blob: 4bb42e19d53767c779f6d739796f884eea7142c8 [file] [log] [blame]
Robert Love85b4aa42008-12-09 15:10:24 -08001/*
Chris Leechaf7f85d2009-08-25 13:59:24 -07002 * Copyright(c) 2007 - 2009 Intel Corporation. All rights reserved.
Robert Love85b4aa42008-12-09 15:10:24 -08003 *
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>
Robert Love85b4aa42008-12-09 15:10:24 -080021#include <linux/spinlock.h>
Robert Love85b4aa42008-12-09 15:10:24 -080022#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>
Robert Love85b4aa42008-12-09 15:10:24 -080027#include <linux/crc32.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
Robert Love85b4aa42008-12-09 15:10:24 -080029#include <linux/cpu.h>
30#include <linux/fs.h>
31#include <linux/sysfs.h>
32#include <linux/ctype.h>
Tejun Heo2ca32b42011-01-28 16:05:32 -080033#include <linux/workqueue.h>
john fastabend6f6c2aa2011-11-18 13:35:56 -080034#include <net/dcbnl.h>
35#include <net/dcbevent.h>
Robert Love85b4aa42008-12-09 15:10:24 -080036#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>
Joe Eykholt97c83892009-03-17 11:42:40 -070043#include <scsi/fc/fc_fip.h>
Robert Love85b4aa42008-12-09 15:10:24 -080044
45#include <scsi/libfc.h>
46#include <scsi/fc_frame.h>
47#include <scsi/libfcoe.h>
Robert Love85b4aa42008-12-09 15:10:24 -080048
Vasu Devfdd780272009-03-17 11:42:24 -070049#include "fcoe.h"
50
Robert Love85b4aa42008-12-09 15:10:24 -080051MODULE_AUTHOR("Open-FCoE.org");
52MODULE_DESCRIPTION("FCoE");
Vasu Dev9b34ecf2009-03-17 11:42:13 -070053MODULE_LICENSE("GPL v2");
Robert Love85b4aa42008-12-09 15:10:24 -080054
Yi Zou05cc7392009-08-25 13:59:03 -070055/* Performance tuning parameters for fcoe */
Vasu Dev860eca22011-09-27 21:38:18 -070056static unsigned int fcoe_ddp_min = 4096;
Yi Zou05cc7392009-08-25 13:59:03 -070057module_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
Bart Van Assche7c9c6842012-01-13 17:26:25 -080061unsigned 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);
Chris Leechdfc1d0f2009-08-25 14:00:13 -070066
Tejun Heo2ca32b42011-01-28 16:05:32 -080067static struct workqueue_struct *fcoe_wq;
68
Joe Eykholte7a51992009-08-25 14:04:08 -070069/* fcoe_percpu_clean completion. Waiter protected by fcoe_create_mutex */
70static DECLARE_COMPLETION(fcoe_flush_completion);
71
Robert Love85b4aa42008-12-09 15:10:24 -080072/* fcoe host list */
Chris Leech090eb6c2009-08-25 14:00:28 -070073/* must only by accessed under the RTNL mutex */
Bart Van Assche7c9c6842012-01-13 17:26:25 -080074static LIST_HEAD(fcoe_hostlist);
75static DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu);
Robert Love85b4aa42008-12-09 15:10:24 -080076
Chris Leechdd3fd722009-04-21 16:27:36 -070077/* Function Prototypes */
Robert Love1875f272009-11-03 11:47:50 -080078static int fcoe_reset(struct Scsi_Host *);
Vasu Devfdd780272009-03-17 11:42:24 -070079static 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 *);
Robert Love1875f272009-11-03 11:47:50 -080082static int fcoe_percpu_receive_thread(void *);
Robert Love1875f272009-11-03 11:47:50 -080083static void fcoe_percpu_clean(struct fc_lport *);
Robert Love5e4f8fe2010-05-07 15:18:35 -070084static int fcoe_link_speed_update(struct fc_lport *);
Robert Love1875f272009-11-03 11:47:50 -080085static int fcoe_link_ok(struct fc_lport *);
Vasu Devfdd780272009-03-17 11:42:24 -070086
87static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *);
88static int fcoe_hostlist_add(const struct fc_lport *);
Vasu Devfdd780272009-03-17 11:42:24 -070089
Robert Love85b4aa42008-12-09 15:10:24 -080090static int fcoe_device_notification(struct notifier_block *, ulong, void *);
91static void fcoe_dev_setup(void);
92static void fcoe_dev_cleanup(void);
Robert Love1875f272009-11-03 11:47:50 -080093static struct fcoe_interface
94*fcoe_hostlist_lookup_port(const struct net_device *);
Robert Love85b4aa42008-12-09 15:10:24 -080095
Robert Love1875f272009-11-03 11:47:50 -080096static 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);
Yi Zou71f89492011-06-20 16:59:10 -0700107static int fcoe_ddp_target(struct fc_lport *, u16, struct scatterlist *,
108 unsigned int);
Robert Love1875f272009-11-03 11:47:50 -0800109static int fcoe_cpu_callback(struct notifier_block *, unsigned long, void *);
john fastabend6f6c2aa2011-11-18 13:35:56 -0800110static int fcoe_dcb_app_notification(struct notifier_block *notifier,
111 ulong event, void *ptr);
Robert Love1875f272009-11-03 11:47:50 -0800112
Yi Zou78a58242011-01-28 16:05:16 -0800113static 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);
Robert Love1875f272009-11-03 11:47:50 -0800118
Robert Love1875f272009-11-03 11:47:50 -0800119static 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);
Chris Leech859b7b62009-11-20 14:54:47 -0800126static void fcoe_recv_frame(struct sk_buff *skb);
Robert Love1875f272009-11-03 11:47:50 -0800127
Yi Zoub84056b2009-11-20 14:55:19 -0800128static void fcoe_get_lesb(struct fc_lport *, struct fc_els_lesb *);
129
Robert Love1875f272009-11-03 11:47:50 -0800130/* notification function for packets from net device */
Robert Love85b4aa42008-12-09 15:10:24 -0800131static struct notifier_block fcoe_notifier = {
132 .notifier_call = fcoe_device_notification,
133};
134
Robert Love1875f272009-11-03 11:47:50 -0800135/* notification function for CPU hotplug events */
136static struct notifier_block fcoe_cpu_notifier = {
137 .notifier_call = fcoe_cpu_callback,
138};
139
john fastabend6f6c2aa2011-11-18 13:35:56 -0800140/* notification function for DCB events */
141static struct notifier_block dcb_notifier = {
142 .notifier_call = fcoe_dcb_app_notification,
143};
144
Yi Zou8ca86f82011-01-28 16:05:11 -0800145static struct scsi_transport_template *fcoe_nport_scsi_transport;
146static struct scsi_transport_template *fcoe_vport_scsi_transport;
Vasu Dev7f349142009-03-27 09:06:31 -0700147
Robert Love1875f272009-11-03 11:47:50 -0800148static 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 *);
Joe Eykholt7d65b0d2010-03-12 16:08:02 -0800152static void fcoe_set_port_id(struct fc_lport *, u32, struct fc_frame *);
Robert Love1875f272009-11-03 11:47:50 -0800153
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,
Yi Zou71f89492011-06-20 16:59:10 -0700158 .ddp_target = fcoe_ddp_target,
Robert Love1875f272009-11-03 11:47:50 -0800159 .elsct_send = fcoe_elsct_send,
Yi Zoub84056b2009-11-20 14:55:19 -0800160 .get_lesb = fcoe_get_lesb,
Joe Eykholt7d65b0d2010-03-12 16:08:02 -0800161 .lport_set_port_id = fcoe_set_port_id,
Robert Love1875f272009-11-03 11:47:50 -0800162};
Chris Leech9a057532009-11-03 11:46:40 -0800163
Bart Van Assche7c9c6842012-01-13 17:26:25 -0800164static struct fc_function_template fcoe_nport_fc_functions = {
Vasu Dev7f349142009-03-27 09:06:31 -0700165 .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,
Neerav Parikh9f71af22012-01-22 17:30:16 -0800171 .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,
Vasu Dev7f349142009-03-27 09:06:31 -0700179
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,
Chris Leech9a057532009-11-03 11:46:40 -0800203
204 .vport_create = fcoe_vport_create,
205 .vport_delete = fcoe_vport_destroy,
206 .vport_disable = fcoe_vport_disable,
Chris Leechdc8596d2009-11-03 11:47:18 -0800207 .set_vport_symbolic_name = fcoe_set_vport_symbolic_name,
Steve Maa51ab392009-11-03 11:47:34 -0800208
209 .bsg_request = fc_lport_bsg_request,
Vasu Dev7f349142009-03-27 09:06:31 -0700210};
211
Bart Van Assche7c9c6842012-01-13 17:26:25 -0800212static struct fc_function_template fcoe_vport_fc_functions = {
Chris Leeche9084bb2009-11-03 11:46:34 -0800213 .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,
Neerav Parikh7e5adcf2012-02-10 17:18:31 -0800219 .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,
Chris Leeche9084bb2009-11-03 11:46:34 -0800227
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,
Steve Maa51ab392009-11-03 11:47:34 -0800251
252 .bsg_request = fc_lport_bsg_request,
Chris Leeche9084bb2009-11-03 11:46:34 -0800253};
254
Vasu Dev7f349142009-03-27 09:06:31 -0700255static 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,
Vasu Dev14caf442009-10-15 17:46:55 -0700267 .cmd_per_lun = 3,
Vasu Dev7f349142009-03-27 09:06:31 -0700268 .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS,
269 .use_clustering = ENABLE_CLUSTERING,
270 .sg_tablesize = SG_ALL,
271 .max_sectors = 0xffff,
272};
273
Chris Leech54b649f2009-08-25 14:00:07 -0700274/**
Robert Love1875f272009-11-03 11:47:50 -0800275 * fcoe_interface_setup() - Setup a FCoE interface
276 * @fcoe: The new FCoE interface
277 * @netdev: The net device that the fcoe interface is on
Chris Leech54b649f2009-08-25 14:00:07 -0700278 *
279 * Returns : 0 for success
Chris Leech2e70e242009-08-25 14:00:23 -0700280 * Locking: must be called with the RTNL mutex held
Chris Leech54b649f2009-08-25 14:00:07 -0700281 */
282static int fcoe_interface_setup(struct fcoe_interface *fcoe,
283 struct net_device *netdev)
284{
Robert Love619fe4b2012-05-22 19:06:10 -0700285 struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe);
Chris Leech54b649f2009-08-25 14:00:07 -0700286 struct netdev_hw_addr *ha;
Yi Zou5bab87e2009-11-03 11:49:43 -0800287 struct net_device *real_dev;
Chris Leech54b649f2009-08-25 14:00:07 -0700288 u8 flogi_maddr[ETH_ALEN];
Yi Zoub7a727f2009-10-21 16:28:03 -0700289 const struct net_device_ops *ops;
Chris Leech54b649f2009-08-25 14:00:07 -0700290
291 fcoe->netdev = netdev;
292
Yi Zoub7a727f2009-10-21 16:28:03 -0700293 /* 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
Chris Leech54b649f2009-08-25 14:00:07 -0700301 /* Do not support for bonding device */
Jiri Pirkocc8bdf02011-03-01 20:05:35 +0000302 if (netdev->priv_flags & IFF_BONDING && netdev->flags & IFF_MASTER) {
john fastabend59d92512009-11-03 11:48:44 -0800303 FCOE_NETDEV_DBG(netdev, "Bonded interfaces not supported\n");
Chris Leech54b649f2009-08-25 14:00:07 -0700304 return -EOPNOTSUPP;
305 }
306
307 /* look for SAN MAC address, if multiple SAN MACs exist, only
308 * use the first one for SPMA */
Yi Zou5bab87e2009-11-03 11:49:43 -0800309 real_dev = (netdev->priv_flags & IFF_802_1Q_VLAN) ?
310 vlan_dev_real_dev(netdev) : netdev;
Vasu Devd1483bb2011-09-27 21:38:13 -0700311 fcoe->realdev = real_dev;
Chris Leech54b649f2009-08-25 14:00:07 -0700312 rcu_read_lock();
Yi Zou5bab87e2009-11-03 11:49:43 -0800313 for_each_dev_addr(real_dev, ha) {
Chris Leech54b649f2009-08-25 14:00:07 -0700314 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
Yi Zoubf361702009-11-03 11:49:38 -0800315 (is_valid_ether_addr(ha->addr))) {
Chris Leech54b649f2009-08-25 14:00:07 -0700316 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 */
Chris Leech54b649f2009-08-25 14:00:07 -0700332 memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
Jiri Pirkoa748ee22010-04-01 21:22:09 +0000333 dev_uc_add(netdev, flogi_maddr);
Chris Leech54b649f2009-08-25 14:00:07 -0700334 if (fip->spma)
Jiri Pirkoa748ee22010-04-01 21:22:09 +0000335 dev_uc_add(netdev, fip->ctl_src_addr);
Joe Eykholte10f8c62010-07-20 15:20:30 -0700336 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);
Chris Leech54b649f2009-08-25 14:00:07 -0700341
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
Vasu Dev7f349142009-03-27 09:06:31 -0700359/**
Robert Love1875f272009-11-03 11:47:50 -0800360 * fcoe_interface_create() - Create a FCoE interface on a net device
361 * @netdev: The net device to create the FCoE interface on
Joe Eykholt1dd454d2010-07-20 15:20:46 -0700362 * @fip_mode: The mode to use for FIP
Chris Leech030f4e02009-08-25 14:00:02 -0700363 *
364 * Returns: pointer to a struct fcoe_interface or NULL on error
365 */
Joe Eykholt1dd454d2010-07-20 15:20:46 -0700366static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev,
367 enum fip_state fip_mode)
Chris Leech030f4e02009-08-25 14:00:02 -0700368{
Robert Love619fe4b2012-05-22 19:06:10 -0700369 struct fcoe_ctlr *ctlr;
Chris Leech030f4e02009-08-25 14:00:02 -0700370 struct fcoe_interface *fcoe;
Robert Love619fe4b2012-05-22 19:06:10 -0700371 int size;
john fastabend59d92512009-11-03 11:48:44 -0800372 int err;
Chris Leech030f4e02009-08-25 14:00:02 -0700373
Robert Love7287fb92011-01-28 16:03:47 -0800374 if (!try_module_get(THIS_MODULE)) {
375 FCOE_NETDEV_DBG(netdev,
376 "Could not get a reference to the module\n");
377 fcoe = ERR_PTR(-EBUSY);
378 goto out;
379 }
380
Robert Love619fe4b2012-05-22 19:06:10 -0700381 size = sizeof(struct fcoe_ctlr) + sizeof(struct fcoe_interface);
382 ctlr = kzalloc(size, GFP_KERNEL);
383 fcoe = fcoe_ctlr_priv(ctlr);
Chris Leech030f4e02009-08-25 14:00:02 -0700384 if (!fcoe) {
385 FCOE_NETDEV_DBG(netdev, "Could not allocate fcoe structure\n");
Robert Love7287fb92011-01-28 16:03:47 -0800386 fcoe = ERR_PTR(-ENOMEM);
Robert Love6f687942012-02-10 17:18:36 -0800387 goto out_putmod;
Chris Leech030f4e02009-08-25 14:00:02 -0700388 }
389
Chris Leech2e70e242009-08-25 14:00:23 -0700390 dev_hold(netdev);
Chris Leech54b649f2009-08-25 14:00:07 -0700391
392 /*
393 * Initialize FIP.
394 */
Robert Love619fe4b2012-05-22 19:06:10 -0700395 fcoe_ctlr_init(ctlr, fip_mode);
396 ctlr->send = fcoe_fip_send;
397 ctlr->update_mac = fcoe_update_src_mac;
398 ctlr->get_src_addr = fcoe_get_src_mac;
Chris Leech54b649f2009-08-25 14:00:07 -0700399
john fastabend59d92512009-11-03 11:48:44 -0800400 err = fcoe_interface_setup(fcoe, netdev);
401 if (err) {
Robert Love619fe4b2012-05-22 19:06:10 -0700402 fcoe_ctlr_destroy(ctlr);
john fastabend59d92512009-11-03 11:48:44 -0800403 dev_put(netdev);
Robert Love7287fb92011-01-28 16:03:47 -0800404 fcoe = ERR_PTR(err);
Robert Love6f687942012-02-10 17:18:36 -0800405 goto out_putmod;
john fastabend59d92512009-11-03 11:48:44 -0800406 }
Chris Leech030f4e02009-08-25 14:00:02 -0700407
Robert Love7287fb92011-01-28 16:03:47 -0800408 goto out;
409
Robert Love6f687942012-02-10 17:18:36 -0800410out_putmod:
Robert Love7287fb92011-01-28 16:03:47 -0800411 module_put(THIS_MODULE);
412out:
Chris Leech030f4e02009-08-25 14:00:02 -0700413 return fcoe;
414}
415
416/**
Vasu Dev433eba02012-04-20 12:16:27 -0700417 * fcoe_interface_remove() - remove FCoE interface from netdev
Vasu Devf04ca1b2011-04-01 16:06:45 -0700418 * @fcoe: The FCoE interface to be cleaned up
419 *
420 * Caller must be holding the RTNL mutex
421 */
Vasu Dev433eba02012-04-20 12:16:27 -0700422static void fcoe_interface_remove(struct fcoe_interface *fcoe)
Vasu Devf04ca1b2011-04-01 16:06:45 -0700423{
424 struct net_device *netdev = fcoe->netdev;
Robert Love619fe4b2012-05-22 19:06:10 -0700425 struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe);
Vasu Devf04ca1b2011-04-01 16:06:45 -0700426 u8 flogi_maddr[ETH_ALEN];
427 const struct net_device_ops *ops;
Vasu Devf04ca1b2011-04-01 16:06:45 -0700428
429 /*
430 * Don't listen for Ethernet packets anymore.
431 * synchronize_net() ensures that the packet handlers are not running
432 * on another CPU. dev_remove_pack() would do that, this calls the
433 * unsyncronized version __dev_remove_pack() to avoid multiple delays.
434 */
435 __dev_remove_pack(&fcoe->fcoe_packet_type);
436 __dev_remove_pack(&fcoe->fip_packet_type);
437 synchronize_net();
438
439 /* Delete secondary MAC addresses */
440 memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
441 dev_uc_del(netdev, flogi_maddr);
442 if (fip->spma)
443 dev_uc_del(netdev, fip->ctl_src_addr);
444 if (fip->mode == FIP_MODE_VN2VN) {
445 dev_mc_del(netdev, FIP_ALL_VN2VN_MACS);
446 dev_mc_del(netdev, FIP_ALL_P2P_MACS);
447 } else
448 dev_mc_del(netdev, FIP_ALL_ENODE_MACS);
449
Vasu Devf04ca1b2011-04-01 16:06:45 -0700450 /* Tell the LLD we are done w/ FCoE */
451 ops = netdev->netdev_ops;
452 if (ops->ndo_fcoe_disable) {
453 if (ops->ndo_fcoe_disable(netdev))
454 FCOE_NETDEV_DBG(netdev, "Failed to disable FCoE"
455 " specific feature for LLD.\n");
456 }
Vasu Dev433eba02012-04-20 12:16:27 -0700457 fcoe->removed = 1;
458}
Neerav Parikhb2085a42011-06-20 16:59:51 -0700459
Vasu Dev433eba02012-04-20 12:16:27 -0700460
461/**
462 * fcoe_interface_cleanup() - Clean up a FCoE interface
463 * @fcoe: The FCoE interface to be cleaned up
464 */
465static void fcoe_interface_cleanup(struct fcoe_interface *fcoe)
466{
467 struct net_device *netdev = fcoe->netdev;
Robert Love619fe4b2012-05-22 19:06:10 -0700468 struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe);
Vasu Dev433eba02012-04-20 12:16:27 -0700469
470 rtnl_lock();
471 if (!fcoe->removed)
472 fcoe_interface_remove(fcoe);
Robert Love848e7d52011-08-25 12:40:47 -0700473 rtnl_unlock();
474
Neerav Parikhb2085a42011-06-20 16:59:51 -0700475 /* Release the self-reference taken during fcoe_interface_create() */
Robert Love1a8ef412012-02-10 17:18:46 -0800476 /* tear-down the FCoE controller */
477 fcoe_ctlr_destroy(fip);
Robert Love619fe4b2012-05-22 19:06:10 -0700478 scsi_host_put(fip->lp->host);
479 kfree(fip);
Robert Love1a8ef412012-02-10 17:18:46 -0800480 dev_put(netdev);
481 module_put(THIS_MODULE);
Vasu Devf04ca1b2011-04-01 16:06:45 -0700482}
483
484/**
Robert Love1875f272009-11-03 11:47:50 -0800485 * fcoe_fip_recv() - Handler for received FIP frames
486 * @skb: The receive skb
487 * @netdev: The associated net device
488 * @ptype: The packet_type structure which was used to register this handler
489 * @orig_dev: The original net_device the the skb was received on.
490 * (in case dev is a bond)
Vasu Devab6b85c2009-05-17 12:33:08 +0000491 *
492 * Returns: 0 for success
493 */
Robert Love1875f272009-11-03 11:47:50 -0800494static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *netdev,
Vasu Devab6b85c2009-05-17 12:33:08 +0000495 struct packet_type *ptype,
496 struct net_device *orig_dev)
497{
Chris Leech259ad852009-08-25 13:59:41 -0700498 struct fcoe_interface *fcoe;
Robert Love619fe4b2012-05-22 19:06:10 -0700499 struct fcoe_ctlr *ctlr;
Vasu Devab6b85c2009-05-17 12:33:08 +0000500
Chris Leech259ad852009-08-25 13:59:41 -0700501 fcoe = container_of(ptype, struct fcoe_interface, fip_packet_type);
Robert Love619fe4b2012-05-22 19:06:10 -0700502 ctlr = fcoe_to_ctlr(fcoe);
503 fcoe_ctlr_recv(ctlr, skb);
Vasu Devab6b85c2009-05-17 12:33:08 +0000504 return 0;
505}
506
507/**
Vasu Dev980f5152011-07-27 15:11:05 -0700508 * fcoe_port_send() - Send an Ethernet-encapsulated FIP/FCoE frame
509 * @port: The FCoE port
510 * @skb: The FIP/FCoE packet to be sent
511 */
512static void fcoe_port_send(struct fcoe_port *port, struct sk_buff *skb)
513{
514 if (port->fcoe_pending_queue.qlen)
515 fcoe_check_wait_queue(port->lport, skb);
516 else if (fcoe_start_io(skb))
517 fcoe_check_wait_queue(port->lport, skb);
518}
519
520/**
Robert Love1875f272009-11-03 11:47:50 -0800521 * fcoe_fip_send() - Send an Ethernet-encapsulated FIP frame
522 * @fip: The FCoE controller
523 * @skb: The FIP packet to be sent
Vasu Devab6b85c2009-05-17 12:33:08 +0000524 */
525static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
526{
Chris Leech3fe9a0b2009-08-25 13:59:46 -0700527 skb->dev = fcoe_from_ctlr(fip)->netdev;
Vasu Dev980f5152011-07-27 15:11:05 -0700528 fcoe_port_send(lport_priv(fip->lp), skb);
Vasu Devab6b85c2009-05-17 12:33:08 +0000529}
530
531/**
Robert Love1875f272009-11-03 11:47:50 -0800532 * fcoe_update_src_mac() - Update the Ethernet MAC filters
533 * @lport: The local port to update the source MAC on
534 * @addr: Unicast MAC address to add
Vasu Devab6b85c2009-05-17 12:33:08 +0000535 *
536 * Remove any previously-set unicast MAC filter.
537 * Add secondary FCoE MAC address filter for our OUI.
538 */
Chris Leech11b56182009-11-03 11:46:29 -0800539static void fcoe_update_src_mac(struct fc_lport *lport, u8 *addr)
Vasu Devab6b85c2009-05-17 12:33:08 +0000540{
Chris Leech11b56182009-11-03 11:46:29 -0800541 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudi8597ae82011-01-28 16:05:37 -0800542 struct fcoe_interface *fcoe = port->priv;
Vasu Devab6b85c2009-05-17 12:33:08 +0000543
Chris Leech11b56182009-11-03 11:46:29 -0800544 if (!is_zero_ether_addr(port->data_src_addr))
Jiri Pirkoa748ee22010-04-01 21:22:09 +0000545 dev_uc_del(fcoe->netdev, port->data_src_addr);
Chris Leech11b56182009-11-03 11:46:29 -0800546 if (!is_zero_ether_addr(addr))
Jiri Pirkoa748ee22010-04-01 21:22:09 +0000547 dev_uc_add(fcoe->netdev, addr);
Chris Leech11b56182009-11-03 11:46:29 -0800548 memcpy(port->data_src_addr, addr, ETH_ALEN);
Vasu Devab6b85c2009-05-17 12:33:08 +0000549}
550
551/**
Chris Leech11b56182009-11-03 11:46:29 -0800552 * fcoe_get_src_mac() - return the Ethernet source address for an lport
553 * @lport: libfc lport
554 */
555static u8 *fcoe_get_src_mac(struct fc_lport *lport)
556{
557 struct fcoe_port *port = lport_priv(lport);
558
559 return port->data_src_addr;
560}
561
562/**
Robert Love1875f272009-11-03 11:47:50 -0800563 * fcoe_lport_config() - Set up a local port
564 * @lport: The local port to be setup
Vasu Dev7f349142009-03-27 09:06:31 -0700565 *
566 * Returns: 0 for success
567 */
Robert Love1875f272009-11-03 11:47:50 -0800568static int fcoe_lport_config(struct fc_lport *lport)
Vasu Dev7f349142009-03-27 09:06:31 -0700569{
Robert Love1875f272009-11-03 11:47:50 -0800570 lport->link_up = 0;
571 lport->qfull = 0;
572 lport->max_retry_count = 3;
573 lport->max_rport_retry_count = 3;
574 lport->e_d_tov = 2 * 1000; /* FC-FS default */
575 lport->r_a_tov = 2 * 2 * 1000;
576 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
577 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
578 lport->does_npiv = 1;
Vasu Dev7f349142009-03-27 09:06:31 -0700579
Robert Love1875f272009-11-03 11:47:50 -0800580 fc_lport_init_stats(lport);
Vasu Dev7f349142009-03-27 09:06:31 -0700581
582 /* lport fc_lport related configuration */
Robert Love1875f272009-11-03 11:47:50 -0800583 fc_lport_config(lport);
Vasu Dev7f349142009-03-27 09:06:31 -0700584
585 /* offload related configuration */
Robert Love1875f272009-11-03 11:47:50 -0800586 lport->crc_offload = 0;
587 lport->seq_offload = 0;
588 lport->lro_enabled = 0;
589 lport->lro_xid = 0;
590 lport->lso_max = 0;
Vasu Dev7f349142009-03-27 09:06:31 -0700591
592 return 0;
593}
594
595/**
Yi Zou54a5b212010-07-20 15:21:17 -0700596 * fcoe_netdev_features_change - Updates the lport's offload flags based
597 * on the LLD netdev's FCoE feature flags
598 */
599static void fcoe_netdev_features_change(struct fc_lport *lport,
600 struct net_device *netdev)
601{
602 mutex_lock(&lport->lp_mutex);
603
604 if (netdev->features & NETIF_F_SG)
605 lport->sg_supp = 1;
606 else
607 lport->sg_supp = 0;
608
609 if (netdev->features & NETIF_F_FCOE_CRC) {
610 lport->crc_offload = 1;
611 FCOE_NETDEV_DBG(netdev, "Supports FCCRC offload\n");
612 } else {
613 lport->crc_offload = 0;
614 }
615
616 if (netdev->features & NETIF_F_FSO) {
617 lport->seq_offload = 1;
618 lport->lso_max = netdev->gso_max_size;
619 FCOE_NETDEV_DBG(netdev, "Supports LSO for max len 0x%x\n",
620 lport->lso_max);
621 } else {
622 lport->seq_offload = 0;
623 lport->lso_max = 0;
624 }
625
626 if (netdev->fcoe_ddp_xid) {
627 lport->lro_enabled = 1;
628 lport->lro_xid = netdev->fcoe_ddp_xid;
629 FCOE_NETDEV_DBG(netdev, "Supports LRO for max xid 0x%x\n",
630 lport->lro_xid);
631 } else {
632 lport->lro_enabled = 0;
633 lport->lro_xid = 0;
634 }
635
636 mutex_unlock(&lport->lp_mutex);
637}
638
639/**
Robert Love1875f272009-11-03 11:47:50 -0800640 * fcoe_netdev_config() - Set up net devive for SW FCoE
641 * @lport: The local port that is associated with the net device
642 * @netdev: The associated net device
Vasu Dev7f349142009-03-27 09:06:31 -0700643 *
Robert Love1875f272009-11-03 11:47:50 -0800644 * Must be called after fcoe_lport_config() as it will use local port mutex
Vasu Dev7f349142009-03-27 09:06:31 -0700645 *
Robert Love1875f272009-11-03 11:47:50 -0800646 * Returns: 0 for success
Vasu Dev7f349142009-03-27 09:06:31 -0700647 */
Robert Love1875f272009-11-03 11:47:50 -0800648static int fcoe_netdev_config(struct fc_lport *lport, struct net_device *netdev)
Vasu Dev7f349142009-03-27 09:06:31 -0700649{
650 u32 mfs;
651 u64 wwnn, wwpn;
Chris Leech25024982009-08-25 13:59:35 -0700652 struct fcoe_interface *fcoe;
Robert Love619fe4b2012-05-22 19:06:10 -0700653 struct fcoe_ctlr *ctlr;
Chris Leech014f5c32009-08-25 13:59:30 -0700654 struct fcoe_port *port;
Vasu Dev7f349142009-03-27 09:06:31 -0700655
656 /* Setup lport private data to point to fcoe softc */
Robert Love1875f272009-11-03 11:47:50 -0800657 port = lport_priv(lport);
Bhanu Prakash Gollapudi8597ae82011-01-28 16:05:37 -0800658 fcoe = port->priv;
Robert Love619fe4b2012-05-22 19:06:10 -0700659 ctlr = fcoe_to_ctlr(fcoe);
Vasu Dev7f349142009-03-27 09:06:31 -0700660
661 /*
662 * Determine max frame size based on underlying device and optional
663 * user-configured limit. If the MFS is too low, fcoe_link_ok()
664 * will return 0, so do this first.
665 */
Yi Zou7221d7e2009-10-21 16:27:52 -0700666 mfs = netdev->mtu;
667 if (netdev->features & NETIF_F_FCOE_MTU) {
668 mfs = FCOE_MTU;
669 FCOE_NETDEV_DBG(netdev, "Supports FCOE_MTU of %d bytes\n", mfs);
670 }
671 mfs -= (sizeof(struct fcoe_hdr) + sizeof(struct fcoe_crc_eof));
Robert Love1875f272009-11-03 11:47:50 -0800672 if (fc_set_mfs(lport, mfs))
Vasu Dev7f349142009-03-27 09:06:31 -0700673 return -EINVAL;
674
Vasu Dev7f349142009-03-27 09:06:31 -0700675 /* offload features support */
Yi Zou54a5b212010-07-20 15:21:17 -0700676 fcoe_netdev_features_change(lport, netdev);
Vasu Dev7f349142009-03-27 09:06:31 -0700677
Chris Leech014f5c32009-08-25 13:59:30 -0700678 skb_queue_head_init(&port->fcoe_pending_queue);
679 port->fcoe_pending_queue_active = 0;
Robert Love1875f272009-11-03 11:47:50 -0800680 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long)lport);
Vasu Dev7f349142009-03-27 09:06:31 -0700681
Robert Love5e4f8fe2010-05-07 15:18:35 -0700682 fcoe_link_speed_update(lport);
683
Robert Love1875f272009-11-03 11:47:50 -0800684 if (!lport->vport) {
Yi Zoudcece412009-11-20 15:22:21 -0800685 if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
Robert Love619fe4b2012-05-22 19:06:10 -0700686 wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr, 1, 0);
Robert Love1875f272009-11-03 11:47:50 -0800687 fc_set_wwnn(lport, wwnn);
Yi Zoudcece412009-11-20 15:22:21 -0800688 if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
Robert Love619fe4b2012-05-22 19:06:10 -0700689 wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
Vasu Devcf4aebca2010-07-20 15:21:22 -0700690 2, 0);
Robert Love1875f272009-11-03 11:47:50 -0800691 fc_set_wwpn(lport, wwpn);
Chris Leech9a057532009-11-03 11:46:40 -0800692 }
Vasu Dev7f349142009-03-27 09:06:31 -0700693
Vasu Dev7f349142009-03-27 09:06:31 -0700694 return 0;
695}
696
697/**
Robert Love1875f272009-11-03 11:47:50 -0800698 * fcoe_shost_config() - Set up the SCSI host associated with a local port
699 * @lport: The local port
Robert Love1875f272009-11-03 11:47:50 -0800700 * @dev: The device associated with the SCSI host
Vasu Dev7f349142009-03-27 09:06:31 -0700701 *
702 * Must be called after fcoe_lport_config() and fcoe_netdev_config()
703 *
Robert Love1875f272009-11-03 11:47:50 -0800704 * Returns: 0 for success
Vasu Dev7f349142009-03-27 09:06:31 -0700705 */
Vasu Dev8ba00a42010-04-09 14:22:54 -0700706static int fcoe_shost_config(struct fc_lport *lport, struct device *dev)
Vasu Dev7f349142009-03-27 09:06:31 -0700707{
708 int rc = 0;
709
710 /* lport scsi host config */
Robert Love1875f272009-11-03 11:47:50 -0800711 lport->host->max_lun = FCOE_MAX_LUN;
712 lport->host->max_id = FCOE_MAX_FCP_TARGET;
713 lport->host->max_channel = 0;
Vasu Devda87bfa2010-04-09 14:22:59 -0700714 lport->host->max_cmd_len = FCOE_MAX_CMD_LEN;
715
Robert Love1875f272009-11-03 11:47:50 -0800716 if (lport->vport)
Yi Zou8ca86f82011-01-28 16:05:11 -0800717 lport->host->transportt = fcoe_vport_scsi_transport;
Chris Leeche9084bb2009-11-03 11:46:34 -0800718 else
Yi Zou8ca86f82011-01-28 16:05:11 -0800719 lport->host->transportt = fcoe_nport_scsi_transport;
Vasu Dev7f349142009-03-27 09:06:31 -0700720
721 /* add the new host to the SCSI-ml */
Robert Love1875f272009-11-03 11:47:50 -0800722 rc = scsi_add_host(lport->host, dev);
Vasu Dev7f349142009-03-27 09:06:31 -0700723 if (rc) {
Robert Love1875f272009-11-03 11:47:50 -0800724 FCOE_NETDEV_DBG(fcoe_netdev(lport), "fcoe_shost_config: "
Robert Loved5488eb2009-06-10 15:30:59 -0700725 "error on scsi_add_host\n");
Vasu Dev7f349142009-03-27 09:06:31 -0700726 return rc;
727 }
Chris Leech9a057532009-11-03 11:46:40 -0800728
Robert Love1875f272009-11-03 11:47:50 -0800729 if (!lport->vport)
Alexey Dobriyan4be929b2010-05-24 14:33:03 -0700730 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
Chris Leech9a057532009-11-03 11:46:40 -0800731
Robert Love1875f272009-11-03 11:47:50 -0800732 snprintf(fc_host_symbolic_name(lport->host), FC_SYMBOLIC_NAME_SIZE,
Chris Leech5baa17c2009-11-03 11:46:56 -0800733 "%s v%s over %s", FCOE_NAME, FCOE_VERSION,
Robert Love1875f272009-11-03 11:47:50 -0800734 fcoe_netdev(lport)->name);
Vasu Dev7f349142009-03-27 09:06:31 -0700735
736 return 0;
737}
738
Neerav Parikh6fef3902012-01-22 17:30:10 -0800739
740/**
741 * fcoe_fdmi_info() - Get FDMI related info from net devive for SW FCoE
742 * @lport: The local port that is associated with the net device
743 * @netdev: The associated net device
744 *
745 * Must be called after fcoe_shost_config() as it will use local port mutex
746 *
747 */
748static void fcoe_fdmi_info(struct fc_lport *lport, struct net_device *netdev)
749{
750 struct fcoe_interface *fcoe;
751 struct fcoe_port *port;
752 struct net_device *realdev;
753 int rc;
754 struct netdev_fcoe_hbainfo fdmi;
755
756 port = lport_priv(lport);
757 fcoe = port->priv;
758 realdev = fcoe->realdev;
759
760 if (!realdev)
761 return;
762
763 /* No FDMI state m/c for NPIV ports */
764 if (lport->vport)
765 return;
766
767 if (realdev->netdev_ops->ndo_fcoe_get_hbainfo) {
768 memset(&fdmi, 0, sizeof(fdmi));
769 rc = realdev->netdev_ops->ndo_fcoe_get_hbainfo(realdev,
770 &fdmi);
771 if (rc) {
772 printk(KERN_INFO "fcoe: Failed to retrieve FDMI "
773 "information from netdev.\n");
774 return;
775 }
776
777 snprintf(fc_host_serial_number(lport->host),
778 FC_SERIAL_NUMBER_SIZE,
779 "%s",
780 fdmi.serial_number);
781 snprintf(fc_host_manufacturer(lport->host),
782 FC_SERIAL_NUMBER_SIZE,
783 "%s",
784 fdmi.manufacturer);
785 snprintf(fc_host_model(lport->host),
786 FC_SYMBOLIC_NAME_SIZE,
787 "%s",
788 fdmi.model);
789 snprintf(fc_host_model_description(lport->host),
790 FC_SYMBOLIC_NAME_SIZE,
791 "%s",
792 fdmi.model_description);
793 snprintf(fc_host_hardware_version(lport->host),
794 FC_VERSION_STRING_SIZE,
795 "%s",
796 fdmi.hardware_version);
797 snprintf(fc_host_driver_version(lport->host),
798 FC_VERSION_STRING_SIZE,
799 "%s",
800 fdmi.driver_version);
801 snprintf(fc_host_optionrom_version(lport->host),
802 FC_VERSION_STRING_SIZE,
803 "%s",
804 fdmi.optionrom_version);
805 snprintf(fc_host_firmware_version(lport->host),
806 FC_VERSION_STRING_SIZE,
807 "%s",
808 fdmi.firmware_version);
809
810 /* Enable FDMI lport states */
811 lport->fdmi_enabled = 1;
812 } else {
813 lport->fdmi_enabled = 0;
814 printk(KERN_INFO "fcoe: No FDMI support.\n");
815 }
816}
817
Robert Love1875f272009-11-03 11:47:50 -0800818/**
819 * fcoe_oem_match() - The match routine for the offloaded exchange manager
820 * @fp: The I/O frame
Vasu Devd7179682009-07-29 17:05:21 -0700821 *
Robert Love1875f272009-11-03 11:47:50 -0800822 * This routine will be associated with an exchange manager (EM). When
823 * the libfc exchange handling code is looking for an EM to use it will
824 * call this routine and pass it the frame that it wishes to send. This
825 * routine will return True if the associated EM is to be used and False
826 * if the echange code should continue looking for an EM.
827 *
828 * The offload EM that this routine is associated with will handle any
829 * packets that are for SCSI read requests.
830 *
Kiran Patil1ff99182011-06-20 16:59:15 -0700831 * This has been enhanced to work when FCoE stack is operating in target
832 * mode.
833 *
Robert Love1875f272009-11-03 11:47:50 -0800834 * Returns: True for read types I/O, otherwise returns false.
Vasu Devd7179682009-07-29 17:05:21 -0700835 */
Bart Van Assche7c9c6842012-01-13 17:26:25 -0800836static bool fcoe_oem_match(struct fc_frame *fp)
Vasu Devd7179682009-07-29 17:05:21 -0700837{
Kiran Patil1ff99182011-06-20 16:59:15 -0700838 struct fc_frame_header *fh = fc_frame_header_get(fp);
839 struct fcp_cmnd *fcp;
840
841 if (fc_fcp_is_read(fr_fsp(fp)) &&
842 (fr_fsp(fp)->data_len > fcoe_ddp_min))
843 return true;
Yi Zoua762dce2012-01-13 17:26:15 -0800844 else if ((fr_fsp(fp) == NULL) &&
845 (fh->fh_r_ctl == FC_RCTL_DD_UNSOL_CMD) &&
846 (ntohs(fh->fh_rx_id) == FC_XID_UNKNOWN)) {
Kiran Patil1ff99182011-06-20 16:59:15 -0700847 fcp = fc_frame_payload_get(fp, sizeof(*fcp));
Yi Zoua762dce2012-01-13 17:26:15 -0800848 if ((fcp->fc_flags & FCP_CFL_WRDATA) &&
849 (ntohl(fcp->fc_dl) > fcoe_ddp_min))
Kiran Patil1ff99182011-06-20 16:59:15 -0700850 return true;
851 }
852 return false;
Vasu Devd7179682009-07-29 17:05:21 -0700853}
854
Vasu Dev7f349142009-03-27 09:06:31 -0700855/**
Robert Love1875f272009-11-03 11:47:50 -0800856 * fcoe_em_config() - Allocate and configure an exchange manager
857 * @lport: The local port that the new EM will be associated with
Vasu Dev7f349142009-03-27 09:06:31 -0700858 *
Robert Love1875f272009-11-03 11:47:50 -0800859 * Returns: 0 on success
Vasu Dev7f349142009-03-27 09:06:31 -0700860 */
Robert Love1875f272009-11-03 11:47:50 -0800861static inline int fcoe_em_config(struct fc_lport *lport)
Vasu Dev7f349142009-03-27 09:06:31 -0700862{
Robert Love1875f272009-11-03 11:47:50 -0800863 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudi8597ae82011-01-28 16:05:37 -0800864 struct fcoe_interface *fcoe = port->priv;
Chris Leech25024982009-08-25 13:59:35 -0700865 struct fcoe_interface *oldfcoe = NULL;
Vasu Dev1d1b88d2009-07-29 17:05:45 -0700866 struct net_device *old_real_dev, *cur_real_dev;
Vasu Devd7179682009-07-29 17:05:21 -0700867 u16 min_xid = FCOE_MIN_XID;
868 u16 max_xid = FCOE_MAX_XID;
869
870 /*
871 * Check if need to allocate an em instance for
872 * offload exchange ids to be shared across all VN_PORTs/lport.
873 */
Robert Love1875f272009-11-03 11:47:50 -0800874 if (!lport->lro_enabled || !lport->lro_xid ||
875 (lport->lro_xid >= max_xid)) {
876 lport->lro_xid = 0;
Vasu Devd7179682009-07-29 17:05:21 -0700877 goto skip_oem;
878 }
879
880 /*
881 * Reuse existing offload em instance in case
Vasu Dev1d1b88d2009-07-29 17:05:45 -0700882 * it is already allocated on real eth device
Vasu Devd7179682009-07-29 17:05:21 -0700883 */
Chris Leech25024982009-08-25 13:59:35 -0700884 if (fcoe->netdev->priv_flags & IFF_802_1Q_VLAN)
885 cur_real_dev = vlan_dev_real_dev(fcoe->netdev);
Vasu Dev1d1b88d2009-07-29 17:05:45 -0700886 else
Chris Leech25024982009-08-25 13:59:35 -0700887 cur_real_dev = fcoe->netdev;
Vasu Dev1d1b88d2009-07-29 17:05:45 -0700888
Chris Leech25024982009-08-25 13:59:35 -0700889 list_for_each_entry(oldfcoe, &fcoe_hostlist, list) {
Chris Leech25024982009-08-25 13:59:35 -0700890 if (oldfcoe->netdev->priv_flags & IFF_802_1Q_VLAN)
891 old_real_dev = vlan_dev_real_dev(oldfcoe->netdev);
Vasu Dev1d1b88d2009-07-29 17:05:45 -0700892 else
Chris Leech25024982009-08-25 13:59:35 -0700893 old_real_dev = oldfcoe->netdev;
Vasu Dev1d1b88d2009-07-29 17:05:45 -0700894
895 if (cur_real_dev == old_real_dev) {
Chris Leech991cbb62009-08-25 13:59:51 -0700896 fcoe->oem = oldfcoe->oem;
Vasu Devd7179682009-07-29 17:05:21 -0700897 break;
898 }
899 }
900
Chris Leech991cbb62009-08-25 13:59:51 -0700901 if (fcoe->oem) {
Robert Love1875f272009-11-03 11:47:50 -0800902 if (!fc_exch_mgr_add(lport, fcoe->oem, fcoe_oem_match)) {
Vasu Devd7179682009-07-29 17:05:21 -0700903 printk(KERN_ERR "fcoe_em_config: failed to add "
904 "offload em:%p on interface:%s\n",
Chris Leech991cbb62009-08-25 13:59:51 -0700905 fcoe->oem, fcoe->netdev->name);
Vasu Devd7179682009-07-29 17:05:21 -0700906 return -ENOMEM;
907 }
908 } else {
Robert Love1875f272009-11-03 11:47:50 -0800909 fcoe->oem = fc_exch_mgr_alloc(lport, FC_CLASS_3,
910 FCOE_MIN_XID, lport->lro_xid,
911 fcoe_oem_match);
Chris Leech991cbb62009-08-25 13:59:51 -0700912 if (!fcoe->oem) {
Vasu Devd7179682009-07-29 17:05:21 -0700913 printk(KERN_ERR "fcoe_em_config: failed to allocate "
914 "em for offload exches on interface:%s\n",
Chris Leech25024982009-08-25 13:59:35 -0700915 fcoe->netdev->name);
Vasu Devd7179682009-07-29 17:05:21 -0700916 return -ENOMEM;
917 }
918 }
919
920 /*
921 * Exclude offload EM xid range from next EM xid range.
922 */
Robert Love1875f272009-11-03 11:47:50 -0800923 min_xid += lport->lro_xid + 1;
Vasu Devd7179682009-07-29 17:05:21 -0700924
925skip_oem:
Robert Love1875f272009-11-03 11:47:50 -0800926 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, min_xid, max_xid, NULL)) {
Vasu Devd7179682009-07-29 17:05:21 -0700927 printk(KERN_ERR "fcoe_em_config: failed to "
Chris Leech25024982009-08-25 13:59:35 -0700928 "allocate em on interface %s\n", fcoe->netdev->name);
Vasu Dev7f349142009-03-27 09:06:31 -0700929 return -ENOMEM;
Vasu Devd7179682009-07-29 17:05:21 -0700930 }
Vasu Dev7f349142009-03-27 09:06:31 -0700931
932 return 0;
933}
934
935/**
Robert Love1875f272009-11-03 11:47:50 -0800936 * fcoe_if_destroy() - Tear down a SW FCoE instance
937 * @lport: The local port to be destroyed
Vasu Dev34ce27b2010-05-07 15:18:46 -0700938 *
Vasu Dev7f349142009-03-27 09:06:31 -0700939 */
Chris Leechaf7f85d2009-08-25 13:59:24 -0700940static void fcoe_if_destroy(struct fc_lport *lport)
Vasu Dev7f349142009-03-27 09:06:31 -0700941{
Neerav Parikhb2085a42011-06-20 16:59:51 -0700942 struct fcoe_port *port = lport_priv(lport);
943 struct fcoe_interface *fcoe = port->priv;
944 struct net_device *netdev = fcoe->netdev;
945
946 FCOE_NETDEV_DBG(netdev, "Destroying interface\n");
947
948 /* Logout of the fabric */
949 fc_fabric_logoff(lport);
950
951 /* Cleanup the fc_lport */
952 fc_lport_destroy(lport);
953
954 /* Stop the transmit retry timer */
955 del_timer_sync(&port->timer);
956
957 /* Free existing transmit skbs */
958 fcoe_clean_pending_queue(lport);
959
960 rtnl_lock();
961 if (!is_zero_ether_addr(port->data_src_addr))
962 dev_uc_del(netdev, port->data_src_addr);
Vasu Dev433eba02012-04-20 12:16:27 -0700963 if (lport->vport)
964 synchronize_net();
965 else
966 fcoe_interface_remove(fcoe);
Neerav Parikhb2085a42011-06-20 16:59:51 -0700967 rtnl_unlock();
968
Chris Leech54b649f2009-08-25 14:00:07 -0700969 /* Free queued packets for the per-CPU receive threads */
970 fcoe_percpu_clean(lport);
971
Vasu Dev7f349142009-03-27 09:06:31 -0700972 /* Detach from the scsi-ml */
Chris Leechaf7f85d2009-08-25 13:59:24 -0700973 fc_remove_host(lport->host);
974 scsi_remove_host(lport->host);
Vasu Dev7f349142009-03-27 09:06:31 -0700975
Yi Zou80e736f2010-11-30 16:18:07 -0800976 /* Destroy lport scsi_priv */
977 fc_fcp_destroy(lport);
978
Vasu Dev7f349142009-03-27 09:06:31 -0700979 /* There are no more rports or I/O, free the EM */
Chris Leechaf7f85d2009-08-25 13:59:24 -0700980 fc_exch_mgr_free(lport);
Vasu Dev7f349142009-03-27 09:06:31 -0700981
Vasu Dev7f349142009-03-27 09:06:31 -0700982 /* Free memory used by statistical counters */
Chris Leechaf7f85d2009-08-25 13:59:24 -0700983 fc_lport_free_stats(lport);
Vasu Dev7f349142009-03-27 09:06:31 -0700984
Vasu Dev3cab4462012-04-20 12:16:38 -0700985 /*
986 * Release the Scsi_Host for vport but hold on to
987 * master lport until it fcoe interface fully cleaned-up.
988 */
989 if (lport->vport)
990 scsi_host_put(lport->host);
Vasu Dev7f349142009-03-27 09:06:31 -0700991}
992
Robert Love1875f272009-11-03 11:47:50 -0800993/**
994 * fcoe_ddp_setup() - Call a LLD's ddp_setup through the net device
995 * @lport: The local port to setup DDP for
996 * @xid: The exchange ID for this DDP transfer
997 * @sgl: The scatterlist describing this transfer
998 * @sgc: The number of sg items
Vasu Dev7f349142009-03-27 09:06:31 -0700999 *
Robert Love1875f272009-11-03 11:47:50 -08001000 * Returns: 0 if the DDP context was not configured
Vasu Dev7f349142009-03-27 09:06:31 -07001001 */
Robert Love1875f272009-11-03 11:47:50 -08001002static int fcoe_ddp_setup(struct fc_lport *lport, u16 xid,
1003 struct scatterlist *sgl, unsigned int sgc)
Vasu Dev7f349142009-03-27 09:06:31 -07001004{
Robert Love1875f272009-11-03 11:47:50 -08001005 struct net_device *netdev = fcoe_netdev(lport);
Vasu Dev7f349142009-03-27 09:06:31 -07001006
Robert Love1875f272009-11-03 11:47:50 -08001007 if (netdev->netdev_ops->ndo_fcoe_ddp_setup)
1008 return netdev->netdev_ops->ndo_fcoe_ddp_setup(netdev,
1009 xid, sgl,
1010 sgc);
Vasu Dev7f349142009-03-27 09:06:31 -07001011
1012 return 0;
1013}
1014
Vasu Dev7f349142009-03-27 09:06:31 -07001015/**
Yi Zou71f89492011-06-20 16:59:10 -07001016 * fcoe_ddp_target() - Call a LLD's ddp_target through the net device
1017 * @lport: The local port to setup DDP for
1018 * @xid: The exchange ID for this DDP transfer
1019 * @sgl: The scatterlist describing this transfer
1020 * @sgc: The number of sg items
1021 *
1022 * Returns: 0 if the DDP context was not configured
1023 */
1024static int fcoe_ddp_target(struct fc_lport *lport, u16 xid,
1025 struct scatterlist *sgl, unsigned int sgc)
1026{
1027 struct net_device *netdev = fcoe_netdev(lport);
1028
1029 if (netdev->netdev_ops->ndo_fcoe_ddp_target)
1030 return netdev->netdev_ops->ndo_fcoe_ddp_target(netdev, xid,
1031 sgl, sgc);
1032
1033 return 0;
1034}
1035
1036
1037/**
Robert Love1875f272009-11-03 11:47:50 -08001038 * fcoe_ddp_done() - Call a LLD's ddp_done through the net device
1039 * @lport: The local port to complete DDP on
1040 * @xid: The exchange ID for this DDP transfer
Vasu Dev7f349142009-03-27 09:06:31 -07001041 *
Robert Love1875f272009-11-03 11:47:50 -08001042 * Returns: the length of data that have been completed by DDP
1043 */
1044static int fcoe_ddp_done(struct fc_lport *lport, u16 xid)
1045{
1046 struct net_device *netdev = fcoe_netdev(lport);
1047
1048 if (netdev->netdev_ops->ndo_fcoe_ddp_done)
1049 return netdev->netdev_ops->ndo_fcoe_ddp_done(netdev, xid);
1050 return 0;
1051}
1052
1053/**
1054 * fcoe_if_create() - Create a FCoE instance on an interface
1055 * @fcoe: The FCoE interface to create a local port on
1056 * @parent: The device pointer to be the parent in sysfs for the SCSI host
1057 * @npiv: Indicates if the port is a vport or not
Vasu Dev7f349142009-03-27 09:06:31 -07001058 *
Robert Love1875f272009-11-03 11:47:50 -08001059 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1060 *
1061 * Returns: The allocated fc_lport or an error pointer
Vasu Dev7f349142009-03-27 09:06:31 -07001062 */
Chris Leech030f4e02009-08-25 14:00:02 -07001063static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
Chris Leech9a057532009-11-03 11:46:40 -08001064 struct device *parent, int npiv)
Vasu Dev7f349142009-03-27 09:06:31 -07001065{
Robert Love619fe4b2012-05-22 19:06:10 -07001066 struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe);
Robert Love1875f272009-11-03 11:47:50 -08001067 struct net_device *netdev = fcoe->netdev;
Vasu Dev72fa3962011-02-25 15:03:01 -08001068 struct fc_lport *lport, *n_port;
Chris Leech014f5c32009-08-25 13:59:30 -07001069 struct fcoe_port *port;
Vasu Dev72fa3962011-02-25 15:03:01 -08001070 struct Scsi_Host *shost;
Robert Love1875f272009-11-03 11:47:50 -08001071 int rc;
Chris Leech9a057532009-11-03 11:46:40 -08001072 /*
1073 * parent is only a vport if npiv is 1,
1074 * but we'll only use vport in that case so go ahead and set it
1075 */
1076 struct fc_vport *vport = dev_to_vport(parent);
Vasu Dev7f349142009-03-27 09:06:31 -07001077
Robert Loved5488eb2009-06-10 15:30:59 -07001078 FCOE_NETDEV_DBG(netdev, "Create Interface\n");
Vasu Dev7f349142009-03-27 09:06:31 -07001079
Vasu Dev72fa3962011-02-25 15:03:01 -08001080 if (!npiv)
1081 lport = libfc_host_alloc(&fcoe_shost_template, sizeof(*port));
1082 else
1083 lport = libfc_vport_create(vport, sizeof(*port));
1084
Chris Leech86221962009-11-03 11:46:08 -08001085 if (!lport) {
Chris Leech014f5c32009-08-25 13:59:30 -07001086 FCOE_NETDEV_DBG(netdev, "Could not allocate host structure\n");
1087 rc = -ENOMEM;
Chris Leech030f4e02009-08-25 14:00:02 -07001088 goto out;
Chris Leech014f5c32009-08-25 13:59:30 -07001089 }
Chris Leech014f5c32009-08-25 13:59:30 -07001090 port = lport_priv(lport);
Chris Leech2e70e242009-08-25 14:00:23 -07001091 port->lport = lport;
Bhanu Prakash Gollapudi8597ae82011-01-28 16:05:37 -08001092 port->priv = fcoe;
1093 port->max_queue_depth = FCOE_MAX_QUEUE_DEPTH;
1094 port->min_queue_depth = FCOE_MIN_QUEUE_DEPTH;
Chris Leech2e70e242009-08-25 14:00:23 -07001095 INIT_WORK(&port->destroy_work, fcoe_destroy_work);
Vasu Dev7f349142009-03-27 09:06:31 -07001096
Robert Love1875f272009-11-03 11:47:50 -08001097 /* configure a fc_lport including the exchange manager */
Chris Leechaf7f85d2009-08-25 13:59:24 -07001098 rc = fcoe_lport_config(lport);
Vasu Dev7f349142009-03-27 09:06:31 -07001099 if (rc) {
Robert Loved5488eb2009-06-10 15:30:59 -07001100 FCOE_NETDEV_DBG(netdev, "Could not configure lport for the "
1101 "interface\n");
Vasu Dev7f349142009-03-27 09:06:31 -07001102 goto out_host_put;
1103 }
1104
Chris Leech9a057532009-11-03 11:46:40 -08001105 if (npiv) {
Chris Leech9f8f3aa2010-04-09 14:23:16 -07001106 FCOE_NETDEV_DBG(netdev, "Setting vport names, "
1107 "%16.16llx %16.16llx\n",
Robert Love1875f272009-11-03 11:47:50 -08001108 vport->node_name, vport->port_name);
Chris Leech9a057532009-11-03 11:46:40 -08001109 fc_set_wwnn(lport, vport->node_name);
1110 fc_set_wwpn(lport, vport->port_name);
1111 }
1112
Vasu Devab6b85c2009-05-17 12:33:08 +00001113 /* configure lport network properties */
Chris Leechaf7f85d2009-08-25 13:59:24 -07001114 rc = fcoe_netdev_config(lport, netdev);
Vasu Devab6b85c2009-05-17 12:33:08 +00001115 if (rc) {
Robert Loved5488eb2009-06-10 15:30:59 -07001116 FCOE_NETDEV_DBG(netdev, "Could not configure netdev for the "
1117 "interface\n");
Chris Leech54b649f2009-08-25 14:00:07 -07001118 goto out_lp_destroy;
Vasu Devab6b85c2009-05-17 12:33:08 +00001119 }
Joe Eykholt97c83892009-03-17 11:42:40 -07001120
Vasu Dev7f349142009-03-27 09:06:31 -07001121 /* configure lport scsi host properties */
Vasu Dev8ba00a42010-04-09 14:22:54 -07001122 rc = fcoe_shost_config(lport, parent);
Vasu Dev7f349142009-03-27 09:06:31 -07001123 if (rc) {
Robert Loved5488eb2009-06-10 15:30:59 -07001124 FCOE_NETDEV_DBG(netdev, "Could not configure shost for the "
1125 "interface\n");
Chris Leech54b649f2009-08-25 14:00:07 -07001126 goto out_lp_destroy;
Vasu Dev7f349142009-03-27 09:06:31 -07001127 }
1128
Vasu Dev7f349142009-03-27 09:06:31 -07001129 /* Initialize the library */
Robert Love619fe4b2012-05-22 19:06:10 -07001130 rc = fcoe_libfc_config(lport, ctlr, &fcoe_libfc_fcn_templ, 1);
Vasu Dev7f349142009-03-27 09:06:31 -07001131 if (rc) {
Robert Loved5488eb2009-06-10 15:30:59 -07001132 FCOE_NETDEV_DBG(netdev, "Could not configure libfc for the "
1133 "interface\n");
Vasu Dev7f349142009-03-27 09:06:31 -07001134 goto out_lp_destroy;
1135 }
1136
Neerav Parikh6fef3902012-01-22 17:30:10 -08001137 /* Initialized FDMI information */
1138 fcoe_fdmi_info(lport, netdev);
1139
Vasu Dev72fa3962011-02-25 15:03:01 -08001140 /*
1141 * fcoe_em_alloc() and fcoe_hostlist_add() both
1142 * need to be atomic with respect to other changes to the
1143 * hostlist since fcoe_em_alloc() looks for an existing EM
1144 * instance on host list updated by fcoe_hostlist_add().
1145 *
1146 * This is currently handled through the fcoe_config_mutex
1147 * begin held.
1148 */
1149 if (!npiv)
Chris Leech9a057532009-11-03 11:46:40 -08001150 /* lport exch manager allocation */
1151 rc = fcoe_em_config(lport);
Vasu Dev72fa3962011-02-25 15:03:01 -08001152 else {
1153 shost = vport_to_shost(vport);
1154 n_port = shost_priv(shost);
1155 rc = fc_exch_mgr_list_clone(n_port, lport);
1156 }
1157
1158 if (rc) {
1159 FCOE_NETDEV_DBG(netdev, "Could not configure the EM\n");
1160 goto out_lp_destroy;
Vasu Dev96316092009-07-29 17:05:00 -07001161 }
1162
Chris Leechaf7f85d2009-08-25 13:59:24 -07001163 return lport;
Vasu Dev7f349142009-03-27 09:06:31 -07001164
1165out_lp_destroy:
Chris Leechaf7f85d2009-08-25 13:59:24 -07001166 fc_exch_mgr_free(lport);
Vasu Dev7f349142009-03-27 09:06:31 -07001167out_host_put:
Chris Leechaf7f85d2009-08-25 13:59:24 -07001168 scsi_host_put(lport->host);
1169out:
1170 return ERR_PTR(rc);
Vasu Dev7f349142009-03-27 09:06:31 -07001171}
1172
1173/**
Robert Love1875f272009-11-03 11:47:50 -08001174 * fcoe_if_init() - Initialization routine for fcoe.ko
Vasu Dev7f349142009-03-27 09:06:31 -07001175 *
Robert Love1875f272009-11-03 11:47:50 -08001176 * Attaches the SW FCoE transport to the FC transport
1177 *
1178 * Returns: 0 on success
Vasu Dev7f349142009-03-27 09:06:31 -07001179 */
1180static int __init fcoe_if_init(void)
1181{
1182 /* attach to scsi transport */
Yi Zou8ca86f82011-01-28 16:05:11 -08001183 fcoe_nport_scsi_transport =
1184 fc_attach_transport(&fcoe_nport_fc_functions);
1185 fcoe_vport_scsi_transport =
1186 fc_attach_transport(&fcoe_vport_fc_functions);
Vasu Dev7f349142009-03-27 09:06:31 -07001187
Yi Zou8ca86f82011-01-28 16:05:11 -08001188 if (!fcoe_nport_scsi_transport) {
Robert Loved5488eb2009-06-10 15:30:59 -07001189 printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n");
Vasu Dev7f349142009-03-27 09:06:31 -07001190 return -ENODEV;
1191 }
1192
1193 return 0;
1194}
1195
1196/**
Robert Love1875f272009-11-03 11:47:50 -08001197 * fcoe_if_exit() - Tear down fcoe.ko
Vasu Dev7f349142009-03-27 09:06:31 -07001198 *
Robert Love1875f272009-11-03 11:47:50 -08001199 * Detaches the SW FCoE transport from the FC transport
1200 *
1201 * Returns: 0 on success
Vasu Dev7f349142009-03-27 09:06:31 -07001202 */
Bart Van Assche7c9c6842012-01-13 17:26:25 -08001203static int __exit fcoe_if_exit(void)
Vasu Dev7f349142009-03-27 09:06:31 -07001204{
Yi Zou8ca86f82011-01-28 16:05:11 -08001205 fc_release_transport(fcoe_nport_scsi_transport);
1206 fc_release_transport(fcoe_vport_scsi_transport);
1207 fcoe_nport_scsi_transport = NULL;
1208 fcoe_vport_scsi_transport = NULL;
Vasu Dev7f349142009-03-27 09:06:31 -07001209 return 0;
1210}
1211
Robert Love85b4aa42008-12-09 15:10:24 -08001212/**
Robert Love1875f272009-11-03 11:47:50 -08001213 * fcoe_percpu_thread_create() - Create a receive thread for an online CPU
1214 * @cpu: The CPU index of the CPU to create a receive thread for
Robert Love8976f422009-03-17 11:41:46 -07001215 */
1216static void fcoe_percpu_thread_create(unsigned int cpu)
1217{
1218 struct fcoe_percpu_s *p;
1219 struct task_struct *thread;
1220
1221 p = &per_cpu(fcoe_percpu, cpu);
1222
Eric Dumazet5c609ff2011-09-27 21:37:52 -07001223 thread = kthread_create_on_node(fcoe_percpu_receive_thread,
1224 (void *)p, cpu_to_node(cpu),
1225 "fcoethread/%d", cpu);
Robert Love8976f422009-03-17 11:41:46 -07001226
Joe Eykholte7a51992009-08-25 14:04:08 -07001227 if (likely(!IS_ERR(thread))) {
Robert Love8976f422009-03-17 11:41:46 -07001228 kthread_bind(thread, cpu);
1229 wake_up_process(thread);
1230
1231 spin_lock_bh(&p->fcoe_rx_list.lock);
1232 p->thread = thread;
1233 spin_unlock_bh(&p->fcoe_rx_list.lock);
1234 }
1235}
1236
1237/**
Robert Love1875f272009-11-03 11:47:50 -08001238 * fcoe_percpu_thread_destroy() - Remove the receive thread of a CPU
1239 * @cpu: The CPU index of the CPU whose receive thread is to be destroyed
Robert Love8976f422009-03-17 11:41:46 -07001240 *
1241 * Destroys a per-CPU Rx thread. Any pending skbs are moved to the
1242 * current CPU's Rx thread. If the thread being destroyed is bound to
1243 * the CPU processing this context the skbs will be freed.
1244 */
1245static void fcoe_percpu_thread_destroy(unsigned int cpu)
1246{
1247 struct fcoe_percpu_s *p;
1248 struct task_struct *thread;
1249 struct page *crc_eof;
1250 struct sk_buff *skb;
1251#ifdef CONFIG_SMP
1252 struct fcoe_percpu_s *p0;
Joe Eykholtf018b732010-03-12 16:08:55 -08001253 unsigned targ_cpu = get_cpu();
Robert Love8976f422009-03-17 11:41:46 -07001254#endif /* CONFIG_SMP */
1255
Robert Loved5488eb2009-06-10 15:30:59 -07001256 FCOE_DBG("Destroying receive thread for CPU %d\n", cpu);
Robert Love8976f422009-03-17 11:41:46 -07001257
1258 /* Prevent any new skbs from being queued for this CPU. */
1259 p = &per_cpu(fcoe_percpu, cpu);
1260 spin_lock_bh(&p->fcoe_rx_list.lock);
1261 thread = p->thread;
1262 p->thread = NULL;
1263 crc_eof = p->crc_eof_page;
1264 p->crc_eof_page = NULL;
1265 p->crc_eof_offset = 0;
1266 spin_unlock_bh(&p->fcoe_rx_list.lock);
1267
1268#ifdef CONFIG_SMP
1269 /*
1270 * Don't bother moving the skb's if this context is running
1271 * on the same CPU that is having its thread destroyed. This
1272 * can easily happen when the module is removed.
1273 */
1274 if (cpu != targ_cpu) {
1275 p0 = &per_cpu(fcoe_percpu, targ_cpu);
1276 spin_lock_bh(&p0->fcoe_rx_list.lock);
1277 if (p0->thread) {
Robert Loved5488eb2009-06-10 15:30:59 -07001278 FCOE_DBG("Moving frames from CPU %d to CPU %d\n",
1279 cpu, targ_cpu);
Robert Love8976f422009-03-17 11:41:46 -07001280
1281 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
1282 __skb_queue_tail(&p0->fcoe_rx_list, skb);
1283 spin_unlock_bh(&p0->fcoe_rx_list.lock);
1284 } else {
1285 /*
1286 * The targeted CPU is not initialized and cannot accept
Robert Love1875f272009-11-03 11:47:50 -08001287 * new skbs. Unlock the targeted CPU and drop the skbs
Robert Love8976f422009-03-17 11:41:46 -07001288 * on the CPU that is going offline.
1289 */
1290 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
1291 kfree_skb(skb);
1292 spin_unlock_bh(&p0->fcoe_rx_list.lock);
1293 }
1294 } else {
1295 /*
1296 * This scenario occurs when the module is being removed
1297 * and all threads are being destroyed. skbs will continue
1298 * to be shifted from the CPU thread that is being removed
1299 * to the CPU thread associated with the CPU that is processing
1300 * the module removal. Once there is only one CPU Rx thread it
1301 * will reach this case and we will drop all skbs and later
1302 * stop the thread.
1303 */
1304 spin_lock_bh(&p->fcoe_rx_list.lock);
1305 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
1306 kfree_skb(skb);
1307 spin_unlock_bh(&p->fcoe_rx_list.lock);
1308 }
Joe Eykholtf018b732010-03-12 16:08:55 -08001309 put_cpu();
Robert Love8976f422009-03-17 11:41:46 -07001310#else
1311 /*
Chris Leechdd3fd722009-04-21 16:27:36 -07001312 * This a non-SMP scenario where the singular Rx thread is
Robert Love8976f422009-03-17 11:41:46 -07001313 * being removed. Free all skbs and stop the thread.
1314 */
1315 spin_lock_bh(&p->fcoe_rx_list.lock);
1316 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
1317 kfree_skb(skb);
1318 spin_unlock_bh(&p->fcoe_rx_list.lock);
1319#endif
1320
1321 if (thread)
1322 kthread_stop(thread);
1323
1324 if (crc_eof)
1325 put_page(crc_eof);
1326}
1327
1328/**
Robert Love1875f272009-11-03 11:47:50 -08001329 * fcoe_cpu_callback() - Handler for CPU hotplug events
1330 * @nfb: The callback data block
1331 * @action: The event triggering the callback
1332 * @hcpu: The index of the CPU that the event is for
Robert Love8976f422009-03-17 11:41:46 -07001333 *
Robert Love1875f272009-11-03 11:47:50 -08001334 * This creates or destroys per-CPU data for fcoe
Robert Love8976f422009-03-17 11:41:46 -07001335 *
1336 * Returns NOTIFY_OK always.
1337 */
1338static int fcoe_cpu_callback(struct notifier_block *nfb,
1339 unsigned long action, void *hcpu)
1340{
1341 unsigned cpu = (unsigned long)hcpu;
1342
1343 switch (action) {
1344 case CPU_ONLINE:
1345 case CPU_ONLINE_FROZEN:
Robert Loved5488eb2009-06-10 15:30:59 -07001346 FCOE_DBG("CPU %x online: Create Rx thread\n", cpu);
Robert Love8976f422009-03-17 11:41:46 -07001347 fcoe_percpu_thread_create(cpu);
1348 break;
1349 case CPU_DEAD:
1350 case CPU_DEAD_FROZEN:
Robert Loved5488eb2009-06-10 15:30:59 -07001351 FCOE_DBG("CPU %x offline: Remove Rx thread\n", cpu);
Robert Love8976f422009-03-17 11:41:46 -07001352 fcoe_percpu_thread_destroy(cpu);
1353 break;
1354 default:
1355 break;
1356 }
1357 return NOTIFY_OK;
1358}
1359
Robert Love8976f422009-03-17 11:41:46 -07001360/**
Kiran Patil064287e2011-06-20 16:59:20 -07001361 * fcoe_select_cpu() - Selects CPU to handle post-processing of incoming
1362 * command.
Kiran Patil064287e2011-06-20 16:59:20 -07001363 *
Vasu Devd2722812011-07-27 15:11:10 -07001364 * This routine selects next CPU based on cpumask to distribute
1365 * incoming requests in round robin.
Kiran Patil064287e2011-06-20 16:59:20 -07001366 *
Vasu Devd2722812011-07-27 15:11:10 -07001367 * Returns: int CPU number
Kiran Patil064287e2011-06-20 16:59:20 -07001368 */
Vasu Devd2722812011-07-27 15:11:10 -07001369static inline unsigned int fcoe_select_cpu(void)
Kiran Patil064287e2011-06-20 16:59:20 -07001370{
1371 static unsigned int selected_cpu;
1372
Vasu Devd2722812011-07-27 15:11:10 -07001373 selected_cpu = cpumask_next(selected_cpu, cpu_online_mask);
1374 if (selected_cpu >= nr_cpu_ids)
1375 selected_cpu = cpumask_first(cpu_online_mask);
1376
Kiran Patil064287e2011-06-20 16:59:20 -07001377 return selected_cpu;
1378}
1379
1380/**
Robert Love1875f272009-11-03 11:47:50 -08001381 * fcoe_rcv() - Receive packets from a net device
1382 * @skb: The received packet
1383 * @netdev: The net device that the packet was received on
1384 * @ptype: The packet type context
1385 * @olddev: The last device net device
Robert Love85b4aa42008-12-09 15:10:24 -08001386 *
Robert Love1875f272009-11-03 11:47:50 -08001387 * This routine is called by NET_RX_SOFTIRQ. It receives a packet, builds a
1388 * FC frame and passes the frame to libfc.
Robert Love85b4aa42008-12-09 15:10:24 -08001389 *
1390 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001391 */
Bart Van Assche7c9c6842012-01-13 17:26:25 -08001392static int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev,
Robert Love85b4aa42008-12-09 15:10:24 -08001393 struct packet_type *ptype, struct net_device *olddev)
1394{
Robert Love1875f272009-11-03 11:47:50 -08001395 struct fc_lport *lport;
Robert Love85b4aa42008-12-09 15:10:24 -08001396 struct fcoe_rcv_info *fr;
Robert Love619fe4b2012-05-22 19:06:10 -07001397 struct fcoe_ctlr *ctlr;
Chris Leech259ad852009-08-25 13:59:41 -07001398 struct fcoe_interface *fcoe;
Robert Love85b4aa42008-12-09 15:10:24 -08001399 struct fc_frame_header *fh;
Robert Love85b4aa42008-12-09 15:10:24 -08001400 struct fcoe_percpu_s *fps;
Vasu Dev519e5132010-07-20 15:19:32 -07001401 struct ethhdr *eh;
Vasu Devb2f00912009-08-25 13:58:53 -07001402 unsigned int cpu;
Robert Love85b4aa42008-12-09 15:10:24 -08001403
Chris Leech259ad852009-08-25 13:59:41 -07001404 fcoe = container_of(ptype, struct fcoe_interface, fcoe_packet_type);
Robert Love619fe4b2012-05-22 19:06:10 -07001405 ctlr = fcoe_to_ctlr(fcoe);
1406 lport = ctlr->lp;
Robert Love1875f272009-11-03 11:47:50 -08001407 if (unlikely(!lport)) {
1408 FCOE_NETDEV_DBG(netdev, "Cannot find hba structure");
Robert Love85b4aa42008-12-09 15:10:24 -08001409 goto err2;
1410 }
Robert Love1875f272009-11-03 11:47:50 -08001411 if (!lport->link_up)
Joe Eykholt97c83892009-03-17 11:42:40 -07001412 goto err2;
Robert Love85b4aa42008-12-09 15:10:24 -08001413
Robert Love1875f272009-11-03 11:47:50 -08001414 FCOE_NETDEV_DBG(netdev, "skb_info: len:%d data_len:%d head:%p "
Robert Loved5488eb2009-06-10 15:30:59 -07001415 "data:%p tail:%p end:%p sum:%d dev:%s",
1416 skb->len, skb->data_len, skb->head, skb->data,
1417 skb_tail_pointer(skb), skb_end_pointer(skb),
1418 skb->csum, skb->dev ? skb->dev->name : "<NULL>");
Robert Love85b4aa42008-12-09 15:10:24 -08001419
Vasu Dev519e5132010-07-20 15:19:32 -07001420 eh = eth_hdr(skb);
Vasu Dev519e5132010-07-20 15:19:32 -07001421
Robert Love619fe4b2012-05-22 19:06:10 -07001422 if (is_fip_mode(ctlr) &&
1423 compare_ether_addr(eh->h_source, ctlr->dest_addr)) {
Vasu Dev519e5132010-07-20 15:19:32 -07001424 FCOE_NETDEV_DBG(netdev, "wrong source mac address:%pM\n",
1425 eh->h_source);
Robert Love85b4aa42008-12-09 15:10:24 -08001426 goto err;
1427 }
1428
1429 /*
1430 * Check for minimum frame length, and make sure required FCoE
1431 * and FC headers are pulled into the linear data area.
1432 */
1433 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
Robert Love1875f272009-11-03 11:47:50 -08001434 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
Robert Love85b4aa42008-12-09 15:10:24 -08001435 goto err;
1436
1437 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
1438 fh = (struct fc_frame_header *) skb_transport_header(skb);
1439
Robert Love0ee31cb2010-10-08 17:12:46 -07001440 if (ntoh24(&eh->h_dest[3]) != ntoh24(fh->fh_d_id)) {
1441 FCOE_NETDEV_DBG(netdev, "FC frame d_id mismatch with MAC:%pM\n",
1442 eh->h_dest);
1443 goto err;
1444 }
1445
Robert Love85b4aa42008-12-09 15:10:24 -08001446 fr = fcoe_dev_from_skb(skb);
Robert Love1875f272009-11-03 11:47:50 -08001447 fr->fr_dev = lport;
Robert Love5e5e92d2009-03-17 11:41:35 -07001448
Robert Love85b4aa42008-12-09 15:10:24 -08001449 /*
Vasu Devb2f00912009-08-25 13:58:53 -07001450 * In case the incoming frame's exchange is originated from
1451 * the initiator, then received frame's exchange id is ANDed
1452 * with fc_cpu_mask bits to get the same cpu on which exchange
Vasu Devd2722812011-07-27 15:11:10 -07001453 * was originated, otherwise select cpu using rx exchange id
1454 * or fcoe_select_cpu().
Robert Love85b4aa42008-12-09 15:10:24 -08001455 */
Vasu Devb2f00912009-08-25 13:58:53 -07001456 if (ntoh24(fh->fh_f_ctl) & FC_FC_EX_CTX)
1457 cpu = ntohs(fh->fh_ox_id) & fc_cpu_mask;
Kiran Patil064287e2011-06-20 16:59:20 -07001458 else {
Vasu Devd2722812011-07-27 15:11:10 -07001459 if (ntohs(fh->fh_rx_id) == FC_XID_UNKNOWN)
1460 cpu = fcoe_select_cpu();
1461 else
Kiran Patil29bdd2b2011-06-20 16:59:25 -07001462 cpu = ntohs(fh->fh_rx_id) & fc_cpu_mask;
Kiran Patil064287e2011-06-20 16:59:20 -07001463 }
Vasu Dev324f6672011-07-27 15:10:39 -07001464
1465 if (cpu >= nr_cpu_ids)
1466 goto err;
1467
Robert Love8976f422009-03-17 11:41:46 -07001468 fps = &per_cpu(fcoe_percpu, cpu);
Neil Horman94aa29f2012-03-09 14:50:08 -08001469 spin_lock(&fps->fcoe_rx_list.lock);
Robert Love8976f422009-03-17 11:41:46 -07001470 if (unlikely(!fps->thread)) {
1471 /*
1472 * The targeted CPU is not ready, let's target
1473 * the first CPU now. For non-SMP systems this
1474 * will check the same CPU twice.
1475 */
Robert Love1875f272009-11-03 11:47:50 -08001476 FCOE_NETDEV_DBG(netdev, "CPU is online, but no receive thread "
Robert Loved5488eb2009-06-10 15:30:59 -07001477 "ready for incoming skb- using first online "
1478 "CPU.\n");
Robert Love8976f422009-03-17 11:41:46 -07001479
Neil Horman94aa29f2012-03-09 14:50:08 -08001480 spin_unlock(&fps->fcoe_rx_list.lock);
Rusty Russell69571772009-12-17 11:43:14 -06001481 cpu = cpumask_first(cpu_online_mask);
Robert Love8976f422009-03-17 11:41:46 -07001482 fps = &per_cpu(fcoe_percpu, cpu);
Neil Horman94aa29f2012-03-09 14:50:08 -08001483 spin_lock(&fps->fcoe_rx_list.lock);
Robert Love8976f422009-03-17 11:41:46 -07001484 if (!fps->thread) {
Neil Horman94aa29f2012-03-09 14:50:08 -08001485 spin_unlock(&fps->fcoe_rx_list.lock);
Robert Love8976f422009-03-17 11:41:46 -07001486 goto err;
1487 }
1488 }
1489
1490 /*
1491 * We now have a valid CPU that we're targeting for
1492 * this skb. We also have this receive thread locked,
1493 * so we're free to queue skbs into it's queue.
1494 */
Robert Love85b4aa42008-12-09 15:10:24 -08001495
Neil Horman5e70c4c2012-03-09 14:49:48 -08001496 /*
1497 * Note: We used to have a set of conditions under which we would
1498 * call fcoe_recv_frame directly, rather than queuing to the rx list
1499 * as it could save a few cycles, but doing so is prohibited, as
1500 * fcoe_recv_frame has several paths that may sleep, which is forbidden
1501 * in softirq context.
Chris Leech859b7b62009-11-20 14:54:47 -08001502 */
Neil Horman5e70c4c2012-03-09 14:49:48 -08001503 __skb_queue_tail(&fps->fcoe_rx_list, skb);
Neil Horman20dc3812012-03-09 14:50:24 -08001504 if (fps->thread->state == TASK_INTERRUPTIBLE)
Neil Horman5e70c4c2012-03-09 14:49:48 -08001505 wake_up_process(fps->thread);
Neil Horman94aa29f2012-03-09 14:50:08 -08001506 spin_unlock(&fps->fcoe_rx_list.lock);
Robert Love85b4aa42008-12-09 15:10:24 -08001507
1508 return 0;
1509err:
Joe Eykholtf018b732010-03-12 16:08:55 -08001510 per_cpu_ptr(lport->dev_stats, get_cpu())->ErrorFrames++;
1511 put_cpu();
Robert Love85b4aa42008-12-09 15:10:24 -08001512err2:
1513 kfree_skb(skb);
1514 return -1;
1515}
Robert Love85b4aa42008-12-09 15:10:24 -08001516
1517/**
Bhanu Prakash Gollapudi8597ae82011-01-28 16:05:37 -08001518 * fcoe_alloc_paged_crc_eof() - Allocate a page to be used for the trailer CRC
Robert Love1875f272009-11-03 11:47:50 -08001519 * @skb: The packet to be transmitted
1520 * @tlen: The total length of the trailer
1521 *
Robert Love85b4aa42008-12-09 15:10:24 -08001522 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001523 */
Bhanu Prakash Gollapudi8597ae82011-01-28 16:05:37 -08001524static int fcoe_alloc_paged_crc_eof(struct sk_buff *skb, int tlen)
Robert Love85b4aa42008-12-09 15:10:24 -08001525{
1526 struct fcoe_percpu_s *fps;
Bhanu Prakash Gollapudi8597ae82011-01-28 16:05:37 -08001527 int rc;
Robert Love85b4aa42008-12-09 15:10:24 -08001528
Robert Love5e5e92d2009-03-17 11:41:35 -07001529 fps = &get_cpu_var(fcoe_percpu);
Bhanu Prakash Gollapudi8597ae82011-01-28 16:05:37 -08001530 rc = fcoe_get_paged_crc_eof(skb, tlen, fps);
Robert Love5e5e92d2009-03-17 11:41:35 -07001531 put_cpu_var(fcoe_percpu);
Robert Love85b4aa42008-12-09 15:10:24 -08001532
Bhanu Prakash Gollapudi8597ae82011-01-28 16:05:37 -08001533 return rc;
Robert Love85b4aa42008-12-09 15:10:24 -08001534}
Robert Love85b4aa42008-12-09 15:10:24 -08001535
1536/**
Robert Love1875f272009-11-03 11:47:50 -08001537 * fcoe_xmit() - Transmit a FCoE frame
1538 * @lport: The local port that the frame is to be transmitted for
1539 * @fp: The frame to be transmitted
Robert Love85b4aa42008-12-09 15:10:24 -08001540 *
Robert Love1875f272009-11-03 11:47:50 -08001541 * Return: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001542 */
Bart Van Assche7c9c6842012-01-13 17:26:25 -08001543static int fcoe_xmit(struct fc_lport *lport, struct fc_frame *fp)
Robert Love85b4aa42008-12-09 15:10:24 -08001544{
Vasu Dev4bb6b512009-05-06 10:52:34 -07001545 int wlen;
Robert Love85b4aa42008-12-09 15:10:24 -08001546 u32 crc;
1547 struct ethhdr *eh;
1548 struct fcoe_crc_eof *cp;
1549 struct sk_buff *skb;
1550 struct fcoe_dev_stats *stats;
1551 struct fc_frame_header *fh;
1552 unsigned int hlen; /* header length implies the version */
1553 unsigned int tlen; /* trailer length */
1554 unsigned int elen; /* eth header, may include vlan */
Robert Love1875f272009-11-03 11:47:50 -08001555 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudi8597ae82011-01-28 16:05:37 -08001556 struct fcoe_interface *fcoe = port->priv;
Robert Love619fe4b2012-05-22 19:06:10 -07001557 struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe);
Robert Love85b4aa42008-12-09 15:10:24 -08001558 u8 sof, eof;
1559 struct fcoe_hdr *hp;
1560
1561 WARN_ON((fr_len(fp) % sizeof(u32)) != 0);
1562
Robert Love85b4aa42008-12-09 15:10:24 -08001563 fh = fc_frame_header_get(fp);
Joe Eykholt97c83892009-03-17 11:42:40 -07001564 skb = fp_skb(fp);
1565 wlen = skb->len / FCOE_WORD_TO_BYTE;
1566
Robert Love1875f272009-11-03 11:47:50 -08001567 if (!lport->link_up) {
Dan Carpenter3caf02e2009-04-21 16:27:25 -07001568 kfree_skb(skb);
Joe Eykholt97c83892009-03-17 11:42:40 -07001569 return 0;
Robert Love85b4aa42008-12-09 15:10:24 -08001570 }
1571
Joe Eykholt9860eeb2010-03-12 16:07:52 -08001572 if (unlikely(fh->fh_type == FC_TYPE_ELS) &&
Robert Love619fe4b2012-05-22 19:06:10 -07001573 fcoe_ctlr_els_send(ctlr, lport, skb))
Joe Eykholt97c83892009-03-17 11:42:40 -07001574 return 0;
1575
Robert Love85b4aa42008-12-09 15:10:24 -08001576 sof = fr_sof(fp);
1577 eof = fr_eof(fp);
1578
Vasu Dev4e57e1c2009-05-06 10:52:46 -07001579 elen = sizeof(struct ethhdr);
Robert Love85b4aa42008-12-09 15:10:24 -08001580 hlen = sizeof(struct fcoe_hdr);
1581 tlen = sizeof(struct fcoe_crc_eof);
1582 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
1583
1584 /* crc offload */
Robert Love1875f272009-11-03 11:47:50 -08001585 if (likely(lport->crc_offload)) {
Yi Zoucf64bc82012-03-16 23:08:12 +00001586 skb->ip_summed = CHECKSUM_UNNECESSARY;
Robert Love85b4aa42008-12-09 15:10:24 -08001587 skb->csum_start = skb_headroom(skb);
1588 skb->csum_offset = skb->len;
1589 crc = 0;
1590 } else {
1591 skb->ip_summed = CHECKSUM_NONE;
1592 crc = fcoe_fc_crc(fp);
1593 }
1594
Chris Leech014f5c32009-08-25 13:59:30 -07001595 /* copy port crc and eof to the skb buff */
Robert Love85b4aa42008-12-09 15:10:24 -08001596 if (skb_is_nonlinear(skb)) {
1597 skb_frag_t *frag;
Bhanu Prakash Gollapudi8597ae82011-01-28 16:05:37 -08001598 if (fcoe_alloc_paged_crc_eof(skb, tlen)) {
Roel Kluine9041582009-02-27 10:56:22 -08001599 kfree_skb(skb);
Robert Love85b4aa42008-12-09 15:10:24 -08001600 return -ENOMEM;
1601 }
1602 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
Cong Wang77dfce02011-11-25 23:14:23 +08001603 cp = kmap_atomic(skb_frag_page(frag))
Robert Love85b4aa42008-12-09 15:10:24 -08001604 + frag->page_offset;
1605 } else {
1606 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
1607 }
1608
1609 memset(cp, 0, sizeof(*cp));
1610 cp->fcoe_eof = eof;
1611 cp->fcoe_crc32 = cpu_to_le32(~crc);
1612
1613 if (skb_is_nonlinear(skb)) {
Cong Wang77dfce02011-11-25 23:14:23 +08001614 kunmap_atomic(cp);
Robert Love85b4aa42008-12-09 15:10:24 -08001615 cp = NULL;
1616 }
1617
Chris Leech014f5c32009-08-25 13:59:30 -07001618 /* adjust skb network/transport offsets to match mac/fcoe/port */
Robert Love85b4aa42008-12-09 15:10:24 -08001619 skb_push(skb, elen + hlen);
1620 skb_reset_mac_header(skb);
1621 skb_reset_network_header(skb);
1622 skb->mac_len = elen;
Yi Zou211c7382009-02-27 14:06:37 -08001623 skb->protocol = htons(ETH_P_FCOE);
john fastabend6f6c2aa2011-11-18 13:35:56 -08001624 skb->priority = port->priority;
1625
Vasu Devd1483bb2011-09-27 21:38:13 -07001626 if (fcoe->netdev->priv_flags & IFF_802_1Q_VLAN &&
1627 fcoe->realdev->features & NETIF_F_HW_VLAN_TX) {
1628 skb->vlan_tci = VLAN_TAG_PRESENT |
1629 vlan_dev_vlan_id(fcoe->netdev);
1630 skb->dev = fcoe->realdev;
1631 } else
1632 skb->dev = fcoe->netdev;
Robert Love85b4aa42008-12-09 15:10:24 -08001633
1634 /* fill up mac and fcoe headers */
1635 eh = eth_hdr(skb);
1636 eh->h_proto = htons(ETH_P_FCOE);
Robert Love619fe4b2012-05-22 19:06:10 -07001637 memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN);
1638 if (ctlr->map_dest)
Joe Eykholtcd229e42010-07-20 15:20:40 -07001639 memcpy(eh->h_dest + 3, fh->fh_d_id, 3);
Robert Love85b4aa42008-12-09 15:10:24 -08001640
Robert Love619fe4b2012-05-22 19:06:10 -07001641 if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN))
1642 memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN);
Robert Love85b4aa42008-12-09 15:10:24 -08001643 else
Chris Leech11b56182009-11-03 11:46:29 -08001644 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
Robert Love85b4aa42008-12-09 15:10:24 -08001645
1646 hp = (struct fcoe_hdr *)(eh + 1);
1647 memset(hp, 0, sizeof(*hp));
1648 if (FC_FCOE_VER)
1649 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
1650 hp->fcoe_sof = sof;
1651
Yi Zou39ca9a02009-02-27 14:07:15 -08001652 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
Robert Love1875f272009-11-03 11:47:50 -08001653 if (lport->seq_offload && fr_max_payload(fp)) {
Yi Zou39ca9a02009-02-27 14:07:15 -08001654 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
1655 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
1656 } else {
1657 skb_shinfo(skb)->gso_type = 0;
1658 skb_shinfo(skb)->gso_size = 0;
1659 }
Robert Love85b4aa42008-12-09 15:10:24 -08001660 /* update tx stats: regardless if LLD fails */
Joe Eykholtf018b732010-03-12 16:08:55 -08001661 stats = per_cpu_ptr(lport->dev_stats, get_cpu());
Robert Love582b45b2009-03-31 15:51:50 -07001662 stats->TxFrames++;
1663 stats->TxWords += wlen;
Joe Eykholtf018b732010-03-12 16:08:55 -08001664 put_cpu();
Robert Love85b4aa42008-12-09 15:10:24 -08001665
1666 /* send down to lld */
Robert Love1875f272009-11-03 11:47:50 -08001667 fr_dev(fp) = lport;
Vasu Dev980f5152011-07-27 15:11:05 -07001668 fcoe_port_send(port, skb);
Robert Love85b4aa42008-12-09 15:10:24 -08001669 return 0;
1670}
Robert Love85b4aa42008-12-09 15:10:24 -08001671
Robert Love34f42a02009-02-27 10:55:45 -08001672/**
Robert Love1875f272009-11-03 11:47:50 -08001673 * fcoe_percpu_flush_done() - Indicate per-CPU queue flush completion
1674 * @skb: The completed skb (argument required by destructor)
Joe Eykholte7a51992009-08-25 14:04:08 -07001675 */
1676static void fcoe_percpu_flush_done(struct sk_buff *skb)
1677{
1678 complete(&fcoe_flush_completion);
1679}
1680
1681/**
Vasu Dev52ee8322011-01-28 16:03:52 -08001682 * fcoe_filter_frames() - filter out bad fcoe frames, i.e. bad CRC
1683 * @lport: The local port the frame was received on
1684 * @fp: The received frame
1685 *
1686 * Return: 0 on passing filtering checks
1687 */
1688static inline int fcoe_filter_frames(struct fc_lport *lport,
1689 struct fc_frame *fp)
1690{
Robert Love619fe4b2012-05-22 19:06:10 -07001691 struct fcoe_ctlr *ctlr;
Vasu Dev52ee8322011-01-28 16:03:52 -08001692 struct fcoe_interface *fcoe;
1693 struct fc_frame_header *fh;
1694 struct sk_buff *skb = (struct sk_buff *)fp;
1695 struct fcoe_dev_stats *stats;
1696
1697 /*
1698 * We only check CRC if no offload is available and if it is
1699 * it's solicited data, in which case, the FCP layer would
1700 * check it during the copy.
1701 */
1702 if (lport->crc_offload && skb->ip_summed == CHECKSUM_UNNECESSARY)
1703 fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
1704 else
1705 fr_flags(fp) |= FCPHF_CRC_UNCHECKED;
1706
1707 fh = (struct fc_frame_header *) skb_transport_header(skb);
1708 fh = fc_frame_header_get(fp);
1709 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA && fh->fh_type == FC_TYPE_FCP)
1710 return 0;
1711
Bhanu Prakash Gollapudi8597ae82011-01-28 16:05:37 -08001712 fcoe = ((struct fcoe_port *)lport_priv(lport))->priv;
Robert Love619fe4b2012-05-22 19:06:10 -07001713 ctlr = fcoe_to_ctlr(fcoe);
1714 if (is_fip_mode(ctlr) && fc_frame_payload_op(fp) == ELS_LOGO &&
Vasu Dev52ee8322011-01-28 16:03:52 -08001715 ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
1716 FCOE_DBG("fcoe: dropping FCoE lport LOGO in fip mode\n");
1717 return -EINVAL;
1718 }
1719
Dan Carpenterf2f96d22011-02-25 15:03:23 -08001720 if (!(fr_flags(fp) & FCPHF_CRC_UNCHECKED) ||
Vasu Dev52ee8322011-01-28 16:03:52 -08001721 le32_to_cpu(fr_crc(fp)) == ~crc32(~0, skb->data, skb->len)) {
1722 fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
1723 return 0;
1724 }
1725
1726 stats = per_cpu_ptr(lport->dev_stats, get_cpu());
1727 stats->InvalidCRCCount++;
1728 if (stats->InvalidCRCCount < 5)
1729 printk(KERN_WARNING "fcoe: dropping frame with CRC error\n");
Thomas Gleixner7e1e7ea2011-11-11 20:52:01 +01001730 put_cpu();
Vasu Dev52ee8322011-01-28 16:03:52 -08001731 return -EINVAL;
1732}
1733
1734/**
Chris Leech859b7b62009-11-20 14:54:47 -08001735 * fcoe_recv_frame() - process a single received frame
1736 * @skb: frame to process
1737 */
1738static void fcoe_recv_frame(struct sk_buff *skb)
1739{
1740 u32 fr_len;
1741 struct fc_lport *lport;
1742 struct fcoe_rcv_info *fr;
1743 struct fcoe_dev_stats *stats;
Chris Leech859b7b62009-11-20 14:54:47 -08001744 struct fcoe_crc_eof crc_eof;
1745 struct fc_frame *fp;
Chris Leech859b7b62009-11-20 14:54:47 -08001746 struct fcoe_port *port;
1747 struct fcoe_hdr *hp;
1748
1749 fr = fcoe_dev_from_skb(skb);
1750 lport = fr->fr_dev;
1751 if (unlikely(!lport)) {
1752 if (skb->destructor != fcoe_percpu_flush_done)
1753 FCOE_NETDEV_DBG(skb->dev, "NULL lport in skb");
1754 kfree_skb(skb);
1755 return;
1756 }
1757
1758 FCOE_NETDEV_DBG(skb->dev, "skb_info: len:%d data_len:%d "
1759 "head:%p data:%p tail:%p end:%p sum:%d dev:%s",
1760 skb->len, skb->data_len,
1761 skb->head, skb->data, skb_tail_pointer(skb),
1762 skb_end_pointer(skb), skb->csum,
1763 skb->dev ? skb->dev->name : "<NULL>");
1764
Chris Leech859b7b62009-11-20 14:54:47 -08001765 port = lport_priv(lport);
Robert Lovef1633012011-12-16 14:24:49 -08001766 skb_linearize(skb); /* check for skb_is_nonlinear is within skb_linearize */
Chris Leech859b7b62009-11-20 14:54:47 -08001767
1768 /*
1769 * Frame length checks and setting up the header pointers
1770 * was done in fcoe_rcv already.
1771 */
1772 hp = (struct fcoe_hdr *) skb_network_header(skb);
Chris Leech859b7b62009-11-20 14:54:47 -08001773
Joe Eykholtf018b732010-03-12 16:08:55 -08001774 stats = per_cpu_ptr(lport->dev_stats, get_cpu());
Chris Leech859b7b62009-11-20 14:54:47 -08001775 if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) {
1776 if (stats->ErrorFrames < 5)
1777 printk(KERN_WARNING "fcoe: FCoE version "
1778 "mismatch: The frame has "
1779 "version %x, but the "
1780 "initiator supports version "
1781 "%x\n", FC_FCOE_DECAPS_VER(hp),
1782 FC_FCOE_VER);
Joe Eykholtf018b732010-03-12 16:08:55 -08001783 goto drop;
Chris Leech859b7b62009-11-20 14:54:47 -08001784 }
1785
1786 skb_pull(skb, sizeof(struct fcoe_hdr));
1787 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
1788
1789 stats->RxFrames++;
1790 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
1791
1792 fp = (struct fc_frame *)skb;
1793 fc_frame_init(fp);
1794 fr_dev(fp) = lport;
1795 fr_sof(fp) = hp->fcoe_sof;
1796
1797 /* Copy out the CRC and EOF trailer for access */
Joe Eykholtf018b732010-03-12 16:08:55 -08001798 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof)))
1799 goto drop;
Chris Leech859b7b62009-11-20 14:54:47 -08001800 fr_eof(fp) = crc_eof.fcoe_eof;
1801 fr_crc(fp) = crc_eof.fcoe_crc32;
Joe Eykholtf018b732010-03-12 16:08:55 -08001802 if (pskb_trim(skb, fr_len))
1803 goto drop;
Chris Leech859b7b62009-11-20 14:54:47 -08001804
Vasu Dev52ee8322011-01-28 16:03:52 -08001805 if (!fcoe_filter_frames(lport, fp)) {
1806 put_cpu();
1807 fc_exch_recv(lport, fp);
1808 return;
Chris Leech859b7b62009-11-20 14:54:47 -08001809 }
Joe Eykholtf018b732010-03-12 16:08:55 -08001810drop:
1811 stats->ErrorFrames++;
1812 put_cpu();
1813 kfree_skb(skb);
Chris Leech859b7b62009-11-20 14:54:47 -08001814}
1815
1816/**
Robert Love1875f272009-11-03 11:47:50 -08001817 * fcoe_percpu_receive_thread() - The per-CPU packet receive thread
1818 * @arg: The per-CPU context
Robert Love85b4aa42008-12-09 15:10:24 -08001819 *
1820 * Return: 0 for success
Robert Love85b4aa42008-12-09 15:10:24 -08001821 */
Bart Van Assche7c9c6842012-01-13 17:26:25 -08001822static int fcoe_percpu_receive_thread(void *arg)
Robert Love85b4aa42008-12-09 15:10:24 -08001823{
1824 struct fcoe_percpu_s *p = arg;
Robert Love85b4aa42008-12-09 15:10:24 -08001825 struct sk_buff *skb;
Neil Horman20dc3812012-03-09 14:50:24 -08001826 struct sk_buff_head tmp;
1827
1828 skb_queue_head_init(&tmp);
Robert Love85b4aa42008-12-09 15:10:24 -08001829
Robert Love4469c192009-02-27 10:56:38 -08001830 set_user_nice(current, -20);
Robert Love85b4aa42008-12-09 15:10:24 -08001831
1832 while (!kthread_should_stop()) {
1833
1834 spin_lock_bh(&p->fcoe_rx_list.lock);
Neil Horman20dc3812012-03-09 14:50:24 -08001835 skb_queue_splice_init(&p->fcoe_rx_list, &tmp);
1836 spin_unlock_bh(&p->fcoe_rx_list.lock);
1837
1838 while ((skb = __skb_dequeue(&tmp)) != NULL)
1839 fcoe_recv_frame(skb);
1840
1841 spin_lock_bh(&p->fcoe_rx_list.lock);
1842 if (!skb_queue_len(&p->fcoe_rx_list)) {
Robert Love85b4aa42008-12-09 15:10:24 -08001843 set_current_state(TASK_INTERRUPTIBLE);
1844 spin_unlock_bh(&p->fcoe_rx_list.lock);
1845 schedule();
1846 set_current_state(TASK_RUNNING);
Neil Horman20dc3812012-03-09 14:50:24 -08001847 } else
1848 spin_unlock_bh(&p->fcoe_rx_list.lock);
Robert Love85b4aa42008-12-09 15:10:24 -08001849 }
1850 return 0;
1851}
1852
1853/**
Robert Love1875f272009-11-03 11:47:50 -08001854 * fcoe_dev_setup() - Setup the link change notification interface
Robert Love34f42a02009-02-27 10:55:45 -08001855 */
Randy Dunlapb0d428a2009-04-27 21:49:31 -07001856static void fcoe_dev_setup(void)
Robert Love85b4aa42008-12-09 15:10:24 -08001857{
john fastabend6f6c2aa2011-11-18 13:35:56 -08001858 register_dcbevent_notifier(&dcb_notifier);
Robert Love85b4aa42008-12-09 15:10:24 -08001859 register_netdevice_notifier(&fcoe_notifier);
1860}
1861
1862/**
Robert Love1875f272009-11-03 11:47:50 -08001863 * fcoe_dev_cleanup() - Cleanup the link change notification interface
Robert Love34f42a02009-02-27 10:55:45 -08001864 */
Robert Love85b4aa42008-12-09 15:10:24 -08001865static void fcoe_dev_cleanup(void)
1866{
john fastabend6f6c2aa2011-11-18 13:35:56 -08001867 unregister_dcbevent_notifier(&dcb_notifier);
Robert Love85b4aa42008-12-09 15:10:24 -08001868 unregister_netdevice_notifier(&fcoe_notifier);
1869}
1870
john fastabend6f6c2aa2011-11-18 13:35:56 -08001871static struct fcoe_interface *
1872fcoe_hostlist_lookup_realdev_port(struct net_device *netdev)
1873{
1874 struct fcoe_interface *fcoe;
1875 struct net_device *real_dev;
1876
1877 list_for_each_entry(fcoe, &fcoe_hostlist, list) {
1878 if (fcoe->netdev->priv_flags & IFF_802_1Q_VLAN)
1879 real_dev = vlan_dev_real_dev(fcoe->netdev);
1880 else
1881 real_dev = fcoe->netdev;
1882
1883 if (netdev == real_dev)
1884 return fcoe;
1885 }
1886 return NULL;
1887}
1888
1889static int fcoe_dcb_app_notification(struct notifier_block *notifier,
1890 ulong event, void *ptr)
1891{
1892 struct dcb_app_type *entry = ptr;
Robert Love619fe4b2012-05-22 19:06:10 -07001893 struct fcoe_ctlr *ctlr;
john fastabend6f6c2aa2011-11-18 13:35:56 -08001894 struct fcoe_interface *fcoe;
1895 struct net_device *netdev;
1896 struct fcoe_port *port;
1897 int prio;
1898
1899 if (entry->app.selector != DCB_APP_IDTYPE_ETHTYPE)
1900 return NOTIFY_OK;
1901
1902 netdev = dev_get_by_index(&init_net, entry->ifindex);
1903 if (!netdev)
1904 return NOTIFY_OK;
1905
1906 fcoe = fcoe_hostlist_lookup_realdev_port(netdev);
1907 dev_put(netdev);
1908 if (!fcoe)
1909 return NOTIFY_OK;
1910
Robert Love619fe4b2012-05-22 19:06:10 -07001911 ctlr = fcoe_to_ctlr(fcoe);
1912
john fastabend6f6c2aa2011-11-18 13:35:56 -08001913 if (entry->dcbx & DCB_CAP_DCBX_VER_CEE)
1914 prio = ffs(entry->app.priority) - 1;
1915 else
1916 prio = entry->app.priority;
1917
1918 if (prio < 0)
1919 return NOTIFY_OK;
1920
1921 if (entry->app.protocol == ETH_P_FIP ||
1922 entry->app.protocol == ETH_P_FCOE)
Robert Love619fe4b2012-05-22 19:06:10 -07001923 ctlr->priority = prio;
john fastabend6f6c2aa2011-11-18 13:35:56 -08001924
1925 if (entry->app.protocol == ETH_P_FCOE) {
Robert Love619fe4b2012-05-22 19:06:10 -07001926 port = lport_priv(ctlr->lp);
john fastabend6f6c2aa2011-11-18 13:35:56 -08001927 port->priority = prio;
1928 }
1929
1930 return NOTIFY_OK;
1931}
1932
Robert Love85b4aa42008-12-09 15:10:24 -08001933/**
Robert Love1875f272009-11-03 11:47:50 -08001934 * fcoe_device_notification() - Handler for net device events
1935 * @notifier: The context of the notification
1936 * @event: The type of event
1937 * @ptr: The net device that the event was on
Robert Love85b4aa42008-12-09 15:10:24 -08001938 *
Robert Love1875f272009-11-03 11:47:50 -08001939 * This function is called by the Ethernet driver in case of link change event.
Robert Love85b4aa42008-12-09 15:10:24 -08001940 *
1941 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001942 */
Robert Love85b4aa42008-12-09 15:10:24 -08001943static int fcoe_device_notification(struct notifier_block *notifier,
1944 ulong event, void *ptr)
1945{
Robert Love1875f272009-11-03 11:47:50 -08001946 struct fc_lport *lport = NULL;
Vasu Dev1d1b88d2009-07-29 17:05:45 -07001947 struct net_device *netdev = ptr;
Robert Love619fe4b2012-05-22 19:06:10 -07001948 struct fcoe_ctlr *ctlr;
Chris Leech014f5c32009-08-25 13:59:30 -07001949 struct fcoe_interface *fcoe;
Chris Leech2e70e242009-08-25 14:00:23 -07001950 struct fcoe_port *port;
Robert Love85b4aa42008-12-09 15:10:24 -08001951 struct fcoe_dev_stats *stats;
Joe Eykholt97c83892009-03-17 11:42:40 -07001952 u32 link_possible = 1;
Robert Love85b4aa42008-12-09 15:10:24 -08001953 u32 mfs;
1954 int rc = NOTIFY_OK;
1955
Chris Leech014f5c32009-08-25 13:59:30 -07001956 list_for_each_entry(fcoe, &fcoe_hostlist, list) {
Chris Leech25024982009-08-25 13:59:35 -07001957 if (fcoe->netdev == netdev) {
Robert Love619fe4b2012-05-22 19:06:10 -07001958 ctlr = fcoe_to_ctlr(fcoe);
1959 lport = ctlr->lp;
Robert Love85b4aa42008-12-09 15:10:24 -08001960 break;
1961 }
1962 }
Robert Love1875f272009-11-03 11:47:50 -08001963 if (!lport) {
Robert Love85b4aa42008-12-09 15:10:24 -08001964 rc = NOTIFY_DONE;
1965 goto out;
1966 }
1967
Robert Love85b4aa42008-12-09 15:10:24 -08001968 switch (event) {
1969 case NETDEV_DOWN:
1970 case NETDEV_GOING_DOWN:
Joe Eykholt97c83892009-03-17 11:42:40 -07001971 link_possible = 0;
Robert Love85b4aa42008-12-09 15:10:24 -08001972 break;
1973 case NETDEV_UP:
1974 case NETDEV_CHANGE:
Robert Love85b4aa42008-12-09 15:10:24 -08001975 break;
1976 case NETDEV_CHANGEMTU:
Yi Zou7221d7e2009-10-21 16:27:52 -07001977 if (netdev->features & NETIF_F_FCOE_MTU)
1978 break;
Vasu Dev1d1b88d2009-07-29 17:05:45 -07001979 mfs = netdev->mtu - (sizeof(struct fcoe_hdr) +
1980 sizeof(struct fcoe_crc_eof));
Robert Love85b4aa42008-12-09 15:10:24 -08001981 if (mfs >= FC_MIN_MAX_FRAME)
Robert Love1875f272009-11-03 11:47:50 -08001982 fc_set_mfs(lport, mfs);
Robert Love85b4aa42008-12-09 15:10:24 -08001983 break;
1984 case NETDEV_REGISTER:
1985 break;
Chris Leech2e70e242009-08-25 14:00:23 -07001986 case NETDEV_UNREGISTER:
1987 list_del(&fcoe->list);
Robert Love619fe4b2012-05-22 19:06:10 -07001988 port = lport_priv(ctlr->lp);
Tejun Heo2ca32b42011-01-28 16:05:32 -08001989 queue_work(fcoe_wq, &port->destroy_work);
Chris Leech2e70e242009-08-25 14:00:23 -07001990 goto out;
1991 break;
Yi Zou54a5b212010-07-20 15:21:17 -07001992 case NETDEV_FEAT_CHANGE:
1993 fcoe_netdev_features_change(lport, netdev);
1994 break;
Robert Love85b4aa42008-12-09 15:10:24 -08001995 default:
Vasu Dev1d1b88d2009-07-29 17:05:45 -07001996 FCOE_NETDEV_DBG(netdev, "Unknown event %ld "
Robert Loved5488eb2009-06-10 15:30:59 -07001997 "from netdev netlink\n", event);
Robert Love85b4aa42008-12-09 15:10:24 -08001998 }
Robert Love5e4f8fe2010-05-07 15:18:35 -07001999
2000 fcoe_link_speed_update(lport);
2001
Robert Love1875f272009-11-03 11:47:50 -08002002 if (link_possible && !fcoe_link_ok(lport))
Robert Love619fe4b2012-05-22 19:06:10 -07002003 fcoe_ctlr_link_up(ctlr);
2004 else if (fcoe_ctlr_link_down(ctlr)) {
Joe Eykholtf018b732010-03-12 16:08:55 -08002005 stats = per_cpu_ptr(lport->dev_stats, get_cpu());
Joe Eykholt97c83892009-03-17 11:42:40 -07002006 stats->LinkFailureCount++;
Joe Eykholtf018b732010-03-12 16:08:55 -08002007 put_cpu();
Robert Love1875f272009-11-03 11:47:50 -08002008 fcoe_clean_pending_queue(lport);
Robert Love85b4aa42008-12-09 15:10:24 -08002009 }
2010out:
2011 return rc;
2012}
2013
2014/**
Vasu Dev55a66d32009-12-10 09:59:31 -08002015 * fcoe_disable() - Disables a FCoE interface
Yi Zou78a58242011-01-28 16:05:16 -08002016 * @netdev : The net_device object the Ethernet interface to create on
Vasu Dev55a66d32009-12-10 09:59:31 -08002017 *
Yi Zou78a58242011-01-28 16:05:16 -08002018 * Called from fcoe transport.
Vasu Dev55a66d32009-12-10 09:59:31 -08002019 *
2020 * Returns: 0 for success
2021 */
Yi Zou78a58242011-01-28 16:05:16 -08002022static int fcoe_disable(struct net_device *netdev)
Vasu Dev55a66d32009-12-10 09:59:31 -08002023{
Robert Love619fe4b2012-05-22 19:06:10 -07002024 struct fcoe_ctlr *ctlr;
Vasu Dev55a66d32009-12-10 09:59:31 -08002025 struct fcoe_interface *fcoe;
Vasu Dev55a66d32009-12-10 09:59:31 -08002026 int rc = 0;
2027
2028 mutex_lock(&fcoe_config_mutex);
Vasu Dev55a66d32009-12-10 09:59:31 -08002029
Robert Loveee5df622011-04-01 16:05:59 -07002030 rtnl_lock();
Vasu Dev55a66d32009-12-10 09:59:31 -08002031 fcoe = fcoe_hostlist_lookup_port(netdev);
2032 rtnl_unlock();
2033
Chris Leech9ee50e42010-04-09 14:22:23 -07002034 if (fcoe) {
Robert Love619fe4b2012-05-22 19:06:10 -07002035 ctlr = fcoe_to_ctlr(fcoe);
2036 fcoe_ctlr_link_down(ctlr);
2037 fcoe_clean_pending_queue(ctlr->lp);
Chris Leech9ee50e42010-04-09 14:22:23 -07002038 } else
Vasu Dev55a66d32009-12-10 09:59:31 -08002039 rc = -ENODEV;
2040
Vasu Dev55a66d32009-12-10 09:59:31 -08002041 mutex_unlock(&fcoe_config_mutex);
2042 return rc;
2043}
2044
2045/**
2046 * fcoe_enable() - Enables a FCoE interface
Yi Zou78a58242011-01-28 16:05:16 -08002047 * @netdev : The net_device object the Ethernet interface to create on
Vasu Dev55a66d32009-12-10 09:59:31 -08002048 *
Yi Zou78a58242011-01-28 16:05:16 -08002049 * Called from fcoe transport.
Vasu Dev55a66d32009-12-10 09:59:31 -08002050 *
2051 * Returns: 0 for success
2052 */
Yi Zou78a58242011-01-28 16:05:16 -08002053static int fcoe_enable(struct net_device *netdev)
Vasu Dev55a66d32009-12-10 09:59:31 -08002054{
Robert Love619fe4b2012-05-22 19:06:10 -07002055 struct fcoe_ctlr *ctlr;
Vasu Dev55a66d32009-12-10 09:59:31 -08002056 struct fcoe_interface *fcoe;
Vasu Dev55a66d32009-12-10 09:59:31 -08002057 int rc = 0;
2058
2059 mutex_lock(&fcoe_config_mutex);
Robert Loveee5df622011-04-01 16:05:59 -07002060 rtnl_lock();
Vasu Dev55a66d32009-12-10 09:59:31 -08002061 fcoe = fcoe_hostlist_lookup_port(netdev);
2062 rtnl_unlock();
2063
Robert Love619fe4b2012-05-22 19:06:10 -07002064 if (!fcoe) {
Vasu Dev55a66d32009-12-10 09:59:31 -08002065 rc = -ENODEV;
Robert Love619fe4b2012-05-22 19:06:10 -07002066 goto out;
2067 }
Vasu Dev55a66d32009-12-10 09:59:31 -08002068
Robert Love619fe4b2012-05-22 19:06:10 -07002069 ctlr = fcoe_to_ctlr(fcoe);
2070
2071 if (!fcoe_link_ok(ctlr->lp))
2072 fcoe_ctlr_link_up(ctlr);
2073
2074out:
Vasu Dev55a66d32009-12-10 09:59:31 -08002075 mutex_unlock(&fcoe_config_mutex);
2076 return rc;
2077}
2078
2079/**
Robert Love1875f272009-11-03 11:47:50 -08002080 * fcoe_destroy() - Destroy a FCoE interface
Yi Zou78a58242011-01-28 16:05:16 -08002081 * @netdev : The net_device object the Ethernet interface to create on
Robert Love1875f272009-11-03 11:47:50 -08002082 *
Yi Zou78a58242011-01-28 16:05:16 -08002083 * Called from fcoe transport
Robert Love85b4aa42008-12-09 15:10:24 -08002084 *
2085 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08002086 */
Yi Zou78a58242011-01-28 16:05:16 -08002087static int fcoe_destroy(struct net_device *netdev)
Robert Love85b4aa42008-12-09 15:10:24 -08002088{
Robert Love619fe4b2012-05-22 19:06:10 -07002089 struct fcoe_ctlr *ctlr;
Chris Leech030f4e02009-08-25 14:00:02 -07002090 struct fcoe_interface *fcoe;
Vasu Devf04ca1b2011-04-01 16:06:45 -07002091 struct fc_lport *lport;
Neerav Parikhb2085a42011-06-20 16:59:51 -07002092 struct fcoe_port *port;
Mike Christie8eca355f2009-10-21 16:27:44 -07002093 int rc = 0;
Robert Love85b4aa42008-12-09 15:10:24 -08002094
Chris Leechdfc1d0f2009-08-25 14:00:13 -07002095 mutex_lock(&fcoe_config_mutex);
Robert Loveee5df622011-04-01 16:05:59 -07002096 rtnl_lock();
Chris Leech2e70e242009-08-25 14:00:23 -07002097 fcoe = fcoe_hostlist_lookup_port(netdev);
2098 if (!fcoe) {
Robert Love85b4aa42008-12-09 15:10:24 -08002099 rc = -ENODEV;
Yi Zou78a58242011-01-28 16:05:16 -08002100 goto out_nodev;
Robert Love85b4aa42008-12-09 15:10:24 -08002101 }
Robert Love619fe4b2012-05-22 19:06:10 -07002102 ctlr = fcoe_to_ctlr(fcoe);
2103 lport = ctlr->lp;
Neerav Parikhb2085a42011-06-20 16:59:51 -07002104 port = lport_priv(lport);
Yi Zou54a5b212010-07-20 15:21:17 -07002105 list_del(&fcoe->list);
Neerav Parikhb2085a42011-06-20 16:59:51 -07002106 queue_work(fcoe_wq, &port->destroy_work);
Robert Love85b4aa42008-12-09 15:10:24 -08002107out_nodev:
Neerav Parikhb2085a42011-06-20 16:59:51 -07002108 rtnl_unlock();
Chris Leechdfc1d0f2009-08-25 14:00:13 -07002109 mutex_unlock(&fcoe_config_mutex);
Robert Love85b4aa42008-12-09 15:10:24 -08002110 return rc;
2111}
2112
Robert Love1875f272009-11-03 11:47:50 -08002113/**
2114 * fcoe_destroy_work() - Destroy a FCoE port in a deferred work context
2115 * @work: Handle to the FCoE port to be destroyed
2116 */
Chris Leech2e70e242009-08-25 14:00:23 -07002117static void fcoe_destroy_work(struct work_struct *work)
2118{
2119 struct fcoe_port *port;
Neerav Parikhb2085a42011-06-20 16:59:51 -07002120 struct fcoe_interface *fcoe;
Chris Leech2e70e242009-08-25 14:00:23 -07002121
2122 port = container_of(work, struct fcoe_port, destroy_work);
2123 mutex_lock(&fcoe_config_mutex);
Neerav Parikhb2085a42011-06-20 16:59:51 -07002124
Neerav Parikhb2085a42011-06-20 16:59:51 -07002125 fcoe = port->priv;
Chris Leech2e70e242009-08-25 14:00:23 -07002126 fcoe_if_destroy(port->lport);
Robert Loveccefd232012-02-10 17:18:41 -08002127 fcoe_interface_cleanup(fcoe);
Neerav Parikhb2085a42011-06-20 16:59:51 -07002128
Chris Leech2e70e242009-08-25 14:00:23 -07002129 mutex_unlock(&fcoe_config_mutex);
2130}
2131
Robert Love85b4aa42008-12-09 15:10:24 -08002132/**
Yi Zou78a58242011-01-28 16:05:16 -08002133 * fcoe_match() - Check if the FCoE is supported on the given netdevice
2134 * @netdev : The net_device object the Ethernet interface to create on
Robert Love1875f272009-11-03 11:47:50 -08002135 *
Yi Zou78a58242011-01-28 16:05:16 -08002136 * Called from fcoe transport.
2137 *
2138 * Returns: always returns true as this is the default FCoE transport,
2139 * i.e., support all netdevs.
2140 */
2141static bool fcoe_match(struct net_device *netdev)
2142{
2143 return true;
2144}
2145
2146/**
john fastabend6f6c2aa2011-11-18 13:35:56 -08002147 * fcoe_dcb_create() - Initialize DCB attributes and hooks
2148 * @netdev: The net_device object of the L2 link that should be queried
2149 * @port: The fcoe_port to bind FCoE APP priority with
2150 * @
2151 */
2152static void fcoe_dcb_create(struct fcoe_interface *fcoe)
2153{
2154#ifdef CONFIG_DCB
2155 int dcbx;
2156 u8 fup, up;
2157 struct net_device *netdev = fcoe->realdev;
Robert Love619fe4b2012-05-22 19:06:10 -07002158 struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe);
2159 struct fcoe_port *port = lport_priv(ctlr->lp);
john fastabend6f6c2aa2011-11-18 13:35:56 -08002160 struct dcb_app app = {
2161 .priority = 0,
2162 .protocol = ETH_P_FCOE
2163 };
2164
2165 /* setup DCB priority attributes. */
2166 if (netdev && netdev->dcbnl_ops && netdev->dcbnl_ops->getdcbx) {
2167 dcbx = netdev->dcbnl_ops->getdcbx(netdev);
2168
2169 if (dcbx & DCB_CAP_DCBX_VER_IEEE) {
2170 app.selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE;
2171 up = dcb_ieee_getapp_mask(netdev, &app);
2172 app.protocol = ETH_P_FIP;
2173 fup = dcb_ieee_getapp_mask(netdev, &app);
2174 } else {
2175 app.selector = DCB_APP_IDTYPE_ETHTYPE;
2176 up = dcb_getapp(netdev, &app);
2177 app.protocol = ETH_P_FIP;
2178 fup = dcb_getapp(netdev, &app);
2179 }
2180
2181 port->priority = ffs(up) ? ffs(up) - 1 : 0;
Robert Love619fe4b2012-05-22 19:06:10 -07002182 ctlr->priority = ffs(fup) ? ffs(fup) - 1 : port->priority;
john fastabend6f6c2aa2011-11-18 13:35:56 -08002183 }
2184#endif
2185}
2186
2187/**
Yi Zou78a58242011-01-28 16:05:16 -08002188 * fcoe_create() - Create a fcoe interface
2189 * @netdev : The net_device object the Ethernet interface to create on
2190 * @fip_mode: The FIP mode for this creation
2191 *
2192 * Called from fcoe transport
Robert Love85b4aa42008-12-09 15:10:24 -08002193 *
2194 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08002195 */
Yi Zou78a58242011-01-28 16:05:16 -08002196static int fcoe_create(struct net_device *netdev, enum fip_state fip_mode)
Robert Love85b4aa42008-12-09 15:10:24 -08002197{
Neerav Parikhb2085a42011-06-20 16:59:51 -07002198 int rc = 0;
Robert Love619fe4b2012-05-22 19:06:10 -07002199 struct fcoe_ctlr *ctlr;
Chris Leech030f4e02009-08-25 14:00:02 -07002200 struct fcoe_interface *fcoe;
Chris Leechaf7f85d2009-08-25 13:59:24 -07002201 struct fc_lport *lport;
Robert Love85b4aa42008-12-09 15:10:24 -08002202
Chris Leechdfc1d0f2009-08-25 14:00:13 -07002203 mutex_lock(&fcoe_config_mutex);
Robert Loveee5df622011-04-01 16:05:59 -07002204 rtnl_lock();
Vasu Dev34ce27b2010-05-07 15:18:46 -07002205
Robert Love85b4aa42008-12-09 15:10:24 -08002206 /* look for existing lport */
2207 if (fcoe_hostlist_lookup(netdev)) {
2208 rc = -EEXIST;
Yi Zou78a58242011-01-28 16:05:16 -08002209 goto out_nodev;
Robert Love85b4aa42008-12-09 15:10:24 -08002210 }
Robert Love85b4aa42008-12-09 15:10:24 -08002211
Joe Eykholt1dd454d2010-07-20 15:20:46 -07002212 fcoe = fcoe_interface_create(netdev, fip_mode);
Robert Love7287fb92011-01-28 16:03:47 -08002213 if (IS_ERR(fcoe)) {
2214 rc = PTR_ERR(fcoe);
Yi Zou78a58242011-01-28 16:05:16 -08002215 goto out_nodev;
Chris Leech030f4e02009-08-25 14:00:02 -07002216 }
2217
Robert Love619fe4b2012-05-22 19:06:10 -07002218 ctlr = fcoe_to_ctlr(fcoe);
2219
Chris Leech9a057532009-11-03 11:46:40 -08002220 lport = fcoe_if_create(fcoe, &netdev->dev, 0);
Chris Leechaf7f85d2009-08-25 13:59:24 -07002221 if (IS_ERR(lport)) {
Robert Loved5488eb2009-06-10 15:30:59 -07002222 printk(KERN_ERR "fcoe: Failed to create interface (%s)\n",
Robert Love85b4aa42008-12-09 15:10:24 -08002223 netdev->name);
Robert Love85b4aa42008-12-09 15:10:24 -08002224 rc = -EIO;
Robert Love848e7d52011-08-25 12:40:47 -07002225 rtnl_unlock();
Chris Leech2e70e242009-08-25 14:00:23 -07002226 fcoe_interface_cleanup(fcoe);
Robert Love848e7d52011-08-25 12:40:47 -07002227 goto out_nortnl;
Robert Love85b4aa42008-12-09 15:10:24 -08002228 }
Chris Leech030f4e02009-08-25 14:00:02 -07002229
Chris Leech54b649f2009-08-25 14:00:07 -07002230 /* Make this the "master" N_Port */
Robert Love619fe4b2012-05-22 19:06:10 -07002231 ctlr->lp = lport;
Chris Leech030f4e02009-08-25 14:00:02 -07002232
john fastabend6f6c2aa2011-11-18 13:35:56 -08002233 /* setup DCB priority attributes. */
2234 fcoe_dcb_create(fcoe);
2235
Chris Leechc863df32009-08-25 14:00:18 -07002236 /* add to lports list */
2237 fcoe_hostlist_add(lport);
2238
Chris Leech54b649f2009-08-25 14:00:07 -07002239 /* start FIP Discovery and FLOGI */
2240 lport->boot_time = jiffies;
2241 fc_fabric_login(lport);
Robert Love22805122012-03-13 18:22:12 -07002242 if (!fcoe_link_ok(lport)) {
2243 rtnl_unlock();
Robert Love619fe4b2012-05-22 19:06:10 -07002244 fcoe_ctlr_link_up(ctlr);
Robert Love22805122012-03-13 18:22:12 -07002245 mutex_unlock(&fcoe_config_mutex);
2246 return rc;
2247 }
Chris Leech54b649f2009-08-25 14:00:07 -07002248
Robert Love85b4aa42008-12-09 15:10:24 -08002249out_nodev:
Vasu Dev34ce27b2010-05-07 15:18:46 -07002250 rtnl_unlock();
Robert Love848e7d52011-08-25 12:40:47 -07002251out_nortnl:
Chris Leechdfc1d0f2009-08-25 14:00:13 -07002252 mutex_unlock(&fcoe_config_mutex);
Robert Love85b4aa42008-12-09 15:10:24 -08002253 return rc;
2254}
2255
Robert Love34f42a02009-02-27 10:55:45 -08002256/**
Robert Love5e4f8fe2010-05-07 15:18:35 -07002257 * fcoe_link_speed_update() - Update the supported and actual link speeds
2258 * @lport: The local port to update speeds for
Robert Love85b4aa42008-12-09 15:10:24 -08002259 *
Robert Love5e4f8fe2010-05-07 15:18:35 -07002260 * Returns: 0 if the ethtool query was successful
2261 * -1 if the ethtool query failed
Robert Love85b4aa42008-12-09 15:10:24 -08002262 */
Bart Van Assche7c9c6842012-01-13 17:26:25 -08002263static int fcoe_link_speed_update(struct fc_lport *lport)
Robert Love85b4aa42008-12-09 15:10:24 -08002264{
Bhanu Prakash Gollapudi8597ae82011-01-28 16:05:37 -08002265 struct net_device *netdev = fcoe_netdev(lport);
David Decotigny8ae6daca2011-04-27 18:32:38 +00002266 struct ethtool_cmd ecmd;
Robert Love85b4aa42008-12-09 15:10:24 -08002267
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00002268 if (!__ethtool_get_settings(netdev, &ecmd)) {
Robert Love1875f272009-11-03 11:47:50 -08002269 lport->link_supported_speeds &=
Yi Zou2f718d62009-07-29 17:04:01 -07002270 ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
2271 if (ecmd.supported & (SUPPORTED_1000baseT_Half |
2272 SUPPORTED_1000baseT_Full))
Robert Love1875f272009-11-03 11:47:50 -08002273 lport->link_supported_speeds |= FC_PORTSPEED_1GBIT;
Yi Zou2f718d62009-07-29 17:04:01 -07002274 if (ecmd.supported & SUPPORTED_10000baseT_Full)
Robert Love1875f272009-11-03 11:47:50 -08002275 lport->link_supported_speeds |=
Yi Zou2f718d62009-07-29 17:04:01 -07002276 FC_PORTSPEED_10GBIT;
David Decotigny8ae6daca2011-04-27 18:32:38 +00002277 switch (ethtool_cmd_speed(&ecmd)) {
2278 case SPEED_1000:
Robert Love1875f272009-11-03 11:47:50 -08002279 lport->link_speed = FC_PORTSPEED_1GBIT;
David Decotigny8ae6daca2011-04-27 18:32:38 +00002280 break;
2281 case SPEED_10000:
Robert Love1875f272009-11-03 11:47:50 -08002282 lport->link_speed = FC_PORTSPEED_10GBIT;
David Decotigny8ae6daca2011-04-27 18:32:38 +00002283 break;
2284 }
Yi Zou2f718d62009-07-29 17:04:01 -07002285 return 0;
2286 }
2287 return -1;
Robert Love85b4aa42008-12-09 15:10:24 -08002288}
Robert Love85b4aa42008-12-09 15:10:24 -08002289
Robert Love34f42a02009-02-27 10:55:45 -08002290/**
Robert Love5e4f8fe2010-05-07 15:18:35 -07002291 * fcoe_link_ok() - Check if the link is OK for a local port
2292 * @lport: The local port to check link on
2293 *
2294 * Returns: 0 if link is UP and OK, -1 if not
2295 *
2296 */
Bart Van Assche7c9c6842012-01-13 17:26:25 -08002297static int fcoe_link_ok(struct fc_lport *lport)
Robert Love5e4f8fe2010-05-07 15:18:35 -07002298{
Bhanu Prakash Gollapudi8597ae82011-01-28 16:05:37 -08002299 struct net_device *netdev = fcoe_netdev(lport);
Robert Love5e4f8fe2010-05-07 15:18:35 -07002300
2301 if (netif_oper_up(netdev))
2302 return 0;
2303 return -1;
2304}
2305
2306/**
Robert Love1875f272009-11-03 11:47:50 -08002307 * fcoe_percpu_clean() - Clear all pending skbs for an local port
2308 * @lport: The local port whose skbs are to be cleared
Joe Eykholte7a51992009-08-25 14:04:08 -07002309 *
2310 * Must be called with fcoe_create_mutex held to single-thread completion.
2311 *
2312 * This flushes the pending skbs by adding a new skb to each queue and
2313 * waiting until they are all freed. This assures us that not only are
2314 * there no packets that will be handled by the lport, but also that any
2315 * threads already handling packet have returned.
Robert Love85b4aa42008-12-09 15:10:24 -08002316 */
Bart Van Assche7c9c6842012-01-13 17:26:25 -08002317static void fcoe_percpu_clean(struct fc_lport *lport)
Robert Love85b4aa42008-12-09 15:10:24 -08002318{
Robert Love85b4aa42008-12-09 15:10:24 -08002319 struct fcoe_percpu_s *pp;
Neil Hormandd060e72012-03-09 14:50:19 -08002320 struct sk_buff *skb;
Robert Love5e5e92d2009-03-17 11:41:35 -07002321 unsigned int cpu;
Robert Love85b4aa42008-12-09 15:10:24 -08002322
Robert Love5e5e92d2009-03-17 11:41:35 -07002323 for_each_possible_cpu(cpu) {
2324 pp = &per_cpu(fcoe_percpu, cpu);
Joe Eykholte7a51992009-08-25 14:04:08 -07002325
Neil Hormandd060e72012-03-09 14:50:19 -08002326 if (!pp->thread || !cpu_online(cpu))
Joe Eykholte7a51992009-08-25 14:04:08 -07002327 continue;
Joe Eykholte7a51992009-08-25 14:04:08 -07002328
2329 skb = dev_alloc_skb(0);
Dan Carpenterb3b8abd2012-04-20 12:16:54 -07002330 if (!skb)
Joe Eykholte7a51992009-08-25 14:04:08 -07002331 continue;
Dan Carpenterb3b8abd2012-04-20 12:16:54 -07002332
Joe Eykholte7a51992009-08-25 14:04:08 -07002333 skb->destructor = fcoe_percpu_flush_done;
2334
Neil Hormandd060e72012-03-09 14:50:19 -08002335 spin_lock_bh(&pp->fcoe_rx_list.lock);
Joe Eykholte7a51992009-08-25 14:04:08 -07002336 __skb_queue_tail(&pp->fcoe_rx_list, skb);
2337 if (pp->fcoe_rx_list.qlen == 1)
2338 wake_up_process(pp->thread);
Robert Love5e5e92d2009-03-17 11:41:35 -07002339 spin_unlock_bh(&pp->fcoe_rx_list.lock);
Joe Eykholte7a51992009-08-25 14:04:08 -07002340
2341 wait_for_completion(&fcoe_flush_completion);
Robert Love85b4aa42008-12-09 15:10:24 -08002342 }
2343}
Robert Love85b4aa42008-12-09 15:10:24 -08002344
2345/**
Robert Love1875f272009-11-03 11:47:50 -08002346 * fcoe_reset() - Reset a local port
2347 * @shost: The SCSI host associated with the local port to be reset
Robert Love85b4aa42008-12-09 15:10:24 -08002348 *
Robert Love1875f272009-11-03 11:47:50 -08002349 * Returns: Always 0 (return value required by FC transport template)
Robert Love85b4aa42008-12-09 15:10:24 -08002350 */
Bart Van Assche7c9c6842012-01-13 17:26:25 -08002351static int fcoe_reset(struct Scsi_Host *shost)
Robert Love85b4aa42008-12-09 15:10:24 -08002352{
2353 struct fc_lport *lport = shost_priv(shost);
Vasu Devd2f80952011-02-25 15:03:28 -08002354 struct fcoe_port *port = lport_priv(lport);
2355 struct fcoe_interface *fcoe = port->priv;
Robert Love619fe4b2012-05-22 19:06:10 -07002356 struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe);
Vasu Devd2f80952011-02-25 15:03:28 -08002357
Robert Love619fe4b2012-05-22 19:06:10 -07002358 fcoe_ctlr_link_down(ctlr);
2359 fcoe_clean_pending_queue(ctlr->lp);
2360 if (!fcoe_link_ok(ctlr->lp))
2361 fcoe_ctlr_link_up(ctlr);
Robert Love85b4aa42008-12-09 15:10:24 -08002362 return 0;
2363}
Robert Love85b4aa42008-12-09 15:10:24 -08002364
Robert Love34f42a02009-02-27 10:55:45 -08002365/**
Robert Love1875f272009-11-03 11:47:50 -08002366 * fcoe_hostlist_lookup_port() - Find the FCoE interface associated with a net device
2367 * @netdev: The net device used as a key
Robert Love85b4aa42008-12-09 15:10:24 -08002368 *
Robert Love1875f272009-11-03 11:47:50 -08002369 * Locking: Must be called with the RNL mutex held.
2370 *
2371 * Returns: NULL or the FCoE interface
Robert Love85b4aa42008-12-09 15:10:24 -08002372 */
Chris Leech014f5c32009-08-25 13:59:30 -07002373static struct fcoe_interface *
Robert Love1875f272009-11-03 11:47:50 -08002374fcoe_hostlist_lookup_port(const struct net_device *netdev)
Robert Love85b4aa42008-12-09 15:10:24 -08002375{
Chris Leech014f5c32009-08-25 13:59:30 -07002376 struct fcoe_interface *fcoe;
Robert Love85b4aa42008-12-09 15:10:24 -08002377
Chris Leech014f5c32009-08-25 13:59:30 -07002378 list_for_each_entry(fcoe, &fcoe_hostlist, list) {
Robert Love1875f272009-11-03 11:47:50 -08002379 if (fcoe->netdev == netdev)
Chris Leech014f5c32009-08-25 13:59:30 -07002380 return fcoe;
Robert Love85b4aa42008-12-09 15:10:24 -08002381 }
Robert Love85b4aa42008-12-09 15:10:24 -08002382 return NULL;
2383}
2384
Robert Love34f42a02009-02-27 10:55:45 -08002385/**
Robert Love1875f272009-11-03 11:47:50 -08002386 * fcoe_hostlist_lookup() - Find the local port associated with a
2387 * given net device
2388 * @netdev: The netdevice used as a key
Robert Love85b4aa42008-12-09 15:10:24 -08002389 *
Robert Love1875f272009-11-03 11:47:50 -08002390 * Locking: Must be called with the RTNL mutex held
2391 *
2392 * Returns: NULL or the local port
Robert Love85b4aa42008-12-09 15:10:24 -08002393 */
Chris Leech090eb6c2009-08-25 14:00:28 -07002394static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev)
Robert Love85b4aa42008-12-09 15:10:24 -08002395{
Robert Love619fe4b2012-05-22 19:06:10 -07002396 struct fcoe_ctlr *ctlr;
Chris Leech014f5c32009-08-25 13:59:30 -07002397 struct fcoe_interface *fcoe;
Robert Love85b4aa42008-12-09 15:10:24 -08002398
Chris Leech014f5c32009-08-25 13:59:30 -07002399 fcoe = fcoe_hostlist_lookup_port(netdev);
Robert Love619fe4b2012-05-22 19:06:10 -07002400 ctlr = fcoe_to_ctlr(fcoe);
2401 return (fcoe) ? ctlr->lp : NULL;
Robert Love85b4aa42008-12-09 15:10:24 -08002402}
Robert Love85b4aa42008-12-09 15:10:24 -08002403
Robert Love34f42a02009-02-27 10:55:45 -08002404/**
Robert Love1875f272009-11-03 11:47:50 -08002405 * fcoe_hostlist_add() - Add the FCoE interface identified by a local
2406 * port to the hostlist
2407 * @lport: The local port that identifies the FCoE interface to be added
2408 *
2409 * Locking: must be called with the RTNL mutex held
Robert Love85b4aa42008-12-09 15:10:24 -08002410 *
2411 * Returns: 0 for success
2412 */
Chris Leech090eb6c2009-08-25 14:00:28 -07002413static int fcoe_hostlist_add(const struct fc_lport *lport)
Robert Love85b4aa42008-12-09 15:10:24 -08002414{
Chris Leech014f5c32009-08-25 13:59:30 -07002415 struct fcoe_interface *fcoe;
2416 struct fcoe_port *port;
Robert Love85b4aa42008-12-09 15:10:24 -08002417
Chris Leech014f5c32009-08-25 13:59:30 -07002418 fcoe = fcoe_hostlist_lookup_port(fcoe_netdev(lport));
2419 if (!fcoe) {
2420 port = lport_priv(lport);
Bhanu Prakash Gollapudi8597ae82011-01-28 16:05:37 -08002421 fcoe = port->priv;
Chris Leech014f5c32009-08-25 13:59:30 -07002422 list_add_tail(&fcoe->list, &fcoe_hostlist);
Robert Love85b4aa42008-12-09 15:10:24 -08002423 }
2424 return 0;
2425}
Robert Love85b4aa42008-12-09 15:10:24 -08002426
Yi Zou78a58242011-01-28 16:05:16 -08002427
2428static struct fcoe_transport fcoe_sw_transport = {
2429 .name = {FCOE_TRANSPORT_DEFAULT},
2430 .attached = false,
2431 .list = LIST_HEAD_INIT(fcoe_sw_transport.list),
2432 .match = fcoe_match,
2433 .create = fcoe_create,
2434 .destroy = fcoe_destroy,
2435 .enable = fcoe_enable,
2436 .disable = fcoe_disable,
2437};
2438
Robert Love34f42a02009-02-27 10:55:45 -08002439/**
Robert Love1875f272009-11-03 11:47:50 -08002440 * fcoe_init() - Initialize fcoe.ko
Robert Love85b4aa42008-12-09 15:10:24 -08002441 *
Robert Love1875f272009-11-03 11:47:50 -08002442 * Returns: 0 on success, or a negative value on failure
Robert Love34f42a02009-02-27 10:55:45 -08002443 */
Robert Love85b4aa42008-12-09 15:10:24 -08002444static int __init fcoe_init(void)
2445{
Robert Love1875f272009-11-03 11:47:50 -08002446 struct fcoe_percpu_s *p;
Robert Love38eccab2009-03-17 11:41:30 -07002447 unsigned int cpu;
Robert Love8976f422009-03-17 11:41:46 -07002448 int rc = 0;
Robert Love85b4aa42008-12-09 15:10:24 -08002449
Tejun Heo2ca32b42011-01-28 16:05:32 -08002450 fcoe_wq = alloc_workqueue("fcoe", 0, 0);
2451 if (!fcoe_wq)
2452 return -ENOMEM;
2453
Yi Zou78a58242011-01-28 16:05:16 -08002454 /* register as a fcoe transport */
2455 rc = fcoe_transport_attach(&fcoe_sw_transport);
2456 if (rc) {
2457 printk(KERN_ERR "failed to register an fcoe transport, check "
2458 "if libfcoe is loaded\n");
2459 return rc;
2460 }
2461
Chris Leechdfc1d0f2009-08-25 14:00:13 -07002462 mutex_lock(&fcoe_config_mutex);
2463
Robert Love38eccab2009-03-17 11:41:30 -07002464 for_each_possible_cpu(cpu) {
Robert Love5e5e92d2009-03-17 11:41:35 -07002465 p = &per_cpu(fcoe_percpu, cpu);
Robert Love38eccab2009-03-17 11:41:30 -07002466 skb_queue_head_init(&p->fcoe_rx_list);
2467 }
2468
Robert Love8976f422009-03-17 11:41:46 -07002469 for_each_online_cpu(cpu)
2470 fcoe_percpu_thread_create(cpu);
Robert Love85b4aa42008-12-09 15:10:24 -08002471
Robert Love8976f422009-03-17 11:41:46 -07002472 /* Initialize per CPU interrupt thread */
2473 rc = register_hotcpu_notifier(&fcoe_cpu_notifier);
2474 if (rc)
2475 goto out_free;
Robert Love85b4aa42008-12-09 15:10:24 -08002476
Robert Love8976f422009-03-17 11:41:46 -07002477 /* Setup link change notification */
Robert Love85b4aa42008-12-09 15:10:24 -08002478 fcoe_dev_setup();
2479
Chris Leech5892c322009-08-25 13:59:14 -07002480 rc = fcoe_if_init();
2481 if (rc)
2482 goto out_free;
Robert Love85b4aa42008-12-09 15:10:24 -08002483
Chris Leechdfc1d0f2009-08-25 14:00:13 -07002484 mutex_unlock(&fcoe_config_mutex);
Robert Love85b4aa42008-12-09 15:10:24 -08002485 return 0;
Robert Love8976f422009-03-17 11:41:46 -07002486
2487out_free:
2488 for_each_online_cpu(cpu) {
2489 fcoe_percpu_thread_destroy(cpu);
2490 }
Chris Leechdfc1d0f2009-08-25 14:00:13 -07002491 mutex_unlock(&fcoe_config_mutex);
Tejun Heo2ca32b42011-01-28 16:05:32 -08002492 destroy_workqueue(fcoe_wq);
Robert Love8976f422009-03-17 11:41:46 -07002493 return rc;
Robert Love85b4aa42008-12-09 15:10:24 -08002494}
2495module_init(fcoe_init);
2496
2497/**
Robert Love1875f272009-11-03 11:47:50 -08002498 * fcoe_exit() - Clean up fcoe.ko
Robert Love85b4aa42008-12-09 15:10:24 -08002499 *
Robert Love1875f272009-11-03 11:47:50 -08002500 * Returns: 0 on success or a negative value on failure
Robert Love34f42a02009-02-27 10:55:45 -08002501 */
Robert Love85b4aa42008-12-09 15:10:24 -08002502static void __exit fcoe_exit(void)
2503{
Chris Leech014f5c32009-08-25 13:59:30 -07002504 struct fcoe_interface *fcoe, *tmp;
Robert Love619fe4b2012-05-22 19:06:10 -07002505 struct fcoe_ctlr *ctlr;
Chris Leech2e70e242009-08-25 14:00:23 -07002506 struct fcoe_port *port;
Robert Love1875f272009-11-03 11:47:50 -08002507 unsigned int cpu;
Robert Love85b4aa42008-12-09 15:10:24 -08002508
Chris Leechdfc1d0f2009-08-25 14:00:13 -07002509 mutex_lock(&fcoe_config_mutex);
2510
Robert Love85b4aa42008-12-09 15:10:24 -08002511 fcoe_dev_cleanup();
2512
Vasu Dev5919a592009-03-27 09:03:29 -07002513 /* releases the associated fcoe hosts */
Chris Leech090eb6c2009-08-25 14:00:28 -07002514 rtnl_lock();
2515 list_for_each_entry_safe(fcoe, tmp, &fcoe_hostlist, list) {
Chris Leechc863df32009-08-25 14:00:18 -07002516 list_del(&fcoe->list);
Robert Love619fe4b2012-05-22 19:06:10 -07002517 ctlr = fcoe_to_ctlr(fcoe);
2518 port = lport_priv(ctlr->lp);
Tejun Heo2ca32b42011-01-28 16:05:32 -08002519 queue_work(fcoe_wq, &port->destroy_work);
Chris Leechc863df32009-08-25 14:00:18 -07002520 }
Chris Leech090eb6c2009-08-25 14:00:28 -07002521 rtnl_unlock();
Robert Love85b4aa42008-12-09 15:10:24 -08002522
Robert Love8976f422009-03-17 11:41:46 -07002523 unregister_hotcpu_notifier(&fcoe_cpu_notifier);
2524
Chris Leech014f5c32009-08-25 13:59:30 -07002525 for_each_online_cpu(cpu)
Robert Love8976f422009-03-17 11:41:46 -07002526 fcoe_percpu_thread_destroy(cpu);
Robert Love85b4aa42008-12-09 15:10:24 -08002527
Chris Leechdfc1d0f2009-08-25 14:00:13 -07002528 mutex_unlock(&fcoe_config_mutex);
Chris Leech2e70e242009-08-25 14:00:23 -07002529
Tejun Heo2ca32b42011-01-28 16:05:32 -08002530 /*
2531 * destroy_work's may be chained but destroy_workqueue()
2532 * can take care of them. Just kill the fcoe_wq.
2533 */
2534 destroy_workqueue(fcoe_wq);
Chris Leech2e70e242009-08-25 14:00:23 -07002535
Tejun Heo2ca32b42011-01-28 16:05:32 -08002536 /*
2537 * Detaching from the scsi transport must happen after all
2538 * destroys are done on the fcoe_wq. destroy_workqueue will
2539 * enusre the fcoe_wq is flushed.
2540 */
Chris Leech2e70e242009-08-25 14:00:23 -07002541 fcoe_if_exit();
Yi Zou78a58242011-01-28 16:05:16 -08002542
2543 /* detach from fcoe transport */
2544 fcoe_transport_detach(&fcoe_sw_transport);
Robert Love85b4aa42008-12-09 15:10:24 -08002545}
2546module_exit(fcoe_exit);
Chris Leech11b56182009-11-03 11:46:29 -08002547
2548/**
2549 * fcoe_flogi_resp() - FCoE specific FLOGI and FDISC response handler
2550 * @seq: active sequence in the FLOGI or FDISC exchange
2551 * @fp: response frame, or error encoded in a pointer (timeout)
2552 * @arg: pointer the the fcoe_ctlr structure
2553 *
Uwe Kleine-König65155b32010-06-11 12:17:01 +02002554 * This handles MAC address management for FCoE, then passes control on to
Chris Leech11b56182009-11-03 11:46:29 -08002555 * the libfc FLOGI response handler.
2556 */
2557static void fcoe_flogi_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg)
2558{
2559 struct fcoe_ctlr *fip = arg;
2560 struct fc_exch *exch = fc_seq_exch(seq);
2561 struct fc_lport *lport = exch->lp;
2562 u8 *mac;
2563
2564 if (IS_ERR(fp))
2565 goto done;
2566
2567 mac = fr_cb(fp)->granted_mac;
Vasu Dev907c07d2011-10-28 11:34:23 -07002568 /* pre-FIP */
2569 if (is_zero_ether_addr(mac))
2570 fcoe_ctlr_recv_flogi(fip, lport, fp);
2571 if (!is_zero_ether_addr(mac))
2572 fcoe_update_src_mac(lport, mac);
Chris Leech11b56182009-11-03 11:46:29 -08002573done:
2574 fc_lport_flogi_resp(seq, fp, lport);
2575}
2576
2577/**
2578 * fcoe_logo_resp() - FCoE specific LOGO response handler
2579 * @seq: active sequence in the LOGO exchange
2580 * @fp: response frame, or error encoded in a pointer (timeout)
2581 * @arg: pointer the the fcoe_ctlr structure
2582 *
Uwe Kleine-König65155b32010-06-11 12:17:01 +02002583 * This handles MAC address management for FCoE, then passes control on to
Chris Leech11b56182009-11-03 11:46:29 -08002584 * the libfc LOGO response handler.
2585 */
2586static void fcoe_logo_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg)
2587{
Joe Eykholt386309ce2009-11-03 11:49:16 -08002588 struct fc_lport *lport = arg;
Chris Leech11b56182009-11-03 11:46:29 -08002589 static u8 zero_mac[ETH_ALEN] = { 0 };
2590
2591 if (!IS_ERR(fp))
Joe Eykholt386309ce2009-11-03 11:49:16 -08002592 fcoe_update_src_mac(lport, zero_mac);
Chris Leech11b56182009-11-03 11:46:29 -08002593 fc_lport_logo_resp(seq, fp, lport);
2594}
2595
2596/**
2597 * fcoe_elsct_send - FCoE specific ELS handler
2598 *
2599 * This does special case handling of FIP encapsualted ELS exchanges for FCoE,
2600 * using FCoE specific response handlers and passing the FIP controller as
2601 * the argument (the lport is still available from the exchange).
2602 *
2603 * Most of the work here is just handed off to the libfc routine.
2604 */
Robert Love1875f272009-11-03 11:47:50 -08002605static struct fc_seq *fcoe_elsct_send(struct fc_lport *lport, u32 did,
2606 struct fc_frame *fp, unsigned int op,
2607 void (*resp)(struct fc_seq *,
2608 struct fc_frame *,
2609 void *),
2610 void *arg, u32 timeout)
Chris Leech11b56182009-11-03 11:46:29 -08002611{
2612 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudi8597ae82011-01-28 16:05:37 -08002613 struct fcoe_interface *fcoe = port->priv;
Robert Love619fe4b2012-05-22 19:06:10 -07002614 struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe);
Chris Leech11b56182009-11-03 11:46:29 -08002615 struct fc_frame_header *fh = fc_frame_header_get(fp);
2616
2617 switch (op) {
2618 case ELS_FLOGI:
2619 case ELS_FDISC:
Joe Eykholte10f8c62010-07-20 15:20:30 -07002620 if (lport->point_to_multipoint)
2621 break;
Chris Leech11b56182009-11-03 11:46:29 -08002622 return fc_elsct_send(lport, did, fp, op, fcoe_flogi_resp,
2623 fip, timeout);
2624 case ELS_LOGO:
2625 /* only hook onto fabric logouts, not port logouts */
2626 if (ntoh24(fh->fh_d_id) != FC_FID_FLOGI)
2627 break;
2628 return fc_elsct_send(lport, did, fp, op, fcoe_logo_resp,
Joe Eykholt386309ce2009-11-03 11:49:16 -08002629 lport, timeout);
Chris Leech11b56182009-11-03 11:46:29 -08002630 }
2631 return fc_elsct_send(lport, did, fp, op, resp, arg, timeout);
2632}
2633
Chris Leech9a057532009-11-03 11:46:40 -08002634/**
2635 * fcoe_vport_create() - create an fc_host/scsi_host for a vport
2636 * @vport: fc_vport object to create a new fc_host for
2637 * @disabled: start the new fc_host in a disabled state by default?
2638 *
2639 * Returns: 0 for success
2640 */
2641static int fcoe_vport_create(struct fc_vport *vport, bool disabled)
2642{
2643 struct Scsi_Host *shost = vport_to_shost(vport);
2644 struct fc_lport *n_port = shost_priv(shost);
2645 struct fcoe_port *port = lport_priv(n_port);
Bhanu Prakash Gollapudi8597ae82011-01-28 16:05:37 -08002646 struct fcoe_interface *fcoe = port->priv;
Chris Leech9a057532009-11-03 11:46:40 -08002647 struct net_device *netdev = fcoe->netdev;
2648 struct fc_lport *vn_port;
Neerav Parikhbdf25212011-05-16 16:45:29 -07002649 int rc;
2650 char buf[32];
2651
2652 rc = fcoe_validate_vport_create(vport);
2653 if (rc) {
Bhanu Prakash Gollapudid8348952011-08-04 17:38:49 -07002654 fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
Neerav Parikhbdf25212011-05-16 16:45:29 -07002655 printk(KERN_ERR "fcoe: Failed to create vport, "
2656 "WWPN (0x%s) already exists\n",
2657 buf);
2658 return rc;
2659 }
Chris Leech9a057532009-11-03 11:46:40 -08002660
2661 mutex_lock(&fcoe_config_mutex);
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00002662 rtnl_lock();
Chris Leech9a057532009-11-03 11:46:40 -08002663 vn_port = fcoe_if_create(fcoe, &vport->dev, 1);
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00002664 rtnl_unlock();
Chris Leech9a057532009-11-03 11:46:40 -08002665 mutex_unlock(&fcoe_config_mutex);
2666
2667 if (IS_ERR(vn_port)) {
2668 printk(KERN_ERR "fcoe: fcoe_vport_create(%s) failed\n",
2669 netdev->name);
2670 return -EIO;
2671 }
2672
2673 if (disabled) {
2674 fc_vport_set_state(vport, FC_VPORT_DISABLED);
2675 } else {
2676 vn_port->boot_time = jiffies;
2677 fc_fabric_login(vn_port);
2678 fc_vport_setlink(vn_port);
2679 }
2680 return 0;
2681}
2682
2683/**
2684 * fcoe_vport_destroy() - destroy the fc_host/scsi_host for a vport
2685 * @vport: fc_vport object that is being destroyed
2686 *
2687 * Returns: 0 for success
2688 */
2689static int fcoe_vport_destroy(struct fc_vport *vport)
2690{
2691 struct Scsi_Host *shost = vport_to_shost(vport);
2692 struct fc_lport *n_port = shost_priv(shost);
2693 struct fc_lport *vn_port = vport->dd_data;
Chris Leech9a057532009-11-03 11:46:40 -08002694
2695 mutex_lock(&n_port->lp_mutex);
2696 list_del(&vn_port->list);
2697 mutex_unlock(&n_port->lp_mutex);
Robert Loveccefd232012-02-10 17:18:41 -08002698
2699 mutex_lock(&fcoe_config_mutex);
2700 fcoe_if_destroy(vn_port);
2701 mutex_unlock(&fcoe_config_mutex);
2702
Chris Leech9a057532009-11-03 11:46:40 -08002703 return 0;
2704}
2705
2706/**
2707 * fcoe_vport_disable() - change vport state
2708 * @vport: vport to bring online/offline
2709 * @disable: should the vport be disabled?
2710 */
2711static int fcoe_vport_disable(struct fc_vport *vport, bool disable)
2712{
2713 struct fc_lport *lport = vport->dd_data;
2714
2715 if (disable) {
2716 fc_vport_set_state(vport, FC_VPORT_DISABLED);
2717 fc_fabric_logoff(lport);
2718 } else {
2719 lport->boot_time = jiffies;
2720 fc_fabric_login(lport);
2721 fc_vport_setlink(lport);
2722 }
2723
2724 return 0;
2725}
2726
Chris Leechdc8596d2009-11-03 11:47:18 -08002727/**
2728 * fcoe_vport_set_symbolic_name() - append vport string to symbolic name
2729 * @vport: fc_vport with a new symbolic name string
2730 *
2731 * After generating a new symbolic name string, a new RSPN_ID request is
2732 * sent to the name server. There is no response handler, so if it fails
2733 * for some reason it will not be retried.
2734 */
2735static void fcoe_set_vport_symbolic_name(struct fc_vport *vport)
2736{
2737 struct fc_lport *lport = vport->dd_data;
2738 struct fc_frame *fp;
2739 size_t len;
2740
2741 snprintf(fc_host_symbolic_name(lport->host), FC_SYMBOLIC_NAME_SIZE,
2742 "%s v%s over %s : %s", FCOE_NAME, FCOE_VERSION,
2743 fcoe_netdev(lport)->name, vport->symbolic_name);
2744
2745 if (lport->state != LPORT_ST_READY)
2746 return;
2747
2748 len = strnlen(fc_host_symbolic_name(lport->host), 255);
2749 fp = fc_frame_alloc(lport,
2750 sizeof(struct fc_ct_hdr) +
2751 sizeof(struct fc_ns_rspn) + len);
2752 if (!fp)
2753 return;
2754 lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, FC_NS_RSPN_ID,
Joe Eykholtb94f8952009-11-03 11:50:21 -08002755 NULL, NULL, 3 * lport->r_a_tov);
Chris Leechdc8596d2009-11-03 11:47:18 -08002756}
Yi Zoub84056b2009-11-20 14:55:19 -08002757
2758/**
2759 * fcoe_get_lesb() - Fill the FCoE Link Error Status Block
2760 * @lport: the local port
2761 * @fc_lesb: the link error status block
2762 */
2763static void fcoe_get_lesb(struct fc_lport *lport,
2764 struct fc_els_lesb *fc_lesb)
2765{
Yi Zoub84056b2009-11-20 14:55:19 -08002766 struct net_device *netdev = fcoe_netdev(lport);
2767
Bhanu Prakash Gollapudi814740d2011-10-03 16:45:01 -07002768 __fcoe_get_lesb(lport, fc_lesb, netdev);
Yi Zoub84056b2009-11-20 14:55:19 -08002769}
Joe Eykholt7d65b0d2010-03-12 16:08:02 -08002770
2771/**
2772 * fcoe_set_port_id() - Callback from libfc when Port_ID is set.
2773 * @lport: the local port
2774 * @port_id: the port ID
2775 * @fp: the received frame, if any, that caused the port_id to be set.
2776 *
2777 * This routine handles the case where we received a FLOGI and are
2778 * entering point-to-point mode. We need to call fcoe_ctlr_recv_flogi()
2779 * so it can set the non-mapped mode and gateway address.
2780 *
2781 * The FLOGI LS_ACC is handled by fcoe_flogi_resp().
2782 */
2783static void fcoe_set_port_id(struct fc_lport *lport,
2784 u32 port_id, struct fc_frame *fp)
2785{
2786 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudi8597ae82011-01-28 16:05:37 -08002787 struct fcoe_interface *fcoe = port->priv;
Robert Love619fe4b2012-05-22 19:06:10 -07002788 struct fcoe_ctlr *ctlr = fcoe_to_ctlr(fcoe);
Joe Eykholt7d65b0d2010-03-12 16:08:02 -08002789
2790 if (fp && fc_frame_payload_op(fp) == ELS_FLOGI)
Robert Love619fe4b2012-05-22 19:06:10 -07002791 fcoe_ctlr_recv_flogi(ctlr, lport, fp);
Joe Eykholt7d65b0d2010-03-12 16:08:02 -08002792}