1
2
3
4
5
6
7
8
9
10
11#define QLA1280_VERSION "3.27.1"
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330#include <linux/module.h>
331
332#include <linux/types.h>
333#include <linux/string.h>
334#include <linux/errno.h>
335#include <linux/kernel.h>
336#include <linux/ioport.h>
337#include <linux/delay.h>
338#include <linux/timer.h>
339#include <linux/pci.h>
340#include <linux/proc_fs.h>
341#include <linux/stat.h>
342#include <linux/pci_ids.h>
343#include <linux/interrupt.h>
344#include <linux/init.h>
345#include <linux/dma-mapping.h>
346#include <linux/firmware.h>
347
348#include <asm/io.h>
349#include <asm/irq.h>
350#include <asm/byteorder.h>
351#include <asm/processor.h>
352#include <asm/types.h>
353
354#include <scsi/scsi.h>
355#include <scsi/scsi_cmnd.h>
356#include <scsi/scsi_device.h>
357#include <scsi/scsi_host.h>
358#include <scsi/scsi_tcq.h>
359
360
361
362
363
364
365#define DEBUG_QLA1280_INTR 0
366#define DEBUG_PRINT_NVRAM 0
367#define DEBUG_QLA1280 0
368
369#define MEMORY_MAPPED_IO 1
370
371#include "qla1280.h"
372
373#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
374#define QLA_64BIT_PTR 1
375#endif
376
377#define NVRAM_DELAY() udelay(500)
378
379#define IS_ISP1040(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020)
380#define IS_ISP1x40(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020 || \
381 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1240)
382#define IS_ISP1x160(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP10160 || \
383 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP12160)
384
385
386static int qla1280_probe_one(struct pci_dev *, const struct pci_device_id *);
387static void qla1280_remove_one(struct pci_dev *);
388
389
390
391
392static void qla1280_done(struct scsi_qla_host *);
393static int qla1280_get_token(char *);
394static int qla1280_setup(char *s) __init;
395
396
397
398
399static int qla1280_load_firmware(struct scsi_qla_host *);
400static int qla1280_init_rings(struct scsi_qla_host *);
401static int qla1280_nvram_config(struct scsi_qla_host *);
402static int qla1280_mailbox_command(struct scsi_qla_host *,
403 uint8_t, uint16_t *);
404static int qla1280_bus_reset(struct scsi_qla_host *, int);
405static int qla1280_device_reset(struct scsi_qla_host *, int, int);
406static int qla1280_abort_command(struct scsi_qla_host *, struct srb *, int);
407static int qla1280_abort_isp(struct scsi_qla_host *);
408#ifdef QLA_64BIT_PTR
409static int qla1280_64bit_start_scsi(struct scsi_qla_host *, struct srb *);
410#else
411static int qla1280_32bit_start_scsi(struct scsi_qla_host *, struct srb *);
412#endif
413static void qla1280_nv_write(struct scsi_qla_host *, uint16_t);
414static void qla1280_poll(struct scsi_qla_host *);
415static void qla1280_reset_adapter(struct scsi_qla_host *);
416static void qla1280_marker(struct scsi_qla_host *, int, int, int, u8);
417static void qla1280_isp_cmd(struct scsi_qla_host *);
418static void qla1280_isr(struct scsi_qla_host *, struct list_head *);
419static void qla1280_rst_aen(struct scsi_qla_host *);
420static void qla1280_status_entry(struct scsi_qla_host *, struct response *,
421 struct list_head *);
422static void qla1280_error_entry(struct scsi_qla_host *, struct response *,
423 struct list_head *);
424static uint16_t qla1280_get_nvram_word(struct scsi_qla_host *, uint32_t);
425static uint16_t qla1280_nvram_request(struct scsi_qla_host *, uint32_t);
426static uint16_t qla1280_debounce_register(volatile uint16_t __iomem *);
427static request_t *qla1280_req_pkt(struct scsi_qla_host *);
428static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *,
429 unsigned int);
430static void qla1280_get_target_parameters(struct scsi_qla_host *,
431 struct scsi_device *);
432static int qla1280_set_target_parameters(struct scsi_qla_host *, int, int);
433
434
435static struct qla_driver_setup driver_setup;
436
437
438
439
440static inline uint16_t
441qla1280_data_direction(struct scsi_cmnd *cmnd)
442{
443 switch(cmnd->sc_data_direction) {
444 case DMA_FROM_DEVICE:
445 return BIT_5;
446 case DMA_TO_DEVICE:
447 return BIT_6;
448 case DMA_BIDIRECTIONAL:
449 return BIT_5 | BIT_6;
450
451
452
453
454
455 case DMA_NONE:
456 default:
457 return 0;
458 }
459}
460
461#if DEBUG_QLA1280
462static void __qla1280_print_scsi_cmd(struct scsi_cmnd * cmd);
463static void __qla1280_dump_buffer(char *, int);
464#endif
465
466
467
468
469
470#ifdef MODULE
471static char *qla1280;
472
473
474module_param(qla1280, charp, 0);
475#else
476__setup("qla1280=", qla1280_setup);
477#endif
478
479
480
481
482
483
484
485
486#define CMD_SP(Cmnd) &Cmnd->SCp
487#define CMD_CDBLEN(Cmnd) Cmnd->cmd_len
488#define CMD_CDBP(Cmnd) Cmnd->cmnd
489#define CMD_SNSP(Cmnd) Cmnd->sense_buffer
490#define CMD_SNSLEN(Cmnd) SCSI_SENSE_BUFFERSIZE
491#define CMD_RESULT(Cmnd) Cmnd->result
492#define CMD_HANDLE(Cmnd) Cmnd->host_scribble
493
494#define CMD_HOST(Cmnd) Cmnd->device->host
495#define SCSI_BUS_32(Cmnd) Cmnd->device->channel
496#define SCSI_TCN_32(Cmnd) Cmnd->device->id
497#define SCSI_LUN_32(Cmnd) Cmnd->device->lun
498
499
500
501
502
503
504struct qla_boards {
505 char *name;
506 int numPorts;
507 int fw_index;
508};
509
510
511static struct pci_device_id qla1280_pci_tbl[] = {
512 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP12160,
513 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
514 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1020,
515 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
516 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1080,
517 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
518 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1240,
519 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
520 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1280,
521 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
522 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP10160,
523 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5},
524 {0,}
525};
526MODULE_DEVICE_TABLE(pci, qla1280_pci_tbl);
527
528static DEFINE_MUTEX(qla1280_firmware_mutex);
529
530struct qla_fw {
531 char *fwname;
532 const struct firmware *fw;
533};
534
535#define QL_NUM_FW_IMAGES 3
536
537static struct qla_fw qla1280_fw_tbl[QL_NUM_FW_IMAGES] = {
538 {"qlogic/1040.bin", NULL},
539 {"qlogic/1280.bin", NULL},
540 {"qlogic/12160.bin", NULL},
541};
542
543
544static struct qla_boards ql1280_board_tbl[] = {
545 {.name = "QLA12160", .numPorts = 2, .fw_index = 2},
546 {.name = "QLA1040" , .numPorts = 1, .fw_index = 0},
547 {.name = "QLA1080" , .numPorts = 1, .fw_index = 1},
548 {.name = "QLA1240" , .numPorts = 2, .fw_index = 1},
549 {.name = "QLA1280" , .numPorts = 2, .fw_index = 1},
550 {.name = "QLA10160", .numPorts = 1, .fw_index = 2},
551 {.name = " ", .numPorts = 0, .fw_index = -1},
552};
553
554static int qla1280_verbose = 1;
555
556#if DEBUG_QLA1280
557static int ql_debug_level = 1;
558#define dprintk(level, format, a...) \
559 do { if (ql_debug_level >= level) printk(KERN_ERR format, ##a); } while(0)
560#define qla1280_dump_buffer(level, buf, size) \
561 if (ql_debug_level >= level) __qla1280_dump_buffer(buf, size)
562#define qla1280_print_scsi_cmd(level, cmd) \
563 if (ql_debug_level >= level) __qla1280_print_scsi_cmd(cmd)
564#else
565#define ql_debug_level 0
566#define dprintk(level, format, a...) do{}while(0)
567#define qla1280_dump_buffer(a, b, c) do{}while(0)
568#define qla1280_print_scsi_cmd(a, b) do{}while(0)
569#endif
570
571#define ENTER(x) dprintk(3, "qla1280 : Entering %s()\n", x);
572#define LEAVE(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
573#define ENTER_INTR(x) dprintk(4, "qla1280 : Entering %s()\n", x);
574#define LEAVE_INTR(x) dprintk(4, "qla1280 : Leaving %s()\n", x);
575
576
577static int qla1280_read_nvram(struct scsi_qla_host *ha)
578{
579 uint16_t *wptr;
580 uint8_t chksum;
581 int cnt, i;
582 struct nvram *nv;
583
584 ENTER("qla1280_read_nvram");
585
586 if (driver_setup.no_nvram)
587 return 1;
588
589 printk(KERN_INFO "scsi(%ld): Reading NVRAM\n", ha->host_no);
590
591 wptr = (uint16_t *)&ha->nvram;
592 nv = &ha->nvram;
593 chksum = 0;
594 for (cnt = 0; cnt < 3; cnt++) {
595 *wptr = qla1280_get_nvram_word(ha, cnt);
596 chksum += *wptr & 0xff;
597 chksum += (*wptr >> 8) & 0xff;
598 wptr++;
599 }
600
601 if (nv->id0 != 'I' || nv->id1 != 'S' ||
602 nv->id2 != 'P' || nv->id3 != ' ' || nv->version < 1) {
603 dprintk(2, "Invalid nvram ID or version!\n");
604 chksum = 1;
605 } else {
606 for (; cnt < sizeof(struct nvram); cnt++) {
607 *wptr = qla1280_get_nvram_word(ha, cnt);
608 chksum += *wptr & 0xff;
609 chksum += (*wptr >> 8) & 0xff;
610 wptr++;
611 }
612 }
613
614 dprintk(3, "qla1280_read_nvram: NVRAM Magic ID= %c %c %c %02x"
615 " version %i\n", nv->id0, nv->id1, nv->id2, nv->id3,
616 nv->version);
617
618
619 if (chksum) {
620 if (!driver_setup.no_nvram)
621 printk(KERN_WARNING "scsi(%ld): Unable to identify or "
622 "validate NVRAM checksum, using default "
623 "settings\n", ha->host_no);
624 ha->nvram_valid = 0;
625 } else
626 ha->nvram_valid = 1;
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644 nv->isp_parameter = cpu_to_le16(nv->isp_parameter);
645 nv->firmware_feature.w = cpu_to_le16(nv->firmware_feature.w);
646 for(i = 0; i < MAX_BUSES; i++) {
647 nv->bus[i].selection_timeout = cpu_to_le16(nv->bus[i].selection_timeout);
648 nv->bus[i].max_queue_depth = cpu_to_le16(nv->bus[i].max_queue_depth);
649 }
650 dprintk(1, "qla1280_read_nvram: Completed Reading NVRAM\n");
651 LEAVE("qla1280_read_nvram");
652
653 return chksum;
654}
655
656
657
658
659
660static const char *
661qla1280_info(struct Scsi_Host *host)
662{
663 static char qla1280_scsi_name_buffer[125];
664 char *bp;
665 struct scsi_qla_host *ha;
666 struct qla_boards *bdp;
667
668 bp = &qla1280_scsi_name_buffer[0];
669 ha = (struct scsi_qla_host *)host->hostdata;
670 bdp = &ql1280_board_tbl[ha->devnum];
671 memset(bp, 0, sizeof(qla1280_scsi_name_buffer));
672
673 sprintf (bp,
674 "QLogic %s PCI to SCSI Host Adapter\n"
675 " Firmware version: %2d.%02d.%02d, Driver version %s",
676 &bdp->name[0], ha->fwver1, ha->fwver2, ha->fwver3,
677 QLA1280_VERSION);
678 return bp;
679}
680
681
682
683
684
685
686
687
688
689
690
691
692static int
693qla1280_queuecommand_lck(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
694{
695 struct Scsi_Host *host = cmd->device->host;
696 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
697 struct srb *sp = (struct srb *)CMD_SP(cmd);
698 int status;
699
700 cmd->scsi_done = fn;
701 sp->cmd = cmd;
702 sp->flags = 0;
703 sp->wait = NULL;
704 CMD_HANDLE(cmd) = (unsigned char *)NULL;
705
706 qla1280_print_scsi_cmd(5, cmd);
707
708#ifdef QLA_64BIT_PTR
709
710
711
712
713
714
715 status = qla1280_64bit_start_scsi(ha, sp);
716#else
717 status = qla1280_32bit_start_scsi(ha, sp);
718#endif
719 return status;
720}
721
722static DEF_SCSI_QCMD(qla1280_queuecommand)
723
724enum action {
725 ABORT_COMMAND,
726 DEVICE_RESET,
727 BUS_RESET,
728 ADAPTER_RESET,
729};
730
731
732static void qla1280_mailbox_timeout(struct timer_list *t)
733{
734 struct scsi_qla_host *ha = from_timer(ha, t, mailbox_timer);
735 struct device_reg __iomem *reg;
736 reg = ha->iobase;
737
738 ha->mailbox_out[0] = RD_REG_WORD(®->mailbox0);
739 printk(KERN_ERR "scsi(%ld): mailbox timed out, mailbox0 %04x, "
740 "ictrl %04x, istatus %04x\n", ha->host_no, ha->mailbox_out[0],
741 RD_REG_WORD(®->ictrl), RD_REG_WORD(®->istatus));
742 complete(ha->mailbox_wait);
743}
744
745static int
746_qla1280_wait_for_single_command(struct scsi_qla_host *ha, struct srb *sp,
747 struct completion *wait)
748{
749 int status = FAILED;
750 struct scsi_cmnd *cmd = sp->cmd;
751
752 spin_unlock_irq(ha->host->host_lock);
753 wait_for_completion_timeout(wait, 4*HZ);
754 spin_lock_irq(ha->host->host_lock);
755 sp->wait = NULL;
756 if(CMD_HANDLE(cmd) == COMPLETED_HANDLE) {
757 status = SUCCESS;
758 (*cmd->scsi_done)(cmd);
759 }
760 return status;
761}
762
763static int
764qla1280_wait_for_single_command(struct scsi_qla_host *ha, struct srb *sp)
765{
766 DECLARE_COMPLETION_ONSTACK(wait);
767
768 sp->wait = &wait;
769 return _qla1280_wait_for_single_command(ha, sp, &wait);
770}
771
772static int
773qla1280_wait_for_pending_commands(struct scsi_qla_host *ha, int bus, int target)
774{
775 int cnt;
776 int status;
777 struct srb *sp;
778 struct scsi_cmnd *cmd;
779
780 status = SUCCESS;
781
782
783
784
785
786 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
787 sp = ha->outstanding_cmds[cnt];
788 if (sp) {
789 cmd = sp->cmd;
790
791 if (bus >= 0 && SCSI_BUS_32(cmd) != bus)
792 continue;
793 if (target >= 0 && SCSI_TCN_32(cmd) != target)
794 continue;
795
796 status = qla1280_wait_for_single_command(ha, sp);
797 if (status == FAILED)
798 break;
799 }
800 }
801 return status;
802}
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818static int
819qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
820{
821 struct scsi_qla_host *ha;
822 int bus, target, lun;
823 struct srb *sp;
824 int i, found;
825 int result=FAILED;
826 int wait_for_bus=-1;
827 int wait_for_target = -1;
828 DECLARE_COMPLETION_ONSTACK(wait);
829
830 ENTER("qla1280_error_action");
831
832 ha = (struct scsi_qla_host *)(CMD_HOST(cmd)->hostdata);
833 sp = (struct srb *)CMD_SP(cmd);
834 bus = SCSI_BUS_32(cmd);
835 target = SCSI_TCN_32(cmd);
836 lun = SCSI_LUN_32(cmd);
837
838 dprintk(4, "error_action %i, istatus 0x%04x\n", action,
839 RD_REG_WORD(&ha->iobase->istatus));
840
841 dprintk(4, "host_cmd 0x%04x, ictrl 0x%04x, jiffies %li\n",
842 RD_REG_WORD(&ha->iobase->host_cmd),
843 RD_REG_WORD(&ha->iobase->ictrl), jiffies);
844
845 if (qla1280_verbose)
846 printk(KERN_INFO "scsi(%li): Resetting Cmnd=0x%p, "
847 "Handle=0x%p, action=0x%x\n",
848 ha->host_no, cmd, CMD_HANDLE(cmd), action);
849
850
851
852
853
854
855
856 found = -1;
857 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
858 if (sp == ha->outstanding_cmds[i]) {
859 found = i;
860 sp->wait = &wait;
861 break;
862 }
863 }
864
865 if (found < 0) {
866 result = SUCCESS;
867 if (qla1280_verbose) {
868 printk(KERN_INFO
869 "scsi(%ld:%d:%d:%d): specified command has "
870 "already completed.\n", ha->host_no, bus,
871 target, lun);
872 }
873 }
874
875 switch (action) {
876
877 case ABORT_COMMAND:
878 dprintk(1, "qla1280: RISC aborting command\n");
879
880
881
882
883
884 if (found >= 0)
885 qla1280_abort_command(ha, sp, found);
886 break;
887
888 case DEVICE_RESET:
889 if (qla1280_verbose)
890 printk(KERN_INFO
891 "scsi(%ld:%d:%d:%d): Queueing device reset "
892 "command.\n", ha->host_no, bus, target, lun);
893 if (qla1280_device_reset(ha, bus, target) == 0) {
894
895 wait_for_bus = bus;
896 wait_for_target = target;
897 }
898 break;
899
900 case BUS_RESET:
901 if (qla1280_verbose)
902 printk(KERN_INFO "qla1280(%ld:%d): Issued bus "
903 "reset.\n", ha->host_no, bus);
904 if (qla1280_bus_reset(ha, bus) == 0) {
905
906 wait_for_bus = bus;
907 }
908 break;
909
910 case ADAPTER_RESET:
911 default:
912 if (qla1280_verbose) {
913 printk(KERN_INFO
914 "scsi(%ld): Issued ADAPTER RESET\n",
915 ha->host_no);
916 printk(KERN_INFO "scsi(%ld): I/O processing will "
917 "continue automatically\n", ha->host_no);
918 }
919 ha->flags.reset_active = 1;
920
921 if (qla1280_abort_isp(ha) != 0) {
922 result = FAILED;
923 }
924
925 ha->flags.reset_active = 0;
926 }
927
928
929
930
931
932
933
934
935
936
937 if (found >= 0)
938 result = _qla1280_wait_for_single_command(ha, sp, &wait);
939
940 if (action == ABORT_COMMAND && result != SUCCESS) {
941 printk(KERN_WARNING
942 "scsi(%li:%i:%i:%i): "
943 "Unable to abort command!\n",
944 ha->host_no, bus, target, lun);
945 }
946
947
948
949
950
951
952
953
954
955
956
957 if (result == SUCCESS && wait_for_bus >= 0) {
958 result = qla1280_wait_for_pending_commands(ha,
959 wait_for_bus, wait_for_target);
960 }
961
962 dprintk(1, "RESET returning %d\n", result);
963
964 LEAVE("qla1280_error_action");
965 return result;
966}
967
968
969
970
971
972static int
973qla1280_eh_abort(struct scsi_cmnd * cmd)
974{
975 int rc;
976
977 spin_lock_irq(cmd->device->host->host_lock);
978 rc = qla1280_error_action(cmd, ABORT_COMMAND);
979 spin_unlock_irq(cmd->device->host->host_lock);
980
981 return rc;
982}
983
984
985
986
987
988static int
989qla1280_eh_device_reset(struct scsi_cmnd *cmd)
990{
991 int rc;
992
993 spin_lock_irq(cmd->device->host->host_lock);
994 rc = qla1280_error_action(cmd, DEVICE_RESET);
995 spin_unlock_irq(cmd->device->host->host_lock);
996
997 return rc;
998}
999
1000
1001
1002
1003
1004static int
1005qla1280_eh_bus_reset(struct scsi_cmnd *cmd)
1006{
1007 int rc;
1008
1009 spin_lock_irq(cmd->device->host->host_lock);
1010 rc = qla1280_error_action(cmd, BUS_RESET);
1011 spin_unlock_irq(cmd->device->host->host_lock);
1012
1013 return rc;
1014}
1015
1016
1017
1018
1019
1020static int
1021qla1280_eh_adapter_reset(struct scsi_cmnd *cmd)
1022{
1023 int rc;
1024
1025 spin_lock_irq(cmd->device->host->host_lock);
1026 rc = qla1280_error_action(cmd, ADAPTER_RESET);
1027 spin_unlock_irq(cmd->device->host->host_lock);
1028
1029 return rc;
1030}
1031
1032static int
1033qla1280_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1034 sector_t capacity, int geom[])
1035{
1036 int heads, sectors, cylinders;
1037
1038 heads = 64;
1039 sectors = 32;
1040 cylinders = (unsigned long)capacity / (heads * sectors);
1041 if (cylinders > 1024) {
1042 heads = 255;
1043 sectors = 63;
1044 cylinders = (unsigned long)capacity / (heads * sectors);
1045
1046
1047 }
1048
1049 geom[0] = heads;
1050 geom[1] = sectors;
1051 geom[2] = cylinders;
1052
1053 return 0;
1054}
1055
1056
1057
1058static inline void
1059qla1280_disable_intrs(struct scsi_qla_host *ha)
1060{
1061 WRT_REG_WORD(&ha->iobase->ictrl, 0);
1062 RD_REG_WORD(&ha->iobase->ictrl);
1063}
1064
1065
1066static inline void
1067qla1280_enable_intrs(struct scsi_qla_host *ha)
1068{
1069 WRT_REG_WORD(&ha->iobase->ictrl, (ISP_EN_INT | ISP_EN_RISC));
1070 RD_REG_WORD(&ha->iobase->ictrl);
1071}
1072
1073
1074
1075
1076
1077static irqreturn_t
1078qla1280_intr_handler(int irq, void *dev_id)
1079{
1080 struct scsi_qla_host *ha;
1081 struct device_reg __iomem *reg;
1082 u16 data;
1083 int handled = 0;
1084
1085 ENTER_INTR ("qla1280_intr_handler");
1086 ha = (struct scsi_qla_host *)dev_id;
1087
1088 spin_lock(ha->host->host_lock);
1089
1090 ha->isr_count++;
1091 reg = ha->iobase;
1092
1093 qla1280_disable_intrs(ha);
1094
1095 data = qla1280_debounce_register(®->istatus);
1096
1097 if (data & RISC_INT) {
1098 qla1280_isr(ha, &ha->done_q);
1099 handled = 1;
1100 }
1101 if (!list_empty(&ha->done_q))
1102 qla1280_done(ha);
1103
1104 spin_unlock(ha->host->host_lock);
1105
1106 qla1280_enable_intrs(ha);
1107
1108 LEAVE_INTR("qla1280_intr_handler");
1109 return IRQ_RETVAL(handled);
1110}
1111
1112
1113static int
1114qla1280_set_target_parameters(struct scsi_qla_host *ha, int bus, int target)
1115{
1116 uint8_t mr;
1117 uint16_t mb[MAILBOX_REGISTER_COUNT];
1118 struct nvram *nv;
1119 int status, lun;
1120
1121 nv = &ha->nvram;
1122
1123 mr = BIT_3 | BIT_2 | BIT_1 | BIT_0;
1124
1125
1126 mb[0] = MBC_SET_TARGET_PARAMETERS;
1127 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
1128 mb[2] = nv->bus[bus].target[target].parameter.renegotiate_on_error << 8;
1129 mb[2] |= nv->bus[bus].target[target].parameter.stop_queue_on_check << 9;
1130 mb[2] |= nv->bus[bus].target[target].parameter.auto_request_sense << 10;
1131 mb[2] |= nv->bus[bus].target[target].parameter.tag_queuing << 11;
1132 mb[2] |= nv->bus[bus].target[target].parameter.enable_sync << 12;
1133 mb[2] |= nv->bus[bus].target[target].parameter.enable_wide << 13;
1134 mb[2] |= nv->bus[bus].target[target].parameter.parity_checking << 14;
1135 mb[2] |= nv->bus[bus].target[target].parameter.disconnect_allowed << 15;
1136
1137 if (IS_ISP1x160(ha)) {
1138 mb[2] |= nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr << 5;
1139 mb[3] = (nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8);
1140 mb[6] = (nv->bus[bus].target[target].ppr_1x160.flags.ppr_options << 8) |
1141 nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width;
1142 mr |= BIT_6;
1143 } else {
1144 mb[3] = (nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8);
1145 }
1146 mb[3] |= nv->bus[bus].target[target].sync_period;
1147
1148 status = qla1280_mailbox_command(ha, mr, mb);
1149
1150
1151 for (lun = 0; lun < MAX_LUNS; lun++) {
1152 mb[0] = MBC_SET_DEVICE_QUEUE;
1153 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
1154 mb[1] |= lun;
1155 mb[2] = nv->bus[bus].max_queue_depth;
1156 mb[3] = nv->bus[bus].target[target].execution_throttle;
1157 status |= qla1280_mailbox_command(ha, 0x0f, mb);
1158 }
1159
1160 if (status)
1161 printk(KERN_WARNING "scsi(%ld:%i:%i): "
1162 "qla1280_set_target_parameters() failed\n",
1163 ha->host_no, bus, target);
1164 return status;
1165}
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179static int
1180qla1280_slave_configure(struct scsi_device *device)
1181{
1182 struct scsi_qla_host *ha;
1183 int default_depth = 3;
1184 int bus = device->channel;
1185 int target = device->id;
1186 int status = 0;
1187 struct nvram *nv;
1188 unsigned long flags;
1189
1190 ha = (struct scsi_qla_host *)device->host->hostdata;
1191 nv = &ha->nvram;
1192
1193 if (qla1280_check_for_dead_scsi_bus(ha, bus))
1194 return 1;
1195
1196 if (device->tagged_supported &&
1197 (ha->bus_settings[bus].qtag_enables & (BIT_0 << target))) {
1198 scsi_change_queue_depth(device, ha->bus_settings[bus].hiwat);
1199 } else {
1200 scsi_change_queue_depth(device, default_depth);
1201 }
1202
1203 nv->bus[bus].target[target].parameter.enable_sync = device->sdtr;
1204 nv->bus[bus].target[target].parameter.enable_wide = device->wdtr;
1205 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = device->ppr;
1206
1207 if (driver_setup.no_sync ||
1208 (driver_setup.sync_mask &&
1209 (~driver_setup.sync_mask & (1 << target))))
1210 nv->bus[bus].target[target].parameter.enable_sync = 0;
1211 if (driver_setup.no_wide ||
1212 (driver_setup.wide_mask &&
1213 (~driver_setup.wide_mask & (1 << target))))
1214 nv->bus[bus].target[target].parameter.enable_wide = 0;
1215 if (IS_ISP1x160(ha)) {
1216 if (driver_setup.no_ppr ||
1217 (driver_setup.ppr_mask &&
1218 (~driver_setup.ppr_mask & (1 << target))))
1219 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
1220 }
1221
1222 spin_lock_irqsave(ha->host->host_lock, flags);
1223 if (nv->bus[bus].target[target].parameter.enable_sync)
1224 status = qla1280_set_target_parameters(ha, bus, target);
1225 qla1280_get_target_parameters(ha, device);
1226 spin_unlock_irqrestore(ha->host->host_lock, flags);
1227 return status;
1228}
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238static void
1239qla1280_done(struct scsi_qla_host *ha)
1240{
1241 struct srb *sp;
1242 struct list_head *done_q;
1243 int bus, target;
1244 struct scsi_cmnd *cmd;
1245
1246 ENTER("qla1280_done");
1247
1248 done_q = &ha->done_q;
1249
1250 while (!list_empty(done_q)) {
1251 sp = list_entry(done_q->next, struct srb, list);
1252
1253 list_del(&sp->list);
1254
1255 cmd = sp->cmd;
1256 bus = SCSI_BUS_32(cmd);
1257 target = SCSI_TCN_32(cmd);
1258
1259 switch ((CMD_RESULT(cmd) >> 16)) {
1260 case DID_RESET:
1261
1262 if (!ha->flags.abort_isp_active)
1263 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
1264 break;
1265 case DID_ABORT:
1266 sp->flags &= ~SRB_ABORT_PENDING;
1267 sp->flags |= SRB_ABORTED;
1268 break;
1269 default:
1270 break;
1271 }
1272
1273
1274 scsi_dma_unmap(cmd);
1275
1276
1277 ha->actthreads--;
1278
1279 if (sp->wait == NULL)
1280 (*(cmd)->scsi_done)(cmd);
1281 else
1282 complete(sp->wait);
1283 }
1284 LEAVE("qla1280_done");
1285}
1286
1287
1288
1289
1290static int
1291qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
1292{
1293 int host_status = DID_ERROR;
1294 uint16_t comp_status = le16_to_cpu(sts->comp_status);
1295 uint16_t state_flags = le16_to_cpu(sts->state_flags);
1296 uint32_t residual_length = le32_to_cpu(sts->residual_length);
1297 uint16_t scsi_status = le16_to_cpu(sts->scsi_status);
1298#if DEBUG_QLA1280_INTR
1299 static char *reason[] = {
1300 "DID_OK",
1301 "DID_NO_CONNECT",
1302 "DID_BUS_BUSY",
1303 "DID_TIME_OUT",
1304 "DID_BAD_TARGET",
1305 "DID_ABORT",
1306 "DID_PARITY",
1307 "DID_ERROR",
1308 "DID_RESET",
1309 "DID_BAD_INTR"
1310 };
1311#endif
1312
1313 ENTER("qla1280_return_status");
1314
1315#if DEBUG_QLA1280_INTR
1316
1317
1318
1319
1320#endif
1321
1322 switch (comp_status) {
1323 case CS_COMPLETE:
1324 host_status = DID_OK;
1325 break;
1326
1327 case CS_INCOMPLETE:
1328 if (!(state_flags & SF_GOT_BUS))
1329 host_status = DID_NO_CONNECT;
1330 else if (!(state_flags & SF_GOT_TARGET))
1331 host_status = DID_BAD_TARGET;
1332 else if (!(state_flags & SF_SENT_CDB))
1333 host_status = DID_ERROR;
1334 else if (!(state_flags & SF_TRANSFERRED_DATA))
1335 host_status = DID_ERROR;
1336 else if (!(state_flags & SF_GOT_STATUS))
1337 host_status = DID_ERROR;
1338 else if (!(state_flags & SF_GOT_SENSE))
1339 host_status = DID_ERROR;
1340 break;
1341
1342 case CS_RESET:
1343 host_status = DID_RESET;
1344 break;
1345
1346 case CS_ABORTED:
1347 host_status = DID_ABORT;
1348 break;
1349
1350 case CS_TIMEOUT:
1351 host_status = DID_TIME_OUT;
1352 break;
1353
1354 case CS_DATA_OVERRUN:
1355 dprintk(2, "Data overrun 0x%x\n", residual_length);
1356 dprintk(2, "qla1280_return_status: response packet data\n");
1357 qla1280_dump_buffer(2, (char *)sts, RESPONSE_ENTRY_SIZE);
1358 host_status = DID_ERROR;
1359 break;
1360
1361 case CS_DATA_UNDERRUN:
1362 if ((scsi_bufflen(cp) - residual_length) <
1363 cp->underflow) {
1364 printk(KERN_WARNING
1365 "scsi: Underflow detected - retrying "
1366 "command.\n");
1367 host_status = DID_ERROR;
1368 } else {
1369 scsi_set_resid(cp, residual_length);
1370 host_status = DID_OK;
1371 }
1372 break;
1373
1374 default:
1375 host_status = DID_ERROR;
1376 break;
1377 }
1378
1379#if DEBUG_QLA1280_INTR
1380 dprintk(1, "qla1280 ISP status: host status (%s) scsi status %x\n",
1381 reason[host_status], scsi_status);
1382#endif
1383
1384 LEAVE("qla1280_return_status");
1385
1386 return (scsi_status & 0xff) | (host_status << 16);
1387}
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403static int
1404qla1280_initialize_adapter(struct scsi_qla_host *ha)
1405{
1406 struct device_reg __iomem *reg;
1407 int status;
1408 int bus;
1409 unsigned long flags;
1410
1411 ENTER("qla1280_initialize_adapter");
1412
1413
1414 ha->flags.online = 0;
1415 ha->flags.disable_host_adapter = 0;
1416 ha->flags.reset_active = 0;
1417 ha->flags.abort_isp_active = 0;
1418
1419
1420 if (IS_ISP1040(ha))
1421 driver_setup.no_nvram = 1;
1422
1423 dprintk(1, "Configure PCI space for adapter...\n");
1424
1425 reg = ha->iobase;
1426
1427
1428 WRT_REG_WORD(®->semaphore, 0);
1429 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
1430 WRT_REG_WORD(®->host_cmd, HC_CLR_HOST_INT);
1431 RD_REG_WORD(®->host_cmd);
1432
1433 if (qla1280_read_nvram(ha)) {
1434 dprintk(2, "qla1280_initialize_adapter: failed to read "
1435 "NVRAM\n");
1436 }
1437
1438
1439
1440
1441
1442
1443 spin_lock_irqsave(ha->host->host_lock, flags);
1444
1445 status = qla1280_load_firmware(ha);
1446 if (status) {
1447 printk(KERN_ERR "scsi(%li): initialize: pci probe failed!\n",
1448 ha->host_no);
1449 goto out;
1450 }
1451
1452
1453 dprintk(1, "scsi(%ld): Configure NVRAM parameters\n", ha->host_no);
1454 qla1280_nvram_config(ha);
1455
1456 if (ha->flags.disable_host_adapter) {
1457 status = 1;
1458 goto out;
1459 }
1460
1461 status = qla1280_init_rings(ha);
1462 if (status)
1463 goto out;
1464
1465
1466 for (bus = 0; bus < ha->ports; bus++) {
1467 if (!ha->bus_settings[bus].disable_scsi_reset &&
1468 qla1280_bus_reset(ha, bus) &&
1469 qla1280_bus_reset(ha, bus))
1470 ha->bus_settings[bus].scsi_bus_dead = 1;
1471 }
1472
1473 ha->flags.online = 1;
1474 out:
1475 spin_unlock_irqrestore(ha->host->host_lock, flags);
1476
1477 if (status)
1478 dprintk(2, "qla1280_initialize_adapter: **** FAILED ****\n");
1479
1480 LEAVE("qla1280_initialize_adapter");
1481 return status;
1482}
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496static const struct firmware *
1497qla1280_request_firmware(struct scsi_qla_host *ha)
1498{
1499 const struct firmware *fw;
1500 int err;
1501 int index;
1502 char *fwname;
1503
1504 spin_unlock_irq(ha->host->host_lock);
1505 mutex_lock(&qla1280_firmware_mutex);
1506
1507 index = ql1280_board_tbl[ha->devnum].fw_index;
1508 fw = qla1280_fw_tbl[index].fw;
1509 if (fw)
1510 goto out;
1511
1512 fwname = qla1280_fw_tbl[index].fwname;
1513 err = request_firmware(&fw, fwname, &ha->pdev->dev);
1514
1515 if (err) {
1516 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
1517 fwname, err);
1518 fw = ERR_PTR(err);
1519 goto unlock;
1520 }
1521 if ((fw->size % 2) || (fw->size < 6)) {
1522 printk(KERN_ERR "Invalid firmware length %zu in image \"%s\"\n",
1523 fw->size, fwname);
1524 release_firmware(fw);
1525 fw = ERR_PTR(-EINVAL);
1526 goto unlock;
1527 }
1528
1529 qla1280_fw_tbl[index].fw = fw;
1530
1531 out:
1532 ha->fwver1 = fw->data[0];
1533 ha->fwver2 = fw->data[1];
1534 ha->fwver3 = fw->data[2];
1535 unlock:
1536 mutex_unlock(&qla1280_firmware_mutex);
1537 spin_lock_irq(ha->host->host_lock);
1538 return fw;
1539}
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551static int
1552qla1280_chip_diag(struct scsi_qla_host *ha)
1553{
1554 uint16_t mb[MAILBOX_REGISTER_COUNT];
1555 struct device_reg __iomem *reg = ha->iobase;
1556 int status = 0;
1557 int cnt;
1558 uint16_t data;
1559 dprintk(3, "qla1280_chip_diag: testing device at 0x%p \n", ®->id_l);
1560
1561 dprintk(1, "scsi(%ld): Verifying chip\n", ha->host_no);
1562
1563
1564 WRT_REG_WORD(®->ictrl, ISP_RESET);
1565
1566
1567
1568
1569
1570
1571
1572
1573 udelay(20);
1574 data = qla1280_debounce_register(®->ictrl);
1575
1576
1577
1578 for (cnt = 1000000; cnt && data & ISP_RESET; cnt--) {
1579 udelay(5);
1580 data = RD_REG_WORD(®->ictrl);
1581 }
1582
1583 if (!cnt)
1584 goto fail;
1585
1586
1587 dprintk(3, "qla1280_chip_diag: reset register cleared by chip reset\n");
1588
1589 WRT_REG_WORD(®->cfg_1, 0);
1590
1591
1592
1593 WRT_REG_WORD(®->host_cmd, HC_RESET_RISC |
1594 HC_RELEASE_RISC | HC_DISABLE_BIOS);
1595
1596 RD_REG_WORD(®->id_l);
1597 data = qla1280_debounce_register(®->mailbox0);
1598
1599
1600
1601
1602 for (cnt = 1000000; cnt && data == MBS_BUSY; cnt--) {
1603 udelay(5);
1604 data = RD_REG_WORD(®->mailbox0);
1605 }
1606
1607 if (!cnt)
1608 goto fail;
1609
1610
1611 dprintk(3, "qla1280_chip_diag: Checking product ID of chip\n");
1612
1613 if (RD_REG_WORD(®->mailbox1) != PROD_ID_1 ||
1614 (RD_REG_WORD(®->mailbox2) != PROD_ID_2 &&
1615 RD_REG_WORD(®->mailbox2) != PROD_ID_2a) ||
1616 RD_REG_WORD(®->mailbox3) != PROD_ID_3 ||
1617 RD_REG_WORD(®->mailbox4) != PROD_ID_4) {
1618 printk(KERN_INFO "qla1280: Wrong product ID = "
1619 "0x%x,0x%x,0x%x,0x%x\n",
1620 RD_REG_WORD(®->mailbox1),
1621 RD_REG_WORD(®->mailbox2),
1622 RD_REG_WORD(®->mailbox3),
1623 RD_REG_WORD(®->mailbox4));
1624 goto fail;
1625 }
1626
1627
1628
1629
1630 qla1280_enable_intrs(ha);
1631
1632 dprintk(1, "qla1280_chip_diag: Checking mailboxes of chip\n");
1633
1634 mb[0] = MBC_MAILBOX_REGISTER_TEST;
1635 mb[1] = 0xAAAA;
1636 mb[2] = 0x5555;
1637 mb[3] = 0xAA55;
1638 mb[4] = 0x55AA;
1639 mb[5] = 0xA5A5;
1640 mb[6] = 0x5A5A;
1641 mb[7] = 0x2525;
1642
1643 status = qla1280_mailbox_command(ha, 0xff, mb);
1644 if (status)
1645 goto fail;
1646
1647 if (mb[1] != 0xAAAA || mb[2] != 0x5555 || mb[3] != 0xAA55 ||
1648 mb[4] != 0x55AA || mb[5] != 0xA5A5 || mb[6] != 0x5A5A ||
1649 mb[7] != 0x2525) {
1650 printk(KERN_INFO "qla1280: Failed mbox check\n");
1651 goto fail;
1652 }
1653
1654 dprintk(3, "qla1280_chip_diag: exiting normally\n");
1655 return 0;
1656 fail:
1657 dprintk(2, "qla1280_chip_diag: **** FAILED ****\n");
1658 return status;
1659}
1660
1661static int
1662qla1280_load_firmware_pio(struct scsi_qla_host *ha)
1663{
1664
1665
1666 const struct firmware *fw;
1667 const __le16 *fw_data;
1668 uint16_t risc_address, risc_code_size;
1669 uint16_t mb[MAILBOX_REGISTER_COUNT], i;
1670 int err = 0;
1671
1672 fw = qla1280_request_firmware(ha);
1673 if (IS_ERR(fw))
1674 return PTR_ERR(fw);
1675
1676 fw_data = (const __le16 *)&fw->data[0];
1677 ha->fwstart = __le16_to_cpu(fw_data[2]);
1678
1679
1680 risc_address = ha->fwstart;
1681 fw_data = (const __le16 *)&fw->data[6];
1682 risc_code_size = (fw->size - 6) / 2;
1683
1684 for (i = 0; i < risc_code_size; i++) {
1685 mb[0] = MBC_WRITE_RAM_WORD;
1686 mb[1] = risc_address + i;
1687 mb[2] = __le16_to_cpu(fw_data[i]);
1688
1689 err = qla1280_mailbox_command(ha, BIT_0 | BIT_1 | BIT_2, mb);
1690 if (err) {
1691 printk(KERN_ERR "scsi(%li): Failed to load firmware\n",
1692 ha->host_no);
1693 break;
1694 }
1695 }
1696
1697 return err;
1698}
1699
1700#ifdef QLA_64BIT_PTR
1701#define LOAD_CMD MBC_LOAD_RAM_A64_ROM
1702#define DUMP_CMD MBC_DUMP_RAM_A64_ROM
1703#define CMD_ARGS (BIT_7 | BIT_6 | BIT_4 | BIT_3 | BIT_2 | BIT_1 | BIT_0)
1704#else
1705#define LOAD_CMD MBC_LOAD_RAM
1706#define DUMP_CMD MBC_DUMP_RAM
1707#define CMD_ARGS (BIT_4 | BIT_3 | BIT_2 | BIT_1 | BIT_0)
1708#endif
1709
1710#define DUMP_IT_BACK 0
1711static int
1712qla1280_load_firmware_dma(struct scsi_qla_host *ha)
1713{
1714
1715 const struct firmware *fw;
1716 const __le16 *fw_data;
1717 uint16_t risc_address, risc_code_size;
1718 uint16_t mb[MAILBOX_REGISTER_COUNT], cnt;
1719 int err = 0, num, i;
1720#if DUMP_IT_BACK
1721 uint8_t *sp, *tbuf;
1722 dma_addr_t p_tbuf;
1723
1724 tbuf = dma_alloc_coherent(&ha->pdev->dev, 8000, &p_tbuf, GFP_KERNEL);
1725 if (!tbuf)
1726 return -ENOMEM;
1727#endif
1728
1729 fw = qla1280_request_firmware(ha);
1730 if (IS_ERR(fw))
1731 return PTR_ERR(fw);
1732
1733 fw_data = (const __le16 *)&fw->data[0];
1734 ha->fwstart = __le16_to_cpu(fw_data[2]);
1735
1736
1737 risc_address = ha->fwstart;
1738 fw_data = (const __le16 *)&fw->data[6];
1739 risc_code_size = (fw->size - 6) / 2;
1740
1741 dprintk(1, "%s: DMA RISC code (%i) words\n",
1742 __func__, risc_code_size);
1743
1744 num = 0;
1745 while (risc_code_size > 0) {
1746 int warn __attribute__((unused)) = 0;
1747
1748 cnt = 2000 >> 1;
1749
1750 if (cnt > risc_code_size)
1751 cnt = risc_code_size;
1752
1753 dprintk(2, "qla1280_setup_chip: loading risc @ =(0x%p),"
1754 "%d,%d(0x%x)\n",
1755 fw_data, cnt, num, risc_address);
1756 for(i = 0; i < cnt; i++)
1757 ((__le16 *)ha->request_ring)[i] = fw_data[i];
1758
1759 mb[0] = LOAD_CMD;
1760 mb[1] = risc_address;
1761 mb[4] = cnt;
1762 mb[3] = ha->request_dma & 0xffff;
1763 mb[2] = (ha->request_dma >> 16) & 0xffff;
1764 mb[7] = upper_32_bits(ha->request_dma) & 0xffff;
1765 mb[6] = upper_32_bits(ha->request_dma) >> 16;
1766 dprintk(2, "%s: op=%d 0x%p = 0x%4x,0x%4x,0x%4x,0x%4x\n",
1767 __func__, mb[0],
1768 (void *)(long)ha->request_dma,
1769 mb[6], mb[7], mb[2], mb[3]);
1770 err = qla1280_mailbox_command(ha, CMD_ARGS, mb);
1771 if (err) {
1772 printk(KERN_ERR "scsi(%li): Failed to load partial "
1773 "segment of f\n", ha->host_no);
1774 goto out;
1775 }
1776
1777#if DUMP_IT_BACK
1778 mb[0] = DUMP_CMD;
1779 mb[1] = risc_address;
1780 mb[4] = cnt;
1781 mb[3] = p_tbuf & 0xffff;
1782 mb[2] = (p_tbuf >> 16) & 0xffff;
1783 mb[7] = upper_32_bits(p_tbuf) & 0xffff;
1784 mb[6] = upper_32_bits(p_tbuf) >> 16;
1785
1786 err = qla1280_mailbox_command(ha, CMD_ARGS, mb);
1787 if (err) {
1788 printk(KERN_ERR
1789 "Failed to dump partial segment of f/w\n");
1790 goto out;
1791 }
1792 sp = (uint8_t *)ha->request_ring;
1793 for (i = 0; i < (cnt << 1); i++) {
1794 if (tbuf[i] != sp[i] && warn++ < 10) {
1795 printk(KERN_ERR "%s: FW compare error @ "
1796 "byte(0x%x) loop#=%x\n",
1797 __func__, i, num);
1798 printk(KERN_ERR "%s: FWbyte=%x "
1799 "FWfromChip=%x\n",
1800 __func__, sp[i], tbuf[i]);
1801
1802 }
1803 }
1804#endif
1805 risc_address += cnt;
1806 risc_code_size = risc_code_size - cnt;
1807 fw_data = fw_data + cnt;
1808 num++;
1809 }
1810
1811 out:
1812#if DUMP_IT_BACK
1813 dma_free_coherent(&ha->pdev->dev, 8000, tbuf, p_tbuf);
1814#endif
1815 return err;
1816}
1817
1818static int
1819qla1280_start_firmware(struct scsi_qla_host *ha)
1820{
1821 uint16_t mb[MAILBOX_REGISTER_COUNT];
1822 int err;
1823
1824 dprintk(1, "%s: Verifying checksum of loaded RISC code.\n",
1825 __func__);
1826
1827
1828 mb[0] = MBC_VERIFY_CHECKSUM;
1829
1830 mb[1] = ha->fwstart;
1831 err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
1832 if (err) {
1833 printk(KERN_ERR "scsi(%li): RISC checksum failed.\n", ha->host_no);
1834 return err;
1835 }
1836
1837
1838 dprintk(1, "%s: start firmware running.\n", __func__);
1839 mb[0] = MBC_EXECUTE_FIRMWARE;
1840 mb[1] = ha->fwstart;
1841 err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
1842 if (err) {
1843 printk(KERN_ERR "scsi(%li): Failed to start firmware\n",
1844 ha->host_no);
1845 }
1846
1847 return err;
1848}
1849
1850static int
1851qla1280_load_firmware(struct scsi_qla_host *ha)
1852{
1853
1854 int err;
1855
1856 err = qla1280_chip_diag(ha);
1857 if (err)
1858 goto out;
1859 if (IS_ISP1040(ha))
1860 err = qla1280_load_firmware_pio(ha);
1861 else
1862 err = qla1280_load_firmware_dma(ha);
1863 if (err)
1864 goto out;
1865 err = qla1280_start_firmware(ha);
1866 out:
1867 return err;
1868}
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883static int
1884qla1280_init_rings(struct scsi_qla_host *ha)
1885{
1886 uint16_t mb[MAILBOX_REGISTER_COUNT];
1887 int status = 0;
1888
1889 ENTER("qla1280_init_rings");
1890
1891
1892 memset(ha->outstanding_cmds, 0,
1893 sizeof(struct srb *) * MAX_OUTSTANDING_COMMANDS);
1894
1895
1896 ha->request_ring_ptr = ha->request_ring;
1897 ha->req_ring_index = 0;
1898 ha->req_q_cnt = REQUEST_ENTRY_CNT;
1899
1900 mb[0] = MBC_INIT_REQUEST_QUEUE_A64;
1901 mb[1] = REQUEST_ENTRY_CNT;
1902 mb[3] = ha->request_dma & 0xffff;
1903 mb[2] = (ha->request_dma >> 16) & 0xffff;
1904 mb[4] = 0;
1905 mb[7] = upper_32_bits(ha->request_dma) & 0xffff;
1906 mb[6] = upper_32_bits(ha->request_dma) >> 16;
1907 if (!(status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_4 |
1908 BIT_3 | BIT_2 | BIT_1 | BIT_0,
1909 &mb[0]))) {
1910
1911 ha->response_ring_ptr = ha->response_ring;
1912 ha->rsp_ring_index = 0;
1913
1914 mb[0] = MBC_INIT_RESPONSE_QUEUE_A64;
1915 mb[1] = RESPONSE_ENTRY_CNT;
1916 mb[3] = ha->response_dma & 0xffff;
1917 mb[2] = (ha->response_dma >> 16) & 0xffff;
1918 mb[5] = 0;
1919 mb[7] = upper_32_bits(ha->response_dma) & 0xffff;
1920 mb[6] = upper_32_bits(ha->response_dma) >> 16;
1921 status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_5 |
1922 BIT_3 | BIT_2 | BIT_1 | BIT_0,
1923 &mb[0]);
1924 }
1925
1926 if (status)
1927 dprintk(2, "qla1280_init_rings: **** FAILED ****\n");
1928
1929 LEAVE("qla1280_init_rings");
1930 return status;
1931}
1932
1933static void
1934qla1280_print_settings(struct nvram *nv)
1935{
1936 dprintk(1, "qla1280 : initiator scsi id bus[0]=%d\n",
1937 nv->bus[0].config_1.initiator_id);
1938 dprintk(1, "qla1280 : initiator scsi id bus[1]=%d\n",
1939 nv->bus[1].config_1.initiator_id);
1940
1941 dprintk(1, "qla1280 : bus reset delay[0]=%d\n",
1942 nv->bus[0].bus_reset_delay);
1943 dprintk(1, "qla1280 : bus reset delay[1]=%d\n",
1944 nv->bus[1].bus_reset_delay);
1945
1946 dprintk(1, "qla1280 : retry count[0]=%d\n", nv->bus[0].retry_count);
1947 dprintk(1, "qla1280 : retry delay[0]=%d\n", nv->bus[0].retry_delay);
1948 dprintk(1, "qla1280 : retry count[1]=%d\n", nv->bus[1].retry_count);
1949 dprintk(1, "qla1280 : retry delay[1]=%d\n", nv->bus[1].retry_delay);
1950
1951 dprintk(1, "qla1280 : async data setup time[0]=%d\n",
1952 nv->bus[0].config_2.async_data_setup_time);
1953 dprintk(1, "qla1280 : async data setup time[1]=%d\n",
1954 nv->bus[1].config_2.async_data_setup_time);
1955
1956 dprintk(1, "qla1280 : req/ack active negation[0]=%d\n",
1957 nv->bus[0].config_2.req_ack_active_negation);
1958 dprintk(1, "qla1280 : req/ack active negation[1]=%d\n",
1959 nv->bus[1].config_2.req_ack_active_negation);
1960
1961 dprintk(1, "qla1280 : data line active negation[0]=%d\n",
1962 nv->bus[0].config_2.data_line_active_negation);
1963 dprintk(1, "qla1280 : data line active negation[1]=%d\n",
1964 nv->bus[1].config_2.data_line_active_negation);
1965
1966 dprintk(1, "qla1280 : disable loading risc code=%d\n",
1967 nv->cntr_flags_1.disable_loading_risc_code);
1968
1969 dprintk(1, "qla1280 : enable 64bit addressing=%d\n",
1970 nv->cntr_flags_1.enable_64bit_addressing);
1971
1972 dprintk(1, "qla1280 : selection timeout limit[0]=%d\n",
1973 nv->bus[0].selection_timeout);
1974 dprintk(1, "qla1280 : selection timeout limit[1]=%d\n",
1975 nv->bus[1].selection_timeout);
1976
1977 dprintk(1, "qla1280 : max queue depth[0]=%d\n",
1978 nv->bus[0].max_queue_depth);
1979 dprintk(1, "qla1280 : max queue depth[1]=%d\n",
1980 nv->bus[1].max_queue_depth);
1981}
1982
1983static void
1984qla1280_set_target_defaults(struct scsi_qla_host *ha, int bus, int target)
1985{
1986 struct nvram *nv = &ha->nvram;
1987
1988 nv->bus[bus].target[target].parameter.renegotiate_on_error = 1;
1989 nv->bus[bus].target[target].parameter.auto_request_sense = 1;
1990 nv->bus[bus].target[target].parameter.tag_queuing = 1;
1991 nv->bus[bus].target[target].parameter.enable_sync = 1;
1992#if 1
1993 nv->bus[bus].target[target].parameter.enable_wide = 1;
1994#endif
1995 nv->bus[bus].target[target].execution_throttle =
1996 nv->bus[bus].max_queue_depth - 1;
1997 nv->bus[bus].target[target].parameter.parity_checking = 1;
1998 nv->bus[bus].target[target].parameter.disconnect_allowed = 1;
1999
2000 if (IS_ISP1x160(ha)) {
2001 nv->bus[bus].target[target].flags.flags1x160.device_enable = 1;
2002 nv->bus[bus].target[target].flags.flags1x160.sync_offset = 0x0e;
2003 nv->bus[bus].target[target].sync_period = 9;
2004 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1;
2005 nv->bus[bus].target[target].ppr_1x160.flags.ppr_options = 2;
2006 nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width = 1;
2007 } else {
2008 nv->bus[bus].target[target].flags.flags1x80.device_enable = 1;
2009 nv->bus[bus].target[target].flags.flags1x80.sync_offset = 12;
2010 nv->bus[bus].target[target].sync_period = 10;
2011 }
2012}
2013
2014static void
2015qla1280_set_defaults(struct scsi_qla_host *ha)
2016{
2017 struct nvram *nv = &ha->nvram;
2018 int bus, target;
2019
2020 dprintk(1, "Using defaults for NVRAM: \n");
2021 memset(nv, 0, sizeof(struct nvram));
2022
2023
2024 nv->firmware_feature.f.enable_fast_posting = 1;
2025 nv->firmware_feature.f.disable_synchronous_backoff = 1;
2026 nv->termination.scsi_bus_0_control = 3;
2027 nv->termination.scsi_bus_1_control = 3;
2028 nv->termination.auto_term_support = 1;
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038 nv->isp_config.burst_enable = 1;
2039 if (IS_ISP1040(ha))
2040 nv->isp_config.fifo_threshold |= 3;
2041 else
2042 nv->isp_config.fifo_threshold |= 4;
2043
2044 if (IS_ISP1x160(ha))
2045 nv->isp_parameter = 0x01;
2046
2047 for (bus = 0; bus < MAX_BUSES; bus++) {
2048 nv->bus[bus].config_1.initiator_id = 7;
2049 nv->bus[bus].config_2.req_ack_active_negation = 1;
2050 nv->bus[bus].config_2.data_line_active_negation = 1;
2051 nv->bus[bus].selection_timeout = 250;
2052 nv->bus[bus].max_queue_depth = 32;
2053
2054 if (IS_ISP1040(ha)) {
2055 nv->bus[bus].bus_reset_delay = 3;
2056 nv->bus[bus].config_2.async_data_setup_time = 6;
2057 nv->bus[bus].retry_delay = 1;
2058 } else {
2059 nv->bus[bus].bus_reset_delay = 5;
2060 nv->bus[bus].config_2.async_data_setup_time = 8;
2061 }
2062
2063 for (target = 0; target < MAX_TARGETS; target++)
2064 qla1280_set_target_defaults(ha, bus, target);
2065 }
2066}
2067
2068static int
2069qla1280_config_target(struct scsi_qla_host *ha, int bus, int target)
2070{
2071 struct nvram *nv = &ha->nvram;
2072 uint16_t mb[MAILBOX_REGISTER_COUNT];
2073 int status, lun;
2074 uint16_t flag;
2075
2076
2077 mb[0] = MBC_SET_TARGET_PARAMETERS;
2078 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
2079
2080
2081
2082
2083
2084
2085 mb[2] = (TP_RENEGOTIATE | TP_AUTO_REQUEST_SENSE | TP_TAGGED_QUEUE
2086 | TP_WIDE | TP_PARITY | TP_DISCONNECT);
2087
2088 if (IS_ISP1x160(ha))
2089 mb[3] = nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8;
2090 else
2091 mb[3] = nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8;
2092 mb[3] |= nv->bus[bus].target[target].sync_period;
2093 status = qla1280_mailbox_command(ha, 0x0f, mb);
2094
2095
2096 flag = (BIT_0 << target);
2097 if (nv->bus[bus].target[target].parameter.tag_queuing)
2098 ha->bus_settings[bus].qtag_enables |= flag;
2099
2100
2101 if (IS_ISP1x160(ha)) {
2102 if (nv->bus[bus].target[target].flags.flags1x160.device_enable)
2103 ha->bus_settings[bus].device_enables |= flag;
2104 ha->bus_settings[bus].lun_disables |= 0;
2105 } else {
2106 if (nv->bus[bus].target[target].flags.flags1x80.device_enable)
2107 ha->bus_settings[bus].device_enables |= flag;
2108
2109 if (nv->bus[bus].target[target].flags.flags1x80.lun_disable)
2110 ha->bus_settings[bus].lun_disables |= flag;
2111 }
2112
2113
2114 for (lun = 0; lun < MAX_LUNS; lun++) {
2115 mb[0] = MBC_SET_DEVICE_QUEUE;
2116 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
2117 mb[1] |= lun;
2118 mb[2] = nv->bus[bus].max_queue_depth;
2119 mb[3] = nv->bus[bus].target[target].execution_throttle;
2120 status |= qla1280_mailbox_command(ha, 0x0f, mb);
2121 }
2122
2123 return status;
2124}
2125
2126static int
2127qla1280_config_bus(struct scsi_qla_host *ha, int bus)
2128{
2129 struct nvram *nv = &ha->nvram;
2130 uint16_t mb[MAILBOX_REGISTER_COUNT];
2131 int target, status;
2132
2133
2134 ha->bus_settings[bus].disable_scsi_reset =
2135 nv->bus[bus].config_1.scsi_reset_disable;
2136
2137
2138 ha->bus_settings[bus].id = nv->bus[bus].config_1.initiator_id;
2139 mb[0] = MBC_SET_INITIATOR_ID;
2140 mb[1] = bus ? ha->bus_settings[bus].id | BIT_7 :
2141 ha->bus_settings[bus].id;
2142 status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2143
2144
2145 ha->bus_settings[bus].bus_reset_delay =
2146 nv->bus[bus].bus_reset_delay;
2147
2148
2149 ha->bus_settings[bus].hiwat = nv->bus[bus].max_queue_depth - 1;
2150
2151
2152 for (target = 0; target < MAX_TARGETS; target++)
2153 status |= qla1280_config_target(ha, bus, target);
2154
2155 return status;
2156}
2157
2158static int
2159qla1280_nvram_config(struct scsi_qla_host *ha)
2160{
2161 struct device_reg __iomem *reg = ha->iobase;
2162 struct nvram *nv = &ha->nvram;
2163 int bus, target, status = 0;
2164 uint16_t mb[MAILBOX_REGISTER_COUNT];
2165
2166 ENTER("qla1280_nvram_config");
2167
2168 if (ha->nvram_valid) {
2169
2170 for (bus = 0; bus < MAX_BUSES; bus++)
2171 for (target = 0; target < MAX_TARGETS; target++) {
2172 nv->bus[bus].target[target].parameter.
2173 auto_request_sense = 1;
2174 }
2175 } else {
2176 qla1280_set_defaults(ha);
2177 }
2178
2179 qla1280_print_settings(nv);
2180
2181
2182 ha->flags.disable_risc_code_load =
2183 nv->cntr_flags_1.disable_loading_risc_code;
2184
2185 if (IS_ISP1040(ha)) {
2186 uint16_t hwrev, cfg1, cdma_conf;
2187
2188 hwrev = RD_REG_WORD(®->cfg_0) & ISP_CFG0_HWMSK;
2189
2190 cfg1 = RD_REG_WORD(®->cfg_1) & ~(BIT_4 | BIT_5 | BIT_6);
2191 cdma_conf = RD_REG_WORD(®->cdma_cfg);
2192
2193
2194 if (hwrev != ISP_CFG0_1040A)
2195 cfg1 |= nv->isp_config.fifo_threshold << 4;
2196
2197 cfg1 |= nv->isp_config.burst_enable << 2;
2198 WRT_REG_WORD(®->cfg_1, cfg1);
2199
2200 WRT_REG_WORD(®->cdma_cfg, cdma_conf | CDMA_CONF_BENAB);
2201 WRT_REG_WORD(®->ddma_cfg, cdma_conf | DDMA_CONF_BENAB);
2202 } else {
2203 uint16_t cfg1, term;
2204
2205
2206 cfg1 = nv->isp_config.fifo_threshold << 4;
2207 cfg1 |= nv->isp_config.burst_enable << 2;
2208
2209 if (ha->ports > 1)
2210 cfg1 |= BIT_13;
2211 WRT_REG_WORD(®->cfg_1, cfg1);
2212
2213
2214 WRT_REG_WORD(®->gpio_enable,
2215 BIT_7 | BIT_3 | BIT_2 | BIT_1 | BIT_0);
2216 term = nv->termination.scsi_bus_1_control;
2217 term |= nv->termination.scsi_bus_0_control << 2;
2218 term |= nv->termination.auto_term_support << 7;
2219 RD_REG_WORD(®->id_l);
2220 WRT_REG_WORD(®->gpio_data, term);
2221 }
2222 RD_REG_WORD(®->id_l);
2223
2224
2225 mb[0] = MBC_SET_SYSTEM_PARAMETER;
2226 mb[1] = nv->isp_parameter;
2227 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2228
2229 if (IS_ISP1x40(ha)) {
2230
2231 mb[0] = MBC_SET_CLOCK_RATE;
2232 mb[1] = 40;
2233 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2234 }
2235
2236
2237 mb[0] = MBC_SET_FIRMWARE_FEATURES;
2238 mb[1] = nv->firmware_feature.f.enable_fast_posting;
2239 mb[1] |= nv->firmware_feature.f.report_lvd_bus_transition << 1;
2240 mb[1] |= nv->firmware_feature.f.disable_synchronous_backoff << 5;
2241 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2242
2243
2244 mb[0] = MBC_SET_RETRY_COUNT;
2245 mb[1] = nv->bus[0].retry_count;
2246 mb[2] = nv->bus[0].retry_delay;
2247 mb[6] = nv->bus[1].retry_count;
2248 mb[7] = nv->bus[1].retry_delay;
2249 status |= qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_2 |
2250 BIT_1 | BIT_0, &mb[0]);
2251
2252
2253 mb[0] = MBC_SET_ASYNC_DATA_SETUP;
2254 mb[1] = nv->bus[0].config_2.async_data_setup_time;
2255 mb[2] = nv->bus[1].config_2.async_data_setup_time;
2256 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2257
2258
2259 mb[0] = MBC_SET_ACTIVE_NEGATION;
2260 mb[1] = 0;
2261 if (nv->bus[0].config_2.req_ack_active_negation)
2262 mb[1] |= BIT_5;
2263 if (nv->bus[0].config_2.data_line_active_negation)
2264 mb[1] |= BIT_4;
2265 mb[2] = 0;
2266 if (nv->bus[1].config_2.req_ack_active_negation)
2267 mb[2] |= BIT_5;
2268 if (nv->bus[1].config_2.data_line_active_negation)
2269 mb[2] |= BIT_4;
2270 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
2271
2272 mb[0] = MBC_SET_DATA_OVERRUN_RECOVERY;
2273 mb[1] = 2;
2274 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2275
2276
2277 mb[0] = MBC_SET_PCI_CONTROL;
2278 mb[1] = BIT_1;
2279 mb[2] = BIT_1;
2280 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
2281
2282 mb[0] = MBC_SET_TAG_AGE_LIMIT;
2283 mb[1] = 8;
2284 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2285
2286
2287 mb[0] = MBC_SET_SELECTION_TIMEOUT;
2288 mb[1] = nv->bus[0].selection_timeout;
2289 mb[2] = nv->bus[1].selection_timeout;
2290 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
2291
2292 for (bus = 0; bus < ha->ports; bus++)
2293 status |= qla1280_config_bus(ha, bus);
2294
2295 if (status)
2296 dprintk(2, "qla1280_nvram_config: **** FAILED ****\n");
2297
2298 LEAVE("qla1280_nvram_config");
2299 return status;
2300}
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314static uint16_t
2315qla1280_get_nvram_word(struct scsi_qla_host *ha, uint32_t address)
2316{
2317 uint32_t nv_cmd;
2318 uint16_t data;
2319
2320 nv_cmd = address << 16;
2321 nv_cmd |= NV_READ_OP;
2322
2323 data = le16_to_cpu(qla1280_nvram_request(ha, nv_cmd));
2324
2325 dprintk(8, "qla1280_get_nvram_word: exiting normally NVRAM data = "
2326 "0x%x", data);
2327
2328 return data;
2329}
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345static uint16_t
2346qla1280_nvram_request(struct scsi_qla_host *ha, uint32_t nv_cmd)
2347{
2348 struct device_reg __iomem *reg = ha->iobase;
2349 int cnt;
2350 uint16_t data = 0;
2351 uint16_t reg_data;
2352
2353
2354
2355 nv_cmd <<= 5;
2356 for (cnt = 0; cnt < 11; cnt++) {
2357 if (nv_cmd & BIT_31)
2358 qla1280_nv_write(ha, NV_DATA_OUT);
2359 else
2360 qla1280_nv_write(ha, 0);
2361 nv_cmd <<= 1;
2362 }
2363
2364
2365
2366 for (cnt = 0; cnt < 16; cnt++) {
2367 WRT_REG_WORD(®->nvram, (NV_SELECT | NV_CLOCK));
2368 RD_REG_WORD(®->id_l);
2369 NVRAM_DELAY();
2370 data <<= 1;
2371 reg_data = RD_REG_WORD(®->nvram);
2372 if (reg_data & NV_DATA_IN)
2373 data |= BIT_0;
2374 WRT_REG_WORD(®->nvram, NV_SELECT);
2375 RD_REG_WORD(®->id_l);
2376 NVRAM_DELAY();
2377 }
2378
2379
2380
2381 WRT_REG_WORD(®->nvram, NV_DESELECT);
2382 RD_REG_WORD(®->id_l);
2383 NVRAM_DELAY();
2384
2385 return data;
2386}
2387
2388static void
2389qla1280_nv_write(struct scsi_qla_host *ha, uint16_t data)
2390{
2391 struct device_reg __iomem *reg = ha->iobase;
2392
2393 WRT_REG_WORD(®->nvram, data | NV_SELECT);
2394 RD_REG_WORD(®->id_l);
2395 NVRAM_DELAY();
2396 WRT_REG_WORD(®->nvram, data | NV_SELECT | NV_CLOCK);
2397 RD_REG_WORD(®->id_l);
2398 NVRAM_DELAY();
2399 WRT_REG_WORD(®->nvram, data | NV_SELECT);
2400 RD_REG_WORD(®->id_l);
2401 NVRAM_DELAY();
2402}
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419static int
2420qla1280_mailbox_command(struct scsi_qla_host *ha, uint8_t mr, uint16_t *mb)
2421{
2422 struct device_reg __iomem *reg = ha->iobase;
2423 int status = 0;
2424 int cnt;
2425 uint16_t *optr, *iptr;
2426 uint16_t __iomem *mptr;
2427 DECLARE_COMPLETION_ONSTACK(wait);
2428
2429 ENTER("qla1280_mailbox_command");
2430
2431 if (ha->mailbox_wait) {
2432 printk(KERN_ERR "Warning mailbox wait already in use!\n");
2433 }
2434 ha->mailbox_wait = &wait;
2435
2436
2437
2438
2439
2440
2441 mptr = (uint16_t __iomem *) ®->mailbox0;
2442 iptr = mb;
2443 for (cnt = 0; cnt < MAILBOX_REGISTER_COUNT; cnt++) {
2444 if (mr & BIT_0) {
2445 WRT_REG_WORD(mptr, (*iptr));
2446 }
2447
2448 mr >>= 1;
2449 mptr++;
2450 iptr++;
2451 }
2452
2453
2454
2455
2456 timer_setup(&ha->mailbox_timer, qla1280_mailbox_timeout, 0);
2457 mod_timer(&ha->mailbox_timer, jiffies + 20 * HZ);
2458
2459 spin_unlock_irq(ha->host->host_lock);
2460 WRT_REG_WORD(®->host_cmd, HC_SET_HOST_INT);
2461 qla1280_debounce_register(®->istatus);
2462
2463 wait_for_completion(&wait);
2464 del_timer_sync(&ha->mailbox_timer);
2465
2466 spin_lock_irq(ha->host->host_lock);
2467
2468 ha->mailbox_wait = NULL;
2469
2470
2471 if (ha->mailbox_out[0] != MBS_CMD_CMP) {
2472 printk(KERN_WARNING "qla1280_mailbox_command: Command failed, "
2473 "mailbox0 = 0x%04x, mailbox_out0 = 0x%04x, istatus = "
2474 "0x%04x\n",
2475 mb[0], ha->mailbox_out[0], RD_REG_WORD(®->istatus));
2476 printk(KERN_WARNING "m0 %04x, m1 %04x, m2 %04x, m3 %04x\n",
2477 RD_REG_WORD(®->mailbox0), RD_REG_WORD(®->mailbox1),
2478 RD_REG_WORD(®->mailbox2), RD_REG_WORD(®->mailbox3));
2479 printk(KERN_WARNING "m4 %04x, m5 %04x, m6 %04x, m7 %04x\n",
2480 RD_REG_WORD(®->mailbox4), RD_REG_WORD(®->mailbox5),
2481 RD_REG_WORD(®->mailbox6), RD_REG_WORD(®->mailbox7));
2482 status = 1;
2483 }
2484
2485
2486 optr = mb;
2487 iptr = (uint16_t *) &ha->mailbox_out[0];
2488 mr = MAILBOX_REGISTER_COUNT;
2489 memcpy(optr, iptr, MAILBOX_REGISTER_COUNT * sizeof(uint16_t));
2490
2491 if (ha->flags.reset_marker)
2492 qla1280_rst_aen(ha);
2493
2494 if (status)
2495 dprintk(2, "qla1280_mailbox_command: **** FAILED, mailbox0 = "
2496 "0x%x ****\n", mb[0]);
2497
2498 LEAVE("qla1280_mailbox_command");
2499 return status;
2500}
2501
2502
2503
2504
2505
2506
2507
2508
2509static void
2510qla1280_poll(struct scsi_qla_host *ha)
2511{
2512 struct device_reg __iomem *reg = ha->iobase;
2513 uint16_t data;
2514 LIST_HEAD(done_q);
2515
2516
2517
2518
2519 data = RD_REG_WORD(®->istatus);
2520 if (data & RISC_INT)
2521 qla1280_isr(ha, &done_q);
2522
2523 if (!ha->mailbox_wait) {
2524 if (ha->flags.reset_marker)
2525 qla1280_rst_aen(ha);
2526 }
2527
2528 if (!list_empty(&done_q))
2529 qla1280_done(ha);
2530
2531
2532}
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545static int
2546qla1280_bus_reset(struct scsi_qla_host *ha, int bus)
2547{
2548 uint16_t mb[MAILBOX_REGISTER_COUNT];
2549 uint16_t reset_delay;
2550 int status;
2551
2552 dprintk(3, "qla1280_bus_reset: entered\n");
2553
2554 if (qla1280_verbose)
2555 printk(KERN_INFO "scsi(%li:%i): Resetting SCSI BUS\n",
2556 ha->host_no, bus);
2557
2558 reset_delay = ha->bus_settings[bus].bus_reset_delay;
2559 mb[0] = MBC_BUS_RESET;
2560 mb[1] = reset_delay;
2561 mb[2] = (uint16_t) bus;
2562 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2563
2564 if (status) {
2565 if (ha->bus_settings[bus].failed_reset_count > 2)
2566 ha->bus_settings[bus].scsi_bus_dead = 1;
2567 ha->bus_settings[bus].failed_reset_count++;
2568 } else {
2569 spin_unlock_irq(ha->host->host_lock);
2570 ssleep(reset_delay);
2571 spin_lock_irq(ha->host->host_lock);
2572
2573 ha->bus_settings[bus].scsi_bus_dead = 0;
2574 ha->bus_settings[bus].failed_reset_count = 0;
2575 ha->bus_settings[bus].reset_marker = 0;
2576
2577 qla1280_marker(ha, bus, 0, 0, MK_SYNC_ALL);
2578 }
2579
2580
2581
2582
2583
2584
2585 if (status)
2586 dprintk(2, "qla1280_bus_reset: **** FAILED ****\n");
2587 else
2588 dprintk(3, "qla1280_bus_reset: exiting normally\n");
2589
2590 return status;
2591}
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605static int
2606qla1280_device_reset(struct scsi_qla_host *ha, int bus, int target)
2607{
2608 uint16_t mb[MAILBOX_REGISTER_COUNT];
2609 int status;
2610
2611 ENTER("qla1280_device_reset");
2612
2613 mb[0] = MBC_ABORT_TARGET;
2614 mb[1] = (bus ? (target | BIT_7) : target) << 8;
2615 mb[2] = 1;
2616 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2617
2618
2619 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
2620
2621 if (status)
2622 dprintk(2, "qla1280_device_reset: **** FAILED ****\n");
2623
2624 LEAVE("qla1280_device_reset");
2625 return status;
2626}
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639static int
2640qla1280_abort_command(struct scsi_qla_host *ha, struct srb * sp, int handle)
2641{
2642 uint16_t mb[MAILBOX_REGISTER_COUNT];
2643 unsigned int bus, target, lun;
2644 int status;
2645
2646 ENTER("qla1280_abort_command");
2647
2648 bus = SCSI_BUS_32(sp->cmd);
2649 target = SCSI_TCN_32(sp->cmd);
2650 lun = SCSI_LUN_32(sp->cmd);
2651
2652 sp->flags |= SRB_ABORT_PENDING;
2653
2654 mb[0] = MBC_ABORT_COMMAND;
2655 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
2656 mb[2] = handle >> 16;
2657 mb[3] = handle & 0xffff;
2658 status = qla1280_mailbox_command(ha, 0x0f, &mb[0]);
2659
2660 if (status) {
2661 dprintk(2, "qla1280_abort_command: **** FAILED ****\n");
2662 sp->flags &= ~SRB_ABORT_PENDING;
2663 }
2664
2665
2666 LEAVE("qla1280_abort_command");
2667 return status;
2668}
2669
2670
2671
2672
2673
2674
2675
2676
2677static void
2678qla1280_reset_adapter(struct scsi_qla_host *ha)
2679{
2680 struct device_reg __iomem *reg = ha->iobase;
2681
2682 ENTER("qla1280_reset_adapter");
2683
2684
2685 ha->flags.online = 0;
2686 WRT_REG_WORD(®->ictrl, ISP_RESET);
2687 WRT_REG_WORD(®->host_cmd,
2688 HC_RESET_RISC | HC_RELEASE_RISC | HC_DISABLE_BIOS);
2689 RD_REG_WORD(®->id_l);
2690
2691 LEAVE("qla1280_reset_adapter");
2692}
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705static void
2706qla1280_marker(struct scsi_qla_host *ha, int bus, int id, int lun, u8 type)
2707{
2708 struct mrk_entry *pkt;
2709
2710 ENTER("qla1280_marker");
2711
2712
2713 if ((pkt = (struct mrk_entry *) qla1280_req_pkt(ha))) {
2714 pkt->entry_type = MARKER_TYPE;
2715 pkt->lun = (uint8_t) lun;
2716 pkt->target = (uint8_t) (bus ? (id | BIT_7) : id);
2717 pkt->modifier = type;
2718 pkt->entry_status = 0;
2719
2720
2721 qla1280_isp_cmd(ha);
2722 }
2723
2724 LEAVE("qla1280_marker");
2725}
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740#ifdef QLA_64BIT_PTR
2741static int
2742qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
2743{
2744 struct device_reg __iomem *reg = ha->iobase;
2745 struct scsi_cmnd *cmd = sp->cmd;
2746 cmd_a64_entry_t *pkt;
2747 __le32 *dword_ptr;
2748 dma_addr_t dma_handle;
2749 int status = 0;
2750 int cnt;
2751 int req_cnt;
2752 int seg_cnt;
2753 u8 dir;
2754
2755 ENTER("qla1280_64bit_start_scsi:");
2756
2757
2758 req_cnt = 1;
2759 seg_cnt = scsi_dma_map(cmd);
2760 if (seg_cnt > 0) {
2761 if (seg_cnt > 2) {
2762 req_cnt += (seg_cnt - 2) / 5;
2763 if ((seg_cnt - 2) % 5)
2764 req_cnt++;
2765 }
2766 } else if (seg_cnt < 0) {
2767 status = 1;
2768 goto out;
2769 }
2770
2771 if ((req_cnt + 2) >= ha->req_q_cnt) {
2772
2773 cnt = RD_REG_WORD(®->mailbox4);
2774 if (ha->req_ring_index < cnt)
2775 ha->req_q_cnt = cnt - ha->req_ring_index;
2776 else
2777 ha->req_q_cnt =
2778 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
2779 }
2780
2781 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
2782 ha->req_q_cnt, seg_cnt);
2783
2784
2785 if ((req_cnt + 2) >= ha->req_q_cnt) {
2786 status = SCSI_MLQUEUE_HOST_BUSY;
2787 dprintk(2, "qla1280_start_scsi: in-ptr=0x%x req_q_cnt="
2788 "0x%xreq_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt,
2789 req_cnt);
2790 goto out;
2791 }
2792
2793
2794 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
2795 ha->outstanding_cmds[cnt] != NULL; cnt++);
2796
2797 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
2798 status = SCSI_MLQUEUE_HOST_BUSY;
2799 dprintk(2, "qla1280_start_scsi: NO ROOM IN "
2800 "OUTSTANDING ARRAY, req_q_cnt=0x%x", ha->req_q_cnt);
2801 goto out;
2802 }
2803
2804 ha->outstanding_cmds[cnt] = sp;
2805 ha->req_q_cnt -= req_cnt;
2806 CMD_HANDLE(sp->cmd) = (unsigned char *)(unsigned long)(cnt + 1);
2807
2808 dprintk(2, "start: cmd=%p sp=%p CDB=%xm, handle %lx\n", cmd, sp,
2809 cmd->cmnd[0], (long)CMD_HANDLE(sp->cmd));
2810 dprintk(2, " bus %i, target %i, lun %i\n",
2811 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
2812 qla1280_dump_buffer(2, cmd->cmnd, MAX_COMMAND_SIZE);
2813
2814
2815
2816
2817 pkt = (cmd_a64_entry_t *) ha->request_ring_ptr;
2818
2819 pkt->entry_type = COMMAND_A64_TYPE;
2820 pkt->entry_count = (uint8_t) req_cnt;
2821 pkt->sys_define = (uint8_t) ha->req_ring_index;
2822 pkt->entry_status = 0;
2823 pkt->handle = cpu_to_le32(cnt);
2824
2825
2826 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
2827
2828
2829 pkt->timeout = cpu_to_le16(scsi_cmd_to_rq(cmd)->timeout / HZ);
2830
2831
2832 pkt->lun = SCSI_LUN_32(cmd);
2833 pkt->target = SCSI_BUS_32(cmd) ?
2834 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
2835
2836
2837 if (cmd->device->simple_tags)
2838 pkt->control_flags |= cpu_to_le16(BIT_3);
2839
2840
2841 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
2842 memcpy(pkt->scsi_cdb, CMD_CDBP(cmd), CMD_CDBLEN(cmd));
2843
2844
2845
2846 dir = qla1280_data_direction(cmd);
2847 pkt->control_flags |= cpu_to_le16(dir);
2848
2849
2850 pkt->dseg_count = cpu_to_le16(seg_cnt);
2851
2852
2853
2854
2855 if (seg_cnt) {
2856 struct scatterlist *sg, *s;
2857 int remseg = seg_cnt;
2858
2859 sg = scsi_sglist(cmd);
2860
2861
2862 dword_ptr = (u32 *)&pkt->dseg_0_address;
2863
2864
2865 for_each_sg(sg, s, seg_cnt, cnt) {
2866 if (cnt == 2)
2867 break;
2868
2869 dma_handle = sg_dma_address(s);
2870 *dword_ptr++ =
2871 cpu_to_le32(lower_32_bits(dma_handle));
2872 *dword_ptr++ =
2873 cpu_to_le32(upper_32_bits(dma_handle));
2874 *dword_ptr++ = cpu_to_le32(sg_dma_len(s));
2875 dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
2876 cpu_to_le32(upper_32_bits(dma_handle)),
2877 cpu_to_le32(lower_32_bits(dma_handle)),
2878 cpu_to_le32(sg_dma_len(sg_next(s))));
2879 remseg--;
2880 }
2881 dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather "
2882 "command packet data - b %i, t %i, l %i \n",
2883 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
2884 SCSI_LUN_32(cmd));
2885 qla1280_dump_buffer(5, (char *)pkt,
2886 REQUEST_ENTRY_SIZE);
2887
2888
2889
2890
2891 dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
2892 "remains\n", seg_cnt);
2893
2894 while (remseg > 0) {
2895
2896 sg = s;
2897
2898 ha->req_ring_index++;
2899 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
2900 ha->req_ring_index = 0;
2901 ha->request_ring_ptr =
2902 ha->request_ring;
2903 } else
2904 ha->request_ring_ptr++;
2905
2906 pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
2907
2908
2909 memset(pkt, 0, REQUEST_ENTRY_SIZE);
2910
2911
2912 ((struct cont_a64_entry *) pkt)->entry_type =
2913 CONTINUE_A64_TYPE;
2914 ((struct cont_a64_entry *) pkt)->entry_count = 1;
2915 ((struct cont_a64_entry *) pkt)->sys_define =
2916 (uint8_t)ha->req_ring_index;
2917
2918 dword_ptr =
2919 (u32 *)&((struct cont_a64_entry *) pkt)->dseg_0_address;
2920
2921
2922 for_each_sg(sg, s, remseg, cnt) {
2923 if (cnt == 5)
2924 break;
2925 dma_handle = sg_dma_address(s);
2926 *dword_ptr++ =
2927 cpu_to_le32(lower_32_bits(dma_handle));
2928 *dword_ptr++ =
2929 cpu_to_le32(upper_32_bits(dma_handle));
2930 *dword_ptr++ =
2931 cpu_to_le32(sg_dma_len(s));
2932 dprintk(3, "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
2933 cpu_to_le32(upper_32_bits(dma_handle)),
2934 cpu_to_le32(lower_32_bits(dma_handle)),
2935 cpu_to_le32(sg_dma_len(s)));
2936 }
2937 remseg -= cnt;
2938 dprintk(5, "qla1280_64bit_start_scsi: "
2939 "continuation packet data - b %i, t "
2940 "%i, l %i \n", SCSI_BUS_32(cmd),
2941 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
2942 qla1280_dump_buffer(5, (char *)pkt,
2943 REQUEST_ENTRY_SIZE);
2944 }
2945 } else {
2946 dprintk(5, "qla1280_64bit_start_scsi: No data, command "
2947 "packet data - b %i, t %i, l %i \n",
2948 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
2949 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
2950 }
2951
2952 ha->req_ring_index++;
2953 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
2954 ha->req_ring_index = 0;
2955 ha->request_ring_ptr = ha->request_ring;
2956 } else
2957 ha->request_ring_ptr++;
2958
2959
2960 dprintk(2,
2961 "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
2962 sp->flags |= SRB_SENT;
2963 ha->actthreads++;
2964 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
2965
2966 out:
2967 if (status)
2968 dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
2969 else
2970 dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
2971
2972 return status;
2973}
2974#else
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995static int
2996qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
2997{
2998 struct device_reg __iomem *reg = ha->iobase;
2999 struct scsi_cmnd *cmd = sp->cmd;
3000 struct cmd_entry *pkt;
3001 __le32 *dword_ptr;
3002 int status = 0;
3003 int cnt;
3004 int req_cnt;
3005 int seg_cnt;
3006 u8 dir;
3007
3008 ENTER("qla1280_32bit_start_scsi");
3009
3010 dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd, sp,
3011 cmd->cmnd[0]);
3012
3013
3014 req_cnt = 1;
3015 seg_cnt = scsi_dma_map(cmd);
3016 if (seg_cnt) {
3017
3018
3019
3020
3021 if (seg_cnt > 4) {
3022 req_cnt += (seg_cnt - 4) / 7;
3023 if ((seg_cnt - 4) % 7)
3024 req_cnt++;
3025 }
3026 dprintk(3, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
3027 cmd, seg_cnt, req_cnt);
3028 } else if (seg_cnt < 0) {
3029 status = 1;
3030 goto out;
3031 }
3032
3033 if ((req_cnt + 2) >= ha->req_q_cnt) {
3034
3035 cnt = RD_REG_WORD(®->mailbox4);
3036 if (ha->req_ring_index < cnt)
3037 ha->req_q_cnt = cnt - ha->req_ring_index;
3038 else
3039 ha->req_q_cnt =
3040 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3041 }
3042
3043 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
3044 ha->req_q_cnt, seg_cnt);
3045
3046 if ((req_cnt + 2) >= ha->req_q_cnt) {
3047 status = SCSI_MLQUEUE_HOST_BUSY;
3048 dprintk(2, "qla1280_32bit_start_scsi: in-ptr=0x%x, "
3049 "req_q_cnt=0x%x, req_cnt=0x%x", ha->req_ring_index,
3050 ha->req_q_cnt, req_cnt);
3051 goto out;
3052 }
3053
3054
3055 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
3056 ha->outstanding_cmds[cnt]; cnt++);
3057
3058 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
3059 status = SCSI_MLQUEUE_HOST_BUSY;
3060 dprintk(2, "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
3061 "ARRAY, req_q_cnt=0x%x\n", ha->req_q_cnt);
3062 goto out;
3063 }
3064
3065 CMD_HANDLE(sp->cmd) = (unsigned char *) (unsigned long)(cnt + 1);
3066 ha->outstanding_cmds[cnt] = sp;
3067 ha->req_q_cnt -= req_cnt;
3068
3069
3070
3071
3072 pkt = (struct cmd_entry *) ha->request_ring_ptr;
3073
3074 pkt->entry_type = COMMAND_TYPE;
3075 pkt->entry_count = (uint8_t) req_cnt;
3076 pkt->sys_define = (uint8_t) ha->req_ring_index;
3077 pkt->entry_status = 0;
3078 pkt->handle = cpu_to_le32(cnt);
3079
3080
3081 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
3082
3083
3084 pkt->timeout = cpu_to_le16(scsi_cmd_to_rq(cmd)->timeout / HZ);
3085
3086
3087 pkt->lun = SCSI_LUN_32(cmd);
3088 pkt->target = SCSI_BUS_32(cmd) ?
3089 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3090
3091
3092 if (cmd->device->simple_tags)
3093 pkt->control_flags |= cpu_to_le16(BIT_3);
3094
3095
3096 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
3097 memcpy(pkt->scsi_cdb, CMD_CDBP(cmd), CMD_CDBLEN(cmd));
3098
3099
3100
3101 dir = qla1280_data_direction(cmd);
3102 pkt->control_flags |= cpu_to_le16(dir);
3103
3104
3105 pkt->dseg_count = cpu_to_le16(seg_cnt);
3106
3107
3108
3109
3110 if (seg_cnt) {
3111 struct scatterlist *sg, *s;
3112 int remseg = seg_cnt;
3113
3114 sg = scsi_sglist(cmd);
3115
3116
3117 dword_ptr = &pkt->dseg_0_address;
3118
3119 dprintk(3, "Building S/G data segments..\n");
3120 qla1280_dump_buffer(1, (char *)sg, 4 * 16);
3121
3122
3123 for_each_sg(sg, s, seg_cnt, cnt) {
3124 if (cnt == 4)
3125 break;
3126 *dword_ptr++ =
3127 cpu_to_le32(lower_32_bits(sg_dma_address(s)));
3128 *dword_ptr++ = cpu_to_le32(sg_dma_len(s));
3129 dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n",
3130 (lower_32_bits(sg_dma_address(s))),
3131 (sg_dma_len(s)));
3132 remseg--;
3133 }
3134
3135
3136
3137 dprintk(3, "S/G Building Continuation"
3138 "...seg_cnt=0x%x remains\n", seg_cnt);
3139 while (remseg > 0) {
3140
3141 sg = s;
3142
3143 ha->req_ring_index++;
3144 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3145 ha->req_ring_index = 0;
3146 ha->request_ring_ptr =
3147 ha->request_ring;
3148 } else
3149 ha->request_ring_ptr++;
3150
3151 pkt = (struct cmd_entry *)ha->request_ring_ptr;
3152
3153
3154 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3155
3156
3157 ((struct cont_entry *) pkt)->
3158 entry_type = CONTINUE_TYPE;
3159 ((struct cont_entry *) pkt)->entry_count = 1;
3160
3161 ((struct cont_entry *) pkt)->sys_define =
3162 (uint8_t) ha->req_ring_index;
3163
3164
3165 dword_ptr =
3166 &((struct cont_entry *) pkt)->dseg_0_address;
3167
3168
3169 for_each_sg(sg, s, remseg, cnt) {
3170 if (cnt == 7)
3171 break;
3172 *dword_ptr++ =
3173 cpu_to_le32(lower_32_bits(sg_dma_address(s)));
3174 *dword_ptr++ =
3175 cpu_to_le32(sg_dma_len(s));
3176 dprintk(1,
3177 "S/G Segment Cont. phys_addr=0x%x, "
3178 "len=0x%x\n",
3179 cpu_to_le32(lower_32_bits(sg_dma_address(s))),
3180 cpu_to_le32(sg_dma_len(s)));
3181 }
3182 remseg -= cnt;
3183 dprintk(5, "qla1280_32bit_start_scsi: "
3184 "continuation packet data - "
3185 "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd),
3186 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3187 qla1280_dump_buffer(5, (char *)pkt,
3188 REQUEST_ENTRY_SIZE);
3189 }
3190 } else {
3191 dprintk(5, "qla1280_32bit_start_scsi: No data, command "
3192 "packet data - \n");
3193 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
3194 }
3195 dprintk(5, "qla1280_32bit_start_scsi: First IOCB block:\n");
3196 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3197 REQUEST_ENTRY_SIZE);
3198
3199
3200 ha->req_ring_index++;
3201 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3202 ha->req_ring_index = 0;
3203 ha->request_ring_ptr = ha->request_ring;
3204 } else
3205 ha->request_ring_ptr++;
3206
3207
3208 dprintk(2, "qla1280_32bit_start_scsi: Wakeup RISC "
3209 "for pending command\n");
3210 sp->flags |= SRB_SENT;
3211 ha->actthreads++;
3212 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3213
3214out:
3215 if (status)
3216 dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
3217
3218 LEAVE("qla1280_32bit_start_scsi");
3219
3220 return status;
3221}
3222#endif
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235static request_t *
3236qla1280_req_pkt(struct scsi_qla_host *ha)
3237{
3238 struct device_reg __iomem *reg = ha->iobase;
3239 request_t *pkt = NULL;
3240 int cnt;
3241 uint32_t timer;
3242
3243 ENTER("qla1280_req_pkt");
3244
3245
3246
3247
3248
3249 for (timer = 15000000; timer; timer--) {
3250 if (ha->req_q_cnt > 0) {
3251
3252 cnt = RD_REG_WORD(®->mailbox4);
3253 if (ha->req_ring_index < cnt)
3254 ha->req_q_cnt = cnt - ha->req_ring_index;
3255 else
3256 ha->req_q_cnt =
3257 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3258 }
3259
3260
3261 if (ha->req_q_cnt > 0) {
3262 ha->req_q_cnt--;
3263 pkt = ha->request_ring_ptr;
3264
3265
3266 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3267
3268
3269
3270
3271
3272
3273 pkt->sys_define = (uint8_t) ha->req_ring_index;
3274
3275
3276 pkt->entry_count = 1;
3277
3278 break;
3279 }
3280
3281 udelay(2);
3282
3283
3284 qla1280_poll(ha);
3285 }
3286
3287 if (!pkt)
3288 dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
3289 else
3290 dprintk(3, "qla1280_req_pkt: exiting normally\n");
3291
3292 return pkt;
3293}
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303static void
3304qla1280_isp_cmd(struct scsi_qla_host *ha)
3305{
3306 struct device_reg __iomem *reg = ha->iobase;
3307
3308 ENTER("qla1280_isp_cmd");
3309
3310 dprintk(5, "qla1280_isp_cmd: IOCB data:\n");
3311 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3312 REQUEST_ENTRY_SIZE);
3313
3314
3315 ha->req_ring_index++;
3316 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3317 ha->req_ring_index = 0;
3318 ha->request_ring_ptr = ha->request_ring;
3319 } else
3320 ha->request_ring_ptr++;
3321
3322
3323
3324
3325 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3326
3327 LEAVE("qla1280_isp_cmd");
3328}
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342static void
3343qla1280_isr(struct scsi_qla_host *ha, struct list_head *done_q)
3344{
3345 struct device_reg __iomem *reg = ha->iobase;
3346 struct response *pkt;
3347 struct srb *sp = NULL;
3348 uint16_t mailbox[MAILBOX_REGISTER_COUNT];
3349 uint16_t *wptr;
3350 uint32_t index;
3351 u16 istatus;
3352
3353 ENTER("qla1280_isr");
3354
3355 istatus = RD_REG_WORD(®->istatus);
3356 if (!(istatus & (RISC_INT | PCI_INT)))
3357 return;
3358
3359
3360 mailbox[5] = RD_REG_WORD(®->mailbox5);
3361
3362
3363
3364 mailbox[0] = RD_REG_WORD_dmasync(®->semaphore);
3365
3366 if (mailbox[0] & BIT_0) {
3367
3368
3369
3370 wptr = &mailbox[0];
3371 *wptr++ = RD_REG_WORD(®->mailbox0);
3372 *wptr++ = RD_REG_WORD(®->mailbox1);
3373 *wptr = RD_REG_WORD(®->mailbox2);
3374 if (mailbox[0] != MBA_SCSI_COMPLETION) {
3375 wptr++;
3376 *wptr++ = RD_REG_WORD(®->mailbox3);
3377 *wptr++ = RD_REG_WORD(®->mailbox4);
3378 wptr++;
3379 *wptr++ = RD_REG_WORD(®->mailbox6);
3380 *wptr = RD_REG_WORD(®->mailbox7);
3381 }
3382
3383
3384
3385 WRT_REG_WORD(®->semaphore, 0);
3386 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
3387
3388 dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
3389 mailbox[0]);
3390
3391
3392 switch (mailbox[0]) {
3393 case MBA_SCSI_COMPLETION:
3394 dprintk(5, "qla1280_isr: mailbox SCSI response "
3395 "completion\n");
3396
3397 if (ha->flags.online) {
3398
3399 index = mailbox[2] << 16 | mailbox[1];
3400
3401
3402 if (index < MAX_OUTSTANDING_COMMANDS)
3403 sp = ha->outstanding_cmds[index];
3404 else
3405 sp = NULL;
3406
3407 if (sp) {
3408
3409 ha->outstanding_cmds[index] = NULL;
3410
3411
3412 CMD_RESULT(sp->cmd) = 0;
3413 CMD_HANDLE(sp->cmd) = COMPLETED_HANDLE;
3414
3415
3416 list_add_tail(&sp->list, done_q);
3417 } else {
3418
3419
3420
3421 printk(KERN_WARNING
3422 "qla1280: ISP invalid handle\n");
3423 }
3424 }
3425 break;
3426
3427 case MBA_BUS_RESET:
3428 ha->flags.reset_marker = 1;
3429 index = mailbox[6] & BIT_0;
3430 ha->bus_settings[index].reset_marker = 1;
3431
3432 printk(KERN_DEBUG "qla1280_isr(): index %i "
3433 "asynchronous BUS_RESET\n", index);
3434 break;
3435
3436 case MBA_SYSTEM_ERR:
3437 printk(KERN_WARNING
3438 "qla1280: ISP System Error - mbx1=%xh, mbx2="
3439 "%xh, mbx3=%xh\n", mailbox[1], mailbox[2],
3440 mailbox[3]);
3441 break;
3442
3443 case MBA_REQ_TRANSFER_ERR:
3444 printk(KERN_WARNING
3445 "qla1280: ISP Request Transfer Error\n");
3446 break;
3447
3448 case MBA_RSP_TRANSFER_ERR:
3449 printk(KERN_WARNING
3450 "qla1280: ISP Response Transfer Error\n");
3451 break;
3452
3453 case MBA_WAKEUP_THRES:
3454 dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
3455 break;
3456
3457 case MBA_TIMEOUT_RESET:
3458 dprintk(2,
3459 "qla1280_isr: asynchronous TIMEOUT_RESET\n");
3460 break;
3461
3462 case MBA_DEVICE_RESET:
3463 printk(KERN_INFO "qla1280_isr(): asynchronous "
3464 "BUS_DEVICE_RESET\n");
3465
3466 ha->flags.reset_marker = 1;
3467 index = mailbox[6] & BIT_0;
3468 ha->bus_settings[index].reset_marker = 1;
3469 break;
3470
3471 case MBA_BUS_MODE_CHANGE:
3472 dprintk(2,
3473 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
3474 break;
3475
3476 default:
3477
3478 if (mailbox[0] < MBA_ASYNC_EVENT) {
3479 wptr = &mailbox[0];
3480 memcpy((uint16_t *) ha->mailbox_out, wptr,
3481 MAILBOX_REGISTER_COUNT *
3482 sizeof(uint16_t));
3483
3484 if(ha->mailbox_wait != NULL)
3485 complete(ha->mailbox_wait);
3486 }
3487 break;
3488 }
3489 } else {
3490 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
3491 }
3492
3493
3494
3495
3496
3497 if (!(ha->flags.online && !ha->mailbox_wait)) {
3498 dprintk(2, "qla1280_isr: Response pointer Error\n");
3499 goto out;
3500 }
3501
3502 if (mailbox[5] >= RESPONSE_ENTRY_CNT)
3503 goto out;
3504
3505 while (ha->rsp_ring_index != mailbox[5]) {
3506 pkt = ha->response_ring_ptr;
3507
3508 dprintk(5, "qla1280_isr: ha->rsp_ring_index = 0x%x, mailbox[5]"
3509 " = 0x%x\n", ha->rsp_ring_index, mailbox[5]);
3510 dprintk(5,"qla1280_isr: response packet data\n");
3511 qla1280_dump_buffer(5, (char *)pkt, RESPONSE_ENTRY_SIZE);
3512
3513 if (pkt->entry_type == STATUS_TYPE) {
3514 if ((le16_to_cpu(pkt->scsi_status) & 0xff)
3515 || pkt->comp_status || pkt->entry_status) {
3516 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3517 "0x%x mailbox[5] = 0x%x, comp_status "
3518 "= 0x%x, scsi_status = 0x%x\n",
3519 ha->rsp_ring_index, mailbox[5],
3520 le16_to_cpu(pkt->comp_status),
3521 le16_to_cpu(pkt->scsi_status));
3522 }
3523 } else {
3524 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3525 "0x%x, mailbox[5] = 0x%x\n",
3526 ha->rsp_ring_index, mailbox[5]);
3527 dprintk(2, "qla1280_isr: response packet data\n");
3528 qla1280_dump_buffer(2, (char *)pkt,
3529 RESPONSE_ENTRY_SIZE);
3530 }
3531
3532 if (pkt->entry_type == STATUS_TYPE || pkt->entry_status) {
3533 dprintk(2, "status: Cmd %p, handle %i\n",
3534 ha->outstanding_cmds[pkt->handle]->cmd,
3535 pkt->handle);
3536 if (pkt->entry_type == STATUS_TYPE)
3537 qla1280_status_entry(ha, pkt, done_q);
3538 else
3539 qla1280_error_entry(ha, pkt, done_q);
3540
3541 ha->rsp_ring_index++;
3542 if (ha->rsp_ring_index == RESPONSE_ENTRY_CNT) {
3543 ha->rsp_ring_index = 0;
3544 ha->response_ring_ptr = ha->response_ring;
3545 } else
3546 ha->response_ring_ptr++;
3547 WRT_REG_WORD(®->mailbox5, ha->rsp_ring_index);
3548 }
3549 }
3550
3551 out:
3552 LEAVE("qla1280_isr");
3553}
3554
3555
3556
3557
3558
3559
3560
3561
3562static void
3563qla1280_rst_aen(struct scsi_qla_host *ha)
3564{
3565 uint8_t bus;
3566
3567 ENTER("qla1280_rst_aen");
3568
3569 if (ha->flags.online && !ha->flags.reset_active &&
3570 !ha->flags.abort_isp_active) {
3571 ha->flags.reset_active = 1;
3572 while (ha->flags.reset_marker) {
3573
3574 ha->flags.reset_marker = 0;
3575 for (bus = 0; bus < ha->ports &&
3576 !ha->flags.reset_marker; bus++) {
3577 if (ha->bus_settings[bus].reset_marker) {
3578 ha->bus_settings[bus].reset_marker = 0;
3579 qla1280_marker(ha, bus, 0, 0,
3580 MK_SYNC_ALL);
3581 }
3582 }
3583 }
3584 }
3585
3586 LEAVE("qla1280_rst_aen");
3587}
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599static void
3600qla1280_status_entry(struct scsi_qla_host *ha, struct response *pkt,
3601 struct list_head *done_q)
3602{
3603 int sense_sz;
3604 struct srb *sp;
3605 struct scsi_cmnd *cmd;
3606 uint32_t handle = le32_to_cpu(pkt->handle);
3607 uint16_t scsi_status = le16_to_cpu(pkt->scsi_status);
3608 uint16_t comp_status = le16_to_cpu(pkt->comp_status);
3609
3610 ENTER("qla1280_status_entry");
3611
3612
3613 if (handle < MAX_OUTSTANDING_COMMANDS)
3614 sp = ha->outstanding_cmds[handle];
3615 else
3616 sp = NULL;
3617
3618 if (!sp) {
3619 printk(KERN_WARNING "qla1280: Status Entry invalid handle\n");
3620 goto out;
3621 }
3622
3623
3624 ha->outstanding_cmds[handle] = NULL;
3625
3626 cmd = sp->cmd;
3627
3628 if (comp_status || scsi_status) {
3629 dprintk(3, "scsi: comp_status = 0x%x, scsi_status = "
3630 "0x%x, handle = 0x%x\n", comp_status,
3631 scsi_status, handle);
3632 }
3633
3634
3635 if ((scsi_status & 0xFF) == SAM_STAT_TASK_SET_FULL ||
3636 (scsi_status & 0xFF) == SAM_STAT_BUSY) {
3637 CMD_RESULT(cmd) = scsi_status & 0xff;
3638 } else {
3639
3640
3641 CMD_RESULT(cmd) = qla1280_return_status(pkt, cmd);
3642
3643 if (scsi_status & SAM_STAT_CHECK_CONDITION) {
3644 if (comp_status != CS_ARS_FAILED) {
3645 uint16_t req_sense_length =
3646 le16_to_cpu(pkt->req_sense_length);
3647 if (req_sense_length < CMD_SNSLEN(cmd))
3648 sense_sz = req_sense_length;
3649 else
3650
3651
3652
3653
3654
3655 sense_sz = CMD_SNSLEN(cmd) - 1;
3656
3657 memcpy(cmd->sense_buffer,
3658 &pkt->req_sense_data, sense_sz);
3659 } else
3660 sense_sz = 0;
3661 memset(cmd->sense_buffer + sense_sz, 0,
3662 SCSI_SENSE_BUFFERSIZE - sense_sz);
3663
3664 dprintk(2, "qla1280_status_entry: Check "
3665 "condition Sense data, b %i, t %i, "
3666 "l %i\n", SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
3667 SCSI_LUN_32(cmd));
3668 if (sense_sz)
3669 qla1280_dump_buffer(2,
3670 (char *)cmd->sense_buffer,
3671 sense_sz);
3672 }
3673 }
3674
3675 CMD_HANDLE(sp->cmd) = COMPLETED_HANDLE;
3676
3677
3678 list_add_tail(&sp->list, done_q);
3679 out:
3680 LEAVE("qla1280_status_entry");
3681}
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692static void
3693qla1280_error_entry(struct scsi_qla_host *ha, struct response *pkt,
3694 struct list_head *done_q)
3695{
3696 struct srb *sp;
3697 uint32_t handle = le32_to_cpu(pkt->handle);
3698
3699 ENTER("qla1280_error_entry");
3700
3701 if (pkt->entry_status & BIT_3)
3702 dprintk(2, "qla1280_error_entry: BAD PAYLOAD flag error\n");
3703 else if (pkt->entry_status & BIT_2)
3704 dprintk(2, "qla1280_error_entry: BAD HEADER flag error\n");
3705 else if (pkt->entry_status & BIT_1)
3706 dprintk(2, "qla1280_error_entry: FULL flag error\n");
3707 else
3708 dprintk(2, "qla1280_error_entry: UNKNOWN flag error\n");
3709
3710
3711 if (handle < MAX_OUTSTANDING_COMMANDS)
3712 sp = ha->outstanding_cmds[handle];
3713 else
3714 sp = NULL;
3715
3716 if (sp) {
3717
3718 ha->outstanding_cmds[handle] = NULL;
3719
3720
3721 if (pkt->entry_status & (BIT_3 + BIT_2)) {
3722
3723
3724 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
3725 } else if (pkt->entry_status & BIT_1) {
3726 CMD_RESULT(sp->cmd) = DID_BUS_BUSY << 16;
3727 } else {
3728
3729 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
3730 }
3731
3732 CMD_HANDLE(sp->cmd) = COMPLETED_HANDLE;
3733
3734
3735 list_add_tail(&sp->list, done_q);
3736 }
3737#ifdef QLA_64BIT_PTR
3738 else if (pkt->entry_type == COMMAND_A64_TYPE) {
3739 printk(KERN_WARNING "!qla1280: Error Entry invalid handle");
3740 }
3741#endif
3742
3743 LEAVE("qla1280_error_entry");
3744}
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756static int
3757qla1280_abort_isp(struct scsi_qla_host *ha)
3758{
3759 struct device_reg __iomem *reg = ha->iobase;
3760 struct srb *sp;
3761 int status = 0;
3762 int cnt;
3763 int bus;
3764
3765 ENTER("qla1280_abort_isp");
3766
3767 if (ha->flags.abort_isp_active || !ha->flags.online)
3768 goto out;
3769
3770 ha->flags.abort_isp_active = 1;
3771
3772
3773 qla1280_disable_intrs(ha);
3774 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
3775 RD_REG_WORD(®->id_l);
3776
3777 printk(KERN_INFO "scsi(%li): dequeuing outstanding commands\n",
3778 ha->host_no);
3779
3780 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3781 struct scsi_cmnd *cmd;
3782 sp = ha->outstanding_cmds[cnt];
3783 if (sp) {
3784 cmd = sp->cmd;
3785 CMD_RESULT(cmd) = DID_RESET << 16;
3786 CMD_HANDLE(cmd) = COMPLETED_HANDLE;
3787 ha->outstanding_cmds[cnt] = NULL;
3788 list_add_tail(&sp->list, &ha->done_q);
3789 }
3790 }
3791
3792 qla1280_done(ha);
3793
3794 status = qla1280_load_firmware(ha);
3795 if (status)
3796 goto out;
3797
3798
3799 qla1280_nvram_config (ha);
3800
3801 status = qla1280_init_rings(ha);
3802 if (status)
3803 goto out;
3804
3805
3806 for (bus = 0; bus < ha->ports; bus++)
3807 qla1280_bus_reset(ha, bus);
3808
3809 ha->flags.abort_isp_active = 0;
3810 out:
3811 if (status) {
3812 printk(KERN_WARNING
3813 "qla1280: ISP error recovery failed, board disabled");
3814 qla1280_reset_adapter(ha);
3815 dprintk(2, "qla1280_abort_isp: **** FAILED ****\n");
3816 }
3817
3818 LEAVE("qla1280_abort_isp");
3819 return status;
3820}
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833static u16
3834qla1280_debounce_register(volatile u16 __iomem * addr)
3835{
3836 volatile u16 ret;
3837 volatile u16 ret2;
3838
3839 ret = RD_REG_WORD(addr);
3840 ret2 = RD_REG_WORD(addr);
3841
3842 if (ret == ret2)
3843 return ret;
3844
3845 do {
3846 cpu_relax();
3847 ret = RD_REG_WORD(addr);
3848 ret2 = RD_REG_WORD(addr);
3849 } while (ret != ret2);
3850
3851 return ret;
3852}
3853
3854
3855
3856
3857
3858
3859
3860#define SET_SXP_BANK 0x0100
3861#define SCSI_PHASE_INVALID 0x87FF
3862static int
3863qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *ha, unsigned int bus)
3864{
3865 uint16_t config_reg, scsi_control;
3866 struct device_reg __iomem *reg = ha->iobase;
3867
3868 if (ha->bus_settings[bus].scsi_bus_dead) {
3869 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
3870 config_reg = RD_REG_WORD(®->cfg_1);
3871 WRT_REG_WORD(®->cfg_1, SET_SXP_BANK);
3872 scsi_control = RD_REG_WORD(®->scsiControlPins);
3873 WRT_REG_WORD(®->cfg_1, config_reg);
3874 WRT_REG_WORD(®->host_cmd, HC_RELEASE_RISC);
3875
3876 if (scsi_control == SCSI_PHASE_INVALID) {
3877 ha->bus_settings[bus].scsi_bus_dead = 1;
3878 return 1;
3879 } else {
3880 ha->bus_settings[bus].scsi_bus_dead = 0;
3881 ha->bus_settings[bus].failed_reset_count = 0;
3882 }
3883 }
3884 return 0;
3885}
3886
3887static void
3888qla1280_get_target_parameters(struct scsi_qla_host *ha,
3889 struct scsi_device *device)
3890{
3891 uint16_t mb[MAILBOX_REGISTER_COUNT];
3892 int bus, target, lun;
3893
3894 bus = device->channel;
3895 target = device->id;
3896 lun = device->lun;
3897
3898
3899 mb[0] = MBC_GET_TARGET_PARAMETERS;
3900 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
3901 mb[1] <<= 8;
3902 qla1280_mailbox_command(ha, BIT_6 | BIT_3 | BIT_2 | BIT_1 | BIT_0,
3903 &mb[0]);
3904
3905 printk(KERN_INFO "scsi(%li:%d:%d:%d):", ha->host_no, bus, target, lun);
3906
3907 if (mb[3] != 0) {
3908 printk(KERN_CONT " Sync: period %d, offset %d",
3909 (mb[3] & 0xff), (mb[3] >> 8));
3910 if (mb[2] & BIT_13)
3911 printk(KERN_CONT ", Wide");
3912 if ((mb[2] & BIT_5) && ((mb[6] >> 8) & 0xff) >= 2)
3913 printk(KERN_CONT ", DT");
3914 } else
3915 printk(KERN_CONT " Async");
3916
3917 if (device->simple_tags)
3918 printk(KERN_CONT ", Tagged queuing: depth %d", device->queue_depth);
3919 printk(KERN_CONT "\n");
3920}
3921
3922
3923#if DEBUG_QLA1280
3924static void
3925__qla1280_dump_buffer(char *b, int size)
3926{
3927 int cnt;
3928 u8 c;
3929
3930 printk(KERN_DEBUG " 0 1 2 3 4 5 6 7 8 9 Ah "
3931 "Bh Ch Dh Eh Fh\n");
3932 printk(KERN_DEBUG "---------------------------------------------"
3933 "------------------\n");
3934
3935 for (cnt = 0; cnt < size;) {
3936 c = *b++;
3937
3938 printk("0x%02x", c);
3939 cnt++;
3940 if (!(cnt % 16))
3941 printk("\n");
3942 else
3943 printk(" ");
3944 }
3945 if (cnt % 16)
3946 printk("\n");
3947}
3948
3949
3950
3951
3952
3953static void
3954__qla1280_print_scsi_cmd(struct scsi_cmnd *cmd)
3955{
3956 struct scsi_qla_host *ha;
3957 struct Scsi_Host *host = CMD_HOST(cmd);
3958 struct srb *sp;
3959
3960
3961 int i;
3962 ha = (struct scsi_qla_host *)host->hostdata;
3963
3964 sp = (struct srb *)CMD_SP(cmd);
3965 printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd, CMD_HANDLE(cmd));
3966 printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
3967 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd),
3968 CMD_CDBLEN(cmd));
3969 printk(" CDB = ");
3970 for (i = 0; i < cmd->cmd_len; i++) {
3971 printk("0x%02x ", cmd->cmnd[i]);
3972 }
3973 printk(" seg_cnt =%d\n", scsi_sg_count(cmd));
3974 printk(" request buffer=0x%p, request buffer len=0x%x\n",
3975 scsi_sglist(cmd), scsi_bufflen(cmd));
3976
3977
3978
3979
3980
3981
3982 printk(" tag=%d, transfersize=0x%x \n",
3983 scsi_cmd_to_rq(cmd)->tag, cmd->transfersize);
3984 printk(" SP=0x%p\n", CMD_SP(cmd));
3985 printk(" underflow size = 0x%x, direction=0x%x\n",
3986 cmd->underflow, cmd->sc_data_direction);
3987}
3988
3989
3990
3991
3992
3993static void
3994ql1280_dump_device(struct scsi_qla_host *ha)
3995{
3996
3997 struct scsi_cmnd *cp;
3998 struct srb *sp;
3999 int i;
4000
4001 printk(KERN_DEBUG "Outstanding Commands on controller:\n");
4002
4003 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
4004 if ((sp = ha->outstanding_cmds[i]) == NULL)
4005 continue;
4006 if ((cp = sp->cmd) == NULL)
4007 continue;
4008 qla1280_print_scsi_cmd(1, cp);
4009 }
4010}
4011#endif
4012
4013
4014enum tokens {
4015 TOKEN_NVRAM,
4016 TOKEN_SYNC,
4017 TOKEN_WIDE,
4018 TOKEN_PPR,
4019 TOKEN_VERBOSE,
4020 TOKEN_DEBUG,
4021};
4022
4023struct setup_tokens {
4024 char *token;
4025 int val;
4026};
4027
4028static struct setup_tokens setup_token[] __initdata =
4029{
4030 { "nvram", TOKEN_NVRAM },
4031 { "sync", TOKEN_SYNC },
4032 { "wide", TOKEN_WIDE },
4033 { "ppr", TOKEN_PPR },
4034 { "verbose", TOKEN_VERBOSE },
4035 { "debug", TOKEN_DEBUG },
4036};
4037
4038
4039
4040
4041
4042
4043
4044
4045static int __init
4046qla1280_setup(char *s)
4047{
4048 char *cp, *ptr;
4049 unsigned long val;
4050 int toke;
4051
4052 cp = s;
4053
4054 while (cp && (ptr = strchr(cp, ':'))) {
4055 ptr++;
4056 if (!strcmp(ptr, "yes")) {
4057 val = 0x10000;
4058 ptr += 3;
4059 } else if (!strcmp(ptr, "no")) {
4060 val = 0;
4061 ptr += 2;
4062 } else
4063 val = simple_strtoul(ptr, &ptr, 0);
4064
4065 switch ((toke = qla1280_get_token(cp))) {
4066 case TOKEN_NVRAM:
4067 if (!val)
4068 driver_setup.no_nvram = 1;
4069 break;
4070 case TOKEN_SYNC:
4071 if (!val)
4072 driver_setup.no_sync = 1;
4073 else if (val != 0x10000)
4074 driver_setup.sync_mask = val;
4075 break;
4076 case TOKEN_WIDE:
4077 if (!val)
4078 driver_setup.no_wide = 1;
4079 else if (val != 0x10000)
4080 driver_setup.wide_mask = val;
4081 break;
4082 case TOKEN_PPR:
4083 if (!val)
4084 driver_setup.no_ppr = 1;
4085 else if (val != 0x10000)
4086 driver_setup.ppr_mask = val;
4087 break;
4088 case TOKEN_VERBOSE:
4089 qla1280_verbose = val;
4090 break;
4091 default:
4092 printk(KERN_INFO "qla1280: unknown boot option %s\n",
4093 cp);
4094 }
4095
4096 cp = strchr(ptr, ';');
4097 if (cp)
4098 cp++;
4099 else {
4100 break;
4101 }
4102 }
4103 return 1;
4104}
4105
4106
4107static int __init
4108qla1280_get_token(char *str)
4109{
4110 char *sep;
4111 long ret = -1;
4112 int i;
4113
4114 sep = strchr(str, ':');
4115
4116 if (sep) {
4117 for (i = 0; i < ARRAY_SIZE(setup_token); i++) {
4118 if (!strncmp(setup_token[i].token, str, (sep - str))) {
4119 ret = setup_token[i].val;
4120 break;
4121 }
4122 }
4123 }
4124
4125 return ret;
4126}
4127
4128
4129static struct scsi_host_template qla1280_driver_template = {
4130 .module = THIS_MODULE,
4131 .proc_name = "qla1280",
4132 .name = "Qlogic ISP 1280/12160",
4133 .info = qla1280_info,
4134 .slave_configure = qla1280_slave_configure,
4135 .queuecommand = qla1280_queuecommand,
4136 .eh_abort_handler = qla1280_eh_abort,
4137 .eh_device_reset_handler= qla1280_eh_device_reset,
4138 .eh_bus_reset_handler = qla1280_eh_bus_reset,
4139 .eh_host_reset_handler = qla1280_eh_adapter_reset,
4140 .bios_param = qla1280_biosparam,
4141 .can_queue = MAX_OUTSTANDING_COMMANDS,
4142 .this_id = -1,
4143 .sg_tablesize = SG_ALL,
4144};
4145
4146
4147static int
4148qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4149{
4150 int devnum = id->driver_data;
4151 struct qla_boards *bdp = &ql1280_board_tbl[devnum];
4152 struct Scsi_Host *host;
4153 struct scsi_qla_host *ha;
4154 int error = -ENODEV;
4155
4156
4157 if (pdev->subsystem_vendor == PCI_VENDOR_ID_AMI) {
4158 printk(KERN_INFO
4159 "qla1280: Skipping AMI SubSys Vendor ID Chip\n");
4160 goto error;
4161 }
4162
4163 printk(KERN_INFO "qla1280: %s found on PCI bus %i, dev %i\n",
4164 bdp->name, pdev->bus->number, PCI_SLOT(pdev->devfn));
4165
4166 if (pci_enable_device(pdev)) {
4167 printk(KERN_WARNING
4168 "qla1280: Failed to enabled pci device, aborting.\n");
4169 goto error;
4170 }
4171
4172 pci_set_master(pdev);
4173
4174 error = -ENOMEM;
4175 host = scsi_host_alloc(&qla1280_driver_template, sizeof(*ha));
4176 if (!host) {
4177 printk(KERN_WARNING
4178 "qla1280: Failed to register host, aborting.\n");
4179 goto error_disable_device;
4180 }
4181
4182 ha = (struct scsi_qla_host *)host->hostdata;
4183 memset(ha, 0, sizeof(struct scsi_qla_host));
4184
4185 ha->pdev = pdev;
4186 ha->devnum = devnum;
4187
4188#ifdef QLA_64BIT_PTR
4189 if (dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(64))) {
4190 if (dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32))) {
4191 printk(KERN_WARNING "scsi(%li): Unable to set a "
4192 "suitable DMA mask - aborting\n", ha->host_no);
4193 error = -ENODEV;
4194 goto error_put_host;
4195 }
4196 } else
4197 dprintk(2, "scsi(%li): 64 Bit PCI Addressing Enabled\n",
4198 ha->host_no);
4199#else
4200 if (dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32))) {
4201 printk(KERN_WARNING "scsi(%li): Unable to set a "
4202 "suitable DMA mask - aborting\n", ha->host_no);
4203 error = -ENODEV;
4204 goto error_put_host;
4205 }
4206#endif
4207
4208 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
4209 ((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
4210 &ha->request_dma, GFP_KERNEL);
4211 if (!ha->request_ring) {
4212 printk(KERN_INFO "qla1280: Failed to get request memory\n");
4213 goto error_put_host;
4214 }
4215
4216 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
4217 ((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
4218 &ha->response_dma, GFP_KERNEL);
4219 if (!ha->response_ring) {
4220 printk(KERN_INFO "qla1280: Failed to get response memory\n");
4221 goto error_free_request_ring;
4222 }
4223
4224 ha->ports = bdp->numPorts;
4225
4226 ha->host = host;
4227 ha->host_no = host->host_no;
4228
4229 host->irq = pdev->irq;
4230 host->max_channel = bdp->numPorts - 1;
4231 host->max_lun = MAX_LUNS - 1;
4232 host->max_id = MAX_TARGETS;
4233 host->max_sectors = 1024;
4234 host->unique_id = host->host_no;
4235
4236 error = -ENODEV;
4237
4238#if MEMORY_MAPPED_IO
4239 ha->mmpbase = pci_ioremap_bar(ha->pdev, 1);
4240 if (!ha->mmpbase) {
4241 printk(KERN_INFO "qla1280: Unable to map I/O memory\n");
4242 goto error_free_response_ring;
4243 }
4244
4245 host->base = (unsigned long)ha->mmpbase;
4246 ha->iobase = (struct device_reg __iomem *)ha->mmpbase;
4247#else
4248 host->io_port = pci_resource_start(ha->pdev, 0);
4249 if (!request_region(host->io_port, 0xff, "qla1280")) {
4250 printk(KERN_INFO "qla1280: Failed to reserve i/o region "
4251 "0x%04lx-0x%04lx - already in use\n",
4252 host->io_port, host->io_port + 0xff);
4253 goto error_free_response_ring;
4254 }
4255
4256 ha->iobase = (struct device_reg *)host->io_port;
4257#endif
4258
4259 INIT_LIST_HEAD(&ha->done_q);
4260
4261
4262 qla1280_disable_intrs(ha);
4263
4264 if (request_irq(pdev->irq, qla1280_intr_handler, IRQF_SHARED,
4265 "qla1280", ha)) {
4266 printk("qla1280 : Failed to reserve interrupt %d already "
4267 "in use\n", pdev->irq);
4268 goto error_release_region;
4269 }
4270
4271
4272 if (qla1280_initialize_adapter(ha)) {
4273 printk(KERN_INFO "qla1x160: Failed to initialize adapter\n");
4274 goto error_free_irq;
4275 }
4276
4277
4278 host->this_id = ha->bus_settings[0].id;
4279
4280 pci_set_drvdata(pdev, host);
4281
4282 error = scsi_add_host(host, &pdev->dev);
4283 if (error)
4284 goto error_disable_adapter;
4285 scsi_scan_host(host);
4286
4287 return 0;
4288
4289 error_disable_adapter:
4290 qla1280_disable_intrs(ha);
4291 error_free_irq:
4292 free_irq(pdev->irq, ha);
4293 error_release_region:
4294#if MEMORY_MAPPED_IO
4295 iounmap(ha->mmpbase);
4296#else
4297 release_region(host->io_port, 0xff);
4298#endif
4299 error_free_response_ring:
4300 dma_free_coherent(&ha->pdev->dev,
4301 ((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
4302 ha->response_ring, ha->response_dma);
4303 error_free_request_ring:
4304 dma_free_coherent(&ha->pdev->dev,
4305 ((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
4306 ha->request_ring, ha->request_dma);
4307 error_put_host:
4308 scsi_host_put(host);
4309 error_disable_device:
4310 pci_disable_device(pdev);
4311 error:
4312 return error;
4313}
4314
4315
4316static void
4317qla1280_remove_one(struct pci_dev *pdev)
4318{
4319 struct Scsi_Host *host = pci_get_drvdata(pdev);
4320 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
4321
4322 scsi_remove_host(host);
4323
4324 qla1280_disable_intrs(ha);
4325
4326 free_irq(pdev->irq, ha);
4327
4328#if MEMORY_MAPPED_IO
4329 iounmap(ha->mmpbase);
4330#else
4331 release_region(host->io_port, 0xff);
4332#endif
4333
4334 dma_free_coherent(&ha->pdev->dev,
4335 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4336 ha->request_ring, ha->request_dma);
4337 dma_free_coherent(&ha->pdev->dev,
4338 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4339 ha->response_ring, ha->response_dma);
4340
4341 pci_disable_device(pdev);
4342
4343 scsi_host_put(host);
4344}
4345
4346static struct pci_driver qla1280_pci_driver = {
4347 .name = "qla1280",
4348 .id_table = qla1280_pci_tbl,
4349 .probe = qla1280_probe_one,
4350 .remove = qla1280_remove_one,
4351};
4352
4353static int __init
4354qla1280_init(void)
4355{
4356 if (sizeof(struct srb) > sizeof(struct scsi_pointer)) {
4357 printk(KERN_WARNING
4358 "qla1280: struct srb too big, aborting\n");
4359 return -EINVAL;
4360 }
4361
4362#ifdef MODULE
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375 if (qla1280)
4376 qla1280_setup(qla1280);
4377#endif
4378
4379 return pci_register_driver(&qla1280_pci_driver);
4380}
4381
4382static void __exit
4383qla1280_exit(void)
4384{
4385 int i;
4386
4387 pci_unregister_driver(&qla1280_pci_driver);
4388
4389 for (i = 0; i < QL_NUM_FW_IMAGES; i++) {
4390 release_firmware(qla1280_fw_tbl[i].fw);
4391 qla1280_fw_tbl[i].fw = NULL;
4392 }
4393}
4394
4395module_init(qla1280_init);
4396module_exit(qla1280_exit);
4397
4398MODULE_AUTHOR("Qlogic & Jes Sorensen");
4399MODULE_DESCRIPTION("Qlogic ISP SCSI (qla1x80/qla1x160) driver");
4400MODULE_LICENSE("GPL");
4401MODULE_FIRMWARE("qlogic/1040.bin");
4402MODULE_FIRMWARE("qlogic/1280.bin");
4403MODULE_FIRMWARE("qlogic/12160.bin");
4404MODULE_VERSION(QLA1280_VERSION);
4405