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