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