Skip to content

Commit c2be7a5

Browse files
committed
HSD #15012366445: drivers: net: stmmac_main: Add support for HW-accelerated VLAN Stripping
Currently, VLAN tag stripping is done by driver in stmmac_rx_vlan(). Add support for VLAN tag stripping by the MAC hardware for MAC drivers that support it. This is done by adding rx_hw_vlan() and set_hw_vlan_mode() callbacks at stmmac_ops struct which are called if registered by the MAC driver. This patch is applying at the higher level of the driver at stmmac_main this will be upstreammed by IoTG team and thus it is decoupled from the next patch. Signed-off-by: Boon Khai Ng <boon.khai.ng@intel.com>
1 parent dd1c68b commit c2be7a5

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

drivers/net/ethernet/stmicro/stmmac/hwif.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ struct stmmac_desc_ops {
5555
void (*set_tx_ic)(struct dma_desc *p);
5656
/* Last tx segment reports the transmit status */
5757
int (*get_tx_ls)(struct dma_desc *p);
58+
/* RX VLAN TCI */
59+
int (*get_rx_vlan_tci)(struct dma_desc *p);
60+
/* RX VLAN valid */
61+
bool (*get_rx_vlan_valid)(struct dma_desc *p);
5862
/* Return the transmit status looking at the TDES1 */
5963
int (*tx_status)(void *data, struct stmmac_extra_stats *x,
6064
struct dma_desc *p, void __iomem *ioaddr);
@@ -116,6 +120,10 @@ struct stmmac_desc_ops {
116120
stmmac_do_void_callback(__priv, desc, set_tx_ic, __args)
117121
#define stmmac_get_tx_ls(__priv, __args...) \
118122
stmmac_do_callback(__priv, desc, get_tx_ls, __args)
123+
#define stmmac_get_rx_vlan_tci(__priv,__args...) \
124+
stmmac_do_callback(__priv, desc, get_tx_vlan_tci, __args)
125+
#define stmmac_get_rx_vlan_valid(__priv,__args...) \
126+
stmmac_do_callback(__priv, desc, get_tx_vlan_valid, __args)
119127
#define stmmac_tx_status(__priv, __args...) \
120128
stmmac_do_callback(__priv, desc, tx_status, __args)
121129
#define stmmac_get_tx_len(__priv, __args...) \
@@ -368,6 +376,10 @@ struct stmmac_ops {
368376
void (*update_vlan_hash)(struct mac_device_info *hw, u32 hash,
369377
__le16 perfect_match, bool is_double);
370378
void (*enable_vlan)(struct mac_device_info *hw, u32 type);
379+
void (*rx_hw_vlan)(struct net_device *dev, struct mac_device_info *hw,
380+
struct dma_desc *rx_desc, struct sk_buff *skb);
381+
void (*set_hw_vlan_mode)(void __iomem *ioaddr,
382+
netdev_features_t features);
371383
int (*add_hw_vlan_rx_fltr)(struct net_device *dev,
372384
struct mac_device_info *hw,
373385
__be16 proto, u16 vid);
@@ -475,6 +487,10 @@ struct stmmac_ops {
475487
stmmac_do_void_callback(__priv, mac, update_vlan_hash, __args)
476488
#define stmmac_enable_vlan(__priv, __args...) \
477489
stmmac_do_void_callback(__priv, mac, enable_vlan, __args)
490+
#define stmmac_rx_hw_vlan(__priv, __args...) \
491+
stmmac_do_void_callback(__priv, mac, rx_hw_vlan, __args)
492+
#define stmmac_set_hw_vlan_mode(__priv, __args...) \
493+
stmmac_do_void_callback(__priv, mac, set_hw_vlan_mode, __args)
478494
#define stmmac_add_hw_vlan_rx_fltr(__priv, __args...) \
479495
stmmac_do_callback(__priv, mac, add_hw_vlan_rx_fltr, __args)
480496
#define stmmac_del_hw_vlan_rx_fltr(__priv, __args...) \

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3412,6 +3412,10 @@ static int stmmac_hw_setup(struct net_device *dev, bool ptp_register)
34123412
stmmac_fpe_handshake(priv, true);
34133413
}
34143414

3415+
/* Set HW VLAN Stripping mode */
3416+
if (priv->plat->use_hw_vlan)
3417+
stmmac_set_hw_vlan_mode(priv, priv->ioaddr, dev->features);
3418+
34153419
return 0;
34163420
}
34173421

@@ -5390,7 +5394,14 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
53905394
/* Got entire packet into SKB. Finish it. */
53915395

53925396
stmmac_get_rx_hwtstamp(priv, p, np, skb);
5393-
stmmac_rx_vlan(priv->dev, skb);
5397+
5398+
/* Switch between rx_hw_vlan or rx_vlan */
5399+
if(priv->plat->use_hw_vlan)
5400+
stmmac_rx_hw_vlan(priv, priv->dev,
5401+
priv->hw, p, skb);
5402+
else
5403+
stmmac_rx_vlan(priv->dev, skb);
5404+
53945405
skb->protocol = eth_type_trans(skb, priv->dev);
53955406

53965407
if (unlikely(!coe))
@@ -5641,6 +5652,10 @@ static int stmmac_set_features(struct net_device *netdev,
56415652
{
56425653
struct stmmac_priv *priv = netdev_priv(netdev);
56435654

5655+
netdev_features_t changed;
5656+
5657+
changed = netdev->features ^ features;
5658+
56445659
/* Keep the COE Type in case of csum is supporting */
56455660
if (features & NETIF_F_RXCSUM)
56465661
priv->hw->rx_csum = priv->plat->rx_coe;
@@ -5659,6 +5674,9 @@ static int stmmac_set_features(struct net_device *netdev,
56595674
stmmac_enable_sph(priv, priv->ioaddr, sph_en, chan);
56605675
}
56615676

5677+
if(changed & NETIF_F_HW_VLAN_CTAG_RX)
5678+
stmmac_set_hw_vlan_mode(priv, priv->ioaddr, features);
5679+
56625680
return 0;
56635681
}
56645682

@@ -7200,6 +7218,8 @@ int stmmac_dvr_probe(struct device *device,
72007218
#ifdef STMMAC_VLAN_TAG_USED
72017219
/* Both mac100 and gmac support receive VLAN tag detection */
72027220
ndev->features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX;
7221+
ndev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX;
7222+
72037223
if (priv->dma_cap.vlhash) {
72047224
ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
72057225
ndev->features |= NETIF_F_HW_VLAN_STAG_FILTER;

include/linux/stmmac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,5 +271,6 @@ struct plat_stmmacenet_data {
271271
int msi_tx_base_vec;
272272
bool use_phy_wol;
273273
bool sph_disable;
274+
bool use_hw_vlan;
274275
};
275276
#endif

0 commit comments

Comments
 (0)