Skip to content

Commit

Permalink
vlan: convert to net_device_ops
Browse files Browse the repository at this point in the history
Convert vlan devices and function pointers to net_device_ops.

Signed-off-by: Stephen Hemminger <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Stephen Hemminger authored and davem330 committed Nov 20, 2008
1 parent 5bc3eb7 commit 656299f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
18 changes: 10 additions & 8 deletions net/8021q/vlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void unregister_vlan_dev(struct net_device *dev)
{
struct vlan_dev_info *vlan = vlan_dev_info(dev);
struct net_device *real_dev = vlan->real_dev;
const struct net_device_ops *ops = real_dev->netdev_ops;
struct vlan_group *grp;
u16 vlan_id = vlan->vlan_id;

Expand All @@ -156,7 +157,7 @@ void unregister_vlan_dev(struct net_device *dev)
* HW accelerating devices or SW vlan input packet processing.
*/
if (real_dev->features & NETIF_F_HW_VLAN_FILTER)
real_dev->vlan_rx_kill_vid(real_dev, vlan_id);
ops->ndo_vlan_rx_kill_vid(real_dev, vlan_id);

vlan_group_set_device(grp, vlan_id, NULL);
grp->nr_vlans--;
Expand All @@ -170,7 +171,7 @@ void unregister_vlan_dev(struct net_device *dev)
vlan_gvrp_uninit_applicant(real_dev);

if (real_dev->features & NETIF_F_HW_VLAN_RX)
real_dev->vlan_rx_register(real_dev, NULL);
ops->ndo_vlan_rx_register(real_dev, NULL);

hlist_del_rcu(&grp->hlist);

Expand Down Expand Up @@ -205,21 +206,21 @@ static void vlan_transfer_operstate(const struct net_device *dev,

int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id)
{
char *name = real_dev->name;
const char *name = real_dev->name;
const struct net_device_ops *ops = real_dev->netdev_ops;

if (real_dev->features & NETIF_F_VLAN_CHALLENGED) {
pr_info("8021q: VLANs not supported on %s\n", name);
return -EOPNOTSUPP;
}

if ((real_dev->features & NETIF_F_HW_VLAN_RX) &&
!real_dev->vlan_rx_register) {
if ((real_dev->features & NETIF_F_HW_VLAN_RX) && !ops->ndo_vlan_rx_register) {
pr_info("8021q: device %s has buggy VLAN hw accel\n", name);
return -EOPNOTSUPP;
}

if ((real_dev->features & NETIF_F_HW_VLAN_FILTER) &&
(!real_dev->vlan_rx_add_vid || !real_dev->vlan_rx_kill_vid)) {
(!ops->ndo_vlan_rx_add_vid || !ops->ndo_vlan_rx_kill_vid)) {
pr_info("8021q: Device %s has buggy VLAN hw accel\n", name);
return -EOPNOTSUPP;
}
Expand All @@ -240,6 +241,7 @@ int register_vlan_dev(struct net_device *dev)
{
struct vlan_dev_info *vlan = vlan_dev_info(dev);
struct net_device *real_dev = vlan->real_dev;
const struct net_device_ops *ops = real_dev->netdev_ops;
u16 vlan_id = vlan->vlan_id;
struct vlan_group *grp, *ngrp = NULL;
int err;
Expand Down Expand Up @@ -275,9 +277,9 @@ int register_vlan_dev(struct net_device *dev)
grp->nr_vlans++;

if (ngrp && real_dev->features & NETIF_F_HW_VLAN_RX)
real_dev->vlan_rx_register(real_dev, ngrp);
ops->ndo_vlan_rx_register(real_dev, ngrp);
if (real_dev->features & NETIF_F_HW_VLAN_FILTER)
real_dev->vlan_rx_add_vid(real_dev, vlan_id);
ops->ndo_vlan_rx_add_vid(real_dev, vlan_id);

return 0;

Expand Down
30 changes: 18 additions & 12 deletions net/8021q/vlan_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ static int vlan_dev_set_mac_address(struct net_device *dev, void *p)
static int vlan_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{
struct net_device *real_dev = vlan_dev_info(dev)->real_dev;
const struct net_device_ops *ops = real_dev->netdev_ops;
struct ifreq ifrr;
int err = -EOPNOTSUPP;

Expand All @@ -534,8 +535,8 @@ static int vlan_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
case SIOCGMIIPHY:
case SIOCGMIIREG:
case SIOCSMIIREG:
if (real_dev->do_ioctl && netif_device_present(real_dev))
err = real_dev->do_ioctl(real_dev, &ifrr, cmd);
if (netif_device_present(real_dev) && ops->ndo_do_ioctl)
err = ops->ndo_do_ioctl(real_dev, &ifrr, cmd);
break;
}

Expand Down Expand Up @@ -697,23 +698,28 @@ static const struct ethtool_ops vlan_ethtool_ops = {
.get_flags = vlan_ethtool_get_flags,
};

static const struct net_device_ops vlan_netdev_ops = {
.ndo_change_mtu = vlan_dev_change_mtu,
.ndo_init = vlan_dev_init,
.ndo_uninit = vlan_dev_uninit,
.ndo_open = vlan_dev_open,
.ndo_stop = vlan_dev_stop,
.ndo_validate_addr = eth_validate_addr,
.ndo_set_mac_address = vlan_dev_set_mac_address,
.ndo_set_rx_mode = vlan_dev_set_rx_mode,
.ndo_set_multicast_list = vlan_dev_set_rx_mode,
.ndo_change_rx_flags = vlan_dev_change_rx_flags,
.ndo_do_ioctl = vlan_dev_ioctl,
};

void vlan_setup(struct net_device *dev)
{
ether_setup(dev);

dev->priv_flags |= IFF_802_1Q_VLAN;
dev->tx_queue_len = 0;

dev->change_mtu = vlan_dev_change_mtu;
dev->init = vlan_dev_init;
dev->uninit = vlan_dev_uninit;
dev->open = vlan_dev_open;
dev->stop = vlan_dev_stop;
dev->set_mac_address = vlan_dev_set_mac_address;
dev->set_rx_mode = vlan_dev_set_rx_mode;
dev->set_multicast_list = vlan_dev_set_rx_mode;
dev->change_rx_flags = vlan_dev_change_rx_flags;
dev->do_ioctl = vlan_dev_ioctl;
dev->netdev_ops = &vlan_netdev_ops;
dev->destructor = free_netdev;
dev->ethtool_ops = &vlan_ethtool_ops;

Expand Down

0 comments on commit 656299f

Please sign in to comment.