blob: d5fb79a880018cf7f0ddb461e3fcf1df5a68451f [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 *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070016static void qla2x00_status_cont_entry(scsi_qla_host_t *, 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 *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080019static struct scsi_qla_host *qla2x00_get_rsp_host(struct rsp_que *);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021/**
22 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
23 * @irq:
24 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 *
26 * Called by system whenever the host adapter generates an interrupt.
27 *
28 * Returns handled flag.
29 */
30irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +010031qla2100_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080033 scsi_qla_host_t *vha;
34 struct qla_hw_data *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -070035 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 unsigned long iter;
Seokmann Ju14e660e2007-09-20 14:07:36 -070038 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070039 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080040 struct rsp_que *rsp;
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
Andrew Vasquezc6952482008-04-03 13:13:17 -070053 spin_lock(&ha->hardware_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080054 vha = qla2x00_get_rsp_host(rsp);
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 }
Andrew Vasquezc6952482008-04-03 13:13:17 -0700105 spin_unlock(&ha->hardware_lock);
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800138 rsp = (struct rsp_que *) dev_id;
139 if (!rsp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800141 "%s(): NULL response queue pointer\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 return (IRQ_NONE);
143 }
144
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800145 ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700146 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 status = 0;
148
Andrew Vasquezc6952482008-04-03 13:13:17 -0700149 spin_lock(&ha->hardware_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800150 vha = qla2x00_get_rsp_host(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 for (iter = 50; iter--; ) {
152 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
153 if (stat & HSR_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -0700154 if (pci_channel_offline(ha->pdev))
155 break;
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 hccr = RD_REG_WORD(&reg->hccr);
158 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Andrew Vasquez07f31802006-12-13 19:20:31 -0800159 qla_printk(KERN_INFO, ha, "Parity error -- "
160 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 else
Andrew Vasquez07f31802006-12-13 19:20:31 -0800162 qla_printk(KERN_INFO, ha, "RISC paused -- "
163 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165 /*
166 * Issue a "HARD" reset in order for the RISC
167 * interrupt bit to be cleared. Schedule a big
168 * hammmer to get out of the RISC PAUSED state.
169 */
170 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
171 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800172
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800173 ha->isp_ops->fw_dump(vha, 1);
174 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 break;
176 } else if ((stat & HSR_RISC_INT) == 0)
177 break;
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 case 0x1:
181 case 0x2:
182 case 0x10:
183 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800184 qla2x00_mbx_completion(vha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 status |= MBX_INTERRUPT;
186
187 /* Release mailbox registers. */
188 WRT_REG_WORD(&reg->semaphore, 0);
189 break;
190 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700191 mb[0] = MSW(stat);
192 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
193 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
194 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800195 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700196 break;
197 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800198 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 break;
200 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700201 mb[0] = MBA_CMPLT_1_16BIT;
202 mb[1] = MSW(stat);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800203 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 break;
205 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700206 mb[0] = MBA_SCSI_COMPLETION;
207 mb[1] = MSW(stat);
208 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800209 qla2x00_async_event(vha, rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 break;
211 default:
212 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700213 "(%d).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800214 vha->host_no, stat & 0xff));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 break;
216 }
217 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
218 RD_REG_WORD_RELAXED(&reg->hccr);
219 }
Andrew Vasquezc6952482008-04-03 13:13:17 -0700220 spin_unlock(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
223 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800225 complete(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 }
227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 return (IRQ_HANDLED);
229}
230
231/**
232 * qla2x00_mbx_completion() - Process mailbox command completions.
233 * @ha: SCSI driver HA context
234 * @mb0: Mailbox0 register
235 */
236static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800237qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238{
239 uint16_t cnt;
240 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800241 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700242 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244 /* Load return mailbox registers. */
245 ha->flags.mbox_int = 1;
246 ha->mailbox_out[0] = mb0;
247 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
248
249 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700250 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
252 if (cnt == 4 || cnt == 5)
253 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
254 else
255 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 wptr++;
258 }
259
260 if (ha->mcp) {
261 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800262 __func__, vha->host_no, ha->mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 } else {
264 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800265 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 }
267}
268
269/**
270 * qla2x00_async_event() - Process aynchronous events.
271 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700272 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700274void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800275qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700277#define LS_UNKNOWN 2
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700278 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 char *link_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 uint16_t handle_cnt;
281 uint16_t cnt;
282 uint32_t handles[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800283 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700284 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 uint32_t rscn_entry, host_pid;
286 uint8_t rscn_queue_index;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700287 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289 /* Setup to process RIO completion. */
290 handle_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 switch (mb[0]) {
292 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700293 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 handle_cnt = 1;
295 break;
296 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700297 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 handle_cnt = 1;
299 mb[0] = MBA_SCSI_COMPLETION;
300 break;
301 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700302 handles[0] = mb[1];
303 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 handle_cnt = 2;
305 mb[0] = MBA_SCSI_COMPLETION;
306 break;
307 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700308 handles[0] = mb[1];
309 handles[1] = mb[2];
310 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 handle_cnt = 3;
312 mb[0] = MBA_SCSI_COMPLETION;
313 break;
314 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700315 handles[0] = mb[1];
316 handles[1] = mb[2];
317 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
319 handle_cnt = 4;
320 mb[0] = MBA_SCSI_COMPLETION;
321 break;
322 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700323 handles[0] = mb[1];
324 handles[1] = mb[2];
325 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
327 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
328 handle_cnt = 5;
329 mb[0] = MBA_SCSI_COMPLETION;
330 break;
331 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700332 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 handles[1] = le32_to_cpu(
334 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
335 RD_MAILBOX_REG(ha, reg, 6));
336 handle_cnt = 2;
337 mb[0] = MBA_SCSI_COMPLETION;
338 break;
339 default:
340 break;
341 }
342
343 switch (mb[0]) {
344 case MBA_SCSI_COMPLETION: /* Fast Post */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800345 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 break;
347
348 for (cnt = 0; cnt < handle_cnt; cnt++)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800349 qla2x00_process_completed_request(vha, rsp->req,
350 handles[cnt]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 break;
352
353 case MBA_RESET: /* Reset */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800354 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n",
355 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800357 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 break;
359
360 case MBA_SYSTEM_ERR: /* System Error */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 qla_printk(KERN_INFO, ha,
362 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
363 mb[1], mb[2], mb[3]);
364
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800365 qla2x00_post_hwe_work(vha, mb[0], mb[1], mb[2], mb[3]);
366 ha->isp_ops->fw_dump(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Andrew Vasqueze4289242007-07-19 15:05:56 -0700368 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700369 if (mb[1] == 0 && mb[2] == 0) {
370 qla_printk(KERN_ERR, ha,
371 "Unrecoverable Hardware Error: adapter "
372 "marked OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800373 vha->flags.online = 0;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700374 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800375 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700376 } else if (mb[1] == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 qla_printk(KERN_INFO, ha,
378 "Unrecoverable Hardware Error: adapter marked "
379 "OFFLINE!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800380 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800382 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 break;
384
385 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
386 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800387 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
389
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800390 qla2x00_post_hwe_work(vha, mb[0], mb[1], mb[2], mb[3]);
391 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 break;
393
394 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
395 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800396 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
398
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800399 qla2x00_post_hwe_work(vha, mb[0], mb[1], mb[2], mb[3]);
400 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 break;
402
403 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
404 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800405 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 break;
407
408 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800409 DEBUG2(printk("scsi(%ld): LIP occurred (%x).\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 mb[1]));
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700411 qla_printk(KERN_INFO, ha, "LIP occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800413 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
414 atomic_set(&vha->loop_state, LOOP_DOWN);
415 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
416 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 }
418
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800419 if (vha->vp_idx) {
420 atomic_set(&vha->vp_state, VP_FAILED);
421 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700422 }
423
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800424 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
425 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800427 vha->flags.management_server_logged_in = 0;
428 qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 break;
430
431 case MBA_LOOP_UP: /* Loop Up Event */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
433 link_speed = link_speeds[0];
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700434 ha->link_data_rate = PORT_SPEED_1GB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 } else {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700436 link_speed = link_speeds[LS_UNKNOWN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 if (mb[1] < 5)
438 link_speed = link_speeds[mb[1]];
439 ha->link_data_rate = mb[1];
440 }
441
442 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800443 vha->host_no, link_speed));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
445 link_speed);
446
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800447 vha->flags.management_server_logged_in = 0;
448 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 break;
450
451 case MBA_LOOP_DOWN: /* Loop Down Event */
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700452 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800453 "(%x %x %x).\n", vha->host_no, mb[1], mb[2], mb[3]));
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700454 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x %x %x).\n",
455 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800457 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
458 atomic_set(&vha->loop_state, LOOP_DOWN);
459 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
460 vha->device_flags |= DFLG_NO_CABLE;
461 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 }
463
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800464 if (vha->vp_idx) {
465 atomic_set(&vha->vp_state, VP_FAILED);
466 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700467 }
468
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800469 vha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700470 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800471 qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 break;
473
474 case MBA_LIP_RESET: /* LIP reset occurred */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800476 vha->host_no, mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 qla_printk(KERN_INFO, ha,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700478 "LIP reset occurred (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800480 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
481 atomic_set(&vha->loop_state, LOOP_DOWN);
482 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
483 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 }
485
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800486 if (vha->vp_idx) {
487 atomic_set(&vha->vp_state, VP_FAILED);
488 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700489 }
490
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800491 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 ha->operating_mode = LOOP;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800494 vha->flags.management_server_logged_in = 0;
495 qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 break;
497
498 case MBA_POINT_TO_POINT: /* Point-to-Point */
499 if (IS_QLA2100(ha))
500 break;
501
502 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800503 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505 /*
506 * Until there's a transition from loop down to loop up, treat
507 * this as loop down only.
508 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800509 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
510 atomic_set(&vha->loop_state, LOOP_DOWN);
511 if (!atomic_read(&vha->loop_down_timer))
512 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800514 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 }
516
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800517 if (vha->vp_idx) {
518 atomic_set(&vha->vp_state, VP_FAILED);
519 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700520 }
521
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800522 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
523 set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
524
525 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
526 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800527
528 ha->flags.gpsc_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800529 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 break;
531
532 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
533 if (IS_QLA2100(ha))
534 break;
535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
537 "received.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800538 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 qla_printk(KERN_INFO, ha,
540 "Configuration change detected: value=%x.\n", mb[1]);
541
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800542 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
543 atomic_set(&vha->loop_state, LOOP_DOWN);
544 if (!atomic_read(&vha->loop_down_timer))
545 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 LOOP_DOWN_TIME);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800547 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 }
549
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800550 if (vha->vp_idx) {
551 atomic_set(&vha->vp_state, VP_FAILED);
552 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700553 }
554
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800555 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
556 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 break;
558
559 case MBA_PORT_UPDATE: /* Port database update */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800560 /* Only handle SCNs for our Vport index. */
561 if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff))
562 break;
563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 /*
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700565 * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 * event etc. earlier indicating loop is down) then process
567 * it. Otherwise ignore it and Wait for RSCN to come in.
568 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800569 atomic_set(&vha->loop_down_timer, 0);
570 if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
571 atomic_read(&vha->loop_state) != LOOP_DEAD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800573 "ignored %04x/%04x/%04x.\n", vha->host_no, mb[1],
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700574 mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 break;
576 }
577
578 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800579 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 DEBUG(printk(KERN_INFO
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700581 "scsi(%ld): Port database changed %04x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800582 vha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
584 /*
585 * Mark all devices as missing so we will login again.
586 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800587 atomic_set(&vha->loop_state, LOOP_UP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800589 qla2x00_mark_all_devices_lost(vha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800591 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800593 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
594 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 break;
596
597 case MBA_RSCN_UPDATE: /* State Change Registration */
Seokmann Ju3c397402008-05-19 14:25:39 -0700598 /* Check if the Vport has issued a SCR */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800599 if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
Seokmann Ju3c397402008-05-19 14:25:39 -0700600 break;
601 /* Only handle SCNs for our Vport index. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800602 if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff))
Seokmann Ju3c397402008-05-19 14:25:39 -0700603 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800605 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 DEBUG(printk(KERN_INFO
Shyam Sundarf4a8dbc2007-11-12 10:30:59 -0800607 "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800608 vha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Ravi Anand59d72d82008-09-11 21:22:53 -0700610 rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800611 host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
612 | vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 if (rscn_entry == host_pid) {
614 DEBUG(printk(KERN_INFO
615 "scsi(%ld): Ignoring RSCN update to local host "
616 "port ID (%06x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800617 vha->host_no, host_pid));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 break;
619 }
620
Ravi Anand59d72d82008-09-11 21:22:53 -0700621 /* Ignore reserved bits from RSCN-payload. */
622 rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800623 rscn_queue_index = vha->rscn_in_ptr + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 if (rscn_queue_index == MAX_RSCN_COUNT)
625 rscn_queue_index = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800626 if (rscn_queue_index != vha->rscn_out_ptr) {
627 vha->rscn_queue[vha->rscn_in_ptr] = rscn_entry;
628 vha->rscn_in_ptr = rscn_queue_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800630 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 }
632
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800633 atomic_set(&vha->loop_state, LOOP_UPDATE);
634 atomic_set(&vha->loop_down_timer, 0);
635 vha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800637 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
638 set_bit(RSCN_UPDATE, &vha->dpc_flags);
639 qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 break;
641
642 /* case MBA_RIO_RESPONSE: */
643 case MBA_ZIO_RESPONSE:
644 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800645 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 DEBUG(printk(KERN_INFO
647 "scsi(%ld): [R|Z]IO update completion.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800648 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Andrew Vasqueze4289242007-07-19 15:05:56 -0700650 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800651 qla24xx_process_response_queue(rsp);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700652 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800653 qla2x00_process_response_queue(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700655
656 case MBA_DISCARD_RND_FRAME:
657 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800658 "%04x.\n", vha->host_no, mb[1], mb[2], mb[3]));
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700659 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700660
661 case MBA_TRACE_NOTIFICATION:
662 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800663 vha->host_no, mb[1], mb[2]));
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700664 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700665
666 case MBA_ISP84XX_ALERT:
667 DEBUG2(printk("scsi(%ld): ISP84XX Alert Notification -- "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800668 "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700669
670 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
671 switch (mb[1]) {
672 case A84_PANIC_RECOVERY:
673 qla_printk(KERN_INFO, ha, "Alert 84XX: panic recovery "
674 "%04x %04x\n", mb[2], mb[3]);
675 break;
676 case A84_OP_LOGIN_COMPLETE:
677 ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
678 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
679 "firmware version %x\n", ha->cs84xx->op_fw_version));
680 break;
681 case A84_DIAG_LOGIN_COMPLETE:
682 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
683 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
684 "diagnostic firmware version %x\n",
685 ha->cs84xx->diag_fw_version));
686 break;
687 case A84_GOLD_LOGIN_COMPLETE:
688 ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
689 ha->cs84xx->fw_update = 1;
690 DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX: gold "
691 "firmware version %x\n",
692 ha->cs84xx->gold_fw_version));
693 break;
694 default:
695 qla_printk(KERN_ERR, ha,
696 "Alert 84xx: Invalid Alert %04x %04x %04x\n",
697 mb[1], mb[2], mb[3]);
698 }
699 spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
700 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700702
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800703 if (!vha->vp_idx && ha->num_vhosts)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800704 qla2x00_alert_all_vps(rsp, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705}
706
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700707static void
708qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
709{
710 fc_port_t *fcport = data;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800711 struct scsi_qla_host *vha = fcport->vha;
712 struct qla_hw_data *ha = vha->hw;
713 struct req_que *req = NULL;
714
715 req = ha->req_q_map[vha->req_ques[0]];
716 if (!req)
717 return;
718 if (req->max_q_depth <= sdev->queue_depth)
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700719 return;
720
721 if (sdev->ordered_tags)
722 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
723 sdev->queue_depth + 1);
724 else
725 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
726 sdev->queue_depth + 1);
727
728 fcport->last_ramp_up = jiffies;
729
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800730 DEBUG2(qla_printk(KERN_INFO, ha,
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700731 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800732 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700733 sdev->queue_depth));
734}
735
736static void
737qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
738{
739 fc_port_t *fcport = data;
740
741 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
742 return;
743
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800744 DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700745 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800746 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700747 sdev->queue_depth));
748}
749
750static inline void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800751qla2x00_ramp_up_queue_depth(scsi_qla_host_t *vha, struct req_que *req,
752 srb_t *sp)
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700753{
754 fc_port_t *fcport;
755 struct scsi_device *sdev;
756
757 sdev = sp->cmd->device;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800758 if (sdev->queue_depth >= req->max_q_depth)
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700759 return;
760
761 fcport = sp->fcport;
762 if (time_before(jiffies,
763 fcport->last_ramp_up + ql2xqfullrampup * HZ))
764 return;
765 if (time_before(jiffies,
766 fcport->last_queue_full + ql2xqfullrampup * HZ))
767 return;
768
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700769 starget_for_each_device(sdev->sdev_target, fcport,
770 qla2x00_adjust_sdev_qdepth_up);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700771}
772
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773/**
774 * qla2x00_process_completed_request() - Process a Fast Post response.
775 * @ha: SCSI driver HA context
776 * @index: SRB index
777 */
778static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800779qla2x00_process_completed_request(struct scsi_qla_host *vha,
780 struct req_que *req, uint32_t index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781{
782 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800783 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
785 /* Validate handle. */
786 if (index >= MAX_OUTSTANDING_COMMANDS) {
787 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800788 vha->host_no, index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 qla_printk(KERN_WARNING, ha,
790 "Invalid SCSI completion handle %d.\n", index);
791
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800792 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 return;
794 }
795
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800796 sp = req->outstanding_cmds[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 if (sp) {
798 /* Free outstanding command slot. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800799 req->outstanding_cmds[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 CMD_COMPL_STATUS(sp->cmd) = 0L;
802 CMD_SCSI_STATUS(sp->cmd) = 0L;
803
804 /* Save ISP completion status */
805 sp->cmd->result = DID_OK << 16;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700806
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800807 qla2x00_ramp_up_queue_depth(vha, req, sp);
808 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 } else {
810 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800811 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 qla_printk(KERN_WARNING, ha,
813 "Invalid ISP SCSI completion handle\n");
814
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800815 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 }
817}
818
819/**
820 * qla2x00_process_response_queue() - Process response queue entries.
821 * @ha: SCSI driver HA context
822 */
823void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800824qla2x00_process_response_queue(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825{
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800826 struct scsi_qla_host *vha;
827 struct qla_hw_data *ha = rsp->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700828 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 sts_entry_t *pkt;
830 uint16_t handle_cnt;
831 uint16_t cnt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800832
833 vha = qla2x00_get_rsp_host(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800835 if (!vha->flags.online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 return;
837
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800838 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
839 pkt = (sts_entry_t *)rsp->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800841 rsp->ring_index++;
842 if (rsp->ring_index == rsp->length) {
843 rsp->ring_index = 0;
844 rsp->ring_ptr = rsp->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800846 rsp->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 }
848
849 if (pkt->entry_status != 0) {
850 DEBUG3(printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800851 "scsi(%ld): Process error entry.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800853 qla2x00_error_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
855 wmb();
856 continue;
857 }
858
859 switch (pkt->entry_type) {
860 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800861 qla2x00_status_entry(vha, rsp, pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 break;
863 case STATUS_TYPE_21:
864 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
865 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800866 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 ((sts21_entry_t *)pkt)->handle[cnt]);
868 }
869 break;
870 case STATUS_TYPE_22:
871 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
872 for (cnt = 0; cnt < handle_cnt; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800873 qla2x00_process_completed_request(vha, rsp->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 ((sts22_entry_t *)pkt)->handle[cnt]);
875 }
876 break;
877 case STATUS_CONT_TYPE:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800878 qla2x00_status_cont_entry(vha, (sts_cont_entry_t *)pkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 default:
881 /* Type Not Supported. */
882 DEBUG4(printk(KERN_WARNING
883 "scsi(%ld): Received unknown response pkt type %x "
884 "entry status=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800885 vha->host_no, pkt->entry_type, pkt->entry_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 break;
887 }
888 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
889 wmb();
890 }
891
892 /* Adjust ring index */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800893 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894}
895
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800896static inline void
897qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len)
898{
899 struct scsi_cmnd *cp = sp->cmd;
900
901 if (sense_len >= SCSI_SENSE_BUFFERSIZE)
902 sense_len = SCSI_SENSE_BUFFERSIZE;
903
904 CMD_ACTUAL_SNSLEN(cp) = sense_len;
905 sp->request_sense_length = sense_len;
906 sp->request_sense_ptr = cp->sense_buffer;
907 if (sp->request_sense_length > 32)
908 sense_len = 32;
909
910 memcpy(cp->sense_buffer, sense_data, sense_len);
911
912 sp->request_sense_ptr += sense_len;
913 sp->request_sense_length -= sense_len;
914 if (sp->request_sense_length != 0)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800915 sp->fcport->vha->status_srb = sp;
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800916
917 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800918 "cmd=%p pid=%ld\n", __func__, sp->fcport->vha->host_no,
Andrew Vasquez19851f12008-08-13 21:37:00 -0700919 cp->device->channel, cp->device->id, cp->device->lun, cp,
920 cp->serial_number));
Andrew Vasquez4733fcb2008-01-17 09:02:07 -0800921 if (sense_len)
922 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
923 CMD_ACTUAL_SNSLEN(cp)));
924}
925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926/**
927 * qla2x00_status_entry() - Process a Status IOCB entry.
928 * @ha: SCSI driver HA context
929 * @pkt: Entry pointer
930 */
931static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800932qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 fc_port_t *fcport;
936 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700937 sts_entry_t *sts;
938 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 uint16_t comp_status;
940 uint16_t scsi_status;
941 uint8_t lscsi_status;
942 int32_t resid;
Ravi Ananded17c71b52006-05-17 15:08:55 -0700943 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700944 uint8_t *rsp_info, *sense_data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800945 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800946 struct req_que *req = rsp->req;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700947
948 sts = (sts_entry_t *) pkt;
949 sts24 = (struct sts_entry_24xx *) pkt;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700950 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700951 comp_status = le16_to_cpu(sts24->comp_status);
952 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
953 } else {
954 comp_status = le16_to_cpu(sts->comp_status);
955 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
956 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
958 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700959 if (comp_status == CS_COMPLETE && scsi_status == 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800960 qla2x00_process_completed_request(vha, req, sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
962 return;
963 }
964
965 /* Validate handle. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700966 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800967 sp = req->outstanding_cmds[sts->handle];
968 req->outstanding_cmds[sts->handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 } else
970 sp = NULL;
971
972 if (sp == NULL) {
973 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800974 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
976
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800977 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
978 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 return;
980 }
981 cp = sp->cmd;
982 if (cp == NULL) {
983 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800984 "pkt->handle=%d sp=%p.\n", vha->host_no, sts->handle, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 qla_printk(KERN_WARNING, ha,
986 "Command is NULL: already returned to OS (sp=%p)\n", sp);
987
988 return;
989 }
990
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700991 lscsi_status = scsi_status & STATUS_MASK;
992 CMD_ENTRY_STATUS(cp) = sts->entry_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 CMD_COMPL_STATUS(cp) = comp_status;
994 CMD_SCSI_STATUS(cp) = scsi_status;
995
bdf79622005-04-17 15:06:53 -0500996 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Ravi Ananded17c71b52006-05-17 15:08:55 -0700998 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700999 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001000 sense_len = le32_to_cpu(sts24->sense_len);
1001 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
1002 resid_len = le32_to_cpu(sts24->rsp_residual_count);
Ravi Ananded17c71b52006-05-17 15:08:55 -07001003 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001004 rsp_info = sts24->data;
1005 sense_data = sts24->data;
1006 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
1007 } else {
1008 sense_len = le16_to_cpu(sts->req_sense_length);
1009 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
1010 resid_len = le32_to_cpu(sts->residual_length);
1011 rsp_info = sts->rsp_info;
1012 sense_data = sts->req_sense_data;
1013 }
1014
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 /* Check for any FCP transport errors. */
1016 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001017 /* Sense data lies beyond any FCP RESPONSE data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001018 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001019 sense_data += rsp_info_len;
1020 if (rsp_info_len > 3 && rsp_info[3]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
1022 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001023 "retrying command\n", vha->host_no,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001024 cp->device->channel, cp->device->id,
1025 cp->device->lun, rsp_info_len, rsp_info[0],
1026 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
1027 rsp_info[5], rsp_info[6], rsp_info[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
1029 cp->result = DID_BUS_BUSY << 16;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001030 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 return;
1032 }
1033 }
1034
Andrew Vasquez3e8ce322008-02-28 14:06:10 -08001035 /* Check for overrun. */
1036 if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
1037 scsi_status & SS_RESIDUAL_OVER)
1038 comp_status = CS_DATA_OVERRUN;
1039
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 /*
1041 * Based on Host and scsi status generate status code for Linux
1042 */
1043 switch (comp_status) {
1044 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001045 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 if (scsi_status == 0) {
1047 cp->result = DID_OK << 16;
1048 break;
1049 }
1050 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001051 resid = resid_len;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001052 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 CMD_RESID_LEN(cp) = resid;
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001054
1055 if (!lscsi_status &&
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001056 ((unsigned)(scsi_bufflen(cp) - resid) <
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001057 cp->underflow)) {
1058 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001059 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1060 "detected (%x of %x bytes)...returning "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001061 "error status.\n", vha->host_no,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001062 cp->device->channel, cp->device->id,
1063 cp->device->lun, resid,
1064 scsi_bufflen(cp));
Andrew Vasquez0da69df2005-12-06 10:58:06 -08001065
1066 cp->result = DID_ERROR << 16;
1067 break;
1068 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 cp->result = DID_OK << 16 | lscsi_status;
1071
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001072 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1073 DEBUG2(printk(KERN_INFO
1074 "scsi(%ld): QUEUE FULL status detected "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001075 "0x%x-0x%x.\n", vha->host_no, comp_status,
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001076 scsi_status));
1077
1078 /* Adjust queue depth for all luns on the port. */
1079 fcport->last_queue_full = jiffies;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001080 starget_for_each_device(cp->device->sdev_target,
1081 fcport, qla2x00_adjust_sdev_qdepth_down);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001082 break;
1083 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 if (lscsi_status != SS_CHECK_CONDITION)
1085 break;
1086
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001087 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 if (!(scsi_status & SS_SENSE_LEN_VALID))
1089 break;
1090
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001091 qla2x00_handle_sense(sp, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 break;
1093
1094 case CS_DATA_UNDERRUN:
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001095 resid = resid_len;
Ravi Ananded17c71b52006-05-17 15:08:55 -07001096 /* Use F/W calculated residual length. */
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001097 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez2d136932008-09-11 21:22:52 -07001098 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1099 lscsi_status = 0;
1100 } else if (resid != fw_resid_len) {
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001101 scsi_status &= ~SS_RESIDUAL_UNDER;
1102 lscsi_status = 0;
1103 }
Ravi Ananded17c71b52006-05-17 15:08:55 -07001104 resid = fw_resid_len;
Andrew Vasquez6acf8192007-10-19 15:59:18 -07001105 }
Ravi Ananded17c71b52006-05-17 15:08:55 -07001106
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 if (scsi_status & SS_RESIDUAL_UNDER) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001108 scsi_set_resid(cp, resid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 CMD_RESID_LEN(cp) = resid;
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -08001110 } else {
1111 DEBUG2(printk(KERN_INFO
1112 "scsi(%ld:%d:%d) UNDERRUN status detected "
Ravi Ananded17c71b52006-05-17 15:08:55 -07001113 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001114 "os_underflow=0x%x\n", vha->host_no,
Ravi Ananded17c71b52006-05-17 15:08:55 -07001115 cp->device->id, cp->device->lun, comp_status,
1116 scsi_status, resid_len, resid, cp->cmnd[0],
1117 cp->underflow));
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -08001118
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 }
1120
1121 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001122 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 * Status.
1124 */
1125 if (lscsi_status != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 cp->result = DID_OK << 16 | lscsi_status;
1127
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001128 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
1129 DEBUG2(printk(KERN_INFO
1130 "scsi(%ld): QUEUE FULL status detected "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001131 "0x%x-0x%x.\n", vha->host_no, comp_status,
Andrew Vasquezffec28a2007-01-29 10:22:27 -08001132 scsi_status));
1133
1134 /*
1135 * Adjust queue depth for all luns on the
1136 * port.
1137 */
1138 fcport->last_queue_full = jiffies;
1139 starget_for_each_device(
1140 cp->device->sdev_target, fcport,
1141 qla2x00_adjust_sdev_qdepth_down);
1142 break;
1143 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 if (lscsi_status != SS_CHECK_CONDITION)
1145 break;
1146
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001147 memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 if (!(scsi_status & SS_SENSE_LEN_VALID))
1149 break;
1150
Andrew Vasquez4733fcb2008-01-17 09:02:07 -08001151 qla2x00_handle_sense(sp, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 } else {
1153 /*
1154 * If RISC reports underrun and target does not report
1155 * it then we must have a lost frame, so tell upper
1156 * layer to retry it by reporting a bus busy.
1157 */
1158 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1159 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001160 "frame(s) detected (%x of %x bytes)..."
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001161 "retrying command.\n",
1162 vha->host_no, cp->device->channel,
1163 cp->device->id, cp->device->lun, resid,
1164 scsi_bufflen(cp)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
1166 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 break;
1168 }
1169
1170 /* Handle mid-layer underflow */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001171 if ((unsigned)(scsi_bufflen(cp) - resid) <
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 cp->underflow) {
1173 qla_printk(KERN_INFO, ha,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001174 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1175 "detected (%x of %x bytes)...returning "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001176 "error status.\n", vha->host_no,
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001177 cp->device->channel, cp->device->id,
1178 cp->device->lun, resid,
1179 scsi_bufflen(cp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
1181 cp->result = DID_ERROR << 16;
1182 break;
1183 }
1184
1185 /* Everybody online, looking good... */
1186 cp->result = DID_OK << 16;
1187 }
1188 break;
1189
1190 case CS_DATA_OVERRUN:
1191 DEBUG2(printk(KERN_INFO
1192 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001193 vha->host_no, cp->device->id, cp->device->lun, comp_status,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001194 scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 DEBUG2(printk(KERN_INFO
1196 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1197 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1198 cp->cmnd[4], cp->cmnd[5]));
1199 DEBUG2(printk(KERN_INFO
1200 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1201 "status!\n",
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001202 cp->serial_number, scsi_bufflen(cp), resid_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
1204 cp->result = DID_ERROR << 16;
1205 break;
1206
1207 case CS_PORT_LOGGED_OUT:
1208 case CS_PORT_CONFIG_CHG:
1209 case CS_PORT_BUSY:
1210 case CS_INCOMPLETE:
1211 case CS_PORT_UNAVAILABLE:
1212 /*
1213 * If the port is in Target Down state, return all IOs for this
1214 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1215 * retry_queue.
1216 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1218 "pid=%ld, compl status=0x%x, port state=0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001219 vha->host_no, cp->device->id, cp->device->lun,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001220 cp->serial_number, comp_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 atomic_read(&fcport->state)));
1222
Mike Christie056a4482008-08-19 18:45:29 -05001223 /*
1224 * We are going to have the fc class block the rport
1225 * while we try to recover so instruct the mid layer
1226 * to requeue until the class decides how to handle this.
1227 */
1228 cp->result = DID_TRANSPORT_DISRUPTED << 16;
Andrew Vasqueza7a28502008-08-13 21:36:57 -07001229 if (atomic_read(&fcport->state) == FCS_ONLINE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001230 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 break;
1232
1233 case CS_RESET:
1234 DEBUG2(printk(KERN_INFO
1235 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001236 vha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
f4f051e2005-04-17 15:02:26 -05001238 cp->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 break;
1240
1241 case CS_ABORTED:
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001242 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 * hv2.19.12 - DID_ABORT does not retry the request if we
1244 * aborted this request then abort otherwise it must be a
1245 * reset.
1246 */
1247 DEBUG2(printk(KERN_INFO
1248 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001249 vha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
1251 cp->result = DID_RESET << 16;
1252 break;
1253
1254 case CS_TIMEOUT:
Mike Christie056a4482008-08-19 18:45:29 -05001255 /*
1256 * We are going to have the fc class block the rport
1257 * while we try to recover so instruct the mid layer
1258 * to requeue until the class decides how to handle this.
1259 */
1260 cp->result = DID_TRANSPORT_DISRUPTED << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Andrew Vasqueze4289242007-07-19 15:05:56 -07001262 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001263 DEBUG2(printk(KERN_INFO
1264 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001265 "0x%x-0x%x\n", vha->host_no, cp->device->channel,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001266 cp->device->id, cp->device->lun, comp_status,
1267 scsi_status));
1268 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001270 DEBUG2(printk(KERN_INFO
1271 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001272 "sflags=%x.\n", vha->host_no, cp->device->channel,
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001273 cp->device->id, cp->device->lun, comp_status, scsi_status,
1274 le16_to_cpu(sts->status_flags)));
1275
1276 /* Check to see if logout occurred. */
1277 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001278 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 break;
1280
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 default:
1282 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001283 "0x%x-0x%x.\n", vha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 qla_printk(KERN_INFO, ha,
1285 "Unknown status detected 0x%x-0x%x.\n",
1286 comp_status, scsi_status);
1287
1288 cp->result = DID_ERROR << 16;
1289 break;
1290 }
1291
1292 /* Place command on done queue. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001293 if (vha->status_srb == NULL)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001294 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295}
1296
1297/**
1298 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1299 * @ha: SCSI driver HA context
1300 * @pkt: Entry pointer
1301 *
1302 * Extended sense data.
1303 */
1304static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001305qla2x00_status_cont_entry(scsi_qla_host_t *vha, sts_cont_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306{
1307 uint8_t sense_sz = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001308 struct qla_hw_data *ha = vha->hw;
1309 srb_t *sp = vha->status_srb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 struct scsi_cmnd *cp;
1311
1312 if (sp != NULL && sp->request_sense_length != 0) {
1313 cp = sp->cmd;
1314 if (cp == NULL) {
1315 DEBUG2(printk("%s(): Cmd already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001316 "sp=%p.\n", __func__, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 qla_printk(KERN_INFO, ha,
1318 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001319 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001321 vha->status_srb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 return;
1323 }
1324
1325 if (sp->request_sense_length > sizeof(pkt->data)) {
1326 sense_sz = sizeof(pkt->data);
1327 } else {
1328 sense_sz = sp->request_sense_length;
1329 }
1330
1331 /* Move sense data. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07001332 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001333 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1335 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1336
1337 sp->request_sense_ptr += sense_sz;
1338 sp->request_sense_length -= sense_sz;
1339
1340 /* Place command on done queue. */
1341 if (sp->request_sense_length == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001342 vha->status_srb = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001343 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 }
1345 }
1346}
1347
1348/**
1349 * qla2x00_error_entry() - Process an error entry.
1350 * @ha: SCSI driver HA context
1351 * @pkt: Entry pointer
1352 */
1353static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001354qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355{
1356 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001357 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001358 struct req_que *req = rsp->req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359#if defined(QL_DEBUG_LEVEL_2)
1360 if (pkt->entry_status & RF_INV_E_ORDER)
1361 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1362 else if (pkt->entry_status & RF_INV_E_COUNT)
1363 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1364 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001365 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 "%s: Invalid Entry Parameter\n", __func__);
1367 else if (pkt->entry_status & RF_INV_E_TYPE)
1368 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1369 else if (pkt->entry_status & RF_BUSY)
1370 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1371 else
1372 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1373#endif
1374
1375 /* Validate handle. */
1376 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001377 sp = req->outstanding_cmds[pkt->handle];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 else
1379 sp = NULL;
1380
1381 if (sp) {
1382 /* Free outstanding command slot. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001383 req->outstanding_cmds[pkt->handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001384
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 /* Bad payload or header */
1386 if (pkt->entry_status &
1387 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1388 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1389 sp->cmd->result = DID_ERROR << 16;
1390 } else if (pkt->entry_status & RF_BUSY) {
1391 sp->cmd->result = DID_BUS_BUSY << 16;
1392 } else {
1393 sp->cmd->result = DID_ERROR << 16;
1394 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001395 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001397 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1398 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001400 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 qla_printk(KERN_WARNING, ha,
1402 "Error entry - invalid handle\n");
1403
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001404 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1405 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 }
1407}
1408
1409/**
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001410 * qla24xx_mbx_completion() - Process mailbox command completions.
1411 * @ha: SCSI driver HA context
1412 * @mb0: Mailbox0 register
1413 */
1414static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001415qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001416{
1417 uint16_t cnt;
1418 uint16_t __iomem *wptr;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001419 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001420 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1421
1422 /* Load return mailbox registers. */
1423 ha->flags.mbox_int = 1;
1424 ha->mailbox_out[0] = mb0;
1425 wptr = (uint16_t __iomem *)&reg->mailbox1;
1426
1427 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1428 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1429 wptr++;
1430 }
1431
1432 if (ha->mcp) {
1433 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001434 __func__, vha->host_no, ha->mcp->mb[0]));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001435 } else {
1436 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001437 __func__, vha->host_no));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001438 }
1439}
1440
1441/**
1442 * qla24xx_process_response_queue() - Process response queue entries.
1443 * @ha: SCSI driver HA context
1444 */
1445void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001446qla24xx_process_response_queue(struct rsp_que *rsp)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001447{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001448 struct qla_hw_data *ha = rsp->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001449 struct sts_entry_24xx *pkt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001450 struct scsi_qla_host *vha;
1451
1452 vha = qla2x00_get_rsp_host(rsp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001453
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001454 if (!vha->flags.online)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001455 return;
1456
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001457 while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
1458 pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001459
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001460 rsp->ring_index++;
1461 if (rsp->ring_index == rsp->length) {
1462 rsp->ring_index = 0;
1463 rsp->ring_ptr = rsp->ring;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001464 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001465 rsp->ring_ptr++;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001466 }
1467
1468 if (pkt->entry_status != 0) {
1469 DEBUG3(printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001470 "scsi(%ld): Process error entry.\n", vha->host_no));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001471
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001472 qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001473 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1474 wmb();
1475 continue;
1476 }
1477
1478 switch (pkt->entry_type) {
1479 case STATUS_TYPE:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001480 qla2x00_status_entry(vha, rsp, pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001481 break;
1482 case STATUS_CONT_TYPE:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001483 qla2x00_status_cont_entry(vha, (sts_cont_entry_t *)pkt);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001484 break;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001485 case VP_RPT_ID_IOCB_TYPE:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001486 qla24xx_report_id_acquisition(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001487 (struct vp_rpt_id_entry_24xx *)pkt);
1488 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001489 default:
1490 /* Type Not Supported. */
1491 DEBUG4(printk(KERN_WARNING
1492 "scsi(%ld): Received unknown response pkt type %x "
1493 "entry status=%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001494 vha->host_no, pkt->entry_type, pkt->entry_status));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001495 break;
1496 }
1497 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1498 wmb();
1499 }
1500
1501 /* Adjust ring index */
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001502 ha->isp_ops->wrt_rsp_reg(ha, rsp->id, rsp->ring_index);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001503}
1504
Andrew Vasquez05236a02007-09-20 14:07:37 -07001505static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001506qla2xxx_check_risc_status(scsi_qla_host_t *vha)
Andrew Vasquez05236a02007-09-20 14:07:37 -07001507{
1508 int rval;
1509 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001510 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez05236a02007-09-20 14:07:37 -07001511 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1512
1513 if (!IS_QLA25XX(ha))
1514 return;
1515
1516 rval = QLA_SUCCESS;
1517 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1518 RD_REG_DWORD(&reg->iobase_addr);
1519 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1520 for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1521 rval == QLA_SUCCESS; cnt--) {
1522 if (cnt) {
1523 WRT_REG_DWORD(&reg->iobase_window, 0x0001);
1524 udelay(10);
1525 } else
1526 rval = QLA_FUNCTION_TIMEOUT;
1527 }
1528 if (rval == QLA_SUCCESS)
1529 goto next_test;
1530
1531 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1532 for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
1533 rval == QLA_SUCCESS; cnt--) {
1534 if (cnt) {
1535 WRT_REG_DWORD(&reg->iobase_window, 0x0003);
1536 udelay(10);
1537 } else
1538 rval = QLA_FUNCTION_TIMEOUT;
1539 }
1540 if (rval != QLA_SUCCESS)
1541 goto done;
1542
1543next_test:
1544 if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
1545 qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
1546
1547done:
1548 WRT_REG_DWORD(&reg->iobase_window, 0x0000);
1549 RD_REG_DWORD(&reg->iobase_window);
1550}
1551
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001552/**
1553 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1554 * @irq:
1555 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001556 *
1557 * Called by system whenever the host adapter generates an interrupt.
1558 *
1559 * Returns handled flag.
1560 */
1561irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001562qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001563{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001564 scsi_qla_host_t *vha;
1565 struct qla_hw_data *ha;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001566 struct device_reg_24xx __iomem *reg;
1567 int status;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001568 unsigned long iter;
1569 uint32_t stat;
1570 uint32_t hccr;
1571 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001572 struct rsp_que *rsp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001573
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001574 rsp = (struct rsp_que *) dev_id;
1575 if (!rsp) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001576 printk(KERN_INFO
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001577 "%s(): NULL response queue pointer\n", __func__);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001578 return IRQ_NONE;
1579 }
1580
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001581 ha = rsp->hw;
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001582 reg = &ha->iobase->isp24;
1583 status = 0;
1584
Andrew Vasquezc6952482008-04-03 13:13:17 -07001585 spin_lock(&ha->hardware_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001586 vha = qla2x00_get_rsp_host(rsp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001587 for (iter = 50; iter--; ) {
1588 stat = RD_REG_DWORD(&reg->host_status);
1589 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001590 if (pci_channel_offline(ha->pdev))
1591 break;
1592
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001593 if (ha->hw_event_pause_errors == 0)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001594 qla2x00_post_hwe_work(vha, HW_EVENT_PARITY_ERR,
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001595 0, MSW(stat), LSW(stat));
1596 else if (ha->hw_event_pause_errors < 0xffffffff)
1597 ha->hw_event_pause_errors++;
1598
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001599 hccr = RD_REG_DWORD(&reg->hccr);
1600
1601 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1602 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001603
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001604 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001605
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001606 ha->isp_ops->fw_dump(vha, 1);
1607 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001608 break;
1609 } else if ((stat & HSRX_RISC_INT) == 0)
1610 break;
1611
1612 switch (stat & 0xff) {
1613 case 0x1:
1614 case 0x2:
1615 case 0x10:
1616 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001617 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001618 status |= MBX_INTERRUPT;
1619
1620 break;
1621 case 0x12:
1622 mb[0] = MSW(stat);
1623 mb[1] = RD_REG_WORD(&reg->mailbox1);
1624 mb[2] = RD_REG_WORD(&reg->mailbox2);
1625 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001626 qla2x00_async_event(vha, rsp, mb);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001627 break;
1628 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001629 case 0x14:
1630 qla24xx_process_response_queue(rsp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001631 break;
1632 default:
1633 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1634 "(%d).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001635 vha->host_no, stat & 0xff));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001636 break;
1637 }
1638 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1639 RD_REG_DWORD_RELAXED(&reg->hccr);
1640 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07001641 spin_unlock(&ha->hardware_lock);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001642
1643 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1644 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001645 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001646 complete(&ha->mbx_intr_comp);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001647 }
1648
1649 return IRQ_HANDLED;
1650}
1651
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001652static irqreturn_t
1653qla24xx_msix_rsp_q(int irq, void *dev_id)
1654{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001655 struct qla_hw_data *ha;
1656 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001657 struct device_reg_24xx __iomem *reg;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001658
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001659 rsp = (struct rsp_que *) dev_id;
1660 if (!rsp) {
1661 printk(KERN_INFO
1662 "%s(): NULL response queue pointer\n", __func__);
1663 return IRQ_NONE;
1664 }
1665 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001666 reg = &ha->iobase->isp24;
1667
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001668 spin_lock_irq(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001669
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001670 qla24xx_process_response_queue(rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001671 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001672
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001673 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001674
1675 return IRQ_HANDLED;
1676}
1677
1678static irqreturn_t
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001679qla25xx_msix_rsp_q(int irq, void *dev_id)
1680{
1681 struct qla_hw_data *ha;
1682 struct rsp_que *rsp;
1683 struct device_reg_24xx __iomem *reg;
1684 uint16_t msix_disabled_hccr = 0;
1685
1686 rsp = (struct rsp_que *) dev_id;
1687 if (!rsp) {
1688 printk(KERN_INFO
1689 "%s(): NULL response queue pointer\n", __func__);
1690 return IRQ_NONE;
1691 }
1692 ha = rsp->hw;
1693 reg = &ha->iobase->isp24;
1694
1695 spin_lock_irq(&ha->hardware_lock);
1696
1697 msix_disabled_hccr = rsp->options;
1698 if (!rsp->id)
1699 msix_disabled_hccr &= __constant_cpu_to_le32(BIT_22);
1700 else
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001701 msix_disabled_hccr &= __constant_cpu_to_le32(BIT_6);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001702
1703 qla24xx_process_response_queue(rsp);
1704
1705 if (!msix_disabled_hccr)
1706 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1707
1708 spin_unlock_irq(&ha->hardware_lock);
1709
1710 return IRQ_HANDLED;
1711}
1712
1713static irqreturn_t
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001714qla24xx_msix_default(int irq, void *dev_id)
1715{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001716 scsi_qla_host_t *vha;
1717 struct qla_hw_data *ha;
1718 struct rsp_que *rsp;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001719 struct device_reg_24xx __iomem *reg;
1720 int status;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001721 uint32_t stat;
1722 uint32_t hccr;
1723 uint16_t mb[4];
1724
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001725 rsp = (struct rsp_que *) dev_id;
1726 if (!rsp) {
1727 DEBUG(printk(
1728 "%s(): NULL response queue pointer\n", __func__));
1729 return IRQ_NONE;
1730 }
1731 ha = rsp->hw;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001732 reg = &ha->iobase->isp24;
1733 status = 0;
1734
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001735 spin_lock_irq(&ha->hardware_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001736 vha = qla2x00_get_rsp_host(rsp);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001737 do {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001738 stat = RD_REG_DWORD(&reg->host_status);
1739 if (stat & HSRX_RISC_PAUSED) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07001740 if (pci_channel_offline(ha->pdev))
1741 break;
1742
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001743 if (ha->hw_event_pause_errors == 0)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001744 qla2x00_post_hwe_work(vha, HW_EVENT_PARITY_ERR,
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001745 0, MSW(stat), LSW(stat));
1746 else if (ha->hw_event_pause_errors < 0xffffffff)
1747 ha->hw_event_pause_errors++;
1748
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001749 hccr = RD_REG_DWORD(&reg->hccr);
1750
1751 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1752 "Dumping firmware!\n", hccr);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001753
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001754 qla2xxx_check_risc_status(vha);
Andrew Vasquez05236a02007-09-20 14:07:37 -07001755
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001756 ha->isp_ops->fw_dump(vha, 1);
1757 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001758 break;
1759 } else if ((stat & HSRX_RISC_INT) == 0)
1760 break;
1761
1762 switch (stat & 0xff) {
1763 case 0x1:
1764 case 0x2:
1765 case 0x10:
1766 case 0x11:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001767 qla24xx_mbx_completion(vha, MSW(stat));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001768 status |= MBX_INTERRUPT;
1769
1770 break;
1771 case 0x12:
1772 mb[0] = MSW(stat);
1773 mb[1] = RD_REG_WORD(&reg->mailbox1);
1774 mb[2] = RD_REG_WORD(&reg->mailbox2);
1775 mb[3] = RD_REG_WORD(&reg->mailbox3);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001776 qla2x00_async_event(vha, rsp, mb);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001777 break;
1778 case 0x13:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001779 case 0x14:
1780 qla24xx_process_response_queue(rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001781 break;
1782 default:
1783 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1784 "(%d).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001785 vha->host_no, stat & 0xff));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001786 break;
1787 }
1788 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
Andrew Vasquez87f27012007-09-20 14:07:49 -07001789 } while (0);
Andrew Vasquez0e973a22008-05-12 22:21:09 -07001790 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001791
1792 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1793 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001794 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001795 complete(&ha->mbx_intr_comp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001796 }
1797
1798 return IRQ_HANDLED;
1799}
1800
1801/* Interrupt handling helpers. */
1802
1803struct qla_init_msix_entry {
1804 uint16_t entry;
1805 uint16_t index;
1806 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07001807 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001808};
1809
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001810static struct qla_init_msix_entry base_queue = {
1811 .entry = 0,
1812 .index = 0,
1813 .name = "qla2xxx (default)",
1814 .handler = qla24xx_msix_default,
1815};
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001816
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001817static struct qla_init_msix_entry base_rsp_queue = {
1818 .entry = 1,
1819 .index = 1,
1820 .name = "qla2xxx (rsp_q)",
1821 .handler = qla24xx_msix_rsp_q,
1822};
1823
1824static struct qla_init_msix_entry multi_rsp_queue = {
1825 .entry = 1,
1826 .index = 1,
1827 .name = "qla2xxx (multi_q)",
1828 .handler = qla25xx_msix_rsp_q,
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001829};
1830
1831static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001832qla24xx_disable_msix(struct qla_hw_data *ha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001833{
1834 int i;
1835 struct qla_msix_entry *qentry;
1836
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001837 for (i = 0; i < ha->msix_count; i++) {
1838 qentry = &ha->msix_entries[i];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001839 if (qentry->have_irq)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001840 free_irq(qentry->vector, qentry->rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001841 }
1842 pci_disable_msix(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001843 kfree(ha->msix_entries);
1844 ha->msix_entries = NULL;
1845 ha->flags.msix_enabled = 0;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001846}
1847
1848static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001849qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001850{
1851 int i, ret;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001852 struct msix_entry *entries;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001853 struct qla_msix_entry *qentry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001854 struct qla_init_msix_entry *msix_queue;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001855
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001856 entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
1857 GFP_KERNEL);
1858 if (!entries)
1859 return -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001860
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001861 for (i = 0; i < ha->msix_count; i++)
1862 entries[i].entry = i;
1863
1864 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001865 if (ret) {
1866 qla_printk(KERN_WARNING, ha,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001867 "MSI-X: Failed to enable support -- %d/%d\n"
1868 " Retry with %d vectors\n", ha->msix_count, ret, ret);
1869 ha->msix_count = ret;
1870 ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
1871 if (ret) {
1872 qla_printk(KERN_WARNING, ha, "MSI-X: Failed to enable"
1873 " support, giving up -- %d/%d\n",
1874 ha->msix_count, ret);
1875 goto msix_out;
1876 }
1877 ha->max_queues = ha->msix_count - 1;
1878 }
1879 ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
1880 ha->msix_count, GFP_KERNEL);
1881 if (!ha->msix_entries) {
1882 ret = -ENOMEM;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001883 goto msix_out;
1884 }
1885 ha->flags.msix_enabled = 1;
1886
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001887 for (i = 0; i < ha->msix_count; i++) {
1888 qentry = &ha->msix_entries[i];
1889 qentry->vector = entries[i].vector;
1890 qentry->entry = entries[i].entry;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001891 qentry->have_irq = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001892 qentry->rsp = NULL;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001893 }
1894
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001895 /* Enable MSI-X for AENs for queue 0 */
1896 qentry = &ha->msix_entries[0];
1897 ret = request_irq(qentry->vector, base_queue.handler, 0,
1898 base_queue.name, rsp);
1899 if (ret) {
1900 qla_printk(KERN_WARNING, ha,
1901 "MSI-X: Unable to register handler -- %x/%d.\n",
1902 qentry->vector, ret);
1903 qla24xx_disable_msix(ha);
1904 goto msix_out;
1905 }
1906 qentry->have_irq = 1;
1907 qentry->rsp = rsp;
1908
1909 /* Enable MSI-X vector for response queue update for queue 0 */
1910 if (ha->max_queues > 1 && ha->mqiobase) {
1911 ha->mqenable = 1;
1912 msix_queue = &multi_rsp_queue;
1913 qla_printk(KERN_INFO, ha,
1914 "MQ enabled, Number of Queue Resources: %d \n",
1915 ha->max_queues);
1916 } else {
1917 ha->mqenable = 0;
1918 msix_queue = &base_rsp_queue;
1919 }
1920
1921 qentry = &ha->msix_entries[1];
1922 ret = request_irq(qentry->vector, msix_queue->handler, 0,
1923 msix_queue->name, rsp);
1924 if (ret) {
1925 qla_printk(KERN_WARNING, ha,
1926 "MSI-X: Unable to register handler -- %x/%d.\n",
1927 qentry->vector, ret);
1928 qla24xx_disable_msix(ha);
1929 ha->mqenable = 0;
1930 goto msix_out;
1931 }
1932 qentry->have_irq = 1;
1933 qentry->rsp = rsp;
1934
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001935msix_out:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001936 kfree(entries);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001937 return ret;
1938}
1939
1940int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001941qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001942{
1943 int ret;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001944 device_reg_t __iomem *reg = ha->iobase;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001945
1946 /* If possible, enable MSI-X. */
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001947 if (!IS_QLA2432(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha))
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001948 goto skip_msix;
1949
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001950 if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX ||
1951 !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001952 DEBUG2(qla_printk(KERN_WARNING, ha,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001953 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1954 ha->pdev->revision, ha->fw_attributes));
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001955
1956 goto skip_msix;
1957 }
1958
Andrew Vasquezda7429f2008-01-17 09:02:11 -08001959 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
1960 (ha->pdev->subsystem_device == 0x7040 ||
1961 ha->pdev->subsystem_device == 0x7041 ||
1962 ha->pdev->subsystem_device == 0x1705)) {
1963 DEBUG2(qla_printk(KERN_WARNING, ha,
1964 "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
1965 ha->pdev->subsystem_vendor,
1966 ha->pdev->subsystem_device));
1967
1968 goto skip_msi;
1969 }
1970
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001971 ret = qla24xx_enable_msix(ha, rsp);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001972 if (!ret) {
1973 DEBUG2(qla_printk(KERN_INFO, ha,
1974 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1975 ha->fw_attributes));
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001976 goto clear_risc_ints;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001977 }
1978 qla_printk(KERN_WARNING, ha,
1979 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1980skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001981
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001982 if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha))
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001983 goto skip_msi;
1984
1985 ret = pci_enable_msi(ha->pdev);
1986 if (!ret) {
1987 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1988 ha->flags.msi_enabled = 1;
1989 }
1990skip_msi:
1991
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001992 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001993 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, rsp);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001994 if (ret) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001995 qla_printk(KERN_WARNING, ha,
1996 "Failed to reserve interrupt %d already in use.\n",
1997 ha->pdev->irq);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08001998 goto fail;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001999 }
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002000 ha->flags.inta_enabled = 1;
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002001clear_risc_ints:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002002
Andrew Vasquezc6952482008-04-03 13:13:17 -07002003 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002004 if (IS_FWI2_CAPABLE(ha)) {
2005 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
2006 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
2007 } else {
2008 WRT_REG_WORD(&reg->isp.semaphore, 0);
2009 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
2010 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
2011 }
Andrew Vasquezc6952482008-04-03 13:13:17 -07002012 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez963b0fd2008-01-31 12:33:50 -08002013
2014fail:
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002015 return ret;
2016}
2017
2018void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002019qla2x00_free_irqs(scsi_qla_host_t *vha)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002020{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002021 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002022 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002023
2024 if (ha->flags.msix_enabled)
2025 qla24xx_disable_msix(ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002026 else if (ha->flags.inta_enabled) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002027 free_irq(ha->pdev->irq, rsp);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07002028 pci_disable_msi(ha->pdev);
2029 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002030}
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002031
2032static struct scsi_qla_host *
2033qla2x00_get_rsp_host(struct rsp_que *rsp)
2034{
2035 srb_t *sp;
2036 struct qla_hw_data *ha = rsp->hw;
2037 struct scsi_qla_host *vha = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002038 struct sts_entry_24xx *pkt;
2039 struct req_que *req;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002040
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002041 if (rsp->id) {
2042 pkt = (struct sts_entry_24xx *) rsp->ring_ptr;
2043 req = rsp->req;
2044 if (pkt && pkt->handle < MAX_OUTSTANDING_COMMANDS) {
2045 sp = req->outstanding_cmds[pkt->handle];
2046 if (sp)
2047 vha = sp->vha;
2048 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002049 }
2050 if (!vha)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002051 /* handle it in base queue */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002052 vha = pci_get_drvdata(ha->pdev);
2053
2054 return vha;
2055}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002056
2057int qla25xx_request_irq(struct rsp_que *rsp)
2058{
2059 struct qla_hw_data *ha = rsp->hw;
2060 struct qla_init_msix_entry *intr = &multi_rsp_queue;
2061 struct qla_msix_entry *msix = rsp->msix;
2062 int ret;
2063
2064 ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
2065 if (ret) {
2066 qla_printk(KERN_WARNING, ha,
2067 "MSI-X: Unable to register handler -- %x/%d.\n",
2068 msix->vector, ret);
2069 return ret;
2070 }
2071 msix->have_irq = 1;
2072 msix->rsp = rsp;
2073 return ret;
2074}
2075
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002076void
2077qla25xx_wrt_rsp_reg(struct qla_hw_data *ha, uint16_t id, uint16_t index)
2078{
2079 device_reg_t __iomem *reg = (void *) ha->mqiobase + QLA_QUE_PAGE * id;
2080 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, index);
2081}
2082
2083void
2084qla24xx_wrt_rsp_reg(struct qla_hw_data *ha, uint16_t id, uint16_t index)
2085{
2086 device_reg_t __iomem *reg = (void *) ha->iobase;
2087 WRT_REG_DWORD(&reg->isp24.rsp_q_out, index);
2088}
2089