1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2008 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/delay.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/idr.h>
26 #include <linux/interrupt.h>
27 #include <linux/kthread.h>
28 #include <linux/pci.h>
29 #include <linux/spinlock.h>
31 #include <scsi/scsi.h>
32 #include <scsi/scsi_device.h>
33 #include <scsi/scsi_host.h>
34 #include <scsi/scsi_transport_fc.h>
38 #include "lpfc_sli4.h"
40 #include "lpfc_disc.h"
41 #include "lpfc_scsi.h"
43 #include "lpfc_logmsg.h"
44 #include "lpfc_crtn.h"
45 #include "lpfc_version.h"
46 #include "lpfc_vport.h"
48 inline void lpfc_vport_set_state(struct lpfc_vport
*vport
,
49 enum fc_vport_state new_state
)
51 struct fc_vport
*fc_vport
= vport
->fc_vport
;
55 * When the transport defines fc_vport_set state we will replace
56 * this code with the following line
58 /* fc_vport_set_state(fc_vport, new_state); */
59 if (new_state
!= FC_VPORT_INITIALIZING
)
60 fc_vport
->vport_last_state
= fc_vport
->vport_state
;
61 fc_vport
->vport_state
= new_state
;
64 /* for all the error states we will set the invternal state to FAILED */
66 case FC_VPORT_NO_FABRIC_SUPP
:
67 case FC_VPORT_NO_FABRIC_RSCS
:
68 case FC_VPORT_FABRIC_LOGOUT
:
69 case FC_VPORT_FABRIC_REJ_WWN
:
71 vport
->port_state
= LPFC_VPORT_FAILED
;
73 case FC_VPORT_LINKDOWN
:
74 vport
->port_state
= LPFC_VPORT_UNKNOWN
;
83 lpfc_alloc_vpi(struct lpfc_hba
*phba
)
87 spin_lock_irq(&phba
->hbalock
);
88 /* Start at bit 1 because vpi zero is reserved for the physical port */
89 vpi
= find_next_zero_bit(phba
->vpi_bmask
, (phba
->max_vpi
+ 1), 1);
90 if (vpi
> phba
->max_vpi
)
93 set_bit(vpi
, phba
->vpi_bmask
);
94 if (phba
->sli_rev
== LPFC_SLI_REV4
)
95 phba
->sli4_hba
.max_cfg_param
.vpi_used
++;
96 spin_unlock_irq(&phba
->hbalock
);
101 lpfc_free_vpi(struct lpfc_hba
*phba
, int vpi
)
105 spin_lock_irq(&phba
->hbalock
);
106 clear_bit(vpi
, phba
->vpi_bmask
);
107 if (phba
->sli_rev
== LPFC_SLI_REV4
)
108 phba
->sli4_hba
.max_cfg_param
.vpi_used
--;
109 spin_unlock_irq(&phba
->hbalock
);
113 lpfc_vport_sparm(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
117 struct lpfc_dmabuf
*mp
;
120 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
126 lpfc_read_sparam(phba
, pmb
, vport
->vpi
);
128 * Grab buffer pointer and clear context1 so we can use
129 * lpfc_sli_issue_box_wait
131 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
132 pmb
->context1
= NULL
;
135 rc
= lpfc_sli_issue_mbox_wait(phba
, pmb
, phba
->fc_ratov
* 2);
136 if (rc
!= MBX_SUCCESS
) {
137 if (signal_pending(current
)) {
138 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
139 "1830 Signal aborted mbxCmd x%x\n",
141 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
143 if (rc
!= MBX_TIMEOUT
)
144 mempool_free(pmb
, phba
->mbox_mem_pool
);
147 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
148 "1818 VPort failed init, mbxCmd x%x "
149 "READ_SPARM mbxStatus x%x, rc = x%x\n",
150 mb
->mbxCommand
, mb
->mbxStatus
, rc
);
151 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
153 if (rc
!= MBX_TIMEOUT
)
154 mempool_free(pmb
, phba
->mbox_mem_pool
);
159 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof (struct serv_parm
));
160 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
161 sizeof (struct lpfc_name
));
162 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
163 sizeof (struct lpfc_name
));
165 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
167 mempool_free(pmb
, phba
->mbox_mem_pool
);
173 lpfc_valid_wwn_format(struct lpfc_hba
*phba
, struct lpfc_name
*wwn
,
174 const char *name_type
)
176 /* ensure that IEEE format 1 addresses
177 * contain zeros in bits 59-48
179 if (!((wwn
->u
.wwn
[0] >> 4) == 1 &&
180 ((wwn
->u
.wwn
[0] & 0xf) != 0 || (wwn
->u
.wwn
[1] & 0xf) != 0)))
183 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
184 "1822 Invalid %s: %02x:%02x:%02x:%02x:"
185 "%02x:%02x:%02x:%02x\n",
187 wwn
->u
.wwn
[0], wwn
->u
.wwn
[1],
188 wwn
->u
.wwn
[2], wwn
->u
.wwn
[3],
189 wwn
->u
.wwn
[4], wwn
->u
.wwn
[5],
190 wwn
->u
.wwn
[6], wwn
->u
.wwn
[7]);
195 lpfc_unique_wwpn(struct lpfc_hba
*phba
, struct lpfc_vport
*new_vport
)
197 struct lpfc_vport
*vport
;
200 spin_lock_irqsave(&phba
->hbalock
, flags
);
201 list_for_each_entry(vport
, &phba
->port_list
, listentry
) {
202 if (vport
== new_vport
)
204 /* If they match, return not unique */
205 if (memcmp(&vport
->fc_sparam
.portName
,
206 &new_vport
->fc_sparam
.portName
,
207 sizeof(struct lpfc_name
)) == 0) {
208 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
212 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
217 * lpfc_discovery_wait - Wait for driver discovery to quiesce
218 * @vport: The virtual port for which this call is being executed.
220 * This driver calls this routine specifically from lpfc_vport_delete
221 * to enforce a synchronous execution of vport
222 * delete relative to discovery activities. The
223 * lpfc_vport_delete routine should not return until it
224 * can reasonably guarantee that discovery has quiesced.
225 * Post FDISC LOGO, the driver must wait until its SAN teardown is
226 * complete and all resources recovered before allowing
229 * This routine does not require any locks held.
231 static void lpfc_discovery_wait(struct lpfc_vport
*vport
)
233 struct lpfc_hba
*phba
= vport
->phba
;
234 uint32_t wait_flags
= 0;
235 unsigned long wait_time_max
;
236 unsigned long start_time
;
238 wait_flags
= FC_RSCN_MODE
| FC_RSCN_DISCOVERY
| FC_NLP_MORE
|
239 FC_RSCN_DEFERRED
| FC_NDISC_ACTIVE
| FC_DISC_TMO
;
242 * The time constraint on this loop is a balance between the
243 * fabric RA_TOV value and dev_loss tmo. The driver's
244 * devloss_tmo is 10 giving this loop a 3x multiplier minimally.
246 wait_time_max
= msecs_to_jiffies(((phba
->fc_ratov
* 3) + 3) * 1000);
247 wait_time_max
+= jiffies
;
248 start_time
= jiffies
;
249 while (time_before(jiffies
, wait_time_max
)) {
250 if ((vport
->num_disc_nodes
> 0) ||
251 (vport
->fc_flag
& wait_flags
) ||
252 ((vport
->port_state
> LPFC_VPORT_FAILED
) &&
253 (vport
->port_state
< LPFC_VPORT_READY
))) {
254 lpfc_printf_log(phba
, KERN_INFO
, LOG_VPORT
,
255 "1833 Vport discovery quiesce Wait:"
256 " vpi x%x state x%x fc_flags x%x"
257 " num_nodes x%x, waiting 1000 msecs"
258 " total wait msecs x%x\n",
259 vport
->vpi
, vport
->port_state
,
260 vport
->fc_flag
, vport
->num_disc_nodes
,
261 jiffies_to_msecs(jiffies
- start_time
));
264 /* Base case. Wait variants satisfied. Break out */
265 lpfc_printf_log(phba
, KERN_INFO
, LOG_VPORT
,
266 "1834 Vport discovery quiesced:"
267 " vpi x%x state x%x fc_flags x%x"
269 vport
->vpi
, vport
->port_state
,
271 jiffies_to_msecs(jiffies
277 if (time_after(jiffies
, wait_time_max
))
278 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
279 "1835 Vport discovery quiesce failed:"
280 " vpi x%x state x%x fc_flags x%x"
282 vport
->vpi
, vport
->port_state
,
284 jiffies_to_msecs(jiffies
- start_time
));
288 lpfc_vport_create(struct fc_vport
*fc_vport
, bool disable
)
290 struct lpfc_nodelist
*ndlp
;
291 struct Scsi_Host
*shost
= fc_vport
->shost
;
292 struct lpfc_vport
*pport
= (struct lpfc_vport
*) shost
->hostdata
;
293 struct lpfc_hba
*phba
= pport
->phba
;
294 struct lpfc_vport
*vport
= NULL
;
297 int rc
= VPORT_ERROR
;
300 if ((phba
->sli_rev
< 3) || !(phba
->cfg_enable_npiv
)) {
301 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
302 "1808 Create VPORT failed: "
303 "NPIV is not enabled: SLImode:%d\n",
309 vpi
= lpfc_alloc_vpi(phba
);
311 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
312 "1809 Create VPORT failed: "
313 "Max VPORTs (%d) exceeded\n",
315 rc
= VPORT_NORESOURCES
;
320 * In SLI4, the vpi must be activated before it can be used
323 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
324 rc
= lpfc_sli4_init_vpi(phba
, vpi
);
326 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
327 "1838 Failed to INIT_VPI on vpi %d "
328 "status %d\n", vpi
, rc
);
329 rc
= VPORT_NORESOURCES
;
330 lpfc_free_vpi(phba
, vpi
);
335 /* Assign an unused board number */
336 if ((instance
= lpfc_get_instance()) < 0) {
337 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
338 "1810 Create VPORT failed: Cannot get "
339 "instance number\n");
340 lpfc_free_vpi(phba
, vpi
);
341 rc
= VPORT_NORESOURCES
;
345 vport
= lpfc_create_port(phba
, instance
, &fc_vport
->dev
);
347 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
348 "1811 Create VPORT failed: vpi x%x\n", vpi
);
349 lpfc_free_vpi(phba
, vpi
);
350 rc
= VPORT_NORESOURCES
;
355 lpfc_debugfs_initialize(vport
);
357 if ((status
= lpfc_vport_sparm(phba
, vport
))) {
358 if (status
== -EINTR
) {
359 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
360 "1831 Create VPORT Interrupted.\n");
363 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
364 "1813 Create VPORT failed. "
365 "Cannot get sparam\n");
366 rc
= VPORT_NORESOURCES
;
368 lpfc_free_vpi(phba
, vpi
);
373 memcpy(vport
->fc_portname
.u
.wwn
, vport
->fc_sparam
.portName
.u
.wwn
, 8);
374 memcpy(vport
->fc_nodename
.u
.wwn
, vport
->fc_sparam
.nodeName
.u
.wwn
, 8);
375 if (fc_vport
->node_name
!= 0)
376 u64_to_wwn(fc_vport
->node_name
, vport
->fc_nodename
.u
.wwn
);
377 if (fc_vport
->port_name
!= 0)
378 u64_to_wwn(fc_vport
->port_name
, vport
->fc_portname
.u
.wwn
);
380 memcpy(&vport
->fc_sparam
.portName
, vport
->fc_portname
.u
.wwn
, 8);
381 memcpy(&vport
->fc_sparam
.nodeName
, vport
->fc_nodename
.u
.wwn
, 8);
383 if (!lpfc_valid_wwn_format(phba
, &vport
->fc_sparam
.nodeName
, "WWNN") ||
384 !lpfc_valid_wwn_format(phba
, &vport
->fc_sparam
.portName
, "WWPN")) {
385 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
386 "1821 Create VPORT failed. "
387 "Invalid WWN format\n");
388 lpfc_free_vpi(phba
, vpi
);
394 if (!lpfc_unique_wwpn(phba
, vport
)) {
395 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
396 "1823 Create VPORT failed. "
397 "Duplicate WWN on HBA\n");
398 lpfc_free_vpi(phba
, vpi
);
404 /* Create binary sysfs attribute for vport */
405 lpfc_alloc_sysfs_attr(vport
);
407 *(struct lpfc_vport
**)fc_vport
->dd_data
= vport
;
408 vport
->fc_vport
= fc_vport
;
410 if ((phba
->link_state
< LPFC_LINK_UP
) ||
411 (phba
->fc_topology
== TOPOLOGY_LOOP
)) {
412 lpfc_vport_set_state(vport
, FC_VPORT_LINKDOWN
);
418 lpfc_vport_set_state(vport
, FC_VPORT_DISABLED
);
423 /* Use the Physical nodes Fabric NDLP to determine if the link is
424 * up and ready to FDISC.
426 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
427 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
428 ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
429 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
) {
430 lpfc_set_disctmo(vport
);
431 lpfc_initial_fdisc(vport
);
433 lpfc_vport_set_state(vport
, FC_VPORT_NO_FABRIC_SUPP
);
434 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
435 "0262 No NPIV Fabric support\n");
438 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
443 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
444 "1825 Vport Created.\n");
445 lpfc_host_attrib_init(lpfc_shost_from_vport(vport
));
451 disable_vport(struct fc_vport
*fc_vport
)
453 struct lpfc_vport
*vport
= *(struct lpfc_vport
**)fc_vport
->dd_data
;
454 struct lpfc_hba
*phba
= vport
->phba
;
455 struct lpfc_nodelist
*ndlp
= NULL
, *next_ndlp
= NULL
;
458 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
459 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)
460 && phba
->link_state
>= LPFC_LINK_UP
) {
461 vport
->unreg_vpi_cmpl
= VPORT_INVAL
;
462 timeout
= msecs_to_jiffies(phba
->fc_ratov
* 2000);
463 if (!lpfc_issue_els_npiv_logo(vport
, ndlp
))
464 while (vport
->unreg_vpi_cmpl
== VPORT_INVAL
&& timeout
)
465 timeout
= schedule_timeout(timeout
);
468 lpfc_sli_host_down(vport
);
470 /* Mark all nodes for discovery so we can remove them by
471 * calling lpfc_cleanup_rpis(vport, 1)
473 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
474 if (!NLP_CHK_NODE_ACT(ndlp
))
476 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
478 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
479 NLP_EVT_DEVICE_RECOVERY
);
481 lpfc_cleanup_rpis(vport
, 1);
483 lpfc_stop_vport_timers(vport
);
484 lpfc_unreg_all_rpis(vport
);
485 lpfc_unreg_default_rpis(vport
);
487 * Completion of unreg_vpi (lpfc_mbx_cmpl_unreg_vpi) does the
488 * scsi_host_put() to release the vport.
490 lpfc_mbx_unreg_vpi(vport
);
492 lpfc_vport_set_state(vport
, FC_VPORT_DISABLED
);
493 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
494 "1826 Vport Disabled.\n");
499 enable_vport(struct fc_vport
*fc_vport
)
501 struct lpfc_vport
*vport
= *(struct lpfc_vport
**)fc_vport
->dd_data
;
502 struct lpfc_hba
*phba
= vport
->phba
;
503 struct lpfc_nodelist
*ndlp
= NULL
;
505 if ((phba
->link_state
< LPFC_LINK_UP
) ||
506 (phba
->fc_topology
== TOPOLOGY_LOOP
)) {
507 lpfc_vport_set_state(vport
, FC_VPORT_LINKDOWN
);
511 vport
->load_flag
|= FC_LOADING
;
512 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
514 /* Use the Physical nodes Fabric NDLP to determine if the link is
515 * up and ready to FDISC.
517 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
518 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)
519 && ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
520 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
) {
521 lpfc_set_disctmo(vport
);
522 lpfc_initial_fdisc(vport
);
524 lpfc_vport_set_state(vport
, FC_VPORT_NO_FABRIC_SUPP
);
525 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
526 "0264 No NPIV Fabric support\n");
529 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
531 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
532 "1827 Vport Enabled.\n");
537 lpfc_vport_disable(struct fc_vport
*fc_vport
, bool disable
)
540 return disable_vport(fc_vport
);
542 return enable_vport(fc_vport
);
547 lpfc_vport_delete(struct fc_vport
*fc_vport
)
549 struct lpfc_nodelist
*ndlp
= NULL
;
550 struct Scsi_Host
*shost
= (struct Scsi_Host
*) fc_vport
->shost
;
551 struct lpfc_vport
*vport
= *(struct lpfc_vport
**)fc_vport
->dd_data
;
552 struct lpfc_hba
*phba
= vport
->phba
;
555 if (vport
->port_type
== LPFC_PHYSICAL_PORT
) {
556 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
557 "1812 vport_delete failed: Cannot delete "
562 * If we are not unloading the driver then prevent the vport_delete
563 * from happening until after this vport's discovery is finished.
565 if (!(phba
->pport
->load_flag
& FC_UNLOADING
)) {
567 while (check_count
< ((phba
->fc_ratov
* 3) + 3) &&
568 vport
->port_state
> LPFC_VPORT_FAILED
&&
569 vport
->port_state
< LPFC_VPORT_READY
) {
573 if (vport
->port_state
> LPFC_VPORT_FAILED
&&
574 vport
->port_state
< LPFC_VPORT_READY
)
578 * This is a bit of a mess. We want to ensure the shost doesn't get
579 * torn down until we're done with the embedded lpfc_vport structure.
581 * Beyond holding a reference for this function, we also need a
582 * reference for outstanding I/O requests we schedule during delete
583 * processing. But once we scsi_remove_host() we can no longer obtain
584 * a reference through scsi_host_get().
586 * So we take two references here. We release one reference at the
587 * bottom of the function -- after delinking the vport. And we
588 * release the other at the completion of the unreg_vpi that get's
589 * initiated after we've disposed of all other resources associated
592 if (!scsi_host_get(shost
))
594 if (!scsi_host_get(shost
)) {
595 scsi_host_put(shost
);
598 spin_lock_irq(&phba
->hbalock
);
599 vport
->load_flag
|= FC_UNLOADING
;
600 spin_unlock_irq(&phba
->hbalock
);
602 lpfc_free_sysfs_attr(vport
);
604 lpfc_debugfs_terminate(vport
);
606 /* Remove FC host and then SCSI host with the vport */
607 fc_remove_host(lpfc_shost_from_vport(vport
));
608 scsi_remove_host(lpfc_shost_from_vport(vport
));
610 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
612 /* In case of driver unload, we shall not perform fabric logo as the
613 * worker thread already stopped at this stage and, in this case, we
614 * can safely skip the fabric logo.
616 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
617 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
618 ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
&&
619 phba
->link_state
>= LPFC_LINK_UP
) {
620 /* First look for the Fabric ndlp */
621 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
624 else if (!NLP_CHK_NODE_ACT(ndlp
)) {
625 ndlp
= lpfc_enable_node(vport
, ndlp
,
626 NLP_STE_UNUSED_NODE
);
630 /* Remove ndlp from vport npld list */
631 lpfc_dequeue_node(vport
, ndlp
);
633 /* Indicate free memory when release */
634 spin_lock_irq(&phba
->ndlp_lock
);
635 NLP_SET_FREE_REQ(ndlp
);
636 spin_unlock_irq(&phba
->ndlp_lock
);
637 /* Kick off release ndlp when it can be safely done */
643 /* Otherwise, we will perform fabric logo as needed */
644 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
645 ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
&&
646 phba
->link_state
>= LPFC_LINK_UP
&&
647 phba
->fc_topology
!= TOPOLOGY_LOOP
) {
648 if (vport
->cfg_enable_da_id
) {
649 timeout
= msecs_to_jiffies(phba
->fc_ratov
* 2000);
650 if (!lpfc_ns_cmd(vport
, SLI_CTNS_DA_ID
, 0, 0))
651 while (vport
->ct_flags
&& timeout
)
652 timeout
= schedule_timeout(timeout
);
654 lpfc_printf_log(vport
->phba
, KERN_WARNING
,
656 "1829 CT command failed to "
657 "delete objects on fabric. \n");
659 /* First look for the Fabric ndlp */
660 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
662 /* Cannot find existing Fabric ndlp, allocate one */
663 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
666 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
667 /* Indicate free memory when release */
668 NLP_SET_FREE_REQ(ndlp
);
670 if (!NLP_CHK_NODE_ACT(ndlp
))
671 ndlp
= lpfc_enable_node(vport
, ndlp
,
672 NLP_STE_UNUSED_NODE
);
676 /* Remove ndlp from vport npld list */
677 lpfc_dequeue_node(vport
, ndlp
);
678 spin_lock_irq(&phba
->ndlp_lock
);
679 if (!NLP_CHK_FREE_REQ(ndlp
))
680 /* Indicate free memory when release */
681 NLP_SET_FREE_REQ(ndlp
);
683 /* Skip this if ndlp is already in free mode */
684 spin_unlock_irq(&phba
->ndlp_lock
);
687 spin_unlock_irq(&phba
->ndlp_lock
);
689 vport
->unreg_vpi_cmpl
= VPORT_INVAL
;
690 timeout
= msecs_to_jiffies(phba
->fc_ratov
* 2000);
691 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
693 if (!lpfc_issue_els_npiv_logo(vport
, ndlp
))
694 while (vport
->unreg_vpi_cmpl
== VPORT_INVAL
&& timeout
)
695 timeout
= schedule_timeout(timeout
);
698 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
699 lpfc_discovery_wait(vport
);
703 lpfc_sli_host_down(vport
);
705 lpfc_stop_vport_timers(vport
);
707 if (!(phba
->pport
->load_flag
& FC_UNLOADING
)) {
708 lpfc_unreg_all_rpis(vport
);
709 lpfc_unreg_default_rpis(vport
);
711 * Completion of unreg_vpi (lpfc_mbx_cmpl_unreg_vpi)
712 * does the scsi_host_put() to release the vport.
714 if (lpfc_mbx_unreg_vpi(vport
))
715 scsi_host_put(shost
);
717 scsi_host_put(shost
);
719 lpfc_free_vpi(phba
, vport
->vpi
);
720 vport
->work_port_events
= 0;
721 spin_lock_irq(&phba
->hbalock
);
722 list_del_init(&vport
->listentry
);
723 spin_unlock_irq(&phba
->hbalock
);
724 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
725 "1828 Vport Deleted.\n");
726 scsi_host_put(shost
);
731 lpfc_create_vport_work_array(struct lpfc_hba
*phba
)
733 struct lpfc_vport
*port_iterator
;
734 struct lpfc_vport
**vports
;
736 vports
= kzalloc((phba
->max_vpi
+ 1) * sizeof(struct lpfc_vport
*),
740 spin_lock_irq(&phba
->hbalock
);
741 list_for_each_entry(port_iterator
, &phba
->port_list
, listentry
) {
742 if (!scsi_host_get(lpfc_shost_from_vport(port_iterator
))) {
743 lpfc_printf_vlog(port_iterator
, KERN_WARNING
, LOG_VPORT
,
744 "1801 Create vport work array FAILED: "
745 "cannot do scsi_host_get\n");
748 vports
[index
++] = port_iterator
;
750 spin_unlock_irq(&phba
->hbalock
);
755 lpfc_destroy_vport_work_array(struct lpfc_hba
*phba
, struct lpfc_vport
**vports
)
760 for (i
=0; vports
[i
] != NULL
&& i
<= phba
->max_vpi
; i
++)
761 scsi_host_put(lpfc_shost_from_vport(vports
[i
]));
767 * lpfc_vport_reset_stat_data - Reset the statistical data for the vport
768 * @vport: Pointer to vport object.
770 * This function resets the statistical data for the vport. This function
771 * is called with the host_lock held
774 lpfc_vport_reset_stat_data(struct lpfc_vport
*vport
)
776 struct lpfc_nodelist
*ndlp
= NULL
, *next_ndlp
= NULL
;
778 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
779 if (!NLP_CHK_NODE_ACT(ndlp
))
782 memset(ndlp
->lat_data
, 0, LPFC_MAX_BUCKET_COUNT
*
783 sizeof(struct lpfc_scsicmd_bkt
));
789 * lpfc_alloc_bucket - Allocate data buffer required for statistical data
790 * @vport: Pointer to vport object.
792 * This function allocates data buffer required for all the FC
793 * nodes of the vport to collect statistical data.
796 lpfc_alloc_bucket(struct lpfc_vport
*vport
)
798 struct lpfc_nodelist
*ndlp
= NULL
, *next_ndlp
= NULL
;
800 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
801 if (!NLP_CHK_NODE_ACT(ndlp
))
804 kfree(ndlp
->lat_data
);
805 ndlp
->lat_data
= NULL
;
807 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
) {
808 ndlp
->lat_data
= kcalloc(LPFC_MAX_BUCKET_COUNT
,
809 sizeof(struct lpfc_scsicmd_bkt
),
813 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
814 "0287 lpfc_alloc_bucket failed to "
815 "allocate statistical data buffer DID "
816 "0x%x\n", ndlp
->nlp_DID
);
822 * lpfc_free_bucket - Free data buffer required for statistical data
823 * @vport: Pointer to vport object.
825 * Th function frees statistical data buffer of all the FC
826 * nodes of the vport.
829 lpfc_free_bucket(struct lpfc_vport
*vport
)
831 struct lpfc_nodelist
*ndlp
= NULL
, *next_ndlp
= NULL
;
833 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
834 if (!NLP_CHK_NODE_ACT(ndlp
))
837 kfree(ndlp
->lat_data
);
838 ndlp
->lat_data
= NULL
;
This page took 0.060493 seconds and 5 git commands to generate.