[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID:
<PAXPR04MB85105409DFD9E82A8EE1528B885D2@PAXPR04MB8510.eurprd04.prod.outlook.com>
Date: Fri, 8 Nov 2024 01:32:12 +0000
From: Wei Fang <wei.fang@....com>
To: Frank Li <frank.li@....com>
CC: Claudiu Manoil <claudiu.manoil@....com>, Vladimir Oltean
<vladimir.oltean@....com>, Clark Wang <xiaoning.wang@....com>,
"andrew+netdev@...n.ch" <andrew+netdev@...n.ch>, "davem@...emloft.net"
<davem@...emloft.net>, "edumazet@...gle.com" <edumazet@...gle.com>,
"kuba@...nel.org" <kuba@...nel.org>, "pabeni@...hat.com" <pabeni@...hat.com>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"imx@...ts.linux.dev" <imx@...ts.linux.dev>
Subject: RE: [PATCH net-next 2/5] net: enetc: add Tx checksum offload for
i.MX95 ENETC
>
> On Thu, Nov 07, 2024 at 11:38:14AM +0800, Wei Fang wrote:
> > In addition to supporting Rx checksum offload, i.MX95 ENETC also
> > supports Tx checksum offload. The transmit checksum offload is
> > implemented through the Tx BD. To support Tx checksum offload,
> > software needs to fill some auxiliary information in Tx BD, such as IP
> > version, IP header offset and size, whether L4 is UDP or TCP, etc.
>
> Add empty line here
>
> > Same as Rx checksum offload, Tx checksum offload capability isn't
> > defined in register, so tx_csum bit is added to struct enetc_drvdata
> > to indicate whether the device supports Tx checksum offload.
> >
> > Signed-off-by: Wei Fang <wei.fang@....com>
> > ---
> > drivers/net/ethernet/freescale/enetc/enetc.c | 52
> > ++++++++++++++++--- drivers/net/ethernet/freescale/enetc/enetc.h | 2
> +
> > .../net/ethernet/freescale/enetc/enetc_hw.h | 14 +++--
> > .../freescale/enetc/enetc_pf_common.c | 3 ++
> > 4 files changed, 61 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c
> > b/drivers/net/ethernet/freescale/enetc/enetc.c
> > index 3137b6ee62d3..f98d14841838 100644
> > --- a/drivers/net/ethernet/freescale/enetc/enetc.c
> > +++ b/drivers/net/ethernet/freescale/enetc/enetc.c
> > @@ -143,6 +143,26 @@ static int enetc_ptp_parse(struct sk_buff *skb, u8
> *udp,
> > return 0;
> > }
> >
> > +static bool enetc_tx_csum_offload_check(struct sk_buff *skb) {
> > + if (ip_hdr(skb)->version == 4)
> > + return ip_hdr(skb)->protocol == IPPROTO_TCP ||
> > + ip_hdr(skb)->protocol == IPPROTO_UDP;
> > + else if (ip_hdr(skb)->version == 6)
>
> needn't else
>
> > + return ipv6_hdr(skb)->nexthdr == NEXTHDR_TCP ||
> > + ipv6_hdr(skb)->nexthdr == NEXTHDR_UDP;
> > + else
>
> needn't else, I remember some compiler check will report warning.
>
I'm not sure whether other compilers complain warning, but I can
refine this helper function.
> > + return false;
> > +}
> > +
> > +static bool enetc_skb_is_tcp(struct sk_buff *skb) {
> > + if (ip_hdr(skb)->version == 4)
> > + return ip_hdr(skb)->protocol == IPPROTO_TCP;
> > + else
> > + return ipv6_hdr(skb)->nexthdr == NEXTHDR_TCP; }
> > +
> > static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct
> > sk_buff *skb) {
> > bool do_vlan, do_onestep_tstamp = false, do_twostep_tstamp = false;
> > @@ -160,6 +180,29 @@ static int enetc_map_tx_buffs(struct enetc_bdr
> *tx_ring, struct sk_buff *skb)
> > dma_addr_t dma;
> > u8 flags = 0;
> >
> > + enetc_clear_tx_bd(&temp_bd);
> > + if (skb->ip_summed == CHECKSUM_PARTIAL) {
> > + /* Can not support TSD and checksum offload at the same time */
> > + if (priv->active_offloads & ENETC_F_TXCSUM &&
> > + enetc_tx_csum_offload_check(skb) && !tx_ring->tsd_enable) {
> > + bool is_ipv6 = ip_hdr(skb)->version == 6;
> > + bool is_tcp = enetc_skb_is_tcp(skb);
> > +
> > + temp_bd.l3_start = skb_network_offset(skb);
> > + temp_bd.ipcs = is_ipv6 ? 0 : 1;
> > + temp_bd.l3_hdr_size = skb_network_header_len(skb) / 4;
> > + temp_bd.l3t = is_ipv6 ? 1 : 0;
> > + temp_bd.l4t = is_tcp ? ENETC_TXBD_L4T_TCP :
> ENETC_TXBD_L4T_UDP;
> > + flags |= ENETC_TXBD_FLAGS_CSUM_LSO |
> ENETC_TXBD_FLAGS_L4CS;
> > + } else {
> > + if (skb_checksum_help(skb)) {
> > + dev_err(tx_ring->dev, "skb_checksum_help() error\n");
> > +
> > + return 0;
> > + }
> > + }
> > + }
> > +
> > i = tx_ring->next_to_use;
> > txbd = ENETC_TXBD(*tx_ring, i);
> > prefetchw(txbd);
> > @@ -170,7 +213,6 @@ static int enetc_map_tx_buffs(struct enetc_bdr
> > *tx_ring, struct sk_buff *skb)
> >
> > temp_bd.addr = cpu_to_le64(dma);
> > temp_bd.buf_len = cpu_to_le16(len);
> > - temp_bd.lstatus = 0;
>
> not sure why remove clean lstatus here.
>
Below is the snippet of Tx BD format, set lstatus to 0 will clear
the auxiliary information for LSO, due to we have cleared the
entire Tx BD at the beginning (enetc_clear_tx_bd(&temp_bd)).
So it is safe to remove lstatus.
union {
struct {
u8 l3_start:7;
u8 ipcs:1;
u8 l3_hdr_size:7;
u8 l3t:1;
u8 resv:5;
u8 l4t:3;
u8 flags;
}; /* default layout */
__le32 txstart;
__le32 lstatus;
};
Powered by blists - more mailing lists