[SCSI] qla2xxx: fix remote port timeout with qla2xxx driver
[linux-2.6.git] / drivers / scsi / qla2xxx / qla_rscn.c
blob1eba988286360efd49a696eb80613e5310953663
1 /*
2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2005 QLogic Corporation
6 * (www.qlogic.com)
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
19 #include "qla_def.h"
21 /**
22 * IO descriptor handle definitions.
24 * Signature form:
26 * |31------28|27-------------------12|11-------0|
27 * | Type | Rolling Signature | Index |
28 * |----------|-----------------------|----------|
30 **/
32 #define HDL_TYPE_SCSI 0
33 #define HDL_TYPE_ASYNC_IOCB 0x0A
35 #define HDL_INDEX_BITS 12
36 #define HDL_ITER_BITS 16
37 #define HDL_TYPE_BITS 4
39 #define HDL_INDEX_MASK ((1UL << HDL_INDEX_BITS) - 1)
40 #define HDL_ITER_MASK ((1UL << HDL_ITER_BITS) - 1)
41 #define HDL_TYPE_MASK ((1UL << HDL_TYPE_BITS) - 1)
43 #define HDL_INDEX_SHIFT 0
44 #define HDL_ITER_SHIFT (HDL_INDEX_SHIFT + HDL_INDEX_BITS)
45 #define HDL_TYPE_SHIFT (HDL_ITER_SHIFT + HDL_ITER_BITS)
47 /* Local Prototypes. */
48 static inline uint32_t qla2x00_to_handle(uint16_t, uint16_t, uint16_t);
49 static inline uint16_t qla2x00_handle_to_idx(uint32_t);
50 static inline uint32_t qla2x00_iodesc_to_handle(struct io_descriptor *);
51 static inline struct io_descriptor *qla2x00_handle_to_iodesc(scsi_qla_host_t *,
52 uint32_t);
54 static inline struct io_descriptor *qla2x00_alloc_iodesc(scsi_qla_host_t *);
55 static inline void qla2x00_free_iodesc(struct io_descriptor *);
56 static inline void qla2x00_init_io_descriptors(scsi_qla_host_t *);
58 static void qla2x00_iodesc_timeout(unsigned long);
59 static inline void qla2x00_add_iodesc_timer(struct io_descriptor *);
60 static inline void qla2x00_remove_iodesc_timer(struct io_descriptor *);
62 static inline void qla2x00_update_login_fcport(scsi_qla_host_t *,
63 struct mbx_entry *, fc_port_t *);
65 static int qla2x00_send_abort_iocb(scsi_qla_host_t *, struct io_descriptor *,
66 uint32_t, int);
67 static int qla2x00_send_abort_iocb_cb(scsi_qla_host_t *, struct io_descriptor *,
68 struct mbx_entry *);
70 static int qla2x00_send_adisc_iocb(scsi_qla_host_t *, struct io_descriptor *,
71 int);
72 static int qla2x00_send_adisc_iocb_cb(scsi_qla_host_t *, struct io_descriptor *,
73 struct mbx_entry *);
75 static int qla2x00_send_logout_iocb(scsi_qla_host_t *, struct io_descriptor *,
76 int);
77 static int qla2x00_send_logout_iocb_cb(scsi_qla_host_t *,
78 struct io_descriptor *, struct mbx_entry *);
80 static int qla2x00_send_login_iocb(scsi_qla_host_t *, struct io_descriptor *,
81 port_id_t *, int);
82 static int qla2x00_send_login_iocb_cb(scsi_qla_host_t *, struct io_descriptor *,
83 struct mbx_entry *);
85 /**
86 * Mailbox IOCB callback array.
87 **/
88 static int (*iocb_function_cb_list[LAST_IOCB_CB])
89 (scsi_qla_host_t *, struct io_descriptor *, struct mbx_entry *) = {
91 qla2x00_send_abort_iocb_cb,
92 qla2x00_send_adisc_iocb_cb,
93 qla2x00_send_logout_iocb_cb,
94 qla2x00_send_login_iocb_cb,
98 /**
99 * Generic IO descriptor handle routines.
103 * qla2x00_to_handle() - Create a descriptor handle.
104 * @type: descriptor type
105 * @iter: descriptor rolling signature
106 * @idx: index to the descriptor array
108 * Returns a composite handle based in the @type, @iter, and @idx.
110 static inline uint32_t
111 qla2x00_to_handle(uint16_t type, uint16_t iter, uint16_t idx)
113 return ((uint32_t)(((uint32_t)type << HDL_TYPE_SHIFT) |
114 ((uint32_t)iter << HDL_ITER_SHIFT) |
115 ((uint32_t)idx << HDL_INDEX_SHIFT)));
119 * qla2x00_handle_to_idx() - Retrive the index for a given handle.
120 * @handle: descriptor handle
122 * Returns the index specified by the @handle.
124 static inline uint16_t
125 qla2x00_handle_to_idx(uint32_t handle)
127 return ((uint16_t)(((handle) >> HDL_INDEX_SHIFT) & HDL_INDEX_MASK));
131 * qla2x00_iodesc_to_handle() - Convert an IO descriptor to a unique handle.
132 * @iodesc: io descriptor
134 * Returns a unique handle for @iodesc.
136 static inline uint32_t
137 qla2x00_iodesc_to_handle(struct io_descriptor *iodesc)
139 uint32_t handle;
141 handle = qla2x00_to_handle(HDL_TYPE_ASYNC_IOCB,
142 ++iodesc->ha->iodesc_signature, iodesc->idx);
143 iodesc->signature = handle;
145 return (handle);
149 * qla2x00_handle_to_iodesc() - Retrieve an IO descriptor given a unique handle.
150 * @ha: HA context
151 * @handle: handle to io descriptor
153 * Returns a pointer to the io descriptor, or NULL, if the io descriptor does
154 * not exist or the io descriptors signature does not @handle.
156 static inline struct io_descriptor *
157 qla2x00_handle_to_iodesc(scsi_qla_host_t *ha, uint32_t handle)
159 uint16_t idx;
160 struct io_descriptor *iodesc;
162 idx = qla2x00_handle_to_idx(handle);
163 iodesc = &ha->io_descriptors[idx];
164 if (iodesc)
165 if (iodesc->signature != handle)
166 iodesc = NULL;
168 return (iodesc);
173 * IO descriptor allocation routines.
177 * qla2x00_alloc_iodesc() - Allocate an IO descriptor from the pool.
178 * @ha: HA context
180 * Returns a pointer to the allocated io descriptor, or NULL, if none available.
182 static inline struct io_descriptor *
183 qla2x00_alloc_iodesc(scsi_qla_host_t *ha)
185 uint16_t iter;
186 struct io_descriptor *iodesc;
188 iodesc = NULL;
189 for (iter = 0; iter < MAX_IO_DESCRIPTORS; iter++) {
190 if (ha->io_descriptors[iter].used)
191 continue;
193 iodesc = &ha->io_descriptors[iter];
194 iodesc->used = 1;
195 iodesc->idx = iter;
196 init_timer(&iodesc->timer);
197 iodesc->ha = ha;
198 iodesc->signature = qla2x00_iodesc_to_handle(iodesc);
199 break;
202 return (iodesc);
206 * qla2x00_free_iodesc() - Free an IO descriptor.
207 * @iodesc: io descriptor
209 * NOTE: The io descriptors timer *must* be stopped before it can be free'd.
211 static inline void
212 qla2x00_free_iodesc(struct io_descriptor *iodesc)
214 iodesc->used = 0;
215 iodesc->signature = 0;
219 * qla2x00_remove_iodesc_timer() - Remove an active timer from an IO descriptor.
220 * @iodesc: io descriptor
222 static inline void
223 qla2x00_remove_iodesc_timer(struct io_descriptor *iodesc)
225 if (iodesc->timer.function != NULL) {
226 del_timer_sync(&iodesc->timer);
227 iodesc->timer.data = (unsigned long) NULL;
228 iodesc->timer.function = NULL;
233 * qla2x00_init_io_descriptors() - Initialize the pool of IO descriptors.
234 * @ha: HA context
236 static inline void
237 qla2x00_init_io_descriptors(scsi_qla_host_t *ha)
239 uint16_t iter;
241 for (iter = 0; iter < MAX_IO_DESCRIPTORS; iter++) {
242 if (!ha->io_descriptors[iter].used)
243 continue;
245 qla2x00_remove_iodesc_timer(&ha->io_descriptors[iter]);
246 qla2x00_free_iodesc(&ha->io_descriptors[iter]);
252 * IO descriptor timer routines.
256 * qla2x00_iodesc_timeout() - Timeout IO descriptor handler.
257 * @data: io descriptor
259 static void
260 qla2x00_iodesc_timeout(unsigned long data)
262 struct io_descriptor *iodesc;
264 iodesc = (struct io_descriptor *) data;
266 DEBUG14(printk("scsi(%ld): IO descriptor timeout, index=%x "
267 "signature=%08x, scheduling ISP abort.\n", iodesc->ha->host_no,
268 iodesc->idx, iodesc->signature));
270 qla2x00_free_iodesc(iodesc);
272 qla_printk(KERN_WARNING, iodesc->ha,
273 "IO descriptor timeout. Scheduling ISP abort.\n");
274 set_bit(ISP_ABORT_NEEDED, &iodesc->ha->dpc_flags);
278 * qla2x00_add_iodesc_timer() - Add and start a timer for an IO descriptor.
279 * @iodesc: io descriptor
281 * NOTE:
282 * The firmware shall timeout an outstanding mailbox IOCB in 2 * R_A_TOV (in
283 * tenths of a second) after it hits the wire. But, if there are any request
284 * resource contraints (i.e. during heavy I/O), exchanges can be held off for
285 * at most R_A_TOV. Therefore, the driver will wait 4 * R_A_TOV before
286 * scheduling a recovery (big hammer).
288 static inline void
289 qla2x00_add_iodesc_timer(struct io_descriptor *iodesc)
291 unsigned long timeout;
293 timeout = (iodesc->ha->r_a_tov * 4) / 10;
294 init_timer(&iodesc->timer);
295 iodesc->timer.data = (unsigned long) iodesc;
296 iodesc->timer.expires = jiffies + (timeout * HZ);
297 iodesc->timer.function =
298 (void (*) (unsigned long)) qla2x00_iodesc_timeout;
299 add_timer(&iodesc->timer);
303 * IO descriptor support routines.
307 * qla2x00_update_login_fcport() - Update fcport data after login processing.
308 * @ha: HA context
309 * @mbxstat: Mailbox command status IOCB
310 * @fcport: port to update
312 static inline void
313 qla2x00_update_login_fcport(scsi_qla_host_t *ha, struct mbx_entry *mbxstat,
314 fc_port_t *fcport)
316 if (le16_to_cpu(mbxstat->mb1) & BIT_0) {
317 fcport->port_type = FCT_INITIATOR;
318 } else {
319 fcport->port_type = FCT_TARGET;
320 if (le16_to_cpu(mbxstat->mb1) & BIT_1) {
321 fcport->flags |= FCF_TAPE_PRESENT;
324 fcport->login_retry = 0;
325 fcport->port_login_retry_count = ha->port_down_retry_count *
326 PORT_RETRY_TIME;
327 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
328 PORT_RETRY_TIME);
329 fcport->flags |= FCF_FABRIC_DEVICE;
330 fcport->flags &= ~FCF_FAILOVER_NEEDED;
331 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
332 atomic_set(&fcport->state, FCS_ONLINE);
333 if (fcport->rport)
334 fc_remote_port_unblock(fcport->rport);
339 * Mailbox IOCB commands.
343 * qla2x00_get_mbx_iocb_entry() - Retrieve an IOCB from the request queue.
344 * @ha: HA context
345 * @handle: handle to io descriptor
347 * Returns a pointer to the reqest entry, or NULL, if none were available.
349 static inline struct mbx_entry *
350 qla2x00_get_mbx_iocb_entry(scsi_qla_host_t *ha, uint32_t handle)
352 uint16_t cnt;
353 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
354 struct mbx_entry *mbxentry;
356 mbxentry = NULL;
358 if (ha->req_q_cnt < 3) {
359 cnt = qla2x00_debounce_register(ISP_REQ_Q_OUT(ha, reg));
360 if (ha->req_ring_index < cnt)
361 ha->req_q_cnt = cnt - ha->req_ring_index;
362 else
363 ha->req_q_cnt = ha->request_q_length -
364 (ha->req_ring_index - cnt);
366 if (ha->req_q_cnt >= 3) {
367 mbxentry = (struct mbx_entry *)ha->request_ring_ptr;
369 memset(mbxentry, 0, sizeof(struct mbx_entry));
370 mbxentry->entry_type = MBX_IOCB_TYPE;
371 mbxentry->entry_count = 1;
372 mbxentry->sys_define1 = SOURCE_ASYNC_IOCB;
373 mbxentry->handle = handle;
375 return (mbxentry);
379 * qla2x00_send_abort_iocb() - Issue an abort IOCB to the firmware.
380 * @ha: HA context
381 * @iodesc: io descriptor
382 * @handle_to_abort: firmware handle to abort
383 * @ha_locked: is function called with the hardware lock
385 * Returns QLA_SUCCESS if the IOCB was issued.
387 static int
388 qla2x00_send_abort_iocb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
389 uint32_t handle_to_abort, int ha_locked)
391 unsigned long flags = 0;
392 struct mbx_entry *mbxentry;
394 /* Send marker if required. */
395 if (qla2x00_issue_marker(ha, ha_locked) != QLA_SUCCESS)
396 return (QLA_FUNCTION_FAILED);
398 if (!ha_locked)
399 spin_lock_irqsave(&ha->hardware_lock, flags);
401 /* Build abort mailbox IOCB. */
402 mbxentry = qla2x00_get_mbx_iocb_entry(ha, iodesc->signature);
403 if (mbxentry == NULL) {
404 if (!ha_locked)
405 spin_unlock_irqrestore(&ha->hardware_lock, flags);
407 return (QLA_FUNCTION_FAILED);
409 mbxentry->mb0 = __constant_cpu_to_le16(MBC_ABORT_COMMAND);
410 mbxentry->mb1 = mbxentry->loop_id.extended =
411 cpu_to_le16(iodesc->remote_fcport->loop_id);
412 mbxentry->mb2 = LSW(handle_to_abort);
413 mbxentry->mb3 = MSW(handle_to_abort);
414 wmb();
416 qla2x00_add_iodesc_timer(iodesc);
418 /* Issue command to ISP. */
419 qla2x00_isp_cmd(ha);
421 if (!ha_locked)
422 spin_unlock_irqrestore(&ha->hardware_lock, flags);
424 DEBUG14(printk("scsi(%ld): Sending Abort IOCB (%08x) to [%x], aborting "
425 "%08x.\n", ha->host_no, iodesc->signature,
426 iodesc->remote_fcport->loop_id, handle_to_abort));
428 return (QLA_SUCCESS);
432 * qla2x00_send_abort_iocb_cb() - Abort IOCB callback.
433 * @ha: HA context
434 * @iodesc: io descriptor
435 * @mbxstat: mailbox status IOCB
437 * Returns QLA_SUCCESS if @iodesc can be freed by the caller, else, @iodesc
438 * will be used for a retry.
440 static int
441 qla2x00_send_abort_iocb_cb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
442 struct mbx_entry *mbxstat)
444 DEBUG14(printk("scsi(%ld): Abort IOCB -- sent to [%x/%02x%02x%02x], "
445 "status=%x mb0=%x.\n", ha->host_no, iodesc->remote_fcport->loop_id,
446 iodesc->d_id.b.domain, iodesc->d_id.b.area, iodesc->d_id.b.al_pa,
447 le16_to_cpu(mbxstat->status), le16_to_cpu(mbxstat->mb0)));
449 return (QLA_SUCCESS);
454 * qla2x00_send_adisc_iocb() - Issue a Get Port Database IOCB to the firmware.
455 * @ha: HA context
456 * @iodesc: io descriptor
457 * @ha_locked: is function called with the hardware lock
459 * Returns QLA_SUCCESS if the IOCB was issued.
461 static int
462 qla2x00_send_adisc_iocb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
463 int ha_locked)
465 unsigned long flags = 0;
466 struct mbx_entry *mbxentry;
468 /* Send marker if required. */
469 if (qla2x00_issue_marker(ha, ha_locked) != QLA_SUCCESS)
470 return (QLA_FUNCTION_FAILED);
472 if (!ha_locked)
473 spin_lock_irqsave(&ha->hardware_lock, flags);
475 /* Build Get Port Database IOCB. */
476 mbxentry = qla2x00_get_mbx_iocb_entry(ha, iodesc->signature);
477 if (mbxentry == NULL) {
478 if (!ha_locked)
479 spin_unlock_irqrestore(&ha->hardware_lock, flags);
481 return (QLA_FUNCTION_FAILED);
483 mbxentry->mb0 = __constant_cpu_to_le16(MBC_GET_PORT_DATABASE);
484 mbxentry->mb1 = mbxentry->loop_id.extended =
485 cpu_to_le16(iodesc->remote_fcport->loop_id);
486 mbxentry->mb2 = cpu_to_le16(MSW(LSD(ha->iodesc_pd_dma)));
487 mbxentry->mb3 = cpu_to_le16(LSW(LSD(ha->iodesc_pd_dma)));
488 mbxentry->mb6 = cpu_to_le16(MSW(MSD(ha->iodesc_pd_dma)));
489 mbxentry->mb7 = cpu_to_le16(LSW(MSD(ha->iodesc_pd_dma)));
490 mbxentry->mb10 = __constant_cpu_to_le16(BIT_0);
491 wmb();
493 qla2x00_add_iodesc_timer(iodesc);
495 /* Issue command to ISP. */
496 qla2x00_isp_cmd(ha);
498 if (!ha_locked)
499 spin_unlock_irqrestore(&ha->hardware_lock, flags);
501 DEBUG14(printk("scsi(%ld): Sending Adisc IOCB (%08x) to [%x].\n",
502 ha->host_no, iodesc->signature, iodesc->remote_fcport->loop_id));
504 return (QLA_SUCCESS);
508 * qla2x00_send_adisc_iocb_cb() - Get Port Database IOCB callback.
509 * @ha: HA context
510 * @iodesc: io descriptor
511 * @mbxstat: mailbox status IOCB
513 * Returns QLA_SUCCESS if @iodesc can be freed by the caller, else, @iodesc
514 * will be used for a retry.
516 static int
517 qla2x00_send_adisc_iocb_cb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
518 struct mbx_entry *mbxstat)
520 fc_port_t *remote_fcport;
522 remote_fcport = iodesc->remote_fcport;
524 /* Ensure the port IDs are consistent. */
525 if (remote_fcport->d_id.b24 != iodesc->d_id.b24) {
526 DEBUG14(printk("scsi(%ld): Adisc IOCB -- ignoring, remote port "
527 "id changed from [%02x%02x%02x] to [%02x%02x%02x].\n",
528 ha->host_no, remote_fcport->d_id.b.domain,
529 remote_fcport->d_id.b.area, remote_fcport->d_id.b.al_pa,
530 iodesc->d_id.b.domain, iodesc->d_id.b.area,
531 iodesc->d_id.b.al_pa));
533 return (QLA_SUCCESS);
536 /* Only process the last command. */
537 if (remote_fcport->iodesc_idx_sent != iodesc->idx) {
538 DEBUG14(printk("scsi(%ld): Adisc IOCB -- ignoring, sent to "
539 "[%02x%02x%02x], expected %x, received %x.\n", ha->host_no,
540 iodesc->d_id.b.domain, iodesc->d_id.b.area,
541 iodesc->d_id.b.al_pa, remote_fcport->iodesc_idx_sent,
542 iodesc->idx));
544 return (QLA_SUCCESS);
547 if (le16_to_cpu(mbxstat->status) == CS_COMPLETE) {
548 DEBUG14(printk("scsi(%ld): Adisc IOCB -- marking "
549 "[%x/%02x%02x%02x] online.\n", ha->host_no,
550 remote_fcport->loop_id, remote_fcport->d_id.b.domain,
551 remote_fcport->d_id.b.area, remote_fcport->d_id.b.al_pa));
553 atomic_set(&remote_fcport->state, FCS_ONLINE);
554 } else {
555 DEBUG14(printk("scsi(%ld): Adisc IOCB -- marking "
556 "[%x/%02x%02x%02x] lost, status=%x mb0=%x.\n", ha->host_no,
557 remote_fcport->loop_id, remote_fcport->d_id.b.domain,
558 remote_fcport->d_id.b.area, remote_fcport->d_id.b.al_pa,
559 le16_to_cpu(mbxstat->status), le16_to_cpu(mbxstat->mb0)));
561 if (atomic_read(&remote_fcport->state) != FCS_DEVICE_DEAD)
562 atomic_set(&remote_fcport->state, FCS_DEVICE_LOST);
564 remote_fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
566 return (QLA_SUCCESS);
571 * qla2x00_send_logout_iocb() - Issue a fabric port logout IOCB to the firmware.
572 * @ha: HA context
573 * @iodesc: io descriptor
574 * @ha_locked: is function called with the hardware lock
576 * Returns QLA_SUCCESS if the IOCB was issued.
578 static int
579 qla2x00_send_logout_iocb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
580 int ha_locked)
582 unsigned long flags = 0;
583 struct mbx_entry *mbxentry;
585 /* Send marker if required. */
586 if (qla2x00_issue_marker(ha, ha_locked) != QLA_SUCCESS)
587 return (QLA_FUNCTION_FAILED);
589 if (!ha_locked)
590 spin_lock_irqsave(&ha->hardware_lock, flags);
592 /* Build fabric port logout mailbox IOCB. */
593 mbxentry = qla2x00_get_mbx_iocb_entry(ha, iodesc->signature);
594 if (mbxentry == NULL) {
595 if (!ha_locked)
596 spin_unlock_irqrestore(&ha->hardware_lock, flags);
598 return (QLA_FUNCTION_FAILED);
600 mbxentry->mb0 = __constant_cpu_to_le16(MBC_LOGOUT_FABRIC_PORT);
601 mbxentry->mb1 = mbxentry->loop_id.extended =
602 cpu_to_le16(iodesc->remote_fcport->loop_id);
603 wmb();
605 qla2x00_add_iodesc_timer(iodesc);
607 /* Issue command to ISP. */
608 qla2x00_isp_cmd(ha);
610 if (!ha_locked)
611 spin_unlock_irqrestore(&ha->hardware_lock, flags);
613 DEBUG14(printk("scsi(%ld): Sending Logout IOCB (%08x) to [%x].\n",
614 ha->host_no, iodesc->signature, iodesc->remote_fcport->loop_id));
616 return (QLA_SUCCESS);
620 * qla2x00_send_logout_iocb_cb() - Fabric port logout IOCB callback.
621 * @ha: HA context
622 * @iodesc: io descriptor
623 * @mbxstat: mailbox status IOCB
625 * Returns QLA_SUCCESS if @iodesc can be freed by the caller, else, @iodesc
626 * will be used for a retry.
628 static int
629 qla2x00_send_logout_iocb_cb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
630 struct mbx_entry *mbxstat)
632 DEBUG14(printk("scsi(%ld): Logout IOCB -- sent to [%x/%02x%02x%02x], "
633 "status=%x mb0=%x mb1=%x.\n", ha->host_no,
634 iodesc->remote_fcport->loop_id,
635 iodesc->remote_fcport->d_id.b.domain,
636 iodesc->remote_fcport->d_id.b.area,
637 iodesc->remote_fcport->d_id.b.al_pa, le16_to_cpu(mbxstat->status),
638 le16_to_cpu(mbxstat->mb0), le16_to_cpu(mbxstat->mb1)));
640 return (QLA_SUCCESS);
645 * qla2x00_send_login_iocb() - Issue a fabric port login IOCB to the firmware.
646 * @ha: HA context
647 * @iodesc: io descriptor
648 * @d_id: port id for device
649 * @ha_locked: is function called with the hardware lock
651 * Returns QLA_SUCCESS if the IOCB was issued.
653 static int
654 qla2x00_send_login_iocb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
655 port_id_t *d_id, int ha_locked)
657 unsigned long flags = 0;
658 struct mbx_entry *mbxentry;
660 /* Send marker if required. */
661 if (qla2x00_issue_marker(ha, ha_locked) != QLA_SUCCESS)
662 return (QLA_FUNCTION_FAILED);
664 if (!ha_locked)
665 spin_lock_irqsave(&ha->hardware_lock, flags);
667 /* Build fabric port login mailbox IOCB. */
668 mbxentry = qla2x00_get_mbx_iocb_entry(ha, iodesc->signature);
669 if (mbxentry == NULL) {
670 if (!ha_locked)
671 spin_unlock_irqrestore(&ha->hardware_lock, flags);
673 return (QLA_FUNCTION_FAILED);
675 mbxentry->mb0 = __constant_cpu_to_le16(MBC_LOGIN_FABRIC_PORT);
676 mbxentry->mb1 = mbxentry->loop_id.extended =
677 cpu_to_le16(iodesc->remote_fcport->loop_id);
678 mbxentry->mb2 = cpu_to_le16(d_id->b.domain);
679 mbxentry->mb3 = cpu_to_le16(d_id->b.area << 8 | d_id->b.al_pa);
680 mbxentry->mb10 = __constant_cpu_to_le16(BIT_0);
681 wmb();
683 qla2x00_add_iodesc_timer(iodesc);
685 /* Issue command to ISP. */
686 qla2x00_isp_cmd(ha);
688 if (!ha_locked)
689 spin_unlock_irqrestore(&ha->hardware_lock, flags);
691 DEBUG14(printk("scsi(%ld): Sending Login IOCB (%08x) to "
692 "[%x/%02x%02x%02x].\n", ha->host_no, iodesc->signature,
693 iodesc->remote_fcport->loop_id, d_id->b.domain, d_id->b.area,
694 d_id->b.al_pa));
696 return (QLA_SUCCESS);
700 * qla2x00_send_login_iocb_cb() - Fabric port logout IOCB callback.
701 * @ha: HA context
702 * @iodesc: io descriptor
703 * @mbxstat: mailbox status IOCB
705 * Returns QLA_SUCCESS if @iodesc can be freed by the caller, else, @iodesc
706 * will be used for a retry.
708 static int
709 qla2x00_send_login_iocb_cb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
710 struct mbx_entry *mbxstat)
712 int rval;
713 fc_port_t *fcport, *remote_fcport, *exist_fcport;
714 struct io_descriptor *abort_iodesc, *login_iodesc;
715 uint16_t status, mb[8];
716 uint16_t reuse;
717 uint16_t remote_loopid;
718 port_id_t remote_did, inuse_did;
720 remote_fcport = iodesc->remote_fcport;
722 /* Only process the last command. */
723 if (remote_fcport->iodesc_idx_sent != iodesc->idx) {
724 DEBUG14(printk("scsi(%ld): Login IOCB -- ignoring, sent to "
725 "[%02x%02x%02x], expected %x, received %x.\n",
726 ha->host_no, iodesc->d_id.b.domain, iodesc->d_id.b.area,
727 iodesc->d_id.b.al_pa, remote_fcport->iodesc_idx_sent,
728 iodesc->idx));
730 /* Free RSCN fcport resources. */
731 if (remote_fcport->port_type == FCT_RSCN) {
732 DEBUG14(printk("scsi(%ld): Login IOCB -- Freeing RSCN "
733 "fcport %p [%x/%02x%02x%02x] given ignored Login "
734 "IOCB.\n", ha->host_no, remote_fcport,
735 remote_fcport->loop_id,
736 remote_fcport->d_id.b.domain,
737 remote_fcport->d_id.b.area,
738 remote_fcport->d_id.b.al_pa));
740 list_del(&remote_fcport->list);
741 kfree(remote_fcport);
743 return (QLA_SUCCESS);
746 status = le16_to_cpu(mbxstat->status);
747 mb[0] = le16_to_cpu(mbxstat->mb0);
748 mb[1] = le16_to_cpu(mbxstat->mb1);
749 mb[2] = le16_to_cpu(mbxstat->mb2);
750 mb[6] = le16_to_cpu(mbxstat->mb6);
751 mb[7] = le16_to_cpu(mbxstat->mb7);
753 /* Good status? */
754 if ((status == CS_COMPLETE || status == CS_COMPLETE_CHKCOND) &&
755 mb[0] == MBS_COMMAND_COMPLETE) {
757 DEBUG14(printk("scsi(%ld): Login IOCB -- status=%x mb1=%x pn="
758 "%02x%02x%02x%02x%02x%02x%02x%02x.\n", ha->host_no, status,
759 mb[1], mbxstat->port_name[0], mbxstat->port_name[1],
760 mbxstat->port_name[2], mbxstat->port_name[3],
761 mbxstat->port_name[4], mbxstat->port_name[5],
762 mbxstat->port_name[6], mbxstat->port_name[7]));
764 memcpy(remote_fcport->node_name, mbxstat->node_name, WWN_SIZE);
765 memcpy(remote_fcport->port_name, mbxstat->port_name, WWN_SIZE);
767 /* Is the device already in our fcports list? */
768 if (remote_fcport->port_type != FCT_RSCN) {
769 DEBUG14(printk("scsi(%ld): Login IOCB -- marking "
770 "[%x/%02x%02x%02x] online.\n", ha->host_no,
771 remote_fcport->loop_id,
772 remote_fcport->d_id.b.domain,
773 remote_fcport->d_id.b.area,
774 remote_fcport->d_id.b.al_pa));
776 qla2x00_update_login_fcport(ha, mbxstat, remote_fcport);
778 return (QLA_SUCCESS);
781 /* Does the RSCN portname already exist in our fcports list? */
782 exist_fcport = NULL;
783 list_for_each_entry(fcport, &ha->fcports, list) {
784 if (memcmp(remote_fcport->port_name, fcport->port_name,
785 WWN_SIZE) == 0) {
786 exist_fcport = fcport;
787 break;
790 if (exist_fcport != NULL) {
791 DEBUG14(printk("scsi(%ld): Login IOCB -- found RSCN "
792 "fcport in fcports list [%p].\n", ha->host_no,
793 exist_fcport));
795 /* Abort any ADISC that could have been sent. */
796 if (exist_fcport->iodesc_idx_sent != iodesc->idx &&
797 exist_fcport->iodesc_idx_sent <
798 MAX_IO_DESCRIPTORS &&
799 ha->io_descriptors[exist_fcport->iodesc_idx_sent].
800 cb_idx == ADISC_PORT_IOCB_CB) {
802 abort_iodesc = qla2x00_alloc_iodesc(ha);
803 if (abort_iodesc) {
804 DEBUG14(printk("scsi(%ld): Login IOCB "
805 "-- issuing abort to outstanding "
806 "Adisc [%x/%02x%02x%02x].\n",
807 ha->host_no, remote_fcport->loop_id,
808 exist_fcport->d_id.b.domain,
809 exist_fcport->d_id.b.area,
810 exist_fcport->d_id.b.al_pa));
812 abort_iodesc->cb_idx = ABORT_IOCB_CB;
813 abort_iodesc->d_id.b24 =
814 exist_fcport->d_id.b24;
815 abort_iodesc->remote_fcport =
816 exist_fcport;
817 exist_fcport->iodesc_idx_sent =
818 abort_iodesc->idx;
819 qla2x00_send_abort_iocb(ha,
820 abort_iodesc, ha->io_descriptors[
821 exist_fcport->iodesc_idx_sent].
822 signature, 1);
823 } else {
824 DEBUG14(printk("scsi(%ld): Login IOCB "
825 "-- unable to abort outstanding "
826 "Adisc [%x/%02x%02x%02x].\n",
827 ha->host_no, remote_fcport->loop_id,
828 exist_fcport->d_id.b.domain,
829 exist_fcport->d_id.b.area,
830 exist_fcport->d_id.b.al_pa));
835 * If the existing fcport is waiting to send an ADISC
836 * or LOGIN, then reuse remote fcport (RSCN) to
837 * continue waiting.
839 reuse = 0;
840 remote_loopid = remote_fcport->loop_id;
841 remote_did.b24 = remote_fcport->d_id.b24;
842 if (exist_fcport->iodesc_idx_sent ==
843 IODESC_ADISC_NEEDED ||
844 exist_fcport->iodesc_idx_sent ==
845 IODESC_LOGIN_NEEDED) {
846 DEBUG14(printk("scsi(%ld): Login IOCB -- "
847 "existing fcport [%x/%02x%02x%02x] "
848 "waiting for IO descriptor, reuse RSCN "
849 "fcport.\n", ha->host_no,
850 exist_fcport->loop_id,
851 exist_fcport->d_id.b.domain,
852 exist_fcport->d_id.b.area,
853 exist_fcport->d_id.b.al_pa));
855 reuse++;
856 remote_fcport->iodesc_idx_sent =
857 exist_fcport->iodesc_idx_sent;
858 exist_fcport->iodesc_idx_sent =
859 IODESC_INVALID_INDEX;
860 remote_fcport->loop_id = exist_fcport->loop_id;
861 remote_fcport->d_id.b24 =
862 exist_fcport->d_id.b24;
865 /* Logout the old loopid. */
866 if (!reuse &&
867 exist_fcport->loop_id != remote_fcport->loop_id &&
868 exist_fcport->loop_id != FC_NO_LOOP_ID) {
869 login_iodesc = qla2x00_alloc_iodesc(ha);
870 if (login_iodesc) {
871 DEBUG14(printk("scsi(%ld): Login IOCB "
872 "-- issuing logout to free old "
873 "loop id [%x/%02x%02x%02x].\n",
874 ha->host_no, exist_fcport->loop_id,
875 exist_fcport->d_id.b.domain,
876 exist_fcport->d_id.b.area,
877 exist_fcport->d_id.b.al_pa));
879 login_iodesc->cb_idx =
880 LOGOUT_PORT_IOCB_CB;
881 login_iodesc->d_id.b24 =
882 exist_fcport->d_id.b24;
883 login_iodesc->remote_fcport =
884 exist_fcport;
885 exist_fcport->iodesc_idx_sent =
886 login_iodesc->idx;
887 qla2x00_send_logout_iocb(ha,
888 login_iodesc, 1);
889 } else {
890 /* Ran out of IO descriptiors. */
891 DEBUG14(printk("scsi(%ld): Login IOCB "
892 "-- unable to logout to free old "
893 "loop id [%x/%02x%02x%02x].\n",
894 ha->host_no, exist_fcport->loop_id,
895 exist_fcport->d_id.b.domain,
896 exist_fcport->d_id.b.area,
897 exist_fcport->d_id.b.al_pa));
899 exist_fcport->iodesc_idx_sent =
900 IODESC_INVALID_INDEX;
905 /* Update existing fcport with remote fcport info. */
906 DEBUG14(printk("scsi(%ld): Login IOCB -- marking "
907 "existing fcport [%x/%02x%02x%02x] online.\n",
908 ha->host_no, remote_loopid, remote_did.b.domain,
909 remote_did.b.area, remote_did.b.al_pa));
911 memcpy(exist_fcport->node_name,
912 remote_fcport->node_name, WWN_SIZE);
913 exist_fcport->loop_id = remote_loopid;
914 exist_fcport->d_id.b24 = remote_did.b24;
915 qla2x00_update_login_fcport(ha, mbxstat, exist_fcport);
917 /* Finally, free the remote (RSCN) fcport. */
918 if (!reuse) {
919 DEBUG14(printk("scsi(%ld): Login IOCB -- "
920 "Freeing RSCN fcport %p "
921 "[%x/%02x%02x%02x].\n", ha->host_no,
922 remote_fcport, remote_fcport->loop_id,
923 remote_fcport->d_id.b.domain,
924 remote_fcport->d_id.b.area,
925 remote_fcport->d_id.b.al_pa));
927 list_del(&remote_fcport->list);
928 kfree(remote_fcport);
931 return (QLA_SUCCESS);
935 * A new device has been added, move the RSCN fcport to our
936 * fcports list.
938 DEBUG14(printk("scsi(%ld): Login IOCB -- adding RSCN fcport "
939 "[%x/%02x%02x%02x] to fcports list.\n", ha->host_no,
940 remote_fcport->loop_id, remote_fcport->d_id.b.domain,
941 remote_fcport->d_id.b.area, remote_fcport->d_id.b.al_pa));
943 list_del(&remote_fcport->list);
944 remote_fcport->flags = (FCF_RLC_SUPPORT | FCF_RESCAN_NEEDED);
945 qla2x00_update_login_fcport(ha, mbxstat, remote_fcport);
946 list_add_tail(&remote_fcport->list, &ha->fcports);
947 set_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags);
948 } else {
949 /* Handle login failure. */
950 if (remote_fcport->login_retry != 0) {
951 if (mb[0] == MBS_LOOP_ID_USED) {
952 inuse_did.b.domain = LSB(mb[1]);
953 inuse_did.b.area = MSB(mb[2]);
954 inuse_did.b.al_pa = LSB(mb[2]);
956 DEBUG14(printk("scsi(%ld): Login IOCB -- loop "
957 "id [%x] used by port id [%02x%02x%02x].\n",
958 ha->host_no, remote_fcport->loop_id,
959 inuse_did.b.domain, inuse_did.b.area,
960 inuse_did.b.al_pa));
962 if (remote_fcport->d_id.b24 ==
963 INVALID_PORT_ID) {
965 * Invalid port id means we are trying
966 * to login to a remote port with just
967 * a loop id without knowing about the
968 * port id. Copy the port id and try
969 * again.
971 remote_fcport->d_id.b24 = inuse_did.b24;
972 iodesc->d_id.b24 = inuse_did.b24;
973 } else {
974 remote_fcport->loop_id++;
975 rval = qla2x00_find_new_loop_id(ha,
976 remote_fcport);
977 if (rval == QLA_FUNCTION_FAILED) {
978 /* No more loop ids. */
979 return (QLA_SUCCESS);
982 } else if (mb[0] == MBS_PORT_ID_USED) {
984 * Device has another loop ID. The firmware
985 * group recommends the driver perform an
986 * implicit login with the specified ID.
988 DEBUG14(printk("scsi(%ld): Login IOCB -- port "
989 "id [%02x%02x%02x] already assigned to "
990 "loop id [%x].\n", ha->host_no,
991 iodesc->d_id.b.domain, iodesc->d_id.b.area,
992 iodesc->d_id.b.al_pa, mb[1]));
994 remote_fcport->loop_id = mb[1];
996 } else {
997 /* Unable to perform login, try again. */
998 DEBUG14(printk("scsi(%ld): Login IOCB -- "
999 "failed login [%x/%02x%02x%02x], status=%x "
1000 "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n",
1001 ha->host_no, remote_fcport->loop_id,
1002 iodesc->d_id.b.domain, iodesc->d_id.b.area,
1003 iodesc->d_id.b.al_pa, status, mb[0], mb[1],
1004 mb[2], mb[6], mb[7]));
1007 /* Reissue Login with the same IO descriptor. */
1008 iodesc->signature =
1009 qla2x00_iodesc_to_handle(iodesc);
1010 iodesc->cb_idx = LOGIN_PORT_IOCB_CB;
1011 iodesc->d_id.b24 = remote_fcport->d_id.b24;
1012 remote_fcport->iodesc_idx_sent = iodesc->idx;
1013 remote_fcport->login_retry--;
1015 DEBUG14(printk("scsi(%ld): Login IOCB -- retrying "
1016 "login to [%x/%02x%02x%02x] (%d).\n", ha->host_no,
1017 remote_fcport->loop_id,
1018 remote_fcport->d_id.b.domain,
1019 remote_fcport->d_id.b.area,
1020 remote_fcport->d_id.b.al_pa,
1021 remote_fcport->login_retry));
1023 qla2x00_send_login_iocb(ha, iodesc,
1024 &remote_fcport->d_id, 1);
1026 return (QLA_FUNCTION_FAILED);
1027 } else {
1028 /* No more logins, mark device dead. */
1029 DEBUG14(printk("scsi(%ld): Login IOCB -- failed "
1030 "login [%x/%02x%02x%02x] after retries, status=%x "
1031 "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n",
1032 ha->host_no, remote_fcport->loop_id,
1033 iodesc->d_id.b.domain, iodesc->d_id.b.area,
1034 iodesc->d_id.b.al_pa, status, mb[0], mb[1],
1035 mb[2], mb[6], mb[7]));
1037 atomic_set(&remote_fcport->state, FCS_DEVICE_DEAD);
1038 if (remote_fcport->port_type == FCT_RSCN) {
1039 DEBUG14(printk("scsi(%ld): Login IOCB -- "
1040 "Freeing dead RSCN fcport %p "
1041 "[%x/%02x%02x%02x].\n", ha->host_no,
1042 remote_fcport, remote_fcport->loop_id,
1043 remote_fcport->d_id.b.domain,
1044 remote_fcport->d_id.b.area,
1045 remote_fcport->d_id.b.al_pa));
1047 list_del(&remote_fcport->list);
1048 kfree(remote_fcport);
1053 return (QLA_SUCCESS);
1058 * IO descriptor processing routines.
1062 * qla2x00_alloc_rscn_fcport() - Allocate an RSCN type fcport.
1063 * @ha: HA context
1064 * @flags: allocation flags
1066 * Returns a pointer to the allocated RSCN fcport, or NULL, if none available.
1068 fc_port_t *
1069 qla2x00_alloc_rscn_fcport(scsi_qla_host_t *ha, int flags)
1071 fc_port_t *fcport;
1073 fcport = qla2x00_alloc_fcport(ha, flags);
1074 if (fcport == NULL)
1075 return (fcport);
1077 /* Setup RSCN fcport structure. */
1078 fcport->port_type = FCT_RSCN;
1080 return (fcport);
1084 * qla2x00_handle_port_rscn() - Handle port RSCN.
1085 * @ha: HA context
1086 * @rscn_entry: RSCN entry
1087 * @fcport: fcport entry to updated
1089 * Returns QLA_SUCCESS if the port RSCN was handled.
1092 qla2x00_handle_port_rscn(scsi_qla_host_t *ha, uint32_t rscn_entry,
1093 fc_port_t *known_fcport, int ha_locked)
1095 int rval;
1096 port_id_t rscn_pid;
1097 fc_port_t *fcport, *remote_fcport, *rscn_fcport;
1098 struct io_descriptor *iodesc;
1100 remote_fcport = NULL;
1101 rscn_fcport = NULL;
1103 /* Prepare port id based on incoming entries. */
1104 if (known_fcport) {
1105 rscn_pid.b24 = known_fcport->d_id.b24;
1106 remote_fcport = known_fcport;
1108 DEBUG14(printk("scsi(%ld): Handle RSCN -- process RSCN for "
1109 "fcport [%02x%02x%02x].\n", ha->host_no,
1110 remote_fcport->d_id.b.domain, remote_fcport->d_id.b.area,
1111 remote_fcport->d_id.b.al_pa));
1112 } else {
1113 rscn_pid.b.domain = LSB(MSW(rscn_entry));
1114 rscn_pid.b.area = MSB(LSW(rscn_entry));
1115 rscn_pid.b.al_pa = LSB(LSW(rscn_entry));
1117 DEBUG14(printk("scsi(%ld): Handle RSCN -- process RSCN for "
1118 "port id [%02x%02x%02x].\n", ha->host_no,
1119 rscn_pid.b.domain, rscn_pid.b.area, rscn_pid.b.al_pa));
1122 * Search fcport lists for a known entry at the specified port
1123 * ID.
1125 list_for_each_entry(fcport, &ha->fcports, list) {
1126 if (rscn_pid.b24 == fcport->d_id.b24) {
1127 remote_fcport = fcport;
1128 break;
1131 list_for_each_entry(fcport, &ha->rscn_fcports, list) {
1132 if (rscn_pid.b24 == fcport->d_id.b24) {
1133 rscn_fcport = fcport;
1134 break;
1137 if (remote_fcport == NULL)
1138 remote_fcport = rscn_fcport;
1142 * If the port is already in our fcport list and online, send an ADISC
1143 * to see if it's still alive. Issue login if a new fcport or the known
1144 * fcport is currently offline.
1146 if (remote_fcport) {
1148 * No need to send request if the remote fcport is currently
1149 * waiting for an available io descriptor.
1151 if (known_fcport == NULL &&
1152 (remote_fcport->iodesc_idx_sent == IODESC_ADISC_NEEDED ||
1153 remote_fcport->iodesc_idx_sent == IODESC_LOGIN_NEEDED)) {
1155 * If previous waiting io descriptor is an ADISC, then
1156 * the new RSCN may come from a new remote fcport being
1157 * plugged into the same location.
1159 if (remote_fcport->port_type == FCT_RSCN) {
1160 remote_fcport->iodesc_idx_sent =
1161 IODESC_LOGIN_NEEDED;
1162 } else if (remote_fcport->iodesc_idx_sent ==
1163 IODESC_ADISC_NEEDED) {
1164 fc_port_t *new_fcport;
1166 remote_fcport->iodesc_idx_sent =
1167 IODESC_INVALID_INDEX;
1169 /* Create new fcport for later login. */
1170 new_fcport = qla2x00_alloc_rscn_fcport(ha,
1171 ha_locked ? GFP_ATOMIC: GFP_KERNEL);
1172 if (new_fcport) {
1173 DEBUG14(printk("scsi(%ld): Handle RSCN "
1174 "-- creating RSCN fcport %p for "
1175 "future login.\n", ha->host_no,
1176 new_fcport));
1178 new_fcport->d_id.b24 =
1179 remote_fcport->d_id.b24;
1180 new_fcport->iodesc_idx_sent =
1181 IODESC_LOGIN_NEEDED;
1183 list_add_tail(&new_fcport->list,
1184 &ha->rscn_fcports);
1185 set_bit(IODESC_PROCESS_NEEDED,
1186 &ha->dpc_flags);
1187 } else {
1188 DEBUG14(printk("scsi(%ld): Handle RSCN "
1189 "-- unable to allocate RSCN fcport "
1190 "for future login.\n",
1191 ha->host_no));
1194 return (QLA_SUCCESS);
1197 /* Send ADISC if the fcport is online */
1198 if (atomic_read(&remote_fcport->state) == FCS_ONLINE ||
1199 remote_fcport->iodesc_idx_sent == IODESC_ADISC_NEEDED) {
1201 atomic_set(&remote_fcport->state, FCS_DEVICE_LOST);
1203 iodesc = qla2x00_alloc_iodesc(ha);
1204 if (iodesc == NULL) {
1205 /* Mark fcport for later adisc processing */
1206 DEBUG14(printk("scsi(%ld): Handle RSCN -- not "
1207 "enough IO descriptors for Adisc, flag "
1208 "for later processing.\n", ha->host_no));
1210 remote_fcport->iodesc_idx_sent =
1211 IODESC_ADISC_NEEDED;
1212 set_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags);
1214 return (QLA_SUCCESS);
1217 iodesc->cb_idx = ADISC_PORT_IOCB_CB;
1218 iodesc->d_id.b24 = rscn_pid.b24;
1219 iodesc->remote_fcport = remote_fcport;
1220 remote_fcport->iodesc_idx_sent = iodesc->idx;
1221 qla2x00_send_adisc_iocb(ha, iodesc, ha_locked);
1223 return (QLA_SUCCESS);
1224 } else if (remote_fcport->iodesc_idx_sent <
1225 MAX_IO_DESCRIPTORS &&
1226 ha->io_descriptors[remote_fcport->iodesc_idx_sent].cb_idx ==
1227 ADISC_PORT_IOCB_CB) {
1229 * Receiving another RSCN while an ADISC is pending,
1230 * abort the IOCB. Use the same descriptor for the
1231 * abort.
1233 uint32_t handle_to_abort;
1235 iodesc = &ha->io_descriptors[
1236 remote_fcport->iodesc_idx_sent];
1237 qla2x00_remove_iodesc_timer(iodesc);
1238 handle_to_abort = iodesc->signature;
1239 iodesc->signature = qla2x00_iodesc_to_handle(iodesc);
1240 iodesc->cb_idx = ABORT_IOCB_CB;
1241 iodesc->d_id.b24 = remote_fcport->d_id.b24;
1242 iodesc->remote_fcport = remote_fcport;
1243 remote_fcport->iodesc_idx_sent = iodesc->idx;
1245 DEBUG14(printk("scsi(%ld): Handle RSCN -- issuing "
1246 "abort to outstanding Adisc [%x/%02x%02x%02x].\n",
1247 ha->host_no, remote_fcport->loop_id,
1248 iodesc->d_id.b.domain, iodesc->d_id.b.area,
1249 iodesc->d_id.b.al_pa));
1251 qla2x00_send_abort_iocb(ha, iodesc, handle_to_abort,
1252 ha_locked);
1256 /* We need to login to the remote port, find it. */
1257 if (known_fcport) {
1258 remote_fcport = known_fcport;
1259 } else if (rscn_fcport && rscn_fcport->d_id.b24 != INVALID_PORT_ID &&
1260 rscn_fcport->iodesc_idx_sent < MAX_IO_DESCRIPTORS &&
1261 ha->io_descriptors[rscn_fcport->iodesc_idx_sent].cb_idx ==
1262 LOGIN_PORT_IOCB_CB) {
1264 * Ignore duplicate RSCN on fcport which has already
1265 * initiated a login IOCB.
1267 DEBUG14(printk("scsi(%ld): Handle RSCN -- ignoring, login "
1268 "already sent to [%02x%02x%02x].\n", ha->host_no,
1269 rscn_fcport->d_id.b.domain, rscn_fcport->d_id.b.area,
1270 rscn_fcport->d_id.b.al_pa));
1272 return (QLA_SUCCESS);
1273 } else if (rscn_fcport && rscn_fcport->d_id.b24 != INVALID_PORT_ID &&
1274 rscn_fcport != remote_fcport) {
1275 /* Reuse same rscn fcport. */
1276 DEBUG14(printk("scsi(%ld): Handle RSCN -- reusing RSCN fcport "
1277 "[%02x%02x%02x].\n", ha->host_no,
1278 rscn_fcport->d_id.b.domain, rscn_fcport->d_id.b.area,
1279 rscn_fcport->d_id.b.al_pa));
1281 remote_fcport = rscn_fcport;
1282 } else {
1283 /* Create new fcport for later login. */
1284 remote_fcport = qla2x00_alloc_rscn_fcport(ha,
1285 ha_locked ? GFP_ATOMIC: GFP_KERNEL);
1286 list_add_tail(&remote_fcport->list, &ha->rscn_fcports);
1288 if (remote_fcport == NULL)
1289 return (QLA_SUCCESS);
1291 /* Prepare fcport for login. */
1292 atomic_set(&remote_fcport->state, FCS_DEVICE_LOST);
1293 remote_fcport->login_retry = 3; /* ha->login_retry_count; */
1294 remote_fcport->d_id.b24 = rscn_pid.b24;
1296 iodesc = qla2x00_alloc_iodesc(ha);
1297 if (iodesc == NULL) {
1298 /* Mark fcport for later adisc processing. */
1299 DEBUG14(printk("scsi(%ld): Handle RSCN -- not enough IO "
1300 "descriptors for Login, flag for later processing.\n",
1301 ha->host_no));
1303 remote_fcport->iodesc_idx_sent = IODESC_LOGIN_NEEDED;
1304 set_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags);
1306 return (QLA_SUCCESS);
1309 if (known_fcport == NULL || rscn_pid.b24 != INVALID_PORT_ID) {
1310 remote_fcport->loop_id = ha->min_external_loopid;
1312 rval = qla2x00_find_new_loop_id(ha, remote_fcport);
1313 if (rval == QLA_FUNCTION_FAILED) {
1314 /* No more loop ids, failed. */
1315 DEBUG14(printk("scsi(%ld): Handle RSCN -- no available "
1316 "loop id to perform Login, failed.\n",
1317 ha->host_no));
1319 return (rval);
1323 iodesc->cb_idx = LOGIN_PORT_IOCB_CB;
1324 iodesc->d_id.b24 = rscn_pid.b24;
1325 iodesc->remote_fcport = remote_fcport;
1326 remote_fcport->iodesc_idx_sent = iodesc->idx;
1328 DEBUG14(printk("scsi(%ld): Handle RSCN -- attempting login to "
1329 "[%x/%02x%02x%02x].\n", ha->host_no, remote_fcport->loop_id,
1330 iodesc->d_id.b.domain, iodesc->d_id.b.area, iodesc->d_id.b.al_pa));
1332 qla2x00_send_login_iocb(ha, iodesc, &rscn_pid, ha_locked);
1334 return (QLA_SUCCESS);
1338 * qla2x00_process_iodesc() - Complete IO descriptor processing.
1339 * @ha: HA context
1340 * @mbxstat: Mailbox IOCB status
1342 void
1343 qla2x00_process_iodesc(scsi_qla_host_t *ha, struct mbx_entry *mbxstat)
1345 int rval;
1346 uint32_t signature;
1347 fc_port_t *fcport;
1348 struct io_descriptor *iodesc;
1350 signature = mbxstat->handle;
1352 DEBUG14(printk("scsi(%ld): Process IODesc -- processing %08x.\n",
1353 ha->host_no, signature));
1355 /* Retrieve proper IO descriptor. */
1356 iodesc = qla2x00_handle_to_iodesc(ha, signature);
1357 if (iodesc == NULL) {
1358 DEBUG14(printk("scsi(%ld): Process IODesc -- ignoring, "
1359 "incorrect signature %08x.\n", ha->host_no, signature));
1361 return;
1364 /* Stop IO descriptor timer. */
1365 qla2x00_remove_iodesc_timer(iodesc);
1367 /* Verify signature match. */
1368 if (iodesc->signature != signature) {
1369 DEBUG14(printk("scsi(%ld): Process IODesc -- ignoring, "
1370 "signature mismatch, sent %08x, received %08x.\n",
1371 ha->host_no, iodesc->signature, signature));
1373 return;
1376 /* Go with IOCB callback. */
1377 rval = iocb_function_cb_list[iodesc->cb_idx](ha, iodesc, mbxstat);
1378 if (rval != QLA_SUCCESS) {
1379 /* IO descriptor reused by callback. */
1380 return;
1383 qla2x00_free_iodesc(iodesc);
1385 if (test_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags)) {
1386 /* Scan our fcports list for any RSCN requests. */
1387 list_for_each_entry(fcport, &ha->fcports, list) {
1388 if (fcport->iodesc_idx_sent == IODESC_ADISC_NEEDED ||
1389 fcport->iodesc_idx_sent == IODESC_LOGIN_NEEDED) {
1390 qla2x00_handle_port_rscn(ha, 0, fcport, 1);
1391 return;
1395 /* Scan our RSCN fcports list for any RSCN requests. */
1396 list_for_each_entry(fcport, &ha->rscn_fcports, list) {
1397 if (fcport->iodesc_idx_sent == IODESC_ADISC_NEEDED ||
1398 fcport->iodesc_idx_sent == IODESC_LOGIN_NEEDED) {
1399 qla2x00_handle_port_rscn(ha, 0, fcport, 1);
1400 return;
1404 clear_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags);
1408 * qla2x00_cancel_io_descriptors() - Cancel all outstanding io descriptors.
1409 * @ha: HA context
1411 * This routine will also delete any RSCN entries related to the outstanding
1412 * IO descriptors.
1414 void
1415 qla2x00_cancel_io_descriptors(scsi_qla_host_t *ha)
1417 fc_port_t *fcport, *fcptemp;
1419 clear_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags);
1421 /* Abort all IO descriptors. */
1422 qla2x00_init_io_descriptors(ha);
1424 /* Reset all pending IO descriptors in fcports list. */
1425 list_for_each_entry(fcport, &ha->fcports, list) {
1426 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1429 /* Reset all pending IO descriptors in rscn fcports list. */
1430 list_for_each_entry_safe(fcport, fcptemp, &ha->rscn_fcports, list) {
1431 DEBUG14(printk("scsi(%ld): Cancel IOs -- Freeing RSCN fcport "
1432 "%p [%x/%02x%02x%02x].\n", ha->host_no, fcport,
1433 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
1434 fcport->d_id.b.al_pa));
1436 list_del(&fcport->list);
1437 kfree(fcport);