]>
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 | ||
a13d8ac0 MR |
768 | if (!ql2xqfulltracking) |
769 | return; | |
770 | ||
2afa19a9 | 771 | req = vha->req; |
73208dfd AC |
772 | if (!req) |
773 | return; | |
774 | if (req->max_q_depth <= sdev->queue_depth) | |
df7baa50 AV |
775 | return; |
776 | ||
777 | if (sdev->ordered_tags) | |
778 | scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, | |
779 | sdev->queue_depth + 1); | |
780 | else | |
781 | scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, | |
782 | sdev->queue_depth + 1); | |
783 | ||
784 | fcport->last_ramp_up = jiffies; | |
785 | ||
e315cd28 | 786 | DEBUG2(qla_printk(KERN_INFO, ha, |
df7baa50 | 787 | "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n", |
e315cd28 | 788 | fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun, |
df7baa50 AV |
789 | sdev->queue_depth)); |
790 | } | |
791 | ||
792 | static void | |
793 | qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data) | |
794 | { | |
795 | fc_port_t *fcport = data; | |
796 | ||
797 | if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1)) | |
798 | return; | |
799 | ||
e315cd28 | 800 | DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw, |
df7baa50 | 801 | "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n", |
e315cd28 | 802 | fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun, |
df7baa50 AV |
803 | sdev->queue_depth)); |
804 | } | |
805 | ||
806 | static inline void | |
73208dfd AC |
807 | qla2x00_ramp_up_queue_depth(scsi_qla_host_t *vha, struct req_que *req, |
808 | srb_t *sp) | |
df7baa50 AV |
809 | { |
810 | fc_port_t *fcport; | |
811 | struct scsi_device *sdev; | |
812 | ||
a13d8ac0 MR |
813 | if (!ql2xqfulltracking) |
814 | return; | |
815 | ||
df7baa50 | 816 | sdev = sp->cmd->device; |
73208dfd | 817 | if (sdev->queue_depth >= req->max_q_depth) |
df7baa50 AV |
818 | return; |
819 | ||
820 | fcport = sp->fcport; | |
821 | if (time_before(jiffies, | |
822 | fcport->last_ramp_up + ql2xqfullrampup * HZ)) | |
823 | return; | |
824 | if (time_before(jiffies, | |
825 | fcport->last_queue_full + ql2xqfullrampup * HZ)) | |
826 | return; | |
827 | ||
df7baa50 AV |
828 | starget_for_each_device(sdev->sdev_target, fcport, |
829 | qla2x00_adjust_sdev_qdepth_up); | |
df7baa50 AV |
830 | } |
831 | ||
1da177e4 LT |
832 | /** |
833 | * qla2x00_process_completed_request() - Process a Fast Post response. | |
834 | * @ha: SCSI driver HA context | |
835 | * @index: SRB index | |
836 | */ | |
837 | static void | |
73208dfd AC |
838 | qla2x00_process_completed_request(struct scsi_qla_host *vha, |
839 | struct req_que *req, uint32_t index) | |
1da177e4 LT |
840 | { |
841 | srb_t *sp; | |
e315cd28 | 842 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
843 | |
844 | /* Validate handle. */ | |
845 | if (index >= MAX_OUTSTANDING_COMMANDS) { | |
846 | DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n", | |
e315cd28 | 847 | vha->host_no, index)); |
1da177e4 LT |
848 | qla_printk(KERN_WARNING, ha, |
849 | "Invalid SCSI completion handle %d.\n", index); | |
850 | ||
e315cd28 | 851 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
1da177e4 LT |
852 | return; |
853 | } | |
854 | ||
e315cd28 | 855 | sp = req->outstanding_cmds[index]; |
1da177e4 LT |
856 | if (sp) { |
857 | /* Free outstanding command slot. */ | |
e315cd28 | 858 | req->outstanding_cmds[index] = NULL; |
1da177e4 | 859 | |
1da177e4 LT |
860 | /* Save ISP completion status */ |
861 | sp->cmd->result = DID_OK << 16; | |
df7baa50 | 862 | |
73208dfd AC |
863 | qla2x00_ramp_up_queue_depth(vha, req, sp); |
864 | qla2x00_sp_compl(ha, sp); | |
1da177e4 | 865 | } else { |
2afa19a9 AC |
866 | DEBUG2(printk("scsi(%ld) Req:%d: Invalid ISP SCSI completion" |
867 | " handle(%d)\n", vha->host_no, req->id, index)); | |
1da177e4 LT |
868 | qla_printk(KERN_WARNING, ha, |
869 | "Invalid ISP SCSI completion handle\n"); | |
870 | ||
e315cd28 | 871 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
1da177e4 LT |
872 | } |
873 | } | |
874 | ||
875 | /** | |
876 | * qla2x00_process_response_queue() - Process response queue entries. | |
877 | * @ha: SCSI driver HA context | |
878 | */ | |
879 | void | |
73208dfd | 880 | qla2x00_process_response_queue(struct rsp_que *rsp) |
1da177e4 | 881 | { |
73208dfd AC |
882 | struct scsi_qla_host *vha; |
883 | struct qla_hw_data *ha = rsp->hw; | |
3d71644c | 884 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
1da177e4 LT |
885 | sts_entry_t *pkt; |
886 | uint16_t handle_cnt; | |
887 | uint16_t cnt; | |
73208dfd | 888 | |
2afa19a9 | 889 | vha = pci_get_drvdata(ha->pdev); |
1da177e4 | 890 | |
e315cd28 | 891 | if (!vha->flags.online) |
1da177e4 LT |
892 | return; |
893 | ||
e315cd28 AC |
894 | while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) { |
895 | pkt = (sts_entry_t *)rsp->ring_ptr; | |
1da177e4 | 896 | |
e315cd28 AC |
897 | rsp->ring_index++; |
898 | if (rsp->ring_index == rsp->length) { | |
899 | rsp->ring_index = 0; | |
900 | rsp->ring_ptr = rsp->ring; | |
1da177e4 | 901 | } else { |
e315cd28 | 902 | rsp->ring_ptr++; |
1da177e4 LT |
903 | } |
904 | ||
905 | if (pkt->entry_status != 0) { | |
906 | DEBUG3(printk(KERN_INFO | |
e315cd28 | 907 | "scsi(%ld): Process error entry.\n", vha->host_no)); |
1da177e4 | 908 | |
73208dfd | 909 | qla2x00_error_entry(vha, rsp, pkt); |
1da177e4 LT |
910 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; |
911 | wmb(); | |
912 | continue; | |
913 | } | |
914 | ||
915 | switch (pkt->entry_type) { | |
916 | case STATUS_TYPE: | |
73208dfd | 917 | qla2x00_status_entry(vha, rsp, pkt); |
1da177e4 LT |
918 | break; |
919 | case STATUS_TYPE_21: | |
920 | handle_cnt = ((sts21_entry_t *)pkt)->handle_count; | |
921 | for (cnt = 0; cnt < handle_cnt; cnt++) { | |
73208dfd | 922 | qla2x00_process_completed_request(vha, rsp->req, |
1da177e4 LT |
923 | ((sts21_entry_t *)pkt)->handle[cnt]); |
924 | } | |
925 | break; | |
926 | case STATUS_TYPE_22: | |
927 | handle_cnt = ((sts22_entry_t *)pkt)->handle_count; | |
928 | for (cnt = 0; cnt < handle_cnt; cnt++) { | |
73208dfd | 929 | qla2x00_process_completed_request(vha, rsp->req, |
1da177e4 LT |
930 | ((sts22_entry_t *)pkt)->handle[cnt]); |
931 | } | |
932 | break; | |
933 | case STATUS_CONT_TYPE: | |
2afa19a9 | 934 | qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt); |
1da177e4 | 935 | break; |
1da177e4 LT |
936 | default: |
937 | /* Type Not Supported. */ | |
938 | DEBUG4(printk(KERN_WARNING | |
939 | "scsi(%ld): Received unknown response pkt type %x " | |
940 | "entry status=%x.\n", | |
e315cd28 | 941 | vha->host_no, pkt->entry_type, pkt->entry_status)); |
1da177e4 LT |
942 | break; |
943 | } | |
944 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; | |
945 | wmb(); | |
946 | } | |
947 | ||
948 | /* Adjust ring index */ | |
e315cd28 | 949 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index); |
1da177e4 LT |
950 | } |
951 | ||
4733fcb1 | 952 | static inline void |
2afa19a9 AC |
953 | qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len, |
954 | struct rsp_que *rsp) | |
4733fcb1 AV |
955 | { |
956 | struct scsi_cmnd *cp = sp->cmd; | |
957 | ||
958 | if (sense_len >= SCSI_SENSE_BUFFERSIZE) | |
959 | sense_len = SCSI_SENSE_BUFFERSIZE; | |
960 | ||
4733fcb1 AV |
961 | sp->request_sense_length = sense_len; |
962 | sp->request_sense_ptr = cp->sense_buffer; | |
963 | if (sp->request_sense_length > 32) | |
964 | sense_len = 32; | |
965 | ||
966 | memcpy(cp->sense_buffer, sense_data, sense_len); | |
967 | ||
968 | sp->request_sense_ptr += sense_len; | |
969 | sp->request_sense_length -= sense_len; | |
970 | if (sp->request_sense_length != 0) | |
2afa19a9 | 971 | rsp->status_srb = sp; |
4733fcb1 AV |
972 | |
973 | DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) " | |
e315cd28 | 974 | "cmd=%p pid=%ld\n", __func__, sp->fcport->vha->host_no, |
19851f13 AV |
975 | cp->device->channel, cp->device->id, cp->device->lun, cp, |
976 | cp->serial_number)); | |
4733fcb1 | 977 | if (sense_len) |
ddb9b126 | 978 | DEBUG5(qla2x00_dump_buffer(cp->sense_buffer, sense_len)); |
4733fcb1 AV |
979 | } |
980 | ||
1da177e4 LT |
981 | /** |
982 | * qla2x00_status_entry() - Process a Status IOCB entry. | |
983 | * @ha: SCSI driver HA context | |
984 | * @pkt: Entry pointer | |
985 | */ | |
986 | static void | |
73208dfd | 987 | qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt) |
1da177e4 | 988 | { |
1da177e4 | 989 | srb_t *sp; |
1da177e4 LT |
990 | fc_port_t *fcport; |
991 | struct scsi_cmnd *cp; | |
9a853f71 AV |
992 | sts_entry_t *sts; |
993 | struct sts_entry_24xx *sts24; | |
1da177e4 LT |
994 | uint16_t comp_status; |
995 | uint16_t scsi_status; | |
996 | uint8_t lscsi_status; | |
997 | int32_t resid; | |
ed17c71b | 998 | uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len; |
9a853f71 | 999 | uint8_t *rsp_info, *sense_data; |
e315cd28 | 1000 | struct qla_hw_data *ha = vha->hw; |
2afa19a9 AC |
1001 | uint32_t handle; |
1002 | uint16_t que; | |
1003 | struct req_que *req; | |
9a853f71 AV |
1004 | |
1005 | sts = (sts_entry_t *) pkt; | |
1006 | sts24 = (struct sts_entry_24xx *) pkt; | |
e428924c | 1007 | if (IS_FWI2_CAPABLE(ha)) { |
9a853f71 AV |
1008 | comp_status = le16_to_cpu(sts24->comp_status); |
1009 | scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK; | |
1010 | } else { | |
1011 | comp_status = le16_to_cpu(sts->comp_status); | |
1012 | scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK; | |
1013 | } | |
2afa19a9 AC |
1014 | handle = (uint32_t) LSW(sts->handle); |
1015 | que = MSW(sts->handle); | |
1016 | req = ha->req_q_map[que]; | |
1da177e4 | 1017 | /* Fast path completion. */ |
9a853f71 | 1018 | if (comp_status == CS_COMPLETE && scsi_status == 0) { |
2afa19a9 | 1019 | qla2x00_process_completed_request(vha, req, handle); |
1da177e4 LT |
1020 | |
1021 | return; | |
1022 | } | |
1023 | ||
1024 | /* Validate handle. */ | |
2afa19a9 AC |
1025 | if (handle < MAX_OUTSTANDING_COMMANDS) { |
1026 | sp = req->outstanding_cmds[handle]; | |
1027 | req->outstanding_cmds[handle] = NULL; | |
1da177e4 LT |
1028 | } else |
1029 | sp = NULL; | |
1030 | ||
1031 | if (sp == NULL) { | |
1032 | DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n", | |
e315cd28 | 1033 | vha->host_no)); |
1da177e4 LT |
1034 | qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n"); |
1035 | ||
e315cd28 AC |
1036 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
1037 | qla2xxx_wake_dpc(vha); | |
1da177e4 LT |
1038 | return; |
1039 | } | |
1040 | cp = sp->cmd; | |
1041 | if (cp == NULL) { | |
1042 | DEBUG2(printk("scsi(%ld): Command already returned back to OS " | |
2afa19a9 | 1043 | "pkt->handle=%d sp=%p.\n", vha->host_no, handle, sp)); |
1da177e4 LT |
1044 | qla_printk(KERN_WARNING, ha, |
1045 | "Command is NULL: already returned to OS (sp=%p)\n", sp); | |
1046 | ||
1047 | return; | |
1048 | } | |
1049 | ||
9a853f71 | 1050 | lscsi_status = scsi_status & STATUS_MASK; |
1da177e4 | 1051 | |
bdf79621 | 1052 | fcport = sp->fcport; |
1da177e4 | 1053 | |
ed17c71b | 1054 | sense_len = rsp_info_len = resid_len = fw_resid_len = 0; |
e428924c | 1055 | if (IS_FWI2_CAPABLE(ha)) { |
9a853f71 AV |
1056 | sense_len = le32_to_cpu(sts24->sense_len); |
1057 | rsp_info_len = le32_to_cpu(sts24->rsp_data_len); | |
1058 | resid_len = le32_to_cpu(sts24->rsp_residual_count); | |
ed17c71b | 1059 | fw_resid_len = le32_to_cpu(sts24->residual_len); |
9a853f71 AV |
1060 | rsp_info = sts24->data; |
1061 | sense_data = sts24->data; | |
1062 | host_to_fcp_swap(sts24->data, sizeof(sts24->data)); | |
1063 | } else { | |
1064 | sense_len = le16_to_cpu(sts->req_sense_length); | |
1065 | rsp_info_len = le16_to_cpu(sts->rsp_info_len); | |
1066 | resid_len = le32_to_cpu(sts->residual_length); | |
1067 | rsp_info = sts->rsp_info; | |
1068 | sense_data = sts->req_sense_data; | |
1069 | } | |
1070 | ||
1da177e4 LT |
1071 | /* Check for any FCP transport errors. */ |
1072 | if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) { | |
9a853f71 | 1073 | /* Sense data lies beyond any FCP RESPONSE data. */ |
e428924c | 1074 | if (IS_FWI2_CAPABLE(ha)) |
9a853f71 AV |
1075 | sense_data += rsp_info_len; |
1076 | if (rsp_info_len > 3 && rsp_info[3]) { | |
1da177e4 LT |
1077 | DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol " |
1078 | "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..." | |
e315cd28 | 1079 | "retrying command\n", vha->host_no, |
9a853f71 AV |
1080 | cp->device->channel, cp->device->id, |
1081 | cp->device->lun, rsp_info_len, rsp_info[0], | |
1082 | rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4], | |
1083 | rsp_info[5], rsp_info[6], rsp_info[7])); | |
1da177e4 LT |
1084 | |
1085 | cp->result = DID_BUS_BUSY << 16; | |
73208dfd | 1086 | qla2x00_sp_compl(ha, sp); |
1da177e4 LT |
1087 | return; |
1088 | } | |
1089 | } | |
1090 | ||
3e8ce320 AV |
1091 | /* Check for overrun. */ |
1092 | if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE && | |
1093 | scsi_status & SS_RESIDUAL_OVER) | |
1094 | comp_status = CS_DATA_OVERRUN; | |
1095 | ||
1da177e4 LT |
1096 | /* |
1097 | * Based on Host and scsi status generate status code for Linux | |
1098 | */ | |
1099 | switch (comp_status) { | |
1100 | case CS_COMPLETE: | |
df7baa50 | 1101 | case CS_QUEUE_FULL: |
1da177e4 LT |
1102 | if (scsi_status == 0) { |
1103 | cp->result = DID_OK << 16; | |
1104 | break; | |
1105 | } | |
1106 | if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) { | |
9a853f71 | 1107 | resid = resid_len; |
385d70b4 | 1108 | scsi_set_resid(cp, resid); |
0da69df1 AV |
1109 | |
1110 | if (!lscsi_status && | |
385d70b4 | 1111 | ((unsigned)(scsi_bufflen(cp) - resid) < |
0da69df1 AV |
1112 | cp->underflow)) { |
1113 | qla_printk(KERN_INFO, ha, | |
385d70b4 FT |
1114 | "scsi(%ld:%d:%d:%d): Mid-layer underflow " |
1115 | "detected (%x of %x bytes)...returning " | |
e315cd28 | 1116 | "error status.\n", vha->host_no, |
385d70b4 FT |
1117 | cp->device->channel, cp->device->id, |
1118 | cp->device->lun, resid, | |
1119 | scsi_bufflen(cp)); | |
0da69df1 AV |
1120 | |
1121 | cp->result = DID_ERROR << 16; | |
1122 | break; | |
1123 | } | |
1da177e4 | 1124 | } |
1da177e4 LT |
1125 | cp->result = DID_OK << 16 | lscsi_status; |
1126 | ||
df7baa50 AV |
1127 | if (lscsi_status == SAM_STAT_TASK_SET_FULL) { |
1128 | DEBUG2(printk(KERN_INFO | |
1129 | "scsi(%ld): QUEUE FULL status detected " | |
e315cd28 | 1130 | "0x%x-0x%x.\n", vha->host_no, comp_status, |
df7baa50 AV |
1131 | scsi_status)); |
1132 | ||
1133 | /* Adjust queue depth for all luns on the port. */ | |
a13d8ac0 MR |
1134 | if (!ql2xqfulltracking) |
1135 | break; | |
df7baa50 | 1136 | fcport->last_queue_full = jiffies; |
df7baa50 AV |
1137 | starget_for_each_device(cp->device->sdev_target, |
1138 | fcport, qla2x00_adjust_sdev_qdepth_down); | |
df7baa50 AV |
1139 | break; |
1140 | } | |
1da177e4 LT |
1141 | if (lscsi_status != SS_CHECK_CONDITION) |
1142 | break; | |
1143 | ||
b80ca4f7 | 1144 | memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); |
1da177e4 LT |
1145 | if (!(scsi_status & SS_SENSE_LEN_VALID)) |
1146 | break; | |
1147 | ||
2afa19a9 | 1148 | qla2x00_handle_sense(sp, sense_data, sense_len, rsp); |
1da177e4 LT |
1149 | break; |
1150 | ||
1151 | case CS_DATA_UNDERRUN: | |
9a853f71 | 1152 | resid = resid_len; |
ed17c71b | 1153 | /* Use F/W calculated residual length. */ |
6acf8190 | 1154 | if (IS_FWI2_CAPABLE(ha)) { |
2d136938 AV |
1155 | if (!(scsi_status & SS_RESIDUAL_UNDER)) { |
1156 | lscsi_status = 0; | |
1157 | } else if (resid != fw_resid_len) { | |
6acf8190 AV |
1158 | scsi_status &= ~SS_RESIDUAL_UNDER; |
1159 | lscsi_status = 0; | |
1160 | } | |
ed17c71b | 1161 | resid = fw_resid_len; |
6acf8190 | 1162 | } |
ed17c71b | 1163 | |
1da177e4 | 1164 | if (scsi_status & SS_RESIDUAL_UNDER) { |
385d70b4 | 1165 | scsi_set_resid(cp, resid); |
e038a1be AV |
1166 | } else { |
1167 | DEBUG2(printk(KERN_INFO | |
1168 | "scsi(%ld:%d:%d) UNDERRUN status detected " | |
ed17c71b | 1169 | "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x " |
e315cd28 | 1170 | "os_underflow=0x%x\n", vha->host_no, |
ed17c71b RA |
1171 | cp->device->id, cp->device->lun, comp_status, |
1172 | scsi_status, resid_len, resid, cp->cmnd[0], | |
1173 | cp->underflow)); | |
e038a1be | 1174 | |
1da177e4 LT |
1175 | } |
1176 | ||
1177 | /* | |
fa2a1ce5 | 1178 | * Check to see if SCSI Status is non zero. If so report SCSI |
1da177e4 LT |
1179 | * Status. |
1180 | */ | |
1181 | if (lscsi_status != 0) { | |
1da177e4 LT |
1182 | cp->result = DID_OK << 16 | lscsi_status; |
1183 | ||
ffec28a3 AV |
1184 | if (lscsi_status == SAM_STAT_TASK_SET_FULL) { |
1185 | DEBUG2(printk(KERN_INFO | |
1186 | "scsi(%ld): QUEUE FULL status detected " | |
e315cd28 | 1187 | "0x%x-0x%x.\n", vha->host_no, comp_status, |
ffec28a3 AV |
1188 | scsi_status)); |
1189 | ||
1190 | /* | |
1191 | * Adjust queue depth for all luns on the | |
1192 | * port. | |
1193 | */ | |
a13d8ac0 MR |
1194 | if (!ql2xqfulltracking) |
1195 | break; | |
ffec28a3 AV |
1196 | fcport->last_queue_full = jiffies; |
1197 | starget_for_each_device( | |
1198 | cp->device->sdev_target, fcport, | |
1199 | qla2x00_adjust_sdev_qdepth_down); | |
1200 | break; | |
1201 | } | |
1da177e4 LT |
1202 | if (lscsi_status != SS_CHECK_CONDITION) |
1203 | break; | |
1204 | ||
b80ca4f7 | 1205 | memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); |
1da177e4 LT |
1206 | if (!(scsi_status & SS_SENSE_LEN_VALID)) |
1207 | break; | |
1208 | ||
2afa19a9 | 1209 | qla2x00_handle_sense(sp, sense_data, sense_len, rsp); |
1da177e4 LT |
1210 | } else { |
1211 | /* | |
1212 | * If RISC reports underrun and target does not report | |
1213 | * it then we must have a lost frame, so tell upper | |
1214 | * layer to retry it by reporting a bus busy. | |
1215 | */ | |
1216 | if (!(scsi_status & SS_RESIDUAL_UNDER)) { | |
1217 | DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped " | |
385d70b4 | 1218 | "frame(s) detected (%x of %x bytes)..." |
e315cd28 AC |
1219 | "retrying command.\n", |
1220 | vha->host_no, cp->device->channel, | |
1221 | cp->device->id, cp->device->lun, resid, | |
1222 | scsi_bufflen(cp))); | |
1da177e4 LT |
1223 | |
1224 | cp->result = DID_BUS_BUSY << 16; | |
1da177e4 LT |
1225 | break; |
1226 | } | |
1227 | ||
1228 | /* Handle mid-layer underflow */ | |
385d70b4 | 1229 | if ((unsigned)(scsi_bufflen(cp) - resid) < |
1da177e4 LT |
1230 | cp->underflow) { |
1231 | qla_printk(KERN_INFO, ha, | |
385d70b4 FT |
1232 | "scsi(%ld:%d:%d:%d): Mid-layer underflow " |
1233 | "detected (%x of %x bytes)...returning " | |
e315cd28 | 1234 | "error status.\n", vha->host_no, |
385d70b4 FT |
1235 | cp->device->channel, cp->device->id, |
1236 | cp->device->lun, resid, | |
1237 | scsi_bufflen(cp)); | |
1da177e4 LT |
1238 | |
1239 | cp->result = DID_ERROR << 16; | |
1240 | break; | |
1241 | } | |
1242 | ||
1243 | /* Everybody online, looking good... */ | |
1244 | cp->result = DID_OK << 16; | |
1245 | } | |
1246 | break; | |
1247 | ||
1248 | case CS_DATA_OVERRUN: | |
1249 | DEBUG2(printk(KERN_INFO | |
1250 | "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n", | |
e315cd28 | 1251 | vha->host_no, cp->device->id, cp->device->lun, comp_status, |
9a853f71 | 1252 | scsi_status)); |
1da177e4 LT |
1253 | DEBUG2(printk(KERN_INFO |
1254 | "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", | |
1255 | cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3], | |
1256 | cp->cmnd[4], cp->cmnd[5])); | |
1257 | DEBUG2(printk(KERN_INFO | |
1258 | "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR " | |
1259 | "status!\n", | |
385d70b4 | 1260 | cp->serial_number, scsi_bufflen(cp), resid_len)); |
1da177e4 LT |
1261 | |
1262 | cp->result = DID_ERROR << 16; | |
1263 | break; | |
1264 | ||
1265 | case CS_PORT_LOGGED_OUT: | |
1266 | case CS_PORT_CONFIG_CHG: | |
1267 | case CS_PORT_BUSY: | |
1268 | case CS_INCOMPLETE: | |
1269 | case CS_PORT_UNAVAILABLE: | |
1270 | /* | |
1271 | * If the port is in Target Down state, return all IOs for this | |
1272 | * Target with DID_NO_CONNECT ELSE Queue the IOs in the | |
1273 | * retry_queue. | |
1274 | */ | |
1da177e4 LT |
1275 | DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down " |
1276 | "pid=%ld, compl status=0x%x, port state=0x%x\n", | |
e315cd28 | 1277 | vha->host_no, cp->device->id, cp->device->lun, |
9a853f71 | 1278 | cp->serial_number, comp_status, |
1da177e4 LT |
1279 | atomic_read(&fcport->state))); |
1280 | ||
056a4483 MC |
1281 | /* |
1282 | * We are going to have the fc class block the rport | |
1283 | * while we try to recover so instruct the mid layer | |
1284 | * to requeue until the class decides how to handle this. | |
1285 | */ | |
1286 | cp->result = DID_TRANSPORT_DISRUPTED << 16; | |
a7a28504 | 1287 | if (atomic_read(&fcport->state) == FCS_ONLINE) |
e315cd28 | 1288 | qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1); |
1da177e4 LT |
1289 | break; |
1290 | ||
1291 | case CS_RESET: | |
1292 | DEBUG2(printk(KERN_INFO | |
1293 | "scsi(%ld): RESET status detected 0x%x-0x%x.\n", | |
e315cd28 | 1294 | vha->host_no, comp_status, scsi_status)); |
1da177e4 | 1295 | |
f4f051eb | 1296 | cp->result = DID_RESET << 16; |
1da177e4 LT |
1297 | break; |
1298 | ||
1299 | case CS_ABORTED: | |
fa2a1ce5 | 1300 | /* |
1da177e4 LT |
1301 | * hv2.19.12 - DID_ABORT does not retry the request if we |
1302 | * aborted this request then abort otherwise it must be a | |
1303 | * reset. | |
1304 | */ | |
1305 | DEBUG2(printk(KERN_INFO | |
1306 | "scsi(%ld): ABORT status detected 0x%x-0x%x.\n", | |
e315cd28 | 1307 | vha->host_no, comp_status, scsi_status)); |
1da177e4 LT |
1308 | |
1309 | cp->result = DID_RESET << 16; | |
1310 | break; | |
1311 | ||
1312 | case CS_TIMEOUT: | |
056a4483 MC |
1313 | /* |
1314 | * We are going to have the fc class block the rport | |
1315 | * while we try to recover so instruct the mid layer | |
1316 | * to requeue until the class decides how to handle this. | |
1317 | */ | |
1318 | cp->result = DID_TRANSPORT_DISRUPTED << 16; | |
9a853f71 | 1319 | |
e428924c | 1320 | if (IS_FWI2_CAPABLE(ha)) { |
9a853f71 AV |
1321 | DEBUG2(printk(KERN_INFO |
1322 | "scsi(%ld:%d:%d:%d): TIMEOUT status detected " | |
e315cd28 | 1323 | "0x%x-0x%x\n", vha->host_no, cp->device->channel, |
9a853f71 AV |
1324 | cp->device->id, cp->device->lun, comp_status, |
1325 | scsi_status)); | |
1326 | break; | |
1327 | } | |
1da177e4 LT |
1328 | DEBUG2(printk(KERN_INFO |
1329 | "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x " | |
e315cd28 | 1330 | "sflags=%x.\n", vha->host_no, cp->device->channel, |
9a853f71 AV |
1331 | cp->device->id, cp->device->lun, comp_status, scsi_status, |
1332 | le16_to_cpu(sts->status_flags))); | |
1da177e4 | 1333 | |
9a853f71 AV |
1334 | /* Check to see if logout occurred. */ |
1335 | if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT)) | |
e315cd28 | 1336 | qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1); |
1da177e4 LT |
1337 | break; |
1338 | ||
1da177e4 LT |
1339 | default: |
1340 | DEBUG3(printk("scsi(%ld): Error detected (unknown status) " | |
e315cd28 | 1341 | "0x%x-0x%x.\n", vha->host_no, comp_status, scsi_status)); |
1da177e4 LT |
1342 | qla_printk(KERN_INFO, ha, |
1343 | "Unknown status detected 0x%x-0x%x.\n", | |
1344 | comp_status, scsi_status); | |
1345 | ||
1346 | cp->result = DID_ERROR << 16; | |
1347 | break; | |
1348 | } | |
1349 | ||
1350 | /* Place command on done queue. */ | |
2afa19a9 | 1351 | if (rsp->status_srb == NULL) |
73208dfd | 1352 | qla2x00_sp_compl(ha, sp); |
1da177e4 LT |
1353 | } |
1354 | ||
1355 | /** | |
1356 | * qla2x00_status_cont_entry() - Process a Status Continuations entry. | |
1357 | * @ha: SCSI driver HA context | |
1358 | * @pkt: Entry pointer | |
1359 | * | |
1360 | * Extended sense data. | |
1361 | */ | |
1362 | static void | |
2afa19a9 | 1363 | qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt) |
1da177e4 LT |
1364 | { |
1365 | uint8_t sense_sz = 0; | |
2afa19a9 AC |
1366 | struct qla_hw_data *ha = rsp->hw; |
1367 | srb_t *sp = rsp->status_srb; | |
1da177e4 LT |
1368 | struct scsi_cmnd *cp; |
1369 | ||
1370 | if (sp != NULL && sp->request_sense_length != 0) { | |
1371 | cp = sp->cmd; | |
1372 | if (cp == NULL) { | |
1373 | DEBUG2(printk("%s(): Cmd already returned back to OS " | |
75bc4190 | 1374 | "sp=%p.\n", __func__, sp)); |
1da177e4 LT |
1375 | qla_printk(KERN_INFO, ha, |
1376 | "cmd is NULL: already returned to OS (sp=%p)\n", | |
fa2a1ce5 | 1377 | sp); |
1da177e4 | 1378 | |
2afa19a9 | 1379 | rsp->status_srb = NULL; |
1da177e4 LT |
1380 | return; |
1381 | } | |
1382 | ||
1383 | if (sp->request_sense_length > sizeof(pkt->data)) { | |
1384 | sense_sz = sizeof(pkt->data); | |
1385 | } else { | |
1386 | sense_sz = sp->request_sense_length; | |
1387 | } | |
1388 | ||
1389 | /* Move sense data. */ | |
e428924c | 1390 | if (IS_FWI2_CAPABLE(ha)) |
9a853f71 | 1391 | host_to_fcp_swap(pkt->data, sizeof(pkt->data)); |
1da177e4 LT |
1392 | memcpy(sp->request_sense_ptr, pkt->data, sense_sz); |
1393 | DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz)); | |
1394 | ||
1395 | sp->request_sense_ptr += sense_sz; | |
1396 | sp->request_sense_length -= sense_sz; | |
1397 | ||
1398 | /* Place command on done queue. */ | |
1399 | if (sp->request_sense_length == 0) { | |
2afa19a9 | 1400 | rsp->status_srb = NULL; |
73208dfd | 1401 | qla2x00_sp_compl(ha, sp); |
1da177e4 LT |
1402 | } |
1403 | } | |
1404 | } | |
1405 | ||
1406 | /** | |
1407 | * qla2x00_error_entry() - Process an error entry. | |
1408 | * @ha: SCSI driver HA context | |
1409 | * @pkt: Entry pointer | |
1410 | */ | |
1411 | static void | |
73208dfd | 1412 | qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt) |
1da177e4 LT |
1413 | { |
1414 | srb_t *sp; | |
e315cd28 | 1415 | struct qla_hw_data *ha = vha->hw; |
2afa19a9 AC |
1416 | uint32_t handle = LSW(pkt->handle); |
1417 | uint16_t que = MSW(pkt->handle); | |
1418 | struct req_que *req = ha->req_q_map[que]; | |
1da177e4 LT |
1419 | #if defined(QL_DEBUG_LEVEL_2) |
1420 | if (pkt->entry_status & RF_INV_E_ORDER) | |
1421 | qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__); | |
1422 | else if (pkt->entry_status & RF_INV_E_COUNT) | |
1423 | qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__); | |
1424 | else if (pkt->entry_status & RF_INV_E_PARAM) | |
fa2a1ce5 | 1425 | qla_printk(KERN_ERR, ha, |
1da177e4 LT |
1426 | "%s: Invalid Entry Parameter\n", __func__); |
1427 | else if (pkt->entry_status & RF_INV_E_TYPE) | |
1428 | qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__); | |
1429 | else if (pkt->entry_status & RF_BUSY) | |
1430 | qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__); | |
1431 | else | |
1432 | qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__); | |
1433 | #endif | |
1434 | ||
1435 | /* Validate handle. */ | |
2afa19a9 AC |
1436 | if (handle < MAX_OUTSTANDING_COMMANDS) |
1437 | sp = req->outstanding_cmds[handle]; | |
1da177e4 LT |
1438 | else |
1439 | sp = NULL; | |
1440 | ||
1441 | if (sp) { | |
1442 | /* Free outstanding command slot. */ | |
2afa19a9 | 1443 | req->outstanding_cmds[handle] = NULL; |
354d6b21 | 1444 | |
1da177e4 LT |
1445 | /* Bad payload or header */ |
1446 | if (pkt->entry_status & | |
1447 | (RF_INV_E_ORDER | RF_INV_E_COUNT | | |
1448 | RF_INV_E_PARAM | RF_INV_E_TYPE)) { | |
1449 | sp->cmd->result = DID_ERROR << 16; | |
1450 | } else if (pkt->entry_status & RF_BUSY) { | |
1451 | sp->cmd->result = DID_BUS_BUSY << 16; | |
1452 | } else { | |
1453 | sp->cmd->result = DID_ERROR << 16; | |
1454 | } | |
73208dfd | 1455 | qla2x00_sp_compl(ha, sp); |
1da177e4 | 1456 | |
9a853f71 AV |
1457 | } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type == |
1458 | COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) { | |
1da177e4 | 1459 | DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n", |
e315cd28 | 1460 | vha->host_no)); |
1da177e4 LT |
1461 | qla_printk(KERN_WARNING, ha, |
1462 | "Error entry - invalid handle\n"); | |
1463 | ||
e315cd28 AC |
1464 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
1465 | qla2xxx_wake_dpc(vha); | |
1da177e4 LT |
1466 | } |
1467 | } | |
1468 | ||
9a853f71 AV |
1469 | /** |
1470 | * qla24xx_mbx_completion() - Process mailbox command completions. | |
1471 | * @ha: SCSI driver HA context | |
1472 | * @mb0: Mailbox0 register | |
1473 | */ | |
1474 | static void | |
e315cd28 | 1475 | qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0) |
9a853f71 AV |
1476 | { |
1477 | uint16_t cnt; | |
1478 | uint16_t __iomem *wptr; | |
e315cd28 | 1479 | struct qla_hw_data *ha = vha->hw; |
9a853f71 AV |
1480 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
1481 | ||
1482 | /* Load return mailbox registers. */ | |
1483 | ha->flags.mbox_int = 1; | |
1484 | ha->mailbox_out[0] = mb0; | |
1485 | wptr = (uint16_t __iomem *)®->mailbox1; | |
1486 | ||
1487 | for (cnt = 1; cnt < ha->mbx_count; cnt++) { | |
1488 | ha->mailbox_out[cnt] = RD_REG_WORD(wptr); | |
1489 | wptr++; | |
1490 | } | |
1491 | ||
1492 | if (ha->mcp) { | |
1493 | DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n", | |
e315cd28 | 1494 | __func__, vha->host_no, ha->mcp->mb[0])); |
9a853f71 AV |
1495 | } else { |
1496 | DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n", | |
e315cd28 | 1497 | __func__, vha->host_no)); |
9a853f71 AV |
1498 | } |
1499 | } | |
1500 | ||
1501 | /** | |
1502 | * qla24xx_process_response_queue() - Process response queue entries. | |
1503 | * @ha: SCSI driver HA context | |
1504 | */ | |
2afa19a9 AC |
1505 | void qla24xx_process_response_queue(struct scsi_qla_host *vha, |
1506 | struct rsp_que *rsp) | |
9a853f71 | 1507 | { |
9a853f71 AV |
1508 | struct sts_entry_24xx *pkt; |
1509 | ||
e315cd28 | 1510 | if (!vha->flags.online) |
9a853f71 AV |
1511 | return; |
1512 | ||
e315cd28 AC |
1513 | while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) { |
1514 | pkt = (struct sts_entry_24xx *)rsp->ring_ptr; | |
9a853f71 | 1515 | |
e315cd28 AC |
1516 | rsp->ring_index++; |
1517 | if (rsp->ring_index == rsp->length) { | |
1518 | rsp->ring_index = 0; | |
1519 | rsp->ring_ptr = rsp->ring; | |
9a853f71 | 1520 | } else { |
e315cd28 | 1521 | rsp->ring_ptr++; |
9a853f71 AV |
1522 | } |
1523 | ||
1524 | if (pkt->entry_status != 0) { | |
1525 | DEBUG3(printk(KERN_INFO | |
e315cd28 | 1526 | "scsi(%ld): Process error entry.\n", vha->host_no)); |
9a853f71 | 1527 | |
73208dfd | 1528 | qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt); |
9a853f71 AV |
1529 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; |
1530 | wmb(); | |
1531 | continue; | |
1532 | } | |
1533 | ||
1534 | switch (pkt->entry_type) { | |
1535 | case STATUS_TYPE: | |
73208dfd | 1536 | qla2x00_status_entry(vha, rsp, pkt); |
9a853f71 AV |
1537 | break; |
1538 | case STATUS_CONT_TYPE: | |
2afa19a9 | 1539 | qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt); |
9a853f71 | 1540 | break; |
2c3dfe3f | 1541 | case VP_RPT_ID_IOCB_TYPE: |
e315cd28 | 1542 | qla24xx_report_id_acquisition(vha, |
2c3dfe3f SJ |
1543 | (struct vp_rpt_id_entry_24xx *)pkt); |
1544 | break; | |
9a853f71 AV |
1545 | default: |
1546 | /* Type Not Supported. */ | |
1547 | DEBUG4(printk(KERN_WARNING | |
1548 | "scsi(%ld): Received unknown response pkt type %x " | |
1549 | "entry status=%x.\n", | |
e315cd28 | 1550 | vha->host_no, pkt->entry_type, pkt->entry_status)); |
9a853f71 AV |
1551 | break; |
1552 | } | |
1553 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; | |
1554 | wmb(); | |
1555 | } | |
1556 | ||
1557 | /* Adjust ring index */ | |
08029990 | 1558 | WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index); |
9a853f71 AV |
1559 | } |
1560 | ||
05236a05 | 1561 | static void |
e315cd28 | 1562 | qla2xxx_check_risc_status(scsi_qla_host_t *vha) |
05236a05 AV |
1563 | { |
1564 | int rval; | |
1565 | uint32_t cnt; | |
e315cd28 | 1566 | struct qla_hw_data *ha = vha->hw; |
05236a05 AV |
1567 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
1568 | ||
3a03eb79 | 1569 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)) |
05236a05 AV |
1570 | return; |
1571 | ||
1572 | rval = QLA_SUCCESS; | |
1573 | WRT_REG_DWORD(®->iobase_addr, 0x7C00); | |
1574 | RD_REG_DWORD(®->iobase_addr); | |
1575 | WRT_REG_DWORD(®->iobase_window, 0x0001); | |
1576 | for (cnt = 10000; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 && | |
1577 | rval == QLA_SUCCESS; cnt--) { | |
1578 | if (cnt) { | |
1579 | WRT_REG_DWORD(®->iobase_window, 0x0001); | |
1580 | udelay(10); | |
1581 | } else | |
1582 | rval = QLA_FUNCTION_TIMEOUT; | |
1583 | } | |
1584 | if (rval == QLA_SUCCESS) | |
1585 | goto next_test; | |
1586 | ||
1587 | WRT_REG_DWORD(®->iobase_window, 0x0003); | |
1588 | for (cnt = 100; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 && | |
1589 | rval == QLA_SUCCESS; cnt--) { | |
1590 | if (cnt) { | |
1591 | WRT_REG_DWORD(®->iobase_window, 0x0003); | |
1592 | udelay(10); | |
1593 | } else | |
1594 | rval = QLA_FUNCTION_TIMEOUT; | |
1595 | } | |
1596 | if (rval != QLA_SUCCESS) | |
1597 | goto done; | |
1598 | ||
1599 | next_test: | |
1600 | if (RD_REG_DWORD(®->iobase_c8) & BIT_3) | |
1601 | qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n"); | |
1602 | ||
1603 | done: | |
1604 | WRT_REG_DWORD(®->iobase_window, 0x0000); | |
1605 | RD_REG_DWORD(®->iobase_window); | |
1606 | } | |
1607 | ||
9a853f71 AV |
1608 | /** |
1609 | * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx. | |
1610 | * @irq: | |
1611 | * @dev_id: SCSI driver HA context | |
9a853f71 AV |
1612 | * |
1613 | * Called by system whenever the host adapter generates an interrupt. | |
1614 | * | |
1615 | * Returns handled flag. | |
1616 | */ | |
1617 | irqreturn_t | |
7d12e780 | 1618 | qla24xx_intr_handler(int irq, void *dev_id) |
9a853f71 | 1619 | { |
e315cd28 AC |
1620 | scsi_qla_host_t *vha; |
1621 | struct qla_hw_data *ha; | |
9a853f71 AV |
1622 | struct device_reg_24xx __iomem *reg; |
1623 | int status; | |
9a853f71 AV |
1624 | unsigned long iter; |
1625 | uint32_t stat; | |
1626 | uint32_t hccr; | |
1627 | uint16_t mb[4]; | |
e315cd28 | 1628 | struct rsp_que *rsp; |
9a853f71 | 1629 | |
e315cd28 AC |
1630 | rsp = (struct rsp_que *) dev_id; |
1631 | if (!rsp) { | |
9a853f71 | 1632 | printk(KERN_INFO |
e315cd28 | 1633 | "%s(): NULL response queue pointer\n", __func__); |
9a853f71 AV |
1634 | return IRQ_NONE; |
1635 | } | |
1636 | ||
e315cd28 | 1637 | ha = rsp->hw; |
9a853f71 AV |
1638 | reg = &ha->iobase->isp24; |
1639 | status = 0; | |
1640 | ||
c6952483 | 1641 | spin_lock(&ha->hardware_lock); |
2afa19a9 | 1642 | vha = pci_get_drvdata(ha->pdev); |
9a853f71 AV |
1643 | for (iter = 50; iter--; ) { |
1644 | stat = RD_REG_DWORD(®->host_status); | |
1645 | if (stat & HSRX_RISC_PAUSED) { | |
14e660e6 SJ |
1646 | if (pci_channel_offline(ha->pdev)) |
1647 | break; | |
1648 | ||
9a853f71 AV |
1649 | hccr = RD_REG_DWORD(®->hccr); |
1650 | ||
1651 | qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, " | |
1652 | "Dumping firmware!\n", hccr); | |
05236a05 | 1653 | |
e315cd28 | 1654 | qla2xxx_check_risc_status(vha); |
05236a05 | 1655 | |
e315cd28 AC |
1656 | ha->isp_ops->fw_dump(vha, 1); |
1657 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
9a853f71 AV |
1658 | break; |
1659 | } else if ((stat & HSRX_RISC_INT) == 0) | |
1660 | break; | |
1661 | ||
1662 | switch (stat & 0xff) { | |
1663 | case 0x1: | |
1664 | case 0x2: | |
1665 | case 0x10: | |
1666 | case 0x11: | |
e315cd28 | 1667 | qla24xx_mbx_completion(vha, MSW(stat)); |
9a853f71 AV |
1668 | status |= MBX_INTERRUPT; |
1669 | ||
1670 | break; | |
1671 | case 0x12: | |
1672 | mb[0] = MSW(stat); | |
1673 | mb[1] = RD_REG_WORD(®->mailbox1); | |
1674 | mb[2] = RD_REG_WORD(®->mailbox2); | |
1675 | mb[3] = RD_REG_WORD(®->mailbox3); | |
73208dfd | 1676 | qla2x00_async_event(vha, rsp, mb); |
9a853f71 AV |
1677 | break; |
1678 | case 0x13: | |
73208dfd | 1679 | case 0x14: |
2afa19a9 | 1680 | qla24xx_process_response_queue(vha, rsp); |
9a853f71 AV |
1681 | break; |
1682 | default: | |
1683 | DEBUG2(printk("scsi(%ld): Unrecognized interrupt type " | |
1684 | "(%d).\n", | |
e315cd28 | 1685 | vha->host_no, stat & 0xff)); |
9a853f71 AV |
1686 | break; |
1687 | } | |
1688 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT); | |
1689 | RD_REG_DWORD_RELAXED(®->hccr); | |
1690 | } | |
c6952483 | 1691 | spin_unlock(&ha->hardware_lock); |
9a853f71 AV |
1692 | |
1693 | if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) && | |
1694 | (status & MBX_INTERRUPT) && ha->flags.mbox_int) { | |
9a853f71 | 1695 | set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); |
0b05a1f0 | 1696 | complete(&ha->mbx_intr_comp); |
9a853f71 AV |
1697 | } |
1698 | ||
1699 | return IRQ_HANDLED; | |
1700 | } | |
1701 | ||
a8488abe AV |
1702 | static irqreturn_t |
1703 | qla24xx_msix_rsp_q(int irq, void *dev_id) | |
1704 | { | |
e315cd28 AC |
1705 | struct qla_hw_data *ha; |
1706 | struct rsp_que *rsp; | |
a8488abe | 1707 | struct device_reg_24xx __iomem *reg; |
2afa19a9 | 1708 | struct scsi_qla_host *vha; |
a8488abe | 1709 | |
e315cd28 AC |
1710 | rsp = (struct rsp_que *) dev_id; |
1711 | if (!rsp) { | |
1712 | printk(KERN_INFO | |
1713 | "%s(): NULL response queue pointer\n", __func__); | |
1714 | return IRQ_NONE; | |
1715 | } | |
1716 | ha = rsp->hw; | |
a8488abe AV |
1717 | reg = &ha->iobase->isp24; |
1718 | ||
0e973a24 | 1719 | spin_lock_irq(&ha->hardware_lock); |
a8488abe | 1720 | |
2afa19a9 AC |
1721 | vha = qla25xx_get_host(rsp); |
1722 | qla24xx_process_response_queue(vha, rsp); | |
a8488abe | 1723 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT); |
a8488abe | 1724 | |
0e973a24 | 1725 | spin_unlock_irq(&ha->hardware_lock); |
a8488abe AV |
1726 | |
1727 | return IRQ_HANDLED; | |
1728 | } | |
1729 | ||
68ca949c AC |
1730 | static irqreturn_t |
1731 | qla25xx_msix_rsp_q(int irq, void *dev_id) | |
1732 | { | |
1733 | struct qla_hw_data *ha; | |
1734 | struct rsp_que *rsp; | |
1735 | ||
1736 | rsp = (struct rsp_que *) dev_id; | |
1737 | if (!rsp) { | |
1738 | printk(KERN_INFO | |
1739 | "%s(): NULL response queue pointer\n", __func__); | |
1740 | return IRQ_NONE; | |
1741 | } | |
1742 | ha = rsp->hw; | |
1743 | ||
1744 | queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work); | |
1745 | ||
1746 | return IRQ_HANDLED; | |
1747 | } | |
1748 | ||
a8488abe AV |
1749 | static irqreturn_t |
1750 | qla24xx_msix_default(int irq, void *dev_id) | |
1751 | { | |
e315cd28 AC |
1752 | scsi_qla_host_t *vha; |
1753 | struct qla_hw_data *ha; | |
1754 | struct rsp_que *rsp; | |
a8488abe AV |
1755 | struct device_reg_24xx __iomem *reg; |
1756 | int status; | |
a8488abe AV |
1757 | uint32_t stat; |
1758 | uint32_t hccr; | |
1759 | uint16_t mb[4]; | |
1760 | ||
e315cd28 AC |
1761 | rsp = (struct rsp_que *) dev_id; |
1762 | if (!rsp) { | |
1763 | DEBUG(printk( | |
1764 | "%s(): NULL response queue pointer\n", __func__)); | |
1765 | return IRQ_NONE; | |
1766 | } | |
1767 | ha = rsp->hw; | |
a8488abe AV |
1768 | reg = &ha->iobase->isp24; |
1769 | status = 0; | |
1770 | ||
0e973a24 | 1771 | spin_lock_irq(&ha->hardware_lock); |
2afa19a9 | 1772 | vha = pci_get_drvdata(ha->pdev); |
87f27015 | 1773 | do { |
a8488abe AV |
1774 | stat = RD_REG_DWORD(®->host_status); |
1775 | if (stat & HSRX_RISC_PAUSED) { | |
14e660e6 SJ |
1776 | if (pci_channel_offline(ha->pdev)) |
1777 | break; | |
1778 | ||
a8488abe AV |
1779 | hccr = RD_REG_DWORD(®->hccr); |
1780 | ||
1781 | qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, " | |
1782 | "Dumping firmware!\n", hccr); | |
05236a05 | 1783 | |
e315cd28 | 1784 | qla2xxx_check_risc_status(vha); |
05236a05 | 1785 | |
e315cd28 AC |
1786 | ha->isp_ops->fw_dump(vha, 1); |
1787 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
a8488abe AV |
1788 | break; |
1789 | } else if ((stat & HSRX_RISC_INT) == 0) | |
1790 | break; | |
1791 | ||
1792 | switch (stat & 0xff) { | |
1793 | case 0x1: | |
1794 | case 0x2: | |
1795 | case 0x10: | |
1796 | case 0x11: | |
e315cd28 | 1797 | qla24xx_mbx_completion(vha, MSW(stat)); |
a8488abe AV |
1798 | status |= MBX_INTERRUPT; |
1799 | ||
1800 | break; | |
1801 | case 0x12: | |
1802 | mb[0] = MSW(stat); | |
1803 | mb[1] = RD_REG_WORD(®->mailbox1); | |
1804 | mb[2] = RD_REG_WORD(®->mailbox2); | |
1805 | mb[3] = RD_REG_WORD(®->mailbox3); | |
73208dfd | 1806 | qla2x00_async_event(vha, rsp, mb); |
a8488abe AV |
1807 | break; |
1808 | case 0x13: | |
73208dfd | 1809 | case 0x14: |
2afa19a9 | 1810 | qla24xx_process_response_queue(vha, rsp); |
a8488abe AV |
1811 | break; |
1812 | default: | |
1813 | DEBUG2(printk("scsi(%ld): Unrecognized interrupt type " | |
1814 | "(%d).\n", | |
e315cd28 | 1815 | vha->host_no, stat & 0xff)); |
a8488abe AV |
1816 | break; |
1817 | } | |
1818 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT); | |
87f27015 | 1819 | } while (0); |
0e973a24 | 1820 | spin_unlock_irq(&ha->hardware_lock); |
a8488abe AV |
1821 | |
1822 | if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) && | |
1823 | (status & MBX_INTERRUPT) && ha->flags.mbox_int) { | |
a8488abe | 1824 | set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); |
0b05a1f0 | 1825 | complete(&ha->mbx_intr_comp); |
a8488abe AV |
1826 | } |
1827 | ||
1828 | return IRQ_HANDLED; | |
1829 | } | |
1830 | ||
1831 | /* Interrupt handling helpers. */ | |
1832 | ||
1833 | struct qla_init_msix_entry { | |
a8488abe | 1834 | const char *name; |
476834c2 | 1835 | irq_handler_t handler; |
a8488abe AV |
1836 | }; |
1837 | ||
68ca949c | 1838 | static struct qla_init_msix_entry msix_entries[3] = { |
2afa19a9 AC |
1839 | { "qla2xxx (default)", qla24xx_msix_default }, |
1840 | { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q }, | |
68ca949c | 1841 | { "qla2xxx (multiq)", qla25xx_msix_rsp_q }, |
a8488abe AV |
1842 | }; |
1843 | ||
1844 | static void | |
e315cd28 | 1845 | qla24xx_disable_msix(struct qla_hw_data *ha) |
a8488abe AV |
1846 | { |
1847 | int i; | |
1848 | struct qla_msix_entry *qentry; | |
1849 | ||
73208dfd AC |
1850 | for (i = 0; i < ha->msix_count; i++) { |
1851 | qentry = &ha->msix_entries[i]; | |
a8488abe | 1852 | if (qentry->have_irq) |
73208dfd | 1853 | free_irq(qentry->vector, qentry->rsp); |
a8488abe AV |
1854 | } |
1855 | pci_disable_msix(ha->pdev); | |
73208dfd AC |
1856 | kfree(ha->msix_entries); |
1857 | ha->msix_entries = NULL; | |
1858 | ha->flags.msix_enabled = 0; | |
a8488abe AV |
1859 | } |
1860 | ||
1861 | static int | |
73208dfd | 1862 | qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp) |
a8488abe | 1863 | { |
ad038fa8 | 1864 | #define MIN_MSIX_COUNT 2 |
a8488abe | 1865 | int i, ret; |
73208dfd | 1866 | struct msix_entry *entries; |
a8488abe | 1867 | struct qla_msix_entry *qentry; |
73208dfd AC |
1868 | |
1869 | entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count, | |
1870 | GFP_KERNEL); | |
1871 | if (!entries) | |
1872 | return -ENOMEM; | |
a8488abe | 1873 | |
73208dfd AC |
1874 | for (i = 0; i < ha->msix_count; i++) |
1875 | entries[i].entry = i; | |
a8488abe | 1876 | |
73208dfd | 1877 | ret = pci_enable_msix(ha->pdev, entries, ha->msix_count); |
a8488abe | 1878 | if (ret) { |
ad038fa8 LC |
1879 | if (ret < MIN_MSIX_COUNT) |
1880 | goto msix_failed; | |
1881 | ||
a8488abe | 1882 | qla_printk(KERN_WARNING, ha, |
73208dfd AC |
1883 | "MSI-X: Failed to enable support -- %d/%d\n" |
1884 | " Retry with %d vectors\n", ha->msix_count, ret, ret); | |
1885 | ha->msix_count = ret; | |
1886 | ret = pci_enable_msix(ha->pdev, entries, ha->msix_count); | |
1887 | if (ret) { | |
ad038fa8 | 1888 | msix_failed: |
73208dfd AC |
1889 | qla_printk(KERN_WARNING, ha, "MSI-X: Failed to enable" |
1890 | " support, giving up -- %d/%d\n", | |
1891 | ha->msix_count, ret); | |
1892 | goto msix_out; | |
1893 | } | |
2afa19a9 | 1894 | ha->max_rsp_queues = ha->msix_count - 1; |
73208dfd AC |
1895 | } |
1896 | ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) * | |
1897 | ha->msix_count, GFP_KERNEL); | |
1898 | if (!ha->msix_entries) { | |
1899 | ret = -ENOMEM; | |
a8488abe AV |
1900 | goto msix_out; |
1901 | } | |
1902 | ha->flags.msix_enabled = 1; | |
1903 | ||
73208dfd AC |
1904 | for (i = 0; i < ha->msix_count; i++) { |
1905 | qentry = &ha->msix_entries[i]; | |
1906 | qentry->vector = entries[i].vector; | |
1907 | qentry->entry = entries[i].entry; | |
a8488abe | 1908 | qentry->have_irq = 0; |
73208dfd | 1909 | qentry->rsp = NULL; |
a8488abe AV |
1910 | } |
1911 | ||
2afa19a9 AC |
1912 | /* Enable MSI-X vectors for the base queue */ |
1913 | for (i = 0; i < 2; i++) { | |
1914 | qentry = &ha->msix_entries[i]; | |
1915 | ret = request_irq(qentry->vector, msix_entries[i].handler, | |
1916 | 0, msix_entries[i].name, rsp); | |
1917 | if (ret) { | |
1918 | qla_printk(KERN_WARNING, ha, | |
73208dfd AC |
1919 | "MSI-X: Unable to register handler -- %x/%d.\n", |
1920 | qentry->vector, ret); | |
2afa19a9 AC |
1921 | qla24xx_disable_msix(ha); |
1922 | ha->mqenable = 0; | |
1923 | goto msix_out; | |
1924 | } | |
1925 | qentry->have_irq = 1; | |
1926 | qentry->rsp = rsp; | |
1927 | rsp->msix = qentry; | |
73208dfd | 1928 | } |
73208dfd AC |
1929 | |
1930 | /* Enable MSI-X vector for response queue update for queue 0 */ | |
2afa19a9 | 1931 | if (ha->mqiobase && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1)) |
73208dfd | 1932 | ha->mqenable = 1; |
73208dfd | 1933 | |
a8488abe | 1934 | msix_out: |
73208dfd | 1935 | kfree(entries); |
a8488abe AV |
1936 | return ret; |
1937 | } | |
1938 | ||
1939 | int | |
73208dfd | 1940 | qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp) |
a8488abe AV |
1941 | { |
1942 | int ret; | |
963b0fdd | 1943 | device_reg_t __iomem *reg = ha->iobase; |
a8488abe AV |
1944 | |
1945 | /* If possible, enable MSI-X. */ | |
3a03eb79 AV |
1946 | if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && |
1947 | !IS_QLA8432(ha) && !IS_QLA8001(ha)) | |
a8488abe AV |
1948 | goto skip_msix; |
1949 | ||
e315cd28 AC |
1950 | if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX || |
1951 | !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) { | |
a8488abe | 1952 | DEBUG2(qla_printk(KERN_WARNING, ha, |
e315cd28 AC |
1953 | "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n", |
1954 | ha->pdev->revision, ha->fw_attributes)); | |
a8488abe AV |
1955 | |
1956 | goto skip_msix; | |
1957 | } | |
1958 | ||
da7429f9 AV |
1959 | if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP && |
1960 | (ha->pdev->subsystem_device == 0x7040 || | |
1961 | ha->pdev->subsystem_device == 0x7041 || | |
1962 | ha->pdev->subsystem_device == 0x1705)) { | |
1963 | DEBUG2(qla_printk(KERN_WARNING, ha, | |
1964 | "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n", | |
1965 | ha->pdev->subsystem_vendor, | |
1966 | ha->pdev->subsystem_device)); | |
1967 | ||
1968 | goto skip_msi; | |
1969 | } | |
1970 | ||
73208dfd | 1971 | ret = qla24xx_enable_msix(ha, rsp); |
a8488abe AV |
1972 | if (!ret) { |
1973 | DEBUG2(qla_printk(KERN_INFO, ha, | |
1974 | "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision, | |
1975 | ha->fw_attributes)); | |
963b0fdd | 1976 | goto clear_risc_ints; |
a8488abe AV |
1977 | } |
1978 | qla_printk(KERN_WARNING, ha, | |
1979 | "MSI-X: Falling back-to INTa mode -- %d.\n", ret); | |
1980 | skip_msix: | |
cbedb601 | 1981 | |
3a03eb79 AV |
1982 | if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) && |
1983 | !IS_QLA8001(ha)) | |
cbedb601 AV |
1984 | goto skip_msi; |
1985 | ||
1986 | ret = pci_enable_msi(ha->pdev); | |
1987 | if (!ret) { | |
1988 | DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n")); | |
1989 | ha->flags.msi_enabled = 1; | |
1990 | } | |
1991 | skip_msi: | |
1992 | ||
fd34f556 | 1993 | ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler, |
d1b1bef4 | 1994 | IRQF_SHARED, QLA2XXX_DRIVER_NAME, rsp); |
963b0fdd | 1995 | if (ret) { |
a8488abe AV |
1996 | qla_printk(KERN_WARNING, ha, |
1997 | "Failed to reserve interrupt %d already in use.\n", | |
1998 | ha->pdev->irq); | |
963b0fdd AV |
1999 | goto fail; |
2000 | } | |
2001 | ha->flags.inta_enabled = 1; | |
963b0fdd AV |
2002 | clear_risc_ints: |
2003 | ||
3a03eb79 AV |
2004 | /* |
2005 | * FIXME: Noted that 8014s were being dropped during NK testing. | |
2006 | * Timing deltas during MSI-X/INTa transitions? | |
2007 | */ | |
2008 | if (IS_QLA81XX(ha)) | |
2009 | goto fail; | |
c6952483 | 2010 | spin_lock_irq(&ha->hardware_lock); |
963b0fdd AV |
2011 | if (IS_FWI2_CAPABLE(ha)) { |
2012 | WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_HOST_INT); | |
2013 | WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_RISC_INT); | |
2014 | } else { | |
2015 | WRT_REG_WORD(®->isp.semaphore, 0); | |
2016 | WRT_REG_WORD(®->isp.hccr, HCCR_CLR_RISC_INT); | |
2017 | WRT_REG_WORD(®->isp.hccr, HCCR_CLR_HOST_INT); | |
a8488abe | 2018 | } |
c6952483 | 2019 | spin_unlock_irq(&ha->hardware_lock); |
a8488abe | 2020 | |
963b0fdd | 2021 | fail: |
a8488abe AV |
2022 | return ret; |
2023 | } | |
2024 | ||
2025 | void | |
e315cd28 | 2026 | qla2x00_free_irqs(scsi_qla_host_t *vha) |
a8488abe | 2027 | { |
e315cd28 | 2028 | struct qla_hw_data *ha = vha->hw; |
73208dfd | 2029 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
a8488abe AV |
2030 | |
2031 | if (ha->flags.msix_enabled) | |
2032 | qla24xx_disable_msix(ha); | |
cbedb601 | 2033 | else if (ha->flags.inta_enabled) { |
e315cd28 | 2034 | free_irq(ha->pdev->irq, rsp); |
cbedb601 AV |
2035 | pci_disable_msi(ha->pdev); |
2036 | } | |
a8488abe | 2037 | } |
e315cd28 | 2038 | |
73208dfd AC |
2039 | |
2040 | int qla25xx_request_irq(struct rsp_que *rsp) | |
2041 | { | |
2042 | struct qla_hw_data *ha = rsp->hw; | |
2afa19a9 | 2043 | struct qla_init_msix_entry *intr = &msix_entries[2]; |
73208dfd AC |
2044 | struct qla_msix_entry *msix = rsp->msix; |
2045 | int ret; | |
2046 | ||
2047 | ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp); | |
2048 | if (ret) { | |
2049 | qla_printk(KERN_WARNING, ha, | |
2050 | "MSI-X: Unable to register handler -- %x/%d.\n", | |
2051 | msix->vector, ret); | |
2052 | return ret; | |
2053 | } | |
2054 | msix->have_irq = 1; | |
2055 | msix->rsp = rsp; | |
2056 | return ret; | |
2057 | } | |
2afa19a9 AC |
2058 | |
2059 | struct scsi_qla_host * | |
2060 | qla25xx_get_host(struct rsp_que *rsp) | |
2061 | { | |
2062 | srb_t *sp; | |
2063 | struct qla_hw_data *ha = rsp->hw; | |
2064 | struct scsi_qla_host *vha = NULL; | |
2065 | struct sts_entry_24xx *pkt; | |
2066 | struct req_que *req; | |
2067 | uint16_t que; | |
2068 | uint32_t handle; | |
2069 | ||
2070 | pkt = (struct sts_entry_24xx *) rsp->ring_ptr; | |
2071 | que = MSW(pkt->handle); | |
2072 | handle = (uint32_t) LSW(pkt->handle); | |
2073 | req = ha->req_q_map[que]; | |
2074 | if (handle < MAX_OUTSTANDING_COMMANDS) { | |
2075 | sp = req->outstanding_cmds[handle]; | |
2076 | if (sp) | |
2077 | return sp->fcport->vha; | |
2078 | else | |
2079 | goto base_que; | |
2080 | } | |
2081 | base_que: | |
2082 | vha = pci_get_drvdata(ha->pdev); | |
2083 | return vha; | |
2084 | } |