23 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 #include <linux/module.h>
26 #include <linux/slab.h>
28 #include <linux/netdevice.h>
30 #include <linux/ethtool.h>
35 #include <linux/if_vlan.h>
48 static int vlan_dev_rebuild_header(
struct sk_buff *
skb)
61 pr_debug(
"%s: unable to resolve type %X addresses\n",
103 unsigned int vhdrlen = 0;
111 vlan_tci |= vlan_dev_get_egress_qos_mask(dev, skb);
134 rc = dev_hard_header(skb, dev, type, daddr, saddr, len + vhdrlen);
142 #ifdef CONFIG_NET_POLL_CONTROLLER
144 netpoll_send_skb(vlan->netpoll, skb);
168 vlan_tci |= vlan_dev_get_egress_qos_mask(dev, skb);
169 skb = __vlan_hwaccel_put_tag(skb, vlan_tci);
174 if (
unlikely(netpoll_tx_running(dev)))
175 return vlan_netpoll_send_skb(vlan, skb);
183 u64_stats_update_begin(&stats->
syncp);
186 u64_stats_update_end(&stats->
syncp);
194 static int vlan_dev_change_mtu(
struct net_device *dev,
int new_mtu)
267 vlan->
flags = (old_flags & ~mask) | (flags & mask);
270 if (vlan->
flags & VLAN_FLAG_GVRP)
283 static int vlan_dev_open(
struct net_device *dev)
315 if (netif_carrier_ok(real_dev))
330 static int vlan_dev_stop(
struct net_device *dev)
349 static int vlan_dev_set_mac_address(
struct net_device *dev,
void *
p)
355 if (!is_valid_ether_addr(addr->
sa_data))
389 if (netif_device_present(real_dev) && ops->
ndo_do_ioctl)
412 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
420 if (ops->ndo_fcoe_ddp_setup)
421 rc = ops->ndo_fcoe_ddp_setup(real_dev, xid, sgl, sgc);
426 static int vlan_dev_fcoe_ddp_done(
struct net_device *dev,
u16 xid)
432 if (ops->ndo_fcoe_ddp_done)
433 len = ops->ndo_fcoe_ddp_done(real_dev, xid);
438 static int vlan_dev_fcoe_enable(
struct net_device *dev)
444 if (ops->ndo_fcoe_enable)
445 rc = ops->ndo_fcoe_enable(real_dev);
449 static int vlan_dev_fcoe_disable(
struct net_device *dev)
455 if (ops->ndo_fcoe_disable)
456 rc = ops->ndo_fcoe_disable(real_dev);
460 static int vlan_dev_fcoe_get_wwn(
struct net_device *dev,
u64 *wwn,
int type)
466 if (ops->ndo_fcoe_get_wwn)
467 rc = ops->ndo_fcoe_get_wwn(real_dev, wwn, type);
471 static int vlan_dev_fcoe_ddp_target(
struct net_device *dev,
u16 xid,
478 if (ops->ndo_fcoe_ddp_target)
479 rc = ops->ndo_fcoe_ddp_target(real_dev, xid, sgl, sgc);
485 static void vlan_dev_change_rx_flags(
struct net_device *dev,
int change)
497 static void vlan_dev_set_rx_mode(
struct net_device *vlan_dev)
511 static void vlan_dev_set_lockdep_one(
struct net_device *dev,
516 &vlan_netdev_xmit_lock_key,
523 &vlan_netdev_addr_lock_key,
525 netdev_for_each_tx_queue(dev, vlan_dev_set_lockdep_one, &subclass);
528 static const struct header_ops vlan_header_ops = {
529 .create = vlan_dev_hard_header,
530 .rebuild = vlan_dev_rebuild_header,
536 static int vlan_dev_init(
struct net_device *dev)
562 if (is_zero_ether_addr(dev->
dev_addr))
567 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
568 dev->fcoe_ddp_xid = real_dev->fcoe_ddp_xid;
582 if (is_vlan_dev(real_dev))
585 vlan_dev_set_lockdep_class(dev, subclass);
594 static void vlan_dev_uninit(
struct net_device *dev)
626 static int vlan_ethtool_get_settings(
struct net_device *dev,
634 static void vlan_ethtool_get_drvinfo(
struct net_device *dev,
651 u64 rxpackets, rxbytes, rxmulticast, txpackets, txbytes;
656 start = u64_stats_fetch_begin_bh(&p->
syncp);
662 }
while (u64_stats_fetch_retry_bh(&p->
syncp, start));
679 #ifdef CONFIG_NET_POLL_CONTROLLER
680 static void vlan_dev_poll_controller(
struct net_device *dev)
693 netpoll = kzalloc(
sizeof(*netpoll), gfp);
704 vlan->netpoll = netpoll;
710 static void vlan_dev_netpoll_cleanup(
struct net_device *dev)
713 struct netpoll *netpoll = vlan->netpoll;
718 vlan->netpoll =
NULL;
724 static const struct ethtool_ops vlan_ethtool_ops = {
725 .get_settings = vlan_ethtool_get_settings,
726 .get_drvinfo = vlan_ethtool_get_drvinfo,
731 .ndo_change_mtu = vlan_dev_change_mtu,
732 .ndo_init = vlan_dev_init,
733 .ndo_uninit = vlan_dev_uninit,
734 .ndo_open = vlan_dev_open,
735 .ndo_stop = vlan_dev_stop,
736 .ndo_start_xmit = vlan_dev_hard_start_xmit,
738 .ndo_set_mac_address = vlan_dev_set_mac_address,
739 .ndo_set_rx_mode = vlan_dev_set_rx_mode,
740 .ndo_change_rx_flags = vlan_dev_change_rx_flags,
741 .ndo_do_ioctl = vlan_dev_ioctl,
742 .ndo_neigh_setup = vlan_dev_neigh_setup,
743 .ndo_get_stats64 = vlan_dev_get_stats64,
744 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
745 .ndo_fcoe_ddp_setup = vlan_dev_fcoe_ddp_setup,
746 .ndo_fcoe_ddp_done = vlan_dev_fcoe_ddp_done,
747 .ndo_fcoe_enable = vlan_dev_fcoe_enable,
748 .ndo_fcoe_disable = vlan_dev_fcoe_disable,
749 .ndo_fcoe_get_wwn = vlan_dev_fcoe_get_wwn,
750 .ndo_fcoe_ddp_target = vlan_dev_fcoe_ddp_target,
752 #ifdef CONFIG_NET_POLL_CONTROLLER
753 .ndo_poll_controller = vlan_dev_poll_controller,
754 .ndo_netpoll_setup = vlan_dev_netpoll_setup,
755 .ndo_netpoll_cleanup = vlan_dev_netpoll_cleanup,
757 .ndo_fix_features = vlan_dev_fix_features,