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;
293 if ((phba->sli_rev < 3) ||
294 !(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
295 lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
296 "1808 Create VPORT failed: "
297 "NPIV is not enabled: SLImode:%d\n",
303 vpi = lpfc_alloc_vpi(phba);
305 lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
306 "1809 Create VPORT failed: "
307 "Max VPORTs (%d) exceeded\n",
309 rc = VPORT_NORESOURCES;
314 /* Assign an unused board number */
315 if ((instance = lpfc_get_instance()) < 0) {
316 lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
317 "1810 Create VPORT failed: Cannot get "
318 "instance number\n");
319 lpfc_free_vpi(phba, vpi);
320 rc = VPORT_NORESOURCES;
324 vport = lpfc_create_port(phba, instance, &fc_vport->dev);
326 lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
327 "1811 Create VPORT failed: vpi x%x\n", vpi);
328 lpfc_free_vpi(phba, vpi);
329 rc = VPORT_NORESOURCES;
334 lpfc_debugfs_initialize(vport);
336 if ((status = lpfc_vport_sparm(phba, vport))) {
337 if (status == -EINTR) {
338 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
339 "1831 Create VPORT Interrupted.\n");
342 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
343 "1813 Create VPORT failed. "
344 "Cannot get sparam\n");
345 rc = VPORT_NORESOURCES;
347 lpfc_free_vpi(phba, vpi);
352 memcpy(vport->fc_portname.u.wwn, vport->fc_sparam.portName.u.wwn, 8);
353 memcpy(vport->fc_nodename.u.wwn, vport->fc_sparam.nodeName.u.wwn, 8);
354 size = strnlen(fc_vport->symbolic_name, LPFC_VNAME_LEN);
356 vport->vname = kzalloc(size+1, GFP_KERNEL);
358 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
359 "1814 Create VPORT failed. "
360 "vname allocation failed.\n");
362 lpfc_free_vpi(phba, vpi);
366 memcpy(vport->vname, fc_vport->symbolic_name, size+1);
368 if (fc_vport->node_name != 0)
369 u64_to_wwn(fc_vport->node_name, vport->fc_nodename.u.wwn);
370 if (fc_vport->port_name != 0)
371 u64_to_wwn(fc_vport->port_name, vport->fc_portname.u.wwn);
373 memcpy(&vport->fc_sparam.portName, vport->fc_portname.u.wwn, 8);
374 memcpy(&vport->fc_sparam.nodeName, vport->fc_nodename.u.wwn, 8);
376 if (!lpfc_valid_wwn_format(phba, &vport->fc_sparam.nodeName, "WWNN") ||
377 !lpfc_valid_wwn_format(phba, &vport->fc_sparam.portName, "WWPN")) {
378 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
379 "1821 Create VPORT failed. "
380 "Invalid WWN format\n");
381 lpfc_free_vpi(phba, vpi);
387 if (!lpfc_unique_wwpn(phba, vport)) {
388 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
389 "1823 Create VPORT failed. "
390 "Duplicate WWN on HBA\n");
391 lpfc_free_vpi(phba, vpi);
397 *(struct lpfc_vport **)fc_vport->dd_data = vport;
398 vport->fc_vport = fc_vport;
400 if ((phba->link_state < LPFC_LINK_UP) ||
401 (phba->fc_topology == TOPOLOGY_LOOP)) {
402 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
412 /* Use the Physical nodes Fabric NDLP to determine if the link is
413 * up and ready to FDISC.
415 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
416 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
417 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
418 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) {
419 lpfc_set_disctmo(vport);
420 lpfc_initial_fdisc(vport);
422 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
423 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
424 "0262 No NPIV Fabric support\n");
427 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
432 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
433 "1825 Vport Created.\n");
434 lpfc_host_attrib_init(lpfc_shost_from_vport(vport));
440 disable_vport(struct fc_vport *fc_vport)
442 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
443 struct lpfc_hba *phba = vport->phba;
444 struct lpfc_nodelist *ndlp = NULL, *next_ndlp = NULL;
447 ndlp = lpfc_findnode_did(vport, Fabric_DID);
448 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
449 && phba->link_state >= LPFC_LINK_UP) {
450 vport->unreg_vpi_cmpl = VPORT_INVAL;
451 timeout = msecs_to_jiffies(phba->fc_ratov * 2000);
452 if (!lpfc_issue_els_npiv_logo(vport, ndlp))
453 while (vport->unreg_vpi_cmpl == VPORT_INVAL && timeout)
454 timeout = schedule_timeout(timeout);
457 lpfc_sli_host_down(vport);
459 /* Mark all nodes for discovery so we can remove them by
460 * calling lpfc_cleanup_rpis(vport, 1)
462 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
463 if (!NLP_CHK_NODE_ACT(ndlp))
465 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
467 lpfc_disc_state_machine(vport, ndlp, NULL,
468 NLP_EVT_DEVICE_RECOVERY);
470 lpfc_cleanup_rpis(vport, 1);
472 lpfc_stop_vport_timers(vport);
473 lpfc_unreg_all_rpis(vport);
474 lpfc_unreg_default_rpis(vport);
476 * Completion of unreg_vpi (lpfc_mbx_cmpl_unreg_vpi) does the
477 * scsi_host_put() to release the vport.
479 lpfc_mbx_unreg_vpi(vport);
481 lpfc_vport_set_state(vport, FC_VPORT_DISABLED);
482 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
483 "1826 Vport Disabled.\n");
488 enable_vport(struct fc_vport *fc_vport)
490 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
491 struct lpfc_hba *phba = vport->phba;
492 struct lpfc_nodelist *ndlp = NULL;
494 if ((phba->link_state < LPFC_LINK_UP) ||
495 (phba->fc_topology == TOPOLOGY_LOOP)) {
496 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
500 vport->load_flag |= FC_LOADING;
501 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
503 /* Use the Physical nodes Fabric NDLP to determine if the link is
504 * up and ready to FDISC.
506 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
507 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
508 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
509 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) {
510 lpfc_set_disctmo(vport);
511 lpfc_initial_fdisc(vport);
513 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
514 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
515 "0264 No NPIV Fabric support\n");
518 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
520 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
521 "1827 Vport Enabled.\n");
526 lpfc_vport_disable(struct fc_vport *fc_vport, bool disable)
529 return disable_vport(fc_vport);
531 return enable_vport(fc_vport);
536 lpfc_vport_delete(struct fc_vport *fc_vport)
538 struct lpfc_nodelist *ndlp = NULL;
539 struct Scsi_Host *shost = (struct Scsi_Host *) fc_vport->shost;
540 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
541 struct lpfc_hba *phba = vport->phba;
544 if (vport->port_type == LPFC_PHYSICAL_PORT) {
545 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
546 "1812 vport_delete failed: Cannot delete "
551 * If we are not unloading the driver then prevent the vport_delete
552 * from happening until after this vport's discovery is finished.
554 if (!(phba->pport->load_flag & FC_UNLOADING)) {
556 while (check_count < ((phba->fc_ratov * 3) + 3) &&
557 vport->port_state > LPFC_VPORT_FAILED &&
558 vport->port_state < LPFC_VPORT_READY) {
562 if (vport->port_state > LPFC_VPORT_FAILED &&
563 vport->port_state < LPFC_VPORT_READY)
567 * This is a bit of a mess. We want to ensure the shost doesn't get
568 * torn down until we're done with the embedded lpfc_vport structure.
570 * Beyond holding a reference for this function, we also need a
571 * reference for outstanding I/O requests we schedule during delete
572 * processing. But once we scsi_remove_host() we can no longer obtain
573 * a reference through scsi_host_get().
575 * So we take two references here. We release one reference at the
576 * bottom of the function -- after delinking the vport. And we
577 * release the other at the completion of the unreg_vpi that get's
578 * initiated after we've disposed of all other resources associated
581 if (!scsi_host_get(shost))
583 if (!scsi_host_get(shost)) {
584 scsi_host_put(shost);
587 spin_lock_irq(&phba->hbalock);
588 vport->load_flag |= FC_UNLOADING;
589 spin_unlock_irq(&phba->hbalock);
591 lpfc_debugfs_terminate(vport);
592 fc_remove_host(lpfc_shost_from_vport(vport));
593 scsi_remove_host(lpfc_shost_from_vport(vport));
595 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
597 /* In case of driver unload, we shall not perform fabric logo as the
598 * worker thread already stopped at this stage and, in this case, we
599 * can safely skip the fabric logo.
601 if (phba->pport->load_flag & FC_UNLOADING) {
602 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
603 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE &&
604 phba->link_state >= LPFC_LINK_UP) {
605 /* First look for the Fabric ndlp */
606 ndlp = lpfc_findnode_did(vport, Fabric_DID);
609 else if (!NLP_CHK_NODE_ACT(ndlp)) {
610 ndlp = lpfc_enable_node(vport, ndlp,
611 NLP_STE_UNUSED_NODE);
615 /* Remove ndlp from vport npld list */
616 lpfc_dequeue_node(vport, ndlp);
618 /* Indicate free memory when release */
619 spin_lock_irq(&phba->ndlp_lock);
620 NLP_SET_FREE_REQ(ndlp);
621 spin_unlock_irq(&phba->ndlp_lock);
622 /* Kick off release ndlp when it can be safely done */
628 /* Otherwise, we will perform fabric logo as needed */
629 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
630 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE &&
631 phba->link_state >= LPFC_LINK_UP &&
632 phba->fc_topology != TOPOLOGY_LOOP) {
633 if (vport->cfg_enable_da_id) {
634 timeout = msecs_to_jiffies(phba->fc_ratov * 2000);
635 if (!lpfc_ns_cmd(vport, SLI_CTNS_DA_ID, 0, 0))
636 while (vport->ct_flags && timeout)
637 timeout = schedule_timeout(timeout);
639 lpfc_printf_log(vport->phba, KERN_WARNING,
641 "1829 CT command failed to "
642 "delete objects on fabric. \n");
644 /* First look for the Fabric ndlp */
645 ndlp = lpfc_findnode_did(vport, Fabric_DID);
647 /* Cannot find existing Fabric ndlp, allocate one */
648 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
651 lpfc_nlp_init(vport, ndlp, Fabric_DID);
652 /* Indicate free memory when release */
653 NLP_SET_FREE_REQ(ndlp);
655 if (!NLP_CHK_NODE_ACT(ndlp))
656 ndlp = lpfc_enable_node(vport, ndlp,
657 NLP_STE_UNUSED_NODE);
661 /* Remove ndlp from vport npld list */
662 lpfc_dequeue_node(vport, ndlp);
663 spin_lock_irq(&phba->ndlp_lock);
664 if (!NLP_CHK_FREE_REQ(ndlp))
665 /* Indicate free memory when release */
666 NLP_SET_FREE_REQ(ndlp);
668 /* Skip this if ndlp is already in free mode */
669 spin_unlock_irq(&phba->ndlp_lock);
672 spin_unlock_irq(&phba->ndlp_lock);
674 vport->unreg_vpi_cmpl = VPORT_INVAL;
675 timeout = msecs_to_jiffies(phba->fc_ratov * 2000);
676 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
678 if (!lpfc_issue_els_npiv_logo(vport, ndlp))
679 while (vport->unreg_vpi_cmpl == VPORT_INVAL && timeout)
680 timeout = schedule_timeout(timeout);
683 if (!(phba->pport->load_flag & FC_UNLOADING))
684 lpfc_discovery_wait(vport);
688 lpfc_sli_host_down(vport);
690 lpfc_stop_vport_timers(vport);
692 if (!(phba->pport->load_flag & FC_UNLOADING)) {
693 lpfc_unreg_all_rpis(vport);
694 lpfc_unreg_default_rpis(vport);
696 * Completion of unreg_vpi (lpfc_mbx_cmpl_unreg_vpi)
697 * does the scsi_host_put() to release the vport.
699 if (lpfc_mbx_unreg_vpi(vport))
700 scsi_host_put(shost);
702 scsi_host_put(shost);
704 lpfc_free_vpi(phba, vport->vpi);
705 vport->work_port_events = 0;
706 spin_lock_irq(&phba->hbalock);
707 list_del_init(&vport->listentry);
708 spin_unlock_irq(&phba->hbalock);
709 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
710 "1828 Vport Deleted.\n");
711 scsi_host_put(shost);
716 lpfc_create_vport_work_array(struct lpfc_hba *phba)
718 struct lpfc_vport *port_iterator;
719 struct lpfc_vport **vports;
721 vports = kzalloc((phba->max_vpi + 1) * sizeof(struct lpfc_vport *),
725 spin_lock_irq(&phba->hbalock);
726 list_for_each_entry(port_iterator, &phba->port_list, listentry) {
727 if (!scsi_host_get(lpfc_shost_from_vport(port_iterator))) {
728 lpfc_printf_vlog(port_iterator, KERN_WARNING, LOG_VPORT,
729 "1801 Create vport work array FAILED: "
730 "cannot do scsi_host_get\n");
733 vports[index++] = port_iterator;
735 spin_unlock_irq(&phba->hbalock);
740 lpfc_destroy_vport_work_array(struct lpfc_hba *phba, struct lpfc_vport **vports)
745 for (i=0; vports[i] != NULL && i <= phba->max_vpi; i++)
746 scsi_host_put(lpfc_shost_from_vport(vports[i]));
752 * lpfc_vport_reset_stat_data: Reset the statistical data for the vport.
753 * @vport: Pointer to vport object.
755 * This function resets the statistical data for the vport. This function
756 * is called with the host_lock held
759 lpfc_vport_reset_stat_data(struct lpfc_vport *vport)
761 struct lpfc_nodelist *ndlp = NULL, *next_ndlp = NULL;
763 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
764 if (!NLP_CHK_NODE_ACT(ndlp))
767 memset(ndlp->lat_data, 0, LPFC_MAX_BUCKET_COUNT *
768 sizeof(struct lpfc_scsicmd_bkt));
774 * lpfc_alloc_bucket: Allocate data buffer required for collecting
776 * @vport: Pointer to vport object.
778 * This function allocates data buffer required for all the FC
779 * nodes of the vport to collect statistical data.
782 lpfc_alloc_bucket(struct lpfc_vport *vport)
784 struct lpfc_nodelist *ndlp = NULL, *next_ndlp = NULL;
786 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
787 if (!NLP_CHK_NODE_ACT(ndlp))
790 kfree(ndlp->lat_data);
791 ndlp->lat_data = NULL;
793 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
794 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
795 sizeof(struct lpfc_scsicmd_bkt),
799 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
800 "0287 lpfc_alloc_bucket failed to "
801 "allocate statistical data buffer DID "
802 "0x%x\n", ndlp->nlp_DID);
808 * lpfc_free_bucket: Free data buffer required for collecting
810 * @vport: Pointer to vport object.
812 * Th function frees statistical data buffer of all the FC
813 * nodes of the vport.
816 lpfc_free_bucket(struct lpfc_vport *vport)
818 struct lpfc_nodelist *ndlp = NULL, *next_ndlp = NULL;
820 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
821 if (!NLP_CHK_NODE_ACT(ndlp))
824 kfree(ndlp->lat_data);
825 ndlp->lat_data = NULL;