summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Pirko <jpirko@redhat.com>2011-07-20 23:26:31 -0400
committerDavid S. Miller <davem@davemloft.net>2011-07-21 16:47:57 -0400
commit5622e4044a916de1af84bfcc4d437ce0c799d531 (patch)
tree1ed8e79892147ffe8c746cc4b5f6ee6eeb06426b
parenta4aeb26628b5184386f99cf202ac837b0e56c975 (diff)
e1000: do vlan cleanup
- unify vlan and nonvlan rx path - kill adapter->vlgrp and e1000_vlan_rx_register - allow to turn on/off rx/tx vlan accel via ethtool (set_features) Signed-off-by: Jiri Pirko <jpirko@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/e1000/e1000.h2
-rw-r--r--drivers/net/e1000/e1000_main.c168
2 files changed, 108 insertions, 62 deletions
diff --git a/drivers/net/e1000/e1000.h b/drivers/net/e1000/e1000.h
index 8676899120c3..24f41da8c4be 100644
--- a/drivers/net/e1000/e1000.h
+++ b/drivers/net/e1000/e1000.h
@@ -215,7 +215,7 @@ struct e1000_adapter {
215 struct timer_list tx_fifo_stall_timer; 215 struct timer_list tx_fifo_stall_timer;
216 struct timer_list watchdog_timer; 216 struct timer_list watchdog_timer;
217 struct timer_list phy_info_timer; 217 struct timer_list phy_info_timer;
218 struct vlan_group *vlgrp; 218 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
219 u16 mng_vlan_id; 219 u16 mng_vlan_id;
220 u32 bd_number; 220 u32 bd_number;
221 u32 rx_buffer_len; 221 u32 rx_buffer_len;
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index 188d99ae9084..acaebecf0ca7 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -30,6 +30,8 @@
30#include <net/ip6_checksum.h> 30#include <net/ip6_checksum.h>
31#include <linux/io.h> 31#include <linux/io.h>
32#include <linux/prefetch.h> 32#include <linux/prefetch.h>
33#include <linux/bitops.h>
34#include <linux/if_vlan.h>
33 35
34/* Intel Media SOC GbE MDIO physical base address */ 36/* Intel Media SOC GbE MDIO physical base address */
35static unsigned long ce4100_gbe_mdio_base_phy; 37static unsigned long ce4100_gbe_mdio_base_phy;
@@ -166,7 +168,8 @@ static void e1000_smartspeed(struct e1000_adapter *adapter);
166static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter, 168static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
167 struct sk_buff *skb); 169 struct sk_buff *skb);
168 170
169static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp); 171static bool e1000_vlan_used(struct e1000_adapter *adapter);
172static void e1000_vlan_mode(struct net_device *netdev, u32 features);
170static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid); 173static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid);
171static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid); 174static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid);
172static void e1000_restore_vlan(struct e1000_adapter *adapter); 175static void e1000_restore_vlan(struct e1000_adapter *adapter);
@@ -330,21 +333,24 @@ static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
330 struct net_device *netdev = adapter->netdev; 333 struct net_device *netdev = adapter->netdev;
331 u16 vid = hw->mng_cookie.vlan_id; 334 u16 vid = hw->mng_cookie.vlan_id;
332 u16 old_vid = adapter->mng_vlan_id; 335 u16 old_vid = adapter->mng_vlan_id;
333 if (adapter->vlgrp) {
334 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
335 if (hw->mng_cookie.status &
336 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
337 e1000_vlan_rx_add_vid(netdev, vid);
338 adapter->mng_vlan_id = vid;
339 } else
340 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
341 336
342 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && 337 if (!e1000_vlan_used(adapter))
343 (vid != old_vid) && 338 return;
344 !vlan_group_get_device(adapter->vlgrp, old_vid)) 339
345 e1000_vlan_rx_kill_vid(netdev, old_vid); 340 if (!test_bit(vid, adapter->active_vlans)) {
346 } else 341 if (hw->mng_cookie.status &
342 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
343 e1000_vlan_rx_add_vid(netdev, vid);
347 adapter->mng_vlan_id = vid; 344 adapter->mng_vlan_id = vid;
345 } else {
346 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
347 }
348 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
349 (vid != old_vid) &&
350 !test_bit(old_vid, adapter->active_vlans))
351 e1000_vlan_rx_kill_vid(netdev, old_vid);
352 } else {
353 adapter->mng_vlan_id = vid;
348 } 354 }
349} 355}
350 356
@@ -797,11 +803,28 @@ static int e1000_is_need_ioport(struct pci_dev *pdev)
797 } 803 }
798} 804}
799 805
806static u32 e1000_fix_features(struct net_device *netdev, u32 features)
807{
808 /*
809 * Since there is no support for separate rx/tx vlan accel
810 * enable/disable make sure tx flag is always in same state as rx.
811 */
812 if (features & NETIF_F_HW_VLAN_RX)
813 features |= NETIF_F_HW_VLAN_TX;
814 else
815 features &= ~NETIF_F_HW_VLAN_TX;
816
817 return features;
818}
819
800static int e1000_set_features(struct net_device *netdev, u32 features) 820static int e1000_set_features(struct net_device *netdev, u32 features)
801{ 821{
802 struct e1000_adapter *adapter = netdev_priv(netdev); 822 struct e1000_adapter *adapter = netdev_priv(netdev);
803 u32 changed = features ^ netdev->features; 823 u32 changed = features ^ netdev->features;
804 824
825 if (changed & NETIF_F_HW_VLAN_RX)
826 e1000_vlan_mode(netdev, features);
827
805 if (!(changed & NETIF_F_RXCSUM)) 828 if (!(changed & NETIF_F_RXCSUM))
806 return 0; 829 return 0;
807 830
@@ -822,18 +845,17 @@ static const struct net_device_ops e1000_netdev_ops = {
822 .ndo_get_stats = e1000_get_stats, 845 .ndo_get_stats = e1000_get_stats,
823 .ndo_set_rx_mode = e1000_set_rx_mode, 846 .ndo_set_rx_mode = e1000_set_rx_mode,
824 .ndo_set_mac_address = e1000_set_mac, 847 .ndo_set_mac_address = e1000_set_mac,
825 .ndo_tx_timeout = e1000_tx_timeout, 848 .ndo_tx_timeout = e1000_tx_timeout,
826 .ndo_change_mtu = e1000_change_mtu, 849 .ndo_change_mtu = e1000_change_mtu,
827 .ndo_do_ioctl = e1000_ioctl, 850 .ndo_do_ioctl = e1000_ioctl,
828 .ndo_validate_addr = eth_validate_addr, 851 .ndo_validate_addr = eth_validate_addr,
829
830 .ndo_vlan_rx_register = e1000_vlan_rx_register,
831 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid, 852 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
832 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid, 853 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
833#ifdef CONFIG_NET_POLL_CONTROLLER 854#ifdef CONFIG_NET_POLL_CONTROLLER
834 .ndo_poll_controller = e1000_netpoll, 855 .ndo_poll_controller = e1000_netpoll,
835#endif 856#endif
836 .ndo_set_features = e1000_set_features, 857 .ndo_fix_features = e1000_fix_features,
858 .ndo_set_features = e1000_set_features,
837}; 859};
838 860
839/** 861/**
@@ -1036,9 +1058,9 @@ static int __devinit e1000_probe(struct pci_dev *pdev,
1036 1058
1037 if (hw->mac_type >= e1000_82543) { 1059 if (hw->mac_type >= e1000_82543) {
1038 netdev->hw_features = NETIF_F_SG | 1060 netdev->hw_features = NETIF_F_SG |
1039 NETIF_F_HW_CSUM; 1061 NETIF_F_HW_CSUM |
1062 NETIF_F_HW_VLAN_RX;
1040 netdev->features = NETIF_F_HW_VLAN_TX | 1063 netdev->features = NETIF_F_HW_VLAN_TX |
1041 NETIF_F_HW_VLAN_RX |
1042 NETIF_F_HW_VLAN_FILTER; 1064 NETIF_F_HW_VLAN_FILTER;
1043 } 1065 }
1044 1066
@@ -1197,6 +1219,8 @@ static int __devinit e1000_probe(struct pci_dev *pdev,
1197 if (err) 1219 if (err)
1198 goto err_register; 1220 goto err_register;
1199 1221
1222 e1000_vlan_mode(netdev, netdev->features);
1223
1200 /* print bus type/speed/width info */ 1224 /* print bus type/speed/width info */
1201 e_info(probe, "(PCI%s:%dMHz:%d-bit) %pM\n", 1225 e_info(probe, "(PCI%s:%dMHz:%d-bit) %pM\n",
1202 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" : ""), 1226 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" : ""),
@@ -1441,8 +1465,7 @@ static int e1000_close(struct net_device *netdev)
1441 * the same ID is registered on the host OS (let 8021q kill it) */ 1465 * the same ID is registered on the host OS (let 8021q kill it) */
1442 if ((hw->mng_cookie.status & 1466 if ((hw->mng_cookie.status &
1443 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && 1467 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1444 !(adapter->vlgrp && 1468 !test_bit(adapter->mng_vlan_id, adapter->active_vlans)) {
1445 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
1446 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); 1469 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1447 } 1470 }
1448 1471
@@ -2233,7 +2256,7 @@ static void e1000_set_rx_mode(struct net_device *netdev)
2233 else 2256 else
2234 rctl &= ~E1000_RCTL_MPE; 2257 rctl &= ~E1000_RCTL_MPE;
2235 /* Enable VLAN filter if there is a VLAN */ 2258 /* Enable VLAN filter if there is a VLAN */
2236 if (adapter->vlgrp) 2259 if (e1000_vlan_used(adapter))
2237 rctl |= E1000_RCTL_VFE; 2260 rctl |= E1000_RCTL_VFE;
2238 } 2261 }
2239 2262
@@ -3180,7 +3203,7 @@ static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
3180 } 3203 }
3181 } 3204 }
3182 3205
3183 if (unlikely(vlan_tx_tag_present(skb))) { 3206 if (vlan_tx_tag_present(skb)) {
3184 tx_flags |= E1000_TX_FLAGS_VLAN; 3207 tx_flags |= E1000_TX_FLAGS_VLAN;
3185 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); 3208 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3186 } 3209 }
@@ -3735,12 +3758,12 @@ static void e1000_receive_skb(struct e1000_adapter *adapter, u8 status,
3735{ 3758{
3736 skb->protocol = eth_type_trans(skb, adapter->netdev); 3759 skb->protocol = eth_type_trans(skb, adapter->netdev);
3737 3760
3738 if ((unlikely(adapter->vlgrp && (status & E1000_RXD_STAT_VP)))) 3761 if (status & E1000_RXD_STAT_VP) {
3739 vlan_gro_receive(&adapter->napi, adapter->vlgrp, 3762 u16 vid = le16_to_cpu(vlan) & E1000_RXD_SPC_VLAN_MASK;
3740 le16_to_cpu(vlan) & E1000_RXD_SPC_VLAN_MASK, 3763
3741 skb); 3764 __vlan_hwaccel_put_tag(skb, vid);
3742 else 3765 }
3743 napi_gro_receive(&adapter->napi, skb); 3766 napi_gro_receive(&adapter->napi, skb);
3744} 3767}
3745 3768
3746/** 3769/**
@@ -4523,46 +4546,61 @@ void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value)
4523 outl(value, port); 4546 outl(value, port);
4524} 4547}
4525 4548
4526static void e1000_vlan_rx_register(struct net_device *netdev, 4549static bool e1000_vlan_used(struct e1000_adapter *adapter)
4527 struct vlan_group *grp) 4550{
4551 u16 vid;
4552
4553 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
4554 return true;
4555 return false;
4556}
4557
4558static void e1000_vlan_filter_on_off(struct e1000_adapter *adapter,
4559 bool filter_on)
4528{ 4560{
4529 struct e1000_adapter *adapter = netdev_priv(netdev);
4530 struct e1000_hw *hw = &adapter->hw; 4561 struct e1000_hw *hw = &adapter->hw;
4531 u32 ctrl, rctl; 4562 u32 rctl;
4532 4563
4533 if (!test_bit(__E1000_DOWN, &adapter->flags)) 4564 if (!test_bit(__E1000_DOWN, &adapter->flags))
4534 e1000_irq_disable(adapter); 4565 e1000_irq_disable(adapter);
4535 adapter->vlgrp = grp;
4536
4537 if (grp) {
4538 /* enable VLAN tag insert/strip */
4539 ctrl = er32(CTRL);
4540 ctrl |= E1000_CTRL_VME;
4541 ew32(CTRL, ctrl);
4542 4566
4567 if (filter_on) {
4543 /* enable VLAN receive filtering */ 4568 /* enable VLAN receive filtering */
4544 rctl = er32(RCTL); 4569 rctl = er32(RCTL);
4545 rctl &= ~E1000_RCTL_CFIEN; 4570 rctl &= ~E1000_RCTL_CFIEN;
4546 if (!(netdev->flags & IFF_PROMISC)) 4571 if (!(adapter->netdev->flags & IFF_PROMISC))
4547 rctl |= E1000_RCTL_VFE; 4572 rctl |= E1000_RCTL_VFE;
4548 ew32(RCTL, rctl); 4573 ew32(RCTL, rctl);
4549 e1000_update_mng_vlan(adapter); 4574 e1000_update_mng_vlan(adapter);
4550 } else { 4575 } else {
4551 /* disable VLAN tag insert/strip */
4552 ctrl = er32(CTRL);
4553 ctrl &= ~E1000_CTRL_VME;
4554 ew32(CTRL, ctrl);
4555
4556 /* disable VLAN receive filtering */ 4576 /* disable VLAN receive filtering */
4557 rctl = er32(RCTL); 4577 rctl = er32(RCTL);
4558 rctl &= ~E1000_RCTL_VFE; 4578 rctl &= ~E1000_RCTL_VFE;
4559 ew32(RCTL, rctl); 4579 ew32(RCTL, rctl);
4580 }
4560 4581
4561 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) { 4582 if (!test_bit(__E1000_DOWN, &adapter->flags))
4562 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); 4583 e1000_irq_enable(adapter);
4563 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; 4584}
4564 } 4585
4586static void e1000_vlan_mode(struct net_device *netdev, u32 features)
4587{
4588 struct e1000_adapter *adapter = netdev_priv(netdev);
4589 struct e1000_hw *hw = &adapter->hw;
4590 u32 ctrl;
4591
4592 if (!test_bit(__E1000_DOWN, &adapter->flags))
4593 e1000_irq_disable(adapter);
4594
4595 ctrl = er32(CTRL);
4596 if (features & NETIF_F_HW_VLAN_RX) {
4597 /* enable VLAN tag insert/strip */
4598 ctrl |= E1000_CTRL_VME;
4599 } else {
4600 /* disable VLAN tag insert/strip */
4601 ctrl &= ~E1000_CTRL_VME;
4565 } 4602 }
4603 ew32(CTRL, ctrl);
4566 4604
4567 if (!test_bit(__E1000_DOWN, &adapter->flags)) 4605 if (!test_bit(__E1000_DOWN, &adapter->flags))
4568 e1000_irq_enable(adapter); 4606 e1000_irq_enable(adapter);
@@ -4578,11 +4616,17 @@ static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
4578 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && 4616 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4579 (vid == adapter->mng_vlan_id)) 4617 (vid == adapter->mng_vlan_id))
4580 return; 4618 return;
4619
4620 if (!e1000_vlan_used(adapter))
4621 e1000_vlan_filter_on_off(adapter, true);
4622
4581 /* add VID to filter table */ 4623 /* add VID to filter table */
4582 index = (vid >> 5) & 0x7F; 4624 index = (vid >> 5) & 0x7F;
4583 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index); 4625 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
4584 vfta |= (1 << (vid & 0x1F)); 4626 vfta |= (1 << (vid & 0x1F));
4585 e1000_write_vfta(hw, index, vfta); 4627 e1000_write_vfta(hw, index, vfta);
4628
4629 set_bit(vid, adapter->active_vlans);
4586} 4630}
4587 4631
4588static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) 4632static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
@@ -4593,7 +4637,6 @@ static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
4593 4637
4594 if (!test_bit(__E1000_DOWN, &adapter->flags)) 4638 if (!test_bit(__E1000_DOWN, &adapter->flags))
4595 e1000_irq_disable(adapter); 4639 e1000_irq_disable(adapter);
4596 vlan_group_set_device(adapter->vlgrp, vid, NULL);
4597 if (!test_bit(__E1000_DOWN, &adapter->flags)) 4640 if (!test_bit(__E1000_DOWN, &adapter->flags))
4598 e1000_irq_enable(adapter); 4641 e1000_irq_enable(adapter);
4599 4642
@@ -4602,20 +4645,23 @@ static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
4602 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index); 4645 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
4603 vfta &= ~(1 << (vid & 0x1F)); 4646 vfta &= ~(1 << (vid & 0x1F));
4604 e1000_write_vfta(hw, index, vfta); 4647 e1000_write_vfta(hw, index, vfta);
4648
4649 clear_bit(vid, adapter->active_vlans);
4650
4651 if (!e1000_vlan_used(adapter))
4652 e1000_vlan_filter_on_off(adapter, false);
4605} 4653}
4606 4654
4607static void e1000_restore_vlan(struct e1000_adapter *adapter) 4655static void e1000_restore_vlan(struct e1000_adapter *adapter)
4608{ 4656{
4609 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp); 4657 u16 vid;
4610 4658
4611 if (adapter->vlgrp) { 4659 if (!e1000_vlan_used(adapter))
4612 u16 vid; 4660 return;
4613 for (vid = 0; vid < VLAN_N_VID; vid++) { 4661
4614 if (!vlan_group_get_device(adapter->vlgrp, vid)) 4662 e1000_vlan_filter_on_off(adapter, true);
4615 continue; 4663 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
4616 e1000_vlan_rx_add_vid(adapter->netdev, vid); 4664 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4617 }
4618 }
4619} 4665}
4620 4666
4621int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx) 4667int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)