2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <scsi/scsi_transport_fc.h>
12 * IO descriptor handle definitions.
16 * |31------28|27-------------------12|11-------0|
17 * | Type | Rolling Signature | Index |
18 * |----------|-----------------------|----------|
22 #define HDL_TYPE_SCSI 0
23 #define HDL_TYPE_ASYNC_IOCB 0x0A
25 #define HDL_INDEX_BITS 12
26 #define HDL_ITER_BITS 16
27 #define HDL_TYPE_BITS 4
29 #define HDL_INDEX_MASK ((1UL << HDL_INDEX_BITS) - 1)
30 #define HDL_ITER_MASK ((1UL << HDL_ITER_BITS) - 1)
31 #define HDL_TYPE_MASK ((1UL << HDL_TYPE_BITS) - 1)
33 #define HDL_INDEX_SHIFT 0
34 #define HDL_ITER_SHIFT (HDL_INDEX_SHIFT + HDL_INDEX_BITS)
35 #define HDL_TYPE_SHIFT (HDL_ITER_SHIFT + HDL_ITER_BITS)
37 /* Local Prototypes. */
38 static inline uint32_t qla2x00_to_handle(uint16_t, uint16_t, uint16_t);
39 static inline uint16_t qla2x00_handle_to_idx(uint32_t);
40 static inline uint32_t qla2x00_iodesc_to_handle(struct io_descriptor *);
41 static inline struct io_descriptor *qla2x00_handle_to_iodesc(scsi_qla_host_t *,
44 static inline struct io_descriptor *qla2x00_alloc_iodesc(scsi_qla_host_t *);
45 static inline void qla2x00_free_iodesc(struct io_descriptor *);
46 static inline void qla2x00_init_io_descriptors(scsi_qla_host_t *);
48 static void qla2x00_iodesc_timeout(unsigned long);
49 static inline void qla2x00_add_iodesc_timer(struct io_descriptor *);
50 static inline void qla2x00_remove_iodesc_timer(struct io_descriptor *);
52 static inline void qla2x00_update_login_fcport(scsi_qla_host_t *,
53 struct mbx_entry *, fc_port_t *);
55 static int qla2x00_send_abort_iocb(scsi_qla_host_t *, struct io_descriptor *,
57 static int qla2x00_send_abort_iocb_cb(scsi_qla_host_t *, struct io_descriptor *,
60 static int qla2x00_send_adisc_iocb(scsi_qla_host_t *, struct io_descriptor *,
62 static int qla2x00_send_adisc_iocb_cb(scsi_qla_host_t *, struct io_descriptor *,
65 static int qla2x00_send_logout_iocb(scsi_qla_host_t *, struct io_descriptor *,
67 static int qla2x00_send_logout_iocb_cb(scsi_qla_host_t *,
68 struct io_descriptor *, struct mbx_entry *);
70 static int qla2x00_send_login_iocb(scsi_qla_host_t *, struct io_descriptor *,
72 static int qla2x00_send_login_iocb_cb(scsi_qla_host_t *, struct io_descriptor *,
76 * Mailbox IOCB callback array.
78 static int (*iocb_function_cb_list[LAST_IOCB_CB])
79 (scsi_qla_host_t *, struct io_descriptor *, struct mbx_entry *) = {
81 qla2x00_send_abort_iocb_cb,
82 qla2x00_send_adisc_iocb_cb,
83 qla2x00_send_logout_iocb_cb,
84 qla2x00_send_login_iocb_cb,
89 * Generic IO descriptor handle routines.
93 * qla2x00_to_handle() - Create a descriptor handle.
94 * @type: descriptor type
95 * @iter: descriptor rolling signature
96 * @idx: index to the descriptor array
98 * Returns a composite handle based in the @type, @iter, and @idx.
100 static inline uint32_t
101 qla2x00_to_handle(uint16_t type, uint16_t iter, uint16_t idx)
103 return ((uint32_t)(((uint32_t)type << HDL_TYPE_SHIFT) |
104 ((uint32_t)iter << HDL_ITER_SHIFT) |
105 ((uint32_t)idx << HDL_INDEX_SHIFT)));
109 * qla2x00_handle_to_idx() - Retrive the index for a given handle.
110 * @handle: descriptor handle
112 * Returns the index specified by the @handle.
114 static inline uint16_t
115 qla2x00_handle_to_idx(uint32_t handle)
117 return ((uint16_t)(((handle) >> HDL_INDEX_SHIFT) & HDL_INDEX_MASK));
121 * qla2x00_iodesc_to_handle() - Convert an IO descriptor to a unique handle.
122 * @iodesc: io descriptor
124 * Returns a unique handle for @iodesc.
126 static inline uint32_t
127 qla2x00_iodesc_to_handle(struct io_descriptor *iodesc)
131 handle = qla2x00_to_handle(HDL_TYPE_ASYNC_IOCB,
132 ++iodesc->ha->iodesc_signature, iodesc->idx);
133 iodesc->signature = handle;
139 * qla2x00_handle_to_iodesc() - Retrieve an IO descriptor given a unique handle.
141 * @handle: handle to io descriptor
143 * Returns a pointer to the io descriptor, or NULL, if the io descriptor does
144 * not exist or the io descriptors signature does not @handle.
146 static inline struct io_descriptor *
147 qla2x00_handle_to_iodesc(scsi_qla_host_t *ha, uint32_t handle)
150 struct io_descriptor *iodesc;
152 idx = qla2x00_handle_to_idx(handle);
153 iodesc = &ha->io_descriptors[idx];
155 if (iodesc->signature != handle)
163 * IO descriptor allocation routines.
167 * qla2x00_alloc_iodesc() - Allocate an IO descriptor from the pool.
170 * Returns a pointer to the allocated io descriptor, or NULL, if none available.
172 static inline struct io_descriptor *
173 qla2x00_alloc_iodesc(scsi_qla_host_t *ha)
176 struct io_descriptor *iodesc;
179 for (iter = 0; iter < MAX_IO_DESCRIPTORS; iter++) {
180 if (ha->io_descriptors[iter].used)
183 iodesc = &ha->io_descriptors[iter];
186 init_timer(&iodesc->timer);
188 iodesc->signature = qla2x00_iodesc_to_handle(iodesc);
196 * qla2x00_free_iodesc() - Free an IO descriptor.
197 * @iodesc: io descriptor
199 * NOTE: The io descriptors timer *must* be stopped before it can be free'd.
202 qla2x00_free_iodesc(struct io_descriptor *iodesc)
205 iodesc->signature = 0;
209 * qla2x00_remove_iodesc_timer() - Remove an active timer from an IO descriptor.
210 * @iodesc: io descriptor
213 qla2x00_remove_iodesc_timer(struct io_descriptor *iodesc)
215 if (iodesc->timer.function != NULL) {
216 del_timer_sync(&iodesc->timer);
217 iodesc->timer.data = (unsigned long) NULL;
218 iodesc->timer.function = NULL;
223 * qla2x00_init_io_descriptors() - Initialize the pool of IO descriptors.
227 qla2x00_init_io_descriptors(scsi_qla_host_t *ha)
231 for (iter = 0; iter < MAX_IO_DESCRIPTORS; iter++) {
232 if (!ha->io_descriptors[iter].used)
235 qla2x00_remove_iodesc_timer(&ha->io_descriptors[iter]);
236 qla2x00_free_iodesc(&ha->io_descriptors[iter]);
242 * IO descriptor timer routines.
246 * qla2x00_iodesc_timeout() - Timeout IO descriptor handler.
247 * @data: io descriptor
250 qla2x00_iodesc_timeout(unsigned long data)
252 struct io_descriptor *iodesc;
254 iodesc = (struct io_descriptor *) data;
256 DEBUG14(printk("scsi(%ld): IO descriptor timeout, index=%x "
257 "signature=%08x, scheduling ISP abort.\n", iodesc->ha->host_no,
258 iodesc->idx, iodesc->signature));
260 qla2x00_free_iodesc(iodesc);
262 qla_printk(KERN_WARNING, iodesc->ha,
263 "IO descriptor timeout. Scheduling ISP abort.\n");
264 set_bit(ISP_ABORT_NEEDED, &iodesc->ha->dpc_flags);
268 * qla2x00_add_iodesc_timer() - Add and start a timer for an IO descriptor.
269 * @iodesc: io descriptor
272 * The firmware shall timeout an outstanding mailbox IOCB in 2 * R_A_TOV (in
273 * tenths of a second) after it hits the wire. But, if there are any request
274 * resource contraints (i.e. during heavy I/O), exchanges can be held off for
275 * at most R_A_TOV. Therefore, the driver will wait 4 * R_A_TOV before
276 * scheduling a recovery (big hammer).
279 qla2x00_add_iodesc_timer(struct io_descriptor *iodesc)
281 unsigned long timeout;
283 timeout = (iodesc->ha->r_a_tov * 4) / 10;
284 init_timer(&iodesc->timer);
285 iodesc->timer.data = (unsigned long) iodesc;
286 iodesc->timer.expires = jiffies + (timeout * HZ);
287 iodesc->timer.function =
288 (void (*) (unsigned long)) qla2x00_iodesc_timeout;
289 add_timer(&iodesc->timer);
293 * IO descriptor support routines.
297 * qla2x00_update_login_fcport() - Update fcport data after login processing.
299 * @mbxstat: Mailbox command status IOCB
300 * @fcport: port to update
303 qla2x00_update_login_fcport(scsi_qla_host_t *ha, struct mbx_entry *mbxstat,
306 if (le16_to_cpu(mbxstat->mb1) & BIT_0) {
307 fcport->port_type = FCT_INITIATOR;
309 fcport->port_type = FCT_TARGET;
310 if (le16_to_cpu(mbxstat->mb1) & BIT_1) {
311 fcport->flags |= FCF_TAPE_PRESENT;
314 fcport->login_retry = 0;
315 fcport->port_login_retry_count = ha->port_down_retry_count *
317 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
319 fcport->flags |= FCF_FABRIC_DEVICE;
320 fcport->flags &= ~FCF_FAILOVER_NEEDED;
321 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
322 atomic_set(&fcport->state, FCS_ONLINE);
324 fc_remote_port_unblock(fcport->rport);
329 * Mailbox IOCB commands.
333 * qla2x00_get_mbx_iocb_entry() - Retrieve an IOCB from the request queue.
335 * @handle: handle to io descriptor
337 * Returns a pointer to the reqest entry, or NULL, if none were available.
339 static inline struct mbx_entry *
340 qla2x00_get_mbx_iocb_entry(scsi_qla_host_t *ha, uint32_t handle)
343 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
344 struct mbx_entry *mbxentry;
348 if (ha->req_q_cnt < 3) {
349 cnt = qla2x00_debounce_register(ISP_REQ_Q_OUT(ha, reg));
350 if (ha->req_ring_index < cnt)
351 ha->req_q_cnt = cnt - ha->req_ring_index;
353 ha->req_q_cnt = ha->request_q_length -
354 (ha->req_ring_index - cnt);
356 if (ha->req_q_cnt >= 3) {
357 mbxentry = (struct mbx_entry *)ha->request_ring_ptr;
359 memset(mbxentry, 0, sizeof(struct mbx_entry));
360 mbxentry->entry_type = MBX_IOCB_TYPE;
361 mbxentry->entry_count = 1;
362 mbxentry->sys_define1 = SOURCE_ASYNC_IOCB;
363 mbxentry->handle = handle;
369 * qla2x00_send_abort_iocb() - Issue an abort IOCB to the firmware.
371 * @iodesc: io descriptor
372 * @handle_to_abort: firmware handle to abort
373 * @ha_locked: is function called with the hardware lock
375 * Returns QLA_SUCCESS if the IOCB was issued.
378 qla2x00_send_abort_iocb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
379 uint32_t handle_to_abort, int ha_locked)
381 unsigned long flags = 0;
382 struct mbx_entry *mbxentry;
384 /* Send marker if required. */
385 if (qla2x00_issue_marker(ha, ha_locked) != QLA_SUCCESS)
386 return (QLA_FUNCTION_FAILED);
389 spin_lock_irqsave(&ha->hardware_lock, flags);
391 /* Build abort mailbox IOCB. */
392 mbxentry = qla2x00_get_mbx_iocb_entry(ha, iodesc->signature);
393 if (mbxentry == NULL) {
395 spin_unlock_irqrestore(&ha->hardware_lock, flags);
397 return (QLA_FUNCTION_FAILED);
399 mbxentry->mb0 = __constant_cpu_to_le16(MBC_ABORT_COMMAND);
400 mbxentry->mb1 = mbxentry->loop_id.extended =
401 cpu_to_le16(iodesc->remote_fcport->loop_id);
402 mbxentry->mb2 = LSW(handle_to_abort);
403 mbxentry->mb3 = MSW(handle_to_abort);
406 qla2x00_add_iodesc_timer(iodesc);
408 /* Issue command to ISP. */
412 spin_unlock_irqrestore(&ha->hardware_lock, flags);
414 DEBUG14(printk("scsi(%ld): Sending Abort IOCB (%08x) to [%x], aborting "
415 "%08x.\n", ha->host_no, iodesc->signature,
416 iodesc->remote_fcport->loop_id, handle_to_abort));
418 return (QLA_SUCCESS);
422 * qla2x00_send_abort_iocb_cb() - Abort IOCB callback.
424 * @iodesc: io descriptor
425 * @mbxstat: mailbox status IOCB
427 * Returns QLA_SUCCESS if @iodesc can be freed by the caller, else, @iodesc
428 * will be used for a retry.
431 qla2x00_send_abort_iocb_cb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
432 struct mbx_entry *mbxstat)
434 DEBUG14(printk("scsi(%ld): Abort IOCB -- sent to [%x/%02x%02x%02x], "
435 "status=%x mb0=%x.\n", ha->host_no, iodesc->remote_fcport->loop_id,
436 iodesc->d_id.b.domain, iodesc->d_id.b.area, iodesc->d_id.b.al_pa,
437 le16_to_cpu(mbxstat->status), le16_to_cpu(mbxstat->mb0)));
439 return (QLA_SUCCESS);
444 * qla2x00_send_adisc_iocb() - Issue a Get Port Database IOCB to the firmware.
446 * @iodesc: io descriptor
447 * @ha_locked: is function called with the hardware lock
449 * Returns QLA_SUCCESS if the IOCB was issued.
452 qla2x00_send_adisc_iocb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
455 unsigned long flags = 0;
456 struct mbx_entry *mbxentry;
458 /* Send marker if required. */
459 if (qla2x00_issue_marker(ha, ha_locked) != QLA_SUCCESS)
460 return (QLA_FUNCTION_FAILED);
463 spin_lock_irqsave(&ha->hardware_lock, flags);
465 /* Build Get Port Database IOCB. */
466 mbxentry = qla2x00_get_mbx_iocb_entry(ha, iodesc->signature);
467 if (mbxentry == NULL) {
469 spin_unlock_irqrestore(&ha->hardware_lock, flags);
471 return (QLA_FUNCTION_FAILED);
473 mbxentry->mb0 = __constant_cpu_to_le16(MBC_GET_PORT_DATABASE);
474 mbxentry->mb1 = mbxentry->loop_id.extended =
475 cpu_to_le16(iodesc->remote_fcport->loop_id);
476 mbxentry->mb2 = cpu_to_le16(MSW(LSD(ha->iodesc_pd_dma)));
477 mbxentry->mb3 = cpu_to_le16(LSW(LSD(ha->iodesc_pd_dma)));
478 mbxentry->mb6 = cpu_to_le16(MSW(MSD(ha->iodesc_pd_dma)));
479 mbxentry->mb7 = cpu_to_le16(LSW(MSD(ha->iodesc_pd_dma)));
480 mbxentry->mb10 = __constant_cpu_to_le16(BIT_0);
483 qla2x00_add_iodesc_timer(iodesc);
485 /* Issue command to ISP. */
489 spin_unlock_irqrestore(&ha->hardware_lock, flags);
491 DEBUG14(printk("scsi(%ld): Sending Adisc IOCB (%08x) to [%x].\n",
492 ha->host_no, iodesc->signature, iodesc->remote_fcport->loop_id));
494 return (QLA_SUCCESS);
498 * qla2x00_send_adisc_iocb_cb() - Get Port Database IOCB callback.
500 * @iodesc: io descriptor
501 * @mbxstat: mailbox status IOCB
503 * Returns QLA_SUCCESS if @iodesc can be freed by the caller, else, @iodesc
504 * will be used for a retry.
507 qla2x00_send_adisc_iocb_cb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
508 struct mbx_entry *mbxstat)
510 fc_port_t *remote_fcport;
512 remote_fcport = iodesc->remote_fcport;
514 /* Ensure the port IDs are consistent. */
515 if (remote_fcport->d_id.b24 != iodesc->d_id.b24) {
516 DEBUG14(printk("scsi(%ld): Adisc IOCB -- ignoring, remote port "
517 "id changed from [%02x%02x%02x] to [%02x%02x%02x].\n",
518 ha->host_no, remote_fcport->d_id.b.domain,
519 remote_fcport->d_id.b.area, remote_fcport->d_id.b.al_pa,
520 iodesc->d_id.b.domain, iodesc->d_id.b.area,
521 iodesc->d_id.b.al_pa));
523 return (QLA_SUCCESS);
526 /* Only process the last command. */
527 if (remote_fcport->iodesc_idx_sent != iodesc->idx) {
528 DEBUG14(printk("scsi(%ld): Adisc IOCB -- ignoring, sent to "
529 "[%02x%02x%02x], expected %x, received %x.\n", ha->host_no,
530 iodesc->d_id.b.domain, iodesc->d_id.b.area,
531 iodesc->d_id.b.al_pa, remote_fcport->iodesc_idx_sent,
534 return (QLA_SUCCESS);
537 if (le16_to_cpu(mbxstat->status) == CS_COMPLETE) {
538 DEBUG14(printk("scsi(%ld): Adisc IOCB -- marking "
539 "[%x/%02x%02x%02x] online.\n", ha->host_no,
540 remote_fcport->loop_id, remote_fcport->d_id.b.domain,
541 remote_fcport->d_id.b.area, remote_fcport->d_id.b.al_pa));
543 atomic_set(&remote_fcport->state, FCS_ONLINE);
545 DEBUG14(printk("scsi(%ld): Adisc IOCB -- marking "
546 "[%x/%02x%02x%02x] lost, status=%x mb0=%x.\n", ha->host_no,
547 remote_fcport->loop_id, remote_fcport->d_id.b.domain,
548 remote_fcport->d_id.b.area, remote_fcport->d_id.b.al_pa,
549 le16_to_cpu(mbxstat->status), le16_to_cpu(mbxstat->mb0)));
551 if (atomic_read(&remote_fcport->state) != FCS_DEVICE_DEAD)
552 atomic_set(&remote_fcport->state, FCS_DEVICE_LOST);
554 remote_fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
556 return (QLA_SUCCESS);
561 * qla2x00_send_logout_iocb() - Issue a fabric port logout IOCB to the firmware.
563 * @iodesc: io descriptor
564 * @ha_locked: is function called with the hardware lock
566 * Returns QLA_SUCCESS if the IOCB was issued.
569 qla2x00_send_logout_iocb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
572 unsigned long flags = 0;
573 struct mbx_entry *mbxentry;
575 /* Send marker if required. */
576 if (qla2x00_issue_marker(ha, ha_locked) != QLA_SUCCESS)
577 return (QLA_FUNCTION_FAILED);
580 spin_lock_irqsave(&ha->hardware_lock, flags);
582 /* Build fabric port logout mailbox IOCB. */
583 mbxentry = qla2x00_get_mbx_iocb_entry(ha, iodesc->signature);
584 if (mbxentry == NULL) {
586 spin_unlock_irqrestore(&ha->hardware_lock, flags);
588 return (QLA_FUNCTION_FAILED);
590 mbxentry->mb0 = __constant_cpu_to_le16(MBC_LOGOUT_FABRIC_PORT);
591 mbxentry->mb1 = mbxentry->loop_id.extended =
592 cpu_to_le16(iodesc->remote_fcport->loop_id);
595 qla2x00_add_iodesc_timer(iodesc);
597 /* Issue command to ISP. */
601 spin_unlock_irqrestore(&ha->hardware_lock, flags);
603 DEBUG14(printk("scsi(%ld): Sending Logout IOCB (%08x) to [%x].\n",
604 ha->host_no, iodesc->signature, iodesc->remote_fcport->loop_id));
606 return (QLA_SUCCESS);
610 * qla2x00_send_logout_iocb_cb() - Fabric port logout IOCB callback.
612 * @iodesc: io descriptor
613 * @mbxstat: mailbox status IOCB
615 * Returns QLA_SUCCESS if @iodesc can be freed by the caller, else, @iodesc
616 * will be used for a retry.
619 qla2x00_send_logout_iocb_cb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
620 struct mbx_entry *mbxstat)
622 DEBUG14(printk("scsi(%ld): Logout IOCB -- sent to [%x/%02x%02x%02x], "
623 "status=%x mb0=%x mb1=%x.\n", ha->host_no,
624 iodesc->remote_fcport->loop_id,
625 iodesc->remote_fcport->d_id.b.domain,
626 iodesc->remote_fcport->d_id.b.area,
627 iodesc->remote_fcport->d_id.b.al_pa, le16_to_cpu(mbxstat->status),
628 le16_to_cpu(mbxstat->mb0), le16_to_cpu(mbxstat->mb1)));
630 return (QLA_SUCCESS);
635 * qla2x00_send_login_iocb() - Issue a fabric port login IOCB to the firmware.
637 * @iodesc: io descriptor
638 * @d_id: port id for device
639 * @ha_locked: is function called with the hardware lock
641 * Returns QLA_SUCCESS if the IOCB was issued.
644 qla2x00_send_login_iocb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
645 port_id_t *d_id, int ha_locked)
647 unsigned long flags = 0;
648 struct mbx_entry *mbxentry;
650 /* Send marker if required. */
651 if (qla2x00_issue_marker(ha, ha_locked) != QLA_SUCCESS)
652 return (QLA_FUNCTION_FAILED);
655 spin_lock_irqsave(&ha->hardware_lock, flags);
657 /* Build fabric port login mailbox IOCB. */
658 mbxentry = qla2x00_get_mbx_iocb_entry(ha, iodesc->signature);
659 if (mbxentry == NULL) {
661 spin_unlock_irqrestore(&ha->hardware_lock, flags);
663 return (QLA_FUNCTION_FAILED);
665 mbxentry->mb0 = __constant_cpu_to_le16(MBC_LOGIN_FABRIC_PORT);
666 mbxentry->mb1 = mbxentry->loop_id.extended =
667 cpu_to_le16(iodesc->remote_fcport->loop_id);
668 mbxentry->mb2 = cpu_to_le16(d_id->b.domain);
669 mbxentry->mb3 = cpu_to_le16(d_id->b.area << 8 | d_id->b.al_pa);
670 mbxentry->mb10 = __constant_cpu_to_le16(BIT_0);
673 qla2x00_add_iodesc_timer(iodesc);
675 /* Issue command to ISP. */
679 spin_unlock_irqrestore(&ha->hardware_lock, flags);
681 DEBUG14(printk("scsi(%ld): Sending Login IOCB (%08x) to "
682 "[%x/%02x%02x%02x].\n", ha->host_no, iodesc->signature,
683 iodesc->remote_fcport->loop_id, d_id->b.domain, d_id->b.area,
686 return (QLA_SUCCESS);
690 * qla2x00_send_login_iocb_cb() - Fabric port logout IOCB callback.
692 * @iodesc: io descriptor
693 * @mbxstat: mailbox status IOCB
695 * Returns QLA_SUCCESS if @iodesc can be freed by the caller, else, @iodesc
696 * will be used for a retry.
699 qla2x00_send_login_iocb_cb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
700 struct mbx_entry *mbxstat)
703 fc_port_t *fcport, *remote_fcport, *exist_fcport;
704 struct io_descriptor *abort_iodesc, *login_iodesc;
705 uint16_t status, mb[8];
707 uint16_t remote_loopid;
708 port_id_t remote_did, inuse_did;
710 remote_fcport = iodesc->remote_fcport;
712 /* Only process the last command. */
713 if (remote_fcport->iodesc_idx_sent != iodesc->idx) {
714 DEBUG14(printk("scsi(%ld): Login IOCB -- ignoring, sent to "
715 "[%02x%02x%02x], expected %x, received %x.\n",
716 ha->host_no, iodesc->d_id.b.domain, iodesc->d_id.b.area,
717 iodesc->d_id.b.al_pa, remote_fcport->iodesc_idx_sent,
720 /* Free RSCN fcport resources. */
721 if (remote_fcport->port_type == FCT_RSCN) {
722 DEBUG14(printk("scsi(%ld): Login IOCB -- Freeing RSCN "
723 "fcport %p [%x/%02x%02x%02x] given ignored Login "
724 "IOCB.\n", ha->host_no, remote_fcport,
725 remote_fcport->loop_id,
726 remote_fcport->d_id.b.domain,
727 remote_fcport->d_id.b.area,
728 remote_fcport->d_id.b.al_pa));
730 list_del(&remote_fcport->list);
731 kfree(remote_fcport);
733 return (QLA_SUCCESS);
736 status = le16_to_cpu(mbxstat->status);
737 mb[0] = le16_to_cpu(mbxstat->mb0);
738 mb[1] = le16_to_cpu(mbxstat->mb1);
739 mb[2] = le16_to_cpu(mbxstat->mb2);
740 mb[6] = le16_to_cpu(mbxstat->mb6);
741 mb[7] = le16_to_cpu(mbxstat->mb7);
744 if ((status == CS_COMPLETE || status == CS_COMPLETE_CHKCOND) &&
745 mb[0] == MBS_COMMAND_COMPLETE) {
747 DEBUG14(printk("scsi(%ld): Login IOCB -- status=%x mb1=%x pn="
748 "%02x%02x%02x%02x%02x%02x%02x%02x.\n", ha->host_no, status,
749 mb[1], mbxstat->port_name[0], mbxstat->port_name[1],
750 mbxstat->port_name[2], mbxstat->port_name[3],
751 mbxstat->port_name[4], mbxstat->port_name[5],
752 mbxstat->port_name[6], mbxstat->port_name[7]));
754 memcpy(remote_fcport->node_name, mbxstat->node_name, WWN_SIZE);
755 memcpy(remote_fcport->port_name, mbxstat->port_name, WWN_SIZE);
757 /* Is the device already in our fcports list? */
758 if (remote_fcport->port_type != FCT_RSCN) {
759 DEBUG14(printk("scsi(%ld): Login IOCB -- marking "
760 "[%x/%02x%02x%02x] online.\n", ha->host_no,
761 remote_fcport->loop_id,
762 remote_fcport->d_id.b.domain,
763 remote_fcport->d_id.b.area,
764 remote_fcport->d_id.b.al_pa));
766 qla2x00_update_login_fcport(ha, mbxstat, remote_fcport);
768 return (QLA_SUCCESS);
771 /* Does the RSCN portname already exist in our fcports list? */
773 list_for_each_entry(fcport, &ha->fcports, list) {
774 if (memcmp(remote_fcport->port_name, fcport->port_name,
776 exist_fcport = fcport;
780 if (exist_fcport != NULL) {
781 DEBUG14(printk("scsi(%ld): Login IOCB -- found RSCN "
782 "fcport in fcports list [%p].\n", ha->host_no,
785 /* Abort any ADISC that could have been sent. */
786 if (exist_fcport->iodesc_idx_sent != iodesc->idx &&
787 exist_fcport->iodesc_idx_sent <
788 MAX_IO_DESCRIPTORS &&
789 ha->io_descriptors[exist_fcport->iodesc_idx_sent].
790 cb_idx == ADISC_PORT_IOCB_CB) {
792 abort_iodesc = qla2x00_alloc_iodesc(ha);
794 DEBUG14(printk("scsi(%ld): Login IOCB "
795 "-- issuing abort to outstanding "
796 "Adisc [%x/%02x%02x%02x].\n",
797 ha->host_no, remote_fcport->loop_id,
798 exist_fcport->d_id.b.domain,
799 exist_fcport->d_id.b.area,
800 exist_fcport->d_id.b.al_pa));
802 abort_iodesc->cb_idx = ABORT_IOCB_CB;
803 abort_iodesc->d_id.b24 =
804 exist_fcport->d_id.b24;
805 abort_iodesc->remote_fcport =
807 exist_fcport->iodesc_idx_sent =
809 qla2x00_send_abort_iocb(ha,
810 abort_iodesc, ha->io_descriptors[
811 exist_fcport->iodesc_idx_sent].
814 DEBUG14(printk("scsi(%ld): Login IOCB "
815 "-- unable to abort outstanding "
816 "Adisc [%x/%02x%02x%02x].\n",
817 ha->host_no, remote_fcport->loop_id,
818 exist_fcport->d_id.b.domain,
819 exist_fcport->d_id.b.area,
820 exist_fcport->d_id.b.al_pa));
825 * If the existing fcport is waiting to send an ADISC
826 * or LOGIN, then reuse remote fcport (RSCN) to
830 remote_loopid = remote_fcport->loop_id;
831 remote_did.b24 = remote_fcport->d_id.b24;
832 if (exist_fcport->iodesc_idx_sent ==
833 IODESC_ADISC_NEEDED ||
834 exist_fcport->iodesc_idx_sent ==
835 IODESC_LOGIN_NEEDED) {
836 DEBUG14(printk("scsi(%ld): Login IOCB -- "
837 "existing fcport [%x/%02x%02x%02x] "
838 "waiting for IO descriptor, reuse RSCN "
839 "fcport.\n", ha->host_no,
840 exist_fcport->loop_id,
841 exist_fcport->d_id.b.domain,
842 exist_fcport->d_id.b.area,
843 exist_fcport->d_id.b.al_pa));
846 remote_fcport->iodesc_idx_sent =
847 exist_fcport->iodesc_idx_sent;
848 exist_fcport->iodesc_idx_sent =
849 IODESC_INVALID_INDEX;
850 remote_fcport->loop_id = exist_fcport->loop_id;
851 remote_fcport->d_id.b24 =
852 exist_fcport->d_id.b24;
855 /* Logout the old loopid. */
857 exist_fcport->loop_id != remote_fcport->loop_id &&
858 exist_fcport->loop_id != FC_NO_LOOP_ID) {
859 login_iodesc = qla2x00_alloc_iodesc(ha);
861 DEBUG14(printk("scsi(%ld): Login IOCB "
862 "-- issuing logout to free old "
863 "loop id [%x/%02x%02x%02x].\n",
864 ha->host_no, exist_fcport->loop_id,
865 exist_fcport->d_id.b.domain,
866 exist_fcport->d_id.b.area,
867 exist_fcport->d_id.b.al_pa));
869 login_iodesc->cb_idx =
871 login_iodesc->d_id.b24 =
872 exist_fcport->d_id.b24;
873 login_iodesc->remote_fcport =
875 exist_fcport->iodesc_idx_sent =
877 qla2x00_send_logout_iocb(ha,
880 /* Ran out of IO descriptiors. */
881 DEBUG14(printk("scsi(%ld): Login IOCB "
882 "-- unable to logout to free old "
883 "loop id [%x/%02x%02x%02x].\n",
884 ha->host_no, exist_fcport->loop_id,
885 exist_fcport->d_id.b.domain,
886 exist_fcport->d_id.b.area,
887 exist_fcport->d_id.b.al_pa));
889 exist_fcport->iodesc_idx_sent =
890 IODESC_INVALID_INDEX;
895 /* Update existing fcport with remote fcport info. */
896 DEBUG14(printk("scsi(%ld): Login IOCB -- marking "
897 "existing fcport [%x/%02x%02x%02x] online.\n",
898 ha->host_no, remote_loopid, remote_did.b.domain,
899 remote_did.b.area, remote_did.b.al_pa));
901 memcpy(exist_fcport->node_name,
902 remote_fcport->node_name, WWN_SIZE);
903 exist_fcport->loop_id = remote_loopid;
904 exist_fcport->d_id.b24 = remote_did.b24;
905 qla2x00_update_login_fcport(ha, mbxstat, exist_fcport);
907 /* Finally, free the remote (RSCN) fcport. */
909 DEBUG14(printk("scsi(%ld): Login IOCB -- "
910 "Freeing RSCN fcport %p "
911 "[%x/%02x%02x%02x].\n", ha->host_no,
912 remote_fcport, remote_fcport->loop_id,
913 remote_fcport->d_id.b.domain,
914 remote_fcport->d_id.b.area,
915 remote_fcport->d_id.b.al_pa));
917 list_del(&remote_fcport->list);
918 kfree(remote_fcport);
921 return (QLA_SUCCESS);
925 * A new device has been added, move the RSCN fcport to our
928 DEBUG14(printk("scsi(%ld): Login IOCB -- adding RSCN fcport "
929 "[%x/%02x%02x%02x] to fcports list.\n", ha->host_no,
930 remote_fcport->loop_id, remote_fcport->d_id.b.domain,
931 remote_fcport->d_id.b.area, remote_fcport->d_id.b.al_pa));
933 list_del(&remote_fcport->list);
934 remote_fcport->flags = (FCF_RLC_SUPPORT | FCF_RESCAN_NEEDED);
935 qla2x00_update_login_fcport(ha, mbxstat, remote_fcport);
936 list_add_tail(&remote_fcport->list, &ha->fcports);
937 set_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags);
939 /* Handle login failure. */
940 if (remote_fcport->login_retry != 0) {
941 if (mb[0] == MBS_LOOP_ID_USED) {
942 inuse_did.b.domain = LSB(mb[1]);
943 inuse_did.b.area = MSB(mb[2]);
944 inuse_did.b.al_pa = LSB(mb[2]);
946 DEBUG14(printk("scsi(%ld): Login IOCB -- loop "
947 "id [%x] used by port id [%02x%02x%02x].\n",
948 ha->host_no, remote_fcport->loop_id,
949 inuse_did.b.domain, inuse_did.b.area,
952 if (remote_fcport->d_id.b24 ==
955 * Invalid port id means we are trying
956 * to login to a remote port with just
957 * a loop id without knowing about the
958 * port id. Copy the port id and try
961 remote_fcport->d_id.b24 = inuse_did.b24;
962 iodesc->d_id.b24 = inuse_did.b24;
964 remote_fcport->loop_id++;
965 rval = qla2x00_find_new_loop_id(ha,
967 if (rval == QLA_FUNCTION_FAILED) {
968 /* No more loop ids. */
969 return (QLA_SUCCESS);
972 } else if (mb[0] == MBS_PORT_ID_USED) {
974 * Device has another loop ID. The firmware
975 * group recommends the driver perform an
976 * implicit login with the specified ID.
978 DEBUG14(printk("scsi(%ld): Login IOCB -- port "
979 "id [%02x%02x%02x] already assigned to "
980 "loop id [%x].\n", ha->host_no,
981 iodesc->d_id.b.domain, iodesc->d_id.b.area,
982 iodesc->d_id.b.al_pa, mb[1]));
984 remote_fcport->loop_id = mb[1];
987 /* Unable to perform login, try again. */
988 DEBUG14(printk("scsi(%ld): Login IOCB -- "
989 "failed login [%x/%02x%02x%02x], status=%x "
990 "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n",
991 ha->host_no, remote_fcport->loop_id,
992 iodesc->d_id.b.domain, iodesc->d_id.b.area,
993 iodesc->d_id.b.al_pa, status, mb[0], mb[1],
994 mb[2], mb[6], mb[7]));
997 /* Reissue Login with the same IO descriptor. */
999 qla2x00_iodesc_to_handle(iodesc);
1000 iodesc->cb_idx = LOGIN_PORT_IOCB_CB;
1001 iodesc->d_id.b24 = remote_fcport->d_id.b24;
1002 remote_fcport->iodesc_idx_sent = iodesc->idx;
1003 remote_fcport->login_retry--;
1005 DEBUG14(printk("scsi(%ld): Login IOCB -- retrying "
1006 "login to [%x/%02x%02x%02x] (%d).\n", ha->host_no,
1007 remote_fcport->loop_id,
1008 remote_fcport->d_id.b.domain,
1009 remote_fcport->d_id.b.area,
1010 remote_fcport->d_id.b.al_pa,
1011 remote_fcport->login_retry));
1013 qla2x00_send_login_iocb(ha, iodesc,
1014 &remote_fcport->d_id, 1);
1016 return (QLA_FUNCTION_FAILED);
1018 /* No more logins, mark device dead. */
1019 DEBUG14(printk("scsi(%ld): Login IOCB -- failed "
1020 "login [%x/%02x%02x%02x] after retries, status=%x "
1021 "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n",
1022 ha->host_no, remote_fcport->loop_id,
1023 iodesc->d_id.b.domain, iodesc->d_id.b.area,
1024 iodesc->d_id.b.al_pa, status, mb[0], mb[1],
1025 mb[2], mb[6], mb[7]));
1027 atomic_set(&remote_fcport->state, FCS_DEVICE_DEAD);
1028 if (remote_fcport->port_type == FCT_RSCN) {
1029 DEBUG14(printk("scsi(%ld): Login IOCB -- "
1030 "Freeing dead RSCN fcport %p "
1031 "[%x/%02x%02x%02x].\n", ha->host_no,
1032 remote_fcport, remote_fcport->loop_id,
1033 remote_fcport->d_id.b.domain,
1034 remote_fcport->d_id.b.area,
1035 remote_fcport->d_id.b.al_pa));
1037 list_del(&remote_fcport->list);
1038 kfree(remote_fcport);
1043 return (QLA_SUCCESS);
1048 * IO descriptor processing routines.
1052 * qla2x00_alloc_rscn_fcport() - Allocate an RSCN type fcport.
1054 * @flags: allocation flags
1056 * Returns a pointer to the allocated RSCN fcport, or NULL, if none available.
1059 qla2x00_alloc_rscn_fcport(scsi_qla_host_t *ha, gfp_t flags)
1063 fcport = qla2x00_alloc_fcport(ha, flags);
1067 /* Setup RSCN fcport structure. */
1068 fcport->port_type = FCT_RSCN;
1074 * qla2x00_handle_port_rscn() - Handle port RSCN.
1076 * @rscn_entry: RSCN entry
1077 * @fcport: fcport entry to updated
1079 * Returns QLA_SUCCESS if the port RSCN was handled.
1082 qla2x00_handle_port_rscn(scsi_qla_host_t *ha, uint32_t rscn_entry,
1083 fc_port_t *known_fcport, int ha_locked)
1087 fc_port_t *fcport, *remote_fcport, *rscn_fcport;
1088 struct io_descriptor *iodesc;
1090 remote_fcport = NULL;
1093 /* Prepare port id based on incoming entries. */
1095 rscn_pid.b24 = known_fcport->d_id.b24;
1096 remote_fcport = known_fcport;
1098 DEBUG14(printk("scsi(%ld): Handle RSCN -- process RSCN for "
1099 "fcport [%02x%02x%02x].\n", ha->host_no,
1100 remote_fcport->d_id.b.domain, remote_fcport->d_id.b.area,
1101 remote_fcport->d_id.b.al_pa));
1103 rscn_pid.b.domain = LSB(MSW(rscn_entry));
1104 rscn_pid.b.area = MSB(LSW(rscn_entry));
1105 rscn_pid.b.al_pa = LSB(LSW(rscn_entry));
1107 DEBUG14(printk("scsi(%ld): Handle RSCN -- process RSCN for "
1108 "port id [%02x%02x%02x].\n", ha->host_no,
1109 rscn_pid.b.domain, rscn_pid.b.area, rscn_pid.b.al_pa));
1112 * Search fcport lists for a known entry at the specified port
1115 list_for_each_entry(fcport, &ha->fcports, list) {
1116 if (rscn_pid.b24 == fcport->d_id.b24) {
1117 remote_fcport = fcport;
1121 list_for_each_entry(fcport, &ha->rscn_fcports, list) {
1122 if (rscn_pid.b24 == fcport->d_id.b24) {
1123 rscn_fcport = fcport;
1127 if (remote_fcport == NULL)
1128 remote_fcport = rscn_fcport;
1132 * If the port is already in our fcport list and online, send an ADISC
1133 * to see if it's still alive. Issue login if a new fcport or the known
1134 * fcport is currently offline.
1136 if (remote_fcport) {
1138 * No need to send request if the remote fcport is currently
1139 * waiting for an available io descriptor.
1141 if (known_fcport == NULL &&
1142 (remote_fcport->iodesc_idx_sent == IODESC_ADISC_NEEDED ||
1143 remote_fcport->iodesc_idx_sent == IODESC_LOGIN_NEEDED)) {
1145 * If previous waiting io descriptor is an ADISC, then
1146 * the new RSCN may come from a new remote fcport being
1147 * plugged into the same location.
1149 if (remote_fcport->port_type == FCT_RSCN) {
1150 remote_fcport->iodesc_idx_sent =
1151 IODESC_LOGIN_NEEDED;
1152 } else if (remote_fcport->iodesc_idx_sent ==
1153 IODESC_ADISC_NEEDED) {
1154 fc_port_t *new_fcport;
1156 remote_fcport->iodesc_idx_sent =
1157 IODESC_INVALID_INDEX;
1159 /* Create new fcport for later login. */
1160 new_fcport = qla2x00_alloc_rscn_fcport(ha,
1161 ha_locked ? GFP_ATOMIC: GFP_KERNEL);
1163 DEBUG14(printk("scsi(%ld): Handle RSCN "
1164 "-- creating RSCN fcport %p for "
1165 "future login.\n", ha->host_no,
1168 new_fcport->d_id.b24 =
1169 remote_fcport->d_id.b24;
1170 new_fcport->iodesc_idx_sent =
1171 IODESC_LOGIN_NEEDED;
1173 list_add_tail(&new_fcport->list,
1175 set_bit(IODESC_PROCESS_NEEDED,
1178 DEBUG14(printk("scsi(%ld): Handle RSCN "
1179 "-- unable to allocate RSCN fcport "
1180 "for future login.\n",
1184 return (QLA_SUCCESS);
1187 /* Send ADISC if the fcport is online */
1188 if (atomic_read(&remote_fcport->state) == FCS_ONLINE ||
1189 remote_fcport->iodesc_idx_sent == IODESC_ADISC_NEEDED) {
1191 atomic_set(&remote_fcport->state, FCS_DEVICE_LOST);
1193 iodesc = qla2x00_alloc_iodesc(ha);
1194 if (iodesc == NULL) {
1195 /* Mark fcport for later adisc processing */
1196 DEBUG14(printk("scsi(%ld): Handle RSCN -- not "
1197 "enough IO descriptors for Adisc, flag "
1198 "for later processing.\n", ha->host_no));
1200 remote_fcport->iodesc_idx_sent =
1201 IODESC_ADISC_NEEDED;
1202 set_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags);
1204 return (QLA_SUCCESS);
1207 iodesc->cb_idx = ADISC_PORT_IOCB_CB;
1208 iodesc->d_id.b24 = rscn_pid.b24;
1209 iodesc->remote_fcport = remote_fcport;
1210 remote_fcport->iodesc_idx_sent = iodesc->idx;
1211 qla2x00_send_adisc_iocb(ha, iodesc, ha_locked);
1213 return (QLA_SUCCESS);
1214 } else if (remote_fcport->iodesc_idx_sent <
1215 MAX_IO_DESCRIPTORS &&
1216 ha->io_descriptors[remote_fcport->iodesc_idx_sent].cb_idx ==
1217 ADISC_PORT_IOCB_CB) {
1219 * Receiving another RSCN while an ADISC is pending,
1220 * abort the IOCB. Use the same descriptor for the
1223 uint32_t handle_to_abort;
1225 iodesc = &ha->io_descriptors[
1226 remote_fcport->iodesc_idx_sent];
1227 qla2x00_remove_iodesc_timer(iodesc);
1228 handle_to_abort = iodesc->signature;
1229 iodesc->signature = qla2x00_iodesc_to_handle(iodesc);
1230 iodesc->cb_idx = ABORT_IOCB_CB;
1231 iodesc->d_id.b24 = remote_fcport->d_id.b24;
1232 iodesc->remote_fcport = remote_fcport;
1233 remote_fcport->iodesc_idx_sent = iodesc->idx;
1235 DEBUG14(printk("scsi(%ld): Handle RSCN -- issuing "
1236 "abort to outstanding Adisc [%x/%02x%02x%02x].\n",
1237 ha->host_no, remote_fcport->loop_id,
1238 iodesc->d_id.b.domain, iodesc->d_id.b.area,
1239 iodesc->d_id.b.al_pa));
1241 qla2x00_send_abort_iocb(ha, iodesc, handle_to_abort,
1246 /* We need to login to the remote port, find it. */
1248 remote_fcport = known_fcport;
1249 } else if (rscn_fcport && rscn_fcport->d_id.b24 != INVALID_PORT_ID &&
1250 rscn_fcport->iodesc_idx_sent < MAX_IO_DESCRIPTORS &&
1251 ha->io_descriptors[rscn_fcport->iodesc_idx_sent].cb_idx ==
1252 LOGIN_PORT_IOCB_CB) {
1254 * Ignore duplicate RSCN on fcport which has already
1255 * initiated a login IOCB.
1257 DEBUG14(printk("scsi(%ld): Handle RSCN -- ignoring, login "
1258 "already sent to [%02x%02x%02x].\n", ha->host_no,
1259 rscn_fcport->d_id.b.domain, rscn_fcport->d_id.b.area,
1260 rscn_fcport->d_id.b.al_pa));
1262 return (QLA_SUCCESS);
1263 } else if (rscn_fcport && rscn_fcport->d_id.b24 != INVALID_PORT_ID &&
1264 rscn_fcport != remote_fcport) {
1265 /* Reuse same rscn fcport. */
1266 DEBUG14(printk("scsi(%ld): Handle RSCN -- reusing RSCN fcport "
1267 "[%02x%02x%02x].\n", ha->host_no,
1268 rscn_fcport->d_id.b.domain, rscn_fcport->d_id.b.area,
1269 rscn_fcport->d_id.b.al_pa));
1271 remote_fcport = rscn_fcport;
1273 /* Create new fcport for later login. */
1274 remote_fcport = qla2x00_alloc_rscn_fcport(ha,
1275 ha_locked ? GFP_ATOMIC: GFP_KERNEL);
1276 list_add_tail(&remote_fcport->list, &ha->rscn_fcports);
1278 if (remote_fcport == NULL)
1279 return (QLA_SUCCESS);
1281 /* Prepare fcport for login. */
1282 atomic_set(&remote_fcport->state, FCS_DEVICE_LOST);
1283 remote_fcport->login_retry = 3; /* ha->login_retry_count; */
1284 remote_fcport->d_id.b24 = rscn_pid.b24;
1286 iodesc = qla2x00_alloc_iodesc(ha);
1287 if (iodesc == NULL) {
1288 /* Mark fcport for later adisc processing. */
1289 DEBUG14(printk("scsi(%ld): Handle RSCN -- not enough IO "
1290 "descriptors for Login, flag for later processing.\n",
1293 remote_fcport->iodesc_idx_sent = IODESC_LOGIN_NEEDED;
1294 set_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags);
1296 return (QLA_SUCCESS);
1299 if (known_fcport == NULL || rscn_pid.b24 != INVALID_PORT_ID) {
1300 remote_fcport->loop_id = ha->min_external_loopid;
1302 rval = qla2x00_find_new_loop_id(ha, remote_fcport);
1303 if (rval == QLA_FUNCTION_FAILED) {
1304 /* No more loop ids, failed. */
1305 DEBUG14(printk("scsi(%ld): Handle RSCN -- no available "
1306 "loop id to perform Login, failed.\n",
1313 iodesc->cb_idx = LOGIN_PORT_IOCB_CB;
1314 iodesc->d_id.b24 = rscn_pid.b24;
1315 iodesc->remote_fcport = remote_fcport;
1316 remote_fcport->iodesc_idx_sent = iodesc->idx;
1318 DEBUG14(printk("scsi(%ld): Handle RSCN -- attempting login to "
1319 "[%x/%02x%02x%02x].\n", ha->host_no, remote_fcport->loop_id,
1320 iodesc->d_id.b.domain, iodesc->d_id.b.area, iodesc->d_id.b.al_pa));
1322 qla2x00_send_login_iocb(ha, iodesc, &rscn_pid, ha_locked);
1324 return (QLA_SUCCESS);
1328 * qla2x00_process_iodesc() - Complete IO descriptor processing.
1330 * @mbxstat: Mailbox IOCB status
1333 qla2x00_process_iodesc(scsi_qla_host_t *ha, struct mbx_entry *mbxstat)
1338 struct io_descriptor *iodesc;
1340 signature = mbxstat->handle;
1342 DEBUG14(printk("scsi(%ld): Process IODesc -- processing %08x.\n",
1343 ha->host_no, signature));
1345 /* Retrieve proper IO descriptor. */
1346 iodesc = qla2x00_handle_to_iodesc(ha, signature);
1347 if (iodesc == NULL) {
1348 DEBUG14(printk("scsi(%ld): Process IODesc -- ignoring, "
1349 "incorrect signature %08x.\n", ha->host_no, signature));
1354 /* Stop IO descriptor timer. */
1355 qla2x00_remove_iodesc_timer(iodesc);
1357 /* Verify signature match. */
1358 if (iodesc->signature != signature) {
1359 DEBUG14(printk("scsi(%ld): Process IODesc -- ignoring, "
1360 "signature mismatch, sent %08x, received %08x.\n",
1361 ha->host_no, iodesc->signature, signature));
1366 /* Go with IOCB callback. */
1367 rval = iocb_function_cb_list[iodesc->cb_idx](ha, iodesc, mbxstat);
1368 if (rval != QLA_SUCCESS) {
1369 /* IO descriptor reused by callback. */
1373 qla2x00_free_iodesc(iodesc);
1375 if (test_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags)) {
1376 /* Scan our fcports list for any RSCN requests. */
1377 list_for_each_entry(fcport, &ha->fcports, list) {
1378 if (fcport->iodesc_idx_sent == IODESC_ADISC_NEEDED ||
1379 fcport->iodesc_idx_sent == IODESC_LOGIN_NEEDED) {
1380 qla2x00_handle_port_rscn(ha, 0, fcport, 1);
1385 /* Scan our RSCN fcports list for any RSCN requests. */
1386 list_for_each_entry(fcport, &ha->rscn_fcports, list) {
1387 if (fcport->iodesc_idx_sent == IODESC_ADISC_NEEDED ||
1388 fcport->iodesc_idx_sent == IODESC_LOGIN_NEEDED) {
1389 qla2x00_handle_port_rscn(ha, 0, fcport, 1);
1394 clear_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags);
1398 * qla2x00_cancel_io_descriptors() - Cancel all outstanding io descriptors.
1401 * This routine will also delete any RSCN entries related to the outstanding
1405 qla2x00_cancel_io_descriptors(scsi_qla_host_t *ha)
1407 fc_port_t *fcport, *fcptemp;
1409 clear_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags);
1411 /* Abort all IO descriptors. */
1412 qla2x00_init_io_descriptors(ha);
1414 /* Reset all pending IO descriptors in fcports list. */
1415 list_for_each_entry(fcport, &ha->fcports, list) {
1416 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1419 /* Reset all pending IO descriptors in rscn fcports list. */
1420 list_for_each_entry_safe(fcport, fcptemp, &ha->rscn_fcports, list) {
1421 DEBUG14(printk("scsi(%ld): Cancel IOs -- Freeing RSCN fcport "
1422 "%p [%x/%02x%02x%02x].\n", ha->host_no, fcport,
1423 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
1424 fcport->d_id.b.al_pa));
1426 list_del(&fcport->list);