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