]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
fa90c54f | 2 | * QLogic Fibre Channel HBA Driver |
01e58d8e | 3 | * Copyright (c) 2003-2008 QLogic Corporation |
1da177e4 | 4 | * |
fa90c54f | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
1da177e4 LT |
6 | */ |
7 | #include "qla_def.h" | |
8 | ||
05236a05 | 9 | #include <linux/delay.h> |
df7baa50 AV |
10 | #include <scsi/scsi_tcq.h> |
11 | ||
1da177e4 | 12 | static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t); |
73208dfd AC |
13 | static void qla2x00_process_completed_request(struct scsi_qla_host *, |
14 | struct req_que *, uint32_t); | |
15 | static void qla2x00_status_entry(scsi_qla_host_t *, struct rsp_que *, void *); | |
2afa19a9 | 16 | static void qla2x00_status_cont_entry(struct rsp_que *, sts_cont_entry_t *); |
73208dfd AC |
17 | static void qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *, |
18 | sts_entry_t *); | |
9a853f71 | 19 | |
1da177e4 LT |
20 | /** |
21 | * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200. | |
22 | * @irq: | |
23 | * @dev_id: SCSI driver HA context | |
1da177e4 LT |
24 | * |
25 | * Called by system whenever the host adapter generates an interrupt. | |
26 | * | |
27 | * Returns handled flag. | |
28 | */ | |
29 | irqreturn_t | |
7d12e780 | 30 | qla2100_intr_handler(int irq, void *dev_id) |
1da177e4 | 31 | { |
e315cd28 AC |
32 | scsi_qla_host_t *vha; |
33 | struct qla_hw_data *ha; | |
3d71644c | 34 | struct device_reg_2xxx __iomem *reg; |
1da177e4 | 35 | int status; |
1da177e4 | 36 | unsigned long iter; |
14e660e6 | 37 | uint16_t hccr; |
9a853f71 | 38 | uint16_t mb[4]; |
e315cd28 | 39 | struct rsp_que *rsp; |
1da177e4 | 40 | |
e315cd28 AC |
41 | rsp = (struct rsp_que *) dev_id; |
42 | if (!rsp) { | |
1da177e4 | 43 | printk(KERN_INFO |
e315cd28 | 44 | "%s(): NULL response queue pointer\n", __func__); |
1da177e4 LT |
45 | return (IRQ_NONE); |
46 | } | |
47 | ||
e315cd28 | 48 | ha = rsp->hw; |
3d71644c | 49 | reg = &ha->iobase->isp; |
1da177e4 LT |
50 | status = 0; |
51 | ||
c6952483 | 52 | spin_lock(&ha->hardware_lock); |
2afa19a9 | 53 | vha = pci_get_drvdata(ha->pdev); |
1da177e4 | 54 | for (iter = 50; iter--; ) { |
14e660e6 SJ |
55 | hccr = RD_REG_WORD(®->hccr); |
56 | if (hccr & HCCR_RISC_PAUSE) { | |
57 | if (pci_channel_offline(ha->pdev)) | |
58 | break; | |
59 | ||
60 | /* | |
61 | * Issue a "HARD" reset in order for the RISC interrupt | |
62 | * bit to be cleared. Schedule a big hammmer to get | |
63 | * out of the RISC PAUSED state. | |
64 | */ | |
65 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); | |
66 | RD_REG_WORD(®->hccr); | |
67 | ||
e315cd28 AC |
68 | ha->isp_ops->fw_dump(vha, 1); |
69 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
14e660e6 SJ |
70 | break; |
71 | } else if ((RD_REG_WORD(®->istatus) & ISR_RISC_INT) == 0) | |
1da177e4 LT |
72 | break; |
73 | ||
74 | if (RD_REG_WORD(®->semaphore) & BIT_0) { | |
75 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); | |
76 | RD_REG_WORD(®->hccr); | |
77 | ||
78 | /* Get mailbox data. */ | |
9a853f71 AV |
79 | mb[0] = RD_MAILBOX_REG(ha, reg, 0); |
80 | if (mb[0] > 0x3fff && mb[0] < 0x8000) { | |
e315cd28 | 81 | qla2x00_mbx_completion(vha, mb[0]); |
1da177e4 | 82 | status |= MBX_INTERRUPT; |
9a853f71 AV |
83 | } else if (mb[0] > 0x7fff && mb[0] < 0xc000) { |
84 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); | |
85 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); | |
86 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); | |
73208dfd | 87 | qla2x00_async_event(vha, rsp, mb); |
1da177e4 LT |
88 | } else { |
89 | /*EMPTY*/ | |
90 | DEBUG2(printk("scsi(%ld): Unrecognized " | |
9a853f71 | 91 | "interrupt type (%d).\n", |
e315cd28 | 92 | vha->host_no, mb[0])); |
1da177e4 LT |
93 | } |
94 | /* Release mailbox registers. */ | |
95 | WRT_REG_WORD(®->semaphore, 0); | |
96 | RD_REG_WORD(®->semaphore); | |
97 | } else { | |
73208dfd | 98 | qla2x00_process_response_queue(rsp); |
1da177e4 LT |
99 | |
100 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); | |
101 | RD_REG_WORD(®->hccr); | |
102 | } | |
103 | } | |
c6952483 | 104 | spin_unlock(&ha->hardware_lock); |
1da177e4 | 105 | |
1da177e4 LT |
106 | if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) && |
107 | (status & MBX_INTERRUPT) && ha->flags.mbox_int) { | |
1da177e4 | 108 | set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); |
0b05a1f0 | 109 | complete(&ha->mbx_intr_comp); |
1da177e4 LT |
110 | } |
111 | ||
1da177e4 LT |
112 | return (IRQ_HANDLED); |
113 | } | |
114 | ||
115 | /** | |
116 | * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx. | |
117 | * @irq: | |
118 | * @dev_id: SCSI driver HA context | |
1da177e4 LT |
119 | * |
120 | * Called by system whenever the host adapter generates an interrupt. | |
121 | * | |
122 | * Returns handled flag. | |
123 | */ | |
124 | irqreturn_t | |
7d12e780 | 125 | qla2300_intr_handler(int irq, void *dev_id) |
1da177e4 | 126 | { |
e315cd28 | 127 | scsi_qla_host_t *vha; |
3d71644c | 128 | struct device_reg_2xxx __iomem *reg; |
1da177e4 | 129 | int status; |
1da177e4 LT |
130 | unsigned long iter; |
131 | uint32_t stat; | |
1da177e4 | 132 | uint16_t hccr; |
9a853f71 | 133 | uint16_t mb[4]; |
e315cd28 AC |
134 | struct rsp_que *rsp; |
135 | struct qla_hw_data *ha; | |
1da177e4 | 136 | |
e315cd28 AC |
137 | rsp = (struct rsp_que *) dev_id; |
138 | if (!rsp) { | |
1da177e4 | 139 | printk(KERN_INFO |
e315cd28 | 140 | "%s(): NULL response queue pointer\n", __func__); |
1da177e4 LT |
141 | return (IRQ_NONE); |
142 | } | |
143 | ||
e315cd28 | 144 | ha = rsp->hw; |
3d71644c | 145 | reg = &ha->iobase->isp; |
1da177e4 LT |
146 | status = 0; |
147 | ||
c6952483 | 148 | spin_lock(&ha->hardware_lock); |
2afa19a9 | 149 | vha = pci_get_drvdata(ha->pdev); |
1da177e4 LT |
150 | for (iter = 50; iter--; ) { |
151 | stat = RD_REG_DWORD(®->u.isp2300.host_status); | |
152 | if (stat & HSR_RISC_PAUSED) { | |
14e660e6 SJ |
153 | if (pci_channel_offline(ha->pdev)) |
154 | break; | |
155 | ||
1da177e4 LT |
156 | hccr = RD_REG_WORD(®->hccr); |
157 | if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8)) | |
07f31805 AV |
158 | qla_printk(KERN_INFO, ha, "Parity error -- " |
159 | "HCCR=%x, Dumping firmware!\n", hccr); | |
1da177e4 | 160 | else |
07f31805 AV |
161 | qla_printk(KERN_INFO, ha, "RISC paused -- " |
162 | "HCCR=%x, Dumping firmware!\n", hccr); | |
1da177e4 LT |
163 | |
164 | /* | |
165 | * Issue a "HARD" reset in order for the RISC | |
166 | * interrupt bit to be cleared. Schedule a big | |
167 | * hammmer to get out of the RISC PAUSED state. | |
168 | */ | |
169 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); | |
170 | RD_REG_WORD(®->hccr); | |
07f31805 | 171 | |
e315cd28 AC |
172 | ha->isp_ops->fw_dump(vha, 1); |
173 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
1da177e4 LT |
174 | break; |
175 | } else if ((stat & HSR_RISC_INT) == 0) | |
176 | break; | |
177 | ||
1da177e4 | 178 | switch (stat & 0xff) { |
1da177e4 LT |
179 | case 0x1: |
180 | case 0x2: | |
181 | case 0x10: | |
182 | case 0x11: | |
e315cd28 | 183 | qla2x00_mbx_completion(vha, MSW(stat)); |
1da177e4 LT |
184 | status |= MBX_INTERRUPT; |
185 | ||
186 | /* Release mailbox registers. */ | |
187 | WRT_REG_WORD(®->semaphore, 0); | |
188 | break; | |
189 | case 0x12: | |
9a853f71 AV |
190 | mb[0] = MSW(stat); |
191 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); | |
192 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); | |
193 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); | |
73208dfd | 194 | qla2x00_async_event(vha, rsp, mb); |
9a853f71 AV |
195 | break; |
196 | case 0x13: | |
73208dfd | 197 | qla2x00_process_response_queue(rsp); |
1da177e4 LT |
198 | break; |
199 | case 0x15: | |
9a853f71 AV |
200 | mb[0] = MBA_CMPLT_1_16BIT; |
201 | mb[1] = MSW(stat); | |
73208dfd | 202 | qla2x00_async_event(vha, rsp, mb); |
1da177e4 LT |
203 | break; |
204 | case 0x16: | |
9a853f71 AV |
205 | mb[0] = MBA_SCSI_COMPLETION; |
206 | mb[1] = MSW(stat); | |
207 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); | |
73208dfd | 208 | qla2x00_async_event(vha, rsp, mb); |
1da177e4 LT |
209 | break; |
210 | default: | |
211 | DEBUG2(printk("scsi(%ld): Unrecognized interrupt type " | |
9a853f71 | 212 | "(%d).\n", |
e315cd28 | 213 | vha->host_no, stat & 0xff)); |
1da177e4 LT |
214 | break; |
215 | } | |
216 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); | |
217 | RD_REG_WORD_RELAXED(®->hccr); | |
218 | } | |
c6952483 | 219 | spin_unlock(&ha->hardware_lock); |
1da177e4 | 220 | |
1da177e4 LT |
221 | if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) && |
222 | (status & MBX_INTERRUPT) && ha->flags.mbox_int) { | |
1da177e4 | 223 | set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); |
0b05a1f0 | 224 | complete(&ha->mbx_intr_comp); |
1da177e4 LT |
225 | } |
226 | ||
1da177e4 LT |
227 | return (IRQ_HANDLED); |
228 | } | |
229 | ||
230 | /** | |
231 | * qla2x00_mbx_completion() - Process mailbox command completions. | |
232 | * @ha: SCSI driver HA context | |
233 | * @mb0: Mailbox0 register | |
234 | */ | |
235 | static void | |
e315cd28 | 236 | qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0) |
1da177e4 LT |
237 | { |
238 | uint16_t cnt; | |
239 | uint16_t __iomem *wptr; | |
e315cd28 | 240 | struct qla_hw_data *ha = vha->hw; |
3d71644c | 241 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
1da177e4 LT |
242 | |
243 | /* Load return mailbox registers. */ | |
244 | ha->flags.mbox_int = 1; | |
245 | ha->mailbox_out[0] = mb0; | |
246 | wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1); | |
247 | ||
248 | for (cnt = 1; cnt < ha->mbx_count; cnt++) { | |
fa2a1ce5 | 249 | if (IS_QLA2200(ha) && cnt == 8) |
1da177e4 LT |
250 | wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8); |
251 | if (cnt == 4 || cnt == 5) | |
252 | ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr); | |
253 | else | |
254 | ha->mailbox_out[cnt] = RD_REG_WORD(wptr); | |
fa2a1ce5 | 255 | |
1da177e4 LT |
256 | wptr++; |
257 | } | |
258 | ||
259 | if (ha->mcp) { | |
260 | DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n", | |
e315cd28 | 261 | __func__, vha->host_no, ha->mcp->mb[0])); |
1da177e4 LT |
262 | } else { |
263 | DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n", | |
e315cd28 | 264 | __func__, vha->host_no)); |
1da177e4 LT |
265 | } |
266 | } | |
267 | ||
8a659571 AV |
268 | static void |
269 | qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr) | |
270 | { | |
271 | static char *event[] = | |
272 | { "Complete", "Request Notification", "Time Extension" }; | |
273 | int rval; | |
274 | struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24; | |
275 | uint16_t __iomem *wptr; | |
276 | uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS]; | |
277 | ||
278 | /* Seed data -- mailbox1 -> mailbox7. */ | |
279 | wptr = (uint16_t __iomem *)®24->mailbox1; | |
280 | for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++) | |
281 | mb[cnt] = RD_REG_WORD(wptr); | |
282 | ||
283 | DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- " | |
284 | "%04x %04x %04x %04x %04x %04x %04x.\n", vha->host_no, | |
285 | event[aen & 0xff], | |
286 | mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6])); | |
287 | ||
288 | /* Acknowledgement needed? [Notify && non-zero timeout]. */ | |
289 | timeout = (descr >> 8) & 0xf; | |
290 | if (aen != MBA_IDC_NOTIFY || !timeout) | |
291 | return; | |
292 | ||
293 | DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- " | |
294 | "ACK timeout=%d.\n", vha->host_no, event[aen & 0xff], timeout)); | |
295 | ||
296 | rval = qla2x00_post_idc_ack_work(vha, mb); | |
297 | if (rval != QLA_SUCCESS) | |
298 | qla_printk(KERN_WARNING, vha->hw, | |
299 | "IDC failed to post ACK.\n"); | |
300 | } | |
301 | ||
1da177e4 LT |
302 | /** |
303 | * qla2x00_async_event() - Process aynchronous events. | |
304 | * @ha: SCSI driver HA context | |
9a853f71 | 305 | * @mb: Mailbox registers (0 - 3) |
1da177e4 | 306 | */ |
2c3dfe3f | 307 | void |
73208dfd | 308 | qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb) |
1da177e4 | 309 | { |
9a853f71 | 310 | #define LS_UNKNOWN 2 |
3a03eb79 | 311 | static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" }; |
1da177e4 | 312 | char *link_speed; |
1da177e4 LT |
313 | uint16_t handle_cnt; |
314 | uint16_t cnt; | |
315 | uint32_t handles[5]; | |
e315cd28 | 316 | struct qla_hw_data *ha = vha->hw; |
3d71644c | 317 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
1da177e4 LT |
318 | uint32_t rscn_entry, host_pid; |
319 | uint8_t rscn_queue_index; | |
4d4df193 | 320 | unsigned long flags; |
1da177e4 LT |
321 | |
322 | /* Setup to process RIO completion. */ | |
323 | handle_cnt = 0; | |
3a03eb79 AV |
324 | if (IS_QLA81XX(ha)) |
325 | goto skip_rio; | |
1da177e4 LT |
326 | switch (mb[0]) { |
327 | case MBA_SCSI_COMPLETION: | |
9a853f71 | 328 | handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1])); |
1da177e4 LT |
329 | handle_cnt = 1; |
330 | break; | |
331 | case MBA_CMPLT_1_16BIT: | |
9a853f71 | 332 | handles[0] = mb[1]; |
1da177e4 LT |
333 | handle_cnt = 1; |
334 | mb[0] = MBA_SCSI_COMPLETION; | |
335 | break; | |
336 | case MBA_CMPLT_2_16BIT: | |
9a853f71 AV |
337 | handles[0] = mb[1]; |
338 | handles[1] = mb[2]; | |
1da177e4 LT |
339 | handle_cnt = 2; |
340 | mb[0] = MBA_SCSI_COMPLETION; | |
341 | break; | |
342 | case MBA_CMPLT_3_16BIT: | |
9a853f71 AV |
343 | handles[0] = mb[1]; |
344 | handles[1] = mb[2]; | |
345 | handles[2] = mb[3]; | |
1da177e4 LT |
346 | handle_cnt = 3; |
347 | mb[0] = MBA_SCSI_COMPLETION; | |
348 | break; | |
349 | case MBA_CMPLT_4_16BIT: | |
9a853f71 AV |
350 | handles[0] = mb[1]; |
351 | handles[1] = mb[2]; | |
352 | handles[2] = mb[3]; | |
1da177e4 LT |
353 | handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6); |
354 | handle_cnt = 4; | |
355 | mb[0] = MBA_SCSI_COMPLETION; | |
356 | break; | |
357 | case MBA_CMPLT_5_16BIT: | |
9a853f71 AV |
358 | handles[0] = mb[1]; |
359 | handles[1] = mb[2]; | |
360 | handles[2] = mb[3]; | |
1da177e4 LT |
361 | handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6); |
362 | handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7); | |
363 | handle_cnt = 5; | |
364 | mb[0] = MBA_SCSI_COMPLETION; | |
365 | break; | |
366 | case MBA_CMPLT_2_32BIT: | |
9a853f71 | 367 | handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1])); |
1da177e4 LT |
368 | handles[1] = le32_to_cpu( |
369 | ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) | | |
370 | RD_MAILBOX_REG(ha, reg, 6)); | |
371 | handle_cnt = 2; | |
372 | mb[0] = MBA_SCSI_COMPLETION; | |
373 | break; | |
374 | default: | |
375 | break; | |
376 | } | |
3a03eb79 | 377 | skip_rio: |
1da177e4 LT |
378 | switch (mb[0]) { |
379 | case MBA_SCSI_COMPLETION: /* Fast Post */ | |
e315cd28 | 380 | if (!vha->flags.online) |
1da177e4 LT |
381 | break; |
382 | ||
383 | for (cnt = 0; cnt < handle_cnt; cnt++) | |
73208dfd AC |
384 | qla2x00_process_completed_request(vha, rsp->req, |
385 | handles[cnt]); | |
1da177e4 LT |
386 | break; |
387 | ||
388 | case MBA_RESET: /* Reset */ | |
e315cd28 AC |
389 | DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", |
390 | vha->host_no)); | |
1da177e4 | 391 | |
e315cd28 | 392 | set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
1da177e4 LT |
393 | break; |
394 | ||
395 | case MBA_SYSTEM_ERR: /* System Error */ | |
1da177e4 LT |
396 | qla_printk(KERN_INFO, ha, |
397 | "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n", | |
398 | mb[1], mb[2], mb[3]); | |
399 | ||
e315cd28 | 400 | ha->isp_ops->fw_dump(vha, 1); |
1da177e4 | 401 | |
e428924c | 402 | if (IS_FWI2_CAPABLE(ha)) { |
9a853f71 AV |
403 | if (mb[1] == 0 && mb[2] == 0) { |
404 | qla_printk(KERN_ERR, ha, | |
405 | "Unrecoverable Hardware Error: adapter " | |
406 | "marked OFFLINE!\n"); | |
e315cd28 | 407 | vha->flags.online = 0; |
9a853f71 | 408 | } else |
e315cd28 | 409 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
9a853f71 | 410 | } else if (mb[1] == 0) { |
1da177e4 LT |
411 | qla_printk(KERN_INFO, ha, |
412 | "Unrecoverable Hardware Error: adapter marked " | |
413 | "OFFLINE!\n"); | |
e315cd28 | 414 | vha->flags.online = 0; |
1da177e4 | 415 | } else |
e315cd28 | 416 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
1da177e4 LT |
417 | break; |
418 | ||
419 | case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */ | |
420 | DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n", | |
e315cd28 | 421 | vha->host_no)); |
1da177e4 LT |
422 | qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n"); |
423 | ||
e315cd28 | 424 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
1da177e4 LT |
425 | break; |
426 | ||
427 | case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */ | |
428 | DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n", | |
e315cd28 | 429 | vha->host_no)); |
1da177e4 LT |
430 | qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n"); |
431 | ||
e315cd28 | 432 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
1da177e4 LT |
433 | break; |
434 | ||
435 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up */ | |
436 | DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n", | |
e315cd28 | 437 | vha->host_no)); |
1da177e4 LT |
438 | break; |
439 | ||
440 | case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */ | |
e315cd28 | 441 | DEBUG2(printk("scsi(%ld): LIP occurred (%x).\n", vha->host_no, |
1da177e4 | 442 | mb[1])); |
cc3ef7bc | 443 | qla_printk(KERN_INFO, ha, "LIP occurred (%x).\n", mb[1]); |
1da177e4 | 444 | |
e315cd28 AC |
445 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
446 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
447 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | |
448 | qla2x00_mark_all_devices_lost(vha, 1); | |
1da177e4 LT |
449 | } |
450 | ||
e315cd28 AC |
451 | if (vha->vp_idx) { |
452 | atomic_set(&vha->vp_state, VP_FAILED); | |
453 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); | |
2c3dfe3f SJ |
454 | } |
455 | ||
e315cd28 AC |
456 | set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags); |
457 | set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags); | |
1da177e4 | 458 | |
e315cd28 AC |
459 | vha->flags.management_server_logged_in = 0; |
460 | qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]); | |
1da177e4 LT |
461 | break; |
462 | ||
463 | case MBA_LOOP_UP: /* Loop Up Event */ | |
1da177e4 LT |
464 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
465 | link_speed = link_speeds[0]; | |
d8b45213 | 466 | ha->link_data_rate = PORT_SPEED_1GB; |
1da177e4 | 467 | } else { |
9a853f71 | 468 | link_speed = link_speeds[LS_UNKNOWN]; |
1da177e4 LT |
469 | if (mb[1] < 5) |
470 | link_speed = link_speeds[mb[1]]; | |
3a03eb79 AV |
471 | else if (mb[1] == 0x13) |
472 | link_speed = link_speeds[5]; | |
1da177e4 LT |
473 | ha->link_data_rate = mb[1]; |
474 | } | |
475 | ||
476 | DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n", | |
e315cd28 | 477 | vha->host_no, link_speed)); |
1da177e4 LT |
478 | qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n", |
479 | link_speed); | |
480 | ||
e315cd28 AC |
481 | vha->flags.management_server_logged_in = 0; |
482 | qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate); | |
1da177e4 LT |
483 | break; |
484 | ||
485 | case MBA_LOOP_DOWN: /* Loop Down Event */ | |
4d4df193 | 486 | DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN " |
e315cd28 | 487 | "(%x %x %x).\n", vha->host_no, mb[1], mb[2], mb[3])); |
4d4df193 HK |
488 | qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x %x %x).\n", |
489 | mb[1], mb[2], mb[3]); | |
1da177e4 | 490 | |
e315cd28 AC |
491 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
492 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
493 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | |
494 | vha->device_flags |= DFLG_NO_CABLE; | |
495 | qla2x00_mark_all_devices_lost(vha, 1); | |
1da177e4 LT |
496 | } |
497 | ||
e315cd28 AC |
498 | if (vha->vp_idx) { |
499 | atomic_set(&vha->vp_state, VP_FAILED); | |
500 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); | |
2c3dfe3f SJ |
501 | } |
502 | ||
e315cd28 | 503 | vha->flags.management_server_logged_in = 0; |
d8b45213 | 504 | ha->link_data_rate = PORT_SPEED_UNKNOWN; |
e315cd28 | 505 | qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0); |
1da177e4 LT |
506 | break; |
507 | ||
508 | case MBA_LIP_RESET: /* LIP reset occurred */ | |
1da177e4 | 509 | DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n", |
e315cd28 | 510 | vha->host_no, mb[1])); |
1da177e4 | 511 | qla_printk(KERN_INFO, ha, |
cc3ef7bc | 512 | "LIP reset occurred (%x).\n", mb[1]); |
1da177e4 | 513 | |
e315cd28 AC |
514 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
515 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
516 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | |
517 | qla2x00_mark_all_devices_lost(vha, 1); | |
1da177e4 LT |
518 | } |
519 | ||
e315cd28 AC |
520 | if (vha->vp_idx) { |
521 | atomic_set(&vha->vp_state, VP_FAILED); | |
522 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); | |
2c3dfe3f SJ |
523 | } |
524 | ||
e315cd28 | 525 | set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
1da177e4 LT |
526 | |
527 | ha->operating_mode = LOOP; | |
e315cd28 AC |
528 | vha->flags.management_server_logged_in = 0; |
529 | qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]); | |
1da177e4 LT |
530 | break; |
531 | ||
3a03eb79 | 532 | /* case MBA_DCBX_COMPLETE: */ |
1da177e4 LT |
533 | case MBA_POINT_TO_POINT: /* Point-to-Point */ |
534 | if (IS_QLA2100(ha)) | |
535 | break; | |
536 | ||
3a03eb79 AV |
537 | if (IS_QLA81XX(ha)) |
538 | DEBUG2(printk("scsi(%ld): DCBX Completed -- %04x %04x " | |
539 | "%04x\n", vha->host_no, mb[1], mb[2], mb[3])); | |
540 | else | |
541 | DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE " | |
542 | "received.\n", vha->host_no)); | |
1da177e4 LT |
543 | |
544 | /* | |
545 | * Until there's a transition from loop down to loop up, treat | |
546 | * this as loop down only. | |
547 | */ | |
e315cd28 AC |
548 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
549 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
550 | if (!atomic_read(&vha->loop_down_timer)) | |
551 | atomic_set(&vha->loop_down_timer, | |
1da177e4 | 552 | LOOP_DOWN_TIME); |
e315cd28 | 553 | qla2x00_mark_all_devices_lost(vha, 1); |
1da177e4 LT |
554 | } |
555 | ||
e315cd28 AC |
556 | if (vha->vp_idx) { |
557 | atomic_set(&vha->vp_state, VP_FAILED); | |
558 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); | |
2c3dfe3f SJ |
559 | } |
560 | ||
e315cd28 AC |
561 | if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) |
562 | set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); | |
563 | ||
564 | set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags); | |
565 | set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags); | |
4346b149 AV |
566 | |
567 | ha->flags.gpsc_supported = 1; | |
e315cd28 | 568 | vha->flags.management_server_logged_in = 0; |
1da177e4 LT |
569 | break; |
570 | ||
571 | case MBA_CHG_IN_CONNECTION: /* Change in connection mode */ | |
572 | if (IS_QLA2100(ha)) | |
573 | break; | |
574 | ||
1da177e4 LT |
575 | DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection " |
576 | "received.\n", | |
e315cd28 | 577 | vha->host_no)); |
1da177e4 LT |
578 | qla_printk(KERN_INFO, ha, |
579 | "Configuration change detected: value=%x.\n", mb[1]); | |
580 | ||
e315cd28 AC |
581 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
582 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
583 | if (!atomic_read(&vha->loop_down_timer)) | |
584 | atomic_set(&vha->loop_down_timer, | |
1da177e4 | 585 | LOOP_DOWN_TIME); |
e315cd28 | 586 | qla2x00_mark_all_devices_lost(vha, 1); |
1da177e4 LT |
587 | } |
588 | ||
e315cd28 AC |
589 | if (vha->vp_idx) { |
590 | atomic_set(&vha->vp_state, VP_FAILED); | |
591 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); | |
2c3dfe3f SJ |
592 | } |
593 | ||
e315cd28 AC |
594 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
595 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); | |
1da177e4 LT |
596 | break; |
597 | ||
598 | case MBA_PORT_UPDATE: /* Port database update */ | |
73208dfd AC |
599 | /* Only handle SCNs for our Vport index. */ |
600 | if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff)) | |
601 | break; | |
602 | ||
1da177e4 | 603 | /* |
cc3ef7bc | 604 | * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET |
1da177e4 LT |
605 | * event etc. earlier indicating loop is down) then process |
606 | * it. Otherwise ignore it and Wait for RSCN to come in. | |
607 | */ | |
e315cd28 AC |
608 | atomic_set(&vha->loop_down_timer, 0); |
609 | if (atomic_read(&vha->loop_state) != LOOP_DOWN && | |
610 | atomic_read(&vha->loop_state) != LOOP_DEAD) { | |
1da177e4 | 611 | DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE " |
e315cd28 | 612 | "ignored %04x/%04x/%04x.\n", vha->host_no, mb[1], |
9a853f71 | 613 | mb[2], mb[3])); |
1da177e4 LT |
614 | break; |
615 | } | |
616 | ||
617 | DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n", | |
e315cd28 | 618 | vha->host_no)); |
1da177e4 | 619 | DEBUG(printk(KERN_INFO |
9a853f71 | 620 | "scsi(%ld): Port database changed %04x %04x %04x.\n", |
e315cd28 | 621 | vha->host_no, mb[1], mb[2], mb[3])); |
1da177e4 LT |
622 | |
623 | /* | |
624 | * Mark all devices as missing so we will login again. | |
625 | */ | |
e315cd28 | 626 | atomic_set(&vha->loop_state, LOOP_UP); |
1da177e4 | 627 | |
e315cd28 | 628 | qla2x00_mark_all_devices_lost(vha, 1); |
1da177e4 | 629 | |
e315cd28 | 630 | vha->flags.rscn_queue_overflow = 1; |
1da177e4 | 631 | |
e315cd28 AC |
632 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
633 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); | |
1da177e4 LT |
634 | break; |
635 | ||
636 | case MBA_RSCN_UPDATE: /* State Change Registration */ | |
3c397400 | 637 | /* Check if the Vport has issued a SCR */ |
e315cd28 | 638 | if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags)) |
3c397400 SJ |
639 | break; |
640 | /* Only handle SCNs for our Vport index. */ | |
e315cd28 | 641 | if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff)) |
3c397400 | 642 | break; |
1da177e4 | 643 | DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n", |
e315cd28 | 644 | vha->host_no)); |
1da177e4 | 645 | DEBUG(printk(KERN_INFO |
f4a8dbc7 | 646 | "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n", |
e315cd28 | 647 | vha->host_no, mb[1], mb[2], mb[3])); |
1da177e4 | 648 | |
59d72d87 | 649 | rscn_entry = ((mb[1] & 0xff) << 16) | mb[2]; |
e315cd28 AC |
650 | host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8) |
651 | | vha->d_id.b.al_pa; | |
1da177e4 LT |
652 | if (rscn_entry == host_pid) { |
653 | DEBUG(printk(KERN_INFO | |
654 | "scsi(%ld): Ignoring RSCN update to local host " | |
655 | "port ID (%06x)\n", | |
e315cd28 | 656 | vha->host_no, host_pid)); |
1da177e4 LT |
657 | break; |
658 | } | |
659 | ||
59d72d87 RA |
660 | /* Ignore reserved bits from RSCN-payload. */ |
661 | rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2]; | |
e315cd28 | 662 | rscn_queue_index = vha->rscn_in_ptr + 1; |
1da177e4 LT |
663 | if (rscn_queue_index == MAX_RSCN_COUNT) |
664 | rscn_queue_index = 0; | |
e315cd28 AC |
665 | if (rscn_queue_index != vha->rscn_out_ptr) { |
666 | vha->rscn_queue[vha->rscn_in_ptr] = rscn_entry; | |
667 | vha->rscn_in_ptr = rscn_queue_index; | |
1da177e4 | 668 | } else { |
e315cd28 | 669 | vha->flags.rscn_queue_overflow = 1; |
1da177e4 LT |
670 | } |
671 | ||
e315cd28 AC |
672 | atomic_set(&vha->loop_state, LOOP_UPDATE); |
673 | atomic_set(&vha->loop_down_timer, 0); | |
674 | vha->flags.management_server_logged_in = 0; | |
1da177e4 | 675 | |
e315cd28 AC |
676 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
677 | set_bit(RSCN_UPDATE, &vha->dpc_flags); | |
678 | qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry); | |
1da177e4 LT |
679 | break; |
680 | ||
681 | /* case MBA_RIO_RESPONSE: */ | |
682 | case MBA_ZIO_RESPONSE: | |
3fd67cdf | 683 | DEBUG3(printk("scsi(%ld): [R|Z]IO update completion.\n", |
e315cd28 | 684 | vha->host_no)); |
1da177e4 | 685 | |
e428924c | 686 | if (IS_FWI2_CAPABLE(ha)) |
2afa19a9 | 687 | qla24xx_process_response_queue(vha, rsp); |
4fdfefe5 | 688 | else |
73208dfd | 689 | qla2x00_process_response_queue(rsp); |
1da177e4 | 690 | break; |
9a853f71 AV |
691 | |
692 | case MBA_DISCARD_RND_FRAME: | |
693 | DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x " | |
e315cd28 | 694 | "%04x.\n", vha->host_no, mb[1], mb[2], mb[3])); |
9a853f71 | 695 | break; |
45ebeb56 AV |
696 | |
697 | case MBA_TRACE_NOTIFICATION: | |
698 | DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n", | |
e315cd28 | 699 | vha->host_no, mb[1], mb[2])); |
45ebeb56 | 700 | break; |
4d4df193 HK |
701 | |
702 | case MBA_ISP84XX_ALERT: | |
703 | DEBUG2(printk("scsi(%ld): ISP84XX Alert Notification -- " | |
e315cd28 | 704 | "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3])); |
4d4df193 HK |
705 | |
706 | spin_lock_irqsave(&ha->cs84xx->access_lock, flags); | |
707 | switch (mb[1]) { | |
708 | case A84_PANIC_RECOVERY: | |
709 | qla_printk(KERN_INFO, ha, "Alert 84XX: panic recovery " | |
710 | "%04x %04x\n", mb[2], mb[3]); | |
711 | break; | |
712 | case A84_OP_LOGIN_COMPLETE: | |
713 | ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2]; | |
714 | DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:" | |
715 | "firmware version %x\n", ha->cs84xx->op_fw_version)); | |
716 | break; | |
717 | case A84_DIAG_LOGIN_COMPLETE: | |
718 | ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2]; | |
719 | DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:" | |
720 | "diagnostic firmware version %x\n", | |
721 | ha->cs84xx->diag_fw_version)); | |
722 | break; | |
723 | case A84_GOLD_LOGIN_COMPLETE: | |
724 | ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2]; | |
725 | ha->cs84xx->fw_update = 1; | |
726 | DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX: gold " | |
727 | "firmware version %x\n", | |
728 | ha->cs84xx->gold_fw_version)); | |
729 | break; | |
730 | default: | |
731 | qla_printk(KERN_ERR, ha, | |
732 | "Alert 84xx: Invalid Alert %04x %04x %04x\n", | |
733 | mb[1], mb[2], mb[3]); | |
734 | } | |
735 | spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags); | |
736 | break; | |
3a03eb79 AV |
737 | case MBA_DCBX_START: |
738 | DEBUG2(printk("scsi(%ld): DCBX Started -- %04x %04x %04x\n", | |
739 | vha->host_no, mb[1], mb[2], mb[3])); | |
740 | break; | |
741 | case MBA_DCBX_PARAM_UPDATE: | |
742 | DEBUG2(printk("scsi(%ld): DCBX Parameters Updated -- " | |
743 | "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3])); | |
744 | break; | |
745 | case MBA_FCF_CONF_ERR: | |
746 | DEBUG2(printk("scsi(%ld): FCF Configuration Error -- " | |
747 | "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3])); | |
748 | break; | |
749 | case MBA_IDC_COMPLETE: | |
3a03eb79 | 750 | case MBA_IDC_NOTIFY: |
3a03eb79 | 751 | case MBA_IDC_TIME_EXT: |
8a659571 | 752 | qla81xx_idc_event(vha, mb[0], mb[1]); |
3a03eb79 | 753 | break; |
1da177e4 | 754 | } |
2c3dfe3f | 755 | |
e315cd28 | 756 | if (!vha->vp_idx && ha->num_vhosts) |
73208dfd | 757 | qla2x00_alert_all_vps(rsp, mb); |
1da177e4 LT |
758 | } |
759 | ||
df7baa50 AV |
760 | static void |
761 | qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data) | |
762 | { | |
763 | fc_port_t *fcport = data; | |
73208dfd AC |
764 | struct scsi_qla_host *vha = fcport->vha; |
765 | struct qla_hw_data *ha = vha->hw; | |
766 | struct req_que *req = NULL; | |
767 | ||
2afa19a9 | 768 | req = vha->req; |
73208dfd AC |
769 | if (!req) |
770 | return; | |
771 | if (req->max_q_depth <= sdev->queue_depth) | |
df7baa50 AV |
772 | return; |
773 | ||
774 | if (sdev->ordered_tags) | |
775 | scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, | |
776 | sdev->queue_depth + 1); | |
777 | else | |
778 | scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, | |
779 | sdev->queue_depth + 1); | |
780 | ||
781 | fcport->last_ramp_up = jiffies; | |
782 | ||
e315cd28 | 783 | DEBUG2(qla_printk(KERN_INFO, ha, |
df7baa50 | 784 | "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n", |
e315cd28 | 785 | fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun, |
df7baa50 AV |
786 | sdev->queue_depth)); |
787 | } | |
788 | ||
789 | static void | |
790 | qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data) | |
791 | { | |
792 | fc_port_t *fcport = data; | |
793 | ||
794 | if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1)) | |
795 | return; | |
796 | ||
e315cd28 | 797 | DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw, |
df7baa50 | 798 | "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n", |
e315cd28 | 799 | fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun, |
df7baa50 AV |
800 | sdev->queue_depth)); |
801 | } | |
802 | ||
803 | static inline void | |
73208dfd AC |
804 | qla2x00_ramp_up_queue_depth(scsi_qla_host_t *vha, struct req_que *req, |
805 | srb_t *sp) | |
df7baa50 AV |
806 | { |
807 | fc_port_t *fcport; | |
808 | struct scsi_device *sdev; | |
809 | ||
810 | sdev = sp->cmd->device; | |
73208dfd | 811 | if (sdev->queue_depth >= req->max_q_depth) |
df7baa50 AV |
812 | return; |
813 | ||
814 | fcport = sp->fcport; | |
815 | if (time_before(jiffies, | |
816 | fcport->last_ramp_up + ql2xqfullrampup * HZ)) | |
817 | return; | |
818 | if (time_before(jiffies, | |
819 | fcport->last_queue_full + ql2xqfullrampup * HZ)) | |
820 | return; | |
821 | ||
df7baa50 AV |
822 | starget_for_each_device(sdev->sdev_target, fcport, |
823 | qla2x00_adjust_sdev_qdepth_up); | |
df7baa50 AV |
824 | } |
825 | ||
1da177e4 LT |
826 | /** |
827 | * qla2x00_process_completed_request() - Process a Fast Post response. | |
828 | * @ha: SCSI driver HA context | |
829 | * @index: SRB index | |
830 | */ | |
831 | static void | |
73208dfd AC |
832 | qla2x00_process_completed_request(struct scsi_qla_host *vha, |
833 | struct req_que *req, uint32_t index) | |
1da177e4 LT |
834 | { |
835 | srb_t *sp; | |
e315cd28 | 836 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
837 | |
838 | /* Validate handle. */ | |
839 | if (index >= MAX_OUTSTANDING_COMMANDS) { | |
840 | DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n", | |
e315cd28 | 841 | vha->host_no, index)); |
1da177e4 LT |
842 | qla_printk(KERN_WARNING, ha, |
843 | "Invalid SCSI completion handle %d.\n", index); | |
844 | ||
e315cd28 | 845 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
1da177e4 LT |
846 | return; |
847 | } | |
848 | ||
e315cd28 | 849 | sp = req->outstanding_cmds[index]; |
1da177e4 LT |
850 | if (sp) { |
851 | /* Free outstanding command slot. */ | |
e315cd28 | 852 | req->outstanding_cmds[index] = NULL; |
1da177e4 | 853 | |
1da177e4 LT |
854 | /* Save ISP completion status */ |
855 | sp->cmd->result = DID_OK << 16; | |
df7baa50 | 856 | |
73208dfd AC |
857 | qla2x00_ramp_up_queue_depth(vha, req, sp); |
858 | qla2x00_sp_compl(ha, sp); | |
1da177e4 | 859 | } else { |
2afa19a9 AC |
860 | DEBUG2(printk("scsi(%ld) Req:%d: Invalid ISP SCSI completion" |
861 | " handle(%d)\n", vha->host_no, req->id, index)); | |
1da177e4 LT |
862 | qla_printk(KERN_WARNING, ha, |
863 | "Invalid ISP SCSI completion handle\n"); | |
864 | ||
e315cd28 | 865 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
1da177e4 LT |
866 | } |
867 | } | |
868 | ||
869 | /** | |
870 | * qla2x00_process_response_queue() - Process response queue entries. | |
871 | * @ha: SCSI driver HA context | |
872 | */ | |
873 | void | |
73208dfd | 874 | qla2x00_process_response_queue(struct rsp_que *rsp) |
1da177e4 | 875 | { |
73208dfd AC |
876 | struct scsi_qla_host *vha; |
877 | struct qla_hw_data *ha = rsp->hw; | |
3d71644c | 878 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
1da177e4 LT |
879 | sts_entry_t *pkt; |
880 | uint16_t handle_cnt; | |
881 | uint16_t cnt; | |
73208dfd | 882 | |
2afa19a9 | 883 | vha = pci_get_drvdata(ha->pdev); |
1da177e4 | 884 | |
e315cd28 | 885 | if (!vha->flags.online) |
1da177e4 LT |
886 | return; |
887 | ||
e315cd28 AC |
888 | while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) { |
889 | pkt = (sts_entry_t *)rsp->ring_ptr; | |
1da177e4 | 890 | |
e315cd28 AC |
891 | rsp->ring_index++; |
892 | if (rsp->ring_index == rsp->length) { | |
893 | rsp->ring_index = 0; | |
894 | rsp->ring_ptr = rsp->ring; | |
1da177e4 | 895 | } else { |
e315cd28 | 896 | rsp->ring_ptr++; |
1da177e4 LT |
897 | } |
898 | ||
899 | if (pkt->entry_status != 0) { | |
900 | DEBUG3(printk(KERN_INFO | |
e315cd28 | 901 | "scsi(%ld): Process error entry.\n", vha->host_no)); |
1da177e4 | 902 | |
73208dfd | 903 | qla2x00_error_entry(vha, rsp, pkt); |
1da177e4 LT |
904 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; |
905 | wmb(); | |
906 | continue; | |
907 | } | |
908 | ||
909 | switch (pkt->entry_type) { | |
910 | case STATUS_TYPE: | |
73208dfd | 911 | qla2x00_status_entry(vha, rsp, pkt); |
1da177e4 LT |
912 | break; |
913 | case STATUS_TYPE_21: | |
914 | handle_cnt = ((sts21_entry_t *)pkt)->handle_count; | |
915 | for (cnt = 0; cnt < handle_cnt; cnt++) { | |
73208dfd | 916 | qla2x00_process_completed_request(vha, rsp->req, |
1da177e4 LT |
917 | ((sts21_entry_t *)pkt)->handle[cnt]); |
918 | } | |
919 | break; | |
920 | case STATUS_TYPE_22: | |
921 | handle_cnt = ((sts22_entry_t *)pkt)->handle_count; | |
922 | for (cnt = 0; cnt < handle_cnt; cnt++) { | |
73208dfd | 923 | qla2x00_process_completed_request(vha, rsp->req, |
1da177e4 LT |
924 | ((sts22_entry_t *)pkt)->handle[cnt]); |
925 | } | |
926 | break; | |
927 | case STATUS_CONT_TYPE: | |
2afa19a9 | 928 | qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt); |
1da177e4 | 929 | break; |
1da177e4 LT |
930 | default: |
931 | /* Type Not Supported. */ | |
932 | DEBUG4(printk(KERN_WARNING | |
933 | "scsi(%ld): Received unknown response pkt type %x " | |
934 | "entry status=%x.\n", | |
e315cd28 | 935 | vha->host_no, pkt->entry_type, pkt->entry_status)); |
1da177e4 LT |
936 | break; |
937 | } | |
938 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; | |
939 | wmb(); | |
940 | } | |
941 | ||
942 | /* Adjust ring index */ | |
e315cd28 | 943 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index); |
1da177e4 LT |
944 | } |
945 | ||
4733fcb1 | 946 | static inline void |
2afa19a9 AC |
947 | qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len, |
948 | struct rsp_que *rsp) | |
4733fcb1 AV |
949 | { |
950 | struct scsi_cmnd *cp = sp->cmd; | |
951 | ||
952 | if (sense_len >= SCSI_SENSE_BUFFERSIZE) | |
953 | sense_len = SCSI_SENSE_BUFFERSIZE; | |
954 | ||
4733fcb1 AV |
955 | sp->request_sense_length = sense_len; |
956 | sp->request_sense_ptr = cp->sense_buffer; | |
957 | if (sp->request_sense_length > 32) | |
958 | sense_len = 32; | |
959 | ||
960 | memcpy(cp->sense_buffer, sense_data, sense_len); | |
961 | ||
962 | sp->request_sense_ptr += sense_len; | |
963 | sp->request_sense_length -= sense_len; | |
964 | if (sp->request_sense_length != 0) | |
2afa19a9 | 965 | rsp->status_srb = sp; |
4733fcb1 AV |
966 | |
967 | DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) " | |
e315cd28 | 968 | "cmd=%p pid=%ld\n", __func__, sp->fcport->vha->host_no, |
19851f13 AV |
969 | cp->device->channel, cp->device->id, cp->device->lun, cp, |
970 | cp->serial_number)); | |
4733fcb1 | 971 | if (sense_len) |
ddb9b126 | 972 | DEBUG5(qla2x00_dump_buffer(cp->sense_buffer, sense_len)); |
4733fcb1 AV |
973 | } |
974 | ||
1da177e4 LT |
975 | /** |
976 | * qla2x00_status_entry() - Process a Status IOCB entry. | |
977 | * @ha: SCSI driver HA context | |
978 | * @pkt: Entry pointer | |
979 | */ | |
980 | static void | |
73208dfd | 981 | qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt) |
1da177e4 | 982 | { |
1da177e4 | 983 | srb_t *sp; |
1da177e4 LT |
984 | fc_port_t *fcport; |
985 | struct scsi_cmnd *cp; | |
9a853f71 AV |
986 | sts_entry_t *sts; |
987 | struct sts_entry_24xx *sts24; | |
1da177e4 LT |
988 | uint16_t comp_status; |
989 | uint16_t scsi_status; | |
990 | uint8_t lscsi_status; | |
991 | int32_t resid; | |
ed17c71b | 992 | uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len; |
9a853f71 | 993 | uint8_t *rsp_info, *sense_data; |
e315cd28 | 994 | struct qla_hw_data *ha = vha->hw; |
2afa19a9 AC |
995 | uint32_t handle; |
996 | uint16_t que; | |
997 | struct req_que *req; | |
9a853f71 AV |
998 | |
999 | sts = (sts_entry_t *) pkt; | |
1000 | sts24 = (struct sts_entry_24xx *) pkt; | |
e428924c | 1001 | if (IS_FWI2_CAPABLE(ha)) { |
9a853f71 AV |
1002 | comp_status = le16_to_cpu(sts24->comp_status); |
1003 | scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK; | |
1004 | } else { | |
1005 | comp_status = le16_to_cpu(sts->comp_status); | |
1006 | scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK; | |
1007 | } | |
2afa19a9 AC |
1008 | handle = (uint32_t) LSW(sts->handle); |
1009 | que = MSW(sts->handle); | |
1010 | req = ha->req_q_map[que]; | |
1da177e4 | 1011 | /* Fast path completion. */ |
9a853f71 | 1012 | if (comp_status == CS_COMPLETE && scsi_status == 0) { |
2afa19a9 | 1013 | qla2x00_process_completed_request(vha, req, handle); |
1da177e4 LT |
1014 | |
1015 | return; | |
1016 | } | |
1017 | ||
1018 | /* Validate handle. */ | |
2afa19a9 AC |
1019 | if (handle < MAX_OUTSTANDING_COMMANDS) { |
1020 | sp = req->outstanding_cmds[handle]; | |
1021 | req->outstanding_cmds[handle] = NULL; | |
1da177e4 LT |
1022 | } else |
1023 | sp = NULL; | |
1024 | ||
1025 | if (sp == NULL) { | |
1026 | DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n", | |
e315cd28 | 1027 | vha->host_no)); |
1da177e4 LT |
1028 | qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n"); |
1029 | ||
e315cd28 AC |
1030 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
1031 | qla2xxx_wake_dpc(vha); | |
1da177e4 LT |
1032 | return; |
1033 | } | |
1034 | cp = sp->cmd; | |
1035 | if (cp == NULL) { | |
1036 | DEBUG2(printk("scsi(%ld): Command already returned back to OS " | |
2afa19a9 | 1037 | "pkt->handle=%d sp=%p.\n", vha->host_no, handle, sp)); |
1da177e4 LT |
1038 | qla_printk(KERN_WARNING, ha, |
1039 | "Command is NULL: already returned to OS (sp=%p)\n", sp); | |
1040 | ||
1041 | return; | |
1042 | } | |
1043 | ||
9a853f71 | 1044 | lscsi_status = scsi_status & STATUS_MASK; |
1da177e4 | 1045 | |
bdf79621 | 1046 | fcport = sp->fcport; |
1da177e4 | 1047 | |
ed17c71b | 1048 | sense_len = rsp_info_len = resid_len = fw_resid_len = 0; |
e428924c | 1049 | if (IS_FWI2_CAPABLE(ha)) { |
9a853f71 AV |
1050 | sense_len = le32_to_cpu(sts24->sense_len); |
1051 | rsp_info_len = le32_to_cpu(sts24->rsp_data_len); | |
1052 | resid_len = le32_to_cpu(sts24->rsp_residual_count); | |
ed17c71b | 1053 | fw_resid_len = le32_to_cpu(sts24->residual_len); |
9a853f71 AV |
1054 | rsp_info = sts24->data; |
1055 | sense_data = sts24->data; | |
1056 | host_to_fcp_swap(sts24->data, sizeof(sts24->data)); | |
1057 | } else { | |
1058 | sense_len = le16_to_cpu(sts->req_sense_length); | |
1059 | rsp_info_len = le16_to_cpu(sts->rsp_info_len); | |
1060 | resid_len = le32_to_cpu(sts->residual_length); | |
1061 | rsp_info = sts->rsp_info; | |
1062 | sense_data = sts->req_sense_data; | |
1063 | } | |
1064 | ||
1da177e4 LT |
1065 | /* Check for any FCP transport errors. */ |
1066 | if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) { | |
9a853f71 | 1067 | /* Sense data lies beyond any FCP RESPONSE data. */ |
e428924c | 1068 | if (IS_FWI2_CAPABLE(ha)) |
9a853f71 AV |
1069 | sense_data += rsp_info_len; |
1070 | if (rsp_info_len > 3 && rsp_info[3]) { | |
1da177e4 LT |
1071 | DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol " |
1072 | "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..." | |
e315cd28 | 1073 | "retrying command\n", vha->host_no, |
9a853f71 AV |
1074 | cp->device->channel, cp->device->id, |
1075 | cp->device->lun, rsp_info_len, rsp_info[0], | |
1076 | rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4], | |
1077 | rsp_info[5], rsp_info[6], rsp_info[7])); | |
1da177e4 LT |
1078 | |
1079 | cp->result = DID_BUS_BUSY << 16; | |
73208dfd | 1080 | qla2x00_sp_compl(ha, sp); |
1da177e4 LT |
1081 | return; |
1082 | } | |
1083 | } | |
1084 | ||
3e8ce320 AV |
1085 | /* Check for overrun. */ |
1086 | if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE && | |
1087 | scsi_status & SS_RESIDUAL_OVER) | |
1088 | comp_status = CS_DATA_OVERRUN; | |
1089 | ||
1da177e4 LT |
1090 | /* |
1091 | * Based on Host and scsi status generate status code for Linux | |
1092 | */ | |
1093 | switch (comp_status) { | |
1094 | case CS_COMPLETE: | |
df7baa50 | 1095 | case CS_QUEUE_FULL: |
1da177e4 LT |
1096 | if (scsi_status == 0) { |
1097 | cp->result = DID_OK << 16; | |
1098 | break; | |
1099 | } | |
1100 | if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) { | |
9a853f71 | 1101 | resid = resid_len; |
385d70b4 | 1102 | scsi_set_resid(cp, resid); |
0da69df1 AV |
1103 | |
1104 | if (!lscsi_status && | |
385d70b4 | 1105 | ((unsigned)(scsi_bufflen(cp) - resid) < |
0da69df1 AV |
1106 | cp->underflow)) { |
1107 | qla_printk(KERN_INFO, ha, | |
385d70b4 FT |
1108 | "scsi(%ld:%d:%d:%d): Mid-layer underflow " |
1109 | "detected (%x of %x bytes)...returning " | |
e315cd28 | 1110 | "error status.\n", vha->host_no, |
385d70b4 FT |
1111 | cp->device->channel, cp->device->id, |
1112 | cp->device->lun, resid, | |
1113 | scsi_bufflen(cp)); | |
0da69df1 AV |
1114 | |
1115 | cp->result = DID_ERROR << 16; | |
1116 | break; | |
1117 | } | |
1da177e4 | 1118 | } |
1da177e4 LT |
1119 | cp->result = DID_OK << 16 | lscsi_status; |
1120 | ||
df7baa50 AV |
1121 | if (lscsi_status == SAM_STAT_TASK_SET_FULL) { |
1122 | DEBUG2(printk(KERN_INFO | |
1123 | "scsi(%ld): QUEUE FULL status detected " | |
e315cd28 | 1124 | "0x%x-0x%x.\n", vha->host_no, comp_status, |
df7baa50 AV |
1125 | scsi_status)); |
1126 | ||
1127 | /* Adjust queue depth for all luns on the port. */ | |
1128 | fcport->last_queue_full = jiffies; | |
df7baa50 AV |
1129 | starget_for_each_device(cp->device->sdev_target, |
1130 | fcport, qla2x00_adjust_sdev_qdepth_down); | |
df7baa50 AV |
1131 | break; |
1132 | } | |
1da177e4 LT |
1133 | if (lscsi_status != SS_CHECK_CONDITION) |
1134 | break; | |
1135 | ||
b80ca4f7 | 1136 | memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); |
1da177e4 LT |
1137 | if (!(scsi_status & SS_SENSE_LEN_VALID)) |
1138 | break; | |
1139 | ||
2afa19a9 | 1140 | qla2x00_handle_sense(sp, sense_data, sense_len, rsp); |
1da177e4 LT |
1141 | break; |
1142 | ||
1143 | case CS_DATA_UNDERRUN: | |
9a853f71 | 1144 | resid = resid_len; |
ed17c71b | 1145 | /* Use F/W calculated residual length. */ |
6acf8190 | 1146 | if (IS_FWI2_CAPABLE(ha)) { |
2d136938 AV |
1147 | if (!(scsi_status & SS_RESIDUAL_UNDER)) { |
1148 | lscsi_status = 0; | |
1149 | } else if (resid != fw_resid_len) { | |
6acf8190 AV |
1150 | scsi_status &= ~SS_RESIDUAL_UNDER; |
1151 | lscsi_status = 0; | |
1152 | } | |
ed17c71b | 1153 | resid = fw_resid_len; |
6acf8190 | 1154 | } |
ed17c71b | 1155 | |
1da177e4 | 1156 | if (scsi_status & SS_RESIDUAL_UNDER) { |
385d70b4 | 1157 | scsi_set_resid(cp, resid); |
e038a1be AV |
1158 | } else { |
1159 | DEBUG2(printk(KERN_INFO | |
1160 | "scsi(%ld:%d:%d) UNDERRUN status detected " | |
ed17c71b | 1161 | "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x " |
e315cd28 | 1162 | "os_underflow=0x%x\n", vha->host_no, |
ed17c71b RA |
1163 | cp->device->id, cp->device->lun, comp_status, |
1164 | scsi_status, resid_len, resid, cp->cmnd[0], | |
1165 | cp->underflow)); | |
e038a1be | 1166 | |
1da177e4 LT |
1167 | } |
1168 | ||
1169 | /* | |
fa2a1ce5 | 1170 | * Check to see if SCSI Status is non zero. If so report SCSI |
1da177e4 LT |
1171 | * Status. |
1172 | */ | |
1173 | if (lscsi_status != 0) { | |
1da177e4 LT |
1174 | cp->result = DID_OK << 16 | lscsi_status; |
1175 | ||
ffec28a3 AV |
1176 | if (lscsi_status == SAM_STAT_TASK_SET_FULL) { |
1177 | DEBUG2(printk(KERN_INFO | |
1178 | "scsi(%ld): QUEUE FULL status detected " | |
e315cd28 | 1179 | "0x%x-0x%x.\n", vha->host_no, comp_status, |
ffec28a3 AV |
1180 | scsi_status)); |
1181 | ||
1182 | /* | |
1183 | * Adjust queue depth for all luns on the | |
1184 | * port. | |
1185 | */ | |
1186 | fcport->last_queue_full = jiffies; | |
1187 | starget_for_each_device( | |
1188 | cp->device->sdev_target, fcport, | |
1189 | qla2x00_adjust_sdev_qdepth_down); | |
1190 | break; | |
1191 | } | |
1da177e4 LT |
1192 | if (lscsi_status != SS_CHECK_CONDITION) |
1193 | break; | |
1194 | ||
b80ca4f7 | 1195 | memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); |
1da177e4 LT |
1196 | if (!(scsi_status & SS_SENSE_LEN_VALID)) |
1197 | break; | |
1198 | ||
2afa19a9 | 1199 | qla2x00_handle_sense(sp, sense_data, sense_len, rsp); |
1da177e4 LT |
1200 | } else { |
1201 | /* | |
1202 | * If RISC reports underrun and target does not report | |
1203 | * it then we must have a lost frame, so tell upper | |
1204 | * layer to retry it by reporting a bus busy. | |
1205 | */ | |
1206 | if (!(scsi_status & SS_RESIDUAL_UNDER)) { | |
1207 | DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped " | |
385d70b4 | 1208 | "frame(s) detected (%x of %x bytes)..." |
e315cd28 AC |
1209 | "retrying command.\n", |
1210 | vha->host_no, cp->device->channel, | |
1211 | cp->device->id, cp->device->lun, resid, | |
1212 | scsi_bufflen(cp))); | |
1da177e4 LT |
1213 | |
1214 | cp->result = DID_BUS_BUSY << 16; | |
1da177e4 LT |
1215 | break; |
1216 | } | |
1217 | ||
1218 | /* Handle mid-layer underflow */ | |
385d70b4 | 1219 | if ((unsigned)(scsi_bufflen(cp) - resid) < |
1da177e4 LT |
1220 | cp->underflow) { |
1221 | qla_printk(KERN_INFO, ha, | |
385d70b4 FT |
1222 | "scsi(%ld:%d:%d:%d): Mid-layer underflow " |
1223 | "detected (%x of %x bytes)...returning " | |
e315cd28 | 1224 | "error status.\n", vha->host_no, |
385d70b4 FT |
1225 | cp->device->channel, cp->device->id, |
1226 | cp->device->lun, resid, | |
1227 | scsi_bufflen(cp)); | |
1da177e4 LT |
1228 | |
1229 | cp->result = DID_ERROR << 16; | |
1230 | break; | |
1231 | } | |
1232 | ||
1233 | /* Everybody online, looking good... */ | |
1234 | cp->result = DID_OK << 16; | |
1235 | } | |
1236 | break; | |
1237 | ||
1238 | case CS_DATA_OVERRUN: | |
1239 | DEBUG2(printk(KERN_INFO | |
1240 | "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n", | |
e315cd28 | 1241 | vha->host_no, cp->device->id, cp->device->lun, comp_status, |
9a853f71 | 1242 | scsi_status)); |
1da177e4 LT |
1243 | DEBUG2(printk(KERN_INFO |
1244 | "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", | |
1245 | cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3], | |
1246 | cp->cmnd[4], cp->cmnd[5])); | |
1247 | DEBUG2(printk(KERN_INFO | |
1248 | "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR " | |
1249 | "status!\n", | |
385d70b4 | 1250 | cp->serial_number, scsi_bufflen(cp), resid_len)); |
1da177e4 LT |
1251 | |
1252 | cp->result = DID_ERROR << 16; | |
1253 | break; | |
1254 | ||
1255 | case CS_PORT_LOGGED_OUT: | |
1256 | case CS_PORT_CONFIG_CHG: | |
1257 | case CS_PORT_BUSY: | |
1258 | case CS_INCOMPLETE: | |
1259 | case CS_PORT_UNAVAILABLE: | |
1260 | /* | |
1261 | * If the port is in Target Down state, return all IOs for this | |
1262 | * Target with DID_NO_CONNECT ELSE Queue the IOs in the | |
1263 | * retry_queue. | |
1264 | */ | |
1da177e4 LT |
1265 | DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down " |
1266 | "pid=%ld, compl status=0x%x, port state=0x%x\n", | |
e315cd28 | 1267 | vha->host_no, cp->device->id, cp->device->lun, |
9a853f71 | 1268 | cp->serial_number, comp_status, |
1da177e4 LT |
1269 | atomic_read(&fcport->state))); |
1270 | ||
056a4483 MC |
1271 | /* |
1272 | * We are going to have the fc class block the rport | |
1273 | * while we try to recover so instruct the mid layer | |
1274 | * to requeue until the class decides how to handle this. | |
1275 | */ | |
1276 | cp->result = DID_TRANSPORT_DISRUPTED << 16; | |
a7a28504 | 1277 | if (atomic_read(&fcport->state) == FCS_ONLINE) |
e315cd28 | 1278 | qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1); |
1da177e4 LT |
1279 | break; |
1280 | ||
1281 | case CS_RESET: | |
1282 | DEBUG2(printk(KERN_INFO | |
1283 | "scsi(%ld): RESET status detected 0x%x-0x%x.\n", | |
e315cd28 | 1284 | vha->host_no, comp_status, scsi_status)); |
1da177e4 | 1285 | |
f4f051eb | 1286 | cp->result = DID_RESET << 16; |
1da177e4 LT |
1287 | break; |
1288 | ||
1289 | case CS_ABORTED: | |
fa2a1ce5 | 1290 | /* |
1da177e4 LT |
1291 | * hv2.19.12 - DID_ABORT does not retry the request if we |
1292 | * aborted this request then abort otherwise it must be a | |
1293 | * reset. | |
1294 | */ | |
1295 | DEBUG2(printk(KERN_INFO | |
1296 | "scsi(%ld): ABORT status detected 0x%x-0x%x.\n", | |
e315cd28 | 1297 | vha->host_no, comp_status, scsi_status)); |
1da177e4 LT |
1298 | |
1299 | cp->result = DID_RESET << 16; | |
1300 | break; | |
1301 | ||
1302 | case CS_TIMEOUT: | |
056a4483 MC |
1303 | /* |
1304 | * We are going to have the fc class block the rport | |
1305 | * while we try to recover so instruct the mid layer | |
1306 | * to requeue until the class decides how to handle this. | |
1307 | */ | |
1308 | cp->result = DID_TRANSPORT_DISRUPTED << 16; | |
9a853f71 | 1309 | |
e428924c | 1310 | if (IS_FWI2_CAPABLE(ha)) { |
9a853f71 AV |
1311 | DEBUG2(printk(KERN_INFO |
1312 | "scsi(%ld:%d:%d:%d): TIMEOUT status detected " | |
e315cd28 | 1313 | "0x%x-0x%x\n", vha->host_no, cp->device->channel, |
9a853f71 AV |
1314 | cp->device->id, cp->device->lun, comp_status, |
1315 | scsi_status)); | |
1316 | break; | |
1317 | } | |
1da177e4 LT |
1318 | DEBUG2(printk(KERN_INFO |
1319 | "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x " | |
e315cd28 | 1320 | "sflags=%x.\n", vha->host_no, cp->device->channel, |
9a853f71 AV |
1321 | cp->device->id, cp->device->lun, comp_status, scsi_status, |
1322 | le16_to_cpu(sts->status_flags))); | |
1da177e4 | 1323 | |
9a853f71 AV |
1324 | /* Check to see if logout occurred. */ |
1325 | if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT)) | |
e315cd28 | 1326 | qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1); |
1da177e4 LT |
1327 | break; |
1328 | ||
1da177e4 LT |
1329 | default: |
1330 | DEBUG3(printk("scsi(%ld): Error detected (unknown status) " | |
e315cd28 | 1331 | "0x%x-0x%x.\n", vha->host_no, comp_status, scsi_status)); |
1da177e4 LT |
1332 | qla_printk(KERN_INFO, ha, |
1333 | "Unknown status detected 0x%x-0x%x.\n", | |
1334 | comp_status, scsi_status); | |
1335 | ||
1336 | cp->result = DID_ERROR << 16; | |
1337 | break; | |
1338 | } | |
1339 | ||
1340 | /* Place command on done queue. */ | |
2afa19a9 | 1341 | if (rsp->status_srb == NULL) |
73208dfd | 1342 | qla2x00_sp_compl(ha, sp); |
1da177e4 LT |
1343 | } |
1344 | ||
1345 | /** | |
1346 | * qla2x00_status_cont_entry() - Process a Status Continuations entry. | |
1347 | * @ha: SCSI driver HA context | |
1348 | * @pkt: Entry pointer | |
1349 | * | |
1350 | * Extended sense data. | |
1351 | */ | |
1352 | static void | |
2afa19a9 | 1353 | qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt) |
1da177e4 LT |
1354 | { |
1355 | uint8_t sense_sz = 0; | |
2afa19a9 AC |
1356 | struct qla_hw_data *ha = rsp->hw; |
1357 | srb_t *sp = rsp->status_srb; | |
1da177e4 LT |
1358 | struct scsi_cmnd *cp; |
1359 | ||
1360 | if (sp != NULL && sp->request_sense_length != 0) { | |
1361 | cp = sp->cmd; | |
1362 | if (cp == NULL) { | |
1363 | DEBUG2(printk("%s(): Cmd already returned back to OS " | |
75bc4190 | 1364 | "sp=%p.\n", __func__, sp)); |
1da177e4 LT |
1365 | qla_printk(KERN_INFO, ha, |
1366 | "cmd is NULL: already returned to OS (sp=%p)\n", | |
fa2a1ce5 | 1367 | sp); |
1da177e4 | 1368 | |
2afa19a9 | 1369 | rsp->status_srb = NULL; |
1da177e4 LT |
1370 | return; |
1371 | } | |
1372 | ||
1373 | if (sp->request_sense_length > sizeof(pkt->data)) { | |
1374 | sense_sz = sizeof(pkt->data); | |
1375 | } else { | |
1376 | sense_sz = sp->request_sense_length; | |
1377 | } | |
1378 | ||
1379 | /* Move sense data. */ | |
e428924c | 1380 | if (IS_FWI2_CAPABLE(ha)) |
9a853f71 | 1381 | host_to_fcp_swap(pkt->data, sizeof(pkt->data)); |
1da177e4 LT |
1382 | memcpy(sp->request_sense_ptr, pkt->data, sense_sz); |
1383 | DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz)); | |
1384 | ||
1385 | sp->request_sense_ptr += sense_sz; | |
1386 | sp->request_sense_length -= sense_sz; | |
1387 | ||
1388 | /* Place command on done queue. */ | |
1389 | if (sp->request_sense_length == 0) { | |
2afa19a9 | 1390 | rsp->status_srb = NULL; |
73208dfd | 1391 | qla2x00_sp_compl(ha, sp); |
1da177e4 LT |
1392 | } |
1393 | } | |
1394 | } | |
1395 | ||
1396 | /** | |
1397 | * qla2x00_error_entry() - Process an error entry. | |
1398 | * @ha: SCSI driver HA context | |
1399 | * @pkt: Entry pointer | |
1400 | */ | |
1401 | static void | |
73208dfd | 1402 | qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt) |
1da177e4 LT |
1403 | { |
1404 | srb_t *sp; | |
e315cd28 | 1405 | struct qla_hw_data *ha = vha->hw; |
2afa19a9 AC |
1406 | uint32_t handle = LSW(pkt->handle); |
1407 | uint16_t que = MSW(pkt->handle); | |
1408 | struct req_que *req = ha->req_q_map[que]; | |
1da177e4 LT |
1409 | #if defined(QL_DEBUG_LEVEL_2) |
1410 | if (pkt->entry_status & RF_INV_E_ORDER) | |
1411 | qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__); | |
1412 | else if (pkt->entry_status & RF_INV_E_COUNT) | |
1413 | qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__); | |
1414 | else if (pkt->entry_status & RF_INV_E_PARAM) | |
fa2a1ce5 | 1415 | qla_printk(KERN_ERR, ha, |
1da177e4 LT |
1416 | "%s: Invalid Entry Parameter\n", __func__); |
1417 | else if (pkt->entry_status & RF_INV_E_TYPE) | |
1418 | qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__); | |
1419 | else if (pkt->entry_status & RF_BUSY) | |
1420 | qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__); | |
1421 | else | |
1422 | qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__); | |
1423 | #endif | |
1424 | ||
1425 | /* Validate handle. */ | |
2afa19a9 AC |
1426 | if (handle < MAX_OUTSTANDING_COMMANDS) |
1427 | sp = req->outstanding_cmds[handle]; | |
1da177e4 LT |
1428 | else |
1429 | sp = NULL; | |
1430 | ||
1431 | if (sp) { | |
1432 | /* Free outstanding command slot. */ | |
2afa19a9 | 1433 | req->outstanding_cmds[handle] = NULL; |
354d6b21 | 1434 | |
1da177e4 LT |
1435 | /* Bad payload or header */ |
1436 | if (pkt->entry_status & | |
1437 | (RF_INV_E_ORDER | RF_INV_E_COUNT | | |
1438 | RF_INV_E_PARAM | RF_INV_E_TYPE)) { | |
1439 | sp->cmd->result = DID_ERROR << 16; | |
1440 | } else if (pkt->entry_status & RF_BUSY) { | |
1441 | sp->cmd->result = DID_BUS_BUSY << 16; | |
1442 | } else { | |
1443 | sp->cmd->result = DID_ERROR << 16; | |
1444 | } | |
73208dfd | 1445 | qla2x00_sp_compl(ha, sp); |
1da177e4 | 1446 | |
9a853f71 AV |
1447 | } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type == |
1448 | COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) { | |
1da177e4 | 1449 | DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n", |
e315cd28 | 1450 | vha->host_no)); |
1da177e4 LT |
1451 | qla_printk(KERN_WARNING, ha, |
1452 | "Error entry - invalid handle\n"); | |
1453 | ||
e315cd28 AC |
1454 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
1455 | qla2xxx_wake_dpc(vha); | |
1da177e4 LT |
1456 | } |
1457 | } | |
1458 | ||
9a853f71 AV |
1459 | /** |
1460 | * qla24xx_mbx_completion() - Process mailbox command completions. | |
1461 | * @ha: SCSI driver HA context | |
1462 | * @mb0: Mailbox0 register | |
1463 | */ | |
1464 | static void | |
e315cd28 | 1465 | qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0) |
9a853f71 AV |
1466 | { |
1467 | uint16_t cnt; | |
1468 | uint16_t __iomem *wptr; | |
e315cd28 | 1469 | struct qla_hw_data *ha = vha->hw; |
9a853f71 AV |
1470 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
1471 | ||
1472 | /* Load return mailbox registers. */ | |
1473 | ha->flags.mbox_int = 1; | |
1474 | ha->mailbox_out[0] = mb0; | |
1475 | wptr = (uint16_t __iomem *)®->mailbox1; | |
1476 | ||
1477 | for (cnt = 1; cnt < ha->mbx_count; cnt++) { | |
1478 | ha->mailbox_out[cnt] = RD_REG_WORD(wptr); | |
1479 | wptr++; | |
1480 | } | |
1481 | ||
1482 | if (ha->mcp) { | |
1483 | DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n", | |
e315cd28 | 1484 | __func__, vha->host_no, ha->mcp->mb[0])); |
9a853f71 AV |
1485 | } else { |
1486 | DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n", | |
e315cd28 | 1487 | __func__, vha->host_no)); |
9a853f71 AV |
1488 | } |
1489 | } | |
1490 | ||
1491 | /** | |
1492 | * qla24xx_process_response_queue() - Process response queue entries. | |
1493 | * @ha: SCSI driver HA context | |
1494 | */ | |
2afa19a9 AC |
1495 | void qla24xx_process_response_queue(struct scsi_qla_host *vha, |
1496 | struct rsp_que *rsp) | |
9a853f71 | 1497 | { |
9a853f71 AV |
1498 | struct sts_entry_24xx *pkt; |
1499 | ||
e315cd28 | 1500 | if (!vha->flags.online) |
9a853f71 AV |
1501 | return; |
1502 | ||
e315cd28 AC |
1503 | while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) { |
1504 | pkt = (struct sts_entry_24xx *)rsp->ring_ptr; | |
9a853f71 | 1505 | |
e315cd28 AC |
1506 | rsp->ring_index++; |
1507 | if (rsp->ring_index == rsp->length) { | |
1508 | rsp->ring_index = 0; | |
1509 | rsp->ring_ptr = rsp->ring; | |
9a853f71 | 1510 | } else { |
e315cd28 | 1511 | rsp->ring_ptr++; |
9a853f71 AV |
1512 | } |
1513 | ||
1514 | if (pkt->entry_status != 0) { | |
1515 | DEBUG3(printk(KERN_INFO | |
e315cd28 | 1516 | "scsi(%ld): Process error entry.\n", vha->host_no)); |
9a853f71 | 1517 | |
73208dfd | 1518 | qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt); |
9a853f71 AV |
1519 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; |
1520 | wmb(); | |
1521 | continue; | |
1522 | } | |
1523 | ||
1524 | switch (pkt->entry_type) { | |
1525 | case STATUS_TYPE: | |
73208dfd | 1526 | qla2x00_status_entry(vha, rsp, pkt); |
9a853f71 AV |
1527 | break; |
1528 | case STATUS_CONT_TYPE: | |
2afa19a9 | 1529 | qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt); |
9a853f71 | 1530 | break; |
2c3dfe3f | 1531 | case VP_RPT_ID_IOCB_TYPE: |
e315cd28 | 1532 | qla24xx_report_id_acquisition(vha, |
2c3dfe3f SJ |
1533 | (struct vp_rpt_id_entry_24xx *)pkt); |
1534 | break; | |
9a853f71 AV |
1535 | default: |
1536 | /* Type Not Supported. */ | |
1537 | DEBUG4(printk(KERN_WARNING | |
1538 | "scsi(%ld): Received unknown response pkt type %x " | |
1539 | "entry status=%x.\n", | |
e315cd28 | 1540 | vha->host_no, pkt->entry_type, pkt->entry_status)); |
9a853f71 AV |
1541 | break; |
1542 | } | |
1543 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; | |
1544 | wmb(); | |
1545 | } | |
1546 | ||
1547 | /* Adjust ring index */ | |
08029990 | 1548 | WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index); |
9a853f71 AV |
1549 | } |
1550 | ||
05236a05 | 1551 | static void |
e315cd28 | 1552 | qla2xxx_check_risc_status(scsi_qla_host_t *vha) |
05236a05 AV |
1553 | { |
1554 | int rval; | |
1555 | uint32_t cnt; | |
e315cd28 | 1556 | struct qla_hw_data *ha = vha->hw; |
05236a05 AV |
1557 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
1558 | ||
3a03eb79 | 1559 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)) |
05236a05 AV |
1560 | return; |
1561 | ||
1562 | rval = QLA_SUCCESS; | |
1563 | WRT_REG_DWORD(®->iobase_addr, 0x7C00); | |
1564 | RD_REG_DWORD(®->iobase_addr); | |
1565 | WRT_REG_DWORD(®->iobase_window, 0x0001); | |
1566 | for (cnt = 10000; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 && | |
1567 | rval == QLA_SUCCESS; cnt--) { | |
1568 | if (cnt) { | |
1569 | WRT_REG_DWORD(®->iobase_window, 0x0001); | |
1570 | udelay(10); | |
1571 | } else | |
1572 | rval = QLA_FUNCTION_TIMEOUT; | |
1573 | } | |
1574 | if (rval == QLA_SUCCESS) | |
1575 | goto next_test; | |
1576 | ||
1577 | WRT_REG_DWORD(®->iobase_window, 0x0003); | |
1578 | for (cnt = 100; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 && | |
1579 | rval == QLA_SUCCESS; cnt--) { | |
1580 | if (cnt) { | |
1581 | WRT_REG_DWORD(®->iobase_window, 0x0003); | |
1582 | udelay(10); | |
1583 | } else | |
1584 | rval = QLA_FUNCTION_TIMEOUT; | |
1585 | } | |
1586 | if (rval != QLA_SUCCESS) | |
1587 | goto done; | |
1588 | ||
1589 | next_test: | |
1590 | if (RD_REG_DWORD(®->iobase_c8) & BIT_3) | |
1591 | qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n"); | |
1592 | ||
1593 | done: | |
1594 | WRT_REG_DWORD(®->iobase_window, 0x0000); | |
1595 | RD_REG_DWORD(®->iobase_window); | |
1596 | } | |
1597 | ||
9a853f71 AV |
1598 | /** |
1599 | * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx. | |
1600 | * @irq: | |
1601 | * @dev_id: SCSI driver HA context | |
9a853f71 AV |
1602 | * |
1603 | * Called by system whenever the host adapter generates an interrupt. | |
1604 | * | |
1605 | * Returns handled flag. | |
1606 | */ | |
1607 | irqreturn_t | |
7d12e780 | 1608 | qla24xx_intr_handler(int irq, void *dev_id) |
9a853f71 | 1609 | { |
e315cd28 AC |
1610 | scsi_qla_host_t *vha; |
1611 | struct qla_hw_data *ha; | |
9a853f71 AV |
1612 | struct device_reg_24xx __iomem *reg; |
1613 | int status; | |
9a853f71 AV |
1614 | unsigned long iter; |
1615 | uint32_t stat; | |
1616 | uint32_t hccr; | |
1617 | uint16_t mb[4]; | |
e315cd28 | 1618 | struct rsp_que *rsp; |
9a853f71 | 1619 | |
e315cd28 AC |
1620 | rsp = (struct rsp_que *) dev_id; |
1621 | if (!rsp) { | |
9a853f71 | 1622 | printk(KERN_INFO |
e315cd28 | 1623 | "%s(): NULL response queue pointer\n", __func__); |
9a853f71 AV |
1624 | return IRQ_NONE; |
1625 | } | |
1626 | ||
e315cd28 | 1627 | ha = rsp->hw; |
9a853f71 AV |
1628 | reg = &ha->iobase->isp24; |
1629 | status = 0; | |
1630 | ||
c6952483 | 1631 | spin_lock(&ha->hardware_lock); |
2afa19a9 | 1632 | vha = pci_get_drvdata(ha->pdev); |
9a853f71 AV |
1633 | for (iter = 50; iter--; ) { |
1634 | stat = RD_REG_DWORD(®->host_status); | |
1635 | if (stat & HSRX_RISC_PAUSED) { | |
14e660e6 SJ |
1636 | if (pci_channel_offline(ha->pdev)) |
1637 | break; | |
1638 | ||
9a853f71 AV |
1639 | hccr = RD_REG_DWORD(®->hccr); |
1640 | ||
1641 | qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, " | |
1642 | "Dumping firmware!\n", hccr); | |
05236a05 | 1643 | |
e315cd28 | 1644 | qla2xxx_check_risc_status(vha); |
05236a05 | 1645 | |
e315cd28 AC |
1646 | ha->isp_ops->fw_dump(vha, 1); |
1647 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
9a853f71 AV |
1648 | break; |
1649 | } else if ((stat & HSRX_RISC_INT) == 0) | |
1650 | break; | |
1651 | ||
1652 | switch (stat & 0xff) { | |
1653 | case 0x1: | |
1654 | case 0x2: | |
1655 | case 0x10: | |
1656 | case 0x11: | |
e315cd28 | 1657 | qla24xx_mbx_completion(vha, MSW(stat)); |
9a853f71 AV |
1658 | status |= MBX_INTERRUPT; |
1659 | ||
1660 | break; | |
1661 | case 0x12: | |
1662 | mb[0] = MSW(stat); | |
1663 | mb[1] = RD_REG_WORD(®->mailbox1); | |
1664 | mb[2] = RD_REG_WORD(®->mailbox2); | |
1665 | mb[3] = RD_REG_WORD(®->mailbox3); | |
73208dfd | 1666 | qla2x00_async_event(vha, rsp, mb); |
9a853f71 AV |
1667 | break; |
1668 | case 0x13: | |
73208dfd | 1669 | case 0x14: |
2afa19a9 | 1670 | qla24xx_process_response_queue(vha, rsp); |
9a853f71 AV |
1671 | break; |
1672 | default: | |
1673 | DEBUG2(printk("scsi(%ld): Unrecognized interrupt type " | |
1674 | "(%d).\n", | |
e315cd28 | 1675 | vha->host_no, stat & 0xff)); |
9a853f71 AV |
1676 | break; |
1677 | } | |
1678 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT); | |
1679 | RD_REG_DWORD_RELAXED(®->hccr); | |
1680 | } | |
c6952483 | 1681 | spin_unlock(&ha->hardware_lock); |
9a853f71 AV |
1682 | |
1683 | if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) && | |
1684 | (status & MBX_INTERRUPT) && ha->flags.mbox_int) { | |
9a853f71 | 1685 | set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); |
0b05a1f0 | 1686 | complete(&ha->mbx_intr_comp); |
9a853f71 AV |
1687 | } |
1688 | ||
1689 | return IRQ_HANDLED; | |
1690 | } | |
1691 | ||
a8488abe AV |
1692 | static irqreturn_t |
1693 | qla24xx_msix_rsp_q(int irq, void *dev_id) | |
1694 | { | |
e315cd28 AC |
1695 | struct qla_hw_data *ha; |
1696 | struct rsp_que *rsp; | |
a8488abe | 1697 | struct device_reg_24xx __iomem *reg; |
2afa19a9 | 1698 | struct scsi_qla_host *vha; |
a8488abe | 1699 | |
e315cd28 AC |
1700 | rsp = (struct rsp_que *) dev_id; |
1701 | if (!rsp) { | |
1702 | printk(KERN_INFO | |
1703 | "%s(): NULL response queue pointer\n", __func__); | |
1704 | return IRQ_NONE; | |
1705 | } | |
1706 | ha = rsp->hw; | |
a8488abe AV |
1707 | reg = &ha->iobase->isp24; |
1708 | ||
0e973a24 | 1709 | spin_lock_irq(&ha->hardware_lock); |
a8488abe | 1710 | |
2afa19a9 AC |
1711 | vha = qla25xx_get_host(rsp); |
1712 | qla24xx_process_response_queue(vha, rsp); | |
a8488abe | 1713 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT); |
a8488abe | 1714 | |
0e973a24 | 1715 | spin_unlock_irq(&ha->hardware_lock); |
a8488abe AV |
1716 | |
1717 | return IRQ_HANDLED; | |
1718 | } | |
1719 | ||
68ca949c AC |
1720 | static irqreturn_t |
1721 | qla25xx_msix_rsp_q(int irq, void *dev_id) | |
1722 | { | |
1723 | struct qla_hw_data *ha; | |
1724 | struct rsp_que *rsp; | |
1725 | ||
1726 | rsp = (struct rsp_que *) dev_id; | |
1727 | if (!rsp) { | |
1728 | printk(KERN_INFO | |
1729 | "%s(): NULL response queue pointer\n", __func__); | |
1730 | return IRQ_NONE; | |
1731 | } | |
1732 | ha = rsp->hw; | |
1733 | ||
1734 | queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work); | |
1735 | ||
1736 | return IRQ_HANDLED; | |
1737 | } | |
1738 | ||
a8488abe AV |
1739 | static irqreturn_t |
1740 | qla24xx_msix_default(int irq, void *dev_id) | |
1741 | { | |
e315cd28 AC |
1742 | scsi_qla_host_t *vha; |
1743 | struct qla_hw_data *ha; | |
1744 | struct rsp_que *rsp; | |
a8488abe AV |
1745 | struct device_reg_24xx __iomem *reg; |
1746 | int status; | |
a8488abe AV |
1747 | uint32_t stat; |
1748 | uint32_t hccr; | |
1749 | uint16_t mb[4]; | |
1750 | ||
e315cd28 AC |
1751 | rsp = (struct rsp_que *) dev_id; |
1752 | if (!rsp) { | |
1753 | DEBUG(printk( | |
1754 | "%s(): NULL response queue pointer\n", __func__)); | |
1755 | return IRQ_NONE; | |
1756 | } | |
1757 | ha = rsp->hw; | |
a8488abe AV |
1758 | reg = &ha->iobase->isp24; |
1759 | status = 0; | |
1760 | ||
0e973a24 | 1761 | spin_lock_irq(&ha->hardware_lock); |
2afa19a9 | 1762 | vha = pci_get_drvdata(ha->pdev); |
87f27015 | 1763 | do { |
a8488abe AV |
1764 | stat = RD_REG_DWORD(®->host_status); |
1765 | if (stat & HSRX_RISC_PAUSED) { | |
14e660e6 SJ |
1766 | if (pci_channel_offline(ha->pdev)) |
1767 | break; | |
1768 | ||
a8488abe AV |
1769 | hccr = RD_REG_DWORD(®->hccr); |
1770 | ||
1771 | qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, " | |
1772 | "Dumping firmware!\n", hccr); | |
05236a05 | 1773 | |
e315cd28 | 1774 | qla2xxx_check_risc_status(vha); |
05236a05 | 1775 | |
e315cd28 AC |
1776 | ha->isp_ops->fw_dump(vha, 1); |
1777 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
a8488abe AV |
1778 | break; |
1779 | } else if ((stat & HSRX_RISC_INT) == 0) | |
1780 | break; | |
1781 | ||
1782 | switch (stat & 0xff) { | |
1783 | case 0x1: | |
1784 | case 0x2: | |
1785 | case 0x10: | |
1786 | case 0x11: | |
e315cd28 | 1787 | qla24xx_mbx_completion(vha, MSW(stat)); |
a8488abe AV |
1788 | status |= MBX_INTERRUPT; |
1789 | ||
1790 | break; | |
1791 | case 0x12: | |
1792 | mb[0] = MSW(stat); | |
1793 | mb[1] = RD_REG_WORD(®->mailbox1); | |
1794 | mb[2] = RD_REG_WORD(®->mailbox2); | |
1795 | mb[3] = RD_REG_WORD(®->mailbox3); | |
73208dfd | 1796 | qla2x00_async_event(vha, rsp, mb); |
a8488abe AV |
1797 | break; |
1798 | case 0x13: | |
73208dfd | 1799 | case 0x14: |
2afa19a9 | 1800 | qla24xx_process_response_queue(vha, rsp); |
a8488abe AV |
1801 | break; |
1802 | default: | |
1803 | DEBUG2(printk("scsi(%ld): Unrecognized interrupt type " | |
1804 | "(%d).\n", | |
e315cd28 | 1805 | vha->host_no, stat & 0xff)); |
a8488abe AV |
1806 | break; |
1807 | } | |
1808 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT); | |
87f27015 | 1809 | } while (0); |
0e973a24 | 1810 | spin_unlock_irq(&ha->hardware_lock); |
a8488abe AV |
1811 | |
1812 | if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) && | |
1813 | (status & MBX_INTERRUPT) && ha->flags.mbox_int) { | |
a8488abe | 1814 | set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); |
0b05a1f0 | 1815 | complete(&ha->mbx_intr_comp); |
a8488abe AV |
1816 | } |
1817 | ||
1818 | return IRQ_HANDLED; | |
1819 | } | |
1820 | ||
1821 | /* Interrupt handling helpers. */ | |
1822 | ||
1823 | struct qla_init_msix_entry { | |
a8488abe | 1824 | const char *name; |
476834c2 | 1825 | irq_handler_t handler; |
a8488abe AV |
1826 | }; |
1827 | ||
68ca949c | 1828 | static struct qla_init_msix_entry msix_entries[3] = { |
2afa19a9 AC |
1829 | { "qla2xxx (default)", qla24xx_msix_default }, |
1830 | { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q }, | |
68ca949c | 1831 | { "qla2xxx (multiq)", qla25xx_msix_rsp_q }, |
a8488abe AV |
1832 | }; |
1833 | ||
1834 | static void | |
e315cd28 | 1835 | qla24xx_disable_msix(struct qla_hw_data *ha) |
a8488abe AV |
1836 | { |
1837 | int i; | |
1838 | struct qla_msix_entry *qentry; | |
1839 | ||
73208dfd AC |
1840 | for (i = 0; i < ha->msix_count; i++) { |
1841 | qentry = &ha->msix_entries[i]; | |
a8488abe | 1842 | if (qentry->have_irq) |
73208dfd | 1843 | free_irq(qentry->vector, qentry->rsp); |
a8488abe AV |
1844 | } |
1845 | pci_disable_msix(ha->pdev); | |
73208dfd AC |
1846 | kfree(ha->msix_entries); |
1847 | ha->msix_entries = NULL; | |
1848 | ha->flags.msix_enabled = 0; | |
a8488abe AV |
1849 | } |
1850 | ||
1851 | static int | |
73208dfd | 1852 | qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp) |
a8488abe | 1853 | { |
ad038fa8 | 1854 | #define MIN_MSIX_COUNT 2 |
a8488abe | 1855 | int i, ret; |
73208dfd | 1856 | struct msix_entry *entries; |
a8488abe | 1857 | struct qla_msix_entry *qentry; |
73208dfd AC |
1858 | |
1859 | entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count, | |
1860 | GFP_KERNEL); | |
1861 | if (!entries) | |
1862 | return -ENOMEM; | |
a8488abe | 1863 | |
73208dfd AC |
1864 | for (i = 0; i < ha->msix_count; i++) |
1865 | entries[i].entry = i; | |
a8488abe | 1866 | |
73208dfd | 1867 | ret = pci_enable_msix(ha->pdev, entries, ha->msix_count); |
a8488abe | 1868 | if (ret) { |
ad038fa8 LC |
1869 | if (ret < MIN_MSIX_COUNT) |
1870 | goto msix_failed; | |
1871 | ||
a8488abe | 1872 | qla_printk(KERN_WARNING, ha, |
73208dfd AC |
1873 | "MSI-X: Failed to enable support -- %d/%d\n" |
1874 | " Retry with %d vectors\n", ha->msix_count, ret, ret); | |
1875 | ha->msix_count = ret; | |
1876 | ret = pci_enable_msix(ha->pdev, entries, ha->msix_count); | |
1877 | if (ret) { | |
ad038fa8 | 1878 | msix_failed: |
73208dfd AC |
1879 | qla_printk(KERN_WARNING, ha, "MSI-X: Failed to enable" |
1880 | " support, giving up -- %d/%d\n", | |
1881 | ha->msix_count, ret); | |
1882 | goto msix_out; | |
1883 | } | |
2afa19a9 | 1884 | ha->max_rsp_queues = ha->msix_count - 1; |
73208dfd AC |
1885 | } |
1886 | ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) * | |
1887 | ha->msix_count, GFP_KERNEL); | |
1888 | if (!ha->msix_entries) { | |
1889 | ret = -ENOMEM; | |
a8488abe AV |
1890 | goto msix_out; |
1891 | } | |
1892 | ha->flags.msix_enabled = 1; | |
1893 | ||
73208dfd AC |
1894 | for (i = 0; i < ha->msix_count; i++) { |
1895 | qentry = &ha->msix_entries[i]; | |
1896 | qentry->vector = entries[i].vector; | |
1897 | qentry->entry = entries[i].entry; | |
a8488abe | 1898 | qentry->have_irq = 0; |
73208dfd | 1899 | qentry->rsp = NULL; |
a8488abe AV |
1900 | } |
1901 | ||
2afa19a9 AC |
1902 | /* Enable MSI-X vectors for the base queue */ |
1903 | for (i = 0; i < 2; i++) { | |
1904 | qentry = &ha->msix_entries[i]; | |
1905 | ret = request_irq(qentry->vector, msix_entries[i].handler, | |
1906 | 0, msix_entries[i].name, rsp); | |
1907 | if (ret) { | |
1908 | qla_printk(KERN_WARNING, ha, | |
73208dfd AC |
1909 | "MSI-X: Unable to register handler -- %x/%d.\n", |
1910 | qentry->vector, ret); | |
2afa19a9 AC |
1911 | qla24xx_disable_msix(ha); |
1912 | ha->mqenable = 0; | |
1913 | goto msix_out; | |
1914 | } | |
1915 | qentry->have_irq = 1; | |
1916 | qentry->rsp = rsp; | |
1917 | rsp->msix = qentry; | |
73208dfd | 1918 | } |
73208dfd AC |
1919 | |
1920 | /* Enable MSI-X vector for response queue update for queue 0 */ | |
2afa19a9 | 1921 | if (ha->mqiobase && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1)) |
73208dfd | 1922 | ha->mqenable = 1; |
73208dfd | 1923 | |
a8488abe | 1924 | msix_out: |
73208dfd | 1925 | kfree(entries); |
a8488abe AV |
1926 | return ret; |
1927 | } | |
1928 | ||
1929 | int | |
73208dfd | 1930 | qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp) |
a8488abe AV |
1931 | { |
1932 | int ret; | |
963b0fdd | 1933 | device_reg_t __iomem *reg = ha->iobase; |
a8488abe AV |
1934 | |
1935 | /* If possible, enable MSI-X. */ | |
3a03eb79 AV |
1936 | if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && |
1937 | !IS_QLA8432(ha) && !IS_QLA8001(ha)) | |
a8488abe AV |
1938 | goto skip_msix; |
1939 | ||
e315cd28 AC |
1940 | if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX || |
1941 | !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) { | |
a8488abe | 1942 | DEBUG2(qla_printk(KERN_WARNING, ha, |
e315cd28 AC |
1943 | "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n", |
1944 | ha->pdev->revision, ha->fw_attributes)); | |
a8488abe AV |
1945 | |
1946 | goto skip_msix; | |
1947 | } | |
1948 | ||
da7429f9 AV |
1949 | if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP && |
1950 | (ha->pdev->subsystem_device == 0x7040 || | |
1951 | ha->pdev->subsystem_device == 0x7041 || | |
1952 | ha->pdev->subsystem_device == 0x1705)) { | |
1953 | DEBUG2(qla_printk(KERN_WARNING, ha, | |
1954 | "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n", | |
1955 | ha->pdev->subsystem_vendor, | |
1956 | ha->pdev->subsystem_device)); | |
1957 | ||
1958 | goto skip_msi; | |
1959 | } | |
1960 | ||
73208dfd | 1961 | ret = qla24xx_enable_msix(ha, rsp); |
a8488abe AV |
1962 | if (!ret) { |
1963 | DEBUG2(qla_printk(KERN_INFO, ha, | |
1964 | "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision, | |
1965 | ha->fw_attributes)); | |
963b0fdd | 1966 | goto clear_risc_ints; |
a8488abe AV |
1967 | } |
1968 | qla_printk(KERN_WARNING, ha, | |
1969 | "MSI-X: Falling back-to INTa mode -- %d.\n", ret); | |
1970 | skip_msix: | |
cbedb601 | 1971 | |
3a03eb79 AV |
1972 | if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) && |
1973 | !IS_QLA8001(ha)) | |
cbedb601 AV |
1974 | goto skip_msi; |
1975 | ||
1976 | ret = pci_enable_msi(ha->pdev); | |
1977 | if (!ret) { | |
1978 | DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n")); | |
1979 | ha->flags.msi_enabled = 1; | |
1980 | } | |
1981 | skip_msi: | |
1982 | ||
fd34f556 | 1983 | ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler, |
d1b1bef4 | 1984 | IRQF_SHARED, QLA2XXX_DRIVER_NAME, rsp); |
963b0fdd | 1985 | if (ret) { |
a8488abe AV |
1986 | qla_printk(KERN_WARNING, ha, |
1987 | "Failed to reserve interrupt %d already in use.\n", | |
1988 | ha->pdev->irq); | |
963b0fdd AV |
1989 | goto fail; |
1990 | } | |
1991 | ha->flags.inta_enabled = 1; | |
963b0fdd AV |
1992 | clear_risc_ints: |
1993 | ||
3a03eb79 AV |
1994 | /* |
1995 | * FIXME: Noted that 8014s were being dropped during NK testing. | |
1996 | * Timing deltas during MSI-X/INTa transitions? | |
1997 | */ | |
1998 | if (IS_QLA81XX(ha)) | |
1999 | goto fail; | |
c6952483 | 2000 | spin_lock_irq(&ha->hardware_lock); |
963b0fdd AV |
2001 | if (IS_FWI2_CAPABLE(ha)) { |
2002 | WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_HOST_INT); | |
2003 | WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_RISC_INT); | |
2004 | } else { | |
2005 | WRT_REG_WORD(®->isp.semaphore, 0); | |
2006 | WRT_REG_WORD(®->isp.hccr, HCCR_CLR_RISC_INT); | |
2007 | WRT_REG_WORD(®->isp.hccr, HCCR_CLR_HOST_INT); | |
a8488abe | 2008 | } |
c6952483 | 2009 | spin_unlock_irq(&ha->hardware_lock); |
a8488abe | 2010 | |
963b0fdd | 2011 | fail: |
a8488abe AV |
2012 | return ret; |
2013 | } | |
2014 | ||
2015 | void | |
e315cd28 | 2016 | qla2x00_free_irqs(scsi_qla_host_t *vha) |
a8488abe | 2017 | { |
e315cd28 | 2018 | struct qla_hw_data *ha = vha->hw; |
73208dfd | 2019 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
a8488abe AV |
2020 | |
2021 | if (ha->flags.msix_enabled) | |
2022 | qla24xx_disable_msix(ha); | |
cbedb601 | 2023 | else if (ha->flags.inta_enabled) { |
e315cd28 | 2024 | free_irq(ha->pdev->irq, rsp); |
cbedb601 AV |
2025 | pci_disable_msi(ha->pdev); |
2026 | } | |
a8488abe | 2027 | } |
e315cd28 | 2028 | |
73208dfd AC |
2029 | |
2030 | int qla25xx_request_irq(struct rsp_que *rsp) | |
2031 | { | |
2032 | struct qla_hw_data *ha = rsp->hw; | |
2afa19a9 | 2033 | struct qla_init_msix_entry *intr = &msix_entries[2]; |
73208dfd AC |
2034 | struct qla_msix_entry *msix = rsp->msix; |
2035 | int ret; | |
2036 | ||
2037 | ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp); | |
2038 | if (ret) { | |
2039 | qla_printk(KERN_WARNING, ha, | |
2040 | "MSI-X: Unable to register handler -- %x/%d.\n", | |
2041 | msix->vector, ret); | |
2042 | return ret; | |
2043 | } | |
2044 | msix->have_irq = 1; | |
2045 | msix->rsp = rsp; | |
2046 | return ret; | |
2047 | } | |
2afa19a9 AC |
2048 | |
2049 | struct scsi_qla_host * | |
2050 | qla25xx_get_host(struct rsp_que *rsp) | |
2051 | { | |
2052 | srb_t *sp; | |
2053 | struct qla_hw_data *ha = rsp->hw; | |
2054 | struct scsi_qla_host *vha = NULL; | |
2055 | struct sts_entry_24xx *pkt; | |
2056 | struct req_que *req; | |
2057 | uint16_t que; | |
2058 | uint32_t handle; | |
2059 | ||
2060 | pkt = (struct sts_entry_24xx *) rsp->ring_ptr; | |
2061 | que = MSW(pkt->handle); | |
2062 | handle = (uint32_t) LSW(pkt->handle); | |
2063 | req = ha->req_q_map[que]; | |
2064 | if (handle < MAX_OUTSTANDING_COMMANDS) { | |
2065 | sp = req->outstanding_cmds[handle]; | |
2066 | if (sp) | |
2067 | return sp->fcport->vha; | |
2068 | else | |
2069 | goto base_que; | |
2070 | } | |
2071 | base_que: | |
2072 | vha = pci_get_drvdata(ha->pdev); | |
2073 | return vha; | |
2074 | } |