aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/bonding/bond_main.c
diff options
context:
space:
mode:
authorStephen Hemminger <shemminger@vyatta.com>2008-11-20 00:56:05 -0500
committerDavid S. Miller <davem@davemloft.net>2008-11-20 01:42:42 -0500
commiteb7cc59a038b4e1914ae991d313f35904924759f (patch)
tree4f4af2bd1e4e86582b45e9ce18ca88fcff287665 /drivers/net/bonding/bond_main.c
parent656299f706e52e0409733d704c2761f1b12d6954 (diff)
bonding: convert to net_device_ops
Convert to net_device_ops table. Note: for some operations move error checking into generic networking layer (rather than looking at pointers in bonding). A couple of gratituous style cleanups to get rid of extra {} Signed-off-by: Stephen Hemminger <shemminger@vyatta.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/bonding/bond_main.c')
-rw-r--r--drivers/net/bonding/bond_main.c92
1 files changed, 49 insertions, 43 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index db5f5c24a250..614656c8187b 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -462,10 +462,11 @@ static void bond_vlan_rx_register(struct net_device *bond_dev, struct vlan_group
462 462
463 bond_for_each_slave(bond, slave, i) { 463 bond_for_each_slave(bond, slave, i) {
464 struct net_device *slave_dev = slave->dev; 464 struct net_device *slave_dev = slave->dev;
465 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
465 466
466 if ((slave_dev->features & NETIF_F_HW_VLAN_RX) && 467 if ((slave_dev->features & NETIF_F_HW_VLAN_RX) &&
467 slave_dev->vlan_rx_register) { 468 slave_ops->ndo_vlan_rx_register) {
468 slave_dev->vlan_rx_register(slave_dev, grp); 469 slave_ops->ndo_vlan_rx_register(slave_dev, grp);
469 } 470 }
470 } 471 }
471} 472}
@@ -483,10 +484,11 @@ static void bond_vlan_rx_add_vid(struct net_device *bond_dev, uint16_t vid)
483 484
484 bond_for_each_slave(bond, slave, i) { 485 bond_for_each_slave(bond, slave, i) {
485 struct net_device *slave_dev = slave->dev; 486 struct net_device *slave_dev = slave->dev;
487 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
486 488
487 if ((slave_dev->features & NETIF_F_HW_VLAN_FILTER) && 489 if ((slave_dev->features & NETIF_F_HW_VLAN_FILTER) &&
488 slave_dev->vlan_rx_add_vid) { 490 slave_ops->ndo_vlan_rx_add_vid) {
489 slave_dev->vlan_rx_add_vid(slave_dev, vid); 491 slave_ops->ndo_vlan_rx_add_vid(slave_dev, vid);
490 } 492 }
491 } 493 }
492 494
@@ -512,14 +514,15 @@ static void bond_vlan_rx_kill_vid(struct net_device *bond_dev, uint16_t vid)
512 514
513 bond_for_each_slave(bond, slave, i) { 515 bond_for_each_slave(bond, slave, i) {
514 struct net_device *slave_dev = slave->dev; 516 struct net_device *slave_dev = slave->dev;
517 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
515 518
516 if ((slave_dev->features & NETIF_F_HW_VLAN_FILTER) && 519 if ((slave_dev->features & NETIF_F_HW_VLAN_FILTER) &&
517 slave_dev->vlan_rx_kill_vid) { 520 slave_ops->ndo_vlan_rx_kill_vid) {
518 /* Save and then restore vlan_dev in the grp array, 521 /* Save and then restore vlan_dev in the grp array,
519 * since the slave's driver might clear it. 522 * since the slave's driver might clear it.
520 */ 523 */
521 vlan_dev = vlan_group_get_device(bond->vlgrp, vid); 524 vlan_dev = vlan_group_get_device(bond->vlgrp, vid);
522 slave_dev->vlan_rx_kill_vid(slave_dev, vid); 525 slave_ops->ndo_vlan_rx_kill_vid(slave_dev, vid);
523 vlan_group_set_device(bond->vlgrp, vid, vlan_dev); 526 vlan_group_set_device(bond->vlgrp, vid, vlan_dev);
524 } 527 }
525 } 528 }
@@ -535,26 +538,23 @@ static void bond_vlan_rx_kill_vid(struct net_device *bond_dev, uint16_t vid)
535static void bond_add_vlans_on_slave(struct bonding *bond, struct net_device *slave_dev) 538static void bond_add_vlans_on_slave(struct bonding *bond, struct net_device *slave_dev)
536{ 539{
537 struct vlan_entry *vlan; 540 struct vlan_entry *vlan;
541 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
538 542
539 write_lock_bh(&bond->lock); 543 write_lock_bh(&bond->lock);
540 544
541 if (list_empty(&bond->vlan_list)) { 545 if (list_empty(&bond->vlan_list))
542 goto out; 546 goto out;
543 }
544 547
545 if ((slave_dev->features & NETIF_F_HW_VLAN_RX) && 548 if ((slave_dev->features & NETIF_F_HW_VLAN_RX) &&
546 slave_dev->vlan_rx_register) { 549 slave_ops->ndo_vlan_rx_register)
547 slave_dev->vlan_rx_register(slave_dev, bond->vlgrp); 550 slave_ops->ndo_vlan_rx_register(slave_dev, bond->vlgrp);
548 }
549 551
550 if (!(slave_dev->features & NETIF_F_HW_VLAN_FILTER) || 552 if (!(slave_dev->features & NETIF_F_HW_VLAN_FILTER) ||
551 !(slave_dev->vlan_rx_add_vid)) { 553 !(slave_ops->ndo_vlan_rx_add_vid))
552 goto out; 554 goto out;
553 }
554 555
555 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { 556 list_for_each_entry(vlan, &bond->vlan_list, vlan_list)
556 slave_dev->vlan_rx_add_vid(slave_dev, vlan->vlan_id); 557 slave_ops->ndo_vlan_rx_add_vid(slave_dev, vlan->vlan_id);
557 }
558 558
559out: 559out:
560 write_unlock_bh(&bond->lock); 560 write_unlock_bh(&bond->lock);
@@ -562,34 +562,32 @@ out:
562 562
563static void bond_del_vlans_from_slave(struct bonding *bond, struct net_device *slave_dev) 563static void bond_del_vlans_from_slave(struct bonding *bond, struct net_device *slave_dev)
564{ 564{
565 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
565 struct vlan_entry *vlan; 566 struct vlan_entry *vlan;
566 struct net_device *vlan_dev; 567 struct net_device *vlan_dev;
567 568
568 write_lock_bh(&bond->lock); 569 write_lock_bh(&bond->lock);
569 570
570 if (list_empty(&bond->vlan_list)) { 571 if (list_empty(&bond->vlan_list))
571 goto out; 572 goto out;
572 }
573 573
574 if (!(slave_dev->features & NETIF_F_HW_VLAN_FILTER) || 574 if (!(slave_dev->features & NETIF_F_HW_VLAN_FILTER) ||
575 !(slave_dev->vlan_rx_kill_vid)) { 575 !(slave_ops->ndo_vlan_rx_kill_vid))
576 goto unreg; 576 goto unreg;
577 }
578 577
579 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { 578 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
580 /* Save and then restore vlan_dev in the grp array, 579 /* Save and then restore vlan_dev in the grp array,
581 * since the slave's driver might clear it. 580 * since the slave's driver might clear it.
582 */ 581 */
583 vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id); 582 vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
584 slave_dev->vlan_rx_kill_vid(slave_dev, vlan->vlan_id); 583 slave_ops->ndo_vlan_rx_kill_vid(slave_dev, vlan->vlan_id);
585 vlan_group_set_device(bond->vlgrp, vlan->vlan_id, vlan_dev); 584 vlan_group_set_device(bond->vlgrp, vlan->vlan_id, vlan_dev);
586 } 585 }
587 586
588unreg: 587unreg:
589 if ((slave_dev->features & NETIF_F_HW_VLAN_RX) && 588 if ((slave_dev->features & NETIF_F_HW_VLAN_RX) &&
590 slave_dev->vlan_rx_register) { 589 slave_ops->ndo_vlan_rx_register)
591 slave_dev->vlan_rx_register(slave_dev, NULL); 590 slave_ops->ndo_vlan_rx_register(slave_dev, NULL);
592 }
593 591
594out: 592out:
595 write_unlock_bh(&bond->lock); 593 write_unlock_bh(&bond->lock);
@@ -698,15 +696,15 @@ static int bond_update_speed_duplex(struct slave *slave)
698 */ 696 */
699static int bond_check_dev_link(struct bonding *bond, struct net_device *slave_dev, int reporting) 697static int bond_check_dev_link(struct bonding *bond, struct net_device *slave_dev, int reporting)
700{ 698{
699 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
701 static int (* ioctl)(struct net_device *, struct ifreq *, int); 700 static int (* ioctl)(struct net_device *, struct ifreq *, int);
702 struct ifreq ifr; 701 struct ifreq ifr;
703 struct mii_ioctl_data *mii; 702 struct mii_ioctl_data *mii;
704 703
705 if (bond->params.use_carrier) { 704 if (bond->params.use_carrier)
706 return netif_carrier_ok(slave_dev) ? BMSR_LSTATUS : 0; 705 return netif_carrier_ok(slave_dev) ? BMSR_LSTATUS : 0;
707 }
708 706
709 ioctl = slave_dev->do_ioctl; 707 ioctl = slave_ops->ndo_do_ioctl;
710 if (ioctl) { 708 if (ioctl) {
711 /* TODO: set pointer to correct ioctl on a per team member */ 709 /* TODO: set pointer to correct ioctl on a per team member */
712 /* bases to make this more efficient. that is, once */ 710 /* bases to make this more efficient. that is, once */
@@ -1401,6 +1399,7 @@ static void bond_setup_by_slave(struct net_device *bond_dev,
1401int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) 1399int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1402{ 1400{
1403 struct bonding *bond = netdev_priv(bond_dev); 1401 struct bonding *bond = netdev_priv(bond_dev);
1402 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
1404 struct slave *new_slave = NULL; 1403 struct slave *new_slave = NULL;
1405 struct dev_mc_list *dmi; 1404 struct dev_mc_list *dmi;
1406 struct sockaddr addr; 1405 struct sockaddr addr;
@@ -1409,7 +1408,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1409 int res = 0; 1408 int res = 0;
1410 1409
1411 if (!bond->params.use_carrier && slave_dev->ethtool_ops == NULL && 1410 if (!bond->params.use_carrier && slave_dev->ethtool_ops == NULL &&
1412 slave_dev->do_ioctl == NULL) { 1411 slave_ops->ndo_do_ioctl == NULL) {
1413 printk(KERN_WARNING DRV_NAME 1412 printk(KERN_WARNING DRV_NAME
1414 ": %s: Warning: no link monitoring support for %s\n", 1413 ": %s: Warning: no link monitoring support for %s\n",
1415 bond_dev->name, slave_dev->name); 1414 bond_dev->name, slave_dev->name);
@@ -1491,7 +1490,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1491 goto err_undo_flags; 1490 goto err_undo_flags;
1492 } 1491 }
1493 1492
1494 if (slave_dev->set_mac_address == NULL) { 1493 if (slave_ops->ndo_set_mac_address == NULL) {
1495 if (bond->slave_cnt == 0) { 1494 if (bond->slave_cnt == 0) {
1496 printk(KERN_WARNING DRV_NAME 1495 printk(KERN_WARNING DRV_NAME
1497 ": %s: Warning: The first slave device " 1496 ": %s: Warning: The first slave device "
@@ -4208,6 +4207,10 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr)
4208 int res = 0; 4207 int res = 0;
4209 int i; 4208 int i;
4210 4209
4210 if (bond->params.mode == BOND_MODE_ALB)
4211 return bond_alb_set_mac_address(bond_dev, addr);
4212
4213
4211 dprintk("bond=%p, name=%s\n", bond, (bond_dev ? bond_dev->name : "None")); 4214 dprintk("bond=%p, name=%s\n", bond, (bond_dev ? bond_dev->name : "None"));
4212 4215
4213 /* 4216 /*
@@ -4237,9 +4240,10 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr)
4237 */ 4240 */
4238 4241
4239 bond_for_each_slave(bond, slave, i) { 4242 bond_for_each_slave(bond, slave, i) {
4243 const struct net_device_ops *slave_ops = slave->dev->netdev_ops;
4240 dprintk("slave %p %s\n", slave, slave->dev->name); 4244 dprintk("slave %p %s\n", slave, slave->dev->name);
4241 4245
4242 if (slave->dev->set_mac_address == NULL) { 4246 if (slave_ops->ndo_set_mac_address == NULL) {
4243 res = -EOPNOTSUPP; 4247 res = -EOPNOTSUPP;
4244 dprintk("EOPNOTSUPP %s\n", slave->dev->name); 4248 dprintk("EOPNOTSUPP %s\n", slave->dev->name);
4245 goto unwind; 4249 goto unwind;
@@ -4517,7 +4521,6 @@ void bond_set_mode_ops(struct bonding *bond, int mode)
4517 /* FALLTHRU */ 4521 /* FALLTHRU */
4518 case BOND_MODE_TLB: 4522 case BOND_MODE_TLB:
4519 bond_dev->hard_start_xmit = bond_alb_xmit; 4523 bond_dev->hard_start_xmit = bond_alb_xmit;
4520 bond_dev->set_mac_address = bond_alb_set_mac_address;
4521 break; 4524 break;
4522 default: 4525 default:
4523 /* Should never happen, mode already checked */ 4526 /* Should never happen, mode already checked */
@@ -4547,6 +4550,20 @@ static const struct ethtool_ops bond_ethtool_ops = {
4547 .get_flags = ethtool_op_get_flags, 4550 .get_flags = ethtool_op_get_flags,
4548}; 4551};
4549 4552
4553static const struct net_device_ops bond_netdev_ops = {
4554 .ndo_open = bond_open,
4555 .ndo_stop = bond_close,
4556 .ndo_get_stats = bond_get_stats,
4557 .ndo_do_ioctl = bond_do_ioctl,
4558 .ndo_set_multicast_list = bond_set_multicast_list,
4559 .ndo_change_mtu = bond_change_mtu,
4560 .ndo_validate_addr = NULL,
4561 .ndo_set_mac_address = bond_set_mac_address,
4562 .ndo_vlan_rx_register = bond_vlan_rx_register,
4563 .ndo_vlan_rx_add_vid = bond_vlan_rx_add_vid,
4564 .ndo_vlan_rx_kill_vid = bond_vlan_rx_kill_vid,
4565};
4566
4550/* 4567/*
4551 * Does not allocate but creates a /proc entry. 4568 * Does not allocate but creates a /proc entry.
4552 * Allowed to fail. 4569 * Allowed to fail.
@@ -4579,16 +4596,8 @@ static int bond_init(struct net_device *bond_dev, struct bond_params *params)
4579 INIT_LIST_HEAD(&bond->vlan_list); 4596 INIT_LIST_HEAD(&bond->vlan_list);
4580 4597
4581 /* Initialize the device entry points */ 4598 /* Initialize the device entry points */
4582 bond_dev->open = bond_open; 4599 bond_dev->netdev_ops = &bond_netdev_ops;
4583 bond_dev->stop = bond_close;
4584 bond_dev->get_stats = bond_get_stats;
4585 bond_dev->do_ioctl = bond_do_ioctl;
4586 bond_dev->ethtool_ops = &bond_ethtool_ops; 4600 bond_dev->ethtool_ops = &bond_ethtool_ops;
4587 bond_dev->set_multicast_list = bond_set_multicast_list;
4588 bond_dev->change_mtu = bond_change_mtu;
4589 bond_dev->set_mac_address = bond_set_mac_address;
4590 bond_dev->validate_addr = NULL;
4591
4592 bond_set_mode_ops(bond, bond->params.mode); 4601 bond_set_mode_ops(bond, bond->params.mode);
4593 4602
4594 bond_dev->destructor = bond_destructor; 4603 bond_dev->destructor = bond_destructor;
@@ -4617,9 +4626,6 @@ static int bond_init(struct net_device *bond_dev, struct bond_params *params)
4617 * when there are slaves that are not hw accel 4626 * when there are slaves that are not hw accel
4618 * capable 4627 * capable
4619 */ 4628 */
4620 bond_dev->vlan_rx_register = bond_vlan_rx_register;
4621 bond_dev->vlan_rx_add_vid = bond_vlan_rx_add_vid;
4622 bond_dev->vlan_rx_kill_vid = bond_vlan_rx_kill_vid;
4623 bond_dev->features |= (NETIF_F_HW_VLAN_TX | 4629 bond_dev->features |= (NETIF_F_HW_VLAN_TX |
4624 NETIF_F_HW_VLAN_RX | 4630 NETIF_F_HW_VLAN_RX |
4625 NETIF_F_HW_VLAN_FILTER); 4631 NETIF_F_HW_VLAN_FILTER);