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