Skip to content

Commit

Permalink
netdev: add more functions to netdevice ops
Browse files Browse the repository at this point in the history
This patch moves neigh_setup and hard_start_xmit into the network device ops
structure. For bisection, fix all the previously converted drivers as well.
Bonding driver took the biggest hit on this.

Added a prefetch of the hard_start_xmit in the fast path to try and reduce
any impact this would have.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Stephen Hemminger authored and David S. Miller committed Nov 21, 2008
1 parent 6ab33d5 commit 0082982
Show file tree
Hide file tree
Showing 36 changed files with 183 additions and 93 deletions.
2 changes: 1 addition & 1 deletion drivers/net/8139cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,7 @@ static const struct net_device_ops cp_netdev_ops = {
.ndo_set_multicast_list = cp_set_rx_mode,
.ndo_get_stats = cp_get_stats,
.ndo_do_ioctl = cp_ioctl,
.ndo_start_xmit = cp_start_xmit,
.ndo_tx_timeout = cp_tx_timeout,
#if CP_VLAN_TAG_USED
.ndo_vlan_rx_register = cp_vlan_rx_register,
Expand Down Expand Up @@ -1949,7 +1950,6 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);

dev->netdev_ops = &cp_netdev_ops;
dev->hard_start_xmit = cp_start_xmit;
netif_napi_add(dev, &cp->napi, cp_rx_poll, 16);
dev->ethtool_ops = &cp_ethtool_ops;
dev->watchdog_timeo = TX_TIMEOUT;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/8139too.c
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ static const struct net_device_ops rtl8139_netdev_ops = {
.ndo_stop = rtl8139_close,
.ndo_get_stats = rtl8139_get_stats,
.ndo_validate_addr = eth_validate_addr,
.ndo_start_xmit = rtl8139_start_xmit,
.ndo_set_multicast_list = rtl8139_set_rx_mode,
.ndo_do_ioctl = netdev_ioctl,
.ndo_tx_timeout = rtl8139_tx_timeout,
Expand Down Expand Up @@ -992,7 +993,6 @@ static int __devinit rtl8139_init_one (struct pci_dev *pdev,
dev->netdev_ops = &rtl8139_netdev_ops;
dev->ethtool_ops = &rtl8139_ethtool_ops;
dev->watchdog_timeo = TX_TIMEOUT;
dev->hard_start_xmit = rtl8139_start_xmit;
netif_napi_add(dev, &tp->napi, rtl8139_poll, 64);

/* note: the hardware is not capable of sg/csum/highdma, however
Expand Down
4 changes: 3 additions & 1 deletion drivers/net/acenic.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,13 @@ static const struct net_device_ops ace_netdev_ops = {
.ndo_stop = ace_close,
.ndo_tx_timeout = ace_watchdog,
.ndo_get_stats = ace_get_stats,
.ndo_start_xmit = ace_start_xmit,
.ndo_set_multicast_list = ace_set_multicast_list,
.ndo_set_mac_address = ace_set_mac_addr,
.ndo_change_mtu = ace_change_mtu,
#if ACENIC_DO_VLAN
.ndo_vlan_rx_register = ace_vlan_rx_register,
#endif
};

static int __devinit acenic_probe_one(struct pci_dev *pdev,
Expand Down Expand Up @@ -489,7 +492,6 @@ static int __devinit acenic_probe_one(struct pci_dev *pdev,
dev->watchdog_timeo = 5*HZ;

dev->netdev_ops = &ace_netdev_ops;
dev->hard_start_xmit = &ace_start_xmit;
SET_ETHTOOL_OPS(dev, &ace_ethtool_ops);

/* we only display this string ONCE */
Expand Down
3 changes: 2 additions & 1 deletion drivers/net/atl1e/atl1e_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2256,6 +2256,7 @@ static void atl1e_shutdown(struct pci_dev *pdev)
static const struct net_device_ops atl1e_netdev_ops = {
.ndo_open = atl1e_open,
.ndo_stop = atl1e_close,
.ndo_start_xmit = atl1e_xmit_frame,
.ndo_get_stats = atl1e_get_stats,
.ndo_set_multicast_list = atl1e_set_multi,
.ndo_validate_addr = eth_validate_addr,
Expand All @@ -2277,7 +2278,7 @@ static int atl1e_init_netdev(struct net_device *netdev, struct pci_dev *pdev)

netdev->irq = pdev->irq;
netdev->netdev_ops = &atl1e_netdev_ops;
netdev->hard_start_xmit = atl1e_xmit_frame,

netdev->watchdog_timeo = AT_TX_WATCHDOG;
atl1e_set_ethtool_ops(netdev);

Expand Down
4 changes: 2 additions & 2 deletions drivers/net/atlx/atl1.c
Original file line number Diff line number Diff line change
Expand Up @@ -2883,12 +2883,13 @@ static void atl1_poll_controller(struct net_device *netdev)
static const struct net_device_ops atl1_netdev_ops = {
.ndo_open = atl1_open,
.ndo_stop = atl1_close,
.ndo_start_xmit = atl1_xmit_frame,
.ndo_set_multicast_list = atlx_set_multi,
.ndo_validate_addr = eth_validate_addr,
.ndo_set_mac_address = atl1_set_mac,
.ndo_change_mtu = atl1_change_mtu,
.ndo_do_ioctl = atlx_ioctl,
.ndo_tx_timeout = atlx_tx_timeout,
.ndo_tx_timeout = atlx_tx_timeout,
.ndo_vlan_rx_register = atlx_vlan_rx_register,
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = atl1_poll_controller,
Expand Down Expand Up @@ -2983,7 +2984,6 @@ static int __devinit atl1_probe(struct pci_dev *pdev,
adapter->mii.reg_num_mask = 0x1f;

netdev->netdev_ops = &atl1_netdev_ops;
netdev->hard_start_xmit = &atl1_xmit_frame;
netdev->watchdog_timeo = 5 * HZ;

netdev->ethtool_ops = &atl1_ethtool_ops;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/atlx/atl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,7 @@ static void atl2_poll_controller(struct net_device *netdev)
static const struct net_device_ops atl2_netdev_ops = {
.ndo_open = atl2_open,
.ndo_stop = atl2_close,
.ndo_start_xmit = atl2_xmit_frame,
.ndo_set_multicast_list = atl2_set_multi,
.ndo_validate_addr = eth_validate_addr,
.ndo_set_mac_address = atl2_set_mac,
Expand Down Expand Up @@ -1400,7 +1401,6 @@ static int __devinit atl2_probe(struct pci_dev *pdev,

atl2_setup_pcicmd(pdev);

netdev->hard_start_xmit = &atl2_xmit_frame;
netdev->netdev_ops = &atl2_netdev_ops;
atl2_set_ethtool_ops(netdev);
netdev->watchdog_timeo = 5 * HZ;
Expand Down
56 changes: 46 additions & 10 deletions drivers/net/bonding/bond_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1377,14 +1377,12 @@ static int bond_compute_features(struct bonding *bond)
return 0;
}


static void bond_setup_by_slave(struct net_device *bond_dev,
struct net_device *slave_dev)
{
struct bonding *bond = netdev_priv(bond_dev);

bond_dev->neigh_setup = slave_dev->neigh_setup;
bond_dev->header_ops = slave_dev->header_ops;
bond_dev->header_ops = slave_dev->header_ops;

bond_dev->type = slave_dev->type;
bond_dev->hard_header_len = slave_dev->hard_header_len;
Expand Down Expand Up @@ -4124,6 +4122,20 @@ static void bond_set_multicast_list(struct net_device *bond_dev)
read_unlock(&bond->lock);
}

static int bond_neigh_setup(struct net_device *dev, struct neigh_parms *parms)
{
struct bonding *bond = netdev_priv(dev);
struct slave *slave = bond->first_slave;

if (slave) {
const struct net_device_ops *slave_ops
= slave->dev->netdev_ops;
if (slave_ops->ndo_neigh_setup)
return slave_ops->ndo_neigh_setup(dev, parms);
}
return 0;
}

/*
* Change the MTU of all of a master's slaves to match the master
*/
Expand Down Expand Up @@ -4490,6 +4502,35 @@ static void bond_set_xmit_hash_policy(struct bonding *bond)
}
}

static int bond_start_xmit(struct sk_buff *skb, struct net_device *dev)
{
const struct bonding *bond = netdev_priv(dev);

switch (bond->params.mode) {
case BOND_MODE_ROUNDROBIN:
return bond_xmit_roundrobin(skb, dev);
case BOND_MODE_ACTIVEBACKUP:
return bond_xmit_activebackup(skb, dev);
case BOND_MODE_XOR:
return bond_xmit_xor(skb, dev);
case BOND_MODE_BROADCAST:
return bond_xmit_broadcast(skb, dev);
case BOND_MODE_8023AD:
return bond_3ad_xmit_xor(skb, dev);
case BOND_MODE_ALB:
case BOND_MODE_TLB:
return bond_alb_xmit(skb, dev);
default:
/* Should never happen, mode already checked */
printk(KERN_ERR DRV_NAME ": %s: Error: Unknown bonding mode %d\n",
dev->name, bond->params.mode);
WARN_ON_ONCE(1);
dev_kfree_skb(skb);
return NETDEV_TX_OK;
}
}


/*
* set bond mode specific net device operations
*/
Expand All @@ -4499,28 +4540,22 @@ void bond_set_mode_ops(struct bonding *bond, int mode)

switch (mode) {
case BOND_MODE_ROUNDROBIN:
bond_dev->hard_start_xmit = bond_xmit_roundrobin;
break;
case BOND_MODE_ACTIVEBACKUP:
bond_dev->hard_start_xmit = bond_xmit_activebackup;
break;
case BOND_MODE_XOR:
bond_dev->hard_start_xmit = bond_xmit_xor;
bond_set_xmit_hash_policy(bond);
break;
case BOND_MODE_BROADCAST:
bond_dev->hard_start_xmit = bond_xmit_broadcast;
break;
case BOND_MODE_8023AD:
bond_set_master_3ad_flags(bond);
bond_dev->hard_start_xmit = bond_3ad_xmit_xor;
bond_set_xmit_hash_policy(bond);
break;
case BOND_MODE_ALB:
bond_set_master_alb_flags(bond);
/* FALLTHRU */
case BOND_MODE_TLB:
bond_dev->hard_start_xmit = bond_alb_xmit;
break;
default:
/* Should never happen, mode already checked */
Expand Down Expand Up @@ -4553,12 +4588,13 @@ static const struct ethtool_ops bond_ethtool_ops = {
static const struct net_device_ops bond_netdev_ops = {
.ndo_open = bond_open,
.ndo_stop = bond_close,
.ndo_start_xmit = bond_start_xmit,
.ndo_get_stats = bond_get_stats,
.ndo_do_ioctl = bond_do_ioctl,
.ndo_set_multicast_list = bond_set_multicast_list,
.ndo_change_mtu = bond_change_mtu,
.ndo_validate_addr = NULL,
.ndo_set_mac_address = bond_set_mac_address,
.ndo_neigh_setup = bond_neigh_setup,
.ndo_vlan_rx_register = bond_vlan_rx_register,
.ndo_vlan_rx_add_vid = bond_vlan_rx_add_vid,
.ndo_vlan_rx_kill_vid = bond_vlan_rx_kill_vid,
Expand Down
6 changes: 3 additions & 3 deletions drivers/net/chelsio/cxgb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ static int t1_set_mac_addr(struct net_device *dev, void *p)
}

#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
static void vlan_rx_register(struct net_device *dev,
static void t1_vlan_rx_register(struct net_device *dev,
struct vlan_group *grp)
{
struct adapter *adapter = dev->ml_priv;
Expand Down Expand Up @@ -1013,14 +1013,15 @@ void t1_fatal_err(struct adapter *adapter)
static const struct net_device_ops cxgb_netdev_ops = {
.ndo_open = cxgb_open,
.ndo_stop = cxgb_close,
.ndo_start_xmit = t1_start_xmit,
.ndo_get_stats = t1_get_stats,
.ndo_validate_addr = eth_validate_addr,
.ndo_set_multicast_list = t1_set_rxmode,
.ndo_do_ioctl = t1_ioctl,
.ndo_change_mtu = t1_change_mtu,
.ndo_set_mac_address = t1_set_mac_addr,
#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
.ndo_vlan_rx_register = vlan_rx_register,
.ndo_vlan_rx_register = t1_vlan_rx_register,
#endif
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = t1_netpoll,
Expand Down Expand Up @@ -1157,7 +1158,6 @@ static int __devinit init_one(struct pci_dev *pdev,
}

netdev->netdev_ops = &cxgb_netdev_ops;
netdev->hard_start_xmit = t1_start_xmit;
netdev->hard_header_len += (adapter->flags & TSO_CAPABLE) ?
sizeof(struct cpl_tx_pkt_lso) : sizeof(struct cpl_tx_pkt);

Expand Down
1 change: 0 additions & 1 deletion drivers/net/cxgb3/cxgb3_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2955,7 +2955,6 @@ static int __devinit init_one(struct pci_dev *pdev,

netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
netdev->netdev_ops = &cxgb_netdev_ops;
netdev->hard_start_xmit = t3_eth_xmit;
SET_ETHTOOL_OPS(netdev, &cxgb_ethtool_ops);
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/e100.c
Original file line number Diff line number Diff line change
Expand Up @@ -2615,6 +2615,7 @@ static int e100_close(struct net_device *netdev)
static const struct net_device_ops e100_netdev_ops = {
.ndo_open = e100_open,
.ndo_stop = e100_close,
.ndo_start_xmit = e100_xmit_frame,
.ndo_validate_addr = eth_validate_addr,
.ndo_set_multicast_list = e100_set_multicast_list,
.ndo_set_mac_address = e100_set_mac_address,
Expand All @@ -2640,7 +2641,6 @@ static int __devinit e100_probe(struct pci_dev *pdev,
}

netdev->netdev_ops = &e100_netdev_ops;
netdev->hard_start_xmit = e100_xmit_frame;
SET_ETHTOOL_OPS(netdev, &e100_ethtool_ops);
netdev->watchdog_timeo = E100_WATCHDOG_PERIOD;
strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/e1000/e1000_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@ static int e1000_is_need_ioport(struct pci_dev *pdev)
static const struct net_device_ops e1000_netdev_ops = {
.ndo_open = e1000_open,
.ndo_stop = e1000_close,
.ndo_start_xmit = e1000_xmit_frame,
.ndo_get_stats = e1000_get_stats,
.ndo_set_rx_mode = e1000_set_rx_mode,
.ndo_set_mac_address = e1000_set_mac,
Expand Down Expand Up @@ -1001,7 +1002,6 @@ static int __devinit e1000_probe(struct pci_dev *pdev,
}

netdev->netdev_ops = &e1000_netdev_ops;
netdev->hard_start_xmit = &e1000_xmit_frame;
e1000_set_ethtool_ops(netdev);
netdev->watchdog_timeo = 5 * HZ;
netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/e1000e/netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -4707,6 +4707,7 @@ static void e1000_eeprom_checks(struct e1000_adapter *adapter)
static const struct net_device_ops e1000e_netdev_ops = {
.ndo_open = e1000_open,
.ndo_stop = e1000_close,
.ndo_start_xmit = e1000_xmit_frame,
.ndo_get_stats = e1000_get_stats,
.ndo_set_multicast_list = e1000_set_multi,
.ndo_set_mac_address = e1000_set_mac,
Expand Down Expand Up @@ -4822,7 +4823,6 @@ static int __devinit e1000_probe(struct pci_dev *pdev,

/* construct the net_device struct */
netdev->netdev_ops = &e1000e_netdev_ops;
netdev->hard_start_xmit = &e1000_xmit_frame;
e1000e_set_ethtool_ops(netdev);
netdev->watchdog_timeo = 5 * HZ;
netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/enic/enic_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,7 @@ static void enic_iounmap(struct enic *enic)
static const struct net_device_ops enic_netdev_ops = {
.ndo_open = enic_open,
.ndo_stop = enic_stop,
.ndo_start_xmit = enic_hard_start_xmit,
.ndo_get_stats = enic_get_stats,
.ndo_validate_addr = eth_validate_addr,
.ndo_set_multicast_list = enic_set_multicast_list,
Expand Down Expand Up @@ -1830,7 +1831,6 @@ static int __devinit enic_probe(struct pci_dev *pdev,
}

netdev->netdev_ops = &enic_netdev_ops;
netdev->hard_start_xmit = enic_hard_start_xmit;
netdev->watchdog_timeo = 2 * HZ;
netdev->ethtool_ops = &enic_ethtool_ops;

Expand Down
22 changes: 19 additions & 3 deletions drivers/net/forcedeth.c
Original file line number Diff line number Diff line change
Expand Up @@ -5412,6 +5412,23 @@ static const struct net_device_ops nv_netdev_ops = {
.ndo_open = nv_open,
.ndo_stop = nv_close,
.ndo_get_stats = nv_get_stats,
.ndo_start_xmit = nv_start_xmit,
.ndo_tx_timeout = nv_tx_timeout,
.ndo_change_mtu = nv_change_mtu,
.ndo_validate_addr = eth_validate_addr,
.ndo_set_mac_address = nv_set_mac_address,
.ndo_set_multicast_list = nv_set_multicast,
.ndo_vlan_rx_register = nv_vlan_rx_register,
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = nv_poll_controller,
#endif
};

static const struct net_device_ops nv_netdev_ops_optimized = {
.ndo_open = nv_open,
.ndo_stop = nv_close,
.ndo_get_stats = nv_get_stats,
.ndo_start_xmit = nv_start_xmit_optimized,
.ndo_tx_timeout = nv_tx_timeout,
.ndo_change_mtu = nv_change_mtu,
.ndo_validate_addr = eth_validate_addr,
Expand Down Expand Up @@ -5592,11 +5609,10 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
goto out_freering;

if (!nv_optimized(np))
dev->hard_start_xmit = nv_start_xmit;
dev->netdev_ops = &nv_netdev_ops;
else
dev->hard_start_xmit = nv_start_xmit_optimized;
dev->netdev_ops = &nv_netdev_ops_optimized;

dev->netdev_ops = &nv_netdev_ops;
#ifdef CONFIG_FORCEDETH_NAPI
netif_napi_add(dev, &np->napi, nv_napi_poll, RX_WORK_PER_LOOP);
#endif
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/ifb.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ static void ri_tasklet(unsigned long dev)
}

static const struct net_device_ops ifb_netdev_ops = {
.ndo_validate_addr = eth_validate_addr,
.ndo_open = ifb_open,
.ndo_stop = ifb_close,
.ndo_start_xmit = ifb_xmit,
.ndo_validate_addr = eth_validate_addr,
};

static void ifb_setup(struct net_device *dev)
{
/* Initialize the device structure. */
dev->hard_start_xmit = ifb_xmit;
dev->destructor = free_netdev;
dev->netdev_ops = &ifb_netdev_ops;

Expand Down
Loading

0 comments on commit 0082982

Please sign in to comment.