1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <scsi/libfc.h>
25#include <linux/export.h>
26
27
28
29
30
31
32
33struct fc_lport *libfc_vport_create(struct fc_vport *vport, int privsize)
34{
35 struct Scsi_Host *shost = vport_to_shost(vport);
36 struct fc_lport *n_port = shost_priv(shost);
37 struct fc_lport *vn_port;
38
39 vn_port = libfc_host_alloc(shost->hostt, privsize);
40 if (!vn_port)
41 return vn_port;
42
43 vn_port->vport = vport;
44 vport->dd_data = vn_port;
45
46 mutex_lock(&n_port->lp_mutex);
47 list_add_tail(&vn_port->list, &n_port->vports);
48 mutex_unlock(&n_port->lp_mutex);
49
50 return vn_port;
51}
52EXPORT_SYMBOL(libfc_vport_create);
53
54
55
56
57
58
59
60
61struct fc_lport *fc_vport_id_lookup(struct fc_lport *n_port, u32 port_id)
62{
63 struct fc_lport *lport = NULL;
64 struct fc_lport *vn_port;
65
66 if (n_port->port_id == port_id)
67 return n_port;
68
69 if (port_id == FC_FID_FLOGI)
70 return n_port;
71
72 mutex_lock(&n_port->lp_mutex);
73 list_for_each_entry(vn_port, &n_port->vports, list) {
74 if (vn_port->port_id == port_id) {
75 lport = vn_port;
76 break;
77 }
78 }
79 mutex_unlock(&n_port->lp_mutex);
80
81 return lport;
82}
83EXPORT_SYMBOL(fc_vport_id_lookup);
84
85
86
87
88
89
90
91enum libfc_lport_mutex_class {
92 LPORT_MUTEX_NORMAL = 0,
93 LPORT_MUTEX_VN_PORT = 1,
94};
95
96
97
98
99
100
101
102
103static void __fc_vport_setlink(struct fc_lport *n_port,
104 struct fc_lport *vn_port)
105{
106 struct fc_vport *vport = vn_port->vport;
107
108 if (vn_port->state == LPORT_ST_DISABLED)
109 return;
110
111 if (n_port->state == LPORT_ST_READY) {
112 if (n_port->npiv_enabled) {
113 fc_vport_set_state(vport, FC_VPORT_INITIALIZING);
114 __fc_linkup(vn_port);
115 } else {
116 fc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
117 __fc_linkdown(vn_port);
118 }
119 } else {
120 fc_vport_set_state(vport, FC_VPORT_LINKDOWN);
121 __fc_linkdown(vn_port);
122 }
123}
124
125
126
127
128
129void fc_vport_setlink(struct fc_lport *vn_port)
130{
131 struct fc_vport *vport = vn_port->vport;
132 struct Scsi_Host *shost = vport_to_shost(vport);
133 struct fc_lport *n_port = shost_priv(shost);
134
135 mutex_lock(&n_port->lp_mutex);
136 mutex_lock_nested(&vn_port->lp_mutex, LPORT_MUTEX_VN_PORT);
137 __fc_vport_setlink(n_port, vn_port);
138 mutex_unlock(&vn_port->lp_mutex);
139 mutex_unlock(&n_port->lp_mutex);
140}
141EXPORT_SYMBOL(fc_vport_setlink);
142
143
144
145
146
147
148
149void fc_vports_linkchange(struct fc_lport *n_port)
150{
151 struct fc_lport *vn_port;
152
153 list_for_each_entry(vn_port, &n_port->vports, list) {
154 mutex_lock_nested(&vn_port->lp_mutex, LPORT_MUTEX_VN_PORT);
155 __fc_vport_setlink(n_port, vn_port);
156 mutex_unlock(&vn_port->lp_mutex);
157 }
158}
159
160