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