]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/scsi/lpfc/lpfc_vport.c
1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2016 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/slab.h>
30 #include <linux/spinlock.h>
32 #include <scsi/scsi.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi_host.h>
35 #include <scsi/scsi_transport_fc.h>
39 #include "lpfc_sli4.h"
41 #include "lpfc_disc.h"
42 #include "lpfc_scsi.h"
44 #include "lpfc_logmsg.h"
45 #include "lpfc_crtn.h"
46 #include "lpfc_version.h"
47 #include "lpfc_vport.h"
49 inline void lpfc_vport_set_state(struct lpfc_vport
*vport
,
50 enum fc_vport_state new_state
)
52 struct fc_vport
*fc_vport
= vport
->fc_vport
;
56 * When the transport defines fc_vport_set state we will replace
57 * this code with the following line
59 /* fc_vport_set_state(fc_vport, new_state); */
60 if (new_state
!= FC_VPORT_INITIALIZING
)
61 fc_vport
->vport_last_state
= fc_vport
->vport_state
;
62 fc_vport
->vport_state
= new_state
;
65 /* for all the error states we will set the invternal state to FAILED */
67 case FC_VPORT_NO_FABRIC_SUPP
:
68 case FC_VPORT_NO_FABRIC_RSCS
:
69 case FC_VPORT_FABRIC_LOGOUT
:
70 case FC_VPORT_FABRIC_REJ_WWN
:
72 vport
->port_state
= LPFC_VPORT_FAILED
;
74 case FC_VPORT_LINKDOWN
:
75 vport
->port_state
= LPFC_VPORT_UNKNOWN
;
84 lpfc_alloc_vpi(struct lpfc_hba
*phba
)
88 spin_lock_irq(&phba
->hbalock
);
89 /* Start at bit 1 because vpi zero is reserved for the physical port */
90 vpi
= find_next_zero_bit(phba
->vpi_bmask
, (phba
->max_vpi
+ 1), 1);
91 if (vpi
> phba
->max_vpi
)
94 set_bit(vpi
, phba
->vpi_bmask
);
95 if (phba
->sli_rev
== LPFC_SLI_REV4
)
96 phba
->sli4_hba
.max_cfg_param
.vpi_used
++;
97 spin_unlock_irq(&phba
->hbalock
);
102 lpfc_free_vpi(struct lpfc_hba
*phba
, int vpi
)
106 spin_lock_irq(&phba
->hbalock
);
107 clear_bit(vpi
, phba
->vpi_bmask
);
108 if (phba
->sli_rev
== LPFC_SLI_REV4
)
109 phba
->sli4_hba
.max_cfg_param
.vpi_used
--;
110 spin_unlock_irq(&phba
->hbalock
);
114 lpfc_vport_sparm(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
118 struct lpfc_dmabuf
*mp
;
121 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
127 rc
= lpfc_read_sparam(phba
, pmb
, vport
->vpi
);
129 mempool_free(pmb
, phba
->mbox_mem_pool
);
134 * Grab buffer pointer and clear context1 so we can use
135 * lpfc_sli_issue_box_wait
137 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
138 pmb
->context1
= NULL
;
141 rc
= lpfc_sli_issue_mbox_wait(phba
, pmb
, phba
->fc_ratov
* 2);
142 if (rc
!= MBX_SUCCESS
) {
143 if (signal_pending(current
)) {
144 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
145 "1830 Signal aborted mbxCmd x%x\n",
147 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
149 if (rc
!= MBX_TIMEOUT
)
150 mempool_free(pmb
, phba
->mbox_mem_pool
);
153 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
154 "1818 VPort failed init, mbxCmd x%x "
155 "READ_SPARM mbxStatus x%x, rc = x%x\n",
156 mb
->mbxCommand
, mb
->mbxStatus
, rc
);
157 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
159 if (rc
!= MBX_TIMEOUT
)
160 mempool_free(pmb
, phba
->mbox_mem_pool
);
165 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof (struct serv_parm
));
166 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
167 sizeof (struct lpfc_name
));
168 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
169 sizeof (struct lpfc_name
));
171 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
173 mempool_free(pmb
, phba
->mbox_mem_pool
);
179 lpfc_valid_wwn_format(struct lpfc_hba
*phba
, struct lpfc_name
*wwn
,
180 const char *name_type
)
182 /* ensure that IEEE format 1 addresses
183 * contain zeros in bits 59-48
185 if (!((wwn
->u
.wwn
[0] >> 4) == 1 &&
186 ((wwn
->u
.wwn
[0] & 0xf) != 0 || (wwn
->u
.wwn
[1] & 0xf) != 0)))
189 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
190 "1822 Invalid %s: %02x:%02x:%02x:%02x:"
191 "%02x:%02x:%02x:%02x\n",
193 wwn
->u
.wwn
[0], wwn
->u
.wwn
[1],
194 wwn
->u
.wwn
[2], wwn
->u
.wwn
[3],
195 wwn
->u
.wwn
[4], wwn
->u
.wwn
[5],
196 wwn
->u
.wwn
[6], wwn
->u
.wwn
[7]);
201 lpfc_unique_wwpn(struct lpfc_hba
*phba
, struct lpfc_vport
*new_vport
)
203 struct lpfc_vport
*vport
;
206 spin_lock_irqsave(&phba
->hbalock
, flags
);
207 list_for_each_entry(vport
, &phba
->port_list
, listentry
) {
208 if (vport
== new_vport
)
210 /* If they match, return not unique */
211 if (memcmp(&vport
->fc_sparam
.portName
,
212 &new_vport
->fc_sparam
.portName
,
213 sizeof(struct lpfc_name
)) == 0) {
214 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
218 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
223 * lpfc_discovery_wait - Wait for driver discovery to quiesce
224 * @vport: The virtual port for which this call is being executed.
226 * This driver calls this routine specifically from lpfc_vport_delete
227 * to enforce a synchronous execution of vport
228 * delete relative to discovery activities. The
229 * lpfc_vport_delete routine should not return until it
230 * can reasonably guarantee that discovery has quiesced.
231 * Post FDISC LOGO, the driver must wait until its SAN teardown is
232 * complete and all resources recovered before allowing
235 * This routine does not require any locks held.
237 static void lpfc_discovery_wait(struct lpfc_vport
*vport
)
239 struct lpfc_hba
*phba
= vport
->phba
;
240 uint32_t wait_flags
= 0;
241 unsigned long wait_time_max
;
242 unsigned long start_time
;
244 wait_flags
= FC_RSCN_MODE
| FC_RSCN_DISCOVERY
| FC_NLP_MORE
|
245 FC_RSCN_DEFERRED
| FC_NDISC_ACTIVE
| FC_DISC_TMO
;
248 * The time constraint on this loop is a balance between the
249 * fabric RA_TOV value and dev_loss tmo. The driver's
250 * devloss_tmo is 10 giving this loop a 3x multiplier minimally.
252 wait_time_max
= msecs_to_jiffies(((phba
->fc_ratov
* 3) + 3) * 1000);
253 wait_time_max
+= jiffies
;
254 start_time
= jiffies
;
255 while (time_before(jiffies
, wait_time_max
)) {
256 if ((vport
->num_disc_nodes
> 0) ||
257 (vport
->fc_flag
& wait_flags
) ||
258 ((vport
->port_state
> LPFC_VPORT_FAILED
) &&
259 (vport
->port_state
< LPFC_VPORT_READY
))) {
260 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_VPORT
,
261 "1833 Vport discovery quiesce Wait:"
262 " state x%x fc_flags x%x"
263 " num_nodes x%x, waiting 1000 msecs"
264 " total wait msecs x%x\n",
265 vport
->port_state
, vport
->fc_flag
,
266 vport
->num_disc_nodes
,
267 jiffies_to_msecs(jiffies
- start_time
));
270 /* Base case. Wait variants satisfied. Break out */
271 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_VPORT
,
272 "1834 Vport discovery quiesced:"
273 " state x%x fc_flags x%x"
275 vport
->port_state
, vport
->fc_flag
,
276 jiffies_to_msecs(jiffies
282 if (time_after(jiffies
, wait_time_max
))
283 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
284 "1835 Vport discovery quiesce failed:"
285 " state x%x fc_flags x%x wait msecs x%x\n",
286 vport
->port_state
, vport
->fc_flag
,
287 jiffies_to_msecs(jiffies
- start_time
));
291 lpfc_vport_create(struct fc_vport
*fc_vport
, bool disable
)
293 struct lpfc_nodelist
*ndlp
;
294 struct Scsi_Host
*shost
= fc_vport
->shost
;
295 struct lpfc_vport
*pport
= (struct lpfc_vport
*) shost
->hostdata
;
296 struct lpfc_hba
*phba
= pport
->phba
;
297 struct lpfc_vport
*vport
= NULL
;
300 int rc
= VPORT_ERROR
;
303 if ((phba
->sli_rev
< 3) || !(phba
->cfg_enable_npiv
)) {
304 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
305 "1808 Create VPORT failed: "
306 "NPIV is not enabled: SLImode:%d\n",
312 vpi
= lpfc_alloc_vpi(phba
);
314 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
315 "1809 Create VPORT failed: "
316 "Max VPORTs (%d) exceeded\n",
318 rc
= VPORT_NORESOURCES
;
322 /* Assign an unused board number */
323 if ((instance
= lpfc_get_instance()) < 0) {
324 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
325 "1810 Create VPORT failed: Cannot get "
326 "instance number\n");
327 lpfc_free_vpi(phba
, vpi
);
328 rc
= VPORT_NORESOURCES
;
332 vport
= lpfc_create_port(phba
, instance
, &fc_vport
->dev
);
334 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
335 "1811 Create VPORT failed: vpi x%x\n", vpi
);
336 lpfc_free_vpi(phba
, vpi
);
337 rc
= VPORT_NORESOURCES
;
342 lpfc_debugfs_initialize(vport
);
344 if ((status
= lpfc_vport_sparm(phba
, vport
))) {
345 if (status
== -EINTR
) {
346 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
347 "1831 Create VPORT Interrupted.\n");
350 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
351 "1813 Create VPORT failed. "
352 "Cannot get sparam\n");
353 rc
= VPORT_NORESOURCES
;
355 lpfc_free_vpi(phba
, vpi
);
360 u64_to_wwn(fc_vport
->node_name
, vport
->fc_nodename
.u
.wwn
);
361 u64_to_wwn(fc_vport
->port_name
, vport
->fc_portname
.u
.wwn
);
363 memcpy(&vport
->fc_sparam
.portName
, vport
->fc_portname
.u
.wwn
, 8);
364 memcpy(&vport
->fc_sparam
.nodeName
, vport
->fc_nodename
.u
.wwn
, 8);
366 if (!lpfc_valid_wwn_format(phba
, &vport
->fc_sparam
.nodeName
, "WWNN") ||
367 !lpfc_valid_wwn_format(phba
, &vport
->fc_sparam
.portName
, "WWPN")) {
368 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
369 "1821 Create VPORT failed. "
370 "Invalid WWN format\n");
371 lpfc_free_vpi(phba
, vpi
);
377 if (!lpfc_unique_wwpn(phba
, vport
)) {
378 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
379 "1823 Create VPORT failed. "
380 "Duplicate WWN on HBA\n");
381 lpfc_free_vpi(phba
, vpi
);
387 /* Create binary sysfs attribute for vport */
388 lpfc_alloc_sysfs_attr(vport
);
390 /* Set the DFT_LUN_Q_DEPTH accordingly */
391 vport
->cfg_lun_queue_depth
= phba
->pport
->cfg_lun_queue_depth
;
393 *(struct lpfc_vport
**)fc_vport
->dd_data
= vport
;
394 vport
->fc_vport
= fc_vport
;
396 /* At this point we are fully registered with SCSI Layer. */
397 vport
->load_flag
|= FC_ALLOW_FDMI
;
398 if (phba
->cfg_enable_SmartSAN
||
399 (phba
->cfg_fdmi_on
== LPFC_FDMI_SUPPORT
)) {
400 /* Setup appropriate attribute masks */
401 vport
->fdmi_hba_mask
= phba
->pport
->fdmi_hba_mask
;
402 vport
->fdmi_port_mask
= phba
->pport
->fdmi_port_mask
;
406 * In SLI4, the vpi must be activated before it can be used
409 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
410 (pport
->fc_flag
& FC_VFI_REGISTERED
)) {
411 rc
= lpfc_sli4_init_vpi(vport
);
413 lpfc_printf_log(phba
, KERN_ERR
, LOG_VPORT
,
414 "1838 Failed to INIT_VPI on vpi %d "
415 "status %d\n", vpi
, rc
);
416 rc
= VPORT_NORESOURCES
;
417 lpfc_free_vpi(phba
, vpi
);
420 } else if (phba
->sli_rev
== LPFC_SLI_REV4
) {
422 * Driver cannot INIT_VPI now. Set the flags to
423 * init_vpi when reg_vfi complete.
425 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
426 lpfc_vport_set_state(vport
, FC_VPORT_LINKDOWN
);
431 if ((phba
->link_state
< LPFC_LINK_UP
) ||
432 (pport
->port_state
< LPFC_FABRIC_CFG_LINK
) ||
433 (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
)) {
434 lpfc_vport_set_state(vport
, FC_VPORT_LINKDOWN
);
440 lpfc_vport_set_state(vport
, FC_VPORT_DISABLED
);
445 /* Use the Physical nodes Fabric NDLP to determine if the link is
446 * up and ready to FDISC.
448 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
449 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
450 ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
451 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
) {
452 lpfc_set_disctmo(vport
);
453 lpfc_initial_fdisc(vport
);
455 lpfc_vport_set_state(vport
, FC_VPORT_NO_FABRIC_SUPP
);
456 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
457 "0262 No NPIV Fabric support\n");
460 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
465 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
466 "1825 Vport Created.\n");
467 lpfc_host_attrib_init(lpfc_shost_from_vport(vport
));
473 disable_vport(struct fc_vport
*fc_vport
)
475 struct lpfc_vport
*vport
= *(struct lpfc_vport
**)fc_vport
->dd_data
;
476 struct lpfc_hba
*phba
= vport
->phba
;
477 struct lpfc_nodelist
*ndlp
= NULL
, *next_ndlp
= NULL
;
479 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
481 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
482 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)
483 && phba
->link_state
>= LPFC_LINK_UP
) {
484 vport
->unreg_vpi_cmpl
= VPORT_INVAL
;
485 timeout
= msecs_to_jiffies(phba
->fc_ratov
* 2000);
486 if (!lpfc_issue_els_npiv_logo(vport
, ndlp
))
487 while (vport
->unreg_vpi_cmpl
== VPORT_INVAL
&& timeout
)
488 timeout
= schedule_timeout(timeout
);
491 lpfc_sli_host_down(vport
);
493 /* Mark all nodes for discovery so we can remove them by
494 * calling lpfc_cleanup_rpis(vport, 1)
496 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
497 if (!NLP_CHK_NODE_ACT(ndlp
))
499 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
501 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
502 NLP_EVT_DEVICE_RECOVERY
);
504 lpfc_cleanup_rpis(vport
, 1);
506 lpfc_stop_vport_timers(vport
);
507 lpfc_unreg_all_rpis(vport
);
508 lpfc_unreg_default_rpis(vport
);
510 * Completion of unreg_vpi (lpfc_mbx_cmpl_unreg_vpi) does the
511 * scsi_host_put() to release the vport.
513 lpfc_mbx_unreg_vpi(vport
);
514 spin_lock_irq(shost
->host_lock
);
515 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
516 spin_unlock_irq(shost
->host_lock
);
518 lpfc_vport_set_state(vport
, FC_VPORT_DISABLED
);
519 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
520 "1826 Vport Disabled.\n");
525 enable_vport(struct fc_vport
*fc_vport
)
527 struct lpfc_vport
*vport
= *(struct lpfc_vport
**)fc_vport
->dd_data
;
528 struct lpfc_hba
*phba
= vport
->phba
;
529 struct lpfc_nodelist
*ndlp
= NULL
;
530 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
532 if ((phba
->link_state
< LPFC_LINK_UP
) ||
533 (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
)) {
534 lpfc_vport_set_state(vport
, FC_VPORT_LINKDOWN
);
538 spin_lock_irq(shost
->host_lock
);
539 vport
->load_flag
|= FC_LOADING
;
540 if (vport
->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
) {
541 spin_unlock_irq(shost
->host_lock
);
542 lpfc_issue_init_vpi(vport
);
546 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
547 spin_unlock_irq(shost
->host_lock
);
549 /* Use the Physical nodes Fabric NDLP to determine if the link is
550 * up and ready to FDISC.
552 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
553 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)
554 && ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
555 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
) {
556 lpfc_set_disctmo(vport
);
557 lpfc_initial_fdisc(vport
);
559 lpfc_vport_set_state(vport
, FC_VPORT_NO_FABRIC_SUPP
);
560 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
561 "0264 No NPIV Fabric support\n");
564 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
568 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
569 "1827 Vport Enabled.\n");
574 lpfc_vport_disable(struct fc_vport
*fc_vport
, bool disable
)
577 return disable_vport(fc_vport
);
579 return enable_vport(fc_vport
);
584 lpfc_vport_delete(struct fc_vport
*fc_vport
)
586 struct lpfc_nodelist
*ndlp
= NULL
;
587 struct lpfc_vport
*vport
= *(struct lpfc_vport
**)fc_vport
->dd_data
;
588 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
589 struct lpfc_hba
*phba
= vport
->phba
;
591 bool ns_ndlp_referenced
= false;
593 if (vport
->port_type
== LPFC_PHYSICAL_PORT
) {
594 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
595 "1812 vport_delete failed: Cannot delete "
600 /* If the vport is a static vport fail the deletion. */
601 if ((vport
->vport_flag
& STATIC_VPORT
) &&
602 !(phba
->pport
->load_flag
& FC_UNLOADING
)) {
603 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
604 "1837 vport_delete failed: Cannot delete "
608 spin_lock_irq(&phba
->hbalock
);
609 vport
->load_flag
|= FC_UNLOADING
;
610 spin_unlock_irq(&phba
->hbalock
);
612 * If we are not unloading the driver then prevent the vport_delete
613 * from happening until after this vport's discovery is finished.
615 if (!(phba
->pport
->load_flag
& FC_UNLOADING
)) {
617 while (check_count
< ((phba
->fc_ratov
* 3) + 3) &&
618 vport
->port_state
> LPFC_VPORT_FAILED
&&
619 vport
->port_state
< LPFC_VPORT_READY
) {
623 if (vport
->port_state
> LPFC_VPORT_FAILED
&&
624 vport
->port_state
< LPFC_VPORT_READY
)
628 * This is a bit of a mess. We want to ensure the shost doesn't get
629 * torn down until we're done with the embedded lpfc_vport structure.
631 * Beyond holding a reference for this function, we also need a
632 * reference for outstanding I/O requests we schedule during delete
633 * processing. But once we scsi_remove_host() we can no longer obtain
634 * a reference through scsi_host_get().
636 * So we take two references here. We release one reference at the
637 * bottom of the function -- after delinking the vport. And we
638 * release the other at the completion of the unreg_vpi that get's
639 * initiated after we've disposed of all other resources associated
642 if (!scsi_host_get(shost
))
644 if (!scsi_host_get(shost
)) {
645 scsi_host_put(shost
);
648 lpfc_free_sysfs_attr(vport
);
650 lpfc_debugfs_terminate(vport
);
653 * The call to fc_remove_host might release the NameServer ndlp. Since
654 * we might need to use the ndlp to send the DA_ID CT command,
655 * increment the reference for the NameServer ndlp to prevent it from
658 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
659 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
661 ns_ndlp_referenced
= true;
664 /* Remove FC host and then SCSI host with the vport */
665 fc_remove_host(shost
);
666 scsi_remove_host(shost
);
668 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
670 /* In case of driver unload, we shall not perform fabric logo as the
671 * worker thread already stopped at this stage and, in this case, we
672 * can safely skip the fabric logo.
674 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
675 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
676 ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
&&
677 phba
->link_state
>= LPFC_LINK_UP
) {
678 /* First look for the Fabric ndlp */
679 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
682 else if (!NLP_CHK_NODE_ACT(ndlp
)) {
683 ndlp
= lpfc_enable_node(vport
, ndlp
,
684 NLP_STE_UNUSED_NODE
);
688 /* Remove ndlp from vport npld list */
689 lpfc_dequeue_node(vport
, ndlp
);
691 /* Indicate free memory when release */
692 spin_lock_irq(&phba
->ndlp_lock
);
693 NLP_SET_FREE_REQ(ndlp
);
694 spin_unlock_irq(&phba
->ndlp_lock
);
695 /* Kick off release ndlp when it can be safely done */
701 /* Otherwise, we will perform fabric logo as needed */
702 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
703 ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
&&
704 phba
->link_state
>= LPFC_LINK_UP
&&
705 phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
) {
706 if (vport
->cfg_enable_da_id
) {
707 timeout
= msecs_to_jiffies(phba
->fc_ratov
* 2000);
708 if (!lpfc_ns_cmd(vport
, SLI_CTNS_DA_ID
, 0, 0))
709 while (vport
->ct_flags
&& timeout
)
710 timeout
= schedule_timeout(timeout
);
712 lpfc_printf_log(vport
->phba
, KERN_WARNING
,
714 "1829 CT command failed to "
715 "delete objects on fabric\n");
717 /* First look for the Fabric ndlp */
718 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
720 /* Cannot find existing Fabric ndlp, allocate one */
721 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
724 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
725 /* Indicate free memory when release */
726 NLP_SET_FREE_REQ(ndlp
);
728 if (!NLP_CHK_NODE_ACT(ndlp
)) {
729 ndlp
= lpfc_enable_node(vport
, ndlp
,
730 NLP_STE_UNUSED_NODE
);
735 /* Remove ndlp from vport list */
736 lpfc_dequeue_node(vport
, ndlp
);
737 spin_lock_irq(&phba
->ndlp_lock
);
738 if (!NLP_CHK_FREE_REQ(ndlp
))
739 /* Indicate free memory when release */
740 NLP_SET_FREE_REQ(ndlp
);
742 /* Skip this if ndlp is already in free mode */
743 spin_unlock_irq(&phba
->ndlp_lock
);
746 spin_unlock_irq(&phba
->ndlp_lock
);
750 * If the vpi is not registered, then a valid FDISC doesn't
751 * exist and there is no need for a ELS LOGO. Just cleanup
754 if (!(vport
->vpi_state
& LPFC_VPI_REGISTERED
)) {
759 vport
->unreg_vpi_cmpl
= VPORT_INVAL
;
760 timeout
= msecs_to_jiffies(phba
->fc_ratov
* 2000);
761 if (!lpfc_issue_els_npiv_logo(vport
, ndlp
))
762 while (vport
->unreg_vpi_cmpl
== VPORT_INVAL
&& timeout
)
763 timeout
= schedule_timeout(timeout
);
766 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
767 lpfc_discovery_wait(vport
);
772 * If the NameServer ndlp has been incremented to allow the DA_ID CT
773 * command to be sent, decrement the ndlp now.
775 if (ns_ndlp_referenced
) {
776 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
781 lpfc_sli_host_down(vport
);
783 lpfc_stop_vport_timers(vport
);
785 if (!(phba
->pport
->load_flag
& FC_UNLOADING
)) {
786 lpfc_unreg_all_rpis(vport
);
787 lpfc_unreg_default_rpis(vport
);
789 * Completion of unreg_vpi (lpfc_mbx_cmpl_unreg_vpi)
790 * does the scsi_host_put() to release the vport.
792 if (!(vport
->vpi_state
& LPFC_VPI_REGISTERED
) ||
793 lpfc_mbx_unreg_vpi(vport
))
794 scsi_host_put(shost
);
796 scsi_host_put(shost
);
798 lpfc_free_vpi(phba
, vport
->vpi
);
799 vport
->work_port_events
= 0;
800 spin_lock_irq(&phba
->hbalock
);
801 list_del_init(&vport
->listentry
);
802 spin_unlock_irq(&phba
->hbalock
);
803 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_VPORT
,
804 "1828 Vport Deleted.\n");
805 scsi_host_put(shost
);
810 lpfc_create_vport_work_array(struct lpfc_hba
*phba
)
812 struct lpfc_vport
*port_iterator
;
813 struct lpfc_vport
**vports
;
815 vports
= kzalloc((phba
->max_vports
+ 1) * sizeof(struct lpfc_vport
*),
819 spin_lock_irq(&phba
->hbalock
);
820 list_for_each_entry(port_iterator
, &phba
->port_list
, listentry
) {
821 if (port_iterator
->load_flag
& FC_UNLOADING
)
823 if (!scsi_host_get(lpfc_shost_from_vport(port_iterator
))) {
824 lpfc_printf_vlog(port_iterator
, KERN_ERR
, LOG_VPORT
,
825 "1801 Create vport work array FAILED: "
826 "cannot do scsi_host_get\n");
829 vports
[index
++] = port_iterator
;
831 spin_unlock_irq(&phba
->hbalock
);
836 lpfc_destroy_vport_work_array(struct lpfc_hba
*phba
, struct lpfc_vport
**vports
)
841 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
842 scsi_host_put(lpfc_shost_from_vport(vports
[i
]));
848 * lpfc_vport_reset_stat_data - Reset the statistical data for the vport
849 * @vport: Pointer to vport object.
851 * This function resets the statistical data for the vport. This function
852 * is called with the host_lock held
855 lpfc_vport_reset_stat_data(struct lpfc_vport
*vport
)
857 struct lpfc_nodelist
*ndlp
= NULL
, *next_ndlp
= NULL
;
859 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
860 if (!NLP_CHK_NODE_ACT(ndlp
))
863 memset(ndlp
->lat_data
, 0, LPFC_MAX_BUCKET_COUNT
*
864 sizeof(struct lpfc_scsicmd_bkt
));
870 * lpfc_alloc_bucket - Allocate data buffer required for statistical data
871 * @vport: Pointer to vport object.
873 * This function allocates data buffer required for all the FC
874 * nodes of the vport to collect statistical data.
877 lpfc_alloc_bucket(struct lpfc_vport
*vport
)
879 struct lpfc_nodelist
*ndlp
= NULL
, *next_ndlp
= NULL
;
881 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
882 if (!NLP_CHK_NODE_ACT(ndlp
))
885 kfree(ndlp
->lat_data
);
886 ndlp
->lat_data
= NULL
;
888 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
) {
889 ndlp
->lat_data
= kcalloc(LPFC_MAX_BUCKET_COUNT
,
890 sizeof(struct lpfc_scsicmd_bkt
),
894 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
895 "0287 lpfc_alloc_bucket failed to "
896 "allocate statistical data buffer DID "
897 "0x%x\n", ndlp
->nlp_DID
);
903 * lpfc_free_bucket - Free data buffer required for statistical data
904 * @vport: Pointer to vport object.
906 * Th function frees statistical data buffer of all the FC
907 * nodes of the vport.
910 lpfc_free_bucket(struct lpfc_vport
*vport
)
912 struct lpfc_nodelist
*ndlp
= NULL
, *next_ndlp
= NULL
;
914 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
915 if (!NLP_CHK_NODE_ACT(ndlp
))
918 kfree(ndlp
->lat_data
);
919 ndlp
->lat_data
= NULL
;