[SCSI] fcoe: fcoe_interface create, destroy and refcounting
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / scsi / fcoe / fcoe.c
1 /*
2 * Copyright(c) 2007 - 2009 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>
22 #include <linux/spinlock.h>
23 #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>
28 #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>
40 #include <scsi/fc/fc_fip.h>
41
42 #include <scsi/libfc.h>
43 #include <scsi/fc_frame.h>
44 #include <scsi/libfcoe.h>
45
46 #include "fcoe.h"
47
48 MODULE_AUTHOR("Open-FCoE.org");
49 MODULE_DESCRIPTION("FCoE");
50 MODULE_LICENSE("GPL v2");
51
52 /* Performance tuning parameters for fcoe */
53 static unsigned int fcoe_ddp_min;
54 module_param_named(ddp_min, fcoe_ddp_min, uint, S_IRUGO | S_IWUSR);
55 MODULE_PARM_DESC(ddp_min, "Minimum I/O size in bytes for " \
56 "Direct Data Placement (DDP).");
57
58 /* fcoe host list */
59 LIST_HEAD(fcoe_hostlist);
60 DEFINE_RWLOCK(fcoe_hostlist_lock);
61 DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu);
62
63 /* Function Prototypes */
64 static int fcoe_reset(struct Scsi_Host *shost);
65 static int fcoe_xmit(struct fc_lport *, struct fc_frame *);
66 static int fcoe_rcv(struct sk_buff *, struct net_device *,
67 struct packet_type *, struct net_device *);
68 static int fcoe_percpu_receive_thread(void *arg);
69 static void fcoe_clean_pending_queue(struct fc_lport *lp);
70 static void fcoe_percpu_clean(struct fc_lport *lp);
71 static int fcoe_link_ok(struct fc_lport *lp);
72
73 static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *);
74 static int fcoe_hostlist_add(const struct fc_lport *);
75 static int fcoe_hostlist_remove(const struct fc_lport *);
76
77 static void fcoe_check_wait_queue(struct fc_lport *, struct sk_buff *);
78 static int fcoe_device_notification(struct notifier_block *, ulong, void *);
79 static void fcoe_dev_setup(void);
80 static void fcoe_dev_cleanup(void);
81
82 /* notification function from net device */
83 static struct notifier_block fcoe_notifier = {
84 .notifier_call = fcoe_device_notification,
85 };
86
87 static struct scsi_transport_template *scsi_transport_fcoe_sw;
88
89 struct fc_function_template fcoe_transport_function = {
90 .show_host_node_name = 1,
91 .show_host_port_name = 1,
92 .show_host_supported_classes = 1,
93 .show_host_supported_fc4s = 1,
94 .show_host_active_fc4s = 1,
95 .show_host_maxframe_size = 1,
96
97 .show_host_port_id = 1,
98 .show_host_supported_speeds = 1,
99 .get_host_speed = fc_get_host_speed,
100 .show_host_speed = 1,
101 .show_host_port_type = 1,
102 .get_host_port_state = fc_get_host_port_state,
103 .show_host_port_state = 1,
104 .show_host_symbolic_name = 1,
105
106 .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv),
107 .show_rport_maxframe_size = 1,
108 .show_rport_supported_classes = 1,
109
110 .show_host_fabric_name = 1,
111 .show_starget_node_name = 1,
112 .show_starget_port_name = 1,
113 .show_starget_port_id = 1,
114 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
115 .show_rport_dev_loss_tmo = 1,
116 .get_fc_host_stats = fc_get_host_stats,
117 .issue_fc_host_lip = fcoe_reset,
118
119 .terminate_rport_io = fc_rport_terminate_io,
120 };
121
122 static struct scsi_host_template fcoe_shost_template = {
123 .module = THIS_MODULE,
124 .name = "FCoE Driver",
125 .proc_name = FCOE_NAME,
126 .queuecommand = fc_queuecommand,
127 .eh_abort_handler = fc_eh_abort,
128 .eh_device_reset_handler = fc_eh_device_reset,
129 .eh_host_reset_handler = fc_eh_host_reset,
130 .slave_alloc = fc_slave_alloc,
131 .change_queue_depth = fc_change_queue_depth,
132 .change_queue_type = fc_change_queue_type,
133 .this_id = -1,
134 .cmd_per_lun = 32,
135 .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS,
136 .use_clustering = ENABLE_CLUSTERING,
137 .sg_tablesize = SG_ALL,
138 .max_sectors = 0xffff,
139 };
140
141 /**
142 * fcoe_interface_create()
143 * @netdev: network interface
144 *
145 * Returns: pointer to a struct fcoe_interface or NULL on error
146 */
147 static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev)
148 {
149 struct fcoe_interface *fcoe;
150
151 fcoe = kzalloc(sizeof(*fcoe), GFP_KERNEL);
152 if (!fcoe) {
153 FCOE_NETDEV_DBG(netdev, "Could not allocate fcoe structure\n");
154 return NULL;
155 }
156
157 kref_init(&fcoe->kref);
158 fcoe->netdev = netdev;
159
160 return fcoe;
161 }
162
163 /**
164 * fcoe_interface_release() - fcoe_port kref release function
165 * @kref: embedded reference count in an fcoe_interface struct
166 */
167 static void fcoe_interface_release(struct kref *kref)
168 {
169 struct fcoe_interface *fcoe;
170
171 fcoe = container_of(kref, struct fcoe_interface, kref);
172 kfree(fcoe);
173 }
174
175 /**
176 * fcoe_interface_get()
177 * @fcoe:
178 */
179 static inline void fcoe_interface_get(struct fcoe_interface *fcoe)
180 {
181 kref_get(&fcoe->kref);
182 }
183
184 /**
185 * fcoe_interface_put()
186 * @fcoe:
187 */
188 static inline void fcoe_interface_put(struct fcoe_interface *fcoe)
189 {
190 kref_put(&fcoe->kref, fcoe_interface_release);
191 }
192
193 /**
194 * fcoe_fip_recv - handle a received FIP frame.
195 * @skb: the receive skb
196 * @dev: associated &net_device
197 * @ptype: the &packet_type structure which was used to register this handler.
198 * @orig_dev: original receive &net_device, in case @dev is a bond.
199 *
200 * Returns: 0 for success
201 */
202 static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *dev,
203 struct packet_type *ptype,
204 struct net_device *orig_dev)
205 {
206 struct fcoe_interface *fcoe;
207
208 fcoe = container_of(ptype, struct fcoe_interface, fip_packet_type);
209 fcoe_ctlr_recv(&fcoe->ctlr, skb);
210 return 0;
211 }
212
213 /**
214 * fcoe_fip_send() - send an Ethernet-encapsulated FIP frame.
215 * @fip: FCoE controller.
216 * @skb: FIP Packet.
217 */
218 static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
219 {
220 skb->dev = fcoe_from_ctlr(fip)->netdev;
221 dev_queue_xmit(skb);
222 }
223
224 /**
225 * fcoe_update_src_mac() - Update Ethernet MAC filters.
226 * @fip: FCoE controller.
227 * @old: Unicast MAC address to delete if the MAC is non-zero.
228 * @new: Unicast MAC address to add.
229 *
230 * Remove any previously-set unicast MAC filter.
231 * Add secondary FCoE MAC address filter for our OUI.
232 */
233 static void fcoe_update_src_mac(struct fcoe_ctlr *fip, u8 *old, u8 *new)
234 {
235 struct fcoe_interface *fcoe;
236
237 fcoe = fcoe_from_ctlr(fip);
238 rtnl_lock();
239 if (!is_zero_ether_addr(old))
240 dev_unicast_delete(fcoe->netdev, old);
241 dev_unicast_add(fcoe->netdev, new);
242 rtnl_unlock();
243 }
244
245 /**
246 * fcoe_lport_config() - sets up the fc_lport
247 * @lp: ptr to the fc_lport
248 *
249 * Returns: 0 for success
250 */
251 static int fcoe_lport_config(struct fc_lport *lp)
252 {
253 lp->link_up = 0;
254 lp->qfull = 0;
255 lp->max_retry_count = 3;
256 lp->max_rport_retry_count = 3;
257 lp->e_d_tov = 2 * 1000; /* FC-FS default */
258 lp->r_a_tov = 2 * 2 * 1000;
259 lp->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
260 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
261
262 fc_lport_init_stats(lp);
263
264 /* lport fc_lport related configuration */
265 fc_lport_config(lp);
266
267 /* offload related configuration */
268 lp->crc_offload = 0;
269 lp->seq_offload = 0;
270 lp->lro_enabled = 0;
271 lp->lro_xid = 0;
272 lp->lso_max = 0;
273
274 return 0;
275 }
276
277 /**
278 * fcoe_netdev_cleanup() - clean up netdev configurations
279 * @port: ptr to the fcoe_port
280 */
281 void fcoe_netdev_cleanup(struct fcoe_port *port)
282 {
283 u8 flogi_maddr[ETH_ALEN];
284 struct fcoe_interface *fcoe = port->fcoe;
285
286 /* Don't listen for Ethernet packets anymore */
287 dev_remove_pack(&fcoe->fcoe_packet_type);
288 dev_remove_pack(&fcoe->fip_packet_type);
289
290 /* Delete secondary MAC addresses */
291 rtnl_lock();
292 memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
293 dev_unicast_delete(fcoe->netdev, flogi_maddr);
294 if (!is_zero_ether_addr(fcoe->ctlr.data_src_addr))
295 dev_unicast_delete(fcoe->netdev, fcoe->ctlr.data_src_addr);
296 if (fcoe->ctlr.spma)
297 dev_unicast_delete(fcoe->netdev, fcoe->ctlr.ctl_src_addr);
298 dev_mc_delete(fcoe->netdev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
299 rtnl_unlock();
300 }
301
302 /**
303 * fcoe_queue_timer() - fcoe queue timer
304 * @lp: the fc_lport pointer
305 *
306 * Calls fcoe_check_wait_queue on timeout
307 *
308 */
309 static void fcoe_queue_timer(ulong lp)
310 {
311 fcoe_check_wait_queue((struct fc_lport *)lp, NULL);
312 }
313
314 /**
315 * fcoe_netdev_config() - Set up netdev for SW FCoE
316 * @lp : ptr to the fc_lport
317 * @netdev : ptr to the associated netdevice struct
318 *
319 * Must be called after fcoe_lport_config() as it will use lport mutex
320 *
321 * Returns : 0 for success
322 */
323 static int fcoe_netdev_config(struct fc_lport *lp, struct net_device *netdev)
324 {
325 u32 mfs;
326 u64 wwnn, wwpn;
327 struct fcoe_interface *fcoe;
328 struct fcoe_port *port;
329 u8 flogi_maddr[ETH_ALEN];
330 struct netdev_hw_addr *ha;
331
332 /* Setup lport private data to point to fcoe softc */
333 port = lport_priv(lp);
334 fcoe = port->fcoe;
335 fcoe->ctlr.lp = lp;
336 fcoe->netdev = netdev;
337
338 /* Do not support for bonding device */
339 if ((netdev->priv_flags & IFF_MASTER_ALB) ||
340 (netdev->priv_flags & IFF_SLAVE_INACTIVE) ||
341 (netdev->priv_flags & IFF_MASTER_8023AD)) {
342 return -EOPNOTSUPP;
343 }
344
345 /*
346 * Determine max frame size based on underlying device and optional
347 * user-configured limit. If the MFS is too low, fcoe_link_ok()
348 * will return 0, so do this first.
349 */
350 mfs = netdev->mtu - (sizeof(struct fcoe_hdr) +
351 sizeof(struct fcoe_crc_eof));
352 if (fc_set_mfs(lp, mfs))
353 return -EINVAL;
354
355 /* offload features support */
356 if (netdev->features & NETIF_F_SG)
357 lp->sg_supp = 1;
358
359 if (netdev->features & NETIF_F_FCOE_CRC) {
360 lp->crc_offload = 1;
361 FCOE_NETDEV_DBG(netdev, "Supports FCCRC offload\n");
362 }
363 if (netdev->features & NETIF_F_FSO) {
364 lp->seq_offload = 1;
365 lp->lso_max = netdev->gso_max_size;
366 FCOE_NETDEV_DBG(netdev, "Supports LSO for max len 0x%x\n",
367 lp->lso_max);
368 }
369 if (netdev->fcoe_ddp_xid) {
370 lp->lro_enabled = 1;
371 lp->lro_xid = netdev->fcoe_ddp_xid;
372 FCOE_NETDEV_DBG(netdev, "Supports LRO for max xid 0x%x\n",
373 lp->lro_xid);
374 }
375 skb_queue_head_init(&port->fcoe_pending_queue);
376 port->fcoe_pending_queue_active = 0;
377 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long)lp);
378
379 /* look for SAN MAC address, if multiple SAN MACs exist, only
380 * use the first one for SPMA */
381 rcu_read_lock();
382 for_each_dev_addr(netdev, ha) {
383 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
384 (is_valid_ether_addr(fcoe->ctlr.ctl_src_addr))) {
385 memcpy(fcoe->ctlr.ctl_src_addr, ha->addr, ETH_ALEN);
386 fcoe->ctlr.spma = 1;
387 break;
388 }
389 }
390 rcu_read_unlock();
391
392 /* setup Source Mac Address */
393 if (!fcoe->ctlr.spma)
394 memcpy(fcoe->ctlr.ctl_src_addr, netdev->dev_addr,
395 netdev->addr_len);
396
397 wwnn = fcoe_wwn_from_mac(netdev->dev_addr, 1, 0);
398 fc_set_wwnn(lp, wwnn);
399 /* XXX - 3rd arg needs to be vlan id */
400 wwpn = fcoe_wwn_from_mac(netdev->dev_addr, 2, 0);
401 fc_set_wwpn(lp, wwpn);
402
403 /*
404 * Add FCoE MAC address as second unicast MAC address
405 * or enter promiscuous mode if not capable of listening
406 * for multiple unicast MACs.
407 */
408 rtnl_lock();
409 memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
410 dev_unicast_add(netdev, flogi_maddr);
411 if (fcoe->ctlr.spma)
412 dev_unicast_add(netdev, fcoe->ctlr.ctl_src_addr);
413 dev_mc_add(netdev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
414 rtnl_unlock();
415
416 /*
417 * setup the receive function from ethernet driver
418 * on the ethertype for the given device
419 */
420 fcoe->fcoe_packet_type.func = fcoe_rcv;
421 fcoe->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
422 fcoe->fcoe_packet_type.dev = netdev;
423 dev_add_pack(&fcoe->fcoe_packet_type);
424
425 fcoe->fip_packet_type.func = fcoe_fip_recv;
426 fcoe->fip_packet_type.type = htons(ETH_P_FIP);
427 fcoe->fip_packet_type.dev = netdev;
428 dev_add_pack(&fcoe->fip_packet_type);
429
430 return 0;
431 }
432
433 /**
434 * fcoe_shost_config() - Sets up fc_lport->host
435 * @lp : ptr to the fc_lport
436 * @shost : ptr to the associated scsi host
437 * @dev : device associated to scsi host
438 *
439 * Must be called after fcoe_lport_config() and fcoe_netdev_config()
440 *
441 * Returns : 0 for success
442 */
443 static int fcoe_shost_config(struct fc_lport *lp, struct Scsi_Host *shost,
444 struct device *dev)
445 {
446 int rc = 0;
447
448 /* lport scsi host config */
449 lp->host = shost;
450
451 lp->host->max_lun = FCOE_MAX_LUN;
452 lp->host->max_id = FCOE_MAX_FCP_TARGET;
453 lp->host->max_channel = 0;
454 lp->host->transportt = scsi_transport_fcoe_sw;
455
456 /* add the new host to the SCSI-ml */
457 rc = scsi_add_host(lp->host, dev);
458 if (rc) {
459 FCOE_NETDEV_DBG(fcoe_netdev(lp), "fcoe_shost_config: "
460 "error on scsi_add_host\n");
461 return rc;
462 }
463 sprintf(fc_host_symbolic_name(lp->host), "%s v%s over %s",
464 FCOE_NAME, FCOE_VERSION,
465 fcoe_netdev(lp)->name);
466
467 return 0;
468 }
469
470 /*
471 * fcoe_oem_match() - match for read types IO
472 * @fp: the fc_frame for new IO.
473 *
474 * Returns : true for read types IO, otherwise returns false.
475 */
476 bool fcoe_oem_match(struct fc_frame *fp)
477 {
478 return fc_fcp_is_read(fr_fsp(fp)) &&
479 (fr_fsp(fp)->data_len > fcoe_ddp_min);
480 }
481
482 /**
483 * fcoe_em_config() - allocates em for this lport
484 * @lp: the fcoe that em is to allocated for
485 *
486 * Called with write fcoe_hostlist_lock held.
487 *
488 * Returns : 0 on success
489 */
490 static inline int fcoe_em_config(struct fc_lport *lp)
491 {
492 struct fcoe_port *port = lport_priv(lp);
493 struct fcoe_interface *fcoe = port->fcoe;
494 struct fcoe_interface *oldfcoe = NULL;
495 struct net_device *old_real_dev, *cur_real_dev;
496 u16 min_xid = FCOE_MIN_XID;
497 u16 max_xid = FCOE_MAX_XID;
498
499 /*
500 * Check if need to allocate an em instance for
501 * offload exchange ids to be shared across all VN_PORTs/lport.
502 */
503 if (!lp->lro_enabled || !lp->lro_xid || (lp->lro_xid >= max_xid)) {
504 lp->lro_xid = 0;
505 goto skip_oem;
506 }
507
508 /*
509 * Reuse existing offload em instance in case
510 * it is already allocated on real eth device
511 */
512 if (fcoe->netdev->priv_flags & IFF_802_1Q_VLAN)
513 cur_real_dev = vlan_dev_real_dev(fcoe->netdev);
514 else
515 cur_real_dev = fcoe->netdev;
516
517 list_for_each_entry(oldfcoe, &fcoe_hostlist, list) {
518 if (oldfcoe->netdev->priv_flags & IFF_802_1Q_VLAN)
519 old_real_dev = vlan_dev_real_dev(oldfcoe->netdev);
520 else
521 old_real_dev = oldfcoe->netdev;
522
523 if (cur_real_dev == old_real_dev) {
524 fcoe->oem = oldfcoe->oem;
525 break;
526 }
527 }
528
529 if (fcoe->oem) {
530 if (!fc_exch_mgr_add(lp, fcoe->oem, fcoe_oem_match)) {
531 printk(KERN_ERR "fcoe_em_config: failed to add "
532 "offload em:%p on interface:%s\n",
533 fcoe->oem, fcoe->netdev->name);
534 return -ENOMEM;
535 }
536 } else {
537 fcoe->oem = fc_exch_mgr_alloc(lp, FC_CLASS_3,
538 FCOE_MIN_XID, lp->lro_xid,
539 fcoe_oem_match);
540 if (!fcoe->oem) {
541 printk(KERN_ERR "fcoe_em_config: failed to allocate "
542 "em for offload exches on interface:%s\n",
543 fcoe->netdev->name);
544 return -ENOMEM;
545 }
546 }
547
548 /*
549 * Exclude offload EM xid range from next EM xid range.
550 */
551 min_xid += lp->lro_xid + 1;
552
553 skip_oem:
554 if (!fc_exch_mgr_alloc(lp, FC_CLASS_3, min_xid, max_xid, NULL)) {
555 printk(KERN_ERR "fcoe_em_config: failed to "
556 "allocate em on interface %s\n", fcoe->netdev->name);
557 return -ENOMEM;
558 }
559
560 return 0;
561 }
562
563 /**
564 * fcoe_if_destroy() - FCoE software HBA tear-down function
565 * @lport: fc_lport to destroy
566 */
567 static void fcoe_if_destroy(struct fc_lport *lport)
568 {
569 struct fcoe_port *port = lport_priv(lport);
570 struct fcoe_interface *fcoe = port->fcoe;
571 struct net_device *netdev = fcoe->netdev;
572
573 FCOE_NETDEV_DBG(netdev, "Destroying interface\n");
574
575 /* Logout of the fabric */
576 fc_fabric_logoff(lport);
577
578 /* Remove the instance from fcoe's list */
579 fcoe_hostlist_remove(lport);
580
581 /* clean up netdev configurations */
582 fcoe_netdev_cleanup(port);
583
584 /* tear-down the FCoE controller */
585 fcoe_ctlr_destroy(&fcoe->ctlr);
586
587 /* Free queued packets for the per-CPU receive threads */
588 fcoe_percpu_clean(lport);
589
590 /* Cleanup the fc_lport */
591 fc_lport_destroy(lport);
592 fc_fcp_destroy(lport);
593
594 /* Detach from the scsi-ml */
595 fc_remove_host(lport->host);
596 scsi_remove_host(lport->host);
597
598 /* There are no more rports or I/O, free the EM */
599 fc_exch_mgr_free(lport);
600
601 /* Free existing skbs */
602 fcoe_clean_pending_queue(lport);
603
604 /* Stop the timer */
605 del_timer_sync(&port->timer);
606
607 /* Free memory used by statistical counters */
608 fc_lport_free_stats(lport);
609
610 /* Release the net_device and Scsi_Host */
611 dev_put(netdev);
612 scsi_host_put(lport->host);
613 fcoe_interface_put(fcoe);
614 }
615
616 /*
617 * fcoe_ddp_setup - calls LLD's ddp_setup through net_device
618 * @lp: the corresponding fc_lport
619 * @xid: the exchange id for this ddp transfer
620 * @sgl: the scatterlist describing this transfer
621 * @sgc: number of sg items
622 *
623 * Returns : 0 no ddp
624 */
625 static int fcoe_ddp_setup(struct fc_lport *lp, u16 xid,
626 struct scatterlist *sgl, unsigned int sgc)
627 {
628 struct net_device *n = fcoe_netdev(lp);
629
630 if (n->netdev_ops && n->netdev_ops->ndo_fcoe_ddp_setup)
631 return n->netdev_ops->ndo_fcoe_ddp_setup(n, xid, sgl, sgc);
632
633 return 0;
634 }
635
636 /*
637 * fcoe_ddp_done - calls LLD's ddp_done through net_device
638 * @lp: the corresponding fc_lport
639 * @xid: the exchange id for this ddp transfer
640 *
641 * Returns : the length of data that have been completed by ddp
642 */
643 static int fcoe_ddp_done(struct fc_lport *lp, u16 xid)
644 {
645 struct net_device *n = fcoe_netdev(lp);
646
647 if (n->netdev_ops && n->netdev_ops->ndo_fcoe_ddp_done)
648 return n->netdev_ops->ndo_fcoe_ddp_done(n, xid);
649 return 0;
650 }
651
652 static struct libfc_function_template fcoe_libfc_fcn_templ = {
653 .frame_send = fcoe_xmit,
654 .ddp_setup = fcoe_ddp_setup,
655 .ddp_done = fcoe_ddp_done,
656 };
657
658 /**
659 * fcoe_if_create() - this function creates the fcoe port
660 * @fcoe: fcoe_interface structure to create an fc_lport instance on
661 * @parent: device pointer to be the parent in sysfs for the SCSI host
662 *
663 * Creates fc_lport struct and scsi_host for lport, configures lport
664 * and starts fabric login.
665 *
666 * Returns : The allocated fc_lport or an error pointer
667 */
668 static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
669 struct device *parent)
670 {
671 int rc;
672 struct fc_lport *lport = NULL;
673 struct fcoe_port *port;
674 struct Scsi_Host *shost;
675 struct net_device *netdev = fcoe->netdev;
676
677 FCOE_NETDEV_DBG(netdev, "Create Interface\n");
678
679 shost = libfc_host_alloc(&fcoe_shost_template,
680 sizeof(struct fcoe_port));
681 if (!shost) {
682 FCOE_NETDEV_DBG(netdev, "Could not allocate host structure\n");
683 rc = -ENOMEM;
684 goto out;
685 }
686 lport = shost_priv(shost);
687 port = lport_priv(lport);
688 port->fcoe = fcoe;
689
690 /* configure fc_lport, e.g., em */
691 rc = fcoe_lport_config(lport);
692 if (rc) {
693 FCOE_NETDEV_DBG(netdev, "Could not configure lport for the "
694 "interface\n");
695 goto out_host_put;
696 }
697
698 /*
699 * Initialize FIP.
700 */
701 fcoe_ctlr_init(&fcoe->ctlr);
702 fcoe->ctlr.send = fcoe_fip_send;
703 fcoe->ctlr.update_mac = fcoe_update_src_mac;
704
705 /* configure lport network properties */
706 rc = fcoe_netdev_config(lport, netdev);
707 if (rc) {
708 FCOE_NETDEV_DBG(netdev, "Could not configure netdev for the "
709 "interface\n");
710 goto out_netdev_cleanup;
711 }
712
713 /* configure lport scsi host properties */
714 rc = fcoe_shost_config(lport, shost, parent);
715 if (rc) {
716 FCOE_NETDEV_DBG(netdev, "Could not configure shost for the "
717 "interface\n");
718 goto out_netdev_cleanup;
719 }
720
721 /* Initialize the library */
722 rc = fcoe_libfc_config(lport, &fcoe_libfc_fcn_templ);
723 if (rc) {
724 FCOE_NETDEV_DBG(netdev, "Could not configure libfc for the "
725 "interface\n");
726 goto out_lp_destroy;
727 }
728
729 /*
730 * fcoe_em_alloc() and fcoe_hostlist_add() both
731 * need to be atomic under fcoe_hostlist_lock
732 * since fcoe_em_alloc() looks for an existing EM
733 * instance on host list updated by fcoe_hostlist_add().
734 */
735 write_lock(&fcoe_hostlist_lock);
736 /* lport exch manager allocation */
737 rc = fcoe_em_config(lport);
738 if (rc) {
739 FCOE_NETDEV_DBG(netdev, "Could not configure the EM for the "
740 "interface\n");
741 goto out_lp_destroy;
742 }
743
744 /* add to lports list */
745 fcoe_hostlist_add(lport);
746 write_unlock(&fcoe_hostlist_lock);
747
748 lport->boot_time = jiffies;
749
750 fc_fabric_login(lport);
751
752 if (!fcoe_link_ok(lport))
753 fcoe_ctlr_link_up(&fcoe->ctlr);
754
755 dev_hold(netdev);
756 fcoe_interface_get(fcoe);
757 return lport;
758
759 out_lp_destroy:
760 fc_exch_mgr_free(lport);
761 out_netdev_cleanup:
762 fcoe_netdev_cleanup(port);
763 out_host_put:
764 scsi_host_put(lport->host);
765 out:
766 return ERR_PTR(rc);
767 }
768
769 /**
770 * fcoe_if_init() - attach to scsi transport
771 *
772 * Returns : 0 on success
773 */
774 static int __init fcoe_if_init(void)
775 {
776 /* attach to scsi transport */
777 scsi_transport_fcoe_sw =
778 fc_attach_transport(&fcoe_transport_function);
779
780 if (!scsi_transport_fcoe_sw) {
781 printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n");
782 return -ENODEV;
783 }
784
785 return 0;
786 }
787
788 /**
789 * fcoe_if_exit() - detach from scsi transport
790 *
791 * Returns : 0 on success
792 */
793 int __exit fcoe_if_exit(void)
794 {
795 fc_release_transport(scsi_transport_fcoe_sw);
796 return 0;
797 }
798
799 /**
800 * fcoe_percpu_thread_create() - Create a receive thread for an online cpu
801 * @cpu: cpu index for the online cpu
802 */
803 static void fcoe_percpu_thread_create(unsigned int cpu)
804 {
805 struct fcoe_percpu_s *p;
806 struct task_struct *thread;
807
808 p = &per_cpu(fcoe_percpu, cpu);
809
810 thread = kthread_create(fcoe_percpu_receive_thread,
811 (void *)p, "fcoethread/%d", cpu);
812
813 if (likely(!IS_ERR(p->thread))) {
814 kthread_bind(thread, cpu);
815 wake_up_process(thread);
816
817 spin_lock_bh(&p->fcoe_rx_list.lock);
818 p->thread = thread;
819 spin_unlock_bh(&p->fcoe_rx_list.lock);
820 }
821 }
822
823 /**
824 * fcoe_percpu_thread_destroy() - removes the rx thread for the given cpu
825 * @cpu: cpu index the rx thread is to be removed
826 *
827 * Destroys a per-CPU Rx thread. Any pending skbs are moved to the
828 * current CPU's Rx thread. If the thread being destroyed is bound to
829 * the CPU processing this context the skbs will be freed.
830 */
831 static void fcoe_percpu_thread_destroy(unsigned int cpu)
832 {
833 struct fcoe_percpu_s *p;
834 struct task_struct *thread;
835 struct page *crc_eof;
836 struct sk_buff *skb;
837 #ifdef CONFIG_SMP
838 struct fcoe_percpu_s *p0;
839 unsigned targ_cpu = smp_processor_id();
840 #endif /* CONFIG_SMP */
841
842 FCOE_DBG("Destroying receive thread for CPU %d\n", cpu);
843
844 /* Prevent any new skbs from being queued for this CPU. */
845 p = &per_cpu(fcoe_percpu, cpu);
846 spin_lock_bh(&p->fcoe_rx_list.lock);
847 thread = p->thread;
848 p->thread = NULL;
849 crc_eof = p->crc_eof_page;
850 p->crc_eof_page = NULL;
851 p->crc_eof_offset = 0;
852 spin_unlock_bh(&p->fcoe_rx_list.lock);
853
854 #ifdef CONFIG_SMP
855 /*
856 * Don't bother moving the skb's if this context is running
857 * on the same CPU that is having its thread destroyed. This
858 * can easily happen when the module is removed.
859 */
860 if (cpu != targ_cpu) {
861 p0 = &per_cpu(fcoe_percpu, targ_cpu);
862 spin_lock_bh(&p0->fcoe_rx_list.lock);
863 if (p0->thread) {
864 FCOE_DBG("Moving frames from CPU %d to CPU %d\n",
865 cpu, targ_cpu);
866
867 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
868 __skb_queue_tail(&p0->fcoe_rx_list, skb);
869 spin_unlock_bh(&p0->fcoe_rx_list.lock);
870 } else {
871 /*
872 * The targeted CPU is not initialized and cannot accept
873 * new skbs. Unlock the targeted CPU and drop the skbs
874 * on the CPU that is going offline.
875 */
876 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
877 kfree_skb(skb);
878 spin_unlock_bh(&p0->fcoe_rx_list.lock);
879 }
880 } else {
881 /*
882 * This scenario occurs when the module is being removed
883 * and all threads are being destroyed. skbs will continue
884 * to be shifted from the CPU thread that is being removed
885 * to the CPU thread associated with the CPU that is processing
886 * the module removal. Once there is only one CPU Rx thread it
887 * will reach this case and we will drop all skbs and later
888 * stop the thread.
889 */
890 spin_lock_bh(&p->fcoe_rx_list.lock);
891 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
892 kfree_skb(skb);
893 spin_unlock_bh(&p->fcoe_rx_list.lock);
894 }
895 #else
896 /*
897 * This a non-SMP scenario where the singular Rx thread is
898 * being removed. Free all skbs and stop the thread.
899 */
900 spin_lock_bh(&p->fcoe_rx_list.lock);
901 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
902 kfree_skb(skb);
903 spin_unlock_bh(&p->fcoe_rx_list.lock);
904 #endif
905
906 if (thread)
907 kthread_stop(thread);
908
909 if (crc_eof)
910 put_page(crc_eof);
911 }
912
913 /**
914 * fcoe_cpu_callback() - fcoe cpu hotplug event callback
915 * @nfb: callback data block
916 * @action: event triggering the callback
917 * @hcpu: index for the cpu of this event
918 *
919 * This creates or destroys per cpu data for fcoe
920 *
921 * Returns NOTIFY_OK always.
922 */
923 static int fcoe_cpu_callback(struct notifier_block *nfb,
924 unsigned long action, void *hcpu)
925 {
926 unsigned cpu = (unsigned long)hcpu;
927
928 switch (action) {
929 case CPU_ONLINE:
930 case CPU_ONLINE_FROZEN:
931 FCOE_DBG("CPU %x online: Create Rx thread\n", cpu);
932 fcoe_percpu_thread_create(cpu);
933 break;
934 case CPU_DEAD:
935 case CPU_DEAD_FROZEN:
936 FCOE_DBG("CPU %x offline: Remove Rx thread\n", cpu);
937 fcoe_percpu_thread_destroy(cpu);
938 break;
939 default:
940 break;
941 }
942 return NOTIFY_OK;
943 }
944
945 static struct notifier_block fcoe_cpu_notifier = {
946 .notifier_call = fcoe_cpu_callback,
947 };
948
949 /**
950 * fcoe_rcv() - this is the fcoe receive function called by NET_RX_SOFTIRQ
951 * @skb: the receive skb
952 * @dev: associated net device
953 * @ptype: context
954 * @olddev: last device
955 *
956 * this function will receive the packet and build fc frame and pass it up
957 *
958 * Returns: 0 for success
959 */
960 int fcoe_rcv(struct sk_buff *skb, struct net_device *dev,
961 struct packet_type *ptype, struct net_device *olddev)
962 {
963 struct fc_lport *lp;
964 struct fcoe_rcv_info *fr;
965 struct fcoe_interface *fcoe;
966 struct fc_frame_header *fh;
967 struct fcoe_percpu_s *fps;
968 unsigned int cpu;
969
970 fcoe = container_of(ptype, struct fcoe_interface, fcoe_packet_type);
971 lp = fcoe->ctlr.lp;
972 if (unlikely(lp == NULL)) {
973 FCOE_NETDEV_DBG(dev, "Cannot find hba structure");
974 goto err2;
975 }
976 if (!lp->link_up)
977 goto err2;
978
979 FCOE_NETDEV_DBG(dev, "skb_info: len:%d data_len:%d head:%p "
980 "data:%p tail:%p end:%p sum:%d dev:%s",
981 skb->len, skb->data_len, skb->head, skb->data,
982 skb_tail_pointer(skb), skb_end_pointer(skb),
983 skb->csum, skb->dev ? skb->dev->name : "<NULL>");
984
985 /* check for FCOE packet type */
986 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
987 FCOE_NETDEV_DBG(dev, "Wrong FC type frame");
988 goto err;
989 }
990
991 /*
992 * Check for minimum frame length, and make sure required FCoE
993 * and FC headers are pulled into the linear data area.
994 */
995 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
996 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
997 goto err;
998
999 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
1000 fh = (struct fc_frame_header *) skb_transport_header(skb);
1001
1002 fr = fcoe_dev_from_skb(skb);
1003 fr->fr_dev = lp;
1004 fr->ptype = ptype;
1005
1006 /*
1007 * In case the incoming frame's exchange is originated from
1008 * the initiator, then received frame's exchange id is ANDed
1009 * with fc_cpu_mask bits to get the same cpu on which exchange
1010 * was originated, otherwise just use the current cpu.
1011 */
1012 if (ntoh24(fh->fh_f_ctl) & FC_FC_EX_CTX)
1013 cpu = ntohs(fh->fh_ox_id) & fc_cpu_mask;
1014 else
1015 cpu = smp_processor_id();
1016
1017 fps = &per_cpu(fcoe_percpu, cpu);
1018 spin_lock_bh(&fps->fcoe_rx_list.lock);
1019 if (unlikely(!fps->thread)) {
1020 /*
1021 * The targeted CPU is not ready, let's target
1022 * the first CPU now. For non-SMP systems this
1023 * will check the same CPU twice.
1024 */
1025 FCOE_NETDEV_DBG(dev, "CPU is online, but no receive thread "
1026 "ready for incoming skb- using first online "
1027 "CPU.\n");
1028
1029 spin_unlock_bh(&fps->fcoe_rx_list.lock);
1030 cpu = first_cpu(cpu_online_map);
1031 fps = &per_cpu(fcoe_percpu, cpu);
1032 spin_lock_bh(&fps->fcoe_rx_list.lock);
1033 if (!fps->thread) {
1034 spin_unlock_bh(&fps->fcoe_rx_list.lock);
1035 goto err;
1036 }
1037 }
1038
1039 /*
1040 * We now have a valid CPU that we're targeting for
1041 * this skb. We also have this receive thread locked,
1042 * so we're free to queue skbs into it's queue.
1043 */
1044 __skb_queue_tail(&fps->fcoe_rx_list, skb);
1045 if (fps->fcoe_rx_list.qlen == 1)
1046 wake_up_process(fps->thread);
1047
1048 spin_unlock_bh(&fps->fcoe_rx_list.lock);
1049
1050 return 0;
1051 err:
1052 fc_lport_get_stats(lp)->ErrorFrames++;
1053
1054 err2:
1055 kfree_skb(skb);
1056 return -1;
1057 }
1058
1059 /**
1060 * fcoe_start_io() - pass to netdev to start xmit for fcoe
1061 * @skb: the skb to be xmitted
1062 *
1063 * Returns: 0 for success
1064 */
1065 static inline int fcoe_start_io(struct sk_buff *skb)
1066 {
1067 int rc;
1068
1069 skb_get(skb);
1070 rc = dev_queue_xmit(skb);
1071 if (rc != 0)
1072 return rc;
1073 kfree_skb(skb);
1074 return 0;
1075 }
1076
1077 /**
1078 * fcoe_get_paged_crc_eof() - in case we need to alloc a page for crc_eof
1079 * @skb: the skb to be xmitted
1080 * @tlen: total len
1081 *
1082 * Returns: 0 for success
1083 */
1084 static int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen)
1085 {
1086 struct fcoe_percpu_s *fps;
1087 struct page *page;
1088
1089 fps = &get_cpu_var(fcoe_percpu);
1090 page = fps->crc_eof_page;
1091 if (!page) {
1092 page = alloc_page(GFP_ATOMIC);
1093 if (!page) {
1094 put_cpu_var(fcoe_percpu);
1095 return -ENOMEM;
1096 }
1097 fps->crc_eof_page = page;
1098 fps->crc_eof_offset = 0;
1099 }
1100
1101 get_page(page);
1102 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page,
1103 fps->crc_eof_offset, tlen);
1104 skb->len += tlen;
1105 skb->data_len += tlen;
1106 skb->truesize += tlen;
1107 fps->crc_eof_offset += sizeof(struct fcoe_crc_eof);
1108
1109 if (fps->crc_eof_offset >= PAGE_SIZE) {
1110 fps->crc_eof_page = NULL;
1111 fps->crc_eof_offset = 0;
1112 put_page(page);
1113 }
1114 put_cpu_var(fcoe_percpu);
1115 return 0;
1116 }
1117
1118 /**
1119 * fcoe_fc_crc() - calculates FC CRC in this fcoe skb
1120 * @fp: the fc_frame containing data to be checksummed
1121 *
1122 * This uses crc32() to calculate the crc for port frame
1123 * Return : 32 bit crc
1124 */
1125 u32 fcoe_fc_crc(struct fc_frame *fp)
1126 {
1127 struct sk_buff *skb = fp_skb(fp);
1128 struct skb_frag_struct *frag;
1129 unsigned char *data;
1130 unsigned long off, len, clen;
1131 u32 crc;
1132 unsigned i;
1133
1134 crc = crc32(~0, skb->data, skb_headlen(skb));
1135
1136 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1137 frag = &skb_shinfo(skb)->frags[i];
1138 off = frag->page_offset;
1139 len = frag->size;
1140 while (len > 0) {
1141 clen = min(len, PAGE_SIZE - (off & ~PAGE_MASK));
1142 data = kmap_atomic(frag->page + (off >> PAGE_SHIFT),
1143 KM_SKB_DATA_SOFTIRQ);
1144 crc = crc32(crc, data + (off & ~PAGE_MASK), clen);
1145 kunmap_atomic(data, KM_SKB_DATA_SOFTIRQ);
1146 off += clen;
1147 len -= clen;
1148 }
1149 }
1150 return crc;
1151 }
1152
1153 /**
1154 * fcoe_xmit() - FCoE frame transmit function
1155 * @lp: the associated local fcoe
1156 * @fp: the fc_frame to be transmitted
1157 *
1158 * Return : 0 for success
1159 */
1160 int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp)
1161 {
1162 int wlen;
1163 u32 crc;
1164 struct ethhdr *eh;
1165 struct fcoe_crc_eof *cp;
1166 struct sk_buff *skb;
1167 struct fcoe_dev_stats *stats;
1168 struct fc_frame_header *fh;
1169 unsigned int hlen; /* header length implies the version */
1170 unsigned int tlen; /* trailer length */
1171 unsigned int elen; /* eth header, may include vlan */
1172 struct fcoe_port *port = lport_priv(lp);
1173 struct fcoe_interface *fcoe = port->fcoe;
1174 u8 sof, eof;
1175 struct fcoe_hdr *hp;
1176
1177 WARN_ON((fr_len(fp) % sizeof(u32)) != 0);
1178
1179 fh = fc_frame_header_get(fp);
1180 skb = fp_skb(fp);
1181 wlen = skb->len / FCOE_WORD_TO_BYTE;
1182
1183 if (!lp->link_up) {
1184 kfree_skb(skb);
1185 return 0;
1186 }
1187
1188 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ) &&
1189 fcoe_ctlr_els_send(&fcoe->ctlr, skb))
1190 return 0;
1191
1192 sof = fr_sof(fp);
1193 eof = fr_eof(fp);
1194
1195 elen = sizeof(struct ethhdr);
1196 hlen = sizeof(struct fcoe_hdr);
1197 tlen = sizeof(struct fcoe_crc_eof);
1198 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
1199
1200 /* crc offload */
1201 if (likely(lp->crc_offload)) {
1202 skb->ip_summed = CHECKSUM_PARTIAL;
1203 skb->csum_start = skb_headroom(skb);
1204 skb->csum_offset = skb->len;
1205 crc = 0;
1206 } else {
1207 skb->ip_summed = CHECKSUM_NONE;
1208 crc = fcoe_fc_crc(fp);
1209 }
1210
1211 /* copy port crc and eof to the skb buff */
1212 if (skb_is_nonlinear(skb)) {
1213 skb_frag_t *frag;
1214 if (fcoe_get_paged_crc_eof(skb, tlen)) {
1215 kfree_skb(skb);
1216 return -ENOMEM;
1217 }
1218 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
1219 cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ)
1220 + frag->page_offset;
1221 } else {
1222 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
1223 }
1224
1225 memset(cp, 0, sizeof(*cp));
1226 cp->fcoe_eof = eof;
1227 cp->fcoe_crc32 = cpu_to_le32(~crc);
1228
1229 if (skb_is_nonlinear(skb)) {
1230 kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ);
1231 cp = NULL;
1232 }
1233
1234 /* adjust skb network/transport offsets to match mac/fcoe/port */
1235 skb_push(skb, elen + hlen);
1236 skb_reset_mac_header(skb);
1237 skb_reset_network_header(skb);
1238 skb->mac_len = elen;
1239 skb->protocol = htons(ETH_P_FCOE);
1240 skb->dev = fcoe->netdev;
1241
1242 /* fill up mac and fcoe headers */
1243 eh = eth_hdr(skb);
1244 eh->h_proto = htons(ETH_P_FCOE);
1245 if (fcoe->ctlr.map_dest)
1246 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
1247 else
1248 /* insert GW address */
1249 memcpy(eh->h_dest, fcoe->ctlr.dest_addr, ETH_ALEN);
1250
1251 if (unlikely(fcoe->ctlr.flogi_oxid != FC_XID_UNKNOWN))
1252 memcpy(eh->h_source, fcoe->ctlr.ctl_src_addr, ETH_ALEN);
1253 else
1254 memcpy(eh->h_source, fcoe->ctlr.data_src_addr, ETH_ALEN);
1255
1256 hp = (struct fcoe_hdr *)(eh + 1);
1257 memset(hp, 0, sizeof(*hp));
1258 if (FC_FCOE_VER)
1259 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
1260 hp->fcoe_sof = sof;
1261
1262 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
1263 if (lp->seq_offload && fr_max_payload(fp)) {
1264 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
1265 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
1266 } else {
1267 skb_shinfo(skb)->gso_type = 0;
1268 skb_shinfo(skb)->gso_size = 0;
1269 }
1270 /* update tx stats: regardless if LLD fails */
1271 stats = fc_lport_get_stats(lp);
1272 stats->TxFrames++;
1273 stats->TxWords += wlen;
1274
1275 /* send down to lld */
1276 fr_dev(fp) = lp;
1277 if (port->fcoe_pending_queue.qlen)
1278 fcoe_check_wait_queue(lp, skb);
1279 else if (fcoe_start_io(skb))
1280 fcoe_check_wait_queue(lp, skb);
1281
1282 return 0;
1283 }
1284
1285 /**
1286 * fcoe_percpu_receive_thread() - recv thread per cpu
1287 * @arg: ptr to the fcoe per cpu struct
1288 *
1289 * Return: 0 for success
1290 */
1291 int fcoe_percpu_receive_thread(void *arg)
1292 {
1293 struct fcoe_percpu_s *p = arg;
1294 u32 fr_len;
1295 struct fc_lport *lp;
1296 struct fcoe_rcv_info *fr;
1297 struct fcoe_dev_stats *stats;
1298 struct fc_frame_header *fh;
1299 struct sk_buff *skb;
1300 struct fcoe_crc_eof crc_eof;
1301 struct fc_frame *fp;
1302 u8 *mac = NULL;
1303 struct fcoe_port *port;
1304 struct fcoe_hdr *hp;
1305
1306 set_user_nice(current, -20);
1307
1308 while (!kthread_should_stop()) {
1309
1310 spin_lock_bh(&p->fcoe_rx_list.lock);
1311 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) == NULL) {
1312 set_current_state(TASK_INTERRUPTIBLE);
1313 spin_unlock_bh(&p->fcoe_rx_list.lock);
1314 schedule();
1315 set_current_state(TASK_RUNNING);
1316 if (kthread_should_stop())
1317 return 0;
1318 spin_lock_bh(&p->fcoe_rx_list.lock);
1319 }
1320 spin_unlock_bh(&p->fcoe_rx_list.lock);
1321 fr = fcoe_dev_from_skb(skb);
1322 lp = fr->fr_dev;
1323 if (unlikely(lp == NULL)) {
1324 FCOE_NETDEV_DBG(skb->dev, "Invalid HBA Structure");
1325 kfree_skb(skb);
1326 continue;
1327 }
1328
1329 FCOE_NETDEV_DBG(skb->dev, "skb_info: len:%d data_len:%d "
1330 "head:%p data:%p tail:%p end:%p sum:%d dev:%s",
1331 skb->len, skb->data_len,
1332 skb->head, skb->data, skb_tail_pointer(skb),
1333 skb_end_pointer(skb), skb->csum,
1334 skb->dev ? skb->dev->name : "<NULL>");
1335
1336 /*
1337 * Save source MAC address before discarding header.
1338 */
1339 port = lport_priv(lp);
1340 if (skb_is_nonlinear(skb))
1341 skb_linearize(skb); /* not ideal */
1342 mac = eth_hdr(skb)->h_source;
1343
1344 /*
1345 * Frame length checks and setting up the header pointers
1346 * was done in fcoe_rcv already.
1347 */
1348 hp = (struct fcoe_hdr *) skb_network_header(skb);
1349 fh = (struct fc_frame_header *) skb_transport_header(skb);
1350
1351 stats = fc_lport_get_stats(lp);
1352 if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) {
1353 if (stats->ErrorFrames < 5)
1354 printk(KERN_WARNING "fcoe: FCoE version "
1355 "mismatch: The frame has "
1356 "version %x, but the "
1357 "initiator supports version "
1358 "%x\n", FC_FCOE_DECAPS_VER(hp),
1359 FC_FCOE_VER);
1360 stats->ErrorFrames++;
1361 kfree_skb(skb);
1362 continue;
1363 }
1364
1365 skb_pull(skb, sizeof(struct fcoe_hdr));
1366 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
1367
1368 stats->RxFrames++;
1369 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
1370
1371 fp = (struct fc_frame *)skb;
1372 fc_frame_init(fp);
1373 fr_dev(fp) = lp;
1374 fr_sof(fp) = hp->fcoe_sof;
1375
1376 /* Copy out the CRC and EOF trailer for access */
1377 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
1378 kfree_skb(skb);
1379 continue;
1380 }
1381 fr_eof(fp) = crc_eof.fcoe_eof;
1382 fr_crc(fp) = crc_eof.fcoe_crc32;
1383 if (pskb_trim(skb, fr_len)) {
1384 kfree_skb(skb);
1385 continue;
1386 }
1387
1388 /*
1389 * We only check CRC if no offload is available and if it is
1390 * it's solicited data, in which case, the FCP layer would
1391 * check it during the copy.
1392 */
1393 if (lp->crc_offload && skb->ip_summed == CHECKSUM_UNNECESSARY)
1394 fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
1395 else
1396 fr_flags(fp) |= FCPHF_CRC_UNCHECKED;
1397
1398 fh = fc_frame_header_get(fp);
1399 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
1400 fh->fh_type == FC_TYPE_FCP) {
1401 fc_exch_recv(lp, fp);
1402 continue;
1403 }
1404 if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) {
1405 if (le32_to_cpu(fr_crc(fp)) !=
1406 ~crc32(~0, skb->data, fr_len)) {
1407 if (stats->InvalidCRCCount < 5)
1408 printk(KERN_WARNING "fcoe: dropping "
1409 "frame with CRC error\n");
1410 stats->InvalidCRCCount++;
1411 stats->ErrorFrames++;
1412 fc_frame_free(fp);
1413 continue;
1414 }
1415 fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
1416 }
1417 if (unlikely(port->fcoe->ctlr.flogi_oxid != FC_XID_UNKNOWN) &&
1418 fcoe_ctlr_recv_flogi(&port->fcoe->ctlr, fp, mac)) {
1419 fc_frame_free(fp);
1420 continue;
1421 }
1422 fc_exch_recv(lp, fp);
1423 }
1424 return 0;
1425 }
1426
1427 /**
1428 * fcoe_check_wait_queue() - attempt to clear the transmit backlog
1429 * @lp: the fc_lport
1430 *
1431 * This empties the wait_queue, dequeue the head of the wait_queue queue
1432 * and calls fcoe_start_io() for each packet, if all skb have been
1433 * transmitted, return qlen or -1 if a error occurs, then restore
1434 * wait_queue and try again later.
1435 *
1436 * The wait_queue is used when the skb transmit fails. skb will go
1437 * in the wait_queue which will be emptied by the timer function or
1438 * by the next skb transmit.
1439 */
1440 static void fcoe_check_wait_queue(struct fc_lport *lp, struct sk_buff *skb)
1441 {
1442 struct fcoe_port *port = lport_priv(lp);
1443 int rc;
1444
1445 spin_lock_bh(&port->fcoe_pending_queue.lock);
1446
1447 if (skb)
1448 __skb_queue_tail(&port->fcoe_pending_queue, skb);
1449
1450 if (port->fcoe_pending_queue_active)
1451 goto out;
1452 port->fcoe_pending_queue_active = 1;
1453
1454 while (port->fcoe_pending_queue.qlen) {
1455 /* keep qlen > 0 until fcoe_start_io succeeds */
1456 port->fcoe_pending_queue.qlen++;
1457 skb = __skb_dequeue(&port->fcoe_pending_queue);
1458
1459 spin_unlock_bh(&port->fcoe_pending_queue.lock);
1460 rc = fcoe_start_io(skb);
1461 spin_lock_bh(&port->fcoe_pending_queue.lock);
1462
1463 if (rc) {
1464 __skb_queue_head(&port->fcoe_pending_queue, skb);
1465 /* undo temporary increment above */
1466 port->fcoe_pending_queue.qlen--;
1467 break;
1468 }
1469 /* undo temporary increment above */
1470 port->fcoe_pending_queue.qlen--;
1471 }
1472
1473 if (port->fcoe_pending_queue.qlen < FCOE_LOW_QUEUE_DEPTH)
1474 lp->qfull = 0;
1475 if (port->fcoe_pending_queue.qlen && !timer_pending(&port->timer))
1476 mod_timer(&port->timer, jiffies + 2);
1477 port->fcoe_pending_queue_active = 0;
1478 out:
1479 if (port->fcoe_pending_queue.qlen > FCOE_MAX_QUEUE_DEPTH)
1480 lp->qfull = 1;
1481 spin_unlock_bh(&port->fcoe_pending_queue.lock);
1482 return;
1483 }
1484
1485 /**
1486 * fcoe_dev_setup() - setup link change notification interface
1487 */
1488 static void fcoe_dev_setup(void)
1489 {
1490 register_netdevice_notifier(&fcoe_notifier);
1491 }
1492
1493 /**
1494 * fcoe_dev_cleanup() - cleanup link change notification interface
1495 */
1496 static void fcoe_dev_cleanup(void)
1497 {
1498 unregister_netdevice_notifier(&fcoe_notifier);
1499 }
1500
1501 /**
1502 * fcoe_device_notification() - netdev event notification callback
1503 * @notifier: context of the notification
1504 * @event: type of event
1505 * @ptr: fixed array for output parsed ifname
1506 *
1507 * This function is called by the ethernet driver in case of link change event
1508 *
1509 * Returns: 0 for success
1510 */
1511 static int fcoe_device_notification(struct notifier_block *notifier,
1512 ulong event, void *ptr)
1513 {
1514 struct fc_lport *lp = NULL;
1515 struct net_device *netdev = ptr;
1516 struct fcoe_interface *fcoe;
1517 struct fcoe_dev_stats *stats;
1518 u32 link_possible = 1;
1519 u32 mfs;
1520 int rc = NOTIFY_OK;
1521
1522 read_lock(&fcoe_hostlist_lock);
1523 list_for_each_entry(fcoe, &fcoe_hostlist, list) {
1524 if (fcoe->netdev == netdev) {
1525 lp = fcoe->ctlr.lp;
1526 break;
1527 }
1528 }
1529 read_unlock(&fcoe_hostlist_lock);
1530 if (lp == NULL) {
1531 rc = NOTIFY_DONE;
1532 goto out;
1533 }
1534
1535 switch (event) {
1536 case NETDEV_DOWN:
1537 case NETDEV_GOING_DOWN:
1538 link_possible = 0;
1539 break;
1540 case NETDEV_UP:
1541 case NETDEV_CHANGE:
1542 break;
1543 case NETDEV_CHANGEMTU:
1544 mfs = netdev->mtu - (sizeof(struct fcoe_hdr) +
1545 sizeof(struct fcoe_crc_eof));
1546 if (mfs >= FC_MIN_MAX_FRAME)
1547 fc_set_mfs(lp, mfs);
1548 break;
1549 case NETDEV_REGISTER:
1550 break;
1551 default:
1552 FCOE_NETDEV_DBG(netdev, "Unknown event %ld "
1553 "from netdev netlink\n", event);
1554 }
1555 if (link_possible && !fcoe_link_ok(lp))
1556 fcoe_ctlr_link_up(&fcoe->ctlr);
1557 else if (fcoe_ctlr_link_down(&fcoe->ctlr)) {
1558 stats = fc_lport_get_stats(lp);
1559 stats->LinkFailureCount++;
1560 fcoe_clean_pending_queue(lp);
1561 }
1562 out:
1563 return rc;
1564 }
1565
1566 /**
1567 * fcoe_if_to_netdev() - parse a name buffer to get netdev
1568 * @buffer: incoming buffer to be copied
1569 *
1570 * Returns: NULL or ptr to net_device
1571 */
1572 static struct net_device *fcoe_if_to_netdev(const char *buffer)
1573 {
1574 char *cp;
1575 char ifname[IFNAMSIZ + 2];
1576
1577 if (buffer) {
1578 strlcpy(ifname, buffer, IFNAMSIZ);
1579 cp = ifname + strlen(ifname);
1580 while (--cp >= ifname && *cp == '\n')
1581 *cp = '\0';
1582 return dev_get_by_name(&init_net, ifname);
1583 }
1584 return NULL;
1585 }
1586
1587 /**
1588 * fcoe_netdev_to_module_owner() - finds out the driver module of the netdev
1589 * @netdev: the target netdev
1590 *
1591 * Returns: ptr to the struct module, NULL for failure
1592 */
1593 static struct module *
1594 fcoe_netdev_to_module_owner(const struct net_device *netdev)
1595 {
1596 struct device *dev;
1597
1598 if (!netdev)
1599 return NULL;
1600
1601 dev = netdev->dev.parent;
1602 if (!dev)
1603 return NULL;
1604
1605 if (!dev->driver)
1606 return NULL;
1607
1608 return dev->driver->owner;
1609 }
1610
1611 /**
1612 * fcoe_ethdrv_get() - Hold the Ethernet driver
1613 * @netdev: the target netdev
1614 *
1615 * Holds the Ethernet driver module by try_module_get() for
1616 * the corresponding netdev.
1617 *
1618 * Returns: 0 for success
1619 */
1620 static int fcoe_ethdrv_get(const struct net_device *netdev)
1621 {
1622 struct module *owner;
1623
1624 owner = fcoe_netdev_to_module_owner(netdev);
1625 if (owner) {
1626 FCOE_NETDEV_DBG(netdev, "Hold driver module %s\n",
1627 module_name(owner));
1628 return try_module_get(owner);
1629 }
1630 return -ENODEV;
1631 }
1632
1633 /**
1634 * fcoe_ethdrv_put() - Release the Ethernet driver
1635 * @netdev: the target netdev
1636 *
1637 * Releases the Ethernet driver module by module_put for
1638 * the corresponding netdev.
1639 *
1640 * Returns: 0 for success
1641 */
1642 static int fcoe_ethdrv_put(const struct net_device *netdev)
1643 {
1644 struct module *owner;
1645
1646 owner = fcoe_netdev_to_module_owner(netdev);
1647 if (owner) {
1648 FCOE_NETDEV_DBG(netdev, "Release driver module %s\n",
1649 module_name(owner));
1650 module_put(owner);
1651 return 0;
1652 }
1653 return -ENODEV;
1654 }
1655
1656 /**
1657 * fcoe_destroy() - handles the destroy from sysfs
1658 * @buffer: expected to be an eth if name
1659 * @kp: associated kernel param
1660 *
1661 * Returns: 0 for success
1662 */
1663 static int fcoe_destroy(const char *buffer, struct kernel_param *kp)
1664 {
1665 struct net_device *netdev;
1666 struct fcoe_interface *fcoe;
1667 struct fcoe_port *port;
1668 struct fc_lport *lport;
1669 int rc;
1670
1671 netdev = fcoe_if_to_netdev(buffer);
1672 if (!netdev) {
1673 rc = -ENODEV;
1674 goto out_nodev;
1675 }
1676 /* look for existing lport */
1677 lport = fcoe_hostlist_lookup(netdev);
1678 if (!lport) {
1679 rc = -ENODEV;
1680 goto out_putdev;
1681 }
1682 port = lport_priv(lport);
1683 fcoe = port->fcoe;
1684 fcoe_if_destroy(lport);
1685 fcoe_ethdrv_put(netdev);
1686 rc = 0;
1687 out_putdev:
1688 dev_put(netdev);
1689 out_nodev:
1690 return rc;
1691 }
1692
1693 /**
1694 * fcoe_create() - Handles the create call from sysfs
1695 * @buffer: expected to be an eth if name
1696 * @kp: associated kernel param
1697 *
1698 * Returns: 0 for success
1699 */
1700 static int fcoe_create(const char *buffer, struct kernel_param *kp)
1701 {
1702 int rc;
1703 struct fcoe_interface *fcoe;
1704 struct fc_lport *lport;
1705 struct net_device *netdev;
1706
1707 netdev = fcoe_if_to_netdev(buffer);
1708 if (!netdev) {
1709 rc = -ENODEV;
1710 goto out_nodev;
1711 }
1712 /* look for existing lport */
1713 if (fcoe_hostlist_lookup(netdev)) {
1714 rc = -EEXIST;
1715 goto out_putdev;
1716 }
1717 fcoe_ethdrv_get(netdev);
1718
1719 fcoe = fcoe_interface_create(netdev);
1720 if (!fcoe) {
1721 rc = -ENOMEM;
1722 goto out_putdev;
1723 }
1724
1725 lport = fcoe_if_create(fcoe, &netdev->dev);
1726 if (IS_ERR(lport)) {
1727 printk(KERN_ERR "fcoe: Failed to create interface (%s)\n",
1728 netdev->name);
1729 fcoe_ethdrv_put(netdev);
1730 rc = -EIO;
1731 goto out_free;
1732 }
1733
1734 dev_put(netdev);
1735 return 0;
1736
1737 out_free:
1738 fcoe_interface_put(fcoe);
1739 out_putdev:
1740 dev_put(netdev);
1741 out_nodev:
1742 return rc;
1743 }
1744
1745 module_param_call(create, fcoe_create, NULL, NULL, S_IWUSR);
1746 __MODULE_PARM_TYPE(create, "string");
1747 MODULE_PARM_DESC(create, "Create fcoe fcoe using net device passed in.");
1748 module_param_call(destroy, fcoe_destroy, NULL, NULL, S_IWUSR);
1749 __MODULE_PARM_TYPE(destroy, "string");
1750 MODULE_PARM_DESC(destroy, "Destroy fcoe fcoe");
1751
1752 /**
1753 * fcoe_link_ok() - Check if link is ok for the fc_lport
1754 * @lp: ptr to the fc_lport
1755 *
1756 * Any permanently-disqualifying conditions have been previously checked.
1757 * This also updates the speed setting, which may change with link for 100/1000.
1758 *
1759 * This function should probably be checking for PAUSE support at some point
1760 * in the future. Currently Per-priority-pause is not determinable using
1761 * ethtool, so we shouldn't be restrictive until that problem is resolved.
1762 *
1763 * Returns: 0 if link is OK for use by FCoE.
1764 *
1765 */
1766 int fcoe_link_ok(struct fc_lport *lp)
1767 {
1768 struct fcoe_port *port = lport_priv(lp);
1769 struct net_device *dev = port->fcoe->netdev;
1770 struct ethtool_cmd ecmd = { ETHTOOL_GSET };
1771
1772 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev) &&
1773 (!dev_ethtool_get_settings(dev, &ecmd))) {
1774 lp->link_supported_speeds &=
1775 ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
1776 if (ecmd.supported & (SUPPORTED_1000baseT_Half |
1777 SUPPORTED_1000baseT_Full))
1778 lp->link_supported_speeds |= FC_PORTSPEED_1GBIT;
1779 if (ecmd.supported & SUPPORTED_10000baseT_Full)
1780 lp->link_supported_speeds |=
1781 FC_PORTSPEED_10GBIT;
1782 if (ecmd.speed == SPEED_1000)
1783 lp->link_speed = FC_PORTSPEED_1GBIT;
1784 if (ecmd.speed == SPEED_10000)
1785 lp->link_speed = FC_PORTSPEED_10GBIT;
1786
1787 return 0;
1788 }
1789 return -1;
1790 }
1791
1792 /**
1793 * fcoe_percpu_clean() - Clear the pending skbs for an lport
1794 * @lp: the fc_lport
1795 */
1796 void fcoe_percpu_clean(struct fc_lport *lp)
1797 {
1798 struct fcoe_percpu_s *pp;
1799 struct fcoe_rcv_info *fr;
1800 struct sk_buff_head *list;
1801 struct sk_buff *skb, *next;
1802 struct sk_buff *head;
1803 unsigned int cpu;
1804
1805 for_each_possible_cpu(cpu) {
1806 pp = &per_cpu(fcoe_percpu, cpu);
1807 spin_lock_bh(&pp->fcoe_rx_list.lock);
1808 list = &pp->fcoe_rx_list;
1809 head = list->next;
1810 for (skb = head; skb != (struct sk_buff *)list;
1811 skb = next) {
1812 next = skb->next;
1813 fr = fcoe_dev_from_skb(skb);
1814 if (fr->fr_dev == lp) {
1815 __skb_unlink(skb, list);
1816 kfree_skb(skb);
1817 }
1818 }
1819 spin_unlock_bh(&pp->fcoe_rx_list.lock);
1820 }
1821 }
1822
1823 /**
1824 * fcoe_clean_pending_queue() - Dequeue a skb and free it
1825 * @lp: the corresponding fc_lport
1826 *
1827 * Returns: none
1828 */
1829 void fcoe_clean_pending_queue(struct fc_lport *lp)
1830 {
1831 struct fcoe_port *port = lport_priv(lp);
1832 struct sk_buff *skb;
1833
1834 spin_lock_bh(&port->fcoe_pending_queue.lock);
1835 while ((skb = __skb_dequeue(&port->fcoe_pending_queue)) != NULL) {
1836 spin_unlock_bh(&port->fcoe_pending_queue.lock);
1837 kfree_skb(skb);
1838 spin_lock_bh(&port->fcoe_pending_queue.lock);
1839 }
1840 spin_unlock_bh(&port->fcoe_pending_queue.lock);
1841 }
1842
1843 /**
1844 * fcoe_reset() - Resets the fcoe
1845 * @shost: shost the reset is from
1846 *
1847 * Returns: always 0
1848 */
1849 int fcoe_reset(struct Scsi_Host *shost)
1850 {
1851 struct fc_lport *lport = shost_priv(shost);
1852 fc_lport_reset(lport);
1853 return 0;
1854 }
1855
1856 /**
1857 * fcoe_hostlist_lookup_port() - find the corresponding lport by a given device
1858 * @dev: this is currently ptr to net_device
1859 *
1860 * Called with fcoe_hostlist_lock held.
1861 *
1862 * Returns: NULL or the located fcoe_port
1863 */
1864 static struct fcoe_interface *
1865 fcoe_hostlist_lookup_port(const struct net_device *dev)
1866 {
1867 struct fcoe_interface *fcoe;
1868
1869 list_for_each_entry(fcoe, &fcoe_hostlist, list) {
1870 if (fcoe->netdev == dev)
1871 return fcoe;
1872 }
1873 return NULL;
1874 }
1875
1876 /**
1877 * fcoe_hostlist_lookup() - Find the corresponding lport by netdev
1878 * @netdev: ptr to net_device
1879 *
1880 * Returns: 0 for success
1881 */
1882 struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev)
1883 {
1884 struct fcoe_interface *fcoe;
1885
1886 read_lock(&fcoe_hostlist_lock);
1887 fcoe = fcoe_hostlist_lookup_port(netdev);
1888 read_unlock(&fcoe_hostlist_lock);
1889
1890 return (fcoe) ? fcoe->ctlr.lp : NULL;
1891 }
1892
1893 /**
1894 * fcoe_hostlist_add() - Add a lport to lports list
1895 * @lp: ptr to the fc_lport to be added
1896 *
1897 * Called with write fcoe_hostlist_lock held.
1898 *
1899 * Returns: 0 for success
1900 */
1901 int fcoe_hostlist_add(const struct fc_lport *lport)
1902 {
1903 struct fcoe_interface *fcoe;
1904 struct fcoe_port *port;
1905
1906 fcoe = fcoe_hostlist_lookup_port(fcoe_netdev(lport));
1907 if (!fcoe) {
1908 port = lport_priv(lport);
1909 fcoe = port->fcoe;
1910 list_add_tail(&fcoe->list, &fcoe_hostlist);
1911 }
1912 return 0;
1913 }
1914
1915 /**
1916 * fcoe_hostlist_remove() - remove a lport from lports list
1917 * @lp: ptr to the fc_lport to be removed
1918 *
1919 * Returns: 0 for success
1920 */
1921 int fcoe_hostlist_remove(const struct fc_lport *lport)
1922 {
1923 struct fcoe_interface *fcoe;
1924
1925 write_lock_bh(&fcoe_hostlist_lock);
1926 fcoe = fcoe_hostlist_lookup_port(fcoe_netdev(lport));
1927 BUG_ON(!fcoe);
1928 list_del(&fcoe->list);
1929 write_unlock_bh(&fcoe_hostlist_lock);
1930
1931 return 0;
1932 }
1933
1934 /**
1935 * fcoe_init() - fcoe module loading initialization
1936 *
1937 * Returns 0 on success, negative on failure
1938 */
1939 static int __init fcoe_init(void)
1940 {
1941 unsigned int cpu;
1942 int rc = 0;
1943 struct fcoe_percpu_s *p;
1944
1945 for_each_possible_cpu(cpu) {
1946 p = &per_cpu(fcoe_percpu, cpu);
1947 skb_queue_head_init(&p->fcoe_rx_list);
1948 }
1949
1950 for_each_online_cpu(cpu)
1951 fcoe_percpu_thread_create(cpu);
1952
1953 /* Initialize per CPU interrupt thread */
1954 rc = register_hotcpu_notifier(&fcoe_cpu_notifier);
1955 if (rc)
1956 goto out_free;
1957
1958 /* Setup link change notification */
1959 fcoe_dev_setup();
1960
1961 rc = fcoe_if_init();
1962 if (rc)
1963 goto out_free;
1964
1965 return 0;
1966
1967 out_free:
1968 for_each_online_cpu(cpu) {
1969 fcoe_percpu_thread_destroy(cpu);
1970 }
1971
1972 return rc;
1973 }
1974 module_init(fcoe_init);
1975
1976 /**
1977 * fcoe_exit() - fcoe module unloading cleanup
1978 *
1979 * Returns 0 on success, negative on failure
1980 */
1981 static void __exit fcoe_exit(void)
1982 {
1983 unsigned int cpu;
1984 struct fcoe_interface *fcoe, *tmp;
1985
1986 fcoe_dev_cleanup();
1987
1988 /* releases the associated fcoe hosts */
1989 list_for_each_entry_safe(fcoe, tmp, &fcoe_hostlist, list)
1990 fcoe_if_destroy(fcoe->ctlr.lp);
1991
1992 unregister_hotcpu_notifier(&fcoe_cpu_notifier);
1993
1994 for_each_online_cpu(cpu)
1995 fcoe_percpu_thread_destroy(cpu);
1996
1997 /* detach from scsi transport */
1998 fcoe_if_exit();
1999 }
2000 module_exit(fcoe_exit);