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