Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 2 | * QLogic Fibre Channel HBA Driver |
Andrew Vasquez | 01e58d8 | 2008-04-03 13:13:13 -0700 | [diff] [blame] | 3 | * Copyright (c) 2003-2008 QLogic Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | #include "qla_def.h" |
| 8 | |
Andrew Vasquez | 05236a0 | 2007-09-20 14:07:37 -0700 | [diff] [blame] | 9 | #include <linux/delay.h> |
Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 10 | #include <scsi/scsi_tcq.h> |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | static void qla2x00_process_completed_request(struct scsi_qla_host *, uint32_t); |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 14 | static void qla2x00_status_entry(scsi_qla_host_t *, void *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | static void qla2x00_status_cont_entry(scsi_qla_host_t *, sts_cont_entry_t *); |
| 16 | static void qla2x00_error_entry(scsi_qla_host_t *, sts_entry_t *); |
| 17 | static void qla2x00_ms_entry(scsi_qla_host_t *, ms_iocb_entry_t *); |
| 18 | |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 19 | static void qla24xx_ms_entry(scsi_qla_host_t *, struct ct_entry_24xx *); |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | /** |
| 22 | * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200. |
| 23 | * @irq: |
| 24 | * @dev_id: SCSI driver HA context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | * |
| 26 | * Called by system whenever the host adapter generates an interrupt. |
| 27 | * |
| 28 | * Returns handled flag. |
| 29 | */ |
| 30 | irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 31 | qla2100_intr_handler(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | { |
| 33 | scsi_qla_host_t *ha; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 34 | struct device_reg_2xxx __iomem *reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | unsigned long iter; |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 37 | uint16_t hccr; |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 38 | uint16_t mb[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | ha = (scsi_qla_host_t *) dev_id; |
| 41 | if (!ha) { |
| 42 | printk(KERN_INFO |
| 43 | "%s(): NULL host pointer\n", __func__); |
| 44 | return (IRQ_NONE); |
| 45 | } |
| 46 | |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 47 | reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | status = 0; |
| 49 | |
Andrew Vasquez | c695248 | 2008-04-03 13:13:17 -0700 | [diff] [blame] | 50 | spin_lock(&ha->hardware_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | for (iter = 50; iter--; ) { |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 52 | hccr = RD_REG_WORD(®->hccr); |
| 53 | if (hccr & HCCR_RISC_PAUSE) { |
| 54 | if (pci_channel_offline(ha->pdev)) |
| 55 | break; |
| 56 | |
| 57 | /* |
| 58 | * Issue a "HARD" reset in order for the RISC interrupt |
| 59 | * bit to be cleared. Schedule a big hammmer to get |
| 60 | * out of the RISC PAUSED state. |
| 61 | */ |
| 62 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 63 | RD_REG_WORD(®->hccr); |
| 64 | |
| 65 | ha->isp_ops->fw_dump(ha, 1); |
| 66 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 67 | break; |
| 68 | } else if ((RD_REG_WORD(®->istatus) & ISR_RISC_INT) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | break; |
| 70 | |
| 71 | if (RD_REG_WORD(®->semaphore) & BIT_0) { |
| 72 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 73 | RD_REG_WORD(®->hccr); |
| 74 | |
| 75 | /* Get mailbox data. */ |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 76 | mb[0] = RD_MAILBOX_REG(ha, reg, 0); |
| 77 | if (mb[0] > 0x3fff && mb[0] < 0x8000) { |
| 78 | qla2x00_mbx_completion(ha, mb[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | status |= MBX_INTERRUPT; |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 80 | } else if (mb[0] > 0x7fff && mb[0] < 0xc000) { |
| 81 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 82 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 83 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 84 | qla2x00_async_event(ha, mb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } else { |
| 86 | /*EMPTY*/ |
| 87 | DEBUG2(printk("scsi(%ld): Unrecognized " |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 88 | "interrupt type (%d).\n", |
| 89 | ha->host_no, mb[0])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | /* Release mailbox registers. */ |
| 92 | WRT_REG_WORD(®->semaphore, 0); |
| 93 | RD_REG_WORD(®->semaphore); |
| 94 | } else { |
| 95 | qla2x00_process_response_queue(ha); |
| 96 | |
| 97 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 98 | RD_REG_WORD(®->hccr); |
| 99 | } |
| 100 | } |
Andrew Vasquez | c695248 | 2008-04-03 13:13:17 -0700 | [diff] [blame] | 101 | spin_unlock(&ha->hardware_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) && |
| 104 | (status & MBX_INTERRUPT) && ha->flags.mbox_int) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); |
Marcus Barrow | 0b05a1f | 2008-01-17 09:02:13 -0800 | [diff] [blame] | 106 | complete(&ha->mbx_intr_comp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | return (IRQ_HANDLED); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx. |
| 114 | * @irq: |
| 115 | * @dev_id: SCSI driver HA context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | * |
| 117 | * Called by system whenever the host adapter generates an interrupt. |
| 118 | * |
| 119 | * Returns handled flag. |
| 120 | */ |
| 121 | irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 122 | qla2300_intr_handler(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
| 124 | scsi_qla_host_t *ha; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 125 | struct device_reg_2xxx __iomem *reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | unsigned long iter; |
| 128 | uint32_t stat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | uint16_t hccr; |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 130 | uint16_t mb[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
| 132 | ha = (scsi_qla_host_t *) dev_id; |
| 133 | if (!ha) { |
| 134 | printk(KERN_INFO |
| 135 | "%s(): NULL host pointer\n", __func__); |
| 136 | return (IRQ_NONE); |
| 137 | } |
| 138 | |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 139 | reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | status = 0; |
| 141 | |
Andrew Vasquez | c695248 | 2008-04-03 13:13:17 -0700 | [diff] [blame] | 142 | spin_lock(&ha->hardware_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | for (iter = 50; iter--; ) { |
| 144 | stat = RD_REG_DWORD(®->u.isp2300.host_status); |
| 145 | if (stat & HSR_RISC_PAUSED) { |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 146 | if (pci_channel_offline(ha->pdev)) |
| 147 | break; |
| 148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | hccr = RD_REG_WORD(®->hccr); |
| 150 | if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8)) |
Andrew Vasquez | 07f3180 | 2006-12-13 19:20:31 -0800 | [diff] [blame] | 151 | qla_printk(KERN_INFO, ha, "Parity error -- " |
| 152 | "HCCR=%x, Dumping firmware!\n", hccr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | else |
Andrew Vasquez | 07f3180 | 2006-12-13 19:20:31 -0800 | [diff] [blame] | 154 | qla_printk(KERN_INFO, ha, "RISC paused -- " |
| 155 | "HCCR=%x, Dumping firmware!\n", hccr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | /* |
| 158 | * Issue a "HARD" reset in order for the RISC |
| 159 | * interrupt bit to be cleared. Schedule a big |
| 160 | * hammmer to get out of the RISC PAUSED state. |
| 161 | */ |
| 162 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 163 | RD_REG_WORD(®->hccr); |
Andrew Vasquez | 07f3180 | 2006-12-13 19:20:31 -0800 | [diff] [blame] | 164 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 165 | ha->isp_ops->fw_dump(ha, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 167 | break; |
| 168 | } else if ((stat & HSR_RISC_INT) == 0) |
| 169 | break; |
| 170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | switch (stat & 0xff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | case 0x1: |
| 173 | case 0x2: |
| 174 | case 0x10: |
| 175 | case 0x11: |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 176 | qla2x00_mbx_completion(ha, MSW(stat)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | status |= MBX_INTERRUPT; |
| 178 | |
| 179 | /* Release mailbox registers. */ |
| 180 | WRT_REG_WORD(®->semaphore, 0); |
| 181 | break; |
| 182 | case 0x12: |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 183 | mb[0] = MSW(stat); |
| 184 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 185 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 186 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 187 | qla2x00_async_event(ha, mb); |
| 188 | break; |
| 189 | case 0x13: |
| 190 | qla2x00_process_response_queue(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | break; |
| 192 | case 0x15: |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 193 | mb[0] = MBA_CMPLT_1_16BIT; |
| 194 | mb[1] = MSW(stat); |
| 195 | qla2x00_async_event(ha, mb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | break; |
| 197 | case 0x16: |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 198 | mb[0] = MBA_SCSI_COMPLETION; |
| 199 | mb[1] = MSW(stat); |
| 200 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 201 | qla2x00_async_event(ha, mb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | break; |
| 203 | default: |
| 204 | DEBUG2(printk("scsi(%ld): Unrecognized interrupt type " |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 205 | "(%d).\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | ha->host_no, stat & 0xff)); |
| 207 | break; |
| 208 | } |
| 209 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 210 | RD_REG_WORD_RELAXED(®->hccr); |
| 211 | } |
Andrew Vasquez | c695248 | 2008-04-03 13:13:17 -0700 | [diff] [blame] | 212 | spin_unlock(&ha->hardware_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) && |
| 215 | (status & MBX_INTERRUPT) && ha->flags.mbox_int) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); |
Marcus Barrow | 0b05a1f | 2008-01-17 09:02:13 -0800 | [diff] [blame] | 217 | complete(&ha->mbx_intr_comp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | return (IRQ_HANDLED); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * qla2x00_mbx_completion() - Process mailbox command completions. |
| 225 | * @ha: SCSI driver HA context |
| 226 | * @mb0: Mailbox0 register |
| 227 | */ |
| 228 | static void |
| 229 | qla2x00_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0) |
| 230 | { |
| 231 | uint16_t cnt; |
| 232 | uint16_t __iomem *wptr; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 233 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
| 235 | /* Load return mailbox registers. */ |
| 236 | ha->flags.mbox_int = 1; |
| 237 | ha->mailbox_out[0] = mb0; |
| 238 | wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1); |
| 239 | |
| 240 | for (cnt = 1; cnt < ha->mbx_count; cnt++) { |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 241 | if (IS_QLA2200(ha) && cnt == 8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8); |
| 243 | if (cnt == 4 || cnt == 5) |
| 244 | ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr); |
| 245 | else |
| 246 | ha->mailbox_out[cnt] = RD_REG_WORD(wptr); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | wptr++; |
| 249 | } |
| 250 | |
| 251 | if (ha->mcp) { |
| 252 | DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n", |
| 253 | __func__, ha->host_no, ha->mcp->mb[0])); |
| 254 | } else { |
| 255 | DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n", |
| 256 | __func__, ha->host_no)); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * qla2x00_async_event() - Process aynchronous events. |
| 262 | * @ha: SCSI driver HA context |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 263 | * @mb: Mailbox registers (0 - 3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | */ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 265 | void |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 266 | qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | { |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 268 | #define LS_UNKNOWN 2 |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 269 | static char *link_speeds[5] = { "1", "2", "?", "4", "8" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | char *link_speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | uint16_t handle_cnt; |
| 272 | uint16_t cnt; |
| 273 | uint32_t handles[5]; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 274 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | uint32_t rscn_entry, host_pid; |
| 276 | uint8_t rscn_queue_index; |
| 277 | |
| 278 | /* Setup to process RIO completion. */ |
| 279 | handle_cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | switch (mb[0]) { |
| 281 | case MBA_SCSI_COMPLETION: |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 282 | handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | handle_cnt = 1; |
| 284 | break; |
| 285 | case MBA_CMPLT_1_16BIT: |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 286 | handles[0] = mb[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | handle_cnt = 1; |
| 288 | mb[0] = MBA_SCSI_COMPLETION; |
| 289 | break; |
| 290 | case MBA_CMPLT_2_16BIT: |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 291 | handles[0] = mb[1]; |
| 292 | handles[1] = mb[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | handle_cnt = 2; |
| 294 | mb[0] = MBA_SCSI_COMPLETION; |
| 295 | break; |
| 296 | case MBA_CMPLT_3_16BIT: |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 297 | handles[0] = mb[1]; |
| 298 | handles[1] = mb[2]; |
| 299 | handles[2] = mb[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | handle_cnt = 3; |
| 301 | mb[0] = MBA_SCSI_COMPLETION; |
| 302 | break; |
| 303 | case MBA_CMPLT_4_16BIT: |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 304 | handles[0] = mb[1]; |
| 305 | handles[1] = mb[2]; |
| 306 | handles[2] = mb[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6); |
| 308 | handle_cnt = 4; |
| 309 | mb[0] = MBA_SCSI_COMPLETION; |
| 310 | break; |
| 311 | case MBA_CMPLT_5_16BIT: |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 312 | handles[0] = mb[1]; |
| 313 | handles[1] = mb[2]; |
| 314 | handles[2] = mb[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6); |
| 316 | handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7); |
| 317 | handle_cnt = 5; |
| 318 | mb[0] = MBA_SCSI_COMPLETION; |
| 319 | break; |
| 320 | case MBA_CMPLT_2_32BIT: |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 321 | handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | handles[1] = le32_to_cpu( |
| 323 | ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) | |
| 324 | RD_MAILBOX_REG(ha, reg, 6)); |
| 325 | handle_cnt = 2; |
| 326 | mb[0] = MBA_SCSI_COMPLETION; |
| 327 | break; |
| 328 | default: |
| 329 | break; |
| 330 | } |
| 331 | |
| 332 | switch (mb[0]) { |
| 333 | case MBA_SCSI_COMPLETION: /* Fast Post */ |
| 334 | if (!ha->flags.online) |
| 335 | break; |
| 336 | |
| 337 | for (cnt = 0; cnt < handle_cnt; cnt++) |
| 338 | qla2x00_process_completed_request(ha, handles[cnt]); |
| 339 | break; |
| 340 | |
| 341 | case MBA_RESET: /* Reset */ |
| 342 | DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", ha->host_no)); |
| 343 | |
| 344 | set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); |
| 345 | break; |
| 346 | |
| 347 | case MBA_SYSTEM_ERR: /* System Error */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | qla_printk(KERN_INFO, ha, |
| 349 | "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n", |
| 350 | mb[1], mb[2], mb[3]); |
| 351 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 352 | ha->isp_ops->fw_dump(ha, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 354 | if (IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 355 | if (mb[1] == 0 && mb[2] == 0) { |
| 356 | qla_printk(KERN_ERR, ha, |
| 357 | "Unrecoverable Hardware Error: adapter " |
| 358 | "marked OFFLINE!\n"); |
| 359 | ha->flags.online = 0; |
| 360 | } else |
| 361 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 362 | } else if (mb[1] == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | qla_printk(KERN_INFO, ha, |
| 364 | "Unrecoverable Hardware Error: adapter marked " |
| 365 | "OFFLINE!\n"); |
| 366 | ha->flags.online = 0; |
| 367 | } else |
| 368 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 369 | break; |
| 370 | |
| 371 | case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */ |
| 372 | DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n", |
| 373 | ha->host_no)); |
| 374 | qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n"); |
| 375 | |
| 376 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 377 | break; |
| 378 | |
| 379 | case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */ |
| 380 | DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n", |
| 381 | ha->host_no)); |
| 382 | qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n"); |
| 383 | |
| 384 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 385 | break; |
| 386 | |
| 387 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up */ |
| 388 | DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n", |
| 389 | ha->host_no)); |
| 390 | break; |
| 391 | |
| 392 | case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | DEBUG2(printk("scsi(%ld): LIP occured (%x).\n", ha->host_no, |
| 394 | mb[1])); |
| 395 | qla_printk(KERN_INFO, ha, "LIP occured (%x).\n", mb[1]); |
| 396 | |
| 397 | if (atomic_read(&ha->loop_state) != LOOP_DOWN) { |
| 398 | atomic_set(&ha->loop_state, LOOP_DOWN); |
| 399 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 400 | qla2x00_mark_all_devices_lost(ha, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 403 | if (ha->parent) { |
| 404 | atomic_set(&ha->vp_state, VP_FAILED); |
| 405 | fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED); |
| 406 | } |
| 407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); |
| 409 | |
| 410 | ha->flags.management_server_logged_in = 0; |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame^] | 411 | qla2x00_post_aen_work(ha, FCH_EVT_LIP, mb[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | break; |
| 413 | |
| 414 | case MBA_LOOP_UP: /* Loop Up Event */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 416 | link_speed = link_speeds[0]; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 417 | ha->link_data_rate = PORT_SPEED_1GB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | } else { |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 419 | link_speed = link_speeds[LS_UNKNOWN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | if (mb[1] < 5) |
| 421 | link_speed = link_speeds[mb[1]]; |
| 422 | ha->link_data_rate = mb[1]; |
| 423 | } |
| 424 | |
| 425 | DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n", |
| 426 | ha->host_no, link_speed)); |
| 427 | qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n", |
| 428 | link_speed); |
| 429 | |
| 430 | ha->flags.management_server_logged_in = 0; |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame^] | 431 | qla2x00_post_aen_work(ha, FCH_EVT_LINKUP, ha->link_data_rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | break; |
| 433 | |
| 434 | case MBA_LOOP_DOWN: /* Loop Down Event */ |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 435 | DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN (%x).\n", |
| 436 | ha->host_no, mb[1])); |
| 437 | qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x).\n", mb[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
| 439 | if (atomic_read(&ha->loop_state) != LOOP_DOWN) { |
| 440 | atomic_set(&ha->loop_state, LOOP_DOWN); |
| 441 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 442 | ha->device_flags |= DFLG_NO_CABLE; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 443 | qla2x00_mark_all_devices_lost(ha, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 446 | if (ha->parent) { |
| 447 | atomic_set(&ha->vp_state, VP_FAILED); |
| 448 | fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED); |
| 449 | } |
| 450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | ha->flags.management_server_logged_in = 0; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 452 | ha->link_data_rate = PORT_SPEED_UNKNOWN; |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 453 | if (ql2xfdmienable) |
| 454 | set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags); |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame^] | 455 | qla2x00_post_aen_work(ha, FCH_EVT_LINKDOWN, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | break; |
| 457 | |
| 458 | case MBA_LIP_RESET: /* LIP reset occurred */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n", |
| 460 | ha->host_no, mb[1])); |
| 461 | qla_printk(KERN_INFO, ha, |
| 462 | "LIP reset occured (%x).\n", mb[1]); |
| 463 | |
| 464 | if (atomic_read(&ha->loop_state) != LOOP_DOWN) { |
| 465 | atomic_set(&ha->loop_state, LOOP_DOWN); |
| 466 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 467 | qla2x00_mark_all_devices_lost(ha, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 470 | if (ha->parent) { |
| 471 | atomic_set(&ha->vp_state, VP_FAILED); |
| 472 | fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED); |
| 473 | } |
| 474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); |
| 476 | |
| 477 | ha->operating_mode = LOOP; |
| 478 | ha->flags.management_server_logged_in = 0; |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame^] | 479 | qla2x00_post_aen_work(ha, FCH_EVT_LIPRESET, mb[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | break; |
| 481 | |
| 482 | case MBA_POINT_TO_POINT: /* Point-to-Point */ |
| 483 | if (IS_QLA2100(ha)) |
| 484 | break; |
| 485 | |
| 486 | DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n", |
| 487 | ha->host_no)); |
| 488 | |
| 489 | /* |
| 490 | * Until there's a transition from loop down to loop up, treat |
| 491 | * this as loop down only. |
| 492 | */ |
| 493 | if (atomic_read(&ha->loop_state) != LOOP_DOWN) { |
| 494 | atomic_set(&ha->loop_state, LOOP_DOWN); |
| 495 | if (!atomic_read(&ha->loop_down_timer)) |
| 496 | atomic_set(&ha->loop_down_timer, |
| 497 | LOOP_DOWN_TIME); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 498 | qla2x00_mark_all_devices_lost(ha, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 501 | if (ha->parent) { |
| 502 | atomic_set(&ha->vp_state, VP_FAILED); |
| 503 | fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED); |
| 504 | } |
| 505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) { |
| 507 | set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); |
| 508 | } |
| 509 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); |
Andrew Vasquez | 4346b14 | 2006-12-13 19:20:28 -0800 | [diff] [blame] | 510 | |
| 511 | ha->flags.gpsc_supported = 1; |
Andrew Vasquez | 02d638b | 2007-08-12 18:22:54 -0700 | [diff] [blame] | 512 | ha->flags.management_server_logged_in = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | break; |
| 514 | |
| 515 | case MBA_CHG_IN_CONNECTION: /* Change in connection mode */ |
| 516 | if (IS_QLA2100(ha)) |
| 517 | break; |
| 518 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection " |
| 520 | "received.\n", |
| 521 | ha->host_no)); |
| 522 | qla_printk(KERN_INFO, ha, |
| 523 | "Configuration change detected: value=%x.\n", mb[1]); |
| 524 | |
| 525 | if (atomic_read(&ha->loop_state) != LOOP_DOWN) { |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 526 | atomic_set(&ha->loop_state, LOOP_DOWN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | if (!atomic_read(&ha->loop_down_timer)) |
| 528 | atomic_set(&ha->loop_down_timer, |
| 529 | LOOP_DOWN_TIME); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 530 | qla2x00_mark_all_devices_lost(ha, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 533 | if (ha->parent) { |
| 534 | atomic_set(&ha->vp_state, VP_FAILED); |
| 535 | fc_vport_set_state(ha->fc_vport, FC_VPORT_FAILED); |
| 536 | } |
| 537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 539 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 540 | break; |
| 541 | |
| 542 | case MBA_PORT_UPDATE: /* Port database update */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET |
| 545 | * event etc. earlier indicating loop is down) then process |
| 546 | * it. Otherwise ignore it and Wait for RSCN to come in. |
| 547 | */ |
| 548 | atomic_set(&ha->loop_down_timer, 0); |
| 549 | if (atomic_read(&ha->loop_state) != LOOP_DOWN && |
| 550 | atomic_read(&ha->loop_state) != LOOP_DEAD) { |
| 551 | DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE " |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 552 | "ignored %04x/%04x/%04x.\n", ha->host_no, mb[1], |
| 553 | mb[2], mb[3])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | break; |
| 555 | } |
| 556 | |
| 557 | DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n", |
| 558 | ha->host_no)); |
| 559 | DEBUG(printk(KERN_INFO |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 560 | "scsi(%ld): Port database changed %04x %04x %04x.\n", |
| 561 | ha->host_no, mb[1], mb[2], mb[3])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | |
| 563 | /* |
| 564 | * Mark all devices as missing so we will login again. |
| 565 | */ |
| 566 | atomic_set(&ha->loop_state, LOOP_UP); |
| 567 | |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 568 | qla2x00_mark_all_devices_lost(ha, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
| 570 | ha->flags.rscn_queue_overflow = 1; |
| 571 | |
| 572 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 573 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | break; |
| 575 | |
| 576 | case MBA_RSCN_UPDATE: /* State Change Registration */ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 577 | /* Check if the Vport has issued a SCR */ |
| 578 | if (ha->parent && test_bit(VP_SCR_NEEDED, &ha->vp_flags)) |
| 579 | break; |
Shyam Sundar | f4a8dbc | 2007-11-12 10:30:59 -0800 | [diff] [blame] | 580 | /* Only handle SCNs for our Vport index. */ |
| 581 | if (ha->flags.npiv_supported && ha->vp_idx != mb[3]) |
| 582 | break; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n", |
| 585 | ha->host_no)); |
| 586 | DEBUG(printk(KERN_INFO |
Shyam Sundar | f4a8dbc | 2007-11-12 10:30:59 -0800 | [diff] [blame] | 587 | "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n", |
| 588 | ha->host_no, mb[1], mb[2], mb[3])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | |
| 590 | rscn_entry = (mb[1] << 16) | mb[2]; |
| 591 | host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) | |
| 592 | ha->d_id.b.al_pa; |
| 593 | if (rscn_entry == host_pid) { |
| 594 | DEBUG(printk(KERN_INFO |
| 595 | "scsi(%ld): Ignoring RSCN update to local host " |
| 596 | "port ID (%06x)\n", |
| 597 | ha->host_no, host_pid)); |
| 598 | break; |
| 599 | } |
| 600 | |
| 601 | rscn_queue_index = ha->rscn_in_ptr + 1; |
| 602 | if (rscn_queue_index == MAX_RSCN_COUNT) |
| 603 | rscn_queue_index = 0; |
| 604 | if (rscn_queue_index != ha->rscn_out_ptr) { |
| 605 | ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry; |
| 606 | ha->rscn_in_ptr = rscn_queue_index; |
| 607 | } else { |
| 608 | ha->flags.rscn_queue_overflow = 1; |
| 609 | } |
| 610 | |
| 611 | atomic_set(&ha->loop_state, LOOP_UPDATE); |
| 612 | atomic_set(&ha->loop_down_timer, 0); |
| 613 | ha->flags.management_server_logged_in = 0; |
| 614 | |
| 615 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 616 | set_bit(RSCN_UPDATE, &ha->dpc_flags); |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame^] | 617 | qla2x00_post_aen_work(ha, FCH_EVT_RSCN, rscn_entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | break; |
| 619 | |
| 620 | /* case MBA_RIO_RESPONSE: */ |
| 621 | case MBA_ZIO_RESPONSE: |
| 622 | DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n", |
| 623 | ha->host_no)); |
| 624 | DEBUG(printk(KERN_INFO |
| 625 | "scsi(%ld): [R|Z]IO update completion.\n", |
| 626 | ha->host_no)); |
| 627 | |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 628 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 629 | qla24xx_process_response_queue(ha); |
| 630 | else |
| 631 | qla2x00_process_response_queue(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | break; |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 633 | |
| 634 | case MBA_DISCARD_RND_FRAME: |
| 635 | DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x " |
| 636 | "%04x.\n", ha->host_no, mb[1], mb[2], mb[3])); |
| 637 | break; |
Andrew Vasquez | 45ebeb5 | 2006-08-01 13:48:14 -0700 | [diff] [blame] | 638 | |
| 639 | case MBA_TRACE_NOTIFICATION: |
| 640 | DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n", |
| 641 | ha->host_no, mb[1], mb[2])); |
| 642 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 644 | |
| 645 | if (!ha->parent && ha->num_vhosts) |
| 646 | qla2x00_alert_all_vps(ha, mb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 649 | static void |
| 650 | qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data) |
| 651 | { |
| 652 | fc_port_t *fcport = data; |
| 653 | |
| 654 | if (fcport->ha->max_q_depth <= sdev->queue_depth) |
| 655 | return; |
| 656 | |
| 657 | if (sdev->ordered_tags) |
| 658 | scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, |
| 659 | sdev->queue_depth + 1); |
| 660 | else |
| 661 | scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, |
| 662 | sdev->queue_depth + 1); |
| 663 | |
| 664 | fcport->last_ramp_up = jiffies; |
| 665 | |
| 666 | DEBUG2(qla_printk(KERN_INFO, fcport->ha, |
| 667 | "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n", |
| 668 | fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun, |
| 669 | sdev->queue_depth)); |
| 670 | } |
| 671 | |
| 672 | static void |
| 673 | qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data) |
| 674 | { |
| 675 | fc_port_t *fcport = data; |
| 676 | |
| 677 | if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1)) |
| 678 | return; |
| 679 | |
| 680 | DEBUG2(qla_printk(KERN_INFO, fcport->ha, |
| 681 | "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n", |
| 682 | fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun, |
| 683 | sdev->queue_depth)); |
| 684 | } |
| 685 | |
| 686 | static inline void |
| 687 | qla2x00_ramp_up_queue_depth(scsi_qla_host_t *ha, srb_t *sp) |
| 688 | { |
| 689 | fc_port_t *fcport; |
| 690 | struct scsi_device *sdev; |
| 691 | |
| 692 | sdev = sp->cmd->device; |
| 693 | if (sdev->queue_depth >= ha->max_q_depth) |
| 694 | return; |
| 695 | |
| 696 | fcport = sp->fcport; |
| 697 | if (time_before(jiffies, |
| 698 | fcport->last_ramp_up + ql2xqfullrampup * HZ)) |
| 699 | return; |
| 700 | if (time_before(jiffies, |
| 701 | fcport->last_queue_full + ql2xqfullrampup * HZ)) |
| 702 | return; |
| 703 | |
Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 704 | starget_for_each_device(sdev->sdev_target, fcport, |
| 705 | qla2x00_adjust_sdev_qdepth_up); |
Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | /** |
| 709 | * qla2x00_process_completed_request() - Process a Fast Post response. |
| 710 | * @ha: SCSI driver HA context |
| 711 | * @index: SRB index |
| 712 | */ |
| 713 | static void |
| 714 | qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index) |
| 715 | { |
| 716 | srb_t *sp; |
| 717 | |
| 718 | /* Validate handle. */ |
| 719 | if (index >= MAX_OUTSTANDING_COMMANDS) { |
| 720 | DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n", |
| 721 | ha->host_no, index)); |
| 722 | qla_printk(KERN_WARNING, ha, |
| 723 | "Invalid SCSI completion handle %d.\n", index); |
| 724 | |
| 725 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 726 | return; |
| 727 | } |
| 728 | |
| 729 | sp = ha->outstanding_cmds[index]; |
| 730 | if (sp) { |
| 731 | /* Free outstanding command slot. */ |
| 732 | ha->outstanding_cmds[index] = NULL; |
| 733 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | CMD_COMPL_STATUS(sp->cmd) = 0L; |
| 735 | CMD_SCSI_STATUS(sp->cmd) = 0L; |
| 736 | |
| 737 | /* Save ISP completion status */ |
| 738 | sp->cmd->result = DID_OK << 16; |
Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 739 | |
| 740 | qla2x00_ramp_up_queue_depth(ha, sp); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 741 | qla2x00_sp_compl(ha, sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | } else { |
| 743 | DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n", |
| 744 | ha->host_no)); |
| 745 | qla_printk(KERN_WARNING, ha, |
| 746 | "Invalid ISP SCSI completion handle\n"); |
| 747 | |
| 748 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | /** |
| 753 | * qla2x00_process_response_queue() - Process response queue entries. |
| 754 | * @ha: SCSI driver HA context |
| 755 | */ |
| 756 | void |
| 757 | qla2x00_process_response_queue(struct scsi_qla_host *ha) |
| 758 | { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 759 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | sts_entry_t *pkt; |
| 761 | uint16_t handle_cnt; |
| 762 | uint16_t cnt; |
| 763 | |
| 764 | if (!ha->flags.online) |
| 765 | return; |
| 766 | |
| 767 | while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) { |
| 768 | pkt = (sts_entry_t *)ha->response_ring_ptr; |
| 769 | |
| 770 | ha->rsp_ring_index++; |
| 771 | if (ha->rsp_ring_index == ha->response_q_length) { |
| 772 | ha->rsp_ring_index = 0; |
| 773 | ha->response_ring_ptr = ha->response_ring; |
| 774 | } else { |
| 775 | ha->response_ring_ptr++; |
| 776 | } |
| 777 | |
| 778 | if (pkt->entry_status != 0) { |
| 779 | DEBUG3(printk(KERN_INFO |
| 780 | "scsi(%ld): Process error entry.\n", ha->host_no)); |
| 781 | |
| 782 | qla2x00_error_entry(ha, pkt); |
| 783 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; |
| 784 | wmb(); |
| 785 | continue; |
| 786 | } |
| 787 | |
| 788 | switch (pkt->entry_type) { |
| 789 | case STATUS_TYPE: |
| 790 | qla2x00_status_entry(ha, pkt); |
| 791 | break; |
| 792 | case STATUS_TYPE_21: |
| 793 | handle_cnt = ((sts21_entry_t *)pkt)->handle_count; |
| 794 | for (cnt = 0; cnt < handle_cnt; cnt++) { |
| 795 | qla2x00_process_completed_request(ha, |
| 796 | ((sts21_entry_t *)pkt)->handle[cnt]); |
| 797 | } |
| 798 | break; |
| 799 | case STATUS_TYPE_22: |
| 800 | handle_cnt = ((sts22_entry_t *)pkt)->handle_count; |
| 801 | for (cnt = 0; cnt < handle_cnt; cnt++) { |
| 802 | qla2x00_process_completed_request(ha, |
| 803 | ((sts22_entry_t *)pkt)->handle[cnt]); |
| 804 | } |
| 805 | break; |
| 806 | case STATUS_CONT_TYPE: |
| 807 | qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt); |
| 808 | break; |
| 809 | case MS_IOCB_TYPE: |
| 810 | qla2x00_ms_entry(ha, (ms_iocb_entry_t *)pkt); |
| 811 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | default: |
| 813 | /* Type Not Supported. */ |
| 814 | DEBUG4(printk(KERN_WARNING |
| 815 | "scsi(%ld): Received unknown response pkt type %x " |
| 816 | "entry status=%x.\n", |
| 817 | ha->host_no, pkt->entry_type, pkt->entry_status)); |
| 818 | break; |
| 819 | } |
| 820 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; |
| 821 | wmb(); |
| 822 | } |
| 823 | |
| 824 | /* Adjust ring index */ |
| 825 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index); |
| 826 | } |
| 827 | |
Andrew Vasquez | 4733fcb | 2008-01-17 09:02:07 -0800 | [diff] [blame] | 828 | static inline void |
| 829 | qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len) |
| 830 | { |
| 831 | struct scsi_cmnd *cp = sp->cmd; |
| 832 | |
| 833 | if (sense_len >= SCSI_SENSE_BUFFERSIZE) |
| 834 | sense_len = SCSI_SENSE_BUFFERSIZE; |
| 835 | |
| 836 | CMD_ACTUAL_SNSLEN(cp) = sense_len; |
| 837 | sp->request_sense_length = sense_len; |
| 838 | sp->request_sense_ptr = cp->sense_buffer; |
| 839 | if (sp->request_sense_length > 32) |
| 840 | sense_len = 32; |
| 841 | |
| 842 | memcpy(cp->sense_buffer, sense_data, sense_len); |
| 843 | |
| 844 | sp->request_sense_ptr += sense_len; |
| 845 | sp->request_sense_length -= sense_len; |
| 846 | if (sp->request_sense_length != 0) |
| 847 | sp->ha->status_srb = sp; |
| 848 | |
| 849 | DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) " |
| 850 | "cmd=%p pid=%ld\n", __func__, sp->ha->host_no, cp->device->channel, |
| 851 | cp->device->id, cp->device->lun, cp, cp->serial_number)); |
| 852 | if (sense_len) |
| 853 | DEBUG5(qla2x00_dump_buffer(cp->sense_buffer, |
| 854 | CMD_ACTUAL_SNSLEN(cp))); |
| 855 | } |
| 856 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | /** |
| 858 | * qla2x00_status_entry() - Process a Status IOCB entry. |
| 859 | * @ha: SCSI driver HA context |
| 860 | * @pkt: Entry pointer |
| 861 | */ |
| 862 | static void |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 863 | qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | srb_t *sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | fc_port_t *fcport; |
| 867 | struct scsi_cmnd *cp; |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 868 | sts_entry_t *sts; |
| 869 | struct sts_entry_24xx *sts24; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | uint16_t comp_status; |
| 871 | uint16_t scsi_status; |
| 872 | uint8_t lscsi_status; |
| 873 | int32_t resid; |
Ravi Anand | ed17c71b5 | 2006-05-17 15:08:55 -0700 | [diff] [blame] | 874 | uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len; |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 875 | uint8_t *rsp_info, *sense_data; |
| 876 | |
| 877 | sts = (sts_entry_t *) pkt; |
| 878 | sts24 = (struct sts_entry_24xx *) pkt; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 879 | if (IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 880 | comp_status = le16_to_cpu(sts24->comp_status); |
| 881 | scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK; |
| 882 | } else { |
| 883 | comp_status = le16_to_cpu(sts->comp_status); |
| 884 | scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK; |
| 885 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | |
| 887 | /* Fast path completion. */ |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 888 | if (comp_status == CS_COMPLETE && scsi_status == 0) { |
| 889 | qla2x00_process_completed_request(ha, sts->handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | |
| 891 | return; |
| 892 | } |
| 893 | |
| 894 | /* Validate handle. */ |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 895 | if (sts->handle < MAX_OUTSTANDING_COMMANDS) { |
| 896 | sp = ha->outstanding_cmds[sts->handle]; |
| 897 | ha->outstanding_cmds[sts->handle] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | } else |
| 899 | sp = NULL; |
| 900 | |
| 901 | if (sp == NULL) { |
| 902 | DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n", |
| 903 | ha->host_no)); |
| 904 | qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n"); |
| 905 | |
| 906 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 907 | qla2xxx_wake_dpc(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | return; |
| 909 | } |
| 910 | cp = sp->cmd; |
| 911 | if (cp == NULL) { |
| 912 | DEBUG2(printk("scsi(%ld): Command already returned back to OS " |
Andrew Vasquez | 75bc419 | 2006-05-17 15:09:22 -0700 | [diff] [blame] | 913 | "pkt->handle=%d sp=%p.\n", ha->host_no, sts->handle, sp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | qla_printk(KERN_WARNING, ha, |
| 915 | "Command is NULL: already returned to OS (sp=%p)\n", sp); |
| 916 | |
| 917 | return; |
| 918 | } |
| 919 | |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 920 | lscsi_status = scsi_status & STATUS_MASK; |
| 921 | CMD_ENTRY_STATUS(cp) = sts->entry_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | CMD_COMPL_STATUS(cp) = comp_status; |
| 923 | CMD_SCSI_STATUS(cp) = scsi_status; |
| 924 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 925 | fcport = sp->fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | |
Ravi Anand | ed17c71b5 | 2006-05-17 15:08:55 -0700 | [diff] [blame] | 927 | sense_len = rsp_info_len = resid_len = fw_resid_len = 0; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 928 | if (IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 929 | sense_len = le32_to_cpu(sts24->sense_len); |
| 930 | rsp_info_len = le32_to_cpu(sts24->rsp_data_len); |
| 931 | resid_len = le32_to_cpu(sts24->rsp_residual_count); |
Ravi Anand | ed17c71b5 | 2006-05-17 15:08:55 -0700 | [diff] [blame] | 932 | fw_resid_len = le32_to_cpu(sts24->residual_len); |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 933 | rsp_info = sts24->data; |
| 934 | sense_data = sts24->data; |
| 935 | host_to_fcp_swap(sts24->data, sizeof(sts24->data)); |
| 936 | } else { |
| 937 | sense_len = le16_to_cpu(sts->req_sense_length); |
| 938 | rsp_info_len = le16_to_cpu(sts->rsp_info_len); |
| 939 | resid_len = le32_to_cpu(sts->residual_length); |
| 940 | rsp_info = sts->rsp_info; |
| 941 | sense_data = sts->req_sense_data; |
| 942 | } |
| 943 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | /* Check for any FCP transport errors. */ |
| 945 | if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) { |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 946 | /* Sense data lies beyond any FCP RESPONSE data. */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 947 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 948 | sense_data += rsp_info_len; |
| 949 | if (rsp_info_len > 3 && rsp_info[3]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol " |
| 951 | "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..." |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 952 | "retrying command\n", ha->host_no, |
| 953 | cp->device->channel, cp->device->id, |
| 954 | cp->device->lun, rsp_info_len, rsp_info[0], |
| 955 | rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4], |
| 956 | rsp_info[5], rsp_info[6], rsp_info[7])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | |
| 958 | cp->result = DID_BUS_BUSY << 16; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 959 | qla2x00_sp_compl(ha, sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | return; |
| 961 | } |
| 962 | } |
| 963 | |
Andrew Vasquez | 3e8ce32 | 2008-02-28 14:06:10 -0800 | [diff] [blame] | 964 | /* Check for overrun. */ |
| 965 | if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE && |
| 966 | scsi_status & SS_RESIDUAL_OVER) |
| 967 | comp_status = CS_DATA_OVERRUN; |
| 968 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | /* |
| 970 | * Based on Host and scsi status generate status code for Linux |
| 971 | */ |
| 972 | switch (comp_status) { |
| 973 | case CS_COMPLETE: |
Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 974 | case CS_QUEUE_FULL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | if (scsi_status == 0) { |
| 976 | cp->result = DID_OK << 16; |
| 977 | break; |
| 978 | } |
| 979 | if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) { |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 980 | resid = resid_len; |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 981 | scsi_set_resid(cp, resid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | CMD_RESID_LEN(cp) = resid; |
Andrew Vasquez | 0da69df | 2005-12-06 10:58:06 -0800 | [diff] [blame] | 983 | |
| 984 | if (!lscsi_status && |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 985 | ((unsigned)(scsi_bufflen(cp) - resid) < |
Andrew Vasquez | 0da69df | 2005-12-06 10:58:06 -0800 | [diff] [blame] | 986 | cp->underflow)) { |
| 987 | qla_printk(KERN_INFO, ha, |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 988 | "scsi(%ld:%d:%d:%d): Mid-layer underflow " |
| 989 | "detected (%x of %x bytes)...returning " |
| 990 | "error status.\n", ha->host_no, |
| 991 | cp->device->channel, cp->device->id, |
| 992 | cp->device->lun, resid, |
| 993 | scsi_bufflen(cp)); |
Andrew Vasquez | 0da69df | 2005-12-06 10:58:06 -0800 | [diff] [blame] | 994 | |
| 995 | cp->result = DID_ERROR << 16; |
| 996 | break; |
| 997 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | cp->result = DID_OK << 16 | lscsi_status; |
| 1000 | |
Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 1001 | if (lscsi_status == SAM_STAT_TASK_SET_FULL) { |
| 1002 | DEBUG2(printk(KERN_INFO |
| 1003 | "scsi(%ld): QUEUE FULL status detected " |
| 1004 | "0x%x-0x%x.\n", ha->host_no, comp_status, |
| 1005 | scsi_status)); |
| 1006 | |
| 1007 | /* Adjust queue depth for all luns on the port. */ |
| 1008 | fcport->last_queue_full = jiffies; |
Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 1009 | starget_for_each_device(cp->device->sdev_target, |
| 1010 | fcport, qla2x00_adjust_sdev_qdepth_down); |
Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 1011 | break; |
| 1012 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | if (lscsi_status != SS_CHECK_CONDITION) |
| 1014 | break; |
| 1015 | |
FUJITA Tomonori | b80ca4f | 2008-01-13 15:46:13 +0900 | [diff] [blame] | 1016 | memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | if (!(scsi_status & SS_SENSE_LEN_VALID)) |
| 1018 | break; |
| 1019 | |
Andrew Vasquez | 4733fcb | 2008-01-17 09:02:07 -0800 | [diff] [blame] | 1020 | qla2x00_handle_sense(sp, sense_data, sense_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | break; |
| 1022 | |
| 1023 | case CS_DATA_UNDERRUN: |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1024 | resid = resid_len; |
Ravi Anand | ed17c71b5 | 2006-05-17 15:08:55 -0700 | [diff] [blame] | 1025 | /* Use F/W calculated residual length. */ |
Andrew Vasquez | 6acf819 | 2007-10-19 15:59:18 -0700 | [diff] [blame] | 1026 | if (IS_FWI2_CAPABLE(ha)) { |
| 1027 | if (scsi_status & SS_RESIDUAL_UNDER && |
| 1028 | resid != fw_resid_len) { |
| 1029 | scsi_status &= ~SS_RESIDUAL_UNDER; |
| 1030 | lscsi_status = 0; |
| 1031 | } |
Ravi Anand | ed17c71b5 | 2006-05-17 15:08:55 -0700 | [diff] [blame] | 1032 | resid = fw_resid_len; |
Andrew Vasquez | 6acf819 | 2007-10-19 15:59:18 -0700 | [diff] [blame] | 1033 | } |
Ravi Anand | ed17c71b5 | 2006-05-17 15:08:55 -0700 | [diff] [blame] | 1034 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | if (scsi_status & SS_RESIDUAL_UNDER) { |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 1036 | scsi_set_resid(cp, resid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | CMD_RESID_LEN(cp) = resid; |
andrew.vasquez@qlogic.com | e038a1be | 2006-01-13 17:04:59 -0800 | [diff] [blame] | 1038 | } else { |
| 1039 | DEBUG2(printk(KERN_INFO |
| 1040 | "scsi(%ld:%d:%d) UNDERRUN status detected " |
Ravi Anand | ed17c71b5 | 2006-05-17 15:08:55 -0700 | [diff] [blame] | 1041 | "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x " |
| 1042 | "os_underflow=0x%x\n", ha->host_no, |
| 1043 | cp->device->id, cp->device->lun, comp_status, |
| 1044 | scsi_status, resid_len, resid, cp->cmnd[0], |
| 1045 | cp->underflow)); |
andrew.vasquez@qlogic.com | e038a1be | 2006-01-13 17:04:59 -0800 | [diff] [blame] | 1046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | /* |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1050 | * Check to see if SCSI Status is non zero. If so report SCSI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | * Status. |
| 1052 | */ |
| 1053 | if (lscsi_status != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | cp->result = DID_OK << 16 | lscsi_status; |
| 1055 | |
Andrew Vasquez | ffec28a | 2007-01-29 10:22:27 -0800 | [diff] [blame] | 1056 | if (lscsi_status == SAM_STAT_TASK_SET_FULL) { |
| 1057 | DEBUG2(printk(KERN_INFO |
| 1058 | "scsi(%ld): QUEUE FULL status detected " |
| 1059 | "0x%x-0x%x.\n", ha->host_no, comp_status, |
| 1060 | scsi_status)); |
| 1061 | |
| 1062 | /* |
| 1063 | * Adjust queue depth for all luns on the |
| 1064 | * port. |
| 1065 | */ |
| 1066 | fcport->last_queue_full = jiffies; |
| 1067 | starget_for_each_device( |
| 1068 | cp->device->sdev_target, fcport, |
| 1069 | qla2x00_adjust_sdev_qdepth_down); |
| 1070 | break; |
| 1071 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | if (lscsi_status != SS_CHECK_CONDITION) |
| 1073 | break; |
| 1074 | |
FUJITA Tomonori | b80ca4f | 2008-01-13 15:46:13 +0900 | [diff] [blame] | 1075 | memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | if (!(scsi_status & SS_SENSE_LEN_VALID)) |
| 1077 | break; |
| 1078 | |
Andrew Vasquez | 4733fcb | 2008-01-17 09:02:07 -0800 | [diff] [blame] | 1079 | qla2x00_handle_sense(sp, sense_data, sense_len); |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1080 | |
Shyam Sundar | 8084fe1 | 2007-07-19 15:05:59 -0700 | [diff] [blame] | 1081 | /* |
| 1082 | * In case of a Underrun condition, set both the lscsi |
| 1083 | * status and the completion status to appropriate |
| 1084 | * values. |
| 1085 | */ |
| 1086 | if (resid && |
Boaz Harrosh | 4b39c1d | 2007-07-22 17:28:55 +0300 | [diff] [blame] | 1087 | ((unsigned)(scsi_bufflen(cp) - resid) < |
Shyam Sundar | 8084fe1 | 2007-07-19 15:05:59 -0700 | [diff] [blame] | 1088 | cp->underflow)) { |
| 1089 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 1090 | "scsi(%ld:%d:%d:%d): Mid-layer underflow " |
| 1091 | "detected (%x of %x bytes)...returning " |
| 1092 | "error status.\n", ha->host_no, |
| 1093 | cp->device->channel, cp->device->id, |
| 1094 | cp->device->lun, resid, |
Boaz Harrosh | 4b39c1d | 2007-07-22 17:28:55 +0300 | [diff] [blame] | 1095 | scsi_bufflen(cp))); |
Shyam Sundar | 8084fe1 | 2007-07-19 15:05:59 -0700 | [diff] [blame] | 1096 | |
| 1097 | cp->result = DID_ERROR << 16 | lscsi_status; |
| 1098 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | } else { |
| 1100 | /* |
| 1101 | * If RISC reports underrun and target does not report |
| 1102 | * it then we must have a lost frame, so tell upper |
| 1103 | * layer to retry it by reporting a bus busy. |
| 1104 | */ |
| 1105 | if (!(scsi_status & SS_RESIDUAL_UNDER)) { |
| 1106 | DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped " |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 1107 | "frame(s) detected (%x of %x bytes)..." |
| 1108 | "retrying command.\n", ha->host_no, |
| 1109 | cp->device->channel, cp->device->id, |
| 1110 | cp->device->lun, resid, |
| 1111 | scsi_bufflen(cp))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | |
| 1113 | cp->result = DID_BUS_BUSY << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | break; |
| 1115 | } |
| 1116 | |
| 1117 | /* Handle mid-layer underflow */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 1118 | if ((unsigned)(scsi_bufflen(cp) - resid) < |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | cp->underflow) { |
| 1120 | qla_printk(KERN_INFO, ha, |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 1121 | "scsi(%ld:%d:%d:%d): Mid-layer underflow " |
| 1122 | "detected (%x of %x bytes)...returning " |
| 1123 | "error status.\n", ha->host_no, |
| 1124 | cp->device->channel, cp->device->id, |
| 1125 | cp->device->lun, resid, |
| 1126 | scsi_bufflen(cp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | |
| 1128 | cp->result = DID_ERROR << 16; |
| 1129 | break; |
| 1130 | } |
| 1131 | |
| 1132 | /* Everybody online, looking good... */ |
| 1133 | cp->result = DID_OK << 16; |
| 1134 | } |
| 1135 | break; |
| 1136 | |
| 1137 | case CS_DATA_OVERRUN: |
| 1138 | DEBUG2(printk(KERN_INFO |
| 1139 | "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n", |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1140 | ha->host_no, cp->device->id, cp->device->lun, comp_status, |
| 1141 | scsi_status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | DEBUG2(printk(KERN_INFO |
| 1143 | "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", |
| 1144 | cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3], |
| 1145 | cp->cmnd[4], cp->cmnd[5])); |
| 1146 | DEBUG2(printk(KERN_INFO |
| 1147 | "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR " |
| 1148 | "status!\n", |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 1149 | cp->serial_number, scsi_bufflen(cp), resid_len)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | |
| 1151 | cp->result = DID_ERROR << 16; |
| 1152 | break; |
| 1153 | |
| 1154 | case CS_PORT_LOGGED_OUT: |
| 1155 | case CS_PORT_CONFIG_CHG: |
| 1156 | case CS_PORT_BUSY: |
| 1157 | case CS_INCOMPLETE: |
| 1158 | case CS_PORT_UNAVAILABLE: |
| 1159 | /* |
| 1160 | * If the port is in Target Down state, return all IOs for this |
| 1161 | * Target with DID_NO_CONNECT ELSE Queue the IOs in the |
| 1162 | * retry_queue. |
| 1163 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down " |
| 1165 | "pid=%ld, compl status=0x%x, port state=0x%x\n", |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1166 | ha->host_no, cp->device->id, cp->device->lun, |
| 1167 | cp->serial_number, comp_status, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | atomic_read(&fcport->state))); |
| 1169 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1170 | cp->result = DID_BUS_BUSY << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | if (atomic_read(&fcport->state) == FCS_ONLINE) { |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 1172 | qla2x00_mark_device_lost(ha, fcport, 1, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | break; |
| 1175 | |
| 1176 | case CS_RESET: |
| 1177 | DEBUG2(printk(KERN_INFO |
| 1178 | "scsi(%ld): RESET status detected 0x%x-0x%x.\n", |
| 1179 | ha->host_no, comp_status, scsi_status)); |
| 1180 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1181 | cp->result = DID_RESET << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | break; |
| 1183 | |
| 1184 | case CS_ABORTED: |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1185 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | * hv2.19.12 - DID_ABORT does not retry the request if we |
| 1187 | * aborted this request then abort otherwise it must be a |
| 1188 | * reset. |
| 1189 | */ |
| 1190 | DEBUG2(printk(KERN_INFO |
| 1191 | "scsi(%ld): ABORT status detected 0x%x-0x%x.\n", |
| 1192 | ha->host_no, comp_status, scsi_status)); |
| 1193 | |
| 1194 | cp->result = DID_RESET << 16; |
| 1195 | break; |
| 1196 | |
| 1197 | case CS_TIMEOUT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | cp->result = DID_BUS_BUSY << 16; |
| 1199 | |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1200 | if (IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1201 | DEBUG2(printk(KERN_INFO |
| 1202 | "scsi(%ld:%d:%d:%d): TIMEOUT status detected " |
| 1203 | "0x%x-0x%x\n", ha->host_no, cp->device->channel, |
| 1204 | cp->device->id, cp->device->lun, comp_status, |
| 1205 | scsi_status)); |
| 1206 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | } |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1208 | DEBUG2(printk(KERN_INFO |
| 1209 | "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x " |
| 1210 | "sflags=%x.\n", ha->host_no, cp->device->channel, |
| 1211 | cp->device->id, cp->device->lun, comp_status, scsi_status, |
| 1212 | le16_to_cpu(sts->status_flags))); |
| 1213 | |
| 1214 | /* Check to see if logout occurred. */ |
| 1215 | if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT)) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 1216 | qla2x00_mark_device_lost(ha, fcport, 1, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | break; |
| 1218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | default: |
| 1220 | DEBUG3(printk("scsi(%ld): Error detected (unknown status) " |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1221 | "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | qla_printk(KERN_INFO, ha, |
| 1223 | "Unknown status detected 0x%x-0x%x.\n", |
| 1224 | comp_status, scsi_status); |
| 1225 | |
| 1226 | cp->result = DID_ERROR << 16; |
| 1227 | break; |
| 1228 | } |
| 1229 | |
| 1230 | /* Place command on done queue. */ |
| 1231 | if (ha->status_srb == NULL) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1232 | qla2x00_sp_compl(ha, sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | /** |
| 1236 | * qla2x00_status_cont_entry() - Process a Status Continuations entry. |
| 1237 | * @ha: SCSI driver HA context |
| 1238 | * @pkt: Entry pointer |
| 1239 | * |
| 1240 | * Extended sense data. |
| 1241 | */ |
| 1242 | static void |
| 1243 | qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt) |
| 1244 | { |
| 1245 | uint8_t sense_sz = 0; |
| 1246 | srb_t *sp = ha->status_srb; |
| 1247 | struct scsi_cmnd *cp; |
| 1248 | |
| 1249 | if (sp != NULL && sp->request_sense_length != 0) { |
| 1250 | cp = sp->cmd; |
| 1251 | if (cp == NULL) { |
| 1252 | DEBUG2(printk("%s(): Cmd already returned back to OS " |
Andrew Vasquez | 75bc419 | 2006-05-17 15:09:22 -0700 | [diff] [blame] | 1253 | "sp=%p.\n", __func__, sp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | qla_printk(KERN_INFO, ha, |
| 1255 | "cmd is NULL: already returned to OS (sp=%p)\n", |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1256 | sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | |
| 1258 | ha->status_srb = NULL; |
| 1259 | return; |
| 1260 | } |
| 1261 | |
| 1262 | if (sp->request_sense_length > sizeof(pkt->data)) { |
| 1263 | sense_sz = sizeof(pkt->data); |
| 1264 | } else { |
| 1265 | sense_sz = sp->request_sense_length; |
| 1266 | } |
| 1267 | |
| 1268 | /* Move sense data. */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1269 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1270 | host_to_fcp_swap(pkt->data, sizeof(pkt->data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | memcpy(sp->request_sense_ptr, pkt->data, sense_sz); |
| 1272 | DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz)); |
| 1273 | |
| 1274 | sp->request_sense_ptr += sense_sz; |
| 1275 | sp->request_sense_length -= sense_sz; |
| 1276 | |
| 1277 | /* Place command on done queue. */ |
| 1278 | if (sp->request_sense_length == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | ha->status_srb = NULL; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1280 | qla2x00_sp_compl(ha, sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | /** |
| 1286 | * qla2x00_error_entry() - Process an error entry. |
| 1287 | * @ha: SCSI driver HA context |
| 1288 | * @pkt: Entry pointer |
| 1289 | */ |
| 1290 | static void |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1291 | qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | { |
| 1293 | srb_t *sp; |
| 1294 | |
| 1295 | #if defined(QL_DEBUG_LEVEL_2) |
| 1296 | if (pkt->entry_status & RF_INV_E_ORDER) |
| 1297 | qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__); |
| 1298 | else if (pkt->entry_status & RF_INV_E_COUNT) |
| 1299 | qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__); |
| 1300 | else if (pkt->entry_status & RF_INV_E_PARAM) |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1301 | qla_printk(KERN_ERR, ha, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | "%s: Invalid Entry Parameter\n", __func__); |
| 1303 | else if (pkt->entry_status & RF_INV_E_TYPE) |
| 1304 | qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__); |
| 1305 | else if (pkt->entry_status & RF_BUSY) |
| 1306 | qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__); |
| 1307 | else |
| 1308 | qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__); |
| 1309 | #endif |
| 1310 | |
| 1311 | /* Validate handle. */ |
| 1312 | if (pkt->handle < MAX_OUTSTANDING_COMMANDS) |
| 1313 | sp = ha->outstanding_cmds[pkt->handle]; |
| 1314 | else |
| 1315 | sp = NULL; |
| 1316 | |
| 1317 | if (sp) { |
| 1318 | /* Free outstanding command slot. */ |
| 1319 | ha->outstanding_cmds[pkt->handle] = NULL; |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 1320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | /* Bad payload or header */ |
| 1322 | if (pkt->entry_status & |
| 1323 | (RF_INV_E_ORDER | RF_INV_E_COUNT | |
| 1324 | RF_INV_E_PARAM | RF_INV_E_TYPE)) { |
| 1325 | sp->cmd->result = DID_ERROR << 16; |
| 1326 | } else if (pkt->entry_status & RF_BUSY) { |
| 1327 | sp->cmd->result = DID_BUS_BUSY << 16; |
| 1328 | } else { |
| 1329 | sp->cmd->result = DID_ERROR << 16; |
| 1330 | } |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1331 | qla2x00_sp_compl(ha, sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1333 | } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type == |
| 1334 | COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n", |
| 1336 | ha->host_no)); |
| 1337 | qla_printk(KERN_WARNING, ha, |
| 1338 | "Error entry - invalid handle\n"); |
| 1339 | |
| 1340 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 1341 | qla2xxx_wake_dpc(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | /** |
| 1346 | * qla2x00_ms_entry() - Process a Management Server entry. |
| 1347 | * @ha: SCSI driver HA context |
| 1348 | * @index: Response queue out pointer |
| 1349 | */ |
| 1350 | static void |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1351 | qla2x00_ms_entry(scsi_qla_host_t *ha, ms_iocb_entry_t *pkt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | { |
| 1353 | srb_t *sp; |
| 1354 | |
| 1355 | DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n", |
| 1356 | __func__, ha->host_no, pkt, pkt->handle1)); |
| 1357 | |
| 1358 | /* Validate handle. */ |
| 1359 | if (pkt->handle1 < MAX_OUTSTANDING_COMMANDS) |
| 1360 | sp = ha->outstanding_cmds[pkt->handle1]; |
| 1361 | else |
| 1362 | sp = NULL; |
| 1363 | |
| 1364 | if (sp == NULL) { |
| 1365 | DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n", |
| 1366 | ha->host_no)); |
| 1367 | qla_printk(KERN_WARNING, ha, "MS entry - invalid handle\n"); |
| 1368 | |
| 1369 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 1370 | return; |
| 1371 | } |
| 1372 | |
| 1373 | CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->status); |
| 1374 | CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status; |
| 1375 | |
| 1376 | /* Free outstanding command slot. */ |
| 1377 | ha->outstanding_cmds[pkt->handle1] = NULL; |
| 1378 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1379 | qla2x00_sp_compl(ha, sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | } |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1381 | |
| 1382 | |
| 1383 | /** |
| 1384 | * qla24xx_mbx_completion() - Process mailbox command completions. |
| 1385 | * @ha: SCSI driver HA context |
| 1386 | * @mb0: Mailbox0 register |
| 1387 | */ |
| 1388 | static void |
| 1389 | qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0) |
| 1390 | { |
| 1391 | uint16_t cnt; |
| 1392 | uint16_t __iomem *wptr; |
| 1393 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1394 | |
| 1395 | /* Load return mailbox registers. */ |
| 1396 | ha->flags.mbox_int = 1; |
| 1397 | ha->mailbox_out[0] = mb0; |
| 1398 | wptr = (uint16_t __iomem *)®->mailbox1; |
| 1399 | |
| 1400 | for (cnt = 1; cnt < ha->mbx_count; cnt++) { |
| 1401 | ha->mailbox_out[cnt] = RD_REG_WORD(wptr); |
| 1402 | wptr++; |
| 1403 | } |
| 1404 | |
| 1405 | if (ha->mcp) { |
| 1406 | DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n", |
| 1407 | __func__, ha->host_no, ha->mcp->mb[0])); |
| 1408 | } else { |
| 1409 | DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n", |
| 1410 | __func__, ha->host_no)); |
| 1411 | } |
| 1412 | } |
| 1413 | |
| 1414 | /** |
| 1415 | * qla24xx_process_response_queue() - Process response queue entries. |
| 1416 | * @ha: SCSI driver HA context |
| 1417 | */ |
| 1418 | void |
| 1419 | qla24xx_process_response_queue(struct scsi_qla_host *ha) |
| 1420 | { |
| 1421 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1422 | struct sts_entry_24xx *pkt; |
| 1423 | |
| 1424 | if (!ha->flags.online) |
| 1425 | return; |
| 1426 | |
| 1427 | while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) { |
| 1428 | pkt = (struct sts_entry_24xx *)ha->response_ring_ptr; |
| 1429 | |
| 1430 | ha->rsp_ring_index++; |
| 1431 | if (ha->rsp_ring_index == ha->response_q_length) { |
| 1432 | ha->rsp_ring_index = 0; |
| 1433 | ha->response_ring_ptr = ha->response_ring; |
| 1434 | } else { |
| 1435 | ha->response_ring_ptr++; |
| 1436 | } |
| 1437 | |
| 1438 | if (pkt->entry_status != 0) { |
| 1439 | DEBUG3(printk(KERN_INFO |
| 1440 | "scsi(%ld): Process error entry.\n", ha->host_no)); |
| 1441 | |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1442 | qla2x00_error_entry(ha, (sts_entry_t *) pkt); |
| 1443 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; |
| 1444 | wmb(); |
| 1445 | continue; |
| 1446 | } |
| 1447 | |
| 1448 | switch (pkt->entry_type) { |
| 1449 | case STATUS_TYPE: |
| 1450 | qla2x00_status_entry(ha, pkt); |
| 1451 | break; |
| 1452 | case STATUS_CONT_TYPE: |
| 1453 | qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt); |
| 1454 | break; |
| 1455 | case MS_IOCB_TYPE: |
| 1456 | qla24xx_ms_entry(ha, (struct ct_entry_24xx *)pkt); |
| 1457 | break; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1458 | case VP_RPT_ID_IOCB_TYPE: |
| 1459 | qla24xx_report_id_acquisition(ha, |
| 1460 | (struct vp_rpt_id_entry_24xx *)pkt); |
| 1461 | break; |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1462 | default: |
| 1463 | /* Type Not Supported. */ |
| 1464 | DEBUG4(printk(KERN_WARNING |
| 1465 | "scsi(%ld): Received unknown response pkt type %x " |
| 1466 | "entry status=%x.\n", |
| 1467 | ha->host_no, pkt->entry_type, pkt->entry_status)); |
| 1468 | break; |
| 1469 | } |
| 1470 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; |
| 1471 | wmb(); |
| 1472 | } |
| 1473 | |
| 1474 | /* Adjust ring index */ |
| 1475 | WRT_REG_DWORD(®->rsp_q_out, ha->rsp_ring_index); |
| 1476 | } |
| 1477 | |
Andrew Vasquez | 05236a0 | 2007-09-20 14:07:37 -0700 | [diff] [blame] | 1478 | static void |
| 1479 | qla2xxx_check_risc_status(scsi_qla_host_t *ha) |
| 1480 | { |
| 1481 | int rval; |
| 1482 | uint32_t cnt; |
| 1483 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1484 | |
| 1485 | if (!IS_QLA25XX(ha)) |
| 1486 | return; |
| 1487 | |
| 1488 | rval = QLA_SUCCESS; |
| 1489 | WRT_REG_DWORD(®->iobase_addr, 0x7C00); |
| 1490 | RD_REG_DWORD(®->iobase_addr); |
| 1491 | WRT_REG_DWORD(®->iobase_window, 0x0001); |
| 1492 | for (cnt = 10000; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 && |
| 1493 | rval == QLA_SUCCESS; cnt--) { |
| 1494 | if (cnt) { |
| 1495 | WRT_REG_DWORD(®->iobase_window, 0x0001); |
| 1496 | udelay(10); |
| 1497 | } else |
| 1498 | rval = QLA_FUNCTION_TIMEOUT; |
| 1499 | } |
| 1500 | if (rval == QLA_SUCCESS) |
| 1501 | goto next_test; |
| 1502 | |
| 1503 | WRT_REG_DWORD(®->iobase_window, 0x0003); |
| 1504 | for (cnt = 100; (RD_REG_DWORD(®->iobase_window) & BIT_0) == 0 && |
| 1505 | rval == QLA_SUCCESS; cnt--) { |
| 1506 | if (cnt) { |
| 1507 | WRT_REG_DWORD(®->iobase_window, 0x0003); |
| 1508 | udelay(10); |
| 1509 | } else |
| 1510 | rval = QLA_FUNCTION_TIMEOUT; |
| 1511 | } |
| 1512 | if (rval != QLA_SUCCESS) |
| 1513 | goto done; |
| 1514 | |
| 1515 | next_test: |
| 1516 | if (RD_REG_DWORD(®->iobase_c8) & BIT_3) |
| 1517 | qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n"); |
| 1518 | |
| 1519 | done: |
| 1520 | WRT_REG_DWORD(®->iobase_window, 0x0000); |
| 1521 | RD_REG_DWORD(®->iobase_window); |
| 1522 | } |
| 1523 | |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1524 | /** |
| 1525 | * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx. |
| 1526 | * @irq: |
| 1527 | * @dev_id: SCSI driver HA context |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1528 | * |
| 1529 | * Called by system whenever the host adapter generates an interrupt. |
| 1530 | * |
| 1531 | * Returns handled flag. |
| 1532 | */ |
| 1533 | irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1534 | qla24xx_intr_handler(int irq, void *dev_id) |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1535 | { |
| 1536 | scsi_qla_host_t *ha; |
| 1537 | struct device_reg_24xx __iomem *reg; |
| 1538 | int status; |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1539 | unsigned long iter; |
| 1540 | uint32_t stat; |
| 1541 | uint32_t hccr; |
| 1542 | uint16_t mb[4]; |
| 1543 | |
| 1544 | ha = (scsi_qla_host_t *) dev_id; |
| 1545 | if (!ha) { |
| 1546 | printk(KERN_INFO |
| 1547 | "%s(): NULL host pointer\n", __func__); |
| 1548 | return IRQ_NONE; |
| 1549 | } |
| 1550 | |
| 1551 | reg = &ha->iobase->isp24; |
| 1552 | status = 0; |
| 1553 | |
Andrew Vasquez | c695248 | 2008-04-03 13:13:17 -0700 | [diff] [blame] | 1554 | spin_lock(&ha->hardware_lock); |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1555 | for (iter = 50; iter--; ) { |
| 1556 | stat = RD_REG_DWORD(®->host_status); |
| 1557 | if (stat & HSRX_RISC_PAUSED) { |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 1558 | if (pci_channel_offline(ha->pdev)) |
| 1559 | break; |
| 1560 | |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1561 | hccr = RD_REG_DWORD(®->hccr); |
| 1562 | |
| 1563 | qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, " |
| 1564 | "Dumping firmware!\n", hccr); |
Andrew Vasquez | 05236a0 | 2007-09-20 14:07:37 -0700 | [diff] [blame] | 1565 | |
| 1566 | qla2xxx_check_risc_status(ha); |
| 1567 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1568 | ha->isp_ops->fw_dump(ha, 1); |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1569 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 1570 | break; |
| 1571 | } else if ((stat & HSRX_RISC_INT) == 0) |
| 1572 | break; |
| 1573 | |
| 1574 | switch (stat & 0xff) { |
| 1575 | case 0x1: |
| 1576 | case 0x2: |
| 1577 | case 0x10: |
| 1578 | case 0x11: |
| 1579 | qla24xx_mbx_completion(ha, MSW(stat)); |
| 1580 | status |= MBX_INTERRUPT; |
| 1581 | |
| 1582 | break; |
| 1583 | case 0x12: |
| 1584 | mb[0] = MSW(stat); |
| 1585 | mb[1] = RD_REG_WORD(®->mailbox1); |
| 1586 | mb[2] = RD_REG_WORD(®->mailbox2); |
| 1587 | mb[3] = RD_REG_WORD(®->mailbox3); |
| 1588 | qla2x00_async_event(ha, mb); |
| 1589 | break; |
| 1590 | case 0x13: |
| 1591 | qla24xx_process_response_queue(ha); |
| 1592 | break; |
| 1593 | default: |
| 1594 | DEBUG2(printk("scsi(%ld): Unrecognized interrupt type " |
| 1595 | "(%d).\n", |
| 1596 | ha->host_no, stat & 0xff)); |
| 1597 | break; |
| 1598 | } |
| 1599 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT); |
| 1600 | RD_REG_DWORD_RELAXED(®->hccr); |
| 1601 | } |
Andrew Vasquez | c695248 | 2008-04-03 13:13:17 -0700 | [diff] [blame] | 1602 | spin_unlock(&ha->hardware_lock); |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1603 | |
| 1604 | if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) && |
| 1605 | (status & MBX_INTERRUPT) && ha->flags.mbox_int) { |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1606 | set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); |
Marcus Barrow | 0b05a1f | 2008-01-17 09:02:13 -0800 | [diff] [blame] | 1607 | complete(&ha->mbx_intr_comp); |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | return IRQ_HANDLED; |
| 1611 | } |
| 1612 | |
| 1613 | /** |
| 1614 | * qla24xx_ms_entry() - Process a Management Server entry. |
| 1615 | * @ha: SCSI driver HA context |
| 1616 | * @index: Response queue out pointer |
| 1617 | */ |
| 1618 | static void |
| 1619 | qla24xx_ms_entry(scsi_qla_host_t *ha, struct ct_entry_24xx *pkt) |
| 1620 | { |
| 1621 | srb_t *sp; |
| 1622 | |
| 1623 | DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n", |
| 1624 | __func__, ha->host_no, pkt, pkt->handle)); |
| 1625 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1626 | DEBUG9(printk("%s: ct pkt dump:\n", __func__)); |
| 1627 | DEBUG9(qla2x00_dump_buffer((void *)pkt, sizeof(struct ct_entry_24xx))); |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1628 | |
| 1629 | /* Validate handle. */ |
| 1630 | if (pkt->handle < MAX_OUTSTANDING_COMMANDS) |
| 1631 | sp = ha->outstanding_cmds[pkt->handle]; |
| 1632 | else |
| 1633 | sp = NULL; |
| 1634 | |
| 1635 | if (sp == NULL) { |
| 1636 | DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n", |
| 1637 | ha->host_no)); |
| 1638 | DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n", |
| 1639 | ha->host_no)); |
| 1640 | qla_printk(KERN_WARNING, ha, "MS entry - invalid handle %d\n", |
| 1641 | pkt->handle); |
| 1642 | |
| 1643 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 1644 | return; |
| 1645 | } |
| 1646 | |
| 1647 | CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->comp_status); |
| 1648 | CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status; |
| 1649 | |
| 1650 | /* Free outstanding command slot. */ |
| 1651 | ha->outstanding_cmds[pkt->handle] = NULL; |
| 1652 | |
| 1653 | qla2x00_sp_compl(ha, sp); |
| 1654 | } |
| 1655 | |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1656 | static irqreturn_t |
| 1657 | qla24xx_msix_rsp_q(int irq, void *dev_id) |
| 1658 | { |
| 1659 | scsi_qla_host_t *ha; |
| 1660 | struct device_reg_24xx __iomem *reg; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1661 | |
| 1662 | ha = dev_id; |
| 1663 | reg = &ha->iobase->isp24; |
| 1664 | |
Andrew Vasquez | c695248 | 2008-04-03 13:13:17 -0700 | [diff] [blame] | 1665 | spin_lock(&ha->hardware_lock); |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1666 | |
| 1667 | qla24xx_process_response_queue(ha); |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1668 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT); |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1669 | |
Andrew Vasquez | c695248 | 2008-04-03 13:13:17 -0700 | [diff] [blame] | 1670 | spin_unlock(&ha->hardware_lock); |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1671 | |
| 1672 | return IRQ_HANDLED; |
| 1673 | } |
| 1674 | |
| 1675 | static irqreturn_t |
| 1676 | qla24xx_msix_default(int irq, void *dev_id) |
| 1677 | { |
| 1678 | scsi_qla_host_t *ha; |
| 1679 | struct device_reg_24xx __iomem *reg; |
| 1680 | int status; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1681 | uint32_t stat; |
| 1682 | uint32_t hccr; |
| 1683 | uint16_t mb[4]; |
| 1684 | |
| 1685 | ha = dev_id; |
| 1686 | reg = &ha->iobase->isp24; |
| 1687 | status = 0; |
| 1688 | |
Andrew Vasquez | c695248 | 2008-04-03 13:13:17 -0700 | [diff] [blame] | 1689 | spin_lock(&ha->hardware_lock); |
Andrew Vasquez | 87f2701 | 2007-09-20 14:07:49 -0700 | [diff] [blame] | 1690 | do { |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1691 | stat = RD_REG_DWORD(®->host_status); |
| 1692 | if (stat & HSRX_RISC_PAUSED) { |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 1693 | if (pci_channel_offline(ha->pdev)) |
| 1694 | break; |
| 1695 | |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1696 | hccr = RD_REG_DWORD(®->hccr); |
| 1697 | |
| 1698 | qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, " |
| 1699 | "Dumping firmware!\n", hccr); |
Andrew Vasquez | 05236a0 | 2007-09-20 14:07:37 -0700 | [diff] [blame] | 1700 | |
| 1701 | qla2xxx_check_risc_status(ha); |
| 1702 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1703 | ha->isp_ops->fw_dump(ha, 1); |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1704 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 1705 | break; |
| 1706 | } else if ((stat & HSRX_RISC_INT) == 0) |
| 1707 | break; |
| 1708 | |
| 1709 | switch (stat & 0xff) { |
| 1710 | case 0x1: |
| 1711 | case 0x2: |
| 1712 | case 0x10: |
| 1713 | case 0x11: |
| 1714 | qla24xx_mbx_completion(ha, MSW(stat)); |
| 1715 | status |= MBX_INTERRUPT; |
| 1716 | |
| 1717 | break; |
| 1718 | case 0x12: |
| 1719 | mb[0] = MSW(stat); |
| 1720 | mb[1] = RD_REG_WORD(®->mailbox1); |
| 1721 | mb[2] = RD_REG_WORD(®->mailbox2); |
| 1722 | mb[3] = RD_REG_WORD(®->mailbox3); |
| 1723 | qla2x00_async_event(ha, mb); |
| 1724 | break; |
| 1725 | case 0x13: |
| 1726 | qla24xx_process_response_queue(ha); |
| 1727 | break; |
| 1728 | default: |
| 1729 | DEBUG2(printk("scsi(%ld): Unrecognized interrupt type " |
| 1730 | "(%d).\n", |
| 1731 | ha->host_no, stat & 0xff)); |
| 1732 | break; |
| 1733 | } |
| 1734 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT); |
Andrew Vasquez | 87f2701 | 2007-09-20 14:07:49 -0700 | [diff] [blame] | 1735 | } while (0); |
Andrew Vasquez | c695248 | 2008-04-03 13:13:17 -0700 | [diff] [blame] | 1736 | spin_unlock(&ha->hardware_lock); |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1737 | |
| 1738 | if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) && |
| 1739 | (status & MBX_INTERRUPT) && ha->flags.mbox_int) { |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1740 | set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); |
Marcus Barrow | 0b05a1f | 2008-01-17 09:02:13 -0800 | [diff] [blame] | 1741 | complete(&ha->mbx_intr_comp); |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | return IRQ_HANDLED; |
| 1745 | } |
| 1746 | |
| 1747 | /* Interrupt handling helpers. */ |
| 1748 | |
| 1749 | struct qla_init_msix_entry { |
| 1750 | uint16_t entry; |
| 1751 | uint16_t index; |
| 1752 | const char *name; |
Jeff Garzik | 476834c | 2007-05-23 14:41:44 -0700 | [diff] [blame] | 1753 | irq_handler_t handler; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1754 | }; |
| 1755 | |
| 1756 | static struct qla_init_msix_entry imsix_entries[QLA_MSIX_ENTRIES] = { |
| 1757 | { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT, |
| 1758 | "qla2xxx (default)", qla24xx_msix_default }, |
| 1759 | |
| 1760 | { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q, |
| 1761 | "qla2xxx (rsp_q)", qla24xx_msix_rsp_q }, |
| 1762 | }; |
| 1763 | |
| 1764 | static void |
| 1765 | qla24xx_disable_msix(scsi_qla_host_t *ha) |
| 1766 | { |
| 1767 | int i; |
| 1768 | struct qla_msix_entry *qentry; |
| 1769 | |
| 1770 | for (i = 0; i < QLA_MSIX_ENTRIES; i++) { |
| 1771 | qentry = &ha->msix_entries[imsix_entries[i].index]; |
| 1772 | if (qentry->have_irq) |
| 1773 | free_irq(qentry->msix_vector, ha); |
| 1774 | } |
| 1775 | pci_disable_msix(ha->pdev); |
| 1776 | } |
| 1777 | |
| 1778 | static int |
| 1779 | qla24xx_enable_msix(scsi_qla_host_t *ha) |
| 1780 | { |
| 1781 | int i, ret; |
| 1782 | struct msix_entry entries[QLA_MSIX_ENTRIES]; |
| 1783 | struct qla_msix_entry *qentry; |
| 1784 | |
| 1785 | for (i = 0; i < QLA_MSIX_ENTRIES; i++) |
| 1786 | entries[i].entry = imsix_entries[i].entry; |
| 1787 | |
| 1788 | ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries)); |
| 1789 | if (ret) { |
| 1790 | qla_printk(KERN_WARNING, ha, |
| 1791 | "MSI-X: Failed to enable support -- %d/%d\n", |
| 1792 | QLA_MSIX_ENTRIES, ret); |
| 1793 | goto msix_out; |
| 1794 | } |
| 1795 | ha->flags.msix_enabled = 1; |
| 1796 | |
| 1797 | for (i = 0; i < QLA_MSIX_ENTRIES; i++) { |
| 1798 | qentry = &ha->msix_entries[imsix_entries[i].index]; |
| 1799 | qentry->msix_vector = entries[i].vector; |
| 1800 | qentry->msix_entry = entries[i].entry; |
| 1801 | qentry->have_irq = 0; |
| 1802 | ret = request_irq(qentry->msix_vector, |
| 1803 | imsix_entries[i].handler, 0, imsix_entries[i].name, ha); |
| 1804 | if (ret) { |
| 1805 | qla_printk(KERN_WARNING, ha, |
| 1806 | "MSI-X: Unable to register handler -- %x/%d.\n", |
| 1807 | imsix_entries[i].index, ret); |
| 1808 | qla24xx_disable_msix(ha); |
| 1809 | goto msix_out; |
| 1810 | } |
| 1811 | qentry->have_irq = 1; |
| 1812 | } |
| 1813 | |
| 1814 | msix_out: |
| 1815 | return ret; |
| 1816 | } |
| 1817 | |
| 1818 | int |
| 1819 | qla2x00_request_irqs(scsi_qla_host_t *ha) |
| 1820 | { |
| 1821 | int ret; |
Andrew Vasquez | 963b0fd | 2008-01-31 12:33:50 -0800 | [diff] [blame] | 1822 | device_reg_t __iomem *reg = ha->iobase; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1823 | |
| 1824 | /* If possible, enable MSI-X. */ |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1825 | if (!IS_QLA2432(ha) && !IS_QLA2532(ha)) |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1826 | goto skip_msix; |
| 1827 | |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1828 | if (IS_QLA2432(ha) && (ha->chip_revision < QLA_MSIX_CHIP_REV_24XX || |
| 1829 | !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) { |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1830 | DEBUG2(qla_printk(KERN_WARNING, ha, |
| 1831 | "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n", |
| 1832 | ha->chip_revision, ha->fw_attributes)); |
| 1833 | |
| 1834 | goto skip_msix; |
| 1835 | } |
| 1836 | |
Andrew Vasquez | da7429f | 2008-01-17 09:02:11 -0800 | [diff] [blame] | 1837 | if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP && |
| 1838 | (ha->pdev->subsystem_device == 0x7040 || |
| 1839 | ha->pdev->subsystem_device == 0x7041 || |
| 1840 | ha->pdev->subsystem_device == 0x1705)) { |
| 1841 | DEBUG2(qla_printk(KERN_WARNING, ha, |
| 1842 | "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n", |
| 1843 | ha->pdev->subsystem_vendor, |
| 1844 | ha->pdev->subsystem_device)); |
| 1845 | |
| 1846 | goto skip_msi; |
| 1847 | } |
| 1848 | |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1849 | ret = qla24xx_enable_msix(ha); |
| 1850 | if (!ret) { |
| 1851 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 1852 | "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision, |
| 1853 | ha->fw_attributes)); |
Andrew Vasquez | 963b0fd | 2008-01-31 12:33:50 -0800 | [diff] [blame] | 1854 | goto clear_risc_ints; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1855 | } |
| 1856 | qla_printk(KERN_WARNING, ha, |
| 1857 | "MSI-X: Falling back-to INTa mode -- %d.\n", ret); |
| 1858 | skip_msix: |
Andrew Vasquez | cbedb60 | 2007-05-07 07:43:02 -0700 | [diff] [blame] | 1859 | |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1860 | if (!IS_QLA24XX(ha) && !IS_QLA2532(ha)) |
Andrew Vasquez | cbedb60 | 2007-05-07 07:43:02 -0700 | [diff] [blame] | 1861 | goto skip_msi; |
| 1862 | |
| 1863 | ret = pci_enable_msi(ha->pdev); |
| 1864 | if (!ret) { |
| 1865 | DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n")); |
| 1866 | ha->flags.msi_enabled = 1; |
| 1867 | } |
| 1868 | skip_msi: |
| 1869 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1870 | ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler, |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1871 | IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha); |
Andrew Vasquez | 963b0fd | 2008-01-31 12:33:50 -0800 | [diff] [blame] | 1872 | if (ret) { |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1873 | qla_printk(KERN_WARNING, ha, |
| 1874 | "Failed to reserve interrupt %d already in use.\n", |
| 1875 | ha->pdev->irq); |
Andrew Vasquez | 963b0fd | 2008-01-31 12:33:50 -0800 | [diff] [blame] | 1876 | goto fail; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1877 | } |
Andrew Vasquez | 963b0fd | 2008-01-31 12:33:50 -0800 | [diff] [blame] | 1878 | ha->flags.inta_enabled = 1; |
| 1879 | ha->host->irq = ha->pdev->irq; |
| 1880 | clear_risc_ints: |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1881 | |
Andrew Vasquez | 963b0fd | 2008-01-31 12:33:50 -0800 | [diff] [blame] | 1882 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | c695248 | 2008-04-03 13:13:17 -0700 | [diff] [blame] | 1883 | spin_lock_irq(&ha->hardware_lock); |
Andrew Vasquez | 963b0fd | 2008-01-31 12:33:50 -0800 | [diff] [blame] | 1884 | if (IS_FWI2_CAPABLE(ha)) { |
| 1885 | WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_HOST_INT); |
| 1886 | WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_RISC_INT); |
| 1887 | } else { |
| 1888 | WRT_REG_WORD(®->isp.semaphore, 0); |
| 1889 | WRT_REG_WORD(®->isp.hccr, HCCR_CLR_RISC_INT); |
| 1890 | WRT_REG_WORD(®->isp.hccr, HCCR_CLR_HOST_INT); |
| 1891 | } |
Andrew Vasquez | c695248 | 2008-04-03 13:13:17 -0700 | [diff] [blame] | 1892 | spin_unlock_irq(&ha->hardware_lock); |
Andrew Vasquez | 963b0fd | 2008-01-31 12:33:50 -0800 | [diff] [blame] | 1893 | ha->isp_ops->enable_intrs(ha); |
| 1894 | |
| 1895 | fail: |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1896 | return ret; |
| 1897 | } |
| 1898 | |
| 1899 | void |
| 1900 | qla2x00_free_irqs(scsi_qla_host_t *ha) |
| 1901 | { |
| 1902 | |
| 1903 | if (ha->flags.msix_enabled) |
| 1904 | qla24xx_disable_msix(ha); |
Andrew Vasquez | cbedb60 | 2007-05-07 07:43:02 -0700 | [diff] [blame] | 1905 | else if (ha->flags.inta_enabled) { |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1906 | free_irq(ha->host->irq, ha); |
Andrew Vasquez | cbedb60 | 2007-05-07 07:43:02 -0700 | [diff] [blame] | 1907 | pci_disable_msi(ha->pdev); |
| 1908 | } |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1909 | } |