net: ethernet: ti: cpsw: fix min eth packet size for non-switch use-cases
commit acc68b8d2a1196c4db806947606f162dbeed2274 upstream. The CPSW switchdev driver inherited fix from commit9421c90150
("net: ethernet: ti: cpsw: fix min eth packet size") which changes min TX packet size to 64bytes (VLAN_ETH_ZLEN, excluding ETH_FCS). It was done to fix HW packed drop issue when packets are sent from Host to the port with PVID and un-tagging enabled. Unfortunately this breaks some other non-switch specific use-cases, like: - [1] CPSW port as DSA CPU port with DSA-tag applied at the end of the packet - [2] Some industrial protocols, which expects min TX packet size 60Bytes (excluding FCS). Fix it by configuring min TX packet size depending on driver mode - 60Bytes (ETH_ZLEN) for multi mac (dual-mac) mode - 64Bytes (VLAN_ETH_ZLEN) for switch mode and update it during driver mode change and annotate with READ_ONCE()/WRITE_ONCE() as it can be read by napi while writing. [1] https://lore.kernel.org/netdev/20210531124051.GA15218@cephalopod/ [2] https://e2e.ti.com/support/arm/sitara_arm/f/791/t/701669 Cc: stable@vger.kernel.org Fixes:ed3525eda4
("net: ethernet: ti: introduce cpsw switchdev based driver part 1 - dual-emac") Reported-by: Ben Hutchings <ben.hutchings@essensium.com> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
561d13128b
commit
4716a2145b
@@ -928,7 +928,7 @@ static netdev_tx_t cpsw_ndo_start_xmit(struct sk_buff *skb,
|
|||||||
struct cpdma_chan *txch;
|
struct cpdma_chan *txch;
|
||||||
int ret, q_idx;
|
int ret, q_idx;
|
||||||
|
|
||||||
if (skb_padto(skb, CPSW_MIN_PACKET_SIZE)) {
|
if (skb_put_padto(skb, READ_ONCE(priv->tx_packet_min))) {
|
||||||
cpsw_err(priv, tx_err, "packet pad failed\n");
|
cpsw_err(priv, tx_err, "packet pad failed\n");
|
||||||
ndev->stats.tx_dropped++;
|
ndev->stats.tx_dropped++;
|
||||||
return NET_XMIT_DROP;
|
return NET_XMIT_DROP;
|
||||||
@@ -1108,7 +1108,7 @@ static int cpsw_ndo_xdp_xmit(struct net_device *ndev, int n,
|
|||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
xdpf = frames[i];
|
xdpf = frames[i];
|
||||||
if (xdpf->len < CPSW_MIN_PACKET_SIZE) {
|
if (xdpf->len < READ_ONCE(priv->tx_packet_min)) {
|
||||||
xdp_return_frame_rx_napi(xdpf);
|
xdp_return_frame_rx_napi(xdpf);
|
||||||
drops++;
|
drops++;
|
||||||
continue;
|
continue;
|
||||||
@@ -1402,6 +1402,7 @@ static int cpsw_create_ports(struct cpsw_common *cpsw)
|
|||||||
priv->dev = dev;
|
priv->dev = dev;
|
||||||
priv->msg_enable = netif_msg_init(debug_level, CPSW_DEBUG);
|
priv->msg_enable = netif_msg_init(debug_level, CPSW_DEBUG);
|
||||||
priv->emac_port = i + 1;
|
priv->emac_port = i + 1;
|
||||||
|
priv->tx_packet_min = CPSW_MIN_PACKET_SIZE;
|
||||||
|
|
||||||
if (is_valid_ether_addr(slave_data->mac_addr)) {
|
if (is_valid_ether_addr(slave_data->mac_addr)) {
|
||||||
ether_addr_copy(priv->mac_addr, slave_data->mac_addr);
|
ether_addr_copy(priv->mac_addr, slave_data->mac_addr);
|
||||||
@@ -1699,6 +1700,7 @@ static int cpsw_dl_switch_mode_set(struct devlink *dl, u32 id,
|
|||||||
|
|
||||||
priv = netdev_priv(sl_ndev);
|
priv = netdev_priv(sl_ndev);
|
||||||
slave->port_vlan = vlan;
|
slave->port_vlan = vlan;
|
||||||
|
WRITE_ONCE(priv->tx_packet_min, CPSW_MIN_PACKET_SIZE_VLAN);
|
||||||
if (netif_running(sl_ndev))
|
if (netif_running(sl_ndev))
|
||||||
cpsw_port_add_switch_def_ale_entries(priv,
|
cpsw_port_add_switch_def_ale_entries(priv,
|
||||||
slave);
|
slave);
|
||||||
@@ -1727,6 +1729,7 @@ static int cpsw_dl_switch_mode_set(struct devlink *dl, u32 id,
|
|||||||
|
|
||||||
priv = netdev_priv(slave->ndev);
|
priv = netdev_priv(slave->ndev);
|
||||||
slave->port_vlan = slave->data->dual_emac_res_vlan;
|
slave->port_vlan = slave->data->dual_emac_res_vlan;
|
||||||
|
WRITE_ONCE(priv->tx_packet_min, CPSW_MIN_PACKET_SIZE);
|
||||||
cpsw_port_add_dual_emac_def_ale_entries(priv, slave);
|
cpsw_port_add_dual_emac_def_ale_entries(priv, slave);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -89,7 +89,8 @@ do { \
|
|||||||
|
|
||||||
#define CPSW_POLL_WEIGHT 64
|
#define CPSW_POLL_WEIGHT 64
|
||||||
#define CPSW_RX_VLAN_ENCAP_HDR_SIZE 4
|
#define CPSW_RX_VLAN_ENCAP_HDR_SIZE 4
|
||||||
#define CPSW_MIN_PACKET_SIZE (VLAN_ETH_ZLEN)
|
#define CPSW_MIN_PACKET_SIZE_VLAN (VLAN_ETH_ZLEN)
|
||||||
|
#define CPSW_MIN_PACKET_SIZE (ETH_ZLEN)
|
||||||
#define CPSW_MAX_PACKET_SIZE (VLAN_ETH_FRAME_LEN +\
|
#define CPSW_MAX_PACKET_SIZE (VLAN_ETH_FRAME_LEN +\
|
||||||
ETH_FCS_LEN +\
|
ETH_FCS_LEN +\
|
||||||
CPSW_RX_VLAN_ENCAP_HDR_SIZE)
|
CPSW_RX_VLAN_ENCAP_HDR_SIZE)
|
||||||
@@ -380,6 +381,7 @@ struct cpsw_priv {
|
|||||||
u32 emac_port;
|
u32 emac_port;
|
||||||
struct cpsw_common *cpsw;
|
struct cpsw_common *cpsw;
|
||||||
int offload_fwd_mark;
|
int offload_fwd_mark;
|
||||||
|
u32 tx_packet_min;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ndev_to_cpsw(ndev) (((struct cpsw_priv *)netdev_priv(ndev))->cpsw)
|
#define ndev_to_cpsw(ndev) (((struct cpsw_priv *)netdev_priv(ndev))->cpsw)
|
||||||
|
Reference in New Issue
Block a user