blob: 6426c7ed9ccc1ac67a0650f1b3483763247c59f9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez07e264b2011-03-30 11:46:23 -07003 * Copyright (c) 2003-2011 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"
8
Andrew Vasquez05236a02007-09-20 14:07:37 -07009#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070011#include <scsi/scsi_tcq.h>
Giridhar Malavali9a069e12010-01-12 13:02:47 -080012#include <scsi/scsi_bsg_fc.h>
Arun Easibad75002010-05-04 15:01:30 -070013#include <scsi/scsi_eh.h>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080016static void qla2x00_process_completed_request(struct scsi_qla_host *,
17 struct req_que *, uint32_t);
18static void qla2x00_status_entry(scsi_qla_host_t *, struct rsp_que *, void *);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070019static void qla2x00_status_cont_entry(struct rsp_que *, sts_cont_entry_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080020static void qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
21 sts_entry_t *);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070022
Linus Torvalds1da177e2005-04-16 15:20:36 -070023/**
24 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
25 * @irq:
26 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 *
28 * Called by system whenever the host adapter generates an interrupt.
29 *
30 * Returns handled flag.
31 */
32irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +010033qla2100_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080035 scsi_qla_host_t *vha;
36 struct qla_hw_data *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -070037 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 unsigned long iter;
Seokmann Ju14e660e2007-09-20 14:07:36 -070040 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070041 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080042 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070043 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080045 rsp = (struct rsp_que *) dev_id;
46 if (!rsp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 printk(KERN_INFO
Saurav Kashyap7c3df132011-07-14 12:00:13 -070048 "%s(): NULL response queue pointer.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 return (IRQ_NONE);
50 }
51
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080052 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -070053 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 status = 0;
55
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070056 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070057 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 for (iter = 50; iter--; ) {
Seokmann Ju14e660e2007-09-20 14:07:36 -070059 hccr = RD_REG_WORD(&reg->hccr);
60 if (hccr & HCCR_RISC_PAUSE) {
61 if (pci_channel_offline(ha->pdev))
62 break;
63
64 /*
65 * Issue a "HARD" reset in order for the RISC interrupt
Justin P. Mattocka06a0f82011-06-23 23:22:27 -070066 * bit to be cleared. Schedule a big hammer to get
Seokmann Ju14e660e2007-09-20 14:07:36 -070067 * out of the RISC PAUSED state.
68 */
69 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
70 RD_REG_WORD(&reg->hccr);
71
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080072 ha->isp_ops->fw_dump(vha, 1);
73 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -070074 break;
75 } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 break;
77
78 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
79 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
80 RD_REG_WORD(&reg->hccr);
81
82 /* Get mailbox data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -070083 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
84 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080085 qla2x00_mbx_completion(vha, mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 status |= MBX_INTERRUPT;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070087 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
88 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
89 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
90 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080091 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 } else {
93 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -070094 ql_dbg(ql_dbg_async, vha, 0x5025,
95 "Unrecognized interrupt type (%d).\n",
96 mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 }
98 /* Release mailbox registers. */
99 WRT_REG_WORD(&reg->semaphore, 0);
100 RD_REG_WORD(&reg->semaphore);
101 } else {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800102 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
105 RD_REG_WORD(&reg->hccr);
106 }
107 }
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700108 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
111 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800113 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 }
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 return (IRQ_HANDLED);
117}
118
119/**
120 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
121 * @irq:
122 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 *
124 * Called by system whenever the host adapter generates an interrupt.
125 *
126 * Returns handled flag.
127 */
128irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100129qla2300_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800131 scsi_qla_host_t *vha;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700132 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 unsigned long iter;
135 uint32_t stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700137 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800138 struct rsp_que *rsp;
139 struct qla_hw_data *ha;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700140 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800142 rsp = (struct rsp_que *) dev_id;
143 if (!rsp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 printk(KERN_INFO
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700145 "%s(): NULL response queue pointer.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 return (IRQ_NONE);
147 }
148
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800149 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700150 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 status = 0;
152
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700153 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700154 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 for (iter = 50; iter--; ) {
156 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
157 if (stat & HSR_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800158 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -0700159 break;
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 hccr = RD_REG_WORD(&reg->hccr);
162 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700163 ql_log(ql_log_warn, vha, 0x5026,
164 "Parity error -- HCCR=%x, Dumping "
165 "firmware.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700167 ql_log(ql_log_warn, vha, 0x5027,
168 "RISC paused -- HCCR=%x, Dumping "
169 "firmware.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 /*
172 * Issue a "HARD" reset in order for the RISC
173 * interrupt bit to be cleared. Schedule a big
Justin P. Mattocka06a0f82011-06-23 23:22:27 -0700174 * hammer to get out of the RISC PAUSED state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 */
176 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
177 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800178
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800179 ha->isp_ops->fw_dump(vha, 1);
180 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 break;
182 } else if ((stat & HSR_RISC_INT) == 0)
183 break;
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 case 0x1:
187 case 0x2:
188 case 0x10:
189 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800190 qla2x00_mbx_completion(vha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 status |= MBX_INTERRUPT;
192
193 /* Release mailbox registers. */
194 WRT_REG_WORD(&reg->semaphore, 0);
195 break;
196 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700197 mb[0] = MSW(stat);
198 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
199 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
200 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800201 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700202 break;
203 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800204 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 break;
206 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700207 mb[0] = MBA_CMPLT_1_16BIT;
208 mb[1] = MSW(stat);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800209 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 break;
211 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700212 mb[0] = MBA_SCSI_COMPLETION;
213 mb[1] = MSW(stat);
214 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800215 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 break;
217 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700218 ql_dbg(ql_dbg_async, vha, 0x5028,
219 "Unrecognized interrupt type (%d).\n", stat & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 break;
221 }
222 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
223 RD_REG_WORD_RELAXED(&reg->hccr);
224 }
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700225 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
228 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800230 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 }
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 return (IRQ_HANDLED);
234}
235
236/**
237 * qla2x00_mbx_completion() - Process mailbox command completions.
238 * @ha: SCSI driver HA context
239 * @mb0: Mailbox0 register
240 */
241static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800242qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243{
244 uint16_t cnt;
245 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800246 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700247 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 /* Load return mailbox registers. */
250 ha->flags.mbox_int = 1;
251 ha->mailbox_out[0] = mb0;
252 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
253
254 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700255 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
257 if (cnt == 4 || cnt == 5)
258 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
259 else
260 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 wptr++;
263 }
264
Chad Dupuiscfb09192011-11-18 09:03:07 -0800265 if (!ha->mcp)
266 ql_dbg(ql_dbg_async, vha, 0x5001, "MBX pointer ERROR.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267}
268
Andrew Vasquez8a659572009-02-08 20:50:12 -0800269static void
270qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
271{
272 static char *event[] =
273 { "Complete", "Request Notification", "Time Extension" };
274 int rval;
275 struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
276 uint16_t __iomem *wptr;
277 uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
278
279 /* Seed data -- mailbox1 -> mailbox7. */
280 wptr = (uint16_t __iomem *)&reg24->mailbox1;
281 for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
282 mb[cnt] = RD_REG_WORD(wptr);
283
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700284 ql_dbg(ql_dbg_async, vha, 0x5021,
285 "Inter-Driver Commucation %s -- "
286 "%04x %04x %04x %04x %04x %04x %04x.\n",
287 event[aen & 0xff], mb[0], mb[1], mb[2], mb[3],
288 mb[4], mb[5], mb[6]);
Andrew Vasquez8a659572009-02-08 20:50:12 -0800289
290 /* Acknowledgement needed? [Notify && non-zero timeout]. */
291 timeout = (descr >> 8) & 0xf;
292 if (aen != MBA_IDC_NOTIFY || !timeout)
293 return;
294
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700295 ql_dbg(ql_dbg_async, vha, 0x5022,
Joe Perchesd8424f62011-11-18 09:03:06 -0800296 "%lu Inter-Driver Communication %s -- ACK timeout=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700297 vha->host_no, event[aen & 0xff], timeout);
Andrew Vasquez8a659572009-02-08 20:50:12 -0800298
299 rval = qla2x00_post_idc_ack_work(vha, mb);
300 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700301 ql_log(ql_log_warn, vha, 0x5023,
Andrew Vasquez8a659572009-02-08 20:50:12 -0800302 "IDC failed to post ACK.\n");
303}
304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305/**
306 * qla2x00_async_event() - Process aynchronous events.
307 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700308 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700310void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800311qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700313#define LS_UNKNOWN 2
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800314 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 char *link_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 uint16_t handle_cnt;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700317 uint16_t cnt, mbx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 uint32_t handles[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800319 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700320 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700321 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
Andrew Vasquezbc5c2aa2010-12-21 16:00:24 -0800322 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 uint32_t rscn_entry, host_pid;
324 uint8_t rscn_queue_index;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700325 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
327 /* Setup to process RIO completion. */
328 handle_cnt = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700329 if (IS_QLA8XXX_TYPE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800330 goto skip_rio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 switch (mb[0]) {
332 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700333 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 handle_cnt = 1;
335 break;
336 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700337 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 handle_cnt = 1;
339 mb[0] = MBA_SCSI_COMPLETION;
340 break;
341 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700342 handles[0] = mb[1];
343 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 handle_cnt = 2;
345 mb[0] = MBA_SCSI_COMPLETION;
346 break;
347 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700348 handles[0] = mb[1];
349 handles[1] = mb[2];
350 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 handle_cnt = 3;
352 mb[0] = MBA_SCSI_COMPLETION;
353 break;
354 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700355 handles[0] = mb[1];
356 handles[1] = mb[2];
357 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
359 handle_cnt = 4;
360 mb[0] = MBA_SCSI_COMPLETION;
361 break;
362 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700363 handles[0] = mb[1];
364 handles[1] = mb[2];
365 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
367 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
368 handle_cnt = 5;
369 mb[0] = MBA_SCSI_COMPLETION;
370 break;
371 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700372 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 handles[1] = le32_to_cpu(
374 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
375 RD_MAILBOX_REG(ha, reg, 6));
376 handle_cnt = 2;
377 mb[0] = MBA_SCSI_COMPLETION;
378 break;
379 default:
380 break;
381 }
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800382skip_rio:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 switch (mb[0]) {
384 case MBA_SCSI_COMPLETION: /* Fast Post */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800385 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 break;
387
388 for (cnt = 0; cnt < handle_cnt; cnt++)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800389 qla2x00_process_completed_request(vha, rsp->req,
390 handles[cnt]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 break;
392
393 case MBA_RESET: /* Reset */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700394 ql_dbg(ql_dbg_async, vha, 0x5002,
395 "Asynchronous RESET.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800397 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 break;
399
400 case MBA_SYSTEM_ERR: /* System Error */
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700401 mbx = IS_QLA81XX(ha) ? RD_REG_WORD(&reg24->mailbox7) : 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700402 ql_log(ql_log_warn, vha, 0x5003,
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700403 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh "
404 "mbx7=%xh.\n", mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800406 ha->isp_ops->fw_dump(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Andrew Vasqueze4289242007-07-19 15:05:56 -0700408 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700409 if (mb[1] == 0 && mb[2] == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700410 ql_log(ql_log_fatal, vha, 0x5004,
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700411 "Unrecoverable Hardware Error: adapter "
412 "marked OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800413 vha->flags.online = 0;
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700414 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300415 /* Check to see if MPI timeout occurred */
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700416 if ((mbx & MBX_3) && (ha->flags.port0))
417 set_bit(MPI_RESET_NEEDED,
418 &vha->dpc_flags);
419
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800420 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700421 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700422 } else if (mb[1] == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700423 ql_log(ql_log_fatal, vha, 0x5005,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 "Unrecoverable Hardware Error: adapter marked "
425 "OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800426 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800428 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 break;
430
431 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700432 ql_log(ql_log_warn, vha, 0x5006,
433 "ISP Request Transfer Error (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800435 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 break;
437
438 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700439 ql_log(ql_log_warn, vha, 0x5007,
440 "ISP Response Transfer Error.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800442 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 break;
444
445 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700446 ql_dbg(ql_dbg_async, vha, 0x5008,
447 "Asynchronous WAKEUP_THRES.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 break;
449
450 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Chad Dupuiscfb09192011-11-18 09:03:07 -0800451 ql_dbg(ql_dbg_async, vha, 0x5009,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700452 "LIP occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800454 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
455 atomic_set(&vha->loop_state, LOOP_DOWN);
456 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
457 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 }
459
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800460 if (vha->vp_idx) {
461 atomic_set(&vha->vp_state, VP_FAILED);
462 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700463 }
464
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800465 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
466 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800468 vha->flags.management_server_logged_in = 0;
469 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 break;
471
472 case MBA_LOOP_UP: /* Loop Up Event */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
474 link_speed = link_speeds[0];
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700475 ha->link_data_rate = PORT_SPEED_1GB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 } else {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700477 link_speed = link_speeds[LS_UNKNOWN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 if (mb[1] < 5)
479 link_speed = link_speeds[mb[1]];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800480 else if (mb[1] == 0x13)
481 link_speed = link_speeds[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 ha->link_data_rate = mb[1];
483 }
484
Chad Dupuiscfb09192011-11-18 09:03:07 -0800485 ql_dbg(ql_dbg_async, vha, 0x500a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700486 "LOOP UP detected (%s Gbps).\n", link_speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800488 vha->flags.management_server_logged_in = 0;
489 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 break;
491
492 case MBA_LOOP_DOWN: /* Loop Down Event */
Andrew Vasquezbdab23d2009-10-13 15:16:46 -0700493 mbx = IS_QLA81XX(ha) ? RD_REG_WORD(&reg24->mailbox4) : 0;
Andrew Vasquezbc5c2aa2010-12-21 16:00:24 -0800494 mbx = IS_QLA82XX(ha) ? RD_REG_WORD(&reg82->mailbox_out[4]) : mbx;
Chad Dupuiscfb09192011-11-18 09:03:07 -0800495 ql_dbg(ql_dbg_async, vha, 0x500b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700496 "LOOP DOWN detected (%x %x %x %x).\n",
497 mb[1], mb[2], mb[3], mbx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800499 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
500 atomic_set(&vha->loop_state, LOOP_DOWN);
501 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
502 vha->device_flags |= DFLG_NO_CABLE;
503 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 }
505
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800506 if (vha->vp_idx) {
507 atomic_set(&vha->vp_state, VP_FAILED);
508 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700509 }
510
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800511 vha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700512 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800513 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 break;
515
516 case MBA_LIP_RESET: /* LIP reset occurred */
Chad Dupuiscfb09192011-11-18 09:03:07 -0800517 ql_dbg(ql_dbg_async, vha, 0x500c,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700518 "LIP reset occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800520 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
521 atomic_set(&vha->loop_state, LOOP_DOWN);
522 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
523 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 }
525
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800526 if (vha->vp_idx) {
527 atomic_set(&vha->vp_state, VP_FAILED);
528 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700529 }
530
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800531 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
533 ha->operating_mode = LOOP;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800534 vha->flags.management_server_logged_in = 0;
535 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 break;
537
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800538 /* case MBA_DCBX_COMPLETE: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 case MBA_POINT_TO_POINT: /* Point-to-Point */
540 if (IS_QLA2100(ha))
541 break;
542
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700543 if (IS_QLA8XXX_TYPE(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700544 ql_dbg(ql_dbg_async, vha, 0x500d,
545 "DCBX Completed -- %04x %04x %04x.\n",
546 mb[1], mb[2], mb[3]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700547 if (ha->notify_dcbx_comp)
548 complete(&ha->dcbx_comp);
549
550 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700551 ql_dbg(ql_dbg_async, vha, 0x500e,
552 "Asynchronous P2P MODE received.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
554 /*
555 * Until there's a transition from loop down to loop up, treat
556 * this as loop down only.
557 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800558 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
559 atomic_set(&vha->loop_state, LOOP_DOWN);
560 if (!atomic_read(&vha->loop_down_timer))
561 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800563 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 }
565
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800566 if (vha->vp_idx) {
567 atomic_set(&vha->vp_state, VP_FAILED);
568 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700569 }
570
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800571 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
572 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
573
574 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
575 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800576
577 ha->flags.gpsc_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800578 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 break;
580
581 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
582 if (IS_QLA2100(ha))
583 break;
584
Chad Dupuiscfb09192011-11-18 09:03:07 -0800585 ql_dbg(ql_dbg_async, vha, 0x500f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 "Configuration change detected: value=%x.\n", mb[1]);
587
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800588 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
589 atomic_set(&vha->loop_state, LOOP_DOWN);
590 if (!atomic_read(&vha->loop_down_timer))
591 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800593 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 }
595
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800596 if (vha->vp_idx) {
597 atomic_set(&vha->vp_state, VP_FAILED);
598 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700599 }
600
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800601 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
602 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 break;
604
605 case MBA_PORT_UPDATE: /* Port database update */
Santosh Vernekar55903b92009-07-31 15:09:25 -0700606 /*
607 * Handle only global and vn-port update events
608 *
609 * Relevant inputs:
610 * mb[1] = N_Port handle of changed port
611 * OR 0xffff for global event
612 * mb[2] = New login state
613 * 7 = Port logged out
614 * mb[3] = LSB is vp_idx, 0xff = all vps
615 *
616 * Skip processing if:
617 * Event is global, vp_idx is NOT all vps,
618 * vp_idx does not match
619 * Event is not global, vp_idx does not match
620 */
Andrew Vasquez12cec632010-03-19 16:59:17 -0700621 if (IS_QLA2XXX_MIDTYPE(ha) &&
622 ((mb[1] == 0xffff && (mb[3] & 0xff) != 0xff) ||
623 (mb[1] != 0xffff)) && vha->vp_idx != (mb[3] & 0xff))
624 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800625
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700626 /* Global event -- port logout or port unavailable. */
627 if (mb[1] == 0xffff && mb[2] == 0x7) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700628 ql_dbg(ql_dbg_async, vha, 0x5010,
629 "Port unavailable %04x %04x %04x.\n",
630 mb[1], mb[2], mb[3]);
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700631
632 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
633 atomic_set(&vha->loop_state, LOOP_DOWN);
634 atomic_set(&vha->loop_down_timer,
635 LOOP_DOWN_TIME);
636 vha->device_flags |= DFLG_NO_CABLE;
637 qla2x00_mark_all_devices_lost(vha, 1);
638 }
639
640 if (vha->vp_idx) {
641 atomic_set(&vha->vp_state, VP_FAILED);
642 fc_vport_set_state(vha->fc_vport,
643 FC_VPORT_FAILED);
Santosh Vernekarfaadc5e2009-07-31 15:09:26 -0700644 qla2x00_mark_all_devices_lost(vha, 1);
Andrew Vasquez9764ff82009-07-31 15:09:24 -0700645 }
646
647 vha->flags.management_server_logged_in = 0;
648 ha->link_data_rate = PORT_SPEED_UNKNOWN;
649 break;
650 }
651
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 /*
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700653 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 * event etc. earlier indicating loop is down) then process
655 * it. Otherwise ignore it and Wait for RSCN to come in.
656 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800657 atomic_set(&vha->loop_down_timer, 0);
658 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
659 atomic_read(&vha->loop_state) != LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700660 ql_dbg(ql_dbg_async, vha, 0x5011,
661 "Asynchronous PORT UPDATE ignored %04x/%04x/%04x.\n",
662 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 break;
664 }
665
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700666 ql_dbg(ql_dbg_async, vha, 0x5012,
667 "Port database changed %04x %04x %04x.\n",
668 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
670 /*
671 * Mark all devices as missing so we will login again.
672 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800673 atomic_set(&vha->loop_state, LOOP_UP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800675 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800677 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800679 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
680 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 break;
682
683 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju3c397402008-05-19 14:25:39 -0700684 /* Check if the Vport has issued a SCR */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800685 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
Seokmann Ju3c397402008-05-19 14:25:39 -0700686 break;
687 /* Only handle SCNs for our Vport index. */
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700688 if (ha->flags.npiv_supported && vha->vp_idx != (mb[3] & 0xff))
Seokmann Ju3c397402008-05-19 14:25:39 -0700689 break;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700690
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700691 ql_dbg(ql_dbg_async, vha, 0x5013,
692 "RSCN database changed -- %04x %04x %04x.\n",
693 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
Ravi Anand59d72d82008-09-11 21:22:53 -0700695 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800696 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
697 | vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 if (rscn_entry == host_pid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700699 ql_dbg(ql_dbg_async, vha, 0x5014,
700 "Ignoring RSCN update to local host "
701 "port ID (%06x).\n", host_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 break;
703 }
704
Ravi Anand59d72d82008-09-11 21:22:53 -0700705 /* Ignore reserved bits from RSCN-payload. */
706 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800707 rscn_queue_index = vha->rscn_in_ptr + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 if (rscn_queue_index == MAX_RSCN_COUNT)
709 rscn_queue_index = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800710 if (rscn_queue_index != vha->rscn_out_ptr) {
711 vha->rscn_queue[vha->rscn_in_ptr] = rscn_entry;
712 vha->rscn_in_ptr = rscn_queue_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800714 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 }
716
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800717 atomic_set(&vha->loop_down_timer, 0);
718 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800720 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
721 set_bit(RSCN_UPDATE, &vha->dpc_flags);
722 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 break;
724
725 /* case MBA_RIO_RESPONSE: */
726 case MBA_ZIO_RESPONSE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700727 ql_dbg(ql_dbg_async, vha, 0x5015,
728 "[R|Z]IO update completion.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
Andrew Vasqueze4289242007-07-19 15:05:56 -0700730 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700731 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700732 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800733 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700735
736 case MBA_DISCARD_RND_FRAME:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700737 ql_dbg(ql_dbg_async, vha, 0x5016,
738 "Discard RND Frame -- %04x %04x %04x.\n",
739 mb[1], mb[2], mb[3]);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700740 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700741
742 case MBA_TRACE_NOTIFICATION:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700743 ql_dbg(ql_dbg_async, vha, 0x5017,
744 "Trace Notification -- %04x %04x.\n", mb[1], mb[2]);
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700745 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700746
747 case MBA_ISP84XX_ALERT:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700748 ql_dbg(ql_dbg_async, vha, 0x5018,
749 "ISP84XX Alert Notification -- %04x %04x %04x.\n",
750 mb[1], mb[2], mb[3]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700751
752 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
753 switch (mb[1]) {
754 case A84_PANIC_RECOVERY:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700755 ql_log(ql_log_info, vha, 0x5019,
756 "Alert 84XX: panic recovery %04x %04x.\n",
757 mb[2], mb[3]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700758 break;
759 case A84_OP_LOGIN_COMPLETE:
760 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700761 ql_log(ql_log_info, vha, 0x501a,
762 "Alert 84XX: firmware version %x.\n",
763 ha->cs84xx->op_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700764 break;
765 case A84_DIAG_LOGIN_COMPLETE:
766 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700767 ql_log(ql_log_info, vha, 0x501b,
768 "Alert 84XX: diagnostic firmware version %x.\n",
769 ha->cs84xx->diag_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700770 break;
771 case A84_GOLD_LOGIN_COMPLETE:
772 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
773 ha->cs84xx->fw_update = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700774 ql_log(ql_log_info, vha, 0x501c,
775 "Alert 84XX: gold firmware version %x.\n",
776 ha->cs84xx->gold_fw_version);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700777 break;
778 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700779 ql_log(ql_log_warn, vha, 0x501d,
780 "Alert 84xx: Invalid Alert %04x %04x %04x.\n",
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700781 mb[1], mb[2], mb[3]);
782 }
783 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
784 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800785 case MBA_DCBX_START:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700786 ql_dbg(ql_dbg_async, vha, 0x501e,
787 "DCBX Started -- %04x %04x %04x.\n",
788 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800789 break;
790 case MBA_DCBX_PARAM_UPDATE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700791 ql_dbg(ql_dbg_async, vha, 0x501f,
792 "DCBX Parameters Updated -- %04x %04x %04x.\n",
793 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800794 break;
795 case MBA_FCF_CONF_ERR:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700796 ql_dbg(ql_dbg_async, vha, 0x5020,
797 "FCF Configuration Error -- %04x %04x %04x.\n",
798 mb[1], mb[2], mb[3]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800799 break;
800 case MBA_IDC_COMPLETE:
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800801 case MBA_IDC_NOTIFY:
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800802 case MBA_IDC_TIME_EXT:
Andrew Vasquez8a659572009-02-08 20:50:12 -0800803 qla81xx_idc_event(vha, mb[0], mb[1]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800804 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700806
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800807 if (!vha->vp_idx && ha->num_vhosts)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800808 qla2x00_alert_all_vps(rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809}
810
811/**
812 * qla2x00_process_completed_request() - Process a Fast Post response.
813 * @ha: SCSI driver HA context
814 * @index: SRB index
815 */
816static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800817qla2x00_process_completed_request(struct scsi_qla_host *vha,
818 struct req_que *req, uint32_t index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819{
820 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800821 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
823 /* Validate handle. */
824 if (index >= MAX_OUTSTANDING_COMMANDS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700825 ql_log(ql_log_warn, vha, 0x3014,
826 "Invalid SCSI command index (%x).\n", index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Giridhar Malavali8f7daea2011-03-30 11:46:26 -0700828 if (IS_QLA82XX(ha))
829 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
830 else
831 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 return;
833 }
834
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800835 sp = req->outstanding_cmds[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 if (sp) {
837 /* Free outstanding command slot. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800838 req->outstanding_cmds[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 /* Save ISP completion status */
841 sp->cmd->result = DID_OK << 16;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800842 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700844 ql_log(ql_log_warn, vha, 0x3016, "Invalid SCSI SRB.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Giridhar Malavali8f7daea2011-03-30 11:46:26 -0700846 if (IS_QLA82XX(ha))
847 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
848 else
849 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 }
851}
852
Andrew Vasquezac280b62009-08-20 11:06:05 -0700853static srb_t *
854qla2x00_get_sp_from_handle(scsi_qla_host_t *vha, const char *func,
855 struct req_que *req, void *iocb)
856{
857 struct qla_hw_data *ha = vha->hw;
858 sts_entry_t *pkt = iocb;
859 srb_t *sp = NULL;
860 uint16_t index;
861
862 index = LSW(pkt->handle);
863 if (index >= MAX_OUTSTANDING_COMMANDS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700864 ql_log(ql_log_warn, vha, 0x5031,
865 "Invalid command index (%x).\n", index);
Giridhar Malavali8f7daea2011-03-30 11:46:26 -0700866 if (IS_QLA82XX(ha))
867 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
868 else
869 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700870 goto done;
871 }
872 sp = req->outstanding_cmds[index];
873 if (!sp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700874 ql_log(ql_log_warn, vha, 0x5032,
875 "Invalid completion handle (%x) -- timed-out.\n", index);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700876 return sp;
877 }
878 if (sp->handle != index) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700879 ql_log(ql_log_warn, vha, 0x5033,
880 "SRB handle (%x) mismatch %x.\n", sp->handle, index);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700881 return NULL;
882 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800883
Andrew Vasquezac280b62009-08-20 11:06:05 -0700884 req->outstanding_cmds[index] = NULL;
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800885
Andrew Vasquezac280b62009-08-20 11:06:05 -0700886done:
887 return sp;
888}
889
890static void
891qla2x00_mbx_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
892 struct mbx_entry *mbx)
893{
894 const char func[] = "MBX-IOCB";
895 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700896 fc_port_t *fcport;
897 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700898 struct srb_iocb *lio;
899 struct srb_ctx *ctx;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700900 uint16_t *data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700901 uint16_t status;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700902
903 sp = qla2x00_get_sp_from_handle(vha, func, req, mbx);
904 if (!sp)
905 return;
906
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700907 ctx = sp->ctx;
908 lio = ctx->u.iocb_cmd;
909 type = ctx->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700910 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700911 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700912
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700913 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700914 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700915 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700916 if (mbx->entry_status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700917 ql_dbg(ql_dbg_async, vha, 0x5043,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800918 "Async-%s error entry - hdl=%x portid=%02x%02x%02x "
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -0700919 "entry-status=%x status=%x state-flag=%x "
Chad Dupuiscfb09192011-11-18 09:03:07 -0800920 "status-flags=%x.\n", type, sp->handle,
921 fcport->d_id.b.domain, fcport->d_id.b.area,
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -0700922 fcport->d_id.b.al_pa, mbx->entry_status,
923 le16_to_cpu(mbx->status), le16_to_cpu(mbx->state_flags),
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700924 le16_to_cpu(mbx->status_flags));
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -0700925
Chad Dupuiscfb09192011-11-18 09:03:07 -0800926 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5029,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700927 (uint8_t *)mbx, sizeof(*mbx));
Andrew Vasquezac280b62009-08-20 11:06:05 -0700928
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700929 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700930 }
931
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700932 status = le16_to_cpu(mbx->status);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700933 if (status == 0x30 && ctx->type == SRB_LOGIN_CMD &&
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700934 le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE)
935 status = 0;
936 if (!status && le16_to_cpu(mbx->mb0) == MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700937 ql_dbg(ql_dbg_async, vha, 0x5045,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800938 "Async-%s complete - hdl=%x portid=%02x%02x%02x mbx1=%x.\n",
939 type, sp->handle, fcport->d_id.b.domain,
940 fcport->d_id.b.area, fcport->d_id.b.al_pa,
941 le16_to_cpu(mbx->mb1));
Andrew Vasquezac280b62009-08-20 11:06:05 -0700942
943 data[0] = MBS_COMMAND_COMPLETE;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700944 if (ctx->type == SRB_LOGIN_CMD) {
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700945 fcport->port_type = FCT_TARGET;
946 if (le16_to_cpu(mbx->mb1) & BIT_0)
947 fcport->port_type = FCT_INITIATOR;
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700948 else if (le16_to_cpu(mbx->mb1) & BIT_1)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700949 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700950 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700951 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700952 }
953
954 data[0] = le16_to_cpu(mbx->mb0);
955 switch (data[0]) {
956 case MBS_PORT_ID_USED:
957 data[1] = le16_to_cpu(mbx->mb1);
958 break;
959 case MBS_LOOP_ID_USED:
960 break;
961 default:
962 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700963 break;
964 }
965
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700966 ql_log(ql_log_warn, vha, 0x5046,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800967 "Async-%s failed - hdl=%x portid=%02x%02x%02x status=%x "
968 "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n", type, sp->handle,
969 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
970 status, le16_to_cpu(mbx->mb0), le16_to_cpu(mbx->mb1),
Andrew Vasquezac280b62009-08-20 11:06:05 -0700971 le16_to_cpu(mbx->mb2), le16_to_cpu(mbx->mb6),
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700972 le16_to_cpu(mbx->mb7));
Andrew Vasquezac280b62009-08-20 11:06:05 -0700973
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700974logio_done:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700975 lio->done(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700976}
977
978static void
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +0500979qla2x00_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
980 sts_entry_t *pkt, int iocb_type)
981{
982 const char func[] = "CT_IOCB";
983 const char *type;
984 struct qla_hw_data *ha = vha->hw;
985 srb_t *sp;
986 struct srb_ctx *sp_bsg;
987 struct fc_bsg_job *bsg_job;
988 uint16_t comp_status;
989
990 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
991 if (!sp)
992 return;
993
994 sp_bsg = sp->ctx;
995 bsg_job = sp_bsg->u.bsg_job;
996
997 type = NULL;
998 switch (sp_bsg->type) {
999 case SRB_CT_CMD:
1000 type = "ct pass-through";
1001 break;
1002 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001003 ql_log(ql_log_warn, vha, 0x5047,
1004 "Unrecognized SRB: (%p) type=%d.\n", sp, sp_bsg->type);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001005 return;
1006 }
1007
1008 comp_status = le16_to_cpu(pkt->comp_status);
1009
1010 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1011 * fc payload to the caller
1012 */
1013 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1014 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1015
1016 if (comp_status != CS_COMPLETE) {
1017 if (comp_status == CS_DATA_UNDERRUN) {
1018 bsg_job->reply->result = DID_OK << 16;
1019 bsg_job->reply->reply_payload_rcv_len =
1020 le16_to_cpu(((sts_entry_t *)pkt)->rsp_info_len);
1021
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001022 ql_log(ql_log_warn, vha, 0x5048,
1023 "CT pass-through-%s error "
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001024 "comp_status-status=0x%x total_byte = 0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001025 type, comp_status,
1026 bsg_job->reply->reply_payload_rcv_len);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001027 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001028 ql_log(ql_log_warn, vha, 0x5049,
1029 "CT pass-through-%s error "
1030 "comp_status-status=0x%x.\n", type, comp_status);
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001031 bsg_job->reply->result = DID_ERROR << 16;
1032 bsg_job->reply->reply_payload_rcv_len = 0;
1033 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001034 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5035,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001035 (uint8_t *)pkt, sizeof(*pkt));
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001036 } else {
Justin P. Mattock6eab04a2011-04-08 19:49:08 -07001037 bsg_job->reply->result = DID_OK << 16;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001038 bsg_job->reply->reply_payload_rcv_len =
1039 bsg_job->reply_payload.payload_len;
1040 bsg_job->reply_len = 0;
1041 }
1042
1043 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1044 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1045
1046 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
1047 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1048
1049 if (sp_bsg->type == SRB_ELS_CMD_HST || sp_bsg->type == SRB_CT_CMD)
1050 kfree(sp->fcport);
1051
1052 kfree(sp->ctx);
1053 mempool_free(sp, ha->srb_mempool);
1054 bsg_job->job_done(bsg_job);
1055}
1056
1057static void
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001058qla24xx_els_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
1059 struct sts_entry_24xx *pkt, int iocb_type)
1060{
1061 const char func[] = "ELS_CT_IOCB";
1062 const char *type;
1063 struct qla_hw_data *ha = vha->hw;
1064 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001065 struct srb_ctx *sp_bsg;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001066 struct fc_bsg_job *bsg_job;
1067 uint16_t comp_status;
1068 uint32_t fw_status[3];
1069 uint8_t* fw_sts_ptr;
1070
1071 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1072 if (!sp)
1073 return;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001074 sp_bsg = sp->ctx;
1075 bsg_job = sp_bsg->u.bsg_job;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001076
1077 type = NULL;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001078 switch (sp_bsg->type) {
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001079 case SRB_ELS_CMD_RPT:
1080 case SRB_ELS_CMD_HST:
1081 type = "els";
1082 break;
1083 case SRB_CT_CMD:
1084 type = "ct pass-through";
1085 break;
1086 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001087 ql_log(ql_log_warn, vha, 0x503e,
1088 "Unrecognized SRB: (%p) type=%d.\n", sp, sp_bsg->type);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001089 return;
1090 }
1091
1092 comp_status = fw_status[0] = le16_to_cpu(pkt->comp_status);
1093 fw_status[1] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1);
1094 fw_status[2] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2);
1095
1096 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1097 * fc payload to the caller
1098 */
1099 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1100 bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(fw_status);
1101
1102 if (comp_status != CS_COMPLETE) {
1103 if (comp_status == CS_DATA_UNDERRUN) {
1104 bsg_job->reply->result = DID_OK << 16;
1105 bsg_job->reply->reply_payload_rcv_len =
1106 le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->total_byte_count);
1107
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001108 ql_log(ql_log_info, vha, 0x503f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001109 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001110 "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001111 type, sp->handle, comp_status, fw_status[1], fw_status[2],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001112 le16_to_cpu(((struct els_sts_entry_24xx *)
1113 pkt)->total_byte_count));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001114 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1115 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1116 }
1117 else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001118 ql_log(ql_log_info, vha, 0x5040,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001119 "ELS-CT pass-through-%s error hdl=%x comp_status-status=0x%x "
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001120 "error subcode 1=0x%x error subcode 2=0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001121 type, sp->handle, comp_status,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001122 le16_to_cpu(((struct els_sts_entry_24xx *)
1123 pkt)->error_subcode_1),
1124 le16_to_cpu(((struct els_sts_entry_24xx *)
1125 pkt)->error_subcode_2));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001126 bsg_job->reply->result = DID_ERROR << 16;
1127 bsg_job->reply->reply_payload_rcv_len = 0;
1128 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1129 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1130 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001131 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5056,
1132 (uint8_t *)pkt, sizeof(*pkt));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001133 }
1134 else {
Justin P. Mattock6eab04a2011-04-08 19:49:08 -07001135 bsg_job->reply->result = DID_OK << 16;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001136 bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
1137 bsg_job->reply_len = 0;
1138 }
1139
1140 dma_unmap_sg(&ha->pdev->dev,
1141 bsg_job->request_payload.sg_list,
1142 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1143 dma_unmap_sg(&ha->pdev->dev,
1144 bsg_job->reply_payload.sg_list,
1145 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001146 if ((sp_bsg->type == SRB_ELS_CMD_HST) ||
1147 (sp_bsg->type == SRB_CT_CMD))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001148 kfree(sp->fcport);
1149 kfree(sp->ctx);
1150 mempool_free(sp, ha->srb_mempool);
1151 bsg_job->job_done(bsg_job);
1152}
1153
1154static void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001155qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req,
1156 struct logio_entry_24xx *logio)
1157{
1158 const char func[] = "LOGIO-IOCB";
1159 const char *type;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001160 fc_port_t *fcport;
1161 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001162 struct srb_iocb *lio;
1163 struct srb_ctx *ctx;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001164 uint16_t *data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001165 uint32_t iop[2];
1166
1167 sp = qla2x00_get_sp_from_handle(vha, func, req, logio);
1168 if (!sp)
1169 return;
1170
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001171 ctx = sp->ctx;
1172 lio = ctx->u.iocb_cmd;
1173 type = ctx->name;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001174 fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001175 data = lio->u.logio.data;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001176
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001177 data[0] = MBS_COMMAND_ERROR;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001178 data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001179 QLA_LOGIO_LOGIN_RETRIED : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001180 if (logio->entry_status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001181 ql_log(ql_log_warn, vha, 0x5034,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001182 "Async-%s error entry - hdl=%x"
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001183 "portid=%02x%02x%02x entry-status=%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001184 type, sp->handle, fcport->d_id.b.domain,
1185 fcport->d_id.b.area, fcport->d_id.b.al_pa,
1186 logio->entry_status);
1187 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x504d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001188 (uint8_t *)logio, sizeof(*logio));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001189
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001190 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001191 }
1192
1193 if (le16_to_cpu(logio->comp_status) == CS_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001194 ql_dbg(ql_dbg_async, vha, 0x5036,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001195 "Async-%s complete - hdl=%x portid=%02x%02x%02x "
1196 "iop0=%x.\n", type, sp->handle, fcport->d_id.b.domain,
1197 fcport->d_id.b.area, fcport->d_id.b.al_pa,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001198 le32_to_cpu(logio->io_parameter[0]));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001199
1200 data[0] = MBS_COMMAND_COMPLETE;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001201 if (ctx->type != SRB_LOGIN_CMD)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001202 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001203
1204 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1205 if (iop[0] & BIT_4) {
1206 fcport->port_type = FCT_TARGET;
1207 if (iop[0] & BIT_8)
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07001208 fcport->flags |= FCF_FCP2_DEVICE;
Andrew Vasquezb0cd5792010-05-28 15:08:22 -07001209 } else if (iop[0] & BIT_5)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001210 fcport->port_type = FCT_INITIATOR;
Andrew Vasquezb0cd5792010-05-28 15:08:22 -07001211
Andrew Vasquezac280b62009-08-20 11:06:05 -07001212 if (logio->io_parameter[7] || logio->io_parameter[8])
1213 fcport->supported_classes |= FC_COS_CLASS2;
1214 if (logio->io_parameter[9] || logio->io_parameter[10])
1215 fcport->supported_classes |= FC_COS_CLASS3;
1216
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001217 goto logio_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001218 }
1219
1220 iop[0] = le32_to_cpu(logio->io_parameter[0]);
1221 iop[1] = le32_to_cpu(logio->io_parameter[1]);
1222 switch (iop[0]) {
1223 case LSC_SCODE_PORTID_USED:
1224 data[0] = MBS_PORT_ID_USED;
1225 data[1] = LSW(iop[1]);
1226 break;
1227 case LSC_SCODE_NPORT_USED:
1228 data[0] = MBS_LOOP_ID_USED;
1229 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001230 default:
1231 data[0] = MBS_COMMAND_ERROR;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001232 break;
1233 }
1234
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001235 ql_dbg(ql_dbg_async, vha, 0x5037,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001236 "Async-%s failed - hdl=%x portid=%02x%02x%02x comp=%x "
1237 "iop0=%x iop1=%x.\n", type, sp->handle, fcport->d_id.b.domain,
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -07001238 fcport->d_id.b.area, fcport->d_id.b.al_pa,
Andrew Vasquezac280b62009-08-20 11:06:05 -07001239 le16_to_cpu(logio->comp_status),
1240 le32_to_cpu(logio->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001241 le32_to_cpu(logio->io_parameter[1]));
Andrew Vasquezac280b62009-08-20 11:06:05 -07001242
Andrew Vasquez99b0bec2010-05-04 15:01:25 -07001243logio_done:
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001244 lio->done(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001245}
1246
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001247static void
1248qla24xx_tm_iocb_entry(scsi_qla_host_t *vha, struct req_que *req,
1249 struct tsk_mgmt_entry *tsk)
1250{
1251 const char func[] = "TMF-IOCB";
1252 const char *type;
1253 fc_port_t *fcport;
1254 srb_t *sp;
1255 struct srb_iocb *iocb;
1256 struct srb_ctx *ctx;
1257 struct sts_entry_24xx *sts = (struct sts_entry_24xx *)tsk;
1258 int error = 1;
1259
1260 sp = qla2x00_get_sp_from_handle(vha, func, req, tsk);
1261 if (!sp)
1262 return;
1263
1264 ctx = sp->ctx;
1265 iocb = ctx->u.iocb_cmd;
1266 type = ctx->name;
1267 fcport = sp->fcport;
1268
1269 if (sts->entry_status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001270 ql_log(ql_log_warn, vha, 0x5038,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001271 "Async-%s error - hdl=%x entry-status(%x).\n",
1272 type, sp->handle, sts->entry_status);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001273 } else if (sts->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001274 ql_log(ql_log_warn, vha, 0x5039,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001275 "Async-%s error - hdl=%x completion status(%x).\n",
1276 type, sp->handle, sts->comp_status);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001277 } else if (!(le16_to_cpu(sts->scsi_status) &
1278 SS_RESPONSE_INFO_LEN_VALID)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001279 ql_log(ql_log_warn, vha, 0x503a,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001280 "Async-%s error - hdl=%x no response info(%x).\n",
1281 type, sp->handle, sts->scsi_status);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001282 } else if (le32_to_cpu(sts->rsp_data_len) < 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001283 ql_log(ql_log_warn, vha, 0x503b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001284 "Async-%s error - hdl=%x not enough response(%d).\n",
1285 type, sp->handle, sts->rsp_data_len);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001286 } else if (sts->data[3]) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001287 ql_log(ql_log_warn, vha, 0x503c,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001288 "Async-%s error - hdl=%x response(%x).\n",
1289 type, sp->handle, sts->data[3]);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001290 } else {
1291 error = 0;
1292 }
1293
1294 if (error) {
1295 iocb->u.tmf.data = error;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001296 ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x5055,
1297 (uint8_t *)sts, sizeof(*sts));
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001298 }
1299
1300 iocb->done(sp);
1301}
1302
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303/**
1304 * qla2x00_process_response_queue() - Process response queue entries.
1305 * @ha: SCSI driver HA context
1306 */
1307void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001308qla2x00_process_response_queue(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001310 struct scsi_qla_host *vha;
1311 struct qla_hw_data *ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001312 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 sts_entry_t *pkt;
1314 uint16_t handle_cnt;
1315 uint16_t cnt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001316
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001317 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001319 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 return;
1321
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001322 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1323 pkt = (sts_entry_t *)rsp->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001325 rsp->ring_index++;
1326 if (rsp->ring_index == rsp->length) {
1327 rsp->ring_index = 0;
1328 rsp->ring_ptr = rsp->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001330 rsp->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 }
1332
1333 if (pkt->entry_status != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001334 qla2x00_error_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1336 wmb();
1337 continue;
1338 }
1339
1340 switch (pkt->entry_type) {
1341 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001342 qla2x00_status_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 break;
1344 case STATUS_TYPE_21:
1345 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
1346 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001347 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 ((sts21_entry_t *)pkt)->handle[cnt]);
1349 }
1350 break;
1351 case STATUS_TYPE_22:
1352 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
1353 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001354 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 ((sts22_entry_t *)pkt)->handle[cnt]);
1356 }
1357 break;
1358 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001359 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001361 case MBX_IOCB_TYPE:
1362 qla2x00_mbx_iocb_entry(vha, rsp->req,
1363 (struct mbx_entry *)pkt);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001364 break;
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05001365 case CT_IOCB_TYPE:
1366 qla2x00_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
1367 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 default:
1369 /* Type Not Supported. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001370 ql_log(ql_log_warn, vha, 0x504a,
1371 "Received unknown response pkt type %x "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 "entry status=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001373 pkt->entry_type, pkt->entry_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 break;
1375 }
1376 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1377 wmb();
1378 }
1379
1380 /* Adjust ring index */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001381 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382}
1383
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001384static inline void
Andrew Vasquez55442132010-07-23 15:28:27 +05001385qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t par_sense_len,
1386 uint32_t sense_len, struct rsp_que *rsp)
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001387{
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001388 struct scsi_qla_host *vha = sp->fcport->vha;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001389 struct scsi_cmnd *cp = sp->cmd;
1390
1391 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
1392 sense_len = SCSI_SENSE_BUFFERSIZE;
1393
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001394 sp->request_sense_length = sense_len;
1395 sp->request_sense_ptr = cp->sense_buffer;
Andrew Vasquez55442132010-07-23 15:28:27 +05001396 if (sp->request_sense_length > par_sense_len)
1397 sense_len = par_sense_len;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001398
1399 memcpy(cp->sense_buffer, sense_data, sense_len);
1400
1401 sp->request_sense_ptr += sense_len;
1402 sp->request_sense_length -= sense_len;
1403 if (sp->request_sense_length != 0)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001404 rsp->status_srb = sp;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001405
Chad Dupuiscfb09192011-11-18 09:03:07 -08001406 if (sense_len) {
1407 ql_dbg(ql_dbg_io + ql_dbg_buffer, vha, 0x301c,
1408 "Check condition Sense data, nexus%ld:%d:%d cmd=%p.\n",
1409 sp->fcport->vha->host_no, cp->device->id, cp->device->lun,
1410 cp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001411 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302b,
1412 cp->sense_buffer, sense_len);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001413 }
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001414}
1415
Arun Easibad75002010-05-04 15:01:30 -07001416struct scsi_dif_tuple {
1417 __be16 guard; /* Checksum */
1418 __be16 app_tag; /* APPL identifer */
1419 __be32 ref_tag; /* Target LBA or indirect LBA */
1420};
1421
1422/*
1423 * Checks the guard or meta-data for the type of error
1424 * detected by the HBA. In case of errors, we set the
1425 * ASC/ASCQ fields in the sense buffer with ILLEGAL_REQUEST
1426 * to indicate to the kernel that the HBA detected error.
1427 */
Arun Easi8cb20492011-08-16 11:29:22 -07001428static inline int
Arun Easibad75002010-05-04 15:01:30 -07001429qla2x00_handle_dif_error(srb_t *sp, struct sts_entry_24xx *sts24)
1430{
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001431 struct scsi_qla_host *vha = sp->fcport->vha;
Arun Easibad75002010-05-04 15:01:30 -07001432 struct scsi_cmnd *cmd = sp->cmd;
Arun Easi8cb20492011-08-16 11:29:22 -07001433 uint8_t *ap = &sts24->data[12];
1434 uint8_t *ep = &sts24->data[20];
Arun Easibad75002010-05-04 15:01:30 -07001435 uint32_t e_ref_tag, a_ref_tag;
1436 uint16_t e_app_tag, a_app_tag;
1437 uint16_t e_guard, a_guard;
1438
Arun Easi8cb20492011-08-16 11:29:22 -07001439 /*
1440 * swab32 of the "data" field in the beginning of qla2x00_status_entry()
1441 * would make guard field appear at offset 2
1442 */
1443 a_guard = le16_to_cpu(*(uint16_t *)(ap + 2));
1444 a_app_tag = le16_to_cpu(*(uint16_t *)(ap + 0));
1445 a_ref_tag = le32_to_cpu(*(uint32_t *)(ap + 4));
1446 e_guard = le16_to_cpu(*(uint16_t *)(ep + 2));
1447 e_app_tag = le16_to_cpu(*(uint16_t *)(ep + 0));
1448 e_ref_tag = le32_to_cpu(*(uint32_t *)(ep + 4));
Arun Easibad75002010-05-04 15:01:30 -07001449
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001450 ql_dbg(ql_dbg_io, vha, 0x3023,
1451 "iocb(s) %p Returned STATUS.\n", sts24);
Arun Easibad75002010-05-04 15:01:30 -07001452
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001453 ql_dbg(ql_dbg_io, vha, 0x3024,
1454 "DIF ERROR in cmd 0x%x lba 0x%llx act ref"
Arun Easibad75002010-05-04 15:01:30 -07001455 " tag=0x%x, exp ref_tag=0x%x, act app tag=0x%x, exp app"
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001456 " tag=0x%x, act guard=0x%x, exp guard=0x%x.\n",
Arun Easibad75002010-05-04 15:01:30 -07001457 cmd->cmnd[0], (u64)scsi_get_lba(cmd), a_ref_tag, e_ref_tag,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001458 a_app_tag, e_app_tag, a_guard, e_guard);
Arun Easibad75002010-05-04 15:01:30 -07001459
Arun Easi8cb20492011-08-16 11:29:22 -07001460 /*
1461 * Ignore sector if:
1462 * For type 3: ref & app tag is all 'f's
1463 * For type 0,1,2: app tag is all 'f's
1464 */
1465 if ((a_app_tag == 0xffff) &&
1466 ((scsi_get_prot_type(cmd) != SCSI_PROT_DIF_TYPE3) ||
1467 (a_ref_tag == 0xffffffff))) {
1468 uint32_t blocks_done, resid;
1469 sector_t lba_s = scsi_get_lba(cmd);
1470
1471 /* 2TB boundary case covered automatically with this */
1472 blocks_done = e_ref_tag - (uint32_t)lba_s + 1;
1473
1474 resid = scsi_bufflen(cmd) - (blocks_done *
1475 cmd->device->sector_size);
1476
1477 scsi_set_resid(cmd, resid);
1478 cmd->result = DID_OK << 16;
1479
1480 /* Update protection tag */
1481 if (scsi_prot_sg_count(cmd)) {
1482 uint32_t i, j = 0, k = 0, num_ent;
1483 struct scatterlist *sg;
1484 struct sd_dif_tuple *spt;
1485
1486 /* Patch the corresponding protection tags */
1487 scsi_for_each_prot_sg(cmd, sg,
1488 scsi_prot_sg_count(cmd), i) {
1489 num_ent = sg_dma_len(sg) / 8;
1490 if (k + num_ent < blocks_done) {
1491 k += num_ent;
1492 continue;
1493 }
1494 j = blocks_done - k - 1;
1495 k = blocks_done;
1496 break;
1497 }
1498
1499 if (k != blocks_done) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001500 ql_log(ql_log_warn, vha, 0x302f,
Randy Dunlap8ec9c7f2011-09-23 15:40:50 -07001501 "unexpected tag values tag:lba=%x:%llx)\n",
1502 e_ref_tag, (unsigned long long)lba_s);
Arun Easi8cb20492011-08-16 11:29:22 -07001503 return 1;
1504 }
1505
1506 spt = page_address(sg_page(sg)) + sg->offset;
1507 spt += j;
1508
1509 spt->app_tag = 0xffff;
1510 if (scsi_get_prot_type(cmd) == SCSI_PROT_DIF_TYPE3)
1511 spt->ref_tag = 0xffffffff;
1512 }
1513
1514 return 0;
1515 }
1516
Arun Easibad75002010-05-04 15:01:30 -07001517 /* check guard */
1518 if (e_guard != a_guard) {
1519 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1520 0x10, 0x1);
1521 set_driver_byte(cmd, DRIVER_SENSE);
1522 set_host_byte(cmd, DID_ABORT);
1523 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
Arun Easi8cb20492011-08-16 11:29:22 -07001524 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001525 }
1526
Arun Easie02587d2011-08-16 11:29:23 -07001527 /* check ref tag */
1528 if (e_ref_tag != a_ref_tag) {
1529 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1530 0x10, 0x3);
1531 set_driver_byte(cmd, DRIVER_SENSE);
1532 set_host_byte(cmd, DID_ABORT);
1533 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
1534 return 1;
1535 }
1536
Arun Easibad75002010-05-04 15:01:30 -07001537 /* check appl tag */
1538 if (e_app_tag != a_app_tag) {
1539 scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
1540 0x10, 0x2);
1541 set_driver_byte(cmd, DRIVER_SENSE);
1542 set_host_byte(cmd, DID_ABORT);
1543 cmd->result |= SAM_STAT_CHECK_CONDITION << 1;
Arun Easi8cb20492011-08-16 11:29:22 -07001544 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001545 }
1546
Arun Easi8cb20492011-08-16 11:29:22 -07001547 return 1;
Arun Easibad75002010-05-04 15:01:30 -07001548}
1549
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550/**
1551 * qla2x00_status_entry() - Process a Status IOCB entry.
1552 * @ha: SCSI driver HA context
1553 * @pkt: Entry pointer
1554 */
1555static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001556qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 fc_port_t *fcport;
1560 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001561 sts_entry_t *sts;
1562 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 uint16_t comp_status;
1564 uint16_t scsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001565 uint16_t ox_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 uint8_t lscsi_status;
1567 int32_t resid;
Andrew Vasquez55442132010-07-23 15:28:27 +05001568 uint32_t sense_len, par_sense_len, rsp_info_len, resid_len,
1569 fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001570 uint8_t *rsp_info, *sense_data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001571 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001572 uint32_t handle;
1573 uint16_t que;
1574 struct req_que *req;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001575 int logit = 1;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001576
1577 sts = (sts_entry_t *) pkt;
1578 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001579 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001580 comp_status = le16_to_cpu(sts24->comp_status);
1581 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
1582 } else {
1583 comp_status = le16_to_cpu(sts->comp_status);
1584 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1585 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001586 handle = (uint32_t) LSW(sts->handle);
1587 que = MSW(sts->handle);
1588 req = ha->req_q_map[que];
Giridhar Malavalia9083012010-04-12 17:59:55 -07001589
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001591 if (comp_status == CS_COMPLETE && scsi_status == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001592 qla2x00_process_completed_request(vha, req, handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
1594 return;
1595 }
1596
1597 /* Validate handle. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001598 if (handle < MAX_OUTSTANDING_COMMANDS) {
1599 sp = req->outstanding_cmds[handle];
1600 req->outstanding_cmds[handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 } else
1602 sp = NULL;
1603
1604 if (sp == NULL) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001605 ql_dbg(ql_dbg_io, vha, 0x3017,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001606 "Invalid status handle (0x%x).\n", sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001608 if (IS_QLA82XX(ha))
1609 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1610 else
1611 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001612 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 return;
1614 }
1615 cp = sp->cmd;
1616 if (cp == NULL) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001617 ql_dbg(ql_dbg_io, vha, 0x3018,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001618 "Command already returned (0x%x/%p).\n",
1619 sts->handle, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
1621 return;
1622 }
1623
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001624 lscsi_status = scsi_status & STATUS_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625
bdf79622005-04-17 15:06:53 -05001626 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001628 ox_id = 0;
Andrew Vasquez55442132010-07-23 15:28:27 +05001629 sense_len = par_sense_len = rsp_info_len = resid_len =
1630 fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001631 if (IS_FWI2_CAPABLE(ha)) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001632 if (scsi_status & SS_SENSE_LEN_VALID)
1633 sense_len = le32_to_cpu(sts24->sense_len);
1634 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
1635 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
1636 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER))
1637 resid_len = le32_to_cpu(sts24->rsp_residual_count);
1638 if (comp_status == CS_DATA_UNDERRUN)
1639 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001640 rsp_info = sts24->data;
1641 sense_data = sts24->data;
1642 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001643 ox_id = le16_to_cpu(sts24->ox_id);
Andrew Vasquez55442132010-07-23 15:28:27 +05001644 par_sense_len = sizeof(sts24->data);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001645 } else {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001646 if (scsi_status & SS_SENSE_LEN_VALID)
1647 sense_len = le16_to_cpu(sts->req_sense_length);
1648 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID)
1649 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001650 resid_len = le32_to_cpu(sts->residual_length);
1651 rsp_info = sts->rsp_info;
1652 sense_data = sts->req_sense_data;
Andrew Vasquez55442132010-07-23 15:28:27 +05001653 par_sense_len = sizeof(sts->req_sense_data);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001654 }
1655
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 /* Check for any FCP transport errors. */
1657 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001658 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasquez55442132010-07-23 15:28:27 +05001659 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001660 sense_data += rsp_info_len;
Andrew Vasquez55442132010-07-23 15:28:27 +05001661 par_sense_len -= rsp_info_len;
1662 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001663 if (rsp_info_len > 3 && rsp_info[3]) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001664 ql_dbg(ql_dbg_io, vha, 0x3019,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001665 "FCP I/O protocol failure (0x%x/0x%x).\n",
1666 rsp_info_len, rsp_info[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
1668 cp->result = DID_BUS_BUSY << 16;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001669 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 }
1671 }
1672
Andrew Vasquez3e8ce322008-02-28 14:06:10 -08001673 /* Check for overrun. */
1674 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
1675 scsi_status & SS_RESIDUAL_OVER)
1676 comp_status = CS_DATA_OVERRUN;
1677
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 /*
1679 * Based on Host and scsi status generate status code for Linux
1680 */
1681 switch (comp_status) {
1682 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001683 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 if (scsi_status == 0) {
1685 cp->result = DID_OK << 16;
1686 break;
1687 }
1688 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001689 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001690 scsi_set_resid(cp, resid);
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001691
1692 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001693 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001694 cp->underflow)) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001695 ql_dbg(ql_dbg_io, vha, 0x301a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001696 "Mid-layer underflow "
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001697 "detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001698 resid, scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001699
1700 cp->result = DID_ERROR << 16;
1701 break;
1702 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 cp->result = DID_OK << 16 | lscsi_status;
1705
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001706 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001707 ql_dbg(ql_dbg_io, vha, 0x301b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001708 "QUEUE FULL detected.\n");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001709 break;
1710 }
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001711 logit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 if (lscsi_status != SS_CHECK_CONDITION)
1713 break;
1714
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001715 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 if (!(scsi_status & SS_SENSE_LEN_VALID))
1717 break;
1718
Andrew Vasquez55442132010-07-23 15:28:27 +05001719 qla2x00_handle_sense(sp, sense_data, par_sense_len, sense_len,
1720 rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 break;
1722
1723 case CS_DATA_UNDERRUN:
Ravi Ananded17c712006-05-17 15:08:55 -07001724 /* Use F/W calculated residual length. */
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001725 resid = IS_FWI2_CAPABLE(ha) ? fw_resid_len : resid_len;
1726 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 if (scsi_status & SS_RESIDUAL_UNDER) {
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001728 if (IS_FWI2_CAPABLE(ha) && fw_resid_len != resid_len) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001729 ql_dbg(ql_dbg_io, vha, 0x301d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001730 "Dropped frame(s) detected "
1731 "(0x%x of 0x%x bytes).\n",
1732 resid, scsi_bufflen(cp));
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08001733
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001734 cp->result = DID_ERROR << 16 | lscsi_status;
Arun Easi4e85e3d2011-11-18 09:02:10 -08001735 goto check_scsi_status;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001736 }
1737
1738 if (!lscsi_status &&
1739 ((unsigned)(scsi_bufflen(cp) - resid) <
1740 cp->underflow)) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001741 ql_dbg(ql_dbg_io, vha, 0x301e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001742 "Mid-layer underflow "
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001743 "detected (0x%x of 0x%x bytes).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001744 resid, scsi_bufflen(cp));
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001745
1746 cp->result = DID_ERROR << 16;
1747 break;
1748 }
Lalit Chandivade0374f552010-09-03 14:57:04 -07001749 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001750 ql_dbg(ql_dbg_io, vha, 0x301f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001751 "Dropped frame(s) detected (0x%x "
1752 "of 0x%x bytes).\n", resid, scsi_bufflen(cp));
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001753
Lalit Chandivade0374f552010-09-03 14:57:04 -07001754 cp->result = DID_ERROR << 16 | lscsi_status;
1755 goto check_scsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 }
1757
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001758 cp->result = DID_OK << 16 | lscsi_status;
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001759 logit = 0;
Lalit Chandivade0f00a202009-10-13 15:16:52 -07001760
Lalit Chandivade0374f552010-09-03 14:57:04 -07001761check_scsi_status:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001763 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 * Status.
1765 */
1766 if (lscsi_status != 0) {
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001767 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001768 ql_dbg(ql_dbg_io, vha, 0x3020,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001769 "QUEUE FULL detected.\n");
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001770 logit = 1;
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001771 break;
1772 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 if (lscsi_status != SS_CHECK_CONDITION)
1774 break;
1775
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001776 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 if (!(scsi_status & SS_SENSE_LEN_VALID))
1778 break;
1779
Andrew Vasquez55442132010-07-23 15:28:27 +05001780 qla2x00_handle_sense(sp, sense_data, par_sense_len,
1781 sense_len, rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 }
1783 break;
1784
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 case CS_PORT_LOGGED_OUT:
1786 case CS_PORT_CONFIG_CHG:
1787 case CS_PORT_BUSY:
1788 case CS_INCOMPLETE:
1789 case CS_PORT_UNAVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 case CS_TIMEOUT:
Chad Dupuisff454b02010-10-15 11:27:42 -07001791 case CS_RESET:
1792
Mike Christie056a4482008-08-19 18:45:29 -05001793 /*
1794 * We are going to have the fc class block the rport
1795 * while we try to recover so instruct the mid layer
1796 * to requeue until the class decides how to handle this.
1797 */
1798 cp->result = DID_TRANSPORT_DISRUPTED << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001800 if (comp_status == CS_TIMEOUT) {
1801 if (IS_FWI2_CAPABLE(ha))
1802 break;
1803 else if ((le16_to_cpu(sts->status_flags) &
1804 SF_LOGOUT_SENT) == 0)
1805 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001807
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001808 ql_dbg(ql_dbg_io, vha, 0x3021,
1809 "Port down status: port-state=0x%x.\n",
1810 atomic_read(&fcport->state));
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001811
1812 if (atomic_read(&fcport->state) == FCS_ONLINE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001813 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 break;
1815
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001816 case CS_ABORTED:
1817 cp->result = DID_RESET << 16;
1818 break;
Arun Easibad75002010-05-04 15:01:30 -07001819
1820 case CS_DIF_ERROR:
Arun Easi8cb20492011-08-16 11:29:22 -07001821 logit = qla2x00_handle_dif_error(sp, sts24);
Arun Easibad75002010-05-04 15:01:30 -07001822 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 cp->result = DID_ERROR << 16;
1825 break;
1826 }
1827
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001828out:
1829 if (logit)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001830 ql_dbg(ql_dbg_io, vha, 0x3022,
1831 "FCP command status: 0x%x-0x%x (0x%x) "
Chad Dupuiscfb09192011-11-18 09:03:07 -08001832 "nexus=%ld:%d:%d portid=%02x%02x%02x oxid=0x%x "
1833 "cdb=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x len=0x%x "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001834 "rsp_info=0x%x resid=0x%x fw_resid=0x%x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001835 comp_status, scsi_status, cp->result, vha->host_no,
1836 cp->device->id, cp->device->lun, fcport->d_id.b.domain,
1837 fcport->d_id.b.area, fcport->d_id.b.al_pa, ox_id,
1838 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1839 cp->cmnd[4], cp->cmnd[5], cp->cmnd[6], cp->cmnd[7],
1840 cp->cmnd[8], cp->cmnd[9], scsi_bufflen(cp), rsp_info_len,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001841 resid_len, fw_resid_len);
Andrew Vasquezb7d22802010-05-04 15:01:27 -07001842
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001843 if (rsp->status_srb == NULL)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001844 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845}
1846
1847/**
1848 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1849 * @ha: SCSI driver HA context
1850 * @pkt: Entry pointer
1851 *
1852 * Extended sense data.
1853 */
1854static void
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001855qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856{
1857 uint8_t sense_sz = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001858 struct qla_hw_data *ha = rsp->hw;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001859 struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001860 srb_t *sp = rsp->status_srb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 struct scsi_cmnd *cp;
1862
1863 if (sp != NULL && sp->request_sense_length != 0) {
1864 cp = sp->cmd;
1865 if (cp == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001866 ql_log(ql_log_warn, vha, 0x3025,
1867 "cmd is NULL: already returned to OS (sp=%p).\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001868 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001870 rsp->status_srb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 return;
1872 }
1873
1874 if (sp->request_sense_length > sizeof(pkt->data)) {
1875 sense_sz = sizeof(pkt->data);
1876 } else {
1877 sense_sz = sp->request_sense_length;
1878 }
1879
1880 /* Move sense data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001881 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001882 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001884 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302c,
1885 sp->request_sense_ptr, sense_sz);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
1887 sp->request_sense_ptr += sense_sz;
1888 sp->request_sense_length -= sense_sz;
1889
1890 /* Place command on done queue. */
1891 if (sp->request_sense_length == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001892 rsp->status_srb = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001893 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 }
1895 }
1896}
1897
Giridhar Malavalic4631192011-11-18 09:03:08 -08001898static int
1899qla2x00_free_sp_ctx(scsi_qla_host_t *vha, srb_t *sp)
1900{
1901 struct qla_hw_data *ha = vha->hw;
1902 struct srb_ctx *ctx;
1903
1904 if (!sp->ctx)
1905 return 1;
1906
1907 ctx = sp->ctx;
1908
1909 if (ctx->type == SRB_LOGIN_CMD ||
1910 ctx->type == SRB_LOGOUT_CMD ||
1911 ctx->type == SRB_TM_CMD) {
1912 ctx->u.iocb_cmd->done(sp);
1913 return 0;
1914 } else if (ctx->type == SRB_ADISC_CMD) {
1915 ctx->u.iocb_cmd->free(sp);
1916 return 0;
1917 } else {
1918 struct fc_bsg_job *bsg_job;
1919
1920 bsg_job = ctx->u.bsg_job;
1921 if (ctx->type == SRB_ELS_CMD_HST ||
1922 ctx->type == SRB_CT_CMD)
1923 kfree(sp->fcport);
1924
1925 bsg_job->reply->reply_data.ctels_reply.status =
1926 FC_CTELS_STATUS_OK;
1927 bsg_job->reply->result = DID_ERROR << 16;
1928 bsg_job->reply->reply_payload_rcv_len = 0;
1929 kfree(sp->ctx);
1930 mempool_free(sp, ha->srb_mempool);
1931 bsg_job->job_done(bsg_job);
1932 return 0;
1933 }
1934 return 1;
1935}
1936
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937/**
1938 * qla2x00_error_entry() - Process an error entry.
1939 * @ha: SCSI driver HA context
1940 * @pkt: Entry pointer
1941 */
1942static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001943qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944{
1945 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001946 struct qla_hw_data *ha = vha->hw;
Giridhar Malavalic4631192011-11-18 09:03:08 -08001947 const char func[] = "ERROR-IOCB";
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001948 uint16_t que = MSW(pkt->handle);
1949 struct req_que *req = ha->req_q_map[que];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001950
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 if (pkt->entry_status & RF_INV_E_ORDER)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001952 ql_dbg(ql_dbg_async, vha, 0x502a,
1953 "Invalid Entry Order.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 else if (pkt->entry_status & RF_INV_E_COUNT)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001955 ql_dbg(ql_dbg_async, vha, 0x502b,
1956 "Invalid Entry Count.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 else if (pkt->entry_status & RF_INV_E_PARAM)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001958 ql_dbg(ql_dbg_async, vha, 0x502c,
1959 "Invalid Entry Parameter.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 else if (pkt->entry_status & RF_INV_E_TYPE)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001961 ql_dbg(ql_dbg_async, vha, 0x502d,
1962 "Invalid Entry Type.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 else if (pkt->entry_status & RF_BUSY)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001964 ql_dbg(ql_dbg_async, vha, 0x502e,
1965 "Busy.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001967 ql_dbg(ql_dbg_async, vha, 0x502f,
1968 "UNKNOWN flag error.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969
Giridhar Malavalic4631192011-11-18 09:03:08 -08001970 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 if (sp) {
Giridhar Malavalic4631192011-11-18 09:03:08 -08001972 if (qla2x00_free_sp_ctx(vha, sp)) {
1973 if (pkt->entry_status &
1974 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1975 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1976 sp->cmd->result = DID_ERROR << 16;
1977 } else if (pkt->entry_status & RF_BUSY) {
1978 sp->cmd->result = DID_BUS_BUSY << 16;
1979 } else {
1980 sp->cmd->result = DID_ERROR << 16;
1981 }
1982 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001984 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001985 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7
1986 || pkt->entry_type == COMMAND_TYPE_6) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001987 ql_log(ql_log_warn, vha, 0x5030,
1988 "Error entry - invalid handle.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07001990 if (IS_QLA82XX(ha))
1991 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
1992 else
1993 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001994 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 }
1996}
1997
1998/**
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001999 * qla24xx_mbx_completion() - Process mailbox command completions.
2000 * @ha: SCSI driver HA context
2001 * @mb0: Mailbox0 register
2002 */
2003static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002004qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002005{
2006 uint16_t cnt;
2007 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002008 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002009 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2010
2011 /* Load return mailbox registers. */
2012 ha->flags.mbox_int = 1;
2013 ha->mailbox_out[0] = mb0;
2014 wptr = (uint16_t __iomem *)&reg->mailbox1;
2015
2016 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
2017 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
2018 wptr++;
2019 }
2020
Chad Dupuiscfb09192011-11-18 09:03:07 -08002021 if (!ha->mcp)
2022 ql_dbg(ql_dbg_async, vha, 0x504e, "MBX pointer ERRROR.\n");
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002023}
2024
2025/**
2026 * qla24xx_process_response_queue() - Process response queue entries.
2027 * @ha: SCSI driver HA context
2028 */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002029void qla24xx_process_response_queue(struct scsi_qla_host *vha,
2030 struct rsp_que *rsp)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002031{
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002032 struct sts_entry_24xx *pkt;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002033 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002034
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002035 if (!vha->flags.online)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002036 return;
2037
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002038 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
2039 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002040
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002041 rsp->ring_index++;
2042 if (rsp->ring_index == rsp->length) {
2043 rsp->ring_index = 0;
2044 rsp->ring_ptr = rsp->ring;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002045 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002046 rsp->ring_ptr++;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002047 }
2048
2049 if (pkt->entry_status != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002050 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002051 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2052 wmb();
2053 continue;
2054 }
2055
2056 switch (pkt->entry_type) {
2057 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002058 qla2x00_status_entry(vha, rsp, pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002059 break;
2060 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002061 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002062 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002063 case VP_RPT_ID_IOCB_TYPE:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002064 qla24xx_report_id_acquisition(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002065 (struct vp_rpt_id_entry_24xx *)pkt);
2066 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07002067 case LOGINOUT_PORT_IOCB_TYPE:
2068 qla24xx_logio_entry(vha, rsp->req,
2069 (struct logio_entry_24xx *)pkt);
2070 break;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07002071 case TSK_MGMT_IOCB_TYPE:
2072 qla24xx_tm_iocb_entry(vha, rsp->req,
2073 (struct tsk_mgmt_entry *)pkt);
2074 break;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002075 case CT_IOCB_TYPE:
2076 qla24xx_els_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
2077 clear_bit(MBX_INTERRUPT, &vha->hw->mbx_cmd_flags);
2078 break;
2079 case ELS_IOCB_TYPE:
2080 qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE);
2081 break;
Saurav Kashyap54883292011-08-16 11:31:48 -07002082 case MARKER_TYPE:
2083 /* Do nothing in this case, this check is to prevent it
2084 * from falling into default case
2085 */
2086 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002087 default:
2088 /* Type Not Supported. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002089 ql_dbg(ql_dbg_async, vha, 0x5042,
2090 "Received unknown response pkt type %x "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002091 "entry status=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002092 pkt->entry_type, pkt->entry_status);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002093 break;
2094 }
2095 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
2096 wmb();
2097 }
2098
2099 /* Adjust ring index */
Giridhar Malavalia9083012010-04-12 17:59:55 -07002100 if (IS_QLA82XX(ha)) {
2101 struct device_reg_82xx __iomem *reg = &ha->iobase->isp82;
2102 WRT_REG_DWORD(&reg->rsp_q_out[0], rsp->ring_index);
2103 } else
2104 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002105}
2106
Andrew Vasquez05236a02007-09-20 14:07:37 -07002107static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002108qla2xxx_check_risc_status(scsi_qla_host_t *vha)
Andrew Vasquez05236a02007-09-20 14:07:37 -07002109{
2110 int rval;
2111 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002112 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez05236a02007-09-20 14:07:37 -07002113 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2114
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002115 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez05236a02007-09-20 14:07:37 -07002116 return;
2117
2118 rval = QLA_SUCCESS;
2119 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
2120 RD_REG_DWORD(&reg->iobase_addr);
2121 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
2122 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
2123 rval == QLA_SUCCESS; cnt--) {
2124 if (cnt) {
2125 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
2126 udelay(10);
2127 } else
2128 rval = QLA_FUNCTION_TIMEOUT;
2129 }
2130 if (rval == QLA_SUCCESS)
2131 goto next_test;
2132
2133 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
2134 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
2135 rval == QLA_SUCCESS; cnt--) {
2136 if (cnt) {
2137 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
2138 udelay(10);
2139 } else
2140 rval = QLA_FUNCTION_TIMEOUT;
2141 }
2142 if (rval != QLA_SUCCESS)
2143 goto done;
2144
2145next_test:
2146 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002147 ql_log(ql_log_info, vha, 0x504c,
2148 "Additional code -- 0x55AA.\n");
Andrew Vasquez05236a02007-09-20 14:07:37 -07002149
2150done:
2151 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
2152 RD_REG_DWORD(&reg->iobase_window);
2153}
2154
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002155/**
2156 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
2157 * @irq:
2158 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002159 *
2160 * Called by system whenever the host adapter generates an interrupt.
2161 *
2162 * Returns handled flag.
2163 */
2164irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01002165qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002166{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002167 scsi_qla_host_t *vha;
2168 struct qla_hw_data *ha;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002169 struct device_reg_24xx __iomem *reg;
2170 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002171 unsigned long iter;
2172 uint32_t stat;
2173 uint32_t hccr;
2174 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002175 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002176 unsigned long flags;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002177
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002178 rsp = (struct rsp_que *) dev_id;
2179 if (!rsp) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002180 printk(KERN_INFO
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002181 "%s(): NULL response queue pointer.\n", __func__);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002182 return IRQ_NONE;
2183 }
2184
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002185 ha = rsp->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002186 reg = &ha->iobase->isp24;
2187 status = 0;
2188
Andrew Vasquez85880802009-12-15 21:29:46 -08002189 if (unlikely(pci_channel_offline(ha->pdev)))
2190 return IRQ_HANDLED;
2191
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002192 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002193 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002194 for (iter = 50; iter--; ) {
2195 stat = RD_REG_DWORD(&reg->host_status);
2196 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08002197 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07002198 break;
2199
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002200 hccr = RD_REG_DWORD(&reg->hccr);
2201
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002202 ql_log(ql_log_warn, vha, 0x504b,
2203 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2204 hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002205
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002206 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002207
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002208 ha->isp_ops->fw_dump(vha, 1);
2209 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002210 break;
2211 } else if ((stat & HSRX_RISC_INT) == 0)
2212 break;
2213
2214 switch (stat & 0xff) {
2215 case 0x1:
2216 case 0x2:
2217 case 0x10:
2218 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002219 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002220 status |= MBX_INTERRUPT;
2221
2222 break;
2223 case 0x12:
2224 mb[0] = MSW(stat);
2225 mb[1] = RD_REG_WORD(&reg->mailbox1);
2226 mb[2] = RD_REG_WORD(&reg->mailbox2);
2227 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002228 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002229 break;
2230 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002231 case 0x14:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002232 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002233 break;
2234 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002235 ql_dbg(ql_dbg_async, vha, 0x504f,
2236 "Unrecognized interrupt type (%d).\n", stat * 0xff);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002237 break;
2238 }
2239 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2240 RD_REG_DWORD_RELAXED(&reg->hccr);
2241 }
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07002242 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002243
2244 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
2245 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002246 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002247 complete(&ha->mbx_intr_comp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07002248 }
2249
2250 return IRQ_HANDLED;
2251}
2252
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002253static irqreturn_t
2254qla24xx_msix_rsp_q(int irq, void *dev_id)
2255{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002256 struct qla_hw_data *ha;
2257 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002258 struct device_reg_24xx __iomem *reg;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002259 struct scsi_qla_host *vha;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002260 unsigned long flags;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002261
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002262 rsp = (struct rsp_que *) dev_id;
2263 if (!rsp) {
2264 printk(KERN_INFO
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002265 "%s(): NULL response queue pointer.\n", __func__);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002266 return IRQ_NONE;
2267 }
2268 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002269 reg = &ha->iobase->isp24;
2270
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002271 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002272
Anirban Chakrabortya67093d2010-02-04 14:17:59 -08002273 vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002274 qla24xx_process_response_queue(vha, rsp);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002275 if (!ha->flags.disable_msix_handshake) {
Anirban Chakrabortyeb941142009-08-04 16:12:13 -07002276 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2277 RD_REG_DWORD_RELAXED(&reg->hccr);
2278 }
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002279 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002280
2281 return IRQ_HANDLED;
2282}
2283
2284static irqreturn_t
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002285qla25xx_msix_rsp_q(int irq, void *dev_id)
2286{
2287 struct qla_hw_data *ha;
2288 struct rsp_que *rsp;
Anirban Chakraborty31557542009-12-02 10:36:55 -08002289 struct device_reg_24xx __iomem *reg;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002290 unsigned long flags;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002291
2292 rsp = (struct rsp_que *) dev_id;
2293 if (!rsp) {
2294 printk(KERN_INFO
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002295 "%s(): NULL response queue pointer.\n", __func__);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002296 return IRQ_NONE;
2297 }
2298 ha = rsp->hw;
2299
Anirban Chakraborty31557542009-12-02 10:36:55 -08002300 /* Clear the interrupt, if enabled, for this response queue */
Andrew Vasquezd4247542011-10-26 14:20:13 -07002301 if (!ha->flags.disable_msix_handshake) {
Anirban Chakraborty31557542009-12-02 10:36:55 -08002302 reg = &ha->iobase->isp24;
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002303 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002304 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
2305 RD_REG_DWORD_RELAXED(&reg->hccr);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002306 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002307 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002308 queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work);
2309
2310 return IRQ_HANDLED;
2311}
2312
2313static irqreturn_t
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002314qla24xx_msix_default(int irq, void *dev_id)
2315{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002316 scsi_qla_host_t *vha;
2317 struct qla_hw_data *ha;
2318 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002319 struct device_reg_24xx __iomem *reg;
2320 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002321 uint32_t stat;
2322 uint32_t hccr;
2323 uint16_t mb[4];
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002324 unsigned long flags;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002325
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002326 rsp = (struct rsp_que *) dev_id;
2327 if (!rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002328 printk(KERN_INFO
2329 "%s(): NULL response queue pointer.\n", __func__);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002330 return IRQ_NONE;
2331 }
2332 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002333 reg = &ha->iobase->isp24;
2334 status = 0;
2335
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002336 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002337 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002338 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002339 stat = RD_REG_DWORD(&reg->host_status);
2340 if (stat & HSRX_RISC_PAUSED) {
Andrew Vasquez85880802009-12-15 21:29:46 -08002341 if (unlikely(pci_channel_offline(ha->pdev)))
Seokmann Ju14e660e2007-09-20 14:07:36 -07002342 break;
2343
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002344 hccr = RD_REG_DWORD(&reg->hccr);
2345
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002346 ql_log(ql_log_info, vha, 0x5050,
2347 "RISC paused -- HCCR=%x, Dumping firmware.\n",
2348 hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002349
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002350 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07002351
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002352 ha->isp_ops->fw_dump(vha, 1);
2353 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002354 break;
2355 } else if ((stat & HSRX_RISC_INT) == 0)
2356 break;
2357
2358 switch (stat & 0xff) {
2359 case 0x1:
2360 case 0x2:
2361 case 0x10:
2362 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002363 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002364 status |= MBX_INTERRUPT;
2365
2366 break;
2367 case 0x12:
2368 mb[0] = MSW(stat);
2369 mb[1] = RD_REG_WORD(&reg->mailbox1);
2370 mb[2] = RD_REG_WORD(&reg->mailbox2);
2371 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002372 qla2x00_async_event(vha, rsp, mb);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002373 break;
2374 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002375 case 0x14:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002376 qla24xx_process_response_queue(vha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002377 break;
2378 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002379 ql_dbg(ql_dbg_async, vha, 0x5051,
2380 "Unrecognized interrupt type (%d).\n", stat & 0xff);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002381 break;
2382 }
2383 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07002384 } while (0);
Xiaotian Feng0f19bc62010-01-29 18:09:30 +08002385 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002386
2387 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
2388 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002389 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002390 complete(&ha->mbx_intr_comp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002391 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002392 return IRQ_HANDLED;
2393}
2394
2395/* Interrupt handling helpers. */
2396
2397struct qla_init_msix_entry {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002398 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07002399 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002400};
2401
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002402static struct qla_init_msix_entry msix_entries[3] = {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002403 { "qla2xxx (default)", qla24xx_msix_default },
2404 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002405 { "qla2xxx (multiq)", qla25xx_msix_rsp_q },
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002406};
2407
Giridhar Malavalia9083012010-04-12 17:59:55 -07002408static struct qla_init_msix_entry qla82xx_msix_entries[2] = {
2409 { "qla2xxx (default)", qla82xx_msix_default },
2410 { "qla2xxx (rsp_q)", qla82xx_msix_rsp_q },
2411};
2412
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002413static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002414qla24xx_disable_msix(struct qla_hw_data *ha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002415{
2416 int i;
2417 struct qla_msix_entry *qentry;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002418 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002419
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002420 for (i = 0; i < ha->msix_count; i++) {
2421 qentry = &ha->msix_entries[i];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002422 if (qentry->have_irq)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002423 free_irq(qentry->vector, qentry->rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002424 }
2425 pci_disable_msix(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002426 kfree(ha->msix_entries);
2427 ha->msix_entries = NULL;
2428 ha->flags.msix_enabled = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002429 ql_dbg(ql_dbg_init, vha, 0x0042,
2430 "Disabled the MSI.\n");
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002431}
2432
2433static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002434qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002435{
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002436#define MIN_MSIX_COUNT 2
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002437 int i, ret;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002438 struct msix_entry *entries;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002439 struct qla_msix_entry *qentry;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002440 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002441
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002442 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002443 GFP_KERNEL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002444 if (!entries) {
2445 ql_log(ql_log_warn, vha, 0x00bc,
2446 "Failed to allocate memory for msix_entry.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002447 return -ENOMEM;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002448 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002449
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002450 for (i = 0; i < ha->msix_count; i++)
2451 entries[i].entry = i;
2452
2453 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002454 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002455 if (ret < MIN_MSIX_COUNT)
2456 goto msix_failed;
2457
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002458 ql_log(ql_log_warn, vha, 0x00c6,
2459 "MSI-X: Failed to enable support "
2460 "-- %d/%d\n Retry with %d vectors.\n",
2461 ha->msix_count, ret, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002462 ha->msix_count = ret;
2463 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
2464 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08002465msix_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002466 ql_log(ql_log_fatal, vha, 0x00c7,
2467 "MSI-X: Failed to enable support, "
2468 "giving up -- %d/%d.\n",
2469 ha->msix_count, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002470 goto msix_out;
2471 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002472 ha->max_rsp_queues = ha->msix_count - 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002473 }
2474 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
2475 ha->msix_count, GFP_KERNEL);
2476 if (!ha->msix_entries) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002477 ql_log(ql_log_fatal, vha, 0x00c8,
2478 "Failed to allocate memory for ha->msix_entries.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002479 ret = -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002480 goto msix_out;
2481 }
2482 ha->flags.msix_enabled = 1;
2483
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002484 for (i = 0; i < ha->msix_count; i++) {
2485 qentry = &ha->msix_entries[i];
2486 qentry->vector = entries[i].vector;
2487 qentry->entry = entries[i].entry;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002488 qentry->have_irq = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002489 qentry->rsp = NULL;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002490 }
2491
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002492 /* Enable MSI-X vectors for the base queue */
2493 for (i = 0; i < 2; i++) {
2494 qentry = &ha->msix_entries[i];
Giridhar Malavalia9083012010-04-12 17:59:55 -07002495 if (IS_QLA82XX(ha)) {
2496 ret = request_irq(qentry->vector,
2497 qla82xx_msix_entries[i].handler,
2498 0, qla82xx_msix_entries[i].name, rsp);
2499 } else {
2500 ret = request_irq(qentry->vector,
2501 msix_entries[i].handler,
2502 0, msix_entries[i].name, rsp);
2503 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002504 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002505 ql_log(ql_log_fatal, vha, 0x00cb,
2506 "MSI-X: unable to register handler -- %x/%d.\n",
2507 qentry->vector, ret);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002508 qla24xx_disable_msix(ha);
2509 ha->mqenable = 0;
2510 goto msix_out;
2511 }
2512 qentry->have_irq = 1;
2513 qentry->rsp = rsp;
2514 rsp->msix = qentry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002515 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002516
2517 /* Enable MSI-X vector for response queue update for queue 0 */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002518 if (ha->mqiobase && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002519 ha->mqenable = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002520 ql_dbg(ql_dbg_multiq, vha, 0xc005,
2521 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
2522 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
2523 ql_dbg(ql_dbg_init, vha, 0x0055,
2524 "mqiobase=%p, max_rsp_queues=%d, max_req_queues=%d.\n",
2525 ha->mqiobase, ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002526
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002527msix_out:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002528 kfree(entries);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002529 return ret;
2530}
2531
2532int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002533qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002534{
2535 int ret;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002536 device_reg_t __iomem *reg = ha->iobase;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002537 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002538
2539 /* If possible, enable MSI-X. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002540 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) &&
Giridhar Malavalia9083012010-04-12 17:59:55 -07002541 !IS_QLA8432(ha) && !IS_QLA8XXX_TYPE(ha))
Ben Hutchings6377a7a2010-03-19 16:59:19 -07002542 goto skip_msi;
2543
2544 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
2545 (ha->pdev->subsystem_device == 0x7040 ||
2546 ha->pdev->subsystem_device == 0x7041 ||
2547 ha->pdev->subsystem_device == 0x1705)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002548 ql_log(ql_log_warn, vha, 0x0034,
2549 "MSI-X: Unsupported ISP 2432 SSVID/SSDID (0x%X,0x%X).\n",
Ben Hutchings6377a7a2010-03-19 16:59:19 -07002550 ha->pdev->subsystem_vendor,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002551 ha->pdev->subsystem_device);
Ben Hutchings6377a7a2010-03-19 16:59:19 -07002552 goto skip_msi;
2553 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002554
Chad Dupuis42cd4f52011-08-16 11:29:24 -07002555 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002556 ql_log(ql_log_warn, vha, 0x0035,
2557 "MSI-X; Unsupported ISP2432 (0x%X, 0x%X).\n",
Chad Dupuis42cd4f52011-08-16 11:29:24 -07002558 ha->pdev->revision, QLA_MSIX_CHIP_REV_24XX);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002559 goto skip_msix;
2560 }
2561
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002562 ret = qla24xx_enable_msix(ha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002563 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002564 ql_dbg(ql_dbg_init, vha, 0x0036,
2565 "MSI-X: Enabled (0x%X, 0x%X).\n",
2566 ha->chip_revision, ha->fw_attributes);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002567 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002568 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002569 ql_log(ql_log_info, vha, 0x0037,
2570 "MSI-X Falling back-to MSI mode -%d.\n", ret);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002571skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002572
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002573 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
2574 !IS_QLA8001(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002575 goto skip_msi;
2576
2577 ret = pci_enable_msi(ha->pdev);
2578 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002579 ql_dbg(ql_dbg_init, vha, 0x0038,
2580 "MSI: Enabled.\n");
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002581 ha->flags.msi_enabled = 1;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002582 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002583 ql_log(ql_log_warn, vha, 0x0039,
2584 "MSI-X; Falling back-to INTa mode -- %d.\n", ret);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002585skip_msi:
2586
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002587 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Mike Hernandez7992abf2010-11-23 16:52:47 -08002588 ha->flags.msi_enabled ? 0 : IRQF_SHARED,
2589 QLA2XXX_DRIVER_NAME, rsp);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002590 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002591 ql_log(ql_log_warn, vha, 0x003a,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002592 "Failed to reserve interrupt %d already in use.\n",
2593 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002594 goto fail;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002595 }
Mike Hernandez7992abf2010-11-23 16:52:47 -08002596
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002597clear_risc_ints:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002598
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002599 /*
2600 * FIXME: Noted that 8014s were being dropped during NK testing.
2601 * Timing deltas during MSI-X/INTa transitions?
2602 */
Giridhar Malavalia9083012010-04-12 17:59:55 -07002603 if (IS_QLA81XX(ha) || IS_QLA82XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002604 goto fail;
Andrew Vasquezc6952482008-04-03 13:13:17 -07002605 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002606 if (IS_FWI2_CAPABLE(ha)) {
2607 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
2608 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
2609 } else {
2610 WRT_REG_WORD(&reg->isp.semaphore, 0);
2611 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
2612 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
2613 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07002614 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002615
2616fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002617 return ret;
2618}
2619
2620void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002621qla2x00_free_irqs(scsi_qla_host_t *vha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002622{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002623 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002624 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002625
2626 if (ha->flags.msix_enabled)
2627 qla24xx_disable_msix(ha);
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002628 else if (ha->flags.msi_enabled) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002629 free_irq(ha->pdev->irq, rsp);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002630 pci_disable_msi(ha->pdev);
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002631 } else
2632 free_irq(ha->pdev->irq, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002633}
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002634
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002635
2636int qla25xx_request_irq(struct rsp_que *rsp)
2637{
2638 struct qla_hw_data *ha = rsp->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002639 struct qla_init_msix_entry *intr = &msix_entries[2];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002640 struct qla_msix_entry *msix = rsp->msix;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002641 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002642 int ret;
2643
2644 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
2645 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002646 ql_log(ql_log_fatal, vha, 0x00e6,
2647 "MSI-X: Unable to register handler -- %x/%d.\n",
2648 msix->vector, ret);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002649 return ret;
2650 }
2651 msix->have_irq = 1;
2652 msix->rsp = rsp;
2653 return ret;
2654}