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