aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/fcoe
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/fcoe')
-rw-r--r--drivers/scsi/fcoe/fcoe.c398
-rw-r--r--drivers/scsi/fcoe/fcoe.h25
-rw-r--r--drivers/scsi/fcoe/libfcoe.c125
3 files changed, 304 insertions, 244 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);
diff --git a/drivers/scsi/fcoe/fcoe.h b/drivers/scsi/fcoe/fcoe.h
index 917aae886897..0d724fa0898f 100644
--- a/drivers/scsi/fcoe/fcoe.h
+++ b/drivers/scsi/fcoe/fcoe.h
@@ -40,6 +40,30 @@
40#define FCOE_MIN_XID 0x0001 /* the min xid supported by fcoe_sw */ 40#define FCOE_MIN_XID 0x0001 /* the min xid supported by fcoe_sw */
41#define FCOE_MAX_XID 0x07ef /* the max xid supported by fcoe_sw */ 41#define FCOE_MAX_XID 0x07ef /* the max xid supported by fcoe_sw */
42 42
43unsigned int fcoe_debug_logging;
44module_param_named(debug_logging, fcoe_debug_logging, int, S_IRUGO|S_IWUSR);
45MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");
46
47#define FCOE_LOGGING 0x01 /* General logging, not categorized */
48#define FCOE_NETDEV_LOGGING 0x02 /* Netdevice logging */
49
50#define FCOE_CHECK_LOGGING(LEVEL, CMD) \
51do { \
52 if (unlikely(fcoe_debug_logging & LEVEL)) \
53 do { \
54 CMD; \
55 } while (0); \
56} while (0);
57
58#define FCOE_DBG(fmt, args...) \
59 FCOE_CHECK_LOGGING(FCOE_LOGGING, \
60 printk(KERN_INFO "fcoe: " fmt, ##args);)
61
62#define FCOE_NETDEV_DBG(netdev, fmt, args...) \
63 FCOE_CHECK_LOGGING(FCOE_NETDEV_LOGGING, \
64 printk(KERN_INFO "fcoe: %s" fmt, \
65 netdev->name, ##args);)
66
43/* 67/*
44 * this percpu struct for fcoe 68 * this percpu struct for fcoe
45 */ 69 */
@@ -61,6 +85,7 @@ struct fcoe_softc {
61 struct packet_type fip_packet_type; 85 struct packet_type fip_packet_type;
62 struct sk_buff_head fcoe_pending_queue; 86 struct sk_buff_head fcoe_pending_queue;
63 u8 fcoe_pending_queue_active; 87 u8 fcoe_pending_queue_active;
88 struct timer_list timer; /* queue timer */
64 struct fcoe_ctlr ctlr; 89 struct fcoe_ctlr ctlr;
65}; 90};
66 91
diff --git a/drivers/scsi/fcoe/libfcoe.c b/drivers/scsi/fcoe/libfcoe.c
index 62ba0f39c6bd..f544340d318b 100644
--- a/drivers/scsi/fcoe/libfcoe.c
+++ b/drivers/scsi/fcoe/libfcoe.c
@@ -56,15 +56,28 @@ static void fcoe_ctlr_recv_work(struct work_struct *);
56 56
57static u8 fcoe_all_fcfs[ETH_ALEN] = FIP_ALL_FCF_MACS; 57static u8 fcoe_all_fcfs[ETH_ALEN] = FIP_ALL_FCF_MACS;
58 58
59static u32 fcoe_ctlr_debug; /* 1 for basic, 2 for noisy debug */ 59unsigned int libfcoe_debug_logging;
60module_param_named(debug_logging, libfcoe_debug_logging, int, S_IRUGO|S_IWUSR);
61MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");
60 62
61#define FIP_DBG_LVL(level, fmt, args...) \ 63#define LIBFCOE_LOGGING 0x01 /* General logging, not categorized */
64#define LIBFCOE_FIP_LOGGING 0x02 /* FIP logging */
65
66#define LIBFCOE_CHECK_LOGGING(LEVEL, CMD) \
67do { \
68 if (unlikely(libfcoe_debug_logging & LEVEL)) \
62 do { \ 69 do { \
63 if (fcoe_ctlr_debug >= (level)) \ 70 CMD; \
64 FC_DBG(fmt, ##args); \ 71 } while (0); \
65 } while (0) 72} while (0);
73
74#define LIBFCOE_DBG(fmt, args...) \
75 LIBFCOE_CHECK_LOGGING(LIBFCOE_LOGGING, \
76 printk(KERN_INFO "libfcoe: " fmt, ##args);)
66 77
67#define FIP_DBG(fmt, args...) FIP_DBG_LVL(1, fmt, ##args) 78#define LIBFCOE_FIP_DBG(fmt, args...) \
79 LIBFCOE_CHECK_LOGGING(LIBFCOE_FIP_LOGGING, \
80 printk(KERN_INFO "fip: " fmt, ##args);)
68 81
69/* 82/*
70 * Return non-zero if FCF fcoe_size has been validated. 83 * Return non-zero if FCF fcoe_size has been validated.
@@ -198,6 +211,8 @@ static void fcoe_ctlr_solicit(struct fcoe_ctlr *fip, struct fcoe_fcf *fcf)
198 sol->fip.fip_subcode = FIP_SC_SOL; 211 sol->fip.fip_subcode = FIP_SC_SOL;
199 sol->fip.fip_dl_len = htons(sizeof(sol->desc) / FIP_BPW); 212 sol->fip.fip_dl_len = htons(sizeof(sol->desc) / FIP_BPW);
200 sol->fip.fip_flags = htons(FIP_FL_FPMA); 213 sol->fip.fip_flags = htons(FIP_FL_FPMA);
214 if (fip->spma)
215 sol->fip.fip_flags |= htons(FIP_FL_SPMA);
201 216
202 sol->desc.mac.fd_desc.fip_dtype = FIP_DT_MAC; 217 sol->desc.mac.fd_desc.fip_dtype = FIP_DT_MAC;
203 sol->desc.mac.fd_desc.fip_dlen = sizeof(sol->desc.mac) / FIP_BPW; 218 sol->desc.mac.fd_desc.fip_dlen = sizeof(sol->desc.mac) / FIP_BPW;
@@ -213,7 +228,7 @@ static void fcoe_ctlr_solicit(struct fcoe_ctlr *fip, struct fcoe_fcf *fcf)
213 sol->desc.size.fd_size = htons(fcoe_size); 228 sol->desc.size.fd_size = htons(fcoe_size);
214 229
215 skb_put(skb, sizeof(*sol)); 230 skb_put(skb, sizeof(*sol));
216 skb->protocol = htons(ETH_P_802_3); 231 skb->protocol = htons(ETH_P_FIP);
217 skb_reset_mac_header(skb); 232 skb_reset_mac_header(skb);
218 skb_reset_network_header(skb); 233 skb_reset_network_header(skb);
219 fip->send(fip, skb); 234 fip->send(fip, skb);
@@ -241,7 +256,7 @@ void fcoe_ctlr_link_up(struct fcoe_ctlr *fip)
241 fip->last_link = 1; 256 fip->last_link = 1;
242 fip->link = 1; 257 fip->link = 1;
243 spin_unlock_bh(&fip->lock); 258 spin_unlock_bh(&fip->lock);
244 FIP_DBG("%s", "setting AUTO mode.\n"); 259 LIBFCOE_FIP_DBG("%s", "setting AUTO mode.\n");
245 fc_linkup(fip->lp); 260 fc_linkup(fip->lp);
246 fcoe_ctlr_solicit(fip, NULL); 261 fcoe_ctlr_solicit(fip, NULL);
247 } else 262 } else
@@ -350,6 +365,8 @@ static void fcoe_ctlr_send_keep_alive(struct fcoe_ctlr *fip, int ports, u8 *sa)
350 kal->fip.fip_dl_len = htons((sizeof(kal->mac) + 365 kal->fip.fip_dl_len = htons((sizeof(kal->mac) +
351 ports * sizeof(*vn)) / FIP_BPW); 366 ports * sizeof(*vn)) / FIP_BPW);
352 kal->fip.fip_flags = htons(FIP_FL_FPMA); 367 kal->fip.fip_flags = htons(FIP_FL_FPMA);
368 if (fip->spma)
369 kal->fip.fip_flags |= htons(FIP_FL_SPMA);
353 370
354 kal->mac.fd_desc.fip_dtype = FIP_DT_MAC; 371 kal->mac.fd_desc.fip_dtype = FIP_DT_MAC;
355 kal->mac.fd_desc.fip_dlen = sizeof(kal->mac) / FIP_BPW; 372 kal->mac.fd_desc.fip_dlen = sizeof(kal->mac) / FIP_BPW;
@@ -365,7 +382,7 @@ static void fcoe_ctlr_send_keep_alive(struct fcoe_ctlr *fip, int ports, u8 *sa)
365 } 382 }
366 383
367 skb_put(skb, len); 384 skb_put(skb, len);
368 skb->protocol = htons(ETH_P_802_3); 385 skb->protocol = htons(ETH_P_FIP);
369 skb_reset_mac_header(skb); 386 skb_reset_mac_header(skb);
370 skb_reset_network_header(skb); 387 skb_reset_network_header(skb);
371 fip->send(fip, skb); 388 fip->send(fip, skb);
@@ -413,6 +430,8 @@ static int fcoe_ctlr_encaps(struct fcoe_ctlr *fip,
413 cap->fip.fip_subcode = FIP_SC_REQ; 430 cap->fip.fip_subcode = FIP_SC_REQ;
414 cap->fip.fip_dl_len = htons((dlen + sizeof(*mac)) / FIP_BPW); 431 cap->fip.fip_dl_len = htons((dlen + sizeof(*mac)) / FIP_BPW);
415 cap->fip.fip_flags = htons(FIP_FL_FPMA); 432 cap->fip.fip_flags = htons(FIP_FL_FPMA);
433 if (fip->spma)
434 cap->fip.fip_flags |= htons(FIP_FL_SPMA);
416 435
417 cap->encaps.fd_desc.fip_dtype = dtype; 436 cap->encaps.fd_desc.fip_dtype = dtype;
418 cap->encaps.fd_desc.fip_dlen = dlen / FIP_BPW; 437 cap->encaps.fd_desc.fip_dlen = dlen / FIP_BPW;
@@ -421,10 +440,12 @@ static int fcoe_ctlr_encaps(struct fcoe_ctlr *fip,
421 memset(mac, 0, sizeof(mac)); 440 memset(mac, 0, sizeof(mac));
422 mac->fd_desc.fip_dtype = FIP_DT_MAC; 441 mac->fd_desc.fip_dtype = FIP_DT_MAC;
423 mac->fd_desc.fip_dlen = sizeof(*mac) / FIP_BPW; 442 mac->fd_desc.fip_dlen = sizeof(*mac) / FIP_BPW;
424 if (dtype != ELS_FLOGI) 443 if (dtype != FIP_DT_FLOGI)
425 memcpy(mac->fd_mac, fip->data_src_addr, ETH_ALEN); 444 memcpy(mac->fd_mac, fip->data_src_addr, ETH_ALEN);
445 else if (fip->spma)
446 memcpy(mac->fd_mac, fip->ctl_src_addr, ETH_ALEN);
426 447
427 skb->protocol = htons(ETH_P_802_3); 448 skb->protocol = htons(ETH_P_FIP);
428 skb_reset_mac_header(skb); 449 skb_reset_mac_header(skb);
429 skb_reset_network_header(skb); 450 skb_reset_network_header(skb);
430 return 0; 451 return 0;
@@ -447,14 +468,10 @@ int fcoe_ctlr_els_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
447 u16 old_xid; 468 u16 old_xid;
448 u8 op; 469 u8 op;
449 470
450 if (fip->state == FIP_ST_NON_FIP)
451 return 0;
452
453 fh = (struct fc_frame_header *)skb->data; 471 fh = (struct fc_frame_header *)skb->data;
454 op = *(u8 *)(fh + 1); 472 op = *(u8 *)(fh + 1);
455 473
456 switch (op) { 474 if (op == ELS_FLOGI) {
457 case ELS_FLOGI:
458 old_xid = fip->flogi_oxid; 475 old_xid = fip->flogi_oxid;
459 fip->flogi_oxid = ntohs(fh->fh_ox_id); 476 fip->flogi_oxid = ntohs(fh->fh_ox_id);
460 if (fip->state == FIP_ST_AUTO) { 477 if (fip->state == FIP_ST_AUTO) {
@@ -466,6 +483,15 @@ int fcoe_ctlr_els_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
466 fip->map_dest = 1; 483 fip->map_dest = 1;
467 return 0; 484 return 0;
468 } 485 }
486 if (fip->state == FIP_ST_NON_FIP)
487 fip->map_dest = 1;
488 }
489
490 if (fip->state == FIP_ST_NON_FIP)
491 return 0;
492
493 switch (op) {
494 case ELS_FLOGI:
469 op = FIP_DT_FLOGI; 495 op = FIP_DT_FLOGI;
470 break; 496 break;
471 case ELS_FDISC: 497 case ELS_FDISC:
@@ -601,7 +627,8 @@ static int fcoe_ctlr_parse_adv(struct sk_buff *skb, struct fcoe_fcf *fcf)
601 ((struct fip_mac_desc *)desc)->fd_mac, 627 ((struct fip_mac_desc *)desc)->fd_mac,
602 ETH_ALEN); 628 ETH_ALEN);
603 if (!is_valid_ether_addr(fcf->fcf_mac)) { 629 if (!is_valid_ether_addr(fcf->fcf_mac)) {
604 FIP_DBG("invalid MAC addr in FIP adv\n"); 630 LIBFCOE_FIP_DBG("Invalid MAC address "
631 "in FIP adv\n");
605 return -EINVAL; 632 return -EINVAL;
606 } 633 }
607 break; 634 break;
@@ -634,8 +661,8 @@ static int fcoe_ctlr_parse_adv(struct sk_buff *skb, struct fcoe_fcf *fcf)
634 case FIP_DT_LOGO: 661 case FIP_DT_LOGO:
635 case FIP_DT_ELP: 662 case FIP_DT_ELP:
636 default: 663 default:
637 FIP_DBG("unexpected descriptor type %x in FIP adv\n", 664 LIBFCOE_FIP_DBG("unexpected descriptor type %x "
638 desc->fip_dtype); 665 "in FIP adv\n", desc->fip_dtype);
639 /* standard says ignore unknown descriptors >= 128 */ 666 /* standard says ignore unknown descriptors >= 128 */
640 if (desc->fip_dtype < FIP_DT_VENDOR_BASE) 667 if (desc->fip_dtype < FIP_DT_VENDOR_BASE)
641 return -EINVAL; 668 return -EINVAL;
@@ -651,8 +678,8 @@ static int fcoe_ctlr_parse_adv(struct sk_buff *skb, struct fcoe_fcf *fcf)
651 return 0; 678 return 0;
652 679
653len_err: 680len_err:
654 FIP_DBG("FIP length error in descriptor type %x len %zu\n", 681 LIBFCOE_FIP_DBG("FIP length error in descriptor type %x len %zu\n",
655 desc->fip_dtype, dlen); 682 desc->fip_dtype, dlen);
656 return -EINVAL; 683 return -EINVAL;
657} 684}
658 685
@@ -715,9 +742,10 @@ static void fcoe_ctlr_recv_adv(struct fcoe_ctlr *fip, struct sk_buff *skb)
715 } 742 }
716 mtu_valid = fcoe_ctlr_mtu_valid(fcf); 743 mtu_valid = fcoe_ctlr_mtu_valid(fcf);
717 fcf->time = jiffies; 744 fcf->time = jiffies;
718 FIP_DBG_LVL(found ? 2 : 1, "%s FCF for fab %llx map %x val %d\n", 745 if (!found) {
719 found ? "old" : "new", 746 LIBFCOE_FIP_DBG("New FCF for fab %llx map %x val %d\n",
720 fcf->fabric_name, fcf->fc_map, mtu_valid); 747 fcf->fabric_name, fcf->fc_map, mtu_valid);
748 }
721 749
722 /* 750 /*
723 * If this advertisement is not solicited and our max receive size 751 * If this advertisement is not solicited and our max receive size
@@ -794,7 +822,8 @@ static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb)
794 ((struct fip_mac_desc *)desc)->fd_mac, 822 ((struct fip_mac_desc *)desc)->fd_mac,
795 ETH_ALEN); 823 ETH_ALEN);
796 if (!is_valid_ether_addr(granted_mac)) { 824 if (!is_valid_ether_addr(granted_mac)) {
797 FIP_DBG("invalid MAC addrs in FIP ELS\n"); 825 LIBFCOE_FIP_DBG("Invalid MAC address "
826 "in FIP ELS\n");
798 goto drop; 827 goto drop;
799 } 828 }
800 break; 829 break;
@@ -812,8 +841,8 @@ static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb)
812 els_dtype = desc->fip_dtype; 841 els_dtype = desc->fip_dtype;
813 break; 842 break;
814 default: 843 default:
815 FIP_DBG("unexpected descriptor type %x " 844 LIBFCOE_FIP_DBG("unexpected descriptor type %x "
816 "in FIP adv\n", desc->fip_dtype); 845 "in FIP adv\n", desc->fip_dtype);
817 /* standard says ignore unknown descriptors >= 128 */ 846 /* standard says ignore unknown descriptors >= 128 */
818 if (desc->fip_dtype < FIP_DT_VENDOR_BASE) 847 if (desc->fip_dtype < FIP_DT_VENDOR_BASE)
819 goto drop; 848 goto drop;
@@ -854,8 +883,8 @@ static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb)
854 return; 883 return;
855 884
856len_err: 885len_err:
857 FIP_DBG("FIP length error in descriptor type %x len %zu\n", 886 LIBFCOE_FIP_DBG("FIP length error in descriptor type %x len %zu\n",
858 desc->fip_dtype, dlen); 887 desc->fip_dtype, dlen);
859drop: 888drop:
860 kfree_skb(skb); 889 kfree_skb(skb);
861} 890}
@@ -881,7 +910,7 @@ static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip,
881 struct fc_lport *lp = fip->lp; 910 struct fc_lport *lp = fip->lp;
882 u32 desc_mask; 911 u32 desc_mask;
883 912
884 FIP_DBG("Clear Virtual Link received\n"); 913 LIBFCOE_FIP_DBG("Clear Virtual Link received\n");
885 if (!fcf) 914 if (!fcf)
886 return; 915 return;
887 if (!fcf || !fc_host_port_id(lp->host)) 916 if (!fcf || !fc_host_port_id(lp->host))
@@ -939,9 +968,9 @@ static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip,
939 * reset only if all required descriptors were present and valid. 968 * reset only if all required descriptors were present and valid.
940 */ 969 */
941 if (desc_mask) { 970 if (desc_mask) {
942 FIP_DBG("missing descriptors mask %x\n", desc_mask); 971 LIBFCOE_FIP_DBG("missing descriptors mask %x\n", desc_mask);
943 } else { 972 } else {
944 FIP_DBG("performing Clear Virtual Link\n"); 973 LIBFCOE_FIP_DBG("performing Clear Virtual Link\n");
945 fcoe_ctlr_reset(fip, FIP_ST_ENABLED); 974 fcoe_ctlr_reset(fip, FIP_ST_ENABLED);
946 } 975 }
947} 976}
@@ -989,10 +1018,6 @@ static int fcoe_ctlr_recv_handler(struct fcoe_ctlr *fip, struct sk_buff *skb)
989 op = ntohs(fiph->fip_op); 1018 op = ntohs(fiph->fip_op);
990 sub = fiph->fip_subcode; 1019 sub = fiph->fip_subcode;
991 1020
992 FIP_DBG_LVL(2, "ver %x op %x/%x dl %x fl %x\n",
993 FIP_VER_DECAPS(fiph->fip_ver), op, sub,
994 ntohs(fiph->fip_dl_len), ntohs(fiph->fip_flags));
995
996 if (FIP_VER_DECAPS(fiph->fip_ver) != FIP_VER) 1021 if (FIP_VER_DECAPS(fiph->fip_ver) != FIP_VER)
997 goto drop; 1022 goto drop;
998 if (ntohs(fiph->fip_dl_len) * FIP_BPW + sizeof(*fiph) > skb->len) 1023 if (ntohs(fiph->fip_dl_len) * FIP_BPW + sizeof(*fiph) > skb->len)
@@ -1004,7 +1029,7 @@ static int fcoe_ctlr_recv_handler(struct fcoe_ctlr *fip, struct sk_buff *skb)
1004 fip->map_dest = 0; 1029 fip->map_dest = 0;
1005 fip->state = FIP_ST_ENABLED; 1030 fip->state = FIP_ST_ENABLED;
1006 state = FIP_ST_ENABLED; 1031 state = FIP_ST_ENABLED;
1007 FIP_DBG("using FIP mode\n"); 1032 LIBFCOE_FIP_DBG("Using FIP mode\n");
1008 } 1033 }
1009 spin_unlock_bh(&fip->lock); 1034 spin_unlock_bh(&fip->lock);
1010 if (state != FIP_ST_ENABLED) 1035 if (state != FIP_ST_ENABLED)
@@ -1039,14 +1064,15 @@ static void fcoe_ctlr_select(struct fcoe_ctlr *fip)
1039 struct fcoe_fcf *best = NULL; 1064 struct fcoe_fcf *best = NULL;
1040 1065
1041 list_for_each_entry(fcf, &fip->fcfs, list) { 1066 list_for_each_entry(fcf, &fip->fcfs, list) {
1042 FIP_DBG("consider FCF for fab %llx VFID %d map %x val %d\n", 1067 LIBFCOE_FIP_DBG("consider FCF for fab %llx VFID %d map %x "
1043 fcf->fabric_name, fcf->vfid, 1068 "val %d\n", fcf->fabric_name, fcf->vfid,
1044 fcf->fc_map, fcoe_ctlr_mtu_valid(fcf)); 1069 fcf->fc_map, fcoe_ctlr_mtu_valid(fcf));
1045 if (!fcoe_ctlr_fcf_usable(fcf)) { 1070 if (!fcoe_ctlr_fcf_usable(fcf)) {
1046 FIP_DBG("FCF for fab %llx map %x %svalid %savailable\n", 1071 LIBFCOE_FIP_DBG("FCF for fab %llx map %x %svalid "
1047 fcf->fabric_name, fcf->fc_map, 1072 "%savailable\n", fcf->fabric_name,
1048 (fcf->flags & FIP_FL_SOL) ? "" : "in", 1073 fcf->fc_map, (fcf->flags & FIP_FL_SOL)
1049 (fcf->flags & FIP_FL_AVAIL) ? "" : "un"); 1074 ? "" : "in", (fcf->flags & FIP_FL_AVAIL)
1075 ? "" : "un");
1050 continue; 1076 continue;
1051 } 1077 }
1052 if (!best) { 1078 if (!best) {
@@ -1056,7 +1082,8 @@ static void fcoe_ctlr_select(struct fcoe_ctlr *fip)
1056 if (fcf->fabric_name != best->fabric_name || 1082 if (fcf->fabric_name != best->fabric_name ||
1057 fcf->vfid != best->vfid || 1083 fcf->vfid != best->vfid ||
1058 fcf->fc_map != best->fc_map) { 1084 fcf->fc_map != best->fc_map) {
1059 FIP_DBG("conflicting fabric, VFID, or FC-MAP\n"); 1085 LIBFCOE_FIP_DBG("Conflicting fabric, VFID, "
1086 "or FC-MAP\n");
1060 return; 1087 return;
1061 } 1088 }
1062 if (fcf->pri < best->pri) 1089 if (fcf->pri < best->pri)
@@ -1100,7 +1127,7 @@ static void fcoe_ctlr_timeout(unsigned long arg)
1100 if (sel != fcf) { 1127 if (sel != fcf) {
1101 fcf = sel; /* the old FCF may have been freed */ 1128 fcf = sel; /* the old FCF may have been freed */
1102 if (sel) { 1129 if (sel) {
1103 printk(KERN_INFO "host%d: FIP selected " 1130 printk(KERN_INFO "libfcoe: host%d: FIP selected "
1104 "Fibre-Channel Forwarder MAC %s\n", 1131 "Fibre-Channel Forwarder MAC %s\n",
1105 fip->lp->host->host_no, 1132 fip->lp->host->host_no,
1106 print_mac(buf, sel->fcf_mac)); 1133 print_mac(buf, sel->fcf_mac));
@@ -1110,7 +1137,7 @@ static void fcoe_ctlr_timeout(unsigned long arg)
1110 fip->ctlr_ka_time = jiffies + sel->fka_period; 1137 fip->ctlr_ka_time = jiffies + sel->fka_period;
1111 fip->link = 1; 1138 fip->link = 1;
1112 } else { 1139 } else {
1113 printk(KERN_NOTICE "host%d: " 1140 printk(KERN_NOTICE "libfcoe: host%d: "
1114 "FIP Fibre-Channel Forwarder timed out. " 1141 "FIP Fibre-Channel Forwarder timed out. "
1115 "Starting FCF discovery.\n", 1142 "Starting FCF discovery.\n",
1116 fip->lp->host->host_no); 1143 fip->lp->host->host_no);
@@ -1234,7 +1261,7 @@ int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *fip, struct fc_frame *fp, u8 *sa)
1234 return -EINVAL; 1261 return -EINVAL;
1235 } 1262 }
1236 fip->state = FIP_ST_NON_FIP; 1263 fip->state = FIP_ST_NON_FIP;
1237 FIP_DBG("received FLOGI LS_ACC using non-FIP mode\n"); 1264 LIBFCOE_FIP_DBG("received FLOGI LS_ACC using non-FIP mode\n");
1238 1265
1239 /* 1266 /*
1240 * FLOGI accepted. 1267 * FLOGI accepted.
@@ -1263,7 +1290,7 @@ int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *fip, struct fc_frame *fp, u8 *sa)
1263 memcpy(fip->dest_addr, sa, ETH_ALEN); 1290 memcpy(fip->dest_addr, sa, ETH_ALEN);
1264 fip->map_dest = 0; 1291 fip->map_dest = 0;
1265 if (fip->state == FIP_ST_NON_FIP) 1292 if (fip->state == FIP_ST_NON_FIP)
1266 FIP_DBG("received FLOGI REQ, " 1293 LIBFCOE_FIP_DBG("received FLOGI REQ, "
1267 "using non-FIP mode\n"); 1294 "using non-FIP mode\n");
1268 fip->state = FIP_ST_NON_FIP; 1295 fip->state = FIP_ST_NON_FIP;
1269 } 1296 }