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