blob: 0f04258becbf0483c0abf524fe65a5e097d3c674 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 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 Vasquezdf7baa52006-10-13 09:33:39 -07009#include <scsi/scsi_tcq.h>
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070012static void qla2x00_async_event(scsi_qla_host_t *, uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070013static void qla2x00_process_completed_request(struct scsi_qla_host *, uint32_t);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070014static void qla2x00_status_entry(scsi_qla_host_t *, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070015static void qla2x00_status_cont_entry(scsi_qla_host_t *, sts_cont_entry_t *);
16static void qla2x00_error_entry(scsi_qla_host_t *, sts_entry_t *);
17static void qla2x00_ms_entry(scsi_qla_host_t *, ms_iocb_entry_t *);
18
Andrew Vasquez9a853f72005-07-06 10:31:27 -070019static void qla24xx_ms_entry(scsi_qla_host_t *, struct ct_entry_24xx *);
20
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{
33 scsi_qla_host_t *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -070034 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 int status;
36 unsigned long flags;
37 unsigned long iter;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070038 uint16_t mb[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40 ha = (scsi_qla_host_t *) dev_id;
41 if (!ha) {
42 printk(KERN_INFO
43 "%s(): NULL host pointer\n", __func__);
44 return (IRQ_NONE);
45 }
46
Andrew Vasquez3d716442005-07-06 10:30:26 -070047 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 status = 0;
49
50 spin_lock_irqsave(&ha->hardware_lock, flags);
51 for (iter = 50; iter--; ) {
52 if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
53 break;
54
55 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
56 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
57 RD_REG_WORD(&reg->hccr);
58
59 /* Get mailbox data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -070060 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
61 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
62 qla2x00_mbx_completion(ha, mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 status |= MBX_INTERRUPT;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070064 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
65 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
66 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
67 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
68 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 } else {
70 /*EMPTY*/
71 DEBUG2(printk("scsi(%ld): Unrecognized "
Andrew Vasquez9a853f72005-07-06 10:31:27 -070072 "interrupt type (%d).\n",
73 ha->host_no, mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 }
75 /* Release mailbox registers. */
76 WRT_REG_WORD(&reg->semaphore, 0);
77 RD_REG_WORD(&reg->semaphore);
78 } else {
79 qla2x00_process_response_queue(ha);
80
81 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
82 RD_REG_WORD(&reg->hccr);
83 }
84 }
85 spin_unlock_irqrestore(&ha->hardware_lock, flags);
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
88 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
90 up(&ha->mbx_intr_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 }
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 return (IRQ_HANDLED);
94}
95
96/**
97 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
98 * @irq:
99 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 *
101 * Called by system whenever the host adapter generates an interrupt.
102 *
103 * Returns handled flag.
104 */
105irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100106qla2300_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
108 scsi_qla_host_t *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700109 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 int status;
111 unsigned long flags;
112 unsigned long iter;
113 uint32_t stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700115 uint16_t mb[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117 ha = (scsi_qla_host_t *) dev_id;
118 if (!ha) {
119 printk(KERN_INFO
120 "%s(): NULL host pointer\n", __func__);
121 return (IRQ_NONE);
122 }
123
Andrew Vasquez3d716442005-07-06 10:30:26 -0700124 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 status = 0;
126
127 spin_lock_irqsave(&ha->hardware_lock, flags);
128 for (iter = 50; iter--; ) {
129 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
130 if (stat & HSR_RISC_PAUSED) {
131 hccr = RD_REG_WORD(&reg->hccr);
132 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
Andrew Vasquez07f31802006-12-13 19:20:31 -0800133 qla_printk(KERN_INFO, ha, "Parity error -- "
134 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 else
Andrew Vasquez07f31802006-12-13 19:20:31 -0800136 qla_printk(KERN_INFO, ha, "RISC paused -- "
137 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 /*
140 * Issue a "HARD" reset in order for the RISC
141 * interrupt bit to be cleared. Schedule a big
142 * hammmer to get out of the RISC PAUSED state.
143 */
144 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
145 RD_REG_WORD(&reg->hccr);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800146
147 ha->isp_ops.fw_dump(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
149 break;
150 } else if ((stat & HSR_RISC_INT) == 0)
151 break;
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 case 0x1:
155 case 0x2:
156 case 0x10:
157 case 0x11:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700158 qla2x00_mbx_completion(ha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 status |= MBX_INTERRUPT;
160
161 /* Release mailbox registers. */
162 WRT_REG_WORD(&reg->semaphore, 0);
163 break;
164 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700165 mb[0] = MSW(stat);
166 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
167 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
168 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
169 qla2x00_async_event(ha, mb);
170 break;
171 case 0x13:
172 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 break;
174 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700175 mb[0] = MBA_CMPLT_1_16BIT;
176 mb[1] = MSW(stat);
177 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 break;
179 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700180 mb[0] = MBA_SCSI_COMPLETION;
181 mb[1] = MSW(stat);
182 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
183 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 break;
185 default:
186 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700187 "(%d).\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 ha->host_no, stat & 0xff));
189 break;
190 }
191 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
192 RD_REG_WORD_RELAXED(&reg->hccr);
193 }
194 spin_unlock_irqrestore(&ha->hardware_lock, flags);
195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
197 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
199 up(&ha->mbx_intr_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 }
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 return (IRQ_HANDLED);
203}
204
205/**
206 * qla2x00_mbx_completion() - Process mailbox command completions.
207 * @ha: SCSI driver HA context
208 * @mb0: Mailbox0 register
209 */
210static void
211qla2x00_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
212{
213 uint16_t cnt;
214 uint16_t __iomem *wptr;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700215 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 /* Load return mailbox registers. */
218 ha->flags.mbox_int = 1;
219 ha->mailbox_out[0] = mb0;
220 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
221
222 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700223 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
225 if (cnt == 4 || cnt == 5)
226 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
227 else
228 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 wptr++;
231 }
232
233 if (ha->mcp) {
234 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
235 __func__, ha->host_no, ha->mcp->mb[0]));
236 } else {
237 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
238 __func__, ha->host_no));
239 }
240}
241
242/**
243 * qla2x00_async_event() - Process aynchronous events.
244 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700245 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 */
247static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700248qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700250#define LS_UNKNOWN 2
251 static char *link_speeds[5] = { "1", "2", "?", "4", "10" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 char *link_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 uint16_t handle_cnt;
254 uint16_t cnt;
255 uint32_t handles[5];
Andrew Vasquez3d716442005-07-06 10:30:26 -0700256 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 uint32_t rscn_entry, host_pid;
258 uint8_t rscn_queue_index;
259
260 /* Setup to process RIO completion. */
261 handle_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 switch (mb[0]) {
263 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700264 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 handle_cnt = 1;
266 break;
267 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700268 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 handle_cnt = 1;
270 mb[0] = MBA_SCSI_COMPLETION;
271 break;
272 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700273 handles[0] = mb[1];
274 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 handle_cnt = 2;
276 mb[0] = MBA_SCSI_COMPLETION;
277 break;
278 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700279 handles[0] = mb[1];
280 handles[1] = mb[2];
281 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 handle_cnt = 3;
283 mb[0] = MBA_SCSI_COMPLETION;
284 break;
285 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700286 handles[0] = mb[1];
287 handles[1] = mb[2];
288 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
290 handle_cnt = 4;
291 mb[0] = MBA_SCSI_COMPLETION;
292 break;
293 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700294 handles[0] = mb[1];
295 handles[1] = mb[2];
296 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
298 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
299 handle_cnt = 5;
300 mb[0] = MBA_SCSI_COMPLETION;
301 break;
302 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700303 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 handles[1] = le32_to_cpu(
305 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
306 RD_MAILBOX_REG(ha, reg, 6));
307 handle_cnt = 2;
308 mb[0] = MBA_SCSI_COMPLETION;
309 break;
310 default:
311 break;
312 }
313
314 switch (mb[0]) {
315 case MBA_SCSI_COMPLETION: /* Fast Post */
316 if (!ha->flags.online)
317 break;
318
319 for (cnt = 0; cnt < handle_cnt; cnt++)
320 qla2x00_process_completed_request(ha, handles[cnt]);
321 break;
322
323 case MBA_RESET: /* Reset */
324 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", ha->host_no));
325
326 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
327 break;
328
329 case MBA_SYSTEM_ERR: /* System Error */
330 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
331 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
332 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
333
334 qla_printk(KERN_INFO, ha,
335 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
336 mb[1], mb[2], mb[3]);
337
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700338 ha->isp_ops.fw_dump(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800340 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700341 if (mb[1] == 0 && mb[2] == 0) {
342 qla_printk(KERN_ERR, ha,
343 "Unrecoverable Hardware Error: adapter "
344 "marked OFFLINE!\n");
345 ha->flags.online = 0;
346 } else
347 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
348 } else if (mb[1] == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 qla_printk(KERN_INFO, ha,
350 "Unrecoverable Hardware Error: adapter marked "
351 "OFFLINE!\n");
352 ha->flags.online = 0;
353 } else
354 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
355 break;
356
357 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
358 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
359 ha->host_no));
360 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
361
362 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
363 break;
364
365 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
366 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
367 ha->host_no));
368 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
369
370 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
371 break;
372
373 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
374 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
375 ha->host_no));
376 break;
377
378 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 DEBUG2(printk("scsi(%ld): LIP occured (%x).\n", ha->host_no,
380 mb[1]));
381 qla_printk(KERN_INFO, ha, "LIP occured (%x).\n", mb[1]);
382
383 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
384 atomic_set(&ha->loop_state, LOOP_DOWN);
385 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800386 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 }
388
389 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
390
391 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 break;
393
394 case MBA_LOOP_UP: /* Loop Up Event */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
396 link_speed = link_speeds[0];
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700397 ha->link_data_rate = PORT_SPEED_1GB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 } else {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700399 link_speed = link_speeds[LS_UNKNOWN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 if (mb[1] < 5)
401 link_speed = link_speeds[mb[1]];
402 ha->link_data_rate = mb[1];
403 }
404
405 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
406 ha->host_no, link_speed));
407 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
408 link_speed);
409
410 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 break;
412
413 case MBA_LOOP_DOWN: /* Loop Down Event */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700414 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN (%x).\n",
415 ha->host_no, mb[1]));
416 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
419 atomic_set(&ha->loop_state, LOOP_DOWN);
420 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
421 ha->device_flags |= DFLG_NO_CABLE;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800422 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 }
424
425 ha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700426 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Andrew Vasquezcca53352005-08-26 19:08:30 -0700427 if (ql2xfdmienable)
428 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 break;
430
431 case MBA_LIP_RESET: /* LIP reset occurred */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
433 ha->host_no, mb[1]));
434 qla_printk(KERN_INFO, ha,
435 "LIP reset occured (%x).\n", mb[1]);
436
437 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
438 atomic_set(&ha->loop_state, LOOP_DOWN);
439 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800440 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 }
442
443 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
444
445 ha->operating_mode = LOOP;
446 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 break;
448
449 case MBA_POINT_TO_POINT: /* Point-to-Point */
450 if (IS_QLA2100(ha))
451 break;
452
453 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
454 ha->host_no));
455
456 /*
457 * Until there's a transition from loop down to loop up, treat
458 * this as loop down only.
459 */
460 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
461 atomic_set(&ha->loop_state, LOOP_DOWN);
462 if (!atomic_read(&ha->loop_down_timer))
463 atomic_set(&ha->loop_down_timer,
464 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800465 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 }
467
468 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
469 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
470 }
471 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800472
473 ha->flags.gpsc_supported = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 break;
475
476 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
477 if (IS_QLA2100(ha))
478 break;
479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
481 "received.\n",
482 ha->host_no));
483 qla_printk(KERN_INFO, ha,
484 "Configuration change detected: value=%x.\n", mb[1]);
485
486 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700487 atomic_set(&ha->loop_state, LOOP_DOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 if (!atomic_read(&ha->loop_down_timer))
489 atomic_set(&ha->loop_down_timer,
490 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800491 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 }
493
494 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
495 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
496 break;
497
498 case MBA_PORT_UPDATE: /* Port database update */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET
501 * event etc. earlier indicating loop is down) then process
502 * it. Otherwise ignore it and Wait for RSCN to come in.
503 */
504 atomic_set(&ha->loop_down_timer, 0);
505 if (atomic_read(&ha->loop_state) != LOOP_DOWN &&
506 atomic_read(&ha->loop_state) != LOOP_DEAD) {
507 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700508 "ignored %04x/%04x/%04x.\n", ha->host_no, mb[1],
509 mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 break;
511 }
512
513 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
514 ha->host_no));
515 DEBUG(printk(KERN_INFO
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700516 "scsi(%ld): Port database changed %04x %04x %04x.\n",
517 ha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
519 /*
520 * Mark all devices as missing so we will login again.
521 */
522 atomic_set(&ha->loop_state, LOOP_UP);
523
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800524 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526 ha->flags.rscn_queue_overflow = 1;
527
528 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
529 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 break;
531
532 case MBA_RSCN_UPDATE: /* State Change Registration */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
534 ha->host_no));
535 DEBUG(printk(KERN_INFO
536 "scsi(%ld): RSCN database changed -- %04x %04x.\n",
537 ha->host_no, mb[1], mb[2]));
538
539 rscn_entry = (mb[1] << 16) | mb[2];
540 host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) |
541 ha->d_id.b.al_pa;
542 if (rscn_entry == host_pid) {
543 DEBUG(printk(KERN_INFO
544 "scsi(%ld): Ignoring RSCN update to local host "
545 "port ID (%06x)\n",
546 ha->host_no, host_pid));
547 break;
548 }
549
550 rscn_queue_index = ha->rscn_in_ptr + 1;
551 if (rscn_queue_index == MAX_RSCN_COUNT)
552 rscn_queue_index = 0;
553 if (rscn_queue_index != ha->rscn_out_ptr) {
554 ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry;
555 ha->rscn_in_ptr = rscn_queue_index;
556 } else {
557 ha->flags.rscn_queue_overflow = 1;
558 }
559
560 atomic_set(&ha->loop_state, LOOP_UPDATE);
561 atomic_set(&ha->loop_down_timer, 0);
562 ha->flags.management_server_logged_in = 0;
563
564 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
565 set_bit(RSCN_UPDATE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 break;
567
568 /* case MBA_RIO_RESPONSE: */
569 case MBA_ZIO_RESPONSE:
570 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
571 ha->host_no));
572 DEBUG(printk(KERN_INFO
573 "scsi(%ld): [R|Z]IO update completion.\n",
574 ha->host_no));
575
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800576 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700577 qla24xx_process_response_queue(ha);
578 else
579 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700581
582 case MBA_DISCARD_RND_FRAME:
583 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
584 "%04x.\n", ha->host_no, mb[1], mb[2], mb[3]));
585 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700586
587 case MBA_TRACE_NOTIFICATION:
588 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
589 ha->host_no, mb[1], mb[2]));
590 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 }
592}
593
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700594static void
595qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
596{
597 fc_port_t *fcport = data;
598
599 if (fcport->ha->max_q_depth <= sdev->queue_depth)
600 return;
601
602 if (sdev->ordered_tags)
603 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
604 sdev->queue_depth + 1);
605 else
606 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
607 sdev->queue_depth + 1);
608
609 fcport->last_ramp_up = jiffies;
610
611 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
612 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
613 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
614 sdev->queue_depth));
615}
616
617static void
618qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
619{
620 fc_port_t *fcport = data;
621
622 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
623 return;
624
625 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
626 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
627 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
628 sdev->queue_depth));
629}
630
631static inline void
632qla2x00_ramp_up_queue_depth(scsi_qla_host_t *ha, srb_t *sp)
633{
634 fc_port_t *fcport;
635 struct scsi_device *sdev;
636
637 sdev = sp->cmd->device;
638 if (sdev->queue_depth >= ha->max_q_depth)
639 return;
640
641 fcport = sp->fcport;
642 if (time_before(jiffies,
643 fcport->last_ramp_up + ql2xqfullrampup * HZ))
644 return;
645 if (time_before(jiffies,
646 fcport->last_queue_full + ql2xqfullrampup * HZ))
647 return;
648
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700649 starget_for_each_device(sdev->sdev_target, fcport,
650 qla2x00_adjust_sdev_qdepth_up);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700651}
652
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653/**
654 * qla2x00_process_completed_request() - Process a Fast Post response.
655 * @ha: SCSI driver HA context
656 * @index: SRB index
657 */
658static void
659qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
660{
661 srb_t *sp;
662
663 /* Validate handle. */
664 if (index >= MAX_OUTSTANDING_COMMANDS) {
665 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
666 ha->host_no, index));
667 qla_printk(KERN_WARNING, ha,
668 "Invalid SCSI completion handle %d.\n", index);
669
670 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
671 return;
672 }
673
674 sp = ha->outstanding_cmds[index];
675 if (sp) {
676 /* Free outstanding command slot. */
677 ha->outstanding_cmds[index] = NULL;
678
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 CMD_COMPL_STATUS(sp->cmd) = 0L;
680 CMD_SCSI_STATUS(sp->cmd) = 0L;
681
682 /* Save ISP completion status */
683 sp->cmd->result = DID_OK << 16;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700684
685 qla2x00_ramp_up_queue_depth(ha, sp);
f4f051e2005-04-17 15:02:26 -0500686 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 } else {
688 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
689 ha->host_no));
690 qla_printk(KERN_WARNING, ha,
691 "Invalid ISP SCSI completion handle\n");
692
693 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
694 }
695}
696
697/**
698 * qla2x00_process_response_queue() - Process response queue entries.
699 * @ha: SCSI driver HA context
700 */
701void
702qla2x00_process_response_queue(struct scsi_qla_host *ha)
703{
Andrew Vasquez3d716442005-07-06 10:30:26 -0700704 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 sts_entry_t *pkt;
706 uint16_t handle_cnt;
707 uint16_t cnt;
708
709 if (!ha->flags.online)
710 return;
711
712 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
713 pkt = (sts_entry_t *)ha->response_ring_ptr;
714
715 ha->rsp_ring_index++;
716 if (ha->rsp_ring_index == ha->response_q_length) {
717 ha->rsp_ring_index = 0;
718 ha->response_ring_ptr = ha->response_ring;
719 } else {
720 ha->response_ring_ptr++;
721 }
722
723 if (pkt->entry_status != 0) {
724 DEBUG3(printk(KERN_INFO
725 "scsi(%ld): Process error entry.\n", ha->host_no));
726
727 qla2x00_error_entry(ha, pkt);
728 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
729 wmb();
730 continue;
731 }
732
733 switch (pkt->entry_type) {
734 case STATUS_TYPE:
735 qla2x00_status_entry(ha, pkt);
736 break;
737 case STATUS_TYPE_21:
738 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
739 for (cnt = 0; cnt < handle_cnt; cnt++) {
740 qla2x00_process_completed_request(ha,
741 ((sts21_entry_t *)pkt)->handle[cnt]);
742 }
743 break;
744 case STATUS_TYPE_22:
745 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
746 for (cnt = 0; cnt < handle_cnt; cnt++) {
747 qla2x00_process_completed_request(ha,
748 ((sts22_entry_t *)pkt)->handle[cnt]);
749 }
750 break;
751 case STATUS_CONT_TYPE:
752 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
753 break;
754 case MS_IOCB_TYPE:
755 qla2x00_ms_entry(ha, (ms_iocb_entry_t *)pkt);
756 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 default:
758 /* Type Not Supported. */
759 DEBUG4(printk(KERN_WARNING
760 "scsi(%ld): Received unknown response pkt type %x "
761 "entry status=%x.\n",
762 ha->host_no, pkt->entry_type, pkt->entry_status));
763 break;
764 }
765 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
766 wmb();
767 }
768
769 /* Adjust ring index */
770 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index);
771}
772
773/**
774 * qla2x00_status_entry() - Process a Status IOCB entry.
775 * @ha: SCSI driver HA context
776 * @pkt: Entry pointer
777 */
778static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700779qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 fc_port_t *fcport;
783 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700784 sts_entry_t *sts;
785 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 uint16_t comp_status;
787 uint16_t scsi_status;
788 uint8_t lscsi_status;
789 int32_t resid;
Ravi Ananded17c71b52006-05-17 15:08:55 -0700790 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700791 uint8_t *rsp_info, *sense_data;
792
793 sts = (sts_entry_t *) pkt;
794 sts24 = (struct sts_entry_24xx *) pkt;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800795 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700796 comp_status = le16_to_cpu(sts24->comp_status);
797 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
798 } else {
799 comp_status = le16_to_cpu(sts->comp_status);
800 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
801 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
803 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700804 if (comp_status == CS_COMPLETE && scsi_status == 0) {
805 qla2x00_process_completed_request(ha, sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
807 return;
808 }
809
810 /* Validate handle. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700811 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
812 sp = ha->outstanding_cmds[sts->handle];
813 ha->outstanding_cmds[sts->handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 } else
815 sp = NULL;
816
817 if (sp == NULL) {
818 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
819 ha->host_no));
820 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
821
822 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +0100823 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 return;
825 }
826 cp = sp->cmd;
827 if (cp == NULL) {
828 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -0700829 "pkt->handle=%d sp=%p.\n", ha->host_no, sts->handle, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 qla_printk(KERN_WARNING, ha,
831 "Command is NULL: already returned to OS (sp=%p)\n", sp);
832
833 return;
834 }
835
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700836 lscsi_status = scsi_status & STATUS_MASK;
837 CMD_ENTRY_STATUS(cp) = sts->entry_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 CMD_COMPL_STATUS(cp) = comp_status;
839 CMD_SCSI_STATUS(cp) = scsi_status;
840
bdf79622005-04-17 15:06:53 -0500841 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
Ravi Ananded17c71b52006-05-17 15:08:55 -0700843 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800844 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700845 sense_len = le32_to_cpu(sts24->sense_len);
846 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
847 resid_len = le32_to_cpu(sts24->rsp_residual_count);
Ravi Ananded17c71b52006-05-17 15:08:55 -0700848 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700849 rsp_info = sts24->data;
850 sense_data = sts24->data;
851 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
852 } else {
853 sense_len = le16_to_cpu(sts->req_sense_length);
854 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
855 resid_len = le32_to_cpu(sts->residual_length);
856 rsp_info = sts->rsp_info;
857 sense_data = sts->req_sense_data;
858 }
859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 /* Check for any FCP transport errors. */
861 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700862 /* Sense data lies beyond any FCP RESPONSE data. */
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800863 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700864 sense_data += rsp_info_len;
865 if (rsp_info_len > 3 && rsp_info[3]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
867 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700868 "retrying command\n", ha->host_no,
869 cp->device->channel, cp->device->id,
870 cp->device->lun, rsp_info_len, rsp_info[0],
871 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
872 rsp_info[5], rsp_info[6], rsp_info[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
874 cp->result = DID_BUS_BUSY << 16;
f4f051e2005-04-17 15:02:26 -0500875 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 return;
877 }
878 }
879
880 /*
881 * Based on Host and scsi status generate status code for Linux
882 */
883 switch (comp_status) {
884 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700885 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 if (scsi_status == 0) {
887 cp->result = DID_OK << 16;
888 break;
889 }
890 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700891 resid = resid_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 cp->resid = resid;
893 CMD_RESID_LEN(cp) = resid;
Andrew Vasquez0da69df2005-12-06 10:58:06 -0800894
895 if (!lscsi_status &&
896 ((unsigned)(cp->request_bufflen - resid) <
897 cp->underflow)) {
898 qla_printk(KERN_INFO, ha,
899 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
900 "detected (%x of %x bytes)...returning "
901 "error status.\n", ha->host_no,
902 cp->device->channel, cp->device->id,
903 cp->device->lun, resid,
904 cp->request_bufflen);
905
906 cp->result = DID_ERROR << 16;
907 break;
908 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 cp->result = DID_OK << 16 | lscsi_status;
911
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700912 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
913 DEBUG2(printk(KERN_INFO
914 "scsi(%ld): QUEUE FULL status detected "
915 "0x%x-0x%x.\n", ha->host_no, comp_status,
916 scsi_status));
917
918 /* Adjust queue depth for all luns on the port. */
919 fcport->last_queue_full = jiffies;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700920 starget_for_each_device(cp->device->sdev_target,
921 fcport, qla2x00_adjust_sdev_qdepth_down);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700922 break;
923 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 if (lscsi_status != SS_CHECK_CONDITION)
925 break;
926
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700927 /* Copy Sense Data into sense buffer. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
929
930 if (!(scsi_status & SS_SENSE_LEN_VALID))
931 break;
932
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700933 if (sense_len >= sizeof(cp->sense_buffer))
934 sense_len = sizeof(cp->sense_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700936 CMD_ACTUAL_SNSLEN(cp) = sense_len;
937 sp->request_sense_length = sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 sp->request_sense_ptr = cp->sense_buffer;
939
940 if (sp->request_sense_length > 32)
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700941 sense_len = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700943 memcpy(cp->sense_buffer, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700945 sp->request_sense_ptr += sense_len;
946 sp->request_sense_length -= sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 if (sp->request_sense_length != 0)
948 ha->status_srb = sp;
949
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 DEBUG5(printk("%s(): Check condition Sense data, "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700951 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n", __func__,
952 ha->host_no, cp->device->channel, cp->device->id,
953 cp->device->lun, cp, cp->serial_number));
954 if (sense_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
956 CMD_ACTUAL_SNSLEN(cp)));
957 break;
958
959 case CS_DATA_UNDERRUN:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700960 resid = resid_len;
Ravi Ananded17c71b52006-05-17 15:08:55 -0700961 /* Use F/W calculated residual length. */
962 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
963 resid = fw_resid_len;
964
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 if (scsi_status & SS_RESIDUAL_UNDER) {
966 cp->resid = resid;
967 CMD_RESID_LEN(cp) = resid;
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -0800968 } else {
969 DEBUG2(printk(KERN_INFO
970 "scsi(%ld:%d:%d) UNDERRUN status detected "
Ravi Ananded17c71b52006-05-17 15:08:55 -0700971 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
972 "os_underflow=0x%x\n", ha->host_no,
973 cp->device->id, cp->device->lun, comp_status,
974 scsi_status, resid_len, resid, cp->cmnd[0],
975 cp->underflow));
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -0800976
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 }
978
979 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700980 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 * Status.
982 */
983 if (lscsi_status != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 cp->result = DID_OK << 16 | lscsi_status;
985
Andrew Vasquezffec28a2007-01-29 10:22:27 -0800986 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
987 DEBUG2(printk(KERN_INFO
988 "scsi(%ld): QUEUE FULL status detected "
989 "0x%x-0x%x.\n", ha->host_no, comp_status,
990 scsi_status));
991
992 /*
993 * Adjust queue depth for all luns on the
994 * port.
995 */
996 fcport->last_queue_full = jiffies;
997 starget_for_each_device(
998 cp->device->sdev_target, fcport,
999 qla2x00_adjust_sdev_qdepth_down);
1000 break;
1001 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 if (lscsi_status != SS_CHECK_CONDITION)
1003 break;
1004
1005 /* Copy Sense Data into sense buffer */
1006 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
1007
1008 if (!(scsi_status & SS_SENSE_LEN_VALID))
1009 break;
1010
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001011 if (sense_len >= sizeof(cp->sense_buffer))
1012 sense_len = sizeof(cp->sense_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001014 CMD_ACTUAL_SNSLEN(cp) = sense_len;
1015 sp->request_sense_length = sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 sp->request_sense_ptr = cp->sense_buffer;
1017
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001018 if (sp->request_sense_length > 32)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001019 sense_len = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001021 memcpy(cp->sense_buffer, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001023 sp->request_sense_ptr += sense_len;
1024 sp->request_sense_length -= sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 if (sp->request_sense_length != 0)
1026 ha->status_srb = sp;
1027
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 DEBUG5(printk("%s(): Check condition Sense data, "
1029 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001030 __func__, ha->host_no, cp->device->channel,
1031 cp->device->id, cp->device->lun, cp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 cp->serial_number));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001033
1034 if (sense_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
1036 CMD_ACTUAL_SNSLEN(cp)));
1037 } else {
1038 /*
1039 * If RISC reports underrun and target does not report
1040 * it then we must have a lost frame, so tell upper
1041 * layer to retry it by reporting a bus busy.
1042 */
1043 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1044 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1045 "frame(s) detected (%x of %x bytes)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001046 "retrying command.\n", ha->host_no,
1047 cp->device->channel, cp->device->id,
1048 cp->device->lun, resid,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 cp->request_bufflen));
1050
1051 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 break;
1053 }
1054
1055 /* Handle mid-layer underflow */
1056 if ((unsigned)(cp->request_bufflen - resid) <
1057 cp->underflow) {
1058 qla_printk(KERN_INFO, ha,
1059 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1060 "detected (%x of %x bytes)...returning "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001061 "error status.\n", ha->host_no,
1062 cp->device->channel, cp->device->id,
1063 cp->device->lun, resid,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 cp->request_bufflen);
1065
1066 cp->result = DID_ERROR << 16;
1067 break;
1068 }
1069
1070 /* Everybody online, looking good... */
1071 cp->result = DID_OK << 16;
1072 }
1073 break;
1074
1075 case CS_DATA_OVERRUN:
1076 DEBUG2(printk(KERN_INFO
1077 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001078 ha->host_no, cp->device->id, cp->device->lun, comp_status,
1079 scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 DEBUG2(printk(KERN_INFO
1081 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1082 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1083 cp->cmnd[4], cp->cmnd[5]));
1084 DEBUG2(printk(KERN_INFO
1085 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1086 "status!\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001087 cp->serial_number, cp->request_bufflen, resid_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
1089 cp->result = DID_ERROR << 16;
1090 break;
1091
1092 case CS_PORT_LOGGED_OUT:
1093 case CS_PORT_CONFIG_CHG:
1094 case CS_PORT_BUSY:
1095 case CS_INCOMPLETE:
1096 case CS_PORT_UNAVAILABLE:
1097 /*
1098 * If the port is in Target Down state, return all IOs for this
1099 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1100 * retry_queue.
1101 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1103 "pid=%ld, compl status=0x%x, port state=0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001104 ha->host_no, cp->device->id, cp->device->lun,
1105 cp->serial_number, comp_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 atomic_read(&fcport->state)));
1107
f4f051e2005-04-17 15:02:26 -05001108 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 if (atomic_read(&fcport->state) == FCS_ONLINE) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001110 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 break;
1113
1114 case CS_RESET:
1115 DEBUG2(printk(KERN_INFO
1116 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1117 ha->host_no, comp_status, scsi_status));
1118
f4f051e2005-04-17 15:02:26 -05001119 cp->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 break;
1121
1122 case CS_ABORTED:
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001123 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 * hv2.19.12 - DID_ABORT does not retry the request if we
1125 * aborted this request then abort otherwise it must be a
1126 * reset.
1127 */
1128 DEBUG2(printk(KERN_INFO
1129 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1130 ha->host_no, comp_status, scsi_status));
1131
1132 cp->result = DID_RESET << 16;
1133 break;
1134
1135 case CS_TIMEOUT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 cp->result = DID_BUS_BUSY << 16;
1137
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001138 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001139 DEBUG2(printk(KERN_INFO
1140 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1141 "0x%x-0x%x\n", ha->host_no, cp->device->channel,
1142 cp->device->id, cp->device->lun, comp_status,
1143 scsi_status));
1144 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001146 DEBUG2(printk(KERN_INFO
1147 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1148 "sflags=%x.\n", ha->host_no, cp->device->channel,
1149 cp->device->id, cp->device->lun, comp_status, scsi_status,
1150 le16_to_cpu(sts->status_flags)));
1151
1152 /* Check to see if logout occurred. */
1153 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001154 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 break;
1156
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 default:
1158 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001159 "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 qla_printk(KERN_INFO, ha,
1161 "Unknown status detected 0x%x-0x%x.\n",
1162 comp_status, scsi_status);
1163
1164 cp->result = DID_ERROR << 16;
1165 break;
1166 }
1167
1168 /* Place command on done queue. */
1169 if (ha->status_srb == NULL)
f4f051e2005-04-17 15:02:26 -05001170 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171}
1172
1173/**
1174 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1175 * @ha: SCSI driver HA context
1176 * @pkt: Entry pointer
1177 *
1178 * Extended sense data.
1179 */
1180static void
1181qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1182{
1183 uint8_t sense_sz = 0;
1184 srb_t *sp = ha->status_srb;
1185 struct scsi_cmnd *cp;
1186
1187 if (sp != NULL && sp->request_sense_length != 0) {
1188 cp = sp->cmd;
1189 if (cp == NULL) {
1190 DEBUG2(printk("%s(): Cmd already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001191 "sp=%p.\n", __func__, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 qla_printk(KERN_INFO, ha,
1193 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001194 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
1196 ha->status_srb = NULL;
1197 return;
1198 }
1199
1200 if (sp->request_sense_length > sizeof(pkt->data)) {
1201 sense_sz = sizeof(pkt->data);
1202 } else {
1203 sense_sz = sp->request_sense_length;
1204 }
1205
1206 /* Move sense data. */
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001207 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001208 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1210 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1211
1212 sp->request_sense_ptr += sense_sz;
1213 sp->request_sense_length -= sense_sz;
1214
1215 /* Place command on done queue. */
1216 if (sp->request_sense_length == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 ha->status_srb = NULL;
f4f051e2005-04-17 15:02:26 -05001218 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 }
1220 }
1221}
1222
1223/**
1224 * qla2x00_error_entry() - Process an error entry.
1225 * @ha: SCSI driver HA context
1226 * @pkt: Entry pointer
1227 */
1228static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001229qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230{
1231 srb_t *sp;
1232
1233#if defined(QL_DEBUG_LEVEL_2)
1234 if (pkt->entry_status & RF_INV_E_ORDER)
1235 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1236 else if (pkt->entry_status & RF_INV_E_COUNT)
1237 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1238 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001239 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 "%s: Invalid Entry Parameter\n", __func__);
1241 else if (pkt->entry_status & RF_INV_E_TYPE)
1242 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1243 else if (pkt->entry_status & RF_BUSY)
1244 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1245 else
1246 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1247#endif
1248
1249 /* Validate handle. */
1250 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1251 sp = ha->outstanding_cmds[pkt->handle];
1252 else
1253 sp = NULL;
1254
1255 if (sp) {
1256 /* Free outstanding command slot. */
1257 ha->outstanding_cmds[pkt->handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001258
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 /* Bad payload or header */
1260 if (pkt->entry_status &
1261 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1262 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1263 sp->cmd->result = DID_ERROR << 16;
1264 } else if (pkt->entry_status & RF_BUSY) {
1265 sp->cmd->result = DID_BUS_BUSY << 16;
1266 } else {
1267 sp->cmd->result = DID_ERROR << 16;
1268 }
f4f051e2005-04-17 15:02:26 -05001269 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001271 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1272 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1274 ha->host_no));
1275 qla_printk(KERN_WARNING, ha,
1276 "Error entry - invalid handle\n");
1277
1278 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +01001279 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 }
1281}
1282
1283/**
1284 * qla2x00_ms_entry() - Process a Management Server entry.
1285 * @ha: SCSI driver HA context
1286 * @index: Response queue out pointer
1287 */
1288static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001289qla2x00_ms_entry(scsi_qla_host_t *ha, ms_iocb_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290{
1291 srb_t *sp;
1292
1293 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1294 __func__, ha->host_no, pkt, pkt->handle1));
1295
1296 /* Validate handle. */
1297 if (pkt->handle1 < MAX_OUTSTANDING_COMMANDS)
1298 sp = ha->outstanding_cmds[pkt->handle1];
1299 else
1300 sp = NULL;
1301
1302 if (sp == NULL) {
1303 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1304 ha->host_no));
1305 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle\n");
1306
1307 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1308 return;
1309 }
1310
1311 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->status);
1312 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1313
1314 /* Free outstanding command slot. */
1315 ha->outstanding_cmds[pkt->handle1] = NULL;
1316
f4f051e2005-04-17 15:02:26 -05001317 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318}
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001319
1320
1321/**
1322 * qla24xx_mbx_completion() - Process mailbox command completions.
1323 * @ha: SCSI driver HA context
1324 * @mb0: Mailbox0 register
1325 */
1326static void
1327qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
1328{
1329 uint16_t cnt;
1330 uint16_t __iomem *wptr;
1331 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1332
1333 /* Load return mailbox registers. */
1334 ha->flags.mbox_int = 1;
1335 ha->mailbox_out[0] = mb0;
1336 wptr = (uint16_t __iomem *)&reg->mailbox1;
1337
1338 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1339 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1340 wptr++;
1341 }
1342
1343 if (ha->mcp) {
1344 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1345 __func__, ha->host_no, ha->mcp->mb[0]));
1346 } else {
1347 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1348 __func__, ha->host_no));
1349 }
1350}
1351
1352/**
1353 * qla24xx_process_response_queue() - Process response queue entries.
1354 * @ha: SCSI driver HA context
1355 */
1356void
1357qla24xx_process_response_queue(struct scsi_qla_host *ha)
1358{
1359 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1360 struct sts_entry_24xx *pkt;
1361
1362 if (!ha->flags.online)
1363 return;
1364
1365 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
1366 pkt = (struct sts_entry_24xx *)ha->response_ring_ptr;
1367
1368 ha->rsp_ring_index++;
1369 if (ha->rsp_ring_index == ha->response_q_length) {
1370 ha->rsp_ring_index = 0;
1371 ha->response_ring_ptr = ha->response_ring;
1372 } else {
1373 ha->response_ring_ptr++;
1374 }
1375
1376 if (pkt->entry_status != 0) {
1377 DEBUG3(printk(KERN_INFO
1378 "scsi(%ld): Process error entry.\n", ha->host_no));
1379
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001380 qla2x00_error_entry(ha, (sts_entry_t *) pkt);
1381 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1382 wmb();
1383 continue;
1384 }
1385
1386 switch (pkt->entry_type) {
1387 case STATUS_TYPE:
1388 qla2x00_status_entry(ha, pkt);
1389 break;
1390 case STATUS_CONT_TYPE:
1391 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
1392 break;
1393 case MS_IOCB_TYPE:
1394 qla24xx_ms_entry(ha, (struct ct_entry_24xx *)pkt);
1395 break;
1396 default:
1397 /* Type Not Supported. */
1398 DEBUG4(printk(KERN_WARNING
1399 "scsi(%ld): Received unknown response pkt type %x "
1400 "entry status=%x.\n",
1401 ha->host_no, pkt->entry_type, pkt->entry_status));
1402 break;
1403 }
1404 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1405 wmb();
1406 }
1407
1408 /* Adjust ring index */
1409 WRT_REG_DWORD(&reg->rsp_q_out, ha->rsp_ring_index);
1410}
1411
1412/**
1413 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1414 * @irq:
1415 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001416 *
1417 * Called by system whenever the host adapter generates an interrupt.
1418 *
1419 * Returns handled flag.
1420 */
1421irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001422qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001423{
1424 scsi_qla_host_t *ha;
1425 struct device_reg_24xx __iomem *reg;
1426 int status;
1427 unsigned long flags;
1428 unsigned long iter;
1429 uint32_t stat;
1430 uint32_t hccr;
1431 uint16_t mb[4];
1432
1433 ha = (scsi_qla_host_t *) dev_id;
1434 if (!ha) {
1435 printk(KERN_INFO
1436 "%s(): NULL host pointer\n", __func__);
1437 return IRQ_NONE;
1438 }
1439
1440 reg = &ha->iobase->isp24;
1441 status = 0;
1442
1443 spin_lock_irqsave(&ha->hardware_lock, flags);
1444 for (iter = 50; iter--; ) {
1445 stat = RD_REG_DWORD(&reg->host_status);
1446 if (stat & HSRX_RISC_PAUSED) {
1447 hccr = RD_REG_DWORD(&reg->hccr);
1448
1449 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1450 "Dumping firmware!\n", hccr);
Andrew Vasquez96ca5ca2006-12-13 19:20:32 -08001451 ha->isp_ops.fw_dump(ha, 1);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001452 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1453 break;
1454 } else if ((stat & HSRX_RISC_INT) == 0)
1455 break;
1456
1457 switch (stat & 0xff) {
1458 case 0x1:
1459 case 0x2:
1460 case 0x10:
1461 case 0x11:
1462 qla24xx_mbx_completion(ha, MSW(stat));
1463 status |= MBX_INTERRUPT;
1464
1465 break;
1466 case 0x12:
1467 mb[0] = MSW(stat);
1468 mb[1] = RD_REG_WORD(&reg->mailbox1);
1469 mb[2] = RD_REG_WORD(&reg->mailbox2);
1470 mb[3] = RD_REG_WORD(&reg->mailbox3);
1471 qla2x00_async_event(ha, mb);
1472 break;
1473 case 0x13:
1474 qla24xx_process_response_queue(ha);
1475 break;
1476 default:
1477 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1478 "(%d).\n",
1479 ha->host_no, stat & 0xff));
1480 break;
1481 }
1482 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1483 RD_REG_DWORD_RELAXED(&reg->hccr);
1484 }
1485 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1486
1487 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1488 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001489 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1490 up(&ha->mbx_intr_sem);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001491 }
1492
1493 return IRQ_HANDLED;
1494}
1495
1496/**
1497 * qla24xx_ms_entry() - Process a Management Server entry.
1498 * @ha: SCSI driver HA context
1499 * @index: Response queue out pointer
1500 */
1501static void
1502qla24xx_ms_entry(scsi_qla_host_t *ha, struct ct_entry_24xx *pkt)
1503{
1504 srb_t *sp;
1505
1506 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1507 __func__, ha->host_no, pkt, pkt->handle));
1508
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001509 DEBUG9(printk("%s: ct pkt dump:\n", __func__));
1510 DEBUG9(qla2x00_dump_buffer((void *)pkt, sizeof(struct ct_entry_24xx)));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001511
1512 /* Validate handle. */
1513 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1514 sp = ha->outstanding_cmds[pkt->handle];
1515 else
1516 sp = NULL;
1517
1518 if (sp == NULL) {
1519 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1520 ha->host_no));
1521 DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n",
1522 ha->host_no));
1523 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle %d\n",
1524 pkt->handle);
1525
1526 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1527 return;
1528 }
1529
1530 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->comp_status);
1531 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1532
1533 /* Free outstanding command slot. */
1534 ha->outstanding_cmds[pkt->handle] = NULL;
1535
1536 qla2x00_sp_compl(ha, sp);
1537}
1538
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001539static irqreturn_t
1540qla24xx_msix_rsp_q(int irq, void *dev_id)
1541{
1542 scsi_qla_host_t *ha;
1543 struct device_reg_24xx __iomem *reg;
1544 unsigned long flags;
1545
1546 ha = dev_id;
1547 reg = &ha->iobase->isp24;
1548
1549 spin_lock_irqsave(&ha->hardware_lock, flags);
1550
1551 qla24xx_process_response_queue(ha);
1552
1553 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1554 RD_REG_DWORD_RELAXED(&reg->hccr);
1555
1556 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1557
1558 return IRQ_HANDLED;
1559}
1560
1561static irqreturn_t
1562qla24xx_msix_default(int irq, void *dev_id)
1563{
1564 scsi_qla_host_t *ha;
1565 struct device_reg_24xx __iomem *reg;
1566 int status;
1567 unsigned long flags;
1568 unsigned long iter;
1569 uint32_t stat;
1570 uint32_t hccr;
1571 uint16_t mb[4];
1572
1573 ha = dev_id;
1574 reg = &ha->iobase->isp24;
1575 status = 0;
1576
1577 spin_lock_irqsave(&ha->hardware_lock, flags);
1578 for (iter = 50; iter--; ) {
1579 stat = RD_REG_DWORD(&reg->host_status);
1580 if (stat & HSRX_RISC_PAUSED) {
1581 hccr = RD_REG_DWORD(&reg->hccr);
1582
1583 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1584 "Dumping firmware!\n", hccr);
1585 ha->isp_ops.fw_dump(ha, 1);
1586 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1587 break;
1588 } else if ((stat & HSRX_RISC_INT) == 0)
1589 break;
1590
1591 switch (stat & 0xff) {
1592 case 0x1:
1593 case 0x2:
1594 case 0x10:
1595 case 0x11:
1596 qla24xx_mbx_completion(ha, MSW(stat));
1597 status |= MBX_INTERRUPT;
1598
1599 break;
1600 case 0x12:
1601 mb[0] = MSW(stat);
1602 mb[1] = RD_REG_WORD(&reg->mailbox1);
1603 mb[2] = RD_REG_WORD(&reg->mailbox2);
1604 mb[3] = RD_REG_WORD(&reg->mailbox3);
1605 qla2x00_async_event(ha, mb);
1606 break;
1607 case 0x13:
1608 qla24xx_process_response_queue(ha);
1609 break;
1610 default:
1611 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1612 "(%d).\n",
1613 ha->host_no, stat & 0xff));
1614 break;
1615 }
1616 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1617 RD_REG_DWORD_RELAXED(&reg->hccr);
1618 }
1619 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1620
1621 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1622 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001623 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1624 up(&ha->mbx_intr_sem);
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001625 }
1626
1627 return IRQ_HANDLED;
1628}
1629
1630/* Interrupt handling helpers. */
1631
1632struct qla_init_msix_entry {
1633 uint16_t entry;
1634 uint16_t index;
1635 const char *name;
Jeff Garzik476834c2007-05-23 14:41:44 -07001636 irq_handler_t handler;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001637};
1638
1639static struct qla_init_msix_entry imsix_entries[QLA_MSIX_ENTRIES] = {
1640 { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT,
1641 "qla2xxx (default)", qla24xx_msix_default },
1642
1643 { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q,
1644 "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
1645};
1646
1647static void
1648qla24xx_disable_msix(scsi_qla_host_t *ha)
1649{
1650 int i;
1651 struct qla_msix_entry *qentry;
1652
1653 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1654 qentry = &ha->msix_entries[imsix_entries[i].index];
1655 if (qentry->have_irq)
1656 free_irq(qentry->msix_vector, ha);
1657 }
1658 pci_disable_msix(ha->pdev);
1659}
1660
1661static int
1662qla24xx_enable_msix(scsi_qla_host_t *ha)
1663{
1664 int i, ret;
1665 struct msix_entry entries[QLA_MSIX_ENTRIES];
1666 struct qla_msix_entry *qentry;
1667
1668 for (i = 0; i < QLA_MSIX_ENTRIES; i++)
1669 entries[i].entry = imsix_entries[i].entry;
1670
1671 ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries));
1672 if (ret) {
1673 qla_printk(KERN_WARNING, ha,
1674 "MSI-X: Failed to enable support -- %d/%d\n",
1675 QLA_MSIX_ENTRIES, ret);
1676 goto msix_out;
1677 }
1678 ha->flags.msix_enabled = 1;
1679
1680 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1681 qentry = &ha->msix_entries[imsix_entries[i].index];
1682 qentry->msix_vector = entries[i].vector;
1683 qentry->msix_entry = entries[i].entry;
1684 qentry->have_irq = 0;
1685 ret = request_irq(qentry->msix_vector,
1686 imsix_entries[i].handler, 0, imsix_entries[i].name, ha);
1687 if (ret) {
1688 qla_printk(KERN_WARNING, ha,
1689 "MSI-X: Unable to register handler -- %x/%d.\n",
1690 imsix_entries[i].index, ret);
1691 qla24xx_disable_msix(ha);
1692 goto msix_out;
1693 }
1694 qentry->have_irq = 1;
1695 }
1696
1697msix_out:
1698 return ret;
1699}
1700
1701int
1702qla2x00_request_irqs(scsi_qla_host_t *ha)
1703{
1704 int ret;
1705
1706 /* If possible, enable MSI-X. */
1707 if (!IS_QLA2432(ha))
1708 goto skip_msix;
1709
1710 if (ha->chip_revision < QLA_MSIX_CHIP_REV_24XX ||
1711 !QLA_MSIX_FW_MODE_1(ha->fw_attributes)) {
1712 DEBUG2(qla_printk(KERN_WARNING, ha,
1713 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1714 ha->chip_revision, ha->fw_attributes));
1715
1716 goto skip_msix;
1717 }
1718
1719 ret = qla24xx_enable_msix(ha);
1720 if (!ret) {
1721 DEBUG2(qla_printk(KERN_INFO, ha,
1722 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1723 ha->fw_attributes));
1724 return ret;
1725 }
1726 qla_printk(KERN_WARNING, ha,
1727 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1728skip_msix:
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001729
1730 if (!IS_QLA24XX(ha))
1731 goto skip_msi;
1732
1733 ret = pci_enable_msi(ha->pdev);
1734 if (!ret) {
1735 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1736 ha->flags.msi_enabled = 1;
1737 }
1738skip_msi:
1739
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001740 ret = request_irq(ha->pdev->irq, ha->isp_ops.intr_handler,
1741 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
Andrew Vasquezd88021a2007-01-29 10:22:20 -08001742 if (!ret) {
1743 ha->flags.inta_enabled = 1;
1744 ha->host->irq = ha->pdev->irq;
1745 } else {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001746 qla_printk(KERN_WARNING, ha,
1747 "Failed to reserve interrupt %d already in use.\n",
1748 ha->pdev->irq);
1749 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001750
1751 return ret;
1752}
1753
1754void
1755qla2x00_free_irqs(scsi_qla_host_t *ha)
1756{
1757
1758 if (ha->flags.msix_enabled)
1759 qla24xx_disable_msix(ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001760 else if (ha->flags.inta_enabled) {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001761 free_irq(ha->host->irq, ha);
Andrew Vasquezcbedb602007-05-07 07:43:02 -07001762 pci_disable_msi(ha->pdev);
1763 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001764}