blob: 9bc86b9e86b172145443d161e0715658df6acdc7 [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);
Chad Dupuisf3ddac12013-10-30 03:38:16 -040059 /* Check for PCI disconnection */
60 if (hccr == 0xffff) {
61 /*
62 * Schedule this on the default system workqueue so that
63 * all the adapter workqueues and the DPC thread can be
64 * shutdown cleanly.
65 */
66 schedule_work(&ha->board_disable);
67 break;
68 }
Seokmann Ju14e660e2007-09-20 14:07:36 -070069 if (hccr & HCCR_RISC_PAUSE) {
70 if (pci_channel_offline(ha->pdev))
71 break;
72
73 /*
74 * Issue a "HARD" reset in order for the RISC interrupt
Justin P. Mattocka06a0f82011-06-23 23:22:27 -070075 * bit to be cleared. Schedule a big hammer to get
Seokmann Ju14e660e2007-09-20 14:07:36 -070076 * out of the RISC PAUSED state.
77 */
78 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
79 RD_REG_WORD(&reg->hccr);
80
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080081 ha->isp_ops->fw_dump(vha, 1);
82 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -070083 break;
84 } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 break;
86
87 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
88 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
89 RD_REG_WORD(&reg->hccr);
90
91 /* Get mailbox data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -070092 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
93 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080094 qla2x00_mbx_completion(vha, mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 status |= MBX_INTERRUPT;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070096 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
97 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
98 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
99 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800100 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 } else {
102 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700103 ql_dbg(ql_dbg_async, vha, 0x5025,
104 "Unrecognized interrupt type (%d).\n",
105 mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 }
107 /* Release mailbox registers. */
108 WRT_REG_WORD(&reg->semaphore, 0);
109 RD_REG_WORD(&reg->semaphore);
110 } else {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800111 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
114 RD_REG_WORD(&reg->hccr);
115 }
116 }
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -0700117 qla2x00_handle_mbx_completion(ha, status);
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700118 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 return (IRQ_HANDLED);
121}
122
Chad Dupuisf3ddac12013-10-30 03:38:16 -0400123bool
124qla2x00_check_reg_for_disconnect(scsi_qla_host_t *vha, uint32_t reg)
125{
126 /* Check for PCI disconnection */
127 if (reg == 0xffffffff) {
128 /*
129 * Schedule this on the default system workqueue so that all the
130 * adapter workqueues and the DPC thread can be shutdown
131 * cleanly.
132 */
133 schedule_work(&vha->hw->board_disable);
134 return true;
135 } else
136 return false;
137}
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139/**
140 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
141 * @irq:
142 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 *
144 * Called by system whenever the host adapter generates an interrupt.
145 *
146 * Returns handled flag.
147 */
148irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100149qla2300_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800151 scsi_qla_host_t *vha;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700152 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 unsigned long iter;
155 uint32_t stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700157 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800158 struct rsp_que *rsp;
159 struct qla_hw_data *ha;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700160 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800162 rsp = (struct rsp_que *) dev_id;
163 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -0800164 ql_log(ql_log_info, NULL, 0x5058,
165 "%s: NULL response queue pointer.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 return (IRQ_NONE);
167 }
168
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800169 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700170 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 status = 0;
172
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700173 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700174 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 for (iter = 50; iter--; ) {
176 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
Chad Dupuisf3ddac12013-10-30 03:38:16 -0400177 if (qla2x00_check_reg_for_disconnect(vha, stat))
178 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 if (stat & HSR_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800180 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -0700181 break;
182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 hccr = RD_REG_WORD(&reg->hccr);
Chad Dupuisf3ddac12013-10-30 03:38:16 -0400184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700186 ql_log(ql_log_warn, vha, 0x5026,
187 "Parity error -- HCCR=%x, Dumping "
188 "firmware.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700190 ql_log(ql_log_warn, vha, 0x5027,
191 "RISC paused -- HCCR=%x, Dumping "
192 "firmware.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194 /*
195 * Issue a "HARD" reset in order for the RISC
196 * interrupt bit to be cleared. Schedule a big
Justin P. Mattocka06a0f82011-06-23 23:22:27 -0700197 * hammer to get out of the RISC PAUSED state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 */
199 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
200 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800201
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800202 ha->isp_ops->fw_dump(vha, 1);
203 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 break;
205 } else if ((stat & HSR_RISC_INT) == 0)
206 break;
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 case 0x1:
210 case 0x2:
211 case 0x10:
212 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800213 qla2x00_mbx_completion(vha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 status |= MBX_INTERRUPT;
215
216 /* Release mailbox registers. */
217 WRT_REG_WORD(&reg->semaphore, 0);
218 break;
219 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700220 mb[0] = MSW(stat);
221 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
222 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
223 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800224 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700225 break;
226 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800227 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 break;
229 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700230 mb[0] = MBA_CMPLT_1_16BIT;
231 mb[1] = MSW(stat);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800232 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 break;
234 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700235 mb[0] = MBA_SCSI_COMPLETION;
236 mb[1] = MSW(stat);
237 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800238 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 break;
240 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700241 ql_dbg(ql_dbg_async, vha, 0x5028,
242 "Unrecognized interrupt type (%d).\n", stat & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 break;
244 }
245 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
246 RD_REG_WORD_RELAXED(&reg->hccr);
247 }
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -0700248 qla2x00_handle_mbx_completion(ha, status);
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700249 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 return (IRQ_HANDLED);
252}
253
254/**
255 * qla2x00_mbx_completion() - Process mailbox command completions.
256 * @ha: SCSI driver HA context
257 * @mb0: Mailbox0 register
258 */
259static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800260qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261{
262 uint16_t cnt;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800263 uint32_t mboxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800265 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700266 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800268 /* Read all mbox registers? */
269 mboxes = (1 << ha->mbx_count) - 1;
270 if (!ha->mcp)
Masanari Iidaa7201012012-11-21 02:40:42 -0500271 ql_dbg(ql_dbg_async, vha, 0x5001, "MBX pointer ERROR.\n");
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800272 else
273 mboxes = ha->mcp->in_mb;
274
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 /* Load return mailbox registers. */
276 ha->flags.mbox_int = 1;
277 ha->mailbox_out[0] = mb0;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800278 mboxes >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
280
281 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700282 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800284 if ((cnt == 4 || cnt == 5) && (mboxes & BIT_0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800286 else if (mboxes & BIT_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 wptr++;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800290 mboxes >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292}
293
Andrew Vasquez8a659572009-02-08 20:50:12 -0800294static void
295qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
296{
297 static char *event[] =
298 { "Complete", "Request Notification", "Time Extension" };
299 int rval;
300 struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
Chad Dupuis9e5054e2013-10-30 03:38:23 -0400301 struct device_reg_82xx __iomem *reg82 = &vha->hw->iobase->isp82;
Andrew Vasquez8a659572009-02-08 20:50:12 -0800302 uint16_t __iomem *wptr;
303 uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
304
305 /* Seed data -- mailbox1 -> mailbox7. */
Chad Dupuis9e5054e2013-10-30 03:38:23 -0400306 if (IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw))
307 wptr = (uint16_t __iomem *)&reg24->mailbox1;
308 else if (IS_QLA8044(vha->hw))
309 wptr = (uint16_t __iomem *)&reg82->mailbox_out[1];
310 else
311 return;
312
Andrew Vasquez8a659572009-02-08 20:50:12 -0800313 for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
314 mb[cnt] = RD_REG_WORD(wptr);
315
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700316 ql_dbg(ql_dbg_async, vha, 0x5021,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800317 "Inter-Driver Communication %s -- "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700318 "%04x %04x %04x %04x %04x %04x %04x.\n",
319 event[aen & 0xff], mb[0], mb[1], mb[2], mb[3],
320 mb[4], mb[5], mb[6]);
Santosh Vernekar454073c2013-08-27 01:37:48 -0400321 switch (aen) {
322 /* Handle IDC Error completion case. */
323 case MBA_IDC_COMPLETE:
324 if (mb[1] >> 15) {
325 vha->hw->flags.idc_compl_status = 1;
Chad Dupuis9aaf2ce2013-10-30 03:38:25 -0400326 if (vha->hw->notify_dcbx_comp && !vha->vp_idx)
Santosh Vernekar454073c2013-08-27 01:37:48 -0400327 complete(&vha->hw->dcbx_comp);
328 }
329 break;
330
331 case MBA_IDC_NOTIFY:
332 /* Acknowledgement needed? [Notify && non-zero timeout]. */
333 timeout = (descr >> 8) & 0xf;
334 ql_dbg(ql_dbg_async, vha, 0x5022,
335 "%lu Inter-Driver Communication %s -- ACK timeout=%d.\n",
336 vha->host_no, event[aen & 0xff], timeout);
337
338 if (!timeout)
339 return;
340 rval = qla2x00_post_idc_ack_work(vha, mb);
341 if (rval != QLA_SUCCESS)
342 ql_log(ql_log_warn, vha, 0x5023,
343 "IDC failed to post ACK.\n");
344 break;
345 case MBA_IDC_TIME_EXT:
346 vha->hw->idc_extend_tmo = descr;
347 ql_dbg(ql_dbg_async, vha, 0x5087,
348 "%lu Inter-Driver Communication %s -- "
349 "Extend timeout by=%d.\n",
350 vha->host_no, event[aen & 0xff], vha->hw->idc_extend_tmo);
351 break;
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400352 }
Andrew Vasquez8a659572009-02-08 20:50:12 -0800353}
354
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400355#define LS_UNKNOWN 2
Joe Carnucciod0297c92012-11-21 02:40:40 -0500356const char *
357qla2x00_get_link_speed_str(struct qla_hw_data *ha, uint16_t speed)
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400358{
Joe Carnucciod0297c92012-11-21 02:40:40 -0500359 static const char * const link_speeds[] = {
360 "1", "2", "?", "4", "8", "16", "10"
361 };
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400362
363 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Joe Carnucciod0297c92012-11-21 02:40:40 -0500364 return link_speeds[0];
365 else if (speed == 0x13)
366 return link_speeds[6];
367 else if (speed < 6)
368 return link_speeds[speed];
369 else
370 return link_speeds[LS_UNKNOWN];
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400371}
372
Saurav Kashyapfa492632012-11-21 02:40:29 -0500373static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400374qla83xx_handle_8200_aen(scsi_qla_host_t *vha, uint16_t *mb)
375{
376 struct qla_hw_data *ha = vha->hw;
377
378 /*
379 * 8200 AEN Interpretation:
380 * mb[0] = AEN code
381 * mb[1] = AEN Reason code
382 * mb[2] = LSW of Peg-Halt Status-1 Register
383 * mb[6] = MSW of Peg-Halt Status-1 Register
384 * mb[3] = LSW of Peg-Halt Status-2 register
385 * mb[7] = MSW of Peg-Halt Status-2 register
386 * mb[4] = IDC Device-State Register value
387 * mb[5] = IDC Driver-Presence Register value
388 */
389 ql_dbg(ql_dbg_async, vha, 0x506b, "AEN Code: mb[0] = 0x%x AEN reason: "
390 "mb[1] = 0x%x PH-status1: mb[2] = 0x%x PH-status1: mb[6] = 0x%x.\n",
391 mb[0], mb[1], mb[2], mb[6]);
392 ql_dbg(ql_dbg_async, vha, 0x506c, "PH-status2: mb[3] = 0x%x "
393 "PH-status2: mb[7] = 0x%x Device-State: mb[4] = 0x%x "
394 "Drv-Presence: mb[5] = 0x%x.\n", mb[3], mb[7], mb[4], mb[5]);
395
396 if (mb[1] & (IDC_PEG_HALT_STATUS_CHANGE | IDC_NIC_FW_REPORTED_FAILURE |
397 IDC_HEARTBEAT_FAILURE)) {
398 ha->flags.nic_core_hung = 1;
399 ql_log(ql_log_warn, vha, 0x5060,
400 "83XX: F/W Error Reported: Check if reset required.\n");
401
402 if (mb[1] & IDC_PEG_HALT_STATUS_CHANGE) {
403 uint32_t protocol_engine_id, fw_err_code, err_level;
404
405 /*
406 * IDC_PEG_HALT_STATUS_CHANGE interpretation:
407 * - PEG-Halt Status-1 Register:
408 * (LSW = mb[2], MSW = mb[6])
409 * Bits 0-7 = protocol-engine ID
410 * Bits 8-28 = f/w error code
411 * Bits 29-31 = Error-level
412 * Error-level 0x1 = Non-Fatal error
413 * Error-level 0x2 = Recoverable Fatal error
414 * Error-level 0x4 = UnRecoverable Fatal error
415 * - PEG-Halt Status-2 Register:
416 * (LSW = mb[3], MSW = mb[7])
417 */
418 protocol_engine_id = (mb[2] & 0xff);
419 fw_err_code = (((mb[2] & 0xff00) >> 8) |
420 ((mb[6] & 0x1fff) << 8));
421 err_level = ((mb[6] & 0xe000) >> 13);
422 ql_log(ql_log_warn, vha, 0x5061, "PegHalt Status-1 "
423 "Register: protocol_engine_id=0x%x "
424 "fw_err_code=0x%x err_level=0x%x.\n",
425 protocol_engine_id, fw_err_code, err_level);
426 ql_log(ql_log_warn, vha, 0x5062, "PegHalt Status-2 "
427 "Register: 0x%x%x.\n", mb[7], mb[3]);
428 if (err_level == ERR_LEVEL_NON_FATAL) {
429 ql_log(ql_log_warn, vha, 0x5063,
430 "Not a fatal error, f/w has recovered "
431 "iteself.\n");
432 } else if (err_level == ERR_LEVEL_RECOVERABLE_FATAL) {
433 ql_log(ql_log_fatal, vha, 0x5064,
434 "Recoverable Fatal error: Chip reset "
435 "required.\n");
436 qla83xx_schedule_work(vha,
437 QLA83XX_NIC_CORE_RESET);
438 } else if (err_level == ERR_LEVEL_UNRECOVERABLE_FATAL) {
439 ql_log(ql_log_fatal, vha, 0x5065,
440 "Unrecoverable Fatal error: Set FAILED "
441 "state, reboot required.\n");
442 qla83xx_schedule_work(vha,
443 QLA83XX_NIC_CORE_UNRECOVERABLE);
444 }
445 }
446
447 if (mb[1] & IDC_NIC_FW_REPORTED_FAILURE) {
448 uint16_t peg_fw_state, nw_interface_link_up;
449 uint16_t nw_interface_signal_detect, sfp_status;
450 uint16_t htbt_counter, htbt_monitor_enable;
451 uint16_t sfp_additonal_info, sfp_multirate;
452 uint16_t sfp_tx_fault, link_speed, dcbx_status;
453
454 /*
455 * IDC_NIC_FW_REPORTED_FAILURE interpretation:
456 * - PEG-to-FC Status Register:
457 * (LSW = mb[2], MSW = mb[6])
458 * Bits 0-7 = Peg-Firmware state
459 * Bit 8 = N/W Interface Link-up
460 * Bit 9 = N/W Interface signal detected
461 * Bits 10-11 = SFP Status
462 * SFP Status 0x0 = SFP+ transceiver not expected
463 * SFP Status 0x1 = SFP+ transceiver not present
464 * SFP Status 0x2 = SFP+ transceiver invalid
465 * SFP Status 0x3 = SFP+ transceiver present and
466 * valid
467 * Bits 12-14 = Heartbeat Counter
468 * Bit 15 = Heartbeat Monitor Enable
469 * Bits 16-17 = SFP Additional Info
470 * SFP info 0x0 = Unregocnized transceiver for
471 * Ethernet
472 * SFP info 0x1 = SFP+ brand validation failed
473 * SFP info 0x2 = SFP+ speed validation failed
474 * SFP info 0x3 = SFP+ access error
475 * Bit 18 = SFP Multirate
476 * Bit 19 = SFP Tx Fault
477 * Bits 20-22 = Link Speed
478 * Bits 23-27 = Reserved
479 * Bits 28-30 = DCBX Status
480 * DCBX Status 0x0 = DCBX Disabled
481 * DCBX Status 0x1 = DCBX Enabled
482 * DCBX Status 0x2 = DCBX Exchange error
483 * Bit 31 = Reserved
484 */
485 peg_fw_state = (mb[2] & 0x00ff);
486 nw_interface_link_up = ((mb[2] & 0x0100) >> 8);
487 nw_interface_signal_detect = ((mb[2] & 0x0200) >> 9);
488 sfp_status = ((mb[2] & 0x0c00) >> 10);
489 htbt_counter = ((mb[2] & 0x7000) >> 12);
490 htbt_monitor_enable = ((mb[2] & 0x8000) >> 15);
491 sfp_additonal_info = (mb[6] & 0x0003);
492 sfp_multirate = ((mb[6] & 0x0004) >> 2);
493 sfp_tx_fault = ((mb[6] & 0x0008) >> 3);
494 link_speed = ((mb[6] & 0x0070) >> 4);
495 dcbx_status = ((mb[6] & 0x7000) >> 12);
496
497 ql_log(ql_log_warn, vha, 0x5066,
498 "Peg-to-Fc Status Register:\n"
499 "peg_fw_state=0x%x, nw_interface_link_up=0x%x, "
500 "nw_interface_signal_detect=0x%x"
501 "\nsfp_statis=0x%x.\n ", peg_fw_state,
502 nw_interface_link_up, nw_interface_signal_detect,
503 sfp_status);
504 ql_log(ql_log_warn, vha, 0x5067,
505 "htbt_counter=0x%x, htbt_monitor_enable=0x%x, "
506 "sfp_additonal_info=0x%x, sfp_multirate=0x%x.\n ",
507 htbt_counter, htbt_monitor_enable,
508 sfp_additonal_info, sfp_multirate);
509 ql_log(ql_log_warn, vha, 0x5068,
510 "sfp_tx_fault=0x%x, link_state=0x%x, "
511 "dcbx_status=0x%x.\n", sfp_tx_fault, link_speed,
512 dcbx_status);
513
514 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
515 }
516
517 if (mb[1] & IDC_HEARTBEAT_FAILURE) {
518 ql_log(ql_log_warn, vha, 0x5069,
519 "Heartbeat Failure encountered, chip reset "
520 "required.\n");
521
522 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
523 }
524 }
525
526 if (mb[1] & IDC_DEVICE_STATE_CHANGE) {
527 ql_log(ql_log_info, vha, 0x506a,
528 "IDC Device-State changed = 0x%x.\n", mb[4]);
Saurav Kashyap6c3943c2013-02-08 01:58:02 -0500529 if (ha->flags.nic_core_reset_owner)
530 return;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400531 qla83xx_schedule_work(vha, MBA_IDC_AEN);
532 }
533}
534
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -0500535int
536qla2x00_is_a_vp_did(scsi_qla_host_t *vha, uint32_t rscn_entry)
537{
538 struct qla_hw_data *ha = vha->hw;
539 scsi_qla_host_t *vp;
540 uint32_t vp_did;
541 unsigned long flags;
542 int ret = 0;
543
544 if (!ha->num_vhosts)
545 return ret;
546
547 spin_lock_irqsave(&ha->vport_slock, flags);
548 list_for_each_entry(vp, &ha->vp_list, list) {
549 vp_did = vp->d_id.b24;
550 if (vp_did == rscn_entry) {
551 ret = 1;
552 break;
553 }
554 }
555 spin_unlock_irqrestore(&ha->vport_slock, flags);
556
557 return ret;
558}
559
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560/**
561 * qla2x00_async_event() - Process aynchronous events.
562 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700563 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700565void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800566qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 uint16_t handle_cnt;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700569 uint16_t cnt, mbx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 uint32_t handles[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800571 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700572 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700573 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
Andrew Vasquezbc5c2aa2010-12-21 16:00:24 -0800574 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 uint32_t rscn_entry, host_pid;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700576 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 /* Setup to process RIO completion. */
579 handle_cnt = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800580 if (IS_CNA_CAPABLE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800581 goto skip_rio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 switch (mb[0]) {
583 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700584 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 handle_cnt = 1;
586 break;
587 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700588 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 handle_cnt = 1;
590 mb[0] = MBA_SCSI_COMPLETION;
591 break;
592 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700593 handles[0] = mb[1];
594 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 handle_cnt = 2;
596 mb[0] = MBA_SCSI_COMPLETION;
597 break;
598 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700599 handles[0] = mb[1];
600 handles[1] = mb[2];
601 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 handle_cnt = 3;
603 mb[0] = MBA_SCSI_COMPLETION;
604 break;
605 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700606 handles[0] = mb[1];
607 handles[1] = mb[2];
608 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
610 handle_cnt = 4;
611 mb[0] = MBA_SCSI_COMPLETION;
612 break;
613 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700614 handles[0] = mb[1];
615 handles[1] = mb[2];
616 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
618 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
619 handle_cnt = 5;
620 mb[0] = MBA_SCSI_COMPLETION;
621 break;
622 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700623 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 handles[1] = le32_to_cpu(
625 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
626 RD_MAILBOX_REG(ha, reg, 6));
627 handle_cnt = 2;
628 mb[0] = MBA_SCSI_COMPLETION;
629 break;
630 default:
631 break;
632 }
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800633skip_rio:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 switch (mb[0]) {
635 case MBA_SCSI_COMPLETION: /* Fast Post */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800636 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 break;
638
639 for (cnt = 0; cnt < handle_cnt; cnt++)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800640 qla2x00_process_completed_request(vha, rsp->req,
641 handles[cnt]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 break;
643
644 case MBA_RESET: /* Reset */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700645 ql_dbg(ql_dbg_async, vha, 0x5002,
646 "Asynchronous RESET.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800648 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 break;
650
651 case MBA_SYSTEM_ERR: /* System Error */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800652 mbx = (IS_QLA81XX(ha) || IS_QLA83XX(ha)) ?
653 RD_REG_WORD(&reg24->mailbox7) : 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700654 ql_log(ql_log_warn, vha, 0x5003,
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700655 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh "
656 "mbx7=%xh.\n", mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800658 ha->isp_ops->fw_dump(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Andrew Vasqueze4289242007-07-19 15:05:56 -0700660 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700661 if (mb[1] == 0 && mb[2] == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700662 ql_log(ql_log_fatal, vha, 0x5004,
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700663 "Unrecoverable Hardware Error: adapter "
664 "marked OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800665 vha->flags.online = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800666 vha->device_flags |= DFLG_DEV_FAILED;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700667 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300668 /* Check to see if MPI timeout occurred */
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700669 if ((mbx & MBX_3) && (ha->flags.port0))
670 set_bit(MPI_RESET_NEEDED,
671 &vha->dpc_flags);
672
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800673 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700674 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700675 } else if (mb[1] == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700676 ql_log(ql_log_fatal, vha, 0x5005,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 "Unrecoverable Hardware Error: adapter marked "
678 "OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800679 vha->flags.online = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800680 vha->device_flags |= DFLG_DEV_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800682 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 break;
684
685 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700686 ql_log(ql_log_warn, vha, 0x5006,
687 "ISP Request Transfer Error (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800689 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 break;
691
692 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700693 ql_log(ql_log_warn, vha, 0x5007,
694 "ISP Response Transfer Error.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800696 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 break;
698
699 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700700 ql_dbg(ql_dbg_async, vha, 0x5008,
701 "Asynchronous WAKEUP_THRES.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400703 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Chad Dupuiscfb09192011-11-18 09:03:07 -0800705 ql_dbg(ql_dbg_async, vha, 0x5009,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700706 "LIP occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800708 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
709 atomic_set(&vha->loop_state, LOOP_DOWN);
710 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
711 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 }
713
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800714 if (vha->vp_idx) {
715 atomic_set(&vha->vp_state, VP_FAILED);
716 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700717 }
718
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800719 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
720 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800722 vha->flags.management_server_logged_in = 0;
723 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 break;
725
726 case MBA_LOOP_UP: /* Loop Up Event */
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400727 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700728 ha->link_data_rate = PORT_SPEED_1GB;
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400729 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 ha->link_data_rate = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Chad Dupuiscfb09192011-11-18 09:03:07 -0800732 ql_dbg(ql_dbg_async, vha, 0x500a,
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400733 "LOOP UP detected (%s Gbps).\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -0500734 qla2x00_get_link_speed_str(ha, ha->link_data_rate));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800736 vha->flags.management_server_logged_in = 0;
737 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 break;
739
740 case MBA_LOOP_DOWN: /* Loop Down Event */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800741 mbx = (IS_QLA81XX(ha) || IS_QLA8031(ha))
742 ? RD_REG_WORD(&reg24->mailbox4) : 0;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400743 mbx = (IS_P3P_TYPE(ha)) ? RD_REG_WORD(&reg82->mailbox_out[4])
744 : mbx;
Chad Dupuiscfb09192011-11-18 09:03:07 -0800745 ql_dbg(ql_dbg_async, vha, 0x500b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700746 "LOOP DOWN detected (%x %x %x %x).\n",
747 mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800749 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
750 atomic_set(&vha->loop_state, LOOP_DOWN);
751 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
752 vha->device_flags |= DFLG_NO_CABLE;
753 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 }
755
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800756 if (vha->vp_idx) {
757 atomic_set(&vha->vp_state, VP_FAILED);
758 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700759 }
760
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800761 vha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700762 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800763 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 break;
765
766 case MBA_LIP_RESET: /* LIP reset occurred */
Chad Dupuiscfb09192011-11-18 09:03:07 -0800767 ql_dbg(ql_dbg_async, vha, 0x500c,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700768 "LIP reset occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800770 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
771 atomic_set(&vha->loop_state, LOOP_DOWN);
772 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
773 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 }
775
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800776 if (vha->vp_idx) {
777 atomic_set(&vha->vp_state, VP_FAILED);
778 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700779 }
780
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800781 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
783 ha->operating_mode = LOOP;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800784 vha->flags.management_server_logged_in = 0;
785 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 break;
787
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800788 /* case MBA_DCBX_COMPLETE: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 case MBA_POINT_TO_POINT: /* Point-to-Point */
790 if (IS_QLA2100(ha))
791 break;
792
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400793 if (IS_CNA_CAPABLE(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700794 ql_dbg(ql_dbg_async, vha, 0x500d,
795 "DCBX Completed -- %04x %04x %04x.\n",
796 mb[1], mb[2], mb[3]);
Chad Dupuis9aaf2ce2013-10-30 03:38:25 -0400797 if (ha->notify_dcbx_comp && !vha->vp_idx)
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700798 complete(&ha->dcbx_comp);
799
800 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700801 ql_dbg(ql_dbg_async, vha, 0x500e,
802 "Asynchronous P2P MODE received.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
804 /*
805 * Until there's a transition from loop down to loop up, treat
806 * this as loop down only.
807 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800808 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
809 atomic_set(&vha->loop_state, LOOP_DOWN);
810 if (!atomic_read(&vha->loop_down_timer))
811 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800813 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 }
815
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800816 if (vha->vp_idx) {
817 atomic_set(&vha->vp_state, VP_FAILED);
818 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700819 }
820
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800821 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
822 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
823
824 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
825 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800826
827 ha->flags.gpsc_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800828 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 break;
830
831 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
832 if (IS_QLA2100(ha))
833 break;
834
Chad Dupuiscfb09192011-11-18 09:03:07 -0800835 ql_dbg(ql_dbg_async, vha, 0x500f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 "Configuration change detected: value=%x.\n", mb[1]);
837
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800838 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
839 atomic_set(&vha->loop_state, LOOP_DOWN);
840 if (!atomic_read(&vha->loop_down_timer))
841 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800843 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 }
845
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800846 if (vha->vp_idx) {
847 atomic_set(&vha->vp_state, VP_FAILED);
848 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700849 }
850
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800851 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
852 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 break;
854
855 case MBA_PORT_UPDATE: /* Port database update */
Santosh Vernekar55903b92009-07-31 15:09:25 -0700856 /*
857 * Handle only global and vn-port update events
858 *
859 * Relevant inputs:
860 * mb[1] = N_Port handle of changed port
861 * OR 0xffff for global event
862 * mb[2] = New login state
863 * 7 = Port logged out
864 * mb[3] = LSB is vp_idx, 0xff = all vps
865 *
866 * Skip processing if:
867 * Event is global, vp_idx is NOT all vps,
868 * vp_idx does not match
869 * Event is not global, vp_idx does not match
870 */
Andrew Vasquez12cec63e42010-03-19 16:59:17 -0700871 if (IS_QLA2XXX_MIDTYPE(ha) &&
872 ((mb[1] == 0xffff && (mb[3] & 0xff) != 0xff) ||
873 (mb[1] != 0xffff)) && vha->vp_idx != (mb[3] & 0xff))
874 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800875
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700876 /* Global event -- port logout or port unavailable. */
877 if (mb[1] == 0xffff && mb[2] == 0x7) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700878 ql_dbg(ql_dbg_async, vha, 0x5010,
879 "Port unavailable %04x %04x %04x.\n",
880 mb[1], mb[2], mb[3]);
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400881 ql_log(ql_log_warn, vha, 0x505e,
882 "Link is offline.\n");
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700883
884 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
885 atomic_set(&vha->loop_state, LOOP_DOWN);
886 atomic_set(&vha->loop_down_timer,
887 LOOP_DOWN_TIME);
888 vha->device_flags |= DFLG_NO_CABLE;
889 qla2x00_mark_all_devices_lost(vha, 1);
890 }
891
892 if (vha->vp_idx) {
893 atomic_set(&vha->vp_state, VP_FAILED);
894 fc_vport_set_state(vha->fc_vport,
895 FC_VPORT_FAILED);
Santosh Vernekarfaadc5e2009-07-31 15:09:26 -0700896 qla2x00_mark_all_devices_lost(vha, 1);
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700897 }
898
899 vha->flags.management_server_logged_in = 0;
900 ha->link_data_rate = PORT_SPEED_UNKNOWN;
901 break;
902 }
903
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 /*
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700905 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 * event etc. earlier indicating loop is down) then process
907 * it. Otherwise ignore it and Wait for RSCN to come in.
908 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800909 atomic_set(&vha->loop_down_timer, 0);
Chad Dupuis79cc7852012-08-22 14:21:09 -0400910 if (mb[1] != 0xffff || (mb[2] != 0x6 && mb[2] != 0x4)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700911 ql_dbg(ql_dbg_async, vha, 0x5011,
912 "Asynchronous PORT UPDATE ignored %04x/%04x/%04x.\n",
913 mb[1], mb[2], mb[3]);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400914
915 qlt_async_event(mb[0], vha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 break;
917 }
918
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700919 ql_dbg(ql_dbg_async, vha, 0x5012,
920 "Port database changed %04x %04x %04x.\n",
921 mb[1], mb[2], mb[3]);
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400922 ql_log(ql_log_warn, vha, 0x505f,
923 "Link is operational (%s Gbps).\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -0500924 qla2x00_get_link_speed_str(ha, ha->link_data_rate));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
926 /*
927 * Mark all devices as missing so we will login again.
928 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800929 atomic_set(&vha->loop_state, LOOP_UP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800931 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400933 if (vha->vp_idx == 0 && !qla_ini_mode_enabled(vha))
934 set_bit(SCR_PENDING, &vha->dpc_flags);
935
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800936 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
937 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400938
939 qlt_async_event(mb[0], vha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 break;
941
942 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju3c397402008-05-19 14:25:39 -0700943 /* Check if the Vport has issued a SCR */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800944 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
Seokmann Ju3c397402008-05-19 14:25:39 -0700945 break;
946 /* Only handle SCNs for our Vport index. */
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700947 if (ha->flags.npiv_supported && vha->vp_idx != (mb[3] & 0xff))
Seokmann Ju3c397402008-05-19 14:25:39 -0700948 break;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700949
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700950 ql_dbg(ql_dbg_async, vha, 0x5013,
951 "RSCN database changed -- %04x %04x %04x.\n",
952 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
Ravi Anand59d72d82008-09-11 21:22:53 -0700954 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800955 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
956 | vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 if (rscn_entry == host_pid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700958 ql_dbg(ql_dbg_async, vha, 0x5014,
959 "Ignoring RSCN update to local host "
960 "port ID (%06x).\n", host_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 break;
962 }
963
Ravi Anand59d72d82008-09-11 21:22:53 -0700964 /* Ignore reserved bits from RSCN-payload. */
965 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -0500967 /* Skip RSCNs for virtual ports on the same physical port */
968 if (qla2x00_is_a_vp_did(vha, rscn_entry))
969 break;
970
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800971 atomic_set(&vha->loop_down_timer, 0);
972 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800974 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
975 set_bit(RSCN_UPDATE, &vha->dpc_flags);
976 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 break;
978
979 /* case MBA_RIO_RESPONSE: */
980 case MBA_ZIO_RESPONSE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700981 ql_dbg(ql_dbg_async, vha, 0x5015,
982 "[R|Z]IO update completion.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Andrew Vasqueze4289242007-07-19 15:05:56 -0700984 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700985 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700986 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800987 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700989
990 case MBA_DISCARD_RND_FRAME:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700991 ql_dbg(ql_dbg_async, vha, 0x5016,
992 "Discard RND Frame -- %04x %04x %04x.\n",
993 mb[1], mb[2], mb[3]);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700994 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700995
996 case MBA_TRACE_NOTIFICATION:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700997 ql_dbg(ql_dbg_async, vha, 0x5017,
998 "Trace Notification -- %04x %04x.\n", mb[1], mb[2]);
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700999 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001000
1001 case MBA_ISP84XX_ALERT:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001002 ql_dbg(ql_dbg_async, vha, 0x5018,
1003 "ISP84XX Alert Notification -- %04x %04x %04x.\n",
1004 mb[1], mb[2], mb[3]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001005
1006 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
1007 switch (mb[1]) {
1008 case A84_PANIC_RECOVERY:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001009 ql_log(ql_log_info, vha, 0x5019,
1010 "Alert 84XX: panic recovery %04x %04x.\n",
1011 mb[2], mb[3]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001012 break;
1013 case A84_OP_LOGIN_COMPLETE:
1014 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001015 ql_log(ql_log_info, vha, 0x501a,
1016 "Alert 84XX: firmware version %x.\n",
1017 ha->cs84xx->op_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001018 break;
1019 case A84_DIAG_LOGIN_COMPLETE:
1020 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001021 ql_log(ql_log_info, vha, 0x501b,
1022 "Alert 84XX: diagnostic firmware version %x.\n",
1023 ha->cs84xx->diag_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001024 break;
1025 case A84_GOLD_LOGIN_COMPLETE:
1026 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
1027 ha->cs84xx->fw_update = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001028 ql_log(ql_log_info, vha, 0x501c,
1029 "Alert 84XX: gold firmware version %x.\n",
1030 ha->cs84xx->gold_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001031 break;
1032 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001033 ql_log(ql_log_warn, vha, 0x501d,
1034 "Alert 84xx: Invalid Alert %04x %04x %04x.\n",
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001035 mb[1], mb[2], mb[3]);
1036 }
1037 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
1038 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001039 case MBA_DCBX_START:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001040 ql_dbg(ql_dbg_async, vha, 0x501e,
1041 "DCBX Started -- %04x %04x %04x.\n",
1042 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001043 break;
1044 case MBA_DCBX_PARAM_UPDATE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001045 ql_dbg(ql_dbg_async, vha, 0x501f,
1046 "DCBX Parameters Updated -- %04x %04x %04x.\n",
1047 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001048 break;
1049 case MBA_FCF_CONF_ERR:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001050 ql_dbg(ql_dbg_async, vha, 0x5020,
1051 "FCF Configuration Error -- %04x %04x %04x.\n",
1052 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001053 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001054 case MBA_IDC_NOTIFY:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001055 if (IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
Chad Dupuis67b2a312013-02-08 01:57:51 -05001056 mb[4] = RD_REG_WORD(&reg24->mailbox4);
1057 if (((mb[2] & 0x7fff) == MBC_PORT_RESET ||
1058 (mb[2] & 0x7fff) == MBC_SET_PORT_CONFIG) &&
1059 (mb[4] & INTERNAL_LOOPBACK_MASK) != 0) {
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04001060 set_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags);
Chad Dupuis67b2a312013-02-08 01:57:51 -05001061 /*
1062 * Extend loop down timer since port is active.
1063 */
1064 if (atomic_read(&vha->loop_state) == LOOP_DOWN)
1065 atomic_set(&vha->loop_down_timer,
1066 LOOP_DOWN_TIME);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04001067 qla2xxx_wake_dpc(vha);
1068 }
Chad Dupuis67b2a312013-02-08 01:57:51 -05001069 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04001070 case MBA_IDC_COMPLETE:
Chad Dupuis9aaf2ce2013-10-30 03:38:25 -04001071 if (ha->notify_lb_portup_comp && !vha->vp_idx)
Chad Dupuisf356bef2013-02-08 01:58:04 -05001072 complete(&ha->lb_portup_comp);
1073 /* Fallthru */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001074 case MBA_IDC_TIME_EXT:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001075 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) ||
1076 IS_QLA8044(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001077 qla81xx_idc_event(vha, mb[0], mb[1]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001078 break;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001079
1080 case MBA_IDC_AEN:
1081 mb[4] = RD_REG_WORD(&reg24->mailbox4);
1082 mb[5] = RD_REG_WORD(&reg24->mailbox5);
1083 mb[6] = RD_REG_WORD(&reg24->mailbox6);
1084 mb[7] = RD_REG_WORD(&reg24->mailbox7);
1085 qla83xx_handle_8200_aen(vha, mb);
1086 break;
1087
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001088 default:
1089 ql_dbg(ql_dbg_async, vha, 0x5057,
1090 "Unknown AEN:%04x %04x %04x %04x\n",
1091 mb[0], mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001093
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001094 qlt_async_event(mb[0], vha, mb);
1095
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001096 if (!vha->vp_idx && ha->num_vhosts)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001097 qla2x00_alert_all_vps(rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098}
1099
1100/**
1101 * qla2x00_process_completed_request() - Process a Fast Post response.
1102 * @ha: SCSI driver HA context
1103 * @index: SRB index
1104 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001105void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001106qla2x00_process_completed_request(struct scsi_qla_host *vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001107 struct req_que *req, uint32_t index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108{
1109 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001110 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
1112 /* Validate handle. */
Chad Dupuis8d93f552013-01-30 03:34:37 -05001113 if (index >= req->num_outstanding_cmds) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001114 ql_log(ql_log_warn, vha, 0x3014,
1115 "Invalid SCSI command index (%x).\n", index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001117 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001118 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1119 else
1120 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 return;
1122 }
1123
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001124 sp = req->outstanding_cmds[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 if (sp) {
1126 /* Free outstanding command slot. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001127 req->outstanding_cmds[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 /* Save ISP completion status */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001130 sp->done(ha, sp, DID_OK << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001132 ql_log(ql_log_warn, vha, 0x3016, "Invalid SCSI SRB.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001134 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001135 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1136 else
1137 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 }
1139}
1140
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001141srb_t *
Andrew Vasquezac280b62009-08-20 11:06:05 -07001142qla2x00_get_sp_from_handle(scsi_qla_host_t *vha, const char *func,
1143 struct req_que *req, void *iocb)
1144{
1145 struct qla_hw_data *ha = vha->hw;
1146 sts_entry_t *pkt = iocb;
1147 srb_t *sp = NULL;
1148 uint16_t index;
1149
1150 index = LSW(pkt->handle);
Chad Dupuis8d93f552013-01-30 03:34:37 -05001151 if (index >= req->num_outstanding_cmds) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001152 ql_log(ql_log_warn, vha, 0x5031,
1153 "Invalid command index (%x).\n", index);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001154 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001155 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1156 else
1157 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001158 goto done;
1159 }
1160 sp = req->outstanding_cmds[index];
1161 if (!sp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001162 ql_log(ql_log_warn, vha, 0x5032,
1163 "Invalid completion handle (%x) -- timed-out.\n", index);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001164 return sp;
1165 }
1166 if (sp->handle != index) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001167 ql_log(ql_log_warn, vha, 0x5033,
1168 "SRB handle (%x) mismatch %x.\n", sp->handle, index);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001169 return NULL;
1170 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001171
Andrew Vasquezac280b62009-08-20 11:06:05 -07001172 req->outstanding_cmds[index] = NULL;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001173
Andrew Vasquezac280b62009-08-20 11:06:05 -07001174done:
1175 return sp;
1176}
1177
1178static void
1179qla2x00_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1180 struct mbx_entry *mbx)
1181{
1182 const char func[] = "MBX-IOCB";
1183 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001184 fc_port_t *fcport;
1185 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001186 struct srb_iocb *lio;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001187 uint16_t *data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001188 uint16_t status;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001189
1190 sp = qla2x00_get_sp_from_handle(vha, func, req, mbx);
1191 if (!sp)
1192 return;
1193
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001194 lio = &sp->u.iocb_cmd;
1195 type = sp->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001196 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001197 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001198
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001199 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001200 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001201 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001202 if (mbx->entry_status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001203 ql_dbg(ql_dbg_async, vha, 0x5043,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001204 "Async-%s error entry - hdl=%x portid=%02x%02x%02x "
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001205 "entry-status=%x status=%x state-flag=%x "
Chad Dupuiscfb09192011-11-18 09:03:07 -08001206 "status-flags=%x.\n", type, sp->handle,
1207 fcport->d_id.b.domain, fcport->d_id.b.area,
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001208 fcport->d_id.b.al_pa, mbx->entry_status,
1209 le16_to_cpu(mbx->status), le16_to_cpu(mbx->state_flags),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001210 le16_to_cpu(mbx->status_flags));
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001211
Chad Dupuiscfb09192011-11-18 09:03:07 -08001212 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5029,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001213 (uint8_t *)mbx, sizeof(*mbx));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001214
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001215 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001216 }
1217
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001218 status = le16_to_cpu(mbx->status);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001219 if (status == 0x30 && sp->type == SRB_LOGIN_CMD &&
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001220 le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE)
1221 status = 0;
1222 if (!status && le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001223 ql_dbg(ql_dbg_async, vha, 0x5045,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001224 "Async-%s complete - hdl=%x portid=%02x%02x%02x mbx1=%x.\n",
1225 type, sp->handle, fcport->d_id.b.domain,
1226 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1227 le16_to_cpu(mbx->mb1));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001228
1229 data[0] = MBS_COMMAND_COMPLETE;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001230 if (sp->type == SRB_LOGIN_CMD) {
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001231 fcport->port_type = FCT_TARGET;
1232 if (le16_to_cpu(mbx->mb1) & BIT_0)
1233 fcport->port_type = FCT_INITIATOR;
Andrew Vasquez6ac52602010-05-28 15:08:19 -07001234 else if (le16_to_cpu(mbx->mb1) & BIT_1)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001235 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001236 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001237 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001238 }
1239
1240 data[0] = le16_to_cpu(mbx->mb0);
1241 switch (data[0]) {
1242 case MBS_PORT_ID_USED:
1243 data[1] = le16_to_cpu(mbx->mb1);
1244 break;
1245 case MBS_LOOP_ID_USED:
1246 break;
1247 default:
1248 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001249 break;
1250 }
1251
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001252 ql_log(ql_log_warn, vha, 0x5046,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001253 "Async-%s failed - hdl=%x portid=%02x%02x%02x status=%x "
1254 "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n", type, sp->handle,
1255 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
1256 status, le16_to_cpu(mbx->mb0), le16_to_cpu(mbx->mb1),
Andrew Vasquezac280b62009-08-20 11:06:05 -07001257 le16_to_cpu(mbx->mb2), le16_to_cpu(mbx->mb6),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001258 le16_to_cpu(mbx->mb7));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001259
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001260logio_done:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001261 sp->done(vha, sp, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001262}
1263
1264static void
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001265qla2x00_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1266 sts_entry_t *pkt, int iocb_type)
1267{
1268 const char func[] = "CT_IOCB";
1269 const char *type;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001270 srb_t *sp;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001271 struct fc_bsg_job *bsg_job;
1272 uint16_t comp_status;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001273 int res;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001274
1275 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1276 if (!sp)
1277 return;
1278
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001279 bsg_job = sp->u.bsg_job;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001280
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001281 type = "ct pass-through";
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001282
1283 comp_status = le16_to_cpu(pkt->comp_status);
1284
1285 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1286 * fc payload to the caller
1287 */
1288 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1289 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1290
1291 if (comp_status != CS_COMPLETE) {
1292 if (comp_status == CS_DATA_UNDERRUN) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001293 res = DID_OK << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001294 bsg_job->reply->reply_payload_rcv_len =
1295 le16_to_cpu(((sts_entry_t *)pkt)->rsp_info_len);
1296
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001297 ql_log(ql_log_warn, vha, 0x5048,
1298 "CT pass-through-%s error "
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001299 "comp_status-status=0x%x total_byte = 0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001300 type, comp_status,
1301 bsg_job->reply->reply_payload_rcv_len);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001302 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001303 ql_log(ql_log_warn, vha, 0x5049,
1304 "CT pass-through-%s error "
1305 "comp_status-status=0x%x.\n", type, comp_status);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001306 res = DID_ERROR << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001307 bsg_job->reply->reply_payload_rcv_len = 0;
1308 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001309 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5035,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001310 (uint8_t *)pkt, sizeof(*pkt));
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001311 } else {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001312 res = DID_OK << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001313 bsg_job->reply->reply_payload_rcv_len =
1314 bsg_job->reply_payload.payload_len;
1315 bsg_job->reply_len = 0;
1316 }
1317
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001318 sp->done(vha, sp, res);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001319}
1320
1321static void
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001322qla24xx_els_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1323 struct sts_entry_24xx *pkt, int iocb_type)
1324{
1325 const char func[] = "ELS_CT_IOCB";
1326 const char *type;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001327 srb_t *sp;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001328 struct fc_bsg_job *bsg_job;
1329 uint16_t comp_status;
1330 uint32_t fw_status[3];
1331 uint8_t* fw_sts_ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001332 int res;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001333
1334 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1335 if (!sp)
1336 return;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001337 bsg_job = sp->u.bsg_job;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001338
1339 type = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001340 switch (sp->type) {
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001341 case SRB_ELS_CMD_RPT:
1342 case SRB_ELS_CMD_HST:
1343 type = "els";
1344 break;
1345 case SRB_CT_CMD:
1346 type = "ct pass-through";
1347 break;
1348 default:
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001349 ql_dbg(ql_dbg_user, vha, 0x503e,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001350 "Unrecognized SRB: (%p) type=%d.\n", sp, sp->type);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001351 return;
1352 }
1353
1354 comp_status = fw_status[0] = le16_to_cpu(pkt->comp_status);
1355 fw_status[1] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1);
1356 fw_status[2] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2);
1357
1358 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1359 * fc payload to the caller
1360 */
1361 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1362 bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(fw_status);
1363
1364 if (comp_status != CS_COMPLETE) {
1365 if (comp_status == CS_DATA_UNDERRUN) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001366 res = DID_OK << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001367 bsg_job->reply->reply_payload_rcv_len =
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001368 le16_to_cpu(((struct els_sts_entry_24xx *)pkt)->total_byte_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001369
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001370 ql_dbg(ql_dbg_user, vha, 0x503f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001371 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001372 "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001373 type, sp->handle, comp_status, fw_status[1], fw_status[2],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001374 le16_to_cpu(((struct els_sts_entry_24xx *)
1375 pkt)->total_byte_count));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001376 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1377 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1378 }
1379 else {
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001380 ql_dbg(ql_dbg_user, vha, 0x5040,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001381 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001382 "error subcode 1=0x%x error subcode 2=0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001383 type, sp->handle, comp_status,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001384 le16_to_cpu(((struct els_sts_entry_24xx *)
1385 pkt)->error_subcode_1),
1386 le16_to_cpu(((struct els_sts_entry_24xx *)
1387 pkt)->error_subcode_2));
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001388 res = DID_ERROR << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001389 bsg_job->reply->reply_payload_rcv_len = 0;
1390 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1391 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1392 }
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001393 ql_dump_buffer(ql_dbg_user + ql_dbg_buffer, vha, 0x5056,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001394 (uint8_t *)pkt, sizeof(*pkt));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001395 }
1396 else {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001397 res = DID_OK << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001398 bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
1399 bsg_job->reply_len = 0;
1400 }
1401
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001402 sp->done(vha, sp, res);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001403}
1404
1405static void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001406qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req,
1407 struct logio_entry_24xx *logio)
1408{
1409 const char func[] = "LOGIO-IOCB";
1410 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001411 fc_port_t *fcport;
1412 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001413 struct srb_iocb *lio;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001414 uint16_t *data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001415 uint32_t iop[2];
1416
1417 sp = qla2x00_get_sp_from_handle(vha, func, req, logio);
1418 if (!sp)
1419 return;
1420
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001421 lio = &sp->u.iocb_cmd;
1422 type = sp->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001423 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001424 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001425
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001426 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001427 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001428 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001429 if (logio->entry_status) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001430 ql_log(ql_log_warn, fcport->vha, 0x5034,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001431 "Async-%s error entry - hdl=%x"
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001432 "portid=%02x%02x%02x entry-status=%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001433 type, sp->handle, fcport->d_id.b.domain,
1434 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1435 logio->entry_status);
1436 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x504d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001437 (uint8_t *)logio, sizeof(*logio));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001438
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001439 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001440 }
1441
1442 if (le16_to_cpu(logio->comp_status) == CS_COMPLETE) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001443 ql_dbg(ql_dbg_async, fcport->vha, 0x5036,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001444 "Async-%s complete - hdl=%x portid=%02x%02x%02x "
1445 "iop0=%x.\n", type, sp->handle, fcport->d_id.b.domain,
1446 fcport->d_id.b.area, fcport->d_id.b.al_pa,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001447 le32_to_cpu(logio->io_parameter[0]));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001448
1449 data[0] = MBS_COMMAND_COMPLETE;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001450 if (sp->type != SRB_LOGIN_CMD)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001451 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001452
1453 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1454 if (iop[0] & BIT_4) {
1455 fcport->port_type = FCT_TARGET;
1456 if (iop[0] & BIT_8)
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07001457 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquezb0cd5792010-05-28 15:08:22 -07001458 } else if (iop[0] & BIT_5)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001459 fcport->port_type = FCT_INITIATOR;
Andrew Vasquezb0cd5792010-05-28 15:08:22 -07001460
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001461 if (iop[0] & BIT_7)
1462 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
1463
Andrew Vasquezac280b62009-08-20 11:06:05 -07001464 if (logio->io_parameter[7] || logio->io_parameter[8])
1465 fcport->supported_classes |= FC_COS_CLASS2;
1466 if (logio->io_parameter[9] || logio->io_parameter[10])
1467 fcport->supported_classes |= FC_COS_CLASS3;
1468
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001469 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001470 }
1471
1472 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1473 iop[1] = le32_to_cpu(logio->io_parameter[1]);
1474 switch (iop[0]) {
1475 case LSC_SCODE_PORTID_USED:
1476 data[0] = MBS_PORT_ID_USED;
1477 data[1] = LSW(iop[1]);
1478 break;
1479 case LSC_SCODE_NPORT_USED:
1480 data[0] = MBS_LOOP_ID_USED;
1481 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001482 default:
1483 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001484 break;
1485 }
1486
Arun Easi5e19ed92012-02-09 11:15:51 -08001487 ql_dbg(ql_dbg_async, fcport->vha, 0x5037,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001488 "Async-%s failed - hdl=%x portid=%02x%02x%02x comp=%x "
1489 "iop0=%x iop1=%x.\n", type, sp->handle, fcport->d_id.b.domain,
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001490 fcport->d_id.b.area, fcport->d_id.b.al_pa,
Andrew Vasquezac280b62009-08-20 11:06:05 -07001491 le16_to_cpu(logio->comp_status),
1492 le32_to_cpu(logio->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001493 le32_to_cpu(logio->io_parameter[1]));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001494
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001495logio_done:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001496 sp->done(vha, sp, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001497}
1498
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001499static void
1500qla24xx_tm_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1501 struct tsk_mgmt_entry *tsk)
1502{
1503 const char func[] = "TMF-IOCB";
1504 const char *type;
1505 fc_port_t *fcport;
1506 srb_t *sp;
1507 struct srb_iocb *iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001508 struct sts_entry_24xx *sts = (struct sts_entry_24xx *)tsk;
1509 int error = 1;
1510
1511 sp = qla2x00_get_sp_from_handle(vha, func, req, tsk);
1512 if (!sp)
1513 return;
1514
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001515 iocb = &sp->u.iocb_cmd;
1516 type = sp->name;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001517 fcport = sp->fcport;
1518
1519 if (sts->entry_status) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001520 ql_log(ql_log_warn, fcport->vha, 0x5038,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001521 "Async-%s error - hdl=%x entry-status(%x).\n",
1522 type, sp->handle, sts->entry_status);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001523 } else if (sts->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001524 ql_log(ql_log_warn, fcport->vha, 0x5039,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001525 "Async-%s error - hdl=%x completion status(%x).\n",
1526 type, sp->handle, sts->comp_status);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001527 } else if (!(le16_to_cpu(sts->scsi_status) &
1528 SS_RESPONSE_INFO_LEN_VALID)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001529 ql_log(ql_log_warn, fcport->vha, 0x503a,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001530 "Async-%s error - hdl=%x no response info(%x).\n",
1531 type, sp->handle, sts->scsi_status);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001532 } else if (le32_to_cpu(sts->rsp_data_len) < 4) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001533 ql_log(ql_log_warn, fcport->vha, 0x503b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001534 "Async-%s error - hdl=%x not enough response(%d).\n",
1535 type, sp->handle, sts->rsp_data_len);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001536 } else if (sts->data[3]) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001537 ql_log(ql_log_warn, fcport->vha, 0x503c,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001538 "Async-%s error - hdl=%x response(%x).\n",
1539 type, sp->handle, sts->data[3]);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001540 } else {
1541 error = 0;
1542 }
1543
1544 if (error) {
1545 iocb->u.tmf.data = error;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001546 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5055,
1547 (uint8_t *)sts, sizeof(*sts));
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001548 }
1549
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001550 sp->done(vha, sp, 0);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001551}
1552
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553/**
1554 * qla2x00_process_response_queue() - Process response queue entries.
1555 * @ha: SCSI driver HA context
1556 */
1557void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001558qla2x00_process_response_queue(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001560 struct scsi_qla_host *vha;
1561 struct qla_hw_data *ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001562 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 sts_entry_t *pkt;
1564 uint16_t handle_cnt;
1565 uint16_t cnt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001566
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001567 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001569 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 return;
1571
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001572 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1573 pkt = (sts_entry_t *)rsp->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001575 rsp->ring_index++;
1576 if (rsp->ring_index == rsp->length) {
1577 rsp->ring_index = 0;
1578 rsp->ring_ptr = rsp->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001580 rsp->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 }
1582
1583 if (pkt->entry_status != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001584 qla2x00_error_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1586 wmb();
1587 continue;
1588 }
1589
1590 switch (pkt->entry_type) {
1591 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001592 qla2x00_status_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 break;
1594 case STATUS_TYPE_21:
1595 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
1596 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001597 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 ((sts21_entry_t *)pkt)->handle[cnt]);
1599 }
1600 break;
1601 case STATUS_TYPE_22:
1602 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
1603 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001604 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 ((sts22_entry_t *)pkt)->handle[cnt]);
1606 }
1607 break;
1608 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001609 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001611 case MBX_IOCB_TYPE:
1612 qla2x00_mbx_iocb_entry(vha, rsp->req,
1613 (struct mbx_entry *)pkt);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001614 break;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001615 case CT_IOCB_TYPE:
1616 qla2x00_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
1617 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 default:
1619 /* Type Not Supported. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001620 ql_log(ql_log_warn, vha, 0x504a,
1621 "Received unknown response pkt type %x "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 "entry status=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001623 pkt->entry_type, pkt->entry_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 break;
1625 }
1626 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1627 wmb();
1628 }
1629
1630 /* Adjust ring index */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001631 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632}
1633
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001634static inline void
Andrew Vasquez55442132010-07-23 15:28:27 +05001635qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t par_sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001636 uint32_t sense_len, struct rsp_que *rsp, int res)
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001637{
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001638 struct scsi_qla_host *vha = sp->fcport->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001639 struct scsi_cmnd *cp = GET_CMD_SP(sp);
1640 uint32_t track_sense_len;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001641
1642 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
1643 sense_len = SCSI_SENSE_BUFFERSIZE;
1644
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001645 SET_CMD_SENSE_LEN(sp, sense_len);
1646 SET_CMD_SENSE_PTR(sp, cp->sense_buffer);
1647 track_sense_len = sense_len;
1648
1649 if (sense_len > par_sense_len)
Andrew Vasquez55442132010-07-23 15:28:27 +05001650 sense_len = par_sense_len;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001651
1652 memcpy(cp->sense_buffer, sense_data, sense_len);
1653
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001654 SET_CMD_SENSE_PTR(sp, cp->sense_buffer + sense_len);
1655 track_sense_len -= sense_len;
1656 SET_CMD_SENSE_LEN(sp, track_sense_len);
1657
1658 if (track_sense_len != 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001659 rsp->status_srb = sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001660 cp->result = res;
1661 }
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001662
Chad Dupuiscfb09192011-11-18 09:03:07 -08001663 if (sense_len) {
1664 ql_dbg(ql_dbg_io + ql_dbg_buffer, vha, 0x301c,
1665 "Check condition Sense data, nexus%ld:%d:%d cmd=%p.\n",
1666 sp->fcport->vha->host_no, cp->device->id, cp->device->lun,
1667 cp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001668 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302b,
1669 cp->sense_buffer, sense_len);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001670 }
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001671}
1672
Arun Easibad75002010-05-04 15:01:30 -07001673struct scsi_dif_tuple {
1674 __be16 guard; /* Checksum */
Masanari Iidad6a03582012-08-22 14:20:58 -04001675 __be16 app_tag; /* APPL identifier */
Arun Easibad75002010-05-04 15:01:30 -07001676 __be32 ref_tag; /* Target LBA or indirect LBA */
1677};
1678
1679/*
1680 * Checks the guard or meta-data for the type of error
1681 * detected by the HBA. In case of errors, we set the
1682 * ASC/ASCQ fields in the sense buffer with ILLEGAL_REQUEST
1683 * to indicate to the kernel that the HBA detected error.
1684 */
Arun Easi8cb20492011-08-16 11:29:22 -07001685static inline int
Arun Easibad75002010-05-04 15:01:30 -07001686qla2x00_handle_dif_error(srb_t *sp, struct sts_entry_24xx *sts24)
1687{
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001688 struct scsi_qla_host *vha = sp->fcport->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001689 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Arun Easi8cb20492011-08-16 11:29:22 -07001690 uint8_t *ap = &sts24->data[12];
1691 uint8_t *ep = &sts24->data[20];
Arun Easibad75002010-05-04 15:01:30 -07001692 uint32_t e_ref_tag, a_ref_tag;
1693 uint16_t e_app_tag, a_app_tag;
1694 uint16_t e_guard, a_guard;
1695
Arun Easi8cb20492011-08-16 11:29:22 -07001696 /*
1697 * swab32 of the "data" field in the beginning of qla2x00_status_entry()
1698 * would make guard field appear at offset 2
1699 */
1700 a_guard = le16_to_cpu(*(uint16_t *)(ap + 2));
1701 a_app_tag = le16_to_cpu(*(uint16_t *)(ap + 0));
1702 a_ref_tag = le32_to_cpu(*(uint32_t *)(ap + 4));
1703 e_guard = le16_to_cpu(*(uint16_t *)(ep + 2));
1704 e_app_tag = le16_to_cpu(*(uint16_t *)(ep + 0));
1705 e_ref_tag = le32_to_cpu(*(uint32_t *)(ep + 4));
Arun Easibad75002010-05-04 15:01:30 -07001706
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001707 ql_dbg(ql_dbg_io, vha, 0x3023,
1708 "iocb(s) %p Returned STATUS.\n", sts24);
Arun Easibad75002010-05-04 15:01:30 -07001709
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001710 ql_dbg(ql_dbg_io, vha, 0x3024,
1711 "DIF ERROR in cmd 0x%x lba 0x%llx act ref"
Arun Easibad75002010-05-04 15:01:30 -07001712 " tag=0x%x, exp ref_tag=0x%x, act app tag=0x%x, exp app"
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001713 " tag=0x%x, act guard=0x%x, exp guard=0x%x.\n",
Arun Easibad75002010-05-04 15:01:30 -07001714 cmd->cmnd[0], (u64)scsi_get_lba(cmd), a_ref_tag, e_ref_tag,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001715 a_app_tag, e_app_tag, a_guard, e_guard);
Arun Easibad75002010-05-04 15:01:30 -07001716
Arun Easi8cb20492011-08-16 11:29:22 -07001717 /*
1718 * Ignore sector if:
1719 * For type 3: ref & app tag is all 'f's
1720 * For type 0,1,2: app tag is all 'f's
1721 */
1722 if ((a_app_tag == 0xffff) &&
1723 ((scsi_get_prot_type(cmd) != SCSI_PROT_DIF_TYPE3) ||
1724 (a_ref_tag == 0xffffffff))) {
1725 uint32_t blocks_done, resid;
1726 sector_t lba_s = scsi_get_lba(cmd);
1727
1728 /* 2TB boundary case covered automatically with this */
1729 blocks_done = e_ref_tag - (uint32_t)lba_s + 1;
1730
1731 resid = scsi_bufflen(cmd) - (blocks_done *
1732 cmd->device->sector_size);
1733
1734 scsi_set_resid(cmd, resid);
1735 cmd->result = DID_OK << 16;
1736
1737 /* Update protection tag */
1738 if (scsi_prot_sg_count(cmd)) {
1739 uint32_t i, j = 0, k = 0, num_ent;
1740 struct scatterlist *sg;
1741 struct sd_dif_tuple *spt;
1742
1743 /* Patch the corresponding protection tags */
1744 scsi_for_each_prot_sg(cmd, sg,
1745 scsi_prot_sg_count(cmd), i) {
1746 num_ent = sg_dma_len(sg) / 8;
1747 if (k + num_ent < blocks_done) {
1748 k += num_ent;
1749 continue;
1750 }
1751 j = blocks_done - k - 1;
1752 k = blocks_done;
1753 break;
1754 }
1755
1756 if (k != blocks_done) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001757 ql_log(ql_log_warn, vha, 0x302f,
Randy Dunlap8ec9c7f2011-09-23 15:40:50 -07001758 "unexpected tag values tag:lba=%x:%llx)\n",
1759 e_ref_tag, (unsigned long long)lba_s);
Arun Easi8cb20492011-08-16 11:29:22 -07001760 return 1;
1761 }
1762
1763 spt = page_address(sg_page(sg)) + sg->offset;
1764 spt += j;
1765
1766 spt->app_tag = 0xffff;
1767 if (scsi_get_prot_type(cmd) == SCSI_PROT_DIF_TYPE3)
1768 spt->ref_tag = 0xffffffff;
1769 }
1770
1771 return 0;
1772 }
1773
Arun Easibad75002010-05-04 15:01:30 -07001774 /* check guard */
1775 if (e_guard != a_guard) {
1776 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1777 0x10, 0x1);
1778 set_driver_byte(cmd, DRIVER_SENSE);
1779 set_host_byte(cmd, DID_ABORT);
1780 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
Arun Easi8cb20492011-08-16 11:29:22 -07001781 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001782 }
1783
Arun Easie02587d2011-08-16 11:29:23 -07001784 /* check ref tag */
1785 if (e_ref_tag != a_ref_tag) {
1786 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1787 0x10, 0x3);
1788 set_driver_byte(cmd, DRIVER_SENSE);
1789 set_host_byte(cmd, DID_ABORT);
1790 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
1791 return 1;
1792 }
1793
Arun Easibad75002010-05-04 15:01:30 -07001794 /* check appl tag */
1795 if (e_app_tag != a_app_tag) {
1796 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1797 0x10, 0x2);
1798 set_driver_byte(cmd, DRIVER_SENSE);
1799 set_host_byte(cmd, DID_ABORT);
1800 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
Arun Easi8cb20492011-08-16 11:29:22 -07001801 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001802 }
1803
Arun Easi8cb20492011-08-16 11:29:22 -07001804 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001805}
1806
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001807static void
1808qla25xx_process_bidir_status_iocb(scsi_qla_host_t *vha, void *pkt,
1809 struct req_que *req, uint32_t index)
1810{
1811 struct qla_hw_data *ha = vha->hw;
1812 srb_t *sp;
1813 uint16_t comp_status;
1814 uint16_t scsi_status;
1815 uint16_t thread_id;
1816 uint32_t rval = EXT_STATUS_OK;
1817 struct fc_bsg_job *bsg_job = NULL;
1818 sts_entry_t *sts;
1819 struct sts_entry_24xx *sts24;
1820 sts = (sts_entry_t *) pkt;
1821 sts24 = (struct sts_entry_24xx *) pkt;
1822
1823 /* Validate handle. */
Chad Dupuis8d93f552013-01-30 03:34:37 -05001824 if (index >= req->num_outstanding_cmds) {
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001825 ql_log(ql_log_warn, vha, 0x70af,
1826 "Invalid SCSI completion handle 0x%x.\n", index);
1827 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1828 return;
1829 }
1830
1831 sp = req->outstanding_cmds[index];
1832 if (sp) {
1833 /* Free outstanding command slot. */
1834 req->outstanding_cmds[index] = NULL;
1835 bsg_job = sp->u.bsg_job;
1836 } else {
1837 ql_log(ql_log_warn, vha, 0x70b0,
1838 "Req:%d: Invalid ISP SCSI completion handle(0x%x)\n",
1839 req->id, index);
1840
1841 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1842 return;
1843 }
1844
1845 if (IS_FWI2_CAPABLE(ha)) {
1846 comp_status = le16_to_cpu(sts24->comp_status);
1847 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
1848 } else {
1849 comp_status = le16_to_cpu(sts->comp_status);
1850 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1851 }
1852
1853 thread_id = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1854 switch (comp_status) {
1855 case CS_COMPLETE:
1856 if (scsi_status == 0) {
1857 bsg_job->reply->reply_payload_rcv_len =
1858 bsg_job->reply_payload.payload_len;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -04001859 vha->qla_stats.input_bytes +=
1860 bsg_job->reply->reply_payload_rcv_len;
1861 vha->qla_stats.input_requests++;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001862 rval = EXT_STATUS_OK;
1863 }
1864 goto done;
1865
1866 case CS_DATA_OVERRUN:
1867 ql_dbg(ql_dbg_user, vha, 0x70b1,
1868 "Command completed with date overrun thread_id=%d\n",
1869 thread_id);
1870 rval = EXT_STATUS_DATA_OVERRUN;
1871 break;
1872
1873 case CS_DATA_UNDERRUN:
1874 ql_dbg(ql_dbg_user, vha, 0x70b2,
1875 "Command completed with date underrun thread_id=%d\n",
1876 thread_id);
1877 rval = EXT_STATUS_DATA_UNDERRUN;
1878 break;
1879 case CS_BIDIR_RD_OVERRUN:
1880 ql_dbg(ql_dbg_user, vha, 0x70b3,
1881 "Command completed with read data overrun thread_id=%d\n",
1882 thread_id);
1883 rval = EXT_STATUS_DATA_OVERRUN;
1884 break;
1885
1886 case CS_BIDIR_RD_WR_OVERRUN:
1887 ql_dbg(ql_dbg_user, vha, 0x70b4,
1888 "Command completed with read and write data overrun "
1889 "thread_id=%d\n", thread_id);
1890 rval = EXT_STATUS_DATA_OVERRUN;
1891 break;
1892
1893 case CS_BIDIR_RD_OVERRUN_WR_UNDERRUN:
1894 ql_dbg(ql_dbg_user, vha, 0x70b5,
1895 "Command completed with read data over and write data "
1896 "underrun thread_id=%d\n", thread_id);
1897 rval = EXT_STATUS_DATA_OVERRUN;
1898 break;
1899
1900 case CS_BIDIR_RD_UNDERRUN:
1901 ql_dbg(ql_dbg_user, vha, 0x70b6,
1902 "Command completed with read data data underrun "
1903 "thread_id=%d\n", thread_id);
1904 rval = EXT_STATUS_DATA_UNDERRUN;
1905 break;
1906
1907 case CS_BIDIR_RD_UNDERRUN_WR_OVERRUN:
1908 ql_dbg(ql_dbg_user, vha, 0x70b7,
1909 "Command completed with read data under and write data "
1910 "overrun thread_id=%d\n", thread_id);
1911 rval = EXT_STATUS_DATA_UNDERRUN;
1912 break;
1913
1914 case CS_BIDIR_RD_WR_UNDERRUN:
1915 ql_dbg(ql_dbg_user, vha, 0x70b8,
1916 "Command completed with read and write data underrun "
1917 "thread_id=%d\n", thread_id);
1918 rval = EXT_STATUS_DATA_UNDERRUN;
1919 break;
1920
1921 case CS_BIDIR_DMA:
1922 ql_dbg(ql_dbg_user, vha, 0x70b9,
1923 "Command completed with data DMA error thread_id=%d\n",
1924 thread_id);
1925 rval = EXT_STATUS_DMA_ERR;
1926 break;
1927
1928 case CS_TIMEOUT:
1929 ql_dbg(ql_dbg_user, vha, 0x70ba,
1930 "Command completed with timeout thread_id=%d\n",
1931 thread_id);
1932 rval = EXT_STATUS_TIMEOUT;
1933 break;
1934 default:
1935 ql_dbg(ql_dbg_user, vha, 0x70bb,
1936 "Command completed with completion status=0x%x "
1937 "thread_id=%d\n", comp_status, thread_id);
1938 rval = EXT_STATUS_ERR;
1939 break;
1940 }
1941 bsg_job->reply->reply_payload_rcv_len = 0;
1942
1943done:
1944 /* Return the vendor specific reply to API */
1945 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
1946 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1947 /* Always return DID_OK, bsg will send the vendor specific response
1948 * in this case only */
1949 sp->done(vha, sp, (DID_OK << 6));
1950
1951}
1952
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953/**
1954 * qla2x00_status_entry() - Process a Status IOCB entry.
1955 * @ha: SCSI driver HA context
1956 * @pkt: Entry pointer
1957 */
1958static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001959qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 fc_port_t *fcport;
1963 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001964 sts_entry_t *sts;
1965 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 uint16_t comp_status;
1967 uint16_t scsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001968 uint16_t ox_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 uint8_t lscsi_status;
1970 int32_t resid;
Andrew Vasquez55442132010-07-23 15:28:27 +05001971 uint32_t sense_len, par_sense_len, rsp_info_len, resid_len,
1972 fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001973 uint8_t *rsp_info, *sense_data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001974 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001975 uint32_t handle;
1976 uint16_t que;
1977 struct req_que *req;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001978 int logit = 1;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001979 int res = 0;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001980 uint16_t state_flags = 0;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001981
1982 sts = (sts_entry_t *) pkt;
1983 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001984 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001985 comp_status = le16_to_cpu(sts24->comp_status);
1986 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001987 state_flags = le16_to_cpu(sts24->state_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001988 } else {
1989 comp_status = le16_to_cpu(sts->comp_status);
1990 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1991 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001992 handle = (uint32_t) LSW(sts->handle);
1993 que = MSW(sts->handle);
1994 req = ha->req_q_map[que];
Giridhar Malavalia9083012010-04-12 17:59:55 -07001995
Chad Dupuis36008cf2013-10-03 03:21:13 -04001996 /* Check for invalid queue pointer */
1997 if (req == NULL ||
1998 que >= find_first_zero_bit(ha->req_qid_map, ha->max_req_queues)) {
1999 ql_dbg(ql_dbg_io, vha, 0x3059,
2000 "Invalid status handle (0x%x): Bad req pointer. req=%p, "
2001 "que=%u.\n", sts->handle, req, que);
2002 return;
2003 }
2004
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 /* Validate handle. */
Chad Dupuis8d93f552013-01-30 03:34:37 -05002006 if (handle < req->num_outstanding_cmds)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002007 sp = req->outstanding_cmds[handle];
Chad Dupuis8d93f552013-01-30 03:34:37 -05002008 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 sp = NULL;
2010
2011 if (sp == NULL) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08002012 ql_dbg(ql_dbg_io, vha, 0x3017,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002013 "Invalid status handle (0x%x).\n", sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002015 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07002016 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
2017 else
2018 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002019 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 return;
2021 }
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002022
2023 if (unlikely((state_flags & BIT_1) && (sp->type == SRB_BIDI_CMD))) {
2024 qla25xx_process_bidir_status_iocb(vha, pkt, req, handle);
2025 return;
2026 }
2027
2028 /* Fast path completion. */
2029 if (comp_status == CS_COMPLETE && scsi_status == 0) {
2030 qla2x00_process_completed_request(vha, req, handle);
2031
2032 return;
2033 }
2034
2035 req->outstanding_cmds[handle] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002036 cp = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 if (cp == NULL) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08002038 ql_dbg(ql_dbg_io, vha, 0x3018,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002039 "Command already returned (0x%x/%p).\n",
2040 sts->handle, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041
2042 return;
2043 }
2044
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002045 lscsi_status = scsi_status & STATUS_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046
bdf79622005-04-17 15:06:53 -05002047 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002049 ox_id = 0;
Andrew Vasquez55442132010-07-23 15:28:27 +05002050 sense_len = par_sense_len = rsp_info_len = resid_len =
2051 fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002052 if (IS_FWI2_CAPABLE(ha)) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002053 if (scsi_status & SS_SENSE_LEN_VALID)
2054 sense_len = le32_to_cpu(sts24->sense_len);
2055 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
2056 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
2057 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER))
2058 resid_len = le32_to_cpu(sts24->rsp_residual_count);
2059 if (comp_status == CS_DATA_UNDERRUN)
2060 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002061 rsp_info = sts24->data;
2062 sense_data = sts24->data;
2063 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002064 ox_id = le16_to_cpu(sts24->ox_id);
Andrew Vasquez55442132010-07-23 15:28:27 +05002065 par_sense_len = sizeof(sts24->data);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002066 } else {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002067 if (scsi_status & SS_SENSE_LEN_VALID)
2068 sense_len = le16_to_cpu(sts->req_sense_length);
2069 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
2070 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002071 resid_len = le32_to_cpu(sts->residual_length);
2072 rsp_info = sts->rsp_info;
2073 sense_data = sts->req_sense_data;
Andrew Vasquez55442132010-07-23 15:28:27 +05002074 par_sense_len = sizeof(sts->req_sense_data);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002075 }
2076
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 /* Check for any FCP transport errors. */
2078 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002079 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasquez55442132010-07-23 15:28:27 +05002080 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002081 sense_data += rsp_info_len;
Andrew Vasquez55442132010-07-23 15:28:27 +05002082 par_sense_len -= rsp_info_len;
2083 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002084 if (rsp_info_len > 3 && rsp_info[3]) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002085 ql_dbg(ql_dbg_io, fcport->vha, 0x3019,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002086 "FCP I/O protocol failure (0x%x/0x%x).\n",
2087 rsp_info_len, rsp_info[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002089 res = DID_BUS_BUSY << 16;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002090 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 }
2092 }
2093
Andrew Vasquez3e8ce322008-02-28 14:06:10 -08002094 /* Check for overrun. */
2095 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
2096 scsi_status & SS_RESIDUAL_OVER)
2097 comp_status = CS_DATA_OVERRUN;
2098
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 /*
2100 * Based on Host and scsi status generate status code for Linux
2101 */
2102 switch (comp_status) {
2103 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002104 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 if (scsi_status == 0) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002106 res = DID_OK << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 break;
2108 }
2109 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002110 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002111 scsi_set_resid(cp, resid);
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002112
2113 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002114 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002115 cp->underflow)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002116 ql_dbg(ql_dbg_io, fcport->vha, 0x301a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002117 "Mid-layer underflow "
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002118 "detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002119 resid, scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002120
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002121 res = DID_ERROR << 16;
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002122 break;
2123 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002125 res = DID_OK << 16 | lscsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002127 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002128 ql_dbg(ql_dbg_io, fcport->vha, 0x301b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002129 "QUEUE FULL detected.\n");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002130 break;
2131 }
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002132 logit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 if (lscsi_status != SS_CHECK_CONDITION)
2134 break;
2135
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002136 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 if (!(scsi_status & SS_SENSE_LEN_VALID))
2138 break;
2139
Andrew Vasquez55442132010-07-23 15:28:27 +05002140 qla2x00_handle_sense(sp, sense_data, par_sense_len, sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002141 rsp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 break;
2143
2144 case CS_DATA_UNDERRUN:
Ravi Ananded17c71b52006-05-17 15:08:55 -07002145 /* Use F/W calculated residual length. */
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002146 resid = IS_FWI2_CAPABLE(ha) ? fw_resid_len : resid_len;
2147 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 if (scsi_status & SS_RESIDUAL_UNDER) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002149 if (IS_FWI2_CAPABLE(ha) && fw_resid_len != resid_len) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002150 ql_dbg(ql_dbg_io, fcport->vha, 0x301d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002151 "Dropped frame(s) detected "
2152 "(0x%x of 0x%x bytes).\n",
2153 resid, scsi_bufflen(cp));
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08002154
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002155 res = DID_ERROR << 16 | lscsi_status;
Arun Easi4e85e3d2011-11-18 09:02:10 -08002156 goto check_scsi_status;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002157 }
2158
2159 if (!lscsi_status &&
2160 ((unsigned)(scsi_bufflen(cp) - resid) <
2161 cp->underflow)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002162 ql_dbg(ql_dbg_io, fcport->vha, 0x301e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002163 "Mid-layer underflow "
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002164 "detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002165 resid, scsi_bufflen(cp));
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002166
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002167 res = DID_ERROR << 16;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002168 break;
2169 }
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002170 } else if (lscsi_status != SAM_STAT_TASK_SET_FULL &&
2171 lscsi_status != SAM_STAT_BUSY) {
2172 /*
2173 * scsi status of task set and busy are considered to be
2174 * task not completed.
2175 */
2176
Arun Easi5e19ed92012-02-09 11:15:51 -08002177 ql_dbg(ql_dbg_io, fcport->vha, 0x301f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002178 "Dropped frame(s) detected (0x%x "
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002179 "of 0x%x bytes).\n", resid,
2180 scsi_bufflen(cp));
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002181
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002182 res = DID_ERROR << 16 | lscsi_status;
Lalit Chandivade0374f552010-09-03 14:57:04 -07002183 goto check_scsi_status;
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002184 } else {
2185 ql_dbg(ql_dbg_io, fcport->vha, 0x3030,
2186 "scsi_status: 0x%x, lscsi_status: 0x%x\n",
2187 scsi_status, lscsi_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 }
2189
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002190 res = DID_OK << 16 | lscsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002191 logit = 0;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002192
Lalit Chandivade0374f552010-09-03 14:57:04 -07002193check_scsi_status:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002195 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 * Status.
2197 */
2198 if (lscsi_status != 0) {
Andrew Vasquezffec28a2007-01-29 10:22:27 -08002199 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002200 ql_dbg(ql_dbg_io, fcport->vha, 0x3020,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002201 "QUEUE FULL detected.\n");
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002202 logit = 1;
Andrew Vasquezffec28a2007-01-29 10:22:27 -08002203 break;
2204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 if (lscsi_status != SS_CHECK_CONDITION)
2206 break;
2207
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002208 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 if (!(scsi_status & SS_SENSE_LEN_VALID))
2210 break;
2211
Andrew Vasquez55442132010-07-23 15:28:27 +05002212 qla2x00_handle_sense(sp, sense_data, par_sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002213 sense_len, rsp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 }
2215 break;
2216
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 case CS_PORT_LOGGED_OUT:
2218 case CS_PORT_CONFIG_CHG:
2219 case CS_PORT_BUSY:
2220 case CS_INCOMPLETE:
2221 case CS_PORT_UNAVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 case CS_TIMEOUT:
Chad Dupuisff454b02010-10-15 11:27:42 -07002223 case CS_RESET:
2224
Mike Christie056a4482008-08-19 18:45:29 -05002225 /*
2226 * We are going to have the fc class block the rport
2227 * while we try to recover so instruct the mid layer
2228 * to requeue until the class decides how to handle this.
2229 */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002230 res = DID_TRANSPORT_DISRUPTED << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002232 if (comp_status == CS_TIMEOUT) {
2233 if (IS_FWI2_CAPABLE(ha))
2234 break;
2235 else if ((le16_to_cpu(sts->status_flags) &
2236 SF_LOGOUT_SENT) == 0)
2237 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002239
Arun Easi5e19ed92012-02-09 11:15:51 -08002240 ql_dbg(ql_dbg_io, fcport->vha, 0x3021,
Chad Dupuis0e948972013-08-27 01:37:39 -04002241 "Port to be marked lost on fcport=%02x%02x%02x, current "
2242 "port state= %s.\n", fcport->d_id.b.domain,
2243 fcport->d_id.b.area, fcport->d_id.b.al_pa,
2244 port_state_str[atomic_read(&fcport->state)]);
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002245
2246 if (atomic_read(&fcport->state) == FCS_ONLINE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002247 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 break;
2249
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002250 case CS_ABORTED:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002251 res = DID_RESET << 16;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002252 break;
Arun Easibad75002010-05-04 15:01:30 -07002253
2254 case CS_DIF_ERROR:
Arun Easi8cb20492011-08-16 11:29:22 -07002255 logit = qla2x00_handle_dif_error(sp, sts24);
Arun Easifb6e4662012-08-22 14:21:32 -04002256 res = cp->result;
Arun Easibad75002010-05-04 15:01:30 -07002257 break;
Arun Easi9e522cd2012-08-22 14:21:31 -04002258
2259 case CS_TRANSPORT:
2260 res = DID_ERROR << 16;
2261
2262 if (!IS_PI_SPLIT_DET_CAPABLE(ha))
2263 break;
2264
2265 if (state_flags & BIT_4)
2266 scmd_printk(KERN_WARNING, cp,
2267 "Unsupported device '%s' found.\n",
2268 cp->device->vendor);
2269 break;
2270
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 default:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002272 res = DID_ERROR << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 break;
2274 }
2275
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002276out:
2277 if (logit)
Arun Easi5e19ed92012-02-09 11:15:51 -08002278 ql_dbg(ql_dbg_io, fcport->vha, 0x3022,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04002279 "FCP command status: 0x%x-0x%x (0x%x) nexus=%ld:%d:%d "
2280 "portid=%02x%02x%02x oxid=0x%x cdb=%10phN len=0x%x "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002281 "rsp_info=0x%x resid=0x%x fw_resid=0x%x.\n",
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002282 comp_status, scsi_status, res, vha->host_no,
Chad Dupuiscfb09192011-11-18 09:03:07 -08002283 cp->device->id, cp->device->lun, fcport->d_id.b.domain,
2284 fcport->d_id.b.area, fcport->d_id.b.al_pa, ox_id,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04002285 cp->cmnd, scsi_bufflen(cp), rsp_info_len,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002286 resid_len, fw_resid_len);
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002287
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002288 if (rsp->status_srb == NULL)
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002289 sp->done(ha, sp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290}
2291
2292/**
2293 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
2294 * @ha: SCSI driver HA context
2295 * @pkt: Entry pointer
2296 *
2297 * Extended sense data.
2298 */
2299static void
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002300qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002302 uint8_t sense_sz = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002303 struct qla_hw_data *ha = rsp->hw;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002304 struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002305 srb_t *sp = rsp->status_srb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 struct scsi_cmnd *cp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002307 uint32_t sense_len;
2308 uint8_t *sense_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002310 if (!sp || !GET_CMD_SENSE_LEN(sp))
2311 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002313 sense_len = GET_CMD_SENSE_LEN(sp);
2314 sense_ptr = GET_CMD_SENSE_PTR(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002316 cp = GET_CMD_SP(sp);
2317 if (cp == NULL) {
2318 ql_log(ql_log_warn, vha, 0x3025,
2319 "cmd is NULL: already returned to OS (sp=%p).\n", sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002321 rsp->status_srb = NULL;
2322 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002325 if (sense_len > sizeof(pkt->data))
2326 sense_sz = sizeof(pkt->data);
2327 else
2328 sense_sz = sense_len;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002329
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002330 /* Move sense data. */
2331 if (IS_FWI2_CAPABLE(ha))
2332 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
2333 memcpy(sense_ptr, pkt->data, sense_sz);
2334 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302c,
2335 sense_ptr, sense_sz);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002336
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002337 sense_len -= sense_sz;
2338 sense_ptr += sense_sz;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002339
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002340 SET_CMD_SENSE_PTR(sp, sense_ptr);
2341 SET_CMD_SENSE_LEN(sp, sense_len);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002342
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002343 /* Place command on done queue. */
2344 if (sense_len == 0) {
2345 rsp->status_srb = NULL;
2346 sp->done(ha, sp, cp->result);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002347 }
Giridhar Malavalic4631192011-11-18 09:03:08 -08002348}
2349
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350/**
2351 * qla2x00_error_entry() - Process an error entry.
2352 * @ha: SCSI driver HA context
2353 * @pkt: Entry pointer
2354 */
2355static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002356qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357{
2358 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002359 struct qla_hw_data *ha = vha->hw;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002360 const char func[] = "ERROR-IOCB";
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002361 uint16_t que = MSW(pkt->handle);
Arun Easia6fe35c2012-02-09 11:16:01 -08002362 struct req_que *req = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002363 int res = DID_ERROR << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002364
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002365 ql_dbg(ql_dbg_async, vha, 0x502a,
2366 "type of error status in response: 0x%x\n", pkt->entry_status);
2367
Arun Easia6fe35c2012-02-09 11:16:01 -08002368 if (que >= ha->max_req_queues || !ha->req_q_map[que])
2369 goto fatal;
2370
2371 req = ha->req_q_map[que];
2372
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002373 if (pkt->entry_status & RF_BUSY)
2374 res = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375
Giridhar Malavalic4631192011-11-18 09:03:08 -08002376 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
Arun Easia6fe35c2012-02-09 11:16:01 -08002377 if (sp) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002378 sp->done(ha, sp, res);
Arun Easia6fe35c2012-02-09 11:16:01 -08002379 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 }
Arun Easia6fe35c2012-02-09 11:16:01 -08002381fatal:
2382 ql_log(ql_log_warn, vha, 0x5030,
2383 "Error entry - invalid handle/queue.\n");
2384
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002385 if (IS_P3P_TYPE(ha))
Arun Easia6fe35c2012-02-09 11:16:01 -08002386 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
2387 else
2388 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2389 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390}
2391
2392/**
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002393 * qla24xx_mbx_completion() - Process mailbox command completions.
2394 * @ha: SCSI driver HA context
2395 * @mb0: Mailbox0 register
2396 */
2397static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002398qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002399{
2400 uint16_t cnt;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002401 uint32_t mboxes;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002402 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002403 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002404 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2405
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002406 /* Read all mbox registers? */
2407 mboxes = (1 << ha->mbx_count) - 1;
2408 if (!ha->mcp)
Masanari Iidaa7201012012-11-21 02:40:42 -05002409 ql_dbg(ql_dbg_async, vha, 0x504e, "MBX pointer ERROR.\n");
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002410 else
2411 mboxes = ha->mcp->in_mb;
2412
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002413 /* Load return mailbox registers. */
2414 ha->flags.mbox_int = 1;
2415 ha->mailbox_out[0] = mb0;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002416 mboxes >>= 1;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002417 wptr = (uint16_t __iomem *)&reg->mailbox1;
2418
2419 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002420 if (mboxes & BIT_0)
2421 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
2422
2423 mboxes >>= 1;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002424 wptr++;
2425 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002426}
2427
2428/**
2429 * qla24xx_process_response_queue() - Process response queue entries.
2430 * @ha: SCSI driver HA context
2431 */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002432void qla24xx_process_response_queue(struct scsi_qla_host *vha,
2433 struct rsp_que *rsp)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002434{
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002435 struct sts_entry_24xx *pkt;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002436 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002437
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002438 if (!vha->flags.online)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002439 return;
2440
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002441 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
2442 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002443
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002444 rsp->ring_index++;
2445 if (rsp->ring_index == rsp->length) {
2446 rsp->ring_index = 0;
2447 rsp->ring_ptr = rsp->ring;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002448 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002449 rsp->ring_ptr++;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002450 }
2451
2452 if (pkt->entry_status != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002453 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002454
2455 (void)qlt_24xx_process_response_error(vha, pkt);
2456
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002457 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2458 wmb();
2459 continue;
2460 }
2461
2462 switch (pkt->entry_type) {
2463 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002464 qla2x00_status_entry(vha, rsp, pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002465 break;
2466 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002467 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002468 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002469 case VP_RPT_ID_IOCB_TYPE:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002470 qla24xx_report_id_acquisition(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002471 (struct vp_rpt_id_entry_24xx *)pkt);
2472 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07002473 case LOGINOUT_PORT_IOCB_TYPE:
2474 qla24xx_logio_entry(vha, rsp->req,
2475 (struct logio_entry_24xx *)pkt);
2476 break;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07002477 case TSK_MGMT_IOCB_TYPE:
2478 qla24xx_tm_iocb_entry(vha, rsp->req,
2479 (struct tsk_mgmt_entry *)pkt);
2480 break;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002481 case CT_IOCB_TYPE:
2482 qla24xx_els_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002483 break;
2484 case ELS_IOCB_TYPE:
2485 qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE);
2486 break;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002487 case ABTS_RECV_24XX:
2488 /* ensure that the ATIO queue is empty */
2489 qlt_24xx_process_atio_queue(vha);
2490 case ABTS_RESP_24XX:
2491 case CTIO_TYPE7:
2492 case NOTIFY_ACK_TYPE:
2493 qlt_response_pkt_all_vps(vha, (response_t *)pkt);
2494 break;
Saurav Kashyap54883292011-08-16 11:31:48 -07002495 case MARKER_TYPE:
2496 /* Do nothing in this case, this check is to prevent it
2497 * from falling into default case
2498 */
2499 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002500 default:
2501 /* Type Not Supported. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002502 ql_dbg(ql_dbg_async, vha, 0x5042,
2503 "Received unknown response pkt type %x "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002504 "entry status=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002505 pkt->entry_type, pkt->entry_status);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002506 break;
2507 }
2508 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2509 wmb();
2510 }
2511
2512 /* Adjust ring index */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002513 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002514 struct device_reg_82xx __iomem *reg = &ha->iobase->isp82;
2515 WRT_REG_DWORD(&reg->rsp_q_out[0], rsp->ring_index);
2516 } else
2517 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002518}
2519
Andrew Vasquez05236a02007-09-20 14:07:37 -07002520static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002521qla2xxx_check_risc_status(scsi_qla_host_t *vha)
Andrew Vasquez05236a02007-09-20 14:07:37 -07002522{
2523 int rval;
2524 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002525 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez05236a02007-09-20 14:07:37 -07002526 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2527
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002528 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha))
Andrew Vasquez05236a02007-09-20 14:07:37 -07002529 return;
2530
2531 rval = QLA_SUCCESS;
2532 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
2533 RD_REG_DWORD(&reg->iobase_addr);
2534 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
2535 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
2536 rval == QLA_SUCCESS; cnt--) {
2537 if (cnt) {
2538 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
2539 udelay(10);
2540 } else
2541 rval = QLA_FUNCTION_TIMEOUT;
2542 }
2543 if (rval == QLA_SUCCESS)
2544 goto next_test;
2545
Bart Van Asscheb2ec76c2013-06-25 11:27:29 -04002546 rval = QLA_SUCCESS;
Andrew Vasquez05236a02007-09-20 14:07:37 -07002547 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
2548 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
2549 rval == QLA_SUCCESS; cnt--) {
2550 if (cnt) {
2551 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
2552 udelay(10);
2553 } else
2554 rval = QLA_FUNCTION_TIMEOUT;
2555 }
2556 if (rval != QLA_SUCCESS)
2557 goto done;
2558
2559next_test:
2560 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002561 ql_log(ql_log_info, vha, 0x504c,
2562 "Additional code -- 0x55AA.\n");
Andrew Vasquez05236a02007-09-20 14:07:37 -07002563
2564done:
2565 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
2566 RD_REG_DWORD(&reg->iobase_window);
2567}
2568
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002569/**
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002570 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP24xx.
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002571 * @irq:
2572 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002573 *
2574 * Called by system whenever the host adapter generates an interrupt.
2575 *
2576 * Returns handled flag.
2577 */
2578irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01002579qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002580{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002581 scsi_qla_host_t *vha;
2582 struct qla_hw_data *ha;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002583 struct device_reg_24xx __iomem *reg;
2584 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002585 unsigned long iter;
2586 uint32_t stat;
2587 uint32_t hccr;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002588 uint16_t mb[8];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002589 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002590 unsigned long flags;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002591
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002592 rsp = (struct rsp_que *) dev_id;
2593 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002594 ql_log(ql_log_info, NULL, 0x5059,
2595 "%s: NULL response queue pointer.\n", __func__);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002596 return IRQ_NONE;
2597 }
2598
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002599 ha = rsp->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002600 reg = &ha->iobase->isp24;
2601 status = 0;
2602
Andrew Vasquez85880802009-12-15 21:29:46 -08002603 if (unlikely(pci_channel_offline(ha->pdev)))
2604 return IRQ_HANDLED;
2605
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002606 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002607 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002608 for (iter = 50; iter--; ) {
2609 stat = RD_REG_DWORD(&reg->host_status);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002610 if (qla2x00_check_reg_for_disconnect(vha, stat))
2611 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002612 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08002613 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07002614 break;
2615
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002616 hccr = RD_REG_DWORD(&reg->hccr);
2617
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002618 ql_log(ql_log_warn, vha, 0x504b,
2619 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2620 hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002621
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002622 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002623
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002624 ha->isp_ops->fw_dump(vha, 1);
2625 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002626 break;
2627 } else if ((stat & HSRX_RISC_INT) == 0)
2628 break;
2629
2630 switch (stat & 0xff) {
Arun Easifafbda92012-08-22 14:21:16 -04002631 case INTR_ROM_MB_SUCCESS:
2632 case INTR_ROM_MB_FAILED:
2633 case INTR_MB_SUCCESS:
2634 case INTR_MB_FAILED:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002635 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002636 status |= MBX_INTERRUPT;
2637
2638 break;
Arun Easifafbda92012-08-22 14:21:16 -04002639 case INTR_ASYNC_EVENT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002640 mb[0] = MSW(stat);
2641 mb[1] = RD_REG_WORD(&reg->mailbox1);
2642 mb[2] = RD_REG_WORD(&reg->mailbox2);
2643 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002644 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002645 break;
Arun Easifafbda92012-08-22 14:21:16 -04002646 case INTR_RSP_QUE_UPDATE:
2647 case INTR_RSP_QUE_UPDATE_83XX:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002648 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002649 break;
Arun Easifafbda92012-08-22 14:21:16 -04002650 case INTR_ATIO_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002651 qlt_24xx_process_atio_queue(vha);
2652 break;
Arun Easifafbda92012-08-22 14:21:16 -04002653 case INTR_ATIO_RSP_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002654 qlt_24xx_process_atio_queue(vha);
2655 qla24xx_process_response_queue(vha, rsp);
2656 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002657 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002658 ql_dbg(ql_dbg_async, vha, 0x504f,
2659 "Unrecognized interrupt type (%d).\n", stat * 0xff);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002660 break;
2661 }
2662 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2663 RD_REG_DWORD_RELAXED(&reg->hccr);
Giridhar Malavalicb860bb2012-08-22 14:21:30 -04002664 if (unlikely(IS_QLA83XX(ha) && (ha->pdev->revision == 1)))
2665 ndelay(3500);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002666 }
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -07002667 qla2x00_handle_mbx_completion(ha, status);
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002668 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002669
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002670 return IRQ_HANDLED;
2671}
2672
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002673static irqreturn_t
2674qla24xx_msix_rsp_q(int irq, void *dev_id)
2675{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002676 struct qla_hw_data *ha;
2677 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002678 struct device_reg_24xx __iomem *reg;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002679 struct scsi_qla_host *vha;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002680 unsigned long flags;
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002681 uint32_t stat = 0;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002682
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002683 rsp = (struct rsp_que *) dev_id;
2684 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002685 ql_log(ql_log_info, NULL, 0x505a,
2686 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002687 return IRQ_NONE;
2688 }
2689 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002690 reg = &ha->iobase->isp24;
2691
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002692 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002693
Anirban Chakrabortya67093d2010-02-04 14:17:59 -08002694 vha = pci_get_drvdata(ha->pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002695 /*
2696 * Use host_status register to check to PCI disconnection before we
2697 * we process the response queue.
2698 */
2699 stat = RD_REG_DWORD(&reg->host_status);
2700 if (qla2x00_check_reg_for_disconnect(vha, stat))
2701 goto out;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002702 qla24xx_process_response_queue(vha, rsp);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002703 if (!ha->flags.disable_msix_handshake) {
Anirban Chakrabortyeb941142009-08-04 16:12:13 -07002704 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2705 RD_REG_DWORD_RELAXED(&reg->hccr);
2706 }
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002707out:
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002708 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002709
2710 return IRQ_HANDLED;
2711}
2712
2713static irqreturn_t
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002714qla25xx_msix_rsp_q(int irq, void *dev_id)
2715{
2716 struct qla_hw_data *ha;
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002717 scsi_qla_host_t *vha;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002718 struct rsp_que *rsp;
Anirban Chakraborty31557542009-12-02 10:36:55 -08002719 struct device_reg_24xx __iomem *reg;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002720 unsigned long flags;
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002721 uint32_t hccr = 0;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002722
2723 rsp = (struct rsp_que *) dev_id;
2724 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002725 ql_log(ql_log_info, NULL, 0x505b,
2726 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002727 return IRQ_NONE;
2728 }
2729 ha = rsp->hw;
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002730 vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002731
Anirban Chakraborty31557542009-12-02 10:36:55 -08002732 /* Clear the interrupt, if enabled, for this response queue */
Andrew Vasquezd4247542011-10-26 14:20:13 -07002733 if (!ha->flags.disable_msix_handshake) {
Anirban Chakraborty31557542009-12-02 10:36:55 -08002734 reg = &ha->iobase->isp24;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002735 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002736 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002737 hccr = RD_REG_DWORD_RELAXED(&reg->hccr);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002738 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002739 }
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002740 if (qla2x00_check_reg_for_disconnect(vha, hccr))
2741 goto out;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002742 queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work);
2743
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002744out:
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002745 return IRQ_HANDLED;
2746}
2747
2748static irqreturn_t
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002749qla24xx_msix_default(int irq, void *dev_id)
2750{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002751 scsi_qla_host_t *vha;
2752 struct qla_hw_data *ha;
2753 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002754 struct device_reg_24xx __iomem *reg;
2755 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002756 uint32_t stat;
2757 uint32_t hccr;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002758 uint16_t mb[8];
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002759 unsigned long flags;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002760
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002761 rsp = (struct rsp_que *) dev_id;
2762 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002763 ql_log(ql_log_info, NULL, 0x505c,
2764 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002765 return IRQ_NONE;
2766 }
2767 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002768 reg = &ha->iobase->isp24;
2769 status = 0;
2770
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002771 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002772 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002773 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002774 stat = RD_REG_DWORD(&reg->host_status);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002775 if (qla2x00_check_reg_for_disconnect(vha, stat))
2776 break;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002777 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08002778 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07002779 break;
2780
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002781 hccr = RD_REG_DWORD(&reg->hccr);
2782
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002783 ql_log(ql_log_info, vha, 0x5050,
2784 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2785 hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002786
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002787 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002788
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002789 ha->isp_ops->fw_dump(vha, 1);
2790 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002791 break;
2792 } else if ((stat & HSRX_RISC_INT) == 0)
2793 break;
2794
2795 switch (stat & 0xff) {
Arun Easifafbda92012-08-22 14:21:16 -04002796 case INTR_ROM_MB_SUCCESS:
2797 case INTR_ROM_MB_FAILED:
2798 case INTR_MB_SUCCESS:
2799 case INTR_MB_FAILED:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002800 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002801 status |= MBX_INTERRUPT;
2802
2803 break;
Arun Easifafbda92012-08-22 14:21:16 -04002804 case INTR_ASYNC_EVENT:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002805 mb[0] = MSW(stat);
2806 mb[1] = RD_REG_WORD(&reg->mailbox1);
2807 mb[2] = RD_REG_WORD(&reg->mailbox2);
2808 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002809 qla2x00_async_event(vha, rsp, mb);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002810 break;
Arun Easifafbda92012-08-22 14:21:16 -04002811 case INTR_RSP_QUE_UPDATE:
2812 case INTR_RSP_QUE_UPDATE_83XX:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002813 qla24xx_process_response_queue(vha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002814 break;
Arun Easifafbda92012-08-22 14:21:16 -04002815 case INTR_ATIO_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002816 qlt_24xx_process_atio_queue(vha);
2817 break;
Arun Easifafbda92012-08-22 14:21:16 -04002818 case INTR_ATIO_RSP_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002819 qlt_24xx_process_atio_queue(vha);
2820 qla24xx_process_response_queue(vha, rsp);
2821 break;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002822 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002823 ql_dbg(ql_dbg_async, vha, 0x5051,
2824 "Unrecognized interrupt type (%d).\n", stat & 0xff);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002825 break;
2826 }
2827 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002828 } while (0);
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -07002829 qla2x00_handle_mbx_completion(ha, status);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002830 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002831
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002832 return IRQ_HANDLED;
2833}
2834
2835/* Interrupt handling helpers. */
2836
2837struct qla_init_msix_entry {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002838 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07002839 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002840};
2841
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002842static struct qla_init_msix_entry msix_entries[3] = {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002843 { "qla2xxx (default)", qla24xx_msix_default },
2844 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002845 { "qla2xxx (multiq)", qla25xx_msix_rsp_q },
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002846};
2847
Giridhar Malavalia9083012010-04-12 17:59:55 -07002848static struct qla_init_msix_entry qla82xx_msix_entries[2] = {
2849 { "qla2xxx (default)", qla82xx_msix_default },
2850 { "qla2xxx (rsp_q)", qla82xx_msix_rsp_q },
2851};
2852
Arun Easiaa230bc2013-01-30 03:34:39 -05002853static struct qla_init_msix_entry qla83xx_msix_entries[3] = {
2854 { "qla2xxx (default)", qla24xx_msix_default },
2855 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
2856 { "qla2xxx (atio_q)", qla83xx_msix_atio_q },
2857};
2858
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002859static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002860qla24xx_disable_msix(struct qla_hw_data *ha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002861{
2862 int i;
2863 struct qla_msix_entry *qentry;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002864 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002865
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002866 for (i = 0; i < ha->msix_count; i++) {
2867 qentry = &ha->msix_entries[i];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002868 if (qentry->have_irq)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002869 free_irq(qentry->vector, qentry->rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002870 }
2871 pci_disable_msix(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002872 kfree(ha->msix_entries);
2873 ha->msix_entries = NULL;
2874 ha->flags.msix_enabled = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002875 ql_dbg(ql_dbg_init, vha, 0x0042,
2876 "Disabled the MSI.\n");
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002877}
2878
2879static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002880qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002881{
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002882#define MIN_MSIX_COUNT 2
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002883 int i, ret;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002884 struct msix_entry *entries;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002885 struct qla_msix_entry *qentry;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002886 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002887
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002888 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002889 GFP_KERNEL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002890 if (!entries) {
2891 ql_log(ql_log_warn, vha, 0x00bc,
2892 "Failed to allocate memory for msix_entry.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002893 return -ENOMEM;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002894 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002895
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002896 for (i = 0; i < ha->msix_count; i++)
2897 entries[i].entry = i;
2898
2899 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002900 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002901 if (ret < MIN_MSIX_COUNT)
2902 goto msix_failed;
2903
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002904 ql_log(ql_log_warn, vha, 0x00c6,
2905 "MSI-X: Failed to enable support "
2906 "-- %d/%d\n Retry with %d vectors.\n",
2907 ha->msix_count, ret, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002908 ha->msix_count = ret;
2909 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
2910 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002911msix_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002912 ql_log(ql_log_fatal, vha, 0x00c7,
2913 "MSI-X: Failed to enable support, "
2914 "giving up -- %d/%d.\n",
2915 ha->msix_count, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002916 goto msix_out;
2917 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002918 ha->max_rsp_queues = ha->msix_count - 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002919 }
2920 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
2921 ha->msix_count, GFP_KERNEL);
2922 if (!ha->msix_entries) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002923 ql_log(ql_log_fatal, vha, 0x00c8,
2924 "Failed to allocate memory for ha->msix_entries.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002925 ret = -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002926 goto msix_out;
2927 }
2928 ha->flags.msix_enabled = 1;
2929
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002930 for (i = 0; i < ha->msix_count; i++) {
2931 qentry = &ha->msix_entries[i];
2932 qentry->vector = entries[i].vector;
2933 qentry->entry = entries[i].entry;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002934 qentry->have_irq = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002935 qentry->rsp = NULL;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002936 }
2937
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002938 /* Enable MSI-X vectors for the base queue */
Arun Easiaa230bc2013-01-30 03:34:39 -05002939 for (i = 0; i < ha->msix_count; i++) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002940 qentry = &ha->msix_entries[i];
Arun Easiaa230bc2013-01-30 03:34:39 -05002941 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) {
2942 ret = request_irq(qentry->vector,
2943 qla83xx_msix_entries[i].handler,
2944 0, qla83xx_msix_entries[i].name, rsp);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002945 } else if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002946 ret = request_irq(qentry->vector,
2947 qla82xx_msix_entries[i].handler,
2948 0, qla82xx_msix_entries[i].name, rsp);
2949 } else {
2950 ret = request_irq(qentry->vector,
2951 msix_entries[i].handler,
2952 0, msix_entries[i].name, rsp);
2953 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002954 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002955 ql_log(ql_log_fatal, vha, 0x00cb,
2956 "MSI-X: unable to register handler -- %x/%d.\n",
2957 qentry->vector, ret);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002958 qla24xx_disable_msix(ha);
2959 ha->mqenable = 0;
2960 goto msix_out;
2961 }
2962 qentry->have_irq = 1;
2963 qentry->rsp = rsp;
2964 rsp->msix = qentry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002965 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002966
2967 /* Enable MSI-X vector for response queue update for queue 0 */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002968 if (IS_QLA83XX(ha)) {
2969 if (ha->msixbase && ha->mqiobase &&
2970 (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
2971 ha->mqenable = 1;
2972 } else
2973 if (ha->mqiobase
2974 && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
2975 ha->mqenable = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002976 ql_dbg(ql_dbg_multiq, vha, 0xc005,
2977 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
2978 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
2979 ql_dbg(ql_dbg_init, vha, 0x0055,
2980 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
2981 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002982
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002983msix_out:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002984 kfree(entries);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002985 return ret;
2986}
2987
2988int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002989qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002990{
Sawan Chandak7fa3e232013-10-30 03:38:10 -04002991 int ret = QLA_FUNCTION_FAILED;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002992 device_reg_t __iomem *reg = ha->iobase;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002993 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002994
2995 /* If possible, enable MSI-X. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002996 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002997 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha) && !IS_QLAFX00(ha))
Ben Hutchings6377a7a2010-03-19 16:59:19 -07002998 goto skip_msi;
2999
3000 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
3001 (ha->pdev->subsystem_device == 0x7040 ||
3002 ha->pdev->subsystem_device == 0x7041 ||
3003 ha->pdev->subsystem_device == 0x1705)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003004 ql_log(ql_log_warn, vha, 0x0034,
3005 "MSI-X: Unsupported ISP 2432 SSVID/SSDID (0x%X,0x%X).\n",
Ben Hutchings6377a7a2010-03-19 16:59:19 -07003006 ha->pdev->subsystem_vendor,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003007 ha->pdev->subsystem_device);
Ben Hutchings6377a7a2010-03-19 16:59:19 -07003008 goto skip_msi;
3009 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003010
Chad Dupuis42cd4f52011-08-16 11:29:24 -07003011 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003012 ql_log(ql_log_warn, vha, 0x0035,
3013 "MSI-X; Unsupported ISP2432 (0x%X, 0x%X).\n",
Chad Dupuis42cd4f52011-08-16 11:29:24 -07003014 ha->pdev->revision, QLA_MSIX_CHIP_REV_24XX);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003015 goto skip_msix;
3016 }
3017
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003018 ret = qla24xx_enable_msix(ha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003019 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003020 ql_dbg(ql_dbg_init, vha, 0x0036,
3021 "MSI-X: Enabled (0x%X, 0x%X).\n",
3022 ha->chip_revision, ha->fw_attributes);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003023 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003024 }
Sawan Chandak7fa3e232013-10-30 03:38:10 -04003025
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003026skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07003027
Sawan Chandak7fa3e232013-10-30 03:38:10 -04003028 ql_log(ql_log_info, vha, 0x0037,
3029 "Falling back-to MSI mode -%d.\n", ret);
3030
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003031 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003032 !IS_QLA8001(ha) && !IS_P3P_TYPE(ha) && !IS_QLAFX00(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07003033 goto skip_msi;
3034
3035 ret = pci_enable_msi(ha->pdev);
3036 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003037 ql_dbg(ql_dbg_init, vha, 0x0038,
3038 "MSI: Enabled.\n");
Andrew Vasquezcbedb602007-05-07 07:43:02 -07003039 ha->flags.msi_enabled = 1;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003040 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003041 ql_log(ql_log_warn, vha, 0x0039,
Sawan Chandak7fa3e232013-10-30 03:38:10 -04003042 "Falling back-to INTa mode -- %d.\n", ret);
3043skip_msi:
Giridhar Malavalia033b652012-08-22 14:21:07 -04003044
3045 /* Skip INTx on ISP82xx. */
3046 if (!ha->flags.msi_enabled && IS_QLA82XX(ha))
3047 return QLA_FUNCTION_FAILED;
3048
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003049 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Mike Hernandez7992abf2010-11-23 16:52:47 -08003050 ha->flags.msi_enabled ? 0 : IRQF_SHARED,
3051 QLA2XXX_DRIVER_NAME, rsp);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003052 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003053 ql_log(ql_log_warn, vha, 0x003a,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003054 "Failed to reserve interrupt %d already in use.\n",
3055 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003056 goto fail;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003057 } else if (!ha->flags.msi_enabled) {
Saurav Kashyap68d91cb2012-11-21 02:40:44 -05003058 ql_dbg(ql_dbg_init, vha, 0x0125,
3059 "INTa mode: Enabled.\n");
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003060 ha->flags.mr_intr_valid = 1;
3061 }
Mike Hernandez7992abf2010-11-23 16:52:47 -08003062
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003063clear_risc_ints:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003064
Andrew Vasquezc6952482008-04-03 13:13:17 -07003065 spin_lock_irq(&ha->hardware_lock);
Giridhar Malavalic1114952012-08-22 14:21:33 -04003066 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003067 WRT_REG_WORD(&reg->isp.semaphore, 0);
Andrew Vasquezc6952482008-04-03 13:13:17 -07003068 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003069
3070fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003071 return ret;
3072}
3073
3074void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003075qla2x00_free_irqs(scsi_qla_host_t *vha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003076{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003077 struct qla_hw_data *ha = vha->hw;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003078 struct rsp_que *rsp;
3079
3080 /*
3081 * We need to check that ha->rsp_q_map is valid in case we are called
3082 * from a probe failure context.
3083 */
3084 if (!ha->rsp_q_map || !ha->rsp_q_map[0])
3085 return;
3086 rsp = ha->rsp_q_map[0];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003087
3088 if (ha->flags.msix_enabled)
3089 qla24xx_disable_msix(ha);
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003090 else if (ha->flags.msi_enabled) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003091 free_irq(ha->pdev->irq, rsp);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07003092 pci_disable_msi(ha->pdev);
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003093 } else
3094 free_irq(ha->pdev->irq, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003095}
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003096
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003097
3098int qla25xx_request_irq(struct rsp_que *rsp)
3099{
3100 struct qla_hw_data *ha = rsp->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003101 struct qla_init_msix_entry *intr = &msix_entries[2];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003102 struct qla_msix_entry *msix = rsp->msix;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003103 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003104 int ret;
3105
3106 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
3107 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003108 ql_log(ql_log_fatal, vha, 0x00e6,
3109 "MSI-X: Unable to register handler -- %x/%d.\n",
3110 msix->vector, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003111 return ret;
3112 }
3113 msix->have_irq = 1;
3114 msix->rsp = rsp;
3115 return ret;
3116}