blob: a64c398c981e69b3b08aac432ae26e6e31cffd1c [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>
21#include <linux/version.h>
Robert Love85b4aa42008-12-09 15:10:24 -080022#include <linux/spinlock.h>
Robert Love85b4aa42008-12-09 15:10:24 -080023#include <linux/netdevice.h>
24#include <linux/etherdevice.h>
25#include <linux/ethtool.h>
26#include <linux/if_ether.h>
27#include <linux/if_vlan.h>
Robert Love85b4aa42008-12-09 15:10:24 -080028#include <linux/crc32.h>
29#include <linux/cpu.h>
30#include <linux/fs.h>
31#include <linux/sysfs.h>
32#include <linux/ctype.h>
33#include <scsi/scsi_tcq.h>
34#include <scsi/scsicam.h>
35#include <scsi/scsi_transport.h>
36#include <scsi/scsi_transport_fc.h>
37#include <net/rtnetlink.h>
38
39#include <scsi/fc/fc_encaps.h>
Joe Eykholt97c83892009-03-17 11:42:40 -070040#include <scsi/fc/fc_fip.h>
Robert Love85b4aa42008-12-09 15:10:24 -080041
42#include <scsi/libfc.h>
43#include <scsi/fc_frame.h>
44#include <scsi/libfcoe.h>
Robert Love85b4aa42008-12-09 15:10:24 -080045
Vasu Devfdd78022009-03-17 11:42:24 -070046#include "fcoe.h"
47
Robert Love85b4aa42008-12-09 15:10:24 -080048MODULE_AUTHOR("Open-FCoE.org");
49MODULE_DESCRIPTION("FCoE");
Vasu Dev9b34ecf2009-03-17 11:42:13 -070050MODULE_LICENSE("GPL v2");
Robert Love85b4aa42008-12-09 15:10:24 -080051
Yi Zou05cc7392009-08-25 13:59:03 -070052/* Performance tuning parameters for fcoe */
53static unsigned int fcoe_ddp_min;
54module_param_named(ddp_min, fcoe_ddp_min, uint, S_IRUGO | S_IWUSR);
55MODULE_PARM_DESC(ddp_min, "Minimum I/O size in bytes for " \
56 "Direct Data Placement (DDP).");
57
Chris Leechdfc1d0f2009-08-25 14:00:13 -070058DEFINE_MUTEX(fcoe_config_mutex);
59
Joe Eykholte7a51992009-08-25 14:04:08 -070060/* fcoe_percpu_clean completion. Waiter protected by fcoe_create_mutex */
61static DECLARE_COMPLETION(fcoe_flush_completion);
62
Robert Love85b4aa42008-12-09 15:10:24 -080063/* fcoe host list */
Chris Leech090eb6c2009-08-25 14:00:28 -070064/* must only by accessed under the RTNL mutex */
Robert Love85b4aa42008-12-09 15:10:24 -080065LIST_HEAD(fcoe_hostlist);
Robert Love5e5e92d2009-03-17 11:41:35 -070066DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu);
Robert Love85b4aa42008-12-09 15:10:24 -080067
Chris Leechdd3fd722009-04-21 16:27:36 -070068/* Function Prototypes */
Vasu Devfdd78022009-03-17 11:42:24 -070069static int fcoe_reset(struct Scsi_Host *shost);
70static int fcoe_xmit(struct fc_lport *, struct fc_frame *);
71static int fcoe_rcv(struct sk_buff *, struct net_device *,
72 struct packet_type *, struct net_device *);
73static int fcoe_percpu_receive_thread(void *arg);
74static void fcoe_clean_pending_queue(struct fc_lport *lp);
75static void fcoe_percpu_clean(struct fc_lport *lp);
76static int fcoe_link_ok(struct fc_lport *lp);
77
78static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *);
79static int fcoe_hostlist_add(const struct fc_lport *);
Vasu Devfdd78022009-03-17 11:42:24 -070080
Vasu Dev4bb6b512009-05-06 10:52:34 -070081static void fcoe_check_wait_queue(struct fc_lport *, struct sk_buff *);
Robert Love85b4aa42008-12-09 15:10:24 -080082static int fcoe_device_notification(struct notifier_block *, ulong, void *);
83static void fcoe_dev_setup(void);
84static void fcoe_dev_cleanup(void);
Chris Leech2e70e242009-08-25 14:00:23 -070085static struct fcoe_interface *
86 fcoe_hostlist_lookup_port(const struct net_device *dev);
Robert Love85b4aa42008-12-09 15:10:24 -080087
88/* notification function from net device */
89static struct notifier_block fcoe_notifier = {
90 .notifier_call = fcoe_device_notification,
91};
92
Vasu Dev7f349142009-03-27 09:06:31 -070093static struct scsi_transport_template *scsi_transport_fcoe_sw;
94
95struct fc_function_template fcoe_transport_function = {
96 .show_host_node_name = 1,
97 .show_host_port_name = 1,
98 .show_host_supported_classes = 1,
99 .show_host_supported_fc4s = 1,
100 .show_host_active_fc4s = 1,
101 .show_host_maxframe_size = 1,
102
103 .show_host_port_id = 1,
104 .show_host_supported_speeds = 1,
105 .get_host_speed = fc_get_host_speed,
106 .show_host_speed = 1,
107 .show_host_port_type = 1,
108 .get_host_port_state = fc_get_host_port_state,
109 .show_host_port_state = 1,
110 .show_host_symbolic_name = 1,
111
112 .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv),
113 .show_rport_maxframe_size = 1,
114 .show_rport_supported_classes = 1,
115
116 .show_host_fabric_name = 1,
117 .show_starget_node_name = 1,
118 .show_starget_port_name = 1,
119 .show_starget_port_id = 1,
120 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
121 .show_rport_dev_loss_tmo = 1,
122 .get_fc_host_stats = fc_get_host_stats,
123 .issue_fc_host_lip = fcoe_reset,
124
125 .terminate_rport_io = fc_rport_terminate_io,
126};
127
128static struct scsi_host_template fcoe_shost_template = {
129 .module = THIS_MODULE,
130 .name = "FCoE Driver",
131 .proc_name = FCOE_NAME,
132 .queuecommand = fc_queuecommand,
133 .eh_abort_handler = fc_eh_abort,
134 .eh_device_reset_handler = fc_eh_device_reset,
135 .eh_host_reset_handler = fc_eh_host_reset,
136 .slave_alloc = fc_slave_alloc,
137 .change_queue_depth = fc_change_queue_depth,
138 .change_queue_type = fc_change_queue_type,
139 .this_id = -1,
Vasu Dev14caf442009-10-15 17:46:55 -0700140 .cmd_per_lun = 3,
Vasu Dev7f349142009-03-27 09:06:31 -0700141 .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS,
142 .use_clustering = ENABLE_CLUSTERING,
143 .sg_tablesize = SG_ALL,
144 .max_sectors = 0xffff,
145};
146
Chris Leech54b649f2009-08-25 14:00:07 -0700147static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *dev,
148 struct packet_type *ptype,
149 struct net_device *orig_dev);
150/**
151 * fcoe_interface_setup()
152 * @fcoe: new fcoe_interface
153 * @netdev : ptr to the associated netdevice struct
154 *
155 * Returns : 0 for success
Chris Leech2e70e242009-08-25 14:00:23 -0700156 * Locking: must be called with the RTNL mutex held
Chris Leech54b649f2009-08-25 14:00:07 -0700157 */
158static int fcoe_interface_setup(struct fcoe_interface *fcoe,
159 struct net_device *netdev)
160{
161 struct fcoe_ctlr *fip = &fcoe->ctlr;
162 struct netdev_hw_addr *ha;
163 u8 flogi_maddr[ETH_ALEN];
Yi Zoub7a727f2009-10-21 16:28:03 -0700164 const struct net_device_ops *ops;
Chris Leech54b649f2009-08-25 14:00:07 -0700165
166 fcoe->netdev = netdev;
167
Yi Zoub7a727f2009-10-21 16:28:03 -0700168 /* Let LLD initialize for FCoE */
169 ops = netdev->netdev_ops;
170 if (ops->ndo_fcoe_enable) {
171 if (ops->ndo_fcoe_enable(netdev))
172 FCOE_NETDEV_DBG(netdev, "Failed to enable FCoE"
173 " specific feature for LLD.\n");
174 }
175
Chris Leech54b649f2009-08-25 14:00:07 -0700176 /* Do not support for bonding device */
177 if ((netdev->priv_flags & IFF_MASTER_ALB) ||
178 (netdev->priv_flags & IFF_SLAVE_INACTIVE) ||
179 (netdev->priv_flags & IFF_MASTER_8023AD)) {
180 return -EOPNOTSUPP;
181 }
182
183 /* look for SAN MAC address, if multiple SAN MACs exist, only
184 * use the first one for SPMA */
185 rcu_read_lock();
186 for_each_dev_addr(netdev, ha) {
187 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
188 (is_valid_ether_addr(fip->ctl_src_addr))) {
189 memcpy(fip->ctl_src_addr, ha->addr, ETH_ALEN);
190 fip->spma = 1;
191 break;
192 }
193 }
194 rcu_read_unlock();
195
196 /* setup Source Mac Address */
197 if (!fip->spma)
198 memcpy(fip->ctl_src_addr, netdev->dev_addr, netdev->addr_len);
199
200 /*
201 * Add FCoE MAC address as second unicast MAC address
202 * or enter promiscuous mode if not capable of listening
203 * for multiple unicast MACs.
204 */
Chris Leech54b649f2009-08-25 14:00:07 -0700205 memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
206 dev_unicast_add(netdev, flogi_maddr);
207 if (fip->spma)
208 dev_unicast_add(netdev, fip->ctl_src_addr);
209 dev_mc_add(netdev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
Chris Leech54b649f2009-08-25 14:00:07 -0700210
211 /*
212 * setup the receive function from ethernet driver
213 * on the ethertype for the given device
214 */
215 fcoe->fcoe_packet_type.func = fcoe_rcv;
216 fcoe->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
217 fcoe->fcoe_packet_type.dev = netdev;
218 dev_add_pack(&fcoe->fcoe_packet_type);
219
220 fcoe->fip_packet_type.func = fcoe_fip_recv;
221 fcoe->fip_packet_type.type = htons(ETH_P_FIP);
222 fcoe->fip_packet_type.dev = netdev;
223 dev_add_pack(&fcoe->fip_packet_type);
224
225 return 0;
226}
227
228static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb);
Chris Leech11b56182009-11-03 11:46:29 -0800229static void fcoe_update_src_mac(struct fc_lport *lport, u8 *addr);
230static u8 *fcoe_get_src_mac(struct fc_lport *lport);
Chris Leech2e70e242009-08-25 14:00:23 -0700231static void fcoe_destroy_work(struct work_struct *work);
Chris Leech54b649f2009-08-25 14:00:07 -0700232
Vasu Dev7f349142009-03-27 09:06:31 -0700233/**
Chris Leech030f4e02009-08-25 14:00:02 -0700234 * fcoe_interface_create()
235 * @netdev: network interface
236 *
237 * Returns: pointer to a struct fcoe_interface or NULL on error
238 */
239static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev)
240{
241 struct fcoe_interface *fcoe;
242
243 fcoe = kzalloc(sizeof(*fcoe), GFP_KERNEL);
244 if (!fcoe) {
245 FCOE_NETDEV_DBG(netdev, "Could not allocate fcoe structure\n");
246 return NULL;
247 }
248
Chris Leech2e70e242009-08-25 14:00:23 -0700249 dev_hold(netdev);
Chris Leech030f4e02009-08-25 14:00:02 -0700250 kref_init(&fcoe->kref);
Chris Leech54b649f2009-08-25 14:00:07 -0700251
252 /*
253 * Initialize FIP.
254 */
255 fcoe_ctlr_init(&fcoe->ctlr);
256 fcoe->ctlr.send = fcoe_fip_send;
257 fcoe->ctlr.update_mac = fcoe_update_src_mac;
Chris Leech11b56182009-11-03 11:46:29 -0800258 fcoe->ctlr.get_src_addr = fcoe_get_src_mac;
Chris Leech54b649f2009-08-25 14:00:07 -0700259
260 fcoe_interface_setup(fcoe, netdev);
Chris Leech030f4e02009-08-25 14:00:02 -0700261
262 return fcoe;
263}
264
265/**
Chris Leech54b649f2009-08-25 14:00:07 -0700266 * fcoe_interface_cleanup() - clean up netdev configurations
267 * @fcoe:
Chris Leech2e70e242009-08-25 14:00:23 -0700268 *
269 * Caller must be holding the RTNL mutex
Chris Leech54b649f2009-08-25 14:00:07 -0700270 */
271void fcoe_interface_cleanup(struct fcoe_interface *fcoe)
272{
273 struct net_device *netdev = fcoe->netdev;
274 struct fcoe_ctlr *fip = &fcoe->ctlr;
275 u8 flogi_maddr[ETH_ALEN];
Yi Zoub7a727f2009-10-21 16:28:03 -0700276 const struct net_device_ops *ops;
Chris Leech54b649f2009-08-25 14:00:07 -0700277
278 /*
279 * Don't listen for Ethernet packets anymore.
280 * synchronize_net() ensures that the packet handlers are not running
281 * on another CPU. dev_remove_pack() would do that, this calls the
282 * unsyncronized version __dev_remove_pack() to avoid multiple delays.
283 */
284 __dev_remove_pack(&fcoe->fcoe_packet_type);
285 __dev_remove_pack(&fcoe->fip_packet_type);
286 synchronize_net();
287
Chris Leech54b649f2009-08-25 14:00:07 -0700288 /* Delete secondary MAC addresses */
Chris Leech54b649f2009-08-25 14:00:07 -0700289 memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
290 dev_unicast_delete(netdev, flogi_maddr);
Chris Leech54b649f2009-08-25 14:00:07 -0700291 if (fip->spma)
292 dev_unicast_delete(netdev, fip->ctl_src_addr);
293 dev_mc_delete(netdev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
Yi Zoub7a727f2009-10-21 16:28:03 -0700294
295 /* Tell the LLD we are done w/ FCoE */
296 ops = netdev->netdev_ops;
297 if (ops->ndo_fcoe_disable) {
298 if (ops->ndo_fcoe_disable(netdev))
299 FCOE_NETDEV_DBG(netdev, "Failed to disable FCoE"
300 " specific feature for LLD.\n");
301 }
Chris Leech54b649f2009-08-25 14:00:07 -0700302}
303
304/**
Chris Leech030f4e02009-08-25 14:00:02 -0700305 * fcoe_interface_release() - fcoe_port kref release function
306 * @kref: embedded reference count in an fcoe_interface struct
307 */
308static void fcoe_interface_release(struct kref *kref)
309{
310 struct fcoe_interface *fcoe;
Chris Leech2e70e242009-08-25 14:00:23 -0700311 struct net_device *netdev;
Chris Leech030f4e02009-08-25 14:00:02 -0700312
313 fcoe = container_of(kref, struct fcoe_interface, kref);
Chris Leech2e70e242009-08-25 14:00:23 -0700314 netdev = fcoe->netdev;
315 /* tear-down the FCoE controller */
316 fcoe_ctlr_destroy(&fcoe->ctlr);
Chris Leech030f4e02009-08-25 14:00:02 -0700317 kfree(fcoe);
Chris Leech2e70e242009-08-25 14:00:23 -0700318 dev_put(netdev);
Chris Leech030f4e02009-08-25 14:00:02 -0700319}
320
321/**
322 * fcoe_interface_get()
323 * @fcoe:
324 */
325static inline void fcoe_interface_get(struct fcoe_interface *fcoe)
326{
327 kref_get(&fcoe->kref);
328}
329
330/**
331 * fcoe_interface_put()
332 * @fcoe:
333 */
334static inline void fcoe_interface_put(struct fcoe_interface *fcoe)
335{
336 kref_put(&fcoe->kref, fcoe_interface_release);
337}
338
339/**
Vasu Devab6b85c2009-05-17 12:33:08 +0000340 * fcoe_fip_recv - handle a received FIP frame.
341 * @skb: the receive skb
342 * @dev: associated &net_device
343 * @ptype: the &packet_type structure which was used to register this handler.
344 * @orig_dev: original receive &net_device, in case @dev is a bond.
345 *
346 * Returns: 0 for success
347 */
348static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *dev,
349 struct packet_type *ptype,
350 struct net_device *orig_dev)
351{
Chris Leech259ad852009-08-25 13:59:41 -0700352 struct fcoe_interface *fcoe;
Vasu Devab6b85c2009-05-17 12:33:08 +0000353
Chris Leech259ad852009-08-25 13:59:41 -0700354 fcoe = container_of(ptype, struct fcoe_interface, fip_packet_type);
Chris Leech3fe9a0b2009-08-25 13:59:46 -0700355 fcoe_ctlr_recv(&fcoe->ctlr, skb);
Vasu Devab6b85c2009-05-17 12:33:08 +0000356 return 0;
357}
358
359/**
360 * fcoe_fip_send() - send an Ethernet-encapsulated FIP frame.
361 * @fip: FCoE controller.
362 * @skb: FIP Packet.
363 */
364static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
365{
Chris Leech3fe9a0b2009-08-25 13:59:46 -0700366 skb->dev = fcoe_from_ctlr(fip)->netdev;
Vasu Devab6b85c2009-05-17 12:33:08 +0000367 dev_queue_xmit(skb);
368}
369
370/**
371 * fcoe_update_src_mac() - Update Ethernet MAC filters.
Chris Leech11b56182009-11-03 11:46:29 -0800372 * @lport: libfc lport
373 * @addr: Unicast MAC address to add.
Vasu Devab6b85c2009-05-17 12:33:08 +0000374 *
375 * Remove any previously-set unicast MAC filter.
376 * Add secondary FCoE MAC address filter for our OUI.
377 */
Chris Leech11b56182009-11-03 11:46:29 -0800378static void fcoe_update_src_mac(struct fc_lport *lport, u8 *addr)
Vasu Devab6b85c2009-05-17 12:33:08 +0000379{
Chris Leech11b56182009-11-03 11:46:29 -0800380 struct fcoe_port *port = lport_priv(lport);
381 struct fcoe_interface *fcoe = port->fcoe;
Vasu Devab6b85c2009-05-17 12:33:08 +0000382
Vasu Devab6b85c2009-05-17 12:33:08 +0000383 rtnl_lock();
Chris Leech11b56182009-11-03 11:46:29 -0800384 if (!is_zero_ether_addr(port->data_src_addr))
385 dev_unicast_delete(fcoe->netdev, port->data_src_addr);
386 if (!is_zero_ether_addr(addr))
387 dev_unicast_add(fcoe->netdev, addr);
388 memcpy(port->data_src_addr, addr, ETH_ALEN);
Vasu Devab6b85c2009-05-17 12:33:08 +0000389 rtnl_unlock();
390}
391
392/**
Chris Leech11b56182009-11-03 11:46:29 -0800393 * fcoe_get_src_mac() - return the Ethernet source address for an lport
394 * @lport: libfc lport
395 */
396static u8 *fcoe_get_src_mac(struct fc_lport *lport)
397{
398 struct fcoe_port *port = lport_priv(lport);
399
400 return port->data_src_addr;
401}
402
403/**
Vasu Dev7f349142009-03-27 09:06:31 -0700404 * fcoe_lport_config() - sets up the fc_lport
405 * @lp: ptr to the fc_lport
Vasu Dev7f349142009-03-27 09:06:31 -0700406 *
407 * Returns: 0 for success
408 */
409static int fcoe_lport_config(struct fc_lport *lp)
410{
411 lp->link_up = 0;
412 lp->qfull = 0;
413 lp->max_retry_count = 3;
Abhijeet Joglekara3666952009-05-01 10:01:26 -0700414 lp->max_rport_retry_count = 3;
Vasu Dev7f349142009-03-27 09:06:31 -0700415 lp->e_d_tov = 2 * 1000; /* FC-FS default */
416 lp->r_a_tov = 2 * 2 * 1000;
417 lp->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
418 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
419
420 fc_lport_init_stats(lp);
421
422 /* lport fc_lport related configuration */
423 fc_lport_config(lp);
424
425 /* offload related configuration */
426 lp->crc_offload = 0;
427 lp->seq_offload = 0;
428 lp->lro_enabled = 0;
429 lp->lro_xid = 0;
430 lp->lso_max = 0;
431
432 return 0;
433}
434
435/**
Vasu Dev1047f222009-05-06 10:52:40 -0700436 * fcoe_queue_timer() - fcoe queue timer
437 * @lp: the fc_lport pointer
438 *
439 * Calls fcoe_check_wait_queue on timeout
440 *
441 */
442static void fcoe_queue_timer(ulong lp)
443{
444 fcoe_check_wait_queue((struct fc_lport *)lp, NULL);
445}
446
447/**
Vasu Dev7f349142009-03-27 09:06:31 -0700448 * fcoe_netdev_config() - Set up netdev for SW FCoE
449 * @lp : ptr to the fc_lport
450 * @netdev : ptr to the associated netdevice struct
451 *
452 * Must be called after fcoe_lport_config() as it will use lport mutex
453 *
454 * Returns : 0 for success
455 */
456static int fcoe_netdev_config(struct fc_lport *lp, struct net_device *netdev)
457{
458 u32 mfs;
459 u64 wwnn, wwpn;
Chris Leech25024982009-08-25 13:59:35 -0700460 struct fcoe_interface *fcoe;
Chris Leech014f5c32009-08-25 13:59:30 -0700461 struct fcoe_port *port;
Vasu Dev7f349142009-03-27 09:06:31 -0700462
463 /* Setup lport private data to point to fcoe softc */
Chris Leech014f5c32009-08-25 13:59:30 -0700464 port = lport_priv(lp);
Chris Leech25024982009-08-25 13:59:35 -0700465 fcoe = port->fcoe;
Vasu Dev7f349142009-03-27 09:06:31 -0700466
467 /*
468 * Determine max frame size based on underlying device and optional
469 * user-configured limit. If the MFS is too low, fcoe_link_ok()
470 * will return 0, so do this first.
471 */
Yi Zou7221d7e2009-10-21 16:27:52 -0700472 mfs = netdev->mtu;
473 if (netdev->features & NETIF_F_FCOE_MTU) {
474 mfs = FCOE_MTU;
475 FCOE_NETDEV_DBG(netdev, "Supports FCOE_MTU of %d bytes\n", mfs);
476 }
477 mfs -= (sizeof(struct fcoe_hdr) + sizeof(struct fcoe_crc_eof));
Vasu Dev7f349142009-03-27 09:06:31 -0700478 if (fc_set_mfs(lp, mfs))
479 return -EINVAL;
480
Vasu Dev7f349142009-03-27 09:06:31 -0700481 /* offload features support */
Vasu Dev1d1b88d2009-07-29 17:05:45 -0700482 if (netdev->features & NETIF_F_SG)
Vasu Dev7f349142009-03-27 09:06:31 -0700483 lp->sg_supp = 1;
484
Vasu Dev7f349142009-03-27 09:06:31 -0700485 if (netdev->features & NETIF_F_FCOE_CRC) {
486 lp->crc_offload = 1;
Robert Loved5488eb2009-06-10 15:30:59 -0700487 FCOE_NETDEV_DBG(netdev, "Supports FCCRC offload\n");
Vasu Dev7f349142009-03-27 09:06:31 -0700488 }
Vasu Dev7f349142009-03-27 09:06:31 -0700489 if (netdev->features & NETIF_F_FSO) {
490 lp->seq_offload = 1;
491 lp->lso_max = netdev->gso_max_size;
Robert Loved5488eb2009-06-10 15:30:59 -0700492 FCOE_NETDEV_DBG(netdev, "Supports LSO for max len 0x%x\n",
493 lp->lso_max);
Vasu Dev7f349142009-03-27 09:06:31 -0700494 }
Vasu Dev7f349142009-03-27 09:06:31 -0700495 if (netdev->fcoe_ddp_xid) {
496 lp->lro_enabled = 1;
497 lp->lro_xid = netdev->fcoe_ddp_xid;
Robert Loved5488eb2009-06-10 15:30:59 -0700498 FCOE_NETDEV_DBG(netdev, "Supports LRO for max xid 0x%x\n",
499 lp->lro_xid);
Vasu Dev7f349142009-03-27 09:06:31 -0700500 }
Chris Leech014f5c32009-08-25 13:59:30 -0700501 skb_queue_head_init(&port->fcoe_pending_queue);
502 port->fcoe_pending_queue_active = 0;
503 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long)lp);
Vasu Dev7f349142009-03-27 09:06:31 -0700504
Vasu Dev1d1b88d2009-07-29 17:05:45 -0700505 wwnn = fcoe_wwn_from_mac(netdev->dev_addr, 1, 0);
Vasu Dev7f349142009-03-27 09:06:31 -0700506 fc_set_wwnn(lp, wwnn);
507 /* XXX - 3rd arg needs to be vlan id */
Vasu Dev1d1b88d2009-07-29 17:05:45 -0700508 wwpn = fcoe_wwn_from_mac(netdev->dev_addr, 2, 0);
Vasu Dev7f349142009-03-27 09:06:31 -0700509 fc_set_wwpn(lp, wwpn);
510
Vasu Dev7f349142009-03-27 09:06:31 -0700511 return 0;
512}
513
514/**
515 * fcoe_shost_config() - Sets up fc_lport->host
516 * @lp : ptr to the fc_lport
517 * @shost : ptr to the associated scsi host
518 * @dev : device associated to scsi host
519 *
520 * Must be called after fcoe_lport_config() and fcoe_netdev_config()
521 *
522 * Returns : 0 for success
523 */
524static int fcoe_shost_config(struct fc_lport *lp, struct Scsi_Host *shost,
525 struct device *dev)
526{
527 int rc = 0;
528
529 /* lport scsi host config */
Vasu Dev7f349142009-03-27 09:06:31 -0700530 lp->host->max_lun = FCOE_MAX_LUN;
531 lp->host->max_id = FCOE_MAX_FCP_TARGET;
532 lp->host->max_channel = 0;
533 lp->host->transportt = scsi_transport_fcoe_sw;
534
535 /* add the new host to the SCSI-ml */
536 rc = scsi_add_host(lp->host, dev);
537 if (rc) {
Robert Loved5488eb2009-06-10 15:30:59 -0700538 FCOE_NETDEV_DBG(fcoe_netdev(lp), "fcoe_shost_config: "
539 "error on scsi_add_host\n");
Vasu Dev7f349142009-03-27 09:06:31 -0700540 return rc;
541 }
542 sprintf(fc_host_symbolic_name(lp->host), "%s v%s over %s",
543 FCOE_NAME, FCOE_VERSION,
544 fcoe_netdev(lp)->name);
545
546 return 0;
547}
548
Vasu Devd7179682009-07-29 17:05:21 -0700549/*
550 * fcoe_oem_match() - match for read types IO
551 * @fp: the fc_frame for new IO.
552 *
553 * Returns : true for read types IO, otherwise returns false.
554 */
555bool fcoe_oem_match(struct fc_frame *fp)
556{
Yi Zou05cc7392009-08-25 13:59:03 -0700557 return fc_fcp_is_read(fr_fsp(fp)) &&
558 (fr_fsp(fp)->data_len > fcoe_ddp_min);
Vasu Devd7179682009-07-29 17:05:21 -0700559}
560
Vasu Dev7f349142009-03-27 09:06:31 -0700561/**
562 * fcoe_em_config() - allocates em for this lport
Chris Leech014f5c32009-08-25 13:59:30 -0700563 * @lp: the fcoe that em is to allocated for
Vasu Dev7f349142009-03-27 09:06:31 -0700564 *
565 * Returns : 0 on success
566 */
567static inline int fcoe_em_config(struct fc_lport *lp)
568{
Chris Leech014f5c32009-08-25 13:59:30 -0700569 struct fcoe_port *port = lport_priv(lp);
Chris Leech25024982009-08-25 13:59:35 -0700570 struct fcoe_interface *fcoe = port->fcoe;
571 struct fcoe_interface *oldfcoe = NULL;
Vasu Dev1d1b88d2009-07-29 17:05:45 -0700572 struct net_device *old_real_dev, *cur_real_dev;
Vasu Devd7179682009-07-29 17:05:21 -0700573 u16 min_xid = FCOE_MIN_XID;
574 u16 max_xid = FCOE_MAX_XID;
575
576 /*
577 * Check if need to allocate an em instance for
578 * offload exchange ids to be shared across all VN_PORTs/lport.
579 */
580 if (!lp->lro_enabled || !lp->lro_xid || (lp->lro_xid >= max_xid)) {
581 lp->lro_xid = 0;
582 goto skip_oem;
583 }
584
585 /*
586 * Reuse existing offload em instance in case
Vasu Dev1d1b88d2009-07-29 17:05:45 -0700587 * it is already allocated on real eth device
Vasu Devd7179682009-07-29 17:05:21 -0700588 */
Chris Leech25024982009-08-25 13:59:35 -0700589 if (fcoe->netdev->priv_flags & IFF_802_1Q_VLAN)
590 cur_real_dev = vlan_dev_real_dev(fcoe->netdev);
Vasu Dev1d1b88d2009-07-29 17:05:45 -0700591 else
Chris Leech25024982009-08-25 13:59:35 -0700592 cur_real_dev = fcoe->netdev;
Vasu Dev1d1b88d2009-07-29 17:05:45 -0700593
Chris Leech25024982009-08-25 13:59:35 -0700594 list_for_each_entry(oldfcoe, &fcoe_hostlist, list) {
Chris Leech25024982009-08-25 13:59:35 -0700595 if (oldfcoe->netdev->priv_flags & IFF_802_1Q_VLAN)
596 old_real_dev = vlan_dev_real_dev(oldfcoe->netdev);
Vasu Dev1d1b88d2009-07-29 17:05:45 -0700597 else
Chris Leech25024982009-08-25 13:59:35 -0700598 old_real_dev = oldfcoe->netdev;
Vasu Dev1d1b88d2009-07-29 17:05:45 -0700599
600 if (cur_real_dev == old_real_dev) {
Chris Leech991cbb62009-08-25 13:59:51 -0700601 fcoe->oem = oldfcoe->oem;
Vasu Devd7179682009-07-29 17:05:21 -0700602 break;
603 }
604 }
605
Chris Leech991cbb62009-08-25 13:59:51 -0700606 if (fcoe->oem) {
607 if (!fc_exch_mgr_add(lp, fcoe->oem, fcoe_oem_match)) {
Vasu Devd7179682009-07-29 17:05:21 -0700608 printk(KERN_ERR "fcoe_em_config: failed to add "
609 "offload em:%p on interface:%s\n",
Chris Leech991cbb62009-08-25 13:59:51 -0700610 fcoe->oem, fcoe->netdev->name);
Vasu Devd7179682009-07-29 17:05:21 -0700611 return -ENOMEM;
612 }
613 } else {
Chris Leech991cbb62009-08-25 13:59:51 -0700614 fcoe->oem = fc_exch_mgr_alloc(lp, FC_CLASS_3,
Vasu Devd7179682009-07-29 17:05:21 -0700615 FCOE_MIN_XID, lp->lro_xid,
616 fcoe_oem_match);
Chris Leech991cbb62009-08-25 13:59:51 -0700617 if (!fcoe->oem) {
Vasu Devd7179682009-07-29 17:05:21 -0700618 printk(KERN_ERR "fcoe_em_config: failed to allocate "
619 "em for offload exches on interface:%s\n",
Chris Leech25024982009-08-25 13:59:35 -0700620 fcoe->netdev->name);
Vasu Devd7179682009-07-29 17:05:21 -0700621 return -ENOMEM;
622 }
623 }
624
625 /*
626 * Exclude offload EM xid range from next EM xid range.
627 */
628 min_xid += lp->lro_xid + 1;
629
630skip_oem:
631 if (!fc_exch_mgr_alloc(lp, FC_CLASS_3, min_xid, max_xid, NULL)) {
632 printk(KERN_ERR "fcoe_em_config: failed to "
Chris Leech25024982009-08-25 13:59:35 -0700633 "allocate em on interface %s\n", fcoe->netdev->name);
Vasu Dev7f349142009-03-27 09:06:31 -0700634 return -ENOMEM;
Vasu Devd7179682009-07-29 17:05:21 -0700635 }
Vasu Dev7f349142009-03-27 09:06:31 -0700636
637 return 0;
638}
639
640/**
641 * fcoe_if_destroy() - FCoE software HBA tear-down function
Chris Leechaf7f85d2009-08-25 13:59:24 -0700642 * @lport: fc_lport to destroy
Vasu Dev7f349142009-03-27 09:06:31 -0700643 */
Chris Leechaf7f85d2009-08-25 13:59:24 -0700644static void fcoe_if_destroy(struct fc_lport *lport)
Vasu Dev7f349142009-03-27 09:06:31 -0700645{
Chris Leech014f5c32009-08-25 13:59:30 -0700646 struct fcoe_port *port = lport_priv(lport);
647 struct fcoe_interface *fcoe = port->fcoe;
Chris Leech25024982009-08-25 13:59:35 -0700648 struct net_device *netdev = fcoe->netdev;
Vasu Dev7f349142009-03-27 09:06:31 -0700649
Robert Loved5488eb2009-06-10 15:30:59 -0700650 FCOE_NETDEV_DBG(netdev, "Destroying interface\n");
Vasu Dev7f349142009-03-27 09:06:31 -0700651
Vasu Dev7f349142009-03-27 09:06:31 -0700652 /* Logout of the fabric */
Chris Leechaf7f85d2009-08-25 13:59:24 -0700653 fc_fabric_logoff(lport);
Vasu Dev7f349142009-03-27 09:06:31 -0700654
Vasu Dev7f349142009-03-27 09:06:31 -0700655 /* Cleanup the fc_lport */
Chris Leechaf7f85d2009-08-25 13:59:24 -0700656 fc_lport_destroy(lport);
657 fc_fcp_destroy(lport);
Vasu Dev7f349142009-03-27 09:06:31 -0700658
Chris Leech54b649f2009-08-25 14:00:07 -0700659 /* Stop the transmit retry timer */
660 del_timer_sync(&port->timer);
661
662 /* Free existing transmit skbs */
663 fcoe_clean_pending_queue(lport);
664
Chris Leech11b56182009-11-03 11:46:29 -0800665 rtnl_lock();
666 if (!is_zero_ether_addr(port->data_src_addr))
667 dev_unicast_delete(netdev, port->data_src_addr);
668 rtnl_unlock();
669
Chris Leech54b649f2009-08-25 14:00:07 -0700670 /* receives may not be stopped until after this */
671 fcoe_interface_put(fcoe);
672
673 /* Free queued packets for the per-CPU receive threads */
674 fcoe_percpu_clean(lport);
675
Vasu Dev7f349142009-03-27 09:06:31 -0700676 /* Detach from the scsi-ml */
Chris Leechaf7f85d2009-08-25 13:59:24 -0700677 fc_remove_host(lport->host);
678 scsi_remove_host(lport->host);
Vasu Dev7f349142009-03-27 09:06:31 -0700679
680 /* There are no more rports or I/O, free the EM */
Chris Leechaf7f85d2009-08-25 13:59:24 -0700681 fc_exch_mgr_free(lport);
Vasu Dev7f349142009-03-27 09:06:31 -0700682
Vasu Dev7f349142009-03-27 09:06:31 -0700683 /* Free memory used by statistical counters */
Chris Leechaf7f85d2009-08-25 13:59:24 -0700684 fc_lport_free_stats(lport);
Vasu Dev7f349142009-03-27 09:06:31 -0700685
Chris Leech2e70e242009-08-25 14:00:23 -0700686 /* Release the Scsi_Host */
Chris Leechaf7f85d2009-08-25 13:59:24 -0700687 scsi_host_put(lport->host);
Vasu Dev7f349142009-03-27 09:06:31 -0700688}
689
690/*
691 * fcoe_ddp_setup - calls LLD's ddp_setup through net_device
692 * @lp: the corresponding fc_lport
693 * @xid: the exchange id for this ddp transfer
694 * @sgl: the scatterlist describing this transfer
695 * @sgc: number of sg items
696 *
697 * Returns : 0 no ddp
698 */
699static int fcoe_ddp_setup(struct fc_lport *lp, u16 xid,
700 struct scatterlist *sgl, unsigned int sgc)
701{
702 struct net_device *n = fcoe_netdev(lp);
703
Yi Zoub04d0232009-10-21 16:26:55 -0700704 if (n->netdev_ops->ndo_fcoe_ddp_setup)
Vasu Dev7f349142009-03-27 09:06:31 -0700705 return n->netdev_ops->ndo_fcoe_ddp_setup(n, xid, sgl, sgc);
706
707 return 0;
708}
709
710/*
711 * fcoe_ddp_done - calls LLD's ddp_done through net_device
712 * @lp: the corresponding fc_lport
713 * @xid: the exchange id for this ddp transfer
714 *
715 * Returns : the length of data that have been completed by ddp
716 */
717static int fcoe_ddp_done(struct fc_lport *lp, u16 xid)
718{
719 struct net_device *n = fcoe_netdev(lp);
720
Yi Zoub04d0232009-10-21 16:26:55 -0700721 if (n->netdev_ops->ndo_fcoe_ddp_done)
Vasu Dev7f349142009-03-27 09:06:31 -0700722 return n->netdev_ops->ndo_fcoe_ddp_done(n, xid);
723 return 0;
724}
725
Chris Leech11b56182009-11-03 11:46:29 -0800726static struct fc_seq *fcoe_elsct_send(struct fc_lport *lport,
727 u32 did, struct fc_frame *fp, unsigned int op,
728 void (*resp)(struct fc_seq *, struct fc_frame *, void *),
729 void *arg, u32 timeout);
730
Vasu Dev7f349142009-03-27 09:06:31 -0700731static struct libfc_function_template fcoe_libfc_fcn_templ = {
732 .frame_send = fcoe_xmit,
733 .ddp_setup = fcoe_ddp_setup,
734 .ddp_done = fcoe_ddp_done,
Chris Leech11b56182009-11-03 11:46:29 -0800735 .elsct_send = fcoe_elsct_send,
Vasu Dev7f349142009-03-27 09:06:31 -0700736};
737
738/**
Chris Leech030f4e02009-08-25 14:00:02 -0700739 * fcoe_if_create() - this function creates the fcoe port
740 * @fcoe: fcoe_interface structure to create an fc_lport instance on
Chris Leechaf7f85d2009-08-25 13:59:24 -0700741 * @parent: device pointer to be the parent in sysfs for the SCSI host
Vasu Dev7f349142009-03-27 09:06:31 -0700742 *
Chris Leech54b649f2009-08-25 14:00:07 -0700743 * Creates fc_lport struct and scsi_host for lport, configures lport.
Vasu Dev7f349142009-03-27 09:06:31 -0700744 *
Chris Leechaf7f85d2009-08-25 13:59:24 -0700745 * Returns : The allocated fc_lport or an error pointer
Vasu Dev7f349142009-03-27 09:06:31 -0700746 */
Chris Leech030f4e02009-08-25 14:00:02 -0700747static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
Chris Leechaf7f85d2009-08-25 13:59:24 -0700748 struct device *parent)
Vasu Dev7f349142009-03-27 09:06:31 -0700749{
750 int rc;
Chris Leechaf7f85d2009-08-25 13:59:24 -0700751 struct fc_lport *lport = NULL;
Chris Leech014f5c32009-08-25 13:59:30 -0700752 struct fcoe_port *port;
Vasu Dev7f349142009-03-27 09:06:31 -0700753 struct Scsi_Host *shost;
Chris Leech030f4e02009-08-25 14:00:02 -0700754 struct net_device *netdev = fcoe->netdev;
Vasu Dev7f349142009-03-27 09:06:31 -0700755
Robert Loved5488eb2009-06-10 15:30:59 -0700756 FCOE_NETDEV_DBG(netdev, "Create Interface\n");
Vasu Dev7f349142009-03-27 09:06:31 -0700757
Chris Leech86221962009-11-03 11:46:08 -0800758 lport = libfc_host_alloc(&fcoe_shost_template,
Chris Leech014f5c32009-08-25 13:59:30 -0700759 sizeof(struct fcoe_port));
Chris Leech86221962009-11-03 11:46:08 -0800760 if (!lport) {
Chris Leech014f5c32009-08-25 13:59:30 -0700761 FCOE_NETDEV_DBG(netdev, "Could not allocate host structure\n");
762 rc = -ENOMEM;
Chris Leech030f4e02009-08-25 14:00:02 -0700763 goto out;
Chris Leech014f5c32009-08-25 13:59:30 -0700764 }
Chris Leech86221962009-11-03 11:46:08 -0800765 shost = lport->host;
Chris Leech014f5c32009-08-25 13:59:30 -0700766 port = lport_priv(lport);
Chris Leech2e70e242009-08-25 14:00:23 -0700767 port->lport = lport;
Chris Leech014f5c32009-08-25 13:59:30 -0700768 port->fcoe = fcoe;
Chris Leech2e70e242009-08-25 14:00:23 -0700769 INIT_WORK(&port->destroy_work, fcoe_destroy_work);
Vasu Dev7f349142009-03-27 09:06:31 -0700770
771 /* configure fc_lport, e.g., em */
Chris Leechaf7f85d2009-08-25 13:59:24 -0700772 rc = fcoe_lport_config(lport);
Vasu Dev7f349142009-03-27 09:06:31 -0700773 if (rc) {
Robert Loved5488eb2009-06-10 15:30:59 -0700774 FCOE_NETDEV_DBG(netdev, "Could not configure lport for the "
775 "interface\n");
Vasu Dev7f349142009-03-27 09:06:31 -0700776 goto out_host_put;
777 }
778
Vasu Devab6b85c2009-05-17 12:33:08 +0000779 /* configure lport network properties */
Chris Leechaf7f85d2009-08-25 13:59:24 -0700780 rc = fcoe_netdev_config(lport, netdev);
Vasu Devab6b85c2009-05-17 12:33:08 +0000781 if (rc) {
Robert Loved5488eb2009-06-10 15:30:59 -0700782 FCOE_NETDEV_DBG(netdev, "Could not configure netdev for the "
783 "interface\n");
Chris Leech54b649f2009-08-25 14:00:07 -0700784 goto out_lp_destroy;
Vasu Devab6b85c2009-05-17 12:33:08 +0000785 }
Joe Eykholt97c83892009-03-17 11:42:40 -0700786
Vasu Dev7f349142009-03-27 09:06:31 -0700787 /* configure lport scsi host properties */
Chris Leechaf7f85d2009-08-25 13:59:24 -0700788 rc = fcoe_shost_config(lport, shost, parent);
Vasu Dev7f349142009-03-27 09:06:31 -0700789 if (rc) {
Robert Loved5488eb2009-06-10 15:30:59 -0700790 FCOE_NETDEV_DBG(netdev, "Could not configure shost for the "
791 "interface\n");
Chris Leech54b649f2009-08-25 14:00:07 -0700792 goto out_lp_destroy;
Vasu Dev7f349142009-03-27 09:06:31 -0700793 }
794
Vasu Dev7f349142009-03-27 09:06:31 -0700795 /* Initialize the library */
Chris Leechaf7f85d2009-08-25 13:59:24 -0700796 rc = fcoe_libfc_config(lport, &fcoe_libfc_fcn_templ);
Vasu Dev7f349142009-03-27 09:06:31 -0700797 if (rc) {
Robert Loved5488eb2009-06-10 15:30:59 -0700798 FCOE_NETDEV_DBG(netdev, "Could not configure libfc for the "
799 "interface\n");
Vasu Dev7f349142009-03-27 09:06:31 -0700800 goto out_lp_destroy;
801 }
802
Vasu Deve8af4d42009-07-29 17:05:15 -0700803 /*
804 * fcoe_em_alloc() and fcoe_hostlist_add() both
Chris Leechc863df32009-08-25 14:00:18 -0700805 * need to be atomic with respect to other changes to the hostlist
Vasu Deve8af4d42009-07-29 17:05:15 -0700806 * since fcoe_em_alloc() looks for an existing EM
807 * instance on host list updated by fcoe_hostlist_add().
Chris Leechc863df32009-08-25 14:00:18 -0700808 *
809 * This is currently handled through the fcoe_config_mutex begin held.
Vasu Deve8af4d42009-07-29 17:05:15 -0700810 */
Chris Leechc863df32009-08-25 14:00:18 -0700811
Vasu Dev96316092009-07-29 17:05:00 -0700812 /* lport exch manager allocation */
Chris Leechaf7f85d2009-08-25 13:59:24 -0700813 rc = fcoe_em_config(lport);
Vasu Dev96316092009-07-29 17:05:00 -0700814 if (rc) {
815 FCOE_NETDEV_DBG(netdev, "Could not configure the EM for the "
816 "interface\n");
817 goto out_lp_destroy;
818 }
819
Chris Leech030f4e02009-08-25 14:00:02 -0700820 fcoe_interface_get(fcoe);
Chris Leechaf7f85d2009-08-25 13:59:24 -0700821 return lport;
Vasu Dev7f349142009-03-27 09:06:31 -0700822
823out_lp_destroy:
Chris Leechaf7f85d2009-08-25 13:59:24 -0700824 fc_exch_mgr_free(lport);
Vasu Dev7f349142009-03-27 09:06:31 -0700825out_host_put:
Chris Leechaf7f85d2009-08-25 13:59:24 -0700826 scsi_host_put(lport->host);
827out:
828 return ERR_PTR(rc);
Vasu Dev7f349142009-03-27 09:06:31 -0700829}
830
831/**
832 * fcoe_if_init() - attach to scsi transport
833 *
834 * Returns : 0 on success
835 */
836static int __init fcoe_if_init(void)
837{
838 /* attach to scsi transport */
839 scsi_transport_fcoe_sw =
840 fc_attach_transport(&fcoe_transport_function);
841
842 if (!scsi_transport_fcoe_sw) {
Robert Loved5488eb2009-06-10 15:30:59 -0700843 printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n");
Vasu Dev7f349142009-03-27 09:06:31 -0700844 return -ENODEV;
845 }
846
847 return 0;
848}
849
850/**
851 * fcoe_if_exit() - detach from scsi transport
852 *
853 * Returns : 0 on success
854 */
855int __exit fcoe_if_exit(void)
856{
857 fc_release_transport(scsi_transport_fcoe_sw);
Chris Leechdfc1d0f2009-08-25 14:00:13 -0700858 scsi_transport_fcoe_sw = NULL;
Vasu Dev7f349142009-03-27 09:06:31 -0700859 return 0;
860}
861
Robert Love85b4aa42008-12-09 15:10:24 -0800862/**
Robert Love8976f422009-03-17 11:41:46 -0700863 * fcoe_percpu_thread_create() - Create a receive thread for an online cpu
864 * @cpu: cpu index for the online cpu
865 */
866static void fcoe_percpu_thread_create(unsigned int cpu)
867{
868 struct fcoe_percpu_s *p;
869 struct task_struct *thread;
870
871 p = &per_cpu(fcoe_percpu, cpu);
872
873 thread = kthread_create(fcoe_percpu_receive_thread,
874 (void *)p, "fcoethread/%d", cpu);
875
Joe Eykholte7a51992009-08-25 14:04:08 -0700876 if (likely(!IS_ERR(thread))) {
Robert Love8976f422009-03-17 11:41:46 -0700877 kthread_bind(thread, cpu);
878 wake_up_process(thread);
879
880 spin_lock_bh(&p->fcoe_rx_list.lock);
881 p->thread = thread;
882 spin_unlock_bh(&p->fcoe_rx_list.lock);
883 }
884}
885
886/**
887 * fcoe_percpu_thread_destroy() - removes the rx thread for the given cpu
888 * @cpu: cpu index the rx thread is to be removed
889 *
890 * Destroys a per-CPU Rx thread. Any pending skbs are moved to the
891 * current CPU's Rx thread. If the thread being destroyed is bound to
892 * the CPU processing this context the skbs will be freed.
893 */
894static void fcoe_percpu_thread_destroy(unsigned int cpu)
895{
896 struct fcoe_percpu_s *p;
897 struct task_struct *thread;
898 struct page *crc_eof;
899 struct sk_buff *skb;
900#ifdef CONFIG_SMP
901 struct fcoe_percpu_s *p0;
902 unsigned targ_cpu = smp_processor_id();
903#endif /* CONFIG_SMP */
904
Robert Loved5488eb2009-06-10 15:30:59 -0700905 FCOE_DBG("Destroying receive thread for CPU %d\n", cpu);
Robert Love8976f422009-03-17 11:41:46 -0700906
907 /* Prevent any new skbs from being queued for this CPU. */
908 p = &per_cpu(fcoe_percpu, cpu);
909 spin_lock_bh(&p->fcoe_rx_list.lock);
910 thread = p->thread;
911 p->thread = NULL;
912 crc_eof = p->crc_eof_page;
913 p->crc_eof_page = NULL;
914 p->crc_eof_offset = 0;
915 spin_unlock_bh(&p->fcoe_rx_list.lock);
916
917#ifdef CONFIG_SMP
918 /*
919 * Don't bother moving the skb's if this context is running
920 * on the same CPU that is having its thread destroyed. This
921 * can easily happen when the module is removed.
922 */
923 if (cpu != targ_cpu) {
924 p0 = &per_cpu(fcoe_percpu, targ_cpu);
925 spin_lock_bh(&p0->fcoe_rx_list.lock);
926 if (p0->thread) {
Robert Loved5488eb2009-06-10 15:30:59 -0700927 FCOE_DBG("Moving frames from CPU %d to CPU %d\n",
928 cpu, targ_cpu);
Robert Love8976f422009-03-17 11:41:46 -0700929
930 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
931 __skb_queue_tail(&p0->fcoe_rx_list, skb);
932 spin_unlock_bh(&p0->fcoe_rx_list.lock);
933 } else {
934 /*
935 * The targeted CPU is not initialized and cannot accept
936 * new skbs. Unlock the targeted CPU and drop the skbs
937 * on the CPU that is going offline.
938 */
939 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
940 kfree_skb(skb);
941 spin_unlock_bh(&p0->fcoe_rx_list.lock);
942 }
943 } else {
944 /*
945 * This scenario occurs when the module is being removed
946 * and all threads are being destroyed. skbs will continue
947 * to be shifted from the CPU thread that is being removed
948 * to the CPU thread associated with the CPU that is processing
949 * the module removal. Once there is only one CPU Rx thread it
950 * will reach this case and we will drop all skbs and later
951 * stop the thread.
952 */
953 spin_lock_bh(&p->fcoe_rx_list.lock);
954 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
955 kfree_skb(skb);
956 spin_unlock_bh(&p->fcoe_rx_list.lock);
957 }
958#else
959 /*
Chris Leechdd3fd722009-04-21 16:27:36 -0700960 * This a non-SMP scenario where the singular Rx thread is
Robert Love8976f422009-03-17 11:41:46 -0700961 * being removed. Free all skbs and stop the thread.
962 */
963 spin_lock_bh(&p->fcoe_rx_list.lock);
964 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
965 kfree_skb(skb);
966 spin_unlock_bh(&p->fcoe_rx_list.lock);
967#endif
968
969 if (thread)
970 kthread_stop(thread);
971
972 if (crc_eof)
973 put_page(crc_eof);
974}
975
976/**
977 * fcoe_cpu_callback() - fcoe cpu hotplug event callback
978 * @nfb: callback data block
979 * @action: event triggering the callback
980 * @hcpu: index for the cpu of this event
981 *
982 * This creates or destroys per cpu data for fcoe
983 *
984 * Returns NOTIFY_OK always.
985 */
986static int fcoe_cpu_callback(struct notifier_block *nfb,
987 unsigned long action, void *hcpu)
988{
989 unsigned cpu = (unsigned long)hcpu;
990
991 switch (action) {
992 case CPU_ONLINE:
993 case CPU_ONLINE_FROZEN:
Robert Loved5488eb2009-06-10 15:30:59 -0700994 FCOE_DBG("CPU %x online: Create Rx thread\n", cpu);
Robert Love8976f422009-03-17 11:41:46 -0700995 fcoe_percpu_thread_create(cpu);
996 break;
997 case CPU_DEAD:
998 case CPU_DEAD_FROZEN:
Robert Loved5488eb2009-06-10 15:30:59 -0700999 FCOE_DBG("CPU %x offline: Remove Rx thread\n", cpu);
Robert Love8976f422009-03-17 11:41:46 -07001000 fcoe_percpu_thread_destroy(cpu);
1001 break;
1002 default:
1003 break;
1004 }
1005 return NOTIFY_OK;
1006}
1007
1008static struct notifier_block fcoe_cpu_notifier = {
1009 .notifier_call = fcoe_cpu_callback,
1010};
1011
1012/**
Robert Love34f42a02009-02-27 10:55:45 -08001013 * fcoe_rcv() - this is the fcoe receive function called by NET_RX_SOFTIRQ
Robert Love85b4aa42008-12-09 15:10:24 -08001014 * @skb: the receive skb
1015 * @dev: associated net device
1016 * @ptype: context
Chris Leechdd3fd722009-04-21 16:27:36 -07001017 * @olddev: last device
Robert Love85b4aa42008-12-09 15:10:24 -08001018 *
1019 * this function will receive the packet and build fc frame and pass it up
1020 *
1021 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001022 */
Robert Love85b4aa42008-12-09 15:10:24 -08001023int fcoe_rcv(struct sk_buff *skb, struct net_device *dev,
1024 struct packet_type *ptype, struct net_device *olddev)
1025{
1026 struct fc_lport *lp;
1027 struct fcoe_rcv_info *fr;
Chris Leech259ad852009-08-25 13:59:41 -07001028 struct fcoe_interface *fcoe;
Robert Love85b4aa42008-12-09 15:10:24 -08001029 struct fc_frame_header *fh;
Robert Love85b4aa42008-12-09 15:10:24 -08001030 struct fcoe_percpu_s *fps;
Vasu Devb2f00912009-08-25 13:58:53 -07001031 unsigned int cpu;
Robert Love85b4aa42008-12-09 15:10:24 -08001032
Chris Leech259ad852009-08-25 13:59:41 -07001033 fcoe = container_of(ptype, struct fcoe_interface, fcoe_packet_type);
Chris Leech3fe9a0b2009-08-25 13:59:46 -07001034 lp = fcoe->ctlr.lp;
Robert Love85b4aa42008-12-09 15:10:24 -08001035 if (unlikely(lp == NULL)) {
Robert Loved5488eb2009-06-10 15:30:59 -07001036 FCOE_NETDEV_DBG(dev, "Cannot find hba structure");
Robert Love85b4aa42008-12-09 15:10:24 -08001037 goto err2;
1038 }
Joe Eykholt97c83892009-03-17 11:42:40 -07001039 if (!lp->link_up)
1040 goto err2;
Robert Love85b4aa42008-12-09 15:10:24 -08001041
Robert Loved5488eb2009-06-10 15:30:59 -07001042 FCOE_NETDEV_DBG(dev, "skb_info: len:%d data_len:%d head:%p "
1043 "data:%p tail:%p end:%p sum:%d dev:%s",
1044 skb->len, skb->data_len, skb->head, skb->data,
1045 skb_tail_pointer(skb), skb_end_pointer(skb),
1046 skb->csum, skb->dev ? skb->dev->name : "<NULL>");
Robert Love85b4aa42008-12-09 15:10:24 -08001047
1048 /* check for FCOE packet type */
1049 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
Robert Loved5488eb2009-06-10 15:30:59 -07001050 FCOE_NETDEV_DBG(dev, "Wrong FC type frame");
Robert Love85b4aa42008-12-09 15:10:24 -08001051 goto err;
1052 }
1053
1054 /*
1055 * Check for minimum frame length, and make sure required FCoE
1056 * and FC headers are pulled into the linear data area.
1057 */
1058 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
1059 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
1060 goto err;
1061
1062 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
1063 fh = (struct fc_frame_header *) skb_transport_header(skb);
1064
Robert Love85b4aa42008-12-09 15:10:24 -08001065 fr = fcoe_dev_from_skb(skb);
1066 fr->fr_dev = lp;
1067 fr->ptype = ptype;
Robert Love5e5e92d2009-03-17 11:41:35 -07001068
Robert Love85b4aa42008-12-09 15:10:24 -08001069 /*
Vasu Devb2f00912009-08-25 13:58:53 -07001070 * In case the incoming frame's exchange is originated from
1071 * the initiator, then received frame's exchange id is ANDed
1072 * with fc_cpu_mask bits to get the same cpu on which exchange
1073 * was originated, otherwise just use the current cpu.
Robert Love85b4aa42008-12-09 15:10:24 -08001074 */
Vasu Devb2f00912009-08-25 13:58:53 -07001075 if (ntoh24(fh->fh_f_ctl) & FC_FC_EX_CTX)
1076 cpu = ntohs(fh->fh_ox_id) & fc_cpu_mask;
1077 else
1078 cpu = smp_processor_id();
Robert Love5e5e92d2009-03-17 11:41:35 -07001079
Robert Love8976f422009-03-17 11:41:46 -07001080 fps = &per_cpu(fcoe_percpu, cpu);
Robert Love85b4aa42008-12-09 15:10:24 -08001081 spin_lock_bh(&fps->fcoe_rx_list.lock);
Robert Love8976f422009-03-17 11:41:46 -07001082 if (unlikely(!fps->thread)) {
1083 /*
1084 * The targeted CPU is not ready, let's target
1085 * the first CPU now. For non-SMP systems this
1086 * will check the same CPU twice.
1087 */
Robert Loved5488eb2009-06-10 15:30:59 -07001088 FCOE_NETDEV_DBG(dev, "CPU is online, but no receive thread "
1089 "ready for incoming skb- using first online "
1090 "CPU.\n");
Robert Love8976f422009-03-17 11:41:46 -07001091
1092 spin_unlock_bh(&fps->fcoe_rx_list.lock);
1093 cpu = first_cpu(cpu_online_map);
1094 fps = &per_cpu(fcoe_percpu, cpu);
1095 spin_lock_bh(&fps->fcoe_rx_list.lock);
1096 if (!fps->thread) {
1097 spin_unlock_bh(&fps->fcoe_rx_list.lock);
1098 goto err;
1099 }
1100 }
1101
1102 /*
1103 * We now have a valid CPU that we're targeting for
1104 * this skb. We also have this receive thread locked,
1105 * so we're free to queue skbs into it's queue.
1106 */
Robert Love85b4aa42008-12-09 15:10:24 -08001107 __skb_queue_tail(&fps->fcoe_rx_list, skb);
1108 if (fps->fcoe_rx_list.qlen == 1)
1109 wake_up_process(fps->thread);
1110
1111 spin_unlock_bh(&fps->fcoe_rx_list.lock);
1112
1113 return 0;
1114err:
Robert Love582b45b2009-03-31 15:51:50 -07001115 fc_lport_get_stats(lp)->ErrorFrames++;
Robert Love85b4aa42008-12-09 15:10:24 -08001116
1117err2:
1118 kfree_skb(skb);
1119 return -1;
1120}
Robert Love85b4aa42008-12-09 15:10:24 -08001121
1122/**
Robert Love34f42a02009-02-27 10:55:45 -08001123 * fcoe_start_io() - pass to netdev to start xmit for fcoe
Robert Love85b4aa42008-12-09 15:10:24 -08001124 * @skb: the skb to be xmitted
1125 *
1126 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001127 */
Robert Love85b4aa42008-12-09 15:10:24 -08001128static inline int fcoe_start_io(struct sk_buff *skb)
1129{
1130 int rc;
1131
1132 skb_get(skb);
1133 rc = dev_queue_xmit(skb);
1134 if (rc != 0)
1135 return rc;
1136 kfree_skb(skb);
1137 return 0;
1138}
1139
1140/**
Chris Leechdd3fd722009-04-21 16:27:36 -07001141 * fcoe_get_paged_crc_eof() - in case we need to alloc a page for crc_eof
Robert Love85b4aa42008-12-09 15:10:24 -08001142 * @skb: the skb to be xmitted
1143 * @tlen: total len
1144 *
1145 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001146 */
Robert Love85b4aa42008-12-09 15:10:24 -08001147static int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen)
1148{
1149 struct fcoe_percpu_s *fps;
1150 struct page *page;
Robert Love85b4aa42008-12-09 15:10:24 -08001151
Robert Love5e5e92d2009-03-17 11:41:35 -07001152 fps = &get_cpu_var(fcoe_percpu);
Robert Love85b4aa42008-12-09 15:10:24 -08001153 page = fps->crc_eof_page;
1154 if (!page) {
1155 page = alloc_page(GFP_ATOMIC);
1156 if (!page) {
Robert Love5e5e92d2009-03-17 11:41:35 -07001157 put_cpu_var(fcoe_percpu);
Robert Love85b4aa42008-12-09 15:10:24 -08001158 return -ENOMEM;
1159 }
1160 fps->crc_eof_page = page;
Robert Love8976f422009-03-17 11:41:46 -07001161 fps->crc_eof_offset = 0;
Robert Love85b4aa42008-12-09 15:10:24 -08001162 }
1163
1164 get_page(page);
1165 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page,
1166 fps->crc_eof_offset, tlen);
1167 skb->len += tlen;
1168 skb->data_len += tlen;
1169 skb->truesize += tlen;
1170 fps->crc_eof_offset += sizeof(struct fcoe_crc_eof);
1171
1172 if (fps->crc_eof_offset >= PAGE_SIZE) {
1173 fps->crc_eof_page = NULL;
1174 fps->crc_eof_offset = 0;
1175 put_page(page);
1176 }
Robert Love5e5e92d2009-03-17 11:41:35 -07001177 put_cpu_var(fcoe_percpu);
Robert Love85b4aa42008-12-09 15:10:24 -08001178 return 0;
1179}
1180
1181/**
Robert Love34f42a02009-02-27 10:55:45 -08001182 * fcoe_fc_crc() - calculates FC CRC in this fcoe skb
Chris Leechdd3fd722009-04-21 16:27:36 -07001183 * @fp: the fc_frame containing data to be checksummed
Robert Love85b4aa42008-12-09 15:10:24 -08001184 *
Chris Leech014f5c32009-08-25 13:59:30 -07001185 * This uses crc32() to calculate the crc for port frame
Robert Love85b4aa42008-12-09 15:10:24 -08001186 * Return : 32 bit crc
Robert Love34f42a02009-02-27 10:55:45 -08001187 */
Robert Love85b4aa42008-12-09 15:10:24 -08001188u32 fcoe_fc_crc(struct fc_frame *fp)
1189{
1190 struct sk_buff *skb = fp_skb(fp);
1191 struct skb_frag_struct *frag;
1192 unsigned char *data;
1193 unsigned long off, len, clen;
1194 u32 crc;
1195 unsigned i;
1196
1197 crc = crc32(~0, skb->data, skb_headlen(skb));
1198
1199 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1200 frag = &skb_shinfo(skb)->frags[i];
1201 off = frag->page_offset;
1202 len = frag->size;
1203 while (len > 0) {
1204 clen = min(len, PAGE_SIZE - (off & ~PAGE_MASK));
1205 data = kmap_atomic(frag->page + (off >> PAGE_SHIFT),
1206 KM_SKB_DATA_SOFTIRQ);
1207 crc = crc32(crc, data + (off & ~PAGE_MASK), clen);
1208 kunmap_atomic(data, KM_SKB_DATA_SOFTIRQ);
1209 off += clen;
1210 len -= clen;
1211 }
1212 }
1213 return crc;
1214}
Robert Love85b4aa42008-12-09 15:10:24 -08001215
1216/**
Robert Love34f42a02009-02-27 10:55:45 -08001217 * fcoe_xmit() - FCoE frame transmit function
Chris Leech014f5c32009-08-25 13:59:30 -07001218 * @lp: the associated local fcoe
Robert Love85b4aa42008-12-09 15:10:24 -08001219 * @fp: the fc_frame to be transmitted
1220 *
1221 * Return : 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001222 */
Robert Love85b4aa42008-12-09 15:10:24 -08001223int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp)
1224{
Vasu Dev4bb6b512009-05-06 10:52:34 -07001225 int wlen;
Robert Love85b4aa42008-12-09 15:10:24 -08001226 u32 crc;
1227 struct ethhdr *eh;
1228 struct fcoe_crc_eof *cp;
1229 struct sk_buff *skb;
1230 struct fcoe_dev_stats *stats;
1231 struct fc_frame_header *fh;
1232 unsigned int hlen; /* header length implies the version */
1233 unsigned int tlen; /* trailer length */
1234 unsigned int elen; /* eth header, may include vlan */
Chris Leech3fe9a0b2009-08-25 13:59:46 -07001235 struct fcoe_port *port = lport_priv(lp);
1236 struct fcoe_interface *fcoe = port->fcoe;
Robert Love85b4aa42008-12-09 15:10:24 -08001237 u8 sof, eof;
1238 struct fcoe_hdr *hp;
1239
1240 WARN_ON((fr_len(fp) % sizeof(u32)) != 0);
1241
Robert Love85b4aa42008-12-09 15:10:24 -08001242 fh = fc_frame_header_get(fp);
Joe Eykholt97c83892009-03-17 11:42:40 -07001243 skb = fp_skb(fp);
1244 wlen = skb->len / FCOE_WORD_TO_BYTE;
1245
1246 if (!lp->link_up) {
Dan Carpenter3caf02e2009-04-21 16:27:25 -07001247 kfree_skb(skb);
Joe Eykholt97c83892009-03-17 11:42:40 -07001248 return 0;
Robert Love85b4aa42008-12-09 15:10:24 -08001249 }
1250
Joe Eykholt97c83892009-03-17 11:42:40 -07001251 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ) &&
Chris Leech11b56182009-11-03 11:46:29 -08001252 fcoe_ctlr_els_send(&fcoe->ctlr, lp, skb))
Joe Eykholt97c83892009-03-17 11:42:40 -07001253 return 0;
1254
Robert Love85b4aa42008-12-09 15:10:24 -08001255 sof = fr_sof(fp);
1256 eof = fr_eof(fp);
1257
Vasu Dev4e57e1c2009-05-06 10:52:46 -07001258 elen = sizeof(struct ethhdr);
Robert Love85b4aa42008-12-09 15:10:24 -08001259 hlen = sizeof(struct fcoe_hdr);
1260 tlen = sizeof(struct fcoe_crc_eof);
1261 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
1262
1263 /* crc offload */
1264 if (likely(lp->crc_offload)) {
Yi Zou39ca9a02009-02-27 14:07:15 -08001265 skb->ip_summed = CHECKSUM_PARTIAL;
Robert Love85b4aa42008-12-09 15:10:24 -08001266 skb->csum_start = skb_headroom(skb);
1267 skb->csum_offset = skb->len;
1268 crc = 0;
1269 } else {
1270 skb->ip_summed = CHECKSUM_NONE;
1271 crc = fcoe_fc_crc(fp);
1272 }
1273
Chris Leech014f5c32009-08-25 13:59:30 -07001274 /* copy port crc and eof to the skb buff */
Robert Love85b4aa42008-12-09 15:10:24 -08001275 if (skb_is_nonlinear(skb)) {
1276 skb_frag_t *frag;
1277 if (fcoe_get_paged_crc_eof(skb, tlen)) {
Roel Kluine9041582009-02-27 10:56:22 -08001278 kfree_skb(skb);
Robert Love85b4aa42008-12-09 15:10:24 -08001279 return -ENOMEM;
1280 }
1281 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
1282 cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ)
1283 + frag->page_offset;
1284 } else {
1285 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
1286 }
1287
1288 memset(cp, 0, sizeof(*cp));
1289 cp->fcoe_eof = eof;
1290 cp->fcoe_crc32 = cpu_to_le32(~crc);
1291
1292 if (skb_is_nonlinear(skb)) {
1293 kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ);
1294 cp = NULL;
1295 }
1296
Chris Leech014f5c32009-08-25 13:59:30 -07001297 /* adjust skb network/transport offsets to match mac/fcoe/port */
Robert Love85b4aa42008-12-09 15:10:24 -08001298 skb_push(skb, elen + hlen);
1299 skb_reset_mac_header(skb);
1300 skb_reset_network_header(skb);
1301 skb->mac_len = elen;
Yi Zou211c7382009-02-27 14:06:37 -08001302 skb->protocol = htons(ETH_P_FCOE);
Chris Leech3fe9a0b2009-08-25 13:59:46 -07001303 skb->dev = fcoe->netdev;
Robert Love85b4aa42008-12-09 15:10:24 -08001304
1305 /* fill up mac and fcoe headers */
1306 eh = eth_hdr(skb);
1307 eh->h_proto = htons(ETH_P_FCOE);
Chris Leech3fe9a0b2009-08-25 13:59:46 -07001308 if (fcoe->ctlr.map_dest)
Robert Love85b4aa42008-12-09 15:10:24 -08001309 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
1310 else
1311 /* insert GW address */
Chris Leech3fe9a0b2009-08-25 13:59:46 -07001312 memcpy(eh->h_dest, fcoe->ctlr.dest_addr, ETH_ALEN);
Robert Love85b4aa42008-12-09 15:10:24 -08001313
Chris Leech3fe9a0b2009-08-25 13:59:46 -07001314 if (unlikely(fcoe->ctlr.flogi_oxid != FC_XID_UNKNOWN))
1315 memcpy(eh->h_source, fcoe->ctlr.ctl_src_addr, ETH_ALEN);
Robert Love85b4aa42008-12-09 15:10:24 -08001316 else
Chris Leech11b56182009-11-03 11:46:29 -08001317 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
Robert Love85b4aa42008-12-09 15:10:24 -08001318
1319 hp = (struct fcoe_hdr *)(eh + 1);
1320 memset(hp, 0, sizeof(*hp));
1321 if (FC_FCOE_VER)
1322 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
1323 hp->fcoe_sof = sof;
1324
Yi Zou39ca9a02009-02-27 14:07:15 -08001325 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
1326 if (lp->seq_offload && fr_max_payload(fp)) {
1327 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
1328 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
1329 } else {
1330 skb_shinfo(skb)->gso_type = 0;
1331 skb_shinfo(skb)->gso_size = 0;
1332 }
Robert Love85b4aa42008-12-09 15:10:24 -08001333 /* update tx stats: regardless if LLD fails */
Robert Love582b45b2009-03-31 15:51:50 -07001334 stats = fc_lport_get_stats(lp);
1335 stats->TxFrames++;
1336 stats->TxWords += wlen;
Robert Love85b4aa42008-12-09 15:10:24 -08001337
1338 /* send down to lld */
1339 fr_dev(fp) = lp;
Chris Leech014f5c32009-08-25 13:59:30 -07001340 if (port->fcoe_pending_queue.qlen)
Vasu Dev4bb6b512009-05-06 10:52:34 -07001341 fcoe_check_wait_queue(lp, skb);
1342 else if (fcoe_start_io(skb))
1343 fcoe_check_wait_queue(lp, skb);
Robert Love85b4aa42008-12-09 15:10:24 -08001344
1345 return 0;
1346}
Robert Love85b4aa42008-12-09 15:10:24 -08001347
Robert Love34f42a02009-02-27 10:55:45 -08001348/**
Joe Eykholte7a51992009-08-25 14:04:08 -07001349 * fcoe_percpu_flush_done() - Indicate percpu queue flush completion.
1350 * @skb: the skb being completed.
1351 */
1352static void fcoe_percpu_flush_done(struct sk_buff *skb)
1353{
1354 complete(&fcoe_flush_completion);
1355}
1356
1357/**
Robert Love34f42a02009-02-27 10:55:45 -08001358 * fcoe_percpu_receive_thread() - recv thread per cpu
Robert Love85b4aa42008-12-09 15:10:24 -08001359 * @arg: ptr to the fcoe per cpu struct
1360 *
1361 * Return: 0 for success
Robert Love85b4aa42008-12-09 15:10:24 -08001362 */
1363int fcoe_percpu_receive_thread(void *arg)
1364{
1365 struct fcoe_percpu_s *p = arg;
1366 u32 fr_len;
1367 struct fc_lport *lp;
1368 struct fcoe_rcv_info *fr;
1369 struct fcoe_dev_stats *stats;
1370 struct fc_frame_header *fh;
1371 struct sk_buff *skb;
1372 struct fcoe_crc_eof crc_eof;
1373 struct fc_frame *fp;
1374 u8 *mac = NULL;
Chris Leech014f5c32009-08-25 13:59:30 -07001375 struct fcoe_port *port;
Robert Love85b4aa42008-12-09 15:10:24 -08001376 struct fcoe_hdr *hp;
1377
Robert Love4469c192009-02-27 10:56:38 -08001378 set_user_nice(current, -20);
Robert Love85b4aa42008-12-09 15:10:24 -08001379
1380 while (!kthread_should_stop()) {
1381
1382 spin_lock_bh(&p->fcoe_rx_list.lock);
1383 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) == NULL) {
1384 set_current_state(TASK_INTERRUPTIBLE);
1385 spin_unlock_bh(&p->fcoe_rx_list.lock);
1386 schedule();
1387 set_current_state(TASK_RUNNING);
1388 if (kthread_should_stop())
1389 return 0;
1390 spin_lock_bh(&p->fcoe_rx_list.lock);
1391 }
1392 spin_unlock_bh(&p->fcoe_rx_list.lock);
1393 fr = fcoe_dev_from_skb(skb);
1394 lp = fr->fr_dev;
1395 if (unlikely(lp == NULL)) {
Joe Eykholte7a51992009-08-25 14:04:08 -07001396 if (skb->destructor != fcoe_percpu_flush_done)
1397 FCOE_NETDEV_DBG(skb->dev, "NULL lport in skb");
Robert Love85b4aa42008-12-09 15:10:24 -08001398 kfree_skb(skb);
1399 continue;
1400 }
1401
Robert Loved5488eb2009-06-10 15:30:59 -07001402 FCOE_NETDEV_DBG(skb->dev, "skb_info: len:%d data_len:%d "
1403 "head:%p data:%p tail:%p end:%p sum:%d dev:%s",
1404 skb->len, skb->data_len,
1405 skb->head, skb->data, skb_tail_pointer(skb),
1406 skb_end_pointer(skb), skb->csum,
1407 skb->dev ? skb->dev->name : "<NULL>");
Robert Love85b4aa42008-12-09 15:10:24 -08001408
1409 /*
1410 * Save source MAC address before discarding header.
1411 */
Chris Leech014f5c32009-08-25 13:59:30 -07001412 port = lport_priv(lp);
Robert Love85b4aa42008-12-09 15:10:24 -08001413 if (skb_is_nonlinear(skb))
1414 skb_linearize(skb); /* not ideal */
Joe Eykholt97c83892009-03-17 11:42:40 -07001415 mac = eth_hdr(skb)->h_source;
Robert Love85b4aa42008-12-09 15:10:24 -08001416
1417 /*
1418 * Frame length checks and setting up the header pointers
1419 * was done in fcoe_rcv already.
1420 */
1421 hp = (struct fcoe_hdr *) skb_network_header(skb);
1422 fh = (struct fc_frame_header *) skb_transport_header(skb);
1423
Robert Love582b45b2009-03-31 15:51:50 -07001424 stats = fc_lport_get_stats(lp);
Robert Love85b4aa42008-12-09 15:10:24 -08001425 if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) {
Robert Love582b45b2009-03-31 15:51:50 -07001426 if (stats->ErrorFrames < 5)
Robert Loved5488eb2009-06-10 15:30:59 -07001427 printk(KERN_WARNING "fcoe: FCoE version "
Robert Love582b45b2009-03-31 15:51:50 -07001428 "mismatch: The frame has "
1429 "version %x, but the "
1430 "initiator supports version "
1431 "%x\n", FC_FCOE_DECAPS_VER(hp),
1432 FC_FCOE_VER);
1433 stats->ErrorFrames++;
Robert Love85b4aa42008-12-09 15:10:24 -08001434 kfree_skb(skb);
1435 continue;
1436 }
1437
1438 skb_pull(skb, sizeof(struct fcoe_hdr));
1439 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
1440
Robert Love582b45b2009-03-31 15:51:50 -07001441 stats->RxFrames++;
1442 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
Robert Love85b4aa42008-12-09 15:10:24 -08001443
1444 fp = (struct fc_frame *)skb;
1445 fc_frame_init(fp);
1446 fr_dev(fp) = lp;
1447 fr_sof(fp) = hp->fcoe_sof;
1448
1449 /* Copy out the CRC and EOF trailer for access */
1450 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
1451 kfree_skb(skb);
1452 continue;
1453 }
1454 fr_eof(fp) = crc_eof.fcoe_eof;
1455 fr_crc(fp) = crc_eof.fcoe_crc32;
1456 if (pskb_trim(skb, fr_len)) {
1457 kfree_skb(skb);
1458 continue;
1459 }
1460
1461 /*
1462 * We only check CRC if no offload is available and if it is
1463 * it's solicited data, in which case, the FCP layer would
1464 * check it during the copy.
1465 */
Yi Zou07c00ec2009-02-27 14:07:31 -08001466 if (lp->crc_offload && skb->ip_summed == CHECKSUM_UNNECESSARY)
Robert Love85b4aa42008-12-09 15:10:24 -08001467 fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
1468 else
1469 fr_flags(fp) |= FCPHF_CRC_UNCHECKED;
1470
1471 fh = fc_frame_header_get(fp);
1472 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
1473 fh->fh_type == FC_TYPE_FCP) {
Vasu Dev52ff8782009-07-29 17:05:10 -07001474 fc_exch_recv(lp, fp);
Robert Love85b4aa42008-12-09 15:10:24 -08001475 continue;
1476 }
1477 if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) {
1478 if (le32_to_cpu(fr_crc(fp)) !=
1479 ~crc32(~0, skb->data, fr_len)) {
Robert Loved5488eb2009-06-10 15:30:59 -07001480 if (stats->InvalidCRCCount < 5)
Robert Love85b4aa42008-12-09 15:10:24 -08001481 printk(KERN_WARNING "fcoe: dropping "
1482 "frame with CRC error\n");
1483 stats->InvalidCRCCount++;
1484 stats->ErrorFrames++;
1485 fc_frame_free(fp);
1486 continue;
1487 }
1488 fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
1489 }
Vasu Dev52ff8782009-07-29 17:05:10 -07001490 fc_exch_recv(lp, fp);
Robert Love85b4aa42008-12-09 15:10:24 -08001491 }
1492 return 0;
1493}
1494
1495/**
Chris Leechdd3fd722009-04-21 16:27:36 -07001496 * fcoe_check_wait_queue() - attempt to clear the transmit backlog
1497 * @lp: the fc_lport
Robert Love85b4aa42008-12-09 15:10:24 -08001498 *
1499 * This empties the wait_queue, dequeue the head of the wait_queue queue
1500 * and calls fcoe_start_io() for each packet, if all skb have been
Vasu Devc826a312009-02-27 10:56:27 -08001501 * transmitted, return qlen or -1 if a error occurs, then restore
Chris Leechdd3fd722009-04-21 16:27:36 -07001502 * wait_queue and try again later.
Robert Love85b4aa42008-12-09 15:10:24 -08001503 *
1504 * The wait_queue is used when the skb transmit fails. skb will go
Chris Leechdd3fd722009-04-21 16:27:36 -07001505 * in the wait_queue which will be emptied by the timer function or
Robert Love85b4aa42008-12-09 15:10:24 -08001506 * by the next skb transmit.
Robert Love34f42a02009-02-27 10:55:45 -08001507 */
Vasu Dev4bb6b512009-05-06 10:52:34 -07001508static void fcoe_check_wait_queue(struct fc_lport *lp, struct sk_buff *skb)
Robert Love85b4aa42008-12-09 15:10:24 -08001509{
Chris Leech014f5c32009-08-25 13:59:30 -07001510 struct fcoe_port *port = lport_priv(lp);
Vasu Dev4bb6b512009-05-06 10:52:34 -07001511 int rc;
Robert Love85b4aa42008-12-09 15:10:24 -08001512
Chris Leech014f5c32009-08-25 13:59:30 -07001513 spin_lock_bh(&port->fcoe_pending_queue.lock);
Vasu Dev4bb6b512009-05-06 10:52:34 -07001514
1515 if (skb)
Chris Leech014f5c32009-08-25 13:59:30 -07001516 __skb_queue_tail(&port->fcoe_pending_queue, skb);
Vasu Dev4bb6b512009-05-06 10:52:34 -07001517
Chris Leech014f5c32009-08-25 13:59:30 -07001518 if (port->fcoe_pending_queue_active)
Vasu Devc826a312009-02-27 10:56:27 -08001519 goto out;
Chris Leech014f5c32009-08-25 13:59:30 -07001520 port->fcoe_pending_queue_active = 1;
Chris Leech55c8baf2009-02-27 10:56:32 -08001521
Chris Leech014f5c32009-08-25 13:59:30 -07001522 while (port->fcoe_pending_queue.qlen) {
Chris Leech55c8baf2009-02-27 10:56:32 -08001523 /* keep qlen > 0 until fcoe_start_io succeeds */
Chris Leech014f5c32009-08-25 13:59:30 -07001524 port->fcoe_pending_queue.qlen++;
1525 skb = __skb_dequeue(&port->fcoe_pending_queue);
Chris Leech55c8baf2009-02-27 10:56:32 -08001526
Chris Leech014f5c32009-08-25 13:59:30 -07001527 spin_unlock_bh(&port->fcoe_pending_queue.lock);
Chris Leech55c8baf2009-02-27 10:56:32 -08001528 rc = fcoe_start_io(skb);
Chris Leech014f5c32009-08-25 13:59:30 -07001529 spin_lock_bh(&port->fcoe_pending_queue.lock);
Chris Leech55c8baf2009-02-27 10:56:32 -08001530
1531 if (rc) {
Chris Leech014f5c32009-08-25 13:59:30 -07001532 __skb_queue_head(&port->fcoe_pending_queue, skb);
Chris Leech55c8baf2009-02-27 10:56:32 -08001533 /* undo temporary increment above */
Chris Leech014f5c32009-08-25 13:59:30 -07001534 port->fcoe_pending_queue.qlen--;
Chris Leech55c8baf2009-02-27 10:56:32 -08001535 break;
Robert Love85b4aa42008-12-09 15:10:24 -08001536 }
Chris Leech55c8baf2009-02-27 10:56:32 -08001537 /* undo temporary increment above */
Chris Leech014f5c32009-08-25 13:59:30 -07001538 port->fcoe_pending_queue.qlen--;
Robert Love85b4aa42008-12-09 15:10:24 -08001539 }
Chris Leech55c8baf2009-02-27 10:56:32 -08001540
Chris Leech014f5c32009-08-25 13:59:30 -07001541 if (port->fcoe_pending_queue.qlen < FCOE_LOW_QUEUE_DEPTH)
Chris Leech55c8baf2009-02-27 10:56:32 -08001542 lp->qfull = 0;
Chris Leech014f5c32009-08-25 13:59:30 -07001543 if (port->fcoe_pending_queue.qlen && !timer_pending(&port->timer))
1544 mod_timer(&port->timer, jiffies + 2);
1545 port->fcoe_pending_queue_active = 0;
Vasu Devc826a312009-02-27 10:56:27 -08001546out:
Chris Leech014f5c32009-08-25 13:59:30 -07001547 if (port->fcoe_pending_queue.qlen > FCOE_MAX_QUEUE_DEPTH)
Vasu Dev4bb6b512009-05-06 10:52:34 -07001548 lp->qfull = 1;
Chris Leech014f5c32009-08-25 13:59:30 -07001549 spin_unlock_bh(&port->fcoe_pending_queue.lock);
Vasu Dev4bb6b512009-05-06 10:52:34 -07001550 return;
Robert Love85b4aa42008-12-09 15:10:24 -08001551}
1552
1553/**
Robert Love34f42a02009-02-27 10:55:45 -08001554 * fcoe_dev_setup() - setup link change notification interface
1555 */
Randy Dunlapb0d428a2009-04-27 21:49:31 -07001556static void fcoe_dev_setup(void)
Robert Love85b4aa42008-12-09 15:10:24 -08001557{
Robert Love85b4aa42008-12-09 15:10:24 -08001558 register_netdevice_notifier(&fcoe_notifier);
1559}
1560
1561/**
Randy Dunlapb0d428a2009-04-27 21:49:31 -07001562 * fcoe_dev_cleanup() - cleanup link change notification interface
Robert Love34f42a02009-02-27 10:55:45 -08001563 */
Robert Love85b4aa42008-12-09 15:10:24 -08001564static void fcoe_dev_cleanup(void)
1565{
1566 unregister_netdevice_notifier(&fcoe_notifier);
1567}
1568
1569/**
Robert Love34f42a02009-02-27 10:55:45 -08001570 * fcoe_device_notification() - netdev event notification callback
Robert Love85b4aa42008-12-09 15:10:24 -08001571 * @notifier: context of the notification
1572 * @event: type of event
1573 * @ptr: fixed array for output parsed ifname
1574 *
1575 * This function is called by the ethernet driver in case of link change event
1576 *
1577 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001578 */
Robert Love85b4aa42008-12-09 15:10:24 -08001579static int fcoe_device_notification(struct notifier_block *notifier,
1580 ulong event, void *ptr)
1581{
1582 struct fc_lport *lp = NULL;
Vasu Dev1d1b88d2009-07-29 17:05:45 -07001583 struct net_device *netdev = ptr;
Chris Leech014f5c32009-08-25 13:59:30 -07001584 struct fcoe_interface *fcoe;
Chris Leech2e70e242009-08-25 14:00:23 -07001585 struct fcoe_port *port;
Robert Love85b4aa42008-12-09 15:10:24 -08001586 struct fcoe_dev_stats *stats;
Joe Eykholt97c83892009-03-17 11:42:40 -07001587 u32 link_possible = 1;
Robert Love85b4aa42008-12-09 15:10:24 -08001588 u32 mfs;
1589 int rc = NOTIFY_OK;
1590
Chris Leech014f5c32009-08-25 13:59:30 -07001591 list_for_each_entry(fcoe, &fcoe_hostlist, list) {
Chris Leech25024982009-08-25 13:59:35 -07001592 if (fcoe->netdev == netdev) {
Chris Leech3fe9a0b2009-08-25 13:59:46 -07001593 lp = fcoe->ctlr.lp;
Robert Love85b4aa42008-12-09 15:10:24 -08001594 break;
1595 }
1596 }
Robert Love85b4aa42008-12-09 15:10:24 -08001597 if (lp == NULL) {
1598 rc = NOTIFY_DONE;
1599 goto out;
1600 }
1601
Robert Love85b4aa42008-12-09 15:10:24 -08001602 switch (event) {
1603 case NETDEV_DOWN:
1604 case NETDEV_GOING_DOWN:
Joe Eykholt97c83892009-03-17 11:42:40 -07001605 link_possible = 0;
Robert Love85b4aa42008-12-09 15:10:24 -08001606 break;
1607 case NETDEV_UP:
1608 case NETDEV_CHANGE:
Robert Love85b4aa42008-12-09 15:10:24 -08001609 break;
1610 case NETDEV_CHANGEMTU:
Yi Zou7221d7e2009-10-21 16:27:52 -07001611 if (netdev->features & NETIF_F_FCOE_MTU)
1612 break;
Vasu Dev1d1b88d2009-07-29 17:05:45 -07001613 mfs = netdev->mtu - (sizeof(struct fcoe_hdr) +
1614 sizeof(struct fcoe_crc_eof));
Robert Love85b4aa42008-12-09 15:10:24 -08001615 if (mfs >= FC_MIN_MAX_FRAME)
1616 fc_set_mfs(lp, mfs);
Robert Love85b4aa42008-12-09 15:10:24 -08001617 break;
1618 case NETDEV_REGISTER:
1619 break;
Chris Leech2e70e242009-08-25 14:00:23 -07001620 case NETDEV_UNREGISTER:
1621 list_del(&fcoe->list);
1622 port = lport_priv(fcoe->ctlr.lp);
1623 fcoe_interface_cleanup(fcoe);
1624 schedule_work(&port->destroy_work);
1625 goto out;
1626 break;
Robert Love85b4aa42008-12-09 15:10:24 -08001627 default:
Vasu Dev1d1b88d2009-07-29 17:05:45 -07001628 FCOE_NETDEV_DBG(netdev, "Unknown event %ld "
Robert Loved5488eb2009-06-10 15:30:59 -07001629 "from netdev netlink\n", event);
Robert Love85b4aa42008-12-09 15:10:24 -08001630 }
Joe Eykholt97c83892009-03-17 11:42:40 -07001631 if (link_possible && !fcoe_link_ok(lp))
Chris Leech3fe9a0b2009-08-25 13:59:46 -07001632 fcoe_ctlr_link_up(&fcoe->ctlr);
1633 else if (fcoe_ctlr_link_down(&fcoe->ctlr)) {
Joe Eykholt97c83892009-03-17 11:42:40 -07001634 stats = fc_lport_get_stats(lp);
1635 stats->LinkFailureCount++;
1636 fcoe_clean_pending_queue(lp);
Robert Love85b4aa42008-12-09 15:10:24 -08001637 }
1638out:
1639 return rc;
1640}
1641
1642/**
Robert Love34f42a02009-02-27 10:55:45 -08001643 * fcoe_if_to_netdev() - parse a name buffer to get netdev
Robert Love85b4aa42008-12-09 15:10:24 -08001644 * @buffer: incoming buffer to be copied
1645 *
Chris Leechdd3fd722009-04-21 16:27:36 -07001646 * Returns: NULL or ptr to net_device
Robert Love34f42a02009-02-27 10:55:45 -08001647 */
Robert Love85b4aa42008-12-09 15:10:24 -08001648static struct net_device *fcoe_if_to_netdev(const char *buffer)
1649{
1650 char *cp;
1651 char ifname[IFNAMSIZ + 2];
1652
1653 if (buffer) {
1654 strlcpy(ifname, buffer, IFNAMSIZ);
1655 cp = ifname + strlen(ifname);
1656 while (--cp >= ifname && *cp == '\n')
1657 *cp = '\0';
1658 return dev_get_by_name(&init_net, ifname);
1659 }
1660 return NULL;
1661}
1662
1663/**
Robert Love34f42a02009-02-27 10:55:45 -08001664 * fcoe_destroy() - handles the destroy from sysfs
Chris Leechdd3fd722009-04-21 16:27:36 -07001665 * @buffer: expected to be an eth if name
Robert Love85b4aa42008-12-09 15:10:24 -08001666 * @kp: associated kernel param
1667 *
1668 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001669 */
Robert Love85b4aa42008-12-09 15:10:24 -08001670static int fcoe_destroy(const char *buffer, struct kernel_param *kp)
1671{
Chris Leech030f4e02009-08-25 14:00:02 -07001672 struct fcoe_interface *fcoe;
Chris Leech2e70e242009-08-25 14:00:23 -07001673 struct net_device *netdev;
Mike Christie8eca355f2009-10-21 16:27:44 -07001674 int rc = 0;
Robert Love85b4aa42008-12-09 15:10:24 -08001675
Chris Leechdfc1d0f2009-08-25 14:00:13 -07001676 mutex_lock(&fcoe_config_mutex);
1677#ifdef CONFIG_FCOE_MODULE
1678 /*
1679 * Make sure the module has been initialized, and is not about to be
1680 * removed. Module paramter sysfs files are writable before the
1681 * module_init function is called and after module_exit.
1682 */
1683 if (THIS_MODULE->state != MODULE_STATE_LIVE) {
1684 rc = -ENODEV;
1685 goto out_nodev;
1686 }
1687#endif
1688
Robert Love85b4aa42008-12-09 15:10:24 -08001689 netdev = fcoe_if_to_netdev(buffer);
1690 if (!netdev) {
1691 rc = -ENODEV;
1692 goto out_nodev;
1693 }
Chris Leech2e70e242009-08-25 14:00:23 -07001694
Chris Leech090eb6c2009-08-25 14:00:28 -07001695 rtnl_lock();
Chris Leech2e70e242009-08-25 14:00:23 -07001696 fcoe = fcoe_hostlist_lookup_port(netdev);
1697 if (!fcoe) {
Chris Leech090eb6c2009-08-25 14:00:28 -07001698 rtnl_unlock();
Robert Love85b4aa42008-12-09 15:10:24 -08001699 rc = -ENODEV;
1700 goto out_putdev;
1701 }
Chris Leech2e70e242009-08-25 14:00:23 -07001702 list_del(&fcoe->list);
Chris Leech2e70e242009-08-25 14:00:23 -07001703 fcoe_interface_cleanup(fcoe);
1704 rtnl_unlock();
1705 fcoe_if_destroy(fcoe->ctlr.lp);
Robert Love85b4aa42008-12-09 15:10:24 -08001706out_putdev:
1707 dev_put(netdev);
1708out_nodev:
Chris Leechdfc1d0f2009-08-25 14:00:13 -07001709 mutex_unlock(&fcoe_config_mutex);
Robert Love85b4aa42008-12-09 15:10:24 -08001710 return rc;
1711}
1712
Chris Leech2e70e242009-08-25 14:00:23 -07001713static void fcoe_destroy_work(struct work_struct *work)
1714{
1715 struct fcoe_port *port;
1716
1717 port = container_of(work, struct fcoe_port, destroy_work);
1718 mutex_lock(&fcoe_config_mutex);
1719 fcoe_if_destroy(port->lport);
1720 mutex_unlock(&fcoe_config_mutex);
1721}
1722
Robert Love85b4aa42008-12-09 15:10:24 -08001723/**
Robert Love34f42a02009-02-27 10:55:45 -08001724 * fcoe_create() - Handles the create call from sysfs
Chris Leechdd3fd722009-04-21 16:27:36 -07001725 * @buffer: expected to be an eth if name
Robert Love85b4aa42008-12-09 15:10:24 -08001726 * @kp: associated kernel param
1727 *
1728 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001729 */
Robert Love85b4aa42008-12-09 15:10:24 -08001730static int fcoe_create(const char *buffer, struct kernel_param *kp)
1731{
1732 int rc;
Chris Leech030f4e02009-08-25 14:00:02 -07001733 struct fcoe_interface *fcoe;
Chris Leechaf7f85d2009-08-25 13:59:24 -07001734 struct fc_lport *lport;
Robert Love85b4aa42008-12-09 15:10:24 -08001735 struct net_device *netdev;
1736
Chris Leechdfc1d0f2009-08-25 14:00:13 -07001737 mutex_lock(&fcoe_config_mutex);
1738#ifdef CONFIG_FCOE_MODULE
1739 /*
1740 * Make sure the module has been initialized, and is not about to be
1741 * removed. Module paramter sysfs files are writable before the
1742 * module_init function is called and after module_exit.
1743 */
1744 if (THIS_MODULE->state != MODULE_STATE_LIVE) {
1745 rc = -ENODEV;
1746 goto out_nodev;
1747 }
1748#endif
1749
Chris Leech2e70e242009-08-25 14:00:23 -07001750 rtnl_lock();
Robert Love85b4aa42008-12-09 15:10:24 -08001751 netdev = fcoe_if_to_netdev(buffer);
1752 if (!netdev) {
1753 rc = -ENODEV;
1754 goto out_nodev;
1755 }
Chris Leech2e70e242009-08-25 14:00:23 -07001756
Robert Love85b4aa42008-12-09 15:10:24 -08001757 /* look for existing lport */
1758 if (fcoe_hostlist_lookup(netdev)) {
1759 rc = -EEXIST;
1760 goto out_putdev;
1761 }
Robert Love85b4aa42008-12-09 15:10:24 -08001762
Chris Leech030f4e02009-08-25 14:00:02 -07001763 fcoe = fcoe_interface_create(netdev);
1764 if (!fcoe) {
1765 rc = -ENOMEM;
1766 goto out_putdev;
1767 }
1768
1769 lport = fcoe_if_create(fcoe, &netdev->dev);
Chris Leechaf7f85d2009-08-25 13:59:24 -07001770 if (IS_ERR(lport)) {
Robert Loved5488eb2009-06-10 15:30:59 -07001771 printk(KERN_ERR "fcoe: Failed to create interface (%s)\n",
Robert Love85b4aa42008-12-09 15:10:24 -08001772 netdev->name);
Robert Love85b4aa42008-12-09 15:10:24 -08001773 rc = -EIO;
Chris Leech2e70e242009-08-25 14:00:23 -07001774 fcoe_interface_cleanup(fcoe);
Chris Leech030f4e02009-08-25 14:00:02 -07001775 goto out_free;
Robert Love85b4aa42008-12-09 15:10:24 -08001776 }
Chris Leech030f4e02009-08-25 14:00:02 -07001777
Chris Leech54b649f2009-08-25 14:00:07 -07001778 /* Make this the "master" N_Port */
1779 fcoe->ctlr.lp = lport;
Chris Leech030f4e02009-08-25 14:00:02 -07001780
Chris Leechc863df32009-08-25 14:00:18 -07001781 /* add to lports list */
1782 fcoe_hostlist_add(lport);
1783
Chris Leech54b649f2009-08-25 14:00:07 -07001784 /* start FIP Discovery and FLOGI */
1785 lport->boot_time = jiffies;
1786 fc_fabric_login(lport);
1787 if (!fcoe_link_ok(lport))
1788 fcoe_ctlr_link_up(&fcoe->ctlr);
1789
1790 rc = 0;
Chris Leech030f4e02009-08-25 14:00:02 -07001791out_free:
Chris Leech54b649f2009-08-25 14:00:07 -07001792 /*
1793 * Release from init in fcoe_interface_create(), on success lport
1794 * should be holding a reference taken in fcoe_if_create().
1795 */
Chris Leech030f4e02009-08-25 14:00:02 -07001796 fcoe_interface_put(fcoe);
Robert Love85b4aa42008-12-09 15:10:24 -08001797out_putdev:
1798 dev_put(netdev);
1799out_nodev:
Chris Leech2e70e242009-08-25 14:00:23 -07001800 rtnl_unlock();
Chris Leechdfc1d0f2009-08-25 14:00:13 -07001801 mutex_unlock(&fcoe_config_mutex);
Robert Love85b4aa42008-12-09 15:10:24 -08001802 return rc;
1803}
1804
1805module_param_call(create, fcoe_create, NULL, NULL, S_IWUSR);
1806__MODULE_PARM_TYPE(create, "string");
Chris Leech014f5c32009-08-25 13:59:30 -07001807MODULE_PARM_DESC(create, "Create fcoe fcoe using net device passed in.");
Robert Love85b4aa42008-12-09 15:10:24 -08001808module_param_call(destroy, fcoe_destroy, NULL, NULL, S_IWUSR);
1809__MODULE_PARM_TYPE(destroy, "string");
Chris Leech014f5c32009-08-25 13:59:30 -07001810MODULE_PARM_DESC(destroy, "Destroy fcoe fcoe");
Robert Love85b4aa42008-12-09 15:10:24 -08001811
Robert Love34f42a02009-02-27 10:55:45 -08001812/**
1813 * fcoe_link_ok() - Check if link is ok for the fc_lport
Robert Love85b4aa42008-12-09 15:10:24 -08001814 * @lp: ptr to the fc_lport
1815 *
1816 * Any permanently-disqualifying conditions have been previously checked.
1817 * This also updates the speed setting, which may change with link for 100/1000.
1818 *
1819 * This function should probably be checking for PAUSE support at some point
1820 * in the future. Currently Per-priority-pause is not determinable using
1821 * ethtool, so we shouldn't be restrictive until that problem is resolved.
1822 *
1823 * Returns: 0 if link is OK for use by FCoE.
1824 *
1825 */
1826int fcoe_link_ok(struct fc_lport *lp)
1827{
Chris Leech014f5c32009-08-25 13:59:30 -07001828 struct fcoe_port *port = lport_priv(lp);
Chris Leech25024982009-08-25 13:59:35 -07001829 struct net_device *dev = port->fcoe->netdev;
Robert Love85b4aa42008-12-09 15:10:24 -08001830 struct ethtool_cmd ecmd = { ETHTOOL_GSET };
Robert Love85b4aa42008-12-09 15:10:24 -08001831
Yi Zou2f718d62009-07-29 17:04:01 -07001832 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev) &&
1833 (!dev_ethtool_get_settings(dev, &ecmd))) {
1834 lp->link_supported_speeds &=
1835 ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
1836 if (ecmd.supported & (SUPPORTED_1000baseT_Half |
1837 SUPPORTED_1000baseT_Full))
1838 lp->link_supported_speeds |= FC_PORTSPEED_1GBIT;
1839 if (ecmd.supported & SUPPORTED_10000baseT_Full)
1840 lp->link_supported_speeds |=
1841 FC_PORTSPEED_10GBIT;
1842 if (ecmd.speed == SPEED_1000)
1843 lp->link_speed = FC_PORTSPEED_1GBIT;
1844 if (ecmd.speed == SPEED_10000)
1845 lp->link_speed = FC_PORTSPEED_10GBIT;
Robert Love85b4aa42008-12-09 15:10:24 -08001846
Yi Zou2f718d62009-07-29 17:04:01 -07001847 return 0;
1848 }
1849 return -1;
Robert Love85b4aa42008-12-09 15:10:24 -08001850}
Robert Love85b4aa42008-12-09 15:10:24 -08001851
Robert Love34f42a02009-02-27 10:55:45 -08001852/**
1853 * fcoe_percpu_clean() - Clear the pending skbs for an lport
Robert Love85b4aa42008-12-09 15:10:24 -08001854 * @lp: the fc_lport
Joe Eykholte7a51992009-08-25 14:04:08 -07001855 *
1856 * Must be called with fcoe_create_mutex held to single-thread completion.
1857 *
1858 * This flushes the pending skbs by adding a new skb to each queue and
1859 * waiting until they are all freed. This assures us that not only are
1860 * there no packets that will be handled by the lport, but also that any
1861 * threads already handling packet have returned.
Robert Love85b4aa42008-12-09 15:10:24 -08001862 */
1863void fcoe_percpu_clean(struct fc_lport *lp)
1864{
Robert Love85b4aa42008-12-09 15:10:24 -08001865 struct fcoe_percpu_s *pp;
1866 struct fcoe_rcv_info *fr;
1867 struct sk_buff_head *list;
1868 struct sk_buff *skb, *next;
1869 struct sk_buff *head;
Robert Love5e5e92d2009-03-17 11:41:35 -07001870 unsigned int cpu;
Robert Love85b4aa42008-12-09 15:10:24 -08001871
Robert Love5e5e92d2009-03-17 11:41:35 -07001872 for_each_possible_cpu(cpu) {
1873 pp = &per_cpu(fcoe_percpu, cpu);
1874 spin_lock_bh(&pp->fcoe_rx_list.lock);
1875 list = &pp->fcoe_rx_list;
1876 head = list->next;
1877 for (skb = head; skb != (struct sk_buff *)list;
1878 skb = next) {
1879 next = skb->next;
1880 fr = fcoe_dev_from_skb(skb);
1881 if (fr->fr_dev == lp) {
1882 __skb_unlink(skb, list);
1883 kfree_skb(skb);
Robert Love85b4aa42008-12-09 15:10:24 -08001884 }
Robert Love85b4aa42008-12-09 15:10:24 -08001885 }
Joe Eykholte7a51992009-08-25 14:04:08 -07001886
1887 if (!pp->thread || !cpu_online(cpu)) {
1888 spin_unlock_bh(&pp->fcoe_rx_list.lock);
1889 continue;
1890 }
1891
1892 skb = dev_alloc_skb(0);
1893 if (!skb) {
1894 spin_unlock_bh(&pp->fcoe_rx_list.lock);
1895 continue;
1896 }
1897 skb->destructor = fcoe_percpu_flush_done;
1898
1899 __skb_queue_tail(&pp->fcoe_rx_list, skb);
1900 if (pp->fcoe_rx_list.qlen == 1)
1901 wake_up_process(pp->thread);
Robert Love5e5e92d2009-03-17 11:41:35 -07001902 spin_unlock_bh(&pp->fcoe_rx_list.lock);
Joe Eykholte7a51992009-08-25 14:04:08 -07001903
1904 wait_for_completion(&fcoe_flush_completion);
Robert Love85b4aa42008-12-09 15:10:24 -08001905 }
1906}
Robert Love85b4aa42008-12-09 15:10:24 -08001907
1908/**
Robert Love34f42a02009-02-27 10:55:45 -08001909 * fcoe_clean_pending_queue() - Dequeue a skb and free it
Robert Love85b4aa42008-12-09 15:10:24 -08001910 * @lp: the corresponding fc_lport
1911 *
1912 * Returns: none
Robert Love34f42a02009-02-27 10:55:45 -08001913 */
Robert Love85b4aa42008-12-09 15:10:24 -08001914void fcoe_clean_pending_queue(struct fc_lport *lp)
1915{
Chris Leech014f5c32009-08-25 13:59:30 -07001916 struct fcoe_port *port = lport_priv(lp);
Robert Love85b4aa42008-12-09 15:10:24 -08001917 struct sk_buff *skb;
1918
Chris Leech014f5c32009-08-25 13:59:30 -07001919 spin_lock_bh(&port->fcoe_pending_queue.lock);
1920 while ((skb = __skb_dequeue(&port->fcoe_pending_queue)) != NULL) {
1921 spin_unlock_bh(&port->fcoe_pending_queue.lock);
Robert Love85b4aa42008-12-09 15:10:24 -08001922 kfree_skb(skb);
Chris Leech014f5c32009-08-25 13:59:30 -07001923 spin_lock_bh(&port->fcoe_pending_queue.lock);
Robert Love85b4aa42008-12-09 15:10:24 -08001924 }
Chris Leech014f5c32009-08-25 13:59:30 -07001925 spin_unlock_bh(&port->fcoe_pending_queue.lock);
Robert Love85b4aa42008-12-09 15:10:24 -08001926}
Robert Love85b4aa42008-12-09 15:10:24 -08001927
1928/**
Robert Love34f42a02009-02-27 10:55:45 -08001929 * fcoe_reset() - Resets the fcoe
Robert Love85b4aa42008-12-09 15:10:24 -08001930 * @shost: shost the reset is from
1931 *
1932 * Returns: always 0
1933 */
1934int fcoe_reset(struct Scsi_Host *shost)
1935{
1936 struct fc_lport *lport = shost_priv(shost);
1937 fc_lport_reset(lport);
1938 return 0;
1939}
Robert Love85b4aa42008-12-09 15:10:24 -08001940
Robert Love34f42a02009-02-27 10:55:45 -08001941/**
Chris Leech014f5c32009-08-25 13:59:30 -07001942 * fcoe_hostlist_lookup_port() - find the corresponding lport by a given device
Chris Leechdd3fd722009-04-21 16:27:36 -07001943 * @dev: this is currently ptr to net_device
Robert Love85b4aa42008-12-09 15:10:24 -08001944 *
Chris Leech014f5c32009-08-25 13:59:30 -07001945 * Returns: NULL or the located fcoe_port
Chris Leech090eb6c2009-08-25 14:00:28 -07001946 * Locking: must be called with the RNL mutex held
Robert Love85b4aa42008-12-09 15:10:24 -08001947 */
Chris Leech014f5c32009-08-25 13:59:30 -07001948static struct fcoe_interface *
1949fcoe_hostlist_lookup_port(const struct net_device *dev)
Robert Love85b4aa42008-12-09 15:10:24 -08001950{
Chris Leech014f5c32009-08-25 13:59:30 -07001951 struct fcoe_interface *fcoe;
Robert Love85b4aa42008-12-09 15:10:24 -08001952
Chris Leech014f5c32009-08-25 13:59:30 -07001953 list_for_each_entry(fcoe, &fcoe_hostlist, list) {
Chris Leech25024982009-08-25 13:59:35 -07001954 if (fcoe->netdev == dev)
Chris Leech014f5c32009-08-25 13:59:30 -07001955 return fcoe;
Robert Love85b4aa42008-12-09 15:10:24 -08001956 }
Robert Love85b4aa42008-12-09 15:10:24 -08001957 return NULL;
1958}
1959
Robert Love34f42a02009-02-27 10:55:45 -08001960/**
1961 * fcoe_hostlist_lookup() - Find the corresponding lport by netdev
Robert Love85b4aa42008-12-09 15:10:24 -08001962 * @netdev: ptr to net_device
1963 *
1964 * Returns: 0 for success
Chris Leech090eb6c2009-08-25 14:00:28 -07001965 * Locking: must be called with the RTNL mutex held
Robert Love85b4aa42008-12-09 15:10:24 -08001966 */
Chris Leech090eb6c2009-08-25 14:00:28 -07001967static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev)
Robert Love85b4aa42008-12-09 15:10:24 -08001968{
Chris Leech014f5c32009-08-25 13:59:30 -07001969 struct fcoe_interface *fcoe;
Robert Love85b4aa42008-12-09 15:10:24 -08001970
Chris Leech014f5c32009-08-25 13:59:30 -07001971 fcoe = fcoe_hostlist_lookup_port(netdev);
Chris Leech3fe9a0b2009-08-25 13:59:46 -07001972 return (fcoe) ? fcoe->ctlr.lp : NULL;
Robert Love85b4aa42008-12-09 15:10:24 -08001973}
Robert Love85b4aa42008-12-09 15:10:24 -08001974
Robert Love34f42a02009-02-27 10:55:45 -08001975/**
1976 * fcoe_hostlist_add() - Add a lport to lports list
Chris Leechdd3fd722009-04-21 16:27:36 -07001977 * @lp: ptr to the fc_lport to be added
Robert Love85b4aa42008-12-09 15:10:24 -08001978 *
1979 * Returns: 0 for success
Chris Leech090eb6c2009-08-25 14:00:28 -07001980 * Locking: must be called with the RTNL mutex held
Robert Love85b4aa42008-12-09 15:10:24 -08001981 */
Chris Leech090eb6c2009-08-25 14:00:28 -07001982static int fcoe_hostlist_add(const struct fc_lport *lport)
Robert Love85b4aa42008-12-09 15:10:24 -08001983{
Chris Leech014f5c32009-08-25 13:59:30 -07001984 struct fcoe_interface *fcoe;
1985 struct fcoe_port *port;
Robert Love85b4aa42008-12-09 15:10:24 -08001986
Chris Leech014f5c32009-08-25 13:59:30 -07001987 fcoe = fcoe_hostlist_lookup_port(fcoe_netdev(lport));
1988 if (!fcoe) {
1989 port = lport_priv(lport);
1990 fcoe = port->fcoe;
1991 list_add_tail(&fcoe->list, &fcoe_hostlist);
Robert Love85b4aa42008-12-09 15:10:24 -08001992 }
1993 return 0;
1994}
Robert Love85b4aa42008-12-09 15:10:24 -08001995
Robert Love34f42a02009-02-27 10:55:45 -08001996/**
Robert Love34f42a02009-02-27 10:55:45 -08001997 * fcoe_init() - fcoe module loading initialization
Robert Love85b4aa42008-12-09 15:10:24 -08001998 *
Robert Love85b4aa42008-12-09 15:10:24 -08001999 * Returns 0 on success, negative on failure
Robert Love34f42a02009-02-27 10:55:45 -08002000 */
Robert Love85b4aa42008-12-09 15:10:24 -08002001static int __init fcoe_init(void)
2002{
Robert Love38eccab2009-03-17 11:41:30 -07002003 unsigned int cpu;
Robert Love8976f422009-03-17 11:41:46 -07002004 int rc = 0;
Robert Love85b4aa42008-12-09 15:10:24 -08002005 struct fcoe_percpu_s *p;
2006
Chris Leechdfc1d0f2009-08-25 14:00:13 -07002007 mutex_lock(&fcoe_config_mutex);
2008
Robert Love38eccab2009-03-17 11:41:30 -07002009 for_each_possible_cpu(cpu) {
Robert Love5e5e92d2009-03-17 11:41:35 -07002010 p = &per_cpu(fcoe_percpu, cpu);
Robert Love38eccab2009-03-17 11:41:30 -07002011 skb_queue_head_init(&p->fcoe_rx_list);
2012 }
2013
Robert Love8976f422009-03-17 11:41:46 -07002014 for_each_online_cpu(cpu)
2015 fcoe_percpu_thread_create(cpu);
Robert Love85b4aa42008-12-09 15:10:24 -08002016
Robert Love8976f422009-03-17 11:41:46 -07002017 /* Initialize per CPU interrupt thread */
2018 rc = register_hotcpu_notifier(&fcoe_cpu_notifier);
2019 if (rc)
2020 goto out_free;
Robert Love85b4aa42008-12-09 15:10:24 -08002021
Robert Love8976f422009-03-17 11:41:46 -07002022 /* Setup link change notification */
Robert Love85b4aa42008-12-09 15:10:24 -08002023 fcoe_dev_setup();
2024
Chris Leech5892c322009-08-25 13:59:14 -07002025 rc = fcoe_if_init();
2026 if (rc)
2027 goto out_free;
Robert Love85b4aa42008-12-09 15:10:24 -08002028
Chris Leechdfc1d0f2009-08-25 14:00:13 -07002029 mutex_unlock(&fcoe_config_mutex);
Robert Love85b4aa42008-12-09 15:10:24 -08002030 return 0;
Robert Love8976f422009-03-17 11:41:46 -07002031
2032out_free:
2033 for_each_online_cpu(cpu) {
2034 fcoe_percpu_thread_destroy(cpu);
2035 }
Chris Leechdfc1d0f2009-08-25 14:00:13 -07002036 mutex_unlock(&fcoe_config_mutex);
Robert Love8976f422009-03-17 11:41:46 -07002037 return rc;
Robert Love85b4aa42008-12-09 15:10:24 -08002038}
2039module_init(fcoe_init);
2040
2041/**
Robert Love34f42a02009-02-27 10:55:45 -08002042 * fcoe_exit() - fcoe module unloading cleanup
Robert Love85b4aa42008-12-09 15:10:24 -08002043 *
2044 * Returns 0 on success, negative on failure
Robert Love34f42a02009-02-27 10:55:45 -08002045 */
Robert Love85b4aa42008-12-09 15:10:24 -08002046static void __exit fcoe_exit(void)
2047{
Robert Love5e5e92d2009-03-17 11:41:35 -07002048 unsigned int cpu;
Chris Leech014f5c32009-08-25 13:59:30 -07002049 struct fcoe_interface *fcoe, *tmp;
Chris Leech2e70e242009-08-25 14:00:23 -07002050 struct fcoe_port *port;
Robert Love85b4aa42008-12-09 15:10:24 -08002051
Chris Leechdfc1d0f2009-08-25 14:00:13 -07002052 mutex_lock(&fcoe_config_mutex);
2053
Robert Love85b4aa42008-12-09 15:10:24 -08002054 fcoe_dev_cleanup();
2055
Vasu Dev5919a592009-03-27 09:03:29 -07002056 /* releases the associated fcoe hosts */
Chris Leech090eb6c2009-08-25 14:00:28 -07002057 rtnl_lock();
2058 list_for_each_entry_safe(fcoe, tmp, &fcoe_hostlist, list) {
Chris Leechc863df32009-08-25 14:00:18 -07002059 list_del(&fcoe->list);
Chris Leech2e70e242009-08-25 14:00:23 -07002060 port = lport_priv(fcoe->ctlr.lp);
Chris Leech2e70e242009-08-25 14:00:23 -07002061 fcoe_interface_cleanup(fcoe);
Chris Leech2e70e242009-08-25 14:00:23 -07002062 schedule_work(&port->destroy_work);
Chris Leechc863df32009-08-25 14:00:18 -07002063 }
Chris Leech090eb6c2009-08-25 14:00:28 -07002064 rtnl_unlock();
Robert Love85b4aa42008-12-09 15:10:24 -08002065
Robert Love8976f422009-03-17 11:41:46 -07002066 unregister_hotcpu_notifier(&fcoe_cpu_notifier);
2067
Chris Leech014f5c32009-08-25 13:59:30 -07002068 for_each_online_cpu(cpu)
Robert Love8976f422009-03-17 11:41:46 -07002069 fcoe_percpu_thread_destroy(cpu);
Robert Love85b4aa42008-12-09 15:10:24 -08002070
Chris Leechdfc1d0f2009-08-25 14:00:13 -07002071 mutex_unlock(&fcoe_config_mutex);
Chris Leech2e70e242009-08-25 14:00:23 -07002072
2073 /* flush any asyncronous interface destroys,
2074 * this should happen after the netdev notifier is unregistered */
2075 flush_scheduled_work();
2076
2077 /* detach from scsi transport
2078 * must happen after all destroys are done, therefor after the flush */
2079 fcoe_if_exit();
Robert Love85b4aa42008-12-09 15:10:24 -08002080}
2081module_exit(fcoe_exit);
Chris Leech11b56182009-11-03 11:46:29 -08002082
2083/**
2084 * fcoe_flogi_resp() - FCoE specific FLOGI and FDISC response handler
2085 * @seq: active sequence in the FLOGI or FDISC exchange
2086 * @fp: response frame, or error encoded in a pointer (timeout)
2087 * @arg: pointer the the fcoe_ctlr structure
2088 *
2089 * This handles MAC address managment for FCoE, then passes control on to
2090 * the libfc FLOGI response handler.
2091 */
2092static void fcoe_flogi_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg)
2093{
2094 struct fcoe_ctlr *fip = arg;
2095 struct fc_exch *exch = fc_seq_exch(seq);
2096 struct fc_lport *lport = exch->lp;
2097 u8 *mac;
2098
2099 if (IS_ERR(fp))
2100 goto done;
2101
2102 mac = fr_cb(fp)->granted_mac;
2103 if (is_zero_ether_addr(mac)) {
2104 /* pre-FIP */
2105 mac = eth_hdr(&fp->skb)->h_source;
2106 if (fcoe_ctlr_recv_flogi(fip, lport, fp, mac)) {
2107 fc_frame_free(fp);
2108 return;
2109 }
2110 } else {
2111 /* FIP, libfcoe has already seen it */
2112 fip->update_mac(lport, fr_cb(fp)->granted_mac);
2113 }
2114done:
2115 fc_lport_flogi_resp(seq, fp, lport);
2116}
2117
2118/**
2119 * fcoe_logo_resp() - FCoE specific LOGO response handler
2120 * @seq: active sequence in the LOGO exchange
2121 * @fp: response frame, or error encoded in a pointer (timeout)
2122 * @arg: pointer the the fcoe_ctlr structure
2123 *
2124 * This handles MAC address managment for FCoE, then passes control on to
2125 * the libfc LOGO response handler.
2126 */
2127static void fcoe_logo_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg)
2128{
2129 struct fcoe_ctlr *fip = arg;
2130 struct fc_exch *exch = fc_seq_exch(seq);
2131 struct fc_lport *lport = exch->lp;
2132 static u8 zero_mac[ETH_ALEN] = { 0 };
2133
2134 if (!IS_ERR(fp))
2135 fip->update_mac(lport, zero_mac);
2136 fc_lport_logo_resp(seq, fp, lport);
2137}
2138
2139/**
2140 * fcoe_elsct_send - FCoE specific ELS handler
2141 *
2142 * This does special case handling of FIP encapsualted ELS exchanges for FCoE,
2143 * using FCoE specific response handlers and passing the FIP controller as
2144 * the argument (the lport is still available from the exchange).
2145 *
2146 * Most of the work here is just handed off to the libfc routine.
2147 */
2148static struct fc_seq *fcoe_elsct_send(struct fc_lport *lport,
2149 u32 did, struct fc_frame *fp, unsigned int op,
2150 void (*resp)(struct fc_seq *, struct fc_frame *, void *),
2151 void *arg, u32 timeout)
2152{
2153 struct fcoe_port *port = lport_priv(lport);
2154 struct fcoe_interface *fcoe = port->fcoe;
2155 struct fcoe_ctlr *fip = &fcoe->ctlr;
2156 struct fc_frame_header *fh = fc_frame_header_get(fp);
2157
2158 switch (op) {
2159 case ELS_FLOGI:
2160 case ELS_FDISC:
2161 return fc_elsct_send(lport, did, fp, op, fcoe_flogi_resp,
2162 fip, timeout);
2163 case ELS_LOGO:
2164 /* only hook onto fabric logouts, not port logouts */
2165 if (ntoh24(fh->fh_d_id) != FC_FID_FLOGI)
2166 break;
2167 return fc_elsct_send(lport, did, fp, op, fcoe_logo_resp,
2168 fip, timeout);
2169 }
2170 return fc_elsct_send(lport, did, fp, op, resp, arg, timeout);
2171}
2172