blob: d3b6df4d55c890990f75d0239a62fd65b22213a9 [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
653 spin_unlock_irq(&ha->hardware_lock);
654 starget_for_each_device(sdev->sdev_target, fcport,
655 qla2x00_adjust_sdev_qdepth_up);
656 spin_lock_irq(&ha->hardware_lock);
657}
658
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659/**
660 * qla2x00_process_completed_request() - Process a Fast Post response.
661 * @ha: SCSI driver HA context
662 * @index: SRB index
663 */
664static void
665qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
666{
667 srb_t *sp;
668
669 /* Validate handle. */
670 if (index >= MAX_OUTSTANDING_COMMANDS) {
671 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
672 ha->host_no, index));
673 qla_printk(KERN_WARNING, ha,
674 "Invalid SCSI completion handle %d.\n", index);
675
676 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
677 return;
678 }
679
680 sp = ha->outstanding_cmds[index];
681 if (sp) {
682 /* Free outstanding command slot. */
683 ha->outstanding_cmds[index] = NULL;
684
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 CMD_COMPL_STATUS(sp->cmd) = 0L;
686 CMD_SCSI_STATUS(sp->cmd) = 0L;
687
688 /* Save ISP completion status */
689 sp->cmd->result = DID_OK << 16;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700690
691 qla2x00_ramp_up_queue_depth(ha, sp);
f4f051e2005-04-17 15:02:26 -0500692 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 } else {
694 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
695 ha->host_no));
696 qla_printk(KERN_WARNING, ha,
697 "Invalid ISP SCSI completion handle\n");
698
699 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
700 }
701}
702
703/**
704 * qla2x00_process_response_queue() - Process response queue entries.
705 * @ha: SCSI driver HA context
706 */
707void
708qla2x00_process_response_queue(struct scsi_qla_host *ha)
709{
Andrew Vasquez3d716442005-07-06 10:30:26 -0700710 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 sts_entry_t *pkt;
712 uint16_t handle_cnt;
713 uint16_t cnt;
714
715 if (!ha->flags.online)
716 return;
717
718 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
719 pkt = (sts_entry_t *)ha->response_ring_ptr;
720
721 ha->rsp_ring_index++;
722 if (ha->rsp_ring_index == ha->response_q_length) {
723 ha->rsp_ring_index = 0;
724 ha->response_ring_ptr = ha->response_ring;
725 } else {
726 ha->response_ring_ptr++;
727 }
728
729 if (pkt->entry_status != 0) {
730 DEBUG3(printk(KERN_INFO
731 "scsi(%ld): Process error entry.\n", ha->host_no));
732
733 qla2x00_error_entry(ha, pkt);
734 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
735 wmb();
736 continue;
737 }
738
739 switch (pkt->entry_type) {
740 case STATUS_TYPE:
741 qla2x00_status_entry(ha, pkt);
742 break;
743 case STATUS_TYPE_21:
744 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
745 for (cnt = 0; cnt < handle_cnt; cnt++) {
746 qla2x00_process_completed_request(ha,
747 ((sts21_entry_t *)pkt)->handle[cnt]);
748 }
749 break;
750 case STATUS_TYPE_22:
751 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
752 for (cnt = 0; cnt < handle_cnt; cnt++) {
753 qla2x00_process_completed_request(ha,
754 ((sts22_entry_t *)pkt)->handle[cnt]);
755 }
756 break;
757 case STATUS_CONT_TYPE:
758 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
759 break;
760 case MS_IOCB_TYPE:
761 qla2x00_ms_entry(ha, (ms_iocb_entry_t *)pkt);
762 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 default:
764 /* Type Not Supported. */
765 DEBUG4(printk(KERN_WARNING
766 "scsi(%ld): Received unknown response pkt type %x "
767 "entry status=%x.\n",
768 ha->host_no, pkt->entry_type, pkt->entry_status));
769 break;
770 }
771 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
772 wmb();
773 }
774
775 /* Adjust ring index */
776 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index);
777}
778
779/**
780 * qla2x00_status_entry() - Process a Status IOCB entry.
781 * @ha: SCSI driver HA context
782 * @pkt: Entry pointer
783 */
784static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700785qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 fc_port_t *fcport;
789 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700790 sts_entry_t *sts;
791 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 uint16_t comp_status;
793 uint16_t scsi_status;
794 uint8_t lscsi_status;
795 int32_t resid;
Ravi Ananded17c71b52006-05-17 15:08:55 -0700796 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700797 uint8_t *rsp_info, *sense_data;
798
799 sts = (sts_entry_t *) pkt;
800 sts24 = (struct sts_entry_24xx *) pkt;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800801 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700802 comp_status = le16_to_cpu(sts24->comp_status);
803 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
804 } else {
805 comp_status = le16_to_cpu(sts->comp_status);
806 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
807 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
809 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700810 if (comp_status == CS_COMPLETE && scsi_status == 0) {
811 qla2x00_process_completed_request(ha, sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813 return;
814 }
815
816 /* Validate handle. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700817 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
818 sp = ha->outstanding_cmds[sts->handle];
819 ha->outstanding_cmds[sts->handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 } else
821 sp = NULL;
822
823 if (sp == NULL) {
824 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
825 ha->host_no));
826 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
827
828 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +0100829 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 return;
831 }
832 cp = sp->cmd;
833 if (cp == NULL) {
834 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -0700835 "pkt->handle=%d sp=%p.\n", ha->host_no, sts->handle, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 qla_printk(KERN_WARNING, ha,
837 "Command is NULL: already returned to OS (sp=%p)\n", sp);
838
839 return;
840 }
841
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700842 lscsi_status = scsi_status & STATUS_MASK;
843 CMD_ENTRY_STATUS(cp) = sts->entry_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 CMD_COMPL_STATUS(cp) = comp_status;
845 CMD_SCSI_STATUS(cp) = scsi_status;
846
bdf79622005-04-17 15:06:53 -0500847 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
Ravi Ananded17c71b52006-05-17 15:08:55 -0700849 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800850 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700851 sense_len = le32_to_cpu(sts24->sense_len);
852 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
853 resid_len = le32_to_cpu(sts24->rsp_residual_count);
Ravi Ananded17c71b52006-05-17 15:08:55 -0700854 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700855 rsp_info = sts24->data;
856 sense_data = sts24->data;
857 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
858 } else {
859 sense_len = le16_to_cpu(sts->req_sense_length);
860 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
861 resid_len = le32_to_cpu(sts->residual_length);
862 rsp_info = sts->rsp_info;
863 sense_data = sts->req_sense_data;
864 }
865
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 /* Check for any FCP transport errors. */
867 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700868 /* Sense data lies beyond any FCP RESPONSE data. */
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800869 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700870 sense_data += rsp_info_len;
871 if (rsp_info_len > 3 && rsp_info[3]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
873 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700874 "retrying command\n", ha->host_no,
875 cp->device->channel, cp->device->id,
876 cp->device->lun, rsp_info_len, rsp_info[0],
877 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
878 rsp_info[5], rsp_info[6], rsp_info[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
880 cp->result = DID_BUS_BUSY << 16;
f4f051e2005-04-17 15:02:26 -0500881 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 return;
883 }
884 }
885
886 /*
887 * Based on Host and scsi status generate status code for Linux
888 */
889 switch (comp_status) {
890 case CS_COMPLETE:
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700891 case CS_QUEUE_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 if (scsi_status == 0) {
893 cp->result = DID_OK << 16;
894 break;
895 }
896 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700897 resid = resid_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 cp->resid = resid;
899 CMD_RESID_LEN(cp) = resid;
Andrew Vasquez0da69df2005-12-06 10:58:06 -0800900
901 if (!lscsi_status &&
902 ((unsigned)(cp->request_bufflen - resid) <
903 cp->underflow)) {
904 qla_printk(KERN_INFO, ha,
905 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
906 "detected (%x of %x bytes)...returning "
907 "error status.\n", ha->host_no,
908 cp->device->channel, cp->device->id,
909 cp->device->lun, resid,
910 cp->request_bufflen);
911
912 cp->result = DID_ERROR << 16;
913 break;
914 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 cp->result = DID_OK << 16 | lscsi_status;
917
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700918 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
919 DEBUG2(printk(KERN_INFO
920 "scsi(%ld): QUEUE FULL status detected "
921 "0x%x-0x%x.\n", ha->host_no, comp_status,
922 scsi_status));
923
924 /* Adjust queue depth for all luns on the port. */
925 fcport->last_queue_full = jiffies;
926 spin_unlock_irq(&ha->hardware_lock);
927 starget_for_each_device(cp->device->sdev_target,
928 fcport, qla2x00_adjust_sdev_qdepth_down);
929 spin_lock_irq(&ha->hardware_lock);
930 break;
931 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 if (lscsi_status != SS_CHECK_CONDITION)
933 break;
934
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700935 /* Copy Sense Data into sense buffer. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
937
938 if (!(scsi_status & SS_SENSE_LEN_VALID))
939 break;
940
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700941 if (sense_len >= sizeof(cp->sense_buffer))
942 sense_len = sizeof(cp->sense_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700944 CMD_ACTUAL_SNSLEN(cp) = sense_len;
945 sp->request_sense_length = sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 sp->request_sense_ptr = cp->sense_buffer;
947
948 if (sp->request_sense_length > 32)
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700949 sense_len = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700951 memcpy(cp->sense_buffer, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700953 sp->request_sense_ptr += sense_len;
954 sp->request_sense_length -= sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 if (sp->request_sense_length != 0)
956 ha->status_srb = sp;
957
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 DEBUG5(printk("%s(): Check condition Sense data, "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700959 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n", __func__,
960 ha->host_no, cp->device->channel, cp->device->id,
961 cp->device->lun, cp, cp->serial_number));
962 if (sense_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
964 CMD_ACTUAL_SNSLEN(cp)));
965 break;
966
967 case CS_DATA_UNDERRUN:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700968 resid = resid_len;
Ravi Ananded17c71b52006-05-17 15:08:55 -0700969 /* Use F/W calculated residual length. */
970 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
971 resid = fw_resid_len;
972
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 if (scsi_status & SS_RESIDUAL_UNDER) {
974 cp->resid = resid;
975 CMD_RESID_LEN(cp) = resid;
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -0800976 } else {
977 DEBUG2(printk(KERN_INFO
978 "scsi(%ld:%d:%d) UNDERRUN status detected "
Ravi Ananded17c71b52006-05-17 15:08:55 -0700979 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
980 "os_underflow=0x%x\n", ha->host_no,
981 cp->device->id, cp->device->lun, comp_status,
982 scsi_status, resid_len, resid, cp->cmnd[0],
983 cp->underflow));
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -0800984
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 }
986
987 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700988 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 * Status.
990 */
991 if (lscsi_status != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 cp->result = DID_OK << 16 | lscsi_status;
993
994 if (lscsi_status != SS_CHECK_CONDITION)
995 break;
996
997 /* Copy Sense Data into sense buffer */
998 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
999
1000 if (!(scsi_status & SS_SENSE_LEN_VALID))
1001 break;
1002
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001003 if (sense_len >= sizeof(cp->sense_buffer))
1004 sense_len = sizeof(cp->sense_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001006 CMD_ACTUAL_SNSLEN(cp) = sense_len;
1007 sp->request_sense_length = sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 sp->request_sense_ptr = cp->sense_buffer;
1009
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001010 if (sp->request_sense_length > 32)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001011 sense_len = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001013 memcpy(cp->sense_buffer, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001015 sp->request_sense_ptr += sense_len;
1016 sp->request_sense_length -= sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 if (sp->request_sense_length != 0)
1018 ha->status_srb = sp;
1019
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 DEBUG5(printk("%s(): Check condition Sense data, "
1021 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001022 __func__, ha->host_no, cp->device->channel,
1023 cp->device->id, cp->device->lun, cp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 cp->serial_number));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001025
1026 if (sense_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
1028 CMD_ACTUAL_SNSLEN(cp)));
1029 } else {
1030 /*
1031 * If RISC reports underrun and target does not report
1032 * it then we must have a lost frame, so tell upper
1033 * layer to retry it by reporting a bus busy.
1034 */
1035 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1036 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1037 "frame(s) detected (%x of %x bytes)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001038 "retrying command.\n", ha->host_no,
1039 cp->device->channel, cp->device->id,
1040 cp->device->lun, resid,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 cp->request_bufflen));
1042
1043 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 break;
1045 }
1046
1047 /* Handle mid-layer underflow */
1048 if ((unsigned)(cp->request_bufflen - resid) <
1049 cp->underflow) {
1050 qla_printk(KERN_INFO, ha,
1051 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1052 "detected (%x of %x bytes)...returning "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001053 "error status.\n", ha->host_no,
1054 cp->device->channel, cp->device->id,
1055 cp->device->lun, resid,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 cp->request_bufflen);
1057
1058 cp->result = DID_ERROR << 16;
1059 break;
1060 }
1061
1062 /* Everybody online, looking good... */
1063 cp->result = DID_OK << 16;
1064 }
1065 break;
1066
1067 case CS_DATA_OVERRUN:
1068 DEBUG2(printk(KERN_INFO
1069 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001070 ha->host_no, cp->device->id, cp->device->lun, comp_status,
1071 scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 DEBUG2(printk(KERN_INFO
1073 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1074 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1075 cp->cmnd[4], cp->cmnd[5]));
1076 DEBUG2(printk(KERN_INFO
1077 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1078 "status!\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001079 cp->serial_number, cp->request_bufflen, resid_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
1081 cp->result = DID_ERROR << 16;
1082 break;
1083
1084 case CS_PORT_LOGGED_OUT:
1085 case CS_PORT_CONFIG_CHG:
1086 case CS_PORT_BUSY:
1087 case CS_INCOMPLETE:
1088 case CS_PORT_UNAVAILABLE:
1089 /*
1090 * If the port is in Target Down state, return all IOs for this
1091 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1092 * retry_queue.
1093 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1095 "pid=%ld, compl status=0x%x, port state=0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001096 ha->host_no, cp->device->id, cp->device->lun,
1097 cp->serial_number, comp_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 atomic_read(&fcport->state)));
1099
f4f051e2005-04-17 15:02:26 -05001100 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 if (atomic_read(&fcport->state) == FCS_ONLINE) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001102 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 break;
1105
1106 case CS_RESET:
1107 DEBUG2(printk(KERN_INFO
1108 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1109 ha->host_no, comp_status, scsi_status));
1110
f4f051e2005-04-17 15:02:26 -05001111 cp->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 break;
1113
1114 case CS_ABORTED:
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001115 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 * hv2.19.12 - DID_ABORT does not retry the request if we
1117 * aborted this request then abort otherwise it must be a
1118 * reset.
1119 */
1120 DEBUG2(printk(KERN_INFO
1121 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1122 ha->host_no, comp_status, scsi_status));
1123
1124 cp->result = DID_RESET << 16;
1125 break;
1126
1127 case CS_TIMEOUT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 cp->result = DID_BUS_BUSY << 16;
1129
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001130 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001131 DEBUG2(printk(KERN_INFO
1132 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1133 "0x%x-0x%x\n", ha->host_no, cp->device->channel,
1134 cp->device->id, cp->device->lun, comp_status,
1135 scsi_status));
1136 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001138 DEBUG2(printk(KERN_INFO
1139 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1140 "sflags=%x.\n", ha->host_no, cp->device->channel,
1141 cp->device->id, cp->device->lun, comp_status, scsi_status,
1142 le16_to_cpu(sts->status_flags)));
1143
1144 /* Check to see if logout occurred. */
1145 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001146 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 break;
1148
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 default:
1150 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001151 "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 qla_printk(KERN_INFO, ha,
1153 "Unknown status detected 0x%x-0x%x.\n",
1154 comp_status, scsi_status);
1155
1156 cp->result = DID_ERROR << 16;
1157 break;
1158 }
1159
1160 /* Place command on done queue. */
1161 if (ha->status_srb == NULL)
f4f051e2005-04-17 15:02:26 -05001162 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163}
1164
1165/**
1166 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1167 * @ha: SCSI driver HA context
1168 * @pkt: Entry pointer
1169 *
1170 * Extended sense data.
1171 */
1172static void
1173qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1174{
1175 uint8_t sense_sz = 0;
1176 srb_t *sp = ha->status_srb;
1177 struct scsi_cmnd *cp;
1178
1179 if (sp != NULL && sp->request_sense_length != 0) {
1180 cp = sp->cmd;
1181 if (cp == NULL) {
1182 DEBUG2(printk("%s(): Cmd already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001183 "sp=%p.\n", __func__, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 qla_printk(KERN_INFO, ha,
1185 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001186 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
1188 ha->status_srb = NULL;
1189 return;
1190 }
1191
1192 if (sp->request_sense_length > sizeof(pkt->data)) {
1193 sense_sz = sizeof(pkt->data);
1194 } else {
1195 sense_sz = sp->request_sense_length;
1196 }
1197
1198 /* Move sense data. */
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001199 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001200 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1202 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1203
1204 sp->request_sense_ptr += sense_sz;
1205 sp->request_sense_length -= sense_sz;
1206
1207 /* Place command on done queue. */
1208 if (sp->request_sense_length == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 ha->status_srb = NULL;
f4f051e2005-04-17 15:02:26 -05001210 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 }
1212 }
1213}
1214
1215/**
1216 * qla2x00_error_entry() - Process an error entry.
1217 * @ha: SCSI driver HA context
1218 * @pkt: Entry pointer
1219 */
1220static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001221qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222{
1223 srb_t *sp;
1224
1225#if defined(QL_DEBUG_LEVEL_2)
1226 if (pkt->entry_status & RF_INV_E_ORDER)
1227 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1228 else if (pkt->entry_status & RF_INV_E_COUNT)
1229 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1230 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001231 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 "%s: Invalid Entry Parameter\n", __func__);
1233 else if (pkt->entry_status & RF_INV_E_TYPE)
1234 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1235 else if (pkt->entry_status & RF_BUSY)
1236 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1237 else
1238 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1239#endif
1240
1241 /* Validate handle. */
1242 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1243 sp = ha->outstanding_cmds[pkt->handle];
1244 else
1245 sp = NULL;
1246
1247 if (sp) {
1248 /* Free outstanding command slot. */
1249 ha->outstanding_cmds[pkt->handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001250
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 /* Bad payload or header */
1252 if (pkt->entry_status &
1253 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1254 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1255 sp->cmd->result = DID_ERROR << 16;
1256 } else if (pkt->entry_status & RF_BUSY) {
1257 sp->cmd->result = DID_BUS_BUSY << 16;
1258 } else {
1259 sp->cmd->result = DID_ERROR << 16;
1260 }
f4f051e2005-04-17 15:02:26 -05001261 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001263 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1264 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1266 ha->host_no));
1267 qla_printk(KERN_WARNING, ha,
1268 "Error entry - invalid handle\n");
1269
1270 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +01001271 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 }
1273}
1274
1275/**
1276 * qla2x00_ms_entry() - Process a Management Server entry.
1277 * @ha: SCSI driver HA context
1278 * @index: Response queue out pointer
1279 */
1280static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001281qla2x00_ms_entry(scsi_qla_host_t *ha, ms_iocb_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282{
1283 srb_t *sp;
1284
1285 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1286 __func__, ha->host_no, pkt, pkt->handle1));
1287
1288 /* Validate handle. */
1289 if (pkt->handle1 < MAX_OUTSTANDING_COMMANDS)
1290 sp = ha->outstanding_cmds[pkt->handle1];
1291 else
1292 sp = NULL;
1293
1294 if (sp == NULL) {
1295 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1296 ha->host_no));
1297 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle\n");
1298
1299 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1300 return;
1301 }
1302
1303 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->status);
1304 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1305
1306 /* Free outstanding command slot. */
1307 ha->outstanding_cmds[pkt->handle1] = NULL;
1308
f4f051e2005-04-17 15:02:26 -05001309 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310}
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001311
1312
1313/**
1314 * qla24xx_mbx_completion() - Process mailbox command completions.
1315 * @ha: SCSI driver HA context
1316 * @mb0: Mailbox0 register
1317 */
1318static void
1319qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
1320{
1321 uint16_t cnt;
1322 uint16_t __iomem *wptr;
1323 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1324
1325 /* Load return mailbox registers. */
1326 ha->flags.mbox_int = 1;
1327 ha->mailbox_out[0] = mb0;
1328 wptr = (uint16_t __iomem *)&reg->mailbox1;
1329
1330 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1331 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1332 wptr++;
1333 }
1334
1335 if (ha->mcp) {
1336 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1337 __func__, ha->host_no, ha->mcp->mb[0]));
1338 } else {
1339 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1340 __func__, ha->host_no));
1341 }
1342}
1343
1344/**
1345 * qla24xx_process_response_queue() - Process response queue entries.
1346 * @ha: SCSI driver HA context
1347 */
1348void
1349qla24xx_process_response_queue(struct scsi_qla_host *ha)
1350{
1351 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1352 struct sts_entry_24xx *pkt;
1353
1354 if (!ha->flags.online)
1355 return;
1356
1357 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
1358 pkt = (struct sts_entry_24xx *)ha->response_ring_ptr;
1359
1360 ha->rsp_ring_index++;
1361 if (ha->rsp_ring_index == ha->response_q_length) {
1362 ha->rsp_ring_index = 0;
1363 ha->response_ring_ptr = ha->response_ring;
1364 } else {
1365 ha->response_ring_ptr++;
1366 }
1367
1368 if (pkt->entry_status != 0) {
1369 DEBUG3(printk(KERN_INFO
1370 "scsi(%ld): Process error entry.\n", ha->host_no));
1371
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001372 qla2x00_error_entry(ha, (sts_entry_t *) pkt);
1373 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1374 wmb();
1375 continue;
1376 }
1377
1378 switch (pkt->entry_type) {
1379 case STATUS_TYPE:
1380 qla2x00_status_entry(ha, pkt);
1381 break;
1382 case STATUS_CONT_TYPE:
1383 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
1384 break;
1385 case MS_IOCB_TYPE:
1386 qla24xx_ms_entry(ha, (struct ct_entry_24xx *)pkt);
1387 break;
1388 default:
1389 /* Type Not Supported. */
1390 DEBUG4(printk(KERN_WARNING
1391 "scsi(%ld): Received unknown response pkt type %x "
1392 "entry status=%x.\n",
1393 ha->host_no, pkt->entry_type, pkt->entry_status));
1394 break;
1395 }
1396 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1397 wmb();
1398 }
1399
1400 /* Adjust ring index */
1401 WRT_REG_DWORD(&reg->rsp_q_out, ha->rsp_ring_index);
1402}
1403
1404/**
1405 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1406 * @irq:
1407 * @dev_id: SCSI driver HA context
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001408 *
1409 * Called by system whenever the host adapter generates an interrupt.
1410 *
1411 * Returns handled flag.
1412 */
1413irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001414qla24xx_intr_handler(int irq, void *dev_id)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001415{
1416 scsi_qla_host_t *ha;
1417 struct device_reg_24xx __iomem *reg;
1418 int status;
1419 unsigned long flags;
1420 unsigned long iter;
1421 uint32_t stat;
1422 uint32_t hccr;
1423 uint16_t mb[4];
1424
1425 ha = (scsi_qla_host_t *) dev_id;
1426 if (!ha) {
1427 printk(KERN_INFO
1428 "%s(): NULL host pointer\n", __func__);
1429 return IRQ_NONE;
1430 }
1431
1432 reg = &ha->iobase->isp24;
1433 status = 0;
1434
1435 spin_lock_irqsave(&ha->hardware_lock, flags);
1436 for (iter = 50; iter--; ) {
1437 stat = RD_REG_DWORD(&reg->host_status);
1438 if (stat & HSRX_RISC_PAUSED) {
1439 hccr = RD_REG_DWORD(&reg->hccr);
1440
1441 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1442 "Dumping firmware!\n", hccr);
1443 qla24xx_fw_dump(ha, 1);
1444
1445 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1446 break;
1447 } else if ((stat & HSRX_RISC_INT) == 0)
1448 break;
1449
1450 switch (stat & 0xff) {
1451 case 0x1:
1452 case 0x2:
1453 case 0x10:
1454 case 0x11:
1455 qla24xx_mbx_completion(ha, MSW(stat));
1456 status |= MBX_INTERRUPT;
1457
1458 break;
1459 case 0x12:
1460 mb[0] = MSW(stat);
1461 mb[1] = RD_REG_WORD(&reg->mailbox1);
1462 mb[2] = RD_REG_WORD(&reg->mailbox2);
1463 mb[3] = RD_REG_WORD(&reg->mailbox3);
1464 qla2x00_async_event(ha, mb);
1465 break;
1466 case 0x13:
1467 qla24xx_process_response_queue(ha);
1468 break;
1469 default:
1470 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1471 "(%d).\n",
1472 ha->host_no, stat & 0xff));
1473 break;
1474 }
1475 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1476 RD_REG_DWORD_RELAXED(&reg->hccr);
1477 }
1478 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1479
1480 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1481 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1482 spin_lock_irqsave(&ha->mbx_reg_lock, flags);
1483
1484 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1485 up(&ha->mbx_intr_sem);
1486
1487 spin_unlock_irqrestore(&ha->mbx_reg_lock, flags);
1488 }
1489
1490 return IRQ_HANDLED;
1491}
1492
1493/**
1494 * qla24xx_ms_entry() - Process a Management Server entry.
1495 * @ha: SCSI driver HA context
1496 * @index: Response queue out pointer
1497 */
1498static void
1499qla24xx_ms_entry(scsi_qla_host_t *ha, struct ct_entry_24xx *pkt)
1500{
1501 srb_t *sp;
1502
1503 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1504 __func__, ha->host_no, pkt, pkt->handle));
1505
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001506 DEBUG9(printk("%s: ct pkt dump:\n", __func__));
1507 DEBUG9(qla2x00_dump_buffer((void *)pkt, sizeof(struct ct_entry_24xx)));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001508
1509 /* Validate handle. */
1510 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1511 sp = ha->outstanding_cmds[pkt->handle];
1512 else
1513 sp = NULL;
1514
1515 if (sp == NULL) {
1516 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1517 ha->host_no));
1518 DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n",
1519 ha->host_no));
1520 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle %d\n",
1521 pkt->handle);
1522
1523 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1524 return;
1525 }
1526
1527 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->comp_status);
1528 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1529
1530 /* Free outstanding command slot. */
1531 ha->outstanding_cmds[pkt->handle] = NULL;
1532
1533 qla2x00_sp_compl(ha, sp);
1534}
1535