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_disc.h"
39 #include "lpfc_scsi.h"
41 #include "lpfc_logmsg.h"
42 #include "lpfc_crtn.h"
43 #include "lpfc_version.h"
44 #include "lpfc_vport.h"
46 inline void lpfc_vport_set_state(struct lpfc_vport
*vport
,
47 enum fc_vport_state new_state
)
49 struct fc_vport
*fc_vport
= vport
->fc_vport
;
53 * When the transport defines fc_vport_set state we will replace
54 * this code with the following line
56 /* fc_vport_set_state(fc_vport, new_state); */
57 if (new_state
!= FC_VPORT_INITIALIZING
)
58 fc_vport
->vport_last_state
= fc_vport
->vport_state
;
59 fc_vport
->vport_state
= new_state
;
62 /* for all the error states we will set the invternal state to FAILED */
64 case FC_VPORT_NO_FABRIC_SUPP
:
65 case FC_VPORT_NO_FABRIC_RSCS
:
66 case FC_VPORT_FABRIC_LOGOUT
:
67 case FC_VPORT_FABRIC_REJ_WWN
:
69 vport
->port_state
= LPFC_VPORT_FAILED
;
71 case FC_VPORT_LINKDOWN
:
72 vport
->port_state
= LPFC_VPORT_UNKNOWN
;
81 lpfc_alloc_vpi(struct lpfc_hba
*phba
)
85 spin_lock_irq(&phba
->hbalock
);
86 /* Start at bit 1 because vpi zero is reserved for the physical port */
87 vpi
= find_next_zero_bit(phba
->vpi_bmask
, (phba
->max_vpi
+ 1), 1);
88 if (vpi
> phba
->max_vpi
)
91 set_bit(vpi
, phba
->vpi_bmask
);
92 spin_unlock_irq(&phba
->hbalock
);
97 lpfc_free_vpi(struct lpfc_hba
*phba
, int vpi
)
99 spin_lock_irq(&phba
->hbalock
);
100 clear_bit(vpi
, phba
->vpi_bmask
);
101 spin_unlock_irq(&phba
->hbalock
);
105 lpfc_vport_sparm(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
109 struct lpfc_dmabuf
*mp
;
112 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
118 lpfc_read_sparam(phba
, pmb
, vport
->vpi
);
120 * Grab buffer pointer and clear context1 so we can use
121 * lpfc_sli_issue_box_wait
123 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
124 pmb
->context1
= NULL
;
127 rc
= lpfc_sli_issue_mbox_wait(phba
, pmb
, phba
->fc_ratov
* 2);
128 if (rc
!= MBX_SUCCESS
) {
129 if (signal_pending(current
)) {
130 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
131 "1830 Signal aborted mbxCmd x%x\n",
133 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
135 if (rc
!= MBX_TIMEOUT
)
136 mempool_free(pmb
, phba
->mbox_mem_pool
);
139 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
140 "1818 VPort failed init, mbxCmd x%x "
141 "READ_SPARM mbxStatus x%x, rc = x%x\n",
142 mb
->mbxCommand
, mb
->mbxStatus
, rc
);
143 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
145 if (rc
!= MBX_TIMEOUT
)
146 mempool_free(pmb
, phba
->mbox_mem_pool
);
151 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof (struct serv_parm
));
152 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
153 sizeof (struct lpfc_name
));
154 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
155 sizeof (struct lpfc_name
));
157 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
159 mempool_free(pmb
, phba
->mbox_mem_pool
);
165 lpfc_valid_wwn_format(struct lpfc_hba
*phba
, struct lpfc_name
*wwn
,
166 const char *name_type
)
168 /* ensure that IEEE format 1 addresses
169 * contain zeros in bits 59-48
171 if (!((wwn
->u
.wwn
[0] >> 4) == 1 &&
172 ((wwn
->u
.wwn
[0] & 0xf) != 0 || (wwn
->u
.wwn
[1] & 0xf) != 0)))
175 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
176 "1822 Invalid %s: %02x:%02x:%02x:%02x:"
177 "%02x:%02x:%02x:%02x\n",
179 wwn
->u
.wwn
[0], wwn
->u
.wwn
[1],
180 wwn
->u
.wwn
[2], wwn
->u
.wwn
[3],
181 wwn
->u
.wwn
[4], wwn
->u
.wwn
[5],
182 wwn
->u
.wwn
[6], wwn
->u
.wwn
[7]);
187 lpfc_unique_wwpn(struct lpfc_hba
*phba
, struct lpfc_vport
*new_vport
)
189 struct lpfc_vport
*vport
;
192 spin_lock_irqsave(&phba
->hbalock
, flags
);
193 list_for_each_entry(vport
, &phba
->port_list
, listentry
) {
194 if (vport
== new_vport
)
196 /* If they match, return not unique */
197 if (memcmp(&vport
->fc_sparam
.portName
,
198 &new_vport
->fc_sparam
.portName
,
199 sizeof(struct lpfc_name
)) == 0) {
200 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
204 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
209 * lpfc_discovery_wait - Wait for driver discovery to quiesce
210 * @vport: The virtual port for which this call is being executed.
212 * This driver calls this routine specifically from lpfc_vport_delete
213 * to enforce a synchronous execution of vport
214 * delete relative to discovery activities. The
215 * lpfc_vport_delete routine should not return until it
216 * can reasonably guarantee that discovery has quiesced.
217 * Post FDISC LOGO, the driver must wait until its SAN teardown is
218 * complete and all resources recovered before allowing
221 * This routine does not require any locks held.
223 static void lpfc_discovery_wait(struct lpfc_vport
*vport
)
225 struct lpfc_hba
*phba
= vport
->phba
;
226 uint32_t wait_flags
= 0;
227 unsigned long wait_time_max
;
228 unsigned long start_time
;
230 wait_flags
= FC_RSCN_MODE
| FC_RSCN_DISCOVERY
| FC_NLP_MORE
|
231 FC_RSCN_DEFERRED
| FC_NDISC_ACTIVE
| FC_DISC_TMO
;
234 * The time constraint on this loop is a balance between the
235 * fabric RA_TOV value and dev_loss tmo. The driver's
236 * devloss_tmo is 10 giving this loop a 3x multiplier minimally.
238 wait_time_max
= msecs_to_jiffies(((phba
->fc_ratov
* 3) + 3) * 1000);
239 wait_time_max
+= jiffies
;
240 start_time
= jiffies
;
241 while (time_before(jiffies
, wait_time_max
)) {
242 if ((vport
->num_disc_nodes
> 0) ||
243 (vport
->fc_flag
& wait_flags
) ||
244 ((vport
->port_state
> LPFC_VPORT_FAILED
) &&
245 (vport
->port_state
< LPFC_VPORT_READY
))) {
246 lpfc_printf_log(phba
, KERN_INFO
, LOG_VPORT
,
247 "1833 Vport discovery quiesce Wait:"
248 " vpi x%x state x%x fc_flags x%x"
249 " num_nodes x%x, waiting 1000 msecs"
250 " total wait msecs x%x\n",
251 vport
->vpi
, vport
->port_state
,
252 vport
->fc_flag
, vport
->num_disc_nodes
,
253 jiffies_to_msecs(jiffies
- start_time
));
256 /* Base case. Wait variants satisfied. Break out */
257 lpfc_printf_log(phba
, KERN_INFO
, LOG_VPORT
,
258 "1834 Vport discovery quiesced:"
259 " vpi x%x state x%x fc_flags x%x"
261 vport
->vpi
, vport
->port_state
,
263 jiffies_to_msecs(jiffies
269 if (time_after(jiffies
, wait_time_max
))
270 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
271 "1835 Vport discovery quiesce failed:"
272 " vpi x%x state x%x fc_flags x%x"
274 vport
->vpi
, vport
->port_state
,
276 jiffies_to_msecs(jiffies
- start_time
));
280 lpfc_vport_create(struct fc_vport
*fc_vport
, bool disable
)
282 struct lpfc_nodelist
*ndlp
;
283 struct Scsi_Host
*shost
= fc_vport
->shost
;
284 struct lpfc_vport
*pport
= (struct lpfc_vport
*) shost
->hostdata
;
285 struct lpfc_hba
*phba
= pport
->phba
;
286 struct lpfc_vport
*vport
= NULL
;
289 int rc
= VPORT_ERROR
;
292 if ((phba
->sli_rev
< 3) || !(phba
->cfg_enable_npiv
)) {
293 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
294 "1808 Create VPORT failed: "
295 "NPIV is not enabled: SLImode:%d\n",
301 vpi
= lpfc_alloc_vpi(phba
);
303 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
304 "1809 Create VPORT failed: "
305 "Max VPORTs (%d) exceeded\n",
307 rc
= VPORT_NORESOURCES
;
312 /* Assign an unused board number */
313 if ((instance
= lpfc_get_instance()) < 0) {
314 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
315 "1810 Create VPORT failed: Cannot get "
316 "instance number\n");
317 lpfc_free_vpi(phba
, vpi
);
318 rc
= VPORT_NORESOURCES
;
322 vport
= lpfc_create_port(phba
, instance
, &fc_vport
->dev
);
324 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
325 "1811 Create VPORT failed: vpi x%x\n", vpi
);
326 lpfc_free_vpi(phba
, vpi
);
327 rc
= VPORT_NORESOURCES
;
332 lpfc_debugfs_initialize(vport
);
334 if ((status
= lpfc_vport_sparm(phba
, vport
))) {
335 if (status
== -EINTR
) {
336 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
337 "1831 Create VPORT Interrupted.\n");
340 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
341 "1813 Create VPORT failed. "
342 "Cannot get sparam\n");
343 rc
= VPORT_NORESOURCES
;
345 lpfc_free_vpi(phba
, vpi
);
350 memcpy(vport
->fc_portname
.u
.wwn
, vport
->fc_sparam
.portName
.u
.wwn
, 8);
351 memcpy(vport
->fc_nodename
.u
.wwn
, vport
->fc_sparam
.nodeName
.u
.wwn
, 8);
352 if (fc_vport
->node_name
!= 0)
353 u64_to_wwn(fc_vport
->node_name
, vport
->fc_nodename
.u
.wwn
);
354 if (fc_vport
->port_name
!= 0)
355 u64_to_wwn(fc_vport
->port_name
, vport
->fc_portname
.u
.wwn
);
357 memcpy(&vport
->fc_sparam
.portName
, vport
->fc_portname
.u
.wwn
, 8);
358 memcpy(&vport
->fc_sparam
.nodeName
, vport
->fc_nodename
.u
.wwn
, 8);
360 if (!lpfc_valid_wwn_format(phba
, &vport
->fc_sparam
.nodeName
, "WWNN") ||
361 !lpfc_valid_wwn_format(phba
, &vport
->fc_sparam
.portName
, "WWPN")) {
362 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
363 "1821 Create VPORT failed. "
364 "Invalid WWN format\n");
365 lpfc_free_vpi(phba
, vpi
);
371 if (!lpfc_unique_wwpn(phba
, vport
)) {
372 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
373 "1823 Create VPORT failed. "
374 "Duplicate WWN on HBA\n");
375 lpfc_free_vpi(phba
, vpi
);
381 /* Create binary sysfs attribute for vport */
382 lpfc_alloc_sysfs_attr(vport
);
384 *(struct lpfc_vport
**)fc_vport
->dd_data
= vport
;
385 vport
->fc_vport
= fc_vport
;
387 if ((phba
->link_state
< LPFC_LINK_UP
) ||
388 (phba
->fc_topology
== TOPOLOGY_LOOP
)) {
389 lpfc_vport_set_state(vport
, FC_VPORT_LINKDOWN
);
395 lpfc_vport_set_state(vport
, FC_VPORT_DISABLED
);
400 /* Use the Physical nodes Fabric NDLP to determine if the link is
401 * up and ready to FDISC.
403 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
404 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
405 ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
406 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
) {
407 lpfc_set_disctmo(vport
);
408 lpfc_initial_fdisc(vport
);
410 lpfc_vport_set_state(vport
, FC_VPORT_NO_FABRIC_SUPP
);
411 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
412 "0262 No NPIV Fabric support\n");
415 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
420 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
421 "1825 Vport Created.\n");
422 lpfc_host_attrib_init(lpfc_shost_from_vport(vport
));
428 disable_vport(struct fc_vport
*fc_vport
)
430 struct lpfc_vport
*vport
= *(struct lpfc_vport
**)fc_vport
->dd_data
;
431 struct lpfc_hba
*phba
= vport
->phba
;
432 struct lpfc_nodelist
*ndlp
= NULL
, *next_ndlp
= NULL
;
435 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
436 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)
437 && phba
->link_state
>= LPFC_LINK_UP
) {
438 vport
->unreg_vpi_cmpl
= VPORT_INVAL
;
439 timeout
= msecs_to_jiffies(phba
->fc_ratov
* 2000);
440 if (!lpfc_issue_els_npiv_logo(vport
, ndlp
))
441 while (vport
->unreg_vpi_cmpl
== VPORT_INVAL
&& timeout
)
442 timeout
= schedule_timeout(timeout
);
445 lpfc_sli_host_down(vport
);
447 /* Mark all nodes for discovery so we can remove them by
448 * calling lpfc_cleanup_rpis(vport, 1)
450 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
451 if (!NLP_CHK_NODE_ACT(ndlp
))
453 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
455 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
456 NLP_EVT_DEVICE_RECOVERY
);
458 lpfc_cleanup_rpis(vport
, 1);
460 lpfc_stop_vport_timers(vport
);
461 lpfc_unreg_all_rpis(vport
);
462 lpfc_unreg_default_rpis(vport
);
464 * Completion of unreg_vpi (lpfc_mbx_cmpl_unreg_vpi) does the
465 * scsi_host_put() to release the vport.
467 lpfc_mbx_unreg_vpi(vport
);
469 lpfc_vport_set_state(vport
, FC_VPORT_DISABLED
);
470 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
471 "1826 Vport Disabled.\n");
476 enable_vport(struct fc_vport
*fc_vport
)
478 struct lpfc_vport
*vport
= *(struct lpfc_vport
**)fc_vport
->dd_data
;
479 struct lpfc_hba
*phba
= vport
->phba
;
480 struct lpfc_nodelist
*ndlp
= NULL
;
482 if ((phba
->link_state
< LPFC_LINK_UP
) ||
483 (phba
->fc_topology
== TOPOLOGY_LOOP
)) {
484 lpfc_vport_set_state(vport
, FC_VPORT_LINKDOWN
);
488 vport
->load_flag
|= FC_LOADING
;
489 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
491 /* Use the Physical nodes Fabric NDLP to determine if the link is
492 * up and ready to FDISC.
494 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
495 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)
496 && ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
497 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
) {
498 lpfc_set_disctmo(vport
);
499 lpfc_initial_fdisc(vport
);
501 lpfc_vport_set_state(vport
, FC_VPORT_NO_FABRIC_SUPP
);
502 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
503 "0264 No NPIV Fabric support\n");
506 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
508 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
509 "1827 Vport Enabled.\n");
514 lpfc_vport_disable(struct fc_vport
*fc_vport
, bool disable
)
517 return disable_vport(fc_vport
);
519 return enable_vport(fc_vport
);
524 lpfc_vport_delete(struct fc_vport
*fc_vport
)
526 struct lpfc_nodelist
*ndlp
= NULL
;
527 struct Scsi_Host
*shost
= (struct Scsi_Host
*) fc_vport
->shost
;
528 struct lpfc_vport
*vport
= *(struct lpfc_vport
**)fc_vport
->dd_data
;
529 struct lpfc_hba
*phba
= vport
->phba
;
532 if (vport
->port_type
== LPFC_PHYSICAL_PORT
) {
533 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
534 "1812 vport_delete failed: Cannot delete "
539 * If we are not unloading the driver then prevent the vport_delete
540 * from happening until after this vport's discovery is finished.
542 if (!(phba
->pport
->load_flag
& FC_UNLOADING
)) {
544 while (check_count
< ((phba
->fc_ratov
* 3) + 3) &&
545 vport
->port_state
> LPFC_VPORT_FAILED
&&
546 vport
->port_state
< LPFC_VPORT_READY
) {
550 if (vport
->port_state
> LPFC_VPORT_FAILED
&&
551 vport
->port_state
< LPFC_VPORT_READY
)
555 * This is a bit of a mess. We want to ensure the shost doesn't get
556 * torn down until we're done with the embedded lpfc_vport structure.
558 * Beyond holding a reference for this function, we also need a
559 * reference for outstanding I/O requests we schedule during delete
560 * processing. But once we scsi_remove_host() we can no longer obtain
561 * a reference through scsi_host_get().
563 * So we take two references here. We release one reference at the
564 * bottom of the function -- after delinking the vport. And we
565 * release the other at the completion of the unreg_vpi that get's
566 * initiated after we've disposed of all other resources associated
569 if (!scsi_host_get(shost
))
571 if (!scsi_host_get(shost
)) {
572 scsi_host_put(shost
);
575 spin_lock_irq(&phba
->hbalock
);
576 vport
->load_flag
|= FC_UNLOADING
;
577 spin_unlock_irq(&phba
->hbalock
);
579 lpfc_free_sysfs_attr(vport
);
581 lpfc_debugfs_terminate(vport
);
583 /* Remove FC host and then SCSI host with the vport */
584 fc_remove_host(lpfc_shost_from_vport(vport
));
585 scsi_remove_host(lpfc_shost_from_vport(vport
));
587 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
589 /* In case of driver unload, we shall not perform fabric logo as the
590 * worker thread already stopped at this stage and, in this case, we
591 * can safely skip the fabric logo.
593 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
594 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
595 ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
&&
596 phba
->link_state
>= LPFC_LINK_UP
) {
597 /* First look for the Fabric ndlp */
598 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
601 else if (!NLP_CHK_NODE_ACT(ndlp
)) {
602 ndlp
= lpfc_enable_node(vport
, ndlp
,
603 NLP_STE_UNUSED_NODE
);
607 /* Remove ndlp from vport npld list */
608 lpfc_dequeue_node(vport
, ndlp
);
610 /* Indicate free memory when release */
611 spin_lock_irq(&phba
->ndlp_lock
);
612 NLP_SET_FREE_REQ(ndlp
);
613 spin_unlock_irq(&phba
->ndlp_lock
);
614 /* Kick off release ndlp when it can be safely done */
620 /* Otherwise, we will perform fabric logo as needed */
621 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
622 ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
&&
623 phba
->link_state
>= LPFC_LINK_UP
&&
624 phba
->fc_topology
!= TOPOLOGY_LOOP
) {
625 if (vport
->cfg_enable_da_id
) {
626 timeout
= msecs_to_jiffies(phba
->fc_ratov
* 2000);
627 if (!lpfc_ns_cmd(vport
, SLI_CTNS_DA_ID
, 0, 0))
628 while (vport
->ct_flags
&& timeout
)
629 timeout
= schedule_timeout(timeout
);
631 lpfc_printf_log(vport
->phba
, KERN_WARNING
,
633 "1829 CT command failed to "
634 "delete objects on fabric. \n");
636 /* First look for the Fabric ndlp */
637 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
639 /* Cannot find existing Fabric ndlp, allocate one */
640 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
643 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
644 /* Indicate free memory when release */
645 NLP_SET_FREE_REQ(ndlp
);
647 if (!NLP_CHK_NODE_ACT(ndlp
))
648 ndlp
= lpfc_enable_node(vport
, ndlp
,
649 NLP_STE_UNUSED_NODE
);
653 /* Remove ndlp from vport npld list */
654 lpfc_dequeue_node(vport
, ndlp
);
655 spin_lock_irq(&phba
->ndlp_lock
);
656 if (!NLP_CHK_FREE_REQ(ndlp
))
657 /* Indicate free memory when release */
658 NLP_SET_FREE_REQ(ndlp
);
660 /* Skip this if ndlp is already in free mode */
661 spin_unlock_irq(&phba
->ndlp_lock
);
664 spin_unlock_irq(&phba
->ndlp_lock
);
666 vport
->unreg_vpi_cmpl
= VPORT_INVAL
;
667 timeout
= msecs_to_jiffies(phba
->fc_ratov
* 2000);
668 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
670 if (!lpfc_issue_els_npiv_logo(vport
, ndlp
))
671 while (vport
->unreg_vpi_cmpl
== VPORT_INVAL
&& timeout
)
672 timeout
= schedule_timeout(timeout
);
675 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
676 lpfc_discovery_wait(vport
);
680 lpfc_sli_host_down(vport
);
682 lpfc_stop_vport_timers(vport
);
684 if (!(phba
->pport
->load_flag
& FC_UNLOADING
)) {
685 lpfc_unreg_all_rpis(vport
);
686 lpfc_unreg_default_rpis(vport
);
688 * Completion of unreg_vpi (lpfc_mbx_cmpl_unreg_vpi)
689 * does the scsi_host_put() to release the vport.
691 if (lpfc_mbx_unreg_vpi(vport
))
692 scsi_host_put(shost
);
694 scsi_host_put(shost
);
696 lpfc_free_vpi(phba
, vport
->vpi
);
697 vport
->work_port_events
= 0;
698 spin_lock_irq(&phba
->hbalock
);
699 list_del_init(&vport
->listentry
);
700 spin_unlock_irq(&phba
->hbalock
);
701 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
702 "1828 Vport Deleted.\n");
703 scsi_host_put(shost
);
708 lpfc_create_vport_work_array(struct lpfc_hba
*phba
)
710 struct lpfc_vport
*port_iterator
;
711 struct lpfc_vport
**vports
;
713 vports
= kzalloc((phba
->max_vpi
+ 1) * sizeof(struct lpfc_vport
*),
717 spin_lock_irq(&phba
->hbalock
);
718 list_for_each_entry(port_iterator
, &phba
->port_list
, listentry
) {
719 if (!scsi_host_get(lpfc_shost_from_vport(port_iterator
))) {
720 lpfc_printf_vlog(port_iterator
, KERN_WARNING
, LOG_VPORT
,
721 "1801 Create vport work array FAILED: "
722 "cannot do scsi_host_get\n");
725 vports
[index
++] = port_iterator
;
727 spin_unlock_irq(&phba
->hbalock
);
732 lpfc_destroy_vport_work_array(struct lpfc_hba
*phba
, struct lpfc_vport
**vports
)
737 for (i
=0; vports
[i
] != NULL
&& i
<= phba
->max_vpi
; i
++)
738 scsi_host_put(lpfc_shost_from_vport(vports
[i
]));
744 * lpfc_vport_reset_stat_data - Reset the statistical data for the vport
745 * @vport: Pointer to vport object.
747 * This function resets the statistical data for the vport. This function
748 * is called with the host_lock held
751 lpfc_vport_reset_stat_data(struct lpfc_vport
*vport
)
753 struct lpfc_nodelist
*ndlp
= NULL
, *next_ndlp
= NULL
;
755 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
756 if (!NLP_CHK_NODE_ACT(ndlp
))
759 memset(ndlp
->lat_data
, 0, LPFC_MAX_BUCKET_COUNT
*
760 sizeof(struct lpfc_scsicmd_bkt
));
766 * lpfc_alloc_bucket - Allocate data buffer required for statistical data
767 * @vport: Pointer to vport object.
769 * This function allocates data buffer required for all the FC
770 * nodes of the vport to collect statistical data.
773 lpfc_alloc_bucket(struct lpfc_vport
*vport
)
775 struct lpfc_nodelist
*ndlp
= NULL
, *next_ndlp
= NULL
;
777 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
778 if (!NLP_CHK_NODE_ACT(ndlp
))
781 kfree(ndlp
->lat_data
);
782 ndlp
->lat_data
= NULL
;
784 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
) {
785 ndlp
->lat_data
= kcalloc(LPFC_MAX_BUCKET_COUNT
,
786 sizeof(struct lpfc_scsicmd_bkt
),
790 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
791 "0287 lpfc_alloc_bucket failed to "
792 "allocate statistical data buffer DID "
793 "0x%x\n", ndlp
->nlp_DID
);
799 * lpfc_free_bucket - Free data buffer required for statistical data
800 * @vport: Pointer to vport object.
802 * Th function frees statistical data buffer of all the FC
803 * nodes of the vport.
806 lpfc_free_bucket(struct lpfc_vport
*vport
)
808 struct lpfc_nodelist
*ndlp
= NULL
, *next_ndlp
= NULL
;
810 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
811 if (!NLP_CHK_NODE_ACT(ndlp
))
814 kfree(ndlp
->lat_data
);
815 ndlp
->lat_data
= NULL
;