blob: 873c82014b16067ef6479b3fb306c0e5be5a427f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Chad Dupuis46152ce2012-08-22 14:21:08 -04003 * Copyright (c) 2003-2012 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_process_completed_request(struct scsi_qla_host *,
18 struct req_que *, uint32_t);
19static void qla2x00_status_entry(scsi_qla_host_t *, struct rsp_que *, void *);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070020static void qla2x00_status_cont_entry(struct rsp_que *, sts_cont_entry_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080021static void qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
22 sts_entry_t *);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070023
Linus Torvalds1da177e2005-04-16 15:20:36 -070024/**
25 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
26 * @irq:
27 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 *
29 * Called by system whenever the host adapter generates an interrupt.
30 *
31 * Returns handled flag.
32 */
33irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +010034qla2100_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080036 scsi_qla_host_t *vha;
37 struct qla_hw_data *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -070038 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 unsigned long iter;
Seokmann Ju14e660e2007-09-20 14:07:36 -070041 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070042 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080043 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070044 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080046 rsp = (struct rsp_que *) dev_id;
47 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -080048 ql_log(ql_log_info, NULL, 0x505d,
49 "%s: NULL response queue pointer.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 return (IRQ_NONE);
51 }
52
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080053 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -070054 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 status = 0;
56
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070057 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070058 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 for (iter = 50; iter--; ) {
Seokmann Ju14e660e2007-09-20 14:07:36 -070060 hccr = RD_REG_WORD(&reg->hccr);
61 if (hccr & HCCR_RISC_PAUSE) {
62 if (pci_channel_offline(ha->pdev))
63 break;
64
65 /*
66 * Issue a "HARD" reset in order for the RISC interrupt
Justin P. Mattocka06a0f82011-06-23 23:22:27 -070067 * bit to be cleared. Schedule a big hammer to get
Seokmann Ju14e660e2007-09-20 14:07:36 -070068 * out of the RISC PAUSED state.
69 */
70 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
71 RD_REG_WORD(&reg->hccr);
72
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080073 ha->isp_ops->fw_dump(vha, 1);
74 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -070075 break;
76 } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 break;
78
79 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
80 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
81 RD_REG_WORD(&reg->hccr);
82
83 /* Get mailbox data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -070084 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
85 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080086 qla2x00_mbx_completion(vha, mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 status |= MBX_INTERRUPT;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070088 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
89 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
90 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
91 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080092 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 } else {
94 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -070095 ql_dbg(ql_dbg_async, vha, 0x5025,
96 "Unrecognized interrupt type (%d).\n",
97 mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 }
99 /* Release mailbox registers. */
100 WRT_REG_WORD(&reg->semaphore, 0);
101 RD_REG_WORD(&reg->semaphore);
102 } else {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800103 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
106 RD_REG_WORD(&reg->hccr);
107 }
108 }
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700109 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
112 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800114 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 }
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 return (IRQ_HANDLED);
118}
119
120/**
121 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
122 * @irq:
123 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 *
125 * Called by system whenever the host adapter generates an interrupt.
126 *
127 * Returns handled flag.
128 */
129irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100130qla2300_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800132 scsi_qla_host_t *vha;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700133 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 unsigned long iter;
136 uint32_t stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700138 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800139 struct rsp_que *rsp;
140 struct qla_hw_data *ha;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700141 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800143 rsp = (struct rsp_que *) dev_id;
144 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -0800145 ql_log(ql_log_info, NULL, 0x5058,
146 "%s: NULL response queue pointer.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 return (IRQ_NONE);
148 }
149
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800150 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700151 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 status = 0;
153
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700154 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700155 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 for (iter = 50; iter--; ) {
157 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
158 if (stat & HSR_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800159 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -0700160 break;
161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 hccr = RD_REG_WORD(&reg->hccr);
163 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700164 ql_log(ql_log_warn, vha, 0x5026,
165 "Parity error -- HCCR=%x, Dumping "
166 "firmware.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700168 ql_log(ql_log_warn, vha, 0x5027,
169 "RISC paused -- HCCR=%x, Dumping "
170 "firmware.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 /*
173 * Issue a "HARD" reset in order for the RISC
174 * interrupt bit to be cleared. Schedule a big
Justin P. Mattocka06a0f82011-06-23 23:22:27 -0700175 * hammer to get out of the RISC PAUSED state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 */
177 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
178 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800179
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800180 ha->isp_ops->fw_dump(vha, 1);
181 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 break;
183 } else if ((stat & HSR_RISC_INT) == 0)
184 break;
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 case 0x1:
188 case 0x2:
189 case 0x10:
190 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800191 qla2x00_mbx_completion(vha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 status |= MBX_INTERRUPT;
193
194 /* Release mailbox registers. */
195 WRT_REG_WORD(&reg->semaphore, 0);
196 break;
197 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700198 mb[0] = MSW(stat);
199 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
200 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
201 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800202 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700203 break;
204 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800205 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 break;
207 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700208 mb[0] = MBA_CMPLT_1_16BIT;
209 mb[1] = MSW(stat);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800210 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 break;
212 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700213 mb[0] = MBA_SCSI_COMPLETION;
214 mb[1] = MSW(stat);
215 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800216 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 break;
218 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700219 ql_dbg(ql_dbg_async, vha, 0x5028,
220 "Unrecognized interrupt type (%d).\n", stat & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 break;
222 }
223 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
224 RD_REG_WORD_RELAXED(&reg->hccr);
225 }
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700226 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
229 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800231 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 }
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 return (IRQ_HANDLED);
235}
236
237/**
238 * qla2x00_mbx_completion() - Process mailbox command completions.
239 * @ha: SCSI driver HA context
240 * @mb0: Mailbox0 register
241 */
242static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800243qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
245 uint16_t cnt;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800246 uint32_t mboxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800248 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700249 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800251 /* Read all mbox registers? */
252 mboxes = (1 << ha->mbx_count) - 1;
253 if (!ha->mcp)
Masanari Iidaa7201012012-11-21 02:40:42 -0500254 ql_dbg(ql_dbg_async, vha, 0x5001, "MBX pointer ERROR.\n");
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800255 else
256 mboxes = ha->mcp->in_mb;
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 /* Load return mailbox registers. */
259 ha->flags.mbox_int = 1;
260 ha->mailbox_out[0] = mb0;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800261 mboxes >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
263
264 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700265 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800267 if ((cnt == 4 || cnt == 5) && (mboxes & BIT_0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800269 else if (mboxes & BIT_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 wptr++;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -0800273 mboxes >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275}
276
Andrew Vasquez8a659572009-02-08 20:50:12 -0800277static void
278qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
279{
280 static char *event[] =
281 { "Complete", "Request Notification", "Time Extension" };
282 int rval;
283 struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
284 uint16_t __iomem *wptr;
285 uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
286
287 /* Seed data -- mailbox1 -> mailbox7. */
288 wptr = (uint16_t __iomem *)&reg24->mailbox1;
289 for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
290 mb[cnt] = RD_REG_WORD(wptr);
291
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700292 ql_dbg(ql_dbg_async, vha, 0x5021,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800293 "Inter-Driver Communication %s -- "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700294 "%04x %04x %04x %04x %04x %04x %04x.\n",
295 event[aen & 0xff], mb[0], mb[1], mb[2], mb[3],
296 mb[4], mb[5], mb[6]);
Chad Dupuisbf5b8ad2012-08-22 14:21:24 -0400297 if ((aen == MBA_IDC_COMPLETE && mb[1] >> 15)) {
298 vha->hw->flags.idc_compl_status = 1;
299 if (vha->hw->notify_dcbx_comp)
300 complete(&vha->hw->dcbx_comp);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400301 }
Andrew Vasquez8a659572009-02-08 20:50:12 -0800302
Chad Dupuisbf5b8ad2012-08-22 14:21:24 -0400303 /* Acknowledgement needed? [Notify && non-zero timeout]. */
304 timeout = (descr >> 8) & 0xf;
305 if (aen != MBA_IDC_NOTIFY || !timeout)
306 return;
307
308 ql_dbg(ql_dbg_async, vha, 0x5022,
309 "%lu Inter-Driver Communication %s -- ACK timeout=%d.\n",
310 vha->host_no, event[aen & 0xff], timeout);
311
Andrew Vasquez8a659572009-02-08 20:50:12 -0800312 rval = qla2x00_post_idc_ack_work(vha, mb);
313 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700314 ql_log(ql_log_warn, vha, 0x5023,
Andrew Vasquez8a659572009-02-08 20:50:12 -0800315 "IDC failed to post ACK.\n");
316}
317
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400318#define LS_UNKNOWN 2
Joe Carnucciod0297c92012-11-21 02:40:40 -0500319const char *
320qla2x00_get_link_speed_str(struct qla_hw_data *ha, uint16_t speed)
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400321{
Joe Carnucciod0297c92012-11-21 02:40:40 -0500322 static const char * const link_speeds[] = {
323 "1", "2", "?", "4", "8", "16", "10"
324 };
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400325
326 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Joe Carnucciod0297c92012-11-21 02:40:40 -0500327 return link_speeds[0];
328 else if (speed == 0x13)
329 return link_speeds[6];
330 else if (speed < 6)
331 return link_speeds[speed];
332 else
333 return link_speeds[LS_UNKNOWN];
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400334}
335
Saurav Kashyapfa492632012-11-21 02:40:29 -0500336static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400337qla83xx_handle_8200_aen(scsi_qla_host_t *vha, uint16_t *mb)
338{
339 struct qla_hw_data *ha = vha->hw;
340
341 /*
342 * 8200 AEN Interpretation:
343 * mb[0] = AEN code
344 * mb[1] = AEN Reason code
345 * mb[2] = LSW of Peg-Halt Status-1 Register
346 * mb[6] = MSW of Peg-Halt Status-1 Register
347 * mb[3] = LSW of Peg-Halt Status-2 register
348 * mb[7] = MSW of Peg-Halt Status-2 register
349 * mb[4] = IDC Device-State Register value
350 * mb[5] = IDC Driver-Presence Register value
351 */
352 ql_dbg(ql_dbg_async, vha, 0x506b, "AEN Code: mb[0] = 0x%x AEN reason: "
353 "mb[1] = 0x%x PH-status1: mb[2] = 0x%x PH-status1: mb[6] = 0x%x.\n",
354 mb[0], mb[1], mb[2], mb[6]);
355 ql_dbg(ql_dbg_async, vha, 0x506c, "PH-status2: mb[3] = 0x%x "
356 "PH-status2: mb[7] = 0x%x Device-State: mb[4] = 0x%x "
357 "Drv-Presence: mb[5] = 0x%x.\n", mb[3], mb[7], mb[4], mb[5]);
358
359 if (mb[1] & (IDC_PEG_HALT_STATUS_CHANGE | IDC_NIC_FW_REPORTED_FAILURE |
360 IDC_HEARTBEAT_FAILURE)) {
361 ha->flags.nic_core_hung = 1;
362 ql_log(ql_log_warn, vha, 0x5060,
363 "83XX: F/W Error Reported: Check if reset required.\n");
364
365 if (mb[1] & IDC_PEG_HALT_STATUS_CHANGE) {
366 uint32_t protocol_engine_id, fw_err_code, err_level;
367
368 /*
369 * IDC_PEG_HALT_STATUS_CHANGE interpretation:
370 * - PEG-Halt Status-1 Register:
371 * (LSW = mb[2], MSW = mb[6])
372 * Bits 0-7 = protocol-engine ID
373 * Bits 8-28 = f/w error code
374 * Bits 29-31 = Error-level
375 * Error-level 0x1 = Non-Fatal error
376 * Error-level 0x2 = Recoverable Fatal error
377 * Error-level 0x4 = UnRecoverable Fatal error
378 * - PEG-Halt Status-2 Register:
379 * (LSW = mb[3], MSW = mb[7])
380 */
381 protocol_engine_id = (mb[2] & 0xff);
382 fw_err_code = (((mb[2] & 0xff00) >> 8) |
383 ((mb[6] & 0x1fff) << 8));
384 err_level = ((mb[6] & 0xe000) >> 13);
385 ql_log(ql_log_warn, vha, 0x5061, "PegHalt Status-1 "
386 "Register: protocol_engine_id=0x%x "
387 "fw_err_code=0x%x err_level=0x%x.\n",
388 protocol_engine_id, fw_err_code, err_level);
389 ql_log(ql_log_warn, vha, 0x5062, "PegHalt Status-2 "
390 "Register: 0x%x%x.\n", mb[7], mb[3]);
391 if (err_level == ERR_LEVEL_NON_FATAL) {
392 ql_log(ql_log_warn, vha, 0x5063,
393 "Not a fatal error, f/w has recovered "
394 "iteself.\n");
395 } else if (err_level == ERR_LEVEL_RECOVERABLE_FATAL) {
396 ql_log(ql_log_fatal, vha, 0x5064,
397 "Recoverable Fatal error: Chip reset "
398 "required.\n");
399 qla83xx_schedule_work(vha,
400 QLA83XX_NIC_CORE_RESET);
401 } else if (err_level == ERR_LEVEL_UNRECOVERABLE_FATAL) {
402 ql_log(ql_log_fatal, vha, 0x5065,
403 "Unrecoverable Fatal error: Set FAILED "
404 "state, reboot required.\n");
405 qla83xx_schedule_work(vha,
406 QLA83XX_NIC_CORE_UNRECOVERABLE);
407 }
408 }
409
410 if (mb[1] & IDC_NIC_FW_REPORTED_FAILURE) {
411 uint16_t peg_fw_state, nw_interface_link_up;
412 uint16_t nw_interface_signal_detect, sfp_status;
413 uint16_t htbt_counter, htbt_monitor_enable;
414 uint16_t sfp_additonal_info, sfp_multirate;
415 uint16_t sfp_tx_fault, link_speed, dcbx_status;
416
417 /*
418 * IDC_NIC_FW_REPORTED_FAILURE interpretation:
419 * - PEG-to-FC Status Register:
420 * (LSW = mb[2], MSW = mb[6])
421 * Bits 0-7 = Peg-Firmware state
422 * Bit 8 = N/W Interface Link-up
423 * Bit 9 = N/W Interface signal detected
424 * Bits 10-11 = SFP Status
425 * SFP Status 0x0 = SFP+ transceiver not expected
426 * SFP Status 0x1 = SFP+ transceiver not present
427 * SFP Status 0x2 = SFP+ transceiver invalid
428 * SFP Status 0x3 = SFP+ transceiver present and
429 * valid
430 * Bits 12-14 = Heartbeat Counter
431 * Bit 15 = Heartbeat Monitor Enable
432 * Bits 16-17 = SFP Additional Info
433 * SFP info 0x0 = Unregocnized transceiver for
434 * Ethernet
435 * SFP info 0x1 = SFP+ brand validation failed
436 * SFP info 0x2 = SFP+ speed validation failed
437 * SFP info 0x3 = SFP+ access error
438 * Bit 18 = SFP Multirate
439 * Bit 19 = SFP Tx Fault
440 * Bits 20-22 = Link Speed
441 * Bits 23-27 = Reserved
442 * Bits 28-30 = DCBX Status
443 * DCBX Status 0x0 = DCBX Disabled
444 * DCBX Status 0x1 = DCBX Enabled
445 * DCBX Status 0x2 = DCBX Exchange error
446 * Bit 31 = Reserved
447 */
448 peg_fw_state = (mb[2] & 0x00ff);
449 nw_interface_link_up = ((mb[2] & 0x0100) >> 8);
450 nw_interface_signal_detect = ((mb[2] & 0x0200) >> 9);
451 sfp_status = ((mb[2] & 0x0c00) >> 10);
452 htbt_counter = ((mb[2] & 0x7000) >> 12);
453 htbt_monitor_enable = ((mb[2] & 0x8000) >> 15);
454 sfp_additonal_info = (mb[6] & 0x0003);
455 sfp_multirate = ((mb[6] & 0x0004) >> 2);
456 sfp_tx_fault = ((mb[6] & 0x0008) >> 3);
457 link_speed = ((mb[6] & 0x0070) >> 4);
458 dcbx_status = ((mb[6] & 0x7000) >> 12);
459
460 ql_log(ql_log_warn, vha, 0x5066,
461 "Peg-to-Fc Status Register:\n"
462 "peg_fw_state=0x%x, nw_interface_link_up=0x%x, "
463 "nw_interface_signal_detect=0x%x"
464 "\nsfp_statis=0x%x.\n ", peg_fw_state,
465 nw_interface_link_up, nw_interface_signal_detect,
466 sfp_status);
467 ql_log(ql_log_warn, vha, 0x5067,
468 "htbt_counter=0x%x, htbt_monitor_enable=0x%x, "
469 "sfp_additonal_info=0x%x, sfp_multirate=0x%x.\n ",
470 htbt_counter, htbt_monitor_enable,
471 sfp_additonal_info, sfp_multirate);
472 ql_log(ql_log_warn, vha, 0x5068,
473 "sfp_tx_fault=0x%x, link_state=0x%x, "
474 "dcbx_status=0x%x.\n", sfp_tx_fault, link_speed,
475 dcbx_status);
476
477 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
478 }
479
480 if (mb[1] & IDC_HEARTBEAT_FAILURE) {
481 ql_log(ql_log_warn, vha, 0x5069,
482 "Heartbeat Failure encountered, chip reset "
483 "required.\n");
484
485 qla83xx_schedule_work(vha, QLA83XX_NIC_CORE_RESET);
486 }
487 }
488
489 if (mb[1] & IDC_DEVICE_STATE_CHANGE) {
490 ql_log(ql_log_info, vha, 0x506a,
491 "IDC Device-State changed = 0x%x.\n", mb[4]);
492 qla83xx_schedule_work(vha, MBA_IDC_AEN);
493 }
494}
495
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496/**
497 * qla2x00_async_event() - Process aynchronous events.
498 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700499 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700501void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800502qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 uint16_t handle_cnt;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700505 uint16_t cnt, mbx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 uint32_t handles[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800507 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700508 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700509 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
Andrew Vasquezbc5c2aa2010-12-21 16:00:24 -0800510 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 uint32_t rscn_entry, host_pid;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700512 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
514 /* Setup to process RIO completion. */
515 handle_cnt = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800516 if (IS_CNA_CAPABLE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800517 goto skip_rio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 switch (mb[0]) {
519 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700520 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 handle_cnt = 1;
522 break;
523 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700524 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 handle_cnt = 1;
526 mb[0] = MBA_SCSI_COMPLETION;
527 break;
528 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700529 handles[0] = mb[1];
530 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 handle_cnt = 2;
532 mb[0] = MBA_SCSI_COMPLETION;
533 break;
534 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700535 handles[0] = mb[1];
536 handles[1] = mb[2];
537 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 handle_cnt = 3;
539 mb[0] = MBA_SCSI_COMPLETION;
540 break;
541 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700542 handles[0] = mb[1];
543 handles[1] = mb[2];
544 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
546 handle_cnt = 4;
547 mb[0] = MBA_SCSI_COMPLETION;
548 break;
549 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700550 handles[0] = mb[1];
551 handles[1] = mb[2];
552 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
554 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
555 handle_cnt = 5;
556 mb[0] = MBA_SCSI_COMPLETION;
557 break;
558 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700559 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 handles[1] = le32_to_cpu(
561 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
562 RD_MAILBOX_REG(ha, reg, 6));
563 handle_cnt = 2;
564 mb[0] = MBA_SCSI_COMPLETION;
565 break;
566 default:
567 break;
568 }
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800569skip_rio:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 switch (mb[0]) {
571 case MBA_SCSI_COMPLETION: /* Fast Post */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800572 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 break;
574
575 for (cnt = 0; cnt < handle_cnt; cnt++)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800576 qla2x00_process_completed_request(vha, rsp->req,
577 handles[cnt]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 break;
579
580 case MBA_RESET: /* Reset */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700581 ql_dbg(ql_dbg_async, vha, 0x5002,
582 "Asynchronous RESET.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800584 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 break;
586
587 case MBA_SYSTEM_ERR: /* System Error */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800588 mbx = (IS_QLA81XX(ha) || IS_QLA83XX(ha)) ?
589 RD_REG_WORD(&reg24->mailbox7) : 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700590 ql_log(ql_log_warn, vha, 0x5003,
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700591 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh "
592 "mbx7=%xh.\n", mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800594 ha->isp_ops->fw_dump(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
Andrew Vasqueze4289242007-07-19 15:05:56 -0700596 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700597 if (mb[1] == 0 && mb[2] == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700598 ql_log(ql_log_fatal, vha, 0x5004,
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700599 "Unrecoverable Hardware Error: adapter "
600 "marked OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800601 vha->flags.online = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800602 vha->device_flags |= DFLG_DEV_FAILED;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700603 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300604 /* Check to see if MPI timeout occurred */
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700605 if ((mbx & MBX_3) && (ha->flags.port0))
606 set_bit(MPI_RESET_NEEDED,
607 &vha->dpc_flags);
608
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800609 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700610 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700611 } else if (mb[1] == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700612 ql_log(ql_log_fatal, vha, 0x5005,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 "Unrecoverable Hardware Error: adapter marked "
614 "OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800615 vha->flags.online = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800616 vha->device_flags |= DFLG_DEV_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800618 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 break;
620
621 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700622 ql_log(ql_log_warn, vha, 0x5006,
623 "ISP Request Transfer Error (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800625 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 break;
627
628 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700629 ql_log(ql_log_warn, vha, 0x5007,
630 "ISP Response Transfer Error.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800632 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 break;
634
635 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700636 ql_dbg(ql_dbg_async, vha, 0x5008,
637 "Asynchronous WAKEUP_THRES.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400639 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Chad Dupuiscfb09192011-11-18 09:03:07 -0800641 ql_dbg(ql_dbg_async, vha, 0x5009,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700642 "LIP occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800644 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
645 atomic_set(&vha->loop_state, LOOP_DOWN);
646 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
647 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 }
649
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800650 if (vha->vp_idx) {
651 atomic_set(&vha->vp_state, VP_FAILED);
652 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700653 }
654
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800655 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
656 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800658 vha->flags.management_server_logged_in = 0;
659 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 break;
661
662 case MBA_LOOP_UP: /* Loop Up Event */
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400663 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700664 ha->link_data_rate = PORT_SPEED_1GB;
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400665 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 ha->link_data_rate = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Chad Dupuiscfb09192011-11-18 09:03:07 -0800668 ql_dbg(ql_dbg_async, vha, 0x500a,
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400669 "LOOP UP detected (%s Gbps).\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -0500670 qla2x00_get_link_speed_str(ha, ha->link_data_rate));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800672 vha->flags.management_server_logged_in = 0;
673 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 break;
675
676 case MBA_LOOP_DOWN: /* Loop Down Event */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800677 mbx = (IS_QLA81XX(ha) || IS_QLA8031(ha))
678 ? RD_REG_WORD(&reg24->mailbox4) : 0;
Andrew Vasquezbc5c2aa2010-12-21 16:00:24 -0800679 mbx = IS_QLA82XX(ha) ? RD_REG_WORD(&reg82->mailbox_out[4]) : mbx;
Chad Dupuiscfb09192011-11-18 09:03:07 -0800680 ql_dbg(ql_dbg_async, vha, 0x500b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700681 "LOOP DOWN detected (%x %x %x %x).\n",
682 mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800684 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
685 atomic_set(&vha->loop_state, LOOP_DOWN);
686 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
687 vha->device_flags |= DFLG_NO_CABLE;
688 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 }
690
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800691 if (vha->vp_idx) {
692 atomic_set(&vha->vp_state, VP_FAILED);
693 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700694 }
695
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800696 vha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700697 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800698 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 break;
700
701 case MBA_LIP_RESET: /* LIP reset occurred */
Chad Dupuiscfb09192011-11-18 09:03:07 -0800702 ql_dbg(ql_dbg_async, vha, 0x500c,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700703 "LIP reset occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800705 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
706 atomic_set(&vha->loop_state, LOOP_DOWN);
707 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
708 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 }
710
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800711 if (vha->vp_idx) {
712 atomic_set(&vha->vp_state, VP_FAILED);
713 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700714 }
715
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800716 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
718 ha->operating_mode = LOOP;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800719 vha->flags.management_server_logged_in = 0;
720 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 break;
722
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800723 /* case MBA_DCBX_COMPLETE: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 case MBA_POINT_TO_POINT: /* Point-to-Point */
725 if (IS_QLA2100(ha))
726 break;
727
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800728 if (IS_QLA81XX(ha) || IS_QLA82XX(ha) || IS_QLA8031(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700729 ql_dbg(ql_dbg_async, vha, 0x500d,
730 "DCBX Completed -- %04x %04x %04x.\n",
731 mb[1], mb[2], mb[3]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700732 if (ha->notify_dcbx_comp)
733 complete(&ha->dcbx_comp);
734
735 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700736 ql_dbg(ql_dbg_async, vha, 0x500e,
737 "Asynchronous P2P MODE received.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
739 /*
740 * Until there's a transition from loop down to loop up, treat
741 * this as loop down only.
742 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800743 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
744 atomic_set(&vha->loop_state, LOOP_DOWN);
745 if (!atomic_read(&vha->loop_down_timer))
746 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800748 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 }
750
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800751 if (vha->vp_idx) {
752 atomic_set(&vha->vp_state, VP_FAILED);
753 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700754 }
755
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800756 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
757 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
758
759 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
760 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800761
762 ha->flags.gpsc_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800763 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 break;
765
766 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
767 if (IS_QLA2100(ha))
768 break;
769
Chad Dupuiscfb09192011-11-18 09:03:07 -0800770 ql_dbg(ql_dbg_async, vha, 0x500f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 "Configuration change detected: value=%x.\n", mb[1]);
772
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800773 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
774 atomic_set(&vha->loop_state, LOOP_DOWN);
775 if (!atomic_read(&vha->loop_down_timer))
776 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800778 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 }
780
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800781 if (vha->vp_idx) {
782 atomic_set(&vha->vp_state, VP_FAILED);
783 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700784 }
785
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800786 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
787 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 break;
789
790 case MBA_PORT_UPDATE: /* Port database update */
Santosh Vernekar55903b92009-07-31 15:09:25 -0700791 /*
792 * Handle only global and vn-port update events
793 *
794 * Relevant inputs:
795 * mb[1] = N_Port handle of changed port
796 * OR 0xffff for global event
797 * mb[2] = New login state
798 * 7 = Port logged out
799 * mb[3] = LSB is vp_idx, 0xff = all vps
800 *
801 * Skip processing if:
802 * Event is global, vp_idx is NOT all vps,
803 * vp_idx does not match
804 * Event is not global, vp_idx does not match
805 */
Andrew Vasquez12cec63e42010-03-19 16:59:17 -0700806 if (IS_QLA2XXX_MIDTYPE(ha) &&
807 ((mb[1] == 0xffff && (mb[3] & 0xff) != 0xff) ||
808 (mb[1] != 0xffff)) && vha->vp_idx != (mb[3] & 0xff))
809 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800810
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700811 /* Global event -- port logout or port unavailable. */
812 if (mb[1] == 0xffff && mb[2] == 0x7) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700813 ql_dbg(ql_dbg_async, vha, 0x5010,
814 "Port unavailable %04x %04x %04x.\n",
815 mb[1], mb[2], mb[3]);
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400816 ql_log(ql_log_warn, vha, 0x505e,
817 "Link is offline.\n");
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700818
819 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
820 atomic_set(&vha->loop_state, LOOP_DOWN);
821 atomic_set(&vha->loop_down_timer,
822 LOOP_DOWN_TIME);
823 vha->device_flags |= DFLG_NO_CABLE;
824 qla2x00_mark_all_devices_lost(vha, 1);
825 }
826
827 if (vha->vp_idx) {
828 atomic_set(&vha->vp_state, VP_FAILED);
829 fc_vport_set_state(vha->fc_vport,
830 FC_VPORT_FAILED);
Santosh Vernekarfaadc5e2009-07-31 15:09:26 -0700831 qla2x00_mark_all_devices_lost(vha, 1);
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700832 }
833
834 vha->flags.management_server_logged_in = 0;
835 ha->link_data_rate = PORT_SPEED_UNKNOWN;
836 break;
837 }
838
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 /*
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700840 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 * event etc. earlier indicating loop is down) then process
842 * it. Otherwise ignore it and Wait for RSCN to come in.
843 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800844 atomic_set(&vha->loop_down_timer, 0);
Chad Dupuis79cc7852012-08-22 14:21:09 -0400845 if (mb[1] != 0xffff || (mb[2] != 0x6 && mb[2] != 0x4)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700846 ql_dbg(ql_dbg_async, vha, 0x5011,
847 "Asynchronous PORT UPDATE ignored %04x/%04x/%04x.\n",
848 mb[1], mb[2], mb[3]);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400849
850 qlt_async_event(mb[0], vha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 break;
852 }
853
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700854 ql_dbg(ql_dbg_async, vha, 0x5012,
855 "Port database changed %04x %04x %04x.\n",
856 mb[1], mb[2], mb[3]);
Chad Dupuisdaae62a2012-05-15 14:34:23 -0400857 ql_log(ql_log_warn, vha, 0x505f,
858 "Link is operational (%s Gbps).\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -0500859 qla2x00_get_link_speed_str(ha, ha->link_data_rate));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
861 /*
862 * Mark all devices as missing so we will login again.
863 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800864 atomic_set(&vha->loop_state, LOOP_UP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800866 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400868 if (vha->vp_idx == 0 && !qla_ini_mode_enabled(vha))
869 set_bit(SCR_PENDING, &vha->dpc_flags);
870
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800871 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
872 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400873
874 qlt_async_event(mb[0], vha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 break;
876
877 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju3c397402008-05-19 14:25:39 -0700878 /* Check if the Vport has issued a SCR */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800879 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
Seokmann Ju3c397402008-05-19 14:25:39 -0700880 break;
881 /* Only handle SCNs for our Vport index. */
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700882 if (ha->flags.npiv_supported && vha->vp_idx != (mb[3] & 0xff))
Seokmann Ju3c397402008-05-19 14:25:39 -0700883 break;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700884
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700885 ql_dbg(ql_dbg_async, vha, 0x5013,
886 "RSCN database changed -- %04x %04x %04x.\n",
887 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
Ravi Anand59d72d82008-09-11 21:22:53 -0700889 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800890 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
891 | vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 if (rscn_entry == host_pid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700893 ql_dbg(ql_dbg_async, vha, 0x5014,
894 "Ignoring RSCN update to local host "
895 "port ID (%06x).\n", host_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 break;
897 }
898
Ravi Anand59d72d82008-09-11 21:22:53 -0700899 /* Ignore reserved bits from RSCN-payload. */
900 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800902 atomic_set(&vha->loop_down_timer, 0);
903 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800905 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
906 set_bit(RSCN_UPDATE, &vha->dpc_flags);
907 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 break;
909
910 /* case MBA_RIO_RESPONSE: */
911 case MBA_ZIO_RESPONSE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700912 ql_dbg(ql_dbg_async, vha, 0x5015,
913 "[R|Z]IO update completion.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Andrew Vasqueze4289242007-07-19 15:05:56 -0700915 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700916 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700917 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800918 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700920
921 case MBA_DISCARD_RND_FRAME:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700922 ql_dbg(ql_dbg_async, vha, 0x5016,
923 "Discard RND Frame -- %04x %04x %04x.\n",
924 mb[1], mb[2], mb[3]);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700925 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700926
927 case MBA_TRACE_NOTIFICATION:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700928 ql_dbg(ql_dbg_async, vha, 0x5017,
929 "Trace Notification -- %04x %04x.\n", mb[1], mb[2]);
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700930 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700931
932 case MBA_ISP84XX_ALERT:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700933 ql_dbg(ql_dbg_async, vha, 0x5018,
934 "ISP84XX Alert Notification -- %04x %04x %04x.\n",
935 mb[1], mb[2], mb[3]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700936
937 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
938 switch (mb[1]) {
939 case A84_PANIC_RECOVERY:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700940 ql_log(ql_log_info, vha, 0x5019,
941 "Alert 84XX: panic recovery %04x %04x.\n",
942 mb[2], mb[3]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700943 break;
944 case A84_OP_LOGIN_COMPLETE:
945 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700946 ql_log(ql_log_info, vha, 0x501a,
947 "Alert 84XX: firmware version %x.\n",
948 ha->cs84xx->op_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700949 break;
950 case A84_DIAG_LOGIN_COMPLETE:
951 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700952 ql_log(ql_log_info, vha, 0x501b,
953 "Alert 84XX: diagnostic firmware version %x.\n",
954 ha->cs84xx->diag_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700955 break;
956 case A84_GOLD_LOGIN_COMPLETE:
957 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
958 ha->cs84xx->fw_update = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700959 ql_log(ql_log_info, vha, 0x501c,
960 "Alert 84XX: gold firmware version %x.\n",
961 ha->cs84xx->gold_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700962 break;
963 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700964 ql_log(ql_log_warn, vha, 0x501d,
965 "Alert 84xx: Invalid Alert %04x %04x %04x.\n",
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700966 mb[1], mb[2], mb[3]);
967 }
968 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
969 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800970 case MBA_DCBX_START:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700971 ql_dbg(ql_dbg_async, vha, 0x501e,
972 "DCBX Started -- %04x %04x %04x.\n",
973 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800974 break;
975 case MBA_DCBX_PARAM_UPDATE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700976 ql_dbg(ql_dbg_async, vha, 0x501f,
977 "DCBX Parameters Updated -- %04x %04x %04x.\n",
978 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800979 break;
980 case MBA_FCF_CONF_ERR:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700981 ql_dbg(ql_dbg_async, vha, 0x5020,
982 "FCF Configuration Error -- %04x %04x %04x.\n",
983 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800984 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800985 case MBA_IDC_NOTIFY:
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400986 /* See if we need to quiesce any I/O */
987 if (IS_QLA8031(vha->hw))
988 if ((mb[2] & 0x7fff) == MBC_PORT_RESET ||
989 (mb[2] & 0x7fff) == MBC_SET_PORT_CONFIG) {
990 set_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400991 qla2xxx_wake_dpc(vha);
992 }
993 case MBA_IDC_COMPLETE:
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800994 case MBA_IDC_TIME_EXT:
Chad Dupuisbf5b8ad2012-08-22 14:21:24 -0400995 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400996 qla81xx_idc_event(vha, mb[0], mb[1]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800997 break;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400998
999 case MBA_IDC_AEN:
1000 mb[4] = RD_REG_WORD(&reg24->mailbox4);
1001 mb[5] = RD_REG_WORD(&reg24->mailbox5);
1002 mb[6] = RD_REG_WORD(&reg24->mailbox6);
1003 mb[7] = RD_REG_WORD(&reg24->mailbox7);
1004 qla83xx_handle_8200_aen(vha, mb);
1005 break;
1006
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001007 default:
1008 ql_dbg(ql_dbg_async, vha, 0x5057,
1009 "Unknown AEN:%04x %04x %04x %04x\n",
1010 mb[0], mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001012
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001013 qlt_async_event(mb[0], vha, mb);
1014
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001015 if (!vha->vp_idx && ha->num_vhosts)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001016 qla2x00_alert_all_vps(rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017}
1018
1019/**
1020 * qla2x00_process_completed_request() - Process a Fast Post response.
1021 * @ha: SCSI driver HA context
1022 * @index: SRB index
1023 */
1024static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001025qla2x00_process_completed_request(struct scsi_qla_host *vha,
1026 struct req_que *req, uint32_t index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027{
1028 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001029 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030
1031 /* Validate handle. */
1032 if (index >= MAX_OUTSTANDING_COMMANDS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001033 ql_log(ql_log_warn, vha, 0x3014,
1034 "Invalid SCSI command index (%x).\n", index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001036 if (IS_QLA82XX(ha))
1037 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1038 else
1039 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 return;
1041 }
1042
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001043 sp = req->outstanding_cmds[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 if (sp) {
1045 /* Free outstanding command slot. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001046 req->outstanding_cmds[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 /* Save ISP completion status */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001049 sp->done(ha, sp, DID_OK << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001051 ql_log(ql_log_warn, vha, 0x3016, "Invalid SCSI SRB.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001053 if (IS_QLA82XX(ha))
1054 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1055 else
1056 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 }
1058}
1059
Andrew Vasquezac280b62009-08-20 11:06:05 -07001060static srb_t *
1061qla2x00_get_sp_from_handle(scsi_qla_host_t *vha, const char *func,
1062 struct req_que *req, void *iocb)
1063{
1064 struct qla_hw_data *ha = vha->hw;
1065 sts_entry_t *pkt = iocb;
1066 srb_t *sp = NULL;
1067 uint16_t index;
1068
1069 index = LSW(pkt->handle);
1070 if (index >= MAX_OUTSTANDING_COMMANDS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001071 ql_log(ql_log_warn, vha, 0x5031,
1072 "Invalid command index (%x).\n", index);
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001073 if (IS_QLA82XX(ha))
1074 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1075 else
1076 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001077 goto done;
1078 }
1079 sp = req->outstanding_cmds[index];
1080 if (!sp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001081 ql_log(ql_log_warn, vha, 0x5032,
1082 "Invalid completion handle (%x) -- timed-out.\n", index);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001083 return sp;
1084 }
1085 if (sp->handle != index) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001086 ql_log(ql_log_warn, vha, 0x5033,
1087 "SRB handle (%x) mismatch %x.\n", sp->handle, index);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001088 return NULL;
1089 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001090
Andrew Vasquezac280b62009-08-20 11:06:05 -07001091 req->outstanding_cmds[index] = NULL;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001092
Andrew Vasquezac280b62009-08-20 11:06:05 -07001093done:
1094 return sp;
1095}
1096
1097static void
1098qla2x00_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1099 struct mbx_entry *mbx)
1100{
1101 const char func[] = "MBX-IOCB";
1102 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001103 fc_port_t *fcport;
1104 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001105 struct srb_iocb *lio;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001106 uint16_t *data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001107 uint16_t status;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001108
1109 sp = qla2x00_get_sp_from_handle(vha, func, req, mbx);
1110 if (!sp)
1111 return;
1112
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001113 lio = &sp->u.iocb_cmd;
1114 type = sp->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001115 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001116 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001117
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001118 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001119 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001120 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001121 if (mbx->entry_status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001122 ql_dbg(ql_dbg_async, vha, 0x5043,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001123 "Async-%s error entry - hdl=%x portid=%02x%02x%02x "
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001124 "entry-status=%x status=%x state-flag=%x "
Chad Dupuiscfb09192011-11-18 09:03:07 -08001125 "status-flags=%x.\n", type, sp->handle,
1126 fcport->d_id.b.domain, fcport->d_id.b.area,
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001127 fcport->d_id.b.al_pa, mbx->entry_status,
1128 le16_to_cpu(mbx->status), le16_to_cpu(mbx->state_flags),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001129 le16_to_cpu(mbx->status_flags));
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001130
Chad Dupuiscfb09192011-11-18 09:03:07 -08001131 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5029,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001132 (uint8_t *)mbx, sizeof(*mbx));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001133
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001134 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001135 }
1136
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001137 status = le16_to_cpu(mbx->status);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001138 if (status == 0x30 && sp->type == SRB_LOGIN_CMD &&
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001139 le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE)
1140 status = 0;
1141 if (!status && le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001142 ql_dbg(ql_dbg_async, vha, 0x5045,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001143 "Async-%s complete - hdl=%x portid=%02x%02x%02x mbx1=%x.\n",
1144 type, sp->handle, fcport->d_id.b.domain,
1145 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1146 le16_to_cpu(mbx->mb1));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001147
1148 data[0] = MBS_COMMAND_COMPLETE;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001149 if (sp->type == SRB_LOGIN_CMD) {
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001150 fcport->port_type = FCT_TARGET;
1151 if (le16_to_cpu(mbx->mb1) & BIT_0)
1152 fcport->port_type = FCT_INITIATOR;
Andrew Vasquez6ac52602010-05-28 15:08:19 -07001153 else if (le16_to_cpu(mbx->mb1) & BIT_1)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001154 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001155 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001156 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001157 }
1158
1159 data[0] = le16_to_cpu(mbx->mb0);
1160 switch (data[0]) {
1161 case MBS_PORT_ID_USED:
1162 data[1] = le16_to_cpu(mbx->mb1);
1163 break;
1164 case MBS_LOOP_ID_USED:
1165 break;
1166 default:
1167 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001168 break;
1169 }
1170
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001171 ql_log(ql_log_warn, vha, 0x5046,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001172 "Async-%s failed - hdl=%x portid=%02x%02x%02x status=%x "
1173 "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n", type, sp->handle,
1174 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
1175 status, le16_to_cpu(mbx->mb0), le16_to_cpu(mbx->mb1),
Andrew Vasquezac280b62009-08-20 11:06:05 -07001176 le16_to_cpu(mbx->mb2), le16_to_cpu(mbx->mb6),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001177 le16_to_cpu(mbx->mb7));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001178
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001179logio_done:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001180 sp->done(vha, sp, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001181}
1182
1183static void
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001184qla2x00_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1185 sts_entry_t *pkt, int iocb_type)
1186{
1187 const char func[] = "CT_IOCB";
1188 const char *type;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001189 srb_t *sp;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001190 struct fc_bsg_job *bsg_job;
1191 uint16_t comp_status;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001192 int res;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001193
1194 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1195 if (!sp)
1196 return;
1197
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001198 bsg_job = sp->u.bsg_job;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001199
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001200 type = "ct pass-through";
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001201
1202 comp_status = le16_to_cpu(pkt->comp_status);
1203
1204 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1205 * fc payload to the caller
1206 */
1207 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1208 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1209
1210 if (comp_status != CS_COMPLETE) {
1211 if (comp_status == CS_DATA_UNDERRUN) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001212 res = DID_OK << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001213 bsg_job->reply->reply_payload_rcv_len =
1214 le16_to_cpu(((sts_entry_t *)pkt)->rsp_info_len);
1215
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001216 ql_log(ql_log_warn, vha, 0x5048,
1217 "CT pass-through-%s error "
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001218 "comp_status-status=0x%x total_byte = 0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001219 type, comp_status,
1220 bsg_job->reply->reply_payload_rcv_len);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001221 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001222 ql_log(ql_log_warn, vha, 0x5049,
1223 "CT pass-through-%s error "
1224 "comp_status-status=0x%x.\n", type, comp_status);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001225 res = DID_ERROR << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001226 bsg_job->reply->reply_payload_rcv_len = 0;
1227 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001228 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5035,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001229 (uint8_t *)pkt, sizeof(*pkt));
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001230 } else {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001231 res = DID_OK << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001232 bsg_job->reply->reply_payload_rcv_len =
1233 bsg_job->reply_payload.payload_len;
1234 bsg_job->reply_len = 0;
1235 }
1236
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001237 sp->done(vha, sp, res);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001238}
1239
1240static void
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001241qla24xx_els_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1242 struct sts_entry_24xx *pkt, int iocb_type)
1243{
1244 const char func[] = "ELS_CT_IOCB";
1245 const char *type;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001246 srb_t *sp;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001247 struct fc_bsg_job *bsg_job;
1248 uint16_t comp_status;
1249 uint32_t fw_status[3];
1250 uint8_t* fw_sts_ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001251 int res;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001252
1253 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1254 if (!sp)
1255 return;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001256 bsg_job = sp->u.bsg_job;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001257
1258 type = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001259 switch (sp->type) {
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001260 case SRB_ELS_CMD_RPT:
1261 case SRB_ELS_CMD_HST:
1262 type = "els";
1263 break;
1264 case SRB_CT_CMD:
1265 type = "ct pass-through";
1266 break;
1267 default:
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001268 ql_dbg(ql_dbg_user, vha, 0x503e,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001269 "Unrecognized SRB: (%p) type=%d.\n", sp, sp->type);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001270 return;
1271 }
1272
1273 comp_status = fw_status[0] = le16_to_cpu(pkt->comp_status);
1274 fw_status[1] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1);
1275 fw_status[2] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2);
1276
1277 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1278 * fc payload to the caller
1279 */
1280 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1281 bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(fw_status);
1282
1283 if (comp_status != CS_COMPLETE) {
1284 if (comp_status == CS_DATA_UNDERRUN) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001285 res = DID_OK << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001286 bsg_job->reply->reply_payload_rcv_len =
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001287 le16_to_cpu(((struct els_sts_entry_24xx *)pkt)->total_byte_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001288
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001289 ql_dbg(ql_dbg_user, vha, 0x503f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001290 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001291 "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001292 type, sp->handle, comp_status, fw_status[1], fw_status[2],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001293 le16_to_cpu(((struct els_sts_entry_24xx *)
1294 pkt)->total_byte_count));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001295 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1296 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1297 }
1298 else {
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001299 ql_dbg(ql_dbg_user, vha, 0x5040,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001300 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001301 "error subcode 1=0x%x error subcode 2=0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001302 type, sp->handle, comp_status,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001303 le16_to_cpu(((struct els_sts_entry_24xx *)
1304 pkt)->error_subcode_1),
1305 le16_to_cpu(((struct els_sts_entry_24xx *)
1306 pkt)->error_subcode_2));
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001307 res = DID_ERROR << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001308 bsg_job->reply->reply_payload_rcv_len = 0;
1309 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1310 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1311 }
Andrew Vasquez37fed3e2012-02-09 11:15:37 -08001312 ql_dump_buffer(ql_dbg_user + ql_dbg_buffer, vha, 0x5056,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001313 (uint8_t *)pkt, sizeof(*pkt));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001314 }
1315 else {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001316 res = DID_OK << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001317 bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
1318 bsg_job->reply_len = 0;
1319 }
1320
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001321 sp->done(vha, sp, res);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001322}
1323
1324static void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001325qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req,
1326 struct logio_entry_24xx *logio)
1327{
1328 const char func[] = "LOGIO-IOCB";
1329 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001330 fc_port_t *fcport;
1331 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001332 struct srb_iocb *lio;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001333 uint16_t *data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001334 uint32_t iop[2];
1335
1336 sp = qla2x00_get_sp_from_handle(vha, func, req, logio);
1337 if (!sp)
1338 return;
1339
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001340 lio = &sp->u.iocb_cmd;
1341 type = sp->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001342 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001343 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001344
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001345 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001346 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001347 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001348 if (logio->entry_status) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001349 ql_log(ql_log_warn, fcport->vha, 0x5034,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001350 "Async-%s error entry - hdl=%x"
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001351 "portid=%02x%02x%02x entry-status=%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001352 type, sp->handle, fcport->d_id.b.domain,
1353 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1354 logio->entry_status);
1355 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x504d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001356 (uint8_t *)logio, sizeof(*logio));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001357
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001358 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001359 }
1360
1361 if (le16_to_cpu(logio->comp_status) == CS_COMPLETE) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001362 ql_dbg(ql_dbg_async, fcport->vha, 0x5036,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001363 "Async-%s complete - hdl=%x portid=%02x%02x%02x "
1364 "iop0=%x.\n", type, sp->handle, fcport->d_id.b.domain,
1365 fcport->d_id.b.area, fcport->d_id.b.al_pa,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001366 le32_to_cpu(logio->io_parameter[0]));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001367
1368 data[0] = MBS_COMMAND_COMPLETE;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001369 if (sp->type != SRB_LOGIN_CMD)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001370 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001371
1372 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1373 if (iop[0] & BIT_4) {
1374 fcport->port_type = FCT_TARGET;
1375 if (iop[0] & BIT_8)
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07001376 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquezb0cd5792010-05-28 15:08:22 -07001377 } else if (iop[0] & BIT_5)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001378 fcport->port_type = FCT_INITIATOR;
Andrew Vasquezb0cd5792010-05-28 15:08:22 -07001379
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001380 if (iop[0] & BIT_7)
1381 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
1382
Andrew Vasquezac280b62009-08-20 11:06:05 -07001383 if (logio->io_parameter[7] || logio->io_parameter[8])
1384 fcport->supported_classes |= FC_COS_CLASS2;
1385 if (logio->io_parameter[9] || logio->io_parameter[10])
1386 fcport->supported_classes |= FC_COS_CLASS3;
1387
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001388 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001389 }
1390
1391 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1392 iop[1] = le32_to_cpu(logio->io_parameter[1]);
1393 switch (iop[0]) {
1394 case LSC_SCODE_PORTID_USED:
1395 data[0] = MBS_PORT_ID_USED;
1396 data[1] = LSW(iop[1]);
1397 break;
1398 case LSC_SCODE_NPORT_USED:
1399 data[0] = MBS_LOOP_ID_USED;
1400 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001401 default:
1402 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001403 break;
1404 }
1405
Arun Easi5e19ed92012-02-09 11:15:51 -08001406 ql_dbg(ql_dbg_async, fcport->vha, 0x5037,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001407 "Async-%s failed - hdl=%x portid=%02x%02x%02x comp=%x "
1408 "iop0=%x iop1=%x.\n", type, sp->handle, fcport->d_id.b.domain,
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001409 fcport->d_id.b.area, fcport->d_id.b.al_pa,
Andrew Vasquezac280b62009-08-20 11:06:05 -07001410 le16_to_cpu(logio->comp_status),
1411 le32_to_cpu(logio->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001412 le32_to_cpu(logio->io_parameter[1]));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001413
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001414logio_done:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001415 sp->done(vha, sp, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001416}
1417
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001418static void
1419qla24xx_tm_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1420 struct tsk_mgmt_entry *tsk)
1421{
1422 const char func[] = "TMF-IOCB";
1423 const char *type;
1424 fc_port_t *fcport;
1425 srb_t *sp;
1426 struct srb_iocb *iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001427 struct sts_entry_24xx *sts = (struct sts_entry_24xx *)tsk;
1428 int error = 1;
1429
1430 sp = qla2x00_get_sp_from_handle(vha, func, req, tsk);
1431 if (!sp)
1432 return;
1433
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001434 iocb = &sp->u.iocb_cmd;
1435 type = sp->name;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001436 fcport = sp->fcport;
1437
1438 if (sts->entry_status) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001439 ql_log(ql_log_warn, fcport->vha, 0x5038,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001440 "Async-%s error - hdl=%x entry-status(%x).\n",
1441 type, sp->handle, sts->entry_status);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001442 } else if (sts->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001443 ql_log(ql_log_warn, fcport->vha, 0x5039,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001444 "Async-%s error - hdl=%x completion status(%x).\n",
1445 type, sp->handle, sts->comp_status);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001446 } else if (!(le16_to_cpu(sts->scsi_status) &
1447 SS_RESPONSE_INFO_LEN_VALID)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001448 ql_log(ql_log_warn, fcport->vha, 0x503a,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001449 "Async-%s error - hdl=%x no response info(%x).\n",
1450 type, sp->handle, sts->scsi_status);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001451 } else if (le32_to_cpu(sts->rsp_data_len) < 4) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001452 ql_log(ql_log_warn, fcport->vha, 0x503b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001453 "Async-%s error - hdl=%x not enough response(%d).\n",
1454 type, sp->handle, sts->rsp_data_len);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001455 } else if (sts->data[3]) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001456 ql_log(ql_log_warn, fcport->vha, 0x503c,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001457 "Async-%s error - hdl=%x response(%x).\n",
1458 type, sp->handle, sts->data[3]);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001459 } else {
1460 error = 0;
1461 }
1462
1463 if (error) {
1464 iocb->u.tmf.data = error;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001465 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5055,
1466 (uint8_t *)sts, sizeof(*sts));
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001467 }
1468
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001469 sp->done(vha, sp, 0);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001470}
1471
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472/**
1473 * qla2x00_process_response_queue() - Process response queue entries.
1474 * @ha: SCSI driver HA context
1475 */
1476void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001477qla2x00_process_response_queue(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001479 struct scsi_qla_host *vha;
1480 struct qla_hw_data *ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001481 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 sts_entry_t *pkt;
1483 uint16_t handle_cnt;
1484 uint16_t cnt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001485
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001486 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001488 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 return;
1490
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001491 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1492 pkt = (sts_entry_t *)rsp->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001494 rsp->ring_index++;
1495 if (rsp->ring_index == rsp->length) {
1496 rsp->ring_index = 0;
1497 rsp->ring_ptr = rsp->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001499 rsp->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 }
1501
1502 if (pkt->entry_status != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001503 qla2x00_error_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1505 wmb();
1506 continue;
1507 }
1508
1509 switch (pkt->entry_type) {
1510 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001511 qla2x00_status_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 break;
1513 case STATUS_TYPE_21:
1514 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
1515 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001516 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 ((sts21_entry_t *)pkt)->handle[cnt]);
1518 }
1519 break;
1520 case STATUS_TYPE_22:
1521 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
1522 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001523 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 ((sts22_entry_t *)pkt)->handle[cnt]);
1525 }
1526 break;
1527 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001528 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001530 case MBX_IOCB_TYPE:
1531 qla2x00_mbx_iocb_entry(vha, rsp->req,
1532 (struct mbx_entry *)pkt);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001533 break;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001534 case CT_IOCB_TYPE:
1535 qla2x00_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
1536 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 default:
1538 /* Type Not Supported. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001539 ql_log(ql_log_warn, vha, 0x504a,
1540 "Received unknown response pkt type %x "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 "entry status=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001542 pkt->entry_type, pkt->entry_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 break;
1544 }
1545 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1546 wmb();
1547 }
1548
1549 /* Adjust ring index */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001550 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551}
1552
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001553static inline void
Andrew Vasquez55442132010-07-23 15:28:27 +05001554qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t par_sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001555 uint32_t sense_len, struct rsp_que *rsp, int res)
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001556{
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001557 struct scsi_qla_host *vha = sp->fcport->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001558 struct scsi_cmnd *cp = GET_CMD_SP(sp);
1559 uint32_t track_sense_len;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001560
1561 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
1562 sense_len = SCSI_SENSE_BUFFERSIZE;
1563
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001564 SET_CMD_SENSE_LEN(sp, sense_len);
1565 SET_CMD_SENSE_PTR(sp, cp->sense_buffer);
1566 track_sense_len = sense_len;
1567
1568 if (sense_len > par_sense_len)
Andrew Vasquez55442132010-07-23 15:28:27 +05001569 sense_len = par_sense_len;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001570
1571 memcpy(cp->sense_buffer, sense_data, sense_len);
1572
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001573 SET_CMD_SENSE_PTR(sp, cp->sense_buffer + sense_len);
1574 track_sense_len -= sense_len;
1575 SET_CMD_SENSE_LEN(sp, track_sense_len);
1576
1577 if (track_sense_len != 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001578 rsp->status_srb = sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001579 cp->result = res;
1580 }
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001581
Chad Dupuiscfb09192011-11-18 09:03:07 -08001582 if (sense_len) {
1583 ql_dbg(ql_dbg_io + ql_dbg_buffer, vha, 0x301c,
1584 "Check condition Sense data, nexus%ld:%d:%d cmd=%p.\n",
1585 sp->fcport->vha->host_no, cp->device->id, cp->device->lun,
1586 cp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001587 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302b,
1588 cp->sense_buffer, sense_len);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001589 }
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001590}
1591
Arun Easibad75002010-05-04 15:01:30 -07001592struct scsi_dif_tuple {
1593 __be16 guard; /* Checksum */
Masanari Iidad6a03582012-08-22 14:20:58 -04001594 __be16 app_tag; /* APPL identifier */
Arun Easibad75002010-05-04 15:01:30 -07001595 __be32 ref_tag; /* Target LBA or indirect LBA */
1596};
1597
1598/*
1599 * Checks the guard or meta-data for the type of error
1600 * detected by the HBA. In case of errors, we set the
1601 * ASC/ASCQ fields in the sense buffer with ILLEGAL_REQUEST
1602 * to indicate to the kernel that the HBA detected error.
1603 */
Arun Easi8cb20492011-08-16 11:29:22 -07001604static inline int
Arun Easibad75002010-05-04 15:01:30 -07001605qla2x00_handle_dif_error(srb_t *sp, struct sts_entry_24xx *sts24)
1606{
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001607 struct scsi_qla_host *vha = sp->fcport->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001608 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Arun Easi8cb20492011-08-16 11:29:22 -07001609 uint8_t *ap = &sts24->data[12];
1610 uint8_t *ep = &sts24->data[20];
Arun Easibad75002010-05-04 15:01:30 -07001611 uint32_t e_ref_tag, a_ref_tag;
1612 uint16_t e_app_tag, a_app_tag;
1613 uint16_t e_guard, a_guard;
1614
Arun Easi8cb20492011-08-16 11:29:22 -07001615 /*
1616 * swab32 of the "data" field in the beginning of qla2x00_status_entry()
1617 * would make guard field appear at offset 2
1618 */
1619 a_guard = le16_to_cpu(*(uint16_t *)(ap + 2));
1620 a_app_tag = le16_to_cpu(*(uint16_t *)(ap + 0));
1621 a_ref_tag = le32_to_cpu(*(uint32_t *)(ap + 4));
1622 e_guard = le16_to_cpu(*(uint16_t *)(ep + 2));
1623 e_app_tag = le16_to_cpu(*(uint16_t *)(ep + 0));
1624 e_ref_tag = le32_to_cpu(*(uint32_t *)(ep + 4));
Arun Easibad75002010-05-04 15:01:30 -07001625
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001626 ql_dbg(ql_dbg_io, vha, 0x3023,
1627 "iocb(s) %p Returned STATUS.\n", sts24);
Arun Easibad75002010-05-04 15:01:30 -07001628
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001629 ql_dbg(ql_dbg_io, vha, 0x3024,
1630 "DIF ERROR in cmd 0x%x lba 0x%llx act ref"
Arun Easibad75002010-05-04 15:01:30 -07001631 " tag=0x%x, exp ref_tag=0x%x, act app tag=0x%x, exp app"
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001632 " tag=0x%x, act guard=0x%x, exp guard=0x%x.\n",
Arun Easibad75002010-05-04 15:01:30 -07001633 cmd->cmnd[0], (u64)scsi_get_lba(cmd), a_ref_tag, e_ref_tag,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001634 a_app_tag, e_app_tag, a_guard, e_guard);
Arun Easibad75002010-05-04 15:01:30 -07001635
Arun Easi8cb20492011-08-16 11:29:22 -07001636 /*
1637 * Ignore sector if:
1638 * For type 3: ref & app tag is all 'f's
1639 * For type 0,1,2: app tag is all 'f's
1640 */
1641 if ((a_app_tag == 0xffff) &&
1642 ((scsi_get_prot_type(cmd) != SCSI_PROT_DIF_TYPE3) ||
1643 (a_ref_tag == 0xffffffff))) {
1644 uint32_t blocks_done, resid;
1645 sector_t lba_s = scsi_get_lba(cmd);
1646
1647 /* 2TB boundary case covered automatically with this */
1648 blocks_done = e_ref_tag - (uint32_t)lba_s + 1;
1649
1650 resid = scsi_bufflen(cmd) - (blocks_done *
1651 cmd->device->sector_size);
1652
1653 scsi_set_resid(cmd, resid);
1654 cmd->result = DID_OK << 16;
1655
1656 /* Update protection tag */
1657 if (scsi_prot_sg_count(cmd)) {
1658 uint32_t i, j = 0, k = 0, num_ent;
1659 struct scatterlist *sg;
1660 struct sd_dif_tuple *spt;
1661
1662 /* Patch the corresponding protection tags */
1663 scsi_for_each_prot_sg(cmd, sg,
1664 scsi_prot_sg_count(cmd), i) {
1665 num_ent = sg_dma_len(sg) / 8;
1666 if (k + num_ent < blocks_done) {
1667 k += num_ent;
1668 continue;
1669 }
1670 j = blocks_done - k - 1;
1671 k = blocks_done;
1672 break;
1673 }
1674
1675 if (k != blocks_done) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001676 ql_log(ql_log_warn, vha, 0x302f,
Randy Dunlap8ec9c7f2011-09-23 15:40:50 -07001677 "unexpected tag values tag:lba=%x:%llx)\n",
1678 e_ref_tag, (unsigned long long)lba_s);
Arun Easi8cb20492011-08-16 11:29:22 -07001679 return 1;
1680 }
1681
1682 spt = page_address(sg_page(sg)) + sg->offset;
1683 spt += j;
1684
1685 spt->app_tag = 0xffff;
1686 if (scsi_get_prot_type(cmd) == SCSI_PROT_DIF_TYPE3)
1687 spt->ref_tag = 0xffffffff;
1688 }
1689
1690 return 0;
1691 }
1692
Arun Easibad75002010-05-04 15:01:30 -07001693 /* check guard */
1694 if (e_guard != a_guard) {
1695 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1696 0x10, 0x1);
1697 set_driver_byte(cmd, DRIVER_SENSE);
1698 set_host_byte(cmd, DID_ABORT);
1699 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
Arun Easi8cb20492011-08-16 11:29:22 -07001700 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001701 }
1702
Arun Easie02587d2011-08-16 11:29:23 -07001703 /* check ref tag */
1704 if (e_ref_tag != a_ref_tag) {
1705 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1706 0x10, 0x3);
1707 set_driver_byte(cmd, DRIVER_SENSE);
1708 set_host_byte(cmd, DID_ABORT);
1709 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
1710 return 1;
1711 }
1712
Arun Easibad75002010-05-04 15:01:30 -07001713 /* check appl tag */
1714 if (e_app_tag != a_app_tag) {
1715 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1716 0x10, 0x2);
1717 set_driver_byte(cmd, DRIVER_SENSE);
1718 set_host_byte(cmd, DID_ABORT);
1719 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
Arun Easi8cb20492011-08-16 11:29:22 -07001720 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001721 }
1722
Arun Easi8cb20492011-08-16 11:29:22 -07001723 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001724}
1725
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001726static void
1727qla25xx_process_bidir_status_iocb(scsi_qla_host_t *vha, void *pkt,
1728 struct req_que *req, uint32_t index)
1729{
1730 struct qla_hw_data *ha = vha->hw;
1731 srb_t *sp;
1732 uint16_t comp_status;
1733 uint16_t scsi_status;
1734 uint16_t thread_id;
1735 uint32_t rval = EXT_STATUS_OK;
1736 struct fc_bsg_job *bsg_job = NULL;
1737 sts_entry_t *sts;
1738 struct sts_entry_24xx *sts24;
1739 sts = (sts_entry_t *) pkt;
1740 sts24 = (struct sts_entry_24xx *) pkt;
1741
1742 /* Validate handle. */
1743 if (index >= MAX_OUTSTANDING_COMMANDS) {
1744 ql_log(ql_log_warn, vha, 0x70af,
1745 "Invalid SCSI completion handle 0x%x.\n", index);
1746 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1747 return;
1748 }
1749
1750 sp = req->outstanding_cmds[index];
1751 if (sp) {
1752 /* Free outstanding command slot. */
1753 req->outstanding_cmds[index] = NULL;
1754 bsg_job = sp->u.bsg_job;
1755 } else {
1756 ql_log(ql_log_warn, vha, 0x70b0,
1757 "Req:%d: Invalid ISP SCSI completion handle(0x%x)\n",
1758 req->id, index);
1759
1760 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1761 return;
1762 }
1763
1764 if (IS_FWI2_CAPABLE(ha)) {
1765 comp_status = le16_to_cpu(sts24->comp_status);
1766 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
1767 } else {
1768 comp_status = le16_to_cpu(sts->comp_status);
1769 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1770 }
1771
1772 thread_id = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1773 switch (comp_status) {
1774 case CS_COMPLETE:
1775 if (scsi_status == 0) {
1776 bsg_job->reply->reply_payload_rcv_len =
1777 bsg_job->reply_payload.payload_len;
1778 rval = EXT_STATUS_OK;
1779 }
1780 goto done;
1781
1782 case CS_DATA_OVERRUN:
1783 ql_dbg(ql_dbg_user, vha, 0x70b1,
1784 "Command completed with date overrun thread_id=%d\n",
1785 thread_id);
1786 rval = EXT_STATUS_DATA_OVERRUN;
1787 break;
1788
1789 case CS_DATA_UNDERRUN:
1790 ql_dbg(ql_dbg_user, vha, 0x70b2,
1791 "Command completed with date underrun thread_id=%d\n",
1792 thread_id);
1793 rval = EXT_STATUS_DATA_UNDERRUN;
1794 break;
1795 case CS_BIDIR_RD_OVERRUN:
1796 ql_dbg(ql_dbg_user, vha, 0x70b3,
1797 "Command completed with read data overrun thread_id=%d\n",
1798 thread_id);
1799 rval = EXT_STATUS_DATA_OVERRUN;
1800 break;
1801
1802 case CS_BIDIR_RD_WR_OVERRUN:
1803 ql_dbg(ql_dbg_user, vha, 0x70b4,
1804 "Command completed with read and write data overrun "
1805 "thread_id=%d\n", thread_id);
1806 rval = EXT_STATUS_DATA_OVERRUN;
1807 break;
1808
1809 case CS_BIDIR_RD_OVERRUN_WR_UNDERRUN:
1810 ql_dbg(ql_dbg_user, vha, 0x70b5,
1811 "Command completed with read data over and write data "
1812 "underrun thread_id=%d\n", thread_id);
1813 rval = EXT_STATUS_DATA_OVERRUN;
1814 break;
1815
1816 case CS_BIDIR_RD_UNDERRUN:
1817 ql_dbg(ql_dbg_user, vha, 0x70b6,
1818 "Command completed with read data data underrun "
1819 "thread_id=%d\n", thread_id);
1820 rval = EXT_STATUS_DATA_UNDERRUN;
1821 break;
1822
1823 case CS_BIDIR_RD_UNDERRUN_WR_OVERRUN:
1824 ql_dbg(ql_dbg_user, vha, 0x70b7,
1825 "Command completed with read data under and write data "
1826 "overrun thread_id=%d\n", thread_id);
1827 rval = EXT_STATUS_DATA_UNDERRUN;
1828 break;
1829
1830 case CS_BIDIR_RD_WR_UNDERRUN:
1831 ql_dbg(ql_dbg_user, vha, 0x70b8,
1832 "Command completed with read and write data underrun "
1833 "thread_id=%d\n", thread_id);
1834 rval = EXT_STATUS_DATA_UNDERRUN;
1835 break;
1836
1837 case CS_BIDIR_DMA:
1838 ql_dbg(ql_dbg_user, vha, 0x70b9,
1839 "Command completed with data DMA error thread_id=%d\n",
1840 thread_id);
1841 rval = EXT_STATUS_DMA_ERR;
1842 break;
1843
1844 case CS_TIMEOUT:
1845 ql_dbg(ql_dbg_user, vha, 0x70ba,
1846 "Command completed with timeout thread_id=%d\n",
1847 thread_id);
1848 rval = EXT_STATUS_TIMEOUT;
1849 break;
1850 default:
1851 ql_dbg(ql_dbg_user, vha, 0x70bb,
1852 "Command completed with completion status=0x%x "
1853 "thread_id=%d\n", comp_status, thread_id);
1854 rval = EXT_STATUS_ERR;
1855 break;
1856 }
1857 bsg_job->reply->reply_payload_rcv_len = 0;
1858
1859done:
1860 /* Return the vendor specific reply to API */
1861 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
1862 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1863 /* Always return DID_OK, bsg will send the vendor specific response
1864 * in this case only */
1865 sp->done(vha, sp, (DID_OK << 6));
1866
1867}
1868
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869/**
1870 * qla2x00_status_entry() - Process a Status IOCB entry.
1871 * @ha: SCSI driver HA context
1872 * @pkt: Entry pointer
1873 */
1874static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001875qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 fc_port_t *fcport;
1879 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001880 sts_entry_t *sts;
1881 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 uint16_t comp_status;
1883 uint16_t scsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001884 uint16_t ox_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 uint8_t lscsi_status;
1886 int32_t resid;
Andrew Vasquez55442132010-07-23 15:28:27 +05001887 uint32_t sense_len, par_sense_len, rsp_info_len, resid_len,
1888 fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001889 uint8_t *rsp_info, *sense_data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001890 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001891 uint32_t handle;
1892 uint16_t que;
1893 struct req_que *req;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001894 int logit = 1;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001895 int res = 0;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001896 uint16_t state_flags = 0;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001897
1898 sts = (sts_entry_t *) pkt;
1899 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001900 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001901 comp_status = le16_to_cpu(sts24->comp_status);
1902 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001903 state_flags = le16_to_cpu(sts24->state_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001904 } else {
1905 comp_status = le16_to_cpu(sts->comp_status);
1906 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1907 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001908 handle = (uint32_t) LSW(sts->handle);
1909 que = MSW(sts->handle);
1910 req = ha->req_q_map[que];
Giridhar Malavalia9083012010-04-12 17:59:55 -07001911
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 /* Validate handle. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001913 if (handle < MAX_OUTSTANDING_COMMANDS) {
1914 sp = req->outstanding_cmds[handle];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 } else
1916 sp = NULL;
1917
1918 if (sp == NULL) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001919 ql_dbg(ql_dbg_io, vha, 0x3017,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001920 "Invalid status handle (0x%x).\n", sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001922 if (IS_QLA82XX(ha))
1923 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1924 else
1925 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001926 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 return;
1928 }
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001929
1930 if (unlikely((state_flags & BIT_1) && (sp->type == SRB_BIDI_CMD))) {
1931 qla25xx_process_bidir_status_iocb(vha, pkt, req, handle);
1932 return;
1933 }
1934
1935 /* Fast path completion. */
1936 if (comp_status == CS_COMPLETE && scsi_status == 0) {
1937 qla2x00_process_completed_request(vha, req, handle);
1938
1939 return;
1940 }
1941
1942 req->outstanding_cmds[handle] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001943 cp = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 if (cp == NULL) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001945 ql_dbg(ql_dbg_io, vha, 0x3018,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001946 "Command already returned (0x%x/%p).\n",
1947 sts->handle, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948
1949 return;
1950 }
1951
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001952 lscsi_status = scsi_status & STATUS_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953
bdf79622005-04-17 15:06:53 -05001954 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001956 ox_id = 0;
Andrew Vasquez55442132010-07-23 15:28:27 +05001957 sense_len = par_sense_len = rsp_info_len = resid_len =
1958 fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001959 if (IS_FWI2_CAPABLE(ha)) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001960 if (scsi_status & SS_SENSE_LEN_VALID)
1961 sense_len = le32_to_cpu(sts24->sense_len);
1962 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
1963 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
1964 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER))
1965 resid_len = le32_to_cpu(sts24->rsp_residual_count);
1966 if (comp_status == CS_DATA_UNDERRUN)
1967 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001968 rsp_info = sts24->data;
1969 sense_data = sts24->data;
1970 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001971 ox_id = le16_to_cpu(sts24->ox_id);
Andrew Vasquez55442132010-07-23 15:28:27 +05001972 par_sense_len = sizeof(sts24->data);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001973 } else {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001974 if (scsi_status & SS_SENSE_LEN_VALID)
1975 sense_len = le16_to_cpu(sts->req_sense_length);
1976 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
1977 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001978 resid_len = le32_to_cpu(sts->residual_length);
1979 rsp_info = sts->rsp_info;
1980 sense_data = sts->req_sense_data;
Andrew Vasquez55442132010-07-23 15:28:27 +05001981 par_sense_len = sizeof(sts->req_sense_data);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001982 }
1983
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 /* Check for any FCP transport errors. */
1985 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001986 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasquez55442132010-07-23 15:28:27 +05001987 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001988 sense_data += rsp_info_len;
Andrew Vasquez55442132010-07-23 15:28:27 +05001989 par_sense_len -= rsp_info_len;
1990 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001991 if (rsp_info_len > 3 && rsp_info[3]) {
Arun Easi5e19ed92012-02-09 11:15:51 -08001992 ql_dbg(ql_dbg_io, fcport->vha, 0x3019,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001993 "FCP I/O protocol failure (0x%x/0x%x).\n",
1994 rsp_info_len, rsp_info[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001996 res = DID_BUS_BUSY << 16;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001997 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 }
1999 }
2000
Andrew Vasquez3e8ce322008-02-28 14:06:10 -08002001 /* Check for overrun. */
2002 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
2003 scsi_status & SS_RESIDUAL_OVER)
2004 comp_status = CS_DATA_OVERRUN;
2005
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 /*
2007 * Based on Host and scsi status generate status code for Linux
2008 */
2009 switch (comp_status) {
2010 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002011 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 if (scsi_status == 0) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002013 res = DID_OK << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 break;
2015 }
2016 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002017 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002018 scsi_set_resid(cp, resid);
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002019
2020 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002021 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002022 cp->underflow)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002023 ql_dbg(ql_dbg_io, fcport->vha, 0x301a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002024 "Mid-layer underflow "
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002025 "detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002026 resid, scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002027
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002028 res = DID_ERROR << 16;
Andrew Vasquez0da69df2005-12-06 10:58:06 -08002029 break;
2030 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002032 res = DID_OK << 16 | lscsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002034 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002035 ql_dbg(ql_dbg_io, fcport->vha, 0x301b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002036 "QUEUE FULL detected.\n");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07002037 break;
2038 }
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002039 logit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 if (lscsi_status != SS_CHECK_CONDITION)
2041 break;
2042
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002043 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 if (!(scsi_status & SS_SENSE_LEN_VALID))
2045 break;
2046
Andrew Vasquez55442132010-07-23 15:28:27 +05002047 qla2x00_handle_sense(sp, sense_data, par_sense_len, sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002048 rsp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 break;
2050
2051 case CS_DATA_UNDERRUN:
Ravi Ananded17c71b52006-05-17 15:08:55 -07002052 /* Use F/W calculated residual length. */
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002053 resid = IS_FWI2_CAPABLE(ha) ? fw_resid_len : resid_len;
2054 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 if (scsi_status & SS_RESIDUAL_UNDER) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002056 if (IS_FWI2_CAPABLE(ha) && fw_resid_len != resid_len) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002057 ql_dbg(ql_dbg_io, fcport->vha, 0x301d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002058 "Dropped frame(s) detected "
2059 "(0x%x of 0x%x bytes).\n",
2060 resid, scsi_bufflen(cp));
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08002061
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002062 res = DID_ERROR << 16 | lscsi_status;
Arun Easi4e85e3d2011-11-18 09:02:10 -08002063 goto check_scsi_status;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002064 }
2065
2066 if (!lscsi_status &&
2067 ((unsigned)(scsi_bufflen(cp) - resid) <
2068 cp->underflow)) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002069 ql_dbg(ql_dbg_io, fcport->vha, 0x301e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002070 "Mid-layer underflow "
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002071 "detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002072 resid, scsi_bufflen(cp));
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002073
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002074 res = DID_ERROR << 16;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002075 break;
2076 }
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002077 } else if (lscsi_status != SAM_STAT_TASK_SET_FULL &&
2078 lscsi_status != SAM_STAT_BUSY) {
2079 /*
2080 * scsi status of task set and busy are considered to be
2081 * task not completed.
2082 */
2083
Arun Easi5e19ed92012-02-09 11:15:51 -08002084 ql_dbg(ql_dbg_io, fcport->vha, 0x301f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002085 "Dropped frame(s) detected (0x%x "
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002086 "of 0x%x bytes).\n", resid,
2087 scsi_bufflen(cp));
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002088
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002089 res = DID_ERROR << 16 | lscsi_status;
Lalit Chandivade0374f552010-09-03 14:57:04 -07002090 goto check_scsi_status;
Giridhar Malavali4aee5762012-04-25 07:26:15 -07002091 } else {
2092 ql_dbg(ql_dbg_io, fcport->vha, 0x3030,
2093 "scsi_status: 0x%x, lscsi_status: 0x%x\n",
2094 scsi_status, lscsi_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 }
2096
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002097 res = DID_OK << 16 | lscsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002098 logit = 0;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07002099
Lalit Chandivade0374f552010-09-03 14:57:04 -07002100check_scsi_status:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002102 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 * Status.
2104 */
2105 if (lscsi_status != 0) {
Andrew Vasquezffec28a2007-01-29 10:22:27 -08002106 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Arun Easi5e19ed92012-02-09 11:15:51 -08002107 ql_dbg(ql_dbg_io, fcport->vha, 0x3020,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002108 "QUEUE FULL detected.\n");
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002109 logit = 1;
Andrew Vasquezffec28a2007-01-29 10:22:27 -08002110 break;
2111 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 if (lscsi_status != SS_CHECK_CONDITION)
2113 break;
2114
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002115 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 if (!(scsi_status & SS_SENSE_LEN_VALID))
2117 break;
2118
Andrew Vasquez55442132010-07-23 15:28:27 +05002119 qla2x00_handle_sense(sp, sense_data, par_sense_len,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002120 sense_len, rsp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 }
2122 break;
2123
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 case CS_PORT_LOGGED_OUT:
2125 case CS_PORT_CONFIG_CHG:
2126 case CS_PORT_BUSY:
2127 case CS_INCOMPLETE:
2128 case CS_PORT_UNAVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 case CS_TIMEOUT:
Chad Dupuisff454b02010-10-15 11:27:42 -07002130 case CS_RESET:
2131
Mike Christie056a4482008-08-19 18:45:29 -05002132 /*
2133 * We are going to have the fc class block the rport
2134 * while we try to recover so instruct the mid layer
2135 * to requeue until the class decides how to handle this.
2136 */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002137 res = DID_TRANSPORT_DISRUPTED << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002139 if (comp_status == CS_TIMEOUT) {
2140 if (IS_FWI2_CAPABLE(ha))
2141 break;
2142 else if ((le16_to_cpu(sts->status_flags) &
2143 SF_LOGOUT_SENT) == 0)
2144 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002146
Arun Easi5e19ed92012-02-09 11:15:51 -08002147 ql_dbg(ql_dbg_io, fcport->vha, 0x3021,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002148 "Port down status: port-state=0x%x.\n",
2149 atomic_read(&fcport->state));
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002150
2151 if (atomic_read(&fcport->state) == FCS_ONLINE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002152 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 break;
2154
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002155 case CS_ABORTED:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002156 res = DID_RESET << 16;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002157 break;
Arun Easibad75002010-05-04 15:01:30 -07002158
2159 case CS_DIF_ERROR:
Arun Easi8cb20492011-08-16 11:29:22 -07002160 logit = qla2x00_handle_dif_error(sp, sts24);
Arun Easifb6e4662012-08-22 14:21:32 -04002161 res = cp->result;
Arun Easibad75002010-05-04 15:01:30 -07002162 break;
Arun Easi9e522cd2012-08-22 14:21:31 -04002163
2164 case CS_TRANSPORT:
2165 res = DID_ERROR << 16;
2166
2167 if (!IS_PI_SPLIT_DET_CAPABLE(ha))
2168 break;
2169
2170 if (state_flags & BIT_4)
2171 scmd_printk(KERN_WARNING, cp,
2172 "Unsupported device '%s' found.\n",
2173 cp->device->vendor);
2174 break;
2175
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 default:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002177 res = DID_ERROR << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 break;
2179 }
2180
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002181out:
2182 if (logit)
Arun Easi5e19ed92012-02-09 11:15:51 -08002183 ql_dbg(ql_dbg_io, fcport->vha, 0x3022,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002184 "FCP command status: 0x%x-0x%x (0x%x) "
Chad Dupuiscfb09192011-11-18 09:03:07 -08002185 "nexus=%ld:%d:%d portid=%02x%02x%02x oxid=0x%x "
2186 "cdb=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x len=0x%x "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002187 "rsp_info=0x%x resid=0x%x fw_resid=0x%x.\n",
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002188 comp_status, scsi_status, res, vha->host_no,
Chad Dupuiscfb09192011-11-18 09:03:07 -08002189 cp->device->id, cp->device->lun, fcport->d_id.b.domain,
2190 fcport->d_id.b.area, fcport->d_id.b.al_pa, ox_id,
2191 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
2192 cp->cmnd[4], cp->cmnd[5], cp->cmnd[6], cp->cmnd[7],
2193 cp->cmnd[8], cp->cmnd[9], scsi_bufflen(cp), rsp_info_len,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002194 resid_len, fw_resid_len);
Andrew Vasquezb7d22802010-05-04 15:01:27 -07002195
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002196 if (rsp->status_srb == NULL)
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002197 sp->done(ha, sp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198}
2199
2200/**
2201 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
2202 * @ha: SCSI driver HA context
2203 * @pkt: Entry pointer
2204 *
2205 * Extended sense data.
2206 */
2207static void
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002208qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002210 uint8_t sense_sz = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002211 struct qla_hw_data *ha = rsp->hw;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002212 struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002213 srb_t *sp = rsp->status_srb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 struct scsi_cmnd *cp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002215 uint32_t sense_len;
2216 uint8_t *sense_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002218 if (!sp || !GET_CMD_SENSE_LEN(sp))
2219 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002221 sense_len = GET_CMD_SENSE_LEN(sp);
2222 sense_ptr = GET_CMD_SENSE_PTR(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002224 cp = GET_CMD_SP(sp);
2225 if (cp == NULL) {
2226 ql_log(ql_log_warn, vha, 0x3025,
2227 "cmd is NULL: already returned to OS (sp=%p).\n", sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002229 rsp->status_srb = NULL;
2230 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002233 if (sense_len > sizeof(pkt->data))
2234 sense_sz = sizeof(pkt->data);
2235 else
2236 sense_sz = sense_len;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002237
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002238 /* Move sense data. */
2239 if (IS_FWI2_CAPABLE(ha))
2240 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
2241 memcpy(sense_ptr, pkt->data, sense_sz);
2242 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302c,
2243 sense_ptr, sense_sz);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002244
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002245 sense_len -= sense_sz;
2246 sense_ptr += sense_sz;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002247
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002248 SET_CMD_SENSE_PTR(sp, sense_ptr);
2249 SET_CMD_SENSE_LEN(sp, sense_len);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002250
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002251 /* Place command on done queue. */
2252 if (sense_len == 0) {
2253 rsp->status_srb = NULL;
2254 sp->done(ha, sp, cp->result);
Giridhar Malavalic4631192011-11-18 09:03:08 -08002255 }
Giridhar Malavalic4631192011-11-18 09:03:08 -08002256}
2257
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258/**
2259 * qla2x00_error_entry() - Process an error entry.
2260 * @ha: SCSI driver HA context
2261 * @pkt: Entry pointer
2262 */
2263static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002264qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265{
2266 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002267 struct qla_hw_data *ha = vha->hw;
Giridhar Malavalic4631192011-11-18 09:03:08 -08002268 const char func[] = "ERROR-IOCB";
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002269 uint16_t que = MSW(pkt->handle);
Arun Easia6fe35c2012-02-09 11:16:01 -08002270 struct req_que *req = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002271 int res = DID_ERROR << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002272
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002273 ql_dbg(ql_dbg_async, vha, 0x502a,
2274 "type of error status in response: 0x%x\n", pkt->entry_status);
2275
Arun Easia6fe35c2012-02-09 11:16:01 -08002276 if (que >= ha->max_req_queues || !ha->req_q_map[que])
2277 goto fatal;
2278
2279 req = ha->req_q_map[que];
2280
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002281 if (pkt->entry_status & RF_BUSY)
2282 res = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283
Giridhar Malavalic4631192011-11-18 09:03:08 -08002284 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
Arun Easia6fe35c2012-02-09 11:16:01 -08002285 if (sp) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002286 sp->done(ha, sp, res);
Arun Easia6fe35c2012-02-09 11:16:01 -08002287 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 }
Arun Easia6fe35c2012-02-09 11:16:01 -08002289fatal:
2290 ql_log(ql_log_warn, vha, 0x5030,
2291 "Error entry - invalid handle/queue.\n");
2292
2293 if (IS_QLA82XX(ha))
2294 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
2295 else
2296 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2297 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298}
2299
2300/**
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002301 * qla24xx_mbx_completion() - Process mailbox command completions.
2302 * @ha: SCSI driver HA context
2303 * @mb0: Mailbox0 register
2304 */
2305static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002306qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002307{
2308 uint16_t cnt;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002309 uint32_t mboxes;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002310 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002311 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002312 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2313
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002314 /* Read all mbox registers? */
2315 mboxes = (1 << ha->mbx_count) - 1;
2316 if (!ha->mcp)
Masanari Iidaa7201012012-11-21 02:40:42 -05002317 ql_dbg(ql_dbg_async, vha, 0x504e, "MBX pointer ERROR.\n");
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002318 else
2319 mboxes = ha->mcp->in_mb;
2320
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002321 /* Load return mailbox registers. */
2322 ha->flags.mbox_int = 1;
2323 ha->mailbox_out[0] = mb0;
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002324 mboxes >>= 1;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002325 wptr = (uint16_t __iomem *)&reg->mailbox1;
2326
2327 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquez4fa94f82011-11-18 09:03:09 -08002328 if (mboxes & BIT_0)
2329 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
2330
2331 mboxes >>= 1;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002332 wptr++;
2333 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002334}
2335
2336/**
2337 * qla24xx_process_response_queue() - Process response queue entries.
2338 * @ha: SCSI driver HA context
2339 */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002340void qla24xx_process_response_queue(struct scsi_qla_host *vha,
2341 struct rsp_que *rsp)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002342{
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002343 struct sts_entry_24xx *pkt;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002344 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002345
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002346 if (!vha->flags.online)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002347 return;
2348
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002349 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
2350 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002351
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002352 rsp->ring_index++;
2353 if (rsp->ring_index == rsp->length) {
2354 rsp->ring_index = 0;
2355 rsp->ring_ptr = rsp->ring;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002356 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002357 rsp->ring_ptr++;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002358 }
2359
2360 if (pkt->entry_status != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002361 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002362
2363 (void)qlt_24xx_process_response_error(vha, pkt);
2364
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002365 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2366 wmb();
2367 continue;
2368 }
2369
2370 switch (pkt->entry_type) {
2371 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002372 qla2x00_status_entry(vha, rsp, pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002373 break;
2374 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002375 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002376 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002377 case VP_RPT_ID_IOCB_TYPE:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002378 qla24xx_report_id_acquisition(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002379 (struct vp_rpt_id_entry_24xx *)pkt);
2380 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07002381 case LOGINOUT_PORT_IOCB_TYPE:
2382 qla24xx_logio_entry(vha, rsp->req,
2383 (struct logio_entry_24xx *)pkt);
2384 break;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07002385 case TSK_MGMT_IOCB_TYPE:
2386 qla24xx_tm_iocb_entry(vha, rsp->req,
2387 (struct tsk_mgmt_entry *)pkt);
2388 break;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002389 case CT_IOCB_TYPE:
2390 qla24xx_els_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002391 break;
2392 case ELS_IOCB_TYPE:
2393 qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE);
2394 break;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002395 case ABTS_RECV_24XX:
2396 /* ensure that the ATIO queue is empty */
2397 qlt_24xx_process_atio_queue(vha);
2398 case ABTS_RESP_24XX:
2399 case CTIO_TYPE7:
2400 case NOTIFY_ACK_TYPE:
2401 qlt_response_pkt_all_vps(vha, (response_t *)pkt);
2402 break;
Saurav Kashyap54883292011-08-16 11:31:48 -07002403 case MARKER_TYPE:
2404 /* Do nothing in this case, this check is to prevent it
2405 * from falling into default case
2406 */
2407 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002408 default:
2409 /* Type Not Supported. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002410 ql_dbg(ql_dbg_async, vha, 0x5042,
2411 "Received unknown response pkt type %x "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002412 "entry status=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002413 pkt->entry_type, pkt->entry_status);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002414 break;
2415 }
2416 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2417 wmb();
2418 }
2419
2420 /* Adjust ring index */
Giridhar Malavalia9083012010-04-12 17:59:55 -07002421 if (IS_QLA82XX(ha)) {
2422 struct device_reg_82xx __iomem *reg = &ha->iobase->isp82;
2423 WRT_REG_DWORD(&reg->rsp_q_out[0], rsp->ring_index);
2424 } else
2425 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002426}
2427
Andrew Vasquez05236a02007-09-20 14:07:37 -07002428static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002429qla2xxx_check_risc_status(scsi_qla_host_t *vha)
Andrew Vasquez05236a02007-09-20 14:07:37 -07002430{
2431 int rval;
2432 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002433 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez05236a02007-09-20 14:07:37 -07002434 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2435
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002436 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha))
Andrew Vasquez05236a02007-09-20 14:07:37 -07002437 return;
2438
2439 rval = QLA_SUCCESS;
2440 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
2441 RD_REG_DWORD(&reg->iobase_addr);
2442 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
2443 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
2444 rval == QLA_SUCCESS; cnt--) {
2445 if (cnt) {
2446 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
2447 udelay(10);
2448 } else
2449 rval = QLA_FUNCTION_TIMEOUT;
2450 }
2451 if (rval == QLA_SUCCESS)
2452 goto next_test;
2453
2454 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
2455 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
2456 rval == QLA_SUCCESS; cnt--) {
2457 if (cnt) {
2458 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
2459 udelay(10);
2460 } else
2461 rval = QLA_FUNCTION_TIMEOUT;
2462 }
2463 if (rval != QLA_SUCCESS)
2464 goto done;
2465
2466next_test:
2467 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002468 ql_log(ql_log_info, vha, 0x504c,
2469 "Additional code -- 0x55AA.\n");
Andrew Vasquez05236a02007-09-20 14:07:37 -07002470
2471done:
2472 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
2473 RD_REG_DWORD(&reg->iobase_window);
2474}
2475
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002476/**
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002477 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP24xx.
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002478 * @irq:
2479 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002480 *
2481 * Called by system whenever the host adapter generates an interrupt.
2482 *
2483 * Returns handled flag.
2484 */
2485irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01002486qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002487{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002488 scsi_qla_host_t *vha;
2489 struct qla_hw_data *ha;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002490 struct device_reg_24xx __iomem *reg;
2491 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002492 unsigned long iter;
2493 uint32_t stat;
2494 uint32_t hccr;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002495 uint16_t mb[8];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002496 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002497 unsigned long flags;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002498
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002499 rsp = (struct rsp_que *) dev_id;
2500 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002501 ql_log(ql_log_info, NULL, 0x5059,
2502 "%s: NULL response queue pointer.\n", __func__);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002503 return IRQ_NONE;
2504 }
2505
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002506 ha = rsp->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002507 reg = &ha->iobase->isp24;
2508 status = 0;
2509
Andrew Vasquez85880802009-12-15 21:29:46 -08002510 if (unlikely(pci_channel_offline(ha->pdev)))
2511 return IRQ_HANDLED;
2512
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002513 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002514 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002515 for (iter = 50; iter--; ) {
2516 stat = RD_REG_DWORD(&reg->host_status);
2517 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08002518 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07002519 break;
2520
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002521 hccr = RD_REG_DWORD(&reg->hccr);
2522
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002523 ql_log(ql_log_warn, vha, 0x504b,
2524 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2525 hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002526
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002527 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002528
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002529 ha->isp_ops->fw_dump(vha, 1);
2530 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002531 break;
2532 } else if ((stat & HSRX_RISC_INT) == 0)
2533 break;
2534
2535 switch (stat & 0xff) {
Arun Easifafbda92012-08-22 14:21:16 -04002536 case INTR_ROM_MB_SUCCESS:
2537 case INTR_ROM_MB_FAILED:
2538 case INTR_MB_SUCCESS:
2539 case INTR_MB_FAILED:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002540 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002541 status |= MBX_INTERRUPT;
2542
2543 break;
Arun Easifafbda92012-08-22 14:21:16 -04002544 case INTR_ASYNC_EVENT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002545 mb[0] = MSW(stat);
2546 mb[1] = RD_REG_WORD(&reg->mailbox1);
2547 mb[2] = RD_REG_WORD(&reg->mailbox2);
2548 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002549 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002550 break;
Arun Easifafbda92012-08-22 14:21:16 -04002551 case INTR_RSP_QUE_UPDATE:
2552 case INTR_RSP_QUE_UPDATE_83XX:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002553 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002554 break;
Arun Easifafbda92012-08-22 14:21:16 -04002555 case INTR_ATIO_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002556 qlt_24xx_process_atio_queue(vha);
2557 break;
Arun Easifafbda92012-08-22 14:21:16 -04002558 case INTR_ATIO_RSP_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002559 qlt_24xx_process_atio_queue(vha);
2560 qla24xx_process_response_queue(vha, rsp);
2561 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002562 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002563 ql_dbg(ql_dbg_async, vha, 0x504f,
2564 "Unrecognized interrupt type (%d).\n", stat * 0xff);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002565 break;
2566 }
2567 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2568 RD_REG_DWORD_RELAXED(&reg->hccr);
Giridhar Malavalicb860bb2012-08-22 14:21:30 -04002569 if (unlikely(IS_QLA83XX(ha) && (ha->pdev->revision == 1)))
2570 ndelay(3500);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002571 }
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002572 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002573
2574 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
2575 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002576 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002577 complete(&ha->mbx_intr_comp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002578 }
2579
2580 return IRQ_HANDLED;
2581}
2582
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002583static irqreturn_t
2584qla24xx_msix_rsp_q(int irq, void *dev_id)
2585{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002586 struct qla_hw_data *ha;
2587 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002588 struct device_reg_24xx __iomem *reg;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002589 struct scsi_qla_host *vha;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002590 unsigned long flags;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002591
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002592 rsp = (struct rsp_que *) dev_id;
2593 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002594 ql_log(ql_log_info, NULL, 0x505a,
2595 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002596 return IRQ_NONE;
2597 }
2598 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002599 reg = &ha->iobase->isp24;
2600
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002601 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002602
Anirban Chakrabortya67093d2010-02-04 14:17:59 -08002603 vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002604 qla24xx_process_response_queue(vha, rsp);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002605 if (!ha->flags.disable_msix_handshake) {
Anirban Chakrabortyeb941142009-08-04 16:12:13 -07002606 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2607 RD_REG_DWORD_RELAXED(&reg->hccr);
2608 }
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002609 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002610
2611 return IRQ_HANDLED;
2612}
2613
2614static irqreturn_t
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002615qla25xx_msix_rsp_q(int irq, void *dev_id)
2616{
2617 struct qla_hw_data *ha;
2618 struct rsp_que *rsp;
Anirban Chakraborty31557542009-12-02 10:36:55 -08002619 struct device_reg_24xx __iomem *reg;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002620 unsigned long flags;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002621
2622 rsp = (struct rsp_que *) dev_id;
2623 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002624 ql_log(ql_log_info, NULL, 0x505b,
2625 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002626 return IRQ_NONE;
2627 }
2628 ha = rsp->hw;
2629
Anirban Chakraborty31557542009-12-02 10:36:55 -08002630 /* Clear the interrupt, if enabled, for this response queue */
Andrew Vasquezd4247542011-10-26 14:20:13 -07002631 if (!ha->flags.disable_msix_handshake) {
Anirban Chakraborty31557542009-12-02 10:36:55 -08002632 reg = &ha->iobase->isp24;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002633 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002634 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2635 RD_REG_DWORD_RELAXED(&reg->hccr);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002636 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002637 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002638 queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work);
2639
2640 return IRQ_HANDLED;
2641}
2642
2643static irqreturn_t
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002644qla24xx_msix_default(int irq, void *dev_id)
2645{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002646 scsi_qla_host_t *vha;
2647 struct qla_hw_data *ha;
2648 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002649 struct device_reg_24xx __iomem *reg;
2650 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002651 uint32_t stat;
2652 uint32_t hccr;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002653 uint16_t mb[8];
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002654 unsigned long flags;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002655
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002656 rsp = (struct rsp_que *) dev_id;
2657 if (!rsp) {
Chad Dupuis3256b432012-02-09 11:15:47 -08002658 ql_log(ql_log_info, NULL, 0x505c,
2659 "%s: NULL response queue pointer.\n", __func__);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002660 return IRQ_NONE;
2661 }
2662 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002663 reg = &ha->iobase->isp24;
2664 status = 0;
2665
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002666 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002667 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002668 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002669 stat = RD_REG_DWORD(&reg->host_status);
2670 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08002671 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07002672 break;
2673
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002674 hccr = RD_REG_DWORD(&reg->hccr);
2675
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002676 ql_log(ql_log_info, vha, 0x5050,
2677 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2678 hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002679
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002680 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002681
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002682 ha->isp_ops->fw_dump(vha, 1);
2683 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002684 break;
2685 } else if ((stat & HSRX_RISC_INT) == 0)
2686 break;
2687
2688 switch (stat & 0xff) {
Arun Easifafbda92012-08-22 14:21:16 -04002689 case INTR_ROM_MB_SUCCESS:
2690 case INTR_ROM_MB_FAILED:
2691 case INTR_MB_SUCCESS:
2692 case INTR_MB_FAILED:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002693 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002694 status |= MBX_INTERRUPT;
2695
2696 break;
Arun Easifafbda92012-08-22 14:21:16 -04002697 case INTR_ASYNC_EVENT:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002698 mb[0] = MSW(stat);
2699 mb[1] = RD_REG_WORD(&reg->mailbox1);
2700 mb[2] = RD_REG_WORD(&reg->mailbox2);
2701 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002702 qla2x00_async_event(vha, rsp, mb);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002703 break;
Arun Easifafbda92012-08-22 14:21:16 -04002704 case INTR_RSP_QUE_UPDATE:
2705 case INTR_RSP_QUE_UPDATE_83XX:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002706 qla24xx_process_response_queue(vha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002707 break;
Arun Easifafbda92012-08-22 14:21:16 -04002708 case INTR_ATIO_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002709 qlt_24xx_process_atio_queue(vha);
2710 break;
Arun Easifafbda92012-08-22 14:21:16 -04002711 case INTR_ATIO_RSP_QUE_UPDATE:
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002712 qlt_24xx_process_atio_queue(vha);
2713 qla24xx_process_response_queue(vha, rsp);
2714 break;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002715 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002716 ql_dbg(ql_dbg_async, vha, 0x5051,
2717 "Unrecognized interrupt type (%d).\n", stat & 0xff);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002718 break;
2719 }
2720 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002721 } while (0);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002722 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002723
2724 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
2725 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002726 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002727 complete(&ha->mbx_intr_comp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002728 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002729 return IRQ_HANDLED;
2730}
2731
2732/* Interrupt handling helpers. */
2733
2734struct qla_init_msix_entry {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002735 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07002736 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002737};
2738
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002739static struct qla_init_msix_entry msix_entries[3] = {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002740 { "qla2xxx (default)", qla24xx_msix_default },
2741 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002742 { "qla2xxx (multiq)", qla25xx_msix_rsp_q },
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002743};
2744
Giridhar Malavalia9083012010-04-12 17:59:55 -07002745static struct qla_init_msix_entry qla82xx_msix_entries[2] = {
2746 { "qla2xxx (default)", qla82xx_msix_default },
2747 { "qla2xxx (rsp_q)", qla82xx_msix_rsp_q },
2748};
2749
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002750static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002751qla24xx_disable_msix(struct qla_hw_data *ha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002752{
2753 int i;
2754 struct qla_msix_entry *qentry;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002755 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002756
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002757 for (i = 0; i < ha->msix_count; i++) {
2758 qentry = &ha->msix_entries[i];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002759 if (qentry->have_irq)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002760 free_irq(qentry->vector, qentry->rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002761 }
2762 pci_disable_msix(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002763 kfree(ha->msix_entries);
2764 ha->msix_entries = NULL;
2765 ha->flags.msix_enabled = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002766 ql_dbg(ql_dbg_init, vha, 0x0042,
2767 "Disabled the MSI.\n");
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002768}
2769
2770static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002771qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002772{
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002773#define MIN_MSIX_COUNT 2
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002774 int i, ret;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002775 struct msix_entry *entries;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002776 struct qla_msix_entry *qentry;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002777 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002778
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002779 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002780 GFP_KERNEL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002781 if (!entries) {
2782 ql_log(ql_log_warn, vha, 0x00bc,
2783 "Failed to allocate memory for msix_entry.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002784 return -ENOMEM;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002785 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002786
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002787 for (i = 0; i < ha->msix_count; i++)
2788 entries[i].entry = i;
2789
2790 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002791 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002792 if (ret < MIN_MSIX_COUNT)
2793 goto msix_failed;
2794
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002795 ql_log(ql_log_warn, vha, 0x00c6,
2796 "MSI-X: Failed to enable support "
2797 "-- %d/%d\n Retry with %d vectors.\n",
2798 ha->msix_count, ret, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002799 ha->msix_count = ret;
2800 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
2801 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002802msix_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002803 ql_log(ql_log_fatal, vha, 0x00c7,
2804 "MSI-X: Failed to enable support, "
2805 "giving up -- %d/%d.\n",
2806 ha->msix_count, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002807 goto msix_out;
2808 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002809 ha->max_rsp_queues = ha->msix_count - 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002810 }
2811 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
2812 ha->msix_count, GFP_KERNEL);
2813 if (!ha->msix_entries) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002814 ql_log(ql_log_fatal, vha, 0x00c8,
2815 "Failed to allocate memory for ha->msix_entries.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002816 ret = -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002817 goto msix_out;
2818 }
2819 ha->flags.msix_enabled = 1;
2820
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002821 for (i = 0; i < ha->msix_count; i++) {
2822 qentry = &ha->msix_entries[i];
2823 qentry->vector = entries[i].vector;
2824 qentry->entry = entries[i].entry;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002825 qentry->have_irq = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002826 qentry->rsp = NULL;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002827 }
2828
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002829 /* Enable MSI-X vectors for the base queue */
2830 for (i = 0; i < 2; i++) {
2831 qentry = &ha->msix_entries[i];
Giridhar Malavalia9083012010-04-12 17:59:55 -07002832 if (IS_QLA82XX(ha)) {
2833 ret = request_irq(qentry->vector,
2834 qla82xx_msix_entries[i].handler,
2835 0, qla82xx_msix_entries[i].name, rsp);
2836 } else {
2837 ret = request_irq(qentry->vector,
2838 msix_entries[i].handler,
2839 0, msix_entries[i].name, rsp);
2840 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002841 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002842 ql_log(ql_log_fatal, vha, 0x00cb,
2843 "MSI-X: unable to register handler -- %x/%d.\n",
2844 qentry->vector, ret);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002845 qla24xx_disable_msix(ha);
2846 ha->mqenable = 0;
2847 goto msix_out;
2848 }
2849 qentry->have_irq = 1;
2850 qentry->rsp = rsp;
2851 rsp->msix = qentry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002852 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002853
2854 /* Enable MSI-X vector for response queue update for queue 0 */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002855 if (IS_QLA83XX(ha)) {
2856 if (ha->msixbase && ha->mqiobase &&
2857 (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
2858 ha->mqenable = 1;
2859 } else
2860 if (ha->mqiobase
2861 && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
2862 ha->mqenable = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002863 ql_dbg(ql_dbg_multiq, vha, 0xc005,
2864 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
2865 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
2866 ql_dbg(ql_dbg_init, vha, 0x0055,
2867 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
2868 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002869
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002870msix_out:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002871 kfree(entries);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002872 return ret;
2873}
2874
2875int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002876qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002877{
2878 int ret;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002879 device_reg_t __iomem *reg = ha->iobase;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002880 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002881
2882 /* If possible, enable MSI-X. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002883 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
2884 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha))
Ben Hutchings6377a7a2010-03-19 16:59:19 -07002885 goto skip_msi;
2886
2887 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
2888 (ha->pdev->subsystem_device == 0x7040 ||
2889 ha->pdev->subsystem_device == 0x7041 ||
2890 ha->pdev->subsystem_device == 0x1705)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002891 ql_log(ql_log_warn, vha, 0x0034,
2892 "MSI-X: Unsupported ISP 2432 SSVID/SSDID (0x%X,0x%X).\n",
Ben Hutchings6377a7a2010-03-19 16:59:19 -07002893 ha->pdev->subsystem_vendor,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002894 ha->pdev->subsystem_device);
Ben Hutchings6377a7a2010-03-19 16:59:19 -07002895 goto skip_msi;
2896 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002897
Chad Dupuis42cd4f52011-08-16 11:29:24 -07002898 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002899 ql_log(ql_log_warn, vha, 0x0035,
2900 "MSI-X; Unsupported ISP2432 (0x%X, 0x%X).\n",
Chad Dupuis42cd4f52011-08-16 11:29:24 -07002901 ha->pdev->revision, QLA_MSIX_CHIP_REV_24XX);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002902 goto skip_msix;
2903 }
2904
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002905 ret = qla24xx_enable_msix(ha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002906 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002907 ql_dbg(ql_dbg_init, vha, 0x0036,
2908 "MSI-X: Enabled (0x%X, 0x%X).\n",
2909 ha->chip_revision, ha->fw_attributes);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002910 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002911 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002912 ql_log(ql_log_info, vha, 0x0037,
2913 "MSI-X Falling back-to MSI mode -%d.\n", ret);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002914skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002915
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002916 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
Giridhar Malavali487370a2012-08-22 14:21:34 -04002917 !IS_QLA8001(ha) && !IS_QLA82XX(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002918 goto skip_msi;
2919
2920 ret = pci_enable_msi(ha->pdev);
2921 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002922 ql_dbg(ql_dbg_init, vha, 0x0038,
2923 "MSI: Enabled.\n");
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002924 ha->flags.msi_enabled = 1;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002925 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002926 ql_log(ql_log_warn, vha, 0x0039,
2927 "MSI-X; Falling back-to INTa mode -- %d.\n", ret);
Giridhar Malavalia033b652012-08-22 14:21:07 -04002928
2929 /* Skip INTx on ISP82xx. */
2930 if (!ha->flags.msi_enabled && IS_QLA82XX(ha))
2931 return QLA_FUNCTION_FAILED;
2932
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002933skip_msi:
2934
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002935 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Mike Hernandez7992abf2010-11-23 16:52:47 -08002936 ha->flags.msi_enabled ? 0 : IRQF_SHARED,
2937 QLA2XXX_DRIVER_NAME, rsp);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002938 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002939 ql_log(ql_log_warn, vha, 0x003a,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002940 "Failed to reserve interrupt %d already in use.\n",
2941 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002942 goto fail;
Saurav Kashyap68d91cb2012-11-21 02:40:44 -05002943 } else if (!ha->flags.msi_enabled)
2944 ql_dbg(ql_dbg_init, vha, 0x0125,
2945 "INTa mode: Enabled.\n");
Mike Hernandez7992abf2010-11-23 16:52:47 -08002946
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002947clear_risc_ints:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002948
Andrew Vasquezc6952482008-04-03 13:13:17 -07002949 spin_lock_irq(&ha->hardware_lock);
Giridhar Malavalic1114952012-08-22 14:21:33 -04002950 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002951 WRT_REG_WORD(&reg->isp.semaphore, 0);
Andrew Vasquezc6952482008-04-03 13:13:17 -07002952 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002953
2954fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002955 return ret;
2956}
2957
2958void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002959qla2x00_free_irqs(scsi_qla_host_t *vha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002960{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002961 struct qla_hw_data *ha = vha->hw;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002962 struct rsp_que *rsp;
2963
2964 /*
2965 * We need to check that ha->rsp_q_map is valid in case we are called
2966 * from a probe failure context.
2967 */
2968 if (!ha->rsp_q_map || !ha->rsp_q_map[0])
2969 return;
2970 rsp = ha->rsp_q_map[0];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002971
2972 if (ha->flags.msix_enabled)
2973 qla24xx_disable_msix(ha);
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002974 else if (ha->flags.msi_enabled) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002975 free_irq(ha->pdev->irq, rsp);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002976 pci_disable_msi(ha->pdev);
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002977 } else
2978 free_irq(ha->pdev->irq, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002979}
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002980
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002981
2982int qla25xx_request_irq(struct rsp_que *rsp)
2983{
2984 struct qla_hw_data *ha = rsp->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002985 struct qla_init_msix_entry *intr = &msix_entries[2];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002986 struct qla_msix_entry *msix = rsp->msix;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002987 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002988 int ret;
2989
2990 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
2991 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002992 ql_log(ql_log_fatal, vha, 0x00e6,
2993 "MSI-X: Unable to register handler -- %x/%d.\n",
2994 msix->vector, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002995 return ret;
2996 }
2997 msix->have_irq = 1;
2998 msix->rsp = rsp;
2999 return ret;
3000}