aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Leech <christopher.leech@intel.com>2009-11-03 14:46:14 -0500
committerJames Bottomley <James.Bottomley@suse.de>2009-12-04 13:00:56 -0500
commit174e1ebffd30a7599b889900089f7acef944cc6b (patch)
tree69b5d4e22f1b997128789eddcd1ec61a33d5903e
parent86221969e20a2f60ce104160dc836a964974673b (diff)
[SCSI] libfc: add some generic NPIV support routines to libfc
Adds a function to create a new VN_Port instances, which share the EM list with the N_Port, VN_Port lookup by fabric ID when responding to a new request (otherwise the exchange lookup from the N_Ports EM list is trusted to return an exchange with a cached lport value for the correct VN_Port), a pointer to a fc_vport structure for VN_Ports, and flags to indicate if an N_Port supports NPIV and if the switch/fabric allows it. Signed-off-by: Chris Leech <christopher.leech@intel.com> Signed-off-by: Robert Love <robert.w.love@intel.com> Signed-off-by: James Bottomley <James.Bottomley@suse.de>
-rw-r--r--drivers/scsi/libfc/Makefile3
-rw-r--r--drivers/scsi/libfc/fc_exch.c29
-rw-r--r--drivers/scsi/libfc/fc_npiv.c86
-rw-r--r--include/scsi/libfc.h20
4 files changed, 137 insertions, 1 deletions
diff --git a/drivers/scsi/libfc/Makefile b/drivers/scsi/libfc/Makefile
index 2be549c1db77..4bb23ac86a5c 100644
--- a/drivers/scsi/libfc/Makefile
+++ b/drivers/scsi/libfc/Makefile
@@ -10,4 +10,5 @@ libfc-objs := \
10 fc_frame.o \ 10 fc_frame.o \
11 fc_lport.o \ 11 fc_lport.o \
12 fc_rport.o \ 12 fc_rport.o \
13 fc_fcp.o 13 fc_fcp.o \
14 fc_npiv.o
diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
index ee6031e24c14..751a485685d9 100644
--- a/drivers/scsi/libfc/fc_exch.c
+++ b/drivers/scsi/libfc/fc_exch.c
@@ -1134,6 +1134,15 @@ static void fc_exch_recv_req(struct fc_lport *lp, struct fc_exch_mgr *mp,
1134 u32 f_ctl; 1134 u32 f_ctl;
1135 enum fc_pf_rjt_reason reject; 1135 enum fc_pf_rjt_reason reject;
1136 1136
1137 /* We can have the wrong fc_lport at this point with NPIV, which is a
1138 * problem now that we know a new exchange needs to be allocated
1139 */
1140 lp = fc_vport_id_lookup(lp, ntoh24(fh->fh_d_id));
1141 if (!lp) {
1142 fc_frame_free(fp);
1143 return;
1144 }
1145
1137 fr_seq(fp) = NULL; 1146 fr_seq(fp) = NULL;
1138 reject = fc_seq_lookup_recip(lp, mp, fp); 1147 reject = fc_seq_lookup_recip(lp, mp, fp);
1139 if (reject == FC_RJT_NONE) { 1148 if (reject == FC_RJT_NONE) {
@@ -1900,6 +1909,26 @@ void fc_exch_mgr_del(struct fc_exch_mgr_anchor *ema)
1900} 1909}
1901EXPORT_SYMBOL(fc_exch_mgr_del); 1910EXPORT_SYMBOL(fc_exch_mgr_del);
1902 1911
1912/**
1913 * fc_exch_mgr_list_clone() - share all exchange manager objects
1914 * @src: source lport to clone exchange managers from
1915 * @dst: new lport that takes references to all the exchange managers
1916 */
1917int fc_exch_mgr_list_clone(struct fc_lport *src, struct fc_lport *dst)
1918{
1919 struct fc_exch_mgr_anchor *ema, *tmp;
1920
1921 list_for_each_entry(ema, &src->ema_list, ema_list) {
1922 if (!fc_exch_mgr_add(dst, ema->mp, ema->match))
1923 goto err;
1924 }
1925 return 0;
1926err:
1927 list_for_each_entry_safe(ema, tmp, &dst->ema_list, ema_list)
1928 fc_exch_mgr_del(ema);
1929 return -ENOMEM;
1930}
1931
1903struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lp, 1932struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lp,
1904 enum fc_class class, 1933 enum fc_class class,
1905 u16 min_xid, u16 max_xid, 1934 u16 min_xid, u16 max_xid,
diff --git a/drivers/scsi/libfc/fc_npiv.c b/drivers/scsi/libfc/fc_npiv.c
new file mode 100644
index 000000000000..39f02c09a8d9
--- /dev/null
+++ b/drivers/scsi/libfc/fc_npiv.c
@@ -0,0 +1,86 @@
1/*
2 * Copyright(c) 2009 Intel Corporation. All rights reserved.
3 *
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.
7 *
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
11 * more details.
12 *
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.
16 *
17 * Maintained at www.Open-FCoE.org
18 */
19
20/*
21 * NPIV VN_Port helper functions for libfc
22 */
23
24#include <scsi/libfc.h>
25
26/**
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
30 */
31
32struct fc_lport *libfc_vport_create(struct fc_vport *vport, int privsize)
33{
34 struct Scsi_Host *shost = vport_to_shost(vport);
35 struct fc_lport *n_port = shost_priv(shost);
36 struct fc_lport *vn_port;
37
38 vn_port = libfc_host_alloc(shost->hostt, privsize);
39 if (!vn_port)
40 goto err_out;
41 if (fc_exch_mgr_list_clone(n_port, vn_port))
42 goto err_put;
43
44 vn_port->vport = vport;
45 vport->dd_data = vn_port;
46
47 mutex_lock(&n_port->lp_mutex);
48 list_add_tail(&vn_port->list, &n_port->vports);
49 mutex_unlock(&n_port->lp_mutex);
50
51 return vn_port;
52
53err_put:
54 scsi_host_put(vn_port->host);
55err_out:
56 return NULL;
57}
58EXPORT_SYMBOL(libfc_vport_create);
59
60/**
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
64 *
65 * Returns: matching lport pointer or NULL if there is no match
66 */
67struct fc_lport *fc_vport_id_lookup(struct fc_lport *n_port, u32 port_id)
68{
69 struct fc_lport *lport = NULL;
70 struct fc_lport *vn_port;
71
72 if (fc_host_port_id(n_port->host) == port_id)
73 return n_port;
74
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) {
78 lport = vn_port;
79 break;
80 }
81 }
82 mutex_unlock(&n_port->lp_mutex);
83
84 return lport;
85}
86
diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
index ed3057b4e78d..2c6d55de8ccd 100644
--- a/include/scsi/libfc.h
+++ b/include/scsi/libfc.h
@@ -640,6 +640,8 @@ struct fc_lport {
640 /* Associations */ 640 /* Associations */
641 struct Scsi_Host *host; 641 struct Scsi_Host *host;
642 struct list_head ema_list; 642 struct list_head ema_list;
643 struct list_head vports; /* child vports if N_Port */
644 struct fc_vport *vport; /* parent vport if VN_Port */
643 struct fc_rport_priv *dns_rp; 645 struct fc_rport_priv *dns_rp;
644 struct fc_rport_priv *ptp_rp; 646 struct fc_rport_priv *ptp_rp;
645 void *scsi_priv; 647 void *scsi_priv;
@@ -664,6 +666,8 @@ struct fc_lport {
664 u32 seq_offload:1; /* seq offload supported */ 666 u32 seq_offload:1; /* seq offload supported */
665 u32 crc_offload:1; /* crc offload supported */ 667 u32 crc_offload:1; /* crc offload supported */
666 u32 lro_enabled:1; /* large receive offload */ 668 u32 lro_enabled:1; /* large receive offload */
669 u32 does_npiv:1; /* supports multiple vports */
670 u32 npiv_enabled:1; /* switch/fabric allows NPIV */
667 u32 mfs; /* max FC payload size */ 671 u32 mfs; /* max FC payload size */
668 unsigned int service_params; 672 unsigned int service_params;
669 unsigned int e_d_tov; 673 unsigned int e_d_tov;
@@ -753,6 +757,7 @@ libfc_host_alloc(struct scsi_host_template *sht, int priv_size)
753 lport = shost_priv(shost); 757 lport = shost_priv(shost);
754 lport->host = shost; 758 lport->host = shost;
755 INIT_LIST_HEAD(&lport->ema_list); 759 INIT_LIST_HEAD(&lport->ema_list);
760 INIT_LIST_HEAD(&lport->vports);
756 return lport; 761 return lport;
757} 762}
758 763
@@ -805,6 +810,15 @@ int fc_lport_reset(struct fc_lport *);
805 */ 810 */
806int fc_set_mfs(struct fc_lport *lp, u32 mfs); 811int fc_set_mfs(struct fc_lport *lp, u32 mfs);
807 812
813/*
814 * Allocate a new lport struct for an NPIV VN_Port
815 */
816struct fc_lport *libfc_vport_create(struct fc_vport *vport, int privsize);
817
818/*
819 * Find an NPIV VN_Port by port ID
820 */
821struct fc_lport *fc_vport_id_lookup(struct fc_lport *n_port, u32 port_id);
808 822
809/* 823/*
810 * REMOTE PORT LAYER 824 * REMOTE PORT LAYER
@@ -912,6 +926,12 @@ struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *lport,
912void fc_exch_mgr_del(struct fc_exch_mgr_anchor *ema); 926void fc_exch_mgr_del(struct fc_exch_mgr_anchor *ema);
913 927
914/* 928/*
929 * Clone an exchange manager list, getting reference holds for each EM.
930 * This is for use with NPIV and sharing the X_ID space between VN_Ports.
931 */
932int fc_exch_mgr_list_clone(struct fc_lport *src, struct fc_lport *dst);
933
934/*
915 * Allocates an Exchange Manager (EM). 935 * Allocates an Exchange Manager (EM).
916 * 936 *
917 * The EM manages exchanges for their allocation and 937 * The EM manages exchanges for their allocation and