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