blob: 6c6e624a5aa6b52525da4dd43aee1f65f8139782 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Armen Baloyanbd21eaf2014-04-11 16:54:24 -04003 * Copyright (c) 2003-2014 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>
Quinn Trane326d222017-06-13 20:47:18 -070012#include <linux/cpu.h>
Bart Van Assche09ce66a2016-11-15 11:21:46 -080013#include <linux/t10-pi.h>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070014#include <scsi/scsi_tcq.h>
Giridhar Malavali9a069e12010-01-12 13:02:47 -080015#include <scsi/scsi_bsg_fc.h>
Arun Easibad75002010-05-04 15:01:30 -070016#include <scsi/scsi_eh.h>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070017
Linus Torvalds1da177e2005-04-16 15:20:36 -070018static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080019static void qla2x00_status_entry(scsi_qla_host_t *, struct rsp_que *, void *);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070020static void qla2x00_status_cont_entry(struct rsp_que *, sts_cont_entry_t *);
Quinn Tranc5419e22017-06-13 20:47:16 -070021static int qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
Anirban Chakraborty73208df2008-12-09 16:45:39 -080022 sts_entry_t *);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070023
Linus Torvalds1da177e2005-04-16 15:20:36 -070024/**
25 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
26 * @irq:
27 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 *
29 * Called by system whenever the host adapter generates an interrupt.
30 *
31 * Returns handled flag.
32 */
33irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +010034qla2100_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080036 scsi_qla_host_t *vha;
37 struct qla_hw_data *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -070038 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 unsigned long iter;
Seokmann Ju14e660e2007-09-20 14:07:36 -070041 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070042 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080043 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070044 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080046 rsp = (struct rsp_que *) dev_id;
47 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -080048 ql_log(ql_log_info, NULL, 0x505d,
49 "%s: NULL response queue pointer.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 return (IRQ_NONE);
51 }
52
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080053 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -070054 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 status = 0;
56
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070057 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070058 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 for (iter = 50; iter--; ) {
Seokmann Ju14e660e2007-09-20 14:07:36 -070060 hccr = RD_REG_WORD(&reg->hccr);
Joe Lawrencec821e0d2014-08-26 17:11:41 -040061 if (qla2x00_check_reg16_for_disconnect(vha, hccr))
Chad Dupuisf3ddac12013-10-30 03:38:16 -040062 break;
Seokmann Ju14e660e2007-09-20 14:07:36 -070063 if (hccr & HCCR_RISC_PAUSE) {
64 if (pci_channel_offline(ha->pdev))
65 break;
66
67 /*
68 * Issue a "HARD" reset in order for the RISC interrupt
Justin P. Mattocka06a0f82011-06-23 23:22:27 -070069 * bit to be cleared. Schedule a big hammer to get
Seokmann Ju14e660e2007-09-20 14:07:36 -070070 * out of the RISC PAUSED state.
71 */
72 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
73 RD_REG_WORD(&reg->hccr);
74
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080075 ha->isp_ops->fw_dump(vha, 1);
76 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -070077 break;
78 } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 break;
80
81 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
82 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
83 RD_REG_WORD(&reg->hccr);
84
85 /* Get mailbox data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -070086 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
87 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080088 qla2x00_mbx_completion(vha, mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 status |= MBX_INTERRUPT;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070090 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
91 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
92 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
93 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080094 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 } else {
96 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -070097 ql_dbg(ql_dbg_async, vha, 0x5025,
98 "Unrecognized interrupt type (%d).\n",
99 mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 }
101 /* Release mailbox registers. */
102 WRT_REG_WORD(&reg->semaphore, 0);
103 RD_REG_WORD(&reg->semaphore);
104 } else {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800105 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
108 RD_REG_WORD(&reg->hccr);
109 }
110 }
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -0700111 qla2x00_handle_mbx_completion(ha, status);
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700112 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 return (IRQ_HANDLED);
115}
116
Chad Dupuisf3ddac12013-10-30 03:38:16 -0400117bool
Joe Lawrencec821e0d2014-08-26 17:11:41 -0400118qla2x00_check_reg32_for_disconnect(scsi_qla_host_t *vha, uint32_t reg)
Chad Dupuisf3ddac12013-10-30 03:38:16 -0400119{
120 /* Check for PCI disconnection */
Thadeu Lima de Souza Cascardoa30c2a32015-04-30 09:13:05 -0300121 if (reg == 0xffffffff && !pci_channel_offline(vha->hw->pdev)) {
Joe Lawrencebeb9e312014-08-26 17:12:14 -0400122 if (!test_and_set_bit(PFLG_DISCONNECTED, &vha->pci_flags) &&
Joe Lawrence6b383972014-08-26 17:12:29 -0400123 !test_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags) &&
124 !test_bit(PFLG_DRIVER_PROBING, &vha->pci_flags)) {
Joe Lawrence232792b2014-08-26 17:12:01 -0400125 /*
126 * Schedule this (only once) on the default system
127 * workqueue so that all the adapter workqueues and the
128 * DPC thread can be shutdown cleanly.
129 */
130 schedule_work(&vha->hw->board_disable);
131 }
Chad Dupuisf3ddac12013-10-30 03:38:16 -0400132 return true;
133 } else
134 return false;
135}
136
Joe Lawrencec821e0d2014-08-26 17:11:41 -0400137bool
138qla2x00_check_reg16_for_disconnect(scsi_qla_host_t *vha, uint16_t reg)
139{
140 return qla2x00_check_reg32_for_disconnect(vha, 0xffff0000 | reg);
141}
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143/**
144 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
145 * @irq:
146 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 *
148 * Called by system whenever the host adapter generates an interrupt.
149 *
150 * Returns handled flag.
151 */
152irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100153qla2300_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800155 scsi_qla_host_t *vha;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700156 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 unsigned long iter;
159 uint32_t stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700161 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800162 struct rsp_que *rsp;
163 struct qla_hw_data *ha;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700164 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800166 rsp = (struct rsp_que *) dev_id;
167 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -0800168 ql_log(ql_log_info, NULL, 0x5058,
169 "%s: NULL response queue pointer.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 return (IRQ_NONE);
171 }
172
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800173 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700174 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 status = 0;
176
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700177 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700178 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 for (iter = 50; iter--; ) {
180 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
Joe Lawrencec821e0d2014-08-26 17:11:41 -0400181 if (qla2x00_check_reg32_for_disconnect(vha, stat))
Chad Dupuisf3ddac12013-10-30 03:38:16 -0400182 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 if (stat & HSR_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800184 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -0700185 break;
186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 hccr = RD_REG_WORD(&reg->hccr);
Chad Dupuisf3ddac12013-10-30 03:38:16 -0400188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700190 ql_log(ql_log_warn, vha, 0x5026,
191 "Parity error -- HCCR=%x, Dumping "
192 "firmware.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700194 ql_log(ql_log_warn, vha, 0x5027,
195 "RISC paused -- HCCR=%x, Dumping "
196 "firmware.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 /*
199 * Issue a "HARD" reset in order for the RISC
200 * interrupt bit to be cleared. Schedule a big
Justin P. Mattocka06a0f82011-06-23 23:22:27 -0700201 * hammer to get out of the RISC PAUSED state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 */
203 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
204 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800205
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800206 ha->isp_ops->fw_dump(vha, 1);
207 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 break;
209 } else if ((stat & HSR_RISC_INT) == 0)
210 break;
211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 case 0x1:
214 case 0x2:
215 case 0x10:
216 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800217 qla2x00_mbx_completion(vha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 status |= MBX_INTERRUPT;
219
220 /* Release mailbox registers. */
221 WRT_REG_WORD(&reg->semaphore, 0);
222 break;
223 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700224 mb[0] = MSW(stat);
225 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
226 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
227 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800228 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700229 break;
230 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800231 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 break;
233 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700234 mb[0] = MBA_CMPLT_1_16BIT;
235 mb[1] = MSW(stat);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800236 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 break;
238 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700239 mb[0] = MBA_SCSI_COMPLETION;
240 mb[1] = MSW(stat);
241 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800242 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 break;
244 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700245 ql_dbg(ql_dbg_async, vha, 0x5028,
246 "Unrecognized interrupt type (%d).\n", stat & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 break;
248 }
249 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
250 RD_REG_WORD_RELAXED(&reg->hccr);
251 }
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -0700252 qla2x00_handle_mbx_completion(ha, status);
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700253 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 return (IRQ_HANDLED);
256}
257
258/**
259 * qla2x00_mbx_completion() - Process mailbox command completions.
260 * @ha: SCSI driver HA context
261 * @mb0: Mailbox0 register
262 */
263static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800264qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
266 uint16_t cnt;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800267 uint32_t mboxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800269 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700270 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800272 /* Read all mbox registers? */
273 mboxes = (1 << ha->mbx_count) - 1;
274 if (!ha->mcp)
Masanari Iidaa7201012012-11-21 02:40:42 -0500275 ql_dbg(ql_dbg_async, vha, 0x5001, "MBX pointer ERROR.\n");
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800276 else
277 mboxes = ha->mcp->in_mb;
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 /* Load return mailbox registers. */
280 ha->flags.mbox_int = 1;
281 ha->mailbox_out[0] = mb0;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800282 mboxes >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
284
285 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700286 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800288 if ((cnt == 4 || cnt == 5) && (mboxes & BIT_0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800290 else if (mboxes & BIT_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 wptr++;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800294 mboxes >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296}
297
Andrew Vasquez8a659572009-02-08 20:50:12 -0800298static void
299qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
300{
301 static char *event[] =
302 { "Complete", "Request Notification", "Time Extension" };
303 int rval;
304 struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
Chad Dupuis9e5054e2013-10-30 03:38:23 -0400305 struct device_reg_82xx __iomem *reg82 = &vha->hw->iobase->isp82;
Andrew Vasquez8a659572009-02-08 20:50:12 -0800306 uint16_t __iomem *wptr;
307 uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
308
309 /* Seed data -- mailbox1 -> mailbox7. */
Chad Dupuis9e5054e2013-10-30 03:38:23 -0400310 if (IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw))
311 wptr = (uint16_t __iomem *)&reg24->mailbox1;
312 else if (IS_QLA8044(vha->hw))
313 wptr = (uint16_t __iomem *)&reg82->mailbox_out[1];
314 else
315 return;
316
Andrew Vasquez8a659572009-02-08 20:50:12 -0800317 for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
318 mb[cnt] = RD_REG_WORD(wptr);
319
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700320 ql_dbg(ql_dbg_async, vha, 0x5021,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800321 "Inter-Driver Communication %s -- "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700322 "%04x %04x %04x %04x %04x %04x %04x.\n",
323 event[aen & 0xff], mb[0], mb[1], mb[2], mb[3],
324 mb[4], mb[5], mb[6]);
Santosh Vernekar454073c2013-08-27 01:37:48 -0400325 switch (aen) {
326 /* Handle IDC Error completion case. */
327 case MBA_IDC_COMPLETE:
328 if (mb[1] >> 15) {
329 vha->hw->flags.idc_compl_status = 1;
Chad Dupuis9aaf2ce2013-10-30 03:38:25 -0400330 if (vha->hw->notify_dcbx_comp && !vha->vp_idx)
Santosh Vernekar454073c2013-08-27 01:37:48 -0400331 complete(&vha->hw->dcbx_comp);
332 }
333 break;
334
335 case MBA_IDC_NOTIFY:
336 /* Acknowledgement needed? [Notify && non-zero timeout]. */
337 timeout = (descr >> 8) & 0xf;
338 ql_dbg(ql_dbg_async, vha, 0x5022,
339 "%lu Inter-Driver Communication %s -- ACK timeout=%d.\n",
340 vha->host_no, event[aen & 0xff], timeout);
341
342 if (!timeout)
343 return;
344 rval = qla2x00_post_idc_ack_work(vha, mb);
345 if (rval != QLA_SUCCESS)
346 ql_log(ql_log_warn, vha, 0x5023,
347 "IDC failed to post ACK.\n");
348 break;
349 case MBA_IDC_TIME_EXT:
350 vha->hw->idc_extend_tmo = descr;
351 ql_dbg(ql_dbg_async, vha, 0x5087,
352 "%lu Inter-Driver Communication %s -- "
353 "Extend timeout by=%d.\n",
354 vha->host_no, event[aen & 0xff], vha->hw->idc_extend_tmo);
355 break;
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400356 }
Andrew Vasquez8a659572009-02-08 20:50:12 -0800357}
358
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400359#define LS_UNKNOWN 2
Joe Carnucciod0297c92012-11-21 02:40:40 -0500360const char *
361qla2x00_get_link_speed_str(struct qla_hw_data *ha, uint16_t speed)
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400362{
Chad Dupuisf73cb692014-02-26 04:15:06 -0500363 static const char *const link_speeds[] = {
364 "1", "2", "?", "4", "8", "16", "32", "10"
Joe Carnucciod0297c92012-11-21 02:40:40 -0500365 };
Chad Dupuisf73cb692014-02-26 04:15:06 -0500366#define QLA_LAST_SPEED 7
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400367
368 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Joe Carnucciod0297c92012-11-21 02:40:40 -0500369 return link_speeds[0];
370 else if (speed == 0x13)
Chad Dupuisf73cb692014-02-26 04:15:06 -0500371 return link_speeds[QLA_LAST_SPEED];
372 else if (speed < QLA_LAST_SPEED)
Joe Carnucciod0297c92012-11-21 02:40:40 -0500373 return link_speeds[speed];
374 else
375 return link_speeds[LS_UNKNOWN];
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400376}
377
Saurav Kashyapfa492632012-11-21 02:40:29 -0500378static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400379qla83xx_handle_8200_aen(scsi_qla_host_t *vha, uint16_t *mb)
380{
381 struct qla_hw_data *ha = vha->hw;
382
383 /*
384 * 8200 AEN Interpretation:
385 * mb[0] = AEN code
386 * mb[1] = AEN Reason code
387 * mb[2] = LSW of Peg-Halt Status-1 Register
388 * mb[6] = MSW of Peg-Halt Status-1 Register
389 * mb[3] = LSW of Peg-Halt Status-2 register
390 * mb[7] = MSW of Peg-Halt Status-2 register
391 * mb[4] = IDC Device-State Register value
392 * mb[5] = IDC Driver-Presence Register value
393 */
394 ql_dbg(ql_dbg_async, vha, 0x506b, "AEN Code: mb[0] = 0x%x AEN reason: "
395 "mb[1] = 0x%x PH-status1: mb[2] = 0x%x PH-status1: mb[6] = 0x%x.\n",
396 mb[0], mb[1], mb[2], mb[6]);
397 ql_dbg(ql_dbg_async, vha, 0x506c, "PH-status2: mb[3] = 0x%x "
398 "PH-status2: mb[7] = 0x%x Device-State: mb[4] = 0x%x "
399 "Drv-Presence: mb[5] = 0x%x.\n", mb[3], mb[7], mb[4], mb[5]);
400
401 if (mb[1] & (IDC_PEG_HALT_STATUS_CHANGE | IDC_NIC_FW_REPORTED_FAILURE |
402 IDC_HEARTBEAT_FAILURE)) {
403 ha->flags.nic_core_hung = 1;
404 ql_log(ql_log_warn, vha, 0x5060,
405 "83XX: F/W Error Reported: Check if reset required.\n");
406
407 if (mb[1] & IDC_PEG_HALT_STATUS_CHANGE) {
408 uint32_t protocol_engine_id, fw_err_code, err_level;
409
410 /*
411 * IDC_PEG_HALT_STATUS_CHANGE interpretation:
412 * - PEG-Halt Status-1 Register:
413 * (LSW = mb[2], MSW = mb[6])
414 * Bits 0-7 = protocol-engine ID
415 * Bits 8-28 = f/w error code
416 * Bits 29-31 = Error-level
417 * Error-level 0x1 = Non-Fatal error
418 * Error-level 0x2 = Recoverable Fatal error
419 * Error-level 0x4 = UnRecoverable Fatal error
420 * - PEG-Halt Status-2 Register:
421 * (LSW = mb[3], MSW = mb[7])
422 */
423 protocol_engine_id = (mb[2] & 0xff);
424 fw_err_code = (((mb[2] & 0xff00) >> 8) |
425 ((mb[6] & 0x1fff) << 8));
426 err_level = ((mb[6] & 0xe000) >> 13);
427 ql_log(ql_log_warn, vha, 0x5061, "PegHalt Status-1 "
428 "Register: protocol_engine_id=0x%x "
429 "fw_err_code=0x%x err_level=0x%x.\n",
430 protocol_engine_id, fw_err_code, err_level);
431 ql_log(ql_log_warn, vha, 0x5062, "PegHalt Status-2 "
432 "Register: 0x%x%x.\n", mb[7], mb[3]);
433 if (err_level == ERR_LEVEL_NON_FATAL) {
434 ql_log(ql_log_warn, vha, 0x5063,
Colin Ian King0bf0efa2017-06-30 14:47:41 +0100435 "Not a fatal error, f/w has recovered itself.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400436 } else if (err_level == ERR_LEVEL_RECOVERABLE_FATAL) {
437 ql_log(ql_log_fatal, vha, 0x5064,
438 "Recoverable Fatal error: Chip reset "
439 "required.\n");
440 qla83xx_schedule_work(vha,
441 QLA83XX_NIC_CORE_RESET);
442 } else if (err_level == ERR_LEVEL_UNRECOVERABLE_FATAL) {
443 ql_log(ql_log_fatal, vha, 0x5065,
444 "Unrecoverable Fatal error: Set FAILED "
445 "state, reboot required.\n");
446 qla83xx_schedule_work(vha,
447 QLA83XX_NIC_CORE_UNRECOVERABLE);
448 }
449 }
450
451 if (mb[1] & IDC_NIC_FW_REPORTED_FAILURE) {
452 uint16_t peg_fw_state, nw_interface_link_up;
453 uint16_t nw_interface_signal_detect, sfp_status;
454 uint16_t htbt_counter, htbt_monitor_enable;
455 uint16_t sfp_additonal_info, sfp_multirate;
456 uint16_t sfp_tx_fault, link_speed, dcbx_status;
457
458 /*
459 * IDC_NIC_FW_REPORTED_FAILURE interpretation:
460 * - PEG-to-FC Status Register:
461 * (LSW = mb[2], MSW = mb[6])
462 * Bits 0-7 = Peg-Firmware state
463 * Bit 8 = N/W Interface Link-up
464 * Bit 9 = N/W Interface signal detected
465 * Bits 10-11 = SFP Status
466 * SFP Status 0x0 = SFP+ transceiver not expected
467 * SFP Status 0x1 = SFP+ transceiver not present
468 * SFP Status 0x2 = SFP+ transceiver invalid
469 * SFP Status 0x3 = SFP+ transceiver present and
470 * valid
471 * Bits 12-14 = Heartbeat Counter
472 * Bit 15 = Heartbeat Monitor Enable
473 * Bits 16-17 = SFP Additional Info
474 * SFP info 0x0 = Unregocnized transceiver for
475 * Ethernet
476 * SFP info 0x1 = SFP+ brand validation failed
477 * SFP info 0x2 = SFP+ speed validation failed
478 * SFP info 0x3 = SFP+ access error
479 * Bit 18 = SFP Multirate
480 * Bit 19 = SFP Tx Fault
481 * Bits 20-22 = Link Speed
482 * Bits 23-27 = Reserved
483 * Bits 28-30 = DCBX Status
484 * DCBX Status 0x0 = DCBX Disabled
485 * DCBX Status 0x1 = DCBX Enabled
486 * DCBX Status 0x2 = DCBX Exchange error
487 * Bit 31 = Reserved
488 */
489 peg_fw_state = (mb[2] & 0x00ff);
490 nw_interface_link_up = ((mb[2] & 0x0100) >> 8);
491 nw_interface_signal_detect = ((mb[2] & 0x0200) >> 9);
492 sfp_status = ((mb[2] & 0x0c00) >> 10);
493 htbt_counter = ((mb[2] & 0x7000) >> 12);
494 htbt_monitor_enable = ((mb[2] & 0x8000) >> 15);
495 sfp_additonal_info = (mb[6] & 0x0003);
496 sfp_multirate = ((mb[6] & 0x0004) >> 2);
497 sfp_tx_fault = ((mb[6] & 0x0008) >> 3);
498 link_speed = ((mb[6] & 0x0070) >> 4);
499 dcbx_status = ((mb[6] & 0x7000) >> 12);
500
501 ql_log(ql_log_warn, vha, 0x5066,
502 "Peg-to-Fc Status Register:\n"
503 "peg_fw_state=0x%x, nw_interface_link_up=0x%x, "
504 "nw_interface_signal_detect=0x%x"
505 "\nsfp_statis=0x%x.\n ", peg_fw_state,
506 nw_interface_link_up, nw_interface_signal_detect,
507 sfp_status);
508 ql_log(ql_log_warn, vha, 0x5067,
509 "htbt_counter=0x%x, htbt_monitor_enable=0x%x, "
510 "sfp_additonal_info=0x%x, sfp_multirate=0x%x.\n ",
511 htbt_counter, htbt_monitor_enable,
512 sfp_additonal_info, sfp_multirate);
513 ql_log(ql_log_warn, vha, 0x5068,
514 "sfp_tx_fault=0x%x, link_state=0x%x, "
515 "dcbx_status=0x%x.\n", sfp_tx_fault, link_speed,
516 dcbx_status);
517
518 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
519 }
520
521 if (mb[1] & IDC_HEARTBEAT_FAILURE) {
522 ql_log(ql_log_warn, vha, 0x5069,
523 "Heartbeat Failure encountered, chip reset "
524 "required.\n");
525
526 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
527 }
528 }
529
530 if (mb[1] & IDC_DEVICE_STATE_CHANGE) {
531 ql_log(ql_log_info, vha, 0x506a,
532 "IDC Device-State changed = 0x%x.\n", mb[4]);
Saurav Kashyap6c3943c2013-02-08 01:58:02 -0500533 if (ha->flags.nic_core_reset_owner)
534 return;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400535 qla83xx_schedule_work(vha, MBA_IDC_AEN);
536 }
537}
538
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -0500539int
540qla2x00_is_a_vp_did(scsi_qla_host_t *vha, uint32_t rscn_entry)
541{
542 struct qla_hw_data *ha = vha->hw;
543 scsi_qla_host_t *vp;
544 uint32_t vp_did;
545 unsigned long flags;
546 int ret = 0;
547
548 if (!ha->num_vhosts)
549 return ret;
550
551 spin_lock_irqsave(&ha->vport_slock, flags);
552 list_for_each_entry(vp, &ha->vp_list, list) {
553 vp_did = vp->d_id.b24;
554 if (vp_did == rscn_entry) {
555 ret = 1;
556 break;
557 }
558 }
559 spin_unlock_irqrestore(&ha->vport_slock, flags);
560
561 return ret;
562}
563
Quinn Tran726b8542017-01-19 22:28:00 -0800564fc_port_t *
Joe Carnuccio17cac3a2015-08-04 13:37:52 -0400565qla2x00_find_fcport_by_loopid(scsi_qla_host_t *vha, uint16_t loop_id)
566{
Quinn Tran726b8542017-01-19 22:28:00 -0800567 fc_port_t *f, *tf;
Joe Carnuccio17cac3a2015-08-04 13:37:52 -0400568
Quinn Tran726b8542017-01-19 22:28:00 -0800569 f = tf = NULL;
570 list_for_each_entry_safe(f, tf, &vha->vp_fcports, list)
571 if (f->loop_id == loop_id)
572 return f;
573 return NULL;
574}
575
576fc_port_t *
577qla2x00_find_fcport_by_wwpn(scsi_qla_host_t *vha, u8 *wwpn, u8 incl_deleted)
578{
579 fc_port_t *f, *tf;
580
581 f = tf = NULL;
582 list_for_each_entry_safe(f, tf, &vha->vp_fcports, list) {
583 if (memcmp(f->port_name, wwpn, WWN_SIZE) == 0) {
584 if (incl_deleted)
585 return f;
586 else if (f->deleted == 0)
587 return f;
588 }
589 }
590 return NULL;
591}
592
593fc_port_t *
594qla2x00_find_fcport_by_nportid(scsi_qla_host_t *vha, port_id_t *id,
595 u8 incl_deleted)
596{
597 fc_port_t *f, *tf;
598
599 f = tf = NULL;
600 list_for_each_entry_safe(f, tf, &vha->vp_fcports, list) {
601 if (f->d_id.b24 == id->b24) {
602 if (incl_deleted)
603 return f;
604 else if (f->deleted == 0)
605 return f;
606 }
607 }
Joe Carnuccio17cac3a2015-08-04 13:37:52 -0400608 return NULL;
609}
610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611/**
612 * qla2x00_async_event() - Process aynchronous events.
613 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700614 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700616void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800617qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 uint16_t handle_cnt;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700620 uint16_t cnt, mbx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 uint32_t handles[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800622 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700623 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700624 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
Andrew Vasquezbc5c2aa2010-12-21 16:00:24 -0800625 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Bart Van Assche52c82822015-07-09 07:23:26 -0700626 uint32_t rscn_entry, host_pid;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700627 unsigned long flags;
Chad Dupuisef86cb22014-09-25 05:17:01 -0400628 fc_port_t *fcport = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
630 /* Setup to process RIO completion. */
631 handle_cnt = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800632 if (IS_CNA_CAPABLE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800633 goto skip_rio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 switch (mb[0]) {
635 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700636 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 handle_cnt = 1;
638 break;
639 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700640 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 handle_cnt = 1;
642 mb[0] = MBA_SCSI_COMPLETION;
643 break;
644 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700645 handles[0] = mb[1];
646 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 handle_cnt = 2;
648 mb[0] = MBA_SCSI_COMPLETION;
649 break;
650 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700651 handles[0] = mb[1];
652 handles[1] = mb[2];
653 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 handle_cnt = 3;
655 mb[0] = MBA_SCSI_COMPLETION;
656 break;
657 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700658 handles[0] = mb[1];
659 handles[1] = mb[2];
660 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
662 handle_cnt = 4;
663 mb[0] = MBA_SCSI_COMPLETION;
664 break;
665 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700666 handles[0] = mb[1];
667 handles[1] = mb[2];
668 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
670 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
671 handle_cnt = 5;
672 mb[0] = MBA_SCSI_COMPLETION;
673 break;
674 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700675 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 handles[1] = le32_to_cpu(
677 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
678 RD_MAILBOX_REG(ha, reg, 6));
679 handle_cnt = 2;
680 mb[0] = MBA_SCSI_COMPLETION;
681 break;
682 default:
683 break;
684 }
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800685skip_rio:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 switch (mb[0]) {
687 case MBA_SCSI_COMPLETION: /* Fast Post */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800688 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 break;
690
691 for (cnt = 0; cnt < handle_cnt; cnt++)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800692 qla2x00_process_completed_request(vha, rsp->req,
693 handles[cnt]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 break;
695
696 case MBA_RESET: /* Reset */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700697 ql_dbg(ql_dbg_async, vha, 0x5002,
698 "Asynchronous RESET.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800700 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 break;
702
703 case MBA_SYSTEM_ERR: /* System Error */
Chad Dupuisf73cb692014-02-26 04:15:06 -0500704 mbx = (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) ?
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800705 RD_REG_WORD(&reg24->mailbox7) : 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700706 ql_log(ql_log_warn, vha, 0x5003,
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700707 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh "
708 "mbx7=%xh.\n", mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800710 ha->isp_ops->fw_dump(vha, 1);
Quinn Tranec7193e2017-03-15 09:48:55 -0700711 ha->flags.fw_init_done = 0;
Quinn Tran4b60c822017-06-13 20:47:21 -0700712 QLA_FW_STOPPED(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Andrew Vasqueze4289242007-07-19 15:05:56 -0700714 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700715 if (mb[1] == 0 && mb[2] == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700716 ql_log(ql_log_fatal, vha, 0x5004,
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700717 "Unrecoverable Hardware Error: adapter "
718 "marked OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800719 vha->flags.online = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800720 vha->device_flags |= DFLG_DEV_FAILED;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700721 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300722 /* Check to see if MPI timeout occurred */
Chad Dupuisf73cb692014-02-26 04:15:06 -0500723 if ((mbx & MBX_3) && (ha->port_no == 0))
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700724 set_bit(MPI_RESET_NEEDED,
725 &vha->dpc_flags);
726
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800727 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700728 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700729 } else if (mb[1] == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700730 ql_log(ql_log_fatal, vha, 0x5005,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 "Unrecoverable Hardware Error: adapter marked "
732 "OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800733 vha->flags.online = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800734 vha->device_flags |= DFLG_DEV_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800736 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 break;
738
739 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700740 ql_log(ql_log_warn, vha, 0x5006,
741 "ISP Request Transfer Error (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800743 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 break;
745
746 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700747 ql_log(ql_log_warn, vha, 0x5007,
Joe Carnuccio41233cd2016-07-06 11:14:29 -0400748 "ISP Response Transfer Error (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800750 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 break;
752
753 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700754 ql_dbg(ql_dbg_async, vha, 0x5008,
Joe Carnuccio41233cd2016-07-06 11:14:29 -0400755 "Asynchronous WAKEUP_THRES (%x).\n", mb[1]);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400756 break;
Joe Carnuccio41233cd2016-07-06 11:14:29 -0400757
758 case MBA_LOOP_INIT_ERR:
Sawan Chandak75d560e2016-07-06 11:14:33 -0400759 ql_log(ql_log_warn, vha, 0x5090,
Joe Carnuccio41233cd2016-07-06 11:14:29 -0400760 "LOOP INIT ERROR (%x).\n", mb[1]);
761 ha->isp_ops->fw_dump(vha, 1);
762 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
763 break;
764
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Quinn Tranec7193e2017-03-15 09:48:55 -0700766 ha->flags.lip_ae = 1;
767 ha->flags.n2n_ae = 0;
768
Chad Dupuiscfb09192011-11-18 09:03:07 -0800769 ql_dbg(ql_dbg_async, vha, 0x5009,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700770 "LIP occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800772 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
773 atomic_set(&vha->loop_state, LOOP_DOWN);
774 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
775 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 }
777
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800778 if (vha->vp_idx) {
779 atomic_set(&vha->vp_state, VP_FAILED);
780 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700781 }
782
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800783 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
784 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800786 vha->flags.management_server_logged_in = 0;
787 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 break;
789
790 case MBA_LOOP_UP: /* Loop Up Event */
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400791 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700792 ha->link_data_rate = PORT_SPEED_1GB;
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400793 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 ha->link_data_rate = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Chad Dupuis8e5a9482014-08-08 07:38:09 -0400796 ql_log(ql_log_info, vha, 0x500a,
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400797 "LOOP UP detected (%s Gbps).\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -0500798 qla2x00_get_link_speed_str(ha, ha->link_data_rate));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800800 vha->flags.management_server_logged_in = 0;
801 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 break;
803
804 case MBA_LOOP_DOWN: /* Loop Down Event */
Quinn Tranec7193e2017-03-15 09:48:55 -0700805 ha->flags.n2n_ae = 0;
806 ha->flags.lip_ae = 0;
807 ha->current_topology = 0;
808
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800809 mbx = (IS_QLA81XX(ha) || IS_QLA8031(ha))
810 ? RD_REG_WORD(&reg24->mailbox4) : 0;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400811 mbx = (IS_P3P_TYPE(ha)) ? RD_REG_WORD(&reg82->mailbox_out[4])
812 : mbx;
Chad Dupuis8e5a9482014-08-08 07:38:09 -0400813 ql_log(ql_log_info, vha, 0x500b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700814 "LOOP DOWN detected (%x %x %x %x).\n",
815 mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800817 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
818 atomic_set(&vha->loop_state, LOOP_DOWN);
819 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
Himanshu Madhani2486c622014-09-25 05:17:00 -0400820 /*
821 * In case of loop down, restore WWPN from
822 * NVRAM in case of FA-WWPN capable ISP
Sawan Chandak718abbd2015-04-09 15:00:07 -0400823 * Restore for Physical Port only
Himanshu Madhani2486c622014-09-25 05:17:00 -0400824 */
Sawan Chandak718abbd2015-04-09 15:00:07 -0400825 if (!vha->vp_idx) {
826 if (ha->flags.fawwpn_enabled) {
827 void *wwpn = ha->init_cb->port_name;
828 memcpy(vha->port_name, wwpn, WWN_SIZE);
829 fc_host_port_name(vha->host) =
830 wwn_to_u64(vha->port_name);
831 ql_dbg(ql_dbg_init + ql_dbg_verbose,
Quinn Tran83548fe2017-06-02 09:12:01 -0700832 vha, 0x00d8, "LOOP DOWN detected,"
Sawan Chandak718abbd2015-04-09 15:00:07 -0400833 "restore WWPN %016llx\n",
834 wwn_to_u64(vha->port_name));
835 }
Himanshu Madhani2486c622014-09-25 05:17:00 -0400836
Sawan Chandak718abbd2015-04-09 15:00:07 -0400837 clear_bit(VP_CONFIG_OK, &vha->vp_flags);
Himanshu Madhani2486c622014-09-25 05:17:00 -0400838 }
839
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800840 vha->device_flags |= DFLG_NO_CABLE;
841 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 }
843
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800844 if (vha->vp_idx) {
845 atomic_set(&vha->vp_state, VP_FAILED);
846 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700847 }
848
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800849 vha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700850 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800851 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 break;
853
854 case MBA_LIP_RESET: /* LIP reset occurred */
Chad Dupuiscfb09192011-11-18 09:03:07 -0800855 ql_dbg(ql_dbg_async, vha, 0x500c,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700856 "LIP reset occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800858 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
859 atomic_set(&vha->loop_state, LOOP_DOWN);
860 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
861 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 }
863
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800864 if (vha->vp_idx) {
865 atomic_set(&vha->vp_state, VP_FAILED);
866 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700867 }
868
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800869 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
871 ha->operating_mode = LOOP;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800872 vha->flags.management_server_logged_in = 0;
873 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 break;
875
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800876 /* case MBA_DCBX_COMPLETE: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 case MBA_POINT_TO_POINT: /* Point-to-Point */
Quinn Tranec7193e2017-03-15 09:48:55 -0700878 ha->flags.lip_ae = 0;
879 ha->flags.n2n_ae = 1;
880
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 if (IS_QLA2100(ha))
882 break;
883
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400884 if (IS_CNA_CAPABLE(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700885 ql_dbg(ql_dbg_async, vha, 0x500d,
886 "DCBX Completed -- %04x %04x %04x.\n",
887 mb[1], mb[2], mb[3]);
Chad Dupuis9aaf2ce2013-10-30 03:38:25 -0400888 if (ha->notify_dcbx_comp && !vha->vp_idx)
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700889 complete(&ha->dcbx_comp);
890
891 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700892 ql_dbg(ql_dbg_async, vha, 0x500e,
893 "Asynchronous P2P MODE received.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
895 /*
896 * Until there's a transition from loop down to loop up, treat
897 * this as loop down only.
898 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800899 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
900 atomic_set(&vha->loop_state, LOOP_DOWN);
901 if (!atomic_read(&vha->loop_down_timer))
902 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800904 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 }
906
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800907 if (vha->vp_idx) {
908 atomic_set(&vha->vp_state, VP_FAILED);
909 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700910 }
911
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800912 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
913 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
914
915 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
916 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800917
918 ha->flags.gpsc_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800919 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 break;
921
922 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
923 if (IS_QLA2100(ha))
924 break;
925
Chad Dupuiscfb09192011-11-18 09:03:07 -0800926 ql_dbg(ql_dbg_async, vha, 0x500f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 "Configuration change detected: value=%x.\n", mb[1]);
928
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800929 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
930 atomic_set(&vha->loop_state, LOOP_DOWN);
931 if (!atomic_read(&vha->loop_down_timer))
932 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800934 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 }
936
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800937 if (vha->vp_idx) {
938 atomic_set(&vha->vp_state, VP_FAILED);
939 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700940 }
941
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800942 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
943 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 break;
945
946 case MBA_PORT_UPDATE: /* Port database update */
Santosh Vernekar55903b92009-07-31 15:09:25 -0700947 /*
948 * Handle only global and vn-port update events
949 *
950 * Relevant inputs:
951 * mb[1] = N_Port handle of changed port
952 * OR 0xffff for global event
953 * mb[2] = New login state
954 * 7 = Port logged out
955 * mb[3] = LSB is vp_idx, 0xff = all vps
956 *
957 * Skip processing if:
958 * Event is global, vp_idx is NOT all vps,
959 * vp_idx does not match
960 * Event is not global, vp_idx does not match
961 */
Andrew Vasquez12cec63e42010-03-19 16:59:17 -0700962 if (IS_QLA2XXX_MIDTYPE(ha) &&
963 ((mb[1] == 0xffff && (mb[3] & 0xff) != 0xff) ||
964 (mb[1] != 0xffff)) && vha->vp_idx != (mb[3] & 0xff))
965 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800966
Joe Carnuccio17cac3a2015-08-04 13:37:52 -0400967 if (mb[2] == 0x7) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700968 ql_dbg(ql_dbg_async, vha, 0x5010,
Joe Carnuccio17cac3a2015-08-04 13:37:52 -0400969 "Port %s %04x %04x %04x.\n",
970 mb[1] == 0xffff ? "unavailable" : "logout",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700971 mb[1], mb[2], mb[3]);
Joe Carnuccio17cac3a2015-08-04 13:37:52 -0400972
973 if (mb[1] == 0xffff)
974 goto global_port_update;
975
Quinn Tranb98ae0d2017-06-02 09:12:00 -0700976 if (mb[1] == NPH_SNS_LID(ha)) {
977 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
978 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
979 break;
980 }
981
982 /* use handle_cnt for loop id/nport handle */
983 if (IS_FWI2_CAPABLE(ha))
984 handle_cnt = NPH_SNS;
985 else
986 handle_cnt = SIMPLE_NAME_SERVER;
987 if (mb[1] == handle_cnt) {
988 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
989 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
990 break;
991 }
992
Joe Carnuccio17cac3a2015-08-04 13:37:52 -0400993 /* Port logout */
994 fcport = qla2x00_find_fcport_by_loopid(vha, mb[1]);
995 if (!fcport)
996 break;
997 if (atomic_read(&fcport->state) != FCS_ONLINE)
998 break;
999 ql_dbg(ql_dbg_async, vha, 0x508a,
1000 "Marking port lost loopid=%04x portid=%06x.\n",
1001 fcport->loop_id, fcport->d_id.b24);
Quinn Tran726b8542017-01-19 22:28:00 -08001002 if (qla_ini_mode_enabled(vha)) {
1003 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
1004 fcport->logout_on_delete = 0;
1005 qlt_schedule_sess_for_deletion_lock(fcport);
1006 }
Joe Carnuccio17cac3a2015-08-04 13:37:52 -04001007 break;
1008
1009global_port_update:
Andrew Vasquez9764ff82009-07-31 15:09:24 -07001010 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
1011 atomic_set(&vha->loop_state, LOOP_DOWN);
1012 atomic_set(&vha->loop_down_timer,
1013 LOOP_DOWN_TIME);
1014 vha->device_flags |= DFLG_NO_CABLE;
1015 qla2x00_mark_all_devices_lost(vha, 1);
1016 }
1017
1018 if (vha->vp_idx) {
1019 atomic_set(&vha->vp_state, VP_FAILED);
1020 fc_vport_set_state(vha->fc_vport,
1021 FC_VPORT_FAILED);
Santosh Vernekarfaadc5e2009-07-31 15:09:26 -07001022 qla2x00_mark_all_devices_lost(vha, 1);
Andrew Vasquez9764ff82009-07-31 15:09:24 -07001023 }
1024
1025 vha->flags.management_server_logged_in = 0;
1026 ha->link_data_rate = PORT_SPEED_UNKNOWN;
1027 break;
1028 }
1029
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 /*
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07001031 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 * event etc. earlier indicating loop is down) then process
1033 * it. Otherwise ignore it and Wait for RSCN to come in.
1034 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001035 atomic_set(&vha->loop_down_timer, 0);
Chad Dupuis8e5a9482014-08-08 07:38:09 -04001036 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
1037 atomic_read(&vha->loop_state) != LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001038 ql_dbg(ql_dbg_async, vha, 0x5011,
1039 "Asynchronous PORT UPDATE ignored %04x/%04x/%04x.\n",
1040 mb[1], mb[2], mb[3]);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001041
1042 qlt_async_event(mb[0], vha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 break;
1044 }
1045
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001046 ql_dbg(ql_dbg_async, vha, 0x5012,
1047 "Port database changed %04x %04x %04x.\n",
1048 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
1050 /*
1051 * Mark all devices as missing so we will login again.
1052 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001053 atomic_set(&vha->loop_state, LOOP_UP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001055 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001057 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1058 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Sawan Chandakded64112015-04-09 15:00:06 -04001059 set_bit(VP_CONFIG_OK, &vha->vp_flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001060
1061 qlt_async_event(mb[0], vha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 break;
1063
1064 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju3c397402008-05-19 14:25:39 -07001065 /* Check if the Vport has issued a SCR */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001066 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
Seokmann Ju3c397402008-05-19 14:25:39 -07001067 break;
1068 /* Only handle SCNs for our Vport index. */
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001069 if (ha->flags.npiv_supported && vha->vp_idx != (mb[3] & 0xff))
Seokmann Ju3c397402008-05-19 14:25:39 -07001070 break;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001071
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001072 ql_dbg(ql_dbg_async, vha, 0x5013,
1073 "RSCN database changed -- %04x %04x %04x.\n",
1074 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
Ravi Anand59d72d82008-09-11 21:22:53 -07001076 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001077 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
1078 | vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 if (rscn_entry == host_pid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001080 ql_dbg(ql_dbg_async, vha, 0x5014,
1081 "Ignoring RSCN update to local host "
1082 "port ID (%06x).\n", host_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 break;
1084 }
1085
Ravi Anand59d72d82008-09-11 21:22:53 -07001086 /* Ignore reserved bits from RSCN-payload. */
1087 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05001089 /* Skip RSCNs for virtual ports on the same physical port */
1090 if (qla2x00_is_a_vp_did(vha, rscn_entry))
1091 break;
1092
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001093 atomic_set(&vha->loop_down_timer, 0);
1094 vha->flags.management_server_logged_in = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08001095 {
1096 struct event_arg ea;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
Quinn Tran726b8542017-01-19 22:28:00 -08001098 memset(&ea, 0, sizeof(ea));
1099 ea.event = FCME_RSCN;
1100 ea.id.b24 = rscn_entry;
Quinn Tran41dc5292017-01-19 22:28:03 -08001101 ea.id.b.rsvd_1 = rscn_entry >> 24;
Quinn Tran726b8542017-01-19 22:28:00 -08001102 qla2x00_fcport_event_handler(vha, &ea);
Quinn Tran41dc5292017-01-19 22:28:03 -08001103 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
Quinn Tran726b8542017-01-19 22:28:00 -08001104 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 /* case MBA_RIO_RESPONSE: */
1107 case MBA_ZIO_RESPONSE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001108 ql_dbg(ql_dbg_async, vha, 0x5015,
1109 "[R|Z]IO update completion.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110
Andrew Vasqueze4289242007-07-19 15:05:56 -07001111 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001112 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001113 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001114 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001116
1117 case MBA_DISCARD_RND_FRAME:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001118 ql_dbg(ql_dbg_async, vha, 0x5016,
1119 "Discard RND Frame -- %04x %04x %04x.\n",
1120 mb[1], mb[2], mb[3]);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001121 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -07001122
1123 case MBA_TRACE_NOTIFICATION:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001124 ql_dbg(ql_dbg_async, vha, 0x5017,
1125 "Trace Notification -- %04x %04x.\n", mb[1], mb[2]);
Andrew Vasquez45ebeb52006-08-01 13:48:14 -07001126 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001127
1128 case MBA_ISP84XX_ALERT:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001129 ql_dbg(ql_dbg_async, vha, 0x5018,
1130 "ISP84XX Alert Notification -- %04x %04x %04x.\n",
1131 mb[1], mb[2], mb[3]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001132
1133 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
1134 switch (mb[1]) {
1135 case A84_PANIC_RECOVERY:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001136 ql_log(ql_log_info, vha, 0x5019,
1137 "Alert 84XX: panic recovery %04x %04x.\n",
1138 mb[2], mb[3]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001139 break;
1140 case A84_OP_LOGIN_COMPLETE:
1141 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001142 ql_log(ql_log_info, vha, 0x501a,
1143 "Alert 84XX: firmware version %x.\n",
1144 ha->cs84xx->op_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001145 break;
1146 case A84_DIAG_LOGIN_COMPLETE:
1147 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001148 ql_log(ql_log_info, vha, 0x501b,
1149 "Alert 84XX: diagnostic firmware version %x.\n",
1150 ha->cs84xx->diag_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001151 break;
1152 case A84_GOLD_LOGIN_COMPLETE:
1153 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
1154 ha->cs84xx->fw_update = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001155 ql_log(ql_log_info, vha, 0x501c,
1156 "Alert 84XX: gold firmware version %x.\n",
1157 ha->cs84xx->gold_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001158 break;
1159 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001160 ql_log(ql_log_warn, vha, 0x501d,
1161 "Alert 84xx: Invalid Alert %04x %04x %04x.\n",
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001162 mb[1], mb[2], mb[3]);
1163 }
1164 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
1165 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001166 case MBA_DCBX_START:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001167 ql_dbg(ql_dbg_async, vha, 0x501e,
1168 "DCBX Started -- %04x %04x %04x.\n",
1169 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001170 break;
1171 case MBA_DCBX_PARAM_UPDATE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001172 ql_dbg(ql_dbg_async, vha, 0x501f,
1173 "DCBX Parameters Updated -- %04x %04x %04x.\n",
1174 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001175 break;
1176 case MBA_FCF_CONF_ERR:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001177 ql_dbg(ql_dbg_async, vha, 0x5020,
1178 "FCF Configuration Error -- %04x %04x %04x.\n",
1179 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001180 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001181 case MBA_IDC_NOTIFY:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001182 if (IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
Chad Dupuis67b2a312013-02-08 01:57:51 -05001183 mb[4] = RD_REG_WORD(&reg24->mailbox4);
1184 if (((mb[2] & 0x7fff) == MBC_PORT_RESET ||
1185 (mb[2] & 0x7fff) == MBC_SET_PORT_CONFIG) &&
1186 (mb[4] & INTERNAL_LOOPBACK_MASK) != 0) {
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04001187 set_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags);
Chad Dupuis67b2a312013-02-08 01:57:51 -05001188 /*
1189 * Extend loop down timer since port is active.
1190 */
1191 if (atomic_read(&vha->loop_state) == LOOP_DOWN)
1192 atomic_set(&vha->loop_down_timer,
1193 LOOP_DOWN_TIME);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04001194 qla2xxx_wake_dpc(vha);
1195 }
Chad Dupuis67b2a312013-02-08 01:57:51 -05001196 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04001197 case MBA_IDC_COMPLETE:
Chad Dupuis9aaf2ce2013-10-30 03:38:25 -04001198 if (ha->notify_lb_portup_comp && !vha->vp_idx)
Chad Dupuisf356bef2013-02-08 01:58:04 -05001199 complete(&ha->lb_portup_comp);
1200 /* Fallthru */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001201 case MBA_IDC_TIME_EXT:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001202 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) ||
1203 IS_QLA8044(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001204 qla81xx_idc_event(vha, mb[0], mb[1]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001205 break;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001206
1207 case MBA_IDC_AEN:
1208 mb[4] = RD_REG_WORD(&reg24->mailbox4);
1209 mb[5] = RD_REG_WORD(&reg24->mailbox5);
1210 mb[6] = RD_REG_WORD(&reg24->mailbox6);
1211 mb[7] = RD_REG_WORD(&reg24->mailbox7);
1212 qla83xx_handle_8200_aen(vha, mb);
1213 break;
1214
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001215 case MBA_DPORT_DIAGNOSTICS:
1216 ql_dbg(ql_dbg_async, vha, 0x5052,
Joe Carnuccioef55e512016-07-06 11:14:30 -04001217 "D-Port Diagnostics: %04x result=%s\n",
Joe Carnuccioec891462016-07-06 11:14:26 -04001218 mb[0],
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001219 mb[1] == 0 ? "start" :
Joe Carnuccioef55e512016-07-06 11:14:30 -04001220 mb[1] == 1 ? "done (pass)" :
1221 mb[1] == 2 ? "done (error)" : "other");
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001222 break;
1223
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04001224 case MBA_TEMPERATURE_ALERT:
1225 ql_dbg(ql_dbg_async, vha, 0x505e,
1226 "TEMPERATURE ALERT: %04x %04x %04x\n", mb[1], mb[2], mb[3]);
1227 if (mb[1] == 0x12)
1228 schedule_work(&ha->board_disable);
1229 break;
1230
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001231 default:
1232 ql_dbg(ql_dbg_async, vha, 0x5057,
1233 "Unknown AEN:%04x %04x %04x %04x\n",
1234 mb[0], mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001236
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001237 qlt_async_event(mb[0], vha, mb);
1238
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001239 if (!vha->vp_idx && ha->num_vhosts)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001240 qla2x00_alert_all_vps(rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241}
1242
1243/**
1244 * qla2x00_process_completed_request() - Process a Fast Post response.
1245 * @ha: SCSI driver HA context
1246 * @index: SRB index
1247 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001248void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001249qla2x00_process_completed_request(struct scsi_qla_host *vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001250 struct req_que *req, uint32_t index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251{
1252 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001253 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
1255 /* Validate handle. */
Chad Dupuis8d93f552013-01-30 03:34:37 -05001256 if (index >= req->num_outstanding_cmds) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001257 ql_log(ql_log_warn, vha, 0x3014,
1258 "Invalid SCSI command index (%x).\n", index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001260 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001261 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1262 else
1263 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 return;
1265 }
1266
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001267 sp = req->outstanding_cmds[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 if (sp) {
1269 /* Free outstanding command slot. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001270 req->outstanding_cmds[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 /* Save ISP completion status */
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001273 sp->done(sp, DID_OK << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001275 ql_log(ql_log_warn, vha, 0x3016, "Invalid SCSI SRB.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001277 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001278 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1279 else
1280 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 }
1282}
1283
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001284srb_t *
Andrew Vasquezac280b62009-08-20 11:06:05 -07001285qla2x00_get_sp_from_handle(scsi_qla_host_t *vha, const char *func,
1286 struct req_que *req, void *iocb)
1287{
1288 struct qla_hw_data *ha = vha->hw;
1289 sts_entry_t *pkt = iocb;
1290 srb_t *sp = NULL;
1291 uint16_t index;
1292
1293 index = LSW(pkt->handle);
Chad Dupuis8d93f552013-01-30 03:34:37 -05001294 if (index >= req->num_outstanding_cmds) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001295 ql_log(ql_log_warn, vha, 0x5031,
Quinn Tran726b8542017-01-19 22:28:00 -08001296 "Invalid command index (%x) type %8ph.\n",
1297 index, iocb);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001298 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001299 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1300 else
1301 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001302 goto done;
1303 }
1304 sp = req->outstanding_cmds[index];
1305 if (!sp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001306 ql_log(ql_log_warn, vha, 0x5032,
1307 "Invalid completion handle (%x) -- timed-out.\n", index);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001308 return sp;
1309 }
1310 if (sp->handle != index) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001311 ql_log(ql_log_warn, vha, 0x5033,
1312 "SRB handle (%x) mismatch %x.\n", sp->handle, index);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001313 return NULL;
1314 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001315
Andrew Vasquezac280b62009-08-20 11:06:05 -07001316 req->outstanding_cmds[index] = NULL;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001317
Andrew Vasquezac280b62009-08-20 11:06:05 -07001318done:
1319 return sp;
1320}
1321
1322static void
1323qla2x00_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1324 struct mbx_entry *mbx)
1325{
1326 const char func[] = "MBX-IOCB";
1327 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001328 fc_port_t *fcport;
1329 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001330 struct srb_iocb *lio;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001331 uint16_t *data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001332 uint16_t status;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001333
1334 sp = qla2x00_get_sp_from_handle(vha, func, req, mbx);
1335 if (!sp)
1336 return;
1337
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001338 lio = &sp->u.iocb_cmd;
1339 type = sp->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001340 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001341 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001342
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001343 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001344 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001345 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001346 if (mbx->entry_status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001347 ql_dbg(ql_dbg_async, vha, 0x5043,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001348 "Async-%s error entry - hdl=%x portid=%02x%02x%02x "
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001349 "entry-status=%x status=%x state-flag=%x "
Chad Dupuiscfb09192011-11-18 09:03:07 -08001350 "status-flags=%x.\n", type, sp->handle,
1351 fcport->d_id.b.domain, fcport->d_id.b.area,
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001352 fcport->d_id.b.al_pa, mbx->entry_status,
1353 le16_to_cpu(mbx->status), le16_to_cpu(mbx->state_flags),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001354 le16_to_cpu(mbx->status_flags));
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001355
Chad Dupuiscfb09192011-11-18 09:03:07 -08001356 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5029,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001357 (uint8_t *)mbx, sizeof(*mbx));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001358
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001359 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001360 }
1361
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001362 status = le16_to_cpu(mbx->status);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001363 if (status == 0x30 && sp->type == SRB_LOGIN_CMD &&
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001364 le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE)
1365 status = 0;
1366 if (!status && le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001367 ql_dbg(ql_dbg_async, vha, 0x5045,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001368 "Async-%s complete - hdl=%x portid=%02x%02x%02x mbx1=%x.\n",
1369 type, sp->handle, fcport->d_id.b.domain,
1370 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1371 le16_to_cpu(mbx->mb1));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001372
1373 data[0] = MBS_COMMAND_COMPLETE;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001374 if (sp->type == SRB_LOGIN_CMD) {
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001375 fcport->port_type = FCT_TARGET;
1376 if (le16_to_cpu(mbx->mb1) & BIT_0)
1377 fcport->port_type = FCT_INITIATOR;
Andrew Vasquez6ac52602010-05-28 15:08:19 -07001378 else if (le16_to_cpu(mbx->mb1) & BIT_1)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001379 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001380 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001381 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001382 }
1383
1384 data[0] = le16_to_cpu(mbx->mb0);
1385 switch (data[0]) {
1386 case MBS_PORT_ID_USED:
1387 data[1] = le16_to_cpu(mbx->mb1);
1388 break;
1389 case MBS_LOOP_ID_USED:
1390 break;
1391 default:
1392 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001393 break;
1394 }
1395
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001396 ql_log(ql_log_warn, vha, 0x5046,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001397 "Async-%s failed - hdl=%x portid=%02x%02x%02x status=%x "
1398 "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n", type, sp->handle,
1399 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
1400 status, le16_to_cpu(mbx->mb0), le16_to_cpu(mbx->mb1),
Andrew Vasquezac280b62009-08-20 11:06:05 -07001401 le16_to_cpu(mbx->mb2), le16_to_cpu(mbx->mb6),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001402 le16_to_cpu(mbx->mb7));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001403
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001404logio_done:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001405 sp->done(sp, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001406}
1407
1408static void
Quinn Tran726b8542017-01-19 22:28:00 -08001409qla24xx_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1410 struct mbx_24xx_entry *pkt)
1411{
1412 const char func[] = "MBX-IOCB2";
1413 srb_t *sp;
1414 struct srb_iocb *si;
1415 u16 sz, i;
1416 int res;
1417
1418 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1419 if (!sp)
1420 return;
1421
1422 si = &sp->u.iocb_cmd;
1423 sz = min(ARRAY_SIZE(pkt->mb), ARRAY_SIZE(sp->u.iocb_cmd.u.mbx.in_mb));
1424
1425 for (i = 0; i < sz; i++)
1426 si->u.mbx.in_mb[i] = le16_to_cpu(pkt->mb[i]);
1427
1428 res = (si->u.mbx.in_mb[0] & MBS_MASK);
1429
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001430 sp->done(sp, res);
Quinn Tran726b8542017-01-19 22:28:00 -08001431}
1432
1433static void
1434qla24xxx_nack_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1435 struct nack_to_isp *pkt)
1436{
1437 const char func[] = "nack";
1438 srb_t *sp;
1439 int res = 0;
1440
1441 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1442 if (!sp)
1443 return;
1444
1445 if (pkt->u.isp2x.status != cpu_to_le16(NOTIFY_ACK_SUCCESS))
1446 res = QLA_FUNCTION_FAILED;
1447
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001448 sp->done(sp, res);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001449}
1450
1451static void
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001452qla2x00_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1453 sts_entry_t *pkt, int iocb_type)
1454{
1455 const char func[] = "CT_IOCB";
1456 const char *type;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001457 srb_t *sp;
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01001458 struct bsg_job *bsg_job;
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001459 struct fc_bsg_reply *bsg_reply;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001460 uint16_t comp_status;
Quinn Tran726b8542017-01-19 22:28:00 -08001461 int res = 0;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001462
1463 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1464 if (!sp)
1465 return;
1466
Quinn Tran726b8542017-01-19 22:28:00 -08001467 switch (sp->type) {
1468 case SRB_CT_CMD:
1469 bsg_job = sp->u.bsg_job;
1470 bsg_reply = bsg_job->reply;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001471
Quinn Tran726b8542017-01-19 22:28:00 -08001472 type = "ct pass-through";
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001473
Quinn Tran726b8542017-01-19 22:28:00 -08001474 comp_status = le16_to_cpu(pkt->comp_status);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001475
Quinn Tran726b8542017-01-19 22:28:00 -08001476 /*
1477 * return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1478 * fc payload to the caller
1479 */
1480 bsg_reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1481 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001482
Quinn Tran726b8542017-01-19 22:28:00 -08001483 if (comp_status != CS_COMPLETE) {
1484 if (comp_status == CS_DATA_UNDERRUN) {
1485 res = DID_OK << 16;
1486 bsg_reply->reply_payload_rcv_len =
1487 le16_to_cpu(((sts_entry_t *)pkt)->rsp_info_len);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001488
Quinn Tran726b8542017-01-19 22:28:00 -08001489 ql_log(ql_log_warn, vha, 0x5048,
1490 "CT pass-through-%s error comp_status=0x%x total_byte=0x%x.\n",
1491 type, comp_status,
1492 bsg_reply->reply_payload_rcv_len);
1493 } else {
1494 ql_log(ql_log_warn, vha, 0x5049,
1495 "CT pass-through-%s error comp_status=0x%x.\n",
1496 type, comp_status);
1497 res = DID_ERROR << 16;
1498 bsg_reply->reply_payload_rcv_len = 0;
1499 }
1500 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5035,
1501 (uint8_t *)pkt, sizeof(*pkt));
1502 } else {
1503 res = DID_OK << 16;
1504 bsg_reply->reply_payload_rcv_len =
1505 bsg_job->reply_payload.payload_len;
1506 bsg_job->reply_len = 0;
1507 }
1508 break;
1509 case SRB_CT_PTHRU_CMD:
1510 /*
1511 * borrowing sts_entry_24xx.comp_status.
1512 * same location as ct_entry_24xx.comp_status
1513 */
1514 res = qla2x00_chk_ms_status(vha, (ms_iocb_entry_t *)pkt,
1515 (struct ct_sns_rsp *)sp->u.iocb_cmd.u.ctarg.rsp,
1516 sp->name);
1517 break;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001518 }
1519
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001520 sp->done(sp, res);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001521}
1522
1523static void
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001524qla24xx_els_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1525 struct sts_entry_24xx *pkt, int iocb_type)
1526{
1527 const char func[] = "ELS_CT_IOCB";
1528 const char *type;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001529 srb_t *sp;
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01001530 struct bsg_job *bsg_job;
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001531 struct fc_bsg_reply *bsg_reply;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001532 uint16_t comp_status;
1533 uint32_t fw_status[3];
1534 uint8_t* fw_sts_ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001535 int res;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001536
1537 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1538 if (!sp)
1539 return;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001540 bsg_job = sp->u.bsg_job;
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001541 bsg_reply = bsg_job->reply;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001542
1543 type = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001544 switch (sp->type) {
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001545 case SRB_ELS_CMD_RPT:
1546 case SRB_ELS_CMD_HST:
1547 type = "els";
1548 break;
1549 case SRB_CT_CMD:
1550 type = "ct pass-through";
1551 break;
Himanshu Madhani6eb54712015-12-17 14:57:00 -05001552 case SRB_ELS_DCMD:
1553 type = "Driver ELS logo";
1554 ql_dbg(ql_dbg_user, vha, 0x5047,
1555 "Completing %s: (%p) type=%d.\n", type, sp, sp->type);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001556 sp->done(sp, 0);
Himanshu Madhani6eb54712015-12-17 14:57:00 -05001557 return;
Quinn Tran726b8542017-01-19 22:28:00 -08001558 case SRB_CT_PTHRU_CMD:
1559 /* borrowing sts_entry_24xx.comp_status.
1560 same location as ct_entry_24xx.comp_status
1561 */
1562 res = qla2x00_chk_ms_status(vha, (ms_iocb_entry_t *)pkt,
1563 (struct ct_sns_rsp *)sp->u.iocb_cmd.u.ctarg.rsp,
1564 sp->name);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001565 sp->done(sp, res);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001566 return;
1567 default:
1568 ql_dbg(ql_dbg_user, vha, 0x503e,
1569 "Unrecognized SRB: (%p) type=%d.\n", sp, sp->type);
1570 return;
1571 }
1572
1573 comp_status = fw_status[0] = le16_to_cpu(pkt->comp_status);
1574 fw_status[1] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1);
1575 fw_status[2] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2);
1576
1577 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1578 * fc payload to the caller
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001579 */
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001580 bsg_reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001581 bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(fw_status);
1582
1583 if (comp_status != CS_COMPLETE) {
1584 if (comp_status == CS_DATA_UNDERRUN) {
1585 res = DID_OK << 16;
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001586 bsg_reply->reply_payload_rcv_len =
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001587 le16_to_cpu(((struct els_sts_entry_24xx *)pkt)->total_byte_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001588
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001589 ql_dbg(ql_dbg_user, vha, 0x503f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001590 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001591 "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001592 type, sp->handle, comp_status, fw_status[1], fw_status[2],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001593 le16_to_cpu(((struct els_sts_entry_24xx *)
1594 pkt)->total_byte_count));
Christoph Hellwig82ed4db2017-01-27 09:46:29 +01001595 fw_sts_ptr = ((uint8_t*)scsi_req(bsg_job->req)->sense) +
1596 sizeof(struct fc_bsg_reply);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001597 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1598 }
1599 else {
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001600 ql_dbg(ql_dbg_user, vha, 0x5040,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001601 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001602 "error subcode 1=0x%x error subcode 2=0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001603 type, sp->handle, comp_status,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001604 le16_to_cpu(((struct els_sts_entry_24xx *)
1605 pkt)->error_subcode_1),
1606 le16_to_cpu(((struct els_sts_entry_24xx *)
1607 pkt)->error_subcode_2));
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001608 res = DID_ERROR << 16;
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001609 bsg_reply->reply_payload_rcv_len = 0;
Christoph Hellwig82ed4db2017-01-27 09:46:29 +01001610 fw_sts_ptr = ((uint8_t*)scsi_req(bsg_job->req)->sense) +
1611 sizeof(struct fc_bsg_reply);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001612 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1613 }
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001614 ql_dump_buffer(ql_dbg_user + ql_dbg_buffer, vha, 0x5056,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001615 (uint8_t *)pkt, sizeof(*pkt));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001616 }
1617 else {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001618 res = DID_OK << 16;
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01001619 bsg_reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001620 bsg_job->reply_len = 0;
1621 }
1622
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001623 sp->done(sp, res);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001624}
1625
1626static void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001627qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req,
1628 struct logio_entry_24xx *logio)
1629{
1630 const char func[] = "LOGIO-IOCB";
1631 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001632 fc_port_t *fcport;
1633 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001634 struct srb_iocb *lio;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001635 uint16_t *data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001636 uint32_t iop[2];
1637
1638 sp = qla2x00_get_sp_from_handle(vha, func, req, logio);
1639 if (!sp)
1640 return;
1641
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001642 lio = &sp->u.iocb_cmd;
1643 type = sp->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001644 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001645 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001646
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001647 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001648 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001649 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001650 if (logio->entry_status) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001651 ql_log(ql_log_warn, fcport->vha, 0x5034,
Quinn Tran5b334692017-03-15 09:48:48 -07001652 "Async-%s error entry - %8phC hdl=%x"
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001653 "portid=%02x%02x%02x entry-status=%x.\n",
Quinn Tran5b334692017-03-15 09:48:48 -07001654 type, fcport->port_name, sp->handle, fcport->d_id.b.domain,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001655 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1656 logio->entry_status);
1657 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x504d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001658 (uint8_t *)logio, sizeof(*logio));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001659
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001660 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001661 }
1662
1663 if (le16_to_cpu(logio->comp_status) == CS_COMPLETE) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001664 ql_dbg(ql_dbg_async, fcport->vha, 0x5036,
Quinn Tran5b334692017-03-15 09:48:48 -07001665 "Async-%s complete - %8phC hdl=%x portid=%02x%02x%02x "
1666 "iop0=%x.\n", type, fcport->port_name, sp->handle,
1667 fcport->d_id.b.domain,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001668 fcport->d_id.b.area, fcport->d_id.b.al_pa,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001669 le32_to_cpu(logio->io_parameter[0]));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001670
Quinn Tranead03852017-01-19 22:28:01 -08001671 vha->hw->exch_starvation = 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001672 data[0] = MBS_COMMAND_COMPLETE;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001673 if (sp->type != SRB_LOGIN_CMD)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001674 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001675
1676 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1677 if (iop[0] & BIT_4) {
1678 fcport->port_type = FCT_TARGET;
1679 if (iop[0] & BIT_8)
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07001680 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquezb0cd5792010-05-28 15:08:22 -07001681 } else if (iop[0] & BIT_5)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001682 fcport->port_type = FCT_INITIATOR;
Andrew Vasquezb0cd5792010-05-28 15:08:22 -07001683
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001684 if (iop[0] & BIT_7)
1685 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
1686
Andrew Vasquezac280b62009-08-20 11:06:05 -07001687 if (logio->io_parameter[7] || logio->io_parameter[8])
1688 fcport->supported_classes |= FC_COS_CLASS2;
1689 if (logio->io_parameter[9] || logio->io_parameter[10])
1690 fcport->supported_classes |= FC_COS_CLASS3;
1691
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001692 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001693 }
1694
1695 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1696 iop[1] = le32_to_cpu(logio->io_parameter[1]);
Quinn Tran726b8542017-01-19 22:28:00 -08001697 lio->u.logio.iop[0] = iop[0];
1698 lio->u.logio.iop[1] = iop[1];
Andrew Vasquezac280b62009-08-20 11:06:05 -07001699 switch (iop[0]) {
1700 case LSC_SCODE_PORTID_USED:
1701 data[0] = MBS_PORT_ID_USED;
1702 data[1] = LSW(iop[1]);
1703 break;
1704 case LSC_SCODE_NPORT_USED:
1705 data[0] = MBS_LOOP_ID_USED;
1706 break;
Quinn Tran5b334692017-03-15 09:48:48 -07001707 case LSC_SCODE_CMD_FAILED:
1708 if (iop[1] == 0x0606) {
1709 /*
1710 * PLOGI/PRLI Completed. We must have Recv PLOGI/PRLI,
1711 * Target side acked.
1712 */
1713 data[0] = MBS_COMMAND_COMPLETE;
1714 goto logio_done;
1715 }
1716 data[0] = MBS_COMMAND_ERROR;
1717 break;
Quinn Tranead03852017-01-19 22:28:01 -08001718 case LSC_SCODE_NOXCB:
1719 vha->hw->exch_starvation++;
1720 if (vha->hw->exch_starvation > 5) {
Quinn Tran83548fe2017-06-02 09:12:01 -07001721 ql_log(ql_log_warn, vha, 0xd046,
Quinn Tranead03852017-01-19 22:28:01 -08001722 "Exchange starvation. Resetting RISC\n");
1723
1724 vha->hw->exch_starvation = 0;
1725
1726 if (IS_P3P_TYPE(vha->hw))
1727 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1728 else
1729 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1730 qla2xxx_wake_dpc(vha);
1731 }
1732 /* drop through */
Andrew Vasquezac280b62009-08-20 11:06:05 -07001733 default:
1734 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001735 break;
1736 }
1737
Arun Easi5e19ed92012-02-09 11:15:51 -08001738 ql_dbg(ql_dbg_async, fcport->vha, 0x5037,
Quinn Tran5b334692017-03-15 09:48:48 -07001739 "Async-%s failed - %8phC hdl=%x portid=%02x%02x%02x comp=%x "
1740 "iop0=%x iop1=%x.\n", type, fcport->port_name,
1741 sp->handle, fcport->d_id.b.domain,
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001742 fcport->d_id.b.area, fcport->d_id.b.al_pa,
Andrew Vasquezac280b62009-08-20 11:06:05 -07001743 le16_to_cpu(logio->comp_status),
1744 le32_to_cpu(logio->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001745 le32_to_cpu(logio->io_parameter[1]));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001746
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001747logio_done:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001748 sp->done(sp, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001749}
1750
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001751static void
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001752qla24xx_tm_iocb_entry(scsi_qla_host_t *vha, struct req_que *req, void *tsk)
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001753{
1754 const char func[] = "TMF-IOCB";
1755 const char *type;
1756 fc_port_t *fcport;
1757 srb_t *sp;
1758 struct srb_iocb *iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001759 struct sts_entry_24xx *sts = (struct sts_entry_24xx *)tsk;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001760
1761 sp = qla2x00_get_sp_from_handle(vha, func, req, tsk);
1762 if (!sp)
1763 return;
1764
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001765 iocb = &sp->u.iocb_cmd;
1766 type = sp->name;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001767 fcport = sp->fcport;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001768 iocb->u.tmf.data = QLA_SUCCESS;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001769
1770 if (sts->entry_status) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001771 ql_log(ql_log_warn, fcport->vha, 0x5038,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001772 "Async-%s error - hdl=%x entry-status(%x).\n",
1773 type, sp->handle, sts->entry_status);
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001774 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07001775 } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001776 ql_log(ql_log_warn, fcport->vha, 0x5039,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001777 "Async-%s error - hdl=%x completion status(%x).\n",
1778 type, sp->handle, sts->comp_status);
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001779 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
1780 } else if ((le16_to_cpu(sts->scsi_status) &
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001781 SS_RESPONSE_INFO_LEN_VALID)) {
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001782 if (le32_to_cpu(sts->rsp_data_len) < 4) {
1783 ql_log(ql_log_warn, fcport->vha, 0x503b,
1784 "Async-%s error - hdl=%x not enough response(%d).\n",
1785 type, sp->handle, sts->rsp_data_len);
1786 } else if (sts->data[3]) {
1787 ql_log(ql_log_warn, fcport->vha, 0x503c,
1788 "Async-%s error - hdl=%x response(%x).\n",
1789 type, sp->handle, sts->data[3]);
Bart Van Assche8d2b21d2015-06-04 15:58:09 -07001790 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001791 }
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001792 }
1793
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001794 if (iocb->u.tmf.data != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001795 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5055,
1796 (uint8_t *)sts, sizeof(*sts));
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001797
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001798 sp->done(sp, 0);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001799}
1800
Duane Grigsby7401bc12017-06-21 13:48:42 -07001801static void
1802qla24xx_nvme_iocb_entry(scsi_qla_host_t *vha, struct req_que *req, void *tsk)
1803{
1804 const char func[] = "NVME-IOCB";
1805 fc_port_t *fcport;
1806 srb_t *sp;
1807 struct srb_iocb *iocb;
1808 struct sts_entry_24xx *sts = (struct sts_entry_24xx *)tsk;
1809 uint16_t state_flags;
1810 struct nvmefc_fcp_req *fd;
1811 uint16_t ret = 0;
1812 struct srb_iocb *nvme;
1813
1814 sp = qla2x00_get_sp_from_handle(vha, func, req, tsk);
1815 if (!sp)
1816 return;
1817
1818 iocb = &sp->u.iocb_cmd;
1819 fcport = sp->fcport;
1820 iocb->u.nvme.comp_status = le16_to_cpu(sts->comp_status);
1821 state_flags = le16_to_cpu(sts->state_flags);
1822 fd = iocb->u.nvme.desc;
1823 nvme = &sp->u.iocb_cmd;
1824
1825 if (unlikely(nvme->u.nvme.aen_op))
1826 atomic_dec(&sp->vha->nvme_active_aen_cnt);
1827
1828 /*
1829 * State flags: Bit 6 and 0.
1830 * If 0 is set, we don't care about 6.
1831 * both cases resp was dma'd to host buffer
1832 * if both are 0, that is good path case.
1833 * if six is set and 0 is clear, we need to
1834 * copy resp data from status iocb to resp buffer.
1835 */
1836 if (!(state_flags & (SF_FCP_RSP_DMA | SF_NVME_ERSP))) {
1837 iocb->u.nvme.rsp_pyld_len = 0;
1838 } else if ((state_flags & SF_FCP_RSP_DMA)) {
1839 iocb->u.nvme.rsp_pyld_len = le16_to_cpu(sts->nvme_rsp_pyld_len);
1840 } else if (state_flags & SF_NVME_ERSP) {
1841 uint32_t *inbuf, *outbuf;
1842 uint16_t iter;
1843
1844 inbuf = (uint32_t *)&sts->nvme_ersp_data;
1845 outbuf = (uint32_t *)fd->rspaddr;
1846 iocb->u.nvme.rsp_pyld_len = le16_to_cpu(sts->nvme_rsp_pyld_len);
1847 iter = iocb->u.nvme.rsp_pyld_len >> 2;
1848 for (; iter; iter--)
1849 *outbuf++ = swab32(*inbuf++);
1850 } else { /* unhandled case */
1851 ql_log(ql_log_warn, fcport->vha, 0x503a,
1852 "NVME-%s error. Unhandled state_flags of %x\n",
1853 sp->name, state_flags);
1854 }
1855
1856 fd->transferred_length = fd->payload_length -
1857 le32_to_cpu(sts->residual_len);
1858
1859 if (sts->entry_status) {
1860 ql_log(ql_log_warn, fcport->vha, 0x5038,
1861 "NVME-%s error - hdl=%x entry-status(%x).\n",
1862 sp->name, sp->handle, sts->entry_status);
1863 ret = QLA_FUNCTION_FAILED;
1864 } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
1865 ql_log(ql_log_warn, fcport->vha, 0x5039,
1866 "NVME-%s error - hdl=%x completion status(%x) resid=%x ox_id=%x\n",
1867 sp->name, sp->handle, sts->comp_status,
1868 le32_to_cpu(sts->residual_len), sts->ox_id);
1869 ret = QLA_FUNCTION_FAILED;
1870 }
1871 sp->done(sp, ret);
1872}
1873
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874/**
1875 * qla2x00_process_response_queue() - Process response queue entries.
1876 * @ha: SCSI driver HA context
1877 */
1878void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001879qla2x00_process_response_queue(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001881 struct scsi_qla_host *vha;
1882 struct qla_hw_data *ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001883 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 sts_entry_t *pkt;
1885 uint16_t handle_cnt;
1886 uint16_t cnt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001887
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001888 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001890 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 return;
1892
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001893 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1894 pkt = (sts_entry_t *)rsp->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001896 rsp->ring_index++;
1897 if (rsp->ring_index == rsp->length) {
1898 rsp->ring_index = 0;
1899 rsp->ring_ptr = rsp->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001901 rsp->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 }
1903
1904 if (pkt->entry_status != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001905 qla2x00_error_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1907 wmb();
1908 continue;
1909 }
1910
1911 switch (pkt->entry_type) {
1912 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001913 qla2x00_status_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 break;
1915 case STATUS_TYPE_21:
1916 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
1917 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001918 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 ((sts21_entry_t *)pkt)->handle[cnt]);
1920 }
1921 break;
1922 case STATUS_TYPE_22:
1923 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
1924 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001925 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 ((sts22_entry_t *)pkt)->handle[cnt]);
1927 }
1928 break;
1929 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001930 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001932 case MBX_IOCB_TYPE:
1933 qla2x00_mbx_iocb_entry(vha, rsp->req,
1934 (struct mbx_entry *)pkt);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001935 break;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001936 case CT_IOCB_TYPE:
1937 qla2x00_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
1938 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 default:
1940 /* Type Not Supported. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001941 ql_log(ql_log_warn, vha, 0x504a,
1942 "Received unknown response pkt type %x "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 "entry status=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001944 pkt->entry_type, pkt->entry_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 break;
1946 }
1947 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1948 wmb();
1949 }
1950
1951 /* Adjust ring index */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001952 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953}
1954
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001955static inline void
Andrew Vasquez55442132010-07-23 15:28:27 +05001956qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t par_sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001957 uint32_t sense_len, struct rsp_que *rsp, int res)
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001958{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001959 struct scsi_qla_host *vha = sp->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001960 struct scsi_cmnd *cp = GET_CMD_SP(sp);
1961 uint32_t track_sense_len;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001962
1963 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
1964 sense_len = SCSI_SENSE_BUFFERSIZE;
1965
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001966 SET_CMD_SENSE_LEN(sp, sense_len);
1967 SET_CMD_SENSE_PTR(sp, cp->sense_buffer);
1968 track_sense_len = sense_len;
1969
1970 if (sense_len > par_sense_len)
Andrew Vasquez55442132010-07-23 15:28:27 +05001971 sense_len = par_sense_len;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001972
1973 memcpy(cp->sense_buffer, sense_data, sense_len);
1974
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001975 SET_CMD_SENSE_PTR(sp, cp->sense_buffer + sense_len);
1976 track_sense_len -= sense_len;
1977 SET_CMD_SENSE_LEN(sp, track_sense_len);
1978
1979 if (track_sense_len != 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001980 rsp->status_srb = sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001981 cp->result = res;
1982 }
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001983
Chad Dupuiscfb09192011-11-18 09:03:07 -08001984 if (sense_len) {
1985 ql_dbg(ql_dbg_io + ql_dbg_buffer, vha, 0x301c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001986 "Check condition Sense data, nexus%ld:%d:%llu cmd=%p.\n",
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001987 sp->vha->host_no, cp->device->id, cp->device->lun,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001988 cp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001989 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302b,
1990 cp->sense_buffer, sense_len);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001991 }
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001992}
1993
Arun Easibad75002010-05-04 15:01:30 -07001994struct scsi_dif_tuple {
1995 __be16 guard; /* Checksum */
Masanari Iidad6a03582012-08-22 14:20:58 -04001996 __be16 app_tag; /* APPL identifier */
Arun Easibad75002010-05-04 15:01:30 -07001997 __be32 ref_tag; /* Target LBA or indirect LBA */
1998};
1999
2000/*
2001 * Checks the guard or meta-data for the type of error
2002 * detected by the HBA. In case of errors, we set the
2003 * ASC/ASCQ fields in the sense buffer with ILLEGAL_REQUEST
2004 * to indicate to the kernel that the HBA detected error.
2005 */
Arun Easi8cb20492011-08-16 11:29:22 -07002006static inline int
Arun Easibad75002010-05-04 15:01:30 -07002007qla2x00_handle_dif_error(srb_t *sp, struct sts_entry_24xx *sts24)
2008{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08002009 struct scsi_qla_host *vha = sp->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002010 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Arun Easi8cb20492011-08-16 11:29:22 -07002011 uint8_t *ap = &sts24->data[12];
2012 uint8_t *ep = &sts24->data[20];
Arun Easibad75002010-05-04 15:01:30 -07002013 uint32_t e_ref_tag, a_ref_tag;
2014 uint16_t e_app_tag, a_app_tag;
2015 uint16_t e_guard, a_guard;
2016
Arun Easi8cb20492011-08-16 11:29:22 -07002017 /*
2018 * swab32 of the "data" field in the beginning of qla2x00_status_entry()
2019 * would make guard field appear at offset 2
2020 */
2021 a_guard = le16_to_cpu(*(uint16_t *)(ap + 2));
2022 a_app_tag = le16_to_cpu(*(uint16_t *)(ap + 0));
2023 a_ref_tag = le32_to_cpu(*(uint32_t *)(ap + 4));
2024 e_guard = le16_to_cpu(*(uint16_t *)(ep + 2));
2025 e_app_tag = le16_to_cpu(*(uint16_t *)(ep + 0));
2026 e_ref_tag = le32_to_cpu(*(uint32_t *)(ep + 4));
Arun Easibad75002010-05-04 15:01:30 -07002027
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002028 ql_dbg(ql_dbg_io, vha, 0x3023,
2029 "iocb(s) %p Returned STATUS.\n", sts24);
Arun Easibad75002010-05-04 15:01:30 -07002030
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002031 ql_dbg(ql_dbg_io, vha, 0x3024,
2032 "DIF ERROR in cmd 0x%x lba 0x%llx act ref"
Arun Easibad75002010-05-04 15:01:30 -07002033 " tag=0x%x, exp ref_tag=0x%x, act app tag=0x%x, exp app"
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002034 " tag=0x%x, act guard=0x%x, exp guard=0x%x.\n",
Arun Easibad75002010-05-04 15:01:30 -07002035 cmd->cmnd[0], (u64)scsi_get_lba(cmd), a_ref_tag, e_ref_tag,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002036 a_app_tag, e_app_tag, a_guard, e_guard);
Arun Easibad75002010-05-04 15:01:30 -07002037
Arun Easi8cb20492011-08-16 11:29:22 -07002038 /*
2039 * Ignore sector if:
2040 * For type 3: ref & app tag is all 'f's
2041 * For type 0,1,2: app tag is all 'f's
2042 */
2043 if ((a_app_tag == 0xffff) &&
2044 ((scsi_get_prot_type(cmd) != SCSI_PROT_DIF_TYPE3) ||
2045 (a_ref_tag == 0xffffffff))) {
2046 uint32_t blocks_done, resid;
2047 sector_t lba_s = scsi_get_lba(cmd);
2048
2049 /* 2TB boundary case covered automatically with this */
2050 blocks_done = e_ref_tag - (uint32_t)lba_s + 1;
2051
2052 resid = scsi_bufflen(cmd) - (blocks_done *
2053 cmd->device->sector_size);
2054
2055 scsi_set_resid(cmd, resid);
2056 cmd->result = DID_OK << 16;
2057
2058 /* Update protection tag */
2059 if (scsi_prot_sg_count(cmd)) {
2060 uint32_t i, j = 0, k = 0, num_ent;
2061 struct scatterlist *sg;
Christoph Hellwig27c0e832016-09-11 19:35:40 +02002062 struct t10_pi_tuple *spt;
Arun Easi8cb20492011-08-16 11:29:22 -07002063
2064 /* Patch the corresponding protection tags */
2065 scsi_for_each_prot_sg(cmd, sg,
2066 scsi_prot_sg_count(cmd), i) {
2067 num_ent = sg_dma_len(sg) / 8;
2068 if (k + num_ent < blocks_done) {
2069 k += num_ent;
2070 continue;
2071 }
2072 j = blocks_done - k - 1;
2073 k = blocks_done;
2074 break;
2075 }
2076
2077 if (k != blocks_done) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08002078 ql_log(ql_log_warn, vha, 0x302f,
Randy Dunlap8ec9c7f2011-09-23 15:40:50 -07002079 "unexpected tag values tag:lba=%x:%llx)\n",
2080 e_ref_tag, (unsigned long long)lba_s);
Arun Easi8cb20492011-08-16 11:29:22 -07002081 return 1;
2082 }
2083
2084 spt = page_address(sg_page(sg)) + sg->offset;
2085 spt += j;
2086
2087 spt->app_tag = 0xffff;
2088 if (scsi_get_prot_type(cmd) == SCSI_PROT_DIF_TYPE3)
2089 spt->ref_tag = 0xffffffff;
2090 }
2091
2092 return 0;
2093 }
2094
Arun Easibad75002010-05-04 15:01:30 -07002095 /* check guard */
2096 if (e_guard != a_guard) {
2097 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2098 0x10, 0x1);
2099 set_driver_byte(cmd, DRIVER_SENSE);
2100 set_host_byte(cmd, DID_ABORT);
2101 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
Arun Easi8cb20492011-08-16 11:29:22 -07002102 return 1;
Arun Easibad75002010-05-04 15:01:30 -07002103 }
2104
Arun Easie02587d2011-08-16 11:29:23 -07002105 /* check ref tag */
2106 if (e_ref_tag != a_ref_tag) {
2107 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2108 0x10, 0x3);
2109 set_driver_byte(cmd, DRIVER_SENSE);
2110 set_host_byte(cmd, DID_ABORT);
2111 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
2112 return 1;
2113 }
2114
Arun Easibad75002010-05-04 15:01:30 -07002115 /* check appl tag */
2116 if (e_app_tag != a_app_tag) {
2117 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
2118 0x10, 0x2);
2119 set_driver_byte(cmd, DRIVER_SENSE);
2120 set_host_byte(cmd, DID_ABORT);
2121 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
Arun Easi8cb20492011-08-16 11:29:22 -07002122 return 1;
Arun Easibad75002010-05-04 15:01:30 -07002123 }
2124
Arun Easi8cb20492011-08-16 11:29:22 -07002125 return 1;
Arun Easibad75002010-05-04 15:01:30 -07002126}
2127
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002128static void
2129qla25xx_process_bidir_status_iocb(scsi_qla_host_t *vha, void *pkt,
2130 struct req_que *req, uint32_t index)
2131{
2132 struct qla_hw_data *ha = vha->hw;
2133 srb_t *sp;
2134 uint16_t comp_status;
2135 uint16_t scsi_status;
2136 uint16_t thread_id;
2137 uint32_t rval = EXT_STATUS_OK;
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +01002138 struct bsg_job *bsg_job = NULL;
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002139 struct fc_bsg_request *bsg_request;
2140 struct fc_bsg_reply *bsg_reply;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002141 sts_entry_t *sts;
2142 struct sts_entry_24xx *sts24;
2143 sts = (sts_entry_t *) pkt;
2144 sts24 = (struct sts_entry_24xx *) pkt;
2145
2146 /* Validate handle. */
Chad Dupuis8d93f552013-01-30 03:34:37 -05002147 if (index >= req->num_outstanding_cmds) {
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002148 ql_log(ql_log_warn, vha, 0x70af,
2149 "Invalid SCSI completion handle 0x%x.\n", index);
2150 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2151 return;
2152 }
2153
2154 sp = req->outstanding_cmds[index];
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002155 if (!sp) {
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002156 ql_log(ql_log_warn, vha, 0x70b0,
2157 "Req:%d: Invalid ISP SCSI completion handle(0x%x)\n",
2158 req->id, index);
2159
2160 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2161 return;
2162 }
2163
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002164 /* Free outstanding command slot. */
2165 req->outstanding_cmds[index] = NULL;
2166 bsg_job = sp->u.bsg_job;
2167 bsg_request = bsg_job->request;
2168 bsg_reply = bsg_job->reply;
2169
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002170 if (IS_FWI2_CAPABLE(ha)) {
2171 comp_status = le16_to_cpu(sts24->comp_status);
2172 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
2173 } else {
2174 comp_status = le16_to_cpu(sts->comp_status);
2175 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
2176 }
2177
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002178 thread_id = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002179 switch (comp_status) {
2180 case CS_COMPLETE:
2181 if (scsi_status == 0) {
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002182 bsg_reply->reply_payload_rcv_len =
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002183 bsg_job->reply_payload.payload_len;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -04002184 vha->qla_stats.input_bytes +=
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002185 bsg_reply->reply_payload_rcv_len;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -04002186 vha->qla_stats.input_requests++;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002187 rval = EXT_STATUS_OK;
2188 }
2189 goto done;
2190
2191 case CS_DATA_OVERRUN:
2192 ql_dbg(ql_dbg_user, vha, 0x70b1,
Milan P Gandhi5a68a1c2017-03-31 14:37:04 -07002193 "Command completed with data overrun thread_id=%d\n",
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002194 thread_id);
2195 rval = EXT_STATUS_DATA_OVERRUN;
2196 break;
2197
2198 case CS_DATA_UNDERRUN:
2199 ql_dbg(ql_dbg_user, vha, 0x70b2,
Milan P Gandhi5a68a1c2017-03-31 14:37:04 -07002200 "Command completed with data underrun thread_id=%d\n",
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002201 thread_id);
2202 rval = EXT_STATUS_DATA_UNDERRUN;
2203 break;
2204 case CS_BIDIR_RD_OVERRUN:
2205 ql_dbg(ql_dbg_user, vha, 0x70b3,
2206 "Command completed with read data overrun thread_id=%d\n",
2207 thread_id);
2208 rval = EXT_STATUS_DATA_OVERRUN;
2209 break;
2210
2211 case CS_BIDIR_RD_WR_OVERRUN:
2212 ql_dbg(ql_dbg_user, vha, 0x70b4,
2213 "Command completed with read and write data overrun "
2214 "thread_id=%d\n", thread_id);
2215 rval = EXT_STATUS_DATA_OVERRUN;
2216 break;
2217
2218 case CS_BIDIR_RD_OVERRUN_WR_UNDERRUN:
2219 ql_dbg(ql_dbg_user, vha, 0x70b5,
2220 "Command completed with read data over and write data "
2221 "underrun thread_id=%d\n", thread_id);
2222 rval = EXT_STATUS_DATA_OVERRUN;
2223 break;
2224
2225 case CS_BIDIR_RD_UNDERRUN:
2226 ql_dbg(ql_dbg_user, vha, 0x70b6,
Milan P Gandhi5a68a1c2017-03-31 14:37:04 -07002227 "Command completed with read data underrun "
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002228 "thread_id=%d\n", thread_id);
2229 rval = EXT_STATUS_DATA_UNDERRUN;
2230 break;
2231
2232 case CS_BIDIR_RD_UNDERRUN_WR_OVERRUN:
2233 ql_dbg(ql_dbg_user, vha, 0x70b7,
2234 "Command completed with read data under and write data "
2235 "overrun thread_id=%d\n", thread_id);
2236 rval = EXT_STATUS_DATA_UNDERRUN;
2237 break;
2238
2239 case CS_BIDIR_RD_WR_UNDERRUN:
2240 ql_dbg(ql_dbg_user, vha, 0x70b8,
2241 "Command completed with read and write data underrun "
2242 "thread_id=%d\n", thread_id);
2243 rval = EXT_STATUS_DATA_UNDERRUN;
2244 break;
2245
2246 case CS_BIDIR_DMA:
2247 ql_dbg(ql_dbg_user, vha, 0x70b9,
2248 "Command completed with data DMA error thread_id=%d\n",
2249 thread_id);
2250 rval = EXT_STATUS_DMA_ERR;
2251 break;
2252
2253 case CS_TIMEOUT:
2254 ql_dbg(ql_dbg_user, vha, 0x70ba,
2255 "Command completed with timeout thread_id=%d\n",
2256 thread_id);
2257 rval = EXT_STATUS_TIMEOUT;
2258 break;
2259 default:
2260 ql_dbg(ql_dbg_user, vha, 0x70bb,
2261 "Command completed with completion status=0x%x "
2262 "thread_id=%d\n", comp_status, thread_id);
2263 rval = EXT_STATUS_ERR;
2264 break;
2265 }
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002266 bsg_reply->reply_payload_rcv_len = 0;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002267
2268done:
2269 /* Return the vendor specific reply to API */
Johannes Thumshirn01e0e152016-11-17 10:31:12 +01002270 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002271 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2272 /* Always return DID_OK, bsg will send the vendor specific response
2273 * in this case only */
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08002274 sp->done(sp, DID_OK << 6);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002275
2276}
2277
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278/**
2279 * qla2x00_status_entry() - Process a Status IOCB entry.
2280 * @ha: SCSI driver HA context
2281 * @pkt: Entry pointer
2282 */
2283static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002284qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 fc_port_t *fcport;
2288 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002289 sts_entry_t *sts;
2290 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 uint16_t comp_status;
2292 uint16_t scsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002293 uint16_t ox_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 uint8_t lscsi_status;
2295 int32_t resid;
Andrew Vasquez55442132010-07-23 15:28:27 +05002296 uint32_t sense_len, par_sense_len, rsp_info_len, resid_len,
2297 fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002298 uint8_t *rsp_info, *sense_data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002299 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002300 uint32_t handle;
2301 uint16_t que;
2302 struct req_que *req;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002303 int logit = 1;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002304 int res = 0;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002305 uint16_t state_flags = 0;
Chad Dupuise05fe292014-09-25 05:16:59 -04002306 uint16_t retry_delay = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08002307 uint8_t no_logout = 0;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002308
2309 sts = (sts_entry_t *) pkt;
2310 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002311 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002312 comp_status = le16_to_cpu(sts24->comp_status);
2313 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002314 state_flags = le16_to_cpu(sts24->state_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002315 } else {
2316 comp_status = le16_to_cpu(sts->comp_status);
2317 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
2318 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002319 handle = (uint32_t) LSW(sts->handle);
2320 que = MSW(sts->handle);
2321 req = ha->req_q_map[que];
Giridhar Malavalia9083012010-04-12 17:59:55 -07002322
Chad Dupuis36008cf2013-10-03 03:21:13 -04002323 /* Check for invalid queue pointer */
2324 if (req == NULL ||
2325 que >= find_first_zero_bit(ha->req_qid_map, ha->max_req_queues)) {
2326 ql_dbg(ql_dbg_io, vha, 0x3059,
2327 "Invalid status handle (0x%x): Bad req pointer. req=%p, "
2328 "que=%u.\n", sts->handle, req, que);
2329 return;
2330 }
2331
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 /* Validate handle. */
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04002333 if (handle < req->num_outstanding_cmds) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002334 sp = req->outstanding_cmds[handle];
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04002335 if (!sp) {
2336 ql_dbg(ql_dbg_io, vha, 0x3075,
2337 "%s(%ld): Already returned command for status handle (0x%x).\n",
2338 __func__, vha->host_no, sts->handle);
2339 return;
2340 }
2341 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08002342 ql_dbg(ql_dbg_io, vha, 0x3017,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04002343 "Invalid status handle, out of range (0x%x).\n",
2344 sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
Chad Dupuisacd3ce882014-04-11 16:54:07 -04002346 if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
2347 if (IS_P3P_TYPE(ha))
2348 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
2349 else
2350 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2351 qla2xxx_wake_dpc(vha);
2352 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 return;
2354 }
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002355
Quinn Tranc5419e22017-06-13 20:47:16 -07002356 if (sp->cmd_type != TYPE_SRB) {
2357 req->outstanding_cmds[handle] = NULL;
2358 ql_dbg(ql_dbg_io, vha, 0x3015,
2359 "Unknown sp->cmd_type %x %p).\n",
2360 sp->cmd_type, sp);
2361 return;
2362 }
2363
Duane Grigsby7401bc12017-06-21 13:48:42 -07002364 /* NVME completion. */
2365 if (sp->type == SRB_NVME_CMD) {
2366 qla24xx_nvme_iocb_entry(vha, req, pkt);
2367 return;
2368 }
2369
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002370 if (unlikely((state_flags & BIT_1) && (sp->type == SRB_BIDI_CMD))) {
2371 qla25xx_process_bidir_status_iocb(vha, pkt, req, handle);
2372 return;
2373 }
2374
Armen Baloyanfaef62d2014-02-26 04:15:17 -05002375 /* Task Management completion. */
2376 if (sp->type == SRB_TM_CMD) {
2377 qla24xx_tm_iocb_entry(vha, req, pkt);
2378 return;
2379 }
2380
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002381 /* Fast path completion. */
2382 if (comp_status == CS_COMPLETE && scsi_status == 0) {
2383 qla2x00_process_completed_request(vha, req, handle);
2384
2385 return;
2386 }
2387
2388 req->outstanding_cmds[handle] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002389 cp = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 if (cp == NULL) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08002391 ql_dbg(ql_dbg_io, vha, 0x3018,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002392 "Command already returned (0x%x/%p).\n",
2393 sts->handle, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394
2395 return;
2396 }
2397
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002398 lscsi_status = scsi_status & STATUS_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399
bdf79622005-04-17 15:06:53 -05002400 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002402 ox_id = 0;
Andrew Vasquez55442132010-07-23 15:28:27 +05002403 sense_len = par_sense_len = rsp_info_len = resid_len =
2404 fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002405 if (IS_FWI2_CAPABLE(ha)) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002406 if (scsi_status & SS_SENSE_LEN_VALID)
2407 sense_len = le32_to_cpu(sts24->sense_len);
2408 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
2409 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
2410 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER))
2411 resid_len = le32_to_cpu(sts24->rsp_residual_count);
2412 if (comp_status == CS_DATA_UNDERRUN)
2413 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002414 rsp_info = sts24->data;
2415 sense_data = sts24->data;
2416 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002417 ox_id = le16_to_cpu(sts24->ox_id);
Andrew Vasquez55442132010-07-23 15:28:27 +05002418 par_sense_len = sizeof(sts24->data);
Chad Dupuise05fe292014-09-25 05:16:59 -04002419 /* Valid values of the retry delay timer are 0x1-0xffef */
2420 if (sts24->retry_delay > 0 && sts24->retry_delay < 0xfff1)
2421 retry_delay = sts24->retry_delay;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002422 } else {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002423 if (scsi_status & SS_SENSE_LEN_VALID)
2424 sense_len = le16_to_cpu(sts->req_sense_length);
2425 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
2426 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002427 resid_len = le32_to_cpu(sts->residual_length);
2428 rsp_info = sts->rsp_info;
2429 sense_data = sts->req_sense_data;
Andrew Vasquez55442132010-07-23 15:28:27 +05002430 par_sense_len = sizeof(sts->req_sense_data);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002431 }
2432
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 /* Check for any FCP transport errors. */
2434 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002435 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasquez55442132010-07-23 15:28:27 +05002436 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002437 sense_data += rsp_info_len;
Andrew Vasquez55442132010-07-23 15:28:27 +05002438 par_sense_len -= rsp_info_len;
2439 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002440 if (rsp_info_len > 3 && rsp_info[3]) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002441 ql_dbg(ql_dbg_io, fcport->vha, 0x3019,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002442 "FCP I/O protocol failure (0x%x/0x%x).\n",
2443 rsp_info_len, rsp_info[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002445 res = DID_BUS_BUSY << 16;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002446 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 }
2448 }
2449
Andrew Vasquez3e8ce322008-02-28 14:06:10 -08002450 /* Check for overrun. */
2451 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
2452 scsi_status & SS_RESIDUAL_OVER)
2453 comp_status = CS_DATA_OVERRUN;
2454
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 /*
Chad Dupuise05fe292014-09-25 05:16:59 -04002456 * Check retry_delay_timer value if we receive a busy or
2457 * queue full.
2458 */
2459 if (lscsi_status == SAM_STAT_TASK_SET_FULL ||
2460 lscsi_status == SAM_STAT_BUSY)
2461 qla2x00_set_retry_delay_timestamp(fcport, retry_delay);
2462
2463 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 * Based on Host and scsi status generate status code for Linux
2465 */
2466 switch (comp_status) {
2467 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002468 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 if (scsi_status == 0) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002470 res = DID_OK << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 break;
2472 }
2473 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002474 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002475 scsi_set_resid(cp, resid);
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002476
2477 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002478 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002479 cp->underflow)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002480 ql_dbg(ql_dbg_io, fcport->vha, 0x301a,
Quinn Tran83548fe2017-06-02 09:12:01 -07002481 "Mid-layer underflow detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002482 resid, scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002483
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002484 res = DID_ERROR << 16;
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002485 break;
2486 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002488 res = DID_OK << 16 | lscsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002490 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002491 ql_dbg(ql_dbg_io, fcport->vha, 0x301b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002492 "QUEUE FULL detected.\n");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002493 break;
2494 }
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002495 logit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 if (lscsi_status != SS_CHECK_CONDITION)
2497 break;
2498
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002499 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 if (!(scsi_status & SS_SENSE_LEN_VALID))
2501 break;
2502
Andrew Vasquez55442132010-07-23 15:28:27 +05002503 qla2x00_handle_sense(sp, sense_data, par_sense_len, sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002504 rsp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 break;
2506
2507 case CS_DATA_UNDERRUN:
Ravi Ananded17c71b52006-05-17 15:08:55 -07002508 /* Use F/W calculated residual length. */
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002509 resid = IS_FWI2_CAPABLE(ha) ? fw_resid_len : resid_len;
2510 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 if (scsi_status & SS_RESIDUAL_UNDER) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002512 if (IS_FWI2_CAPABLE(ha) && fw_resid_len != resid_len) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002513 ql_dbg(ql_dbg_io, fcport->vha, 0x301d,
Quinn Tran83548fe2017-06-02 09:12:01 -07002514 "Dropped frame(s) detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002515 resid, scsi_bufflen(cp));
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08002516
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002517 res = DID_ERROR << 16 | lscsi_status;
Arun Easi4e85e3d2011-11-18 09:02:10 -08002518 goto check_scsi_status;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002519 }
2520
2521 if (!lscsi_status &&
2522 ((unsigned)(scsi_bufflen(cp) - resid) <
2523 cp->underflow)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002524 ql_dbg(ql_dbg_io, fcport->vha, 0x301e,
Quinn Tran83548fe2017-06-02 09:12:01 -07002525 "Mid-layer underflow detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002526 resid, scsi_bufflen(cp));
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002527
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002528 res = DID_ERROR << 16;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002529 break;
2530 }
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002531 } else if (lscsi_status != SAM_STAT_TASK_SET_FULL &&
2532 lscsi_status != SAM_STAT_BUSY) {
2533 /*
2534 * scsi status of task set and busy are considered to be
2535 * task not completed.
2536 */
2537
Arun Easi5e19ed92012-02-09 11:15:51 -08002538 ql_dbg(ql_dbg_io, fcport->vha, 0x301f,
Quinn Tran83548fe2017-06-02 09:12:01 -07002539 "Dropped frame(s) detected (0x%x of 0x%x bytes).\n",
2540 resid, scsi_bufflen(cp));
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002541
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002542 res = DID_ERROR << 16 | lscsi_status;
Lalit Chandivade0374f552010-09-03 14:57:04 -07002543 goto check_scsi_status;
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002544 } else {
2545 ql_dbg(ql_dbg_io, fcport->vha, 0x3030,
2546 "scsi_status: 0x%x, lscsi_status: 0x%x\n",
2547 scsi_status, lscsi_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 }
2549
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002550 res = DID_OK << 16 | lscsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002551 logit = 0;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002552
Lalit Chandivade0374f552010-09-03 14:57:04 -07002553check_scsi_status:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002555 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 * Status.
2557 */
2558 if (lscsi_status != 0) {
Andrew Vasquezffec28a2007-01-29 10:22:27 -08002559 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002560 ql_dbg(ql_dbg_io, fcport->vha, 0x3020,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002561 "QUEUE FULL detected.\n");
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002562 logit = 1;
Andrew Vasquezffec28a2007-01-29 10:22:27 -08002563 break;
2564 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 if (lscsi_status != SS_CHECK_CONDITION)
2566 break;
2567
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002568 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 if (!(scsi_status & SS_SENSE_LEN_VALID))
2570 break;
2571
Andrew Vasquez55442132010-07-23 15:28:27 +05002572 qla2x00_handle_sense(sp, sense_data, par_sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002573 sense_len, rsp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 }
2575 break;
2576
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 case CS_PORT_LOGGED_OUT:
Quinn Tran726b8542017-01-19 22:28:00 -08002578 no_logout = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 case CS_PORT_CONFIG_CHG:
2580 case CS_PORT_BUSY:
2581 case CS_INCOMPLETE:
2582 case CS_PORT_UNAVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 case CS_TIMEOUT:
Chad Dupuisff454b02010-10-15 11:27:42 -07002584 case CS_RESET:
2585
Mike Christie056a4482008-08-19 18:45:29 -05002586 /*
2587 * We are going to have the fc class block the rport
2588 * while we try to recover so instruct the mid layer
2589 * to requeue until the class decides how to handle this.
2590 */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002591 res = DID_TRANSPORT_DISRUPTED << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002593 if (comp_status == CS_TIMEOUT) {
2594 if (IS_FWI2_CAPABLE(ha))
2595 break;
2596 else if ((le16_to_cpu(sts->status_flags) &
2597 SF_LOGOUT_SENT) == 0)
2598 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002600
Quinn Tran726b8542017-01-19 22:28:00 -08002601 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2602 ql_dbg(ql_dbg_disc, fcport->vha, 0x3021,
2603 "Port to be marked lost on fcport=%02x%02x%02x, current "
2604 "port state= %s comp_status %x.\n", fcport->d_id.b.domain,
2605 fcport->d_id.b.area, fcport->d_id.b.al_pa,
2606 port_state_str[atomic_read(&fcport->state)],
2607 comp_status);
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002608
Quinn Tran726b8542017-01-19 22:28:00 -08002609 if (no_logout)
2610 fcport->logout_on_delete = 0;
2611
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002612 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
Quinn Tran726b8542017-01-19 22:28:00 -08002613 qlt_schedule_sess_for_deletion_lock(fcport);
2614 }
2615
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 break;
2617
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002618 case CS_ABORTED:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002619 res = DID_RESET << 16;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002620 break;
Arun Easibad75002010-05-04 15:01:30 -07002621
2622 case CS_DIF_ERROR:
Arun Easi8cb20492011-08-16 11:29:22 -07002623 logit = qla2x00_handle_dif_error(sp, sts24);
Arun Easifb6e4662012-08-22 14:21:32 -04002624 res = cp->result;
Arun Easibad75002010-05-04 15:01:30 -07002625 break;
Arun Easi9e522cd2012-08-22 14:21:31 -04002626
2627 case CS_TRANSPORT:
2628 res = DID_ERROR << 16;
2629
2630 if (!IS_PI_SPLIT_DET_CAPABLE(ha))
2631 break;
2632
2633 if (state_flags & BIT_4)
2634 scmd_printk(KERN_WARNING, cp,
2635 "Unsupported device '%s' found.\n",
2636 cp->device->vendor);
2637 break;
2638
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 default:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002640 res = DID_ERROR << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 break;
2642 }
2643
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002644out:
2645 if (logit)
Arun Easi5e19ed92012-02-09 11:15:51 -08002646 ql_dbg(ql_dbg_io, fcport->vha, 0x3022,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02002647 "FCP command status: 0x%x-0x%x (0x%x) nexus=%ld:%d:%llu "
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04002648 "portid=%02x%02x%02x oxid=0x%x cdb=%10phN len=0x%x "
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04002649 "rsp_info=0x%x resid=0x%x fw_resid=0x%x sp=%p cp=%p.\n",
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002650 comp_status, scsi_status, res, vha->host_no,
Chad Dupuiscfb09192011-11-18 09:03:07 -08002651 cp->device->id, cp->device->lun, fcport->d_id.b.domain,
2652 fcport->d_id.b.area, fcport->d_id.b.al_pa, ox_id,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04002653 cp->cmnd, scsi_bufflen(cp), rsp_info_len,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04002654 resid_len, fw_resid_len, sp, cp);
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002655
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002656 if (rsp->status_srb == NULL)
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08002657 sp->done(sp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658}
2659
2660/**
2661 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
2662 * @ha: SCSI driver HA context
2663 * @pkt: Entry pointer
2664 *
2665 * Extended sense data.
2666 */
2667static void
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002668qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002670 uint8_t sense_sz = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002671 struct qla_hw_data *ha = rsp->hw;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002672 struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002673 srb_t *sp = rsp->status_srb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 struct scsi_cmnd *cp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002675 uint32_t sense_len;
2676 uint8_t *sense_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002678 if (!sp || !GET_CMD_SENSE_LEN(sp))
2679 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002681 sense_len = GET_CMD_SENSE_LEN(sp);
2682 sense_ptr = GET_CMD_SENSE_PTR(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002684 cp = GET_CMD_SP(sp);
2685 if (cp == NULL) {
2686 ql_log(ql_log_warn, vha, 0x3025,
2687 "cmd is NULL: already returned to OS (sp=%p).\n", sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002689 rsp->status_srb = NULL;
2690 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002693 if (sense_len > sizeof(pkt->data))
2694 sense_sz = sizeof(pkt->data);
2695 else
2696 sense_sz = sense_len;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002697
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002698 /* Move sense data. */
2699 if (IS_FWI2_CAPABLE(ha))
2700 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
2701 memcpy(sense_ptr, pkt->data, sense_sz);
2702 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302c,
2703 sense_ptr, sense_sz);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002704
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002705 sense_len -= sense_sz;
2706 sense_ptr += sense_sz;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002707
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002708 SET_CMD_SENSE_PTR(sp, sense_ptr);
2709 SET_CMD_SENSE_LEN(sp, sense_len);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002710
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002711 /* Place command on done queue. */
2712 if (sense_len == 0) {
2713 rsp->status_srb = NULL;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08002714 sp->done(sp, cp->result);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002715 }
Giridhar Malavalic4631192011-11-18 09:03:08 -08002716}
2717
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718/**
2719 * qla2x00_error_entry() - Process an error entry.
2720 * @ha: SCSI driver HA context
2721 * @pkt: Entry pointer
Quinn Tranc5419e22017-06-13 20:47:16 -07002722 * return : 1=allow further error analysis. 0=no additional error analysis.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 */
Quinn Tranc5419e22017-06-13 20:47:16 -07002724static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002725qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726{
2727 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002728 struct qla_hw_data *ha = vha->hw;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002729 const char func[] = "ERROR-IOCB";
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002730 uint16_t que = MSW(pkt->handle);
Arun Easia6fe35c2012-02-09 11:16:01 -08002731 struct req_que *req = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002732 int res = DID_ERROR << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002733
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002734 ql_dbg(ql_dbg_async, vha, 0x502a,
Quinn Tran82de8022017-06-13 20:47:17 -07002735 "iocb type %xh with error status %xh, handle %xh, rspq id %d\n",
2736 pkt->entry_type, pkt->entry_status, pkt->handle, rsp->id);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002737
Arun Easia6fe35c2012-02-09 11:16:01 -08002738 if (que >= ha->max_req_queues || !ha->req_q_map[que])
2739 goto fatal;
2740
2741 req = ha->req_q_map[que];
2742
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002743 if (pkt->entry_status & RF_BUSY)
2744 res = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745
Quinn Tranc5419e22017-06-13 20:47:16 -07002746 if ((pkt->handle & ~QLA_TGT_HANDLE_MASK) == QLA_TGT_SKIP_HANDLE)
2747 return 0;
Quinn Tran4f060732016-12-23 18:06:13 -08002748
Quinn Tranc5419e22017-06-13 20:47:16 -07002749 switch (pkt->entry_type) {
2750 case NOTIFY_ACK_TYPE:
2751 case STATUS_TYPE:
2752 case STATUS_CONT_TYPE:
2753 case LOGINOUT_PORT_IOCB_TYPE:
2754 case CT_IOCB_TYPE:
2755 case ELS_IOCB_TYPE:
2756 case ABORT_IOCB_TYPE:
2757 case MBX_IOCB_TYPE:
2758 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
2759 if (sp) {
2760 sp->done(sp, res);
2761 return 0;
2762 }
2763 break;
2764
2765 case ABTS_RESP_24XX:
2766 case CTIO_TYPE7:
2767 case CTIO_CRC2:
2768 default:
2769 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 }
Arun Easia6fe35c2012-02-09 11:16:01 -08002771fatal:
2772 ql_log(ql_log_warn, vha, 0x5030,
Chad Dupuisfd49a542015-08-04 13:37:58 -04002773 "Error entry - invalid handle/queue (%04x).\n", que);
Quinn Tranc5419e22017-06-13 20:47:16 -07002774 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775}
2776
2777/**
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002778 * qla24xx_mbx_completion() - Process mailbox command completions.
2779 * @ha: SCSI driver HA context
2780 * @mb0: Mailbox0 register
2781 */
2782static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002783qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002784{
2785 uint16_t cnt;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002786 uint32_t mboxes;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002787 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002788 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002789 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2790
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002791 /* Read all mbox registers? */
2792 mboxes = (1 << ha->mbx_count) - 1;
2793 if (!ha->mcp)
Masanari Iidaa7201012012-11-21 02:40:42 -05002794 ql_dbg(ql_dbg_async, vha, 0x504e, "MBX pointer ERROR.\n");
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002795 else
2796 mboxes = ha->mcp->in_mb;
2797
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002798 /* Load return mailbox registers. */
2799 ha->flags.mbox_int = 1;
2800 ha->mailbox_out[0] = mb0;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002801 mboxes >>= 1;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002802 wptr = (uint16_t __iomem *)&reg->mailbox1;
2803
2804 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002805 if (mboxes & BIT_0)
2806 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
2807
2808 mboxes >>= 1;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002809 wptr++;
2810 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002811}
2812
Armen Baloyan4440e462014-02-26 04:15:18 -05002813static void
2814qla24xx_abort_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
2815 struct abort_entry_24xx *pkt)
2816{
2817 const char func[] = "ABT_IOCB";
2818 srb_t *sp;
2819 struct srb_iocb *abt;
2820
2821 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
2822 if (!sp)
2823 return;
2824
2825 abt = &sp->u.iocb_cmd;
Quinn Tran15f30a52017-03-15 09:48:52 -07002826 abt->u.abt.comp_status = le16_to_cpu(pkt->nport_handle);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08002827 sp->done(sp, 0);
Armen Baloyan4440e462014-02-26 04:15:18 -05002828}
2829
Duane Grigsbye84067d2017-06-21 13:48:43 -07002830void qla24xx_nvme_ls4_iocb(scsi_qla_host_t *vha, struct pt_ls4_request *pkt,
2831 struct req_que *req)
2832{
2833 srb_t *sp;
2834 const char func[] = "LS4_IOCB";
2835 uint16_t comp_status;
2836
2837 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
2838 if (!sp)
2839 return;
2840
2841 comp_status = le16_to_cpu(pkt->status);
2842 sp->done(sp, comp_status);
2843}
2844
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002845/**
2846 * qla24xx_process_response_queue() - Process response queue entries.
2847 * @ha: SCSI driver HA context
2848 */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002849void qla24xx_process_response_queue(struct scsi_qla_host *vha,
2850 struct rsp_que *rsp)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002851{
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002852 struct sts_entry_24xx *pkt;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002853 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002854
Quinn Tranec7193e2017-03-15 09:48:55 -07002855 if (!ha->flags.fw_started)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002856 return;
2857
Quinn Trane326d222017-06-13 20:47:18 -07002858 if (rsp->qpair->cpuid != smp_processor_id())
2859 qla_cpu_update(rsp->qpair, smp_processor_id());
2860
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002861 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
2862 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002863
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002864 rsp->ring_index++;
2865 if (rsp->ring_index == rsp->length) {
2866 rsp->ring_index = 0;
2867 rsp->ring_ptr = rsp->ring;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002868 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002869 rsp->ring_ptr++;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002870 }
2871
2872 if (pkt->entry_status != 0) {
Quinn Tranc5419e22017-06-13 20:47:16 -07002873 if (qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt))
Quinn Tranf83adb62014-04-11 16:54:43 -04002874 goto process_err;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002875
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002876 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2877 wmb();
2878 continue;
2879 }
Quinn Tranf83adb62014-04-11 16:54:43 -04002880process_err:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002881
2882 switch (pkt->entry_type) {
2883 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002884 qla2x00_status_entry(vha, rsp, pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002885 break;
2886 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002887 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002888 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002889 case VP_RPT_ID_IOCB_TYPE:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002890 qla24xx_report_id_acquisition(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002891 (struct vp_rpt_id_entry_24xx *)pkt);
2892 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07002893 case LOGINOUT_PORT_IOCB_TYPE:
2894 qla24xx_logio_entry(vha, rsp->req,
2895 (struct logio_entry_24xx *)pkt);
2896 break;
Quinn Tranf83adb62014-04-11 16:54:43 -04002897 case CT_IOCB_TYPE:
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002898 qla24xx_els_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002899 break;
Quinn Tranf83adb62014-04-11 16:54:43 -04002900 case ELS_IOCB_TYPE:
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002901 qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE);
2902 break;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002903 case ABTS_RECV_24XX:
Quinn Tran2f424b92015-12-17 14:57:07 -05002904 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
2905 /* ensure that the ATIO queue is empty */
Quinn Tran82de8022017-06-13 20:47:17 -07002906 qlt_handle_abts_recv(vha, rsp,
2907 (response_t *)pkt);
Quinn Tran2f424b92015-12-17 14:57:07 -05002908 break;
2909 } else {
2910 /* drop through */
2911 qlt_24xx_process_atio_queue(vha, 1);
2912 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002913 case ABTS_RESP_24XX:
2914 case CTIO_TYPE7:
Quinn Tranf83adb62014-04-11 16:54:43 -04002915 case CTIO_CRC2:
Quinn Tran82de8022017-06-13 20:47:17 -07002916 qlt_response_pkt_all_vps(vha, rsp, (response_t *)pkt);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002917 break;
Duane Grigsbye84067d2017-06-21 13:48:43 -07002918 case PT_LS4_REQUEST:
2919 qla24xx_nvme_ls4_iocb(vha, (struct pt_ls4_request *)pkt,
2920 rsp->req);
2921 break;
Quinn Tran726b8542017-01-19 22:28:00 -08002922 case NOTIFY_ACK_TYPE:
2923 if (pkt->handle == QLA_TGT_SKIP_HANDLE)
Quinn Tran82de8022017-06-13 20:47:17 -07002924 qlt_response_pkt_all_vps(vha, rsp,
2925 (response_t *)pkt);
Quinn Tran726b8542017-01-19 22:28:00 -08002926 else
2927 qla24xxx_nack_iocb_entry(vha, rsp->req,
2928 (struct nack_to_isp *)pkt);
2929 break;
Saurav Kashyap54883292011-08-16 11:31:48 -07002930 case MARKER_TYPE:
2931 /* Do nothing in this case, this check is to prevent it
2932 * from falling into default case
2933 */
2934 break;
Armen Baloyan4440e462014-02-26 04:15:18 -05002935 case ABORT_IOCB_TYPE:
2936 qla24xx_abort_iocb_entry(vha, rsp->req,
2937 (struct abort_entry_24xx *)pkt);
2938 break;
Quinn Tran726b8542017-01-19 22:28:00 -08002939 case MBX_IOCB_TYPE:
2940 qla24xx_mbx_iocb_entry(vha, rsp->req,
2941 (struct mbx_24xx_entry *)pkt);
2942 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002943 default:
2944 /* Type Not Supported. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002945 ql_dbg(ql_dbg_async, vha, 0x5042,
2946 "Received unknown response pkt type %x "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002947 "entry status=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002948 pkt->entry_type, pkt->entry_status);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002949 break;
2950 }
2951 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2952 wmb();
2953 }
2954
2955 /* Adjust ring index */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002956 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002957 struct device_reg_82xx __iomem *reg = &ha->iobase->isp82;
2958 WRT_REG_DWORD(&reg->rsp_q_out[0], rsp->ring_index);
Quinn Tran726b8542017-01-19 22:28:00 -08002959 } else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002960 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
Quinn Tran726b8542017-01-19 22:28:00 -08002961 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002962}
2963
Andrew Vasquez05236a02007-09-20 14:07:37 -07002964static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002965qla2xxx_check_risc_status(scsi_qla_host_t *vha)
Andrew Vasquez05236a02007-09-20 14:07:37 -07002966{
2967 int rval;
2968 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002969 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez05236a02007-09-20 14:07:37 -07002970 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2971
Chad Dupuisf73cb692014-02-26 04:15:06 -05002972 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2973 !IS_QLA27XX(ha))
Andrew Vasquez05236a02007-09-20 14:07:37 -07002974 return;
2975
2976 rval = QLA_SUCCESS;
2977 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
2978 RD_REG_DWORD(&reg->iobase_addr);
2979 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
2980 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
2981 rval == QLA_SUCCESS; cnt--) {
2982 if (cnt) {
2983 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
2984 udelay(10);
2985 } else
2986 rval = QLA_FUNCTION_TIMEOUT;
2987 }
2988 if (rval == QLA_SUCCESS)
2989 goto next_test;
2990
Bart Van Asscheb2ec76c2013-06-25 11:27:29 -04002991 rval = QLA_SUCCESS;
Andrew Vasquez05236a02007-09-20 14:07:37 -07002992 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
2993 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
2994 rval == QLA_SUCCESS; cnt--) {
2995 if (cnt) {
2996 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
2997 udelay(10);
2998 } else
2999 rval = QLA_FUNCTION_TIMEOUT;
3000 }
3001 if (rval != QLA_SUCCESS)
3002 goto done;
3003
3004next_test:
3005 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003006 ql_log(ql_log_info, vha, 0x504c,
3007 "Additional code -- 0x55AA.\n");
Andrew Vasquez05236a02007-09-20 14:07:37 -07003008
3009done:
3010 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
3011 RD_REG_DWORD(&reg->iobase_window);
3012}
3013
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003014/**
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003015 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP24xx.
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003016 * @irq:
3017 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003018 *
3019 * Called by system whenever the host adapter generates an interrupt.
3020 *
3021 * Returns handled flag.
3022 */
3023irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01003024qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003025{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003026 scsi_qla_host_t *vha;
3027 struct qla_hw_data *ha;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003028 struct device_reg_24xx __iomem *reg;
3029 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003030 unsigned long iter;
3031 uint32_t stat;
3032 uint32_t hccr;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003033 uint16_t mb[8];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003034 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07003035 unsigned long flags;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003036
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003037 rsp = (struct rsp_que *) dev_id;
3038 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08003039 ql_log(ql_log_info, NULL, 0x5059,
3040 "%s: NULL response queue pointer.\n", __func__);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003041 return IRQ_NONE;
3042 }
3043
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003044 ha = rsp->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003045 reg = &ha->iobase->isp24;
3046 status = 0;
3047
Andrew Vasquez85880802009-12-15 21:29:46 -08003048 if (unlikely(pci_channel_offline(ha->pdev)))
3049 return IRQ_HANDLED;
3050
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07003051 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003052 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003053 for (iter = 50; iter--; ) {
3054 stat = RD_REG_DWORD(&reg->host_status);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04003055 if (qla2x00_check_reg32_for_disconnect(vha, stat))
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003056 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003057 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08003058 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07003059 break;
3060
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003061 hccr = RD_REG_DWORD(&reg->hccr);
3062
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003063 ql_log(ql_log_warn, vha, 0x504b,
3064 "RISC paused -- HCCR=%x, Dumping firmware.\n",
3065 hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07003066
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003067 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07003068
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003069 ha->isp_ops->fw_dump(vha, 1);
3070 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003071 break;
3072 } else if ((stat & HSRX_RISC_INT) == 0)
3073 break;
3074
3075 switch (stat & 0xff) {
Arun Easifafbda92012-08-22 14:21:16 -04003076 case INTR_ROM_MB_SUCCESS:
3077 case INTR_ROM_MB_FAILED:
3078 case INTR_MB_SUCCESS:
3079 case INTR_MB_FAILED:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003080 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003081 status |= MBX_INTERRUPT;
3082
3083 break;
Arun Easifafbda92012-08-22 14:21:16 -04003084 case INTR_ASYNC_EVENT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003085 mb[0] = MSW(stat);
3086 mb[1] = RD_REG_WORD(&reg->mailbox1);
3087 mb[2] = RD_REG_WORD(&reg->mailbox2);
3088 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003089 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003090 break;
Arun Easifafbda92012-08-22 14:21:16 -04003091 case INTR_RSP_QUE_UPDATE:
3092 case INTR_RSP_QUE_UPDATE_83XX:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003093 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003094 break;
Quinn Tran2f424b92015-12-17 14:57:07 -05003095 case INTR_ATIO_QUE_UPDATE:{
3096 unsigned long flags2;
3097 spin_lock_irqsave(&ha->tgt.atio_lock, flags2);
3098 qlt_24xx_process_atio_queue(vha, 1);
3099 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003100 break;
Quinn Tran2f424b92015-12-17 14:57:07 -05003101 }
3102 case INTR_ATIO_RSP_QUE_UPDATE: {
3103 unsigned long flags2;
3104 spin_lock_irqsave(&ha->tgt.atio_lock, flags2);
3105 qlt_24xx_process_atio_queue(vha, 1);
3106 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2);
3107
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003108 qla24xx_process_response_queue(vha, rsp);
3109 break;
Quinn Tran2f424b92015-12-17 14:57:07 -05003110 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003111 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003112 ql_dbg(ql_dbg_async, vha, 0x504f,
3113 "Unrecognized interrupt type (%d).\n", stat * 0xff);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003114 break;
3115 }
3116 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
3117 RD_REG_DWORD_RELAXED(&reg->hccr);
Giridhar Malavalicb860bb2012-08-22 14:21:30 -04003118 if (unlikely(IS_QLA83XX(ha) && (ha->pdev->revision == 1)))
3119 ndelay(3500);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003120 }
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -07003121 qla2x00_handle_mbx_completion(ha, status);
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07003122 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003123
Andrew Vasquez9a853f72005-07-06 10:31:27 -07003124 return IRQ_HANDLED;
3125}
3126
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003127static irqreturn_t
3128qla24xx_msix_rsp_q(int irq, void *dev_id)
3129{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003130 struct qla_hw_data *ha;
3131 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003132 struct device_reg_24xx __iomem *reg;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003133 struct scsi_qla_host *vha;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08003134 unsigned long flags;
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003135 uint32_t stat = 0;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003136
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003137 rsp = (struct rsp_que *) dev_id;
3138 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08003139 ql_log(ql_log_info, NULL, 0x505a,
3140 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003141 return IRQ_NONE;
3142 }
3143 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003144 reg = &ha->iobase->isp24;
3145
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08003146 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003147
Anirban Chakrabortya67093d2010-02-04 14:17:59 -08003148 vha = pci_get_drvdata(ha->pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003149 /*
3150 * Use host_status register to check to PCI disconnection before we
3151 * we process the response queue.
3152 */
3153 stat = RD_REG_DWORD(&reg->host_status);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04003154 if (qla2x00_check_reg32_for_disconnect(vha, stat))
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003155 goto out;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003156 qla24xx_process_response_queue(vha, rsp);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003157 if (!ha->flags.disable_msix_handshake) {
Anirban Chakrabortyeb941142009-08-04 16:12:13 -07003158 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
3159 RD_REG_DWORD_RELAXED(&reg->hccr);
3160 }
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003161out:
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08003162 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003163
3164 return IRQ_HANDLED;
3165}
3166
3167static irqreturn_t
3168qla24xx_msix_default(int irq, void *dev_id)
3169{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003170 scsi_qla_host_t *vha;
3171 struct qla_hw_data *ha;
3172 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003173 struct device_reg_24xx __iomem *reg;
3174 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003175 uint32_t stat;
3176 uint32_t hccr;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003177 uint16_t mb[8];
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08003178 unsigned long flags;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003179
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003180 rsp = (struct rsp_que *) dev_id;
3181 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08003182 ql_log(ql_log_info, NULL, 0x505c,
3183 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003184 return IRQ_NONE;
3185 }
3186 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003187 reg = &ha->iobase->isp24;
3188 status = 0;
3189
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08003190 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003191 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez87f27012007-09-20 14:07:49 -07003192 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003193 stat = RD_REG_DWORD(&reg->host_status);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04003194 if (qla2x00_check_reg32_for_disconnect(vha, stat))
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003195 break;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003196 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08003197 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07003198 break;
3199
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003200 hccr = RD_REG_DWORD(&reg->hccr);
3201
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003202 ql_log(ql_log_info, vha, 0x5050,
3203 "RISC paused -- HCCR=%x, Dumping firmware.\n",
3204 hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07003205
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003206 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07003207
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003208 ha->isp_ops->fw_dump(vha, 1);
3209 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003210 break;
3211 } else if ((stat & HSRX_RISC_INT) == 0)
3212 break;
3213
3214 switch (stat & 0xff) {
Arun Easifafbda92012-08-22 14:21:16 -04003215 case INTR_ROM_MB_SUCCESS:
3216 case INTR_ROM_MB_FAILED:
3217 case INTR_MB_SUCCESS:
3218 case INTR_MB_FAILED:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003219 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003220 status |= MBX_INTERRUPT;
3221
3222 break;
Arun Easifafbda92012-08-22 14:21:16 -04003223 case INTR_ASYNC_EVENT:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003224 mb[0] = MSW(stat);
3225 mb[1] = RD_REG_WORD(&reg->mailbox1);
3226 mb[2] = RD_REG_WORD(&reg->mailbox2);
3227 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003228 qla2x00_async_event(vha, rsp, mb);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003229 break;
Arun Easifafbda92012-08-22 14:21:16 -04003230 case INTR_RSP_QUE_UPDATE:
3231 case INTR_RSP_QUE_UPDATE_83XX:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003232 qla24xx_process_response_queue(vha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003233 break;
Quinn Tran2f424b92015-12-17 14:57:07 -05003234 case INTR_ATIO_QUE_UPDATE:{
3235 unsigned long flags2;
3236 spin_lock_irqsave(&ha->tgt.atio_lock, flags2);
3237 qlt_24xx_process_atio_queue(vha, 1);
3238 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003239 break;
Quinn Tran2f424b92015-12-17 14:57:07 -05003240 }
3241 case INTR_ATIO_RSP_QUE_UPDATE: {
3242 unsigned long flags2;
3243 spin_lock_irqsave(&ha->tgt.atio_lock, flags2);
3244 qlt_24xx_process_atio_queue(vha, 1);
3245 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2);
3246
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003247 qla24xx_process_response_queue(vha, rsp);
3248 break;
Quinn Tran2f424b92015-12-17 14:57:07 -05003249 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003250 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003251 ql_dbg(ql_dbg_async, vha, 0x5051,
3252 "Unrecognized interrupt type (%d).\n", stat & 0xff);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003253 break;
3254 }
3255 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07003256 } while (0);
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -07003257 qla2x00_handle_mbx_completion(ha, status);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08003258 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003259
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003260 return IRQ_HANDLED;
3261}
3262
Michael Hernandezd7459522016-12-12 14:40:07 -08003263irqreturn_t
3264qla2xxx_msix_rsp_q(int irq, void *dev_id)
3265{
3266 struct qla_hw_data *ha;
3267 struct qla_qpair *qpair;
3268 struct device_reg_24xx __iomem *reg;
3269 unsigned long flags;
3270
3271 qpair = dev_id;
3272 if (!qpair) {
3273 ql_log(ql_log_info, NULL, 0x505b,
3274 "%s: NULL response queue pointer.\n", __func__);
3275 return IRQ_NONE;
3276 }
3277 ha = qpair->hw;
3278
3279 /* Clear the interrupt, if enabled, for this response queue */
3280 if (unlikely(!ha->flags.disable_msix_handshake)) {
3281 reg = &ha->iobase->isp24;
3282 spin_lock_irqsave(&ha->hardware_lock, flags);
3283 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
3284 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3285 }
3286
3287 queue_work(ha->wq, &qpair->q_work);
3288
3289 return IRQ_HANDLED;
3290}
3291
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003292/* Interrupt handling helpers. */
3293
3294struct qla_init_msix_entry {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003295 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07003296 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003297};
3298
Nicolas Iooss44a8f952016-12-26 14:23:10 +01003299static const struct qla_init_msix_entry msix_entries[] = {
Quinn Trane326d222017-06-13 20:47:18 -07003300 { "default", qla24xx_msix_default },
3301 { "rsp_q", qla24xx_msix_rsp_q },
3302 { "atio_q", qla83xx_msix_atio_q },
3303 { "qpair_multiq", qla2xxx_msix_rsp_q },
Arun Easiaa230bc2013-01-30 03:34:39 -05003304};
3305
Nicolas Iooss44a8f952016-12-26 14:23:10 +01003306static const struct qla_init_msix_entry qla82xx_msix_entries[] = {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003307 { "qla2xxx (default)", qla82xx_msix_default },
3308 { "qla2xxx (rsp_q)", qla82xx_msix_rsp_q },
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003309};
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003310
3311static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003312qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003313{
3314 int i, ret;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003315 struct qla_msix_entry *qentry;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003316 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Michael Hernandez67f2db82017-02-15 15:37:21 -08003317 int min_vecs = QLA_BASE_VECTORS;
Christoph Hellwig17e5fc52017-01-11 17:55:45 +01003318 struct irq_affinity desc = {
3319 .pre_vectors = QLA_BASE_VECTORS,
3320 };
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003321
Michael Hernandez67f2db82017-02-15 15:37:21 -08003322 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) {
Christoph Hellwig17e5fc52017-01-11 17:55:45 +01003323 desc.pre_vectors++;
Michael Hernandez67f2db82017-02-15 15:37:21 -08003324 min_vecs++;
3325 }
Christoph Hellwig17e5fc52017-01-11 17:55:45 +01003326
Quinn Tran09620ee2017-06-13 20:47:20 -07003327 if (USER_CTRL_IRQ(ha)) {
3328 /* user wants to control IRQ setting for target mode */
3329 ret = pci_alloc_irq_vectors(ha->pdev, min_vecs,
3330 ha->msix_count, PCI_IRQ_MSIX);
3331 } else
3332 ret = pci_alloc_irq_vectors_affinity(ha->pdev, min_vecs,
3333 ha->msix_count, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY,
3334 &desc);
Christoph Hellwig17e5fc52017-01-11 17:55:45 +01003335
Alexander Gordeev84e32a02014-08-18 08:01:47 +02003336 if (ret < 0) {
3337 ql_log(ql_log_fatal, vha, 0x00c7,
3338 "MSI-X: Failed to enable support, "
3339 "giving up -- %d/%d.\n",
3340 ha->msix_count, ret);
3341 goto msix_out;
3342 } else if (ret < ha->msix_count) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003343 ql_log(ql_log_warn, vha, 0x00c6,
3344 "MSI-X: Failed to enable support "
Michael Hernandezd7459522016-12-12 14:40:07 -08003345 "with %d vectors, using %d vectors.\n",
3346 ha->msix_count, ret);
Quinn Trancb432852016-02-04 11:45:16 -05003347 ha->msix_count = ret;
Michael Hernandezd7459522016-12-12 14:40:07 -08003348 /* Recalculate queue values */
3349 if (ha->mqiobase && ql2xmqsupport) {
3350 ha->max_req_queues = ha->msix_count - 1;
3351
3352 /* ATIOQ needs 1 vector. That's 1 less QPair */
3353 if (QLA_TGT_MODE_ENABLED())
3354 ha->max_req_queues--;
3355
3356 ha->max_rsp_queues = ha->max_req_queues;
3357
3358 ha->max_qpairs = ha->max_req_queues - 1;
3359 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0190,
3360 "Adjusted Max no of queues pairs: %d.\n", ha->max_qpairs);
3361 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003362 }
3363 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
3364 ha->msix_count, GFP_KERNEL);
3365 if (!ha->msix_entries) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003366 ql_log(ql_log_fatal, vha, 0x00c8,
3367 "Failed to allocate memory for ha->msix_entries.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003368 ret = -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003369 goto msix_out;
3370 }
3371 ha->flags.msix_enabled = 1;
3372
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003373 for (i = 0; i < ha->msix_count; i++) {
3374 qentry = &ha->msix_entries[i];
Michael Hernandez4fa18342016-12-12 14:40:06 -08003375 qentry->vector = pci_irq_vector(ha->pdev, i);
3376 qentry->entry = i;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003377 qentry->have_irq = 0;
Michael Hernandezd7459522016-12-12 14:40:07 -08003378 qentry->in_use = 0;
Michael Hernandez4fa18342016-12-12 14:40:06 -08003379 qentry->handle = NULL;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003380 }
3381
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003382 /* Enable MSI-X vectors for the base queue */
Christoph Hellwig17e5fc52017-01-11 17:55:45 +01003383 for (i = 0; i < QLA_BASE_VECTORS; i++) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003384 qentry = &ha->msix_entries[i];
Michael Hernandez4fa18342016-12-12 14:40:06 -08003385 qentry->handle = rsp;
Johannes Thumshirnef8d1d512016-07-06 09:51:50 +02003386 rsp->msix = qentry;
Michael Hernandezd7459522016-12-12 14:40:07 -08003387 scnprintf(qentry->name, sizeof(qentry->name),
Quinn Trane326d222017-06-13 20:47:18 -07003388 "qla2xxx%lu_%s", vha->host_no, msix_entries[i].name);
Chad Dupuisf3247772014-02-26 04:15:14 -05003389 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07003390 ret = request_irq(qentry->vector,
3391 qla82xx_msix_entries[i].handler,
3392 0, qla82xx_msix_entries[i].name, rsp);
Chad Dupuisf3247772014-02-26 04:15:14 -05003393 else
Giridhar Malavalia9083012010-04-12 17:59:55 -07003394 ret = request_irq(qentry->vector,
3395 msix_entries[i].handler,
Quinn Trane326d222017-06-13 20:47:18 -07003396 0, qentry->name, rsp);
Chad Dupuisf3247772014-02-26 04:15:14 -05003397 if (ret)
3398 goto msix_register_fail;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003399 qentry->have_irq = 1;
Quinn Tran093df732016-12-12 14:40:09 -08003400 qentry->in_use = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003401 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003402
Chad Dupuisf3247772014-02-26 04:15:14 -05003403 /*
3404 * If target mode is enable, also request the vector for the ATIO
3405 * queue.
3406 */
3407 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) {
Quinn Tran093df732016-12-12 14:40:09 -08003408 qentry = &ha->msix_entries[QLA_ATIO_VECTOR];
Johannes Thumshirnef8d1d512016-07-06 09:51:50 +02003409 rsp->msix = qentry;
Michael Hernandezd7459522016-12-12 14:40:07 -08003410 qentry->handle = rsp;
3411 scnprintf(qentry->name, sizeof(qentry->name),
Quinn Trane326d222017-06-13 20:47:18 -07003412 "qla2xxx%lu_%s", vha->host_no,
3413 msix_entries[QLA_ATIO_VECTOR].name);
Quinn Tran093df732016-12-12 14:40:09 -08003414 qentry->in_use = 1;
Chad Dupuisf3247772014-02-26 04:15:14 -05003415 ret = request_irq(qentry->vector,
Quinn Tran093df732016-12-12 14:40:09 -08003416 msix_entries[QLA_ATIO_VECTOR].handler,
Quinn Trane326d222017-06-13 20:47:18 -07003417 0, qentry->name, rsp);
Chad Dupuisf3247772014-02-26 04:15:14 -05003418 qentry->have_irq = 1;
Chad Dupuisf3247772014-02-26 04:15:14 -05003419 }
3420
3421msix_register_fail:
3422 if (ret) {
3423 ql_log(ql_log_fatal, vha, 0x00cb,
3424 "MSI-X: unable to register handler -- %x/%d.\n",
3425 qentry->vector, ret);
Michael Hernandez4fa18342016-12-12 14:40:06 -08003426 qla2x00_free_irqs(vha);
Chad Dupuisf3247772014-02-26 04:15:14 -05003427 ha->mqenable = 0;
3428 goto msix_out;
3429 }
3430
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003431 /* Enable MSI-X vector for response queue update for queue 0 */
himanshu.madhani@cavium.comcb590702017-05-24 18:06:18 -07003432 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003433 if (ha->msixbase && ha->mqiobase &&
Michael Hernandezd7459522016-12-12 14:40:07 -08003434 (ha->max_rsp_queues > 1 || ha->max_req_queues > 1 ||
3435 ql2xmqsupport))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003436 ha->mqenable = 1;
3437 } else
Michael Hernandezd7459522016-12-12 14:40:07 -08003438 if (ha->mqiobase &&
3439 (ha->max_rsp_queues > 1 || ha->max_req_queues > 1 ||
3440 ql2xmqsupport))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003441 ha->mqenable = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003442 ql_dbg(ql_dbg_multiq, vha, 0xc005,
3443 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
3444 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
3445 ql_dbg(ql_dbg_init, vha, 0x0055,
3446 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
3447 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003448
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003449msix_out:
3450 return ret;
3451}
3452
3453int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003454qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003455{
Sawan Chandak7fa3e232013-10-30 03:38:10 -04003456 int ret = QLA_FUNCTION_FAILED;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003457 device_reg_t *reg = ha->iobase;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003458 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003459
3460 /* If possible, enable MSI-X. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003461 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
Chad Dupuisf73cb692014-02-26 04:15:06 -05003462 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha) && !IS_QLAFX00(ha) &&
3463 !IS_QLA27XX(ha))
Ben Hutchings6377a7a2010-03-19 16:59:19 -07003464 goto skip_msi;
3465
3466 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
3467 (ha->pdev->subsystem_device == 0x7040 ||
3468 ha->pdev->subsystem_device == 0x7041 ||
3469 ha->pdev->subsystem_device == 0x1705)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003470 ql_log(ql_log_warn, vha, 0x0034,
3471 "MSI-X: Unsupported ISP 2432 SSVID/SSDID (0x%X,0x%X).\n",
Ben Hutchings6377a7a2010-03-19 16:59:19 -07003472 ha->pdev->subsystem_vendor,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003473 ha->pdev->subsystem_device);
Ben Hutchings6377a7a2010-03-19 16:59:19 -07003474 goto skip_msi;
3475 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003476
Chad Dupuis42cd4f52011-08-16 11:29:24 -07003477 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003478 ql_log(ql_log_warn, vha, 0x0035,
3479 "MSI-X; Unsupported ISP2432 (0x%X, 0x%X).\n",
Chad Dupuis42cd4f52011-08-16 11:29:24 -07003480 ha->pdev->revision, QLA_MSIX_CHIP_REV_24XX);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003481 goto skip_msix;
3482 }
3483
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003484 ret = qla24xx_enable_msix(ha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003485 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003486 ql_dbg(ql_dbg_init, vha, 0x0036,
3487 "MSI-X: Enabled (0x%X, 0x%X).\n",
3488 ha->chip_revision, ha->fw_attributes);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003489 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003490 }
Sawan Chandak7fa3e232013-10-30 03:38:10 -04003491
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003492skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07003493
Sawan Chandak7fa3e232013-10-30 03:38:10 -04003494 ql_log(ql_log_info, vha, 0x0037,
3495 "Falling back-to MSI mode -%d.\n", ret);
3496
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003497 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
Chad Dupuisf73cb692014-02-26 04:15:06 -05003498 !IS_QLA8001(ha) && !IS_P3P_TYPE(ha) && !IS_QLAFX00(ha) &&
3499 !IS_QLA27XX(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07003500 goto skip_msi;
3501
Michael Hernandez4fa18342016-12-12 14:40:06 -08003502 ret = pci_alloc_irq_vectors(ha->pdev, 1, 1, PCI_IRQ_MSI);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07003503 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003504 ql_dbg(ql_dbg_init, vha, 0x0038,
3505 "MSI: Enabled.\n");
Andrew Vasquezcbedb602007-05-07 07:43:02 -07003506 ha->flags.msi_enabled = 1;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003507 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003508 ql_log(ql_log_warn, vha, 0x0039,
Sawan Chandak7fa3e232013-10-30 03:38:10 -04003509 "Falling back-to INTa mode -- %d.\n", ret);
3510skip_msi:
Giridhar Malavalia033b652012-08-22 14:21:07 -04003511
3512 /* Skip INTx on ISP82xx. */
3513 if (!ha->flags.msi_enabled && IS_QLA82XX(ha))
3514 return QLA_FUNCTION_FAILED;
3515
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003516 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Mike Hernandez7992abf2010-11-23 16:52:47 -08003517 ha->flags.msi_enabled ? 0 : IRQF_SHARED,
3518 QLA2XXX_DRIVER_NAME, rsp);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003519 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003520 ql_log(ql_log_warn, vha, 0x003a,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003521 "Failed to reserve interrupt %d already in use.\n",
3522 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003523 goto fail;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003524 } else if (!ha->flags.msi_enabled) {
Saurav Kashyap68d91cb2012-11-21 02:40:44 -05003525 ql_dbg(ql_dbg_init, vha, 0x0125,
3526 "INTa mode: Enabled.\n");
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003527 ha->flags.mr_intr_valid = 1;
3528 }
Mike Hernandez7992abf2010-11-23 16:52:47 -08003529
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003530clear_risc_ints:
Joe Carnuccio4bb2efc2014-09-25 05:16:42 -04003531 if (IS_FWI2_CAPABLE(ha) || IS_QLAFX00(ha))
3532 goto fail;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003533
Andrew Vasquezc6952482008-04-03 13:13:17 -07003534 spin_lock_irq(&ha->hardware_lock);
Joe Carnuccio4bb2efc2014-09-25 05:16:42 -04003535 WRT_REG_WORD(&reg->isp.semaphore, 0);
Andrew Vasquezc6952482008-04-03 13:13:17 -07003536 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003537
3538fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003539 return ret;
3540}
3541
3542void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003543qla2x00_free_irqs(scsi_qla_host_t *vha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003544{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003545 struct qla_hw_data *ha = vha->hw;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003546 struct rsp_que *rsp;
Michael Hernandez4fa18342016-12-12 14:40:06 -08003547 struct qla_msix_entry *qentry;
3548 int i;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003549
3550 /*
3551 * We need to check that ha->rsp_q_map is valid in case we are called
3552 * from a probe failure context.
3553 */
3554 if (!ha->rsp_q_map || !ha->rsp_q_map[0])
Bart Van Assche27873de2017-01-23 08:34:45 -08003555 goto free_irqs;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003556 rsp = ha->rsp_q_map[0];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003557
Michael Hernandez4fa18342016-12-12 14:40:06 -08003558 if (ha->flags.msix_enabled) {
3559 for (i = 0; i < ha->msix_count; i++) {
3560 qentry = &ha->msix_entries[i];
3561 if (qentry->have_irq) {
3562 irq_set_affinity_notifier(qentry->vector, NULL);
3563 free_irq(pci_irq_vector(ha->pdev, i), qentry->handle);
3564 }
3565 }
3566 kfree(ha->msix_entries);
3567 ha->msix_entries = NULL;
3568 ha->flags.msix_enabled = 0;
3569 ql_dbg(ql_dbg_init, vha, 0x0042,
3570 "Disabled MSI-X.\n");
3571 } else {
3572 free_irq(pci_irq_vector(ha->pdev, 0), rsp);
3573 }
3574
Bart Van Assche27873de2017-01-23 08:34:45 -08003575free_irqs:
Michael Hernandez4fa18342016-12-12 14:40:06 -08003576 pci_free_irq_vectors(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003577}
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003578
Michael Hernandezd7459522016-12-12 14:40:07 -08003579int qla25xx_request_irq(struct qla_hw_data *ha, struct qla_qpair *qpair,
3580 struct qla_msix_entry *msix, int vector_type)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003581{
Nicolas Iooss44a8f952016-12-26 14:23:10 +01003582 const struct qla_init_msix_entry *intr = &msix_entries[vector_type];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003583 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003584 int ret;
3585
Michael Hernandezd7459522016-12-12 14:40:07 -08003586 scnprintf(msix->name, sizeof(msix->name),
3587 "qla2xxx%lu_qpair%d", vha->host_no, qpair->id);
3588 ret = request_irq(msix->vector, intr->handler, 0, msix->name, qpair);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003589 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003590 ql_log(ql_log_fatal, vha, 0x00e6,
3591 "MSI-X: Unable to register handler -- %x/%d.\n",
3592 msix->vector, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003593 return ret;
3594 }
3595 msix->have_irq = 1;
Michael Hernandezd7459522016-12-12 14:40:07 -08003596 msix->handle = qpair;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003597 return ret;
3598}