blob: 39b5082eb3bc22d62e0dafbbeeb57b5d8501c738 [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
9static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070010static void qla2x00_async_event(scsi_qla_host_t *, uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070011static void qla2x00_process_completed_request(struct scsi_qla_host *, uint32_t);
Andrew Vasquez9a853f72005-07-06 10:31:27 -070012static void qla2x00_status_entry(scsi_qla_host_t *, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070013static void qla2x00_status_cont_entry(scsi_qla_host_t *, sts_cont_entry_t *);
14static void qla2x00_error_entry(scsi_qla_host_t *, sts_entry_t *);
15static void qla2x00_ms_entry(scsi_qla_host_t *, ms_iocb_entry_t *);
16
Andrew Vasquez9a853f72005-07-06 10:31:27 -070017static void qla24xx_ms_entry(scsi_qla_host_t *, struct ct_entry_24xx *);
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019/**
20 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
21 * @irq:
22 * @dev_id: SCSI driver HA context
23 * @regs:
24 *
25 * Called by system whenever the host adapter generates an interrupt.
26 *
27 * Returns handled flag.
28 */
29irqreturn_t
30qla2100_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
31{
32 scsi_qla_host_t *ha;
Andrew Vasquez3d716442005-07-06 10:30:26 -070033 struct device_reg_2xxx __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 int status;
35 unsigned long flags;
36 unsigned long iter;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070037 uint16_t mb[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39 ha = (scsi_qla_host_t *) dev_id;
40 if (!ha) {
41 printk(KERN_INFO
42 "%s(): NULL host pointer\n", __func__);
43 return (IRQ_NONE);
44 }
45
Andrew Vasquez3d716442005-07-06 10:30:26 -070046 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 status = 0;
48
49 spin_lock_irqsave(&ha->hardware_lock, flags);
50 for (iter = 50; iter--; ) {
51 if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
52 break;
53
54 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
55 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
56 RD_REG_WORD(&reg->hccr);
57
58 /* Get mailbox data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -070059 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
60 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
61 qla2x00_mbx_completion(ha, mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 status |= MBX_INTERRUPT;
Andrew Vasquez9a853f72005-07-06 10:31:27 -070063 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
64 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
65 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
66 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
67 qla2x00_async_event(ha, mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 } else {
69 /*EMPTY*/
70 DEBUG2(printk("scsi(%ld): Unrecognized "
Andrew Vasquez9a853f72005-07-06 10:31:27 -070071 "interrupt type (%d).\n",
72 ha->host_no, mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 }
74 /* Release mailbox registers. */
75 WRT_REG_WORD(&reg->semaphore, 0);
76 RD_REG_WORD(&reg->semaphore);
77 } else {
78 qla2x00_process_response_queue(ha);
79
80 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
81 RD_REG_WORD(&reg->hccr);
82 }
83 }
84 spin_unlock_irqrestore(&ha->hardware_lock, flags);
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
87 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
88 spin_lock_irqsave(&ha->mbx_reg_lock, flags);
89
90 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
91 up(&ha->mbx_intr_sem);
92
93 spin_unlock_irqrestore(&ha->mbx_reg_lock, flags);
94 }
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 return (IRQ_HANDLED);
97}
98
99/**
100 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
101 * @irq:
102 * @dev_id: SCSI driver HA context
103 * @regs:
104 *
105 * Called by system whenever the host adapter generates an interrupt.
106 *
107 * Returns handled flag.
108 */
109irqreturn_t
110qla2300_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
111{
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;
398
399 /* Update AEN queue. */
400 qla2x00_enqueue_aen(ha, MBA_LIP_OCCURRED, NULL);
401
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 break;
403
404 case MBA_LOOP_UP: /* Loop Up Event */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
406 link_speed = link_speeds[0];
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800407 ha->link_data_rate = LDR_1GB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 } else {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700409 link_speed = link_speeds[LS_UNKNOWN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 if (mb[1] < 5)
411 link_speed = link_speeds[mb[1]];
412 ha->link_data_rate = mb[1];
413 }
414
415 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
416 ha->host_no, link_speed));
417 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
418 link_speed);
419
420 ha->flags.management_server_logged_in = 0;
421
422 /* Update AEN queue. */
423 qla2x00_enqueue_aen(ha, MBA_LOOP_UP, NULL);
424 break;
425
426 case MBA_LOOP_DOWN: /* Loop Down Event */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700427 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN (%x).\n",
428 ha->host_no, mb[1]));
429 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x).\n", mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
431 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
432 atomic_set(&ha->loop_state, LOOP_DOWN);
433 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
434 ha->device_flags |= DFLG_NO_CABLE;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800435 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 }
437
438 ha->flags.management_server_logged_in = 0;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800439 ha->link_data_rate = LDR_UNKNOWN;
Andrew Vasquezcca53352005-08-26 19:08:30 -0700440 if (ql2xfdmienable)
441 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
443 /* Update AEN queue. */
444 qla2x00_enqueue_aen(ha, MBA_LOOP_DOWN, NULL);
445 break;
446
447 case MBA_LIP_RESET: /* LIP reset occurred */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
449 ha->host_no, mb[1]));
450 qla_printk(KERN_INFO, ha,
451 "LIP reset occured (%x).\n", mb[1]);
452
453 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
454 atomic_set(&ha->loop_state, LOOP_DOWN);
455 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800456 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 }
458
459 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
460
461 ha->operating_mode = LOOP;
462 ha->flags.management_server_logged_in = 0;
463
464 /* Update AEN queue. */
465 qla2x00_enqueue_aen(ha, MBA_LIP_RESET, NULL);
466
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 break;
468
469 case MBA_POINT_TO_POINT: /* Point-to-Point */
470 if (IS_QLA2100(ha))
471 break;
472
473 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
474 ha->host_no));
475
476 /*
477 * Until there's a transition from loop down to loop up, treat
478 * this as loop down only.
479 */
480 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
481 atomic_set(&ha->loop_state, LOOP_DOWN);
482 if (!atomic_read(&ha->loop_down_timer))
483 atomic_set(&ha->loop_down_timer,
484 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800485 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 }
487
488 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
489 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
490 }
491 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
492 break;
493
494 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
495 if (IS_QLA2100(ha))
496 break;
497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
499 "received.\n",
500 ha->host_no));
501 qla_printk(KERN_INFO, ha,
502 "Configuration change detected: value=%x.\n", mb[1]);
503
504 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700505 atomic_set(&ha->loop_state, LOOP_DOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 if (!atomic_read(&ha->loop_down_timer))
507 atomic_set(&ha->loop_down_timer,
508 LOOP_DOWN_TIME);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800509 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 }
511
512 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
513 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
514 break;
515
516 case MBA_PORT_UPDATE: /* Port database update */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 /*
518 * If a single remote port just logged into (or logged out of)
519 * us, create a new entry in our rscn fcports list and handle
520 * the event like an RSCN.
521 */
andrew.vasquez@qlogic.com79f89a42006-01-13 17:05:58 -0800522 if (ql2xprocessrscn &&
523 !IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA6312(ha) &&
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800524 !IS_QLA6322(ha) && !IS_QLA24XX(ha) && !IS_QLA54XX(ha) &&
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700525 ha->flags.init_done && mb[1] != 0xffff &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 ((ha->operating_mode == P2P && mb[1] != 0) ||
527 (ha->operating_mode != P2P && mb[1] !=
528 SNS_FIRST_LOOP_ID)) && (mb[2] == 6 || mb[2] == 7)) {
529 int rval;
530 fc_port_t *rscn_fcport;
531
532 /* Create new fcport for login. */
533 rscn_fcport = qla2x00_alloc_rscn_fcport(ha, GFP_ATOMIC);
534 if (rscn_fcport) {
535 DEBUG14(printk("scsi(%ld): Port Update -- "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700536 "creating RSCN fcport %p for %x/%x/%x.\n",
537 ha->host_no, rscn_fcport, mb[1], mb[2],
538 mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
540 rscn_fcport->loop_id = mb[1];
541 rscn_fcport->d_id.b24 = INVALID_PORT_ID;
542 atomic_set(&rscn_fcport->state,
543 FCS_DEVICE_LOST);
544 list_add_tail(&rscn_fcport->list,
545 &ha->rscn_fcports);
546
547 rval = qla2x00_handle_port_rscn(ha, 0,
548 rscn_fcport, 1);
549 if (rval == QLA_SUCCESS)
550 break;
551 } else {
552 DEBUG14(printk("scsi(%ld): Port Update -- "
553 "-- unable to allocate RSCN fcport "
554 "login.\n", ha->host_no));
555 }
556 }
557
558 /*
559 * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET
560 * event etc. earlier indicating loop is down) then process
561 * it. Otherwise ignore it and Wait for RSCN to come in.
562 */
563 atomic_set(&ha->loop_down_timer, 0);
564 if (atomic_read(&ha->loop_state) != LOOP_DOWN &&
565 atomic_read(&ha->loop_state) != LOOP_DEAD) {
566 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700567 "ignored %04x/%04x/%04x.\n", ha->host_no, mb[1],
568 mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 break;
570 }
571
572 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
573 ha->host_no));
574 DEBUG(printk(KERN_INFO
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700575 "scsi(%ld): Port database changed %04x %04x %04x.\n",
576 ha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 /*
579 * Mark all devices as missing so we will login again.
580 */
581 atomic_set(&ha->loop_state, LOOP_UP);
582
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800583 qla2x00_mark_all_devices_lost(ha, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
585 ha->flags.rscn_queue_overflow = 1;
586
587 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
588 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
589
590 /* Update AEN queue. */
591 qla2x00_enqueue_aen(ha, MBA_PORT_UPDATE, NULL);
592 break;
593
594 case MBA_RSCN_UPDATE: /* State Change Registration */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
596 ha->host_no));
597 DEBUG(printk(KERN_INFO
598 "scsi(%ld): RSCN database changed -- %04x %04x.\n",
599 ha->host_no, mb[1], mb[2]));
600
601 rscn_entry = (mb[1] << 16) | mb[2];
602 host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) |
603 ha->d_id.b.al_pa;
604 if (rscn_entry == host_pid) {
605 DEBUG(printk(KERN_INFO
606 "scsi(%ld): Ignoring RSCN update to local host "
607 "port ID (%06x)\n",
608 ha->host_no, host_pid));
609 break;
610 }
611
612 rscn_queue_index = ha->rscn_in_ptr + 1;
613 if (rscn_queue_index == MAX_RSCN_COUNT)
614 rscn_queue_index = 0;
615 if (rscn_queue_index != ha->rscn_out_ptr) {
616 ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry;
617 ha->rscn_in_ptr = rscn_queue_index;
618 } else {
619 ha->flags.rscn_queue_overflow = 1;
620 }
621
622 atomic_set(&ha->loop_state, LOOP_UPDATE);
623 atomic_set(&ha->loop_down_timer, 0);
624 ha->flags.management_server_logged_in = 0;
625
626 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
627 set_bit(RSCN_UPDATE, &ha->dpc_flags);
628
629 /* Update AEN queue. */
630 qla2x00_enqueue_aen(ha, MBA_RSCN_UPDATE, &mb[0]);
631 break;
632
633 /* case MBA_RIO_RESPONSE: */
634 case MBA_ZIO_RESPONSE:
635 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
636 ha->host_no));
637 DEBUG(printk(KERN_INFO
638 "scsi(%ld): [R|Z]IO update completion.\n",
639 ha->host_no));
640
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800641 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700642 qla24xx_process_response_queue(ha);
643 else
644 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700646
647 case MBA_DISCARD_RND_FRAME:
648 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
649 "%04x.\n", ha->host_no, mb[1], mb[2], mb[3]));
650 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 }
652}
653
654/**
655 * qla2x00_process_completed_request() - Process a Fast Post response.
656 * @ha: SCSI driver HA context
657 * @index: SRB index
658 */
659static void
660qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
661{
662 srb_t *sp;
663
664 /* Validate handle. */
665 if (index >= MAX_OUTSTANDING_COMMANDS) {
666 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
667 ha->host_no, index));
668 qla_printk(KERN_WARNING, ha,
669 "Invalid SCSI completion handle %d.\n", index);
670
671 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
672 return;
673 }
674
675 sp = ha->outstanding_cmds[index];
676 if (sp) {
677 /* Free outstanding command slot. */
678 ha->outstanding_cmds[index] = NULL;
679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 CMD_COMPL_STATUS(sp->cmd) = 0L;
681 CMD_SCSI_STATUS(sp->cmd) = 0L;
682
683 /* Save ISP completion status */
684 sp->cmd->result = DID_OK << 16;
f4f051e2005-04-17 15:02:26 -0500685 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 } else {
687 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
688 ha->host_no));
689 qla_printk(KERN_WARNING, ha,
690 "Invalid ISP SCSI completion handle\n");
691
692 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
693 }
694}
695
696/**
697 * qla2x00_process_response_queue() - Process response queue entries.
698 * @ha: SCSI driver HA context
699 */
700void
701qla2x00_process_response_queue(struct scsi_qla_host *ha)
702{
Andrew Vasquez3d716442005-07-06 10:30:26 -0700703 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 sts_entry_t *pkt;
705 uint16_t handle_cnt;
706 uint16_t cnt;
707
708 if (!ha->flags.online)
709 return;
710
711 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
712 pkt = (sts_entry_t *)ha->response_ring_ptr;
713
714 ha->rsp_ring_index++;
715 if (ha->rsp_ring_index == ha->response_q_length) {
716 ha->rsp_ring_index = 0;
717 ha->response_ring_ptr = ha->response_ring;
718 } else {
719 ha->response_ring_ptr++;
720 }
721
722 if (pkt->entry_status != 0) {
723 DEBUG3(printk(KERN_INFO
724 "scsi(%ld): Process error entry.\n", ha->host_no));
725
726 qla2x00_error_entry(ha, pkt);
727 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
728 wmb();
729 continue;
730 }
731
732 switch (pkt->entry_type) {
733 case STATUS_TYPE:
734 qla2x00_status_entry(ha, pkt);
735 break;
736 case STATUS_TYPE_21:
737 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
738 for (cnt = 0; cnt < handle_cnt; cnt++) {
739 qla2x00_process_completed_request(ha,
740 ((sts21_entry_t *)pkt)->handle[cnt]);
741 }
742 break;
743 case STATUS_TYPE_22:
744 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
745 for (cnt = 0; cnt < handle_cnt; cnt++) {
746 qla2x00_process_completed_request(ha,
747 ((sts22_entry_t *)pkt)->handle[cnt]);
748 }
749 break;
750 case STATUS_CONT_TYPE:
751 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
752 break;
753 case MS_IOCB_TYPE:
754 qla2x00_ms_entry(ha, (ms_iocb_entry_t *)pkt);
755 break;
756 case MBX_IOCB_TYPE:
757 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
758 !IS_QLA6312(ha) && !IS_QLA6322(ha)) {
759 if (pkt->sys_define == SOURCE_ASYNC_IOCB) {
760 qla2x00_process_iodesc(ha,
761 (struct mbx_entry *)pkt);
762 } else {
763 /* MBX IOCB Type Not Supported. */
764 DEBUG4(printk(KERN_WARNING
765 "scsi(%ld): Received unknown MBX "
766 "IOCB response pkt type=%x "
767 "source=%x entry status=%x.\n",
768 ha->host_no, pkt->entry_type,
769 pkt->sys_define,
770 pkt->entry_status));
771 }
772 break;
773 }
774 /* Fallthrough. */
775 default:
776 /* Type Not Supported. */
777 DEBUG4(printk(KERN_WARNING
778 "scsi(%ld): Received unknown response pkt type %x "
779 "entry status=%x.\n",
780 ha->host_no, pkt->entry_type, pkt->entry_status));
781 break;
782 }
783 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
784 wmb();
785 }
786
787 /* Adjust ring index */
788 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index);
789}
790
791/**
792 * qla2x00_status_entry() - Process a Status IOCB entry.
793 * @ha: SCSI driver HA context
794 * @pkt: Entry pointer
795 */
796static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700797qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 fc_port_t *fcport;
801 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700802 sts_entry_t *sts;
803 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 uint16_t comp_status;
805 uint16_t scsi_status;
806 uint8_t lscsi_status;
807 int32_t resid;
Ravi Ananded17c71b52006-05-17 15:08:55 -0700808 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700809 uint8_t *rsp_info, *sense_data;
810
811 sts = (sts_entry_t *) pkt;
812 sts24 = (struct sts_entry_24xx *) pkt;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800813 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700814 comp_status = le16_to_cpu(sts24->comp_status);
815 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
816 } else {
817 comp_status = le16_to_cpu(sts->comp_status);
818 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
819 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
821 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700822 if (comp_status == CS_COMPLETE && scsi_status == 0) {
823 qla2x00_process_completed_request(ha, sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
825 return;
826 }
827
828 /* Validate handle. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700829 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
830 sp = ha->outstanding_cmds[sts->handle];
831 ha->outstanding_cmds[sts->handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 } else
833 sp = NULL;
834
835 if (sp == NULL) {
836 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
837 ha->host_no));
838 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
839
840 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +0100841 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 return;
843 }
844 cp = sp->cmd;
845 if (cp == NULL) {
846 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -0700847 "pkt->handle=%d sp=%p.\n", ha->host_no, sts->handle, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 qla_printk(KERN_WARNING, ha,
849 "Command is NULL: already returned to OS (sp=%p)\n", sp);
850
851 return;
852 }
853
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700854 lscsi_status = scsi_status & STATUS_MASK;
855 CMD_ENTRY_STATUS(cp) = sts->entry_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 CMD_COMPL_STATUS(cp) = comp_status;
857 CMD_SCSI_STATUS(cp) = scsi_status;
858
bdf79622005-04-17 15:06:53 -0500859 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Ravi Ananded17c71b52006-05-17 15:08:55 -0700861 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800862 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700863 sense_len = le32_to_cpu(sts24->sense_len);
864 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
865 resid_len = le32_to_cpu(sts24->rsp_residual_count);
Ravi Ananded17c71b52006-05-17 15:08:55 -0700866 fw_resid_len = le32_to_cpu(sts24->residual_len);
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700867 rsp_info = sts24->data;
868 sense_data = sts24->data;
869 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
870 } else {
871 sense_len = le16_to_cpu(sts->req_sense_length);
872 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
873 resid_len = le32_to_cpu(sts->residual_length);
874 rsp_info = sts->rsp_info;
875 sense_data = sts->req_sense_data;
876 }
877
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 /* Check for any FCP transport errors. */
879 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700880 /* Sense data lies beyond any FCP RESPONSE data. */
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800881 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700882 sense_data += rsp_info_len;
883 if (rsp_info_len > 3 && rsp_info[3]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
885 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700886 "retrying command\n", ha->host_no,
887 cp->device->channel, cp->device->id,
888 cp->device->lun, rsp_info_len, rsp_info[0],
889 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
890 rsp_info[5], rsp_info[6], rsp_info[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
892 cp->result = DID_BUS_BUSY << 16;
f4f051e2005-04-17 15:02:26 -0500893 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 return;
895 }
896 }
897
898 /*
899 * Based on Host and scsi status generate status code for Linux
900 */
901 switch (comp_status) {
902 case CS_COMPLETE:
903 if (scsi_status == 0) {
904 cp->result = DID_OK << 16;
905 break;
906 }
907 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700908 resid = resid_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 cp->resid = resid;
910 CMD_RESID_LEN(cp) = resid;
Andrew Vasquez0da69df2005-12-06 10:58:06 -0800911
912 if (!lscsi_status &&
913 ((unsigned)(cp->request_bufflen - resid) <
914 cp->underflow)) {
915 qla_printk(KERN_INFO, ha,
916 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
917 "detected (%x of %x bytes)...returning "
918 "error status.\n", ha->host_no,
919 cp->device->channel, cp->device->id,
920 cp->device->lun, resid,
921 cp->request_bufflen);
922
923 cp->result = DID_ERROR << 16;
924 break;
925 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 cp->result = DID_OK << 16 | lscsi_status;
928
929 if (lscsi_status != SS_CHECK_CONDITION)
930 break;
931
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700932 /* Copy Sense Data into sense buffer. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
934
935 if (!(scsi_status & SS_SENSE_LEN_VALID))
936 break;
937
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700938 if (sense_len >= sizeof(cp->sense_buffer))
939 sense_len = sizeof(cp->sense_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700941 CMD_ACTUAL_SNSLEN(cp) = sense_len;
942 sp->request_sense_length = sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 sp->request_sense_ptr = cp->sense_buffer;
944
945 if (sp->request_sense_length > 32)
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700946 sense_len = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700948 memcpy(cp->sense_buffer, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700950 sp->request_sense_ptr += sense_len;
951 sp->request_sense_length -= sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 if (sp->request_sense_length != 0)
953 ha->status_srb = sp;
954
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 DEBUG5(printk("%s(): Check condition Sense data, "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700956 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n", __func__,
957 ha->host_no, cp->device->channel, cp->device->id,
958 cp->device->lun, cp, cp->serial_number));
959 if (sense_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
961 CMD_ACTUAL_SNSLEN(cp)));
962 break;
963
964 case CS_DATA_UNDERRUN:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700965 resid = resid_len;
Ravi Ananded17c71b52006-05-17 15:08:55 -0700966 /* Use F/W calculated residual length. */
967 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
968 resid = fw_resid_len;
969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 if (scsi_status & SS_RESIDUAL_UNDER) {
971 cp->resid = resid;
972 CMD_RESID_LEN(cp) = resid;
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -0800973 } else {
974 DEBUG2(printk(KERN_INFO
975 "scsi(%ld:%d:%d) UNDERRUN status detected "
Ravi Ananded17c71b52006-05-17 15:08:55 -0700976 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
977 "os_underflow=0x%x\n", ha->host_no,
978 cp->device->id, cp->device->lun, comp_status,
979 scsi_status, resid_len, resid, cp->cmnd[0],
980 cp->underflow));
andrew.vasquez@qlogic.come038a1be2006-01-13 17:04:59 -0800981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 }
983
984 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700985 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 * Status.
987 */
988 if (lscsi_status != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 cp->result = DID_OK << 16 | lscsi_status;
990
991 if (lscsi_status != SS_CHECK_CONDITION)
992 break;
993
994 /* Copy Sense Data into sense buffer */
995 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
996
997 if (!(scsi_status & SS_SENSE_LEN_VALID))
998 break;
999
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001000 if (sense_len >= sizeof(cp->sense_buffer))
1001 sense_len = sizeof(cp->sense_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001003 CMD_ACTUAL_SNSLEN(cp) = sense_len;
1004 sp->request_sense_length = sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 sp->request_sense_ptr = cp->sense_buffer;
1006
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001007 if (sp->request_sense_length > 32)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001008 sense_len = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001010 memcpy(cp->sense_buffer, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001012 sp->request_sense_ptr += sense_len;
1013 sp->request_sense_length -= sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 if (sp->request_sense_length != 0)
1015 ha->status_srb = sp;
1016
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 DEBUG5(printk("%s(): Check condition Sense data, "
1018 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001019 __func__, ha->host_no, cp->device->channel,
1020 cp->device->id, cp->device->lun, cp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 cp->serial_number));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001022
1023 if (sense_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
1025 CMD_ACTUAL_SNSLEN(cp)));
1026 } else {
1027 /*
1028 * If RISC reports underrun and target does not report
1029 * it then we must have a lost frame, so tell upper
1030 * layer to retry it by reporting a bus busy.
1031 */
1032 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1033 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1034 "frame(s) detected (%x of %x bytes)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001035 "retrying command.\n", ha->host_no,
1036 cp->device->channel, cp->device->id,
1037 cp->device->lun, resid,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 cp->request_bufflen));
1039
1040 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 break;
1042 }
1043
1044 /* Handle mid-layer underflow */
1045 if ((unsigned)(cp->request_bufflen - resid) <
1046 cp->underflow) {
1047 qla_printk(KERN_INFO, ha,
1048 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1049 "detected (%x of %x bytes)...returning "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001050 "error status.\n", ha->host_no,
1051 cp->device->channel, cp->device->id,
1052 cp->device->lun, resid,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 cp->request_bufflen);
1054
1055 cp->result = DID_ERROR << 16;
1056 break;
1057 }
1058
1059 /* Everybody online, looking good... */
1060 cp->result = DID_OK << 16;
1061 }
1062 break;
1063
1064 case CS_DATA_OVERRUN:
1065 DEBUG2(printk(KERN_INFO
1066 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001067 ha->host_no, cp->device->id, cp->device->lun, comp_status,
1068 scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 DEBUG2(printk(KERN_INFO
1070 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1071 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1072 cp->cmnd[4], cp->cmnd[5]));
1073 DEBUG2(printk(KERN_INFO
1074 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1075 "status!\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001076 cp->serial_number, cp->request_bufflen, resid_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
1078 cp->result = DID_ERROR << 16;
1079 break;
1080
1081 case CS_PORT_LOGGED_OUT:
1082 case CS_PORT_CONFIG_CHG:
1083 case CS_PORT_BUSY:
1084 case CS_INCOMPLETE:
1085 case CS_PORT_UNAVAILABLE:
1086 /*
1087 * If the port is in Target Down state, return all IOs for this
1088 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1089 * retry_queue.
1090 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1092 "pid=%ld, compl status=0x%x, port state=0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001093 ha->host_no, cp->device->id, cp->device->lun,
1094 cp->serial_number, comp_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 atomic_read(&fcport->state)));
1096
f4f051e2005-04-17 15:02:26 -05001097 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 if (atomic_read(&fcport->state) == FCS_ONLINE) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001099 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 break;
1102
1103 case CS_RESET:
1104 DEBUG2(printk(KERN_INFO
1105 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1106 ha->host_no, comp_status, scsi_status));
1107
f4f051e2005-04-17 15:02:26 -05001108 cp->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 break;
1110
1111 case CS_ABORTED:
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001112 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 * hv2.19.12 - DID_ABORT does not retry the request if we
1114 * aborted this request then abort otherwise it must be a
1115 * reset.
1116 */
1117 DEBUG2(printk(KERN_INFO
1118 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1119 ha->host_no, comp_status, scsi_status));
1120
1121 cp->result = DID_RESET << 16;
1122 break;
1123
1124 case CS_TIMEOUT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 cp->result = DID_BUS_BUSY << 16;
1126
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001127 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001128 DEBUG2(printk(KERN_INFO
1129 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1130 "0x%x-0x%x\n", ha->host_no, cp->device->channel,
1131 cp->device->id, cp->device->lun, comp_status,
1132 scsi_status));
1133 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001135 DEBUG2(printk(KERN_INFO
1136 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1137 "sflags=%x.\n", ha->host_no, cp->device->channel,
1138 cp->device->id, cp->device->lun, comp_status, scsi_status,
1139 le16_to_cpu(sts->status_flags)));
1140
1141 /* Check to see if logout occurred. */
1142 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001143 qla2x00_mark_device_lost(ha, fcport, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 break;
1145
1146 case CS_QUEUE_FULL:
1147 DEBUG2(printk(KERN_INFO
1148 "scsi(%ld): QUEUE FULL status detected 0x%x-0x%x.\n",
1149 ha->host_no, comp_status, scsi_status));
1150
1151 /* SCSI Mid-Layer handles device queue full */
1152
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001153 cp->result = DID_OK << 16 | lscsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 break;
1156
1157 default:
1158 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001159 "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 qla_printk(KERN_INFO, ha,
1161 "Unknown status detected 0x%x-0x%x.\n",
1162 comp_status, scsi_status);
1163
1164 cp->result = DID_ERROR << 16;
1165 break;
1166 }
1167
1168 /* Place command on done queue. */
1169 if (ha->status_srb == NULL)
f4f051e2005-04-17 15:02:26 -05001170 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171}
1172
1173/**
1174 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1175 * @ha: SCSI driver HA context
1176 * @pkt: Entry pointer
1177 *
1178 * Extended sense data.
1179 */
1180static void
1181qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1182{
1183 uint8_t sense_sz = 0;
1184 srb_t *sp = ha->status_srb;
1185 struct scsi_cmnd *cp;
1186
1187 if (sp != NULL && sp->request_sense_length != 0) {
1188 cp = sp->cmd;
1189 if (cp == NULL) {
1190 DEBUG2(printk("%s(): Cmd already returned back to OS "
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001191 "sp=%p.\n", __func__, sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 qla_printk(KERN_INFO, ha,
1193 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001194 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
1196 ha->status_srb = NULL;
1197 return;
1198 }
1199
1200 if (sp->request_sense_length > sizeof(pkt->data)) {
1201 sense_sz = sizeof(pkt->data);
1202 } else {
1203 sense_sz = sp->request_sense_length;
1204 }
1205
1206 /* Move sense data. */
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001207 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001208 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1210 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1211
1212 sp->request_sense_ptr += sense_sz;
1213 sp->request_sense_length -= sense_sz;
1214
1215 /* Place command on done queue. */
1216 if (sp->request_sense_length == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 ha->status_srb = NULL;
f4f051e2005-04-17 15:02:26 -05001218 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 }
1220 }
1221}
1222
1223/**
1224 * qla2x00_error_entry() - Process an error entry.
1225 * @ha: SCSI driver HA context
1226 * @pkt: Entry pointer
1227 */
1228static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001229qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230{
1231 srb_t *sp;
1232
1233#if defined(QL_DEBUG_LEVEL_2)
1234 if (pkt->entry_status & RF_INV_E_ORDER)
1235 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1236 else if (pkt->entry_status & RF_INV_E_COUNT)
1237 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1238 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001239 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 "%s: Invalid Entry Parameter\n", __func__);
1241 else if (pkt->entry_status & RF_INV_E_TYPE)
1242 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1243 else if (pkt->entry_status & RF_BUSY)
1244 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1245 else
1246 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1247#endif
1248
1249 /* Validate handle. */
1250 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1251 sp = ha->outstanding_cmds[pkt->handle];
1252 else
1253 sp = NULL;
1254
1255 if (sp) {
1256 /* Free outstanding command slot. */
1257 ha->outstanding_cmds[pkt->handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001258
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 /* Bad payload or header */
1260 if (pkt->entry_status &
1261 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1262 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1263 sp->cmd->result = DID_ERROR << 16;
1264 } else if (pkt->entry_status & RF_BUSY) {
1265 sp->cmd->result = DID_BUS_BUSY << 16;
1266 } else {
1267 sp->cmd->result = DID_ERROR << 16;
1268 }
f4f051e2005-04-17 15:02:26 -05001269 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001271 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1272 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1274 ha->host_no));
1275 qla_printk(KERN_WARNING, ha,
1276 "Error entry - invalid handle\n");
1277
1278 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +01001279 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 }
1281}
1282
1283/**
1284 * qla2x00_ms_entry() - Process a Management Server entry.
1285 * @ha: SCSI driver HA context
1286 * @index: Response queue out pointer
1287 */
1288static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001289qla2x00_ms_entry(scsi_qla_host_t *ha, ms_iocb_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290{
1291 srb_t *sp;
1292
1293 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1294 __func__, ha->host_no, pkt, pkt->handle1));
1295
1296 /* Validate handle. */
1297 if (pkt->handle1 < MAX_OUTSTANDING_COMMANDS)
1298 sp = ha->outstanding_cmds[pkt->handle1];
1299 else
1300 sp = NULL;
1301
1302 if (sp == NULL) {
1303 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1304 ha->host_no));
1305 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle\n");
1306
1307 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1308 return;
1309 }
1310
1311 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->status);
1312 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1313
1314 /* Free outstanding command slot. */
1315 ha->outstanding_cmds[pkt->handle1] = NULL;
1316
f4f051e2005-04-17 15:02:26 -05001317 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318}
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001319
1320
1321/**
1322 * qla24xx_mbx_completion() - Process mailbox command completions.
1323 * @ha: SCSI driver HA context
1324 * @mb0: Mailbox0 register
1325 */
1326static void
1327qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
1328{
1329 uint16_t cnt;
1330 uint16_t __iomem *wptr;
1331 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1332
1333 /* Load return mailbox registers. */
1334 ha->flags.mbox_int = 1;
1335 ha->mailbox_out[0] = mb0;
1336 wptr = (uint16_t __iomem *)&reg->mailbox1;
1337
1338 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1339 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1340 wptr++;
1341 }
1342
1343 if (ha->mcp) {
1344 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1345 __func__, ha->host_no, ha->mcp->mb[0]));
1346 } else {
1347 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1348 __func__, ha->host_no));
1349 }
1350}
1351
1352/**
1353 * qla24xx_process_response_queue() - Process response queue entries.
1354 * @ha: SCSI driver HA context
1355 */
1356void
1357qla24xx_process_response_queue(struct scsi_qla_host *ha)
1358{
1359 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1360 struct sts_entry_24xx *pkt;
1361
1362 if (!ha->flags.online)
1363 return;
1364
1365 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
1366 pkt = (struct sts_entry_24xx *)ha->response_ring_ptr;
1367
1368 ha->rsp_ring_index++;
1369 if (ha->rsp_ring_index == ha->response_q_length) {
1370 ha->rsp_ring_index = 0;
1371 ha->response_ring_ptr = ha->response_ring;
1372 } else {
1373 ha->response_ring_ptr++;
1374 }
1375
1376 if (pkt->entry_status != 0) {
1377 DEBUG3(printk(KERN_INFO
1378 "scsi(%ld): Process error entry.\n", ha->host_no));
1379
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001380 qla2x00_error_entry(ha, (sts_entry_t *) pkt);
1381 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1382 wmb();
1383 continue;
1384 }
1385
1386 switch (pkt->entry_type) {
1387 case STATUS_TYPE:
1388 qla2x00_status_entry(ha, pkt);
1389 break;
1390 case STATUS_CONT_TYPE:
1391 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
1392 break;
1393 case MS_IOCB_TYPE:
1394 qla24xx_ms_entry(ha, (struct ct_entry_24xx *)pkt);
1395 break;
1396 default:
1397 /* Type Not Supported. */
1398 DEBUG4(printk(KERN_WARNING
1399 "scsi(%ld): Received unknown response pkt type %x "
1400 "entry status=%x.\n",
1401 ha->host_no, pkt->entry_type, pkt->entry_status));
1402 break;
1403 }
1404 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1405 wmb();
1406 }
1407
1408 /* Adjust ring index */
1409 WRT_REG_DWORD(&reg->rsp_q_out, ha->rsp_ring_index);
1410}
1411
1412/**
1413 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1414 * @irq:
1415 * @dev_id: SCSI driver HA context
1416 * @regs:
1417 *
1418 * Called by system whenever the host adapter generates an interrupt.
1419 *
1420 * Returns handled flag.
1421 */
1422irqreturn_t
1423qla24xx_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1424{
1425 scsi_qla_host_t *ha;
1426 struct device_reg_24xx __iomem *reg;
1427 int status;
1428 unsigned long flags;
1429 unsigned long iter;
1430 uint32_t stat;
1431 uint32_t hccr;
1432 uint16_t mb[4];
1433
1434 ha = (scsi_qla_host_t *) dev_id;
1435 if (!ha) {
1436 printk(KERN_INFO
1437 "%s(): NULL host pointer\n", __func__);
1438 return IRQ_NONE;
1439 }
1440
1441 reg = &ha->iobase->isp24;
1442 status = 0;
1443
1444 spin_lock_irqsave(&ha->hardware_lock, flags);
1445 for (iter = 50; iter--; ) {
1446 stat = RD_REG_DWORD(&reg->host_status);
1447 if (stat & HSRX_RISC_PAUSED) {
1448 hccr = RD_REG_DWORD(&reg->hccr);
1449
1450 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1451 "Dumping firmware!\n", hccr);
1452 qla24xx_fw_dump(ha, 1);
1453
1454 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1455 break;
1456 } else if ((stat & HSRX_RISC_INT) == 0)
1457 break;
1458
1459 switch (stat & 0xff) {
1460 case 0x1:
1461 case 0x2:
1462 case 0x10:
1463 case 0x11:
1464 qla24xx_mbx_completion(ha, MSW(stat));
1465 status |= MBX_INTERRUPT;
1466
1467 break;
1468 case 0x12:
1469 mb[0] = MSW(stat);
1470 mb[1] = RD_REG_WORD(&reg->mailbox1);
1471 mb[2] = RD_REG_WORD(&reg->mailbox2);
1472 mb[3] = RD_REG_WORD(&reg->mailbox3);
1473 qla2x00_async_event(ha, mb);
1474 break;
1475 case 0x13:
1476 qla24xx_process_response_queue(ha);
1477 break;
1478 default:
1479 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1480 "(%d).\n",
1481 ha->host_no, stat & 0xff));
1482 break;
1483 }
1484 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1485 RD_REG_DWORD_RELAXED(&reg->hccr);
1486 }
1487 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1488
1489 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1490 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1491 spin_lock_irqsave(&ha->mbx_reg_lock, flags);
1492
1493 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1494 up(&ha->mbx_intr_sem);
1495
1496 spin_unlock_irqrestore(&ha->mbx_reg_lock, flags);
1497 }
1498
1499 return IRQ_HANDLED;
1500}
1501
1502/**
1503 * qla24xx_ms_entry() - Process a Management Server entry.
1504 * @ha: SCSI driver HA context
1505 * @index: Response queue out pointer
1506 */
1507static void
1508qla24xx_ms_entry(scsi_qla_host_t *ha, struct ct_entry_24xx *pkt)
1509{
1510 srb_t *sp;
1511
1512 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1513 __func__, ha->host_no, pkt, pkt->handle));
1514
1515 DEBUG9(printk("%s: ct pkt dump:\n", __func__);)
1516 DEBUG9(qla2x00_dump_buffer((void *)pkt, sizeof(struct ct_entry_24xx));)
1517
1518 /* Validate handle. */
1519 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1520 sp = ha->outstanding_cmds[pkt->handle];
1521 else
1522 sp = NULL;
1523
1524 if (sp == NULL) {
1525 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1526 ha->host_no));
1527 DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n",
1528 ha->host_no));
1529 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle %d\n",
1530 pkt->handle);
1531
1532 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1533 return;
1534 }
1535
1536 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->comp_status);
1537 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1538
1539 /* Free outstanding command slot. */
1540 ha->outstanding_cmds[pkt->handle] = NULL;
1541
1542 qla2x00_sp_compl(ha, sp);
1543}
1544