]>
Commit | Line | Data |
---|---|---|
85b4aa49 | 1 | /* |
af7f85d9 | 2 | * Copyright(c) 2007 - 2009 Intel Corporation. All rights reserved. |
85b4aa49 RL |
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 | #include <linux/module.h> | |
85b4aa49 | 21 | #include <linux/spinlock.h> |
85b4aa49 RL |
22 | #include <linux/netdevice.h> |
23 | #include <linux/etherdevice.h> | |
24 | #include <linux/ethtool.h> | |
25 | #include <linux/if_ether.h> | |
26 | #include <linux/if_vlan.h> | |
85b4aa49 | 27 | #include <linux/crc32.h> |
5a0e3ad6 | 28 | #include <linux/slab.h> |
85b4aa49 RL |
29 | #include <linux/cpu.h> |
30 | #include <linux/fs.h> | |
31 | #include <linux/sysfs.h> | |
32 | #include <linux/ctype.h> | |
2ca32b48 | 33 | #include <linux/workqueue.h> |
6f6c2aa3 | 34 | #include <net/dcbnl.h> |
35 | #include <net/dcbevent.h> | |
85b4aa49 RL |
36 | #include <scsi/scsi_tcq.h> |
37 | #include <scsi/scsicam.h> | |
38 | #include <scsi/scsi_transport.h> | |
39 | #include <scsi/scsi_transport_fc.h> | |
40 | #include <net/rtnetlink.h> | |
41 | ||
42 | #include <scsi/fc/fc_encaps.h> | |
97c8389d | 43 | #include <scsi/fc/fc_fip.h> |
8d55e507 | 44 | #include <scsi/fc/fc_fcoe.h> |
85b4aa49 RL |
45 | |
46 | #include <scsi/libfc.h> | |
47 | #include <scsi/fc_frame.h> | |
48 | #include <scsi/libfcoe.h> | |
85b4aa49 | 49 | |
fdd78027 | 50 | #include "fcoe.h" |
7f349142 | 51 | |
85b4aa49 RL |
52 | MODULE_AUTHOR("Open-FCoE.org"); |
53 | MODULE_DESCRIPTION("FCoE"); | |
9b34ecff | 54 | MODULE_LICENSE("GPL v2"); |
85b4aa49 | 55 | |
05cc7390 | 56 | /* Performance tuning parameters for fcoe */ |
860eca2b | 57 | static unsigned int fcoe_ddp_min = 4096; |
05cc7390 YZ |
58 | module_param_named(ddp_min, fcoe_ddp_min, uint, S_IRUGO | S_IWUSR); |
59 | MODULE_PARM_DESC(ddp_min, "Minimum I/O size in bytes for " \ | |
60 | "Direct Data Placement (DDP)."); | |
61 | ||
7c9c6841 BVA |
62 | unsigned int fcoe_debug_logging; |
63 | module_param_named(debug_logging, fcoe_debug_logging, int, S_IRUGO|S_IWUSR); | |
64 | MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels"); | |
65 | ||
62d57f20 | 66 | static unsigned int fcoe_e_d_tov = 2 * 1000; |
69aabcce HR |
67 | module_param_named(e_d_tov, fcoe_e_d_tov, int, S_IRUGO|S_IWUSR); |
68 | MODULE_PARM_DESC(e_d_tov, "E_D_TOV in ms, default 2000"); | |
69 | ||
62d57f20 | 70 | static unsigned int fcoe_r_a_tov = 2 * 2 * 1000; |
69aabcce HR |
71 | module_param_named(r_a_tov, fcoe_r_a_tov, int, S_IRUGO|S_IWUSR); |
72 | MODULE_PARM_DESC(r_a_tov, "R_A_TOV in ms, default 4000"); | |
73 | ||
7c9c6841 | 74 | static DEFINE_MUTEX(fcoe_config_mutex); |
dfc1d0fe | 75 | |
2ca32b48 TH |
76 | static struct workqueue_struct *fcoe_wq; |
77 | ||
85b4aa49 | 78 | /* fcoe host list */ |
090eb6c4 | 79 | /* must only by accessed under the RTNL mutex */ |
7c9c6841 BVA |
80 | static LIST_HEAD(fcoe_hostlist); |
81 | static DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu); | |
85b4aa49 | 82 | |
dd3fd72e | 83 | /* Function Prototypes */ |
1875f27e | 84 | static int fcoe_reset(struct Scsi_Host *); |
fdd78027 VD |
85 | static int fcoe_xmit(struct fc_lport *, struct fc_frame *); |
86 | static int fcoe_rcv(struct sk_buff *, struct net_device *, | |
87 | struct packet_type *, struct net_device *); | |
1875f27e RL |
88 | static void fcoe_percpu_clean(struct fc_lport *); |
89 | static int fcoe_link_ok(struct fc_lport *); | |
fdd78027 VD |
90 | |
91 | static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *); | |
92 | static int fcoe_hostlist_add(const struct fc_lport *); | |
f9184df3 | 93 | static void fcoe_hostlist_del(const struct fc_lport *); |
fdd78027 | 94 | |
85b4aa49 RL |
95 | static int fcoe_device_notification(struct notifier_block *, ulong, void *); |
96 | static void fcoe_dev_setup(void); | |
97 | static void fcoe_dev_cleanup(void); | |
1875f27e RL |
98 | static struct fcoe_interface |
99 | *fcoe_hostlist_lookup_port(const struct net_device *); | |
100 | ||
101 | static int fcoe_fip_recv(struct sk_buff *, struct net_device *, | |
102 | struct packet_type *, struct net_device *); | |
d242e668 HR |
103 | static int fcoe_fip_vlan_recv(struct sk_buff *, struct net_device *, |
104 | struct packet_type *, struct net_device *); | |
1875f27e RL |
105 | |
106 | static void fcoe_fip_send(struct fcoe_ctlr *, struct sk_buff *); | |
107 | static void fcoe_update_src_mac(struct fc_lport *, u8 *); | |
108 | static u8 *fcoe_get_src_mac(struct fc_lport *); | |
109 | static void fcoe_destroy_work(struct work_struct *); | |
110 | ||
111 | static int fcoe_ddp_setup(struct fc_lport *, u16, struct scatterlist *, | |
112 | unsigned int); | |
113 | static int fcoe_ddp_done(struct fc_lport *, u16); | |
71f89491 YZ |
114 | static int fcoe_ddp_target(struct fc_lport *, u16, struct scatterlist *, |
115 | unsigned int); | |
6f6c2aa3 | 116 | static int fcoe_dcb_app_notification(struct notifier_block *notifier, |
117 | ulong event, void *ptr); | |
1875f27e | 118 | |
78a58246 | 119 | static bool fcoe_match(struct net_device *netdev); |
1917d42d | 120 | static int fcoe_create(struct net_device *netdev, enum fip_mode fip_mode); |
78a58246 YZ |
121 | static int fcoe_destroy(struct net_device *netdev); |
122 | static int fcoe_enable(struct net_device *netdev); | |
123 | static int fcoe_disable(struct net_device *netdev); | |
1875f27e | 124 | |
435c8667 RL |
125 | /* fcoe_syfs control interface handlers */ |
126 | static int fcoe_ctlr_alloc(struct net_device *netdev); | |
127 | static int fcoe_ctlr_enabled(struct fcoe_ctlr_device *cdev); | |
a87dccc7 | 128 | static void fcoe_ctlr_mode(struct fcoe_ctlr_device *ctlr_dev); |
435c8667 | 129 | |
1875f27e RL |
130 | static struct fc_seq *fcoe_elsct_send(struct fc_lport *, |
131 | u32 did, struct fc_frame *, | |
132 | unsigned int op, | |
133 | void (*resp)(struct fc_seq *, | |
134 | struct fc_frame *, | |
135 | void *), | |
136 | void *, u32 timeout); | |
859b7b64 | 137 | static void fcoe_recv_frame(struct sk_buff *skb); |
1875f27e | 138 | |
1875f27e | 139 | /* notification function for packets from net device */ |
85b4aa49 RL |
140 | static struct notifier_block fcoe_notifier = { |
141 | .notifier_call = fcoe_device_notification, | |
142 | }; | |
143 | ||
6f6c2aa3 | 144 | /* notification function for DCB events */ |
145 | static struct notifier_block dcb_notifier = { | |
146 | .notifier_call = fcoe_dcb_app_notification, | |
147 | }; | |
148 | ||
8ca86f84 YZ |
149 | static struct scsi_transport_template *fcoe_nport_scsi_transport; |
150 | static struct scsi_transport_template *fcoe_vport_scsi_transport; | |
7f349142 | 151 | |
1875f27e RL |
152 | static int fcoe_vport_destroy(struct fc_vport *); |
153 | static int fcoe_vport_create(struct fc_vport *, bool disabled); | |
154 | static int fcoe_vport_disable(struct fc_vport *, bool disable); | |
155 | static void fcoe_set_vport_symbolic_name(struct fc_vport *); | |
7d65b0df | 156 | static void fcoe_set_port_id(struct fc_lport *, u32, struct fc_frame *); |
8d55e507 | 157 | static void fcoe_fcf_get_vlan_id(struct fcoe_fcf_device *); |
6f7f74ab | 158 | static void fcoe_vport_remove(struct fc_lport *); |
a87dccc7 | 159 | |
8d55e507 | 160 | static struct fcoe_sysfs_function_template fcoe_sysfs_templ = { |
a87dccc7 | 161 | .set_fcoe_ctlr_mode = fcoe_ctlr_mode, |
435c8667 | 162 | .set_fcoe_ctlr_enabled = fcoe_ctlr_enabled, |
8d55e507 RL |
163 | .get_fcoe_ctlr_link_fail = fcoe_ctlr_get_lesb, |
164 | .get_fcoe_ctlr_vlink_fail = fcoe_ctlr_get_lesb, | |
165 | .get_fcoe_ctlr_miss_fka = fcoe_ctlr_get_lesb, | |
166 | .get_fcoe_ctlr_symb_err = fcoe_ctlr_get_lesb, | |
167 | .get_fcoe_ctlr_err_block = fcoe_ctlr_get_lesb, | |
168 | .get_fcoe_ctlr_fcs_error = fcoe_ctlr_get_lesb, | |
169 | ||
170 | .get_fcoe_fcf_selected = fcoe_fcf_get_selected, | |
171 | .get_fcoe_fcf_vlan_id = fcoe_fcf_get_vlan_id, | |
172 | }; | |
1875f27e RL |
173 | |
174 | static struct libfc_function_template fcoe_libfc_fcn_templ = { | |
175 | .frame_send = fcoe_xmit, | |
176 | .ddp_setup = fcoe_ddp_setup, | |
177 | .ddp_done = fcoe_ddp_done, | |
71f89491 | 178 | .ddp_target = fcoe_ddp_target, |
1875f27e | 179 | .elsct_send = fcoe_elsct_send, |
b84056bf | 180 | .get_lesb = fcoe_get_lesb, |
7d65b0df | 181 | .lport_set_port_id = fcoe_set_port_id, |
1875f27e | 182 | }; |
9a05753b | 183 | |
7c9c6841 | 184 | static struct fc_function_template fcoe_nport_fc_functions = { |
7f349142 VD |
185 | .show_host_node_name = 1, |
186 | .show_host_port_name = 1, | |
187 | .show_host_supported_classes = 1, | |
188 | .show_host_supported_fc4s = 1, | |
189 | .show_host_active_fc4s = 1, | |
190 | .show_host_maxframe_size = 1, | |
9f71af2f NP |
191 | .show_host_serial_number = 1, |
192 | .show_host_manufacturer = 1, | |
193 | .show_host_model = 1, | |
194 | .show_host_model_description = 1, | |
195 | .show_host_hardware_version = 1, | |
196 | .show_host_driver_version = 1, | |
197 | .show_host_firmware_version = 1, | |
198 | .show_host_optionrom_version = 1, | |
7f349142 VD |
199 | |
200 | .show_host_port_id = 1, | |
201 | .show_host_supported_speeds = 1, | |
202 | .get_host_speed = fc_get_host_speed, | |
203 | .show_host_speed = 1, | |
204 | .show_host_port_type = 1, | |
205 | .get_host_port_state = fc_get_host_port_state, | |
206 | .show_host_port_state = 1, | |
207 | .show_host_symbolic_name = 1, | |
208 | ||
209 | .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv), | |
210 | .show_rport_maxframe_size = 1, | |
211 | .show_rport_supported_classes = 1, | |
212 | ||
213 | .show_host_fabric_name = 1, | |
214 | .show_starget_node_name = 1, | |
215 | .show_starget_port_name = 1, | |
216 | .show_starget_port_id = 1, | |
217 | .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, | |
218 | .show_rport_dev_loss_tmo = 1, | |
219 | .get_fc_host_stats = fc_get_host_stats, | |
220 | .issue_fc_host_lip = fcoe_reset, | |
221 | ||
222 | .terminate_rport_io = fc_rport_terminate_io, | |
9a05753b CL |
223 | |
224 | .vport_create = fcoe_vport_create, | |
225 | .vport_delete = fcoe_vport_destroy, | |
226 | .vport_disable = fcoe_vport_disable, | |
dc8596d3 | 227 | .set_vport_symbolic_name = fcoe_set_vport_symbolic_name, |
a51ab396 SM |
228 | |
229 | .bsg_request = fc_lport_bsg_request, | |
7f349142 VD |
230 | }; |
231 | ||
7c9c6841 | 232 | static struct fc_function_template fcoe_vport_fc_functions = { |
e9084bb8 CL |
233 | .show_host_node_name = 1, |
234 | .show_host_port_name = 1, | |
235 | .show_host_supported_classes = 1, | |
236 | .show_host_supported_fc4s = 1, | |
237 | .show_host_active_fc4s = 1, | |
238 | .show_host_maxframe_size = 1, | |
7e5adcfb NP |
239 | .show_host_serial_number = 1, |
240 | .show_host_manufacturer = 1, | |
241 | .show_host_model = 1, | |
242 | .show_host_model_description = 1, | |
243 | .show_host_hardware_version = 1, | |
244 | .show_host_driver_version = 1, | |
245 | .show_host_firmware_version = 1, | |
246 | .show_host_optionrom_version = 1, | |
e9084bb8 CL |
247 | |
248 | .show_host_port_id = 1, | |
249 | .show_host_supported_speeds = 1, | |
250 | .get_host_speed = fc_get_host_speed, | |
251 | .show_host_speed = 1, | |
252 | .show_host_port_type = 1, | |
253 | .get_host_port_state = fc_get_host_port_state, | |
254 | .show_host_port_state = 1, | |
255 | .show_host_symbolic_name = 1, | |
256 | ||
257 | .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv), | |
258 | .show_rport_maxframe_size = 1, | |
259 | .show_rport_supported_classes = 1, | |
260 | ||
261 | .show_host_fabric_name = 1, | |
262 | .show_starget_node_name = 1, | |
263 | .show_starget_port_name = 1, | |
264 | .show_starget_port_id = 1, | |
265 | .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, | |
266 | .show_rport_dev_loss_tmo = 1, | |
267 | .get_fc_host_stats = fc_get_host_stats, | |
268 | .issue_fc_host_lip = fcoe_reset, | |
269 | ||
270 | .terminate_rport_io = fc_rport_terminate_io, | |
a51ab396 SM |
271 | |
272 | .bsg_request = fc_lport_bsg_request, | |
e9084bb8 CL |
273 | }; |
274 | ||
7f349142 VD |
275 | static struct scsi_host_template fcoe_shost_template = { |
276 | .module = THIS_MODULE, | |
277 | .name = "FCoE Driver", | |
278 | .proc_name = FCOE_NAME, | |
279 | .queuecommand = fc_queuecommand, | |
b6a05c82 | 280 | .eh_timed_out = fc_eh_timed_out, |
7f349142 VD |
281 | .eh_abort_handler = fc_eh_abort, |
282 | .eh_device_reset_handler = fc_eh_device_reset, | |
283 | .eh_host_reset_handler = fc_eh_host_reset, | |
284 | .slave_alloc = fc_slave_alloc, | |
db5ed4df | 285 | .change_queue_depth = scsi_change_queue_depth, |
7f349142 | 286 | .this_id = -1, |
14caf44c | 287 | .cmd_per_lun = 3, |
7f349142 VD |
288 | .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS, |
289 | .use_clustering = ENABLE_CLUSTERING, | |
290 | .sg_tablesize = SG_ALL, | |
291 | .max_sectors = 0xffff, | |
c40ecc12 | 292 | .track_queue_depth = 1, |
7f349142 VD |
293 | }; |
294 | ||
54b649f8 | 295 | /** |
1875f27e RL |
296 | * fcoe_interface_setup() - Setup a FCoE interface |
297 | * @fcoe: The new FCoE interface | |
298 | * @netdev: The net device that the fcoe interface is on | |
54b649f8 CL |
299 | * |
300 | * Returns : 0 for success | |
2e70e241 | 301 | * Locking: must be called with the RTNL mutex held |
54b649f8 CL |
302 | */ |
303 | static int fcoe_interface_setup(struct fcoe_interface *fcoe, | |
304 | struct net_device *netdev) | |
305 | { | |
619fe4be | 306 | struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe); |
54b649f8 | 307 | struct netdev_hw_addr *ha; |
5bab87e6 | 308 | struct net_device *real_dev; |
54b649f8 | 309 | u8 flogi_maddr[ETH_ALEN]; |
b7a727f1 | 310 | const struct net_device_ops *ops; |
54b649f8 CL |
311 | |
312 | fcoe->netdev = netdev; | |
313 | ||
b7a727f1 YZ |
314 | /* Let LLD initialize for FCoE */ |
315 | ops = netdev->netdev_ops; | |
316 | if (ops->ndo_fcoe_enable) { | |
317 | if (ops->ndo_fcoe_enable(netdev)) | |
318 | FCOE_NETDEV_DBG(netdev, "Failed to enable FCoE" | |
319 | " specific feature for LLD.\n"); | |
320 | } | |
321 | ||
54b649f8 | 322 | /* Do not support for bonding device */ |
cc8bdf06 | 323 | if (netdev->priv_flags & IFF_BONDING && netdev->flags & IFF_MASTER) { |
59d92516 | 324 | FCOE_NETDEV_DBG(netdev, "Bonded interfaces not supported\n"); |
54b649f8 CL |
325 | return -EOPNOTSUPP; |
326 | } | |
327 | ||
328 | /* look for SAN MAC address, if multiple SAN MACs exist, only | |
329 | * use the first one for SPMA */ | |
d0d7b10b | 330 | real_dev = is_vlan_dev(netdev) ? vlan_dev_real_dev(netdev) : netdev; |
d1483bb9 | 331 | fcoe->realdev = real_dev; |
54b649f8 | 332 | rcu_read_lock(); |
5bab87e6 | 333 | for_each_dev_addr(real_dev, ha) { |
54b649f8 | 334 | if ((ha->type == NETDEV_HW_ADDR_T_SAN) && |
bf361707 | 335 | (is_valid_ether_addr(ha->addr))) { |
54b649f8 CL |
336 | memcpy(fip->ctl_src_addr, ha->addr, ETH_ALEN); |
337 | fip->spma = 1; | |
338 | break; | |
339 | } | |
340 | } | |
341 | rcu_read_unlock(); | |
342 | ||
343 | /* setup Source Mac Address */ | |
344 | if (!fip->spma) | |
345 | memcpy(fip->ctl_src_addr, netdev->dev_addr, netdev->addr_len); | |
346 | ||
347 | /* | |
348 | * Add FCoE MAC address as second unicast MAC address | |
349 | * or enter promiscuous mode if not capable of listening | |
350 | * for multiple unicast MACs. | |
351 | */ | |
54b649f8 | 352 | memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN); |
a748ee24 | 353 | dev_uc_add(netdev, flogi_maddr); |
54b649f8 | 354 | if (fip->spma) |
a748ee24 | 355 | dev_uc_add(netdev, fip->ctl_src_addr); |
e10f8c66 JE |
356 | if (fip->mode == FIP_MODE_VN2VN) { |
357 | dev_mc_add(netdev, FIP_ALL_VN2VN_MACS); | |
358 | dev_mc_add(netdev, FIP_ALL_P2P_MACS); | |
359 | } else | |
360 | dev_mc_add(netdev, FIP_ALL_ENODE_MACS); | |
54b649f8 CL |
361 | |
362 | /* | |
363 | * setup the receive function from ethernet driver | |
364 | * on the ethertype for the given device | |
365 | */ | |
366 | fcoe->fcoe_packet_type.func = fcoe_rcv; | |
420fa211 | 367 | fcoe->fcoe_packet_type.type = htons(ETH_P_FCOE); |
54b649f8 CL |
368 | fcoe->fcoe_packet_type.dev = netdev; |
369 | dev_add_pack(&fcoe->fcoe_packet_type); | |
370 | ||
371 | fcoe->fip_packet_type.func = fcoe_fip_recv; | |
372 | fcoe->fip_packet_type.type = htons(ETH_P_FIP); | |
373 | fcoe->fip_packet_type.dev = netdev; | |
374 | dev_add_pack(&fcoe->fip_packet_type); | |
375 | ||
d242e668 HR |
376 | if (netdev != real_dev) { |
377 | fcoe->fip_vlan_packet_type.func = fcoe_fip_vlan_recv; | |
378 | fcoe->fip_vlan_packet_type.type = htons(ETH_P_FIP); | |
379 | fcoe->fip_vlan_packet_type.dev = real_dev; | |
380 | dev_add_pack(&fcoe->fip_vlan_packet_type); | |
381 | } | |
54b649f8 CL |
382 | return 0; |
383 | } | |
384 | ||
030f4e00 | 385 | /** |
1875f27e RL |
386 | * fcoe_interface_create() - Create a FCoE interface on a net device |
387 | * @netdev: The net device to create the FCoE interface on | |
1dd454d9 | 388 | * @fip_mode: The mode to use for FIP |
030f4e00 CL |
389 | * |
390 | * Returns: pointer to a struct fcoe_interface or NULL on error | |
391 | */ | |
1dd454d9 | 392 | static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev, |
49b1b8ad | 393 | enum fip_mode fip_mode) |
030f4e00 | 394 | { |
8d55e507 | 395 | struct fcoe_ctlr_device *ctlr_dev; |
619fe4be | 396 | struct fcoe_ctlr *ctlr; |
030f4e00 | 397 | struct fcoe_interface *fcoe; |
619fe4be | 398 | int size; |
59d92516 | 399 | int err; |
030f4e00 | 400 | |
7287fb91 RL |
401 | if (!try_module_get(THIS_MODULE)) { |
402 | FCOE_NETDEV_DBG(netdev, | |
403 | "Could not get a reference to the module\n"); | |
404 | fcoe = ERR_PTR(-EBUSY); | |
405 | goto out; | |
406 | } | |
407 | ||
619fe4be | 408 | size = sizeof(struct fcoe_ctlr) + sizeof(struct fcoe_interface); |
8d55e507 RL |
409 | ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &fcoe_sysfs_templ, |
410 | size); | |
411 | if (!ctlr_dev) { | |
412 | FCOE_DBG("Failed to add fcoe_ctlr_device\n"); | |
7287fb91 | 413 | fcoe = ERR_PTR(-ENOMEM); |
6f68794c | 414 | goto out_putmod; |
030f4e00 CL |
415 | } |
416 | ||
8d55e507 | 417 | ctlr = fcoe_ctlr_device_priv(ctlr_dev); |
9d34876f | 418 | ctlr->cdev = ctlr_dev; |
8d55e507 RL |
419 | fcoe = fcoe_ctlr_priv(ctlr); |
420 | ||
2e70e241 | 421 | dev_hold(netdev); |
54b649f8 CL |
422 | |
423 | /* | |
424 | * Initialize FIP. | |
425 | */ | |
619fe4be RL |
426 | fcoe_ctlr_init(ctlr, fip_mode); |
427 | ctlr->send = fcoe_fip_send; | |
428 | ctlr->update_mac = fcoe_update_src_mac; | |
429 | ctlr->get_src_addr = fcoe_get_src_mac; | |
54b649f8 | 430 | |
59d92516 | 431 | err = fcoe_interface_setup(fcoe, netdev); |
432 | if (err) { | |
619fe4be | 433 | fcoe_ctlr_destroy(ctlr); |
8d55e507 | 434 | fcoe_ctlr_device_delete(ctlr_dev); |
59d92516 | 435 | dev_put(netdev); |
7287fb91 | 436 | fcoe = ERR_PTR(err); |
6f68794c | 437 | goto out_putmod; |
59d92516 | 438 | } |
030f4e00 | 439 | |
7287fb91 RL |
440 | goto out; |
441 | ||
6f68794c | 442 | out_putmod: |
7287fb91 RL |
443 | module_put(THIS_MODULE); |
444 | out: | |
030f4e00 CL |
445 | return fcoe; |
446 | } | |
447 | ||
54b649f8 | 448 | /** |
433eba04 | 449 | * fcoe_interface_remove() - remove FCoE interface from netdev |
1875f27e | 450 | * @fcoe: The FCoE interface to be cleaned up |
2e70e241 CL |
451 | * |
452 | * Caller must be holding the RTNL mutex | |
54b649f8 | 453 | */ |
433eba04 | 454 | static void fcoe_interface_remove(struct fcoe_interface *fcoe) |
54b649f8 CL |
455 | { |
456 | struct net_device *netdev = fcoe->netdev; | |
619fe4be | 457 | struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe); |
54b649f8 | 458 | u8 flogi_maddr[ETH_ALEN]; |
b7a727f1 | 459 | const struct net_device_ops *ops; |
54b649f8 CL |
460 | |
461 | /* | |
462 | * Don't listen for Ethernet packets anymore. | |
463 | * synchronize_net() ensures that the packet handlers are not running | |
464 | * on another CPU. dev_remove_pack() would do that, this calls the | |
465 | * unsyncronized version __dev_remove_pack() to avoid multiple delays. | |
466 | */ | |
467 | __dev_remove_pack(&fcoe->fcoe_packet_type); | |
468 | __dev_remove_pack(&fcoe->fip_packet_type); | |
d242e668 HR |
469 | if (netdev != fcoe->realdev) |
470 | __dev_remove_pack(&fcoe->fip_vlan_packet_type); | |
54b649f8 CL |
471 | synchronize_net(); |
472 | ||
54b649f8 | 473 | /* Delete secondary MAC addresses */ |
54b649f8 | 474 | memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN); |
a748ee24 | 475 | dev_uc_del(netdev, flogi_maddr); |
54b649f8 | 476 | if (fip->spma) |
a748ee24 | 477 | dev_uc_del(netdev, fip->ctl_src_addr); |
e10f8c66 JE |
478 | if (fip->mode == FIP_MODE_VN2VN) { |
479 | dev_mc_del(netdev, FIP_ALL_VN2VN_MACS); | |
480 | dev_mc_del(netdev, FIP_ALL_P2P_MACS); | |
481 | } else | |
482 | dev_mc_del(netdev, FIP_ALL_ENODE_MACS); | |
b7a727f1 YZ |
483 | |
484 | /* Tell the LLD we are done w/ FCoE */ | |
485 | ops = netdev->netdev_ops; | |
486 | if (ops->ndo_fcoe_disable) { | |
487 | if (ops->ndo_fcoe_disable(netdev)) | |
488 | FCOE_NETDEV_DBG(netdev, "Failed to disable FCoE" | |
489 | " specific feature for LLD.\n"); | |
490 | } | |
433eba04 VD |
491 | fcoe->removed = 1; |
492 | } | |
493 | ||
494 | ||
495 | /** | |
496 | * fcoe_interface_cleanup() - Clean up a FCoE interface | |
497 | * @fcoe: The FCoE interface to be cleaned up | |
498 | */ | |
499 | static void fcoe_interface_cleanup(struct fcoe_interface *fcoe) | |
500 | { | |
501 | struct net_device *netdev = fcoe->netdev; | |
619fe4be | 502 | struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe); |
b2085a4e NP |
503 | |
504 | /* Release the self-reference taken during fcoe_interface_create() */ | |
1a8ef414 RL |
505 | /* tear-down the FCoE controller */ |
506 | fcoe_ctlr_destroy(fip); | |
619fe4be | 507 | scsi_host_put(fip->lp->host); |
1a8ef414 RL |
508 | dev_put(netdev); |
509 | module_put(THIS_MODULE); | |
030f4e00 CL |
510 | } |
511 | ||
ab6b85c1 | 512 | /** |
1875f27e RL |
513 | * fcoe_fip_recv() - Handler for received FIP frames |
514 | * @skb: The receive skb | |
515 | * @netdev: The associated net device | |
516 | * @ptype: The packet_type structure which was used to register this handler | |
78cfe97f | 517 | * @orig_dev: The original net_device the skb was received on. |
1875f27e | 518 | * (in case dev is a bond) |
ab6b85c1 VD |
519 | * |
520 | * Returns: 0 for success | |
521 | */ | |
1875f27e | 522 | static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *netdev, |
ab6b85c1 VD |
523 | struct packet_type *ptype, |
524 | struct net_device *orig_dev) | |
525 | { | |
259ad85d | 526 | struct fcoe_interface *fcoe; |
619fe4be | 527 | struct fcoe_ctlr *ctlr; |
ab6b85c1 | 528 | |
259ad85d | 529 | fcoe = container_of(ptype, struct fcoe_interface, fip_packet_type); |
619fe4be RL |
530 | ctlr = fcoe_to_ctlr(fcoe); |
531 | fcoe_ctlr_recv(ctlr, skb); | |
ab6b85c1 VD |
532 | return 0; |
533 | } | |
534 | ||
d242e668 HR |
535 | /** |
536 | * fcoe_fip_vlan_recv() - Handler for received FIP VLAN discovery frames | |
537 | * @skb: The receive skb | |
538 | * @netdev: The associated net device | |
539 | * @ptype: The packet_type structure which was used to register this handler | |
78cfe97f | 540 | * @orig_dev: The original net_device the skb was received on. |
d242e668 HR |
541 | * (in case dev is a bond) |
542 | * | |
543 | * Returns: 0 for success | |
544 | */ | |
545 | static int fcoe_fip_vlan_recv(struct sk_buff *skb, struct net_device *netdev, | |
546 | struct packet_type *ptype, | |
547 | struct net_device *orig_dev) | |
548 | { | |
549 | struct fcoe_interface *fcoe; | |
550 | struct fcoe_ctlr *ctlr; | |
551 | ||
552 | fcoe = container_of(ptype, struct fcoe_interface, fip_vlan_packet_type); | |
553 | ctlr = fcoe_to_ctlr(fcoe); | |
554 | fcoe_ctlr_recv(ctlr, skb); | |
555 | return 0; | |
556 | } | |
557 | ||
980f5156 VD |
558 | /** |
559 | * fcoe_port_send() - Send an Ethernet-encapsulated FIP/FCoE frame | |
560 | * @port: The FCoE port | |
561 | * @skb: The FIP/FCoE packet to be sent | |
562 | */ | |
563 | static void fcoe_port_send(struct fcoe_port *port, struct sk_buff *skb) | |
564 | { | |
565 | if (port->fcoe_pending_queue.qlen) | |
566 | fcoe_check_wait_queue(port->lport, skb); | |
567 | else if (fcoe_start_io(skb)) | |
568 | fcoe_check_wait_queue(port->lport, skb); | |
569 | } | |
570 | ||
ab6b85c1 | 571 | /** |
1875f27e RL |
572 | * fcoe_fip_send() - Send an Ethernet-encapsulated FIP frame |
573 | * @fip: The FCoE controller | |
574 | * @skb: The FIP packet to be sent | |
ab6b85c1 VD |
575 | */ |
576 | static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb) | |
577 | { | |
d242e668 HR |
578 | struct fcoe_interface *fcoe = fcoe_from_ctlr(fip); |
579 | struct fip_frame { | |
580 | struct ethhdr eth; | |
581 | struct fip_header fip; | |
582 | } __packed *frame; | |
583 | ||
584 | /* | |
585 | * Use default VLAN for FIP VLAN discovery protocol | |
586 | */ | |
587 | frame = (struct fip_frame *)skb->data; | |
f7e6ed06 HR |
588 | if (ntohs(frame->eth.h_proto) == ETH_P_FIP && |
589 | ntohs(frame->fip.fip_op) == FIP_OP_VLAN && | |
d242e668 HR |
590 | fcoe->realdev != fcoe->netdev) |
591 | skb->dev = fcoe->realdev; | |
592 | else | |
593 | skb->dev = fcoe->netdev; | |
980f5156 | 594 | fcoe_port_send(lport_priv(fip->lp), skb); |
ab6b85c1 VD |
595 | } |
596 | ||
597 | /** | |
1875f27e RL |
598 | * fcoe_update_src_mac() - Update the Ethernet MAC filters |
599 | * @lport: The local port to update the source MAC on | |
600 | * @addr: Unicast MAC address to add | |
ab6b85c1 VD |
601 | * |
602 | * Remove any previously-set unicast MAC filter. | |
603 | * Add secondary FCoE MAC address filter for our OUI. | |
604 | */ | |
11b56188 | 605 | static void fcoe_update_src_mac(struct fc_lport *lport, u8 *addr) |
ab6b85c1 | 606 | { |
11b56188 | 607 | struct fcoe_port *port = lport_priv(lport); |
8597ae8b | 608 | struct fcoe_interface *fcoe = port->priv; |
25024989 | 609 | |
11b56188 | 610 | if (!is_zero_ether_addr(port->data_src_addr)) |
a748ee24 | 611 | dev_uc_del(fcoe->netdev, port->data_src_addr); |
11b56188 | 612 | if (!is_zero_ether_addr(addr)) |
a748ee24 | 613 | dev_uc_add(fcoe->netdev, addr); |
11b56188 | 614 | memcpy(port->data_src_addr, addr, ETH_ALEN); |
ab6b85c1 VD |
615 | } |
616 | ||
11b56188 CL |
617 | /** |
618 | * fcoe_get_src_mac() - return the Ethernet source address for an lport | |
619 | * @lport: libfc lport | |
620 | */ | |
621 | static u8 *fcoe_get_src_mac(struct fc_lport *lport) | |
622 | { | |
623 | struct fcoe_port *port = lport_priv(lport); | |
624 | ||
625 | return port->data_src_addr; | |
626 | } | |
627 | ||
7f349142 | 628 | /** |
1875f27e RL |
629 | * fcoe_lport_config() - Set up a local port |
630 | * @lport: The local port to be setup | |
7f349142 VD |
631 | * |
632 | * Returns: 0 for success | |
633 | */ | |
1875f27e | 634 | static int fcoe_lport_config(struct fc_lport *lport) |
7f349142 | 635 | { |
1875f27e RL |
636 | lport->link_up = 0; |
637 | lport->qfull = 0; | |
638 | lport->max_retry_count = 3; | |
639 | lport->max_rport_retry_count = 3; | |
69aabcce HR |
640 | lport->e_d_tov = fcoe_e_d_tov; |
641 | lport->r_a_tov = fcoe_r_a_tov; | |
1875f27e RL |
642 | lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS | |
643 | FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL); | |
644 | lport->does_npiv = 1; | |
645 | ||
646 | fc_lport_init_stats(lport); | |
7f349142 VD |
647 | |
648 | /* lport fc_lport related configuration */ | |
1875f27e | 649 | fc_lport_config(lport); |
7f349142 VD |
650 | |
651 | /* offload related configuration */ | |
1875f27e RL |
652 | lport->crc_offload = 0; |
653 | lport->seq_offload = 0; | |
654 | lport->lro_enabled = 0; | |
655 | lport->lro_xid = 0; | |
656 | lport->lso_max = 0; | |
7f349142 VD |
657 | |
658 | return 0; | |
659 | } | |
660 | ||
54a5b21d YZ |
661 | /** |
662 | * fcoe_netdev_features_change - Updates the lport's offload flags based | |
663 | * on the LLD netdev's FCoE feature flags | |
664 | */ | |
665 | static void fcoe_netdev_features_change(struct fc_lport *lport, | |
666 | struct net_device *netdev) | |
667 | { | |
668 | mutex_lock(&lport->lp_mutex); | |
669 | ||
670 | if (netdev->features & NETIF_F_SG) | |
671 | lport->sg_supp = 1; | |
672 | else | |
673 | lport->sg_supp = 0; | |
674 | ||
675 | if (netdev->features & NETIF_F_FCOE_CRC) { | |
676 | lport->crc_offload = 1; | |
677 | FCOE_NETDEV_DBG(netdev, "Supports FCCRC offload\n"); | |
678 | } else { | |
679 | lport->crc_offload = 0; | |
680 | } | |
681 | ||
682 | if (netdev->features & NETIF_F_FSO) { | |
683 | lport->seq_offload = 1; | |
684 | lport->lso_max = netdev->gso_max_size; | |
685 | FCOE_NETDEV_DBG(netdev, "Supports LSO for max len 0x%x\n", | |
686 | lport->lso_max); | |
687 | } else { | |
688 | lport->seq_offload = 0; | |
689 | lport->lso_max = 0; | |
690 | } | |
691 | ||
692 | if (netdev->fcoe_ddp_xid) { | |
693 | lport->lro_enabled = 1; | |
694 | lport->lro_xid = netdev->fcoe_ddp_xid; | |
695 | FCOE_NETDEV_DBG(netdev, "Supports LRO for max xid 0x%x\n", | |
696 | lport->lro_xid); | |
697 | } else { | |
698 | lport->lro_enabled = 0; | |
699 | lport->lro_xid = 0; | |
700 | } | |
701 | ||
702 | mutex_unlock(&lport->lp_mutex); | |
703 | } | |
704 | ||
7f349142 | 705 | /** |
1875f27e RL |
706 | * fcoe_netdev_config() - Set up net devive for SW FCoE |
707 | * @lport: The local port that is associated with the net device | |
708 | * @netdev: The associated net device | |
7f349142 | 709 | * |
1875f27e | 710 | * Must be called after fcoe_lport_config() as it will use local port mutex |
7f349142 | 711 | * |
1875f27e | 712 | * Returns: 0 for success |
7f349142 | 713 | */ |
1875f27e | 714 | static int fcoe_netdev_config(struct fc_lport *lport, struct net_device *netdev) |
7f349142 VD |
715 | { |
716 | u32 mfs; | |
717 | u64 wwnn, wwpn; | |
25024989 | 718 | struct fcoe_interface *fcoe; |
619fe4be | 719 | struct fcoe_ctlr *ctlr; |
014f5c3f | 720 | struct fcoe_port *port; |
7f349142 VD |
721 | |
722 | /* Setup lport private data to point to fcoe softc */ | |
1875f27e | 723 | port = lport_priv(lport); |
8597ae8b | 724 | fcoe = port->priv; |
619fe4be | 725 | ctlr = fcoe_to_ctlr(fcoe); |
7f349142 | 726 | |
9a6cf881 | 727 | /* Figure out the VLAN ID, if any */ |
d0d7b10b | 728 | if (is_vlan_dev(netdev)) |
9a6cf881 HR |
729 | lport->vlan = vlan_dev_vlan_id(netdev); |
730 | else | |
731 | lport->vlan = 0; | |
732 | ||
7f349142 VD |
733 | /* |
734 | * Determine max frame size based on underlying device and optional | |
735 | * user-configured limit. If the MFS is too low, fcoe_link_ok() | |
736 | * will return 0, so do this first. | |
737 | */ | |
7221d7e5 YZ |
738 | mfs = netdev->mtu; |
739 | if (netdev->features & NETIF_F_FCOE_MTU) { | |
740 | mfs = FCOE_MTU; | |
741 | FCOE_NETDEV_DBG(netdev, "Supports FCOE_MTU of %d bytes\n", mfs); | |
742 | } | |
743 | mfs -= (sizeof(struct fcoe_hdr) + sizeof(struct fcoe_crc_eof)); | |
1875f27e | 744 | if (fc_set_mfs(lport, mfs)) |
7f349142 VD |
745 | return -EINVAL; |
746 | ||
7f349142 | 747 | /* offload features support */ |
54a5b21d | 748 | fcoe_netdev_features_change(lport, netdev); |
7f349142 | 749 | |
014f5c3f CL |
750 | skb_queue_head_init(&port->fcoe_pending_queue); |
751 | port->fcoe_pending_queue_active = 0; | |
13059106 | 752 | timer_setup(&port->timer, fcoe_queue_timer, 0); |
7f349142 | 753 | |
5e4f8fe7 RL |
754 | fcoe_link_speed_update(lport); |
755 | ||
1875f27e | 756 | if (!lport->vport) { |
dcece412 | 757 | if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN)) |
619fe4be | 758 | wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr, 1, 0); |
1875f27e | 759 | fc_set_wwnn(lport, wwnn); |
dcece412 | 760 | if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN)) |
619fe4be | 761 | wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr, |
cf4aebca | 762 | 2, 0); |
1875f27e | 763 | fc_set_wwpn(lport, wwpn); |
9a05753b | 764 | } |
7f349142 | 765 | |
7f349142 VD |
766 | return 0; |
767 | } | |
768 | ||
769 | /** | |
1875f27e RL |
770 | * fcoe_shost_config() - Set up the SCSI host associated with a local port |
771 | * @lport: The local port | |
1875f27e | 772 | * @dev: The device associated with the SCSI host |
7f349142 VD |
773 | * |
774 | * Must be called after fcoe_lport_config() and fcoe_netdev_config() | |
775 | * | |
1875f27e | 776 | * Returns: 0 for success |
7f349142 | 777 | */ |
8ba00a4b | 778 | static int fcoe_shost_config(struct fc_lport *lport, struct device *dev) |
7f349142 VD |
779 | { |
780 | int rc = 0; | |
781 | ||
782 | /* lport scsi host config */ | |
1875f27e RL |
783 | lport->host->max_lun = FCOE_MAX_LUN; |
784 | lport->host->max_id = FCOE_MAX_FCP_TARGET; | |
785 | lport->host->max_channel = 0; | |
da87bfab VD |
786 | lport->host->max_cmd_len = FCOE_MAX_CMD_LEN; |
787 | ||
1875f27e | 788 | if (lport->vport) |
8ca86f84 | 789 | lport->host->transportt = fcoe_vport_scsi_transport; |
e9084bb8 | 790 | else |
8ca86f84 | 791 | lport->host->transportt = fcoe_nport_scsi_transport; |
7f349142 VD |
792 | |
793 | /* add the new host to the SCSI-ml */ | |
1875f27e | 794 | rc = scsi_add_host(lport->host, dev); |
7f349142 | 795 | if (rc) { |
1875f27e | 796 | FCOE_NETDEV_DBG(fcoe_netdev(lport), "fcoe_shost_config: " |
d5488eb9 | 797 | "error on scsi_add_host\n"); |
7f349142 VD |
798 | return rc; |
799 | } | |
9a05753b | 800 | |
1875f27e | 801 | if (!lport->vport) |
4be929be | 802 | fc_host_max_npiv_vports(lport->host) = USHRT_MAX; |
9a05753b | 803 | |
1875f27e | 804 | snprintf(fc_host_symbolic_name(lport->host), FC_SYMBOLIC_NAME_SIZE, |
5baa17c3 | 805 | "%s v%s over %s", FCOE_NAME, FCOE_VERSION, |
1875f27e | 806 | fcoe_netdev(lport)->name); |
7f349142 VD |
807 | |
808 | return 0; | |
809 | } | |
810 | ||
6fef3902 NP |
811 | |
812 | /** | |
813 | * fcoe_fdmi_info() - Get FDMI related info from net devive for SW FCoE | |
814 | * @lport: The local port that is associated with the net device | |
815 | * @netdev: The associated net device | |
816 | * | |
817 | * Must be called after fcoe_shost_config() as it will use local port mutex | |
818 | * | |
819 | */ | |
820 | static void fcoe_fdmi_info(struct fc_lport *lport, struct net_device *netdev) | |
821 | { | |
822 | struct fcoe_interface *fcoe; | |
823 | struct fcoe_port *port; | |
824 | struct net_device *realdev; | |
825 | int rc; | |
6fef3902 NP |
826 | |
827 | port = lport_priv(lport); | |
828 | fcoe = port->priv; | |
829 | realdev = fcoe->realdev; | |
830 | ||
6fef3902 NP |
831 | /* No FDMI state m/c for NPIV ports */ |
832 | if (lport->vport) | |
833 | return; | |
834 | ||
835 | if (realdev->netdev_ops->ndo_fcoe_get_hbainfo) { | |
f07d46bb NP |
836 | struct netdev_fcoe_hbainfo *fdmi; |
837 | fdmi = kzalloc(sizeof(*fdmi), GFP_KERNEL); | |
838 | if (!fdmi) | |
839 | return; | |
840 | ||
6fef3902 | 841 | rc = realdev->netdev_ops->ndo_fcoe_get_hbainfo(realdev, |
f07d46bb | 842 | fdmi); |
6fef3902 NP |
843 | if (rc) { |
844 | printk(KERN_INFO "fcoe: Failed to retrieve FDMI " | |
845 | "information from netdev.\n"); | |
846 | return; | |
847 | } | |
848 | ||
849 | snprintf(fc_host_serial_number(lport->host), | |
850 | FC_SERIAL_NUMBER_SIZE, | |
851 | "%s", | |
f07d46bb | 852 | fdmi->serial_number); |
6fef3902 NP |
853 | snprintf(fc_host_manufacturer(lport->host), |
854 | FC_SERIAL_NUMBER_SIZE, | |
855 | "%s", | |
f07d46bb | 856 | fdmi->manufacturer); |
6fef3902 NP |
857 | snprintf(fc_host_model(lport->host), |
858 | FC_SYMBOLIC_NAME_SIZE, | |
859 | "%s", | |
f07d46bb | 860 | fdmi->model); |
6fef3902 NP |
861 | snprintf(fc_host_model_description(lport->host), |
862 | FC_SYMBOLIC_NAME_SIZE, | |
863 | "%s", | |
f07d46bb | 864 | fdmi->model_description); |
6fef3902 NP |
865 | snprintf(fc_host_hardware_version(lport->host), |
866 | FC_VERSION_STRING_SIZE, | |
867 | "%s", | |
f07d46bb | 868 | fdmi->hardware_version); |
6fef3902 NP |
869 | snprintf(fc_host_driver_version(lport->host), |
870 | FC_VERSION_STRING_SIZE, | |
871 | "%s", | |
f07d46bb | 872 | fdmi->driver_version); |
6fef3902 NP |
873 | snprintf(fc_host_optionrom_version(lport->host), |
874 | FC_VERSION_STRING_SIZE, | |
875 | "%s", | |
f07d46bb | 876 | fdmi->optionrom_version); |
6fef3902 NP |
877 | snprintf(fc_host_firmware_version(lport->host), |
878 | FC_VERSION_STRING_SIZE, | |
879 | "%s", | |
f07d46bb | 880 | fdmi->firmware_version); |
6fef3902 NP |
881 | |
882 | /* Enable FDMI lport states */ | |
883 | lport->fdmi_enabled = 1; | |
f07d46bb | 884 | kfree(fdmi); |
6fef3902 NP |
885 | } else { |
886 | lport->fdmi_enabled = 0; | |
887 | printk(KERN_INFO "fcoe: No FDMI support.\n"); | |
888 | } | |
889 | } | |
890 | ||
1875f27e RL |
891 | /** |
892 | * fcoe_oem_match() - The match routine for the offloaded exchange manager | |
893 | * @fp: The I/O frame | |
d7179680 | 894 | * |
1875f27e RL |
895 | * This routine will be associated with an exchange manager (EM). When |
896 | * the libfc exchange handling code is looking for an EM to use it will | |
897 | * call this routine and pass it the frame that it wishes to send. This | |
898 | * routine will return True if the associated EM is to be used and False | |
899 | * if the echange code should continue looking for an EM. | |
900 | * | |
901 | * The offload EM that this routine is associated with will handle any | |
902 | * packets that are for SCSI read requests. | |
903 | * | |
1ff9918b KP |
904 | * This has been enhanced to work when FCoE stack is operating in target |
905 | * mode. | |
906 | * | |
1875f27e | 907 | * Returns: True for read types I/O, otherwise returns false. |
d7179680 | 908 | */ |
7c9c6841 | 909 | static bool fcoe_oem_match(struct fc_frame *fp) |
d7179680 | 910 | { |
1ff9918b KP |
911 | struct fc_frame_header *fh = fc_frame_header_get(fp); |
912 | struct fcp_cmnd *fcp; | |
913 | ||
914 | if (fc_fcp_is_read(fr_fsp(fp)) && | |
915 | (fr_fsp(fp)->data_len > fcoe_ddp_min)) | |
916 | return true; | |
a762dce4 YZ |
917 | else if ((fr_fsp(fp) == NULL) && |
918 | (fh->fh_r_ctl == FC_RCTL_DD_UNSOL_CMD) && | |
919 | (ntohs(fh->fh_rx_id) == FC_XID_UNKNOWN)) { | |
1ff9918b | 920 | fcp = fc_frame_payload_get(fp, sizeof(*fcp)); |
a762dce4 YZ |
921 | if ((fcp->fc_flags & FCP_CFL_WRDATA) && |
922 | (ntohl(fcp->fc_dl) > fcoe_ddp_min)) | |
1ff9918b KP |
923 | return true; |
924 | } | |
925 | return false; | |
d7179680 VD |
926 | } |
927 | ||
7f349142 | 928 | /** |
1875f27e RL |
929 | * fcoe_em_config() - Allocate and configure an exchange manager |
930 | * @lport: The local port that the new EM will be associated with | |
7f349142 | 931 | * |
1875f27e | 932 | * Returns: 0 on success |
7f349142 | 933 | */ |
1875f27e | 934 | static inline int fcoe_em_config(struct fc_lport *lport) |
7f349142 | 935 | { |
1875f27e | 936 | struct fcoe_port *port = lport_priv(lport); |
8597ae8b | 937 | struct fcoe_interface *fcoe = port->priv; |
25024989 | 938 | struct fcoe_interface *oldfcoe = NULL; |
1d1b88dc | 939 | struct net_device *old_real_dev, *cur_real_dev; |
d7179680 VD |
940 | u16 min_xid = FCOE_MIN_XID; |
941 | u16 max_xid = FCOE_MAX_XID; | |
942 | ||
943 | /* | |
944 | * Check if need to allocate an em instance for | |
945 | * offload exchange ids to be shared across all VN_PORTs/lport. | |
946 | */ | |
1875f27e RL |
947 | if (!lport->lro_enabled || !lport->lro_xid || |
948 | (lport->lro_xid >= max_xid)) { | |
949 | lport->lro_xid = 0; | |
d7179680 VD |
950 | goto skip_oem; |
951 | } | |
952 | ||
953 | /* | |
954 | * Reuse existing offload em instance in case | |
1d1b88dc | 955 | * it is already allocated on real eth device |
d7179680 | 956 | */ |
d0d7b10b | 957 | if (is_vlan_dev(fcoe->netdev)) |
25024989 | 958 | cur_real_dev = vlan_dev_real_dev(fcoe->netdev); |
1d1b88dc | 959 | else |
25024989 | 960 | cur_real_dev = fcoe->netdev; |
1d1b88dc | 961 | |
25024989 | 962 | list_for_each_entry(oldfcoe, &fcoe_hostlist, list) { |
d0d7b10b | 963 | if (is_vlan_dev(oldfcoe->netdev)) |
25024989 | 964 | old_real_dev = vlan_dev_real_dev(oldfcoe->netdev); |
1d1b88dc | 965 | else |
25024989 | 966 | old_real_dev = oldfcoe->netdev; |
1d1b88dc VD |
967 | |
968 | if (cur_real_dev == old_real_dev) { | |
991cbb60 | 969 | fcoe->oem = oldfcoe->oem; |
d7179680 VD |
970 | break; |
971 | } | |
972 | } | |
973 | ||
991cbb60 | 974 | if (fcoe->oem) { |
1875f27e | 975 | if (!fc_exch_mgr_add(lport, fcoe->oem, fcoe_oem_match)) { |
d7179680 VD |
976 | printk(KERN_ERR "fcoe_em_config: failed to add " |
977 | "offload em:%p on interface:%s\n", | |
991cbb60 | 978 | fcoe->oem, fcoe->netdev->name); |
d7179680 VD |
979 | return -ENOMEM; |
980 | } | |
981 | } else { | |
1875f27e RL |
982 | fcoe->oem = fc_exch_mgr_alloc(lport, FC_CLASS_3, |
983 | FCOE_MIN_XID, lport->lro_xid, | |
984 | fcoe_oem_match); | |
991cbb60 | 985 | if (!fcoe->oem) { |
d7179680 VD |
986 | printk(KERN_ERR "fcoe_em_config: failed to allocate " |
987 | "em for offload exches on interface:%s\n", | |
25024989 | 988 | fcoe->netdev->name); |
d7179680 VD |
989 | return -ENOMEM; |
990 | } | |
991 | } | |
992 | ||
993 | /* | |
994 | * Exclude offload EM xid range from next EM xid range. | |
995 | */ | |
1875f27e | 996 | min_xid += lport->lro_xid + 1; |
d7179680 VD |
997 | |
998 | skip_oem: | |
1875f27e | 999 | if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, min_xid, max_xid, NULL)) { |
d7179680 | 1000 | printk(KERN_ERR "fcoe_em_config: failed to " |
25024989 | 1001 | "allocate em on interface %s\n", fcoe->netdev->name); |
7f349142 | 1002 | return -ENOMEM; |
d7179680 | 1003 | } |
7f349142 VD |
1004 | |
1005 | return 0; | |
1006 | } | |
1007 | ||
1008 | /** | |
1875f27e RL |
1009 | * fcoe_if_destroy() - Tear down a SW FCoE instance |
1010 | * @lport: The local port to be destroyed | |
34ce27bc | 1011 | * |
7eccdf00 HR |
1012 | * Locking: Must be called with the RTNL mutex held. |
1013 | * | |
7f349142 | 1014 | */ |
af7f85d9 | 1015 | static void fcoe_if_destroy(struct fc_lport *lport) |
7f349142 | 1016 | { |
b2085a4e NP |
1017 | struct fcoe_port *port = lport_priv(lport); |
1018 | struct fcoe_interface *fcoe = port->priv; | |
1019 | struct net_device *netdev = fcoe->netdev; | |
1020 | ||
1021 | FCOE_NETDEV_DBG(netdev, "Destroying interface\n"); | |
1022 | ||
1023 | /* Logout of the fabric */ | |
1024 | fc_fabric_logoff(lport); | |
1025 | ||
1026 | /* Cleanup the fc_lport */ | |
1027 | fc_lport_destroy(lport); | |
1028 | ||
1029 | /* Stop the transmit retry timer */ | |
1030 | del_timer_sync(&port->timer); | |
1031 | ||
1032 | /* Free existing transmit skbs */ | |
1033 | fcoe_clean_pending_queue(lport); | |
1034 | ||
b2085a4e NP |
1035 | if (!is_zero_ether_addr(port->data_src_addr)) |
1036 | dev_uc_del(netdev, port->data_src_addr); | |
433eba04 VD |
1037 | if (lport->vport) |
1038 | synchronize_net(); | |
1039 | else | |
1040 | fcoe_interface_remove(fcoe); | |
b2085a4e | 1041 | |
f161fb72 | 1042 | /* Free queued packets for the per-CPU receive threads */ |
af7f85d9 | 1043 | fcoe_percpu_clean(lport); |
f161fb72 | 1044 | |
7f349142 | 1045 | /* Detach from the scsi-ml */ |
af7f85d9 CL |
1046 | fc_remove_host(lport->host); |
1047 | scsi_remove_host(lport->host); | |
7f349142 | 1048 | |
80e736f8 YZ |
1049 | /* Destroy lport scsi_priv */ |
1050 | fc_fcp_destroy(lport); | |
1051 | ||
7f349142 | 1052 | /* There are no more rports or I/O, free the EM */ |
af7f85d9 | 1053 | fc_exch_mgr_free(lport); |
7f349142 | 1054 | |
7f349142 | 1055 | /* Free memory used by statistical counters */ |
af7f85d9 | 1056 | fc_lport_free_stats(lport); |
7f349142 | 1057 | |
3cab4468 VD |
1058 | /* |
1059 | * Release the Scsi_Host for vport but hold on to | |
1060 | * master lport until it fcoe interface fully cleaned-up. | |
1061 | */ | |
1062 | if (lport->vport) | |
1063 | scsi_host_put(lport->host); | |
7f349142 VD |
1064 | } |
1065 | ||
1875f27e RL |
1066 | /** |
1067 | * fcoe_ddp_setup() - Call a LLD's ddp_setup through the net device | |
1068 | * @lport: The local port to setup DDP for | |
1069 | * @xid: The exchange ID for this DDP transfer | |
1070 | * @sgl: The scatterlist describing this transfer | |
1071 | * @sgc: The number of sg items | |
7f349142 | 1072 | * |
1875f27e | 1073 | * Returns: 0 if the DDP context was not configured |
7f349142 | 1074 | */ |
1875f27e RL |
1075 | static int fcoe_ddp_setup(struct fc_lport *lport, u16 xid, |
1076 | struct scatterlist *sgl, unsigned int sgc) | |
7f349142 | 1077 | { |
1875f27e | 1078 | struct net_device *netdev = fcoe_netdev(lport); |
7f349142 | 1079 | |
1875f27e RL |
1080 | if (netdev->netdev_ops->ndo_fcoe_ddp_setup) |
1081 | return netdev->netdev_ops->ndo_fcoe_ddp_setup(netdev, | |
1082 | xid, sgl, | |
1083 | sgc); | |
7f349142 VD |
1084 | |
1085 | return 0; | |
1086 | } | |
1087 | ||
71f89491 YZ |
1088 | /** |
1089 | * fcoe_ddp_target() - Call a LLD's ddp_target through the net device | |
1090 | * @lport: The local port to setup DDP for | |
1091 | * @xid: The exchange ID for this DDP transfer | |
1092 | * @sgl: The scatterlist describing this transfer | |
1093 | * @sgc: The number of sg items | |
1094 | * | |
1095 | * Returns: 0 if the DDP context was not configured | |
1096 | */ | |
1097 | static int fcoe_ddp_target(struct fc_lport *lport, u16 xid, | |
1098 | struct scatterlist *sgl, unsigned int sgc) | |
1099 | { | |
1100 | struct net_device *netdev = fcoe_netdev(lport); | |
1101 | ||
1102 | if (netdev->netdev_ops->ndo_fcoe_ddp_target) | |
1103 | return netdev->netdev_ops->ndo_fcoe_ddp_target(netdev, xid, | |
1104 | sgl, sgc); | |
1105 | ||
1106 | return 0; | |
1107 | } | |
1108 | ||
1109 | ||
1875f27e RL |
1110 | /** |
1111 | * fcoe_ddp_done() - Call a LLD's ddp_done through the net device | |
1112 | * @lport: The local port to complete DDP on | |
1113 | * @xid: The exchange ID for this DDP transfer | |
7f349142 | 1114 | * |
1875f27e | 1115 | * Returns: the length of data that have been completed by DDP |
7f349142 | 1116 | */ |
1875f27e | 1117 | static int fcoe_ddp_done(struct fc_lport *lport, u16 xid) |
7f349142 | 1118 | { |
1875f27e | 1119 | struct net_device *netdev = fcoe_netdev(lport); |
7f349142 | 1120 | |
1875f27e RL |
1121 | if (netdev->netdev_ops->ndo_fcoe_ddp_done) |
1122 | return netdev->netdev_ops->ndo_fcoe_ddp_done(netdev, xid); | |
7f349142 VD |
1123 | return 0; |
1124 | } | |
1125 | ||
7f349142 | 1126 | /** |
1875f27e RL |
1127 | * fcoe_if_create() - Create a FCoE instance on an interface |
1128 | * @fcoe: The FCoE interface to create a local port on | |
1129 | * @parent: The device pointer to be the parent in sysfs for the SCSI host | |
1130 | * @npiv: Indicates if the port is a vport or not | |
7f349142 | 1131 | * |
1875f27e | 1132 | * Creates a fc_lport instance and a Scsi_Host instance and configure them. |
7f349142 | 1133 | * |
1875f27e | 1134 | * Returns: The allocated fc_lport or an error pointer |
7f349142 | 1135 | */ |
030f4e00 | 1136 | static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe, |
9a05753b | 1137 | struct device *parent, int npiv) |
7f349142 | 1138 | { |
619fe4be | 1139 | struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe); |
1875f27e | 1140 | struct net_device *netdev = fcoe->netdev; |
72fa396b | 1141 | struct fc_lport *lport, *n_port; |
014f5c3f | 1142 | struct fcoe_port *port; |
72fa396b | 1143 | struct Scsi_Host *shost; |
1875f27e | 1144 | int rc; |
9a05753b CL |
1145 | /* |
1146 | * parent is only a vport if npiv is 1, | |
1147 | * but we'll only use vport in that case so go ahead and set it | |
1148 | */ | |
1149 | struct fc_vport *vport = dev_to_vport(parent); | |
7f349142 | 1150 | |
d5488eb9 | 1151 | FCOE_NETDEV_DBG(netdev, "Create Interface\n"); |
7f349142 | 1152 | |
72fa396b VD |
1153 | if (!npiv) |
1154 | lport = libfc_host_alloc(&fcoe_shost_template, sizeof(*port)); | |
1155 | else | |
1156 | lport = libfc_vport_create(vport, sizeof(*port)); | |
1157 | ||
86221969 | 1158 | if (!lport) { |
d5488eb9 | 1159 | FCOE_NETDEV_DBG(netdev, "Could not allocate host structure\n"); |
af7f85d9 | 1160 | rc = -ENOMEM; |
030f4e00 | 1161 | goto out; |
7f349142 | 1162 | } |
014f5c3f | 1163 | port = lport_priv(lport); |
2e70e241 | 1164 | port->lport = lport; |
8597ae8b | 1165 | port->priv = fcoe; |
66524ec9 | 1166 | port->get_netdev = fcoe_netdev; |
8597ae8b BPG |
1167 | port->max_queue_depth = FCOE_MAX_QUEUE_DEPTH; |
1168 | port->min_queue_depth = FCOE_MIN_QUEUE_DEPTH; | |
2e70e241 | 1169 | INIT_WORK(&port->destroy_work, fcoe_destroy_work); |
7f349142 | 1170 | |
f9184df3 NH |
1171 | /* |
1172 | * Need to add the lport to the hostlist | |
1173 | * so we catch NETDEV_CHANGE events. | |
1174 | */ | |
1175 | fcoe_hostlist_add(lport); | |
1176 | ||
1875f27e | 1177 | /* configure a fc_lport including the exchange manager */ |
af7f85d9 | 1178 | rc = fcoe_lport_config(lport); |
7f349142 | 1179 | if (rc) { |
d5488eb9 RL |
1180 | FCOE_NETDEV_DBG(netdev, "Could not configure lport for the " |
1181 | "interface\n"); | |
7f349142 VD |
1182 | goto out_host_put; |
1183 | } | |
1184 | ||
9a05753b | 1185 | if (npiv) { |
9f8f3aa6 CL |
1186 | FCOE_NETDEV_DBG(netdev, "Setting vport names, " |
1187 | "%16.16llx %16.16llx\n", | |
1875f27e | 1188 | vport->node_name, vport->port_name); |
9a05753b CL |
1189 | fc_set_wwnn(lport, vport->node_name); |
1190 | fc_set_wwpn(lport, vport->port_name); | |
1191 | } | |
1192 | ||
ab6b85c1 | 1193 | /* configure lport network properties */ |
af7f85d9 | 1194 | rc = fcoe_netdev_config(lport, netdev); |
ab6b85c1 | 1195 | if (rc) { |
d5488eb9 RL |
1196 | FCOE_NETDEV_DBG(netdev, "Could not configure netdev for the " |
1197 | "interface\n"); | |
54b649f8 | 1198 | goto out_lp_destroy; |
ab6b85c1 | 1199 | } |
97c8389d | 1200 | |
7f349142 | 1201 | /* configure lport scsi host properties */ |
8ba00a4b | 1202 | rc = fcoe_shost_config(lport, parent); |
7f349142 | 1203 | if (rc) { |
d5488eb9 RL |
1204 | FCOE_NETDEV_DBG(netdev, "Could not configure shost for the " |
1205 | "interface\n"); | |
54b649f8 | 1206 | goto out_lp_destroy; |
7f349142 VD |
1207 | } |
1208 | ||
96316099 | 1209 | /* Initialize the library */ |
619fe4be | 1210 | rc = fcoe_libfc_config(lport, ctlr, &fcoe_libfc_fcn_templ, 1); |
7f349142 | 1211 | if (rc) { |
96316099 | 1212 | FCOE_NETDEV_DBG(netdev, "Could not configure libfc for the " |
d5488eb9 | 1213 | "interface\n"); |
96316099 | 1214 | goto out_lp_destroy; |
7f349142 VD |
1215 | } |
1216 | ||
6fef3902 NP |
1217 | /* Initialized FDMI information */ |
1218 | fcoe_fdmi_info(lport, netdev); | |
1219 | ||
72fa396b VD |
1220 | /* |
1221 | * fcoe_em_alloc() and fcoe_hostlist_add() both | |
1222 | * need to be atomic with respect to other changes to the | |
1223 | * hostlist since fcoe_em_alloc() looks for an existing EM | |
1224 | * instance on host list updated by fcoe_hostlist_add(). | |
1225 | * | |
1226 | * This is currently handled through the fcoe_config_mutex | |
1227 | * begin held. | |
1228 | */ | |
1229 | if (!npiv) | |
9a05753b CL |
1230 | /* lport exch manager allocation */ |
1231 | rc = fcoe_em_config(lport); | |
72fa396b VD |
1232 | else { |
1233 | shost = vport_to_shost(vport); | |
1234 | n_port = shost_priv(shost); | |
1235 | rc = fc_exch_mgr_list_clone(n_port, lport); | |
1236 | } | |
1237 | ||
1238 | if (rc) { | |
1239 | FCOE_NETDEV_DBG(netdev, "Could not configure the EM\n"); | |
1240 | goto out_lp_destroy; | |
7f349142 VD |
1241 | } |
1242 | ||
af7f85d9 | 1243 | return lport; |
7f349142 VD |
1244 | |
1245 | out_lp_destroy: | |
af7f85d9 | 1246 | fc_exch_mgr_free(lport); |
7f349142 | 1247 | out_host_put: |
f9184df3 | 1248 | fcoe_hostlist_del(lport); |
af7f85d9 CL |
1249 | scsi_host_put(lport->host); |
1250 | out: | |
1251 | return ERR_PTR(rc); | |
7f349142 VD |
1252 | } |
1253 | ||
1254 | /** | |
1875f27e | 1255 | * fcoe_if_init() - Initialization routine for fcoe.ko |
7f349142 | 1256 | * |
1875f27e RL |
1257 | * Attaches the SW FCoE transport to the FC transport |
1258 | * | |
1259 | * Returns: 0 on success | |
7f349142 VD |
1260 | */ |
1261 | static int __init fcoe_if_init(void) | |
1262 | { | |
1263 | /* attach to scsi transport */ | |
8ca86f84 YZ |
1264 | fcoe_nport_scsi_transport = |
1265 | fc_attach_transport(&fcoe_nport_fc_functions); | |
1266 | fcoe_vport_scsi_transport = | |
1267 | fc_attach_transport(&fcoe_vport_fc_functions); | |
7f349142 | 1268 | |
8ca86f84 | 1269 | if (!fcoe_nport_scsi_transport) { |
d5488eb9 | 1270 | printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n"); |
7f349142 VD |
1271 | return -ENODEV; |
1272 | } | |
1273 | ||
1274 | return 0; | |
1275 | } | |
1276 | ||
1277 | /** | |
1875f27e RL |
1278 | * fcoe_if_exit() - Tear down fcoe.ko |
1279 | * | |
1280 | * Detaches the SW FCoE transport from the FC transport | |
7f349142 | 1281 | * |
1875f27e | 1282 | * Returns: 0 on success |
7f349142 | 1283 | */ |
7c9c6841 | 1284 | static int __exit fcoe_if_exit(void) |
7f349142 | 1285 | { |
8ca86f84 YZ |
1286 | fc_release_transport(fcoe_nport_scsi_transport); |
1287 | fc_release_transport(fcoe_vport_scsi_transport); | |
1288 | fcoe_nport_scsi_transport = NULL; | |
1289 | fcoe_vport_scsi_transport = NULL; | |
7f349142 VD |
1290 | return 0; |
1291 | } | |
1292 | ||
4b9bc86d | 1293 | static void fcoe_thread_cleanup_local(unsigned int cpu) |
8976f424 | 1294 | { |
8976f424 | 1295 | struct page *crc_eof; |
4b9bc86d | 1296 | struct fcoe_percpu_s *p; |
8976f424 | 1297 | |
4b9bc86d | 1298 | p = per_cpu_ptr(&fcoe_percpu, cpu); |
8976f424 | 1299 | spin_lock_bh(&p->fcoe_rx_list.lock); |
8976f424 RL |
1300 | crc_eof = p->crc_eof_page; |
1301 | p->crc_eof_page = NULL; | |
1302 | p->crc_eof_offset = 0; | |
1303 | spin_unlock_bh(&p->fcoe_rx_list.lock); | |
1304 | ||
8976f424 RL |
1305 | if (crc_eof) |
1306 | put_page(crc_eof); | |
4b9bc86d | 1307 | flush_work(&p->work); |
8976f424 RL |
1308 | } |
1309 | ||
064287ee KP |
1310 | /** |
1311 | * fcoe_select_cpu() - Selects CPU to handle post-processing of incoming | |
1312 | * command. | |
064287ee | 1313 | * |
d272281c VD |
1314 | * This routine selects next CPU based on cpumask to distribute |
1315 | * incoming requests in round robin. | |
064287ee | 1316 | * |
d272281c | 1317 | * Returns: int CPU number |
064287ee | 1318 | */ |
d272281c | 1319 | static inline unsigned int fcoe_select_cpu(void) |
064287ee KP |
1320 | { |
1321 | static unsigned int selected_cpu; | |
1322 | ||
d272281c VD |
1323 | selected_cpu = cpumask_next(selected_cpu, cpu_online_mask); |
1324 | if (selected_cpu >= nr_cpu_ids) | |
1325 | selected_cpu = cpumask_first(cpu_online_mask); | |
1326 | ||
064287ee KP |
1327 | return selected_cpu; |
1328 | } | |
1329 | ||
85b4aa49 | 1330 | /** |
1875f27e RL |
1331 | * fcoe_rcv() - Receive packets from a net device |
1332 | * @skb: The received packet | |
1333 | * @netdev: The net device that the packet was received on | |
1334 | * @ptype: The packet type context | |
1335 | * @olddev: The last device net device | |
85b4aa49 | 1336 | * |
1875f27e RL |
1337 | * This routine is called by NET_RX_SOFTIRQ. It receives a packet, builds a |
1338 | * FC frame and passes the frame to libfc. | |
85b4aa49 RL |
1339 | * |
1340 | * Returns: 0 for success | |
34f42a07 | 1341 | */ |
7c9c6841 | 1342 | static int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev, |
85b4aa49 RL |
1343 | struct packet_type *ptype, struct net_device *olddev) |
1344 | { | |
1875f27e | 1345 | struct fc_lport *lport; |
85b4aa49 | 1346 | struct fcoe_rcv_info *fr; |
619fe4be | 1347 | struct fcoe_ctlr *ctlr; |
259ad85d | 1348 | struct fcoe_interface *fcoe; |
85b4aa49 | 1349 | struct fc_frame_header *fh; |
85b4aa49 | 1350 | struct fcoe_percpu_s *fps; |
519e5135 | 1351 | struct ethhdr *eh; |
b2f0091f | 1352 | unsigned int cpu; |
85b4aa49 | 1353 | |
259ad85d | 1354 | fcoe = container_of(ptype, struct fcoe_interface, fcoe_packet_type); |
619fe4be RL |
1355 | ctlr = fcoe_to_ctlr(fcoe); |
1356 | lport = ctlr->lp; | |
1875f27e | 1357 | if (unlikely(!lport)) { |
465b87bf | 1358 | FCOE_NETDEV_DBG(netdev, "Cannot find hba structure\n"); |
85b4aa49 RL |
1359 | goto err2; |
1360 | } | |
1875f27e | 1361 | if (!lport->link_up) |
97c8389d | 1362 | goto err2; |
85b4aa49 | 1363 | |
465b87bf BVA |
1364 | FCOE_NETDEV_DBG(netdev, |
1365 | "skb_info: len:%d data_len:%d head:%p data:%p tail:%p end:%p sum:%d dev:%s\n", | |
d5488eb9 RL |
1366 | skb->len, skb->data_len, skb->head, skb->data, |
1367 | skb_tail_pointer(skb), skb_end_pointer(skb), | |
1368 | skb->csum, skb->dev ? skb->dev->name : "<NULL>"); | |
85b4aa49 | 1369 | |
8b612434 NH |
1370 | |
1371 | skb = skb_share_check(skb, GFP_ATOMIC); | |
1372 | ||
1373 | if (skb == NULL) | |
1374 | return NET_RX_DROP; | |
1375 | ||
519e5135 | 1376 | eh = eth_hdr(skb); |
519e5135 | 1377 | |
619fe4be | 1378 | if (is_fip_mode(ctlr) && |
6942df7f | 1379 | !ether_addr_equal(eh->h_source, ctlr->dest_addr)) { |
519e5135 VD |
1380 | FCOE_NETDEV_DBG(netdev, "wrong source mac address:%pM\n", |
1381 | eh->h_source); | |
85b4aa49 RL |
1382 | goto err; |
1383 | } | |
1384 | ||
1385 | /* | |
1386 | * Check for minimum frame length, and make sure required FCoE | |
1387 | * and FC headers are pulled into the linear data area. | |
1388 | */ | |
1389 | if (unlikely((skb->len < FCOE_MIN_FRAME) || | |
1875f27e | 1390 | !pskb_may_pull(skb, FCOE_HEADER_LEN))) |
85b4aa49 RL |
1391 | goto err; |
1392 | ||
1393 | skb_set_transport_header(skb, sizeof(struct fcoe_hdr)); | |
1394 | fh = (struct fc_frame_header *) skb_transport_header(skb); | |
1395 | ||
0ee31cb5 RL |
1396 | if (ntoh24(&eh->h_dest[3]) != ntoh24(fh->fh_d_id)) { |
1397 | FCOE_NETDEV_DBG(netdev, "FC frame d_id mismatch with MAC:%pM\n", | |
1398 | eh->h_dest); | |
1399 | goto err; | |
1400 | } | |
1401 | ||
85b4aa49 | 1402 | fr = fcoe_dev_from_skb(skb); |
1875f27e | 1403 | fr->fr_dev = lport; |
5e5e92df | 1404 | |
85b4aa49 | 1405 | /* |
b2f0091f VD |
1406 | * In case the incoming frame's exchange is originated from |
1407 | * the initiator, then received frame's exchange id is ANDed | |
1408 | * with fc_cpu_mask bits to get the same cpu on which exchange | |
d272281c VD |
1409 | * was originated, otherwise select cpu using rx exchange id |
1410 | * or fcoe_select_cpu(). | |
85b4aa49 | 1411 | */ |
b2f0091f VD |
1412 | if (ntoh24(fh->fh_f_ctl) & FC_FC_EX_CTX) |
1413 | cpu = ntohs(fh->fh_ox_id) & fc_cpu_mask; | |
064287ee | 1414 | else { |
d272281c VD |
1415 | if (ntohs(fh->fh_rx_id) == FC_XID_UNKNOWN) |
1416 | cpu = fcoe_select_cpu(); | |
1417 | else | |
29bdd2bb | 1418 | cpu = ntohs(fh->fh_rx_id) & fc_cpu_mask; |
064287ee | 1419 | } |
324f6678 VD |
1420 | |
1421 | if (cpu >= nr_cpu_ids) | |
1422 | goto err; | |
1423 | ||
8976f424 | 1424 | fps = &per_cpu(fcoe_percpu, cpu); |
94aa29f2 | 1425 | spin_lock(&fps->fcoe_rx_list.lock); |
8976f424 RL |
1426 | /* |
1427 | * We now have a valid CPU that we're targeting for | |
1428 | * this skb. We also have this receive thread locked, | |
1429 | * so we're free to queue skbs into it's queue. | |
1430 | */ | |
85b4aa49 | 1431 | |
5e70c4c4 NH |
1432 | /* |
1433 | * Note: We used to have a set of conditions under which we would | |
1434 | * call fcoe_recv_frame directly, rather than queuing to the rx list | |
1435 | * as it could save a few cycles, but doing so is prohibited, as | |
1436 | * fcoe_recv_frame has several paths that may sleep, which is forbidden | |
1437 | * in softirq context. | |
859b7b64 | 1438 | */ |
5e70c4c4 | 1439 | __skb_queue_tail(&fps->fcoe_rx_list, skb); |
4b9bc86d | 1440 | schedule_work_on(cpu, &fps->work); |
94aa29f2 | 1441 | spin_unlock(&fps->fcoe_rx_list.lock); |
85b4aa49 | 1442 | |
34bac2ef | 1443 | return NET_RX_SUCCESS; |
85b4aa49 | 1444 | err: |
1bd49b48 | 1445 | per_cpu_ptr(lport->stats, get_cpu())->ErrorFrames++; |
f018b73a | 1446 | put_cpu(); |
85b4aa49 RL |
1447 | err2: |
1448 | kfree_skb(skb); | |
34bac2ef | 1449 | return NET_RX_DROP; |
85b4aa49 | 1450 | } |
85b4aa49 RL |
1451 | |
1452 | /** | |
8597ae8b | 1453 | * fcoe_alloc_paged_crc_eof() - Allocate a page to be used for the trailer CRC |
1875f27e RL |
1454 | * @skb: The packet to be transmitted |
1455 | * @tlen: The total length of the trailer | |
1456 | * | |
85b4aa49 | 1457 | * Returns: 0 for success |
34f42a07 | 1458 | */ |
8597ae8b | 1459 | static int fcoe_alloc_paged_crc_eof(struct sk_buff *skb, int tlen) |
85b4aa49 RL |
1460 | { |
1461 | struct fcoe_percpu_s *fps; | |
8597ae8b | 1462 | int rc; |
85b4aa49 | 1463 | |
5e5e92df | 1464 | fps = &get_cpu_var(fcoe_percpu); |
8597ae8b | 1465 | rc = fcoe_get_paged_crc_eof(skb, tlen, fps); |
5e5e92df | 1466 | put_cpu_var(fcoe_percpu); |
85b4aa49 | 1467 | |
8597ae8b | 1468 | return rc; |
85b4aa49 | 1469 | } |
85b4aa49 RL |
1470 | |
1471 | /** | |
1875f27e RL |
1472 | * fcoe_xmit() - Transmit a FCoE frame |
1473 | * @lport: The local port that the frame is to be transmitted for | |
1474 | * @fp: The frame to be transmitted | |
85b4aa49 | 1475 | * |
1875f27e | 1476 | * Return: 0 for success |
34f42a07 | 1477 | */ |
7c9c6841 | 1478 | static int fcoe_xmit(struct fc_lport *lport, struct fc_frame *fp) |
85b4aa49 | 1479 | { |
4bb6b515 | 1480 | int wlen; |
85b4aa49 RL |
1481 | u32 crc; |
1482 | struct ethhdr *eh; | |
1483 | struct fcoe_crc_eof *cp; | |
1484 | struct sk_buff *skb; | |
1bd49b48 | 1485 | struct fc_stats *stats; |
85b4aa49 RL |
1486 | struct fc_frame_header *fh; |
1487 | unsigned int hlen; /* header length implies the version */ | |
1488 | unsigned int tlen; /* trailer length */ | |
1489 | unsigned int elen; /* eth header, may include vlan */ | |
1875f27e | 1490 | struct fcoe_port *port = lport_priv(lport); |
8597ae8b | 1491 | struct fcoe_interface *fcoe = port->priv; |
619fe4be | 1492 | struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe); |
85b4aa49 RL |
1493 | u8 sof, eof; |
1494 | struct fcoe_hdr *hp; | |
1495 | ||
1496 | WARN_ON((fr_len(fp) % sizeof(u32)) != 0); | |
1497 | ||
85b4aa49 | 1498 | fh = fc_frame_header_get(fp); |
97c8389d JE |
1499 | skb = fp_skb(fp); |
1500 | wlen = skb->len / FCOE_WORD_TO_BYTE; | |
1501 | ||
1875f27e | 1502 | if (!lport->link_up) { |
3caf02ee | 1503 | kfree_skb(skb); |
97c8389d | 1504 | return 0; |
85b4aa49 RL |
1505 | } |
1506 | ||
9860eeb4 | 1507 | if (unlikely(fh->fh_type == FC_TYPE_ELS) && |
619fe4be | 1508 | fcoe_ctlr_els_send(ctlr, lport, skb)) |
97c8389d JE |
1509 | return 0; |
1510 | ||
85b4aa49 RL |
1511 | sof = fr_sof(fp); |
1512 | eof = fr_eof(fp); | |
1513 | ||
4e57e1cb | 1514 | elen = sizeof(struct ethhdr); |
85b4aa49 RL |
1515 | hlen = sizeof(struct fcoe_hdr); |
1516 | tlen = sizeof(struct fcoe_crc_eof); | |
1517 | wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE; | |
1518 | ||
1519 | /* crc offload */ | |
1875f27e | 1520 | if (likely(lport->crc_offload)) { |
253aab05 | 1521 | skb->ip_summed = CHECKSUM_PARTIAL; |
85b4aa49 RL |
1522 | skb->csum_start = skb_headroom(skb); |
1523 | skb->csum_offset = skb->len; | |
1524 | crc = 0; | |
1525 | } else { | |
1526 | skb->ip_summed = CHECKSUM_NONE; | |
1527 | crc = fcoe_fc_crc(fp); | |
1528 | } | |
1529 | ||
014f5c3f | 1530 | /* copy port crc and eof to the skb buff */ |
85b4aa49 RL |
1531 | if (skb_is_nonlinear(skb)) { |
1532 | skb_frag_t *frag; | |
8597ae8b | 1533 | if (fcoe_alloc_paged_crc_eof(skb, tlen)) { |
e9041581 | 1534 | kfree_skb(skb); |
85b4aa49 RL |
1535 | return -ENOMEM; |
1536 | } | |
1537 | frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1]; | |
77dfce07 | 1538 | cp = kmap_atomic(skb_frag_page(frag)) |
85b4aa49 RL |
1539 | + frag->page_offset; |
1540 | } else { | |
4df864c1 | 1541 | cp = skb_put(skb, tlen); |
85b4aa49 RL |
1542 | } |
1543 | ||
1544 | memset(cp, 0, sizeof(*cp)); | |
1545 | cp->fcoe_eof = eof; | |
1546 | cp->fcoe_crc32 = cpu_to_le32(~crc); | |
1547 | ||
1548 | if (skb_is_nonlinear(skb)) { | |
77dfce07 | 1549 | kunmap_atomic(cp); |
85b4aa49 RL |
1550 | cp = NULL; |
1551 | } | |
1552 | ||
014f5c3f | 1553 | /* adjust skb network/transport offsets to match mac/fcoe/port */ |
85b4aa49 RL |
1554 | skb_push(skb, elen + hlen); |
1555 | skb_reset_mac_header(skb); | |
1556 | skb_reset_network_header(skb); | |
1557 | skb->mac_len = elen; | |
211c738d | 1558 | skb->protocol = htons(ETH_P_FCOE); |
31c37a6f | 1559 | skb->priority = fcoe->priority; |
6f6c2aa3 | 1560 | |
d0d7b10b | 1561 | if (is_vlan_dev(fcoe->netdev) && |
f646968f | 1562 | fcoe->realdev->features & NETIF_F_HW_VLAN_CTAG_TX) { |
2884d423 | 1563 | /* must set skb->dev before calling vlan_put_tag */ |
d1483bb9 | 1564 | skb->dev = fcoe->realdev; |
b960a0ac JP |
1565 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), |
1566 | vlan_dev_vlan_id(fcoe->netdev)); | |
d1483bb9 VD |
1567 | } else |
1568 | skb->dev = fcoe->netdev; | |
85b4aa49 RL |
1569 | |
1570 | /* fill up mac and fcoe headers */ | |
1571 | eh = eth_hdr(skb); | |
1572 | eh->h_proto = htons(ETH_P_FCOE); | |
619fe4be RL |
1573 | memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN); |
1574 | if (ctlr->map_dest) | |
cd229e42 | 1575 | memcpy(eh->h_dest + 3, fh->fh_d_id, 3); |
85b4aa49 | 1576 | |
619fe4be RL |
1577 | if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN)) |
1578 | memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN); | |
85b4aa49 | 1579 | else |
11b56188 | 1580 | memcpy(eh->h_source, port->data_src_addr, ETH_ALEN); |
85b4aa49 RL |
1581 | |
1582 | hp = (struct fcoe_hdr *)(eh + 1); | |
1583 | memset(hp, 0, sizeof(*hp)); | |
1584 | if (FC_FCOE_VER) | |
1585 | FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER); | |
1586 | hp->fcoe_sof = sof; | |
1587 | ||
39ca9a06 | 1588 | /* fcoe lso, mss is in max_payload which is non-zero for FCP data */ |
1875f27e | 1589 | if (lport->seq_offload && fr_max_payload(fp)) { |
39ca9a06 YZ |
1590 | skb_shinfo(skb)->gso_type = SKB_GSO_FCOE; |
1591 | skb_shinfo(skb)->gso_size = fr_max_payload(fp); | |
1592 | } else { | |
1593 | skb_shinfo(skb)->gso_type = 0; | |
1594 | skb_shinfo(skb)->gso_size = 0; | |
1595 | } | |
85b4aa49 | 1596 | /* update tx stats: regardless if LLD fails */ |
1bd49b48 | 1597 | stats = per_cpu_ptr(lport->stats, get_cpu()); |
582b45bc RL |
1598 | stats->TxFrames++; |
1599 | stats->TxWords += wlen; | |
f018b73a | 1600 | put_cpu(); |
85b4aa49 RL |
1601 | |
1602 | /* send down to lld */ | |
1875f27e | 1603 | fr_dev(fp) = lport; |
980f5156 | 1604 | fcoe_port_send(port, skb); |
85b4aa49 RL |
1605 | return 0; |
1606 | } | |
85b4aa49 | 1607 | |
52ee8321 VD |
1608 | /** |
1609 | * fcoe_filter_frames() - filter out bad fcoe frames, i.e. bad CRC | |
1610 | * @lport: The local port the frame was received on | |
1611 | * @fp: The received frame | |
1612 | * | |
1613 | * Return: 0 on passing filtering checks | |
1614 | */ | |
1615 | static inline int fcoe_filter_frames(struct fc_lport *lport, | |
1616 | struct fc_frame *fp) | |
1617 | { | |
619fe4be | 1618 | struct fcoe_ctlr *ctlr; |
52ee8321 VD |
1619 | struct fcoe_interface *fcoe; |
1620 | struct fc_frame_header *fh; | |
1621 | struct sk_buff *skb = (struct sk_buff *)fp; | |
1bd49b48 | 1622 | struct fc_stats *stats; |
52ee8321 VD |
1623 | |
1624 | /* | |
1625 | * We only check CRC if no offload is available and if it is | |
1626 | * it's solicited data, in which case, the FCP layer would | |
1627 | * check it during the copy. | |
1628 | */ | |
1629 | if (lport->crc_offload && skb->ip_summed == CHECKSUM_UNNECESSARY) | |
1630 | fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED; | |
1631 | else | |
1632 | fr_flags(fp) |= FCPHF_CRC_UNCHECKED; | |
1633 | ||
1634 | fh = (struct fc_frame_header *) skb_transport_header(skb); | |
1635 | fh = fc_frame_header_get(fp); | |
1636 | if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA && fh->fh_type == FC_TYPE_FCP) | |
1637 | return 0; | |
1638 | ||
8597ae8b | 1639 | fcoe = ((struct fcoe_port *)lport_priv(lport))->priv; |
619fe4be RL |
1640 | ctlr = fcoe_to_ctlr(fcoe); |
1641 | if (is_fip_mode(ctlr) && fc_frame_payload_op(fp) == ELS_LOGO && | |
52ee8321 VD |
1642 | ntoh24(fh->fh_s_id) == FC_FID_FLOGI) { |
1643 | FCOE_DBG("fcoe: dropping FCoE lport LOGO in fip mode\n"); | |
1644 | return -EINVAL; | |
1645 | } | |
1646 | ||
f2f96d20 | 1647 | if (!(fr_flags(fp) & FCPHF_CRC_UNCHECKED) || |
52ee8321 VD |
1648 | le32_to_cpu(fr_crc(fp)) == ~crc32(~0, skb->data, skb->len)) { |
1649 | fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED; | |
1650 | return 0; | |
1651 | } | |
1652 | ||
1bd49b48 | 1653 | stats = per_cpu_ptr(lport->stats, get_cpu()); |
52ee8321 VD |
1654 | stats->InvalidCRCCount++; |
1655 | if (stats->InvalidCRCCount < 5) | |
1656 | printk(KERN_WARNING "fcoe: dropping frame with CRC error\n"); | |
7e1e7ead | 1657 | put_cpu(); |
52ee8321 VD |
1658 | return -EINVAL; |
1659 | } | |
1660 | ||
34f42a07 | 1661 | /** |
859b7b64 CL |
1662 | * fcoe_recv_frame() - process a single received frame |
1663 | * @skb: frame to process | |
85b4aa49 | 1664 | */ |
859b7b64 | 1665 | static void fcoe_recv_frame(struct sk_buff *skb) |
85b4aa49 | 1666 | { |
85b4aa49 | 1667 | u32 fr_len; |
1875f27e | 1668 | struct fc_lport *lport; |
85b4aa49 | 1669 | struct fcoe_rcv_info *fr; |
1bd49b48 | 1670 | struct fc_stats *stats; |
85b4aa49 RL |
1671 | struct fcoe_crc_eof crc_eof; |
1672 | struct fc_frame *fp; | |
014f5c3f | 1673 | struct fcoe_port *port; |
85b4aa49 RL |
1674 | struct fcoe_hdr *hp; |
1675 | ||
859b7b64 CL |
1676 | fr = fcoe_dev_from_skb(skb); |
1677 | lport = fr->fr_dev; | |
1678 | if (unlikely(!lport)) { | |
4b9bc86d | 1679 | FCOE_NETDEV_DBG(skb->dev, "NULL lport in skb\n"); |
859b7b64 CL |
1680 | kfree_skb(skb); |
1681 | return; | |
1682 | } | |
1683 | ||
465b87bf BVA |
1684 | FCOE_NETDEV_DBG(skb->dev, |
1685 | "skb_info: len:%d data_len:%d head:%p data:%p tail:%p end:%p sum:%d dev:%s\n", | |
859b7b64 CL |
1686 | skb->len, skb->data_len, |
1687 | skb->head, skb->data, skb_tail_pointer(skb), | |
1688 | skb_end_pointer(skb), skb->csum, | |
1689 | skb->dev ? skb->dev->name : "<NULL>"); | |
1690 | ||
859b7b64 | 1691 | port = lport_priv(lport); |
f1633011 | 1692 | skb_linearize(skb); /* check for skb_is_nonlinear is within skb_linearize */ |
859b7b64 CL |
1693 | |
1694 | /* | |
1695 | * Frame length checks and setting up the header pointers | |
1696 | * was done in fcoe_rcv already. | |
1697 | */ | |
1698 | hp = (struct fcoe_hdr *) skb_network_header(skb); | |
859b7b64 | 1699 | |
1bd49b48 | 1700 | stats = per_cpu_ptr(lport->stats, get_cpu()); |
859b7b64 CL |
1701 | if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) { |
1702 | if (stats->ErrorFrames < 5) | |
1703 | printk(KERN_WARNING "fcoe: FCoE version " | |
1704 | "mismatch: The frame has " | |
1705 | "version %x, but the " | |
1706 | "initiator supports version " | |
1707 | "%x\n", FC_FCOE_DECAPS_VER(hp), | |
1708 | FC_FCOE_VER); | |
f018b73a | 1709 | goto drop; |
859b7b64 CL |
1710 | } |
1711 | ||
1712 | skb_pull(skb, sizeof(struct fcoe_hdr)); | |
1713 | fr_len = skb->len - sizeof(struct fcoe_crc_eof); | |
1714 | ||
1715 | stats->RxFrames++; | |
1716 | stats->RxWords += fr_len / FCOE_WORD_TO_BYTE; | |
1717 | ||
1718 | fp = (struct fc_frame *)skb; | |
1719 | fc_frame_init(fp); | |
1720 | fr_dev(fp) = lport; | |
1721 | fr_sof(fp) = hp->fcoe_sof; | |
1722 | ||
1723 | /* Copy out the CRC and EOF trailer for access */ | |
f018b73a JE |
1724 | if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) |
1725 | goto drop; | |
859b7b64 CL |
1726 | fr_eof(fp) = crc_eof.fcoe_eof; |
1727 | fr_crc(fp) = crc_eof.fcoe_crc32; | |
f018b73a JE |
1728 | if (pskb_trim(skb, fr_len)) |
1729 | goto drop; | |
859b7b64 | 1730 | |
52ee8321 VD |
1731 | if (!fcoe_filter_frames(lport, fp)) { |
1732 | put_cpu(); | |
1733 | fc_exch_recv(lport, fp); | |
1734 | return; | |
859b7b64 | 1735 | } |
f018b73a JE |
1736 | drop: |
1737 | stats->ErrorFrames++; | |
1738 | put_cpu(); | |
1739 | kfree_skb(skb); | |
859b7b64 CL |
1740 | } |
1741 | ||
1742 | /** | |
4b9bc86d SAS |
1743 | * fcoe_receive_work() - The per-CPU worker |
1744 | * @work: The work struct | |
859b7b64 | 1745 | * |
859b7b64 | 1746 | */ |
4b9bc86d | 1747 | static void fcoe_receive_work(struct work_struct *work) |
859b7b64 | 1748 | { |
4b9bc86d | 1749 | struct fcoe_percpu_s *p; |
859b7b64 | 1750 | struct sk_buff *skb; |
20dc3811 NH |
1751 | struct sk_buff_head tmp; |
1752 | ||
4b9bc86d | 1753 | p = container_of(work, struct fcoe_percpu_s, work); |
20dc3811 | 1754 | skb_queue_head_init(&tmp); |
859b7b64 | 1755 | |
4b9bc86d SAS |
1756 | spin_lock_bh(&p->fcoe_rx_list.lock); |
1757 | skb_queue_splice_init(&p->fcoe_rx_list, &tmp); | |
1758 | spin_unlock_bh(&p->fcoe_rx_list.lock); | |
95fdd5e9 | 1759 | |
4b9bc86d SAS |
1760 | if (!skb_queue_len(&tmp)) |
1761 | return; | |
95fdd5e9 | 1762 | |
4b9bc86d SAS |
1763 | while ((skb = __skb_dequeue(&tmp))) |
1764 | fcoe_recv_frame(skb); | |
85b4aa49 RL |
1765 | } |
1766 | ||
85b4aa49 | 1767 | /** |
1875f27e | 1768 | * fcoe_dev_setup() - Setup the link change notification interface |
34f42a07 | 1769 | */ |
b0d428ad | 1770 | static void fcoe_dev_setup(void) |
85b4aa49 | 1771 | { |
6f6c2aa3 | 1772 | register_dcbevent_notifier(&dcb_notifier); |
85b4aa49 RL |
1773 | register_netdevice_notifier(&fcoe_notifier); |
1774 | } | |
1775 | ||
1776 | /** | |
1875f27e | 1777 | * fcoe_dev_cleanup() - Cleanup the link change notification interface |
34f42a07 | 1778 | */ |
85b4aa49 RL |
1779 | static void fcoe_dev_cleanup(void) |
1780 | { | |
6f6c2aa3 | 1781 | unregister_dcbevent_notifier(&dcb_notifier); |
85b4aa49 RL |
1782 | unregister_netdevice_notifier(&fcoe_notifier); |
1783 | } | |
1784 | ||
6f6c2aa3 | 1785 | static struct fcoe_interface * |
1786 | fcoe_hostlist_lookup_realdev_port(struct net_device *netdev) | |
1787 | { | |
1788 | struct fcoe_interface *fcoe; | |
1789 | struct net_device *real_dev; | |
1790 | ||
1791 | list_for_each_entry(fcoe, &fcoe_hostlist, list) { | |
d0d7b10b | 1792 | if (is_vlan_dev(fcoe->netdev)) |
6f6c2aa3 | 1793 | real_dev = vlan_dev_real_dev(fcoe->netdev); |
1794 | else | |
1795 | real_dev = fcoe->netdev; | |
1796 | ||
1797 | if (netdev == real_dev) | |
1798 | return fcoe; | |
1799 | } | |
1800 | return NULL; | |
1801 | } | |
1802 | ||
1803 | static int fcoe_dcb_app_notification(struct notifier_block *notifier, | |
1804 | ulong event, void *ptr) | |
1805 | { | |
1806 | struct dcb_app_type *entry = ptr; | |
619fe4be | 1807 | struct fcoe_ctlr *ctlr; |
6f6c2aa3 | 1808 | struct fcoe_interface *fcoe; |
1809 | struct net_device *netdev; | |
6f6c2aa3 | 1810 | int prio; |
1811 | ||
1812 | if (entry->app.selector != DCB_APP_IDTYPE_ETHTYPE) | |
1813 | return NOTIFY_OK; | |
1814 | ||
1815 | netdev = dev_get_by_index(&init_net, entry->ifindex); | |
1816 | if (!netdev) | |
1817 | return NOTIFY_OK; | |
1818 | ||
1819 | fcoe = fcoe_hostlist_lookup_realdev_port(netdev); | |
1820 | dev_put(netdev); | |
1821 | if (!fcoe) | |
1822 | return NOTIFY_OK; | |
1823 | ||
619fe4be RL |
1824 | ctlr = fcoe_to_ctlr(fcoe); |
1825 | ||
6f6c2aa3 | 1826 | if (entry->dcbx & DCB_CAP_DCBX_VER_CEE) |
1827 | prio = ffs(entry->app.priority) - 1; | |
1828 | else | |
1829 | prio = entry->app.priority; | |
1830 | ||
1831 | if (prio < 0) | |
1832 | return NOTIFY_OK; | |
1833 | ||
1834 | if (entry->app.protocol == ETH_P_FIP || | |
1835 | entry->app.protocol == ETH_P_FCOE) | |
619fe4be | 1836 | ctlr->priority = prio; |
6f6c2aa3 | 1837 | |
31c37a6f NP |
1838 | if (entry->app.protocol == ETH_P_FCOE) |
1839 | fcoe->priority = prio; | |
6f6c2aa3 | 1840 | |
1841 | return NOTIFY_OK; | |
1842 | } | |
1843 | ||
85b4aa49 | 1844 | /** |
1875f27e RL |
1845 | * fcoe_device_notification() - Handler for net device events |
1846 | * @notifier: The context of the notification | |
1847 | * @event: The type of event | |
1848 | * @ptr: The net device that the event was on | |
85b4aa49 | 1849 | * |
1875f27e | 1850 | * This function is called by the Ethernet driver in case of link change event. |
85b4aa49 RL |
1851 | * |
1852 | * Returns: 0 for success | |
34f42a07 | 1853 | */ |
85b4aa49 RL |
1854 | static int fcoe_device_notification(struct notifier_block *notifier, |
1855 | ulong event, void *ptr) | |
1856 | { | |
435c8667 | 1857 | struct fcoe_ctlr_device *cdev; |
1875f27e | 1858 | struct fc_lport *lport = NULL; |
351638e7 | 1859 | struct net_device *netdev = netdev_notifier_info_to_dev(ptr); |
619fe4be | 1860 | struct fcoe_ctlr *ctlr; |
014f5c3f | 1861 | struct fcoe_interface *fcoe; |
2e70e241 | 1862 | struct fcoe_port *port; |
1bd49b48 | 1863 | struct fc_stats *stats; |
97c8389d | 1864 | u32 link_possible = 1; |
85b4aa49 RL |
1865 | u32 mfs; |
1866 | int rc = NOTIFY_OK; | |
1867 | ||
014f5c3f | 1868 | list_for_each_entry(fcoe, &fcoe_hostlist, list) { |
25024989 | 1869 | if (fcoe->netdev == netdev) { |
619fe4be RL |
1870 | ctlr = fcoe_to_ctlr(fcoe); |
1871 | lport = ctlr->lp; | |
85b4aa49 RL |
1872 | break; |
1873 | } | |
1874 | } | |
1875f27e | 1875 | if (!lport) { |
85b4aa49 RL |
1876 | rc = NOTIFY_DONE; |
1877 | goto out; | |
1878 | } | |
1879 | ||
85b4aa49 RL |
1880 | switch (event) { |
1881 | case NETDEV_DOWN: | |
1882 | case NETDEV_GOING_DOWN: | |
97c8389d | 1883 | link_possible = 0; |
85b4aa49 RL |
1884 | break; |
1885 | case NETDEV_UP: | |
1886 | case NETDEV_CHANGE: | |
85b4aa49 RL |
1887 | break; |
1888 | case NETDEV_CHANGEMTU: | |
7221d7e5 YZ |
1889 | if (netdev->features & NETIF_F_FCOE_MTU) |
1890 | break; | |
1d1b88dc VD |
1891 | mfs = netdev->mtu - (sizeof(struct fcoe_hdr) + |
1892 | sizeof(struct fcoe_crc_eof)); | |
85b4aa49 | 1893 | if (mfs >= FC_MIN_MAX_FRAME) |
1875f27e | 1894 | fc_set_mfs(lport, mfs); |
85b4aa49 RL |
1895 | break; |
1896 | case NETDEV_REGISTER: | |
1897 | break; | |
2e70e241 CL |
1898 | case NETDEV_UNREGISTER: |
1899 | list_del(&fcoe->list); | |
619fe4be | 1900 | port = lport_priv(ctlr->lp); |
7eccdf00 HR |
1901 | fcoe_vport_remove(lport); |
1902 | mutex_lock(&fcoe_config_mutex); | |
1903 | fcoe_if_destroy(lport); | |
1904 | if (!fcoe->removed) | |
1905 | fcoe_interface_remove(fcoe); | |
1906 | fcoe_interface_cleanup(fcoe); | |
1907 | mutex_unlock(&fcoe_config_mutex); | |
1908 | fcoe_ctlr_device_delete(fcoe_ctlr_to_ctlr_dev(ctlr)); | |
2e70e241 CL |
1909 | goto out; |
1910 | break; | |
54a5b21d YZ |
1911 | case NETDEV_FEAT_CHANGE: |
1912 | fcoe_netdev_features_change(lport, netdev); | |
1913 | break; | |
85b4aa49 | 1914 | default: |
1d1b88dc | 1915 | FCOE_NETDEV_DBG(netdev, "Unknown event %ld " |
d5488eb9 | 1916 | "from netdev netlink\n", event); |
85b4aa49 | 1917 | } |
5e4f8fe7 RL |
1918 | |
1919 | fcoe_link_speed_update(lport); | |
1920 | ||
435c8667 RL |
1921 | cdev = fcoe_ctlr_to_ctlr_dev(ctlr); |
1922 | ||
1923 | if (link_possible && !fcoe_link_ok(lport)) { | |
1924 | switch (cdev->enabled) { | |
1925 | case FCOE_CTLR_DISABLED: | |
1926 | pr_info("Link up while interface is disabled.\n"); | |
1927 | break; | |
1928 | case FCOE_CTLR_ENABLED: | |
1929 | case FCOE_CTLR_UNUSED: | |
1930 | fcoe_ctlr_link_up(ctlr); | |
1931 | }; | |
1932 | } else if (fcoe_ctlr_link_down(ctlr)) { | |
1933 | switch (cdev->enabled) { | |
1934 | case FCOE_CTLR_DISABLED: | |
1935 | pr_info("Link down while interface is disabled.\n"); | |
1936 | break; | |
1937 | case FCOE_CTLR_ENABLED: | |
1938 | case FCOE_CTLR_UNUSED: | |
1939 | stats = per_cpu_ptr(lport->stats, get_cpu()); | |
1940 | stats->LinkFailureCount++; | |
1941 | put_cpu(); | |
1942 | fcoe_clean_pending_queue(lport); | |
1943 | }; | |
85b4aa49 RL |
1944 | } |
1945 | out: | |
1946 | return rc; | |
1947 | } | |
1948 | ||
55a66d3c VD |
1949 | /** |
1950 | * fcoe_disable() - Disables a FCoE interface | |
78a58246 | 1951 | * @netdev : The net_device object the Ethernet interface to create on |
55a66d3c | 1952 | * |
78a58246 | 1953 | * Called from fcoe transport. |
55a66d3c VD |
1954 | * |
1955 | * Returns: 0 for success | |
435c8667 RL |
1956 | * |
1957 | * Deprecated: use fcoe_ctlr_enabled() | |
55a66d3c | 1958 | */ |
78a58246 | 1959 | static int fcoe_disable(struct net_device *netdev) |
55a66d3c | 1960 | { |
619fe4be | 1961 | struct fcoe_ctlr *ctlr; |
55a66d3c | 1962 | struct fcoe_interface *fcoe; |
55a66d3c VD |
1963 | int rc = 0; |
1964 | ||
1965 | mutex_lock(&fcoe_config_mutex); | |
55a66d3c | 1966 | |
ee5df628 | 1967 | rtnl_lock(); |
55a66d3c VD |
1968 | fcoe = fcoe_hostlist_lookup_port(netdev); |
1969 | rtnl_unlock(); | |
1970 | ||
9ee50e48 | 1971 | if (fcoe) { |
619fe4be RL |
1972 | ctlr = fcoe_to_ctlr(fcoe); |
1973 | fcoe_ctlr_link_down(ctlr); | |
1974 | fcoe_clean_pending_queue(ctlr->lp); | |
9ee50e48 | 1975 | } else |
55a66d3c VD |
1976 | rc = -ENODEV; |
1977 | ||
55a66d3c VD |
1978 | mutex_unlock(&fcoe_config_mutex); |
1979 | return rc; | |
1980 | } | |
1981 | ||
1982 | /** | |
1983 | * fcoe_enable() - Enables a FCoE interface | |
78a58246 | 1984 | * @netdev : The net_device object the Ethernet interface to create on |
55a66d3c | 1985 | * |
78a58246 | 1986 | * Called from fcoe transport. |
55a66d3c VD |
1987 | * |
1988 | * Returns: 0 for success | |
1989 | */ | |
78a58246 | 1990 | static int fcoe_enable(struct net_device *netdev) |
55a66d3c | 1991 | { |
619fe4be | 1992 | struct fcoe_ctlr *ctlr; |
55a66d3c | 1993 | struct fcoe_interface *fcoe; |
55a66d3c VD |
1994 | int rc = 0; |
1995 | ||
1996 | mutex_lock(&fcoe_config_mutex); | |
ee5df628 | 1997 | rtnl_lock(); |
55a66d3c VD |
1998 | fcoe = fcoe_hostlist_lookup_port(netdev); |
1999 | rtnl_unlock(); | |
2000 | ||
619fe4be | 2001 | if (!fcoe) { |
55a66d3c | 2002 | rc = -ENODEV; |
619fe4be RL |
2003 | goto out; |
2004 | } | |
55a66d3c | 2005 | |
619fe4be RL |
2006 | ctlr = fcoe_to_ctlr(fcoe); |
2007 | ||
2008 | if (!fcoe_link_ok(ctlr->lp)) | |
2009 | fcoe_ctlr_link_up(ctlr); | |
2010 | ||
2011 | out: | |
55a66d3c VD |
2012 | mutex_unlock(&fcoe_config_mutex); |
2013 | return rc; | |
2014 | } | |
2015 | ||
435c8667 RL |
2016 | /** |
2017 | * fcoe_ctlr_enabled() - Enable or disable an FCoE Controller | |
2018 | * @cdev: The FCoE Controller that is being enabled or disabled | |
2019 | * | |
2020 | * fcoe_sysfs will ensure that the state of 'enabled' has | |
2021 | * changed, so no checking is necessary here. This routine simply | |
2022 | * calls fcoe_enable or fcoe_disable, both of which are deprecated. | |
2023 | * When those routines are removed the functionality can be merged | |
2024 | * here. | |
2025 | */ | |
2026 | static int fcoe_ctlr_enabled(struct fcoe_ctlr_device *cdev) | |
2027 | { | |
2028 | struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev); | |
2029 | struct fc_lport *lport = ctlr->lp; | |
2030 | struct net_device *netdev = fcoe_netdev(lport); | |
2031 | ||
2032 | switch (cdev->enabled) { | |
2033 | case FCOE_CTLR_ENABLED: | |
2034 | return fcoe_enable(netdev); | |
2035 | case FCOE_CTLR_DISABLED: | |
2036 | return fcoe_disable(netdev); | |
2037 | case FCOE_CTLR_UNUSED: | |
2038 | default: | |
2039 | return -ENOTSUPP; | |
2040 | }; | |
2041 | } | |
2042 | ||
a87dccc7 HR |
2043 | /** |
2044 | * fcoe_ctlr_mode() - Switch FIP mode | |
2045 | * @cdev: The FCoE Controller that is being modified | |
2046 | * | |
2047 | * When the FIP mode has been changed we need to update | |
2048 | * the multicast addresses to ensure we get the correct | |
2049 | * frames. | |
2050 | */ | |
2051 | static void fcoe_ctlr_mode(struct fcoe_ctlr_device *ctlr_dev) | |
2052 | { | |
2053 | struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev); | |
2054 | struct fcoe_interface *fcoe = fcoe_ctlr_priv(ctlr); | |
2055 | ||
2056 | if (ctlr_dev->mode == FIP_CONN_TYPE_VN2VN && | |
2057 | ctlr->mode != FIP_MODE_VN2VN) { | |
2058 | dev_mc_del(fcoe->netdev, FIP_ALL_ENODE_MACS); | |
2059 | dev_mc_add(fcoe->netdev, FIP_ALL_VN2VN_MACS); | |
2060 | dev_mc_add(fcoe->netdev, FIP_ALL_P2P_MACS); | |
2061 | } else if (ctlr->mode != FIP_MODE_FABRIC) { | |
2062 | dev_mc_del(fcoe->netdev, FIP_ALL_VN2VN_MACS); | |
2063 | dev_mc_del(fcoe->netdev, FIP_ALL_P2P_MACS); | |
2064 | dev_mc_add(fcoe->netdev, FIP_ALL_ENODE_MACS); | |
2065 | } | |
2066 | fcoe_ctlr_set_fip_mode(ctlr_dev); | |
2067 | } | |
2068 | ||
85b4aa49 | 2069 | /** |
1875f27e | 2070 | * fcoe_destroy() - Destroy a FCoE interface |
78a58246 | 2071 | * @netdev : The net_device object the Ethernet interface to create on |
1875f27e | 2072 | * |
78a58246 | 2073 | * Called from fcoe transport |
85b4aa49 RL |
2074 | * |
2075 | * Returns: 0 for success | |
34f42a07 | 2076 | */ |
78a58246 | 2077 | static int fcoe_destroy(struct net_device *netdev) |
85b4aa49 | 2078 | { |
619fe4be | 2079 | struct fcoe_ctlr *ctlr; |
030f4e00 | 2080 | struct fcoe_interface *fcoe; |
f04ca1b6 | 2081 | struct fc_lport *lport; |
b2085a4e | 2082 | struct fcoe_port *port; |
8eca355f | 2083 | int rc = 0; |
85b4aa49 | 2084 | |
dfc1d0fe | 2085 | mutex_lock(&fcoe_config_mutex); |
ee5df628 | 2086 | rtnl_lock(); |
2e70e241 CL |
2087 | fcoe = fcoe_hostlist_lookup_port(netdev); |
2088 | if (!fcoe) { | |
85b4aa49 | 2089 | rc = -ENODEV; |
78a58246 | 2090 | goto out_nodev; |
85b4aa49 | 2091 | } |
619fe4be RL |
2092 | ctlr = fcoe_to_ctlr(fcoe); |
2093 | lport = ctlr->lp; | |
b2085a4e | 2094 | port = lport_priv(lport); |
54a5b21d | 2095 | list_del(&fcoe->list); |
b2085a4e | 2096 | queue_work(fcoe_wq, &port->destroy_work); |
85b4aa49 | 2097 | out_nodev: |
b2085a4e | 2098 | rtnl_unlock(); |
dfc1d0fe | 2099 | mutex_unlock(&fcoe_config_mutex); |
85b4aa49 RL |
2100 | return rc; |
2101 | } | |
2102 | ||
1875f27e RL |
2103 | /** |
2104 | * fcoe_destroy_work() - Destroy a FCoE port in a deferred work context | |
2105 | * @work: Handle to the FCoE port to be destroyed | |
2106 | */ | |
2e70e241 CL |
2107 | static void fcoe_destroy_work(struct work_struct *work) |
2108 | { | |
f9c4358e RL |
2109 | struct fcoe_ctlr_device *cdev; |
2110 | struct fcoe_ctlr *ctlr; | |
2e70e241 | 2111 | struct fcoe_port *port; |
b2085a4e | 2112 | struct fcoe_interface *fcoe; |
2e70e241 CL |
2113 | |
2114 | port = container_of(work, struct fcoe_port, destroy_work); | |
94aa743a | 2115 | |
6f7f74ab | 2116 | fcoe_vport_remove(port->lport); |
94aa743a | 2117 | |
2e70e241 | 2118 | mutex_lock(&fcoe_config_mutex); |
b2085a4e | 2119 | |
b2085a4e | 2120 | fcoe = port->priv; |
f9c4358e RL |
2121 | ctlr = fcoe_to_ctlr(fcoe); |
2122 | cdev = fcoe_ctlr_to_ctlr_dev(ctlr); | |
2123 | ||
9eed785b | 2124 | rtnl_lock(); |
2e70e241 | 2125 | fcoe_if_destroy(port->lport); |
9eed785b HR |
2126 | if (!fcoe->removed) |
2127 | fcoe_interface_remove(fcoe); | |
2128 | rtnl_unlock(); | |
ccefd23e | 2129 | fcoe_interface_cleanup(fcoe); |
b2085a4e | 2130 | |
2e70e241 | 2131 | mutex_unlock(&fcoe_config_mutex); |
f9c4358e RL |
2132 | |
2133 | fcoe_ctlr_device_delete(cdev); | |
2e70e241 CL |
2134 | } |
2135 | ||
78a58246 YZ |
2136 | /** |
2137 | * fcoe_match() - Check if the FCoE is supported on the given netdevice | |
2138 | * @netdev : The net_device object the Ethernet interface to create on | |
2139 | * | |
2140 | * Called from fcoe transport. | |
2141 | * | |
2142 | * Returns: always returns true as this is the default FCoE transport, | |
2143 | * i.e., support all netdevs. | |
2144 | */ | |
2145 | static bool fcoe_match(struct net_device *netdev) | |
2146 | { | |
2147 | return true; | |
2148 | } | |
2149 | ||
6f6c2aa3 | 2150 | /** |
2151 | * fcoe_dcb_create() - Initialize DCB attributes and hooks | |
2152 | * @netdev: The net_device object of the L2 link that should be queried | |
2153 | * @port: The fcoe_port to bind FCoE APP priority with | |
2154 | * @ | |
2155 | */ | |
2156 | static void fcoe_dcb_create(struct fcoe_interface *fcoe) | |
2157 | { | |
c216e876 HR |
2158 | int ctlr_prio = TC_PRIO_BESTEFFORT; |
2159 | int fcoe_prio = TC_PRIO_INTERACTIVE; | |
c5969656 | 2160 | struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe); |
6f6c2aa3 | 2161 | #ifdef CONFIG_DCB |
2162 | int dcbx; | |
2163 | u8 fup, up; | |
2164 | struct net_device *netdev = fcoe->realdev; | |
6f6c2aa3 | 2165 | struct dcb_app app = { |
2166 | .priority = 0, | |
2167 | .protocol = ETH_P_FCOE | |
2168 | }; | |
2169 | ||
2170 | /* setup DCB priority attributes. */ | |
2171 | if (netdev && netdev->dcbnl_ops && netdev->dcbnl_ops->getdcbx) { | |
2172 | dcbx = netdev->dcbnl_ops->getdcbx(netdev); | |
2173 | ||
2174 | if (dcbx & DCB_CAP_DCBX_VER_IEEE) { | |
2175 | app.selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE; | |
2176 | up = dcb_ieee_getapp_mask(netdev, &app); | |
2177 | app.protocol = ETH_P_FIP; | |
2178 | fup = dcb_ieee_getapp_mask(netdev, &app); | |
2179 | } else { | |
2180 | app.selector = DCB_APP_IDTYPE_ETHTYPE; | |
2181 | up = dcb_getapp(netdev, &app); | |
2182 | app.protocol = ETH_P_FIP; | |
2183 | fup = dcb_getapp(netdev, &app); | |
2184 | } | |
2185 | ||
c216e876 HR |
2186 | fcoe_prio = ffs(up) ? ffs(up) - 1 : 0; |
2187 | ctlr_prio = ffs(fup) ? ffs(fup) - 1 : fcoe_prio; | |
6f6c2aa3 | 2188 | } |
2189 | #endif | |
c216e876 HR |
2190 | fcoe->priority = fcoe_prio; |
2191 | ctlr->priority = ctlr_prio; | |
6f6c2aa3 | 2192 | } |
2193 | ||
435c8667 RL |
2194 | enum fcoe_create_link_state { |
2195 | FCOE_CREATE_LINK_DOWN, | |
2196 | FCOE_CREATE_LINK_UP, | |
2197 | }; | |
2198 | ||
85b4aa49 | 2199 | /** |
435c8667 RL |
2200 | * _fcoe_create() - (internal) Create a fcoe interface |
2201 | * @netdev : The net_device object the Ethernet interface to create on | |
2202 | * @fip_mode: The FIP mode for this creation | |
2203 | * @link_state: The ctlr link state on creation | |
1875f27e | 2204 | * |
435c8667 RL |
2205 | * Called from either the libfcoe 'create' module parameter |
2206 | * via fcoe_create or from fcoe_syfs's ctlr_create file. | |
85b4aa49 | 2207 | * |
435c8667 RL |
2208 | * libfcoe's 'create' module parameter is deprecated so some |
2209 | * consolidation of code can be done when that interface is | |
2210 | * removed. | |
34f42a07 | 2211 | */ |
1917d42d | 2212 | static int _fcoe_create(struct net_device *netdev, enum fip_mode fip_mode, |
435c8667 | 2213 | enum fcoe_create_link_state link_state) |
85b4aa49 | 2214 | { |
b2085a4e | 2215 | int rc = 0; |
8d55e507 | 2216 | struct fcoe_ctlr_device *ctlr_dev; |
619fe4be | 2217 | struct fcoe_ctlr *ctlr; |
030f4e00 | 2218 | struct fcoe_interface *fcoe; |
af7f85d9 | 2219 | struct fc_lport *lport; |
85b4aa49 | 2220 | |
dfc1d0fe | 2221 | mutex_lock(&fcoe_config_mutex); |
ee5df628 | 2222 | rtnl_lock(); |
34ce27bc | 2223 | |
85b4aa49 RL |
2224 | /* look for existing lport */ |
2225 | if (fcoe_hostlist_lookup(netdev)) { | |
2226 | rc = -EEXIST; | |
78a58246 | 2227 | goto out_nodev; |
85b4aa49 | 2228 | } |
85b4aa49 | 2229 | |
1dd454d9 | 2230 | fcoe = fcoe_interface_create(netdev, fip_mode); |
7287fb91 RL |
2231 | if (IS_ERR(fcoe)) { |
2232 | rc = PTR_ERR(fcoe); | |
78a58246 | 2233 | goto out_nodev; |
030f4e00 CL |
2234 | } |
2235 | ||
619fe4be | 2236 | ctlr = fcoe_to_ctlr(fcoe); |
8d55e507 RL |
2237 | ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr); |
2238 | lport = fcoe_if_create(fcoe, &ctlr_dev->dev, 0); | |
af7f85d9 | 2239 | if (IS_ERR(lport)) { |
d5488eb9 | 2240 | printk(KERN_ERR "fcoe: Failed to create interface (%s)\n", |
85b4aa49 | 2241 | netdev->name); |
85b4aa49 | 2242 | rc = -EIO; |
9eed785b HR |
2243 | if (!fcoe->removed) |
2244 | fcoe_interface_remove(fcoe); | |
848e7d5b | 2245 | rtnl_unlock(); |
2e70e241 | 2246 | fcoe_interface_cleanup(fcoe); |
f9c4358e RL |
2247 | mutex_unlock(&fcoe_config_mutex); |
2248 | fcoe_ctlr_device_delete(ctlr_dev); | |
3011b482 | 2249 | return rc; |
85b4aa49 | 2250 | } |
030f4e00 | 2251 | |
54b649f8 | 2252 | /* Make this the "master" N_Port */ |
619fe4be | 2253 | ctlr->lp = lport; |
54b649f8 | 2254 | |
6f6c2aa3 | 2255 | /* setup DCB priority attributes. */ |
2256 | fcoe_dcb_create(fcoe); | |
2257 | ||
54b649f8 CL |
2258 | /* start FIP Discovery and FLOGI */ |
2259 | lport->boot_time = jiffies; | |
2260 | fc_fabric_login(lport); | |
435c8667 RL |
2261 | |
2262 | /* | |
2263 | * If the fcoe_ctlr_device is to be set to DISABLED | |
2264 | * it must be done after the lport is added to the | |
2265 | * hostlist, but before the rtnl_lock is released. | |
2266 | * This is because the rtnl_lock protects the | |
2267 | * hostlist that fcoe_device_notification uses. If | |
2268 | * the FCoE Controller is intended to be created | |
2269 | * DISABLED then 'enabled' needs to be considered | |
2270 | * handling link events. 'enabled' must be set | |
2271 | * before the lport can be found in the hostlist | |
2272 | * when a link up event is received. | |
2273 | */ | |
2274 | if (link_state == FCOE_CREATE_LINK_UP) | |
2275 | ctlr_dev->enabled = FCOE_CTLR_ENABLED; | |
2276 | else | |
2277 | ctlr_dev->enabled = FCOE_CTLR_DISABLED; | |
2278 | ||
2279 | if (link_state == FCOE_CREATE_LINK_UP && | |
2280 | !fcoe_link_ok(lport)) { | |
22805123 | 2281 | rtnl_unlock(); |
619fe4be | 2282 | fcoe_ctlr_link_up(ctlr); |
22805123 RL |
2283 | mutex_unlock(&fcoe_config_mutex); |
2284 | return rc; | |
2285 | } | |
030f4e00 | 2286 | |
85b4aa49 | 2287 | out_nodev: |
34ce27bc | 2288 | rtnl_unlock(); |
dfc1d0fe | 2289 | mutex_unlock(&fcoe_config_mutex); |
3011b482 | 2290 | |
85b4aa49 RL |
2291 | return rc; |
2292 | } | |
2293 | ||
435c8667 RL |
2294 | /** |
2295 | * fcoe_create() - Create a fcoe interface | |
2296 | * @netdev : The net_device object the Ethernet interface to create on | |
2297 | * @fip_mode: The FIP mode for this creation | |
2298 | * | |
2299 | * Called from fcoe transport | |
2300 | * | |
2301 | * Returns: 0 for success | |
2302 | */ | |
1917d42d | 2303 | static int fcoe_create(struct net_device *netdev, enum fip_mode fip_mode) |
435c8667 RL |
2304 | { |
2305 | return _fcoe_create(netdev, fip_mode, FCOE_CREATE_LINK_UP); | |
2306 | } | |
2307 | ||
2308 | /** | |
2309 | * fcoe_ctlr_alloc() - Allocate a fcoe interface from fcoe_sysfs | |
2310 | * @netdev: The net_device to be used by the allocated FCoE Controller | |
2311 | * | |
2312 | * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr | |
2313 | * in a link_down state. The allows the user an opportunity to configure | |
2314 | * the FCoE Controller from sysfs before enabling the FCoE Controller. | |
2315 | * | |
2316 | * Creating in with this routine starts the FCoE Controller in Fabric | |
2317 | * mode. The user can change to VN2VN or another mode before enabling. | |
2318 | */ | |
2319 | static int fcoe_ctlr_alloc(struct net_device *netdev) | |
2320 | { | |
2321 | return _fcoe_create(netdev, FIP_MODE_FABRIC, | |
2322 | FCOE_CREATE_LINK_DOWN); | |
2323 | } | |
2324 | ||
5e4f8fe7 RL |
2325 | /** |
2326 | * fcoe_link_ok() - Check if the link is OK for a local port | |
2327 | * @lport: The local port to check link on | |
2328 | * | |
2329 | * Returns: 0 if link is UP and OK, -1 if not | |
2330 | * | |
2331 | */ | |
7c9c6841 | 2332 | static int fcoe_link_ok(struct fc_lport *lport) |
5e4f8fe7 | 2333 | { |
8597ae8b | 2334 | struct net_device *netdev = fcoe_netdev(lport); |
5e4f8fe7 RL |
2335 | |
2336 | if (netif_oper_up(netdev)) | |
2337 | return 0; | |
2338 | return -1; | |
2339 | } | |
2340 | ||
34f42a07 | 2341 | /** |
1875f27e RL |
2342 | * fcoe_percpu_clean() - Clear all pending skbs for an local port |
2343 | * @lport: The local port whose skbs are to be cleared | |
e7a51997 JE |
2344 | * |
2345 | * Must be called with fcoe_create_mutex held to single-thread completion. | |
2346 | * | |
4b9bc86d SAS |
2347 | * This flushes the pending skbs by flush the work item for each CPU. The work |
2348 | * item on each possible CPU is flushed because we may have used the per-CPU | |
2349 | * struct of an offline CPU. | |
85b4aa49 | 2350 | */ |
7c9c6841 | 2351 | static void fcoe_percpu_clean(struct fc_lport *lport) |
85b4aa49 | 2352 | { |
85b4aa49 | 2353 | struct fcoe_percpu_s *pp; |
5e5e92df | 2354 | unsigned int cpu; |
85b4aa49 | 2355 | |
5e5e92df RL |
2356 | for_each_possible_cpu(cpu) { |
2357 | pp = &per_cpu(fcoe_percpu, cpu); | |
e7a51997 | 2358 | |
4b9bc86d | 2359 | flush_work(&pp->work); |
85b4aa49 RL |
2360 | } |
2361 | } | |
85b4aa49 | 2362 | |
34f42a07 | 2363 | /** |
1875f27e RL |
2364 | * fcoe_reset() - Reset a local port |
2365 | * @shost: The SCSI host associated with the local port to be reset | |
85b4aa49 | 2366 | * |
1875f27e | 2367 | * Returns: Always 0 (return value required by FC transport template) |
85b4aa49 | 2368 | */ |
7c9c6841 | 2369 | static int fcoe_reset(struct Scsi_Host *shost) |
85b4aa49 RL |
2370 | { |
2371 | struct fc_lport *lport = shost_priv(shost); | |
d2f80952 VD |
2372 | struct fcoe_port *port = lport_priv(lport); |
2373 | struct fcoe_interface *fcoe = port->priv; | |
619fe4be | 2374 | struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe); |
435c8667 | 2375 | struct fcoe_ctlr_device *cdev = fcoe_ctlr_to_ctlr_dev(ctlr); |
d2f80952 | 2376 | |
619fe4be RL |
2377 | fcoe_ctlr_link_down(ctlr); |
2378 | fcoe_clean_pending_queue(ctlr->lp); | |
435c8667 RL |
2379 | |
2380 | if (cdev->enabled != FCOE_CTLR_DISABLED && | |
2381 | !fcoe_link_ok(ctlr->lp)) | |
619fe4be | 2382 | fcoe_ctlr_link_up(ctlr); |
85b4aa49 RL |
2383 | return 0; |
2384 | } | |
85b4aa49 | 2385 | |
34f42a07 | 2386 | /** |
1875f27e RL |
2387 | * fcoe_hostlist_lookup_port() - Find the FCoE interface associated with a net device |
2388 | * @netdev: The net device used as a key | |
85b4aa49 | 2389 | * |
1875f27e RL |
2390 | * Locking: Must be called with the RNL mutex held. |
2391 | * | |
2392 | * Returns: NULL or the FCoE interface | |
85b4aa49 | 2393 | */ |
014f5c3f | 2394 | static struct fcoe_interface * |
1875f27e | 2395 | fcoe_hostlist_lookup_port(const struct net_device *netdev) |
85b4aa49 | 2396 | { |
014f5c3f | 2397 | struct fcoe_interface *fcoe; |
85b4aa49 | 2398 | |
014f5c3f | 2399 | list_for_each_entry(fcoe, &fcoe_hostlist, list) { |
1875f27e | 2400 | if (fcoe->netdev == netdev) |
014f5c3f | 2401 | return fcoe; |
85b4aa49 | 2402 | } |
85b4aa49 RL |
2403 | return NULL; |
2404 | } | |
2405 | ||
34f42a07 | 2406 | /** |
1875f27e RL |
2407 | * fcoe_hostlist_lookup() - Find the local port associated with a |
2408 | * given net device | |
2409 | * @netdev: The netdevice used as a key | |
85b4aa49 | 2410 | * |
1875f27e RL |
2411 | * Locking: Must be called with the RTNL mutex held |
2412 | * | |
2413 | * Returns: NULL or the local port | |
85b4aa49 | 2414 | */ |
090eb6c4 | 2415 | static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev) |
85b4aa49 | 2416 | { |
619fe4be | 2417 | struct fcoe_ctlr *ctlr; |
014f5c3f | 2418 | struct fcoe_interface *fcoe; |
85b4aa49 | 2419 | |
014f5c3f | 2420 | fcoe = fcoe_hostlist_lookup_port(netdev); |
619fe4be RL |
2421 | ctlr = fcoe_to_ctlr(fcoe); |
2422 | return (fcoe) ? ctlr->lp : NULL; | |
85b4aa49 | 2423 | } |
85b4aa49 | 2424 | |
34f42a07 | 2425 | /** |
1875f27e RL |
2426 | * fcoe_hostlist_add() - Add the FCoE interface identified by a local |
2427 | * port to the hostlist | |
2428 | * @lport: The local port that identifies the FCoE interface to be added | |
85b4aa49 | 2429 | * |
090eb6c4 | 2430 | * Locking: must be called with the RTNL mutex held |
1875f27e RL |
2431 | * |
2432 | * Returns: 0 for success | |
85b4aa49 | 2433 | */ |
090eb6c4 | 2434 | static int fcoe_hostlist_add(const struct fc_lport *lport) |
85b4aa49 | 2435 | { |
014f5c3f CL |
2436 | struct fcoe_interface *fcoe; |
2437 | struct fcoe_port *port; | |
2438 | ||
2439 | fcoe = fcoe_hostlist_lookup_port(fcoe_netdev(lport)); | |
2440 | if (!fcoe) { | |
2441 | port = lport_priv(lport); | |
8597ae8b | 2442 | fcoe = port->priv; |
014f5c3f | 2443 | list_add_tail(&fcoe->list, &fcoe_hostlist); |
85b4aa49 RL |
2444 | } |
2445 | return 0; | |
2446 | } | |
85b4aa49 | 2447 | |
f9184df3 NH |
2448 | /** |
2449 | * fcoe_hostlist_del() - Remove the FCoE interface identified by a local | |
2450 | * port to the hostlist | |
2451 | * @lport: The local port that identifies the FCoE interface to be added | |
2452 | * | |
2453 | * Locking: must be called with the RTNL mutex held | |
2454 | * | |
2455 | */ | |
2456 | static void fcoe_hostlist_del(const struct fc_lport *lport) | |
2457 | { | |
2458 | struct fcoe_interface *fcoe; | |
2459 | struct fcoe_port *port; | |
2460 | ||
2461 | port = lport_priv(lport); | |
2462 | fcoe = port->priv; | |
2463 | list_del(&fcoe->list); | |
2464 | return; | |
2465 | } | |
78a58246 YZ |
2466 | |
2467 | static struct fcoe_transport fcoe_sw_transport = { | |
2468 | .name = {FCOE_TRANSPORT_DEFAULT}, | |
2469 | .attached = false, | |
2470 | .list = LIST_HEAD_INIT(fcoe_sw_transport.list), | |
2471 | .match = fcoe_match, | |
435c8667 | 2472 | .alloc = fcoe_ctlr_alloc, |
78a58246 YZ |
2473 | .create = fcoe_create, |
2474 | .destroy = fcoe_destroy, | |
2475 | .enable = fcoe_enable, | |
2476 | .disable = fcoe_disable, | |
2477 | }; | |
2478 | ||
85b4aa49 | 2479 | /** |
1875f27e | 2480 | * fcoe_init() - Initialize fcoe.ko |
85b4aa49 | 2481 | * |
1875f27e | 2482 | * Returns: 0 on success, or a negative value on failure |
34f42a07 | 2483 | */ |
85b4aa49 RL |
2484 | static int __init fcoe_init(void) |
2485 | { | |
1875f27e | 2486 | struct fcoe_percpu_s *p; |
38eccabd | 2487 | unsigned int cpu; |
8976f424 | 2488 | int rc = 0; |
85b4aa49 | 2489 | |
2ca32b48 TH |
2490 | fcoe_wq = alloc_workqueue("fcoe", 0, 0); |
2491 | if (!fcoe_wq) | |
2492 | return -ENOMEM; | |
2493 | ||
78a58246 YZ |
2494 | /* register as a fcoe transport */ |
2495 | rc = fcoe_transport_attach(&fcoe_sw_transport); | |
2496 | if (rc) { | |
2497 | printk(KERN_ERR "failed to register an fcoe transport, check " | |
2498 | "if libfcoe is loaded\n"); | |
a561a8ea | 2499 | goto out_destroy; |
78a58246 YZ |
2500 | } |
2501 | ||
dfc1d0fe CL |
2502 | mutex_lock(&fcoe_config_mutex); |
2503 | ||
38eccabd | 2504 | for_each_possible_cpu(cpu) { |
4b9bc86d SAS |
2505 | p = per_cpu_ptr(&fcoe_percpu, cpu); |
2506 | INIT_WORK(&p->work, fcoe_receive_work); | |
38eccabd RL |
2507 | skb_queue_head_init(&p->fcoe_rx_list); |
2508 | } | |
2509 | ||
8976f424 | 2510 | /* Setup link change notification */ |
85b4aa49 RL |
2511 | fcoe_dev_setup(); |
2512 | ||
5892c32f CL |
2513 | rc = fcoe_if_init(); |
2514 | if (rc) | |
2515 | goto out_free; | |
85b4aa49 | 2516 | |
dfc1d0fe | 2517 | mutex_unlock(&fcoe_config_mutex); |
85b4aa49 | 2518 | return 0; |
8976f424 RL |
2519 | |
2520 | out_free: | |
dfc1d0fe | 2521 | mutex_unlock(&fcoe_config_mutex); |
a561a8ea | 2522 | out_destroy: |
2ca32b48 | 2523 | destroy_workqueue(fcoe_wq); |
8976f424 | 2524 | return rc; |
85b4aa49 RL |
2525 | } |
2526 | module_init(fcoe_init); | |
2527 | ||
2528 | /** | |
1875f27e | 2529 | * fcoe_exit() - Clean up fcoe.ko |
85b4aa49 | 2530 | * |
1875f27e | 2531 | * Returns: 0 on success or a negative value on failure |
34f42a07 | 2532 | */ |
85b4aa49 RL |
2533 | static void __exit fcoe_exit(void) |
2534 | { | |
014f5c3f | 2535 | struct fcoe_interface *fcoe, *tmp; |
619fe4be | 2536 | struct fcoe_ctlr *ctlr; |
2e70e241 | 2537 | struct fcoe_port *port; |
1875f27e | 2538 | unsigned int cpu; |
85b4aa49 | 2539 | |
dfc1d0fe CL |
2540 | mutex_lock(&fcoe_config_mutex); |
2541 | ||
85b4aa49 RL |
2542 | fcoe_dev_cleanup(); |
2543 | ||
5919a595 | 2544 | /* releases the associated fcoe hosts */ |
090eb6c4 CL |
2545 | rtnl_lock(); |
2546 | list_for_each_entry_safe(fcoe, tmp, &fcoe_hostlist, list) { | |
619fe4be RL |
2547 | ctlr = fcoe_to_ctlr(fcoe); |
2548 | port = lport_priv(ctlr->lp); | |
f9184df3 | 2549 | fcoe_hostlist_del(port->lport); |
2ca32b48 | 2550 | queue_work(fcoe_wq, &port->destroy_work); |
c863df33 | 2551 | } |
090eb6c4 | 2552 | rtnl_unlock(); |
85b4aa49 | 2553 | |
4b9bc86d SAS |
2554 | for_each_possible_cpu(cpu) |
2555 | fcoe_thread_cleanup_local(cpu); | |
cd45ae38 | 2556 | |
dfc1d0fe | 2557 | mutex_unlock(&fcoe_config_mutex); |
2e70e241 | 2558 | |
2ca32b48 TH |
2559 | /* |
2560 | * destroy_work's may be chained but destroy_workqueue() | |
2561 | * can take care of them. Just kill the fcoe_wq. | |
2562 | */ | |
2563 | destroy_workqueue(fcoe_wq); | |
2e70e241 | 2564 | |
2ca32b48 TH |
2565 | /* |
2566 | * Detaching from the scsi transport must happen after all | |
2567 | * destroys are done on the fcoe_wq. destroy_workqueue will | |
2568 | * enusre the fcoe_wq is flushed. | |
2569 | */ | |
2e70e241 | 2570 | fcoe_if_exit(); |
78a58246 YZ |
2571 | |
2572 | /* detach from fcoe transport */ | |
2573 | fcoe_transport_detach(&fcoe_sw_transport); | |
85b4aa49 RL |
2574 | } |
2575 | module_exit(fcoe_exit); | |
11b56188 CL |
2576 | |
2577 | /** | |
2578 | * fcoe_flogi_resp() - FCoE specific FLOGI and FDISC response handler | |
2579 | * @seq: active sequence in the FLOGI or FDISC exchange | |
2580 | * @fp: response frame, or error encoded in a pointer (timeout) | |
78cfe97f | 2581 | * @arg: pointer to the fcoe_ctlr structure |
11b56188 | 2582 | * |
65155b37 | 2583 | * This handles MAC address management for FCoE, then passes control on to |
11b56188 CL |
2584 | * the libfc FLOGI response handler. |
2585 | */ | |
2586 | static void fcoe_flogi_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) | |
2587 | { | |
2588 | struct fcoe_ctlr *fip = arg; | |
2589 | struct fc_exch *exch = fc_seq_exch(seq); | |
2590 | struct fc_lport *lport = exch->lp; | |
2591 | u8 *mac; | |
2592 | ||
2593 | if (IS_ERR(fp)) | |
2594 | goto done; | |
2595 | ||
2596 | mac = fr_cb(fp)->granted_mac; | |
907c07d4 VD |
2597 | /* pre-FIP */ |
2598 | if (is_zero_ether_addr(mac)) | |
2599 | fcoe_ctlr_recv_flogi(fip, lport, fp); | |
2600 | if (!is_zero_ether_addr(mac)) | |
2601 | fcoe_update_src_mac(lport, mac); | |
11b56188 CL |
2602 | done: |
2603 | fc_lport_flogi_resp(seq, fp, lport); | |
2604 | } | |
2605 | ||
2606 | /** | |
2607 | * fcoe_logo_resp() - FCoE specific LOGO response handler | |
2608 | * @seq: active sequence in the LOGO exchange | |
2609 | * @fp: response frame, or error encoded in a pointer (timeout) | |
78cfe97f | 2610 | * @arg: pointer to the fcoe_ctlr structure |
11b56188 | 2611 | * |
65155b37 | 2612 | * This handles MAC address management for FCoE, then passes control on to |
11b56188 CL |
2613 | * the libfc LOGO response handler. |
2614 | */ | |
2615 | static void fcoe_logo_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) | |
2616 | { | |
386309ce | 2617 | struct fc_lport *lport = arg; |
11b56188 CL |
2618 | static u8 zero_mac[ETH_ALEN] = { 0 }; |
2619 | ||
2620 | if (!IS_ERR(fp)) | |
386309ce | 2621 | fcoe_update_src_mac(lport, zero_mac); |
11b56188 CL |
2622 | fc_lport_logo_resp(seq, fp, lport); |
2623 | } | |
2624 | ||
2625 | /** | |
2626 | * fcoe_elsct_send - FCoE specific ELS handler | |
2627 | * | |
2628 | * This does special case handling of FIP encapsualted ELS exchanges for FCoE, | |
2629 | * using FCoE specific response handlers and passing the FIP controller as | |
2630 | * the argument (the lport is still available from the exchange). | |
2631 | * | |
2632 | * Most of the work here is just handed off to the libfc routine. | |
2633 | */ | |
1875f27e RL |
2634 | static struct fc_seq *fcoe_elsct_send(struct fc_lport *lport, u32 did, |
2635 | struct fc_frame *fp, unsigned int op, | |
2636 | void (*resp)(struct fc_seq *, | |
2637 | struct fc_frame *, | |
2638 | void *), | |
2639 | void *arg, u32 timeout) | |
11b56188 CL |
2640 | { |
2641 | struct fcoe_port *port = lport_priv(lport); | |
8597ae8b | 2642 | struct fcoe_interface *fcoe = port->priv; |
619fe4be | 2643 | struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe); |
11b56188 CL |
2644 | struct fc_frame_header *fh = fc_frame_header_get(fp); |
2645 | ||
2646 | switch (op) { | |
2647 | case ELS_FLOGI: | |
2648 | case ELS_FDISC: | |
e10f8c66 JE |
2649 | if (lport->point_to_multipoint) |
2650 | break; | |
11b56188 CL |
2651 | return fc_elsct_send(lport, did, fp, op, fcoe_flogi_resp, |
2652 | fip, timeout); | |
2653 | case ELS_LOGO: | |
2654 | /* only hook onto fabric logouts, not port logouts */ | |
2655 | if (ntoh24(fh->fh_d_id) != FC_FID_FLOGI) | |
2656 | break; | |
2657 | return fc_elsct_send(lport, did, fp, op, fcoe_logo_resp, | |
386309ce | 2658 | lport, timeout); |
11b56188 CL |
2659 | } |
2660 | return fc_elsct_send(lport, did, fp, op, resp, arg, timeout); | |
2661 | } | |
2662 | ||
9a05753b CL |
2663 | /** |
2664 | * fcoe_vport_create() - create an fc_host/scsi_host for a vport | |
2665 | * @vport: fc_vport object to create a new fc_host for | |
2666 | * @disabled: start the new fc_host in a disabled state by default? | |
2667 | * | |
2668 | * Returns: 0 for success | |
2669 | */ | |
2670 | static int fcoe_vport_create(struct fc_vport *vport, bool disabled) | |
2671 | { | |
2672 | struct Scsi_Host *shost = vport_to_shost(vport); | |
2673 | struct fc_lport *n_port = shost_priv(shost); | |
2674 | struct fcoe_port *port = lport_priv(n_port); | |
8597ae8b | 2675 | struct fcoe_interface *fcoe = port->priv; |
9a05753b CL |
2676 | struct net_device *netdev = fcoe->netdev; |
2677 | struct fc_lport *vn_port; | |
bdf25218 NP |
2678 | int rc; |
2679 | char buf[32]; | |
2680 | ||
2681 | rc = fcoe_validate_vport_create(vport); | |
2682 | if (rc) { | |
d834895c | 2683 | fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf)); |
bdf25218 NP |
2684 | printk(KERN_ERR "fcoe: Failed to create vport, " |
2685 | "WWPN (0x%s) already exists\n", | |
2686 | buf); | |
2687 | return rc; | |
2688 | } | |
9a05753b CL |
2689 | |
2690 | mutex_lock(&fcoe_config_mutex); | |
4bc71cb9 | 2691 | rtnl_lock(); |
9a05753b | 2692 | vn_port = fcoe_if_create(fcoe, &vport->dev, 1); |
4bc71cb9 | 2693 | rtnl_unlock(); |
9a05753b CL |
2694 | mutex_unlock(&fcoe_config_mutex); |
2695 | ||
2696 | if (IS_ERR(vn_port)) { | |
2697 | printk(KERN_ERR "fcoe: fcoe_vport_create(%s) failed\n", | |
2698 | netdev->name); | |
2699 | return -EIO; | |
2700 | } | |
2701 | ||
2702 | if (disabled) { | |
2703 | fc_vport_set_state(vport, FC_VPORT_DISABLED); | |
2704 | } else { | |
2705 | vn_port->boot_time = jiffies; | |
2706 | fc_fabric_login(vn_port); | |
2707 | fc_vport_setlink(vn_port); | |
2708 | } | |
2709 | return 0; | |
2710 | } | |
2711 | ||
2712 | /** | |
2713 | * fcoe_vport_destroy() - destroy the fc_host/scsi_host for a vport | |
2714 | * @vport: fc_vport object that is being destroyed | |
2715 | * | |
2716 | * Returns: 0 for success | |
2717 | */ | |
2718 | static int fcoe_vport_destroy(struct fc_vport *vport) | |
2719 | { | |
2720 | struct Scsi_Host *shost = vport_to_shost(vport); | |
2721 | struct fc_lport *n_port = shost_priv(shost); | |
2722 | struct fc_lport *vn_port = vport->dd_data; | |
9a05753b CL |
2723 | |
2724 | mutex_lock(&n_port->lp_mutex); | |
2725 | list_del(&vn_port->list); | |
2726 | mutex_unlock(&n_port->lp_mutex); | |
ccefd23e RL |
2727 | |
2728 | mutex_lock(&fcoe_config_mutex); | |
7eccdf00 | 2729 | rtnl_lock(); |
ccefd23e | 2730 | fcoe_if_destroy(vn_port); |
7eccdf00 | 2731 | rtnl_unlock(); |
ccefd23e RL |
2732 | mutex_unlock(&fcoe_config_mutex); |
2733 | ||
9a05753b CL |
2734 | return 0; |
2735 | } | |
2736 | ||
6f7f74ab HR |
2737 | /** |
2738 | * fcoe_vport_remove() - remove attached vports | |
2739 | * @lport: lport for which the vports should be removed | |
2740 | */ | |
2741 | static void fcoe_vport_remove(struct fc_lport *lport) | |
2742 | { | |
2743 | struct Scsi_Host *shost; | |
2744 | struct fc_host_attrs *fc_host; | |
2745 | unsigned long flags; | |
2746 | struct fc_vport *vport; | |
2747 | struct fc_vport *next_vport; | |
2748 | ||
2749 | shost = lport->host; | |
2750 | fc_host = shost_to_fc_host(shost); | |
2751 | ||
2752 | /* Loop through all the vports and mark them for deletion */ | |
2753 | spin_lock_irqsave(shost->host_lock, flags); | |
2754 | list_for_each_entry_safe(vport, next_vport, &fc_host->vports, peers) { | |
2755 | if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) { | |
2756 | continue; | |
2757 | } else { | |
2758 | vport->flags |= FC_VPORT_DELETING; | |
2759 | queue_work(fc_host_work_q(shost), | |
2760 | &vport->vport_delete_work); | |
2761 | } | |
2762 | } | |
2763 | spin_unlock_irqrestore(shost->host_lock, flags); | |
2764 | ||
2765 | flush_workqueue(fc_host_work_q(shost)); | |
2766 | } | |
2767 | ||
9a05753b CL |
2768 | /** |
2769 | * fcoe_vport_disable() - change vport state | |
2770 | * @vport: vport to bring online/offline | |
2771 | * @disable: should the vport be disabled? | |
2772 | */ | |
2773 | static int fcoe_vport_disable(struct fc_vport *vport, bool disable) | |
2774 | { | |
2775 | struct fc_lport *lport = vport->dd_data; | |
2776 | ||
2777 | if (disable) { | |
2778 | fc_vport_set_state(vport, FC_VPORT_DISABLED); | |
2779 | fc_fabric_logoff(lport); | |
2780 | } else { | |
2781 | lport->boot_time = jiffies; | |
2782 | fc_fabric_login(lport); | |
2783 | fc_vport_setlink(lport); | |
2784 | } | |
2785 | ||
2786 | return 0; | |
2787 | } | |
2788 | ||
dc8596d3 CL |
2789 | /** |
2790 | * fcoe_vport_set_symbolic_name() - append vport string to symbolic name | |
2791 | * @vport: fc_vport with a new symbolic name string | |
2792 | * | |
2793 | * After generating a new symbolic name string, a new RSPN_ID request is | |
2794 | * sent to the name server. There is no response handler, so if it fails | |
2795 | * for some reason it will not be retried. | |
2796 | */ | |
2797 | static void fcoe_set_vport_symbolic_name(struct fc_vport *vport) | |
2798 | { | |
2799 | struct fc_lport *lport = vport->dd_data; | |
2800 | struct fc_frame *fp; | |
2801 | size_t len; | |
2802 | ||
2803 | snprintf(fc_host_symbolic_name(lport->host), FC_SYMBOLIC_NAME_SIZE, | |
2804 | "%s v%s over %s : %s", FCOE_NAME, FCOE_VERSION, | |
2805 | fcoe_netdev(lport)->name, vport->symbolic_name); | |
2806 | ||
2807 | if (lport->state != LPORT_ST_READY) | |
2808 | return; | |
2809 | ||
2810 | len = strnlen(fc_host_symbolic_name(lport->host), 255); | |
2811 | fp = fc_frame_alloc(lport, | |
2812 | sizeof(struct fc_ct_hdr) + | |
2813 | sizeof(struct fc_ns_rspn) + len); | |
2814 | if (!fp) | |
2815 | return; | |
2816 | lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, FC_NS_RSPN_ID, | |
b94f8951 | 2817 | NULL, NULL, 3 * lport->r_a_tov); |
dc8596d3 | 2818 | } |
b84056bf | 2819 | |
8d55e507 RL |
2820 | static void fcoe_fcf_get_vlan_id(struct fcoe_fcf_device *fcf_dev) |
2821 | { | |
2822 | struct fcoe_ctlr_device *ctlr_dev = | |
2823 | fcoe_fcf_dev_to_ctlr_dev(fcf_dev); | |
2824 | struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev); | |
2825 | struct fcoe_interface *fcoe = fcoe_ctlr_priv(ctlr); | |
2826 | ||
2827 | fcf_dev->vlan_id = vlan_dev_vlan_id(fcoe->netdev); | |
2828 | } | |
2829 | ||
7d65b0df JE |
2830 | /** |
2831 | * fcoe_set_port_id() - Callback from libfc when Port_ID is set. | |
2832 | * @lport: the local port | |
2833 | * @port_id: the port ID | |
2834 | * @fp: the received frame, if any, that caused the port_id to be set. | |
2835 | * | |
2836 | * This routine handles the case where we received a FLOGI and are | |
2837 | * entering point-to-point mode. We need to call fcoe_ctlr_recv_flogi() | |
2838 | * so it can set the non-mapped mode and gateway address. | |
2839 | * | |
2840 | * The FLOGI LS_ACC is handled by fcoe_flogi_resp(). | |
2841 | */ | |
2842 | static void fcoe_set_port_id(struct fc_lport *lport, | |
2843 | u32 port_id, struct fc_frame *fp) | |
2844 | { | |
2845 | struct fcoe_port *port = lport_priv(lport); | |
8597ae8b | 2846 | struct fcoe_interface *fcoe = port->priv; |
619fe4be | 2847 | struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe); |
7d65b0df JE |
2848 | |
2849 | if (fp && fc_frame_payload_op(fp) == ELS_FLOGI) | |
619fe4be | 2850 | fcoe_ctlr_recv_flogi(ctlr, lport, fp); |
7d65b0df | 2851 | } |