blob: b2b93dfbffd36fc8d089439b488a2c28daff68ab [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>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070012#include <scsi/scsi_tcq.h>
Giridhar Malavali9a069e12010-01-12 13:02:47 -080013#include <scsi/scsi_bsg_fc.h>
Arun Easibad75002010-05-04 15:01:30 -070014#include <scsi/scsi_eh.h>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070015
Linus Torvalds1da177e2005-04-16 15:20:36 -070016static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080017static void qla2x00_status_entry(scsi_qla_host_t *, struct rsp_que *, void *);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070018static void qla2x00_status_cont_entry(struct rsp_que *, sts_cont_entry_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080019static void qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
20 sts_entry_t *);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022/**
23 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
24 * @irq:
25 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 *
27 * Called by system whenever the host adapter generates an interrupt.
28 *
29 * Returns handled flag.
30 */
31irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +010032qla2100_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080034 scsi_qla_host_t *vha;
35 struct qla_hw_data *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -070036 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 unsigned long iter;
Seokmann Ju14e660e2007-09-20 14:07:36 -070039 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070040 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080041 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070042 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080044 rsp = (struct rsp_que *) dev_id;
45 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -080046 ql_log(ql_log_info, NULL, 0x505d,
47 "%s: NULL response queue pointer.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 return (IRQ_NONE);
49 }
50
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080051 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -070052 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 status = 0;
54
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070055 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070056 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 for (iter = 50; iter--; ) {
Seokmann Ju14e660e2007-09-20 14:07:36 -070058 hccr = RD_REG_WORD(&reg->hccr);
Joe Lawrencec821e0d2014-08-26 17:11:41 -040059 if (qla2x00_check_reg16_for_disconnect(vha, hccr))
Chad Dupuisf3ddac12013-10-30 03:38:16 -040060 break;
Seokmann Ju14e660e2007-09-20 14:07:36 -070061 if (hccr & HCCR_RISC_PAUSE) {
62 if (pci_channel_offline(ha->pdev))
63 break;
64
65 /*
66 * Issue a "HARD" reset in order for the RISC interrupt
Justin P. Mattocka06a0f82011-06-23 23:22:27 -070067 * bit to be cleared. Schedule a big hammer to get
Seokmann Ju14e660e2007-09-20 14:07:36 -070068 * out of the RISC PAUSED state.
69 */
70 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
71 RD_REG_WORD(&reg->hccr);
72
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080073 ha->isp_ops->fw_dump(vha, 1);
74 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -070075 break;
76 } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 break;
78
79 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
80 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
81 RD_REG_WORD(&reg->hccr);
82
83 /* Get mailbox data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -070084 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
85 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080086 qla2x00_mbx_completion(vha, mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 status |= MBX_INTERRUPT;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070088 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
89 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
90 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
91 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080092 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 } else {
94 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -070095 ql_dbg(ql_dbg_async, vha, 0x5025,
96 "Unrecognized interrupt type (%d).\n",
97 mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 }
99 /* Release mailbox registers. */
100 WRT_REG_WORD(&reg->semaphore, 0);
101 RD_REG_WORD(&reg->semaphore);
102 } else {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800103 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
106 RD_REG_WORD(&reg->hccr);
107 }
108 }
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -0700109 qla2x00_handle_mbx_completion(ha, status);
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700110 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 return (IRQ_HANDLED);
113}
114
Chad Dupuisf3ddac12013-10-30 03:38:16 -0400115bool
Joe Lawrencec821e0d2014-08-26 17:11:41 -0400116qla2x00_check_reg32_for_disconnect(scsi_qla_host_t *vha, uint32_t reg)
Chad Dupuisf3ddac12013-10-30 03:38:16 -0400117{
118 /* Check for PCI disconnection */
Thadeu Lima de Souza Cascardoa30c2a32015-04-30 09:13:05 -0300119 if (reg == 0xffffffff && !pci_channel_offline(vha->hw->pdev)) {
Joe Lawrencebeb9e312014-08-26 17:12:14 -0400120 if (!test_and_set_bit(PFLG_DISCONNECTED, &vha->pci_flags) &&
Joe Lawrence6b383972014-08-26 17:12:29 -0400121 !test_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags) &&
122 !test_bit(PFLG_DRIVER_PROBING, &vha->pci_flags)) {
Joe Lawrence232792b2014-08-26 17:12:01 -0400123 /*
124 * Schedule this (only once) on the default system
125 * workqueue so that all the adapter workqueues and the
126 * DPC thread can be shutdown cleanly.
127 */
128 schedule_work(&vha->hw->board_disable);
129 }
Chad Dupuisf3ddac12013-10-30 03:38:16 -0400130 return true;
131 } else
132 return false;
133}
134
Joe Lawrencec821e0d2014-08-26 17:11:41 -0400135bool
136qla2x00_check_reg16_for_disconnect(scsi_qla_host_t *vha, uint16_t reg)
137{
138 return qla2x00_check_reg32_for_disconnect(vha, 0xffff0000 | reg);
139}
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141/**
142 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
143 * @irq:
144 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 *
146 * Called by system whenever the host adapter generates an interrupt.
147 *
148 * Returns handled flag.
149 */
150irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100151qla2300_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800153 scsi_qla_host_t *vha;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700154 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 unsigned long iter;
157 uint32_t stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700159 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800160 struct rsp_que *rsp;
161 struct qla_hw_data *ha;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700162 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800164 rsp = (struct rsp_que *) dev_id;
165 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -0800166 ql_log(ql_log_info, NULL, 0x5058,
167 "%s: NULL response queue pointer.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 return (IRQ_NONE);
169 }
170
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800171 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700172 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 status = 0;
174
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700175 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700176 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 for (iter = 50; iter--; ) {
178 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
Joe Lawrencec821e0d2014-08-26 17:11:41 -0400179 if (qla2x00_check_reg32_for_disconnect(vha, stat))
Chad Dupuisf3ddac12013-10-30 03:38:16 -0400180 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 if (stat & HSR_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800182 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -0700183 break;
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 hccr = RD_REG_WORD(&reg->hccr);
Chad Dupuisf3ddac12013-10-30 03:38:16 -0400186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700188 ql_log(ql_log_warn, vha, 0x5026,
189 "Parity error -- HCCR=%x, Dumping "
190 "firmware.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700192 ql_log(ql_log_warn, vha, 0x5027,
193 "RISC paused -- HCCR=%x, Dumping "
194 "firmware.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
196 /*
197 * Issue a "HARD" reset in order for the RISC
198 * interrupt bit to be cleared. Schedule a big
Justin P. Mattocka06a0f82011-06-23 23:22:27 -0700199 * hammer to get out of the RISC PAUSED state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 */
201 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
202 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800203
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800204 ha->isp_ops->fw_dump(vha, 1);
205 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 break;
207 } else if ((stat & HSR_RISC_INT) == 0)
208 break;
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 case 0x1:
212 case 0x2:
213 case 0x10:
214 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800215 qla2x00_mbx_completion(vha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 status |= MBX_INTERRUPT;
217
218 /* Release mailbox registers. */
219 WRT_REG_WORD(&reg->semaphore, 0);
220 break;
221 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700222 mb[0] = MSW(stat);
223 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
224 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
225 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800226 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700227 break;
228 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800229 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 break;
231 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700232 mb[0] = MBA_CMPLT_1_16BIT;
233 mb[1] = MSW(stat);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800234 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 break;
236 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700237 mb[0] = MBA_SCSI_COMPLETION;
238 mb[1] = MSW(stat);
239 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800240 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 break;
242 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700243 ql_dbg(ql_dbg_async, vha, 0x5028,
244 "Unrecognized interrupt type (%d).\n", stat & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 break;
246 }
247 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
248 RD_REG_WORD_RELAXED(&reg->hccr);
249 }
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -0700250 qla2x00_handle_mbx_completion(ha, status);
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700251 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 return (IRQ_HANDLED);
254}
255
256/**
257 * qla2x00_mbx_completion() - Process mailbox command completions.
258 * @ha: SCSI driver HA context
259 * @mb0: Mailbox0 register
260 */
261static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800262qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
264 uint16_t cnt;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800265 uint32_t mboxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800267 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700268 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800270 /* Read all mbox registers? */
271 mboxes = (1 << ha->mbx_count) - 1;
272 if (!ha->mcp)
Masanari Iidaa7201012012-11-21 02:40:42 -0500273 ql_dbg(ql_dbg_async, vha, 0x5001, "MBX pointer ERROR.\n");
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800274 else
275 mboxes = ha->mcp->in_mb;
276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 /* Load return mailbox registers. */
278 ha->flags.mbox_int = 1;
279 ha->mailbox_out[0] = mb0;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800280 mboxes >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
282
283 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700284 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800286 if ((cnt == 4 || cnt == 5) && (mboxes & BIT_0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800288 else if (mboxes & BIT_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700290
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 wptr++;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800292 mboxes >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294}
295
Andrew Vasquez8a659572009-02-08 20:50:12 -0800296static void
297qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
298{
299 static char *event[] =
300 { "Complete", "Request Notification", "Time Extension" };
301 int rval;
302 struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
Chad Dupuis9e5054e2013-10-30 03:38:23 -0400303 struct device_reg_82xx __iomem *reg82 = &vha->hw->iobase->isp82;
Andrew Vasquez8a659572009-02-08 20:50:12 -0800304 uint16_t __iomem *wptr;
305 uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
306
307 /* Seed data -- mailbox1 -> mailbox7. */
Chad Dupuis9e5054e2013-10-30 03:38:23 -0400308 if (IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw))
309 wptr = (uint16_t __iomem *)&reg24->mailbox1;
310 else if (IS_QLA8044(vha->hw))
311 wptr = (uint16_t __iomem *)&reg82->mailbox_out[1];
312 else
313 return;
314
Andrew Vasquez8a659572009-02-08 20:50:12 -0800315 for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
316 mb[cnt] = RD_REG_WORD(wptr);
317
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700318 ql_dbg(ql_dbg_async, vha, 0x5021,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800319 "Inter-Driver Communication %s -- "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700320 "%04x %04x %04x %04x %04x %04x %04x.\n",
321 event[aen & 0xff], mb[0], mb[1], mb[2], mb[3],
322 mb[4], mb[5], mb[6]);
Santosh Vernekar454073c2013-08-27 01:37:48 -0400323 switch (aen) {
324 /* Handle IDC Error completion case. */
325 case MBA_IDC_COMPLETE:
326 if (mb[1] >> 15) {
327 vha->hw->flags.idc_compl_status = 1;
Chad Dupuis9aaf2ce2013-10-30 03:38:25 -0400328 if (vha->hw->notify_dcbx_comp && !vha->vp_idx)
Santosh Vernekar454073c2013-08-27 01:37:48 -0400329 complete(&vha->hw->dcbx_comp);
330 }
331 break;
332
333 case MBA_IDC_NOTIFY:
334 /* Acknowledgement needed? [Notify && non-zero timeout]. */
335 timeout = (descr >> 8) & 0xf;
336 ql_dbg(ql_dbg_async, vha, 0x5022,
337 "%lu Inter-Driver Communication %s -- ACK timeout=%d.\n",
338 vha->host_no, event[aen & 0xff], timeout);
339
340 if (!timeout)
341 return;
342 rval = qla2x00_post_idc_ack_work(vha, mb);
343 if (rval != QLA_SUCCESS)
344 ql_log(ql_log_warn, vha, 0x5023,
345 "IDC failed to post ACK.\n");
346 break;
347 case MBA_IDC_TIME_EXT:
348 vha->hw->idc_extend_tmo = descr;
349 ql_dbg(ql_dbg_async, vha, 0x5087,
350 "%lu Inter-Driver Communication %s -- "
351 "Extend timeout by=%d.\n",
352 vha->host_no, event[aen & 0xff], vha->hw->idc_extend_tmo);
353 break;
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400354 }
Andrew Vasquez8a659572009-02-08 20:50:12 -0800355}
356
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400357#define LS_UNKNOWN 2
Joe Carnucciod0297c92012-11-21 02:40:40 -0500358const char *
359qla2x00_get_link_speed_str(struct qla_hw_data *ha, uint16_t speed)
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400360{
Chad Dupuisf73cb692014-02-26 04:15:06 -0500361 static const char *const link_speeds[] = {
362 "1", "2", "?", "4", "8", "16", "32", "10"
Joe Carnucciod0297c92012-11-21 02:40:40 -0500363 };
Chad Dupuisf73cb692014-02-26 04:15:06 -0500364#define QLA_LAST_SPEED 7
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400365
366 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Joe Carnucciod0297c92012-11-21 02:40:40 -0500367 return link_speeds[0];
368 else if (speed == 0x13)
Chad Dupuisf73cb692014-02-26 04:15:06 -0500369 return link_speeds[QLA_LAST_SPEED];
370 else if (speed < QLA_LAST_SPEED)
Joe Carnucciod0297c92012-11-21 02:40:40 -0500371 return link_speeds[speed];
372 else
373 return link_speeds[LS_UNKNOWN];
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400374}
375
Saurav Kashyapfa492632012-11-21 02:40:29 -0500376static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400377qla83xx_handle_8200_aen(scsi_qla_host_t *vha, uint16_t *mb)
378{
379 struct qla_hw_data *ha = vha->hw;
380
381 /*
382 * 8200 AEN Interpretation:
383 * mb[0] = AEN code
384 * mb[1] = AEN Reason code
385 * mb[2] = LSW of Peg-Halt Status-1 Register
386 * mb[6] = MSW of Peg-Halt Status-1 Register
387 * mb[3] = LSW of Peg-Halt Status-2 register
388 * mb[7] = MSW of Peg-Halt Status-2 register
389 * mb[4] = IDC Device-State Register value
390 * mb[5] = IDC Driver-Presence Register value
391 */
392 ql_dbg(ql_dbg_async, vha, 0x506b, "AEN Code: mb[0] = 0x%x AEN reason: "
393 "mb[1] = 0x%x PH-status1: mb[2] = 0x%x PH-status1: mb[6] = 0x%x.\n",
394 mb[0], mb[1], mb[2], mb[6]);
395 ql_dbg(ql_dbg_async, vha, 0x506c, "PH-status2: mb[3] = 0x%x "
396 "PH-status2: mb[7] = 0x%x Device-State: mb[4] = 0x%x "
397 "Drv-Presence: mb[5] = 0x%x.\n", mb[3], mb[7], mb[4], mb[5]);
398
399 if (mb[1] & (IDC_PEG_HALT_STATUS_CHANGE | IDC_NIC_FW_REPORTED_FAILURE |
400 IDC_HEARTBEAT_FAILURE)) {
401 ha->flags.nic_core_hung = 1;
402 ql_log(ql_log_warn, vha, 0x5060,
403 "83XX: F/W Error Reported: Check if reset required.\n");
404
405 if (mb[1] & IDC_PEG_HALT_STATUS_CHANGE) {
406 uint32_t protocol_engine_id, fw_err_code, err_level;
407
408 /*
409 * IDC_PEG_HALT_STATUS_CHANGE interpretation:
410 * - PEG-Halt Status-1 Register:
411 * (LSW = mb[2], MSW = mb[6])
412 * Bits 0-7 = protocol-engine ID
413 * Bits 8-28 = f/w error code
414 * Bits 29-31 = Error-level
415 * Error-level 0x1 = Non-Fatal error
416 * Error-level 0x2 = Recoverable Fatal error
417 * Error-level 0x4 = UnRecoverable Fatal error
418 * - PEG-Halt Status-2 Register:
419 * (LSW = mb[3], MSW = mb[7])
420 */
421 protocol_engine_id = (mb[2] & 0xff);
422 fw_err_code = (((mb[2] & 0xff00) >> 8) |
423 ((mb[6] & 0x1fff) << 8));
424 err_level = ((mb[6] & 0xe000) >> 13);
425 ql_log(ql_log_warn, vha, 0x5061, "PegHalt Status-1 "
426 "Register: protocol_engine_id=0x%x "
427 "fw_err_code=0x%x err_level=0x%x.\n",
428 protocol_engine_id, fw_err_code, err_level);
429 ql_log(ql_log_warn, vha, 0x5062, "PegHalt Status-2 "
430 "Register: 0x%x%x.\n", mb[7], mb[3]);
431 if (err_level == ERR_LEVEL_NON_FATAL) {
432 ql_log(ql_log_warn, vha, 0x5063,
433 "Not a fatal error, f/w has recovered "
434 "iteself.\n");
435 } else if (err_level == ERR_LEVEL_RECOVERABLE_FATAL) {
436 ql_log(ql_log_fatal, vha, 0x5064,
437 "Recoverable Fatal error: Chip reset "
438 "required.\n");
439 qla83xx_schedule_work(vha,
440 QLA83XX_NIC_CORE_RESET);
441 } else if (err_level == ERR_LEVEL_UNRECOVERABLE_FATAL) {
442 ql_log(ql_log_fatal, vha, 0x5065,
443 "Unrecoverable Fatal error: Set FAILED "
444 "state, reboot required.\n");
445 qla83xx_schedule_work(vha,
446 QLA83XX_NIC_CORE_UNRECOVERABLE);
447 }
448 }
449
450 if (mb[1] & IDC_NIC_FW_REPORTED_FAILURE) {
451 uint16_t peg_fw_state, nw_interface_link_up;
452 uint16_t nw_interface_signal_detect, sfp_status;
453 uint16_t htbt_counter, htbt_monitor_enable;
454 uint16_t sfp_additonal_info, sfp_multirate;
455 uint16_t sfp_tx_fault, link_speed, dcbx_status;
456
457 /*
458 * IDC_NIC_FW_REPORTED_FAILURE interpretation:
459 * - PEG-to-FC Status Register:
460 * (LSW = mb[2], MSW = mb[6])
461 * Bits 0-7 = Peg-Firmware state
462 * Bit 8 = N/W Interface Link-up
463 * Bit 9 = N/W Interface signal detected
464 * Bits 10-11 = SFP Status
465 * SFP Status 0x0 = SFP+ transceiver not expected
466 * SFP Status 0x1 = SFP+ transceiver not present
467 * SFP Status 0x2 = SFP+ transceiver invalid
468 * SFP Status 0x3 = SFP+ transceiver present and
469 * valid
470 * Bits 12-14 = Heartbeat Counter
471 * Bit 15 = Heartbeat Monitor Enable
472 * Bits 16-17 = SFP Additional Info
473 * SFP info 0x0 = Unregocnized transceiver for
474 * Ethernet
475 * SFP info 0x1 = SFP+ brand validation failed
476 * SFP info 0x2 = SFP+ speed validation failed
477 * SFP info 0x3 = SFP+ access error
478 * Bit 18 = SFP Multirate
479 * Bit 19 = SFP Tx Fault
480 * Bits 20-22 = Link Speed
481 * Bits 23-27 = Reserved
482 * Bits 28-30 = DCBX Status
483 * DCBX Status 0x0 = DCBX Disabled
484 * DCBX Status 0x1 = DCBX Enabled
485 * DCBX Status 0x2 = DCBX Exchange error
486 * Bit 31 = Reserved
487 */
488 peg_fw_state = (mb[2] & 0x00ff);
489 nw_interface_link_up = ((mb[2] & 0x0100) >> 8);
490 nw_interface_signal_detect = ((mb[2] & 0x0200) >> 9);
491 sfp_status = ((mb[2] & 0x0c00) >> 10);
492 htbt_counter = ((mb[2] & 0x7000) >> 12);
493 htbt_monitor_enable = ((mb[2] & 0x8000) >> 15);
494 sfp_additonal_info = (mb[6] & 0x0003);
495 sfp_multirate = ((mb[6] & 0x0004) >> 2);
496 sfp_tx_fault = ((mb[6] & 0x0008) >> 3);
497 link_speed = ((mb[6] & 0x0070) >> 4);
498 dcbx_status = ((mb[6] & 0x7000) >> 12);
499
500 ql_log(ql_log_warn, vha, 0x5066,
501 "Peg-to-Fc Status Register:\n"
502 "peg_fw_state=0x%x, nw_interface_link_up=0x%x, "
503 "nw_interface_signal_detect=0x%x"
504 "\nsfp_statis=0x%x.\n ", peg_fw_state,
505 nw_interface_link_up, nw_interface_signal_detect,
506 sfp_status);
507 ql_log(ql_log_warn, vha, 0x5067,
508 "htbt_counter=0x%x, htbt_monitor_enable=0x%x, "
509 "sfp_additonal_info=0x%x, sfp_multirate=0x%x.\n ",
510 htbt_counter, htbt_monitor_enable,
511 sfp_additonal_info, sfp_multirate);
512 ql_log(ql_log_warn, vha, 0x5068,
513 "sfp_tx_fault=0x%x, link_state=0x%x, "
514 "dcbx_status=0x%x.\n", sfp_tx_fault, link_speed,
515 dcbx_status);
516
517 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
518 }
519
520 if (mb[1] & IDC_HEARTBEAT_FAILURE) {
521 ql_log(ql_log_warn, vha, 0x5069,
522 "Heartbeat Failure encountered, chip reset "
523 "required.\n");
524
525 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
526 }
527 }
528
529 if (mb[1] & IDC_DEVICE_STATE_CHANGE) {
530 ql_log(ql_log_info, vha, 0x506a,
531 "IDC Device-State changed = 0x%x.\n", mb[4]);
Saurav Kashyap6c3943c2013-02-08 01:58:02 -0500532 if (ha->flags.nic_core_reset_owner)
533 return;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400534 qla83xx_schedule_work(vha, MBA_IDC_AEN);
535 }
536}
537
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -0500538int
539qla2x00_is_a_vp_did(scsi_qla_host_t *vha, uint32_t rscn_entry)
540{
541 struct qla_hw_data *ha = vha->hw;
542 scsi_qla_host_t *vp;
543 uint32_t vp_did;
544 unsigned long flags;
545 int ret = 0;
546
547 if (!ha->num_vhosts)
548 return ret;
549
550 spin_lock_irqsave(&ha->vport_slock, flags);
551 list_for_each_entry(vp, &ha->vp_list, list) {
552 vp_did = vp->d_id.b24;
553 if (vp_did == rscn_entry) {
554 ret = 1;
555 break;
556 }
557 }
558 spin_unlock_irqrestore(&ha->vport_slock, flags);
559
560 return ret;
561}
562
Joe Carnuccio17cac3a2015-08-04 13:37:52 -0400563static inline fc_port_t *
564qla2x00_find_fcport_by_loopid(scsi_qla_host_t *vha, uint16_t loop_id)
565{
566 fc_port_t *fcport;
567
568 list_for_each_entry(fcport, &vha->vp_fcports, list)
569 if (fcport->loop_id == loop_id)
570 return fcport;
571 return NULL;
572}
573
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574/**
575 * qla2x00_async_event() - Process aynchronous events.
576 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700577 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700579void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800580qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 uint16_t handle_cnt;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700583 uint16_t cnt, mbx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 uint32_t handles[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800585 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700586 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700587 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
Andrew Vasquezbc5c2aa2010-12-21 16:00:24 -0800588 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Bart Van Assche52c82822015-07-09 07:23:26 -0700589 uint32_t rscn_entry, host_pid;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700590 unsigned long flags;
Chad Dupuisef86cb22014-09-25 05:17:01 -0400591 fc_port_t *fcport = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
593 /* Setup to process RIO completion. */
594 handle_cnt = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800595 if (IS_CNA_CAPABLE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800596 goto skip_rio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 switch (mb[0]) {
598 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700599 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 handle_cnt = 1;
601 break;
602 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700603 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 handle_cnt = 1;
605 mb[0] = MBA_SCSI_COMPLETION;
606 break;
607 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700608 handles[0] = mb[1];
609 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 handle_cnt = 2;
611 mb[0] = MBA_SCSI_COMPLETION;
612 break;
613 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700614 handles[0] = mb[1];
615 handles[1] = mb[2];
616 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 handle_cnt = 3;
618 mb[0] = MBA_SCSI_COMPLETION;
619 break;
620 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700621 handles[0] = mb[1];
622 handles[1] = mb[2];
623 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
625 handle_cnt = 4;
626 mb[0] = MBA_SCSI_COMPLETION;
627 break;
628 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700629 handles[0] = mb[1];
630 handles[1] = mb[2];
631 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
633 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
634 handle_cnt = 5;
635 mb[0] = MBA_SCSI_COMPLETION;
636 break;
637 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700638 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 handles[1] = le32_to_cpu(
640 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
641 RD_MAILBOX_REG(ha, reg, 6));
642 handle_cnt = 2;
643 mb[0] = MBA_SCSI_COMPLETION;
644 break;
645 default:
646 break;
647 }
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800648skip_rio:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 switch (mb[0]) {
650 case MBA_SCSI_COMPLETION: /* Fast Post */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800651 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 break;
653
654 for (cnt = 0; cnt < handle_cnt; cnt++)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800655 qla2x00_process_completed_request(vha, rsp->req,
656 handles[cnt]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 break;
658
659 case MBA_RESET: /* Reset */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700660 ql_dbg(ql_dbg_async, vha, 0x5002,
661 "Asynchronous RESET.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800663 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 break;
665
666 case MBA_SYSTEM_ERR: /* System Error */
Chad Dupuisf73cb692014-02-26 04:15:06 -0500667 mbx = (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) ?
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800668 RD_REG_WORD(&reg24->mailbox7) : 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700669 ql_log(ql_log_warn, vha, 0x5003,
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700670 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh "
671 "mbx7=%xh.\n", mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800673 ha->isp_ops->fw_dump(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Andrew Vasqueze4289242007-07-19 15:05:56 -0700675 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700676 if (mb[1] == 0 && mb[2] == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700677 ql_log(ql_log_fatal, vha, 0x5004,
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700678 "Unrecoverable Hardware Error: adapter "
679 "marked OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800680 vha->flags.online = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800681 vha->device_flags |= DFLG_DEV_FAILED;
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700682 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300683 /* Check to see if MPI timeout occurred */
Chad Dupuisf73cb692014-02-26 04:15:06 -0500684 if ((mbx & MBX_3) && (ha->port_no == 0))
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700685 set_bit(MPI_RESET_NEEDED,
686 &vha->dpc_flags);
687
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800688 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700689 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700690 } else if (mb[1] == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700691 ql_log(ql_log_fatal, vha, 0x5005,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 "Unrecoverable Hardware Error: adapter marked "
693 "OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800694 vha->flags.online = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800695 vha->device_flags |= DFLG_DEV_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800697 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 break;
699
700 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700701 ql_log(ql_log_warn, vha, 0x5006,
702 "ISP Request Transfer Error (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800704 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 break;
706
707 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700708 ql_log(ql_log_warn, vha, 0x5007,
709 "ISP Response Transfer Error.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800711 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 break;
713
714 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700715 ql_dbg(ql_dbg_async, vha, 0x5008,
716 "Asynchronous WAKEUP_THRES.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400718 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Chad Dupuiscfb09192011-11-18 09:03:07 -0800720 ql_dbg(ql_dbg_async, vha, 0x5009,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700721 "LIP occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800723 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
724 atomic_set(&vha->loop_state, LOOP_DOWN);
725 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
726 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 }
728
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800729 if (vha->vp_idx) {
730 atomic_set(&vha->vp_state, VP_FAILED);
731 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700732 }
733
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800734 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
735 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800737 vha->flags.management_server_logged_in = 0;
738 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 break;
740
741 case MBA_LOOP_UP: /* Loop Up Event */
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400742 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700743 ha->link_data_rate = PORT_SPEED_1GB;
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400744 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 ha->link_data_rate = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
Chad Dupuis8e5a9482014-08-08 07:38:09 -0400747 ql_log(ql_log_info, vha, 0x500a,
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400748 "LOOP UP detected (%s Gbps).\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -0500749 qla2x00_get_link_speed_str(ha, ha->link_data_rate));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800751 vha->flags.management_server_logged_in = 0;
752 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 break;
754
755 case MBA_LOOP_DOWN: /* Loop Down Event */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800756 mbx = (IS_QLA81XX(ha) || IS_QLA8031(ha))
757 ? RD_REG_WORD(&reg24->mailbox4) : 0;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400758 mbx = (IS_P3P_TYPE(ha)) ? RD_REG_WORD(&reg82->mailbox_out[4])
759 : mbx;
Chad Dupuis8e5a9482014-08-08 07:38:09 -0400760 ql_log(ql_log_info, vha, 0x500b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700761 "LOOP DOWN detected (%x %x %x %x).\n",
762 mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800764 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
765 atomic_set(&vha->loop_state, LOOP_DOWN);
766 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
Himanshu Madhani2486c622014-09-25 05:17:00 -0400767 /*
768 * In case of loop down, restore WWPN from
769 * NVRAM in case of FA-WWPN capable ISP
Sawan Chandak718abbd2015-04-09 15:00:07 -0400770 * Restore for Physical Port only
Himanshu Madhani2486c622014-09-25 05:17:00 -0400771 */
Sawan Chandak718abbd2015-04-09 15:00:07 -0400772 if (!vha->vp_idx) {
773 if (ha->flags.fawwpn_enabled) {
774 void *wwpn = ha->init_cb->port_name;
775 memcpy(vha->port_name, wwpn, WWN_SIZE);
776 fc_host_port_name(vha->host) =
777 wwn_to_u64(vha->port_name);
778 ql_dbg(ql_dbg_init + ql_dbg_verbose,
779 vha, 0x0144, "LOOP DOWN detected,"
780 "restore WWPN %016llx\n",
781 wwn_to_u64(vha->port_name));
782 }
Himanshu Madhani2486c622014-09-25 05:17:00 -0400783
Sawan Chandak718abbd2015-04-09 15:00:07 -0400784 clear_bit(VP_CONFIG_OK, &vha->vp_flags);
Himanshu Madhani2486c622014-09-25 05:17:00 -0400785 }
786
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800787 vha->device_flags |= DFLG_NO_CABLE;
788 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 }
790
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800791 if (vha->vp_idx) {
792 atomic_set(&vha->vp_state, VP_FAILED);
793 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700794 }
795
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800796 vha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700797 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800798 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 break;
800
801 case MBA_LIP_RESET: /* LIP reset occurred */
Chad Dupuiscfb09192011-11-18 09:03:07 -0800802 ql_dbg(ql_dbg_async, vha, 0x500c,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700803 "LIP reset occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800805 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
806 atomic_set(&vha->loop_state, LOOP_DOWN);
807 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
808 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 }
810
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800811 if (vha->vp_idx) {
812 atomic_set(&vha->vp_state, VP_FAILED);
813 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700814 }
815
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800816 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
818 ha->operating_mode = LOOP;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800819 vha->flags.management_server_logged_in = 0;
820 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 break;
822
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800823 /* case MBA_DCBX_COMPLETE: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 case MBA_POINT_TO_POINT: /* Point-to-Point */
825 if (IS_QLA2100(ha))
826 break;
827
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400828 if (IS_CNA_CAPABLE(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700829 ql_dbg(ql_dbg_async, vha, 0x500d,
830 "DCBX Completed -- %04x %04x %04x.\n",
831 mb[1], mb[2], mb[3]);
Chad Dupuis9aaf2ce2013-10-30 03:38:25 -0400832 if (ha->notify_dcbx_comp && !vha->vp_idx)
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700833 complete(&ha->dcbx_comp);
834
835 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700836 ql_dbg(ql_dbg_async, vha, 0x500e,
837 "Asynchronous P2P MODE received.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
839 /*
840 * Until there's a transition from loop down to loop up, treat
841 * this as loop down only.
842 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800843 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
844 atomic_set(&vha->loop_state, LOOP_DOWN);
845 if (!atomic_read(&vha->loop_down_timer))
846 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800848 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 }
850
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800851 if (vha->vp_idx) {
852 atomic_set(&vha->vp_state, VP_FAILED);
853 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700854 }
855
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800856 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
857 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
858
859 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
860 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800861
862 ha->flags.gpsc_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800863 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 break;
865
866 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
867 if (IS_QLA2100(ha))
868 break;
869
Chad Dupuiscfb09192011-11-18 09:03:07 -0800870 ql_dbg(ql_dbg_async, vha, 0x500f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 "Configuration change detected: value=%x.\n", mb[1]);
872
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800873 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
874 atomic_set(&vha->loop_state, LOOP_DOWN);
875 if (!atomic_read(&vha->loop_down_timer))
876 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800878 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 }
880
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800881 if (vha->vp_idx) {
882 atomic_set(&vha->vp_state, VP_FAILED);
883 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700884 }
885
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800886 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
887 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 break;
889
890 case MBA_PORT_UPDATE: /* Port database update */
Santosh Vernekar55903b92009-07-31 15:09:25 -0700891 /*
892 * Handle only global and vn-port update events
893 *
894 * Relevant inputs:
895 * mb[1] = N_Port handle of changed port
896 * OR 0xffff for global event
897 * mb[2] = New login state
898 * 7 = Port logged out
899 * mb[3] = LSB is vp_idx, 0xff = all vps
900 *
901 * Skip processing if:
902 * Event is global, vp_idx is NOT all vps,
903 * vp_idx does not match
904 * Event is not global, vp_idx does not match
905 */
Andrew Vasquez12cec63e42010-03-19 16:59:17 -0700906 if (IS_QLA2XXX_MIDTYPE(ha) &&
907 ((mb[1] == 0xffff && (mb[3] & 0xff) != 0xff) ||
908 (mb[1] != 0xffff)) && vha->vp_idx != (mb[3] & 0xff))
909 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800910
Joe Carnuccio17cac3a2015-08-04 13:37:52 -0400911 if (mb[2] == 0x7) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700912 ql_dbg(ql_dbg_async, vha, 0x5010,
Joe Carnuccio17cac3a2015-08-04 13:37:52 -0400913 "Port %s %04x %04x %04x.\n",
914 mb[1] == 0xffff ? "unavailable" : "logout",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700915 mb[1], mb[2], mb[3]);
Joe Carnuccio17cac3a2015-08-04 13:37:52 -0400916
917 if (mb[1] == 0xffff)
918 goto global_port_update;
919
920 /* Port logout */
921 fcport = qla2x00_find_fcport_by_loopid(vha, mb[1]);
922 if (!fcport)
923 break;
924 if (atomic_read(&fcport->state) != FCS_ONLINE)
925 break;
926 ql_dbg(ql_dbg_async, vha, 0x508a,
927 "Marking port lost loopid=%04x portid=%06x.\n",
928 fcport->loop_id, fcport->d_id.b24);
929 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
930 break;
931
932global_port_update:
933 /* Port unavailable. */
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400934 ql_log(ql_log_warn, vha, 0x505e,
935 "Link is offline.\n");
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700936
937 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
938 atomic_set(&vha->loop_state, LOOP_DOWN);
939 atomic_set(&vha->loop_down_timer,
940 LOOP_DOWN_TIME);
941 vha->device_flags |= DFLG_NO_CABLE;
942 qla2x00_mark_all_devices_lost(vha, 1);
943 }
944
945 if (vha->vp_idx) {
946 atomic_set(&vha->vp_state, VP_FAILED);
947 fc_vport_set_state(vha->fc_vport,
948 FC_VPORT_FAILED);
Santosh Vernekarfaadc5e2009-07-31 15:09:26 -0700949 qla2x00_mark_all_devices_lost(vha, 1);
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700950 }
951
952 vha->flags.management_server_logged_in = 0;
953 ha->link_data_rate = PORT_SPEED_UNKNOWN;
954 break;
955 }
956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 /*
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700958 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 * event etc. earlier indicating loop is down) then process
960 * it. Otherwise ignore it and Wait for RSCN to come in.
961 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800962 atomic_set(&vha->loop_down_timer, 0);
Chad Dupuis8e5a9482014-08-08 07:38:09 -0400963 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
964 atomic_read(&vha->loop_state) != LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700965 ql_dbg(ql_dbg_async, vha, 0x5011,
966 "Asynchronous PORT UPDATE ignored %04x/%04x/%04x.\n",
967 mb[1], mb[2], mb[3]);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400968
969 qlt_async_event(mb[0], vha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 break;
971 }
972
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700973 ql_dbg(ql_dbg_async, vha, 0x5012,
974 "Port database changed %04x %04x %04x.\n",
975 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977 /*
978 * Mark all devices as missing so we will login again.
979 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800980 atomic_set(&vha->loop_state, LOOP_UP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800982 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400984 if (vha->vp_idx == 0 && !qla_ini_mode_enabled(vha))
985 set_bit(SCR_PENDING, &vha->dpc_flags);
986
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800987 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
988 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Sawan Chandakded64112015-04-09 15:00:06 -0400989 set_bit(VP_CONFIG_OK, &vha->vp_flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400990
991 qlt_async_event(mb[0], vha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 break;
993
994 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju3c397402008-05-19 14:25:39 -0700995 /* Check if the Vport has issued a SCR */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800996 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
Seokmann Ju3c397402008-05-19 14:25:39 -0700997 break;
998 /* Only handle SCNs for our Vport index. */
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700999 if (ha->flags.npiv_supported && vha->vp_idx != (mb[3] & 0xff))
Seokmann Ju3c397402008-05-19 14:25:39 -07001000 break;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001001
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001002 ql_dbg(ql_dbg_async, vha, 0x5013,
1003 "RSCN database changed -- %04x %04x %04x.\n",
1004 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
Ravi Anand59d72d82008-09-11 21:22:53 -07001006 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001007 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
1008 | vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 if (rscn_entry == host_pid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001010 ql_dbg(ql_dbg_async, vha, 0x5014,
1011 "Ignoring RSCN update to local host "
1012 "port ID (%06x).\n", host_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 break;
1014 }
1015
Ravi Anand59d72d82008-09-11 21:22:53 -07001016 /* Ignore reserved bits from RSCN-payload. */
1017 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05001019 /* Skip RSCNs for virtual ports on the same physical port */
1020 if (qla2x00_is_a_vp_did(vha, rscn_entry))
1021 break;
1022
Chad Dupuisef86cb22014-09-25 05:17:01 -04001023 /*
1024 * Search for the rport related to this RSCN entry and mark it
1025 * as lost.
1026 */
1027 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1028 if (atomic_read(&fcport->state) != FCS_ONLINE)
1029 continue;
Chad Dupuisef86cb22014-09-25 05:17:01 -04001030 if (fcport->d_id.b24 == rscn_entry) {
1031 qla2x00_mark_device_lost(vha, fcport, 0, 0);
1032 break;
1033 }
1034 }
1035
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001036 atomic_set(&vha->loop_down_timer, 0);
1037 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001039 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1040 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1041 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 break;
1043
1044 /* case MBA_RIO_RESPONSE: */
1045 case MBA_ZIO_RESPONSE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001046 ql_dbg(ql_dbg_async, vha, 0x5015,
1047 "[R|Z]IO update completion.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
Andrew Vasqueze4289242007-07-19 15:05:56 -07001049 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001050 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001051 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001052 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001054
1055 case MBA_DISCARD_RND_FRAME:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001056 ql_dbg(ql_dbg_async, vha, 0x5016,
1057 "Discard RND Frame -- %04x %04x %04x.\n",
1058 mb[1], mb[2], mb[3]);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001059 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -07001060
1061 case MBA_TRACE_NOTIFICATION:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001062 ql_dbg(ql_dbg_async, vha, 0x5017,
1063 "Trace Notification -- %04x %04x.\n", mb[1], mb[2]);
Andrew Vasquez45ebeb52006-08-01 13:48:14 -07001064 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001065
1066 case MBA_ISP84XX_ALERT:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001067 ql_dbg(ql_dbg_async, vha, 0x5018,
1068 "ISP84XX Alert Notification -- %04x %04x %04x.\n",
1069 mb[1], mb[2], mb[3]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001070
1071 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
1072 switch (mb[1]) {
1073 case A84_PANIC_RECOVERY:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001074 ql_log(ql_log_info, vha, 0x5019,
1075 "Alert 84XX: panic recovery %04x %04x.\n",
1076 mb[2], mb[3]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001077 break;
1078 case A84_OP_LOGIN_COMPLETE:
1079 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001080 ql_log(ql_log_info, vha, 0x501a,
1081 "Alert 84XX: firmware version %x.\n",
1082 ha->cs84xx->op_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001083 break;
1084 case A84_DIAG_LOGIN_COMPLETE:
1085 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001086 ql_log(ql_log_info, vha, 0x501b,
1087 "Alert 84XX: diagnostic firmware version %x.\n",
1088 ha->cs84xx->diag_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001089 break;
1090 case A84_GOLD_LOGIN_COMPLETE:
1091 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
1092 ha->cs84xx->fw_update = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001093 ql_log(ql_log_info, vha, 0x501c,
1094 "Alert 84XX: gold firmware version %x.\n",
1095 ha->cs84xx->gold_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001096 break;
1097 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001098 ql_log(ql_log_warn, vha, 0x501d,
1099 "Alert 84xx: Invalid Alert %04x %04x %04x.\n",
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001100 mb[1], mb[2], mb[3]);
1101 }
1102 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
1103 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001104 case MBA_DCBX_START:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001105 ql_dbg(ql_dbg_async, vha, 0x501e,
1106 "DCBX Started -- %04x %04x %04x.\n",
1107 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001108 break;
1109 case MBA_DCBX_PARAM_UPDATE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001110 ql_dbg(ql_dbg_async, vha, 0x501f,
1111 "DCBX Parameters Updated -- %04x %04x %04x.\n",
1112 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001113 break;
1114 case MBA_FCF_CONF_ERR:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001115 ql_dbg(ql_dbg_async, vha, 0x5020,
1116 "FCF Configuration Error -- %04x %04x %04x.\n",
1117 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001118 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001119 case MBA_IDC_NOTIFY:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001120 if (IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
Chad Dupuis67b2a312013-02-08 01:57:51 -05001121 mb[4] = RD_REG_WORD(&reg24->mailbox4);
1122 if (((mb[2] & 0x7fff) == MBC_PORT_RESET ||
1123 (mb[2] & 0x7fff) == MBC_SET_PORT_CONFIG) &&
1124 (mb[4] & INTERNAL_LOOPBACK_MASK) != 0) {
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04001125 set_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags);
Chad Dupuis67b2a312013-02-08 01:57:51 -05001126 /*
1127 * Extend loop down timer since port is active.
1128 */
1129 if (atomic_read(&vha->loop_state) == LOOP_DOWN)
1130 atomic_set(&vha->loop_down_timer,
1131 LOOP_DOWN_TIME);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04001132 qla2xxx_wake_dpc(vha);
1133 }
Chad Dupuis67b2a312013-02-08 01:57:51 -05001134 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04001135 case MBA_IDC_COMPLETE:
Chad Dupuis9aaf2ce2013-10-30 03:38:25 -04001136 if (ha->notify_lb_portup_comp && !vha->vp_idx)
Chad Dupuisf356bef2013-02-08 01:58:04 -05001137 complete(&ha->lb_portup_comp);
1138 /* Fallthru */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001139 case MBA_IDC_TIME_EXT:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001140 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) ||
1141 IS_QLA8044(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001142 qla81xx_idc_event(vha, mb[0], mb[1]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001143 break;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001144
1145 case MBA_IDC_AEN:
1146 mb[4] = RD_REG_WORD(&reg24->mailbox4);
1147 mb[5] = RD_REG_WORD(&reg24->mailbox5);
1148 mb[6] = RD_REG_WORD(&reg24->mailbox6);
1149 mb[7] = RD_REG_WORD(&reg24->mailbox7);
1150 qla83xx_handle_8200_aen(vha, mb);
1151 break;
1152
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001153 case MBA_DPORT_DIAGNOSTICS:
1154 ql_dbg(ql_dbg_async, vha, 0x5052,
1155 "D-Port Diagnostics: %04x %04x=%s\n", mb[0], mb[1],
1156 mb[1] == 0 ? "start" :
1157 mb[1] == 1 ? "done (ok)" :
1158 mb[1] == 2 ? "done (error)" : "other");
1159 break;
1160
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001161 default:
1162 ql_dbg(ql_dbg_async, vha, 0x5057,
1163 "Unknown AEN:%04x %04x %04x %04x\n",
1164 mb[0], mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001166
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001167 qlt_async_event(mb[0], vha, mb);
1168
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001169 if (!vha->vp_idx && ha->num_vhosts)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001170 qla2x00_alert_all_vps(rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171}
1172
1173/**
1174 * qla2x00_process_completed_request() - Process a Fast Post response.
1175 * @ha: SCSI driver HA context
1176 * @index: SRB index
1177 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001178void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001179qla2x00_process_completed_request(struct scsi_qla_host *vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001180 struct req_que *req, uint32_t index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181{
1182 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001183 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
1185 /* Validate handle. */
Chad Dupuis8d93f552013-01-30 03:34:37 -05001186 if (index >= req->num_outstanding_cmds) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001187 ql_log(ql_log_warn, vha, 0x3014,
1188 "Invalid SCSI command index (%x).\n", index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001190 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001191 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1192 else
1193 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 return;
1195 }
1196
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001197 sp = req->outstanding_cmds[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 if (sp) {
1199 /* Free outstanding command slot. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001200 req->outstanding_cmds[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 /* Save ISP completion status */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001203 sp->done(ha, sp, DID_OK << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001205 ql_log(ql_log_warn, vha, 0x3016, "Invalid SCSI SRB.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001207 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001208 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1209 else
1210 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 }
1212}
1213
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001214srb_t *
Andrew Vasquezac280b62009-08-20 11:06:05 -07001215qla2x00_get_sp_from_handle(scsi_qla_host_t *vha, const char *func,
1216 struct req_que *req, void *iocb)
1217{
1218 struct qla_hw_data *ha = vha->hw;
1219 sts_entry_t *pkt = iocb;
1220 srb_t *sp = NULL;
1221 uint16_t index;
1222
1223 index = LSW(pkt->handle);
Chad Dupuis8d93f552013-01-30 03:34:37 -05001224 if (index >= req->num_outstanding_cmds) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001225 ql_log(ql_log_warn, vha, 0x5031,
1226 "Invalid command index (%x).\n", index);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001227 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001228 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1229 else
1230 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001231 goto done;
1232 }
1233 sp = req->outstanding_cmds[index];
1234 if (!sp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001235 ql_log(ql_log_warn, vha, 0x5032,
1236 "Invalid completion handle (%x) -- timed-out.\n", index);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001237 return sp;
1238 }
1239 if (sp->handle != index) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001240 ql_log(ql_log_warn, vha, 0x5033,
1241 "SRB handle (%x) mismatch %x.\n", sp->handle, index);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001242 return NULL;
1243 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001244
Andrew Vasquezac280b62009-08-20 11:06:05 -07001245 req->outstanding_cmds[index] = NULL;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001246
Andrew Vasquezac280b62009-08-20 11:06:05 -07001247done:
1248 return sp;
1249}
1250
1251static void
1252qla2x00_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1253 struct mbx_entry *mbx)
1254{
1255 const char func[] = "MBX-IOCB";
1256 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001257 fc_port_t *fcport;
1258 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001259 struct srb_iocb *lio;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001260 uint16_t *data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001261 uint16_t status;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001262
1263 sp = qla2x00_get_sp_from_handle(vha, func, req, mbx);
1264 if (!sp)
1265 return;
1266
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001267 lio = &sp->u.iocb_cmd;
1268 type = sp->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001269 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001270 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001271
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001272 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001273 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001274 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001275 if (mbx->entry_status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001276 ql_dbg(ql_dbg_async, vha, 0x5043,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001277 "Async-%s error entry - hdl=%x portid=%02x%02x%02x "
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001278 "entry-status=%x status=%x state-flag=%x "
Chad Dupuiscfb09192011-11-18 09:03:07 -08001279 "status-flags=%x.\n", type, sp->handle,
1280 fcport->d_id.b.domain, fcport->d_id.b.area,
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001281 fcport->d_id.b.al_pa, mbx->entry_status,
1282 le16_to_cpu(mbx->status), le16_to_cpu(mbx->state_flags),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001283 le16_to_cpu(mbx->status_flags));
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001284
Chad Dupuiscfb09192011-11-18 09:03:07 -08001285 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5029,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001286 (uint8_t *)mbx, sizeof(*mbx));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001287
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001288 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001289 }
1290
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001291 status = le16_to_cpu(mbx->status);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001292 if (status == 0x30 && sp->type == SRB_LOGIN_CMD &&
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001293 le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE)
1294 status = 0;
1295 if (!status && le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001296 ql_dbg(ql_dbg_async, vha, 0x5045,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001297 "Async-%s complete - hdl=%x portid=%02x%02x%02x mbx1=%x.\n",
1298 type, sp->handle, fcport->d_id.b.domain,
1299 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1300 le16_to_cpu(mbx->mb1));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001301
1302 data[0] = MBS_COMMAND_COMPLETE;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001303 if (sp->type == SRB_LOGIN_CMD) {
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001304 fcport->port_type = FCT_TARGET;
1305 if (le16_to_cpu(mbx->mb1) & BIT_0)
1306 fcport->port_type = FCT_INITIATOR;
Andrew Vasquez6ac52602010-05-28 15:08:19 -07001307 else if (le16_to_cpu(mbx->mb1) & BIT_1)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001308 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001309 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001310 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001311 }
1312
1313 data[0] = le16_to_cpu(mbx->mb0);
1314 switch (data[0]) {
1315 case MBS_PORT_ID_USED:
1316 data[1] = le16_to_cpu(mbx->mb1);
1317 break;
1318 case MBS_LOOP_ID_USED:
1319 break;
1320 default:
1321 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001322 break;
1323 }
1324
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001325 ql_log(ql_log_warn, vha, 0x5046,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001326 "Async-%s failed - hdl=%x portid=%02x%02x%02x status=%x "
1327 "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n", type, sp->handle,
1328 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
1329 status, le16_to_cpu(mbx->mb0), le16_to_cpu(mbx->mb1),
Andrew Vasquezac280b62009-08-20 11:06:05 -07001330 le16_to_cpu(mbx->mb2), le16_to_cpu(mbx->mb6),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001331 le16_to_cpu(mbx->mb7));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001332
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001333logio_done:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001334 sp->done(vha, sp, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001335}
1336
1337static void
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001338qla2x00_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1339 sts_entry_t *pkt, int iocb_type)
1340{
1341 const char func[] = "CT_IOCB";
1342 const char *type;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001343 srb_t *sp;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001344 struct fc_bsg_job *bsg_job;
1345 uint16_t comp_status;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001346 int res;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001347
1348 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1349 if (!sp)
1350 return;
1351
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001352 bsg_job = sp->u.bsg_job;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001353
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001354 type = "ct pass-through";
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001355
1356 comp_status = le16_to_cpu(pkt->comp_status);
1357
1358 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1359 * fc payload to the caller
1360 */
1361 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1362 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1363
1364 if (comp_status != CS_COMPLETE) {
1365 if (comp_status == CS_DATA_UNDERRUN) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001366 res = DID_OK << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001367 bsg_job->reply->reply_payload_rcv_len =
1368 le16_to_cpu(((sts_entry_t *)pkt)->rsp_info_len);
1369
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001370 ql_log(ql_log_warn, vha, 0x5048,
1371 "CT pass-through-%s error "
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001372 "comp_status-status=0x%x total_byte = 0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001373 type, comp_status,
1374 bsg_job->reply->reply_payload_rcv_len);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001375 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001376 ql_log(ql_log_warn, vha, 0x5049,
1377 "CT pass-through-%s error "
1378 "comp_status-status=0x%x.\n", type, comp_status);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001379 res = DID_ERROR << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001380 bsg_job->reply->reply_payload_rcv_len = 0;
1381 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001382 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5035,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001383 (uint8_t *)pkt, sizeof(*pkt));
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001384 } else {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001385 res = DID_OK << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001386 bsg_job->reply->reply_payload_rcv_len =
1387 bsg_job->reply_payload.payload_len;
1388 bsg_job->reply_len = 0;
1389 }
1390
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001391 sp->done(vha, sp, res);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001392}
1393
1394static void
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001395qla24xx_els_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1396 struct sts_entry_24xx *pkt, int iocb_type)
1397{
1398 const char func[] = "ELS_CT_IOCB";
1399 const char *type;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001400 srb_t *sp;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001401 struct fc_bsg_job *bsg_job;
1402 uint16_t comp_status;
1403 uint32_t fw_status[3];
1404 uint8_t* fw_sts_ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001405 int res;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001406
1407 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1408 if (!sp)
1409 return;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001410 bsg_job = sp->u.bsg_job;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001411
1412 type = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001413 switch (sp->type) {
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001414 case SRB_ELS_CMD_RPT:
1415 case SRB_ELS_CMD_HST:
1416 type = "els";
1417 break;
1418 case SRB_CT_CMD:
1419 type = "ct pass-through";
1420 break;
1421 default:
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001422 ql_dbg(ql_dbg_user, vha, 0x503e,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001423 "Unrecognized SRB: (%p) type=%d.\n", sp, sp->type);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001424 return;
1425 }
1426
1427 comp_status = fw_status[0] = le16_to_cpu(pkt->comp_status);
1428 fw_status[1] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1);
1429 fw_status[2] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2);
1430
1431 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1432 * fc payload to the caller
1433 */
1434 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1435 bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(fw_status);
1436
1437 if (comp_status != CS_COMPLETE) {
1438 if (comp_status == CS_DATA_UNDERRUN) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001439 res = DID_OK << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001440 bsg_job->reply->reply_payload_rcv_len =
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001441 le16_to_cpu(((struct els_sts_entry_24xx *)pkt)->total_byte_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001442
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001443 ql_dbg(ql_dbg_user, vha, 0x503f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001444 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001445 "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001446 type, sp->handle, comp_status, fw_status[1], fw_status[2],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001447 le16_to_cpu(((struct els_sts_entry_24xx *)
1448 pkt)->total_byte_count));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001449 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1450 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1451 }
1452 else {
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001453 ql_dbg(ql_dbg_user, vha, 0x5040,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001454 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001455 "error subcode 1=0x%x error subcode 2=0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001456 type, sp->handle, comp_status,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001457 le16_to_cpu(((struct els_sts_entry_24xx *)
1458 pkt)->error_subcode_1),
1459 le16_to_cpu(((struct els_sts_entry_24xx *)
1460 pkt)->error_subcode_2));
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001461 res = DID_ERROR << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001462 bsg_job->reply->reply_payload_rcv_len = 0;
1463 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1464 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1465 }
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001466 ql_dump_buffer(ql_dbg_user + ql_dbg_buffer, vha, 0x5056,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001467 (uint8_t *)pkt, sizeof(*pkt));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001468 }
1469 else {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001470 res = DID_OK << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001471 bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
1472 bsg_job->reply_len = 0;
1473 }
1474
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001475 sp->done(vha, sp, res);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001476}
1477
1478static void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001479qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req,
1480 struct logio_entry_24xx *logio)
1481{
1482 const char func[] = "LOGIO-IOCB";
1483 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001484 fc_port_t *fcport;
1485 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001486 struct srb_iocb *lio;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001487 uint16_t *data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001488 uint32_t iop[2];
1489
1490 sp = qla2x00_get_sp_from_handle(vha, func, req, logio);
1491 if (!sp)
1492 return;
1493
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001494 lio = &sp->u.iocb_cmd;
1495 type = sp->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001496 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001497 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001498
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001499 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001500 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001501 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001502 if (logio->entry_status) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001503 ql_log(ql_log_warn, fcport->vha, 0x5034,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001504 "Async-%s error entry - hdl=%x"
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001505 "portid=%02x%02x%02x entry-status=%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001506 type, sp->handle, fcport->d_id.b.domain,
1507 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1508 logio->entry_status);
1509 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x504d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001510 (uint8_t *)logio, sizeof(*logio));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001511
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001512 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001513 }
1514
1515 if (le16_to_cpu(logio->comp_status) == CS_COMPLETE) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001516 ql_dbg(ql_dbg_async, fcport->vha, 0x5036,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001517 "Async-%s complete - hdl=%x portid=%02x%02x%02x "
1518 "iop0=%x.\n", type, sp->handle, fcport->d_id.b.domain,
1519 fcport->d_id.b.area, fcport->d_id.b.al_pa,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001520 le32_to_cpu(logio->io_parameter[0]));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001521
1522 data[0] = MBS_COMMAND_COMPLETE;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001523 if (sp->type != SRB_LOGIN_CMD)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001524 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001525
1526 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1527 if (iop[0] & BIT_4) {
1528 fcport->port_type = FCT_TARGET;
1529 if (iop[0] & BIT_8)
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07001530 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquezb0cd5792010-05-28 15:08:22 -07001531 } else if (iop[0] & BIT_5)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001532 fcport->port_type = FCT_INITIATOR;
Andrew Vasquezb0cd5792010-05-28 15:08:22 -07001533
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001534 if (iop[0] & BIT_7)
1535 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
1536
Andrew Vasquezac280b62009-08-20 11:06:05 -07001537 if (logio->io_parameter[7] || logio->io_parameter[8])
1538 fcport->supported_classes |= FC_COS_CLASS2;
1539 if (logio->io_parameter[9] || logio->io_parameter[10])
1540 fcport->supported_classes |= FC_COS_CLASS3;
1541
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001542 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001543 }
1544
1545 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1546 iop[1] = le32_to_cpu(logio->io_parameter[1]);
1547 switch (iop[0]) {
1548 case LSC_SCODE_PORTID_USED:
1549 data[0] = MBS_PORT_ID_USED;
1550 data[1] = LSW(iop[1]);
1551 break;
1552 case LSC_SCODE_NPORT_USED:
1553 data[0] = MBS_LOOP_ID_USED;
1554 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001555 default:
1556 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001557 break;
1558 }
1559
Arun Easi5e19ed92012-02-09 11:15:51 -08001560 ql_dbg(ql_dbg_async, fcport->vha, 0x5037,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001561 "Async-%s failed - hdl=%x portid=%02x%02x%02x comp=%x "
1562 "iop0=%x iop1=%x.\n", type, sp->handle, fcport->d_id.b.domain,
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001563 fcport->d_id.b.area, fcport->d_id.b.al_pa,
Andrew Vasquezac280b62009-08-20 11:06:05 -07001564 le16_to_cpu(logio->comp_status),
1565 le32_to_cpu(logio->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001566 le32_to_cpu(logio->io_parameter[1]));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001567
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001568logio_done:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001569 sp->done(vha, sp, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001570}
1571
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001572static void
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001573qla24xx_tm_iocb_entry(scsi_qla_host_t *vha, struct req_que *req, void *tsk)
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001574{
1575 const char func[] = "TMF-IOCB";
1576 const char *type;
1577 fc_port_t *fcport;
1578 srb_t *sp;
1579 struct srb_iocb *iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001580 struct sts_entry_24xx *sts = (struct sts_entry_24xx *)tsk;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001581
1582 sp = qla2x00_get_sp_from_handle(vha, func, req, tsk);
1583 if (!sp)
1584 return;
1585
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001586 iocb = &sp->u.iocb_cmd;
1587 type = sp->name;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001588 fcport = sp->fcport;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001589 iocb->u.tmf.data = QLA_SUCCESS;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001590
1591 if (sts->entry_status) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001592 ql_log(ql_log_warn, fcport->vha, 0x5038,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001593 "Async-%s error - hdl=%x entry-status(%x).\n",
1594 type, sp->handle, sts->entry_status);
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001595 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07001596 } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001597 ql_log(ql_log_warn, fcport->vha, 0x5039,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001598 "Async-%s error - hdl=%x completion status(%x).\n",
1599 type, sp->handle, sts->comp_status);
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001600 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
1601 } else if ((le16_to_cpu(sts->scsi_status) &
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001602 SS_RESPONSE_INFO_LEN_VALID)) {
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001603 if (le32_to_cpu(sts->rsp_data_len) < 4) {
1604 ql_log(ql_log_warn, fcport->vha, 0x503b,
1605 "Async-%s error - hdl=%x not enough response(%d).\n",
1606 type, sp->handle, sts->rsp_data_len);
1607 } else if (sts->data[3]) {
1608 ql_log(ql_log_warn, fcport->vha, 0x503c,
1609 "Async-%s error - hdl=%x response(%x).\n",
1610 type, sp->handle, sts->data[3]);
Bart Van Assche8d2b21d2015-06-04 15:58:09 -07001611 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001612 }
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001613 }
1614
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001615 if (iocb->u.tmf.data != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001616 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5055,
1617 (uint8_t *)sts, sizeof(*sts));
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001618
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001619 sp->done(vha, sp, 0);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001620}
1621
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622/**
1623 * qla2x00_process_response_queue() - Process response queue entries.
1624 * @ha: SCSI driver HA context
1625 */
1626void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001627qla2x00_process_response_queue(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001629 struct scsi_qla_host *vha;
1630 struct qla_hw_data *ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001631 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 sts_entry_t *pkt;
1633 uint16_t handle_cnt;
1634 uint16_t cnt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001635
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001636 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001638 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 return;
1640
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001641 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1642 pkt = (sts_entry_t *)rsp->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001644 rsp->ring_index++;
1645 if (rsp->ring_index == rsp->length) {
1646 rsp->ring_index = 0;
1647 rsp->ring_ptr = rsp->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001649 rsp->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 }
1651
1652 if (pkt->entry_status != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001653 qla2x00_error_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1655 wmb();
1656 continue;
1657 }
1658
1659 switch (pkt->entry_type) {
1660 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001661 qla2x00_status_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 break;
1663 case STATUS_TYPE_21:
1664 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
1665 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001666 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 ((sts21_entry_t *)pkt)->handle[cnt]);
1668 }
1669 break;
1670 case STATUS_TYPE_22:
1671 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
1672 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001673 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 ((sts22_entry_t *)pkt)->handle[cnt]);
1675 }
1676 break;
1677 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001678 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001680 case MBX_IOCB_TYPE:
1681 qla2x00_mbx_iocb_entry(vha, rsp->req,
1682 (struct mbx_entry *)pkt);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001683 break;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001684 case CT_IOCB_TYPE:
1685 qla2x00_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
1686 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 default:
1688 /* Type Not Supported. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001689 ql_log(ql_log_warn, vha, 0x504a,
1690 "Received unknown response pkt type %x "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 "entry status=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001692 pkt->entry_type, pkt->entry_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 break;
1694 }
1695 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1696 wmb();
1697 }
1698
1699 /* Adjust ring index */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001700 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701}
1702
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001703static inline void
Andrew Vasquez55442132010-07-23 15:28:27 +05001704qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t par_sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001705 uint32_t sense_len, struct rsp_que *rsp, int res)
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001706{
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001707 struct scsi_qla_host *vha = sp->fcport->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001708 struct scsi_cmnd *cp = GET_CMD_SP(sp);
1709 uint32_t track_sense_len;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001710
1711 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
1712 sense_len = SCSI_SENSE_BUFFERSIZE;
1713
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001714 SET_CMD_SENSE_LEN(sp, sense_len);
1715 SET_CMD_SENSE_PTR(sp, cp->sense_buffer);
1716 track_sense_len = sense_len;
1717
1718 if (sense_len > par_sense_len)
Andrew Vasquez55442132010-07-23 15:28:27 +05001719 sense_len = par_sense_len;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001720
1721 memcpy(cp->sense_buffer, sense_data, sense_len);
1722
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001723 SET_CMD_SENSE_PTR(sp, cp->sense_buffer + sense_len);
1724 track_sense_len -= sense_len;
1725 SET_CMD_SENSE_LEN(sp, track_sense_len);
1726
1727 if (track_sense_len != 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001728 rsp->status_srb = sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001729 cp->result = res;
1730 }
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001731
Chad Dupuiscfb09192011-11-18 09:03:07 -08001732 if (sense_len) {
1733 ql_dbg(ql_dbg_io + ql_dbg_buffer, vha, 0x301c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001734 "Check condition Sense data, nexus%ld:%d:%llu cmd=%p.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001735 sp->fcport->vha->host_no, cp->device->id, cp->device->lun,
1736 cp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001737 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302b,
1738 cp->sense_buffer, sense_len);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001739 }
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001740}
1741
Arun Easibad75002010-05-04 15:01:30 -07001742struct scsi_dif_tuple {
1743 __be16 guard; /* Checksum */
Masanari Iidad6a03582012-08-22 14:20:58 -04001744 __be16 app_tag; /* APPL identifier */
Arun Easibad75002010-05-04 15:01:30 -07001745 __be32 ref_tag; /* Target LBA or indirect LBA */
1746};
1747
1748/*
1749 * Checks the guard or meta-data for the type of error
1750 * detected by the HBA. In case of errors, we set the
1751 * ASC/ASCQ fields in the sense buffer with ILLEGAL_REQUEST
1752 * to indicate to the kernel that the HBA detected error.
1753 */
Arun Easi8cb20492011-08-16 11:29:22 -07001754static inline int
Arun Easibad75002010-05-04 15:01:30 -07001755qla2x00_handle_dif_error(srb_t *sp, struct sts_entry_24xx *sts24)
1756{
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001757 struct scsi_qla_host *vha = sp->fcport->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001758 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Arun Easi8cb20492011-08-16 11:29:22 -07001759 uint8_t *ap = &sts24->data[12];
1760 uint8_t *ep = &sts24->data[20];
Arun Easibad75002010-05-04 15:01:30 -07001761 uint32_t e_ref_tag, a_ref_tag;
1762 uint16_t e_app_tag, a_app_tag;
1763 uint16_t e_guard, a_guard;
1764
Arun Easi8cb20492011-08-16 11:29:22 -07001765 /*
1766 * swab32 of the "data" field in the beginning of qla2x00_status_entry()
1767 * would make guard field appear at offset 2
1768 */
1769 a_guard = le16_to_cpu(*(uint16_t *)(ap + 2));
1770 a_app_tag = le16_to_cpu(*(uint16_t *)(ap + 0));
1771 a_ref_tag = le32_to_cpu(*(uint32_t *)(ap + 4));
1772 e_guard = le16_to_cpu(*(uint16_t *)(ep + 2));
1773 e_app_tag = le16_to_cpu(*(uint16_t *)(ep + 0));
1774 e_ref_tag = le32_to_cpu(*(uint32_t *)(ep + 4));
Arun Easibad75002010-05-04 15:01:30 -07001775
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001776 ql_dbg(ql_dbg_io, vha, 0x3023,
1777 "iocb(s) %p Returned STATUS.\n", sts24);
Arun Easibad75002010-05-04 15:01:30 -07001778
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001779 ql_dbg(ql_dbg_io, vha, 0x3024,
1780 "DIF ERROR in cmd 0x%x lba 0x%llx act ref"
Arun Easibad75002010-05-04 15:01:30 -07001781 " tag=0x%x, exp ref_tag=0x%x, act app tag=0x%x, exp app"
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001782 " tag=0x%x, act guard=0x%x, exp guard=0x%x.\n",
Arun Easibad75002010-05-04 15:01:30 -07001783 cmd->cmnd[0], (u64)scsi_get_lba(cmd), a_ref_tag, e_ref_tag,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001784 a_app_tag, e_app_tag, a_guard, e_guard);
Arun Easibad75002010-05-04 15:01:30 -07001785
Arun Easi8cb20492011-08-16 11:29:22 -07001786 /*
1787 * Ignore sector if:
1788 * For type 3: ref & app tag is all 'f's
1789 * For type 0,1,2: app tag is all 'f's
1790 */
1791 if ((a_app_tag == 0xffff) &&
1792 ((scsi_get_prot_type(cmd) != SCSI_PROT_DIF_TYPE3) ||
1793 (a_ref_tag == 0xffffffff))) {
1794 uint32_t blocks_done, resid;
1795 sector_t lba_s = scsi_get_lba(cmd);
1796
1797 /* 2TB boundary case covered automatically with this */
1798 blocks_done = e_ref_tag - (uint32_t)lba_s + 1;
1799
1800 resid = scsi_bufflen(cmd) - (blocks_done *
1801 cmd->device->sector_size);
1802
1803 scsi_set_resid(cmd, resid);
1804 cmd->result = DID_OK << 16;
1805
1806 /* Update protection tag */
1807 if (scsi_prot_sg_count(cmd)) {
1808 uint32_t i, j = 0, k = 0, num_ent;
1809 struct scatterlist *sg;
1810 struct sd_dif_tuple *spt;
1811
1812 /* Patch the corresponding protection tags */
1813 scsi_for_each_prot_sg(cmd, sg,
1814 scsi_prot_sg_count(cmd), i) {
1815 num_ent = sg_dma_len(sg) / 8;
1816 if (k + num_ent < blocks_done) {
1817 k += num_ent;
1818 continue;
1819 }
1820 j = blocks_done - k - 1;
1821 k = blocks_done;
1822 break;
1823 }
1824
1825 if (k != blocks_done) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001826 ql_log(ql_log_warn, vha, 0x302f,
Randy Dunlap8ec9c7f2011-09-23 15:40:50 -07001827 "unexpected tag values tag:lba=%x:%llx)\n",
1828 e_ref_tag, (unsigned long long)lba_s);
Arun Easi8cb20492011-08-16 11:29:22 -07001829 return 1;
1830 }
1831
1832 spt = page_address(sg_page(sg)) + sg->offset;
1833 spt += j;
1834
1835 spt->app_tag = 0xffff;
1836 if (scsi_get_prot_type(cmd) == SCSI_PROT_DIF_TYPE3)
1837 spt->ref_tag = 0xffffffff;
1838 }
1839
1840 return 0;
1841 }
1842
Arun Easibad75002010-05-04 15:01:30 -07001843 /* check guard */
1844 if (e_guard != a_guard) {
1845 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1846 0x10, 0x1);
1847 set_driver_byte(cmd, DRIVER_SENSE);
1848 set_host_byte(cmd, DID_ABORT);
1849 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
Arun Easi8cb20492011-08-16 11:29:22 -07001850 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001851 }
1852
Arun Easie02587d2011-08-16 11:29:23 -07001853 /* check ref tag */
1854 if (e_ref_tag != a_ref_tag) {
1855 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1856 0x10, 0x3);
1857 set_driver_byte(cmd, DRIVER_SENSE);
1858 set_host_byte(cmd, DID_ABORT);
1859 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
1860 return 1;
1861 }
1862
Arun Easibad75002010-05-04 15:01:30 -07001863 /* check appl tag */
1864 if (e_app_tag != a_app_tag) {
1865 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1866 0x10, 0x2);
1867 set_driver_byte(cmd, DRIVER_SENSE);
1868 set_host_byte(cmd, DID_ABORT);
1869 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
Arun Easi8cb20492011-08-16 11:29:22 -07001870 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001871 }
1872
Arun Easi8cb20492011-08-16 11:29:22 -07001873 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001874}
1875
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04001876static void
1877qla25xx_process_bidir_status_iocb(scsi_qla_host_t *vha, void *pkt,
1878 struct req_que *req, uint32_t index)
1879{
1880 struct qla_hw_data *ha = vha->hw;
1881 srb_t *sp;
1882 uint16_t comp_status;
1883 uint16_t scsi_status;
1884 uint16_t thread_id;
1885 uint32_t rval = EXT_STATUS_OK;
1886 struct fc_bsg_job *bsg_job = NULL;
1887 sts_entry_t *sts;
1888 struct sts_entry_24xx *sts24;
1889 sts = (sts_entry_t *) pkt;
1890 sts24 = (struct sts_entry_24xx *) pkt;
1891
1892 /* Validate handle. */
Chad Dupuis8d93f552013-01-30 03:34:37 -05001893 if (index >= req->num_outstanding_cmds) {
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04001894 ql_log(ql_log_warn, vha, 0x70af,
1895 "Invalid SCSI completion handle 0x%x.\n", index);
1896 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1897 return;
1898 }
1899
1900 sp = req->outstanding_cmds[index];
1901 if (sp) {
1902 /* Free outstanding command slot. */
1903 req->outstanding_cmds[index] = NULL;
1904 bsg_job = sp->u.bsg_job;
1905 } else {
1906 ql_log(ql_log_warn, vha, 0x70b0,
1907 "Req:%d: Invalid ISP SCSI completion handle(0x%x)\n",
1908 req->id, index);
1909
1910 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1911 return;
1912 }
1913
1914 if (IS_FWI2_CAPABLE(ha)) {
1915 comp_status = le16_to_cpu(sts24->comp_status);
1916 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
1917 } else {
1918 comp_status = le16_to_cpu(sts->comp_status);
1919 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1920 }
1921
1922 thread_id = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1923 switch (comp_status) {
1924 case CS_COMPLETE:
1925 if (scsi_status == 0) {
1926 bsg_job->reply->reply_payload_rcv_len =
1927 bsg_job->reply_payload.payload_len;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -04001928 vha->qla_stats.input_bytes +=
1929 bsg_job->reply->reply_payload_rcv_len;
1930 vha->qla_stats.input_requests++;
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04001931 rval = EXT_STATUS_OK;
1932 }
1933 goto done;
1934
1935 case CS_DATA_OVERRUN:
1936 ql_dbg(ql_dbg_user, vha, 0x70b1,
1937 "Command completed with date overrun thread_id=%d\n",
1938 thread_id);
1939 rval = EXT_STATUS_DATA_OVERRUN;
1940 break;
1941
1942 case CS_DATA_UNDERRUN:
1943 ql_dbg(ql_dbg_user, vha, 0x70b2,
1944 "Command completed with date underrun thread_id=%d\n",
1945 thread_id);
1946 rval = EXT_STATUS_DATA_UNDERRUN;
1947 break;
1948 case CS_BIDIR_RD_OVERRUN:
1949 ql_dbg(ql_dbg_user, vha, 0x70b3,
1950 "Command completed with read data overrun thread_id=%d\n",
1951 thread_id);
1952 rval = EXT_STATUS_DATA_OVERRUN;
1953 break;
1954
1955 case CS_BIDIR_RD_WR_OVERRUN:
1956 ql_dbg(ql_dbg_user, vha, 0x70b4,
1957 "Command completed with read and write data overrun "
1958 "thread_id=%d\n", thread_id);
1959 rval = EXT_STATUS_DATA_OVERRUN;
1960 break;
1961
1962 case CS_BIDIR_RD_OVERRUN_WR_UNDERRUN:
1963 ql_dbg(ql_dbg_user, vha, 0x70b5,
1964 "Command completed with read data over and write data "
1965 "underrun thread_id=%d\n", thread_id);
1966 rval = EXT_STATUS_DATA_OVERRUN;
1967 break;
1968
1969 case CS_BIDIR_RD_UNDERRUN:
1970 ql_dbg(ql_dbg_user, vha, 0x70b6,
1971 "Command completed with read data data underrun "
1972 "thread_id=%d\n", thread_id);
1973 rval = EXT_STATUS_DATA_UNDERRUN;
1974 break;
1975
1976 case CS_BIDIR_RD_UNDERRUN_WR_OVERRUN:
1977 ql_dbg(ql_dbg_user, vha, 0x70b7,
1978 "Command completed with read data under and write data "
1979 "overrun thread_id=%d\n", thread_id);
1980 rval = EXT_STATUS_DATA_UNDERRUN;
1981 break;
1982
1983 case CS_BIDIR_RD_WR_UNDERRUN:
1984 ql_dbg(ql_dbg_user, vha, 0x70b8,
1985 "Command completed with read and write data underrun "
1986 "thread_id=%d\n", thread_id);
1987 rval = EXT_STATUS_DATA_UNDERRUN;
1988 break;
1989
1990 case CS_BIDIR_DMA:
1991 ql_dbg(ql_dbg_user, vha, 0x70b9,
1992 "Command completed with data DMA error thread_id=%d\n",
1993 thread_id);
1994 rval = EXT_STATUS_DMA_ERR;
1995 break;
1996
1997 case CS_TIMEOUT:
1998 ql_dbg(ql_dbg_user, vha, 0x70ba,
1999 "Command completed with timeout thread_id=%d\n",
2000 thread_id);
2001 rval = EXT_STATUS_TIMEOUT;
2002 break;
2003 default:
2004 ql_dbg(ql_dbg_user, vha, 0x70bb,
2005 "Command completed with completion status=0x%x "
2006 "thread_id=%d\n", comp_status, thread_id);
2007 rval = EXT_STATUS_ERR;
2008 break;
2009 }
Bart Van Assche8d2b21d2015-06-04 15:58:09 -07002010 bsg_job->reply->reply_payload_rcv_len = 0;
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04002011
2012done:
2013 /* Return the vendor specific reply to API */
2014 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
2015 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2016 /* Always return DID_OK, bsg will send the vendor specific response
2017 * in this case only */
2018 sp->done(vha, sp, (DID_OK << 6));
2019
2020}
2021
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022/**
2023 * qla2x00_status_entry() - Process a Status IOCB entry.
2024 * @ha: SCSI driver HA context
2025 * @pkt: Entry pointer
2026 */
2027static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002028qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 fc_port_t *fcport;
2032 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002033 sts_entry_t *sts;
2034 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 uint16_t comp_status;
2036 uint16_t scsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002037 uint16_t ox_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 uint8_t lscsi_status;
2039 int32_t resid;
Andrew Vasquez55442132010-07-23 15:28:27 +05002040 uint32_t sense_len, par_sense_len, rsp_info_len, resid_len,
2041 fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002042 uint8_t *rsp_info, *sense_data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002043 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002044 uint32_t handle;
2045 uint16_t que;
2046 struct req_que *req;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002047 int logit = 1;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002048 int res = 0;
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04002049 uint16_t state_flags = 0;
Chad Dupuise05fe292014-09-25 05:16:59 -04002050 uint16_t retry_delay = 0;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002051
2052 sts = (sts_entry_t *) pkt;
2053 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002054 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002055 comp_status = le16_to_cpu(sts24->comp_status);
2056 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04002057 state_flags = le16_to_cpu(sts24->state_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002058 } else {
2059 comp_status = le16_to_cpu(sts->comp_status);
2060 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
2061 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002062 handle = (uint32_t) LSW(sts->handle);
2063 que = MSW(sts->handle);
2064 req = ha->req_q_map[que];
Giridhar Malavalia9083012010-04-12 17:59:55 -07002065
Chad Dupuis36008cf2013-10-03 03:21:13 -04002066 /* Check for invalid queue pointer */
2067 if (req == NULL ||
2068 que >= find_first_zero_bit(ha->req_qid_map, ha->max_req_queues)) {
2069 ql_dbg(ql_dbg_io, vha, 0x3059,
2070 "Invalid status handle (0x%x): Bad req pointer. req=%p, "
2071 "que=%u.\n", sts->handle, req, que);
2072 return;
2073 }
2074
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 /* Validate handle. */
Chad Dupuis8d93f552013-01-30 03:34:37 -05002076 if (handle < req->num_outstanding_cmds)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002077 sp = req->outstanding_cmds[handle];
Chad Dupuis8d93f552013-01-30 03:34:37 -05002078 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 sp = NULL;
2080
2081 if (sp == NULL) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08002082 ql_dbg(ql_dbg_io, vha, 0x3017,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002083 "Invalid status handle (0x%x).\n", sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
Chad Dupuisacd3ce82014-04-11 16:54:07 -04002085 if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
2086 if (IS_P3P_TYPE(ha))
2087 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
2088 else
2089 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2090 qla2xxx_wake_dpc(vha);
2091 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 return;
2093 }
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04002094
2095 if (unlikely((state_flags & BIT_1) && (sp->type == SRB_BIDI_CMD))) {
2096 qla25xx_process_bidir_status_iocb(vha, pkt, req, handle);
2097 return;
2098 }
2099
Armen Baloyanfaef62d2014-02-26 04:15:17 -05002100 /* Task Management completion. */
2101 if (sp->type == SRB_TM_CMD) {
2102 qla24xx_tm_iocb_entry(vha, req, pkt);
2103 return;
2104 }
2105
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04002106 /* Fast path completion. */
2107 if (comp_status == CS_COMPLETE && scsi_status == 0) {
2108 qla2x00_process_completed_request(vha, req, handle);
2109
2110 return;
2111 }
2112
2113 req->outstanding_cmds[handle] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002114 cp = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 if (cp == NULL) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08002116 ql_dbg(ql_dbg_io, vha, 0x3018,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002117 "Command already returned (0x%x/%p).\n",
2118 sts->handle, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119
2120 return;
2121 }
2122
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002123 lscsi_status = scsi_status & STATUS_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
bdf79622005-04-17 15:06:53 -05002125 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002127 ox_id = 0;
Andrew Vasquez55442132010-07-23 15:28:27 +05002128 sense_len = par_sense_len = rsp_info_len = resid_len =
2129 fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002130 if (IS_FWI2_CAPABLE(ha)) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002131 if (scsi_status & SS_SENSE_LEN_VALID)
2132 sense_len = le32_to_cpu(sts24->sense_len);
2133 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
2134 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
2135 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER))
2136 resid_len = le32_to_cpu(sts24->rsp_residual_count);
2137 if (comp_status == CS_DATA_UNDERRUN)
2138 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002139 rsp_info = sts24->data;
2140 sense_data = sts24->data;
2141 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002142 ox_id = le16_to_cpu(sts24->ox_id);
Andrew Vasquez55442132010-07-23 15:28:27 +05002143 par_sense_len = sizeof(sts24->data);
Chad Dupuise05fe292014-09-25 05:16:59 -04002144 /* Valid values of the retry delay timer are 0x1-0xffef */
2145 if (sts24->retry_delay > 0 && sts24->retry_delay < 0xfff1)
2146 retry_delay = sts24->retry_delay;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002147 } else {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002148 if (scsi_status & SS_SENSE_LEN_VALID)
2149 sense_len = le16_to_cpu(sts->req_sense_length);
2150 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
2151 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002152 resid_len = le32_to_cpu(sts->residual_length);
2153 rsp_info = sts->rsp_info;
2154 sense_data = sts->req_sense_data;
Andrew Vasquez55442132010-07-23 15:28:27 +05002155 par_sense_len = sizeof(sts->req_sense_data);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002156 }
2157
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 /* Check for any FCP transport errors. */
2159 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002160 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasquez55442132010-07-23 15:28:27 +05002161 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002162 sense_data += rsp_info_len;
Andrew Vasquez55442132010-07-23 15:28:27 +05002163 par_sense_len -= rsp_info_len;
2164 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002165 if (rsp_info_len > 3 && rsp_info[3]) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002166 ql_dbg(ql_dbg_io, fcport->vha, 0x3019,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002167 "FCP I/O protocol failure (0x%x/0x%x).\n",
2168 rsp_info_len, rsp_info[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002170 res = DID_BUS_BUSY << 16;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002171 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 }
2173 }
2174
Andrew Vasquez3e8ce322008-02-28 14:06:10 -08002175 /* Check for overrun. */
2176 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
2177 scsi_status & SS_RESIDUAL_OVER)
2178 comp_status = CS_DATA_OVERRUN;
2179
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 /*
Chad Dupuise05fe292014-09-25 05:16:59 -04002181 * Check retry_delay_timer value if we receive a busy or
2182 * queue full.
2183 */
2184 if (lscsi_status == SAM_STAT_TASK_SET_FULL ||
2185 lscsi_status == SAM_STAT_BUSY)
2186 qla2x00_set_retry_delay_timestamp(fcport, retry_delay);
2187
2188 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 * Based on Host and scsi status generate status code for Linux
2190 */
2191 switch (comp_status) {
2192 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002193 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 if (scsi_status == 0) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002195 res = DID_OK << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 break;
2197 }
2198 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002199 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002200 scsi_set_resid(cp, resid);
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002201
2202 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002203 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002204 cp->underflow)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002205 ql_dbg(ql_dbg_io, fcport->vha, 0x301a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002206 "Mid-layer underflow "
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002207 "detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002208 resid, scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002209
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002210 res = DID_ERROR << 16;
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002211 break;
2212 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002214 res = DID_OK << 16 | lscsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002216 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002217 ql_dbg(ql_dbg_io, fcport->vha, 0x301b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002218 "QUEUE FULL detected.\n");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002219 break;
2220 }
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002221 logit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 if (lscsi_status != SS_CHECK_CONDITION)
2223 break;
2224
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002225 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 if (!(scsi_status & SS_SENSE_LEN_VALID))
2227 break;
2228
Andrew Vasquez55442132010-07-23 15:28:27 +05002229 qla2x00_handle_sense(sp, sense_data, par_sense_len, sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002230 rsp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 break;
2232
2233 case CS_DATA_UNDERRUN:
Ravi Ananded17c71b52006-05-17 15:08:55 -07002234 /* Use F/W calculated residual length. */
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002235 resid = IS_FWI2_CAPABLE(ha) ? fw_resid_len : resid_len;
2236 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 if (scsi_status & SS_RESIDUAL_UNDER) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002238 if (IS_FWI2_CAPABLE(ha) && fw_resid_len != resid_len) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002239 ql_dbg(ql_dbg_io, fcport->vha, 0x301d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002240 "Dropped frame(s) detected "
2241 "(0x%x of 0x%x bytes).\n",
2242 resid, scsi_bufflen(cp));
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -08002243
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002244 res = DID_ERROR << 16 | lscsi_status;
Arun Easi4e85e3d2011-11-18 09:02:10 -08002245 goto check_scsi_status;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002246 }
2247
2248 if (!lscsi_status &&
2249 ((unsigned)(scsi_bufflen(cp) - resid) <
2250 cp->underflow)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002251 ql_dbg(ql_dbg_io, fcport->vha, 0x301e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002252 "Mid-layer underflow "
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002253 "detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002254 resid, scsi_bufflen(cp));
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002255
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002256 res = DID_ERROR << 16;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002257 break;
2258 }
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002259 } else if (lscsi_status != SAM_STAT_TASK_SET_FULL &&
2260 lscsi_status != SAM_STAT_BUSY) {
2261 /*
2262 * scsi status of task set and busy are considered to be
2263 * task not completed.
2264 */
2265
Arun Easi5e19ed92012-02-09 11:15:51 -08002266 ql_dbg(ql_dbg_io, fcport->vha, 0x301f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002267 "Dropped frame(s) detected (0x%x "
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002268 "of 0x%x bytes).\n", resid,
2269 scsi_bufflen(cp));
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002270
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002271 res = DID_ERROR << 16 | lscsi_status;
Lalit Chandivade0374f552010-09-03 14:57:04 -07002272 goto check_scsi_status;
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002273 } else {
2274 ql_dbg(ql_dbg_io, fcport->vha, 0x3030,
2275 "scsi_status: 0x%x, lscsi_status: 0x%x\n",
2276 scsi_status, lscsi_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 }
2278
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002279 res = DID_OK << 16 | lscsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002280 logit = 0;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002281
Lalit Chandivade0374f552010-09-03 14:57:04 -07002282check_scsi_status:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002284 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 * Status.
2286 */
2287 if (lscsi_status != 0) {
Andrew Vasquezffec28a2007-01-29 10:22:27 -08002288 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002289 ql_dbg(ql_dbg_io, fcport->vha, 0x3020,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002290 "QUEUE FULL detected.\n");
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002291 logit = 1;
Andrew Vasquezffec28a2007-01-29 10:22:27 -08002292 break;
2293 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 if (lscsi_status != SS_CHECK_CONDITION)
2295 break;
2296
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002297 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 if (!(scsi_status & SS_SENSE_LEN_VALID))
2299 break;
2300
Andrew Vasquez55442132010-07-23 15:28:27 +05002301 qla2x00_handle_sense(sp, sense_data, par_sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002302 sense_len, rsp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 }
2304 break;
2305
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 case CS_PORT_LOGGED_OUT:
2307 case CS_PORT_CONFIG_CHG:
2308 case CS_PORT_BUSY:
2309 case CS_INCOMPLETE:
2310 case CS_PORT_UNAVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 case CS_TIMEOUT:
Chad Dupuisff454b02010-10-15 11:27:42 -07002312 case CS_RESET:
2313
Mike Christie056a4482008-08-19 18:45:29 -05002314 /*
2315 * We are going to have the fc class block the rport
2316 * while we try to recover so instruct the mid layer
2317 * to requeue until the class decides how to handle this.
2318 */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002319 res = DID_TRANSPORT_DISRUPTED << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002321 if (comp_status == CS_TIMEOUT) {
2322 if (IS_FWI2_CAPABLE(ha))
2323 break;
2324 else if ((le16_to_cpu(sts->status_flags) &
2325 SF_LOGOUT_SENT) == 0)
2326 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002328
Arun Easi5e19ed92012-02-09 11:15:51 -08002329 ql_dbg(ql_dbg_io, fcport->vha, 0x3021,
Chad Dupuis0e948972013-08-27 01:37:39 -04002330 "Port to be marked lost on fcport=%02x%02x%02x, current "
2331 "port state= %s.\n", fcport->d_id.b.domain,
2332 fcport->d_id.b.area, fcport->d_id.b.al_pa,
2333 port_state_str[atomic_read(&fcport->state)]);
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002334
2335 if (atomic_read(&fcport->state) == FCS_ONLINE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002336 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 break;
2338
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002339 case CS_ABORTED:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002340 res = DID_RESET << 16;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002341 break;
Arun Easibad75002010-05-04 15:01:30 -07002342
2343 case CS_DIF_ERROR:
Arun Easi8cb20492011-08-16 11:29:22 -07002344 logit = qla2x00_handle_dif_error(sp, sts24);
Arun Easifb6e4662012-08-22 14:21:32 -04002345 res = cp->result;
Arun Easibad75002010-05-04 15:01:30 -07002346 break;
Arun Easi9e522cd2012-08-22 14:21:31 -04002347
2348 case CS_TRANSPORT:
2349 res = DID_ERROR << 16;
2350
2351 if (!IS_PI_SPLIT_DET_CAPABLE(ha))
2352 break;
2353
2354 if (state_flags & BIT_4)
2355 scmd_printk(KERN_WARNING, cp,
2356 "Unsupported device '%s' found.\n",
2357 cp->device->vendor);
2358 break;
2359
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 default:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002361 res = DID_ERROR << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 break;
2363 }
2364
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002365out:
2366 if (logit)
Arun Easi5e19ed92012-02-09 11:15:51 -08002367 ql_dbg(ql_dbg_io, fcport->vha, 0x3022,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02002368 "FCP command status: 0x%x-0x%x (0x%x) nexus=%ld:%d:%llu "
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04002369 "portid=%02x%02x%02x oxid=0x%x cdb=%10phN len=0x%x "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002370 "rsp_info=0x%x resid=0x%x fw_resid=0x%x.\n",
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002371 comp_status, scsi_status, res, vha->host_no,
Chad Dupuiscfb09192011-11-18 09:03:07 -08002372 cp->device->id, cp->device->lun, fcport->d_id.b.domain,
2373 fcport->d_id.b.area, fcport->d_id.b.al_pa, ox_id,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04002374 cp->cmnd, scsi_bufflen(cp), rsp_info_len,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002375 resid_len, fw_resid_len);
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002376
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002377 if (rsp->status_srb == NULL)
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002378 sp->done(ha, sp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379}
2380
2381/**
2382 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
2383 * @ha: SCSI driver HA context
2384 * @pkt: Entry pointer
2385 *
2386 * Extended sense data.
2387 */
2388static void
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002389qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002391 uint8_t sense_sz = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002392 struct qla_hw_data *ha = rsp->hw;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002393 struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002394 srb_t *sp = rsp->status_srb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 struct scsi_cmnd *cp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002396 uint32_t sense_len;
2397 uint8_t *sense_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002399 if (!sp || !GET_CMD_SENSE_LEN(sp))
2400 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002402 sense_len = GET_CMD_SENSE_LEN(sp);
2403 sense_ptr = GET_CMD_SENSE_PTR(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002405 cp = GET_CMD_SP(sp);
2406 if (cp == NULL) {
2407 ql_log(ql_log_warn, vha, 0x3025,
2408 "cmd is NULL: already returned to OS (sp=%p).\n", sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002410 rsp->status_srb = NULL;
2411 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002414 if (sense_len > sizeof(pkt->data))
2415 sense_sz = sizeof(pkt->data);
2416 else
2417 sense_sz = sense_len;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002418
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002419 /* Move sense data. */
2420 if (IS_FWI2_CAPABLE(ha))
2421 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
2422 memcpy(sense_ptr, pkt->data, sense_sz);
2423 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302c,
2424 sense_ptr, sense_sz);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002425
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002426 sense_len -= sense_sz;
2427 sense_ptr += sense_sz;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002428
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002429 SET_CMD_SENSE_PTR(sp, sense_ptr);
2430 SET_CMD_SENSE_LEN(sp, sense_len);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002431
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002432 /* Place command on done queue. */
2433 if (sense_len == 0) {
2434 rsp->status_srb = NULL;
2435 sp->done(ha, sp, cp->result);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002436 }
Giridhar Malavalic4631192011-11-18 09:03:08 -08002437}
2438
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439/**
2440 * qla2x00_error_entry() - Process an error entry.
2441 * @ha: SCSI driver HA context
2442 * @pkt: Entry pointer
2443 */
2444static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002445qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446{
2447 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002448 struct qla_hw_data *ha = vha->hw;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002449 const char func[] = "ERROR-IOCB";
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002450 uint16_t que = MSW(pkt->handle);
Arun Easia6fe35c2012-02-09 11:16:01 -08002451 struct req_que *req = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002452 int res = DID_ERROR << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002453
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002454 ql_dbg(ql_dbg_async, vha, 0x502a,
2455 "type of error status in response: 0x%x\n", pkt->entry_status);
2456
Arun Easia6fe35c2012-02-09 11:16:01 -08002457 if (que >= ha->max_req_queues || !ha->req_q_map[que])
2458 goto fatal;
2459
2460 req = ha->req_q_map[que];
2461
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002462 if (pkt->entry_status & RF_BUSY)
2463 res = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464
Giridhar Malavalic4631192011-11-18 09:03:08 -08002465 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
Arun Easia6fe35c2012-02-09 11:16:01 -08002466 if (sp) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002467 sp->done(ha, sp, res);
Arun Easia6fe35c2012-02-09 11:16:01 -08002468 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 }
Arun Easia6fe35c2012-02-09 11:16:01 -08002470fatal:
2471 ql_log(ql_log_warn, vha, 0x5030,
2472 "Error entry - invalid handle/queue.\n");
2473
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002474 if (IS_P3P_TYPE(ha))
Arun Easia6fe35c2012-02-09 11:16:01 -08002475 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
2476 else
2477 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2478 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479}
2480
2481/**
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002482 * qla24xx_mbx_completion() - Process mailbox command completions.
2483 * @ha: SCSI driver HA context
2484 * @mb0: Mailbox0 register
2485 */
2486static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002487qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002488{
2489 uint16_t cnt;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002490 uint32_t mboxes;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002491 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002492 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002493 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2494
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002495 /* Read all mbox registers? */
2496 mboxes = (1 << ha->mbx_count) - 1;
2497 if (!ha->mcp)
Masanari Iidaa7201012012-11-21 02:40:42 -05002498 ql_dbg(ql_dbg_async, vha, 0x504e, "MBX pointer ERROR.\n");
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002499 else
2500 mboxes = ha->mcp->in_mb;
2501
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002502 /* Load return mailbox registers. */
2503 ha->flags.mbox_int = 1;
2504 ha->mailbox_out[0] = mb0;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002505 mboxes >>= 1;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002506 wptr = (uint16_t __iomem *)&reg->mailbox1;
2507
2508 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002509 if (mboxes & BIT_0)
2510 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
2511
2512 mboxes >>= 1;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002513 wptr++;
2514 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002515}
2516
Armen Baloyan4440e462014-02-26 04:15:18 -05002517static void
2518qla24xx_abort_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
2519 struct abort_entry_24xx *pkt)
2520{
2521 const char func[] = "ABT_IOCB";
2522 srb_t *sp;
2523 struct srb_iocb *abt;
2524
2525 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
2526 if (!sp)
2527 return;
2528
2529 abt = &sp->u.iocb_cmd;
2530 abt->u.abt.comp_status = le32_to_cpu(pkt->nport_handle);
2531 sp->done(vha, sp, 0);
2532}
2533
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002534/**
2535 * qla24xx_process_response_queue() - Process response queue entries.
2536 * @ha: SCSI driver HA context
2537 */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002538void qla24xx_process_response_queue(struct scsi_qla_host *vha,
2539 struct rsp_que *rsp)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002540{
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002541 struct sts_entry_24xx *pkt;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002542 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002543
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002544 if (!vha->flags.online)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002545 return;
2546
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002547 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
2548 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002549
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002550 rsp->ring_index++;
2551 if (rsp->ring_index == rsp->length) {
2552 rsp->ring_index = 0;
2553 rsp->ring_ptr = rsp->ring;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002554 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002555 rsp->ring_ptr++;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002556 }
2557
2558 if (pkt->entry_status != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002559 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002560
Quinn Tranf83adb62014-04-11 16:54:43 -04002561 if (qlt_24xx_process_response_error(vha, pkt))
2562 goto process_err;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002563
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002564 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2565 wmb();
2566 continue;
2567 }
Quinn Tranf83adb62014-04-11 16:54:43 -04002568process_err:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002569
2570 switch (pkt->entry_type) {
2571 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002572 qla2x00_status_entry(vha, rsp, pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002573 break;
2574 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002575 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002576 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002577 case VP_RPT_ID_IOCB_TYPE:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002578 qla24xx_report_id_acquisition(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002579 (struct vp_rpt_id_entry_24xx *)pkt);
2580 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07002581 case LOGINOUT_PORT_IOCB_TYPE:
2582 qla24xx_logio_entry(vha, rsp->req,
2583 (struct logio_entry_24xx *)pkt);
2584 break;
Quinn Tranf83adb62014-04-11 16:54:43 -04002585 case CT_IOCB_TYPE:
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002586 qla24xx_els_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002587 break;
Quinn Tranf83adb62014-04-11 16:54:43 -04002588 case ELS_IOCB_TYPE:
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002589 qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE);
2590 break;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002591 case ABTS_RECV_24XX:
2592 /* ensure that the ATIO queue is empty */
2593 qlt_24xx_process_atio_queue(vha);
2594 case ABTS_RESP_24XX:
2595 case CTIO_TYPE7:
2596 case NOTIFY_ACK_TYPE:
Quinn Tranf83adb62014-04-11 16:54:43 -04002597 case CTIO_CRC2:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002598 qlt_response_pkt_all_vps(vha, (response_t *)pkt);
2599 break;
Saurav Kashyap54883292011-08-16 11:31:48 -07002600 case MARKER_TYPE:
2601 /* Do nothing in this case, this check is to prevent it
2602 * from falling into default case
2603 */
2604 break;
Armen Baloyan4440e462014-02-26 04:15:18 -05002605 case ABORT_IOCB_TYPE:
2606 qla24xx_abort_iocb_entry(vha, rsp->req,
2607 (struct abort_entry_24xx *)pkt);
2608 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002609 default:
2610 /* Type Not Supported. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002611 ql_dbg(ql_dbg_async, vha, 0x5042,
2612 "Received unknown response pkt type %x "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002613 "entry status=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002614 pkt->entry_type, pkt->entry_status);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002615 break;
2616 }
2617 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2618 wmb();
2619 }
2620
2621 /* Adjust ring index */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002622 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002623 struct device_reg_82xx __iomem *reg = &ha->iobase->isp82;
2624 WRT_REG_DWORD(&reg->rsp_q_out[0], rsp->ring_index);
2625 } else
2626 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002627}
2628
Andrew Vasquez05236a02007-09-20 14:07:37 -07002629static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002630qla2xxx_check_risc_status(scsi_qla_host_t *vha)
Andrew Vasquez05236a02007-09-20 14:07:37 -07002631{
2632 int rval;
2633 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002634 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez05236a02007-09-20 14:07:37 -07002635 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2636
Chad Dupuisf73cb692014-02-26 04:15:06 -05002637 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2638 !IS_QLA27XX(ha))
Andrew Vasquez05236a02007-09-20 14:07:37 -07002639 return;
2640
2641 rval = QLA_SUCCESS;
2642 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
2643 RD_REG_DWORD(&reg->iobase_addr);
2644 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
2645 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
2646 rval == QLA_SUCCESS; cnt--) {
2647 if (cnt) {
2648 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
2649 udelay(10);
2650 } else
2651 rval = QLA_FUNCTION_TIMEOUT;
2652 }
2653 if (rval == QLA_SUCCESS)
2654 goto next_test;
2655
Bart Van Asscheb2ec76c2013-06-25 11:27:29 -04002656 rval = QLA_SUCCESS;
Andrew Vasquez05236a02007-09-20 14:07:37 -07002657 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
2658 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
2659 rval == QLA_SUCCESS; cnt--) {
2660 if (cnt) {
2661 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
2662 udelay(10);
2663 } else
2664 rval = QLA_FUNCTION_TIMEOUT;
2665 }
2666 if (rval != QLA_SUCCESS)
2667 goto done;
2668
2669next_test:
2670 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002671 ql_log(ql_log_info, vha, 0x504c,
2672 "Additional code -- 0x55AA.\n");
Andrew Vasquez05236a02007-09-20 14:07:37 -07002673
2674done:
2675 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
2676 RD_REG_DWORD(&reg->iobase_window);
2677}
2678
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002679/**
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002680 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP24xx.
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002681 * @irq:
2682 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002683 *
2684 * Called by system whenever the host adapter generates an interrupt.
2685 *
2686 * Returns handled flag.
2687 */
2688irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01002689qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002690{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002691 scsi_qla_host_t *vha;
2692 struct qla_hw_data *ha;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002693 struct device_reg_24xx __iomem *reg;
2694 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002695 unsigned long iter;
2696 uint32_t stat;
2697 uint32_t hccr;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002698 uint16_t mb[8];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002699 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002700 unsigned long flags;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002701
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002702 rsp = (struct rsp_que *) dev_id;
2703 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002704 ql_log(ql_log_info, NULL, 0x5059,
2705 "%s: NULL response queue pointer.\n", __func__);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002706 return IRQ_NONE;
2707 }
2708
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002709 ha = rsp->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002710 reg = &ha->iobase->isp24;
2711 status = 0;
2712
Andrew Vasquez85880802009-12-15 21:29:46 -08002713 if (unlikely(pci_channel_offline(ha->pdev)))
2714 return IRQ_HANDLED;
2715
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002716 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002717 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002718 for (iter = 50; iter--; ) {
2719 stat = RD_REG_DWORD(&reg->host_status);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04002720 if (qla2x00_check_reg32_for_disconnect(vha, stat))
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002721 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002722 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08002723 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07002724 break;
2725
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002726 hccr = RD_REG_DWORD(&reg->hccr);
2727
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002728 ql_log(ql_log_warn, vha, 0x504b,
2729 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2730 hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002731
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002732 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002733
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002734 ha->isp_ops->fw_dump(vha, 1);
2735 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002736 break;
2737 } else if ((stat & HSRX_RISC_INT) == 0)
2738 break;
2739
2740 switch (stat & 0xff) {
Arun Easifafbda92012-08-22 14:21:16 -04002741 case INTR_ROM_MB_SUCCESS:
2742 case INTR_ROM_MB_FAILED:
2743 case INTR_MB_SUCCESS:
2744 case INTR_MB_FAILED:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002745 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002746 status |= MBX_INTERRUPT;
2747
2748 break;
Arun Easifafbda92012-08-22 14:21:16 -04002749 case INTR_ASYNC_EVENT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002750 mb[0] = MSW(stat);
2751 mb[1] = RD_REG_WORD(&reg->mailbox1);
2752 mb[2] = RD_REG_WORD(&reg->mailbox2);
2753 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002754 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002755 break;
Arun Easifafbda92012-08-22 14:21:16 -04002756 case INTR_RSP_QUE_UPDATE:
2757 case INTR_RSP_QUE_UPDATE_83XX:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002758 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002759 break;
Arun Easifafbda92012-08-22 14:21:16 -04002760 case INTR_ATIO_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002761 qlt_24xx_process_atio_queue(vha);
2762 break;
Arun Easifafbda92012-08-22 14:21:16 -04002763 case INTR_ATIO_RSP_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002764 qlt_24xx_process_atio_queue(vha);
2765 qla24xx_process_response_queue(vha, rsp);
2766 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002767 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002768 ql_dbg(ql_dbg_async, vha, 0x504f,
2769 "Unrecognized interrupt type (%d).\n", stat * 0xff);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002770 break;
2771 }
2772 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2773 RD_REG_DWORD_RELAXED(&reg->hccr);
Giridhar Malavalicb860bb2012-08-22 14:21:30 -04002774 if (unlikely(IS_QLA83XX(ha) && (ha->pdev->revision == 1)))
2775 ndelay(3500);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002776 }
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -07002777 qla2x00_handle_mbx_completion(ha, status);
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002778 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002779
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002780 return IRQ_HANDLED;
2781}
2782
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002783static irqreturn_t
2784qla24xx_msix_rsp_q(int irq, void *dev_id)
2785{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002786 struct qla_hw_data *ha;
2787 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002788 struct device_reg_24xx __iomem *reg;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002789 struct scsi_qla_host *vha;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002790 unsigned long flags;
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002791 uint32_t stat = 0;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002792
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002793 rsp = (struct rsp_que *) dev_id;
2794 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002795 ql_log(ql_log_info, NULL, 0x505a,
2796 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002797 return IRQ_NONE;
2798 }
2799 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002800 reg = &ha->iobase->isp24;
2801
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002802 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002803
Anirban Chakrabortya67093d2010-02-04 14:17:59 -08002804 vha = pci_get_drvdata(ha->pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002805 /*
2806 * Use host_status register to check to PCI disconnection before we
2807 * we process the response queue.
2808 */
2809 stat = RD_REG_DWORD(&reg->host_status);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04002810 if (qla2x00_check_reg32_for_disconnect(vha, stat))
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002811 goto out;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002812 qla24xx_process_response_queue(vha, rsp);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002813 if (!ha->flags.disable_msix_handshake) {
Anirban Chakrabortyeb941142009-08-04 16:12:13 -07002814 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2815 RD_REG_DWORD_RELAXED(&reg->hccr);
2816 }
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002817out:
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002818 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002819
2820 return IRQ_HANDLED;
2821}
2822
2823static irqreturn_t
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002824qla25xx_msix_rsp_q(int irq, void *dev_id)
2825{
2826 struct qla_hw_data *ha;
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002827 scsi_qla_host_t *vha;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002828 struct rsp_que *rsp;
Anirban Chakraborty31557542009-12-02 10:36:55 -08002829 struct device_reg_24xx __iomem *reg;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002830 unsigned long flags;
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002831 uint32_t hccr = 0;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002832
2833 rsp = (struct rsp_que *) dev_id;
2834 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002835 ql_log(ql_log_info, NULL, 0x505b,
2836 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002837 return IRQ_NONE;
2838 }
2839 ha = rsp->hw;
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002840 vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002841
Anirban Chakraborty31557542009-12-02 10:36:55 -08002842 /* Clear the interrupt, if enabled, for this response queue */
Andrew Vasquezd4247542011-10-26 14:20:13 -07002843 if (!ha->flags.disable_msix_handshake) {
Anirban Chakraborty31557542009-12-02 10:36:55 -08002844 reg = &ha->iobase->isp24;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002845 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002846 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002847 hccr = RD_REG_DWORD_RELAXED(&reg->hccr);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002848 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002849 }
Joe Lawrencec821e0d2014-08-26 17:11:41 -04002850 if (qla2x00_check_reg32_for_disconnect(vha, hccr))
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002851 goto out;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002852 queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work);
2853
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002854out:
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002855 return IRQ_HANDLED;
2856}
2857
2858static irqreturn_t
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002859qla24xx_msix_default(int irq, void *dev_id)
2860{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002861 scsi_qla_host_t *vha;
2862 struct qla_hw_data *ha;
2863 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002864 struct device_reg_24xx __iomem *reg;
2865 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002866 uint32_t stat;
2867 uint32_t hccr;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002868 uint16_t mb[8];
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002869 unsigned long flags;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002870
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002871 rsp = (struct rsp_que *) dev_id;
2872 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002873 ql_log(ql_log_info, NULL, 0x505c,
2874 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002875 return IRQ_NONE;
2876 }
2877 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002878 reg = &ha->iobase->isp24;
2879 status = 0;
2880
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002881 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002882 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002883 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002884 stat = RD_REG_DWORD(&reg->host_status);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04002885 if (qla2x00_check_reg32_for_disconnect(vha, stat))
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002886 break;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002887 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08002888 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07002889 break;
2890
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002891 hccr = RD_REG_DWORD(&reg->hccr);
2892
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002893 ql_log(ql_log_info, vha, 0x5050,
2894 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2895 hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002896
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002897 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002898
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002899 ha->isp_ops->fw_dump(vha, 1);
2900 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002901 break;
2902 } else if ((stat & HSRX_RISC_INT) == 0)
2903 break;
2904
2905 switch (stat & 0xff) {
Arun Easifafbda92012-08-22 14:21:16 -04002906 case INTR_ROM_MB_SUCCESS:
2907 case INTR_ROM_MB_FAILED:
2908 case INTR_MB_SUCCESS:
2909 case INTR_MB_FAILED:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002910 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002911 status |= MBX_INTERRUPT;
2912
2913 break;
Arun Easifafbda92012-08-22 14:21:16 -04002914 case INTR_ASYNC_EVENT:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002915 mb[0] = MSW(stat);
2916 mb[1] = RD_REG_WORD(&reg->mailbox1);
2917 mb[2] = RD_REG_WORD(&reg->mailbox2);
2918 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002919 qla2x00_async_event(vha, rsp, mb);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002920 break;
Arun Easifafbda92012-08-22 14:21:16 -04002921 case INTR_RSP_QUE_UPDATE:
2922 case INTR_RSP_QUE_UPDATE_83XX:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002923 qla24xx_process_response_queue(vha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002924 break;
Arun Easifafbda92012-08-22 14:21:16 -04002925 case INTR_ATIO_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002926 qlt_24xx_process_atio_queue(vha);
2927 break;
Arun Easifafbda92012-08-22 14:21:16 -04002928 case INTR_ATIO_RSP_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002929 qlt_24xx_process_atio_queue(vha);
2930 qla24xx_process_response_queue(vha, rsp);
2931 break;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002932 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002933 ql_dbg(ql_dbg_async, vha, 0x5051,
2934 "Unrecognized interrupt type (%d).\n", stat & 0xff);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002935 break;
2936 }
2937 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002938 } while (0);
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -07002939 qla2x00_handle_mbx_completion(ha, status);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002940 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002941
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002942 return IRQ_HANDLED;
2943}
2944
2945/* Interrupt handling helpers. */
2946
2947struct qla_init_msix_entry {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002948 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07002949 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002950};
2951
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002952static struct qla_init_msix_entry msix_entries[3] = {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002953 { "qla2xxx (default)", qla24xx_msix_default },
2954 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002955 { "qla2xxx (multiq)", qla25xx_msix_rsp_q },
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002956};
2957
Giridhar Malavalia9083012010-04-12 17:59:55 -07002958static struct qla_init_msix_entry qla82xx_msix_entries[2] = {
2959 { "qla2xxx (default)", qla82xx_msix_default },
2960 { "qla2xxx (rsp_q)", qla82xx_msix_rsp_q },
2961};
2962
Arun Easiaa230bc2013-01-30 03:34:39 -05002963static struct qla_init_msix_entry qla83xx_msix_entries[3] = {
2964 { "qla2xxx (default)", qla24xx_msix_default },
2965 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
2966 { "qla2xxx (atio_q)", qla83xx_msix_atio_q },
2967};
2968
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002969static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002970qla24xx_disable_msix(struct qla_hw_data *ha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002971{
2972 int i;
2973 struct qla_msix_entry *qentry;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002974 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002975
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002976 for (i = 0; i < ha->msix_count; i++) {
2977 qentry = &ha->msix_entries[i];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002978 if (qentry->have_irq)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002979 free_irq(qentry->vector, qentry->rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002980 }
2981 pci_disable_msix(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002982 kfree(ha->msix_entries);
2983 ha->msix_entries = NULL;
2984 ha->flags.msix_enabled = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002985 ql_dbg(ql_dbg_init, vha, 0x0042,
2986 "Disabled the MSI.\n");
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002987}
2988
2989static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002990qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002991{
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002992#define MIN_MSIX_COUNT 2
Chad Dupuisf3247772014-02-26 04:15:14 -05002993#define ATIO_VECTOR 2
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002994 int i, ret;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002995 struct msix_entry *entries;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002996 struct qla_msix_entry *qentry;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002997 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002998
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002999 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
Giridhar Malavalia9083012010-04-12 17:59:55 -07003000 GFP_KERNEL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003001 if (!entries) {
3002 ql_log(ql_log_warn, vha, 0x00bc,
3003 "Failed to allocate memory for msix_entry.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003004 return -ENOMEM;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003005 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003006
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003007 for (i = 0; i < ha->msix_count; i++)
3008 entries[i].entry = i;
3009
Alexander Gordeev84e32a02014-08-18 08:01:47 +02003010 ret = pci_enable_msix_range(ha->pdev,
3011 entries, MIN_MSIX_COUNT, ha->msix_count);
3012 if (ret < 0) {
3013 ql_log(ql_log_fatal, vha, 0x00c7,
3014 "MSI-X: Failed to enable support, "
3015 "giving up -- %d/%d.\n",
3016 ha->msix_count, ret);
3017 goto msix_out;
3018 } else if (ret < ha->msix_count) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003019 ql_log(ql_log_warn, vha, 0x00c6,
3020 "MSI-X: Failed to enable support "
3021 "-- %d/%d\n Retry with %d vectors.\n",
3022 ha->msix_count, ret, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003023 }
Alexander Gordeev84e32a02014-08-18 08:01:47 +02003024 ha->msix_count = ret;
3025 ha->max_rsp_queues = ha->msix_count - 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003026 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
3027 ha->msix_count, GFP_KERNEL);
3028 if (!ha->msix_entries) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003029 ql_log(ql_log_fatal, vha, 0x00c8,
3030 "Failed to allocate memory for ha->msix_entries.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003031 ret = -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003032 goto msix_out;
3033 }
3034 ha->flags.msix_enabled = 1;
3035
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003036 for (i = 0; i < ha->msix_count; i++) {
3037 qentry = &ha->msix_entries[i];
3038 qentry->vector = entries[i].vector;
3039 qentry->entry = entries[i].entry;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003040 qentry->have_irq = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003041 qentry->rsp = NULL;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003042 }
3043
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003044 /* Enable MSI-X vectors for the base queue */
Chad Dupuisf3247772014-02-26 04:15:14 -05003045 for (i = 0; i < 2; i++) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003046 qentry = &ha->msix_entries[i];
Chad Dupuisf3247772014-02-26 04:15:14 -05003047 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07003048 ret = request_irq(qentry->vector,
3049 qla82xx_msix_entries[i].handler,
3050 0, qla82xx_msix_entries[i].name, rsp);
Chad Dupuisf3247772014-02-26 04:15:14 -05003051 else
Giridhar Malavalia9083012010-04-12 17:59:55 -07003052 ret = request_irq(qentry->vector,
3053 msix_entries[i].handler,
3054 0, msix_entries[i].name, rsp);
Chad Dupuisf3247772014-02-26 04:15:14 -05003055 if (ret)
3056 goto msix_register_fail;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003057 qentry->have_irq = 1;
3058 qentry->rsp = rsp;
3059 rsp->msix = qentry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003060 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003061
Chad Dupuisf3247772014-02-26 04:15:14 -05003062 /*
3063 * If target mode is enable, also request the vector for the ATIO
3064 * queue.
3065 */
3066 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) {
3067 qentry = &ha->msix_entries[ATIO_VECTOR];
3068 ret = request_irq(qentry->vector,
3069 qla83xx_msix_entries[ATIO_VECTOR].handler,
3070 0, qla83xx_msix_entries[ATIO_VECTOR].name, rsp);
3071 qentry->have_irq = 1;
3072 qentry->rsp = rsp;
3073 rsp->msix = qentry;
3074 }
3075
3076msix_register_fail:
3077 if (ret) {
3078 ql_log(ql_log_fatal, vha, 0x00cb,
3079 "MSI-X: unable to register handler -- %x/%d.\n",
3080 qentry->vector, ret);
3081 qla24xx_disable_msix(ha);
3082 ha->mqenable = 0;
3083 goto msix_out;
3084 }
3085
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003086 /* Enable MSI-X vector for response queue update for queue 0 */
Chad Dupuisf73cb692014-02-26 04:15:06 -05003087 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003088 if (ha->msixbase && ha->mqiobase &&
3089 (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
3090 ha->mqenable = 1;
3091 } else
3092 if (ha->mqiobase
3093 && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
3094 ha->mqenable = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003095 ql_dbg(ql_dbg_multiq, vha, 0xc005,
3096 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
3097 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
3098 ql_dbg(ql_dbg_init, vha, 0x0055,
3099 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
3100 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003101
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003102msix_out:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003103 kfree(entries);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003104 return ret;
3105}
3106
3107int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003108qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003109{
Sawan Chandak7fa3e232013-10-30 03:38:10 -04003110 int ret = QLA_FUNCTION_FAILED;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003111 device_reg_t *reg = ha->iobase;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003112 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003113
3114 /* If possible, enable MSI-X. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003115 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
Chad Dupuisf73cb692014-02-26 04:15:06 -05003116 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha) && !IS_QLAFX00(ha) &&
3117 !IS_QLA27XX(ha))
Ben Hutchings6377a7a2010-03-19 16:59:19 -07003118 goto skip_msi;
3119
3120 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
3121 (ha->pdev->subsystem_device == 0x7040 ||
3122 ha->pdev->subsystem_device == 0x7041 ||
3123 ha->pdev->subsystem_device == 0x1705)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003124 ql_log(ql_log_warn, vha, 0x0034,
3125 "MSI-X: Unsupported ISP 2432 SSVID/SSDID (0x%X,0x%X).\n",
Ben Hutchings6377a7a2010-03-19 16:59:19 -07003126 ha->pdev->subsystem_vendor,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003127 ha->pdev->subsystem_device);
Ben Hutchings6377a7a2010-03-19 16:59:19 -07003128 goto skip_msi;
3129 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003130
Chad Dupuis42cd4f52011-08-16 11:29:24 -07003131 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003132 ql_log(ql_log_warn, vha, 0x0035,
3133 "MSI-X; Unsupported ISP2432 (0x%X, 0x%X).\n",
Chad Dupuis42cd4f52011-08-16 11:29:24 -07003134 ha->pdev->revision, QLA_MSIX_CHIP_REV_24XX);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003135 goto skip_msix;
3136 }
3137
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003138 ret = qla24xx_enable_msix(ha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003139 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003140 ql_dbg(ql_dbg_init, vha, 0x0036,
3141 "MSI-X: Enabled (0x%X, 0x%X).\n",
3142 ha->chip_revision, ha->fw_attributes);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003143 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003144 }
Sawan Chandak7fa3e232013-10-30 03:38:10 -04003145
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003146skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07003147
Sawan Chandak7fa3e232013-10-30 03:38:10 -04003148 ql_log(ql_log_info, vha, 0x0037,
3149 "Falling back-to MSI mode -%d.\n", ret);
3150
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003151 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
Chad Dupuisf73cb692014-02-26 04:15:06 -05003152 !IS_QLA8001(ha) && !IS_P3P_TYPE(ha) && !IS_QLAFX00(ha) &&
3153 !IS_QLA27XX(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07003154 goto skip_msi;
3155
3156 ret = pci_enable_msi(ha->pdev);
3157 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003158 ql_dbg(ql_dbg_init, vha, 0x0038,
3159 "MSI: Enabled.\n");
Andrew Vasquezcbedb602007-05-07 07:43:02 -07003160 ha->flags.msi_enabled = 1;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003161 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003162 ql_log(ql_log_warn, vha, 0x0039,
Sawan Chandak7fa3e232013-10-30 03:38:10 -04003163 "Falling back-to INTa mode -- %d.\n", ret);
3164skip_msi:
Giridhar Malavalia033b652012-08-22 14:21:07 -04003165
3166 /* Skip INTx on ISP82xx. */
3167 if (!ha->flags.msi_enabled && IS_QLA82XX(ha))
3168 return QLA_FUNCTION_FAILED;
3169
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003170 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Mike Hernandez7992abf2010-11-23 16:52:47 -08003171 ha->flags.msi_enabled ? 0 : IRQF_SHARED,
3172 QLA2XXX_DRIVER_NAME, rsp);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003173 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003174 ql_log(ql_log_warn, vha, 0x003a,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003175 "Failed to reserve interrupt %d already in use.\n",
3176 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003177 goto fail;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003178 } else if (!ha->flags.msi_enabled) {
Saurav Kashyap68d91cb2012-11-21 02:40:44 -05003179 ql_dbg(ql_dbg_init, vha, 0x0125,
3180 "INTa mode: Enabled.\n");
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003181 ha->flags.mr_intr_valid = 1;
3182 }
Mike Hernandez7992abf2010-11-23 16:52:47 -08003183
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003184clear_risc_ints:
Joe Carnuccio4bb2efc2014-09-25 05:16:42 -04003185 if (IS_FWI2_CAPABLE(ha) || IS_QLAFX00(ha))
3186 goto fail;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003187
Andrew Vasquezc6952482008-04-03 13:13:17 -07003188 spin_lock_irq(&ha->hardware_lock);
Joe Carnuccio4bb2efc2014-09-25 05:16:42 -04003189 WRT_REG_WORD(&reg->isp.semaphore, 0);
Andrew Vasquezc6952482008-04-03 13:13:17 -07003190 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003191
3192fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003193 return ret;
3194}
3195
3196void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003197qla2x00_free_irqs(scsi_qla_host_t *vha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003198{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003199 struct qla_hw_data *ha = vha->hw;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003200 struct rsp_que *rsp;
3201
3202 /*
3203 * We need to check that ha->rsp_q_map is valid in case we are called
3204 * from a probe failure context.
3205 */
3206 if (!ha->rsp_q_map || !ha->rsp_q_map[0])
3207 return;
3208 rsp = ha->rsp_q_map[0];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003209
3210 if (ha->flags.msix_enabled)
3211 qla24xx_disable_msix(ha);
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003212 else if (ha->flags.msi_enabled) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003213 free_irq(ha->pdev->irq, rsp);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07003214 pci_disable_msi(ha->pdev);
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003215 } else
3216 free_irq(ha->pdev->irq, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003217}
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003218
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003219
3220int qla25xx_request_irq(struct rsp_que *rsp)
3221{
3222 struct qla_hw_data *ha = rsp->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003223 struct qla_init_msix_entry *intr = &msix_entries[2];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003224 struct qla_msix_entry *msix = rsp->msix;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003225 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003226 int ret;
3227
3228 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
3229 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003230 ql_log(ql_log_fatal, vha, 0x00e6,
3231 "MSI-X: Unable to register handler -- %x/%d.\n",
3232 msix->vector, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003233 return ret;
3234 }
3235 msix->have_irq = 1;
3236 msix->rsp = rsp;
3237 return ret;
3238}