1 /* Modified by Broadcom Corp. Portions Copyright (c) Broadcom Corp, 2012. */
4 * Ethernet-type device handling.
6 * Authors: Ben Greear <greearb@candelatech.com>
7 * Please send support related email to: netdev@vger.kernel.org
8 * VLAN Home Page: http://www.candelatech.com/~greear/vlan.html
10 * Fixes: Mar 22 2001: Martin Bokaemper <mbokaemper@unispherenetworks.com>
11 * - reset skb->pkt_type on incoming packets when MAC was changed
12 * - see that changed MAC is saddr for outgoing packets
13 * Oct 20, 2001: Ard van Breeman:
14 * - Fix MC-list, finally.
15 * - Flush MC-list on VLAN destroy.
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
24 #include <linux/module.h>
25 #include <linux/slab.h>
26 #include <linux/skbuff.h>
27 #include <linux/netdevice.h>
28 #include <linux/etherdevice.h>
29 #include <linux/ethtool.h>
34 #include <linux/if_vlan.h>
40 * Rebuild the Ethernet MAC header. This is called after an ARP
41 * (or in future other address resolution) has completed on this
42 * sk_buff. We now let ARP fill in the other fields.
44 * This routine CANNOT use cached dst->neigh!
45 * Really, it is used only when dst->neigh is wrong.
47 * TODO: This needs a checkup, I'm ignorant here. --BLG
49 static int vlan_dev_rebuild_header(struct sk_buff
*skb
)
51 struct net_device
*dev
= skb
->dev
;
52 struct vlan_ethhdr
*veth
= (struct vlan_ethhdr
*)(skb
->data
);
54 switch (veth
->h_vlan_encapsulated_proto
) {
58 /* TODO: Confirm this will work with VLAN headers... */
59 return arp_find(veth
->h_dest
, skb
);
62 pr_debug("%s: unable to resolve type %X addresses.\n",
63 dev
->name
, ntohs(veth
->h_vlan_encapsulated_proto
));
65 memcpy(veth
->h_source
, dev
->dev_addr
, ETH_ALEN
);
72 static inline struct sk_buff
*vlan_check_reorder_header(struct sk_buff
*skb
)
74 if (vlan_dev_info(skb
->dev
)->flags
& VLAN_FLAG_REORDER_HDR
) {
75 if (skb_cow(skb
, skb_headroom(skb
)) < 0)
78 /* Lifted from Gleb's VLAN code... */
79 memmove(skb
->data
- ETH_HLEN
,
80 skb
->data
- VLAN_ETH_HLEN
, 12);
81 skb
->mac_header
+= VLAN_HLEN
;
88 static inline void vlan_set_encap_proto(struct sk_buff
*skb
,
89 struct vlan_hdr
*vhdr
)
95 * Was a VLAN packet, grab the encapsulated protocol, which the layer
96 * three protocols care about.
99 proto
= vhdr
->h_vlan_encapsulated_proto
;
100 if (ntohs(proto
) >= 1536) {
101 skb
->protocol
= proto
;
106 if (*(unsigned short *)rawp
== 0xFFFF)
108 * This is a magic hack to spot IPX packets. Older Novell
109 * breaks the protocol design and runs IPX over 802.3 without
110 * an 802.2 LLC layer. We look for FFFF which isn't a used
111 * 802.2 SSAP/DSAP. This won't work for fault tolerant netware
112 * but does for the rest.
114 skb
->protocol
= htons(ETH_P_802_3
);
119 skb
->protocol
= htons(ETH_P_802_2
);
123 * Determine the packet's protocol ID. The rule here is that we
124 * assume 802.3 if the type field is short enough to be a length.
125 * This is normal practice and works for any 'now in use' protocol.
127 * Also, at this point we assume that we ARE dealing exclusively with
128 * VLAN packets, or packets that should be made into VLAN packets based
129 * on a default VLAN ID.
131 * NOTE: Should be similar to ethernet/eth.c.
133 * SANITY NOTE: This method is called when a packet is moving up the stack
134 * towards userland. To get here, it would have already passed
135 * through the ethernet/eth.c eth_type_trans() method.
136 * SANITY NOTE 2: We are referencing to the VLAN_HDR frields, which MAY be
137 * stored UNALIGNED in the memory. RISC systems don't like
138 * such cases very much...
139 * SANITY NOTE 2a: According to Dave Miller & Alexey, it will always be
140 * aligned, so there doesn't need to be any of the unaligned
141 * stuff. It has been commented out now... --Ben
144 int BCMFASTPATH_HOST
vlan_skb_recv(struct sk_buff
*skb
, struct net_device
*dev
,
145 struct packet_type
*ptype
, struct net_device
*orig_dev
)
147 struct vlan_hdr
*vhdr
;
148 struct vlan_rx_stats
*rx_stats
;
149 struct net_device
*vlan_dev
;
153 skb
= skb_share_check(skb
, GFP_ATOMIC
);
157 if (unlikely(!pskb_may_pull(skb
, VLAN_HLEN
)))
160 vhdr
= (struct vlan_hdr
*)skb
->data
;
161 vlan_tci
= ntohs(vhdr
->h_vlan_TCI
);
162 vlan_id
= vlan_tci
& VLAN_VID_MASK
;
165 vlan_dev
= __find_vlan_dev(dev
, vlan_id
);
167 /* If the VLAN device is defined, we use it.
168 * If not, and the VID is 0, it is a 802.1p packet (not
169 * really a VLAN), so we will just netif_rx it later to the
170 * original interface, but with the skb->proto set to the
171 * wrapped proto: we do nothing here.
176 pr_debug("%s: ERROR: No net_device for VID: %u on dev: %s\n",
177 __func__
, vlan_id
, dev
->name
);
184 rx_stats
= per_cpu_ptr(vlan_dev_info(skb
->dev
)->vlan_rx_stats
,
186 u64_stats_update_begin(&rx_stats
->syncp
);
187 rx_stats
->rx_packets
++;
188 rx_stats
->rx_bytes
+= skb
->len
;
190 skb
->priority
= vlan_get_ingress_priority(skb
->dev
, vlan_tci
);
192 pr_debug("%s: priority: %u for TCI: %hu\n",
193 __func__
, skb
->priority
, vlan_tci
);
195 switch (skb
->pkt_type
) {
196 case PACKET_BROADCAST
:
197 /* Yeah, stats collect these together.. */
198 /* stats->broadcast ++; // no such counter :-( */
201 case PACKET_MULTICAST
:
202 rx_stats
->rx_multicast
++;
205 case PACKET_OTHERHOST
:
206 /* Our lower layer thinks this is not local, let's make
208 * This allows the VLAN to have a different MAC than the
209 * underlying device, and still route correctly.
211 if (!compare_ether_addr(eth_hdr(skb
)->h_dest
,
213 skb
->pkt_type
= PACKET_HOST
;
218 u64_stats_update_end(&rx_stats
->syncp
);
221 skb_pull_rcsum(skb
, VLAN_HLEN
);
222 vlan_set_encap_proto(skb
, vhdr
);
225 skb
= vlan_check_reorder_header(skb
);
227 rx_stats
->rx_errors
++;
234 return NET_RX_SUCCESS
;
244 vlan_dev_get_egress_qos_mask(struct net_device
*dev
, struct sk_buff
*skb
)
246 struct vlan_priority_tci_mapping
*mp
;
248 mp
= vlan_dev_info(dev
)->egress_priority_map
[(skb
->priority
& 0xF)];
250 if (mp
->priority
== skb
->priority
) {
251 return mp
->vlan_qos
; /* This should already be shifted
252 * to mask correctly with the
261 * Create the VLAN header for an arbitrary protocol layer
263 * saddr=NULL means use device source address
264 * daddr=NULL means leave destination address (eg unresolved arp)
266 * This is called when the SKB is moving down the stack towards the
269 static int vlan_dev_hard_header(struct sk_buff
*skb
, struct net_device
*dev
,
271 const void *daddr
, const void *saddr
,
274 struct vlan_hdr
*vhdr
;
275 unsigned int vhdrlen
= 0;
279 if (WARN_ON(skb_headroom(skb
) < dev
->hard_header_len
))
282 if (!(vlan_dev_info(dev
)->flags
& VLAN_FLAG_REORDER_HDR
)) {
283 vhdr
= (struct vlan_hdr
*) skb_push(skb
, VLAN_HLEN
);
285 vlan_tci
= vlan_dev_info(dev
)->vlan_id
;
286 vlan_tci
|= vlan_dev_get_egress_qos_mask(dev
, skb
);
287 vhdr
->h_vlan_TCI
= htons(vlan_tci
);
290 * Set the protocol type. For a packet of type ETH_P_802_3/2 we
291 * put the length in here instead.
293 if (type
!= ETH_P_802_3
&& type
!= ETH_P_802_2
)
294 vhdr
->h_vlan_encapsulated_proto
= htons(type
);
296 vhdr
->h_vlan_encapsulated_proto
= htons(len
);
298 skb
->protocol
= htons(ETH_P_8021Q
);
303 /* Before delegating work to the lower layer, enter our MAC-address */
305 saddr
= dev
->dev_addr
;
307 /* Now make the underlying real hard header */
308 dev
= vlan_dev_info(dev
)->real_dev
;
309 rc
= dev_hard_header(skb
, dev
, type
, daddr
, saddr
, len
+ vhdrlen
);
315 static netdev_tx_t BCMFASTPATH_HOST
vlan_dev_hard_start_xmit(struct sk_buff
*skb
,
316 struct net_device
*dev
)
318 int i
= skb_get_queue_mapping(skb
);
319 struct netdev_queue
*txq
= netdev_get_tx_queue(dev
, i
);
320 struct vlan_ethhdr
*veth
= (struct vlan_ethhdr
*)(skb
->data
);
324 /* Handle non-VLAN frames if they are sent to us, for example by DHCP.
326 * NOTE: THIS ASSUMES DIX ETHERNET, SPECIFICALLY NOT SUPPORTING
327 * OTHER THINGS LIKE FDDI/TokenRing/802.3 SNAPs...
329 if (veth
->h_vlan_proto
!= htons(ETH_P_8021Q
) ||
330 vlan_dev_info(dev
)->flags
& VLAN_FLAG_REORDER_HDR
) {
331 unsigned int orig_headroom
= skb_headroom(skb
);
334 vlan_dev_info(dev
)->cnt_encap_on_xmit
++;
336 vlan_tci
= vlan_dev_info(dev
)->vlan_id
;
337 vlan_tci
|= vlan_dev_get_egress_qos_mask(dev
, skb
);
338 skb
= __vlan_put_tag(skb
, vlan_tci
);
344 if (orig_headroom
< VLAN_HLEN
)
345 vlan_dev_info(dev
)->cnt_inc_headroom_on_tx
++;
349 skb_set_dev(skb
, vlan_dev_info(dev
)->real_dev
);
351 ret
= dev_queue_xmit(skb
);
353 if (likely(ret
== NET_XMIT_SUCCESS
|| ret
== NET_XMIT_CN
)) {
355 txq
->tx_bytes
+= len
;
362 static netdev_tx_t
vlan_dev_hwaccel_hard_start_xmit(struct sk_buff
*skb
,
363 struct net_device
*dev
)
365 int i
= skb_get_queue_mapping(skb
);
366 struct netdev_queue
*txq
= netdev_get_tx_queue(dev
, i
);
371 vlan_tci
= vlan_dev_info(dev
)->vlan_id
;
372 vlan_tci
|= vlan_dev_get_egress_qos_mask(dev
, skb
);
373 skb
= __vlan_hwaccel_put_tag(skb
, vlan_tci
);
375 skb
->dev
= vlan_dev_info(dev
)->real_dev
;
377 ret
= dev_queue_xmit(skb
);
379 if (likely(ret
== NET_XMIT_SUCCESS
|| ret
== NET_XMIT_CN
)) {
381 txq
->tx_bytes
+= len
;
388 static u16
vlan_dev_select_queue(struct net_device
*dev
, struct sk_buff
*skb
)
390 struct net_device
*rdev
= vlan_dev_info(dev
)->real_dev
;
391 const struct net_device_ops
*ops
= rdev
->netdev_ops
;
393 return ops
->ndo_select_queue(rdev
, skb
);
396 static int vlan_dev_change_mtu(struct net_device
*dev
, int new_mtu
)
398 /* TODO: gotta make sure the underlying layer can handle it,
399 * maybe an IFF_VLAN_CAPABLE flag for devices?
401 if (vlan_dev_info(dev
)->real_dev
->mtu
< new_mtu
)
409 void vlan_dev_set_ingress_priority(const struct net_device
*dev
,
410 u32 skb_prio
, u16 vlan_prio
)
412 struct vlan_dev_info
*vlan
= vlan_dev_info(dev
);
414 if (vlan
->ingress_priority_map
[vlan_prio
& 0x7] && !skb_prio
)
415 vlan
->nr_ingress_mappings
--;
416 else if (!vlan
->ingress_priority_map
[vlan_prio
& 0x7] && skb_prio
)
417 vlan
->nr_ingress_mappings
++;
419 vlan
->ingress_priority_map
[vlan_prio
& 0x7] = skb_prio
;
422 int vlan_dev_set_egress_priority(const struct net_device
*dev
,
423 u32 skb_prio
, u16 vlan_prio
)
425 struct vlan_dev_info
*vlan
= vlan_dev_info(dev
);
426 struct vlan_priority_tci_mapping
*mp
= NULL
;
427 struct vlan_priority_tci_mapping
*np
;
428 u32 vlan_qos
= (vlan_prio
<< VLAN_PRIO_SHIFT
) & VLAN_PRIO_MASK
;
430 /* See if a priority mapping exists.. */
431 mp
= vlan
->egress_priority_map
[skb_prio
& 0xF];
433 if (mp
->priority
== skb_prio
) {
434 if (mp
->vlan_qos
&& !vlan_qos
)
435 vlan
->nr_egress_mappings
--;
436 else if (!mp
->vlan_qos
&& vlan_qos
)
437 vlan
->nr_egress_mappings
++;
438 mp
->vlan_qos
= vlan_qos
;
444 /* Create a new mapping then. */
445 mp
= vlan
->egress_priority_map
[skb_prio
& 0xF];
446 np
= kmalloc(sizeof(struct vlan_priority_tci_mapping
), GFP_KERNEL
);
451 np
->priority
= skb_prio
;
452 np
->vlan_qos
= vlan_qos
;
453 vlan
->egress_priority_map
[skb_prio
& 0xF] = np
;
455 vlan
->nr_egress_mappings
++;
459 /* Flags are defined in the vlan_flags enum in include/linux/if_vlan.h file. */
460 int vlan_dev_change_flags(const struct net_device
*dev
, u32 flags
, u32 mask
)
462 struct vlan_dev_info
*vlan
= vlan_dev_info(dev
);
463 u32 old_flags
= vlan
->flags
;
465 if (mask
& ~(VLAN_FLAG_REORDER_HDR
| VLAN_FLAG_GVRP
|
466 VLAN_FLAG_LOOSE_BINDING
))
469 vlan
->flags
= (old_flags
& ~mask
) | (flags
& mask
);
471 if (netif_running(dev
) && (vlan
->flags
^ old_flags
) & VLAN_FLAG_GVRP
) {
472 if (vlan
->flags
& VLAN_FLAG_GVRP
)
473 vlan_gvrp_request_join(dev
);
475 vlan_gvrp_request_leave(dev
);
480 void vlan_dev_get_realdev_name(const struct net_device
*dev
, char *result
)
482 strncpy(result
, vlan_dev_info(dev
)->real_dev
->name
, 23);
485 static int vlan_dev_open(struct net_device
*dev
)
487 struct vlan_dev_info
*vlan
= vlan_dev_info(dev
);
488 struct net_device
*real_dev
= vlan
->real_dev
;
491 if (!(real_dev
->flags
& IFF_UP
) &&
492 !(vlan
->flags
& VLAN_FLAG_LOOSE_BINDING
))
495 if (compare_ether_addr(dev
->dev_addr
, real_dev
->dev_addr
)) {
496 err
= dev_uc_add(real_dev
, dev
->dev_addr
);
501 if (dev
->flags
& IFF_ALLMULTI
) {
502 err
= dev_set_allmulti(real_dev
, 1);
506 if (dev
->flags
& IFF_PROMISC
) {
507 err
= dev_set_promiscuity(real_dev
, 1);
512 memcpy(vlan
->real_dev_addr
, real_dev
->dev_addr
, ETH_ALEN
);
514 if (vlan
->flags
& VLAN_FLAG_GVRP
)
515 vlan_gvrp_request_join(dev
);
517 if (netif_carrier_ok(real_dev
))
518 netif_carrier_on(dev
);
522 if (dev
->flags
& IFF_ALLMULTI
)
523 dev_set_allmulti(real_dev
, -1);
525 if (compare_ether_addr(dev
->dev_addr
, real_dev
->dev_addr
))
526 dev_uc_del(real_dev
, dev
->dev_addr
);
528 netif_carrier_off(dev
);
532 static int vlan_dev_stop(struct net_device
*dev
)
534 struct vlan_dev_info
*vlan
= vlan_dev_info(dev
);
535 struct net_device
*real_dev
= vlan
->real_dev
;
537 if (vlan
->flags
& VLAN_FLAG_GVRP
)
538 vlan_gvrp_request_leave(dev
);
540 dev_mc_unsync(real_dev
, dev
);
541 dev_uc_unsync(real_dev
, dev
);
542 if (dev
->flags
& IFF_ALLMULTI
)
543 dev_set_allmulti(real_dev
, -1);
544 if (dev
->flags
& IFF_PROMISC
)
545 dev_set_promiscuity(real_dev
, -1);
547 if (compare_ether_addr(dev
->dev_addr
, real_dev
->dev_addr
))
548 dev_uc_del(real_dev
, dev
->dev_addr
);
550 netif_carrier_off(dev
);
554 static int vlan_dev_set_mac_address(struct net_device
*dev
, void *p
)
556 struct net_device
*real_dev
= vlan_dev_info(dev
)->real_dev
;
557 struct sockaddr
*addr
= p
;
560 if (!is_valid_ether_addr(addr
->sa_data
))
561 return -EADDRNOTAVAIL
;
563 if (!(dev
->flags
& IFF_UP
))
566 if (compare_ether_addr(addr
->sa_data
, real_dev
->dev_addr
)) {
567 err
= dev_uc_add(real_dev
, addr
->sa_data
);
572 if (compare_ether_addr(dev
->dev_addr
, real_dev
->dev_addr
))
573 dev_uc_del(real_dev
, dev
->dev_addr
);
576 memcpy(dev
->dev_addr
, addr
->sa_data
, ETH_ALEN
);
580 static int vlan_dev_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
582 struct net_device
*real_dev
= vlan_dev_info(dev
)->real_dev
;
583 const struct net_device_ops
*ops
= real_dev
->netdev_ops
;
585 int err
= -EOPNOTSUPP
;
587 strncpy(ifrr
.ifr_name
, real_dev
->name
, IFNAMSIZ
);
588 ifrr
.ifr_ifru
= ifr
->ifr_ifru
;
594 if (netif_device_present(real_dev
) && ops
->ndo_do_ioctl
)
595 err
= ops
->ndo_do_ioctl(real_dev
, &ifrr
, cmd
);
600 ifr
->ifr_ifru
= ifrr
.ifr_ifru
;
605 static int vlan_dev_neigh_setup(struct net_device
*dev
, struct neigh_parms
*pa
)
607 struct net_device
*real_dev
= vlan_dev_info(dev
)->real_dev
;
608 const struct net_device_ops
*ops
= real_dev
->netdev_ops
;
611 if (netif_device_present(real_dev
) && ops
->ndo_neigh_setup
)
612 err
= ops
->ndo_neigh_setup(real_dev
, pa
);
617 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
618 static int vlan_dev_fcoe_ddp_setup(struct net_device
*dev
, u16 xid
,
619 struct scatterlist
*sgl
, unsigned int sgc
)
621 struct net_device
*real_dev
= vlan_dev_info(dev
)->real_dev
;
622 const struct net_device_ops
*ops
= real_dev
->netdev_ops
;
625 if (ops
->ndo_fcoe_ddp_setup
)
626 rc
= ops
->ndo_fcoe_ddp_setup(real_dev
, xid
, sgl
, sgc
);
631 static int vlan_dev_fcoe_ddp_done(struct net_device
*dev
, u16 xid
)
633 struct net_device
*real_dev
= vlan_dev_info(dev
)->real_dev
;
634 const struct net_device_ops
*ops
= real_dev
->netdev_ops
;
637 if (ops
->ndo_fcoe_ddp_done
)
638 len
= ops
->ndo_fcoe_ddp_done(real_dev
, xid
);
643 static int vlan_dev_fcoe_enable(struct net_device
*dev
)
645 struct net_device
*real_dev
= vlan_dev_info(dev
)->real_dev
;
646 const struct net_device_ops
*ops
= real_dev
->netdev_ops
;
649 if (ops
->ndo_fcoe_enable
)
650 rc
= ops
->ndo_fcoe_enable(real_dev
);
654 static int vlan_dev_fcoe_disable(struct net_device
*dev
)
656 struct net_device
*real_dev
= vlan_dev_info(dev
)->real_dev
;
657 const struct net_device_ops
*ops
= real_dev
->netdev_ops
;
660 if (ops
->ndo_fcoe_disable
)
661 rc
= ops
->ndo_fcoe_disable(real_dev
);
665 static int vlan_dev_fcoe_get_wwn(struct net_device
*dev
, u64
*wwn
, int type
)
667 struct net_device
*real_dev
= vlan_dev_info(dev
)->real_dev
;
668 const struct net_device_ops
*ops
= real_dev
->netdev_ops
;
671 if (ops
->ndo_fcoe_get_wwn
)
672 rc
= ops
->ndo_fcoe_get_wwn(real_dev
, wwn
, type
);
677 static void vlan_dev_change_rx_flags(struct net_device
*dev
, int change
)
679 struct net_device
*real_dev
= vlan_dev_info(dev
)->real_dev
;
681 if (change
& IFF_ALLMULTI
)
682 dev_set_allmulti(real_dev
, dev
->flags
& IFF_ALLMULTI
? 1 : -1);
683 if (change
& IFF_PROMISC
)
684 dev_set_promiscuity(real_dev
, dev
->flags
& IFF_PROMISC
? 1 : -1);
687 static void vlan_dev_set_rx_mode(struct net_device
*vlan_dev
)
689 dev_mc_sync(vlan_dev_info(vlan_dev
)->real_dev
, vlan_dev
);
690 dev_uc_sync(vlan_dev_info(vlan_dev
)->real_dev
, vlan_dev
);
694 * vlan network devices have devices nesting below it, and are a special
695 * "super class" of normal network devices; split their locks off into a
696 * separate class since they always nest.
698 static struct lock_class_key vlan_netdev_xmit_lock_key
;
699 static struct lock_class_key vlan_netdev_addr_lock_key
;
701 static void vlan_dev_set_lockdep_one(struct net_device
*dev
,
702 struct netdev_queue
*txq
,
705 lockdep_set_class_and_subclass(&txq
->_xmit_lock
,
706 &vlan_netdev_xmit_lock_key
,
710 static void vlan_dev_set_lockdep_class(struct net_device
*dev
, int subclass
)
712 lockdep_set_class_and_subclass(&dev
->addr_list_lock
,
713 &vlan_netdev_addr_lock_key
,
715 netdev_for_each_tx_queue(dev
, vlan_dev_set_lockdep_one
, &subclass
);
718 static const struct header_ops vlan_header_ops
= {
719 .create
= vlan_dev_hard_header
,
720 .rebuild
= vlan_dev_rebuild_header
,
721 .parse
= eth_header_parse
,
724 static const struct net_device_ops vlan_netdev_ops
, vlan_netdev_accel_ops
,
725 vlan_netdev_ops_sq
, vlan_netdev_accel_ops_sq
;
727 static int vlan_dev_init(struct net_device
*dev
)
729 struct net_device
*real_dev
= vlan_dev_info(dev
)->real_dev
;
732 netif_carrier_off(dev
);
734 /* IFF_BROADCAST|IFF_MULTICAST; ??? */
735 dev
->flags
= real_dev
->flags
& ~(IFF_UP
| IFF_PROMISC
| IFF_ALLMULTI
|
736 IFF_MASTER
| IFF_SLAVE
);
737 dev
->iflink
= real_dev
->ifindex
;
738 dev
->state
= (real_dev
->state
& ((1<<__LINK_STATE_NOCARRIER
) |
739 (1<<__LINK_STATE_DORMANT
))) |
740 (1<<__LINK_STATE_PRESENT
);
742 dev
->features
|= real_dev
->features
& real_dev
->vlan_features
;
743 dev
->gso_max_size
= real_dev
->gso_max_size
;
745 /* ipv6 shared card related stuff */
746 dev
->dev_id
= real_dev
->dev_id
;
748 if (is_zero_ether_addr(dev
->dev_addr
))
749 memcpy(dev
->dev_addr
, real_dev
->dev_addr
, dev
->addr_len
);
750 if (is_zero_ether_addr(dev
->broadcast
))
751 memcpy(dev
->broadcast
, real_dev
->broadcast
, dev
->addr_len
);
753 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
754 dev
->fcoe_ddp_xid
= real_dev
->fcoe_ddp_xid
;
757 if (real_dev
->features
& NETIF_F_HW_VLAN_TX
) {
758 dev
->header_ops
= real_dev
->header_ops
;
759 dev
->hard_header_len
= real_dev
->hard_header_len
;
760 if (real_dev
->netdev_ops
->ndo_select_queue
)
761 dev
->netdev_ops
= &vlan_netdev_accel_ops_sq
;
763 dev
->netdev_ops
= &vlan_netdev_accel_ops
;
765 dev
->header_ops
= &vlan_header_ops
;
766 dev
->hard_header_len
= real_dev
->hard_header_len
+ VLAN_HLEN
;
767 if (real_dev
->netdev_ops
->ndo_select_queue
)
768 dev
->netdev_ops
= &vlan_netdev_ops_sq
;
770 dev
->netdev_ops
= &vlan_netdev_ops
;
773 if (is_vlan_dev(real_dev
))
776 vlan_dev_set_lockdep_class(dev
, subclass
);
778 vlan_dev_info(dev
)->vlan_rx_stats
= alloc_percpu(struct vlan_rx_stats
);
779 if (!vlan_dev_info(dev
)->vlan_rx_stats
)
785 static void vlan_dev_uninit(struct net_device
*dev
)
787 struct vlan_priority_tci_mapping
*pm
;
788 struct vlan_dev_info
*vlan
= vlan_dev_info(dev
);
791 free_percpu(vlan
->vlan_rx_stats
);
792 vlan
->vlan_rx_stats
= NULL
;
793 for (i
= 0; i
< ARRAY_SIZE(vlan
->egress_priority_map
); i
++) {
794 while ((pm
= vlan
->egress_priority_map
[i
]) != NULL
) {
795 vlan
->egress_priority_map
[i
] = pm
->next
;
801 static int vlan_ethtool_get_settings(struct net_device
*dev
,
802 struct ethtool_cmd
*cmd
)
804 const struct vlan_dev_info
*vlan
= vlan_dev_info(dev
);
805 return dev_ethtool_get_settings(vlan
->real_dev
, cmd
);
808 static void vlan_ethtool_get_drvinfo(struct net_device
*dev
,
809 struct ethtool_drvinfo
*info
)
811 strcpy(info
->driver
, vlan_fullname
);
812 strcpy(info
->version
, vlan_version
);
813 strcpy(info
->fw_version
, "N/A");
816 static u32
vlan_ethtool_get_rx_csum(struct net_device
*dev
)
818 const struct vlan_dev_info
*vlan
= vlan_dev_info(dev
);
819 return dev_ethtool_get_rx_csum(vlan
->real_dev
);
822 static u32
vlan_ethtool_get_flags(struct net_device
*dev
)
824 const struct vlan_dev_info
*vlan
= vlan_dev_info(dev
);
825 return dev_ethtool_get_flags(vlan
->real_dev
);
828 static struct rtnl_link_stats64
*vlan_dev_get_stats64(struct net_device
*dev
, struct rtnl_link_stats64
*stats
)
830 dev_txq_stats_fold(dev
, stats
);
832 if (vlan_dev_info(dev
)->vlan_rx_stats
) {
833 struct vlan_rx_stats
*p
, accum
= {0};
836 for_each_possible_cpu(i
) {
837 u64 rxpackets
, rxbytes
, rxmulticast
;
840 p
= per_cpu_ptr(vlan_dev_info(dev
)->vlan_rx_stats
, i
);
842 start
= u64_stats_fetch_begin_bh(&p
->syncp
);
843 rxpackets
= p
->rx_packets
;
844 rxbytes
= p
->rx_bytes
;
845 rxmulticast
= p
->rx_multicast
;
846 } while (u64_stats_fetch_retry_bh(&p
->syncp
, start
));
847 accum
.rx_packets
+= rxpackets
;
848 accum
.rx_bytes
+= rxbytes
;
849 accum
.rx_multicast
+= rxmulticast
;
850 /* rx_errors is an ulong, not protected by syncp */
851 accum
.rx_errors
+= p
->rx_errors
;
853 stats
->rx_packets
= accum
.rx_packets
;
854 stats
->rx_bytes
= accum
.rx_bytes
;
855 stats
->rx_errors
= accum
.rx_errors
;
856 stats
->multicast
= accum
.rx_multicast
;
861 static int vlan_ethtool_set_tso(struct net_device
*dev
, u32 data
)
864 struct net_device
*real_dev
= vlan_dev_info(dev
)->real_dev
;
866 /* Underlying device must support TSO for VLAN-tagged packets
867 * and must have TSO enabled now.
869 if (!(real_dev
->vlan_features
& NETIF_F_TSO
))
871 if (!(real_dev
->features
& NETIF_F_TSO
))
873 dev
->features
|= NETIF_F_TSO
;
875 dev
->features
&= ~NETIF_F_TSO
;
880 static const struct ethtool_ops vlan_ethtool_ops
= {
881 .get_settings
= vlan_ethtool_get_settings
,
882 .get_drvinfo
= vlan_ethtool_get_drvinfo
,
883 .get_link
= ethtool_op_get_link
,
884 .get_rx_csum
= vlan_ethtool_get_rx_csum
,
885 .get_flags
= vlan_ethtool_get_flags
,
886 .set_tso
= vlan_ethtool_set_tso
,
889 static const struct net_device_ops vlan_netdev_ops
= {
890 .ndo_change_mtu
= vlan_dev_change_mtu
,
891 .ndo_init
= vlan_dev_init
,
892 .ndo_uninit
= vlan_dev_uninit
,
893 .ndo_open
= vlan_dev_open
,
894 .ndo_stop
= vlan_dev_stop
,
895 .ndo_start_xmit
= vlan_dev_hard_start_xmit
,
896 .ndo_validate_addr
= eth_validate_addr
,
897 .ndo_set_mac_address
= vlan_dev_set_mac_address
,
898 .ndo_set_rx_mode
= vlan_dev_set_rx_mode
,
899 .ndo_set_multicast_list
= vlan_dev_set_rx_mode
,
900 .ndo_change_rx_flags
= vlan_dev_change_rx_flags
,
901 .ndo_do_ioctl
= vlan_dev_ioctl
,
902 .ndo_neigh_setup
= vlan_dev_neigh_setup
,
903 .ndo_get_stats64
= vlan_dev_get_stats64
,
904 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
905 .ndo_fcoe_ddp_setup
= vlan_dev_fcoe_ddp_setup
,
906 .ndo_fcoe_ddp_done
= vlan_dev_fcoe_ddp_done
,
907 .ndo_fcoe_enable
= vlan_dev_fcoe_enable
,
908 .ndo_fcoe_disable
= vlan_dev_fcoe_disable
,
909 .ndo_fcoe_get_wwn
= vlan_dev_fcoe_get_wwn
,
913 static const struct net_device_ops vlan_netdev_accel_ops
= {
914 .ndo_change_mtu
= vlan_dev_change_mtu
,
915 .ndo_init
= vlan_dev_init
,
916 .ndo_uninit
= vlan_dev_uninit
,
917 .ndo_open
= vlan_dev_open
,
918 .ndo_stop
= vlan_dev_stop
,
919 .ndo_start_xmit
= vlan_dev_hwaccel_hard_start_xmit
,
920 .ndo_validate_addr
= eth_validate_addr
,
921 .ndo_set_mac_address
= vlan_dev_set_mac_address
,
922 .ndo_set_rx_mode
= vlan_dev_set_rx_mode
,
923 .ndo_set_multicast_list
= vlan_dev_set_rx_mode
,
924 .ndo_change_rx_flags
= vlan_dev_change_rx_flags
,
925 .ndo_do_ioctl
= vlan_dev_ioctl
,
926 .ndo_neigh_setup
= vlan_dev_neigh_setup
,
927 .ndo_get_stats64
= vlan_dev_get_stats64
,
928 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
929 .ndo_fcoe_ddp_setup
= vlan_dev_fcoe_ddp_setup
,
930 .ndo_fcoe_ddp_done
= vlan_dev_fcoe_ddp_done
,
931 .ndo_fcoe_enable
= vlan_dev_fcoe_enable
,
932 .ndo_fcoe_disable
= vlan_dev_fcoe_disable
,
933 .ndo_fcoe_get_wwn
= vlan_dev_fcoe_get_wwn
,
937 static const struct net_device_ops vlan_netdev_ops_sq
= {
938 .ndo_select_queue
= vlan_dev_select_queue
,
939 .ndo_change_mtu
= vlan_dev_change_mtu
,
940 .ndo_init
= vlan_dev_init
,
941 .ndo_uninit
= vlan_dev_uninit
,
942 .ndo_open
= vlan_dev_open
,
943 .ndo_stop
= vlan_dev_stop
,
944 .ndo_start_xmit
= vlan_dev_hard_start_xmit
,
945 .ndo_validate_addr
= eth_validate_addr
,
946 .ndo_set_mac_address
= vlan_dev_set_mac_address
,
947 .ndo_set_rx_mode
= vlan_dev_set_rx_mode
,
948 .ndo_set_multicast_list
= vlan_dev_set_rx_mode
,
949 .ndo_change_rx_flags
= vlan_dev_change_rx_flags
,
950 .ndo_do_ioctl
= vlan_dev_ioctl
,
951 .ndo_neigh_setup
= vlan_dev_neigh_setup
,
952 .ndo_get_stats64
= vlan_dev_get_stats64
,
953 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
954 .ndo_fcoe_ddp_setup
= vlan_dev_fcoe_ddp_setup
,
955 .ndo_fcoe_ddp_done
= vlan_dev_fcoe_ddp_done
,
956 .ndo_fcoe_enable
= vlan_dev_fcoe_enable
,
957 .ndo_fcoe_disable
= vlan_dev_fcoe_disable
,
958 .ndo_fcoe_get_wwn
= vlan_dev_fcoe_get_wwn
,
962 static const struct net_device_ops vlan_netdev_accel_ops_sq
= {
963 .ndo_select_queue
= vlan_dev_select_queue
,
964 .ndo_change_mtu
= vlan_dev_change_mtu
,
965 .ndo_init
= vlan_dev_init
,
966 .ndo_uninit
= vlan_dev_uninit
,
967 .ndo_open
= vlan_dev_open
,
968 .ndo_stop
= vlan_dev_stop
,
969 .ndo_start_xmit
= vlan_dev_hwaccel_hard_start_xmit
,
970 .ndo_validate_addr
= eth_validate_addr
,
971 .ndo_set_mac_address
= vlan_dev_set_mac_address
,
972 .ndo_set_rx_mode
= vlan_dev_set_rx_mode
,
973 .ndo_set_multicast_list
= vlan_dev_set_rx_mode
,
974 .ndo_change_rx_flags
= vlan_dev_change_rx_flags
,
975 .ndo_do_ioctl
= vlan_dev_ioctl
,
976 .ndo_neigh_setup
= vlan_dev_neigh_setup
,
977 .ndo_get_stats64
= vlan_dev_get_stats64
,
978 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
979 .ndo_fcoe_ddp_setup
= vlan_dev_fcoe_ddp_setup
,
980 .ndo_fcoe_ddp_done
= vlan_dev_fcoe_ddp_done
,
981 .ndo_fcoe_enable
= vlan_dev_fcoe_enable
,
982 .ndo_fcoe_disable
= vlan_dev_fcoe_disable
,
983 .ndo_fcoe_get_wwn
= vlan_dev_fcoe_get_wwn
,
987 void vlan_setup(struct net_device
*dev
)
991 dev
->priv_flags
|= IFF_802_1Q_VLAN
;
992 dev
->priv_flags
&= ~IFF_XMIT_DST_RELEASE
;
993 dev
->tx_queue_len
= 0;
995 dev
->netdev_ops
= &vlan_netdev_ops
;
996 dev
->destructor
= free_netdev
;
997 dev
->ethtool_ops
= &vlan_ethtool_ops
;
999 memset(dev
->broadcast
, 0, ETH_ALEN
);