blob: 245e7afb4c4dcf897c54029f8a3940408a2a4fbe [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 Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 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>
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070010#include <scsi/scsi_tcq.h>
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080013static void qla2x00_process_completed_request(struct scsi_qla_host *,
14 struct req_que *, uint32_t);
15static void qla2x00_status_entry(scsi_qla_host_t *, struct rsp_que *, void *);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070016static void qla2x00_status_cont_entry(struct rsp_que *, sts_cont_entry_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080017static void qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
18 sts_entry_t *);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070019
Linus Torvalds1da177e2005-04-16 15:20:36 -070020/**
21 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
22 * @irq:
23 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 *
25 * Called by system whenever the host adapter generates an interrupt.
26 *
27 * Returns handled flag.
28 */
29irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +010030qla2100_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080032 scsi_qla_host_t *vha;
33 struct qla_hw_data *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -070034 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 unsigned long iter;
Seokmann Ju14e660e2007-09-20 14:07:36 -070037 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070038 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080039 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070040 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080042 rsp = (struct rsp_que *) dev_id;
43 if (!rsp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080045 "%s(): NULL response queue pointer\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 return (IRQ_NONE);
47 }
48
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080049 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -070050 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 status = 0;
52
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -070053 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -070054 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 for (iter = 50; iter--; ) {
Seokmann Ju14e660e2007-09-20 14:07:36 -070056 hccr = RD_REG_WORD(&reg->hccr);
57 if (hccr & HCCR_RISC_PAUSE) {
58 if (pci_channel_offline(ha->pdev))
59 break;
60
61 /*
62 * Issue a "HARD" reset in order for the RISC interrupt
63 * bit to be cleared. Schedule a big hammmer to get
64 * out of the RISC PAUSED state.
65 */
66 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
67 RD_REG_WORD(&reg->hccr);
68
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080069 ha->isp_ops->fw_dump(vha, 1);
70 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -070071 break;
72 } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 break;
74
75 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
76 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
77 RD_REG_WORD(&reg->hccr);
78
79 /* Get mailbox data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -070080 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
81 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080082 qla2x00_mbx_completion(vha, mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 status |= MBX_INTERRUPT;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070084 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
85 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
86 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
87 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080088 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 } else {
90 /*EMPTY*/
91 DEBUG2(printk("scsi(%ld): Unrecognized "
Andrew Vasquez9a853f72005-07-06 10:31:27 -070092 "interrupt type (%d).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080093 vha->host_no, mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 }
95 /* Release mailbox registers. */
96 WRT_REG_WORD(&reg->semaphore, 0);
97 RD_REG_WORD(&reg->semaphore);
98 } else {
Anirban Chakraborty73208df2008-12-09 16:45:39 -080099 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
102 RD_REG_WORD(&reg->hccr);
103 }
104 }
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700105 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
108 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800110 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 }
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 return (IRQ_HANDLED);
114}
115
116/**
117 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
118 * @irq:
119 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 *
121 * Called by system whenever the host adapter generates an interrupt.
122 *
123 * Returns handled flag.
124 */
125irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100126qla2300_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800128 scsi_qla_host_t *vha;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700129 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 unsigned long iter;
132 uint32_t stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700134 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800135 struct rsp_que *rsp;
136 struct qla_hw_data *ha;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700137 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800139 rsp = (struct rsp_que *) dev_id;
140 if (!rsp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800142 "%s(): NULL response queue pointer\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 return (IRQ_NONE);
144 }
145
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800146 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700147 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 status = 0;
149
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700150 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700151 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 for (iter = 50; iter--; ) {
153 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
154 if (stat & HSR_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -0700155 if (pci_channel_offline(ha->pdev))
156 break;
157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 hccr = RD_REG_WORD(&reg->hccr);
159 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Andrew Vasquez07f31802006-12-13 19:20:31 -0800160 qla_printk(KERN_INFO, ha, "Parity error -- "
161 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 else
Andrew Vasquez07f31802006-12-13 19:20:31 -0800163 qla_printk(KERN_INFO, ha, "RISC paused -- "
164 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 /*
167 * Issue a "HARD" reset in order for the RISC
168 * interrupt bit to be cleared. Schedule a big
169 * hammmer to get out of the RISC PAUSED state.
170 */
171 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
172 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800173
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800174 ha->isp_ops->fw_dump(vha, 1);
175 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 break;
177 } else if ((stat & HSR_RISC_INT) == 0)
178 break;
179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 case 0x1:
182 case 0x2:
183 case 0x10:
184 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800185 qla2x00_mbx_completion(vha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 status |= MBX_INTERRUPT;
187
188 /* Release mailbox registers. */
189 WRT_REG_WORD(&reg->semaphore, 0);
190 break;
191 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700192 mb[0] = MSW(stat);
193 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
194 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
195 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800196 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700197 break;
198 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800199 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 break;
201 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700202 mb[0] = MBA_CMPLT_1_16BIT;
203 mb[1] = MSW(stat);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800204 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 break;
206 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700207 mb[0] = MBA_SCSI_COMPLETION;
208 mb[1] = MSW(stat);
209 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800210 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 break;
212 default:
213 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700214 "(%d).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800215 vha->host_no, stat & 0xff));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 break;
217 }
218 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
219 RD_REG_WORD_RELAXED(&reg->hccr);
220 }
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -0700221 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
224 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800226 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 }
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 return (IRQ_HANDLED);
230}
231
232/**
233 * qla2x00_mbx_completion() - Process mailbox command completions.
234 * @ha: SCSI driver HA context
235 * @mb0: Mailbox0 register
236 */
237static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800238qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239{
240 uint16_t cnt;
241 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800242 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700243 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245 /* Load return mailbox registers. */
246 ha->flags.mbox_int = 1;
247 ha->mailbox_out[0] = mb0;
248 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
249
250 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700251 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
253 if (cnt == 4 || cnt == 5)
254 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
255 else
256 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 wptr++;
259 }
260
261 if (ha->mcp) {
262 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800263 __func__, vha->host_no, ha->mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 } else {
265 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800266 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 }
268}
269
Andrew Vasquez8a659572009-02-08 20:50:12 -0800270static void
271qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
272{
273 static char *event[] =
274 { "Complete", "Request Notification", "Time Extension" };
275 int rval;
276 struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
277 uint16_t __iomem *wptr;
278 uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
279
280 /* Seed data -- mailbox1 -> mailbox7. */
281 wptr = (uint16_t __iomem *)&reg24->mailbox1;
282 for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
283 mb[cnt] = RD_REG_WORD(wptr);
284
285 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- "
286 "%04x %04x %04x %04x %04x %04x %04x.\n", vha->host_no,
287 event[aen & 0xff],
288 mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6]));
289
290 /* Acknowledgement needed? [Notify && non-zero timeout]. */
291 timeout = (descr >> 8) & 0xf;
292 if (aen != MBA_IDC_NOTIFY || !timeout)
293 return;
294
295 DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- "
296 "ACK timeout=%d.\n", vha->host_no, event[aen & 0xff], timeout));
297
298 rval = qla2x00_post_idc_ack_work(vha, mb);
299 if (rval != QLA_SUCCESS)
300 qla_printk(KERN_WARNING, vha->hw,
301 "IDC failed to post ACK.\n");
302}
303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304/**
305 * qla2x00_async_event() - Process aynchronous events.
306 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700307 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700309void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800310qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311{
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700312#define LS_UNKNOWN 2
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800313 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 char *link_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 uint16_t handle_cnt;
316 uint16_t cnt;
317 uint32_t handles[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800318 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700319 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 uint32_t rscn_entry, host_pid;
321 uint8_t rscn_queue_index;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700322 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 /* Setup to process RIO completion. */
325 handle_cnt = 0;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800326 if (IS_QLA81XX(ha))
327 goto skip_rio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 switch (mb[0]) {
329 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700330 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 handle_cnt = 1;
332 break;
333 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700334 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 handle_cnt = 1;
336 mb[0] = MBA_SCSI_COMPLETION;
337 break;
338 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700339 handles[0] = mb[1];
340 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 handle_cnt = 2;
342 mb[0] = MBA_SCSI_COMPLETION;
343 break;
344 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700345 handles[0] = mb[1];
346 handles[1] = mb[2];
347 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 handle_cnt = 3;
349 mb[0] = MBA_SCSI_COMPLETION;
350 break;
351 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700352 handles[0] = mb[1];
353 handles[1] = mb[2];
354 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
356 handle_cnt = 4;
357 mb[0] = MBA_SCSI_COMPLETION;
358 break;
359 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700360 handles[0] = mb[1];
361 handles[1] = mb[2];
362 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
364 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
365 handle_cnt = 5;
366 mb[0] = MBA_SCSI_COMPLETION;
367 break;
368 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700369 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 handles[1] = le32_to_cpu(
371 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
372 RD_MAILBOX_REG(ha, reg, 6));
373 handle_cnt = 2;
374 mb[0] = MBA_SCSI_COMPLETION;
375 break;
376 default:
377 break;
378 }
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800379skip_rio:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 switch (mb[0]) {
381 case MBA_SCSI_COMPLETION: /* Fast Post */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800382 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 break;
384
385 for (cnt = 0; cnt < handle_cnt; cnt++)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800386 qla2x00_process_completed_request(vha, rsp->req,
387 handles[cnt]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 break;
389
390 case MBA_RESET: /* Reset */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800391 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n",
392 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800394 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 break;
396
397 case MBA_SYSTEM_ERR: /* System Error */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 qla_printk(KERN_INFO, ha,
399 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
400 mb[1], mb[2], mb[3]);
401
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800402 ha->isp_ops->fw_dump(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Andrew Vasqueze4289242007-07-19 15:05:56 -0700404 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700405 if (mb[1] == 0 && mb[2] == 0) {
406 qla_printk(KERN_ERR, ha,
407 "Unrecoverable Hardware Error: adapter "
408 "marked OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800409 vha->flags.online = 0;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700410 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800411 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700412 } else if (mb[1] == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 qla_printk(KERN_INFO, ha,
414 "Unrecoverable Hardware Error: adapter marked "
415 "OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800416 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800418 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 break;
420
421 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
422 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800423 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
425
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800426 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 break;
428
429 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
430 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800431 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
433
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800434 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 break;
436
437 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
438 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800439 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 break;
441
442 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800443 DEBUG2(printk("scsi(%ld): LIP occurred (%x).\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 mb[1]));
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700445 qla_printk(KERN_INFO, ha, "LIP occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800447 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
448 atomic_set(&vha->loop_state, LOOP_DOWN);
449 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
450 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 }
452
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800453 if (vha->vp_idx) {
454 atomic_set(&vha->vp_state, VP_FAILED);
455 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700456 }
457
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800458 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
459 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800461 vha->flags.management_server_logged_in = 0;
462 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 break;
464
465 case MBA_LOOP_UP: /* Loop Up Event */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
467 link_speed = link_speeds[0];
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700468 ha->link_data_rate = PORT_SPEED_1GB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 } else {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700470 link_speed = link_speeds[LS_UNKNOWN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 if (mb[1] < 5)
472 link_speed = link_speeds[mb[1]];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800473 else if (mb[1] == 0x13)
474 link_speed = link_speeds[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 ha->link_data_rate = mb[1];
476 }
477
478 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800479 vha->host_no, link_speed));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
481 link_speed);
482
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800483 vha->flags.management_server_logged_in = 0;
484 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 break;
486
487 case MBA_LOOP_DOWN: /* Loop Down Event */
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700488 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800489 "(%x %x %x).\n", vha->host_no, mb[1], mb[2], mb[3]));
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700490 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x %x %x).\n",
491 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800493 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
494 atomic_set(&vha->loop_state, LOOP_DOWN);
495 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
496 vha->device_flags |= DFLG_NO_CABLE;
497 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
499
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800500 if (vha->vp_idx) {
501 atomic_set(&vha->vp_state, VP_FAILED);
502 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700503 }
504
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800505 vha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700506 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800507 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 break;
509
510 case MBA_LIP_RESET: /* LIP reset occurred */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800512 vha->host_no, mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 qla_printk(KERN_INFO, ha,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700514 "LIP reset occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800516 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
517 atomic_set(&vha->loop_state, LOOP_DOWN);
518 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
519 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 }
521
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800522 if (vha->vp_idx) {
523 atomic_set(&vha->vp_state, VP_FAILED);
524 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700525 }
526
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800527 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
529 ha->operating_mode = LOOP;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800530 vha->flags.management_server_logged_in = 0;
531 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 break;
533
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800534 /* case MBA_DCBX_COMPLETE: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 case MBA_POINT_TO_POINT: /* Point-to-Point */
536 if (IS_QLA2100(ha))
537 break;
538
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800539 if (IS_QLA81XX(ha))
540 DEBUG2(printk("scsi(%ld): DCBX Completed -- %04x %04x "
541 "%04x\n", vha->host_no, mb[1], mb[2], mb[3]));
542 else
543 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE "
544 "received.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546 /*
547 * Until there's a transition from loop down to loop up, treat
548 * this as loop down only.
549 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800550 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
551 atomic_set(&vha->loop_state, LOOP_DOWN);
552 if (!atomic_read(&vha->loop_down_timer))
553 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800555 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 }
557
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800558 if (vha->vp_idx) {
559 atomic_set(&vha->vp_state, VP_FAILED);
560 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700561 }
562
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800563 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
564 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
565
566 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
567 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800568
569 ha->flags.gpsc_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800570 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 break;
572
573 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
574 if (IS_QLA2100(ha))
575 break;
576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
578 "received.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800579 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 qla_printk(KERN_INFO, ha,
581 "Configuration change detected: value=%x.\n", mb[1]);
582
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800583 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
584 atomic_set(&vha->loop_state, LOOP_DOWN);
585 if (!atomic_read(&vha->loop_down_timer))
586 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800588 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 }
590
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800591 if (vha->vp_idx) {
592 atomic_set(&vha->vp_state, VP_FAILED);
593 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700594 }
595
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800596 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
597 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 break;
599
600 case MBA_PORT_UPDATE: /* Port database update */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800601 /* Only handle SCNs for our Vport index. */
602 if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff))
603 break;
604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 /*
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700606 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 * event etc. earlier indicating loop is down) then process
608 * it. Otherwise ignore it and Wait for RSCN to come in.
609 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800610 atomic_set(&vha->loop_down_timer, 0);
611 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
612 atomic_read(&vha->loop_state) != LOOP_DEAD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800614 "ignored %04x/%04x/%04x.\n", vha->host_no, mb[1],
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700615 mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 break;
617 }
618
619 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800620 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 DEBUG(printk(KERN_INFO
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700622 "scsi(%ld): Port database changed %04x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800623 vha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
625 /*
626 * Mark all devices as missing so we will login again.
627 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800628 atomic_set(&vha->loop_state, LOOP_UP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800630 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800632 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800634 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
635 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 break;
637
638 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju3c397402008-05-19 14:25:39 -0700639 /* Check if the Vport has issued a SCR */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800640 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
Seokmann Ju3c397402008-05-19 14:25:39 -0700641 break;
642 /* Only handle SCNs for our Vport index. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800643 if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff))
Seokmann Ju3c397402008-05-19 14:25:39 -0700644 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800646 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 DEBUG(printk(KERN_INFO
Shyam Sundarf4a8dbc2007-11-12 10:30:59 -0800648 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800649 vha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Ravi Anand59d72d82008-09-11 21:22:53 -0700651 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800652 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
653 | vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 if (rscn_entry == host_pid) {
655 DEBUG(printk(KERN_INFO
656 "scsi(%ld): Ignoring RSCN update to local host "
657 "port ID (%06x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800658 vha->host_no, host_pid));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 break;
660 }
661
Ravi Anand59d72d82008-09-11 21:22:53 -0700662 /* Ignore reserved bits from RSCN-payload. */
663 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800664 rscn_queue_index = vha->rscn_in_ptr + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 if (rscn_queue_index == MAX_RSCN_COUNT)
666 rscn_queue_index = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800667 if (rscn_queue_index != vha->rscn_out_ptr) {
668 vha->rscn_queue[vha->rscn_in_ptr] = rscn_entry;
669 vha->rscn_in_ptr = rscn_queue_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800671 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 }
673
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800674 atomic_set(&vha->loop_state, LOOP_UPDATE);
675 atomic_set(&vha->loop_down_timer, 0);
676 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800678 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
679 set_bit(RSCN_UPDATE, &vha->dpc_flags);
680 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 break;
682
683 /* case MBA_RIO_RESPONSE: */
684 case MBA_ZIO_RESPONSE:
Andrew Vasquez3fd67cd2009-01-05 11:18:07 -0800685 DEBUG3(printk("scsi(%ld): [R|Z]IO update completion.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800686 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Andrew Vasqueze4289242007-07-19 15:05:56 -0700688 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700689 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700690 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800691 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700693
694 case MBA_DISCARD_RND_FRAME:
695 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800696 "%04x.\n", vha->host_no, mb[1], mb[2], mb[3]));
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700697 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700698
699 case MBA_TRACE_NOTIFICATION:
700 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800701 vha->host_no, mb[1], mb[2]));
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700702 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700703
704 case MBA_ISP84XX_ALERT:
705 DEBUG2(printk("scsi(%ld): ISP84XX Alert Notification -- "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800706 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700707
708 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
709 switch (mb[1]) {
710 case A84_PANIC_RECOVERY:
711 qla_printk(KERN_INFO, ha, "Alert 84XX: panic recovery "
712 "%04x %04x\n", mb[2], mb[3]);
713 break;
714 case A84_OP_LOGIN_COMPLETE:
715 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
716 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
717 "firmware version %x\n", ha->cs84xx->op_fw_version));
718 break;
719 case A84_DIAG_LOGIN_COMPLETE:
720 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
721 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
722 "diagnostic firmware version %x\n",
723 ha->cs84xx->diag_fw_version));
724 break;
725 case A84_GOLD_LOGIN_COMPLETE:
726 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
727 ha->cs84xx->fw_update = 1;
728 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX: gold "
729 "firmware version %x\n",
730 ha->cs84xx->gold_fw_version));
731 break;
732 default:
733 qla_printk(KERN_ERR, ha,
734 "Alert 84xx: Invalid Alert %04x %04x %04x\n",
735 mb[1], mb[2], mb[3]);
736 }
737 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
738 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800739 case MBA_DCBX_START:
740 DEBUG2(printk("scsi(%ld): DCBX Started -- %04x %04x %04x\n",
741 vha->host_no, mb[1], mb[2], mb[3]));
742 break;
743 case MBA_DCBX_PARAM_UPDATE:
744 DEBUG2(printk("scsi(%ld): DCBX Parameters Updated -- "
745 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
746 break;
747 case MBA_FCF_CONF_ERR:
748 DEBUG2(printk("scsi(%ld): FCF Configuration Error -- "
749 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
750 break;
751 case MBA_IDC_COMPLETE:
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800752 case MBA_IDC_NOTIFY:
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800753 case MBA_IDC_TIME_EXT:
Andrew Vasquez8a659572009-02-08 20:50:12 -0800754 qla81xx_idc_event(vha, mb[0], mb[1]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800755 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700757
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800758 if (!vha->vp_idx && ha->num_vhosts)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800759 qla2x00_alert_all_vps(rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760}
761
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700762static void
763qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
764{
765 fc_port_t *fcport = data;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800766 struct scsi_qla_host *vha = fcport->vha;
767 struct qla_hw_data *ha = vha->hw;
768 struct req_que *req = NULL;
769
Michael Reeda13d8ac2009-04-06 22:33:47 -0700770 if (!ql2xqfulltracking)
771 return;
772
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700773 req = vha->req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800774 if (!req)
775 return;
776 if (req->max_q_depth <= sdev->queue_depth)
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700777 return;
778
779 if (sdev->ordered_tags)
780 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
781 sdev->queue_depth + 1);
782 else
783 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
784 sdev->queue_depth + 1);
785
786 fcport->last_ramp_up = jiffies;
787
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800788 DEBUG2(qla_printk(KERN_INFO, ha,
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700789 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800790 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700791 sdev->queue_depth));
792}
793
794static void
795qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
796{
797 fc_port_t *fcport = data;
798
799 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
800 return;
801
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800802 DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700803 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800804 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700805 sdev->queue_depth));
806}
807
808static inline void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800809qla2x00_ramp_up_queue_depth(scsi_qla_host_t *vha, struct req_que *req,
810 srb_t *sp)
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700811{
812 fc_port_t *fcport;
813 struct scsi_device *sdev;
814
Michael Reeda13d8ac2009-04-06 22:33:47 -0700815 if (!ql2xqfulltracking)
816 return;
817
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700818 sdev = sp->cmd->device;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800819 if (sdev->queue_depth >= req->max_q_depth)
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700820 return;
821
822 fcport = sp->fcport;
823 if (time_before(jiffies,
824 fcport->last_ramp_up + ql2xqfullrampup * HZ))
825 return;
826 if (time_before(jiffies,
827 fcport->last_queue_full + ql2xqfullrampup * HZ))
828 return;
829
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700830 starget_for_each_device(sdev->sdev_target, fcport,
831 qla2x00_adjust_sdev_qdepth_up);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700832}
833
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834/**
835 * qla2x00_process_completed_request() - Process a Fast Post response.
836 * @ha: SCSI driver HA context
837 * @index: SRB index
838 */
839static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800840qla2x00_process_completed_request(struct scsi_qla_host *vha,
841 struct req_que *req, uint32_t index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842{
843 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800844 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
846 /* Validate handle. */
847 if (index >= MAX_OUTSTANDING_COMMANDS) {
848 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800849 vha->host_no, index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 qla_printk(KERN_WARNING, ha,
851 "Invalid SCSI completion handle %d.\n", index);
852
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800853 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 return;
855 }
856
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800857 sp = req->outstanding_cmds[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 if (sp) {
859 /* Free outstanding command slot. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800860 req->outstanding_cmds[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 /* Save ISP completion status */
863 sp->cmd->result = DID_OK << 16;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700864
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800865 qla2x00_ramp_up_queue_depth(vha, req, sp);
866 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 } else {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700868 DEBUG2(printk("scsi(%ld) Req:%d: Invalid ISP SCSI completion"
869 " handle(%d)\n", vha->host_no, req->id, index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 qla_printk(KERN_WARNING, ha,
871 "Invalid ISP SCSI completion handle\n");
872
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800873 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 }
875}
876
877/**
878 * qla2x00_process_response_queue() - Process response queue entries.
879 * @ha: SCSI driver HA context
880 */
881void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800882qla2x00_process_response_queue(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883{
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800884 struct scsi_qla_host *vha;
885 struct qla_hw_data *ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700886 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 sts_entry_t *pkt;
888 uint16_t handle_cnt;
889 uint16_t cnt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800890
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700891 vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800893 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 return;
895
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800896 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
897 pkt = (sts_entry_t *)rsp->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800899 rsp->ring_index++;
900 if (rsp->ring_index == rsp->length) {
901 rsp->ring_index = 0;
902 rsp->ring_ptr = rsp->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800904 rsp->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 }
906
907 if (pkt->entry_status != 0) {
908 DEBUG3(printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800909 "scsi(%ld): Process error entry.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800911 qla2x00_error_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
913 wmb();
914 continue;
915 }
916
917 switch (pkt->entry_type) {
918 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800919 qla2x00_status_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 break;
921 case STATUS_TYPE_21:
922 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
923 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800924 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 ((sts21_entry_t *)pkt)->handle[cnt]);
926 }
927 break;
928 case STATUS_TYPE_22:
929 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
930 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800931 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 ((sts22_entry_t *)pkt)->handle[cnt]);
933 }
934 break;
935 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700936 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 default:
939 /* Type Not Supported. */
940 DEBUG4(printk(KERN_WARNING
941 "scsi(%ld): Received unknown response pkt type %x "
942 "entry status=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800943 vha->host_no, pkt->entry_type, pkt->entry_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 break;
945 }
946 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
947 wmb();
948 }
949
950 /* Adjust ring index */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800951 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952}
953
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800954static inline void
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700955qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len,
956 struct rsp_que *rsp)
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800957{
958 struct scsi_cmnd *cp = sp->cmd;
959
960 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
961 sense_len = SCSI_SENSE_BUFFERSIZE;
962
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800963 sp->request_sense_length = sense_len;
964 sp->request_sense_ptr = cp->sense_buffer;
965 if (sp->request_sense_length > 32)
966 sense_len = 32;
967
968 memcpy(cp->sense_buffer, sense_data, sense_len);
969
970 sp->request_sense_ptr += sense_len;
971 sp->request_sense_length -= sense_len;
972 if (sp->request_sense_length != 0)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700973 rsp->status_srb = sp;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800974
975 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800976 "cmd=%p pid=%ld\n", __func__, sp->fcport->vha->host_no,
Andrew Vasquez19851f12008-08-13 21:37:00 -0700977 cp->device->channel, cp->device->id, cp->device->lun, cp,
978 cp->serial_number));
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800979 if (sense_len)
Shyam Sundarddb9b122009-03-24 09:08:10 -0700980 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer, sense_len));
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800981}
982
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983/**
984 * qla2x00_status_entry() - Process a Status IOCB entry.
985 * @ha: SCSI driver HA context
986 * @pkt: Entry pointer
987 */
988static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800989qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 fc_port_t *fcport;
993 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700994 sts_entry_t *sts;
995 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 uint16_t comp_status;
997 uint16_t scsi_status;
998 uint8_t lscsi_status;
999 int32_t resid;
Ravi Ananded17c71b52006-05-17 15:08:55 -07001000 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001001 uint8_t *rsp_info, *sense_data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001002 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001003 uint32_t handle;
1004 uint16_t que;
1005 struct req_que *req;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001006
1007 sts = (sts_entry_t *) pkt;
1008 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001009 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001010 comp_status = le16_to_cpu(sts24->comp_status);
1011 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
1012 } else {
1013 comp_status = le16_to_cpu(sts->comp_status);
1014 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
1015 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001016 handle = (uint32_t) LSW(sts->handle);
1017 que = MSW(sts->handle);
1018 req = ha->req_q_map[que];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001020 if (comp_status == CS_COMPLETE && scsi_status == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001021 qla2x00_process_completed_request(vha, req, handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
1023 return;
1024 }
1025
1026 /* Validate handle. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001027 if (handle < MAX_OUTSTANDING_COMMANDS) {
1028 sp = req->outstanding_cmds[handle];
1029 req->outstanding_cmds[handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 } else
1031 sp = NULL;
1032
1033 if (sp == NULL) {
1034 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001035 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
1037
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001038 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1039 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 return;
1041 }
1042 cp = sp->cmd;
1043 if (cp == NULL) {
1044 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001045 "pkt->handle=%d sp=%p.\n", vha->host_no, handle, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 qla_printk(KERN_WARNING, ha,
1047 "Command is NULL: already returned to OS (sp=%p)\n", sp);
1048
1049 return;
1050 }
1051
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001052 lscsi_status = scsi_status & STATUS_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
bdf79622005-04-17 15:06:53 -05001054 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
Ravi Ananded17c71b52006-05-17 15:08:55 -07001056 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001057 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001058 sense_len = le32_to_cpu(sts24->sense_len);
1059 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
1060 resid_len = le32_to_cpu(sts24->rsp_residual_count);
Ravi Ananded17c71b52006-05-17 15:08:55 -07001061 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001062 rsp_info = sts24->data;
1063 sense_data = sts24->data;
1064 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
1065 } else {
1066 sense_len = le16_to_cpu(sts->req_sense_length);
1067 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
1068 resid_len = le32_to_cpu(sts->residual_length);
1069 rsp_info = sts->rsp_info;
1070 sense_data = sts->req_sense_data;
1071 }
1072
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 /* Check for any FCP transport errors. */
1074 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001075 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001076 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001077 sense_data += rsp_info_len;
1078 if (rsp_info_len > 3 && rsp_info[3]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
1080 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001081 "retrying command\n", vha->host_no,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001082 cp->device->channel, cp->device->id,
1083 cp->device->lun, rsp_info_len, rsp_info[0],
1084 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
1085 rsp_info[5], rsp_info[6], rsp_info[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
1087 cp->result = DID_BUS_BUSY << 16;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001088 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 return;
1090 }
1091 }
1092
Andrew Vasquez3e8ce322008-02-28 14:06:10 -08001093 /* Check for overrun. */
1094 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
1095 scsi_status & SS_RESIDUAL_OVER)
1096 comp_status = CS_DATA_OVERRUN;
1097
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 /*
1099 * Based on Host and scsi status generate status code for Linux
1100 */
1101 switch (comp_status) {
1102 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001103 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 if (scsi_status == 0) {
1105 cp->result = DID_OK << 16;
1106 break;
1107 }
1108 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001109 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001110 scsi_set_resid(cp, resid);
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001111
1112 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001113 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001114 cp->underflow)) {
1115 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001116 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1117 "detected (%x of %x bytes)...returning "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001118 "error status.\n", vha->host_no,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001119 cp->device->channel, cp->device->id,
1120 cp->device->lun, resid,
1121 scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001122
1123 cp->result = DID_ERROR << 16;
1124 break;
1125 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 cp->result = DID_OK << 16 | lscsi_status;
1128
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001129 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1130 DEBUG2(printk(KERN_INFO
1131 "scsi(%ld): QUEUE FULL status detected "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001132 "0x%x-0x%x.\n", vha->host_no, comp_status,
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001133 scsi_status));
1134
1135 /* Adjust queue depth for all luns on the port. */
Michael Reeda13d8ac2009-04-06 22:33:47 -07001136 if (!ql2xqfulltracking)
1137 break;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001138 fcport->last_queue_full = jiffies;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001139 starget_for_each_device(cp->device->sdev_target,
1140 fcport, qla2x00_adjust_sdev_qdepth_down);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001141 break;
1142 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 if (lscsi_status != SS_CHECK_CONDITION)
1144 break;
1145
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001146 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 if (!(scsi_status & SS_SENSE_LEN_VALID))
1148 break;
1149
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001150 qla2x00_handle_sense(sp, sense_data, sense_len, rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 break;
1152
1153 case CS_DATA_UNDERRUN:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001154 resid = resid_len;
Ravi Ananded17c71b52006-05-17 15:08:55 -07001155 /* Use F/W calculated residual length. */
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001156 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez2d136932008-09-11 21:22:52 -07001157 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1158 lscsi_status = 0;
1159 } else if (resid != fw_resid_len) {
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001160 scsi_status &= ~SS_RESIDUAL_UNDER;
1161 lscsi_status = 0;
1162 }
Ravi Ananded17c71b52006-05-17 15:08:55 -07001163 resid = fw_resid_len;
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001164 }
Ravi Ananded17c71b52006-05-17 15:08:55 -07001165
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 if (scsi_status & SS_RESIDUAL_UNDER) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001167 scsi_set_resid(cp, resid);
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08001168 } else {
1169 DEBUG2(printk(KERN_INFO
1170 "scsi(%ld:%d:%d) UNDERRUN status detected "
Ravi Ananded17c71b52006-05-17 15:08:55 -07001171 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001172 "os_underflow=0x%x\n", vha->host_no,
Ravi Ananded17c71b52006-05-17 15:08:55 -07001173 cp->device->id, cp->device->lun, comp_status,
1174 scsi_status, resid_len, resid, cp->cmnd[0],
1175 cp->underflow));
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -08001176
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 }
1178
1179 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001180 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 * Status.
1182 */
1183 if (lscsi_status != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 cp->result = DID_OK << 16 | lscsi_status;
1185
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001186 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1187 DEBUG2(printk(KERN_INFO
1188 "scsi(%ld): QUEUE FULL status detected "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001189 "0x%x-0x%x.\n", vha->host_no, comp_status,
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001190 scsi_status));
1191
1192 /*
1193 * Adjust queue depth for all luns on the
1194 * port.
1195 */
Michael Reeda13d8ac2009-04-06 22:33:47 -07001196 if (!ql2xqfulltracking)
1197 break;
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001198 fcport->last_queue_full = jiffies;
1199 starget_for_each_device(
1200 cp->device->sdev_target, fcport,
1201 qla2x00_adjust_sdev_qdepth_down);
1202 break;
1203 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 if (lscsi_status != SS_CHECK_CONDITION)
1205 break;
1206
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001207 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 if (!(scsi_status & SS_SENSE_LEN_VALID))
1209 break;
1210
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001211 qla2x00_handle_sense(sp, sense_data, sense_len, rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 } else {
1213 /*
1214 * If RISC reports underrun and target does not report
1215 * it then we must have a lost frame, so tell upper
Andrew Vasquez94b3aa42009-06-03 09:55:18 -07001216 * layer to retry it by reporting an error.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 */
1218 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1219 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001220 "frame(s) detected (%x of %x bytes)..."
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001221 "retrying command.\n",
1222 vha->host_no, cp->device->channel,
1223 cp->device->id, cp->device->lun, resid,
1224 scsi_bufflen(cp)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225
Andrew Vasquez94b3aa42009-06-03 09:55:18 -07001226 cp->result = DID_ERROR << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 break;
1228 }
1229
1230 /* Handle mid-layer underflow */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001231 if ((unsigned)(scsi_bufflen(cp) - resid) <
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 cp->underflow) {
1233 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001234 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1235 "detected (%x of %x bytes)...returning "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001236 "error status.\n", vha->host_no,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001237 cp->device->channel, cp->device->id,
1238 cp->device->lun, resid,
1239 scsi_bufflen(cp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
1241 cp->result = DID_ERROR << 16;
1242 break;
1243 }
1244
1245 /* Everybody online, looking good... */
1246 cp->result = DID_OK << 16;
1247 }
1248 break;
1249
1250 case CS_DATA_OVERRUN:
1251 DEBUG2(printk(KERN_INFO
1252 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001253 vha->host_no, cp->device->id, cp->device->lun, comp_status,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001254 scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 DEBUG2(printk(KERN_INFO
1256 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1257 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1258 cp->cmnd[4], cp->cmnd[5]));
1259 DEBUG2(printk(KERN_INFO
1260 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1261 "status!\n",
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001262 cp->serial_number, scsi_bufflen(cp), resid_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
1264 cp->result = DID_ERROR << 16;
1265 break;
1266
1267 case CS_PORT_LOGGED_OUT:
1268 case CS_PORT_CONFIG_CHG:
1269 case CS_PORT_BUSY:
1270 case CS_INCOMPLETE:
1271 case CS_PORT_UNAVAILABLE:
1272 /*
1273 * If the port is in Target Down state, return all IOs for this
1274 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1275 * retry_queue.
1276 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1278 "pid=%ld, compl status=0x%x, port state=0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001279 vha->host_no, cp->device->id, cp->device->lun,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001280 cp->serial_number, comp_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 atomic_read(&fcport->state)));
1282
Mike Christie056a4482008-08-19 18:45:29 -05001283 /*
1284 * We are going to have the fc class block the rport
1285 * while we try to recover so instruct the mid layer
1286 * to requeue until the class decides how to handle this.
1287 */
1288 cp->result = DID_TRANSPORT_DISRUPTED << 16;
Andrew Vasqueza7a28502008-08-13 21:36:57 -07001289 if (atomic_read(&fcport->state) == FCS_ONLINE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001290 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 break;
1292
1293 case CS_RESET:
1294 DEBUG2(printk(KERN_INFO
1295 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001296 vha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
f4f051e2005-04-17 15:02:26 -05001298 cp->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 break;
1300
1301 case CS_ABORTED:
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001302 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 * hv2.19.12 - DID_ABORT does not retry the request if we
1304 * aborted this request then abort otherwise it must be a
1305 * reset.
1306 */
1307 DEBUG2(printk(KERN_INFO
1308 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001309 vha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
1311 cp->result = DID_RESET << 16;
1312 break;
1313
1314 case CS_TIMEOUT:
Mike Christie056a4482008-08-19 18:45:29 -05001315 /*
1316 * We are going to have the fc class block the rport
1317 * while we try to recover so instruct the mid layer
1318 * to requeue until the class decides how to handle this.
1319 */
1320 cp->result = DID_TRANSPORT_DISRUPTED << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
Andrew Vasqueze4289242007-07-19 15:05:56 -07001322 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001323 DEBUG2(printk(KERN_INFO
1324 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001325 "0x%x-0x%x\n", vha->host_no, cp->device->channel,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001326 cp->device->id, cp->device->lun, comp_status,
1327 scsi_status));
1328 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001330 DEBUG2(printk(KERN_INFO
1331 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001332 "sflags=%x.\n", vha->host_no, cp->device->channel,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001333 cp->device->id, cp->device->lun, comp_status, scsi_status,
1334 le16_to_cpu(sts->status_flags)));
1335
1336 /* Check to see if logout occurred. */
1337 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001338 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 break;
1340
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 default:
1342 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001343 "0x%x-0x%x.\n", vha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 qla_printk(KERN_INFO, ha,
1345 "Unknown status detected 0x%x-0x%x.\n",
1346 comp_status, scsi_status);
1347
1348 cp->result = DID_ERROR << 16;
1349 break;
1350 }
1351
1352 /* Place command on done queue. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001353 if (rsp->status_srb == NULL)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001354 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355}
1356
1357/**
1358 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1359 * @ha: SCSI driver HA context
1360 * @pkt: Entry pointer
1361 *
1362 * Extended sense data.
1363 */
1364static void
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001365qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366{
1367 uint8_t sense_sz = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001368 struct qla_hw_data *ha = rsp->hw;
1369 srb_t *sp = rsp->status_srb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 struct scsi_cmnd *cp;
1371
1372 if (sp != NULL && sp->request_sense_length != 0) {
1373 cp = sp->cmd;
1374 if (cp == NULL) {
1375 DEBUG2(printk("%s(): Cmd already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001376 "sp=%p.\n", __func__, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 qla_printk(KERN_INFO, ha,
1378 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001379 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001381 rsp->status_srb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 return;
1383 }
1384
1385 if (sp->request_sense_length > sizeof(pkt->data)) {
1386 sense_sz = sizeof(pkt->data);
1387 } else {
1388 sense_sz = sp->request_sense_length;
1389 }
1390
1391 /* Move sense data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001392 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001393 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1395 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1396
1397 sp->request_sense_ptr += sense_sz;
1398 sp->request_sense_length -= sense_sz;
1399
1400 /* Place command on done queue. */
1401 if (sp->request_sense_length == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001402 rsp->status_srb = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001403 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 }
1405 }
1406}
1407
1408/**
1409 * qla2x00_error_entry() - Process an error entry.
1410 * @ha: SCSI driver HA context
1411 * @pkt: Entry pointer
1412 */
1413static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001414qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415{
1416 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001417 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001418 uint32_t handle = LSW(pkt->handle);
1419 uint16_t que = MSW(pkt->handle);
1420 struct req_que *req = ha->req_q_map[que];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421#if defined(QL_DEBUG_LEVEL_2)
1422 if (pkt->entry_status & RF_INV_E_ORDER)
1423 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1424 else if (pkt->entry_status & RF_INV_E_COUNT)
1425 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1426 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001427 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 "%s: Invalid Entry Parameter\n", __func__);
1429 else if (pkt->entry_status & RF_INV_E_TYPE)
1430 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1431 else if (pkt->entry_status & RF_BUSY)
1432 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1433 else
1434 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1435#endif
1436
1437 /* Validate handle. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001438 if (handle < MAX_OUTSTANDING_COMMANDS)
1439 sp = req->outstanding_cmds[handle];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 else
1441 sp = NULL;
1442
1443 if (sp) {
1444 /* Free outstanding command slot. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001445 req->outstanding_cmds[handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001446
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 /* Bad payload or header */
1448 if (pkt->entry_status &
1449 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1450 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1451 sp->cmd->result = DID_ERROR << 16;
1452 } else if (pkt->entry_status & RF_BUSY) {
1453 sp->cmd->result = DID_BUS_BUSY << 16;
1454 } else {
1455 sp->cmd->result = DID_ERROR << 16;
1456 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001457 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001459 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1460 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001462 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 qla_printk(KERN_WARNING, ha,
1464 "Error entry - invalid handle\n");
1465
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001466 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1467 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 }
1469}
1470
1471/**
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001472 * qla24xx_mbx_completion() - Process mailbox command completions.
1473 * @ha: SCSI driver HA context
1474 * @mb0: Mailbox0 register
1475 */
1476static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001477qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001478{
1479 uint16_t cnt;
1480 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001481 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001482 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1483
1484 /* Load return mailbox registers. */
1485 ha->flags.mbox_int = 1;
1486 ha->mailbox_out[0] = mb0;
1487 wptr = (uint16_t __iomem *)&reg->mailbox1;
1488
1489 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1490 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1491 wptr++;
1492 }
1493
1494 if (ha->mcp) {
1495 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001496 __func__, vha->host_no, ha->mcp->mb[0]));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001497 } else {
1498 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001499 __func__, vha->host_no));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001500 }
1501}
1502
1503/**
1504 * qla24xx_process_response_queue() - Process response queue entries.
1505 * @ha: SCSI driver HA context
1506 */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001507void qla24xx_process_response_queue(struct scsi_qla_host *vha,
1508 struct rsp_que *rsp)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001509{
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001510 struct sts_entry_24xx *pkt;
1511
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001512 if (!vha->flags.online)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001513 return;
1514
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001515 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1516 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001517
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001518 rsp->ring_index++;
1519 if (rsp->ring_index == rsp->length) {
1520 rsp->ring_index = 0;
1521 rsp->ring_ptr = rsp->ring;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001522 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001523 rsp->ring_ptr++;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001524 }
1525
1526 if (pkt->entry_status != 0) {
1527 DEBUG3(printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001528 "scsi(%ld): Process error entry.\n", vha->host_no));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001529
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001530 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001531 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1532 wmb();
1533 continue;
1534 }
1535
1536 switch (pkt->entry_type) {
1537 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001538 qla2x00_status_entry(vha, rsp, pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001539 break;
1540 case STATUS_CONT_TYPE:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001541 qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001542 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001543 case VP_RPT_ID_IOCB_TYPE:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001544 qla24xx_report_id_acquisition(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001545 (struct vp_rpt_id_entry_24xx *)pkt);
1546 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001547 default:
1548 /* Type Not Supported. */
1549 DEBUG4(printk(KERN_WARNING
1550 "scsi(%ld): Received unknown response pkt type %x "
1551 "entry status=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001552 vha->host_no, pkt->entry_type, pkt->entry_status));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001553 break;
1554 }
1555 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1556 wmb();
1557 }
1558
1559 /* Adjust ring index */
Andrew Vasquez08029992009-03-24 09:07:55 -07001560 WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001561}
1562
Andrew Vasquez05236a02007-09-20 14:07:37 -07001563static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001564qla2xxx_check_risc_status(scsi_qla_host_t *vha)
Andrew Vasquez05236a02007-09-20 14:07:37 -07001565{
1566 int rval;
1567 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001568 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez05236a02007-09-20 14:07:37 -07001569 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1570
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001571 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez05236a02007-09-20 14:07:37 -07001572 return;
1573
1574 rval = QLA_SUCCESS;
1575 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1576 RD_REG_DWORD(&reg->iobase_addr);
1577 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1578 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1579 rval == QLA_SUCCESS; cnt--) {
1580 if (cnt) {
1581 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1582 udelay(10);
1583 } else
1584 rval = QLA_FUNCTION_TIMEOUT;
1585 }
1586 if (rval == QLA_SUCCESS)
1587 goto next_test;
1588
1589 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1590 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1591 rval == QLA_SUCCESS; cnt--) {
1592 if (cnt) {
1593 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1594 udelay(10);
1595 } else
1596 rval = QLA_FUNCTION_TIMEOUT;
1597 }
1598 if (rval != QLA_SUCCESS)
1599 goto done;
1600
1601next_test:
1602 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
1603 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1604
1605done:
1606 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
1607 RD_REG_DWORD(&reg->iobase_window);
1608}
1609
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001610/**
1611 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1612 * @irq:
1613 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001614 *
1615 * Called by system whenever the host adapter generates an interrupt.
1616 *
1617 * Returns handled flag.
1618 */
1619irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001620qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001621{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001622 scsi_qla_host_t *vha;
1623 struct qla_hw_data *ha;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001624 struct device_reg_24xx __iomem *reg;
1625 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001626 unsigned long iter;
1627 uint32_t stat;
1628 uint32_t hccr;
1629 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001630 struct rsp_que *rsp;
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07001631 unsigned long flags;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001632
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001633 rsp = (struct rsp_que *) dev_id;
1634 if (!rsp) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001635 printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001636 "%s(): NULL response queue pointer\n", __func__);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001637 return IRQ_NONE;
1638 }
1639
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001640 ha = rsp->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001641 reg = &ha->iobase->isp24;
1642 status = 0;
1643
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07001644 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001645 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001646 for (iter = 50; iter--; ) {
1647 stat = RD_REG_DWORD(&reg->host_status);
1648 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001649 if (pci_channel_offline(ha->pdev))
1650 break;
1651
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001652 hccr = RD_REG_DWORD(&reg->hccr);
1653
1654 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1655 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001656
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001657 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001658
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001659 ha->isp_ops->fw_dump(vha, 1);
1660 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001661 break;
1662 } else if ((stat & HSRX_RISC_INT) == 0)
1663 break;
1664
1665 switch (stat & 0xff) {
1666 case 0x1:
1667 case 0x2:
1668 case 0x10:
1669 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001670 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001671 status |= MBX_INTERRUPT;
1672
1673 break;
1674 case 0x12:
1675 mb[0] = MSW(stat);
1676 mb[1] = RD_REG_WORD(&reg->mailbox1);
1677 mb[2] = RD_REG_WORD(&reg->mailbox2);
1678 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001679 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001680 break;
1681 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001682 case 0x14:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001683 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001684 break;
1685 default:
1686 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1687 "(%d).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001688 vha->host_no, stat & 0xff));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001689 break;
1690 }
1691 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1692 RD_REG_DWORD_RELAXED(&reg->hccr);
1693 }
Anirban Chakraborty43fac4d2009-06-10 13:55:11 -07001694 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001695
1696 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1697 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001698 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001699 complete(&ha->mbx_intr_comp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001700 }
1701
1702 return IRQ_HANDLED;
1703}
1704
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001705static irqreturn_t
1706qla24xx_msix_rsp_q(int irq, void *dev_id)
1707{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001708 struct qla_hw_data *ha;
1709 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001710 struct device_reg_24xx __iomem *reg;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001711 struct scsi_qla_host *vha;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001712
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001713 rsp = (struct rsp_que *) dev_id;
1714 if (!rsp) {
1715 printk(KERN_INFO
1716 "%s(): NULL response queue pointer\n", __func__);
1717 return IRQ_NONE;
1718 }
1719 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001720 reg = &ha->iobase->isp24;
1721
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001722 spin_lock_irq(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001723
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001724 vha = qla25xx_get_host(rsp);
1725 qla24xx_process_response_queue(vha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001726 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001727
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001728 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001729
1730 return IRQ_HANDLED;
1731}
1732
1733static irqreturn_t
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001734qla25xx_msix_rsp_q(int irq, void *dev_id)
1735{
1736 struct qla_hw_data *ha;
1737 struct rsp_que *rsp;
1738
1739 rsp = (struct rsp_que *) dev_id;
1740 if (!rsp) {
1741 printk(KERN_INFO
1742 "%s(): NULL response queue pointer\n", __func__);
1743 return IRQ_NONE;
1744 }
1745 ha = rsp->hw;
1746
1747 queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work);
1748
1749 return IRQ_HANDLED;
1750}
1751
1752static irqreturn_t
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001753qla24xx_msix_default(int irq, void *dev_id)
1754{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001755 scsi_qla_host_t *vha;
1756 struct qla_hw_data *ha;
1757 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001758 struct device_reg_24xx __iomem *reg;
1759 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001760 uint32_t stat;
1761 uint32_t hccr;
1762 uint16_t mb[4];
1763
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001764 rsp = (struct rsp_que *) dev_id;
1765 if (!rsp) {
1766 DEBUG(printk(
1767 "%s(): NULL response queue pointer\n", __func__));
1768 return IRQ_NONE;
1769 }
1770 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001771 reg = &ha->iobase->isp24;
1772 status = 0;
1773
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001774 spin_lock_irq(&ha->hardware_lock);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001775 vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001776 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001777 stat = RD_REG_DWORD(&reg->host_status);
1778 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001779 if (pci_channel_offline(ha->pdev))
1780 break;
1781
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001782 hccr = RD_REG_DWORD(&reg->hccr);
1783
1784 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1785 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001786
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001787 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001788
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001789 ha->isp_ops->fw_dump(vha, 1);
1790 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001791 break;
1792 } else if ((stat & HSRX_RISC_INT) == 0)
1793 break;
1794
1795 switch (stat & 0xff) {
1796 case 0x1:
1797 case 0x2:
1798 case 0x10:
1799 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001800 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001801 status |= MBX_INTERRUPT;
1802
1803 break;
1804 case 0x12:
1805 mb[0] = MSW(stat);
1806 mb[1] = RD_REG_WORD(&reg->mailbox1);
1807 mb[2] = RD_REG_WORD(&reg->mailbox2);
1808 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001809 qla2x00_async_event(vha, rsp, mb);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001810 break;
1811 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001812 case 0x14:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001813 qla24xx_process_response_queue(vha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001814 break;
1815 default:
1816 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1817 "(%d).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001818 vha->host_no, stat & 0xff));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001819 break;
1820 }
1821 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001822 } while (0);
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001823 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001824
1825 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1826 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001827 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001828 complete(&ha->mbx_intr_comp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001829 }
1830
1831 return IRQ_HANDLED;
1832}
1833
1834/* Interrupt handling helpers. */
1835
1836struct qla_init_msix_entry {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001837 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07001838 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001839};
1840
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001841static struct qla_init_msix_entry msix_entries[3] = {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001842 { "qla2xxx (default)", qla24xx_msix_default },
1843 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001844 { "qla2xxx (multiq)", qla25xx_msix_rsp_q },
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001845};
1846
1847static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001848qla24xx_disable_msix(struct qla_hw_data *ha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001849{
1850 int i;
1851 struct qla_msix_entry *qentry;
1852
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001853 for (i = 0; i < ha->msix_count; i++) {
1854 qentry = &ha->msix_entries[i];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001855 if (qentry->have_irq)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001856 free_irq(qentry->vector, qentry->rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001857 }
1858 pci_disable_msix(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001859 kfree(ha->msix_entries);
1860 ha->msix_entries = NULL;
1861 ha->flags.msix_enabled = 0;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001862}
1863
1864static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001865qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001866{
Lalit Chandivadead038fa2009-01-22 09:45:33 -08001867#define MIN_MSIX_COUNT 2
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001868 int i, ret;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001869 struct msix_entry *entries;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001870 struct qla_msix_entry *qentry;
1871
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001872 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
1873 GFP_KERNEL);
1874 if (!entries)
1875 return -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001876
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001877 for (i = 0; i < ha->msix_count; i++)
1878 entries[i].entry = i;
1879
1880 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001881 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08001882 if (ret < MIN_MSIX_COUNT)
1883 goto msix_failed;
1884
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001885 qla_printk(KERN_WARNING, ha,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001886 "MSI-X: Failed to enable support -- %d/%d\n"
1887 " Retry with %d vectors\n", ha->msix_count, ret, ret);
1888 ha->msix_count = ret;
1889 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
1890 if (ret) {
Lalit Chandivadead038fa2009-01-22 09:45:33 -08001891msix_failed:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001892 qla_printk(KERN_WARNING, ha, "MSI-X: Failed to enable"
1893 " support, giving up -- %d/%d\n",
1894 ha->msix_count, ret);
1895 goto msix_out;
1896 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001897 ha->max_rsp_queues = ha->msix_count - 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001898 }
1899 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
1900 ha->msix_count, GFP_KERNEL);
1901 if (!ha->msix_entries) {
1902 ret = -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001903 goto msix_out;
1904 }
1905 ha->flags.msix_enabled = 1;
1906
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001907 for (i = 0; i < ha->msix_count; i++) {
1908 qentry = &ha->msix_entries[i];
1909 qentry->vector = entries[i].vector;
1910 qentry->entry = entries[i].entry;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001911 qentry->have_irq = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001912 qentry->rsp = NULL;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001913 }
1914
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001915 /* Enable MSI-X vectors for the base queue */
1916 for (i = 0; i < 2; i++) {
1917 qentry = &ha->msix_entries[i];
1918 ret = request_irq(qentry->vector, msix_entries[i].handler,
1919 0, msix_entries[i].name, rsp);
1920 if (ret) {
1921 qla_printk(KERN_WARNING, ha,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001922 "MSI-X: Unable to register handler -- %x/%d.\n",
1923 qentry->vector, ret);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001924 qla24xx_disable_msix(ha);
1925 ha->mqenable = 0;
1926 goto msix_out;
1927 }
1928 qentry->have_irq = 1;
1929 qentry->rsp = rsp;
1930 rsp->msix = qentry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001931 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001932
1933 /* Enable MSI-X vector for response queue update for queue 0 */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001934 if (ha->mqiobase && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001935 ha->mqenable = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001936
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001937msix_out:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001938 kfree(entries);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001939 return ret;
1940}
1941
1942int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001943qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001944{
1945 int ret;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001946 device_reg_t __iomem *reg = ha->iobase;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001947
1948 /* If possible, enable MSI-X. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001949 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) &&
1950 !IS_QLA8432(ha) && !IS_QLA8001(ha))
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001951 goto skip_msix;
1952
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001953 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX ||
1954 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001955 DEBUG2(qla_printk(KERN_WARNING, ha,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001956 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1957 ha->pdev->revision, ha->fw_attributes));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001958
1959 goto skip_msix;
1960 }
1961
Andrew Vasquezda7429f2008-01-17 09:02:11 -08001962 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
1963 (ha->pdev->subsystem_device == 0x7040 ||
1964 ha->pdev->subsystem_device == 0x7041 ||
1965 ha->pdev->subsystem_device == 0x1705)) {
1966 DEBUG2(qla_printk(KERN_WARNING, ha,
1967 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
1968 ha->pdev->subsystem_vendor,
1969 ha->pdev->subsystem_device));
1970
1971 goto skip_msi;
1972 }
1973
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001974 ret = qla24xx_enable_msix(ha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001975 if (!ret) {
1976 DEBUG2(qla_printk(KERN_INFO, ha,
1977 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1978 ha->fw_attributes));
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001979 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001980 }
1981 qla_printk(KERN_WARNING, ha,
1982 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1983skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001984
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001985 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
1986 !IS_QLA8001(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001987 goto skip_msi;
1988
1989 ret = pci_enable_msi(ha->pdev);
1990 if (!ret) {
1991 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1992 ha->flags.msi_enabled = 1;
1993 }
1994skip_msi:
1995
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001996 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Giridhar Malavalid1b1bef2009-03-24 09:08:13 -07001997 IRQF_SHARED, QLA2XXX_DRIVER_NAME, rsp);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001998 if (ret) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001999 qla_printk(KERN_WARNING, ha,
2000 "Failed to reserve interrupt %d already in use.\n",
2001 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002002 goto fail;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002003 }
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002004 ha->flags.inta_enabled = 1;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002005clear_risc_ints:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002006
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002007 /*
2008 * FIXME: Noted that 8014s were being dropped during NK testing.
2009 * Timing deltas during MSI-X/INTa transitions?
2010 */
2011 if (IS_QLA81XX(ha))
2012 goto fail;
Andrew Vasquezc6952482008-04-03 13:13:17 -07002013 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002014 if (IS_FWI2_CAPABLE(ha)) {
2015 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
2016 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
2017 } else {
2018 WRT_REG_WORD(&reg->isp.semaphore, 0);
2019 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
2020 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
2021 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07002022 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002023
2024fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002025 return ret;
2026}
2027
2028void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002029qla2x00_free_irqs(scsi_qla_host_t *vha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002030{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002031 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002032 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002033
2034 if (ha->flags.msix_enabled)
2035 qla24xx_disable_msix(ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002036 else if (ha->flags.inta_enabled) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002037 free_irq(ha->pdev->irq, rsp);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002038 pci_disable_msi(ha->pdev);
2039 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002040}
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002041
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002042
2043int qla25xx_request_irq(struct rsp_que *rsp)
2044{
2045 struct qla_hw_data *ha = rsp->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002046 struct qla_init_msix_entry *intr = &msix_entries[2];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002047 struct qla_msix_entry *msix = rsp->msix;
2048 int ret;
2049
2050 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
2051 if (ret) {
2052 qla_printk(KERN_WARNING, ha,
2053 "MSI-X: Unable to register handler -- %x/%d.\n",
2054 msix->vector, ret);
2055 return ret;
2056 }
2057 msix->have_irq = 1;
2058 msix->rsp = rsp;
2059 return ret;
2060}
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002061
2062struct scsi_qla_host *
2063qla25xx_get_host(struct rsp_que *rsp)
2064{
2065 srb_t *sp;
2066 struct qla_hw_data *ha = rsp->hw;
2067 struct scsi_qla_host *vha = NULL;
2068 struct sts_entry_24xx *pkt;
2069 struct req_que *req;
2070 uint16_t que;
2071 uint32_t handle;
2072
2073 pkt = (struct sts_entry_24xx *) rsp->ring_ptr;
2074 que = MSW(pkt->handle);
2075 handle = (uint32_t) LSW(pkt->handle);
2076 req = ha->req_q_map[que];
2077 if (handle < MAX_OUTSTANDING_COMMANDS) {
2078 sp = req->outstanding_cmds[handle];
2079 if (sp)
2080 return sp->fcport->vha;
2081 else
2082 goto base_que;
2083 }
2084base_que:
2085 vha = pci_get_drvdata(ha->pdev);
2086 return vha;
2087}