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); |
Andrew Vasquez | 4346b14 | 2006-12-13 19:20:28 -0800 | [diff] [blame^] | 478 | |
| 479 | ha->flags.gpsc_supported = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | break; |
| 481 | |
| 482 | case MBA_CHG_IN_CONNECTION: /* Change in connection mode */ |
| 483 | if (IS_QLA2100(ha)) |
| 484 | break; |
| 485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection " |
| 487 | "received.\n", |
| 488 | ha->host_no)); |
| 489 | qla_printk(KERN_INFO, ha, |
| 490 | "Configuration change detected: value=%x.\n", mb[1]); |
| 491 | |
| 492 | if (atomic_read(&ha->loop_state) != LOOP_DOWN) { |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 493 | atomic_set(&ha->loop_state, LOOP_DOWN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | if (!atomic_read(&ha->loop_down_timer)) |
| 495 | atomic_set(&ha->loop_down_timer, |
| 496 | LOOP_DOWN_TIME); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 497 | qla2x00_mark_all_devices_lost(ha, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 501 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 502 | break; |
| 503 | |
| 504 | case MBA_PORT_UPDATE: /* Port database update */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET |
| 507 | * event etc. earlier indicating loop is down) then process |
| 508 | * it. Otherwise ignore it and Wait for RSCN to come in. |
| 509 | */ |
| 510 | atomic_set(&ha->loop_down_timer, 0); |
| 511 | if (atomic_read(&ha->loop_state) != LOOP_DOWN && |
| 512 | atomic_read(&ha->loop_state) != LOOP_DEAD) { |
| 513 | DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE " |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 514 | "ignored %04x/%04x/%04x.\n", ha->host_no, mb[1], |
| 515 | mb[2], mb[3])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | break; |
| 517 | } |
| 518 | |
| 519 | DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n", |
| 520 | ha->host_no)); |
| 521 | DEBUG(printk(KERN_INFO |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 522 | "scsi(%ld): Port database changed %04x %04x %04x.\n", |
| 523 | ha->host_no, mb[1], mb[2], mb[3])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
| 525 | /* |
| 526 | * Mark all devices as missing so we will login again. |
| 527 | */ |
| 528 | atomic_set(&ha->loop_state, LOOP_UP); |
| 529 | |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 530 | qla2x00_mark_all_devices_lost(ha, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
| 532 | ha->flags.rscn_queue_overflow = 1; |
| 533 | |
| 534 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 535 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | break; |
| 537 | |
| 538 | case MBA_RSCN_UPDATE: /* State Change Registration */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n", |
| 540 | ha->host_no)); |
| 541 | DEBUG(printk(KERN_INFO |
| 542 | "scsi(%ld): RSCN database changed -- %04x %04x.\n", |
| 543 | ha->host_no, mb[1], mb[2])); |
| 544 | |
| 545 | rscn_entry = (mb[1] << 16) | mb[2]; |
| 546 | host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) | |
| 547 | ha->d_id.b.al_pa; |
| 548 | if (rscn_entry == host_pid) { |
| 549 | DEBUG(printk(KERN_INFO |
| 550 | "scsi(%ld): Ignoring RSCN update to local host " |
| 551 | "port ID (%06x)\n", |
| 552 | ha->host_no, host_pid)); |
| 553 | break; |
| 554 | } |
| 555 | |
| 556 | rscn_queue_index = ha->rscn_in_ptr + 1; |
| 557 | if (rscn_queue_index == MAX_RSCN_COUNT) |
| 558 | rscn_queue_index = 0; |
| 559 | if (rscn_queue_index != ha->rscn_out_ptr) { |
| 560 | ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry; |
| 561 | ha->rscn_in_ptr = rscn_queue_index; |
| 562 | } else { |
| 563 | ha->flags.rscn_queue_overflow = 1; |
| 564 | } |
| 565 | |
| 566 | atomic_set(&ha->loop_state, LOOP_UPDATE); |
| 567 | atomic_set(&ha->loop_down_timer, 0); |
| 568 | ha->flags.management_server_logged_in = 0; |
| 569 | |
| 570 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 571 | set_bit(RSCN_UPDATE, &ha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | break; |
| 573 | |
| 574 | /* case MBA_RIO_RESPONSE: */ |
| 575 | case MBA_ZIO_RESPONSE: |
| 576 | DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n", |
| 577 | ha->host_no)); |
| 578 | DEBUG(printk(KERN_INFO |
| 579 | "scsi(%ld): [R|Z]IO update completion.\n", |
| 580 | ha->host_no)); |
| 581 | |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 582 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 583 | qla24xx_process_response_queue(ha); |
| 584 | else |
| 585 | qla2x00_process_response_queue(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | break; |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 587 | |
| 588 | case MBA_DISCARD_RND_FRAME: |
| 589 | DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x " |
| 590 | "%04x.\n", ha->host_no, mb[1], mb[2], mb[3])); |
| 591 | break; |
Andrew Vasquez | 45ebeb5 | 2006-08-01 13:48:14 -0700 | [diff] [blame] | 592 | |
| 593 | case MBA_TRACE_NOTIFICATION: |
| 594 | DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n", |
| 595 | ha->host_no, mb[1], mb[2])); |
| 596 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 600 | static void |
| 601 | qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data) |
| 602 | { |
| 603 | fc_port_t *fcport = data; |
| 604 | |
| 605 | if (fcport->ha->max_q_depth <= sdev->queue_depth) |
| 606 | return; |
| 607 | |
| 608 | if (sdev->ordered_tags) |
| 609 | scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, |
| 610 | sdev->queue_depth + 1); |
| 611 | else |
| 612 | scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, |
| 613 | sdev->queue_depth + 1); |
| 614 | |
| 615 | fcport->last_ramp_up = jiffies; |
| 616 | |
| 617 | DEBUG2(qla_printk(KERN_INFO, fcport->ha, |
| 618 | "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n", |
| 619 | fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun, |
| 620 | sdev->queue_depth)); |
| 621 | } |
| 622 | |
| 623 | static void |
| 624 | qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data) |
| 625 | { |
| 626 | fc_port_t *fcport = data; |
| 627 | |
| 628 | if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1)) |
| 629 | return; |
| 630 | |
| 631 | DEBUG2(qla_printk(KERN_INFO, fcport->ha, |
| 632 | "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n", |
| 633 | fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun, |
| 634 | sdev->queue_depth)); |
| 635 | } |
| 636 | |
| 637 | static inline void |
| 638 | qla2x00_ramp_up_queue_depth(scsi_qla_host_t *ha, srb_t *sp) |
| 639 | { |
| 640 | fc_port_t *fcport; |
| 641 | struct scsi_device *sdev; |
| 642 | |
| 643 | sdev = sp->cmd->device; |
| 644 | if (sdev->queue_depth >= ha->max_q_depth) |
| 645 | return; |
| 646 | |
| 647 | fcport = sp->fcport; |
| 648 | if (time_before(jiffies, |
| 649 | fcport->last_ramp_up + ql2xqfullrampup * HZ)) |
| 650 | return; |
| 651 | if (time_before(jiffies, |
| 652 | fcport->last_queue_full + ql2xqfullrampup * HZ)) |
| 653 | return; |
| 654 | |
| 655 | spin_unlock_irq(&ha->hardware_lock); |
| 656 | starget_for_each_device(sdev->sdev_target, fcport, |
| 657 | qla2x00_adjust_sdev_qdepth_up); |
| 658 | spin_lock_irq(&ha->hardware_lock); |
| 659 | } |
| 660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | /** |
| 662 | * qla2x00_process_completed_request() - Process a Fast Post response. |
| 663 | * @ha: SCSI driver HA context |
| 664 | * @index: SRB index |
| 665 | */ |
| 666 | static void |
| 667 | qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index) |
| 668 | { |
| 669 | srb_t *sp; |
| 670 | |
| 671 | /* Validate handle. */ |
| 672 | if (index >= MAX_OUTSTANDING_COMMANDS) { |
| 673 | DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n", |
| 674 | ha->host_no, index)); |
| 675 | qla_printk(KERN_WARNING, ha, |
| 676 | "Invalid SCSI completion handle %d.\n", index); |
| 677 | |
| 678 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 679 | return; |
| 680 | } |
| 681 | |
| 682 | sp = ha->outstanding_cmds[index]; |
| 683 | if (sp) { |
| 684 | /* Free outstanding command slot. */ |
| 685 | ha->outstanding_cmds[index] = NULL; |
| 686 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | CMD_COMPL_STATUS(sp->cmd) = 0L; |
| 688 | CMD_SCSI_STATUS(sp->cmd) = 0L; |
| 689 | |
| 690 | /* Save ISP completion status */ |
| 691 | sp->cmd->result = DID_OK << 16; |
Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 692 | |
| 693 | qla2x00_ramp_up_queue_depth(ha, sp); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 694 | qla2x00_sp_compl(ha, sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | } else { |
| 696 | DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n", |
| 697 | ha->host_no)); |
| 698 | qla_printk(KERN_WARNING, ha, |
| 699 | "Invalid ISP SCSI completion handle\n"); |
| 700 | |
| 701 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | /** |
| 706 | * qla2x00_process_response_queue() - Process response queue entries. |
| 707 | * @ha: SCSI driver HA context |
| 708 | */ |
| 709 | void |
| 710 | qla2x00_process_response_queue(struct scsi_qla_host *ha) |
| 711 | { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 712 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | sts_entry_t *pkt; |
| 714 | uint16_t handle_cnt; |
| 715 | uint16_t cnt; |
| 716 | |
| 717 | if (!ha->flags.online) |
| 718 | return; |
| 719 | |
| 720 | while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) { |
| 721 | pkt = (sts_entry_t *)ha->response_ring_ptr; |
| 722 | |
| 723 | ha->rsp_ring_index++; |
| 724 | if (ha->rsp_ring_index == ha->response_q_length) { |
| 725 | ha->rsp_ring_index = 0; |
| 726 | ha->response_ring_ptr = ha->response_ring; |
| 727 | } else { |
| 728 | ha->response_ring_ptr++; |
| 729 | } |
| 730 | |
| 731 | if (pkt->entry_status != 0) { |
| 732 | DEBUG3(printk(KERN_INFO |
| 733 | "scsi(%ld): Process error entry.\n", ha->host_no)); |
| 734 | |
| 735 | qla2x00_error_entry(ha, pkt); |
| 736 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; |
| 737 | wmb(); |
| 738 | continue; |
| 739 | } |
| 740 | |
| 741 | switch (pkt->entry_type) { |
| 742 | case STATUS_TYPE: |
| 743 | qla2x00_status_entry(ha, pkt); |
| 744 | break; |
| 745 | case STATUS_TYPE_21: |
| 746 | handle_cnt = ((sts21_entry_t *)pkt)->handle_count; |
| 747 | for (cnt = 0; cnt < handle_cnt; cnt++) { |
| 748 | qla2x00_process_completed_request(ha, |
| 749 | ((sts21_entry_t *)pkt)->handle[cnt]); |
| 750 | } |
| 751 | break; |
| 752 | case STATUS_TYPE_22: |
| 753 | handle_cnt = ((sts22_entry_t *)pkt)->handle_count; |
| 754 | for (cnt = 0; cnt < handle_cnt; cnt++) { |
| 755 | qla2x00_process_completed_request(ha, |
| 756 | ((sts22_entry_t *)pkt)->handle[cnt]); |
| 757 | } |
| 758 | break; |
| 759 | case STATUS_CONT_TYPE: |
| 760 | qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt); |
| 761 | break; |
| 762 | case MS_IOCB_TYPE: |
| 763 | qla2x00_ms_entry(ha, (ms_iocb_entry_t *)pkt); |
| 764 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | default: |
| 766 | /* Type Not Supported. */ |
| 767 | DEBUG4(printk(KERN_WARNING |
| 768 | "scsi(%ld): Received unknown response pkt type %x " |
| 769 | "entry status=%x.\n", |
| 770 | ha->host_no, pkt->entry_type, pkt->entry_status)); |
| 771 | break; |
| 772 | } |
| 773 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; |
| 774 | wmb(); |
| 775 | } |
| 776 | |
| 777 | /* Adjust ring index */ |
| 778 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index); |
| 779 | } |
| 780 | |
| 781 | /** |
| 782 | * qla2x00_status_entry() - Process a Status IOCB entry. |
| 783 | * @ha: SCSI driver HA context |
| 784 | * @pkt: Entry pointer |
| 785 | */ |
| 786 | static void |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 787 | qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | srb_t *sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | fc_port_t *fcport; |
| 791 | struct scsi_cmnd *cp; |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 792 | sts_entry_t *sts; |
| 793 | struct sts_entry_24xx *sts24; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | uint16_t comp_status; |
| 795 | uint16_t scsi_status; |
| 796 | uint8_t lscsi_status; |
| 797 | int32_t resid; |
Ravi Anand | ed17c71b5 | 2006-05-17 15:08:55 -0700 | [diff] [blame] | 798 | uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len; |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 799 | uint8_t *rsp_info, *sense_data; |
| 800 | |
| 801 | sts = (sts_entry_t *) pkt; |
| 802 | sts24 = (struct sts_entry_24xx *) pkt; |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 803 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 804 | comp_status = le16_to_cpu(sts24->comp_status); |
| 805 | scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK; |
| 806 | } else { |
| 807 | comp_status = le16_to_cpu(sts->comp_status); |
| 808 | scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK; |
| 809 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | |
| 811 | /* Fast path completion. */ |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 812 | if (comp_status == CS_COMPLETE && scsi_status == 0) { |
| 813 | qla2x00_process_completed_request(ha, sts->handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | |
| 815 | return; |
| 816 | } |
| 817 | |
| 818 | /* Validate handle. */ |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 819 | if (sts->handle < MAX_OUTSTANDING_COMMANDS) { |
| 820 | sp = ha->outstanding_cmds[sts->handle]; |
| 821 | ha->outstanding_cmds[sts->handle] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | } else |
| 823 | sp = NULL; |
| 824 | |
| 825 | if (sp == NULL) { |
| 826 | DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n", |
| 827 | ha->host_no)); |
| 828 | qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n"); |
| 829 | |
| 830 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 831 | qla2xxx_wake_dpc(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | return; |
| 833 | } |
| 834 | cp = sp->cmd; |
| 835 | if (cp == NULL) { |
| 836 | DEBUG2(printk("scsi(%ld): Command already returned back to OS " |
Andrew Vasquez | 75bc419 | 2006-05-17 15:09:22 -0700 | [diff] [blame] | 837 | "pkt->handle=%d sp=%p.\n", ha->host_no, sts->handle, sp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | qla_printk(KERN_WARNING, ha, |
| 839 | "Command is NULL: already returned to OS (sp=%p)\n", sp); |
| 840 | |
| 841 | return; |
| 842 | } |
| 843 | |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 844 | lscsi_status = scsi_status & STATUS_MASK; |
| 845 | CMD_ENTRY_STATUS(cp) = sts->entry_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | CMD_COMPL_STATUS(cp) = comp_status; |
| 847 | CMD_SCSI_STATUS(cp) = scsi_status; |
| 848 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 849 | fcport = sp->fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
Ravi Anand | ed17c71b5 | 2006-05-17 15:08:55 -0700 | [diff] [blame] | 851 | 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] | 852 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 853 | sense_len = le32_to_cpu(sts24->sense_len); |
| 854 | rsp_info_len = le32_to_cpu(sts24->rsp_data_len); |
| 855 | resid_len = le32_to_cpu(sts24->rsp_residual_count); |
Ravi Anand | ed17c71b5 | 2006-05-17 15:08:55 -0700 | [diff] [blame] | 856 | fw_resid_len = le32_to_cpu(sts24->residual_len); |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 857 | rsp_info = sts24->data; |
| 858 | sense_data = sts24->data; |
| 859 | host_to_fcp_swap(sts24->data, sizeof(sts24->data)); |
| 860 | } else { |
| 861 | sense_len = le16_to_cpu(sts->req_sense_length); |
| 862 | rsp_info_len = le16_to_cpu(sts->rsp_info_len); |
| 863 | resid_len = le32_to_cpu(sts->residual_length); |
| 864 | rsp_info = sts->rsp_info; |
| 865 | sense_data = sts->req_sense_data; |
| 866 | } |
| 867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | /* Check for any FCP transport errors. */ |
| 869 | if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) { |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 870 | /* Sense data lies beyond any FCP RESPONSE data. */ |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 871 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 872 | sense_data += rsp_info_len; |
| 873 | if (rsp_info_len > 3 && rsp_info[3]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol " |
| 875 | "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..." |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 876 | "retrying command\n", ha->host_no, |
| 877 | cp->device->channel, cp->device->id, |
| 878 | cp->device->lun, rsp_info_len, rsp_info[0], |
| 879 | rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4], |
| 880 | rsp_info[5], rsp_info[6], rsp_info[7])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | |
| 882 | cp->result = DID_BUS_BUSY << 16; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 883 | qla2x00_sp_compl(ha, sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | return; |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | /* |
| 889 | * Based on Host and scsi status generate status code for Linux |
| 890 | */ |
| 891 | switch (comp_status) { |
| 892 | case CS_COMPLETE: |
Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 893 | case CS_QUEUE_FULL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | if (scsi_status == 0) { |
| 895 | cp->result = DID_OK << 16; |
| 896 | break; |
| 897 | } |
| 898 | if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) { |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 899 | resid = resid_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | cp->resid = resid; |
| 901 | CMD_RESID_LEN(cp) = resid; |
Andrew Vasquez | 0da69df | 2005-12-06 10:58:06 -0800 | [diff] [blame] | 902 | |
| 903 | if (!lscsi_status && |
| 904 | ((unsigned)(cp->request_bufflen - resid) < |
| 905 | cp->underflow)) { |
| 906 | qla_printk(KERN_INFO, ha, |
| 907 | "scsi(%ld:%d:%d:%d): Mid-layer underflow " |
| 908 | "detected (%x of %x bytes)...returning " |
| 909 | "error status.\n", ha->host_no, |
| 910 | cp->device->channel, cp->device->id, |
| 911 | cp->device->lun, resid, |
| 912 | cp->request_bufflen); |
| 913 | |
| 914 | cp->result = DID_ERROR << 16; |
| 915 | break; |
| 916 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | cp->result = DID_OK << 16 | lscsi_status; |
| 919 | |
Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 920 | if (lscsi_status == SAM_STAT_TASK_SET_FULL) { |
| 921 | DEBUG2(printk(KERN_INFO |
| 922 | "scsi(%ld): QUEUE FULL status detected " |
| 923 | "0x%x-0x%x.\n", ha->host_no, comp_status, |
| 924 | scsi_status)); |
| 925 | |
| 926 | /* Adjust queue depth for all luns on the port. */ |
| 927 | fcport->last_queue_full = jiffies; |
| 928 | spin_unlock_irq(&ha->hardware_lock); |
| 929 | starget_for_each_device(cp->device->sdev_target, |
| 930 | fcport, qla2x00_adjust_sdev_qdepth_down); |
| 931 | spin_lock_irq(&ha->hardware_lock); |
| 932 | break; |
| 933 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | if (lscsi_status != SS_CHECK_CONDITION) |
| 935 | break; |
| 936 | |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 937 | /* Copy Sense Data into sense buffer. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer)); |
| 939 | |
| 940 | if (!(scsi_status & SS_SENSE_LEN_VALID)) |
| 941 | break; |
| 942 | |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 943 | if (sense_len >= sizeof(cp->sense_buffer)) |
| 944 | sense_len = sizeof(cp->sense_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 946 | CMD_ACTUAL_SNSLEN(cp) = sense_len; |
| 947 | sp->request_sense_length = sense_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | sp->request_sense_ptr = cp->sense_buffer; |
| 949 | |
| 950 | if (sp->request_sense_length > 32) |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 951 | sense_len = 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 953 | memcpy(cp->sense_buffer, sense_data, sense_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 955 | sp->request_sense_ptr += sense_len; |
| 956 | sp->request_sense_length -= sense_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | if (sp->request_sense_length != 0) |
| 958 | ha->status_srb = sp; |
| 959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | DEBUG5(printk("%s(): Check condition Sense data, " |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 961 | "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n", __func__, |
| 962 | ha->host_no, cp->device->channel, cp->device->id, |
| 963 | cp->device->lun, cp, cp->serial_number)); |
| 964 | if (sense_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | DEBUG5(qla2x00_dump_buffer(cp->sense_buffer, |
| 966 | CMD_ACTUAL_SNSLEN(cp))); |
| 967 | break; |
| 968 | |
| 969 | case CS_DATA_UNDERRUN: |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 970 | resid = resid_len; |
Ravi Anand | ed17c71b5 | 2006-05-17 15:08:55 -0700 | [diff] [blame] | 971 | /* Use F/W calculated residual length. */ |
| 972 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) |
| 973 | resid = fw_resid_len; |
| 974 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | if (scsi_status & SS_RESIDUAL_UNDER) { |
| 976 | cp->resid = resid; |
| 977 | CMD_RESID_LEN(cp) = resid; |
andrew.vasquez@qlogic.com | e038a1b | 2006-01-13 17:04:59 -0800 | [diff] [blame] | 978 | } else { |
| 979 | DEBUG2(printk(KERN_INFO |
| 980 | "scsi(%ld:%d:%d) UNDERRUN status detected " |
Ravi Anand | ed17c71b5 | 2006-05-17 15:08:55 -0700 | [diff] [blame] | 981 | "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x " |
| 982 | "os_underflow=0x%x\n", ha->host_no, |
| 983 | cp->device->id, cp->device->lun, comp_status, |
| 984 | scsi_status, resid_len, resid, cp->cmnd[0], |
| 985 | cp->underflow)); |
andrew.vasquez@qlogic.com | e038a1b | 2006-01-13 17:04:59 -0800 | [diff] [blame] | 986 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | /* |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 990 | * 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] | 991 | * Status. |
| 992 | */ |
| 993 | if (lscsi_status != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | cp->result = DID_OK << 16 | lscsi_status; |
| 995 | |
| 996 | if (lscsi_status != SS_CHECK_CONDITION) |
| 997 | break; |
| 998 | |
| 999 | /* Copy Sense Data into sense buffer */ |
| 1000 | memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer)); |
| 1001 | |
| 1002 | if (!(scsi_status & SS_SENSE_LEN_VALID)) |
| 1003 | break; |
| 1004 | |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1005 | if (sense_len >= sizeof(cp->sense_buffer)) |
| 1006 | sense_len = sizeof(cp->sense_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1008 | CMD_ACTUAL_SNSLEN(cp) = sense_len; |
| 1009 | sp->request_sense_length = sense_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | sp->request_sense_ptr = cp->sense_buffer; |
| 1011 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1012 | if (sp->request_sense_length > 32) |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1013 | sense_len = 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1015 | memcpy(cp->sense_buffer, sense_data, sense_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1017 | sp->request_sense_ptr += sense_len; |
| 1018 | sp->request_sense_length -= sense_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | if (sp->request_sense_length != 0) |
| 1020 | ha->status_srb = sp; |
| 1021 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | DEBUG5(printk("%s(): Check condition Sense data, " |
| 1023 | "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n", |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1024 | __func__, ha->host_no, cp->device->channel, |
| 1025 | cp->device->id, cp->device->lun, cp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | cp->serial_number)); |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1027 | |
| 1028 | if (sense_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | DEBUG5(qla2x00_dump_buffer(cp->sense_buffer, |
| 1030 | CMD_ACTUAL_SNSLEN(cp))); |
| 1031 | } else { |
| 1032 | /* |
| 1033 | * If RISC reports underrun and target does not report |
| 1034 | * it then we must have a lost frame, so tell upper |
| 1035 | * layer to retry it by reporting a bus busy. |
| 1036 | */ |
| 1037 | if (!(scsi_status & SS_RESIDUAL_UNDER)) { |
| 1038 | DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped " |
| 1039 | "frame(s) detected (%x of %x bytes)..." |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1040 | "retrying command.\n", ha->host_no, |
| 1041 | cp->device->channel, cp->device->id, |
| 1042 | cp->device->lun, resid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | cp->request_bufflen)); |
| 1044 | |
| 1045 | cp->result = DID_BUS_BUSY << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | break; |
| 1047 | } |
| 1048 | |
| 1049 | /* Handle mid-layer underflow */ |
| 1050 | if ((unsigned)(cp->request_bufflen - resid) < |
| 1051 | cp->underflow) { |
| 1052 | qla_printk(KERN_INFO, ha, |
| 1053 | "scsi(%ld:%d:%d:%d): Mid-layer underflow " |
| 1054 | "detected (%x of %x bytes)...returning " |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1055 | "error status.\n", ha->host_no, |
| 1056 | cp->device->channel, cp->device->id, |
| 1057 | cp->device->lun, resid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | cp->request_bufflen); |
| 1059 | |
| 1060 | cp->result = DID_ERROR << 16; |
| 1061 | break; |
| 1062 | } |
| 1063 | |
| 1064 | /* Everybody online, looking good... */ |
| 1065 | cp->result = DID_OK << 16; |
| 1066 | } |
| 1067 | break; |
| 1068 | |
| 1069 | case CS_DATA_OVERRUN: |
| 1070 | DEBUG2(printk(KERN_INFO |
| 1071 | "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n", |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1072 | ha->host_no, cp->device->id, cp->device->lun, comp_status, |
| 1073 | scsi_status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | DEBUG2(printk(KERN_INFO |
| 1075 | "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", |
| 1076 | cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3], |
| 1077 | cp->cmnd[4], cp->cmnd[5])); |
| 1078 | DEBUG2(printk(KERN_INFO |
| 1079 | "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR " |
| 1080 | "status!\n", |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1081 | cp->serial_number, cp->request_bufflen, resid_len)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | |
| 1083 | cp->result = DID_ERROR << 16; |
| 1084 | break; |
| 1085 | |
| 1086 | case CS_PORT_LOGGED_OUT: |
| 1087 | case CS_PORT_CONFIG_CHG: |
| 1088 | case CS_PORT_BUSY: |
| 1089 | case CS_INCOMPLETE: |
| 1090 | case CS_PORT_UNAVAILABLE: |
| 1091 | /* |
| 1092 | * If the port is in Target Down state, return all IOs for this |
| 1093 | * Target with DID_NO_CONNECT ELSE Queue the IOs in the |
| 1094 | * retry_queue. |
| 1095 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down " |
| 1097 | "pid=%ld, compl status=0x%x, port state=0x%x\n", |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1098 | ha->host_no, cp->device->id, cp->device->lun, |
| 1099 | cp->serial_number, comp_status, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | atomic_read(&fcport->state))); |
| 1101 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1102 | cp->result = DID_BUS_BUSY << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | if (atomic_read(&fcport->state) == FCS_ONLINE) { |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 1104 | qla2x00_mark_device_lost(ha, fcport, 1, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | break; |
| 1107 | |
| 1108 | case CS_RESET: |
| 1109 | DEBUG2(printk(KERN_INFO |
| 1110 | "scsi(%ld): RESET status detected 0x%x-0x%x.\n", |
| 1111 | ha->host_no, comp_status, scsi_status)); |
| 1112 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1113 | cp->result = DID_RESET << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | break; |
| 1115 | |
| 1116 | case CS_ABORTED: |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1117 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | * hv2.19.12 - DID_ABORT does not retry the request if we |
| 1119 | * aborted this request then abort otherwise it must be a |
| 1120 | * reset. |
| 1121 | */ |
| 1122 | DEBUG2(printk(KERN_INFO |
| 1123 | "scsi(%ld): ABORT status detected 0x%x-0x%x.\n", |
| 1124 | ha->host_no, comp_status, scsi_status)); |
| 1125 | |
| 1126 | cp->result = DID_RESET << 16; |
| 1127 | break; |
| 1128 | |
| 1129 | case CS_TIMEOUT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | cp->result = DID_BUS_BUSY << 16; |
| 1131 | |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 1132 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1133 | DEBUG2(printk(KERN_INFO |
| 1134 | "scsi(%ld:%d:%d:%d): TIMEOUT status detected " |
| 1135 | "0x%x-0x%x\n", ha->host_no, cp->device->channel, |
| 1136 | cp->device->id, cp->device->lun, comp_status, |
| 1137 | scsi_status)); |
| 1138 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | } |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1140 | DEBUG2(printk(KERN_INFO |
| 1141 | "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x " |
| 1142 | "sflags=%x.\n", ha->host_no, cp->device->channel, |
| 1143 | cp->device->id, cp->device->lun, comp_status, scsi_status, |
| 1144 | le16_to_cpu(sts->status_flags))); |
| 1145 | |
| 1146 | /* Check to see if logout occurred. */ |
| 1147 | if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT)) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 1148 | qla2x00_mark_device_lost(ha, fcport, 1, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | break; |
| 1150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | default: |
| 1152 | DEBUG3(printk("scsi(%ld): Error detected (unknown status) " |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1153 | "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | qla_printk(KERN_INFO, ha, |
| 1155 | "Unknown status detected 0x%x-0x%x.\n", |
| 1156 | comp_status, scsi_status); |
| 1157 | |
| 1158 | cp->result = DID_ERROR << 16; |
| 1159 | break; |
| 1160 | } |
| 1161 | |
| 1162 | /* Place command on done queue. */ |
| 1163 | if (ha->status_srb == NULL) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1164 | qla2x00_sp_compl(ha, sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | /** |
| 1168 | * qla2x00_status_cont_entry() - Process a Status Continuations entry. |
| 1169 | * @ha: SCSI driver HA context |
| 1170 | * @pkt: Entry pointer |
| 1171 | * |
| 1172 | * Extended sense data. |
| 1173 | */ |
| 1174 | static void |
| 1175 | qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt) |
| 1176 | { |
| 1177 | uint8_t sense_sz = 0; |
| 1178 | srb_t *sp = ha->status_srb; |
| 1179 | struct scsi_cmnd *cp; |
| 1180 | |
| 1181 | if (sp != NULL && sp->request_sense_length != 0) { |
| 1182 | cp = sp->cmd; |
| 1183 | if (cp == NULL) { |
| 1184 | DEBUG2(printk("%s(): Cmd already returned back to OS " |
Andrew Vasquez | 75bc419 | 2006-05-17 15:09:22 -0700 | [diff] [blame] | 1185 | "sp=%p.\n", __func__, sp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | qla_printk(KERN_INFO, ha, |
| 1187 | "cmd is NULL: already returned to OS (sp=%p)\n", |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1188 | sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | |
| 1190 | ha->status_srb = NULL; |
| 1191 | return; |
| 1192 | } |
| 1193 | |
| 1194 | if (sp->request_sense_length > sizeof(pkt->data)) { |
| 1195 | sense_sz = sizeof(pkt->data); |
| 1196 | } else { |
| 1197 | sense_sz = sp->request_sense_length; |
| 1198 | } |
| 1199 | |
| 1200 | /* Move sense data. */ |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 1201 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1202 | host_to_fcp_swap(pkt->data, sizeof(pkt->data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | memcpy(sp->request_sense_ptr, pkt->data, sense_sz); |
| 1204 | DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz)); |
| 1205 | |
| 1206 | sp->request_sense_ptr += sense_sz; |
| 1207 | sp->request_sense_length -= sense_sz; |
| 1208 | |
| 1209 | /* Place command on done queue. */ |
| 1210 | if (sp->request_sense_length == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | ha->status_srb = NULL; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1212 | qla2x00_sp_compl(ha, sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | } |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | /** |
| 1218 | * qla2x00_error_entry() - Process an error entry. |
| 1219 | * @ha: SCSI driver HA context |
| 1220 | * @pkt: Entry pointer |
| 1221 | */ |
| 1222 | static void |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1223 | qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | { |
| 1225 | srb_t *sp; |
| 1226 | |
| 1227 | #if defined(QL_DEBUG_LEVEL_2) |
| 1228 | if (pkt->entry_status & RF_INV_E_ORDER) |
| 1229 | qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__); |
| 1230 | else if (pkt->entry_status & RF_INV_E_COUNT) |
| 1231 | qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__); |
| 1232 | else if (pkt->entry_status & RF_INV_E_PARAM) |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1233 | qla_printk(KERN_ERR, ha, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | "%s: Invalid Entry Parameter\n", __func__); |
| 1235 | else if (pkt->entry_status & RF_INV_E_TYPE) |
| 1236 | qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__); |
| 1237 | else if (pkt->entry_status & RF_BUSY) |
| 1238 | qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__); |
| 1239 | else |
| 1240 | qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__); |
| 1241 | #endif |
| 1242 | |
| 1243 | /* Validate handle. */ |
| 1244 | if (pkt->handle < MAX_OUTSTANDING_COMMANDS) |
| 1245 | sp = ha->outstanding_cmds[pkt->handle]; |
| 1246 | else |
| 1247 | sp = NULL; |
| 1248 | |
| 1249 | if (sp) { |
| 1250 | /* Free outstanding command slot. */ |
| 1251 | ha->outstanding_cmds[pkt->handle] = NULL; |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 1252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | /* Bad payload or header */ |
| 1254 | if (pkt->entry_status & |
| 1255 | (RF_INV_E_ORDER | RF_INV_E_COUNT | |
| 1256 | RF_INV_E_PARAM | RF_INV_E_TYPE)) { |
| 1257 | sp->cmd->result = DID_ERROR << 16; |
| 1258 | } else if (pkt->entry_status & RF_BUSY) { |
| 1259 | sp->cmd->result = DID_BUS_BUSY << 16; |
| 1260 | } else { |
| 1261 | sp->cmd->result = DID_ERROR << 16; |
| 1262 | } |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1263 | qla2x00_sp_compl(ha, sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1265 | } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type == |
| 1266 | COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n", |
| 1268 | ha->host_no)); |
| 1269 | qla_printk(KERN_WARNING, ha, |
| 1270 | "Error entry - invalid handle\n"); |
| 1271 | |
| 1272 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 1273 | qla2xxx_wake_dpc(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | /** |
| 1278 | * qla2x00_ms_entry() - Process a Management Server entry. |
| 1279 | * @ha: SCSI driver HA context |
| 1280 | * @index: Response queue out pointer |
| 1281 | */ |
| 1282 | static void |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1283 | 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] | 1284 | { |
| 1285 | srb_t *sp; |
| 1286 | |
| 1287 | DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n", |
| 1288 | __func__, ha->host_no, pkt, pkt->handle1)); |
| 1289 | |
| 1290 | /* Validate handle. */ |
| 1291 | if (pkt->handle1 < MAX_OUTSTANDING_COMMANDS) |
| 1292 | sp = ha->outstanding_cmds[pkt->handle1]; |
| 1293 | else |
| 1294 | sp = NULL; |
| 1295 | |
| 1296 | if (sp == NULL) { |
| 1297 | DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n", |
| 1298 | ha->host_no)); |
| 1299 | qla_printk(KERN_WARNING, ha, "MS entry - invalid handle\n"); |
| 1300 | |
| 1301 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 1302 | return; |
| 1303 | } |
| 1304 | |
| 1305 | CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->status); |
| 1306 | CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status; |
| 1307 | |
| 1308 | /* Free outstanding command slot. */ |
| 1309 | ha->outstanding_cmds[pkt->handle1] = NULL; |
| 1310 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1311 | qla2x00_sp_compl(ha, sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | } |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1313 | |
| 1314 | |
| 1315 | /** |
| 1316 | * qla24xx_mbx_completion() - Process mailbox command completions. |
| 1317 | * @ha: SCSI driver HA context |
| 1318 | * @mb0: Mailbox0 register |
| 1319 | */ |
| 1320 | static void |
| 1321 | qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0) |
| 1322 | { |
| 1323 | uint16_t cnt; |
| 1324 | uint16_t __iomem *wptr; |
| 1325 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1326 | |
| 1327 | /* Load return mailbox registers. */ |
| 1328 | ha->flags.mbox_int = 1; |
| 1329 | ha->mailbox_out[0] = mb0; |
| 1330 | wptr = (uint16_t __iomem *)®->mailbox1; |
| 1331 | |
| 1332 | for (cnt = 1; cnt < ha->mbx_count; cnt++) { |
| 1333 | ha->mailbox_out[cnt] = RD_REG_WORD(wptr); |
| 1334 | wptr++; |
| 1335 | } |
| 1336 | |
| 1337 | if (ha->mcp) { |
| 1338 | DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n", |
| 1339 | __func__, ha->host_no, ha->mcp->mb[0])); |
| 1340 | } else { |
| 1341 | DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n", |
| 1342 | __func__, ha->host_no)); |
| 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | /** |
| 1347 | * qla24xx_process_response_queue() - Process response queue entries. |
| 1348 | * @ha: SCSI driver HA context |
| 1349 | */ |
| 1350 | void |
| 1351 | qla24xx_process_response_queue(struct scsi_qla_host *ha) |
| 1352 | { |
| 1353 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1354 | struct sts_entry_24xx *pkt; |
| 1355 | |
| 1356 | if (!ha->flags.online) |
| 1357 | return; |
| 1358 | |
| 1359 | while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) { |
| 1360 | pkt = (struct sts_entry_24xx *)ha->response_ring_ptr; |
| 1361 | |
| 1362 | ha->rsp_ring_index++; |
| 1363 | if (ha->rsp_ring_index == ha->response_q_length) { |
| 1364 | ha->rsp_ring_index = 0; |
| 1365 | ha->response_ring_ptr = ha->response_ring; |
| 1366 | } else { |
| 1367 | ha->response_ring_ptr++; |
| 1368 | } |
| 1369 | |
| 1370 | if (pkt->entry_status != 0) { |
| 1371 | DEBUG3(printk(KERN_INFO |
| 1372 | "scsi(%ld): Process error entry.\n", ha->host_no)); |
| 1373 | |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1374 | qla2x00_error_entry(ha, (sts_entry_t *) pkt); |
| 1375 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; |
| 1376 | wmb(); |
| 1377 | continue; |
| 1378 | } |
| 1379 | |
| 1380 | switch (pkt->entry_type) { |
| 1381 | case STATUS_TYPE: |
| 1382 | qla2x00_status_entry(ha, pkt); |
| 1383 | break; |
| 1384 | case STATUS_CONT_TYPE: |
| 1385 | qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt); |
| 1386 | break; |
| 1387 | case MS_IOCB_TYPE: |
| 1388 | qla24xx_ms_entry(ha, (struct ct_entry_24xx *)pkt); |
| 1389 | break; |
| 1390 | default: |
| 1391 | /* Type Not Supported. */ |
| 1392 | DEBUG4(printk(KERN_WARNING |
| 1393 | "scsi(%ld): Received unknown response pkt type %x " |
| 1394 | "entry status=%x.\n", |
| 1395 | ha->host_no, pkt->entry_type, pkt->entry_status)); |
| 1396 | break; |
| 1397 | } |
| 1398 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; |
| 1399 | wmb(); |
| 1400 | } |
| 1401 | |
| 1402 | /* Adjust ring index */ |
| 1403 | WRT_REG_DWORD(®->rsp_q_out, ha->rsp_ring_index); |
| 1404 | } |
| 1405 | |
| 1406 | /** |
| 1407 | * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx. |
| 1408 | * @irq: |
| 1409 | * @dev_id: SCSI driver HA context |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1410 | * |
| 1411 | * Called by system whenever the host adapter generates an interrupt. |
| 1412 | * |
| 1413 | * Returns handled flag. |
| 1414 | */ |
| 1415 | irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1416 | qla24xx_intr_handler(int irq, void *dev_id) |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1417 | { |
| 1418 | scsi_qla_host_t *ha; |
| 1419 | struct device_reg_24xx __iomem *reg; |
| 1420 | int status; |
| 1421 | unsigned long flags; |
| 1422 | unsigned long iter; |
| 1423 | uint32_t stat; |
| 1424 | uint32_t hccr; |
| 1425 | uint16_t mb[4]; |
| 1426 | |
| 1427 | ha = (scsi_qla_host_t *) dev_id; |
| 1428 | if (!ha) { |
| 1429 | printk(KERN_INFO |
| 1430 | "%s(): NULL host pointer\n", __func__); |
| 1431 | return IRQ_NONE; |
| 1432 | } |
| 1433 | |
| 1434 | reg = &ha->iobase->isp24; |
| 1435 | status = 0; |
| 1436 | |
| 1437 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1438 | for (iter = 50; iter--; ) { |
| 1439 | stat = RD_REG_DWORD(®->host_status); |
| 1440 | if (stat & HSRX_RISC_PAUSED) { |
| 1441 | hccr = RD_REG_DWORD(®->hccr); |
| 1442 | |
| 1443 | qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, " |
| 1444 | "Dumping firmware!\n", hccr); |
| 1445 | qla24xx_fw_dump(ha, 1); |
| 1446 | |
| 1447 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 1448 | break; |
| 1449 | } else if ((stat & HSRX_RISC_INT) == 0) |
| 1450 | break; |
| 1451 | |
| 1452 | switch (stat & 0xff) { |
| 1453 | case 0x1: |
| 1454 | case 0x2: |
| 1455 | case 0x10: |
| 1456 | case 0x11: |
| 1457 | qla24xx_mbx_completion(ha, MSW(stat)); |
| 1458 | status |= MBX_INTERRUPT; |
| 1459 | |
| 1460 | break; |
| 1461 | case 0x12: |
| 1462 | mb[0] = MSW(stat); |
| 1463 | mb[1] = RD_REG_WORD(®->mailbox1); |
| 1464 | mb[2] = RD_REG_WORD(®->mailbox2); |
| 1465 | mb[3] = RD_REG_WORD(®->mailbox3); |
| 1466 | qla2x00_async_event(ha, mb); |
| 1467 | break; |
| 1468 | case 0x13: |
| 1469 | qla24xx_process_response_queue(ha); |
| 1470 | break; |
| 1471 | default: |
| 1472 | DEBUG2(printk("scsi(%ld): Unrecognized interrupt type " |
| 1473 | "(%d).\n", |
| 1474 | ha->host_no, stat & 0xff)); |
| 1475 | break; |
| 1476 | } |
| 1477 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT); |
| 1478 | RD_REG_DWORD_RELAXED(®->hccr); |
| 1479 | } |
| 1480 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1481 | |
| 1482 | if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) && |
| 1483 | (status & MBX_INTERRUPT) && ha->flags.mbox_int) { |
| 1484 | spin_lock_irqsave(&ha->mbx_reg_lock, flags); |
| 1485 | |
| 1486 | set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); |
| 1487 | up(&ha->mbx_intr_sem); |
| 1488 | |
| 1489 | spin_unlock_irqrestore(&ha->mbx_reg_lock, flags); |
| 1490 | } |
| 1491 | |
| 1492 | return IRQ_HANDLED; |
| 1493 | } |
| 1494 | |
| 1495 | /** |
| 1496 | * qla24xx_ms_entry() - Process a Management Server entry. |
| 1497 | * @ha: SCSI driver HA context |
| 1498 | * @index: Response queue out pointer |
| 1499 | */ |
| 1500 | static void |
| 1501 | qla24xx_ms_entry(scsi_qla_host_t *ha, struct ct_entry_24xx *pkt) |
| 1502 | { |
| 1503 | srb_t *sp; |
| 1504 | |
| 1505 | DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n", |
| 1506 | __func__, ha->host_no, pkt, pkt->handle)); |
| 1507 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1508 | DEBUG9(printk("%s: ct pkt dump:\n", __func__)); |
| 1509 | DEBUG9(qla2x00_dump_buffer((void *)pkt, sizeof(struct ct_entry_24xx))); |
Andrew Vasquez | 9a853f7 | 2005-07-06 10:31:27 -0700 | [diff] [blame] | 1510 | |
| 1511 | /* Validate handle. */ |
| 1512 | if (pkt->handle < MAX_OUTSTANDING_COMMANDS) |
| 1513 | sp = ha->outstanding_cmds[pkt->handle]; |
| 1514 | else |
| 1515 | sp = NULL; |
| 1516 | |
| 1517 | if (sp == NULL) { |
| 1518 | DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n", |
| 1519 | ha->host_no)); |
| 1520 | DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n", |
| 1521 | ha->host_no)); |
| 1522 | qla_printk(KERN_WARNING, ha, "MS entry - invalid handle %d\n", |
| 1523 | pkt->handle); |
| 1524 | |
| 1525 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 1526 | return; |
| 1527 | } |
| 1528 | |
| 1529 | CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->comp_status); |
| 1530 | CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status; |
| 1531 | |
| 1532 | /* Free outstanding command slot. */ |
| 1533 | ha->outstanding_cmds[pkt->handle] = NULL; |
| 1534 | |
| 1535 | qla2x00_sp_compl(ha, sp); |
| 1536 | } |
| 1537 | |