git: 4b22565f8598 - stable/14 - mana: fix tso parameters and set hwassist bits

From: Wei Hu <whu_at_FreeBSD.org>
Date: Sat, 09 Sep 2023 14:06:02 UTC
The branch stable/14 has been updated by whu:

URL: https://cgit.FreeBSD.org/src/commit/?id=4b22565f8598f2890d41e179fd36a0845f781262

commit 4b22565f8598f2890d41e179fd36a0845f781262
Author:     Wei Hu <whu@FreeBSD.org>
AuthorDate: 2023-09-04 14:53:10 +0000
Commit:     Wei Hu <whu@FreeBSD.org>
CommitDate: 2023-09-09 13:57:50 +0000

    mana: fix tso parameters and set hwassist bits
    
    The parameters for tso on mana were not set correctly. Also the
    hwassist bits were not set. These two cause tso on mana not work.
    Fixed the issues and make tso working on mana.
    
    Tested by:      whu
    MFC after:      3 days
    Sponsored by:   Microsoft
    
    (cherry picked from commit 643fd7b4bc57de87ddfeb75a8f0bdb27dbb8c3ce)
---
 sys/dev/mana/mana.h    |  1 +
 sys/dev/mana/mana_en.c | 16 +++++++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/sys/dev/mana/mana.h b/sys/dev/mana/mana.h
index df527df10296..9a22ea87baa3 100644
--- a/sys/dev/mana/mana.h
+++ b/sys/dev/mana/mana.h
@@ -186,6 +186,7 @@ struct mana_txq {
  */
 #define	MAX_MBUF_FRAGS		30
 #define MANA_TSO_MAXSEG_SZ	PAGE_SIZE
+#define MANA_TSO_MAX_SZ		IP_MAXPACKET
 
 /* mbuf data and frags dma mappings */
 struct mana_mbuf_head {
diff --git a/sys/dev/mana/mana_en.c b/sys/dev/mana/mana_en.c
index fa49e06e4862..56fa4e51ba26 100644
--- a/sys/dev/mana/mana_en.c
+++ b/sys/dev/mana/mana_en.c
@@ -798,8 +798,7 @@ mana_init_port_context(struct mana_port_context *apc)
 	uint32_t tso_maxsize;
 	int err;
 
-	tso_maxsize = MAX_MBUF_FRAGS * MANA_TSO_MAXSEG_SZ -
-	    (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN);
+	tso_maxsize = MANA_TSO_MAX_SZ;
 
 	/* Create DMA tag for tx bufs */
 	err = bus_dma_tag_create(bus_get_dma_tag(dev),	/* parent */
@@ -2712,6 +2711,7 @@ mana_probe_port(struct mana_context *ac, int port_idx,
 {
 	struct gdma_context *gc = ac->gdma_dev->gdma_context;
 	struct mana_port_context *apc;
+	uint32_t hwassist;
 	if_t ndev;
 	int err;
 
@@ -2774,11 +2774,21 @@ mana_probe_port(struct mana_context *ac, int port_idx,
 	if_setcapenable(ndev, if_getcapabilities(ndev));
 
 	/* TSO parameters */
-	if_sethwtsomax(ndev, MAX_MBUF_FRAGS * MANA_TSO_MAXSEG_SZ -
+	if_sethwtsomax(ndev, MANA_TSO_MAX_SZ -
 	    (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN));
 	if_sethwtsomaxsegcount(ndev, MAX_MBUF_FRAGS);
 	if_sethwtsomaxsegsize(ndev, PAGE_SIZE);
 
+	hwassist = 0;
+	if (if_getcapenable(ndev) & (IFCAP_TSO4 | IFCAP_TSO6))
+		hwassist |= CSUM_TSO;
+	if (if_getcapenable(ndev) & IFCAP_TXCSUM)
+		hwassist |= (CSUM_TCP | CSUM_UDP | CSUM_IP);
+	if (if_getcapenable(ndev) & IFCAP_TXCSUM_IPV6)
+		hwassist |= (CSUM_UDP_IPV6 | CSUM_TCP_IPV6);
+	mana_dbg(NULL, "set hwassist 0x%x\n", hwassist);
+	if_sethwassist(ndev, hwassist);
+
 	ifmedia_init(&apc->media, IFM_IMASK,
 	    mana_ifmedia_change, mana_ifmedia_status);
 	ifmedia_add(&apc->media, IFM_ETHER | IFM_AUTO, 0, NULL);