blob: 8a539dd48753a391462a8c1c60dc913a201afca4 [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 Vasquez9a853f72005-07-06 10:31:27 -0700346 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
347 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);
392 qla2x00_mark_all_devices_lost(ha);
393 }
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 ha->link_data_rate = 0;
406 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
407 link_speed = link_speeds[0];
408 } 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;
435 qla2x00_mark_all_devices_lost(ha);
436 }
437
438 ha->flags.management_server_logged_in = 0;
439 ha->link_data_rate = 0;
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);
456 qla2x00_mark_all_devices_lost(ha);
457 }
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);
485 qla2x00_mark_all_devices_lost(ha);
486 }
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);
509 qla2x00_mark_all_devices_lost(ha);
510 }
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 */
522 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA6312(ha) &&
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700523 !IS_QLA6322(ha) && !IS_QLA24XX(ha) && !IS_QLA25XX(ha) &&
524 ha->flags.init_done && mb[1] != 0xffff &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 ((ha->operating_mode == P2P && mb[1] != 0) ||
526 (ha->operating_mode != P2P && mb[1] !=
527 SNS_FIRST_LOOP_ID)) && (mb[2] == 6 || mb[2] == 7)) {
528 int rval;
529 fc_port_t *rscn_fcport;
530
531 /* Create new fcport for login. */
532 rscn_fcport = qla2x00_alloc_rscn_fcport(ha, GFP_ATOMIC);
533 if (rscn_fcport) {
534 DEBUG14(printk("scsi(%ld): Port Update -- "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700535 "creating RSCN fcport %p for %x/%x/%x.\n",
536 ha->host_no, rscn_fcport, mb[1], mb[2],
537 mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
539 rscn_fcport->loop_id = mb[1];
540 rscn_fcport->d_id.b24 = INVALID_PORT_ID;
541 atomic_set(&rscn_fcport->state,
542 FCS_DEVICE_LOST);
543 list_add_tail(&rscn_fcport->list,
544 &ha->rscn_fcports);
545
546 rval = qla2x00_handle_port_rscn(ha, 0,
547 rscn_fcport, 1);
548 if (rval == QLA_SUCCESS)
549 break;
550 } else {
551 DEBUG14(printk("scsi(%ld): Port Update -- "
552 "-- unable to allocate RSCN fcport "
553 "login.\n", ha->host_no));
554 }
555 }
556
557 /*
558 * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET
559 * event etc. earlier indicating loop is down) then process
560 * it. Otherwise ignore it and Wait for RSCN to come in.
561 */
562 atomic_set(&ha->loop_down_timer, 0);
563 if (atomic_read(&ha->loop_state) != LOOP_DOWN &&
564 atomic_read(&ha->loop_state) != LOOP_DEAD) {
565 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700566 "ignored %04x/%04x/%04x.\n", ha->host_no, mb[1],
567 mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 break;
569 }
570
571 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
572 ha->host_no));
573 DEBUG(printk(KERN_INFO
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700574 "scsi(%ld): Port database changed %04x %04x %04x.\n",
575 ha->host_no, mb[1], mb[2], mb[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577 /*
578 * Mark all devices as missing so we will login again.
579 */
580 atomic_set(&ha->loop_state, LOOP_UP);
581
582 qla2x00_mark_all_devices_lost(ha);
583
584 ha->flags.rscn_queue_overflow = 1;
585
586 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
587 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
588
589 /* Update AEN queue. */
590 qla2x00_enqueue_aen(ha, MBA_PORT_UPDATE, NULL);
591 break;
592
593 case MBA_RSCN_UPDATE: /* State Change Registration */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
595 ha->host_no));
596 DEBUG(printk(KERN_INFO
597 "scsi(%ld): RSCN database changed -- %04x %04x.\n",
598 ha->host_no, mb[1], mb[2]));
599
600 rscn_entry = (mb[1] << 16) | mb[2];
601 host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) |
602 ha->d_id.b.al_pa;
603 if (rscn_entry == host_pid) {
604 DEBUG(printk(KERN_INFO
605 "scsi(%ld): Ignoring RSCN update to local host "
606 "port ID (%06x)\n",
607 ha->host_no, host_pid));
608 break;
609 }
610
611 rscn_queue_index = ha->rscn_in_ptr + 1;
612 if (rscn_queue_index == MAX_RSCN_COUNT)
613 rscn_queue_index = 0;
614 if (rscn_queue_index != ha->rscn_out_ptr) {
615 ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry;
616 ha->rscn_in_ptr = rscn_queue_index;
617 } else {
618 ha->flags.rscn_queue_overflow = 1;
619 }
620
621 atomic_set(&ha->loop_state, LOOP_UPDATE);
622 atomic_set(&ha->loop_down_timer, 0);
623 ha->flags.management_server_logged_in = 0;
624
625 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
626 set_bit(RSCN_UPDATE, &ha->dpc_flags);
627
628 /* Update AEN queue. */
629 qla2x00_enqueue_aen(ha, MBA_RSCN_UPDATE, &mb[0]);
630 break;
631
632 /* case MBA_RIO_RESPONSE: */
633 case MBA_ZIO_RESPONSE:
634 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
635 ha->host_no));
636 DEBUG(printk(KERN_INFO
637 "scsi(%ld): [R|Z]IO update completion.\n",
638 ha->host_no));
639
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700640 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
641 qla24xx_process_response_queue(ha);
642 else
643 qla2x00_process_response_queue(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 break;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700645
646 case MBA_DISCARD_RND_FRAME:
647 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
648 "%04x.\n", ha->host_no, mb[1], mb[2], mb[3]));
649 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 }
651}
652
653/**
654 * qla2x00_process_completed_request() - Process a Fast Post response.
655 * @ha: SCSI driver HA context
656 * @index: SRB index
657 */
658static void
659qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
660{
661 srb_t *sp;
662
663 /* Validate handle. */
664 if (index >= MAX_OUTSTANDING_COMMANDS) {
665 DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
666 ha->host_no, index));
667 qla_printk(KERN_WARNING, ha,
668 "Invalid SCSI completion handle %d.\n", index);
669
670 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
671 return;
672 }
673
674 sp = ha->outstanding_cmds[index];
675 if (sp) {
676 /* Free outstanding command slot. */
677 ha->outstanding_cmds[index] = NULL;
678
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 CMD_COMPL_STATUS(sp->cmd) = 0L;
680 CMD_SCSI_STATUS(sp->cmd) = 0L;
681
682 /* Save ISP completion status */
683 sp->cmd->result = DID_OK << 16;
f4f051e2005-04-17 15:02:26 -0500684 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 } else {
686 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
687 ha->host_no));
688 qla_printk(KERN_WARNING, ha,
689 "Invalid ISP SCSI completion handle\n");
690
691 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
692 }
693}
694
695/**
696 * qla2x00_process_response_queue() - Process response queue entries.
697 * @ha: SCSI driver HA context
698 */
699void
700qla2x00_process_response_queue(struct scsi_qla_host *ha)
701{
Andrew Vasquez3d716442005-07-06 10:30:26 -0700702 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 sts_entry_t *pkt;
704 uint16_t handle_cnt;
705 uint16_t cnt;
706
707 if (!ha->flags.online)
708 return;
709
710 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
711 pkt = (sts_entry_t *)ha->response_ring_ptr;
712
713 ha->rsp_ring_index++;
714 if (ha->rsp_ring_index == ha->response_q_length) {
715 ha->rsp_ring_index = 0;
716 ha->response_ring_ptr = ha->response_ring;
717 } else {
718 ha->response_ring_ptr++;
719 }
720
721 if (pkt->entry_status != 0) {
722 DEBUG3(printk(KERN_INFO
723 "scsi(%ld): Process error entry.\n", ha->host_no));
724
725 qla2x00_error_entry(ha, pkt);
726 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
727 wmb();
728 continue;
729 }
730
731 switch (pkt->entry_type) {
732 case STATUS_TYPE:
733 qla2x00_status_entry(ha, pkt);
734 break;
735 case STATUS_TYPE_21:
736 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
737 for (cnt = 0; cnt < handle_cnt; cnt++) {
738 qla2x00_process_completed_request(ha,
739 ((sts21_entry_t *)pkt)->handle[cnt]);
740 }
741 break;
742 case STATUS_TYPE_22:
743 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
744 for (cnt = 0; cnt < handle_cnt; cnt++) {
745 qla2x00_process_completed_request(ha,
746 ((sts22_entry_t *)pkt)->handle[cnt]);
747 }
748 break;
749 case STATUS_CONT_TYPE:
750 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
751 break;
752 case MS_IOCB_TYPE:
753 qla2x00_ms_entry(ha, (ms_iocb_entry_t *)pkt);
754 break;
755 case MBX_IOCB_TYPE:
756 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
757 !IS_QLA6312(ha) && !IS_QLA6322(ha)) {
758 if (pkt->sys_define == SOURCE_ASYNC_IOCB) {
759 qla2x00_process_iodesc(ha,
760 (struct mbx_entry *)pkt);
761 } else {
762 /* MBX IOCB Type Not Supported. */
763 DEBUG4(printk(KERN_WARNING
764 "scsi(%ld): Received unknown MBX "
765 "IOCB response pkt type=%x "
766 "source=%x entry status=%x.\n",
767 ha->host_no, pkt->entry_type,
768 pkt->sys_define,
769 pkt->entry_status));
770 }
771 break;
772 }
773 /* Fallthrough. */
774 default:
775 /* Type Not Supported. */
776 DEBUG4(printk(KERN_WARNING
777 "scsi(%ld): Received unknown response pkt type %x "
778 "entry status=%x.\n",
779 ha->host_no, pkt->entry_type, pkt->entry_status));
780 break;
781 }
782 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
783 wmb();
784 }
785
786 /* Adjust ring index */
787 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index);
788}
789
790/**
791 * qla2x00_status_entry() - Process a Status IOCB entry.
792 * @ha: SCSI driver HA context
793 * @pkt: Entry pointer
794 */
795static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700796qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 fc_port_t *fcport;
800 struct scsi_cmnd *cp;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700801 sts_entry_t *sts;
802 struct sts_entry_24xx *sts24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 uint16_t comp_status;
804 uint16_t scsi_status;
805 uint8_t lscsi_status;
806 int32_t resid;
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700807 uint32_t sense_len, rsp_info_len, resid_len;
808 uint8_t *rsp_info, *sense_data;
809
810 sts = (sts_entry_t *) pkt;
811 sts24 = (struct sts_entry_24xx *) pkt;
812 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
813 comp_status = le16_to_cpu(sts24->comp_status);
814 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
815 } else {
816 comp_status = le16_to_cpu(sts->comp_status);
817 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
818 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
820 /* Fast path completion. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700821 if (comp_status == CS_COMPLETE && scsi_status == 0) {
822 qla2x00_process_completed_request(ha, sts->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
824 return;
825 }
826
827 /* Validate handle. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700828 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
829 sp = ha->outstanding_cmds[sts->handle];
830 ha->outstanding_cmds[sts->handle] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 } else
832 sp = NULL;
833
834 if (sp == NULL) {
835 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
836 ha->host_no));
837 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
838
839 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700840 if (ha->dpc_wait && !ha->dpc_active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 up(ha->dpc_wait);
842
843 return;
844 }
845 cp = sp->cmd;
846 if (cp == NULL) {
847 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
848 "pkt->handle=%d sp=%p sp->state:%d\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700849 ha->host_no, sts->handle, sp, sp->state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 qla_printk(KERN_WARNING, ha,
851 "Command is NULL: already returned to OS (sp=%p)\n", sp);
852
853 return;
854 }
855
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700856 lscsi_status = scsi_status & STATUS_MASK;
857 CMD_ENTRY_STATUS(cp) = sts->entry_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 CMD_COMPL_STATUS(cp) = comp_status;
859 CMD_SCSI_STATUS(cp) = scsi_status;
860
bdf79622005-04-17 15:06:53 -0500861 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700863 sense_len = rsp_info_len = resid_len = 0;
864 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
865 sense_len = le32_to_cpu(sts24->sense_len);
866 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
867 resid_len = le32_to_cpu(sts24->rsp_residual_count);
868 rsp_info = sts24->data;
869 sense_data = sts24->data;
870 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
871 } else {
872 sense_len = le16_to_cpu(sts->req_sense_length);
873 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
874 resid_len = le32_to_cpu(sts->residual_length);
875 rsp_info = sts->rsp_info;
876 sense_data = sts->req_sense_data;
877 }
878
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 /* Check for any FCP transport errors. */
880 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700881 /* Sense data lies beyond any FCP RESPONSE data. */
882 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
883 sense_data += rsp_info_len;
884 if (rsp_info_len > 3 && rsp_info[3]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
886 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700887 "retrying command\n", ha->host_no,
888 cp->device->channel, cp->device->id,
889 cp->device->lun, rsp_info_len, rsp_info[0],
890 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
891 rsp_info[5], rsp_info[6], rsp_info[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
893 cp->result = DID_BUS_BUSY << 16;
f4f051e2005-04-17 15:02:26 -0500894 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 return;
896 }
897 }
898
899 /*
900 * Based on Host and scsi status generate status code for Linux
901 */
902 switch (comp_status) {
903 case CS_COMPLETE:
904 if (scsi_status == 0) {
905 cp->result = DID_OK << 16;
906 break;
907 }
908 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700909 resid = resid_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 cp->resid = resid;
911 CMD_RESID_LEN(cp) = resid;
Andrew Vasquez0da69df2005-12-06 10:58:06 -0800912
913 if (!lscsi_status &&
914 ((unsigned)(cp->request_bufflen - resid) <
915 cp->underflow)) {
916 qla_printk(KERN_INFO, ha,
917 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
918 "detected (%x of %x bytes)...returning "
919 "error status.\n", ha->host_no,
920 cp->device->channel, cp->device->id,
921 cp->device->lun, resid,
922 cp->request_bufflen);
923
924 cp->result = DID_ERROR << 16;
925 break;
926 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 cp->result = DID_OK << 16 | lscsi_status;
929
930 if (lscsi_status != SS_CHECK_CONDITION)
931 break;
932
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700933 /* Copy Sense Data into sense buffer. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
935
936 if (!(scsi_status & SS_SENSE_LEN_VALID))
937 break;
938
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700939 if (sense_len >= sizeof(cp->sense_buffer))
940 sense_len = sizeof(cp->sense_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700942 CMD_ACTUAL_SNSLEN(cp) = sense_len;
943 sp->request_sense_length = sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 sp->request_sense_ptr = cp->sense_buffer;
945
946 if (sp->request_sense_length > 32)
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700947 sense_len = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700949 memcpy(cp->sense_buffer, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700951 sp->request_sense_ptr += sense_len;
952 sp->request_sense_length -= sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 if (sp->request_sense_length != 0)
954 ha->status_srb = sp;
955
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 DEBUG5(printk("%s(): Check condition Sense data, "
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700957 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n", __func__,
958 ha->host_no, cp->device->channel, cp->device->id,
959 cp->device->lun, cp, cp->serial_number));
960 if (sense_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
962 CMD_ACTUAL_SNSLEN(cp)));
963 break;
964
965 case CS_DATA_UNDERRUN:
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700966 resid = resid_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 if (scsi_status & SS_RESIDUAL_UNDER) {
968 cp->resid = resid;
969 CMD_RESID_LEN(cp) = resid;
andrew.vasquez@qlogic.come038a1b2006-01-13 17:04:59 -0800970 } else {
971 DEBUG2(printk(KERN_INFO
972 "scsi(%ld:%d:%d) UNDERRUN status detected "
973 "0x%x-0x%x.\n", ha->host_no, cp->device->id,
974 cp->device->lun, comp_status, scsi_status));
975
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 }
977
978 /*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700979 * Check to see if SCSI Status is non zero. If so report SCSI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 * Status.
981 */
982 if (lscsi_status != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 cp->result = DID_OK << 16 | lscsi_status;
984
985 if (lscsi_status != SS_CHECK_CONDITION)
986 break;
987
988 /* Copy Sense Data into sense buffer */
989 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
990
991 if (!(scsi_status & SS_SENSE_LEN_VALID))
992 break;
993
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700994 if (sense_len >= sizeof(cp->sense_buffer))
995 sense_len = sizeof(cp->sense_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
Andrew Vasquez9a853f72005-07-06 10:31:27 -0700997 CMD_ACTUAL_SNSLEN(cp) = sense_len;
998 sp->request_sense_length = sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 sp->request_sense_ptr = cp->sense_buffer;
1000
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001001 if (sp->request_sense_length > 32)
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001002 sense_len = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001004 memcpy(cp->sense_buffer, sense_data, sense_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001006 sp->request_sense_ptr += sense_len;
1007 sp->request_sense_length -= sense_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 if (sp->request_sense_length != 0)
1009 ha->status_srb = sp;
1010
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 DEBUG5(printk("%s(): Check condition Sense data, "
1012 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001013 __func__, ha->host_no, cp->device->channel,
1014 cp->device->id, cp->device->lun, cp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 cp->serial_number));
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001016
1017 if (sense_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
1019 CMD_ACTUAL_SNSLEN(cp)));
1020 } else {
1021 /*
1022 * If RISC reports underrun and target does not report
1023 * it then we must have a lost frame, so tell upper
1024 * layer to retry it by reporting a bus busy.
1025 */
1026 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1027 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1028 "frame(s) detected (%x of %x bytes)..."
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001029 "retrying command.\n", ha->host_no,
1030 cp->device->channel, cp->device->id,
1031 cp->device->lun, resid,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 cp->request_bufflen));
1033
1034 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 break;
1036 }
1037
1038 /* Handle mid-layer underflow */
1039 if ((unsigned)(cp->request_bufflen - resid) <
1040 cp->underflow) {
1041 qla_printk(KERN_INFO, ha,
1042 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1043 "detected (%x of %x bytes)...returning "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001044 "error status.\n", ha->host_no,
1045 cp->device->channel, cp->device->id,
1046 cp->device->lun, resid,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 cp->request_bufflen);
1048
1049 cp->result = DID_ERROR << 16;
1050 break;
1051 }
1052
1053 /* Everybody online, looking good... */
1054 cp->result = DID_OK << 16;
1055 }
1056 break;
1057
1058 case CS_DATA_OVERRUN:
1059 DEBUG2(printk(KERN_INFO
1060 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001061 ha->host_no, cp->device->id, cp->device->lun, comp_status,
1062 scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 DEBUG2(printk(KERN_INFO
1064 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1065 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1066 cp->cmnd[4], cp->cmnd[5]));
1067 DEBUG2(printk(KERN_INFO
1068 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1069 "status!\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001070 cp->serial_number, cp->request_bufflen, resid_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
1072 cp->result = DID_ERROR << 16;
1073 break;
1074
1075 case CS_PORT_LOGGED_OUT:
1076 case CS_PORT_CONFIG_CHG:
1077 case CS_PORT_BUSY:
1078 case CS_INCOMPLETE:
1079 case CS_PORT_UNAVAILABLE:
1080 /*
1081 * If the port is in Target Down state, return all IOs for this
1082 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1083 * retry_queue.
1084 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1086 "pid=%ld, compl status=0x%x, port state=0x%x\n",
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001087 ha->host_no, cp->device->id, cp->device->lun,
1088 cp->serial_number, comp_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 atomic_read(&fcport->state)));
1090
f4f051e2005-04-17 15:02:26 -05001091 cp->result = DID_BUS_BUSY << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 if (atomic_read(&fcport->state) == FCS_ONLINE) {
1093 qla2x00_mark_device_lost(ha, fcport, 1);
1094 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 break;
1096
1097 case CS_RESET:
1098 DEBUG2(printk(KERN_INFO
1099 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1100 ha->host_no, comp_status, scsi_status));
1101
f4f051e2005-04-17 15:02:26 -05001102 cp->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 break;
1104
1105 case CS_ABORTED:
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001106 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 * hv2.19.12 - DID_ABORT does not retry the request if we
1108 * aborted this request then abort otherwise it must be a
1109 * reset.
1110 */
1111 DEBUG2(printk(KERN_INFO
1112 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1113 ha->host_no, comp_status, scsi_status));
1114
1115 cp->result = DID_RESET << 16;
1116 break;
1117
1118 case CS_TIMEOUT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 cp->result = DID_BUS_BUSY << 16;
1120
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001121 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1122 DEBUG2(printk(KERN_INFO
1123 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1124 "0x%x-0x%x\n", ha->host_no, cp->device->channel,
1125 cp->device->id, cp->device->lun, comp_status,
1126 scsi_status));
1127 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 }
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001129 DEBUG2(printk(KERN_INFO
1130 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1131 "sflags=%x.\n", ha->host_no, cp->device->channel,
1132 cp->device->id, cp->device->lun, comp_status, scsi_status,
1133 le16_to_cpu(sts->status_flags)));
1134
1135 /* Check to see if logout occurred. */
1136 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
1137 qla2x00_mark_device_lost(ha, fcport, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 break;
1139
1140 case CS_QUEUE_FULL:
1141 DEBUG2(printk(KERN_INFO
1142 "scsi(%ld): QUEUE FULL status detected 0x%x-0x%x.\n",
1143 ha->host_no, comp_status, scsi_status));
1144
1145 /* SCSI Mid-Layer handles device queue full */
1146
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001147 cp->result = DID_OK << 16 | lscsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 break;
1150
1151 default:
1152 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001153 "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 qla_printk(KERN_INFO, ha,
1155 "Unknown status detected 0x%x-0x%x.\n",
1156 comp_status, scsi_status);
1157
1158 cp->result = DID_ERROR << 16;
1159 break;
1160 }
1161
1162 /* Place command on done queue. */
1163 if (ha->status_srb == NULL)
f4f051e2005-04-17 15:02:26 -05001164 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165}
1166
1167/**
1168 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1169 * @ha: SCSI driver HA context
1170 * @pkt: Entry pointer
1171 *
1172 * Extended sense data.
1173 */
1174static void
1175qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1176{
1177 uint8_t sense_sz = 0;
1178 srb_t *sp = ha->status_srb;
1179 struct scsi_cmnd *cp;
1180
1181 if (sp != NULL && sp->request_sense_length != 0) {
1182 cp = sp->cmd;
1183 if (cp == NULL) {
1184 DEBUG2(printk("%s(): Cmd already returned back to OS "
1185 "sp=%p sp->state:%d\n", __func__, sp, sp->state));
1186 qla_printk(KERN_INFO, ha,
1187 "cmd is NULL: already returned to OS (sp=%p)\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001188 sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
1190 ha->status_srb = NULL;
1191 return;
1192 }
1193
1194 if (sp->request_sense_length > sizeof(pkt->data)) {
1195 sense_sz = sizeof(pkt->data);
1196 } else {
1197 sense_sz = sp->request_sense_length;
1198 }
1199
1200 /* Move sense data. */
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001201 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
1202 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1204 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1205
1206 sp->request_sense_ptr += sense_sz;
1207 sp->request_sense_length -= sense_sz;
1208
1209 /* Place command on done queue. */
1210 if (sp->request_sense_length == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 ha->status_srb = NULL;
f4f051e2005-04-17 15:02:26 -05001212 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 }
1214 }
1215}
1216
1217/**
1218 * qla2x00_error_entry() - Process an error entry.
1219 * @ha: SCSI driver HA context
1220 * @pkt: Entry pointer
1221 */
1222static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001223qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224{
1225 srb_t *sp;
1226
1227#if defined(QL_DEBUG_LEVEL_2)
1228 if (pkt->entry_status & RF_INV_E_ORDER)
1229 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
1230 else if (pkt->entry_status & RF_INV_E_COUNT)
1231 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
1232 else if (pkt->entry_status & RF_INV_E_PARAM)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001233 qla_printk(KERN_ERR, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 "%s: Invalid Entry Parameter\n", __func__);
1235 else if (pkt->entry_status & RF_INV_E_TYPE)
1236 qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
1237 else if (pkt->entry_status & RF_BUSY)
1238 qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
1239 else
1240 qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
1241#endif
1242
1243 /* Validate handle. */
1244 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1245 sp = ha->outstanding_cmds[pkt->handle];
1246 else
1247 sp = NULL;
1248
1249 if (sp) {
1250 /* Free outstanding command slot. */
1251 ha->outstanding_cmds[pkt->handle] = NULL;
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001252
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 /* Bad payload or header */
1254 if (pkt->entry_status &
1255 (RF_INV_E_ORDER | RF_INV_E_COUNT |
1256 RF_INV_E_PARAM | RF_INV_E_TYPE)) {
1257 sp->cmd->result = DID_ERROR << 16;
1258 } else if (pkt->entry_status & RF_BUSY) {
1259 sp->cmd->result = DID_BUS_BUSY << 16;
1260 } else {
1261 sp->cmd->result = DID_ERROR << 16;
1262 }
f4f051e2005-04-17 15:02:26 -05001263 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001265 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1266 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
1268 ha->host_no));
1269 qla_printk(KERN_WARNING, ha,
1270 "Error entry - invalid handle\n");
1271
1272 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001273 if (ha->dpc_wait && !ha->dpc_active)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 up(ha->dpc_wait);
1275 }
1276}
1277
1278/**
1279 * qla2x00_ms_entry() - Process a Management Server entry.
1280 * @ha: SCSI driver HA context
1281 * @index: Response queue out pointer
1282 */
1283static void
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001284qla2x00_ms_entry(scsi_qla_host_t *ha, ms_iocb_entry_t *pkt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285{
1286 srb_t *sp;
1287
1288 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1289 __func__, ha->host_no, pkt, pkt->handle1));
1290
1291 /* Validate handle. */
1292 if (pkt->handle1 < MAX_OUTSTANDING_COMMANDS)
1293 sp = ha->outstanding_cmds[pkt->handle1];
1294 else
1295 sp = NULL;
1296
1297 if (sp == NULL) {
1298 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1299 ha->host_no));
1300 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle\n");
1301
1302 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1303 return;
1304 }
1305
1306 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->status);
1307 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1308
1309 /* Free outstanding command slot. */
1310 ha->outstanding_cmds[pkt->handle1] = NULL;
1311
f4f051e2005-04-17 15:02:26 -05001312 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313}
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001314
1315
1316/**
1317 * qla24xx_mbx_completion() - Process mailbox command completions.
1318 * @ha: SCSI driver HA context
1319 * @mb0: Mailbox0 register
1320 */
1321static void
1322qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
1323{
1324 uint16_t cnt;
1325 uint16_t __iomem *wptr;
1326 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1327
1328 /* Load return mailbox registers. */
1329 ha->flags.mbox_int = 1;
1330 ha->mailbox_out[0] = mb0;
1331 wptr = (uint16_t __iomem *)&reg->mailbox1;
1332
1333 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1334 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1335 wptr++;
1336 }
1337
1338 if (ha->mcp) {
1339 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
1340 __func__, ha->host_no, ha->mcp->mb[0]));
1341 } else {
1342 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
1343 __func__, ha->host_no));
1344 }
1345}
1346
1347/**
1348 * qla24xx_process_response_queue() - Process response queue entries.
1349 * @ha: SCSI driver HA context
1350 */
1351void
1352qla24xx_process_response_queue(struct scsi_qla_host *ha)
1353{
1354 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1355 struct sts_entry_24xx *pkt;
1356
1357 if (!ha->flags.online)
1358 return;
1359
1360 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
1361 pkt = (struct sts_entry_24xx *)ha->response_ring_ptr;
1362
1363 ha->rsp_ring_index++;
1364 if (ha->rsp_ring_index == ha->response_q_length) {
1365 ha->rsp_ring_index = 0;
1366 ha->response_ring_ptr = ha->response_ring;
1367 } else {
1368 ha->response_ring_ptr++;
1369 }
1370
1371 if (pkt->entry_status != 0) {
1372 DEBUG3(printk(KERN_INFO
1373 "scsi(%ld): Process error entry.\n", ha->host_no));
1374
Andrew Vasquez9a853f72005-07-06 10:31:27 -07001375 qla2x00_error_entry(ha, (sts_entry_t *) pkt);
1376 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1377 wmb();
1378 continue;
1379 }
1380
1381 switch (pkt->entry_type) {
1382 case STATUS_TYPE:
1383 qla2x00_status_entry(ha, pkt);
1384 break;
1385 case STATUS_CONT_TYPE:
1386 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
1387 break;
1388 case MS_IOCB_TYPE:
1389 qla24xx_ms_entry(ha, (struct ct_entry_24xx *)pkt);
1390 break;
1391 default:
1392 /* Type Not Supported. */
1393 DEBUG4(printk(KERN_WARNING
1394 "scsi(%ld): Received unknown response pkt type %x "
1395 "entry status=%x.\n",
1396 ha->host_no, pkt->entry_type, pkt->entry_status));
1397 break;
1398 }
1399 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1400 wmb();
1401 }
1402
1403 /* Adjust ring index */
1404 WRT_REG_DWORD(&reg->rsp_q_out, ha->rsp_ring_index);
1405}
1406
1407/**
1408 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1409 * @irq:
1410 * @dev_id: SCSI driver HA context
1411 * @regs:
1412 *
1413 * Called by system whenever the host adapter generates an interrupt.
1414 *
1415 * Returns handled flag.
1416 */
1417irqreturn_t
1418qla24xx_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1419{
1420 scsi_qla_host_t *ha;
1421 struct device_reg_24xx __iomem *reg;
1422 int status;
1423 unsigned long flags;
1424 unsigned long iter;
1425 uint32_t stat;
1426 uint32_t hccr;
1427 uint16_t mb[4];
1428
1429 ha = (scsi_qla_host_t *) dev_id;
1430 if (!ha) {
1431 printk(KERN_INFO
1432 "%s(): NULL host pointer\n", __func__);
1433 return IRQ_NONE;
1434 }
1435
1436 reg = &ha->iobase->isp24;
1437 status = 0;
1438
1439 spin_lock_irqsave(&ha->hardware_lock, flags);
1440 for (iter = 50; iter--; ) {
1441 stat = RD_REG_DWORD(&reg->host_status);
1442 if (stat & HSRX_RISC_PAUSED) {
1443 hccr = RD_REG_DWORD(&reg->hccr);
1444
1445 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1446 "Dumping firmware!\n", hccr);
1447 qla24xx_fw_dump(ha, 1);
1448
1449 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1450 break;
1451 } else if ((stat & HSRX_RISC_INT) == 0)
1452 break;
1453
1454 switch (stat & 0xff) {
1455 case 0x1:
1456 case 0x2:
1457 case 0x10:
1458 case 0x11:
1459 qla24xx_mbx_completion(ha, MSW(stat));
1460 status |= MBX_INTERRUPT;
1461
1462 break;
1463 case 0x12:
1464 mb[0] = MSW(stat);
1465 mb[1] = RD_REG_WORD(&reg->mailbox1);
1466 mb[2] = RD_REG_WORD(&reg->mailbox2);
1467 mb[3] = RD_REG_WORD(&reg->mailbox3);
1468 qla2x00_async_event(ha, mb);
1469 break;
1470 case 0x13:
1471 qla24xx_process_response_queue(ha);
1472 break;
1473 default:
1474 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1475 "(%d).\n",
1476 ha->host_no, stat & 0xff));
1477 break;
1478 }
1479 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1480 RD_REG_DWORD_RELAXED(&reg->hccr);
1481 }
1482 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1483
1484 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1485 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1486 spin_lock_irqsave(&ha->mbx_reg_lock, flags);
1487
1488 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1489 up(&ha->mbx_intr_sem);
1490
1491 spin_unlock_irqrestore(&ha->mbx_reg_lock, flags);
1492 }
1493
1494 return IRQ_HANDLED;
1495}
1496
1497/**
1498 * qla24xx_ms_entry() - Process a Management Server entry.
1499 * @ha: SCSI driver HA context
1500 * @index: Response queue out pointer
1501 */
1502static void
1503qla24xx_ms_entry(scsi_qla_host_t *ha, struct ct_entry_24xx *pkt)
1504{
1505 srb_t *sp;
1506
1507 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1508 __func__, ha->host_no, pkt, pkt->handle));
1509
1510 DEBUG9(printk("%s: ct pkt dump:\n", __func__);)
1511 DEBUG9(qla2x00_dump_buffer((void *)pkt, sizeof(struct ct_entry_24xx));)
1512
1513 /* Validate handle. */
1514 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1515 sp = ha->outstanding_cmds[pkt->handle];
1516 else
1517 sp = NULL;
1518
1519 if (sp == NULL) {
1520 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1521 ha->host_no));
1522 DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n",
1523 ha->host_no));
1524 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle %d\n",
1525 pkt->handle);
1526
1527 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1528 return;
1529 }
1530
1531 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->comp_status);
1532 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1533
1534 /* Free outstanding command slot. */
1535 ha->outstanding_cmds[pkt->handle] = NULL;
1536
1537 qla2x00_sp_compl(ha, sp);
1538}
1539