blob: ffd0efdff40e5f04504e2d148349e0909172364f [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 *);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070016static void qla2x00_status_cont_entry(struct rsp_que *, 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 *);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070019
Linus Torvalds1da177e2005-04-16 15:20:36 -070020/**
21 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
22 * @irq:
23 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 *
25 * Called by system whenever the host adapter generates an interrupt.
26 *
27 * Returns handled flag.
28 */
29irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +010030qla2100_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080032 scsi_qla_host_t *vha;
33 struct qla_hw_data *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -070034 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 unsigned long iter;
Seokmann Ju14e660e2007-09-20 14:07:36 -070037 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070038 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080039 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070040 unsigned long flags;
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
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070053 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070054 vha = pci_get_drvdata(ha->pdev);
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 }
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700105 spin_unlock_irqrestore(&ha->hardware_lock, flags);
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;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700137 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800139 rsp = (struct rsp_que *) dev_id;
140 if (!rsp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800142 "%s(): NULL response queue pointer\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 return (IRQ_NONE);
144 }
145
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800146 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700147 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 status = 0;
149
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700150 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700151 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 for (iter = 50; iter--; ) {
153 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
154 if (stat & HSR_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800155 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -0700156 break;
157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 hccr = RD_REG_WORD(&reg->hccr);
159 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Andrew Vasquez07f31802006-12-13 19:20:31 -0800160 qla_printk(KERN_INFO, ha, "Parity error -- "
161 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 else
Andrew Vasquez07f31802006-12-13 19:20:31 -0800163 qla_printk(KERN_INFO, ha, "RISC paused -- "
164 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 /*
167 * Issue a "HARD" reset in order for the RISC
168 * interrupt bit to be cleared. Schedule a big
169 * hammmer to get out of the RISC PAUSED state.
170 */
171 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
172 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800173
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800174 ha->isp_ops->fw_dump(vha, 1);
175 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 break;
177 } else if ((stat & HSR_RISC_INT) == 0)
178 break;
179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 case 0x1:
182 case 0x2:
183 case 0x10:
184 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800185 qla2x00_mbx_completion(vha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 status |= MBX_INTERRUPT;
187
188 /* Release mailbox registers. */
189 WRT_REG_WORD(&reg->semaphore, 0);
190 break;
191 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700192 mb[0] = MSW(stat);
193 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
194 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
195 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800196 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700197 break;
198 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800199 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 break;
201 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700202 mb[0] = MBA_CMPLT_1_16BIT;
203 mb[1] = MSW(stat);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800204 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 break;
206 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700207 mb[0] = MBA_SCSI_COMPLETION;
208 mb[1] = MSW(stat);
209 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800210 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 break;
212 default:
213 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700214 "(%d).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800215 vha->host_no, stat & 0xff));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 break;
217 }
218 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
219 RD_REG_WORD_RELAXED(&reg->hccr);
220 }
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700221 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
224 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800226 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 }
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 return (IRQ_HANDLED);
230}
231
232/**
233 * qla2x00_mbx_completion() - Process mailbox command completions.
234 * @ha: SCSI driver HA context
235 * @mb0: Mailbox0 register
236 */
237static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800238qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239{
240 uint16_t cnt;
241 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800242 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700243 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245 /* Load return mailbox registers. */
246 ha->flags.mbox_int = 1;
247 ha->mailbox_out[0] = mb0;
248 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
249
250 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700251 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
253 if (cnt == 4 || cnt == 5)
254 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
255 else
256 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 wptr++;
259 }
260
261 if (ha->mcp) {
262 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800263 __func__, vha->host_no, ha->mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 } else {
265 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800266 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 }
268}
269
Andrew Vasquez8a659572009-02-08 20:50:12 -0800270static void
271qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
272{
273 static char *event[] =
274 { "Complete", "Request Notification", "Time Extension" };
275 int rval;
276 struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
277 uint16_t __iomem *wptr;
278 uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
279
280 /* Seed data -- mailbox1 -> mailbox7. */
281 wptr = (uint16_t __iomem *)&reg24->mailbox1;
282 for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
283 mb[cnt] = RD_REG_WORD(wptr);
284
285 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- "
286 "%04x %04x %04x %04x %04x %04x %04x.\n", vha->host_no,
287 event[aen & 0xff],
288 mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6]));
289
290 /* Acknowledgement needed? [Notify && non-zero timeout]. */
291 timeout = (descr >> 8) & 0xf;
292 if (aen != MBA_IDC_NOTIFY || !timeout)
293 return;
294
295 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- "
296 "ACK timeout=%d.\n", vha->host_no, event[aen & 0xff], timeout));
297
298 rval = qla2x00_post_idc_ack_work(vha, mb);
299 if (rval != QLA_SUCCESS)
300 qla_printk(KERN_WARNING, vha->hw,
301 "IDC failed to post ACK.\n");
302}
303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304/**
305 * qla2x00_async_event() - Process aynchronous events.
306 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700307 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700309void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800310qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311{
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700312#define LS_UNKNOWN 2
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800313 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 char *link_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 uint16_t handle_cnt;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700316 uint16_t cnt, mbx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 uint32_t handles[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800318 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700319 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700320 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 uint32_t rscn_entry, host_pid;
322 uint8_t rscn_queue_index;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700323 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325 /* Setup to process RIO completion. */
326 handle_cnt = 0;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800327 if (IS_QLA81XX(ha))
328 goto skip_rio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 switch (mb[0]) {
330 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700331 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 handle_cnt = 1;
333 break;
334 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700335 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 handle_cnt = 1;
337 mb[0] = MBA_SCSI_COMPLETION;
338 break;
339 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700340 handles[0] = mb[1];
341 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 handle_cnt = 2;
343 mb[0] = MBA_SCSI_COMPLETION;
344 break;
345 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700346 handles[0] = mb[1];
347 handles[1] = mb[2];
348 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 handle_cnt = 3;
350 mb[0] = MBA_SCSI_COMPLETION;
351 break;
352 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700353 handles[0] = mb[1];
354 handles[1] = mb[2];
355 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
357 handle_cnt = 4;
358 mb[0] = MBA_SCSI_COMPLETION;
359 break;
360 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700361 handles[0] = mb[1];
362 handles[1] = mb[2];
363 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
365 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
366 handle_cnt = 5;
367 mb[0] = MBA_SCSI_COMPLETION;
368 break;
369 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700370 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 handles[1] = le32_to_cpu(
372 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
373 RD_MAILBOX_REG(ha, reg, 6));
374 handle_cnt = 2;
375 mb[0] = MBA_SCSI_COMPLETION;
376 break;
377 default:
378 break;
379 }
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800380skip_rio:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 switch (mb[0]) {
382 case MBA_SCSI_COMPLETION: /* Fast Post */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800383 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 break;
385
386 for (cnt = 0; cnt < handle_cnt; cnt++)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800387 qla2x00_process_completed_request(vha, rsp->req,
388 handles[cnt]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 break;
390
391 case MBA_RESET: /* Reset */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800392 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n",
393 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800395 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 break;
397
398 case MBA_SYSTEM_ERR: /* System Error */
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700399 mbx = IS_QLA81XX(ha) ? RD_REG_WORD(&reg24->mailbox7) : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 qla_printk(KERN_INFO, ha,
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700401 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh "
402 "mbx7=%xh.\n", mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800404 ha->isp_ops->fw_dump(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Andrew Vasqueze4289242007-07-19 15:05:56 -0700406 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700407 if (mb[1] == 0 && mb[2] == 0) {
408 qla_printk(KERN_ERR, ha,
409 "Unrecoverable Hardware Error: adapter "
410 "marked OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800411 vha->flags.online = 0;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700412 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800413 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700414 } else if (mb[1] == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 qla_printk(KERN_INFO, ha,
416 "Unrecoverable Hardware Error: adapter marked "
417 "OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800418 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800420 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 break;
422
423 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700424 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error (%x).\n",
425 vha->host_no, mb[1]));
426 qla_printk(KERN_WARNING, ha,
427 "ISP Request Transfer Error (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800429 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 break;
431
432 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
433 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800434 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
436
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800437 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 break;
439
440 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
441 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800442 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 break;
444
445 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800446 DEBUG2(printk("scsi(%ld): LIP occurred (%x).\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 mb[1]));
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700448 qla_printk(KERN_INFO, ha, "LIP occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800450 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
451 atomic_set(&vha->loop_state, LOOP_DOWN);
452 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
453 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 }
455
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800456 if (vha->vp_idx) {
457 atomic_set(&vha->vp_state, VP_FAILED);
458 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700459 }
460
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800461 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
462 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800464 vha->flags.management_server_logged_in = 0;
465 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 break;
467
468 case MBA_LOOP_UP: /* Loop Up Event */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
470 link_speed = link_speeds[0];
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700471 ha->link_data_rate = PORT_SPEED_1GB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 } else {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700473 link_speed = link_speeds[LS_UNKNOWN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 if (mb[1] < 5)
475 link_speed = link_speeds[mb[1]];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800476 else if (mb[1] == 0x13)
477 link_speed = link_speeds[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 ha->link_data_rate = mb[1];
479 }
480
481 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800482 vha->host_no, link_speed));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
484 link_speed);
485
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800486 vha->flags.management_server_logged_in = 0;
487 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 break;
489
490 case MBA_LOOP_DOWN: /* Loop Down Event */
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700491 mbx = IS_QLA81XX(ha) ? RD_REG_WORD(&reg24->mailbox4) : 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700492 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN "
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700493 "(%x %x %x %x).\n", vha->host_no, mb[1], mb[2], mb[3],
494 mbx));
495 qla_printk(KERN_INFO, ha,
496 "LOOP DOWN detected (%x %x %x %x).\n", mb[1], mb[2], mb[3],
497 mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800499 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
500 atomic_set(&vha->loop_state, LOOP_DOWN);
501 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
502 vha->device_flags |= DFLG_NO_CABLE;
503 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 }
505
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800506 if (vha->vp_idx) {
507 atomic_set(&vha->vp_state, VP_FAILED);
508 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700509 }
510
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800511 vha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700512 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800513 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 break;
515
516 case MBA_LIP_RESET: /* LIP reset occurred */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800518 vha->host_no, mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 qla_printk(KERN_INFO, ha,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700520 "LIP reset occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800522 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
523 atomic_set(&vha->loop_state, LOOP_DOWN);
524 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
525 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 }
527
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800528 if (vha->vp_idx) {
529 atomic_set(&vha->vp_state, VP_FAILED);
530 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700531 }
532
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800533 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
535 ha->operating_mode = LOOP;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800536 vha->flags.management_server_logged_in = 0;
537 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 break;
539
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800540 /* case MBA_DCBX_COMPLETE: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 case MBA_POINT_TO_POINT: /* Point-to-Point */
542 if (IS_QLA2100(ha))
543 break;
544
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800545 if (IS_QLA81XX(ha))
546 DEBUG2(printk("scsi(%ld): DCBX Completed -- %04x %04x "
547 "%04x\n", vha->host_no, mb[1], mb[2], mb[3]));
548 else
549 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE "
550 "received.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
552 /*
553 * Until there's a transition from loop down to loop up, treat
554 * this as loop down only.
555 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800556 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
557 atomic_set(&vha->loop_state, LOOP_DOWN);
558 if (!atomic_read(&vha->loop_down_timer))
559 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800561 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 }
563
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800564 if (vha->vp_idx) {
565 atomic_set(&vha->vp_state, VP_FAILED);
566 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700567 }
568
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800569 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
570 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
571
572 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
573 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800574
575 ha->flags.gpsc_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800576 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 break;
578
579 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
580 if (IS_QLA2100(ha))
581 break;
582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
584 "received.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800585 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 qla_printk(KERN_INFO, ha,
587 "Configuration change detected: value=%x.\n", mb[1]);
588
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800589 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
590 atomic_set(&vha->loop_state, LOOP_DOWN);
591 if (!atomic_read(&vha->loop_down_timer))
592 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800594 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 }
596
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800597 if (vha->vp_idx) {
598 atomic_set(&vha->vp_state, VP_FAILED);
599 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700600 }
601
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800602 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
603 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 break;
605
606 case MBA_PORT_UPDATE: /* Port database update */
Santosh Vernekar55903b92009-07-31 15:09:25 -0700607 /*
608 * Handle only global and vn-port update events
609 *
610 * Relevant inputs:
611 * mb[1] = N_Port handle of changed port
612 * OR 0xffff for global event
613 * mb[2] = New login state
614 * 7 = Port logged out
615 * mb[3] = LSB is vp_idx, 0xff = all vps
616 *
617 * Skip processing if:
618 * Event is global, vp_idx is NOT all vps,
619 * vp_idx does not match
620 * Event is not global, vp_idx does not match
621 */
622 if ((mb[1] == 0xffff && (mb[3] & 0xff) != 0xff)
623 || (mb[1] != 0xffff)) {
624 if (vha->vp_idx != (mb[3] & 0xff))
625 break;
626 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800627
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700628 /* Global event -- port logout or port unavailable. */
629 if (mb[1] == 0xffff && mb[2] == 0x7) {
630 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
631 vha->host_no));
632 DEBUG(printk(KERN_INFO
633 "scsi(%ld): Port unavailable %04x %04x %04x.\n",
634 vha->host_no, mb[1], mb[2], mb[3]));
635
636 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
637 atomic_set(&vha->loop_state, LOOP_DOWN);
638 atomic_set(&vha->loop_down_timer,
639 LOOP_DOWN_TIME);
640 vha->device_flags |= DFLG_NO_CABLE;
641 qla2x00_mark_all_devices_lost(vha, 1);
642 }
643
644 if (vha->vp_idx) {
645 atomic_set(&vha->vp_state, VP_FAILED);
646 fc_vport_set_state(vha->fc_vport,
647 FC_VPORT_FAILED);
Santosh Vernekarfaadc5e2009-07-31 15:09:26 -0700648 qla2x00_mark_all_devices_lost(vha, 1);
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700649 }
650
651 vha->flags.management_server_logged_in = 0;
652 ha->link_data_rate = PORT_SPEED_UNKNOWN;
653 break;
654 }
655
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 /*
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700657 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 * event etc. earlier indicating loop is down) then process
659 * it. Otherwise ignore it and Wait for RSCN to come in.
660 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800661 atomic_set(&vha->loop_down_timer, 0);
662 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
663 atomic_read(&vha->loop_state) != LOOP_DEAD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800665 "ignored %04x/%04x/%04x.\n", vha->host_no, mb[1],
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700666 mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 break;
668 }
669
670 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800671 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 DEBUG(printk(KERN_INFO
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700673 "scsi(%ld): Port database changed %04x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800674 vha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
676 /*
677 * Mark all devices as missing so we will login again.
678 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800679 atomic_set(&vha->loop_state, LOOP_UP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800681 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800683 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800685 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
686 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 break;
688
689 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju3c397402008-05-19 14:25:39 -0700690 /* Check if the Vport has issued a SCR */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800691 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
Seokmann Ju3c397402008-05-19 14:25:39 -0700692 break;
693 /* Only handle SCNs for our Vport index. */
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700694 if (ha->flags.npiv_supported && vha->vp_idx != (mb[3] & 0xff))
Seokmann Ju3c397402008-05-19 14:25:39 -0700695 break;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800698 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 DEBUG(printk(KERN_INFO
Shyam Sundarf4a8dbc2007-11-12 10:30:59 -0800700 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800701 vha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Ravi Anand59d72d82008-09-11 21:22:53 -0700703 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800704 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
705 | vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 if (rscn_entry == host_pid) {
707 DEBUG(printk(KERN_INFO
708 "scsi(%ld): Ignoring RSCN update to local host "
709 "port ID (%06x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800710 vha->host_no, host_pid));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 break;
712 }
713
Ravi Anand59d72d82008-09-11 21:22:53 -0700714 /* Ignore reserved bits from RSCN-payload. */
715 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800716 rscn_queue_index = vha->rscn_in_ptr + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 if (rscn_queue_index == MAX_RSCN_COUNT)
718 rscn_queue_index = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800719 if (rscn_queue_index != vha->rscn_out_ptr) {
720 vha->rscn_queue[vha->rscn_in_ptr] = rscn_entry;
721 vha->rscn_in_ptr = rscn_queue_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800723 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 }
725
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800726 atomic_set(&vha->loop_state, LOOP_UPDATE);
727 atomic_set(&vha->loop_down_timer, 0);
728 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800730 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
731 set_bit(RSCN_UPDATE, &vha->dpc_flags);
732 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 break;
734
735 /* case MBA_RIO_RESPONSE: */
736 case MBA_ZIO_RESPONSE:
Andrew Vasquez3fd67cd2009-01-05 11:18:07 -0800737 DEBUG3(printk("scsi(%ld): [R|Z]IO update completion.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800738 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
Andrew Vasqueze4289242007-07-19 15:05:56 -0700740 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700741 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700742 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800743 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700745
746 case MBA_DISCARD_RND_FRAME:
747 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800748 "%04x.\n", vha->host_no, mb[1], mb[2], mb[3]));
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700749 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700750
751 case MBA_TRACE_NOTIFICATION:
752 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800753 vha->host_no, mb[1], mb[2]));
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700754 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700755
756 case MBA_ISP84XX_ALERT:
757 DEBUG2(printk("scsi(%ld): ISP84XX Alert Notification -- "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800758 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700759
760 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
761 switch (mb[1]) {
762 case A84_PANIC_RECOVERY:
763 qla_printk(KERN_INFO, ha, "Alert 84XX: panic recovery "
764 "%04x %04x\n", mb[2], mb[3]);
765 break;
766 case A84_OP_LOGIN_COMPLETE:
767 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
768 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
769 "firmware version %x\n", ha->cs84xx->op_fw_version));
770 break;
771 case A84_DIAG_LOGIN_COMPLETE:
772 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
773 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
774 "diagnostic firmware version %x\n",
775 ha->cs84xx->diag_fw_version));
776 break;
777 case A84_GOLD_LOGIN_COMPLETE:
778 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
779 ha->cs84xx->fw_update = 1;
780 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX: gold "
781 "firmware version %x\n",
782 ha->cs84xx->gold_fw_version));
783 break;
784 default:
785 qla_printk(KERN_ERR, ha,
786 "Alert 84xx: Invalid Alert %04x %04x %04x\n",
787 mb[1], mb[2], mb[3]);
788 }
789 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
790 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800791 case MBA_DCBX_START:
792 DEBUG2(printk("scsi(%ld): DCBX Started -- %04x %04x %04x\n",
793 vha->host_no, mb[1], mb[2], mb[3]));
794 break;
795 case MBA_DCBX_PARAM_UPDATE:
796 DEBUG2(printk("scsi(%ld): DCBX Parameters Updated -- "
797 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
798 break;
799 case MBA_FCF_CONF_ERR:
800 DEBUG2(printk("scsi(%ld): FCF Configuration Error -- "
801 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
802 break;
803 case MBA_IDC_COMPLETE:
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800804 case MBA_IDC_NOTIFY:
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800805 case MBA_IDC_TIME_EXT:
Andrew Vasquez8a659572009-02-08 20:50:12 -0800806 qla81xx_idc_event(vha, mb[0], mb[1]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800807 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700809
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800810 if (!vha->vp_idx && ha->num_vhosts)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800811 qla2x00_alert_all_vps(rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812}
813
814/**
815 * qla2x00_process_completed_request() - Process a Fast Post response.
816 * @ha: SCSI driver HA context
817 * @index: SRB index
818 */
819static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800820qla2x00_process_completed_request(struct scsi_qla_host *vha,
821 struct req_que *req, uint32_t index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822{
823 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800824 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826 /* Validate handle. */
827 if (index >= MAX_OUTSTANDING_COMMANDS) {
828 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800829 vha->host_no, index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 qla_printk(KERN_WARNING, ha,
831 "Invalid SCSI completion handle %d.\n", index);
832
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800833 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 return;
835 }
836
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800837 sp = req->outstanding_cmds[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 if (sp) {
839 /* Free outstanding command slot. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800840 req->outstanding_cmds[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 /* Save ISP completion status */
843 sp->cmd->result = DID_OK << 16;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800844 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 } else {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700846 DEBUG2(printk("scsi(%ld) Req:%d: Invalid ISP SCSI completion"
847 " handle(%d)\n", vha->host_no, req->id, index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 qla_printk(KERN_WARNING, ha,
849 "Invalid ISP SCSI completion handle\n");
850
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800851 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 }
853}
854
Andrew Vasquezac280b62009-08-20 11:06:05 -0700855static srb_t *
856qla2x00_get_sp_from_handle(scsi_qla_host_t *vha, const char *func,
857 struct req_que *req, void *iocb)
858{
859 struct qla_hw_data *ha = vha->hw;
860 sts_entry_t *pkt = iocb;
861 srb_t *sp = NULL;
862 uint16_t index;
863
864 index = LSW(pkt->handle);
865 if (index >= MAX_OUTSTANDING_COMMANDS) {
866 qla_printk(KERN_WARNING, ha,
867 "%s: Invalid completion handle (%x).\n", func, index);
868 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
869 goto done;
870 }
871 sp = req->outstanding_cmds[index];
872 if (!sp) {
873 qla_printk(KERN_WARNING, ha,
874 "%s: Invalid completion handle (%x) -- timed-out.\n", func,
875 index);
876 return sp;
877 }
878 if (sp->handle != index) {
879 qla_printk(KERN_WARNING, ha,
880 "%s: SRB handle (%x) mismatch %x.\n", func, sp->handle,
881 index);
882 return NULL;
883 }
884 req->outstanding_cmds[index] = NULL;
885done:
886 return sp;
887}
888
889static void
890qla2x00_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
891 struct mbx_entry *mbx)
892{
893 const char func[] = "MBX-IOCB";
894 const char *type;
895 struct qla_hw_data *ha = vha->hw;
896 fc_port_t *fcport;
897 srb_t *sp;
898 struct srb_logio *lio;
899 uint16_t data[2];
900
901 sp = qla2x00_get_sp_from_handle(vha, func, req, mbx);
902 if (!sp)
903 return;
904
905 type = NULL;
906 lio = sp->ctx;
907 switch (lio->ctx.type) {
908 case SRB_LOGIN_CMD:
909 type = "login";
910 break;
911 case SRB_LOGOUT_CMD:
912 type = "logout";
913 break;
914 default:
915 qla_printk(KERN_WARNING, ha,
916 "%s: Unrecognized SRB: (%p) type=%d.\n", func, sp,
917 lio->ctx.type);
918 return;
919 }
920
921 del_timer(&lio->ctx.timer);
922 fcport = sp->fcport;
923
924 data[0] = data[1] = 0;
925 if (mbx->entry_status) {
926 DEBUG2(printk(KERN_WARNING
927 "scsi(%ld:%x): Async-%s error entry - entry-status=%x "
928 "status=%x state-flag=%x status-flags=%x.\n",
929 fcport->vha->host_no, sp->handle, type,
930 mbx->entry_status, le16_to_cpu(mbx->status),
931 le16_to_cpu(mbx->state_flags),
932 le16_to_cpu(mbx->status_flags)));
933 DEBUG2(qla2x00_dump_buffer((uint8_t *)mbx, sizeof(*mbx)));
934
935 data[0] = MBS_COMMAND_ERROR;
936 data[1] = lio->flags & SRB_LOGIN_RETRIED ?
937 QLA_LOGIO_LOGIN_RETRIED: 0;
938 goto done_post_logio_done_work;
939 }
940
941 if (!mbx->status && le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE) {
942 DEBUG2(printk(KERN_DEBUG
943 "scsi(%ld:%x): Async-%s complete - mbx1=%x.\n",
944 fcport->vha->host_no, sp->handle, type,
945 le16_to_cpu(mbx->mb1)));
946
947 data[0] = MBS_COMMAND_COMPLETE;
948 if (lio->ctx.type == SRB_LOGIN_CMD && le16_to_cpu(mbx->mb1) & BIT_1)
Santosh Vernekar8474f3a2009-08-25 11:36:16 -0700949 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700950
951 goto done_post_logio_done_work;
952 }
953
954 data[0] = le16_to_cpu(mbx->mb0);
955 switch (data[0]) {
956 case MBS_PORT_ID_USED:
957 data[1] = le16_to_cpu(mbx->mb1);
958 break;
959 case MBS_LOOP_ID_USED:
960 break;
961 default:
962 data[0] = MBS_COMMAND_ERROR;
963 data[1] = lio->flags & SRB_LOGIN_RETRIED ?
964 QLA_LOGIO_LOGIN_RETRIED: 0;
965 break;
966 }
967
968 DEBUG2(printk(KERN_WARNING
969 "scsi(%ld:%x): Async-%s failed - status=%x mb0=%x mb1=%x mb2=%x "
970 "mb6=%x mb7=%x.\n",
971 fcport->vha->host_no, sp->handle, type, le16_to_cpu(mbx->status),
972 le16_to_cpu(mbx->mb0), le16_to_cpu(mbx->mb1),
973 le16_to_cpu(mbx->mb2), le16_to_cpu(mbx->mb6),
974 le16_to_cpu(mbx->mb7)));
975
976done_post_logio_done_work:
977 lio->ctx.type == SRB_LOGIN_CMD ?
978 qla2x00_post_async_login_done_work(fcport->vha, fcport, data):
979 qla2x00_post_async_logout_done_work(fcport->vha, fcport, data);
980
981 lio->ctx.free(sp);
982}
983
984static void
985qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req,
986 struct logio_entry_24xx *logio)
987{
988 const char func[] = "LOGIO-IOCB";
989 const char *type;
990 struct qla_hw_data *ha = vha->hw;
991 fc_port_t *fcport;
992 srb_t *sp;
993 struct srb_logio *lio;
994 uint16_t data[2];
995 uint32_t iop[2];
996
997 sp = qla2x00_get_sp_from_handle(vha, func, req, logio);
998 if (!sp)
999 return;
1000
1001 type = NULL;
1002 lio = sp->ctx;
1003 switch (lio->ctx.type) {
1004 case SRB_LOGIN_CMD:
1005 type = "login";
1006 break;
1007 case SRB_LOGOUT_CMD:
1008 type = "logout";
1009 break;
1010 default:
1011 qla_printk(KERN_WARNING, ha,
1012 "%s: Unrecognized SRB: (%p) type=%d.\n", func, sp,
1013 lio->ctx.type);
1014 return;
1015 }
1016
1017 del_timer(&lio->ctx.timer);
1018 fcport = sp->fcport;
1019
1020 data[0] = data[1] = 0;
1021 if (logio->entry_status) {
1022 DEBUG2(printk(KERN_WARNING
1023 "scsi(%ld:%x): Async-%s error entry - entry-status=%x.\n",
1024 fcport->vha->host_no, sp->handle, type,
1025 logio->entry_status));
1026 DEBUG2(qla2x00_dump_buffer((uint8_t *)logio, sizeof(*logio)));
1027
1028 data[0] = MBS_COMMAND_ERROR;
1029 data[1] = lio->flags & SRB_LOGIN_RETRIED ?
1030 QLA_LOGIO_LOGIN_RETRIED: 0;
1031 goto done_post_logio_done_work;
1032 }
1033
1034 if (le16_to_cpu(logio->comp_status) == CS_COMPLETE) {
1035 DEBUG2(printk(KERN_DEBUG
1036 "scsi(%ld:%x): Async-%s complete - iop0=%x.\n",
1037 fcport->vha->host_no, sp->handle, type,
1038 le32_to_cpu(logio->io_parameter[0])));
1039
1040 data[0] = MBS_COMMAND_COMPLETE;
1041 if (lio->ctx.type == SRB_LOGOUT_CMD)
1042 goto done_post_logio_done_work;
1043
1044 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1045 if (iop[0] & BIT_4) {
1046 fcport->port_type = FCT_TARGET;
1047 if (iop[0] & BIT_8)
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07001048 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001049 }
1050 if (iop[0] & BIT_5)
1051 fcport->port_type = FCT_INITIATOR;
1052 if (logio->io_parameter[7] || logio->io_parameter[8])
1053 fcport->supported_classes |= FC_COS_CLASS2;
1054 if (logio->io_parameter[9] || logio->io_parameter[10])
1055 fcport->supported_classes |= FC_COS_CLASS3;
1056
1057 goto done_post_logio_done_work;
1058 }
1059
1060 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1061 iop[1] = le32_to_cpu(logio->io_parameter[1]);
1062 switch (iop[0]) {
1063 case LSC_SCODE_PORTID_USED:
1064 data[0] = MBS_PORT_ID_USED;
1065 data[1] = LSW(iop[1]);
1066 break;
1067 case LSC_SCODE_NPORT_USED:
1068 data[0] = MBS_LOOP_ID_USED;
1069 break;
1070 case LSC_SCODE_CMD_FAILED:
1071 if ((iop[1] & 0xff) == 0x05) {
1072 data[0] = MBS_NOT_LOGGED_IN;
1073 break;
1074 }
1075 /* Fall through. */
1076 default:
1077 data[0] = MBS_COMMAND_ERROR;
1078 data[1] = lio->flags & SRB_LOGIN_RETRIED ?
1079 QLA_LOGIO_LOGIN_RETRIED: 0;
1080 break;
1081 }
1082
1083 DEBUG2(printk(KERN_WARNING
1084 "scsi(%ld:%x): Async-%s failed - comp=%x iop0=%x iop1=%x.\n",
1085 fcport->vha->host_no, sp->handle, type,
1086 le16_to_cpu(logio->comp_status),
1087 le32_to_cpu(logio->io_parameter[0]),
1088 le32_to_cpu(logio->io_parameter[1])));
1089
1090done_post_logio_done_work:
1091 lio->ctx.type == SRB_LOGIN_CMD ?
1092 qla2x00_post_async_login_done_work(fcport->vha, fcport, data):
1093 qla2x00_post_async_logout_done_work(fcport->vha, fcport, data);
1094
1095 lio->ctx.free(sp);
1096}
1097
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098/**
1099 * qla2x00_process_response_queue() - Process response queue entries.
1100 * @ha: SCSI driver HA context
1101 */
1102void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001103qla2x00_process_response_queue(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001105 struct scsi_qla_host *vha;
1106 struct qla_hw_data *ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001107 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 sts_entry_t *pkt;
1109 uint16_t handle_cnt;
1110 uint16_t cnt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001111
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001112 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001114 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 return;
1116
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001117 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1118 pkt = (sts_entry_t *)rsp->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001120 rsp->ring_index++;
1121 if (rsp->ring_index == rsp->length) {
1122 rsp->ring_index = 0;
1123 rsp->ring_ptr = rsp->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001125 rsp->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 }
1127
1128 if (pkt->entry_status != 0) {
1129 DEBUG3(printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001130 "scsi(%ld): Process error entry.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001132 qla2x00_error_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1134 wmb();
1135 continue;
1136 }
1137
1138 switch (pkt->entry_type) {
1139 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001140 qla2x00_status_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 break;
1142 case STATUS_TYPE_21:
1143 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
1144 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001145 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 ((sts21_entry_t *)pkt)->handle[cnt]);
1147 }
1148 break;
1149 case STATUS_TYPE_22:
1150 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
1151 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001152 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 ((sts22_entry_t *)pkt)->handle[cnt]);
1154 }
1155 break;
1156 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001157 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001159 case MBX_IOCB_TYPE:
1160 qla2x00_mbx_iocb_entry(vha, rsp->req,
1161 (struct mbx_entry *)pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 default:
1163 /* Type Not Supported. */
1164 DEBUG4(printk(KERN_WARNING
1165 "scsi(%ld): Received unknown response pkt type %x "
1166 "entry status=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001167 vha->host_no, pkt->entry_type, pkt->entry_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 break;
1169 }
1170 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1171 wmb();
1172 }
1173
1174 /* Adjust ring index */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001175 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176}
1177
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001178static inline void
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001179qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len,
1180 struct rsp_que *rsp)
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001181{
1182 struct scsi_cmnd *cp = sp->cmd;
1183
1184 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
1185 sense_len = SCSI_SENSE_BUFFERSIZE;
1186
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001187 sp->request_sense_length = sense_len;
1188 sp->request_sense_ptr = cp->sense_buffer;
1189 if (sp->request_sense_length > 32)
1190 sense_len = 32;
1191
1192 memcpy(cp->sense_buffer, sense_data, sense_len);
1193
1194 sp->request_sense_ptr += sense_len;
1195 sp->request_sense_length -= sense_len;
1196 if (sp->request_sense_length != 0)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001197 rsp->status_srb = sp;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001198
1199 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001200 "cmd=%p pid=%ld\n", __func__, sp->fcport->vha->host_no,
Andrew Vasquez19851f12008-08-13 21:37:00 -07001201 cp->device->channel, cp->device->id, cp->device->lun, cp,
1202 cp->serial_number));
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001203 if (sense_len)
Shyam Sundarddb9b122009-03-24 09:08:10 -07001204 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer, sense_len));
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001205}
1206
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207/**
1208 * qla2x00_status_entry() - Process a Status IOCB entry.
1209 * @ha: SCSI driver HA context
1210 * @pkt: Entry pointer
1211 */
1212static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001213qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 fc_port_t *fcport;
1217 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001218 sts_entry_t *sts;
1219 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 uint16_t comp_status;
1221 uint16_t scsi_status;
1222 uint8_t lscsi_status;
1223 int32_t resid;
Ravi Ananded17c71b52006-05-17 15:08:55 -07001224 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001225 uint8_t *rsp_info, *sense_data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001226 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001227 uint32_t handle;
1228 uint16_t que;
1229 struct req_que *req;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001230
1231 sts = (sts_entry_t *) pkt;
1232 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001233 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001234 comp_status = le16_to_cpu(sts24->comp_status);
1235 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
1236 } else {
1237 comp_status = le16_to_cpu(sts->comp_status);
1238 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1239 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001240 handle = (uint32_t) LSW(sts->handle);
1241 que = MSW(sts->handle);
1242 req = ha->req_q_map[que];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001244 if (comp_status == CS_COMPLETE && scsi_status == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001245 qla2x00_process_completed_request(vha, req, handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246
1247 return;
1248 }
1249
1250 /* Validate handle. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001251 if (handle < MAX_OUTSTANDING_COMMANDS) {
1252 sp = req->outstanding_cmds[handle];
1253 req->outstanding_cmds[handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 } else
1255 sp = NULL;
1256
1257 if (sp == NULL) {
1258 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001259 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
1261
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001262 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1263 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 return;
1265 }
1266 cp = sp->cmd;
1267 if (cp == NULL) {
1268 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001269 "pkt->handle=%d sp=%p.\n", vha->host_no, handle, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 qla_printk(KERN_WARNING, ha,
1271 "Command is NULL: already returned to OS (sp=%p)\n", sp);
1272
1273 return;
1274 }
1275
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001276 lscsi_status = scsi_status & STATUS_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
bdf79622005-04-17 15:06:53 -05001278 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Ravi Ananded17c71b52006-05-17 15:08:55 -07001280 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001281 if (IS_FWI2_CAPABLE(ha)) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001282 if (scsi_status & SS_SENSE_LEN_VALID)
1283 sense_len = le32_to_cpu(sts24->sense_len);
1284 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
1285 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
1286 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER))
1287 resid_len = le32_to_cpu(sts24->rsp_residual_count);
1288 if (comp_status == CS_DATA_UNDERRUN)
1289 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001290 rsp_info = sts24->data;
1291 sense_data = sts24->data;
1292 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
1293 } else {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001294 if (scsi_status & SS_SENSE_LEN_VALID)
1295 sense_len = le16_to_cpu(sts->req_sense_length);
1296 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
1297 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001298 resid_len = le32_to_cpu(sts->residual_length);
1299 rsp_info = sts->rsp_info;
1300 sense_data = sts->req_sense_data;
1301 }
1302
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 /* Check for any FCP transport errors. */
1304 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001305 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001306 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001307 sense_data += rsp_info_len;
1308 if (rsp_info_len > 3 && rsp_info[3]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
1310 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001311 "retrying command\n", vha->host_no,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001312 cp->device->channel, cp->device->id,
1313 cp->device->lun, rsp_info_len, rsp_info[0],
1314 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
1315 rsp_info[5], rsp_info[6], rsp_info[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316
1317 cp->result = DID_BUS_BUSY << 16;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001318 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 return;
1320 }
1321 }
1322
Andrew Vasquez3e8ce322008-02-28 14:06:10 -08001323 /* Check for overrun. */
1324 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
1325 scsi_status & SS_RESIDUAL_OVER)
1326 comp_status = CS_DATA_OVERRUN;
1327
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 /*
1329 * Based on Host and scsi status generate status code for Linux
1330 */
1331 switch (comp_status) {
1332 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001333 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 if (scsi_status == 0) {
1335 cp->result = DID_OK << 16;
1336 break;
1337 }
1338 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001339 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001340 scsi_set_resid(cp, resid);
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001341
1342 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001343 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001344 cp->underflow)) {
1345 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001346 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1347 "detected (%x of %x bytes)...returning "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001348 "error status.\n", vha->host_no,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001349 cp->device->channel, cp->device->id,
1350 cp->device->lun, resid,
1351 scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001352
1353 cp->result = DID_ERROR << 16;
1354 break;
1355 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 cp->result = DID_OK << 16 | lscsi_status;
1358
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001359 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1360 DEBUG2(printk(KERN_INFO
1361 "scsi(%ld): QUEUE FULL status detected "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001362 "0x%x-0x%x.\n", vha->host_no, comp_status,
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001363 scsi_status));
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001364 break;
1365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 if (lscsi_status != SS_CHECK_CONDITION)
1367 break;
1368
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001369 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 if (!(scsi_status & SS_SENSE_LEN_VALID))
1371 break;
1372
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001373 qla2x00_handle_sense(sp, sense_data, sense_len, rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 break;
1375
1376 case CS_DATA_UNDERRUN:
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001377 DEBUG2(printk(KERN_INFO
1378 "scsi(%ld:%d:%d) UNDERRUN status detected 0x%x-0x%x. "
1379 "resid=0x%x fw_resid=0x%x cdb=0x%x os_underflow=0x%x\n",
1380 vha->host_no, cp->device->id, cp->device->lun, comp_status,
1381 scsi_status, resid_len, fw_resid_len, cp->cmnd[0],
1382 cp->underflow));
1383
Ravi Ananded17c71b52006-05-17 15:08:55 -07001384 /* Use F/W calculated residual length. */
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001385 resid = IS_FWI2_CAPABLE(ha) ? fw_resid_len : resid_len;
1386 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 if (scsi_status & SS_RESIDUAL_UNDER) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001388 if (IS_FWI2_CAPABLE(ha) && fw_resid_len != resid_len) {
1389 DEBUG2(printk(
1390 "scsi(%ld:%d:%d:%d) Dropped frame(s) "
1391 "detected (%x of %x bytes)...residual "
1392 "length mismatch...retrying command.\n",
1393 vha->host_no, cp->device->channel,
1394 cp->device->id, cp->device->lun, resid,
1395 scsi_bufflen(cp)));
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08001396
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001397 cp->result = DID_ERROR << 16 | lscsi_status;
1398 break;
1399 }
1400
1401 if (!lscsi_status &&
1402 ((unsigned)(scsi_bufflen(cp) - resid) <
1403 cp->underflow)) {
1404 qla_printk(KERN_INFO, ha,
1405 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1406 "detected (%x of %x bytes)...returning "
1407 "error status.\n", vha->host_no,
1408 cp->device->channel, cp->device->id,
1409 cp->device->lun, resid, scsi_bufflen(cp));
1410
1411 cp->result = DID_ERROR << 16;
1412 break;
1413 }
1414 } else if (!lscsi_status) {
1415 DEBUG2(printk(
1416 "scsi(%ld:%d:%d:%d) Dropped frame(s) detected "
1417 "(%x of %x bytes)...firmware reported underrun..."
1418 "retrying command.\n", vha->host_no,
1419 cp->device->channel, cp->device->id,
1420 cp->device->lun, resid, scsi_bufflen(cp)));
1421
1422 cp->result = DID_ERROR << 16;
1423 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 }
1425
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001426 cp->result = DID_OK << 16 | lscsi_status;
1427
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001429 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 * Status.
1431 */
1432 if (lscsi_status != 0) {
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001433 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1434 DEBUG2(printk(KERN_INFO
1435 "scsi(%ld): QUEUE FULL status detected "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001436 "0x%x-0x%x.\n", vha->host_no, comp_status,
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001437 scsi_status));
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001438 break;
1439 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 if (lscsi_status != SS_CHECK_CONDITION)
1441 break;
1442
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001443 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 if (!(scsi_status & SS_SENSE_LEN_VALID))
1445 break;
1446
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001447 qla2x00_handle_sense(sp, sense_data, sense_len, rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 }
1449 break;
1450
1451 case CS_DATA_OVERRUN:
1452 DEBUG2(printk(KERN_INFO
1453 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001454 vha->host_no, cp->device->id, cp->device->lun, comp_status,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001455 scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 DEBUG2(printk(KERN_INFO
1457 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1458 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1459 cp->cmnd[4], cp->cmnd[5]));
1460 DEBUG2(printk(KERN_INFO
1461 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1462 "status!\n",
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001463 cp->serial_number, scsi_bufflen(cp), resid_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
1465 cp->result = DID_ERROR << 16;
1466 break;
1467
1468 case CS_PORT_LOGGED_OUT:
1469 case CS_PORT_CONFIG_CHG:
1470 case CS_PORT_BUSY:
1471 case CS_INCOMPLETE:
1472 case CS_PORT_UNAVAILABLE:
1473 /*
1474 * If the port is in Target Down state, return all IOs for this
1475 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1476 * retry_queue.
1477 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1479 "pid=%ld, compl status=0x%x, port state=0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001480 vha->host_no, cp->device->id, cp->device->lun,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001481 cp->serial_number, comp_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 atomic_read(&fcport->state)));
1483
Mike Christie056a4482008-08-19 18:45:29 -05001484 /*
1485 * We are going to have the fc class block the rport
1486 * while we try to recover so instruct the mid layer
1487 * to requeue until the class decides how to handle this.
1488 */
1489 cp->result = DID_TRANSPORT_DISRUPTED << 16;
Andrew Vasqueza7a28502008-08-13 21:36:57 -07001490 if (atomic_read(&fcport->state) == FCS_ONLINE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001491 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 break;
1493
1494 case CS_RESET:
1495 DEBUG2(printk(KERN_INFO
1496 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001497 vha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
f4f051e2005-04-17 15:02:26 -05001499 cp->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 break;
1501
1502 case CS_ABORTED:
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001503 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 * hv2.19.12 - DID_ABORT does not retry the request if we
1505 * aborted this request then abort otherwise it must be a
1506 * reset.
1507 */
1508 DEBUG2(printk(KERN_INFO
1509 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001510 vha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
1512 cp->result = DID_RESET << 16;
1513 break;
1514
1515 case CS_TIMEOUT:
Mike Christie056a4482008-08-19 18:45:29 -05001516 /*
1517 * We are going to have the fc class block the rport
1518 * while we try to recover so instruct the mid layer
1519 * to requeue until the class decides how to handle this.
1520 */
1521 cp->result = DID_TRANSPORT_DISRUPTED << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
Andrew Vasqueze4289242007-07-19 15:05:56 -07001523 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001524 DEBUG2(printk(KERN_INFO
1525 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001526 "0x%x-0x%x\n", vha->host_no, cp->device->channel,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001527 cp->device->id, cp->device->lun, comp_status,
1528 scsi_status));
1529 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001531 DEBUG2(printk(KERN_INFO
1532 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001533 "sflags=%x.\n", vha->host_no, cp->device->channel,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001534 cp->device->id, cp->device->lun, comp_status, scsi_status,
1535 le16_to_cpu(sts->status_flags)));
1536
1537 /* Check to see if logout occurred. */
1538 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001539 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 break;
1541
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 default:
1543 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001544 "0x%x-0x%x.\n", vha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 qla_printk(KERN_INFO, ha,
1546 "Unknown status detected 0x%x-0x%x.\n",
1547 comp_status, scsi_status);
1548
1549 cp->result = DID_ERROR << 16;
1550 break;
1551 }
1552
1553 /* Place command on done queue. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001554 if (rsp->status_srb == NULL)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001555 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556}
1557
1558/**
1559 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1560 * @ha: SCSI driver HA context
1561 * @pkt: Entry pointer
1562 *
1563 * Extended sense data.
1564 */
1565static void
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001566qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567{
1568 uint8_t sense_sz = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001569 struct qla_hw_data *ha = rsp->hw;
1570 srb_t *sp = rsp->status_srb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 struct scsi_cmnd *cp;
1572
1573 if (sp != NULL && sp->request_sense_length != 0) {
1574 cp = sp->cmd;
1575 if (cp == NULL) {
1576 DEBUG2(printk("%s(): Cmd already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001577 "sp=%p.\n", __func__, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 qla_printk(KERN_INFO, ha,
1579 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001580 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001582 rsp->status_srb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 return;
1584 }
1585
1586 if (sp->request_sense_length > sizeof(pkt->data)) {
1587 sense_sz = sizeof(pkt->data);
1588 } else {
1589 sense_sz = sp->request_sense_length;
1590 }
1591
1592 /* Move sense data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001593 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001594 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1596 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1597
1598 sp->request_sense_ptr += sense_sz;
1599 sp->request_sense_length -= sense_sz;
1600
1601 /* Place command on done queue. */
1602 if (sp->request_sense_length == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001603 rsp->status_srb = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001604 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 }
1606 }
1607}
1608
1609/**
1610 * qla2x00_error_entry() - Process an error entry.
1611 * @ha: SCSI driver HA context
1612 * @pkt: Entry pointer
1613 */
1614static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001615qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616{
1617 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001618 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001619 uint32_t handle = LSW(pkt->handle);
1620 uint16_t que = MSW(pkt->handle);
1621 struct req_que *req = ha->req_q_map[que];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622#if defined(QL_DEBUG_LEVEL_2)
1623 if (pkt->entry_status & RF_INV_E_ORDER)
1624 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1625 else if (pkt->entry_status & RF_INV_E_COUNT)
1626 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1627 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001628 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 "%s: Invalid Entry Parameter\n", __func__);
1630 else if (pkt->entry_status & RF_INV_E_TYPE)
1631 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1632 else if (pkt->entry_status & RF_BUSY)
1633 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1634 else
1635 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1636#endif
1637
1638 /* Validate handle. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001639 if (handle < MAX_OUTSTANDING_COMMANDS)
1640 sp = req->outstanding_cmds[handle];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 else
1642 sp = NULL;
1643
1644 if (sp) {
1645 /* Free outstanding command slot. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001646 req->outstanding_cmds[handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001647
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 /* Bad payload or header */
1649 if (pkt->entry_status &
1650 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1651 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1652 sp->cmd->result = DID_ERROR << 16;
1653 } else if (pkt->entry_status & RF_BUSY) {
1654 sp->cmd->result = DID_BUS_BUSY << 16;
1655 } else {
1656 sp->cmd->result = DID_ERROR << 16;
1657 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001658 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001660 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1661 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001663 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 qla_printk(KERN_WARNING, ha,
1665 "Error entry - invalid handle\n");
1666
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001667 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1668 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 }
1670}
1671
1672/**
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001673 * qla24xx_mbx_completion() - Process mailbox command completions.
1674 * @ha: SCSI driver HA context
1675 * @mb0: Mailbox0 register
1676 */
1677static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001678qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001679{
1680 uint16_t cnt;
1681 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001682 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001683 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1684
1685 /* Load return mailbox registers. */
1686 ha->flags.mbox_int = 1;
1687 ha->mailbox_out[0] = mb0;
1688 wptr = (uint16_t __iomem *)&reg->mailbox1;
1689
1690 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1691 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1692 wptr++;
1693 }
1694
1695 if (ha->mcp) {
1696 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001697 __func__, vha->host_no, ha->mcp->mb[0]));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001698 } else {
1699 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001700 __func__, vha->host_no));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001701 }
1702}
1703
1704/**
1705 * qla24xx_process_response_queue() - Process response queue entries.
1706 * @ha: SCSI driver HA context
1707 */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001708void qla24xx_process_response_queue(struct scsi_qla_host *vha,
1709 struct rsp_que *rsp)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001710{
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001711 struct sts_entry_24xx *pkt;
1712
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001713 if (!vha->flags.online)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001714 return;
1715
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001716 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1717 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001718
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001719 rsp->ring_index++;
1720 if (rsp->ring_index == rsp->length) {
1721 rsp->ring_index = 0;
1722 rsp->ring_ptr = rsp->ring;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001723 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001724 rsp->ring_ptr++;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001725 }
1726
1727 if (pkt->entry_status != 0) {
1728 DEBUG3(printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001729 "scsi(%ld): Process error entry.\n", vha->host_no));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001730
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001731 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001732 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1733 wmb();
1734 continue;
1735 }
1736
1737 switch (pkt->entry_type) {
1738 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001739 qla2x00_status_entry(vha, rsp, pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001740 break;
1741 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001742 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001743 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001744 case VP_RPT_ID_IOCB_TYPE:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001745 qla24xx_report_id_acquisition(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001746 (struct vp_rpt_id_entry_24xx *)pkt);
1747 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001748 case LOGINOUT_PORT_IOCB_TYPE:
1749 qla24xx_logio_entry(vha, rsp->req,
1750 (struct logio_entry_24xx *)pkt);
1751 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001752 default:
1753 /* Type Not Supported. */
1754 DEBUG4(printk(KERN_WARNING
1755 "scsi(%ld): Received unknown response pkt type %x "
1756 "entry status=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001757 vha->host_no, pkt->entry_type, pkt->entry_status));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001758 break;
1759 }
1760 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1761 wmb();
1762 }
1763
1764 /* Adjust ring index */
Andrew Vasquez08029992009-03-24 09:07:55 -07001765 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001766}
1767
Andrew Vasquez05236a02007-09-20 14:07:37 -07001768static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001769qla2xxx_check_risc_status(scsi_qla_host_t *vha)
Andrew Vasquez05236a02007-09-20 14:07:37 -07001770{
1771 int rval;
1772 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001773 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez05236a02007-09-20 14:07:37 -07001774 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1775
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001776 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez05236a02007-09-20 14:07:37 -07001777 return;
1778
1779 rval = QLA_SUCCESS;
1780 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1781 RD_REG_DWORD(&reg->iobase_addr);
1782 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1783 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1784 rval == QLA_SUCCESS; cnt--) {
1785 if (cnt) {
1786 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1787 udelay(10);
1788 } else
1789 rval = QLA_FUNCTION_TIMEOUT;
1790 }
1791 if (rval == QLA_SUCCESS)
1792 goto next_test;
1793
1794 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1795 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1796 rval == QLA_SUCCESS; cnt--) {
1797 if (cnt) {
1798 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1799 udelay(10);
1800 } else
1801 rval = QLA_FUNCTION_TIMEOUT;
1802 }
1803 if (rval != QLA_SUCCESS)
1804 goto done;
1805
1806next_test:
1807 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
1808 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1809
1810done:
1811 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
1812 RD_REG_DWORD(&reg->iobase_window);
1813}
1814
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001815/**
1816 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1817 * @irq:
1818 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001819 *
1820 * Called by system whenever the host adapter generates an interrupt.
1821 *
1822 * Returns handled flag.
1823 */
1824irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001825qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001826{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001827 scsi_qla_host_t *vha;
1828 struct qla_hw_data *ha;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001829 struct device_reg_24xx __iomem *reg;
1830 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001831 unsigned long iter;
1832 uint32_t stat;
1833 uint32_t hccr;
1834 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001835 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07001836 unsigned long flags;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001837
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001838 rsp = (struct rsp_que *) dev_id;
1839 if (!rsp) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001840 printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001841 "%s(): NULL response queue pointer\n", __func__);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001842 return IRQ_NONE;
1843 }
1844
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001845 ha = rsp->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001846 reg = &ha->iobase->isp24;
1847 status = 0;
1848
Andrew Vasquez85880802009-12-15 21:29:46 -08001849 if (unlikely(pci_channel_offline(ha->pdev)))
1850 return IRQ_HANDLED;
1851
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07001852 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001853 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001854 for (iter = 50; iter--; ) {
1855 stat = RD_REG_DWORD(&reg->host_status);
1856 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08001857 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07001858 break;
1859
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001860 hccr = RD_REG_DWORD(&reg->hccr);
1861
1862 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1863 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001864
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001865 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001866
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001867 ha->isp_ops->fw_dump(vha, 1);
1868 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001869 break;
1870 } else if ((stat & HSRX_RISC_INT) == 0)
1871 break;
1872
1873 switch (stat & 0xff) {
1874 case 0x1:
1875 case 0x2:
1876 case 0x10:
1877 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001878 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001879 status |= MBX_INTERRUPT;
1880
1881 break;
1882 case 0x12:
1883 mb[0] = MSW(stat);
1884 mb[1] = RD_REG_WORD(&reg->mailbox1);
1885 mb[2] = RD_REG_WORD(&reg->mailbox2);
1886 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001887 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001888 break;
1889 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001890 case 0x14:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001891 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001892 break;
1893 default:
1894 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1895 "(%d).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001896 vha->host_no, stat & 0xff));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001897 break;
1898 }
1899 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1900 RD_REG_DWORD_RELAXED(&reg->hccr);
1901 }
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07001902 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001903
1904 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1905 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001906 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001907 complete(&ha->mbx_intr_comp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001908 }
1909
1910 return IRQ_HANDLED;
1911}
1912
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001913static irqreturn_t
1914qla24xx_msix_rsp_q(int irq, void *dev_id)
1915{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001916 struct qla_hw_data *ha;
1917 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001918 struct device_reg_24xx __iomem *reg;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001919 struct scsi_qla_host *vha;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001920
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001921 rsp = (struct rsp_que *) dev_id;
1922 if (!rsp) {
1923 printk(KERN_INFO
1924 "%s(): NULL response queue pointer\n", __func__);
1925 return IRQ_NONE;
1926 }
1927 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001928 reg = &ha->iobase->isp24;
1929
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001930 spin_lock_irq(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001931
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001932 vha = qla25xx_get_host(rsp);
1933 qla24xx_process_response_queue(vha, rsp);
Anirban Chakraborty31557542009-12-02 10:36:55 -08001934 if (!ha->flags.disable_msix_handshake) {
Anirban Chakrabortyeb941142009-08-04 16:12:13 -07001935 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1936 RD_REG_DWORD_RELAXED(&reg->hccr);
1937 }
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001938 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001939
1940 return IRQ_HANDLED;
1941}
1942
1943static irqreturn_t
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001944qla25xx_msix_rsp_q(int irq, void *dev_id)
1945{
1946 struct qla_hw_data *ha;
1947 struct rsp_que *rsp;
Anirban Chakraborty31557542009-12-02 10:36:55 -08001948 struct device_reg_24xx __iomem *reg;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001949
1950 rsp = (struct rsp_que *) dev_id;
1951 if (!rsp) {
1952 printk(KERN_INFO
1953 "%s(): NULL response queue pointer\n", __func__);
1954 return IRQ_NONE;
1955 }
1956 ha = rsp->hw;
1957
Anirban Chakraborty31557542009-12-02 10:36:55 -08001958 /* Clear the interrupt, if enabled, for this response queue */
1959 if (rsp->options & ~BIT_6) {
1960 reg = &ha->iobase->isp24;
1961 spin_lock_irq(&ha->hardware_lock);
1962 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1963 RD_REG_DWORD_RELAXED(&reg->hccr);
1964 spin_unlock_irq(&ha->hardware_lock);
1965 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001966 queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work);
1967
1968 return IRQ_HANDLED;
1969}
1970
1971static irqreturn_t
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001972qla24xx_msix_default(int irq, void *dev_id)
1973{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001974 scsi_qla_host_t *vha;
1975 struct qla_hw_data *ha;
1976 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001977 struct device_reg_24xx __iomem *reg;
1978 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001979 uint32_t stat;
1980 uint32_t hccr;
1981 uint16_t mb[4];
1982
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001983 rsp = (struct rsp_que *) dev_id;
1984 if (!rsp) {
1985 DEBUG(printk(
1986 "%s(): NULL response queue pointer\n", __func__));
1987 return IRQ_NONE;
1988 }
1989 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001990 reg = &ha->iobase->isp24;
1991 status = 0;
1992
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001993 spin_lock_irq(&ha->hardware_lock);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001994 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001995 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001996 stat = RD_REG_DWORD(&reg->host_status);
1997 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08001998 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07001999 break;
2000
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002001 hccr = RD_REG_DWORD(&reg->hccr);
2002
2003 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
2004 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002005
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002006 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002007
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002008 ha->isp_ops->fw_dump(vha, 1);
2009 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002010 break;
2011 } else if ((stat & HSRX_RISC_INT) == 0)
2012 break;
2013
2014 switch (stat & 0xff) {
2015 case 0x1:
2016 case 0x2:
2017 case 0x10:
2018 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002019 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002020 status |= MBX_INTERRUPT;
2021
2022 break;
2023 case 0x12:
2024 mb[0] = MSW(stat);
2025 mb[1] = RD_REG_WORD(&reg->mailbox1);
2026 mb[2] = RD_REG_WORD(&reg->mailbox2);
2027 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002028 qla2x00_async_event(vha, rsp, mb);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002029 break;
2030 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002031 case 0x14:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002032 qla24xx_process_response_queue(vha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002033 break;
2034 default:
2035 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
2036 "(%d).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002037 vha->host_no, stat & 0xff));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002038 break;
2039 }
2040 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002041 } while (0);
Andrew Vasquez0e973a22008-05-12 22:21:09 -07002042 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002043
2044 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
2045 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002046 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002047 complete(&ha->mbx_intr_comp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002048 }
2049
2050 return IRQ_HANDLED;
2051}
2052
2053/* Interrupt handling helpers. */
2054
2055struct qla_init_msix_entry {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002056 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07002057 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002058};
2059
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002060static struct qla_init_msix_entry msix_entries[3] = {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002061 { "qla2xxx (default)", qla24xx_msix_default },
2062 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002063 { "qla2xxx (multiq)", qla25xx_msix_rsp_q },
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002064};
2065
2066static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002067qla24xx_disable_msix(struct qla_hw_data *ha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002068{
2069 int i;
2070 struct qla_msix_entry *qentry;
2071
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002072 for (i = 0; i < ha->msix_count; i++) {
2073 qentry = &ha->msix_entries[i];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002074 if (qentry->have_irq)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002075 free_irq(qentry->vector, qentry->rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002076 }
2077 pci_disable_msix(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002078 kfree(ha->msix_entries);
2079 ha->msix_entries = NULL;
2080 ha->flags.msix_enabled = 0;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002081}
2082
2083static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002084qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002085{
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002086#define MIN_MSIX_COUNT 2
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002087 int i, ret;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002088 struct msix_entry *entries;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002089 struct qla_msix_entry *qentry;
2090
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002091 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
2092 GFP_KERNEL);
2093 if (!entries)
2094 return -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002095
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002096 for (i = 0; i < ha->msix_count; i++)
2097 entries[i].entry = i;
2098
2099 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002100 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002101 if (ret < MIN_MSIX_COUNT)
2102 goto msix_failed;
2103
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002104 qla_printk(KERN_WARNING, ha,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002105 "MSI-X: Failed to enable support -- %d/%d\n"
2106 " Retry with %d vectors\n", ha->msix_count, ret, ret);
2107 ha->msix_count = ret;
2108 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
2109 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002110msix_failed:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002111 qla_printk(KERN_WARNING, ha, "MSI-X: Failed to enable"
2112 " support, giving up -- %d/%d\n",
2113 ha->msix_count, ret);
2114 goto msix_out;
2115 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002116 ha->max_rsp_queues = ha->msix_count - 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002117 }
2118 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
2119 ha->msix_count, GFP_KERNEL);
2120 if (!ha->msix_entries) {
2121 ret = -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002122 goto msix_out;
2123 }
2124 ha->flags.msix_enabled = 1;
2125
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002126 for (i = 0; i < ha->msix_count; i++) {
2127 qentry = &ha->msix_entries[i];
2128 qentry->vector = entries[i].vector;
2129 qentry->entry = entries[i].entry;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002130 qentry->have_irq = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002131 qentry->rsp = NULL;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002132 }
2133
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002134 /* Enable MSI-X vectors for the base queue */
2135 for (i = 0; i < 2; i++) {
2136 qentry = &ha->msix_entries[i];
2137 ret = request_irq(qentry->vector, msix_entries[i].handler,
2138 0, msix_entries[i].name, rsp);
2139 if (ret) {
2140 qla_printk(KERN_WARNING, ha,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002141 "MSI-X: Unable to register handler -- %x/%d.\n",
2142 qentry->vector, ret);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002143 qla24xx_disable_msix(ha);
2144 ha->mqenable = 0;
2145 goto msix_out;
2146 }
2147 qentry->have_irq = 1;
2148 qentry->rsp = rsp;
2149 rsp->msix = qentry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002150 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002151
2152 /* Enable MSI-X vector for response queue update for queue 0 */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002153 if (ha->mqiobase && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002154 ha->mqenable = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002155
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002156msix_out:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002157 kfree(entries);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002158 return ret;
2159}
2160
2161int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002162qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002163{
2164 int ret;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002165 device_reg_t __iomem *reg = ha->iobase;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002166
2167 /* If possible, enable MSI-X. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002168 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) &&
2169 !IS_QLA8432(ha) && !IS_QLA8001(ha))
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002170 goto skip_msix;
2171
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002172 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX ||
2173 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002174 DEBUG2(qla_printk(KERN_WARNING, ha,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002175 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
2176 ha->pdev->revision, ha->fw_attributes));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002177
2178 goto skip_msix;
2179 }
2180
Andrew Vasquezda7429f2008-01-17 09:02:11 -08002181 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
2182 (ha->pdev->subsystem_device == 0x7040 ||
2183 ha->pdev->subsystem_device == 0x7041 ||
2184 ha->pdev->subsystem_device == 0x1705)) {
2185 DEBUG2(qla_printk(KERN_WARNING, ha,
2186 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
2187 ha->pdev->subsystem_vendor,
2188 ha->pdev->subsystem_device));
2189
2190 goto skip_msi;
2191 }
2192
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002193 ret = qla24xx_enable_msix(ha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002194 if (!ret) {
2195 DEBUG2(qla_printk(KERN_INFO, ha,
2196 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
2197 ha->fw_attributes));
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002198 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002199 }
2200 qla_printk(KERN_WARNING, ha,
2201 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
2202skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002203
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002204 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
2205 !IS_QLA8001(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002206 goto skip_msi;
2207
2208 ret = pci_enable_msi(ha->pdev);
2209 if (!ret) {
2210 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
2211 ha->flags.msi_enabled = 1;
2212 }
2213skip_msi:
2214
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002215 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Giridhar Malavalid1b1bef2009-03-24 09:08:13 -07002216 IRQF_SHARED, QLA2XXX_DRIVER_NAME, rsp);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002217 if (ret) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002218 qla_printk(KERN_WARNING, ha,
2219 "Failed to reserve interrupt %d already in use.\n",
2220 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002221 goto fail;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002222 }
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002223 ha->flags.inta_enabled = 1;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002224clear_risc_ints:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002225
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002226 /*
2227 * FIXME: Noted that 8014s were being dropped during NK testing.
2228 * Timing deltas during MSI-X/INTa transitions?
2229 */
2230 if (IS_QLA81XX(ha))
2231 goto fail;
Andrew Vasquezc6952482008-04-03 13:13:17 -07002232 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002233 if (IS_FWI2_CAPABLE(ha)) {
2234 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
2235 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
2236 } else {
2237 WRT_REG_WORD(&reg->isp.semaphore, 0);
2238 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
2239 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
2240 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07002241 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002242
2243fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002244 return ret;
2245}
2246
2247void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002248qla2x00_free_irqs(scsi_qla_host_t *vha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002249{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002250 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002251 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002252
2253 if (ha->flags.msix_enabled)
2254 qla24xx_disable_msix(ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002255 else if (ha->flags.inta_enabled) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002256 free_irq(ha->pdev->irq, rsp);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002257 pci_disable_msi(ha->pdev);
2258 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002259}
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002260
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002261
2262int qla25xx_request_irq(struct rsp_que *rsp)
2263{
2264 struct qla_hw_data *ha = rsp->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002265 struct qla_init_msix_entry *intr = &msix_entries[2];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002266 struct qla_msix_entry *msix = rsp->msix;
2267 int ret;
2268
2269 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
2270 if (ret) {
2271 qla_printk(KERN_WARNING, ha,
2272 "MSI-X: Unable to register handler -- %x/%d.\n",
2273 msix->vector, ret);
2274 return ret;
2275 }
2276 msix->have_irq = 1;
2277 msix->rsp = rsp;
2278 return ret;
2279}
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002280
2281struct scsi_qla_host *
2282qla25xx_get_host(struct rsp_que *rsp)
2283{
2284 srb_t *sp;
2285 struct qla_hw_data *ha = rsp->hw;
2286 struct scsi_qla_host *vha = NULL;
2287 struct sts_entry_24xx *pkt;
2288 struct req_que *req;
2289 uint16_t que;
2290 uint32_t handle;
2291
2292 pkt = (struct sts_entry_24xx *) rsp->ring_ptr;
2293 que = MSW(pkt->handle);
2294 handle = (uint32_t) LSW(pkt->handle);
2295 req = ha->req_q_map[que];
2296 if (handle < MAX_OUTSTANDING_COMMANDS) {
2297 sp = req->outstanding_cmds[handle];
2298 if (sp)
2299 return sp->fcport->vha;
2300 else
2301 goto base_que;
2302 }
2303base_que:
2304 vha = pci_get_drvdata(ha->pdev);
2305 return vha;
2306}