blob: d04981848e561aed9e9c7853619f78c532d84174 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
8
Andrew Vasquez05236a02007-09-20 14:07:37 -07009#include <linux/delay.h>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070010#include <scsi/scsi_tcq.h>
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080013static void qla2x00_process_completed_request(struct scsi_qla_host *,
14 struct req_que *, uint32_t);
15static void qla2x00_status_entry(scsi_qla_host_t *, struct rsp_que *, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070016static void qla2x00_status_cont_entry(scsi_qla_host_t *, sts_cont_entry_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080017static void qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
18 sts_entry_t *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080019static struct scsi_qla_host *qla2x00_get_rsp_host(struct rsp_que *);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021/**
22 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
23 * @irq:
24 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 *
26 * Called by system whenever the host adapter generates an interrupt.
27 *
28 * Returns handled flag.
29 */
30irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +010031qla2100_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080033 scsi_qla_host_t *vha;
34 struct qla_hw_data *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -070035 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 unsigned long iter;
Seokmann Ju14e660e2007-09-20 14:07:36 -070038 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070039 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080040 struct rsp_que *rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080042 rsp = (struct rsp_que *) dev_id;
43 if (!rsp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080045 "%s(): NULL response queue pointer\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 return (IRQ_NONE);
47 }
48
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080049 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -070050 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 status = 0;
52
Andrew Vasquezc6952482008-04-03 13:13:17 -070053 spin_lock(&ha->hardware_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080054 vha = qla2x00_get_rsp_host(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 for (iter = 50; iter--; ) {
Seokmann Ju14e660e2007-09-20 14:07:36 -070056 hccr = RD_REG_WORD(&reg->hccr);
57 if (hccr & HCCR_RISC_PAUSE) {
58 if (pci_channel_offline(ha->pdev))
59 break;
60
61 /*
62 * Issue a "HARD" reset in order for the RISC interrupt
63 * bit to be cleared. Schedule a big hammmer to get
64 * out of the RISC PAUSED state.
65 */
66 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
67 RD_REG_WORD(&reg->hccr);
68
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080069 ha->isp_ops->fw_dump(vha, 1);
70 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -070071 break;
72 } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 break;
74
75 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
76 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
77 RD_REG_WORD(&reg->hccr);
78
79 /* Get mailbox data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -070080 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
81 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080082 qla2x00_mbx_completion(vha, mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 status |= MBX_INTERRUPT;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070084 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
85 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
86 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
87 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080088 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 } else {
90 /*EMPTY*/
91 DEBUG2(printk("scsi(%ld): Unrecognized "
Andrew Vasquez9a853f72005-07-06 10:31:27 -070092 "interrupt type (%d).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080093 vha->host_no, mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 }
95 /* Release mailbox registers. */
96 WRT_REG_WORD(&reg->semaphore, 0);
97 RD_REG_WORD(&reg->semaphore);
98 } else {
Anirban Chakraborty73208df2008-12-09 16:45:39 -080099 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
102 RD_REG_WORD(&reg->hccr);
103 }
104 }
Andrew Vasquezc6952482008-04-03 13:13:17 -0700105 spin_unlock(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
108 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800110 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 }
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 return (IRQ_HANDLED);
114}
115
116/**
117 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
118 * @irq:
119 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 *
121 * Called by system whenever the host adapter generates an interrupt.
122 *
123 * Returns handled flag.
124 */
125irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100126qla2300_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800128 scsi_qla_host_t *vha;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700129 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 unsigned long iter;
132 uint32_t stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700134 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800135 struct rsp_que *rsp;
136 struct qla_hw_data *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800138 rsp = (struct rsp_que *) dev_id;
139 if (!rsp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800141 "%s(): NULL response queue pointer\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 return (IRQ_NONE);
143 }
144
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800145 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700146 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 status = 0;
148
Andrew Vasquezc6952482008-04-03 13:13:17 -0700149 spin_lock(&ha->hardware_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800150 vha = qla2x00_get_rsp_host(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 for (iter = 50; iter--; ) {
152 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
153 if (stat & HSR_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -0700154 if (pci_channel_offline(ha->pdev))
155 break;
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 hccr = RD_REG_WORD(&reg->hccr);
158 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Andrew Vasquez07f31802006-12-13 19:20:31 -0800159 qla_printk(KERN_INFO, ha, "Parity error -- "
160 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 else
Andrew Vasquez07f31802006-12-13 19:20:31 -0800162 qla_printk(KERN_INFO, ha, "RISC paused -- "
163 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165 /*
166 * Issue a "HARD" reset in order for the RISC
167 * interrupt bit to be cleared. Schedule a big
168 * hammmer to get out of the RISC PAUSED state.
169 */
170 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
171 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800172
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800173 ha->isp_ops->fw_dump(vha, 1);
174 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 break;
176 } else if ((stat & HSR_RISC_INT) == 0)
177 break;
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 case 0x1:
181 case 0x2:
182 case 0x10:
183 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800184 qla2x00_mbx_completion(vha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 status |= MBX_INTERRUPT;
186
187 /* Release mailbox registers. */
188 WRT_REG_WORD(&reg->semaphore, 0);
189 break;
190 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700191 mb[0] = MSW(stat);
192 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
193 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
194 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800195 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700196 break;
197 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800198 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 break;
200 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700201 mb[0] = MBA_CMPLT_1_16BIT;
202 mb[1] = MSW(stat);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800203 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 break;
205 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700206 mb[0] = MBA_SCSI_COMPLETION;
207 mb[1] = MSW(stat);
208 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800209 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 break;
211 default:
212 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700213 "(%d).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800214 vha->host_no, stat & 0xff));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 break;
216 }
217 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
218 RD_REG_WORD_RELAXED(&reg->hccr);
219 }
Andrew Vasquezc6952482008-04-03 13:13:17 -0700220 spin_unlock(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
223 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800225 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 }
227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 return (IRQ_HANDLED);
229}
230
231/**
232 * qla2x00_mbx_completion() - Process mailbox command completions.
233 * @ha: SCSI driver HA context
234 * @mb0: Mailbox0 register
235 */
236static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800237qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238{
239 uint16_t cnt;
240 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800241 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700242 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244 /* Load return mailbox registers. */
245 ha->flags.mbox_int = 1;
246 ha->mailbox_out[0] = mb0;
247 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
248
249 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700250 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
252 if (cnt == 4 || cnt == 5)
253 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
254 else
255 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 wptr++;
258 }
259
260 if (ha->mcp) {
261 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800262 __func__, vha->host_no, ha->mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 } else {
264 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800265 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 }
267}
268
Andrew Vasquez8a659572009-02-08 20:50:12 -0800269static void
270qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
271{
272 static char *event[] =
273 { "Complete", "Request Notification", "Time Extension" };
274 int rval;
275 struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
276 uint16_t __iomem *wptr;
277 uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
278
279 /* Seed data -- mailbox1 -> mailbox7. */
280 wptr = (uint16_t __iomem *)&reg24->mailbox1;
281 for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
282 mb[cnt] = RD_REG_WORD(wptr);
283
284 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- "
285 "%04x %04x %04x %04x %04x %04x %04x.\n", vha->host_no,
286 event[aen & 0xff],
287 mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6]));
288
289 /* Acknowledgement needed? [Notify && non-zero timeout]. */
290 timeout = (descr >> 8) & 0xf;
291 if (aen != MBA_IDC_NOTIFY || !timeout)
292 return;
293
294 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- "
295 "ACK timeout=%d.\n", vha->host_no, event[aen & 0xff], timeout));
296
297 rval = qla2x00_post_idc_ack_work(vha, mb);
298 if (rval != QLA_SUCCESS)
299 qla_printk(KERN_WARNING, vha->hw,
300 "IDC failed to post ACK.\n");
301}
302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303/**
304 * qla2x00_async_event() - Process aynchronous events.
305 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700306 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700308void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800309qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700311#define LS_UNKNOWN 2
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800312 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 char *link_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 uint16_t handle_cnt;
315 uint16_t cnt;
316 uint32_t handles[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800317 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700318 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 uint32_t rscn_entry, host_pid;
320 uint8_t rscn_queue_index;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700321 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323 /* Setup to process RIO completion. */
324 handle_cnt = 0;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800325 if (IS_QLA81XX(ha))
326 goto skip_rio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 switch (mb[0]) {
328 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700329 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 handle_cnt = 1;
331 break;
332 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700333 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 handle_cnt = 1;
335 mb[0] = MBA_SCSI_COMPLETION;
336 break;
337 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700338 handles[0] = mb[1];
339 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 handle_cnt = 2;
341 mb[0] = MBA_SCSI_COMPLETION;
342 break;
343 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700344 handles[0] = mb[1];
345 handles[1] = mb[2];
346 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 handle_cnt = 3;
348 mb[0] = MBA_SCSI_COMPLETION;
349 break;
350 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700351 handles[0] = mb[1];
352 handles[1] = mb[2];
353 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
355 handle_cnt = 4;
356 mb[0] = MBA_SCSI_COMPLETION;
357 break;
358 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700359 handles[0] = mb[1];
360 handles[1] = mb[2];
361 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
363 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
364 handle_cnt = 5;
365 mb[0] = MBA_SCSI_COMPLETION;
366 break;
367 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700368 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 handles[1] = le32_to_cpu(
370 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
371 RD_MAILBOX_REG(ha, reg, 6));
372 handle_cnt = 2;
373 mb[0] = MBA_SCSI_COMPLETION;
374 break;
375 default:
376 break;
377 }
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800378skip_rio:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 switch (mb[0]) {
380 case MBA_SCSI_COMPLETION: /* Fast Post */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800381 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 break;
383
384 for (cnt = 0; cnt < handle_cnt; cnt++)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800385 qla2x00_process_completed_request(vha, rsp->req,
386 handles[cnt]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 break;
388
389 case MBA_RESET: /* Reset */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800390 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n",
391 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800393 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 break;
395
396 case MBA_SYSTEM_ERR: /* System Error */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 qla_printk(KERN_INFO, ha,
398 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
399 mb[1], mb[2], mb[3]);
400
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800401 ha->isp_ops->fw_dump(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Andrew Vasqueze4289242007-07-19 15:05:56 -0700403 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700404 if (mb[1] == 0 && mb[2] == 0) {
405 qla_printk(KERN_ERR, ha,
406 "Unrecoverable Hardware Error: adapter "
407 "marked OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800408 vha->flags.online = 0;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700409 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800410 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700411 } else if (mb[1] == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 qla_printk(KERN_INFO, ha,
413 "Unrecoverable Hardware Error: adapter marked "
414 "OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800415 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800417 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 break;
419
420 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
421 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800422 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
424
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800425 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 break;
427
428 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
429 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800430 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
432
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800433 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 break;
435
436 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
437 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800438 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 break;
440
441 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800442 DEBUG2(printk("scsi(%ld): LIP occurred (%x).\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 mb[1]));
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700444 qla_printk(KERN_INFO, ha, "LIP occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800446 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
447 atomic_set(&vha->loop_state, LOOP_DOWN);
448 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
449 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 }
451
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800452 if (vha->vp_idx) {
453 atomic_set(&vha->vp_state, VP_FAILED);
454 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700455 }
456
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800457 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
458 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800460 vha->flags.management_server_logged_in = 0;
461 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 break;
463
464 case MBA_LOOP_UP: /* Loop Up Event */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
466 link_speed = link_speeds[0];
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700467 ha->link_data_rate = PORT_SPEED_1GB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 } else {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700469 link_speed = link_speeds[LS_UNKNOWN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 if (mb[1] < 5)
471 link_speed = link_speeds[mb[1]];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800472 else if (mb[1] == 0x13)
473 link_speed = link_speeds[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 ha->link_data_rate = mb[1];
475 }
476
477 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800478 vha->host_no, link_speed));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
480 link_speed);
481
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800482 vha->flags.management_server_logged_in = 0;
483 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 break;
485
486 case MBA_LOOP_DOWN: /* Loop Down Event */
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700487 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800488 "(%x %x %x).\n", vha->host_no, mb[1], mb[2], mb[3]));
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700489 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x %x %x).\n",
490 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800492 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
493 atomic_set(&vha->loop_state, LOOP_DOWN);
494 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
495 vha->device_flags |= DFLG_NO_CABLE;
496 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 }
498
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800499 if (vha->vp_idx) {
500 atomic_set(&vha->vp_state, VP_FAILED);
501 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700502 }
503
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800504 vha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700505 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800506 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 break;
508
509 case MBA_LIP_RESET: /* LIP reset occurred */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800511 vha->host_no, mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 qla_printk(KERN_INFO, ha,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700513 "LIP reset occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800515 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
516 atomic_set(&vha->loop_state, LOOP_DOWN);
517 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
518 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 }
520
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800521 if (vha->vp_idx) {
522 atomic_set(&vha->vp_state, VP_FAILED);
523 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700524 }
525
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800526 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
528 ha->operating_mode = LOOP;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800529 vha->flags.management_server_logged_in = 0;
530 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 break;
532
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800533 /* case MBA_DCBX_COMPLETE: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 case MBA_POINT_TO_POINT: /* Point-to-Point */
535 if (IS_QLA2100(ha))
536 break;
537
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800538 if (IS_QLA81XX(ha))
539 DEBUG2(printk("scsi(%ld): DCBX Completed -- %04x %04x "
540 "%04x\n", vha->host_no, mb[1], mb[2], mb[3]));
541 else
542 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE "
543 "received.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
545 /*
546 * Until there's a transition from loop down to loop up, treat
547 * this as loop down only.
548 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800549 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
550 atomic_set(&vha->loop_state, LOOP_DOWN);
551 if (!atomic_read(&vha->loop_down_timer))
552 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800554 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 }
556
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800557 if (vha->vp_idx) {
558 atomic_set(&vha->vp_state, VP_FAILED);
559 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700560 }
561
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800562 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
563 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
564
565 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
566 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800567
568 ha->flags.gpsc_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800569 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 break;
571
572 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
573 if (IS_QLA2100(ha))
574 break;
575
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
577 "received.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800578 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 qla_printk(KERN_INFO, ha,
580 "Configuration change detected: value=%x.\n", mb[1]);
581
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800582 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
583 atomic_set(&vha->loop_state, LOOP_DOWN);
584 if (!atomic_read(&vha->loop_down_timer))
585 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800587 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 }
589
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800590 if (vha->vp_idx) {
591 atomic_set(&vha->vp_state, VP_FAILED);
592 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700593 }
594
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800595 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
596 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 break;
598
599 case MBA_PORT_UPDATE: /* Port database update */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800600 /* Only handle SCNs for our Vport index. */
601 if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff))
602 break;
603
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 /*
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700605 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 * event etc. earlier indicating loop is down) then process
607 * it. Otherwise ignore it and Wait for RSCN to come in.
608 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800609 atomic_set(&vha->loop_down_timer, 0);
610 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
611 atomic_read(&vha->loop_state) != LOOP_DEAD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800613 "ignored %04x/%04x/%04x.\n", vha->host_no, mb[1],
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700614 mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 break;
616 }
617
618 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800619 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 DEBUG(printk(KERN_INFO
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700621 "scsi(%ld): Port database changed %04x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800622 vha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
624 /*
625 * Mark all devices as missing so we will login again.
626 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800627 atomic_set(&vha->loop_state, LOOP_UP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800629 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800631 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800633 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
634 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 break;
636
637 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju3c397402008-05-19 14:25:39 -0700638 /* Check if the Vport has issued a SCR */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800639 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
Seokmann Ju3c397402008-05-19 14:25:39 -0700640 break;
641 /* Only handle SCNs for our Vport index. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800642 if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff))
Seokmann Ju3c397402008-05-19 14:25:39 -0700643 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800645 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 DEBUG(printk(KERN_INFO
Shyam Sundarf4a8dbc2007-11-12 10:30:59 -0800647 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800648 vha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Ravi Anand59d72d82008-09-11 21:22:53 -0700650 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800651 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
652 | vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 if (rscn_entry == host_pid) {
654 DEBUG(printk(KERN_INFO
655 "scsi(%ld): Ignoring RSCN update to local host "
656 "port ID (%06x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800657 vha->host_no, host_pid));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 break;
659 }
660
Ravi Anand59d72d82008-09-11 21:22:53 -0700661 /* Ignore reserved bits from RSCN-payload. */
662 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800663 rscn_queue_index = vha->rscn_in_ptr + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 if (rscn_queue_index == MAX_RSCN_COUNT)
665 rscn_queue_index = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800666 if (rscn_queue_index != vha->rscn_out_ptr) {
667 vha->rscn_queue[vha->rscn_in_ptr] = rscn_entry;
668 vha->rscn_in_ptr = rscn_queue_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800670 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 }
672
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800673 atomic_set(&vha->loop_state, LOOP_UPDATE);
674 atomic_set(&vha->loop_down_timer, 0);
675 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800677 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
678 set_bit(RSCN_UPDATE, &vha->dpc_flags);
679 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 break;
681
682 /* case MBA_RIO_RESPONSE: */
683 case MBA_ZIO_RESPONSE:
Andrew Vasquez3fd67cd2009-01-05 11:18:07 -0800684 DEBUG3(printk("scsi(%ld): [R|Z]IO update completion.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800685 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
Andrew Vasqueze4289242007-07-19 15:05:56 -0700687 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800688 qla24xx_process_response_queue(rsp);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700689 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800690 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700692
693 case MBA_DISCARD_RND_FRAME:
694 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800695 "%04x.\n", vha->host_no, mb[1], mb[2], mb[3]));
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700696 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700697
698 case MBA_TRACE_NOTIFICATION:
699 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800700 vha->host_no, mb[1], mb[2]));
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700701 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700702
703 case MBA_ISP84XX_ALERT:
704 DEBUG2(printk("scsi(%ld): ISP84XX Alert Notification -- "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800705 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700706
707 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
708 switch (mb[1]) {
709 case A84_PANIC_RECOVERY:
710 qla_printk(KERN_INFO, ha, "Alert 84XX: panic recovery "
711 "%04x %04x\n", mb[2], mb[3]);
712 break;
713 case A84_OP_LOGIN_COMPLETE:
714 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
715 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
716 "firmware version %x\n", ha->cs84xx->op_fw_version));
717 break;
718 case A84_DIAG_LOGIN_COMPLETE:
719 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
720 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
721 "diagnostic firmware version %x\n",
722 ha->cs84xx->diag_fw_version));
723 break;
724 case A84_GOLD_LOGIN_COMPLETE:
725 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
726 ha->cs84xx->fw_update = 1;
727 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX: gold "
728 "firmware version %x\n",
729 ha->cs84xx->gold_fw_version));
730 break;
731 default:
732 qla_printk(KERN_ERR, ha,
733 "Alert 84xx: Invalid Alert %04x %04x %04x\n",
734 mb[1], mb[2], mb[3]);
735 }
736 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
737 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800738 case MBA_DCBX_START:
739 DEBUG2(printk("scsi(%ld): DCBX Started -- %04x %04x %04x\n",
740 vha->host_no, mb[1], mb[2], mb[3]));
741 break;
742 case MBA_DCBX_PARAM_UPDATE:
743 DEBUG2(printk("scsi(%ld): DCBX Parameters Updated -- "
744 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
745 break;
746 case MBA_FCF_CONF_ERR:
747 DEBUG2(printk("scsi(%ld): FCF Configuration Error -- "
748 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
749 break;
750 case MBA_IDC_COMPLETE:
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800751 case MBA_IDC_NOTIFY:
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800752 case MBA_IDC_TIME_EXT:
Andrew Vasquez8a659572009-02-08 20:50:12 -0800753 qla81xx_idc_event(vha, mb[0], mb[1]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800754 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700756
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800757 if (!vha->vp_idx && ha->num_vhosts)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800758 qla2x00_alert_all_vps(rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759}
760
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700761static void
762qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
763{
764 fc_port_t *fcport = data;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800765 struct scsi_qla_host *vha = fcport->vha;
766 struct qla_hw_data *ha = vha->hw;
767 struct req_que *req = NULL;
768
769 req = ha->req_q_map[vha->req_ques[0]];
770 if (!req)
771 return;
772 if (req->max_q_depth <= sdev->queue_depth)
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700773 return;
774
775 if (sdev->ordered_tags)
776 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
777 sdev->queue_depth + 1);
778 else
779 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
780 sdev->queue_depth + 1);
781
782 fcport->last_ramp_up = jiffies;
783
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800784 DEBUG2(qla_printk(KERN_INFO, ha,
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700785 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800786 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700787 sdev->queue_depth));
788}
789
790static void
791qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
792{
793 fc_port_t *fcport = data;
794
795 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
796 return;
797
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800798 DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700799 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800800 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700801 sdev->queue_depth));
802}
803
804static inline void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800805qla2x00_ramp_up_queue_depth(scsi_qla_host_t *vha, struct req_que *req,
806 srb_t *sp)
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700807{
808 fc_port_t *fcport;
809 struct scsi_device *sdev;
810
811 sdev = sp->cmd->device;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800812 if (sdev->queue_depth >= req->max_q_depth)
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700813 return;
814
815 fcport = sp->fcport;
816 if (time_before(jiffies,
817 fcport->last_ramp_up + ql2xqfullrampup * HZ))
818 return;
819 if (time_before(jiffies,
820 fcport->last_queue_full + ql2xqfullrampup * HZ))
821 return;
822
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700823 starget_for_each_device(sdev->sdev_target, fcport,
824 qla2x00_adjust_sdev_qdepth_up);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700825}
826
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827/**
828 * qla2x00_process_completed_request() - Process a Fast Post response.
829 * @ha: SCSI driver HA context
830 * @index: SRB index
831 */
832static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800833qla2x00_process_completed_request(struct scsi_qla_host *vha,
834 struct req_que *req, uint32_t index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835{
836 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800837 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
839 /* Validate handle. */
840 if (index >= MAX_OUTSTANDING_COMMANDS) {
841 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800842 vha->host_no, index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 qla_printk(KERN_WARNING, ha,
844 "Invalid SCSI completion handle %d.\n", index);
845
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800846 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 return;
848 }
849
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800850 sp = req->outstanding_cmds[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 if (sp) {
852 /* Free outstanding command slot. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800853 req->outstanding_cmds[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 /* Save ISP completion status */
856 sp->cmd->result = DID_OK << 16;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700857
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800858 qla2x00_ramp_up_queue_depth(vha, req, sp);
859 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 } else {
861 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800862 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 qla_printk(KERN_WARNING, ha,
864 "Invalid ISP SCSI completion handle\n");
865
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800866 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 }
868}
869
870/**
871 * qla2x00_process_response_queue() - Process response queue entries.
872 * @ha: SCSI driver HA context
873 */
874void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800875qla2x00_process_response_queue(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876{
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800877 struct scsi_qla_host *vha;
878 struct qla_hw_data *ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700879 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 sts_entry_t *pkt;
881 uint16_t handle_cnt;
882 uint16_t cnt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800883
884 vha = qla2x00_get_rsp_host(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800886 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 return;
888
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800889 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
890 pkt = (sts_entry_t *)rsp->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800892 rsp->ring_index++;
893 if (rsp->ring_index == rsp->length) {
894 rsp->ring_index = 0;
895 rsp->ring_ptr = rsp->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800897 rsp->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 }
899
900 if (pkt->entry_status != 0) {
901 DEBUG3(printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800902 "scsi(%ld): Process error entry.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800904 qla2x00_error_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
906 wmb();
907 continue;
908 }
909
910 switch (pkt->entry_type) {
911 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800912 qla2x00_status_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 break;
914 case STATUS_TYPE_21:
915 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
916 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800917 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 ((sts21_entry_t *)pkt)->handle[cnt]);
919 }
920 break;
921 case STATUS_TYPE_22:
922 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
923 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800924 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 ((sts22_entry_t *)pkt)->handle[cnt]);
926 }
927 break;
928 case STATUS_CONT_TYPE:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800929 qla2x00_status_cont_entry(vha, (sts_cont_entry_t *)pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 default:
932 /* Type Not Supported. */
933 DEBUG4(printk(KERN_WARNING
934 "scsi(%ld): Received unknown response pkt type %x "
935 "entry status=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800936 vha->host_no, pkt->entry_type, pkt->entry_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 break;
938 }
939 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
940 wmb();
941 }
942
943 /* Adjust ring index */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800944 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945}
946
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800947static inline void
948qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len)
949{
950 struct scsi_cmnd *cp = sp->cmd;
951
952 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
953 sense_len = SCSI_SENSE_BUFFERSIZE;
954
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800955 sp->request_sense_length = sense_len;
956 sp->request_sense_ptr = cp->sense_buffer;
957 if (sp->request_sense_length > 32)
958 sense_len = 32;
959
960 memcpy(cp->sense_buffer, sense_data, sense_len);
961
962 sp->request_sense_ptr += sense_len;
963 sp->request_sense_length -= sense_len;
964 if (sp->request_sense_length != 0)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800965 sp->fcport->vha->status_srb = sp;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800966
967 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800968 "cmd=%p pid=%ld\n", __func__, sp->fcport->vha->host_no,
Andrew Vasquez19851f12008-08-13 21:37:00 -0700969 cp->device->channel, cp->device->id, cp->device->lun, cp,
970 cp->serial_number));
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800971 if (sense_len)
Shyam Sundarddb9b122009-03-24 09:08:10 -0700972 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer, sense_len));
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800973}
974
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975/**
976 * qla2x00_status_entry() - Process a Status IOCB entry.
977 * @ha: SCSI driver HA context
978 * @pkt: Entry pointer
979 */
980static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800981qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 fc_port_t *fcport;
985 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700986 sts_entry_t *sts;
987 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 uint16_t comp_status;
989 uint16_t scsi_status;
990 uint8_t lscsi_status;
991 int32_t resid;
Ravi Ananded17c71b52006-05-17 15:08:55 -0700992 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700993 uint8_t *rsp_info, *sense_data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800994 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800995 struct req_que *req = rsp->req;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700996
997 sts = (sts_entry_t *) pkt;
998 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700999 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001000 comp_status = le16_to_cpu(sts24->comp_status);
1001 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
1002 } else {
1003 comp_status = le16_to_cpu(sts->comp_status);
1004 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1005 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
1007 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001008 if (comp_status == CS_COMPLETE && scsi_status == 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001009 qla2x00_process_completed_request(vha, req, sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
1011 return;
1012 }
1013
1014 /* Validate handle. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001015 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001016 sp = req->outstanding_cmds[sts->handle];
1017 req->outstanding_cmds[sts->handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 } else
1019 sp = NULL;
1020
1021 if (sp == NULL) {
1022 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001023 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
1025
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001026 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1027 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 return;
1029 }
1030 cp = sp->cmd;
1031 if (cp == NULL) {
1032 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001033 "pkt->handle=%d sp=%p.\n", vha->host_no, sts->handle, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 qla_printk(KERN_WARNING, ha,
1035 "Command is NULL: already returned to OS (sp=%p)\n", sp);
1036
1037 return;
1038 }
1039
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001040 lscsi_status = scsi_status & STATUS_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
bdf79622005-04-17 15:06:53 -05001042 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
Ravi Ananded17c71b52006-05-17 15:08:55 -07001044 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001045 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001046 sense_len = le32_to_cpu(sts24->sense_len);
1047 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
1048 resid_len = le32_to_cpu(sts24->rsp_residual_count);
Ravi Ananded17c71b52006-05-17 15:08:55 -07001049 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001050 rsp_info = sts24->data;
1051 sense_data = sts24->data;
1052 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
1053 } else {
1054 sense_len = le16_to_cpu(sts->req_sense_length);
1055 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
1056 resid_len = le32_to_cpu(sts->residual_length);
1057 rsp_info = sts->rsp_info;
1058 sense_data = sts->req_sense_data;
1059 }
1060
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 /* Check for any FCP transport errors. */
1062 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001063 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001064 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001065 sense_data += rsp_info_len;
1066 if (rsp_info_len > 3 && rsp_info[3]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
1068 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001069 "retrying command\n", vha->host_no,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001070 cp->device->channel, cp->device->id,
1071 cp->device->lun, rsp_info_len, rsp_info[0],
1072 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
1073 rsp_info[5], rsp_info[6], rsp_info[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
1075 cp->result = DID_BUS_BUSY << 16;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001076 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 return;
1078 }
1079 }
1080
Andrew Vasquez3e8ce322008-02-28 14:06:10 -08001081 /* Check for overrun. */
1082 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
1083 scsi_status & SS_RESIDUAL_OVER)
1084 comp_status = CS_DATA_OVERRUN;
1085
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 /*
1087 * Based on Host and scsi status generate status code for Linux
1088 */
1089 switch (comp_status) {
1090 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001091 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 if (scsi_status == 0) {
1093 cp->result = DID_OK << 16;
1094 break;
1095 }
1096 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001097 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001098 scsi_set_resid(cp, resid);
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001099
1100 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001101 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001102 cp->underflow)) {
1103 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001104 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1105 "detected (%x of %x bytes)...returning "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001106 "error status.\n", vha->host_no,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001107 cp->device->channel, cp->device->id,
1108 cp->device->lun, resid,
1109 scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001110
1111 cp->result = DID_ERROR << 16;
1112 break;
1113 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 cp->result = DID_OK << 16 | lscsi_status;
1116
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001117 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1118 DEBUG2(printk(KERN_INFO
1119 "scsi(%ld): QUEUE FULL status detected "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001120 "0x%x-0x%x.\n", vha->host_no, comp_status,
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001121 scsi_status));
1122
1123 /* Adjust queue depth for all luns on the port. */
1124 fcport->last_queue_full = jiffies;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001125 starget_for_each_device(cp->device->sdev_target,
1126 fcport, qla2x00_adjust_sdev_qdepth_down);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001127 break;
1128 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 if (lscsi_status != SS_CHECK_CONDITION)
1130 break;
1131
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001132 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 if (!(scsi_status & SS_SENSE_LEN_VALID))
1134 break;
1135
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001136 qla2x00_handle_sense(sp, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 break;
1138
1139 case CS_DATA_UNDERRUN:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001140 resid = resid_len;
Ravi Ananded17c71b52006-05-17 15:08:55 -07001141 /* Use F/W calculated residual length. */
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001142 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez2d136932008-09-11 21:22:52 -07001143 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1144 lscsi_status = 0;
1145 } else if (resid != fw_resid_len) {
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001146 scsi_status &= ~SS_RESIDUAL_UNDER;
1147 lscsi_status = 0;
1148 }
Ravi Ananded17c71b52006-05-17 15:08:55 -07001149 resid = fw_resid_len;
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001150 }
Ravi Ananded17c71b52006-05-17 15:08:55 -07001151
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 if (scsi_status & SS_RESIDUAL_UNDER) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001153 scsi_set_resid(cp, resid);
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -08001154 } else {
1155 DEBUG2(printk(KERN_INFO
1156 "scsi(%ld:%d:%d) UNDERRUN status detected "
Ravi Ananded17c71b52006-05-17 15:08:55 -07001157 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001158 "os_underflow=0x%x\n", vha->host_no,
Ravi Ananded17c71b52006-05-17 15:08:55 -07001159 cp->device->id, cp->device->lun, comp_status,
1160 scsi_status, resid_len, resid, cp->cmnd[0],
1161 cp->underflow));
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -08001162
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 }
1164
1165 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001166 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 * Status.
1168 */
1169 if (lscsi_status != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 cp->result = DID_OK << 16 | lscsi_status;
1171
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001172 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1173 DEBUG2(printk(KERN_INFO
1174 "scsi(%ld): QUEUE FULL status detected "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001175 "0x%x-0x%x.\n", vha->host_no, comp_status,
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001176 scsi_status));
1177
1178 /*
1179 * Adjust queue depth for all luns on the
1180 * port.
1181 */
1182 fcport->last_queue_full = jiffies;
1183 starget_for_each_device(
1184 cp->device->sdev_target, fcport,
1185 qla2x00_adjust_sdev_qdepth_down);
1186 break;
1187 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 if (lscsi_status != SS_CHECK_CONDITION)
1189 break;
1190
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001191 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 if (!(scsi_status & SS_SENSE_LEN_VALID))
1193 break;
1194
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001195 qla2x00_handle_sense(sp, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 } else {
1197 /*
1198 * If RISC reports underrun and target does not report
1199 * it then we must have a lost frame, so tell upper
1200 * layer to retry it by reporting a bus busy.
1201 */
1202 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1203 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001204 "frame(s) detected (%x of %x bytes)..."
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001205 "retrying command.\n",
1206 vha->host_no, cp->device->channel,
1207 cp->device->id, cp->device->lun, resid,
1208 scsi_bufflen(cp)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
1210 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 break;
1212 }
1213
1214 /* Handle mid-layer underflow */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001215 if ((unsigned)(scsi_bufflen(cp) - resid) <
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 cp->underflow) {
1217 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001218 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1219 "detected (%x of %x bytes)...returning "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001220 "error status.\n", vha->host_no,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001221 cp->device->channel, cp->device->id,
1222 cp->device->lun, resid,
1223 scsi_bufflen(cp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
1225 cp->result = DID_ERROR << 16;
1226 break;
1227 }
1228
1229 /* Everybody online, looking good... */
1230 cp->result = DID_OK << 16;
1231 }
1232 break;
1233
1234 case CS_DATA_OVERRUN:
1235 DEBUG2(printk(KERN_INFO
1236 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001237 vha->host_no, cp->device->id, cp->device->lun, comp_status,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001238 scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 DEBUG2(printk(KERN_INFO
1240 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1241 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1242 cp->cmnd[4], cp->cmnd[5]));
1243 DEBUG2(printk(KERN_INFO
1244 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1245 "status!\n",
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001246 cp->serial_number, scsi_bufflen(cp), resid_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
1248 cp->result = DID_ERROR << 16;
1249 break;
1250
1251 case CS_PORT_LOGGED_OUT:
1252 case CS_PORT_CONFIG_CHG:
1253 case CS_PORT_BUSY:
1254 case CS_INCOMPLETE:
1255 case CS_PORT_UNAVAILABLE:
1256 /*
1257 * If the port is in Target Down state, return all IOs for this
1258 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1259 * retry_queue.
1260 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1262 "pid=%ld, compl status=0x%x, port state=0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001263 vha->host_no, cp->device->id, cp->device->lun,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001264 cp->serial_number, comp_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 atomic_read(&fcport->state)));
1266
Mike Christie056a4482008-08-19 18:45:29 -05001267 /*
1268 * We are going to have the fc class block the rport
1269 * while we try to recover so instruct the mid layer
1270 * to requeue until the class decides how to handle this.
1271 */
1272 cp->result = DID_TRANSPORT_DISRUPTED << 16;
Andrew Vasqueza7a28502008-08-13 21:36:57 -07001273 if (atomic_read(&fcport->state) == FCS_ONLINE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001274 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 break;
1276
1277 case CS_RESET:
1278 DEBUG2(printk(KERN_INFO
1279 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001280 vha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
f4f051e2005-04-17 15:02:26 -05001282 cp->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 break;
1284
1285 case CS_ABORTED:
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001286 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 * hv2.19.12 - DID_ABORT does not retry the request if we
1288 * aborted this request then abort otherwise it must be a
1289 * reset.
1290 */
1291 DEBUG2(printk(KERN_INFO
1292 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001293 vha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
1295 cp->result = DID_RESET << 16;
1296 break;
1297
1298 case CS_TIMEOUT:
Mike Christie056a4482008-08-19 18:45:29 -05001299 /*
1300 * We are going to have the fc class block the rport
1301 * while we try to recover so instruct the mid layer
1302 * to requeue until the class decides how to handle this.
1303 */
1304 cp->result = DID_TRANSPORT_DISRUPTED << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
Andrew Vasqueze4289242007-07-19 15:05:56 -07001306 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001307 DEBUG2(printk(KERN_INFO
1308 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001309 "0x%x-0x%x\n", vha->host_no, cp->device->channel,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001310 cp->device->id, cp->device->lun, comp_status,
1311 scsi_status));
1312 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001314 DEBUG2(printk(KERN_INFO
1315 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001316 "sflags=%x.\n", vha->host_no, cp->device->channel,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001317 cp->device->id, cp->device->lun, comp_status, scsi_status,
1318 le16_to_cpu(sts->status_flags)));
1319
1320 /* Check to see if logout occurred. */
1321 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001322 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 break;
1324
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 default:
1326 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001327 "0x%x-0x%x.\n", vha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 qla_printk(KERN_INFO, ha,
1329 "Unknown status detected 0x%x-0x%x.\n",
1330 comp_status, scsi_status);
1331
1332 cp->result = DID_ERROR << 16;
1333 break;
1334 }
1335
1336 /* Place command on done queue. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001337 if (vha->status_srb == NULL)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001338 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339}
1340
1341/**
1342 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1343 * @ha: SCSI driver HA context
1344 * @pkt: Entry pointer
1345 *
1346 * Extended sense data.
1347 */
1348static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001349qla2x00_status_cont_entry(scsi_qla_host_t *vha, sts_cont_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350{
1351 uint8_t sense_sz = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001352 struct qla_hw_data *ha = vha->hw;
1353 srb_t *sp = vha->status_srb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 struct scsi_cmnd *cp;
1355
1356 if (sp != NULL && sp->request_sense_length != 0) {
1357 cp = sp->cmd;
1358 if (cp == NULL) {
1359 DEBUG2(printk("%s(): Cmd already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001360 "sp=%p.\n", __func__, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 qla_printk(KERN_INFO, ha,
1362 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001363 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001365 vha->status_srb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 return;
1367 }
1368
1369 if (sp->request_sense_length > sizeof(pkt->data)) {
1370 sense_sz = sizeof(pkt->data);
1371 } else {
1372 sense_sz = sp->request_sense_length;
1373 }
1374
1375 /* Move sense data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001376 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001377 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1379 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1380
1381 sp->request_sense_ptr += sense_sz;
1382 sp->request_sense_length -= sense_sz;
1383
1384 /* Place command on done queue. */
1385 if (sp->request_sense_length == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001386 vha->status_srb = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001387 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 }
1389 }
1390}
1391
1392/**
1393 * qla2x00_error_entry() - Process an error entry.
1394 * @ha: SCSI driver HA context
1395 * @pkt: Entry pointer
1396 */
1397static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001398qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399{
1400 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001401 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001402 struct req_que *req = rsp->req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403#if defined(QL_DEBUG_LEVEL_2)
1404 if (pkt->entry_status & RF_INV_E_ORDER)
1405 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1406 else if (pkt->entry_status & RF_INV_E_COUNT)
1407 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1408 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001409 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 "%s: Invalid Entry Parameter\n", __func__);
1411 else if (pkt->entry_status & RF_INV_E_TYPE)
1412 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1413 else if (pkt->entry_status & RF_BUSY)
1414 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1415 else
1416 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1417#endif
1418
1419 /* Validate handle. */
1420 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001421 sp = req->outstanding_cmds[pkt->handle];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 else
1423 sp = NULL;
1424
1425 if (sp) {
1426 /* Free outstanding command slot. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001427 req->outstanding_cmds[pkt->handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001428
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 /* Bad payload or header */
1430 if (pkt->entry_status &
1431 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1432 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1433 sp->cmd->result = DID_ERROR << 16;
1434 } else if (pkt->entry_status & RF_BUSY) {
1435 sp->cmd->result = DID_BUS_BUSY << 16;
1436 } else {
1437 sp->cmd->result = DID_ERROR << 16;
1438 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001439 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001441 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1442 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001444 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 qla_printk(KERN_WARNING, ha,
1446 "Error entry - invalid handle\n");
1447
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001448 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1449 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 }
1451}
1452
1453/**
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001454 * qla24xx_mbx_completion() - Process mailbox command completions.
1455 * @ha: SCSI driver HA context
1456 * @mb0: Mailbox0 register
1457 */
1458static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001459qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001460{
1461 uint16_t cnt;
1462 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001463 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001464 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1465
1466 /* Load return mailbox registers. */
1467 ha->flags.mbox_int = 1;
1468 ha->mailbox_out[0] = mb0;
1469 wptr = (uint16_t __iomem *)&reg->mailbox1;
1470
1471 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1472 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1473 wptr++;
1474 }
1475
1476 if (ha->mcp) {
1477 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001478 __func__, vha->host_no, ha->mcp->mb[0]));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001479 } else {
1480 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001481 __func__, vha->host_no));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001482 }
1483}
1484
1485/**
1486 * qla24xx_process_response_queue() - Process response queue entries.
1487 * @ha: SCSI driver HA context
1488 */
1489void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001490qla24xx_process_response_queue(struct rsp_que *rsp)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001491{
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001492 struct sts_entry_24xx *pkt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001493 struct scsi_qla_host *vha;
1494
1495 vha = qla2x00_get_rsp_host(rsp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001496
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001497 if (!vha->flags.online)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001498 return;
1499
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001500 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1501 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001502
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001503 rsp->ring_index++;
1504 if (rsp->ring_index == rsp->length) {
1505 rsp->ring_index = 0;
1506 rsp->ring_ptr = rsp->ring;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001507 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001508 rsp->ring_ptr++;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001509 }
1510
1511 if (pkt->entry_status != 0) {
1512 DEBUG3(printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001513 "scsi(%ld): Process error entry.\n", vha->host_no));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001514
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001515 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001516 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1517 wmb();
1518 continue;
1519 }
1520
1521 switch (pkt->entry_type) {
1522 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001523 qla2x00_status_entry(vha, rsp, pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001524 break;
1525 case STATUS_CONT_TYPE:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001526 qla2x00_status_cont_entry(vha, (sts_cont_entry_t *)pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001527 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001528 case VP_RPT_ID_IOCB_TYPE:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001529 qla24xx_report_id_acquisition(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001530 (struct vp_rpt_id_entry_24xx *)pkt);
1531 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001532 default:
1533 /* Type Not Supported. */
1534 DEBUG4(printk(KERN_WARNING
1535 "scsi(%ld): Received unknown response pkt type %x "
1536 "entry status=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001537 vha->host_no, pkt->entry_type, pkt->entry_status));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001538 break;
1539 }
1540 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1541 wmb();
1542 }
1543
1544 /* Adjust ring index */
Andrew Vasquez08029992009-03-24 09:07:55 -07001545 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001546}
1547
Andrew Vasquez05236a02007-09-20 14:07:37 -07001548static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001549qla2xxx_check_risc_status(scsi_qla_host_t *vha)
Andrew Vasquez05236a02007-09-20 14:07:37 -07001550{
1551 int rval;
1552 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001553 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez05236a02007-09-20 14:07:37 -07001554 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1555
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001556 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez05236a02007-09-20 14:07:37 -07001557 return;
1558
1559 rval = QLA_SUCCESS;
1560 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1561 RD_REG_DWORD(&reg->iobase_addr);
1562 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1563 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1564 rval == QLA_SUCCESS; cnt--) {
1565 if (cnt) {
1566 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1567 udelay(10);
1568 } else
1569 rval = QLA_FUNCTION_TIMEOUT;
1570 }
1571 if (rval == QLA_SUCCESS)
1572 goto next_test;
1573
1574 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1575 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1576 rval == QLA_SUCCESS; cnt--) {
1577 if (cnt) {
1578 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1579 udelay(10);
1580 } else
1581 rval = QLA_FUNCTION_TIMEOUT;
1582 }
1583 if (rval != QLA_SUCCESS)
1584 goto done;
1585
1586next_test:
1587 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
1588 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1589
1590done:
1591 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
1592 RD_REG_DWORD(&reg->iobase_window);
1593}
1594
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001595/**
1596 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1597 * @irq:
1598 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001599 *
1600 * Called by system whenever the host adapter generates an interrupt.
1601 *
1602 * Returns handled flag.
1603 */
1604irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001605qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001606{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001607 scsi_qla_host_t *vha;
1608 struct qla_hw_data *ha;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001609 struct device_reg_24xx __iomem *reg;
1610 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001611 unsigned long iter;
1612 uint32_t stat;
1613 uint32_t hccr;
1614 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001615 struct rsp_que *rsp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001616
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001617 rsp = (struct rsp_que *) dev_id;
1618 if (!rsp) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001619 printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001620 "%s(): NULL response queue pointer\n", __func__);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001621 return IRQ_NONE;
1622 }
1623
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001624 ha = rsp->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001625 reg = &ha->iobase->isp24;
1626 status = 0;
1627
Andrew Vasquezc6952482008-04-03 13:13:17 -07001628 spin_lock(&ha->hardware_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001629 vha = qla2x00_get_rsp_host(rsp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001630 for (iter = 50; iter--; ) {
1631 stat = RD_REG_DWORD(&reg->host_status);
1632 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001633 if (pci_channel_offline(ha->pdev))
1634 break;
1635
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001636 hccr = RD_REG_DWORD(&reg->hccr);
1637
1638 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1639 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001640
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001641 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001642
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001643 ha->isp_ops->fw_dump(vha, 1);
1644 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001645 break;
1646 } else if ((stat & HSRX_RISC_INT) == 0)
1647 break;
1648
1649 switch (stat & 0xff) {
1650 case 0x1:
1651 case 0x2:
1652 case 0x10:
1653 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001654 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001655 status |= MBX_INTERRUPT;
1656
1657 break;
1658 case 0x12:
1659 mb[0] = MSW(stat);
1660 mb[1] = RD_REG_WORD(&reg->mailbox1);
1661 mb[2] = RD_REG_WORD(&reg->mailbox2);
1662 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001663 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001664 break;
1665 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001666 case 0x14:
1667 qla24xx_process_response_queue(rsp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001668 break;
1669 default:
1670 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1671 "(%d).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001672 vha->host_no, stat & 0xff));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001673 break;
1674 }
1675 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1676 RD_REG_DWORD_RELAXED(&reg->hccr);
1677 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07001678 spin_unlock(&ha->hardware_lock);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001679
1680 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1681 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001682 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001683 complete(&ha->mbx_intr_comp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001684 }
1685
1686 return IRQ_HANDLED;
1687}
1688
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001689static irqreturn_t
1690qla24xx_msix_rsp_q(int irq, void *dev_id)
1691{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001692 struct qla_hw_data *ha;
1693 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001694 struct device_reg_24xx __iomem *reg;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001695
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001696 rsp = (struct rsp_que *) dev_id;
1697 if (!rsp) {
1698 printk(KERN_INFO
1699 "%s(): NULL response queue pointer\n", __func__);
1700 return IRQ_NONE;
1701 }
1702 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001703 reg = &ha->iobase->isp24;
1704
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001705 spin_lock_irq(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001706
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001707 qla24xx_process_response_queue(rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001708 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001709
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001710 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001711
1712 return IRQ_HANDLED;
1713}
1714
1715static irqreturn_t
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001716qla25xx_msix_rsp_q(int irq, void *dev_id)
1717{
1718 struct qla_hw_data *ha;
1719 struct rsp_que *rsp;
1720 struct device_reg_24xx __iomem *reg;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001721
1722 rsp = (struct rsp_que *) dev_id;
1723 if (!rsp) {
1724 printk(KERN_INFO
1725 "%s(): NULL response queue pointer\n", __func__);
1726 return IRQ_NONE;
1727 }
1728 ha = rsp->hw;
1729 reg = &ha->iobase->isp24;
1730
1731 spin_lock_irq(&ha->hardware_lock);
1732
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001733 qla24xx_process_response_queue(rsp);
1734
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001735 spin_unlock_irq(&ha->hardware_lock);
1736
1737 return IRQ_HANDLED;
1738}
1739
1740static irqreturn_t
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001741qla24xx_msix_default(int irq, void *dev_id)
1742{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001743 scsi_qla_host_t *vha;
1744 struct qla_hw_data *ha;
1745 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001746 struct device_reg_24xx __iomem *reg;
1747 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001748 uint32_t stat;
1749 uint32_t hccr;
1750 uint16_t mb[4];
1751
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001752 rsp = (struct rsp_que *) dev_id;
1753 if (!rsp) {
1754 DEBUG(printk(
1755 "%s(): NULL response queue pointer\n", __func__));
1756 return IRQ_NONE;
1757 }
1758 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001759 reg = &ha->iobase->isp24;
1760 status = 0;
1761
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001762 spin_lock_irq(&ha->hardware_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001763 vha = qla2x00_get_rsp_host(rsp);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001764 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001765 stat = RD_REG_DWORD(&reg->host_status);
1766 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001767 if (pci_channel_offline(ha->pdev))
1768 break;
1769
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001770 hccr = RD_REG_DWORD(&reg->hccr);
1771
1772 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1773 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001774
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001775 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001776
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001777 ha->isp_ops->fw_dump(vha, 1);
1778 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001779 break;
1780 } else if ((stat & HSRX_RISC_INT) == 0)
1781 break;
1782
1783 switch (stat & 0xff) {
1784 case 0x1:
1785 case 0x2:
1786 case 0x10:
1787 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001788 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001789 status |= MBX_INTERRUPT;
1790
1791 break;
1792 case 0x12:
1793 mb[0] = MSW(stat);
1794 mb[1] = RD_REG_WORD(&reg->mailbox1);
1795 mb[2] = RD_REG_WORD(&reg->mailbox2);
1796 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001797 qla2x00_async_event(vha, rsp, mb);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001798 break;
1799 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001800 case 0x14:
1801 qla24xx_process_response_queue(rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001802 break;
1803 default:
1804 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1805 "(%d).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001806 vha->host_no, stat & 0xff));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001807 break;
1808 }
1809 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001810 } while (0);
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001811 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001812
1813 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1814 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001815 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001816 complete(&ha->mbx_intr_comp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001817 }
1818
1819 return IRQ_HANDLED;
1820}
1821
1822/* Interrupt handling helpers. */
1823
1824struct qla_init_msix_entry {
1825 uint16_t entry;
1826 uint16_t index;
1827 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07001828 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001829};
1830
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001831static struct qla_init_msix_entry base_queue = {
1832 .entry = 0,
1833 .index = 0,
1834 .name = "qla2xxx (default)",
1835 .handler = qla24xx_msix_default,
1836};
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001837
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001838static struct qla_init_msix_entry base_rsp_queue = {
1839 .entry = 1,
1840 .index = 1,
1841 .name = "qla2xxx (rsp_q)",
1842 .handler = qla24xx_msix_rsp_q,
1843};
1844
1845static struct qla_init_msix_entry multi_rsp_queue = {
1846 .entry = 1,
1847 .index = 1,
1848 .name = "qla2xxx (multi_q)",
1849 .handler = qla25xx_msix_rsp_q,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001850};
1851
1852static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001853qla24xx_disable_msix(struct qla_hw_data *ha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001854{
1855 int i;
1856 struct qla_msix_entry *qentry;
1857
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001858 for (i = 0; i < ha->msix_count; i++) {
1859 qentry = &ha->msix_entries[i];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001860 if (qentry->have_irq)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001861 free_irq(qentry->vector, qentry->rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001862 }
1863 pci_disable_msix(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001864 kfree(ha->msix_entries);
1865 ha->msix_entries = NULL;
1866 ha->flags.msix_enabled = 0;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001867}
1868
1869static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001870qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001871{
Lalit Chandivadead038fa2009-01-22 09:45:33 -08001872#define MIN_MSIX_COUNT 2
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001873 int i, ret;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001874 struct msix_entry *entries;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001875 struct qla_msix_entry *qentry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001876 struct qla_init_msix_entry *msix_queue;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001877
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001878 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
1879 GFP_KERNEL);
1880 if (!entries)
1881 return -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001882
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001883 for (i = 0; i < ha->msix_count; i++)
1884 entries[i].entry = i;
1885
1886 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001887 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08001888 if (ret < MIN_MSIX_COUNT)
1889 goto msix_failed;
1890
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001891 qla_printk(KERN_WARNING, ha,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001892 "MSI-X: Failed to enable support -- %d/%d\n"
1893 " Retry with %d vectors\n", ha->msix_count, ret, ret);
1894 ha->msix_count = ret;
1895 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
1896 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08001897msix_failed:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001898 qla_printk(KERN_WARNING, ha, "MSI-X: Failed to enable"
1899 " support, giving up -- %d/%d\n",
1900 ha->msix_count, ret);
1901 goto msix_out;
1902 }
1903 ha->max_queues = ha->msix_count - 1;
1904 }
1905 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
1906 ha->msix_count, GFP_KERNEL);
1907 if (!ha->msix_entries) {
1908 ret = -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001909 goto msix_out;
1910 }
1911 ha->flags.msix_enabled = 1;
1912
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001913 for (i = 0; i < ha->msix_count; i++) {
1914 qentry = &ha->msix_entries[i];
1915 qentry->vector = entries[i].vector;
1916 qentry->entry = entries[i].entry;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001917 qentry->have_irq = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001918 qentry->rsp = NULL;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001919 }
1920
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001921 /* Enable MSI-X for AENs for queue 0 */
1922 qentry = &ha->msix_entries[0];
1923 ret = request_irq(qentry->vector, base_queue.handler, 0,
1924 base_queue.name, rsp);
1925 if (ret) {
1926 qla_printk(KERN_WARNING, ha,
1927 "MSI-X: Unable to register handler -- %x/%d.\n",
1928 qentry->vector, ret);
1929 qla24xx_disable_msix(ha);
1930 goto msix_out;
1931 }
1932 qentry->have_irq = 1;
1933 qentry->rsp = rsp;
1934
1935 /* Enable MSI-X vector for response queue update for queue 0 */
1936 if (ha->max_queues > 1 && ha->mqiobase) {
1937 ha->mqenable = 1;
1938 msix_queue = &multi_rsp_queue;
1939 qla_printk(KERN_INFO, ha,
1940 "MQ enabled, Number of Queue Resources: %d \n",
1941 ha->max_queues);
1942 } else {
1943 ha->mqenable = 0;
1944 msix_queue = &base_rsp_queue;
1945 }
1946
1947 qentry = &ha->msix_entries[1];
1948 ret = request_irq(qentry->vector, msix_queue->handler, 0,
1949 msix_queue->name, rsp);
1950 if (ret) {
1951 qla_printk(KERN_WARNING, ha,
1952 "MSI-X: Unable to register handler -- %x/%d.\n",
1953 qentry->vector, ret);
1954 qla24xx_disable_msix(ha);
1955 ha->mqenable = 0;
1956 goto msix_out;
1957 }
1958 qentry->have_irq = 1;
1959 qentry->rsp = rsp;
1960
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001961msix_out:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001962 kfree(entries);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001963 return ret;
1964}
1965
1966int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001967qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001968{
1969 int ret;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001970 device_reg_t __iomem *reg = ha->iobase;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001971
1972 /* If possible, enable MSI-X. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001973 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) &&
1974 !IS_QLA8432(ha) && !IS_QLA8001(ha))
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001975 goto skip_msix;
1976
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001977 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX ||
1978 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001979 DEBUG2(qla_printk(KERN_WARNING, ha,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001980 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1981 ha->pdev->revision, ha->fw_attributes));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001982
1983 goto skip_msix;
1984 }
1985
Andrew Vasquezda7429f2008-01-17 09:02:11 -08001986 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
1987 (ha->pdev->subsystem_device == 0x7040 ||
1988 ha->pdev->subsystem_device == 0x7041 ||
1989 ha->pdev->subsystem_device == 0x1705)) {
1990 DEBUG2(qla_printk(KERN_WARNING, ha,
1991 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
1992 ha->pdev->subsystem_vendor,
1993 ha->pdev->subsystem_device));
1994
1995 goto skip_msi;
1996 }
1997
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001998 ret = qla24xx_enable_msix(ha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001999 if (!ret) {
2000 DEBUG2(qla_printk(KERN_INFO, ha,
2001 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
2002 ha->fw_attributes));
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002003 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002004 }
2005 qla_printk(KERN_WARNING, ha,
2006 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
2007skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002008
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002009 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
2010 !IS_QLA8001(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002011 goto skip_msi;
2012
2013 ret = pci_enable_msi(ha->pdev);
2014 if (!ret) {
2015 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
2016 ha->flags.msi_enabled = 1;
2017 }
2018skip_msi:
2019
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002020 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Giridhar Malavalid1b1bef2009-03-24 09:08:13 -07002021 IRQF_SHARED, QLA2XXX_DRIVER_NAME, rsp);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002022 if (ret) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002023 qla_printk(KERN_WARNING, ha,
2024 "Failed to reserve interrupt %d already in use.\n",
2025 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002026 goto fail;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002027 }
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002028 ha->flags.inta_enabled = 1;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002029clear_risc_ints:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002030
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002031 /*
2032 * FIXME: Noted that 8014s were being dropped during NK testing.
2033 * Timing deltas during MSI-X/INTa transitions?
2034 */
2035 if (IS_QLA81XX(ha))
2036 goto fail;
Andrew Vasquezc6952482008-04-03 13:13:17 -07002037 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002038 if (IS_FWI2_CAPABLE(ha)) {
2039 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
2040 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
2041 } else {
2042 WRT_REG_WORD(&reg->isp.semaphore, 0);
2043 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
2044 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
2045 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07002046 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002047
2048fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002049 return ret;
2050}
2051
2052void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002053qla2x00_free_irqs(scsi_qla_host_t *vha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002054{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002055 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002056 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002057
2058 if (ha->flags.msix_enabled)
2059 qla24xx_disable_msix(ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002060 else if (ha->flags.inta_enabled) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002061 free_irq(ha->pdev->irq, rsp);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002062 pci_disable_msi(ha->pdev);
2063 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002064}
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002065
2066static struct scsi_qla_host *
2067qla2x00_get_rsp_host(struct rsp_que *rsp)
2068{
2069 srb_t *sp;
2070 struct qla_hw_data *ha = rsp->hw;
2071 struct scsi_qla_host *vha = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002072 struct sts_entry_24xx *pkt;
2073 struct req_que *req;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002074
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002075 if (rsp->id) {
2076 pkt = (struct sts_entry_24xx *) rsp->ring_ptr;
2077 req = rsp->req;
2078 if (pkt && pkt->handle < MAX_OUTSTANDING_COMMANDS) {
2079 sp = req->outstanding_cmds[pkt->handle];
2080 if (sp)
Andrew Vasquez444786d2009-01-05 11:18:10 -08002081 vha = sp->fcport->vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002082 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002083 }
2084 if (!vha)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002085 /* handle it in base queue */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002086 vha = pci_get_drvdata(ha->pdev);
2087
2088 return vha;
2089}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002090
2091int qla25xx_request_irq(struct rsp_que *rsp)
2092{
2093 struct qla_hw_data *ha = rsp->hw;
2094 struct qla_init_msix_entry *intr = &multi_rsp_queue;
2095 struct qla_msix_entry *msix = rsp->msix;
2096 int ret;
2097
2098 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
2099 if (ret) {
2100 qla_printk(KERN_WARNING, ha,
2101 "MSI-X: Unable to register handler -- %x/%d.\n",
2102 msix->vector, ret);
2103 return ret;
2104 }
2105 msix->have_irq = 1;
2106 msix->rsp = rsp;
2107 return ret;
2108}