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