blob: 6e649d733353e9035dc629114918ccf8e3d06d09 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Saurav Kashyap1e633952013-02-08 01:57:54 -05003 * Copyright (c) 2003-2013 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04008#include "qla_target.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Andrew Vasquez05236a02007-09-20 14:07:37 -070010#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070012#include <scsi/scsi_tcq.h>
Giridhar Malavali9a069e12010-01-12 13:02:47 -080013#include <scsi/scsi_bsg_fc.h>
Arun Easibad75002010-05-04 15:01:30 -070014#include <scsi/scsi_eh.h>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070015
Linus Torvalds1da177e2005-04-16 15:20:36 -070016static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080017static void qla2x00_status_entry(scsi_qla_host_t *, struct rsp_que *, void *);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070018static void qla2x00_status_cont_entry(struct rsp_que *, sts_cont_entry_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080019static void qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
20 sts_entry_t *);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022/**
23 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
24 * @irq:
25 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 *
27 * Called by system whenever the host adapter generates an interrupt.
28 *
29 * Returns handled flag.
30 */
31irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +010032qla2100_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080034 scsi_qla_host_t *vha;
35 struct qla_hw_data *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -070036 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 unsigned long iter;
Seokmann Ju14e660e2007-09-20 14:07:36 -070039 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070040 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080041 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070042 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080044 rsp = (struct rsp_que *) dev_id;
45 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -080046 ql_log(ql_log_info, NULL, 0x505d,
47 "%s: NULL response queue pointer.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 return (IRQ_NONE);
49 }
50
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080051 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -070052 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 status = 0;
54
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070055 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070056 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 for (iter = 50; iter--; ) {
Seokmann Ju14e660e2007-09-20 14:07:36 -070058 hccr = RD_REG_WORD(&reg->hccr);
59 if (hccr & HCCR_RISC_PAUSE) {
60 if (pci_channel_offline(ha->pdev))
61 break;
62
63 /*
64 * Issue a "HARD" reset in order for the RISC interrupt
Justin P. Mattocka06a0f82011-06-23 23:22:27 -070065 * bit to be cleared. Schedule a big hammer to get
Seokmann Ju14e660e2007-09-20 14:07:36 -070066 * out of the RISC PAUSED state.
67 */
68 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
69 RD_REG_WORD(&reg->hccr);
70
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080071 ha->isp_ops->fw_dump(vha, 1);
72 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -070073 break;
74 } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 break;
76
77 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
78 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
79 RD_REG_WORD(&reg->hccr);
80
81 /* Get mailbox data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -070082 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
83 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080084 qla2x00_mbx_completion(vha, mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 status |= MBX_INTERRUPT;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070086 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
87 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
88 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
89 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080090 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 } else {
92 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -070093 ql_dbg(ql_dbg_async, vha, 0x5025,
94 "Unrecognized interrupt type (%d).\n",
95 mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 }
97 /* Release mailbox registers. */
98 WRT_REG_WORD(&reg->semaphore, 0);
99 RD_REG_WORD(&reg->semaphore);
100 } else {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800101 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
104 RD_REG_WORD(&reg->hccr);
105 }
106 }
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -0700107 qla2x00_handle_mbx_completion(ha, status);
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700108 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 return (IRQ_HANDLED);
111}
112
113/**
114 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
115 * @irq:
116 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 *
118 * Called by system whenever the host adapter generates an interrupt.
119 *
120 * Returns handled flag.
121 */
122irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100123qla2300_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800125 scsi_qla_host_t *vha;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700126 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 unsigned long iter;
129 uint32_t stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700131 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800132 struct rsp_que *rsp;
133 struct qla_hw_data *ha;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700134 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800136 rsp = (struct rsp_que *) dev_id;
137 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -0800138 ql_log(ql_log_info, NULL, 0x5058,
139 "%s: NULL response queue pointer.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 return (IRQ_NONE);
141 }
142
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800143 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700144 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 status = 0;
146
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700147 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700148 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 for (iter = 50; iter--; ) {
150 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
151 if (stat & HSR_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800152 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -0700153 break;
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 hccr = RD_REG_WORD(&reg->hccr);
156 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700157 ql_log(ql_log_warn, vha, 0x5026,
158 "Parity error -- HCCR=%x, Dumping "
159 "firmware.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700161 ql_log(ql_log_warn, vha, 0x5027,
162 "RISC paused -- HCCR=%x, Dumping "
163 "firmware.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165 /*
166 * Issue a "HARD" reset in order for the RISC
167 * interrupt bit to be cleared. Schedule a big
Justin P. Mattocka06a0f82011-06-23 23:22:27 -0700168 * hammer to get out of the RISC PAUSED state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 */
170 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
171 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800172
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800173 ha->isp_ops->fw_dump(vha, 1);
174 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 break;
176 } else if ((stat & HSR_RISC_INT) == 0)
177 break;
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 case 0x1:
181 case 0x2:
182 case 0x10:
183 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800184 qla2x00_mbx_completion(vha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 status |= MBX_INTERRUPT;
186
187 /* Release mailbox registers. */
188 WRT_REG_WORD(&reg->semaphore, 0);
189 break;
190 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700191 mb[0] = MSW(stat);
192 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
193 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
194 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800195 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700196 break;
197 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800198 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 break;
200 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700201 mb[0] = MBA_CMPLT_1_16BIT;
202 mb[1] = MSW(stat);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800203 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 break;
205 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700206 mb[0] = MBA_SCSI_COMPLETION;
207 mb[1] = MSW(stat);
208 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800209 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 break;
211 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700212 ql_dbg(ql_dbg_async, vha, 0x5028,
213 "Unrecognized interrupt type (%d).\n", stat & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 break;
215 }
216 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
217 RD_REG_WORD_RELAXED(&reg->hccr);
218 }
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -0700219 qla2x00_handle_mbx_completion(ha, status);
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700220 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 return (IRQ_HANDLED);
223}
224
225/**
226 * qla2x00_mbx_completion() - Process mailbox command completions.
227 * @ha: SCSI driver HA context
228 * @mb0: Mailbox0 register
229 */
230static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800231qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
233 uint16_t cnt;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800234 uint32_t mboxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800236 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700237 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800239 /* Read all mbox registers? */
240 mboxes = (1 << ha->mbx_count) - 1;
241 if (!ha->mcp)
Masanari Iidaa7201012012-11-21 02:40:42 -0500242 ql_dbg(ql_dbg_async, vha, 0x5001, "MBX pointer ERROR.\n");
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800243 else
244 mboxes = ha->mcp->in_mb;
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 /* Load return mailbox registers. */
247 ha->flags.mbox_int = 1;
248 ha->mailbox_out[0] = mb0;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800249 mboxes >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
251
252 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700253 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800255 if ((cnt == 4 || cnt == 5) && (mboxes & BIT_0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800257 else if (mboxes & BIT_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 wptr++;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800261 mboxes >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263}
264
Andrew Vasquez8a659572009-02-08 20:50:12 -0800265static void
266qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
267{
268 static char *event[] =
269 { "Complete", "Request Notification", "Time Extension" };
270 int rval;
271 struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
272 uint16_t __iomem *wptr;
273 uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
274
275 /* Seed data -- mailbox1 -> mailbox7. */
276 wptr = (uint16_t __iomem *)&reg24->mailbox1;
277 for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
278 mb[cnt] = RD_REG_WORD(wptr);
279
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700280 ql_dbg(ql_dbg_async, vha, 0x5021,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800281 "Inter-Driver Communication %s -- "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700282 "%04x %04x %04x %04x %04x %04x %04x.\n",
283 event[aen & 0xff], mb[0], mb[1], mb[2], mb[3],
284 mb[4], mb[5], mb[6]);
Santosh Vernekar454073c2013-08-27 01:37:48 -0400285 switch (aen) {
286 /* Handle IDC Error completion case. */
287 case MBA_IDC_COMPLETE:
288 if (mb[1] >> 15) {
289 vha->hw->flags.idc_compl_status = 1;
290 if (vha->hw->notify_dcbx_comp)
291 complete(&vha->hw->dcbx_comp);
292 }
293 break;
294
295 case MBA_IDC_NOTIFY:
296 /* Acknowledgement needed? [Notify && non-zero timeout]. */
297 timeout = (descr >> 8) & 0xf;
298 ql_dbg(ql_dbg_async, vha, 0x5022,
299 "%lu Inter-Driver Communication %s -- ACK timeout=%d.\n",
300 vha->host_no, event[aen & 0xff], timeout);
301
302 if (!timeout)
303 return;
304 rval = qla2x00_post_idc_ack_work(vha, mb);
305 if (rval != QLA_SUCCESS)
306 ql_log(ql_log_warn, vha, 0x5023,
307 "IDC failed to post ACK.\n");
308 break;
309 case MBA_IDC_TIME_EXT:
310 vha->hw->idc_extend_tmo = descr;
311 ql_dbg(ql_dbg_async, vha, 0x5087,
312 "%lu Inter-Driver Communication %s -- "
313 "Extend timeout by=%d.\n",
314 vha->host_no, event[aen & 0xff], vha->hw->idc_extend_tmo);
315 break;
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400316 }
Andrew Vasquez8a659572009-02-08 20:50:12 -0800317}
318
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400319#define LS_UNKNOWN 2
Joe Carnucciod0297c92012-11-21 02:40:40 -0500320const char *
321qla2x00_get_link_speed_str(struct qla_hw_data *ha, uint16_t speed)
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400322{
Joe Carnucciod0297c92012-11-21 02:40:40 -0500323 static const char * const link_speeds[] = {
324 "1", "2", "?", "4", "8", "16", "10"
325 };
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400326
327 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Joe Carnucciod0297c92012-11-21 02:40:40 -0500328 return link_speeds[0];
329 else if (speed == 0x13)
330 return link_speeds[6];
331 else if (speed < 6)
332 return link_speeds[speed];
333 else
334 return link_speeds[LS_UNKNOWN];
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400335}
336
Saurav Kashyapfa492632012-11-21 02:40:29 -0500337static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400338qla83xx_handle_8200_aen(scsi_qla_host_t *vha, uint16_t *mb)
339{
340 struct qla_hw_data *ha = vha->hw;
341
342 /*
343 * 8200 AEN Interpretation:
344 * mb[0] = AEN code
345 * mb[1] = AEN Reason code
346 * mb[2] = LSW of Peg-Halt Status-1 Register
347 * mb[6] = MSW of Peg-Halt Status-1 Register
348 * mb[3] = LSW of Peg-Halt Status-2 register
349 * mb[7] = MSW of Peg-Halt Status-2 register
350 * mb[4] = IDC Device-State Register value
351 * mb[5] = IDC Driver-Presence Register value
352 */
353 ql_dbg(ql_dbg_async, vha, 0x506b, "AEN Code: mb[0] = 0x%x AEN reason: "
354 "mb[1] = 0x%x PH-status1: mb[2] = 0x%x PH-status1: mb[6] = 0x%x.\n",
355 mb[0], mb[1], mb[2], mb[6]);
356 ql_dbg(ql_dbg_async, vha, 0x506c, "PH-status2: mb[3] = 0x%x "
357 "PH-status2: mb[7] = 0x%x Device-State: mb[4] = 0x%x "
358 "Drv-Presence: mb[5] = 0x%x.\n", mb[3], mb[7], mb[4], mb[5]);
359
360 if (mb[1] & (IDC_PEG_HALT_STATUS_CHANGE | IDC_NIC_FW_REPORTED_FAILURE |
361 IDC_HEARTBEAT_FAILURE)) {
362 ha->flags.nic_core_hung = 1;
363 ql_log(ql_log_warn, vha, 0x5060,
364 "83XX: F/W Error Reported: Check if reset required.\n");
365
366 if (mb[1] & IDC_PEG_HALT_STATUS_CHANGE) {
367 uint32_t protocol_engine_id, fw_err_code, err_level;
368
369 /*
370 * IDC_PEG_HALT_STATUS_CHANGE interpretation:
371 * - PEG-Halt Status-1 Register:
372 * (LSW = mb[2], MSW = mb[6])
373 * Bits 0-7 = protocol-engine ID
374 * Bits 8-28 = f/w error code
375 * Bits 29-31 = Error-level
376 * Error-level 0x1 = Non-Fatal error
377 * Error-level 0x2 = Recoverable Fatal error
378 * Error-level 0x4 = UnRecoverable Fatal error
379 * - PEG-Halt Status-2 Register:
380 * (LSW = mb[3], MSW = mb[7])
381 */
382 protocol_engine_id = (mb[2] & 0xff);
383 fw_err_code = (((mb[2] & 0xff00) >> 8) |
384 ((mb[6] & 0x1fff) << 8));
385 err_level = ((mb[6] & 0xe000) >> 13);
386 ql_log(ql_log_warn, vha, 0x5061, "PegHalt Status-1 "
387 "Register: protocol_engine_id=0x%x "
388 "fw_err_code=0x%x err_level=0x%x.\n",
389 protocol_engine_id, fw_err_code, err_level);
390 ql_log(ql_log_warn, vha, 0x5062, "PegHalt Status-2 "
391 "Register: 0x%x%x.\n", mb[7], mb[3]);
392 if (err_level == ERR_LEVEL_NON_FATAL) {
393 ql_log(ql_log_warn, vha, 0x5063,
394 "Not a fatal error, f/w has recovered "
395 "iteself.\n");
396 } else if (err_level == ERR_LEVEL_RECOVERABLE_FATAL) {
397 ql_log(ql_log_fatal, vha, 0x5064,
398 "Recoverable Fatal error: Chip reset "
399 "required.\n");
400 qla83xx_schedule_work(vha,
401 QLA83XX_NIC_CORE_RESET);
402 } else if (err_level == ERR_LEVEL_UNRECOVERABLE_FATAL) {
403 ql_log(ql_log_fatal, vha, 0x5065,
404 "Unrecoverable Fatal error: Set FAILED "
405 "state, reboot required.\n");
406 qla83xx_schedule_work(vha,
407 QLA83XX_NIC_CORE_UNRECOVERABLE);
408 }
409 }
410
411 if (mb[1] & IDC_NIC_FW_REPORTED_FAILURE) {
412 uint16_t peg_fw_state, nw_interface_link_up;
413 uint16_t nw_interface_signal_detect, sfp_status;
414 uint16_t htbt_counter, htbt_monitor_enable;
415 uint16_t sfp_additonal_info, sfp_multirate;
416 uint16_t sfp_tx_fault, link_speed, dcbx_status;
417
418 /*
419 * IDC_NIC_FW_REPORTED_FAILURE interpretation:
420 * - PEG-to-FC Status Register:
421 * (LSW = mb[2], MSW = mb[6])
422 * Bits 0-7 = Peg-Firmware state
423 * Bit 8 = N/W Interface Link-up
424 * Bit 9 = N/W Interface signal detected
425 * Bits 10-11 = SFP Status
426 * SFP Status 0x0 = SFP+ transceiver not expected
427 * SFP Status 0x1 = SFP+ transceiver not present
428 * SFP Status 0x2 = SFP+ transceiver invalid
429 * SFP Status 0x3 = SFP+ transceiver present and
430 * valid
431 * Bits 12-14 = Heartbeat Counter
432 * Bit 15 = Heartbeat Monitor Enable
433 * Bits 16-17 = SFP Additional Info
434 * SFP info 0x0 = Unregocnized transceiver for
435 * Ethernet
436 * SFP info 0x1 = SFP+ brand validation failed
437 * SFP info 0x2 = SFP+ speed validation failed
438 * SFP info 0x3 = SFP+ access error
439 * Bit 18 = SFP Multirate
440 * Bit 19 = SFP Tx Fault
441 * Bits 20-22 = Link Speed
442 * Bits 23-27 = Reserved
443 * Bits 28-30 = DCBX Status
444 * DCBX Status 0x0 = DCBX Disabled
445 * DCBX Status 0x1 = DCBX Enabled
446 * DCBX Status 0x2 = DCBX Exchange error
447 * Bit 31 = Reserved
448 */
449 peg_fw_state = (mb[2] & 0x00ff);
450 nw_interface_link_up = ((mb[2] & 0x0100) >> 8);
451 nw_interface_signal_detect = ((mb[2] & 0x0200) >> 9);
452 sfp_status = ((mb[2] & 0x0c00) >> 10);
453 htbt_counter = ((mb[2] & 0x7000) >> 12);
454 htbt_monitor_enable = ((mb[2] & 0x8000) >> 15);
455 sfp_additonal_info = (mb[6] & 0x0003);
456 sfp_multirate = ((mb[6] & 0x0004) >> 2);
457 sfp_tx_fault = ((mb[6] & 0x0008) >> 3);
458 link_speed = ((mb[6] & 0x0070) >> 4);
459 dcbx_status = ((mb[6] & 0x7000) >> 12);
460
461 ql_log(ql_log_warn, vha, 0x5066,
462 "Peg-to-Fc Status Register:\n"
463 "peg_fw_state=0x%x, nw_interface_link_up=0x%x, "
464 "nw_interface_signal_detect=0x%x"
465 "\nsfp_statis=0x%x.\n ", peg_fw_state,
466 nw_interface_link_up, nw_interface_signal_detect,
467 sfp_status);
468 ql_log(ql_log_warn, vha, 0x5067,
469 "htbt_counter=0x%x, htbt_monitor_enable=0x%x, "
470 "sfp_additonal_info=0x%x, sfp_multirate=0x%x.\n ",
471 htbt_counter, htbt_monitor_enable,
472 sfp_additonal_info, sfp_multirate);
473 ql_log(ql_log_warn, vha, 0x5068,
474 "sfp_tx_fault=0x%x, link_state=0x%x, "
475 "dcbx_status=0x%x.\n", sfp_tx_fault, link_speed,
476 dcbx_status);
477
478 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
479 }
480
481 if (mb[1] & IDC_HEARTBEAT_FAILURE) {
482 ql_log(ql_log_warn, vha, 0x5069,
483 "Heartbeat Failure encountered, chip reset "
484 "required.\n");
485
486 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
487 }
488 }
489
490 if (mb[1] & IDC_DEVICE_STATE_CHANGE) {
491 ql_log(ql_log_info, vha, 0x506a,
492 "IDC Device-State changed = 0x%x.\n", mb[4]);
Saurav Kashyap6c3943c2013-02-08 01:58:02 -0500493 if (ha->flags.nic_core_reset_owner)
494 return;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400495 qla83xx_schedule_work(vha, MBA_IDC_AEN);
496 }
497}
498
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -0500499int
500qla2x00_is_a_vp_did(scsi_qla_host_t *vha, uint32_t rscn_entry)
501{
502 struct qla_hw_data *ha = vha->hw;
503 scsi_qla_host_t *vp;
504 uint32_t vp_did;
505 unsigned long flags;
506 int ret = 0;
507
508 if (!ha->num_vhosts)
509 return ret;
510
511 spin_lock_irqsave(&ha->vport_slock, flags);
512 list_for_each_entry(vp, &ha->vp_list, list) {
513 vp_did = vp->d_id.b24;
514 if (vp_did == rscn_entry) {
515 ret = 1;
516 break;
517 }
518 }
519 spin_unlock_irqrestore(&ha->vport_slock, flags);
520
521 return ret;
522}
523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524/**
525 * qla2x00_async_event() - Process aynchronous events.
526 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700527 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700529void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800530qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 uint16_t handle_cnt;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700533 uint16_t cnt, mbx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 uint32_t handles[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800535 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700536 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700537 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
Andrew Vasquezbc5c2aa2010-12-21 16:00:24 -0800538 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 uint32_t rscn_entry, host_pid;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700540 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
542 /* Setup to process RIO completion. */
543 handle_cnt = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800544 if (IS_CNA_CAPABLE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800545 goto skip_rio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 switch (mb[0]) {
547 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700548 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 handle_cnt = 1;
550 break;
551 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700552 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 handle_cnt = 1;
554 mb[0] = MBA_SCSI_COMPLETION;
555 break;
556 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700557 handles[0] = mb[1];
558 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 handle_cnt = 2;
560 mb[0] = MBA_SCSI_COMPLETION;
561 break;
562 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700563 handles[0] = mb[1];
564 handles[1] = mb[2];
565 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 handle_cnt = 3;
567 mb[0] = MBA_SCSI_COMPLETION;
568 break;
569 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700570 handles[0] = mb[1];
571 handles[1] = mb[2];
572 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
574 handle_cnt = 4;
575 mb[0] = MBA_SCSI_COMPLETION;
576 break;
577 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700578 handles[0] = mb[1];
579 handles[1] = mb[2];
580 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
582 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
583 handle_cnt = 5;
584 mb[0] = MBA_SCSI_COMPLETION;
585 break;
586 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700587 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 handles[1] = le32_to_cpu(
589 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
590 RD_MAILBOX_REG(ha, reg, 6));
591 handle_cnt = 2;
592 mb[0] = MBA_SCSI_COMPLETION;
593 break;
594 default:
595 break;
596 }
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800597skip_rio:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 switch (mb[0]) {
599 case MBA_SCSI_COMPLETION: /* Fast Post */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800600 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 break;
602
603 for (cnt = 0; cnt < handle_cnt; cnt++)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800604 qla2x00_process_completed_request(vha, rsp->req,
605 handles[cnt]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 break;
607
608 case MBA_RESET: /* Reset */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700609 ql_dbg(ql_dbg_async, vha, 0x5002,
610 "Asynchronous RESET.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800612 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 break;
614
615 case MBA_SYSTEM_ERR: /* System Error */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800616 mbx = (IS_QLA81XX(ha) || IS_QLA83XX(ha)) ?
617 RD_REG_WORD(&reg24->mailbox7) : 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700618 ql_log(ql_log_warn, vha, 0x5003,
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700619 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh "
620 "mbx7=%xh.\n", mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800622 ha->isp_ops->fw_dump(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
Andrew Vasqueze4289242007-07-19 15:05:56 -0700624 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700625 if (mb[1] == 0 && mb[2] == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700626 ql_log(ql_log_fatal, vha, 0x5004,
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700627 "Unrecoverable Hardware Error: adapter "
628 "marked OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800629 vha->flags.online = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800630 vha->device_flags |= DFLG_DEV_FAILED;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700631 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300632 /* Check to see if MPI timeout occurred */
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700633 if ((mbx & MBX_3) && (ha->flags.port0))
634 set_bit(MPI_RESET_NEEDED,
635 &vha->dpc_flags);
636
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800637 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700638 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700639 } else if (mb[1] == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700640 ql_log(ql_log_fatal, vha, 0x5005,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 "Unrecoverable Hardware Error: adapter marked "
642 "OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800643 vha->flags.online = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800644 vha->device_flags |= DFLG_DEV_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800646 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 break;
648
649 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700650 ql_log(ql_log_warn, vha, 0x5006,
651 "ISP Request Transfer Error (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800653 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 break;
655
656 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700657 ql_log(ql_log_warn, vha, 0x5007,
658 "ISP Response Transfer Error.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800660 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 break;
662
663 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700664 ql_dbg(ql_dbg_async, vha, 0x5008,
665 "Asynchronous WAKEUP_THRES.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400667 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Chad Dupuiscfb09192011-11-18 09:03:07 -0800669 ql_dbg(ql_dbg_async, vha, 0x5009,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700670 "LIP occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800672 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
673 atomic_set(&vha->loop_state, LOOP_DOWN);
674 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
675 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 }
677
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800678 if (vha->vp_idx) {
679 atomic_set(&vha->vp_state, VP_FAILED);
680 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700681 }
682
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800683 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
684 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800686 vha->flags.management_server_logged_in = 0;
687 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 break;
689
690 case MBA_LOOP_UP: /* Loop Up Event */
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400691 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700692 ha->link_data_rate = PORT_SPEED_1GB;
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400693 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 ha->link_data_rate = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Chad Dupuiscfb09192011-11-18 09:03:07 -0800696 ql_dbg(ql_dbg_async, vha, 0x500a,
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400697 "LOOP UP detected (%s Gbps).\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -0500698 qla2x00_get_link_speed_str(ha, ha->link_data_rate));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800700 vha->flags.management_server_logged_in = 0;
701 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 break;
703
704 case MBA_LOOP_DOWN: /* Loop Down Event */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800705 mbx = (IS_QLA81XX(ha) || IS_QLA8031(ha))
706 ? RD_REG_WORD(&reg24->mailbox4) : 0;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400707 mbx = (IS_P3P_TYPE(ha)) ? RD_REG_WORD(&reg82->mailbox_out[4])
708 : mbx;
Chad Dupuiscfb09192011-11-18 09:03:07 -0800709 ql_dbg(ql_dbg_async, vha, 0x500b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700710 "LOOP DOWN detected (%x %x %x %x).\n",
711 mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800713 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
714 atomic_set(&vha->loop_state, LOOP_DOWN);
715 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
716 vha->device_flags |= DFLG_NO_CABLE;
717 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 }
719
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800720 if (vha->vp_idx) {
721 atomic_set(&vha->vp_state, VP_FAILED);
722 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700723 }
724
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800725 vha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700726 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800727 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 break;
729
730 case MBA_LIP_RESET: /* LIP reset occurred */
Chad Dupuiscfb09192011-11-18 09:03:07 -0800731 ql_dbg(ql_dbg_async, vha, 0x500c,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700732 "LIP reset occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800734 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
735 atomic_set(&vha->loop_state, LOOP_DOWN);
736 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
737 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 }
739
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800740 if (vha->vp_idx) {
741 atomic_set(&vha->vp_state, VP_FAILED);
742 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700743 }
744
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800745 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747 ha->operating_mode = LOOP;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800748 vha->flags.management_server_logged_in = 0;
749 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 break;
751
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800752 /* case MBA_DCBX_COMPLETE: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 case MBA_POINT_TO_POINT: /* Point-to-Point */
754 if (IS_QLA2100(ha))
755 break;
756
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400757 if (IS_CNA_CAPABLE(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700758 ql_dbg(ql_dbg_async, vha, 0x500d,
759 "DCBX Completed -- %04x %04x %04x.\n",
760 mb[1], mb[2], mb[3]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700761 if (ha->notify_dcbx_comp)
762 complete(&ha->dcbx_comp);
763
764 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700765 ql_dbg(ql_dbg_async, vha, 0x500e,
766 "Asynchronous P2P MODE received.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
768 /*
769 * Until there's a transition from loop down to loop up, treat
770 * this as loop down only.
771 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800772 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
773 atomic_set(&vha->loop_state, LOOP_DOWN);
774 if (!atomic_read(&vha->loop_down_timer))
775 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800777 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 }
779
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800780 if (vha->vp_idx) {
781 atomic_set(&vha->vp_state, VP_FAILED);
782 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700783 }
784
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800785 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
786 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
787
788 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
789 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800790
791 ha->flags.gpsc_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800792 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 break;
794
795 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
796 if (IS_QLA2100(ha))
797 break;
798
Chad Dupuiscfb09192011-11-18 09:03:07 -0800799 ql_dbg(ql_dbg_async, vha, 0x500f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 "Configuration change detected: value=%x.\n", mb[1]);
801
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800802 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
803 atomic_set(&vha->loop_state, LOOP_DOWN);
804 if (!atomic_read(&vha->loop_down_timer))
805 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800807 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 }
809
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800810 if (vha->vp_idx) {
811 atomic_set(&vha->vp_state, VP_FAILED);
812 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700813 }
814
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800815 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
816 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 break;
818
819 case MBA_PORT_UPDATE: /* Port database update */
Santosh Vernekar55903b92009-07-31 15:09:25 -0700820 /*
821 * Handle only global and vn-port update events
822 *
823 * Relevant inputs:
824 * mb[1] = N_Port handle of changed port
825 * OR 0xffff for global event
826 * mb[2] = New login state
827 * 7 = Port logged out
828 * mb[3] = LSB is vp_idx, 0xff = all vps
829 *
830 * Skip processing if:
831 * Event is global, vp_idx is NOT all vps,
832 * vp_idx does not match
833 * Event is not global, vp_idx does not match
834 */
Andrew Vasquez12cec63e42010-03-19 16:59:17 -0700835 if (IS_QLA2XXX_MIDTYPE(ha) &&
836 ((mb[1] == 0xffff && (mb[3] & 0xff) != 0xff) ||
837 (mb[1] != 0xffff)) && vha->vp_idx != (mb[3] & 0xff))
838 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800839
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700840 /* Global event -- port logout or port unavailable. */
841 if (mb[1] == 0xffff && mb[2] == 0x7) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700842 ql_dbg(ql_dbg_async, vha, 0x5010,
843 "Port unavailable %04x %04x %04x.\n",
844 mb[1], mb[2], mb[3]);
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400845 ql_log(ql_log_warn, vha, 0x505e,
846 "Link is offline.\n");
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700847
848 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
849 atomic_set(&vha->loop_state, LOOP_DOWN);
850 atomic_set(&vha->loop_down_timer,
851 LOOP_DOWN_TIME);
852 vha->device_flags |= DFLG_NO_CABLE;
853 qla2x00_mark_all_devices_lost(vha, 1);
854 }
855
856 if (vha->vp_idx) {
857 atomic_set(&vha->vp_state, VP_FAILED);
858 fc_vport_set_state(vha->fc_vport,
859 FC_VPORT_FAILED);
Santosh Vernekarfaadc5e2009-07-31 15:09:26 -0700860 qla2x00_mark_all_devices_lost(vha, 1);
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700861 }
862
863 vha->flags.management_server_logged_in = 0;
864 ha->link_data_rate = PORT_SPEED_UNKNOWN;
865 break;
866 }
867
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 /*
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700869 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 * event etc. earlier indicating loop is down) then process
871 * it. Otherwise ignore it and Wait for RSCN to come in.
872 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800873 atomic_set(&vha->loop_down_timer, 0);
Chad Dupuis79cc7852012-08-22 14:21:09 -0400874 if (mb[1] != 0xffff || (mb[2] != 0x6 && mb[2] != 0x4)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700875 ql_dbg(ql_dbg_async, vha, 0x5011,
876 "Asynchronous PORT UPDATE ignored %04x/%04x/%04x.\n",
877 mb[1], mb[2], mb[3]);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400878
879 qlt_async_event(mb[0], vha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 break;
881 }
882
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700883 ql_dbg(ql_dbg_async, vha, 0x5012,
884 "Port database changed %04x %04x %04x.\n",
885 mb[1], mb[2], mb[3]);
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400886 ql_log(ql_log_warn, vha, 0x505f,
887 "Link is operational (%s Gbps).\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -0500888 qla2x00_get_link_speed_str(ha, ha->link_data_rate));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890 /*
891 * Mark all devices as missing so we will login again.
892 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800893 atomic_set(&vha->loop_state, LOOP_UP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800895 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400897 if (vha->vp_idx == 0 && !qla_ini_mode_enabled(vha))
898 set_bit(SCR_PENDING, &vha->dpc_flags);
899
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800900 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
901 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400902
903 qlt_async_event(mb[0], vha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 break;
905
906 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju3c397402008-05-19 14:25:39 -0700907 /* Check if the Vport has issued a SCR */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800908 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
Seokmann Ju3c397402008-05-19 14:25:39 -0700909 break;
910 /* Only handle SCNs for our Vport index. */
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700911 if (ha->flags.npiv_supported && vha->vp_idx != (mb[3] & 0xff))
Seokmann Ju3c397402008-05-19 14:25:39 -0700912 break;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700913
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700914 ql_dbg(ql_dbg_async, vha, 0x5013,
915 "RSCN database changed -- %04x %04x %04x.\n",
916 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
Ravi Anand59d72d82008-09-11 21:22:53 -0700918 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800919 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
920 | vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 if (rscn_entry == host_pid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700922 ql_dbg(ql_dbg_async, vha, 0x5014,
923 "Ignoring RSCN update to local host "
924 "port ID (%06x).\n", host_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 break;
926 }
927
Ravi Anand59d72d82008-09-11 21:22:53 -0700928 /* Ignore reserved bits from RSCN-payload. */
929 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -0500931 /* Skip RSCNs for virtual ports on the same physical port */
932 if (qla2x00_is_a_vp_did(vha, rscn_entry))
933 break;
934
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800935 atomic_set(&vha->loop_down_timer, 0);
936 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800938 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
939 set_bit(RSCN_UPDATE, &vha->dpc_flags);
940 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 break;
942
943 /* case MBA_RIO_RESPONSE: */
944 case MBA_ZIO_RESPONSE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700945 ql_dbg(ql_dbg_async, vha, 0x5015,
946 "[R|Z]IO update completion.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
Andrew Vasqueze4289242007-07-19 15:05:56 -0700948 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700949 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700950 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800951 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700953
954 case MBA_DISCARD_RND_FRAME:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700955 ql_dbg(ql_dbg_async, vha, 0x5016,
956 "Discard RND Frame -- %04x %04x %04x.\n",
957 mb[1], mb[2], mb[3]);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700958 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700959
960 case MBA_TRACE_NOTIFICATION:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700961 ql_dbg(ql_dbg_async, vha, 0x5017,
962 "Trace Notification -- %04x %04x.\n", mb[1], mb[2]);
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700963 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700964
965 case MBA_ISP84XX_ALERT:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700966 ql_dbg(ql_dbg_async, vha, 0x5018,
967 "ISP84XX Alert Notification -- %04x %04x %04x.\n",
968 mb[1], mb[2], mb[3]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700969
970 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
971 switch (mb[1]) {
972 case A84_PANIC_RECOVERY:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700973 ql_log(ql_log_info, vha, 0x5019,
974 "Alert 84XX: panic recovery %04x %04x.\n",
975 mb[2], mb[3]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700976 break;
977 case A84_OP_LOGIN_COMPLETE:
978 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700979 ql_log(ql_log_info, vha, 0x501a,
980 "Alert 84XX: firmware version %x.\n",
981 ha->cs84xx->op_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700982 break;
983 case A84_DIAG_LOGIN_COMPLETE:
984 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700985 ql_log(ql_log_info, vha, 0x501b,
986 "Alert 84XX: diagnostic firmware version %x.\n",
987 ha->cs84xx->diag_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700988 break;
989 case A84_GOLD_LOGIN_COMPLETE:
990 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
991 ha->cs84xx->fw_update = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700992 ql_log(ql_log_info, vha, 0x501c,
993 "Alert 84XX: gold firmware version %x.\n",
994 ha->cs84xx->gold_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700995 break;
996 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700997 ql_log(ql_log_warn, vha, 0x501d,
998 "Alert 84xx: Invalid Alert %04x %04x %04x.\n",
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700999 mb[1], mb[2], mb[3]);
1000 }
1001 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
1002 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001003 case MBA_DCBX_START:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001004 ql_dbg(ql_dbg_async, vha, 0x501e,
1005 "DCBX Started -- %04x %04x %04x.\n",
1006 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001007 break;
1008 case MBA_DCBX_PARAM_UPDATE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001009 ql_dbg(ql_dbg_async, vha, 0x501f,
1010 "DCBX Parameters Updated -- %04x %04x %04x.\n",
1011 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001012 break;
1013 case MBA_FCF_CONF_ERR:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001014 ql_dbg(ql_dbg_async, vha, 0x5020,
1015 "FCF Configuration Error -- %04x %04x %04x.\n",
1016 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001017 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001018 case MBA_IDC_NOTIFY:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001019 if (IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
Chad Dupuis67b2a312013-02-08 01:57:51 -05001020 mb[4] = RD_REG_WORD(&reg24->mailbox4);
1021 if (((mb[2] & 0x7fff) == MBC_PORT_RESET ||
1022 (mb[2] & 0x7fff) == MBC_SET_PORT_CONFIG) &&
1023 (mb[4] & INTERNAL_LOOPBACK_MASK) != 0) {
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04001024 set_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags);
Chad Dupuis67b2a312013-02-08 01:57:51 -05001025 /*
1026 * Extend loop down timer since port is active.
1027 */
1028 if (atomic_read(&vha->loop_state) == LOOP_DOWN)
1029 atomic_set(&vha->loop_down_timer,
1030 LOOP_DOWN_TIME);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04001031 qla2xxx_wake_dpc(vha);
1032 }
Chad Dupuis67b2a312013-02-08 01:57:51 -05001033 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04001034 case MBA_IDC_COMPLETE:
Chad Dupuisf356bef2013-02-08 01:58:04 -05001035 if (ha->notify_lb_portup_comp)
1036 complete(&ha->lb_portup_comp);
1037 /* Fallthru */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001038 case MBA_IDC_TIME_EXT:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001039 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) ||
1040 IS_QLA8044(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001041 qla81xx_idc_event(vha, mb[0], mb[1]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001042 break;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001043
1044 case MBA_IDC_AEN:
1045 mb[4] = RD_REG_WORD(&reg24->mailbox4);
1046 mb[5] = RD_REG_WORD(&reg24->mailbox5);
1047 mb[6] = RD_REG_WORD(&reg24->mailbox6);
1048 mb[7] = RD_REG_WORD(&reg24->mailbox7);
1049 qla83xx_handle_8200_aen(vha, mb);
1050 break;
1051
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001052 default:
1053 ql_dbg(ql_dbg_async, vha, 0x5057,
1054 "Unknown AEN:%04x %04x %04x %04x\n",
1055 mb[0], mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001057
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001058 qlt_async_event(mb[0], vha, mb);
1059
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001060 if (!vha->vp_idx && ha->num_vhosts)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001061 qla2x00_alert_all_vps(rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062}
1063
1064/**
1065 * qla2x00_process_completed_request() - Process a Fast Post response.
1066 * @ha: SCSI driver HA context
1067 * @index: SRB index
1068 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001069void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001070qla2x00_process_completed_request(struct scsi_qla_host *vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001071 struct req_que *req, uint32_t index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072{
1073 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001074 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
1076 /* Validate handle. */
Chad Dupuis8d93f552013-01-30 03:34:37 -05001077 if (index >= req->num_outstanding_cmds) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001078 ql_log(ql_log_warn, vha, 0x3014,
1079 "Invalid SCSI command index (%x).\n", index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001081 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001082 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1083 else
1084 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 return;
1086 }
1087
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001088 sp = req->outstanding_cmds[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 if (sp) {
1090 /* Free outstanding command slot. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001091 req->outstanding_cmds[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 /* Save ISP completion status */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001094 sp->done(ha, sp, DID_OK << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001096 ql_log(ql_log_warn, vha, 0x3016, "Invalid SCSI SRB.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001098 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001099 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1100 else
1101 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 }
1103}
1104
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001105srb_t *
Andrew Vasquezac280b62009-08-20 11:06:05 -07001106qla2x00_get_sp_from_handle(scsi_qla_host_t *vha, const char *func,
1107 struct req_que *req, void *iocb)
1108{
1109 struct qla_hw_data *ha = vha->hw;
1110 sts_entry_t *pkt = iocb;
1111 srb_t *sp = NULL;
1112 uint16_t index;
1113
1114 index = LSW(pkt->handle);
Chad Dupuis8d93f552013-01-30 03:34:37 -05001115 if (index >= req->num_outstanding_cmds) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001116 ql_log(ql_log_warn, vha, 0x5031,
1117 "Invalid command index (%x).\n", index);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001118 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001119 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1120 else
1121 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001122 goto done;
1123 }
1124 sp = req->outstanding_cmds[index];
1125 if (!sp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001126 ql_log(ql_log_warn, vha, 0x5032,
1127 "Invalid completion handle (%x) -- timed-out.\n", index);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001128 return sp;
1129 }
1130 if (sp->handle != index) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001131 ql_log(ql_log_warn, vha, 0x5033,
1132 "SRB handle (%x) mismatch %x.\n", sp->handle, index);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001133 return NULL;
1134 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001135
Andrew Vasquezac280b62009-08-20 11:06:05 -07001136 req->outstanding_cmds[index] = NULL;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001137
Andrew Vasquezac280b62009-08-20 11:06:05 -07001138done:
1139 return sp;
1140}
1141
1142static void
1143qla2x00_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1144 struct mbx_entry *mbx)
1145{
1146 const char func[] = "MBX-IOCB";
1147 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001148 fc_port_t *fcport;
1149 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001150 struct srb_iocb *lio;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001151 uint16_t *data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001152 uint16_t status;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001153
1154 sp = qla2x00_get_sp_from_handle(vha, func, req, mbx);
1155 if (!sp)
1156 return;
1157
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001158 lio = &sp->u.iocb_cmd;
1159 type = sp->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001160 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001161 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001162
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001163 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001164 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001165 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001166 if (mbx->entry_status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001167 ql_dbg(ql_dbg_async, vha, 0x5043,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001168 "Async-%s error entry - hdl=%x portid=%02x%02x%02x "
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001169 "entry-status=%x status=%x state-flag=%x "
Chad Dupuiscfb09192011-11-18 09:03:07 -08001170 "status-flags=%x.\n", type, sp->handle,
1171 fcport->d_id.b.domain, fcport->d_id.b.area,
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001172 fcport->d_id.b.al_pa, mbx->entry_status,
1173 le16_to_cpu(mbx->status), le16_to_cpu(mbx->state_flags),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001174 le16_to_cpu(mbx->status_flags));
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001175
Chad Dupuiscfb09192011-11-18 09:03:07 -08001176 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5029,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001177 (uint8_t *)mbx, sizeof(*mbx));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001178
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001179 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001180 }
1181
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001182 status = le16_to_cpu(mbx->status);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001183 if (status == 0x30 && sp->type == SRB_LOGIN_CMD &&
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001184 le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE)
1185 status = 0;
1186 if (!status && le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001187 ql_dbg(ql_dbg_async, vha, 0x5045,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001188 "Async-%s complete - hdl=%x portid=%02x%02x%02x mbx1=%x.\n",
1189 type, sp->handle, fcport->d_id.b.domain,
1190 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1191 le16_to_cpu(mbx->mb1));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001192
1193 data[0] = MBS_COMMAND_COMPLETE;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001194 if (sp->type == SRB_LOGIN_CMD) {
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001195 fcport->port_type = FCT_TARGET;
1196 if (le16_to_cpu(mbx->mb1) & BIT_0)
1197 fcport->port_type = FCT_INITIATOR;
Andrew Vasquez6ac52602010-05-28 15:08:19 -07001198 else if (le16_to_cpu(mbx->mb1) & BIT_1)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001199 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001200 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001201 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001202 }
1203
1204 data[0] = le16_to_cpu(mbx->mb0);
1205 switch (data[0]) {
1206 case MBS_PORT_ID_USED:
1207 data[1] = le16_to_cpu(mbx->mb1);
1208 break;
1209 case MBS_LOOP_ID_USED:
1210 break;
1211 default:
1212 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001213 break;
1214 }
1215
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001216 ql_log(ql_log_warn, vha, 0x5046,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001217 "Async-%s failed - hdl=%x portid=%02x%02x%02x status=%x "
1218 "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n", type, sp->handle,
1219 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
1220 status, le16_to_cpu(mbx->mb0), le16_to_cpu(mbx->mb1),
Andrew Vasquezac280b62009-08-20 11:06:05 -07001221 le16_to_cpu(mbx->mb2), le16_to_cpu(mbx->mb6),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001222 le16_to_cpu(mbx->mb7));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001223
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001224logio_done:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001225 sp->done(vha, sp, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001226}
1227
1228static void
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001229qla2x00_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1230 sts_entry_t *pkt, int iocb_type)
1231{
1232 const char func[] = "CT_IOCB";
1233 const char *type;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001234 srb_t *sp;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001235 struct fc_bsg_job *bsg_job;
1236 uint16_t comp_status;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001237 int res;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001238
1239 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1240 if (!sp)
1241 return;
1242
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001243 bsg_job = sp->u.bsg_job;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001244
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001245 type = "ct pass-through";
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001246
1247 comp_status = le16_to_cpu(pkt->comp_status);
1248
1249 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1250 * fc payload to the caller
1251 */
1252 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1253 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1254
1255 if (comp_status != CS_COMPLETE) {
1256 if (comp_status == CS_DATA_UNDERRUN) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001257 res = DID_OK << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001258 bsg_job->reply->reply_payload_rcv_len =
1259 le16_to_cpu(((sts_entry_t *)pkt)->rsp_info_len);
1260
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001261 ql_log(ql_log_warn, vha, 0x5048,
1262 "CT pass-through-%s error "
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001263 "comp_status-status=0x%x total_byte = 0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001264 type, comp_status,
1265 bsg_job->reply->reply_payload_rcv_len);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001266 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001267 ql_log(ql_log_warn, vha, 0x5049,
1268 "CT pass-through-%s error "
1269 "comp_status-status=0x%x.\n", type, comp_status);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001270 res = DID_ERROR << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001271 bsg_job->reply->reply_payload_rcv_len = 0;
1272 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001273 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5035,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001274 (uint8_t *)pkt, sizeof(*pkt));
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001275 } else {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001276 res = DID_OK << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001277 bsg_job->reply->reply_payload_rcv_len =
1278 bsg_job->reply_payload.payload_len;
1279 bsg_job->reply_len = 0;
1280 }
1281
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001282 sp->done(vha, sp, res);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001283}
1284
1285static void
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001286qla24xx_els_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1287 struct sts_entry_24xx *pkt, int iocb_type)
1288{
1289 const char func[] = "ELS_CT_IOCB";
1290 const char *type;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001291 srb_t *sp;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001292 struct fc_bsg_job *bsg_job;
1293 uint16_t comp_status;
1294 uint32_t fw_status[3];
1295 uint8_t* fw_sts_ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001296 int res;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001297
1298 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1299 if (!sp)
1300 return;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001301 bsg_job = sp->u.bsg_job;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001302
1303 type = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001304 switch (sp->type) {
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001305 case SRB_ELS_CMD_RPT:
1306 case SRB_ELS_CMD_HST:
1307 type = "els";
1308 break;
1309 case SRB_CT_CMD:
1310 type = "ct pass-through";
1311 break;
1312 default:
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001313 ql_dbg(ql_dbg_user, vha, 0x503e,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001314 "Unrecognized SRB: (%p) type=%d.\n", sp, sp->type);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001315 return;
1316 }
1317
1318 comp_status = fw_status[0] = le16_to_cpu(pkt->comp_status);
1319 fw_status[1] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1);
1320 fw_status[2] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2);
1321
1322 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1323 * fc payload to the caller
1324 */
1325 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1326 bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(fw_status);
1327
1328 if (comp_status != CS_COMPLETE) {
1329 if (comp_status == CS_DATA_UNDERRUN) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001330 res = DID_OK << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001331 bsg_job->reply->reply_payload_rcv_len =
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001332 le16_to_cpu(((struct els_sts_entry_24xx *)pkt)->total_byte_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001333
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001334 ql_dbg(ql_dbg_user, vha, 0x503f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001335 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001336 "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001337 type, sp->handle, comp_status, fw_status[1], fw_status[2],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001338 le16_to_cpu(((struct els_sts_entry_24xx *)
1339 pkt)->total_byte_count));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001340 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1341 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1342 }
1343 else {
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001344 ql_dbg(ql_dbg_user, vha, 0x5040,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001345 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001346 "error subcode 1=0x%x error subcode 2=0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001347 type, sp->handle, comp_status,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001348 le16_to_cpu(((struct els_sts_entry_24xx *)
1349 pkt)->error_subcode_1),
1350 le16_to_cpu(((struct els_sts_entry_24xx *)
1351 pkt)->error_subcode_2));
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001352 res = DID_ERROR << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001353 bsg_job->reply->reply_payload_rcv_len = 0;
1354 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1355 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1356 }
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001357 ql_dump_buffer(ql_dbg_user + ql_dbg_buffer, vha, 0x5056,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001358 (uint8_t *)pkt, sizeof(*pkt));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001359 }
1360 else {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001361 res = DID_OK << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001362 bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
1363 bsg_job->reply_len = 0;
1364 }
1365
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001366 sp->done(vha, sp, res);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001367}
1368
1369static void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001370qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req,
1371 struct logio_entry_24xx *logio)
1372{
1373 const char func[] = "LOGIO-IOCB";
1374 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001375 fc_port_t *fcport;
1376 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001377 struct srb_iocb *lio;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001378 uint16_t *data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001379 uint32_t iop[2];
1380
1381 sp = qla2x00_get_sp_from_handle(vha, func, req, logio);
1382 if (!sp)
1383 return;
1384
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001385 lio = &sp->u.iocb_cmd;
1386 type = sp->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001387 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001388 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001389
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001390 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001391 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001392 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001393 if (logio->entry_status) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001394 ql_log(ql_log_warn, fcport->vha, 0x5034,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001395 "Async-%s error entry - hdl=%x"
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001396 "portid=%02x%02x%02x entry-status=%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001397 type, sp->handle, fcport->d_id.b.domain,
1398 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1399 logio->entry_status);
1400 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x504d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001401 (uint8_t *)logio, sizeof(*logio));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001402
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001403 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001404 }
1405
1406 if (le16_to_cpu(logio->comp_status) == CS_COMPLETE) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001407 ql_dbg(ql_dbg_async, fcport->vha, 0x5036,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001408 "Async-%s complete - hdl=%x portid=%02x%02x%02x "
1409 "iop0=%x.\n", type, sp->handle, fcport->d_id.b.domain,
1410 fcport->d_id.b.area, fcport->d_id.b.al_pa,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001411 le32_to_cpu(logio->io_parameter[0]));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001412
1413 data[0] = MBS_COMMAND_COMPLETE;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001414 if (sp->type != SRB_LOGIN_CMD)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001415 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001416
1417 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1418 if (iop[0] & BIT_4) {
1419 fcport->port_type = FCT_TARGET;
1420 if (iop[0] & BIT_8)
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07001421 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquezb0cd5792010-05-28 15:08:22 -07001422 } else if (iop[0] & BIT_5)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001423 fcport->port_type = FCT_INITIATOR;
Andrew Vasquezb0cd5792010-05-28 15:08:22 -07001424
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001425 if (iop[0] & BIT_7)
1426 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
1427
Andrew Vasquezac280b62009-08-20 11:06:05 -07001428 if (logio->io_parameter[7] || logio->io_parameter[8])
1429 fcport->supported_classes |= FC_COS_CLASS2;
1430 if (logio->io_parameter[9] || logio->io_parameter[10])
1431 fcport->supported_classes |= FC_COS_CLASS3;
1432
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001433 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001434 }
1435
1436 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1437 iop[1] = le32_to_cpu(logio->io_parameter[1]);
1438 switch (iop[0]) {
1439 case LSC_SCODE_PORTID_USED:
1440 data[0] = MBS_PORT_ID_USED;
1441 data[1] = LSW(iop[1]);
1442 break;
1443 case LSC_SCODE_NPORT_USED:
1444 data[0] = MBS_LOOP_ID_USED;
1445 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001446 default:
1447 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001448 break;
1449 }
1450
Arun Easi5e19ed92012-02-09 11:15:51 -08001451 ql_dbg(ql_dbg_async, fcport->vha, 0x5037,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001452 "Async-%s failed - hdl=%x portid=%02x%02x%02x comp=%x "
1453 "iop0=%x iop1=%x.\n", type, sp->handle, fcport->d_id.b.domain,
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001454 fcport->d_id.b.area, fcport->d_id.b.al_pa,
Andrew Vasquezac280b62009-08-20 11:06:05 -07001455 le16_to_cpu(logio->comp_status),
1456 le32_to_cpu(logio->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001457 le32_to_cpu(logio->io_parameter[1]));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001458
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001459logio_done:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001460 sp->done(vha, sp, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001461}
1462
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001463static void
1464qla24xx_tm_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1465 struct tsk_mgmt_entry *tsk)
1466{
1467 const char func[] = "TMF-IOCB";
1468 const char *type;
1469 fc_port_t *fcport;
1470 srb_t *sp;
1471 struct srb_iocb *iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001472 struct sts_entry_24xx *sts = (struct sts_entry_24xx *)tsk;
1473 int error = 1;
1474
1475 sp = qla2x00_get_sp_from_handle(vha, func, req, tsk);
1476 if (!sp)
1477 return;
1478
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001479 iocb = &sp->u.iocb_cmd;
1480 type = sp->name;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001481 fcport = sp->fcport;
1482
1483 if (sts->entry_status) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001484 ql_log(ql_log_warn, fcport->vha, 0x5038,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001485 "Async-%s error - hdl=%x entry-status(%x).\n",
1486 type, sp->handle, sts->entry_status);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001487 } else if (sts->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001488 ql_log(ql_log_warn, fcport->vha, 0x5039,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001489 "Async-%s error - hdl=%x completion status(%x).\n",
1490 type, sp->handle, sts->comp_status);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001491 } else if (!(le16_to_cpu(sts->scsi_status) &
1492 SS_RESPONSE_INFO_LEN_VALID)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001493 ql_log(ql_log_warn, fcport->vha, 0x503a,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001494 "Async-%s error - hdl=%x no response info(%x).\n",
1495 type, sp->handle, sts->scsi_status);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001496 } else if (le32_to_cpu(sts->rsp_data_len) < 4) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001497 ql_log(ql_log_warn, fcport->vha, 0x503b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001498 "Async-%s error - hdl=%x not enough response(%d).\n",
1499 type, sp->handle, sts->rsp_data_len);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001500 } else if (sts->data[3]) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001501 ql_log(ql_log_warn, fcport->vha, 0x503c,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001502 "Async-%s error - hdl=%x response(%x).\n",
1503 type, sp->handle, sts->data[3]);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001504 } else {
1505 error = 0;
1506 }
1507
1508 if (error) {
1509 iocb->u.tmf.data = error;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001510 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5055,
1511 (uint8_t *)sts, sizeof(*sts));
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001512 }
1513
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001514 sp->done(vha, sp, 0);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001515}
1516
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517/**
1518 * qla2x00_process_response_queue() - Process response queue entries.
1519 * @ha: SCSI driver HA context
1520 */
1521void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001522qla2x00_process_response_queue(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001524 struct scsi_qla_host *vha;
1525 struct qla_hw_data *ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001526 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 sts_entry_t *pkt;
1528 uint16_t handle_cnt;
1529 uint16_t cnt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001530
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001531 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001533 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 return;
1535
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001536 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1537 pkt = (sts_entry_t *)rsp->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001539 rsp->ring_index++;
1540 if (rsp->ring_index == rsp->length) {
1541 rsp->ring_index = 0;
1542 rsp->ring_ptr = rsp->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001544 rsp->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 }
1546
1547 if (pkt->entry_status != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001548 qla2x00_error_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1550 wmb();
1551 continue;
1552 }
1553
1554 switch (pkt->entry_type) {
1555 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001556 qla2x00_status_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 break;
1558 case STATUS_TYPE_21:
1559 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
1560 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001561 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 ((sts21_entry_t *)pkt)->handle[cnt]);
1563 }
1564 break;
1565 case STATUS_TYPE_22:
1566 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
1567 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001568 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 ((sts22_entry_t *)pkt)->handle[cnt]);
1570 }
1571 break;
1572 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001573 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001575 case MBX_IOCB_TYPE:
1576 qla2x00_mbx_iocb_entry(vha, rsp->req,
1577 (struct mbx_entry *)pkt);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001578 break;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001579 case CT_IOCB_TYPE:
1580 qla2x00_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
1581 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 default:
1583 /* Type Not Supported. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001584 ql_log(ql_log_warn, vha, 0x504a,
1585 "Received unknown response pkt type %x "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 "entry status=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001587 pkt->entry_type, pkt->entry_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 break;
1589 }
1590 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1591 wmb();
1592 }
1593
1594 /* Adjust ring index */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001595 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596}
1597
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001598static inline void
Andrew Vasquez55442132010-07-23 15:28:27 +05001599qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t par_sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001600 uint32_t sense_len, struct rsp_que *rsp, int res)
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001601{
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001602 struct scsi_qla_host *vha = sp->fcport->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001603 struct scsi_cmnd *cp = GET_CMD_SP(sp);
1604 uint32_t track_sense_len;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001605
1606 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
1607 sense_len = SCSI_SENSE_BUFFERSIZE;
1608
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001609 SET_CMD_SENSE_LEN(sp, sense_len);
1610 SET_CMD_SENSE_PTR(sp, cp->sense_buffer);
1611 track_sense_len = sense_len;
1612
1613 if (sense_len > par_sense_len)
Andrew Vasquez55442132010-07-23 15:28:27 +05001614 sense_len = par_sense_len;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001615
1616 memcpy(cp->sense_buffer, sense_data, sense_len);
1617
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001618 SET_CMD_SENSE_PTR(sp, cp->sense_buffer + sense_len);
1619 track_sense_len -= sense_len;
1620 SET_CMD_SENSE_LEN(sp, track_sense_len);
1621
1622 if (track_sense_len != 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001623 rsp->status_srb = sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001624 cp->result = res;
1625 }
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001626
Chad Dupuiscfb09192011-11-18 09:03:07 -08001627 if (sense_len) {
1628 ql_dbg(ql_dbg_io + ql_dbg_buffer, vha, 0x301c,
1629 "Check condition Sense data, nexus%ld:%d:%d cmd=%p.\n",
1630 sp->fcport->vha->host_no, cp->device->id, cp->device->lun,
1631 cp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001632 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302b,
1633 cp->sense_buffer, sense_len);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001634 }
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001635}
1636
Arun Easibad75002010-05-04 15:01:30 -07001637struct scsi_dif_tuple {
1638 __be16 guard; /* Checksum */
Masanari Iidad6a03582012-08-22 14:20:58 -04001639 __be16 app_tag; /* APPL identifier */
Arun Easibad75002010-05-04 15:01:30 -07001640 __be32 ref_tag; /* Target LBA or indirect LBA */
1641};
1642
1643/*
1644 * Checks the guard or meta-data for the type of error
1645 * detected by the HBA. In case of errors, we set the
1646 * ASC/ASCQ fields in the sense buffer with ILLEGAL_REQUEST
1647 * to indicate to the kernel that the HBA detected error.
1648 */
Arun Easi8cb20492011-08-16 11:29:22 -07001649static inline int
Arun Easibad75002010-05-04 15:01:30 -07001650qla2x00_handle_dif_error(srb_t *sp, struct sts_entry_24xx *sts24)
1651{
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001652 struct scsi_qla_host *vha = sp->fcport->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001653 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Arun Easi8cb20492011-08-16 11:29:22 -07001654 uint8_t *ap = &sts24->data[12];
1655 uint8_t *ep = &sts24->data[20];
Arun Easibad75002010-05-04 15:01:30 -07001656 uint32_t e_ref_tag, a_ref_tag;
1657 uint16_t e_app_tag, a_app_tag;
1658 uint16_t e_guard, a_guard;
1659
Arun Easi8cb20492011-08-16 11:29:22 -07001660 /*
1661 * swab32 of the "data" field in the beginning of qla2x00_status_entry()
1662 * would make guard field appear at offset 2
1663 */
1664 a_guard = le16_to_cpu(*(uint16_t *)(ap + 2));
1665 a_app_tag = le16_to_cpu(*(uint16_t *)(ap + 0));
1666 a_ref_tag = le32_to_cpu(*(uint32_t *)(ap + 4));
1667 e_guard = le16_to_cpu(*(uint16_t *)(ep + 2));
1668 e_app_tag = le16_to_cpu(*(uint16_t *)(ep + 0));
1669 e_ref_tag = le32_to_cpu(*(uint32_t *)(ep + 4));
Arun Easibad75002010-05-04 15:01:30 -07001670
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001671 ql_dbg(ql_dbg_io, vha, 0x3023,
1672 "iocb(s) %p Returned STATUS.\n", sts24);
Arun Easibad75002010-05-04 15:01:30 -07001673
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001674 ql_dbg(ql_dbg_io, vha, 0x3024,
1675 "DIF ERROR in cmd 0x%x lba 0x%llx act ref"
Arun Easibad75002010-05-04 15:01:30 -07001676 " tag=0x%x, exp ref_tag=0x%x, act app tag=0x%x, exp app"
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001677 " tag=0x%x, act guard=0x%x, exp guard=0x%x.\n",
Arun Easibad75002010-05-04 15:01:30 -07001678 cmd->cmnd[0], (u64)scsi_get_lba(cmd), a_ref_tag, e_ref_tag,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001679 a_app_tag, e_app_tag, a_guard, e_guard);
Arun Easibad75002010-05-04 15:01:30 -07001680
Arun Easi8cb20492011-08-16 11:29:22 -07001681 /*
1682 * Ignore sector if:
1683 * For type 3: ref & app tag is all 'f's
1684 * For type 0,1,2: app tag is all 'f's
1685 */
1686 if ((a_app_tag == 0xffff) &&
1687 ((scsi_get_prot_type(cmd) != SCSI_PROT_DIF_TYPE3) ||
1688 (a_ref_tag == 0xffffffff))) {
1689 uint32_t blocks_done, resid;
1690 sector_t lba_s = scsi_get_lba(cmd);
1691
1692 /* 2TB boundary case covered automatically with this */
1693 blocks_done = e_ref_tag - (uint32_t)lba_s + 1;
1694
1695 resid = scsi_bufflen(cmd) - (blocks_done *
1696 cmd->device->sector_size);
1697
1698 scsi_set_resid(cmd, resid);
1699 cmd->result = DID_OK << 16;
1700
1701 /* Update protection tag */
1702 if (scsi_prot_sg_count(cmd)) {
1703 uint32_t i, j = 0, k = 0, num_ent;
1704 struct scatterlist *sg;
1705 struct sd_dif_tuple *spt;
1706
1707 /* Patch the corresponding protection tags */
1708 scsi_for_each_prot_sg(cmd, sg,
1709 scsi_prot_sg_count(cmd), i) {
1710 num_ent = sg_dma_len(sg) / 8;
1711 if (k + num_ent < blocks_done) {
1712 k += num_ent;
1713 continue;
1714 }
1715 j = blocks_done - k - 1;
1716 k = blocks_done;
1717 break;
1718 }
1719
1720 if (k != blocks_done) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001721 ql_log(ql_log_warn, vha, 0x302f,
Randy Dunlap8ec9c7f2011-09-23 15:40:50 -07001722 "unexpected tag values tag:lba=%x:%llx)\n",
1723 e_ref_tag, (unsigned long long)lba_s);
Arun Easi8cb20492011-08-16 11:29:22 -07001724 return 1;
1725 }
1726
1727 spt = page_address(sg_page(sg)) + sg->offset;
1728 spt += j;
1729
1730 spt->app_tag = 0xffff;
1731 if (scsi_get_prot_type(cmd) == SCSI_PROT_DIF_TYPE3)
1732 spt->ref_tag = 0xffffffff;
1733 }
1734
1735 return 0;
1736 }
1737
Arun Easibad75002010-05-04 15:01:30 -07001738 /* check guard */
1739 if (e_guard != a_guard) {
1740 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1741 0x10, 0x1);
1742 set_driver_byte(cmd, DRIVER_SENSE);
1743 set_host_byte(cmd, DID_ABORT);
1744 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
Arun Easi8cb20492011-08-16 11:29:22 -07001745 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001746 }
1747
Arun Easie02587d2011-08-16 11:29:23 -07001748 /* check ref tag */
1749 if (e_ref_tag != a_ref_tag) {
1750 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1751 0x10, 0x3);
1752 set_driver_byte(cmd, DRIVER_SENSE);
1753 set_host_byte(cmd, DID_ABORT);
1754 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
1755 return 1;
1756 }
1757
Arun Easibad75002010-05-04 15:01:30 -07001758 /* check appl tag */
1759 if (e_app_tag != a_app_tag) {
1760 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1761 0x10, 0x2);
1762 set_driver_byte(cmd, DRIVER_SENSE);
1763 set_host_byte(cmd, DID_ABORT);
1764 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
Arun Easi8cb20492011-08-16 11:29:22 -07001765 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001766 }
1767
Arun Easi8cb20492011-08-16 11:29:22 -07001768 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001769}
1770
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001771static void
1772qla25xx_process_bidir_status_iocb(scsi_qla_host_t *vha, void *pkt,
1773 struct req_que *req, uint32_t index)
1774{
1775 struct qla_hw_data *ha = vha->hw;
1776 srb_t *sp;
1777 uint16_t comp_status;
1778 uint16_t scsi_status;
1779 uint16_t thread_id;
1780 uint32_t rval = EXT_STATUS_OK;
1781 struct fc_bsg_job *bsg_job = NULL;
1782 sts_entry_t *sts;
1783 struct sts_entry_24xx *sts24;
1784 sts = (sts_entry_t *) pkt;
1785 sts24 = (struct sts_entry_24xx *) pkt;
1786
1787 /* Validate handle. */
Chad Dupuis8d93f552013-01-30 03:34:37 -05001788 if (index >= req->num_outstanding_cmds) {
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001789 ql_log(ql_log_warn, vha, 0x70af,
1790 "Invalid SCSI completion handle 0x%x.\n", index);
1791 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1792 return;
1793 }
1794
1795 sp = req->outstanding_cmds[index];
1796 if (sp) {
1797 /* Free outstanding command slot. */
1798 req->outstanding_cmds[index] = NULL;
1799 bsg_job = sp->u.bsg_job;
1800 } else {
1801 ql_log(ql_log_warn, vha, 0x70b0,
1802 "Req:%d: Invalid ISP SCSI completion handle(0x%x)\n",
1803 req->id, index);
1804
1805 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1806 return;
1807 }
1808
1809 if (IS_FWI2_CAPABLE(ha)) {
1810 comp_status = le16_to_cpu(sts24->comp_status);
1811 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
1812 } else {
1813 comp_status = le16_to_cpu(sts->comp_status);
1814 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1815 }
1816
1817 thread_id = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1818 switch (comp_status) {
1819 case CS_COMPLETE:
1820 if (scsi_status == 0) {
1821 bsg_job->reply->reply_payload_rcv_len =
1822 bsg_job->reply_payload.payload_len;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -04001823 vha->qla_stats.input_bytes +=
1824 bsg_job->reply->reply_payload_rcv_len;
1825 vha->qla_stats.input_requests++;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001826 rval = EXT_STATUS_OK;
1827 }
1828 goto done;
1829
1830 case CS_DATA_OVERRUN:
1831 ql_dbg(ql_dbg_user, vha, 0x70b1,
1832 "Command completed with date overrun thread_id=%d\n",
1833 thread_id);
1834 rval = EXT_STATUS_DATA_OVERRUN;
1835 break;
1836
1837 case CS_DATA_UNDERRUN:
1838 ql_dbg(ql_dbg_user, vha, 0x70b2,
1839 "Command completed with date underrun thread_id=%d\n",
1840 thread_id);
1841 rval = EXT_STATUS_DATA_UNDERRUN;
1842 break;
1843 case CS_BIDIR_RD_OVERRUN:
1844 ql_dbg(ql_dbg_user, vha, 0x70b3,
1845 "Command completed with read data overrun thread_id=%d\n",
1846 thread_id);
1847 rval = EXT_STATUS_DATA_OVERRUN;
1848 break;
1849
1850 case CS_BIDIR_RD_WR_OVERRUN:
1851 ql_dbg(ql_dbg_user, vha, 0x70b4,
1852 "Command completed with read and write data overrun "
1853 "thread_id=%d\n", thread_id);
1854 rval = EXT_STATUS_DATA_OVERRUN;
1855 break;
1856
1857 case CS_BIDIR_RD_OVERRUN_WR_UNDERRUN:
1858 ql_dbg(ql_dbg_user, vha, 0x70b5,
1859 "Command completed with read data over and write data "
1860 "underrun thread_id=%d\n", thread_id);
1861 rval = EXT_STATUS_DATA_OVERRUN;
1862 break;
1863
1864 case CS_BIDIR_RD_UNDERRUN:
1865 ql_dbg(ql_dbg_user, vha, 0x70b6,
1866 "Command completed with read data data underrun "
1867 "thread_id=%d\n", thread_id);
1868 rval = EXT_STATUS_DATA_UNDERRUN;
1869 break;
1870
1871 case CS_BIDIR_RD_UNDERRUN_WR_OVERRUN:
1872 ql_dbg(ql_dbg_user, vha, 0x70b7,
1873 "Command completed with read data under and write data "
1874 "overrun thread_id=%d\n", thread_id);
1875 rval = EXT_STATUS_DATA_UNDERRUN;
1876 break;
1877
1878 case CS_BIDIR_RD_WR_UNDERRUN:
1879 ql_dbg(ql_dbg_user, vha, 0x70b8,
1880 "Command completed with read and write data underrun "
1881 "thread_id=%d\n", thread_id);
1882 rval = EXT_STATUS_DATA_UNDERRUN;
1883 break;
1884
1885 case CS_BIDIR_DMA:
1886 ql_dbg(ql_dbg_user, vha, 0x70b9,
1887 "Command completed with data DMA error thread_id=%d\n",
1888 thread_id);
1889 rval = EXT_STATUS_DMA_ERR;
1890 break;
1891
1892 case CS_TIMEOUT:
1893 ql_dbg(ql_dbg_user, vha, 0x70ba,
1894 "Command completed with timeout thread_id=%d\n",
1895 thread_id);
1896 rval = EXT_STATUS_TIMEOUT;
1897 break;
1898 default:
1899 ql_dbg(ql_dbg_user, vha, 0x70bb,
1900 "Command completed with completion status=0x%x "
1901 "thread_id=%d\n", comp_status, thread_id);
1902 rval = EXT_STATUS_ERR;
1903 break;
1904 }
1905 bsg_job->reply->reply_payload_rcv_len = 0;
1906
1907done:
1908 /* Return the vendor specific reply to API */
1909 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
1910 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1911 /* Always return DID_OK, bsg will send the vendor specific response
1912 * in this case only */
1913 sp->done(vha, sp, (DID_OK << 6));
1914
1915}
1916
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917/**
1918 * qla2x00_status_entry() - Process a Status IOCB entry.
1919 * @ha: SCSI driver HA context
1920 * @pkt: Entry pointer
1921 */
1922static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001923qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 fc_port_t *fcport;
1927 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001928 sts_entry_t *sts;
1929 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 uint16_t comp_status;
1931 uint16_t scsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001932 uint16_t ox_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 uint8_t lscsi_status;
1934 int32_t resid;
Andrew Vasquez55442132010-07-23 15:28:27 +05001935 uint32_t sense_len, par_sense_len, rsp_info_len, resid_len,
1936 fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001937 uint8_t *rsp_info, *sense_data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001938 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001939 uint32_t handle;
1940 uint16_t que;
1941 struct req_que *req;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001942 int logit = 1;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001943 int res = 0;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001944 uint16_t state_flags = 0;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001945
1946 sts = (sts_entry_t *) pkt;
1947 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001948 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001949 comp_status = le16_to_cpu(sts24->comp_status);
1950 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001951 state_flags = le16_to_cpu(sts24->state_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001952 } else {
1953 comp_status = le16_to_cpu(sts->comp_status);
1954 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1955 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001956 handle = (uint32_t) LSW(sts->handle);
1957 que = MSW(sts->handle);
1958 req = ha->req_q_map[que];
Giridhar Malavalia9083012010-04-12 17:59:55 -07001959
Chad Dupuis36008cf2013-10-03 03:21:13 -04001960 /* Check for invalid queue pointer */
1961 if (req == NULL ||
1962 que >= find_first_zero_bit(ha->req_qid_map, ha->max_req_queues)) {
1963 ql_dbg(ql_dbg_io, vha, 0x3059,
1964 "Invalid status handle (0x%x): Bad req pointer. req=%p, "
1965 "que=%u.\n", sts->handle, req, que);
1966 return;
1967 }
1968
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 /* Validate handle. */
Chad Dupuis8d93f552013-01-30 03:34:37 -05001970 if (handle < req->num_outstanding_cmds)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001971 sp = req->outstanding_cmds[handle];
Chad Dupuis8d93f552013-01-30 03:34:37 -05001972 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 sp = NULL;
1974
1975 if (sp == NULL) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001976 ql_dbg(ql_dbg_io, vha, 0x3017,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001977 "Invalid status handle (0x%x).\n", sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001979 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001980 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1981 else
1982 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001983 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 return;
1985 }
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001986
1987 if (unlikely((state_flags & BIT_1) && (sp->type == SRB_BIDI_CMD))) {
1988 qla25xx_process_bidir_status_iocb(vha, pkt, req, handle);
1989 return;
1990 }
1991
1992 /* Fast path completion. */
1993 if (comp_status == CS_COMPLETE && scsi_status == 0) {
Chad Dupuis3c290d02013-01-30 03:34:38 -05001994 qla2x00_do_host_ramp_up(vha);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001995 qla2x00_process_completed_request(vha, req, handle);
1996
1997 return;
1998 }
1999
2000 req->outstanding_cmds[handle] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002001 cp = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 if (cp == NULL) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08002003 ql_dbg(ql_dbg_io, vha, 0x3018,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002004 "Command already returned (0x%x/%p).\n",
2005 sts->handle, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
2007 return;
2008 }
2009
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002010 lscsi_status = scsi_status & STATUS_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011
bdf79622005-04-17 15:06:53 -05002012 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002014 ox_id = 0;
Andrew Vasquez55442132010-07-23 15:28:27 +05002015 sense_len = par_sense_len = rsp_info_len = resid_len =
2016 fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002017 if (IS_FWI2_CAPABLE(ha)) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002018 if (scsi_status & SS_SENSE_LEN_VALID)
2019 sense_len = le32_to_cpu(sts24->sense_len);
2020 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
2021 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
2022 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER))
2023 resid_len = le32_to_cpu(sts24->rsp_residual_count);
2024 if (comp_status == CS_DATA_UNDERRUN)
2025 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002026 rsp_info = sts24->data;
2027 sense_data = sts24->data;
2028 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002029 ox_id = le16_to_cpu(sts24->ox_id);
Andrew Vasquez55442132010-07-23 15:28:27 +05002030 par_sense_len = sizeof(sts24->data);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002031 } else {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002032 if (scsi_status & SS_SENSE_LEN_VALID)
2033 sense_len = le16_to_cpu(sts->req_sense_length);
2034 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
2035 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002036 resid_len = le32_to_cpu(sts->residual_length);
2037 rsp_info = sts->rsp_info;
2038 sense_data = sts->req_sense_data;
Andrew Vasquez55442132010-07-23 15:28:27 +05002039 par_sense_len = sizeof(sts->req_sense_data);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002040 }
2041
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 /* Check for any FCP transport errors. */
2043 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002044 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasquez55442132010-07-23 15:28:27 +05002045 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002046 sense_data += rsp_info_len;
Andrew Vasquez55442132010-07-23 15:28:27 +05002047 par_sense_len -= rsp_info_len;
2048 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002049 if (rsp_info_len > 3 && rsp_info[3]) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002050 ql_dbg(ql_dbg_io, fcport->vha, 0x3019,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002051 "FCP I/O protocol failure (0x%x/0x%x).\n",
2052 rsp_info_len, rsp_info[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002054 res = DID_BUS_BUSY << 16;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002055 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 }
2057 }
2058
Andrew Vasquez3e8ce322008-02-28 14:06:10 -08002059 /* Check for overrun. */
2060 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
2061 scsi_status & SS_RESIDUAL_OVER)
2062 comp_status = CS_DATA_OVERRUN;
2063
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 /*
2065 * Based on Host and scsi status generate status code for Linux
2066 */
2067 switch (comp_status) {
2068 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002069 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 if (scsi_status == 0) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002071 res = DID_OK << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 break;
2073 }
2074 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002075 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002076 scsi_set_resid(cp, resid);
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002077
2078 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002079 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002080 cp->underflow)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002081 ql_dbg(ql_dbg_io, fcport->vha, 0x301a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002082 "Mid-layer underflow "
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002083 "detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002084 resid, scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002085
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002086 res = DID_ERROR << 16;
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002087 break;
2088 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002090 res = DID_OK << 16 | lscsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002092 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002093 ql_dbg(ql_dbg_io, fcport->vha, 0x301b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002094 "QUEUE FULL detected.\n");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002095 break;
2096 }
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002097 logit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 if (lscsi_status != SS_CHECK_CONDITION)
2099 break;
2100
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002101 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 if (!(scsi_status & SS_SENSE_LEN_VALID))
2103 break;
2104
Andrew Vasquez55442132010-07-23 15:28:27 +05002105 qla2x00_handle_sense(sp, sense_data, par_sense_len, sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002106 rsp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 break;
2108
2109 case CS_DATA_UNDERRUN:
Ravi Ananded17c71b52006-05-17 15:08:55 -07002110 /* Use F/W calculated residual length. */
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002111 resid = IS_FWI2_CAPABLE(ha) ? fw_resid_len : resid_len;
2112 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 if (scsi_status & SS_RESIDUAL_UNDER) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002114 if (IS_FWI2_CAPABLE(ha) && fw_resid_len != resid_len) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002115 ql_dbg(ql_dbg_io, fcport->vha, 0x301d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002116 "Dropped frame(s) detected "
2117 "(0x%x of 0x%x bytes).\n",
2118 resid, scsi_bufflen(cp));
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08002119
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002120 res = DID_ERROR << 16 | lscsi_status;
Arun Easi4e85e3d2011-11-18 09:02:10 -08002121 goto check_scsi_status;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002122 }
2123
2124 if (!lscsi_status &&
2125 ((unsigned)(scsi_bufflen(cp) - resid) <
2126 cp->underflow)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002127 ql_dbg(ql_dbg_io, fcport->vha, 0x301e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002128 "Mid-layer underflow "
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002129 "detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002130 resid, scsi_bufflen(cp));
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002131
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002132 res = DID_ERROR << 16;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002133 break;
2134 }
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002135 } else if (lscsi_status != SAM_STAT_TASK_SET_FULL &&
2136 lscsi_status != SAM_STAT_BUSY) {
2137 /*
2138 * scsi status of task set and busy are considered to be
2139 * task not completed.
2140 */
2141
Arun Easi5e19ed92012-02-09 11:15:51 -08002142 ql_dbg(ql_dbg_io, fcport->vha, 0x301f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002143 "Dropped frame(s) detected (0x%x "
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002144 "of 0x%x bytes).\n", resid,
2145 scsi_bufflen(cp));
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002146
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002147 res = DID_ERROR << 16 | lscsi_status;
Lalit Chandivade0374f552010-09-03 14:57:04 -07002148 goto check_scsi_status;
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002149 } else {
2150 ql_dbg(ql_dbg_io, fcport->vha, 0x3030,
2151 "scsi_status: 0x%x, lscsi_status: 0x%x\n",
2152 scsi_status, lscsi_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 }
2154
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002155 res = DID_OK << 16 | lscsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002156 logit = 0;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002157
Lalit Chandivade0374f552010-09-03 14:57:04 -07002158check_scsi_status:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002160 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 * Status.
2162 */
2163 if (lscsi_status != 0) {
Andrew Vasquezffec28a2007-01-29 10:22:27 -08002164 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002165 ql_dbg(ql_dbg_io, fcport->vha, 0x3020,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002166 "QUEUE FULL detected.\n");
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002167 logit = 1;
Andrew Vasquezffec28a2007-01-29 10:22:27 -08002168 break;
2169 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 if (lscsi_status != SS_CHECK_CONDITION)
2171 break;
2172
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002173 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 if (!(scsi_status & SS_SENSE_LEN_VALID))
2175 break;
2176
Andrew Vasquez55442132010-07-23 15:28:27 +05002177 qla2x00_handle_sense(sp, sense_data, par_sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002178 sense_len, rsp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 }
2180 break;
2181
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 case CS_PORT_LOGGED_OUT:
2183 case CS_PORT_CONFIG_CHG:
2184 case CS_PORT_BUSY:
2185 case CS_INCOMPLETE:
2186 case CS_PORT_UNAVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 case CS_TIMEOUT:
Chad Dupuisff454b02010-10-15 11:27:42 -07002188 case CS_RESET:
2189
Mike Christie056a4482008-08-19 18:45:29 -05002190 /*
2191 * We are going to have the fc class block the rport
2192 * while we try to recover so instruct the mid layer
2193 * to requeue until the class decides how to handle this.
2194 */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002195 res = DID_TRANSPORT_DISRUPTED << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002197 if (comp_status == CS_TIMEOUT) {
2198 if (IS_FWI2_CAPABLE(ha))
2199 break;
2200 else if ((le16_to_cpu(sts->status_flags) &
2201 SF_LOGOUT_SENT) == 0)
2202 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002204
Arun Easi5e19ed92012-02-09 11:15:51 -08002205 ql_dbg(ql_dbg_io, fcport->vha, 0x3021,
Chad Dupuis0e948972013-08-27 01:37:39 -04002206 "Port to be marked lost on fcport=%02x%02x%02x, current "
2207 "port state= %s.\n", fcport->d_id.b.domain,
2208 fcport->d_id.b.area, fcport->d_id.b.al_pa,
2209 port_state_str[atomic_read(&fcport->state)]);
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002210
2211 if (atomic_read(&fcport->state) == FCS_ONLINE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002212 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 break;
2214
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002215 case CS_ABORTED:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002216 res = DID_RESET << 16;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002217 break;
Arun Easibad75002010-05-04 15:01:30 -07002218
2219 case CS_DIF_ERROR:
Arun Easi8cb20492011-08-16 11:29:22 -07002220 logit = qla2x00_handle_dif_error(sp, sts24);
Arun Easifb6e4662012-08-22 14:21:32 -04002221 res = cp->result;
Arun Easibad75002010-05-04 15:01:30 -07002222 break;
Arun Easi9e522cd2012-08-22 14:21:31 -04002223
2224 case CS_TRANSPORT:
2225 res = DID_ERROR << 16;
2226
2227 if (!IS_PI_SPLIT_DET_CAPABLE(ha))
2228 break;
2229
2230 if (state_flags & BIT_4)
2231 scmd_printk(KERN_WARNING, cp,
2232 "Unsupported device '%s' found.\n",
2233 cp->device->vendor);
2234 break;
2235
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 default:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002237 res = DID_ERROR << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 break;
2239 }
2240
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002241out:
2242 if (logit)
Arun Easi5e19ed92012-02-09 11:15:51 -08002243 ql_dbg(ql_dbg_io, fcport->vha, 0x3022,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04002244 "FCP command status: 0x%x-0x%x (0x%x) nexus=%ld:%d:%d "
2245 "portid=%02x%02x%02x oxid=0x%x cdb=%10phN len=0x%x "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002246 "rsp_info=0x%x resid=0x%x fw_resid=0x%x.\n",
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002247 comp_status, scsi_status, res, vha->host_no,
Chad Dupuiscfb09192011-11-18 09:03:07 -08002248 cp->device->id, cp->device->lun, fcport->d_id.b.domain,
2249 fcport->d_id.b.area, fcport->d_id.b.al_pa, ox_id,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04002250 cp->cmnd, scsi_bufflen(cp), rsp_info_len,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002251 resid_len, fw_resid_len);
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002252
Chad Dupuis3c290d02013-01-30 03:34:38 -05002253 if (!res)
2254 qla2x00_do_host_ramp_up(vha);
2255
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002256 if (rsp->status_srb == NULL)
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002257 sp->done(ha, sp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258}
2259
2260/**
2261 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
2262 * @ha: SCSI driver HA context
2263 * @pkt: Entry pointer
2264 *
2265 * Extended sense data.
2266 */
2267static void
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002268qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002270 uint8_t sense_sz = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002271 struct qla_hw_data *ha = rsp->hw;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002272 struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002273 srb_t *sp = rsp->status_srb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 struct scsi_cmnd *cp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002275 uint32_t sense_len;
2276 uint8_t *sense_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002278 if (!sp || !GET_CMD_SENSE_LEN(sp))
2279 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002281 sense_len = GET_CMD_SENSE_LEN(sp);
2282 sense_ptr = GET_CMD_SENSE_PTR(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002284 cp = GET_CMD_SP(sp);
2285 if (cp == NULL) {
2286 ql_log(ql_log_warn, vha, 0x3025,
2287 "cmd is NULL: already returned to OS (sp=%p).\n", sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002289 rsp->status_srb = NULL;
2290 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002293 if (sense_len > sizeof(pkt->data))
2294 sense_sz = sizeof(pkt->data);
2295 else
2296 sense_sz = sense_len;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002297
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002298 /* Move sense data. */
2299 if (IS_FWI2_CAPABLE(ha))
2300 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
2301 memcpy(sense_ptr, pkt->data, sense_sz);
2302 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302c,
2303 sense_ptr, sense_sz);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002304
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002305 sense_len -= sense_sz;
2306 sense_ptr += sense_sz;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002307
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002308 SET_CMD_SENSE_PTR(sp, sense_ptr);
2309 SET_CMD_SENSE_LEN(sp, sense_len);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002310
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002311 /* Place command on done queue. */
2312 if (sense_len == 0) {
2313 rsp->status_srb = NULL;
2314 sp->done(ha, sp, cp->result);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002315 }
Giridhar Malavalic4631192011-11-18 09:03:08 -08002316}
2317
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318/**
2319 * qla2x00_error_entry() - Process an error entry.
2320 * @ha: SCSI driver HA context
2321 * @pkt: Entry pointer
2322 */
2323static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002324qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325{
2326 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002327 struct qla_hw_data *ha = vha->hw;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002328 const char func[] = "ERROR-IOCB";
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002329 uint16_t que = MSW(pkt->handle);
Arun Easia6fe35c2012-02-09 11:16:01 -08002330 struct req_que *req = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002331 int res = DID_ERROR << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002332
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002333 ql_dbg(ql_dbg_async, vha, 0x502a,
2334 "type of error status in response: 0x%x\n", pkt->entry_status);
2335
Arun Easia6fe35c2012-02-09 11:16:01 -08002336 if (que >= ha->max_req_queues || !ha->req_q_map[que])
2337 goto fatal;
2338
2339 req = ha->req_q_map[que];
2340
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002341 if (pkt->entry_status & RF_BUSY)
2342 res = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343
Giridhar Malavalic4631192011-11-18 09:03:08 -08002344 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
Arun Easia6fe35c2012-02-09 11:16:01 -08002345 if (sp) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002346 sp->done(ha, sp, res);
Arun Easia6fe35c2012-02-09 11:16:01 -08002347 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 }
Arun Easia6fe35c2012-02-09 11:16:01 -08002349fatal:
2350 ql_log(ql_log_warn, vha, 0x5030,
2351 "Error entry - invalid handle/queue.\n");
2352
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002353 if (IS_P3P_TYPE(ha))
Arun Easia6fe35c2012-02-09 11:16:01 -08002354 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
2355 else
2356 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2357 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358}
2359
2360/**
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002361 * qla24xx_mbx_completion() - Process mailbox command completions.
2362 * @ha: SCSI driver HA context
2363 * @mb0: Mailbox0 register
2364 */
2365static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002366qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002367{
2368 uint16_t cnt;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002369 uint32_t mboxes;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002370 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002371 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002372 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2373
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002374 /* Read all mbox registers? */
2375 mboxes = (1 << ha->mbx_count) - 1;
2376 if (!ha->mcp)
Masanari Iidaa7201012012-11-21 02:40:42 -05002377 ql_dbg(ql_dbg_async, vha, 0x504e, "MBX pointer ERROR.\n");
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002378 else
2379 mboxes = ha->mcp->in_mb;
2380
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002381 /* Load return mailbox registers. */
2382 ha->flags.mbox_int = 1;
2383 ha->mailbox_out[0] = mb0;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002384 mboxes >>= 1;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002385 wptr = (uint16_t __iomem *)&reg->mailbox1;
2386
2387 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002388 if (mboxes & BIT_0)
2389 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
2390
2391 mboxes >>= 1;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002392 wptr++;
2393 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002394}
2395
2396/**
2397 * qla24xx_process_response_queue() - Process response queue entries.
2398 * @ha: SCSI driver HA context
2399 */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002400void qla24xx_process_response_queue(struct scsi_qla_host *vha,
2401 struct rsp_que *rsp)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002402{
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002403 struct sts_entry_24xx *pkt;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002404 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002405
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002406 if (!vha->flags.online)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002407 return;
2408
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002409 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
2410 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002411
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002412 rsp->ring_index++;
2413 if (rsp->ring_index == rsp->length) {
2414 rsp->ring_index = 0;
2415 rsp->ring_ptr = rsp->ring;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002416 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002417 rsp->ring_ptr++;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002418 }
2419
2420 if (pkt->entry_status != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002421 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002422
2423 (void)qlt_24xx_process_response_error(vha, pkt);
2424
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002425 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2426 wmb();
2427 continue;
2428 }
2429
2430 switch (pkt->entry_type) {
2431 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002432 qla2x00_status_entry(vha, rsp, pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002433 break;
2434 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002435 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002436 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002437 case VP_RPT_ID_IOCB_TYPE:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002438 qla24xx_report_id_acquisition(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002439 (struct vp_rpt_id_entry_24xx *)pkt);
2440 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07002441 case LOGINOUT_PORT_IOCB_TYPE:
2442 qla24xx_logio_entry(vha, rsp->req,
2443 (struct logio_entry_24xx *)pkt);
2444 break;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07002445 case TSK_MGMT_IOCB_TYPE:
2446 qla24xx_tm_iocb_entry(vha, rsp->req,
2447 (struct tsk_mgmt_entry *)pkt);
2448 break;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002449 case CT_IOCB_TYPE:
2450 qla24xx_els_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002451 break;
2452 case ELS_IOCB_TYPE:
2453 qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE);
2454 break;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002455 case ABTS_RECV_24XX:
2456 /* ensure that the ATIO queue is empty */
2457 qlt_24xx_process_atio_queue(vha);
2458 case ABTS_RESP_24XX:
2459 case CTIO_TYPE7:
2460 case NOTIFY_ACK_TYPE:
2461 qlt_response_pkt_all_vps(vha, (response_t *)pkt);
2462 break;
Saurav Kashyap54883292011-08-16 11:31:48 -07002463 case MARKER_TYPE:
2464 /* Do nothing in this case, this check is to prevent it
2465 * from falling into default case
2466 */
2467 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002468 default:
2469 /* Type Not Supported. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002470 ql_dbg(ql_dbg_async, vha, 0x5042,
2471 "Received unknown response pkt type %x "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002472 "entry status=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002473 pkt->entry_type, pkt->entry_status);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002474 break;
2475 }
2476 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2477 wmb();
2478 }
2479
2480 /* Adjust ring index */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002481 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002482 struct device_reg_82xx __iomem *reg = &ha->iobase->isp82;
2483 WRT_REG_DWORD(&reg->rsp_q_out[0], rsp->ring_index);
2484 } else
2485 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002486}
2487
Andrew Vasquez05236a02007-09-20 14:07:37 -07002488static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002489qla2xxx_check_risc_status(scsi_qla_host_t *vha)
Andrew Vasquez05236a02007-09-20 14:07:37 -07002490{
2491 int rval;
2492 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002493 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez05236a02007-09-20 14:07:37 -07002494 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2495
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002496 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha))
Andrew Vasquez05236a02007-09-20 14:07:37 -07002497 return;
2498
2499 rval = QLA_SUCCESS;
2500 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
2501 RD_REG_DWORD(&reg->iobase_addr);
2502 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
2503 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
2504 rval == QLA_SUCCESS; cnt--) {
2505 if (cnt) {
2506 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
2507 udelay(10);
2508 } else
2509 rval = QLA_FUNCTION_TIMEOUT;
2510 }
2511 if (rval == QLA_SUCCESS)
2512 goto next_test;
2513
Bart Van Asscheb2ec76c2013-06-25 11:27:29 -04002514 rval = QLA_SUCCESS;
Andrew Vasquez05236a02007-09-20 14:07:37 -07002515 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
2516 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
2517 rval == QLA_SUCCESS; cnt--) {
2518 if (cnt) {
2519 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
2520 udelay(10);
2521 } else
2522 rval = QLA_FUNCTION_TIMEOUT;
2523 }
2524 if (rval != QLA_SUCCESS)
2525 goto done;
2526
2527next_test:
2528 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002529 ql_log(ql_log_info, vha, 0x504c,
2530 "Additional code -- 0x55AA.\n");
Andrew Vasquez05236a02007-09-20 14:07:37 -07002531
2532done:
2533 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
2534 RD_REG_DWORD(&reg->iobase_window);
2535}
2536
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002537/**
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002538 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP24xx.
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002539 * @irq:
2540 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002541 *
2542 * Called by system whenever the host adapter generates an interrupt.
2543 *
2544 * Returns handled flag.
2545 */
2546irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01002547qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002548{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002549 scsi_qla_host_t *vha;
2550 struct qla_hw_data *ha;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002551 struct device_reg_24xx __iomem *reg;
2552 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002553 unsigned long iter;
2554 uint32_t stat;
2555 uint32_t hccr;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002556 uint16_t mb[8];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002557 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002558 unsigned long flags;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002559
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002560 rsp = (struct rsp_que *) dev_id;
2561 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002562 ql_log(ql_log_info, NULL, 0x5059,
2563 "%s: NULL response queue pointer.\n", __func__);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002564 return IRQ_NONE;
2565 }
2566
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002567 ha = rsp->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002568 reg = &ha->iobase->isp24;
2569 status = 0;
2570
Andrew Vasquez85880802009-12-15 21:29:46 -08002571 if (unlikely(pci_channel_offline(ha->pdev)))
2572 return IRQ_HANDLED;
2573
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002574 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002575 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002576 for (iter = 50; iter--; ) {
2577 stat = RD_REG_DWORD(&reg->host_status);
2578 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08002579 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07002580 break;
2581
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002582 hccr = RD_REG_DWORD(&reg->hccr);
2583
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002584 ql_log(ql_log_warn, vha, 0x504b,
2585 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2586 hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002587
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002588 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002589
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002590 ha->isp_ops->fw_dump(vha, 1);
2591 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002592 break;
2593 } else if ((stat & HSRX_RISC_INT) == 0)
2594 break;
2595
2596 switch (stat & 0xff) {
Arun Easifafbda92012-08-22 14:21:16 -04002597 case INTR_ROM_MB_SUCCESS:
2598 case INTR_ROM_MB_FAILED:
2599 case INTR_MB_SUCCESS:
2600 case INTR_MB_FAILED:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002601 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002602 status |= MBX_INTERRUPT;
2603
2604 break;
Arun Easifafbda92012-08-22 14:21:16 -04002605 case INTR_ASYNC_EVENT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002606 mb[0] = MSW(stat);
2607 mb[1] = RD_REG_WORD(&reg->mailbox1);
2608 mb[2] = RD_REG_WORD(&reg->mailbox2);
2609 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002610 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002611 break;
Arun Easifafbda92012-08-22 14:21:16 -04002612 case INTR_RSP_QUE_UPDATE:
2613 case INTR_RSP_QUE_UPDATE_83XX:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002614 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002615 break;
Arun Easifafbda92012-08-22 14:21:16 -04002616 case INTR_ATIO_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002617 qlt_24xx_process_atio_queue(vha);
2618 break;
Arun Easifafbda92012-08-22 14:21:16 -04002619 case INTR_ATIO_RSP_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002620 qlt_24xx_process_atio_queue(vha);
2621 qla24xx_process_response_queue(vha, rsp);
2622 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002623 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002624 ql_dbg(ql_dbg_async, vha, 0x504f,
2625 "Unrecognized interrupt type (%d).\n", stat * 0xff);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002626 break;
2627 }
2628 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2629 RD_REG_DWORD_RELAXED(&reg->hccr);
Giridhar Malavalicb860bb2012-08-22 14:21:30 -04002630 if (unlikely(IS_QLA83XX(ha) && (ha->pdev->revision == 1)))
2631 ndelay(3500);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002632 }
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -07002633 qla2x00_handle_mbx_completion(ha, status);
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002634 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002635
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002636 return IRQ_HANDLED;
2637}
2638
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002639static irqreturn_t
2640qla24xx_msix_rsp_q(int irq, void *dev_id)
2641{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002642 struct qla_hw_data *ha;
2643 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002644 struct device_reg_24xx __iomem *reg;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002645 struct scsi_qla_host *vha;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002646 unsigned long flags;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002647
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002648 rsp = (struct rsp_que *) dev_id;
2649 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002650 ql_log(ql_log_info, NULL, 0x505a,
2651 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002652 return IRQ_NONE;
2653 }
2654 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002655 reg = &ha->iobase->isp24;
2656
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002657 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002658
Anirban Chakrabortya67093d2010-02-04 14:17:59 -08002659 vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002660 qla24xx_process_response_queue(vha, rsp);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002661 if (!ha->flags.disable_msix_handshake) {
Anirban Chakrabortyeb941142009-08-04 16:12:13 -07002662 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2663 RD_REG_DWORD_RELAXED(&reg->hccr);
2664 }
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002665 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002666
2667 return IRQ_HANDLED;
2668}
2669
2670static irqreturn_t
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002671qla25xx_msix_rsp_q(int irq, void *dev_id)
2672{
2673 struct qla_hw_data *ha;
2674 struct rsp_que *rsp;
Anirban Chakraborty31557542009-12-02 10:36:55 -08002675 struct device_reg_24xx __iomem *reg;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002676 unsigned long flags;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002677
2678 rsp = (struct rsp_que *) dev_id;
2679 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002680 ql_log(ql_log_info, NULL, 0x505b,
2681 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002682 return IRQ_NONE;
2683 }
2684 ha = rsp->hw;
2685
Anirban Chakraborty31557542009-12-02 10:36:55 -08002686 /* Clear the interrupt, if enabled, for this response queue */
Andrew Vasquezd4247542011-10-26 14:20:13 -07002687 if (!ha->flags.disable_msix_handshake) {
Anirban Chakraborty31557542009-12-02 10:36:55 -08002688 reg = &ha->iobase->isp24;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002689 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002690 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2691 RD_REG_DWORD_RELAXED(&reg->hccr);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002692 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002693 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002694 queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work);
2695
2696 return IRQ_HANDLED;
2697}
2698
2699static irqreturn_t
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002700qla24xx_msix_default(int irq, void *dev_id)
2701{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002702 scsi_qla_host_t *vha;
2703 struct qla_hw_data *ha;
2704 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002705 struct device_reg_24xx __iomem *reg;
2706 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002707 uint32_t stat;
2708 uint32_t hccr;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002709 uint16_t mb[8];
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002710 unsigned long flags;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002711
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002712 rsp = (struct rsp_que *) dev_id;
2713 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002714 ql_log(ql_log_info, NULL, 0x505c,
2715 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002716 return IRQ_NONE;
2717 }
2718 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002719 reg = &ha->iobase->isp24;
2720 status = 0;
2721
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002722 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002723 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002724 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002725 stat = RD_REG_DWORD(&reg->host_status);
2726 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08002727 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07002728 break;
2729
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002730 hccr = RD_REG_DWORD(&reg->hccr);
2731
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002732 ql_log(ql_log_info, vha, 0x5050,
2733 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2734 hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002735
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002736 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002737
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002738 ha->isp_ops->fw_dump(vha, 1);
2739 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002740 break;
2741 } else if ((stat & HSRX_RISC_INT) == 0)
2742 break;
2743
2744 switch (stat & 0xff) {
Arun Easifafbda92012-08-22 14:21:16 -04002745 case INTR_ROM_MB_SUCCESS:
2746 case INTR_ROM_MB_FAILED:
2747 case INTR_MB_SUCCESS:
2748 case INTR_MB_FAILED:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002749 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002750 status |= MBX_INTERRUPT;
2751
2752 break;
Arun Easifafbda92012-08-22 14:21:16 -04002753 case INTR_ASYNC_EVENT:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002754 mb[0] = MSW(stat);
2755 mb[1] = RD_REG_WORD(&reg->mailbox1);
2756 mb[2] = RD_REG_WORD(&reg->mailbox2);
2757 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002758 qla2x00_async_event(vha, rsp, mb);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002759 break;
Arun Easifafbda92012-08-22 14:21:16 -04002760 case INTR_RSP_QUE_UPDATE:
2761 case INTR_RSP_QUE_UPDATE_83XX:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002762 qla24xx_process_response_queue(vha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002763 break;
Arun Easifafbda92012-08-22 14:21:16 -04002764 case INTR_ATIO_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002765 qlt_24xx_process_atio_queue(vha);
2766 break;
Arun Easifafbda92012-08-22 14:21:16 -04002767 case INTR_ATIO_RSP_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002768 qlt_24xx_process_atio_queue(vha);
2769 qla24xx_process_response_queue(vha, rsp);
2770 break;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002771 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002772 ql_dbg(ql_dbg_async, vha, 0x5051,
2773 "Unrecognized interrupt type (%d).\n", stat & 0xff);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002774 break;
2775 }
2776 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002777 } while (0);
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -07002778 qla2x00_handle_mbx_completion(ha, status);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002779 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002780
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002781 return IRQ_HANDLED;
2782}
2783
2784/* Interrupt handling helpers. */
2785
2786struct qla_init_msix_entry {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002787 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07002788 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002789};
2790
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002791static struct qla_init_msix_entry msix_entries[3] = {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002792 { "qla2xxx (default)", qla24xx_msix_default },
2793 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002794 { "qla2xxx (multiq)", qla25xx_msix_rsp_q },
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002795};
2796
Giridhar Malavalia9083012010-04-12 17:59:55 -07002797static struct qla_init_msix_entry qla82xx_msix_entries[2] = {
2798 { "qla2xxx (default)", qla82xx_msix_default },
2799 { "qla2xxx (rsp_q)", qla82xx_msix_rsp_q },
2800};
2801
Arun Easiaa230bc2013-01-30 03:34:39 -05002802static struct qla_init_msix_entry qla83xx_msix_entries[3] = {
2803 { "qla2xxx (default)", qla24xx_msix_default },
2804 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
2805 { "qla2xxx (atio_q)", qla83xx_msix_atio_q },
2806};
2807
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002808static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002809qla24xx_disable_msix(struct qla_hw_data *ha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002810{
2811 int i;
2812 struct qla_msix_entry *qentry;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002813 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002814
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002815 for (i = 0; i < ha->msix_count; i++) {
2816 qentry = &ha->msix_entries[i];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002817 if (qentry->have_irq)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002818 free_irq(qentry->vector, qentry->rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002819 }
2820 pci_disable_msix(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002821 kfree(ha->msix_entries);
2822 ha->msix_entries = NULL;
2823 ha->flags.msix_enabled = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002824 ql_dbg(ql_dbg_init, vha, 0x0042,
2825 "Disabled the MSI.\n");
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002826}
2827
2828static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002829qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002830{
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002831#define MIN_MSIX_COUNT 2
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002832 int i, ret;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002833 struct msix_entry *entries;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002834 struct qla_msix_entry *qentry;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002835 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002836
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002837 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002838 GFP_KERNEL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002839 if (!entries) {
2840 ql_log(ql_log_warn, vha, 0x00bc,
2841 "Failed to allocate memory for msix_entry.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002842 return -ENOMEM;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002843 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002844
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002845 for (i = 0; i < ha->msix_count; i++)
2846 entries[i].entry = i;
2847
2848 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002849 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002850 if (ret < MIN_MSIX_COUNT)
2851 goto msix_failed;
2852
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002853 ql_log(ql_log_warn, vha, 0x00c6,
2854 "MSI-X: Failed to enable support "
2855 "-- %d/%d\n Retry with %d vectors.\n",
2856 ha->msix_count, ret, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002857 ha->msix_count = ret;
2858 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
2859 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002860msix_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002861 ql_log(ql_log_fatal, vha, 0x00c7,
2862 "MSI-X: Failed to enable support, "
2863 "giving up -- %d/%d.\n",
2864 ha->msix_count, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002865 goto msix_out;
2866 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002867 ha->max_rsp_queues = ha->msix_count - 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002868 }
2869 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
2870 ha->msix_count, GFP_KERNEL);
2871 if (!ha->msix_entries) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002872 ql_log(ql_log_fatal, vha, 0x00c8,
2873 "Failed to allocate memory for ha->msix_entries.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002874 ret = -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002875 goto msix_out;
2876 }
2877 ha->flags.msix_enabled = 1;
2878
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002879 for (i = 0; i < ha->msix_count; i++) {
2880 qentry = &ha->msix_entries[i];
2881 qentry->vector = entries[i].vector;
2882 qentry->entry = entries[i].entry;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002883 qentry->have_irq = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002884 qentry->rsp = NULL;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002885 }
2886
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002887 /* Enable MSI-X vectors for the base queue */
Arun Easiaa230bc2013-01-30 03:34:39 -05002888 for (i = 0; i < ha->msix_count; i++) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002889 qentry = &ha->msix_entries[i];
Arun Easiaa230bc2013-01-30 03:34:39 -05002890 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) {
2891 ret = request_irq(qentry->vector,
2892 qla83xx_msix_entries[i].handler,
2893 0, qla83xx_msix_entries[i].name, rsp);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002894 } else if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002895 ret = request_irq(qentry->vector,
2896 qla82xx_msix_entries[i].handler,
2897 0, qla82xx_msix_entries[i].name, rsp);
2898 } else {
2899 ret = request_irq(qentry->vector,
2900 msix_entries[i].handler,
2901 0, msix_entries[i].name, rsp);
2902 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002903 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002904 ql_log(ql_log_fatal, vha, 0x00cb,
2905 "MSI-X: unable to register handler -- %x/%d.\n",
2906 qentry->vector, ret);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002907 qla24xx_disable_msix(ha);
2908 ha->mqenable = 0;
2909 goto msix_out;
2910 }
2911 qentry->have_irq = 1;
2912 qentry->rsp = rsp;
2913 rsp->msix = qentry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002914 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002915
2916 /* Enable MSI-X vector for response queue update for queue 0 */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002917 if (IS_QLA83XX(ha)) {
2918 if (ha->msixbase && ha->mqiobase &&
2919 (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
2920 ha->mqenable = 1;
2921 } else
2922 if (ha->mqiobase
2923 && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
2924 ha->mqenable = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002925 ql_dbg(ql_dbg_multiq, vha, 0xc005,
2926 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
2927 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
2928 ql_dbg(ql_dbg_init, vha, 0x0055,
2929 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
2930 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002931
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002932msix_out:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002933 kfree(entries);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002934 return ret;
2935}
2936
2937int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002938qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002939{
Sawan Chandak7fa3e232013-10-30 03:38:10 -04002940 int ret = QLA_FUNCTION_FAILED;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002941 device_reg_t __iomem *reg = ha->iobase;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002942 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002943
2944 /* If possible, enable MSI-X. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002945 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002946 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha) && !IS_QLAFX00(ha))
Ben Hutchings6377a7a2010-03-19 16:59:19 -07002947 goto skip_msi;
2948
2949 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
2950 (ha->pdev->subsystem_device == 0x7040 ||
2951 ha->pdev->subsystem_device == 0x7041 ||
2952 ha->pdev->subsystem_device == 0x1705)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002953 ql_log(ql_log_warn, vha, 0x0034,
2954 "MSI-X: Unsupported ISP 2432 SSVID/SSDID (0x%X,0x%X).\n",
Ben Hutchings6377a7a2010-03-19 16:59:19 -07002955 ha->pdev->subsystem_vendor,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002956 ha->pdev->subsystem_device);
Ben Hutchings6377a7a2010-03-19 16:59:19 -07002957 goto skip_msi;
2958 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002959
Chad Dupuis42cd4f52011-08-16 11:29:24 -07002960 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002961 ql_log(ql_log_warn, vha, 0x0035,
2962 "MSI-X; Unsupported ISP2432 (0x%X, 0x%X).\n",
Chad Dupuis42cd4f52011-08-16 11:29:24 -07002963 ha->pdev->revision, QLA_MSIX_CHIP_REV_24XX);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002964 goto skip_msix;
2965 }
2966
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002967 ret = qla24xx_enable_msix(ha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002968 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002969 ql_dbg(ql_dbg_init, vha, 0x0036,
2970 "MSI-X: Enabled (0x%X, 0x%X).\n",
2971 ha->chip_revision, ha->fw_attributes);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002972 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002973 }
Sawan Chandak7fa3e232013-10-30 03:38:10 -04002974
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002975skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002976
Sawan Chandak7fa3e232013-10-30 03:38:10 -04002977 ql_log(ql_log_info, vha, 0x0037,
2978 "Falling back-to MSI mode -%d.\n", ret);
2979
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002980 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002981 !IS_QLA8001(ha) && !IS_P3P_TYPE(ha) && !IS_QLAFX00(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002982 goto skip_msi;
2983
2984 ret = pci_enable_msi(ha->pdev);
2985 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002986 ql_dbg(ql_dbg_init, vha, 0x0038,
2987 "MSI: Enabled.\n");
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002988 ha->flags.msi_enabled = 1;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002989 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002990 ql_log(ql_log_warn, vha, 0x0039,
Sawan Chandak7fa3e232013-10-30 03:38:10 -04002991 "Falling back-to INTa mode -- %d.\n", ret);
2992skip_msi:
Giridhar Malavalia033b652012-08-22 14:21:07 -04002993
2994 /* Skip INTx on ISP82xx. */
2995 if (!ha->flags.msi_enabled && IS_QLA82XX(ha))
2996 return QLA_FUNCTION_FAILED;
2997
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002998 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Mike Hernandez7992abf2010-11-23 16:52:47 -08002999 ha->flags.msi_enabled ? 0 : IRQF_SHARED,
3000 QLA2XXX_DRIVER_NAME, rsp);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003001 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003002 ql_log(ql_log_warn, vha, 0x003a,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003003 "Failed to reserve interrupt %d already in use.\n",
3004 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003005 goto fail;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003006 } else if (!ha->flags.msi_enabled) {
Saurav Kashyap68d91cb2012-11-21 02:40:44 -05003007 ql_dbg(ql_dbg_init, vha, 0x0125,
3008 "INTa mode: Enabled.\n");
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003009 ha->flags.mr_intr_valid = 1;
3010 }
Mike Hernandez7992abf2010-11-23 16:52:47 -08003011
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003012clear_risc_ints:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003013
Andrew Vasquezc6952482008-04-03 13:13:17 -07003014 spin_lock_irq(&ha->hardware_lock);
Giridhar Malavalic1114952012-08-22 14:21:33 -04003015 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003016 WRT_REG_WORD(&reg->isp.semaphore, 0);
Andrew Vasquezc6952482008-04-03 13:13:17 -07003017 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003018
3019fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003020 return ret;
3021}
3022
3023void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003024qla2x00_free_irqs(scsi_qla_host_t *vha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003025{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003026 struct qla_hw_data *ha = vha->hw;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003027 struct rsp_que *rsp;
3028
3029 /*
3030 * We need to check that ha->rsp_q_map is valid in case we are called
3031 * from a probe failure context.
3032 */
3033 if (!ha->rsp_q_map || !ha->rsp_q_map[0])
3034 return;
3035 rsp = ha->rsp_q_map[0];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003036
3037 if (ha->flags.msix_enabled)
3038 qla24xx_disable_msix(ha);
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003039 else if (ha->flags.msi_enabled) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003040 free_irq(ha->pdev->irq, rsp);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07003041 pci_disable_msi(ha->pdev);
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003042 } else
3043 free_irq(ha->pdev->irq, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003044}
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003045
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003046
3047int qla25xx_request_irq(struct rsp_que *rsp)
3048{
3049 struct qla_hw_data *ha = rsp->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003050 struct qla_init_msix_entry *intr = &msix_entries[2];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003051 struct qla_msix_entry *msix = rsp->msix;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003052 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003053 int ret;
3054
3055 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
3056 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003057 ql_log(ql_log_fatal, vha, 0x00e6,
3058 "MSI-X: Unable to register handler -- %x/%d.\n",
3059 msix->vector, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003060 return ret;
3061 }
3062 msix->have_irq = 1;
3063 msix->rsp = rsp;
3064 return ret;
3065}