blob: 0306aa95eb343c2e252e0e055cc4e91e3effb00d [file] [log] [blame]
Robert Love85b4aa42008-12-09 15:10:24 -08001/*
2 * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 * Maintained at www.Open-FCoE.org
18 */
19
20#include <linux/module.h>
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
52/* fcoe host list */
53LIST_HEAD(fcoe_hostlist);
54DEFINE_RWLOCK(fcoe_hostlist_lock);
Robert Love5e5e92d2009-03-17 11:41:35 -070055DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu);
Robert Love85b4aa42008-12-09 15:10:24 -080056
Chris Leechdd3fd722009-04-21 16:27:36 -070057/* Function Prototypes */
Vasu Devfdd78022009-03-17 11:42:24 -070058static int fcoe_reset(struct Scsi_Host *shost);
59static int fcoe_xmit(struct fc_lport *, struct fc_frame *);
60static int fcoe_rcv(struct sk_buff *, struct net_device *,
61 struct packet_type *, struct net_device *);
62static int fcoe_percpu_receive_thread(void *arg);
63static void fcoe_clean_pending_queue(struct fc_lport *lp);
64static void fcoe_percpu_clean(struct fc_lport *lp);
65static int fcoe_link_ok(struct fc_lport *lp);
66
67static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *);
68static int fcoe_hostlist_add(const struct fc_lport *);
69static int fcoe_hostlist_remove(const struct fc_lport *);
70
Vasu Dev4bb6b512009-05-06 10:52:34 -070071static void fcoe_check_wait_queue(struct fc_lport *, struct sk_buff *);
Robert Love85b4aa42008-12-09 15:10:24 -080072static int fcoe_device_notification(struct notifier_block *, ulong, void *);
73static void fcoe_dev_setup(void);
74static void fcoe_dev_cleanup(void);
75
76/* notification function from net device */
77static struct notifier_block fcoe_notifier = {
78 .notifier_call = fcoe_device_notification,
79};
80
Vasu Dev7f349142009-03-27 09:06:31 -070081static struct scsi_transport_template *scsi_transport_fcoe_sw;
82
83struct fc_function_template fcoe_transport_function = {
84 .show_host_node_name = 1,
85 .show_host_port_name = 1,
86 .show_host_supported_classes = 1,
87 .show_host_supported_fc4s = 1,
88 .show_host_active_fc4s = 1,
89 .show_host_maxframe_size = 1,
90
91 .show_host_port_id = 1,
92 .show_host_supported_speeds = 1,
93 .get_host_speed = fc_get_host_speed,
94 .show_host_speed = 1,
95 .show_host_port_type = 1,
96 .get_host_port_state = fc_get_host_port_state,
97 .show_host_port_state = 1,
98 .show_host_symbolic_name = 1,
99
100 .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv),
101 .show_rport_maxframe_size = 1,
102 .show_rport_supported_classes = 1,
103
104 .show_host_fabric_name = 1,
105 .show_starget_node_name = 1,
106 .show_starget_port_name = 1,
107 .show_starget_port_id = 1,
108 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
109 .show_rport_dev_loss_tmo = 1,
110 .get_fc_host_stats = fc_get_host_stats,
111 .issue_fc_host_lip = fcoe_reset,
112
113 .terminate_rport_io = fc_rport_terminate_io,
114};
115
116static struct scsi_host_template fcoe_shost_template = {
117 .module = THIS_MODULE,
118 .name = "FCoE Driver",
119 .proc_name = FCOE_NAME,
120 .queuecommand = fc_queuecommand,
121 .eh_abort_handler = fc_eh_abort,
122 .eh_device_reset_handler = fc_eh_device_reset,
123 .eh_host_reset_handler = fc_eh_host_reset,
124 .slave_alloc = fc_slave_alloc,
125 .change_queue_depth = fc_change_queue_depth,
126 .change_queue_type = fc_change_queue_type,
127 .this_id = -1,
128 .cmd_per_lun = 32,
129 .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS,
130 .use_clustering = ENABLE_CLUSTERING,
131 .sg_tablesize = SG_ALL,
132 .max_sectors = 0xffff,
133};
134
135/**
Vasu Devab6b85c2009-05-17 12:33:08 +0000136 * fcoe_fip_recv - handle a received FIP frame.
137 * @skb: the receive skb
138 * @dev: associated &net_device
139 * @ptype: the &packet_type structure which was used to register this handler.
140 * @orig_dev: original receive &net_device, in case @dev is a bond.
141 *
142 * Returns: 0 for success
143 */
144static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *dev,
145 struct packet_type *ptype,
146 struct net_device *orig_dev)
147{
148 struct fcoe_softc *fc;
149
150 fc = container_of(ptype, struct fcoe_softc, fip_packet_type);
151 fcoe_ctlr_recv(&fc->ctlr, skb);
152 return 0;
153}
154
155/**
156 * fcoe_fip_send() - send an Ethernet-encapsulated FIP frame.
157 * @fip: FCoE controller.
158 * @skb: FIP Packet.
159 */
160static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
161{
162 skb->dev = fcoe_from_ctlr(fip)->real_dev;
163 dev_queue_xmit(skb);
164}
165
166/**
167 * fcoe_update_src_mac() - Update Ethernet MAC filters.
168 * @fip: FCoE controller.
169 * @old: Unicast MAC address to delete if the MAC is non-zero.
170 * @new: Unicast MAC address to add.
171 *
172 * Remove any previously-set unicast MAC filter.
173 * Add secondary FCoE MAC address filter for our OUI.
174 */
175static void fcoe_update_src_mac(struct fcoe_ctlr *fip, u8 *old, u8 *new)
176{
177 struct fcoe_softc *fc;
178
179 fc = fcoe_from_ctlr(fip);
180 rtnl_lock();
181 if (!is_zero_ether_addr(old))
Jiri Pirkoccffad22009-05-22 23:22:17 +0000182 dev_unicast_delete(fc->real_dev, old);
183 dev_unicast_add(fc->real_dev, new);
Vasu Devab6b85c2009-05-17 12:33:08 +0000184 rtnl_unlock();
185}
186
187/**
Vasu Dev7f349142009-03-27 09:06:31 -0700188 * fcoe_lport_config() - sets up the fc_lport
189 * @lp: ptr to the fc_lport
Vasu Dev7f349142009-03-27 09:06:31 -0700190 *
191 * Returns: 0 for success
192 */
193static int fcoe_lport_config(struct fc_lport *lp)
194{
195 lp->link_up = 0;
196 lp->qfull = 0;
197 lp->max_retry_count = 3;
Abhijeet Joglekara3666952009-05-01 10:01:26 -0700198 lp->max_rport_retry_count = 3;
Vasu Dev7f349142009-03-27 09:06:31 -0700199 lp->e_d_tov = 2 * 1000; /* FC-FS default */
200 lp->r_a_tov = 2 * 2 * 1000;
201 lp->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
202 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
203
204 fc_lport_init_stats(lp);
205
206 /* lport fc_lport related configuration */
207 fc_lport_config(lp);
208
209 /* offload related configuration */
210 lp->crc_offload = 0;
211 lp->seq_offload = 0;
212 lp->lro_enabled = 0;
213 lp->lro_xid = 0;
214 lp->lso_max = 0;
215
216 return 0;
217}
218
219/**
Vasu Devab6b85c2009-05-17 12:33:08 +0000220 * fcoe_netdev_cleanup() - clean up netdev configurations
221 * @fc: ptr to the fcoe_softc
222 */
223void fcoe_netdev_cleanup(struct fcoe_softc *fc)
224{
225 u8 flogi_maddr[ETH_ALEN];
226
227 /* Don't listen for Ethernet packets anymore */
228 dev_remove_pack(&fc->fcoe_packet_type);
229 dev_remove_pack(&fc->fip_packet_type);
230
231 /* Delete secondary MAC addresses */
232 rtnl_lock();
233 memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
Jiri Pirkoccffad22009-05-22 23:22:17 +0000234 dev_unicast_delete(fc->real_dev, flogi_maddr);
Vasu Devab6b85c2009-05-17 12:33:08 +0000235 if (!is_zero_ether_addr(fc->ctlr.data_src_addr))
Jiri Pirkoccffad22009-05-22 23:22:17 +0000236 dev_unicast_delete(fc->real_dev, fc->ctlr.data_src_addr);
Vasu Dev184dd342009-05-17 12:33:28 +0000237 if (fc->ctlr.spma)
Jiri Pirkoccffad22009-05-22 23:22:17 +0000238 dev_unicast_delete(fc->real_dev, fc->ctlr.ctl_src_addr);
Vasu Devab6b85c2009-05-17 12:33:08 +0000239 dev_mc_delete(fc->real_dev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
240 rtnl_unlock();
241}
242
243/**
Vasu Dev1047f222009-05-06 10:52:40 -0700244 * fcoe_queue_timer() - fcoe queue timer
245 * @lp: the fc_lport pointer
246 *
247 * Calls fcoe_check_wait_queue on timeout
248 *
249 */
250static void fcoe_queue_timer(ulong lp)
251{
252 fcoe_check_wait_queue((struct fc_lport *)lp, NULL);
253}
254
255/**
Vasu Dev7f349142009-03-27 09:06:31 -0700256 * fcoe_netdev_config() - Set up netdev for SW FCoE
257 * @lp : ptr to the fc_lport
258 * @netdev : ptr to the associated netdevice struct
259 *
260 * Must be called after fcoe_lport_config() as it will use lport mutex
261 *
262 * Returns : 0 for success
263 */
264static int fcoe_netdev_config(struct fc_lport *lp, struct net_device *netdev)
265{
266 u32 mfs;
267 u64 wwnn, wwpn;
268 struct fcoe_softc *fc;
269 u8 flogi_maddr[ETH_ALEN];
Vasu Dev184dd342009-05-17 12:33:28 +0000270 struct netdev_hw_addr *ha;
Vasu Dev7f349142009-03-27 09:06:31 -0700271
272 /* Setup lport private data to point to fcoe softc */
273 fc = lport_priv(lp);
Joe Eykholt97c83892009-03-17 11:42:40 -0700274 fc->ctlr.lp = lp;
Vasu Dev7f349142009-03-27 09:06:31 -0700275 fc->real_dev = netdev;
276 fc->phys_dev = netdev;
277
278 /* Require support for get_pauseparam ethtool op. */
279 if (netdev->priv_flags & IFF_802_1Q_VLAN)
280 fc->phys_dev = vlan_dev_real_dev(netdev);
281
282 /* Do not support for bonding device */
283 if ((fc->real_dev->priv_flags & IFF_MASTER_ALB) ||
284 (fc->real_dev->priv_flags & IFF_SLAVE_INACTIVE) ||
285 (fc->real_dev->priv_flags & IFF_MASTER_8023AD)) {
286 return -EOPNOTSUPP;
287 }
288
289 /*
290 * Determine max frame size based on underlying device and optional
291 * user-configured limit. If the MFS is too low, fcoe_link_ok()
292 * will return 0, so do this first.
293 */
294 mfs = fc->real_dev->mtu - (sizeof(struct fcoe_hdr) +
295 sizeof(struct fcoe_crc_eof));
296 if (fc_set_mfs(lp, mfs))
297 return -EINVAL;
298
Vasu Dev7f349142009-03-27 09:06:31 -0700299 /* offload features support */
300 if (fc->real_dev->features & NETIF_F_SG)
301 lp->sg_supp = 1;
302
303#ifdef NETIF_F_FCOE_CRC
304 if (netdev->features & NETIF_F_FCOE_CRC) {
305 lp->crc_offload = 1;
Robert Loved5488eb2009-06-10 15:30:59 -0700306 FCOE_NETDEV_DBG(netdev, "Supports FCCRC offload\n");
Vasu Dev7f349142009-03-27 09:06:31 -0700307 }
308#endif
309#ifdef NETIF_F_FSO
310 if (netdev->features & NETIF_F_FSO) {
311 lp->seq_offload = 1;
312 lp->lso_max = netdev->gso_max_size;
Robert Loved5488eb2009-06-10 15:30:59 -0700313 FCOE_NETDEV_DBG(netdev, "Supports LSO for max len 0x%x\n",
314 lp->lso_max);
Vasu Dev7f349142009-03-27 09:06:31 -0700315 }
316#endif
317 if (netdev->fcoe_ddp_xid) {
318 lp->lro_enabled = 1;
319 lp->lro_xid = netdev->fcoe_ddp_xid;
Robert Loved5488eb2009-06-10 15:30:59 -0700320 FCOE_NETDEV_DBG(netdev, "Supports LRO for max xid 0x%x\n",
321 lp->lro_xid);
Vasu Dev7f349142009-03-27 09:06:31 -0700322 }
323 skb_queue_head_init(&fc->fcoe_pending_queue);
324 fc->fcoe_pending_queue_active = 0;
Vasu Dev1047f222009-05-06 10:52:40 -0700325 setup_timer(&fc->timer, fcoe_queue_timer, (unsigned long)lp);
Vasu Dev7f349142009-03-27 09:06:31 -0700326
Vasu Dev184dd342009-05-17 12:33:28 +0000327 /* look for SAN MAC address, if multiple SAN MACs exist, only
328 * use the first one for SPMA */
329 rcu_read_lock();
330 for_each_dev_addr(netdev, ha) {
331 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
Yi Zou7a7f0c72009-07-29 17:03:50 -0700332 (is_valid_ether_addr(ha->addr))) {
Vasu Dev184dd342009-05-17 12:33:28 +0000333 memcpy(fc->ctlr.ctl_src_addr, ha->addr, ETH_ALEN);
334 fc->ctlr.spma = 1;
335 break;
336 }
337 }
338 rcu_read_unlock();
339
Vasu Dev7f349142009-03-27 09:06:31 -0700340 /* setup Source Mac Address */
Vasu Dev184dd342009-05-17 12:33:28 +0000341 if (!fc->ctlr.spma)
342 memcpy(fc->ctlr.ctl_src_addr, fc->real_dev->dev_addr,
343 fc->real_dev->addr_len);
Vasu Dev7f349142009-03-27 09:06:31 -0700344
345 wwnn = fcoe_wwn_from_mac(fc->real_dev->dev_addr, 1, 0);
346 fc_set_wwnn(lp, wwnn);
347 /* XXX - 3rd arg needs to be vlan id */
348 wwpn = fcoe_wwn_from_mac(fc->real_dev->dev_addr, 2, 0);
349 fc_set_wwpn(lp, wwpn);
350
351 /*
352 * Add FCoE MAC address as second unicast MAC address
353 * or enter promiscuous mode if not capable of listening
354 * for multiple unicast MACs.
355 */
356 rtnl_lock();
357 memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
Jiri Pirkoccffad22009-05-22 23:22:17 +0000358 dev_unicast_add(fc->real_dev, flogi_maddr);
Vasu Dev184dd342009-05-17 12:33:28 +0000359 if (fc->ctlr.spma)
Jiri Pirkoccffad22009-05-22 23:22:17 +0000360 dev_unicast_add(fc->real_dev, fc->ctlr.ctl_src_addr);
Joe Eykholt6401bdc2009-04-21 16:27:46 -0700361 dev_mc_add(fc->real_dev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
Vasu Dev7f349142009-03-27 09:06:31 -0700362 rtnl_unlock();
363
364 /*
365 * setup the receive function from ethernet driver
366 * on the ethertype for the given device
367 */
368 fc->fcoe_packet_type.func = fcoe_rcv;
369 fc->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
370 fc->fcoe_packet_type.dev = fc->real_dev;
371 dev_add_pack(&fc->fcoe_packet_type);
372
Vasu Devab6b85c2009-05-17 12:33:08 +0000373 fc->fip_packet_type.func = fcoe_fip_recv;
374 fc->fip_packet_type.type = htons(ETH_P_FIP);
375 fc->fip_packet_type.dev = fc->real_dev;
376 dev_add_pack(&fc->fip_packet_type);
377
Vasu Dev7f349142009-03-27 09:06:31 -0700378 return 0;
379}
380
381/**
382 * fcoe_shost_config() - Sets up fc_lport->host
383 * @lp : ptr to the fc_lport
384 * @shost : ptr to the associated scsi host
385 * @dev : device associated to scsi host
386 *
387 * Must be called after fcoe_lport_config() and fcoe_netdev_config()
388 *
389 * Returns : 0 for success
390 */
391static int fcoe_shost_config(struct fc_lport *lp, struct Scsi_Host *shost,
392 struct device *dev)
393{
394 int rc = 0;
395
396 /* lport scsi host config */
397 lp->host = shost;
398
399 lp->host->max_lun = FCOE_MAX_LUN;
400 lp->host->max_id = FCOE_MAX_FCP_TARGET;
401 lp->host->max_channel = 0;
402 lp->host->transportt = scsi_transport_fcoe_sw;
403
404 /* add the new host to the SCSI-ml */
405 rc = scsi_add_host(lp->host, dev);
406 if (rc) {
Robert Loved5488eb2009-06-10 15:30:59 -0700407 FCOE_NETDEV_DBG(fcoe_netdev(lp), "fcoe_shost_config: "
408 "error on scsi_add_host\n");
Vasu Dev7f349142009-03-27 09:06:31 -0700409 return rc;
410 }
411 sprintf(fc_host_symbolic_name(lp->host), "%s v%s over %s",
412 FCOE_NAME, FCOE_VERSION,
413 fcoe_netdev(lp)->name);
414
415 return 0;
416}
417
Vasu Devd7179682009-07-29 17:05:21 -0700418/*
419 * fcoe_oem_match() - match for read types IO
420 * @fp: the fc_frame for new IO.
421 *
422 * Returns : true for read types IO, otherwise returns false.
423 */
424bool fcoe_oem_match(struct fc_frame *fp)
425{
426 return fc_fcp_is_read(fr_fsp(fp));
427}
428
Vasu Dev7f349142009-03-27 09:06:31 -0700429/**
430 * fcoe_em_config() - allocates em for this lport
431 * @lp: the port that em is to allocated for
432 *
Vasu Deve8af4d42009-07-29 17:05:15 -0700433 * Called with write fcoe_hostlist_lock held.
434 *
Vasu Dev7f349142009-03-27 09:06:31 -0700435 * Returns : 0 on success
436 */
437static inline int fcoe_em_config(struct fc_lport *lp)
438{
Vasu Devd7179682009-07-29 17:05:21 -0700439 struct fcoe_softc *fc = lport_priv(lp);
440 struct fcoe_softc *oldfc = NULL;
441 u16 min_xid = FCOE_MIN_XID;
442 u16 max_xid = FCOE_MAX_XID;
443
444 /*
445 * Check if need to allocate an em instance for
446 * offload exchange ids to be shared across all VN_PORTs/lport.
447 */
448 if (!lp->lro_enabled || !lp->lro_xid || (lp->lro_xid >= max_xid)) {
449 lp->lro_xid = 0;
450 goto skip_oem;
451 }
452
453 /*
454 * Reuse existing offload em instance in case
455 * it is already allocated on phys_dev.
456 */
457 list_for_each_entry(oldfc, &fcoe_hostlist, list) {
458 if (oldfc->phys_dev == fc->phys_dev) {
459 fc->oem = oldfc->oem;
460 break;
461 }
462 }
463
464 if (fc->oem) {
465 if (!fc_exch_mgr_add(lp, fc->oem, fcoe_oem_match)) {
466 printk(KERN_ERR "fcoe_em_config: failed to add "
467 "offload em:%p on interface:%s\n",
468 fc->oem, fc->real_dev->name);
469 return -ENOMEM;
470 }
471 } else {
472 fc->oem = fc_exch_mgr_alloc(lp, FC_CLASS_3,
473 FCOE_MIN_XID, lp->lro_xid,
474 fcoe_oem_match);
475 if (!fc->oem) {
476 printk(KERN_ERR "fcoe_em_config: failed to allocate "
477 "em for offload exches on interface:%s\n",
478 fc->real_dev->name);
479 return -ENOMEM;
480 }
481 }
482
483 /*
484 * Exclude offload EM xid range from next EM xid range.
485 */
486 min_xid += lp->lro_xid + 1;
487
488skip_oem:
489 if (!fc_exch_mgr_alloc(lp, FC_CLASS_3, min_xid, max_xid, NULL)) {
490 printk(KERN_ERR "fcoe_em_config: failed to "
491 "allocate em on interface %s\n", fc->real_dev->name);
Vasu Dev7f349142009-03-27 09:06:31 -0700492 return -ENOMEM;
Vasu Devd7179682009-07-29 17:05:21 -0700493 }
Vasu Dev7f349142009-03-27 09:06:31 -0700494
495 return 0;
496}
497
498/**
499 * fcoe_if_destroy() - FCoE software HBA tear-down function
500 * @netdev: ptr to the associated net_device
501 *
502 * Returns: 0 if link is OK for use by FCoE.
503 */
504static int fcoe_if_destroy(struct net_device *netdev)
505{
506 struct fc_lport *lp = NULL;
507 struct fcoe_softc *fc;
Vasu Dev7f349142009-03-27 09:06:31 -0700508
509 BUG_ON(!netdev);
510
Robert Loved5488eb2009-06-10 15:30:59 -0700511 FCOE_NETDEV_DBG(netdev, "Destroying interface\n");
Vasu Dev7f349142009-03-27 09:06:31 -0700512
513 lp = fcoe_hostlist_lookup(netdev);
514 if (!lp)
515 return -ENODEV;
516
517 fc = lport_priv(lp);
518
519 /* Logout of the fabric */
520 fc_fabric_logoff(lp);
521
522 /* Remove the instance from fcoe's list */
523 fcoe_hostlist_remove(lp);
524
Vasu Devab6b85c2009-05-17 12:33:08 +0000525 /* clean up netdev configurations */
526 fcoe_netdev_cleanup(fc);
527
528 /* tear-down the FCoE controller */
Joe Eykholt97c83892009-03-17 11:42:40 -0700529 fcoe_ctlr_destroy(&fc->ctlr);
Vasu Dev7f349142009-03-27 09:06:31 -0700530
Joe Eykholtf161fb72009-07-29 17:04:17 -0700531 /* Free queued packets for the per-CPU receive threads */
532 fcoe_percpu_clean(lp);
533
Vasu Dev7f349142009-03-27 09:06:31 -0700534 /* Cleanup the fc_lport */
535 fc_lport_destroy(lp);
536 fc_fcp_destroy(lp);
537
538 /* Detach from the scsi-ml */
539 fc_remove_host(lp->host);
540 scsi_remove_host(lp->host);
541
542 /* There are no more rports or I/O, free the EM */
Vasu Dev52ff8782009-07-29 17:05:10 -0700543 fc_exch_mgr_free(lp);
Vasu Dev7f349142009-03-27 09:06:31 -0700544
Vasu Dev7f349142009-03-27 09:06:31 -0700545 /* Free existing skbs */
546 fcoe_clean_pending_queue(lp);
547
Vasu Dev1047f222009-05-06 10:52:40 -0700548 /* Stop the timer */
549 del_timer_sync(&fc->timer);
550
Vasu Dev7f349142009-03-27 09:06:31 -0700551 /* Free memory used by statistical counters */
552 fc_lport_free_stats(lp);
553
554 /* Release the net_device and Scsi_Host */
555 dev_put(fc->real_dev);
556 scsi_host_put(lp->host);
557
558 return 0;
559}
560
561/*
562 * fcoe_ddp_setup - calls LLD's ddp_setup through net_device
563 * @lp: the corresponding fc_lport
564 * @xid: the exchange id for this ddp transfer
565 * @sgl: the scatterlist describing this transfer
566 * @sgc: number of sg items
567 *
568 * Returns : 0 no ddp
569 */
570static int fcoe_ddp_setup(struct fc_lport *lp, u16 xid,
571 struct scatterlist *sgl, unsigned int sgc)
572{
573 struct net_device *n = fcoe_netdev(lp);
574
575 if (n->netdev_ops && n->netdev_ops->ndo_fcoe_ddp_setup)
576 return n->netdev_ops->ndo_fcoe_ddp_setup(n, xid, sgl, sgc);
577
578 return 0;
579}
580
581/*
582 * fcoe_ddp_done - calls LLD's ddp_done through net_device
583 * @lp: the corresponding fc_lport
584 * @xid: the exchange id for this ddp transfer
585 *
586 * Returns : the length of data that have been completed by ddp
587 */
588static int fcoe_ddp_done(struct fc_lport *lp, u16 xid)
589{
590 struct net_device *n = fcoe_netdev(lp);
591
592 if (n->netdev_ops && n->netdev_ops->ndo_fcoe_ddp_done)
593 return n->netdev_ops->ndo_fcoe_ddp_done(n, xid);
594 return 0;
595}
596
597static struct libfc_function_template fcoe_libfc_fcn_templ = {
598 .frame_send = fcoe_xmit,
599 .ddp_setup = fcoe_ddp_setup,
600 .ddp_done = fcoe_ddp_done,
601};
602
603/**
604 * fcoe_if_create() - this function creates the fcoe interface
605 * @netdev: pointer the associated netdevice
606 *
607 * Creates fc_lport struct and scsi_host for lport, configures lport
608 * and starts fabric login.
609 *
610 * Returns : 0 on success
611 */
612static int fcoe_if_create(struct net_device *netdev)
613{
614 int rc;
615 struct fc_lport *lp = NULL;
616 struct fcoe_softc *fc;
617 struct Scsi_Host *shost;
618
619 BUG_ON(!netdev);
620
Robert Loved5488eb2009-06-10 15:30:59 -0700621 FCOE_NETDEV_DBG(netdev, "Create Interface\n");
Vasu Dev7f349142009-03-27 09:06:31 -0700622
623 lp = fcoe_hostlist_lookup(netdev);
624 if (lp)
625 return -EEXIST;
626
Vasu Deva0a25da2009-03-17 11:42:29 -0700627 shost = libfc_host_alloc(&fcoe_shost_template,
628 sizeof(struct fcoe_softc));
Vasu Dev7f349142009-03-27 09:06:31 -0700629 if (!shost) {
Robert Loved5488eb2009-06-10 15:30:59 -0700630 FCOE_NETDEV_DBG(netdev, "Could not allocate host structure\n");
Vasu Dev7f349142009-03-27 09:06:31 -0700631 return -ENOMEM;
632 }
633 lp = shost_priv(shost);
634 fc = lport_priv(lp);
635
636 /* configure fc_lport, e.g., em */
637 rc = fcoe_lport_config(lp);
638 if (rc) {
Robert Loved5488eb2009-06-10 15:30:59 -0700639 FCOE_NETDEV_DBG(netdev, "Could not configure lport for the "
640 "interface\n");
Vasu Dev7f349142009-03-27 09:06:31 -0700641 goto out_host_put;
642 }
643
Joe Eykholt97c83892009-03-17 11:42:40 -0700644 /*
645 * Initialize FIP.
646 */
647 fcoe_ctlr_init(&fc->ctlr);
648 fc->ctlr.send = fcoe_fip_send;
649 fc->ctlr.update_mac = fcoe_update_src_mac;
650
Vasu Devab6b85c2009-05-17 12:33:08 +0000651 /* configure lport network properties */
652 rc = fcoe_netdev_config(lp, netdev);
653 if (rc) {
Robert Loved5488eb2009-06-10 15:30:59 -0700654 FCOE_NETDEV_DBG(netdev, "Could not configure netdev for the "
655 "interface\n");
Vasu Devab6b85c2009-05-17 12:33:08 +0000656 goto out_netdev_cleanup;
657 }
Joe Eykholt97c83892009-03-17 11:42:40 -0700658
Vasu Dev7f349142009-03-27 09:06:31 -0700659 /* configure lport scsi host properties */
660 rc = fcoe_shost_config(lp, shost, &netdev->dev);
661 if (rc) {
Robert Loved5488eb2009-06-10 15:30:59 -0700662 FCOE_NETDEV_DBG(netdev, "Could not configure shost for the "
663 "interface\n");
Vasu Devab6b85c2009-05-17 12:33:08 +0000664 goto out_netdev_cleanup;
Vasu Dev7f349142009-03-27 09:06:31 -0700665 }
666
Vasu Dev7f349142009-03-27 09:06:31 -0700667 /* Initialize the library */
668 rc = fcoe_libfc_config(lp, &fcoe_libfc_fcn_templ);
669 if (rc) {
Robert Loved5488eb2009-06-10 15:30:59 -0700670 FCOE_NETDEV_DBG(netdev, "Could not configure libfc for the "
671 "interface\n");
Vasu Dev7f349142009-03-27 09:06:31 -0700672 goto out_lp_destroy;
673 }
674
Vasu Deve8af4d42009-07-29 17:05:15 -0700675 /*
676 * fcoe_em_alloc() and fcoe_hostlist_add() both
677 * need to be atomic under fcoe_hostlist_lock
678 * since fcoe_em_alloc() looks for an existing EM
679 * instance on host list updated by fcoe_hostlist_add().
680 */
681 write_lock(&fcoe_hostlist_lock);
Vasu Dev96316092009-07-29 17:05:00 -0700682 /* lport exch manager allocation */
683 rc = fcoe_em_config(lp);
684 if (rc) {
685 FCOE_NETDEV_DBG(netdev, "Could not configure the EM for the "
686 "interface\n");
687 goto out_lp_destroy;
688 }
689
Vasu Dev7f349142009-03-27 09:06:31 -0700690 /* add to lports list */
691 fcoe_hostlist_add(lp);
Vasu Deve8af4d42009-07-29 17:05:15 -0700692 write_unlock(&fcoe_hostlist_lock);
Vasu Dev7f349142009-03-27 09:06:31 -0700693
694 lp->boot_time = jiffies;
695
696 fc_fabric_login(lp);
697
Joe Eykholt97c83892009-03-17 11:42:40 -0700698 if (!fcoe_link_ok(lp))
699 fcoe_ctlr_link_up(&fc->ctlr);
700
Vasu Dev7f349142009-03-27 09:06:31 -0700701 dev_hold(netdev);
702
703 return rc;
704
705out_lp_destroy:
Vasu Dev52ff8782009-07-29 17:05:10 -0700706 fc_exch_mgr_free(lp);
Vasu Devab6b85c2009-05-17 12:33:08 +0000707out_netdev_cleanup:
708 fcoe_netdev_cleanup(fc);
Vasu Dev7f349142009-03-27 09:06:31 -0700709out_host_put:
710 scsi_host_put(lp->host);
711 return rc;
712}
713
714/**
715 * fcoe_if_init() - attach to scsi transport
716 *
717 * Returns : 0 on success
718 */
719static int __init fcoe_if_init(void)
720{
721 /* attach to scsi transport */
722 scsi_transport_fcoe_sw =
723 fc_attach_transport(&fcoe_transport_function);
724
725 if (!scsi_transport_fcoe_sw) {
Robert Loved5488eb2009-06-10 15:30:59 -0700726 printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n");
Vasu Dev7f349142009-03-27 09:06:31 -0700727 return -ENODEV;
728 }
729
730 return 0;
731}
732
733/**
734 * fcoe_if_exit() - detach from scsi transport
735 *
736 * Returns : 0 on success
737 */
738int __exit fcoe_if_exit(void)
739{
740 fc_release_transport(scsi_transport_fcoe_sw);
741 return 0;
742}
743
Robert Love85b4aa42008-12-09 15:10:24 -0800744/**
Robert Love8976f422009-03-17 11:41:46 -0700745 * fcoe_percpu_thread_create() - Create a receive thread for an online cpu
746 * @cpu: cpu index for the online cpu
747 */
748static void fcoe_percpu_thread_create(unsigned int cpu)
749{
750 struct fcoe_percpu_s *p;
751 struct task_struct *thread;
752
753 p = &per_cpu(fcoe_percpu, cpu);
754
755 thread = kthread_create(fcoe_percpu_receive_thread,
756 (void *)p, "fcoethread/%d", cpu);
757
758 if (likely(!IS_ERR(p->thread))) {
759 kthread_bind(thread, cpu);
760 wake_up_process(thread);
761
762 spin_lock_bh(&p->fcoe_rx_list.lock);
763 p->thread = thread;
764 spin_unlock_bh(&p->fcoe_rx_list.lock);
765 }
766}
767
768/**
769 * fcoe_percpu_thread_destroy() - removes the rx thread for the given cpu
770 * @cpu: cpu index the rx thread is to be removed
771 *
772 * Destroys a per-CPU Rx thread. Any pending skbs are moved to the
773 * current CPU's Rx thread. If the thread being destroyed is bound to
774 * the CPU processing this context the skbs will be freed.
775 */
776static void fcoe_percpu_thread_destroy(unsigned int cpu)
777{
778 struct fcoe_percpu_s *p;
779 struct task_struct *thread;
780 struct page *crc_eof;
781 struct sk_buff *skb;
782#ifdef CONFIG_SMP
783 struct fcoe_percpu_s *p0;
784 unsigned targ_cpu = smp_processor_id();
785#endif /* CONFIG_SMP */
786
Robert Loved5488eb2009-06-10 15:30:59 -0700787 FCOE_DBG("Destroying receive thread for CPU %d\n", cpu);
Robert Love8976f422009-03-17 11:41:46 -0700788
789 /* Prevent any new skbs from being queued for this CPU. */
790 p = &per_cpu(fcoe_percpu, cpu);
791 spin_lock_bh(&p->fcoe_rx_list.lock);
792 thread = p->thread;
793 p->thread = NULL;
794 crc_eof = p->crc_eof_page;
795 p->crc_eof_page = NULL;
796 p->crc_eof_offset = 0;
797 spin_unlock_bh(&p->fcoe_rx_list.lock);
798
799#ifdef CONFIG_SMP
800 /*
801 * Don't bother moving the skb's if this context is running
802 * on the same CPU that is having its thread destroyed. This
803 * can easily happen when the module is removed.
804 */
805 if (cpu != targ_cpu) {
806 p0 = &per_cpu(fcoe_percpu, targ_cpu);
807 spin_lock_bh(&p0->fcoe_rx_list.lock);
808 if (p0->thread) {
Robert Loved5488eb2009-06-10 15:30:59 -0700809 FCOE_DBG("Moving frames from CPU %d to CPU %d\n",
810 cpu, targ_cpu);
Robert Love8976f422009-03-17 11:41:46 -0700811
812 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
813 __skb_queue_tail(&p0->fcoe_rx_list, skb);
814 spin_unlock_bh(&p0->fcoe_rx_list.lock);
815 } else {
816 /*
817 * The targeted CPU is not initialized and cannot accept
818 * new skbs. Unlock the targeted CPU and drop the skbs
819 * on the CPU that is going offline.
820 */
821 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
822 kfree_skb(skb);
823 spin_unlock_bh(&p0->fcoe_rx_list.lock);
824 }
825 } else {
826 /*
827 * This scenario occurs when the module is being removed
828 * and all threads are being destroyed. skbs will continue
829 * to be shifted from the CPU thread that is being removed
830 * to the CPU thread associated with the CPU that is processing
831 * the module removal. Once there is only one CPU Rx thread it
832 * will reach this case and we will drop all skbs and later
833 * stop the thread.
834 */
835 spin_lock_bh(&p->fcoe_rx_list.lock);
836 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
837 kfree_skb(skb);
838 spin_unlock_bh(&p->fcoe_rx_list.lock);
839 }
840#else
841 /*
Chris Leechdd3fd722009-04-21 16:27:36 -0700842 * This a non-SMP scenario where the singular Rx thread is
Robert Love8976f422009-03-17 11:41:46 -0700843 * being removed. Free all skbs and stop the thread.
844 */
845 spin_lock_bh(&p->fcoe_rx_list.lock);
846 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
847 kfree_skb(skb);
848 spin_unlock_bh(&p->fcoe_rx_list.lock);
849#endif
850
851 if (thread)
852 kthread_stop(thread);
853
854 if (crc_eof)
855 put_page(crc_eof);
856}
857
858/**
859 * fcoe_cpu_callback() - fcoe cpu hotplug event callback
860 * @nfb: callback data block
861 * @action: event triggering the callback
862 * @hcpu: index for the cpu of this event
863 *
864 * This creates or destroys per cpu data for fcoe
865 *
866 * Returns NOTIFY_OK always.
867 */
868static int fcoe_cpu_callback(struct notifier_block *nfb,
869 unsigned long action, void *hcpu)
870{
871 unsigned cpu = (unsigned long)hcpu;
872
873 switch (action) {
874 case CPU_ONLINE:
875 case CPU_ONLINE_FROZEN:
Robert Loved5488eb2009-06-10 15:30:59 -0700876 FCOE_DBG("CPU %x online: Create Rx thread\n", cpu);
Robert Love8976f422009-03-17 11:41:46 -0700877 fcoe_percpu_thread_create(cpu);
878 break;
879 case CPU_DEAD:
880 case CPU_DEAD_FROZEN:
Robert Loved5488eb2009-06-10 15:30:59 -0700881 FCOE_DBG("CPU %x offline: Remove Rx thread\n", cpu);
Robert Love8976f422009-03-17 11:41:46 -0700882 fcoe_percpu_thread_destroy(cpu);
883 break;
884 default:
885 break;
886 }
887 return NOTIFY_OK;
888}
889
890static struct notifier_block fcoe_cpu_notifier = {
891 .notifier_call = fcoe_cpu_callback,
892};
893
894/**
Robert Love34f42a02009-02-27 10:55:45 -0800895 * fcoe_rcv() - this is the fcoe receive function called by NET_RX_SOFTIRQ
Robert Love85b4aa42008-12-09 15:10:24 -0800896 * @skb: the receive skb
897 * @dev: associated net device
898 * @ptype: context
Chris Leechdd3fd722009-04-21 16:27:36 -0700899 * @olddev: last device
Robert Love85b4aa42008-12-09 15:10:24 -0800900 *
901 * this function will receive the packet and build fc frame and pass it up
902 *
903 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -0800904 */
Robert Love85b4aa42008-12-09 15:10:24 -0800905int fcoe_rcv(struct sk_buff *skb, struct net_device *dev,
906 struct packet_type *ptype, struct net_device *olddev)
907{
908 struct fc_lport *lp;
909 struct fcoe_rcv_info *fr;
910 struct fcoe_softc *fc;
Robert Love85b4aa42008-12-09 15:10:24 -0800911 struct fc_frame_header *fh;
Robert Love85b4aa42008-12-09 15:10:24 -0800912 struct fcoe_percpu_s *fps;
Robert Love38eccab2009-03-17 11:41:30 -0700913 unsigned short oxid;
Robert Love8976f422009-03-17 11:41:46 -0700914 unsigned int cpu = 0;
Robert Love85b4aa42008-12-09 15:10:24 -0800915
916 fc = container_of(ptype, struct fcoe_softc, fcoe_packet_type);
Joe Eykholt97c83892009-03-17 11:42:40 -0700917 lp = fc->ctlr.lp;
Robert Love85b4aa42008-12-09 15:10:24 -0800918 if (unlikely(lp == NULL)) {
Robert Loved5488eb2009-06-10 15:30:59 -0700919 FCOE_NETDEV_DBG(dev, "Cannot find hba structure");
Robert Love85b4aa42008-12-09 15:10:24 -0800920 goto err2;
921 }
Joe Eykholt97c83892009-03-17 11:42:40 -0700922 if (!lp->link_up)
923 goto err2;
Robert Love85b4aa42008-12-09 15:10:24 -0800924
Robert Loved5488eb2009-06-10 15:30:59 -0700925 FCOE_NETDEV_DBG(dev, "skb_info: len:%d data_len:%d head:%p "
926 "data:%p tail:%p end:%p sum:%d dev:%s",
927 skb->len, skb->data_len, skb->head, skb->data,
928 skb_tail_pointer(skb), skb_end_pointer(skb),
929 skb->csum, skb->dev ? skb->dev->name : "<NULL>");
Robert Love85b4aa42008-12-09 15:10:24 -0800930
931 /* check for FCOE packet type */
932 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
Robert Loved5488eb2009-06-10 15:30:59 -0700933 FCOE_NETDEV_DBG(dev, "Wrong FC type frame");
Robert Love85b4aa42008-12-09 15:10:24 -0800934 goto err;
935 }
936
937 /*
938 * Check for minimum frame length, and make sure required FCoE
939 * and FC headers are pulled into the linear data area.
940 */
941 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
942 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
943 goto err;
944
945 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
946 fh = (struct fc_frame_header *) skb_transport_header(skb);
947
948 oxid = ntohs(fh->fh_ox_id);
949
950 fr = fcoe_dev_from_skb(skb);
951 fr->fr_dev = lp;
952 fr->ptype = ptype;
Robert Love5e5e92d2009-03-17 11:41:35 -0700953
Robert Love85b4aa42008-12-09 15:10:24 -0800954#ifdef CONFIG_SMP
955 /*
956 * The incoming frame exchange id(oxid) is ANDed with num of online
Robert Love8976f422009-03-17 11:41:46 -0700957 * cpu bits to get cpu and then this cpu is used for selecting
958 * a per cpu kernel thread from fcoe_percpu.
Robert Love85b4aa42008-12-09 15:10:24 -0800959 */
Robert Love8976f422009-03-17 11:41:46 -0700960 cpu = oxid & (num_online_cpus() - 1);
Robert Love85b4aa42008-12-09 15:10:24 -0800961#endif
Robert Love5e5e92d2009-03-17 11:41:35 -0700962
Robert Love8976f422009-03-17 11:41:46 -0700963 fps = &per_cpu(fcoe_percpu, cpu);
Robert Love85b4aa42008-12-09 15:10:24 -0800964 spin_lock_bh(&fps->fcoe_rx_list.lock);
Robert Love8976f422009-03-17 11:41:46 -0700965 if (unlikely(!fps->thread)) {
966 /*
967 * The targeted CPU is not ready, let's target
968 * the first CPU now. For non-SMP systems this
969 * will check the same CPU twice.
970 */
Robert Loved5488eb2009-06-10 15:30:59 -0700971 FCOE_NETDEV_DBG(dev, "CPU is online, but no receive thread "
972 "ready for incoming skb- using first online "
973 "CPU.\n");
Robert Love8976f422009-03-17 11:41:46 -0700974
975 spin_unlock_bh(&fps->fcoe_rx_list.lock);
976 cpu = first_cpu(cpu_online_map);
977 fps = &per_cpu(fcoe_percpu, cpu);
978 spin_lock_bh(&fps->fcoe_rx_list.lock);
979 if (!fps->thread) {
980 spin_unlock_bh(&fps->fcoe_rx_list.lock);
981 goto err;
982 }
983 }
984
985 /*
986 * We now have a valid CPU that we're targeting for
987 * this skb. We also have this receive thread locked,
988 * so we're free to queue skbs into it's queue.
989 */
Robert Love85b4aa42008-12-09 15:10:24 -0800990 __skb_queue_tail(&fps->fcoe_rx_list, skb);
991 if (fps->fcoe_rx_list.qlen == 1)
992 wake_up_process(fps->thread);
993
994 spin_unlock_bh(&fps->fcoe_rx_list.lock);
995
996 return 0;
997err:
Robert Love582b45b2009-03-31 15:51:50 -0700998 fc_lport_get_stats(lp)->ErrorFrames++;
Robert Love85b4aa42008-12-09 15:10:24 -0800999
1000err2:
1001 kfree_skb(skb);
1002 return -1;
1003}
Robert Love85b4aa42008-12-09 15:10:24 -08001004
1005/**
Robert Love34f42a02009-02-27 10:55:45 -08001006 * fcoe_start_io() - pass to netdev to start xmit for fcoe
Robert Love85b4aa42008-12-09 15:10:24 -08001007 * @skb: the skb to be xmitted
1008 *
1009 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001010 */
Robert Love85b4aa42008-12-09 15:10:24 -08001011static inline int fcoe_start_io(struct sk_buff *skb)
1012{
1013 int rc;
1014
1015 skb_get(skb);
1016 rc = dev_queue_xmit(skb);
1017 if (rc != 0)
1018 return rc;
1019 kfree_skb(skb);
1020 return 0;
1021}
1022
1023/**
Chris Leechdd3fd722009-04-21 16:27:36 -07001024 * fcoe_get_paged_crc_eof() - in case we need to alloc a page for crc_eof
Robert Love85b4aa42008-12-09 15:10:24 -08001025 * @skb: the skb to be xmitted
1026 * @tlen: total len
1027 *
1028 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001029 */
Robert Love85b4aa42008-12-09 15:10:24 -08001030static int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen)
1031{
1032 struct fcoe_percpu_s *fps;
1033 struct page *page;
Robert Love85b4aa42008-12-09 15:10:24 -08001034
Robert Love5e5e92d2009-03-17 11:41:35 -07001035 fps = &get_cpu_var(fcoe_percpu);
Robert Love85b4aa42008-12-09 15:10:24 -08001036 page = fps->crc_eof_page;
1037 if (!page) {
1038 page = alloc_page(GFP_ATOMIC);
1039 if (!page) {
Robert Love5e5e92d2009-03-17 11:41:35 -07001040 put_cpu_var(fcoe_percpu);
Robert Love85b4aa42008-12-09 15:10:24 -08001041 return -ENOMEM;
1042 }
1043 fps->crc_eof_page = page;
Robert Love8976f422009-03-17 11:41:46 -07001044 fps->crc_eof_offset = 0;
Robert Love85b4aa42008-12-09 15:10:24 -08001045 }
1046
1047 get_page(page);
1048 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page,
1049 fps->crc_eof_offset, tlen);
1050 skb->len += tlen;
1051 skb->data_len += tlen;
1052 skb->truesize += tlen;
1053 fps->crc_eof_offset += sizeof(struct fcoe_crc_eof);
1054
1055 if (fps->crc_eof_offset >= PAGE_SIZE) {
1056 fps->crc_eof_page = NULL;
1057 fps->crc_eof_offset = 0;
1058 put_page(page);
1059 }
Robert Love5e5e92d2009-03-17 11:41:35 -07001060 put_cpu_var(fcoe_percpu);
Robert Love85b4aa42008-12-09 15:10:24 -08001061 return 0;
1062}
1063
1064/**
Robert Love34f42a02009-02-27 10:55:45 -08001065 * fcoe_fc_crc() - calculates FC CRC in this fcoe skb
Chris Leechdd3fd722009-04-21 16:27:36 -07001066 * @fp: the fc_frame containing data to be checksummed
Robert Love85b4aa42008-12-09 15:10:24 -08001067 *
1068 * This uses crc32() to calculate the crc for fc frame
1069 * Return : 32 bit crc
Robert Love34f42a02009-02-27 10:55:45 -08001070 */
Robert Love85b4aa42008-12-09 15:10:24 -08001071u32 fcoe_fc_crc(struct fc_frame *fp)
1072{
1073 struct sk_buff *skb = fp_skb(fp);
1074 struct skb_frag_struct *frag;
1075 unsigned char *data;
1076 unsigned long off, len, clen;
1077 u32 crc;
1078 unsigned i;
1079
1080 crc = crc32(~0, skb->data, skb_headlen(skb));
1081
1082 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1083 frag = &skb_shinfo(skb)->frags[i];
1084 off = frag->page_offset;
1085 len = frag->size;
1086 while (len > 0) {
1087 clen = min(len, PAGE_SIZE - (off & ~PAGE_MASK));
1088 data = kmap_atomic(frag->page + (off >> PAGE_SHIFT),
1089 KM_SKB_DATA_SOFTIRQ);
1090 crc = crc32(crc, data + (off & ~PAGE_MASK), clen);
1091 kunmap_atomic(data, KM_SKB_DATA_SOFTIRQ);
1092 off += clen;
1093 len -= clen;
1094 }
1095 }
1096 return crc;
1097}
Robert Love85b4aa42008-12-09 15:10:24 -08001098
1099/**
Robert Love34f42a02009-02-27 10:55:45 -08001100 * fcoe_xmit() - FCoE frame transmit function
Robert Love85b4aa42008-12-09 15:10:24 -08001101 * @lp: the associated local port
1102 * @fp: the fc_frame to be transmitted
1103 *
1104 * Return : 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001105 */
Robert Love85b4aa42008-12-09 15:10:24 -08001106int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp)
1107{
Vasu Dev4bb6b512009-05-06 10:52:34 -07001108 int wlen;
Robert Love85b4aa42008-12-09 15:10:24 -08001109 u32 crc;
1110 struct ethhdr *eh;
1111 struct fcoe_crc_eof *cp;
1112 struct sk_buff *skb;
1113 struct fcoe_dev_stats *stats;
1114 struct fc_frame_header *fh;
1115 unsigned int hlen; /* header length implies the version */
1116 unsigned int tlen; /* trailer length */
1117 unsigned int elen; /* eth header, may include vlan */
Robert Love85b4aa42008-12-09 15:10:24 -08001118 struct fcoe_softc *fc;
1119 u8 sof, eof;
1120 struct fcoe_hdr *hp;
1121
1122 WARN_ON((fr_len(fp) % sizeof(u32)) != 0);
1123
Robert Lovefc47ff62009-02-27 10:55:55 -08001124 fc = lport_priv(lp);
Robert Love85b4aa42008-12-09 15:10:24 -08001125 fh = fc_frame_header_get(fp);
Joe Eykholt97c83892009-03-17 11:42:40 -07001126 skb = fp_skb(fp);
1127 wlen = skb->len / FCOE_WORD_TO_BYTE;
1128
1129 if (!lp->link_up) {
Dan Carpenter3caf02e2009-04-21 16:27:25 -07001130 kfree_skb(skb);
Joe Eykholt97c83892009-03-17 11:42:40 -07001131 return 0;
Robert Love85b4aa42008-12-09 15:10:24 -08001132 }
1133
Joe Eykholt97c83892009-03-17 11:42:40 -07001134 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ) &&
1135 fcoe_ctlr_els_send(&fc->ctlr, skb))
1136 return 0;
1137
Robert Love85b4aa42008-12-09 15:10:24 -08001138 sof = fr_sof(fp);
1139 eof = fr_eof(fp);
1140
Vasu Dev4e57e1c2009-05-06 10:52:46 -07001141 elen = sizeof(struct ethhdr);
Robert Love85b4aa42008-12-09 15:10:24 -08001142 hlen = sizeof(struct fcoe_hdr);
1143 tlen = sizeof(struct fcoe_crc_eof);
1144 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
1145
1146 /* crc offload */
1147 if (likely(lp->crc_offload)) {
Yi Zou39ca9a02009-02-27 14:07:15 -08001148 skb->ip_summed = CHECKSUM_PARTIAL;
Robert Love85b4aa42008-12-09 15:10:24 -08001149 skb->csum_start = skb_headroom(skb);
1150 skb->csum_offset = skb->len;
1151 crc = 0;
1152 } else {
1153 skb->ip_summed = CHECKSUM_NONE;
1154 crc = fcoe_fc_crc(fp);
1155 }
1156
1157 /* copy fc crc and eof to the skb buff */
1158 if (skb_is_nonlinear(skb)) {
1159 skb_frag_t *frag;
1160 if (fcoe_get_paged_crc_eof(skb, tlen)) {
Roel Kluine9041582009-02-27 10:56:22 -08001161 kfree_skb(skb);
Robert Love85b4aa42008-12-09 15:10:24 -08001162 return -ENOMEM;
1163 }
1164 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
1165 cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ)
1166 + frag->page_offset;
1167 } else {
1168 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
1169 }
1170
1171 memset(cp, 0, sizeof(*cp));
1172 cp->fcoe_eof = eof;
1173 cp->fcoe_crc32 = cpu_to_le32(~crc);
1174
1175 if (skb_is_nonlinear(skb)) {
1176 kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ);
1177 cp = NULL;
1178 }
1179
Chris Leechdd3fd722009-04-21 16:27:36 -07001180 /* adjust skb network/transport offsets to match mac/fcoe/fc */
Robert Love85b4aa42008-12-09 15:10:24 -08001181 skb_push(skb, elen + hlen);
1182 skb_reset_mac_header(skb);
1183 skb_reset_network_header(skb);
1184 skb->mac_len = elen;
Yi Zou211c7382009-02-27 14:06:37 -08001185 skb->protocol = htons(ETH_P_FCOE);
Robert Love85b4aa42008-12-09 15:10:24 -08001186 skb->dev = fc->real_dev;
1187
1188 /* fill up mac and fcoe headers */
1189 eh = eth_hdr(skb);
1190 eh->h_proto = htons(ETH_P_FCOE);
Joe Eykholt97c83892009-03-17 11:42:40 -07001191 if (fc->ctlr.map_dest)
Robert Love85b4aa42008-12-09 15:10:24 -08001192 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
1193 else
1194 /* insert GW address */
Joe Eykholt97c83892009-03-17 11:42:40 -07001195 memcpy(eh->h_dest, fc->ctlr.dest_addr, ETH_ALEN);
Robert Love85b4aa42008-12-09 15:10:24 -08001196
Joe Eykholt97c83892009-03-17 11:42:40 -07001197 if (unlikely(fc->ctlr.flogi_oxid != FC_XID_UNKNOWN))
1198 memcpy(eh->h_source, fc->ctlr.ctl_src_addr, ETH_ALEN);
Robert Love85b4aa42008-12-09 15:10:24 -08001199 else
Joe Eykholt97c83892009-03-17 11:42:40 -07001200 memcpy(eh->h_source, fc->ctlr.data_src_addr, ETH_ALEN);
Robert Love85b4aa42008-12-09 15:10:24 -08001201
1202 hp = (struct fcoe_hdr *)(eh + 1);
1203 memset(hp, 0, sizeof(*hp));
1204 if (FC_FCOE_VER)
1205 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
1206 hp->fcoe_sof = sof;
1207
Yi Zou39ca9a02009-02-27 14:07:15 -08001208#ifdef NETIF_F_FSO
1209 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
1210 if (lp->seq_offload && fr_max_payload(fp)) {
1211 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
1212 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
1213 } else {
1214 skb_shinfo(skb)->gso_type = 0;
1215 skb_shinfo(skb)->gso_size = 0;
1216 }
1217#endif
Robert Love85b4aa42008-12-09 15:10:24 -08001218 /* update tx stats: regardless if LLD fails */
Robert Love582b45b2009-03-31 15:51:50 -07001219 stats = fc_lport_get_stats(lp);
1220 stats->TxFrames++;
1221 stats->TxWords += wlen;
Robert Love85b4aa42008-12-09 15:10:24 -08001222
1223 /* send down to lld */
1224 fr_dev(fp) = lp;
1225 if (fc->fcoe_pending_queue.qlen)
Vasu Dev4bb6b512009-05-06 10:52:34 -07001226 fcoe_check_wait_queue(lp, skb);
1227 else if (fcoe_start_io(skb))
1228 fcoe_check_wait_queue(lp, skb);
Robert Love85b4aa42008-12-09 15:10:24 -08001229
1230 return 0;
1231}
Robert Love85b4aa42008-12-09 15:10:24 -08001232
Robert Love34f42a02009-02-27 10:55:45 -08001233/**
1234 * fcoe_percpu_receive_thread() - recv thread per cpu
Robert Love85b4aa42008-12-09 15:10:24 -08001235 * @arg: ptr to the fcoe per cpu struct
1236 *
1237 * Return: 0 for success
Robert Love85b4aa42008-12-09 15:10:24 -08001238 */
1239int fcoe_percpu_receive_thread(void *arg)
1240{
1241 struct fcoe_percpu_s *p = arg;
1242 u32 fr_len;
1243 struct fc_lport *lp;
1244 struct fcoe_rcv_info *fr;
1245 struct fcoe_dev_stats *stats;
1246 struct fc_frame_header *fh;
1247 struct sk_buff *skb;
1248 struct fcoe_crc_eof crc_eof;
1249 struct fc_frame *fp;
1250 u8 *mac = NULL;
1251 struct fcoe_softc *fc;
1252 struct fcoe_hdr *hp;
1253
Robert Love4469c192009-02-27 10:56:38 -08001254 set_user_nice(current, -20);
Robert Love85b4aa42008-12-09 15:10:24 -08001255
1256 while (!kthread_should_stop()) {
1257
1258 spin_lock_bh(&p->fcoe_rx_list.lock);
1259 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) == NULL) {
1260 set_current_state(TASK_INTERRUPTIBLE);
1261 spin_unlock_bh(&p->fcoe_rx_list.lock);
1262 schedule();
1263 set_current_state(TASK_RUNNING);
1264 if (kthread_should_stop())
1265 return 0;
1266 spin_lock_bh(&p->fcoe_rx_list.lock);
1267 }
1268 spin_unlock_bh(&p->fcoe_rx_list.lock);
1269 fr = fcoe_dev_from_skb(skb);
1270 lp = fr->fr_dev;
1271 if (unlikely(lp == NULL)) {
Robert Loved5488eb2009-06-10 15:30:59 -07001272 FCOE_NETDEV_DBG(skb->dev, "Invalid HBA Structure");
Robert Love85b4aa42008-12-09 15:10:24 -08001273 kfree_skb(skb);
1274 continue;
1275 }
1276
Robert Loved5488eb2009-06-10 15:30:59 -07001277 FCOE_NETDEV_DBG(skb->dev, "skb_info: len:%d data_len:%d "
1278 "head:%p data:%p tail:%p end:%p sum:%d dev:%s",
1279 skb->len, skb->data_len,
1280 skb->head, skb->data, skb_tail_pointer(skb),
1281 skb_end_pointer(skb), skb->csum,
1282 skb->dev ? skb->dev->name : "<NULL>");
Robert Love85b4aa42008-12-09 15:10:24 -08001283
1284 /*
1285 * Save source MAC address before discarding header.
1286 */
1287 fc = lport_priv(lp);
Robert Love85b4aa42008-12-09 15:10:24 -08001288 if (skb_is_nonlinear(skb))
1289 skb_linearize(skb); /* not ideal */
Joe Eykholt97c83892009-03-17 11:42:40 -07001290 mac = eth_hdr(skb)->h_source;
Robert Love85b4aa42008-12-09 15:10:24 -08001291
1292 /*
1293 * Frame length checks and setting up the header pointers
1294 * was done in fcoe_rcv already.
1295 */
1296 hp = (struct fcoe_hdr *) skb_network_header(skb);
1297 fh = (struct fc_frame_header *) skb_transport_header(skb);
1298
Robert Love582b45b2009-03-31 15:51:50 -07001299 stats = fc_lport_get_stats(lp);
Robert Love85b4aa42008-12-09 15:10:24 -08001300 if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) {
Robert Love582b45b2009-03-31 15:51:50 -07001301 if (stats->ErrorFrames < 5)
Robert Loved5488eb2009-06-10 15:30:59 -07001302 printk(KERN_WARNING "fcoe: FCoE version "
Robert Love582b45b2009-03-31 15:51:50 -07001303 "mismatch: The frame has "
1304 "version %x, but the "
1305 "initiator supports version "
1306 "%x\n", FC_FCOE_DECAPS_VER(hp),
1307 FC_FCOE_VER);
1308 stats->ErrorFrames++;
Robert Love85b4aa42008-12-09 15:10:24 -08001309 kfree_skb(skb);
1310 continue;
1311 }
1312
1313 skb_pull(skb, sizeof(struct fcoe_hdr));
1314 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
1315
Robert Love582b45b2009-03-31 15:51:50 -07001316 stats->RxFrames++;
1317 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
Robert Love85b4aa42008-12-09 15:10:24 -08001318
1319 fp = (struct fc_frame *)skb;
1320 fc_frame_init(fp);
1321 fr_dev(fp) = lp;
1322 fr_sof(fp) = hp->fcoe_sof;
1323
1324 /* Copy out the CRC and EOF trailer for access */
1325 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
1326 kfree_skb(skb);
1327 continue;
1328 }
1329 fr_eof(fp) = crc_eof.fcoe_eof;
1330 fr_crc(fp) = crc_eof.fcoe_crc32;
1331 if (pskb_trim(skb, fr_len)) {
1332 kfree_skb(skb);
1333 continue;
1334 }
1335
1336 /*
1337 * We only check CRC if no offload is available and if it is
1338 * it's solicited data, in which case, the FCP layer would
1339 * check it during the copy.
1340 */
Yi Zou07c00ec2009-02-27 14:07:31 -08001341 if (lp->crc_offload && skb->ip_summed == CHECKSUM_UNNECESSARY)
Robert Love85b4aa42008-12-09 15:10:24 -08001342 fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
1343 else
1344 fr_flags(fp) |= FCPHF_CRC_UNCHECKED;
1345
1346 fh = fc_frame_header_get(fp);
1347 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
1348 fh->fh_type == FC_TYPE_FCP) {
Vasu Dev52ff8782009-07-29 17:05:10 -07001349 fc_exch_recv(lp, fp);
Robert Love85b4aa42008-12-09 15:10:24 -08001350 continue;
1351 }
1352 if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) {
1353 if (le32_to_cpu(fr_crc(fp)) !=
1354 ~crc32(~0, skb->data, fr_len)) {
Robert Loved5488eb2009-06-10 15:30:59 -07001355 if (stats->InvalidCRCCount < 5)
Robert Love85b4aa42008-12-09 15:10:24 -08001356 printk(KERN_WARNING "fcoe: dropping "
1357 "frame with CRC error\n");
1358 stats->InvalidCRCCount++;
1359 stats->ErrorFrames++;
1360 fc_frame_free(fp);
1361 continue;
1362 }
1363 fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
1364 }
Joe Eykholt97c83892009-03-17 11:42:40 -07001365 if (unlikely(fc->ctlr.flogi_oxid != FC_XID_UNKNOWN) &&
1366 fcoe_ctlr_recv_flogi(&fc->ctlr, fp, mac)) {
1367 fc_frame_free(fp);
1368 continue;
1369 }
Vasu Dev52ff8782009-07-29 17:05:10 -07001370 fc_exch_recv(lp, fp);
Robert Love85b4aa42008-12-09 15:10:24 -08001371 }
1372 return 0;
1373}
1374
1375/**
Chris Leechdd3fd722009-04-21 16:27:36 -07001376 * fcoe_check_wait_queue() - attempt to clear the transmit backlog
1377 * @lp: the fc_lport
Robert Love85b4aa42008-12-09 15:10:24 -08001378 *
1379 * This empties the wait_queue, dequeue the head of the wait_queue queue
1380 * and calls fcoe_start_io() for each packet, if all skb have been
Vasu Devc826a312009-02-27 10:56:27 -08001381 * transmitted, return qlen or -1 if a error occurs, then restore
Chris Leechdd3fd722009-04-21 16:27:36 -07001382 * wait_queue and try again later.
Robert Love85b4aa42008-12-09 15:10:24 -08001383 *
1384 * The wait_queue is used when the skb transmit fails. skb will go
Chris Leechdd3fd722009-04-21 16:27:36 -07001385 * in the wait_queue which will be emptied by the timer function or
Robert Love85b4aa42008-12-09 15:10:24 -08001386 * by the next skb transmit.
Robert Love34f42a02009-02-27 10:55:45 -08001387 */
Vasu Dev4bb6b512009-05-06 10:52:34 -07001388static void fcoe_check_wait_queue(struct fc_lport *lp, struct sk_buff *skb)
Robert Love85b4aa42008-12-09 15:10:24 -08001389{
Chris Leech55c8baf2009-02-27 10:56:32 -08001390 struct fcoe_softc *fc = lport_priv(lp);
Vasu Dev4bb6b512009-05-06 10:52:34 -07001391 int rc;
Robert Love85b4aa42008-12-09 15:10:24 -08001392
Robert Love85b4aa42008-12-09 15:10:24 -08001393 spin_lock_bh(&fc->fcoe_pending_queue.lock);
Vasu Dev4bb6b512009-05-06 10:52:34 -07001394
1395 if (skb)
1396 __skb_queue_tail(&fc->fcoe_pending_queue, skb);
1397
Vasu Devc826a312009-02-27 10:56:27 -08001398 if (fc->fcoe_pending_queue_active)
1399 goto out;
1400 fc->fcoe_pending_queue_active = 1;
Chris Leech55c8baf2009-02-27 10:56:32 -08001401
1402 while (fc->fcoe_pending_queue.qlen) {
1403 /* keep qlen > 0 until fcoe_start_io succeeds */
1404 fc->fcoe_pending_queue.qlen++;
1405 skb = __skb_dequeue(&fc->fcoe_pending_queue);
1406
1407 spin_unlock_bh(&fc->fcoe_pending_queue.lock);
1408 rc = fcoe_start_io(skb);
1409 spin_lock_bh(&fc->fcoe_pending_queue.lock);
1410
1411 if (rc) {
1412 __skb_queue_head(&fc->fcoe_pending_queue, skb);
1413 /* undo temporary increment above */
1414 fc->fcoe_pending_queue.qlen--;
1415 break;
Robert Love85b4aa42008-12-09 15:10:24 -08001416 }
Chris Leech55c8baf2009-02-27 10:56:32 -08001417 /* undo temporary increment above */
1418 fc->fcoe_pending_queue.qlen--;
Robert Love85b4aa42008-12-09 15:10:24 -08001419 }
Chris Leech55c8baf2009-02-27 10:56:32 -08001420
1421 if (fc->fcoe_pending_queue.qlen < FCOE_LOW_QUEUE_DEPTH)
1422 lp->qfull = 0;
Vasu Dev1047f222009-05-06 10:52:40 -07001423 if (fc->fcoe_pending_queue.qlen && !timer_pending(&fc->timer))
1424 mod_timer(&fc->timer, jiffies + 2);
Vasu Devc826a312009-02-27 10:56:27 -08001425 fc->fcoe_pending_queue_active = 0;
Vasu Devc826a312009-02-27 10:56:27 -08001426out:
Vasu Dev4bb6b512009-05-06 10:52:34 -07001427 if (fc->fcoe_pending_queue.qlen > FCOE_MAX_QUEUE_DEPTH)
1428 lp->qfull = 1;
Robert Love85b4aa42008-12-09 15:10:24 -08001429 spin_unlock_bh(&fc->fcoe_pending_queue.lock);
Vasu Dev4bb6b512009-05-06 10:52:34 -07001430 return;
Robert Love85b4aa42008-12-09 15:10:24 -08001431}
1432
1433/**
Robert Love34f42a02009-02-27 10:55:45 -08001434 * fcoe_dev_setup() - setup link change notification interface
1435 */
Randy Dunlapb0d428a2009-04-27 21:49:31 -07001436static void fcoe_dev_setup(void)
Robert Love85b4aa42008-12-09 15:10:24 -08001437{
Robert Love85b4aa42008-12-09 15:10:24 -08001438 register_netdevice_notifier(&fcoe_notifier);
1439}
1440
1441/**
Randy Dunlapb0d428a2009-04-27 21:49:31 -07001442 * fcoe_dev_cleanup() - cleanup link change notification interface
Robert Love34f42a02009-02-27 10:55:45 -08001443 */
Robert Love85b4aa42008-12-09 15:10:24 -08001444static void fcoe_dev_cleanup(void)
1445{
1446 unregister_netdevice_notifier(&fcoe_notifier);
1447}
1448
1449/**
Robert Love34f42a02009-02-27 10:55:45 -08001450 * fcoe_device_notification() - netdev event notification callback
Robert Love85b4aa42008-12-09 15:10:24 -08001451 * @notifier: context of the notification
1452 * @event: type of event
1453 * @ptr: fixed array for output parsed ifname
1454 *
1455 * This function is called by the ethernet driver in case of link change event
1456 *
1457 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001458 */
Robert Love85b4aa42008-12-09 15:10:24 -08001459static int fcoe_device_notification(struct notifier_block *notifier,
1460 ulong event, void *ptr)
1461{
1462 struct fc_lport *lp = NULL;
1463 struct net_device *real_dev = ptr;
1464 struct fcoe_softc *fc;
1465 struct fcoe_dev_stats *stats;
Joe Eykholt97c83892009-03-17 11:42:40 -07001466 u32 link_possible = 1;
Robert Love85b4aa42008-12-09 15:10:24 -08001467 u32 mfs;
1468 int rc = NOTIFY_OK;
1469
1470 read_lock(&fcoe_hostlist_lock);
1471 list_for_each_entry(fc, &fcoe_hostlist, list) {
1472 if (fc->real_dev == real_dev) {
Joe Eykholt97c83892009-03-17 11:42:40 -07001473 lp = fc->ctlr.lp;
Robert Love85b4aa42008-12-09 15:10:24 -08001474 break;
1475 }
1476 }
1477 read_unlock(&fcoe_hostlist_lock);
1478 if (lp == NULL) {
1479 rc = NOTIFY_DONE;
1480 goto out;
1481 }
1482
Robert Love85b4aa42008-12-09 15:10:24 -08001483 switch (event) {
1484 case NETDEV_DOWN:
1485 case NETDEV_GOING_DOWN:
Joe Eykholt97c83892009-03-17 11:42:40 -07001486 link_possible = 0;
Robert Love85b4aa42008-12-09 15:10:24 -08001487 break;
1488 case NETDEV_UP:
1489 case NETDEV_CHANGE:
Robert Love85b4aa42008-12-09 15:10:24 -08001490 break;
1491 case NETDEV_CHANGEMTU:
1492 mfs = fc->real_dev->mtu -
1493 (sizeof(struct fcoe_hdr) +
1494 sizeof(struct fcoe_crc_eof));
1495 if (mfs >= FC_MIN_MAX_FRAME)
1496 fc_set_mfs(lp, mfs);
Robert Love85b4aa42008-12-09 15:10:24 -08001497 break;
1498 case NETDEV_REGISTER:
1499 break;
1500 default:
Robert Loved5488eb2009-06-10 15:30:59 -07001501 FCOE_NETDEV_DBG(real_dev, "Unknown event %ld "
1502 "from netdev netlink\n", event);
Robert Love85b4aa42008-12-09 15:10:24 -08001503 }
Joe Eykholt97c83892009-03-17 11:42:40 -07001504 if (link_possible && !fcoe_link_ok(lp))
1505 fcoe_ctlr_link_up(&fc->ctlr);
1506 else if (fcoe_ctlr_link_down(&fc->ctlr)) {
1507 stats = fc_lport_get_stats(lp);
1508 stats->LinkFailureCount++;
1509 fcoe_clean_pending_queue(lp);
Robert Love85b4aa42008-12-09 15:10:24 -08001510 }
1511out:
1512 return rc;
1513}
1514
1515/**
Robert Love34f42a02009-02-27 10:55:45 -08001516 * fcoe_if_to_netdev() - parse a name buffer to get netdev
Robert Love85b4aa42008-12-09 15:10:24 -08001517 * @buffer: incoming buffer to be copied
1518 *
Chris Leechdd3fd722009-04-21 16:27:36 -07001519 * Returns: NULL or ptr to net_device
Robert Love34f42a02009-02-27 10:55:45 -08001520 */
Robert Love85b4aa42008-12-09 15:10:24 -08001521static struct net_device *fcoe_if_to_netdev(const char *buffer)
1522{
1523 char *cp;
1524 char ifname[IFNAMSIZ + 2];
1525
1526 if (buffer) {
1527 strlcpy(ifname, buffer, IFNAMSIZ);
1528 cp = ifname + strlen(ifname);
1529 while (--cp >= ifname && *cp == '\n')
1530 *cp = '\0';
1531 return dev_get_by_name(&init_net, ifname);
1532 }
1533 return NULL;
1534}
1535
1536/**
Chris Leechdd3fd722009-04-21 16:27:36 -07001537 * fcoe_netdev_to_module_owner() - finds out the driver module of the netdev
Robert Love85b4aa42008-12-09 15:10:24 -08001538 * @netdev: the target netdev
1539 *
1540 * Returns: ptr to the struct module, NULL for failure
Robert Love34f42a02009-02-27 10:55:45 -08001541 */
Robert Loveb2ab99c2009-02-27 10:55:50 -08001542static struct module *
1543fcoe_netdev_to_module_owner(const struct net_device *netdev)
Robert Love85b4aa42008-12-09 15:10:24 -08001544{
1545 struct device *dev;
1546
1547 if (!netdev)
1548 return NULL;
1549
1550 dev = netdev->dev.parent;
1551 if (!dev)
1552 return NULL;
1553
1554 if (!dev->driver)
1555 return NULL;
1556
1557 return dev->driver->owner;
1558}
1559
1560/**
Robert Love34f42a02009-02-27 10:55:45 -08001561 * fcoe_ethdrv_get() - Hold the Ethernet driver
Robert Love85b4aa42008-12-09 15:10:24 -08001562 * @netdev: the target netdev
1563 *
Robert Love34f42a02009-02-27 10:55:45 -08001564 * Holds the Ethernet driver module by try_module_get() for
1565 * the corresponding netdev.
1566 *
Chris Leechdd3fd722009-04-21 16:27:36 -07001567 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001568 */
Robert Love85b4aa42008-12-09 15:10:24 -08001569static int fcoe_ethdrv_get(const struct net_device *netdev)
1570{
1571 struct module *owner;
1572
1573 owner = fcoe_netdev_to_module_owner(netdev);
1574 if (owner) {
Robert Loved5488eb2009-06-10 15:30:59 -07001575 FCOE_NETDEV_DBG(netdev, "Hold driver module %s\n",
1576 module_name(owner));
Robert Love85b4aa42008-12-09 15:10:24 -08001577 return try_module_get(owner);
1578 }
1579 return -ENODEV;
1580}
1581
1582/**
Robert Love34f42a02009-02-27 10:55:45 -08001583 * fcoe_ethdrv_put() - Release the Ethernet driver
Robert Love85b4aa42008-12-09 15:10:24 -08001584 * @netdev: the target netdev
1585 *
Robert Love34f42a02009-02-27 10:55:45 -08001586 * Releases the Ethernet driver module by module_put for
1587 * the corresponding netdev.
1588 *
Chris Leechdd3fd722009-04-21 16:27:36 -07001589 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001590 */
Robert Love85b4aa42008-12-09 15:10:24 -08001591static int fcoe_ethdrv_put(const struct net_device *netdev)
1592{
1593 struct module *owner;
1594
1595 owner = fcoe_netdev_to_module_owner(netdev);
1596 if (owner) {
Robert Loved5488eb2009-06-10 15:30:59 -07001597 FCOE_NETDEV_DBG(netdev, "Release driver module %s\n",
1598 module_name(owner));
Robert Love85b4aa42008-12-09 15:10:24 -08001599 module_put(owner);
1600 return 0;
1601 }
1602 return -ENODEV;
1603}
1604
1605/**
Robert Love34f42a02009-02-27 10:55:45 -08001606 * fcoe_destroy() - handles the destroy from sysfs
Chris Leechdd3fd722009-04-21 16:27:36 -07001607 * @buffer: expected to be an eth if name
Robert Love85b4aa42008-12-09 15:10:24 -08001608 * @kp: associated kernel param
1609 *
1610 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001611 */
Robert Love85b4aa42008-12-09 15:10:24 -08001612static int fcoe_destroy(const char *buffer, struct kernel_param *kp)
1613{
1614 int rc;
1615 struct net_device *netdev;
1616
1617 netdev = fcoe_if_to_netdev(buffer);
1618 if (!netdev) {
1619 rc = -ENODEV;
1620 goto out_nodev;
1621 }
1622 /* look for existing lport */
1623 if (!fcoe_hostlist_lookup(netdev)) {
1624 rc = -ENODEV;
1625 goto out_putdev;
1626 }
Vasu Dev7f349142009-03-27 09:06:31 -07001627 rc = fcoe_if_destroy(netdev);
Robert Love85b4aa42008-12-09 15:10:24 -08001628 if (rc) {
Robert Loved5488eb2009-06-10 15:30:59 -07001629 printk(KERN_ERR "fcoe: Failed to destroy interface (%s)\n",
Robert Love85b4aa42008-12-09 15:10:24 -08001630 netdev->name);
1631 rc = -EIO;
1632 goto out_putdev;
1633 }
1634 fcoe_ethdrv_put(netdev);
1635 rc = 0;
1636out_putdev:
1637 dev_put(netdev);
1638out_nodev:
1639 return rc;
1640}
1641
1642/**
Robert Love34f42a02009-02-27 10:55:45 -08001643 * fcoe_create() - Handles the create call from sysfs
Chris Leechdd3fd722009-04-21 16:27:36 -07001644 * @buffer: expected to be an eth if name
Robert Love85b4aa42008-12-09 15:10:24 -08001645 * @kp: associated kernel param
1646 *
1647 * Returns: 0 for success
Robert Love34f42a02009-02-27 10:55:45 -08001648 */
Robert Love85b4aa42008-12-09 15:10:24 -08001649static int fcoe_create(const char *buffer, struct kernel_param *kp)
1650{
1651 int rc;
1652 struct net_device *netdev;
1653
1654 netdev = fcoe_if_to_netdev(buffer);
1655 if (!netdev) {
1656 rc = -ENODEV;
1657 goto out_nodev;
1658 }
1659 /* look for existing lport */
1660 if (fcoe_hostlist_lookup(netdev)) {
1661 rc = -EEXIST;
1662 goto out_putdev;
1663 }
1664 fcoe_ethdrv_get(netdev);
1665
Vasu Dev7f349142009-03-27 09:06:31 -07001666 rc = fcoe_if_create(netdev);
Robert Love85b4aa42008-12-09 15:10:24 -08001667 if (rc) {
Robert Loved5488eb2009-06-10 15:30:59 -07001668 printk(KERN_ERR "fcoe: Failed to create interface (%s)\n",
Robert Love85b4aa42008-12-09 15:10:24 -08001669 netdev->name);
1670 fcoe_ethdrv_put(netdev);
1671 rc = -EIO;
1672 goto out_putdev;
1673 }
1674 rc = 0;
1675out_putdev:
1676 dev_put(netdev);
1677out_nodev:
1678 return rc;
1679}
1680
1681module_param_call(create, fcoe_create, NULL, NULL, S_IWUSR);
1682__MODULE_PARM_TYPE(create, "string");
1683MODULE_PARM_DESC(create, "Create fcoe port using net device passed in.");
1684module_param_call(destroy, fcoe_destroy, NULL, NULL, S_IWUSR);
1685__MODULE_PARM_TYPE(destroy, "string");
1686MODULE_PARM_DESC(destroy, "Destroy fcoe port");
1687
Robert Love34f42a02009-02-27 10:55:45 -08001688/**
1689 * fcoe_link_ok() - Check if link is ok for the fc_lport
Robert Love85b4aa42008-12-09 15:10:24 -08001690 * @lp: ptr to the fc_lport
1691 *
1692 * Any permanently-disqualifying conditions have been previously checked.
1693 * This also updates the speed setting, which may change with link for 100/1000.
1694 *
1695 * This function should probably be checking for PAUSE support at some point
1696 * in the future. Currently Per-priority-pause is not determinable using
1697 * ethtool, so we shouldn't be restrictive until that problem is resolved.
1698 *
1699 * Returns: 0 if link is OK for use by FCoE.
1700 *
1701 */
1702int fcoe_link_ok(struct fc_lport *lp)
1703{
Robert Lovefc47ff62009-02-27 10:55:55 -08001704 struct fcoe_softc *fc = lport_priv(lp);
Robert Love85b4aa42008-12-09 15:10:24 -08001705 struct net_device *dev = fc->real_dev;
1706 struct ethtool_cmd ecmd = { ETHTOOL_GSET };
Robert Love85b4aa42008-12-09 15:10:24 -08001707
Yi Zou2f718d62009-07-29 17:04:01 -07001708 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev) &&
1709 (!dev_ethtool_get_settings(dev, &ecmd))) {
1710 lp->link_supported_speeds &=
1711 ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
1712 if (ecmd.supported & (SUPPORTED_1000baseT_Half |
1713 SUPPORTED_1000baseT_Full))
1714 lp->link_supported_speeds |= FC_PORTSPEED_1GBIT;
1715 if (ecmd.supported & SUPPORTED_10000baseT_Full)
1716 lp->link_supported_speeds |=
1717 FC_PORTSPEED_10GBIT;
1718 if (ecmd.speed == SPEED_1000)
1719 lp->link_speed = FC_PORTSPEED_1GBIT;
1720 if (ecmd.speed == SPEED_10000)
1721 lp->link_speed = FC_PORTSPEED_10GBIT;
Robert Love85b4aa42008-12-09 15:10:24 -08001722
Yi Zou2f718d62009-07-29 17:04:01 -07001723 return 0;
1724 }
1725 return -1;
Robert Love85b4aa42008-12-09 15:10:24 -08001726}
Robert Love85b4aa42008-12-09 15:10:24 -08001727
Robert Love34f42a02009-02-27 10:55:45 -08001728/**
1729 * fcoe_percpu_clean() - Clear the pending skbs for an lport
Robert Love85b4aa42008-12-09 15:10:24 -08001730 * @lp: the fc_lport
1731 */
1732void fcoe_percpu_clean(struct fc_lport *lp)
1733{
Robert Love85b4aa42008-12-09 15:10:24 -08001734 struct fcoe_percpu_s *pp;
1735 struct fcoe_rcv_info *fr;
1736 struct sk_buff_head *list;
1737 struct sk_buff *skb, *next;
1738 struct sk_buff *head;
Robert Love5e5e92d2009-03-17 11:41:35 -07001739 unsigned int cpu;
Robert Love85b4aa42008-12-09 15:10:24 -08001740
Robert Love5e5e92d2009-03-17 11:41:35 -07001741 for_each_possible_cpu(cpu) {
1742 pp = &per_cpu(fcoe_percpu, cpu);
1743 spin_lock_bh(&pp->fcoe_rx_list.lock);
1744 list = &pp->fcoe_rx_list;
1745 head = list->next;
1746 for (skb = head; skb != (struct sk_buff *)list;
1747 skb = next) {
1748 next = skb->next;
1749 fr = fcoe_dev_from_skb(skb);
1750 if (fr->fr_dev == lp) {
1751 __skb_unlink(skb, list);
1752 kfree_skb(skb);
Robert Love85b4aa42008-12-09 15:10:24 -08001753 }
Robert Love85b4aa42008-12-09 15:10:24 -08001754 }
Robert Love5e5e92d2009-03-17 11:41:35 -07001755 spin_unlock_bh(&pp->fcoe_rx_list.lock);
Robert Love85b4aa42008-12-09 15:10:24 -08001756 }
1757}
Robert Love85b4aa42008-12-09 15:10:24 -08001758
1759/**
Robert Love34f42a02009-02-27 10:55:45 -08001760 * fcoe_clean_pending_queue() - Dequeue a skb and free it
Robert Love85b4aa42008-12-09 15:10:24 -08001761 * @lp: the corresponding fc_lport
1762 *
1763 * Returns: none
Robert Love34f42a02009-02-27 10:55:45 -08001764 */
Robert Love85b4aa42008-12-09 15:10:24 -08001765void fcoe_clean_pending_queue(struct fc_lport *lp)
1766{
1767 struct fcoe_softc *fc = lport_priv(lp);
1768 struct sk_buff *skb;
1769
1770 spin_lock_bh(&fc->fcoe_pending_queue.lock);
1771 while ((skb = __skb_dequeue(&fc->fcoe_pending_queue)) != NULL) {
1772 spin_unlock_bh(&fc->fcoe_pending_queue.lock);
1773 kfree_skb(skb);
1774 spin_lock_bh(&fc->fcoe_pending_queue.lock);
1775 }
1776 spin_unlock_bh(&fc->fcoe_pending_queue.lock);
1777}
Robert Love85b4aa42008-12-09 15:10:24 -08001778
1779/**
Robert Love34f42a02009-02-27 10:55:45 -08001780 * fcoe_reset() - Resets the fcoe
Robert Love85b4aa42008-12-09 15:10:24 -08001781 * @shost: shost the reset is from
1782 *
1783 * Returns: always 0
1784 */
1785int fcoe_reset(struct Scsi_Host *shost)
1786{
1787 struct fc_lport *lport = shost_priv(shost);
1788 fc_lport_reset(lport);
1789 return 0;
1790}
Robert Love85b4aa42008-12-09 15:10:24 -08001791
Robert Love34f42a02009-02-27 10:55:45 -08001792/**
Robert Love34f42a02009-02-27 10:55:45 -08001793 * fcoe_hostlist_lookup_softc() - find the corresponding lport by a given device
Chris Leechdd3fd722009-04-21 16:27:36 -07001794 * @dev: this is currently ptr to net_device
Robert Love85b4aa42008-12-09 15:10:24 -08001795 *
Vasu Deve8af4d42009-07-29 17:05:15 -07001796 * Called with fcoe_hostlist_lock held.
1797 *
Robert Love85b4aa42008-12-09 15:10:24 -08001798 * Returns: NULL or the located fcoe_softc
1799 */
Robert Loveb2ab99c2009-02-27 10:55:50 -08001800static struct fcoe_softc *
1801fcoe_hostlist_lookup_softc(const struct net_device *dev)
Robert Love85b4aa42008-12-09 15:10:24 -08001802{
1803 struct fcoe_softc *fc;
1804
Robert Love85b4aa42008-12-09 15:10:24 -08001805 list_for_each_entry(fc, &fcoe_hostlist, list) {
Vasu Deve8af4d42009-07-29 17:05:15 -07001806 if (fc->real_dev == dev)
Robert Love85b4aa42008-12-09 15:10:24 -08001807 return fc;
Robert Love85b4aa42008-12-09 15:10:24 -08001808 }
Robert Love85b4aa42008-12-09 15:10:24 -08001809 return NULL;
1810}
1811
Robert Love34f42a02009-02-27 10:55:45 -08001812/**
1813 * fcoe_hostlist_lookup() - Find the corresponding lport by netdev
Robert Love85b4aa42008-12-09 15:10:24 -08001814 * @netdev: ptr to net_device
1815 *
1816 * Returns: 0 for success
1817 */
1818struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev)
1819{
1820 struct fcoe_softc *fc;
1821
Vasu Deve8af4d42009-07-29 17:05:15 -07001822 read_lock(&fcoe_hostlist_lock);
Robert Love85b4aa42008-12-09 15:10:24 -08001823 fc = fcoe_hostlist_lookup_softc(netdev);
Vasu Deve8af4d42009-07-29 17:05:15 -07001824 read_unlock(&fcoe_hostlist_lock);
Robert Love85b4aa42008-12-09 15:10:24 -08001825
Joe Eykholt97c83892009-03-17 11:42:40 -07001826 return (fc) ? fc->ctlr.lp : NULL;
Robert Love85b4aa42008-12-09 15:10:24 -08001827}
Robert Love85b4aa42008-12-09 15:10:24 -08001828
Robert Love34f42a02009-02-27 10:55:45 -08001829/**
1830 * fcoe_hostlist_add() - Add a lport to lports list
Chris Leechdd3fd722009-04-21 16:27:36 -07001831 * @lp: ptr to the fc_lport to be added
Robert Love85b4aa42008-12-09 15:10:24 -08001832 *
Vasu Deve8af4d42009-07-29 17:05:15 -07001833 * Called with write fcoe_hostlist_lock held.
1834 *
Robert Love85b4aa42008-12-09 15:10:24 -08001835 * Returns: 0 for success
1836 */
1837int fcoe_hostlist_add(const struct fc_lport *lp)
1838{
1839 struct fcoe_softc *fc;
1840
1841 fc = fcoe_hostlist_lookup_softc(fcoe_netdev(lp));
1842 if (!fc) {
Robert Lovefc47ff62009-02-27 10:55:55 -08001843 fc = lport_priv(lp);
Robert Love85b4aa42008-12-09 15:10:24 -08001844 list_add_tail(&fc->list, &fcoe_hostlist);
Robert Love85b4aa42008-12-09 15:10:24 -08001845 }
1846 return 0;
1847}
Robert Love85b4aa42008-12-09 15:10:24 -08001848
Robert Love34f42a02009-02-27 10:55:45 -08001849/**
1850 * fcoe_hostlist_remove() - remove a lport from lports list
Chris Leechdd3fd722009-04-21 16:27:36 -07001851 * @lp: ptr to the fc_lport to be removed
Robert Love85b4aa42008-12-09 15:10:24 -08001852 *
1853 * Returns: 0 for success
1854 */
1855int fcoe_hostlist_remove(const struct fc_lport *lp)
1856{
1857 struct fcoe_softc *fc;
1858
Vasu Deve8af4d42009-07-29 17:05:15 -07001859 write_lock_bh(&fcoe_hostlist_lock);
Robert Love85b4aa42008-12-09 15:10:24 -08001860 fc = fcoe_hostlist_lookup_softc(fcoe_netdev(lp));
1861 BUG_ON(!fc);
Robert Love85b4aa42008-12-09 15:10:24 -08001862 list_del(&fc->list);
1863 write_unlock_bh(&fcoe_hostlist_lock);
1864
1865 return 0;
1866}
Robert Love85b4aa42008-12-09 15:10:24 -08001867
1868/**
Robert Love34f42a02009-02-27 10:55:45 -08001869 * fcoe_init() - fcoe module loading initialization
Robert Love85b4aa42008-12-09 15:10:24 -08001870 *
Robert Love85b4aa42008-12-09 15:10:24 -08001871 * Returns 0 on success, negative on failure
Robert Love34f42a02009-02-27 10:55:45 -08001872 */
Robert Love85b4aa42008-12-09 15:10:24 -08001873static int __init fcoe_init(void)
1874{
Robert Love38eccab2009-03-17 11:41:30 -07001875 unsigned int cpu;
Robert Love8976f422009-03-17 11:41:46 -07001876 int rc = 0;
Robert Love85b4aa42008-12-09 15:10:24 -08001877 struct fcoe_percpu_s *p;
1878
Robert Love85b4aa42008-12-09 15:10:24 -08001879 INIT_LIST_HEAD(&fcoe_hostlist);
1880 rwlock_init(&fcoe_hostlist_lock);
1881
Robert Love38eccab2009-03-17 11:41:30 -07001882 for_each_possible_cpu(cpu) {
Robert Love5e5e92d2009-03-17 11:41:35 -07001883 p = &per_cpu(fcoe_percpu, cpu);
Robert Love38eccab2009-03-17 11:41:30 -07001884 skb_queue_head_init(&p->fcoe_rx_list);
1885 }
1886
Robert Love8976f422009-03-17 11:41:46 -07001887 for_each_online_cpu(cpu)
1888 fcoe_percpu_thread_create(cpu);
Robert Love85b4aa42008-12-09 15:10:24 -08001889
Robert Love8976f422009-03-17 11:41:46 -07001890 /* Initialize per CPU interrupt thread */
1891 rc = register_hotcpu_notifier(&fcoe_cpu_notifier);
1892 if (rc)
1893 goto out_free;
Robert Love85b4aa42008-12-09 15:10:24 -08001894
Robert Love8976f422009-03-17 11:41:46 -07001895 /* Setup link change notification */
Robert Love85b4aa42008-12-09 15:10:24 -08001896 fcoe_dev_setup();
1897
Vasu Dev7f349142009-03-27 09:06:31 -07001898 fcoe_if_init();
Robert Love85b4aa42008-12-09 15:10:24 -08001899
1900 return 0;
Robert Love8976f422009-03-17 11:41:46 -07001901
1902out_free:
1903 for_each_online_cpu(cpu) {
1904 fcoe_percpu_thread_destroy(cpu);
1905 }
1906
1907 return rc;
Robert Love85b4aa42008-12-09 15:10:24 -08001908}
1909module_init(fcoe_init);
1910
1911/**
Robert Love34f42a02009-02-27 10:55:45 -08001912 * fcoe_exit() - fcoe module unloading cleanup
Robert Love85b4aa42008-12-09 15:10:24 -08001913 *
1914 * Returns 0 on success, negative on failure
Robert Love34f42a02009-02-27 10:55:45 -08001915 */
Robert Love85b4aa42008-12-09 15:10:24 -08001916static void __exit fcoe_exit(void)
1917{
Robert Love5e5e92d2009-03-17 11:41:35 -07001918 unsigned int cpu;
Robert Love85b4aa42008-12-09 15:10:24 -08001919 struct fcoe_softc *fc, *tmp;
Robert Love85b4aa42008-12-09 15:10:24 -08001920
Robert Love85b4aa42008-12-09 15:10:24 -08001921 fcoe_dev_cleanup();
1922
Vasu Dev5919a592009-03-27 09:03:29 -07001923 /* releases the associated fcoe hosts */
Robert Love85b4aa42008-12-09 15:10:24 -08001924 list_for_each_entry_safe(fc, tmp, &fcoe_hostlist, list)
Vasu Dev7f349142009-03-27 09:06:31 -07001925 fcoe_if_destroy(fc->real_dev);
Robert Love85b4aa42008-12-09 15:10:24 -08001926
Robert Love8976f422009-03-17 11:41:46 -07001927 unregister_hotcpu_notifier(&fcoe_cpu_notifier);
1928
1929 for_each_online_cpu(cpu) {
1930 fcoe_percpu_thread_destroy(cpu);
Robert Love85b4aa42008-12-09 15:10:24 -08001931 }
1932
Vasu Dev7f349142009-03-27 09:06:31 -07001933 /* detach from scsi transport */
1934 fcoe_if_exit();
Robert Love85b4aa42008-12-09 15:10:24 -08001935}
1936module_exit(fcoe_exit);