blob: 6f67a9d4998b6d43fbab53a0a75918c6f607fbf0 [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 Vasquez07e264b2011-03-30 11:46:23 -07003 * Copyright (c) 2003-2011 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"
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04008#include "qla_target.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Andrew Vasquez05236a02007-09-20 14:07:37 -070010#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070012#include <scsi/scsi_tcq.h>
Giridhar Malavali9a069e12010-01-12 13:02:47 -080013#include <scsi/scsi_bsg_fc.h>
Arun Easibad75002010-05-04 15:01:30 -070014#include <scsi/scsi_eh.h>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070015
Linus Torvalds1da177e2005-04-16 15:20:36 -070016static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080017static void qla2x00_process_completed_request(struct scsi_qla_host *,
18 struct req_que *, uint32_t);
19static void qla2x00_status_entry(scsi_qla_host_t *, struct rsp_que *, void *);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070020static void qla2x00_status_cont_entry(struct rsp_que *, sts_cont_entry_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080021static void qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
22 sts_entry_t *);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070023
Linus Torvalds1da177e2005-04-16 15:20:36 -070024/**
25 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
26 * @irq:
27 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 *
29 * Called by system whenever the host adapter generates an interrupt.
30 *
31 * Returns handled flag.
32 */
33irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +010034qla2100_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080036 scsi_qla_host_t *vha;
37 struct qla_hw_data *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -070038 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 unsigned long iter;
Seokmann Ju14e660e2007-09-20 14:07:36 -070041 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070042 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080043 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070044 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080046 rsp = (struct rsp_que *) dev_id;
47 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -080048 ql_log(ql_log_info, NULL, 0x505d,
49 "%s: NULL response queue pointer.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 return (IRQ_NONE);
51 }
52
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080053 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -070054 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 status = 0;
56
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070057 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070058 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 for (iter = 50; iter--; ) {
Seokmann Ju14e660e2007-09-20 14:07:36 -070060 hccr = RD_REG_WORD(&reg->hccr);
61 if (hccr & HCCR_RISC_PAUSE) {
62 if (pci_channel_offline(ha->pdev))
63 break;
64
65 /*
66 * Issue a "HARD" reset in order for the RISC interrupt
Justin P. Mattocka06a0f82011-06-23 23:22:27 -070067 * bit to be cleared. Schedule a big hammer to get
Seokmann Ju14e660e2007-09-20 14:07:36 -070068 * out of the RISC PAUSED state.
69 */
70 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
71 RD_REG_WORD(&reg->hccr);
72
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080073 ha->isp_ops->fw_dump(vha, 1);
74 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -070075 break;
76 } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 break;
78
79 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
80 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
81 RD_REG_WORD(&reg->hccr);
82
83 /* Get mailbox data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -070084 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
85 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080086 qla2x00_mbx_completion(vha, mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 status |= MBX_INTERRUPT;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070088 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
89 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
90 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
91 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080092 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 } else {
94 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -070095 ql_dbg(ql_dbg_async, vha, 0x5025,
96 "Unrecognized interrupt type (%d).\n",
97 mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 }
99 /* Release mailbox registers. */
100 WRT_REG_WORD(&reg->semaphore, 0);
101 RD_REG_WORD(&reg->semaphore);
102 } else {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800103 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
106 RD_REG_WORD(&reg->hccr);
107 }
108 }
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700109 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
112 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800114 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 }
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 return (IRQ_HANDLED);
118}
119
120/**
121 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
122 * @irq:
123 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 *
125 * Called by system whenever the host adapter generates an interrupt.
126 *
127 * Returns handled flag.
128 */
129irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100130qla2300_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800132 scsi_qla_host_t *vha;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700133 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 unsigned long iter;
136 uint32_t stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700138 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800139 struct rsp_que *rsp;
140 struct qla_hw_data *ha;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700141 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800143 rsp = (struct rsp_que *) dev_id;
144 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -0800145 ql_log(ql_log_info, NULL, 0x5058,
146 "%s: NULL response queue pointer.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 return (IRQ_NONE);
148 }
149
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800150 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700151 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 status = 0;
153
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700154 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700155 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 for (iter = 50; iter--; ) {
157 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
158 if (stat & HSR_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800159 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -0700160 break;
161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 hccr = RD_REG_WORD(&reg->hccr);
163 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700164 ql_log(ql_log_warn, vha, 0x5026,
165 "Parity error -- HCCR=%x, Dumping "
166 "firmware.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700168 ql_log(ql_log_warn, vha, 0x5027,
169 "RISC paused -- HCCR=%x, Dumping "
170 "firmware.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 /*
173 * Issue a "HARD" reset in order for the RISC
174 * interrupt bit to be cleared. Schedule a big
Justin P. Mattocka06a0f82011-06-23 23:22:27 -0700175 * hammer to get out of the RISC PAUSED state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 */
177 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
178 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800179
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800180 ha->isp_ops->fw_dump(vha, 1);
181 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 break;
183 } else if ((stat & HSR_RISC_INT) == 0)
184 break;
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 case 0x1:
188 case 0x2:
189 case 0x10:
190 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800191 qla2x00_mbx_completion(vha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 status |= MBX_INTERRUPT;
193
194 /* Release mailbox registers. */
195 WRT_REG_WORD(&reg->semaphore, 0);
196 break;
197 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700198 mb[0] = MSW(stat);
199 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
200 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
201 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800202 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700203 break;
204 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800205 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 break;
207 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700208 mb[0] = MBA_CMPLT_1_16BIT;
209 mb[1] = MSW(stat);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800210 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 break;
212 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700213 mb[0] = MBA_SCSI_COMPLETION;
214 mb[1] = MSW(stat);
215 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800216 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 break;
218 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700219 ql_dbg(ql_dbg_async, vha, 0x5028,
220 "Unrecognized interrupt type (%d).\n", stat & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 break;
222 }
223 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
224 RD_REG_WORD_RELAXED(&reg->hccr);
225 }
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700226 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
229 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800231 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 }
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 return (IRQ_HANDLED);
235}
236
237/**
238 * qla2x00_mbx_completion() - Process mailbox command completions.
239 * @ha: SCSI driver HA context
240 * @mb0: Mailbox0 register
241 */
242static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800243qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
245 uint16_t cnt;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800246 uint32_t mboxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800248 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700249 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800251 /* Read all mbox registers? */
252 mboxes = (1 << ha->mbx_count) - 1;
253 if (!ha->mcp)
254 ql_dbg(ql_dbg_async, vha, 0x5001, "MBX pointer ERRROR.\n");
255 else
256 mboxes = ha->mcp->in_mb;
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 /* Load return mailbox registers. */
259 ha->flags.mbox_int = 1;
260 ha->mailbox_out[0] = mb0;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800261 mboxes >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
263
264 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700265 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800267 if ((cnt == 4 || cnt == 5) && (mboxes & BIT_0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800269 else if (mboxes & BIT_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 wptr++;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800273 mboxes >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275}
276
Andrew Vasquez8a659572009-02-08 20:50:12 -0800277static void
278qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
279{
280 static char *event[] =
281 { "Complete", "Request Notification", "Time Extension" };
282 int rval;
283 struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
284 uint16_t __iomem *wptr;
285 uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
286
287 /* Seed data -- mailbox1 -> mailbox7. */
288 wptr = (uint16_t __iomem *)&reg24->mailbox1;
289 for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
290 mb[cnt] = RD_REG_WORD(wptr);
291
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700292 ql_dbg(ql_dbg_async, vha, 0x5021,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800293 "Inter-Driver Communication %s -- "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700294 "%04x %04x %04x %04x %04x %04x %04x.\n",
295 event[aen & 0xff], mb[0], mb[1], mb[2], mb[3],
296 mb[4], mb[5], mb[6]);
Andrew Vasquez8a659572009-02-08 20:50:12 -0800297
298 /* Acknowledgement needed? [Notify && non-zero timeout]. */
299 timeout = (descr >> 8) & 0xf;
300 if (aen != MBA_IDC_NOTIFY || !timeout)
301 return;
302
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700303 ql_dbg(ql_dbg_async, vha, 0x5022,
Joe Perchesd8424f62011-11-18 09:03:06 -0800304 "%lu Inter-Driver Communication %s -- ACK timeout=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700305 vha->host_no, event[aen & 0xff], timeout);
Andrew Vasquez8a659572009-02-08 20:50:12 -0800306
307 rval = qla2x00_post_idc_ack_work(vha, mb);
308 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700309 ql_log(ql_log_warn, vha, 0x5023,
Andrew Vasquez8a659572009-02-08 20:50:12 -0800310 "IDC failed to post ACK.\n");
311}
312
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400313#define LS_UNKNOWN 2
314char *
315qla2x00_get_link_speed_str(struct qla_hw_data *ha)
316{
317 static char *link_speeds[] = {"1", "2", "?", "4", "8", "16", "10"};
318 char *link_speed;
319 int fw_speed = ha->link_data_rate;
320
321 if (IS_QLA2100(ha) || IS_QLA2200(ha))
322 link_speed = link_speeds[0];
323 else if (fw_speed == 0x13)
324 link_speed = link_speeds[6];
325 else {
326 link_speed = link_speeds[LS_UNKNOWN];
327 if (fw_speed < 6)
328 link_speed =
329 link_speeds[fw_speed];
330 }
331
332 return link_speed;
333}
334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335/**
336 * qla2x00_async_event() - Process aynchronous events.
337 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700338 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700340void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800341qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 uint16_t handle_cnt;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700344 uint16_t cnt, mbx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 uint32_t handles[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800346 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700347 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700348 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
Andrew Vasquezbc5c2aa2010-12-21 16:00:24 -0800349 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 uint32_t rscn_entry, host_pid;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700351 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353 /* Setup to process RIO completion. */
354 handle_cnt = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800355 if (IS_CNA_CAPABLE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800356 goto skip_rio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 switch (mb[0]) {
358 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700359 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 handle_cnt = 1;
361 break;
362 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700363 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 handle_cnt = 1;
365 mb[0] = MBA_SCSI_COMPLETION;
366 break;
367 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700368 handles[0] = mb[1];
369 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 handle_cnt = 2;
371 mb[0] = MBA_SCSI_COMPLETION;
372 break;
373 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700374 handles[0] = mb[1];
375 handles[1] = mb[2];
376 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 handle_cnt = 3;
378 mb[0] = MBA_SCSI_COMPLETION;
379 break;
380 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700381 handles[0] = mb[1];
382 handles[1] = mb[2];
383 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
385 handle_cnt = 4;
386 mb[0] = MBA_SCSI_COMPLETION;
387 break;
388 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700389 handles[0] = mb[1];
390 handles[1] = mb[2];
391 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
393 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
394 handle_cnt = 5;
395 mb[0] = MBA_SCSI_COMPLETION;
396 break;
397 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700398 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 handles[1] = le32_to_cpu(
400 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
401 RD_MAILBOX_REG(ha, reg, 6));
402 handle_cnt = 2;
403 mb[0] = MBA_SCSI_COMPLETION;
404 break;
405 default:
406 break;
407 }
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800408skip_rio:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 switch (mb[0]) {
410 case MBA_SCSI_COMPLETION: /* Fast Post */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800411 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 break;
413
414 for (cnt = 0; cnt < handle_cnt; cnt++)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800415 qla2x00_process_completed_request(vha, rsp->req,
416 handles[cnt]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 break;
418
419 case MBA_RESET: /* Reset */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700420 ql_dbg(ql_dbg_async, vha, 0x5002,
421 "Asynchronous RESET.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800423 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 break;
425
426 case MBA_SYSTEM_ERR: /* System Error */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800427 mbx = (IS_QLA81XX(ha) || IS_QLA83XX(ha)) ?
428 RD_REG_WORD(&reg24->mailbox7) : 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700429 ql_log(ql_log_warn, vha, 0x5003,
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700430 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh "
431 "mbx7=%xh.\n", mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800433 ha->isp_ops->fw_dump(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Andrew Vasqueze4289242007-07-19 15:05:56 -0700435 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700436 if (mb[1] == 0 && mb[2] == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700437 ql_log(ql_log_fatal, vha, 0x5004,
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700438 "Unrecoverable Hardware Error: adapter "
439 "marked OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800440 vha->flags.online = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800441 vha->device_flags |= DFLG_DEV_FAILED;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700442 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300443 /* Check to see if MPI timeout occurred */
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700444 if ((mbx & MBX_3) && (ha->flags.port0))
445 set_bit(MPI_RESET_NEEDED,
446 &vha->dpc_flags);
447
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800448 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700449 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700450 } else if (mb[1] == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700451 ql_log(ql_log_fatal, vha, 0x5005,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 "Unrecoverable Hardware Error: adapter marked "
453 "OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800454 vha->flags.online = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800455 vha->device_flags |= DFLG_DEV_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800457 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 break;
459
460 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700461 ql_log(ql_log_warn, vha, 0x5006,
462 "ISP Request Transfer Error (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800464 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 break;
466
467 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700468 ql_log(ql_log_warn, vha, 0x5007,
469 "ISP Response Transfer Error.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800471 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 break;
473
474 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700475 ql_dbg(ql_dbg_async, vha, 0x5008,
476 "Asynchronous WAKEUP_THRES.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400478 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Chad Dupuiscfb09192011-11-18 09:03:07 -0800480 ql_dbg(ql_dbg_async, vha, 0x5009,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700481 "LIP occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800483 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
484 atomic_set(&vha->loop_state, LOOP_DOWN);
485 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
486 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 }
488
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800489 if (vha->vp_idx) {
490 atomic_set(&vha->vp_state, VP_FAILED);
491 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700492 }
493
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800494 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
495 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800497 vha->flags.management_server_logged_in = 0;
498 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 break;
500
501 case MBA_LOOP_UP: /* Loop Up Event */
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400502 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700503 ha->link_data_rate = PORT_SPEED_1GB;
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400504 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 ha->link_data_rate = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Chad Dupuiscfb09192011-11-18 09:03:07 -0800507 ql_dbg(ql_dbg_async, vha, 0x500a,
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400508 "LOOP UP detected (%s Gbps).\n",
509 qla2x00_get_link_speed_str(ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800511 vha->flags.management_server_logged_in = 0;
512 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 break;
514
515 case MBA_LOOP_DOWN: /* Loop Down Event */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800516 mbx = (IS_QLA81XX(ha) || IS_QLA8031(ha))
517 ? RD_REG_WORD(&reg24->mailbox4) : 0;
Andrew Vasquezbc5c2aa2010-12-21 16:00:24 -0800518 mbx = IS_QLA82XX(ha) ? RD_REG_WORD(&reg82->mailbox_out[4]) : mbx;
Chad Dupuiscfb09192011-11-18 09:03:07 -0800519 ql_dbg(ql_dbg_async, vha, 0x500b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700520 "LOOP DOWN detected (%x %x %x %x).\n",
521 mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800523 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
524 atomic_set(&vha->loop_state, LOOP_DOWN);
525 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
526 vha->device_flags |= DFLG_NO_CABLE;
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 vha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700536 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800537 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 break;
539
540 case MBA_LIP_RESET: /* LIP reset occurred */
Chad Dupuiscfb09192011-11-18 09:03:07 -0800541 ql_dbg(ql_dbg_async, vha, 0x500c,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700542 "LIP reset occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800544 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
545 atomic_set(&vha->loop_state, LOOP_DOWN);
546 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
547 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 }
549
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800550 if (vha->vp_idx) {
551 atomic_set(&vha->vp_state, VP_FAILED);
552 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700553 }
554
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800555 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
557 ha->operating_mode = LOOP;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800558 vha->flags.management_server_logged_in = 0;
559 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 break;
561
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800562 /* case MBA_DCBX_COMPLETE: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 case MBA_POINT_TO_POINT: /* Point-to-Point */
564 if (IS_QLA2100(ha))
565 break;
566
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800567 if (IS_QLA81XX(ha) || IS_QLA82XX(ha) || IS_QLA8031(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700568 ql_dbg(ql_dbg_async, vha, 0x500d,
569 "DCBX Completed -- %04x %04x %04x.\n",
570 mb[1], mb[2], mb[3]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700571 if (ha->notify_dcbx_comp)
572 complete(&ha->dcbx_comp);
573
574 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700575 ql_dbg(ql_dbg_async, vha, 0x500e,
576 "Asynchronous P2P MODE received.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 /*
579 * Until there's a transition from loop down to loop up, treat
580 * this as loop down only.
581 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800582 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
583 atomic_set(&vha->loop_state, LOOP_DOWN);
584 if (!atomic_read(&vha->loop_down_timer))
585 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800587 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 }
589
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800590 if (vha->vp_idx) {
591 atomic_set(&vha->vp_state, VP_FAILED);
592 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700593 }
594
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800595 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
596 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
597
598 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
599 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800600
601 ha->flags.gpsc_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800602 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 break;
604
605 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
606 if (IS_QLA2100(ha))
607 break;
608
Chad Dupuiscfb09192011-11-18 09:03:07 -0800609 ql_dbg(ql_dbg_async, vha, 0x500f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 "Configuration change detected: value=%x.\n", mb[1]);
611
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800612 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
613 atomic_set(&vha->loop_state, LOOP_DOWN);
614 if (!atomic_read(&vha->loop_down_timer))
615 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800617 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 }
619
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800620 if (vha->vp_idx) {
621 atomic_set(&vha->vp_state, VP_FAILED);
622 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700623 }
624
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800625 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
626 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 break;
628
629 case MBA_PORT_UPDATE: /* Port database update */
Santosh Vernekar55903b92009-07-31 15:09:25 -0700630 /*
631 * Handle only global and vn-port update events
632 *
633 * Relevant inputs:
634 * mb[1] = N_Port handle of changed port
635 * OR 0xffff for global event
636 * mb[2] = New login state
637 * 7 = Port logged out
638 * mb[3] = LSB is vp_idx, 0xff = all vps
639 *
640 * Skip processing if:
641 * Event is global, vp_idx is NOT all vps,
642 * vp_idx does not match
643 * Event is not global, vp_idx does not match
644 */
Andrew Vasquez12cec63e42010-03-19 16:59:17 -0700645 if (IS_QLA2XXX_MIDTYPE(ha) &&
646 ((mb[1] == 0xffff && (mb[3] & 0xff) != 0xff) ||
647 (mb[1] != 0xffff)) && vha->vp_idx != (mb[3] & 0xff))
648 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800649
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700650 /* Global event -- port logout or port unavailable. */
651 if (mb[1] == 0xffff && mb[2] == 0x7) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700652 ql_dbg(ql_dbg_async, vha, 0x5010,
653 "Port unavailable %04x %04x %04x.\n",
654 mb[1], mb[2], mb[3]);
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400655 ql_log(ql_log_warn, vha, 0x505e,
656 "Link is offline.\n");
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700657
658 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
659 atomic_set(&vha->loop_state, LOOP_DOWN);
660 atomic_set(&vha->loop_down_timer,
661 LOOP_DOWN_TIME);
662 vha->device_flags |= DFLG_NO_CABLE;
663 qla2x00_mark_all_devices_lost(vha, 1);
664 }
665
666 if (vha->vp_idx) {
667 atomic_set(&vha->vp_state, VP_FAILED);
668 fc_vport_set_state(vha->fc_vport,
669 FC_VPORT_FAILED);
Santosh Vernekarfaadc5e2009-07-31 15:09:26 -0700670 qla2x00_mark_all_devices_lost(vha, 1);
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700671 }
672
673 vha->flags.management_server_logged_in = 0;
674 ha->link_data_rate = PORT_SPEED_UNKNOWN;
675 break;
676 }
677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 /*
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700679 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 * event etc. earlier indicating loop is down) then process
681 * it. Otherwise ignore it and Wait for RSCN to come in.
682 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800683 atomic_set(&vha->loop_down_timer, 0);
684 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
685 atomic_read(&vha->loop_state) != LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700686 ql_dbg(ql_dbg_async, vha, 0x5011,
687 "Asynchronous PORT UPDATE ignored %04x/%04x/%04x.\n",
688 mb[1], mb[2], mb[3]);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400689
690 qlt_async_event(mb[0], vha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 break;
692 }
693
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700694 ql_dbg(ql_dbg_async, vha, 0x5012,
695 "Port database changed %04x %04x %04x.\n",
696 mb[1], mb[2], mb[3]);
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400697 ql_log(ql_log_warn, vha, 0x505f,
698 "Link is operational (%s Gbps).\n",
699 qla2x00_get_link_speed_str(ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
701 /*
702 * Mark all devices as missing so we will login again.
703 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800704 atomic_set(&vha->loop_state, LOOP_UP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800706 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400708 if (vha->vp_idx == 0 && !qla_ini_mode_enabled(vha))
709 set_bit(SCR_PENDING, &vha->dpc_flags);
710
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800711 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
712 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400713
714 qlt_async_event(mb[0], vha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 break;
716
717 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju3c397402008-05-19 14:25:39 -0700718 /* Check if the Vport has issued a SCR */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800719 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
Seokmann Ju3c397402008-05-19 14:25:39 -0700720 break;
721 /* Only handle SCNs for our Vport index. */
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700722 if (ha->flags.npiv_supported && vha->vp_idx != (mb[3] & 0xff))
Seokmann Ju3c397402008-05-19 14:25:39 -0700723 break;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700724
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700725 ql_dbg(ql_dbg_async, vha, 0x5013,
726 "RSCN database changed -- %04x %04x %04x.\n",
727 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
Ravi Anand59d72d82008-09-11 21:22:53 -0700729 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800730 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
731 | vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 if (rscn_entry == host_pid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700733 ql_dbg(ql_dbg_async, vha, 0x5014,
734 "Ignoring RSCN update to local host "
735 "port ID (%06x).\n", host_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 break;
737 }
738
Ravi Anand59d72d82008-09-11 21:22:53 -0700739 /* Ignore reserved bits from RSCN-payload. */
740 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800742 atomic_set(&vha->loop_down_timer, 0);
743 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800745 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
746 set_bit(RSCN_UPDATE, &vha->dpc_flags);
747 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 break;
749
750 /* case MBA_RIO_RESPONSE: */
751 case MBA_ZIO_RESPONSE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700752 ql_dbg(ql_dbg_async, vha, 0x5015,
753 "[R|Z]IO update completion.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Andrew Vasqueze4289242007-07-19 15:05:56 -0700755 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700756 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700757 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800758 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700760
761 case MBA_DISCARD_RND_FRAME:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700762 ql_dbg(ql_dbg_async, vha, 0x5016,
763 "Discard RND Frame -- %04x %04x %04x.\n",
764 mb[1], mb[2], mb[3]);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700765 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700766
767 case MBA_TRACE_NOTIFICATION:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700768 ql_dbg(ql_dbg_async, vha, 0x5017,
769 "Trace Notification -- %04x %04x.\n", mb[1], mb[2]);
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700770 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700771
772 case MBA_ISP84XX_ALERT:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700773 ql_dbg(ql_dbg_async, vha, 0x5018,
774 "ISP84XX Alert Notification -- %04x %04x %04x.\n",
775 mb[1], mb[2], mb[3]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700776
777 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
778 switch (mb[1]) {
779 case A84_PANIC_RECOVERY:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700780 ql_log(ql_log_info, vha, 0x5019,
781 "Alert 84XX: panic recovery %04x %04x.\n",
782 mb[2], mb[3]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700783 break;
784 case A84_OP_LOGIN_COMPLETE:
785 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700786 ql_log(ql_log_info, vha, 0x501a,
787 "Alert 84XX: firmware version %x.\n",
788 ha->cs84xx->op_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700789 break;
790 case A84_DIAG_LOGIN_COMPLETE:
791 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700792 ql_log(ql_log_info, vha, 0x501b,
793 "Alert 84XX: diagnostic firmware version %x.\n",
794 ha->cs84xx->diag_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700795 break;
796 case A84_GOLD_LOGIN_COMPLETE:
797 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
798 ha->cs84xx->fw_update = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700799 ql_log(ql_log_info, vha, 0x501c,
800 "Alert 84XX: gold firmware version %x.\n",
801 ha->cs84xx->gold_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700802 break;
803 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700804 ql_log(ql_log_warn, vha, 0x501d,
805 "Alert 84xx: Invalid Alert %04x %04x %04x.\n",
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700806 mb[1], mb[2], mb[3]);
807 }
808 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
809 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800810 case MBA_DCBX_START:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700811 ql_dbg(ql_dbg_async, vha, 0x501e,
812 "DCBX Started -- %04x %04x %04x.\n",
813 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800814 break;
815 case MBA_DCBX_PARAM_UPDATE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700816 ql_dbg(ql_dbg_async, vha, 0x501f,
817 "DCBX Parameters Updated -- %04x %04x %04x.\n",
818 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800819 break;
820 case MBA_FCF_CONF_ERR:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700821 ql_dbg(ql_dbg_async, vha, 0x5020,
822 "FCF Configuration Error -- %04x %04x %04x.\n",
823 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800824 break;
825 case MBA_IDC_COMPLETE:
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800826 case MBA_IDC_NOTIFY:
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800827 case MBA_IDC_TIME_EXT:
Andrew Vasquez8a659572009-02-08 20:50:12 -0800828 qla81xx_idc_event(vha, mb[0], mb[1]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800829 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800830 default:
831 ql_dbg(ql_dbg_async, vha, 0x5057,
832 "Unknown AEN:%04x %04x %04x %04x\n",
833 mb[0], mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700835
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400836 qlt_async_event(mb[0], vha, mb);
837
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800838 if (!vha->vp_idx && ha->num_vhosts)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800839 qla2x00_alert_all_vps(rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840}
841
842/**
843 * qla2x00_process_completed_request() - Process a Fast Post response.
844 * @ha: SCSI driver HA context
845 * @index: SRB index
846 */
847static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800848qla2x00_process_completed_request(struct scsi_qla_host *vha,
849 struct req_que *req, uint32_t index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850{
851 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800852 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 /* Validate handle. */
855 if (index >= MAX_OUTSTANDING_COMMANDS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700856 ql_log(ql_log_warn, vha, 0x3014,
857 "Invalid SCSI command index (%x).\n", index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Giridhar Malavali8f7daea2011-03-30 11:46:26 -0700859 if (IS_QLA82XX(ha))
860 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
861 else
862 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 return;
864 }
865
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800866 sp = req->outstanding_cmds[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 if (sp) {
868 /* Free outstanding command slot. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800869 req->outstanding_cmds[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 /* Save ISP completion status */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800872 sp->done(ha, sp, DID_OK << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700874 ql_log(ql_log_warn, vha, 0x3016, "Invalid SCSI SRB.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Giridhar Malavali8f7daea2011-03-30 11:46:26 -0700876 if (IS_QLA82XX(ha))
877 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
878 else
879 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 }
881}
882
Andrew Vasquezac280b62009-08-20 11:06:05 -0700883static srb_t *
884qla2x00_get_sp_from_handle(scsi_qla_host_t *vha, const char *func,
885 struct req_que *req, void *iocb)
886{
887 struct qla_hw_data *ha = vha->hw;
888 sts_entry_t *pkt = iocb;
889 srb_t *sp = NULL;
890 uint16_t index;
891
892 index = LSW(pkt->handle);
893 if (index >= MAX_OUTSTANDING_COMMANDS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700894 ql_log(ql_log_warn, vha, 0x5031,
895 "Invalid command index (%x).\n", index);
Giridhar Malavali8f7daea2011-03-30 11:46:26 -0700896 if (IS_QLA82XX(ha))
897 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
898 else
899 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700900 goto done;
901 }
902 sp = req->outstanding_cmds[index];
903 if (!sp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700904 ql_log(ql_log_warn, vha, 0x5032,
905 "Invalid completion handle (%x) -- timed-out.\n", index);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700906 return sp;
907 }
908 if (sp->handle != index) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700909 ql_log(ql_log_warn, vha, 0x5033,
910 "SRB handle (%x) mismatch %x.\n", sp->handle, index);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700911 return NULL;
912 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800913
Andrew Vasquezac280b62009-08-20 11:06:05 -0700914 req->outstanding_cmds[index] = NULL;
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800915
Andrew Vasquezac280b62009-08-20 11:06:05 -0700916done:
917 return sp;
918}
919
920static void
921qla2x00_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
922 struct mbx_entry *mbx)
923{
924 const char func[] = "MBX-IOCB";
925 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700926 fc_port_t *fcport;
927 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700928 struct srb_iocb *lio;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700929 uint16_t *data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700930 uint16_t status;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700931
932 sp = qla2x00_get_sp_from_handle(vha, func, req, mbx);
933 if (!sp)
934 return;
935
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800936 lio = &sp->u.iocb_cmd;
937 type = sp->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700938 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700939 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700940
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700941 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700942 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700943 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700944 if (mbx->entry_status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700945 ql_dbg(ql_dbg_async, vha, 0x5043,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800946 "Async-%s error entry - hdl=%x portid=%02x%02x%02x "
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -0700947 "entry-status=%x status=%x state-flag=%x "
Chad Dupuiscfb09192011-11-18 09:03:07 -0800948 "status-flags=%x.\n", type, sp->handle,
949 fcport->d_id.b.domain, fcport->d_id.b.area,
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -0700950 fcport->d_id.b.al_pa, mbx->entry_status,
951 le16_to_cpu(mbx->status), le16_to_cpu(mbx->state_flags),
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700952 le16_to_cpu(mbx->status_flags));
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -0700953
Chad Dupuiscfb09192011-11-18 09:03:07 -0800954 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5029,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700955 (uint8_t *)mbx, sizeof(*mbx));
Andrew Vasquezac280b62009-08-20 11:06:05 -0700956
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700957 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700958 }
959
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700960 status = le16_to_cpu(mbx->status);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800961 if (status == 0x30 && sp->type == SRB_LOGIN_CMD &&
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700962 le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE)
963 status = 0;
964 if (!status && le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700965 ql_dbg(ql_dbg_async, vha, 0x5045,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800966 "Async-%s complete - hdl=%x portid=%02x%02x%02x mbx1=%x.\n",
967 type, sp->handle, fcport->d_id.b.domain,
968 fcport->d_id.b.area, fcport->d_id.b.al_pa,
969 le16_to_cpu(mbx->mb1));
Andrew Vasquezac280b62009-08-20 11:06:05 -0700970
971 data[0] = MBS_COMMAND_COMPLETE;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800972 if (sp->type == SRB_LOGIN_CMD) {
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700973 fcport->port_type = FCT_TARGET;
974 if (le16_to_cpu(mbx->mb1) & BIT_0)
975 fcport->port_type = FCT_INITIATOR;
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700976 else if (le16_to_cpu(mbx->mb1) & BIT_1)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700977 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700978 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700979 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700980 }
981
982 data[0] = le16_to_cpu(mbx->mb0);
983 switch (data[0]) {
984 case MBS_PORT_ID_USED:
985 data[1] = le16_to_cpu(mbx->mb1);
986 break;
987 case MBS_LOOP_ID_USED:
988 break;
989 default:
990 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700991 break;
992 }
993
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700994 ql_log(ql_log_warn, vha, 0x5046,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800995 "Async-%s failed - hdl=%x portid=%02x%02x%02x status=%x "
996 "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n", type, sp->handle,
997 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
998 status, le16_to_cpu(mbx->mb0), le16_to_cpu(mbx->mb1),
Andrew Vasquezac280b62009-08-20 11:06:05 -0700999 le16_to_cpu(mbx->mb2), le16_to_cpu(mbx->mb6),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001000 le16_to_cpu(mbx->mb7));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001001
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001002logio_done:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001003 sp->done(vha, sp, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001004}
1005
1006static void
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001007qla2x00_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1008 sts_entry_t *pkt, int iocb_type)
1009{
1010 const char func[] = "CT_IOCB";
1011 const char *type;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001012 srb_t *sp;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001013 struct fc_bsg_job *bsg_job;
1014 uint16_t comp_status;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001015 int res;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001016
1017 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1018 if (!sp)
1019 return;
1020
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001021 bsg_job = sp->u.bsg_job;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001022
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001023 type = "ct pass-through";
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001024
1025 comp_status = le16_to_cpu(pkt->comp_status);
1026
1027 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1028 * fc payload to the caller
1029 */
1030 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1031 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1032
1033 if (comp_status != CS_COMPLETE) {
1034 if (comp_status == CS_DATA_UNDERRUN) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001035 res = DID_OK << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001036 bsg_job->reply->reply_payload_rcv_len =
1037 le16_to_cpu(((sts_entry_t *)pkt)->rsp_info_len);
1038
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001039 ql_log(ql_log_warn, vha, 0x5048,
1040 "CT pass-through-%s error "
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001041 "comp_status-status=0x%x total_byte = 0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001042 type, comp_status,
1043 bsg_job->reply->reply_payload_rcv_len);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001044 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001045 ql_log(ql_log_warn, vha, 0x5049,
1046 "CT pass-through-%s error "
1047 "comp_status-status=0x%x.\n", type, comp_status);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001048 res = DID_ERROR << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001049 bsg_job->reply->reply_payload_rcv_len = 0;
1050 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001051 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5035,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001052 (uint8_t *)pkt, sizeof(*pkt));
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001053 } else {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001054 res = DID_OK << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001055 bsg_job->reply->reply_payload_rcv_len =
1056 bsg_job->reply_payload.payload_len;
1057 bsg_job->reply_len = 0;
1058 }
1059
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001060 sp->done(vha, sp, res);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001061}
1062
1063static void
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001064qla24xx_els_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1065 struct sts_entry_24xx *pkt, int iocb_type)
1066{
1067 const char func[] = "ELS_CT_IOCB";
1068 const char *type;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001069 srb_t *sp;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001070 struct fc_bsg_job *bsg_job;
1071 uint16_t comp_status;
1072 uint32_t fw_status[3];
1073 uint8_t* fw_sts_ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001074 int res;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001075
1076 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1077 if (!sp)
1078 return;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001079 bsg_job = sp->u.bsg_job;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001080
1081 type = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001082 switch (sp->type) {
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001083 case SRB_ELS_CMD_RPT:
1084 case SRB_ELS_CMD_HST:
1085 type = "els";
1086 break;
1087 case SRB_CT_CMD:
1088 type = "ct pass-through";
1089 break;
1090 default:
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001091 ql_dbg(ql_dbg_user, vha, 0x503e,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001092 "Unrecognized SRB: (%p) type=%d.\n", sp, sp->type);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001093 return;
1094 }
1095
1096 comp_status = fw_status[0] = le16_to_cpu(pkt->comp_status);
1097 fw_status[1] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1);
1098 fw_status[2] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2);
1099
1100 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1101 * fc payload to the caller
1102 */
1103 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1104 bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(fw_status);
1105
1106 if (comp_status != CS_COMPLETE) {
1107 if (comp_status == CS_DATA_UNDERRUN) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001108 res = DID_OK << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001109 bsg_job->reply->reply_payload_rcv_len =
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001110 le16_to_cpu(((struct els_sts_entry_24xx *)pkt)->total_byte_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001111
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001112 ql_dbg(ql_dbg_user, vha, 0x503f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001113 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001114 "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001115 type, sp->handle, comp_status, fw_status[1], fw_status[2],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001116 le16_to_cpu(((struct els_sts_entry_24xx *)
1117 pkt)->total_byte_count));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001118 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1119 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1120 }
1121 else {
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001122 ql_dbg(ql_dbg_user, vha, 0x5040,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001123 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001124 "error subcode 1=0x%x error subcode 2=0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001125 type, sp->handle, comp_status,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001126 le16_to_cpu(((struct els_sts_entry_24xx *)
1127 pkt)->error_subcode_1),
1128 le16_to_cpu(((struct els_sts_entry_24xx *)
1129 pkt)->error_subcode_2));
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001130 res = DID_ERROR << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001131 bsg_job->reply->reply_payload_rcv_len = 0;
1132 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1133 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1134 }
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001135 ql_dump_buffer(ql_dbg_user + ql_dbg_buffer, vha, 0x5056,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001136 (uint8_t *)pkt, sizeof(*pkt));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001137 }
1138 else {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001139 res = DID_OK << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001140 bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
1141 bsg_job->reply_len = 0;
1142 }
1143
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001144 sp->done(vha, sp, res);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001145}
1146
1147static void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001148qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req,
1149 struct logio_entry_24xx *logio)
1150{
1151 const char func[] = "LOGIO-IOCB";
1152 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001153 fc_port_t *fcport;
1154 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001155 struct srb_iocb *lio;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001156 uint16_t *data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001157 uint32_t iop[2];
1158
1159 sp = qla2x00_get_sp_from_handle(vha, func, req, logio);
1160 if (!sp)
1161 return;
1162
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001163 lio = &sp->u.iocb_cmd;
1164 type = sp->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001165 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001166 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001167
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001168 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001169 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001170 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001171 if (logio->entry_status) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001172 ql_log(ql_log_warn, fcport->vha, 0x5034,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001173 "Async-%s error entry - hdl=%x"
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001174 "portid=%02x%02x%02x entry-status=%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001175 type, sp->handle, fcport->d_id.b.domain,
1176 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1177 logio->entry_status);
1178 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x504d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001179 (uint8_t *)logio, sizeof(*logio));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001180
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001181 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001182 }
1183
1184 if (le16_to_cpu(logio->comp_status) == CS_COMPLETE) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001185 ql_dbg(ql_dbg_async, fcport->vha, 0x5036,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001186 "Async-%s complete - hdl=%x portid=%02x%02x%02x "
1187 "iop0=%x.\n", type, sp->handle, fcport->d_id.b.domain,
1188 fcport->d_id.b.area, fcport->d_id.b.al_pa,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001189 le32_to_cpu(logio->io_parameter[0]));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001190
1191 data[0] = MBS_COMMAND_COMPLETE;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001192 if (sp->type != SRB_LOGIN_CMD)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001193 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001194
1195 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1196 if (iop[0] & BIT_4) {
1197 fcport->port_type = FCT_TARGET;
1198 if (iop[0] & BIT_8)
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07001199 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquezb0cd5792010-05-28 15:08:22 -07001200 } else if (iop[0] & BIT_5)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001201 fcport->port_type = FCT_INITIATOR;
Andrew Vasquezb0cd5792010-05-28 15:08:22 -07001202
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001203 if (iop[0] & BIT_7)
1204 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
1205
Andrew Vasquezac280b62009-08-20 11:06:05 -07001206 if (logio->io_parameter[7] || logio->io_parameter[8])
1207 fcport->supported_classes |= FC_COS_CLASS2;
1208 if (logio->io_parameter[9] || logio->io_parameter[10])
1209 fcport->supported_classes |= FC_COS_CLASS3;
1210
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001211 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001212 }
1213
1214 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1215 iop[1] = le32_to_cpu(logio->io_parameter[1]);
1216 switch (iop[0]) {
1217 case LSC_SCODE_PORTID_USED:
1218 data[0] = MBS_PORT_ID_USED;
1219 data[1] = LSW(iop[1]);
1220 break;
1221 case LSC_SCODE_NPORT_USED:
1222 data[0] = MBS_LOOP_ID_USED;
1223 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001224 default:
1225 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001226 break;
1227 }
1228
Arun Easi5e19ed92012-02-09 11:15:51 -08001229 ql_dbg(ql_dbg_async, fcport->vha, 0x5037,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001230 "Async-%s failed - hdl=%x portid=%02x%02x%02x comp=%x "
1231 "iop0=%x iop1=%x.\n", type, sp->handle, fcport->d_id.b.domain,
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001232 fcport->d_id.b.area, fcport->d_id.b.al_pa,
Andrew Vasquezac280b62009-08-20 11:06:05 -07001233 le16_to_cpu(logio->comp_status),
1234 le32_to_cpu(logio->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001235 le32_to_cpu(logio->io_parameter[1]));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001236
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001237logio_done:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001238 sp->done(vha, sp, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001239}
1240
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001241static void
1242qla24xx_tm_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1243 struct tsk_mgmt_entry *tsk)
1244{
1245 const char func[] = "TMF-IOCB";
1246 const char *type;
1247 fc_port_t *fcport;
1248 srb_t *sp;
1249 struct srb_iocb *iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001250 struct sts_entry_24xx *sts = (struct sts_entry_24xx *)tsk;
1251 int error = 1;
1252
1253 sp = qla2x00_get_sp_from_handle(vha, func, req, tsk);
1254 if (!sp)
1255 return;
1256
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001257 iocb = &sp->u.iocb_cmd;
1258 type = sp->name;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001259 fcport = sp->fcport;
1260
1261 if (sts->entry_status) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001262 ql_log(ql_log_warn, fcport->vha, 0x5038,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001263 "Async-%s error - hdl=%x entry-status(%x).\n",
1264 type, sp->handle, sts->entry_status);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001265 } else if (sts->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001266 ql_log(ql_log_warn, fcport->vha, 0x5039,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001267 "Async-%s error - hdl=%x completion status(%x).\n",
1268 type, sp->handle, sts->comp_status);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001269 } else if (!(le16_to_cpu(sts->scsi_status) &
1270 SS_RESPONSE_INFO_LEN_VALID)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001271 ql_log(ql_log_warn, fcport->vha, 0x503a,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001272 "Async-%s error - hdl=%x no response info(%x).\n",
1273 type, sp->handle, sts->scsi_status);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001274 } else if (le32_to_cpu(sts->rsp_data_len) < 4) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001275 ql_log(ql_log_warn, fcport->vha, 0x503b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001276 "Async-%s error - hdl=%x not enough response(%d).\n",
1277 type, sp->handle, sts->rsp_data_len);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001278 } else if (sts->data[3]) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001279 ql_log(ql_log_warn, fcport->vha, 0x503c,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001280 "Async-%s error - hdl=%x response(%x).\n",
1281 type, sp->handle, sts->data[3]);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001282 } else {
1283 error = 0;
1284 }
1285
1286 if (error) {
1287 iocb->u.tmf.data = error;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001288 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5055,
1289 (uint8_t *)sts, sizeof(*sts));
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001290 }
1291
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001292 sp->done(vha, sp, 0);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001293}
1294
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295/**
1296 * qla2x00_process_response_queue() - Process response queue entries.
1297 * @ha: SCSI driver HA context
1298 */
1299void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001300qla2x00_process_response_queue(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001302 struct scsi_qla_host *vha;
1303 struct qla_hw_data *ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001304 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 sts_entry_t *pkt;
1306 uint16_t handle_cnt;
1307 uint16_t cnt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001308
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001309 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001311 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 return;
1313
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001314 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1315 pkt = (sts_entry_t *)rsp->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001317 rsp->ring_index++;
1318 if (rsp->ring_index == rsp->length) {
1319 rsp->ring_index = 0;
1320 rsp->ring_ptr = rsp->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001322 rsp->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 }
1324
1325 if (pkt->entry_status != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001326 qla2x00_error_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1328 wmb();
1329 continue;
1330 }
1331
1332 switch (pkt->entry_type) {
1333 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001334 qla2x00_status_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 break;
1336 case STATUS_TYPE_21:
1337 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
1338 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001339 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 ((sts21_entry_t *)pkt)->handle[cnt]);
1341 }
1342 break;
1343 case STATUS_TYPE_22:
1344 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
1345 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001346 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 ((sts22_entry_t *)pkt)->handle[cnt]);
1348 }
1349 break;
1350 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001351 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001353 case MBX_IOCB_TYPE:
1354 qla2x00_mbx_iocb_entry(vha, rsp->req,
1355 (struct mbx_entry *)pkt);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001356 break;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001357 case CT_IOCB_TYPE:
1358 qla2x00_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
1359 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 default:
1361 /* Type Not Supported. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001362 ql_log(ql_log_warn, vha, 0x504a,
1363 "Received unknown response pkt type %x "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 "entry status=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001365 pkt->entry_type, pkt->entry_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 break;
1367 }
1368 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1369 wmb();
1370 }
1371
1372 /* Adjust ring index */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001373 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374}
1375
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001376static inline void
Andrew Vasquez55442132010-07-23 15:28:27 +05001377qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t par_sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001378 uint32_t sense_len, struct rsp_que *rsp, int res)
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001379{
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001380 struct scsi_qla_host *vha = sp->fcport->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001381 struct scsi_cmnd *cp = GET_CMD_SP(sp);
1382 uint32_t track_sense_len;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001383
1384 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
1385 sense_len = SCSI_SENSE_BUFFERSIZE;
1386
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001387 SET_CMD_SENSE_LEN(sp, sense_len);
1388 SET_CMD_SENSE_PTR(sp, cp->sense_buffer);
1389 track_sense_len = sense_len;
1390
1391 if (sense_len > par_sense_len)
Andrew Vasquez55442132010-07-23 15:28:27 +05001392 sense_len = par_sense_len;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001393
1394 memcpy(cp->sense_buffer, sense_data, sense_len);
1395
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001396 SET_CMD_SENSE_PTR(sp, cp->sense_buffer + sense_len);
1397 track_sense_len -= sense_len;
1398 SET_CMD_SENSE_LEN(sp, track_sense_len);
1399
1400 if (track_sense_len != 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001401 rsp->status_srb = sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001402 cp->result = res;
1403 }
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001404
Chad Dupuiscfb09192011-11-18 09:03:07 -08001405 if (sense_len) {
1406 ql_dbg(ql_dbg_io + ql_dbg_buffer, vha, 0x301c,
1407 "Check condition Sense data, nexus%ld:%d:%d cmd=%p.\n",
1408 sp->fcport->vha->host_no, cp->device->id, cp->device->lun,
1409 cp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001410 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302b,
1411 cp->sense_buffer, sense_len);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001412 }
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001413}
1414
Arun Easibad75002010-05-04 15:01:30 -07001415struct scsi_dif_tuple {
1416 __be16 guard; /* Checksum */
1417 __be16 app_tag; /* APPL identifer */
1418 __be32 ref_tag; /* Target LBA or indirect LBA */
1419};
1420
1421/*
1422 * Checks the guard or meta-data for the type of error
1423 * detected by the HBA. In case of errors, we set the
1424 * ASC/ASCQ fields in the sense buffer with ILLEGAL_REQUEST
1425 * to indicate to the kernel that the HBA detected error.
1426 */
Arun Easi8cb20492011-08-16 11:29:22 -07001427static inline int
Arun Easibad75002010-05-04 15:01:30 -07001428qla2x00_handle_dif_error(srb_t *sp, struct sts_entry_24xx *sts24)
1429{
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001430 struct scsi_qla_host *vha = sp->fcport->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001431 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Arun Easi8cb20492011-08-16 11:29:22 -07001432 uint8_t *ap = &sts24->data[12];
1433 uint8_t *ep = &sts24->data[20];
Arun Easibad75002010-05-04 15:01:30 -07001434 uint32_t e_ref_tag, a_ref_tag;
1435 uint16_t e_app_tag, a_app_tag;
1436 uint16_t e_guard, a_guard;
1437
Arun Easi8cb20492011-08-16 11:29:22 -07001438 /*
1439 * swab32 of the "data" field in the beginning of qla2x00_status_entry()
1440 * would make guard field appear at offset 2
1441 */
1442 a_guard = le16_to_cpu(*(uint16_t *)(ap + 2));
1443 a_app_tag = le16_to_cpu(*(uint16_t *)(ap + 0));
1444 a_ref_tag = le32_to_cpu(*(uint32_t *)(ap + 4));
1445 e_guard = le16_to_cpu(*(uint16_t *)(ep + 2));
1446 e_app_tag = le16_to_cpu(*(uint16_t *)(ep + 0));
1447 e_ref_tag = le32_to_cpu(*(uint32_t *)(ep + 4));
Arun Easibad75002010-05-04 15:01:30 -07001448
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001449 ql_dbg(ql_dbg_io, vha, 0x3023,
1450 "iocb(s) %p Returned STATUS.\n", sts24);
Arun Easibad75002010-05-04 15:01:30 -07001451
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001452 ql_dbg(ql_dbg_io, vha, 0x3024,
1453 "DIF ERROR in cmd 0x%x lba 0x%llx act ref"
Arun Easibad75002010-05-04 15:01:30 -07001454 " tag=0x%x, exp ref_tag=0x%x, act app tag=0x%x, exp app"
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001455 " tag=0x%x, act guard=0x%x, exp guard=0x%x.\n",
Arun Easibad75002010-05-04 15:01:30 -07001456 cmd->cmnd[0], (u64)scsi_get_lba(cmd), a_ref_tag, e_ref_tag,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001457 a_app_tag, e_app_tag, a_guard, e_guard);
Arun Easibad75002010-05-04 15:01:30 -07001458
Arun Easi8cb20492011-08-16 11:29:22 -07001459 /*
1460 * Ignore sector if:
1461 * For type 3: ref & app tag is all 'f's
1462 * For type 0,1,2: app tag is all 'f's
1463 */
1464 if ((a_app_tag == 0xffff) &&
1465 ((scsi_get_prot_type(cmd) != SCSI_PROT_DIF_TYPE3) ||
1466 (a_ref_tag == 0xffffffff))) {
1467 uint32_t blocks_done, resid;
1468 sector_t lba_s = scsi_get_lba(cmd);
1469
1470 /* 2TB boundary case covered automatically with this */
1471 blocks_done = e_ref_tag - (uint32_t)lba_s + 1;
1472
1473 resid = scsi_bufflen(cmd) - (blocks_done *
1474 cmd->device->sector_size);
1475
1476 scsi_set_resid(cmd, resid);
1477 cmd->result = DID_OK << 16;
1478
1479 /* Update protection tag */
1480 if (scsi_prot_sg_count(cmd)) {
1481 uint32_t i, j = 0, k = 0, num_ent;
1482 struct scatterlist *sg;
1483 struct sd_dif_tuple *spt;
1484
1485 /* Patch the corresponding protection tags */
1486 scsi_for_each_prot_sg(cmd, sg,
1487 scsi_prot_sg_count(cmd), i) {
1488 num_ent = sg_dma_len(sg) / 8;
1489 if (k + num_ent < blocks_done) {
1490 k += num_ent;
1491 continue;
1492 }
1493 j = blocks_done - k - 1;
1494 k = blocks_done;
1495 break;
1496 }
1497
1498 if (k != blocks_done) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001499 ql_log(ql_log_warn, vha, 0x302f,
Randy Dunlap8ec9c7f2011-09-23 15:40:50 -07001500 "unexpected tag values tag:lba=%x:%llx)\n",
1501 e_ref_tag, (unsigned long long)lba_s);
Arun Easi8cb20492011-08-16 11:29:22 -07001502 return 1;
1503 }
1504
1505 spt = page_address(sg_page(sg)) + sg->offset;
1506 spt += j;
1507
1508 spt->app_tag = 0xffff;
1509 if (scsi_get_prot_type(cmd) == SCSI_PROT_DIF_TYPE3)
1510 spt->ref_tag = 0xffffffff;
1511 }
1512
1513 return 0;
1514 }
1515
Arun Easibad75002010-05-04 15:01:30 -07001516 /* check guard */
1517 if (e_guard != a_guard) {
1518 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1519 0x10, 0x1);
1520 set_driver_byte(cmd, DRIVER_SENSE);
1521 set_host_byte(cmd, DID_ABORT);
1522 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
Arun Easi8cb20492011-08-16 11:29:22 -07001523 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001524 }
1525
Arun Easie02587d2011-08-16 11:29:23 -07001526 /* check ref tag */
1527 if (e_ref_tag != a_ref_tag) {
1528 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1529 0x10, 0x3);
1530 set_driver_byte(cmd, DRIVER_SENSE);
1531 set_host_byte(cmd, DID_ABORT);
1532 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
1533 return 1;
1534 }
1535
Arun Easibad75002010-05-04 15:01:30 -07001536 /* check appl tag */
1537 if (e_app_tag != a_app_tag) {
1538 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1539 0x10, 0x2);
1540 set_driver_byte(cmd, DRIVER_SENSE);
1541 set_host_byte(cmd, DID_ABORT);
1542 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
Arun Easi8cb20492011-08-16 11:29:22 -07001543 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001544 }
1545
Arun Easi8cb20492011-08-16 11:29:22 -07001546 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001547}
1548
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549/**
1550 * qla2x00_status_entry() - Process a Status IOCB entry.
1551 * @ha: SCSI driver HA context
1552 * @pkt: Entry pointer
1553 */
1554static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001555qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 fc_port_t *fcport;
1559 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001560 sts_entry_t *sts;
1561 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 uint16_t comp_status;
1563 uint16_t scsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001564 uint16_t ox_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 uint8_t lscsi_status;
1566 int32_t resid;
Andrew Vasquez55442132010-07-23 15:28:27 +05001567 uint32_t sense_len, par_sense_len, rsp_info_len, resid_len,
1568 fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001569 uint8_t *rsp_info, *sense_data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001570 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001571 uint32_t handle;
1572 uint16_t que;
1573 struct req_que *req;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001574 int logit = 1;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001575 int res = 0;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001576
1577 sts = (sts_entry_t *) pkt;
1578 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001579 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001580 comp_status = le16_to_cpu(sts24->comp_status);
1581 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
1582 } else {
1583 comp_status = le16_to_cpu(sts->comp_status);
1584 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1585 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001586 handle = (uint32_t) LSW(sts->handle);
1587 que = MSW(sts->handle);
1588 req = ha->req_q_map[que];
Giridhar Malavalia9083012010-04-12 17:59:55 -07001589
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001591 if (comp_status == CS_COMPLETE && scsi_status == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001592 qla2x00_process_completed_request(vha, req, handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
1594 return;
1595 }
1596
1597 /* Validate handle. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001598 if (handle < MAX_OUTSTANDING_COMMANDS) {
1599 sp = req->outstanding_cmds[handle];
1600 req->outstanding_cmds[handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 } else
1602 sp = NULL;
1603
1604 if (sp == NULL) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001605 ql_dbg(ql_dbg_io, vha, 0x3017,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001606 "Invalid status handle (0x%x).\n", sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001608 if (IS_QLA82XX(ha))
1609 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1610 else
1611 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001612 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 return;
1614 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001615 cp = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 if (cp == NULL) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001617 ql_dbg(ql_dbg_io, vha, 0x3018,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001618 "Command already returned (0x%x/%p).\n",
1619 sts->handle, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
1621 return;
1622 }
1623
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001624 lscsi_status = scsi_status & STATUS_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625
bdf79622005-04-17 15:06:53 -05001626 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001628 ox_id = 0;
Andrew Vasquez55442132010-07-23 15:28:27 +05001629 sense_len = par_sense_len = rsp_info_len = resid_len =
1630 fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001631 if (IS_FWI2_CAPABLE(ha)) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001632 if (scsi_status & SS_SENSE_LEN_VALID)
1633 sense_len = le32_to_cpu(sts24->sense_len);
1634 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
1635 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
1636 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER))
1637 resid_len = le32_to_cpu(sts24->rsp_residual_count);
1638 if (comp_status == CS_DATA_UNDERRUN)
1639 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001640 rsp_info = sts24->data;
1641 sense_data = sts24->data;
1642 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001643 ox_id = le16_to_cpu(sts24->ox_id);
Andrew Vasquez55442132010-07-23 15:28:27 +05001644 par_sense_len = sizeof(sts24->data);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001645 } else {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001646 if (scsi_status & SS_SENSE_LEN_VALID)
1647 sense_len = le16_to_cpu(sts->req_sense_length);
1648 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
1649 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001650 resid_len = le32_to_cpu(sts->residual_length);
1651 rsp_info = sts->rsp_info;
1652 sense_data = sts->req_sense_data;
Andrew Vasquez55442132010-07-23 15:28:27 +05001653 par_sense_len = sizeof(sts->req_sense_data);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001654 }
1655
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 /* Check for any FCP transport errors. */
1657 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001658 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasquez55442132010-07-23 15:28:27 +05001659 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001660 sense_data += rsp_info_len;
Andrew Vasquez55442132010-07-23 15:28:27 +05001661 par_sense_len -= rsp_info_len;
1662 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001663 if (rsp_info_len > 3 && rsp_info[3]) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001664 ql_dbg(ql_dbg_io, fcport->vha, 0x3019,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001665 "FCP I/O protocol failure (0x%x/0x%x).\n",
1666 rsp_info_len, rsp_info[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001668 res = DID_BUS_BUSY << 16;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001669 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 }
1671 }
1672
Andrew Vasquez3e8ce322008-02-28 14:06:10 -08001673 /* Check for overrun. */
1674 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
1675 scsi_status & SS_RESIDUAL_OVER)
1676 comp_status = CS_DATA_OVERRUN;
1677
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 /*
1679 * Based on Host and scsi status generate status code for Linux
1680 */
1681 switch (comp_status) {
1682 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001683 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 if (scsi_status == 0) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001685 res = DID_OK << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 break;
1687 }
1688 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001689 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001690 scsi_set_resid(cp, resid);
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001691
1692 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001693 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001694 cp->underflow)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001695 ql_dbg(ql_dbg_io, fcport->vha, 0x301a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001696 "Mid-layer underflow "
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001697 "detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001698 resid, scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001699
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001700 res = DID_ERROR << 16;
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001701 break;
1702 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001704 res = DID_OK << 16 | lscsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001706 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001707 ql_dbg(ql_dbg_io, fcport->vha, 0x301b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001708 "QUEUE FULL detected.\n");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001709 break;
1710 }
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001711 logit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 if (lscsi_status != SS_CHECK_CONDITION)
1713 break;
1714
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001715 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 if (!(scsi_status & SS_SENSE_LEN_VALID))
1717 break;
1718
Andrew Vasquez55442132010-07-23 15:28:27 +05001719 qla2x00_handle_sense(sp, sense_data, par_sense_len, sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001720 rsp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 break;
1722
1723 case CS_DATA_UNDERRUN:
Ravi Ananded17c71b52006-05-17 15:08:55 -07001724 /* Use F/W calculated residual length. */
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001725 resid = IS_FWI2_CAPABLE(ha) ? fw_resid_len : resid_len;
1726 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 if (scsi_status & SS_RESIDUAL_UNDER) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001728 if (IS_FWI2_CAPABLE(ha) && fw_resid_len != resid_len) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001729 ql_dbg(ql_dbg_io, fcport->vha, 0x301d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001730 "Dropped frame(s) detected "
1731 "(0x%x of 0x%x bytes).\n",
1732 resid, scsi_bufflen(cp));
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08001733
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001734 res = DID_ERROR << 16 | lscsi_status;
Arun Easi4e85e3d2011-11-18 09:02:10 -08001735 goto check_scsi_status;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001736 }
1737
1738 if (!lscsi_status &&
1739 ((unsigned)(scsi_bufflen(cp) - resid) <
1740 cp->underflow)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001741 ql_dbg(ql_dbg_io, fcport->vha, 0x301e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001742 "Mid-layer underflow "
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001743 "detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001744 resid, scsi_bufflen(cp));
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001745
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001746 res = DID_ERROR << 16;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001747 break;
1748 }
Giridhar Malavali4aee5762012-04-25 07:26:15 -07001749 } else if (lscsi_status != SAM_STAT_TASK_SET_FULL &&
1750 lscsi_status != SAM_STAT_BUSY) {
1751 /*
1752 * scsi status of task set and busy are considered to be
1753 * task not completed.
1754 */
1755
Arun Easi5e19ed92012-02-09 11:15:51 -08001756 ql_dbg(ql_dbg_io, fcport->vha, 0x301f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001757 "Dropped frame(s) detected (0x%x "
Giridhar Malavali4aee5762012-04-25 07:26:15 -07001758 "of 0x%x bytes).\n", resid,
1759 scsi_bufflen(cp));
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001760
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001761 res = DID_ERROR << 16 | lscsi_status;
Lalit Chandivade0374f552010-09-03 14:57:04 -07001762 goto check_scsi_status;
Giridhar Malavali4aee5762012-04-25 07:26:15 -07001763 } else {
1764 ql_dbg(ql_dbg_io, fcport->vha, 0x3030,
1765 "scsi_status: 0x%x, lscsi_status: 0x%x\n",
1766 scsi_status, lscsi_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 }
1768
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001769 res = DID_OK << 16 | lscsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001770 logit = 0;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001771
Lalit Chandivade0374f552010-09-03 14:57:04 -07001772check_scsi_status:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001774 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 * Status.
1776 */
1777 if (lscsi_status != 0) {
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001778 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001779 ql_dbg(ql_dbg_io, fcport->vha, 0x3020,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001780 "QUEUE FULL detected.\n");
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001781 logit = 1;
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001782 break;
1783 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 if (lscsi_status != SS_CHECK_CONDITION)
1785 break;
1786
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001787 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 if (!(scsi_status & SS_SENSE_LEN_VALID))
1789 break;
1790
Andrew Vasquez55442132010-07-23 15:28:27 +05001791 qla2x00_handle_sense(sp, sense_data, par_sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001792 sense_len, rsp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 }
1794 break;
1795
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 case CS_PORT_LOGGED_OUT:
1797 case CS_PORT_CONFIG_CHG:
1798 case CS_PORT_BUSY:
1799 case CS_INCOMPLETE:
1800 case CS_PORT_UNAVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 case CS_TIMEOUT:
Chad Dupuisff454b02010-10-15 11:27:42 -07001802 case CS_RESET:
1803
Mike Christie056a4482008-08-19 18:45:29 -05001804 /*
1805 * We are going to have the fc class block the rport
1806 * while we try to recover so instruct the mid layer
1807 * to requeue until the class decides how to handle this.
1808 */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001809 res = DID_TRANSPORT_DISRUPTED << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001811 if (comp_status == CS_TIMEOUT) {
1812 if (IS_FWI2_CAPABLE(ha))
1813 break;
1814 else if ((le16_to_cpu(sts->status_flags) &
1815 SF_LOGOUT_SENT) == 0)
1816 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001818
Arun Easi5e19ed92012-02-09 11:15:51 -08001819 ql_dbg(ql_dbg_io, fcport->vha, 0x3021,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001820 "Port down status: port-state=0x%x.\n",
1821 atomic_read(&fcport->state));
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001822
1823 if (atomic_read(&fcport->state) == FCS_ONLINE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001824 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 break;
1826
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001827 case CS_ABORTED:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001828 res = DID_RESET << 16;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001829 break;
Arun Easibad75002010-05-04 15:01:30 -07001830
1831 case CS_DIF_ERROR:
Arun Easi8cb20492011-08-16 11:29:22 -07001832 logit = qla2x00_handle_dif_error(sp, sts24);
Arun Easibad75002010-05-04 15:01:30 -07001833 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 default:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001835 res = DID_ERROR << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 break;
1837 }
1838
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001839out:
1840 if (logit)
Arun Easi5e19ed92012-02-09 11:15:51 -08001841 ql_dbg(ql_dbg_io, fcport->vha, 0x3022,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001842 "FCP command status: 0x%x-0x%x (0x%x) "
Chad Dupuiscfb09192011-11-18 09:03:07 -08001843 "nexus=%ld:%d:%d portid=%02x%02x%02x oxid=0x%x "
1844 "cdb=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x len=0x%x "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001845 "rsp_info=0x%x resid=0x%x fw_resid=0x%x.\n",
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001846 comp_status, scsi_status, res, vha->host_no,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001847 cp->device->id, cp->device->lun, fcport->d_id.b.domain,
1848 fcport->d_id.b.area, fcport->d_id.b.al_pa, ox_id,
1849 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1850 cp->cmnd[4], cp->cmnd[5], cp->cmnd[6], cp->cmnd[7],
1851 cp->cmnd[8], cp->cmnd[9], scsi_bufflen(cp), rsp_info_len,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001852 resid_len, fw_resid_len);
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001853
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001854 if (rsp->status_srb == NULL)
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001855 sp->done(ha, sp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856}
1857
1858/**
1859 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1860 * @ha: SCSI driver HA context
1861 * @pkt: Entry pointer
1862 *
1863 * Extended sense data.
1864 */
1865static void
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001866qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001868 uint8_t sense_sz = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001869 struct qla_hw_data *ha = rsp->hw;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001870 struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001871 srb_t *sp = rsp->status_srb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 struct scsi_cmnd *cp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001873 uint32_t sense_len;
1874 uint8_t *sense_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001876 if (!sp || !GET_CMD_SENSE_LEN(sp))
1877 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001879 sense_len = GET_CMD_SENSE_LEN(sp);
1880 sense_ptr = GET_CMD_SENSE_PTR(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001882 cp = GET_CMD_SP(sp);
1883 if (cp == NULL) {
1884 ql_log(ql_log_warn, vha, 0x3025,
1885 "cmd is NULL: already returned to OS (sp=%p).\n", sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001887 rsp->status_srb = NULL;
1888 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001891 if (sense_len > sizeof(pkt->data))
1892 sense_sz = sizeof(pkt->data);
1893 else
1894 sense_sz = sense_len;
Giridhar Malavalic4631192011-11-18 09:03:08 -08001895
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001896 /* Move sense data. */
1897 if (IS_FWI2_CAPABLE(ha))
1898 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
1899 memcpy(sense_ptr, pkt->data, sense_sz);
1900 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302c,
1901 sense_ptr, sense_sz);
Giridhar Malavalic4631192011-11-18 09:03:08 -08001902
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001903 sense_len -= sense_sz;
1904 sense_ptr += sense_sz;
Giridhar Malavalic4631192011-11-18 09:03:08 -08001905
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001906 SET_CMD_SENSE_PTR(sp, sense_ptr);
1907 SET_CMD_SENSE_LEN(sp, sense_len);
Giridhar Malavalic4631192011-11-18 09:03:08 -08001908
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001909 /* Place command on done queue. */
1910 if (sense_len == 0) {
1911 rsp->status_srb = NULL;
1912 sp->done(ha, sp, cp->result);
Giridhar Malavalic4631192011-11-18 09:03:08 -08001913 }
Giridhar Malavalic4631192011-11-18 09:03:08 -08001914}
1915
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916/**
1917 * qla2x00_error_entry() - Process an error entry.
1918 * @ha: SCSI driver HA context
1919 * @pkt: Entry pointer
1920 */
1921static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001922qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923{
1924 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001925 struct qla_hw_data *ha = vha->hw;
Giridhar Malavalic4631192011-11-18 09:03:08 -08001926 const char func[] = "ERROR-IOCB";
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001927 uint16_t que = MSW(pkt->handle);
Arun Easia6fe35c2012-02-09 11:16:01 -08001928 struct req_que *req = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001929 int res = DID_ERROR << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001930
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001931 ql_dbg(ql_dbg_async, vha, 0x502a,
1932 "type of error status in response: 0x%x\n", pkt->entry_status);
1933
Arun Easia6fe35c2012-02-09 11:16:01 -08001934 if (que >= ha->max_req_queues || !ha->req_q_map[que])
1935 goto fatal;
1936
1937 req = ha->req_q_map[que];
1938
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001939 if (pkt->entry_status & RF_BUSY)
1940 res = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941
Giridhar Malavalic4631192011-11-18 09:03:08 -08001942 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
Arun Easia6fe35c2012-02-09 11:16:01 -08001943 if (sp) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001944 sp->done(ha, sp, res);
Arun Easia6fe35c2012-02-09 11:16:01 -08001945 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 }
Arun Easia6fe35c2012-02-09 11:16:01 -08001947fatal:
1948 ql_log(ql_log_warn, vha, 0x5030,
1949 "Error entry - invalid handle/queue.\n");
1950
1951 if (IS_QLA82XX(ha))
1952 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1953 else
1954 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1955 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956}
1957
1958/**
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001959 * qla24xx_mbx_completion() - Process mailbox command completions.
1960 * @ha: SCSI driver HA context
1961 * @mb0: Mailbox0 register
1962 */
1963static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001964qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001965{
1966 uint16_t cnt;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08001967 uint32_t mboxes;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001968 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001969 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001970 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1971
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08001972 /* Read all mbox registers? */
1973 mboxes = (1 << ha->mbx_count) - 1;
1974 if (!ha->mcp)
1975 ql_dbg(ql_dbg_async, vha, 0x504e, "MBX pointer ERRROR.\n");
1976 else
1977 mboxes = ha->mcp->in_mb;
1978
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001979 /* Load return mailbox registers. */
1980 ha->flags.mbox_int = 1;
1981 ha->mailbox_out[0] = mb0;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08001982 mboxes >>= 1;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001983 wptr = (uint16_t __iomem *)&reg->mailbox1;
1984
1985 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08001986 if (mboxes & BIT_0)
1987 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1988
1989 mboxes >>= 1;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001990 wptr++;
1991 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001992}
1993
1994/**
1995 * qla24xx_process_response_queue() - Process response queue entries.
1996 * @ha: SCSI driver HA context
1997 */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001998void qla24xx_process_response_queue(struct scsi_qla_host *vha,
1999 struct rsp_que *rsp)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002000{
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002001 struct sts_entry_24xx *pkt;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002002 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002003
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002004 if (!vha->flags.online)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002005 return;
2006
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002007 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
2008 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002009
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002010 rsp->ring_index++;
2011 if (rsp->ring_index == rsp->length) {
2012 rsp->ring_index = 0;
2013 rsp->ring_ptr = rsp->ring;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002014 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002015 rsp->ring_ptr++;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002016 }
2017
2018 if (pkt->entry_status != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002019 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002020
2021 (void)qlt_24xx_process_response_error(vha, pkt);
2022
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002023 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2024 wmb();
2025 continue;
2026 }
2027
2028 switch (pkt->entry_type) {
2029 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002030 qla2x00_status_entry(vha, rsp, pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002031 break;
2032 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002033 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002034 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002035 case VP_RPT_ID_IOCB_TYPE:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002036 qla24xx_report_id_acquisition(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002037 (struct vp_rpt_id_entry_24xx *)pkt);
2038 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07002039 case LOGINOUT_PORT_IOCB_TYPE:
2040 qla24xx_logio_entry(vha, rsp->req,
2041 (struct logio_entry_24xx *)pkt);
2042 break;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07002043 case TSK_MGMT_IOCB_TYPE:
2044 qla24xx_tm_iocb_entry(vha, rsp->req,
2045 (struct tsk_mgmt_entry *)pkt);
2046 break;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002047 case CT_IOCB_TYPE:
2048 qla24xx_els_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002049 break;
2050 case ELS_IOCB_TYPE:
2051 qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE);
2052 break;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002053 case ABTS_RECV_24XX:
2054 /* ensure that the ATIO queue is empty */
2055 qlt_24xx_process_atio_queue(vha);
2056 case ABTS_RESP_24XX:
2057 case CTIO_TYPE7:
2058 case NOTIFY_ACK_TYPE:
2059 qlt_response_pkt_all_vps(vha, (response_t *)pkt);
2060 break;
Saurav Kashyap54883292011-08-16 11:31:48 -07002061 case MARKER_TYPE:
2062 /* Do nothing in this case, this check is to prevent it
2063 * from falling into default case
2064 */
2065 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002066 default:
2067 /* Type Not Supported. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002068 ql_dbg(ql_dbg_async, vha, 0x5042,
2069 "Received unknown response pkt type %x "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002070 "entry status=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002071 pkt->entry_type, pkt->entry_status);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002072 break;
2073 }
2074 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2075 wmb();
2076 }
2077
2078 /* Adjust ring index */
Giridhar Malavalia9083012010-04-12 17:59:55 -07002079 if (IS_QLA82XX(ha)) {
2080 struct device_reg_82xx __iomem *reg = &ha->iobase->isp82;
2081 WRT_REG_DWORD(&reg->rsp_q_out[0], rsp->ring_index);
2082 } else
2083 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002084}
2085
Andrew Vasquez05236a02007-09-20 14:07:37 -07002086static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002087qla2xxx_check_risc_status(scsi_qla_host_t *vha)
Andrew Vasquez05236a02007-09-20 14:07:37 -07002088{
2089 int rval;
2090 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002091 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez05236a02007-09-20 14:07:37 -07002092 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2093
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002094 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha))
Andrew Vasquez05236a02007-09-20 14:07:37 -07002095 return;
2096
2097 rval = QLA_SUCCESS;
2098 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
2099 RD_REG_DWORD(&reg->iobase_addr);
2100 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
2101 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
2102 rval == QLA_SUCCESS; cnt--) {
2103 if (cnt) {
2104 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
2105 udelay(10);
2106 } else
2107 rval = QLA_FUNCTION_TIMEOUT;
2108 }
2109 if (rval == QLA_SUCCESS)
2110 goto next_test;
2111
2112 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
2113 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
2114 rval == QLA_SUCCESS; cnt--) {
2115 if (cnt) {
2116 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
2117 udelay(10);
2118 } else
2119 rval = QLA_FUNCTION_TIMEOUT;
2120 }
2121 if (rval != QLA_SUCCESS)
2122 goto done;
2123
2124next_test:
2125 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002126 ql_log(ql_log_info, vha, 0x504c,
2127 "Additional code -- 0x55AA.\n");
Andrew Vasquez05236a02007-09-20 14:07:37 -07002128
2129done:
2130 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
2131 RD_REG_DWORD(&reg->iobase_window);
2132}
2133
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002134/**
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002135 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP24xx.
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002136 * @irq:
2137 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002138 *
2139 * Called by system whenever the host adapter generates an interrupt.
2140 *
2141 * Returns handled flag.
2142 */
2143irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01002144qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002145{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002146 scsi_qla_host_t *vha;
2147 struct qla_hw_data *ha;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002148 struct device_reg_24xx __iomem *reg;
2149 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002150 unsigned long iter;
2151 uint32_t stat;
2152 uint32_t hccr;
2153 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002154 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002155 unsigned long flags;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002156
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002157 rsp = (struct rsp_que *) dev_id;
2158 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002159 ql_log(ql_log_info, NULL, 0x5059,
2160 "%s: NULL response queue pointer.\n", __func__);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002161 return IRQ_NONE;
2162 }
2163
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002164 ha = rsp->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002165 reg = &ha->iobase->isp24;
2166 status = 0;
2167
Andrew Vasquez85880802009-12-15 21:29:46 -08002168 if (unlikely(pci_channel_offline(ha->pdev)))
2169 return IRQ_HANDLED;
2170
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002171 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002172 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002173 for (iter = 50; iter--; ) {
2174 stat = RD_REG_DWORD(&reg->host_status);
2175 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08002176 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07002177 break;
2178
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002179 hccr = RD_REG_DWORD(&reg->hccr);
2180
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002181 ql_log(ql_log_warn, vha, 0x504b,
2182 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2183 hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002184
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002185 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002186
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002187 ha->isp_ops->fw_dump(vha, 1);
2188 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002189 break;
2190 } else if ((stat & HSRX_RISC_INT) == 0)
2191 break;
2192
2193 switch (stat & 0xff) {
2194 case 0x1:
2195 case 0x2:
2196 case 0x10:
2197 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002198 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002199 status |= MBX_INTERRUPT;
2200
2201 break;
2202 case 0x12:
2203 mb[0] = MSW(stat);
2204 mb[1] = RD_REG_WORD(&reg->mailbox1);
2205 mb[2] = RD_REG_WORD(&reg->mailbox2);
2206 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002207 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002208 break;
2209 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002210 case 0x14:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002211 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002212 break;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002213 case 0x1C: /* ATIO queue updated */
2214 qlt_24xx_process_atio_queue(vha);
2215 break;
2216 case 0x1D: /* ATIO and response queues updated */
2217 qlt_24xx_process_atio_queue(vha);
2218 qla24xx_process_response_queue(vha, rsp);
2219 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002220 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002221 ql_dbg(ql_dbg_async, vha, 0x504f,
2222 "Unrecognized interrupt type (%d).\n", stat * 0xff);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002223 break;
2224 }
2225 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2226 RD_REG_DWORD_RELAXED(&reg->hccr);
2227 }
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002228 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002229
2230 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
2231 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002232 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002233 complete(&ha->mbx_intr_comp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002234 }
2235
2236 return IRQ_HANDLED;
2237}
2238
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002239static irqreturn_t
2240qla24xx_msix_rsp_q(int irq, void *dev_id)
2241{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002242 struct qla_hw_data *ha;
2243 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002244 struct device_reg_24xx __iomem *reg;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002245 struct scsi_qla_host *vha;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002246 unsigned long flags;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002247
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002248 rsp = (struct rsp_que *) dev_id;
2249 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002250 ql_log(ql_log_info, NULL, 0x505a,
2251 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002252 return IRQ_NONE;
2253 }
2254 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002255 reg = &ha->iobase->isp24;
2256
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002257 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002258
Anirban Chakrabortya67093d2010-02-04 14:17:59 -08002259 vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002260 qla24xx_process_response_queue(vha, rsp);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002261 if (!ha->flags.disable_msix_handshake) {
Anirban Chakrabortyeb941142009-08-04 16:12:13 -07002262 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2263 RD_REG_DWORD_RELAXED(&reg->hccr);
2264 }
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002265 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002266
2267 return IRQ_HANDLED;
2268}
2269
2270static irqreturn_t
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002271qla25xx_msix_rsp_q(int irq, void *dev_id)
2272{
2273 struct qla_hw_data *ha;
2274 struct rsp_que *rsp;
Anirban Chakraborty31557542009-12-02 10:36:55 -08002275 struct device_reg_24xx __iomem *reg;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002276 unsigned long flags;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002277
2278 rsp = (struct rsp_que *) dev_id;
2279 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002280 ql_log(ql_log_info, NULL, 0x505b,
2281 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002282 return IRQ_NONE;
2283 }
2284 ha = rsp->hw;
2285
Anirban Chakraborty31557542009-12-02 10:36:55 -08002286 /* Clear the interrupt, if enabled, for this response queue */
Andrew Vasquezd4247542011-10-26 14:20:13 -07002287 if (!ha->flags.disable_msix_handshake) {
Anirban Chakraborty31557542009-12-02 10:36:55 -08002288 reg = &ha->iobase->isp24;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002289 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002290 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2291 RD_REG_DWORD_RELAXED(&reg->hccr);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002292 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002293 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002294 queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work);
2295
2296 return IRQ_HANDLED;
2297}
2298
2299static irqreturn_t
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002300qla24xx_msix_default(int irq, void *dev_id)
2301{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002302 scsi_qla_host_t *vha;
2303 struct qla_hw_data *ha;
2304 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002305 struct device_reg_24xx __iomem *reg;
2306 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002307 uint32_t stat;
2308 uint32_t hccr;
2309 uint16_t mb[4];
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002310 unsigned long flags;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002311
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002312 rsp = (struct rsp_que *) dev_id;
2313 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002314 ql_log(ql_log_info, NULL, 0x505c,
2315 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002316 return IRQ_NONE;
2317 }
2318 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002319 reg = &ha->iobase->isp24;
2320 status = 0;
2321
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002322 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002323 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002324 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002325 stat = RD_REG_DWORD(&reg->host_status);
2326 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08002327 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07002328 break;
2329
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002330 hccr = RD_REG_DWORD(&reg->hccr);
2331
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002332 ql_log(ql_log_info, vha, 0x5050,
2333 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2334 hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002335
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002336 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002337
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002338 ha->isp_ops->fw_dump(vha, 1);
2339 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002340 break;
2341 } else if ((stat & HSRX_RISC_INT) == 0)
2342 break;
2343
2344 switch (stat & 0xff) {
2345 case 0x1:
2346 case 0x2:
2347 case 0x10:
2348 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002349 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002350 status |= MBX_INTERRUPT;
2351
2352 break;
2353 case 0x12:
2354 mb[0] = MSW(stat);
2355 mb[1] = RD_REG_WORD(&reg->mailbox1);
2356 mb[2] = RD_REG_WORD(&reg->mailbox2);
2357 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002358 qla2x00_async_event(vha, rsp, mb);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002359 break;
2360 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002361 case 0x14:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002362 qla24xx_process_response_queue(vha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002363 break;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002364 case 0x1C: /* ATIO queue updated */
2365 qlt_24xx_process_atio_queue(vha);
2366 break;
2367 case 0x1D: /* ATIO and response queues updated */
2368 qlt_24xx_process_atio_queue(vha);
2369 qla24xx_process_response_queue(vha, rsp);
2370 break;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002371 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002372 ql_dbg(ql_dbg_async, vha, 0x5051,
2373 "Unrecognized interrupt type (%d).\n", stat & 0xff);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002374 break;
2375 }
2376 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002377 } while (0);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002378 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002379
2380 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
2381 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002382 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002383 complete(&ha->mbx_intr_comp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002384 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002385 return IRQ_HANDLED;
2386}
2387
2388/* Interrupt handling helpers. */
2389
2390struct qla_init_msix_entry {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002391 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07002392 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002393};
2394
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002395static struct qla_init_msix_entry msix_entries[3] = {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002396 { "qla2xxx (default)", qla24xx_msix_default },
2397 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002398 { "qla2xxx (multiq)", qla25xx_msix_rsp_q },
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002399};
2400
Giridhar Malavalia9083012010-04-12 17:59:55 -07002401static struct qla_init_msix_entry qla82xx_msix_entries[2] = {
2402 { "qla2xxx (default)", qla82xx_msix_default },
2403 { "qla2xxx (rsp_q)", qla82xx_msix_rsp_q },
2404};
2405
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002406static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002407qla24xx_disable_msix(struct qla_hw_data *ha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002408{
2409 int i;
2410 struct qla_msix_entry *qentry;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002411 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002412
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002413 for (i = 0; i < ha->msix_count; i++) {
2414 qentry = &ha->msix_entries[i];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002415 if (qentry->have_irq)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002416 free_irq(qentry->vector, qentry->rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002417 }
2418 pci_disable_msix(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002419 kfree(ha->msix_entries);
2420 ha->msix_entries = NULL;
2421 ha->flags.msix_enabled = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002422 ql_dbg(ql_dbg_init, vha, 0x0042,
2423 "Disabled the MSI.\n");
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002424}
2425
2426static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002427qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002428{
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002429#define MIN_MSIX_COUNT 2
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002430 int i, ret;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002431 struct msix_entry *entries;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002432 struct qla_msix_entry *qentry;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002433 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002434
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002435 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002436 GFP_KERNEL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002437 if (!entries) {
2438 ql_log(ql_log_warn, vha, 0x00bc,
2439 "Failed to allocate memory for msix_entry.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002440 return -ENOMEM;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002441 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002442
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002443 for (i = 0; i < ha->msix_count; i++)
2444 entries[i].entry = i;
2445
2446 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002447 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002448 if (ret < MIN_MSIX_COUNT)
2449 goto msix_failed;
2450
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002451 ql_log(ql_log_warn, vha, 0x00c6,
2452 "MSI-X: Failed to enable support "
2453 "-- %d/%d\n Retry with %d vectors.\n",
2454 ha->msix_count, ret, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002455 ha->msix_count = ret;
2456 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
2457 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002458msix_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002459 ql_log(ql_log_fatal, vha, 0x00c7,
2460 "MSI-X: Failed to enable support, "
2461 "giving up -- %d/%d.\n",
2462 ha->msix_count, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002463 goto msix_out;
2464 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002465 ha->max_rsp_queues = ha->msix_count - 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002466 }
2467 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
2468 ha->msix_count, GFP_KERNEL);
2469 if (!ha->msix_entries) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002470 ql_log(ql_log_fatal, vha, 0x00c8,
2471 "Failed to allocate memory for ha->msix_entries.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002472 ret = -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002473 goto msix_out;
2474 }
2475 ha->flags.msix_enabled = 1;
2476
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002477 for (i = 0; i < ha->msix_count; i++) {
2478 qentry = &ha->msix_entries[i];
2479 qentry->vector = entries[i].vector;
2480 qentry->entry = entries[i].entry;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002481 qentry->have_irq = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002482 qentry->rsp = NULL;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002483 }
2484
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002485 /* Enable MSI-X vectors for the base queue */
2486 for (i = 0; i < 2; i++) {
2487 qentry = &ha->msix_entries[i];
Giridhar Malavalia9083012010-04-12 17:59:55 -07002488 if (IS_QLA82XX(ha)) {
2489 ret = request_irq(qentry->vector,
2490 qla82xx_msix_entries[i].handler,
2491 0, qla82xx_msix_entries[i].name, rsp);
2492 } else {
2493 ret = request_irq(qentry->vector,
2494 msix_entries[i].handler,
2495 0, msix_entries[i].name, rsp);
2496 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002497 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002498 ql_log(ql_log_fatal, vha, 0x00cb,
2499 "MSI-X: unable to register handler -- %x/%d.\n",
2500 qentry->vector, ret);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002501 qla24xx_disable_msix(ha);
2502 ha->mqenable = 0;
2503 goto msix_out;
2504 }
2505 qentry->have_irq = 1;
2506 qentry->rsp = rsp;
2507 rsp->msix = qentry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002508 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002509
2510 /* Enable MSI-X vector for response queue update for queue 0 */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002511 if (IS_QLA83XX(ha)) {
2512 if (ha->msixbase && ha->mqiobase &&
2513 (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
2514 ha->mqenable = 1;
2515 } else
2516 if (ha->mqiobase
2517 && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
2518 ha->mqenable = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002519 ql_dbg(ql_dbg_multiq, vha, 0xc005,
2520 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
2521 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
2522 ql_dbg(ql_dbg_init, vha, 0x0055,
2523 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
2524 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002525
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002526msix_out:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002527 kfree(entries);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002528 return ret;
2529}
2530
2531int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002532qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002533{
2534 int ret;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002535 device_reg_t __iomem *reg = ha->iobase;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002536 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002537
2538 /* If possible, enable MSI-X. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002539 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
2540 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha))
Ben Hutchings6377a7a2010-03-19 16:59:19 -07002541 goto skip_msi;
2542
2543 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
2544 (ha->pdev->subsystem_device == 0x7040 ||
2545 ha->pdev->subsystem_device == 0x7041 ||
2546 ha->pdev->subsystem_device == 0x1705)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002547 ql_log(ql_log_warn, vha, 0x0034,
2548 "MSI-X: Unsupported ISP 2432 SSVID/SSDID (0x%X,0x%X).\n",
Ben Hutchings6377a7a2010-03-19 16:59:19 -07002549 ha->pdev->subsystem_vendor,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002550 ha->pdev->subsystem_device);
Ben Hutchings6377a7a2010-03-19 16:59:19 -07002551 goto skip_msi;
2552 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002553
Chad Dupuis42cd4f52011-08-16 11:29:24 -07002554 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002555 ql_log(ql_log_warn, vha, 0x0035,
2556 "MSI-X; Unsupported ISP2432 (0x%X, 0x%X).\n",
Chad Dupuis42cd4f52011-08-16 11:29:24 -07002557 ha->pdev->revision, QLA_MSIX_CHIP_REV_24XX);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002558 goto skip_msix;
2559 }
2560
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002561 ret = qla24xx_enable_msix(ha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002562 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002563 ql_dbg(ql_dbg_init, vha, 0x0036,
2564 "MSI-X: Enabled (0x%X, 0x%X).\n",
2565 ha->chip_revision, ha->fw_attributes);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002566 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002567 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002568 ql_log(ql_log_info, vha, 0x0037,
2569 "MSI-X Falling back-to MSI mode -%d.\n", ret);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002570skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002571
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002572 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
2573 !IS_QLA8001(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002574 goto skip_msi;
2575
2576 ret = pci_enable_msi(ha->pdev);
2577 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002578 ql_dbg(ql_dbg_init, vha, 0x0038,
2579 "MSI: Enabled.\n");
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002580 ha->flags.msi_enabled = 1;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002581 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002582 ql_log(ql_log_warn, vha, 0x0039,
2583 "MSI-X; Falling back-to INTa mode -- %d.\n", ret);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002584skip_msi:
2585
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002586 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Mike Hernandez7992abf2010-11-23 16:52:47 -08002587 ha->flags.msi_enabled ? 0 : IRQF_SHARED,
2588 QLA2XXX_DRIVER_NAME, rsp);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002589 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002590 ql_log(ql_log_warn, vha, 0x003a,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002591 "Failed to reserve interrupt %d already in use.\n",
2592 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002593 goto fail;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002594 }
Mike Hernandez7992abf2010-11-23 16:52:47 -08002595
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002596clear_risc_ints:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002597
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002598 /*
2599 * FIXME: Noted that 8014s were being dropped during NK testing.
2600 * Timing deltas during MSI-X/INTa transitions?
2601 */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002602 if (IS_QLA81XX(ha) || IS_QLA82XX(ha) || IS_QLA83XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002603 goto fail;
Andrew Vasquezc6952482008-04-03 13:13:17 -07002604 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002605 if (IS_FWI2_CAPABLE(ha)) {
2606 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
2607 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
2608 } else {
2609 WRT_REG_WORD(&reg->isp.semaphore, 0);
2610 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
2611 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
2612 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07002613 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002614
2615fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002616 return ret;
2617}
2618
2619void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002620qla2x00_free_irqs(scsi_qla_host_t *vha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002621{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002622 struct qla_hw_data *ha = vha->hw;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002623 struct rsp_que *rsp;
2624
2625 /*
2626 * We need to check that ha->rsp_q_map is valid in case we are called
2627 * from a probe failure context.
2628 */
2629 if (!ha->rsp_q_map || !ha->rsp_q_map[0])
2630 return;
2631 rsp = ha->rsp_q_map[0];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002632
2633 if (ha->flags.msix_enabled)
2634 qla24xx_disable_msix(ha);
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002635 else if (ha->flags.msi_enabled) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002636 free_irq(ha->pdev->irq, rsp);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002637 pci_disable_msi(ha->pdev);
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002638 } else
2639 free_irq(ha->pdev->irq, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002640}
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002641
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002642
2643int qla25xx_request_irq(struct rsp_que *rsp)
2644{
2645 struct qla_hw_data *ha = rsp->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002646 struct qla_init_msix_entry *intr = &msix_entries[2];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002647 struct qla_msix_entry *msix = rsp->msix;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002648 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002649 int ret;
2650
2651 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
2652 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002653 ql_log(ql_log_fatal, vha, 0x00e6,
2654 "MSI-X: Unable to register handler -- %x/%d.\n",
2655 msix->vector, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002656 return ret;
2657 }
2658 msix->have_irq = 1;
2659 msix->rsp = rsp;
2660 return ret;
2661}