Fix misspellings of "agressive".
[wrt350n-kernel.git] / drivers / scsi / qla2xxx / qla_isr.c
blobd4885616cd39c19077e72b2f083f563ec5cb2ad9
1 /*
2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
6 */
7 #include "qla_def.h"
9 #include <scsi/scsi_tcq.h>
11 static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
12 static void qla2x00_async_event(scsi_qla_host_t *, uint16_t *);
13 static void qla2x00_process_completed_request(struct scsi_qla_host *, uint32_t);
14 static void qla2x00_status_entry(scsi_qla_host_t *, void *);
15 static void qla2x00_status_cont_entry(scsi_qla_host_t *, sts_cont_entry_t *);
16 static void qla2x00_error_entry(scsi_qla_host_t *, sts_entry_t *);
17 static void qla2x00_ms_entry(scsi_qla_host_t *, ms_iocb_entry_t *);
19 static void qla24xx_ms_entry(scsi_qla_host_t *, struct ct_entry_24xx *);
21 /**
22 * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
23 * @irq:
24 * @dev_id: SCSI driver HA context
26 * Called by system whenever the host adapter generates an interrupt.
28 * Returns handled flag.
30 irqreturn_t
31 qla2100_intr_handler(int irq, void *dev_id)
33 scsi_qla_host_t *ha;
34 struct device_reg_2xxx __iomem *reg;
35 int status;
36 unsigned long flags;
37 unsigned long iter;
38 uint16_t mb[4];
40 ha = (scsi_qla_host_t *) dev_id;
41 if (!ha) {
42 printk(KERN_INFO
43 "%s(): NULL host pointer\n", __func__);
44 return (IRQ_NONE);
47 reg = &ha->iobase->isp;
48 status = 0;
50 spin_lock_irqsave(&ha->hardware_lock, flags);
51 for (iter = 50; iter--; ) {
52 if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
53 break;
55 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
56 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
57 RD_REG_WORD(&reg->hccr);
59 /* Get mailbox data. */
60 mb[0] = RD_MAILBOX_REG(ha, reg, 0);
61 if (mb[0] > 0x3fff && mb[0] < 0x8000) {
62 qla2x00_mbx_completion(ha, mb[0]);
63 status |= MBX_INTERRUPT;
64 } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
65 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
66 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
67 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
68 qla2x00_async_event(ha, mb);
69 } else {
70 /*EMPTY*/
71 DEBUG2(printk("scsi(%ld): Unrecognized "
72 "interrupt type (%d).\n",
73 ha->host_no, mb[0]));
75 /* Release mailbox registers. */
76 WRT_REG_WORD(&reg->semaphore, 0);
77 RD_REG_WORD(&reg->semaphore);
78 } else {
79 qla2x00_process_response_queue(ha);
81 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
82 RD_REG_WORD(&reg->hccr);
85 spin_unlock_irqrestore(&ha->hardware_lock, flags);
87 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
88 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
89 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
90 up(&ha->mbx_intr_sem);
93 return (IRQ_HANDLED);
96 /**
97 * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
98 * @irq:
99 * @dev_id: SCSI driver HA context
101 * Called by system whenever the host adapter generates an interrupt.
103 * Returns handled flag.
105 irqreturn_t
106 qla2300_intr_handler(int irq, void *dev_id)
108 scsi_qla_host_t *ha;
109 struct device_reg_2xxx __iomem *reg;
110 int status;
111 unsigned long flags;
112 unsigned long iter;
113 uint32_t stat;
114 uint16_t hccr;
115 uint16_t mb[4];
117 ha = (scsi_qla_host_t *) dev_id;
118 if (!ha) {
119 printk(KERN_INFO
120 "%s(): NULL host pointer\n", __func__);
121 return (IRQ_NONE);
124 reg = &ha->iobase->isp;
125 status = 0;
127 spin_lock_irqsave(&ha->hardware_lock, flags);
128 for (iter = 50; iter--; ) {
129 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
130 if (stat & HSR_RISC_PAUSED) {
131 hccr = RD_REG_WORD(&reg->hccr);
132 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
133 qla_printk(KERN_INFO, ha, "Parity error -- "
134 "HCCR=%x, Dumping firmware!\n", hccr);
135 else
136 qla_printk(KERN_INFO, ha, "RISC paused -- "
137 "HCCR=%x, Dumping firmware!\n", hccr);
140 * Issue a "HARD" reset in order for the RISC
141 * interrupt bit to be cleared. Schedule a big
142 * hammmer to get out of the RISC PAUSED state.
144 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
145 RD_REG_WORD(&reg->hccr);
147 ha->isp_ops.fw_dump(ha, 1);
148 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
149 break;
150 } else if ((stat & HSR_RISC_INT) == 0)
151 break;
153 switch (stat & 0xff) {
154 case 0x1:
155 case 0x2:
156 case 0x10:
157 case 0x11:
158 qla2x00_mbx_completion(ha, MSW(stat));
159 status |= MBX_INTERRUPT;
161 /* Release mailbox registers. */
162 WRT_REG_WORD(&reg->semaphore, 0);
163 break;
164 case 0x12:
165 mb[0] = MSW(stat);
166 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
167 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
168 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
169 qla2x00_async_event(ha, mb);
170 break;
171 case 0x13:
172 qla2x00_process_response_queue(ha);
173 break;
174 case 0x15:
175 mb[0] = MBA_CMPLT_1_16BIT;
176 mb[1] = MSW(stat);
177 qla2x00_async_event(ha, mb);
178 break;
179 case 0x16:
180 mb[0] = MBA_SCSI_COMPLETION;
181 mb[1] = MSW(stat);
182 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
183 qla2x00_async_event(ha, mb);
184 break;
185 default:
186 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
187 "(%d).\n",
188 ha->host_no, stat & 0xff));
189 break;
191 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
192 RD_REG_WORD_RELAXED(&reg->hccr);
194 spin_unlock_irqrestore(&ha->hardware_lock, flags);
196 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
197 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
198 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
199 up(&ha->mbx_intr_sem);
202 return (IRQ_HANDLED);
206 * qla2x00_mbx_completion() - Process mailbox command completions.
207 * @ha: SCSI driver HA context
208 * @mb0: Mailbox0 register
210 static void
211 qla2x00_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
213 uint16_t cnt;
214 uint16_t __iomem *wptr;
215 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
217 /* Load return mailbox registers. */
218 ha->flags.mbox_int = 1;
219 ha->mailbox_out[0] = mb0;
220 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
222 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
223 if (IS_QLA2200(ha) && cnt == 8)
224 wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
225 if (cnt == 4 || cnt == 5)
226 ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
227 else
228 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
230 wptr++;
233 if (ha->mcp) {
234 DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
235 __func__, ha->host_no, ha->mcp->mb[0]));
236 } else {
237 DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
238 __func__, ha->host_no));
243 * qla2x00_async_event() - Process aynchronous events.
244 * @ha: SCSI driver HA context
245 * @mb: Mailbox registers (0 - 3)
247 static void
248 qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
250 #define LS_UNKNOWN 2
251 static char *link_speeds[5] = { "1", "2", "?", "4", "10" };
252 char *link_speed;
253 uint16_t handle_cnt;
254 uint16_t cnt;
255 uint32_t handles[5];
256 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
257 uint32_t rscn_entry, host_pid;
258 uint8_t rscn_queue_index;
260 /* Setup to process RIO completion. */
261 handle_cnt = 0;
262 switch (mb[0]) {
263 case MBA_SCSI_COMPLETION:
264 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
265 handle_cnt = 1;
266 break;
267 case MBA_CMPLT_1_16BIT:
268 handles[0] = mb[1];
269 handle_cnt = 1;
270 mb[0] = MBA_SCSI_COMPLETION;
271 break;
272 case MBA_CMPLT_2_16BIT:
273 handles[0] = mb[1];
274 handles[1] = mb[2];
275 handle_cnt = 2;
276 mb[0] = MBA_SCSI_COMPLETION;
277 break;
278 case MBA_CMPLT_3_16BIT:
279 handles[0] = mb[1];
280 handles[1] = mb[2];
281 handles[2] = mb[3];
282 handle_cnt = 3;
283 mb[0] = MBA_SCSI_COMPLETION;
284 break;
285 case MBA_CMPLT_4_16BIT:
286 handles[0] = mb[1];
287 handles[1] = mb[2];
288 handles[2] = mb[3];
289 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
290 handle_cnt = 4;
291 mb[0] = MBA_SCSI_COMPLETION;
292 break;
293 case MBA_CMPLT_5_16BIT:
294 handles[0] = mb[1];
295 handles[1] = mb[2];
296 handles[2] = mb[3];
297 handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
298 handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
299 handle_cnt = 5;
300 mb[0] = MBA_SCSI_COMPLETION;
301 break;
302 case MBA_CMPLT_2_32BIT:
303 handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
304 handles[1] = le32_to_cpu(
305 ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
306 RD_MAILBOX_REG(ha, reg, 6));
307 handle_cnt = 2;
308 mb[0] = MBA_SCSI_COMPLETION;
309 break;
310 default:
311 break;
314 switch (mb[0]) {
315 case MBA_SCSI_COMPLETION: /* Fast Post */
316 if (!ha->flags.online)
317 break;
319 for (cnt = 0; cnt < handle_cnt; cnt++)
320 qla2x00_process_completed_request(ha, handles[cnt]);
321 break;
323 case MBA_RESET: /* Reset */
324 DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", ha->host_no));
326 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
327 break;
329 case MBA_SYSTEM_ERR: /* System Error */
330 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
331 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
332 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
334 qla_printk(KERN_INFO, ha,
335 "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
336 mb[1], mb[2], mb[3]);
338 ha->isp_ops.fw_dump(ha, 1);
340 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
341 if (mb[1] == 0 && mb[2] == 0) {
342 qla_printk(KERN_ERR, ha,
343 "Unrecoverable Hardware Error: adapter "
344 "marked OFFLINE!\n");
345 ha->flags.online = 0;
346 } else
347 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
348 } else if (mb[1] == 0) {
349 qla_printk(KERN_INFO, ha,
350 "Unrecoverable Hardware Error: adapter marked "
351 "OFFLINE!\n");
352 ha->flags.online = 0;
353 } else
354 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
355 break;
357 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
358 DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
359 ha->host_no));
360 qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
362 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
363 break;
365 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
366 DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
367 ha->host_no));
368 qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
370 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
371 break;
373 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
374 DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
375 ha->host_no));
376 break;
378 case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
379 DEBUG2(printk("scsi(%ld): LIP occured (%x).\n", ha->host_no,
380 mb[1]));
381 qla_printk(KERN_INFO, ha, "LIP occured (%x).\n", mb[1]);
383 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
384 atomic_set(&ha->loop_state, LOOP_DOWN);
385 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
386 qla2x00_mark_all_devices_lost(ha, 1);
389 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
391 ha->flags.management_server_logged_in = 0;
392 break;
394 case MBA_LOOP_UP: /* Loop Up Event */
395 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
396 link_speed = link_speeds[0];
397 ha->link_data_rate = PORT_SPEED_1GB;
398 } else {
399 link_speed = link_speeds[LS_UNKNOWN];
400 if (mb[1] < 5)
401 link_speed = link_speeds[mb[1]];
402 ha->link_data_rate = mb[1];
405 DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
406 ha->host_no, link_speed));
407 qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
408 link_speed);
410 ha->flags.management_server_logged_in = 0;
411 break;
413 case MBA_LOOP_DOWN: /* Loop Down Event */
414 DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN (%x).\n",
415 ha->host_no, mb[1]));
416 qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x).\n", mb[1]);
418 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
419 atomic_set(&ha->loop_state, LOOP_DOWN);
420 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
421 ha->device_flags |= DFLG_NO_CABLE;
422 qla2x00_mark_all_devices_lost(ha, 1);
425 ha->flags.management_server_logged_in = 0;
426 ha->link_data_rate = PORT_SPEED_UNKNOWN;
427 if (ql2xfdmienable)
428 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
429 break;
431 case MBA_LIP_RESET: /* LIP reset occurred */
432 DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
433 ha->host_no, mb[1]));
434 qla_printk(KERN_INFO, ha,
435 "LIP reset occured (%x).\n", mb[1]);
437 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
438 atomic_set(&ha->loop_state, LOOP_DOWN);
439 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
440 qla2x00_mark_all_devices_lost(ha, 1);
443 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
445 ha->operating_mode = LOOP;
446 ha->flags.management_server_logged_in = 0;
447 break;
449 case MBA_POINT_TO_POINT: /* Point-to-Point */
450 if (IS_QLA2100(ha))
451 break;
453 DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n",
454 ha->host_no));
457 * Until there's a transition from loop down to loop up, treat
458 * this as loop down only.
460 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
461 atomic_set(&ha->loop_state, LOOP_DOWN);
462 if (!atomic_read(&ha->loop_down_timer))
463 atomic_set(&ha->loop_down_timer,
464 LOOP_DOWN_TIME);
465 qla2x00_mark_all_devices_lost(ha, 1);
468 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
469 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
471 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
473 ha->flags.gpsc_supported = 1;
474 break;
476 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
477 if (IS_QLA2100(ha))
478 break;
480 DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
481 "received.\n",
482 ha->host_no));
483 qla_printk(KERN_INFO, ha,
484 "Configuration change detected: value=%x.\n", mb[1]);
486 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
487 atomic_set(&ha->loop_state, LOOP_DOWN);
488 if (!atomic_read(&ha->loop_down_timer))
489 atomic_set(&ha->loop_down_timer,
490 LOOP_DOWN_TIME);
491 qla2x00_mark_all_devices_lost(ha, 1);
494 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
495 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
496 break;
498 case MBA_PORT_UPDATE: /* Port database update */
500 * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET
501 * event etc. earlier indicating loop is down) then process
502 * it. Otherwise ignore it and Wait for RSCN to come in.
504 atomic_set(&ha->loop_down_timer, 0);
505 if (atomic_read(&ha->loop_state) != LOOP_DOWN &&
506 atomic_read(&ha->loop_state) != LOOP_DEAD) {
507 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
508 "ignored %04x/%04x/%04x.\n", ha->host_no, mb[1],
509 mb[2], mb[3]));
510 break;
513 DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
514 ha->host_no));
515 DEBUG(printk(KERN_INFO
516 "scsi(%ld): Port database changed %04x %04x %04x.\n",
517 ha->host_no, mb[1], mb[2], mb[3]));
520 * Mark all devices as missing so we will login again.
522 atomic_set(&ha->loop_state, LOOP_UP);
524 qla2x00_mark_all_devices_lost(ha, 1);
526 ha->flags.rscn_queue_overflow = 1;
528 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
529 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
530 break;
532 case MBA_RSCN_UPDATE: /* State Change Registration */
533 DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
534 ha->host_no));
535 DEBUG(printk(KERN_INFO
536 "scsi(%ld): RSCN database changed -- %04x %04x.\n",
537 ha->host_no, mb[1], mb[2]));
539 rscn_entry = (mb[1] << 16) | mb[2];
540 host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) |
541 ha->d_id.b.al_pa;
542 if (rscn_entry == host_pid) {
543 DEBUG(printk(KERN_INFO
544 "scsi(%ld): Ignoring RSCN update to local host "
545 "port ID (%06x)\n",
546 ha->host_no, host_pid));
547 break;
550 rscn_queue_index = ha->rscn_in_ptr + 1;
551 if (rscn_queue_index == MAX_RSCN_COUNT)
552 rscn_queue_index = 0;
553 if (rscn_queue_index != ha->rscn_out_ptr) {
554 ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry;
555 ha->rscn_in_ptr = rscn_queue_index;
556 } else {
557 ha->flags.rscn_queue_overflow = 1;
560 atomic_set(&ha->loop_state, LOOP_UPDATE);
561 atomic_set(&ha->loop_down_timer, 0);
562 ha->flags.management_server_logged_in = 0;
564 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
565 set_bit(RSCN_UPDATE, &ha->dpc_flags);
566 break;
568 /* case MBA_RIO_RESPONSE: */
569 case MBA_ZIO_RESPONSE:
570 DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n",
571 ha->host_no));
572 DEBUG(printk(KERN_INFO
573 "scsi(%ld): [R|Z]IO update completion.\n",
574 ha->host_no));
576 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
577 qla24xx_process_response_queue(ha);
578 else
579 qla2x00_process_response_queue(ha);
580 break;
582 case MBA_DISCARD_RND_FRAME:
583 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
584 "%04x.\n", ha->host_no, mb[1], mb[2], mb[3]));
585 break;
587 case MBA_TRACE_NOTIFICATION:
588 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
589 ha->host_no, mb[1], mb[2]));
590 break;
594 static void
595 qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
597 fc_port_t *fcport = data;
599 if (fcport->ha->max_q_depth <= sdev->queue_depth)
600 return;
602 if (sdev->ordered_tags)
603 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
604 sdev->queue_depth + 1);
605 else
606 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
607 sdev->queue_depth + 1);
609 fcport->last_ramp_up = jiffies;
611 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
612 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
613 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
614 sdev->queue_depth));
617 static void
618 qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
620 fc_port_t *fcport = data;
622 if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
623 return;
625 DEBUG2(qla_printk(KERN_INFO, fcport->ha,
626 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
627 fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
628 sdev->queue_depth));
631 static inline void
632 qla2x00_ramp_up_queue_depth(scsi_qla_host_t *ha, srb_t *sp)
634 fc_port_t *fcport;
635 struct scsi_device *sdev;
637 sdev = sp->cmd->device;
638 if (sdev->queue_depth >= ha->max_q_depth)
639 return;
641 fcport = sp->fcport;
642 if (time_before(jiffies,
643 fcport->last_ramp_up + ql2xqfullrampup * HZ))
644 return;
645 if (time_before(jiffies,
646 fcport->last_queue_full + ql2xqfullrampup * HZ))
647 return;
649 starget_for_each_device(sdev->sdev_target, fcport,
650 qla2x00_adjust_sdev_qdepth_up);
654 * qla2x00_process_completed_request() - Process a Fast Post response.
655 * @ha: SCSI driver HA context
656 * @index: SRB index
658 static void
659 qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
661 srb_t *sp;
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);
670 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
671 return;
674 sp = ha->outstanding_cmds[index];
675 if (sp) {
676 /* Free outstanding command slot. */
677 ha->outstanding_cmds[index] = NULL;
679 CMD_COMPL_STATUS(sp->cmd) = 0L;
680 CMD_SCSI_STATUS(sp->cmd) = 0L;
682 /* Save ISP completion status */
683 sp->cmd->result = DID_OK << 16;
685 qla2x00_ramp_up_queue_depth(ha, sp);
686 qla2x00_sp_compl(ha, sp);
687 } else {
688 DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
689 ha->host_no));
690 qla_printk(KERN_WARNING, ha,
691 "Invalid ISP SCSI completion handle\n");
693 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
698 * qla2x00_process_response_queue() - Process response queue entries.
699 * @ha: SCSI driver HA context
701 void
702 qla2x00_process_response_queue(struct scsi_qla_host *ha)
704 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
705 sts_entry_t *pkt;
706 uint16_t handle_cnt;
707 uint16_t cnt;
709 if (!ha->flags.online)
710 return;
712 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
713 pkt = (sts_entry_t *)ha->response_ring_ptr;
715 ha->rsp_ring_index++;
716 if (ha->rsp_ring_index == ha->response_q_length) {
717 ha->rsp_ring_index = 0;
718 ha->response_ring_ptr = ha->response_ring;
719 } else {
720 ha->response_ring_ptr++;
723 if (pkt->entry_status != 0) {
724 DEBUG3(printk(KERN_INFO
725 "scsi(%ld): Process error entry.\n", ha->host_no));
727 qla2x00_error_entry(ha, pkt);
728 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
729 wmb();
730 continue;
733 switch (pkt->entry_type) {
734 case STATUS_TYPE:
735 qla2x00_status_entry(ha, pkt);
736 break;
737 case STATUS_TYPE_21:
738 handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
739 for (cnt = 0; cnt < handle_cnt; cnt++) {
740 qla2x00_process_completed_request(ha,
741 ((sts21_entry_t *)pkt)->handle[cnt]);
743 break;
744 case STATUS_TYPE_22:
745 handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
746 for (cnt = 0; cnt < handle_cnt; cnt++) {
747 qla2x00_process_completed_request(ha,
748 ((sts22_entry_t *)pkt)->handle[cnt]);
750 break;
751 case STATUS_CONT_TYPE:
752 qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt);
753 break;
754 case MS_IOCB_TYPE:
755 qla2x00_ms_entry(ha, (ms_iocb_entry_t *)pkt);
756 break;
757 default:
758 /* Type Not Supported. */
759 DEBUG4(printk(KERN_WARNING
760 "scsi(%ld): Received unknown response pkt type %x "
761 "entry status=%x.\n",
762 ha->host_no, pkt->entry_type, pkt->entry_status));
763 break;
765 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
766 wmb();
769 /* Adjust ring index */
770 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index);
774 * qla2x00_status_entry() - Process a Status IOCB entry.
775 * @ha: SCSI driver HA context
776 * @pkt: Entry pointer
778 static void
779 qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
781 srb_t *sp;
782 fc_port_t *fcport;
783 struct scsi_cmnd *cp;
784 sts_entry_t *sts;
785 struct sts_entry_24xx *sts24;
786 uint16_t comp_status;
787 uint16_t scsi_status;
788 uint8_t lscsi_status;
789 int32_t resid;
790 uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
791 uint8_t *rsp_info, *sense_data;
793 sts = (sts_entry_t *) pkt;
794 sts24 = (struct sts_entry_24xx *) pkt;
795 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
796 comp_status = le16_to_cpu(sts24->comp_status);
797 scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
798 } else {
799 comp_status = le16_to_cpu(sts->comp_status);
800 scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
803 /* Fast path completion. */
804 if (comp_status == CS_COMPLETE && scsi_status == 0) {
805 qla2x00_process_completed_request(ha, sts->handle);
807 return;
810 /* Validate handle. */
811 if (sts->handle < MAX_OUTSTANDING_COMMANDS) {
812 sp = ha->outstanding_cmds[sts->handle];
813 ha->outstanding_cmds[sts->handle] = NULL;
814 } else
815 sp = NULL;
817 if (sp == NULL) {
818 DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
819 ha->host_no));
820 qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
822 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
823 qla2xxx_wake_dpc(ha);
824 return;
826 cp = sp->cmd;
827 if (cp == NULL) {
828 DEBUG2(printk("scsi(%ld): Command already returned back to OS "
829 "pkt->handle=%d sp=%p.\n", ha->host_no, sts->handle, sp));
830 qla_printk(KERN_WARNING, ha,
831 "Command is NULL: already returned to OS (sp=%p)\n", sp);
833 return;
836 lscsi_status = scsi_status & STATUS_MASK;
837 CMD_ENTRY_STATUS(cp) = sts->entry_status;
838 CMD_COMPL_STATUS(cp) = comp_status;
839 CMD_SCSI_STATUS(cp) = scsi_status;
841 fcport = sp->fcport;
843 sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
844 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
845 sense_len = le32_to_cpu(sts24->sense_len);
846 rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
847 resid_len = le32_to_cpu(sts24->rsp_residual_count);
848 fw_resid_len = le32_to_cpu(sts24->residual_len);
849 rsp_info = sts24->data;
850 sense_data = sts24->data;
851 host_to_fcp_swap(sts24->data, sizeof(sts24->data));
852 } else {
853 sense_len = le16_to_cpu(sts->req_sense_length);
854 rsp_info_len = le16_to_cpu(sts->rsp_info_len);
855 resid_len = le32_to_cpu(sts->residual_length);
856 rsp_info = sts->rsp_info;
857 sense_data = sts->req_sense_data;
860 /* Check for any FCP transport errors. */
861 if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
862 /* Sense data lies beyond any FCP RESPONSE data. */
863 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
864 sense_data += rsp_info_len;
865 if (rsp_info_len > 3 && rsp_info[3]) {
866 DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
867 "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
868 "retrying command\n", ha->host_no,
869 cp->device->channel, cp->device->id,
870 cp->device->lun, rsp_info_len, rsp_info[0],
871 rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
872 rsp_info[5], rsp_info[6], rsp_info[7]));
874 cp->result = DID_BUS_BUSY << 16;
875 qla2x00_sp_compl(ha, sp);
876 return;
881 * Based on Host and scsi status generate status code for Linux
883 switch (comp_status) {
884 case CS_COMPLETE:
885 case CS_QUEUE_FULL:
886 if (scsi_status == 0) {
887 cp->result = DID_OK << 16;
888 break;
890 if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
891 resid = resid_len;
892 cp->resid = resid;
893 CMD_RESID_LEN(cp) = resid;
895 if (!lscsi_status &&
896 ((unsigned)(cp->request_bufflen - resid) <
897 cp->underflow)) {
898 qla_printk(KERN_INFO, ha,
899 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
900 "detected (%x of %x bytes)...returning "
901 "error status.\n", ha->host_no,
902 cp->device->channel, cp->device->id,
903 cp->device->lun, resid,
904 cp->request_bufflen);
906 cp->result = DID_ERROR << 16;
907 break;
910 cp->result = DID_OK << 16 | lscsi_status;
912 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
913 DEBUG2(printk(KERN_INFO
914 "scsi(%ld): QUEUE FULL status detected "
915 "0x%x-0x%x.\n", ha->host_no, comp_status,
916 scsi_status));
918 /* Adjust queue depth for all luns on the port. */
919 fcport->last_queue_full = jiffies;
920 starget_for_each_device(cp->device->sdev_target,
921 fcport, qla2x00_adjust_sdev_qdepth_down);
922 break;
924 if (lscsi_status != SS_CHECK_CONDITION)
925 break;
927 /* Copy Sense Data into sense buffer. */
928 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
930 if (!(scsi_status & SS_SENSE_LEN_VALID))
931 break;
933 if (sense_len >= sizeof(cp->sense_buffer))
934 sense_len = sizeof(cp->sense_buffer);
936 CMD_ACTUAL_SNSLEN(cp) = sense_len;
937 sp->request_sense_length = sense_len;
938 sp->request_sense_ptr = cp->sense_buffer;
940 if (sp->request_sense_length > 32)
941 sense_len = 32;
943 memcpy(cp->sense_buffer, sense_data, sense_len);
945 sp->request_sense_ptr += sense_len;
946 sp->request_sense_length -= sense_len;
947 if (sp->request_sense_length != 0)
948 ha->status_srb = sp;
950 DEBUG5(printk("%s(): Check condition Sense data, "
951 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n", __func__,
952 ha->host_no, cp->device->channel, cp->device->id,
953 cp->device->lun, cp, cp->serial_number));
954 if (sense_len)
955 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
956 CMD_ACTUAL_SNSLEN(cp)));
957 break;
959 case CS_DATA_UNDERRUN:
960 resid = resid_len;
961 /* Use F/W calculated residual length. */
962 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
963 resid = fw_resid_len;
965 if (scsi_status & SS_RESIDUAL_UNDER) {
966 cp->resid = resid;
967 CMD_RESID_LEN(cp) = resid;
968 } else {
969 DEBUG2(printk(KERN_INFO
970 "scsi(%ld:%d:%d) UNDERRUN status detected "
971 "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
972 "os_underflow=0x%x\n", ha->host_no,
973 cp->device->id, cp->device->lun, comp_status,
974 scsi_status, resid_len, resid, cp->cmnd[0],
975 cp->underflow));
980 * Check to see if SCSI Status is non zero. If so report SCSI
981 * Status.
983 if (lscsi_status != 0) {
984 cp->result = DID_OK << 16 | lscsi_status;
986 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
987 DEBUG2(printk(KERN_INFO
988 "scsi(%ld): QUEUE FULL status detected "
989 "0x%x-0x%x.\n", ha->host_no, comp_status,
990 scsi_status));
993 * Adjust queue depth for all luns on the
994 * port.
996 fcport->last_queue_full = jiffies;
997 starget_for_each_device(
998 cp->device->sdev_target, fcport,
999 qla2x00_adjust_sdev_qdepth_down);
1000 break;
1002 if (lscsi_status != SS_CHECK_CONDITION)
1003 break;
1005 /* Copy Sense Data into sense buffer */
1006 memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer));
1008 if (!(scsi_status & SS_SENSE_LEN_VALID))
1009 break;
1011 if (sense_len >= sizeof(cp->sense_buffer))
1012 sense_len = sizeof(cp->sense_buffer);
1014 CMD_ACTUAL_SNSLEN(cp) = sense_len;
1015 sp->request_sense_length = sense_len;
1016 sp->request_sense_ptr = cp->sense_buffer;
1018 if (sp->request_sense_length > 32)
1019 sense_len = 32;
1021 memcpy(cp->sense_buffer, sense_data, sense_len);
1023 sp->request_sense_ptr += sense_len;
1024 sp->request_sense_length -= sense_len;
1025 if (sp->request_sense_length != 0)
1026 ha->status_srb = sp;
1028 DEBUG5(printk("%s(): Check condition Sense data, "
1029 "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n",
1030 __func__, ha->host_no, cp->device->channel,
1031 cp->device->id, cp->device->lun, cp,
1032 cp->serial_number));
1034 if (sense_len)
1035 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer,
1036 CMD_ACTUAL_SNSLEN(cp)));
1037 } else {
1039 * If RISC reports underrun and target does not report
1040 * it then we must have a lost frame, so tell upper
1041 * layer to retry it by reporting a bus busy.
1043 if (!(scsi_status & SS_RESIDUAL_UNDER)) {
1044 DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
1045 "frame(s) detected (%x of %x bytes)..."
1046 "retrying command.\n", ha->host_no,
1047 cp->device->channel, cp->device->id,
1048 cp->device->lun, resid,
1049 cp->request_bufflen));
1051 cp->result = DID_BUS_BUSY << 16;
1052 break;
1055 /* Handle mid-layer underflow */
1056 if ((unsigned)(cp->request_bufflen - resid) <
1057 cp->underflow) {
1058 qla_printk(KERN_INFO, ha,
1059 "scsi(%ld:%d:%d:%d): Mid-layer underflow "
1060 "detected (%x of %x bytes)...returning "
1061 "error status.\n", ha->host_no,
1062 cp->device->channel, cp->device->id,
1063 cp->device->lun, resid,
1064 cp->request_bufflen);
1066 cp->result = DID_ERROR << 16;
1067 break;
1070 /* Everybody online, looking good... */
1071 cp->result = DID_OK << 16;
1073 break;
1075 case CS_DATA_OVERRUN:
1076 DEBUG2(printk(KERN_INFO
1077 "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
1078 ha->host_no, cp->device->id, cp->device->lun, comp_status,
1079 scsi_status));
1080 DEBUG2(printk(KERN_INFO
1081 "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1082 cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
1083 cp->cmnd[4], cp->cmnd[5]));
1084 DEBUG2(printk(KERN_INFO
1085 "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
1086 "status!\n",
1087 cp->serial_number, cp->request_bufflen, resid_len));
1089 cp->result = DID_ERROR << 16;
1090 break;
1092 case CS_PORT_LOGGED_OUT:
1093 case CS_PORT_CONFIG_CHG:
1094 case CS_PORT_BUSY:
1095 case CS_INCOMPLETE:
1096 case CS_PORT_UNAVAILABLE:
1098 * If the port is in Target Down state, return all IOs for this
1099 * Target with DID_NO_CONNECT ELSE Queue the IOs in the
1100 * retry_queue.
1102 DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
1103 "pid=%ld, compl status=0x%x, port state=0x%x\n",
1104 ha->host_no, cp->device->id, cp->device->lun,
1105 cp->serial_number, comp_status,
1106 atomic_read(&fcport->state)));
1108 cp->result = DID_BUS_BUSY << 16;
1109 if (atomic_read(&fcport->state) == FCS_ONLINE) {
1110 qla2x00_mark_device_lost(ha, fcport, 1, 1);
1112 break;
1114 case CS_RESET:
1115 DEBUG2(printk(KERN_INFO
1116 "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
1117 ha->host_no, comp_status, scsi_status));
1119 cp->result = DID_RESET << 16;
1120 break;
1122 case CS_ABORTED:
1124 * hv2.19.12 - DID_ABORT does not retry the request if we
1125 * aborted this request then abort otherwise it must be a
1126 * reset.
1128 DEBUG2(printk(KERN_INFO
1129 "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
1130 ha->host_no, comp_status, scsi_status));
1132 cp->result = DID_RESET << 16;
1133 break;
1135 case CS_TIMEOUT:
1136 cp->result = DID_BUS_BUSY << 16;
1138 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
1139 DEBUG2(printk(KERN_INFO
1140 "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
1141 "0x%x-0x%x\n", ha->host_no, cp->device->channel,
1142 cp->device->id, cp->device->lun, comp_status,
1143 scsi_status));
1144 break;
1146 DEBUG2(printk(KERN_INFO
1147 "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
1148 "sflags=%x.\n", ha->host_no, cp->device->channel,
1149 cp->device->id, cp->device->lun, comp_status, scsi_status,
1150 le16_to_cpu(sts->status_flags)));
1152 /* Check to see if logout occurred. */
1153 if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
1154 qla2x00_mark_device_lost(ha, fcport, 1, 1);
1155 break;
1157 default:
1158 DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
1159 "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status));
1160 qla_printk(KERN_INFO, ha,
1161 "Unknown status detected 0x%x-0x%x.\n",
1162 comp_status, scsi_status);
1164 cp->result = DID_ERROR << 16;
1165 break;
1168 /* Place command on done queue. */
1169 if (ha->status_srb == NULL)
1170 qla2x00_sp_compl(ha, sp);
1174 * qla2x00_status_cont_entry() - Process a Status Continuations entry.
1175 * @ha: SCSI driver HA context
1176 * @pkt: Entry pointer
1178 * Extended sense data.
1180 static void
1181 qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt)
1183 uint8_t sense_sz = 0;
1184 srb_t *sp = ha->status_srb;
1185 struct scsi_cmnd *cp;
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 "
1191 "sp=%p.\n", __func__, sp));
1192 qla_printk(KERN_INFO, ha,
1193 "cmd is NULL: already returned to OS (sp=%p)\n",
1194 sp);
1196 ha->status_srb = NULL;
1197 return;
1200 if (sp->request_sense_length > sizeof(pkt->data)) {
1201 sense_sz = sizeof(pkt->data);
1202 } else {
1203 sense_sz = sp->request_sense_length;
1206 /* Move sense data. */
1207 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
1208 host_to_fcp_swap(pkt->data, sizeof(pkt->data));
1209 memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
1210 DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
1212 sp->request_sense_ptr += sense_sz;
1213 sp->request_sense_length -= sense_sz;
1215 /* Place command on done queue. */
1216 if (sp->request_sense_length == 0) {
1217 ha->status_srb = NULL;
1218 qla2x00_sp_compl(ha, sp);
1224 * qla2x00_error_entry() - Process an error entry.
1225 * @ha: SCSI driver HA context
1226 * @pkt: Entry pointer
1228 static void
1229 qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt)
1231 srb_t *sp;
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)
1239 qla_printk(KERN_ERR, ha,
1240 "%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
1249 /* Validate handle. */
1250 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1251 sp = ha->outstanding_cmds[pkt->handle];
1252 else
1253 sp = NULL;
1255 if (sp) {
1256 /* Free outstanding command slot. */
1257 ha->outstanding_cmds[pkt->handle] = NULL;
1259 /* 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;
1269 qla2x00_sp_compl(ha, sp);
1271 } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
1272 COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
1273 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");
1278 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1279 qla2xxx_wake_dpc(ha);
1284 * qla2x00_ms_entry() - Process a Management Server entry.
1285 * @ha: SCSI driver HA context
1286 * @index: Response queue out pointer
1288 static void
1289 qla2x00_ms_entry(scsi_qla_host_t *ha, ms_iocb_entry_t *pkt)
1291 srb_t *sp;
1293 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1294 __func__, ha->host_no, pkt, pkt->handle1));
1296 /* Validate handle. */
1297 if (pkt->handle1 < MAX_OUTSTANDING_COMMANDS)
1298 sp = ha->outstanding_cmds[pkt->handle1];
1299 else
1300 sp = NULL;
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");
1307 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1308 return;
1311 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->status);
1312 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1314 /* Free outstanding command slot. */
1315 ha->outstanding_cmds[pkt->handle1] = NULL;
1317 qla2x00_sp_compl(ha, sp);
1322 * qla24xx_mbx_completion() - Process mailbox command completions.
1323 * @ha: SCSI driver HA context
1324 * @mb0: Mailbox0 register
1326 static void
1327 qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0)
1329 uint16_t cnt;
1330 uint16_t __iomem *wptr;
1331 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1333 /* Load return mailbox registers. */
1334 ha->flags.mbox_int = 1;
1335 ha->mailbox_out[0] = mb0;
1336 wptr = (uint16_t __iomem *)&reg->mailbox1;
1338 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1339 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
1340 wptr++;
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));
1353 * qla24xx_process_response_queue() - Process response queue entries.
1354 * @ha: SCSI driver HA context
1356 void
1357 qla24xx_process_response_queue(struct scsi_qla_host *ha)
1359 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1360 struct sts_entry_24xx *pkt;
1362 if (!ha->flags.online)
1363 return;
1365 while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
1366 pkt = (struct sts_entry_24xx *)ha->response_ring_ptr;
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++;
1376 if (pkt->entry_status != 0) {
1377 DEBUG3(printk(KERN_INFO
1378 "scsi(%ld): Process error entry.\n", ha->host_no));
1380 qla2x00_error_entry(ha, (sts_entry_t *) pkt);
1381 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1382 wmb();
1383 continue;
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;
1404 ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
1405 wmb();
1408 /* Adjust ring index */
1409 WRT_REG_DWORD(&reg->rsp_q_out, ha->rsp_ring_index);
1413 * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
1414 * @irq:
1415 * @dev_id: SCSI driver HA context
1417 * Called by system whenever the host adapter generates an interrupt.
1419 * Returns handled flag.
1421 irqreturn_t
1422 qla24xx_intr_handler(int irq, void *dev_id)
1424 scsi_qla_host_t *ha;
1425 struct device_reg_24xx __iomem *reg;
1426 int status;
1427 unsigned long flags;
1428 unsigned long iter;
1429 uint32_t stat;
1430 uint32_t hccr;
1431 uint16_t mb[4];
1433 ha = (scsi_qla_host_t *) dev_id;
1434 if (!ha) {
1435 printk(KERN_INFO
1436 "%s(): NULL host pointer\n", __func__);
1437 return IRQ_NONE;
1440 reg = &ha->iobase->isp24;
1441 status = 0;
1443 spin_lock_irqsave(&ha->hardware_lock, flags);
1444 for (iter = 50; iter--; ) {
1445 stat = RD_REG_DWORD(&reg->host_status);
1446 if (stat & HSRX_RISC_PAUSED) {
1447 hccr = RD_REG_DWORD(&reg->hccr);
1449 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1450 "Dumping firmware!\n", hccr);
1451 ha->isp_ops.fw_dump(ha, 1);
1452 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1453 break;
1454 } else if ((stat & HSRX_RISC_INT) == 0)
1455 break;
1457 switch (stat & 0xff) {
1458 case 0x1:
1459 case 0x2:
1460 case 0x10:
1461 case 0x11:
1462 qla24xx_mbx_completion(ha, MSW(stat));
1463 status |= MBX_INTERRUPT;
1465 break;
1466 case 0x12:
1467 mb[0] = MSW(stat);
1468 mb[1] = RD_REG_WORD(&reg->mailbox1);
1469 mb[2] = RD_REG_WORD(&reg->mailbox2);
1470 mb[3] = RD_REG_WORD(&reg->mailbox3);
1471 qla2x00_async_event(ha, mb);
1472 break;
1473 case 0x13:
1474 qla24xx_process_response_queue(ha);
1475 break;
1476 default:
1477 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1478 "(%d).\n",
1479 ha->host_no, stat & 0xff));
1480 break;
1482 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1483 RD_REG_DWORD_RELAXED(&reg->hccr);
1485 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1487 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1488 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1489 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1490 up(&ha->mbx_intr_sem);
1493 return IRQ_HANDLED;
1497 * qla24xx_ms_entry() - Process a Management Server entry.
1498 * @ha: SCSI driver HA context
1499 * @index: Response queue out pointer
1501 static void
1502 qla24xx_ms_entry(scsi_qla_host_t *ha, struct ct_entry_24xx *pkt)
1504 srb_t *sp;
1506 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1507 __func__, ha->host_no, pkt, pkt->handle));
1509 DEBUG9(printk("%s: ct pkt dump:\n", __func__));
1510 DEBUG9(qla2x00_dump_buffer((void *)pkt, sizeof(struct ct_entry_24xx)));
1512 /* Validate handle. */
1513 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
1514 sp = ha->outstanding_cmds[pkt->handle];
1515 else
1516 sp = NULL;
1518 if (sp == NULL) {
1519 DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n",
1520 ha->host_no));
1521 DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n",
1522 ha->host_no));
1523 qla_printk(KERN_WARNING, ha, "MS entry - invalid handle %d\n",
1524 pkt->handle);
1526 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1527 return;
1530 CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->comp_status);
1531 CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status;
1533 /* Free outstanding command slot. */
1534 ha->outstanding_cmds[pkt->handle] = NULL;
1536 qla2x00_sp_compl(ha, sp);
1539 static irqreturn_t
1540 qla24xx_msix_rsp_q(int irq, void *dev_id)
1542 scsi_qla_host_t *ha;
1543 struct device_reg_24xx __iomem *reg;
1544 unsigned long flags;
1546 ha = dev_id;
1547 reg = &ha->iobase->isp24;
1549 spin_lock_irqsave(&ha->hardware_lock, flags);
1551 qla24xx_process_response_queue(ha);
1553 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1554 RD_REG_DWORD_RELAXED(&reg->hccr);
1556 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1558 return IRQ_HANDLED;
1561 static irqreturn_t
1562 qla24xx_msix_default(int irq, void *dev_id)
1564 scsi_qla_host_t *ha;
1565 struct device_reg_24xx __iomem *reg;
1566 int status;
1567 unsigned long flags;
1568 unsigned long iter;
1569 uint32_t stat;
1570 uint32_t hccr;
1571 uint16_t mb[4];
1573 ha = dev_id;
1574 reg = &ha->iobase->isp24;
1575 status = 0;
1577 spin_lock_irqsave(&ha->hardware_lock, flags);
1578 for (iter = 50; iter--; ) {
1579 stat = RD_REG_DWORD(&reg->host_status);
1580 if (stat & HSRX_RISC_PAUSED) {
1581 hccr = RD_REG_DWORD(&reg->hccr);
1583 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1584 "Dumping firmware!\n", hccr);
1585 ha->isp_ops.fw_dump(ha, 1);
1586 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1587 break;
1588 } else if ((stat & HSRX_RISC_INT) == 0)
1589 break;
1591 switch (stat & 0xff) {
1592 case 0x1:
1593 case 0x2:
1594 case 0x10:
1595 case 0x11:
1596 qla24xx_mbx_completion(ha, MSW(stat));
1597 status |= MBX_INTERRUPT;
1599 break;
1600 case 0x12:
1601 mb[0] = MSW(stat);
1602 mb[1] = RD_REG_WORD(&reg->mailbox1);
1603 mb[2] = RD_REG_WORD(&reg->mailbox2);
1604 mb[3] = RD_REG_WORD(&reg->mailbox3);
1605 qla2x00_async_event(ha, mb);
1606 break;
1607 case 0x13:
1608 qla24xx_process_response_queue(ha);
1609 break;
1610 default:
1611 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1612 "(%d).\n",
1613 ha->host_no, stat & 0xff));
1614 break;
1616 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1617 RD_REG_DWORD_RELAXED(&reg->hccr);
1619 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1621 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1622 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1623 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1624 up(&ha->mbx_intr_sem);
1627 return IRQ_HANDLED;
1630 /* Interrupt handling helpers. */
1632 struct qla_init_msix_entry {
1633 uint16_t entry;
1634 uint16_t index;
1635 const char *name;
1636 irqreturn_t (*handler)(int, void *);
1639 static struct qla_init_msix_entry imsix_entries[QLA_MSIX_ENTRIES] = {
1640 { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT,
1641 "qla2xxx (default)", qla24xx_msix_default },
1643 { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q,
1644 "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
1647 static void
1648 qla24xx_disable_msix(scsi_qla_host_t *ha)
1650 int i;
1651 struct qla_msix_entry *qentry;
1653 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1654 qentry = &ha->msix_entries[imsix_entries[i].index];
1655 if (qentry->have_irq)
1656 free_irq(qentry->msix_vector, ha);
1658 pci_disable_msix(ha->pdev);
1661 static int
1662 qla24xx_enable_msix(scsi_qla_host_t *ha)
1664 int i, ret;
1665 struct msix_entry entries[QLA_MSIX_ENTRIES];
1666 struct qla_msix_entry *qentry;
1668 for (i = 0; i < QLA_MSIX_ENTRIES; i++)
1669 entries[i].entry = imsix_entries[i].entry;
1671 ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries));
1672 if (ret) {
1673 qla_printk(KERN_WARNING, ha,
1674 "MSI-X: Failed to enable support -- %d/%d\n",
1675 QLA_MSIX_ENTRIES, ret);
1676 goto msix_out;
1678 ha->flags.msix_enabled = 1;
1680 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1681 qentry = &ha->msix_entries[imsix_entries[i].index];
1682 qentry->msix_vector = entries[i].vector;
1683 qentry->msix_entry = entries[i].entry;
1684 qentry->have_irq = 0;
1685 ret = request_irq(qentry->msix_vector,
1686 imsix_entries[i].handler, 0, imsix_entries[i].name, ha);
1687 if (ret) {
1688 qla_printk(KERN_WARNING, ha,
1689 "MSI-X: Unable to register handler -- %x/%d.\n",
1690 imsix_entries[i].index, ret);
1691 qla24xx_disable_msix(ha);
1692 goto msix_out;
1694 qentry->have_irq = 1;
1697 msix_out:
1698 return ret;
1702 qla2x00_request_irqs(scsi_qla_host_t *ha)
1704 int ret;
1706 /* If possible, enable MSI-X. */
1707 if (!IS_QLA2432(ha))
1708 goto skip_msix;
1710 if (ha->chip_revision < QLA_MSIX_CHIP_REV_24XX ||
1711 !QLA_MSIX_FW_MODE_1(ha->fw_attributes)) {
1712 DEBUG2(qla_printk(KERN_WARNING, ha,
1713 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1714 ha->chip_revision, ha->fw_attributes));
1716 goto skip_msix;
1719 ret = qla24xx_enable_msix(ha);
1720 if (!ret) {
1721 DEBUG2(qla_printk(KERN_INFO, ha,
1722 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1723 ha->fw_attributes));
1724 return ret;
1726 qla_printk(KERN_WARNING, ha,
1727 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1728 skip_msix:
1729 ret = request_irq(ha->pdev->irq, ha->isp_ops.intr_handler,
1730 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
1731 if (!ret) {
1732 ha->flags.inta_enabled = 1;
1733 ha->host->irq = ha->pdev->irq;
1734 } else {
1735 qla_printk(KERN_WARNING, ha,
1736 "Failed to reserve interrupt %d already in use.\n",
1737 ha->pdev->irq);
1740 return ret;
1743 void
1744 qla2x00_free_irqs(scsi_qla_host_t *ha)
1747 if (ha->flags.msix_enabled)
1748 qla24xx_disable_msix(ha);
1749 else if (ha->flags.inta_enabled)
1750 free_irq(ha->host->irq, ha);