aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/fcoe/fcoe.c
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2009-09-08 20:55:21 -0400
committerDan Williams <dan.j.williams@intel.com>2009-09-08 20:55:21 -0400
commitbbb20089a3275a19e475dbc21320c3742e3ca423 (patch)
tree216fdc1cbef450ca688135c5b8969169482d9a48 /drivers/scsi/fcoe/fcoe.c
parent3e48e656903e9fd8bc805c6a2c4264d7808d315b (diff)
parent657a77fa7284d8ae28dfa48f1dc5d919bf5b2843 (diff)
Merge branch 'dmaengine' into async-tx-next
Conflicts: crypto/async_tx/async_xor.c drivers/dma/ioat/dma_v2.h drivers/dma/ioat/pci.c drivers/md/raid5.c
Diffstat (limited to 'drivers/scsi/fcoe/fcoe.c')
-rw-r--r--drivers/scsi/fcoe/fcoe.c398
1 files changed, 203 insertions, 195 deletions
diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
index 03e1926f40b5..0a5609bb5817 100644
--- a/drivers/scsi/fcoe/fcoe.c
+++ b/drivers/scsi/fcoe/fcoe.c
@@ -45,8 +45,6 @@
45 45
46#include "fcoe.h" 46#include "fcoe.h"
47 47
48static int debug_fcoe;
49
50MODULE_AUTHOR("Open-FCoE.org"); 48MODULE_AUTHOR("Open-FCoE.org");
51MODULE_DESCRIPTION("FCoE"); 49MODULE_DESCRIPTION("FCoE");
52MODULE_LICENSE("GPL v2"); 50MODULE_LICENSE("GPL v2");
@@ -54,7 +52,6 @@ MODULE_LICENSE("GPL v2");
54/* fcoe host list */ 52/* fcoe host list */
55LIST_HEAD(fcoe_hostlist); 53LIST_HEAD(fcoe_hostlist);
56DEFINE_RWLOCK(fcoe_hostlist_lock); 54DEFINE_RWLOCK(fcoe_hostlist_lock);
57DEFINE_TIMER(fcoe_timer, NULL, 0, 0);
58DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu); 55DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu);
59 56
60/* Function Prototypes */ 57/* Function Prototypes */
@@ -71,7 +68,7 @@ static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *);
71static int fcoe_hostlist_add(const struct fc_lport *); 68static int fcoe_hostlist_add(const struct fc_lport *);
72static int fcoe_hostlist_remove(const struct fc_lport *); 69static int fcoe_hostlist_remove(const struct fc_lport *);
73 70
74static int fcoe_check_wait_queue(struct fc_lport *); 71static void fcoe_check_wait_queue(struct fc_lport *, struct sk_buff *);
75static int fcoe_device_notification(struct notifier_block *, ulong, void *); 72static int fcoe_device_notification(struct notifier_block *, ulong, void *);
76static void fcoe_dev_setup(void); 73static void fcoe_dev_setup(void);
77static void fcoe_dev_cleanup(void); 74static void fcoe_dev_cleanup(void);
@@ -136,6 +133,58 @@ static struct scsi_host_template fcoe_shost_template = {
136}; 133};
137 134
138/** 135/**
136 * fcoe_fip_recv - handle a received FIP frame.
137 * @skb: the receive skb
138 * @dev: associated &net_device
139 * @ptype: the &packet_type structure which was used to register this handler.
140 * @orig_dev: original receive &net_device, in case @dev is a bond.
141 *
142 * Returns: 0 for success
143 */
144static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *dev,
145 struct packet_type *ptype,
146 struct net_device *orig_dev)
147{
148 struct fcoe_softc *fc;
149
150 fc = container_of(ptype, struct fcoe_softc, fip_packet_type);
151 fcoe_ctlr_recv(&fc->ctlr, skb);
152 return 0;
153}
154
155/**
156 * fcoe_fip_send() - send an Ethernet-encapsulated FIP frame.
157 * @fip: FCoE controller.
158 * @skb: FIP Packet.
159 */
160static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
161{
162 skb->dev = fcoe_from_ctlr(fip)->real_dev;
163 dev_queue_xmit(skb);
164}
165
166/**
167 * fcoe_update_src_mac() - Update Ethernet MAC filters.
168 * @fip: FCoE controller.
169 * @old: Unicast MAC address to delete if the MAC is non-zero.
170 * @new: Unicast MAC address to add.
171 *
172 * Remove any previously-set unicast MAC filter.
173 * Add secondary FCoE MAC address filter for our OUI.
174 */
175static void fcoe_update_src_mac(struct fcoe_ctlr *fip, u8 *old, u8 *new)
176{
177 struct fcoe_softc *fc;
178
179 fc = fcoe_from_ctlr(fip);
180 rtnl_lock();
181 if (!is_zero_ether_addr(old))
182 dev_unicast_delete(fc->real_dev, old);
183 dev_unicast_add(fc->real_dev, new);
184 rtnl_unlock();
185}
186
187/**
139 * fcoe_lport_config() - sets up the fc_lport 188 * fcoe_lport_config() - sets up the fc_lport
140 * @lp: ptr to the fc_lport 189 * @lp: ptr to the fc_lport
141 * 190 *
@@ -146,6 +195,7 @@ static int fcoe_lport_config(struct fc_lport *lp)
146 lp->link_up = 0; 195 lp->link_up = 0;
147 lp->qfull = 0; 196 lp->qfull = 0;
148 lp->max_retry_count = 3; 197 lp->max_retry_count = 3;
198 lp->max_rport_retry_count = 3;
149 lp->e_d_tov = 2 * 1000; /* FC-FS default */ 199 lp->e_d_tov = 2 * 1000; /* FC-FS default */
150 lp->r_a_tov = 2 * 2 * 1000; 200 lp->r_a_tov = 2 * 2 * 1000;
151 lp->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS | 201 lp->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
@@ -167,6 +217,42 @@ static int fcoe_lport_config(struct fc_lport *lp)
167} 217}
168 218
169/** 219/**
220 * fcoe_netdev_cleanup() - clean up netdev configurations
221 * @fc: ptr to the fcoe_softc
222 */
223void fcoe_netdev_cleanup(struct fcoe_softc *fc)
224{
225 u8 flogi_maddr[ETH_ALEN];
226
227 /* Don't listen for Ethernet packets anymore */
228 dev_remove_pack(&fc->fcoe_packet_type);
229 dev_remove_pack(&fc->fip_packet_type);
230
231 /* Delete secondary MAC addresses */
232 rtnl_lock();
233 memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
234 dev_unicast_delete(fc->real_dev, flogi_maddr);
235 if (!is_zero_ether_addr(fc->ctlr.data_src_addr))
236 dev_unicast_delete(fc->real_dev, fc->ctlr.data_src_addr);
237 if (fc->ctlr.spma)
238 dev_unicast_delete(fc->real_dev, fc->ctlr.ctl_src_addr);
239 dev_mc_delete(fc->real_dev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
240 rtnl_unlock();
241}
242
243/**
244 * fcoe_queue_timer() - fcoe queue timer
245 * @lp: the fc_lport pointer
246 *
247 * Calls fcoe_check_wait_queue on timeout
248 *
249 */
250static void fcoe_queue_timer(ulong lp)
251{
252 fcoe_check_wait_queue((struct fc_lport *)lp, NULL);
253}
254
255/**
170 * fcoe_netdev_config() - Set up netdev for SW FCoE 256 * fcoe_netdev_config() - Set up netdev for SW FCoE
171 * @lp : ptr to the fc_lport 257 * @lp : ptr to the fc_lport
172 * @netdev : ptr to the associated netdevice struct 258 * @netdev : ptr to the associated netdevice struct
@@ -181,6 +267,7 @@ static int fcoe_netdev_config(struct fc_lport *lp, struct net_device *netdev)
181 u64 wwnn, wwpn; 267 u64 wwnn, wwpn;
182 struct fcoe_softc *fc; 268 struct fcoe_softc *fc;
183 u8 flogi_maddr[ETH_ALEN]; 269 u8 flogi_maddr[ETH_ALEN];
270 struct netdev_hw_addr *ha;
184 271
185 /* Setup lport private data to point to fcoe softc */ 272 /* Setup lport private data to point to fcoe softc */
186 fc = lport_priv(lp); 273 fc = lport_priv(lp);
@@ -216,30 +303,44 @@ static int fcoe_netdev_config(struct fc_lport *lp, struct net_device *netdev)
216#ifdef NETIF_F_FCOE_CRC 303#ifdef NETIF_F_FCOE_CRC
217 if (netdev->features & NETIF_F_FCOE_CRC) { 304 if (netdev->features & NETIF_F_FCOE_CRC) {
218 lp->crc_offload = 1; 305 lp->crc_offload = 1;
219 printk(KERN_DEBUG "fcoe:%s supports FCCRC offload\n", 306 FCOE_NETDEV_DBG(netdev, "Supports FCCRC offload\n");
220 netdev->name);
221 } 307 }
222#endif 308#endif
223#ifdef NETIF_F_FSO 309#ifdef NETIF_F_FSO
224 if (netdev->features & NETIF_F_FSO) { 310 if (netdev->features & NETIF_F_FSO) {
225 lp->seq_offload = 1; 311 lp->seq_offload = 1;
226 lp->lso_max = netdev->gso_max_size; 312 lp->lso_max = netdev->gso_max_size;
227 printk(KERN_DEBUG "fcoe:%s supports LSO for max len 0x%x\n", 313 FCOE_NETDEV_DBG(netdev, "Supports LSO for max len 0x%x\n",
228 netdev->name, lp->lso_max); 314 lp->lso_max);
229 } 315 }
230#endif 316#endif
231 if (netdev->fcoe_ddp_xid) { 317 if (netdev->fcoe_ddp_xid) {
232 lp->lro_enabled = 1; 318 lp->lro_enabled = 1;
233 lp->lro_xid = netdev->fcoe_ddp_xid; 319 lp->lro_xid = netdev->fcoe_ddp_xid;
234 printk(KERN_DEBUG "fcoe:%s supports LRO for max xid 0x%x\n", 320 FCOE_NETDEV_DBG(netdev, "Supports LRO for max xid 0x%x\n",
235 netdev->name, lp->lro_xid); 321 lp->lro_xid);
236 } 322 }
237 skb_queue_head_init(&fc->fcoe_pending_queue); 323 skb_queue_head_init(&fc->fcoe_pending_queue);
238 fc->fcoe_pending_queue_active = 0; 324 fc->fcoe_pending_queue_active = 0;
325 setup_timer(&fc->timer, fcoe_queue_timer, (unsigned long)lp);
326
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) &&
332 (is_valid_ether_addr(fc->ctlr.ctl_src_addr))) {
333 memcpy(fc->ctlr.ctl_src_addr, ha->addr, ETH_ALEN);
334 fc->ctlr.spma = 1;
335 break;
336 }
337 }
338 rcu_read_unlock();
239 339
240 /* setup Source Mac Address */ 340 /* setup Source Mac Address */
241 memcpy(fc->ctlr.ctl_src_addr, fc->real_dev->dev_addr, 341 if (!fc->ctlr.spma)
242 fc->real_dev->addr_len); 342 memcpy(fc->ctlr.ctl_src_addr, fc->real_dev->dev_addr,
343 fc->real_dev->addr_len);
243 344
244 wwnn = fcoe_wwn_from_mac(fc->real_dev->dev_addr, 1, 0); 345 wwnn = fcoe_wwn_from_mac(fc->real_dev->dev_addr, 1, 0);
245 fc_set_wwnn(lp, wwnn); 346 fc_set_wwnn(lp, wwnn);
@@ -254,7 +355,9 @@ static int fcoe_netdev_config(struct fc_lport *lp, struct net_device *netdev)
254 */ 355 */
255 rtnl_lock(); 356 rtnl_lock();
256 memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN); 357 memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
257 dev_unicast_add(fc->real_dev, flogi_maddr, ETH_ALEN); 358 dev_unicast_add(fc->real_dev, flogi_maddr);
359 if (fc->ctlr.spma)
360 dev_unicast_add(fc->real_dev, fc->ctlr.ctl_src_addr);
258 dev_mc_add(fc->real_dev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0); 361 dev_mc_add(fc->real_dev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
259 rtnl_unlock(); 362 rtnl_unlock();
260 363
@@ -267,6 +370,11 @@ static int fcoe_netdev_config(struct fc_lport *lp, struct net_device *netdev)
267 fc->fcoe_packet_type.dev = fc->real_dev; 370 fc->fcoe_packet_type.dev = fc->real_dev;
268 dev_add_pack(&fc->fcoe_packet_type); 371 dev_add_pack(&fc->fcoe_packet_type);
269 372
373 fc->fip_packet_type.func = fcoe_fip_recv;
374 fc->fip_packet_type.type = htons(ETH_P_FIP);
375 fc->fip_packet_type.dev = fc->real_dev;
376 dev_add_pack(&fc->fip_packet_type);
377
270 return 0; 378 return 0;
271} 379}
272 380
@@ -296,7 +404,8 @@ static int fcoe_shost_config(struct fc_lport *lp, struct Scsi_Host *shost,
296 /* add the new host to the SCSI-ml */ 404 /* add the new host to the SCSI-ml */
297 rc = scsi_add_host(lp->host, dev); 405 rc = scsi_add_host(lp->host, dev);
298 if (rc) { 406 if (rc) {
299 FC_DBG("fcoe_shost_config:error on scsi_add_host\n"); 407 FCOE_NETDEV_DBG(fcoe_netdev(lp), "fcoe_shost_config: "
408 "error on scsi_add_host\n");
300 return rc; 409 return rc;
301 } 410 }
302 sprintf(fc_host_symbolic_name(lp->host), "%s v%s over %s", 411 sprintf(fc_host_symbolic_name(lp->host), "%s v%s over %s",
@@ -334,12 +443,10 @@ static int fcoe_if_destroy(struct net_device *netdev)
334{ 443{
335 struct fc_lport *lp = NULL; 444 struct fc_lport *lp = NULL;
336 struct fcoe_softc *fc; 445 struct fcoe_softc *fc;
337 u8 flogi_maddr[ETH_ALEN];
338 446
339 BUG_ON(!netdev); 447 BUG_ON(!netdev);
340 448
341 printk(KERN_DEBUG "fcoe_if_destroy:interface on %s\n", 449 FCOE_NETDEV_DBG(netdev, "Destroying interface\n");
342 netdev->name);
343 450
344 lp = fcoe_hostlist_lookup(netdev); 451 lp = fcoe_hostlist_lookup(netdev);
345 if (!lp) 452 if (!lp)
@@ -353,9 +460,10 @@ static int fcoe_if_destroy(struct net_device *netdev)
353 /* Remove the instance from fcoe's list */ 460 /* Remove the instance from fcoe's list */
354 fcoe_hostlist_remove(lp); 461 fcoe_hostlist_remove(lp);
355 462
356 /* Don't listen for Ethernet packets anymore */ 463 /* clean up netdev configurations */
357 dev_remove_pack(&fc->fcoe_packet_type); 464 fcoe_netdev_cleanup(fc);
358 dev_remove_pack(&fc->fip_packet_type); 465
466 /* tear-down the FCoE controller */
359 fcoe_ctlr_destroy(&fc->ctlr); 467 fcoe_ctlr_destroy(&fc->ctlr);
360 468
361 /* Cleanup the fc_lport */ 469 /* Cleanup the fc_lport */
@@ -370,22 +478,15 @@ static int fcoe_if_destroy(struct net_device *netdev)
370 if (lp->emp) 478 if (lp->emp)
371 fc_exch_mgr_free(lp->emp); 479 fc_exch_mgr_free(lp->emp);
372 480
373 /* Delete secondary MAC addresses */
374 rtnl_lock();
375 memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
376 dev_unicast_delete(fc->real_dev, flogi_maddr, ETH_ALEN);
377 if (!is_zero_ether_addr(fc->ctlr.data_src_addr))
378 dev_unicast_delete(fc->real_dev,
379 fc->ctlr.data_src_addr, ETH_ALEN);
380 dev_mc_delete(fc->real_dev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
381 rtnl_unlock();
382
383 /* Free the per-CPU receive threads */ 481 /* Free the per-CPU receive threads */
384 fcoe_percpu_clean(lp); 482 fcoe_percpu_clean(lp);
385 483
386 /* Free existing skbs */ 484 /* Free existing skbs */
387 fcoe_clean_pending_queue(lp); 485 fcoe_clean_pending_queue(lp);
388 486
487 /* Stop the timer */
488 del_timer_sync(&fc->timer);
489
389 /* Free memory used by statistical counters */ 490 /* Free memory used by statistical counters */
390 fc_lport_free_stats(lp); 491 fc_lport_free_stats(lp);
391 492
@@ -439,58 +540,6 @@ static struct libfc_function_template fcoe_libfc_fcn_templ = {
439}; 540};
440 541
441/** 542/**
442 * fcoe_fip_recv - handle a received FIP frame.
443 * @skb: the receive skb
444 * @dev: associated &net_device
445 * @ptype: the &packet_type structure which was used to register this handler.
446 * @orig_dev: original receive &net_device, in case @dev is a bond.
447 *
448 * Returns: 0 for success
449 */
450static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *dev,
451 struct packet_type *ptype,
452 struct net_device *orig_dev)
453{
454 struct fcoe_softc *fc;
455
456 fc = container_of(ptype, struct fcoe_softc, fip_packet_type);
457 fcoe_ctlr_recv(&fc->ctlr, skb);
458 return 0;
459}
460
461/**
462 * fcoe_fip_send() - send an Ethernet-encapsulated FIP frame.
463 * @fip: FCoE controller.
464 * @skb: FIP Packet.
465 */
466static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
467{
468 skb->dev = fcoe_from_ctlr(fip)->real_dev;
469 dev_queue_xmit(skb);
470}
471
472/**
473 * fcoe_update_src_mac() - Update Ethernet MAC filters.
474 * @fip: FCoE controller.
475 * @old: Unicast MAC address to delete if the MAC is non-zero.
476 * @new: Unicast MAC address to add.
477 *
478 * Remove any previously-set unicast MAC filter.
479 * Add secondary FCoE MAC address filter for our OUI.
480 */
481static void fcoe_update_src_mac(struct fcoe_ctlr *fip, u8 *old, u8 *new)
482{
483 struct fcoe_softc *fc;
484
485 fc = fcoe_from_ctlr(fip);
486 rtnl_lock();
487 if (!is_zero_ether_addr(old))
488 dev_unicast_delete(fc->real_dev, old, ETH_ALEN);
489 dev_unicast_add(fc->real_dev, new, ETH_ALEN);
490 rtnl_unlock();
491}
492
493/**
494 * fcoe_if_create() - this function creates the fcoe interface 543 * fcoe_if_create() - this function creates the fcoe interface
495 * @netdev: pointer the associated netdevice 544 * @netdev: pointer the associated netdevice
496 * 545 *
@@ -508,8 +557,7 @@ static int fcoe_if_create(struct net_device *netdev)
508 557
509 BUG_ON(!netdev); 558 BUG_ON(!netdev);
510 559
511 printk(KERN_DEBUG "fcoe_if_create:interface on %s\n", 560 FCOE_NETDEV_DBG(netdev, "Create Interface\n");
512 netdev->name);
513 561
514 lp = fcoe_hostlist_lookup(netdev); 562 lp = fcoe_hostlist_lookup(netdev);
515 if (lp) 563 if (lp)
@@ -518,7 +566,7 @@ static int fcoe_if_create(struct net_device *netdev)
518 shost = libfc_host_alloc(&fcoe_shost_template, 566 shost = libfc_host_alloc(&fcoe_shost_template,
519 sizeof(struct fcoe_softc)); 567 sizeof(struct fcoe_softc));
520 if (!shost) { 568 if (!shost) {
521 FC_DBG("Could not allocate host structure\n"); 569 FCOE_NETDEV_DBG(netdev, "Could not allocate host structure\n");
522 return -ENOMEM; 570 return -ENOMEM;
523 } 571 }
524 lp = shost_priv(shost); 572 lp = shost_priv(shost);
@@ -527,14 +575,8 @@ static int fcoe_if_create(struct net_device *netdev)
527 /* configure fc_lport, e.g., em */ 575 /* configure fc_lport, e.g., em */
528 rc = fcoe_lport_config(lp); 576 rc = fcoe_lport_config(lp);
529 if (rc) { 577 if (rc) {
530 FC_DBG("Could not configure lport\n"); 578 FCOE_NETDEV_DBG(netdev, "Could not configure lport for the "
531 goto out_host_put; 579 "interface\n");
532 }
533
534 /* configure lport network properties */
535 rc = fcoe_netdev_config(lp, netdev);
536 if (rc) {
537 FC_DBG("Could not configure netdev for lport\n");
538 goto out_host_put; 580 goto out_host_put;
539 } 581 }
540 582
@@ -545,29 +587,35 @@ static int fcoe_if_create(struct net_device *netdev)
545 fc->ctlr.send = fcoe_fip_send; 587 fc->ctlr.send = fcoe_fip_send;
546 fc->ctlr.update_mac = fcoe_update_src_mac; 588 fc->ctlr.update_mac = fcoe_update_src_mac;
547 589
548 fc->fip_packet_type.func = fcoe_fip_recv; 590 /* configure lport network properties */
549 fc->fip_packet_type.type = htons(ETH_P_FIP); 591 rc = fcoe_netdev_config(lp, netdev);
550 fc->fip_packet_type.dev = fc->real_dev; 592 if (rc) {
551 dev_add_pack(&fc->fip_packet_type); 593 FCOE_NETDEV_DBG(netdev, "Could not configure netdev for the "
594 "interface\n");
595 goto out_netdev_cleanup;
596 }
552 597
553 /* configure lport scsi host properties */ 598 /* configure lport scsi host properties */
554 rc = fcoe_shost_config(lp, shost, &netdev->dev); 599 rc = fcoe_shost_config(lp, shost, &netdev->dev);
555 if (rc) { 600 if (rc) {
556 FC_DBG("Could not configure shost for lport\n"); 601 FCOE_NETDEV_DBG(netdev, "Could not configure shost for the "
557 goto out_host_put; 602 "interface\n");
603 goto out_netdev_cleanup;
558 } 604 }
559 605
560 /* lport exch manager allocation */ 606 /* lport exch manager allocation */
561 rc = fcoe_em_config(lp); 607 rc = fcoe_em_config(lp);
562 if (rc) { 608 if (rc) {
563 FC_DBG("Could not configure em for lport\n"); 609 FCOE_NETDEV_DBG(netdev, "Could not configure the EM for the "
564 goto out_host_put; 610 "interface\n");
611 goto out_netdev_cleanup;
565 } 612 }
566 613
567 /* Initialize the library */ 614 /* Initialize the library */
568 rc = fcoe_libfc_config(lp, &fcoe_libfc_fcn_templ); 615 rc = fcoe_libfc_config(lp, &fcoe_libfc_fcn_templ);
569 if (rc) { 616 if (rc) {
570 FC_DBG("Could not configure libfc for lport!\n"); 617 FCOE_NETDEV_DBG(netdev, "Could not configure libfc for the "
618 "interface\n");
571 goto out_lp_destroy; 619 goto out_lp_destroy;
572 } 620 }
573 621
@@ -587,6 +635,8 @@ static int fcoe_if_create(struct net_device *netdev)
587 635
588out_lp_destroy: 636out_lp_destroy:
589 fc_exch_mgr_free(lp->emp); /* Free the EM */ 637 fc_exch_mgr_free(lp->emp); /* Free the EM */
638out_netdev_cleanup:
639 fcoe_netdev_cleanup(fc);
590out_host_put: 640out_host_put:
591 scsi_host_put(lp->host); 641 scsi_host_put(lp->host);
592 return rc; 642 return rc;
@@ -604,7 +654,7 @@ static int __init fcoe_if_init(void)
604 fc_attach_transport(&fcoe_transport_function); 654 fc_attach_transport(&fcoe_transport_function);
605 655
606 if (!scsi_transport_fcoe_sw) { 656 if (!scsi_transport_fcoe_sw) {
607 printk(KERN_ERR "fcoe_init:fc_attach_transport() failed\n"); 657 printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n");
608 return -ENODEV; 658 return -ENODEV;
609 } 659 }
610 660
@@ -665,7 +715,7 @@ static void fcoe_percpu_thread_destroy(unsigned int cpu)
665 unsigned targ_cpu = smp_processor_id(); 715 unsigned targ_cpu = smp_processor_id();
666#endif /* CONFIG_SMP */ 716#endif /* CONFIG_SMP */
667 717
668 printk(KERN_DEBUG "fcoe: Destroying receive thread for CPU %d\n", cpu); 718 FCOE_DBG("Destroying receive thread for CPU %d\n", cpu);
669 719
670 /* Prevent any new skbs from being queued for this CPU. */ 720 /* Prevent any new skbs from being queued for this CPU. */
671 p = &per_cpu(fcoe_percpu, cpu); 721 p = &per_cpu(fcoe_percpu, cpu);
@@ -687,8 +737,8 @@ static void fcoe_percpu_thread_destroy(unsigned int cpu)
687 p0 = &per_cpu(fcoe_percpu, targ_cpu); 737 p0 = &per_cpu(fcoe_percpu, targ_cpu);
688 spin_lock_bh(&p0->fcoe_rx_list.lock); 738 spin_lock_bh(&p0->fcoe_rx_list.lock);
689 if (p0->thread) { 739 if (p0->thread) {
690 FC_DBG("Moving frames from CPU %d to CPU %d\n", 740 FCOE_DBG("Moving frames from CPU %d to CPU %d\n",
691 cpu, targ_cpu); 741 cpu, targ_cpu);
692 742
693 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) 743 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
694 __skb_queue_tail(&p0->fcoe_rx_list, skb); 744 __skb_queue_tail(&p0->fcoe_rx_list, skb);
@@ -754,12 +804,12 @@ static int fcoe_cpu_callback(struct notifier_block *nfb,
754 switch (action) { 804 switch (action) {
755 case CPU_ONLINE: 805 case CPU_ONLINE:
756 case CPU_ONLINE_FROZEN: 806 case CPU_ONLINE_FROZEN:
757 FC_DBG("CPU %x online: Create Rx thread\n", cpu); 807 FCOE_DBG("CPU %x online: Create Rx thread\n", cpu);
758 fcoe_percpu_thread_create(cpu); 808 fcoe_percpu_thread_create(cpu);
759 break; 809 break;
760 case CPU_DEAD: 810 case CPU_DEAD:
761 case CPU_DEAD_FROZEN: 811 case CPU_DEAD_FROZEN:
762 FC_DBG("CPU %x offline: Remove Rx thread\n", cpu); 812 FCOE_DBG("CPU %x offline: Remove Rx thread\n", cpu);
763 fcoe_percpu_thread_destroy(cpu); 813 fcoe_percpu_thread_destroy(cpu);
764 break; 814 break;
765 default: 815 default:
@@ -797,24 +847,21 @@ int fcoe_rcv(struct sk_buff *skb, struct net_device *dev,
797 fc = container_of(ptype, struct fcoe_softc, fcoe_packet_type); 847 fc = container_of(ptype, struct fcoe_softc, fcoe_packet_type);
798 lp = fc->ctlr.lp; 848 lp = fc->ctlr.lp;
799 if (unlikely(lp == NULL)) { 849 if (unlikely(lp == NULL)) {
800 FC_DBG("cannot find hba structure"); 850 FCOE_NETDEV_DBG(dev, "Cannot find hba structure");
801 goto err2; 851 goto err2;
802 } 852 }
803 if (!lp->link_up) 853 if (!lp->link_up)
804 goto err2; 854 goto err2;
805 855
806 if (unlikely(debug_fcoe)) { 856 FCOE_NETDEV_DBG(dev, "skb_info: len:%d data_len:%d head:%p "
807 FC_DBG("skb_info: len:%d data_len:%d head:%p data:%p tail:%p " 857 "data:%p tail:%p end:%p sum:%d dev:%s",
808 "end:%p sum:%d dev:%s", skb->len, skb->data_len, 858 skb->len, skb->data_len, skb->head, skb->data,
809 skb->head, skb->data, skb_tail_pointer(skb), 859 skb_tail_pointer(skb), skb_end_pointer(skb),
810 skb_end_pointer(skb), skb->csum, 860 skb->csum, skb->dev ? skb->dev->name : "<NULL>");
811 skb->dev ? skb->dev->name : "<NULL>");
812
813 }
814 861
815 /* check for FCOE packet type */ 862 /* check for FCOE packet type */
816 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) { 863 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
817 FC_DBG("wrong FC type frame"); 864 FCOE_NETDEV_DBG(dev, "Wrong FC type frame");
818 goto err; 865 goto err;
819 } 866 }
820 867
@@ -852,8 +899,9 @@ int fcoe_rcv(struct sk_buff *skb, struct net_device *dev,
852 * the first CPU now. For non-SMP systems this 899 * the first CPU now. For non-SMP systems this
853 * will check the same CPU twice. 900 * will check the same CPU twice.
854 */ 901 */
855 FC_DBG("CPU is online, but no receive thread ready " 902 FCOE_NETDEV_DBG(dev, "CPU is online, but no receive thread "
856 "for incoming skb- using first online CPU.\n"); 903 "ready for incoming skb- using first online "
904 "CPU.\n");
857 905
858 spin_unlock_bh(&fps->fcoe_rx_list.lock); 906 spin_unlock_bh(&fps->fcoe_rx_list.lock);
859 cpu = first_cpu(cpu_online_map); 907 cpu = first_cpu(cpu_online_map);
@@ -988,7 +1036,7 @@ u32 fcoe_fc_crc(struct fc_frame *fp)
988 */ 1036 */
989int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp) 1037int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp)
990{ 1038{
991 int wlen, rc = 0; 1039 int wlen;
992 u32 crc; 1040 u32 crc;
993 struct ethhdr *eh; 1041 struct ethhdr *eh;
994 struct fcoe_crc_eof *cp; 1042 struct fcoe_crc_eof *cp;
@@ -1021,8 +1069,7 @@ int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp)
1021 sof = fr_sof(fp); 1069 sof = fr_sof(fp);
1022 eof = fr_eof(fp); 1070 eof = fr_eof(fp);
1023 1071
1024 elen = (fc->real_dev->priv_flags & IFF_802_1Q_VLAN) ? 1072 elen = sizeof(struct ethhdr);
1025 sizeof(struct vlan_ethhdr) : sizeof(struct ethhdr);
1026 hlen = sizeof(struct fcoe_hdr); 1073 hlen = sizeof(struct fcoe_hdr);
1027 tlen = sizeof(struct fcoe_crc_eof); 1074 tlen = sizeof(struct fcoe_crc_eof);
1028 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE; 1075 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
@@ -1107,18 +1154,9 @@ int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp)
1107 /* send down to lld */ 1154 /* send down to lld */
1108 fr_dev(fp) = lp; 1155 fr_dev(fp) = lp;
1109 if (fc->fcoe_pending_queue.qlen) 1156 if (fc->fcoe_pending_queue.qlen)
1110 rc = fcoe_check_wait_queue(lp); 1157 fcoe_check_wait_queue(lp, skb);
1111 1158 else if (fcoe_start_io(skb))
1112 if (rc == 0) 1159 fcoe_check_wait_queue(lp, skb);
1113 rc = fcoe_start_io(skb);
1114
1115 if (rc) {
1116 spin_lock_bh(&fc->fcoe_pending_queue.lock);
1117 __skb_queue_tail(&fc->fcoe_pending_queue, skb);
1118 spin_unlock_bh(&fc->fcoe_pending_queue.lock);
1119 if (fc->fcoe_pending_queue.qlen > FCOE_MAX_QUEUE_DEPTH)
1120 lp->qfull = 1;
1121 }
1122 1160
1123 return 0; 1161 return 0;
1124} 1162}
@@ -1162,19 +1200,17 @@ int fcoe_percpu_receive_thread(void *arg)
1162 fr = fcoe_dev_from_skb(skb); 1200 fr = fcoe_dev_from_skb(skb);
1163 lp = fr->fr_dev; 1201 lp = fr->fr_dev;
1164 if (unlikely(lp == NULL)) { 1202 if (unlikely(lp == NULL)) {
1165 FC_DBG("invalid HBA Structure"); 1203 FCOE_NETDEV_DBG(skb->dev, "Invalid HBA Structure");
1166 kfree_skb(skb); 1204 kfree_skb(skb);
1167 continue; 1205 continue;
1168 } 1206 }
1169 1207
1170 if (unlikely(debug_fcoe)) { 1208 FCOE_NETDEV_DBG(skb->dev, "skb_info: len:%d data_len:%d "
1171 FC_DBG("skb_info: len:%d data_len:%d head:%p data:%p " 1209 "head:%p data:%p tail:%p end:%p sum:%d dev:%s",
1172 "tail:%p end:%p sum:%d dev:%s", 1210 skb->len, skb->data_len,
1173 skb->len, skb->data_len, 1211 skb->head, skb->data, skb_tail_pointer(skb),
1174 skb->head, skb->data, skb_tail_pointer(skb), 1212 skb_end_pointer(skb), skb->csum,
1175 skb_end_pointer(skb), skb->csum, 1213 skb->dev ? skb->dev->name : "<NULL>");
1176 skb->dev ? skb->dev->name : "<NULL>");
1177 }
1178 1214
1179 /* 1215 /*
1180 * Save source MAC address before discarding header. 1216 * Save source MAC address before discarding header.
@@ -1194,7 +1230,7 @@ int fcoe_percpu_receive_thread(void *arg)
1194 stats = fc_lport_get_stats(lp); 1230 stats = fc_lport_get_stats(lp);
1195 if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) { 1231 if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) {
1196 if (stats->ErrorFrames < 5) 1232 if (stats->ErrorFrames < 5)
1197 printk(KERN_WARNING "FCoE version " 1233 printk(KERN_WARNING "fcoe: FCoE version "
1198 "mismatch: The frame has " 1234 "mismatch: The frame has "
1199 "version %x, but the " 1235 "version %x, but the "
1200 "initiator supports version " 1236 "initiator supports version "
@@ -1247,7 +1283,7 @@ int fcoe_percpu_receive_thread(void *arg)
1247 if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) { 1283 if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) {
1248 if (le32_to_cpu(fr_crc(fp)) != 1284 if (le32_to_cpu(fr_crc(fp)) !=
1249 ~crc32(~0, skb->data, fr_len)) { 1285 ~crc32(~0, skb->data, fr_len)) {
1250 if (debug_fcoe || stats->InvalidCRCCount < 5) 1286 if (stats->InvalidCRCCount < 5)
1251 printk(KERN_WARNING "fcoe: dropping " 1287 printk(KERN_WARNING "fcoe: dropping "
1252 "frame with CRC error\n"); 1288 "frame with CRC error\n");
1253 stats->InvalidCRCCount++; 1289 stats->InvalidCRCCount++;
@@ -1268,32 +1304,6 @@ int fcoe_percpu_receive_thread(void *arg)
1268} 1304}
1269 1305
1270/** 1306/**
1271 * fcoe_watchdog() - fcoe timer callback
1272 * @vp:
1273 *
1274 * This checks the pending queue length for fcoe and set lport qfull
1275 * if the FCOE_MAX_QUEUE_DEPTH is reached. This is done for all fc_lport on the
1276 * fcoe_hostlist.
1277 *
1278 * Returns: 0 for success
1279 */
1280void fcoe_watchdog(ulong vp)
1281{
1282 struct fcoe_softc *fc;
1283
1284 read_lock(&fcoe_hostlist_lock);
1285 list_for_each_entry(fc, &fcoe_hostlist, list) {
1286 if (fc->ctlr.lp)
1287 fcoe_check_wait_queue(fc->ctlr.lp);
1288 }
1289 read_unlock(&fcoe_hostlist_lock);
1290
1291 fcoe_timer.expires = jiffies + (1 * HZ);
1292 add_timer(&fcoe_timer);
1293}
1294
1295
1296/**
1297 * fcoe_check_wait_queue() - attempt to clear the transmit backlog 1307 * fcoe_check_wait_queue() - attempt to clear the transmit backlog
1298 * @lp: the fc_lport 1308 * @lp: the fc_lport
1299 * 1309 *
@@ -1305,16 +1315,17 @@ void fcoe_watchdog(ulong vp)
1305 * The wait_queue is used when the skb transmit fails. skb will go 1315 * The wait_queue is used when the skb transmit fails. skb will go
1306 * in the wait_queue which will be emptied by the timer function or 1316 * in the wait_queue which will be emptied by the timer function or
1307 * by the next skb transmit. 1317 * by the next skb transmit.
1308 *
1309 * Returns: 0 for success
1310 */ 1318 */
1311static int fcoe_check_wait_queue(struct fc_lport *lp) 1319static void fcoe_check_wait_queue(struct fc_lport *lp, struct sk_buff *skb)
1312{ 1320{
1313 struct fcoe_softc *fc = lport_priv(lp); 1321 struct fcoe_softc *fc = lport_priv(lp);
1314 struct sk_buff *skb; 1322 int rc;
1315 int rc = -1;
1316 1323
1317 spin_lock_bh(&fc->fcoe_pending_queue.lock); 1324 spin_lock_bh(&fc->fcoe_pending_queue.lock);
1325
1326 if (skb)
1327 __skb_queue_tail(&fc->fcoe_pending_queue, skb);
1328
1318 if (fc->fcoe_pending_queue_active) 1329 if (fc->fcoe_pending_queue_active)
1319 goto out; 1330 goto out;
1320 fc->fcoe_pending_queue_active = 1; 1331 fc->fcoe_pending_queue_active = 1;
@@ -1340,23 +1351,26 @@ static int fcoe_check_wait_queue(struct fc_lport *lp)
1340 1351
1341 if (fc->fcoe_pending_queue.qlen < FCOE_LOW_QUEUE_DEPTH) 1352 if (fc->fcoe_pending_queue.qlen < FCOE_LOW_QUEUE_DEPTH)
1342 lp->qfull = 0; 1353 lp->qfull = 0;
1354 if (fc->fcoe_pending_queue.qlen && !timer_pending(&fc->timer))
1355 mod_timer(&fc->timer, jiffies + 2);
1343 fc->fcoe_pending_queue_active = 0; 1356 fc->fcoe_pending_queue_active = 0;
1344 rc = fc->fcoe_pending_queue.qlen;
1345out: 1357out:
1358 if (fc->fcoe_pending_queue.qlen > FCOE_MAX_QUEUE_DEPTH)
1359 lp->qfull = 1;
1346 spin_unlock_bh(&fc->fcoe_pending_queue.lock); 1360 spin_unlock_bh(&fc->fcoe_pending_queue.lock);
1347 return rc; 1361 return;
1348} 1362}
1349 1363
1350/** 1364/**
1351 * fcoe_dev_setup() - setup link change notification interface 1365 * fcoe_dev_setup() - setup link change notification interface
1352 */ 1366 */
1353static void fcoe_dev_setup() 1367static void fcoe_dev_setup(void)
1354{ 1368{
1355 register_netdevice_notifier(&fcoe_notifier); 1369 register_netdevice_notifier(&fcoe_notifier);
1356} 1370}
1357 1371
1358/** 1372/**
1359 * fcoe_dev_setup() - cleanup link change notification interface 1373 * fcoe_dev_cleanup() - cleanup link change notification interface
1360 */ 1374 */
1361static void fcoe_dev_cleanup(void) 1375static void fcoe_dev_cleanup(void)
1362{ 1376{
@@ -1415,7 +1429,8 @@ static int fcoe_device_notification(struct notifier_block *notifier,
1415 case NETDEV_REGISTER: 1429 case NETDEV_REGISTER:
1416 break; 1430 break;
1417 default: 1431 default:
1418 FC_DBG("Unknown event %ld from netdev netlink\n", event); 1432 FCOE_NETDEV_DBG(real_dev, "Unknown event %ld "
1433 "from netdev netlink\n", event);
1419 } 1434 }
1420 if (link_possible && !fcoe_link_ok(lp)) 1435 if (link_possible && !fcoe_link_ok(lp))
1421 fcoe_ctlr_link_up(&fc->ctlr); 1436 fcoe_ctlr_link_up(&fc->ctlr);
@@ -1488,8 +1503,8 @@ static int fcoe_ethdrv_get(const struct net_device *netdev)
1488 1503
1489 owner = fcoe_netdev_to_module_owner(netdev); 1504 owner = fcoe_netdev_to_module_owner(netdev);
1490 if (owner) { 1505 if (owner) {
1491 printk(KERN_DEBUG "fcoe:hold driver module %s for %s\n", 1506 FCOE_NETDEV_DBG(netdev, "Hold driver module %s\n",
1492 module_name(owner), netdev->name); 1507 module_name(owner));
1493 return try_module_get(owner); 1508 return try_module_get(owner);
1494 } 1509 }
1495 return -ENODEV; 1510 return -ENODEV;
@@ -1510,8 +1525,8 @@ static int fcoe_ethdrv_put(const struct net_device *netdev)
1510 1525
1511 owner = fcoe_netdev_to_module_owner(netdev); 1526 owner = fcoe_netdev_to_module_owner(netdev);
1512 if (owner) { 1527 if (owner) {
1513 printk(KERN_DEBUG "fcoe:release driver module %s for %s\n", 1528 FCOE_NETDEV_DBG(netdev, "Release driver module %s\n",
1514 module_name(owner), netdev->name); 1529 module_name(owner));
1515 module_put(owner); 1530 module_put(owner);
1516 return 0; 1531 return 0;
1517 } 1532 }
@@ -1542,7 +1557,7 @@ static int fcoe_destroy(const char *buffer, struct kernel_param *kp)
1542 } 1557 }
1543 rc = fcoe_if_destroy(netdev); 1558 rc = fcoe_if_destroy(netdev);
1544 if (rc) { 1559 if (rc) {
1545 printk(KERN_ERR "fcoe: fcoe_if_destroy(%s) failed\n", 1560 printk(KERN_ERR "fcoe: Failed to destroy interface (%s)\n",
1546 netdev->name); 1561 netdev->name);
1547 rc = -EIO; 1562 rc = -EIO;
1548 goto out_putdev; 1563 goto out_putdev;
@@ -1581,7 +1596,7 @@ static int fcoe_create(const char *buffer, struct kernel_param *kp)
1581 1596
1582 rc = fcoe_if_create(netdev); 1597 rc = fcoe_if_create(netdev);
1583 if (rc) { 1598 if (rc) {
1584 printk(KERN_ERR "fcoe: fcoe_if_create(%s) failed\n", 1599 printk(KERN_ERR "fcoe: Failed to create interface (%s)\n",
1585 netdev->name); 1600 netdev->name);
1586 fcoe_ethdrv_put(netdev); 1601 fcoe_ethdrv_put(netdev);
1587 rc = -EIO; 1602 rc = -EIO;
@@ -1815,10 +1830,6 @@ static int __init fcoe_init(void)
1815 /* Setup link change notification */ 1830 /* Setup link change notification */
1816 fcoe_dev_setup(); 1831 fcoe_dev_setup();
1817 1832
1818 setup_timer(&fcoe_timer, fcoe_watchdog, 0);
1819
1820 mod_timer(&fcoe_timer, jiffies + (10 * HZ));
1821
1822 fcoe_if_init(); 1833 fcoe_if_init();
1823 1834
1824 return 0; 1835 return 0;
@@ -1844,9 +1855,6 @@ static void __exit fcoe_exit(void)
1844 1855
1845 fcoe_dev_cleanup(); 1856 fcoe_dev_cleanup();
1846 1857
1847 /* Stop the timer */
1848 del_timer_sync(&fcoe_timer);
1849
1850 /* releases the associated fcoe hosts */ 1858 /* releases the associated fcoe hosts */
1851 list_for_each_entry_safe(fc, tmp, &fcoe_hostlist, list) 1859 list_for_each_entry_safe(fc, tmp, &fcoe_hostlist, list)
1852 fcoe_if_destroy(fc->real_dev); 1860 fcoe_if_destroy(fc->real_dev);