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