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