2 * Copyright(c) 2009 Intel Corporation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17 * Maintained at www.Open-FCoE.org
21 * NPIV VN_Port helper functions for libfc
24 #include <scsi/libfc.h>
27 * fc_vport_create() - Create a new NPIV vport instance
28 * @vport: fc_vport structure from scsi_transport_fc
29 * @privsize: driver private data size to allocate along with the Scsi_Host
32 struct fc_lport *libfc_vport_create(struct fc_vport *vport, int privsize)
34 struct Scsi_Host *shost = vport_to_shost(vport);
35 struct fc_lport *n_port = shost_priv(shost);
36 struct fc_lport *vn_port;
38 vn_port = libfc_host_alloc(shost->hostt, privsize);
41 if (fc_exch_mgr_list_clone(n_port, vn_port))
44 vn_port->vport = vport;
45 vport->dd_data = vn_port;
47 mutex_lock(&n_port->lp_mutex);
48 list_add_tail(&vn_port->list, &n_port->vports);
49 mutex_unlock(&n_port->lp_mutex);
54 scsi_host_put(vn_port->host);
58 EXPORT_SYMBOL(libfc_vport_create);
61 * fc_vport_id_lookup() - find NPIV lport that matches a given fabric ID
62 * @n_port: Top level N_Port which may have multiple NPIV VN_Ports
63 * @port_id: Fabric ID to find a match for
65 * Returns: matching lport pointer or NULL if there is no match
67 struct fc_lport *fc_vport_id_lookup(struct fc_lport *n_port, u32 port_id)
69 struct fc_lport *lport = NULL;
70 struct fc_lport *vn_port;
72 if (fc_host_port_id(n_port->host) == port_id)
75 mutex_lock(&n_port->lp_mutex);
76 list_for_each_entry(vn_port, &n_port->vports, list) {
77 if (fc_host_port_id(vn_port->host) == port_id) {
82 mutex_unlock(&n_port->lp_mutex);