blob: eed71ea1d9473fcd3c0837a195943c8cf935c749 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070011#include <scsi/scsi_tcq.h>
Giridhar Malavali9a069e12010-01-12 13:02:47 -080012#include <scsi/scsi_bsg_fc.h>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070013
Linus Torvalds1da177e2005-04-16 15:20:36 -070014static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080015static void qla2x00_process_completed_request(struct scsi_qla_host *,
16 struct req_que *, uint32_t);
17static void qla2x00_status_entry(scsi_qla_host_t *, struct rsp_que *, void *);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070018static void qla2x00_status_cont_entry(struct rsp_que *, sts_cont_entry_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080019static void qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
20 sts_entry_t *);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022/**
23 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
24 * @irq:
25 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 *
27 * Called by system whenever the host adapter generates an interrupt.
28 *
29 * Returns handled flag.
30 */
31irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +010032qla2100_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080034 scsi_qla_host_t *vha;
35 struct qla_hw_data *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -070036 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 unsigned long iter;
Seokmann Ju14e660e2007-09-20 14:07:36 -070039 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070040 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080041 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070042 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080044 rsp = (struct rsp_que *) dev_id;
45 if (!rsp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080047 "%s(): NULL response queue pointer\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 return (IRQ_NONE);
49 }
50
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080051 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -070052 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 status = 0;
54
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070055 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070056 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 for (iter = 50; iter--; ) {
Seokmann Ju14e660e2007-09-20 14:07:36 -070058 hccr = RD_REG_WORD(&reg->hccr);
59 if (hccr & HCCR_RISC_PAUSE) {
60 if (pci_channel_offline(ha->pdev))
61 break;
62
63 /*
64 * Issue a "HARD" reset in order for the RISC interrupt
65 * bit to be cleared. Schedule a big hammmer to get
66 * out of the RISC PAUSED state.
67 */
68 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
69 RD_REG_WORD(&reg->hccr);
70
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080071 ha->isp_ops->fw_dump(vha, 1);
72 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -070073 break;
74 } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 break;
76
77 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
78 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
79 RD_REG_WORD(&reg->hccr);
80
81 /* Get mailbox data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -070082 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
83 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080084 qla2x00_mbx_completion(vha, mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 status |= MBX_INTERRUPT;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070086 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
87 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
88 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
89 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080090 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 } else {
92 /*EMPTY*/
93 DEBUG2(printk("scsi(%ld): Unrecognized "
Andrew Vasquez9a853f72005-07-06 10:31:27 -070094 "interrupt type (%d).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080095 vha->host_no, mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 }
97 /* Release mailbox registers. */
98 WRT_REG_WORD(&reg->semaphore, 0);
99 RD_REG_WORD(&reg->semaphore);
100 } else {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800101 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
104 RD_REG_WORD(&reg->hccr);
105 }
106 }
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700107 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
110 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800112 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 }
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 return (IRQ_HANDLED);
116}
117
118/**
119 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
120 * @irq:
121 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 *
123 * Called by system whenever the host adapter generates an interrupt.
124 *
125 * Returns handled flag.
126 */
127irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100128qla2300_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800130 scsi_qla_host_t *vha;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700131 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 unsigned long iter;
134 uint32_t stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700136 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800137 struct rsp_que *rsp;
138 struct qla_hw_data *ha;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700139 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800141 rsp = (struct rsp_que *) dev_id;
142 if (!rsp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800144 "%s(): NULL response queue pointer\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 return (IRQ_NONE);
146 }
147
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800148 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700149 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 status = 0;
151
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700152 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700153 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 for (iter = 50; iter--; ) {
155 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
156 if (stat & HSR_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800157 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -0700158 break;
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 hccr = RD_REG_WORD(&reg->hccr);
161 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Andrew Vasquez07f31802006-12-13 19:20:31 -0800162 qla_printk(KERN_INFO, ha, "Parity error -- "
163 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 else
Andrew Vasquez07f31802006-12-13 19:20:31 -0800165 qla_printk(KERN_INFO, ha, "RISC paused -- "
166 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 /*
169 * Issue a "HARD" reset in order for the RISC
170 * interrupt bit to be cleared. Schedule a big
171 * hammmer to get out of the RISC PAUSED state.
172 */
173 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
174 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800175
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800176 ha->isp_ops->fw_dump(vha, 1);
177 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 break;
179 } else if ((stat & HSR_RISC_INT) == 0)
180 break;
181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 case 0x1:
184 case 0x2:
185 case 0x10:
186 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800187 qla2x00_mbx_completion(vha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 status |= MBX_INTERRUPT;
189
190 /* Release mailbox registers. */
191 WRT_REG_WORD(&reg->semaphore, 0);
192 break;
193 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700194 mb[0] = MSW(stat);
195 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
196 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
197 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800198 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700199 break;
200 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800201 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 break;
203 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700204 mb[0] = MBA_CMPLT_1_16BIT;
205 mb[1] = MSW(stat);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800206 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 break;
208 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700209 mb[0] = MBA_SCSI_COMPLETION;
210 mb[1] = MSW(stat);
211 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800212 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 break;
214 default:
215 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700216 "(%d).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800217 vha->host_no, stat & 0xff));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 break;
219 }
220 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
221 RD_REG_WORD_RELAXED(&reg->hccr);
222 }
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700223 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
226 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800228 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 }
230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 return (IRQ_HANDLED);
232}
233
234/**
235 * qla2x00_mbx_completion() - Process mailbox command completions.
236 * @ha: SCSI driver HA context
237 * @mb0: Mailbox0 register
238 */
239static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800240qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
242 uint16_t cnt;
243 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800244 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700245 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
247 /* Load return mailbox registers. */
248 ha->flags.mbox_int = 1;
249 ha->mailbox_out[0] = mb0;
250 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
251
252 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700253 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
255 if (cnt == 4 || cnt == 5)
256 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
257 else
258 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 wptr++;
261 }
262
263 if (ha->mcp) {
264 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800265 __func__, vha->host_no, ha->mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 } else {
267 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800268 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 }
270}
271
Andrew Vasquez8a659572009-02-08 20:50:12 -0800272static void
273qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
274{
275 static char *event[] =
276 { "Complete", "Request Notification", "Time Extension" };
277 int rval;
278 struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
279 uint16_t __iomem *wptr;
280 uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
281
282 /* Seed data -- mailbox1 -> mailbox7. */
283 wptr = (uint16_t __iomem *)&reg24->mailbox1;
284 for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
285 mb[cnt] = RD_REG_WORD(wptr);
286
287 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- "
288 "%04x %04x %04x %04x %04x %04x %04x.\n", vha->host_no,
289 event[aen & 0xff],
290 mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6]));
291
292 /* Acknowledgement needed? [Notify && non-zero timeout]. */
293 timeout = (descr >> 8) & 0xf;
294 if (aen != MBA_IDC_NOTIFY || !timeout)
295 return;
296
297 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- "
298 "ACK timeout=%d.\n", vha->host_no, event[aen & 0xff], timeout));
299
300 rval = qla2x00_post_idc_ack_work(vha, mb);
301 if (rval != QLA_SUCCESS)
302 qla_printk(KERN_WARNING, vha->hw,
303 "IDC failed to post ACK.\n");
304}
305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306/**
307 * qla2x00_async_event() - Process aynchronous events.
308 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700309 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700311void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800312qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700314#define LS_UNKNOWN 2
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800315 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 char *link_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 uint16_t handle_cnt;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700318 uint16_t cnt, mbx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 uint32_t handles[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800320 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700321 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700322 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 uint32_t rscn_entry, host_pid;
324 uint8_t rscn_queue_index;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700325 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
327 /* Setup to process RIO completion. */
328 handle_cnt = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700329 if (IS_QLA8XXX_TYPE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800330 goto skip_rio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 switch (mb[0]) {
332 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700333 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 handle_cnt = 1;
335 break;
336 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700337 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 handle_cnt = 1;
339 mb[0] = MBA_SCSI_COMPLETION;
340 break;
341 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700342 handles[0] = mb[1];
343 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 handle_cnt = 2;
345 mb[0] = MBA_SCSI_COMPLETION;
346 break;
347 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700348 handles[0] = mb[1];
349 handles[1] = mb[2];
350 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 handle_cnt = 3;
352 mb[0] = MBA_SCSI_COMPLETION;
353 break;
354 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700355 handles[0] = mb[1];
356 handles[1] = mb[2];
357 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
359 handle_cnt = 4;
360 mb[0] = MBA_SCSI_COMPLETION;
361 break;
362 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700363 handles[0] = mb[1];
364 handles[1] = mb[2];
365 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
367 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
368 handle_cnt = 5;
369 mb[0] = MBA_SCSI_COMPLETION;
370 break;
371 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700372 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 handles[1] = le32_to_cpu(
374 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
375 RD_MAILBOX_REG(ha, reg, 6));
376 handle_cnt = 2;
377 mb[0] = MBA_SCSI_COMPLETION;
378 break;
379 default:
380 break;
381 }
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800382skip_rio:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 switch (mb[0]) {
384 case MBA_SCSI_COMPLETION: /* Fast Post */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800385 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 break;
387
388 for (cnt = 0; cnt < handle_cnt; cnt++)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800389 qla2x00_process_completed_request(vha, rsp->req,
390 handles[cnt]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 break;
392
393 case MBA_RESET: /* Reset */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800394 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n",
395 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800397 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 break;
399
400 case MBA_SYSTEM_ERR: /* System Error */
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700401 mbx = IS_QLA81XX(ha) ? RD_REG_WORD(&reg24->mailbox7) : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 qla_printk(KERN_INFO, ha,
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700403 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh "
404 "mbx7=%xh.\n", mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800406 ha->isp_ops->fw_dump(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Andrew Vasqueze4289242007-07-19 15:05:56 -0700408 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700409 if (mb[1] == 0 && mb[2] == 0) {
410 qla_printk(KERN_ERR, ha,
411 "Unrecoverable Hardware Error: adapter "
412 "marked OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800413 vha->flags.online = 0;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700414 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800415 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700416 } else if (mb[1] == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 qla_printk(KERN_INFO, ha,
418 "Unrecoverable Hardware Error: adapter marked "
419 "OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800420 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800422 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 break;
424
425 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700426 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error (%x).\n",
427 vha->host_no, mb[1]));
428 qla_printk(KERN_WARNING, ha,
429 "ISP Request Transfer Error (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800431 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 break;
433
434 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
435 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800436 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
438
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800439 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 break;
441
442 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
443 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800444 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 break;
446
447 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800448 DEBUG2(printk("scsi(%ld): LIP occurred (%x).\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 mb[1]));
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700450 qla_printk(KERN_INFO, ha, "LIP occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800452 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
453 atomic_set(&vha->loop_state, LOOP_DOWN);
454 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
455 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 }
457
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800458 if (vha->vp_idx) {
459 atomic_set(&vha->vp_state, VP_FAILED);
460 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700461 }
462
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800463 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
464 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800466 vha->flags.management_server_logged_in = 0;
467 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 break;
469
470 case MBA_LOOP_UP: /* Loop Up Event */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
472 link_speed = link_speeds[0];
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700473 ha->link_data_rate = PORT_SPEED_1GB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 } else {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700475 link_speed = link_speeds[LS_UNKNOWN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 if (mb[1] < 5)
477 link_speed = link_speeds[mb[1]];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800478 else if (mb[1] == 0x13)
479 link_speed = link_speeds[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 ha->link_data_rate = mb[1];
481 }
482
483 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800484 vha->host_no, link_speed));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
486 link_speed);
487
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800488 vha->flags.management_server_logged_in = 0;
489 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 break;
491
492 case MBA_LOOP_DOWN: /* Loop Down Event */
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700493 mbx = IS_QLA81XX(ha) ? RD_REG_WORD(&reg24->mailbox4) : 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700494 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN "
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700495 "(%x %x %x %x).\n", vha->host_no, mb[1], mb[2], mb[3],
496 mbx));
497 qla_printk(KERN_INFO, ha,
498 "LOOP DOWN detected (%x %x %x %x).\n", mb[1], mb[2], mb[3],
499 mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800501 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
502 atomic_set(&vha->loop_state, LOOP_DOWN);
503 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
504 vha->device_flags |= DFLG_NO_CABLE;
505 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 }
507
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800508 if (vha->vp_idx) {
509 atomic_set(&vha->vp_state, VP_FAILED);
510 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700511 }
512
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800513 vha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700514 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800515 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 break;
517
518 case MBA_LIP_RESET: /* LIP reset occurred */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800520 vha->host_no, mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 qla_printk(KERN_INFO, ha,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700522 "LIP reset occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800524 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
525 atomic_set(&vha->loop_state, LOOP_DOWN);
526 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
527 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 }
529
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800530 if (vha->vp_idx) {
531 atomic_set(&vha->vp_state, VP_FAILED);
532 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700533 }
534
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800535 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
537 ha->operating_mode = LOOP;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800538 vha->flags.management_server_logged_in = 0;
539 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 break;
541
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800542 /* case MBA_DCBX_COMPLETE: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 case MBA_POINT_TO_POINT: /* Point-to-Point */
544 if (IS_QLA2100(ha))
545 break;
546
Giridhar Malavalia9083012010-04-12 17:59:55 -0700547 if (IS_QLA8XXX_TYPE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800548 DEBUG2(printk("scsi(%ld): DCBX Completed -- %04x %04x "
549 "%04x\n", vha->host_no, mb[1], mb[2], mb[3]));
550 else
551 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE "
552 "received.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
554 /*
555 * Until there's a transition from loop down to loop up, treat
556 * this as loop down only.
557 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800558 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
559 atomic_set(&vha->loop_state, LOOP_DOWN);
560 if (!atomic_read(&vha->loop_down_timer))
561 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800563 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 }
565
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800566 if (vha->vp_idx) {
567 atomic_set(&vha->vp_state, VP_FAILED);
568 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700569 }
570
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800571 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
572 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
573
574 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
575 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800576
577 ha->flags.gpsc_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800578 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 break;
580
581 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
582 if (IS_QLA2100(ha))
583 break;
584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
586 "received.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800587 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 qla_printk(KERN_INFO, ha,
589 "Configuration change detected: value=%x.\n", mb[1]);
590
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800591 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
592 atomic_set(&vha->loop_state, LOOP_DOWN);
593 if (!atomic_read(&vha->loop_down_timer))
594 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800596 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 }
598
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800599 if (vha->vp_idx) {
600 atomic_set(&vha->vp_state, VP_FAILED);
601 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700602 }
603
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800604 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
605 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 break;
607
608 case MBA_PORT_UPDATE: /* Port database update */
Santosh Vernekar55903b92009-07-31 15:09:25 -0700609 /*
610 * Handle only global and vn-port update events
611 *
612 * Relevant inputs:
613 * mb[1] = N_Port handle of changed port
614 * OR 0xffff for global event
615 * mb[2] = New login state
616 * 7 = Port logged out
617 * mb[3] = LSB is vp_idx, 0xff = all vps
618 *
619 * Skip processing if:
620 * Event is global, vp_idx is NOT all vps,
621 * vp_idx does not match
622 * Event is not global, vp_idx does not match
623 */
Andrew Vasquez12cec63e42010-03-19 16:59:17 -0700624 if (IS_QLA2XXX_MIDTYPE(ha) &&
625 ((mb[1] == 0xffff && (mb[3] & 0xff) != 0xff) ||
626 (mb[1] != 0xffff)) && vha->vp_idx != (mb[3] & 0xff))
627 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800628
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700629 /* Global event -- port logout or port unavailable. */
630 if (mb[1] == 0xffff && mb[2] == 0x7) {
631 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
632 vha->host_no));
633 DEBUG(printk(KERN_INFO
634 "scsi(%ld): Port unavailable %04x %04x %04x.\n",
635 vha->host_no, mb[1], mb[2], mb[3]));
636
637 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
638 atomic_set(&vha->loop_state, LOOP_DOWN);
639 atomic_set(&vha->loop_down_timer,
640 LOOP_DOWN_TIME);
641 vha->device_flags |= DFLG_NO_CABLE;
642 qla2x00_mark_all_devices_lost(vha, 1);
643 }
644
645 if (vha->vp_idx) {
646 atomic_set(&vha->vp_state, VP_FAILED);
647 fc_vport_set_state(vha->fc_vport,
648 FC_VPORT_FAILED);
Santosh Vernekarfaadc5e2009-07-31 15:09:26 -0700649 qla2x00_mark_all_devices_lost(vha, 1);
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700650 }
651
652 vha->flags.management_server_logged_in = 0;
653 ha->link_data_rate = PORT_SPEED_UNKNOWN;
654 break;
655 }
656
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 /*
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700658 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 * event etc. earlier indicating loop is down) then process
660 * it. Otherwise ignore it and Wait for RSCN to come in.
661 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800662 atomic_set(&vha->loop_down_timer, 0);
663 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
664 atomic_read(&vha->loop_state) != LOOP_DEAD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800666 "ignored %04x/%04x/%04x.\n", vha->host_no, mb[1],
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700667 mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 break;
669 }
670
671 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800672 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 DEBUG(printk(KERN_INFO
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700674 "scsi(%ld): Port database changed %04x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800675 vha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
677 /*
678 * Mark all devices as missing so we will login again.
679 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800680 atomic_set(&vha->loop_state, LOOP_UP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800682 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800684 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800686 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
687 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 break;
689
690 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju3c397402008-05-19 14:25:39 -0700691 /* Check if the Vport has issued a SCR */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800692 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
Seokmann Ju3c397402008-05-19 14:25:39 -0700693 break;
694 /* Only handle SCNs for our Vport index. */
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700695 if (ha->flags.npiv_supported && vha->vp_idx != (mb[3] & 0xff))
Seokmann Ju3c397402008-05-19 14:25:39 -0700696 break;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800699 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 DEBUG(printk(KERN_INFO
Shyam Sundarf4a8dbc2007-11-12 10:30:59 -0800701 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800702 vha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Ravi Anand59d72d82008-09-11 21:22:53 -0700704 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800705 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
706 | vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 if (rscn_entry == host_pid) {
708 DEBUG(printk(KERN_INFO
709 "scsi(%ld): Ignoring RSCN update to local host "
710 "port ID (%06x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800711 vha->host_no, host_pid));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 break;
713 }
714
Ravi Anand59d72d82008-09-11 21:22:53 -0700715 /* Ignore reserved bits from RSCN-payload. */
716 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800717 rscn_queue_index = vha->rscn_in_ptr + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 if (rscn_queue_index == MAX_RSCN_COUNT)
719 rscn_queue_index = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800720 if (rscn_queue_index != vha->rscn_out_ptr) {
721 vha->rscn_queue[vha->rscn_in_ptr] = rscn_entry;
722 vha->rscn_in_ptr = rscn_queue_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800724 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 }
726
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800727 atomic_set(&vha->loop_state, LOOP_UPDATE);
728 atomic_set(&vha->loop_down_timer, 0);
729 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800731 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
732 set_bit(RSCN_UPDATE, &vha->dpc_flags);
733 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 break;
735
736 /* case MBA_RIO_RESPONSE: */
737 case MBA_ZIO_RESPONSE:
Andrew Vasquez3fd67cd2009-01-05 11:18:07 -0800738 DEBUG3(printk("scsi(%ld): [R|Z]IO update completion.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800739 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
Andrew Vasqueze4289242007-07-19 15:05:56 -0700741 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700742 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700743 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800744 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700746
747 case MBA_DISCARD_RND_FRAME:
748 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800749 "%04x.\n", vha->host_no, mb[1], mb[2], mb[3]));
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700750 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700751
752 case MBA_TRACE_NOTIFICATION:
753 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800754 vha->host_no, mb[1], mb[2]));
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700755 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700756
757 case MBA_ISP84XX_ALERT:
758 DEBUG2(printk("scsi(%ld): ISP84XX Alert Notification -- "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800759 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700760
761 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
762 switch (mb[1]) {
763 case A84_PANIC_RECOVERY:
764 qla_printk(KERN_INFO, ha, "Alert 84XX: panic recovery "
765 "%04x %04x\n", mb[2], mb[3]);
766 break;
767 case A84_OP_LOGIN_COMPLETE:
768 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
769 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
770 "firmware version %x\n", ha->cs84xx->op_fw_version));
771 break;
772 case A84_DIAG_LOGIN_COMPLETE:
773 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
774 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
775 "diagnostic firmware version %x\n",
776 ha->cs84xx->diag_fw_version));
777 break;
778 case A84_GOLD_LOGIN_COMPLETE:
779 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
780 ha->cs84xx->fw_update = 1;
781 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX: gold "
782 "firmware version %x\n",
783 ha->cs84xx->gold_fw_version));
784 break;
785 default:
786 qla_printk(KERN_ERR, ha,
787 "Alert 84xx: Invalid Alert %04x %04x %04x\n",
788 mb[1], mb[2], mb[3]);
789 }
790 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
791 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800792 case MBA_DCBX_START:
793 DEBUG2(printk("scsi(%ld): DCBX Started -- %04x %04x %04x\n",
794 vha->host_no, mb[1], mb[2], mb[3]));
795 break;
796 case MBA_DCBX_PARAM_UPDATE:
797 DEBUG2(printk("scsi(%ld): DCBX Parameters Updated -- "
798 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
799 break;
800 case MBA_FCF_CONF_ERR:
801 DEBUG2(printk("scsi(%ld): FCF Configuration Error -- "
802 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
803 break;
804 case MBA_IDC_COMPLETE:
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800805 case MBA_IDC_NOTIFY:
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800806 case MBA_IDC_TIME_EXT:
Andrew Vasquez8a659572009-02-08 20:50:12 -0800807 qla81xx_idc_event(vha, mb[0], mb[1]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800808 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700810
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800811 if (!vha->vp_idx && ha->num_vhosts)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800812 qla2x00_alert_all_vps(rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813}
814
815/**
816 * qla2x00_process_completed_request() - Process a Fast Post response.
817 * @ha: SCSI driver HA context
818 * @index: SRB index
819 */
820static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800821qla2x00_process_completed_request(struct scsi_qla_host *vha,
822 struct req_que *req, uint32_t index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823{
824 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800825 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
827 /* Validate handle. */
828 if (index >= MAX_OUTSTANDING_COMMANDS) {
829 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800830 vha->host_no, index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 qla_printk(KERN_WARNING, ha,
832 "Invalid SCSI completion handle %d.\n", index);
833
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800834 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 return;
836 }
837
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800838 sp = req->outstanding_cmds[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 if (sp) {
840 /* Free outstanding command slot. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800841 req->outstanding_cmds[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 /* Save ISP completion status */
844 sp->cmd->result = DID_OK << 16;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800845 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 } else {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700847 DEBUG2(printk("scsi(%ld) Req:%d: Invalid ISP SCSI completion"
Giridhar Malavalia9083012010-04-12 17:59:55 -0700848 " handle(0x%x)\n", vha->host_no, req->id, index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 qla_printk(KERN_WARNING, ha,
850 "Invalid ISP SCSI completion handle\n");
851
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800852 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 }
854}
855
Andrew Vasquezac280b62009-08-20 11:06:05 -0700856static srb_t *
857qla2x00_get_sp_from_handle(scsi_qla_host_t *vha, const char *func,
858 struct req_que *req, void *iocb)
859{
860 struct qla_hw_data *ha = vha->hw;
861 sts_entry_t *pkt = iocb;
862 srb_t *sp = NULL;
863 uint16_t index;
864
865 index = LSW(pkt->handle);
866 if (index >= MAX_OUTSTANDING_COMMANDS) {
867 qla_printk(KERN_WARNING, ha,
868 "%s: Invalid completion handle (%x).\n", func, index);
869 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
870 goto done;
871 }
872 sp = req->outstanding_cmds[index];
873 if (!sp) {
874 qla_printk(KERN_WARNING, ha,
875 "%s: Invalid completion handle (%x) -- timed-out.\n", func,
876 index);
877 return sp;
878 }
879 if (sp->handle != index) {
880 qla_printk(KERN_WARNING, ha,
881 "%s: SRB handle (%x) mismatch %x.\n", func, sp->handle,
882 index);
883 return NULL;
884 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800885
Andrew Vasquezac280b62009-08-20 11:06:05 -0700886 req->outstanding_cmds[index] = NULL;
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800887
Andrew Vasquezac280b62009-08-20 11:06:05 -0700888done:
889 return sp;
890}
891
892static void
893qla2x00_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
894 struct mbx_entry *mbx)
895{
896 const char func[] = "MBX-IOCB";
897 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700898 fc_port_t *fcport;
899 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700900 struct srb_iocb *lio;
901 struct srb_ctx *ctx;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700902 uint16_t *data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700903 uint16_t status;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700904
905 sp = qla2x00_get_sp_from_handle(vha, func, req, mbx);
906 if (!sp)
907 return;
908
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700909 ctx = sp->ctx;
910 lio = ctx->u.iocb_cmd;
911 type = ctx->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700912 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700913 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700914
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700915 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700916 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700917 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700918 if (mbx->entry_status) {
919 DEBUG2(printk(KERN_WARNING
920 "scsi(%ld:%x): Async-%s error entry - entry-status=%x "
921 "status=%x state-flag=%x status-flags=%x.\n",
922 fcport->vha->host_no, sp->handle, type,
923 mbx->entry_status, le16_to_cpu(mbx->status),
924 le16_to_cpu(mbx->state_flags),
925 le16_to_cpu(mbx->status_flags)));
926 DEBUG2(qla2x00_dump_buffer((uint8_t *)mbx, sizeof(*mbx)));
927
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700928 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700929 }
930
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700931 status = le16_to_cpu(mbx->status);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700932 if (status == 0x30 && ctx->type == SRB_LOGIN_CMD &&
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700933 le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE)
934 status = 0;
935 if (!status && le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE) {
Andrew Vasquezac280b62009-08-20 11:06:05 -0700936 DEBUG2(printk(KERN_DEBUG
937 "scsi(%ld:%x): Async-%s complete - mbx1=%x.\n",
938 fcport->vha->host_no, sp->handle, type,
939 le16_to_cpu(mbx->mb1)));
940
941 data[0] = MBS_COMMAND_COMPLETE;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700942 if (ctx->type == SRB_LOGIN_CMD) {
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700943 fcport->port_type = FCT_TARGET;
944 if (le16_to_cpu(mbx->mb1) & BIT_0)
945 fcport->port_type = FCT_INITIATOR;
946 if (le16_to_cpu(mbx->mb1) & BIT_1)
947 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700948 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700949 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700950 }
951
952 data[0] = le16_to_cpu(mbx->mb0);
953 switch (data[0]) {
954 case MBS_PORT_ID_USED:
955 data[1] = le16_to_cpu(mbx->mb1);
956 break;
957 case MBS_LOOP_ID_USED:
958 break;
959 default:
960 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700961 break;
962 }
963
964 DEBUG2(printk(KERN_WARNING
965 "scsi(%ld:%x): Async-%s failed - status=%x mb0=%x mb1=%x mb2=%x "
966 "mb6=%x mb7=%x.\n",
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700967 fcport->vha->host_no, sp->handle, type, status,
Andrew Vasquezac280b62009-08-20 11:06:05 -0700968 le16_to_cpu(mbx->mb0), le16_to_cpu(mbx->mb1),
969 le16_to_cpu(mbx->mb2), le16_to_cpu(mbx->mb6),
970 le16_to_cpu(mbx->mb7)));
971
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700972logio_done:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700973 lio->done(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700974}
975
976static void
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800977qla24xx_els_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
978 struct sts_entry_24xx *pkt, int iocb_type)
979{
980 const char func[] = "ELS_CT_IOCB";
981 const char *type;
982 struct qla_hw_data *ha = vha->hw;
983 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700984 struct srb_ctx *sp_bsg;
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800985 struct fc_bsg_job *bsg_job;
986 uint16_t comp_status;
987 uint32_t fw_status[3];
988 uint8_t* fw_sts_ptr;
989
990 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
991 if (!sp)
992 return;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700993 sp_bsg = sp->ctx;
994 bsg_job = sp_bsg->u.bsg_job;
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800995
996 type = NULL;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700997 switch (sp_bsg->type) {
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800998 case SRB_ELS_CMD_RPT:
999 case SRB_ELS_CMD_HST:
1000 type = "els";
1001 break;
1002 case SRB_CT_CMD:
1003 type = "ct pass-through";
1004 break;
1005 default:
1006 qla_printk(KERN_WARNING, ha,
1007 "%s: Unrecognized SRB: (%p) type=%d.\n", func, sp,
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001008 sp_bsg->type);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001009 return;
1010 }
1011
1012 comp_status = fw_status[0] = le16_to_cpu(pkt->comp_status);
1013 fw_status[1] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1);
1014 fw_status[2] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2);
1015
1016 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1017 * fc payload to the caller
1018 */
1019 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1020 bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(fw_status);
1021
1022 if (comp_status != CS_COMPLETE) {
1023 if (comp_status == CS_DATA_UNDERRUN) {
1024 bsg_job->reply->result = DID_OK << 16;
1025 bsg_job->reply->reply_payload_rcv_len =
1026 le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->total_byte_count);
1027
1028 DEBUG2(qla_printk(KERN_WARNING, ha,
1029 "scsi(%ld:0x%x): ELS-CT pass-through-%s error comp_status-status=0x%x "
1030 "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n",
1031 vha->host_no, sp->handle, type, comp_status, fw_status[1], fw_status[2],
1032 le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->total_byte_count)));
1033 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1034 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1035 }
1036 else {
1037 DEBUG2(qla_printk(KERN_WARNING, ha,
1038 "scsi(%ld:0x%x): ELS-CT pass-through-%s error comp_status-status=0x%x "
1039 "error subcode 1=0x%x error subcode 2=0x%x.\n",
1040 vha->host_no, sp->handle, type, comp_status,
1041 le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1),
1042 le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2)));
1043 bsg_job->reply->result = DID_ERROR << 16;
1044 bsg_job->reply->reply_payload_rcv_len = 0;
1045 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1046 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1047 }
1048 DEBUG2(qla2x00_dump_buffer((uint8_t *)pkt, sizeof(*pkt)));
1049 }
1050 else {
1051 bsg_job->reply->result = DID_OK << 16;;
1052 bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
1053 bsg_job->reply_len = 0;
1054 }
1055
1056 dma_unmap_sg(&ha->pdev->dev,
1057 bsg_job->request_payload.sg_list,
1058 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1059 dma_unmap_sg(&ha->pdev->dev,
1060 bsg_job->reply_payload.sg_list,
1061 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001062 if ((sp_bsg->type == SRB_ELS_CMD_HST) ||
1063 (sp_bsg->type == SRB_CT_CMD))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001064 kfree(sp->fcport);
1065 kfree(sp->ctx);
1066 mempool_free(sp, ha->srb_mempool);
1067 bsg_job->job_done(bsg_job);
1068}
1069
1070static void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001071qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req,
1072 struct logio_entry_24xx *logio)
1073{
1074 const char func[] = "LOGIO-IOCB";
1075 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001076 fc_port_t *fcport;
1077 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001078 struct srb_iocb *lio;
1079 struct srb_ctx *ctx;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001080 uint16_t *data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001081 uint32_t iop[2];
1082
1083 sp = qla2x00_get_sp_from_handle(vha, func, req, logio);
1084 if (!sp)
1085 return;
1086
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001087 ctx = sp->ctx;
1088 lio = ctx->u.iocb_cmd;
1089 type = ctx->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001090 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001091 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001092
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001093 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001094 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001095 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001096 if (logio->entry_status) {
1097 DEBUG2(printk(KERN_WARNING
1098 "scsi(%ld:%x): Async-%s error entry - entry-status=%x.\n",
1099 fcport->vha->host_no, sp->handle, type,
1100 logio->entry_status));
1101 DEBUG2(qla2x00_dump_buffer((uint8_t *)logio, sizeof(*logio)));
1102
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001103 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001104 }
1105
1106 if (le16_to_cpu(logio->comp_status) == CS_COMPLETE) {
1107 DEBUG2(printk(KERN_DEBUG
1108 "scsi(%ld:%x): Async-%s complete - iop0=%x.\n",
1109 fcport->vha->host_no, sp->handle, type,
1110 le32_to_cpu(logio->io_parameter[0])));
1111
1112 data[0] = MBS_COMMAND_COMPLETE;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001113 if (ctx->type != SRB_LOGIN_CMD)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001114 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001115
1116 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1117 if (iop[0] & BIT_4) {
1118 fcport->port_type = FCT_TARGET;
1119 if (iop[0] & BIT_8)
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07001120 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001121 }
1122 if (iop[0] & BIT_5)
1123 fcport->port_type = FCT_INITIATOR;
1124 if (logio->io_parameter[7] || logio->io_parameter[8])
1125 fcport->supported_classes |= FC_COS_CLASS2;
1126 if (logio->io_parameter[9] || logio->io_parameter[10])
1127 fcport->supported_classes |= FC_COS_CLASS3;
1128
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001129 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001130 }
1131
1132 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1133 iop[1] = le32_to_cpu(logio->io_parameter[1]);
1134 switch (iop[0]) {
1135 case LSC_SCODE_PORTID_USED:
1136 data[0] = MBS_PORT_ID_USED;
1137 data[1] = LSW(iop[1]);
1138 break;
1139 case LSC_SCODE_NPORT_USED:
1140 data[0] = MBS_LOOP_ID_USED;
1141 break;
1142 case LSC_SCODE_CMD_FAILED:
1143 if ((iop[1] & 0xff) == 0x05) {
1144 data[0] = MBS_NOT_LOGGED_IN;
1145 break;
1146 }
1147 /* Fall through. */
1148 default:
1149 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001150 break;
1151 }
1152
1153 DEBUG2(printk(KERN_WARNING
1154 "scsi(%ld:%x): Async-%s failed - comp=%x iop0=%x iop1=%x.\n",
1155 fcport->vha->host_no, sp->handle, type,
1156 le16_to_cpu(logio->comp_status),
1157 le32_to_cpu(logio->io_parameter[0]),
1158 le32_to_cpu(logio->io_parameter[1])));
1159
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001160logio_done:
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001161 lio->done(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001162}
1163
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001164static void
1165qla24xx_tm_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1166 struct tsk_mgmt_entry *tsk)
1167{
1168 const char func[] = "TMF-IOCB";
1169 const char *type;
1170 fc_port_t *fcport;
1171 srb_t *sp;
1172 struct srb_iocb *iocb;
1173 struct srb_ctx *ctx;
1174 struct sts_entry_24xx *sts = (struct sts_entry_24xx *)tsk;
1175 int error = 1;
1176
1177 sp = qla2x00_get_sp_from_handle(vha, func, req, tsk);
1178 if (!sp)
1179 return;
1180
1181 ctx = sp->ctx;
1182 iocb = ctx->u.iocb_cmd;
1183 type = ctx->name;
1184 fcport = sp->fcport;
1185
1186 if (sts->entry_status) {
1187 DEBUG2(printk(KERN_WARNING
1188 "scsi(%ld:%x): Async-%s error - entry-status(%x).\n",
1189 fcport->vha->host_no, sp->handle, type,
1190 sts->entry_status));
1191 } else if (sts->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1192 DEBUG2(printk(KERN_WARNING
1193 "scsi(%ld:%x): Async-%s error - completion status(%x).\n",
1194 fcport->vha->host_no, sp->handle, type,
1195 sts->comp_status));
1196 } else if (!(le16_to_cpu(sts->scsi_status) &
1197 SS_RESPONSE_INFO_LEN_VALID)) {
1198 DEBUG2(printk(KERN_WARNING
1199 "scsi(%ld:%x): Async-%s error - no response info(%x).\n",
1200 fcport->vha->host_no, sp->handle, type,
1201 sts->scsi_status));
1202 } else if (le32_to_cpu(sts->rsp_data_len) < 4) {
1203 DEBUG2(printk(KERN_WARNING
1204 "scsi(%ld:%x): Async-%s error - not enough response(%d).\n",
1205 fcport->vha->host_no, sp->handle, type,
1206 sts->rsp_data_len));
1207 } else if (sts->data[3]) {
1208 DEBUG2(printk(KERN_WARNING
1209 "scsi(%ld:%x): Async-%s error - response(%x).\n",
1210 fcport->vha->host_no, sp->handle, type,
1211 sts->data[3]));
1212 } else {
1213 error = 0;
1214 }
1215
1216 if (error) {
1217 iocb->u.tmf.data = error;
1218 DEBUG2(qla2x00_dump_buffer((uint8_t *)sts, sizeof(*sts)));
1219 }
1220
1221 iocb->done(sp);
1222}
1223
1224static void
1225qla24xx_marker_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1226 struct mrk_entry_24xx *mrk)
1227{
1228 const char func[] = "MRK-IOCB";
1229 const char *type;
1230 fc_port_t *fcport;
1231 srb_t *sp;
1232 struct srb_iocb *iocb;
1233 struct srb_ctx *ctx;
1234 struct sts_entry_24xx *sts = (struct sts_entry_24xx *)mrk;
1235
1236 sp = qla2x00_get_sp_from_handle(vha, func, req, mrk);
1237 if (!sp)
1238 return;
1239
1240 ctx = sp->ctx;
1241 iocb = ctx->u.iocb_cmd;
1242 type = ctx->name;
1243 fcport = sp->fcport;
1244
1245 if (sts->entry_status) {
1246 iocb->u.marker.data = 1;
1247 DEBUG2(printk(KERN_WARNING
1248 "scsi(%ld:%x): Async-%s error entry - entry-status=%x.\n",
1249 fcport->vha->host_no, sp->handle, type,
1250 sts->entry_status));
1251 DEBUG2(qla2x00_dump_buffer((uint8_t *)mrk, sizeof(*sts)));
1252 }
1253
1254 iocb->done(sp);
1255}
1256
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257/**
1258 * qla2x00_process_response_queue() - Process response queue entries.
1259 * @ha: SCSI driver HA context
1260 */
1261void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001262qla2x00_process_response_queue(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001264 struct scsi_qla_host *vha;
1265 struct qla_hw_data *ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001266 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 sts_entry_t *pkt;
1268 uint16_t handle_cnt;
1269 uint16_t cnt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001270
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001271 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001273 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 return;
1275
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001276 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1277 pkt = (sts_entry_t *)rsp->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001279 rsp->ring_index++;
1280 if (rsp->ring_index == rsp->length) {
1281 rsp->ring_index = 0;
1282 rsp->ring_ptr = rsp->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001284 rsp->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 }
1286
1287 if (pkt->entry_status != 0) {
1288 DEBUG3(printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001289 "scsi(%ld): Process error entry.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001291 qla2x00_error_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1293 wmb();
1294 continue;
1295 }
1296
1297 switch (pkt->entry_type) {
1298 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001299 qla2x00_status_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 break;
1301 case STATUS_TYPE_21:
1302 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
1303 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001304 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 ((sts21_entry_t *)pkt)->handle[cnt]);
1306 }
1307 break;
1308 case STATUS_TYPE_22:
1309 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
1310 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001311 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 ((sts22_entry_t *)pkt)->handle[cnt]);
1313 }
1314 break;
1315 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001316 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001318 case MBX_IOCB_TYPE:
1319 qla2x00_mbx_iocb_entry(vha, rsp->req,
1320 (struct mbx_entry *)pkt);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001321 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 default:
1323 /* Type Not Supported. */
1324 DEBUG4(printk(KERN_WARNING
1325 "scsi(%ld): Received unknown response pkt type %x "
1326 "entry status=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001327 vha->host_no, pkt->entry_type, pkt->entry_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 break;
1329 }
1330 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1331 wmb();
1332 }
1333
1334 /* Adjust ring index */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001335 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336}
1337
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001338static inline void
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001339qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len,
1340 struct rsp_que *rsp)
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001341{
1342 struct scsi_cmnd *cp = sp->cmd;
1343
1344 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
1345 sense_len = SCSI_SENSE_BUFFERSIZE;
1346
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001347 sp->request_sense_length = sense_len;
1348 sp->request_sense_ptr = cp->sense_buffer;
1349 if (sp->request_sense_length > 32)
1350 sense_len = 32;
1351
1352 memcpy(cp->sense_buffer, sense_data, sense_len);
1353
1354 sp->request_sense_ptr += sense_len;
1355 sp->request_sense_length -= sense_len;
1356 if (sp->request_sense_length != 0)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001357 rsp->status_srb = sp;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001358
1359 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001360 "cmd=%p pid=%ld\n", __func__, sp->fcport->vha->host_no,
Andrew Vasquez19851f12008-08-13 21:37:00 -07001361 cp->device->channel, cp->device->id, cp->device->lun, cp,
1362 cp->serial_number));
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001363 if (sense_len)
Shyam Sundarddb9b122009-03-24 09:08:10 -07001364 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer, sense_len));
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001365}
1366
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367/**
1368 * qla2x00_status_entry() - Process a Status IOCB entry.
1369 * @ha: SCSI driver HA context
1370 * @pkt: Entry pointer
1371 */
1372static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001373qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 fc_port_t *fcport;
1377 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001378 sts_entry_t *sts;
1379 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 uint16_t comp_status;
1381 uint16_t scsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001382 uint16_t ox_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 uint8_t lscsi_status;
1384 int32_t resid;
Ravi Ananded17c71b52006-05-17 15:08:55 -07001385 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001386 uint8_t *rsp_info, *sense_data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001387 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001388 uint32_t handle;
1389 uint16_t que;
1390 struct req_que *req;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001391 int logit = 1;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001392
1393 sts = (sts_entry_t *) pkt;
1394 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001395 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001396 comp_status = le16_to_cpu(sts24->comp_status);
1397 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
1398 } else {
1399 comp_status = le16_to_cpu(sts->comp_status);
1400 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1401 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001402 handle = (uint32_t) LSW(sts->handle);
1403 que = MSW(sts->handle);
1404 req = ha->req_q_map[que];
Giridhar Malavalia9083012010-04-12 17:59:55 -07001405
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001407 if (comp_status == CS_COMPLETE && scsi_status == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001408 qla2x00_process_completed_request(vha, req, handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
1410 return;
1411 }
1412
1413 /* Validate handle. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001414 if (handle < MAX_OUTSTANDING_COMMANDS) {
1415 sp = req->outstanding_cmds[handle];
1416 req->outstanding_cmds[handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 } else
1418 sp = NULL;
1419
1420 if (sp == NULL) {
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001421 qla_printk(KERN_WARNING, ha,
1422 "scsi(%ld): Invalid status handle (0x%x).\n", vha->host_no,
1423 sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001425 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1426 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 return;
1428 }
1429 cp = sp->cmd;
1430 if (cp == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 qla_printk(KERN_WARNING, ha,
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001432 "scsi(%ld): Command already returned (0x%x/%p).\n",
1433 vha->host_no, sts->handle, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
1435 return;
1436 }
1437
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001438 lscsi_status = scsi_status & STATUS_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
bdf79622005-04-17 15:06:53 -05001440 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001442 ox_id = 0;
Ravi Ananded17c71b52006-05-17 15:08:55 -07001443 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001444 if (IS_FWI2_CAPABLE(ha)) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001445 if (scsi_status & SS_SENSE_LEN_VALID)
1446 sense_len = le32_to_cpu(sts24->sense_len);
1447 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
1448 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
1449 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER))
1450 resid_len = le32_to_cpu(sts24->rsp_residual_count);
1451 if (comp_status == CS_DATA_UNDERRUN)
1452 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001453 rsp_info = sts24->data;
1454 sense_data = sts24->data;
1455 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001456 ox_id = le16_to_cpu(sts24->ox_id);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001457 } else {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001458 if (scsi_status & SS_SENSE_LEN_VALID)
1459 sense_len = le16_to_cpu(sts->req_sense_length);
1460 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
1461 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001462 resid_len = le32_to_cpu(sts->residual_length);
1463 rsp_info = sts->rsp_info;
1464 sense_data = sts->req_sense_data;
1465 }
1466
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 /* Check for any FCP transport errors. */
1468 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001469 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001470 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001471 sense_data += rsp_info_len;
1472 if (rsp_info_len > 3 && rsp_info[3]) {
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001473 DEBUG2(qla_printk(KERN_INFO, ha,
1474 "scsi(%ld:%d:%d): FCP I/O protocol failure "
1475 "(0x%x/0x%x).\n", vha->host_no, cp->device->id,
1476 cp->device->lun, rsp_info_len, rsp_info[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
1478 cp->result = DID_BUS_BUSY << 16;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001479 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 }
1481 }
1482
Andrew Vasquez3e8ce322008-02-28 14:06:10 -08001483 /* Check for overrun. */
1484 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
1485 scsi_status & SS_RESIDUAL_OVER)
1486 comp_status = CS_DATA_OVERRUN;
1487
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 /*
1489 * Based on Host and scsi status generate status code for Linux
1490 */
1491 switch (comp_status) {
1492 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001493 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 if (scsi_status == 0) {
1495 cp->result = DID_OK << 16;
1496 break;
1497 }
1498 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001499 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001500 scsi_set_resid(cp, resid);
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001501
1502 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001503 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001504 cp->underflow)) {
1505 qla_printk(KERN_INFO, ha,
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001506 "scsi(%ld:%d:%d): Mid-layer underflow "
1507 "detected (0x%x of 0x%x bytes).\n",
1508 vha->host_no, cp->device->id,
1509 cp->device->lun, resid, scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001510
1511 cp->result = DID_ERROR << 16;
1512 break;
1513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 cp->result = DID_OK << 16 | lscsi_status;
1516
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001517 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001518 DEBUG2(qla_printk(KERN_INFO, ha,
1519 "scsi(%ld:%d:%d) QUEUE FULL detected.\n",
1520 vha->host_no, cp->device->id, cp->device->lun));
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001521 break;
1522 }
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001523 logit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 if (lscsi_status != SS_CHECK_CONDITION)
1525 break;
1526
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001527 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 if (!(scsi_status & SS_SENSE_LEN_VALID))
1529 break;
1530
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001531 qla2x00_handle_sense(sp, sense_data, sense_len, rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 break;
1533
1534 case CS_DATA_UNDERRUN:
Ravi Ananded17c71b52006-05-17 15:08:55 -07001535 /* Use F/W calculated residual length. */
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001536 resid = IS_FWI2_CAPABLE(ha) ? fw_resid_len : resid_len;
1537 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 if (scsi_status & SS_RESIDUAL_UNDER) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001539 if (IS_FWI2_CAPABLE(ha) && fw_resid_len != resid_len) {
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001540 DEBUG2(qla_printk(KERN_INFO, ha,
1541 "scsi(%ld:%d:%d) Dropped frame(s) detected "
1542 "(0x%x of 0x%x bytes).\n", vha->host_no,
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001543 cp->device->id, cp->device->lun, resid,
1544 scsi_bufflen(cp)));
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08001545
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001546 cp->result = DID_ERROR << 16 | lscsi_status;
1547 break;
1548 }
1549
1550 if (!lscsi_status &&
1551 ((unsigned)(scsi_bufflen(cp) - resid) <
1552 cp->underflow)) {
1553 qla_printk(KERN_INFO, ha,
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001554 "scsi(%ld:%d:%d): Mid-layer underflow "
1555 "detected (0x%x of 0x%x bytes).\n",
1556 vha->host_no, cp->device->id,
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001557 cp->device->lun, resid, scsi_bufflen(cp));
1558
1559 cp->result = DID_ERROR << 16;
1560 break;
1561 }
1562 } else if (!lscsi_status) {
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001563 DEBUG2(qla_printk(KERN_INFO, ha,
1564 "scsi(%ld:%d:%d) Dropped frame(s) detected (0x%x "
1565 "of 0x%x bytes).\n", vha->host_no, cp->device->id,
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001566 cp->device->lun, resid, scsi_bufflen(cp)));
1567
1568 cp->result = DID_ERROR << 16;
1569 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 }
1571
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001572 cp->result = DID_OK << 16 | lscsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001573 logit = 0;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001574
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001576 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 * Status.
1578 */
1579 if (lscsi_status != 0) {
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001580 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001581 DEBUG2(qla_printk(KERN_INFO, ha,
1582 "scsi(%ld:%d:%d) QUEUE FULL detected.\n",
1583 vha->host_no, cp->device->id,
1584 cp->device->lun));
1585 logit = 1;
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001586 break;
1587 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 if (lscsi_status != SS_CHECK_CONDITION)
1589 break;
1590
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001591 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 if (!(scsi_status & SS_SENSE_LEN_VALID))
1593 break;
1594
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001595 qla2x00_handle_sense(sp, sense_data, sense_len, rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 }
1597 break;
1598
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 case CS_PORT_LOGGED_OUT:
1600 case CS_PORT_CONFIG_CHG:
1601 case CS_PORT_BUSY:
1602 case CS_INCOMPLETE:
1603 case CS_PORT_UNAVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 case CS_TIMEOUT:
Mike Christie056a4482008-08-19 18:45:29 -05001605 /*
1606 * We are going to have the fc class block the rport
1607 * while we try to recover so instruct the mid layer
1608 * to requeue until the class decides how to handle this.
1609 */
1610 cp->result = DID_TRANSPORT_DISRUPTED << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001612 if (comp_status == CS_TIMEOUT) {
1613 if (IS_FWI2_CAPABLE(ha))
1614 break;
1615 else if ((le16_to_cpu(sts->status_flags) &
1616 SF_LOGOUT_SENT) == 0)
1617 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001619
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001620 DEBUG2(qla_printk(KERN_INFO, ha,
1621 "scsi(%ld:%d:%d) Port down status: port-state=0x%x\n",
1622 vha->host_no, cp->device->id, cp->device->lun,
1623 atomic_read(&fcport->state)));
1624
1625 if (atomic_read(&fcport->state) == FCS_ONLINE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001626 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 break;
1628
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001629 case CS_RESET:
1630 case CS_ABORTED:
1631 cp->result = DID_RESET << 16;
1632 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 cp->result = DID_ERROR << 16;
1635 break;
1636 }
1637
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001638out:
1639 if (logit)
1640 DEBUG2(qla_printk(KERN_INFO, ha,
1641 "scsi(%ld:%d:%d) FCP command status: 0x%x-0x%x (0x%x) "
1642 "oxid=0x%x ser=0x%lx cdb=%02x%02x%02x len=0x%x "
1643 "rsp_info=0x%x resid=0x%x fw_resid=0x%x\n", vha->host_no,
1644 cp->device->id, cp->device->lun, comp_status, scsi_status,
1645 cp->result, ox_id, cp->serial_number, cp->cmnd[0],
1646 cp->cmnd[1], cp->cmnd[2], scsi_bufflen(cp), rsp_info_len,
1647 resid_len, fw_resid_len));
1648
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001649 if (rsp->status_srb == NULL)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001650 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651}
1652
1653/**
1654 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1655 * @ha: SCSI driver HA context
1656 * @pkt: Entry pointer
1657 *
1658 * Extended sense data.
1659 */
1660static void
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001661qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662{
1663 uint8_t sense_sz = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001664 struct qla_hw_data *ha = rsp->hw;
1665 srb_t *sp = rsp->status_srb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 struct scsi_cmnd *cp;
1667
1668 if (sp != NULL && sp->request_sense_length != 0) {
1669 cp = sp->cmd;
1670 if (cp == NULL) {
1671 DEBUG2(printk("%s(): Cmd already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001672 "sp=%p.\n", __func__, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 qla_printk(KERN_INFO, ha,
1674 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001675 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001677 rsp->status_srb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 return;
1679 }
1680
1681 if (sp->request_sense_length > sizeof(pkt->data)) {
1682 sense_sz = sizeof(pkt->data);
1683 } else {
1684 sense_sz = sp->request_sense_length;
1685 }
1686
1687 /* Move sense data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001688 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001689 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1691 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1692
1693 sp->request_sense_ptr += sense_sz;
1694 sp->request_sense_length -= sense_sz;
1695
1696 /* Place command on done queue. */
1697 if (sp->request_sense_length == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001698 rsp->status_srb = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001699 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 }
1701 }
1702}
1703
1704/**
1705 * qla2x00_error_entry() - Process an error entry.
1706 * @ha: SCSI driver HA context
1707 * @pkt: Entry pointer
1708 */
1709static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001710qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711{
1712 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001713 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001714 uint32_t handle = LSW(pkt->handle);
1715 uint16_t que = MSW(pkt->handle);
1716 struct req_que *req = ha->req_q_map[que];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717#if defined(QL_DEBUG_LEVEL_2)
1718 if (pkt->entry_status & RF_INV_E_ORDER)
1719 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1720 else if (pkt->entry_status & RF_INV_E_COUNT)
1721 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1722 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001723 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 "%s: Invalid Entry Parameter\n", __func__);
1725 else if (pkt->entry_status & RF_INV_E_TYPE)
1726 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1727 else if (pkt->entry_status & RF_BUSY)
1728 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1729 else
1730 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1731#endif
1732
1733 /* Validate handle. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001734 if (handle < MAX_OUTSTANDING_COMMANDS)
1735 sp = req->outstanding_cmds[handle];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 else
1737 sp = NULL;
1738
1739 if (sp) {
1740 /* Free outstanding command slot. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001741 req->outstanding_cmds[handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001742
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 /* Bad payload or header */
1744 if (pkt->entry_status &
1745 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1746 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1747 sp->cmd->result = DID_ERROR << 16;
1748 } else if (pkt->entry_status & RF_BUSY) {
1749 sp->cmd->result = DID_BUS_BUSY << 16;
1750 } else {
1751 sp->cmd->result = DID_ERROR << 16;
1752 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001753 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001755 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1756 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001758 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 qla_printk(KERN_WARNING, ha,
1760 "Error entry - invalid handle\n");
1761
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001762 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1763 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 }
1765}
1766
1767/**
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001768 * qla24xx_mbx_completion() - Process mailbox command completions.
1769 * @ha: SCSI driver HA context
1770 * @mb0: Mailbox0 register
1771 */
1772static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001773qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001774{
1775 uint16_t cnt;
1776 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001777 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001778 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1779
1780 /* Load return mailbox registers. */
1781 ha->flags.mbox_int = 1;
1782 ha->mailbox_out[0] = mb0;
1783 wptr = (uint16_t __iomem *)&reg->mailbox1;
1784
1785 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1786 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1787 wptr++;
1788 }
1789
1790 if (ha->mcp) {
1791 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001792 __func__, vha->host_no, ha->mcp->mb[0]));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001793 } else {
1794 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001795 __func__, vha->host_no));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001796 }
1797}
1798
1799/**
1800 * qla24xx_process_response_queue() - Process response queue entries.
1801 * @ha: SCSI driver HA context
1802 */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001803void qla24xx_process_response_queue(struct scsi_qla_host *vha,
1804 struct rsp_que *rsp)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001805{
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001806 struct sts_entry_24xx *pkt;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001807 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001808
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001809 if (!vha->flags.online)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001810 return;
1811
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001812 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1813 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001814
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001815 rsp->ring_index++;
1816 if (rsp->ring_index == rsp->length) {
1817 rsp->ring_index = 0;
1818 rsp->ring_ptr = rsp->ring;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001819 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001820 rsp->ring_ptr++;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001821 }
1822
1823 if (pkt->entry_status != 0) {
1824 DEBUG3(printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001825 "scsi(%ld): Process error entry.\n", vha->host_no));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001826
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001827 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001828 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1829 wmb();
1830 continue;
1831 }
1832
1833 switch (pkt->entry_type) {
1834 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001835 qla2x00_status_entry(vha, rsp, pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001836 break;
1837 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001838 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001839 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001840 case VP_RPT_ID_IOCB_TYPE:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001841 qla24xx_report_id_acquisition(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001842 (struct vp_rpt_id_entry_24xx *)pkt);
1843 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001844 case LOGINOUT_PORT_IOCB_TYPE:
1845 qla24xx_logio_entry(vha, rsp->req,
1846 (struct logio_entry_24xx *)pkt);
1847 break;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001848 case TSK_MGMT_IOCB_TYPE:
1849 qla24xx_tm_iocb_entry(vha, rsp->req,
1850 (struct tsk_mgmt_entry *)pkt);
1851 break;
1852 case MARKER_TYPE:
1853 qla24xx_marker_iocb_entry(vha, rsp->req,
1854 (struct mrk_entry_24xx *)pkt);
1855 break;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001856 case CT_IOCB_TYPE:
1857 qla24xx_els_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
1858 clear_bit(MBX_INTERRUPT, &vha->hw->mbx_cmd_flags);
1859 break;
1860 case ELS_IOCB_TYPE:
1861 qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE);
1862 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001863 default:
1864 /* Type Not Supported. */
1865 DEBUG4(printk(KERN_WARNING
1866 "scsi(%ld): Received unknown response pkt type %x "
1867 "entry status=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001868 vha->host_no, pkt->entry_type, pkt->entry_status));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001869 break;
1870 }
1871 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1872 wmb();
1873 }
1874
1875 /* Adjust ring index */
Giridhar Malavalia9083012010-04-12 17:59:55 -07001876 if (IS_QLA82XX(ha)) {
1877 struct device_reg_82xx __iomem *reg = &ha->iobase->isp82;
1878 WRT_REG_DWORD(&reg->rsp_q_out[0], rsp->ring_index);
1879 } else
1880 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001881}
1882
Andrew Vasquez05236a02007-09-20 14:07:37 -07001883static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001884qla2xxx_check_risc_status(scsi_qla_host_t *vha)
Andrew Vasquez05236a02007-09-20 14:07:37 -07001885{
1886 int rval;
1887 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001888 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez05236a02007-09-20 14:07:37 -07001889 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1890
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001891 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez05236a02007-09-20 14:07:37 -07001892 return;
1893
1894 rval = QLA_SUCCESS;
1895 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1896 RD_REG_DWORD(&reg->iobase_addr);
1897 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1898 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1899 rval == QLA_SUCCESS; cnt--) {
1900 if (cnt) {
1901 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1902 udelay(10);
1903 } else
1904 rval = QLA_FUNCTION_TIMEOUT;
1905 }
1906 if (rval == QLA_SUCCESS)
1907 goto next_test;
1908
1909 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1910 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1911 rval == QLA_SUCCESS; cnt--) {
1912 if (cnt) {
1913 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1914 udelay(10);
1915 } else
1916 rval = QLA_FUNCTION_TIMEOUT;
1917 }
1918 if (rval != QLA_SUCCESS)
1919 goto done;
1920
1921next_test:
1922 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
1923 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1924
1925done:
1926 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
1927 RD_REG_DWORD(&reg->iobase_window);
1928}
1929
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001930/**
1931 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1932 * @irq:
1933 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001934 *
1935 * Called by system whenever the host adapter generates an interrupt.
1936 *
1937 * Returns handled flag.
1938 */
1939irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001940qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001941{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001942 scsi_qla_host_t *vha;
1943 struct qla_hw_data *ha;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001944 struct device_reg_24xx __iomem *reg;
1945 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001946 unsigned long iter;
1947 uint32_t stat;
1948 uint32_t hccr;
1949 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001950 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07001951 unsigned long flags;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001952
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001953 rsp = (struct rsp_que *) dev_id;
1954 if (!rsp) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001955 printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001956 "%s(): NULL response queue pointer\n", __func__);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001957 return IRQ_NONE;
1958 }
1959
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001960 ha = rsp->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001961 reg = &ha->iobase->isp24;
1962 status = 0;
1963
Andrew Vasquez85880802009-12-15 21:29:46 -08001964 if (unlikely(pci_channel_offline(ha->pdev)))
1965 return IRQ_HANDLED;
1966
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07001967 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001968 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001969 for (iter = 50; iter--; ) {
1970 stat = RD_REG_DWORD(&reg->host_status);
1971 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08001972 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07001973 break;
1974
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001975 hccr = RD_REG_DWORD(&reg->hccr);
1976
1977 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1978 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001979
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001980 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001981
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001982 ha->isp_ops->fw_dump(vha, 1);
1983 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001984 break;
1985 } else if ((stat & HSRX_RISC_INT) == 0)
1986 break;
1987
1988 switch (stat & 0xff) {
1989 case 0x1:
1990 case 0x2:
1991 case 0x10:
1992 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001993 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001994 status |= MBX_INTERRUPT;
1995
1996 break;
1997 case 0x12:
1998 mb[0] = MSW(stat);
1999 mb[1] = RD_REG_WORD(&reg->mailbox1);
2000 mb[2] = RD_REG_WORD(&reg->mailbox2);
2001 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002002 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002003 break;
2004 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002005 case 0x14:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002006 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002007 break;
2008 default:
2009 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
2010 "(%d).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002011 vha->host_no, stat & 0xff));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002012 break;
2013 }
2014 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2015 RD_REG_DWORD_RELAXED(&reg->hccr);
2016 }
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002017 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002018
2019 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
2020 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002021 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002022 complete(&ha->mbx_intr_comp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002023 }
2024
2025 return IRQ_HANDLED;
2026}
2027
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002028static irqreturn_t
2029qla24xx_msix_rsp_q(int irq, void *dev_id)
2030{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002031 struct qla_hw_data *ha;
2032 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002033 struct device_reg_24xx __iomem *reg;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002034 struct scsi_qla_host *vha;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002035 unsigned long flags;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002036
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002037 rsp = (struct rsp_que *) dev_id;
2038 if (!rsp) {
2039 printk(KERN_INFO
2040 "%s(): NULL response queue pointer\n", __func__);
2041 return IRQ_NONE;
2042 }
2043 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002044 reg = &ha->iobase->isp24;
2045
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002046 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002047
Anirban Chakrabortya67093d2010-02-04 14:17:59 -08002048 vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002049 qla24xx_process_response_queue(vha, rsp);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002050 if (!ha->flags.disable_msix_handshake) {
Anirban Chakrabortyeb941142009-08-04 16:12:13 -07002051 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2052 RD_REG_DWORD_RELAXED(&reg->hccr);
2053 }
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002054 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002055
2056 return IRQ_HANDLED;
2057}
2058
2059static irqreturn_t
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002060qla25xx_msix_rsp_q(int irq, void *dev_id)
2061{
2062 struct qla_hw_data *ha;
2063 struct rsp_que *rsp;
Anirban Chakraborty31557542009-12-02 10:36:55 -08002064 struct device_reg_24xx __iomem *reg;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002065 unsigned long flags;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002066
2067 rsp = (struct rsp_que *) dev_id;
2068 if (!rsp) {
2069 printk(KERN_INFO
2070 "%s(): NULL response queue pointer\n", __func__);
2071 return IRQ_NONE;
2072 }
2073 ha = rsp->hw;
2074
Anirban Chakraborty31557542009-12-02 10:36:55 -08002075 /* Clear the interrupt, if enabled, for this response queue */
2076 if (rsp->options & ~BIT_6) {
2077 reg = &ha->iobase->isp24;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002078 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002079 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2080 RD_REG_DWORD_RELAXED(&reg->hccr);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002081 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002082 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002083 queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work);
2084
2085 return IRQ_HANDLED;
2086}
2087
2088static irqreturn_t
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002089qla24xx_msix_default(int irq, void *dev_id)
2090{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002091 scsi_qla_host_t *vha;
2092 struct qla_hw_data *ha;
2093 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002094 struct device_reg_24xx __iomem *reg;
2095 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002096 uint32_t stat;
2097 uint32_t hccr;
2098 uint16_t mb[4];
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002099 unsigned long flags;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002100
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002101 rsp = (struct rsp_que *) dev_id;
2102 if (!rsp) {
2103 DEBUG(printk(
2104 "%s(): NULL response queue pointer\n", __func__));
2105 return IRQ_NONE;
2106 }
2107 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002108 reg = &ha->iobase->isp24;
2109 status = 0;
2110
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002111 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002112 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002113 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002114 stat = RD_REG_DWORD(&reg->host_status);
2115 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08002116 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07002117 break;
2118
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002119 hccr = RD_REG_DWORD(&reg->hccr);
2120
2121 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
2122 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002123
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002124 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002125
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002126 ha->isp_ops->fw_dump(vha, 1);
2127 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002128 break;
2129 } else if ((stat & HSRX_RISC_INT) == 0)
2130 break;
2131
2132 switch (stat & 0xff) {
2133 case 0x1:
2134 case 0x2:
2135 case 0x10:
2136 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002137 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002138 status |= MBX_INTERRUPT;
2139
2140 break;
2141 case 0x12:
2142 mb[0] = MSW(stat);
2143 mb[1] = RD_REG_WORD(&reg->mailbox1);
2144 mb[2] = RD_REG_WORD(&reg->mailbox2);
2145 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002146 qla2x00_async_event(vha, rsp, mb);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002147 break;
2148 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002149 case 0x14:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002150 qla24xx_process_response_queue(vha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002151 break;
2152 default:
2153 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
2154 "(%d).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002155 vha->host_no, stat & 0xff));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002156 break;
2157 }
2158 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002159 } while (0);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002160 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002161
2162 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
2163 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002164 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002165 complete(&ha->mbx_intr_comp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002166 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002167 return IRQ_HANDLED;
2168}
2169
2170/* Interrupt handling helpers. */
2171
2172struct qla_init_msix_entry {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002173 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07002174 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002175};
2176
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002177static struct qla_init_msix_entry msix_entries[3] = {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002178 { "qla2xxx (default)", qla24xx_msix_default },
2179 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002180 { "qla2xxx (multiq)", qla25xx_msix_rsp_q },
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002181};
2182
Giridhar Malavalia9083012010-04-12 17:59:55 -07002183static struct qla_init_msix_entry qla82xx_msix_entries[2] = {
2184 { "qla2xxx (default)", qla82xx_msix_default },
2185 { "qla2xxx (rsp_q)", qla82xx_msix_rsp_q },
2186};
2187
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002188static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002189qla24xx_disable_msix(struct qla_hw_data *ha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002190{
2191 int i;
2192 struct qla_msix_entry *qentry;
2193
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002194 for (i = 0; i < ha->msix_count; i++) {
2195 qentry = &ha->msix_entries[i];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002196 if (qentry->have_irq)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002197 free_irq(qentry->vector, qentry->rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002198 }
2199 pci_disable_msix(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002200 kfree(ha->msix_entries);
2201 ha->msix_entries = NULL;
2202 ha->flags.msix_enabled = 0;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002203}
2204
2205static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002206qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002207{
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002208#define MIN_MSIX_COUNT 2
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002209 int i, ret;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002210 struct msix_entry *entries;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002211 struct qla_msix_entry *qentry;
2212
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002213 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002214 GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002215 if (!entries)
2216 return -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002217
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002218 for (i = 0; i < ha->msix_count; i++)
2219 entries[i].entry = i;
2220
2221 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002222 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002223 if (ret < MIN_MSIX_COUNT)
2224 goto msix_failed;
2225
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002226 qla_printk(KERN_WARNING, ha,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002227 "MSI-X: Failed to enable support -- %d/%d\n"
2228 " Retry with %d vectors\n", ha->msix_count, ret, ret);
2229 ha->msix_count = ret;
2230 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
2231 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002232msix_failed:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002233 qla_printk(KERN_WARNING, ha, "MSI-X: Failed to enable"
2234 " support, giving up -- %d/%d\n",
2235 ha->msix_count, ret);
2236 goto msix_out;
2237 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002238 ha->max_rsp_queues = ha->msix_count - 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002239 }
2240 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
2241 ha->msix_count, GFP_KERNEL);
2242 if (!ha->msix_entries) {
2243 ret = -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002244 goto msix_out;
2245 }
2246 ha->flags.msix_enabled = 1;
2247
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002248 for (i = 0; i < ha->msix_count; i++) {
2249 qentry = &ha->msix_entries[i];
2250 qentry->vector = entries[i].vector;
2251 qentry->entry = entries[i].entry;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002252 qentry->have_irq = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002253 qentry->rsp = NULL;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002254 }
2255
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002256 /* Enable MSI-X vectors for the base queue */
2257 for (i = 0; i < 2; i++) {
2258 qentry = &ha->msix_entries[i];
Giridhar Malavalia9083012010-04-12 17:59:55 -07002259 if (IS_QLA82XX(ha)) {
2260 ret = request_irq(qentry->vector,
2261 qla82xx_msix_entries[i].handler,
2262 0, qla82xx_msix_entries[i].name, rsp);
2263 } else {
2264 ret = request_irq(qentry->vector,
2265 msix_entries[i].handler,
2266 0, msix_entries[i].name, rsp);
2267 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002268 if (ret) {
2269 qla_printk(KERN_WARNING, ha,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002270 "MSI-X: Unable to register handler -- %x/%d.\n",
2271 qentry->vector, ret);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002272 qla24xx_disable_msix(ha);
2273 ha->mqenable = 0;
2274 goto msix_out;
2275 }
2276 qentry->have_irq = 1;
2277 qentry->rsp = rsp;
2278 rsp->msix = qentry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002279 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002280
2281 /* Enable MSI-X vector for response queue update for queue 0 */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002282 if (ha->mqiobase && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002283 ha->mqenable = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002284
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002285msix_out:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002286 kfree(entries);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002287 return ret;
2288}
2289
2290int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002291qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002292{
2293 int ret;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002294 device_reg_t __iomem *reg = ha->iobase;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002295
2296 /* If possible, enable MSI-X. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002297 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) &&
Giridhar Malavalia9083012010-04-12 17:59:55 -07002298 !IS_QLA8432(ha) && !IS_QLA8XXX_TYPE(ha))
Ben Hutchings6377a7a2010-03-19 16:59:19 -07002299 goto skip_msi;
2300
2301 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
2302 (ha->pdev->subsystem_device == 0x7040 ||
2303 ha->pdev->subsystem_device == 0x7041 ||
2304 ha->pdev->subsystem_device == 0x1705)) {
2305 DEBUG2(qla_printk(KERN_WARNING, ha,
2306 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X,0x%X).\n",
2307 ha->pdev->subsystem_vendor,
2308 ha->pdev->subsystem_device));
2309 goto skip_msi;
2310 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002311
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002312 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX ||
2313 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002314 DEBUG2(qla_printk(KERN_WARNING, ha,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002315 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
2316 ha->pdev->revision, ha->fw_attributes));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002317 goto skip_msix;
2318 }
2319
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002320 ret = qla24xx_enable_msix(ha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002321 if (!ret) {
2322 DEBUG2(qla_printk(KERN_INFO, ha,
2323 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
2324 ha->fw_attributes));
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002325 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002326 }
2327 qla_printk(KERN_WARNING, ha,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002328 "MSI-X: Falling back-to MSI mode -- %d.\n", ret);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002329skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002330
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002331 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
2332 !IS_QLA8001(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002333 goto skip_msi;
2334
2335 ret = pci_enable_msi(ha->pdev);
2336 if (!ret) {
2337 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
2338 ha->flags.msi_enabled = 1;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002339 } else
2340 qla_printk(KERN_WARNING, ha,
2341 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002342skip_msi:
2343
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002344 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Giridhar Malavalid1b1bef2009-03-24 09:08:13 -07002345 IRQF_SHARED, QLA2XXX_DRIVER_NAME, rsp);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002346 if (ret) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002347 qla_printk(KERN_WARNING, ha,
2348 "Failed to reserve interrupt %d already in use.\n",
2349 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002350 goto fail;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002351 }
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002352 ha->flags.inta_enabled = 1;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002353clear_risc_ints:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002354
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002355 /*
2356 * FIXME: Noted that 8014s were being dropped during NK testing.
2357 * Timing deltas during MSI-X/INTa transitions?
2358 */
Giridhar Malavalia9083012010-04-12 17:59:55 -07002359 if (IS_QLA81XX(ha) || IS_QLA82XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002360 goto fail;
Andrew Vasquezc6952482008-04-03 13:13:17 -07002361 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002362 if (IS_FWI2_CAPABLE(ha)) {
2363 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
2364 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
2365 } else {
2366 WRT_REG_WORD(&reg->isp.semaphore, 0);
2367 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
2368 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
2369 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07002370 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002371
2372fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002373 return ret;
2374}
2375
2376void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002377qla2x00_free_irqs(scsi_qla_host_t *vha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002378{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002379 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002380 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002381
2382 if (ha->flags.msix_enabled)
2383 qla24xx_disable_msix(ha);
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002384 else if (ha->flags.msi_enabled) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002385 free_irq(ha->pdev->irq, rsp);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002386 pci_disable_msi(ha->pdev);
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002387 } else
2388 free_irq(ha->pdev->irq, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002389}
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002390
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002391
2392int qla25xx_request_irq(struct rsp_que *rsp)
2393{
2394 struct qla_hw_data *ha = rsp->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002395 struct qla_init_msix_entry *intr = &msix_entries[2];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002396 struct qla_msix_entry *msix = rsp->msix;
2397 int ret;
2398
2399 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
2400 if (ret) {
2401 qla_printk(KERN_WARNING, ha,
2402 "MSI-X: Unable to register handler -- %x/%d.\n",
2403 msix->vector, ret);
2404 return ret;
2405 }
2406 msix->have_irq = 1;
2407 msix->rsp = rsp;
2408 return ret;
2409}