1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#define QLA1280_VERSION "3.23.19 Beta"
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#include <linux/config.h>
242#include <linux/module.h>
243
244#include <linux/version.h>
245#include <linux/types.h>
246#include <linux/string.h>
247#include <linux/errno.h>
248#include <linux/kernel.h>
249#include <linux/interrupt.h>
250#include <linux/ioport.h>
251#include <linux/delay.h>
252#include <linux/timer.h>
253#include <linux/pci.h>
254#include <linux/proc_fs.h>
255#include <linux/blk.h>
256#include <linux/workqueue.h>
257#include <linux/stat.h>
258#include <linux/slab.h>
259
260#include <asm/io.h>
261#include <asm/irq.h>
262#include <asm/byteorder.h>
263#include <asm/processor.h>
264
265#ifndef KERNEL_VERSION
266#define KERNEL_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z))
267#endif
268
269#if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,18)
270#include <linux/pci_ids.h>
271#endif
272
273#include "scsi.h"
274#include "hosts.h"
275#define UNIQUE_FW_NAME
276#include "qla1280.h"
277#include "ql12160_fw.h"
278#include "ql1280_fw.h"
279
280
281
282
283
284#define QL1280_TARGET_MODE_SUPPORT 0
285#define QL1280_LUN_SUPPORT 0
286#define WATCHDOGTIMER 0
287#define MEMORY_MAPPED_IO 0
288#define DEBUG_QLA1280_INTR 0
289#define USE_NVRAM_DEFAULTS 0
290#define DEBUG_PRINT_NVRAM 0
291#define LOADING_RISC_ACTIVITY 0
292#define AUTO_ESCALATE_RESET 0
293#define AUTO_ESCALATE_ABORT 0
294#define STOP_ON_ERROR 0
295#define STOP_ON_RESET 0
296#define STOP_ON_ABORT 0
297#define QLA1280_PROFILE 1
298#define DEBUG_QLA1280 0
299
300
301
302
303#ifndef PCI_DEVICE_ID_QLOGIC_ISP1080
304#define PCI_DEVICE_ID_QLOGIC_ISP1080 0x1080
305#endif
306#ifndef PCI_DEVICE_ID_QLOGIC_ISP1240
307#define PCI_DEVICE_ID_QLOGIC_ISP1240 0x1240
308#endif
309#ifndef PCI_DEVICE_ID_QLOGIC_ISP1280
310#define PCI_DEVICE_ID_QLOGIC_ISP1280 0x1280
311#endif
312#ifndef PCI_DEVICE_ID_QLOGIC_ISP10160
313#define PCI_DEVICE_ID_QLOGIC_ISP10160 0x1016
314#endif
315#ifndef PCI_DEVICE_ID_QLOGIC_ISP12160
316#define PCI_DEVICE_ID_QLOGIC_ISP12160 0x1216
317#endif
318
319#ifndef PCI_VENDOR_ID_AMI
320#define PCI_VENDOR_ID_AMI 0x101e
321#endif
322
323#if (BITS_PER_LONG == 64) || defined CONFIG_HIGHMEM
324#define QLA_64BIT_PTR 1
325#endif
326
327
328#ifdef QLA_64BIT_PTR
329#define pci_dma_lo32(a) (a & 0xffffffff)
330#define pci_dma_hi32(a) (a >> 32)
331#else
332#define pci_dma_lo32(a) (a & 0xffffffff)
333#define pci_dma_hi32(a) 0
334#endif
335
336#define NVRAM_DELAY() udelay(500)
337
338#define CACHE_FLUSH(a) RD_REG_WORD(a)
339#define INVALID_HANDLE (MAX_OUTSTANDING_COMMANDS + 1)
340
341
342
343
344#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
345#define pci_set_dma_mask(dev, mask) dev->dma_mask = mask;
346#define pci_present() pcibios_present()
347#define pci_enable_device(pdev) 0
348#define pci_find_subsys(id, dev, sid, sdev, pdev) pci_find_device(id,dev,pdev)
349#define scsi_set_pci_device(host, pdev)
350#endif
351
352#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
353typedef unsigned long dma_addr_t;
354
355static inline void *
356pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
357 dma_addr_t * dma_handle)
358{
359 void *virt_ptr;
360
361 virt_ptr = kmalloc(size, GFP_KERNEL);
362 if (!virt_ptr)
363 return NULL;
364 *dma_handle = virt_to_bus(virt_ptr);
365 return virt_ptr;
366}
367
368#define pci_free_consistent(cookie, size, ptr, dma_ptr) kfree(ptr)
369#define pci_map_single(cookie, address, size, dir) virt_to_bus(address)
370#define pci_map_sg(cookie, scatter, ents, dir) ents
371#define pci_unmap_single(cookie, address, size, dir)
372#define pci_unmap_sg(cookie, scatter, ents, dir)
373
374#define pci_resource_start(dev, i) dev->base_address[i]
375#endif
376
377
378
379
380static void qla1280_done(struct scsi_qla_host *, srb_t **, srb_t **);
381static void qla1280_next(struct scsi_qla_host *, scsi_lu_t *, int);
382static void qla1280_putq_t(scsi_lu_t *, srb_t *);
383static void qla1280_done_q_put(srb_t *, srb_t **, srb_t **);
384static int qla1280_slave_configure(Scsi_Device *);
385#if STOP_ON_ERROR
386static void qla1280_panic(char *, struct Scsi_Host *host);
387#endif
388static void qla1280_abort_queue_single(struct scsi_qla_host *, int, int,
389 int, uint32_t);
390
391static int qla1280_return_status(sts_entry_t * sts, Scsi_Cmnd * cp);
392static void qla1280_removeq(scsi_lu_t * q, srb_t * sp);
393static void qla1280_mem_free(struct scsi_qla_host *ha);
394void qla1280_do_dpc(void *p);
395#ifdef MODULE
396static char *qla1280_get_token(char *, char *);
397#endif
398static inline void qla1280_enable_intrs(struct scsi_qla_host *);
399static inline void qla1280_disable_intrs(struct scsi_qla_host *);
400
401
402
403
404static int qla1280_initialize_adapter(struct scsi_qla_host *ha);
405static int qla1280_enable_tgt(struct scsi_qla_host *, int);
406static int qla1280_isp_firmware(struct scsi_qla_host *);
407static int qla1280_pci_config(struct scsi_qla_host *);
408static int qla1280_chip_diag(struct scsi_qla_host *);
409static int qla1280_setup_chip(struct scsi_qla_host *);
410static int qla1280_init_rings(struct scsi_qla_host *);
411static int qla1280_nvram_config(struct scsi_qla_host *);
412static int qla1280_mailbox_command(struct scsi_qla_host *,
413 uint8_t, uint16_t *);
414static int qla1280_bus_reset(struct scsi_qla_host *, int);
415static int qla1280_device_reset(struct scsi_qla_host *, int, int);
416static int qla1280_abort_device(struct scsi_qla_host *, int, int, int);
417static int qla1280_abort_command(struct scsi_qla_host *, srb_t *);
418static int qla1280_abort_isp(struct scsi_qla_host *);
419static int qla1280_64bit_start_scsi(struct scsi_qla_host *, srb_t *);
420static int qla1280_32bit_start_scsi(struct scsi_qla_host *, srb_t *);
421static void qla1280_nv_write(struct scsi_qla_host *, uint16_t);
422static void qla1280_poll(struct scsi_qla_host *);
423static void qla1280_reset_adapter(struct scsi_qla_host *);
424static void qla1280_marker(struct scsi_qla_host *, int, int, int, u8);
425static void qla1280_isp_cmd(struct scsi_qla_host *);
426static void qla1280_isr(struct scsi_qla_host *, srb_t **, srb_t **);
427static void qla1280_rst_aen(struct scsi_qla_host *);
428static void qla1280_status_entry(struct scsi_qla_host *, sts_entry_t *,
429 srb_t **, srb_t **);
430static void qla1280_error_entry(struct scsi_qla_host *, response_t *,
431 srb_t **, srb_t **);
432static void qla1280_restart_queues(struct scsi_qla_host *);
433static void qla1280_abort_queues(struct scsi_qla_host *);
434static uint16_t qla1280_get_nvram_word(struct scsi_qla_host *, uint32_t);
435static uint16_t qla1280_nvram_request(struct scsi_qla_host *, uint32_t);
436static uint16_t qla1280_debounce_register(volatile uint16_t *);
437static request_t *qla1280_req_pkt(struct scsi_qla_host *);
438static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *,
439 unsigned int);
440static int qla1280_mem_alloc(struct scsi_qla_host *ha);
441
442static void qla12160_get_target_parameters(struct scsi_qla_host *,
443 uint32_t, uint32_t, uint32_t);
444
445#if QL1280_LUN_SUPPORT
446static void qla1280_enable_lun(struct scsi_qla_host *, int, int);
447#endif
448
449#if QL1280_TARGET_MODE_SUPPORT
450static void qla1280_notify_ack(struct scsi_qla_host *, notify_entry_t *);
451static void qla1280_immed_notify(struct scsi_qla_host *, notify_entry_t *);
452static void qla1280_accept_io(struct scsi_qla_host *, ctio_ret_entry_t *);
453static void qla1280_64bit_continue_io(struct scsi_qla_host *, atio_entry_t *,
454 uint32_t, paddr32_t *);
455static void qla1280_32bit_continue_io(struct scsi_qla_host *, atio_entry_t *,
456 uint32_t, paddr32_t *);
457static void qla1280_atio_entry(struct scsi_qla_host *, atio_entry_t *);
458static void qla1280_notify_entry(struct scsi_qla_host *, notify_entry_t *);
459#endif
460
461#ifdef QL_DEBUG_ROUTINES
462
463
464
465static u8 qla1280_getbyte(u8 *);
466static u16 qla1280_getword(u16 *);
467static u32 qla1280_getdword(u32 *);
468static void qla1280_putbyte(u8 *, u8);
469static void qla1280_putword(u16 *, u8);
470static void qla1280_putdword(u32 *, u32);
471static void __qla1280_print_scsi_cmd(Scsi_Cmnd * cmd);
472static void __qla1280_dump_buffer(char *, u32);
473#endif
474
475
476
477
478#ifdef MODULE
479static char *options = NULL;
480
481
482MODULE_PARM(options, "s");
483#endif
484
485MODULE_LICENSE("GPL");
486
487#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
488
489
490
491
492
493#define PROC_SCSI_QL1280 PROC_SCSI_QLOGICISP
494
495struct proc_dir_entry proc_scsi_qla1280 = {
496 PROC_SCSI_QL1280, 7, "qla1280",
497 S_IFDIR | S_IRUGO | S_IXUGO, 2,
498 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL
499};
500#endif
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516#define CMD_SP(Cmnd) &Cmnd->SCp
517#define CMD_CDBLEN(Cmnd) Cmnd->cmd_len
518#define CMD_CDBP(Cmnd) Cmnd->cmnd
519#define CMD_SNSP(Cmnd) Cmnd->sense_buffer
520#define CMD_SNSLEN(Cmnd) sizeof(Cmnd->sense_buffer)
521#define CMD_RESULT(Cmnd) Cmnd->result
522#define CMD_HANDLE(Cmnd) Cmnd->host_scribble
523
524
525
526
527
528#define NUM_OF_ISP_DEVICES 6
529
530struct qla_boards {
531 unsigned char bdName[9];
532 unsigned long device_id;
533 int numPorts;
534 unsigned short *fwcode;
535 unsigned short *fwlen;
536 unsigned short *fwstart;
537 unsigned char *fwver;
538};
539
540struct qla_boards ql1280_board_tbl[NUM_OF_ISP_DEVICES] = {
541
542 {"QLA12160 ", PCI_DEVICE_ID_QLOGIC_ISP12160, 2,
543 &fw12160i_code01[0], &fw12160i_length01,
544 &fw12160i_addr01, &fw12160i_version_str[0]},
545 {"QLA1080 ", PCI_DEVICE_ID_QLOGIC_ISP1080, 1,
546 &fw1280ei_code01[0], &fw1280ei_length01,
547 &fw1280ei_addr01, &fw1280ei_version_str[0]},
548 {"QLA1240 ", PCI_DEVICE_ID_QLOGIC_ISP1240, 2,
549 &fw1280ei_code01[0], &fw1280ei_length01,
550 &fw1280ei_addr01, &fw1280ei_version_str[0]},
551 {"QLA1280 ", PCI_DEVICE_ID_QLOGIC_ISP1280, 2,
552 &fw1280ei_code01[0], &fw1280ei_length01,
553 &fw1280ei_addr01, &fw1280ei_version_str[0]},
554 {"QLA10160 ", PCI_DEVICE_ID_QLOGIC_ISP10160, 1,
555 &fw12160i_code01[0], &fw12160i_length01,
556 &fw12160i_addr01, &fw12160i_version_str[0]},
557 {" ", 0, 0}
558};
559
560static int qla1280_verbose = 1;
561static struct scsi_qla_host *qla1280_hostlist = NULL;
562#if QLA1280_PROFILE
563static int qla1280_buffer_size = 0;
564static char *qla1280_buffer = NULL;
565#endif
566
567#if DEBUG_QLA1280
568static int ql_debug_print = 1;
569char debug_buff[80];
570#define DEBUG(x) x
571static int ql_debug_level = 0;
572#define dprintk(level, format, a...) \
573 if ((ql_debug_level >= level) && ql_debug_print) printk(KERN_DEBUG format, ##a)
574#define qla1280_dump_buffer(level, buf, size) \
575 if (ql_debug_level >= level) __qla1280_dump_buffer(buf, size)
576#define qla1280_dump_print_cmd(level, cmd) \
577 if (ql_debug_level >= level) __qla1280_print_scsi_cmd(cmd)
578#else
579#define DEBUG(x)
580#define ql_debug_level 0
581#define dprintk(level, format, a...) do{}while(0)
582#define qla1280_dump_buffer(a, b, c) do{}while(0)
583#define qla1280_print_scsi_cmd(a, b) do{}while(0)
584#endif
585
586#define ENTER(x) dprintk(3, "qla1280 : Entering %s()\n", x);
587#define LEAVE(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
588#define ENTER_INTR(x) dprintk(3, "qla1280 : Entering %s()\n", x);
589#define LEAVE_INTR(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
590
591#define SCSI_BUS_32(scp) scp->channel
592#define SCSI_TCN_32(scp) scp->target
593#define SCSI_LUN_32(scp) scp->lun
594
595
596
597
598
599
600
601
602
603
604
605
606
607int
608qla1280_set_info(char *buffer, int length, struct Scsi_Host *HBAptr)
609{
610 return -ENOSYS;
611}
612
613
614
615
616
617
618
619
620
621
622
623#define PROC_BUF &qla1280_buffer[len]
624
625int
626qla1280_proc_info(char *buffer, char **start, off_t offset, int length,
627 int hostno, int inout)
628{
629#if QLA1280_PROFILE
630 struct Scsi_Host *host;
631 struct scsi_qla_host *ha;
632 int size = 0;
633 scsi_lu_t *up;
634 int len = 0;
635 struct qla_boards *bdp;
636 uint32_t b, t, l;
637 host = NULL;
638
639
640 for (ha = qla1280_hostlist; (ha != NULL) && ha->host->host_no != hostno;
641 ha = ha->next) ;
642
643
644 if (!ha) {
645 size = sprintf(buffer, "Can't find adapter for host "
646 "number %d\n", hostno);
647 if (size > length) {
648 return size;
649 } else {
650 return 0;
651 }
652 }
653
654 host = ha->host;
655
656 if (inout == TRUE) {
657 printk(KERN_INFO
658 "qla1280_proc: has data been written to the file.\n");
659 return qla1280_set_info(buffer, length, host);
660 }
661
662
663
664
665
666 if (qla1280_buffer_size != PAGE_SIZE) {
667
668 if (qla1280_buffer != NULL) {
669 free_page((unsigned long)qla1280_buffer);
670 qla1280_buffer_size = 0;
671 }
672 qla1280_buffer = (char *)get_zeroed_page(GFP_KERNEL);
673 }
674 if (qla1280_buffer == NULL) {
675 size = sprintf(buffer, "qla1280 - kmalloc error at line %d\n",
676 __LINE__);
677 return size;
678 }
679
680 qla1280_buffer_size = PAGE_SIZE;
681
682
683 memset(qla1280_buffer, 0, PAGE_SIZE);
684
685
686 bdp = &ql1280_board_tbl[ha->devnum];
687 size = sprintf(PROC_BUF,
688 "QLogic PCI to SCSI Adapter for ISP 1280/12160:\n"
689 " Firmware version: %2d.%02d.%02d, Driver version %s\n",
690 bdp->fwver[0], bdp->fwver[1], bdp->fwver[2],
691 QLA1280_VERSION);
692
693 len += size;
694
695 size = sprintf(PROC_BUF, "SCSI Host Adapter Information: %s\n",
696 bdp->bdName);
697 len += size;
698 size = sprintf(PROC_BUF, "Request Queue = 0x%p, Response Queue = 0x%p\n",
699 (void *)ha->request_dma, (void *)ha->response_dma);
700 len += size;
701 size = sprintf(PROC_BUF, "Request Queue count= 0x%x, Response "
702 "Queue count= 0x%x\n",
703 REQUEST_ENTRY_CNT, RESPONSE_ENTRY_CNT);
704 len += size;
705 size = sprintf(PROC_BUF, "Number of pending commands = 0x%lx\n",
706 ha->actthreads);
707 len += size;
708 size = sprintf(PROC_BUF, "Number of queued commands = 0x%lx\n",
709 ha->qthreads);
710 len += size;
711 size = sprintf(PROC_BUF, "Number of free request entries = %d\n",
712 ha->req_q_cnt);
713 len += size;
714 size = sprintf(PROC_BUF, "\n");
715 len += size;
716
717 size = sprintf(PROC_BUF, "SCSI device Information:\n");
718 len += size;
719
720 for (b = 0; b < MAX_BUSES; b++)
721 for (t = 0; t < MAX_TARGETS; t++) {
722 for (l = 0; l < MAX_LUNS; l++) {
723 up = LU_Q(ha, b, t, l);
724 if (up == NULL)
725 continue;
726
727 if (up->io_cnt == 0 || up->io_cnt < 2)
728 continue;
729
730
731
732 size = sprintf (PROC_BUF,
733 "(%2d:%2d:%2d): Total reqs %ld,",
734 b, t, l, up->io_cnt);
735 len += size;
736
737 size = sprintf(PROC_BUF, " Pend reqs %d,",
738 up->q_outcnt);
739 len += size;
740#if 0
741
742 size = sprintf(PROC_BUF, " Avg resp time %ld%%,",
743 (up->resp_time / up->io_cnt) *
744 100);
745 len += size;
746
747
748 size = sprintf(PROC_BUF,
749 " Avg active time %ld%%\n",
750 (up->act_time / up->io_cnt) * 100);
751#else
752 size = sprintf(PROC_BUF, "\n");
753#endif
754 len += size;
755 }
756 if (len >= qla1280_buffer_size)
757 break;
758 }
759
760 if (len >= qla1280_buffer_size) {
761 printk(KERN_WARNING
762 "qla1280: Overflow buffer in qla1280_proc.c\n");
763 }
764
765 if (offset > len - 1) {
766 free_page((unsigned long) qla1280_buffer);
767 qla1280_buffer = NULL;
768 qla1280_buffer_size = length = 0;
769 *start = NULL;
770 } else {
771 *start = &qla1280_buffer[offset];
772 if (len - offset < length) {
773 length = len - offset;
774 }
775 }
776 return length;
777#else
778 return 0;
779#endif
780}
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798struct Scsi_Host *
799qla1280_do_device_init(struct pci_dev *pdev,
800 Scsi_Host_Template * template,
801 int devnum, struct qla_boards *bdp, int num_hosts)
802{
803 struct Scsi_Host *host;
804 struct scsi_qla_host *ha;
805 struct device_reg *reg;
806
807 printk("qla1x160: Initializing ISP12160 on PCI bus %i, dev %i, irq %i\n",
808 pdev->bus->number, PCI_SLOT(pdev->devfn), pdev->irq);
809
810 host = scsi_register(template, sizeof(struct scsi_qla_host));
811 if (!host) {
812 printk(KERN_WARNING
813 "qla1280: Failed to register host, aborting.\n");
814 goto error;
815 }
816
817 scsi_set_pci_device(host, pdev);
818 ha = (struct scsi_qla_host *)host->hostdata;
819
820 memset(ha, 0, sizeof(struct scsi_qla_host));
821
822 host->irq = pdev->irq;
823 ha->pci_bus = pdev->bus->number;
824 ha->pci_device_fn = pdev->devfn;
825 ha->pdev = pdev;
826 ha->device_id = bdp->device_id;
827 ha->devnum = devnum;
828
829 if (qla1280_mem_alloc(ha)) {
830 printk(KERN_INFO "qla1x160: Failed to get memory\n");
831 goto error;
832 }
833
834 ha->ports = bdp->numPorts;
835
836 ha->host = host;
837 ha->host_no = host->host_no;
838
839 host->can_queue = 0xfffff;
840 host->cmd_per_lun = 1;
841#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
842 host->base = (unsigned char *)ha->mmpbase;
843#else
844 host->base = (unsigned long)ha->mmpbase;
845#endif
846 host->max_channel = bdp->numPorts - 1;
847 host->max_lun = MAX_LUNS - 1;
848 host->max_id = MAX_TARGETS;
849#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,7)
850 host->max_sectors = 1024;
851#endif
852
853 ha->instance = num_hosts;
854 host->unique_id = ha->instance;
855
856 if (qla1280_pci_config(ha)) {
857 printk(KERN_INFO "qla1x160: Unable to configure PCI\n");
858 goto error_mem_alloced;
859 }
860
861
862 qla1280_disable_intrs(ha);
863
864
865 if (request_irq(host->irq, qla1280_intr_handler, SA_SHIRQ,
866 "qla1280", ha)) {
867 printk("qla1280 : Failed to reserve interrupt %d already "
868 "in use\n", host->irq);
869 goto error_mem_alloced;
870 }
871#if !MEMORY_MAPPED_IO
872
873 if (check_region(host->io_port, 0xff)) {
874 printk("qla1280 : Failed to reserve i/o region 0x%04lx-0x%04lx"
875 " already in use\n",
876 host->io_port, host->io_port + 0xff);
877 free_irq(host->irq, ha);
878 goto error_mem_alloced;
879 }
880
881 request_region(host->io_port, 0xff, "qla1280");
882#endif
883
884 reg = ha->iobase;
885
886
887 if (qla1280_initialize_adapter(ha)) {
888 printk(KERN_INFO "qla1x160:Failed to initialize adapter\n");
889 goto error_mem_alloced;
890 }
891
892
893 host->this_id = ha->bus_settings[0].id;
894
895 return host;
896
897 error_mem_alloced:
898 qla1280_mem_free(ha);
899
900 error:
901 if (host) {
902 scsi_unregister(host);
903 }
904 return NULL;
905}
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921int
922qla1280_detect(Scsi_Host_Template * template)
923{
924 struct pci_dev *pdev = NULL;
925 struct Scsi_Host *host;
926 struct scsi_qla_host *ha, *cur_ha;
927 struct qla_boards *bdp;
928 uint16_t subsys_vendor, subsys_device;
929 int num_hosts = 0;
930 int devnum = 0;
931
932 ENTER("qla1280_detect");
933
934 if (sizeof(srb_t) > sizeof(Scsi_Pointer)) {
935 printk(KERN_WARNING
936 "qla1280_detect: [WARNING] srb_t too big\n");
937 return 0;
938 }
939#ifdef MODULE
940 dprintk(1, "DEBUG: qla1280_detect starts at address = %p\n",
941 qla1280_detect);
942
943
944
945
946
947
948
949
950
951
952
953
954 if (options)
955 qla1280_setup(options, NULL);
956
957 printk(KERN_WARNING
958 "qla1280: Please read the file /usr/src/linux/Documentation"
959 "/scsi/qla1280.txt\n"
960 "qla1280: to see the proper way to specify options to the qla1280 "
961 "module\n"
962 "qla1280: Specifically, don't use any commas when passing "
963 "arguments to\n"
964 "qla1280: insmod or else it might trash certain memory areas.\n");
965#endif
966
967 if (!pci_present()) {
968 printk(KERN_INFO "scsi: PCI not present\n");
969 return 0;
970 }
971
972 bdp = &ql1280_board_tbl[0];
973 qla1280_hostlist = NULL;
974#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
975 template->proc_dir = &proc_scsi_qla1280;
976#else
977 template->proc_name = "qla1280";
978#endif
979
980
981
982 while ((pdev = pci_find_subsys(PCI_VENDOR_ID_QLOGIC, bdp->device_id,
983 PCI_ANY_ID, PCI_ANY_ID, pdev))) {
984
985
986 if ((pdev->bus->number != 1) || (PCI_SLOT(pdev->devfn) != 2))
987 continue;
988
989
990 if (pdev->subsystem_vendor == PCI_VENDOR_ID_AMI) {
991 printk(KERN_INFO
992 "qla1x160: Skip AMI SubSys Vendor ID Chip\n");
993 continue;
994 }
995
996 if (pci_enable_device(pdev))
997 goto find_devices;
998
999 host = qla1280_do_device_init(pdev, template, devnum,
1000 bdp, num_hosts);
1001 if (!host)
1002 continue;
1003 ha = (struct scsi_qla_host *)host->hostdata;
1004
1005
1006 cur_ha = qla1280_hostlist = ha;
1007 num_hosts++;
1008 }
1009
1010 find_devices:
1011
1012 pdev = NULL;
1013
1014 for (devnum = 0; bdp->device_id != 0 && devnum < NUM_OF_ISP_DEVICES;
1015 devnum++, bdp++) {
1016
1017 while ((pdev = pci_find_subsys(PCI_VENDOR_ID_QLOGIC,
1018 bdp->device_id, PCI_ANY_ID,
1019 PCI_ANY_ID, pdev))) {
1020 if (pci_enable_device(pdev))
1021 continue;
1022
1023#if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,18)
1024 subsys_vendor = pdev->subsystem_vendor;
1025 subsys_device = pdev->subsystem_device;
1026#else
1027 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID,
1028 &subsys_vendor);
1029 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID,
1030 &subsys_device);
1031#endif
1032
1033
1034
1035
1036
1037 if ((bdp->device_id == PCI_DEVICE_ID_QLOGIC_ISP12160)&&
1038 (pdev->bus->number == 1) &&
1039 (PCI_SLOT(pdev->devfn) == 2))
1040 continue;
1041
1042
1043 if (subsys_vendor == PCI_VENDOR_ID_AMI) {
1044 printk(KERN_INFO
1045 "qla1x160: Skip AMI SubSys Vendor ID Chip\n");
1046 continue;
1047 }
1048 printk(KERN_INFO
1049 "qla1x160: Supported Device Found VID=%x "
1050 "DID=%x SSVID=%x SSDID=%x\n", pdev->vendor,
1051 pdev->device, subsys_vendor, subsys_device);
1052
1053 host = qla1280_do_device_init(pdev, template,
1054 devnum, bdp, num_hosts);
1055 if (!host)
1056 continue;
1057 ha = (struct scsi_qla_host *)host->hostdata;
1058
1059 if (qla1280_hostlist == NULL) {
1060 cur_ha = qla1280_hostlist = ha;
1061 } else {
1062 cur_ha = qla1280_hostlist;
1063 while (cur_ha->next != NULL)
1064 cur_ha = cur_ha->next;
1065 cur_ha->next = ha;
1066 }
1067 num_hosts++;
1068 }
1069 }
1070
1071 LEAVE("qla1280_detect");
1072 return num_hosts;
1073}
1074
1075
1076
1077
1078
1079
1080int
1081qla1280_release(struct Scsi_Host *host)
1082{
1083 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
1084
1085 ENTER("qla1280_release");
1086
1087 if (!ha->flags.online)
1088 return 0;
1089
1090
1091 WRT_REG_WORD(&ha->iobase->ictrl, 0);
1092
1093
1094 if (host->irq)
1095 free_irq(host->irq, ha);
1096
1097#if MEMORY_MAPPED_IO
1098 if (ha->mmpbase)
1099 iounmap((void *)(((unsigned long) ha->mmpbase) & PAGE_MASK));
1100#else
1101
1102 if (host->io_port)
1103 release_region(host->io_port, 0xff);
1104#endif
1105
1106 qla1280_mem_free(ha);
1107
1108 ENTER("qla1280_release");
1109 return 0;
1110}
1111
1112
1113
1114
1115
1116const char *
1117qla1280_info(struct Scsi_Host *host)
1118{
1119 static char qla1280_scsi_name_buffer[125];
1120 char *bp;
1121 struct scsi_qla_host *ha;
1122 struct qla_boards *bdp;
1123
1124 bp = &qla1280_scsi_name_buffer[0];
1125 ha = (struct scsi_qla_host *)host->hostdata;
1126 bdp = &ql1280_board_tbl[ha->devnum];
1127 memset(bp, 0, sizeof(qla1280_scsi_name_buffer));
1128 sprintf (bp,
1129 "QLogic %s PCI to SCSI Host Adapter: bus %d device %d irq %d\n"
1130 " Firmware version: %2d.%02d.%02d, Driver version %s",
1131 &bdp->bdName[0], ha->pci_bus, (ha->pci_device_fn & 0xf8) >> 3,
1132 host->irq, bdp->fwver[0], bdp->fwver[1], bdp->fwver[2],
1133 QLA1280_VERSION);
1134 return bp;
1135}
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148int
1149qla1280_queuecommand(Scsi_Cmnd * cmd, void (*fn) (Scsi_Cmnd *))
1150{
1151 struct scsi_qla_host *ha;
1152 srb_t *sp;
1153 struct Scsi_Host *host;
1154 int bus, target, lun;
1155 scsi_lu_t *q;
1156
1157
1158
1159
1160 host = cmd->host;
1161 ha = (struct scsi_qla_host *)host->hostdata;
1162
1163
1164 sp = (srb_t *)CMD_SP(cmd);
1165 sp->cmd = cmd;
1166 cmd->scsi_done = fn;
1167 if (cmd->flags == 0) {
1168 sp->flags = 0;
1169 }
1170
1171 qla1280_print_scsi_cmd(5, cmd);
1172
1173
1174 bus = SCSI_BUS_32(cmd);
1175 target = SCSI_TCN_32(cmd);
1176 lun = SCSI_LUN_32(cmd);
1177 if ((q = LU_Q(ha, bus, target, lun)) == NULL) {
1178 if ((q = (scsi_lu_t *)kmalloc(sizeof(struct scsi_lu),
1179 GFP_ATOMIC))) {
1180 LU_Q(ha, bus, target, lun) = q;
1181 memset(q, 0, sizeof(struct scsi_lu));
1182 dprintk(1, "Allocate new device queue 0x%p\n",
1183 (void *)q);
1184 } else {
1185 CMD_RESULT(cmd) = DID_BUS_BUSY << 16;
1186 qla1280_done_q_put(sp, &ha->done_q_first,
1187 &ha->done_q_last);
1188
1189#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
1190 schedule_work(&ha->run_qla_bh);
1191#else
1192 schedule_work(&ha->run_qla_bh);
1193#endif
1194 return 0;
1195 }
1196 }
1197
1198
1199 CMD_HANDLE(cmd) = (unsigned char *)INVALID_HANDLE;
1200
1201
1202 ha->qthreads++;
1203 qla1280_putq_t(q, sp);
1204
1205 dprintk(1, "qla1280_QC: t=%x CDB=%x I/OSize=0x%x haQueueCount=0x%lx\n",
1206 target, cmd->cmnd[0], cmd->request_bufflen, ha->qthreads);
1207
1208
1209 if (q->q_outcnt == 0)
1210 qla1280_restart_queues(ha);
1211
1212
1213 return 0;
1214}
1215
1216
1217
1218
1219
1220int
1221qla1280_abort(Scsi_Cmnd * cmd)
1222{
1223 struct scsi_qla_host *ha;
1224 srb_t *sp;
1225 struct Scsi_Host *host;
1226 unsigned int bus, target, lun;
1227 scsi_lu_t *q;
1228 int return_status = SCSI_ABORT_SUCCESS;
1229 int found = 0;
1230 int i;
1231 unsigned char *handle;
1232 u16 data;
1233
1234 ENTER("qla1280_abort");
1235 ha = (struct scsi_qla_host *)cmd->host->hostdata;
1236 host = cmd->host;
1237
1238
1239 sp = (srb_t *)CMD_SP(cmd);
1240 handle = CMD_HANDLE(cmd);
1241 if (qla1280_verbose)
1242 printk(KERN_ERR "scsi(%li): ABORT Command=0x%p, handle=0x%p\n",
1243 ha->host_no, (void *) cmd, (void *) handle);
1244
1245
1246 if (handle == NULL) {
1247
1248 printk(KERN_INFO "qla1280: Aborting a NULL handle\n");
1249 return SCSI_ABORT_NOT_RUNNING;
1250 }
1251 data = qla1280_debounce_register(&ha->iobase->istatus);
1252
1253
1254
1255
1256
1257
1258
1259
1260 if (data & RISC_INT) {
1261
1262 qla1280_isr(ha, &ha->done_q_first, &ha->done_q_last);
1263 }
1264
1265
1266
1267
1268#ifdef UNUSED
1269 handle = CMD_HANDLE(cmd);
1270#endif
1271
1272
1273 bus = SCSI_BUS_32(cmd);
1274 target = SCSI_TCN_32(cmd);
1275 lun = SCSI_LUN_32(cmd);
1276 if ((q = LU_Q(ha, bus, target, lun)) == NULL) {
1277
1278 printk(KERN_WARNING "qla1280 (%d:%d:%d): No LUN queue for the "
1279 "specified device\n", bus, target, lun);
1280 return SCSI_ABORT_NOT_RUNNING;
1281 }
1282#if AUTO_ESCALATE_ABORT
1283 if ((sp->flags & SRB_ABORTED)) {
1284 dprintk(1, "qla1280_abort: Abort escalayted - returning "
1285 "SCSI_ABORT_SNOOZE.\n");
1286 return SCSI_ABORT_SNOOZE;
1287 }
1288#endif
1289
1290 if ((sp->flags & SRB_ABORT_PENDING)) {
1291 if (qla1280_verbose)
1292 printk(KERN_WARNING
1293 "scsi(): Command has a pending abort "
1294 "message - ABORT_PENDING.\n");
1295
1296 return SCSI_ABORT_PENDING;
1297 }
1298#if STOP_ON_ABORT
1299 printk(KERN_WARNING "Scsi layer issued a ABORT command= 0x%p\n", cmd);
1300 qla1280_print_scsi_cmd(2, cmd);
1301#endif
1302
1303
1304
1305
1306
1307
1308 if (!(sp->flags & SRB_SENT)) {
1309 found++;
1310 if (qla1280_verbose)
1311 printk(KERN_WARNING
1312 "scsi(): Command returned from queue "
1313 "aborted.\n");
1314
1315
1316 qla1280_removeq(q, sp);
1317 sp->flags |= SRB_ABORTED;
1318 CMD_RESULT(cmd) = DID_ABORT << 16;
1319 qla1280_done_q_put(sp, &ha->done_q_first, &ha->done_q_last);
1320 return_status = SCSI_ABORT_SUCCESS;
1321 } else {
1322 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
1323 if (sp == ha->outstanding_cmds[i]) {
1324 found++;
1325 dprintk(1,
1326 "qla1280: RISC aborting command.\n");
1327 qla1280_abort_command(ha, sp);
1328 return_status = SCSI_ABORT_PENDING;
1329 break;
1330 }
1331 }
1332 }
1333
1334#if STOP_ON_ABORT
1335 qla1280_panic("qla1280_abort", ha->host);
1336#endif
1337 if (found == 0)
1338 return_status = SCSI_ABORT_NOT_RUNNING;
1339
1340 dprintk(1, "qla1280_abort: Aborted status returned = 0x%x.\n",
1341 return_status);
1342
1343 if (ha->done_q_first)
1344 qla1280_done(ha, &ha->done_q_first, &ha->done_q_last);
1345 if (found)
1346 qla1280_restart_queues(ha);
1347
1348 LEAVE("qla1280_abort");
1349 return return_status;
1350}
1351
1352int
1353qla1280_new_abort(Scsi_Cmnd * cmd)
1354{
1355 struct scsi_qla_host *ha;
1356 srb_t *sp;
1357 struct Scsi_Host *host;
1358 int bus, target, lun;
1359 scsi_lu_t *q;
1360 unsigned long cpu_flags;
1361 int return_status = SCSI_ABORT_SUCCESS;
1362 int found = 0;
1363 int i;
1364 unsigned char *handle;
1365 u16 data;
1366
1367 ENTER("qla1280_abort");
1368 host = cmd->host;
1369 ha = (struct scsi_qla_host *)host->hostdata;
1370
1371
1372 sp = (srb_t *) CMD_SP(cmd);
1373 handle = CMD_HANDLE(cmd);
1374 if (qla1280_verbose)
1375 printk(KERN_ERR "scsi(%li): ABORT Command=0x%p, handle=0x%p\n",
1376 ha->host_no, cmd, handle);
1377
1378
1379 if (handle == NULL) {
1380
1381 printk(KERN_INFO "qla1280: Aborting a NULL handle\n");
1382 return SUCCESS;
1383 }
1384
1385 spin_lock_irqsave (ha->host->host_lock, cpu_flags);
1386 data = qla1280_debounce_register(&ha->iobase->istatus);
1387
1388
1389
1390
1391
1392
1393
1394
1395 if (data & RISC_INT) {
1396
1397 qla1280_isr(ha, &ha->done_q_first, &ha->done_q_last);
1398 }
1399
1400
1401 bus = SCSI_BUS_32(cmd);
1402 target = SCSI_TCN_32(cmd);
1403 lun = SCSI_LUN_32(cmd);
1404 if ((q = LU_Q(ha, bus, target, lun)) == NULL) {
1405
1406 printk(KERN_WARNING "qla1280 (%d:%d:%d): No LUN queue for the "
1407 "specified device\n", bus, target, lun);
1408 return_status = SUCCESS;
1409 goto out;
1410 }
1411
1412 if ((sp->flags & SRB_ABORT_PENDING)) {
1413 if (qla1280_verbose)
1414 printk(KERN_WARNING
1415 "scsi(): Command has a pending abort "
1416 "message - ABORT_PENDING.\n");
1417
1418 return_status = SCSI_ABORT_PENDING;
1419 goto out;
1420 }
1421#if STOP_ON_ABORT
1422 printk(KERN_WARNING "Scsi layer issued a ABORT command= 0x%p\n", cmd);
1423 qla1280_print_scsi_cmd(2, cmd);
1424#endif
1425
1426
1427
1428
1429
1430
1431 if (!(sp->flags & SRB_SENT)) {
1432 found++;
1433 if (qla1280_verbose)
1434 printk(KERN_WARNING
1435 "scsi(): Command returned from queue "
1436 "aborted.\n");
1437
1438
1439 qla1280_removeq(q, sp);
1440 sp->flags |= SRB_ABORTED;
1441 CMD_RESULT(cmd) = DID_ABORT << 16;
1442 qla1280_done_q_put(sp, &ha->done_q_first, &ha->done_q_last);
1443 return_status = SUCCESS;
1444 } else {
1445 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
1446 if (sp == ha->outstanding_cmds[i]) {
1447 found++;
1448 dprintk(1,
1449 "qla1280: RISC aborting command.\n");
1450 qla1280_abort_command(ha, sp);
1451 return_status = SCSI_ABORT_PENDING;
1452 break;
1453 }
1454 }
1455 }
1456
1457#if STOP_ON_ABORT
1458 qla1280_panic("qla1280_abort", ha->host);
1459#endif
1460 if (found == 0)
1461 return_status = SUCCESS;
1462
1463 dprintk(1, "qla1280_abort: Aborted status returned = 0x%x.\n",
1464 return_status);
1465
1466 if (ha->done_q_first)
1467 qla1280_done(ha, &ha->done_q_first, &ha->done_q_last);
1468 if (found)
1469 qla1280_restart_queues(ha);
1470
1471 out:
1472 spin_unlock_irqrestore(ha->host->host_lock, cpu_flags);
1473
1474 LEAVE("qla1280_abort");
1475 return return_status;
1476}
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497int
1498qla1280_reset(Scsi_Cmnd * cmd, unsigned int flags)
1499{
1500 struct scsi_qla_host *ha;
1501 int bus, target, lun;
1502 srb_t *sp;
1503 typedef enum {
1504 ABORT_DEVICE = 1,
1505 DEVICE_RESET = 2,
1506 BUS_RESET = 3,
1507 ADAPTER_RESET = 4,
1508 RESET_DELAYED = 5,
1509 FAIL = 6
1510 } action_t;
1511 action_t action = ADAPTER_RESET;
1512 u16 data;
1513 scsi_lu_t *q;
1514 int result;
1515
1516 ENTER("qla1280_reset");
1517 if (qla1280_verbose)
1518 printk(KERN_INFO "scsi(): Resetting Cmnd=0x%p, Handle=0x%p, "
1519 "flags=0x%x\n", cmd, CMD_HANDLE(cmd), flags);
1520 if (cmd == NULL) {
1521 printk(KERN_WARNING
1522 "(scsi?:?:?:?) Reset called with NULL Scsi_Cmnd "
1523 "pointer, failing.\n");
1524 return SCSI_RESET_SNOOZE;
1525 }
1526 ha = (struct scsi_qla_host *)cmd->host->hostdata;
1527 sp = (srb_t *)CMD_SP(cmd);
1528
1529#if STOP_ON_RESET
1530 qla1280_panic("qla1280_reset", ha->host);
1531#endif
1532
1533
1534 data = qla1280_debounce_register(&ha->iobase->istatus);
1535
1536
1537
1538
1539
1540 if (data & RISC_INT)
1541 qla1280_isr(ha, &ha->done_q_first, &ha->done_q_last);
1542
1543
1544
1545
1546
1547 if (CMD_HANDLE(cmd) == NULL) {
1548
1549
1550
1551
1552
1553 if (flags & SCSI_RESET_SUGGEST_HOST_RESET)
1554 action = ADAPTER_RESET;
1555 else
1556 action = BUS_RESET;
1557 } else {
1558
1559
1560
1561
1562 if (flags & SCSI_RESET_SUGGEST_HOST_RESET)
1563 action = ADAPTER_RESET;
1564 else if (flags & SCSI_RESET_SUGGEST_BUS_RESET)
1565 action = BUS_RESET;
1566 else
1567 action = DEVICE_RESET;
1568 }
1569
1570 bus = SCSI_BUS_32(cmd);
1571 target = SCSI_TCN_32(cmd);
1572 lun = SCSI_LUN_32(cmd);
1573 q = LU_Q(ha, bus, target, lun);
1574
1575#if AUTO_ESCALATE_RESET
1576 if ((action & DEVICE_RESET) && (q->q_flag & QLA1280_QRESET)) {
1577 printk(KERN_INFO
1578 "qla1280(%ld): Bus device reset already sent to "
1579 "device, escalating.\n", ha->host_no);
1580 action = BUS_RESET;
1581 }
1582 if ((action & DEVICE_RESET) && (sp->flags & SRB_ABORT_PENDING)) {
1583 printk(KERN_INFO
1584 "qla1280(%ld):Have already attempted to reach "
1585 "device with abort device\n", ha->host_no);
1586 printk(KERN_INFO "qla1280(%ld):message, will escalate to BUS "
1587 "RESET.\n", ha->host_no);
1588 action = BUS_RESET;
1589 }
1590#endif
1591
1592
1593
1594
1595
1596 result = SCSI_RESET_ERROR;
1597 switch (action) {
1598 case FAIL:
1599 break;
1600
1601 case RESET_DELAYED:
1602 result = SCSI_RESET_PENDING;
1603 break;
1604
1605 case ABORT_DEVICE:
1606 ha->flags.in_reset = TRUE;
1607 if (qla1280_verbose)
1608 printk(KERN_INFO
1609 "scsi(%ld:%d:%d:%d): Queueing abort device "
1610 "command.\n", ha->host_no, bus, target, lun);
1611 qla1280_abort_queue_single(ha, bus, target, lun, DID_ABORT);
1612 if (qla1280_abort_device(ha, bus, target, lun) == 0)
1613 result = SCSI_RESET_PENDING;
1614 break;
1615
1616 case DEVICE_RESET:
1617 if (qla1280_verbose)
1618 printk(KERN_INFO
1619 "scsi(%ld:%d:%d:%d): Queueing device reset "
1620 "command.\n", ha->host_no, bus, target, lun);
1621 ha->flags.in_reset = TRUE;
1622 for (lun = 0; lun < MAX_LUNS; lun++)
1623 qla1280_abort_queue_single(ha, bus, target, lun,
1624 DID_ABORT);
1625 if (qla1280_device_reset(ha, bus, target) == 0)
1626 result = SCSI_RESET_PENDING;
1627 q->q_flag |= QLA1280_QRESET;
1628 break;
1629
1630 case BUS_RESET:
1631 if (qla1280_verbose)
1632 printk(KERN_INFO "qla1280(%ld:%d:%d:%d): Issuing BUS "
1633 "DEVICE RESET.\n", ha->host_no, bus, target,
1634 lun);
1635 ha->flags.in_reset = TRUE;
1636 for (target = 0; target < MAX_TARGETS; target++)
1637 for (lun = 0; lun < MAX_LUNS; lun++)
1638 qla1280_abort_queue_single(ha, bus, target,
1639 lun, DID_RESET);
1640 qla1280_bus_reset(ha, bus);
1641
1642
1643
1644
1645
1646
1647
1648 result = SCSI_RESET_SUCCESS | SCSI_RESET_BUS_RESET;
1649
1650
1651
1652 mdelay(4 * 1000);
1653 barrier();
1654 if (flags & SCSI_RESET_SYNCHRONOUS) {
1655 CMD_RESULT(cmd) = DID_BUS_BUSY << 16;
1656 (*(cmd)->scsi_done)(cmd);
1657 }
1658
1659 break;
1660
1661 case ADAPTER_RESET:
1662 default:
1663 if (qla1280_verbose) {
1664 printk(KERN_INFO
1665 "scsi(%ld:%d:%d:%d): Issued an ADAPTER "
1666 "RESET.\n", ha->host_no, bus, target, lun);
1667 printk(KERN_INFO
1668 "scsi(%ld:%d:%d:%d): I/O processing will "
1669 "continue automatically.\n", ha->host_no, bus,
1670 target, lun);
1671 }
1672 ha->flags.reset_active = TRUE;
1673
1674
1675
1676
1677 if (qla1280_abort_isp(ha) == 0)
1678 result = SCSI_RESET_SUCCESS | SCSI_RESET_HOST_RESET;
1679
1680 ha->flags.reset_active = FALSE;
1681 }
1682
1683 if (ha->done_q_first)
1684 qla1280_done(ha, &ha->done_q_first, &ha->done_q_last);
1685 qla1280_restart_queues(ha);
1686 ha->flags.in_reset = FALSE;
1687
1688 dprintk(1, "RESET returning %d\n", result);
1689
1690 LEAVE("qla1280_reset");
1691 return result;
1692}
1693
1694
1695
1696
1697
1698int
1699qla1280_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1700 sector_t capacity, int geom[])
1701{
1702 int heads, sectors, cylinders;
1703
1704 heads = 64;
1705 sectors = 32;
1706 cylinders = (unsigned long)capacity / (heads * sectors);
1707 if (cylinders > 1024) {
1708 heads = 255;
1709 sectors = 63;
1710 cylinders = (unsigned long)capacity / (heads * sectors);
1711
1712
1713 }
1714
1715 geom[0] = heads;
1716 geom[1] = sectors;
1717 geom[2] = cylinders;
1718
1719 return 0;
1720}
1721
1722
1723
1724
1725
1726void
1727qla1280_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1728{
1729 struct scsi_qla_host *ha;
1730 struct device_reg *reg;
1731 u16 data;
1732
1733 ENTER_INTR ("qla1280_intr_handler");
1734 ha = (struct scsi_qla_host *)dev_id;
1735
1736 spin_lock(ha->host->host_lock);
1737
1738 ha->isr_count++;
1739 reg = ha->iobase;
1740
1741 WRT_REG_WORD(®->ictrl, 0);
1742
1743 data = qla1280_debounce_register(®->istatus);
1744
1745 if (data & RISC_INT) {
1746 qla1280_isr(ha, &ha->done_q_first, &ha->done_q_last);
1747 } else {
1748
1749 dprintk(1, "scsi(%ld): Spurious interrupt - ignoring\n",
1750 ha->host_no);
1751 }
1752
1753 if (ha->done_q_first)
1754 qla1280_done(ha, &ha->done_q_first, &ha->done_q_last);
1755
1756 spin_unlock(ha->host->host_lock);
1757
1758
1759 WRT_REG_WORD(®->ictrl, (ISP_EN_INT | ISP_EN_RISC));
1760
1761 LEAVE_INTR("qla1280_intr_handler");
1762}
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776void
1777qla1280_do_dpc(void *p)
1778{
1779 struct scsi_qla_host *ha = (struct scsi_qla_host *) p;
1780 unsigned long cpu_flags;
1781
1782 spin_lock_irqsave(ha->host->host_lock, cpu_flags);
1783
1784 if (ha->flags.isp_abort_needed)
1785 qla1280_abort_isp(ha);
1786
1787 if (ha->flags.reset_marker)
1788 qla1280_rst_aen(ha);
1789
1790 if (ha->done_q_first)
1791 qla1280_done(ha, &ha->done_q_first, &ha->done_q_last);
1792
1793 spin_unlock_irqrestore(ha->host->host_lock, cpu_flags);
1794}
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807static int
1808qla1280_slave_configure(Scsi_Device * device)
1809{
1810 struct scsi_qla_host *p = (struct scsi_qla_host *)device->host->hostdata;
1811 int bus = device->channel;
1812 int target = device->id;
1813
1814 if (qla1280_check_for_dead_scsi_bus(p, bus))
1815 return 1;
1816 if (device->tagged_supported &&
1817 (p->bus_settings[bus].qtag_enables & (BIT_0 << target))) {
1818 scsi_adjust_queue_depth(device, MSG_ORDERED_TAG,
1819 p->bus_settings[bus].hiwat);
1820
1821 printk(KERN_INFO "scsi(%li:%d:%d:%d): Enabled tagged queuing, "
1822 "queue depth %d.\n", p->host_no, device->channel,
1823 device->id, device->lun, device->new_queue_depth);
1824 } else {
1825 scsi_adjust_queue_depth(device, 0 , 3);
1826 }
1827 qla12160_get_target_parameters(p, bus, target, device->lun);
1828 return 0;
1829}
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844static void
1845qla1280_done(struct scsi_qla_host *ha, srb_t ** done_q_first,
1846 srb_t ** done_q_last)
1847{
1848 srb_t *sp;
1849 scsi_lu_t *q;
1850 int bus, target, lun;
1851 Scsi_Cmnd *cmd;
1852
1853 ENTER("qla1280_done");
1854
1855 while (*done_q_first != NULL) {
1856
1857 sp = *done_q_first;
1858 if (!(*done_q_first = sp->s_next))
1859 *done_q_last = NULL;
1860 else
1861 (*done_q_first)->s_prev = NULL;
1862
1863 cmd = sp->cmd;
1864 bus = SCSI_BUS_32(cmd);
1865 target = SCSI_TCN_32(cmd);
1866 lun = SCSI_LUN_32(cmd);
1867 q = LU_Q(ha, bus, target, lun);
1868
1869
1870 if (q->q_outcnt)
1871 q->q_outcnt--;
1872 if (q->q_outcnt < ha->bus_settings[bus].hiwat) {
1873 q->q_flag &= ~QLA1280_QBUSY;
1874 }
1875
1876 q->io_cnt++;
1877 if (sp->dir & BIT_5)
1878 q->r_cnt++;
1879 else
1880 q->w_cnt++;
1881
1882 switch ((CMD_RESULT(cmd) >> 16)) {
1883 case DID_RESET:
1884 q->q_flag &= ~QLA1280_QRESET;
1885
1886 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
1887 break;
1888 case DID_ABORT:
1889 sp->flags &= ~SRB_ABORT_PENDING;
1890 sp->flags |= SRB_ABORTED;
1891 if (sp->flags & SRB_TIMEOUT)
1892 CMD_RESULT(sp->cmd) = DID_TIME_OUT << 16;
1893 break;
1894 default:
1895 break;
1896 }
1897
1898
1899
1900 if (cmd->use_sg) {
1901 dprintk(1, "S/G unmap_sg cmd=%p\n", cmd);
1902
1903 pci_unmap_sg(ha->pdev, cmd->request_buffer,
1904 cmd->use_sg,
1905 scsi_to_pci_dma_dir(cmd->sc_data_direction));
1906 } else if (cmd->request_bufflen) {
1907
1908
1909
1910 pci_unmap_single(ha->pdev, sp->saved_dma_handle,
1911 cmd->request_bufflen,
1912 scsi_to_pci_dma_dir(cmd->sc_data_direction));
1913 }
1914
1915
1916 CMD_HANDLE(sp->cmd) = NULL;
1917 ha->actthreads--;
1918
1919 (*(cmd)->scsi_done)(cmd);
1920
1921 qla1280_next(ha, q, bus);
1922 }
1923 LEAVE("qla1280_done");
1924}
1925
1926
1927
1928
1929static int
1930qla1280_return_status(sts_entry_t * sts, Scsi_Cmnd * cp)
1931{
1932 int host_status = DID_ERROR;
1933#if DEBUG_QLA1280_INTR
1934 static char *reason[] = {
1935 "DID_OK",
1936 "DID_NO_CONNECT",
1937 "DID_BUS_BUSY",
1938 "DID_TIME_OUT",
1939 "DID_BAD_TARGET",
1940 "DID_ABORT",
1941 "DID_PARITY",
1942 "DID_ERROR",
1943 "DID_RESET",
1944 "DID_BAD_INTR"
1945 };
1946#endif
1947
1948 ENTER("qla1280_return_status");
1949
1950#if DEBUG_QLA1280_INTR
1951
1952
1953
1954
1955#endif
1956 switch (sts->comp_status) {
1957 case CS_COMPLETE:
1958 host_status = DID_OK;
1959 break;
1960
1961 case CS_INCOMPLETE:
1962 if (!(sts->state_flags & SF_GOT_BUS))
1963 host_status = DID_NO_CONNECT;
1964 else if (!(sts->state_flags & SF_GOT_TARGET))
1965 host_status = DID_BAD_TARGET;
1966 else if (!(sts->state_flags & SF_SENT_CDB))
1967 host_status = DID_ERROR;
1968 else if (!(sts->state_flags & SF_TRANSFERRED_DATA))
1969 host_status = DID_ERROR;
1970 else if (!(sts->state_flags & SF_GOT_STATUS))
1971 host_status = DID_ERROR;
1972 else if (!(sts->state_flags & SF_GOT_SENSE))
1973 host_status = DID_ERROR;
1974 break;
1975
1976 case CS_RESET:
1977 host_status = DID_RESET;
1978 break;
1979
1980 case CS_ABORTED:
1981 host_status = DID_ABORT;
1982 break;
1983
1984 case CS_TIMEOUT:
1985 host_status = DID_TIME_OUT;
1986 break;
1987
1988 case CS_DATA_OVERRUN:
1989 dprintk(2, "Data overrun 0x%x\n", sts->residual_length);
1990 dprintk(2, "qla1280_isr: response packet data\n");
1991 qla1280_dump_buffer(2, (char *)sts, RESPONSE_ENTRY_SIZE);
1992 host_status = DID_ERROR;
1993 break;
1994
1995 case CS_DATA_UNDERRUN:
1996 if ((cp->request_bufflen - sts->residual_length) <
1997 cp->underflow) {
1998 printk(KERN_WARNING
1999 "scsi: Underflow detected - retrying "
2000 "command.\n");
2001 host_status = DID_ERROR;
2002 } else
2003 host_status = DID_OK;
2004 break;
2005
2006 default:
2007 host_status = DID_ERROR;
2008 break;
2009 }
2010
2011#if DEBUG_QLA1280_INTR
2012 dprintk(1, "qla1280 ISP status: host status (%s) scsi status %x\n",
2013 reason[host_status], sts->scsi_status);
2014#endif
2015
2016 LEAVE("qla1280_return_status");
2017
2018 return (sts->scsi_status & 0xff) | (host_status << 16);
2019}
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030static void
2031qla1280_done_q_put(srb_t * sp, srb_t ** done_q_first, srb_t ** done_q_last)
2032{
2033 ENTER("qla1280_put_done_q");
2034
2035
2036 sp->s_next = NULL;
2037 sp->s_prev = *done_q_last;
2038 if (!*done_q_first)
2039 *done_q_first = sp;
2040 else
2041 (*done_q_last)->s_next = sp;
2042 *done_q_last = sp;
2043
2044 LEAVE("qla1280_put_done_q");
2045}
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060static void
2061qla1280_next(struct scsi_qla_host *ha, scsi_lu_t * q, int bus)
2062{
2063 srb_t *sp;
2064 int cnt, status;
2065
2066 ENTER("qla1280_next");
2067
2068 while (((sp = q->q_first) != NULL) &&
2069
2070 !(q->q_flag & (QLA1280_QBUSY | QLA1280_QSUSP)) && !ha->flags.abort_isp_active) {
2071
2072 qla1280_removeq(q, sp);
2073
2074 dprintk(1, "starting request 0x%p<-(0x%p)\n", q, sp);
2075 {
2076
2077 q->q_outcnt++;
2078 if (q->q_outcnt >= ha->bus_settings[bus].hiwat)
2079 q->q_flag |= QLA1280_QBUSY;
2080
2081#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,18)
2082 if (ha->flags.enable_64bit_addressing)
2083 status = qla1280_64bit_start_scsi(ha, sp);
2084 else
2085#endif
2086 status = qla1280_32bit_start_scsi(ha, sp);
2087
2088 if (status) {
2089 if (q->q_outcnt == 1) {
2090
2091 for (cnt = 6000000; cnt; cnt--) {
2092#if QLA_64BIT_PTR
2093 if (ha->flags.enable_64bit_addressing)
2094 status =
2095 qla1280_64bit_start_scsi(ha, sp);
2096 else
2097#endif
2098 status =
2099 qla1280_32bit_start_scsi(ha, sp);
2100
2101 if (!status)
2102 break;
2103
2104
2105 qla1280_poll(ha);
2106
2107 udelay(5);
2108 }
2109 if (!cnt) {
2110
2111 CMD_RESULT(sp->cmd) =
2112 DID_TIME_OUT << 16;
2113
2114#if WATCHDOGTIMER
2115
2116 if (sp->flags & SRB_WATCHDOG)
2117 qla1280_timeout_remove
2118 (ha, sp);
2119#endif
2120 CMD_HANDLE(sp->cmd) = NULL;
2121
2122
2123 (*(sp->cmd)->scsi_done)(sp->cmd);
2124
2125 if (q->q_outcnt)
2126 q->q_outcnt--;
2127 }
2128 } else {
2129 qla1280_putq_t(q, sp);
2130
2131 if (q->q_outcnt)
2132 q->q_outcnt--;
2133 if (q->q_outcnt <
2134 ha->bus_settings[bus].hiwat)
2135 q->q_flag &= ~QLA1280_QBUSY;
2136 break;
2137 }
2138 }
2139 }
2140 }
2141
2142 LEAVE("qla1280_next");
2143}
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154static void
2155qla1280_putq_t(scsi_lu_t * q, srb_t * sp)
2156{
2157 ENTER("qla1280_putq_t");
2158
2159 dprintk(1, "Adding to device q=0x%p<-(0x%p)sp\n", (void *) q,
2160 (void *) sp);
2161
2162 sp->s_next = NULL;
2163 if (!q->q_first) {
2164 sp->s_prev = NULL;
2165 q->q_first = sp;
2166 q->q_last = sp;
2167 } else {
2168 sp->s_prev = q->q_last;
2169 q->q_last->s_next = sp;
2170 q->q_last = sp;
2171 }
2172
2173 LEAVE("qla1280_putq_t");
2174}
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186static void
2187qla1280_removeq(scsi_lu_t * q, srb_t * sp)
2188{
2189 dprintk(1, "Removing from device_q (0x%p)->(0x%p)\n", q, sp);
2190
2191 if (sp->s_prev) {
2192 if ((sp->s_prev->s_next = sp->s_next) != NULL)
2193 sp->s_next->s_prev = sp->s_prev;
2194 else
2195 q->q_last = sp->s_prev;
2196 } else if (!(q->q_first = sp->s_next))
2197 q->q_last = NULL;
2198 else
2199 q->q_first->s_prev = NULL;
2200}
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210static int
2211qla1280_mem_alloc(struct scsi_qla_host *ha)
2212{
2213 int status = 1;
2214 dma_addr_t dma_handle;
2215
2216 ENTER("qla1280_mem_alloc");
2217
2218
2219
2220 ha->request_ring = pci_alloc_consistent(ha->pdev,
2221 ((REQUEST_ENTRY_CNT + 1) *
2222 (sizeof(request_t))),
2223 &dma_handle);
2224 if (!ha->request_ring)
2225 goto error;
2226 ha->request_dma = dma_handle;
2227 ha->response_ring = pci_alloc_consistent(ha->pdev,
2228 ((RESPONSE_ENTRY_CNT + 1) *
2229 (sizeof(response_t))),
2230 &dma_handle);
2231 if (!ha->request_ring)
2232 goto error;
2233 ha->response_dma = dma_handle;
2234 status = 0;
2235
2236 error:
2237 if (status)
2238 dprintk(2, "qla1280_mem_alloc: **** FAILED ****\n");
2239
2240 LEAVE("qla1280_mem_alloc");
2241 return status;
2242}
2243
2244
2245
2246
2247
2248
2249
2250
2251static void
2252qla1280_mem_free(struct scsi_qla_host *ha)
2253{
2254 scsi_lu_t *q;
2255 int bus, target, lun;
2256
2257 ENTER("qlc1280_mem_free");
2258 if (ha) {
2259
2260 for (bus = 0; bus < MAX_BUSES; bus++) {
2261 q = LU_Q(ha, bus, ha->bus_settings[bus].id, 0);
2262 for (target = 0; target < MAX_TARGETS; target++)
2263 for (lun = 0; lun < MAX_LUNS; lun++)
2264 if (LU_Q(ha, bus, target, lun) != NULL
2265 && LU_Q(ha, bus, target, lun) != q)
2266 kfree(LU_Q(ha, bus, target, lun));
2267 kfree(q);
2268 }
2269 for (bus = 0; bus < MAX_EQ; bus++)
2270 ha->dev[bus] = NULL;
2271 }
2272
2273
2274
2275 if (ha->request_ring)
2276 pci_free_consistent(ha->pdev,
2277 ((REQUEST_ENTRY_CNT + 1) *
2278 (sizeof(request_t))),
2279 ha->request_ring, ha->request_dma);
2280
2281 if (ha->response_ring)
2282 pci_free_consistent(ha->pdev,
2283 ((RESPONSE_ENTRY_CNT + 1) *
2284 (sizeof(response_t))),
2285 ha->response_ring, ha->response_dma);
2286
2287 if (qla1280_buffer) {
2288 free_page((unsigned long) qla1280_buffer);
2289 qla1280_buffer = NULL;
2290 }
2291
2292 LEAVE("qlc1280_mem_free");
2293}
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309static inline void
2310qla1280_enable_intrs(struct scsi_qla_host *ha)
2311{
2312 struct device_reg *reg;
2313
2314 reg = ha->iobase;
2315
2316 WRT_REG_WORD(®->ictrl, (ISP_EN_INT | ISP_EN_RISC));
2317 ha->flags.ints_enabled = 1;
2318#if 0
2319 printk("Enabling ints\n");
2320#endif
2321}
2322
2323static inline void
2324qla1280_disable_intrs(struct scsi_qla_host *ha)
2325{
2326 struct device_reg *reg;
2327
2328 reg = ha->iobase;
2329
2330 WRT_REG_WORD(®->ictrl, 0);
2331 ha->flags.ints_enabled = 0;
2332#if 0
2333 printk("Disabling ints\n");
2334#endif
2335}
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347static int
2348qla1280_initialize_adapter(struct scsi_qla_host *ha)
2349{
2350 struct device_reg *reg;
2351 int status;
2352 int bus;
2353
2354 ENTER("qla1280_initialize_adapter");
2355
2356
2357 ha->flags.online = FALSE;
2358 ha->flags.isp_abort_needed = FALSE;
2359 ha->flags.disable_host_adapter = FALSE;
2360 ha->flags.reset_active = FALSE;
2361 ha->flags.abort_isp_active = FALSE;
2362
2363 ha->flags.ints_enabled = FALSE;
2364
2365 dprintk(1, "Configure PCI space for adapter...\n");
2366
2367 reg = ha->iobase;
2368
2369
2370 WRT_REG_WORD(®->semaphore, 0);
2371 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
2372 WRT_REG_WORD(®->host_cmd, HC_CLR_HOST_INT);
2373
2374
2375 if (qla1280_verbose)
2376 printk(KERN_INFO "scsi(%li): Determining if RISC is "
2377 "loaded...\n", ha->host_no);
2378 if (qla1280_isp_firmware(ha)) {
2379 if (qla1280_verbose)
2380 printk(KERN_INFO "scsi(%ld): Verifying chip...\n",
2381 ha->host_no);
2382 if (!(status = qla1280_chip_diag (ha))) {
2383 if (qla1280_verbose)
2384 printk(KERN_INFO "scsi(%ld): Setup chip...\n",
2385 ha->host_no);
2386 status = qla1280_setup_chip(ha);
2387 }
2388 } else {
2389 printk(KERN_ERR "initialize: isp_firmware() failed!\n");
2390 status = 1;
2391 }
2392
2393 if (!status) {
2394
2395 if (qla1280_verbose)
2396 printk(KERN_INFO
2397 "scsi(%ld): Configure NVRAM parameters...\n",
2398 ha->host_no);
2399 qla1280_nvram_config(ha);
2400
2401 if (!ha->flags.disable_host_adapter
2402 && !qla1280_init_rings(ha)) {
2403
2404
2405 for (bus = 0; bus < ha->ports; bus++) {
2406 if (!ha->bus_settings[bus].disable_scsi_reset){
2407 if (qla1280_bus_reset(ha, bus)) {
2408 if (qla1280_bus_reset(ha, bus)) {
2409 ha->bus_settings[bus].scsi_bus_dead = TRUE;
2410 }
2411 }
2412 }
2413 }
2414 do {
2415
2416 ha->flags.reset_marker = FALSE;
2417 for (bus = 0; bus < ha->ports; bus++) {
2418 ha->bus_settings[bus].reset_marker = FALSE;
2419 qla1280_marker(ha, bus, 0, 0,
2420 MK_SYNC_ALL);
2421 }
2422 } while (ha->flags.reset_marker);
2423
2424 ha->flags.online = TRUE;
2425
2426
2427 for (bus = 0; bus < ha->ports; bus++) {
2428 if (!(status = qla1280_enable_tgt(ha, bus))) {
2429#if 0
2430 int cnt;
2431 for (cnt = 0; cnt < MAX_LUNS; cnt++) {
2432 qla1280_enable_lun(ha, bus,
2433 cnt);
2434 qla1280_poll(ha);
2435 }
2436#endif
2437 } else
2438 break;
2439 }
2440 } else
2441 status = 1;
2442 } else
2443 printk(KERN_ERR "scsi(%li): initialize: pci probe failed!\n",
2444 ha->host_no);
2445
2446 if (status)
2447 dprintk(2, "qla1280_initialize_adapter: **** FAILED ****\n");
2448
2449 LEAVE("qla1280_initialize_adapter");
2450 return status;
2451}
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464static int
2465qla1280_enable_tgt(struct scsi_qla_host *ha, int bus)
2466{
2467 int status = 0;
2468
2469
2470 dprintk(3, "qla1280_enable_tgt: entered\n");
2471
2472
2473#if 0
2474 mb[0] = MBC_ENABLE_TARGET_MODE;
2475 mb[1] = BIT_15;
2476 mb[2] = (uint16_t) (bus << 15);
2477 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2478#endif
2479 if (status)
2480 dprintk(2, "qla1280_enable_tgt: **** FAILED ****\n");
2481 else
2482 dprintk(3, "qla1280_enable_tgt: exiting normally\n");
2483
2484 return status;
2485}
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498static int
2499qla1280_isp_firmware(struct scsi_qla_host *ha)
2500{
2501 nvram_t *nv = (nvram_t *) ha->response_ring;
2502 uint16_t *wptr;
2503 int status = 0;
2504 int cnt;
2505 uint8_t chksum;
2506 uint16_t mb[MAILBOX_REGISTER_COUNT];
2507
2508 ENTER("qla1280_isp_firmware");
2509
2510
2511 wptr = (uint16_t *) ha->response_ring;
2512 dprintk(1, "qla1280_isp_firmware: Reading NVRAM\n");
2513
2514 chksum = 0;
2515 for (cnt = 0; cnt < sizeof(nvram_t) / 2; cnt++) {
2516 *wptr = qla1280_get_nvram_word (ha, cnt);
2517 chksum += (uint8_t) * wptr;
2518 chksum += (uint8_t) (*wptr >> 8);
2519 wptr++;
2520 }
2521 dprintk(1, "qla1280_isp_firmware: Completed Reading NVRAM\n");
2522
2523 dprintk(3, "qla1280_isp_firmware: NVRAM Magic ID= %c %c %c\n",
2524 (char *)nv->id[0], nv->id[1], nv->id[2]);
2525
2526
2527 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2528 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->version < 1) {
2529 printk(KERN_INFO "qla1280_isp_firmware: Bad checksum or magic "
2530 "number or version in NVRAM.\n");
2531 ha->flags.disable_risc_code_load = FALSE;
2532 } else
2533 ha->flags.disable_risc_code_load =
2534 nv->cntr_flags_1.disable_loading_risc_code;
2535
2536 if (ha->flags.disable_risc_code_load) {
2537 dprintk(3,
2538 "qla1280_isp_firmware: Telling RISC to verify checksum "
2539 "of loaded BIOS code.\n");
2540
2541
2542 mb[0] = MBC_VERIFY_CHECKSUM;
2543
2544 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2545
2546 if (!
2547 (status =
2548 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]))) {
2549
2550 dprintk(3, "qla1280_isp_firmware: Startng F/W "
2551 "execution.\n");
2552
2553 mb[0] = MBC_EXECUTE_FIRMWARE;
2554
2555 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2556 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2557 } else
2558 printk(KERN_INFO "qla1280: RISC checksum failed.\n");
2559 } else {
2560 dprintk(1, "qla1280: NVRAM configured to load RISC load.\n");
2561 status = 1;
2562 }
2563
2564 if (status)
2565 dprintk(2, "qla1280_isp_firmware: **** Load RISC code ****\n");
2566
2567 LEAVE("qla1280_isp_firmware");
2568 return status;
2569}
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581static int
2582qla1280_pci_config(struct scsi_qla_host *ha)
2583{
2584#if MEMORY_MAPPED_IO
2585 uint32_t page_offset, base;
2586 uint32_t mmapbase;
2587#endif
2588 uint16_t buf_wd;
2589 int status = 1;
2590
2591 ENTER("qla1280_pci_config");
2592
2593 pci_set_master(ha->pdev);
2594
2595
2596
2597
2598 pci_read_config_word (ha->pdev, PCI_COMMAND, &buf_wd);
2599#if MEMORY_MAPPED_IO
2600 dprintk(1, "qla1280: MEMORY MAPPED IO is enabled.\n");
2601 buf_wd |= PCI_COMMAND_MEMORY + PCI_COMMAND_IO;
2602#else
2603 buf_wd |= PCI_COMMAND_IO;
2604#endif
2605 pci_write_config_word (ha->pdev, PCI_COMMAND, buf_wd);
2606
2607
2608
2609 pci_read_config_word (ha->pdev, PCI_ROM_ADDRESS, &buf_wd);
2610 buf_wd &= ~PCI_ROM_ADDRESS_ENABLE;
2611 pci_write_config_word (ha->pdev, PCI_ROM_ADDRESS, buf_wd);
2612
2613 ha->host->io_port = pci_resource_start(ha->pdev, 0);
2614 ha->host->io_port &= PCI_BASE_ADDRESS_IO_MASK;
2615 ha->iobase = (struct device_reg *) ha->host->io_port;
2616
2617#if MEMORY_MAPPED_IO
2618
2619
2620
2621 pci_read_config_word (ha->pdev, PCI_BASE_ADDRESS_1, &mmapbase);
2622 mmapbase &= PCI_BASE_ADDRESS_MEM_MASK;
2623
2624
2625
2626
2627 base = mmapbase & PAGE_MASK;
2628 page_offset = mmapbase - base;
2629
2630
2631
2632 ha->mmpbase = ioremap(base, page_offset + 256);
2633 if (ha->mmpbase) {
2634 ha->mmpbase += page_offset;
2635
2636 status = 0;
2637 }
2638#else
2639 status = 0;
2640#endif
2641
2642 LEAVE("qla1280_pci_config");
2643 return status;
2644}
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656static int
2657qla1280_chip_diag(struct scsi_qla_host *ha)
2658{
2659 uint16_t mb[MAILBOX_REGISTER_COUNT];
2660 struct device_reg *reg = ha->iobase;
2661 int status = 0;
2662 int cnt;
2663 uint16_t data;
2664
2665 dprintk(3, "qla1280_chip_diag: testing device at 0x%p \n", ®->id_l);
2666
2667
2668 WRT_REG_WORD(®->ictrl, ISP_RESET);
2669 data = qla1280_debounce_register(®->ictrl);
2670
2671
2672
2673 for (cnt = 6000000; cnt && data & ISP_RESET; cnt--) {
2674 udelay(5);
2675 data = RD_REG_WORD(®->ictrl);
2676 }
2677 if (cnt) {
2678
2679 dprintk(3,
2680 "qla1280_chip_diag: reset register cleared by chip reset\n");
2681
2682 WRT_REG_WORD(®->cfg_1, 0);
2683
2684
2685
2686 WRT_REG_WORD(®->host_cmd, HC_RESET_RISC);
2687 WRT_REG_WORD(®->host_cmd, HC_RELEASE_RISC);
2688 WRT_REG_WORD(®->host_cmd, HC_DISABLE_BIOS);
2689 data = qla1280_debounce_register(®->mailbox0);
2690
2691
2692
2693 for (cnt = 6000000; cnt && data == MBS_BUSY; cnt--) {
2694 udelay(5);
2695 data = RD_REG_WORD(®->mailbox0);
2696 }
2697
2698 if (cnt) {
2699
2700 dprintk(3,
2701 "qla1280_chip_diag: Checking product ID of chip\n");
2702
2703 if (RD_REG_WORD(®->mailbox1) != PROD_ID_1 ||
2704 (RD_REG_WORD(®->mailbox2) != PROD_ID_2 &&
2705 RD_REG_WORD(®->mailbox2) != PROD_ID_2a) ||
2706 RD_REG_WORD(®->mailbox3) != PROD_ID_3 ||
2707 RD_REG_WORD(®->mailbox4) != PROD_ID_4) {
2708 printk(KERN_INFO
2709 "qla1280: Wrong product ID = 0x%x,0x%x,0x%x,"
2710 "0x%x\n", RD_REG_WORD(®->mailbox1),
2711 RD_REG_WORD(®->mailbox2),
2712 RD_REG_WORD(®->mailbox3),
2713 RD_REG_WORD(®->mailbox4));
2714 status = 1;
2715 } else {
2716
2717
2718
2719 qla1280_enable_intrs(ha);
2720 dprintk(1,
2721 "qla1280_chip_diag: Checking mailboxes of chip\n");
2722
2723 mb[0] = MBC_MAILBOX_REGISTER_TEST;
2724 mb[1] = 0xAAAA;
2725 mb[2] = 0x5555;
2726 mb[3] = 0xAA55;
2727 mb[4] = 0x55AA;
2728 mb[5] = 0xA5A5;
2729 mb[6] = 0x5A5A;
2730 mb[7] = 0x2525;
2731 if (!(status = qla1280_mailbox_command(ha,
2732 BIT_7 |
2733 BIT_6 |
2734 BIT_5 |
2735 BIT_4 |
2736 BIT_3 |
2737 BIT_2 |
2738 BIT_1 |
2739 BIT_0,
2740 &mb
2741 [0]))) {
2742 if (mb[1] != 0xAAAA ||
2743 mb[2] != 0x5555 ||
2744 mb[3] != 0xAA55 ||
2745 mb[4] != 0x55AA ||
2746 mb[5] != 0xA5A5 ||
2747 mb[6] != 0x5A5A ||
2748 mb[7] != 0x2525)
2749 status = 1;
2750 if (status == 1)
2751 printk(KERN_INFO
2752 "qla1280: Failed mailbox check\n");
2753 }
2754 }
2755 } else
2756 status = 1;
2757 } else
2758 status = 1;
2759
2760 if (status)
2761 dprintk(2, "qla1280_chip_diag: **** FAILED ****\n");
2762 else
2763 dprintk(3, "qla1280_chip_diag: exiting normally\n");
2764
2765 return status;
2766}
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778#define DUMP_IT_BACK 0
2779static int
2780qla1280_setup_chip(struct scsi_qla_host *ha)
2781{
2782 int status = 0;
2783 uint16_t risc_address;
2784 uint16_t *risc_code_address;
2785 int risc_code_size;
2786 uint16_t mb[MAILBOX_REGISTER_COUNT];
2787 uint16_t cnt;
2788 int num;
2789#if DUMP_IT_BACK
2790 int i;
2791 uint8_t *sp;
2792 uint8_t *tbuf;
2793#ifdef QLA_64BIT_PTR
2794 dma_addr_t p_tbuf;
2795#else
2796 uint32_t p_tbuf;
2797#endif
2798#endif
2799
2800 ENTER("qla1280_setup_chip");
2801
2802
2803#if DUMP_IT_BACK
2804
2805 tbuf = pci_alloc_consistent(ha->pdev, 8000, &p_tbuf);
2806#endif
2807
2808
2809 risc_address = *ql1280_board_tbl[ha->devnum].fwstart;
2810 risc_code_address = ql1280_board_tbl[ha->devnum].fwcode;
2811 risc_code_size = (int) *ql1280_board_tbl[ha->devnum].fwlen;
2812
2813 dprintk(1, "qla1280_setup_chip: DMA RISC code (%i) words\n",
2814 risc_code_size);
2815
2816 num = 0;
2817 while (risc_code_size > 0 && !status) {
2818 cnt = 2000 >> 1;
2819
2820 if (cnt > risc_code_size)
2821 cnt = risc_code_size;
2822
2823 dprintk(1, "qla1280_setup_chip: loading risc @ =(0x%p),"
2824 "%d,%d(0x%x)\n",
2825 risc_code_address, cnt, num, risc_address);
2826 memcpy(ha->request_ring, risc_code_address, (cnt << 1));
2827
2828 flush_cache_all();
2829
2830 mb[0] = MBC_LOAD_RAM;
2831 mb[1] = risc_address;
2832 mb[4] = cnt;
2833 mb[3] = ha->request_dma & 0xffff;
2834 mb[2] = (ha->request_dma >> 16) & 0xffff;
2835 mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
2836 mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
2837 dprintk(1, "qla1280_setup_chip: op=%d 0x%p = 0x%4x,0x%4x,"
2838 "0x%4x,0x%4x\n",
2839 mb[0], ha->request_dma, mb[6], mb[7], mb[2], mb[3]);
2840 if ((status = qla1280_mailbox_command(ha, BIT_4 | BIT_3 |
2841 BIT_2 | BIT_1 | BIT_0,
2842 &mb[0]))) {
2843 printk(KERN_ERR
2844 "Failed to load partial segment of f/w\n");
2845 break;
2846 }
2847#if DUMP_IT_BACK
2848 mb[0] = MBC_READ_RAM_WORD;
2849 mb[1] = risc_address;
2850 mb[4] = cnt;
2851 mb[3] = p_tbuf & 0xffff;
2852 mb[2] = (p_tbuf >> 16) & 0xffff;
2853 mb[7] = pci_dma_hi32(p_tbuf) & 0xffff;
2854 mb[6] = pci_dma_hi32(p_tbuf) >> 16;
2855
2856 if ((status = qla1280_mailbox_command(ha,
2857 BIT_4 | BIT_3 | BIT_2 |
2858 BIT_1 | BIT_0,
2859 &mb[0]))) {
2860 printk(KERN_ERR
2861 "Failed to dump partial segment of f/w\n");
2862 break;
2863 }
2864 sp = (uint8_t *)ha->request_ring;
2865 for (i = 0; i < (cnt << 1); i++) {
2866 if (tbuf[i] != sp[i]) {
2867 printk(KERN_ERR "qla1280_setup_chip: FW "
2868 "compare error @ byte(0x%x) loop#=%x\n",
2869 i, num);
2870 printk(KERN_ERR "setup_chip: FWbyte=%x "
2871 "FWfromChip=%x\n", sp[i], tbuf[i]);
2872
2873 }
2874 }
2875#endif
2876 risc_address += cnt;
2877 risc_code_size = risc_code_size - cnt;
2878 risc_code_address = risc_code_address + cnt;
2879 num++;
2880 }
2881
2882
2883 if (!status) {
2884 dprintk(1, "qla1280_setup_chip: Verifying checksum of "
2885 "loaded RISC code.\n");
2886 mb[0] = MBC_VERIFY_CHECKSUM;
2887
2888 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2889
2890 if (!(status =
2891 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]))) {
2892
2893 dprintk(1,
2894 "qla1280_setup_chip: start firmware running.\n");
2895 mb[0] = MBC_EXECUTE_FIRMWARE;
2896 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2897 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2898 } else
2899 printk(KERN_ERR
2900 "qla1280_setup_chip: Failed checksum.\n");
2901 }
2902
2903
2904#if DUMP_IT_BACK
2905
2906 pci_free_consistent(ha->pdev, 8000, tbuf, p_tbuf);
2907#endif
2908
2909 if (status)
2910 dprintk(2, "qla1280_setup_chip: **** FAILED ****\n");
2911
2912 LEAVE("qla1280_setup_chip");
2913 return status;
2914}
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929static int
2930qla1280_init_rings(struct scsi_qla_host *ha)
2931{
2932 uint16_t mb[MAILBOX_REGISTER_COUNT];
2933 int status = 0;
2934 int cnt;
2935
2936 ENTER("qla1280_init_rings");
2937
2938
2939 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
2940 ha->outstanding_cmds[cnt] = 0;
2941
2942
2943 ha->request_ring_ptr = ha->request_ring;
2944 ha->req_ring_index = 0;
2945 ha->req_q_cnt = REQUEST_ENTRY_CNT;
2946
2947 mb[0] = MBC_INIT_REQUEST_QUEUE_A64;
2948 mb[1] = REQUEST_ENTRY_CNT;
2949 mb[3] = ha->request_dma & 0xffff;
2950 mb[2] = (ha->request_dma >> 16) & 0xffff;
2951 mb[4] = 0;
2952 mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
2953 mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
2954 if (!(status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_4 |
2955 BIT_3 | BIT_2 | BIT_1 | BIT_0,
2956 &mb[0]))) {
2957
2958 ha->response_ring_ptr = ha->response_ring;
2959 ha->rsp_ring_index = 0;
2960
2961 mb[0] = MBC_INIT_RESPONSE_QUEUE_A64;
2962 mb[1] = RESPONSE_ENTRY_CNT;
2963 mb[3] = ha->response_dma & 0xffff;
2964 mb[2] = (ha->response_dma >> 16) & 0xffff;
2965 mb[5] = 0;
2966 mb[7] = pci_dma_hi32(ha->response_dma) & 0xffff;
2967 mb[6] = pci_dma_hi32(ha->response_dma) >> 16;
2968 status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_5 |
2969 BIT_3 | BIT_2 | BIT_1 | BIT_0,
2970 &mb[0]);
2971 }
2972
2973 if (status)
2974 dprintk(2, "qla1280_init_rings: **** FAILED ****\n");
2975
2976 LEAVE("qla1280_init_rings");
2977 return status;
2978}
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993static int
2994qla1280_nvram_config(struct scsi_qla_host *ha)
2995{
2996 struct device_reg *reg = ha->iobase;
2997 nvram_t *nv = (nvram_t *)ha->response_ring;
2998 int status = 0;
2999 int cnt;
3000 int bus, target, lun;
3001 uint16_t *wptr;
3002 uint16_t mb[MAILBOX_REGISTER_COUNT];
3003 uint8_t chksum;
3004 int nvsize;
3005
3006#if DEBUG_PRINT_NVRAM
3007 int saved_print_status = ql_debug_print;
3008#endif
3009 ENTER("qla1280_nvram_config");
3010
3011
3012#if USE_NVRAM_DEFAULTS
3013 chksum = 1;
3014#else
3015 wptr = (uint16_t *) ha->response_ring;
3016 chksum = 0;
3017 if (ha->device_id == PCI_DEVICE_ID_QLOGIC_ISP12160 ||
3018 ha->device_id == PCI_DEVICE_ID_QLOGIC_ISP10160)
3019 nvsize = sizeof(nvram160_t) / 2;
3020 else
3021 nvsize = sizeof(nvram_t) / 2;
3022 for (cnt = 0; cnt < nvsize; cnt++) {
3023 *wptr = qla1280_get_nvram_word(ha, cnt);
3024 chksum += (uint8_t) * wptr;
3025 chksum += (uint8_t) (*wptr >> 8);
3026 wptr++;
3027 }
3028#endif
3029
3030
3031 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
3032 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->version < 1) {
3033#if USE_NVRAM_DEFAULTS
3034 dprintk(1, "Using defaults for NVRAM\n");
3035#else
3036 dprintk(1, "Using defaults for NVRAM: \n");
3037 dprintk(1, "checksum=0x%x, Id=%c, version=0x%x\n",
3038 chksum, nv->id[0], nv->version);
3039 memset(ha->response_ring, 0, sizeof(nvram_t));
3040#endif
3041
3042
3043 nv->firmware_feature.w = BIT_0;
3044 nv->termination.f.scsi_bus_0_control = 3;
3045 nv->termination.f.scsi_bus_1_control = 3;
3046 nv->termination.f.auto_term_support = 1;
3047
3048 for (bus = 0; bus < MAX_BUSES; bus++) {
3049 nv->bus[bus].config_1.initiator_id = 7;
3050 nv->bus[bus].bus_reset_delay = 5;
3051 nv->bus[bus].config_2.async_data_setup_time = 9;
3052 nv->bus[bus].config_2.req_ack_active_negation = 1;
3053 nv->bus[bus].config_2.data_line_active_negation = 1;
3054 nv->bus[bus].selection_timeout = 250;
3055 nv->bus[bus].max_queue_depth = 256;
3056
3057 for (target = 0; target < MAX_TARGETS; target++) {
3058 nv->bus[bus].target[target].parameter.f.
3059 auto_request_sense = 1;
3060 nv->bus[bus].target[target].parameter.f.
3061 disconnect_allowed = 1;
3062 nv->bus[bus].target[target].parameter.f.
3063 tag_queuing = 1;
3064 nv->bus[bus].target[target].flags.
3065 device_enable = 1;
3066 }
3067 }
3068
3069#if USE_NVRAM_DEFAULTS
3070 status = 0;
3071#else
3072 status = 1;
3073#endif
3074 } else {
3075
3076 for (bus = 0; bus < MAX_BUSES; bus++)
3077 for (target = 0; target < MAX_TARGETS; target++) {
3078 nv->bus[bus].target[target].parameter.f.
3079 auto_request_sense = 1;
3080 }
3081 }
3082#if DEBUG_PRINT_NVRAM
3083 ql_debug_print = 1;
3084#endif
3085 dprintk(1, "qla1280 : initiator scsi id bus[0]=%d\n",
3086 nv->bus[0].config_1.initiator_id);
3087 dprintk(1, "qla1280 : initiator scsi id bus[1]=%d\n",
3088 nv->bus[1].config_1.initiator_id);
3089
3090 dprintk(1, "qla1280 : bus reset delay[0]=%d\n",
3091 nv->bus[0].bus_reset_delay);
3092 dprintk(1, "qla1280 : bus reset delay[1]=%d\n",
3093 nv->bus[1].bus_reset_delay);
3094
3095 dprintk(1, "qla1280 : retry count[0]=%d\n", nv->bus[0].retry_count);
3096 dprintk(1, "qla1280 : retry delay[0]=%d\n", nv->bus[0].retry_delay);
3097 dprintk(1, "qla1280 : retry count[1]=%d\n", nv->bus[1].retry_count);
3098 dprintk(1, "qla1280 : retry delay[1]=%d\n", nv->bus[1].retry_delay);
3099
3100 dprintk(1, "qla1280 : async data setup time[0]=%d\n",
3101 nv->bus[0].config_2.async_data_setup_time);
3102 dprintk(1, "qla1280 : async data setup time[1]=%d\n",
3103 nv->bus[1].config_2.async_data_setup_time);
3104
3105 dprintk(1, "qla1280 : req/ack active negation[0]=%d\n",
3106 nv->bus[0].config_2.req_ack_active_negation);
3107 dprintk(1, "qla1280 : req/ack active negation[1]=%d\n",
3108 nv->bus[1].config_2.req_ack_active_negation);
3109
3110 dprintk(1, "qla1280 : data line active negation[0]=%d\n",
3111 nv->bus[0].config_2.data_line_active_negation);
3112 dprintk(1, "qla1280 : data line active negation[1]=%d\n",
3113 nv->bus[1].config_2.data_line_active_negation);
3114
3115 dprintk(1, "qla1280 : disable loading risc code=%d\n",
3116 nv->cntr_flags_1.disable_loading_risc_code);
3117
3118 dprintk(1, "qla1280 : enable 64bit addressing=%d\n",
3119 nv->cntr_flags_1.enable_64bit_addressing);
3120
3121 dprintk(1, "qla1280 : selection timeout limit[0]=%d\n",
3122 nv->bus[0].selection_timeout);
3123 dprintk(1, "qla1280 : selection timeout limit[1]=%d\n",
3124 nv->bus[1].selection_timeout);
3125
3126 dprintk(1, "qla1280 : max queue depth[0]=%d\n",
3127 nv->bus[0].max_queue_depth);
3128 dprintk(1, "qla1280 : max queue depth[1]=%d\n",
3129 nv->bus[1].max_queue_depth);
3130
3131
3132 ha->flags.disable_risc_code_load =
3133 nv->cntr_flags_1.disable_loading_risc_code;
3134
3135#ifdef QLA_64BIT_PTR
3136
3137
3138
3139
3140 ha->flags.enable_64bit_addressing = 1;
3141#else
3142 ha->flags.enable_64bit_addressing = 0;
3143#endif
3144
3145#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,18)
3146 if (ha->flags.enable_64bit_addressing) {
3147 printk(KERN_INFO "scsi(%li): 64 Bit PCI Addressing Enabled\n",
3148 ha->host_no);
3149
3150 pci_set_dma_mask(ha->pdev, (dma_addr_t) ~ 0ULL);
3151 }
3152#endif
3153
3154
3155 mb[0] = nv->isp_config.c;
3156 WRT_REG_WORD(®->cfg_1, mb[0]);
3157
3158
3159 WRT_REG_WORD(®->gpio_enable, (BIT_3 + BIT_2 + BIT_1 + BIT_0));
3160 mb[0] = nv->termination.c & (BIT_3 + BIT_2 + BIT_1 + BIT_0);
3161 WRT_REG_WORD(®->gpio_data, mb[0]);
3162
3163
3164 mb[0] = MBC_SET_SYSTEM_PARAMETER;
3165 mb[1] = nv->isp_parameter;
3166 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
3167
3168
3169 mb[0] = MBC_SET_FIRMWARE_FEATURES;
3170 mb[1] = nv->firmware_feature.w & (BIT_1 | BIT_0);
3171 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
3172
3173
3174 mb[0] = MBC_SET_RETRY_COUNT;
3175 mb[1] = nv->bus[0].retry_count;
3176 mb[2] = nv->bus[0].retry_delay;
3177 mb[6] = nv->bus[1].retry_count;
3178 mb[7] = nv->bus[1].retry_delay;
3179 status |=
3180 qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_2 | BIT_1 | BIT_0,
3181 &mb[0]);
3182
3183
3184 mb[0] = MBC_SET_ASYNC_DATA_SETUP;
3185 mb[1] = nv->bus[0].config_2.async_data_setup_time;
3186 mb[2] = nv->bus[1].config_2.async_data_setup_time;
3187 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
3188
3189
3190 mb[0] = MBC_SET_ACTIVE_NEGATION;
3191 mb[1] = 0;
3192 if (nv->bus[0].config_2.req_ack_active_negation)
3193 mb[1] |= BIT_5;
3194 if (nv->bus[0].config_2.data_line_active_negation)
3195 mb[1] |= BIT_4;
3196 mb[2] = 0;
3197 if (nv->bus[1].config_2.req_ack_active_negation)
3198 mb[2] |= BIT_5;
3199 if (nv->bus[1].config_2.data_line_active_negation)
3200 mb[2] |= BIT_4;
3201 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
3202
3203
3204 mb[0] = MBC_SET_SELECTION_TIMEOUT;
3205 mb[1] = nv->bus[0].selection_timeout;
3206 mb[2] = nv->bus[1].selection_timeout;
3207 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
3208
3209 for (bus = 0; bus < ha->ports; bus++) {
3210
3211 ha->bus_settings[bus].disable_scsi_reset =
3212 nv->bus[bus].config_1.scsi_reset_disable;
3213
3214
3215 ha->bus_settings[bus].id = nv->bus[bus].config_1.initiator_id;
3216 mb[0] = MBC_SET_INITIATOR_ID;
3217 mb[1] = bus ? ha->bus_settings[bus].id | BIT_7 :
3218 ha->bus_settings[bus].id;
3219 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
3220
3221
3222 ha->bus_settings[bus].bus_reset_delay =
3223 nv->bus[bus].bus_reset_delay;
3224
3225
3226 ha->bus_settings[bus].hiwat = nv->bus[bus].max_queue_depth - 1;
3227
3228
3229 for (target = 0; target < MAX_TARGETS; target++) {
3230 uint8_t mr = BIT_3 | BIT_2 | BIT_1 | BIT_0;
3231
3232
3233 mb[0] = MBC_SET_TARGET_PARAMETERS;
3234 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
3235 mb[1] <<= 8;
3236
3237 mb[2] = nv->bus[bus].target[target].parameter.c << 8;
3238 mb[2] |= TP_AUTO_REQUEST_SENSE;
3239 mb[2] &= ~TP_STOP_QUEUE;
3240
3241 mb[3] =
3242 nv->bus[bus].target[target].flags.sync_offset << 8;
3243 mb[3] |= nv->bus[bus].target[target].sync_period;
3244
3245 if (ha->device_id == PCI_DEVICE_ID_QLOGIC_ISP12160 ||
3246 ha->device_id == PCI_DEVICE_ID_QLOGIC_ISP10160) {
3247 nvram160_t *nv2 = (nvram160_t *) nv;
3248 mb[2] |=
3249 nv2->bus[bus].target[target].flags.
3250 enable_ppr << 5;
3251
3252 mb[6] =
3253 nv2->bus[bus].target[target].flags.
3254 ppr_options << 8;
3255 mb[6] |=
3256 nv2->bus[bus].target[target].flags.
3257 ppr_bus_width;
3258 mr |= BIT_6;
3259 }
3260 status = qla1280_mailbox_command(ha, mr, &mb[0]);
3261
3262
3263 mb[0] = BIT_0 << target;
3264 if (nv->bus[bus].target[target].parameter.f.tag_queuing)
3265 ha->bus_settings[bus].qtag_enables |= mb[0];
3266
3267
3268 if (nv->bus[bus].target[target].flags.device_enable)
3269 ha->bus_settings[bus].device_enables |= mb[0];
3270
3271
3272 if (nv->bus[bus].target[target].flags.lun_disable)
3273 ha->bus_settings[bus].lun_disables |= mb[0];
3274
3275
3276 for (lun = 0; lun < MAX_LUNS; lun++) {
3277 mb[0] = MBC_SET_DEVICE_QUEUE;
3278 mb[1] = (uint16_t)(bus ? target | BIT_7 : target);
3279 mb[1] = mb[1] << 8 | lun;
3280 mb[2] = nv->bus[bus].max_queue_depth;
3281 mb[3] = nv->bus[bus].target[target].execution_throttle;
3282 status |=
3283 qla1280_mailbox_command(ha,
3284 BIT_3 | BIT_2 |
3285 BIT_1 | BIT_0,
3286 &mb[0]);
3287 }
3288 }
3289 }
3290
3291#if DEBUG_PRINT_NVRAM
3292 ql_debug_print = saved_print_status;
3293#endif
3294
3295 if (status)
3296 dprintk(2, "qla1280_nvram_config: **** FAILED ****\n");
3297
3298 LEAVE("qla1280_nvram_config");
3299 return status;
3300}
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314static uint16_t
3315qla1280_get_nvram_word(struct scsi_qla_host *ha, uint32_t address)
3316{
3317 uint32_t nv_cmd;
3318 uint16_t data;
3319
3320#ifdef QL_DEBUG_ROUTINES
3321 int saved_print_status = ql_debug_print;
3322#endif
3323
3324 nv_cmd = address << 16;
3325 nv_cmd |= NV_READ_OP;
3326
3327#ifdef QL_DEBUG_ROUTINES
3328 ql_debug_print = FALSE;
3329#endif
3330 data = qla1280_nvram_request(ha, nv_cmd);
3331#ifdef QL_DEBUG_ROUTINES
3332 ql_debug_print = saved_print_status;
3333#endif
3334
3335 dprintk(4,
3336 "qla1280_get_nvram_word: exiting normally NVRAM data = 0x%x",
3337 data);
3338
3339 return data;
3340}
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356static uint16_t
3357qla1280_nvram_request(struct scsi_qla_host *ha, uint32_t nv_cmd)
3358{
3359 struct device_reg *reg = ha->iobase;
3360 int cnt;
3361 uint16_t data = 0;
3362 uint16_t reg_data;
3363
3364
3365
3366 nv_cmd <<= 5;
3367 for (cnt = 0; cnt < 11; cnt++) {
3368 if (nv_cmd & BIT_31)
3369 qla1280_nv_write(ha, NV_DATA_OUT);
3370 else
3371 qla1280_nv_write(ha, 0);
3372 nv_cmd <<= 1;
3373 }
3374
3375
3376
3377 for (cnt = 0; cnt < 16; cnt++) {
3378 WRT_REG_WORD(®->nvram, (NV_SELECT | NV_CLOCK));
3379 NVRAM_DELAY();
3380 data <<= 1;
3381 reg_data = RD_REG_WORD(®->nvram);
3382 if (reg_data & NV_DATA_IN)
3383 data |= BIT_0;
3384 WRT_REG_WORD(®->nvram, NV_SELECT);
3385 NVRAM_DELAY();
3386 }
3387
3388
3389
3390 WRT_REG_WORD(®->nvram, NV_DESELECT);
3391 NVRAM_DELAY();
3392
3393 return data;
3394}
3395
3396static void
3397qla1280_nv_write(struct scsi_qla_host *ha, uint16_t data)
3398{
3399 struct device_reg *reg = ha->iobase;
3400
3401 WRT_REG_WORD(®->nvram, data | NV_SELECT);
3402 NVRAM_DELAY();
3403 WRT_REG_WORD(®->nvram, data | NV_SELECT | NV_CLOCK);
3404 NVRAM_DELAY();
3405 WRT_REG_WORD(®->nvram, data | NV_SELECT);
3406 NVRAM_DELAY();
3407}
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424static int
3425qla1280_mailbox_command(struct scsi_qla_host *ha, uint8_t mr, uint16_t * mb)
3426{
3427 struct device_reg *reg = ha->iobase;
3428#if 0
3429 srb_t *done_q_first = 0;
3430 srb_t *done_q_last = 0;
3431#endif
3432 int status = 0;
3433 int cnt;
3434 uint16_t *optr, *iptr;
3435 uint16_t data;
3436
3437 ENTER("qla1280_mailbox_command");
3438
3439 ha->flags.mbox_busy = TRUE;
3440
3441 if (!ha->flags.ints_enabled)
3442 printk(KERN_DEBUG
3443 "Running qla1280_mailbox_command() with interrupts "
3444 "disabled!\n");
3445
3446
3447
3448
3449
3450 optr = (uint16_t *) ®->mailbox0;
3451 iptr = mb;
3452 for (cnt = 0; cnt < MAILBOX_REGISTER_COUNT; cnt++) {
3453 if (mr & BIT_0) {
3454 WRT_REG_WORD(optr, (*iptr));
3455 }
3456
3457 mr >>= 1;
3458 optr++;
3459 iptr++;
3460 }
3461
3462
3463 ha->flags.mbox_int = FALSE;
3464 ha->flags.mbox_busy = FALSE;
3465 WRT_REG_WORD(®->host_cmd, HC_SET_HOST_INT);
3466 data = qla1280_debounce_register(®->istatus);
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476 for (cnt = 30000000; cnt > 0 && !ha->flags.mbox_int; cnt--) {
3477
3478#if 0
3479 if (data & RISC_INT) {
3480 qla1280_isr(ha, &done_q_first, &done_q_last);
3481 } else
3482#endif
3483 udelay(1);
3484
3485 data = RD_REG_WORD(®->istatus);
3486 }
3487
3488
3489 if (!cnt) {
3490 printk(KERN_WARNING
3491 "qla1280_mailbox_command: **** Command Timeout, "
3492 "mailbox0 = 0x%x****\n", mb[0]);
3493
3494 ha->flags.isp_abort_needed = TRUE;
3495 status = 1;
3496 } else if (ha->mailbox_out[0] != MBS_CMD_CMP)
3497 status = 1;
3498
3499
3500 optr = mb;
3501 iptr = (uint16_t *) &ha->mailbox_out[0];
3502 mr = MAILBOX_REGISTER_COUNT;
3503 memcpy(optr, iptr, MAILBOX_REGISTER_COUNT * sizeof(uint16_t));
3504
3505#if 0
3506
3507 qla1280_isr(ha, &done_q_first, &done_q_last);
3508#endif
3509
3510 if (ha->flags.isp_abort_needed)
3511 qla1280_abort_isp(ha);
3512
3513 if (ha->flags.reset_marker)
3514 qla1280_rst_aen(ha);
3515
3516#if 0
3517 if (done_q_first)
3518 qla1280_done (ha, &done_q_first, &done_q_last);
3519#endif
3520
3521 if (status)
3522 dprintk(2,
3523 "qla1280_mailbox_command: **** FAILED, mailbox0 = 0x%x "
3524 "****n", mb[0]);
3525
3526 LEAVE("qla1280_mailbox_command");
3527 return status;
3528}
3529
3530
3531
3532
3533
3534
3535
3536
3537static void
3538qla1280_poll(struct scsi_qla_host *ha)
3539{
3540 struct device_reg *reg = ha->iobase;
3541 uint16_t data;
3542 srb_t *done_q_first = 0;
3543 srb_t *done_q_last = 0;
3544
3545
3546
3547
3548 data = RD_REG_WORD(®->istatus);
3549 if (data & RISC_INT)
3550 qla1280_isr(ha, &done_q_first, &done_q_last);
3551
3552 if (!ha->flags.mbox_busy) {
3553 if (ha->flags.isp_abort_needed)
3554 qla1280_abort_isp(ha);
3555 if (ha->flags.reset_marker)
3556 qla1280_rst_aen(ha);
3557 }
3558
3559 if (done_q_first)
3560 qla1280_done(ha, &done_q_first, &done_q_last);
3561
3562
3563}
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576static int
3577qla1280_bus_reset(struct scsi_qla_host *ha, int bus)
3578{
3579 uint16_t mb[MAILBOX_REGISTER_COUNT];
3580 int status;
3581
3582 dprintk(3, "qla1280_bus_reset: entered\n");
3583
3584 if (qla1280_verbose)
3585 printk(KERN_INFO "scsi(%li): Resetting SCSI BUS (%i)\n",
3586 ha->host_no, bus);
3587
3588 mb[0] = MBC_BUS_RESET;
3589 mb[1] = ha->bus_settings[bus].bus_reset_delay;
3590 mb[2] = (uint16_t) bus;
3591 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
3592
3593 if (status) {
3594 if (ha->bus_settings[bus].failed_reset_count > 2)
3595 ha->bus_settings[bus].scsi_bus_dead = TRUE;
3596 ha->bus_settings[bus].failed_reset_count++;
3597 } else {
3598
3599
3600
3601#if 0
3602 mdelay(4000);
3603#else
3604 schedule_timeout(4 * HZ);
3605#endif
3606 ha->bus_settings[bus].scsi_bus_dead = FALSE;
3607 ha->bus_settings[bus].failed_reset_count = 0;
3608
3609 qla1280_marker(ha, bus, 0, 0, MK_SYNC_ALL);
3610 }
3611
3612 if (status)
3613 dprintk(2, "qla1280_bus_reset: **** FAILED ****\n");
3614 else
3615 dprintk(3, "qla1280_bus_reset: exiting normally\n");
3616
3617 return status;
3618}
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632static int
3633qla1280_device_reset(struct scsi_qla_host *ha, int bus, int target)
3634{
3635 uint16_t mb[MAILBOX_REGISTER_COUNT];
3636 int status;
3637
3638 ENTER("qla1280_device_reset");
3639
3640 mb[0] = MBC_ABORT_TARGET;
3641 mb[1] = (bus ? (target | BIT_7) : target) << 8;
3642 mb[2] = 1;
3643 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
3644
3645
3646 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
3647
3648 if (status)
3649 dprintk(2, "qla1280_device_reset: **** FAILED ****\n");
3650
3651 LEAVE("qla1280_device_reset");
3652 return status;
3653}
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668static int
3669qla1280_abort_device(struct scsi_qla_host *ha, int bus, int target, int lun)
3670{
3671 uint16_t mb[MAILBOX_REGISTER_COUNT];
3672 int status;
3673
3674 ENTER("qla1280_abort_device");
3675
3676 mb[0] = MBC_ABORT_DEVICE;
3677 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
3678 status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
3679
3680
3681 qla1280_marker(ha, bus, target, lun, MK_SYNC_ID_LUN);
3682
3683 if (status)
3684 dprintk(2, "qla1280_abort_device: **** FAILED ****\n");
3685
3686 LEAVE("qla1280_abort_device");
3687 return status;
3688}
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701static int
3702qla1280_abort_command(struct scsi_qla_host *ha, srb_t * sp)
3703{
3704 uint16_t mb[MAILBOX_REGISTER_COUNT];
3705 unsigned int bus, target, lun;
3706 uint32_t handle;
3707 int status;
3708
3709 ENTER("qla1280_abort_command");
3710
3711
3712 for (handle = 0; handle < MAX_OUTSTANDING_COMMANDS; handle++)
3713 if (ha->outstanding_cmds[handle] == sp)
3714 break;
3715
3716 bus = SCSI_BUS_32(sp->cmd);
3717 target = SCSI_TCN_32(sp->cmd);
3718 lun = SCSI_LUN_32(sp->cmd);
3719
3720 mb[0] = MBC_ABORT_COMMAND;
3721 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
3722 mb[2] = handle >> 16;
3723 mb[3] = handle & 0xffff;
3724 status =
3725 qla1280_mailbox_command(ha, BIT_3 | BIT_2 | BIT_1 | BIT_0, &mb[0]);
3726
3727 if (status)
3728 dprintk(2, "qla1280_abort_command: **** FAILED ****\n");
3729
3730 sp->flags |= SRB_ABORT_PENDING;
3731
3732 LEAVE("qla1280_abort_command");
3733 return status;
3734}
3735
3736
3737
3738
3739
3740
3741
3742
3743static void
3744qla1280_reset_adapter(struct scsi_qla_host *ha)
3745{
3746 struct device_reg *reg = ha->iobase;
3747
3748 ENTER("qla1280_reset_adapter");
3749
3750
3751 ha->flags.online = FALSE;
3752 WRT_REG_WORD(®->ictrl, ISP_RESET);
3753 WRT_REG_WORD(®->host_cmd, HC_RESET_RISC);
3754 WRT_REG_WORD(®->host_cmd, HC_RELEASE_RISC);
3755 WRT_REG_WORD(®->host_cmd, HC_DISABLE_BIOS);
3756
3757 LEAVE("qla1280_reset_adapter");
3758}
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771static void
3772qla1280_marker(struct scsi_qla_host *ha, int bus, int id, int lun, u8 type)
3773{
3774 mrk_entry_t *pkt;
3775
3776 ENTER("qla1280_marker");
3777
3778
3779 if ((pkt = (mrk_entry_t *) qla1280_req_pkt(ha))) {
3780 pkt->entry_type = MARKER_TYPE;
3781 pkt->lun = (uint8_t) lun;
3782 pkt->target = (uint8_t) (bus ? (id | BIT_7) : id);
3783 pkt->modifier = type;
3784
3785
3786 qla1280_isp_cmd(ha);
3787 }
3788
3789 LEAVE("qla1280_marker");
3790}
3791
3792#if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,18)
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805static int
3806qla1280_64bit_start_scsi(struct scsi_qla_host *ha, srb_t * sp)
3807{
3808 struct device_reg *reg = ha->iobase;
3809 Scsi_Cmnd *cmd = sp->cmd;
3810 cmd_a64_entry_t *pkt;
3811 struct scatterlist *sg = NULL;
3812 u32 *dword_ptr;
3813 dma_addr_t dma_handle;
3814 int status = 0;
3815 int cnt;
3816 int req_cnt;
3817 u16 seg_cnt;
3818
3819 ENTER("qla1280_64bit_start_scsi:");
3820
3821 dprintk(1, "64bit_start: cmd=%p sp=%p CDB=%x\n", cmd, sp,
3822 cmd->cmnd[0]);
3823
3824
3825 req_cnt = 1;
3826 if (cmd->use_sg) {
3827 sg = (struct scatterlist *) cmd->request_buffer;
3828 seg_cnt = pci_map_sg (ha->pdev, sg, cmd->use_sg,
3829 scsi_to_pci_dma_dir(cmd->sc_data_direction));
3830
3831 if (seg_cnt > 2) {
3832 req_cnt += (seg_cnt - 2) / 5;
3833 if ((seg_cnt - 2) % 5)
3834 req_cnt++;
3835 }
3836 } else if (cmd->request_bufflen) {
3837 seg_cnt = 1;
3838 } else {
3839 seg_cnt = 0;
3840 }
3841
3842 if ((req_cnt + 2) >= ha->req_q_cnt) {
3843
3844 cnt = RD_REG_WORD(®->mailbox4);
3845 if (ha->req_ring_index < cnt)
3846 ha->req_q_cnt = cnt - ha->req_ring_index;
3847 else
3848 ha->req_q_cnt =
3849 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3850 }
3851
3852
3853 if ((req_cnt + 2) < ha->req_q_cnt) {
3854
3855 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS &&
3856 ha->outstanding_cmds[cnt] != 0; cnt++) ;
3857
3858 if (cnt < MAX_OUTSTANDING_COMMANDS) {
3859 ha->outstanding_cmds[cnt] = sp;
3860 ha->req_q_cnt -= req_cnt;
3861 CMD_HANDLE(sp->cmd) =
3862 (unsigned char *)(unsigned long)cnt;
3863
3864
3865
3866
3867 pkt = (cmd_a64_entry_t *) ha->request_ring_ptr;
3868
3869 pkt->entry_type = COMMAND_A64_TYPE;
3870 pkt->entry_count = (uint8_t) req_cnt;
3871 pkt->sys_define = (uint8_t) ha->req_ring_index;
3872 pkt->handle = (uint32_t) cnt;
3873
3874
3875 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
3876
3877
3878 pkt->timeout = 30;
3879
3880
3881 pkt->lun = SCSI_LUN_32(cmd);
3882 pkt->target = SCSI_BUS_32(cmd) ?
3883 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3884
3885
3886 if (cmd->device->tagged_queue)
3887 pkt->control_flags |= BIT_3;
3888
3889
3890 pkt->cdb_len = (uint16_t)CMD_CDBLEN(cmd);
3891 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), pkt->cdb_len);
3892
3893
3894
3895
3896
3897 if (seg_cnt) {
3898
3899 if ((cmd->data_cmnd[0] == WRITE_6))
3900 pkt->control_flags |= BIT_6;
3901 else
3902 pkt->control_flags |= (BIT_5 | BIT_6);
3903
3904 sp->dir = pkt->control_flags & (BIT_5 | BIT_6);
3905
3906
3907 pkt->dseg_count = seg_cnt;
3908
3909
3910 dword_ptr = (u32 *)&pkt->dseg_0_address;
3911
3912 if (cmd->use_sg) {
3913
3914 for (cnt = 0; cnt < 2 && seg_cnt;
3915 cnt++, seg_cnt--) {
3916
3917 *dword_ptr++ =
3918 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
3919 *dword_ptr++ =
3920 cpu_to_le32(pci_dma_hi32(sg_dma_address(sg)));
3921 *dword_ptr++ =
3922 cpu_to_le32(sg_dma_len(sg));
3923 sg++;
3924 dprintk(1,
3925 "S/G Segment phys_addr=%x %x, len=0x%x\n",
3926 cpu_to_le32(pci_dma_hi32(sg_dma_address(sg))),
3927 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg))),
3928 cpu_to_le32(sg_dma_len(sg)));
3929 }
3930 dprintk(5,
3931 "qla1280_64bit_start_scsi: Scatter/gather "
3932 "command packet data - b %i, t %i, l %i \n",
3933 SCSI_BUS_32(cmd),
3934 SCSI_TCN_32(cmd),
3935 SCSI_LUN_32(cmd));
3936 qla1280_dump_buffer(5, (char *)pkt,
3937 REQUEST_ENTRY_SIZE);
3938
3939
3940
3941
3942 dprintk(1,
3943 "S/G Building Continuation...seg_cnt=0x%x "
3944 "remains\n", seg_cnt);
3945
3946 while (seg_cnt > 0) {
3947
3948 ha->req_ring_index++;
3949 if (ha->req_ring_index ==
3950 REQUEST_ENTRY_CNT) {
3951 ha->req_ring_index = 0;
3952 ha->request_ring_ptr =
3953 ha->request_ring;
3954 } else
3955 ha->request_ring_ptr++;
3956
3957 pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
3958
3959
3960 memset(pkt, 0,
3961 REQUEST_ENTRY_SIZE);
3962
3963
3964 ((cont_a64_entry_t *) pkt)->entry_type =
3965 CONTINUE_A64_TYPE;
3966 ((cont_a64_entry_t *) pkt)->entry_count = 1;
3967 ((cont_a64_entry_t *) pkt)->sys_define =
3968 (uint8_t)ha->req_ring_index;
3969
3970 dword_ptr =
3971 (u32 *)&((cont_a64_entry_t *) pkt)->dseg_0_address;
3972
3973
3974 for (cnt = 0;
3975 cnt < 5 && seg_cnt;
3976 cnt++, seg_cnt--) {
3977
3978 *dword_ptr++ =
3979 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
3980 *dword_ptr++ =
3981 cpu_to_le32(pci_dma_hi32(sg_dma_address(sg)));
3982 *dword_ptr++ =
3983 cpu_to_le32(sg_dma_len(sg));
3984 dprintk(1,
3985 "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
3986 cpu_to_le32(pci_dma_hi32(sg_dma_address(sg))),
3987 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg))),
3988 cpu_to_le32(sg_dma_len(sg)));
3989 sg++;
3990 }
3991 dprintk(5,
3992 "qla1280_64bit_start_scsi: continuation "
3993 "packet data - b %i, t %i, l %i \n",
3994 SCSI_BUS_32(cmd),
3995 SCSI_TCN_32(cmd),
3996 SCSI_LUN_32(cmd));
3997 qla1280_dump_buffer(5,
3998 (char *)pkt,
3999 REQUEST_ENTRY_SIZE);
4000 }
4001 } else {
4002
4003 dma_handle = pci_map_single(ha->pdev,
4004 cmd->request_buffer,
4005 cmd->request_bufflen,
4006 scsi_to_pci_dma_dir(cmd->sc_data_direction));
4007
4008 sp->saved_dma_handle = dma_handle;
4009
4010 *dword_ptr++ =
4011 cpu_to_le32(pci_dma_lo32(dma_handle));
4012 *dword_ptr++ =
4013 cpu_to_le32(pci_dma_hi32(dma_handle));
4014 *dword_ptr =
4015 (uint32_t)cmd->request_bufflen;
4016
4017
4018
4019 dprintk(5,
4020 "qla1280_64bit_start_scsi: No scatter/gather "
4021 "command packet data - b %i, t %i, l %i \n",
4022 SCSI_BUS_32(cmd),
4023 SCSI_TCN_32(cmd),
4024 SCSI_LUN_32(cmd));
4025 qla1280_dump_buffer(5, (char *)pkt,
4026 REQUEST_ENTRY_SIZE);
4027 }
4028 } else {
4029
4030 dword_ptr = (uint32_t *)(pkt + 1);
4031 *dword_ptr++ = 0;
4032 *dword_ptr++ = 0;
4033 *dword_ptr = 0;
4034 dprintk(5,
4035 "qla1280_64bit_start_scsi: No data, command "
4036 "packet data - b %i, t %i, l %i \n",
4037 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
4038 SCSI_LUN_32(cmd));
4039 qla1280_dump_buffer(5, (char *)pkt,
4040 REQUEST_ENTRY_SIZE);
4041 }
4042
4043 ha->req_ring_index++;
4044 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
4045 ha->req_ring_index = 0;
4046 ha->request_ring_ptr = ha->request_ring;
4047 } else
4048 ha->request_ring_ptr++;
4049
4050
4051 dprintk(1,
4052 "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
4053 ha->qthreads--;
4054 sp->flags |= SRB_SENT;
4055 ha->actthreads++;
4056 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
4057 } else {
4058 status = 1;
4059 dprintk(2, "qla1280_64bit_start_scsi: NO ROOM IN "
4060 "OUTSTANDING ARRAY, req_q_cnt=0x%x",
4061 ha->req_q_cnt);
4062 }
4063 } else {
4064 status = 1;
4065 dprintk(2,
4066 "qla1280_64bit_start_scsi: in-ptr=0x%x req_q_cnt=0x%x"
4067 "req_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt,
4068 req_cnt);
4069 }
4070
4071 if (status)
4072 dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
4073 else
4074 dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
4075
4076 return status;
4077}
4078#endif
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099static int
4100qla1280_32bit_start_scsi(struct scsi_qla_host *ha, srb_t * sp)
4101{
4102 struct device_reg *reg = ha->iobase;
4103 Scsi_Cmnd *cmd = sp->cmd;
4104 cmd_entry_t *pkt;
4105 struct scatterlist *sg = NULL;
4106 uint32_t *dword_ptr;
4107 int status = 0;
4108 int cnt;
4109 int req_cnt;
4110 uint16_t seg_cnt;
4111 dma_addr_t dma_handle;
4112
4113 ENTER("qla1280_32bit_start_scsi");
4114
4115 dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd, sp,
4116 cmd->cmnd[0]);
4117
4118
4119 req_cnt = 1;
4120 if (cmd->use_sg) {
4121
4122
4123
4124
4125
4126
4127 sg = (struct scatterlist *) cmd->request_buffer;
4128
4129 seg_cnt = pci_map_sg (ha->pdev, sg, cmd->use_sg,
4130 scsi_to_pci_dma_dir(cmd->sc_data_direction));
4131
4132
4133
4134
4135
4136 if (seg_cnt > 4) {
4137 req_cnt += (seg_cnt - 4) / 7;
4138 if ((seg_cnt - 4) % 7)
4139 req_cnt++;
4140 }
4141 dprintk(1, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
4142 cmd, seg_cnt, req_cnt);
4143 } else if (cmd->request_bufflen) {
4144 dprintk(1, "No S/G transfer t=%x cmd=%p len=%x CDB=%x\n",
4145 SCSI_TCN_32(cmd), cmd, cmd->request_bufflen,
4146 cmd->cmnd[0]);
4147 seg_cnt = 1;
4148 } else {
4149
4150 seg_cnt = 0;
4151 }
4152
4153 if ((req_cnt + 2) >= ha->req_q_cnt) {
4154
4155 cnt = RD_REG_WORD(®->mailbox4);
4156 if (ha->req_ring_index < cnt)
4157 ha->req_q_cnt = cnt - ha->req_ring_index;
4158 else
4159 ha->req_q_cnt =
4160 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
4161 }
4162
4163 dprintk(1, "Number of free entries=(%d) seg_cnt=0x%x\n",
4164 ha->req_q_cnt, seg_cnt);
4165
4166 if ((req_cnt + 2) < ha->req_q_cnt) {
4167
4168 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS &&
4169 (ha->outstanding_cmds[cnt] != 0); cnt++) ;
4170
4171 if (cnt < MAX_OUTSTANDING_COMMANDS) {
4172 CMD_HANDLE(sp->cmd) =
4173 (unsigned char *) (unsigned long) cnt;
4174 ha->outstanding_cmds[cnt] = sp;
4175 ha->req_q_cnt -= req_cnt;
4176
4177
4178
4179
4180 pkt = (cmd_entry_t *) ha->request_ring_ptr;
4181
4182 pkt->entry_type = COMMAND_TYPE;
4183 pkt->entry_count = (uint8_t) req_cnt;
4184 pkt->sys_define = (uint8_t) ha->req_ring_index;
4185 pkt->handle = (uint32_t) cnt;
4186
4187
4188 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
4189
4190
4191 pkt->timeout = 30;
4192
4193
4194 pkt->lun = SCSI_LUN_32(cmd);
4195 pkt->target = SCSI_BUS_32(cmd) ?
4196 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
4197
4198
4199 if (cmd->device->tagged_queue)
4200 pkt->control_flags |= BIT_3;
4201
4202
4203 pkt->cdb_len = (uint16_t) CMD_CDBLEN(cmd);
4204 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), pkt->cdb_len);
4205
4206
4207
4208
4209
4210 if (seg_cnt) {
4211
4212
4213
4214
4215
4216
4217
4218
4219 if ((cmd->data_cmnd[0] == WRITE_6))
4220 pkt->control_flags |= BIT_6;
4221 else
4222 pkt->control_flags |= (BIT_5 | BIT_6);
4223
4224 sp->dir = pkt->control_flags & (BIT_5 | BIT_6);
4225
4226
4227 pkt->dseg_count = seg_cnt;
4228
4229
4230 dword_ptr = &pkt->dseg_0_address;
4231
4232 if (cmd->use_sg) {
4233 dprintk(1, "Building S/G data "
4234 "segments..\n");
4235 qla1280_dump_buffer(1, (char *)sg,
4236 4 * 16);
4237
4238
4239 for (cnt = 0; cnt < 4 && seg_cnt;
4240 cnt++, seg_cnt--) {
4241
4242#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
4243 *dword_ptr++ =
4244 cpu_to_le32(virt_to_bus(sg->address));
4245 *dword_ptr++ = sg->length;
4246 dprintk(1,
4247 "S/G Segment phys_addr=0x%x, len=0x%x\n",
4248 cpu_to_le32(virt_to_bus(sg->address)),
4249 sg->length);
4250#else
4251 *dword_ptr++ =
4252 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
4253 *dword_ptr++ =
4254 cpu_to_le32(sg_dma_len(sg));
4255 dprintk(1, "S/G Segment phys_addr=0x%x, len=0x%x\n",
4256 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg))),
4257 cpu_to_le32(sg_dma_len(sg)));
4258#endif
4259 sg++;
4260 }
4261
4262
4263
4264 dprintk(1, "S/G Building Continuation"
4265 "...seg_cnt=0x%x remains\n",
4266 seg_cnt);
4267 while (seg_cnt > 0) {
4268
4269 ha->req_ring_index++;
4270 if (ha->req_ring_index ==
4271 REQUEST_ENTRY_CNT) {
4272 ha->req_ring_index = 0;
4273 ha->request_ring_ptr =
4274 ha->request_ring;
4275 } else
4276 ha->request_ring_ptr++;
4277
4278 pkt = (cmd_entry_t *)
4279 ha->request_ring_ptr;
4280
4281
4282 memset(pkt, 0,
4283 REQUEST_ENTRY_SIZE);
4284
4285
4286 ((cont_entry_t *) pkt)->
4287 entry_type = CONTINUE_TYPE;
4288 ((cont_entry_t *) pkt)->
4289 entry_count = 1;
4290
4291 ((cont_entry_t *) pkt)->
4292 sys_define =
4293 (uint8_t) ha->
4294 req_ring_index;
4295
4296
4297 dword_ptr =
4298 &((cont_entry_t *) pkt)->dseg_0_address;
4299
4300
4301 for (cnt = 0;
4302 cnt < 7 && seg_cnt;
4303 cnt++, seg_cnt--) {
4304
4305#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
4306 *dword_ptr++ =
4307 cpu_to_le32(virt_to_bus(sg->address));
4308 *dword_ptr++ = sg->length;
4309 dprintk(1,
4310 "S/G Segment Cont. phys_addr=0x%x, len=0x%x\n",
4311 cpu_to_le32(pci_dma_lo32(virt_to_bus(sg->address))), sg->length);
4312#else
4313 *dword_ptr++ =
4314 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
4315 *dword_ptr++ =
4316 cpu_to_le32(sg_dma_len(sg));
4317 dprintk(1,
4318 "S/G Segment Cont. phys_addr=0x%x, "
4319 "len=0x%x\n",
4320 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg))),
4321 cpu_to_le32(sg_dma_len(sg)));
4322#endif
4323 sg++;
4324 }
4325 dprintk(5,
4326 "qla1280_32bit_start_scsi: continuation "
4327 "packet data - scsi(%i:%i:%i)\n",
4328 SCSI_BUS_32(cmd),
4329 SCSI_TCN_32(cmd),
4330 SCSI_LUN_32(cmd));
4331 qla1280_dump_buffer(5,
4332 (char *)pkt,
4333 REQUEST_ENTRY_SIZE);
4334 }
4335 } else {
4336
4337
4338#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
4339 *dword_ptr++ =
4340 cpu_to_le32 (virt_to_bus
4341 (cmd->request_buffer));
4342#else
4343 dma_handle = pci_map_single(ha->pdev,
4344 cmd->request_buffer,
4345 cmd->request_bufflen,
4346 scsi_to_pci_dma_dir(cmd->sc_data_direction));
4347 sp->saved_dma_handle = dma_handle;
4348
4349 *dword_ptr++ =
4350 cpu_to_le32(pci_dma_lo32(dma_handle));
4351#endif
4352 *dword_ptr =
4353 (uint32_t)cmd->request_bufflen;
4354 }
4355 } else {
4356
4357 dword_ptr = (uint32_t *)(pkt + 1);
4358 *dword_ptr++ = 0;
4359 *dword_ptr = 0;
4360 dprintk(5,
4361 "qla1280_32bit_start_scsi: No data, command "
4362 "packet data - \n");
4363 qla1280_dump_buffer(5, (char *)pkt,
4364 REQUEST_ENTRY_SIZE);
4365 }
4366 dprintk(5,
4367 "qla1280_32bit_start_scsi: First IOCB block:\n");
4368 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
4369 REQUEST_ENTRY_SIZE);
4370
4371
4372 ha->req_ring_index++;
4373 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
4374 ha->req_ring_index = 0;
4375 ha->request_ring_ptr = ha->request_ring;
4376 } else
4377 ha->request_ring_ptr++;
4378
4379
4380 dprintk(1, "qla1280_32bit_start_scsi: Wakeup RISC "
4381 "for pending command\n");
4382 ha->qthreads--;
4383 sp->flags |= SRB_SENT;
4384 ha->actthreads++;
4385 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
4386 } else {
4387 status = 1;
4388 dprintk(2,
4389 "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
4390 "ARRAY, req_q_cnt=0x%x\n", ha->req_q_cnt);
4391 }
4392 } else {
4393 status = 1;
4394 dprintk(2,
4395 "qla1280_32bit_start_scsi: in-ptr=0x%x, req_q_cnt=0x%x, "
4396 "req_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt,
4397 req_cnt);
4398 }
4399
4400 if (status)
4401 dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
4402
4403 LEAVE("qla1280_32bit_start_scsi");
4404
4405 return status;
4406}
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419static request_t *
4420qla1280_req_pkt(struct scsi_qla_host *ha)
4421{
4422 struct device_reg *reg = ha->iobase;
4423 request_t *pkt = 0;
4424 int cnt;
4425 uint32_t timer;
4426
4427 ENTER("qla1280_req_pkt");
4428
4429
4430
4431
4432
4433 for (timer = 15000000; timer; timer--) {
4434 if (ha->req_q_cnt > 0) {
4435
4436 cnt = RD_REG_WORD(®->mailbox4);
4437 if (ha->req_ring_index < cnt)
4438 ha->req_q_cnt = cnt - ha->req_ring_index;
4439 else
4440 ha->req_q_cnt =
4441 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
4442 }
4443
4444
4445 if (ha->req_q_cnt > 0) {
4446 ha->req_q_cnt--;
4447 pkt = ha->request_ring_ptr;
4448
4449
4450 memset(pkt, 0, REQUEST_ENTRY_SIZE);
4451
4452
4453 pkt->sys_define = (uint8_t) ha->req_ring_index;
4454
4455
4456 pkt->entry_count = 1;
4457
4458 break;
4459 }
4460
4461 udelay(2);
4462
4463
4464 qla1280_poll(ha);
4465 }
4466
4467 if (!pkt)
4468 dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
4469 else
4470 dprintk(3, "qla1280_req_pkt: exiting normally\n");
4471
4472 return pkt;
4473}
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483static void
4484qla1280_isp_cmd(struct scsi_qla_host *ha)
4485{
4486 struct device_reg *reg = ha->iobase;
4487
4488 ENTER("qla1280_isp_cmd");
4489
4490 dprintk(5, "qla1280_isp_cmd: IOCB data:\n");
4491 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
4492 REQUEST_ENTRY_SIZE);
4493
4494
4495 ha->req_ring_index++;
4496 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
4497 ha->req_ring_index = 0;
4498 ha->request_ring_ptr = ha->request_ring;
4499 } else
4500 ha->request_ring_ptr++;
4501
4502
4503 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
4504
4505 LEAVE("qla1280_isp_cmd");
4506}
4507
4508#if QL1280_LUN_SUPPORT
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518static void
4519qla1280_enable_lun(struct scsi_qla_host *ha, int bus, int lun)
4520{
4521 elun_entry_t *pkt;
4522
4523 ENTER("qla1280_enable_lun");
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540 pkt = (elun_entry_t *) 1;
4541
4542 if (!pkt)
4543 dprintk(2, "qla1280_enable_lun: **** FAILED ****\n");
4544 else
4545 dprintk(3, "qla1280_enable_lun: exiting normally\n");
4546}
4547#endif
4548
4549#if QL1280_TARGET_MODE_SUPPORT
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564static void
4565qla1280_notify_ack(struct scsi_qla_host *ha, notify_entry_t * inotify)
4566{
4567 nack_entry_t *pkt;
4568
4569 dprintk(3, "qla1280_notify_ack: entered\n");
4570
4571
4572 if (pkt = (nack_entry_t *) qla1280_req_pkt(ha)) {
4573 pkt->entry_type = NOTIFY_ACK_TYPE;
4574 pkt->lun = inotify->lun;
4575 pkt->initiator_id = inotify->initiator_id;
4576 pkt->target_id = inotify->target_id;
4577 if (inotify->seq_id == 0)
4578 pkt->event = BIT_7;
4579 else
4580 pkt->seq_id = inotify->seq_id;
4581
4582
4583 qla1280_isp_cmd(ha);
4584 }
4585
4586 if (!pkt)
4587 dprintk(2, "qla1280_notify_ack: **** FAILED ****\n");
4588 else
4589 dprintk(3, "qla1280_notify_ack: exiting normally\n");
4590}
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600static void
4601qla1280_immed_notify(struct scsi_qla_host *ha, notify_entry_t * inotify)
4602{
4603 notify_entry_t *pkt;
4604
4605 dprintk(3, "qla1280_immed_notify: entered\n");
4606
4607
4608 if (pkt = (notify_entry_t *) qla1280_req_pkt(ha)) {
4609 pkt->entry_type = IMMED_NOTIFY_TYPE;
4610 pkt->lun = inotify->lun;
4611 pkt->initiator_id = inotify->initiator_id;
4612 pkt->target_id = inotify->target_id;
4613 pkt->status = 1;
4614
4615
4616 qla1280_isp_cmd(ha);
4617 }
4618
4619 if (!pkt)
4620 dprintk(2, "qla1280_immed_notify: **** FAILED ****\n");
4621 else
4622 dprintk(3, "qla1280_immed_notify: exiting normally\n");
4623}
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633static void
4634qla1280_accept_io(struct scsi_qla_host *ha, ctio_ret_entry_t * ctio)
4635{
4636 atio_entry_t *pkt;
4637
4638 dprintk(3, "qla1280_accept_io: entered\n");
4639
4640
4641 if (pkt = (atio_entry_t *) qla1280_req_pkt(ha)) {
4642 pkt->entry_type = ACCEPT_TGT_IO_TYPE;
4643 pkt->lun = ctio->lun;
4644 pkt->initiator_id = ctio->initiator_id;
4645 pkt->target_id = ctio->target_id;
4646 pkt->tag_value = ctio->tag_value;
4647 pkt->status = 1;
4648
4649
4650 qla1280_isp_cmd(ha);
4651 }
4652
4653 if (!pkt)
4654 dprintk(2, "qla1280_accept_io: **** FAILED ****\n");
4655 else
4656 dprintk(3, "qla1280_accept_io: exiting normally\n");
4657}
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669static void
4670qla1280_64bit_continue_io(struct scsi_qla_host *ha, atio_entry_t * atio,
4671 uint32_t len, paddr32_t * addr)
4672{
4673 ctio_a64_entry_t *pkt;
4674 uint32_t *dword_ptr;
4675
4676 dprintk(3, "qla1280_64bit_continue_io: entered\n");
4677
4678
4679 if (pkt = (ctio_a64_entry_t *) qla1280_req_pkt(ha)) {
4680 pkt->entry_type = CTIO_A64_TYPE;
4681 pkt->lun = atio->lun;
4682 pkt->initiator_id = atio->initiator_id;
4683 pkt->target_id = atio->target_id;
4684 pkt->option_flags = atio->option_flags;
4685 pkt->tag_value = atio->tag_value;
4686 pkt->scsi_status = atio->scsi_status;
4687
4688 if (len) {
4689 pkt->dseg_count = 1;
4690 pkt->transfer_length = len;
4691 pkt->dseg_0_length = len;
4692 dword_ptr = (uint32_t *) addr;
4693 pkt->dseg_0_address[0] = *dword_ptr++;
4694 pkt->dseg_0_address[1] = *dword_ptr;
4695 }
4696
4697
4698 qla1280_isp_cmd(ha);
4699 }
4700
4701 if (!pkt)
4702 dprintk(2, "qla1280_64bit_continue_io: **** FAILED ****\n");
4703 else
4704 dprintk(3, "qla1280_64bit_continue_io: exiting normally\n");
4705}
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717static void
4718qla1280_32bit_continue_io(struct scsi_qla_host *ha, atio_entry_t * atio,
4719 uint32_t len, paddr32_t * addr)
4720{
4721 ctio_entry_t *pkt;
4722 uint32_t *dword_ptr;
4723
4724 dprintk(3, "qla1280_32bit_continue_io: entered\n");
4725
4726
4727 if (pkt = (ctio_entry_t *) qla1280_req_pkt(ha)) {
4728 pkt->entry_type = CONTINUE_TGT_IO_TYPE;
4729 pkt->lun = atio->lun;
4730 pkt->initiator_id = atio->initiator_id;
4731 pkt->target_id = atio->target_id;
4732 pkt->option_flags = atio->option_flags;
4733 pkt->tag_value = atio->tag_value;
4734 pkt->scsi_status = atio->scsi_status;
4735
4736 if (len) {
4737 pkt->dseg_count = 1;
4738 pkt->transfer_length = len;
4739 pkt->dseg_0_length = len;
4740 dword_ptr = (uint32_t *) addr;
4741 pkt->dseg_0_address = *dword_ptr;
4742 }
4743
4744
4745 qla1280_isp_cmd(ha);
4746 }
4747
4748 if (!pkt)
4749 dprintk(2, "qla1280_32bit_continue_io: **** FAILED ****\n");
4750 else
4751 dprintk(3, "qla1280_32bit_continue_io: exiting normally\n");
4752}
4753#endif
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768static void
4769qla1280_isr(struct scsi_qla_host *ha, srb_t ** done_q_first,
4770 srb_t ** done_q_last)
4771{
4772 struct device_reg *reg = ha->iobase;
4773 response_t *pkt;
4774 srb_t *sp = 0;
4775 uint16_t mailbox[MAILBOX_REGISTER_COUNT];
4776 uint16_t *wptr;
4777 uint32_t index;
4778 u16 istatus;
4779
4780 ENTER("qla1280_isr");
4781
4782 istatus = RD_REG_WORD(®->istatus);
4783 if (!(istatus & (RISC_INT | PCI_INT)))
4784 return;
4785
4786
4787 mailbox[5] = RD_REG_WORD(®->mailbox5);
4788
4789
4790
4791 mailbox[0] = RD_REG_WORD(®->semaphore);
4792
4793 if (mailbox[0] & BIT_0) {
4794
4795
4796
4797 wptr = &mailbox[0];
4798 *wptr++ = RD_REG_WORD(®->mailbox0);
4799 *wptr++ = RD_REG_WORD(®->mailbox1);
4800 *wptr = RD_REG_WORD(®->mailbox2);
4801 if (mailbox[0] != MBA_SCSI_COMPLETION) {
4802 wptr++;
4803 *wptr++ = RD_REG_WORD(®->mailbox3);
4804 *wptr++ = RD_REG_WORD(®->mailbox4);
4805 wptr++;
4806 *wptr++ = RD_REG_WORD(®->mailbox6);
4807 *wptr = RD_REG_WORD(®->mailbox7);
4808 }
4809
4810
4811
4812 WRT_REG_WORD(®->semaphore, 0);
4813 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
4814
4815 dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
4816 mailbox[0]);
4817
4818
4819 switch (mailbox[0]) {
4820 case MBA_SCSI_COMPLETION:
4821 dprintk(5,
4822 "qla1280_isr: mailbox SCSI response completion\n");
4823
4824 if (ha->flags.online) {
4825
4826 index = mailbox[2] << 16 | mailbox[1];
4827
4828
4829 if (index < MAX_OUTSTANDING_COMMANDS)
4830 sp = ha->outstanding_cmds[index];
4831 else
4832 sp = 0;
4833
4834 if (sp) {
4835
4836 ha->outstanding_cmds[index] = 0;
4837
4838
4839 CMD_RESULT(sp->cmd) = 0;
4840
4841
4842 sp->s_next = NULL;
4843 sp->s_prev = *done_q_last;
4844 if (!*done_q_first)
4845 *done_q_first = sp;
4846 else
4847 (*done_q_last)->s_next = sp;
4848 *done_q_last = sp;
4849 } else {
4850
4851
4852
4853 printk(KERN_WARNING
4854 "qla1280: ISP invalid handle");
4855 ha->flags.isp_abort_needed = TRUE;
4856 }
4857 }
4858 break;
4859
4860 case MBA_BUS_RESET:
4861 ha->flags.reset_marker = TRUE;
4862 index = mailbox[6] & BIT_0;
4863 ha->bus_settings[index].reset_marker = TRUE;
4864
4865 printk(KERN_DEBUG
4866 "qla1280_isr(): index %i asynchronous "
4867 "BUS_RESET\n", index);
4868 break;
4869
4870 case MBA_SYSTEM_ERR:
4871 printk(KERN_WARNING
4872 "qla1280: ISP System Error - mbx1=%xh, mbx2=%xh, "
4873 "mbx3=%xh\n", mailbox[1], mailbox[2],
4874 mailbox[3]);
4875 ha->flags.isp_abort_needed = TRUE;
4876 break;
4877
4878 case MBA_REQ_TRANSFER_ERR:
4879 printk(KERN_WARNING
4880 "qla1280: ISP Request Transfer Error\n");
4881 ha->flags.isp_abort_needed = TRUE;
4882 break;
4883
4884 case MBA_RSP_TRANSFER_ERR:
4885 printk(KERN_WARNING
4886 "qla1280: ISP Response Transfer Error\n");
4887 ha->flags.isp_abort_needed = TRUE;
4888 break;
4889
4890 case MBA_WAKEUP_THRES:
4891 dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
4892 break;
4893
4894 case MBA_TIMEOUT_RESET:
4895 dprintk(2,
4896 "qla1280_isr: asynchronous TIMEOUT_RESET\n");
4897 break;
4898
4899 case MBA_DEVICE_RESET:
4900 dprintk(2,
4901 "qla1280_isr: asynchronous BUS_DEVICE_RESET\n");
4902 printk(KERN_INFO "qla1280_isr(): asynchronous "
4903 "BUS_DEVICE_RESET\n");
4904
4905 ha->flags.reset_marker = TRUE;
4906 index = mailbox[6] & BIT_0;
4907 ha->bus_settings[index].reset_marker = TRUE;
4908 break;
4909
4910 case MBA_BUS_MODE_CHANGE:
4911 dprintk(2,
4912 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
4913 break;
4914
4915 default:
4916
4917 if (mailbox[0] < MBA_ASYNC_EVENT) {
4918 wptr = &mailbox[0];
4919 memcpy((uint16_t *) ha->mailbox_out, wptr,
4920 MAILBOX_REGISTER_COUNT *
4921 sizeof(uint16_t));
4922 ha->flags.mbox_int = TRUE;
4923 }
4924 break;
4925 }
4926 } else {
4927 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
4928 }
4929
4930
4931
4932
4933
4934
4935 if (ha->flags.online
4936#if 0
4937 && !ha->flags.mbox_busy
4938#endif
4939 ) {
4940 if (mailbox[5] < RESPONSE_ENTRY_CNT) {
4941 while (ha->rsp_ring_index != mailbox[5]) {
4942 pkt = ha->response_ring_ptr;
4943
4944 dprintk(5,
4945 "qla1280_isr: ha->rsp_ring_index = 0x%x, "
4946 "mailbox[5] = 0x%x\n",
4947 ha->rsp_ring_index, mailbox[5]);
4948 dprintk(5,
4949 "qla1280_isr: response packet data\n");
4950 qla1280_dump_buffer(5, (char *)pkt,
4951 RESPONSE_ENTRY_SIZE);
4952
4953 if (pkt->entry_type == STATUS_TYPE) {
4954 if ((pkt->scsi_status & 0xff)
4955 || pkt->comp_status
4956 || pkt->entry_status) {
4957 dprintk(2,
4958 "qla1280_isr: ha->rsp_ring_index = 0x%x"
4959 "mailbox[5] = 0x%x, comp_status = 0x%x, "
4960 "scsi_status = 0x%x\n",
4961 ha->rsp_ring_index,
4962 mailbox[5],
4963 pkt->comp_status,
4964 pkt->scsi_status);
4965 }
4966 } else {
4967 dprintk(2,
4968 "qla1280_isr: ha->rsp_ring_index = 0x%x, "
4969 "mailbox[5] = 0x%x\n",
4970 ha->rsp_ring_index,
4971 mailbox[5]);
4972 dprintk(2,
4973 "qla1280_isr: response packet data\n");
4974 qla1280_dump_buffer(2, (char *)pkt,
4975 RESPONSE_ENTRY_SIZE);
4976 }
4977
4978 if (pkt->entry_type == STATUS_TYPE
4979 || pkt->entry_status) {
4980 if (pkt->entry_type == STATUS_TYPE)
4981 qla1280_status_entry(ha,
4982 (sts_entry_t *) pkt,
4983 done_q_first,
4984 done_q_last);
4985 else
4986 qla1280_error_entry(ha, pkt,
4987 done_q_first,
4988 done_q_last);
4989
4990
4991 ha->rsp_ring_index++;
4992 if (ha->rsp_ring_index ==
4993 RESPONSE_ENTRY_CNT) {
4994 ha->rsp_ring_index = 0;
4995 ha->response_ring_ptr =
4996 ha->response_ring;
4997 } else
4998 ha->response_ring_ptr++;
4999 WRT_REG_WORD(®->mailbox5,
5000 ha->rsp_ring_index);
5001 }
5002#if QLA1280_TARGET_MODE_SUPPORT
5003 else {
5004 pkt = &response_entry;
5005
5006
5007 dptr1 =
5008 (uint32_t *)ha->response_ring_ptr;
5009 dptr2 = (uint32_t *) pkt;
5010 for (index = 0;
5011 index < RESPONSE_ENTRY_SIZE / 4;
5012 index++)
5013 *dptr2++ = *dptr1++;
5014
5015
5016 ha->rsp_ring_index++;
5017 if (ha->rsp_ring_index ==
5018 RESPONSE_ENTRY_CNT) {
5019 ha->rsp_ring_index = 0;
5020 ha->response_ring_ptr =
5021 ha->response_ring;
5022 } else
5023 ha->response_ring_ptr++;
5024 WRT_REG_WORD(®->mailbox5,
5025 ha->rsp_ring_index);
5026
5027 switch (pkt->entry_type) {
5028 case ACCEPT_TGT_IO_TYPE:
5029 qla1280_atio_entry(ha,
5030 (atio_entry_t *) pkt);
5031 break;
5032 case IMMED_NOTIFY_TYPE:
5033 qla1280_notify_entry(ha,
5034 (notify_entry_t *) pkt);
5035 break;
5036 case CTIO_RET_TYPE:
5037 qla1280_accept_io(ha,
5038 (ctio_ret_entry_t *) pkt);
5039 break;
5040 default:
5041 break;
5042 }
5043 }
5044#endif
5045 }
5046 } else {
5047 ha->flags.isp_abort_needed = TRUE;
5048 dprintk(2, "qla1280_isr: Response pointer Error\n");
5049 }
5050 }
5051
5052 LEAVE("qla1280_isr");
5053}
5054
5055
5056
5057
5058
5059
5060
5061
5062static void
5063qla1280_rst_aen(struct scsi_qla_host *ha)
5064{
5065#if QL1280_TARGET_MODE_SUPPORT
5066 notify_entry_t nentry;
5067#endif
5068 uint8_t bus;
5069
5070 ENTER("qla1280_rst_aen");
5071
5072 if (ha->flags.online && !ha->flags.reset_active &&
5073 !ha->flags.abort_isp_active) {
5074 ha->flags.reset_active = TRUE;
5075 while (ha->flags.reset_marker) {
5076
5077 ha->flags.reset_marker = FALSE;
5078 for (bus = 0; bus < ha->ports &&
5079 !ha->flags.reset_marker; bus++) {
5080 if (ha->bus_settings[bus].reset_marker) {
5081 ha->bus_settings[bus].reset_marker =
5082 FALSE;
5083 qla1280_marker(ha, bus, 0, 0,
5084 MK_SYNC_ALL);
5085
5086 if (!ha->flags.reset_marker) {
5087#if QL1280_TARGET_MODE_SUPPORT
5088
5089 memset(&nentry, 0,
5090 sizeof(notify_entry_t));
5091
5092 nentry.initiator_id =
5093 nentry.target_id =
5094 bus ? ha->bus_settings[bus].id | BIT_7 :
5095 ha->bus_settings[bus].id;
5096 qla1280_notify_entry(ha,
5097 &nentry);
5098#endif
5099
5100 }
5101 }
5102 }
5103 }
5104 }
5105
5106 LEAVE("qla1280_rst_aen");
5107}
5108
5109#if QL1280_TARGET_MODE_SUPPORT
5110
5111
5112
5113
5114
5115
5116
5117
5118static void
5119qla1280_atio_entry(struct scsi_qla_host *ha, atio_entry_t * pkt)
5120{
5121 uint64_t *a64;
5122 uint64_t *end_a64;
5123 paddr32_t phy_addr[2];
5124 paddr32_t end_addr[2];
5125 uint32_t len;
5126 uint32_t offset;
5127 uint8_t t;
5128 uint8_t *sense_ptr;
5129
5130 dprintk(3, "qla1280_atio_entry: entered\n");
5131
5132 t = pkt->initiator_id;
5133 sense_ptr = ha->tsense + t * TARGET_SENSE_SIZE;
5134 a64 = (uint64_t *)&phy_addr[0];
5135 end_a64 = (uint64_t *)&end_addr[0];
5136
5137 switch (pkt->status & ~BIT_7) {
5138 case 7:
5139 dprintk(2, "qla1280_atio_entry: Path invalid\n");
5140 break;
5141
5142 case 0x14:
5143 dprintk(2, "qla1280_atio_entry: Target Bus Phase "
5144 "Sequence Failure\n");
5145
5146 if (pkt->status & BIT_7) {
5147 memcpy(sense_ptr, &pkt->sense_data, TARGET_SENSE_SIZE);
5148 } else {
5149 memset(sense_ptr, 0, TARGET_SENSE_SIZE);
5150 *sense_ptr = 0x70;
5151 *(sense_ptr + 2) = SD_HARDERR;
5152 *(sense_ptr + 7) = TARGET_SENSE_SIZE - 8;
5153 *(sense_ptr + 12) = SC_SELFAIL;
5154 }
5155 pkt->scsi_status = S_CKCON;
5156 pkt->option_flags |= OF_SSTS | OF_NO_DATA;
5157
5158#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,18)
5159 if (ha->flags.enable_64bit_addressing)
5160 qla1280_64bit_continue_io(ha, pkt, 0, 0);
5161 else
5162#endif
5163 qla1280_32bit_continue_io(ha, pkt, 0, 0);
5164 break;
5165
5166 case 0x16:
5167 dprintk(2, "qla1280_atio_entry: Target Bus Phase "
5168 "Sequence Failure\n");
5169 break;
5170
5171 case 0x17:
5172 dprintk(2, "qla1280_atio_entry: Target Bus Phase "
5173 "Sequence Failure\n");
5174 break;
5175
5176 case 0x3D:
5177
5178
5179 if (pkt->lun && pkt->cdb[0] != SS_INQUIR &&
5180 pkt->cdb[0] != SS_REQSEN)
5181 pkt->cdb[0] = SS_TEST;
5182
5183 switch (pkt->cdb[0]) {
5184 case SS_TEST:
5185 dprintk(3, "qla1280_atio_entry: SS_TEST\n");
5186
5187 memset(sense_ptr, 0, TARGET_SENSE_SIZE);
5188 len = 0;
5189 if (pkt->lun == 0)
5190 pkt->scsi_status = S_GOOD;
5191 else {
5192 *sense_ptr = 0x70;
5193 *(sense_ptr + 2) = SD_ILLREQ;
5194 *(sense_ptr + 7) = TARGET_SENSE_SIZE - 8;
5195 *(sense_ptr + 12) = SC_INVLUN;
5196 pkt->scsi_status = S_CKCON;
5197 }
5198
5199 pkt->option_flags |= (OF_SSTS | OF_NO_DATA);
5200 break;
5201
5202 case SS_REQSEN:
5203 dprintk(3, "qla1280_atio_entry: SS_REQSEN\n");
5204
5205 phy_addr[0] = ha->tsense_dma;
5206 phy_addr[1] = 0;
5207 *a64 += t * TARGET_SENSE_SIZE;
5208 if (pkt->cdb[4] > TARGET_SENSE_SIZE)
5209 len = TARGET_SENSE_SIZE;
5210 else
5211 len = pkt->cdb[4];
5212 pkt->scsi_status = S_GOOD;
5213 pkt->option_flags |= (OF_SSTS | OF_DATA_IN);
5214 break;
5215
5216 case SS_INQUIR:
5217 dprintk(3, "qla1280_atio_entry: SS_INQUIR\n");
5218
5219 memset(sense_ptr, 0, TARGET_SENSE_SIZE);
5220 phy_addr[0] = ha->tbuf_dma;
5221 phy_addr[1] = 0;
5222 *a64 += TARGET_INQ_OFFSET;
5223
5224 if (pkt->lun == 0) {
5225 ha->tbuf->inq.id_type = ID_PROCESOR;
5226 ha->tbuf->inq.id_pqual = ID_QOK;
5227 } else {
5228 ha->tbuf->inq.id_type = ID_NODEV;
5229 ha->tbuf->inq.id_pqual = ID_QNOLU;
5230 }
5231
5232 if (pkt->cdb[4] > sizeof(struct ident))
5233 len = sizeof(struct ident);
5234 else
5235 len = pkt->cdb[4];
5236 pkt->scsi_status = S_GOOD;
5237 pkt->option_flags |= (OF_SSTS | OF_DATA_IN);
5238 break;
5239
5240 case SM_WRDB:
5241 memset(sense_ptr, 0, TARGET_SENSE_SIZE);
5242 offset = pkt->cdb[5];
5243 offset |= pkt->cdb[4] << 8;
5244 offset |= pkt->cdb[3] << 16;
5245 len = pkt->cdb[8];
5246 len |= pkt->cdb[7] << 8;
5247 len |= pkt->cdb[6] << 16;
5248 end_addr[0] = phy_addr[0] = ha->tbuf_dma;
5249 end_addr[1] = phy_addr[1] = 0;
5250 *end_a64 += TARGET_DATA_OFFSET + TARGET_DATA_SIZE;
5251 switch (pkt->cdb[1] & 7) {
5252 case RW_BUF_HDATA:
5253 dprintk(3, "qla1280_atio_entry: SM_WRDB, "
5254 "RW_BUF_HDATA\n");
5255
5256 if (len > TARGET_DATA_SIZE + 4) {
5257 dprintk(2,
5258 "qla1280_atio_entry: SM_WRDB, "
5259 "length > buffer size\n");
5260
5261 *sense_ptr = 0x70;
5262 *(sense_ptr + 2) = SD_ILLREQ;
5263 *(sense_ptr + 7) =
5264 TARGET_SENSE_SIZE - 8;
5265 *(sense_ptr + 12) = SC_ILLCDB;
5266 pkt->scsi_status = S_CKCON;
5267 pkt->option_flags |=
5268 (OF_SSTS | OF_NO_DATA);
5269 len = 0;
5270 } else if (len) {
5271 pkt->scsi_status = S_GOOD;
5272 pkt->option_flags |=
5273 (OF_SSTS | OF_DATA_OUT);
5274 dprintk(3,
5275 "qla1280_atio_entry: Issuing "
5276 "SDI_TARMOD_WRCOMP\n");
5277
5278 sdi_xaen(SDI_TARMOD_WRCOMP, ha->cntlr,
5279 pkt->target_id, pkt->lun, 0,
5280 offset);
5281 } else {
5282 dprintk(2,
5283 "qla1280_atio_entry: SM_WRDB, "
5284 "zero length\n");
5285
5286 pkt->scsi_status = S_GOOD;
5287 pkt->option_flags |=
5288 (OF_SSTS | OF_NO_DATA);
5289 }
5290
5291 break;
5292 case RW_BUF_DATA:
5293 dprintk(3, "qla1280_atio_entry: SM_WRDB, "
5294 "RW_BUF_DATA\n");
5295
5296 *a64 += offset + TARGET_DATA_OFFSET;
5297 if (pkt->cdb[2] != 0 || *a64 >= *end_a64 ||
5298 *a64 + len > *end_a64) {
5299 dprintk(2,
5300 "qla1280_atio_entry: SM_WRDB, "
5301 "RW_BUF_DATA BAD\n");
5302 dprintk(2, "buf_id=0x%x, offset=0x%x, "
5303 "length=0x%x\n", pkt->cdb[2],
5304 offset, len);
5305
5306 *sense_ptr = 0x70;
5307 *(sense_ptr + 2) = SD_ILLREQ;
5308 *(sense_ptr + 7) =
5309 TARGET_SENSE_SIZE - 8;
5310 *(sense_ptr + 12) = SC_ILLCDB;
5311 len = 0;
5312 pkt->scsi_status = S_CKCON;
5313 pkt->option_flags |=
5314 (OF_SSTS | OF_NO_DATA);
5315 } else if (len) {
5316 pkt->scsi_status = S_GOOD;
5317 pkt->option_flags |=
5318 (OF_SSTS | OF_DATA_OUT);
5319 dprintk(3,
5320 "qla1280_atio_entry: Issuing "
5321 "SDI_TARMOD_WRCOMP\n");
5322
5323 sdi_xaen(SDI_TARMOD_WRCOMP, ha->cntlr,
5324 pkt->target_id, pkt->lun, 0,
5325 offset);
5326 } else {
5327 dprintk(2,
5328 "qla1280_atio_entry: SM_WRDB, "
5329 "zero length\n");
5330
5331 pkt->scsi_status = S_GOOD;
5332 pkt->option_flags |=
5333 (OF_SSTS | OF_NO_DATA);
5334 }
5335 break;
5336
5337 default:
5338 dprintk(2, "qla1280_atio_entry: SM_WRDB "
5339 "unknown mode\n");
5340
5341 *sense_ptr = 0x70;
5342 *(sense_ptr + 2) = SD_ILLREQ;
5343 *(sense_ptr + 7) = TARGET_SENSE_SIZE - 8;
5344 *(sense_ptr + 12) = SC_ILLCDB;
5345 len = 0;
5346 pkt->scsi_status = S_CKCON;
5347 pkt->option_flags |= (OF_SSTS | OF_NO_DATA);
5348 break;
5349 }
5350 break;
5351
5352 case SM_RDDB:
5353 memset(sense_ptr, 0, TARGET_SENSE_SIZE);
5354 offset = pkt->cdb[5];
5355 offset |= pkt->cdb[4] << 8;
5356 offset |= pkt->cdb[3] << 16;
5357 len = pkt->cdb[8];
5358 len |= pkt->cdb[7] << 8;
5359 len |= pkt->cdb[6] << 16;
5360 end_addr[0] = phy_addr[0] = ha->tbuf_dma;
5361 end_addr[1] = phy_addr[1] = 0;
5362 *end_a64 += TARGET_DATA_OFFSET + TARGET_DATA_SIZE;
5363 switch (pkt->cdb[1] & 7) {
5364 case RW_BUF_HDATA:
5365 dprintk(3, "qla1280_atio_entry: SM_RDDB, "
5366 "RW_BUF_HDATA\n");
5367
5368 if (len) {
5369 ha->tbuf->hdr[0] = 0;
5370 ha->tbuf->hdr[1] =
5371 (TARGET_DATA_SIZE >> 16) & 0xff;
5372 ha->tbuf->hdr[2] =
5373 (TARGET_DATA_SIZE >> 8) & 0xff;
5374 ha->tbuf->hdr[3] =
5375 TARGET_DATA_SIZE & 0xff;
5376 if (len > TARGET_DATA_SIZE + 4)
5377 len = TARGET_DATA_SIZE + 4;
5378 pkt->scsi_status = S_GOOD;
5379 pkt->option_flags |=
5380 (OF_SSTS | OF_DATA_IN);
5381 } else {
5382 dprintk(2,
5383 "qla1280_atio_entry: SM_RDDB, "
5384 "zero length\n");
5385
5386 pkt->scsi_status = S_GOOD;
5387 pkt->option_flags |=
5388 (OF_SSTS | OF_NO_DATA);
5389 }
5390 break;
5391 case RW_BUF_DATA:
5392 dprintk(3, "qla1280_atio_entry: SM_RDDB, "
5393 "RW_BUF_DATA\n");
5394
5395 *a64 += offset + TARGET_DATA_OFFSET;
5396 if (pkt->cdb[2] != 0 || *a64 >= *end_a64) {
5397 dprintk(2,
5398 "qla1280_atio_entry: SM_RDDB, "
5399 "RW_BUF_DATA BAD\n");
5400 dprintk(2, "buf_id=0x%x, offset=0x%x\n"
5401 pkt->cdb[2], offset);
5402
5403 *sense_ptr = 0x70;
5404 *(sense_ptr + 2) = SD_ILLREQ;
5405 *(sense_ptr + 7) =
5406 TARGET_SENSE_SIZE - 8;
5407 *(sense_ptr + 12) = SC_ILLCDB;
5408 len = 0;
5409 pkt->scsi_status = S_CKCON;
5410 pkt->option_flags |=
5411 (OF_SSTS | OF_NO_DATA);
5412 } else {
5413 if (*a64 + len > *end_a64)
5414 len = *end_a64 - *a64;
5415 if (len) {
5416 pkt->scsi_status = S_GOOD;
5417 pkt->option_flags |=
5418 (OF_SSTS | OF_DATA_IN);
5419 } else {
5420 dprintk(2,
5421 "qla1280_atio_entry: SM_RDDB, "
5422 "zero length\n");
5423
5424 pkt->scsi_status = S_GOOD;
5425 pkt->option_flags |=
5426 (OF_SSTS | OF_NO_DATA);
5427 }
5428 }
5429 break;
5430 case RW_BUF_DESC:
5431 dprintk(3, "qla1280_atio_entry: SM_RDDB, "
5432 "RW_BUF_DESC\n");
5433
5434 if (len) {
5435 if (len > 4)
5436 len = 4;
5437
5438 ha->tbuf->hdr[0] = 0;
5439 if (pkt->cdb[2] != 0) {
5440 ha->tbuf->hdr[1] = 0;
5441 ha->tbuf->hdr[2] = 0;
5442 ha->tbuf->hdr[3] = 0;
5443 } else {
5444 ha->tbuf->hdr[1] =
5445 (TARGET_DATA_SIZE >> 16) &
5446 0xff;
5447 ha->tbuf->hdr[2] =
5448 (TARGET_DATA_SIZE >> 8) &
5449 0xff;
5450 ha->tbuf->hdr[3] =
5451 TARGET_DATA_SIZE & 0xff;
5452 }
5453 pkt->scsi_status = S_GOOD;
5454 pkt->option_flags |=
5455 (OF_SSTS | OF_DATA_IN);
5456 } else {
5457 dprintk(2,
5458 "qla1280_atio_entry: SM_RDDB,"
5459 " zero length\n");
5460
5461 pkt->scsi_status = S_GOOD;
5462 pkt->option_flags |=
5463 (OF_SSTS | OF_NO_DATA);
5464 }
5465 break;
5466 default:
5467 dprintk(2, "qla1280_atio_entry: SM_RDDB "
5468 "unknown mode\n");
5469
5470 *sense_ptr = 0x70;
5471 *(sense_ptr + 2) = SD_ILLREQ;
5472 *(sense_ptr + 7) = TARGET_SENSE_SIZE - 8;
5473 *(sense_ptr + 12) = SC_ILLCDB;
5474 len = 0;
5475 pkt->scsi_status = S_CKCON;
5476 pkt->option_flags |= (OF_SSTS | OF_NO_DATA);
5477 break;
5478 }
5479 break;
5480
5481 default:
5482 dprintk(2,
5483 "qla1280_atio_entry: Unknown SCSI command\n");
5484 qla1280_dump_buffer(2, &pkt->cdb[0], pkt->cdb_len);
5485
5486 memset(sense_ptr, 0, TARGET_SENSE_SIZE);
5487 *sense_ptr = 0x70;
5488 *(sense_ptr + 2) = SD_ILLREQ;
5489 *(sense_ptr + 7) = TARGET_SENSE_SIZE - 8;
5490 *(sense_ptr + 12) = SC_INVOPCODE;
5491 len = 0;
5492 pkt->scsi_status = S_CKCON;
5493 pkt->option_flags |= (OF_SSTS | OF_NO_DATA);
5494 break;
5495 }
5496#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,18)
5497 if (ha->flags.enable_64bit_addressing)
5498 qla1280_64bit_continue_io(ha, pkt, len,
5499 (paddr32_t *)&phy_addr);
5500 else
5501#endif
5502 qla1280_32bit_continue_io(ha, pkt, len,
5503 (paddr32_t *)&phy_addr);
5504 break;
5505
5506 default:
5507 break;
5508 }
5509
5510 dprintk(3, "qla1280_atio_entry: exiting normally\n");
5511}
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521static void
5522qla1280_notify_entry(struct scsi_qla_host *ha, notify_entry_t * pkt)
5523{
5524 dprintk(3, "qla1280_notify_entry: entered\n");
5525
5526
5527 qla1280_notify_ack(ha, pkt);
5528
5529
5530 qla1280_immed_notify(ha, pkt);
5531
5532 dprintk(3, "qla1280_notify_entry: exiting normally\n");
5533}
5534#endif
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546static void
5547qla1280_status_entry(struct scsi_qla_host *ha, sts_entry_t * pkt,
5548 srb_t ** done_q_first, srb_t ** done_q_last)
5549{
5550 unsigned int bus, target, lun;
5551 int sense_sz;
5552 srb_t *sp;
5553 scsi_lu_t *q;
5554 Scsi_Cmnd *cmd;
5555
5556 ENTER("qla1280_status_entry");
5557
5558
5559 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
5560 sp = ha->outstanding_cmds[pkt->handle];
5561 else
5562 sp = 0;
5563
5564 if (sp) {
5565
5566 ha->outstanding_cmds[pkt->handle] = 0;
5567
5568 cmd = sp->cmd;
5569
5570
5571 bus = SCSI_BUS_32(cmd);
5572 target = SCSI_TCN_32(cmd);
5573 lun = SCSI_LUN_32(cmd);
5574 q = LU_Q(ha, bus, target, lun);
5575
5576 if (pkt->comp_status || pkt->scsi_status) {
5577 dprintk(1, "scsi: comp_status = 0x%x, scsi_status = "
5578 "0x%x, handle = 0x%x\n", pkt->comp_status,
5579 pkt->scsi_status, pkt->handle);
5580 }
5581
5582
5583 if (pkt->scsi_status & SS_BUSY_CONDITION &&
5584 pkt->scsi_status != SS_RESERVE_CONFLICT) {
5585 CMD_RESULT(cmd) =
5586 DID_BUS_BUSY << 16 | (pkt->scsi_status & 0xff);
5587 } else {
5588
5589
5590 CMD_RESULT(cmd) = qla1280_return_status(pkt, cmd);
5591
5592 if (pkt->scsi_status & SS_CHECK_CONDITION) {
5593 if (pkt->comp_status != CS_ARS_FAILED) {
5594 if (pkt->req_sense_length <
5595 CMD_SNSLEN(cmd))
5596 sense_sz = pkt->req_sense_length;
5597 else
5598
5599
5600
5601
5602
5603 sense_sz = CMD_SNSLEN(cmd) - 1;
5604
5605 memcpy(cmd->sense_buffer,
5606 &pkt->req_sense_data, sense_sz);
5607 } else
5608 sense_sz = 0;
5609 memset(cmd->sense_buffer + sense_sz, 0,
5610 sizeof(cmd->sense_buffer) - sense_sz);
5611
5612 dprintk(2, "qla1280_status_entry: Check "
5613 "condition Sense data, b %i, t %i, "
5614 "l %i\n", bus, target, lun);
5615 if (sense_sz)
5616 qla1280_dump_buffer(2, (char *)cmd->sense_buffer,
5617 sense_sz);
5618 }
5619 }
5620
5621 qla1280_done_q_put(sp, done_q_first, done_q_last);
5622 } else {
5623 printk(KERN_WARNING "qla1280: Status Entry invalid handle\n");
5624 ha->flags.isp_abort_needed = TRUE;
5625 }
5626
5627 LEAVE("qla1280_status_entry");
5628}
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640static void
5641qla1280_error_entry(struct scsi_qla_host *ha, response_t * pkt,
5642 srb_t ** done_q_first, srb_t ** done_q_last)
5643{
5644 srb_t *sp;
5645
5646 ENTER("qla1280_error_entry");
5647
5648 if (pkt->entry_status & BIT_3)
5649 dprintk(2, "qla1280_error_entry: BAD PAYLOAD flag error\n");
5650 else if (pkt->entry_status & BIT_2)
5651 dprintk(2, "qla1280_error_entry: BAD HEADER flag error\n");
5652 else if (pkt->entry_status & BIT_1)
5653 dprintk(2, "qla1280_error_entry: FULL flag error\n");
5654 else
5655 dprintk(2, "qla1280_error_entry: UNKNOWN flag error\n");
5656
5657
5658 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
5659 sp = ha->outstanding_cmds[pkt->handle];
5660 else
5661 sp = 0;
5662
5663 if (sp) {
5664
5665 ha->outstanding_cmds[pkt->handle] = 0;
5666
5667
5668 if (pkt->entry_status & (BIT_3 + BIT_2)) {
5669
5670
5671 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
5672 } else if (pkt->entry_status & BIT_1) {
5673 CMD_RESULT(sp->cmd) = DID_BUS_BUSY << 16;
5674 } else {
5675
5676 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
5677 }
5678
5679 qla1280_done_q_put(sp, done_q_first, done_q_last);
5680 }
5681#ifdef QLA_64BIT_PTR
5682 else if (pkt->entry_type == COMMAND_A64_TYPE) {
5683 printk(KERN_WARNING "!qla1280: Error Entry invalid handle");
5684 ha->flags.isp_abort_needed = TRUE;
5685 }
5686#endif
5687
5688 LEAVE("qla1280_error_entry");
5689}
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701static int
5702qla1280_abort_isp(struct scsi_qla_host *ha)
5703{
5704#if 0
5705 struct device_reg *reg = ha->iobase;
5706#endif
5707 srb_t *sp;
5708 scsi_lu_t *q;
5709 int status = 0;
5710 int cnt;
5711 int bus, target, lun;
5712
5713 ENTER("qla1280_abort_isp");
5714
5715 ha->flags.isp_abort_needed = FALSE;
5716 if (!ha->flags.abort_isp_active && ha->flags.online) {
5717 ha->flags.abort_isp_active = TRUE;
5718
5719
5720 qla1280_disable_intrs(ha);
5721
5722
5723 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
5724 sp = ha->outstanding_cmds[cnt];
5725 if (sp) {
5726 ha->outstanding_cmds[cnt] = 0;
5727
5728
5729 bus = SCSI_BUS_32(sp->cmd);
5730 target = SCSI_TCN_32(sp->cmd);
5731 lun = SCSI_LUN_32(sp->cmd);
5732
5733 q = LU_Q(ha, bus, target, lun);
5734
5735
5736 q->q_outcnt = 0;
5737 q->q_flag &= ~QLA1280_QBUSY;
5738 q->q_flag = 0;
5739
5740
5741
5742
5743
5744
5745 sp->flags = 0;
5746 qla1280_putq_t(q, sp);
5747 }
5748 }
5749
5750
5751 if (qla1280_isp_firmware (ha)) {
5752 if (!(status = qla1280_chip_diag(ha)))
5753 status = qla1280_setup_chip(ha);
5754 }
5755
5756 if (!status) {
5757
5758 qla1280_nvram_config (ha);
5759
5760 if (!(status = qla1280_init_rings(ha))) {
5761
5762 for (bus = 0; bus < ha->ports; bus++) {
5763 qla1280_bus_reset(ha, bus);
5764 }
5765 do {
5766
5767 ha->flags.reset_marker = FALSE;
5768 for (bus = 0; bus < ha->ports; bus++) {
5769 ha->bus_settings[bus].
5770 reset_marker = FALSE;
5771 qla1280_marker(ha, bus, 0, 0,
5772 MK_SYNC_ALL);
5773 }
5774 } while (ha->flags.reset_marker);
5775
5776
5777 for (bus = 0; bus < ha->ports; bus++) {
5778 if (!
5779 (status =
5780 qla1280_enable_tgt(ha, bus))) {
5781 for (cnt = 0; cnt < MAX_LUNS;
5782 cnt++) {
5783
5784 qla1280_poll(ha);
5785 }
5786 } else
5787 break;
5788 }
5789
5790 if (!status) {
5791
5792 qla1280_enable_intrs(ha);
5793 ha->flags.abort_isp_active = FALSE;
5794
5795 qla1280_restart_queues(ha);
5796 }
5797 }
5798 }
5799 }
5800
5801 if (status) {
5802 printk(KERN_WARNING
5803 "qla1280: ISP error recovery failed, board disabled");
5804 qla1280_reset_adapter(ha);
5805 qla1280_abort_queues(ha);
5806
5807 dprintk(2, "qla1280_abort_isp: **** FAILED ****\n");
5808 }
5809
5810 LEAVE("qla1280_abort_isp");
5811 return status;
5812}
5813
5814
5815
5816
5817
5818
5819
5820
5821static void
5822qla1280_restart_queues(struct scsi_qla_host *ha)
5823{
5824 scsi_lu_t *q;
5825 int bus, target, lun;
5826
5827 ENTER("qla1280_restart_queues");
5828
5829 for (bus = 0; bus < ha->ports; bus++)
5830 for (target = 0; target < MAX_TARGETS; target++)
5831 for (lun = 0; lun < MAX_LUNS; lun++) {
5832 q = LU_Q(ha, bus, target, lun);
5833 if (q != NULL) {
5834 if (q->q_first)
5835 qla1280_next(ha, q, bus);
5836 }
5837 }
5838 dprintk(3, "qla1280_restart_queues: exiting normally\n");
5839}
5840
5841
5842
5843
5844
5845
5846
5847
5848static void
5849qla1280_abort_queue_single(struct scsi_qla_host *ha, int bus,
5850 int target, int lun, uint32_t stat)
5851{
5852 scsi_lu_t *q;
5853 srb_t *sp, *sp_next;
5854
5855 ENTER("qla1280_abort_queue_single");
5856 q = LU_Q(ha, bus, target, lun);
5857 if (q != NULL) {
5858 sp = q->q_first;
5859 q->q_first = q->q_last = NULL;
5860
5861 while (sp) {
5862 sp_next = sp->s_next;
5863 CMD_RESULT(sp->cmd) = stat;
5864 qla1280_done_q_put(sp, &ha->done_q_first,
5865 &ha->done_q_last);
5866 sp = sp_next;
5867 }
5868 }
5869 LEAVE("qla1280_abort_queue_single");
5870}
5871
5872
5873
5874
5875
5876
5877
5878
5879static void
5880qla1280_abort_queues(struct scsi_qla_host *ha)
5881{
5882 uint32_t bus, target, lun;
5883
5884 ENTER("qla1280_abort_queues");
5885
5886 for (bus = 0; bus < ha->ports; bus++)
5887 for (target = 0; target < MAX_TARGETS; target++)
5888 for (lun = 0; lun < MAX_LUNS; lun++)
5889 qla1280_abort_queue_single(ha, bus, target,
5890 lun, DID_RESET);
5891
5892 LEAVE("qla1280_abort_queues");
5893}
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905static u16
5906qla1280_debounce_register(volatile u16 * addr)
5907{
5908 volatile u16 ret;
5909 volatile u16 ret2;
5910
5911 ret = RD_REG_WORD(addr);
5912 ret2 = RD_REG_WORD(addr);
5913
5914 if (ret == ret2)
5915 return ret;
5916
5917 do {
5918 cpu_relax();
5919 ret = RD_REG_WORD(addr);
5920 ret2 = RD_REG_WORD(addr);
5921 } while (ret != ret2);
5922
5923 return ret;
5924}
5925
5926#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
5927#ifdef MODULE
5928Scsi_Host_Template driver_template = QLA1280_LINUX_TEMPLATE;
5929#include "scsi_module.c"
5930#endif
5931#else
5932static Scsi_Host_Template driver_template = QLA1280_LINUX_TEMPLATE;
5933#include "scsi_module.c"
5934#endif
5935
5936
5937
5938
5939
5940
5941#define SET_SXP_BANK 0x0100
5942#define SCSI_PHASE_INVALID 0x87FF
5943static int
5944qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *ha, unsigned int bus)
5945{
5946 uint16_t config_reg, scsi_control;
5947 struct device_reg *reg = ha->iobase;
5948#if 0
5949 unsigned int bus;
5950 Scsi_Cmnd *cp;
5951
5952
5953
5954
5955
5956
5957 cp = sp->cmd;
5958 bus = SCSI_BUS_32(cp);
5959#endif
5960 if (ha->bus_settings[bus].scsi_bus_dead) {
5961 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
5962 config_reg = RD_REG_WORD(®->cfg_1);
5963 WRT_REG_WORD(®->cfg_1, SET_SXP_BANK);
5964 scsi_control = RD_REG_WORD(®->scsiControlPins);
5965 WRT_REG_WORD(®->cfg_1, config_reg);
5966 WRT_REG_WORD(®->host_cmd, HC_RELEASE_RISC);
5967
5968 if (scsi_control == SCSI_PHASE_INVALID) {
5969 ha->bus_settings[bus].scsi_bus_dead = TRUE;
5970#if 0
5971 CMD_RESULT(cp) = DID_NO_CONNECT << 16;
5972 CMD_HANDLE(cp) = NULL;
5973
5974
5975 (*(cp)->scsi_done)(cp);
5976#endif
5977 return TRUE;
5978 } else {
5979 ha->bus_settings[bus].scsi_bus_dead = FALSE;
5980 ha->bus_settings[bus].failed_reset_count = 0;
5981 }
5982 }
5983 return FALSE;
5984}
5985
5986static void
5987qla12160_get_target_parameters(struct scsi_qla_host *ha, uint32_t bus,
5988 uint32_t target, uint32_t lun)
5989{
5990 uint16_t mb[MAILBOX_REGISTER_COUNT];
5991
5992 mb[0] = MBC_GET_TARGET_PARAMETERS;
5993 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
5994 mb[1] <<= 8;
5995 qla1280_mailbox_command(ha, BIT_6 | BIT_3 | BIT_2 | BIT_1 | BIT_0,
5996 &mb[0]);
5997 if (mb[3] != 0) {
5998 printk(KERN_INFO
5999 "scsi(%ld:%d:%d:%d): Synchronous transfer at period "
6000 "%d, offset %d. \n", ha->host_no, bus, target, lun,
6001 (mb[3] & 0xff), (mb[3] >> 8));
6002 }
6003
6004 if ((mb[2] & BIT_5) && ((mb[6] >> 8) & 0xff) >= 2) {
6005 printk(KERN_INFO
6006 "scsi(%ld:%d:%d:%d): Dual Transition enabled.\n",
6007 ha->host_no, bus, target, lun);
6008 }
6009}
6010
6011#ifdef QL_DEBUG_ROUTINES
6012
6013
6014
6015
6016
6017
6018
6019static u8
6020qla1280_getbyte (u8 * port)
6021{
6022 u8 ret;
6023
6024#if MEMORY_MAPPED_IO
6025 ret = readb((unsigned long) port);
6026#else
6027 ret = inb((unsigned long) port);
6028#endif
6029
6030 if (ql_debug_print)
6031 printk(KERN_DEBUG
6032 "qla1280_getbyte: address = 0x%p, data = 0x%x", port,
6033 ret);
6034
6035 return ret;
6036}
6037
6038
6039
6040
6041static u16
6042qla1280_getword (u16 * port)
6043{
6044 u16 ret;
6045
6046#if MEMORY_MAPPED_IO
6047 ret = readw(unsigned long) port;
6048#else
6049 ret = inw((unsigned long) port);
6050#endif
6051
6052 if (ql_debug_print)
6053 printk(KERN_DEBUG
6054 "qla1280_getbyte: address = 0x%p, data = 0x%x", port,
6055 ret);
6056
6057 return ret;
6058}
6059
6060
6061
6062
6063static u32
6064qla1280_getdword (u32 * port)
6065{
6066 u32 ret;
6067
6068#if MEMORY_MAPPED_IO
6069 ret = readl((unsigned long) port);
6070#else
6071 ret = inl((unsigned long) port);
6072#endif
6073
6074 if (ql_debug_print)
6075 printk(KERN_DEBUG
6076 "qla1280_getbyte: address = 0x%p, data = 0x%x", port,
6077 ret);
6078
6079 return ret;
6080}
6081
6082
6083
6084
6085static void
6086qla1280_putbyte(u8 * port, u8 data)
6087{
6088#if MEMORY_MAPPED_IO
6089 writeb(data, (unsigned long) port);
6090#else
6091 outb(data, (unsigned long) port);
6092#endif
6093
6094 if (ql_debug_print)
6095 printk(KERN_DEBUG
6096 "qla1280_getbyte: address = 0x%p, data = 0x%x", port,
6097 data);
6098}
6099
6100
6101
6102
6103static void
6104qla1280_putword(u16 * port, u16 data)
6105{
6106#if MEMORY_MAPPED_IO
6107 writew(data, (unsigned long) port);
6108#else
6109 outw(data, (unsigned long) port);
6110#endif
6111
6112 if (ql_debug_print)
6113 printk(KERN_DEBUG
6114 "qla1280_getbyte: address = 0x%p, data = 0x%x", port,
6115 data);
6116}
6117
6118
6119
6120
6121static void
6122qla1280_putdword(u32 * port, u32 data)
6123{
6124#if MEMORY_MAPPED_IO
6125 writel(data, (unsigned long) port);
6126#else
6127 outl(data, (unsigned long) port);
6128#endif
6129
6130 if (ql_debug_print)
6131 printk(KERN_DEBUG
6132 "qla1280_getbyte: address = 0x%p, data = 0x%x", port,
6133 data);
6134}
6135
6136
6137
6138
6139
6140static void
6141qla1280_debug(void)
6142{
6143 qla1280_getbyte(0);
6144 qla1280_getword(0);
6145 qla1280_getdword(0);
6146 qla1280_putbyte(0, 0);
6147 qla1280_putword(0, 0);
6148 qla1280_putdword(0, 0);
6149}
6150
6151static void
6152__qla1280_dump_buffer(char *b, int size)
6153{
6154 int cnt;
6155 u8 c;
6156
6157 if (ql_debug_print) {
6158 printk(KERN_DEBUG
6159 " 0 1 2 3 4 5 6 7 8 9 Ah "
6160 "Bh Ch Dh Eh Fh\n");
6161 printk(KERN_DEBUG
6162 "---------------------------------------------"
6163 "------------------\n");
6164
6165 for (cnt = 0; cnt < size;) {
6166 c = *b++;
6167 if (c < 16)
6168 printk(' ');
6169 printk("0x%x", c);
6170 cnt++;
6171 if (!(cnt % 16))
6172 printk("\n");
6173 else if (c < 10)
6174 printk(" ");
6175 else
6176 printk(' ');
6177 }
6178 if (cnt % 16)
6179 printk("\n");
6180 }
6181}
6182
6183
6184
6185
6186
6187static void
6188qla1280_print_scsi_cmd(Scsi_Cmnd * cmd)
6189{
6190 struct scsi_qla_host *ha;
6191 struct Scsi_Host *host = cmd->host;
6192 srb_t *sp;
6193
6194
6195 int i;
6196 ha = (struct scsi_qla_host *)host->hostdata;
6197
6198 sp = (srb_t *)CMD_SP(cmd);
6199 printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd, CMD_HANDLE(cmd));
6200 printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
6201 cmd->channel, cmd->target, cmd->lun, cmd->cmd_len);
6202 printk(" CDB = ");
6203 for (i = 0; i < cmd->cmd_len; i++) {
6204 printk("0x%02x ", cmd->cmnd[i]);
6205 }
6206 printk(" seg_cnt =%d\n", cmd->use_sg);
6207 printk(" request buffer=0x%p, request buffer len=0x%x\n",
6208 cmd->request_buffer, cmd->request_bufflen);
6209
6210
6211
6212
6213
6214
6215 printk(" tag=%d, flags=0x%x, transfersize=0x%x \n",
6216 cmd->tag, cmd->flags, cmd->transfersize);
6217 printk(" Pid=%li, SP=0x%p\n", cmd->pid, CMD_SP(cmd));
6218 printk(" underflow size = 0x%x, direction=0x%x, req.cmd=0x%x \n",
6219 cmd->underflow, sp->dir, cmd->request->cmd);
6220}
6221
6222
6223
6224
6225
6226void
6227ql1280_dump_device(struct scsi_qla_host *ha)
6228{
6229
6230 Scsi_Cmnd *cp;
6231 srb_t *sp;
6232 int i;
6233 if (ql_debug_print) {
6234 printk(KERN_DEBUG "Outstanding Commands on controller:\n");
6235
6236 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
6237 if ((sp = ha->outstanding_cmds[i]) == NULL)
6238 continue;
6239 if ((cp = sp->cmd) == NULL)
6240 continue;
6241 qla1280_print_scsi_cmd(1, cp);
6242 }
6243 }
6244}
6245#endif
6246
6247#if STOP_ON_ERROR
6248
6249
6250
6251
6252static void
6253qla1280_panic(char *cp, struct Scsi_Host *host)
6254{
6255 struct scsi_qla_host *ha;
6256 long *fp;
6257
6258 ha = (struct scsi_qla_host *)host->hostdata;
6259 printk(KERN_ERR "qla1280 - PANIC: %s\n", cp);
6260 printk(KERN_ERR "Current time=0x%lx\n", jiffies);
6261 printk(KERN_ERR "Number of pending commands =0x%lx\n", ha->actthreads);
6262 printk(KERN_ERR "Number of SCSI queued commands =0x%lx\n",
6263 ha->qthreads);
6264 printk(KERN_ERR "Number of free entries = (%d)\n", ha->req_q_cnt);
6265 printk(KERN_ERR "Request Queue @ 0x%lx, Response Queue @ 0x%lx\n",
6266 ha->request_dma, ha->response_dma);
6267 printk(KERN_ERR "Request In Ptr %d\n", ha->req_ring_index);
6268 fp = (long *) &ha->flags;
6269 printk(KERN_ERR "HA flags =0x%lx\n", *fp);
6270 if (ql_debug_level >= 2) {
6271 ql_debug_print = 1;
6272#if 0
6273 ql1280_dump_device((struct scsi_qla_host *)host->hostdata);
6274#endif
6275 }
6276 sti();
6277 panic("Ooops");
6278
6279
6280
6281
6282
6283
6284
6285}
6286#endif
6287
6288#ifdef MODULE
6289
6290
6291
6292
6293
6294
6295
6296void
6297qla1280_setup(char *s, int *dummy)
6298{
6299 char *end, *str, *cp;
6300
6301 printk(KERN_INFO "scsi: Processing Option str = %s\n", s);
6302 end = strchr (s, '\0');
6303
6304 str = s;
6305 for (cp = s; *cp && cp != end; cp++) {
6306 cp = qla1280_get_token(cp, str);
6307 printk(KERN_INFO "scsi: token str = %s\n", str);
6308
6309 }
6310}
6311
6312static char *
6313qla1280_get_token(char *cmdline, char *str)
6314{
6315 register char *cp = cmdline;
6316
6317
6318 while (strchr (cp, ' '))
6319 ++cp;
6320
6321 str = cp;
6322
6323 while (*cp && !(strchr (cp, ' ') || strchr (cp, ':')))
6324 cp++;
6325 *cp = '\0';
6326 return cp;
6327}
6328#endif
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341