Commit f75884d28a6eae5a422d0454b982da3842f777af
1 parent
688cb30bdc
Exists in
master
and in
7 other branches
[QLOGICPTI]: Handle INQUIRY response sniffing correctly.
These days, in 2.6.x, even INQUIRY commands are sent using scatter gather lists. Bug reported by Tom 'spot' Callaway. Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 1 changed file with 35 additions and 4 deletions Inline Diff
drivers/scsi/qlogicpti.c
1 | /* qlogicpti.c: Performance Technologies QlogicISP sbus card driver. | 1 | /* qlogicpti.c: Performance Technologies QlogicISP sbus card driver. |
2 | * | 2 | * |
3 | * Copyright (C) 1996 David S. Miller (davem@caipfs.rutgers.edu) | 3 | * Copyright (C) 1996 David S. Miller (davem@caipfs.rutgers.edu) |
4 | * | 4 | * |
5 | * A lot of this driver was directly stolen from Erik H. Moe's PCI | 5 | * A lot of this driver was directly stolen from Erik H. Moe's PCI |
6 | * Qlogic ISP driver. Mucho kudos to him for this code. | 6 | * Qlogic ISP driver. Mucho kudos to him for this code. |
7 | * | 7 | * |
8 | * An even bigger kudos to John Grana at Performance Technologies | 8 | * An even bigger kudos to John Grana at Performance Technologies |
9 | * for providing me with the hardware to write this driver, you rule | 9 | * for providing me with the hardware to write this driver, you rule |
10 | * John you really do. | 10 | * John you really do. |
11 | * | 11 | * |
12 | * May, 2, 1997: Added support for QLGC,isp --jj | 12 | * May, 2, 1997: Added support for QLGC,isp --jj |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
16 | #include <linux/delay.h> | 16 | #include <linux/delay.h> |
17 | #include <linux/types.h> | 17 | #include <linux/types.h> |
18 | #include <linux/string.h> | 18 | #include <linux/string.h> |
19 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
20 | #include <linux/blkdev.h> | 20 | #include <linux/blkdev.h> |
21 | #include <linux/proc_fs.h> | 21 | #include <linux/proc_fs.h> |
22 | #include <linux/stat.h> | 22 | #include <linux/stat.h> |
23 | #include <linux/init.h> | 23 | #include <linux/init.h> |
24 | #include <linux/spinlock.h> | 24 | #include <linux/spinlock.h> |
25 | #include <linux/interrupt.h> | 25 | #include <linux/interrupt.h> |
26 | #include <linux/module.h> | 26 | #include <linux/module.h> |
27 | 27 | ||
28 | #include <asm/byteorder.h> | 28 | #include <asm/byteorder.h> |
29 | 29 | ||
30 | #include "qlogicpti.h" | 30 | #include "qlogicpti.h" |
31 | 31 | ||
32 | #include <asm/sbus.h> | 32 | #include <asm/sbus.h> |
33 | #include <asm/dma.h> | 33 | #include <asm/dma.h> |
34 | #include <asm/system.h> | 34 | #include <asm/system.h> |
35 | #include <asm/ptrace.h> | 35 | #include <asm/ptrace.h> |
36 | #include <asm/pgtable.h> | 36 | #include <asm/pgtable.h> |
37 | #include <asm/oplib.h> | 37 | #include <asm/oplib.h> |
38 | #include <asm/io.h> | 38 | #include <asm/io.h> |
39 | #include <asm/irq.h> | 39 | #include <asm/irq.h> |
40 | 40 | ||
41 | #include <scsi/scsi.h> | 41 | #include <scsi/scsi.h> |
42 | #include <scsi/scsi_cmnd.h> | 42 | #include <scsi/scsi_cmnd.h> |
43 | #include <scsi/scsi_device.h> | 43 | #include <scsi/scsi_device.h> |
44 | #include <scsi/scsi_eh.h> | 44 | #include <scsi/scsi_eh.h> |
45 | #include <scsi/scsi_request.h> | 45 | #include <scsi/scsi_request.h> |
46 | #include <scsi/scsi_tcq.h> | 46 | #include <scsi/scsi_tcq.h> |
47 | #include <scsi/scsi_host.h> | 47 | #include <scsi/scsi_host.h> |
48 | 48 | ||
49 | 49 | ||
50 | 50 | ||
51 | #define MAX_TARGETS 16 | 51 | #define MAX_TARGETS 16 |
52 | #define MAX_LUNS 8 /* 32 for 1.31 F/W */ | 52 | #define MAX_LUNS 8 /* 32 for 1.31 F/W */ |
53 | 53 | ||
54 | #define DEFAULT_LOOP_COUNT 10000 | 54 | #define DEFAULT_LOOP_COUNT 10000 |
55 | 55 | ||
56 | #include "qlogicpti_asm.c" | 56 | #include "qlogicpti_asm.c" |
57 | 57 | ||
58 | static struct qlogicpti *qptichain = NULL; | 58 | static struct qlogicpti *qptichain = NULL; |
59 | static DEFINE_SPINLOCK(qptichain_lock); | 59 | static DEFINE_SPINLOCK(qptichain_lock); |
60 | static int qptis_running = 0; | 60 | static int qptis_running = 0; |
61 | 61 | ||
62 | #define PACKB(a, b) (((a)<<4)|(b)) | 62 | #define PACKB(a, b) (((a)<<4)|(b)) |
63 | 63 | ||
64 | static const u_char mbox_param[] = { | 64 | static const u_char mbox_param[] = { |
65 | PACKB(1, 1), /* MBOX_NO_OP */ | 65 | PACKB(1, 1), /* MBOX_NO_OP */ |
66 | PACKB(5, 5), /* MBOX_LOAD_RAM */ | 66 | PACKB(5, 5), /* MBOX_LOAD_RAM */ |
67 | PACKB(2, 0), /* MBOX_EXEC_FIRMWARE */ | 67 | PACKB(2, 0), /* MBOX_EXEC_FIRMWARE */ |
68 | PACKB(5, 5), /* MBOX_DUMP_RAM */ | 68 | PACKB(5, 5), /* MBOX_DUMP_RAM */ |
69 | PACKB(3, 3), /* MBOX_WRITE_RAM_WORD */ | 69 | PACKB(3, 3), /* MBOX_WRITE_RAM_WORD */ |
70 | PACKB(2, 3), /* MBOX_READ_RAM_WORD */ | 70 | PACKB(2, 3), /* MBOX_READ_RAM_WORD */ |
71 | PACKB(6, 6), /* MBOX_MAILBOX_REG_TEST */ | 71 | PACKB(6, 6), /* MBOX_MAILBOX_REG_TEST */ |
72 | PACKB(2, 3), /* MBOX_VERIFY_CHECKSUM */ | 72 | PACKB(2, 3), /* MBOX_VERIFY_CHECKSUM */ |
73 | PACKB(1, 3), /* MBOX_ABOUT_FIRMWARE */ | 73 | PACKB(1, 3), /* MBOX_ABOUT_FIRMWARE */ |
74 | PACKB(0, 0), /* 0x0009 */ | 74 | PACKB(0, 0), /* 0x0009 */ |
75 | PACKB(0, 0), /* 0x000a */ | 75 | PACKB(0, 0), /* 0x000a */ |
76 | PACKB(0, 0), /* 0x000b */ | 76 | PACKB(0, 0), /* 0x000b */ |
77 | PACKB(0, 0), /* 0x000c */ | 77 | PACKB(0, 0), /* 0x000c */ |
78 | PACKB(0, 0), /* 0x000d */ | 78 | PACKB(0, 0), /* 0x000d */ |
79 | PACKB(1, 2), /* MBOX_CHECK_FIRMWARE */ | 79 | PACKB(1, 2), /* MBOX_CHECK_FIRMWARE */ |
80 | PACKB(0, 0), /* 0x000f */ | 80 | PACKB(0, 0), /* 0x000f */ |
81 | PACKB(5, 5), /* MBOX_INIT_REQ_QUEUE */ | 81 | PACKB(5, 5), /* MBOX_INIT_REQ_QUEUE */ |
82 | PACKB(6, 6), /* MBOX_INIT_RES_QUEUE */ | 82 | PACKB(6, 6), /* MBOX_INIT_RES_QUEUE */ |
83 | PACKB(4, 4), /* MBOX_EXECUTE_IOCB */ | 83 | PACKB(4, 4), /* MBOX_EXECUTE_IOCB */ |
84 | PACKB(2, 2), /* MBOX_WAKE_UP */ | 84 | PACKB(2, 2), /* MBOX_WAKE_UP */ |
85 | PACKB(1, 6), /* MBOX_STOP_FIRMWARE */ | 85 | PACKB(1, 6), /* MBOX_STOP_FIRMWARE */ |
86 | PACKB(4, 4), /* MBOX_ABORT */ | 86 | PACKB(4, 4), /* MBOX_ABORT */ |
87 | PACKB(2, 2), /* MBOX_ABORT_DEVICE */ | 87 | PACKB(2, 2), /* MBOX_ABORT_DEVICE */ |
88 | PACKB(3, 3), /* MBOX_ABORT_TARGET */ | 88 | PACKB(3, 3), /* MBOX_ABORT_TARGET */ |
89 | PACKB(2, 2), /* MBOX_BUS_RESET */ | 89 | PACKB(2, 2), /* MBOX_BUS_RESET */ |
90 | PACKB(2, 3), /* MBOX_STOP_QUEUE */ | 90 | PACKB(2, 3), /* MBOX_STOP_QUEUE */ |
91 | PACKB(2, 3), /* MBOX_START_QUEUE */ | 91 | PACKB(2, 3), /* MBOX_START_QUEUE */ |
92 | PACKB(2, 3), /* MBOX_SINGLE_STEP_QUEUE */ | 92 | PACKB(2, 3), /* MBOX_SINGLE_STEP_QUEUE */ |
93 | PACKB(2, 3), /* MBOX_ABORT_QUEUE */ | 93 | PACKB(2, 3), /* MBOX_ABORT_QUEUE */ |
94 | PACKB(2, 4), /* MBOX_GET_DEV_QUEUE_STATUS */ | 94 | PACKB(2, 4), /* MBOX_GET_DEV_QUEUE_STATUS */ |
95 | PACKB(0, 0), /* 0x001e */ | 95 | PACKB(0, 0), /* 0x001e */ |
96 | PACKB(1, 3), /* MBOX_GET_FIRMWARE_STATUS */ | 96 | PACKB(1, 3), /* MBOX_GET_FIRMWARE_STATUS */ |
97 | PACKB(1, 2), /* MBOX_GET_INIT_SCSI_ID */ | 97 | PACKB(1, 2), /* MBOX_GET_INIT_SCSI_ID */ |
98 | PACKB(1, 2), /* MBOX_GET_SELECT_TIMEOUT */ | 98 | PACKB(1, 2), /* MBOX_GET_SELECT_TIMEOUT */ |
99 | PACKB(1, 3), /* MBOX_GET_RETRY_COUNT */ | 99 | PACKB(1, 3), /* MBOX_GET_RETRY_COUNT */ |
100 | PACKB(1, 2), /* MBOX_GET_TAG_AGE_LIMIT */ | 100 | PACKB(1, 2), /* MBOX_GET_TAG_AGE_LIMIT */ |
101 | PACKB(1, 2), /* MBOX_GET_CLOCK_RATE */ | 101 | PACKB(1, 2), /* MBOX_GET_CLOCK_RATE */ |
102 | PACKB(1, 2), /* MBOX_GET_ACT_NEG_STATE */ | 102 | PACKB(1, 2), /* MBOX_GET_ACT_NEG_STATE */ |
103 | PACKB(1, 2), /* MBOX_GET_ASYNC_DATA_SETUP_TIME */ | 103 | PACKB(1, 2), /* MBOX_GET_ASYNC_DATA_SETUP_TIME */ |
104 | PACKB(1, 3), /* MBOX_GET_SBUS_PARAMS */ | 104 | PACKB(1, 3), /* MBOX_GET_SBUS_PARAMS */ |
105 | PACKB(2, 4), /* MBOX_GET_TARGET_PARAMS */ | 105 | PACKB(2, 4), /* MBOX_GET_TARGET_PARAMS */ |
106 | PACKB(2, 4), /* MBOX_GET_DEV_QUEUE_PARAMS */ | 106 | PACKB(2, 4), /* MBOX_GET_DEV_QUEUE_PARAMS */ |
107 | PACKB(0, 0), /* 0x002a */ | 107 | PACKB(0, 0), /* 0x002a */ |
108 | PACKB(0, 0), /* 0x002b */ | 108 | PACKB(0, 0), /* 0x002b */ |
109 | PACKB(0, 0), /* 0x002c */ | 109 | PACKB(0, 0), /* 0x002c */ |
110 | PACKB(0, 0), /* 0x002d */ | 110 | PACKB(0, 0), /* 0x002d */ |
111 | PACKB(0, 0), /* 0x002e */ | 111 | PACKB(0, 0), /* 0x002e */ |
112 | PACKB(0, 0), /* 0x002f */ | 112 | PACKB(0, 0), /* 0x002f */ |
113 | PACKB(2, 2), /* MBOX_SET_INIT_SCSI_ID */ | 113 | PACKB(2, 2), /* MBOX_SET_INIT_SCSI_ID */ |
114 | PACKB(2, 2), /* MBOX_SET_SELECT_TIMEOUT */ | 114 | PACKB(2, 2), /* MBOX_SET_SELECT_TIMEOUT */ |
115 | PACKB(3, 3), /* MBOX_SET_RETRY_COUNT */ | 115 | PACKB(3, 3), /* MBOX_SET_RETRY_COUNT */ |
116 | PACKB(2, 2), /* MBOX_SET_TAG_AGE_LIMIT */ | 116 | PACKB(2, 2), /* MBOX_SET_TAG_AGE_LIMIT */ |
117 | PACKB(2, 2), /* MBOX_SET_CLOCK_RATE */ | 117 | PACKB(2, 2), /* MBOX_SET_CLOCK_RATE */ |
118 | PACKB(2, 2), /* MBOX_SET_ACTIVE_NEG_STATE */ | 118 | PACKB(2, 2), /* MBOX_SET_ACTIVE_NEG_STATE */ |
119 | PACKB(2, 2), /* MBOX_SET_ASYNC_DATA_SETUP_TIME */ | 119 | PACKB(2, 2), /* MBOX_SET_ASYNC_DATA_SETUP_TIME */ |
120 | PACKB(3, 3), /* MBOX_SET_SBUS_CONTROL_PARAMS */ | 120 | PACKB(3, 3), /* MBOX_SET_SBUS_CONTROL_PARAMS */ |
121 | PACKB(4, 4), /* MBOX_SET_TARGET_PARAMS */ | 121 | PACKB(4, 4), /* MBOX_SET_TARGET_PARAMS */ |
122 | PACKB(4, 4), /* MBOX_SET_DEV_QUEUE_PARAMS */ | 122 | PACKB(4, 4), /* MBOX_SET_DEV_QUEUE_PARAMS */ |
123 | PACKB(0, 0), /* 0x003a */ | 123 | PACKB(0, 0), /* 0x003a */ |
124 | PACKB(0, 0), /* 0x003b */ | 124 | PACKB(0, 0), /* 0x003b */ |
125 | PACKB(0, 0), /* 0x003c */ | 125 | PACKB(0, 0), /* 0x003c */ |
126 | PACKB(0, 0), /* 0x003d */ | 126 | PACKB(0, 0), /* 0x003d */ |
127 | PACKB(0, 0), /* 0x003e */ | 127 | PACKB(0, 0), /* 0x003e */ |
128 | PACKB(0, 0), /* 0x003f */ | 128 | PACKB(0, 0), /* 0x003f */ |
129 | PACKB(0, 0), /* 0x0040 */ | 129 | PACKB(0, 0), /* 0x0040 */ |
130 | PACKB(0, 0), /* 0x0041 */ | 130 | PACKB(0, 0), /* 0x0041 */ |
131 | PACKB(0, 0) /* 0x0042 */ | 131 | PACKB(0, 0) /* 0x0042 */ |
132 | }; | 132 | }; |
133 | 133 | ||
134 | #define MAX_MBOX_COMMAND (sizeof(mbox_param)/sizeof(u_short)) | 134 | #define MAX_MBOX_COMMAND (sizeof(mbox_param)/sizeof(u_short)) |
135 | 135 | ||
136 | /* queue length's _must_ be power of two: */ | 136 | /* queue length's _must_ be power of two: */ |
137 | #define QUEUE_DEPTH(in, out, ql) ((in - out) & (ql)) | 137 | #define QUEUE_DEPTH(in, out, ql) ((in - out) & (ql)) |
138 | #define REQ_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, \ | 138 | #define REQ_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, \ |
139 | QLOGICPTI_REQ_QUEUE_LEN) | 139 | QLOGICPTI_REQ_QUEUE_LEN) |
140 | #define RES_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, RES_QUEUE_LEN) | 140 | #define RES_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, RES_QUEUE_LEN) |
141 | 141 | ||
142 | static inline void qlogicpti_enable_irqs(struct qlogicpti *qpti) | 142 | static inline void qlogicpti_enable_irqs(struct qlogicpti *qpti) |
143 | { | 143 | { |
144 | sbus_writew(SBUS_CTRL_ERIRQ | SBUS_CTRL_GENAB, | 144 | sbus_writew(SBUS_CTRL_ERIRQ | SBUS_CTRL_GENAB, |
145 | qpti->qregs + SBUS_CTRL); | 145 | qpti->qregs + SBUS_CTRL); |
146 | } | 146 | } |
147 | 147 | ||
148 | static inline void qlogicpti_disable_irqs(struct qlogicpti *qpti) | 148 | static inline void qlogicpti_disable_irqs(struct qlogicpti *qpti) |
149 | { | 149 | { |
150 | sbus_writew(0, qpti->qregs + SBUS_CTRL); | 150 | sbus_writew(0, qpti->qregs + SBUS_CTRL); |
151 | } | 151 | } |
152 | 152 | ||
153 | static inline void set_sbus_cfg1(struct qlogicpti *qpti) | 153 | static inline void set_sbus_cfg1(struct qlogicpti *qpti) |
154 | { | 154 | { |
155 | u16 val; | 155 | u16 val; |
156 | u8 bursts = qpti->bursts; | 156 | u8 bursts = qpti->bursts; |
157 | 157 | ||
158 | #if 0 /* It appears that at least PTI cards do not support | 158 | #if 0 /* It appears that at least PTI cards do not support |
159 | * 64-byte bursts and that setting the B64 bit actually | 159 | * 64-byte bursts and that setting the B64 bit actually |
160 | * is a nop and the chip ends up using the smallest burst | 160 | * is a nop and the chip ends up using the smallest burst |
161 | * size. -DaveM | 161 | * size. -DaveM |
162 | */ | 162 | */ |
163 | if (sbus_can_burst64(qpti->sdev) && (bursts & DMA_BURST64)) { | 163 | if (sbus_can_burst64(qpti->sdev) && (bursts & DMA_BURST64)) { |
164 | val = (SBUS_CFG1_BENAB | SBUS_CFG1_B64); | 164 | val = (SBUS_CFG1_BENAB | SBUS_CFG1_B64); |
165 | } else | 165 | } else |
166 | #endif | 166 | #endif |
167 | if (bursts & DMA_BURST32) { | 167 | if (bursts & DMA_BURST32) { |
168 | val = (SBUS_CFG1_BENAB | SBUS_CFG1_B32); | 168 | val = (SBUS_CFG1_BENAB | SBUS_CFG1_B32); |
169 | } else if (bursts & DMA_BURST16) { | 169 | } else if (bursts & DMA_BURST16) { |
170 | val = (SBUS_CFG1_BENAB | SBUS_CFG1_B16); | 170 | val = (SBUS_CFG1_BENAB | SBUS_CFG1_B16); |
171 | } else if (bursts & DMA_BURST8) { | 171 | } else if (bursts & DMA_BURST8) { |
172 | val = (SBUS_CFG1_BENAB | SBUS_CFG1_B8); | 172 | val = (SBUS_CFG1_BENAB | SBUS_CFG1_B8); |
173 | } else { | 173 | } else { |
174 | val = 0; /* No sbus bursts for you... */ | 174 | val = 0; /* No sbus bursts for you... */ |
175 | } | 175 | } |
176 | sbus_writew(val, qpti->qregs + SBUS_CFG1); | 176 | sbus_writew(val, qpti->qregs + SBUS_CFG1); |
177 | } | 177 | } |
178 | 178 | ||
179 | static int qlogicpti_mbox_command(struct qlogicpti *qpti, u_short param[], int force) | 179 | static int qlogicpti_mbox_command(struct qlogicpti *qpti, u_short param[], int force) |
180 | { | 180 | { |
181 | int loop_count; | 181 | int loop_count; |
182 | u16 tmp; | 182 | u16 tmp; |
183 | 183 | ||
184 | if (mbox_param[param[0]] == 0) | 184 | if (mbox_param[param[0]] == 0) |
185 | return 1; | 185 | return 1; |
186 | 186 | ||
187 | /* Set SBUS semaphore. */ | 187 | /* Set SBUS semaphore. */ |
188 | tmp = sbus_readw(qpti->qregs + SBUS_SEMAPHORE); | 188 | tmp = sbus_readw(qpti->qregs + SBUS_SEMAPHORE); |
189 | tmp |= SBUS_SEMAPHORE_LCK; | 189 | tmp |= SBUS_SEMAPHORE_LCK; |
190 | sbus_writew(tmp, qpti->qregs + SBUS_SEMAPHORE); | 190 | sbus_writew(tmp, qpti->qregs + SBUS_SEMAPHORE); |
191 | 191 | ||
192 | /* Wait for host IRQ bit to clear. */ | 192 | /* Wait for host IRQ bit to clear. */ |
193 | loop_count = DEFAULT_LOOP_COUNT; | 193 | loop_count = DEFAULT_LOOP_COUNT; |
194 | while (--loop_count && (sbus_readw(qpti->qregs + HCCTRL) & HCCTRL_HIRQ)) { | 194 | while (--loop_count && (sbus_readw(qpti->qregs + HCCTRL) & HCCTRL_HIRQ)) { |
195 | barrier(); | 195 | barrier(); |
196 | cpu_relax(); | 196 | cpu_relax(); |
197 | } | 197 | } |
198 | if (!loop_count) | 198 | if (!loop_count) |
199 | printk(KERN_EMERG "qlogicpti: mbox_command loop timeout #1\n"); | 199 | printk(KERN_EMERG "qlogicpti: mbox_command loop timeout #1\n"); |
200 | 200 | ||
201 | /* Write mailbox command registers. */ | 201 | /* Write mailbox command registers. */ |
202 | switch (mbox_param[param[0]] >> 4) { | 202 | switch (mbox_param[param[0]] >> 4) { |
203 | case 6: sbus_writew(param[5], qpti->qregs + MBOX5); | 203 | case 6: sbus_writew(param[5], qpti->qregs + MBOX5); |
204 | case 5: sbus_writew(param[4], qpti->qregs + MBOX4); | 204 | case 5: sbus_writew(param[4], qpti->qregs + MBOX4); |
205 | case 4: sbus_writew(param[3], qpti->qregs + MBOX3); | 205 | case 4: sbus_writew(param[3], qpti->qregs + MBOX3); |
206 | case 3: sbus_writew(param[2], qpti->qregs + MBOX2); | 206 | case 3: sbus_writew(param[2], qpti->qregs + MBOX2); |
207 | case 2: sbus_writew(param[1], qpti->qregs + MBOX1); | 207 | case 2: sbus_writew(param[1], qpti->qregs + MBOX1); |
208 | case 1: sbus_writew(param[0], qpti->qregs + MBOX0); | 208 | case 1: sbus_writew(param[0], qpti->qregs + MBOX0); |
209 | } | 209 | } |
210 | 210 | ||
211 | /* Clear RISC interrupt. */ | 211 | /* Clear RISC interrupt. */ |
212 | tmp = sbus_readw(qpti->qregs + HCCTRL); | 212 | tmp = sbus_readw(qpti->qregs + HCCTRL); |
213 | tmp |= HCCTRL_CRIRQ; | 213 | tmp |= HCCTRL_CRIRQ; |
214 | sbus_writew(tmp, qpti->qregs + HCCTRL); | 214 | sbus_writew(tmp, qpti->qregs + HCCTRL); |
215 | 215 | ||
216 | /* Clear SBUS semaphore. */ | 216 | /* Clear SBUS semaphore. */ |
217 | sbus_writew(0, qpti->qregs + SBUS_SEMAPHORE); | 217 | sbus_writew(0, qpti->qregs + SBUS_SEMAPHORE); |
218 | 218 | ||
219 | /* Set HOST interrupt. */ | 219 | /* Set HOST interrupt. */ |
220 | tmp = sbus_readw(qpti->qregs + HCCTRL); | 220 | tmp = sbus_readw(qpti->qregs + HCCTRL); |
221 | tmp |= HCCTRL_SHIRQ; | 221 | tmp |= HCCTRL_SHIRQ; |
222 | sbus_writew(tmp, qpti->qregs + HCCTRL); | 222 | sbus_writew(tmp, qpti->qregs + HCCTRL); |
223 | 223 | ||
224 | /* Wait for HOST interrupt clears. */ | 224 | /* Wait for HOST interrupt clears. */ |
225 | loop_count = DEFAULT_LOOP_COUNT; | 225 | loop_count = DEFAULT_LOOP_COUNT; |
226 | while (--loop_count && | 226 | while (--loop_count && |
227 | (sbus_readw(qpti->qregs + HCCTRL) & HCCTRL_CRIRQ)) | 227 | (sbus_readw(qpti->qregs + HCCTRL) & HCCTRL_CRIRQ)) |
228 | udelay(20); | 228 | udelay(20); |
229 | if (!loop_count) | 229 | if (!loop_count) |
230 | printk(KERN_EMERG "qlogicpti: mbox_command[%04x] loop timeout #2\n", | 230 | printk(KERN_EMERG "qlogicpti: mbox_command[%04x] loop timeout #2\n", |
231 | param[0]); | 231 | param[0]); |
232 | 232 | ||
233 | /* Wait for SBUS semaphore to get set. */ | 233 | /* Wait for SBUS semaphore to get set. */ |
234 | loop_count = DEFAULT_LOOP_COUNT; | 234 | loop_count = DEFAULT_LOOP_COUNT; |
235 | while (--loop_count && | 235 | while (--loop_count && |
236 | !(sbus_readw(qpti->qregs + SBUS_SEMAPHORE) & SBUS_SEMAPHORE_LCK)) { | 236 | !(sbus_readw(qpti->qregs + SBUS_SEMAPHORE) & SBUS_SEMAPHORE_LCK)) { |
237 | udelay(20); | 237 | udelay(20); |
238 | 238 | ||
239 | /* Workaround for some buggy chips. */ | 239 | /* Workaround for some buggy chips. */ |
240 | if (sbus_readw(qpti->qregs + MBOX0) & 0x4000) | 240 | if (sbus_readw(qpti->qregs + MBOX0) & 0x4000) |
241 | break; | 241 | break; |
242 | } | 242 | } |
243 | if (!loop_count) | 243 | if (!loop_count) |
244 | printk(KERN_EMERG "qlogicpti: mbox_command[%04x] loop timeout #3\n", | 244 | printk(KERN_EMERG "qlogicpti: mbox_command[%04x] loop timeout #3\n", |
245 | param[0]); | 245 | param[0]); |
246 | 246 | ||
247 | /* Wait for MBOX busy condition to go away. */ | 247 | /* Wait for MBOX busy condition to go away. */ |
248 | loop_count = DEFAULT_LOOP_COUNT; | 248 | loop_count = DEFAULT_LOOP_COUNT; |
249 | while (--loop_count && (sbus_readw(qpti->qregs + MBOX0) == 0x04)) | 249 | while (--loop_count && (sbus_readw(qpti->qregs + MBOX0) == 0x04)) |
250 | udelay(20); | 250 | udelay(20); |
251 | if (!loop_count) | 251 | if (!loop_count) |
252 | printk(KERN_EMERG "qlogicpti: mbox_command[%04x] loop timeout #4\n", | 252 | printk(KERN_EMERG "qlogicpti: mbox_command[%04x] loop timeout #4\n", |
253 | param[0]); | 253 | param[0]); |
254 | 254 | ||
255 | /* Read back output parameters. */ | 255 | /* Read back output parameters. */ |
256 | switch (mbox_param[param[0]] & 0xf) { | 256 | switch (mbox_param[param[0]] & 0xf) { |
257 | case 6: param[5] = sbus_readw(qpti->qregs + MBOX5); | 257 | case 6: param[5] = sbus_readw(qpti->qregs + MBOX5); |
258 | case 5: param[4] = sbus_readw(qpti->qregs + MBOX4); | 258 | case 5: param[4] = sbus_readw(qpti->qregs + MBOX4); |
259 | case 4: param[3] = sbus_readw(qpti->qregs + MBOX3); | 259 | case 4: param[3] = sbus_readw(qpti->qregs + MBOX3); |
260 | case 3: param[2] = sbus_readw(qpti->qregs + MBOX2); | 260 | case 3: param[2] = sbus_readw(qpti->qregs + MBOX2); |
261 | case 2: param[1] = sbus_readw(qpti->qregs + MBOX1); | 261 | case 2: param[1] = sbus_readw(qpti->qregs + MBOX1); |
262 | case 1: param[0] = sbus_readw(qpti->qregs + MBOX0); | 262 | case 1: param[0] = sbus_readw(qpti->qregs + MBOX0); |
263 | } | 263 | } |
264 | 264 | ||
265 | /* Clear RISC interrupt. */ | 265 | /* Clear RISC interrupt. */ |
266 | tmp = sbus_readw(qpti->qregs + HCCTRL); | 266 | tmp = sbus_readw(qpti->qregs + HCCTRL); |
267 | tmp |= HCCTRL_CRIRQ; | 267 | tmp |= HCCTRL_CRIRQ; |
268 | sbus_writew(tmp, qpti->qregs + HCCTRL); | 268 | sbus_writew(tmp, qpti->qregs + HCCTRL); |
269 | 269 | ||
270 | /* Release SBUS semaphore. */ | 270 | /* Release SBUS semaphore. */ |
271 | tmp = sbus_readw(qpti->qregs + SBUS_SEMAPHORE); | 271 | tmp = sbus_readw(qpti->qregs + SBUS_SEMAPHORE); |
272 | tmp &= ~(SBUS_SEMAPHORE_LCK); | 272 | tmp &= ~(SBUS_SEMAPHORE_LCK); |
273 | sbus_writew(tmp, qpti->qregs + SBUS_SEMAPHORE); | 273 | sbus_writew(tmp, qpti->qregs + SBUS_SEMAPHORE); |
274 | 274 | ||
275 | /* We're done. */ | 275 | /* We're done. */ |
276 | return 0; | 276 | return 0; |
277 | } | 277 | } |
278 | 278 | ||
279 | static inline void qlogicpti_set_hostdev_defaults(struct qlogicpti *qpti) | 279 | static inline void qlogicpti_set_hostdev_defaults(struct qlogicpti *qpti) |
280 | { | 280 | { |
281 | int i; | 281 | int i; |
282 | 282 | ||
283 | qpti->host_param.initiator_scsi_id = qpti->scsi_id; | 283 | qpti->host_param.initiator_scsi_id = qpti->scsi_id; |
284 | qpti->host_param.bus_reset_delay = 3; | 284 | qpti->host_param.bus_reset_delay = 3; |
285 | qpti->host_param.retry_count = 0; | 285 | qpti->host_param.retry_count = 0; |
286 | qpti->host_param.retry_delay = 5; | 286 | qpti->host_param.retry_delay = 5; |
287 | qpti->host_param.async_data_setup_time = 3; | 287 | qpti->host_param.async_data_setup_time = 3; |
288 | qpti->host_param.req_ack_active_negation = 1; | 288 | qpti->host_param.req_ack_active_negation = 1; |
289 | qpti->host_param.data_line_active_negation = 1; | 289 | qpti->host_param.data_line_active_negation = 1; |
290 | qpti->host_param.data_dma_burst_enable = 1; | 290 | qpti->host_param.data_dma_burst_enable = 1; |
291 | qpti->host_param.command_dma_burst_enable = 1; | 291 | qpti->host_param.command_dma_burst_enable = 1; |
292 | qpti->host_param.tag_aging = 8; | 292 | qpti->host_param.tag_aging = 8; |
293 | qpti->host_param.selection_timeout = 250; | 293 | qpti->host_param.selection_timeout = 250; |
294 | qpti->host_param.max_queue_depth = 256; | 294 | qpti->host_param.max_queue_depth = 256; |
295 | 295 | ||
296 | for(i = 0; i < MAX_TARGETS; i++) { | 296 | for(i = 0; i < MAX_TARGETS; i++) { |
297 | /* | 297 | /* |
298 | * disconnect, parity, arq, reneg on reset, and, oddly enough | 298 | * disconnect, parity, arq, reneg on reset, and, oddly enough |
299 | * tags...the midlayer's notion of tagged support has to match | 299 | * tags...the midlayer's notion of tagged support has to match |
300 | * our device settings, and since we base whether we enable a | 300 | * our device settings, and since we base whether we enable a |
301 | * tag on a per-cmnd basis upon what the midlayer sez, we | 301 | * tag on a per-cmnd basis upon what the midlayer sez, we |
302 | * actually enable the capability here. | 302 | * actually enable the capability here. |
303 | */ | 303 | */ |
304 | qpti->dev_param[i].device_flags = 0xcd; | 304 | qpti->dev_param[i].device_flags = 0xcd; |
305 | qpti->dev_param[i].execution_throttle = 16; | 305 | qpti->dev_param[i].execution_throttle = 16; |
306 | if (qpti->ultra) { | 306 | if (qpti->ultra) { |
307 | qpti->dev_param[i].synchronous_period = 12; | 307 | qpti->dev_param[i].synchronous_period = 12; |
308 | qpti->dev_param[i].synchronous_offset = 8; | 308 | qpti->dev_param[i].synchronous_offset = 8; |
309 | } else { | 309 | } else { |
310 | qpti->dev_param[i].synchronous_period = 25; | 310 | qpti->dev_param[i].synchronous_period = 25; |
311 | qpti->dev_param[i].synchronous_offset = 12; | 311 | qpti->dev_param[i].synchronous_offset = 12; |
312 | } | 312 | } |
313 | qpti->dev_param[i].device_enable = 1; | 313 | qpti->dev_param[i].device_enable = 1; |
314 | } | 314 | } |
315 | /* this is very important to set! */ | 315 | /* this is very important to set! */ |
316 | qpti->sbits = 1 << qpti->scsi_id; | 316 | qpti->sbits = 1 << qpti->scsi_id; |
317 | } | 317 | } |
318 | 318 | ||
319 | static int qlogicpti_reset_hardware(struct Scsi_Host *host) | 319 | static int qlogicpti_reset_hardware(struct Scsi_Host *host) |
320 | { | 320 | { |
321 | struct qlogicpti *qpti = (struct qlogicpti *) host->hostdata; | 321 | struct qlogicpti *qpti = (struct qlogicpti *) host->hostdata; |
322 | u_short param[6]; | 322 | u_short param[6]; |
323 | unsigned short risc_code_addr; | 323 | unsigned short risc_code_addr; |
324 | int loop_count, i; | 324 | int loop_count, i; |
325 | unsigned long flags; | 325 | unsigned long flags; |
326 | 326 | ||
327 | risc_code_addr = 0x1000; /* all load addresses are at 0x1000 */ | 327 | risc_code_addr = 0x1000; /* all load addresses are at 0x1000 */ |
328 | 328 | ||
329 | spin_lock_irqsave(host->host_lock, flags); | 329 | spin_lock_irqsave(host->host_lock, flags); |
330 | 330 | ||
331 | sbus_writew(HCCTRL_PAUSE, qpti->qregs + HCCTRL); | 331 | sbus_writew(HCCTRL_PAUSE, qpti->qregs + HCCTRL); |
332 | 332 | ||
333 | /* Only reset the scsi bus if it is not free. */ | 333 | /* Only reset the scsi bus if it is not free. */ |
334 | if (sbus_readw(qpti->qregs + CPU_PCTRL) & CPU_PCTRL_BSY) { | 334 | if (sbus_readw(qpti->qregs + CPU_PCTRL) & CPU_PCTRL_BSY) { |
335 | sbus_writew(CPU_ORIDE_RMOD, qpti->qregs + CPU_ORIDE); | 335 | sbus_writew(CPU_ORIDE_RMOD, qpti->qregs + CPU_ORIDE); |
336 | sbus_writew(CPU_CMD_BRESET, qpti->qregs + CPU_CMD); | 336 | sbus_writew(CPU_CMD_BRESET, qpti->qregs + CPU_CMD); |
337 | udelay(400); | 337 | udelay(400); |
338 | } | 338 | } |
339 | 339 | ||
340 | sbus_writew(SBUS_CTRL_RESET, qpti->qregs + SBUS_CTRL); | 340 | sbus_writew(SBUS_CTRL_RESET, qpti->qregs + SBUS_CTRL); |
341 | sbus_writew((DMA_CTRL_CCLEAR | DMA_CTRL_CIRQ), qpti->qregs + CMD_DMA_CTRL); | 341 | sbus_writew((DMA_CTRL_CCLEAR | DMA_CTRL_CIRQ), qpti->qregs + CMD_DMA_CTRL); |
342 | sbus_writew((DMA_CTRL_CCLEAR | DMA_CTRL_CIRQ), qpti->qregs + DATA_DMA_CTRL); | 342 | sbus_writew((DMA_CTRL_CCLEAR | DMA_CTRL_CIRQ), qpti->qregs + DATA_DMA_CTRL); |
343 | 343 | ||
344 | loop_count = DEFAULT_LOOP_COUNT; | 344 | loop_count = DEFAULT_LOOP_COUNT; |
345 | while (--loop_count && ((sbus_readw(qpti->qregs + MBOX0) & 0xff) == 0x04)) | 345 | while (--loop_count && ((sbus_readw(qpti->qregs + MBOX0) & 0xff) == 0x04)) |
346 | udelay(20); | 346 | udelay(20); |
347 | if (!loop_count) | 347 | if (!loop_count) |
348 | printk(KERN_EMERG "qlogicpti: reset_hardware loop timeout\n"); | 348 | printk(KERN_EMERG "qlogicpti: reset_hardware loop timeout\n"); |
349 | 349 | ||
350 | sbus_writew(HCCTRL_PAUSE, qpti->qregs + HCCTRL); | 350 | sbus_writew(HCCTRL_PAUSE, qpti->qregs + HCCTRL); |
351 | set_sbus_cfg1(qpti); | 351 | set_sbus_cfg1(qpti); |
352 | qlogicpti_enable_irqs(qpti); | 352 | qlogicpti_enable_irqs(qpti); |
353 | 353 | ||
354 | if (sbus_readw(qpti->qregs + RISC_PSR) & RISC_PSR_ULTRA) { | 354 | if (sbus_readw(qpti->qregs + RISC_PSR) & RISC_PSR_ULTRA) { |
355 | qpti->ultra = 1; | 355 | qpti->ultra = 1; |
356 | sbus_writew((RISC_MTREG_P0ULTRA | RISC_MTREG_P1ULTRA), | 356 | sbus_writew((RISC_MTREG_P0ULTRA | RISC_MTREG_P1ULTRA), |
357 | qpti->qregs + RISC_MTREG); | 357 | qpti->qregs + RISC_MTREG); |
358 | } else { | 358 | } else { |
359 | qpti->ultra = 0; | 359 | qpti->ultra = 0; |
360 | sbus_writew((RISC_MTREG_P0DFLT | RISC_MTREG_P1DFLT), | 360 | sbus_writew((RISC_MTREG_P0DFLT | RISC_MTREG_P1DFLT), |
361 | qpti->qregs + RISC_MTREG); | 361 | qpti->qregs + RISC_MTREG); |
362 | } | 362 | } |
363 | 363 | ||
364 | /* reset adapter and per-device default values. */ | 364 | /* reset adapter and per-device default values. */ |
365 | /* do it after finding out whether we're ultra mode capable */ | 365 | /* do it after finding out whether we're ultra mode capable */ |
366 | qlogicpti_set_hostdev_defaults(qpti); | 366 | qlogicpti_set_hostdev_defaults(qpti); |
367 | 367 | ||
368 | /* Release the RISC processor. */ | 368 | /* Release the RISC processor. */ |
369 | sbus_writew(HCCTRL_REL, qpti->qregs + HCCTRL); | 369 | sbus_writew(HCCTRL_REL, qpti->qregs + HCCTRL); |
370 | 370 | ||
371 | /* Get RISC to start executing the firmware code. */ | 371 | /* Get RISC to start executing the firmware code. */ |
372 | param[0] = MBOX_EXEC_FIRMWARE; | 372 | param[0] = MBOX_EXEC_FIRMWARE; |
373 | param[1] = risc_code_addr; | 373 | param[1] = risc_code_addr; |
374 | if (qlogicpti_mbox_command(qpti, param, 1)) { | 374 | if (qlogicpti_mbox_command(qpti, param, 1)) { |
375 | printk(KERN_EMERG "qlogicpti%d: Cannot execute ISP firmware.\n", | 375 | printk(KERN_EMERG "qlogicpti%d: Cannot execute ISP firmware.\n", |
376 | qpti->qpti_id); | 376 | qpti->qpti_id); |
377 | spin_unlock_irqrestore(host->host_lock, flags); | 377 | spin_unlock_irqrestore(host->host_lock, flags); |
378 | return 1; | 378 | return 1; |
379 | } | 379 | } |
380 | 380 | ||
381 | /* Set initiator scsi ID. */ | 381 | /* Set initiator scsi ID. */ |
382 | param[0] = MBOX_SET_INIT_SCSI_ID; | 382 | param[0] = MBOX_SET_INIT_SCSI_ID; |
383 | param[1] = qpti->host_param.initiator_scsi_id; | 383 | param[1] = qpti->host_param.initiator_scsi_id; |
384 | if (qlogicpti_mbox_command(qpti, param, 1) || | 384 | if (qlogicpti_mbox_command(qpti, param, 1) || |
385 | (param[0] != MBOX_COMMAND_COMPLETE)) { | 385 | (param[0] != MBOX_COMMAND_COMPLETE)) { |
386 | printk(KERN_EMERG "qlogicpti%d: Cannot set initiator SCSI ID.\n", | 386 | printk(KERN_EMERG "qlogicpti%d: Cannot set initiator SCSI ID.\n", |
387 | qpti->qpti_id); | 387 | qpti->qpti_id); |
388 | spin_unlock_irqrestore(host->host_lock, flags); | 388 | spin_unlock_irqrestore(host->host_lock, flags); |
389 | return 1; | 389 | return 1; |
390 | } | 390 | } |
391 | 391 | ||
392 | /* Initialize state of the queues, both hw and sw. */ | 392 | /* Initialize state of the queues, both hw and sw. */ |
393 | qpti->req_in_ptr = qpti->res_out_ptr = 0; | 393 | qpti->req_in_ptr = qpti->res_out_ptr = 0; |
394 | 394 | ||
395 | param[0] = MBOX_INIT_RES_QUEUE; | 395 | param[0] = MBOX_INIT_RES_QUEUE; |
396 | param[1] = RES_QUEUE_LEN + 1; | 396 | param[1] = RES_QUEUE_LEN + 1; |
397 | param[2] = (u_short) (qpti->res_dvma >> 16); | 397 | param[2] = (u_short) (qpti->res_dvma >> 16); |
398 | param[3] = (u_short) (qpti->res_dvma & 0xffff); | 398 | param[3] = (u_short) (qpti->res_dvma & 0xffff); |
399 | param[4] = param[5] = 0; | 399 | param[4] = param[5] = 0; |
400 | if (qlogicpti_mbox_command(qpti, param, 1)) { | 400 | if (qlogicpti_mbox_command(qpti, param, 1)) { |
401 | printk(KERN_EMERG "qlogicpti%d: Cannot init response queue.\n", | 401 | printk(KERN_EMERG "qlogicpti%d: Cannot init response queue.\n", |
402 | qpti->qpti_id); | 402 | qpti->qpti_id); |
403 | spin_unlock_irqrestore(host->host_lock, flags); | 403 | spin_unlock_irqrestore(host->host_lock, flags); |
404 | return 1; | 404 | return 1; |
405 | } | 405 | } |
406 | 406 | ||
407 | param[0] = MBOX_INIT_REQ_QUEUE; | 407 | param[0] = MBOX_INIT_REQ_QUEUE; |
408 | param[1] = QLOGICPTI_REQ_QUEUE_LEN + 1; | 408 | param[1] = QLOGICPTI_REQ_QUEUE_LEN + 1; |
409 | param[2] = (u_short) (qpti->req_dvma >> 16); | 409 | param[2] = (u_short) (qpti->req_dvma >> 16); |
410 | param[3] = (u_short) (qpti->req_dvma & 0xffff); | 410 | param[3] = (u_short) (qpti->req_dvma & 0xffff); |
411 | param[4] = param[5] = 0; | 411 | param[4] = param[5] = 0; |
412 | if (qlogicpti_mbox_command(qpti, param, 1)) { | 412 | if (qlogicpti_mbox_command(qpti, param, 1)) { |
413 | printk(KERN_EMERG "qlogicpti%d: Cannot init request queue.\n", | 413 | printk(KERN_EMERG "qlogicpti%d: Cannot init request queue.\n", |
414 | qpti->qpti_id); | 414 | qpti->qpti_id); |
415 | spin_unlock_irqrestore(host->host_lock, flags); | 415 | spin_unlock_irqrestore(host->host_lock, flags); |
416 | return 1; | 416 | return 1; |
417 | } | 417 | } |
418 | 418 | ||
419 | param[0] = MBOX_SET_RETRY_COUNT; | 419 | param[0] = MBOX_SET_RETRY_COUNT; |
420 | param[1] = qpti->host_param.retry_count; | 420 | param[1] = qpti->host_param.retry_count; |
421 | param[2] = qpti->host_param.retry_delay; | 421 | param[2] = qpti->host_param.retry_delay; |
422 | qlogicpti_mbox_command(qpti, param, 0); | 422 | qlogicpti_mbox_command(qpti, param, 0); |
423 | 423 | ||
424 | param[0] = MBOX_SET_TAG_AGE_LIMIT; | 424 | param[0] = MBOX_SET_TAG_AGE_LIMIT; |
425 | param[1] = qpti->host_param.tag_aging; | 425 | param[1] = qpti->host_param.tag_aging; |
426 | qlogicpti_mbox_command(qpti, param, 0); | 426 | qlogicpti_mbox_command(qpti, param, 0); |
427 | 427 | ||
428 | for (i = 0; i < MAX_TARGETS; i++) { | 428 | for (i = 0; i < MAX_TARGETS; i++) { |
429 | param[0] = MBOX_GET_DEV_QUEUE_PARAMS; | 429 | param[0] = MBOX_GET_DEV_QUEUE_PARAMS; |
430 | param[1] = (i << 8); | 430 | param[1] = (i << 8); |
431 | qlogicpti_mbox_command(qpti, param, 0); | 431 | qlogicpti_mbox_command(qpti, param, 0); |
432 | } | 432 | } |
433 | 433 | ||
434 | param[0] = MBOX_GET_FIRMWARE_STATUS; | 434 | param[0] = MBOX_GET_FIRMWARE_STATUS; |
435 | qlogicpti_mbox_command(qpti, param, 0); | 435 | qlogicpti_mbox_command(qpti, param, 0); |
436 | 436 | ||
437 | param[0] = MBOX_SET_SELECT_TIMEOUT; | 437 | param[0] = MBOX_SET_SELECT_TIMEOUT; |
438 | param[1] = qpti->host_param.selection_timeout; | 438 | param[1] = qpti->host_param.selection_timeout; |
439 | qlogicpti_mbox_command(qpti, param, 0); | 439 | qlogicpti_mbox_command(qpti, param, 0); |
440 | 440 | ||
441 | for (i = 0; i < MAX_TARGETS; i++) { | 441 | for (i = 0; i < MAX_TARGETS; i++) { |
442 | param[0] = MBOX_SET_TARGET_PARAMS; | 442 | param[0] = MBOX_SET_TARGET_PARAMS; |
443 | param[1] = (i << 8); | 443 | param[1] = (i << 8); |
444 | param[2] = (qpti->dev_param[i].device_flags << 8); | 444 | param[2] = (qpti->dev_param[i].device_flags << 8); |
445 | /* | 445 | /* |
446 | * Since we're now loading 1.31 f/w, force narrow/async. | 446 | * Since we're now loading 1.31 f/w, force narrow/async. |
447 | */ | 447 | */ |
448 | param[2] |= 0xc0; | 448 | param[2] |= 0xc0; |
449 | param[3] = 0; /* no offset, we do not have sync mode yet */ | 449 | param[3] = 0; /* no offset, we do not have sync mode yet */ |
450 | qlogicpti_mbox_command(qpti, param, 0); | 450 | qlogicpti_mbox_command(qpti, param, 0); |
451 | } | 451 | } |
452 | 452 | ||
453 | /* | 453 | /* |
454 | * Always (sigh) do an initial bus reset (kicks f/w). | 454 | * Always (sigh) do an initial bus reset (kicks f/w). |
455 | */ | 455 | */ |
456 | param[0] = MBOX_BUS_RESET; | 456 | param[0] = MBOX_BUS_RESET; |
457 | param[1] = qpti->host_param.bus_reset_delay; | 457 | param[1] = qpti->host_param.bus_reset_delay; |
458 | qlogicpti_mbox_command(qpti, param, 0); | 458 | qlogicpti_mbox_command(qpti, param, 0); |
459 | qpti->send_marker = 1; | 459 | qpti->send_marker = 1; |
460 | 460 | ||
461 | spin_unlock_irqrestore(host->host_lock, flags); | 461 | spin_unlock_irqrestore(host->host_lock, flags); |
462 | return 0; | 462 | return 0; |
463 | } | 463 | } |
464 | 464 | ||
465 | #define PTI_RESET_LIMIT 400 | 465 | #define PTI_RESET_LIMIT 400 |
466 | 466 | ||
467 | static int __init qlogicpti_load_firmware(struct qlogicpti *qpti) | 467 | static int __init qlogicpti_load_firmware(struct qlogicpti *qpti) |
468 | { | 468 | { |
469 | struct Scsi_Host *host = qpti->qhost; | 469 | struct Scsi_Host *host = qpti->qhost; |
470 | unsigned short csum = 0; | 470 | unsigned short csum = 0; |
471 | unsigned short param[6]; | 471 | unsigned short param[6]; |
472 | unsigned short *risc_code, risc_code_addr, risc_code_length; | 472 | unsigned short *risc_code, risc_code_addr, risc_code_length; |
473 | unsigned long flags; | 473 | unsigned long flags; |
474 | int i, timeout; | 474 | int i, timeout; |
475 | 475 | ||
476 | risc_code = &sbus_risc_code01[0]; | 476 | risc_code = &sbus_risc_code01[0]; |
477 | risc_code_addr = 0x1000; /* all f/w modules load at 0x1000 */ | 477 | risc_code_addr = 0x1000; /* all f/w modules load at 0x1000 */ |
478 | risc_code_length = sbus_risc_code_length01; | 478 | risc_code_length = sbus_risc_code_length01; |
479 | 479 | ||
480 | spin_lock_irqsave(host->host_lock, flags); | 480 | spin_lock_irqsave(host->host_lock, flags); |
481 | 481 | ||
482 | /* Verify the checksum twice, one before loading it, and once | 482 | /* Verify the checksum twice, one before loading it, and once |
483 | * afterwards via the mailbox commands. | 483 | * afterwards via the mailbox commands. |
484 | */ | 484 | */ |
485 | for (i = 0; i < risc_code_length; i++) | 485 | for (i = 0; i < risc_code_length; i++) |
486 | csum += risc_code[i]; | 486 | csum += risc_code[i]; |
487 | if (csum) { | 487 | if (csum) { |
488 | spin_unlock_irqrestore(host->host_lock, flags); | 488 | spin_unlock_irqrestore(host->host_lock, flags); |
489 | printk(KERN_EMERG "qlogicpti%d: Aieee, firmware checksum failed!", | 489 | printk(KERN_EMERG "qlogicpti%d: Aieee, firmware checksum failed!", |
490 | qpti->qpti_id); | 490 | qpti->qpti_id); |
491 | return 1; | 491 | return 1; |
492 | } | 492 | } |
493 | sbus_writew(SBUS_CTRL_RESET, qpti->qregs + SBUS_CTRL); | 493 | sbus_writew(SBUS_CTRL_RESET, qpti->qregs + SBUS_CTRL); |
494 | sbus_writew((DMA_CTRL_CCLEAR | DMA_CTRL_CIRQ), qpti->qregs + CMD_DMA_CTRL); | 494 | sbus_writew((DMA_CTRL_CCLEAR | DMA_CTRL_CIRQ), qpti->qregs + CMD_DMA_CTRL); |
495 | sbus_writew((DMA_CTRL_CCLEAR | DMA_CTRL_CIRQ), qpti->qregs + DATA_DMA_CTRL); | 495 | sbus_writew((DMA_CTRL_CCLEAR | DMA_CTRL_CIRQ), qpti->qregs + DATA_DMA_CTRL); |
496 | timeout = PTI_RESET_LIMIT; | 496 | timeout = PTI_RESET_LIMIT; |
497 | while (--timeout && (sbus_readw(qpti->qregs + SBUS_CTRL) & SBUS_CTRL_RESET)) | 497 | while (--timeout && (sbus_readw(qpti->qregs + SBUS_CTRL) & SBUS_CTRL_RESET)) |
498 | udelay(20); | 498 | udelay(20); |
499 | if (!timeout) { | 499 | if (!timeout) { |
500 | spin_unlock_irqrestore(host->host_lock, flags); | 500 | spin_unlock_irqrestore(host->host_lock, flags); |
501 | printk(KERN_EMERG "qlogicpti%d: Cannot reset the ISP.", qpti->qpti_id); | 501 | printk(KERN_EMERG "qlogicpti%d: Cannot reset the ISP.", qpti->qpti_id); |
502 | return 1; | 502 | return 1; |
503 | } | 503 | } |
504 | 504 | ||
505 | sbus_writew(HCCTRL_RESET, qpti->qregs + HCCTRL); | 505 | sbus_writew(HCCTRL_RESET, qpti->qregs + HCCTRL); |
506 | mdelay(1); | 506 | mdelay(1); |
507 | 507 | ||
508 | sbus_writew((SBUS_CTRL_GENAB | SBUS_CTRL_ERIRQ), qpti->qregs + SBUS_CTRL); | 508 | sbus_writew((SBUS_CTRL_GENAB | SBUS_CTRL_ERIRQ), qpti->qregs + SBUS_CTRL); |
509 | set_sbus_cfg1(qpti); | 509 | set_sbus_cfg1(qpti); |
510 | sbus_writew(0, qpti->qregs + SBUS_SEMAPHORE); | 510 | sbus_writew(0, qpti->qregs + SBUS_SEMAPHORE); |
511 | 511 | ||
512 | if (sbus_readw(qpti->qregs + RISC_PSR) & RISC_PSR_ULTRA) { | 512 | if (sbus_readw(qpti->qregs + RISC_PSR) & RISC_PSR_ULTRA) { |
513 | qpti->ultra = 1; | 513 | qpti->ultra = 1; |
514 | sbus_writew((RISC_MTREG_P0ULTRA | RISC_MTREG_P1ULTRA), | 514 | sbus_writew((RISC_MTREG_P0ULTRA | RISC_MTREG_P1ULTRA), |
515 | qpti->qregs + RISC_MTREG); | 515 | qpti->qregs + RISC_MTREG); |
516 | } else { | 516 | } else { |
517 | qpti->ultra = 0; | 517 | qpti->ultra = 0; |
518 | sbus_writew((RISC_MTREG_P0DFLT | RISC_MTREG_P1DFLT), | 518 | sbus_writew((RISC_MTREG_P0DFLT | RISC_MTREG_P1DFLT), |
519 | qpti->qregs + RISC_MTREG); | 519 | qpti->qregs + RISC_MTREG); |
520 | } | 520 | } |
521 | 521 | ||
522 | sbus_writew(HCCTRL_REL, qpti->qregs + HCCTRL); | 522 | sbus_writew(HCCTRL_REL, qpti->qregs + HCCTRL); |
523 | 523 | ||
524 | /* Pin lines are only stable while RISC is paused. */ | 524 | /* Pin lines are only stable while RISC is paused. */ |
525 | sbus_writew(HCCTRL_PAUSE, qpti->qregs + HCCTRL); | 525 | sbus_writew(HCCTRL_PAUSE, qpti->qregs + HCCTRL); |
526 | if (sbus_readw(qpti->qregs + CPU_PDIFF) & CPU_PDIFF_MODE) | 526 | if (sbus_readw(qpti->qregs + CPU_PDIFF) & CPU_PDIFF_MODE) |
527 | qpti->differential = 1; | 527 | qpti->differential = 1; |
528 | else | 528 | else |
529 | qpti->differential = 0; | 529 | qpti->differential = 0; |
530 | sbus_writew(HCCTRL_REL, qpti->qregs + HCCTRL); | 530 | sbus_writew(HCCTRL_REL, qpti->qregs + HCCTRL); |
531 | 531 | ||
532 | /* This shouldn't be necessary- we've reset things so we should be | 532 | /* This shouldn't be necessary- we've reset things so we should be |
533 | running from the ROM now.. */ | 533 | running from the ROM now.. */ |
534 | 534 | ||
535 | param[0] = MBOX_STOP_FIRMWARE; | 535 | param[0] = MBOX_STOP_FIRMWARE; |
536 | param[1] = param[2] = param[3] = param[4] = param[5] = 0; | 536 | param[1] = param[2] = param[3] = param[4] = param[5] = 0; |
537 | if (qlogicpti_mbox_command(qpti, param, 1)) { | 537 | if (qlogicpti_mbox_command(qpti, param, 1)) { |
538 | printk(KERN_EMERG "qlogicpti%d: Cannot stop firmware for reload.\n", | 538 | printk(KERN_EMERG "qlogicpti%d: Cannot stop firmware for reload.\n", |
539 | qpti->qpti_id); | 539 | qpti->qpti_id); |
540 | spin_unlock_irqrestore(host->host_lock, flags); | 540 | spin_unlock_irqrestore(host->host_lock, flags); |
541 | return 1; | 541 | return 1; |
542 | } | 542 | } |
543 | 543 | ||
544 | /* Load it up.. */ | 544 | /* Load it up.. */ |
545 | for (i = 0; i < risc_code_length; i++) { | 545 | for (i = 0; i < risc_code_length; i++) { |
546 | param[0] = MBOX_WRITE_RAM_WORD; | 546 | param[0] = MBOX_WRITE_RAM_WORD; |
547 | param[1] = risc_code_addr + i; | 547 | param[1] = risc_code_addr + i; |
548 | param[2] = risc_code[i]; | 548 | param[2] = risc_code[i]; |
549 | if (qlogicpti_mbox_command(qpti, param, 1) || | 549 | if (qlogicpti_mbox_command(qpti, param, 1) || |
550 | param[0] != MBOX_COMMAND_COMPLETE) { | 550 | param[0] != MBOX_COMMAND_COMPLETE) { |
551 | printk("qlogicpti%d: Firmware dload failed, I'm bolixed!\n", | 551 | printk("qlogicpti%d: Firmware dload failed, I'm bolixed!\n", |
552 | qpti->qpti_id); | 552 | qpti->qpti_id); |
553 | spin_unlock_irqrestore(host->host_lock, flags); | 553 | spin_unlock_irqrestore(host->host_lock, flags); |
554 | return 1; | 554 | return 1; |
555 | } | 555 | } |
556 | } | 556 | } |
557 | 557 | ||
558 | /* Reset the ISP again. */ | 558 | /* Reset the ISP again. */ |
559 | sbus_writew(HCCTRL_RESET, qpti->qregs + HCCTRL); | 559 | sbus_writew(HCCTRL_RESET, qpti->qregs + HCCTRL); |
560 | mdelay(1); | 560 | mdelay(1); |
561 | 561 | ||
562 | qlogicpti_enable_irqs(qpti); | 562 | qlogicpti_enable_irqs(qpti); |
563 | sbus_writew(0, qpti->qregs + SBUS_SEMAPHORE); | 563 | sbus_writew(0, qpti->qregs + SBUS_SEMAPHORE); |
564 | sbus_writew(HCCTRL_REL, qpti->qregs + HCCTRL); | 564 | sbus_writew(HCCTRL_REL, qpti->qregs + HCCTRL); |
565 | 565 | ||
566 | /* Ask ISP to verify the checksum of the new code. */ | 566 | /* Ask ISP to verify the checksum of the new code. */ |
567 | param[0] = MBOX_VERIFY_CHECKSUM; | 567 | param[0] = MBOX_VERIFY_CHECKSUM; |
568 | param[1] = risc_code_addr; | 568 | param[1] = risc_code_addr; |
569 | if (qlogicpti_mbox_command(qpti, param, 1) || | 569 | if (qlogicpti_mbox_command(qpti, param, 1) || |
570 | (param[0] != MBOX_COMMAND_COMPLETE)) { | 570 | (param[0] != MBOX_COMMAND_COMPLETE)) { |
571 | printk(KERN_EMERG "qlogicpti%d: New firmware csum failure!\n", | 571 | printk(KERN_EMERG "qlogicpti%d: New firmware csum failure!\n", |
572 | qpti->qpti_id); | 572 | qpti->qpti_id); |
573 | spin_unlock_irqrestore(host->host_lock, flags); | 573 | spin_unlock_irqrestore(host->host_lock, flags); |
574 | return 1; | 574 | return 1; |
575 | } | 575 | } |
576 | 576 | ||
577 | /* Start using newly downloaded firmware. */ | 577 | /* Start using newly downloaded firmware. */ |
578 | param[0] = MBOX_EXEC_FIRMWARE; | 578 | param[0] = MBOX_EXEC_FIRMWARE; |
579 | param[1] = risc_code_addr; | 579 | param[1] = risc_code_addr; |
580 | qlogicpti_mbox_command(qpti, param, 1); | 580 | qlogicpti_mbox_command(qpti, param, 1); |
581 | 581 | ||
582 | param[0] = MBOX_ABOUT_FIRMWARE; | 582 | param[0] = MBOX_ABOUT_FIRMWARE; |
583 | if (qlogicpti_mbox_command(qpti, param, 1) || | 583 | if (qlogicpti_mbox_command(qpti, param, 1) || |
584 | (param[0] != MBOX_COMMAND_COMPLETE)) { | 584 | (param[0] != MBOX_COMMAND_COMPLETE)) { |
585 | printk(KERN_EMERG "qlogicpti%d: AboutFirmware cmd fails.\n", | 585 | printk(KERN_EMERG "qlogicpti%d: AboutFirmware cmd fails.\n", |
586 | qpti->qpti_id); | 586 | qpti->qpti_id); |
587 | spin_unlock_irqrestore(host->host_lock, flags); | 587 | spin_unlock_irqrestore(host->host_lock, flags); |
588 | return 1; | 588 | return 1; |
589 | } | 589 | } |
590 | 590 | ||
591 | /* Snag the major and minor revisions from the result. */ | 591 | /* Snag the major and minor revisions from the result. */ |
592 | qpti->fware_majrev = param[1]; | 592 | qpti->fware_majrev = param[1]; |
593 | qpti->fware_minrev = param[2]; | 593 | qpti->fware_minrev = param[2]; |
594 | qpti->fware_micrev = param[3]; | 594 | qpti->fware_micrev = param[3]; |
595 | 595 | ||
596 | /* Set the clock rate */ | 596 | /* Set the clock rate */ |
597 | param[0] = MBOX_SET_CLOCK_RATE; | 597 | param[0] = MBOX_SET_CLOCK_RATE; |
598 | param[1] = qpti->clock; | 598 | param[1] = qpti->clock; |
599 | if (qlogicpti_mbox_command(qpti, param, 1) || | 599 | if (qlogicpti_mbox_command(qpti, param, 1) || |
600 | (param[0] != MBOX_COMMAND_COMPLETE)) { | 600 | (param[0] != MBOX_COMMAND_COMPLETE)) { |
601 | printk(KERN_EMERG "qlogicpti%d: could not set clock rate.\n", | 601 | printk(KERN_EMERG "qlogicpti%d: could not set clock rate.\n", |
602 | qpti->qpti_id); | 602 | qpti->qpti_id); |
603 | spin_unlock_irqrestore(host->host_lock, flags); | 603 | spin_unlock_irqrestore(host->host_lock, flags); |
604 | return 1; | 604 | return 1; |
605 | } | 605 | } |
606 | 606 | ||
607 | if (qpti->is_pti != 0) { | 607 | if (qpti->is_pti != 0) { |
608 | /* Load scsi initiator ID and interrupt level into sbus static ram. */ | 608 | /* Load scsi initiator ID and interrupt level into sbus static ram. */ |
609 | param[0] = MBOX_WRITE_RAM_WORD; | 609 | param[0] = MBOX_WRITE_RAM_WORD; |
610 | param[1] = 0xff80; | 610 | param[1] = 0xff80; |
611 | param[2] = (unsigned short) qpti->scsi_id; | 611 | param[2] = (unsigned short) qpti->scsi_id; |
612 | qlogicpti_mbox_command(qpti, param, 1); | 612 | qlogicpti_mbox_command(qpti, param, 1); |
613 | 613 | ||
614 | param[0] = MBOX_WRITE_RAM_WORD; | 614 | param[0] = MBOX_WRITE_RAM_WORD; |
615 | param[1] = 0xff00; | 615 | param[1] = 0xff00; |
616 | param[2] = (unsigned short) 3; | 616 | param[2] = (unsigned short) 3; |
617 | qlogicpti_mbox_command(qpti, param, 1); | 617 | qlogicpti_mbox_command(qpti, param, 1); |
618 | } | 618 | } |
619 | 619 | ||
620 | spin_unlock_irqrestore(host->host_lock, flags); | 620 | spin_unlock_irqrestore(host->host_lock, flags); |
621 | return 0; | 621 | return 0; |
622 | } | 622 | } |
623 | 623 | ||
624 | static int qlogicpti_verify_tmon(struct qlogicpti *qpti) | 624 | static int qlogicpti_verify_tmon(struct qlogicpti *qpti) |
625 | { | 625 | { |
626 | int curstat = sbus_readb(qpti->sreg); | 626 | int curstat = sbus_readb(qpti->sreg); |
627 | 627 | ||
628 | curstat &= 0xf0; | 628 | curstat &= 0xf0; |
629 | if (!(curstat & SREG_FUSE) && (qpti->swsreg & SREG_FUSE)) | 629 | if (!(curstat & SREG_FUSE) && (qpti->swsreg & SREG_FUSE)) |
630 | printk("qlogicpti%d: Fuse returned to normal state.\n", qpti->qpti_id); | 630 | printk("qlogicpti%d: Fuse returned to normal state.\n", qpti->qpti_id); |
631 | if (!(curstat & SREG_TPOWER) && (qpti->swsreg & SREG_TPOWER)) | 631 | if (!(curstat & SREG_TPOWER) && (qpti->swsreg & SREG_TPOWER)) |
632 | printk("qlogicpti%d: termpwr back to normal state.\n", qpti->qpti_id); | 632 | printk("qlogicpti%d: termpwr back to normal state.\n", qpti->qpti_id); |
633 | if (curstat != qpti->swsreg) { | 633 | if (curstat != qpti->swsreg) { |
634 | int error = 0; | 634 | int error = 0; |
635 | if (curstat & SREG_FUSE) { | 635 | if (curstat & SREG_FUSE) { |
636 | error++; | 636 | error++; |
637 | printk("qlogicpti%d: Fuse is open!\n", qpti->qpti_id); | 637 | printk("qlogicpti%d: Fuse is open!\n", qpti->qpti_id); |
638 | } | 638 | } |
639 | if (curstat & SREG_TPOWER) { | 639 | if (curstat & SREG_TPOWER) { |
640 | error++; | 640 | error++; |
641 | printk("qlogicpti%d: termpwr failure\n", qpti->qpti_id); | 641 | printk("qlogicpti%d: termpwr failure\n", qpti->qpti_id); |
642 | } | 642 | } |
643 | if (qpti->differential && | 643 | if (qpti->differential && |
644 | (curstat & SREG_DSENSE) != SREG_DSENSE) { | 644 | (curstat & SREG_DSENSE) != SREG_DSENSE) { |
645 | error++; | 645 | error++; |
646 | printk("qlogicpti%d: You have a single ended device on a " | 646 | printk("qlogicpti%d: You have a single ended device on a " |
647 | "differential bus! Please fix!\n", qpti->qpti_id); | 647 | "differential bus! Please fix!\n", qpti->qpti_id); |
648 | } | 648 | } |
649 | qpti->swsreg = curstat; | 649 | qpti->swsreg = curstat; |
650 | return error; | 650 | return error; |
651 | } | 651 | } |
652 | return 0; | 652 | return 0; |
653 | } | 653 | } |
654 | 654 | ||
655 | static irqreturn_t qpti_intr(int irq, void *dev_id, struct pt_regs *regs); | 655 | static irqreturn_t qpti_intr(int irq, void *dev_id, struct pt_regs *regs); |
656 | 656 | ||
657 | static void __init qpti_chain_add(struct qlogicpti *qpti) | 657 | static void __init qpti_chain_add(struct qlogicpti *qpti) |
658 | { | 658 | { |
659 | spin_lock_irq(&qptichain_lock); | 659 | spin_lock_irq(&qptichain_lock); |
660 | if (qptichain != NULL) { | 660 | if (qptichain != NULL) { |
661 | struct qlogicpti *qlink = qptichain; | 661 | struct qlogicpti *qlink = qptichain; |
662 | 662 | ||
663 | while(qlink->next) | 663 | while(qlink->next) |
664 | qlink = qlink->next; | 664 | qlink = qlink->next; |
665 | qlink->next = qpti; | 665 | qlink->next = qpti; |
666 | } else { | 666 | } else { |
667 | qptichain = qpti; | 667 | qptichain = qpti; |
668 | } | 668 | } |
669 | qpti->next = NULL; | 669 | qpti->next = NULL; |
670 | spin_unlock_irq(&qptichain_lock); | 670 | spin_unlock_irq(&qptichain_lock); |
671 | } | 671 | } |
672 | 672 | ||
673 | static void __init qpti_chain_del(struct qlogicpti *qpti) | 673 | static void __init qpti_chain_del(struct qlogicpti *qpti) |
674 | { | 674 | { |
675 | spin_lock_irq(&qptichain_lock); | 675 | spin_lock_irq(&qptichain_lock); |
676 | if (qptichain == qpti) { | 676 | if (qptichain == qpti) { |
677 | qptichain = qpti->next; | 677 | qptichain = qpti->next; |
678 | } else { | 678 | } else { |
679 | struct qlogicpti *qlink = qptichain; | 679 | struct qlogicpti *qlink = qptichain; |
680 | while(qlink->next != qpti) | 680 | while(qlink->next != qpti) |
681 | qlink = qlink->next; | 681 | qlink = qlink->next; |
682 | qlink->next = qpti->next; | 682 | qlink->next = qpti->next; |
683 | } | 683 | } |
684 | qpti->next = NULL; | 684 | qpti->next = NULL; |
685 | spin_unlock_irq(&qptichain_lock); | 685 | spin_unlock_irq(&qptichain_lock); |
686 | } | 686 | } |
687 | 687 | ||
688 | static int __init qpti_map_regs(struct qlogicpti *qpti) | 688 | static int __init qpti_map_regs(struct qlogicpti *qpti) |
689 | { | 689 | { |
690 | struct sbus_dev *sdev = qpti->sdev; | 690 | struct sbus_dev *sdev = qpti->sdev; |
691 | 691 | ||
692 | qpti->qregs = sbus_ioremap(&sdev->resource[0], 0, | 692 | qpti->qregs = sbus_ioremap(&sdev->resource[0], 0, |
693 | sdev->reg_addrs[0].reg_size, | 693 | sdev->reg_addrs[0].reg_size, |
694 | "PTI Qlogic/ISP"); | 694 | "PTI Qlogic/ISP"); |
695 | if (!qpti->qregs) { | 695 | if (!qpti->qregs) { |
696 | printk("PTI: Qlogic/ISP registers are unmappable\n"); | 696 | printk("PTI: Qlogic/ISP registers are unmappable\n"); |
697 | return -1; | 697 | return -1; |
698 | } | 698 | } |
699 | if (qpti->is_pti) { | 699 | if (qpti->is_pti) { |
700 | qpti->sreg = sbus_ioremap(&sdev->resource[0], (16 * 4096), | 700 | qpti->sreg = sbus_ioremap(&sdev->resource[0], (16 * 4096), |
701 | sizeof(unsigned char), | 701 | sizeof(unsigned char), |
702 | "PTI Qlogic/ISP statreg"); | 702 | "PTI Qlogic/ISP statreg"); |
703 | if (!qpti->sreg) { | 703 | if (!qpti->sreg) { |
704 | printk("PTI: Qlogic/ISP status register is unmappable\n"); | 704 | printk("PTI: Qlogic/ISP status register is unmappable\n"); |
705 | return -1; | 705 | return -1; |
706 | } | 706 | } |
707 | } | 707 | } |
708 | return 0; | 708 | return 0; |
709 | } | 709 | } |
710 | 710 | ||
711 | static int __init qpti_register_irq(struct qlogicpti *qpti) | 711 | static int __init qpti_register_irq(struct qlogicpti *qpti) |
712 | { | 712 | { |
713 | struct sbus_dev *sdev = qpti->sdev; | 713 | struct sbus_dev *sdev = qpti->sdev; |
714 | 714 | ||
715 | qpti->qhost->irq = qpti->irq = sdev->irqs[0]; | 715 | qpti->qhost->irq = qpti->irq = sdev->irqs[0]; |
716 | 716 | ||
717 | /* We used to try various overly-clever things to | 717 | /* We used to try various overly-clever things to |
718 | * reduce the interrupt processing overhead on | 718 | * reduce the interrupt processing overhead on |
719 | * sun4c/sun4m when multiple PTI's shared the | 719 | * sun4c/sun4m when multiple PTI's shared the |
720 | * same IRQ. It was too complex and messy to | 720 | * same IRQ. It was too complex and messy to |
721 | * sanely maintain. | 721 | * sanely maintain. |
722 | */ | 722 | */ |
723 | if (request_irq(qpti->irq, qpti_intr, | 723 | if (request_irq(qpti->irq, qpti_intr, |
724 | SA_SHIRQ, "Qlogic/PTI", qpti)) | 724 | SA_SHIRQ, "Qlogic/PTI", qpti)) |
725 | goto fail; | 725 | goto fail; |
726 | 726 | ||
727 | printk("qpti%d: IRQ %s ", qpti->qpti_id, __irq_itoa(qpti->irq)); | 727 | printk("qpti%d: IRQ %s ", qpti->qpti_id, __irq_itoa(qpti->irq)); |
728 | 728 | ||
729 | return 0; | 729 | return 0; |
730 | 730 | ||
731 | fail: | 731 | fail: |
732 | printk("qpti%d: Cannot acquire irq line\n", qpti->qpti_id); | 732 | printk("qpti%d: Cannot acquire irq line\n", qpti->qpti_id); |
733 | return -1; | 733 | return -1; |
734 | } | 734 | } |
735 | 735 | ||
736 | static void __init qpti_get_scsi_id(struct qlogicpti *qpti) | 736 | static void __init qpti_get_scsi_id(struct qlogicpti *qpti) |
737 | { | 737 | { |
738 | qpti->scsi_id = prom_getintdefault(qpti->prom_node, | 738 | qpti->scsi_id = prom_getintdefault(qpti->prom_node, |
739 | "initiator-id", | 739 | "initiator-id", |
740 | -1); | 740 | -1); |
741 | if (qpti->scsi_id == -1) | 741 | if (qpti->scsi_id == -1) |
742 | qpti->scsi_id = prom_getintdefault(qpti->prom_node, | 742 | qpti->scsi_id = prom_getintdefault(qpti->prom_node, |
743 | "scsi-initiator-id", | 743 | "scsi-initiator-id", |
744 | -1); | 744 | -1); |
745 | if (qpti->scsi_id == -1) | 745 | if (qpti->scsi_id == -1) |
746 | qpti->scsi_id = | 746 | qpti->scsi_id = |
747 | prom_getintdefault(qpti->sdev->bus->prom_node, | 747 | prom_getintdefault(qpti->sdev->bus->prom_node, |
748 | "scsi-initiator-id", 7); | 748 | "scsi-initiator-id", 7); |
749 | qpti->qhost->this_id = qpti->scsi_id; | 749 | qpti->qhost->this_id = qpti->scsi_id; |
750 | qpti->qhost->max_sectors = 64; | 750 | qpti->qhost->max_sectors = 64; |
751 | 751 | ||
752 | printk("SCSI ID %d ", qpti->scsi_id); | 752 | printk("SCSI ID %d ", qpti->scsi_id); |
753 | } | 753 | } |
754 | 754 | ||
755 | static void qpti_get_bursts(struct qlogicpti *qpti) | 755 | static void qpti_get_bursts(struct qlogicpti *qpti) |
756 | { | 756 | { |
757 | struct sbus_dev *sdev = qpti->sdev; | 757 | struct sbus_dev *sdev = qpti->sdev; |
758 | u8 bursts, bmask; | 758 | u8 bursts, bmask; |
759 | 759 | ||
760 | bursts = prom_getintdefault(qpti->prom_node, "burst-sizes", 0xff); | 760 | bursts = prom_getintdefault(qpti->prom_node, "burst-sizes", 0xff); |
761 | bmask = prom_getintdefault(sdev->bus->prom_node, | 761 | bmask = prom_getintdefault(sdev->bus->prom_node, |
762 | "burst-sizes", 0xff); | 762 | "burst-sizes", 0xff); |
763 | if (bmask != 0xff) | 763 | if (bmask != 0xff) |
764 | bursts &= bmask; | 764 | bursts &= bmask; |
765 | if (bursts == 0xff || | 765 | if (bursts == 0xff || |
766 | (bursts & DMA_BURST16) == 0 || | 766 | (bursts & DMA_BURST16) == 0 || |
767 | (bursts & DMA_BURST32) == 0) | 767 | (bursts & DMA_BURST32) == 0) |
768 | bursts = (DMA_BURST32 - 1); | 768 | bursts = (DMA_BURST32 - 1); |
769 | 769 | ||
770 | qpti->bursts = bursts; | 770 | qpti->bursts = bursts; |
771 | } | 771 | } |
772 | 772 | ||
773 | static void qpti_get_clock(struct qlogicpti *qpti) | 773 | static void qpti_get_clock(struct qlogicpti *qpti) |
774 | { | 774 | { |
775 | unsigned int cfreq; | 775 | unsigned int cfreq; |
776 | 776 | ||
777 | /* Check for what the clock input to this card is. | 777 | /* Check for what the clock input to this card is. |
778 | * Default to 40Mhz. | 778 | * Default to 40Mhz. |
779 | */ | 779 | */ |
780 | cfreq = prom_getintdefault(qpti->prom_node,"clock-frequency",40000000); | 780 | cfreq = prom_getintdefault(qpti->prom_node,"clock-frequency",40000000); |
781 | qpti->clock = (cfreq + 500000)/1000000; | 781 | qpti->clock = (cfreq + 500000)/1000000; |
782 | if (qpti->clock == 0) /* bullshit */ | 782 | if (qpti->clock == 0) /* bullshit */ |
783 | qpti->clock = 40; | 783 | qpti->clock = 40; |
784 | } | 784 | } |
785 | 785 | ||
786 | /* The request and response queues must each be aligned | 786 | /* The request and response queues must each be aligned |
787 | * on a page boundary. | 787 | * on a page boundary. |
788 | */ | 788 | */ |
789 | static int __init qpti_map_queues(struct qlogicpti *qpti) | 789 | static int __init qpti_map_queues(struct qlogicpti *qpti) |
790 | { | 790 | { |
791 | struct sbus_dev *sdev = qpti->sdev; | 791 | struct sbus_dev *sdev = qpti->sdev; |
792 | 792 | ||
793 | #define QSIZE(entries) (((entries) + 1) * QUEUE_ENTRY_LEN) | 793 | #define QSIZE(entries) (((entries) + 1) * QUEUE_ENTRY_LEN) |
794 | qpti->res_cpu = sbus_alloc_consistent(sdev, | 794 | qpti->res_cpu = sbus_alloc_consistent(sdev, |
795 | QSIZE(RES_QUEUE_LEN), | 795 | QSIZE(RES_QUEUE_LEN), |
796 | &qpti->res_dvma); | 796 | &qpti->res_dvma); |
797 | if (qpti->res_cpu == NULL || | 797 | if (qpti->res_cpu == NULL || |
798 | qpti->res_dvma == 0) { | 798 | qpti->res_dvma == 0) { |
799 | printk("QPTI: Cannot map response queue.\n"); | 799 | printk("QPTI: Cannot map response queue.\n"); |
800 | return -1; | 800 | return -1; |
801 | } | 801 | } |
802 | 802 | ||
803 | qpti->req_cpu = sbus_alloc_consistent(sdev, | 803 | qpti->req_cpu = sbus_alloc_consistent(sdev, |
804 | QSIZE(QLOGICPTI_REQ_QUEUE_LEN), | 804 | QSIZE(QLOGICPTI_REQ_QUEUE_LEN), |
805 | &qpti->req_dvma); | 805 | &qpti->req_dvma); |
806 | if (qpti->req_cpu == NULL || | 806 | if (qpti->req_cpu == NULL || |
807 | qpti->req_dvma == 0) { | 807 | qpti->req_dvma == 0) { |
808 | sbus_free_consistent(sdev, QSIZE(RES_QUEUE_LEN), | 808 | sbus_free_consistent(sdev, QSIZE(RES_QUEUE_LEN), |
809 | qpti->res_cpu, qpti->res_dvma); | 809 | qpti->res_cpu, qpti->res_dvma); |
810 | printk("QPTI: Cannot map request queue.\n"); | 810 | printk("QPTI: Cannot map request queue.\n"); |
811 | return -1; | 811 | return -1; |
812 | } | 812 | } |
813 | memset(qpti->res_cpu, 0, QSIZE(RES_QUEUE_LEN)); | 813 | memset(qpti->res_cpu, 0, QSIZE(RES_QUEUE_LEN)); |
814 | memset(qpti->req_cpu, 0, QSIZE(QLOGICPTI_REQ_QUEUE_LEN)); | 814 | memset(qpti->req_cpu, 0, QSIZE(QLOGICPTI_REQ_QUEUE_LEN)); |
815 | return 0; | 815 | return 0; |
816 | } | 816 | } |
817 | 817 | ||
818 | /* Detect all PTI Qlogic ISP's in the machine. */ | 818 | /* Detect all PTI Qlogic ISP's in the machine. */ |
819 | static int __init qlogicpti_detect(struct scsi_host_template *tpnt) | 819 | static int __init qlogicpti_detect(struct scsi_host_template *tpnt) |
820 | { | 820 | { |
821 | struct qlogicpti *qpti; | 821 | struct qlogicpti *qpti; |
822 | struct Scsi_Host *qpti_host; | 822 | struct Scsi_Host *qpti_host; |
823 | struct sbus_bus *sbus; | 823 | struct sbus_bus *sbus; |
824 | struct sbus_dev *sdev; | 824 | struct sbus_dev *sdev; |
825 | int nqptis = 0, nqptis_in_use = 0; | 825 | int nqptis = 0, nqptis_in_use = 0; |
826 | 826 | ||
827 | tpnt->proc_name = "qlogicpti"; | 827 | tpnt->proc_name = "qlogicpti"; |
828 | for_each_sbus(sbus) { | 828 | for_each_sbus(sbus) { |
829 | for_each_sbusdev(sdev, sbus) { | 829 | for_each_sbusdev(sdev, sbus) { |
830 | /* Is this a red snapper? */ | 830 | /* Is this a red snapper? */ |
831 | if (strcmp(sdev->prom_name, "ptisp") && | 831 | if (strcmp(sdev->prom_name, "ptisp") && |
832 | strcmp(sdev->prom_name, "PTI,ptisp") && | 832 | strcmp(sdev->prom_name, "PTI,ptisp") && |
833 | strcmp(sdev->prom_name, "QLGC,isp") && | 833 | strcmp(sdev->prom_name, "QLGC,isp") && |
834 | strcmp(sdev->prom_name, "SUNW,isp")) | 834 | strcmp(sdev->prom_name, "SUNW,isp")) |
835 | continue; | 835 | continue; |
836 | 836 | ||
837 | /* Sometimes Antares cards come up not completely | 837 | /* Sometimes Antares cards come up not completely |
838 | * setup, and we get a report of a zero IRQ. | 838 | * setup, and we get a report of a zero IRQ. |
839 | * Skip over them in such cases so we survive. | 839 | * Skip over them in such cases so we survive. |
840 | */ | 840 | */ |
841 | if (sdev->irqs[0] == 0) { | 841 | if (sdev->irqs[0] == 0) { |
842 | printk("qpti%d: Adapter reports no interrupt, " | 842 | printk("qpti%d: Adapter reports no interrupt, " |
843 | "skipping over this card.", nqptis); | 843 | "skipping over this card.", nqptis); |
844 | continue; | 844 | continue; |
845 | } | 845 | } |
846 | 846 | ||
847 | /* Yep, register and allocate software state. */ | 847 | /* Yep, register and allocate software state. */ |
848 | qpti_host = scsi_register(tpnt, sizeof(struct qlogicpti)); | 848 | qpti_host = scsi_register(tpnt, sizeof(struct qlogicpti)); |
849 | if (!qpti_host) { | 849 | if (!qpti_host) { |
850 | printk("QPTI: Cannot register PTI Qlogic ISP SCSI host"); | 850 | printk("QPTI: Cannot register PTI Qlogic ISP SCSI host"); |
851 | continue; | 851 | continue; |
852 | } | 852 | } |
853 | qpti = (struct qlogicpti *) qpti_host->hostdata; | 853 | qpti = (struct qlogicpti *) qpti_host->hostdata; |
854 | 854 | ||
855 | /* We are wide capable, 16 targets. */ | 855 | /* We are wide capable, 16 targets. */ |
856 | qpti_host->max_id = MAX_TARGETS; | 856 | qpti_host->max_id = MAX_TARGETS; |
857 | 857 | ||
858 | /* Setup back pointers and misc. state. */ | 858 | /* Setup back pointers and misc. state. */ |
859 | qpti->qhost = qpti_host; | 859 | qpti->qhost = qpti_host; |
860 | qpti->sdev = sdev; | 860 | qpti->sdev = sdev; |
861 | qpti->qpti_id = nqptis++; | 861 | qpti->qpti_id = nqptis++; |
862 | qpti->prom_node = sdev->prom_node; | 862 | qpti->prom_node = sdev->prom_node; |
863 | prom_getstring(qpti->prom_node, "name", | 863 | prom_getstring(qpti->prom_node, "name", |
864 | qpti->prom_name, | 864 | qpti->prom_name, |
865 | sizeof(qpti->prom_name)); | 865 | sizeof(qpti->prom_name)); |
866 | 866 | ||
867 | /* This is not correct, actually. There's a switch | 867 | /* This is not correct, actually. There's a switch |
868 | * on the PTI cards that put them into "emulation" | 868 | * on the PTI cards that put them into "emulation" |
869 | * mode- i.e., report themselves as QLGC,isp | 869 | * mode- i.e., report themselves as QLGC,isp |
870 | * instead of PTI,ptisp. The only real substantive | 870 | * instead of PTI,ptisp. The only real substantive |
871 | * difference between non-pti and pti cards is | 871 | * difference between non-pti and pti cards is |
872 | * the tmon register. Which is possibly even | 872 | * the tmon register. Which is possibly even |
873 | * there for Qlogic cards, but non-functional. | 873 | * there for Qlogic cards, but non-functional. |
874 | */ | 874 | */ |
875 | qpti->is_pti = (strcmp (qpti->prom_name, "QLGC,isp") != 0); | 875 | qpti->is_pti = (strcmp (qpti->prom_name, "QLGC,isp") != 0); |
876 | 876 | ||
877 | qpti_chain_add(qpti); | 877 | qpti_chain_add(qpti); |
878 | if (qpti_map_regs(qpti) < 0) | 878 | if (qpti_map_regs(qpti) < 0) |
879 | goto fail_unlink; | 879 | goto fail_unlink; |
880 | 880 | ||
881 | if (qpti_register_irq(qpti) < 0) | 881 | if (qpti_register_irq(qpti) < 0) |
882 | goto fail_unmap_regs; | 882 | goto fail_unmap_regs; |
883 | 883 | ||
884 | qpti_get_scsi_id(qpti); | 884 | qpti_get_scsi_id(qpti); |
885 | qpti_get_bursts(qpti); | 885 | qpti_get_bursts(qpti); |
886 | qpti_get_clock(qpti); | 886 | qpti_get_clock(qpti); |
887 | 887 | ||
888 | /* Clear out scsi_cmnd array. */ | 888 | /* Clear out scsi_cmnd array. */ |
889 | memset(qpti->cmd_slots, 0, sizeof(qpti->cmd_slots)); | 889 | memset(qpti->cmd_slots, 0, sizeof(qpti->cmd_slots)); |
890 | 890 | ||
891 | if (qpti_map_queues(qpti) < 0) | 891 | if (qpti_map_queues(qpti) < 0) |
892 | goto fail_free_irq; | 892 | goto fail_free_irq; |
893 | 893 | ||
894 | /* Load the firmware. */ | 894 | /* Load the firmware. */ |
895 | if (qlogicpti_load_firmware(qpti)) | 895 | if (qlogicpti_load_firmware(qpti)) |
896 | goto fail_unmap_queues; | 896 | goto fail_unmap_queues; |
897 | if (qpti->is_pti) { | 897 | if (qpti->is_pti) { |
898 | /* Check the PTI status reg. */ | 898 | /* Check the PTI status reg. */ |
899 | if (qlogicpti_verify_tmon(qpti)) | 899 | if (qlogicpti_verify_tmon(qpti)) |
900 | goto fail_unmap_queues; | 900 | goto fail_unmap_queues; |
901 | } | 901 | } |
902 | 902 | ||
903 | /* Reset the ISP and init res/req queues. */ | 903 | /* Reset the ISP and init res/req queues. */ |
904 | if (qlogicpti_reset_hardware(qpti_host)) | 904 | if (qlogicpti_reset_hardware(qpti_host)) |
905 | goto fail_unmap_queues; | 905 | goto fail_unmap_queues; |
906 | 906 | ||
907 | printk("(Firmware v%d.%d.%d)", qpti->fware_majrev, | 907 | printk("(Firmware v%d.%d.%d)", qpti->fware_majrev, |
908 | qpti->fware_minrev, qpti->fware_micrev); | 908 | qpti->fware_minrev, qpti->fware_micrev); |
909 | { | 909 | { |
910 | char buffer[60]; | 910 | char buffer[60]; |
911 | 911 | ||
912 | prom_getstring (qpti->prom_node, | 912 | prom_getstring (qpti->prom_node, |
913 | "isp-fcode", buffer, 60); | 913 | "isp-fcode", buffer, 60); |
914 | if (buffer[0]) | 914 | if (buffer[0]) |
915 | printk("(Firmware %s)", buffer); | 915 | printk("(Firmware %s)", buffer); |
916 | if (prom_getbool(qpti->prom_node, "differential")) | 916 | if (prom_getbool(qpti->prom_node, "differential")) |
917 | qpti->differential = 1; | 917 | qpti->differential = 1; |
918 | } | 918 | } |
919 | 919 | ||
920 | printk (" [%s Wide, using %s interface]\n", | 920 | printk (" [%s Wide, using %s interface]\n", |
921 | (qpti->ultra ? "Ultra" : "Fast"), | 921 | (qpti->ultra ? "Ultra" : "Fast"), |
922 | (qpti->differential ? "differential" : "single ended")); | 922 | (qpti->differential ? "differential" : "single ended")); |
923 | 923 | ||
924 | nqptis_in_use++; | 924 | nqptis_in_use++; |
925 | continue; | 925 | continue; |
926 | 926 | ||
927 | fail_unmap_queues: | 927 | fail_unmap_queues: |
928 | #define QSIZE(entries) (((entries) + 1) * QUEUE_ENTRY_LEN) | 928 | #define QSIZE(entries) (((entries) + 1) * QUEUE_ENTRY_LEN) |
929 | sbus_free_consistent(qpti->sdev, | 929 | sbus_free_consistent(qpti->sdev, |
930 | QSIZE(RES_QUEUE_LEN), | 930 | QSIZE(RES_QUEUE_LEN), |
931 | qpti->res_cpu, qpti->res_dvma); | 931 | qpti->res_cpu, qpti->res_dvma); |
932 | sbus_free_consistent(qpti->sdev, | 932 | sbus_free_consistent(qpti->sdev, |
933 | QSIZE(QLOGICPTI_REQ_QUEUE_LEN), | 933 | QSIZE(QLOGICPTI_REQ_QUEUE_LEN), |
934 | qpti->req_cpu, qpti->req_dvma); | 934 | qpti->req_cpu, qpti->req_dvma); |
935 | #undef QSIZE | 935 | #undef QSIZE |
936 | fail_free_irq: | 936 | fail_free_irq: |
937 | free_irq(qpti->irq, qpti); | 937 | free_irq(qpti->irq, qpti); |
938 | 938 | ||
939 | fail_unmap_regs: | 939 | fail_unmap_regs: |
940 | sbus_iounmap(qpti->qregs, | 940 | sbus_iounmap(qpti->qregs, |
941 | qpti->sdev->reg_addrs[0].reg_size); | 941 | qpti->sdev->reg_addrs[0].reg_size); |
942 | if (qpti->is_pti) | 942 | if (qpti->is_pti) |
943 | sbus_iounmap(qpti->sreg, sizeof(unsigned char)); | 943 | sbus_iounmap(qpti->sreg, sizeof(unsigned char)); |
944 | fail_unlink: | 944 | fail_unlink: |
945 | qpti_chain_del(qpti); | 945 | qpti_chain_del(qpti); |
946 | scsi_unregister(qpti->qhost); | 946 | scsi_unregister(qpti->qhost); |
947 | } | 947 | } |
948 | } | 948 | } |
949 | if (nqptis) | 949 | if (nqptis) |
950 | printk("QPTI: Total of %d PTI Qlogic/ISP hosts found, %d actually in use.\n", | 950 | printk("QPTI: Total of %d PTI Qlogic/ISP hosts found, %d actually in use.\n", |
951 | nqptis, nqptis_in_use); | 951 | nqptis, nqptis_in_use); |
952 | qptis_running = nqptis_in_use; | 952 | qptis_running = nqptis_in_use; |
953 | return nqptis; | 953 | return nqptis; |
954 | } | 954 | } |
955 | 955 | ||
956 | static int qlogicpti_release(struct Scsi_Host *host) | 956 | static int qlogicpti_release(struct Scsi_Host *host) |
957 | { | 957 | { |
958 | struct qlogicpti *qpti = (struct qlogicpti *) host->hostdata; | 958 | struct qlogicpti *qpti = (struct qlogicpti *) host->hostdata; |
959 | 959 | ||
960 | /* Remove visibility from IRQ handlers. */ | 960 | /* Remove visibility from IRQ handlers. */ |
961 | qpti_chain_del(qpti); | 961 | qpti_chain_del(qpti); |
962 | 962 | ||
963 | /* Shut up the card. */ | 963 | /* Shut up the card. */ |
964 | sbus_writew(0, qpti->qregs + SBUS_CTRL); | 964 | sbus_writew(0, qpti->qregs + SBUS_CTRL); |
965 | 965 | ||
966 | /* Free IRQ handler and unmap Qlogic,ISP and PTI status regs. */ | 966 | /* Free IRQ handler and unmap Qlogic,ISP and PTI status regs. */ |
967 | free_irq(qpti->irq, qpti); | 967 | free_irq(qpti->irq, qpti); |
968 | 968 | ||
969 | #define QSIZE(entries) (((entries) + 1) * QUEUE_ENTRY_LEN) | 969 | #define QSIZE(entries) (((entries) + 1) * QUEUE_ENTRY_LEN) |
970 | sbus_free_consistent(qpti->sdev, | 970 | sbus_free_consistent(qpti->sdev, |
971 | QSIZE(RES_QUEUE_LEN), | 971 | QSIZE(RES_QUEUE_LEN), |
972 | qpti->res_cpu, qpti->res_dvma); | 972 | qpti->res_cpu, qpti->res_dvma); |
973 | sbus_free_consistent(qpti->sdev, | 973 | sbus_free_consistent(qpti->sdev, |
974 | QSIZE(QLOGICPTI_REQ_QUEUE_LEN), | 974 | QSIZE(QLOGICPTI_REQ_QUEUE_LEN), |
975 | qpti->req_cpu, qpti->req_dvma); | 975 | qpti->req_cpu, qpti->req_dvma); |
976 | #undef QSIZE | 976 | #undef QSIZE |
977 | 977 | ||
978 | sbus_iounmap(qpti->qregs, qpti->sdev->reg_addrs[0].reg_size); | 978 | sbus_iounmap(qpti->qregs, qpti->sdev->reg_addrs[0].reg_size); |
979 | if (qpti->is_pti) | 979 | if (qpti->is_pti) |
980 | sbus_iounmap(qpti->sreg, sizeof(unsigned char)); | 980 | sbus_iounmap(qpti->sreg, sizeof(unsigned char)); |
981 | 981 | ||
982 | return 0; | 982 | return 0; |
983 | } | 983 | } |
984 | 984 | ||
985 | const char *qlogicpti_info(struct Scsi_Host *host) | 985 | const char *qlogicpti_info(struct Scsi_Host *host) |
986 | { | 986 | { |
987 | static char buf[80]; | 987 | static char buf[80]; |
988 | struct qlogicpti *qpti = (struct qlogicpti *) host->hostdata; | 988 | struct qlogicpti *qpti = (struct qlogicpti *) host->hostdata; |
989 | 989 | ||
990 | sprintf(buf, "PTI Qlogic,ISP SBUS SCSI irq %s regs at %p", | 990 | sprintf(buf, "PTI Qlogic,ISP SBUS SCSI irq %s regs at %p", |
991 | __irq_itoa(qpti->qhost->irq), qpti->qregs); | 991 | __irq_itoa(qpti->qhost->irq), qpti->qregs); |
992 | return buf; | 992 | return buf; |
993 | } | 993 | } |
994 | 994 | ||
995 | /* I am a certified frobtronicist. */ | 995 | /* I am a certified frobtronicist. */ |
996 | static inline void marker_frob(struct Command_Entry *cmd) | 996 | static inline void marker_frob(struct Command_Entry *cmd) |
997 | { | 997 | { |
998 | struct Marker_Entry *marker = (struct Marker_Entry *) cmd; | 998 | struct Marker_Entry *marker = (struct Marker_Entry *) cmd; |
999 | 999 | ||
1000 | memset(marker, 0, sizeof(struct Marker_Entry)); | 1000 | memset(marker, 0, sizeof(struct Marker_Entry)); |
1001 | marker->hdr.entry_cnt = 1; | 1001 | marker->hdr.entry_cnt = 1; |
1002 | marker->hdr.entry_type = ENTRY_MARKER; | 1002 | marker->hdr.entry_type = ENTRY_MARKER; |
1003 | marker->modifier = SYNC_ALL; | 1003 | marker->modifier = SYNC_ALL; |
1004 | marker->rsvd = 0; | 1004 | marker->rsvd = 0; |
1005 | } | 1005 | } |
1006 | 1006 | ||
1007 | static inline void cmd_frob(struct Command_Entry *cmd, struct scsi_cmnd *Cmnd, | 1007 | static inline void cmd_frob(struct Command_Entry *cmd, struct scsi_cmnd *Cmnd, |
1008 | struct qlogicpti *qpti) | 1008 | struct qlogicpti *qpti) |
1009 | { | 1009 | { |
1010 | memset(cmd, 0, sizeof(struct Command_Entry)); | 1010 | memset(cmd, 0, sizeof(struct Command_Entry)); |
1011 | cmd->hdr.entry_cnt = 1; | 1011 | cmd->hdr.entry_cnt = 1; |
1012 | cmd->hdr.entry_type = ENTRY_COMMAND; | 1012 | cmd->hdr.entry_type = ENTRY_COMMAND; |
1013 | cmd->target_id = Cmnd->device->id; | 1013 | cmd->target_id = Cmnd->device->id; |
1014 | cmd->target_lun = Cmnd->device->lun; | 1014 | cmd->target_lun = Cmnd->device->lun; |
1015 | cmd->cdb_length = Cmnd->cmd_len; | 1015 | cmd->cdb_length = Cmnd->cmd_len; |
1016 | cmd->control_flags = 0; | 1016 | cmd->control_flags = 0; |
1017 | if (Cmnd->device->tagged_supported) { | 1017 | if (Cmnd->device->tagged_supported) { |
1018 | if (qpti->cmd_count[Cmnd->device->id] == 0) | 1018 | if (qpti->cmd_count[Cmnd->device->id] == 0) |
1019 | qpti->tag_ages[Cmnd->device->id] = jiffies; | 1019 | qpti->tag_ages[Cmnd->device->id] = jiffies; |
1020 | if ((jiffies - qpti->tag_ages[Cmnd->device->id]) > (5*HZ)) { | 1020 | if ((jiffies - qpti->tag_ages[Cmnd->device->id]) > (5*HZ)) { |
1021 | cmd->control_flags = CFLAG_ORDERED_TAG; | 1021 | cmd->control_flags = CFLAG_ORDERED_TAG; |
1022 | qpti->tag_ages[Cmnd->device->id] = jiffies; | 1022 | qpti->tag_ages[Cmnd->device->id] = jiffies; |
1023 | } else | 1023 | } else |
1024 | cmd->control_flags = CFLAG_SIMPLE_TAG; | 1024 | cmd->control_flags = CFLAG_SIMPLE_TAG; |
1025 | } | 1025 | } |
1026 | if ((Cmnd->cmnd[0] == WRITE_6) || | 1026 | if ((Cmnd->cmnd[0] == WRITE_6) || |
1027 | (Cmnd->cmnd[0] == WRITE_10) || | 1027 | (Cmnd->cmnd[0] == WRITE_10) || |
1028 | (Cmnd->cmnd[0] == WRITE_12)) | 1028 | (Cmnd->cmnd[0] == WRITE_12)) |
1029 | cmd->control_flags |= CFLAG_WRITE; | 1029 | cmd->control_flags |= CFLAG_WRITE; |
1030 | else | 1030 | else |
1031 | cmd->control_flags |= CFLAG_READ; | 1031 | cmd->control_flags |= CFLAG_READ; |
1032 | cmd->time_out = 30; | 1032 | cmd->time_out = 30; |
1033 | memcpy(cmd->cdb, Cmnd->cmnd, Cmnd->cmd_len); | 1033 | memcpy(cmd->cdb, Cmnd->cmnd, Cmnd->cmd_len); |
1034 | } | 1034 | } |
1035 | 1035 | ||
1036 | /* Do it to it baby. */ | 1036 | /* Do it to it baby. */ |
1037 | static inline int load_cmd(struct scsi_cmnd *Cmnd, struct Command_Entry *cmd, | 1037 | static inline int load_cmd(struct scsi_cmnd *Cmnd, struct Command_Entry *cmd, |
1038 | struct qlogicpti *qpti, u_int in_ptr, u_int out_ptr) | 1038 | struct qlogicpti *qpti, u_int in_ptr, u_int out_ptr) |
1039 | { | 1039 | { |
1040 | struct dataseg *ds; | 1040 | struct dataseg *ds; |
1041 | struct scatterlist *sg; | 1041 | struct scatterlist *sg; |
1042 | int i, n; | 1042 | int i, n; |
1043 | 1043 | ||
1044 | if (Cmnd->use_sg) { | 1044 | if (Cmnd->use_sg) { |
1045 | int sg_count; | 1045 | int sg_count; |
1046 | 1046 | ||
1047 | sg = (struct scatterlist *) Cmnd->buffer; | 1047 | sg = (struct scatterlist *) Cmnd->buffer; |
1048 | sg_count = sbus_map_sg(qpti->sdev, sg, Cmnd->use_sg, Cmnd->sc_data_direction); | 1048 | sg_count = sbus_map_sg(qpti->sdev, sg, Cmnd->use_sg, Cmnd->sc_data_direction); |
1049 | 1049 | ||
1050 | ds = cmd->dataseg; | 1050 | ds = cmd->dataseg; |
1051 | cmd->segment_cnt = sg_count; | 1051 | cmd->segment_cnt = sg_count; |
1052 | 1052 | ||
1053 | /* Fill in first four sg entries: */ | 1053 | /* Fill in first four sg entries: */ |
1054 | n = sg_count; | 1054 | n = sg_count; |
1055 | if (n > 4) | 1055 | if (n > 4) |
1056 | n = 4; | 1056 | n = 4; |
1057 | for (i = 0; i < n; i++, sg++) { | 1057 | for (i = 0; i < n; i++, sg++) { |
1058 | ds[i].d_base = sg_dma_address(sg); | 1058 | ds[i].d_base = sg_dma_address(sg); |
1059 | ds[i].d_count = sg_dma_len(sg); | 1059 | ds[i].d_count = sg_dma_len(sg); |
1060 | } | 1060 | } |
1061 | sg_count -= 4; | 1061 | sg_count -= 4; |
1062 | while (sg_count > 0) { | 1062 | while (sg_count > 0) { |
1063 | struct Continuation_Entry *cont; | 1063 | struct Continuation_Entry *cont; |
1064 | 1064 | ||
1065 | ++cmd->hdr.entry_cnt; | 1065 | ++cmd->hdr.entry_cnt; |
1066 | cont = (struct Continuation_Entry *) &qpti->req_cpu[in_ptr]; | 1066 | cont = (struct Continuation_Entry *) &qpti->req_cpu[in_ptr]; |
1067 | in_ptr = NEXT_REQ_PTR(in_ptr); | 1067 | in_ptr = NEXT_REQ_PTR(in_ptr); |
1068 | if (in_ptr == out_ptr) | 1068 | if (in_ptr == out_ptr) |
1069 | return -1; | 1069 | return -1; |
1070 | 1070 | ||
1071 | cont->hdr.entry_type = ENTRY_CONTINUATION; | 1071 | cont->hdr.entry_type = ENTRY_CONTINUATION; |
1072 | cont->hdr.entry_cnt = 0; | 1072 | cont->hdr.entry_cnt = 0; |
1073 | cont->hdr.sys_def_1 = 0; | 1073 | cont->hdr.sys_def_1 = 0; |
1074 | cont->hdr.flags = 0; | 1074 | cont->hdr.flags = 0; |
1075 | cont->reserved = 0; | 1075 | cont->reserved = 0; |
1076 | ds = cont->dataseg; | 1076 | ds = cont->dataseg; |
1077 | n = sg_count; | 1077 | n = sg_count; |
1078 | if (n > 7) | 1078 | if (n > 7) |
1079 | n = 7; | 1079 | n = 7; |
1080 | for (i = 0; i < n; i++, sg++) { | 1080 | for (i = 0; i < n; i++, sg++) { |
1081 | ds[i].d_base = sg_dma_address(sg); | 1081 | ds[i].d_base = sg_dma_address(sg); |
1082 | ds[i].d_count = sg_dma_len(sg); | 1082 | ds[i].d_count = sg_dma_len(sg); |
1083 | } | 1083 | } |
1084 | sg_count -= n; | 1084 | sg_count -= n; |
1085 | } | 1085 | } |
1086 | } else if (Cmnd->request_bufflen) { | 1086 | } else if (Cmnd->request_bufflen) { |
1087 | Cmnd->SCp.ptr = (char *)(unsigned long) | 1087 | Cmnd->SCp.ptr = (char *)(unsigned long) |
1088 | sbus_map_single(qpti->sdev, | 1088 | sbus_map_single(qpti->sdev, |
1089 | Cmnd->request_buffer, | 1089 | Cmnd->request_buffer, |
1090 | Cmnd->request_bufflen, | 1090 | Cmnd->request_bufflen, |
1091 | Cmnd->sc_data_direction); | 1091 | Cmnd->sc_data_direction); |
1092 | 1092 | ||
1093 | cmd->dataseg[0].d_base = (u32) ((unsigned long)Cmnd->SCp.ptr); | 1093 | cmd->dataseg[0].d_base = (u32) ((unsigned long)Cmnd->SCp.ptr); |
1094 | cmd->dataseg[0].d_count = Cmnd->request_bufflen; | 1094 | cmd->dataseg[0].d_count = Cmnd->request_bufflen; |
1095 | cmd->segment_cnt = 1; | 1095 | cmd->segment_cnt = 1; |
1096 | } else { | 1096 | } else { |
1097 | cmd->dataseg[0].d_base = 0; | 1097 | cmd->dataseg[0].d_base = 0; |
1098 | cmd->dataseg[0].d_count = 0; | 1098 | cmd->dataseg[0].d_count = 0; |
1099 | cmd->segment_cnt = 1; /* Shouldn't this be 0? */ | 1099 | cmd->segment_cnt = 1; /* Shouldn't this be 0? */ |
1100 | } | 1100 | } |
1101 | 1101 | ||
1102 | /* Committed, record Scsi_Cmd so we can find it later. */ | 1102 | /* Committed, record Scsi_Cmd so we can find it later. */ |
1103 | cmd->handle = in_ptr; | 1103 | cmd->handle = in_ptr; |
1104 | qpti->cmd_slots[in_ptr] = Cmnd; | 1104 | qpti->cmd_slots[in_ptr] = Cmnd; |
1105 | 1105 | ||
1106 | qpti->cmd_count[Cmnd->device->id]++; | 1106 | qpti->cmd_count[Cmnd->device->id]++; |
1107 | sbus_writew(in_ptr, qpti->qregs + MBOX4); | 1107 | sbus_writew(in_ptr, qpti->qregs + MBOX4); |
1108 | qpti->req_in_ptr = in_ptr; | 1108 | qpti->req_in_ptr = in_ptr; |
1109 | 1109 | ||
1110 | return in_ptr; | 1110 | return in_ptr; |
1111 | } | 1111 | } |
1112 | 1112 | ||
1113 | static inline void update_can_queue(struct Scsi_Host *host, u_int in_ptr, u_int out_ptr) | 1113 | static inline void update_can_queue(struct Scsi_Host *host, u_int in_ptr, u_int out_ptr) |
1114 | { | 1114 | { |
1115 | /* Temporary workaround until bug is found and fixed (one bug has been found | 1115 | /* Temporary workaround until bug is found and fixed (one bug has been found |
1116 | already, but fixing it makes things even worse) -jj */ | 1116 | already, but fixing it makes things even worse) -jj */ |
1117 | int num_free = QLOGICPTI_REQ_QUEUE_LEN - REQ_QUEUE_DEPTH(in_ptr, out_ptr) - 64; | 1117 | int num_free = QLOGICPTI_REQ_QUEUE_LEN - REQ_QUEUE_DEPTH(in_ptr, out_ptr) - 64; |
1118 | host->can_queue = host->host_busy + num_free; | 1118 | host->can_queue = host->host_busy + num_free; |
1119 | host->sg_tablesize = QLOGICPTI_MAX_SG(num_free); | 1119 | host->sg_tablesize = QLOGICPTI_MAX_SG(num_free); |
1120 | } | 1120 | } |
1121 | 1121 | ||
1122 | static unsigned int scsi_rbuf_get(struct scsi_cmnd *cmd, unsigned char **buf_out) | ||
1123 | { | ||
1124 | unsigned char *buf; | ||
1125 | unsigned int buflen; | ||
1126 | |||
1127 | if (cmd->use_sg) { | ||
1128 | struct scatterlist *sg; | ||
1129 | |||
1130 | sg = (struct scatterlist *) cmd->request_buffer; | ||
1131 | buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset; | ||
1132 | buflen = sg->length; | ||
1133 | } else { | ||
1134 | buf = cmd->request_buffer; | ||
1135 | buflen = cmd->request_bufflen; | ||
1136 | } | ||
1137 | |||
1138 | *buf_out = buf; | ||
1139 | return buflen; | ||
1140 | } | ||
1141 | |||
1142 | static void scsi_rbuf_put(struct scsi_cmnd *cmd, unsigned char *buf) | ||
1143 | { | ||
1144 | if (cmd->use_sg) { | ||
1145 | struct scatterlist *sg; | ||
1146 | |||
1147 | sg = (struct scatterlist *) cmd->request_buffer; | ||
1148 | kunmap_atomic(buf - sg->offset, KM_IRQ0); | ||
1149 | } | ||
1150 | } | ||
1151 | |||
1122 | /* | 1152 | /* |
1123 | * Until we scan the entire bus with inquiries, go throught this fella... | 1153 | * Until we scan the entire bus with inquiries, go throught this fella... |
1124 | */ | 1154 | */ |
1125 | static void ourdone(struct scsi_cmnd *Cmnd) | 1155 | static void ourdone(struct scsi_cmnd *Cmnd) |
1126 | { | 1156 | { |
1127 | struct qlogicpti *qpti = (struct qlogicpti *) Cmnd->device->host->hostdata; | 1157 | struct qlogicpti *qpti = (struct qlogicpti *) Cmnd->device->host->hostdata; |
1128 | int tgt = Cmnd->device->id; | 1158 | int tgt = Cmnd->device->id; |
1129 | void (*done) (struct scsi_cmnd *); | 1159 | void (*done) (struct scsi_cmnd *); |
1130 | 1160 | ||
1131 | /* This grot added by DaveM, blame him for ugliness. | 1161 | /* This grot added by DaveM, blame him for ugliness. |
1132 | * The issue is that in the 2.3.x driver we use the | 1162 | * The issue is that in the 2.3.x driver we use the |
1133 | * host_scribble portion of the scsi command as a | 1163 | * host_scribble portion of the scsi command as a |
1134 | * completion linked list at interrupt service time, | 1164 | * completion linked list at interrupt service time, |
1135 | * so we have to store the done function pointer elsewhere. | 1165 | * so we have to store the done function pointer elsewhere. |
1136 | */ | 1166 | */ |
1137 | done = (void (*)(struct scsi_cmnd *)) | 1167 | done = (void (*)(struct scsi_cmnd *)) |
1138 | (((unsigned long) Cmnd->SCp.Message) | 1168 | (((unsigned long) Cmnd->SCp.Message) |
1139 | #ifdef __sparc_v9__ | 1169 | #ifdef __sparc_v9__ |
1140 | | ((unsigned long) Cmnd->SCp.Status << 32UL) | 1170 | | ((unsigned long) Cmnd->SCp.Status << 32UL) |
1141 | #endif | 1171 | #endif |
1142 | ); | 1172 | ); |
1143 | 1173 | ||
1144 | if ((qpti->sbits & (1 << tgt)) == 0) { | 1174 | if ((qpti->sbits & (1 << tgt)) == 0) { |
1145 | int ok = host_byte(Cmnd->result) == DID_OK; | 1175 | int ok = host_byte(Cmnd->result) == DID_OK; |
1146 | if (Cmnd->cmnd[0] == 0x12 && ok) { | 1176 | if (Cmnd->cmnd[0] == 0x12 && ok) { |
1147 | unsigned char *iqd; | 1177 | unsigned char *iqd; |
1178 | unsigned int iqd_len; | ||
1148 | 1179 | ||
1149 | if (Cmnd->use_sg != 0) | 1180 | iqd_len = scsi_rbuf_get(Cmnd, &iqd); |
1150 | BUG(); | ||
1151 | 1181 | ||
1152 | iqd = ((unsigned char *)Cmnd->buffer); | ||
1153 | |||
1154 | /* tags handled in midlayer */ | 1182 | /* tags handled in midlayer */ |
1155 | /* enable sync mode? */ | 1183 | /* enable sync mode? */ |
1156 | if (iqd[7] & 0x10) { | 1184 | if (iqd[7] & 0x10) { |
1157 | qpti->dev_param[tgt].device_flags |= 0x10; | 1185 | qpti->dev_param[tgt].device_flags |= 0x10; |
1158 | } else { | 1186 | } else { |
1159 | qpti->dev_param[tgt].synchronous_offset = 0; | 1187 | qpti->dev_param[tgt].synchronous_offset = 0; |
1160 | qpti->dev_param[tgt].synchronous_period = 0; | 1188 | qpti->dev_param[tgt].synchronous_period = 0; |
1161 | } | 1189 | } |
1162 | /* are we wide capable? */ | 1190 | /* are we wide capable? */ |
1163 | if (iqd[7] & 0x20) { | 1191 | if (iqd[7] & 0x20) { |
1164 | qpti->dev_param[tgt].device_flags |= 0x20; | 1192 | qpti->dev_param[tgt].device_flags |= 0x20; |
1165 | } | 1193 | } |
1194 | |||
1195 | scsi_rbuf_put(Cmnd, iqd); | ||
1196 | |||
1166 | qpti->sbits |= (1 << tgt); | 1197 | qpti->sbits |= (1 << tgt); |
1167 | } else if (!ok) { | 1198 | } else if (!ok) { |
1168 | qpti->sbits |= (1 << tgt); | 1199 | qpti->sbits |= (1 << tgt); |
1169 | } | 1200 | } |
1170 | } | 1201 | } |
1171 | done(Cmnd); | 1202 | done(Cmnd); |
1172 | } | 1203 | } |
1173 | 1204 | ||
1174 | static int qlogicpti_queuecommand(struct scsi_cmnd *Cmnd, void (*done)(struct scsi_cmnd *)); | 1205 | static int qlogicpti_queuecommand(struct scsi_cmnd *Cmnd, void (*done)(struct scsi_cmnd *)); |
1175 | 1206 | ||
1176 | static int qlogicpti_queuecommand_slow(struct scsi_cmnd *Cmnd, | 1207 | static int qlogicpti_queuecommand_slow(struct scsi_cmnd *Cmnd, |
1177 | void (*done)(struct scsi_cmnd *)) | 1208 | void (*done)(struct scsi_cmnd *)) |
1178 | { | 1209 | { |
1179 | struct qlogicpti *qpti = (struct qlogicpti *) Cmnd->device->host->hostdata; | 1210 | struct qlogicpti *qpti = (struct qlogicpti *) Cmnd->device->host->hostdata; |
1180 | 1211 | ||
1181 | /* | 1212 | /* |
1182 | * done checking this host adapter? | 1213 | * done checking this host adapter? |
1183 | * If not, then rewrite the command | 1214 | * If not, then rewrite the command |
1184 | * to finish through ourdone so we | 1215 | * to finish through ourdone so we |
1185 | * can peek at Inquiry data results. | 1216 | * can peek at Inquiry data results. |
1186 | */ | 1217 | */ |
1187 | if (qpti->sbits && qpti->sbits != 0xffff) { | 1218 | if (qpti->sbits && qpti->sbits != 0xffff) { |
1188 | /* See above about in ourdone this ugliness... */ | 1219 | /* See above about in ourdone this ugliness... */ |
1189 | Cmnd->SCp.Message = ((unsigned long)done) & 0xffffffff; | 1220 | Cmnd->SCp.Message = ((unsigned long)done) & 0xffffffff; |
1190 | #ifdef CONFIG_SPARC64 | 1221 | #ifdef CONFIG_SPARC64 |
1191 | Cmnd->SCp.Status = ((unsigned long)done >> 32UL) & 0xffffffff; | 1222 | Cmnd->SCp.Status = ((unsigned long)done >> 32UL) & 0xffffffff; |
1192 | #endif | 1223 | #endif |
1193 | return qlogicpti_queuecommand(Cmnd, ourdone); | 1224 | return qlogicpti_queuecommand(Cmnd, ourdone); |
1194 | } | 1225 | } |
1195 | 1226 | ||
1196 | /* | 1227 | /* |
1197 | * We've peeked at all targets for this bus- time | 1228 | * We've peeked at all targets for this bus- time |
1198 | * to set parameters for devices for real now. | 1229 | * to set parameters for devices for real now. |
1199 | */ | 1230 | */ |
1200 | if (qpti->sbits == 0xffff) { | 1231 | if (qpti->sbits == 0xffff) { |
1201 | int i; | 1232 | int i; |
1202 | for(i = 0; i < MAX_TARGETS; i++) { | 1233 | for(i = 0; i < MAX_TARGETS; i++) { |
1203 | u_short param[6]; | 1234 | u_short param[6]; |
1204 | param[0] = MBOX_SET_TARGET_PARAMS; | 1235 | param[0] = MBOX_SET_TARGET_PARAMS; |
1205 | param[1] = (i << 8); | 1236 | param[1] = (i << 8); |
1206 | param[2] = (qpti->dev_param[i].device_flags << 8); | 1237 | param[2] = (qpti->dev_param[i].device_flags << 8); |
1207 | if (qpti->dev_param[i].device_flags & 0x10) { | 1238 | if (qpti->dev_param[i].device_flags & 0x10) { |
1208 | param[3] = (qpti->dev_param[i].synchronous_offset << 8) | | 1239 | param[3] = (qpti->dev_param[i].synchronous_offset << 8) | |
1209 | qpti->dev_param[i].synchronous_period; | 1240 | qpti->dev_param[i].synchronous_period; |
1210 | } else { | 1241 | } else { |
1211 | param[3] = 0; | 1242 | param[3] = 0; |
1212 | } | 1243 | } |
1213 | (void) qlogicpti_mbox_command(qpti, param, 0); | 1244 | (void) qlogicpti_mbox_command(qpti, param, 0); |
1214 | } | 1245 | } |
1215 | /* | 1246 | /* |
1216 | * set to zero so any traverse through ourdone | 1247 | * set to zero so any traverse through ourdone |
1217 | * doesn't start the whole process again, | 1248 | * doesn't start the whole process again, |
1218 | */ | 1249 | */ |
1219 | qpti->sbits = 0; | 1250 | qpti->sbits = 0; |
1220 | } | 1251 | } |
1221 | 1252 | ||
1222 | /* check to see if we're done with all adapters... */ | 1253 | /* check to see if we're done with all adapters... */ |
1223 | for (qpti = qptichain; qpti != NULL; qpti = qpti->next) { | 1254 | for (qpti = qptichain; qpti != NULL; qpti = qpti->next) { |
1224 | if (qpti->sbits) { | 1255 | if (qpti->sbits) { |
1225 | break; | 1256 | break; |
1226 | } | 1257 | } |
1227 | } | 1258 | } |
1228 | 1259 | ||
1229 | /* | 1260 | /* |
1230 | * if we hit the end of the chain w/o finding adapters still | 1261 | * if we hit the end of the chain w/o finding adapters still |
1231 | * capability-configuring, then we're done with all adapters | 1262 | * capability-configuring, then we're done with all adapters |
1232 | * and can rock on.. | 1263 | * and can rock on.. |
1233 | */ | 1264 | */ |
1234 | if (qpti == NULL) | 1265 | if (qpti == NULL) |
1235 | Cmnd->device->host->hostt->queuecommand = qlogicpti_queuecommand; | 1266 | Cmnd->device->host->hostt->queuecommand = qlogicpti_queuecommand; |
1236 | 1267 | ||
1237 | return qlogicpti_queuecommand(Cmnd, done); | 1268 | return qlogicpti_queuecommand(Cmnd, done); |
1238 | } | 1269 | } |
1239 | 1270 | ||
1240 | /* | 1271 | /* |
1241 | * The middle SCSI layer ensures that queuecommand never gets invoked | 1272 | * The middle SCSI layer ensures that queuecommand never gets invoked |
1242 | * concurrently with itself or the interrupt handler (though the | 1273 | * concurrently with itself or the interrupt handler (though the |
1243 | * interrupt handler may call this routine as part of | 1274 | * interrupt handler may call this routine as part of |
1244 | * request-completion handling). | 1275 | * request-completion handling). |
1245 | * | 1276 | * |
1246 | * "This code must fly." -davem | 1277 | * "This code must fly." -davem |
1247 | */ | 1278 | */ |
1248 | static int qlogicpti_queuecommand(struct scsi_cmnd *Cmnd, void (*done)(struct scsi_cmnd *)) | 1279 | static int qlogicpti_queuecommand(struct scsi_cmnd *Cmnd, void (*done)(struct scsi_cmnd *)) |
1249 | { | 1280 | { |
1250 | struct Scsi_Host *host = Cmnd->device->host; | 1281 | struct Scsi_Host *host = Cmnd->device->host; |
1251 | struct qlogicpti *qpti = (struct qlogicpti *) host->hostdata; | 1282 | struct qlogicpti *qpti = (struct qlogicpti *) host->hostdata; |
1252 | struct Command_Entry *cmd; | 1283 | struct Command_Entry *cmd; |
1253 | u_int out_ptr; | 1284 | u_int out_ptr; |
1254 | int in_ptr; | 1285 | int in_ptr; |
1255 | 1286 | ||
1256 | Cmnd->scsi_done = done; | 1287 | Cmnd->scsi_done = done; |
1257 | 1288 | ||
1258 | in_ptr = qpti->req_in_ptr; | 1289 | in_ptr = qpti->req_in_ptr; |
1259 | cmd = (struct Command_Entry *) &qpti->req_cpu[in_ptr]; | 1290 | cmd = (struct Command_Entry *) &qpti->req_cpu[in_ptr]; |
1260 | out_ptr = sbus_readw(qpti->qregs + MBOX4); | 1291 | out_ptr = sbus_readw(qpti->qregs + MBOX4); |
1261 | in_ptr = NEXT_REQ_PTR(in_ptr); | 1292 | in_ptr = NEXT_REQ_PTR(in_ptr); |
1262 | if (in_ptr == out_ptr) | 1293 | if (in_ptr == out_ptr) |
1263 | goto toss_command; | 1294 | goto toss_command; |
1264 | 1295 | ||
1265 | if (qpti->send_marker) { | 1296 | if (qpti->send_marker) { |
1266 | marker_frob(cmd); | 1297 | marker_frob(cmd); |
1267 | qpti->send_marker = 0; | 1298 | qpti->send_marker = 0; |
1268 | if (NEXT_REQ_PTR(in_ptr) == out_ptr) { | 1299 | if (NEXT_REQ_PTR(in_ptr) == out_ptr) { |
1269 | sbus_writew(in_ptr, qpti->qregs + MBOX4); | 1300 | sbus_writew(in_ptr, qpti->qregs + MBOX4); |
1270 | qpti->req_in_ptr = in_ptr; | 1301 | qpti->req_in_ptr = in_ptr; |
1271 | goto toss_command; | 1302 | goto toss_command; |
1272 | } | 1303 | } |
1273 | cmd = (struct Command_Entry *) &qpti->req_cpu[in_ptr]; | 1304 | cmd = (struct Command_Entry *) &qpti->req_cpu[in_ptr]; |
1274 | in_ptr = NEXT_REQ_PTR(in_ptr); | 1305 | in_ptr = NEXT_REQ_PTR(in_ptr); |
1275 | } | 1306 | } |
1276 | cmd_frob(cmd, Cmnd, qpti); | 1307 | cmd_frob(cmd, Cmnd, qpti); |
1277 | if ((in_ptr = load_cmd(Cmnd, cmd, qpti, in_ptr, out_ptr)) == -1) | 1308 | if ((in_ptr = load_cmd(Cmnd, cmd, qpti, in_ptr, out_ptr)) == -1) |
1278 | goto toss_command; | 1309 | goto toss_command; |
1279 | 1310 | ||
1280 | update_can_queue(host, in_ptr, out_ptr); | 1311 | update_can_queue(host, in_ptr, out_ptr); |
1281 | 1312 | ||
1282 | return 0; | 1313 | return 0; |
1283 | 1314 | ||
1284 | toss_command: | 1315 | toss_command: |
1285 | printk(KERN_EMERG "qlogicpti%d: request queue overflow\n", | 1316 | printk(KERN_EMERG "qlogicpti%d: request queue overflow\n", |
1286 | qpti->qpti_id); | 1317 | qpti->qpti_id); |
1287 | 1318 | ||
1288 | /* Unfortunately, unless you use the new EH code, which | 1319 | /* Unfortunately, unless you use the new EH code, which |
1289 | * we don't, the midlayer will ignore the return value, | 1320 | * we don't, the midlayer will ignore the return value, |
1290 | * which is insane. We pick up the pieces like this. | 1321 | * which is insane. We pick up the pieces like this. |
1291 | */ | 1322 | */ |
1292 | Cmnd->result = DID_BUS_BUSY; | 1323 | Cmnd->result = DID_BUS_BUSY; |
1293 | done(Cmnd); | 1324 | done(Cmnd); |
1294 | return 1; | 1325 | return 1; |
1295 | } | 1326 | } |
1296 | 1327 | ||
1297 | static int qlogicpti_return_status(struct Status_Entry *sts, int id) | 1328 | static int qlogicpti_return_status(struct Status_Entry *sts, int id) |
1298 | { | 1329 | { |
1299 | int host_status = DID_ERROR; | 1330 | int host_status = DID_ERROR; |
1300 | 1331 | ||
1301 | switch (sts->completion_status) { | 1332 | switch (sts->completion_status) { |
1302 | case CS_COMPLETE: | 1333 | case CS_COMPLETE: |
1303 | host_status = DID_OK; | 1334 | host_status = DID_OK; |
1304 | break; | 1335 | break; |
1305 | case CS_INCOMPLETE: | 1336 | case CS_INCOMPLETE: |
1306 | if (!(sts->state_flags & SF_GOT_BUS)) | 1337 | if (!(sts->state_flags & SF_GOT_BUS)) |
1307 | host_status = DID_NO_CONNECT; | 1338 | host_status = DID_NO_CONNECT; |
1308 | else if (!(sts->state_flags & SF_GOT_TARGET)) | 1339 | else if (!(sts->state_flags & SF_GOT_TARGET)) |
1309 | host_status = DID_BAD_TARGET; | 1340 | host_status = DID_BAD_TARGET; |
1310 | else if (!(sts->state_flags & SF_SENT_CDB)) | 1341 | else if (!(sts->state_flags & SF_SENT_CDB)) |
1311 | host_status = DID_ERROR; | 1342 | host_status = DID_ERROR; |
1312 | else if (!(sts->state_flags & SF_TRANSFERRED_DATA)) | 1343 | else if (!(sts->state_flags & SF_TRANSFERRED_DATA)) |
1313 | host_status = DID_ERROR; | 1344 | host_status = DID_ERROR; |
1314 | else if (!(sts->state_flags & SF_GOT_STATUS)) | 1345 | else if (!(sts->state_flags & SF_GOT_STATUS)) |
1315 | host_status = DID_ERROR; | 1346 | host_status = DID_ERROR; |
1316 | else if (!(sts->state_flags & SF_GOT_SENSE)) | 1347 | else if (!(sts->state_flags & SF_GOT_SENSE)) |
1317 | host_status = DID_ERROR; | 1348 | host_status = DID_ERROR; |
1318 | break; | 1349 | break; |
1319 | case CS_DMA_ERROR: | 1350 | case CS_DMA_ERROR: |
1320 | case CS_TRANSPORT_ERROR: | 1351 | case CS_TRANSPORT_ERROR: |
1321 | host_status = DID_ERROR; | 1352 | host_status = DID_ERROR; |
1322 | break; | 1353 | break; |
1323 | case CS_RESET_OCCURRED: | 1354 | case CS_RESET_OCCURRED: |
1324 | case CS_BUS_RESET: | 1355 | case CS_BUS_RESET: |
1325 | host_status = DID_RESET; | 1356 | host_status = DID_RESET; |
1326 | break; | 1357 | break; |
1327 | case CS_ABORTED: | 1358 | case CS_ABORTED: |
1328 | host_status = DID_ABORT; | 1359 | host_status = DID_ABORT; |
1329 | break; | 1360 | break; |
1330 | case CS_TIMEOUT: | 1361 | case CS_TIMEOUT: |
1331 | host_status = DID_TIME_OUT; | 1362 | host_status = DID_TIME_OUT; |
1332 | break; | 1363 | break; |
1333 | case CS_DATA_OVERRUN: | 1364 | case CS_DATA_OVERRUN: |
1334 | case CS_COMMAND_OVERRUN: | 1365 | case CS_COMMAND_OVERRUN: |
1335 | case CS_STATUS_OVERRUN: | 1366 | case CS_STATUS_OVERRUN: |
1336 | case CS_BAD_MESSAGE: | 1367 | case CS_BAD_MESSAGE: |
1337 | case CS_NO_MESSAGE_OUT: | 1368 | case CS_NO_MESSAGE_OUT: |
1338 | case CS_EXT_ID_FAILED: | 1369 | case CS_EXT_ID_FAILED: |
1339 | case CS_IDE_MSG_FAILED: | 1370 | case CS_IDE_MSG_FAILED: |
1340 | case CS_ABORT_MSG_FAILED: | 1371 | case CS_ABORT_MSG_FAILED: |
1341 | case CS_NOP_MSG_FAILED: | 1372 | case CS_NOP_MSG_FAILED: |
1342 | case CS_PARITY_ERROR_MSG_FAILED: | 1373 | case CS_PARITY_ERROR_MSG_FAILED: |
1343 | case CS_DEVICE_RESET_MSG_FAILED: | 1374 | case CS_DEVICE_RESET_MSG_FAILED: |
1344 | case CS_ID_MSG_FAILED: | 1375 | case CS_ID_MSG_FAILED: |
1345 | case CS_UNEXP_BUS_FREE: | 1376 | case CS_UNEXP_BUS_FREE: |
1346 | host_status = DID_ERROR; | 1377 | host_status = DID_ERROR; |
1347 | break; | 1378 | break; |
1348 | case CS_DATA_UNDERRUN: | 1379 | case CS_DATA_UNDERRUN: |
1349 | host_status = DID_OK; | 1380 | host_status = DID_OK; |
1350 | break; | 1381 | break; |
1351 | default: | 1382 | default: |
1352 | printk(KERN_EMERG "qpti%d: unknown completion status 0x%04x\n", | 1383 | printk(KERN_EMERG "qpti%d: unknown completion status 0x%04x\n", |
1353 | id, sts->completion_status); | 1384 | id, sts->completion_status); |
1354 | host_status = DID_ERROR; | 1385 | host_status = DID_ERROR; |
1355 | break; | 1386 | break; |
1356 | } | 1387 | } |
1357 | 1388 | ||
1358 | return (sts->scsi_status & STATUS_MASK) | (host_status << 16); | 1389 | return (sts->scsi_status & STATUS_MASK) | (host_status << 16); |
1359 | } | 1390 | } |
1360 | 1391 | ||
1361 | static struct scsi_cmnd *qlogicpti_intr_handler(struct qlogicpti *qpti) | 1392 | static struct scsi_cmnd *qlogicpti_intr_handler(struct qlogicpti *qpti) |
1362 | { | 1393 | { |
1363 | struct scsi_cmnd *Cmnd, *done_queue = NULL; | 1394 | struct scsi_cmnd *Cmnd, *done_queue = NULL; |
1364 | struct Status_Entry *sts; | 1395 | struct Status_Entry *sts; |
1365 | u_int in_ptr, out_ptr; | 1396 | u_int in_ptr, out_ptr; |
1366 | 1397 | ||
1367 | if (!(sbus_readw(qpti->qregs + SBUS_STAT) & SBUS_STAT_RINT)) | 1398 | if (!(sbus_readw(qpti->qregs + SBUS_STAT) & SBUS_STAT_RINT)) |
1368 | return NULL; | 1399 | return NULL; |
1369 | 1400 | ||
1370 | in_ptr = sbus_readw(qpti->qregs + MBOX5); | 1401 | in_ptr = sbus_readw(qpti->qregs + MBOX5); |
1371 | sbus_writew(HCCTRL_CRIRQ, qpti->qregs + HCCTRL); | 1402 | sbus_writew(HCCTRL_CRIRQ, qpti->qregs + HCCTRL); |
1372 | if (sbus_readw(qpti->qregs + SBUS_SEMAPHORE) & SBUS_SEMAPHORE_LCK) { | 1403 | if (sbus_readw(qpti->qregs + SBUS_SEMAPHORE) & SBUS_SEMAPHORE_LCK) { |
1373 | switch (sbus_readw(qpti->qregs + MBOX0)) { | 1404 | switch (sbus_readw(qpti->qregs + MBOX0)) { |
1374 | case ASYNC_SCSI_BUS_RESET: | 1405 | case ASYNC_SCSI_BUS_RESET: |
1375 | case EXECUTION_TIMEOUT_RESET: | 1406 | case EXECUTION_TIMEOUT_RESET: |
1376 | qpti->send_marker = 1; | 1407 | qpti->send_marker = 1; |
1377 | break; | 1408 | break; |
1378 | case INVALID_COMMAND: | 1409 | case INVALID_COMMAND: |
1379 | case HOST_INTERFACE_ERROR: | 1410 | case HOST_INTERFACE_ERROR: |
1380 | case COMMAND_ERROR: | 1411 | case COMMAND_ERROR: |
1381 | case COMMAND_PARAM_ERROR: | 1412 | case COMMAND_PARAM_ERROR: |
1382 | break; | 1413 | break; |
1383 | }; | 1414 | }; |
1384 | sbus_writew(0, qpti->qregs + SBUS_SEMAPHORE); | 1415 | sbus_writew(0, qpti->qregs + SBUS_SEMAPHORE); |
1385 | } | 1416 | } |
1386 | 1417 | ||
1387 | /* This looks like a network driver! */ | 1418 | /* This looks like a network driver! */ |
1388 | out_ptr = qpti->res_out_ptr; | 1419 | out_ptr = qpti->res_out_ptr; |
1389 | while (out_ptr != in_ptr) { | 1420 | while (out_ptr != in_ptr) { |
1390 | u_int cmd_slot; | 1421 | u_int cmd_slot; |
1391 | 1422 | ||
1392 | sts = (struct Status_Entry *) &qpti->res_cpu[out_ptr]; | 1423 | sts = (struct Status_Entry *) &qpti->res_cpu[out_ptr]; |
1393 | out_ptr = NEXT_RES_PTR(out_ptr); | 1424 | out_ptr = NEXT_RES_PTR(out_ptr); |
1394 | 1425 | ||
1395 | /* We store an index in the handle, not the pointer in | 1426 | /* We store an index in the handle, not the pointer in |
1396 | * some form. This avoids problems due to the fact | 1427 | * some form. This avoids problems due to the fact |
1397 | * that the handle provided is only 32-bits. -DaveM | 1428 | * that the handle provided is only 32-bits. -DaveM |
1398 | */ | 1429 | */ |
1399 | cmd_slot = sts->handle; | 1430 | cmd_slot = sts->handle; |
1400 | Cmnd = qpti->cmd_slots[cmd_slot]; | 1431 | Cmnd = qpti->cmd_slots[cmd_slot]; |
1401 | qpti->cmd_slots[cmd_slot] = NULL; | 1432 | qpti->cmd_slots[cmd_slot] = NULL; |
1402 | 1433 | ||
1403 | if (sts->completion_status == CS_RESET_OCCURRED || | 1434 | if (sts->completion_status == CS_RESET_OCCURRED || |
1404 | sts->completion_status == CS_ABORTED || | 1435 | sts->completion_status == CS_ABORTED || |
1405 | (sts->status_flags & STF_BUS_RESET)) | 1436 | (sts->status_flags & STF_BUS_RESET)) |
1406 | qpti->send_marker = 1; | 1437 | qpti->send_marker = 1; |
1407 | 1438 | ||
1408 | if (sts->state_flags & SF_GOT_SENSE) | 1439 | if (sts->state_flags & SF_GOT_SENSE) |
1409 | memcpy(Cmnd->sense_buffer, sts->req_sense_data, | 1440 | memcpy(Cmnd->sense_buffer, sts->req_sense_data, |
1410 | sizeof(Cmnd->sense_buffer)); | 1441 | sizeof(Cmnd->sense_buffer)); |
1411 | 1442 | ||
1412 | if (sts->hdr.entry_type == ENTRY_STATUS) | 1443 | if (sts->hdr.entry_type == ENTRY_STATUS) |
1413 | Cmnd->result = | 1444 | Cmnd->result = |
1414 | qlogicpti_return_status(sts, qpti->qpti_id); | 1445 | qlogicpti_return_status(sts, qpti->qpti_id); |
1415 | else | 1446 | else |
1416 | Cmnd->result = DID_ERROR << 16; | 1447 | Cmnd->result = DID_ERROR << 16; |
1417 | 1448 | ||
1418 | if (Cmnd->use_sg) { | 1449 | if (Cmnd->use_sg) { |
1419 | sbus_unmap_sg(qpti->sdev, | 1450 | sbus_unmap_sg(qpti->sdev, |
1420 | (struct scatterlist *)Cmnd->buffer, | 1451 | (struct scatterlist *)Cmnd->buffer, |
1421 | Cmnd->use_sg, | 1452 | Cmnd->use_sg, |
1422 | Cmnd->sc_data_direction); | 1453 | Cmnd->sc_data_direction); |
1423 | } else { | 1454 | } else { |
1424 | sbus_unmap_single(qpti->sdev, | 1455 | sbus_unmap_single(qpti->sdev, |
1425 | (__u32)((unsigned long)Cmnd->SCp.ptr), | 1456 | (__u32)((unsigned long)Cmnd->SCp.ptr), |
1426 | Cmnd->request_bufflen, | 1457 | Cmnd->request_bufflen, |
1427 | Cmnd->sc_data_direction); | 1458 | Cmnd->sc_data_direction); |
1428 | } | 1459 | } |
1429 | qpti->cmd_count[Cmnd->device->id]--; | 1460 | qpti->cmd_count[Cmnd->device->id]--; |
1430 | sbus_writew(out_ptr, qpti->qregs + MBOX5); | 1461 | sbus_writew(out_ptr, qpti->qregs + MBOX5); |
1431 | Cmnd->host_scribble = (unsigned char *) done_queue; | 1462 | Cmnd->host_scribble = (unsigned char *) done_queue; |
1432 | done_queue = Cmnd; | 1463 | done_queue = Cmnd; |
1433 | } | 1464 | } |
1434 | qpti->res_out_ptr = out_ptr; | 1465 | qpti->res_out_ptr = out_ptr; |
1435 | 1466 | ||
1436 | return done_queue; | 1467 | return done_queue; |
1437 | } | 1468 | } |
1438 | 1469 | ||
1439 | static irqreturn_t qpti_intr(int irq, void *dev_id, struct pt_regs *regs) | 1470 | static irqreturn_t qpti_intr(int irq, void *dev_id, struct pt_regs *regs) |
1440 | { | 1471 | { |
1441 | struct qlogicpti *qpti = dev_id; | 1472 | struct qlogicpti *qpti = dev_id; |
1442 | unsigned long flags; | 1473 | unsigned long flags; |
1443 | struct scsi_cmnd *dq; | 1474 | struct scsi_cmnd *dq; |
1444 | 1475 | ||
1445 | spin_lock_irqsave(qpti->qhost->host_lock, flags); | 1476 | spin_lock_irqsave(qpti->qhost->host_lock, flags); |
1446 | dq = qlogicpti_intr_handler(qpti); | 1477 | dq = qlogicpti_intr_handler(qpti); |
1447 | 1478 | ||
1448 | if (dq != NULL) { | 1479 | if (dq != NULL) { |
1449 | do { | 1480 | do { |
1450 | struct scsi_cmnd *next; | 1481 | struct scsi_cmnd *next; |
1451 | 1482 | ||
1452 | next = (struct scsi_cmnd *) dq->host_scribble; | 1483 | next = (struct scsi_cmnd *) dq->host_scribble; |
1453 | dq->scsi_done(dq); | 1484 | dq->scsi_done(dq); |
1454 | dq = next; | 1485 | dq = next; |
1455 | } while (dq != NULL); | 1486 | } while (dq != NULL); |
1456 | } | 1487 | } |
1457 | spin_unlock_irqrestore(qpti->qhost->host_lock, flags); | 1488 | spin_unlock_irqrestore(qpti->qhost->host_lock, flags); |
1458 | 1489 | ||
1459 | return IRQ_HANDLED; | 1490 | return IRQ_HANDLED; |
1460 | } | 1491 | } |
1461 | 1492 | ||
1462 | static int qlogicpti_abort(struct scsi_cmnd *Cmnd) | 1493 | static int qlogicpti_abort(struct scsi_cmnd *Cmnd) |
1463 | { | 1494 | { |
1464 | u_short param[6]; | 1495 | u_short param[6]; |
1465 | struct Scsi_Host *host = Cmnd->device->host; | 1496 | struct Scsi_Host *host = Cmnd->device->host; |
1466 | struct qlogicpti *qpti = (struct qlogicpti *) host->hostdata; | 1497 | struct qlogicpti *qpti = (struct qlogicpti *) host->hostdata; |
1467 | int return_status = SUCCESS; | 1498 | int return_status = SUCCESS; |
1468 | u32 cmd_cookie; | 1499 | u32 cmd_cookie; |
1469 | int i; | 1500 | int i; |
1470 | 1501 | ||
1471 | printk(KERN_WARNING "qlogicpti : Aborting cmd for tgt[%d] lun[%d]\n", | 1502 | printk(KERN_WARNING "qlogicpti : Aborting cmd for tgt[%d] lun[%d]\n", |
1472 | (int)Cmnd->device->id, (int)Cmnd->device->lun); | 1503 | (int)Cmnd->device->id, (int)Cmnd->device->lun); |
1473 | 1504 | ||
1474 | qlogicpti_disable_irqs(qpti); | 1505 | qlogicpti_disable_irqs(qpti); |
1475 | 1506 | ||
1476 | /* Find the 32-bit cookie we gave to the firmware for | 1507 | /* Find the 32-bit cookie we gave to the firmware for |
1477 | * this command. | 1508 | * this command. |
1478 | */ | 1509 | */ |
1479 | for (i = 0; i < QLOGICPTI_REQ_QUEUE_LEN + 1; i++) | 1510 | for (i = 0; i < QLOGICPTI_REQ_QUEUE_LEN + 1; i++) |
1480 | if (qpti->cmd_slots[i] == Cmnd) | 1511 | if (qpti->cmd_slots[i] == Cmnd) |
1481 | break; | 1512 | break; |
1482 | cmd_cookie = i; | 1513 | cmd_cookie = i; |
1483 | 1514 | ||
1484 | param[0] = MBOX_ABORT; | 1515 | param[0] = MBOX_ABORT; |
1485 | param[1] = (((u_short) Cmnd->device->id) << 8) | Cmnd->device->lun; | 1516 | param[1] = (((u_short) Cmnd->device->id) << 8) | Cmnd->device->lun; |
1486 | param[2] = cmd_cookie >> 16; | 1517 | param[2] = cmd_cookie >> 16; |
1487 | param[3] = cmd_cookie & 0xffff; | 1518 | param[3] = cmd_cookie & 0xffff; |
1488 | if (qlogicpti_mbox_command(qpti, param, 0) || | 1519 | if (qlogicpti_mbox_command(qpti, param, 0) || |
1489 | (param[0] != MBOX_COMMAND_COMPLETE)) { | 1520 | (param[0] != MBOX_COMMAND_COMPLETE)) { |
1490 | printk(KERN_EMERG "qlogicpti : scsi abort failure: %x\n", param[0]); | 1521 | printk(KERN_EMERG "qlogicpti : scsi abort failure: %x\n", param[0]); |
1491 | return_status = FAILED; | 1522 | return_status = FAILED; |
1492 | } | 1523 | } |
1493 | 1524 | ||
1494 | qlogicpti_enable_irqs(qpti); | 1525 | qlogicpti_enable_irqs(qpti); |
1495 | 1526 | ||
1496 | return return_status; | 1527 | return return_status; |
1497 | } | 1528 | } |
1498 | 1529 | ||
1499 | static int qlogicpti_reset(struct scsi_cmnd *Cmnd) | 1530 | static int qlogicpti_reset(struct scsi_cmnd *Cmnd) |
1500 | { | 1531 | { |
1501 | u_short param[6]; | 1532 | u_short param[6]; |
1502 | struct Scsi_Host *host = Cmnd->device->host; | 1533 | struct Scsi_Host *host = Cmnd->device->host; |
1503 | struct qlogicpti *qpti = (struct qlogicpti *) host->hostdata; | 1534 | struct qlogicpti *qpti = (struct qlogicpti *) host->hostdata; |
1504 | int return_status = SUCCESS; | 1535 | int return_status = SUCCESS; |
1505 | 1536 | ||
1506 | printk(KERN_WARNING "qlogicpti : Resetting SCSI bus!\n"); | 1537 | printk(KERN_WARNING "qlogicpti : Resetting SCSI bus!\n"); |
1507 | 1538 | ||
1508 | qlogicpti_disable_irqs(qpti); | 1539 | qlogicpti_disable_irqs(qpti); |
1509 | 1540 | ||
1510 | param[0] = MBOX_BUS_RESET; | 1541 | param[0] = MBOX_BUS_RESET; |
1511 | param[1] = qpti->host_param.bus_reset_delay; | 1542 | param[1] = qpti->host_param.bus_reset_delay; |
1512 | if (qlogicpti_mbox_command(qpti, param, 0) || | 1543 | if (qlogicpti_mbox_command(qpti, param, 0) || |
1513 | (param[0] != MBOX_COMMAND_COMPLETE)) { | 1544 | (param[0] != MBOX_COMMAND_COMPLETE)) { |
1514 | printk(KERN_EMERG "qlogicisp : scsi bus reset failure: %x\n", param[0]); | 1545 | printk(KERN_EMERG "qlogicisp : scsi bus reset failure: %x\n", param[0]); |
1515 | return_status = FAILED; | 1546 | return_status = FAILED; |
1516 | } | 1547 | } |
1517 | 1548 | ||
1518 | qlogicpti_enable_irqs(qpti); | 1549 | qlogicpti_enable_irqs(qpti); |
1519 | 1550 | ||
1520 | return return_status; | 1551 | return return_status; |
1521 | } | 1552 | } |
1522 | 1553 | ||
1523 | static struct scsi_host_template driver_template = { | 1554 | static struct scsi_host_template driver_template = { |
1524 | .detect = qlogicpti_detect, | 1555 | .detect = qlogicpti_detect, |
1525 | .release = qlogicpti_release, | 1556 | .release = qlogicpti_release, |
1526 | .info = qlogicpti_info, | 1557 | .info = qlogicpti_info, |
1527 | .queuecommand = qlogicpti_queuecommand_slow, | 1558 | .queuecommand = qlogicpti_queuecommand_slow, |
1528 | .eh_abort_handler = qlogicpti_abort, | 1559 | .eh_abort_handler = qlogicpti_abort, |
1529 | .eh_bus_reset_handler = qlogicpti_reset, | 1560 | .eh_bus_reset_handler = qlogicpti_reset, |
1530 | .can_queue = QLOGICPTI_REQ_QUEUE_LEN, | 1561 | .can_queue = QLOGICPTI_REQ_QUEUE_LEN, |
1531 | .this_id = 7, | 1562 | .this_id = 7, |
1532 | .sg_tablesize = QLOGICPTI_MAX_SG(QLOGICPTI_REQ_QUEUE_LEN), | 1563 | .sg_tablesize = QLOGICPTI_MAX_SG(QLOGICPTI_REQ_QUEUE_LEN), |
1533 | .cmd_per_lun = 1, | 1564 | .cmd_per_lun = 1, |
1534 | .use_clustering = ENABLE_CLUSTERING, | 1565 | .use_clustering = ENABLE_CLUSTERING, |
1535 | }; | 1566 | }; |
1536 | 1567 | ||
1537 | 1568 | ||
1538 | #include "scsi_module.c" | 1569 | #include "scsi_module.c" |
1539 | 1570 |