]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
fa90c54f | 2 | * QLogic Fibre Channel HBA Driver |
bd21eaf9 | 3 | * Copyright (c) 2003-2014 QLogic Corporation |
1da177e4 | 4 | * |
fa90c54f | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
1da177e4 LT |
6 | */ |
7 | #include "qla_def.h" | |
2d70c103 | 8 | #include "qla_target.h" |
1da177e4 | 9 | |
05236a05 | 10 | #include <linux/delay.h> |
5a0e3ad6 | 11 | #include <linux/slab.h> |
09ce66ae | 12 | #include <linux/t10-pi.h> |
df7baa50 | 13 | #include <scsi/scsi_tcq.h> |
9a069e19 | 14 | #include <scsi/scsi_bsg_fc.h> |
bad75002 | 15 | #include <scsi/scsi_eh.h> |
df7baa50 | 16 | |
1da177e4 | 17 | static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t); |
73208dfd | 18 | static void qla2x00_status_entry(scsi_qla_host_t *, struct rsp_que *, void *); |
2afa19a9 | 19 | static void qla2x00_status_cont_entry(struct rsp_que *, sts_cont_entry_t *); |
73208dfd AC |
20 | static void qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *, |
21 | sts_entry_t *); | |
9a853f71 | 22 | |
1da177e4 LT |
23 | /** |
24 | * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200. | |
25 | * @irq: | |
26 | * @dev_id: SCSI driver HA context | |
1da177e4 LT |
27 | * |
28 | * Called by system whenever the host adapter generates an interrupt. | |
29 | * | |
30 | * Returns handled flag. | |
31 | */ | |
32 | irqreturn_t | |
7d12e780 | 33 | qla2100_intr_handler(int irq, void *dev_id) |
1da177e4 | 34 | { |
e315cd28 AC |
35 | scsi_qla_host_t *vha; |
36 | struct qla_hw_data *ha; | |
3d71644c | 37 | struct device_reg_2xxx __iomem *reg; |
1da177e4 | 38 | int status; |
1da177e4 | 39 | unsigned long iter; |
14e660e6 | 40 | uint16_t hccr; |
9a853f71 | 41 | uint16_t mb[4]; |
e315cd28 | 42 | struct rsp_que *rsp; |
43fac4d9 | 43 | unsigned long flags; |
1da177e4 | 44 | |
e315cd28 AC |
45 | rsp = (struct rsp_que *) dev_id; |
46 | if (!rsp) { | |
3256b435 CD |
47 | ql_log(ql_log_info, NULL, 0x505d, |
48 | "%s: NULL response queue pointer.\n", __func__); | |
1da177e4 LT |
49 | return (IRQ_NONE); |
50 | } | |
51 | ||
e315cd28 | 52 | ha = rsp->hw; |
3d71644c | 53 | reg = &ha->iobase->isp; |
1da177e4 LT |
54 | status = 0; |
55 | ||
43fac4d9 | 56 | spin_lock_irqsave(&ha->hardware_lock, flags); |
2afa19a9 | 57 | vha = pci_get_drvdata(ha->pdev); |
1da177e4 | 58 | for (iter = 50; iter--; ) { |
14e660e6 | 59 | hccr = RD_REG_WORD(®->hccr); |
c821e0d5 | 60 | if (qla2x00_check_reg16_for_disconnect(vha, hccr)) |
f3ddac19 | 61 | break; |
14e660e6 SJ |
62 | if (hccr & HCCR_RISC_PAUSE) { |
63 | if (pci_channel_offline(ha->pdev)) | |
64 | break; | |
65 | ||
66 | /* | |
67 | * Issue a "HARD" reset in order for the RISC interrupt | |
a06a0f8e | 68 | * bit to be cleared. Schedule a big hammer to get |
14e660e6 SJ |
69 | * out of the RISC PAUSED state. |
70 | */ | |
71 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); | |
72 | RD_REG_WORD(®->hccr); | |
73 | ||
e315cd28 AC |
74 | ha->isp_ops->fw_dump(vha, 1); |
75 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
14e660e6 SJ |
76 | break; |
77 | } else if ((RD_REG_WORD(®->istatus) & ISR_RISC_INT) == 0) | |
1da177e4 LT |
78 | break; |
79 | ||
80 | if (RD_REG_WORD(®->semaphore) & BIT_0) { | |
81 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); | |
82 | RD_REG_WORD(®->hccr); | |
83 | ||
84 | /* Get mailbox data. */ | |
9a853f71 AV |
85 | mb[0] = RD_MAILBOX_REG(ha, reg, 0); |
86 | if (mb[0] > 0x3fff && mb[0] < 0x8000) { | |
e315cd28 | 87 | qla2x00_mbx_completion(vha, mb[0]); |
1da177e4 | 88 | status |= MBX_INTERRUPT; |
9a853f71 AV |
89 | } else if (mb[0] > 0x7fff && mb[0] < 0xc000) { |
90 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); | |
91 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); | |
92 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); | |
73208dfd | 93 | qla2x00_async_event(vha, rsp, mb); |
1da177e4 LT |
94 | } else { |
95 | /*EMPTY*/ | |
7c3df132 SK |
96 | ql_dbg(ql_dbg_async, vha, 0x5025, |
97 | "Unrecognized interrupt type (%d).\n", | |
98 | mb[0]); | |
1da177e4 LT |
99 | } |
100 | /* Release mailbox registers. */ | |
101 | WRT_REG_WORD(®->semaphore, 0); | |
102 | RD_REG_WORD(®->semaphore); | |
103 | } else { | |
73208dfd | 104 | qla2x00_process_response_queue(rsp); |
1da177e4 LT |
105 | |
106 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); | |
107 | RD_REG_WORD(®->hccr); | |
108 | } | |
109 | } | |
36439832 | 110 | qla2x00_handle_mbx_completion(ha, status); |
43fac4d9 | 111 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
1da177e4 | 112 | |
1da177e4 LT |
113 | return (IRQ_HANDLED); |
114 | } | |
115 | ||
f3ddac19 | 116 | bool |
c821e0d5 | 117 | qla2x00_check_reg32_for_disconnect(scsi_qla_host_t *vha, uint32_t reg) |
f3ddac19 CD |
118 | { |
119 | /* Check for PCI disconnection */ | |
a30c2a3b | 120 | if (reg == 0xffffffff && !pci_channel_offline(vha->hw->pdev)) { |
beb9e315 | 121 | if (!test_and_set_bit(PFLG_DISCONNECTED, &vha->pci_flags) && |
6b383979 JL |
122 | !test_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags) && |
123 | !test_bit(PFLG_DRIVER_PROBING, &vha->pci_flags)) { | |
232792b6 JL |
124 | /* |
125 | * Schedule this (only once) on the default system | |
126 | * workqueue so that all the adapter workqueues and the | |
127 | * DPC thread can be shutdown cleanly. | |
128 | */ | |
129 | schedule_work(&vha->hw->board_disable); | |
130 | } | |
f3ddac19 CD |
131 | return true; |
132 | } else | |
133 | return false; | |
134 | } | |
135 | ||
c821e0d5 JL |
136 | bool |
137 | qla2x00_check_reg16_for_disconnect(scsi_qla_host_t *vha, uint16_t reg) | |
138 | { | |
139 | return qla2x00_check_reg32_for_disconnect(vha, 0xffff0000 | reg); | |
140 | } | |
141 | ||
1da177e4 LT |
142 | /** |
143 | * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx. | |
144 | * @irq: | |
145 | * @dev_id: SCSI driver HA context | |
1da177e4 LT |
146 | * |
147 | * Called by system whenever the host adapter generates an interrupt. | |
148 | * | |
149 | * Returns handled flag. | |
150 | */ | |
151 | irqreturn_t | |
7d12e780 | 152 | qla2300_intr_handler(int irq, void *dev_id) |
1da177e4 | 153 | { |
e315cd28 | 154 | scsi_qla_host_t *vha; |
3d71644c | 155 | struct device_reg_2xxx __iomem *reg; |
1da177e4 | 156 | int status; |
1da177e4 LT |
157 | unsigned long iter; |
158 | uint32_t stat; | |
1da177e4 | 159 | uint16_t hccr; |
9a853f71 | 160 | uint16_t mb[4]; |
e315cd28 AC |
161 | struct rsp_que *rsp; |
162 | struct qla_hw_data *ha; | |
43fac4d9 | 163 | unsigned long flags; |
1da177e4 | 164 | |
e315cd28 AC |
165 | rsp = (struct rsp_que *) dev_id; |
166 | if (!rsp) { | |
3256b435 CD |
167 | ql_log(ql_log_info, NULL, 0x5058, |
168 | "%s: NULL response queue pointer.\n", __func__); | |
1da177e4 LT |
169 | return (IRQ_NONE); |
170 | } | |
171 | ||
e315cd28 | 172 | ha = rsp->hw; |
3d71644c | 173 | reg = &ha->iobase->isp; |
1da177e4 LT |
174 | status = 0; |
175 | ||
43fac4d9 | 176 | spin_lock_irqsave(&ha->hardware_lock, flags); |
2afa19a9 | 177 | vha = pci_get_drvdata(ha->pdev); |
1da177e4 LT |
178 | for (iter = 50; iter--; ) { |
179 | stat = RD_REG_DWORD(®->u.isp2300.host_status); | |
c821e0d5 | 180 | if (qla2x00_check_reg32_for_disconnect(vha, stat)) |
f3ddac19 | 181 | break; |
1da177e4 | 182 | if (stat & HSR_RISC_PAUSED) { |
85880801 | 183 | if (unlikely(pci_channel_offline(ha->pdev))) |
14e660e6 SJ |
184 | break; |
185 | ||
1da177e4 | 186 | hccr = RD_REG_WORD(®->hccr); |
f3ddac19 | 187 | |
1da177e4 | 188 | if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8)) |
7c3df132 SK |
189 | ql_log(ql_log_warn, vha, 0x5026, |
190 | "Parity error -- HCCR=%x, Dumping " | |
191 | "firmware.\n", hccr); | |
1da177e4 | 192 | else |
7c3df132 SK |
193 | ql_log(ql_log_warn, vha, 0x5027, |
194 | "RISC paused -- HCCR=%x, Dumping " | |
195 | "firmware.\n", hccr); | |
1da177e4 LT |
196 | |
197 | /* | |
198 | * Issue a "HARD" reset in order for the RISC | |
199 | * interrupt bit to be cleared. Schedule a big | |
a06a0f8e | 200 | * hammer to get out of the RISC PAUSED state. |
1da177e4 LT |
201 | */ |
202 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); | |
203 | RD_REG_WORD(®->hccr); | |
07f31805 | 204 | |
e315cd28 AC |
205 | ha->isp_ops->fw_dump(vha, 1); |
206 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
1da177e4 LT |
207 | break; |
208 | } else if ((stat & HSR_RISC_INT) == 0) | |
209 | break; | |
210 | ||
1da177e4 | 211 | switch (stat & 0xff) { |
1da177e4 LT |
212 | case 0x1: |
213 | case 0x2: | |
214 | case 0x10: | |
215 | case 0x11: | |
e315cd28 | 216 | qla2x00_mbx_completion(vha, MSW(stat)); |
1da177e4 LT |
217 | status |= MBX_INTERRUPT; |
218 | ||
219 | /* Release mailbox registers. */ | |
220 | WRT_REG_WORD(®->semaphore, 0); | |
221 | break; | |
222 | case 0x12: | |
9a853f71 AV |
223 | mb[0] = MSW(stat); |
224 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); | |
225 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); | |
226 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); | |
73208dfd | 227 | qla2x00_async_event(vha, rsp, mb); |
9a853f71 AV |
228 | break; |
229 | case 0x13: | |
73208dfd | 230 | qla2x00_process_response_queue(rsp); |
1da177e4 LT |
231 | break; |
232 | case 0x15: | |
9a853f71 AV |
233 | mb[0] = MBA_CMPLT_1_16BIT; |
234 | mb[1] = MSW(stat); | |
73208dfd | 235 | qla2x00_async_event(vha, rsp, mb); |
1da177e4 LT |
236 | break; |
237 | case 0x16: | |
9a853f71 AV |
238 | mb[0] = MBA_SCSI_COMPLETION; |
239 | mb[1] = MSW(stat); | |
240 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); | |
73208dfd | 241 | qla2x00_async_event(vha, rsp, mb); |
1da177e4 LT |
242 | break; |
243 | default: | |
7c3df132 SK |
244 | ql_dbg(ql_dbg_async, vha, 0x5028, |
245 | "Unrecognized interrupt type (%d).\n", stat & 0xff); | |
1da177e4 LT |
246 | break; |
247 | } | |
248 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); | |
249 | RD_REG_WORD_RELAXED(®->hccr); | |
250 | } | |
36439832 | 251 | qla2x00_handle_mbx_completion(ha, status); |
43fac4d9 | 252 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
1da177e4 | 253 | |
1da177e4 LT |
254 | return (IRQ_HANDLED); |
255 | } | |
256 | ||
257 | /** | |
258 | * qla2x00_mbx_completion() - Process mailbox command completions. | |
259 | * @ha: SCSI driver HA context | |
260 | * @mb0: Mailbox0 register | |
261 | */ | |
262 | static void | |
e315cd28 | 263 | qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0) |
1da177e4 LT |
264 | { |
265 | uint16_t cnt; | |
4fa94f83 | 266 | uint32_t mboxes; |
1da177e4 | 267 | uint16_t __iomem *wptr; |
e315cd28 | 268 | struct qla_hw_data *ha = vha->hw; |
3d71644c | 269 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
1da177e4 | 270 | |
4fa94f83 AV |
271 | /* Read all mbox registers? */ |
272 | mboxes = (1 << ha->mbx_count) - 1; | |
273 | if (!ha->mcp) | |
a720101d | 274 | ql_dbg(ql_dbg_async, vha, 0x5001, "MBX pointer ERROR.\n"); |
4fa94f83 AV |
275 | else |
276 | mboxes = ha->mcp->in_mb; | |
277 | ||
1da177e4 LT |
278 | /* Load return mailbox registers. */ |
279 | ha->flags.mbox_int = 1; | |
280 | ha->mailbox_out[0] = mb0; | |
4fa94f83 | 281 | mboxes >>= 1; |
1da177e4 LT |
282 | wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1); |
283 | ||
284 | for (cnt = 1; cnt < ha->mbx_count; cnt++) { | |
fa2a1ce5 | 285 | if (IS_QLA2200(ha) && cnt == 8) |
1da177e4 | 286 | wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8); |
4fa94f83 | 287 | if ((cnt == 4 || cnt == 5) && (mboxes & BIT_0)) |
1da177e4 | 288 | ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr); |
4fa94f83 | 289 | else if (mboxes & BIT_0) |
1da177e4 | 290 | ha->mailbox_out[cnt] = RD_REG_WORD(wptr); |
fa2a1ce5 | 291 | |
1da177e4 | 292 | wptr++; |
4fa94f83 | 293 | mboxes >>= 1; |
1da177e4 | 294 | } |
1da177e4 LT |
295 | } |
296 | ||
8a659571 AV |
297 | static void |
298 | qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr) | |
299 | { | |
300 | static char *event[] = | |
301 | { "Complete", "Request Notification", "Time Extension" }; | |
302 | int rval; | |
303 | struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24; | |
9e5054ec | 304 | struct device_reg_82xx __iomem *reg82 = &vha->hw->iobase->isp82; |
8a659571 AV |
305 | uint16_t __iomem *wptr; |
306 | uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS]; | |
307 | ||
308 | /* Seed data -- mailbox1 -> mailbox7. */ | |
9e5054ec CD |
309 | if (IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw)) |
310 | wptr = (uint16_t __iomem *)®24->mailbox1; | |
311 | else if (IS_QLA8044(vha->hw)) | |
312 | wptr = (uint16_t __iomem *)®82->mailbox_out[1]; | |
313 | else | |
314 | return; | |
315 | ||
8a659571 AV |
316 | for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++) |
317 | mb[cnt] = RD_REG_WORD(wptr); | |
318 | ||
7c3df132 | 319 | ql_dbg(ql_dbg_async, vha, 0x5021, |
6246b8a1 | 320 | "Inter-Driver Communication %s -- " |
7c3df132 SK |
321 | "%04x %04x %04x %04x %04x %04x %04x.\n", |
322 | event[aen & 0xff], mb[0], mb[1], mb[2], mb[3], | |
323 | mb[4], mb[5], mb[6]); | |
454073c9 SV |
324 | switch (aen) { |
325 | /* Handle IDC Error completion case. */ | |
326 | case MBA_IDC_COMPLETE: | |
327 | if (mb[1] >> 15) { | |
328 | vha->hw->flags.idc_compl_status = 1; | |
9aaf2cea | 329 | if (vha->hw->notify_dcbx_comp && !vha->vp_idx) |
454073c9 SV |
330 | complete(&vha->hw->dcbx_comp); |
331 | } | |
332 | break; | |
333 | ||
334 | case MBA_IDC_NOTIFY: | |
335 | /* Acknowledgement needed? [Notify && non-zero timeout]. */ | |
336 | timeout = (descr >> 8) & 0xf; | |
337 | ql_dbg(ql_dbg_async, vha, 0x5022, | |
338 | "%lu Inter-Driver Communication %s -- ACK timeout=%d.\n", | |
339 | vha->host_no, event[aen & 0xff], timeout); | |
340 | ||
341 | if (!timeout) | |
342 | return; | |
343 | rval = qla2x00_post_idc_ack_work(vha, mb); | |
344 | if (rval != QLA_SUCCESS) | |
345 | ql_log(ql_log_warn, vha, 0x5023, | |
346 | "IDC failed to post ACK.\n"); | |
347 | break; | |
348 | case MBA_IDC_TIME_EXT: | |
349 | vha->hw->idc_extend_tmo = descr; | |
350 | ql_dbg(ql_dbg_async, vha, 0x5087, | |
351 | "%lu Inter-Driver Communication %s -- " | |
352 | "Extend timeout by=%d.\n", | |
353 | vha->host_no, event[aen & 0xff], vha->hw->idc_extend_tmo); | |
354 | break; | |
bf5b8ad7 | 355 | } |
8a659571 AV |
356 | } |
357 | ||
daae62a3 | 358 | #define LS_UNKNOWN 2 |
d0297c9a JC |
359 | const char * |
360 | qla2x00_get_link_speed_str(struct qla_hw_data *ha, uint16_t speed) | |
daae62a3 | 361 | { |
f73cb695 CD |
362 | static const char *const link_speeds[] = { |
363 | "1", "2", "?", "4", "8", "16", "32", "10" | |
d0297c9a | 364 | }; |
f73cb695 | 365 | #define QLA_LAST_SPEED 7 |
daae62a3 CD |
366 | |
367 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) | |
d0297c9a JC |
368 | return link_speeds[0]; |
369 | else if (speed == 0x13) | |
f73cb695 CD |
370 | return link_speeds[QLA_LAST_SPEED]; |
371 | else if (speed < QLA_LAST_SPEED) | |
d0297c9a JC |
372 | return link_speeds[speed]; |
373 | else | |
374 | return link_speeds[LS_UNKNOWN]; | |
daae62a3 CD |
375 | } |
376 | ||
fa492630 | 377 | static void |
7d613ac6 SV |
378 | qla83xx_handle_8200_aen(scsi_qla_host_t *vha, uint16_t *mb) |
379 | { | |
380 | struct qla_hw_data *ha = vha->hw; | |
381 | ||
382 | /* | |
383 | * 8200 AEN Interpretation: | |
384 | * mb[0] = AEN code | |
385 | * mb[1] = AEN Reason code | |
386 | * mb[2] = LSW of Peg-Halt Status-1 Register | |
387 | * mb[6] = MSW of Peg-Halt Status-1 Register | |
388 | * mb[3] = LSW of Peg-Halt Status-2 register | |
389 | * mb[7] = MSW of Peg-Halt Status-2 register | |
390 | * mb[4] = IDC Device-State Register value | |
391 | * mb[5] = IDC Driver-Presence Register value | |
392 | */ | |
393 | ql_dbg(ql_dbg_async, vha, 0x506b, "AEN Code: mb[0] = 0x%x AEN reason: " | |
394 | "mb[1] = 0x%x PH-status1: mb[2] = 0x%x PH-status1: mb[6] = 0x%x.\n", | |
395 | mb[0], mb[1], mb[2], mb[6]); | |
396 | ql_dbg(ql_dbg_async, vha, 0x506c, "PH-status2: mb[3] = 0x%x " | |
397 | "PH-status2: mb[7] = 0x%x Device-State: mb[4] = 0x%x " | |
398 | "Drv-Presence: mb[5] = 0x%x.\n", mb[3], mb[7], mb[4], mb[5]); | |
399 | ||
400 | if (mb[1] & (IDC_PEG_HALT_STATUS_CHANGE | IDC_NIC_FW_REPORTED_FAILURE | | |
401 | IDC_HEARTBEAT_FAILURE)) { | |
402 | ha->flags.nic_core_hung = 1; | |
403 | ql_log(ql_log_warn, vha, 0x5060, | |
404 | "83XX: F/W Error Reported: Check if reset required.\n"); | |
405 | ||
406 | if (mb[1] & IDC_PEG_HALT_STATUS_CHANGE) { | |
407 | uint32_t protocol_engine_id, fw_err_code, err_level; | |
408 | ||
409 | /* | |
410 | * IDC_PEG_HALT_STATUS_CHANGE interpretation: | |
411 | * - PEG-Halt Status-1 Register: | |
412 | * (LSW = mb[2], MSW = mb[6]) | |
413 | * Bits 0-7 = protocol-engine ID | |
414 | * Bits 8-28 = f/w error code | |
415 | * Bits 29-31 = Error-level | |
416 | * Error-level 0x1 = Non-Fatal error | |
417 | * Error-level 0x2 = Recoverable Fatal error | |
418 | * Error-level 0x4 = UnRecoverable Fatal error | |
419 | * - PEG-Halt Status-2 Register: | |
420 | * (LSW = mb[3], MSW = mb[7]) | |
421 | */ | |
422 | protocol_engine_id = (mb[2] & 0xff); | |
423 | fw_err_code = (((mb[2] & 0xff00) >> 8) | | |
424 | ((mb[6] & 0x1fff) << 8)); | |
425 | err_level = ((mb[6] & 0xe000) >> 13); | |
426 | ql_log(ql_log_warn, vha, 0x5061, "PegHalt Status-1 " | |
427 | "Register: protocol_engine_id=0x%x " | |
428 | "fw_err_code=0x%x err_level=0x%x.\n", | |
429 | protocol_engine_id, fw_err_code, err_level); | |
430 | ql_log(ql_log_warn, vha, 0x5062, "PegHalt Status-2 " | |
431 | "Register: 0x%x%x.\n", mb[7], mb[3]); | |
432 | if (err_level == ERR_LEVEL_NON_FATAL) { | |
433 | ql_log(ql_log_warn, vha, 0x5063, | |
434 | "Not a fatal error, f/w has recovered " | |
435 | "iteself.\n"); | |
436 | } else if (err_level == ERR_LEVEL_RECOVERABLE_FATAL) { | |
437 | ql_log(ql_log_fatal, vha, 0x5064, | |
438 | "Recoverable Fatal error: Chip reset " | |
439 | "required.\n"); | |
440 | qla83xx_schedule_work(vha, | |
441 | QLA83XX_NIC_CORE_RESET); | |
442 | } else if (err_level == ERR_LEVEL_UNRECOVERABLE_FATAL) { | |
443 | ql_log(ql_log_fatal, vha, 0x5065, | |
444 | "Unrecoverable Fatal error: Set FAILED " | |
445 | "state, reboot required.\n"); | |
446 | qla83xx_schedule_work(vha, | |
447 | QLA83XX_NIC_CORE_UNRECOVERABLE); | |
448 | } | |
449 | } | |
450 | ||
451 | if (mb[1] & IDC_NIC_FW_REPORTED_FAILURE) { | |
452 | uint16_t peg_fw_state, nw_interface_link_up; | |
453 | uint16_t nw_interface_signal_detect, sfp_status; | |
454 | uint16_t htbt_counter, htbt_monitor_enable; | |
455 | uint16_t sfp_additonal_info, sfp_multirate; | |
456 | uint16_t sfp_tx_fault, link_speed, dcbx_status; | |
457 | ||
458 | /* | |
459 | * IDC_NIC_FW_REPORTED_FAILURE interpretation: | |
460 | * - PEG-to-FC Status Register: | |
461 | * (LSW = mb[2], MSW = mb[6]) | |
462 | * Bits 0-7 = Peg-Firmware state | |
463 | * Bit 8 = N/W Interface Link-up | |
464 | * Bit 9 = N/W Interface signal detected | |
465 | * Bits 10-11 = SFP Status | |
466 | * SFP Status 0x0 = SFP+ transceiver not expected | |
467 | * SFP Status 0x1 = SFP+ transceiver not present | |
468 | * SFP Status 0x2 = SFP+ transceiver invalid | |
469 | * SFP Status 0x3 = SFP+ transceiver present and | |
470 | * valid | |
471 | * Bits 12-14 = Heartbeat Counter | |
472 | * Bit 15 = Heartbeat Monitor Enable | |
473 | * Bits 16-17 = SFP Additional Info | |
474 | * SFP info 0x0 = Unregocnized transceiver for | |
475 | * Ethernet | |
476 | * SFP info 0x1 = SFP+ brand validation failed | |
477 | * SFP info 0x2 = SFP+ speed validation failed | |
478 | * SFP info 0x3 = SFP+ access error | |
479 | * Bit 18 = SFP Multirate | |
480 | * Bit 19 = SFP Tx Fault | |
481 | * Bits 20-22 = Link Speed | |
482 | * Bits 23-27 = Reserved | |
483 | * Bits 28-30 = DCBX Status | |
484 | * DCBX Status 0x0 = DCBX Disabled | |
485 | * DCBX Status 0x1 = DCBX Enabled | |
486 | * DCBX Status 0x2 = DCBX Exchange error | |
487 | * Bit 31 = Reserved | |
488 | */ | |
489 | peg_fw_state = (mb[2] & 0x00ff); | |
490 | nw_interface_link_up = ((mb[2] & 0x0100) >> 8); | |
491 | nw_interface_signal_detect = ((mb[2] & 0x0200) >> 9); | |
492 | sfp_status = ((mb[2] & 0x0c00) >> 10); | |
493 | htbt_counter = ((mb[2] & 0x7000) >> 12); | |
494 | htbt_monitor_enable = ((mb[2] & 0x8000) >> 15); | |
495 | sfp_additonal_info = (mb[6] & 0x0003); | |
496 | sfp_multirate = ((mb[6] & 0x0004) >> 2); | |
497 | sfp_tx_fault = ((mb[6] & 0x0008) >> 3); | |
498 | link_speed = ((mb[6] & 0x0070) >> 4); | |
499 | dcbx_status = ((mb[6] & 0x7000) >> 12); | |
500 | ||
501 | ql_log(ql_log_warn, vha, 0x5066, | |
502 | "Peg-to-Fc Status Register:\n" | |
503 | "peg_fw_state=0x%x, nw_interface_link_up=0x%x, " | |
504 | "nw_interface_signal_detect=0x%x" | |
505 | "\nsfp_statis=0x%x.\n ", peg_fw_state, | |
506 | nw_interface_link_up, nw_interface_signal_detect, | |
507 | sfp_status); | |
508 | ql_log(ql_log_warn, vha, 0x5067, | |
509 | "htbt_counter=0x%x, htbt_monitor_enable=0x%x, " | |
510 | "sfp_additonal_info=0x%x, sfp_multirate=0x%x.\n ", | |
511 | htbt_counter, htbt_monitor_enable, | |
512 | sfp_additonal_info, sfp_multirate); | |
513 | ql_log(ql_log_warn, vha, 0x5068, | |
514 | "sfp_tx_fault=0x%x, link_state=0x%x, " | |
515 | "dcbx_status=0x%x.\n", sfp_tx_fault, link_speed, | |
516 | dcbx_status); | |
517 | ||
518 | qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET); | |
519 | } | |
520 | ||
521 | if (mb[1] & IDC_HEARTBEAT_FAILURE) { | |
522 | ql_log(ql_log_warn, vha, 0x5069, | |
523 | "Heartbeat Failure encountered, chip reset " | |
524 | "required.\n"); | |
525 | ||
526 | qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET); | |
527 | } | |
528 | } | |
529 | ||
530 | if (mb[1] & IDC_DEVICE_STATE_CHANGE) { | |
531 | ql_log(ql_log_info, vha, 0x506a, | |
532 | "IDC Device-State changed = 0x%x.\n", mb[4]); | |
6c3943cd SK |
533 | if (ha->flags.nic_core_reset_owner) |
534 | return; | |
7d613ac6 SV |
535 | qla83xx_schedule_work(vha, MBA_IDC_AEN); |
536 | } | |
537 | } | |
538 | ||
bb4cf5b7 CD |
539 | int |
540 | qla2x00_is_a_vp_did(scsi_qla_host_t *vha, uint32_t rscn_entry) | |
541 | { | |
542 | struct qla_hw_data *ha = vha->hw; | |
543 | scsi_qla_host_t *vp; | |
544 | uint32_t vp_did; | |
545 | unsigned long flags; | |
546 | int ret = 0; | |
547 | ||
548 | if (!ha->num_vhosts) | |
549 | return ret; | |
550 | ||
551 | spin_lock_irqsave(&ha->vport_slock, flags); | |
552 | list_for_each_entry(vp, &ha->vp_list, list) { | |
553 | vp_did = vp->d_id.b24; | |
554 | if (vp_did == rscn_entry) { | |
555 | ret = 1; | |
556 | break; | |
557 | } | |
558 | } | |
559 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
560 | ||
561 | return ret; | |
562 | } | |
563 | ||
17cac3a1 JC |
564 | static inline fc_port_t * |
565 | qla2x00_find_fcport_by_loopid(scsi_qla_host_t *vha, uint16_t loop_id) | |
566 | { | |
567 | fc_port_t *fcport; | |
568 | ||
569 | list_for_each_entry(fcport, &vha->vp_fcports, list) | |
570 | if (fcport->loop_id == loop_id) | |
571 | return fcport; | |
572 | return NULL; | |
573 | } | |
574 | ||
1da177e4 LT |
575 | /** |
576 | * qla2x00_async_event() - Process aynchronous events. | |
577 | * @ha: SCSI driver HA context | |
9a853f71 | 578 | * @mb: Mailbox registers (0 - 3) |
1da177e4 | 579 | */ |
2c3dfe3f | 580 | void |
73208dfd | 581 | qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb) |
1da177e4 | 582 | { |
1da177e4 | 583 | uint16_t handle_cnt; |
bdab23da | 584 | uint16_t cnt, mbx; |
1da177e4 | 585 | uint32_t handles[5]; |
e315cd28 | 586 | struct qla_hw_data *ha = vha->hw; |
3d71644c | 587 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
bdab23da | 588 | struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24; |
bc5c2aad | 589 | struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82; |
52c82823 | 590 | uint32_t rscn_entry, host_pid; |
4d4df193 | 591 | unsigned long flags; |
ef86cb20 | 592 | fc_port_t *fcport = NULL; |
1da177e4 LT |
593 | |
594 | /* Setup to process RIO completion. */ | |
595 | handle_cnt = 0; | |
6246b8a1 | 596 | if (IS_CNA_CAPABLE(ha)) |
3a03eb79 | 597 | goto skip_rio; |
1da177e4 LT |
598 | switch (mb[0]) { |
599 | case MBA_SCSI_COMPLETION: | |
9a853f71 | 600 | handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1])); |
1da177e4 LT |
601 | handle_cnt = 1; |
602 | break; | |
603 | case MBA_CMPLT_1_16BIT: | |
9a853f71 | 604 | handles[0] = mb[1]; |
1da177e4 LT |
605 | handle_cnt = 1; |
606 | mb[0] = MBA_SCSI_COMPLETION; | |
607 | break; | |
608 | case MBA_CMPLT_2_16BIT: | |
9a853f71 AV |
609 | handles[0] = mb[1]; |
610 | handles[1] = mb[2]; | |
1da177e4 LT |
611 | handle_cnt = 2; |
612 | mb[0] = MBA_SCSI_COMPLETION; | |
613 | break; | |
614 | case MBA_CMPLT_3_16BIT: | |
9a853f71 AV |
615 | handles[0] = mb[1]; |
616 | handles[1] = mb[2]; | |
617 | handles[2] = mb[3]; | |
1da177e4 LT |
618 | handle_cnt = 3; |
619 | mb[0] = MBA_SCSI_COMPLETION; | |
620 | break; | |
621 | case MBA_CMPLT_4_16BIT: | |
9a853f71 AV |
622 | handles[0] = mb[1]; |
623 | handles[1] = mb[2]; | |
624 | handles[2] = mb[3]; | |
1da177e4 LT |
625 | handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6); |
626 | handle_cnt = 4; | |
627 | mb[0] = MBA_SCSI_COMPLETION; | |
628 | break; | |
629 | case MBA_CMPLT_5_16BIT: | |
9a853f71 AV |
630 | handles[0] = mb[1]; |
631 | handles[1] = mb[2]; | |
632 | handles[2] = mb[3]; | |
1da177e4 LT |
633 | handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6); |
634 | handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7); | |
635 | handle_cnt = 5; | |
636 | mb[0] = MBA_SCSI_COMPLETION; | |
637 | break; | |
638 | case MBA_CMPLT_2_32BIT: | |
9a853f71 | 639 | handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1])); |
1da177e4 LT |
640 | handles[1] = le32_to_cpu( |
641 | ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) | | |
642 | RD_MAILBOX_REG(ha, reg, 6)); | |
643 | handle_cnt = 2; | |
644 | mb[0] = MBA_SCSI_COMPLETION; | |
645 | break; | |
646 | default: | |
647 | break; | |
648 | } | |
3a03eb79 | 649 | skip_rio: |
1da177e4 LT |
650 | switch (mb[0]) { |
651 | case MBA_SCSI_COMPLETION: /* Fast Post */ | |
e315cd28 | 652 | if (!vha->flags.online) |
1da177e4 LT |
653 | break; |
654 | ||
655 | for (cnt = 0; cnt < handle_cnt; cnt++) | |
73208dfd AC |
656 | qla2x00_process_completed_request(vha, rsp->req, |
657 | handles[cnt]); | |
1da177e4 LT |
658 | break; |
659 | ||
660 | case MBA_RESET: /* Reset */ | |
7c3df132 SK |
661 | ql_dbg(ql_dbg_async, vha, 0x5002, |
662 | "Asynchronous RESET.\n"); | |
1da177e4 | 663 | |
e315cd28 | 664 | set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
1da177e4 LT |
665 | break; |
666 | ||
667 | case MBA_SYSTEM_ERR: /* System Error */ | |
f73cb695 | 668 | mbx = (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) ? |
6246b8a1 | 669 | RD_REG_WORD(®24->mailbox7) : 0; |
7c3df132 | 670 | ql_log(ql_log_warn, vha, 0x5003, |
bdab23da AV |
671 | "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh " |
672 | "mbx7=%xh.\n", mb[1], mb[2], mb[3], mbx); | |
1da177e4 | 673 | |
e315cd28 | 674 | ha->isp_ops->fw_dump(vha, 1); |
1da177e4 | 675 | |
e428924c | 676 | if (IS_FWI2_CAPABLE(ha)) { |
9a853f71 | 677 | if (mb[1] == 0 && mb[2] == 0) { |
7c3df132 | 678 | ql_log(ql_log_fatal, vha, 0x5004, |
9a853f71 AV |
679 | "Unrecoverable Hardware Error: adapter " |
680 | "marked OFFLINE!\n"); | |
e315cd28 | 681 | vha->flags.online = 0; |
6246b8a1 | 682 | vha->device_flags |= DFLG_DEV_FAILED; |
b1d46989 | 683 | } else { |
25985edc | 684 | /* Check to see if MPI timeout occurred */ |
f73cb695 | 685 | if ((mbx & MBX_3) && (ha->port_no == 0)) |
b1d46989 MI |
686 | set_bit(MPI_RESET_NEEDED, |
687 | &vha->dpc_flags); | |
688 | ||
e315cd28 | 689 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
b1d46989 | 690 | } |
9a853f71 | 691 | } else if (mb[1] == 0) { |
7c3df132 | 692 | ql_log(ql_log_fatal, vha, 0x5005, |
1da177e4 LT |
693 | "Unrecoverable Hardware Error: adapter marked " |
694 | "OFFLINE!\n"); | |
e315cd28 | 695 | vha->flags.online = 0; |
6246b8a1 | 696 | vha->device_flags |= DFLG_DEV_FAILED; |
1da177e4 | 697 | } else |
e315cd28 | 698 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
1da177e4 LT |
699 | break; |
700 | ||
701 | case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */ | |
7c3df132 SK |
702 | ql_log(ql_log_warn, vha, 0x5006, |
703 | "ISP Request Transfer Error (%x).\n", mb[1]); | |
1da177e4 | 704 | |
e315cd28 | 705 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
1da177e4 LT |
706 | break; |
707 | ||
708 | case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */ | |
7c3df132 | 709 | ql_log(ql_log_warn, vha, 0x5007, |
41233cd3 | 710 | "ISP Response Transfer Error (%x).\n", mb[1]); |
1da177e4 | 711 | |
e315cd28 | 712 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
1da177e4 LT |
713 | break; |
714 | ||
715 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up */ | |
7c3df132 | 716 | ql_dbg(ql_dbg_async, vha, 0x5008, |
41233cd3 JC |
717 | "Asynchronous WAKEUP_THRES (%x).\n", mb[1]); |
718 | break; | |
1da177e4 | 719 | |
41233cd3 | 720 | case MBA_LOOP_INIT_ERR: |
75d560e0 | 721 | ql_log(ql_log_warn, vha, 0x5090, |
41233cd3 JC |
722 | "LOOP INIT ERROR (%x).\n", mb[1]); |
723 | ha->isp_ops->fw_dump(vha, 1); | |
724 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
2d70c103 | 725 | break; |
41233cd3 | 726 | |
1da177e4 | 727 | case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */ |
cfb0919c | 728 | ql_dbg(ql_dbg_async, vha, 0x5009, |
7c3df132 | 729 | "LIP occurred (%x).\n", mb[1]); |
1da177e4 | 730 | |
e315cd28 AC |
731 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
732 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
733 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | |
734 | qla2x00_mark_all_devices_lost(vha, 1); | |
1da177e4 LT |
735 | } |
736 | ||
e315cd28 AC |
737 | if (vha->vp_idx) { |
738 | atomic_set(&vha->vp_state, VP_FAILED); | |
739 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); | |
2c3dfe3f SJ |
740 | } |
741 | ||
e315cd28 AC |
742 | set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags); |
743 | set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags); | |
1da177e4 | 744 | |
e315cd28 AC |
745 | vha->flags.management_server_logged_in = 0; |
746 | qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]); | |
1da177e4 LT |
747 | break; |
748 | ||
749 | case MBA_LOOP_UP: /* Loop Up Event */ | |
daae62a3 | 750 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
d8b45213 | 751 | ha->link_data_rate = PORT_SPEED_1GB; |
daae62a3 | 752 | else |
1da177e4 | 753 | ha->link_data_rate = mb[1]; |
1da177e4 | 754 | |
8e5a9484 | 755 | ql_log(ql_log_info, vha, 0x500a, |
daae62a3 | 756 | "LOOP UP detected (%s Gbps).\n", |
d0297c9a | 757 | qla2x00_get_link_speed_str(ha, ha->link_data_rate)); |
1da177e4 | 758 | |
e315cd28 AC |
759 | vha->flags.management_server_logged_in = 0; |
760 | qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate); | |
1da177e4 LT |
761 | break; |
762 | ||
763 | case MBA_LOOP_DOWN: /* Loop Down Event */ | |
6246b8a1 GM |
764 | mbx = (IS_QLA81XX(ha) || IS_QLA8031(ha)) |
765 | ? RD_REG_WORD(®24->mailbox4) : 0; | |
7ec0effd AD |
766 | mbx = (IS_P3P_TYPE(ha)) ? RD_REG_WORD(®82->mailbox_out[4]) |
767 | : mbx; | |
8e5a9484 | 768 | ql_log(ql_log_info, vha, 0x500b, |
7c3df132 SK |
769 | "LOOP DOWN detected (%x %x %x %x).\n", |
770 | mb[1], mb[2], mb[3], mbx); | |
1da177e4 | 771 | |
e315cd28 AC |
772 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
773 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
774 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | |
2486c627 HM |
775 | /* |
776 | * In case of loop down, restore WWPN from | |
777 | * NVRAM in case of FA-WWPN capable ISP | |
718abbdc | 778 | * Restore for Physical Port only |
2486c627 | 779 | */ |
718abbdc SC |
780 | if (!vha->vp_idx) { |
781 | if (ha->flags.fawwpn_enabled) { | |
782 | void *wwpn = ha->init_cb->port_name; | |
783 | memcpy(vha->port_name, wwpn, WWN_SIZE); | |
784 | fc_host_port_name(vha->host) = | |
785 | wwn_to_u64(vha->port_name); | |
786 | ql_dbg(ql_dbg_init + ql_dbg_verbose, | |
787 | vha, 0x0144, "LOOP DOWN detected," | |
788 | "restore WWPN %016llx\n", | |
789 | wwn_to_u64(vha->port_name)); | |
790 | } | |
791 | ||
792 | clear_bit(VP_CONFIG_OK, &vha->vp_flags); | |
2486c627 HM |
793 | } |
794 | ||
e315cd28 AC |
795 | vha->device_flags |= DFLG_NO_CABLE; |
796 | qla2x00_mark_all_devices_lost(vha, 1); | |
1da177e4 LT |
797 | } |
798 | ||
e315cd28 AC |
799 | if (vha->vp_idx) { |
800 | atomic_set(&vha->vp_state, VP_FAILED); | |
801 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); | |
2c3dfe3f SJ |
802 | } |
803 | ||
e315cd28 | 804 | vha->flags.management_server_logged_in = 0; |
d8b45213 | 805 | ha->link_data_rate = PORT_SPEED_UNKNOWN; |
e315cd28 | 806 | qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0); |
1da177e4 LT |
807 | break; |
808 | ||
809 | case MBA_LIP_RESET: /* LIP reset occurred */ | |
cfb0919c | 810 | ql_dbg(ql_dbg_async, vha, 0x500c, |
cc3ef7bc | 811 | "LIP reset occurred (%x).\n", mb[1]); |
1da177e4 | 812 | |
e315cd28 AC |
813 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
814 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
815 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | |
816 | qla2x00_mark_all_devices_lost(vha, 1); | |
1da177e4 LT |
817 | } |
818 | ||
e315cd28 AC |
819 | if (vha->vp_idx) { |
820 | atomic_set(&vha->vp_state, VP_FAILED); | |
821 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); | |
2c3dfe3f SJ |
822 | } |
823 | ||
e315cd28 | 824 | set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
1da177e4 LT |
825 | |
826 | ha->operating_mode = LOOP; | |
e315cd28 AC |
827 | vha->flags.management_server_logged_in = 0; |
828 | qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]); | |
1da177e4 LT |
829 | break; |
830 | ||
3a03eb79 | 831 | /* case MBA_DCBX_COMPLETE: */ |
1da177e4 LT |
832 | case MBA_POINT_TO_POINT: /* Point-to-Point */ |
833 | if (IS_QLA2100(ha)) | |
834 | break; | |
835 | ||
7ec0effd | 836 | if (IS_CNA_CAPABLE(ha)) { |
7c3df132 SK |
837 | ql_dbg(ql_dbg_async, vha, 0x500d, |
838 | "DCBX Completed -- %04x %04x %04x.\n", | |
839 | mb[1], mb[2], mb[3]); | |
9aaf2cea | 840 | if (ha->notify_dcbx_comp && !vha->vp_idx) |
23f2ebd1 SR |
841 | complete(&ha->dcbx_comp); |
842 | ||
843 | } else | |
7c3df132 SK |
844 | ql_dbg(ql_dbg_async, vha, 0x500e, |
845 | "Asynchronous P2P MODE received.\n"); | |
1da177e4 LT |
846 | |
847 | /* | |
848 | * Until there's a transition from loop down to loop up, treat | |
849 | * this as loop down only. | |
850 | */ | |
e315cd28 AC |
851 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
852 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
853 | if (!atomic_read(&vha->loop_down_timer)) | |
854 | atomic_set(&vha->loop_down_timer, | |
1da177e4 | 855 | LOOP_DOWN_TIME); |
e315cd28 | 856 | qla2x00_mark_all_devices_lost(vha, 1); |
1da177e4 LT |
857 | } |
858 | ||
e315cd28 AC |
859 | if (vha->vp_idx) { |
860 | atomic_set(&vha->vp_state, VP_FAILED); | |
861 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); | |
2c3dfe3f SJ |
862 | } |
863 | ||
e315cd28 AC |
864 | if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) |
865 | set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); | |
866 | ||
867 | set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags); | |
868 | set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags); | |
4346b149 AV |
869 | |
870 | ha->flags.gpsc_supported = 1; | |
e315cd28 | 871 | vha->flags.management_server_logged_in = 0; |
1da177e4 LT |
872 | break; |
873 | ||
874 | case MBA_CHG_IN_CONNECTION: /* Change in connection mode */ | |
875 | if (IS_QLA2100(ha)) | |
876 | break; | |
877 | ||
cfb0919c | 878 | ql_dbg(ql_dbg_async, vha, 0x500f, |
1da177e4 LT |
879 | "Configuration change detected: value=%x.\n", mb[1]); |
880 | ||
e315cd28 AC |
881 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
882 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
883 | if (!atomic_read(&vha->loop_down_timer)) | |
884 | atomic_set(&vha->loop_down_timer, | |
1da177e4 | 885 | LOOP_DOWN_TIME); |
e315cd28 | 886 | qla2x00_mark_all_devices_lost(vha, 1); |
1da177e4 LT |
887 | } |
888 | ||
e315cd28 AC |
889 | if (vha->vp_idx) { |
890 | atomic_set(&vha->vp_state, VP_FAILED); | |
891 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); | |
2c3dfe3f SJ |
892 | } |
893 | ||
e315cd28 AC |
894 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
895 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); | |
1da177e4 LT |
896 | break; |
897 | ||
898 | case MBA_PORT_UPDATE: /* Port database update */ | |
55903b9d SV |
899 | /* |
900 | * Handle only global and vn-port update events | |
901 | * | |
902 | * Relevant inputs: | |
903 | * mb[1] = N_Port handle of changed port | |
904 | * OR 0xffff for global event | |
905 | * mb[2] = New login state | |
906 | * 7 = Port logged out | |
907 | * mb[3] = LSB is vp_idx, 0xff = all vps | |
908 | * | |
909 | * Skip processing if: | |
910 | * Event is global, vp_idx is NOT all vps, | |
911 | * vp_idx does not match | |
912 | * Event is not global, vp_idx does not match | |
913 | */ | |
12cec63e AV |
914 | if (IS_QLA2XXX_MIDTYPE(ha) && |
915 | ((mb[1] == 0xffff && (mb[3] & 0xff) != 0xff) || | |
916 | (mb[1] != 0xffff)) && vha->vp_idx != (mb[3] & 0xff)) | |
917 | break; | |
73208dfd | 918 | |
17cac3a1 | 919 | if (mb[2] == 0x7) { |
7c3df132 | 920 | ql_dbg(ql_dbg_async, vha, 0x5010, |
17cac3a1 JC |
921 | "Port %s %04x %04x %04x.\n", |
922 | mb[1] == 0xffff ? "unavailable" : "logout", | |
7c3df132 | 923 | mb[1], mb[2], mb[3]); |
17cac3a1 JC |
924 | |
925 | if (mb[1] == 0xffff) | |
926 | goto global_port_update; | |
927 | ||
928 | /* Port logout */ | |
929 | fcport = qla2x00_find_fcport_by_loopid(vha, mb[1]); | |
930 | if (!fcport) | |
931 | break; | |
932 | if (atomic_read(&fcport->state) != FCS_ONLINE) | |
933 | break; | |
934 | ql_dbg(ql_dbg_async, vha, 0x508a, | |
935 | "Marking port lost loopid=%04x portid=%06x.\n", | |
936 | fcport->loop_id, fcport->d_id.b24); | |
937 | qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1); | |
938 | break; | |
939 | ||
940 | global_port_update: | |
9764ff88 AV |
941 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
942 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
943 | atomic_set(&vha->loop_down_timer, | |
944 | LOOP_DOWN_TIME); | |
945 | vha->device_flags |= DFLG_NO_CABLE; | |
946 | qla2x00_mark_all_devices_lost(vha, 1); | |
947 | } | |
948 | ||
949 | if (vha->vp_idx) { | |
950 | atomic_set(&vha->vp_state, VP_FAILED); | |
951 | fc_vport_set_state(vha->fc_vport, | |
952 | FC_VPORT_FAILED); | |
faadc5e7 | 953 | qla2x00_mark_all_devices_lost(vha, 1); |
9764ff88 AV |
954 | } |
955 | ||
956 | vha->flags.management_server_logged_in = 0; | |
957 | ha->link_data_rate = PORT_SPEED_UNKNOWN; | |
958 | break; | |
959 | } | |
960 | ||
1da177e4 | 961 | /* |
cc3ef7bc | 962 | * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET |
1da177e4 LT |
963 | * event etc. earlier indicating loop is down) then process |
964 | * it. Otherwise ignore it and Wait for RSCN to come in. | |
965 | */ | |
e315cd28 | 966 | atomic_set(&vha->loop_down_timer, 0); |
8e5a9484 CD |
967 | if (atomic_read(&vha->loop_state) != LOOP_DOWN && |
968 | atomic_read(&vha->loop_state) != LOOP_DEAD) { | |
7c3df132 SK |
969 | ql_dbg(ql_dbg_async, vha, 0x5011, |
970 | "Asynchronous PORT UPDATE ignored %04x/%04x/%04x.\n", | |
971 | mb[1], mb[2], mb[3]); | |
2d70c103 NB |
972 | |
973 | qlt_async_event(mb[0], vha, mb); | |
1da177e4 LT |
974 | break; |
975 | } | |
976 | ||
7c3df132 SK |
977 | ql_dbg(ql_dbg_async, vha, 0x5012, |
978 | "Port database changed %04x %04x %04x.\n", | |
979 | mb[1], mb[2], mb[3]); | |
1da177e4 LT |
980 | |
981 | /* | |
982 | * Mark all devices as missing so we will login again. | |
983 | */ | |
e315cd28 | 984 | atomic_set(&vha->loop_state, LOOP_UP); |
1da177e4 | 985 | |
e315cd28 | 986 | qla2x00_mark_all_devices_lost(vha, 1); |
1da177e4 | 987 | |
2d70c103 NB |
988 | if (vha->vp_idx == 0 && !qla_ini_mode_enabled(vha)) |
989 | set_bit(SCR_PENDING, &vha->dpc_flags); | |
990 | ||
e315cd28 AC |
991 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
992 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); | |
ded6411f | 993 | set_bit(VP_CONFIG_OK, &vha->vp_flags); |
2d70c103 NB |
994 | |
995 | qlt_async_event(mb[0], vha, mb); | |
1da177e4 LT |
996 | break; |
997 | ||
998 | case MBA_RSCN_UPDATE: /* State Change Registration */ | |
3c397400 | 999 | /* Check if the Vport has issued a SCR */ |
e315cd28 | 1000 | if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags)) |
3c397400 SJ |
1001 | break; |
1002 | /* Only handle SCNs for our Vport index. */ | |
0d6e61bc | 1003 | if (ha->flags.npiv_supported && vha->vp_idx != (mb[3] & 0xff)) |
3c397400 | 1004 | break; |
0d6e61bc | 1005 | |
7c3df132 SK |
1006 | ql_dbg(ql_dbg_async, vha, 0x5013, |
1007 | "RSCN database changed -- %04x %04x %04x.\n", | |
1008 | mb[1], mb[2], mb[3]); | |
1da177e4 | 1009 | |
59d72d87 | 1010 | rscn_entry = ((mb[1] & 0xff) << 16) | mb[2]; |
e315cd28 AC |
1011 | host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8) |
1012 | | vha->d_id.b.al_pa; | |
1da177e4 | 1013 | if (rscn_entry == host_pid) { |
7c3df132 SK |
1014 | ql_dbg(ql_dbg_async, vha, 0x5014, |
1015 | "Ignoring RSCN update to local host " | |
1016 | "port ID (%06x).\n", host_pid); | |
1da177e4 LT |
1017 | break; |
1018 | } | |
1019 | ||
59d72d87 RA |
1020 | /* Ignore reserved bits from RSCN-payload. */ |
1021 | rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2]; | |
1da177e4 | 1022 | |
bb4cf5b7 CD |
1023 | /* Skip RSCNs for virtual ports on the same physical port */ |
1024 | if (qla2x00_is_a_vp_did(vha, rscn_entry)) | |
1025 | break; | |
1026 | ||
ef86cb20 CD |
1027 | /* |
1028 | * Search for the rport related to this RSCN entry and mark it | |
1029 | * as lost. | |
1030 | */ | |
1031 | list_for_each_entry(fcport, &vha->vp_fcports, list) { | |
1032 | if (atomic_read(&fcport->state) != FCS_ONLINE) | |
1033 | continue; | |
ef86cb20 CD |
1034 | if (fcport->d_id.b24 == rscn_entry) { |
1035 | qla2x00_mark_device_lost(vha, fcport, 0, 0); | |
1036 | break; | |
1037 | } | |
1038 | } | |
1039 | ||
e315cd28 AC |
1040 | atomic_set(&vha->loop_down_timer, 0); |
1041 | vha->flags.management_server_logged_in = 0; | |
1da177e4 | 1042 | |
e315cd28 AC |
1043 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
1044 | set_bit(RSCN_UPDATE, &vha->dpc_flags); | |
1045 | qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry); | |
1da177e4 LT |
1046 | break; |
1047 | ||
1048 | /* case MBA_RIO_RESPONSE: */ | |
1049 | case MBA_ZIO_RESPONSE: | |
7c3df132 SK |
1050 | ql_dbg(ql_dbg_async, vha, 0x5015, |
1051 | "[R|Z]IO update completion.\n"); | |
1da177e4 | 1052 | |
e428924c | 1053 | if (IS_FWI2_CAPABLE(ha)) |
2afa19a9 | 1054 | qla24xx_process_response_queue(vha, rsp); |
4fdfefe5 | 1055 | else |
73208dfd | 1056 | qla2x00_process_response_queue(rsp); |
1da177e4 | 1057 | break; |
9a853f71 AV |
1058 | |
1059 | case MBA_DISCARD_RND_FRAME: | |
7c3df132 SK |
1060 | ql_dbg(ql_dbg_async, vha, 0x5016, |
1061 | "Discard RND Frame -- %04x %04x %04x.\n", | |
1062 | mb[1], mb[2], mb[3]); | |
9a853f71 | 1063 | break; |
45ebeb56 AV |
1064 | |
1065 | case MBA_TRACE_NOTIFICATION: | |
7c3df132 SK |
1066 | ql_dbg(ql_dbg_async, vha, 0x5017, |
1067 | "Trace Notification -- %04x %04x.\n", mb[1], mb[2]); | |
45ebeb56 | 1068 | break; |
4d4df193 HK |
1069 | |
1070 | case MBA_ISP84XX_ALERT: | |
7c3df132 SK |
1071 | ql_dbg(ql_dbg_async, vha, 0x5018, |
1072 | "ISP84XX Alert Notification -- %04x %04x %04x.\n", | |
1073 | mb[1], mb[2], mb[3]); | |
4d4df193 HK |
1074 | |
1075 | spin_lock_irqsave(&ha->cs84xx->access_lock, flags); | |
1076 | switch (mb[1]) { | |
1077 | case A84_PANIC_RECOVERY: | |
7c3df132 SK |
1078 | ql_log(ql_log_info, vha, 0x5019, |
1079 | "Alert 84XX: panic recovery %04x %04x.\n", | |
1080 | mb[2], mb[3]); | |
4d4df193 HK |
1081 | break; |
1082 | case A84_OP_LOGIN_COMPLETE: | |
1083 | ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2]; | |
7c3df132 SK |
1084 | ql_log(ql_log_info, vha, 0x501a, |
1085 | "Alert 84XX: firmware version %x.\n", | |
1086 | ha->cs84xx->op_fw_version); | |
4d4df193 HK |
1087 | break; |
1088 | case A84_DIAG_LOGIN_COMPLETE: | |
1089 | ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2]; | |
7c3df132 SK |
1090 | ql_log(ql_log_info, vha, 0x501b, |
1091 | "Alert 84XX: diagnostic firmware version %x.\n", | |
1092 | ha->cs84xx->diag_fw_version); | |
4d4df193 HK |
1093 | break; |
1094 | case A84_GOLD_LOGIN_COMPLETE: | |
1095 | ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2]; | |
1096 | ha->cs84xx->fw_update = 1; | |
7c3df132 SK |
1097 | ql_log(ql_log_info, vha, 0x501c, |
1098 | "Alert 84XX: gold firmware version %x.\n", | |
1099 | ha->cs84xx->gold_fw_version); | |
4d4df193 HK |
1100 | break; |
1101 | default: | |
7c3df132 SK |
1102 | ql_log(ql_log_warn, vha, 0x501d, |
1103 | "Alert 84xx: Invalid Alert %04x %04x %04x.\n", | |
4d4df193 HK |
1104 | mb[1], mb[2], mb[3]); |
1105 | } | |
1106 | spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags); | |
1107 | break; | |
3a03eb79 | 1108 | case MBA_DCBX_START: |
7c3df132 SK |
1109 | ql_dbg(ql_dbg_async, vha, 0x501e, |
1110 | "DCBX Started -- %04x %04x %04x.\n", | |
1111 | mb[1], mb[2], mb[3]); | |
3a03eb79 AV |
1112 | break; |
1113 | case MBA_DCBX_PARAM_UPDATE: | |
7c3df132 SK |
1114 | ql_dbg(ql_dbg_async, vha, 0x501f, |
1115 | "DCBX Parameters Updated -- %04x %04x %04x.\n", | |
1116 | mb[1], mb[2], mb[3]); | |
3a03eb79 AV |
1117 | break; |
1118 | case MBA_FCF_CONF_ERR: | |
7c3df132 SK |
1119 | ql_dbg(ql_dbg_async, vha, 0x5020, |
1120 | "FCF Configuration Error -- %04x %04x %04x.\n", | |
1121 | mb[1], mb[2], mb[3]); | |
3a03eb79 | 1122 | break; |
3a03eb79 | 1123 | case MBA_IDC_NOTIFY: |
7ec0effd | 1124 | if (IS_QLA8031(vha->hw) || IS_QLA8044(ha)) { |
67b2a31f CD |
1125 | mb[4] = RD_REG_WORD(®24->mailbox4); |
1126 | if (((mb[2] & 0x7fff) == MBC_PORT_RESET || | |
1127 | (mb[2] & 0x7fff) == MBC_SET_PORT_CONFIG) && | |
1128 | (mb[4] & INTERNAL_LOOPBACK_MASK) != 0) { | |
8fcd6b8b | 1129 | set_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags); |
67b2a31f CD |
1130 | /* |
1131 | * Extend loop down timer since port is active. | |
1132 | */ | |
1133 | if (atomic_read(&vha->loop_state) == LOOP_DOWN) | |
1134 | atomic_set(&vha->loop_down_timer, | |
1135 | LOOP_DOWN_TIME); | |
8fcd6b8b CD |
1136 | qla2xxx_wake_dpc(vha); |
1137 | } | |
67b2a31f | 1138 | } |
8fcd6b8b | 1139 | case MBA_IDC_COMPLETE: |
9aaf2cea | 1140 | if (ha->notify_lb_portup_comp && !vha->vp_idx) |
f356bef1 CD |
1141 | complete(&ha->lb_portup_comp); |
1142 | /* Fallthru */ | |
3a03eb79 | 1143 | case MBA_IDC_TIME_EXT: |
7ec0effd AD |
1144 | if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) || |
1145 | IS_QLA8044(ha)) | |
7d613ac6 SV |
1146 | qla81xx_idc_event(vha, mb[0], mb[1]); |
1147 | break; | |
1148 | ||
1149 | case MBA_IDC_AEN: | |
1150 | mb[4] = RD_REG_WORD(®24->mailbox4); | |
1151 | mb[5] = RD_REG_WORD(®24->mailbox5); | |
1152 | mb[6] = RD_REG_WORD(®24->mailbox6); | |
1153 | mb[7] = RD_REG_WORD(®24->mailbox7); | |
1154 | qla83xx_handle_8200_aen(vha, mb); | |
3a03eb79 | 1155 | break; |
7d613ac6 | 1156 | |
b5a340dd JC |
1157 | case MBA_DPORT_DIAGNOSTICS: |
1158 | ql_dbg(ql_dbg_async, vha, 0x5052, | |
ef55e513 | 1159 | "D-Port Diagnostics: %04x result=%s\n", |
ec891462 | 1160 | mb[0], |
b5a340dd | 1161 | mb[1] == 0 ? "start" : |
ef55e513 JC |
1162 | mb[1] == 1 ? "done (pass)" : |
1163 | mb[1] == 2 ? "done (error)" : "other"); | |
b5a340dd JC |
1164 | break; |
1165 | ||
a29b3dd7 JC |
1166 | case MBA_TEMPERATURE_ALERT: |
1167 | ql_dbg(ql_dbg_async, vha, 0x505e, | |
1168 | "TEMPERATURE ALERT: %04x %04x %04x\n", mb[1], mb[2], mb[3]); | |
1169 | if (mb[1] == 0x12) | |
1170 | schedule_work(&ha->board_disable); | |
1171 | break; | |
1172 | ||
6246b8a1 GM |
1173 | default: |
1174 | ql_dbg(ql_dbg_async, vha, 0x5057, | |
1175 | "Unknown AEN:%04x %04x %04x %04x\n", | |
1176 | mb[0], mb[1], mb[2], mb[3]); | |
1da177e4 | 1177 | } |
2c3dfe3f | 1178 | |
2d70c103 NB |
1179 | qlt_async_event(mb[0], vha, mb); |
1180 | ||
e315cd28 | 1181 | if (!vha->vp_idx && ha->num_vhosts) |
73208dfd | 1182 | qla2x00_alert_all_vps(rsp, mb); |
1da177e4 LT |
1183 | } |
1184 | ||
1185 | /** | |
1186 | * qla2x00_process_completed_request() - Process a Fast Post response. | |
1187 | * @ha: SCSI driver HA context | |
1188 | * @index: SRB index | |
1189 | */ | |
8ae6d9c7 | 1190 | void |
73208dfd | 1191 | qla2x00_process_completed_request(struct scsi_qla_host *vha, |
8ae6d9c7 | 1192 | struct req_que *req, uint32_t index) |
1da177e4 LT |
1193 | { |
1194 | srb_t *sp; | |
e315cd28 | 1195 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
1196 | |
1197 | /* Validate handle. */ | |
8d93f550 | 1198 | if (index >= req->num_outstanding_cmds) { |
7c3df132 SK |
1199 | ql_log(ql_log_warn, vha, 0x3014, |
1200 | "Invalid SCSI command index (%x).\n", index); | |
1da177e4 | 1201 | |
7ec0effd | 1202 | if (IS_P3P_TYPE(ha)) |
8f7daead GM |
1203 | set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags); |
1204 | else | |
1205 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
1da177e4 LT |
1206 | return; |
1207 | } | |
1208 | ||
e315cd28 | 1209 | sp = req->outstanding_cmds[index]; |
1da177e4 LT |
1210 | if (sp) { |
1211 | /* Free outstanding command slot. */ | |
e315cd28 | 1212 | req->outstanding_cmds[index] = NULL; |
1da177e4 | 1213 | |
1da177e4 | 1214 | /* Save ISP completion status */ |
9ba56b95 | 1215 | sp->done(ha, sp, DID_OK << 16); |
1da177e4 | 1216 | } else { |
7c3df132 | 1217 | ql_log(ql_log_warn, vha, 0x3016, "Invalid SCSI SRB.\n"); |
1da177e4 | 1218 | |
7ec0effd | 1219 | if (IS_P3P_TYPE(ha)) |
8f7daead GM |
1220 | set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags); |
1221 | else | |
1222 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
1da177e4 LT |
1223 | } |
1224 | } | |
1225 | ||
8ae6d9c7 | 1226 | srb_t * |
ac280b67 AV |
1227 | qla2x00_get_sp_from_handle(scsi_qla_host_t *vha, const char *func, |
1228 | struct req_que *req, void *iocb) | |
1229 | { | |
1230 | struct qla_hw_data *ha = vha->hw; | |
1231 | sts_entry_t *pkt = iocb; | |
1232 | srb_t *sp = NULL; | |
1233 | uint16_t index; | |
1234 | ||
1235 | index = LSW(pkt->handle); | |
8d93f550 | 1236 | if (index >= req->num_outstanding_cmds) { |
7c3df132 SK |
1237 | ql_log(ql_log_warn, vha, 0x5031, |
1238 | "Invalid command index (%x).\n", index); | |
7ec0effd | 1239 | if (IS_P3P_TYPE(ha)) |
8f7daead GM |
1240 | set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags); |
1241 | else | |
1242 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
ac280b67 AV |
1243 | goto done; |
1244 | } | |
1245 | sp = req->outstanding_cmds[index]; | |
1246 | if (!sp) { | |
7c3df132 SK |
1247 | ql_log(ql_log_warn, vha, 0x5032, |
1248 | "Invalid completion handle (%x) -- timed-out.\n", index); | |
ac280b67 AV |
1249 | return sp; |
1250 | } | |
1251 | if (sp->handle != index) { | |
7c3df132 SK |
1252 | ql_log(ql_log_warn, vha, 0x5033, |
1253 | "SRB handle (%x) mismatch %x.\n", sp->handle, index); | |
ac280b67 AV |
1254 | return NULL; |
1255 | } | |
9a069e19 | 1256 | |
ac280b67 | 1257 | req->outstanding_cmds[index] = NULL; |
9a069e19 | 1258 | |
ac280b67 AV |
1259 | done: |
1260 | return sp; | |
1261 | } | |
1262 | ||
1263 | static void | |
1264 | qla2x00_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req, | |
1265 | struct mbx_entry *mbx) | |
1266 | { | |
1267 | const char func[] = "MBX-IOCB"; | |
1268 | const char *type; | |
ac280b67 AV |
1269 | fc_port_t *fcport; |
1270 | srb_t *sp; | |
4916392b | 1271 | struct srb_iocb *lio; |
99b0bec7 | 1272 | uint16_t *data; |
5ff1d584 | 1273 | uint16_t status; |
ac280b67 AV |
1274 | |
1275 | sp = qla2x00_get_sp_from_handle(vha, func, req, mbx); | |
1276 | if (!sp) | |
1277 | return; | |
1278 | ||
9ba56b95 GM |
1279 | lio = &sp->u.iocb_cmd; |
1280 | type = sp->name; | |
ac280b67 | 1281 | fcport = sp->fcport; |
4916392b | 1282 | data = lio->u.logio.data; |
ac280b67 | 1283 | |
5ff1d584 | 1284 | data[0] = MBS_COMMAND_ERROR; |
4916392b | 1285 | data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ? |
5ff1d584 | 1286 | QLA_LOGIO_LOGIN_RETRIED : 0; |
ac280b67 | 1287 | if (mbx->entry_status) { |
7c3df132 | 1288 | ql_dbg(ql_dbg_async, vha, 0x5043, |
cfb0919c | 1289 | "Async-%s error entry - hdl=%x portid=%02x%02x%02x " |
d3fa9e7d | 1290 | "entry-status=%x status=%x state-flag=%x " |
cfb0919c CD |
1291 | "status-flags=%x.\n", type, sp->handle, |
1292 | fcport->d_id.b.domain, fcport->d_id.b.area, | |
d3fa9e7d AV |
1293 | fcport->d_id.b.al_pa, mbx->entry_status, |
1294 | le16_to_cpu(mbx->status), le16_to_cpu(mbx->state_flags), | |
7c3df132 | 1295 | le16_to_cpu(mbx->status_flags)); |
d3fa9e7d | 1296 | |
cfb0919c | 1297 | ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5029, |
7c3df132 | 1298 | (uint8_t *)mbx, sizeof(*mbx)); |
ac280b67 | 1299 | |
99b0bec7 | 1300 | goto logio_done; |
ac280b67 AV |
1301 | } |
1302 | ||
5ff1d584 | 1303 | status = le16_to_cpu(mbx->status); |
9ba56b95 | 1304 | if (status == 0x30 && sp->type == SRB_LOGIN_CMD && |
5ff1d584 AV |
1305 | le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE) |
1306 | status = 0; | |
1307 | if (!status && le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE) { | |
7c3df132 | 1308 | ql_dbg(ql_dbg_async, vha, 0x5045, |
cfb0919c CD |
1309 | "Async-%s complete - hdl=%x portid=%02x%02x%02x mbx1=%x.\n", |
1310 | type, sp->handle, fcport->d_id.b.domain, | |
1311 | fcport->d_id.b.area, fcport->d_id.b.al_pa, | |
1312 | le16_to_cpu(mbx->mb1)); | |
ac280b67 AV |
1313 | |
1314 | data[0] = MBS_COMMAND_COMPLETE; | |
9ba56b95 | 1315 | if (sp->type == SRB_LOGIN_CMD) { |
99b0bec7 AV |
1316 | fcport->port_type = FCT_TARGET; |
1317 | if (le16_to_cpu(mbx->mb1) & BIT_0) | |
1318 | fcport->port_type = FCT_INITIATOR; | |
6ac52608 | 1319 | else if (le16_to_cpu(mbx->mb1) & BIT_1) |
99b0bec7 | 1320 | fcport->flags |= FCF_FCP2_DEVICE; |
5ff1d584 | 1321 | } |
99b0bec7 | 1322 | goto logio_done; |
ac280b67 AV |
1323 | } |
1324 | ||
1325 | data[0] = le16_to_cpu(mbx->mb0); | |
1326 | switch (data[0]) { | |
1327 | case MBS_PORT_ID_USED: | |
1328 | data[1] = le16_to_cpu(mbx->mb1); | |
1329 | break; | |
1330 | case MBS_LOOP_ID_USED: | |
1331 | break; | |
1332 | default: | |
1333 | data[0] = MBS_COMMAND_ERROR; | |
ac280b67 AV |
1334 | break; |
1335 | } | |
1336 | ||
7c3df132 | 1337 | ql_log(ql_log_warn, vha, 0x5046, |
cfb0919c CD |
1338 | "Async-%s failed - hdl=%x portid=%02x%02x%02x status=%x " |
1339 | "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n", type, sp->handle, | |
1340 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa, | |
1341 | status, le16_to_cpu(mbx->mb0), le16_to_cpu(mbx->mb1), | |
ac280b67 | 1342 | le16_to_cpu(mbx->mb2), le16_to_cpu(mbx->mb6), |
7c3df132 | 1343 | le16_to_cpu(mbx->mb7)); |
ac280b67 | 1344 | |
99b0bec7 | 1345 | logio_done: |
9ba56b95 | 1346 | sp->done(vha, sp, 0); |
ac280b67 AV |
1347 | } |
1348 | ||
9bc4f4fb HZ |
1349 | static void |
1350 | qla2x00_ct_entry(scsi_qla_host_t *vha, struct req_que *req, | |
1351 | sts_entry_t *pkt, int iocb_type) | |
1352 | { | |
1353 | const char func[] = "CT_IOCB"; | |
1354 | const char *type; | |
9bc4f4fb | 1355 | srb_t *sp; |
75cc8cfc | 1356 | struct bsg_job *bsg_job; |
01e0e15c | 1357 | struct fc_bsg_reply *bsg_reply; |
9bc4f4fb | 1358 | uint16_t comp_status; |
9ba56b95 | 1359 | int res; |
9bc4f4fb HZ |
1360 | |
1361 | sp = qla2x00_get_sp_from_handle(vha, func, req, pkt); | |
1362 | if (!sp) | |
1363 | return; | |
1364 | ||
9ba56b95 | 1365 | bsg_job = sp->u.bsg_job; |
01e0e15c | 1366 | bsg_reply = bsg_job->reply; |
9bc4f4fb | 1367 | |
9ba56b95 | 1368 | type = "ct pass-through"; |
9bc4f4fb HZ |
1369 | |
1370 | comp_status = le16_to_cpu(pkt->comp_status); | |
1371 | ||
1372 | /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT | |
1373 | * fc payload to the caller | |
1374 | */ | |
01e0e15c | 1375 | bsg_reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK; |
9bc4f4fb HZ |
1376 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); |
1377 | ||
1378 | if (comp_status != CS_COMPLETE) { | |
1379 | if (comp_status == CS_DATA_UNDERRUN) { | |
9ba56b95 | 1380 | res = DID_OK << 16; |
01e0e15c | 1381 | bsg_reply->reply_payload_rcv_len = |
9bc4f4fb HZ |
1382 | le16_to_cpu(((sts_entry_t *)pkt)->rsp_info_len); |
1383 | ||
7c3df132 SK |
1384 | ql_log(ql_log_warn, vha, 0x5048, |
1385 | "CT pass-through-%s error " | |
9bc4f4fb | 1386 | "comp_status-status=0x%x total_byte = 0x%x.\n", |
7c3df132 | 1387 | type, comp_status, |
01e0e15c | 1388 | bsg_reply->reply_payload_rcv_len); |
9bc4f4fb | 1389 | } else { |
7c3df132 SK |
1390 | ql_log(ql_log_warn, vha, 0x5049, |
1391 | "CT pass-through-%s error " | |
1392 | "comp_status-status=0x%x.\n", type, comp_status); | |
9ba56b95 | 1393 | res = DID_ERROR << 16; |
01e0e15c | 1394 | bsg_reply->reply_payload_rcv_len = 0; |
9bc4f4fb | 1395 | } |
cfb0919c | 1396 | ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5035, |
7c3df132 | 1397 | (uint8_t *)pkt, sizeof(*pkt)); |
9bc4f4fb | 1398 | } else { |
9ba56b95 | 1399 | res = DID_OK << 16; |
01e0e15c | 1400 | bsg_reply->reply_payload_rcv_len = |
9bc4f4fb HZ |
1401 | bsg_job->reply_payload.payload_len; |
1402 | bsg_job->reply_len = 0; | |
1403 | } | |
1404 | ||
9ba56b95 | 1405 | sp->done(vha, sp, res); |
9bc4f4fb HZ |
1406 | } |
1407 | ||
9a069e19 GM |
1408 | static void |
1409 | qla24xx_els_ct_entry(scsi_qla_host_t *vha, struct req_que *req, | |
1410 | struct sts_entry_24xx *pkt, int iocb_type) | |
1411 | { | |
1412 | const char func[] = "ELS_CT_IOCB"; | |
1413 | const char *type; | |
9a069e19 | 1414 | srb_t *sp; |
75cc8cfc | 1415 | struct bsg_job *bsg_job; |
01e0e15c | 1416 | struct fc_bsg_reply *bsg_reply; |
9a069e19 GM |
1417 | uint16_t comp_status; |
1418 | uint32_t fw_status[3]; | |
1419 | uint8_t* fw_sts_ptr; | |
9ba56b95 | 1420 | int res; |
9a069e19 GM |
1421 | |
1422 | sp = qla2x00_get_sp_from_handle(vha, func, req, pkt); | |
1423 | if (!sp) | |
1424 | return; | |
9ba56b95 | 1425 | bsg_job = sp->u.bsg_job; |
01e0e15c | 1426 | bsg_reply = bsg_job->reply; |
9a069e19 GM |
1427 | |
1428 | type = NULL; | |
9ba56b95 | 1429 | switch (sp->type) { |
9a069e19 GM |
1430 | case SRB_ELS_CMD_RPT: |
1431 | case SRB_ELS_CMD_HST: | |
1432 | type = "els"; | |
1433 | break; | |
1434 | case SRB_CT_CMD: | |
1435 | type = "ct pass-through"; | |
1436 | break; | |
6eb54715 HM |
1437 | case SRB_ELS_DCMD: |
1438 | type = "Driver ELS logo"; | |
1439 | ql_dbg(ql_dbg_user, vha, 0x5047, | |
1440 | "Completing %s: (%p) type=%d.\n", type, sp, sp->type); | |
1441 | sp->done(vha, sp, 0); | |
1442 | return; | |
9a069e19 | 1443 | default: |
37fed3ee | 1444 | ql_dbg(ql_dbg_user, vha, 0x503e, |
9ba56b95 | 1445 | "Unrecognized SRB: (%p) type=%d.\n", sp, sp->type); |
9a069e19 GM |
1446 | return; |
1447 | } | |
1448 | ||
1449 | comp_status = fw_status[0] = le16_to_cpu(pkt->comp_status); | |
1450 | fw_status[1] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1); | |
1451 | fw_status[2] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2); | |
1452 | ||
1453 | /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT | |
1454 | * fc payload to the caller | |
1455 | */ | |
01e0e15c | 1456 | bsg_reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK; |
9a069e19 GM |
1457 | bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(fw_status); |
1458 | ||
1459 | if (comp_status != CS_COMPLETE) { | |
1460 | if (comp_status == CS_DATA_UNDERRUN) { | |
9ba56b95 | 1461 | res = DID_OK << 16; |
01e0e15c | 1462 | bsg_reply->reply_payload_rcv_len = |
9ba56b95 | 1463 | le16_to_cpu(((struct els_sts_entry_24xx *)pkt)->total_byte_count); |
9a069e19 | 1464 | |
37fed3ee | 1465 | ql_dbg(ql_dbg_user, vha, 0x503f, |
cfb0919c | 1466 | "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x " |
9a069e19 | 1467 | "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n", |
cfb0919c | 1468 | type, sp->handle, comp_status, fw_status[1], fw_status[2], |
7c3df132 SK |
1469 | le16_to_cpu(((struct els_sts_entry_24xx *) |
1470 | pkt)->total_byte_count)); | |
9a069e19 GM |
1471 | fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply); |
1472 | memcpy( fw_sts_ptr, fw_status, sizeof(fw_status)); | |
1473 | } | |
1474 | else { | |
37fed3ee | 1475 | ql_dbg(ql_dbg_user, vha, 0x5040, |
cfb0919c | 1476 | "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x " |
9a069e19 | 1477 | "error subcode 1=0x%x error subcode 2=0x%x.\n", |
cfb0919c | 1478 | type, sp->handle, comp_status, |
7c3df132 SK |
1479 | le16_to_cpu(((struct els_sts_entry_24xx *) |
1480 | pkt)->error_subcode_1), | |
1481 | le16_to_cpu(((struct els_sts_entry_24xx *) | |
1482 | pkt)->error_subcode_2)); | |
9ba56b95 | 1483 | res = DID_ERROR << 16; |
01e0e15c | 1484 | bsg_reply->reply_payload_rcv_len = 0; |
9a069e19 GM |
1485 | fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply); |
1486 | memcpy( fw_sts_ptr, fw_status, sizeof(fw_status)); | |
1487 | } | |
37fed3ee | 1488 | ql_dump_buffer(ql_dbg_user + ql_dbg_buffer, vha, 0x5056, |
7c3df132 | 1489 | (uint8_t *)pkt, sizeof(*pkt)); |
9a069e19 GM |
1490 | } |
1491 | else { | |
9ba56b95 | 1492 | res = DID_OK << 16; |
01e0e15c | 1493 | bsg_reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len; |
9a069e19 GM |
1494 | bsg_job->reply_len = 0; |
1495 | } | |
1496 | ||
9ba56b95 | 1497 | sp->done(vha, sp, res); |
9a069e19 GM |
1498 | } |
1499 | ||
ac280b67 AV |
1500 | static void |
1501 | qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req, | |
1502 | struct logio_entry_24xx *logio) | |
1503 | { | |
1504 | const char func[] = "LOGIO-IOCB"; | |
1505 | const char *type; | |
ac280b67 AV |
1506 | fc_port_t *fcport; |
1507 | srb_t *sp; | |
4916392b | 1508 | struct srb_iocb *lio; |
99b0bec7 | 1509 | uint16_t *data; |
ac280b67 AV |
1510 | uint32_t iop[2]; |
1511 | ||
1512 | sp = qla2x00_get_sp_from_handle(vha, func, req, logio); | |
1513 | if (!sp) | |
1514 | return; | |
1515 | ||
9ba56b95 GM |
1516 | lio = &sp->u.iocb_cmd; |
1517 | type = sp->name; | |
ac280b67 | 1518 | fcport = sp->fcport; |
4916392b | 1519 | data = lio->u.logio.data; |
ac280b67 | 1520 | |
5ff1d584 | 1521 | data[0] = MBS_COMMAND_ERROR; |
4916392b | 1522 | data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ? |
5ff1d584 | 1523 | QLA_LOGIO_LOGIN_RETRIED : 0; |
ac280b67 | 1524 | if (logio->entry_status) { |
5e19ed90 | 1525 | ql_log(ql_log_warn, fcport->vha, 0x5034, |
cfb0919c | 1526 | "Async-%s error entry - hdl=%x" |
d3fa9e7d | 1527 | "portid=%02x%02x%02x entry-status=%x.\n", |
cfb0919c CD |
1528 | type, sp->handle, fcport->d_id.b.domain, |
1529 | fcport->d_id.b.area, fcport->d_id.b.al_pa, | |
1530 | logio->entry_status); | |
1531 | ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x504d, | |
7c3df132 | 1532 | (uint8_t *)logio, sizeof(*logio)); |
ac280b67 | 1533 | |
99b0bec7 | 1534 | goto logio_done; |
ac280b67 AV |
1535 | } |
1536 | ||
1537 | if (le16_to_cpu(logio->comp_status) == CS_COMPLETE) { | |
5e19ed90 | 1538 | ql_dbg(ql_dbg_async, fcport->vha, 0x5036, |
cfb0919c CD |
1539 | "Async-%s complete - hdl=%x portid=%02x%02x%02x " |
1540 | "iop0=%x.\n", type, sp->handle, fcport->d_id.b.domain, | |
1541 | fcport->d_id.b.area, fcport->d_id.b.al_pa, | |
7c3df132 | 1542 | le32_to_cpu(logio->io_parameter[0])); |
ac280b67 AV |
1543 | |
1544 | data[0] = MBS_COMMAND_COMPLETE; | |
9ba56b95 | 1545 | if (sp->type != SRB_LOGIN_CMD) |
99b0bec7 | 1546 | goto logio_done; |
ac280b67 AV |
1547 | |
1548 | iop[0] = le32_to_cpu(logio->io_parameter[0]); | |
1549 | if (iop[0] & BIT_4) { | |
1550 | fcport->port_type = FCT_TARGET; | |
1551 | if (iop[0] & BIT_8) | |
8474f3a0 | 1552 | fcport->flags |= FCF_FCP2_DEVICE; |
b0cd579c | 1553 | } else if (iop[0] & BIT_5) |
ac280b67 | 1554 | fcport->port_type = FCT_INITIATOR; |
b0cd579c | 1555 | |
2d70c103 NB |
1556 | if (iop[0] & BIT_7) |
1557 | fcport->flags |= FCF_CONF_COMP_SUPPORTED; | |
1558 | ||
ac280b67 AV |
1559 | if (logio->io_parameter[7] || logio->io_parameter[8]) |
1560 | fcport->supported_classes |= FC_COS_CLASS2; | |
1561 | if (logio->io_parameter[9] || logio->io_parameter[10]) | |
1562 | fcport->supported_classes |= FC_COS_CLASS3; | |
1563 | ||
99b0bec7 | 1564 | goto logio_done; |
ac280b67 AV |
1565 | } |
1566 | ||
1567 | iop[0] = le32_to_cpu(logio->io_parameter[0]); | |
1568 | iop[1] = le32_to_cpu(logio->io_parameter[1]); | |
1569 | switch (iop[0]) { | |
1570 | case LSC_SCODE_PORTID_USED: | |
1571 | data[0] = MBS_PORT_ID_USED; | |
1572 | data[1] = LSW(iop[1]); | |
1573 | break; | |
1574 | case LSC_SCODE_NPORT_USED: | |
1575 | data[0] = MBS_LOOP_ID_USED; | |
1576 | break; | |
ac280b67 AV |
1577 | default: |
1578 | data[0] = MBS_COMMAND_ERROR; | |
ac280b67 AV |
1579 | break; |
1580 | } | |
1581 | ||
5e19ed90 | 1582 | ql_dbg(ql_dbg_async, fcport->vha, 0x5037, |
cfb0919c CD |
1583 | "Async-%s failed - hdl=%x portid=%02x%02x%02x comp=%x " |
1584 | "iop0=%x iop1=%x.\n", type, sp->handle, fcport->d_id.b.domain, | |
d3fa9e7d | 1585 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
ac280b67 AV |
1586 | le16_to_cpu(logio->comp_status), |
1587 | le32_to_cpu(logio->io_parameter[0]), | |
7c3df132 | 1588 | le32_to_cpu(logio->io_parameter[1])); |
ac280b67 | 1589 | |
99b0bec7 | 1590 | logio_done: |
9ba56b95 | 1591 | sp->done(vha, sp, 0); |
ac280b67 AV |
1592 | } |
1593 | ||
3822263e | 1594 | static void |
faef62d1 | 1595 | qla24xx_tm_iocb_entry(scsi_qla_host_t *vha, struct req_que *req, void *tsk) |
3822263e MI |
1596 | { |
1597 | const char func[] = "TMF-IOCB"; | |
1598 | const char *type; | |
1599 | fc_port_t *fcport; | |
1600 | srb_t *sp; | |
1601 | struct srb_iocb *iocb; | |
3822263e | 1602 | struct sts_entry_24xx *sts = (struct sts_entry_24xx *)tsk; |
3822263e MI |
1603 | |
1604 | sp = qla2x00_get_sp_from_handle(vha, func, req, tsk); | |
1605 | if (!sp) | |
1606 | return; | |
1607 | ||
9ba56b95 GM |
1608 | iocb = &sp->u.iocb_cmd; |
1609 | type = sp->name; | |
3822263e | 1610 | fcport = sp->fcport; |
faef62d1 | 1611 | iocb->u.tmf.data = QLA_SUCCESS; |
3822263e MI |
1612 | |
1613 | if (sts->entry_status) { | |
5e19ed90 | 1614 | ql_log(ql_log_warn, fcport->vha, 0x5038, |
cfb0919c CD |
1615 | "Async-%s error - hdl=%x entry-status(%x).\n", |
1616 | type, sp->handle, sts->entry_status); | |
faef62d1 | 1617 | iocb->u.tmf.data = QLA_FUNCTION_FAILED; |
ad950360 | 1618 | } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) { |
5e19ed90 | 1619 | ql_log(ql_log_warn, fcport->vha, 0x5039, |
cfb0919c CD |
1620 | "Async-%s error - hdl=%x completion status(%x).\n", |
1621 | type, sp->handle, sts->comp_status); | |
faef62d1 AB |
1622 | iocb->u.tmf.data = QLA_FUNCTION_FAILED; |
1623 | } else if ((le16_to_cpu(sts->scsi_status) & | |
3822263e | 1624 | SS_RESPONSE_INFO_LEN_VALID)) { |
faef62d1 AB |
1625 | if (le32_to_cpu(sts->rsp_data_len) < 4) { |
1626 | ql_log(ql_log_warn, fcport->vha, 0x503b, | |
1627 | "Async-%s error - hdl=%x not enough response(%d).\n", | |
1628 | type, sp->handle, sts->rsp_data_len); | |
1629 | } else if (sts->data[3]) { | |
1630 | ql_log(ql_log_warn, fcport->vha, 0x503c, | |
1631 | "Async-%s error - hdl=%x response(%x).\n", | |
1632 | type, sp->handle, sts->data[3]); | |
8d2b21db | 1633 | iocb->u.tmf.data = QLA_FUNCTION_FAILED; |
faef62d1 | 1634 | } |
3822263e MI |
1635 | } |
1636 | ||
faef62d1 | 1637 | if (iocb->u.tmf.data != QLA_SUCCESS) |
7c3df132 SK |
1638 | ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5055, |
1639 | (uint8_t *)sts, sizeof(*sts)); | |
3822263e | 1640 | |
9ba56b95 | 1641 | sp->done(vha, sp, 0); |
3822263e MI |
1642 | } |
1643 | ||
1da177e4 LT |
1644 | /** |
1645 | * qla2x00_process_response_queue() - Process response queue entries. | |
1646 | * @ha: SCSI driver HA context | |
1647 | */ | |
1648 | void | |
73208dfd | 1649 | qla2x00_process_response_queue(struct rsp_que *rsp) |
1da177e4 | 1650 | { |
73208dfd AC |
1651 | struct scsi_qla_host *vha; |
1652 | struct qla_hw_data *ha = rsp->hw; | |
3d71644c | 1653 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
1da177e4 LT |
1654 | sts_entry_t *pkt; |
1655 | uint16_t handle_cnt; | |
1656 | uint16_t cnt; | |
73208dfd | 1657 | |
2afa19a9 | 1658 | vha = pci_get_drvdata(ha->pdev); |
1da177e4 | 1659 | |
e315cd28 | 1660 | if (!vha->flags.online) |
1da177e4 LT |
1661 | return; |
1662 | ||
e315cd28 AC |
1663 | while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) { |
1664 | pkt = (sts_entry_t *)rsp->ring_ptr; | |
1da177e4 | 1665 | |
e315cd28 AC |
1666 | rsp->ring_index++; |
1667 | if (rsp->ring_index == rsp->length) { | |
1668 | rsp->ring_index = 0; | |
1669 | rsp->ring_ptr = rsp->ring; | |
1da177e4 | 1670 | } else { |
e315cd28 | 1671 | rsp->ring_ptr++; |
1da177e4 LT |
1672 | } |
1673 | ||
1674 | if (pkt->entry_status != 0) { | |
73208dfd | 1675 | qla2x00_error_entry(vha, rsp, pkt); |
1da177e4 LT |
1676 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; |
1677 | wmb(); | |
1678 | continue; | |
1679 | } | |
1680 | ||
1681 | switch (pkt->entry_type) { | |
1682 | case STATUS_TYPE: | |
73208dfd | 1683 | qla2x00_status_entry(vha, rsp, pkt); |
1da177e4 LT |
1684 | break; |
1685 | case STATUS_TYPE_21: | |
1686 | handle_cnt = ((sts21_entry_t *)pkt)->handle_count; | |
1687 | for (cnt = 0; cnt < handle_cnt; cnt++) { | |
73208dfd | 1688 | qla2x00_process_completed_request(vha, rsp->req, |
1da177e4 LT |
1689 | ((sts21_entry_t *)pkt)->handle[cnt]); |
1690 | } | |
1691 | break; | |
1692 | case STATUS_TYPE_22: | |
1693 | handle_cnt = ((sts22_entry_t *)pkt)->handle_count; | |
1694 | for (cnt = 0; cnt < handle_cnt; cnt++) { | |
73208dfd | 1695 | qla2x00_process_completed_request(vha, rsp->req, |
1da177e4 LT |
1696 | ((sts22_entry_t *)pkt)->handle[cnt]); |
1697 | } | |
1698 | break; | |
1699 | case STATUS_CONT_TYPE: | |
2afa19a9 | 1700 | qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt); |
1da177e4 | 1701 | break; |
ac280b67 AV |
1702 | case MBX_IOCB_TYPE: |
1703 | qla2x00_mbx_iocb_entry(vha, rsp->req, | |
1704 | (struct mbx_entry *)pkt); | |
3822263e | 1705 | break; |
9bc4f4fb HZ |
1706 | case CT_IOCB_TYPE: |
1707 | qla2x00_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE); | |
1708 | break; | |
1da177e4 LT |
1709 | default: |
1710 | /* Type Not Supported. */ | |
7c3df132 SK |
1711 | ql_log(ql_log_warn, vha, 0x504a, |
1712 | "Received unknown response pkt type %x " | |
1da177e4 | 1713 | "entry status=%x.\n", |
7c3df132 | 1714 | pkt->entry_type, pkt->entry_status); |
1da177e4 LT |
1715 | break; |
1716 | } | |
1717 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; | |
1718 | wmb(); | |
1719 | } | |
1720 | ||
1721 | /* Adjust ring index */ | |
e315cd28 | 1722 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index); |
1da177e4 LT |
1723 | } |
1724 | ||
4733fcb1 | 1725 | static inline void |
5544213b | 1726 | qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t par_sense_len, |
9ba56b95 | 1727 | uint32_t sense_len, struct rsp_que *rsp, int res) |
4733fcb1 | 1728 | { |
7c3df132 | 1729 | struct scsi_qla_host *vha = sp->fcport->vha; |
9ba56b95 GM |
1730 | struct scsi_cmnd *cp = GET_CMD_SP(sp); |
1731 | uint32_t track_sense_len; | |
4733fcb1 AV |
1732 | |
1733 | if (sense_len >= SCSI_SENSE_BUFFERSIZE) | |
1734 | sense_len = SCSI_SENSE_BUFFERSIZE; | |
1735 | ||
9ba56b95 GM |
1736 | SET_CMD_SENSE_LEN(sp, sense_len); |
1737 | SET_CMD_SENSE_PTR(sp, cp->sense_buffer); | |
1738 | track_sense_len = sense_len; | |
1739 | ||
1740 | if (sense_len > par_sense_len) | |
5544213b | 1741 | sense_len = par_sense_len; |
4733fcb1 AV |
1742 | |
1743 | memcpy(cp->sense_buffer, sense_data, sense_len); | |
1744 | ||
9ba56b95 GM |
1745 | SET_CMD_SENSE_PTR(sp, cp->sense_buffer + sense_len); |
1746 | track_sense_len -= sense_len; | |
1747 | SET_CMD_SENSE_LEN(sp, track_sense_len); | |
1748 | ||
1749 | if (track_sense_len != 0) { | |
2afa19a9 | 1750 | rsp->status_srb = sp; |
9ba56b95 GM |
1751 | cp->result = res; |
1752 | } | |
4733fcb1 | 1753 | |
cfb0919c CD |
1754 | if (sense_len) { |
1755 | ql_dbg(ql_dbg_io + ql_dbg_buffer, vha, 0x301c, | |
9cb78c16 | 1756 | "Check condition Sense data, nexus%ld:%d:%llu cmd=%p.\n", |
cfb0919c CD |
1757 | sp->fcport->vha->host_no, cp->device->id, cp->device->lun, |
1758 | cp); | |
7c3df132 SK |
1759 | ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302b, |
1760 | cp->sense_buffer, sense_len); | |
cfb0919c | 1761 | } |
4733fcb1 AV |
1762 | } |
1763 | ||
bad75002 AE |
1764 | struct scsi_dif_tuple { |
1765 | __be16 guard; /* Checksum */ | |
d6a03581 | 1766 | __be16 app_tag; /* APPL identifier */ |
bad75002 AE |
1767 | __be32 ref_tag; /* Target LBA or indirect LBA */ |
1768 | }; | |
1769 | ||
1770 | /* | |
1771 | * Checks the guard or meta-data for the type of error | |
1772 | * detected by the HBA. In case of errors, we set the | |
1773 | * ASC/ASCQ fields in the sense buffer with ILLEGAL_REQUEST | |
1774 | * to indicate to the kernel that the HBA detected error. | |
1775 | */ | |
8cb2049c | 1776 | static inline int |
bad75002 AE |
1777 | qla2x00_handle_dif_error(srb_t *sp, struct sts_entry_24xx *sts24) |
1778 | { | |
7c3df132 | 1779 | struct scsi_qla_host *vha = sp->fcport->vha; |
9ba56b95 | 1780 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); |
8cb2049c AE |
1781 | uint8_t *ap = &sts24->data[12]; |
1782 | uint8_t *ep = &sts24->data[20]; | |
bad75002 AE |
1783 | uint32_t e_ref_tag, a_ref_tag; |
1784 | uint16_t e_app_tag, a_app_tag; | |
1785 | uint16_t e_guard, a_guard; | |
1786 | ||
8cb2049c AE |
1787 | /* |
1788 | * swab32 of the "data" field in the beginning of qla2x00_status_entry() | |
1789 | * would make guard field appear at offset 2 | |
1790 | */ | |
1791 | a_guard = le16_to_cpu(*(uint16_t *)(ap + 2)); | |
1792 | a_app_tag = le16_to_cpu(*(uint16_t *)(ap + 0)); | |
1793 | a_ref_tag = le32_to_cpu(*(uint32_t *)(ap + 4)); | |
1794 | e_guard = le16_to_cpu(*(uint16_t *)(ep + 2)); | |
1795 | e_app_tag = le16_to_cpu(*(uint16_t *)(ep + 0)); | |
1796 | e_ref_tag = le32_to_cpu(*(uint32_t *)(ep + 4)); | |
bad75002 | 1797 | |
7c3df132 SK |
1798 | ql_dbg(ql_dbg_io, vha, 0x3023, |
1799 | "iocb(s) %p Returned STATUS.\n", sts24); | |
bad75002 | 1800 | |
7c3df132 SK |
1801 | ql_dbg(ql_dbg_io, vha, 0x3024, |
1802 | "DIF ERROR in cmd 0x%x lba 0x%llx act ref" | |
bad75002 | 1803 | " tag=0x%x, exp ref_tag=0x%x, act app tag=0x%x, exp app" |
7c3df132 | 1804 | " tag=0x%x, act guard=0x%x, exp guard=0x%x.\n", |
bad75002 | 1805 | cmd->cmnd[0], (u64)scsi_get_lba(cmd), a_ref_tag, e_ref_tag, |
7c3df132 | 1806 | a_app_tag, e_app_tag, a_guard, e_guard); |
bad75002 | 1807 | |
8cb2049c AE |
1808 | /* |
1809 | * Ignore sector if: | |
1810 | * For type 3: ref & app tag is all 'f's | |
1811 | * For type 0,1,2: app tag is all 'f's | |
1812 | */ | |
1813 | if ((a_app_tag == 0xffff) && | |
1814 | ((scsi_get_prot_type(cmd) != SCSI_PROT_DIF_TYPE3) || | |
1815 | (a_ref_tag == 0xffffffff))) { | |
1816 | uint32_t blocks_done, resid; | |
1817 | sector_t lba_s = scsi_get_lba(cmd); | |
1818 | ||
1819 | /* 2TB boundary case covered automatically with this */ | |
1820 | blocks_done = e_ref_tag - (uint32_t)lba_s + 1; | |
1821 | ||
1822 | resid = scsi_bufflen(cmd) - (blocks_done * | |
1823 | cmd->device->sector_size); | |
1824 | ||
1825 | scsi_set_resid(cmd, resid); | |
1826 | cmd->result = DID_OK << 16; | |
1827 | ||
1828 | /* Update protection tag */ | |
1829 | if (scsi_prot_sg_count(cmd)) { | |
1830 | uint32_t i, j = 0, k = 0, num_ent; | |
1831 | struct scatterlist *sg; | |
27c0e83b | 1832 | struct t10_pi_tuple *spt; |
8cb2049c AE |
1833 | |
1834 | /* Patch the corresponding protection tags */ | |
1835 | scsi_for_each_prot_sg(cmd, sg, | |
1836 | scsi_prot_sg_count(cmd), i) { | |
1837 | num_ent = sg_dma_len(sg) / 8; | |
1838 | if (k + num_ent < blocks_done) { | |
1839 | k += num_ent; | |
1840 | continue; | |
1841 | } | |
1842 | j = blocks_done - k - 1; | |
1843 | k = blocks_done; | |
1844 | break; | |
1845 | } | |
1846 | ||
1847 | if (k != blocks_done) { | |
cfb0919c | 1848 | ql_log(ql_log_warn, vha, 0x302f, |
8ec9c7fb RD |
1849 | "unexpected tag values tag:lba=%x:%llx)\n", |
1850 | e_ref_tag, (unsigned long long)lba_s); | |
8cb2049c AE |
1851 | return 1; |
1852 | } | |
1853 | ||
1854 | spt = page_address(sg_page(sg)) + sg->offset; | |
1855 | spt += j; | |
1856 | ||
1857 | spt->app_tag = 0xffff; | |
1858 | if (scsi_get_prot_type(cmd) == SCSI_PROT_DIF_TYPE3) | |
1859 | spt->ref_tag = 0xffffffff; | |
1860 | } | |
1861 | ||
1862 | return 0; | |
1863 | } | |
1864 | ||
bad75002 AE |
1865 | /* check guard */ |
1866 | if (e_guard != a_guard) { | |
1867 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, | |
1868 | 0x10, 0x1); | |
1869 | set_driver_byte(cmd, DRIVER_SENSE); | |
1870 | set_host_byte(cmd, DID_ABORT); | |
1871 | cmd->result |= SAM_STAT_CHECK_CONDITION << 1; | |
8cb2049c | 1872 | return 1; |
bad75002 AE |
1873 | } |
1874 | ||
e02587d7 AE |
1875 | /* check ref tag */ |
1876 | if (e_ref_tag != a_ref_tag) { | |
bad75002 | 1877 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
e02587d7 | 1878 | 0x10, 0x3); |
bad75002 AE |
1879 | set_driver_byte(cmd, DRIVER_SENSE); |
1880 | set_host_byte(cmd, DID_ABORT); | |
1881 | cmd->result |= SAM_STAT_CHECK_CONDITION << 1; | |
8cb2049c | 1882 | return 1; |
bad75002 AE |
1883 | } |
1884 | ||
e02587d7 AE |
1885 | /* check appl tag */ |
1886 | if (e_app_tag != a_app_tag) { | |
bad75002 | 1887 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, |
e02587d7 | 1888 | 0x10, 0x2); |
bad75002 AE |
1889 | set_driver_byte(cmd, DRIVER_SENSE); |
1890 | set_host_byte(cmd, DID_ABORT); | |
1891 | cmd->result |= SAM_STAT_CHECK_CONDITION << 1; | |
8cb2049c | 1892 | return 1; |
bad75002 | 1893 | } |
e02587d7 | 1894 | |
8cb2049c | 1895 | return 1; |
bad75002 AE |
1896 | } |
1897 | ||
a9b6f722 SK |
1898 | static void |
1899 | qla25xx_process_bidir_status_iocb(scsi_qla_host_t *vha, void *pkt, | |
1900 | struct req_que *req, uint32_t index) | |
1901 | { | |
1902 | struct qla_hw_data *ha = vha->hw; | |
1903 | srb_t *sp; | |
1904 | uint16_t comp_status; | |
1905 | uint16_t scsi_status; | |
1906 | uint16_t thread_id; | |
1907 | uint32_t rval = EXT_STATUS_OK; | |
75cc8cfc | 1908 | struct bsg_job *bsg_job = NULL; |
01e0e15c JT |
1909 | struct fc_bsg_request *bsg_request; |
1910 | struct fc_bsg_reply *bsg_reply; | |
a9b6f722 SK |
1911 | sts_entry_t *sts; |
1912 | struct sts_entry_24xx *sts24; | |
1913 | sts = (sts_entry_t *) pkt; | |
1914 | sts24 = (struct sts_entry_24xx *) pkt; | |
1915 | ||
1916 | /* Validate handle. */ | |
8d93f550 | 1917 | if (index >= req->num_outstanding_cmds) { |
a9b6f722 SK |
1918 | ql_log(ql_log_warn, vha, 0x70af, |
1919 | "Invalid SCSI completion handle 0x%x.\n", index); | |
1920 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
1921 | return; | |
1922 | } | |
1923 | ||
1924 | sp = req->outstanding_cmds[index]; | |
01e0e15c | 1925 | if (!sp) { |
a9b6f722 SK |
1926 | ql_log(ql_log_warn, vha, 0x70b0, |
1927 | "Req:%d: Invalid ISP SCSI completion handle(0x%x)\n", | |
1928 | req->id, index); | |
1929 | ||
1930 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
1931 | return; | |
1932 | } | |
1933 | ||
01e0e15c JT |
1934 | /* Free outstanding command slot. */ |
1935 | req->outstanding_cmds[index] = NULL; | |
1936 | bsg_job = sp->u.bsg_job; | |
1937 | bsg_request = bsg_job->request; | |
1938 | bsg_reply = bsg_job->reply; | |
1939 | ||
a9b6f722 SK |
1940 | if (IS_FWI2_CAPABLE(ha)) { |
1941 | comp_status = le16_to_cpu(sts24->comp_status); | |
1942 | scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK; | |
1943 | } else { | |
1944 | comp_status = le16_to_cpu(sts->comp_status); | |
1945 | scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK; | |
1946 | } | |
1947 | ||
01e0e15c | 1948 | thread_id = bsg_request->rqst_data.h_vendor.vendor_cmd[1]; |
a9b6f722 SK |
1949 | switch (comp_status) { |
1950 | case CS_COMPLETE: | |
1951 | if (scsi_status == 0) { | |
01e0e15c | 1952 | bsg_reply->reply_payload_rcv_len = |
a9b6f722 | 1953 | bsg_job->reply_payload.payload_len; |
fabbb8df | 1954 | vha->qla_stats.input_bytes += |
01e0e15c | 1955 | bsg_reply->reply_payload_rcv_len; |
fabbb8df | 1956 | vha->qla_stats.input_requests++; |
a9b6f722 SK |
1957 | rval = EXT_STATUS_OK; |
1958 | } | |
1959 | goto done; | |
1960 | ||
1961 | case CS_DATA_OVERRUN: | |
1962 | ql_dbg(ql_dbg_user, vha, 0x70b1, | |
1963 | "Command completed with date overrun thread_id=%d\n", | |
1964 | thread_id); | |
1965 | rval = EXT_STATUS_DATA_OVERRUN; | |
1966 | break; | |
1967 | ||
1968 | case CS_DATA_UNDERRUN: | |
1969 | ql_dbg(ql_dbg_user, vha, 0x70b2, | |
1970 | "Command completed with date underrun thread_id=%d\n", | |
1971 | thread_id); | |
1972 | rval = EXT_STATUS_DATA_UNDERRUN; | |
1973 | break; | |
1974 | case CS_BIDIR_RD_OVERRUN: | |
1975 | ql_dbg(ql_dbg_user, vha, 0x70b3, | |
1976 | "Command completed with read data overrun thread_id=%d\n", | |
1977 | thread_id); | |
1978 | rval = EXT_STATUS_DATA_OVERRUN; | |
1979 | break; | |
1980 | ||
1981 | case CS_BIDIR_RD_WR_OVERRUN: | |
1982 | ql_dbg(ql_dbg_user, vha, 0x70b4, | |
1983 | "Command completed with read and write data overrun " | |
1984 | "thread_id=%d\n", thread_id); | |
1985 | rval = EXT_STATUS_DATA_OVERRUN; | |
1986 | break; | |
1987 | ||
1988 | case CS_BIDIR_RD_OVERRUN_WR_UNDERRUN: | |
1989 | ql_dbg(ql_dbg_user, vha, 0x70b5, | |
1990 | "Command completed with read data over and write data " | |
1991 | "underrun thread_id=%d\n", thread_id); | |
1992 | rval = EXT_STATUS_DATA_OVERRUN; | |
1993 | break; | |
1994 | ||
1995 | case CS_BIDIR_RD_UNDERRUN: | |
1996 | ql_dbg(ql_dbg_user, vha, 0x70b6, | |
1997 | "Command completed with read data data underrun " | |
1998 | "thread_id=%d\n", thread_id); | |
1999 | rval = EXT_STATUS_DATA_UNDERRUN; | |
2000 | break; | |
2001 | ||
2002 | case CS_BIDIR_RD_UNDERRUN_WR_OVERRUN: | |
2003 | ql_dbg(ql_dbg_user, vha, 0x70b7, | |
2004 | "Command completed with read data under and write data " | |
2005 | "overrun thread_id=%d\n", thread_id); | |
2006 | rval = EXT_STATUS_DATA_UNDERRUN; | |
2007 | break; | |
2008 | ||
2009 | case CS_BIDIR_RD_WR_UNDERRUN: | |
2010 | ql_dbg(ql_dbg_user, vha, 0x70b8, | |
2011 | "Command completed with read and write data underrun " | |
2012 | "thread_id=%d\n", thread_id); | |
2013 | rval = EXT_STATUS_DATA_UNDERRUN; | |
2014 | break; | |
2015 | ||
2016 | case CS_BIDIR_DMA: | |
2017 | ql_dbg(ql_dbg_user, vha, 0x70b9, | |
2018 | "Command completed with data DMA error thread_id=%d\n", | |
2019 | thread_id); | |
2020 | rval = EXT_STATUS_DMA_ERR; | |
2021 | break; | |
2022 | ||
2023 | case CS_TIMEOUT: | |
2024 | ql_dbg(ql_dbg_user, vha, 0x70ba, | |
2025 | "Command completed with timeout thread_id=%d\n", | |
2026 | thread_id); | |
2027 | rval = EXT_STATUS_TIMEOUT; | |
2028 | break; | |
2029 | default: | |
2030 | ql_dbg(ql_dbg_user, vha, 0x70bb, | |
2031 | "Command completed with completion status=0x%x " | |
2032 | "thread_id=%d\n", comp_status, thread_id); | |
2033 | rval = EXT_STATUS_ERR; | |
2034 | break; | |
2035 | } | |
01e0e15c | 2036 | bsg_reply->reply_payload_rcv_len = 0; |
a9b6f722 SK |
2037 | |
2038 | done: | |
2039 | /* Return the vendor specific reply to API */ | |
01e0e15c | 2040 | bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = rval; |
a9b6f722 SK |
2041 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); |
2042 | /* Always return DID_OK, bsg will send the vendor specific response | |
2043 | * in this case only */ | |
2044 | sp->done(vha, sp, (DID_OK << 6)); | |
2045 | ||
2046 | } | |
2047 | ||
1da177e4 LT |
2048 | /** |
2049 | * qla2x00_status_entry() - Process a Status IOCB entry. | |
2050 | * @ha: SCSI driver HA context | |
2051 | * @pkt: Entry pointer | |
2052 | */ | |
2053 | static void | |
73208dfd | 2054 | qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt) |
1da177e4 | 2055 | { |
1da177e4 | 2056 | srb_t *sp; |
1da177e4 LT |
2057 | fc_port_t *fcport; |
2058 | struct scsi_cmnd *cp; | |
9a853f71 AV |
2059 | sts_entry_t *sts; |
2060 | struct sts_entry_24xx *sts24; | |
1da177e4 LT |
2061 | uint16_t comp_status; |
2062 | uint16_t scsi_status; | |
b7d2280c | 2063 | uint16_t ox_id; |
1da177e4 LT |
2064 | uint8_t lscsi_status; |
2065 | int32_t resid; | |
5544213b AV |
2066 | uint32_t sense_len, par_sense_len, rsp_info_len, resid_len, |
2067 | fw_resid_len; | |
9a853f71 | 2068 | uint8_t *rsp_info, *sense_data; |
e315cd28 | 2069 | struct qla_hw_data *ha = vha->hw; |
2afa19a9 AC |
2070 | uint32_t handle; |
2071 | uint16_t que; | |
2072 | struct req_que *req; | |
b7d2280c | 2073 | int logit = 1; |
9ba56b95 | 2074 | int res = 0; |
a9b6f722 | 2075 | uint16_t state_flags = 0; |
e05fe292 | 2076 | uint16_t retry_delay = 0; |
9a853f71 AV |
2077 | |
2078 | sts = (sts_entry_t *) pkt; | |
2079 | sts24 = (struct sts_entry_24xx *) pkt; | |
e428924c | 2080 | if (IS_FWI2_CAPABLE(ha)) { |
9a853f71 AV |
2081 | comp_status = le16_to_cpu(sts24->comp_status); |
2082 | scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK; | |
a9b6f722 | 2083 | state_flags = le16_to_cpu(sts24->state_flags); |
9a853f71 AV |
2084 | } else { |
2085 | comp_status = le16_to_cpu(sts->comp_status); | |
2086 | scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK; | |
2087 | } | |
2afa19a9 AC |
2088 | handle = (uint32_t) LSW(sts->handle); |
2089 | que = MSW(sts->handle); | |
2090 | req = ha->req_q_map[que]; | |
a9083016 | 2091 | |
36008cf1 CD |
2092 | /* Check for invalid queue pointer */ |
2093 | if (req == NULL || | |
2094 | que >= find_first_zero_bit(ha->req_qid_map, ha->max_req_queues)) { | |
2095 | ql_dbg(ql_dbg_io, vha, 0x3059, | |
2096 | "Invalid status handle (0x%x): Bad req pointer. req=%p, " | |
2097 | "que=%u.\n", sts->handle, req, que); | |
2098 | return; | |
2099 | } | |
2100 | ||
1da177e4 | 2101 | /* Validate handle. */ |
c7bc4cae | 2102 | if (handle < req->num_outstanding_cmds) { |
2afa19a9 | 2103 | sp = req->outstanding_cmds[handle]; |
c7bc4cae CD |
2104 | if (!sp) { |
2105 | ql_dbg(ql_dbg_io, vha, 0x3075, | |
2106 | "%s(%ld): Already returned command for status handle (0x%x).\n", | |
2107 | __func__, vha->host_no, sts->handle); | |
2108 | return; | |
2109 | } | |
2110 | } else { | |
cfb0919c | 2111 | ql_dbg(ql_dbg_io, vha, 0x3017, |
c7bc4cae CD |
2112 | "Invalid status handle, out of range (0x%x).\n", |
2113 | sts->handle); | |
1da177e4 | 2114 | |
acd3ce88 CD |
2115 | if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) { |
2116 | if (IS_P3P_TYPE(ha)) | |
2117 | set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags); | |
2118 | else | |
2119 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
2120 | qla2xxx_wake_dpc(vha); | |
2121 | } | |
1da177e4 LT |
2122 | return; |
2123 | } | |
a9b6f722 SK |
2124 | |
2125 | if (unlikely((state_flags & BIT_1) && (sp->type == SRB_BIDI_CMD))) { | |
2126 | qla25xx_process_bidir_status_iocb(vha, pkt, req, handle); | |
2127 | return; | |
2128 | } | |
2129 | ||
faef62d1 AB |
2130 | /* Task Management completion. */ |
2131 | if (sp->type == SRB_TM_CMD) { | |
2132 | qla24xx_tm_iocb_entry(vha, req, pkt); | |
2133 | return; | |
2134 | } | |
2135 | ||
a9b6f722 SK |
2136 | /* Fast path completion. */ |
2137 | if (comp_status == CS_COMPLETE && scsi_status == 0) { | |
2138 | qla2x00_process_completed_request(vha, req, handle); | |
2139 | ||
2140 | return; | |
2141 | } | |
2142 | ||
2143 | req->outstanding_cmds[handle] = NULL; | |
9ba56b95 | 2144 | cp = GET_CMD_SP(sp); |
1da177e4 | 2145 | if (cp == NULL) { |
cfb0919c | 2146 | ql_dbg(ql_dbg_io, vha, 0x3018, |
7c3df132 SK |
2147 | "Command already returned (0x%x/%p).\n", |
2148 | sts->handle, sp); | |
1da177e4 LT |
2149 | |
2150 | return; | |
2151 | } | |
2152 | ||
8ae6d9c7 | 2153 | lscsi_status = scsi_status & STATUS_MASK; |
1da177e4 | 2154 | |
bdf79621 | 2155 | fcport = sp->fcport; |
1da177e4 | 2156 | |
b7d2280c | 2157 | ox_id = 0; |
5544213b AV |
2158 | sense_len = par_sense_len = rsp_info_len = resid_len = |
2159 | fw_resid_len = 0; | |
e428924c | 2160 | if (IS_FWI2_CAPABLE(ha)) { |
0f00a206 LC |
2161 | if (scsi_status & SS_SENSE_LEN_VALID) |
2162 | sense_len = le32_to_cpu(sts24->sense_len); | |
2163 | if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) | |
2164 | rsp_info_len = le32_to_cpu(sts24->rsp_data_len); | |
2165 | if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) | |
2166 | resid_len = le32_to_cpu(sts24->rsp_residual_count); | |
2167 | if (comp_status == CS_DATA_UNDERRUN) | |
2168 | fw_resid_len = le32_to_cpu(sts24->residual_len); | |
9a853f71 AV |
2169 | rsp_info = sts24->data; |
2170 | sense_data = sts24->data; | |
2171 | host_to_fcp_swap(sts24->data, sizeof(sts24->data)); | |
b7d2280c | 2172 | ox_id = le16_to_cpu(sts24->ox_id); |
5544213b | 2173 | par_sense_len = sizeof(sts24->data); |
e05fe292 CD |
2174 | /* Valid values of the retry delay timer are 0x1-0xffef */ |
2175 | if (sts24->retry_delay > 0 && sts24->retry_delay < 0xfff1) | |
2176 | retry_delay = sts24->retry_delay; | |
9a853f71 | 2177 | } else { |
0f00a206 LC |
2178 | if (scsi_status & SS_SENSE_LEN_VALID) |
2179 | sense_len = le16_to_cpu(sts->req_sense_length); | |
2180 | if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) | |
2181 | rsp_info_len = le16_to_cpu(sts->rsp_info_len); | |
9a853f71 AV |
2182 | resid_len = le32_to_cpu(sts->residual_length); |
2183 | rsp_info = sts->rsp_info; | |
2184 | sense_data = sts->req_sense_data; | |
5544213b | 2185 | par_sense_len = sizeof(sts->req_sense_data); |
9a853f71 AV |
2186 | } |
2187 | ||
1da177e4 LT |
2188 | /* Check for any FCP transport errors. */ |
2189 | if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) { | |
9a853f71 | 2190 | /* Sense data lies beyond any FCP RESPONSE data. */ |
5544213b | 2191 | if (IS_FWI2_CAPABLE(ha)) { |
9a853f71 | 2192 | sense_data += rsp_info_len; |
5544213b AV |
2193 | par_sense_len -= rsp_info_len; |
2194 | } | |
9a853f71 | 2195 | if (rsp_info_len > 3 && rsp_info[3]) { |
5e19ed90 | 2196 | ql_dbg(ql_dbg_io, fcport->vha, 0x3019, |
7c3df132 SK |
2197 | "FCP I/O protocol failure (0x%x/0x%x).\n", |
2198 | rsp_info_len, rsp_info[3]); | |
1da177e4 | 2199 | |
9ba56b95 | 2200 | res = DID_BUS_BUSY << 16; |
b7d2280c | 2201 | goto out; |
1da177e4 LT |
2202 | } |
2203 | } | |
2204 | ||
3e8ce320 AV |
2205 | /* Check for overrun. */ |
2206 | if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE && | |
2207 | scsi_status & SS_RESIDUAL_OVER) | |
2208 | comp_status = CS_DATA_OVERRUN; | |
2209 | ||
e05fe292 CD |
2210 | /* |
2211 | * Check retry_delay_timer value if we receive a busy or | |
2212 | * queue full. | |
2213 | */ | |
2214 | if (lscsi_status == SAM_STAT_TASK_SET_FULL || | |
2215 | lscsi_status == SAM_STAT_BUSY) | |
2216 | qla2x00_set_retry_delay_timestamp(fcport, retry_delay); | |
2217 | ||
1da177e4 LT |
2218 | /* |
2219 | * Based on Host and scsi status generate status code for Linux | |
2220 | */ | |
2221 | switch (comp_status) { | |
2222 | case CS_COMPLETE: | |
df7baa50 | 2223 | case CS_QUEUE_FULL: |
1da177e4 | 2224 | if (scsi_status == 0) { |
9ba56b95 | 2225 | res = DID_OK << 16; |
1da177e4 LT |
2226 | break; |
2227 | } | |
2228 | if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) { | |
9a853f71 | 2229 | resid = resid_len; |
385d70b4 | 2230 | scsi_set_resid(cp, resid); |
0da69df1 AV |
2231 | |
2232 | if (!lscsi_status && | |
385d70b4 | 2233 | ((unsigned)(scsi_bufflen(cp) - resid) < |
0da69df1 | 2234 | cp->underflow)) { |
5e19ed90 | 2235 | ql_dbg(ql_dbg_io, fcport->vha, 0x301a, |
7c3df132 | 2236 | "Mid-layer underflow " |
b7d2280c | 2237 | "detected (0x%x of 0x%x bytes).\n", |
7c3df132 | 2238 | resid, scsi_bufflen(cp)); |
0da69df1 | 2239 | |
9ba56b95 | 2240 | res = DID_ERROR << 16; |
0da69df1 AV |
2241 | break; |
2242 | } | |
1da177e4 | 2243 | } |
9ba56b95 | 2244 | res = DID_OK << 16 | lscsi_status; |
1da177e4 | 2245 | |
df7baa50 | 2246 | if (lscsi_status == SAM_STAT_TASK_SET_FULL) { |
5e19ed90 | 2247 | ql_dbg(ql_dbg_io, fcport->vha, 0x301b, |
7c3df132 | 2248 | "QUEUE FULL detected.\n"); |
df7baa50 AV |
2249 | break; |
2250 | } | |
b7d2280c | 2251 | logit = 0; |
1da177e4 LT |
2252 | if (lscsi_status != SS_CHECK_CONDITION) |
2253 | break; | |
2254 | ||
b80ca4f7 | 2255 | memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); |
1da177e4 LT |
2256 | if (!(scsi_status & SS_SENSE_LEN_VALID)) |
2257 | break; | |
2258 | ||
5544213b | 2259 | qla2x00_handle_sense(sp, sense_data, par_sense_len, sense_len, |
9ba56b95 | 2260 | rsp, res); |
1da177e4 LT |
2261 | break; |
2262 | ||
2263 | case CS_DATA_UNDERRUN: | |
ed17c71b | 2264 | /* Use F/W calculated residual length. */ |
0f00a206 LC |
2265 | resid = IS_FWI2_CAPABLE(ha) ? fw_resid_len : resid_len; |
2266 | scsi_set_resid(cp, resid); | |
2267 | if (scsi_status & SS_RESIDUAL_UNDER) { | |
2268 | if (IS_FWI2_CAPABLE(ha) && fw_resid_len != resid_len) { | |
5e19ed90 | 2269 | ql_dbg(ql_dbg_io, fcport->vha, 0x301d, |
7c3df132 SK |
2270 | "Dropped frame(s) detected " |
2271 | "(0x%x of 0x%x bytes).\n", | |
2272 | resid, scsi_bufflen(cp)); | |
0f00a206 | 2273 | |
9ba56b95 | 2274 | res = DID_ERROR << 16 | lscsi_status; |
4e85e3d9 | 2275 | goto check_scsi_status; |
6acf8190 | 2276 | } |
ed17c71b | 2277 | |
0f00a206 LC |
2278 | if (!lscsi_status && |
2279 | ((unsigned)(scsi_bufflen(cp) - resid) < | |
2280 | cp->underflow)) { | |
5e19ed90 | 2281 | ql_dbg(ql_dbg_io, fcport->vha, 0x301e, |
7c3df132 | 2282 | "Mid-layer underflow " |
b7d2280c | 2283 | "detected (0x%x of 0x%x bytes).\n", |
7c3df132 | 2284 | resid, scsi_bufflen(cp)); |
e038a1be | 2285 | |
9ba56b95 | 2286 | res = DID_ERROR << 16; |
0f00a206 LC |
2287 | break; |
2288 | } | |
4aee5766 GM |
2289 | } else if (lscsi_status != SAM_STAT_TASK_SET_FULL && |
2290 | lscsi_status != SAM_STAT_BUSY) { | |
2291 | /* | |
2292 | * scsi status of task set and busy are considered to be | |
2293 | * task not completed. | |
2294 | */ | |
2295 | ||
5e19ed90 | 2296 | ql_dbg(ql_dbg_io, fcport->vha, 0x301f, |
7c3df132 | 2297 | "Dropped frame(s) detected (0x%x " |
4aee5766 GM |
2298 | "of 0x%x bytes).\n", resid, |
2299 | scsi_bufflen(cp)); | |
0f00a206 | 2300 | |
9ba56b95 | 2301 | res = DID_ERROR << 16 | lscsi_status; |
0374f55e | 2302 | goto check_scsi_status; |
4aee5766 GM |
2303 | } else { |
2304 | ql_dbg(ql_dbg_io, fcport->vha, 0x3030, | |
2305 | "scsi_status: 0x%x, lscsi_status: 0x%x\n", | |
2306 | scsi_status, lscsi_status); | |
1da177e4 LT |
2307 | } |
2308 | ||
9ba56b95 | 2309 | res = DID_OK << 16 | lscsi_status; |
b7d2280c | 2310 | logit = 0; |
0f00a206 | 2311 | |
0374f55e | 2312 | check_scsi_status: |
1da177e4 | 2313 | /* |
fa2a1ce5 | 2314 | * Check to see if SCSI Status is non zero. If so report SCSI |
1da177e4 LT |
2315 | * Status. |
2316 | */ | |
2317 | if (lscsi_status != 0) { | |
ffec28a3 | 2318 | if (lscsi_status == SAM_STAT_TASK_SET_FULL) { |
5e19ed90 | 2319 | ql_dbg(ql_dbg_io, fcport->vha, 0x3020, |
7c3df132 | 2320 | "QUEUE FULL detected.\n"); |
b7d2280c | 2321 | logit = 1; |
ffec28a3 AV |
2322 | break; |
2323 | } | |
1da177e4 LT |
2324 | if (lscsi_status != SS_CHECK_CONDITION) |
2325 | break; | |
2326 | ||
b80ca4f7 | 2327 | memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); |
1da177e4 LT |
2328 | if (!(scsi_status & SS_SENSE_LEN_VALID)) |
2329 | break; | |
2330 | ||
5544213b | 2331 | qla2x00_handle_sense(sp, sense_data, par_sense_len, |
9ba56b95 | 2332 | sense_len, rsp, res); |
1da177e4 LT |
2333 | } |
2334 | break; | |
2335 | ||
1da177e4 LT |
2336 | case CS_PORT_LOGGED_OUT: |
2337 | case CS_PORT_CONFIG_CHG: | |
2338 | case CS_PORT_BUSY: | |
2339 | case CS_INCOMPLETE: | |
2340 | case CS_PORT_UNAVAILABLE: | |
b7d2280c | 2341 | case CS_TIMEOUT: |
ff454b01 CD |
2342 | case CS_RESET: |
2343 | ||
056a4483 MC |
2344 | /* |
2345 | * We are going to have the fc class block the rport | |
2346 | * while we try to recover so instruct the mid layer | |
2347 | * to requeue until the class decides how to handle this. | |
2348 | */ | |
9ba56b95 | 2349 | res = DID_TRANSPORT_DISRUPTED << 16; |
b7d2280c AV |
2350 | |
2351 | if (comp_status == CS_TIMEOUT) { | |
2352 | if (IS_FWI2_CAPABLE(ha)) | |
2353 | break; | |
2354 | else if ((le16_to_cpu(sts->status_flags) & | |
2355 | SF_LOGOUT_SENT) == 0) | |
2356 | break; | |
2357 | } | |
2358 | ||
5e19ed90 | 2359 | ql_dbg(ql_dbg_io, fcport->vha, 0x3021, |
0e948975 CD |
2360 | "Port to be marked lost on fcport=%02x%02x%02x, current " |
2361 | "port state= %s.\n", fcport->d_id.b.domain, | |
2362 | fcport->d_id.b.area, fcport->d_id.b.al_pa, | |
2363 | port_state_str[atomic_read(&fcport->state)]); | |
b7d2280c | 2364 | |
a7a28504 | 2365 | if (atomic_read(&fcport->state) == FCS_ONLINE) |
e315cd28 | 2366 | qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1); |
1da177e4 LT |
2367 | break; |
2368 | ||
1da177e4 | 2369 | case CS_ABORTED: |
9ba56b95 | 2370 | res = DID_RESET << 16; |
1da177e4 | 2371 | break; |
bad75002 AE |
2372 | |
2373 | case CS_DIF_ERROR: | |
8cb2049c | 2374 | logit = qla2x00_handle_dif_error(sp, sts24); |
fb6e4668 | 2375 | res = cp->result; |
bad75002 | 2376 | break; |
9e522cd8 AE |
2377 | |
2378 | case CS_TRANSPORT: | |
2379 | res = DID_ERROR << 16; | |
2380 | ||
2381 | if (!IS_PI_SPLIT_DET_CAPABLE(ha)) | |
2382 | break; | |
2383 | ||
2384 | if (state_flags & BIT_4) | |
2385 | scmd_printk(KERN_WARNING, cp, | |
2386 | "Unsupported device '%s' found.\n", | |
2387 | cp->device->vendor); | |
2388 | break; | |
2389 | ||
1da177e4 | 2390 | default: |
9ba56b95 | 2391 | res = DID_ERROR << 16; |
1da177e4 LT |
2392 | break; |
2393 | } | |
2394 | ||
b7d2280c AV |
2395 | out: |
2396 | if (logit) | |
5e19ed90 | 2397 | ql_dbg(ql_dbg_io, fcport->vha, 0x3022, |
9cb78c16 | 2398 | "FCP command status: 0x%x-0x%x (0x%x) nexus=%ld:%d:%llu " |
7b833558 | 2399 | "portid=%02x%02x%02x oxid=0x%x cdb=%10phN len=0x%x " |
c7bc4cae | 2400 | "rsp_info=0x%x resid=0x%x fw_resid=0x%x sp=%p cp=%p.\n", |
9ba56b95 | 2401 | comp_status, scsi_status, res, vha->host_no, |
cfb0919c CD |
2402 | cp->device->id, cp->device->lun, fcport->d_id.b.domain, |
2403 | fcport->d_id.b.area, fcport->d_id.b.al_pa, ox_id, | |
7b833558 | 2404 | cp->cmnd, scsi_bufflen(cp), rsp_info_len, |
c7bc4cae | 2405 | resid_len, fw_resid_len, sp, cp); |
b7d2280c | 2406 | |
2afa19a9 | 2407 | if (rsp->status_srb == NULL) |
9ba56b95 | 2408 | sp->done(ha, sp, res); |
1da177e4 LT |
2409 | } |
2410 | ||
2411 | /** | |
2412 | * qla2x00_status_cont_entry() - Process a Status Continuations entry. | |
2413 | * @ha: SCSI driver HA context | |
2414 | * @pkt: Entry pointer | |
2415 | * | |
2416 | * Extended sense data. | |
2417 | */ | |
2418 | static void | |
2afa19a9 | 2419 | qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt) |
1da177e4 | 2420 | { |
9ba56b95 | 2421 | uint8_t sense_sz = 0; |
2afa19a9 | 2422 | struct qla_hw_data *ha = rsp->hw; |
7c3df132 | 2423 | struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev); |
9ba56b95 | 2424 | srb_t *sp = rsp->status_srb; |
1da177e4 | 2425 | struct scsi_cmnd *cp; |
9ba56b95 GM |
2426 | uint32_t sense_len; |
2427 | uint8_t *sense_ptr; | |
1da177e4 | 2428 | |
9ba56b95 GM |
2429 | if (!sp || !GET_CMD_SENSE_LEN(sp)) |
2430 | return; | |
1da177e4 | 2431 | |
9ba56b95 GM |
2432 | sense_len = GET_CMD_SENSE_LEN(sp); |
2433 | sense_ptr = GET_CMD_SENSE_PTR(sp); | |
1da177e4 | 2434 | |
9ba56b95 GM |
2435 | cp = GET_CMD_SP(sp); |
2436 | if (cp == NULL) { | |
2437 | ql_log(ql_log_warn, vha, 0x3025, | |
2438 | "cmd is NULL: already returned to OS (sp=%p).\n", sp); | |
1da177e4 | 2439 | |
9ba56b95 GM |
2440 | rsp->status_srb = NULL; |
2441 | return; | |
1da177e4 | 2442 | } |
1da177e4 | 2443 | |
9ba56b95 GM |
2444 | if (sense_len > sizeof(pkt->data)) |
2445 | sense_sz = sizeof(pkt->data); | |
2446 | else | |
2447 | sense_sz = sense_len; | |
c4631191 | 2448 | |
9ba56b95 GM |
2449 | /* Move sense data. */ |
2450 | if (IS_FWI2_CAPABLE(ha)) | |
2451 | host_to_fcp_swap(pkt->data, sizeof(pkt->data)); | |
2452 | memcpy(sense_ptr, pkt->data, sense_sz); | |
2453 | ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302c, | |
2454 | sense_ptr, sense_sz); | |
c4631191 | 2455 | |
9ba56b95 GM |
2456 | sense_len -= sense_sz; |
2457 | sense_ptr += sense_sz; | |
c4631191 | 2458 | |
9ba56b95 GM |
2459 | SET_CMD_SENSE_PTR(sp, sense_ptr); |
2460 | SET_CMD_SENSE_LEN(sp, sense_len); | |
2461 | ||
2462 | /* Place command on done queue. */ | |
2463 | if (sense_len == 0) { | |
2464 | rsp->status_srb = NULL; | |
2465 | sp->done(ha, sp, cp->result); | |
c4631191 | 2466 | } |
c4631191 GM |
2467 | } |
2468 | ||
1da177e4 LT |
2469 | /** |
2470 | * qla2x00_error_entry() - Process an error entry. | |
2471 | * @ha: SCSI driver HA context | |
2472 | * @pkt: Entry pointer | |
2473 | */ | |
2474 | static void | |
73208dfd | 2475 | qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt) |
1da177e4 LT |
2476 | { |
2477 | srb_t *sp; | |
e315cd28 | 2478 | struct qla_hw_data *ha = vha->hw; |
c4631191 | 2479 | const char func[] = "ERROR-IOCB"; |
2afa19a9 | 2480 | uint16_t que = MSW(pkt->handle); |
a6fe35c0 | 2481 | struct req_que *req = NULL; |
9ba56b95 | 2482 | int res = DID_ERROR << 16; |
7c3df132 | 2483 | |
9ba56b95 GM |
2484 | ql_dbg(ql_dbg_async, vha, 0x502a, |
2485 | "type of error status in response: 0x%x\n", pkt->entry_status); | |
2486 | ||
a6fe35c0 AE |
2487 | if (que >= ha->max_req_queues || !ha->req_q_map[que]) |
2488 | goto fatal; | |
2489 | ||
2490 | req = ha->req_q_map[que]; | |
2491 | ||
9ba56b95 GM |
2492 | if (pkt->entry_status & RF_BUSY) |
2493 | res = DID_BUS_BUSY << 16; | |
1da177e4 | 2494 | |
4f060736 QT |
2495 | if (pkt->entry_type == NOTIFY_ACK_TYPE && |
2496 | pkt->handle == QLA_TGT_SKIP_HANDLE) | |
2497 | return; | |
2498 | ||
c4631191 | 2499 | sp = qla2x00_get_sp_from_handle(vha, func, req, pkt); |
a6fe35c0 | 2500 | if (sp) { |
9ba56b95 | 2501 | sp->done(ha, sp, res); |
a6fe35c0 | 2502 | return; |
1da177e4 | 2503 | } |
a6fe35c0 AE |
2504 | fatal: |
2505 | ql_log(ql_log_warn, vha, 0x5030, | |
fd49a540 | 2506 | "Error entry - invalid handle/queue (%04x).\n", que); |
1da177e4 LT |
2507 | } |
2508 | ||
9a853f71 AV |
2509 | /** |
2510 | * qla24xx_mbx_completion() - Process mailbox command completions. | |
2511 | * @ha: SCSI driver HA context | |
2512 | * @mb0: Mailbox0 register | |
2513 | */ | |
2514 | static void | |
e315cd28 | 2515 | qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0) |
9a853f71 AV |
2516 | { |
2517 | uint16_t cnt; | |
4fa94f83 | 2518 | uint32_t mboxes; |
9a853f71 | 2519 | uint16_t __iomem *wptr; |
e315cd28 | 2520 | struct qla_hw_data *ha = vha->hw; |
9a853f71 AV |
2521 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
2522 | ||
4fa94f83 AV |
2523 | /* Read all mbox registers? */ |
2524 | mboxes = (1 << ha->mbx_count) - 1; | |
2525 | if (!ha->mcp) | |
a720101d | 2526 | ql_dbg(ql_dbg_async, vha, 0x504e, "MBX pointer ERROR.\n"); |
4fa94f83 AV |
2527 | else |
2528 | mboxes = ha->mcp->in_mb; | |
2529 | ||
9a853f71 AV |
2530 | /* Load return mailbox registers. */ |
2531 | ha->flags.mbox_int = 1; | |
2532 | ha->mailbox_out[0] = mb0; | |
4fa94f83 | 2533 | mboxes >>= 1; |
9a853f71 AV |
2534 | wptr = (uint16_t __iomem *)®->mailbox1; |
2535 | ||
2536 | for (cnt = 1; cnt < ha->mbx_count; cnt++) { | |
4fa94f83 AV |
2537 | if (mboxes & BIT_0) |
2538 | ha->mailbox_out[cnt] = RD_REG_WORD(wptr); | |
2539 | ||
2540 | mboxes >>= 1; | |
9a853f71 AV |
2541 | wptr++; |
2542 | } | |
9a853f71 AV |
2543 | } |
2544 | ||
4440e46d AB |
2545 | static void |
2546 | qla24xx_abort_iocb_entry(scsi_qla_host_t *vha, struct req_que *req, | |
2547 | struct abort_entry_24xx *pkt) | |
2548 | { | |
2549 | const char func[] = "ABT_IOCB"; | |
2550 | srb_t *sp; | |
2551 | struct srb_iocb *abt; | |
2552 | ||
2553 | sp = qla2x00_get_sp_from_handle(vha, func, req, pkt); | |
2554 | if (!sp) | |
2555 | return; | |
2556 | ||
2557 | abt = &sp->u.iocb_cmd; | |
2558 | abt->u.abt.comp_status = le32_to_cpu(pkt->nport_handle); | |
2559 | sp->done(vha, sp, 0); | |
2560 | } | |
2561 | ||
9a853f71 AV |
2562 | /** |
2563 | * qla24xx_process_response_queue() - Process response queue entries. | |
2564 | * @ha: SCSI driver HA context | |
2565 | */ | |
2afa19a9 AC |
2566 | void qla24xx_process_response_queue(struct scsi_qla_host *vha, |
2567 | struct rsp_que *rsp) | |
9a853f71 | 2568 | { |
9a853f71 | 2569 | struct sts_entry_24xx *pkt; |
a9083016 | 2570 | struct qla_hw_data *ha = vha->hw; |
9a853f71 | 2571 | |
e315cd28 | 2572 | if (!vha->flags.online) |
9a853f71 AV |
2573 | return; |
2574 | ||
e315cd28 AC |
2575 | while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) { |
2576 | pkt = (struct sts_entry_24xx *)rsp->ring_ptr; | |
9a853f71 | 2577 | |
e315cd28 AC |
2578 | rsp->ring_index++; |
2579 | if (rsp->ring_index == rsp->length) { | |
2580 | rsp->ring_index = 0; | |
2581 | rsp->ring_ptr = rsp->ring; | |
9a853f71 | 2582 | } else { |
e315cd28 | 2583 | rsp->ring_ptr++; |
9a853f71 AV |
2584 | } |
2585 | ||
2586 | if (pkt->entry_status != 0) { | |
73208dfd | 2587 | qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt); |
2d70c103 | 2588 | |
f83adb61 QT |
2589 | if (qlt_24xx_process_response_error(vha, pkt)) |
2590 | goto process_err; | |
2d70c103 | 2591 | |
9a853f71 AV |
2592 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; |
2593 | wmb(); | |
2594 | continue; | |
2595 | } | |
f83adb61 | 2596 | process_err: |
9a853f71 AV |
2597 | |
2598 | switch (pkt->entry_type) { | |
2599 | case STATUS_TYPE: | |
73208dfd | 2600 | qla2x00_status_entry(vha, rsp, pkt); |
9a853f71 AV |
2601 | break; |
2602 | case STATUS_CONT_TYPE: | |
2afa19a9 | 2603 | qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt); |
9a853f71 | 2604 | break; |
2c3dfe3f | 2605 | case VP_RPT_ID_IOCB_TYPE: |
e315cd28 | 2606 | qla24xx_report_id_acquisition(vha, |
2c3dfe3f SJ |
2607 | (struct vp_rpt_id_entry_24xx *)pkt); |
2608 | break; | |
ac280b67 AV |
2609 | case LOGINOUT_PORT_IOCB_TYPE: |
2610 | qla24xx_logio_entry(vha, rsp->req, | |
2611 | (struct logio_entry_24xx *)pkt); | |
2612 | break; | |
f83adb61 | 2613 | case CT_IOCB_TYPE: |
9a069e19 | 2614 | qla24xx_els_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE); |
9a069e19 | 2615 | break; |
f83adb61 | 2616 | case ELS_IOCB_TYPE: |
9a069e19 GM |
2617 | qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE); |
2618 | break; | |
2d70c103 | 2619 | case ABTS_RECV_24XX: |
2f424b9b QT |
2620 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
2621 | /* ensure that the ATIO queue is empty */ | |
2622 | qlt_handle_abts_recv(vha, (response_t *)pkt); | |
2623 | break; | |
2624 | } else { | |
2625 | /* drop through */ | |
2626 | qlt_24xx_process_atio_queue(vha, 1); | |
2627 | } | |
2d70c103 NB |
2628 | case ABTS_RESP_24XX: |
2629 | case CTIO_TYPE7: | |
2630 | case NOTIFY_ACK_TYPE: | |
f83adb61 | 2631 | case CTIO_CRC2: |
2d70c103 NB |
2632 | qlt_response_pkt_all_vps(vha, (response_t *)pkt); |
2633 | break; | |
54883291 SK |
2634 | case MARKER_TYPE: |
2635 | /* Do nothing in this case, this check is to prevent it | |
2636 | * from falling into default case | |
2637 | */ | |
2638 | break; | |
4440e46d AB |
2639 | case ABORT_IOCB_TYPE: |
2640 | qla24xx_abort_iocb_entry(vha, rsp->req, | |
2641 | (struct abort_entry_24xx *)pkt); | |
2642 | break; | |
9a853f71 AV |
2643 | default: |
2644 | /* Type Not Supported. */ | |
7c3df132 SK |
2645 | ql_dbg(ql_dbg_async, vha, 0x5042, |
2646 | "Received unknown response pkt type %x " | |
9a853f71 | 2647 | "entry status=%x.\n", |
7c3df132 | 2648 | pkt->entry_type, pkt->entry_status); |
9a853f71 AV |
2649 | break; |
2650 | } | |
2651 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; | |
2652 | wmb(); | |
2653 | } | |
2654 | ||
2655 | /* Adjust ring index */ | |
7ec0effd | 2656 | if (IS_P3P_TYPE(ha)) { |
a9083016 GM |
2657 | struct device_reg_82xx __iomem *reg = &ha->iobase->isp82; |
2658 | WRT_REG_DWORD(®->rsp_q_out[0], rsp->ring_index); | |
2659 | } else | |
2660 | WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index); | |
9a853f71 AV |
2661 | } |
2662 | ||
05236a05 | 2663 | static void |
e315cd28 | 2664 | qla2xxx_check_risc_status(scsi_qla_host_t *vha) |
05236a05 AV |
2665 | { |
2666 | int rval; | |
2667 | uint32_t cnt; | |
e315cd28 | 2668 | struct qla_hw_data *ha = vha->hw; |
05236a05 AV |
2669 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
2670 | ||
f73cb695 CD |
2671 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) && |
2672 | !IS_QLA27XX(ha)) | |
05236a05 AV |
2673 | return; |
2674 | ||
2675 | rval = QLA_SUCCESS; | |
2676 | WRT_REG_DWORD(®->iobase_addr, 0x7C00); | |
2677 | RD_REG_DWORD(®->iobase_addr); | |
2678 | WRT_REG_DWORD(®->iobase_window, 0x0001); | |
2679 | for (cnt = 10000; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 && | |
2680 | rval == QLA_SUCCESS; cnt--) { | |
2681 | if (cnt) { | |
2682 | WRT_REG_DWORD(®->iobase_window, 0x0001); | |
2683 | udelay(10); | |
2684 | } else | |
2685 | rval = QLA_FUNCTION_TIMEOUT; | |
2686 | } | |
2687 | if (rval == QLA_SUCCESS) | |
2688 | goto next_test; | |
2689 | ||
b2ec76c5 | 2690 | rval = QLA_SUCCESS; |
05236a05 AV |
2691 | WRT_REG_DWORD(®->iobase_window, 0x0003); |
2692 | for (cnt = 100; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 && | |
2693 | rval == QLA_SUCCESS; cnt--) { | |
2694 | if (cnt) { | |
2695 | WRT_REG_DWORD(®->iobase_window, 0x0003); | |
2696 | udelay(10); | |
2697 | } else | |
2698 | rval = QLA_FUNCTION_TIMEOUT; | |
2699 | } | |
2700 | if (rval != QLA_SUCCESS) | |
2701 | goto done; | |
2702 | ||
2703 | next_test: | |
2704 | if (RD_REG_DWORD(®->iobase_c8) & BIT_3) | |
7c3df132 SK |
2705 | ql_log(ql_log_info, vha, 0x504c, |
2706 | "Additional code -- 0x55AA.\n"); | |
05236a05 AV |
2707 | |
2708 | done: | |
2709 | WRT_REG_DWORD(®->iobase_window, 0x0000); | |
2710 | RD_REG_DWORD(®->iobase_window); | |
2711 | } | |
2712 | ||
9a853f71 | 2713 | /** |
6246b8a1 | 2714 | * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP24xx. |
9a853f71 AV |
2715 | * @irq: |
2716 | * @dev_id: SCSI driver HA context | |
9a853f71 AV |
2717 | * |
2718 | * Called by system whenever the host adapter generates an interrupt. | |
2719 | * | |
2720 | * Returns handled flag. | |
2721 | */ | |
2722 | irqreturn_t | |
7d12e780 | 2723 | qla24xx_intr_handler(int irq, void *dev_id) |
9a853f71 | 2724 | { |
e315cd28 AC |
2725 | scsi_qla_host_t *vha; |
2726 | struct qla_hw_data *ha; | |
9a853f71 AV |
2727 | struct device_reg_24xx __iomem *reg; |
2728 | int status; | |
9a853f71 AV |
2729 | unsigned long iter; |
2730 | uint32_t stat; | |
2731 | uint32_t hccr; | |
7d613ac6 | 2732 | uint16_t mb[8]; |
e315cd28 | 2733 | struct rsp_que *rsp; |
43fac4d9 | 2734 | unsigned long flags; |
9a853f71 | 2735 | |
e315cd28 AC |
2736 | rsp = (struct rsp_que *) dev_id; |
2737 | if (!rsp) { | |
3256b435 CD |
2738 | ql_log(ql_log_info, NULL, 0x5059, |
2739 | "%s: NULL response queue pointer.\n", __func__); | |
9a853f71 AV |
2740 | return IRQ_NONE; |
2741 | } | |
2742 | ||
e315cd28 | 2743 | ha = rsp->hw; |
9a853f71 AV |
2744 | reg = &ha->iobase->isp24; |
2745 | status = 0; | |
2746 | ||
85880801 AV |
2747 | if (unlikely(pci_channel_offline(ha->pdev))) |
2748 | return IRQ_HANDLED; | |
2749 | ||
43fac4d9 | 2750 | spin_lock_irqsave(&ha->hardware_lock, flags); |
2afa19a9 | 2751 | vha = pci_get_drvdata(ha->pdev); |
9a853f71 AV |
2752 | for (iter = 50; iter--; ) { |
2753 | stat = RD_REG_DWORD(®->host_status); | |
c821e0d5 | 2754 | if (qla2x00_check_reg32_for_disconnect(vha, stat)) |
f3ddac19 | 2755 | break; |
9a853f71 | 2756 | if (stat & HSRX_RISC_PAUSED) { |
85880801 | 2757 | if (unlikely(pci_channel_offline(ha->pdev))) |
14e660e6 SJ |
2758 | break; |
2759 | ||
9a853f71 AV |
2760 | hccr = RD_REG_DWORD(®->hccr); |
2761 | ||
7c3df132 SK |
2762 | ql_log(ql_log_warn, vha, 0x504b, |
2763 | "RISC paused -- HCCR=%x, Dumping firmware.\n", | |
2764 | hccr); | |
05236a05 | 2765 | |
e315cd28 | 2766 | qla2xxx_check_risc_status(vha); |
05236a05 | 2767 | |
e315cd28 AC |
2768 | ha->isp_ops->fw_dump(vha, 1); |
2769 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
9a853f71 AV |
2770 | break; |
2771 | } else if ((stat & HSRX_RISC_INT) == 0) | |
2772 | break; | |
2773 | ||
2774 | switch (stat & 0xff) { | |
fafbda9f AE |
2775 | case INTR_ROM_MB_SUCCESS: |
2776 | case INTR_ROM_MB_FAILED: | |
2777 | case INTR_MB_SUCCESS: | |
2778 | case INTR_MB_FAILED: | |
e315cd28 | 2779 | qla24xx_mbx_completion(vha, MSW(stat)); |
9a853f71 AV |
2780 | status |= MBX_INTERRUPT; |
2781 | ||
2782 | break; | |
fafbda9f | 2783 | case INTR_ASYNC_EVENT: |
9a853f71 AV |
2784 | mb[0] = MSW(stat); |
2785 | mb[1] = RD_REG_WORD(®->mailbox1); | |
2786 | mb[2] = RD_REG_WORD(®->mailbox2); | |
2787 | mb[3] = RD_REG_WORD(®->mailbox3); | |
73208dfd | 2788 | qla2x00_async_event(vha, rsp, mb); |
9a853f71 | 2789 | break; |
fafbda9f AE |
2790 | case INTR_RSP_QUE_UPDATE: |
2791 | case INTR_RSP_QUE_UPDATE_83XX: | |
2afa19a9 | 2792 | qla24xx_process_response_queue(vha, rsp); |
9a853f71 | 2793 | break; |
2f424b9b QT |
2794 | case INTR_ATIO_QUE_UPDATE:{ |
2795 | unsigned long flags2; | |
2796 | spin_lock_irqsave(&ha->tgt.atio_lock, flags2); | |
2797 | qlt_24xx_process_atio_queue(vha, 1); | |
2798 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2); | |
2d70c103 | 2799 | break; |
2f424b9b QT |
2800 | } |
2801 | case INTR_ATIO_RSP_QUE_UPDATE: { | |
2802 | unsigned long flags2; | |
2803 | spin_lock_irqsave(&ha->tgt.atio_lock, flags2); | |
2804 | qlt_24xx_process_atio_queue(vha, 1); | |
2805 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2); | |
2806 | ||
2d70c103 NB |
2807 | qla24xx_process_response_queue(vha, rsp); |
2808 | break; | |
2f424b9b | 2809 | } |
9a853f71 | 2810 | default: |
7c3df132 SK |
2811 | ql_dbg(ql_dbg_async, vha, 0x504f, |
2812 | "Unrecognized interrupt type (%d).\n", stat * 0xff); | |
9a853f71 AV |
2813 | break; |
2814 | } | |
2815 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT); | |
2816 | RD_REG_DWORD_RELAXED(®->hccr); | |
cb860bbd GM |
2817 | if (unlikely(IS_QLA83XX(ha) && (ha->pdev->revision == 1))) |
2818 | ndelay(3500); | |
9a853f71 | 2819 | } |
36439832 | 2820 | qla2x00_handle_mbx_completion(ha, status); |
43fac4d9 | 2821 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
9a853f71 | 2822 | |
9a853f71 AV |
2823 | return IRQ_HANDLED; |
2824 | } | |
2825 | ||
a8488abe AV |
2826 | static irqreturn_t |
2827 | qla24xx_msix_rsp_q(int irq, void *dev_id) | |
2828 | { | |
e315cd28 AC |
2829 | struct qla_hw_data *ha; |
2830 | struct rsp_que *rsp; | |
a8488abe | 2831 | struct device_reg_24xx __iomem *reg; |
2afa19a9 | 2832 | struct scsi_qla_host *vha; |
0f19bc68 | 2833 | unsigned long flags; |
f3ddac19 | 2834 | uint32_t stat = 0; |
a8488abe | 2835 | |
e315cd28 AC |
2836 | rsp = (struct rsp_que *) dev_id; |
2837 | if (!rsp) { | |
3256b435 CD |
2838 | ql_log(ql_log_info, NULL, 0x505a, |
2839 | "%s: NULL response queue pointer.\n", __func__); | |
e315cd28 AC |
2840 | return IRQ_NONE; |
2841 | } | |
2842 | ha = rsp->hw; | |
a8488abe AV |
2843 | reg = &ha->iobase->isp24; |
2844 | ||
0f19bc68 | 2845 | spin_lock_irqsave(&ha->hardware_lock, flags); |
a8488abe | 2846 | |
a67093d4 | 2847 | vha = pci_get_drvdata(ha->pdev); |
f3ddac19 CD |
2848 | /* |
2849 | * Use host_status register to check to PCI disconnection before we | |
2850 | * we process the response queue. | |
2851 | */ | |
2852 | stat = RD_REG_DWORD(®->host_status); | |
c821e0d5 | 2853 | if (qla2x00_check_reg32_for_disconnect(vha, stat)) |
f3ddac19 | 2854 | goto out; |
2afa19a9 | 2855 | qla24xx_process_response_queue(vha, rsp); |
3155754a | 2856 | if (!ha->flags.disable_msix_handshake) { |
eb94114b AC |
2857 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT); |
2858 | RD_REG_DWORD_RELAXED(®->hccr); | |
2859 | } | |
f3ddac19 | 2860 | out: |
0f19bc68 | 2861 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
a8488abe AV |
2862 | |
2863 | return IRQ_HANDLED; | |
2864 | } | |
2865 | ||
2866 | static irqreturn_t | |
2867 | qla24xx_msix_default(int irq, void *dev_id) | |
2868 | { | |
e315cd28 AC |
2869 | scsi_qla_host_t *vha; |
2870 | struct qla_hw_data *ha; | |
2871 | struct rsp_que *rsp; | |
a8488abe AV |
2872 | struct device_reg_24xx __iomem *reg; |
2873 | int status; | |
a8488abe AV |
2874 | uint32_t stat; |
2875 | uint32_t hccr; | |
7d613ac6 | 2876 | uint16_t mb[8]; |
0f19bc68 | 2877 | unsigned long flags; |
a8488abe | 2878 | |
e315cd28 AC |
2879 | rsp = (struct rsp_que *) dev_id; |
2880 | if (!rsp) { | |
3256b435 CD |
2881 | ql_log(ql_log_info, NULL, 0x505c, |
2882 | "%s: NULL response queue pointer.\n", __func__); | |
e315cd28 AC |
2883 | return IRQ_NONE; |
2884 | } | |
2885 | ha = rsp->hw; | |
a8488abe AV |
2886 | reg = &ha->iobase->isp24; |
2887 | status = 0; | |
2888 | ||
0f19bc68 | 2889 | spin_lock_irqsave(&ha->hardware_lock, flags); |
2afa19a9 | 2890 | vha = pci_get_drvdata(ha->pdev); |
87f27015 | 2891 | do { |
a8488abe | 2892 | stat = RD_REG_DWORD(®->host_status); |
c821e0d5 | 2893 | if (qla2x00_check_reg32_for_disconnect(vha, stat)) |
f3ddac19 | 2894 | break; |
a8488abe | 2895 | if (stat & HSRX_RISC_PAUSED) { |
85880801 | 2896 | if (unlikely(pci_channel_offline(ha->pdev))) |
14e660e6 SJ |
2897 | break; |
2898 | ||
a8488abe AV |
2899 | hccr = RD_REG_DWORD(®->hccr); |
2900 | ||
7c3df132 SK |
2901 | ql_log(ql_log_info, vha, 0x5050, |
2902 | "RISC paused -- HCCR=%x, Dumping firmware.\n", | |
2903 | hccr); | |
05236a05 | 2904 | |
e315cd28 | 2905 | qla2xxx_check_risc_status(vha); |
05236a05 | 2906 | |
e315cd28 AC |
2907 | ha->isp_ops->fw_dump(vha, 1); |
2908 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
a8488abe AV |
2909 | break; |
2910 | } else if ((stat & HSRX_RISC_INT) == 0) | |
2911 | break; | |
2912 | ||
2913 | switch (stat & 0xff) { | |
fafbda9f AE |
2914 | case INTR_ROM_MB_SUCCESS: |
2915 | case INTR_ROM_MB_FAILED: | |
2916 | case INTR_MB_SUCCESS: | |
2917 | case INTR_MB_FAILED: | |
e315cd28 | 2918 | qla24xx_mbx_completion(vha, MSW(stat)); |
a8488abe AV |
2919 | status |= MBX_INTERRUPT; |
2920 | ||
2921 | break; | |
fafbda9f | 2922 | case INTR_ASYNC_EVENT: |
a8488abe AV |
2923 | mb[0] = MSW(stat); |
2924 | mb[1] = RD_REG_WORD(®->mailbox1); | |
2925 | mb[2] = RD_REG_WORD(®->mailbox2); | |
2926 | mb[3] = RD_REG_WORD(®->mailbox3); | |
73208dfd | 2927 | qla2x00_async_event(vha, rsp, mb); |
a8488abe | 2928 | break; |
fafbda9f AE |
2929 | case INTR_RSP_QUE_UPDATE: |
2930 | case INTR_RSP_QUE_UPDATE_83XX: | |
2afa19a9 | 2931 | qla24xx_process_response_queue(vha, rsp); |
a8488abe | 2932 | break; |
2f424b9b QT |
2933 | case INTR_ATIO_QUE_UPDATE:{ |
2934 | unsigned long flags2; | |
2935 | spin_lock_irqsave(&ha->tgt.atio_lock, flags2); | |
2936 | qlt_24xx_process_atio_queue(vha, 1); | |
2937 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2); | |
2d70c103 | 2938 | break; |
2f424b9b QT |
2939 | } |
2940 | case INTR_ATIO_RSP_QUE_UPDATE: { | |
2941 | unsigned long flags2; | |
2942 | spin_lock_irqsave(&ha->tgt.atio_lock, flags2); | |
2943 | qlt_24xx_process_atio_queue(vha, 1); | |
2944 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2); | |
2945 | ||
2d70c103 NB |
2946 | qla24xx_process_response_queue(vha, rsp); |
2947 | break; | |
2f424b9b | 2948 | } |
a8488abe | 2949 | default: |
7c3df132 SK |
2950 | ql_dbg(ql_dbg_async, vha, 0x5051, |
2951 | "Unrecognized interrupt type (%d).\n", stat & 0xff); | |
a8488abe AV |
2952 | break; |
2953 | } | |
2954 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT); | |
87f27015 | 2955 | } while (0); |
36439832 | 2956 | qla2x00_handle_mbx_completion(ha, status); |
0f19bc68 | 2957 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
a8488abe | 2958 | |
a8488abe AV |
2959 | return IRQ_HANDLED; |
2960 | } | |
2961 | ||
d7459527 MH |
2962 | irqreturn_t |
2963 | qla2xxx_msix_rsp_q(int irq, void *dev_id) | |
2964 | { | |
2965 | struct qla_hw_data *ha; | |
2966 | struct qla_qpair *qpair; | |
2967 | struct device_reg_24xx __iomem *reg; | |
2968 | unsigned long flags; | |
2969 | ||
2970 | qpair = dev_id; | |
2971 | if (!qpair) { | |
2972 | ql_log(ql_log_info, NULL, 0x505b, | |
2973 | "%s: NULL response queue pointer.\n", __func__); | |
2974 | return IRQ_NONE; | |
2975 | } | |
2976 | ha = qpair->hw; | |
2977 | ||
2978 | /* Clear the interrupt, if enabled, for this response queue */ | |
2979 | if (unlikely(!ha->flags.disable_msix_handshake)) { | |
2980 | reg = &ha->iobase->isp24; | |
2981 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
2982 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT); | |
2983 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
2984 | } | |
2985 | ||
2986 | queue_work(ha->wq, &qpair->q_work); | |
2987 | ||
2988 | return IRQ_HANDLED; | |
2989 | } | |
2990 | ||
a8488abe AV |
2991 | /* Interrupt handling helpers. */ |
2992 | ||
2993 | struct qla_init_msix_entry { | |
a8488abe | 2994 | const char *name; |
476834c2 | 2995 | irq_handler_t handler; |
a8488abe AV |
2996 | }; |
2997 | ||
d7459527 | 2998 | static struct qla_init_msix_entry msix_entries[] = { |
2afa19a9 AC |
2999 | { "qla2xxx (default)", qla24xx_msix_default }, |
3000 | { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q }, | |
093df737 | 3001 | { "qla2xxx (atio_q)", qla83xx_msix_atio_q }, |
d7459527 | 3002 | { "qla2xxx (qpair_multiq)", qla2xxx_msix_rsp_q }, |
a8488abe AV |
3003 | }; |
3004 | ||
d7459527 | 3005 | static struct qla_init_msix_entry qla82xx_msix_entries[] = { |
a9083016 GM |
3006 | { "qla2xxx (default)", qla82xx_msix_default }, |
3007 | { "qla2xxx (rsp_q)", qla82xx_msix_rsp_q }, | |
3008 | }; | |
3009 | ||
a8488abe | 3010 | static int |
73208dfd | 3011 | qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp) |
a8488abe AV |
3012 | { |
3013 | int i, ret; | |
a8488abe | 3014 | struct qla_msix_entry *qentry; |
7c3df132 | 3015 | scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev); |
17e5fc58 CH |
3016 | struct irq_affinity desc = { |
3017 | .pre_vectors = QLA_BASE_VECTORS, | |
3018 | }; | |
3019 | ||
3020 | if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) | |
3021 | desc.pre_vectors++; | |
3022 | ||
3023 | ret = pci_alloc_irq_vectors_affinity(ha->pdev, QLA_BASE_VECTORS, | |
3024 | ha->msix_count, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY, | |
3025 | &desc); | |
73208dfd | 3026 | |
84e32a06 AG |
3027 | if (ret < 0) { |
3028 | ql_log(ql_log_fatal, vha, 0x00c7, | |
3029 | "MSI-X: Failed to enable support, " | |
3030 | "giving up -- %d/%d.\n", | |
3031 | ha->msix_count, ret); | |
3032 | goto msix_out; | |
3033 | } else if (ret < ha->msix_count) { | |
7c3df132 SK |
3034 | ql_log(ql_log_warn, vha, 0x00c6, |
3035 | "MSI-X: Failed to enable support " | |
d7459527 MH |
3036 | "with %d vectors, using %d vectors.\n", |
3037 | ha->msix_count, ret); | |
cb43285f | 3038 | ha->msix_count = ret; |
d7459527 MH |
3039 | /* Recalculate queue values */ |
3040 | if (ha->mqiobase && ql2xmqsupport) { | |
3041 | ha->max_req_queues = ha->msix_count - 1; | |
3042 | ||
3043 | /* ATIOQ needs 1 vector. That's 1 less QPair */ | |
3044 | if (QLA_TGT_MODE_ENABLED()) | |
3045 | ha->max_req_queues--; | |
3046 | ||
3047 | ha->max_rsp_queues = ha->max_req_queues; | |
3048 | ||
3049 | ha->max_qpairs = ha->max_req_queues - 1; | |
3050 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0190, | |
3051 | "Adjusted Max no of queues pairs: %d.\n", ha->max_qpairs); | |
3052 | } | |
73208dfd AC |
3053 | } |
3054 | ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) * | |
3055 | ha->msix_count, GFP_KERNEL); | |
3056 | if (!ha->msix_entries) { | |
7c3df132 SK |
3057 | ql_log(ql_log_fatal, vha, 0x00c8, |
3058 | "Failed to allocate memory for ha->msix_entries.\n"); | |
73208dfd | 3059 | ret = -ENOMEM; |
a8488abe AV |
3060 | goto msix_out; |
3061 | } | |
3062 | ha->flags.msix_enabled = 1; | |
3063 | ||
73208dfd AC |
3064 | for (i = 0; i < ha->msix_count; i++) { |
3065 | qentry = &ha->msix_entries[i]; | |
4fa18345 MH |
3066 | qentry->vector = pci_irq_vector(ha->pdev, i); |
3067 | qentry->entry = i; | |
a8488abe | 3068 | qentry->have_irq = 0; |
d7459527 | 3069 | qentry->in_use = 0; |
4fa18345 | 3070 | qentry->handle = NULL; |
a8488abe AV |
3071 | } |
3072 | ||
2afa19a9 | 3073 | /* Enable MSI-X vectors for the base queue */ |
17e5fc58 | 3074 | for (i = 0; i < QLA_BASE_VECTORS; i++) { |
2afa19a9 | 3075 | qentry = &ha->msix_entries[i]; |
4fa18345 | 3076 | qentry->handle = rsp; |
ef8d1d51 | 3077 | rsp->msix = qentry; |
d7459527 MH |
3078 | scnprintf(qentry->name, sizeof(qentry->name), |
3079 | msix_entries[i].name); | |
f324777e | 3080 | if (IS_P3P_TYPE(ha)) |
a9083016 GM |
3081 | ret = request_irq(qentry->vector, |
3082 | qla82xx_msix_entries[i].handler, | |
3083 | 0, qla82xx_msix_entries[i].name, rsp); | |
f324777e | 3084 | else |
a9083016 GM |
3085 | ret = request_irq(qentry->vector, |
3086 | msix_entries[i].handler, | |
3087 | 0, msix_entries[i].name, rsp); | |
f324777e CD |
3088 | if (ret) |
3089 | goto msix_register_fail; | |
3090 | qentry->have_irq = 1; | |
093df737 | 3091 | qentry->in_use = 1; |
f324777e CD |
3092 | } |
3093 | ||
3094 | /* | |
3095 | * If target mode is enable, also request the vector for the ATIO | |
3096 | * queue. | |
3097 | */ | |
3098 | if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) { | |
093df737 | 3099 | qentry = &ha->msix_entries[QLA_ATIO_VECTOR]; |
ef8d1d51 | 3100 | rsp->msix = qentry; |
d7459527 MH |
3101 | qentry->handle = rsp; |
3102 | scnprintf(qentry->name, sizeof(qentry->name), | |
093df737 QT |
3103 | msix_entries[QLA_ATIO_VECTOR].name); |
3104 | qentry->in_use = 1; | |
f324777e | 3105 | ret = request_irq(qentry->vector, |
093df737 QT |
3106 | msix_entries[QLA_ATIO_VECTOR].handler, |
3107 | 0, msix_entries[QLA_ATIO_VECTOR].name, rsp); | |
2afa19a9 | 3108 | qentry->have_irq = 1; |
73208dfd | 3109 | } |
73208dfd | 3110 | |
f324777e CD |
3111 | msix_register_fail: |
3112 | if (ret) { | |
3113 | ql_log(ql_log_fatal, vha, 0x00cb, | |
3114 | "MSI-X: unable to register handler -- %x/%d.\n", | |
3115 | qentry->vector, ret); | |
4fa18345 | 3116 | qla2x00_free_irqs(vha); |
f324777e CD |
3117 | ha->mqenable = 0; |
3118 | goto msix_out; | |
3119 | } | |
3120 | ||
73208dfd | 3121 | /* Enable MSI-X vector for response queue update for queue 0 */ |
f73cb695 | 3122 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
6246b8a1 | 3123 | if (ha->msixbase && ha->mqiobase && |
d7459527 MH |
3124 | (ha->max_rsp_queues > 1 || ha->max_req_queues > 1 || |
3125 | ql2xmqsupport)) | |
6246b8a1 GM |
3126 | ha->mqenable = 1; |
3127 | } else | |
d7459527 MH |
3128 | if (ha->mqiobase && |
3129 | (ha->max_rsp_queues > 1 || ha->max_req_queues > 1 || | |
3130 | ql2xmqsupport)) | |
6246b8a1 | 3131 | ha->mqenable = 1; |
7c3df132 SK |
3132 | ql_dbg(ql_dbg_multiq, vha, 0xc005, |
3133 | "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n", | |
3134 | ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues); | |
3135 | ql_dbg(ql_dbg_init, vha, 0x0055, | |
3136 | "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n", | |
3137 | ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues); | |
73208dfd | 3138 | |
a8488abe AV |
3139 | msix_out: |
3140 | return ret; | |
3141 | } | |
3142 | ||
3143 | int | |
73208dfd | 3144 | qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp) |
a8488abe | 3145 | { |
7fa3e239 | 3146 | int ret = QLA_FUNCTION_FAILED; |
f73cb695 | 3147 | device_reg_t *reg = ha->iobase; |
7c3df132 | 3148 | scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev); |
a8488abe AV |
3149 | |
3150 | /* If possible, enable MSI-X. */ | |
6246b8a1 | 3151 | if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) && |
f73cb695 CD |
3152 | !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha) && !IS_QLAFX00(ha) && |
3153 | !IS_QLA27XX(ha)) | |
6377a7ae BH |
3154 | goto skip_msi; |
3155 | ||
3156 | if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP && | |
3157 | (ha->pdev->subsystem_device == 0x7040 || | |
3158 | ha->pdev->subsystem_device == 0x7041 || | |
3159 | ha->pdev->subsystem_device == 0x1705)) { | |
7c3df132 SK |
3160 | ql_log(ql_log_warn, vha, 0x0034, |
3161 | "MSI-X: Unsupported ISP 2432 SSVID/SSDID (0x%X,0x%X).\n", | |
6377a7ae | 3162 | ha->pdev->subsystem_vendor, |
7c3df132 | 3163 | ha->pdev->subsystem_device); |
6377a7ae BH |
3164 | goto skip_msi; |
3165 | } | |
a8488abe | 3166 | |
42cd4f5d | 3167 | if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX)) { |
7c3df132 SK |
3168 | ql_log(ql_log_warn, vha, 0x0035, |
3169 | "MSI-X; Unsupported ISP2432 (0x%X, 0x%X).\n", | |
42cd4f5d | 3170 | ha->pdev->revision, QLA_MSIX_CHIP_REV_24XX); |
a8488abe AV |
3171 | goto skip_msix; |
3172 | } | |
3173 | ||
73208dfd | 3174 | ret = qla24xx_enable_msix(ha, rsp); |
a8488abe | 3175 | if (!ret) { |
7c3df132 SK |
3176 | ql_dbg(ql_dbg_init, vha, 0x0036, |
3177 | "MSI-X: Enabled (0x%X, 0x%X).\n", | |
3178 | ha->chip_revision, ha->fw_attributes); | |
963b0fdd | 3179 | goto clear_risc_ints; |
a8488abe | 3180 | } |
7fa3e239 | 3181 | |
a8488abe | 3182 | skip_msix: |
cbedb601 | 3183 | |
7fa3e239 SC |
3184 | ql_log(ql_log_info, vha, 0x0037, |
3185 | "Falling back-to MSI mode -%d.\n", ret); | |
3186 | ||
3a03eb79 | 3187 | if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) && |
f73cb695 CD |
3188 | !IS_QLA8001(ha) && !IS_P3P_TYPE(ha) && !IS_QLAFX00(ha) && |
3189 | !IS_QLA27XX(ha)) | |
cbedb601 AV |
3190 | goto skip_msi; |
3191 | ||
4fa18345 | 3192 | ret = pci_alloc_irq_vectors(ha->pdev, 1, 1, PCI_IRQ_MSI); |
cbedb601 | 3193 | if (!ret) { |
7c3df132 SK |
3194 | ql_dbg(ql_dbg_init, vha, 0x0038, |
3195 | "MSI: Enabled.\n"); | |
cbedb601 | 3196 | ha->flags.msi_enabled = 1; |
a9083016 | 3197 | } else |
7c3df132 | 3198 | ql_log(ql_log_warn, vha, 0x0039, |
7fa3e239 SC |
3199 | "Falling back-to INTa mode -- %d.\n", ret); |
3200 | skip_msi: | |
a033b655 GM |
3201 | |
3202 | /* Skip INTx on ISP82xx. */ | |
3203 | if (!ha->flags.msi_enabled && IS_QLA82XX(ha)) | |
3204 | return QLA_FUNCTION_FAILED; | |
3205 | ||
fd34f556 | 3206 | ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler, |
7992abfc MH |
3207 | ha->flags.msi_enabled ? 0 : IRQF_SHARED, |
3208 | QLA2XXX_DRIVER_NAME, rsp); | |
963b0fdd | 3209 | if (ret) { |
7c3df132 | 3210 | ql_log(ql_log_warn, vha, 0x003a, |
a8488abe AV |
3211 | "Failed to reserve interrupt %d already in use.\n", |
3212 | ha->pdev->irq); | |
963b0fdd | 3213 | goto fail; |
8ae6d9c7 | 3214 | } else if (!ha->flags.msi_enabled) { |
68d91cbd SK |
3215 | ql_dbg(ql_dbg_init, vha, 0x0125, |
3216 | "INTa mode: Enabled.\n"); | |
8ae6d9c7 GM |
3217 | ha->flags.mr_intr_valid = 1; |
3218 | } | |
7992abfc | 3219 | |
963b0fdd | 3220 | clear_risc_ints: |
4bb2efc4 JC |
3221 | if (IS_FWI2_CAPABLE(ha) || IS_QLAFX00(ha)) |
3222 | goto fail; | |
963b0fdd | 3223 | |
c6952483 | 3224 | spin_lock_irq(&ha->hardware_lock); |
4bb2efc4 | 3225 | WRT_REG_WORD(®->isp.semaphore, 0); |
c6952483 | 3226 | spin_unlock_irq(&ha->hardware_lock); |
a8488abe | 3227 | |
963b0fdd | 3228 | fail: |
a8488abe AV |
3229 | return ret; |
3230 | } | |
3231 | ||
3232 | void | |
e315cd28 | 3233 | qla2x00_free_irqs(scsi_qla_host_t *vha) |
a8488abe | 3234 | { |
e315cd28 | 3235 | struct qla_hw_data *ha = vha->hw; |
9a347ff4 | 3236 | struct rsp_que *rsp; |
4fa18345 MH |
3237 | struct qla_msix_entry *qentry; |
3238 | int i; | |
9a347ff4 CD |
3239 | |
3240 | /* | |
3241 | * We need to check that ha->rsp_q_map is valid in case we are called | |
3242 | * from a probe failure context. | |
3243 | */ | |
3244 | if (!ha->rsp_q_map || !ha->rsp_q_map[0]) | |
27873de9 | 3245 | goto free_irqs; |
9a347ff4 | 3246 | rsp = ha->rsp_q_map[0]; |
a8488abe | 3247 | |
4fa18345 MH |
3248 | if (ha->flags.msix_enabled) { |
3249 | for (i = 0; i < ha->msix_count; i++) { | |
3250 | qentry = &ha->msix_entries[i]; | |
3251 | if (qentry->have_irq) { | |
3252 | irq_set_affinity_notifier(qentry->vector, NULL); | |
3253 | free_irq(pci_irq_vector(ha->pdev, i), qentry->handle); | |
3254 | } | |
3255 | } | |
3256 | kfree(ha->msix_entries); | |
3257 | ha->msix_entries = NULL; | |
3258 | ha->flags.msix_enabled = 0; | |
3259 | ql_dbg(ql_dbg_init, vha, 0x0042, | |
3260 | "Disabled MSI-X.\n"); | |
3261 | } else { | |
3262 | free_irq(pci_irq_vector(ha->pdev, 0), rsp); | |
3263 | } | |
e315cd28 | 3264 | |
27873de9 | 3265 | free_irqs: |
4fa18345 | 3266 | pci_free_irq_vectors(ha->pdev); |
a8488abe | 3267 | } |
73208dfd | 3268 | |
d7459527 MH |
3269 | int qla25xx_request_irq(struct qla_hw_data *ha, struct qla_qpair *qpair, |
3270 | struct qla_msix_entry *msix, int vector_type) | |
73208dfd | 3271 | { |
d7459527 | 3272 | struct qla_init_msix_entry *intr = &msix_entries[vector_type]; |
7c3df132 | 3273 | scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev); |
73208dfd AC |
3274 | int ret; |
3275 | ||
d7459527 MH |
3276 | scnprintf(msix->name, sizeof(msix->name), |
3277 | "qla2xxx%lu_qpair%d", vha->host_no, qpair->id); | |
3278 | ret = request_irq(msix->vector, intr->handler, 0, msix->name, qpair); | |
73208dfd | 3279 | if (ret) { |
7c3df132 SK |
3280 | ql_log(ql_log_fatal, vha, 0x00e6, |
3281 | "MSI-X: Unable to register handler -- %x/%d.\n", | |
3282 | msix->vector, ret); | |
73208dfd AC |
3283 | return ret; |
3284 | } | |
3285 | msix->have_irq = 1; | |
d7459527 | 3286 | msix->handle = qpair; |
73208dfd AC |
3287 | return ret; |
3288 | } |