blob: bbc24d3afc5baa208491de0c363a126535361f42 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Saurav Kashyap1e633952013-02-08 01:57:54 -05003 * Copyright (c) 2003-2013 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_status_entry(scsi_qla_host_t *, struct rsp_que *, void *);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070018static void qla2x00_status_cont_entry(struct rsp_que *, sts_cont_entry_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080019static void qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
20 sts_entry_t *);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022/**
23 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
24 * @irq:
25 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 *
27 * Called by system whenever the host adapter generates an interrupt.
28 *
29 * Returns handled flag.
30 */
31irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +010032qla2100_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080034 scsi_qla_host_t *vha;
35 struct qla_hw_data *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -070036 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 unsigned long iter;
Seokmann Ju14e660e2007-09-20 14:07:36 -070039 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070040 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080041 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070042 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080044 rsp = (struct rsp_que *) dev_id;
45 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -080046 ql_log(ql_log_info, NULL, 0x505d,
47 "%s: NULL response queue pointer.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 return (IRQ_NONE);
49 }
50
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080051 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -070052 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 status = 0;
54
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070055 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070056 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 for (iter = 50; iter--; ) {
Seokmann Ju14e660e2007-09-20 14:07:36 -070058 hccr = RD_REG_WORD(&reg->hccr);
59 if (hccr & HCCR_RISC_PAUSE) {
60 if (pci_channel_offline(ha->pdev))
61 break;
62
63 /*
64 * Issue a "HARD" reset in order for the RISC interrupt
Justin P. Mattocka06a0f82011-06-23 23:22:27 -070065 * bit to be cleared. Schedule a big hammer to get
Seokmann Ju14e660e2007-09-20 14:07:36 -070066 * out of the RISC PAUSED state.
67 */
68 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
69 RD_REG_WORD(&reg->hccr);
70
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080071 ha->isp_ops->fw_dump(vha, 1);
72 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -070073 break;
74 } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 break;
76
77 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
78 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
79 RD_REG_WORD(&reg->hccr);
80
81 /* Get mailbox data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -070082 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
83 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080084 qla2x00_mbx_completion(vha, mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 status |= MBX_INTERRUPT;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070086 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
87 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
88 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
89 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080090 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 } else {
92 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -070093 ql_dbg(ql_dbg_async, vha, 0x5025,
94 "Unrecognized interrupt type (%d).\n",
95 mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 }
97 /* Release mailbox registers. */
98 WRT_REG_WORD(&reg->semaphore, 0);
99 RD_REG_WORD(&reg->semaphore);
100 } else {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800101 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
104 RD_REG_WORD(&reg->hccr);
105 }
106 }
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -0700107 qla2x00_handle_mbx_completion(ha, status);
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700108 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 return (IRQ_HANDLED);
111}
112
113/**
114 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
115 * @irq:
116 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 *
118 * Called by system whenever the host adapter generates an interrupt.
119 *
120 * Returns handled flag.
121 */
122irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100123qla2300_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800125 scsi_qla_host_t *vha;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700126 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 unsigned long iter;
129 uint32_t stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700131 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800132 struct rsp_que *rsp;
133 struct qla_hw_data *ha;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700134 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800136 rsp = (struct rsp_que *) dev_id;
137 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -0800138 ql_log(ql_log_info, NULL, 0x5058,
139 "%s: NULL response queue pointer.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 return (IRQ_NONE);
141 }
142
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800143 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700144 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 status = 0;
146
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700147 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700148 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 for (iter = 50; iter--; ) {
150 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
151 if (stat & HSR_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800152 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -0700153 break;
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 hccr = RD_REG_WORD(&reg->hccr);
156 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700157 ql_log(ql_log_warn, vha, 0x5026,
158 "Parity error -- HCCR=%x, Dumping "
159 "firmware.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700161 ql_log(ql_log_warn, vha, 0x5027,
162 "RISC paused -- HCCR=%x, Dumping "
163 "firmware.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165 /*
166 * Issue a "HARD" reset in order for the RISC
167 * interrupt bit to be cleared. Schedule a big
Justin P. Mattocka06a0f82011-06-23 23:22:27 -0700168 * hammer to get out of the RISC PAUSED state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 */
170 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
171 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800172
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800173 ha->isp_ops->fw_dump(vha, 1);
174 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 break;
176 } else if ((stat & HSR_RISC_INT) == 0)
177 break;
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 case 0x1:
181 case 0x2:
182 case 0x10:
183 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800184 qla2x00_mbx_completion(vha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 status |= MBX_INTERRUPT;
186
187 /* Release mailbox registers. */
188 WRT_REG_WORD(&reg->semaphore, 0);
189 break;
190 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700191 mb[0] = MSW(stat);
192 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
193 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
194 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800195 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700196 break;
197 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800198 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 break;
200 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700201 mb[0] = MBA_CMPLT_1_16BIT;
202 mb[1] = MSW(stat);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800203 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 break;
205 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700206 mb[0] = MBA_SCSI_COMPLETION;
207 mb[1] = MSW(stat);
208 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800209 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 break;
211 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700212 ql_dbg(ql_dbg_async, vha, 0x5028,
213 "Unrecognized interrupt type (%d).\n", stat & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 break;
215 }
216 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
217 RD_REG_WORD_RELAXED(&reg->hccr);
218 }
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -0700219 qla2x00_handle_mbx_completion(ha, status);
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700220 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 return (IRQ_HANDLED);
223}
224
225/**
226 * qla2x00_mbx_completion() - Process mailbox command completions.
227 * @ha: SCSI driver HA context
228 * @mb0: Mailbox0 register
229 */
230static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800231qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
233 uint16_t cnt;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800234 uint32_t mboxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800236 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700237 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800239 /* Read all mbox registers? */
240 mboxes = (1 << ha->mbx_count) - 1;
241 if (!ha->mcp)
Masanari Iidaa7201012012-11-21 02:40:42 -0500242 ql_dbg(ql_dbg_async, vha, 0x5001, "MBX pointer ERROR.\n");
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800243 else
244 mboxes = ha->mcp->in_mb;
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 /* Load return mailbox registers. */
247 ha->flags.mbox_int = 1;
248 ha->mailbox_out[0] = mb0;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800249 mboxes >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
251
252 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700253 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800255 if ((cnt == 4 || cnt == 5) && (mboxes & BIT_0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800257 else if (mboxes & BIT_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 wptr++;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800261 mboxes >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263}
264
Andrew Vasquez8a659572009-02-08 20:50:12 -0800265static void
266qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
267{
268 static char *event[] =
269 { "Complete", "Request Notification", "Time Extension" };
270 int rval;
271 struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
272 uint16_t __iomem *wptr;
273 uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
274
275 /* Seed data -- mailbox1 -> mailbox7. */
276 wptr = (uint16_t __iomem *)&reg24->mailbox1;
277 for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
278 mb[cnt] = RD_REG_WORD(wptr);
279
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700280 ql_dbg(ql_dbg_async, vha, 0x5021,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800281 "Inter-Driver Communication %s -- "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700282 "%04x %04x %04x %04x %04x %04x %04x.\n",
283 event[aen & 0xff], mb[0], mb[1], mb[2], mb[3],
284 mb[4], mb[5], mb[6]);
Chad Dupuisbf5b8ad2012-08-22 14:21:24 -0400285 if ((aen == MBA_IDC_COMPLETE && mb[1] >> 15)) {
286 vha->hw->flags.idc_compl_status = 1;
287 if (vha->hw->notify_dcbx_comp)
288 complete(&vha->hw->dcbx_comp);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400289 }
Andrew Vasquez8a659572009-02-08 20:50:12 -0800290
Chad Dupuisbf5b8ad2012-08-22 14:21:24 -0400291 /* Acknowledgement needed? [Notify && non-zero timeout]. */
292 timeout = (descr >> 8) & 0xf;
293 if (aen != MBA_IDC_NOTIFY || !timeout)
294 return;
295
296 ql_dbg(ql_dbg_async, vha, 0x5022,
297 "%lu Inter-Driver Communication %s -- ACK timeout=%d.\n",
298 vha->host_no, event[aen & 0xff], timeout);
299
Andrew Vasquez8a659572009-02-08 20:50:12 -0800300 rval = qla2x00_post_idc_ack_work(vha, mb);
301 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700302 ql_log(ql_log_warn, vha, 0x5023,
Andrew Vasquez8a659572009-02-08 20:50:12 -0800303 "IDC failed to post ACK.\n");
304}
305
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400306#define LS_UNKNOWN 2
Joe Carnucciod0297c92012-11-21 02:40:40 -0500307const char *
308qla2x00_get_link_speed_str(struct qla_hw_data *ha, uint16_t speed)
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400309{
Joe Carnucciod0297c92012-11-21 02:40:40 -0500310 static const char * const link_speeds[] = {
311 "1", "2", "?", "4", "8", "16", "10"
312 };
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400313
314 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Joe Carnucciod0297c92012-11-21 02:40:40 -0500315 return link_speeds[0];
316 else if (speed == 0x13)
317 return link_speeds[6];
318 else if (speed < 6)
319 return link_speeds[speed];
320 else
321 return link_speeds[LS_UNKNOWN];
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400322}
323
Saurav Kashyapfa492632012-11-21 02:40:29 -0500324static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400325qla83xx_handle_8200_aen(scsi_qla_host_t *vha, uint16_t *mb)
326{
327 struct qla_hw_data *ha = vha->hw;
328
329 /*
330 * 8200 AEN Interpretation:
331 * mb[0] = AEN code
332 * mb[1] = AEN Reason code
333 * mb[2] = LSW of Peg-Halt Status-1 Register
334 * mb[6] = MSW of Peg-Halt Status-1 Register
335 * mb[3] = LSW of Peg-Halt Status-2 register
336 * mb[7] = MSW of Peg-Halt Status-2 register
337 * mb[4] = IDC Device-State Register value
338 * mb[5] = IDC Driver-Presence Register value
339 */
340 ql_dbg(ql_dbg_async, vha, 0x506b, "AEN Code: mb[0] = 0x%x AEN reason: "
341 "mb[1] = 0x%x PH-status1: mb[2] = 0x%x PH-status1: mb[6] = 0x%x.\n",
342 mb[0], mb[1], mb[2], mb[6]);
343 ql_dbg(ql_dbg_async, vha, 0x506c, "PH-status2: mb[3] = 0x%x "
344 "PH-status2: mb[7] = 0x%x Device-State: mb[4] = 0x%x "
345 "Drv-Presence: mb[5] = 0x%x.\n", mb[3], mb[7], mb[4], mb[5]);
346
347 if (mb[1] & (IDC_PEG_HALT_STATUS_CHANGE | IDC_NIC_FW_REPORTED_FAILURE |
348 IDC_HEARTBEAT_FAILURE)) {
349 ha->flags.nic_core_hung = 1;
350 ql_log(ql_log_warn, vha, 0x5060,
351 "83XX: F/W Error Reported: Check if reset required.\n");
352
353 if (mb[1] & IDC_PEG_HALT_STATUS_CHANGE) {
354 uint32_t protocol_engine_id, fw_err_code, err_level;
355
356 /*
357 * IDC_PEG_HALT_STATUS_CHANGE interpretation:
358 * - PEG-Halt Status-1 Register:
359 * (LSW = mb[2], MSW = mb[6])
360 * Bits 0-7 = protocol-engine ID
361 * Bits 8-28 = f/w error code
362 * Bits 29-31 = Error-level
363 * Error-level 0x1 = Non-Fatal error
364 * Error-level 0x2 = Recoverable Fatal error
365 * Error-level 0x4 = UnRecoverable Fatal error
366 * - PEG-Halt Status-2 Register:
367 * (LSW = mb[3], MSW = mb[7])
368 */
369 protocol_engine_id = (mb[2] & 0xff);
370 fw_err_code = (((mb[2] & 0xff00) >> 8) |
371 ((mb[6] & 0x1fff) << 8));
372 err_level = ((mb[6] & 0xe000) >> 13);
373 ql_log(ql_log_warn, vha, 0x5061, "PegHalt Status-1 "
374 "Register: protocol_engine_id=0x%x "
375 "fw_err_code=0x%x err_level=0x%x.\n",
376 protocol_engine_id, fw_err_code, err_level);
377 ql_log(ql_log_warn, vha, 0x5062, "PegHalt Status-2 "
378 "Register: 0x%x%x.\n", mb[7], mb[3]);
379 if (err_level == ERR_LEVEL_NON_FATAL) {
380 ql_log(ql_log_warn, vha, 0x5063,
381 "Not a fatal error, f/w has recovered "
382 "iteself.\n");
383 } else if (err_level == ERR_LEVEL_RECOVERABLE_FATAL) {
384 ql_log(ql_log_fatal, vha, 0x5064,
385 "Recoverable Fatal error: Chip reset "
386 "required.\n");
387 qla83xx_schedule_work(vha,
388 QLA83XX_NIC_CORE_RESET);
389 } else if (err_level == ERR_LEVEL_UNRECOVERABLE_FATAL) {
390 ql_log(ql_log_fatal, vha, 0x5065,
391 "Unrecoverable Fatal error: Set FAILED "
392 "state, reboot required.\n");
393 qla83xx_schedule_work(vha,
394 QLA83XX_NIC_CORE_UNRECOVERABLE);
395 }
396 }
397
398 if (mb[1] & IDC_NIC_FW_REPORTED_FAILURE) {
399 uint16_t peg_fw_state, nw_interface_link_up;
400 uint16_t nw_interface_signal_detect, sfp_status;
401 uint16_t htbt_counter, htbt_monitor_enable;
402 uint16_t sfp_additonal_info, sfp_multirate;
403 uint16_t sfp_tx_fault, link_speed, dcbx_status;
404
405 /*
406 * IDC_NIC_FW_REPORTED_FAILURE interpretation:
407 * - PEG-to-FC Status Register:
408 * (LSW = mb[2], MSW = mb[6])
409 * Bits 0-7 = Peg-Firmware state
410 * Bit 8 = N/W Interface Link-up
411 * Bit 9 = N/W Interface signal detected
412 * Bits 10-11 = SFP Status
413 * SFP Status 0x0 = SFP+ transceiver not expected
414 * SFP Status 0x1 = SFP+ transceiver not present
415 * SFP Status 0x2 = SFP+ transceiver invalid
416 * SFP Status 0x3 = SFP+ transceiver present and
417 * valid
418 * Bits 12-14 = Heartbeat Counter
419 * Bit 15 = Heartbeat Monitor Enable
420 * Bits 16-17 = SFP Additional Info
421 * SFP info 0x0 = Unregocnized transceiver for
422 * Ethernet
423 * SFP info 0x1 = SFP+ brand validation failed
424 * SFP info 0x2 = SFP+ speed validation failed
425 * SFP info 0x3 = SFP+ access error
426 * Bit 18 = SFP Multirate
427 * Bit 19 = SFP Tx Fault
428 * Bits 20-22 = Link Speed
429 * Bits 23-27 = Reserved
430 * Bits 28-30 = DCBX Status
431 * DCBX Status 0x0 = DCBX Disabled
432 * DCBX Status 0x1 = DCBX Enabled
433 * DCBX Status 0x2 = DCBX Exchange error
434 * Bit 31 = Reserved
435 */
436 peg_fw_state = (mb[2] & 0x00ff);
437 nw_interface_link_up = ((mb[2] & 0x0100) >> 8);
438 nw_interface_signal_detect = ((mb[2] & 0x0200) >> 9);
439 sfp_status = ((mb[2] & 0x0c00) >> 10);
440 htbt_counter = ((mb[2] & 0x7000) >> 12);
441 htbt_monitor_enable = ((mb[2] & 0x8000) >> 15);
442 sfp_additonal_info = (mb[6] & 0x0003);
443 sfp_multirate = ((mb[6] & 0x0004) >> 2);
444 sfp_tx_fault = ((mb[6] & 0x0008) >> 3);
445 link_speed = ((mb[6] & 0x0070) >> 4);
446 dcbx_status = ((mb[6] & 0x7000) >> 12);
447
448 ql_log(ql_log_warn, vha, 0x5066,
449 "Peg-to-Fc Status Register:\n"
450 "peg_fw_state=0x%x, nw_interface_link_up=0x%x, "
451 "nw_interface_signal_detect=0x%x"
452 "\nsfp_statis=0x%x.\n ", peg_fw_state,
453 nw_interface_link_up, nw_interface_signal_detect,
454 sfp_status);
455 ql_log(ql_log_warn, vha, 0x5067,
456 "htbt_counter=0x%x, htbt_monitor_enable=0x%x, "
457 "sfp_additonal_info=0x%x, sfp_multirate=0x%x.\n ",
458 htbt_counter, htbt_monitor_enable,
459 sfp_additonal_info, sfp_multirate);
460 ql_log(ql_log_warn, vha, 0x5068,
461 "sfp_tx_fault=0x%x, link_state=0x%x, "
462 "dcbx_status=0x%x.\n", sfp_tx_fault, link_speed,
463 dcbx_status);
464
465 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
466 }
467
468 if (mb[1] & IDC_HEARTBEAT_FAILURE) {
469 ql_log(ql_log_warn, vha, 0x5069,
470 "Heartbeat Failure encountered, chip reset "
471 "required.\n");
472
473 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
474 }
475 }
476
477 if (mb[1] & IDC_DEVICE_STATE_CHANGE) {
478 ql_log(ql_log_info, vha, 0x506a,
479 "IDC Device-State changed = 0x%x.\n", mb[4]);
Saurav Kashyap6c3943c2013-02-08 01:58:02 -0500480 if (ha->flags.nic_core_reset_owner)
481 return;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400482 qla83xx_schedule_work(vha, MBA_IDC_AEN);
483 }
484}
485
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -0500486int
487qla2x00_is_a_vp_did(scsi_qla_host_t *vha, uint32_t rscn_entry)
488{
489 struct qla_hw_data *ha = vha->hw;
490 scsi_qla_host_t *vp;
491 uint32_t vp_did;
492 unsigned long flags;
493 int ret = 0;
494
495 if (!ha->num_vhosts)
496 return ret;
497
498 spin_lock_irqsave(&ha->vport_slock, flags);
499 list_for_each_entry(vp, &ha->vp_list, list) {
500 vp_did = vp->d_id.b24;
501 if (vp_did == rscn_entry) {
502 ret = 1;
503 break;
504 }
505 }
506 spin_unlock_irqrestore(&ha->vport_slock, flags);
507
508 return ret;
509}
510
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511/**
512 * qla2x00_async_event() - Process aynchronous events.
513 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700514 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700516void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800517qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 uint16_t handle_cnt;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700520 uint16_t cnt, mbx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 uint32_t handles[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800522 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700523 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700524 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
Andrew Vasquezbc5c2aa2010-12-21 16:00:24 -0800525 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 uint32_t rscn_entry, host_pid;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700527 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
529 /* Setup to process RIO completion. */
530 handle_cnt = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800531 if (IS_CNA_CAPABLE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800532 goto skip_rio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 switch (mb[0]) {
534 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700535 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 handle_cnt = 1;
537 break;
538 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700539 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 handle_cnt = 1;
541 mb[0] = MBA_SCSI_COMPLETION;
542 break;
543 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700544 handles[0] = mb[1];
545 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 handle_cnt = 2;
547 mb[0] = MBA_SCSI_COMPLETION;
548 break;
549 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700550 handles[0] = mb[1];
551 handles[1] = mb[2];
552 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 handle_cnt = 3;
554 mb[0] = MBA_SCSI_COMPLETION;
555 break;
556 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700557 handles[0] = mb[1];
558 handles[1] = mb[2];
559 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
561 handle_cnt = 4;
562 mb[0] = MBA_SCSI_COMPLETION;
563 break;
564 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700565 handles[0] = mb[1];
566 handles[1] = mb[2];
567 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
569 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
570 handle_cnt = 5;
571 mb[0] = MBA_SCSI_COMPLETION;
572 break;
573 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700574 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 handles[1] = le32_to_cpu(
576 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
577 RD_MAILBOX_REG(ha, reg, 6));
578 handle_cnt = 2;
579 mb[0] = MBA_SCSI_COMPLETION;
580 break;
581 default:
582 break;
583 }
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800584skip_rio:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 switch (mb[0]) {
586 case MBA_SCSI_COMPLETION: /* Fast Post */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800587 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 break;
589
590 for (cnt = 0; cnt < handle_cnt; cnt++)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800591 qla2x00_process_completed_request(vha, rsp->req,
592 handles[cnt]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 break;
594
595 case MBA_RESET: /* Reset */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700596 ql_dbg(ql_dbg_async, vha, 0x5002,
597 "Asynchronous RESET.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800599 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 break;
601
602 case MBA_SYSTEM_ERR: /* System Error */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800603 mbx = (IS_QLA81XX(ha) || IS_QLA83XX(ha)) ?
604 RD_REG_WORD(&reg24->mailbox7) : 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700605 ql_log(ql_log_warn, vha, 0x5003,
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700606 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh "
607 "mbx7=%xh.\n", mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800609 ha->isp_ops->fw_dump(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Andrew Vasqueze4289242007-07-19 15:05:56 -0700611 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700612 if (mb[1] == 0 && mb[2] == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700613 ql_log(ql_log_fatal, vha, 0x5004,
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700614 "Unrecoverable Hardware Error: adapter "
615 "marked OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800616 vha->flags.online = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800617 vha->device_flags |= DFLG_DEV_FAILED;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700618 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300619 /* Check to see if MPI timeout occurred */
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700620 if ((mbx & MBX_3) && (ha->flags.port0))
621 set_bit(MPI_RESET_NEEDED,
622 &vha->dpc_flags);
623
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800624 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700625 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700626 } else if (mb[1] == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700627 ql_log(ql_log_fatal, vha, 0x5005,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 "Unrecoverable Hardware Error: adapter marked "
629 "OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800630 vha->flags.online = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800631 vha->device_flags |= DFLG_DEV_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800633 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 break;
635
636 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700637 ql_log(ql_log_warn, vha, 0x5006,
638 "ISP Request Transfer Error (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800640 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 break;
642
643 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700644 ql_log(ql_log_warn, vha, 0x5007,
645 "ISP Response Transfer Error.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800647 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 break;
649
650 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700651 ql_dbg(ql_dbg_async, vha, 0x5008,
652 "Asynchronous WAKEUP_THRES.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400654 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Chad Dupuiscfb09192011-11-18 09:03:07 -0800656 ql_dbg(ql_dbg_async, vha, 0x5009,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700657 "LIP occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800659 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
660 atomic_set(&vha->loop_state, LOOP_DOWN);
661 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
662 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 }
664
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800665 if (vha->vp_idx) {
666 atomic_set(&vha->vp_state, VP_FAILED);
667 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700668 }
669
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800670 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
671 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800673 vha->flags.management_server_logged_in = 0;
674 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 break;
676
677 case MBA_LOOP_UP: /* Loop Up Event */
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400678 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700679 ha->link_data_rate = PORT_SPEED_1GB;
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400680 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 ha->link_data_rate = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
Chad Dupuiscfb09192011-11-18 09:03:07 -0800683 ql_dbg(ql_dbg_async, vha, 0x500a,
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400684 "LOOP UP detected (%s Gbps).\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -0500685 qla2x00_get_link_speed_str(ha, ha->link_data_rate));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800687 vha->flags.management_server_logged_in = 0;
688 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 break;
690
691 case MBA_LOOP_DOWN: /* Loop Down Event */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800692 mbx = (IS_QLA81XX(ha) || IS_QLA8031(ha))
693 ? RD_REG_WORD(&reg24->mailbox4) : 0;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400694 mbx = (IS_P3P_TYPE(ha)) ? RD_REG_WORD(&reg82->mailbox_out[4])
695 : mbx;
Chad Dupuiscfb09192011-11-18 09:03:07 -0800696 ql_dbg(ql_dbg_async, vha, 0x500b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700697 "LOOP DOWN detected (%x %x %x %x).\n",
698 mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800700 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
701 atomic_set(&vha->loop_state, LOOP_DOWN);
702 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
703 vha->device_flags |= DFLG_NO_CABLE;
704 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 }
706
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800707 if (vha->vp_idx) {
708 atomic_set(&vha->vp_state, VP_FAILED);
709 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700710 }
711
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800712 vha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700713 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800714 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 break;
716
717 case MBA_LIP_RESET: /* LIP reset occurred */
Chad Dupuiscfb09192011-11-18 09:03:07 -0800718 ql_dbg(ql_dbg_async, vha, 0x500c,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700719 "LIP reset occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800721 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
722 atomic_set(&vha->loop_state, LOOP_DOWN);
723 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
724 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 }
726
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800727 if (vha->vp_idx) {
728 atomic_set(&vha->vp_state, VP_FAILED);
729 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700730 }
731
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800732 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
734 ha->operating_mode = LOOP;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800735 vha->flags.management_server_logged_in = 0;
736 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 break;
738
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800739 /* case MBA_DCBX_COMPLETE: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 case MBA_POINT_TO_POINT: /* Point-to-Point */
741 if (IS_QLA2100(ha))
742 break;
743
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400744 if (IS_CNA_CAPABLE(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700745 ql_dbg(ql_dbg_async, vha, 0x500d,
746 "DCBX Completed -- %04x %04x %04x.\n",
747 mb[1], mb[2], mb[3]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700748 if (ha->notify_dcbx_comp)
749 complete(&ha->dcbx_comp);
750
751 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700752 ql_dbg(ql_dbg_async, vha, 0x500e,
753 "Asynchronous P2P MODE received.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
755 /*
756 * Until there's a transition from loop down to loop up, treat
757 * this as loop down only.
758 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800759 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
760 atomic_set(&vha->loop_state, LOOP_DOWN);
761 if (!atomic_read(&vha->loop_down_timer))
762 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800764 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 }
766
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800767 if (vha->vp_idx) {
768 atomic_set(&vha->vp_state, VP_FAILED);
769 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700770 }
771
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800772 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
773 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
774
775 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
776 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800777
778 ha->flags.gpsc_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800779 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 break;
781
782 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
783 if (IS_QLA2100(ha))
784 break;
785
Chad Dupuiscfb09192011-11-18 09:03:07 -0800786 ql_dbg(ql_dbg_async, vha, 0x500f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 "Configuration change detected: value=%x.\n", mb[1]);
788
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800789 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
790 atomic_set(&vha->loop_state, LOOP_DOWN);
791 if (!atomic_read(&vha->loop_down_timer))
792 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800794 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 }
796
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800797 if (vha->vp_idx) {
798 atomic_set(&vha->vp_state, VP_FAILED);
799 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700800 }
801
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800802 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
803 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 break;
805
806 case MBA_PORT_UPDATE: /* Port database update */
Santosh Vernekar55903b92009-07-31 15:09:25 -0700807 /*
808 * Handle only global and vn-port update events
809 *
810 * Relevant inputs:
811 * mb[1] = N_Port handle of changed port
812 * OR 0xffff for global event
813 * mb[2] = New login state
814 * 7 = Port logged out
815 * mb[3] = LSB is vp_idx, 0xff = all vps
816 *
817 * Skip processing if:
818 * Event is global, vp_idx is NOT all vps,
819 * vp_idx does not match
820 * Event is not global, vp_idx does not match
821 */
Andrew Vasquez12cec63e42010-03-19 16:59:17 -0700822 if (IS_QLA2XXX_MIDTYPE(ha) &&
823 ((mb[1] == 0xffff && (mb[3] & 0xff) != 0xff) ||
824 (mb[1] != 0xffff)) && vha->vp_idx != (mb[3] & 0xff))
825 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800826
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700827 /* Global event -- port logout or port unavailable. */
828 if (mb[1] == 0xffff && mb[2] == 0x7) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700829 ql_dbg(ql_dbg_async, vha, 0x5010,
830 "Port unavailable %04x %04x %04x.\n",
831 mb[1], mb[2], mb[3]);
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400832 ql_log(ql_log_warn, vha, 0x505e,
833 "Link is offline.\n");
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700834
835 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
836 atomic_set(&vha->loop_state, LOOP_DOWN);
837 atomic_set(&vha->loop_down_timer,
838 LOOP_DOWN_TIME);
839 vha->device_flags |= DFLG_NO_CABLE;
840 qla2x00_mark_all_devices_lost(vha, 1);
841 }
842
843 if (vha->vp_idx) {
844 atomic_set(&vha->vp_state, VP_FAILED);
845 fc_vport_set_state(vha->fc_vport,
846 FC_VPORT_FAILED);
Santosh Vernekarfaadc5e2009-07-31 15:09:26 -0700847 qla2x00_mark_all_devices_lost(vha, 1);
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700848 }
849
850 vha->flags.management_server_logged_in = 0;
851 ha->link_data_rate = PORT_SPEED_UNKNOWN;
852 break;
853 }
854
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 /*
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700856 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 * event etc. earlier indicating loop is down) then process
858 * it. Otherwise ignore it and Wait for RSCN to come in.
859 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800860 atomic_set(&vha->loop_down_timer, 0);
Chad Dupuis79cc7852012-08-22 14:21:09 -0400861 if (mb[1] != 0xffff || (mb[2] != 0x6 && mb[2] != 0x4)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700862 ql_dbg(ql_dbg_async, vha, 0x5011,
863 "Asynchronous PORT UPDATE ignored %04x/%04x/%04x.\n",
864 mb[1], mb[2], mb[3]);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400865
866 qlt_async_event(mb[0], vha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 break;
868 }
869
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700870 ql_dbg(ql_dbg_async, vha, 0x5012,
871 "Port database changed %04x %04x %04x.\n",
872 mb[1], mb[2], mb[3]);
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400873 ql_log(ql_log_warn, vha, 0x505f,
874 "Link is operational (%s Gbps).\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -0500875 qla2x00_get_link_speed_str(ha, ha->link_data_rate));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
877 /*
878 * Mark all devices as missing so we will login again.
879 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800880 atomic_set(&vha->loop_state, LOOP_UP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800882 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400884 if (vha->vp_idx == 0 && !qla_ini_mode_enabled(vha))
885 set_bit(SCR_PENDING, &vha->dpc_flags);
886
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800887 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
888 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400889
890 qlt_async_event(mb[0], vha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 break;
892
893 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju3c397402008-05-19 14:25:39 -0700894 /* Check if the Vport has issued a SCR */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800895 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
Seokmann Ju3c397402008-05-19 14:25:39 -0700896 break;
897 /* Only handle SCNs for our Vport index. */
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700898 if (ha->flags.npiv_supported && vha->vp_idx != (mb[3] & 0xff))
Seokmann Ju3c397402008-05-19 14:25:39 -0700899 break;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700900
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700901 ql_dbg(ql_dbg_async, vha, 0x5013,
902 "RSCN database changed -- %04x %04x %04x.\n",
903 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
Ravi Anand59d72d82008-09-11 21:22:53 -0700905 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800906 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
907 | vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 if (rscn_entry == host_pid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700909 ql_dbg(ql_dbg_async, vha, 0x5014,
910 "Ignoring RSCN update to local host "
911 "port ID (%06x).\n", host_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 break;
913 }
914
Ravi Anand59d72d82008-09-11 21:22:53 -0700915 /* Ignore reserved bits from RSCN-payload. */
916 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -0500918 /* Skip RSCNs for virtual ports on the same physical port */
919 if (qla2x00_is_a_vp_did(vha, rscn_entry))
920 break;
921
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800922 atomic_set(&vha->loop_down_timer, 0);
923 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800925 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
926 set_bit(RSCN_UPDATE, &vha->dpc_flags);
927 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 break;
929
930 /* case MBA_RIO_RESPONSE: */
931 case MBA_ZIO_RESPONSE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700932 ql_dbg(ql_dbg_async, vha, 0x5015,
933 "[R|Z]IO update completion.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
Andrew Vasqueze4289242007-07-19 15:05:56 -0700935 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700936 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700937 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800938 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700940
941 case MBA_DISCARD_RND_FRAME:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700942 ql_dbg(ql_dbg_async, vha, 0x5016,
943 "Discard RND Frame -- %04x %04x %04x.\n",
944 mb[1], mb[2], mb[3]);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700945 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700946
947 case MBA_TRACE_NOTIFICATION:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700948 ql_dbg(ql_dbg_async, vha, 0x5017,
949 "Trace Notification -- %04x %04x.\n", mb[1], mb[2]);
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700950 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700951
952 case MBA_ISP84XX_ALERT:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700953 ql_dbg(ql_dbg_async, vha, 0x5018,
954 "ISP84XX Alert Notification -- %04x %04x %04x.\n",
955 mb[1], mb[2], mb[3]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700956
957 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
958 switch (mb[1]) {
959 case A84_PANIC_RECOVERY:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700960 ql_log(ql_log_info, vha, 0x5019,
961 "Alert 84XX: panic recovery %04x %04x.\n",
962 mb[2], mb[3]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700963 break;
964 case A84_OP_LOGIN_COMPLETE:
965 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700966 ql_log(ql_log_info, vha, 0x501a,
967 "Alert 84XX: firmware version %x.\n",
968 ha->cs84xx->op_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700969 break;
970 case A84_DIAG_LOGIN_COMPLETE:
971 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700972 ql_log(ql_log_info, vha, 0x501b,
973 "Alert 84XX: diagnostic firmware version %x.\n",
974 ha->cs84xx->diag_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700975 break;
976 case A84_GOLD_LOGIN_COMPLETE:
977 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
978 ha->cs84xx->fw_update = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700979 ql_log(ql_log_info, vha, 0x501c,
980 "Alert 84XX: gold firmware version %x.\n",
981 ha->cs84xx->gold_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700982 break;
983 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700984 ql_log(ql_log_warn, vha, 0x501d,
985 "Alert 84xx: Invalid Alert %04x %04x %04x.\n",
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700986 mb[1], mb[2], mb[3]);
987 }
988 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
989 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800990 case MBA_DCBX_START:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700991 ql_dbg(ql_dbg_async, vha, 0x501e,
992 "DCBX Started -- %04x %04x %04x.\n",
993 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800994 break;
995 case MBA_DCBX_PARAM_UPDATE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700996 ql_dbg(ql_dbg_async, vha, 0x501f,
997 "DCBX Parameters Updated -- %04x %04x %04x.\n",
998 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800999 break;
1000 case MBA_FCF_CONF_ERR:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001001 ql_dbg(ql_dbg_async, vha, 0x5020,
1002 "FCF Configuration Error -- %04x %04x %04x.\n",
1003 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001004 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001005 case MBA_IDC_NOTIFY:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001006 if (IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
Chad Dupuis67b2a312013-02-08 01:57:51 -05001007 mb[4] = RD_REG_WORD(&reg24->mailbox4);
1008 if (((mb[2] & 0x7fff) == MBC_PORT_RESET ||
1009 (mb[2] & 0x7fff) == MBC_SET_PORT_CONFIG) &&
1010 (mb[4] & INTERNAL_LOOPBACK_MASK) != 0) {
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04001011 set_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags);
Chad Dupuis67b2a312013-02-08 01:57:51 -05001012 /*
1013 * Extend loop down timer since port is active.
1014 */
1015 if (atomic_read(&vha->loop_state) == LOOP_DOWN)
1016 atomic_set(&vha->loop_down_timer,
1017 LOOP_DOWN_TIME);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04001018 qla2xxx_wake_dpc(vha);
1019 }
Chad Dupuis67b2a312013-02-08 01:57:51 -05001020 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04001021 case MBA_IDC_COMPLETE:
Chad Dupuisf356bef2013-02-08 01:58:04 -05001022 if (ha->notify_lb_portup_comp)
1023 complete(&ha->lb_portup_comp);
1024 /* Fallthru */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001025 case MBA_IDC_TIME_EXT:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001026 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) ||
1027 IS_QLA8044(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001028 qla81xx_idc_event(vha, mb[0], mb[1]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001029 break;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001030
1031 case MBA_IDC_AEN:
1032 mb[4] = RD_REG_WORD(&reg24->mailbox4);
1033 mb[5] = RD_REG_WORD(&reg24->mailbox5);
1034 mb[6] = RD_REG_WORD(&reg24->mailbox6);
1035 mb[7] = RD_REG_WORD(&reg24->mailbox7);
1036 qla83xx_handle_8200_aen(vha, mb);
1037 break;
1038
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001039 default:
1040 ql_dbg(ql_dbg_async, vha, 0x5057,
1041 "Unknown AEN:%04x %04x %04x %04x\n",
1042 mb[0], mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001044
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001045 qlt_async_event(mb[0], vha, mb);
1046
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001047 if (!vha->vp_idx && ha->num_vhosts)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001048 qla2x00_alert_all_vps(rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049}
1050
1051/**
1052 * qla2x00_process_completed_request() - Process a Fast Post response.
1053 * @ha: SCSI driver HA context
1054 * @index: SRB index
1055 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001056void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001057qla2x00_process_completed_request(struct scsi_qla_host *vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001058 struct req_que *req, uint32_t index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059{
1060 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001061 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
1063 /* Validate handle. */
Chad Dupuis8d93f552013-01-30 03:34:37 -05001064 if (index >= req->num_outstanding_cmds) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001065 ql_log(ql_log_warn, vha, 0x3014,
1066 "Invalid SCSI command index (%x).\n", index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001068 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001069 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1070 else
1071 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 return;
1073 }
1074
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001075 sp = req->outstanding_cmds[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 if (sp) {
1077 /* Free outstanding command slot. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001078 req->outstanding_cmds[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 /* Save ISP completion status */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001081 sp->done(ha, sp, DID_OK << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001083 ql_log(ql_log_warn, vha, 0x3016, "Invalid SCSI SRB.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001085 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001086 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1087 else
1088 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 }
1090}
1091
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001092srb_t *
Andrew Vasquezac280b62009-08-20 11:06:05 -07001093qla2x00_get_sp_from_handle(scsi_qla_host_t *vha, const char *func,
1094 struct req_que *req, void *iocb)
1095{
1096 struct qla_hw_data *ha = vha->hw;
1097 sts_entry_t *pkt = iocb;
1098 srb_t *sp = NULL;
1099 uint16_t index;
1100
1101 index = LSW(pkt->handle);
Chad Dupuis8d93f552013-01-30 03:34:37 -05001102 if (index >= req->num_outstanding_cmds) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001103 ql_log(ql_log_warn, vha, 0x5031,
1104 "Invalid command index (%x).\n", index);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001105 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001106 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1107 else
1108 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001109 goto done;
1110 }
1111 sp = req->outstanding_cmds[index];
1112 if (!sp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001113 ql_log(ql_log_warn, vha, 0x5032,
1114 "Invalid completion handle (%x) -- timed-out.\n", index);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001115 return sp;
1116 }
1117 if (sp->handle != index) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001118 ql_log(ql_log_warn, vha, 0x5033,
1119 "SRB handle (%x) mismatch %x.\n", sp->handle, index);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001120 return NULL;
1121 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001122
Andrew Vasquezac280b62009-08-20 11:06:05 -07001123 req->outstanding_cmds[index] = NULL;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001124
Andrew Vasquezac280b62009-08-20 11:06:05 -07001125done:
1126 return sp;
1127}
1128
1129static void
1130qla2x00_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1131 struct mbx_entry *mbx)
1132{
1133 const char func[] = "MBX-IOCB";
1134 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001135 fc_port_t *fcport;
1136 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001137 struct srb_iocb *lio;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001138 uint16_t *data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001139 uint16_t status;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001140
1141 sp = qla2x00_get_sp_from_handle(vha, func, req, mbx);
1142 if (!sp)
1143 return;
1144
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001145 lio = &sp->u.iocb_cmd;
1146 type = sp->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001147 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001148 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001149
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001150 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001151 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001152 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001153 if (mbx->entry_status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001154 ql_dbg(ql_dbg_async, vha, 0x5043,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001155 "Async-%s error entry - hdl=%x portid=%02x%02x%02x "
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001156 "entry-status=%x status=%x state-flag=%x "
Chad Dupuiscfb09192011-11-18 09:03:07 -08001157 "status-flags=%x.\n", type, sp->handle,
1158 fcport->d_id.b.domain, fcport->d_id.b.area,
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001159 fcport->d_id.b.al_pa, mbx->entry_status,
1160 le16_to_cpu(mbx->status), le16_to_cpu(mbx->state_flags),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001161 le16_to_cpu(mbx->status_flags));
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001162
Chad Dupuiscfb09192011-11-18 09:03:07 -08001163 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5029,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001164 (uint8_t *)mbx, sizeof(*mbx));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001165
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001166 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001167 }
1168
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001169 status = le16_to_cpu(mbx->status);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001170 if (status == 0x30 && sp->type == SRB_LOGIN_CMD &&
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001171 le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE)
1172 status = 0;
1173 if (!status && le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001174 ql_dbg(ql_dbg_async, vha, 0x5045,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001175 "Async-%s complete - hdl=%x portid=%02x%02x%02x mbx1=%x.\n",
1176 type, sp->handle, fcport->d_id.b.domain,
1177 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1178 le16_to_cpu(mbx->mb1));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001179
1180 data[0] = MBS_COMMAND_COMPLETE;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001181 if (sp->type == SRB_LOGIN_CMD) {
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001182 fcport->port_type = FCT_TARGET;
1183 if (le16_to_cpu(mbx->mb1) & BIT_0)
1184 fcport->port_type = FCT_INITIATOR;
Andrew Vasquez6ac52602010-05-28 15:08:19 -07001185 else if (le16_to_cpu(mbx->mb1) & BIT_1)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001186 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001187 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001188 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001189 }
1190
1191 data[0] = le16_to_cpu(mbx->mb0);
1192 switch (data[0]) {
1193 case MBS_PORT_ID_USED:
1194 data[1] = le16_to_cpu(mbx->mb1);
1195 break;
1196 case MBS_LOOP_ID_USED:
1197 break;
1198 default:
1199 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001200 break;
1201 }
1202
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001203 ql_log(ql_log_warn, vha, 0x5046,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001204 "Async-%s failed - hdl=%x portid=%02x%02x%02x status=%x "
1205 "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n", type, sp->handle,
1206 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
1207 status, le16_to_cpu(mbx->mb0), le16_to_cpu(mbx->mb1),
Andrew Vasquezac280b62009-08-20 11:06:05 -07001208 le16_to_cpu(mbx->mb2), le16_to_cpu(mbx->mb6),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001209 le16_to_cpu(mbx->mb7));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001210
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001211logio_done:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001212 sp->done(vha, sp, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001213}
1214
1215static void
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001216qla2x00_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1217 sts_entry_t *pkt, int iocb_type)
1218{
1219 const char func[] = "CT_IOCB";
1220 const char *type;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001221 srb_t *sp;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001222 struct fc_bsg_job *bsg_job;
1223 uint16_t comp_status;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001224 int res;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001225
1226 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1227 if (!sp)
1228 return;
1229
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001230 bsg_job = sp->u.bsg_job;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001231
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001232 type = "ct pass-through";
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001233
1234 comp_status = le16_to_cpu(pkt->comp_status);
1235
1236 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1237 * fc payload to the caller
1238 */
1239 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1240 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1241
1242 if (comp_status != CS_COMPLETE) {
1243 if (comp_status == CS_DATA_UNDERRUN) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001244 res = DID_OK << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001245 bsg_job->reply->reply_payload_rcv_len =
1246 le16_to_cpu(((sts_entry_t *)pkt)->rsp_info_len);
1247
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001248 ql_log(ql_log_warn, vha, 0x5048,
1249 "CT pass-through-%s error "
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001250 "comp_status-status=0x%x total_byte = 0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001251 type, comp_status,
1252 bsg_job->reply->reply_payload_rcv_len);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001253 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001254 ql_log(ql_log_warn, vha, 0x5049,
1255 "CT pass-through-%s error "
1256 "comp_status-status=0x%x.\n", type, comp_status);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001257 res = DID_ERROR << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001258 bsg_job->reply->reply_payload_rcv_len = 0;
1259 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001260 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5035,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001261 (uint8_t *)pkt, sizeof(*pkt));
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001262 } else {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001263 res = DID_OK << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001264 bsg_job->reply->reply_payload_rcv_len =
1265 bsg_job->reply_payload.payload_len;
1266 bsg_job->reply_len = 0;
1267 }
1268
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001269 sp->done(vha, sp, res);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001270}
1271
1272static void
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001273qla24xx_els_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1274 struct sts_entry_24xx *pkt, int iocb_type)
1275{
1276 const char func[] = "ELS_CT_IOCB";
1277 const char *type;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001278 srb_t *sp;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001279 struct fc_bsg_job *bsg_job;
1280 uint16_t comp_status;
1281 uint32_t fw_status[3];
1282 uint8_t* fw_sts_ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001283 int res;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001284
1285 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1286 if (!sp)
1287 return;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001288 bsg_job = sp->u.bsg_job;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001289
1290 type = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001291 switch (sp->type) {
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001292 case SRB_ELS_CMD_RPT:
1293 case SRB_ELS_CMD_HST:
1294 type = "els";
1295 break;
1296 case SRB_CT_CMD:
1297 type = "ct pass-through";
1298 break;
1299 default:
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001300 ql_dbg(ql_dbg_user, vha, 0x503e,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001301 "Unrecognized SRB: (%p) type=%d.\n", sp, sp->type);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001302 return;
1303 }
1304
1305 comp_status = fw_status[0] = le16_to_cpu(pkt->comp_status);
1306 fw_status[1] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1);
1307 fw_status[2] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2);
1308
1309 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1310 * fc payload to the caller
1311 */
1312 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1313 bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(fw_status);
1314
1315 if (comp_status != CS_COMPLETE) {
1316 if (comp_status == CS_DATA_UNDERRUN) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001317 res = DID_OK << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001318 bsg_job->reply->reply_payload_rcv_len =
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001319 le16_to_cpu(((struct els_sts_entry_24xx *)pkt)->total_byte_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001320
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001321 ql_dbg(ql_dbg_user, vha, 0x503f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001322 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001323 "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001324 type, sp->handle, comp_status, fw_status[1], fw_status[2],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001325 le16_to_cpu(((struct els_sts_entry_24xx *)
1326 pkt)->total_byte_count));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001327 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1328 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1329 }
1330 else {
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001331 ql_dbg(ql_dbg_user, vha, 0x5040,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001332 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001333 "error subcode 1=0x%x error subcode 2=0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001334 type, sp->handle, comp_status,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001335 le16_to_cpu(((struct els_sts_entry_24xx *)
1336 pkt)->error_subcode_1),
1337 le16_to_cpu(((struct els_sts_entry_24xx *)
1338 pkt)->error_subcode_2));
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001339 res = DID_ERROR << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001340 bsg_job->reply->reply_payload_rcv_len = 0;
1341 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1342 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1343 }
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001344 ql_dump_buffer(ql_dbg_user + ql_dbg_buffer, vha, 0x5056,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001345 (uint8_t *)pkt, sizeof(*pkt));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001346 }
1347 else {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001348 res = DID_OK << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001349 bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
1350 bsg_job->reply_len = 0;
1351 }
1352
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001353 sp->done(vha, sp, res);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001354}
1355
1356static void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001357qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req,
1358 struct logio_entry_24xx *logio)
1359{
1360 const char func[] = "LOGIO-IOCB";
1361 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001362 fc_port_t *fcport;
1363 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001364 struct srb_iocb *lio;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001365 uint16_t *data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001366 uint32_t iop[2];
1367
1368 sp = qla2x00_get_sp_from_handle(vha, func, req, logio);
1369 if (!sp)
1370 return;
1371
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001372 lio = &sp->u.iocb_cmd;
1373 type = sp->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001374 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001375 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001376
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001377 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001378 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001379 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001380 if (logio->entry_status) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001381 ql_log(ql_log_warn, fcport->vha, 0x5034,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001382 "Async-%s error entry - hdl=%x"
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001383 "portid=%02x%02x%02x entry-status=%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001384 type, sp->handle, fcport->d_id.b.domain,
1385 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1386 logio->entry_status);
1387 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x504d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001388 (uint8_t *)logio, sizeof(*logio));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001389
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001390 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001391 }
1392
1393 if (le16_to_cpu(logio->comp_status) == CS_COMPLETE) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001394 ql_dbg(ql_dbg_async, fcport->vha, 0x5036,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001395 "Async-%s complete - hdl=%x portid=%02x%02x%02x "
1396 "iop0=%x.\n", type, sp->handle, fcport->d_id.b.domain,
1397 fcport->d_id.b.area, fcport->d_id.b.al_pa,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001398 le32_to_cpu(logio->io_parameter[0]));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001399
1400 data[0] = MBS_COMMAND_COMPLETE;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001401 if (sp->type != SRB_LOGIN_CMD)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001402 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001403
1404 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1405 if (iop[0] & BIT_4) {
1406 fcport->port_type = FCT_TARGET;
1407 if (iop[0] & BIT_8)
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07001408 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquezb0cd5792010-05-28 15:08:22 -07001409 } else if (iop[0] & BIT_5)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001410 fcport->port_type = FCT_INITIATOR;
Andrew Vasquezb0cd5792010-05-28 15:08:22 -07001411
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001412 if (iop[0] & BIT_7)
1413 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
1414
Andrew Vasquezac280b62009-08-20 11:06:05 -07001415 if (logio->io_parameter[7] || logio->io_parameter[8])
1416 fcport->supported_classes |= FC_COS_CLASS2;
1417 if (logio->io_parameter[9] || logio->io_parameter[10])
1418 fcport->supported_classes |= FC_COS_CLASS3;
1419
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001420 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001421 }
1422
1423 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1424 iop[1] = le32_to_cpu(logio->io_parameter[1]);
1425 switch (iop[0]) {
1426 case LSC_SCODE_PORTID_USED:
1427 data[0] = MBS_PORT_ID_USED;
1428 data[1] = LSW(iop[1]);
1429 break;
1430 case LSC_SCODE_NPORT_USED:
1431 data[0] = MBS_LOOP_ID_USED;
1432 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001433 default:
1434 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001435 break;
1436 }
1437
Arun Easi5e19ed92012-02-09 11:15:51 -08001438 ql_dbg(ql_dbg_async, fcport->vha, 0x5037,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001439 "Async-%s failed - hdl=%x portid=%02x%02x%02x comp=%x "
1440 "iop0=%x iop1=%x.\n", type, sp->handle, fcport->d_id.b.domain,
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001441 fcport->d_id.b.area, fcport->d_id.b.al_pa,
Andrew Vasquezac280b62009-08-20 11:06:05 -07001442 le16_to_cpu(logio->comp_status),
1443 le32_to_cpu(logio->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001444 le32_to_cpu(logio->io_parameter[1]));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001445
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001446logio_done:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001447 sp->done(vha, sp, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001448}
1449
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001450static void
1451qla24xx_tm_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1452 struct tsk_mgmt_entry *tsk)
1453{
1454 const char func[] = "TMF-IOCB";
1455 const char *type;
1456 fc_port_t *fcport;
1457 srb_t *sp;
1458 struct srb_iocb *iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001459 struct sts_entry_24xx *sts = (struct sts_entry_24xx *)tsk;
1460 int error = 1;
1461
1462 sp = qla2x00_get_sp_from_handle(vha, func, req, tsk);
1463 if (!sp)
1464 return;
1465
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001466 iocb = &sp->u.iocb_cmd;
1467 type = sp->name;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001468 fcport = sp->fcport;
1469
1470 if (sts->entry_status) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001471 ql_log(ql_log_warn, fcport->vha, 0x5038,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001472 "Async-%s error - hdl=%x entry-status(%x).\n",
1473 type, sp->handle, sts->entry_status);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001474 } else if (sts->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001475 ql_log(ql_log_warn, fcport->vha, 0x5039,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001476 "Async-%s error - hdl=%x completion status(%x).\n",
1477 type, sp->handle, sts->comp_status);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001478 } else if (!(le16_to_cpu(sts->scsi_status) &
1479 SS_RESPONSE_INFO_LEN_VALID)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001480 ql_log(ql_log_warn, fcport->vha, 0x503a,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001481 "Async-%s error - hdl=%x no response info(%x).\n",
1482 type, sp->handle, sts->scsi_status);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001483 } else if (le32_to_cpu(sts->rsp_data_len) < 4) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001484 ql_log(ql_log_warn, fcport->vha, 0x503b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001485 "Async-%s error - hdl=%x not enough response(%d).\n",
1486 type, sp->handle, sts->rsp_data_len);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001487 } else if (sts->data[3]) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001488 ql_log(ql_log_warn, fcport->vha, 0x503c,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001489 "Async-%s error - hdl=%x response(%x).\n",
1490 type, sp->handle, sts->data[3]);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001491 } else {
1492 error = 0;
1493 }
1494
1495 if (error) {
1496 iocb->u.tmf.data = error;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001497 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5055,
1498 (uint8_t *)sts, sizeof(*sts));
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001499 }
1500
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001501 sp->done(vha, sp, 0);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001502}
1503
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504/**
1505 * qla2x00_process_response_queue() - Process response queue entries.
1506 * @ha: SCSI driver HA context
1507 */
1508void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001509qla2x00_process_response_queue(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001511 struct scsi_qla_host *vha;
1512 struct qla_hw_data *ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001513 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 sts_entry_t *pkt;
1515 uint16_t handle_cnt;
1516 uint16_t cnt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001517
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001518 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001520 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 return;
1522
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001523 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1524 pkt = (sts_entry_t *)rsp->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001526 rsp->ring_index++;
1527 if (rsp->ring_index == rsp->length) {
1528 rsp->ring_index = 0;
1529 rsp->ring_ptr = rsp->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001531 rsp->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 }
1533
1534 if (pkt->entry_status != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001535 qla2x00_error_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1537 wmb();
1538 continue;
1539 }
1540
1541 switch (pkt->entry_type) {
1542 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001543 qla2x00_status_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 break;
1545 case STATUS_TYPE_21:
1546 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
1547 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001548 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 ((sts21_entry_t *)pkt)->handle[cnt]);
1550 }
1551 break;
1552 case STATUS_TYPE_22:
1553 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
1554 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001555 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 ((sts22_entry_t *)pkt)->handle[cnt]);
1557 }
1558 break;
1559 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001560 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001562 case MBX_IOCB_TYPE:
1563 qla2x00_mbx_iocb_entry(vha, rsp->req,
1564 (struct mbx_entry *)pkt);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001565 break;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001566 case CT_IOCB_TYPE:
1567 qla2x00_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
1568 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 default:
1570 /* Type Not Supported. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001571 ql_log(ql_log_warn, vha, 0x504a,
1572 "Received unknown response pkt type %x "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 "entry status=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001574 pkt->entry_type, pkt->entry_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 break;
1576 }
1577 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1578 wmb();
1579 }
1580
1581 /* Adjust ring index */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001582 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583}
1584
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001585static inline void
Andrew Vasquez55442132010-07-23 15:28:27 +05001586qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t par_sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001587 uint32_t sense_len, struct rsp_que *rsp, int res)
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001588{
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001589 struct scsi_qla_host *vha = sp->fcport->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001590 struct scsi_cmnd *cp = GET_CMD_SP(sp);
1591 uint32_t track_sense_len;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001592
1593 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
1594 sense_len = SCSI_SENSE_BUFFERSIZE;
1595
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001596 SET_CMD_SENSE_LEN(sp, sense_len);
1597 SET_CMD_SENSE_PTR(sp, cp->sense_buffer);
1598 track_sense_len = sense_len;
1599
1600 if (sense_len > par_sense_len)
Andrew Vasquez55442132010-07-23 15:28:27 +05001601 sense_len = par_sense_len;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001602
1603 memcpy(cp->sense_buffer, sense_data, sense_len);
1604
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001605 SET_CMD_SENSE_PTR(sp, cp->sense_buffer + sense_len);
1606 track_sense_len -= sense_len;
1607 SET_CMD_SENSE_LEN(sp, track_sense_len);
1608
1609 if (track_sense_len != 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001610 rsp->status_srb = sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001611 cp->result = res;
1612 }
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001613
Chad Dupuiscfb09192011-11-18 09:03:07 -08001614 if (sense_len) {
1615 ql_dbg(ql_dbg_io + ql_dbg_buffer, vha, 0x301c,
1616 "Check condition Sense data, nexus%ld:%d:%d cmd=%p.\n",
1617 sp->fcport->vha->host_no, cp->device->id, cp->device->lun,
1618 cp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001619 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302b,
1620 cp->sense_buffer, sense_len);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001621 }
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001622}
1623
Arun Easibad75002010-05-04 15:01:30 -07001624struct scsi_dif_tuple {
1625 __be16 guard; /* Checksum */
Masanari Iidad6a03582012-08-22 14:20:58 -04001626 __be16 app_tag; /* APPL identifier */
Arun Easibad75002010-05-04 15:01:30 -07001627 __be32 ref_tag; /* Target LBA or indirect LBA */
1628};
1629
1630/*
1631 * Checks the guard or meta-data for the type of error
1632 * detected by the HBA. In case of errors, we set the
1633 * ASC/ASCQ fields in the sense buffer with ILLEGAL_REQUEST
1634 * to indicate to the kernel that the HBA detected error.
1635 */
Arun Easi8cb20492011-08-16 11:29:22 -07001636static inline int
Arun Easibad75002010-05-04 15:01:30 -07001637qla2x00_handle_dif_error(srb_t *sp, struct sts_entry_24xx *sts24)
1638{
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001639 struct scsi_qla_host *vha = sp->fcport->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001640 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Arun Easi8cb20492011-08-16 11:29:22 -07001641 uint8_t *ap = &sts24->data[12];
1642 uint8_t *ep = &sts24->data[20];
Arun Easibad75002010-05-04 15:01:30 -07001643 uint32_t e_ref_tag, a_ref_tag;
1644 uint16_t e_app_tag, a_app_tag;
1645 uint16_t e_guard, a_guard;
1646
Arun Easi8cb20492011-08-16 11:29:22 -07001647 /*
1648 * swab32 of the "data" field in the beginning of qla2x00_status_entry()
1649 * would make guard field appear at offset 2
1650 */
1651 a_guard = le16_to_cpu(*(uint16_t *)(ap + 2));
1652 a_app_tag = le16_to_cpu(*(uint16_t *)(ap + 0));
1653 a_ref_tag = le32_to_cpu(*(uint32_t *)(ap + 4));
1654 e_guard = le16_to_cpu(*(uint16_t *)(ep + 2));
1655 e_app_tag = le16_to_cpu(*(uint16_t *)(ep + 0));
1656 e_ref_tag = le32_to_cpu(*(uint32_t *)(ep + 4));
Arun Easibad75002010-05-04 15:01:30 -07001657
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001658 ql_dbg(ql_dbg_io, vha, 0x3023,
1659 "iocb(s) %p Returned STATUS.\n", sts24);
Arun Easibad75002010-05-04 15:01:30 -07001660
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001661 ql_dbg(ql_dbg_io, vha, 0x3024,
1662 "DIF ERROR in cmd 0x%x lba 0x%llx act ref"
Arun Easibad75002010-05-04 15:01:30 -07001663 " tag=0x%x, exp ref_tag=0x%x, act app tag=0x%x, exp app"
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001664 " tag=0x%x, act guard=0x%x, exp guard=0x%x.\n",
Arun Easibad75002010-05-04 15:01:30 -07001665 cmd->cmnd[0], (u64)scsi_get_lba(cmd), a_ref_tag, e_ref_tag,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001666 a_app_tag, e_app_tag, a_guard, e_guard);
Arun Easibad75002010-05-04 15:01:30 -07001667
Arun Easi8cb20492011-08-16 11:29:22 -07001668 /*
1669 * Ignore sector if:
1670 * For type 3: ref & app tag is all 'f's
1671 * For type 0,1,2: app tag is all 'f's
1672 */
1673 if ((a_app_tag == 0xffff) &&
1674 ((scsi_get_prot_type(cmd) != SCSI_PROT_DIF_TYPE3) ||
1675 (a_ref_tag == 0xffffffff))) {
1676 uint32_t blocks_done, resid;
1677 sector_t lba_s = scsi_get_lba(cmd);
1678
1679 /* 2TB boundary case covered automatically with this */
1680 blocks_done = e_ref_tag - (uint32_t)lba_s + 1;
1681
1682 resid = scsi_bufflen(cmd) - (blocks_done *
1683 cmd->device->sector_size);
1684
1685 scsi_set_resid(cmd, resid);
1686 cmd->result = DID_OK << 16;
1687
1688 /* Update protection tag */
1689 if (scsi_prot_sg_count(cmd)) {
1690 uint32_t i, j = 0, k = 0, num_ent;
1691 struct scatterlist *sg;
1692 struct sd_dif_tuple *spt;
1693
1694 /* Patch the corresponding protection tags */
1695 scsi_for_each_prot_sg(cmd, sg,
1696 scsi_prot_sg_count(cmd), i) {
1697 num_ent = sg_dma_len(sg) / 8;
1698 if (k + num_ent < blocks_done) {
1699 k += num_ent;
1700 continue;
1701 }
1702 j = blocks_done - k - 1;
1703 k = blocks_done;
1704 break;
1705 }
1706
1707 if (k != blocks_done) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001708 ql_log(ql_log_warn, vha, 0x302f,
Randy Dunlap8ec9c7f2011-09-23 15:40:50 -07001709 "unexpected tag values tag:lba=%x:%llx)\n",
1710 e_ref_tag, (unsigned long long)lba_s);
Arun Easi8cb20492011-08-16 11:29:22 -07001711 return 1;
1712 }
1713
1714 spt = page_address(sg_page(sg)) + sg->offset;
1715 spt += j;
1716
1717 spt->app_tag = 0xffff;
1718 if (scsi_get_prot_type(cmd) == SCSI_PROT_DIF_TYPE3)
1719 spt->ref_tag = 0xffffffff;
1720 }
1721
1722 return 0;
1723 }
1724
Arun Easibad75002010-05-04 15:01:30 -07001725 /* check guard */
1726 if (e_guard != a_guard) {
1727 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1728 0x10, 0x1);
1729 set_driver_byte(cmd, DRIVER_SENSE);
1730 set_host_byte(cmd, DID_ABORT);
1731 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
Arun Easi8cb20492011-08-16 11:29:22 -07001732 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001733 }
1734
Arun Easie02587d2011-08-16 11:29:23 -07001735 /* check ref tag */
1736 if (e_ref_tag != a_ref_tag) {
1737 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1738 0x10, 0x3);
1739 set_driver_byte(cmd, DRIVER_SENSE);
1740 set_host_byte(cmd, DID_ABORT);
1741 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
1742 return 1;
1743 }
1744
Arun Easibad75002010-05-04 15:01:30 -07001745 /* check appl tag */
1746 if (e_app_tag != a_app_tag) {
1747 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1748 0x10, 0x2);
1749 set_driver_byte(cmd, DRIVER_SENSE);
1750 set_host_byte(cmd, DID_ABORT);
1751 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
Arun Easi8cb20492011-08-16 11:29:22 -07001752 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001753 }
1754
Arun Easi8cb20492011-08-16 11:29:22 -07001755 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001756}
1757
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001758static void
1759qla25xx_process_bidir_status_iocb(scsi_qla_host_t *vha, void *pkt,
1760 struct req_que *req, uint32_t index)
1761{
1762 struct qla_hw_data *ha = vha->hw;
1763 srb_t *sp;
1764 uint16_t comp_status;
1765 uint16_t scsi_status;
1766 uint16_t thread_id;
1767 uint32_t rval = EXT_STATUS_OK;
1768 struct fc_bsg_job *bsg_job = NULL;
1769 sts_entry_t *sts;
1770 struct sts_entry_24xx *sts24;
1771 sts = (sts_entry_t *) pkt;
1772 sts24 = (struct sts_entry_24xx *) pkt;
1773
1774 /* Validate handle. */
Chad Dupuis8d93f552013-01-30 03:34:37 -05001775 if (index >= req->num_outstanding_cmds) {
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001776 ql_log(ql_log_warn, vha, 0x70af,
1777 "Invalid SCSI completion handle 0x%x.\n", index);
1778 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1779 return;
1780 }
1781
1782 sp = req->outstanding_cmds[index];
1783 if (sp) {
1784 /* Free outstanding command slot. */
1785 req->outstanding_cmds[index] = NULL;
1786 bsg_job = sp->u.bsg_job;
1787 } else {
1788 ql_log(ql_log_warn, vha, 0x70b0,
1789 "Req:%d: Invalid ISP SCSI completion handle(0x%x)\n",
1790 req->id, index);
1791
1792 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1793 return;
1794 }
1795
1796 if (IS_FWI2_CAPABLE(ha)) {
1797 comp_status = le16_to_cpu(sts24->comp_status);
1798 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
1799 } else {
1800 comp_status = le16_to_cpu(sts->comp_status);
1801 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1802 }
1803
1804 thread_id = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1805 switch (comp_status) {
1806 case CS_COMPLETE:
1807 if (scsi_status == 0) {
1808 bsg_job->reply->reply_payload_rcv_len =
1809 bsg_job->reply_payload.payload_len;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -04001810 vha->qla_stats.input_bytes +=
1811 bsg_job->reply->reply_payload_rcv_len;
1812 vha->qla_stats.input_requests++;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001813 rval = EXT_STATUS_OK;
1814 }
1815 goto done;
1816
1817 case CS_DATA_OVERRUN:
1818 ql_dbg(ql_dbg_user, vha, 0x70b1,
1819 "Command completed with date overrun thread_id=%d\n",
1820 thread_id);
1821 rval = EXT_STATUS_DATA_OVERRUN;
1822 break;
1823
1824 case CS_DATA_UNDERRUN:
1825 ql_dbg(ql_dbg_user, vha, 0x70b2,
1826 "Command completed with date underrun thread_id=%d\n",
1827 thread_id);
1828 rval = EXT_STATUS_DATA_UNDERRUN;
1829 break;
1830 case CS_BIDIR_RD_OVERRUN:
1831 ql_dbg(ql_dbg_user, vha, 0x70b3,
1832 "Command completed with read data overrun thread_id=%d\n",
1833 thread_id);
1834 rval = EXT_STATUS_DATA_OVERRUN;
1835 break;
1836
1837 case CS_BIDIR_RD_WR_OVERRUN:
1838 ql_dbg(ql_dbg_user, vha, 0x70b4,
1839 "Command completed with read and write data overrun "
1840 "thread_id=%d\n", thread_id);
1841 rval = EXT_STATUS_DATA_OVERRUN;
1842 break;
1843
1844 case CS_BIDIR_RD_OVERRUN_WR_UNDERRUN:
1845 ql_dbg(ql_dbg_user, vha, 0x70b5,
1846 "Command completed with read data over and write data "
1847 "underrun thread_id=%d\n", thread_id);
1848 rval = EXT_STATUS_DATA_OVERRUN;
1849 break;
1850
1851 case CS_BIDIR_RD_UNDERRUN:
1852 ql_dbg(ql_dbg_user, vha, 0x70b6,
1853 "Command completed with read data data underrun "
1854 "thread_id=%d\n", thread_id);
1855 rval = EXT_STATUS_DATA_UNDERRUN;
1856 break;
1857
1858 case CS_BIDIR_RD_UNDERRUN_WR_OVERRUN:
1859 ql_dbg(ql_dbg_user, vha, 0x70b7,
1860 "Command completed with read data under and write data "
1861 "overrun thread_id=%d\n", thread_id);
1862 rval = EXT_STATUS_DATA_UNDERRUN;
1863 break;
1864
1865 case CS_BIDIR_RD_WR_UNDERRUN:
1866 ql_dbg(ql_dbg_user, vha, 0x70b8,
1867 "Command completed with read and write data underrun "
1868 "thread_id=%d\n", thread_id);
1869 rval = EXT_STATUS_DATA_UNDERRUN;
1870 break;
1871
1872 case CS_BIDIR_DMA:
1873 ql_dbg(ql_dbg_user, vha, 0x70b9,
1874 "Command completed with data DMA error thread_id=%d\n",
1875 thread_id);
1876 rval = EXT_STATUS_DMA_ERR;
1877 break;
1878
1879 case CS_TIMEOUT:
1880 ql_dbg(ql_dbg_user, vha, 0x70ba,
1881 "Command completed with timeout thread_id=%d\n",
1882 thread_id);
1883 rval = EXT_STATUS_TIMEOUT;
1884 break;
1885 default:
1886 ql_dbg(ql_dbg_user, vha, 0x70bb,
1887 "Command completed with completion status=0x%x "
1888 "thread_id=%d\n", comp_status, thread_id);
1889 rval = EXT_STATUS_ERR;
1890 break;
1891 }
1892 bsg_job->reply->reply_payload_rcv_len = 0;
1893
1894done:
1895 /* Return the vendor specific reply to API */
1896 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
1897 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1898 /* Always return DID_OK, bsg will send the vendor specific response
1899 * in this case only */
1900 sp->done(vha, sp, (DID_OK << 6));
1901
1902}
1903
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904/**
1905 * qla2x00_status_entry() - Process a Status IOCB entry.
1906 * @ha: SCSI driver HA context
1907 * @pkt: Entry pointer
1908 */
1909static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001910qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 fc_port_t *fcport;
1914 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001915 sts_entry_t *sts;
1916 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 uint16_t comp_status;
1918 uint16_t scsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001919 uint16_t ox_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 uint8_t lscsi_status;
1921 int32_t resid;
Andrew Vasquez55442132010-07-23 15:28:27 +05001922 uint32_t sense_len, par_sense_len, rsp_info_len, resid_len,
1923 fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001924 uint8_t *rsp_info, *sense_data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001925 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001926 uint32_t handle;
1927 uint16_t que;
1928 struct req_que *req;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001929 int logit = 1;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001930 int res = 0;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001931 uint16_t state_flags = 0;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001932
1933 sts = (sts_entry_t *) pkt;
1934 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001935 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001936 comp_status = le16_to_cpu(sts24->comp_status);
1937 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001938 state_flags = le16_to_cpu(sts24->state_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001939 } else {
1940 comp_status = le16_to_cpu(sts->comp_status);
1941 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1942 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001943 handle = (uint32_t) LSW(sts->handle);
1944 que = MSW(sts->handle);
1945 req = ha->req_q_map[que];
Giridhar Malavalia9083012010-04-12 17:59:55 -07001946
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 /* Validate handle. */
Chad Dupuis8d93f552013-01-30 03:34:37 -05001948 if (handle < req->num_outstanding_cmds)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001949 sp = req->outstanding_cmds[handle];
Chad Dupuis8d93f552013-01-30 03:34:37 -05001950 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 sp = NULL;
1952
1953 if (sp == NULL) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001954 ql_dbg(ql_dbg_io, vha, 0x3017,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001955 "Invalid status handle (0x%x).\n", sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001957 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001958 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1959 else
1960 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001961 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 return;
1963 }
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001964
1965 if (unlikely((state_flags & BIT_1) && (sp->type == SRB_BIDI_CMD))) {
1966 qla25xx_process_bidir_status_iocb(vha, pkt, req, handle);
1967 return;
1968 }
1969
1970 /* Fast path completion. */
1971 if (comp_status == CS_COMPLETE && scsi_status == 0) {
Chad Dupuis3c290d02013-01-30 03:34:38 -05001972 qla2x00_do_host_ramp_up(vha);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001973 qla2x00_process_completed_request(vha, req, handle);
1974
1975 return;
1976 }
1977
1978 req->outstanding_cmds[handle] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001979 cp = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 if (cp == NULL) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001981 ql_dbg(ql_dbg_io, vha, 0x3018,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001982 "Command already returned (0x%x/%p).\n",
1983 sts->handle, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984
1985 return;
1986 }
1987
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001988 lscsi_status = scsi_status & STATUS_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
bdf79622005-04-17 15:06:53 -05001990 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001992 ox_id = 0;
Andrew Vasquez55442132010-07-23 15:28:27 +05001993 sense_len = par_sense_len = rsp_info_len = resid_len =
1994 fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001995 if (IS_FWI2_CAPABLE(ha)) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001996 if (scsi_status & SS_SENSE_LEN_VALID)
1997 sense_len = le32_to_cpu(sts24->sense_len);
1998 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
1999 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
2000 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER))
2001 resid_len = le32_to_cpu(sts24->rsp_residual_count);
2002 if (comp_status == CS_DATA_UNDERRUN)
2003 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002004 rsp_info = sts24->data;
2005 sense_data = sts24->data;
2006 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002007 ox_id = le16_to_cpu(sts24->ox_id);
Andrew Vasquez55442132010-07-23 15:28:27 +05002008 par_sense_len = sizeof(sts24->data);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002009 } else {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002010 if (scsi_status & SS_SENSE_LEN_VALID)
2011 sense_len = le16_to_cpu(sts->req_sense_length);
2012 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
2013 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002014 resid_len = le32_to_cpu(sts->residual_length);
2015 rsp_info = sts->rsp_info;
2016 sense_data = sts->req_sense_data;
Andrew Vasquez55442132010-07-23 15:28:27 +05002017 par_sense_len = sizeof(sts->req_sense_data);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002018 }
2019
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 /* Check for any FCP transport errors. */
2021 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002022 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasquez55442132010-07-23 15:28:27 +05002023 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002024 sense_data += rsp_info_len;
Andrew Vasquez55442132010-07-23 15:28:27 +05002025 par_sense_len -= rsp_info_len;
2026 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002027 if (rsp_info_len > 3 && rsp_info[3]) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002028 ql_dbg(ql_dbg_io, fcport->vha, 0x3019,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002029 "FCP I/O protocol failure (0x%x/0x%x).\n",
2030 rsp_info_len, rsp_info[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002032 res = DID_BUS_BUSY << 16;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002033 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 }
2035 }
2036
Andrew Vasquez3e8ce322008-02-28 14:06:10 -08002037 /* Check for overrun. */
2038 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
2039 scsi_status & SS_RESIDUAL_OVER)
2040 comp_status = CS_DATA_OVERRUN;
2041
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 /*
2043 * Based on Host and scsi status generate status code for Linux
2044 */
2045 switch (comp_status) {
2046 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002047 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 if (scsi_status == 0) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002049 res = DID_OK << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 break;
2051 }
2052 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002053 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002054 scsi_set_resid(cp, resid);
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002055
2056 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002057 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002058 cp->underflow)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002059 ql_dbg(ql_dbg_io, fcport->vha, 0x301a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002060 "Mid-layer underflow "
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002061 "detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002062 resid, scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002063
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002064 res = DID_ERROR << 16;
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002065 break;
2066 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002068 res = DID_OK << 16 | lscsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002070 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002071 ql_dbg(ql_dbg_io, fcport->vha, 0x301b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002072 "QUEUE FULL detected.\n");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002073 break;
2074 }
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002075 logit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 if (lscsi_status != SS_CHECK_CONDITION)
2077 break;
2078
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002079 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 if (!(scsi_status & SS_SENSE_LEN_VALID))
2081 break;
2082
Andrew Vasquez55442132010-07-23 15:28:27 +05002083 qla2x00_handle_sense(sp, sense_data, par_sense_len, sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002084 rsp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 break;
2086
2087 case CS_DATA_UNDERRUN:
Ravi Ananded17c71b52006-05-17 15:08:55 -07002088 /* Use F/W calculated residual length. */
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002089 resid = IS_FWI2_CAPABLE(ha) ? fw_resid_len : resid_len;
2090 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 if (scsi_status & SS_RESIDUAL_UNDER) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002092 if (IS_FWI2_CAPABLE(ha) && fw_resid_len != resid_len) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002093 ql_dbg(ql_dbg_io, fcport->vha, 0x301d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002094 "Dropped frame(s) detected "
2095 "(0x%x of 0x%x bytes).\n",
2096 resid, scsi_bufflen(cp));
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08002097
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002098 res = DID_ERROR << 16 | lscsi_status;
Arun Easi4e85e3d2011-11-18 09:02:10 -08002099 goto check_scsi_status;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002100 }
2101
2102 if (!lscsi_status &&
2103 ((unsigned)(scsi_bufflen(cp) - resid) <
2104 cp->underflow)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002105 ql_dbg(ql_dbg_io, fcport->vha, 0x301e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002106 "Mid-layer underflow "
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002107 "detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002108 resid, scsi_bufflen(cp));
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002109
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002110 res = DID_ERROR << 16;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002111 break;
2112 }
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002113 } else if (lscsi_status != SAM_STAT_TASK_SET_FULL &&
2114 lscsi_status != SAM_STAT_BUSY) {
2115 /*
2116 * scsi status of task set and busy are considered to be
2117 * task not completed.
2118 */
2119
Arun Easi5e19ed92012-02-09 11:15:51 -08002120 ql_dbg(ql_dbg_io, fcport->vha, 0x301f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002121 "Dropped frame(s) detected (0x%x "
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002122 "of 0x%x bytes).\n", resid,
2123 scsi_bufflen(cp));
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002124
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002125 res = DID_ERROR << 16 | lscsi_status;
Lalit Chandivade0374f552010-09-03 14:57:04 -07002126 goto check_scsi_status;
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002127 } else {
2128 ql_dbg(ql_dbg_io, fcport->vha, 0x3030,
2129 "scsi_status: 0x%x, lscsi_status: 0x%x\n",
2130 scsi_status, lscsi_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 }
2132
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002133 res = DID_OK << 16 | lscsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002134 logit = 0;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002135
Lalit Chandivade0374f552010-09-03 14:57:04 -07002136check_scsi_status:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002138 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 * Status.
2140 */
2141 if (lscsi_status != 0) {
Andrew Vasquezffec28a2007-01-29 10:22:27 -08002142 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002143 ql_dbg(ql_dbg_io, fcport->vha, 0x3020,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002144 "QUEUE FULL detected.\n");
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002145 logit = 1;
Andrew Vasquezffec28a2007-01-29 10:22:27 -08002146 break;
2147 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 if (lscsi_status != SS_CHECK_CONDITION)
2149 break;
2150
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002151 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 if (!(scsi_status & SS_SENSE_LEN_VALID))
2153 break;
2154
Andrew Vasquez55442132010-07-23 15:28:27 +05002155 qla2x00_handle_sense(sp, sense_data, par_sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002156 sense_len, rsp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 }
2158 break;
2159
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 case CS_PORT_LOGGED_OUT:
2161 case CS_PORT_CONFIG_CHG:
2162 case CS_PORT_BUSY:
2163 case CS_INCOMPLETE:
2164 case CS_PORT_UNAVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 case CS_TIMEOUT:
Chad Dupuisff454b02010-10-15 11:27:42 -07002166 case CS_RESET:
2167
Mike Christie056a4482008-08-19 18:45:29 -05002168 /*
2169 * We are going to have the fc class block the rport
2170 * while we try to recover so instruct the mid layer
2171 * to requeue until the class decides how to handle this.
2172 */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002173 res = DID_TRANSPORT_DISRUPTED << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002175 if (comp_status == CS_TIMEOUT) {
2176 if (IS_FWI2_CAPABLE(ha))
2177 break;
2178 else if ((le16_to_cpu(sts->status_flags) &
2179 SF_LOGOUT_SENT) == 0)
2180 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002182
Arun Easi5e19ed92012-02-09 11:15:51 -08002183 ql_dbg(ql_dbg_io, fcport->vha, 0x3021,
Chad Dupuis0e948972013-08-27 01:37:39 -04002184 "Port to be marked lost on fcport=%02x%02x%02x, current "
2185 "port state= %s.\n", fcport->d_id.b.domain,
2186 fcport->d_id.b.area, fcport->d_id.b.al_pa,
2187 port_state_str[atomic_read(&fcport->state)]);
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002188
2189 if (atomic_read(&fcport->state) == FCS_ONLINE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002190 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 break;
2192
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002193 case CS_ABORTED:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002194 res = DID_RESET << 16;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002195 break;
Arun Easibad75002010-05-04 15:01:30 -07002196
2197 case CS_DIF_ERROR:
Arun Easi8cb20492011-08-16 11:29:22 -07002198 logit = qla2x00_handle_dif_error(sp, sts24);
Arun Easifb6e4662012-08-22 14:21:32 -04002199 res = cp->result;
Arun Easibad75002010-05-04 15:01:30 -07002200 break;
Arun Easi9e522cd2012-08-22 14:21:31 -04002201
2202 case CS_TRANSPORT:
2203 res = DID_ERROR << 16;
2204
2205 if (!IS_PI_SPLIT_DET_CAPABLE(ha))
2206 break;
2207
2208 if (state_flags & BIT_4)
2209 scmd_printk(KERN_WARNING, cp,
2210 "Unsupported device '%s' found.\n",
2211 cp->device->vendor);
2212 break;
2213
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 default:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002215 res = DID_ERROR << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 break;
2217 }
2218
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002219out:
2220 if (logit)
Arun Easi5e19ed92012-02-09 11:15:51 -08002221 ql_dbg(ql_dbg_io, fcport->vha, 0x3022,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04002222 "FCP command status: 0x%x-0x%x (0x%x) nexus=%ld:%d:%d "
2223 "portid=%02x%02x%02x oxid=0x%x cdb=%10phN len=0x%x "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002224 "rsp_info=0x%x resid=0x%x fw_resid=0x%x.\n",
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002225 comp_status, scsi_status, res, vha->host_no,
Chad Dupuiscfb09192011-11-18 09:03:07 -08002226 cp->device->id, cp->device->lun, fcport->d_id.b.domain,
2227 fcport->d_id.b.area, fcport->d_id.b.al_pa, ox_id,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04002228 cp->cmnd, scsi_bufflen(cp), rsp_info_len,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002229 resid_len, fw_resid_len);
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002230
Chad Dupuis3c290d02013-01-30 03:34:38 -05002231 if (!res)
2232 qla2x00_do_host_ramp_up(vha);
2233
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002234 if (rsp->status_srb == NULL)
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002235 sp->done(ha, sp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236}
2237
2238/**
2239 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
2240 * @ha: SCSI driver HA context
2241 * @pkt: Entry pointer
2242 *
2243 * Extended sense data.
2244 */
2245static void
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002246qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002248 uint8_t sense_sz = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002249 struct qla_hw_data *ha = rsp->hw;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002250 struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002251 srb_t *sp = rsp->status_srb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 struct scsi_cmnd *cp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002253 uint32_t sense_len;
2254 uint8_t *sense_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002256 if (!sp || !GET_CMD_SENSE_LEN(sp))
2257 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002259 sense_len = GET_CMD_SENSE_LEN(sp);
2260 sense_ptr = GET_CMD_SENSE_PTR(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002262 cp = GET_CMD_SP(sp);
2263 if (cp == NULL) {
2264 ql_log(ql_log_warn, vha, 0x3025,
2265 "cmd is NULL: already returned to OS (sp=%p).\n", sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002267 rsp->status_srb = NULL;
2268 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002271 if (sense_len > sizeof(pkt->data))
2272 sense_sz = sizeof(pkt->data);
2273 else
2274 sense_sz = sense_len;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002275
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002276 /* Move sense data. */
2277 if (IS_FWI2_CAPABLE(ha))
2278 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
2279 memcpy(sense_ptr, pkt->data, sense_sz);
2280 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302c,
2281 sense_ptr, sense_sz);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002282
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002283 sense_len -= sense_sz;
2284 sense_ptr += sense_sz;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002285
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002286 SET_CMD_SENSE_PTR(sp, sense_ptr);
2287 SET_CMD_SENSE_LEN(sp, sense_len);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002288
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002289 /* Place command on done queue. */
2290 if (sense_len == 0) {
2291 rsp->status_srb = NULL;
2292 sp->done(ha, sp, cp->result);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002293 }
Giridhar Malavalic4631192011-11-18 09:03:08 -08002294}
2295
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296/**
2297 * qla2x00_error_entry() - Process an error entry.
2298 * @ha: SCSI driver HA context
2299 * @pkt: Entry pointer
2300 */
2301static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002302qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303{
2304 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002305 struct qla_hw_data *ha = vha->hw;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002306 const char func[] = "ERROR-IOCB";
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002307 uint16_t que = MSW(pkt->handle);
Arun Easia6fe35c2012-02-09 11:16:01 -08002308 struct req_que *req = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002309 int res = DID_ERROR << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002310
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002311 ql_dbg(ql_dbg_async, vha, 0x502a,
2312 "type of error status in response: 0x%x\n", pkt->entry_status);
2313
Arun Easia6fe35c2012-02-09 11:16:01 -08002314 if (que >= ha->max_req_queues || !ha->req_q_map[que])
2315 goto fatal;
2316
2317 req = ha->req_q_map[que];
2318
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002319 if (pkt->entry_status & RF_BUSY)
2320 res = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321
Giridhar Malavalic4631192011-11-18 09:03:08 -08002322 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
Arun Easia6fe35c2012-02-09 11:16:01 -08002323 if (sp) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002324 sp->done(ha, sp, res);
Arun Easia6fe35c2012-02-09 11:16:01 -08002325 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 }
Arun Easia6fe35c2012-02-09 11:16:01 -08002327fatal:
2328 ql_log(ql_log_warn, vha, 0x5030,
2329 "Error entry - invalid handle/queue.\n");
2330
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002331 if (IS_P3P_TYPE(ha))
Arun Easia6fe35c2012-02-09 11:16:01 -08002332 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
2333 else
2334 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2335 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336}
2337
2338/**
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002339 * qla24xx_mbx_completion() - Process mailbox command completions.
2340 * @ha: SCSI driver HA context
2341 * @mb0: Mailbox0 register
2342 */
2343static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002344qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002345{
2346 uint16_t cnt;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002347 uint32_t mboxes;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002348 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002349 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002350 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2351
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002352 /* Read all mbox registers? */
2353 mboxes = (1 << ha->mbx_count) - 1;
2354 if (!ha->mcp)
Masanari Iidaa7201012012-11-21 02:40:42 -05002355 ql_dbg(ql_dbg_async, vha, 0x504e, "MBX pointer ERROR.\n");
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002356 else
2357 mboxes = ha->mcp->in_mb;
2358
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002359 /* Load return mailbox registers. */
2360 ha->flags.mbox_int = 1;
2361 ha->mailbox_out[0] = mb0;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002362 mboxes >>= 1;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002363 wptr = (uint16_t __iomem *)&reg->mailbox1;
2364
2365 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002366 if (mboxes & BIT_0)
2367 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
2368
2369 mboxes >>= 1;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002370 wptr++;
2371 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002372}
2373
2374/**
2375 * qla24xx_process_response_queue() - Process response queue entries.
2376 * @ha: SCSI driver HA context
2377 */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002378void qla24xx_process_response_queue(struct scsi_qla_host *vha,
2379 struct rsp_que *rsp)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002380{
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002381 struct sts_entry_24xx *pkt;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002382 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002383
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002384 if (!vha->flags.online)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002385 return;
2386
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002387 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
2388 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002389
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002390 rsp->ring_index++;
2391 if (rsp->ring_index == rsp->length) {
2392 rsp->ring_index = 0;
2393 rsp->ring_ptr = rsp->ring;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002394 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002395 rsp->ring_ptr++;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002396 }
2397
2398 if (pkt->entry_status != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002399 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002400
2401 (void)qlt_24xx_process_response_error(vha, pkt);
2402
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002403 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2404 wmb();
2405 continue;
2406 }
2407
2408 switch (pkt->entry_type) {
2409 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002410 qla2x00_status_entry(vha, rsp, pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002411 break;
2412 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002413 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002414 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002415 case VP_RPT_ID_IOCB_TYPE:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002416 qla24xx_report_id_acquisition(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002417 (struct vp_rpt_id_entry_24xx *)pkt);
2418 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07002419 case LOGINOUT_PORT_IOCB_TYPE:
2420 qla24xx_logio_entry(vha, rsp->req,
2421 (struct logio_entry_24xx *)pkt);
2422 break;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07002423 case TSK_MGMT_IOCB_TYPE:
2424 qla24xx_tm_iocb_entry(vha, rsp->req,
2425 (struct tsk_mgmt_entry *)pkt);
2426 break;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002427 case CT_IOCB_TYPE:
2428 qla24xx_els_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002429 break;
2430 case ELS_IOCB_TYPE:
2431 qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE);
2432 break;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002433 case ABTS_RECV_24XX:
2434 /* ensure that the ATIO queue is empty */
2435 qlt_24xx_process_atio_queue(vha);
2436 case ABTS_RESP_24XX:
2437 case CTIO_TYPE7:
2438 case NOTIFY_ACK_TYPE:
2439 qlt_response_pkt_all_vps(vha, (response_t *)pkt);
2440 break;
Saurav Kashyap54883292011-08-16 11:31:48 -07002441 case MARKER_TYPE:
2442 /* Do nothing in this case, this check is to prevent it
2443 * from falling into default case
2444 */
2445 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002446 default:
2447 /* Type Not Supported. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002448 ql_dbg(ql_dbg_async, vha, 0x5042,
2449 "Received unknown response pkt type %x "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002450 "entry status=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002451 pkt->entry_type, pkt->entry_status);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002452 break;
2453 }
2454 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2455 wmb();
2456 }
2457
2458 /* Adjust ring index */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002459 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002460 struct device_reg_82xx __iomem *reg = &ha->iobase->isp82;
2461 WRT_REG_DWORD(&reg->rsp_q_out[0], rsp->ring_index);
2462 } else
2463 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002464}
2465
Andrew Vasquez05236a02007-09-20 14:07:37 -07002466static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002467qla2xxx_check_risc_status(scsi_qla_host_t *vha)
Andrew Vasquez05236a02007-09-20 14:07:37 -07002468{
2469 int rval;
2470 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002471 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez05236a02007-09-20 14:07:37 -07002472 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2473
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002474 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha))
Andrew Vasquez05236a02007-09-20 14:07:37 -07002475 return;
2476
2477 rval = QLA_SUCCESS;
2478 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
2479 RD_REG_DWORD(&reg->iobase_addr);
2480 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
2481 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
2482 rval == QLA_SUCCESS; cnt--) {
2483 if (cnt) {
2484 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
2485 udelay(10);
2486 } else
2487 rval = QLA_FUNCTION_TIMEOUT;
2488 }
2489 if (rval == QLA_SUCCESS)
2490 goto next_test;
2491
Bart Van Asscheb2ec76c2013-06-25 11:27:29 -04002492 rval = QLA_SUCCESS;
Andrew Vasquez05236a02007-09-20 14:07:37 -07002493 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
2494 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
2495 rval == QLA_SUCCESS; cnt--) {
2496 if (cnt) {
2497 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
2498 udelay(10);
2499 } else
2500 rval = QLA_FUNCTION_TIMEOUT;
2501 }
2502 if (rval != QLA_SUCCESS)
2503 goto done;
2504
2505next_test:
2506 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002507 ql_log(ql_log_info, vha, 0x504c,
2508 "Additional code -- 0x55AA.\n");
Andrew Vasquez05236a02007-09-20 14:07:37 -07002509
2510done:
2511 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
2512 RD_REG_DWORD(&reg->iobase_window);
2513}
2514
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002515/**
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002516 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP24xx.
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002517 * @irq:
2518 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002519 *
2520 * Called by system whenever the host adapter generates an interrupt.
2521 *
2522 * Returns handled flag.
2523 */
2524irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01002525qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002526{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002527 scsi_qla_host_t *vha;
2528 struct qla_hw_data *ha;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002529 struct device_reg_24xx __iomem *reg;
2530 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002531 unsigned long iter;
2532 uint32_t stat;
2533 uint32_t hccr;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002534 uint16_t mb[8];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002535 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002536 unsigned long flags;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002537
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002538 rsp = (struct rsp_que *) dev_id;
2539 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002540 ql_log(ql_log_info, NULL, 0x5059,
2541 "%s: NULL response queue pointer.\n", __func__);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002542 return IRQ_NONE;
2543 }
2544
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002545 ha = rsp->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002546 reg = &ha->iobase->isp24;
2547 status = 0;
2548
Andrew Vasquez85880802009-12-15 21:29:46 -08002549 if (unlikely(pci_channel_offline(ha->pdev)))
2550 return IRQ_HANDLED;
2551
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002552 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002553 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002554 for (iter = 50; iter--; ) {
2555 stat = RD_REG_DWORD(&reg->host_status);
2556 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08002557 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07002558 break;
2559
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002560 hccr = RD_REG_DWORD(&reg->hccr);
2561
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002562 ql_log(ql_log_warn, vha, 0x504b,
2563 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2564 hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002565
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002566 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002567
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002568 ha->isp_ops->fw_dump(vha, 1);
2569 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002570 break;
2571 } else if ((stat & HSRX_RISC_INT) == 0)
2572 break;
2573
2574 switch (stat & 0xff) {
Arun Easifafbda92012-08-22 14:21:16 -04002575 case INTR_ROM_MB_SUCCESS:
2576 case INTR_ROM_MB_FAILED:
2577 case INTR_MB_SUCCESS:
2578 case INTR_MB_FAILED:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002579 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002580 status |= MBX_INTERRUPT;
2581
2582 break;
Arun Easifafbda92012-08-22 14:21:16 -04002583 case INTR_ASYNC_EVENT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002584 mb[0] = MSW(stat);
2585 mb[1] = RD_REG_WORD(&reg->mailbox1);
2586 mb[2] = RD_REG_WORD(&reg->mailbox2);
2587 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002588 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002589 break;
Arun Easifafbda92012-08-22 14:21:16 -04002590 case INTR_RSP_QUE_UPDATE:
2591 case INTR_RSP_QUE_UPDATE_83XX:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002592 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002593 break;
Arun Easifafbda92012-08-22 14:21:16 -04002594 case INTR_ATIO_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002595 qlt_24xx_process_atio_queue(vha);
2596 break;
Arun Easifafbda92012-08-22 14:21:16 -04002597 case INTR_ATIO_RSP_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002598 qlt_24xx_process_atio_queue(vha);
2599 qla24xx_process_response_queue(vha, rsp);
2600 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002601 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002602 ql_dbg(ql_dbg_async, vha, 0x504f,
2603 "Unrecognized interrupt type (%d).\n", stat * 0xff);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002604 break;
2605 }
2606 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2607 RD_REG_DWORD_RELAXED(&reg->hccr);
Giridhar Malavalicb860bb2012-08-22 14:21:30 -04002608 if (unlikely(IS_QLA83XX(ha) && (ha->pdev->revision == 1)))
2609 ndelay(3500);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002610 }
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -07002611 qla2x00_handle_mbx_completion(ha, status);
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002612 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002613
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002614 return IRQ_HANDLED;
2615}
2616
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002617static irqreturn_t
2618qla24xx_msix_rsp_q(int irq, void *dev_id)
2619{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002620 struct qla_hw_data *ha;
2621 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002622 struct device_reg_24xx __iomem *reg;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002623 struct scsi_qla_host *vha;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002624 unsigned long flags;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002625
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002626 rsp = (struct rsp_que *) dev_id;
2627 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002628 ql_log(ql_log_info, NULL, 0x505a,
2629 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002630 return IRQ_NONE;
2631 }
2632 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002633 reg = &ha->iobase->isp24;
2634
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002635 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002636
Anirban Chakrabortya67093d2010-02-04 14:17:59 -08002637 vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002638 qla24xx_process_response_queue(vha, rsp);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002639 if (!ha->flags.disable_msix_handshake) {
Anirban Chakrabortyeb941142009-08-04 16:12:13 -07002640 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2641 RD_REG_DWORD_RELAXED(&reg->hccr);
2642 }
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002643 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002644
2645 return IRQ_HANDLED;
2646}
2647
2648static irqreturn_t
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002649qla25xx_msix_rsp_q(int irq, void *dev_id)
2650{
2651 struct qla_hw_data *ha;
2652 struct rsp_que *rsp;
Anirban Chakraborty31557542009-12-02 10:36:55 -08002653 struct device_reg_24xx __iomem *reg;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002654 unsigned long flags;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002655
2656 rsp = (struct rsp_que *) dev_id;
2657 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002658 ql_log(ql_log_info, NULL, 0x505b,
2659 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002660 return IRQ_NONE;
2661 }
2662 ha = rsp->hw;
2663
Anirban Chakraborty31557542009-12-02 10:36:55 -08002664 /* Clear the interrupt, if enabled, for this response queue */
Andrew Vasquezd4247542011-10-26 14:20:13 -07002665 if (!ha->flags.disable_msix_handshake) {
Anirban Chakraborty31557542009-12-02 10:36:55 -08002666 reg = &ha->iobase->isp24;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002667 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002668 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2669 RD_REG_DWORD_RELAXED(&reg->hccr);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002670 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002671 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002672 queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work);
2673
2674 return IRQ_HANDLED;
2675}
2676
2677static irqreturn_t
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002678qla24xx_msix_default(int irq, void *dev_id)
2679{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002680 scsi_qla_host_t *vha;
2681 struct qla_hw_data *ha;
2682 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002683 struct device_reg_24xx __iomem *reg;
2684 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002685 uint32_t stat;
2686 uint32_t hccr;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002687 uint16_t mb[8];
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002688 unsigned long flags;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002689
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002690 rsp = (struct rsp_que *) dev_id;
2691 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002692 ql_log(ql_log_info, NULL, 0x505c,
2693 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002694 return IRQ_NONE;
2695 }
2696 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002697 reg = &ha->iobase->isp24;
2698 status = 0;
2699
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002700 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002701 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002702 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002703 stat = RD_REG_DWORD(&reg->host_status);
2704 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08002705 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07002706 break;
2707
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002708 hccr = RD_REG_DWORD(&reg->hccr);
2709
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002710 ql_log(ql_log_info, vha, 0x5050,
2711 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2712 hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002713
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002714 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002715
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002716 ha->isp_ops->fw_dump(vha, 1);
2717 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002718 break;
2719 } else if ((stat & HSRX_RISC_INT) == 0)
2720 break;
2721
2722 switch (stat & 0xff) {
Arun Easifafbda92012-08-22 14:21:16 -04002723 case INTR_ROM_MB_SUCCESS:
2724 case INTR_ROM_MB_FAILED:
2725 case INTR_MB_SUCCESS:
2726 case INTR_MB_FAILED:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002727 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002728 status |= MBX_INTERRUPT;
2729
2730 break;
Arun Easifafbda92012-08-22 14:21:16 -04002731 case INTR_ASYNC_EVENT:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002732 mb[0] = MSW(stat);
2733 mb[1] = RD_REG_WORD(&reg->mailbox1);
2734 mb[2] = RD_REG_WORD(&reg->mailbox2);
2735 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002736 qla2x00_async_event(vha, rsp, mb);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002737 break;
Arun Easifafbda92012-08-22 14:21:16 -04002738 case INTR_RSP_QUE_UPDATE:
2739 case INTR_RSP_QUE_UPDATE_83XX:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002740 qla24xx_process_response_queue(vha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002741 break;
Arun Easifafbda92012-08-22 14:21:16 -04002742 case INTR_ATIO_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002743 qlt_24xx_process_atio_queue(vha);
2744 break;
Arun Easifafbda92012-08-22 14:21:16 -04002745 case INTR_ATIO_RSP_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002746 qlt_24xx_process_atio_queue(vha);
2747 qla24xx_process_response_queue(vha, rsp);
2748 break;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002749 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002750 ql_dbg(ql_dbg_async, vha, 0x5051,
2751 "Unrecognized interrupt type (%d).\n", stat & 0xff);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002752 break;
2753 }
2754 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002755 } while (0);
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -07002756 qla2x00_handle_mbx_completion(ha, status);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002757 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002758
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002759 return IRQ_HANDLED;
2760}
2761
2762/* Interrupt handling helpers. */
2763
2764struct qla_init_msix_entry {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002765 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07002766 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002767};
2768
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002769static struct qla_init_msix_entry msix_entries[3] = {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002770 { "qla2xxx (default)", qla24xx_msix_default },
2771 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002772 { "qla2xxx (multiq)", qla25xx_msix_rsp_q },
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002773};
2774
Giridhar Malavalia9083012010-04-12 17:59:55 -07002775static struct qla_init_msix_entry qla82xx_msix_entries[2] = {
2776 { "qla2xxx (default)", qla82xx_msix_default },
2777 { "qla2xxx (rsp_q)", qla82xx_msix_rsp_q },
2778};
2779
Arun Easiaa230bc2013-01-30 03:34:39 -05002780static struct qla_init_msix_entry qla83xx_msix_entries[3] = {
2781 { "qla2xxx (default)", qla24xx_msix_default },
2782 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
2783 { "qla2xxx (atio_q)", qla83xx_msix_atio_q },
2784};
2785
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002786static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002787qla24xx_disable_msix(struct qla_hw_data *ha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002788{
2789 int i;
2790 struct qla_msix_entry *qentry;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002791 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002792
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002793 for (i = 0; i < ha->msix_count; i++) {
2794 qentry = &ha->msix_entries[i];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002795 if (qentry->have_irq)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002796 free_irq(qentry->vector, qentry->rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002797 }
2798 pci_disable_msix(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002799 kfree(ha->msix_entries);
2800 ha->msix_entries = NULL;
2801 ha->flags.msix_enabled = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002802 ql_dbg(ql_dbg_init, vha, 0x0042,
2803 "Disabled the MSI.\n");
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002804}
2805
2806static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002807qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002808{
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002809#define MIN_MSIX_COUNT 2
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002810 int i, ret;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002811 struct msix_entry *entries;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002812 struct qla_msix_entry *qentry;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002813 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002814
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002815 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002816 GFP_KERNEL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002817 if (!entries) {
2818 ql_log(ql_log_warn, vha, 0x00bc,
2819 "Failed to allocate memory for msix_entry.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002820 return -ENOMEM;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002821 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002822
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002823 for (i = 0; i < ha->msix_count; i++)
2824 entries[i].entry = i;
2825
2826 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002827 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002828 if (ret < MIN_MSIX_COUNT)
2829 goto msix_failed;
2830
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002831 ql_log(ql_log_warn, vha, 0x00c6,
2832 "MSI-X: Failed to enable support "
2833 "-- %d/%d\n Retry with %d vectors.\n",
2834 ha->msix_count, ret, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002835 ha->msix_count = ret;
2836 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
2837 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002838msix_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002839 ql_log(ql_log_fatal, vha, 0x00c7,
2840 "MSI-X: Failed to enable support, "
2841 "giving up -- %d/%d.\n",
2842 ha->msix_count, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002843 goto msix_out;
2844 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002845 ha->max_rsp_queues = ha->msix_count - 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002846 }
2847 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
2848 ha->msix_count, GFP_KERNEL);
2849 if (!ha->msix_entries) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002850 ql_log(ql_log_fatal, vha, 0x00c8,
2851 "Failed to allocate memory for ha->msix_entries.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002852 ret = -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002853 goto msix_out;
2854 }
2855 ha->flags.msix_enabled = 1;
2856
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002857 for (i = 0; i < ha->msix_count; i++) {
2858 qentry = &ha->msix_entries[i];
2859 qentry->vector = entries[i].vector;
2860 qentry->entry = entries[i].entry;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002861 qentry->have_irq = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002862 qentry->rsp = NULL;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002863 }
2864
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002865 /* Enable MSI-X vectors for the base queue */
Arun Easiaa230bc2013-01-30 03:34:39 -05002866 for (i = 0; i < ha->msix_count; i++) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002867 qentry = &ha->msix_entries[i];
Arun Easiaa230bc2013-01-30 03:34:39 -05002868 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) {
2869 ret = request_irq(qentry->vector,
2870 qla83xx_msix_entries[i].handler,
2871 0, qla83xx_msix_entries[i].name, rsp);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002872 } else if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002873 ret = request_irq(qentry->vector,
2874 qla82xx_msix_entries[i].handler,
2875 0, qla82xx_msix_entries[i].name, rsp);
2876 } else {
2877 ret = request_irq(qentry->vector,
2878 msix_entries[i].handler,
2879 0, msix_entries[i].name, rsp);
2880 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002881 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002882 ql_log(ql_log_fatal, vha, 0x00cb,
2883 "MSI-X: unable to register handler -- %x/%d.\n",
2884 qentry->vector, ret);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002885 qla24xx_disable_msix(ha);
2886 ha->mqenable = 0;
2887 goto msix_out;
2888 }
2889 qentry->have_irq = 1;
2890 qentry->rsp = rsp;
2891 rsp->msix = qentry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002892 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002893
2894 /* Enable MSI-X vector for response queue update for queue 0 */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002895 if (IS_QLA83XX(ha)) {
2896 if (ha->msixbase && ha->mqiobase &&
2897 (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
2898 ha->mqenable = 1;
2899 } else
2900 if (ha->mqiobase
2901 && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
2902 ha->mqenable = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002903 ql_dbg(ql_dbg_multiq, vha, 0xc005,
2904 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
2905 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
2906 ql_dbg(ql_dbg_init, vha, 0x0055,
2907 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
2908 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002909
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002910msix_out:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002911 kfree(entries);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002912 return ret;
2913}
2914
2915int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002916qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002917{
2918 int ret;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002919 device_reg_t __iomem *reg = ha->iobase;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002920 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002921
2922 /* If possible, enable MSI-X. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002923 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002924 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha) && !IS_QLAFX00(ha))
Ben Hutchings6377a7a2010-03-19 16:59:19 -07002925 goto skip_msi;
2926
2927 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
2928 (ha->pdev->subsystem_device == 0x7040 ||
2929 ha->pdev->subsystem_device == 0x7041 ||
2930 ha->pdev->subsystem_device == 0x1705)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002931 ql_log(ql_log_warn, vha, 0x0034,
2932 "MSI-X: Unsupported ISP 2432 SSVID/SSDID (0x%X,0x%X).\n",
Ben Hutchings6377a7a2010-03-19 16:59:19 -07002933 ha->pdev->subsystem_vendor,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002934 ha->pdev->subsystem_device);
Ben Hutchings6377a7a2010-03-19 16:59:19 -07002935 goto skip_msi;
2936 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002937
Chad Dupuis42cd4f52011-08-16 11:29:24 -07002938 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002939 ql_log(ql_log_warn, vha, 0x0035,
2940 "MSI-X; Unsupported ISP2432 (0x%X, 0x%X).\n",
Chad Dupuis42cd4f52011-08-16 11:29:24 -07002941 ha->pdev->revision, QLA_MSIX_CHIP_REV_24XX);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002942 goto skip_msix;
2943 }
2944
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002945 ret = qla24xx_enable_msix(ha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002946 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002947 ql_dbg(ql_dbg_init, vha, 0x0036,
2948 "MSI-X: Enabled (0x%X, 0x%X).\n",
2949 ha->chip_revision, ha->fw_attributes);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002950 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002951 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002952 ql_log(ql_log_info, vha, 0x0037,
2953 "MSI-X Falling back-to MSI mode -%d.\n", ret);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002954skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002955
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002956 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002957 !IS_QLA8001(ha) && !IS_P3P_TYPE(ha) && !IS_QLAFX00(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002958 goto skip_msi;
2959
2960 ret = pci_enable_msi(ha->pdev);
2961 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002962 ql_dbg(ql_dbg_init, vha, 0x0038,
2963 "MSI: Enabled.\n");
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002964 ha->flags.msi_enabled = 1;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002965 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002966 ql_log(ql_log_warn, vha, 0x0039,
2967 "MSI-X; Falling back-to INTa mode -- %d.\n", ret);
Giridhar Malavalia033b652012-08-22 14:21:07 -04002968
2969 /* Skip INTx on ISP82xx. */
2970 if (!ha->flags.msi_enabled && IS_QLA82XX(ha))
2971 return QLA_FUNCTION_FAILED;
2972
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002973skip_msi:
2974
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002975 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Mike Hernandez7992abf2010-11-23 16:52:47 -08002976 ha->flags.msi_enabled ? 0 : IRQF_SHARED,
2977 QLA2XXX_DRIVER_NAME, rsp);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002978 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002979 ql_log(ql_log_warn, vha, 0x003a,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002980 "Failed to reserve interrupt %d already in use.\n",
2981 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002982 goto fail;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002983 } else if (!ha->flags.msi_enabled) {
Saurav Kashyap68d91cb2012-11-21 02:40:44 -05002984 ql_dbg(ql_dbg_init, vha, 0x0125,
2985 "INTa mode: Enabled.\n");
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002986 ha->flags.mr_intr_valid = 1;
2987 }
Mike Hernandez7992abf2010-11-23 16:52:47 -08002988
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002989clear_risc_ints:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002990
Andrew Vasquezc6952482008-04-03 13:13:17 -07002991 spin_lock_irq(&ha->hardware_lock);
Giridhar Malavalic1114952012-08-22 14:21:33 -04002992 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002993 WRT_REG_WORD(&reg->isp.semaphore, 0);
Andrew Vasquezc6952482008-04-03 13:13:17 -07002994 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002995
2996fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002997 return ret;
2998}
2999
3000void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003001qla2x00_free_irqs(scsi_qla_host_t *vha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003002{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003003 struct qla_hw_data *ha = vha->hw;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003004 struct rsp_que *rsp;
3005
3006 /*
3007 * We need to check that ha->rsp_q_map is valid in case we are called
3008 * from a probe failure context.
3009 */
3010 if (!ha->rsp_q_map || !ha->rsp_q_map[0])
3011 return;
3012 rsp = ha->rsp_q_map[0];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003013
3014 if (ha->flags.msix_enabled)
3015 qla24xx_disable_msix(ha);
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003016 else if (ha->flags.msi_enabled) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003017 free_irq(ha->pdev->irq, rsp);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07003018 pci_disable_msi(ha->pdev);
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003019 } else
3020 free_irq(ha->pdev->irq, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003021}
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003022
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003023
3024int qla25xx_request_irq(struct rsp_que *rsp)
3025{
3026 struct qla_hw_data *ha = rsp->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003027 struct qla_init_msix_entry *intr = &msix_entries[2];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003028 struct qla_msix_entry *msix = rsp->msix;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003029 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003030 int ret;
3031
3032 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
3033 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003034 ql_log(ql_log_fatal, vha, 0x00e6,
3035 "MSI-X: Unable to register handler -- %x/%d.\n",
3036 msix->vector, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003037 return ret;
3038 }
3039 msix->have_irq = 1;
3040 msix->rsp = rsp;
3041 return ret;
3042}