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