blob: 39fd17b05be5ada3d3da55515c2d89bba857cd71 [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))
Andrew Vasquez07f31802006-12-13 19:20:31 -0800137 qla_printk(KERN_INFO, ha, "Parity error -- "
138 "HCCR=%x, Dumping firmware!\n", hccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 else
Andrew Vasquez07f31802006-12-13 19:20:31 -0800140 qla_printk(KERN_INFO, ha, "RISC paused -- "
141 "HCCR=%x, Dumping firmware!\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);
Andrew Vasquez07f31802006-12-13 19:20:31 -0800150
151 ha->isp_ops.fw_dump(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
153 break;
154 } else if ((stat & HSR_RISC_INT) == 0)
155 break;
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 switch (stat & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 case 0x1:
159 case 0x2:
160 case 0x10:
161 case 0x11:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700162 qla2x00_mbx_completion(ha, MSW(stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 status |= MBX_INTERRUPT;
164
165 /* Release mailbox registers. */
166 WRT_REG_WORD(&reg->semaphore, 0);
167 break;
168 case 0x12:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700169 mb[0] = MSW(stat);
170 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
171 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
172 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
173 qla2x00_async_event(ha, mb);
174 break;
175 case 0x13:
176 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 break;
178 case 0x15:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700179 mb[0] = MBA_CMPLT_1_16BIT;
180 mb[1] = MSW(stat);
181 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 break;
183 case 0x16:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700184 mb[0] = MBA_SCSI_COMPLETION;
185 mb[1] = MSW(stat);
186 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
187 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 break;
189 default:
190 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700191 "(%d).\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 ha->host_no, stat & 0xff));
193 break;
194 }
195 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
196 RD_REG_WORD_RELAXED(&reg->hccr);
197 }
198 spin_unlock_irqrestore(&ha->hardware_lock, flags);
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
201 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
202 spin_lock_irqsave(&ha->mbx_reg_lock, flags);
203
204 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
205 up(&ha->mbx_intr_sem);
206
207 spin_unlock_irqrestore(&ha->mbx_reg_lock, flags);
208 }
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 return (IRQ_HANDLED);
211}
212
213/**
214 * qla2x00_mbx_completion() - Process mailbox command completions.
215 * @ha: SCSI driver HA context
216 * @mb0: Mailbox0 register
217 */
218static void
219qla2x00_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
220{
221 uint16_t cnt;
222 uint16_t __iomem *wptr;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700223 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225 /* Load return mailbox registers. */
226 ha->flags.mbox_int = 1;
227 ha->mailbox_out[0] = mb0;
228 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
229
230 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700231 if (IS_QLA2200(ha) && cnt == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
233 if (cnt == 4 || cnt == 5)
234 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
235 else
236 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 wptr++;
239 }
240
241 if (ha->mcp) {
242 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
243 __func__, ha->host_no, ha->mcp->mb[0]));
244 } else {
245 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
246 __func__, ha->host_no));
247 }
248}
249
250/**
251 * qla2x00_async_event() - Process aynchronous events.
252 * @ha: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700253 * @mb: Mailbox registers (0 - 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 */
255static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700256qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700258#define LS_UNKNOWN 2
259 static char *link_speeds[5] = { "1", "2", "?", "4", "10" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 char *link_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 uint16_t handle_cnt;
262 uint16_t cnt;
263 uint32_t handles[5];
Andrew Vasquez3d716442005-07-06 10:30:26 -0700264 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 uint32_t rscn_entry, host_pid;
266 uint8_t rscn_queue_index;
267
268 /* Setup to process RIO completion. */
269 handle_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 switch (mb[0]) {
271 case MBA_SCSI_COMPLETION:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700272 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 handle_cnt = 1;
274 break;
275 case MBA_CMPLT_1_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700276 handles[0] = mb[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 handle_cnt = 1;
278 mb[0] = MBA_SCSI_COMPLETION;
279 break;
280 case MBA_CMPLT_2_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700281 handles[0] = mb[1];
282 handles[1] = mb[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 handle_cnt = 2;
284 mb[0] = MBA_SCSI_COMPLETION;
285 break;
286 case MBA_CMPLT_3_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700287 handles[0] = mb[1];
288 handles[1] = mb[2];
289 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 handle_cnt = 3;
291 mb[0] = MBA_SCSI_COMPLETION;
292 break;
293 case MBA_CMPLT_4_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 handle_cnt = 4;
299 mb[0] = MBA_SCSI_COMPLETION;
300 break;
301 case MBA_CMPLT_5_16BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700302 handles[0] = mb[1];
303 handles[1] = mb[2];
304 handles[2] = mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
306 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
307 handle_cnt = 5;
308 mb[0] = MBA_SCSI_COMPLETION;
309 break;
310 case MBA_CMPLT_2_32BIT:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700311 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 handles[1] = le32_to_cpu(
313 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
314 RD_MAILBOX_REG(ha, reg, 6));
315 handle_cnt = 2;
316 mb[0] = MBA_SCSI_COMPLETION;
317 break;
318 default:
319 break;
320 }
321
322 switch (mb[0]) {
323 case MBA_SCSI_COMPLETION: /* Fast Post */
324 if (!ha->flags.online)
325 break;
326
327 for (cnt = 0; cnt < handle_cnt; cnt++)
328 qla2x00_process_completed_request(ha, handles[cnt]);
329 break;
330
331 case MBA_RESET: /* Reset */
332 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", ha->host_no));
333
334 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
335 break;
336
337 case MBA_SYSTEM_ERR: /* System Error */
338 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
339 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
340 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
341
342 qla_printk(KERN_INFO, ha,
343 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
344 mb[1], mb[2], mb[3]);
345
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700346 ha->isp_ops.fw_dump(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800348 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700349 if (mb[1] == 0 && mb[2] == 0) {
350 qla_printk(KERN_ERR, ha,
351 "Unrecoverable Hardware Error: adapter "
352 "marked OFFLINE!\n");
353 ha->flags.online = 0;
354 } else
355 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
356 } else if (mb[1] == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 qla_printk(KERN_INFO, ha,
358 "Unrecoverable Hardware Error: adapter marked "
359 "OFFLINE!\n");
360 ha->flags.online = 0;
361 } else
362 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
363 break;
364
365 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
366 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
367 ha->host_no));
368 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
369
370 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
371 break;
372
373 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
374 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
375 ha->host_no));
376 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
377
378 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
379 break;
380
381 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
382 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
383 ha->host_no));
384 break;
385
386 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 DEBUG2(printk("scsi(%ld): LIP occured (%x).\n", ha->host_no,
388 mb[1]));
389 qla_printk(KERN_INFO, ha, "LIP occured (%x).\n", mb[1]);
390
391 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
392 atomic_set(&ha->loop_state, LOOP_DOWN);
393 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800394 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 }
396
397 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
398
399 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 break;
401
402 case MBA_LOOP_UP: /* Loop Up Event */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
404 link_speed = link_speeds[0];
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700405 ha->link_data_rate = PORT_SPEED_1GB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 } else {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700407 link_speed = link_speeds[LS_UNKNOWN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 if (mb[1] < 5)
409 link_speed = link_speeds[mb[1]];
410 ha->link_data_rate = mb[1];
411 }
412
413 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
414 ha->host_no, link_speed));
415 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
416 link_speed);
417
418 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 break;
420
421 case MBA_LOOP_DOWN: /* Loop Down Event */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700422 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN (%x).\n",
423 ha->host_no, mb[1]));
424 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
427 atomic_set(&ha->loop_state, LOOP_DOWN);
428 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
429 ha->device_flags |= DFLG_NO_CABLE;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800430 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 }
432
433 ha->flags.management_server_logged_in = 0;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700434 ha->link_data_rate = PORT_SPEED_UNKNOWN;
Andrew Vasquezcca53352005-08-26 19:08:30 -0700435 if (ql2xfdmienable)
436 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 break;
438
439 case MBA_LIP_RESET: /* LIP reset occurred */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
441 ha->host_no, mb[1]));
442 qla_printk(KERN_INFO, ha,
443 "LIP reset occured (%x).\n", mb[1]);
444
445 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
446 atomic_set(&ha->loop_state, LOOP_DOWN);
447 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800448 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 }
450
451 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
452
453 ha->operating_mode = LOOP;
454 ha->flags.management_server_logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 break;
456
457 case MBA_POINT_TO_POINT: /* Point-to-Point */
458 if (IS_QLA2100(ha))
459 break;
460
461 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
462 ha->host_no));
463
464 /*
465 * Until there's a transition from loop down to loop up, treat
466 * this as loop down only.
467 */
468 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
469 atomic_set(&ha->loop_state, LOOP_DOWN);
470 if (!atomic_read(&ha->loop_down_timer))
471 atomic_set(&ha->loop_down_timer,
472 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800473 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 }
475
476 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
477 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
478 }
479 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
Andrew Vasquez4346b142006-12-13 19:20:28 -0800480
481 ha->flags.gpsc_supported = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 break;
483
484 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
485 if (IS_QLA2100(ha))
486 break;
487
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
489 "received.\n",
490 ha->host_no));
491 qla_printk(KERN_INFO, ha,
492 "Configuration change detected: value=%x.\n", mb[1]);
493
494 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700495 atomic_set(&ha->loop_state, LOOP_DOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 if (!atomic_read(&ha->loop_down_timer))
497 atomic_set(&ha->loop_down_timer,
498 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800499 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 }
501
502 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
503 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
504 break;
505
506 case MBA_PORT_UPDATE: /* Port database update */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET
509 * event etc. earlier indicating loop is down) then process
510 * it. Otherwise ignore it and Wait for RSCN to come in.
511 */
512 atomic_set(&ha->loop_down_timer, 0);
513 if (atomic_read(&ha->loop_state) != LOOP_DOWN &&
514 atomic_read(&ha->loop_state) != LOOP_DEAD) {
515 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700516 "ignored %04x/%04x/%04x.\n", ha->host_no, mb[1],
517 mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 break;
519 }
520
521 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
522 ha->host_no));
523 DEBUG(printk(KERN_INFO
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700524 "scsi(%ld): Port database changed %04x %04x %04x.\n",
525 ha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
527 /*
528 * Mark all devices as missing so we will login again.
529 */
530 atomic_set(&ha->loop_state, LOOP_UP);
531
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800532 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
534 ha->flags.rscn_queue_overflow = 1;
535
536 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
537 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 break;
539
540 case MBA_RSCN_UPDATE: /* State Change Registration */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
542 ha->host_no));
543 DEBUG(printk(KERN_INFO
544 "scsi(%ld): RSCN database changed -- %04x %04x.\n",
545 ha->host_no, mb[1], mb[2]));
546
547 rscn_entry = (mb[1] << 16) | mb[2];
548 host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) |
549 ha->d_id.b.al_pa;
550 if (rscn_entry == host_pid) {
551 DEBUG(printk(KERN_INFO
552 "scsi(%ld): Ignoring RSCN update to local host "
553 "port ID (%06x)\n",
554 ha->host_no, host_pid));
555 break;
556 }
557
558 rscn_queue_index = ha->rscn_in_ptr + 1;
559 if (rscn_queue_index == MAX_RSCN_COUNT)
560 rscn_queue_index = 0;
561 if (rscn_queue_index != ha->rscn_out_ptr) {
562 ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry;
563 ha->rscn_in_ptr = rscn_queue_index;
564 } else {
565 ha->flags.rscn_queue_overflow = 1;
566 }
567
568 atomic_set(&ha->loop_state, LOOP_UPDATE);
569 atomic_set(&ha->loop_down_timer, 0);
570 ha->flags.management_server_logged_in = 0;
571
572 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
573 set_bit(RSCN_UPDATE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 break;
575
576 /* case MBA_RIO_RESPONSE: */
577 case MBA_ZIO_RESPONSE:
578 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
579 ha->host_no));
580 DEBUG(printk(KERN_INFO
581 "scsi(%ld): [R|Z]IO update completion.\n",
582 ha->host_no));
583
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800584 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700585 qla24xx_process_response_queue(ha);
586 else
587 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700589
590 case MBA_DISCARD_RND_FRAME:
591 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
592 "%04x.\n", ha->host_no, mb[1], mb[2], mb[3]));
593 break;
Andrew Vasquez45ebeb52006-08-01 13:48:14 -0700594
595 case MBA_TRACE_NOTIFICATION:
596 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
597 ha->host_no, mb[1], mb[2]));
598 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 }
600}
601
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700602static void
603qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
604{
605 fc_port_t *fcport = data;
606
607 if (fcport->ha->max_q_depth <= sdev->queue_depth)
608 return;
609
610 if (sdev->ordered_tags)
611 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
612 sdev->queue_depth + 1);
613 else
614 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
615 sdev->queue_depth + 1);
616
617 fcport->last_ramp_up = jiffies;
618
619 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
620 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
621 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
622 sdev->queue_depth));
623}
624
625static void
626qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
627{
628 fc_port_t *fcport = data;
629
630 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
631 return;
632
633 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
634 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
635 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
636 sdev->queue_depth));
637}
638
639static inline void
640qla2x00_ramp_up_queue_depth(scsi_qla_host_t *ha, srb_t *sp)
641{
642 fc_port_t *fcport;
643 struct scsi_device *sdev;
644
645 sdev = sp->cmd->device;
646 if (sdev->queue_depth >= ha->max_q_depth)
647 return;
648
649 fcport = sp->fcport;
650 if (time_before(jiffies,
651 fcport->last_ramp_up + ql2xqfullrampup * HZ))
652 return;
653 if (time_before(jiffies,
654 fcport->last_queue_full + ql2xqfullrampup * HZ))
655 return;
656
657 spin_unlock_irq(&ha->hardware_lock);
658 starget_for_each_device(sdev->sdev_target, fcport,
659 qla2x00_adjust_sdev_qdepth_up);
660 spin_lock_irq(&ha->hardware_lock);
661}
662
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663/**
664 * qla2x00_process_completed_request() - Process a Fast Post response.
665 * @ha: SCSI driver HA context
666 * @index: SRB index
667 */
668static void
669qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
670{
671 srb_t *sp;
672
673 /* Validate handle. */
674 if (index >= MAX_OUTSTANDING_COMMANDS) {
675 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
676 ha->host_no, index));
677 qla_printk(KERN_WARNING, ha,
678 "Invalid SCSI completion handle %d.\n", index);
679
680 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
681 return;
682 }
683
684 sp = ha->outstanding_cmds[index];
685 if (sp) {
686 /* Free outstanding command slot. */
687 ha->outstanding_cmds[index] = NULL;
688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 CMD_COMPL_STATUS(sp->cmd) = 0L;
690 CMD_SCSI_STATUS(sp->cmd) = 0L;
691
692 /* Save ISP completion status */
693 sp->cmd->result = DID_OK << 16;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700694
695 qla2x00_ramp_up_queue_depth(ha, sp);
f4f051e2005-04-17 15:02:26 -0500696 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 } else {
698 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
699 ha->host_no));
700 qla_printk(KERN_WARNING, ha,
701 "Invalid ISP SCSI completion handle\n");
702
703 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
704 }
705}
706
707/**
708 * qla2x00_process_response_queue() - Process response queue entries.
709 * @ha: SCSI driver HA context
710 */
711void
712qla2x00_process_response_queue(struct scsi_qla_host *ha)
713{
Andrew Vasquez3d716442005-07-06 10:30:26 -0700714 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 sts_entry_t *pkt;
716 uint16_t handle_cnt;
717 uint16_t cnt;
718
719 if (!ha->flags.online)
720 return;
721
722 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
723 pkt = (sts_entry_t *)ha->response_ring_ptr;
724
725 ha->rsp_ring_index++;
726 if (ha->rsp_ring_index == ha->response_q_length) {
727 ha->rsp_ring_index = 0;
728 ha->response_ring_ptr = ha->response_ring;
729 } else {
730 ha->response_ring_ptr++;
731 }
732
733 if (pkt->entry_status != 0) {
734 DEBUG3(printk(KERN_INFO
735 "scsi(%ld): Process error entry.\n", ha->host_no));
736
737 qla2x00_error_entry(ha, pkt);
738 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
739 wmb();
740 continue;
741 }
742
743 switch (pkt->entry_type) {
744 case STATUS_TYPE:
745 qla2x00_status_entry(ha, pkt);
746 break;
747 case STATUS_TYPE_21:
748 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
749 for (cnt = 0; cnt < handle_cnt; cnt++) {
750 qla2x00_process_completed_request(ha,
751 ((sts21_entry_t *)pkt)->handle[cnt]);
752 }
753 break;
754 case STATUS_TYPE_22:
755 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
756 for (cnt = 0; cnt < handle_cnt; cnt++) {
757 qla2x00_process_completed_request(ha,
758 ((sts22_entry_t *)pkt)->handle[cnt]);
759 }
760 break;
761 case STATUS_CONT_TYPE:
762 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
763 break;
764 case MS_IOCB_TYPE:
765 qla2x00_ms_entry(ha, (ms_iocb_entry_t *)pkt);
766 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 default:
768 /* Type Not Supported. */
769 DEBUG4(printk(KERN_WARNING
770 "scsi(%ld): Received unknown response pkt type %x "
771 "entry status=%x.\n",
772 ha->host_no, pkt->entry_type, pkt->entry_status));
773 break;
774 }
775 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
776 wmb();
777 }
778
779 /* Adjust ring index */
780 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index);
781}
782
783/**
784 * qla2x00_status_entry() - Process a Status IOCB entry.
785 * @ha: SCSI driver HA context
786 * @pkt: Entry pointer
787 */
788static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700789qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 fc_port_t *fcport;
793 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700794 sts_entry_t *sts;
795 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 uint16_t comp_status;
797 uint16_t scsi_status;
798 uint8_t lscsi_status;
799 int32_t resid;
Ravi Ananded17c712006-05-17 15:08:55 -0700800 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700801 uint8_t *rsp_info, *sense_data;
802
803 sts = (sts_entry_t *) pkt;
804 sts24 = (struct sts_entry_24xx *) pkt;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800805 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700806 comp_status = le16_to_cpu(sts24->comp_status);
807 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
808 } else {
809 comp_status = le16_to_cpu(sts->comp_status);
810 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
811 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700814 if (comp_status == CS_COMPLETE && scsi_status == 0) {
815 qla2x00_process_completed_request(ha, sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
817 return;
818 }
819
820 /* Validate handle. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700821 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
822 sp = ha->outstanding_cmds[sts->handle];
823 ha->outstanding_cmds[sts->handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 } else
825 sp = NULL;
826
827 if (sp == NULL) {
828 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
829 ha->host_no));
830 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
831
832 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +0100833 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 return;
835 }
836 cp = sp->cmd;
837 if (cp == NULL) {
838 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -0700839 "pkt->handle=%d sp=%p.\n", ha->host_no, sts->handle, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 qla_printk(KERN_WARNING, ha,
841 "Command is NULL: already returned to OS (sp=%p)\n", sp);
842
843 return;
844 }
845
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700846 lscsi_status = scsi_status & STATUS_MASK;
847 CMD_ENTRY_STATUS(cp) = sts->entry_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 CMD_COMPL_STATUS(cp) = comp_status;
849 CMD_SCSI_STATUS(cp) = scsi_status;
850
bdf79622005-04-17 15:06:53 -0500851 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
Ravi Ananded17c712006-05-17 15:08:55 -0700853 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800854 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700855 sense_len = le32_to_cpu(sts24->sense_len);
856 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
857 resid_len = le32_to_cpu(sts24->rsp_residual_count);
Ravi Ananded17c712006-05-17 15:08:55 -0700858 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700859 rsp_info = sts24->data;
860 sense_data = sts24->data;
861 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
862 } else {
863 sense_len = le16_to_cpu(sts->req_sense_length);
864 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
865 resid_len = le32_to_cpu(sts->residual_length);
866 rsp_info = sts->rsp_info;
867 sense_data = sts->req_sense_data;
868 }
869
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 /* Check for any FCP transport errors. */
871 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700872 /* Sense data lies beyond any FCP RESPONSE data. */
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800873 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700874 sense_data += rsp_info_len;
875 if (rsp_info_len > 3 && rsp_info[3]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
877 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700878 "retrying command\n", ha->host_no,
879 cp->device->channel, cp->device->id,
880 cp->device->lun, rsp_info_len, rsp_info[0],
881 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
882 rsp_info[5], rsp_info[6], rsp_info[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
884 cp->result = DID_BUS_BUSY << 16;
f4f051e2005-04-17 15:02:26 -0500885 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 return;
887 }
888 }
889
890 /*
891 * Based on Host and scsi status generate status code for Linux
892 */
893 switch (comp_status) {
894 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700895 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 if (scsi_status == 0) {
897 cp->result = DID_OK << 16;
898 break;
899 }
900 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700901 resid = resid_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 cp->resid = resid;
903 CMD_RESID_LEN(cp) = resid;
Andrew Vasquez0da69df2005-12-06 10:58:06 -0800904
905 if (!lscsi_status &&
906 ((unsigned)(cp->request_bufflen - resid) <
907 cp->underflow)) {
908 qla_printk(KERN_INFO, ha,
909 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
910 "detected (%x of %x bytes)...returning "
911 "error status.\n", ha->host_no,
912 cp->device->channel, cp->device->id,
913 cp->device->lun, resid,
914 cp->request_bufflen);
915
916 cp->result = DID_ERROR << 16;
917 break;
918 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 cp->result = DID_OK << 16 | lscsi_status;
921
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700922 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
923 DEBUG2(printk(KERN_INFO
924 "scsi(%ld): QUEUE FULL status detected "
925 "0x%x-0x%x.\n", ha->host_no, comp_status,
926 scsi_status));
927
928 /* Adjust queue depth for all luns on the port. */
929 fcport->last_queue_full = jiffies;
930 spin_unlock_irq(&ha->hardware_lock);
931 starget_for_each_device(cp->device->sdev_target,
932 fcport, qla2x00_adjust_sdev_qdepth_down);
933 spin_lock_irq(&ha->hardware_lock);
934 break;
935 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 if (lscsi_status != SS_CHECK_CONDITION)
937 break;
938
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700939 /* Copy Sense Data into sense buffer. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
941
942 if (!(scsi_status & SS_SENSE_LEN_VALID))
943 break;
944
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700945 if (sense_len >= sizeof(cp->sense_buffer))
946 sense_len = sizeof(cp->sense_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700948 CMD_ACTUAL_SNSLEN(cp) = sense_len;
949 sp->request_sense_length = sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 sp->request_sense_ptr = cp->sense_buffer;
951
952 if (sp->request_sense_length > 32)
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700953 sense_len = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700955 memcpy(cp->sense_buffer, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700957 sp->request_sense_ptr += sense_len;
958 sp->request_sense_length -= sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 if (sp->request_sense_length != 0)
960 ha->status_srb = sp;
961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 DEBUG5(printk("%s(): Check condition Sense data, "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700963 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n", __func__,
964 ha->host_no, cp->device->channel, cp->device->id,
965 cp->device->lun, cp, cp->serial_number));
966 if (sense_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
968 CMD_ACTUAL_SNSLEN(cp)));
969 break;
970
971 case CS_DATA_UNDERRUN:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700972 resid = resid_len;
Ravi Ananded17c712006-05-17 15:08:55 -0700973 /* Use F/W calculated residual length. */
974 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
975 resid = fw_resid_len;
976
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 if (scsi_status & SS_RESIDUAL_UNDER) {
978 cp->resid = resid;
979 CMD_RESID_LEN(cp) = resid;
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -0800980 } else {
981 DEBUG2(printk(KERN_INFO
982 "scsi(%ld:%d:%d) UNDERRUN status detected "
Ravi Ananded17c712006-05-17 15:08:55 -0700983 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
984 "os_underflow=0x%x\n", ha->host_no,
985 cp->device->id, cp->device->lun, comp_status,
986 scsi_status, resid_len, resid, cp->cmnd[0],
987 cp->underflow));
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -0800988
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 }
990
991 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700992 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 * Status.
994 */
995 if (lscsi_status != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 cp->result = DID_OK << 16 | lscsi_status;
997
998 if (lscsi_status != SS_CHECK_CONDITION)
999 break;
1000
1001 /* Copy Sense Data into sense buffer */
1002 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
1003
1004 if (!(scsi_status & SS_SENSE_LEN_VALID))
1005 break;
1006
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001007 if (sense_len >= sizeof(cp->sense_buffer))
1008 sense_len = sizeof(cp->sense_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001010 CMD_ACTUAL_SNSLEN(cp) = sense_len;
1011 sp->request_sense_length = sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 sp->request_sense_ptr = cp->sense_buffer;
1013
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001014 if (sp->request_sense_length > 32)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001015 sense_len = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001017 memcpy(cp->sense_buffer, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001019 sp->request_sense_ptr += sense_len;
1020 sp->request_sense_length -= sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 if (sp->request_sense_length != 0)
1022 ha->status_srb = sp;
1023
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 DEBUG5(printk("%s(): Check condition Sense data, "
1025 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001026 __func__, ha->host_no, cp->device->channel,
1027 cp->device->id, cp->device->lun, cp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 cp->serial_number));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001029
1030 if (sense_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
1032 CMD_ACTUAL_SNSLEN(cp)));
1033 } else {
1034 /*
1035 * If RISC reports underrun and target does not report
1036 * it then we must have a lost frame, so tell upper
1037 * layer to retry it by reporting a bus busy.
1038 */
1039 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1040 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1041 "frame(s) detected (%x of %x bytes)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001042 "retrying command.\n", ha->host_no,
1043 cp->device->channel, cp->device->id,
1044 cp->device->lun, resid,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 cp->request_bufflen));
1046
1047 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 break;
1049 }
1050
1051 /* Handle mid-layer underflow */
1052 if ((unsigned)(cp->request_bufflen - resid) <
1053 cp->underflow) {
1054 qla_printk(KERN_INFO, ha,
1055 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1056 "detected (%x of %x bytes)...returning "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001057 "error status.\n", ha->host_no,
1058 cp->device->channel, cp->device->id,
1059 cp->device->lun, resid,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 cp->request_bufflen);
1061
1062 cp->result = DID_ERROR << 16;
1063 break;
1064 }
1065
1066 /* Everybody online, looking good... */
1067 cp->result = DID_OK << 16;
1068 }
1069 break;
1070
1071 case CS_DATA_OVERRUN:
1072 DEBUG2(printk(KERN_INFO
1073 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001074 ha->host_no, cp->device->id, cp->device->lun, comp_status,
1075 scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 DEBUG2(printk(KERN_INFO
1077 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1078 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1079 cp->cmnd[4], cp->cmnd[5]));
1080 DEBUG2(printk(KERN_INFO
1081 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1082 "status!\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001083 cp->serial_number, cp->request_bufflen, resid_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
1085 cp->result = DID_ERROR << 16;
1086 break;
1087
1088 case CS_PORT_LOGGED_OUT:
1089 case CS_PORT_CONFIG_CHG:
1090 case CS_PORT_BUSY:
1091 case CS_INCOMPLETE:
1092 case CS_PORT_UNAVAILABLE:
1093 /*
1094 * If the port is in Target Down state, return all IOs for this
1095 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1096 * retry_queue.
1097 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1099 "pid=%ld, compl status=0x%x, port state=0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001100 ha->host_no, cp->device->id, cp->device->lun,
1101 cp->serial_number, comp_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 atomic_read(&fcport->state)));
1103
f4f051e2005-04-17 15:02:26 -05001104 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 if (atomic_read(&fcport->state) == FCS_ONLINE) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001106 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 break;
1109
1110 case CS_RESET:
1111 DEBUG2(printk(KERN_INFO
1112 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1113 ha->host_no, comp_status, scsi_status));
1114
f4f051e2005-04-17 15:02:26 -05001115 cp->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 break;
1117
1118 case CS_ABORTED:
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001119 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 * hv2.19.12 - DID_ABORT does not retry the request if we
1121 * aborted this request then abort otherwise it must be a
1122 * reset.
1123 */
1124 DEBUG2(printk(KERN_INFO
1125 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1126 ha->host_no, comp_status, scsi_status));
1127
1128 cp->result = DID_RESET << 16;
1129 break;
1130
1131 case CS_TIMEOUT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 cp->result = DID_BUS_BUSY << 16;
1133
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001134 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001135 DEBUG2(printk(KERN_INFO
1136 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1137 "0x%x-0x%x\n", ha->host_no, cp->device->channel,
1138 cp->device->id, cp->device->lun, comp_status,
1139 scsi_status));
1140 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001142 DEBUG2(printk(KERN_INFO
1143 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1144 "sflags=%x.\n", ha->host_no, cp->device->channel,
1145 cp->device->id, cp->device->lun, comp_status, scsi_status,
1146 le16_to_cpu(sts->status_flags)));
1147
1148 /* Check to see if logout occurred. */
1149 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001150 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 break;
1152
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 default:
1154 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001155 "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 qla_printk(KERN_INFO, ha,
1157 "Unknown status detected 0x%x-0x%x.\n",
1158 comp_status, scsi_status);
1159
1160 cp->result = DID_ERROR << 16;
1161 break;
1162 }
1163
1164 /* Place command on done queue. */
1165 if (ha->status_srb == NULL)
f4f051e2005-04-17 15:02:26 -05001166 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167}
1168
1169/**
1170 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1171 * @ha: SCSI driver HA context
1172 * @pkt: Entry pointer
1173 *
1174 * Extended sense data.
1175 */
1176static void
1177qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1178{
1179 uint8_t sense_sz = 0;
1180 srb_t *sp = ha->status_srb;
1181 struct scsi_cmnd *cp;
1182
1183 if (sp != NULL && sp->request_sense_length != 0) {
1184 cp = sp->cmd;
1185 if (cp == NULL) {
1186 DEBUG2(printk("%s(): Cmd already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001187 "sp=%p.\n", __func__, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 qla_printk(KERN_INFO, ha,
1189 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001190 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191
1192 ha->status_srb = NULL;
1193 return;
1194 }
1195
1196 if (sp->request_sense_length > sizeof(pkt->data)) {
1197 sense_sz = sizeof(pkt->data);
1198 } else {
1199 sense_sz = sp->request_sense_length;
1200 }
1201
1202 /* Move sense data. */
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001203 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001204 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1206 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1207
1208 sp->request_sense_ptr += sense_sz;
1209 sp->request_sense_length -= sense_sz;
1210
1211 /* Place command on done queue. */
1212 if (sp->request_sense_length == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 ha->status_srb = NULL;
f4f051e2005-04-17 15:02:26 -05001214 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 }
1216 }
1217}
1218
1219/**
1220 * qla2x00_error_entry() - Process an error entry.
1221 * @ha: SCSI driver HA context
1222 * @pkt: Entry pointer
1223 */
1224static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001225qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226{
1227 srb_t *sp;
1228
1229#if defined(QL_DEBUG_LEVEL_2)
1230 if (pkt->entry_status & RF_INV_E_ORDER)
1231 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1232 else if (pkt->entry_status & RF_INV_E_COUNT)
1233 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1234 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001235 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 "%s: Invalid Entry Parameter\n", __func__);
1237 else if (pkt->entry_status & RF_INV_E_TYPE)
1238 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1239 else if (pkt->entry_status & RF_BUSY)
1240 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1241 else
1242 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1243#endif
1244
1245 /* Validate handle. */
1246 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1247 sp = ha->outstanding_cmds[pkt->handle];
1248 else
1249 sp = NULL;
1250
1251 if (sp) {
1252 /* Free outstanding command slot. */
1253 ha->outstanding_cmds[pkt->handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001254
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 /* Bad payload or header */
1256 if (pkt->entry_status &
1257 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1258 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1259 sp->cmd->result = DID_ERROR << 16;
1260 } else if (pkt->entry_status & RF_BUSY) {
1261 sp->cmd->result = DID_BUS_BUSY << 16;
1262 } else {
1263 sp->cmd->result = DID_ERROR << 16;
1264 }
f4f051e2005-04-17 15:02:26 -05001265 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001267 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1268 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1270 ha->host_no));
1271 qla_printk(KERN_WARNING, ha,
1272 "Error entry - invalid handle\n");
1273
1274 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +01001275 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 }
1277}
1278
1279/**
1280 * qla2x00_ms_entry() - Process a Management Server entry.
1281 * @ha: SCSI driver HA context
1282 * @index: Response queue out pointer
1283 */
1284static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001285qla2x00_ms_entry(scsi_qla_host_t *ha, ms_iocb_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286{
1287 srb_t *sp;
1288
1289 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1290 __func__, ha->host_no, pkt, pkt->handle1));
1291
1292 /* Validate handle. */
1293 if (pkt->handle1 < MAX_OUTSTANDING_COMMANDS)
1294 sp = ha->outstanding_cmds[pkt->handle1];
1295 else
1296 sp = NULL;
1297
1298 if (sp == NULL) {
1299 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1300 ha->host_no));
1301 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle\n");
1302
1303 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1304 return;
1305 }
1306
1307 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->status);
1308 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1309
1310 /* Free outstanding command slot. */
1311 ha->outstanding_cmds[pkt->handle1] = NULL;
1312
f4f051e2005-04-17 15:02:26 -05001313 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314}
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001315
1316
1317/**
1318 * qla24xx_mbx_completion() - Process mailbox command completions.
1319 * @ha: SCSI driver HA context
1320 * @mb0: Mailbox0 register
1321 */
1322static void
1323qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
1324{
1325 uint16_t cnt;
1326 uint16_t __iomem *wptr;
1327 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1328
1329 /* Load return mailbox registers. */
1330 ha->flags.mbox_int = 1;
1331 ha->mailbox_out[0] = mb0;
1332 wptr = (uint16_t __iomem *)&reg->mailbox1;
1333
1334 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1335 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1336 wptr++;
1337 }
1338
1339 if (ha->mcp) {
1340 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1341 __func__, ha->host_no, ha->mcp->mb[0]));
1342 } else {
1343 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1344 __func__, ha->host_no));
1345 }
1346}
1347
1348/**
1349 * qla24xx_process_response_queue() - Process response queue entries.
1350 * @ha: SCSI driver HA context
1351 */
1352void
1353qla24xx_process_response_queue(struct scsi_qla_host *ha)
1354{
1355 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1356 struct sts_entry_24xx *pkt;
1357
1358 if (!ha->flags.online)
1359 return;
1360
1361 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
1362 pkt = (struct sts_entry_24xx *)ha->response_ring_ptr;
1363
1364 ha->rsp_ring_index++;
1365 if (ha->rsp_ring_index == ha->response_q_length) {
1366 ha->rsp_ring_index = 0;
1367 ha->response_ring_ptr = ha->response_ring;
1368 } else {
1369 ha->response_ring_ptr++;
1370 }
1371
1372 if (pkt->entry_status != 0) {
1373 DEBUG3(printk(KERN_INFO
1374 "scsi(%ld): Process error entry.\n", ha->host_no));
1375
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001376 qla2x00_error_entry(ha, (sts_entry_t *) pkt);
1377 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1378 wmb();
1379 continue;
1380 }
1381
1382 switch (pkt->entry_type) {
1383 case STATUS_TYPE:
1384 qla2x00_status_entry(ha, pkt);
1385 break;
1386 case STATUS_CONT_TYPE:
1387 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
1388 break;
1389 case MS_IOCB_TYPE:
1390 qla24xx_ms_entry(ha, (struct ct_entry_24xx *)pkt);
1391 break;
1392 default:
1393 /* Type Not Supported. */
1394 DEBUG4(printk(KERN_WARNING
1395 "scsi(%ld): Received unknown response pkt type %x "
1396 "entry status=%x.\n",
1397 ha->host_no, pkt->entry_type, pkt->entry_status));
1398 break;
1399 }
1400 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1401 wmb();
1402 }
1403
1404 /* Adjust ring index */
1405 WRT_REG_DWORD(&reg->rsp_q_out, ha->rsp_ring_index);
1406}
1407
1408/**
1409 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1410 * @irq:
1411 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001412 *
1413 * Called by system whenever the host adapter generates an interrupt.
1414 *
1415 * Returns handled flag.
1416 */
1417irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001418qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001419{
1420 scsi_qla_host_t *ha;
1421 struct device_reg_24xx __iomem *reg;
1422 int status;
1423 unsigned long flags;
1424 unsigned long iter;
1425 uint32_t stat;
1426 uint32_t hccr;
1427 uint16_t mb[4];
1428
1429 ha = (scsi_qla_host_t *) dev_id;
1430 if (!ha) {
1431 printk(KERN_INFO
1432 "%s(): NULL host pointer\n", __func__);
1433 return IRQ_NONE;
1434 }
1435
1436 reg = &ha->iobase->isp24;
1437 status = 0;
1438
1439 spin_lock_irqsave(&ha->hardware_lock, flags);
1440 for (iter = 50; iter--; ) {
1441 stat = RD_REG_DWORD(&reg->host_status);
1442 if (stat & HSRX_RISC_PAUSED) {
1443 hccr = RD_REG_DWORD(&reg->hccr);
1444
1445 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1446 "Dumping firmware!\n", hccr);
Andrew Vasquez96ca5ca2006-12-13 19:20:32 -08001447 ha->isp_ops.fw_dump(ha, 1);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001448 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1449 break;
1450 } else if ((stat & HSRX_RISC_INT) == 0)
1451 break;
1452
1453 switch (stat & 0xff) {
1454 case 0x1:
1455 case 0x2:
1456 case 0x10:
1457 case 0x11:
1458 qla24xx_mbx_completion(ha, MSW(stat));
1459 status |= MBX_INTERRUPT;
1460
1461 break;
1462 case 0x12:
1463 mb[0] = MSW(stat);
1464 mb[1] = RD_REG_WORD(&reg->mailbox1);
1465 mb[2] = RD_REG_WORD(&reg->mailbox2);
1466 mb[3] = RD_REG_WORD(&reg->mailbox3);
1467 qla2x00_async_event(ha, mb);
1468 break;
1469 case 0x13:
1470 qla24xx_process_response_queue(ha);
1471 break;
1472 default:
1473 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1474 "(%d).\n",
1475 ha->host_no, stat & 0xff));
1476 break;
1477 }
1478 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1479 RD_REG_DWORD_RELAXED(&reg->hccr);
1480 }
1481 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1482
1483 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1484 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1485 spin_lock_irqsave(&ha->mbx_reg_lock, flags);
1486
1487 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1488 up(&ha->mbx_intr_sem);
1489
1490 spin_unlock_irqrestore(&ha->mbx_reg_lock, flags);
1491 }
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