blob: df69dc016a53e5525f08a054bc841bbf72d17fed [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) {
89 spin_lock_irqsave(&ha->mbx_reg_lock, flags);
90
91 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
92 up(&ha->mbx_intr_sem);
93
94 spin_unlock_irqrestore(&ha->mbx_reg_lock, flags);
95 }
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 return (IRQ_HANDLED);
98}
99
100/**
101 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
102 * @irq:
103 * @dev_id: SCSI driver HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 *
105 * Called by system whenever the host adapter generates an interrupt.
106 *
107 * Returns handled flag.
108 */
109irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100110qla2300_intr_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
112 scsi_qla_host_t *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700113 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 int status;
115 unsigned long flags;
116 unsigned long iter;
117 uint32_t stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 uint16_t hccr;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700119 uint16_t mb[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121 ha = (scsi_qla_host_t *) dev_id;
122 if (!ha) {
123 printk(KERN_INFO
124 "%s(): NULL host pointer\n", __func__);
125 return (IRQ_NONE);
126 }
127
Andrew Vasquez3d716442005-07-06 10:30:26 -0700128 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 status = 0;
130
131 spin_lock_irqsave(&ha->hardware_lock, flags);
132 for (iter = 50; iter--; ) {
133 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
134 if (stat & HSR_RISC_PAUSED) {
135 hccr = RD_REG_WORD(&reg->hccr);
136 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
137 qla_printk(KERN_INFO, ha,
138 "Parity error -- HCCR=%x.\n", hccr);
139 else
140 qla_printk(KERN_INFO, ha,
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700141 "RISC paused -- HCCR=%x.\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 /*
144 * Issue a "HARD" reset in order for the RISC
145 * interrupt bit to be cleared. Schedule a big
146 * hammmer to get out of the RISC PAUSED state.
147 */
148 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
149 RD_REG_WORD(&reg->hccr);
150 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
151 break;
152 } else if ((stat & HSR_RISC_INT) == 0)
153 break;
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 case 0x1:
157 case 0x2:
158 case 0x10:
159 case 0x11:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700160 qla2x00_mbx_completion(ha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 status |= MBX_INTERRUPT;
162
163 /* Release mailbox registers. */
164 WRT_REG_WORD(&reg->semaphore, 0);
165 break;
166 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700167 mb[0] = MSW(stat);
168 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
169 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
170 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
171 qla2x00_async_event(ha, mb);
172 break;
173 case 0x13:
174 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 break;
176 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700177 mb[0] = MBA_CMPLT_1_16BIT;
178 mb[1] = MSW(stat);
179 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 break;
181 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700182 mb[0] = MBA_SCSI_COMPLETION;
183 mb[1] = MSW(stat);
184 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
185 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 break;
187 default:
188 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700189 "(%d).\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 ha->host_no, stat & 0xff));
191 break;
192 }
193 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
194 RD_REG_WORD_RELAXED(&reg->hccr);
195 }
196 spin_unlock_irqrestore(&ha->hardware_lock, flags);
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
199 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
200 spin_lock_irqsave(&ha->mbx_reg_lock, flags);
201
202 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
203 up(&ha->mbx_intr_sem);
204
205 spin_unlock_irqrestore(&ha->mbx_reg_lock, flags);
206 }
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 return (IRQ_HANDLED);
209}
210
211/**
212 * qla2x00_mbx_completion() - Process mailbox command completions.
213 * @ha: SCSI driver HA context
214 * @mb0: Mailbox0 register
215 */
216static void
217qla2x00_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
218{
219 uint16_t cnt;
220 uint16_t __iomem *wptr;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700221 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 /* Load return mailbox registers. */
224 ha->flags.mbox_int = 1;
225 ha->mailbox_out[0] = mb0;
226 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
227
228 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700229 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
231 if (cnt == 4 || cnt == 5)
232 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
233 else
234 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700235
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 wptr++;
237 }
238
239 if (ha->mcp) {
240 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
241 __func__, ha->host_no, ha->mcp->mb[0]));
242 } else {
243 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
244 __func__, ha->host_no));
245 }
246}
247
248/**
249 * qla2x00_async_event() - Process aynchronous events.
250 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700251 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 */
253static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700254qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700256#define LS_UNKNOWN 2
257 static char *link_speeds[5] = { "1", "2", "?", "4", "10" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 char *link_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 uint16_t handle_cnt;
260 uint16_t cnt;
261 uint32_t handles[5];
Andrew Vasquez3d716442005-07-06 10:30:26 -0700262 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 uint32_t rscn_entry, host_pid;
264 uint8_t rscn_queue_index;
265
266 /* Setup to process RIO completion. */
267 handle_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 switch (mb[0]) {
269 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700270 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 handle_cnt = 1;
272 break;
273 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700274 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 handle_cnt = 1;
276 mb[0] = MBA_SCSI_COMPLETION;
277 break;
278 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700279 handles[0] = mb[1];
280 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 handle_cnt = 2;
282 mb[0] = MBA_SCSI_COMPLETION;
283 break;
284 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700285 handles[0] = mb[1];
286 handles[1] = mb[2];
287 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 handle_cnt = 3;
289 mb[0] = MBA_SCSI_COMPLETION;
290 break;
291 case MBA_CMPLT_4_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700292 handles[0] = mb[1];
293 handles[1] = mb[2];
294 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
296 handle_cnt = 4;
297 mb[0] = MBA_SCSI_COMPLETION;
298 break;
299 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700300 handles[0] = mb[1];
301 handles[1] = mb[2];
302 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
304 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
305 handle_cnt = 5;
306 mb[0] = MBA_SCSI_COMPLETION;
307 break;
308 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700309 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 handles[1] = le32_to_cpu(
311 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
312 RD_MAILBOX_REG(ha, reg, 6));
313 handle_cnt = 2;
314 mb[0] = MBA_SCSI_COMPLETION;
315 break;
316 default:
317 break;
318 }
319
320 switch (mb[0]) {
321 case MBA_SCSI_COMPLETION: /* Fast Post */
322 if (!ha->flags.online)
323 break;
324
325 for (cnt = 0; cnt < handle_cnt; cnt++)
326 qla2x00_process_completed_request(ha, handles[cnt]);
327 break;
328
329 case MBA_RESET: /* Reset */
330 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", ha->host_no));
331
332 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
333 break;
334
335 case MBA_SYSTEM_ERR: /* System Error */
336 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
337 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
338 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
339
340 qla_printk(KERN_INFO, ha,
341 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
342 mb[1], mb[2], mb[3]);
343
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700344 ha->isp_ops.fw_dump(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800346 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700347 if (mb[1] == 0 && mb[2] == 0) {
348 qla_printk(KERN_ERR, ha,
349 "Unrecoverable Hardware Error: adapter "
350 "marked OFFLINE!\n");
351 ha->flags.online = 0;
352 } else
353 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
354 } else if (mb[1] == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 qla_printk(KERN_INFO, ha,
356 "Unrecoverable Hardware Error: adapter marked "
357 "OFFLINE!\n");
358 ha->flags.online = 0;
359 } else
360 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
361 break;
362
363 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
364 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
365 ha->host_no));
366 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
367
368 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
369 break;
370
371 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
372 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
373 ha->host_no));
374 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
375
376 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
377 break;
378
379 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
380 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
381 ha->host_no));
382 break;
383
384 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 DEBUG2(printk("scsi(%ld): LIP occured (%x).\n", ha->host_no,
386 mb[1]));
387 qla_printk(KERN_INFO, ha, "LIP occured (%x).\n", mb[1]);
388
389 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
390 atomic_set(&ha->loop_state, LOOP_DOWN);
391 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800392 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 }
394
395 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
396
397 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 break;
399
400 case MBA_LOOP_UP: /* Loop Up Event */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
402 link_speed = link_speeds[0];
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700403 ha->link_data_rate = PORT_SPEED_1GB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 } else {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700405 link_speed = link_speeds[LS_UNKNOWN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 if (mb[1] < 5)
407 link_speed = link_speeds[mb[1]];
408 ha->link_data_rate = mb[1];
409 }
410
411 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
412 ha->host_no, link_speed));
413 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
414 link_speed);
415
416 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 break;
418
419 case MBA_LOOP_DOWN: /* Loop Down Event */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700420 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN (%x).\n",
421 ha->host_no, mb[1]));
422 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
424 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
425 atomic_set(&ha->loop_state, LOOP_DOWN);
426 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
427 ha->device_flags |= DFLG_NO_CABLE;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800428 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 }
430
431 ha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700432 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Andrew Vasquezcca53352005-08-26 19:08:30 -0700433 if (ql2xfdmienable)
434 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 break;
436
437 case MBA_LIP_RESET: /* LIP reset occurred */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
439 ha->host_no, mb[1]));
440 qla_printk(KERN_INFO, ha,
441 "LIP reset occured (%x).\n", mb[1]);
442
443 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
444 atomic_set(&ha->loop_state, LOOP_DOWN);
445 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800446 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 }
448
449 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
450
451 ha->operating_mode = LOOP;
452 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 break;
454
455 case MBA_POINT_TO_POINT: /* Point-to-Point */
456 if (IS_QLA2100(ha))
457 break;
458
459 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
460 ha->host_no));
461
462 /*
463 * Until there's a transition from loop down to loop up, treat
464 * this as loop down only.
465 */
466 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
467 atomic_set(&ha->loop_state, LOOP_DOWN);
468 if (!atomic_read(&ha->loop_down_timer))
469 atomic_set(&ha->loop_down_timer,
470 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800471 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 }
473
474 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
475 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
476 }
477 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
478 break;
479
480 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
481 if (IS_QLA2100(ha))
482 break;
483
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
485 "received.\n",
486 ha->host_no));
487 qla_printk(KERN_INFO, ha,
488 "Configuration change detected: value=%x.\n", mb[1]);
489
490 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700491 atomic_set(&ha->loop_state, LOOP_DOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 if (!atomic_read(&ha->loop_down_timer))
493 atomic_set(&ha->loop_down_timer,
494 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800495 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 }
497
498 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
499 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
500 break;
501
502 case MBA_PORT_UPDATE: /* Port database update */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET
505 * event etc. earlier indicating loop is down) then process
506 * it. Otherwise ignore it and Wait for RSCN to come in.
507 */
508 atomic_set(&ha->loop_down_timer, 0);
509 if (atomic_read(&ha->loop_state) != LOOP_DOWN &&
510 atomic_read(&ha->loop_state) != LOOP_DEAD) {
511 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700512 "ignored %04x/%04x/%04x.\n", ha->host_no, mb[1],
513 mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 break;
515 }
516
517 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
518 ha->host_no));
519 DEBUG(printk(KERN_INFO
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700520 "scsi(%ld): Port database changed %04x %04x %04x.\n",
521 ha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
523 /*
524 * Mark all devices as missing so we will login again.
525 */
526 atomic_set(&ha->loop_state, LOOP_UP);
527
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800528 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
530 ha->flags.rscn_queue_overflow = 1;
531
532 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
533 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 break;
535
536 case MBA_RSCN_UPDATE: /* State Change Registration */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
538 ha->host_no));
539 DEBUG(printk(KERN_INFO
540 "scsi(%ld): RSCN database changed -- %04x %04x.\n",
541 ha->host_no, mb[1], mb[2]));
542
543 rscn_entry = (mb[1] << 16) | mb[2];
544 host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) |
545 ha->d_id.b.al_pa;
546 if (rscn_entry == host_pid) {
547 DEBUG(printk(KERN_INFO
548 "scsi(%ld): Ignoring RSCN update to local host "
549 "port ID (%06x)\n",
550 ha->host_no, host_pid));
551 break;
552 }
553
554 rscn_queue_index = ha->rscn_in_ptr + 1;
555 if (rscn_queue_index == MAX_RSCN_COUNT)
556 rscn_queue_index = 0;
557 if (rscn_queue_index != ha->rscn_out_ptr) {
558 ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry;
559 ha->rscn_in_ptr = rscn_queue_index;
560 } else {
561 ha->flags.rscn_queue_overflow = 1;
562 }
563
564 atomic_set(&ha->loop_state, LOOP_UPDATE);
565 atomic_set(&ha->loop_down_timer, 0);
566 ha->flags.management_server_logged_in = 0;
567
568 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
569 set_bit(RSCN_UPDATE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 break;
571
572 /* case MBA_RIO_RESPONSE: */
573 case MBA_ZIO_RESPONSE:
574 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
575 ha->host_no));
576 DEBUG(printk(KERN_INFO
577 "scsi(%ld): [R|Z]IO update completion.\n",
578 ha->host_no));
579
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800580 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700581 qla24xx_process_response_queue(ha);
582 else
583 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700585
586 case MBA_DISCARD_RND_FRAME:
587 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
588 "%04x.\n", ha->host_no, mb[1], mb[2], mb[3]));
589 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700590
591 case MBA_TRACE_NOTIFICATION:
592 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
593 ha->host_no, mb[1], mb[2]));
594 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 }
596}
597
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700598static void
599qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
600{
601 fc_port_t *fcport = data;
602
603 if (fcport->ha->max_q_depth <= sdev->queue_depth)
604 return;
605
606 if (sdev->ordered_tags)
607 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
608 sdev->queue_depth + 1);
609 else
610 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
611 sdev->queue_depth + 1);
612
613 fcport->last_ramp_up = jiffies;
614
615 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
616 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
617 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
618 sdev->queue_depth));
619}
620
621static void
622qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
623{
624 fc_port_t *fcport = data;
625
626 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
627 return;
628
629 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
630 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
631 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
632 sdev->queue_depth));
633}
634
635static inline void
636qla2x00_ramp_up_queue_depth(scsi_qla_host_t *ha, srb_t *sp)
637{
638 fc_port_t *fcport;
639 struct scsi_device *sdev;
640
641 sdev = sp->cmd->device;
642 if (sdev->queue_depth >= ha->max_q_depth)
643 return;
644
645 fcport = sp->fcport;
646 if (time_before(jiffies,
647 fcport->last_ramp_up + ql2xqfullrampup * HZ))
648 return;
649 if (time_before(jiffies,
650 fcport->last_queue_full + ql2xqfullrampup * HZ))
651 return;
652
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700653 starget_for_each_device(sdev->sdev_target, fcport,
654 qla2x00_adjust_sdev_qdepth_up);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700655}
656
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657/**
658 * qla2x00_process_completed_request() - Process a Fast Post response.
659 * @ha: SCSI driver HA context
660 * @index: SRB index
661 */
662static void
663qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
664{
665 srb_t *sp;
666
667 /* Validate handle. */
668 if (index >= MAX_OUTSTANDING_COMMANDS) {
669 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
670 ha->host_no, index));
671 qla_printk(KERN_WARNING, ha,
672 "Invalid SCSI completion handle %d.\n", index);
673
674 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
675 return;
676 }
677
678 sp = ha->outstanding_cmds[index];
679 if (sp) {
680 /* Free outstanding command slot. */
681 ha->outstanding_cmds[index] = NULL;
682
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 CMD_COMPL_STATUS(sp->cmd) = 0L;
684 CMD_SCSI_STATUS(sp->cmd) = 0L;
685
686 /* Save ISP completion status */
687 sp->cmd->result = DID_OK << 16;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700688
689 qla2x00_ramp_up_queue_depth(ha, sp);
f4f051e2005-04-17 15:02:26 -0500690 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 } else {
692 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
693 ha->host_no));
694 qla_printk(KERN_WARNING, ha,
695 "Invalid ISP SCSI completion handle\n");
696
697 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
698 }
699}
700
701/**
702 * qla2x00_process_response_queue() - Process response queue entries.
703 * @ha: SCSI driver HA context
704 */
705void
706qla2x00_process_response_queue(struct scsi_qla_host *ha)
707{
Andrew Vasquez3d716442005-07-06 10:30:26 -0700708 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 sts_entry_t *pkt;
710 uint16_t handle_cnt;
711 uint16_t cnt;
712
713 if (!ha->flags.online)
714 return;
715
716 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
717 pkt = (sts_entry_t *)ha->response_ring_ptr;
718
719 ha->rsp_ring_index++;
720 if (ha->rsp_ring_index == ha->response_q_length) {
721 ha->rsp_ring_index = 0;
722 ha->response_ring_ptr = ha->response_ring;
723 } else {
724 ha->response_ring_ptr++;
725 }
726
727 if (pkt->entry_status != 0) {
728 DEBUG3(printk(KERN_INFO
729 "scsi(%ld): Process error entry.\n", ha->host_no));
730
731 qla2x00_error_entry(ha, pkt);
732 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
733 wmb();
734 continue;
735 }
736
737 switch (pkt->entry_type) {
738 case STATUS_TYPE:
739 qla2x00_status_entry(ha, pkt);
740 break;
741 case STATUS_TYPE_21:
742 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
743 for (cnt = 0; cnt < handle_cnt; cnt++) {
744 qla2x00_process_completed_request(ha,
745 ((sts21_entry_t *)pkt)->handle[cnt]);
746 }
747 break;
748 case STATUS_TYPE_22:
749 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
750 for (cnt = 0; cnt < handle_cnt; cnt++) {
751 qla2x00_process_completed_request(ha,
752 ((sts22_entry_t *)pkt)->handle[cnt]);
753 }
754 break;
755 case STATUS_CONT_TYPE:
756 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
757 break;
758 case MS_IOCB_TYPE:
759 qla2x00_ms_entry(ha, (ms_iocb_entry_t *)pkt);
760 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 default:
762 /* Type Not Supported. */
763 DEBUG4(printk(KERN_WARNING
764 "scsi(%ld): Received unknown response pkt type %x "
765 "entry status=%x.\n",
766 ha->host_no, pkt->entry_type, pkt->entry_status));
767 break;
768 }
769 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
770 wmb();
771 }
772
773 /* Adjust ring index */
774 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index);
775}
776
777/**
778 * qla2x00_status_entry() - Process a Status IOCB entry.
779 * @ha: SCSI driver HA context
780 * @pkt: Entry pointer
781 */
782static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700783qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 fc_port_t *fcport;
787 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700788 sts_entry_t *sts;
789 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 uint16_t comp_status;
791 uint16_t scsi_status;
792 uint8_t lscsi_status;
793 int32_t resid;
Ravi Ananded17c71b52006-05-17 15:08:55 -0700794 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700795 uint8_t *rsp_info, *sense_data;
796
797 sts = (sts_entry_t *) pkt;
798 sts24 = (struct sts_entry_24xx *) pkt;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800799 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700800 comp_status = le16_to_cpu(sts24->comp_status);
801 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
802 } else {
803 comp_status = le16_to_cpu(sts->comp_status);
804 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
805 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
807 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700808 if (comp_status == CS_COMPLETE && scsi_status == 0) {
809 qla2x00_process_completed_request(ha, sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
811 return;
812 }
813
814 /* Validate handle. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700815 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
816 sp = ha->outstanding_cmds[sts->handle];
817 ha->outstanding_cmds[sts->handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 } else
819 sp = NULL;
820
821 if (sp == NULL) {
822 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
823 ha->host_no));
824 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
825
826 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +0100827 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 return;
829 }
830 cp = sp->cmd;
831 if (cp == NULL) {
832 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -0700833 "pkt->handle=%d sp=%p.\n", ha->host_no, sts->handle, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 qla_printk(KERN_WARNING, ha,
835 "Command is NULL: already returned to OS (sp=%p)\n", sp);
836
837 return;
838 }
839
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700840 lscsi_status = scsi_status & STATUS_MASK;
841 CMD_ENTRY_STATUS(cp) = sts->entry_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 CMD_COMPL_STATUS(cp) = comp_status;
843 CMD_SCSI_STATUS(cp) = scsi_status;
844
bdf79622005-04-17 15:06:53 -0500845 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
Ravi Ananded17c71b52006-05-17 15:08:55 -0700847 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800848 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700849 sense_len = le32_to_cpu(sts24->sense_len);
850 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
851 resid_len = le32_to_cpu(sts24->rsp_residual_count);
Ravi Ananded17c71b52006-05-17 15:08:55 -0700852 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700853 rsp_info = sts24->data;
854 sense_data = sts24->data;
855 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
856 } else {
857 sense_len = le16_to_cpu(sts->req_sense_length);
858 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
859 resid_len = le32_to_cpu(sts->residual_length);
860 rsp_info = sts->rsp_info;
861 sense_data = sts->req_sense_data;
862 }
863
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 /* Check for any FCP transport errors. */
865 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700866 /* Sense data lies beyond any FCP RESPONSE data. */
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800867 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700868 sense_data += rsp_info_len;
869 if (rsp_info_len > 3 && rsp_info[3]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
871 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700872 "retrying command\n", ha->host_no,
873 cp->device->channel, cp->device->id,
874 cp->device->lun, rsp_info_len, rsp_info[0],
875 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
876 rsp_info[5], rsp_info[6], rsp_info[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
878 cp->result = DID_BUS_BUSY << 16;
f4f051e2005-04-17 15:02:26 -0500879 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 return;
881 }
882 }
883
884 /*
885 * Based on Host and scsi status generate status code for Linux
886 */
887 switch (comp_status) {
888 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700889 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 if (scsi_status == 0) {
891 cp->result = DID_OK << 16;
892 break;
893 }
894 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700895 resid = resid_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 cp->resid = resid;
897 CMD_RESID_LEN(cp) = resid;
Andrew Vasquez0da69df2005-12-06 10:58:06 -0800898
899 if (!lscsi_status &&
900 ((unsigned)(cp->request_bufflen - resid) <
901 cp->underflow)) {
902 qla_printk(KERN_INFO, ha,
903 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
904 "detected (%x of %x bytes)...returning "
905 "error status.\n", ha->host_no,
906 cp->device->channel, cp->device->id,
907 cp->device->lun, resid,
908 cp->request_bufflen);
909
910 cp->result = DID_ERROR << 16;
911 break;
912 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 cp->result = DID_OK << 16 | lscsi_status;
915
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700916 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
917 DEBUG2(printk(KERN_INFO
918 "scsi(%ld): QUEUE FULL status detected "
919 "0x%x-0x%x.\n", ha->host_no, comp_status,
920 scsi_status));
921
922 /* Adjust queue depth for all luns on the port. */
923 fcport->last_queue_full = jiffies;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700924 starget_for_each_device(cp->device->sdev_target,
925 fcport, qla2x00_adjust_sdev_qdepth_down);
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700926 break;
927 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 if (lscsi_status != SS_CHECK_CONDITION)
929 break;
930
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700931 /* Copy Sense Data into sense buffer. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
933
934 if (!(scsi_status & SS_SENSE_LEN_VALID))
935 break;
936
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700937 if (sense_len >= sizeof(cp->sense_buffer))
938 sense_len = sizeof(cp->sense_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700940 CMD_ACTUAL_SNSLEN(cp) = sense_len;
941 sp->request_sense_length = sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 sp->request_sense_ptr = cp->sense_buffer;
943
944 if (sp->request_sense_length > 32)
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700945 sense_len = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700947 memcpy(cp->sense_buffer, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700949 sp->request_sense_ptr += sense_len;
950 sp->request_sense_length -= sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 if (sp->request_sense_length != 0)
952 ha->status_srb = sp;
953
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 DEBUG5(printk("%s(): Check condition Sense data, "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700955 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n", __func__,
956 ha->host_no, cp->device->channel, cp->device->id,
957 cp->device->lun, cp, cp->serial_number));
958 if (sense_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
960 CMD_ACTUAL_SNSLEN(cp)));
961 break;
962
963 case CS_DATA_UNDERRUN:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700964 resid = resid_len;
Ravi Ananded17c71b52006-05-17 15:08:55 -0700965 /* Use F/W calculated residual length. */
966 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
967 resid = fw_resid_len;
968
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 if (scsi_status & SS_RESIDUAL_UNDER) {
970 cp->resid = resid;
971 CMD_RESID_LEN(cp) = resid;
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -0800972 } else {
973 DEBUG2(printk(KERN_INFO
974 "scsi(%ld:%d:%d) UNDERRUN status detected "
Ravi Ananded17c71b52006-05-17 15:08:55 -0700975 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
976 "os_underflow=0x%x\n", ha->host_no,
977 cp->device->id, cp->device->lun, comp_status,
978 scsi_status, resid_len, resid, cp->cmnd[0],
979 cp->underflow));
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -0800980
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 }
982
983 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700984 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 * Status.
986 */
987 if (lscsi_status != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 cp->result = DID_OK << 16 | lscsi_status;
989
Andrew Vasquezffec28a2007-01-29 10:22:27 -0800990 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
991 DEBUG2(printk(KERN_INFO
992 "scsi(%ld): QUEUE FULL status detected "
993 "0x%x-0x%x.\n", ha->host_no, comp_status,
994 scsi_status));
995
996 /*
997 * Adjust queue depth for all luns on the
998 * port.
999 */
1000 fcport->last_queue_full = jiffies;
1001 starget_for_each_device(
1002 cp->device->sdev_target, fcport,
1003 qla2x00_adjust_sdev_qdepth_down);
1004 break;
1005 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 if (lscsi_status != SS_CHECK_CONDITION)
1007 break;
1008
1009 /* Copy Sense Data into sense buffer */
1010 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
1011
1012 if (!(scsi_status & SS_SENSE_LEN_VALID))
1013 break;
1014
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001015 if (sense_len >= sizeof(cp->sense_buffer))
1016 sense_len = sizeof(cp->sense_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001018 CMD_ACTUAL_SNSLEN(cp) = sense_len;
1019 sp->request_sense_length = sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 sp->request_sense_ptr = cp->sense_buffer;
1021
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001022 if (sp->request_sense_length > 32)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001023 sense_len = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001025 memcpy(cp->sense_buffer, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001027 sp->request_sense_ptr += sense_len;
1028 sp->request_sense_length -= sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 if (sp->request_sense_length != 0)
1030 ha->status_srb = sp;
1031
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 DEBUG5(printk("%s(): Check condition Sense data, "
1033 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001034 __func__, ha->host_no, cp->device->channel,
1035 cp->device->id, cp->device->lun, cp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 cp->serial_number));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001037
1038 if (sense_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
1040 CMD_ACTUAL_SNSLEN(cp)));
1041 } else {
1042 /*
1043 * If RISC reports underrun and target does not report
1044 * it then we must have a lost frame, so tell upper
1045 * layer to retry it by reporting a bus busy.
1046 */
1047 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1048 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1049 "frame(s) detected (%x of %x bytes)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001050 "retrying command.\n", ha->host_no,
1051 cp->device->channel, cp->device->id,
1052 cp->device->lun, resid,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 cp->request_bufflen));
1054
1055 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 break;
1057 }
1058
1059 /* Handle mid-layer underflow */
1060 if ((unsigned)(cp->request_bufflen - resid) <
1061 cp->underflow) {
1062 qla_printk(KERN_INFO, ha,
1063 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1064 "detected (%x of %x bytes)...returning "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001065 "error status.\n", ha->host_no,
1066 cp->device->channel, cp->device->id,
1067 cp->device->lun, resid,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 cp->request_bufflen);
1069
1070 cp->result = DID_ERROR << 16;
1071 break;
1072 }
1073
1074 /* Everybody online, looking good... */
1075 cp->result = DID_OK << 16;
1076 }
1077 break;
1078
1079 case CS_DATA_OVERRUN:
1080 DEBUG2(printk(KERN_INFO
1081 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001082 ha->host_no, cp->device->id, cp->device->lun, comp_status,
1083 scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 DEBUG2(printk(KERN_INFO
1085 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1086 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1087 cp->cmnd[4], cp->cmnd[5]));
1088 DEBUG2(printk(KERN_INFO
1089 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1090 "status!\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001091 cp->serial_number, cp->request_bufflen, resid_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093 cp->result = DID_ERROR << 16;
1094 break;
1095
1096 case CS_PORT_LOGGED_OUT:
1097 case CS_PORT_CONFIG_CHG:
1098 case CS_PORT_BUSY:
1099 case CS_INCOMPLETE:
1100 case CS_PORT_UNAVAILABLE:
1101 /*
1102 * If the port is in Target Down state, return all IOs for this
1103 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1104 * retry_queue.
1105 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1107 "pid=%ld, compl status=0x%x, port state=0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001108 ha->host_no, cp->device->id, cp->device->lun,
1109 cp->serial_number, comp_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 atomic_read(&fcport->state)));
1111
f4f051e2005-04-17 15:02:26 -05001112 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 if (atomic_read(&fcport->state) == FCS_ONLINE) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001114 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 break;
1117
1118 case CS_RESET:
1119 DEBUG2(printk(KERN_INFO
1120 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1121 ha->host_no, comp_status, scsi_status));
1122
f4f051e2005-04-17 15:02:26 -05001123 cp->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 break;
1125
1126 case CS_ABORTED:
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001127 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 * hv2.19.12 - DID_ABORT does not retry the request if we
1129 * aborted this request then abort otherwise it must be a
1130 * reset.
1131 */
1132 DEBUG2(printk(KERN_INFO
1133 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1134 ha->host_no, comp_status, scsi_status));
1135
1136 cp->result = DID_RESET << 16;
1137 break;
1138
1139 case CS_TIMEOUT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 cp->result = DID_BUS_BUSY << 16;
1141
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001142 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001143 DEBUG2(printk(KERN_INFO
1144 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1145 "0x%x-0x%x\n", ha->host_no, cp->device->channel,
1146 cp->device->id, cp->device->lun, comp_status,
1147 scsi_status));
1148 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001150 DEBUG2(printk(KERN_INFO
1151 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1152 "sflags=%x.\n", ha->host_no, cp->device->channel,
1153 cp->device->id, cp->device->lun, comp_status, scsi_status,
1154 le16_to_cpu(sts->status_flags)));
1155
1156 /* Check to see if logout occurred. */
1157 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001158 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 break;
1160
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 default:
1162 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001163 "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 qla_printk(KERN_INFO, ha,
1165 "Unknown status detected 0x%x-0x%x.\n",
1166 comp_status, scsi_status);
1167
1168 cp->result = DID_ERROR << 16;
1169 break;
1170 }
1171
1172 /* Place command on done queue. */
1173 if (ha->status_srb == NULL)
f4f051e2005-04-17 15:02:26 -05001174 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175}
1176
1177/**
1178 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1179 * @ha: SCSI driver HA context
1180 * @pkt: Entry pointer
1181 *
1182 * Extended sense data.
1183 */
1184static void
1185qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1186{
1187 uint8_t sense_sz = 0;
1188 srb_t *sp = ha->status_srb;
1189 struct scsi_cmnd *cp;
1190
1191 if (sp != NULL && sp->request_sense_length != 0) {
1192 cp = sp->cmd;
1193 if (cp == NULL) {
1194 DEBUG2(printk("%s(): Cmd already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001195 "sp=%p.\n", __func__, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 qla_printk(KERN_INFO, ha,
1197 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001198 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
1200 ha->status_srb = NULL;
1201 return;
1202 }
1203
1204 if (sp->request_sense_length > sizeof(pkt->data)) {
1205 sense_sz = sizeof(pkt->data);
1206 } else {
1207 sense_sz = sp->request_sense_length;
1208 }
1209
1210 /* Move sense data. */
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001211 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001212 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1214 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1215
1216 sp->request_sense_ptr += sense_sz;
1217 sp->request_sense_length -= sense_sz;
1218
1219 /* Place command on done queue. */
1220 if (sp->request_sense_length == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 ha->status_srb = NULL;
f4f051e2005-04-17 15:02:26 -05001222 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 }
1224 }
1225}
1226
1227/**
1228 * qla2x00_error_entry() - Process an error entry.
1229 * @ha: SCSI driver HA context
1230 * @pkt: Entry pointer
1231 */
1232static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001233qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234{
1235 srb_t *sp;
1236
1237#if defined(QL_DEBUG_LEVEL_2)
1238 if (pkt->entry_status & RF_INV_E_ORDER)
1239 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1240 else if (pkt->entry_status & RF_INV_E_COUNT)
1241 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1242 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001243 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 "%s: Invalid Entry Parameter\n", __func__);
1245 else if (pkt->entry_status & RF_INV_E_TYPE)
1246 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1247 else if (pkt->entry_status & RF_BUSY)
1248 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1249 else
1250 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1251#endif
1252
1253 /* Validate handle. */
1254 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1255 sp = ha->outstanding_cmds[pkt->handle];
1256 else
1257 sp = NULL;
1258
1259 if (sp) {
1260 /* Free outstanding command slot. */
1261 ha->outstanding_cmds[pkt->handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001262
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 /* Bad payload or header */
1264 if (pkt->entry_status &
1265 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1266 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1267 sp->cmd->result = DID_ERROR << 16;
1268 } else if (pkt->entry_status & RF_BUSY) {
1269 sp->cmd->result = DID_BUS_BUSY << 16;
1270 } else {
1271 sp->cmd->result = DID_ERROR << 16;
1272 }
f4f051e2005-04-17 15:02:26 -05001273 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001275 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1276 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1278 ha->host_no));
1279 qla_printk(KERN_WARNING, ha,
1280 "Error entry - invalid handle\n");
1281
1282 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +01001283 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 }
1285}
1286
1287/**
1288 * qla2x00_ms_entry() - Process a Management Server entry.
1289 * @ha: SCSI driver HA context
1290 * @index: Response queue out pointer
1291 */
1292static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001293qla2x00_ms_entry(scsi_qla_host_t *ha, ms_iocb_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294{
1295 srb_t *sp;
1296
1297 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1298 __func__, ha->host_no, pkt, pkt->handle1));
1299
1300 /* Validate handle. */
1301 if (pkt->handle1 < MAX_OUTSTANDING_COMMANDS)
1302 sp = ha->outstanding_cmds[pkt->handle1];
1303 else
1304 sp = NULL;
1305
1306 if (sp == NULL) {
1307 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1308 ha->host_no));
1309 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle\n");
1310
1311 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1312 return;
1313 }
1314
1315 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->status);
1316 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1317
1318 /* Free outstanding command slot. */
1319 ha->outstanding_cmds[pkt->handle1] = NULL;
1320
f4f051e2005-04-17 15:02:26 -05001321 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322}
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001323
1324
1325/**
1326 * qla24xx_mbx_completion() - Process mailbox command completions.
1327 * @ha: SCSI driver HA context
1328 * @mb0: Mailbox0 register
1329 */
1330static void
1331qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
1332{
1333 uint16_t cnt;
1334 uint16_t __iomem *wptr;
1335 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1336
1337 /* Load return mailbox registers. */
1338 ha->flags.mbox_int = 1;
1339 ha->mailbox_out[0] = mb0;
1340 wptr = (uint16_t __iomem *)&reg->mailbox1;
1341
1342 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1343 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1344 wptr++;
1345 }
1346
1347 if (ha->mcp) {
1348 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1349 __func__, ha->host_no, ha->mcp->mb[0]));
1350 } else {
1351 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1352 __func__, ha->host_no));
1353 }
1354}
1355
1356/**
1357 * qla24xx_process_response_queue() - Process response queue entries.
1358 * @ha: SCSI driver HA context
1359 */
1360void
1361qla24xx_process_response_queue(struct scsi_qla_host *ha)
1362{
1363 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1364 struct sts_entry_24xx *pkt;
1365
1366 if (!ha->flags.online)
1367 return;
1368
1369 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
1370 pkt = (struct sts_entry_24xx *)ha->response_ring_ptr;
1371
1372 ha->rsp_ring_index++;
1373 if (ha->rsp_ring_index == ha->response_q_length) {
1374 ha->rsp_ring_index = 0;
1375 ha->response_ring_ptr = ha->response_ring;
1376 } else {
1377 ha->response_ring_ptr++;
1378 }
1379
1380 if (pkt->entry_status != 0) {
1381 DEBUG3(printk(KERN_INFO
1382 "scsi(%ld): Process error entry.\n", ha->host_no));
1383
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001384 qla2x00_error_entry(ha, (sts_entry_t *) pkt);
1385 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1386 wmb();
1387 continue;
1388 }
1389
1390 switch (pkt->entry_type) {
1391 case STATUS_TYPE:
1392 qla2x00_status_entry(ha, pkt);
1393 break;
1394 case STATUS_CONT_TYPE:
1395 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
1396 break;
1397 case MS_IOCB_TYPE:
1398 qla24xx_ms_entry(ha, (struct ct_entry_24xx *)pkt);
1399 break;
1400 default:
1401 /* Type Not Supported. */
1402 DEBUG4(printk(KERN_WARNING
1403 "scsi(%ld): Received unknown response pkt type %x "
1404 "entry status=%x.\n",
1405 ha->host_no, pkt->entry_type, pkt->entry_status));
1406 break;
1407 }
1408 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1409 wmb();
1410 }
1411
1412 /* Adjust ring index */
1413 WRT_REG_DWORD(&reg->rsp_q_out, ha->rsp_ring_index);
1414}
1415
1416/**
1417 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1418 * @irq:
1419 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001420 *
1421 * Called by system whenever the host adapter generates an interrupt.
1422 *
1423 * Returns handled flag.
1424 */
1425irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001426qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001427{
1428 scsi_qla_host_t *ha;
1429 struct device_reg_24xx __iomem *reg;
1430 int status;
1431 unsigned long flags;
1432 unsigned long iter;
1433 uint32_t stat;
1434 uint32_t hccr;
1435 uint16_t mb[4];
1436
1437 ha = (scsi_qla_host_t *) dev_id;
1438 if (!ha) {
1439 printk(KERN_INFO
1440 "%s(): NULL host pointer\n", __func__);
1441 return IRQ_NONE;
1442 }
1443
1444 reg = &ha->iobase->isp24;
1445 status = 0;
1446
1447 spin_lock_irqsave(&ha->hardware_lock, flags);
1448 for (iter = 50; iter--; ) {
1449 stat = RD_REG_DWORD(&reg->host_status);
1450 if (stat & HSRX_RISC_PAUSED) {
1451 hccr = RD_REG_DWORD(&reg->hccr);
1452
1453 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1454 "Dumping firmware!\n", hccr);
1455 qla24xx_fw_dump(ha, 1);
1456
1457 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1458 break;
1459 } else if ((stat & HSRX_RISC_INT) == 0)
1460 break;
1461
1462 switch (stat & 0xff) {
1463 case 0x1:
1464 case 0x2:
1465 case 0x10:
1466 case 0x11:
1467 qla24xx_mbx_completion(ha, MSW(stat));
1468 status |= MBX_INTERRUPT;
1469
1470 break;
1471 case 0x12:
1472 mb[0] = MSW(stat);
1473 mb[1] = RD_REG_WORD(&reg->mailbox1);
1474 mb[2] = RD_REG_WORD(&reg->mailbox2);
1475 mb[3] = RD_REG_WORD(&reg->mailbox3);
1476 qla2x00_async_event(ha, mb);
1477 break;
1478 case 0x13:
1479 qla24xx_process_response_queue(ha);
1480 break;
1481 default:
1482 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1483 "(%d).\n",
1484 ha->host_no, stat & 0xff));
1485 break;
1486 }
1487 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1488 RD_REG_DWORD_RELAXED(&reg->hccr);
1489 }
1490 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1491
1492 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1493 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1494 spin_lock_irqsave(&ha->mbx_reg_lock, flags);
1495
1496 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1497 up(&ha->mbx_intr_sem);
1498
1499 spin_unlock_irqrestore(&ha->mbx_reg_lock, flags);
1500 }
1501
1502 return IRQ_HANDLED;
1503}
1504
1505/**
1506 * qla24xx_ms_entry() - Process a Management Server entry.
1507 * @ha: SCSI driver HA context
1508 * @index: Response queue out pointer
1509 */
1510static void
1511qla24xx_ms_entry(scsi_qla_host_t *ha, struct ct_entry_24xx *pkt)
1512{
1513 srb_t *sp;
1514
1515 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1516 __func__, ha->host_no, pkt, pkt->handle));
1517
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001518 DEBUG9(printk("%s: ct pkt dump:\n", __func__));
1519 DEBUG9(qla2x00_dump_buffer((void *)pkt, sizeof(struct ct_entry_24xx)));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001520
1521 /* Validate handle. */
1522 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1523 sp = ha->outstanding_cmds[pkt->handle];
1524 else
1525 sp = NULL;
1526
1527 if (sp == NULL) {
1528 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1529 ha->host_no));
1530 DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n",
1531 ha->host_no));
1532 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle %d\n",
1533 pkt->handle);
1534
1535 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1536 return;
1537 }
1538
1539 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->comp_status);
1540 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1541
1542 /* Free outstanding command slot. */
1543 ha->outstanding_cmds[pkt->handle] = NULL;
1544
1545 qla2x00_sp_compl(ha, sp);
1546}
1547
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001548static irqreturn_t
1549qla24xx_msix_rsp_q(int irq, void *dev_id)
1550{
1551 scsi_qla_host_t *ha;
1552 struct device_reg_24xx __iomem *reg;
1553 unsigned long flags;
1554
1555 ha = dev_id;
1556 reg = &ha->iobase->isp24;
1557
1558 spin_lock_irqsave(&ha->hardware_lock, flags);
1559
1560 qla24xx_process_response_queue(ha);
1561
1562 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1563 RD_REG_DWORD_RELAXED(&reg->hccr);
1564
1565 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1566
1567 return IRQ_HANDLED;
1568}
1569
1570static irqreturn_t
1571qla24xx_msix_default(int irq, void *dev_id)
1572{
1573 scsi_qla_host_t *ha;
1574 struct device_reg_24xx __iomem *reg;
1575 int status;
1576 unsigned long flags;
1577 unsigned long iter;
1578 uint32_t stat;
1579 uint32_t hccr;
1580 uint16_t mb[4];
1581
1582 ha = dev_id;
1583 reg = &ha->iobase->isp24;
1584 status = 0;
1585
1586 spin_lock_irqsave(&ha->hardware_lock, flags);
1587 for (iter = 50; iter--; ) {
1588 stat = RD_REG_DWORD(&reg->host_status);
1589 if (stat & HSRX_RISC_PAUSED) {
1590 hccr = RD_REG_DWORD(&reg->hccr);
1591
1592 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1593 "Dumping firmware!\n", hccr);
1594 ha->isp_ops.fw_dump(ha, 1);
1595 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1596 break;
1597 } else if ((stat & HSRX_RISC_INT) == 0)
1598 break;
1599
1600 switch (stat & 0xff) {
1601 case 0x1:
1602 case 0x2:
1603 case 0x10:
1604 case 0x11:
1605 qla24xx_mbx_completion(ha, MSW(stat));
1606 status |= MBX_INTERRUPT;
1607
1608 break;
1609 case 0x12:
1610 mb[0] = MSW(stat);
1611 mb[1] = RD_REG_WORD(&reg->mailbox1);
1612 mb[2] = RD_REG_WORD(&reg->mailbox2);
1613 mb[3] = RD_REG_WORD(&reg->mailbox3);
1614 qla2x00_async_event(ha, mb);
1615 break;
1616 case 0x13:
1617 qla24xx_process_response_queue(ha);
1618 break;
1619 default:
1620 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1621 "(%d).\n",
1622 ha->host_no, stat & 0xff));
1623 break;
1624 }
1625 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1626 RD_REG_DWORD_RELAXED(&reg->hccr);
1627 }
1628 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1629
1630 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1631 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1632 spin_lock_irqsave(&ha->mbx_reg_lock, flags);
1633
1634 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1635 up(&ha->mbx_intr_sem);
1636
1637 spin_unlock_irqrestore(&ha->mbx_reg_lock, flags);
1638 }
1639
1640 return IRQ_HANDLED;
1641}
1642
1643/* Interrupt handling helpers. */
1644
1645struct qla_init_msix_entry {
1646 uint16_t entry;
1647 uint16_t index;
1648 const char *name;
1649 irqreturn_t (*handler)(int, void *);
1650};
1651
1652static struct qla_init_msix_entry imsix_entries[QLA_MSIX_ENTRIES] = {
1653 { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT,
1654 "qla2xxx (default)", qla24xx_msix_default },
1655
1656 { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q,
1657 "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
1658};
1659
1660static void
1661qla24xx_disable_msix(scsi_qla_host_t *ha)
1662{
1663 int i;
1664 struct qla_msix_entry *qentry;
1665
1666 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1667 qentry = &ha->msix_entries[imsix_entries[i].index];
1668 if (qentry->have_irq)
1669 free_irq(qentry->msix_vector, ha);
1670 }
1671 pci_disable_msix(ha->pdev);
1672}
1673
1674static int
1675qla24xx_enable_msix(scsi_qla_host_t *ha)
1676{
1677 int i, ret;
1678 struct msix_entry entries[QLA_MSIX_ENTRIES];
1679 struct qla_msix_entry *qentry;
1680
1681 for (i = 0; i < QLA_MSIX_ENTRIES; i++)
1682 entries[i].entry = imsix_entries[i].entry;
1683
1684 ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries));
1685 if (ret) {
1686 qla_printk(KERN_WARNING, ha,
1687 "MSI-X: Failed to enable support -- %d/%d\n",
1688 QLA_MSIX_ENTRIES, ret);
1689 goto msix_out;
1690 }
1691 ha->flags.msix_enabled = 1;
1692
1693 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1694 qentry = &ha->msix_entries[imsix_entries[i].index];
1695 qentry->msix_vector = entries[i].vector;
1696 qentry->msix_entry = entries[i].entry;
1697 qentry->have_irq = 0;
1698 ret = request_irq(qentry->msix_vector,
1699 imsix_entries[i].handler, 0, imsix_entries[i].name, ha);
1700 if (ret) {
1701 qla_printk(KERN_WARNING, ha,
1702 "MSI-X: Unable to register handler -- %x/%d.\n",
1703 imsix_entries[i].index, ret);
1704 qla24xx_disable_msix(ha);
1705 goto msix_out;
1706 }
1707 qentry->have_irq = 1;
1708 }
1709
1710msix_out:
1711 return ret;
1712}
1713
1714int
1715qla2x00_request_irqs(scsi_qla_host_t *ha)
1716{
1717 int ret;
1718
1719 /* If possible, enable MSI-X. */
1720 if (!IS_QLA2432(ha))
1721 goto skip_msix;
1722
1723 if (ha->chip_revision < QLA_MSIX_CHIP_REV_24XX ||
1724 !QLA_MSIX_FW_MODE_1(ha->fw_attributes)) {
1725 DEBUG2(qla_printk(KERN_WARNING, ha,
1726 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1727 ha->chip_revision, ha->fw_attributes));
1728
1729 goto skip_msix;
1730 }
1731
1732 ret = qla24xx_enable_msix(ha);
1733 if (!ret) {
1734 DEBUG2(qla_printk(KERN_INFO, ha,
1735 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1736 ha->fw_attributes));
1737 return ret;
1738 }
1739 qla_printk(KERN_WARNING, ha,
1740 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1741skip_msix:
1742 ret = request_irq(ha->pdev->irq, ha->isp_ops.intr_handler,
1743 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
Andrew Vasquezd88021a2007-01-29 10:22:20 -08001744 if (!ret) {
1745 ha->flags.inta_enabled = 1;
1746 ha->host->irq = ha->pdev->irq;
1747 } else {
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001748 qla_printk(KERN_WARNING, ha,
1749 "Failed to reserve interrupt %d already in use.\n",
1750 ha->pdev->irq);
1751 }
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001752
1753 return ret;
1754}
1755
1756void
1757qla2x00_free_irqs(scsi_qla_host_t *ha)
1758{
1759
1760 if (ha->flags.msix_enabled)
1761 qla24xx_disable_msix(ha);
Andrew Vasquezd88021a2007-01-29 10:22:20 -08001762 else if (ha->flags.inta_enabled)
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001763 free_irq(ha->host->irq, ha);
1764}