blob: ea8641b47c86b8df3f216932f40af2404781d920 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Armen Baloyanbd21eaf2014-04-11 16:54:24 -04003 * Copyright (c) 2003-2014 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04008#include "qla_target.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Andrew Vasquez05236a02007-09-20 14:07:37 -070010#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070012#include <scsi/scsi_tcq.h>
Giridhar Malavali9a069e12010-01-12 13:02:47 -080013#include <scsi/scsi_bsg_fc.h>
Arun Easibad75002010-05-04 15:01:30 -070014#include <scsi/scsi_eh.h>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070015
Linus Torvalds1da177e2005-04-16 15:20:36 -070016static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080017static void qla2x00_status_entry(scsi_qla_host_t *, struct rsp_que *, void *);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070018static void qla2x00_status_cont_entry(struct rsp_que *, sts_cont_entry_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080019static void qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
20 sts_entry_t *);
Quinn Trancdb898c2015-12-17 14:57:05 -050021static void qla_irq_affinity_notify(struct irq_affinity_notify *,
22 const cpumask_t *);
23static void qla_irq_affinity_release(struct kref *);
24
Andrew Vasquez9a853f72005-07-06 10:31:27 -070025
Linus Torvalds1da177e2005-04-16 15:20:36 -070026/**
27 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
28 * @irq:
29 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 *
31 * Called by system whenever the host adapter generates an interrupt.
32 *
33 * Returns handled flag.
34 */
35irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +010036qla2100_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080038 scsi_qla_host_t *vha;
39 struct qla_hw_data *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -070040 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 unsigned long iter;
Seokmann Ju14e660e2007-09-20 14:07:36 -070043 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070044 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080045 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070046 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080048 rsp = (struct rsp_que *) dev_id;
49 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -080050 ql_log(ql_log_info, NULL, 0x505d,
51 "%s: NULL response queue pointer.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 return (IRQ_NONE);
53 }
54
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080055 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -070056 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 status = 0;
58
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070059 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070060 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 for (iter = 50; iter--; ) {
Seokmann Ju14e660e2007-09-20 14:07:36 -070062 hccr = RD_REG_WORD(&reg->hccr);
Joe Lawrencec821e0d2014-08-26 17:11:41 -040063 if (qla2x00_check_reg16_for_disconnect(vha, hccr))
Chad Dupuisf3ddac12013-10-30 03:38:16 -040064 break;
Seokmann Ju14e660e2007-09-20 14:07:36 -070065 if (hccr & HCCR_RISC_PAUSE) {
66 if (pci_channel_offline(ha->pdev))
67 break;
68
69 /*
70 * Issue a "HARD" reset in order for the RISC interrupt
Justin P. Mattocka06a0f82011-06-23 23:22:27 -070071 * bit to be cleared. Schedule a big hammer to get
Seokmann Ju14e660e2007-09-20 14:07:36 -070072 * out of the RISC PAUSED state.
73 */
74 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
75 RD_REG_WORD(&reg->hccr);
76
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080077 ha->isp_ops->fw_dump(vha, 1);
78 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -070079 break;
80 } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 break;
82
83 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
84 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
85 RD_REG_WORD(&reg->hccr);
86
87 /* Get mailbox data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -070088 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
89 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080090 qla2x00_mbx_completion(vha, mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 status |= MBX_INTERRUPT;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070092 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
93 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
94 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
95 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080096 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 } else {
98 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -070099 ql_dbg(ql_dbg_async, vha, 0x5025,
100 "Unrecognized interrupt type (%d).\n",
101 mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 }
103 /* Release mailbox registers. */
104 WRT_REG_WORD(&reg->semaphore, 0);
105 RD_REG_WORD(&reg->semaphore);
106 } else {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800107 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
110 RD_REG_WORD(&reg->hccr);
111 }
112 }
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -0700113 qla2x00_handle_mbx_completion(ha, status);
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700114 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 return (IRQ_HANDLED);
117}
118
Chad Dupuisf3ddac12013-10-30 03:38:16 -0400119bool
Joe Lawrencec821e0d2014-08-26 17:11:41 -0400120qla2x00_check_reg32_for_disconnect(scsi_qla_host_t *vha, uint32_t reg)
Chad Dupuisf3ddac12013-10-30 03:38:16 -0400121{
122 /* Check for PCI disconnection */
Thadeu Lima de Souza Cascardoa30c2a32015-04-30 09:13:05 -0300123 if (reg == 0xffffffff && !pci_channel_offline(vha->hw->pdev)) {
Joe Lawrencebeb9e312014-08-26 17:12:14 -0400124 if (!test_and_set_bit(PFLG_DISCONNECTED, &vha->pci_flags) &&
Joe Lawrence6b383972014-08-26 17:12:29 -0400125 !test_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags) &&
126 !test_bit(PFLG_DRIVER_PROBING, &vha->pci_flags)) {
Joe Lawrence232792b2014-08-26 17:12:01 -0400127 /*
128 * Schedule this (only once) on the default system
129 * workqueue so that all the adapter workqueues and the
130 * DPC thread can be shutdown cleanly.
131 */
132 schedule_work(&vha->hw->board_disable);
133 }
Chad Dupuisf3ddac12013-10-30 03:38:16 -0400134 return true;
135 } else
136 return false;
137}
138
Joe Lawrencec821e0d2014-08-26 17:11:41 -0400139bool
140qla2x00_check_reg16_for_disconnect(scsi_qla_host_t *vha, uint16_t reg)
141{
142 return qla2x00_check_reg32_for_disconnect(vha, 0xffff0000 | reg);
143}
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/**
146 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
147 * @irq:
148 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 *
150 * Called by system whenever the host adapter generates an interrupt.
151 *
152 * Returns handled flag.
153 */
154irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100155qla2300_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800157 scsi_qla_host_t *vha;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700158 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 unsigned long iter;
161 uint32_t stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700163 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800164 struct rsp_que *rsp;
165 struct qla_hw_data *ha;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700166 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800168 rsp = (struct rsp_que *) dev_id;
169 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -0800170 ql_log(ql_log_info, NULL, 0x5058,
171 "%s: NULL response queue pointer.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 return (IRQ_NONE);
173 }
174
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800175 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700176 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 status = 0;
178
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700179 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700180 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 for (iter = 50; iter--; ) {
182 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
Joe Lawrencec821e0d2014-08-26 17:11:41 -0400183 if (qla2x00_check_reg32_for_disconnect(vha, stat))
Chad Dupuisf3ddac12013-10-30 03:38:16 -0400184 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 if (stat & HSR_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800186 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -0700187 break;
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 hccr = RD_REG_WORD(&reg->hccr);
Chad Dupuisf3ddac12013-10-30 03:38:16 -0400190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700192 ql_log(ql_log_warn, vha, 0x5026,
193 "Parity error -- HCCR=%x, Dumping "
194 "firmware.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700196 ql_log(ql_log_warn, vha, 0x5027,
197 "RISC paused -- HCCR=%x, Dumping "
198 "firmware.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 /*
201 * Issue a "HARD" reset in order for the RISC
202 * interrupt bit to be cleared. Schedule a big
Justin P. Mattocka06a0f82011-06-23 23:22:27 -0700203 * hammer to get out of the RISC PAUSED state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 */
205 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
206 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800207
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800208 ha->isp_ops->fw_dump(vha, 1);
209 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 break;
211 } else if ((stat & HSR_RISC_INT) == 0)
212 break;
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 case 0x1:
216 case 0x2:
217 case 0x10:
218 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800219 qla2x00_mbx_completion(vha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 status |= MBX_INTERRUPT;
221
222 /* Release mailbox registers. */
223 WRT_REG_WORD(&reg->semaphore, 0);
224 break;
225 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700226 mb[0] = MSW(stat);
227 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
228 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
229 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800230 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700231 break;
232 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800233 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 break;
235 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700236 mb[0] = MBA_CMPLT_1_16BIT;
237 mb[1] = MSW(stat);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800238 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 break;
240 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700241 mb[0] = MBA_SCSI_COMPLETION;
242 mb[1] = MSW(stat);
243 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800244 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 break;
246 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700247 ql_dbg(ql_dbg_async, vha, 0x5028,
248 "Unrecognized interrupt type (%d).\n", stat & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 break;
250 }
251 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
252 RD_REG_WORD_RELAXED(&reg->hccr);
253 }
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -0700254 qla2x00_handle_mbx_completion(ha, status);
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700255 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 return (IRQ_HANDLED);
258}
259
260/**
261 * qla2x00_mbx_completion() - Process mailbox command completions.
262 * @ha: SCSI driver HA context
263 * @mb0: Mailbox0 register
264 */
265static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800266qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
268 uint16_t cnt;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800269 uint32_t mboxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800271 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700272 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800274 /* Read all mbox registers? */
275 mboxes = (1 << ha->mbx_count) - 1;
276 if (!ha->mcp)
Masanari Iidaa7201012012-11-21 02:40:42 -0500277 ql_dbg(ql_dbg_async, vha, 0x5001, "MBX pointer ERROR.\n");
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800278 else
279 mboxes = ha->mcp->in_mb;
280
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 /* Load return mailbox registers. */
282 ha->flags.mbox_int = 1;
283 ha->mailbox_out[0] = mb0;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800284 mboxes >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
286
287 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700288 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800290 if ((cnt == 4 || cnt == 5) && (mboxes & BIT_0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800292 else if (mboxes & BIT_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 wptr++;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800296 mboxes >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
299
Andrew Vasquez8a659572009-02-08 20:50:12 -0800300static void
301qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
302{
303 static char *event[] =
304 { "Complete", "Request Notification", "Time Extension" };
305 int rval;
306 struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
Chad Dupuis9e5054e2013-10-30 03:38:23 -0400307 struct device_reg_82xx __iomem *reg82 = &vha->hw->iobase->isp82;
Andrew Vasquez8a659572009-02-08 20:50:12 -0800308 uint16_t __iomem *wptr;
309 uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
310
311 /* Seed data -- mailbox1 -> mailbox7. */
Chad Dupuis9e5054e2013-10-30 03:38:23 -0400312 if (IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw))
313 wptr = (uint16_t __iomem *)&reg24->mailbox1;
314 else if (IS_QLA8044(vha->hw))
315 wptr = (uint16_t __iomem *)&reg82->mailbox_out[1];
316 else
317 return;
318
Andrew Vasquez8a659572009-02-08 20:50:12 -0800319 for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
320 mb[cnt] = RD_REG_WORD(wptr);
321
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700322 ql_dbg(ql_dbg_async, vha, 0x5021,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800323 "Inter-Driver Communication %s -- "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700324 "%04x %04x %04x %04x %04x %04x %04x.\n",
325 event[aen & 0xff], mb[0], mb[1], mb[2], mb[3],
326 mb[4], mb[5], mb[6]);
Santosh Vernekar454073c2013-08-27 01:37:48 -0400327 switch (aen) {
328 /* Handle IDC Error completion case. */
329 case MBA_IDC_COMPLETE:
330 if (mb[1] >> 15) {
331 vha->hw->flags.idc_compl_status = 1;
Chad Dupuis9aaf2ce2013-10-30 03:38:25 -0400332 if (vha->hw->notify_dcbx_comp && !vha->vp_idx)
Santosh Vernekar454073c2013-08-27 01:37:48 -0400333 complete(&vha->hw->dcbx_comp);
334 }
335 break;
336
337 case MBA_IDC_NOTIFY:
338 /* Acknowledgement needed? [Notify && non-zero timeout]. */
339 timeout = (descr >> 8) & 0xf;
340 ql_dbg(ql_dbg_async, vha, 0x5022,
341 "%lu Inter-Driver Communication %s -- ACK timeout=%d.\n",
342 vha->host_no, event[aen & 0xff], timeout);
343
344 if (!timeout)
345 return;
346 rval = qla2x00_post_idc_ack_work(vha, mb);
347 if (rval != QLA_SUCCESS)
348 ql_log(ql_log_warn, vha, 0x5023,
349 "IDC failed to post ACK.\n");
350 break;
351 case MBA_IDC_TIME_EXT:
352 vha->hw->idc_extend_tmo = descr;
353 ql_dbg(ql_dbg_async, vha, 0x5087,
354 "%lu Inter-Driver Communication %s -- "
355 "Extend timeout by=%d.\n",
356 vha->host_no, event[aen & 0xff], vha->hw->idc_extend_tmo);
357 break;
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400358 }
Andrew Vasquez8a659572009-02-08 20:50:12 -0800359}
360
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400361#define LS_UNKNOWN 2
Joe Carnucciod0297c92012-11-21 02:40:40 -0500362const char *
363qla2x00_get_link_speed_str(struct qla_hw_data *ha, uint16_t speed)
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400364{
Chad Dupuisf73cb692014-02-26 04:15:06 -0500365 static const char *const link_speeds[] = {
366 "1", "2", "?", "4", "8", "16", "32", "10"
Joe Carnucciod0297c92012-11-21 02:40:40 -0500367 };
Chad Dupuisf73cb692014-02-26 04:15:06 -0500368#define QLA_LAST_SPEED 7
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400369
370 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Joe Carnucciod0297c92012-11-21 02:40:40 -0500371 return link_speeds[0];
372 else if (speed == 0x13)
Chad Dupuisf73cb692014-02-26 04:15:06 -0500373 return link_speeds[QLA_LAST_SPEED];
374 else if (speed < QLA_LAST_SPEED)
Joe Carnucciod0297c92012-11-21 02:40:40 -0500375 return link_speeds[speed];
376 else
377 return link_speeds[LS_UNKNOWN];
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400378}
379
Saurav Kashyapfa492632012-11-21 02:40:29 -0500380static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400381qla83xx_handle_8200_aen(scsi_qla_host_t *vha, uint16_t *mb)
382{
383 struct qla_hw_data *ha = vha->hw;
384
385 /*
386 * 8200 AEN Interpretation:
387 * mb[0] = AEN code
388 * mb[1] = AEN Reason code
389 * mb[2] = LSW of Peg-Halt Status-1 Register
390 * mb[6] = MSW of Peg-Halt Status-1 Register
391 * mb[3] = LSW of Peg-Halt Status-2 register
392 * mb[7] = MSW of Peg-Halt Status-2 register
393 * mb[4] = IDC Device-State Register value
394 * mb[5] = IDC Driver-Presence Register value
395 */
396 ql_dbg(ql_dbg_async, vha, 0x506b, "AEN Code: mb[0] = 0x%x AEN reason: "
397 "mb[1] = 0x%x PH-status1: mb[2] = 0x%x PH-status1: mb[6] = 0x%x.\n",
398 mb[0], mb[1], mb[2], mb[6]);
399 ql_dbg(ql_dbg_async, vha, 0x506c, "PH-status2: mb[3] = 0x%x "
400 "PH-status2: mb[7] = 0x%x Device-State: mb[4] = 0x%x "
401 "Drv-Presence: mb[5] = 0x%x.\n", mb[3], mb[7], mb[4], mb[5]);
402
403 if (mb[1] & (IDC_PEG_HALT_STATUS_CHANGE | IDC_NIC_FW_REPORTED_FAILURE |
404 IDC_HEARTBEAT_FAILURE)) {
405 ha->flags.nic_core_hung = 1;
406 ql_log(ql_log_warn, vha, 0x5060,
407 "83XX: F/W Error Reported: Check if reset required.\n");
408
409 if (mb[1] & IDC_PEG_HALT_STATUS_CHANGE) {
410 uint32_t protocol_engine_id, fw_err_code, err_level;
411
412 /*
413 * IDC_PEG_HALT_STATUS_CHANGE interpretation:
414 * - PEG-Halt Status-1 Register:
415 * (LSW = mb[2], MSW = mb[6])
416 * Bits 0-7 = protocol-engine ID
417 * Bits 8-28 = f/w error code
418 * Bits 29-31 = Error-level
419 * Error-level 0x1 = Non-Fatal error
420 * Error-level 0x2 = Recoverable Fatal error
421 * Error-level 0x4 = UnRecoverable Fatal error
422 * - PEG-Halt Status-2 Register:
423 * (LSW = mb[3], MSW = mb[7])
424 */
425 protocol_engine_id = (mb[2] & 0xff);
426 fw_err_code = (((mb[2] & 0xff00) >> 8) |
427 ((mb[6] & 0x1fff) << 8));
428 err_level = ((mb[6] & 0xe000) >> 13);
429 ql_log(ql_log_warn, vha, 0x5061, "PegHalt Status-1 "
430 "Register: protocol_engine_id=0x%x "
431 "fw_err_code=0x%x err_level=0x%x.\n",
432 protocol_engine_id, fw_err_code, err_level);
433 ql_log(ql_log_warn, vha, 0x5062, "PegHalt Status-2 "
434 "Register: 0x%x%x.\n", mb[7], mb[3]);
435 if (err_level == ERR_LEVEL_NON_FATAL) {
436 ql_log(ql_log_warn, vha, 0x5063,
437 "Not a fatal error, f/w has recovered "
438 "iteself.\n");
439 } else if (err_level == ERR_LEVEL_RECOVERABLE_FATAL) {
440 ql_log(ql_log_fatal, vha, 0x5064,
441 "Recoverable Fatal error: Chip reset "
442 "required.\n");
443 qla83xx_schedule_work(vha,
444 QLA83XX_NIC_CORE_RESET);
445 } else if (err_level == ERR_LEVEL_UNRECOVERABLE_FATAL) {
446 ql_log(ql_log_fatal, vha, 0x5065,
447 "Unrecoverable Fatal error: Set FAILED "
448 "state, reboot required.\n");
449 qla83xx_schedule_work(vha,
450 QLA83XX_NIC_CORE_UNRECOVERABLE);
451 }
452 }
453
454 if (mb[1] & IDC_NIC_FW_REPORTED_FAILURE) {
455 uint16_t peg_fw_state, nw_interface_link_up;
456 uint16_t nw_interface_signal_detect, sfp_status;
457 uint16_t htbt_counter, htbt_monitor_enable;
458 uint16_t sfp_additonal_info, sfp_multirate;
459 uint16_t sfp_tx_fault, link_speed, dcbx_status;
460
461 /*
462 * IDC_NIC_FW_REPORTED_FAILURE interpretation:
463 * - PEG-to-FC Status Register:
464 * (LSW = mb[2], MSW = mb[6])
465 * Bits 0-7 = Peg-Firmware state
466 * Bit 8 = N/W Interface Link-up
467 * Bit 9 = N/W Interface signal detected
468 * Bits 10-11 = SFP Status
469 * SFP Status 0x0 = SFP+ transceiver not expected
470 * SFP Status 0x1 = SFP+ transceiver not present
471 * SFP Status 0x2 = SFP+ transceiver invalid
472 * SFP Status 0x3 = SFP+ transceiver present and
473 * valid
474 * Bits 12-14 = Heartbeat Counter
475 * Bit 15 = Heartbeat Monitor Enable
476 * Bits 16-17 = SFP Additional Info
477 * SFP info 0x0 = Unregocnized transceiver for
478 * Ethernet
479 * SFP info 0x1 = SFP+ brand validation failed
480 * SFP info 0x2 = SFP+ speed validation failed
481 * SFP info 0x3 = SFP+ access error
482 * Bit 18 = SFP Multirate
483 * Bit 19 = SFP Tx Fault
484 * Bits 20-22 = Link Speed
485 * Bits 23-27 = Reserved
486 * Bits 28-30 = DCBX Status
487 * DCBX Status 0x0 = DCBX Disabled
488 * DCBX Status 0x1 = DCBX Enabled
489 * DCBX Status 0x2 = DCBX Exchange error
490 * Bit 31 = Reserved
491 */
492 peg_fw_state = (mb[2] & 0x00ff);
493 nw_interface_link_up = ((mb[2] & 0x0100) >> 8);
494 nw_interface_signal_detect = ((mb[2] & 0x0200) >> 9);
495 sfp_status = ((mb[2] & 0x0c00) >> 10);
496 htbt_counter = ((mb[2] & 0x7000) >> 12);
497 htbt_monitor_enable = ((mb[2] & 0x8000) >> 15);
498 sfp_additonal_info = (mb[6] & 0x0003);
499 sfp_multirate = ((mb[6] & 0x0004) >> 2);
500 sfp_tx_fault = ((mb[6] & 0x0008) >> 3);
501 link_speed = ((mb[6] & 0x0070) >> 4);
502 dcbx_status = ((mb[6] & 0x7000) >> 12);
503
504 ql_log(ql_log_warn, vha, 0x5066,
505 "Peg-to-Fc Status Register:\n"
506 "peg_fw_state=0x%x, nw_interface_link_up=0x%x, "
507 "nw_interface_signal_detect=0x%x"
508 "\nsfp_statis=0x%x.\n ", peg_fw_state,
509 nw_interface_link_up, nw_interface_signal_detect,
510 sfp_status);
511 ql_log(ql_log_warn, vha, 0x5067,
512 "htbt_counter=0x%x, htbt_monitor_enable=0x%x, "
513 "sfp_additonal_info=0x%x, sfp_multirate=0x%x.\n ",
514 htbt_counter, htbt_monitor_enable,
515 sfp_additonal_info, sfp_multirate);
516 ql_log(ql_log_warn, vha, 0x5068,
517 "sfp_tx_fault=0x%x, link_state=0x%x, "
518 "dcbx_status=0x%x.\n", sfp_tx_fault, link_speed,
519 dcbx_status);
520
521 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
522 }
523
524 if (mb[1] & IDC_HEARTBEAT_FAILURE) {
525 ql_log(ql_log_warn, vha, 0x5069,
526 "Heartbeat Failure encountered, chip reset "
527 "required.\n");
528
529 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
530 }
531 }
532
533 if (mb[1] & IDC_DEVICE_STATE_CHANGE) {
534 ql_log(ql_log_info, vha, 0x506a,
535 "IDC Device-State changed = 0x%x.\n", mb[4]);
Saurav Kashyap6c3943c2013-02-08 01:58:02 -0500536 if (ha->flags.nic_core_reset_owner)
537 return;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400538 qla83xx_schedule_work(vha, MBA_IDC_AEN);
539 }
540}
541
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -0500542int
543qla2x00_is_a_vp_did(scsi_qla_host_t *vha, uint32_t rscn_entry)
544{
545 struct qla_hw_data *ha = vha->hw;
546 scsi_qla_host_t *vp;
547 uint32_t vp_did;
548 unsigned long flags;
549 int ret = 0;
550
551 if (!ha->num_vhosts)
552 return ret;
553
554 spin_lock_irqsave(&ha->vport_slock, flags);
555 list_for_each_entry(vp, &ha->vp_list, list) {
556 vp_did = vp->d_id.b24;
557 if (vp_did == rscn_entry) {
558 ret = 1;
559 break;
560 }
561 }
562 spin_unlock_irqrestore(&ha->vport_slock, flags);
563
564 return ret;
565}
566
Joe Carnuccio17cac3a2015-08-04 13:37:52 -0400567static inline fc_port_t *
568qla2x00_find_fcport_by_loopid(scsi_qla_host_t *vha, uint16_t loop_id)
569{
570 fc_port_t *fcport;
571
572 list_for_each_entry(fcport, &vha->vp_fcports, list)
573 if (fcport->loop_id == loop_id)
574 return fcport;
575 return NULL;
576}
577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578/**
579 * qla2x00_async_event() - Process aynchronous events.
580 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700581 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700583void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800584qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 uint16_t handle_cnt;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700587 uint16_t cnt, mbx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 uint32_t handles[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800589 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700590 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700591 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
Andrew Vasquezbc5c2aa2010-12-21 16:00:24 -0800592 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Bart Van Assche52c82822015-07-09 07:23:26 -0700593 uint32_t rscn_entry, host_pid;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700594 unsigned long flags;
Chad Dupuisef86cb22014-09-25 05:17:01 -0400595 fc_port_t *fcport = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
597 /* Setup to process RIO completion. */
598 handle_cnt = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800599 if (IS_CNA_CAPABLE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800600 goto skip_rio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 switch (mb[0]) {
602 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700603 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 handle_cnt = 1;
605 break;
606 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700607 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 handle_cnt = 1;
609 mb[0] = MBA_SCSI_COMPLETION;
610 break;
611 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700612 handles[0] = mb[1];
613 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 handle_cnt = 2;
615 mb[0] = MBA_SCSI_COMPLETION;
616 break;
617 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700618 handles[0] = mb[1];
619 handles[1] = mb[2];
620 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 handle_cnt = 3;
622 mb[0] = MBA_SCSI_COMPLETION;
623 break;
624 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700625 handles[0] = mb[1];
626 handles[1] = mb[2];
627 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
629 handle_cnt = 4;
630 mb[0] = MBA_SCSI_COMPLETION;
631 break;
632 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700633 handles[0] = mb[1];
634 handles[1] = mb[2];
635 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
637 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
638 handle_cnt = 5;
639 mb[0] = MBA_SCSI_COMPLETION;
640 break;
641 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700642 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 handles[1] = le32_to_cpu(
644 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
645 RD_MAILBOX_REG(ha, reg, 6));
646 handle_cnt = 2;
647 mb[0] = MBA_SCSI_COMPLETION;
648 break;
649 default:
650 break;
651 }
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800652skip_rio:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 switch (mb[0]) {
654 case MBA_SCSI_COMPLETION: /* Fast Post */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800655 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 break;
657
658 for (cnt = 0; cnt < handle_cnt; cnt++)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800659 qla2x00_process_completed_request(vha, rsp->req,
660 handles[cnt]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 break;
662
663 case MBA_RESET: /* Reset */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700664 ql_dbg(ql_dbg_async, vha, 0x5002,
665 "Asynchronous RESET.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800667 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 break;
669
670 case MBA_SYSTEM_ERR: /* System Error */
Chad Dupuisf73cb692014-02-26 04:15:06 -0500671 mbx = (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) ?
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800672 RD_REG_WORD(&reg24->mailbox7) : 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700673 ql_log(ql_log_warn, vha, 0x5003,
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700674 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh "
675 "mbx7=%xh.\n", mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800677 ha->isp_ops->fw_dump(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Andrew Vasqueze4289242007-07-19 15:05:56 -0700679 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700680 if (mb[1] == 0 && mb[2] == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700681 ql_log(ql_log_fatal, vha, 0x5004,
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700682 "Unrecoverable Hardware Error: adapter "
683 "marked OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800684 vha->flags.online = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800685 vha->device_flags |= DFLG_DEV_FAILED;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700686 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300687 /* Check to see if MPI timeout occurred */
Chad Dupuisf73cb692014-02-26 04:15:06 -0500688 if ((mbx & MBX_3) && (ha->port_no == 0))
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700689 set_bit(MPI_RESET_NEEDED,
690 &vha->dpc_flags);
691
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800692 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700693 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700694 } else if (mb[1] == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700695 ql_log(ql_log_fatal, vha, 0x5005,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 "Unrecoverable Hardware Error: adapter marked "
697 "OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800698 vha->flags.online = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800699 vha->device_flags |= DFLG_DEV_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800701 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 break;
703
704 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700705 ql_log(ql_log_warn, vha, 0x5006,
706 "ISP Request Transfer Error (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800708 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 break;
710
711 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700712 ql_log(ql_log_warn, vha, 0x5007,
713 "ISP Response Transfer Error.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800715 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 break;
717
718 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700719 ql_dbg(ql_dbg_async, vha, 0x5008,
720 "Asynchronous WAKEUP_THRES.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400722 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Chad Dupuiscfb09192011-11-18 09:03:07 -0800724 ql_dbg(ql_dbg_async, vha, 0x5009,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700725 "LIP occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800727 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
728 atomic_set(&vha->loop_state, LOOP_DOWN);
729 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
730 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 }
732
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800733 if (vha->vp_idx) {
734 atomic_set(&vha->vp_state, VP_FAILED);
735 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700736 }
737
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800738 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
739 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800741 vha->flags.management_server_logged_in = 0;
742 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 break;
744
745 case MBA_LOOP_UP: /* Loop Up Event */
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400746 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700747 ha->link_data_rate = PORT_SPEED_1GB;
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400748 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 ha->link_data_rate = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
Chad Dupuis8e5a9482014-08-08 07:38:09 -0400751 ql_log(ql_log_info, vha, 0x500a,
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400752 "LOOP UP detected (%s Gbps).\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -0500753 qla2x00_get_link_speed_str(ha, ha->link_data_rate));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800755 vha->flags.management_server_logged_in = 0;
756 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 break;
758
759 case MBA_LOOP_DOWN: /* Loop Down Event */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800760 mbx = (IS_QLA81XX(ha) || IS_QLA8031(ha))
761 ? RD_REG_WORD(&reg24->mailbox4) : 0;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400762 mbx = (IS_P3P_TYPE(ha)) ? RD_REG_WORD(&reg82->mailbox_out[4])
763 : mbx;
Chad Dupuis8e5a9482014-08-08 07:38:09 -0400764 ql_log(ql_log_info, vha, 0x500b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700765 "LOOP DOWN detected (%x %x %x %x).\n",
766 mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800768 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
769 atomic_set(&vha->loop_state, LOOP_DOWN);
770 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
Himanshu Madhani2486c622014-09-25 05:17:00 -0400771 /*
772 * In case of loop down, restore WWPN from
773 * NVRAM in case of FA-WWPN capable ISP
Sawan Chandak718abbd2015-04-09 15:00:07 -0400774 * Restore for Physical Port only
Himanshu Madhani2486c622014-09-25 05:17:00 -0400775 */
Sawan Chandak718abbd2015-04-09 15:00:07 -0400776 if (!vha->vp_idx) {
777 if (ha->flags.fawwpn_enabled) {
778 void *wwpn = ha->init_cb->port_name;
779 memcpy(vha->port_name, wwpn, WWN_SIZE);
780 fc_host_port_name(vha->host) =
781 wwn_to_u64(vha->port_name);
782 ql_dbg(ql_dbg_init + ql_dbg_verbose,
783 vha, 0x0144, "LOOP DOWN detected,"
784 "restore WWPN %016llx\n",
785 wwn_to_u64(vha->port_name));
786 }
Himanshu Madhani2486c622014-09-25 05:17:00 -0400787
Sawan Chandak718abbd2015-04-09 15:00:07 -0400788 clear_bit(VP_CONFIG_OK, &vha->vp_flags);
Himanshu Madhani2486c622014-09-25 05:17:00 -0400789 }
790
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800791 vha->device_flags |= DFLG_NO_CABLE;
792 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 }
794
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800795 if (vha->vp_idx) {
796 atomic_set(&vha->vp_state, VP_FAILED);
797 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700798 }
799
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800800 vha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700801 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800802 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 break;
804
805 case MBA_LIP_RESET: /* LIP reset occurred */
Chad Dupuiscfb09192011-11-18 09:03:07 -0800806 ql_dbg(ql_dbg_async, vha, 0x500c,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700807 "LIP reset occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800809 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
810 atomic_set(&vha->loop_state, LOOP_DOWN);
811 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
812 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 }
814
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800815 if (vha->vp_idx) {
816 atomic_set(&vha->vp_state, VP_FAILED);
817 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700818 }
819
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800820 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
822 ha->operating_mode = LOOP;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800823 vha->flags.management_server_logged_in = 0;
824 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 break;
826
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800827 /* case MBA_DCBX_COMPLETE: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 case MBA_POINT_TO_POINT: /* Point-to-Point */
829 if (IS_QLA2100(ha))
830 break;
831
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400832 if (IS_CNA_CAPABLE(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700833 ql_dbg(ql_dbg_async, vha, 0x500d,
834 "DCBX Completed -- %04x %04x %04x.\n",
835 mb[1], mb[2], mb[3]);
Chad Dupuis9aaf2ce2013-10-30 03:38:25 -0400836 if (ha->notify_dcbx_comp && !vha->vp_idx)
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700837 complete(&ha->dcbx_comp);
838
839 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700840 ql_dbg(ql_dbg_async, vha, 0x500e,
841 "Asynchronous P2P MODE received.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 /*
844 * Until there's a transition from loop down to loop up, treat
845 * this as loop down only.
846 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800847 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
848 atomic_set(&vha->loop_state, LOOP_DOWN);
849 if (!atomic_read(&vha->loop_down_timer))
850 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800852 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 }
854
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800855 if (vha->vp_idx) {
856 atomic_set(&vha->vp_state, VP_FAILED);
857 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700858 }
859
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800860 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
861 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
862
863 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
864 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800865
866 ha->flags.gpsc_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800867 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 break;
869
870 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
871 if (IS_QLA2100(ha))
872 break;
873
Chad Dupuiscfb09192011-11-18 09:03:07 -0800874 ql_dbg(ql_dbg_async, vha, 0x500f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 "Configuration change detected: value=%x.\n", mb[1]);
876
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800877 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
878 atomic_set(&vha->loop_state, LOOP_DOWN);
879 if (!atomic_read(&vha->loop_down_timer))
880 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800882 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 }
884
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800885 if (vha->vp_idx) {
886 atomic_set(&vha->vp_state, VP_FAILED);
887 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700888 }
889
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800890 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
891 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 break;
893
894 case MBA_PORT_UPDATE: /* Port database update */
Santosh Vernekar55903b92009-07-31 15:09:25 -0700895 /*
896 * Handle only global and vn-port update events
897 *
898 * Relevant inputs:
899 * mb[1] = N_Port handle of changed port
900 * OR 0xffff for global event
901 * mb[2] = New login state
902 * 7 = Port logged out
903 * mb[3] = LSB is vp_idx, 0xff = all vps
904 *
905 * Skip processing if:
906 * Event is global, vp_idx is NOT all vps,
907 * vp_idx does not match
908 * Event is not global, vp_idx does not match
909 */
Andrew Vasquez12cec63e42010-03-19 16:59:17 -0700910 if (IS_QLA2XXX_MIDTYPE(ha) &&
911 ((mb[1] == 0xffff && (mb[3] & 0xff) != 0xff) ||
912 (mb[1] != 0xffff)) && vha->vp_idx != (mb[3] & 0xff))
913 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800914
Joe Carnuccio17cac3a2015-08-04 13:37:52 -0400915 if (mb[2] == 0x7) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700916 ql_dbg(ql_dbg_async, vha, 0x5010,
Joe Carnuccio17cac3a2015-08-04 13:37:52 -0400917 "Port %s %04x %04x %04x.\n",
918 mb[1] == 0xffff ? "unavailable" : "logout",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700919 mb[1], mb[2], mb[3]);
Joe Carnuccio17cac3a2015-08-04 13:37:52 -0400920
921 if (mb[1] == 0xffff)
922 goto global_port_update;
923
924 /* Port logout */
925 fcport = qla2x00_find_fcport_by_loopid(vha, mb[1]);
926 if (!fcport)
927 break;
928 if (atomic_read(&fcport->state) != FCS_ONLINE)
929 break;
930 ql_dbg(ql_dbg_async, vha, 0x508a,
931 "Marking port lost loopid=%04x portid=%06x.\n",
932 fcport->loop_id, fcport->d_id.b24);
933 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
934 break;
935
936global_port_update:
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700937 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
938 atomic_set(&vha->loop_state, LOOP_DOWN);
939 atomic_set(&vha->loop_down_timer,
940 LOOP_DOWN_TIME);
941 vha->device_flags |= DFLG_NO_CABLE;
942 qla2x00_mark_all_devices_lost(vha, 1);
943 }
944
945 if (vha->vp_idx) {
946 atomic_set(&vha->vp_state, VP_FAILED);
947 fc_vport_set_state(vha->fc_vport,
948 FC_VPORT_FAILED);
Santosh Vernekarfaadc5e2009-07-31 15:09:26 -0700949 qla2x00_mark_all_devices_lost(vha, 1);
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700950 }
951
952 vha->flags.management_server_logged_in = 0;
953 ha->link_data_rate = PORT_SPEED_UNKNOWN;
954 break;
955 }
956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 /*
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700958 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 * event etc. earlier indicating loop is down) then process
960 * it. Otherwise ignore it and Wait for RSCN to come in.
961 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800962 atomic_set(&vha->loop_down_timer, 0);
Chad Dupuis8e5a9482014-08-08 07:38:09 -0400963 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
964 atomic_read(&vha->loop_state) != LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700965 ql_dbg(ql_dbg_async, vha, 0x5011,
966 "Asynchronous PORT UPDATE ignored %04x/%04x/%04x.\n",
967 mb[1], mb[2], mb[3]);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400968
969 qlt_async_event(mb[0], vha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 break;
971 }
972
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700973 ql_dbg(ql_dbg_async, vha, 0x5012,
974 "Port database changed %04x %04x %04x.\n",
975 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977 /*
978 * Mark all devices as missing so we will login again.
979 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800980 atomic_set(&vha->loop_state, LOOP_UP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800982 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400984 if (vha->vp_idx == 0 && !qla_ini_mode_enabled(vha))
985 set_bit(SCR_PENDING, &vha->dpc_flags);
986
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800987 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
988 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Sawan Chandakded64112015-04-09 15:00:06 -0400989 set_bit(VP_CONFIG_OK, &vha->vp_flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400990
991 qlt_async_event(mb[0], vha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 break;
993
994 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju3c397402008-05-19 14:25:39 -0700995 /* Check if the Vport has issued a SCR */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800996 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
Seokmann Ju3c397402008-05-19 14:25:39 -0700997 break;
998 /* Only handle SCNs for our Vport index. */
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700999 if (ha->flags.npiv_supported && vha->vp_idx != (mb[3] & 0xff))
Seokmann Ju3c397402008-05-19 14:25:39 -07001000 break;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001001
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001002 ql_dbg(ql_dbg_async, vha, 0x5013,
1003 "RSCN database changed -- %04x %04x %04x.\n",
1004 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
Ravi Anand59d72d82008-09-11 21:22:53 -07001006 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001007 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
1008 | vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 if (rscn_entry == host_pid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001010 ql_dbg(ql_dbg_async, vha, 0x5014,
1011 "Ignoring RSCN update to local host "
1012 "port ID (%06x).\n", host_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 break;
1014 }
1015
Ravi Anand59d72d82008-09-11 21:22:53 -07001016 /* Ignore reserved bits from RSCN-payload. */
1017 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05001019 /* Skip RSCNs for virtual ports on the same physical port */
1020 if (qla2x00_is_a_vp_did(vha, rscn_entry))
1021 break;
1022
Chad Dupuisef86cb22014-09-25 05:17:01 -04001023 /*
1024 * Search for the rport related to this RSCN entry and mark it
1025 * as lost.
1026 */
1027 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1028 if (atomic_read(&fcport->state) != FCS_ONLINE)
1029 continue;
Chad Dupuisef86cb22014-09-25 05:17:01 -04001030 if (fcport->d_id.b24 == rscn_entry) {
1031 qla2x00_mark_device_lost(vha, fcport, 0, 0);
1032 break;
1033 }
1034 }
1035
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001036 atomic_set(&vha->loop_down_timer, 0);
1037 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001039 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1040 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1041 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 break;
1043
1044 /* case MBA_RIO_RESPONSE: */
1045 case MBA_ZIO_RESPONSE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001046 ql_dbg(ql_dbg_async, vha, 0x5015,
1047 "[R|Z]IO update completion.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
Andrew Vasqueze4289242007-07-19 15:05:56 -07001049 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001050 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001051 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001052 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001054
1055 case MBA_DISCARD_RND_FRAME:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001056 ql_dbg(ql_dbg_async, vha, 0x5016,
1057 "Discard RND Frame -- %04x %04x %04x.\n",
1058 mb[1], mb[2], mb[3]);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001059 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -07001060
1061 case MBA_TRACE_NOTIFICATION:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001062 ql_dbg(ql_dbg_async, vha, 0x5017,
1063 "Trace Notification -- %04x %04x.\n", mb[1], mb[2]);
Andrew Vasquez45ebeb52006-08-01 13:48:14 -07001064 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001065
1066 case MBA_ISP84XX_ALERT:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001067 ql_dbg(ql_dbg_async, vha, 0x5018,
1068 "ISP84XX Alert Notification -- %04x %04x %04x.\n",
1069 mb[1], mb[2], mb[3]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001070
1071 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
1072 switch (mb[1]) {
1073 case A84_PANIC_RECOVERY:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001074 ql_log(ql_log_info, vha, 0x5019,
1075 "Alert 84XX: panic recovery %04x %04x.\n",
1076 mb[2], mb[3]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001077 break;
1078 case A84_OP_LOGIN_COMPLETE:
1079 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001080 ql_log(ql_log_info, vha, 0x501a,
1081 "Alert 84XX: firmware version %x.\n",
1082 ha->cs84xx->op_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001083 break;
1084 case A84_DIAG_LOGIN_COMPLETE:
1085 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001086 ql_log(ql_log_info, vha, 0x501b,
1087 "Alert 84XX: diagnostic firmware version %x.\n",
1088 ha->cs84xx->diag_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001089 break;
1090 case A84_GOLD_LOGIN_COMPLETE:
1091 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
1092 ha->cs84xx->fw_update = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001093 ql_log(ql_log_info, vha, 0x501c,
1094 "Alert 84XX: gold firmware version %x.\n",
1095 ha->cs84xx->gold_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001096 break;
1097 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001098 ql_log(ql_log_warn, vha, 0x501d,
1099 "Alert 84xx: Invalid Alert %04x %04x %04x.\n",
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001100 mb[1], mb[2], mb[3]);
1101 }
1102 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
1103 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001104 case MBA_DCBX_START:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001105 ql_dbg(ql_dbg_async, vha, 0x501e,
1106 "DCBX Started -- %04x %04x %04x.\n",
1107 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001108 break;
1109 case MBA_DCBX_PARAM_UPDATE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001110 ql_dbg(ql_dbg_async, vha, 0x501f,
1111 "DCBX Parameters Updated -- %04x %04x %04x.\n",
1112 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001113 break;
1114 case MBA_FCF_CONF_ERR:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001115 ql_dbg(ql_dbg_async, vha, 0x5020,
1116 "FCF Configuration Error -- %04x %04x %04x.\n",
1117 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001118 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001119 case MBA_IDC_NOTIFY:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001120 if (IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
Chad Dupuis67b2a312013-02-08 01:57:51 -05001121 mb[4] = RD_REG_WORD(&reg24->mailbox4);
1122 if (((mb[2] & 0x7fff) == MBC_PORT_RESET ||
1123 (mb[2] & 0x7fff) == MBC_SET_PORT_CONFIG) &&
1124 (mb[4] & INTERNAL_LOOPBACK_MASK) != 0) {
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04001125 set_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags);
Chad Dupuis67b2a312013-02-08 01:57:51 -05001126 /*
1127 * Extend loop down timer since port is active.
1128 */
1129 if (atomic_read(&vha->loop_state) == LOOP_DOWN)
1130 atomic_set(&vha->loop_down_timer,
1131 LOOP_DOWN_TIME);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04001132 qla2xxx_wake_dpc(vha);
1133 }
Chad Dupuis67b2a312013-02-08 01:57:51 -05001134 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04001135 case MBA_IDC_COMPLETE:
Chad Dupuis9aaf2ce2013-10-30 03:38:25 -04001136 if (ha->notify_lb_portup_comp && !vha->vp_idx)
Chad Dupuisf356bef2013-02-08 01:58:04 -05001137 complete(&ha->lb_portup_comp);
1138 /* Fallthru */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001139 case MBA_IDC_TIME_EXT:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001140 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) ||
1141 IS_QLA8044(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001142 qla81xx_idc_event(vha, mb[0], mb[1]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001143 break;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001144
1145 case MBA_IDC_AEN:
1146 mb[4] = RD_REG_WORD(&reg24->mailbox4);
1147 mb[5] = RD_REG_WORD(&reg24->mailbox5);
1148 mb[6] = RD_REG_WORD(&reg24->mailbox6);
1149 mb[7] = RD_REG_WORD(&reg24->mailbox7);
1150 qla83xx_handle_8200_aen(vha, mb);
1151 break;
1152
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001153 case MBA_DPORT_DIAGNOSTICS:
1154 ql_dbg(ql_dbg_async, vha, 0x5052,
1155 "D-Port Diagnostics: %04x %04x=%s\n", mb[0], mb[1],
1156 mb[1] == 0 ? "start" :
1157 mb[1] == 1 ? "done (ok)" :
1158 mb[1] == 2 ? "done (error)" : "other");
1159 break;
1160
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001161 default:
1162 ql_dbg(ql_dbg_async, vha, 0x5057,
1163 "Unknown AEN:%04x %04x %04x %04x\n",
1164 mb[0], mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001166
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001167 qlt_async_event(mb[0], vha, mb);
1168
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001169 if (!vha->vp_idx && ha->num_vhosts)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001170 qla2x00_alert_all_vps(rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171}
1172
1173/**
1174 * qla2x00_process_completed_request() - Process a Fast Post response.
1175 * @ha: SCSI driver HA context
1176 * @index: SRB index
1177 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001178void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001179qla2x00_process_completed_request(struct scsi_qla_host *vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001180 struct req_que *req, uint32_t index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181{
1182 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001183 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
1185 /* Validate handle. */
Chad Dupuis8d93f552013-01-30 03:34:37 -05001186 if (index >= req->num_outstanding_cmds) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001187 ql_log(ql_log_warn, vha, 0x3014,
1188 "Invalid SCSI command index (%x).\n", index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001190 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001191 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1192 else
1193 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 return;
1195 }
1196
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001197 sp = req->outstanding_cmds[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 if (sp) {
1199 /* Free outstanding command slot. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001200 req->outstanding_cmds[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 /* Save ISP completion status */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001203 sp->done(ha, sp, DID_OK << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001205 ql_log(ql_log_warn, vha, 0x3016, "Invalid SCSI SRB.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001207 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001208 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1209 else
1210 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 }
1212}
1213
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001214srb_t *
Andrew Vasquezac280b62009-08-20 11:06:05 -07001215qla2x00_get_sp_from_handle(scsi_qla_host_t *vha, const char *func,
1216 struct req_que *req, void *iocb)
1217{
1218 struct qla_hw_data *ha = vha->hw;
1219 sts_entry_t *pkt = iocb;
1220 srb_t *sp = NULL;
1221 uint16_t index;
1222
1223 index = LSW(pkt->handle);
Chad Dupuis8d93f552013-01-30 03:34:37 -05001224 if (index >= req->num_outstanding_cmds) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001225 ql_log(ql_log_warn, vha, 0x5031,
1226 "Invalid command index (%x).\n", index);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001227 if (IS_P3P_TYPE(ha))
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001228 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1229 else
1230 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001231 goto done;
1232 }
1233 sp = req->outstanding_cmds[index];
1234 if (!sp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001235 ql_log(ql_log_warn, vha, 0x5032,
1236 "Invalid completion handle (%x) -- timed-out.\n", index);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001237 return sp;
1238 }
1239 if (sp->handle != index) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001240 ql_log(ql_log_warn, vha, 0x5033,
1241 "SRB handle (%x) mismatch %x.\n", sp->handle, index);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001242 return NULL;
1243 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001244
Andrew Vasquezac280b62009-08-20 11:06:05 -07001245 req->outstanding_cmds[index] = NULL;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001246
Andrew Vasquezac280b62009-08-20 11:06:05 -07001247done:
1248 return sp;
1249}
1250
1251static void
1252qla2x00_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1253 struct mbx_entry *mbx)
1254{
1255 const char func[] = "MBX-IOCB";
1256 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001257 fc_port_t *fcport;
1258 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001259 struct srb_iocb *lio;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001260 uint16_t *data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001261 uint16_t status;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001262
1263 sp = qla2x00_get_sp_from_handle(vha, func, req, mbx);
1264 if (!sp)
1265 return;
1266
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001267 lio = &sp->u.iocb_cmd;
1268 type = sp->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001269 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001270 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001271
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001272 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001273 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001274 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001275 if (mbx->entry_status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001276 ql_dbg(ql_dbg_async, vha, 0x5043,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001277 "Async-%s error entry - hdl=%x portid=%02x%02x%02x "
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001278 "entry-status=%x status=%x state-flag=%x "
Chad Dupuiscfb09192011-11-18 09:03:07 -08001279 "status-flags=%x.\n", type, sp->handle,
1280 fcport->d_id.b.domain, fcport->d_id.b.area,
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001281 fcport->d_id.b.al_pa, mbx->entry_status,
1282 le16_to_cpu(mbx->status), le16_to_cpu(mbx->state_flags),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001283 le16_to_cpu(mbx->status_flags));
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001284
Chad Dupuiscfb09192011-11-18 09:03:07 -08001285 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5029,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001286 (uint8_t *)mbx, sizeof(*mbx));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001287
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001288 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001289 }
1290
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001291 status = le16_to_cpu(mbx->status);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001292 if (status == 0x30 && sp->type == SRB_LOGIN_CMD &&
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001293 le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE)
1294 status = 0;
1295 if (!status && le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001296 ql_dbg(ql_dbg_async, vha, 0x5045,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001297 "Async-%s complete - hdl=%x portid=%02x%02x%02x mbx1=%x.\n",
1298 type, sp->handle, fcport->d_id.b.domain,
1299 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1300 le16_to_cpu(mbx->mb1));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001301
1302 data[0] = MBS_COMMAND_COMPLETE;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001303 if (sp->type == SRB_LOGIN_CMD) {
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001304 fcport->port_type = FCT_TARGET;
1305 if (le16_to_cpu(mbx->mb1) & BIT_0)
1306 fcport->port_type = FCT_INITIATOR;
Andrew Vasquez6ac52602010-05-28 15:08:19 -07001307 else if (le16_to_cpu(mbx->mb1) & BIT_1)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001308 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001309 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001310 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001311 }
1312
1313 data[0] = le16_to_cpu(mbx->mb0);
1314 switch (data[0]) {
1315 case MBS_PORT_ID_USED:
1316 data[1] = le16_to_cpu(mbx->mb1);
1317 break;
1318 case MBS_LOOP_ID_USED:
1319 break;
1320 default:
1321 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001322 break;
1323 }
1324
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001325 ql_log(ql_log_warn, vha, 0x5046,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001326 "Async-%s failed - hdl=%x portid=%02x%02x%02x status=%x "
1327 "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n", type, sp->handle,
1328 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
1329 status, le16_to_cpu(mbx->mb0), le16_to_cpu(mbx->mb1),
Andrew Vasquezac280b62009-08-20 11:06:05 -07001330 le16_to_cpu(mbx->mb2), le16_to_cpu(mbx->mb6),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001331 le16_to_cpu(mbx->mb7));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001332
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001333logio_done:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001334 sp->done(vha, sp, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001335}
1336
1337static void
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001338qla2x00_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1339 sts_entry_t *pkt, int iocb_type)
1340{
1341 const char func[] = "CT_IOCB";
1342 const char *type;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001343 srb_t *sp;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001344 struct fc_bsg_job *bsg_job;
1345 uint16_t comp_status;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001346 int res;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001347
1348 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1349 if (!sp)
1350 return;
1351
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001352 bsg_job = sp->u.bsg_job;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001353
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001354 type = "ct pass-through";
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001355
1356 comp_status = le16_to_cpu(pkt->comp_status);
1357
1358 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1359 * fc payload to the caller
1360 */
1361 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1362 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1363
1364 if (comp_status != CS_COMPLETE) {
1365 if (comp_status == CS_DATA_UNDERRUN) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001366 res = DID_OK << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001367 bsg_job->reply->reply_payload_rcv_len =
1368 le16_to_cpu(((sts_entry_t *)pkt)->rsp_info_len);
1369
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001370 ql_log(ql_log_warn, vha, 0x5048,
1371 "CT pass-through-%s error "
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001372 "comp_status-status=0x%x total_byte = 0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001373 type, comp_status,
1374 bsg_job->reply->reply_payload_rcv_len);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001375 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001376 ql_log(ql_log_warn, vha, 0x5049,
1377 "CT pass-through-%s error "
1378 "comp_status-status=0x%x.\n", type, comp_status);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001379 res = DID_ERROR << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001380 bsg_job->reply->reply_payload_rcv_len = 0;
1381 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001382 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5035,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001383 (uint8_t *)pkt, sizeof(*pkt));
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001384 } else {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001385 res = DID_OK << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001386 bsg_job->reply->reply_payload_rcv_len =
1387 bsg_job->reply_payload.payload_len;
1388 bsg_job->reply_len = 0;
1389 }
1390
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001391 sp->done(vha, sp, res);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001392}
1393
1394static void
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001395qla24xx_els_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1396 struct sts_entry_24xx *pkt, int iocb_type)
1397{
1398 const char func[] = "ELS_CT_IOCB";
1399 const char *type;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001400 srb_t *sp;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001401 struct fc_bsg_job *bsg_job;
1402 uint16_t comp_status;
1403 uint32_t fw_status[3];
1404 uint8_t* fw_sts_ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001405 int res;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001406
1407 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1408 if (!sp)
1409 return;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001410 bsg_job = sp->u.bsg_job;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001411
1412 type = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001413 switch (sp->type) {
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001414 case SRB_ELS_CMD_RPT:
1415 case SRB_ELS_CMD_HST:
1416 type = "els";
1417 break;
1418 case SRB_CT_CMD:
1419 type = "ct pass-through";
1420 break;
Himanshu Madhani6eb54712015-12-17 14:57:00 -05001421 case SRB_ELS_DCMD:
1422 type = "Driver ELS logo";
1423 ql_dbg(ql_dbg_user, vha, 0x5047,
1424 "Completing %s: (%p) type=%d.\n", type, sp, sp->type);
1425 sp->done(vha, sp, 0);
1426 return;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001427 default:
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001428 ql_dbg(ql_dbg_user, vha, 0x503e,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001429 "Unrecognized SRB: (%p) type=%d.\n", sp, sp->type);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001430 return;
1431 }
1432
1433 comp_status = fw_status[0] = le16_to_cpu(pkt->comp_status);
1434 fw_status[1] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1);
1435 fw_status[2] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2);
1436
1437 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1438 * fc payload to the caller
1439 */
1440 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1441 bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(fw_status);
1442
1443 if (comp_status != CS_COMPLETE) {
1444 if (comp_status == CS_DATA_UNDERRUN) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001445 res = DID_OK << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001446 bsg_job->reply->reply_payload_rcv_len =
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001447 le16_to_cpu(((struct els_sts_entry_24xx *)pkt)->total_byte_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001448
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001449 ql_dbg(ql_dbg_user, vha, 0x503f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001450 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001451 "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001452 type, sp->handle, comp_status, fw_status[1], fw_status[2],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001453 le16_to_cpu(((struct els_sts_entry_24xx *)
1454 pkt)->total_byte_count));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001455 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1456 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1457 }
1458 else {
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001459 ql_dbg(ql_dbg_user, vha, 0x5040,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001460 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001461 "error subcode 1=0x%x error subcode 2=0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001462 type, sp->handle, comp_status,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001463 le16_to_cpu(((struct els_sts_entry_24xx *)
1464 pkt)->error_subcode_1),
1465 le16_to_cpu(((struct els_sts_entry_24xx *)
1466 pkt)->error_subcode_2));
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001467 res = DID_ERROR << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001468 bsg_job->reply->reply_payload_rcv_len = 0;
1469 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1470 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1471 }
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001472 ql_dump_buffer(ql_dbg_user + ql_dbg_buffer, vha, 0x5056,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001473 (uint8_t *)pkt, sizeof(*pkt));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001474 }
1475 else {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001476 res = DID_OK << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001477 bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
1478 bsg_job->reply_len = 0;
1479 }
1480
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001481 sp->done(vha, sp, res);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001482}
1483
1484static void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001485qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req,
1486 struct logio_entry_24xx *logio)
1487{
1488 const char func[] = "LOGIO-IOCB";
1489 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001490 fc_port_t *fcport;
1491 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001492 struct srb_iocb *lio;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001493 uint16_t *data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001494 uint32_t iop[2];
1495
1496 sp = qla2x00_get_sp_from_handle(vha, func, req, logio);
1497 if (!sp)
1498 return;
1499
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001500 lio = &sp->u.iocb_cmd;
1501 type = sp->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001502 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001503 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001504
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001505 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001506 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001507 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001508 if (logio->entry_status) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001509 ql_log(ql_log_warn, fcport->vha, 0x5034,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001510 "Async-%s error entry - hdl=%x"
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001511 "portid=%02x%02x%02x entry-status=%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001512 type, sp->handle, fcport->d_id.b.domain,
1513 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1514 logio->entry_status);
1515 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x504d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001516 (uint8_t *)logio, sizeof(*logio));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001517
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001518 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001519 }
1520
1521 if (le16_to_cpu(logio->comp_status) == CS_COMPLETE) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001522 ql_dbg(ql_dbg_async, fcport->vha, 0x5036,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001523 "Async-%s complete - hdl=%x portid=%02x%02x%02x "
1524 "iop0=%x.\n", type, sp->handle, fcport->d_id.b.domain,
1525 fcport->d_id.b.area, fcport->d_id.b.al_pa,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001526 le32_to_cpu(logio->io_parameter[0]));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001527
1528 data[0] = MBS_COMMAND_COMPLETE;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001529 if (sp->type != SRB_LOGIN_CMD)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001530 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001531
1532 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1533 if (iop[0] & BIT_4) {
1534 fcport->port_type = FCT_TARGET;
1535 if (iop[0] & BIT_8)
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07001536 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquezb0cd5792010-05-28 15:08:22 -07001537 } else if (iop[0] & BIT_5)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001538 fcport->port_type = FCT_INITIATOR;
Andrew Vasquezb0cd5792010-05-28 15:08:22 -07001539
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001540 if (iop[0] & BIT_7)
1541 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
1542
Andrew Vasquezac280b62009-08-20 11:06:05 -07001543 if (logio->io_parameter[7] || logio->io_parameter[8])
1544 fcport->supported_classes |= FC_COS_CLASS2;
1545 if (logio->io_parameter[9] || logio->io_parameter[10])
1546 fcport->supported_classes |= FC_COS_CLASS3;
1547
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001548 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001549 }
1550
1551 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1552 iop[1] = le32_to_cpu(logio->io_parameter[1]);
1553 switch (iop[0]) {
1554 case LSC_SCODE_PORTID_USED:
1555 data[0] = MBS_PORT_ID_USED;
1556 data[1] = LSW(iop[1]);
1557 break;
1558 case LSC_SCODE_NPORT_USED:
1559 data[0] = MBS_LOOP_ID_USED;
1560 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001561 default:
1562 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001563 break;
1564 }
1565
Arun Easi5e19ed92012-02-09 11:15:51 -08001566 ql_dbg(ql_dbg_async, fcport->vha, 0x5037,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001567 "Async-%s failed - hdl=%x portid=%02x%02x%02x comp=%x "
1568 "iop0=%x iop1=%x.\n", type, sp->handle, fcport->d_id.b.domain,
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001569 fcport->d_id.b.area, fcport->d_id.b.al_pa,
Andrew Vasquezac280b62009-08-20 11:06:05 -07001570 le16_to_cpu(logio->comp_status),
1571 le32_to_cpu(logio->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001572 le32_to_cpu(logio->io_parameter[1]));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001573
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001574logio_done:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001575 sp->done(vha, sp, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001576}
1577
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001578static void
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001579qla24xx_tm_iocb_entry(scsi_qla_host_t *vha, struct req_que *req, void *tsk)
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001580{
1581 const char func[] = "TMF-IOCB";
1582 const char *type;
1583 fc_port_t *fcport;
1584 srb_t *sp;
1585 struct srb_iocb *iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001586 struct sts_entry_24xx *sts = (struct sts_entry_24xx *)tsk;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001587
1588 sp = qla2x00_get_sp_from_handle(vha, func, req, tsk);
1589 if (!sp)
1590 return;
1591
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001592 iocb = &sp->u.iocb_cmd;
1593 type = sp->name;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001594 fcport = sp->fcport;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001595 iocb->u.tmf.data = QLA_SUCCESS;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001596
1597 if (sts->entry_status) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001598 ql_log(ql_log_warn, fcport->vha, 0x5038,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001599 "Async-%s error - hdl=%x entry-status(%x).\n",
1600 type, sp->handle, sts->entry_status);
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001601 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07001602 } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001603 ql_log(ql_log_warn, fcport->vha, 0x5039,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001604 "Async-%s error - hdl=%x completion status(%x).\n",
1605 type, sp->handle, sts->comp_status);
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001606 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
1607 } else if ((le16_to_cpu(sts->scsi_status) &
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001608 SS_RESPONSE_INFO_LEN_VALID)) {
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001609 if (le32_to_cpu(sts->rsp_data_len) < 4) {
1610 ql_log(ql_log_warn, fcport->vha, 0x503b,
1611 "Async-%s error - hdl=%x not enough response(%d).\n",
1612 type, sp->handle, sts->rsp_data_len);
1613 } else if (sts->data[3]) {
1614 ql_log(ql_log_warn, fcport->vha, 0x503c,
1615 "Async-%s error - hdl=%x response(%x).\n",
1616 type, sp->handle, sts->data[3]);
Bart Van Assche8d2b21d2015-06-04 15:58:09 -07001617 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001618 }
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001619 }
1620
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001621 if (iocb->u.tmf.data != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001622 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5055,
1623 (uint8_t *)sts, sizeof(*sts));
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001624
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001625 sp->done(vha, sp, 0);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001626}
1627
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628/**
1629 * qla2x00_process_response_queue() - Process response queue entries.
1630 * @ha: SCSI driver HA context
1631 */
1632void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001633qla2x00_process_response_queue(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001635 struct scsi_qla_host *vha;
1636 struct qla_hw_data *ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001637 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 sts_entry_t *pkt;
1639 uint16_t handle_cnt;
1640 uint16_t cnt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001641
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001642 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001644 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 return;
1646
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001647 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1648 pkt = (sts_entry_t *)rsp->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001650 rsp->ring_index++;
1651 if (rsp->ring_index == rsp->length) {
1652 rsp->ring_index = 0;
1653 rsp->ring_ptr = rsp->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001655 rsp->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 }
1657
1658 if (pkt->entry_status != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001659 qla2x00_error_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1661 wmb();
1662 continue;
1663 }
1664
1665 switch (pkt->entry_type) {
1666 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001667 qla2x00_status_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 break;
1669 case STATUS_TYPE_21:
1670 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
1671 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001672 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 ((sts21_entry_t *)pkt)->handle[cnt]);
1674 }
1675 break;
1676 case STATUS_TYPE_22:
1677 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
1678 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001679 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 ((sts22_entry_t *)pkt)->handle[cnt]);
1681 }
1682 break;
1683 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001684 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001686 case MBX_IOCB_TYPE:
1687 qla2x00_mbx_iocb_entry(vha, rsp->req,
1688 (struct mbx_entry *)pkt);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001689 break;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001690 case CT_IOCB_TYPE:
1691 qla2x00_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
1692 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 default:
1694 /* Type Not Supported. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001695 ql_log(ql_log_warn, vha, 0x504a,
1696 "Received unknown response pkt type %x "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 "entry status=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001698 pkt->entry_type, pkt->entry_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 break;
1700 }
1701 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1702 wmb();
1703 }
1704
1705 /* Adjust ring index */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001706 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707}
1708
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001709static inline void
Andrew Vasquez55442132010-07-23 15:28:27 +05001710qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t par_sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001711 uint32_t sense_len, struct rsp_que *rsp, int res)
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001712{
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001713 struct scsi_qla_host *vha = sp->fcport->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001714 struct scsi_cmnd *cp = GET_CMD_SP(sp);
1715 uint32_t track_sense_len;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001716
1717 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
1718 sense_len = SCSI_SENSE_BUFFERSIZE;
1719
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001720 SET_CMD_SENSE_LEN(sp, sense_len);
1721 SET_CMD_SENSE_PTR(sp, cp->sense_buffer);
1722 track_sense_len = sense_len;
1723
1724 if (sense_len > par_sense_len)
Andrew Vasquez55442132010-07-23 15:28:27 +05001725 sense_len = par_sense_len;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001726
1727 memcpy(cp->sense_buffer, sense_data, sense_len);
1728
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001729 SET_CMD_SENSE_PTR(sp, cp->sense_buffer + sense_len);
1730 track_sense_len -= sense_len;
1731 SET_CMD_SENSE_LEN(sp, track_sense_len);
1732
1733 if (track_sense_len != 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001734 rsp->status_srb = sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001735 cp->result = res;
1736 }
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001737
Chad Dupuiscfb09192011-11-18 09:03:07 -08001738 if (sense_len) {
1739 ql_dbg(ql_dbg_io + ql_dbg_buffer, vha, 0x301c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001740 "Check condition Sense data, nexus%ld:%d:%llu cmd=%p.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001741 sp->fcport->vha->host_no, cp->device->id, cp->device->lun,
1742 cp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001743 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302b,
1744 cp->sense_buffer, sense_len);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001745 }
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001746}
1747
Arun Easibad75002010-05-04 15:01:30 -07001748struct scsi_dif_tuple {
1749 __be16 guard; /* Checksum */
Masanari Iidad6a03582012-08-22 14:20:58 -04001750 __be16 app_tag; /* APPL identifier */
Arun Easibad75002010-05-04 15:01:30 -07001751 __be32 ref_tag; /* Target LBA or indirect LBA */
1752};
1753
1754/*
1755 * Checks the guard or meta-data for the type of error
1756 * detected by the HBA. In case of errors, we set the
1757 * ASC/ASCQ fields in the sense buffer with ILLEGAL_REQUEST
1758 * to indicate to the kernel that the HBA detected error.
1759 */
Arun Easi8cb20492011-08-16 11:29:22 -07001760static inline int
Arun Easibad75002010-05-04 15:01:30 -07001761qla2x00_handle_dif_error(srb_t *sp, struct sts_entry_24xx *sts24)
1762{
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001763 struct scsi_qla_host *vha = sp->fcport->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001764 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Arun Easi8cb20492011-08-16 11:29:22 -07001765 uint8_t *ap = &sts24->data[12];
1766 uint8_t *ep = &sts24->data[20];
Arun Easibad75002010-05-04 15:01:30 -07001767 uint32_t e_ref_tag, a_ref_tag;
1768 uint16_t e_app_tag, a_app_tag;
1769 uint16_t e_guard, a_guard;
1770
Arun Easi8cb20492011-08-16 11:29:22 -07001771 /*
1772 * swab32 of the "data" field in the beginning of qla2x00_status_entry()
1773 * would make guard field appear at offset 2
1774 */
1775 a_guard = le16_to_cpu(*(uint16_t *)(ap + 2));
1776 a_app_tag = le16_to_cpu(*(uint16_t *)(ap + 0));
1777 a_ref_tag = le32_to_cpu(*(uint32_t *)(ap + 4));
1778 e_guard = le16_to_cpu(*(uint16_t *)(ep + 2));
1779 e_app_tag = le16_to_cpu(*(uint16_t *)(ep + 0));
1780 e_ref_tag = le32_to_cpu(*(uint32_t *)(ep + 4));
Arun Easibad75002010-05-04 15:01:30 -07001781
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001782 ql_dbg(ql_dbg_io, vha, 0x3023,
1783 "iocb(s) %p Returned STATUS.\n", sts24);
Arun Easibad75002010-05-04 15:01:30 -07001784
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001785 ql_dbg(ql_dbg_io, vha, 0x3024,
1786 "DIF ERROR in cmd 0x%x lba 0x%llx act ref"
Arun Easibad75002010-05-04 15:01:30 -07001787 " tag=0x%x, exp ref_tag=0x%x, act app tag=0x%x, exp app"
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001788 " tag=0x%x, act guard=0x%x, exp guard=0x%x.\n",
Arun Easibad75002010-05-04 15:01:30 -07001789 cmd->cmnd[0], (u64)scsi_get_lba(cmd), a_ref_tag, e_ref_tag,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001790 a_app_tag, e_app_tag, a_guard, e_guard);
Arun Easibad75002010-05-04 15:01:30 -07001791
Arun Easi8cb20492011-08-16 11:29:22 -07001792 /*
1793 * Ignore sector if:
1794 * For type 3: ref & app tag is all 'f's
1795 * For type 0,1,2: app tag is all 'f's
1796 */
1797 if ((a_app_tag == 0xffff) &&
1798 ((scsi_get_prot_type(cmd) != SCSI_PROT_DIF_TYPE3) ||
1799 (a_ref_tag == 0xffffffff))) {
1800 uint32_t blocks_done, resid;
1801 sector_t lba_s = scsi_get_lba(cmd);
1802
1803 /* 2TB boundary case covered automatically with this */
1804 blocks_done = e_ref_tag - (uint32_t)lba_s + 1;
1805
1806 resid = scsi_bufflen(cmd) - (blocks_done *
1807 cmd->device->sector_size);
1808
1809 scsi_set_resid(cmd, resid);
1810 cmd->result = DID_OK << 16;
1811
1812 /* Update protection tag */
1813 if (scsi_prot_sg_count(cmd)) {
1814 uint32_t i, j = 0, k = 0, num_ent;
1815 struct scatterlist *sg;
1816 struct sd_dif_tuple *spt;
1817
1818 /* Patch the corresponding protection tags */
1819 scsi_for_each_prot_sg(cmd, sg,
1820 scsi_prot_sg_count(cmd), i) {
1821 num_ent = sg_dma_len(sg) / 8;
1822 if (k + num_ent < blocks_done) {
1823 k += num_ent;
1824 continue;
1825 }
1826 j = blocks_done - k - 1;
1827 k = blocks_done;
1828 break;
1829 }
1830
1831 if (k != blocks_done) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001832 ql_log(ql_log_warn, vha, 0x302f,
Randy Dunlap8ec9c7f2011-09-23 15:40:50 -07001833 "unexpected tag values tag:lba=%x:%llx)\n",
1834 e_ref_tag, (unsigned long long)lba_s);
Arun Easi8cb20492011-08-16 11:29:22 -07001835 return 1;
1836 }
1837
1838 spt = page_address(sg_page(sg)) + sg->offset;
1839 spt += j;
1840
1841 spt->app_tag = 0xffff;
1842 if (scsi_get_prot_type(cmd) == SCSI_PROT_DIF_TYPE3)
1843 spt->ref_tag = 0xffffffff;
1844 }
1845
1846 return 0;
1847 }
1848
Arun Easibad75002010-05-04 15:01:30 -07001849 /* check guard */
1850 if (e_guard != a_guard) {
1851 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1852 0x10, 0x1);
1853 set_driver_byte(cmd, DRIVER_SENSE);
1854 set_host_byte(cmd, DID_ABORT);
1855 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
Arun Easi8cb20492011-08-16 11:29:22 -07001856 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001857 }
1858
Arun Easie02587d2011-08-16 11:29:23 -07001859 /* check ref tag */
1860 if (e_ref_tag != a_ref_tag) {
1861 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1862 0x10, 0x3);
1863 set_driver_byte(cmd, DRIVER_SENSE);
1864 set_host_byte(cmd, DID_ABORT);
1865 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
1866 return 1;
1867 }
1868
Arun Easibad75002010-05-04 15:01:30 -07001869 /* check appl tag */
1870 if (e_app_tag != a_app_tag) {
1871 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1872 0x10, 0x2);
1873 set_driver_byte(cmd, DRIVER_SENSE);
1874 set_host_byte(cmd, DID_ABORT);
1875 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
Arun Easi8cb20492011-08-16 11:29:22 -07001876 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001877 }
1878
Arun Easi8cb20492011-08-16 11:29:22 -07001879 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001880}
1881
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001882static void
1883qla25xx_process_bidir_status_iocb(scsi_qla_host_t *vha, void *pkt,
1884 struct req_que *req, uint32_t index)
1885{
1886 struct qla_hw_data *ha = vha->hw;
1887 srb_t *sp;
1888 uint16_t comp_status;
1889 uint16_t scsi_status;
1890 uint16_t thread_id;
1891 uint32_t rval = EXT_STATUS_OK;
1892 struct fc_bsg_job *bsg_job = NULL;
1893 sts_entry_t *sts;
1894 struct sts_entry_24xx *sts24;
1895 sts = (sts_entry_t *) pkt;
1896 sts24 = (struct sts_entry_24xx *) pkt;
1897
1898 /* Validate handle. */
Chad Dupuis8d93f552013-01-30 03:34:37 -05001899 if (index >= req->num_outstanding_cmds) {
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001900 ql_log(ql_log_warn, vha, 0x70af,
1901 "Invalid SCSI completion handle 0x%x.\n", index);
1902 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1903 return;
1904 }
1905
1906 sp = req->outstanding_cmds[index];
1907 if (sp) {
1908 /* Free outstanding command slot. */
1909 req->outstanding_cmds[index] = NULL;
1910 bsg_job = sp->u.bsg_job;
1911 } else {
1912 ql_log(ql_log_warn, vha, 0x70b0,
1913 "Req:%d: Invalid ISP SCSI completion handle(0x%x)\n",
1914 req->id, index);
1915
1916 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1917 return;
1918 }
1919
1920 if (IS_FWI2_CAPABLE(ha)) {
1921 comp_status = le16_to_cpu(sts24->comp_status);
1922 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
1923 } else {
1924 comp_status = le16_to_cpu(sts->comp_status);
1925 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1926 }
1927
1928 thread_id = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1929 switch (comp_status) {
1930 case CS_COMPLETE:
1931 if (scsi_status == 0) {
1932 bsg_job->reply->reply_payload_rcv_len =
1933 bsg_job->reply_payload.payload_len;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -04001934 vha->qla_stats.input_bytes +=
1935 bsg_job->reply->reply_payload_rcv_len;
1936 vha->qla_stats.input_requests++;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001937 rval = EXT_STATUS_OK;
1938 }
1939 goto done;
1940
1941 case CS_DATA_OVERRUN:
1942 ql_dbg(ql_dbg_user, vha, 0x70b1,
1943 "Command completed with date overrun thread_id=%d\n",
1944 thread_id);
1945 rval = EXT_STATUS_DATA_OVERRUN;
1946 break;
1947
1948 case CS_DATA_UNDERRUN:
1949 ql_dbg(ql_dbg_user, vha, 0x70b2,
1950 "Command completed with date underrun thread_id=%d\n",
1951 thread_id);
1952 rval = EXT_STATUS_DATA_UNDERRUN;
1953 break;
1954 case CS_BIDIR_RD_OVERRUN:
1955 ql_dbg(ql_dbg_user, vha, 0x70b3,
1956 "Command completed with read data overrun thread_id=%d\n",
1957 thread_id);
1958 rval = EXT_STATUS_DATA_OVERRUN;
1959 break;
1960
1961 case CS_BIDIR_RD_WR_OVERRUN:
1962 ql_dbg(ql_dbg_user, vha, 0x70b4,
1963 "Command completed with read and write data overrun "
1964 "thread_id=%d\n", thread_id);
1965 rval = EXT_STATUS_DATA_OVERRUN;
1966 break;
1967
1968 case CS_BIDIR_RD_OVERRUN_WR_UNDERRUN:
1969 ql_dbg(ql_dbg_user, vha, 0x70b5,
1970 "Command completed with read data over and write data "
1971 "underrun thread_id=%d\n", thread_id);
1972 rval = EXT_STATUS_DATA_OVERRUN;
1973 break;
1974
1975 case CS_BIDIR_RD_UNDERRUN:
1976 ql_dbg(ql_dbg_user, vha, 0x70b6,
1977 "Command completed with read data data underrun "
1978 "thread_id=%d\n", thread_id);
1979 rval = EXT_STATUS_DATA_UNDERRUN;
1980 break;
1981
1982 case CS_BIDIR_RD_UNDERRUN_WR_OVERRUN:
1983 ql_dbg(ql_dbg_user, vha, 0x70b7,
1984 "Command completed with read data under and write data "
1985 "overrun thread_id=%d\n", thread_id);
1986 rval = EXT_STATUS_DATA_UNDERRUN;
1987 break;
1988
1989 case CS_BIDIR_RD_WR_UNDERRUN:
1990 ql_dbg(ql_dbg_user, vha, 0x70b8,
1991 "Command completed with read and write data underrun "
1992 "thread_id=%d\n", thread_id);
1993 rval = EXT_STATUS_DATA_UNDERRUN;
1994 break;
1995
1996 case CS_BIDIR_DMA:
1997 ql_dbg(ql_dbg_user, vha, 0x70b9,
1998 "Command completed with data DMA error thread_id=%d\n",
1999 thread_id);
2000 rval = EXT_STATUS_DMA_ERR;
2001 break;
2002
2003 case CS_TIMEOUT:
2004 ql_dbg(ql_dbg_user, vha, 0x70ba,
2005 "Command completed with timeout thread_id=%d\n",
2006 thread_id);
2007 rval = EXT_STATUS_TIMEOUT;
2008 break;
2009 default:
2010 ql_dbg(ql_dbg_user, vha, 0x70bb,
2011 "Command completed with completion status=0x%x "
2012 "thread_id=%d\n", comp_status, thread_id);
2013 rval = EXT_STATUS_ERR;
2014 break;
2015 }
Bart Van Assche8d2b21d2015-06-04 15:58:09 -07002016 bsg_job->reply->reply_payload_rcv_len = 0;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002017
2018done:
2019 /* Return the vendor specific reply to API */
2020 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
2021 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2022 /* Always return DID_OK, bsg will send the vendor specific response
2023 * in this case only */
2024 sp->done(vha, sp, (DID_OK << 6));
2025
2026}
2027
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028/**
2029 * qla2x00_status_entry() - Process a Status IOCB entry.
2030 * @ha: SCSI driver HA context
2031 * @pkt: Entry pointer
2032 */
2033static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002034qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 fc_port_t *fcport;
2038 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002039 sts_entry_t *sts;
2040 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 uint16_t comp_status;
2042 uint16_t scsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002043 uint16_t ox_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 uint8_t lscsi_status;
2045 int32_t resid;
Andrew Vasquez55442132010-07-23 15:28:27 +05002046 uint32_t sense_len, par_sense_len, rsp_info_len, resid_len,
2047 fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002048 uint8_t *rsp_info, *sense_data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002049 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002050 uint32_t handle;
2051 uint16_t que;
2052 struct req_que *req;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002053 int logit = 1;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002054 int res = 0;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002055 uint16_t state_flags = 0;
Chad Dupuise05fe292014-09-25 05:16:59 -04002056 uint16_t retry_delay = 0;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002057
2058 sts = (sts_entry_t *) pkt;
2059 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002060 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002061 comp_status = le16_to_cpu(sts24->comp_status);
2062 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002063 state_flags = le16_to_cpu(sts24->state_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002064 } else {
2065 comp_status = le16_to_cpu(sts->comp_status);
2066 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
2067 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002068 handle = (uint32_t) LSW(sts->handle);
2069 que = MSW(sts->handle);
2070 req = ha->req_q_map[que];
Giridhar Malavalia9083012010-04-12 17:59:55 -07002071
Chad Dupuis36008cf2013-10-03 03:21:13 -04002072 /* Check for invalid queue pointer */
2073 if (req == NULL ||
2074 que >= find_first_zero_bit(ha->req_qid_map, ha->max_req_queues)) {
2075 ql_dbg(ql_dbg_io, vha, 0x3059,
2076 "Invalid status handle (0x%x): Bad req pointer. req=%p, "
2077 "que=%u.\n", sts->handle, req, que);
2078 return;
2079 }
2080
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 /* Validate handle. */
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04002082 if (handle < req->num_outstanding_cmds) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002083 sp = req->outstanding_cmds[handle];
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04002084 if (!sp) {
2085 ql_dbg(ql_dbg_io, vha, 0x3075,
2086 "%s(%ld): Already returned command for status handle (0x%x).\n",
2087 __func__, vha->host_no, sts->handle);
2088 return;
2089 }
2090 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08002091 ql_dbg(ql_dbg_io, vha, 0x3017,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04002092 "Invalid status handle, out of range (0x%x).\n",
2093 sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094
Chad Dupuisacd3ce882014-04-11 16:54:07 -04002095 if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
2096 if (IS_P3P_TYPE(ha))
2097 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
2098 else
2099 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2100 qla2xxx_wake_dpc(vha);
2101 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 return;
2103 }
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002104
2105 if (unlikely((state_flags & BIT_1) && (sp->type == SRB_BIDI_CMD))) {
2106 qla25xx_process_bidir_status_iocb(vha, pkt, req, handle);
2107 return;
2108 }
2109
Armen Baloyanfaef62d2014-02-26 04:15:17 -05002110 /* Task Management completion. */
2111 if (sp->type == SRB_TM_CMD) {
2112 qla24xx_tm_iocb_entry(vha, req, pkt);
2113 return;
2114 }
2115
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002116 /* Fast path completion. */
2117 if (comp_status == CS_COMPLETE && scsi_status == 0) {
2118 qla2x00_process_completed_request(vha, req, handle);
2119
2120 return;
2121 }
2122
2123 req->outstanding_cmds[handle] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002124 cp = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 if (cp == NULL) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08002126 ql_dbg(ql_dbg_io, vha, 0x3018,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002127 "Command already returned (0x%x/%p).\n",
2128 sts->handle, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129
2130 return;
2131 }
2132
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002133 lscsi_status = scsi_status & STATUS_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
bdf79622005-04-17 15:06:53 -05002135 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002137 ox_id = 0;
Andrew Vasquez55442132010-07-23 15:28:27 +05002138 sense_len = par_sense_len = rsp_info_len = resid_len =
2139 fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002140 if (IS_FWI2_CAPABLE(ha)) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002141 if (scsi_status & SS_SENSE_LEN_VALID)
2142 sense_len = le32_to_cpu(sts24->sense_len);
2143 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
2144 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
2145 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER))
2146 resid_len = le32_to_cpu(sts24->rsp_residual_count);
2147 if (comp_status == CS_DATA_UNDERRUN)
2148 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002149 rsp_info = sts24->data;
2150 sense_data = sts24->data;
2151 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002152 ox_id = le16_to_cpu(sts24->ox_id);
Andrew Vasquez55442132010-07-23 15:28:27 +05002153 par_sense_len = sizeof(sts24->data);
Chad Dupuise05fe292014-09-25 05:16:59 -04002154 /* Valid values of the retry delay timer are 0x1-0xffef */
2155 if (sts24->retry_delay > 0 && sts24->retry_delay < 0xfff1)
2156 retry_delay = sts24->retry_delay;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002157 } else {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002158 if (scsi_status & SS_SENSE_LEN_VALID)
2159 sense_len = le16_to_cpu(sts->req_sense_length);
2160 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
2161 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002162 resid_len = le32_to_cpu(sts->residual_length);
2163 rsp_info = sts->rsp_info;
2164 sense_data = sts->req_sense_data;
Andrew Vasquez55442132010-07-23 15:28:27 +05002165 par_sense_len = sizeof(sts->req_sense_data);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002166 }
2167
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 /* Check for any FCP transport errors. */
2169 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002170 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasquez55442132010-07-23 15:28:27 +05002171 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002172 sense_data += rsp_info_len;
Andrew Vasquez55442132010-07-23 15:28:27 +05002173 par_sense_len -= rsp_info_len;
2174 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002175 if (rsp_info_len > 3 && rsp_info[3]) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002176 ql_dbg(ql_dbg_io, fcport->vha, 0x3019,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002177 "FCP I/O protocol failure (0x%x/0x%x).\n",
2178 rsp_info_len, rsp_info[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002180 res = DID_BUS_BUSY << 16;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002181 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 }
2183 }
2184
Andrew Vasquez3e8ce322008-02-28 14:06:10 -08002185 /* Check for overrun. */
2186 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
2187 scsi_status & SS_RESIDUAL_OVER)
2188 comp_status = CS_DATA_OVERRUN;
2189
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 /*
Chad Dupuise05fe292014-09-25 05:16:59 -04002191 * Check retry_delay_timer value if we receive a busy or
2192 * queue full.
2193 */
2194 if (lscsi_status == SAM_STAT_TASK_SET_FULL ||
2195 lscsi_status == SAM_STAT_BUSY)
2196 qla2x00_set_retry_delay_timestamp(fcport, retry_delay);
2197
2198 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 * Based on Host and scsi status generate status code for Linux
2200 */
2201 switch (comp_status) {
2202 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002203 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 if (scsi_status == 0) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002205 res = DID_OK << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 break;
2207 }
2208 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002209 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002210 scsi_set_resid(cp, resid);
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002211
2212 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002213 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002214 cp->underflow)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002215 ql_dbg(ql_dbg_io, fcport->vha, 0x301a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002216 "Mid-layer underflow "
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002217 "detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002218 resid, scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002219
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002220 res = DID_ERROR << 16;
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002221 break;
2222 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002224 res = DID_OK << 16 | lscsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002226 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002227 ql_dbg(ql_dbg_io, fcport->vha, 0x301b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002228 "QUEUE FULL detected.\n");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002229 break;
2230 }
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002231 logit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 if (lscsi_status != SS_CHECK_CONDITION)
2233 break;
2234
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002235 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 if (!(scsi_status & SS_SENSE_LEN_VALID))
2237 break;
2238
Andrew Vasquez55442132010-07-23 15:28:27 +05002239 qla2x00_handle_sense(sp, sense_data, par_sense_len, sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002240 rsp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 break;
2242
2243 case CS_DATA_UNDERRUN:
Ravi Ananded17c71b52006-05-17 15:08:55 -07002244 /* Use F/W calculated residual length. */
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002245 resid = IS_FWI2_CAPABLE(ha) ? fw_resid_len : resid_len;
2246 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 if (scsi_status & SS_RESIDUAL_UNDER) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002248 if (IS_FWI2_CAPABLE(ha) && fw_resid_len != resid_len) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002249 ql_dbg(ql_dbg_io, fcport->vha, 0x301d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002250 "Dropped frame(s) detected "
2251 "(0x%x of 0x%x bytes).\n",
2252 resid, scsi_bufflen(cp));
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08002253
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002254 res = DID_ERROR << 16 | lscsi_status;
Arun Easi4e85e3d2011-11-18 09:02:10 -08002255 goto check_scsi_status;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002256 }
2257
2258 if (!lscsi_status &&
2259 ((unsigned)(scsi_bufflen(cp) - resid) <
2260 cp->underflow)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002261 ql_dbg(ql_dbg_io, fcport->vha, 0x301e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002262 "Mid-layer underflow "
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002263 "detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002264 resid, scsi_bufflen(cp));
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002265
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002266 res = DID_ERROR << 16;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002267 break;
2268 }
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002269 } else if (lscsi_status != SAM_STAT_TASK_SET_FULL &&
2270 lscsi_status != SAM_STAT_BUSY) {
2271 /*
2272 * scsi status of task set and busy are considered to be
2273 * task not completed.
2274 */
2275
Arun Easi5e19ed92012-02-09 11:15:51 -08002276 ql_dbg(ql_dbg_io, fcport->vha, 0x301f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002277 "Dropped frame(s) detected (0x%x "
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002278 "of 0x%x bytes).\n", resid,
2279 scsi_bufflen(cp));
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002280
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002281 res = DID_ERROR << 16 | lscsi_status;
Lalit Chandivade0374f552010-09-03 14:57:04 -07002282 goto check_scsi_status;
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002283 } else {
2284 ql_dbg(ql_dbg_io, fcport->vha, 0x3030,
2285 "scsi_status: 0x%x, lscsi_status: 0x%x\n",
2286 scsi_status, lscsi_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 }
2288
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002289 res = DID_OK << 16 | lscsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002290 logit = 0;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002291
Lalit Chandivade0374f552010-09-03 14:57:04 -07002292check_scsi_status:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002294 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 * Status.
2296 */
2297 if (lscsi_status != 0) {
Andrew Vasquezffec28a2007-01-29 10:22:27 -08002298 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002299 ql_dbg(ql_dbg_io, fcport->vha, 0x3020,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002300 "QUEUE FULL detected.\n");
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002301 logit = 1;
Andrew Vasquezffec28a2007-01-29 10:22:27 -08002302 break;
2303 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 if (lscsi_status != SS_CHECK_CONDITION)
2305 break;
2306
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002307 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 if (!(scsi_status & SS_SENSE_LEN_VALID))
2309 break;
2310
Andrew Vasquez55442132010-07-23 15:28:27 +05002311 qla2x00_handle_sense(sp, sense_data, par_sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002312 sense_len, rsp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 }
2314 break;
2315
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 case CS_PORT_LOGGED_OUT:
2317 case CS_PORT_CONFIG_CHG:
2318 case CS_PORT_BUSY:
2319 case CS_INCOMPLETE:
2320 case CS_PORT_UNAVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 case CS_TIMEOUT:
Chad Dupuisff454b02010-10-15 11:27:42 -07002322 case CS_RESET:
2323
Mike Christie056a4482008-08-19 18:45:29 -05002324 /*
2325 * We are going to have the fc class block the rport
2326 * while we try to recover so instruct the mid layer
2327 * to requeue until the class decides how to handle this.
2328 */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002329 res = DID_TRANSPORT_DISRUPTED << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002331 if (comp_status == CS_TIMEOUT) {
2332 if (IS_FWI2_CAPABLE(ha))
2333 break;
2334 else if ((le16_to_cpu(sts->status_flags) &
2335 SF_LOGOUT_SENT) == 0)
2336 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002338
Arun Easi5e19ed92012-02-09 11:15:51 -08002339 ql_dbg(ql_dbg_io, fcport->vha, 0x3021,
Chad Dupuis0e948972013-08-27 01:37:39 -04002340 "Port to be marked lost on fcport=%02x%02x%02x, current "
2341 "port state= %s.\n", fcport->d_id.b.domain,
2342 fcport->d_id.b.area, fcport->d_id.b.al_pa,
2343 port_state_str[atomic_read(&fcport->state)]);
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002344
2345 if (atomic_read(&fcport->state) == FCS_ONLINE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002346 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 break;
2348
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002349 case CS_ABORTED:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002350 res = DID_RESET << 16;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002351 break;
Arun Easibad75002010-05-04 15:01:30 -07002352
2353 case CS_DIF_ERROR:
Arun Easi8cb20492011-08-16 11:29:22 -07002354 logit = qla2x00_handle_dif_error(sp, sts24);
Arun Easifb6e4662012-08-22 14:21:32 -04002355 res = cp->result;
Arun Easibad75002010-05-04 15:01:30 -07002356 break;
Arun Easi9e522cd2012-08-22 14:21:31 -04002357
2358 case CS_TRANSPORT:
2359 res = DID_ERROR << 16;
2360
2361 if (!IS_PI_SPLIT_DET_CAPABLE(ha))
2362 break;
2363
2364 if (state_flags & BIT_4)
2365 scmd_printk(KERN_WARNING, cp,
2366 "Unsupported device '%s' found.\n",
2367 cp->device->vendor);
2368 break;
2369
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 default:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002371 res = DID_ERROR << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 break;
2373 }
2374
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002375out:
2376 if (logit)
Arun Easi5e19ed92012-02-09 11:15:51 -08002377 ql_dbg(ql_dbg_io, fcport->vha, 0x3022,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02002378 "FCP command status: 0x%x-0x%x (0x%x) nexus=%ld:%d:%llu "
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04002379 "portid=%02x%02x%02x oxid=0x%x cdb=%10phN len=0x%x "
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04002380 "rsp_info=0x%x resid=0x%x fw_resid=0x%x sp=%p cp=%p.\n",
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002381 comp_status, scsi_status, res, vha->host_no,
Chad Dupuiscfb09192011-11-18 09:03:07 -08002382 cp->device->id, cp->device->lun, fcport->d_id.b.domain,
2383 fcport->d_id.b.area, fcport->d_id.b.al_pa, ox_id,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04002384 cp->cmnd, scsi_bufflen(cp), rsp_info_len,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04002385 resid_len, fw_resid_len, sp, cp);
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002386
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002387 if (rsp->status_srb == NULL)
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002388 sp->done(ha, sp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389}
2390
2391/**
2392 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
2393 * @ha: SCSI driver HA context
2394 * @pkt: Entry pointer
2395 *
2396 * Extended sense data.
2397 */
2398static void
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002399qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002401 uint8_t sense_sz = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002402 struct qla_hw_data *ha = rsp->hw;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002403 struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002404 srb_t *sp = rsp->status_srb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 struct scsi_cmnd *cp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002406 uint32_t sense_len;
2407 uint8_t *sense_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002409 if (!sp || !GET_CMD_SENSE_LEN(sp))
2410 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002412 sense_len = GET_CMD_SENSE_LEN(sp);
2413 sense_ptr = GET_CMD_SENSE_PTR(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002415 cp = GET_CMD_SP(sp);
2416 if (cp == NULL) {
2417 ql_log(ql_log_warn, vha, 0x3025,
2418 "cmd is NULL: already returned to OS (sp=%p).\n", sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002420 rsp->status_srb = NULL;
2421 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002424 if (sense_len > sizeof(pkt->data))
2425 sense_sz = sizeof(pkt->data);
2426 else
2427 sense_sz = sense_len;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002428
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002429 /* Move sense data. */
2430 if (IS_FWI2_CAPABLE(ha))
2431 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
2432 memcpy(sense_ptr, pkt->data, sense_sz);
2433 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302c,
2434 sense_ptr, sense_sz);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002435
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002436 sense_len -= sense_sz;
2437 sense_ptr += sense_sz;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002438
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002439 SET_CMD_SENSE_PTR(sp, sense_ptr);
2440 SET_CMD_SENSE_LEN(sp, sense_len);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002441
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002442 /* Place command on done queue. */
2443 if (sense_len == 0) {
2444 rsp->status_srb = NULL;
2445 sp->done(ha, sp, cp->result);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002446 }
Giridhar Malavalic4631192011-11-18 09:03:08 -08002447}
2448
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449/**
2450 * qla2x00_error_entry() - Process an error entry.
2451 * @ha: SCSI driver HA context
2452 * @pkt: Entry pointer
2453 */
2454static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002455qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456{
2457 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002458 struct qla_hw_data *ha = vha->hw;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002459 const char func[] = "ERROR-IOCB";
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002460 uint16_t que = MSW(pkt->handle);
Arun Easia6fe35c2012-02-09 11:16:01 -08002461 struct req_que *req = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002462 int res = DID_ERROR << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002463
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002464 ql_dbg(ql_dbg_async, vha, 0x502a,
2465 "type of error status in response: 0x%x\n", pkt->entry_status);
2466
Arun Easia6fe35c2012-02-09 11:16:01 -08002467 if (que >= ha->max_req_queues || !ha->req_q_map[que])
2468 goto fatal;
2469
2470 req = ha->req_q_map[que];
2471
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002472 if (pkt->entry_status & RF_BUSY)
2473 res = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474
Giridhar Malavalic4631192011-11-18 09:03:08 -08002475 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
Arun Easia6fe35c2012-02-09 11:16:01 -08002476 if (sp) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002477 sp->done(ha, sp, res);
Arun Easia6fe35c2012-02-09 11:16:01 -08002478 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 }
Arun Easia6fe35c2012-02-09 11:16:01 -08002480fatal:
2481 ql_log(ql_log_warn, vha, 0x5030,
Chad Dupuisfd49a542015-08-04 13:37:58 -04002482 "Error entry - invalid handle/queue (%04x).\n", que);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483}
2484
2485/**
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002486 * qla24xx_mbx_completion() - Process mailbox command completions.
2487 * @ha: SCSI driver HA context
2488 * @mb0: Mailbox0 register
2489 */
2490static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002491qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002492{
2493 uint16_t cnt;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002494 uint32_t mboxes;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002495 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002496 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002497 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2498
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002499 /* Read all mbox registers? */
2500 mboxes = (1 << ha->mbx_count) - 1;
2501 if (!ha->mcp)
Masanari Iidaa7201012012-11-21 02:40:42 -05002502 ql_dbg(ql_dbg_async, vha, 0x504e, "MBX pointer ERROR.\n");
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002503 else
2504 mboxes = ha->mcp->in_mb;
2505
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002506 /* Load return mailbox registers. */
2507 ha->flags.mbox_int = 1;
2508 ha->mailbox_out[0] = mb0;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002509 mboxes >>= 1;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002510 wptr = (uint16_t __iomem *)&reg->mailbox1;
2511
2512 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002513 if (mboxes & BIT_0)
2514 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
2515
2516 mboxes >>= 1;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002517 wptr++;
2518 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002519}
2520
Armen Baloyan4440e462014-02-26 04:15:18 -05002521static void
2522qla24xx_abort_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
2523 struct abort_entry_24xx *pkt)
2524{
2525 const char func[] = "ABT_IOCB";
2526 srb_t *sp;
2527 struct srb_iocb *abt;
2528
2529 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
2530 if (!sp)
2531 return;
2532
2533 abt = &sp->u.iocb_cmd;
2534 abt->u.abt.comp_status = le32_to_cpu(pkt->nport_handle);
2535 sp->done(vha, sp, 0);
2536}
2537
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002538/**
2539 * qla24xx_process_response_queue() - Process response queue entries.
2540 * @ha: SCSI driver HA context
2541 */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002542void qla24xx_process_response_queue(struct scsi_qla_host *vha,
2543 struct rsp_que *rsp)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002544{
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002545 struct sts_entry_24xx *pkt;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002546 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002547
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002548 if (!vha->flags.online)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002549 return;
2550
Bruno Prémont262e2bf2016-06-30 17:00:32 +02002551 if (rsp->msix && rsp->msix->cpuid != smp_processor_id()) {
Quinn Trancdb898c2015-12-17 14:57:05 -05002552 /* if kernel does not notify qla of IRQ's CPU change,
2553 * then set it here.
2554 */
2555 rsp->msix->cpuid = smp_processor_id();
2556 ha->tgt.rspq_vector_cpuid = rsp->msix->cpuid;
2557 }
2558
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002559 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
2560 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002561
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002562 rsp->ring_index++;
2563 if (rsp->ring_index == rsp->length) {
2564 rsp->ring_index = 0;
2565 rsp->ring_ptr = rsp->ring;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002566 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002567 rsp->ring_ptr++;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002568 }
2569
2570 if (pkt->entry_status != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002571 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002572
Quinn Tranf83adb62014-04-11 16:54:43 -04002573 if (qlt_24xx_process_response_error(vha, pkt))
2574 goto process_err;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002575
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002576 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2577 wmb();
2578 continue;
2579 }
Quinn Tranf83adb62014-04-11 16:54:43 -04002580process_err:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002581
2582 switch (pkt->entry_type) {
2583 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002584 qla2x00_status_entry(vha, rsp, pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002585 break;
2586 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002587 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002588 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002589 case VP_RPT_ID_IOCB_TYPE:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002590 qla24xx_report_id_acquisition(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002591 (struct vp_rpt_id_entry_24xx *)pkt);
2592 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07002593 case LOGINOUT_PORT_IOCB_TYPE:
2594 qla24xx_logio_entry(vha, rsp->req,
2595 (struct logio_entry_24xx *)pkt);
2596 break;
Quinn Tranf83adb62014-04-11 16:54:43 -04002597 case CT_IOCB_TYPE:
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002598 qla24xx_els_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002599 break;
Quinn Tranf83adb62014-04-11 16:54:43 -04002600 case ELS_IOCB_TYPE:
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002601 qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE);
2602 break;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002603 case ABTS_RECV_24XX:
Quinn Tran2f424b92015-12-17 14:57:07 -05002604 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
2605 /* ensure that the ATIO queue is empty */
2606 qlt_handle_abts_recv(vha, (response_t *)pkt);
2607 break;
2608 } else {
2609 /* drop through */
2610 qlt_24xx_process_atio_queue(vha, 1);
2611 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002612 case ABTS_RESP_24XX:
2613 case CTIO_TYPE7:
2614 case NOTIFY_ACK_TYPE:
Quinn Tranf83adb62014-04-11 16:54:43 -04002615 case CTIO_CRC2:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002616 qlt_response_pkt_all_vps(vha, (response_t *)pkt);
2617 break;
Saurav Kashyap54883292011-08-16 11:31:48 -07002618 case MARKER_TYPE:
2619 /* Do nothing in this case, this check is to prevent it
2620 * from falling into default case
2621 */
2622 break;
Armen Baloyan4440e462014-02-26 04:15:18 -05002623 case ABORT_IOCB_TYPE:
2624 qla24xx_abort_iocb_entry(vha, rsp->req,
2625 (struct abort_entry_24xx *)pkt);
2626 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002627 default:
2628 /* Type Not Supported. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002629 ql_dbg(ql_dbg_async, vha, 0x5042,
2630 "Received unknown response pkt type %x "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002631 "entry status=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002632 pkt->entry_type, pkt->entry_status);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002633 break;
2634 }
2635 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2636 wmb();
2637 }
2638
2639 /* Adjust ring index */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002640 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002641 struct device_reg_82xx __iomem *reg = &ha->iobase->isp82;
2642 WRT_REG_DWORD(&reg->rsp_q_out[0], rsp->ring_index);
2643 } else
2644 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002645}
2646
Andrew Vasquez05236a02007-09-20 14:07:37 -07002647static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002648qla2xxx_check_risc_status(scsi_qla_host_t *vha)
Andrew Vasquez05236a02007-09-20 14:07:37 -07002649{
2650 int rval;
2651 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002652 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez05236a02007-09-20 14:07:37 -07002653 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2654
Chad Dupuisf73cb692014-02-26 04:15:06 -05002655 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2656 !IS_QLA27XX(ha))
Andrew Vasquez05236a02007-09-20 14:07:37 -07002657 return;
2658
2659 rval = QLA_SUCCESS;
2660 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
2661 RD_REG_DWORD(&reg->iobase_addr);
2662 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
2663 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
2664 rval == QLA_SUCCESS; cnt--) {
2665 if (cnt) {
2666 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
2667 udelay(10);
2668 } else
2669 rval = QLA_FUNCTION_TIMEOUT;
2670 }
2671 if (rval == QLA_SUCCESS)
2672 goto next_test;
2673
Bart Van Asscheb2ec76c2013-06-25 11:27:29 -04002674 rval = QLA_SUCCESS;
Andrew Vasquez05236a02007-09-20 14:07:37 -07002675 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
2676 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
2677 rval == QLA_SUCCESS; cnt--) {
2678 if (cnt) {
2679 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
2680 udelay(10);
2681 } else
2682 rval = QLA_FUNCTION_TIMEOUT;
2683 }
2684 if (rval != QLA_SUCCESS)
2685 goto done;
2686
2687next_test:
2688 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002689 ql_log(ql_log_info, vha, 0x504c,
2690 "Additional code -- 0x55AA.\n");
Andrew Vasquez05236a02007-09-20 14:07:37 -07002691
2692done:
2693 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
2694 RD_REG_DWORD(&reg->iobase_window);
2695}
2696
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002697/**
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002698 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP24xx.
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002699 * @irq:
2700 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002701 *
2702 * Called by system whenever the host adapter generates an interrupt.
2703 *
2704 * Returns handled flag.
2705 */
2706irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01002707qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002708{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002709 scsi_qla_host_t *vha;
2710 struct qla_hw_data *ha;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002711 struct device_reg_24xx __iomem *reg;
2712 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002713 unsigned long iter;
2714 uint32_t stat;
2715 uint32_t hccr;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002716 uint16_t mb[8];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002717 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002718 unsigned long flags;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002719
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002720 rsp = (struct rsp_que *) dev_id;
2721 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002722 ql_log(ql_log_info, NULL, 0x5059,
2723 "%s: NULL response queue pointer.\n", __func__);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002724 return IRQ_NONE;
2725 }
2726
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002727 ha = rsp->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002728 reg = &ha->iobase->isp24;
2729 status = 0;
2730
Andrew Vasquez85880802009-12-15 21:29:46 -08002731 if (unlikely(pci_channel_offline(ha->pdev)))
2732 return IRQ_HANDLED;
2733
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002734 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002735 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002736 for (iter = 50; iter--; ) {
2737 stat = RD_REG_DWORD(&reg->host_status);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04002738 if (qla2x00_check_reg32_for_disconnect(vha, stat))
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002739 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002740 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08002741 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07002742 break;
2743
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002744 hccr = RD_REG_DWORD(&reg->hccr);
2745
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002746 ql_log(ql_log_warn, vha, 0x504b,
2747 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2748 hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002749
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002750 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002751
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002752 ha->isp_ops->fw_dump(vha, 1);
2753 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002754 break;
2755 } else if ((stat & HSRX_RISC_INT) == 0)
2756 break;
2757
2758 switch (stat & 0xff) {
Arun Easifafbda92012-08-22 14:21:16 -04002759 case INTR_ROM_MB_SUCCESS:
2760 case INTR_ROM_MB_FAILED:
2761 case INTR_MB_SUCCESS:
2762 case INTR_MB_FAILED:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002763 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002764 status |= MBX_INTERRUPT;
2765
2766 break;
Arun Easifafbda92012-08-22 14:21:16 -04002767 case INTR_ASYNC_EVENT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002768 mb[0] = MSW(stat);
2769 mb[1] = RD_REG_WORD(&reg->mailbox1);
2770 mb[2] = RD_REG_WORD(&reg->mailbox2);
2771 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002772 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002773 break;
Arun Easifafbda92012-08-22 14:21:16 -04002774 case INTR_RSP_QUE_UPDATE:
2775 case INTR_RSP_QUE_UPDATE_83XX:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002776 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002777 break;
Quinn Tran2f424b92015-12-17 14:57:07 -05002778 case INTR_ATIO_QUE_UPDATE:{
2779 unsigned long flags2;
2780 spin_lock_irqsave(&ha->tgt.atio_lock, flags2);
2781 qlt_24xx_process_atio_queue(vha, 1);
2782 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002783 break;
Quinn Tran2f424b92015-12-17 14:57:07 -05002784 }
2785 case INTR_ATIO_RSP_QUE_UPDATE: {
2786 unsigned long flags2;
2787 spin_lock_irqsave(&ha->tgt.atio_lock, flags2);
2788 qlt_24xx_process_atio_queue(vha, 1);
2789 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2);
2790
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002791 qla24xx_process_response_queue(vha, rsp);
2792 break;
Quinn Tran2f424b92015-12-17 14:57:07 -05002793 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002794 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002795 ql_dbg(ql_dbg_async, vha, 0x504f,
2796 "Unrecognized interrupt type (%d).\n", stat * 0xff);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002797 break;
2798 }
2799 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2800 RD_REG_DWORD_RELAXED(&reg->hccr);
Giridhar Malavalicb860bb2012-08-22 14:21:30 -04002801 if (unlikely(IS_QLA83XX(ha) && (ha->pdev->revision == 1)))
2802 ndelay(3500);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002803 }
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -07002804 qla2x00_handle_mbx_completion(ha, status);
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002805 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002806
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002807 return IRQ_HANDLED;
2808}
2809
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002810static irqreturn_t
2811qla24xx_msix_rsp_q(int irq, void *dev_id)
2812{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002813 struct qla_hw_data *ha;
2814 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002815 struct device_reg_24xx __iomem *reg;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002816 struct scsi_qla_host *vha;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002817 unsigned long flags;
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002818 uint32_t stat = 0;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002819
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002820 rsp = (struct rsp_que *) dev_id;
2821 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002822 ql_log(ql_log_info, NULL, 0x505a,
2823 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002824 return IRQ_NONE;
2825 }
2826 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002827 reg = &ha->iobase->isp24;
2828
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002829 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002830
Anirban Chakrabortya67093d2010-02-04 14:17:59 -08002831 vha = pci_get_drvdata(ha->pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002832 /*
2833 * Use host_status register to check to PCI disconnection before we
2834 * we process the response queue.
2835 */
2836 stat = RD_REG_DWORD(&reg->host_status);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04002837 if (qla2x00_check_reg32_for_disconnect(vha, stat))
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002838 goto out;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002839 qla24xx_process_response_queue(vha, rsp);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002840 if (!ha->flags.disable_msix_handshake) {
Anirban Chakrabortyeb941142009-08-04 16:12:13 -07002841 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2842 RD_REG_DWORD_RELAXED(&reg->hccr);
2843 }
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002844out:
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002845 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002846
2847 return IRQ_HANDLED;
2848}
2849
2850static irqreturn_t
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002851qla25xx_msix_rsp_q(int irq, void *dev_id)
2852{
2853 struct qla_hw_data *ha;
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002854 scsi_qla_host_t *vha;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002855 struct rsp_que *rsp;
Anirban Chakraborty31557542009-12-02 10:36:55 -08002856 struct device_reg_24xx __iomem *reg;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002857 unsigned long flags;
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002858 uint32_t hccr = 0;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002859
2860 rsp = (struct rsp_que *) dev_id;
2861 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002862 ql_log(ql_log_info, NULL, 0x505b,
2863 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002864 return IRQ_NONE;
2865 }
2866 ha = rsp->hw;
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002867 vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002868
Anirban Chakraborty31557542009-12-02 10:36:55 -08002869 /* Clear the interrupt, if enabled, for this response queue */
Andrew Vasquezd4247542011-10-26 14:20:13 -07002870 if (!ha->flags.disable_msix_handshake) {
Anirban Chakraborty31557542009-12-02 10:36:55 -08002871 reg = &ha->iobase->isp24;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002872 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002873 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002874 hccr = RD_REG_DWORD_RELAXED(&reg->hccr);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002875 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002876 }
Joe Lawrencec821e0d2014-08-26 17:11:41 -04002877 if (qla2x00_check_reg32_for_disconnect(vha, hccr))
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002878 goto out;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002879 queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work);
2880
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002881out:
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002882 return IRQ_HANDLED;
2883}
2884
2885static irqreturn_t
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002886qla24xx_msix_default(int irq, void *dev_id)
2887{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002888 scsi_qla_host_t *vha;
2889 struct qla_hw_data *ha;
2890 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002891 struct device_reg_24xx __iomem *reg;
2892 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002893 uint32_t stat;
2894 uint32_t hccr;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002895 uint16_t mb[8];
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002896 unsigned long flags;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002897
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002898 rsp = (struct rsp_que *) dev_id;
2899 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002900 ql_log(ql_log_info, NULL, 0x505c,
2901 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002902 return IRQ_NONE;
2903 }
2904 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002905 reg = &ha->iobase->isp24;
2906 status = 0;
2907
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002908 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002909 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002910 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002911 stat = RD_REG_DWORD(&reg->host_status);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04002912 if (qla2x00_check_reg32_for_disconnect(vha, stat))
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002913 break;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002914 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08002915 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07002916 break;
2917
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002918 hccr = RD_REG_DWORD(&reg->hccr);
2919
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002920 ql_log(ql_log_info, vha, 0x5050,
2921 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2922 hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002923
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002924 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002925
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002926 ha->isp_ops->fw_dump(vha, 1);
2927 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002928 break;
2929 } else if ((stat & HSRX_RISC_INT) == 0)
2930 break;
2931
2932 switch (stat & 0xff) {
Arun Easifafbda92012-08-22 14:21:16 -04002933 case INTR_ROM_MB_SUCCESS:
2934 case INTR_ROM_MB_FAILED:
2935 case INTR_MB_SUCCESS:
2936 case INTR_MB_FAILED:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002937 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002938 status |= MBX_INTERRUPT;
2939
2940 break;
Arun Easifafbda92012-08-22 14:21:16 -04002941 case INTR_ASYNC_EVENT:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002942 mb[0] = MSW(stat);
2943 mb[1] = RD_REG_WORD(&reg->mailbox1);
2944 mb[2] = RD_REG_WORD(&reg->mailbox2);
2945 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002946 qla2x00_async_event(vha, rsp, mb);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002947 break;
Arun Easifafbda92012-08-22 14:21:16 -04002948 case INTR_RSP_QUE_UPDATE:
2949 case INTR_RSP_QUE_UPDATE_83XX:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002950 qla24xx_process_response_queue(vha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002951 break;
Quinn Tran2f424b92015-12-17 14:57:07 -05002952 case INTR_ATIO_QUE_UPDATE:{
2953 unsigned long flags2;
2954 spin_lock_irqsave(&ha->tgt.atio_lock, flags2);
2955 qlt_24xx_process_atio_queue(vha, 1);
2956 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002957 break;
Quinn Tran2f424b92015-12-17 14:57:07 -05002958 }
2959 case INTR_ATIO_RSP_QUE_UPDATE: {
2960 unsigned long flags2;
2961 spin_lock_irqsave(&ha->tgt.atio_lock, flags2);
2962 qlt_24xx_process_atio_queue(vha, 1);
2963 spin_unlock_irqrestore(&ha->tgt.atio_lock, flags2);
2964
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002965 qla24xx_process_response_queue(vha, rsp);
2966 break;
Quinn Tran2f424b92015-12-17 14:57:07 -05002967 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002968 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002969 ql_dbg(ql_dbg_async, vha, 0x5051,
2970 "Unrecognized interrupt type (%d).\n", stat & 0xff);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002971 break;
2972 }
2973 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002974 } while (0);
gurinder.shergill@hp.com36439832013-04-23 10:13:17 -07002975 qla2x00_handle_mbx_completion(ha, status);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002976 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002977
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002978 return IRQ_HANDLED;
2979}
2980
2981/* Interrupt handling helpers. */
2982
2983struct qla_init_msix_entry {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002984 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07002985 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002986};
2987
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002988static struct qla_init_msix_entry msix_entries[3] = {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002989 { "qla2xxx (default)", qla24xx_msix_default },
2990 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002991 { "qla2xxx (multiq)", qla25xx_msix_rsp_q },
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002992};
2993
Giridhar Malavalia9083012010-04-12 17:59:55 -07002994static struct qla_init_msix_entry qla82xx_msix_entries[2] = {
2995 { "qla2xxx (default)", qla82xx_msix_default },
2996 { "qla2xxx (rsp_q)", qla82xx_msix_rsp_q },
2997};
2998
Arun Easiaa230bc2013-01-30 03:34:39 -05002999static struct qla_init_msix_entry qla83xx_msix_entries[3] = {
3000 { "qla2xxx (default)", qla24xx_msix_default },
3001 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
3002 { "qla2xxx (atio_q)", qla83xx_msix_atio_q },
3003};
3004
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003005static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003006qla24xx_disable_msix(struct qla_hw_data *ha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003007{
3008 int i;
3009 struct qla_msix_entry *qentry;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003010 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003011
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003012 for (i = 0; i < ha->msix_count; i++) {
3013 qentry = &ha->msix_entries[i];
Quinn Trancdb898c2015-12-17 14:57:05 -05003014 if (qentry->have_irq) {
3015 /* un-register irq cpu affinity notification */
3016 irq_set_affinity_notifier(qentry->vector, NULL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003017 free_irq(qentry->vector, qentry->rsp);
Quinn Trancdb898c2015-12-17 14:57:05 -05003018 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003019 }
3020 pci_disable_msix(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003021 kfree(ha->msix_entries);
3022 ha->msix_entries = NULL;
3023 ha->flags.msix_enabled = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003024 ql_dbg(ql_dbg_init, vha, 0x0042,
3025 "Disabled the MSI.\n");
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003026}
3027
3028static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003029qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003030{
Lalit Chandivadead038fa2009-01-22 09:45:33 -08003031#define MIN_MSIX_COUNT 2
Chad Dupuisf3247772014-02-26 04:15:14 -05003032#define ATIO_VECTOR 2
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003033 int i, ret;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003034 struct msix_entry *entries;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003035 struct qla_msix_entry *qentry;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003036 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003037
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003038 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
Giridhar Malavalia9083012010-04-12 17:59:55 -07003039 GFP_KERNEL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003040 if (!entries) {
3041 ql_log(ql_log_warn, vha, 0x00bc,
3042 "Failed to allocate memory for msix_entry.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003043 return -ENOMEM;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003044 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003045
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003046 for (i = 0; i < ha->msix_count; i++)
3047 entries[i].entry = i;
3048
Alexander Gordeev84e32a02014-08-18 08:01:47 +02003049 ret = pci_enable_msix_range(ha->pdev,
3050 entries, MIN_MSIX_COUNT, ha->msix_count);
3051 if (ret < 0) {
3052 ql_log(ql_log_fatal, vha, 0x00c7,
3053 "MSI-X: Failed to enable support, "
3054 "giving up -- %d/%d.\n",
3055 ha->msix_count, ret);
3056 goto msix_out;
3057 } else if (ret < ha->msix_count) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003058 ql_log(ql_log_warn, vha, 0x00c6,
3059 "MSI-X: Failed to enable support "
3060 "-- %d/%d\n Retry with %d vectors.\n",
3061 ha->msix_count, ret, ret);
Quinn Trancb432852016-02-04 11:45:16 -05003062 ha->msix_count = ret;
3063 ha->max_rsp_queues = ha->msix_count - 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003064 }
3065 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
3066 ha->msix_count, GFP_KERNEL);
3067 if (!ha->msix_entries) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003068 ql_log(ql_log_fatal, vha, 0x00c8,
3069 "Failed to allocate memory for ha->msix_entries.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003070 ret = -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003071 goto msix_out;
3072 }
3073 ha->flags.msix_enabled = 1;
3074
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003075 for (i = 0; i < ha->msix_count; i++) {
3076 qentry = &ha->msix_entries[i];
3077 qentry->vector = entries[i].vector;
3078 qentry->entry = entries[i].entry;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003079 qentry->have_irq = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003080 qentry->rsp = NULL;
Quinn Trancdb898c2015-12-17 14:57:05 -05003081 qentry->irq_notify.notify = qla_irq_affinity_notify;
3082 qentry->irq_notify.release = qla_irq_affinity_release;
3083 qentry->cpuid = -1;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003084 }
3085
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003086 /* Enable MSI-X vectors for the base queue */
Chad Dupuisf3247772014-02-26 04:15:14 -05003087 for (i = 0; i < 2; i++) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003088 qentry = &ha->msix_entries[i];
Johannes Thumshirnef8d1d512016-07-06 09:51:50 +02003089 qentry->rsp = rsp;
3090 rsp->msix = qentry;
Chad Dupuisf3247772014-02-26 04:15:14 -05003091 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07003092 ret = request_irq(qentry->vector,
3093 qla82xx_msix_entries[i].handler,
3094 0, qla82xx_msix_entries[i].name, rsp);
Chad Dupuisf3247772014-02-26 04:15:14 -05003095 else
Giridhar Malavalia9083012010-04-12 17:59:55 -07003096 ret = request_irq(qentry->vector,
3097 msix_entries[i].handler,
3098 0, msix_entries[i].name, rsp);
Chad Dupuisf3247772014-02-26 04:15:14 -05003099 if (ret)
3100 goto msix_register_fail;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003101 qentry->have_irq = 1;
Quinn Trancdb898c2015-12-17 14:57:05 -05003102
3103 /* Register for CPU affinity notification. */
3104 irq_set_affinity_notifier(qentry->vector, &qentry->irq_notify);
3105
3106 /* Schedule work (ie. trigger a notification) to read cpu
3107 * mask for this specific irq.
3108 * kref_get is required because
3109 * irq_affinity_notify() will do
3110 * kref_put().
3111 */
3112 kref_get(&qentry->irq_notify.kref);
3113 schedule_work(&qentry->irq_notify.work);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003114 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003115
Chad Dupuisf3247772014-02-26 04:15:14 -05003116 /*
3117 * If target mode is enable, also request the vector for the ATIO
3118 * queue.
3119 */
3120 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) {
3121 qentry = &ha->msix_entries[ATIO_VECTOR];
Johannes Thumshirnef8d1d512016-07-06 09:51:50 +02003122 qentry->rsp = rsp;
3123 rsp->msix = qentry;
Chad Dupuisf3247772014-02-26 04:15:14 -05003124 ret = request_irq(qentry->vector,
3125 qla83xx_msix_entries[ATIO_VECTOR].handler,
3126 0, qla83xx_msix_entries[ATIO_VECTOR].name, rsp);
3127 qentry->have_irq = 1;
Chad Dupuisf3247772014-02-26 04:15:14 -05003128 }
3129
3130msix_register_fail:
3131 if (ret) {
3132 ql_log(ql_log_fatal, vha, 0x00cb,
3133 "MSI-X: unable to register handler -- %x/%d.\n",
3134 qentry->vector, ret);
3135 qla24xx_disable_msix(ha);
3136 ha->mqenable = 0;
3137 goto msix_out;
3138 }
3139
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003140 /* Enable MSI-X vector for response queue update for queue 0 */
Chad Dupuisf73cb692014-02-26 04:15:06 -05003141 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003142 if (ha->msixbase && ha->mqiobase &&
3143 (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
3144 ha->mqenable = 1;
3145 } else
3146 if (ha->mqiobase
3147 && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
3148 ha->mqenable = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003149 ql_dbg(ql_dbg_multiq, vha, 0xc005,
3150 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
3151 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
3152 ql_dbg(ql_dbg_init, vha, 0x0055,
3153 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
3154 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003155
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003156msix_out:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003157 kfree(entries);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003158 return ret;
3159}
3160
3161int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003162qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003163{
Sawan Chandak7fa3e232013-10-30 03:38:10 -04003164 int ret = QLA_FUNCTION_FAILED;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003165 device_reg_t *reg = ha->iobase;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003166 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003167
3168 /* If possible, enable MSI-X. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003169 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
Chad Dupuisf73cb692014-02-26 04:15:06 -05003170 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha) && !IS_QLAFX00(ha) &&
3171 !IS_QLA27XX(ha))
Ben Hutchings6377a7a2010-03-19 16:59:19 -07003172 goto skip_msi;
3173
3174 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
3175 (ha->pdev->subsystem_device == 0x7040 ||
3176 ha->pdev->subsystem_device == 0x7041 ||
3177 ha->pdev->subsystem_device == 0x1705)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003178 ql_log(ql_log_warn, vha, 0x0034,
3179 "MSI-X: Unsupported ISP 2432 SSVID/SSDID (0x%X,0x%X).\n",
Ben Hutchings6377a7a2010-03-19 16:59:19 -07003180 ha->pdev->subsystem_vendor,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003181 ha->pdev->subsystem_device);
Ben Hutchings6377a7a2010-03-19 16:59:19 -07003182 goto skip_msi;
3183 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003184
Chad Dupuis42cd4f52011-08-16 11:29:24 -07003185 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003186 ql_log(ql_log_warn, vha, 0x0035,
3187 "MSI-X; Unsupported ISP2432 (0x%X, 0x%X).\n",
Chad Dupuis42cd4f52011-08-16 11:29:24 -07003188 ha->pdev->revision, QLA_MSIX_CHIP_REV_24XX);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003189 goto skip_msix;
3190 }
3191
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003192 ret = qla24xx_enable_msix(ha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003193 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003194 ql_dbg(ql_dbg_init, vha, 0x0036,
3195 "MSI-X: Enabled (0x%X, 0x%X).\n",
3196 ha->chip_revision, ha->fw_attributes);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003197 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003198 }
Sawan Chandak7fa3e232013-10-30 03:38:10 -04003199
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003200skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07003201
Sawan Chandak7fa3e232013-10-30 03:38:10 -04003202 ql_log(ql_log_info, vha, 0x0037,
3203 "Falling back-to MSI mode -%d.\n", ret);
3204
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003205 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
Chad Dupuisf73cb692014-02-26 04:15:06 -05003206 !IS_QLA8001(ha) && !IS_P3P_TYPE(ha) && !IS_QLAFX00(ha) &&
3207 !IS_QLA27XX(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07003208 goto skip_msi;
3209
3210 ret = pci_enable_msi(ha->pdev);
3211 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003212 ql_dbg(ql_dbg_init, vha, 0x0038,
3213 "MSI: Enabled.\n");
Andrew Vasquezcbedb602007-05-07 07:43:02 -07003214 ha->flags.msi_enabled = 1;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003215 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003216 ql_log(ql_log_warn, vha, 0x0039,
Sawan Chandak7fa3e232013-10-30 03:38:10 -04003217 "Falling back-to INTa mode -- %d.\n", ret);
3218skip_msi:
Giridhar Malavalia033b652012-08-22 14:21:07 -04003219
3220 /* Skip INTx on ISP82xx. */
3221 if (!ha->flags.msi_enabled && IS_QLA82XX(ha))
3222 return QLA_FUNCTION_FAILED;
3223
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003224 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Mike Hernandez7992abf2010-11-23 16:52:47 -08003225 ha->flags.msi_enabled ? 0 : IRQF_SHARED,
3226 QLA2XXX_DRIVER_NAME, rsp);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003227 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003228 ql_log(ql_log_warn, vha, 0x003a,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003229 "Failed to reserve interrupt %d already in use.\n",
3230 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003231 goto fail;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003232 } else if (!ha->flags.msi_enabled) {
Saurav Kashyap68d91cb2012-11-21 02:40:44 -05003233 ql_dbg(ql_dbg_init, vha, 0x0125,
3234 "INTa mode: Enabled.\n");
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003235 ha->flags.mr_intr_valid = 1;
3236 }
Mike Hernandez7992abf2010-11-23 16:52:47 -08003237
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003238clear_risc_ints:
Joe Carnuccio4bb2efc2014-09-25 05:16:42 -04003239 if (IS_FWI2_CAPABLE(ha) || IS_QLAFX00(ha))
3240 goto fail;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003241
Andrew Vasquezc6952482008-04-03 13:13:17 -07003242 spin_lock_irq(&ha->hardware_lock);
Joe Carnuccio4bb2efc2014-09-25 05:16:42 -04003243 WRT_REG_WORD(&reg->isp.semaphore, 0);
Andrew Vasquezc6952482008-04-03 13:13:17 -07003244 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08003245
3246fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003247 return ret;
3248}
3249
3250void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003251qla2x00_free_irqs(scsi_qla_host_t *vha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003252{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003253 struct qla_hw_data *ha = vha->hw;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003254 struct rsp_que *rsp;
3255
3256 /*
3257 * We need to check that ha->rsp_q_map is valid in case we are called
3258 * from a probe failure context.
3259 */
3260 if (!ha->rsp_q_map || !ha->rsp_q_map[0])
3261 return;
3262 rsp = ha->rsp_q_map[0];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003263
3264 if (ha->flags.msix_enabled)
3265 qla24xx_disable_msix(ha);
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003266 else if (ha->flags.msi_enabled) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003267 free_irq(ha->pdev->irq, rsp);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07003268 pci_disable_msi(ha->pdev);
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003269 } else
3270 free_irq(ha->pdev->irq, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08003271}
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003272
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003273
3274int qla25xx_request_irq(struct rsp_que *rsp)
3275{
3276 struct qla_hw_data *ha = rsp->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003277 struct qla_init_msix_entry *intr = &msix_entries[2];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003278 struct qla_msix_entry *msix = rsp->msix;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003279 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003280 int ret;
3281
3282 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
3283 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003284 ql_log(ql_log_fatal, vha, 0x00e6,
3285 "MSI-X: Unable to register handler -- %x/%d.\n",
3286 msix->vector, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003287 return ret;
3288 }
3289 msix->have_irq = 1;
3290 msix->rsp = rsp;
3291 return ret;
3292}
Quinn Trancdb898c2015-12-17 14:57:05 -05003293
3294
3295/* irq_set_affinity/irqbalance will trigger notification of cpu mask update */
3296static void qla_irq_affinity_notify(struct irq_affinity_notify *notify,
3297 const cpumask_t *mask)
3298{
3299 struct qla_msix_entry *e =
3300 container_of(notify, struct qla_msix_entry, irq_notify);
3301 struct qla_hw_data *ha;
3302 struct scsi_qla_host *base_vha;
3303
3304 /* user is recommended to set mask to just 1 cpu */
3305 e->cpuid = cpumask_first(mask);
3306
3307 ha = e->rsp->hw;
3308 base_vha = pci_get_drvdata(ha->pdev);
3309
3310 ql_dbg(ql_dbg_init, base_vha, 0xffff,
3311 "%s: host %ld : vector %d cpu %d \n", __func__,
3312 base_vha->host_no, e->vector, e->cpuid);
3313
3314 if (e->have_irq) {
3315 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) &&
3316 (e->entry == QLA83XX_RSPQ_MSIX_ENTRY_NUMBER)) {
3317 ha->tgt.rspq_vector_cpuid = e->cpuid;
3318 ql_dbg(ql_dbg_init, base_vha, 0xffff,
3319 "%s: host%ld: rspq vector %d cpu %d runtime change\n",
3320 __func__, base_vha->host_no, e->vector, e->cpuid);
3321 }
3322 }
3323}
3324
Quinn Tranfb3269b2015-12-17 14:57:06 -05003325static void qla_irq_affinity_release(struct kref *ref)
Quinn Trancdb898c2015-12-17 14:57:05 -05003326{
3327 struct irq_affinity_notify *notify =
3328 container_of(ref, struct irq_affinity_notify, kref);
3329 struct qla_msix_entry *e =
3330 container_of(notify, struct qla_msix_entry, irq_notify);
3331 struct scsi_qla_host *base_vha = pci_get_drvdata(e->rsp->hw->pdev);
3332
3333 ql_dbg(ql_dbg_init, base_vha, 0xffff,
3334 "%s: host%ld: vector %d cpu %d \n", __func__,
3335 base_vha->host_no, e->vector, e->cpuid);
3336}