blob: b3f85def18ccca8daff2a809aac3d7b4e69cec1e [file] [log] [blame]
James Smart92d7f7b2007-06-17 19:56:38 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
James Smarta89a96b2013-07-15 18:35:40 -04004 * Copyright (C) 2004-2013 Emulex. All rights reserved. *
James Smart92d7f7b2007-06-17 19:56:38 -05005 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
8 * *
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 *******************************************************************/
21
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
James Smart92d7f7b2007-06-17 19:56:38 -050030#include <linux/spinlock.h>
31
32#include <scsi/scsi.h>
33#include <scsi/scsi_device.h>
34#include <scsi/scsi_host.h>
35#include <scsi/scsi_transport_fc.h>
James Smartda0436e2009-05-22 14:51:39 -040036#include "lpfc_hw4.h"
James Smart92d7f7b2007-06-17 19:56:38 -050037#include "lpfc_hw.h"
38#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040039#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040040#include "lpfc_nl.h"
James Smart92d7f7b2007-06-17 19:56:38 -050041#include "lpfc_disc.h"
42#include "lpfc_scsi.h"
43#include "lpfc.h"
44#include "lpfc_logmsg.h"
45#include "lpfc_crtn.h"
46#include "lpfc_version.h"
47#include "lpfc_vport.h"
48
49inline void lpfc_vport_set_state(struct lpfc_vport *vport,
50 enum fc_vport_state new_state)
51{
52 struct fc_vport *fc_vport = vport->fc_vport;
53
54 if (fc_vport) {
55 /*
56 * When the transport defines fc_vport_set state we will replace
57 * this code with the following line
58 */
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;
63 }
64
65 /* for all the error states we will set the invternal state to FAILED */
66 switch (new_state) {
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:
71 case FC_VPORT_FAILED:
72 vport->port_state = LPFC_VPORT_FAILED;
73 break;
74 case FC_VPORT_LINKDOWN:
75 vport->port_state = LPFC_VPORT_UNKNOWN;
76 break;
77 default:
78 /* do nothing */
79 break;
80 }
81}
82
James Smart16a3a202013-04-17 20:14:38 -040083int
James Smart92d7f7b2007-06-17 19:56:38 -050084lpfc_alloc_vpi(struct lpfc_hba *phba)
85{
James Smart6d368e52011-05-24 11:44:12 -040086 unsigned long vpi;
James Smart92d7f7b2007-06-17 19:56:38 -050087
88 spin_lock_irq(&phba->hbalock);
James Smart858c9f62007-06-17 19:56:39 -050089 /* 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);
James Smart92d7f7b2007-06-17 19:56:38 -050091 if (vpi > phba->max_vpi)
92 vpi = 0;
93 else
94 set_bit(vpi, phba->vpi_bmask);
James Smartda0436e2009-05-22 14:51:39 -040095 if (phba->sli_rev == LPFC_SLI_REV4)
96 phba->sli4_hba.max_cfg_param.vpi_used++;
James Smart92d7f7b2007-06-17 19:56:38 -050097 spin_unlock_irq(&phba->hbalock);
98 return vpi;
99}
100
101static void
102lpfc_free_vpi(struct lpfc_hba *phba, int vpi)
103{
James Smartda0436e2009-05-22 14:51:39 -0400104 if (vpi == 0)
105 return;
James Smart92d7f7b2007-06-17 19:56:38 -0500106 spin_lock_irq(&phba->hbalock);
107 clear_bit(vpi, phba->vpi_bmask);
James Smartda0436e2009-05-22 14:51:39 -0400108 if (phba->sli_rev == LPFC_SLI_REV4)
109 phba->sli4_hba.max_cfg_param.vpi_used--;
James Smart92d7f7b2007-06-17 19:56:38 -0500110 spin_unlock_irq(&phba->hbalock);
111}
112
113static int
114lpfc_vport_sparm(struct lpfc_hba *phba, struct lpfc_vport *vport)
115{
116 LPFC_MBOXQ_t *pmb;
117 MAILBOX_t *mb;
118 struct lpfc_dmabuf *mp;
119 int rc;
120
121 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
122 if (!pmb) {
123 return -ENOMEM;
124 }
James Smartf4b4c682009-05-22 14:53:12 -0400125 mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500126
James Smart9f1177a2010-02-26 14:12:57 -0500127 rc = lpfc_read_sparam(phba, pmb, vport->vpi);
128 if (rc) {
129 mempool_free(pmb, phba->mbox_mem_pool);
130 return -ENOMEM;
131 }
132
James Smart92d7f7b2007-06-17 19:56:38 -0500133 /*
134 * Grab buffer pointer and clear context1 so we can use
135 * lpfc_sli_issue_box_wait
136 */
137 mp = (struct lpfc_dmabuf *) pmb->context1;
138 pmb->context1 = NULL;
139
140 pmb->vport = vport;
141 rc = lpfc_sli_issue_mbox_wait(phba, pmb, phba->fc_ratov * 2);
142 if (rc != MBX_SUCCESS) {
James Smart98c9ea52007-10-27 13:37:33 -0400143 if (signal_pending(current)) {
144 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT | LOG_VPORT,
145 "1830 Signal aborted mbxCmd x%x\n",
146 mb->mbxCommand);
147 lpfc_mbuf_free(phba, mp->virt, mp->phys);
148 kfree(mp);
149 if (rc != MBX_TIMEOUT)
150 mempool_free(pmb, phba->mbox_mem_pool);
151 return -EINTR;
152 } else {
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);
158 kfree(mp);
159 if (rc != MBX_TIMEOUT)
160 mempool_free(pmb, phba->mbox_mem_pool);
161 return -EIO;
162 }
James Smart92d7f7b2007-06-17 19:56:38 -0500163 }
164
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));
170
171 lpfc_mbuf_free(phba, mp->virt, mp->phys);
172 kfree(mp);
173 mempool_free(pmb, phba->mbox_mem_pool);
174
175 return 0;
176}
177
178static int
179lpfc_valid_wwn_format(struct lpfc_hba *phba, struct lpfc_name *wwn,
180 const char *name_type)
181{
182 /* ensure that IEEE format 1 addresses
183 * contain zeros in bits 59-48
184 */
185 if (!((wwn->u.wwn[0] >> 4) == 1 &&
186 ((wwn->u.wwn[0] & 0xf) != 0 || (wwn->u.wwn[1] & 0xf) != 0)))
187 return 1;
188
189 lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -0400190 "1822 Invalid %s: %02x:%02x:%02x:%02x:"
James Smart92d7f7b2007-06-17 19:56:38 -0500191 "%02x:%02x:%02x:%02x\n",
James Smarte8b62012007-08-02 11:10:09 -0400192 name_type,
James Smart92d7f7b2007-06-17 19:56:38 -0500193 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]);
197 return 0;
198}
199
200static int
201lpfc_unique_wwpn(struct lpfc_hba *phba, struct lpfc_vport *new_vport)
202{
203 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -0400204 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -0500205
James Smart549e55c2007-08-02 11:09:51 -0400206 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500207 list_for_each_entry(vport, &phba->port_list, listentry) {
208 if (vport == new_vport)
209 continue;
210 /* If they match, return not unique */
211 if (memcmp(&vport->fc_sparam.portName,
James Smart549e55c2007-08-02 11:09:51 -0400212 &new_vport->fc_sparam.portName,
213 sizeof(struct lpfc_name)) == 0) {
214 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500215 return 0;
James Smart549e55c2007-08-02 11:09:51 -0400216 }
James Smart92d7f7b2007-06-17 19:56:38 -0500217 }
James Smart549e55c2007-08-02 11:09:51 -0400218 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500219 return 1;
220}
221
James Smart90160e02008-08-24 21:49:45 -0400222/**
James Smart3621a712009-04-06 18:47:14 -0400223 * lpfc_discovery_wait - Wait for driver discovery to quiesce
James Smart90160e02008-08-24 21:49:45 -0400224 * @vport: The virtual port for which this call is being executed.
225 *
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
233 * cleanup.
234 *
235 * This routine does not require any locks held.
236 **/
237static void lpfc_discovery_wait(struct lpfc_vport *vport)
238{
239 struct lpfc_hba *phba = vport->phba;
240 uint32_t wait_flags = 0;
241 unsigned long wait_time_max;
242 unsigned long start_time;
243
244 wait_flags = FC_RSCN_MODE | FC_RSCN_DISCOVERY | FC_NLP_MORE |
245 FC_RSCN_DEFERRED | FC_NDISC_ACTIVE | FC_DISC_TMO;
246
247 /*
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.
251 */
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))) {
James Smart21e9a0a2009-05-22 14:53:21 -0400260 lpfc_printf_vlog(vport, KERN_INFO, LOG_VPORT,
James Smart90160e02008-08-24 21:49:45 -0400261 "1833 Vport discovery quiesce Wait:"
James Smart21e9a0a2009-05-22 14:53:21 -0400262 " state x%x fc_flags x%x"
James Smart90160e02008-08-24 21:49:45 -0400263 " num_nodes x%x, waiting 1000 msecs"
264 " total wait msecs x%x\n",
James Smart21e9a0a2009-05-22 14:53:21 -0400265 vport->port_state, vport->fc_flag,
266 vport->num_disc_nodes,
James Smart90160e02008-08-24 21:49:45 -0400267 jiffies_to_msecs(jiffies - start_time));
268 msleep(1000);
269 } else {
270 /* Base case. Wait variants satisfied. Break out */
James Smart21e9a0a2009-05-22 14:53:21 -0400271 lpfc_printf_vlog(vport, KERN_INFO, LOG_VPORT,
James Smart90160e02008-08-24 21:49:45 -0400272 "1834 Vport discovery quiesced:"
James Smart21e9a0a2009-05-22 14:53:21 -0400273 " state x%x fc_flags x%x"
James Smart90160e02008-08-24 21:49:45 -0400274 " wait msecs x%x\n",
James Smart21e9a0a2009-05-22 14:53:21 -0400275 vport->port_state, vport->fc_flag,
James Smart90160e02008-08-24 21:49:45 -0400276 jiffies_to_msecs(jiffies
277 - start_time));
278 break;
279 }
280 }
281
282 if (time_after(jiffies, wait_time_max))
James Smart21e9a0a2009-05-22 14:53:21 -0400283 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
James Smart90160e02008-08-24 21:49:45 -0400284 "1835 Vport discovery quiesce failed:"
James Smart21e9a0a2009-05-22 14:53:21 -0400285 " state x%x fc_flags x%x wait msecs x%x\n",
286 vport->port_state, vport->fc_flag,
James Smart90160e02008-08-24 21:49:45 -0400287 jiffies_to_msecs(jiffies - start_time));
288}
289
James Smart92d7f7b2007-06-17 19:56:38 -0500290int
291lpfc_vport_create(struct fc_vport *fc_vport, bool disable)
292{
293 struct lpfc_nodelist *ndlp;
James Smart3de2a652007-08-02 11:09:59 -0400294 struct Scsi_Host *shost = fc_vport->shost;
295 struct lpfc_vport *pport = (struct lpfc_vport *) shost->hostdata;
James Smart92d7f7b2007-06-17 19:56:38 -0500296 struct lpfc_hba *phba = pport->phba;
297 struct lpfc_vport *vport = NULL;
298 int instance;
299 int vpi;
300 int rc = VPORT_ERROR;
James Smart98c9ea52007-10-27 13:37:33 -0400301 int status;
James Smart92d7f7b2007-06-17 19:56:38 -0500302
James Smarteada2722008-12-04 22:39:13 -0500303 if ((phba->sli_rev < 3) || !(phba->cfg_enable_npiv)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500304 lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -0400305 "1808 Create VPORT failed: "
James Smart92d7f7b2007-06-17 19:56:38 -0500306 "NPIV is not enabled: SLImode:%d\n",
James Smarte8b62012007-08-02 11:10:09 -0400307 phba->sli_rev);
James Smart92d7f7b2007-06-17 19:56:38 -0500308 rc = VPORT_INVAL;
309 goto error_out;
310 }
311
312 vpi = lpfc_alloc_vpi(phba);
313 if (vpi == 0) {
314 lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -0400315 "1809 Create VPORT failed: "
James Smart92d7f7b2007-06-17 19:56:38 -0500316 "Max VPORTs (%d) exceeded\n",
James Smarte8b62012007-08-02 11:10:09 -0400317 phba->max_vpi);
James Smart92d7f7b2007-06-17 19:56:38 -0500318 rc = VPORT_NORESOURCES;
319 goto error_out;
320 }
321
James Smart92d7f7b2007-06-17 19:56:38 -0500322 /* Assign an unused board number */
323 if ((instance = lpfc_get_instance()) < 0) {
324 lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -0400325 "1810 Create VPORT failed: Cannot get "
326 "instance number\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500327 lpfc_free_vpi(phba, vpi);
328 rc = VPORT_NORESOURCES;
329 goto error_out;
330 }
331
James Smart3de2a652007-08-02 11:09:59 -0400332 vport = lpfc_create_port(phba, instance, &fc_vport->dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500333 if (!vport) {
334 lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -0400335 "1811 Create VPORT failed: vpi x%x\n", vpi);
James Smart92d7f7b2007-06-17 19:56:38 -0500336 lpfc_free_vpi(phba, vpi);
337 rc = VPORT_NORESOURCES;
338 goto error_out;
339 }
340
341 vport->vpi = vpi;
James Smart858c9f62007-06-17 19:56:39 -0500342 lpfc_debugfs_initialize(vport);
343
James Smart98c9ea52007-10-27 13:37:33 -0400344 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");
348 rc = VPORT_ERROR;
349 } else {
350 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
351 "1813 Create VPORT failed. "
352 "Cannot get sparam\n");
353 rc = VPORT_NORESOURCES;
354 }
James Smart92d7f7b2007-06-17 19:56:38 -0500355 lpfc_free_vpi(phba, vpi);
356 destroy_port(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500357 goto error_out;
358 }
359
James Smart1c6834a2009-07-19 10:01:26 -0400360 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);
James Smart92d7f7b2007-06-17 19:56:38 -0500362
363 memcpy(&vport->fc_sparam.portName, vport->fc_portname.u.wwn, 8);
364 memcpy(&vport->fc_sparam.nodeName, vport->fc_nodename.u.wwn, 8);
365
366 if (!lpfc_valid_wwn_format(phba, &vport->fc_sparam.nodeName, "WWNN") ||
367 !lpfc_valid_wwn_format(phba, &vport->fc_sparam.portName, "WWPN")) {
James Smarte8b62012007-08-02 11:10:09 -0400368 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
369 "1821 Create VPORT failed. "
370 "Invalid WWN format\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500371 lpfc_free_vpi(phba, vpi);
372 destroy_port(vport);
373 rc = VPORT_INVAL;
374 goto error_out;
375 }
376
377 if (!lpfc_unique_wwpn(phba, vport)) {
James Smarte8b62012007-08-02 11:10:09 -0400378 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
379 "1823 Create VPORT failed. "
380 "Duplicate WWN on HBA\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500381 lpfc_free_vpi(phba, vpi);
382 destroy_port(vport);
383 rc = VPORT_INVAL;
384 goto error_out;
385 }
386
James Smarteada2722008-12-04 22:39:13 -0500387 /* Create binary sysfs attribute for vport */
388 lpfc_alloc_sysfs_attr(vport);
389
James Smart572709e2013-07-15 18:32:43 -0400390 /* Set the DFT_LUN_Q_DEPTH accordingly */
391 vport->cfg_lun_queue_depth = phba->pport->cfg_lun_queue_depth;
392
James Smart92d7f7b2007-06-17 19:56:38 -0500393 *(struct lpfc_vport **)fc_vport->dd_data = vport;
394 vport->fc_vport = fc_vport;
395
James Smart4258e982015-12-16 18:11:58 -0500396 /* At this point we are fully registered with SCSI Layer. */
397 vport->load_flag |= FC_ALLOW_FDMI;
398 if (phba->cfg_fdmi_on > LPFC_FDMI_NO_SUPPORT) {
399 /* Setup appropriate attribute masks */
400 vport->fdmi_hba_mask = phba->pport->fdmi_hba_mask;
401 vport->fdmi_port_mask = phba->pport->fdmi_port_mask;
402 }
403
James Smart1c6834a2009-07-19 10:01:26 -0400404 /*
405 * In SLI4, the vpi must be activated before it can be used
406 * by the port.
407 */
408 if ((phba->sli_rev == LPFC_SLI_REV4) &&
James Smart76a95d72010-11-20 23:11:48 -0500409 (pport->fc_flag & FC_VFI_REGISTERED)) {
410 rc = lpfc_sli4_init_vpi(vport);
James Smart1c6834a2009-07-19 10:01:26 -0400411 if (rc) {
412 lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
413 "1838 Failed to INIT_VPI on vpi %d "
414 "status %d\n", vpi, rc);
415 rc = VPORT_NORESOURCES;
416 lpfc_free_vpi(phba, vpi);
417 goto error_out;
418 }
419 } else if (phba->sli_rev == LPFC_SLI_REV4) {
420 /*
421 * Driver cannot INIT_VPI now. Set the flags to
422 * init_vpi when reg_vfi complete.
423 */
424 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
425 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
426 rc = VPORT_OK;
427 goto out;
428 }
429
James Smart92d7f7b2007-06-17 19:56:38 -0500430 if ((phba->link_state < LPFC_LINK_UP) ||
James Smart1c6834a2009-07-19 10:01:26 -0400431 (pport->port_state < LPFC_FABRIC_CFG_LINK) ||
James Smart76a95d72010-11-20 23:11:48 -0500432 (phba->fc_topology == LPFC_TOPOLOGY_LOOP)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500433 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
434 rc = VPORT_OK;
435 goto out;
436 }
437
438 if (disable) {
James Smarteada2722008-12-04 22:39:13 -0500439 lpfc_vport_set_state(vport, FC_VPORT_DISABLED);
James Smart92d7f7b2007-06-17 19:56:38 -0500440 rc = VPORT_OK;
441 goto out;
442 }
443
444 /* Use the Physical nodes Fabric NDLP to determine if the link is
445 * up and ready to FDISC.
446 */
447 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500448 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
449 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
James Smart858c9f62007-06-17 19:56:39 -0500450 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) {
451 lpfc_set_disctmo(vport);
452 lpfc_initial_fdisc(vport);
453 } else {
454 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
James Smarte8b62012007-08-02 11:10:09 -0400455 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
456 "0262 No NPIV Fabric support\n");
James Smart858c9f62007-06-17 19:56:39 -0500457 }
James Smart92d7f7b2007-06-17 19:56:38 -0500458 } else {
459 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
460 }
461 rc = VPORT_OK;
462
463out:
James Smarta58cbd52007-08-02 11:09:43 -0400464 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
465 "1825 Vport Created.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500466 lpfc_host_attrib_init(lpfc_shost_from_vport(vport));
467error_out:
468 return rc;
469}
470
James Smart311464e2007-08-02 11:10:37 -0400471static int
James Smart92d7f7b2007-06-17 19:56:38 -0500472disable_vport(struct fc_vport *fc_vport)
473{
474 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
475 struct lpfc_hba *phba = vport->phba;
476 struct lpfc_nodelist *ndlp = NULL, *next_ndlp = NULL;
477 long timeout;
James Smartfedd3b72011-02-16 12:39:24 -0500478 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500479
480 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500481 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
482 && phba->link_state >= LPFC_LINK_UP) {
James Smart92d7f7b2007-06-17 19:56:38 -0500483 vport->unreg_vpi_cmpl = VPORT_INVAL;
484 timeout = msecs_to_jiffies(phba->fc_ratov * 2000);
485 if (!lpfc_issue_els_npiv_logo(vport, ndlp))
486 while (vport->unreg_vpi_cmpl == VPORT_INVAL && timeout)
487 timeout = schedule_timeout(timeout);
488 }
489
490 lpfc_sli_host_down(vport);
491
492 /* Mark all nodes for discovery so we can remove them by
493 * calling lpfc_cleanup_rpis(vport, 1)
494 */
495 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500496 if (!NLP_CHK_NODE_ACT(ndlp))
497 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500498 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
499 continue;
500 lpfc_disc_state_machine(vport, ndlp, NULL,
501 NLP_EVT_DEVICE_RECOVERY);
502 }
503 lpfc_cleanup_rpis(vport, 1);
504
505 lpfc_stop_vport_timers(vport);
506 lpfc_unreg_all_rpis(vport);
507 lpfc_unreg_default_rpis(vport);
508 /*
509 * Completion of unreg_vpi (lpfc_mbx_cmpl_unreg_vpi) does the
510 * scsi_host_put() to release the vport.
511 */
512 lpfc_mbx_unreg_vpi(vport);
James Smartfedd3b72011-02-16 12:39:24 -0500513 spin_lock_irq(shost->host_lock);
514 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
515 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500516
517 lpfc_vport_set_state(vport, FC_VPORT_DISABLED);
James Smarta58cbd52007-08-02 11:09:43 -0400518 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
519 "1826 Vport Disabled.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500520 return VPORT_OK;
521}
522
James Smart311464e2007-08-02 11:10:37 -0400523static int
James Smart92d7f7b2007-06-17 19:56:38 -0500524enable_vport(struct fc_vport *fc_vport)
525{
526 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
527 struct lpfc_hba *phba = vport->phba;
528 struct lpfc_nodelist *ndlp = NULL;
James Smart72100cc2010-02-12 14:43:01 -0500529 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500530
531 if ((phba->link_state < LPFC_LINK_UP) ||
James Smart76a95d72010-11-20 23:11:48 -0500532 (phba->fc_topology == LPFC_TOPOLOGY_LOOP)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500533 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
534 return VPORT_OK;
535 }
536
James Smart72100cc2010-02-12 14:43:01 -0500537 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500538 vport->load_flag |= FC_LOADING;
539 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -0500540 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500541
542 /* Use the Physical nodes Fabric NDLP to determine if the link is
543 * up and ready to FDISC.
544 */
545 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500546 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
547 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
James Smart858c9f62007-06-17 19:56:39 -0500548 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) {
549 lpfc_set_disctmo(vport);
550 lpfc_initial_fdisc(vport);
551 } else {
552 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
James Smarte8b62012007-08-02 11:10:09 -0400553 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
554 "0264 No NPIV Fabric support\n");
James Smart858c9f62007-06-17 19:56:39 -0500555 }
James Smart92d7f7b2007-06-17 19:56:38 -0500556 } else {
557 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
558 }
James Smarta58cbd52007-08-02 11:09:43 -0400559 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
560 "1827 Vport Enabled.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500561 return VPORT_OK;
562}
563
564int
565lpfc_vport_disable(struct fc_vport *fc_vport, bool disable)
566{
567 if (disable)
568 return disable_vport(fc_vport);
569 else
570 return enable_vport(fc_vport);
571}
572
573
574int
575lpfc_vport_delete(struct fc_vport *fc_vport)
576{
577 struct lpfc_nodelist *ndlp = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -0500578 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
James Smartcc823552015-05-21 13:55:26 -0400579 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500580 struct lpfc_hba *phba = vport->phba;
581 long timeout;
James Smart16a3a202013-04-17 20:14:38 -0400582 bool ns_ndlp_referenced = false;
James Smart92d7f7b2007-06-17 19:56:38 -0500583
James Smart51ef4c22007-08-02 11:10:31 -0400584 if (vport->port_type == LPFC_PHYSICAL_PORT) {
585 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
586 "1812 vport_delete failed: Cannot delete "
587 "physical host\n");
588 return VPORT_ERROR;
589 }
James Smart21e9a0a2009-05-22 14:53:21 -0400590
591 /* If the vport is a static vport fail the deletion. */
592 if ((vport->vport_flag & STATIC_VPORT) &&
593 !(phba->pport->load_flag & FC_UNLOADING)) {
594 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
595 "1837 vport_delete failed: Cannot delete "
596 "static vport.\n");
597 return VPORT_ERROR;
598 }
James Smartd439d282010-09-29 11:18:45 -0400599 spin_lock_irq(&phba->hbalock);
600 vport->load_flag |= FC_UNLOADING;
601 spin_unlock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -0400602 /*
603 * If we are not unloading the driver then prevent the vport_delete
604 * from happening until after this vport's discovery is finished.
605 */
606 if (!(phba->pport->load_flag & FC_UNLOADING)) {
607 int check_count = 0;
608 while (check_count < ((phba->fc_ratov * 3) + 3) &&
609 vport->port_state > LPFC_VPORT_FAILED &&
610 vport->port_state < LPFC_VPORT_READY) {
611 check_count++;
612 msleep(1000);
613 }
614 if (vport->port_state > LPFC_VPORT_FAILED &&
615 vport->port_state < LPFC_VPORT_READY)
616 return -EAGAIN;
617 }
James Smart92d7f7b2007-06-17 19:56:38 -0500618 /*
619 * This is a bit of a mess. We want to ensure the shost doesn't get
620 * torn down until we're done with the embedded lpfc_vport structure.
621 *
622 * Beyond holding a reference for this function, we also need a
623 * reference for outstanding I/O requests we schedule during delete
624 * processing. But once we scsi_remove_host() we can no longer obtain
625 * a reference through scsi_host_get().
626 *
627 * So we take two references here. We release one reference at the
628 * bottom of the function -- after delinking the vport. And we
629 * release the other at the completion of the unreg_vpi that get's
630 * initiated after we've disposed of all other resources associated
631 * with the port.
632 */
James Smartd7c255b2008-08-24 21:50:00 -0400633 if (!scsi_host_get(shost))
James Smart92d7f7b2007-06-17 19:56:38 -0500634 return VPORT_INVAL;
James Smartd7c255b2008-08-24 21:50:00 -0400635 if (!scsi_host_get(shost)) {
636 scsi_host_put(shost);
637 return VPORT_INVAL;
638 }
James Smarteada2722008-12-04 22:39:13 -0500639 lpfc_free_sysfs_attr(vport);
640
James Smart858c9f62007-06-17 19:56:39 -0500641 lpfc_debugfs_terminate(vport);
James Smarteada2722008-12-04 22:39:13 -0500642
James Smart16a3a202013-04-17 20:14:38 -0400643 /*
644 * The call to fc_remove_host might release the NameServer ndlp. Since
645 * we might need to use the ndlp to send the DA_ID CT command,
646 * increment the reference for the NameServer ndlp to prevent it from
647 * being released.
648 */
649 ndlp = lpfc_findnode_did(vport, NameServer_DID);
650 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
651 lpfc_nlp_get(ndlp);
652 ns_ndlp_referenced = true;
653 }
654
James Smarteada2722008-12-04 22:39:13 -0500655 /* Remove FC host and then SCSI host with the vport */
James Smartcc823552015-05-21 13:55:26 -0400656 fc_remove_host(shost);
657 scsi_remove_host(shost);
James Smart92d7f7b2007-06-17 19:56:38 -0500658
659 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500660
661 /* In case of driver unload, we shall not perform fabric logo as the
662 * worker thread already stopped at this stage and, in this case, we
663 * can safely skip the fabric logo.
664 */
665 if (phba->pport->load_flag & FC_UNLOADING) {
666 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
667 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE &&
668 phba->link_state >= LPFC_LINK_UP) {
669 /* First look for the Fabric ndlp */
670 ndlp = lpfc_findnode_did(vport, Fabric_DID);
671 if (!ndlp)
672 goto skip_logo;
673 else if (!NLP_CHK_NODE_ACT(ndlp)) {
674 ndlp = lpfc_enable_node(vport, ndlp,
675 NLP_STE_UNUSED_NODE);
676 if (!ndlp)
677 goto skip_logo;
678 }
679 /* Remove ndlp from vport npld list */
680 lpfc_dequeue_node(vport, ndlp);
681
682 /* Indicate free memory when release */
683 spin_lock_irq(&phba->ndlp_lock);
684 NLP_SET_FREE_REQ(ndlp);
685 spin_unlock_irq(&phba->ndlp_lock);
686 /* Kick off release ndlp when it can be safely done */
687 lpfc_nlp_put(ndlp);
688 }
689 goto skip_logo;
690 }
691
692 /* Otherwise, we will perform fabric logo as needed */
693 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
694 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE &&
James Smart58da1ff2008-04-07 10:15:56 -0400695 phba->link_state >= LPFC_LINK_UP &&
James Smart76a95d72010-11-20 23:11:48 -0500696 phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart7ee5d432007-10-27 13:37:17 -0400697 if (vport->cfg_enable_da_id) {
698 timeout = msecs_to_jiffies(phba->fc_ratov * 2000);
699 if (!lpfc_ns_cmd(vport, SLI_CTNS_DA_ID, 0, 0))
700 while (vport->ct_flags && timeout)
701 timeout = schedule_timeout(timeout);
702 else
703 lpfc_printf_log(vport->phba, KERN_WARNING,
704 LOG_VPORT,
705 "1829 CT command failed to "
James Smarte4e74272009-07-19 10:01:38 -0400706 "delete objects on fabric\n");
James Smart7ee5d432007-10-27 13:37:17 -0400707 }
James Smart92d7f7b2007-06-17 19:56:38 -0500708 /* First look for the Fabric ndlp */
709 ndlp = lpfc_findnode_did(vport, Fabric_DID);
710 if (!ndlp) {
711 /* Cannot find existing Fabric ndlp, allocate one */
712 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
713 if (!ndlp)
714 goto skip_logo;
715 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500716 /* Indicate free memory when release */
717 NLP_SET_FREE_REQ(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500718 } else {
James Smart73d91e52011-10-10 21:32:10 -0400719 if (!NLP_CHK_NODE_ACT(ndlp)) {
James Smarte47c9092008-02-08 18:49:26 -0500720 ndlp = lpfc_enable_node(vport, ndlp,
721 NLP_STE_UNUSED_NODE);
722 if (!ndlp)
723 goto skip_logo;
James Smart73d91e52011-10-10 21:32:10 -0400724 }
James Smarte47c9092008-02-08 18:49:26 -0500725
James Smart73d91e52011-10-10 21:32:10 -0400726 /* Remove ndlp from vport list */
James Smart92d7f7b2007-06-17 19:56:38 -0500727 lpfc_dequeue_node(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -0500728 spin_lock_irq(&phba->ndlp_lock);
729 if (!NLP_CHK_FREE_REQ(ndlp))
730 /* Indicate free memory when release */
731 NLP_SET_FREE_REQ(ndlp);
732 else {
733 /* Skip this if ndlp is already in free mode */
734 spin_unlock_irq(&phba->ndlp_lock);
735 goto skip_logo;
736 }
737 spin_unlock_irq(&phba->ndlp_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500738 }
James Smart73d91e52011-10-10 21:32:10 -0400739
740 /*
741 * If the vpi is not registered, then a valid FDISC doesn't
742 * exist and there is no need for a ELS LOGO. Just cleanup
743 * the ndlp.
744 */
745 if (!(vport->vpi_state & LPFC_VPI_REGISTERED)) {
746 lpfc_nlp_put(ndlp);
James Smart5ffc2662009-11-18 15:39:44 -0500747 goto skip_logo;
James Smart73d91e52011-10-10 21:32:10 -0400748 }
749
James Smart92d7f7b2007-06-17 19:56:38 -0500750 vport->unreg_vpi_cmpl = VPORT_INVAL;
751 timeout = msecs_to_jiffies(phba->fc_ratov * 2000);
752 if (!lpfc_issue_els_npiv_logo(vport, ndlp))
753 while (vport->unreg_vpi_cmpl == VPORT_INVAL && timeout)
754 timeout = schedule_timeout(timeout);
755 }
756
James Smart90160e02008-08-24 21:49:45 -0400757 if (!(phba->pport->load_flag & FC_UNLOADING))
758 lpfc_discovery_wait(vport);
759
James Smart92d7f7b2007-06-17 19:56:38 -0500760skip_logo:
James Smart16a3a202013-04-17 20:14:38 -0400761
762 /*
763 * If the NameServer ndlp has been incremented to allow the DA_ID CT
764 * command to be sent, decrement the ndlp now.
765 */
766 if (ns_ndlp_referenced) {
767 ndlp = lpfc_findnode_did(vport, NameServer_DID);
768 lpfc_nlp_put(ndlp);
769 }
770
James Smart87af33f2007-10-27 13:37:43 -0400771 lpfc_cleanup(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500772 lpfc_sli_host_down(vport);
773
James Smart92d7f7b2007-06-17 19:56:38 -0500774 lpfc_stop_vport_timers(vport);
James Smart87af33f2007-10-27 13:37:43 -0400775
776 if (!(phba->pport->load_flag & FC_UNLOADING)) {
James Smarte47c9092008-02-08 18:49:26 -0500777 lpfc_unreg_all_rpis(vport);
James Smart87af33f2007-10-27 13:37:43 -0400778 lpfc_unreg_default_rpis(vport);
779 /*
780 * Completion of unreg_vpi (lpfc_mbx_cmpl_unreg_vpi)
781 * does the scsi_host_put() to release the vport.
782 */
James Smartcc823552015-05-21 13:55:26 -0400783 if (!(vport->vpi_state & LPFC_VPI_REGISTERED) ||
784 lpfc_mbx_unreg_vpi(vport))
James Smartd7c255b2008-08-24 21:50:00 -0400785 scsi_host_put(shost);
786 } else
787 scsi_host_put(shost);
James Smart92d7f7b2007-06-17 19:56:38 -0500788
789 lpfc_free_vpi(phba, vport->vpi);
790 vport->work_port_events = 0;
791 spin_lock_irq(&phba->hbalock);
792 list_del_init(&vport->listentry);
793 spin_unlock_irq(&phba->hbalock);
James Smarta58cbd52007-08-02 11:09:43 -0400794 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
795 "1828 Vport Deleted.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500796 scsi_host_put(shost);
James Smart51ef4c22007-08-02 11:10:31 -0400797 return VPORT_OK;
James Smart92d7f7b2007-06-17 19:56:38 -0500798}
799
James Smart549e55c2007-08-02 11:09:51 -0400800struct lpfc_vport **
801lpfc_create_vport_work_array(struct lpfc_hba *phba)
802{
803 struct lpfc_vport *port_iterator;
804 struct lpfc_vport **vports;
805 int index = 0;
James Smart21e9a0a2009-05-22 14:53:21 -0400806 vports = kzalloc((phba->max_vports + 1) * sizeof(struct lpfc_vport *),
James Smart549e55c2007-08-02 11:09:51 -0400807 GFP_KERNEL);
808 if (vports == NULL)
809 return NULL;
810 spin_lock_irq(&phba->hbalock);
811 list_for_each_entry(port_iterator, &phba->port_list, listentry) {
James Smartdf9e1b52011-12-13 13:22:17 -0500812 if (port_iterator->load_flag & FC_UNLOADING)
813 continue;
James Smarte8b62012007-08-02 11:10:09 -0400814 if (!scsi_host_get(lpfc_shost_from_vport(port_iterator))) {
James Smartdf9e1b52011-12-13 13:22:17 -0500815 lpfc_printf_vlog(port_iterator, KERN_ERR, LOG_VPORT,
James Smarte8b62012007-08-02 11:10:09 -0400816 "1801 Create vport work array FAILED: "
817 "cannot do scsi_host_get\n");
James Smart549e55c2007-08-02 11:09:51 -0400818 continue;
James Smarte8b62012007-08-02 11:10:09 -0400819 }
James Smart549e55c2007-08-02 11:09:51 -0400820 vports[index++] = port_iterator;
821 }
822 spin_unlock_irq(&phba->hbalock);
823 return vports;
824}
825
826void
James Smart09372822008-01-11 01:52:54 -0500827lpfc_destroy_vport_work_array(struct lpfc_hba *phba, struct lpfc_vport **vports)
James Smart549e55c2007-08-02 11:09:51 -0400828{
829 int i;
830 if (vports == NULL)
831 return;
James Smart98fc5dd2010-06-07 15:24:29 -0400832 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart549e55c2007-08-02 11:09:51 -0400833 scsi_host_put(lpfc_shost_from_vport(vports[i]));
834 kfree(vports);
835}
James Smartea2151b2008-09-07 11:52:10 -0400836
837
838/**
James Smart3621a712009-04-06 18:47:14 -0400839 * lpfc_vport_reset_stat_data - Reset the statistical data for the vport
James Smartea2151b2008-09-07 11:52:10 -0400840 * @vport: Pointer to vport object.
841 *
842 * This function resets the statistical data for the vport. This function
843 * is called with the host_lock held
844 **/
845void
846lpfc_vport_reset_stat_data(struct lpfc_vport *vport)
847{
848 struct lpfc_nodelist *ndlp = NULL, *next_ndlp = NULL;
849
850 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
851 if (!NLP_CHK_NODE_ACT(ndlp))
852 continue;
853 if (ndlp->lat_data)
854 memset(ndlp->lat_data, 0, LPFC_MAX_BUCKET_COUNT *
855 sizeof(struct lpfc_scsicmd_bkt));
856 }
857}
858
859
860/**
James Smart3621a712009-04-06 18:47:14 -0400861 * lpfc_alloc_bucket - Allocate data buffer required for statistical data
James Smartea2151b2008-09-07 11:52:10 -0400862 * @vport: Pointer to vport object.
863 *
864 * This function allocates data buffer required for all the FC
865 * nodes of the vport to collect statistical data.
866 **/
867void
868lpfc_alloc_bucket(struct lpfc_vport *vport)
869{
870 struct lpfc_nodelist *ndlp = NULL, *next_ndlp = NULL;
871
872 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
873 if (!NLP_CHK_NODE_ACT(ndlp))
874 continue;
875
876 kfree(ndlp->lat_data);
877 ndlp->lat_data = NULL;
878
879 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
880 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
881 sizeof(struct lpfc_scsicmd_bkt),
882 GFP_ATOMIC);
883
884 if (!ndlp->lat_data)
885 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
886 "0287 lpfc_alloc_bucket failed to "
887 "allocate statistical data buffer DID "
888 "0x%x\n", ndlp->nlp_DID);
889 }
890 }
891}
892
893/**
James Smart3621a712009-04-06 18:47:14 -0400894 * lpfc_free_bucket - Free data buffer required for statistical data
James Smartea2151b2008-09-07 11:52:10 -0400895 * @vport: Pointer to vport object.
896 *
897 * Th function frees statistical data buffer of all the FC
898 * nodes of the vport.
899 **/
900void
901lpfc_free_bucket(struct lpfc_vport *vport)
902{
903 struct lpfc_nodelist *ndlp = NULL, *next_ndlp = NULL;
904
905 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
906 if (!NLP_CHK_NODE_ACT(ndlp))
907 continue;
908
909 kfree(ndlp->lat_data);
910 ndlp->lat_data = NULL;
911 }
912}