Re: ix hardware tso

2023-05-18 Thread Peter Stuge
Alexander Bluhm wrote:
> we cannot do hardware TSO in a bridge.  Maybe we could if all
> bridge members support it.

Just a note that I've discussed another "if all bridge members" case
with dlg; switch drivers eventually knowing to do bridge offloading.


//Peter



Re: ix hardware tso

2023-05-17 Thread Alexander Bluhm
On Tue, May 16, 2023 at 12:35:06PM -0600, Todd C. Miller wrote:
> On Tue, 16 May 2023 19:26:07 +0200, Alexander Bluhm wrote:
> 
> > On Tue, May 16, 2023 at 11:15:31AM -0600, Todd C. Miller wrote:
> > > Would it be possible to move the forward declaration of struct tdb
> > > to netinet/tcp_var.h so it is not required in every driver?
> >
> > sure
> 
> Thanks, that looks better to me.

I have tested ix(4) "Intel X540T" manually, "Intel 82598AF" and
"Intel 82599" are in my automatic setup.  Hvroje also did a lot of
testing.

Diff survived a make release.

I think jan@ should commit this now.  OK bluhm@

Index: dev/pci/if_ix.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/dev/pci/if_ix.c,v
retrieving revision 1.194
diff -u -p -r1.194 if_ix.c
--- dev/pci/if_ix.c 16 May 2023 14:32:54 -  1.194
+++ dev/pci/if_ix.c 17 May 2023 08:53:07 -
@@ -1924,6 +1924,7 @@ ixgbe_setup_interface(struct ix_softc *s
ifp->if_capabilities |= IFCAP_CSUM_TCPv6 | IFCAP_CSUM_UDPv6;
ifp->if_capabilities |= IFCAP_CSUM_IPv4;
 
+   ifp->if_capabilities |= IFCAP_TSOv4 | IFCAP_TSOv6;
if (sc->hw.mac.type != ixgbe_mac_82598EB)
ifp->if_capabilities |= IFCAP_LRO;
 
@@ -2344,6 +2345,7 @@ ixgbe_initialize_transmit_units(struct i
int  i;
uint64_t tdba;
uint32_t txctrl;
+   uint32_t hlreg;
 
/* Setup the Base and Length of the Tx Descriptor Ring */
 
@@ -2405,6 +2407,11 @@ ixgbe_initialize_transmit_units(struct i
rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
}
+
+   /* Enable TCP/UDP padding when using TSO */
+   hlreg = IXGBE_READ_REG(hw, IXGBE_HLREG0);
+   hlreg |= IXGBE_HLREG0_TXPADEN;
+   IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg);
 }
 
 /*
@@ -2473,16 +2480,18 @@ ixgbe_free_transmit_buffers(struct tx_ri
  **/
 
 static inline int
-ixgbe_csum_offload(struct mbuf *mp, uint32_t *vlan_macip_lens,
-uint32_t *type_tucmd_mlhl, uint32_t *olinfo_status)
+ixgbe_tx_offload(struct mbuf *mp, uint32_t *vlan_macip_lens,
+uint32_t *type_tucmd_mlhl, uint32_t *olinfo_status, uint32_t *cmd_type_len,
+uint32_t *mss_l4len_idx)
 {
struct ether_extracted ext;
int offload = 0;
-   uint32_t iphlen;
+   uint32_t ethlen, iphlen;
 
ether_extract_headers(mp, );
+   ethlen = sizeof(*ext.eh);
 
-   *vlan_macip_lens |= (sizeof(*ext.eh) << IXGBE_ADVTXD_MACLEN_SHIFT);
+   *vlan_macip_lens |= (ethlen << IXGBE_ADVTXD_MACLEN_SHIFT);
 
if (ext.ip4) {
iphlen = ext.ip4->ip_hl << 2;
@@ -2500,6 +2509,8 @@ ixgbe_csum_offload(struct mbuf *mp, uint
*type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV6;
 #endif
} else {
+   if (mp->m_pkthdr.csum_flags & M_TCP_TSO)
+   tcpstat_inc(tcps_outbadtso);
return offload;
}
 
@@ -2519,6 +2530,31 @@ ixgbe_csum_offload(struct mbuf *mp, uint
}
}
 
+   if (mp->m_pkthdr.csum_flags & M_TCP_TSO) {
+   if (ext.tcp) {
+   uint32_t hdrlen, thlen, paylen, outlen;
+
+   thlen = ext.tcp->th_off << 2;
+
+   outlen = mp->m_pkthdr.ph_mss;
+   *mss_l4len_idx |= outlen << IXGBE_ADVTXD_MSS_SHIFT;
+   *mss_l4len_idx |= thlen << IXGBE_ADVTXD_L4LEN_SHIFT;
+
+   hdrlen = ethlen + iphlen + thlen;
+   paylen = mp->m_pkthdr.len - hdrlen;
+   CLR(*olinfo_status, IXGBE_ADVTXD_PAYLEN_MASK
+   << IXGBE_ADVTXD_PAYLEN_SHIFT);
+   *olinfo_status |= paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
+
+   *cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
+   offload = 1;
+
+   tcpstat_add(tcps_outpkttso,
+   (paylen + outlen - 1) / outlen);
+   } else
+   tcpstat_inc(tcps_outbadtso);
+   }
+
return offload;
 }
 
@@ -2529,6 +2565,7 @@ ixgbe_tx_ctx_setup(struct tx_ring *txr, 
struct ixgbe_adv_tx_context_desc *TXD;
struct ixgbe_tx_buf *tx_buffer;
uint32_t vlan_macip_lens = 0, type_tucmd_mlhl = 0;
+   uint32_t mss_l4len_idx = 0;
int ctxd = txr->next_avail_desc;
int offload = 0;
 
@@ -2544,8 +2581,8 @@ ixgbe_tx_ctx_setup(struct tx_ring *txr, 
}
 #endif
 
-   offload |= ixgbe_csum_offload(mp, _macip_lens, _tucmd_mlhl,
-   olinfo_status);
+   offload |= ixgbe_tx_offload(mp, _macip_lens, _tucmd_mlhl,
+   olinfo_status, cmd_type_len, _l4len_idx);
 
if (!offload)
return (0);
@@ -2559,7 

Re: ix hardware tso

2023-05-16 Thread Todd C . Miller
On Tue, 16 May 2023 19:26:07 +0200, Alexander Bluhm wrote:

> On Tue, May 16, 2023 at 11:15:31AM -0600, Todd C. Miller wrote:
> > Would it be possible to move the forward declaration of struct tdb
> > to netinet/tcp_var.h so it is not required in every driver?
>
> sure

Thanks, that looks better to me.

 - todd



Re: ix hardware tso

2023-05-16 Thread Alexander Bluhm
On Tue, May 16, 2023 at 11:15:31AM -0600, Todd C. Miller wrote:
> Would it be possible to move the forward declaration of struct tdb
> to netinet/tcp_var.h so it is not required in every driver?

sure

Index: dev/pci/if_ix.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/dev/pci/if_ix.c,v
retrieving revision 1.194
diff -u -p -r1.194 if_ix.c
--- dev/pci/if_ix.c 16 May 2023 14:32:54 -  1.194
+++ dev/pci/if_ix.c 16 May 2023 16:07:53 -
@@ -1924,6 +1924,7 @@ ixgbe_setup_interface(struct ix_softc *s
ifp->if_capabilities |= IFCAP_CSUM_TCPv6 | IFCAP_CSUM_UDPv6;
ifp->if_capabilities |= IFCAP_CSUM_IPv4;
 
+   ifp->if_capabilities |= IFCAP_TSOv4 | IFCAP_TSOv6;
if (sc->hw.mac.type != ixgbe_mac_82598EB)
ifp->if_capabilities |= IFCAP_LRO;
 
@@ -2344,6 +2345,7 @@ ixgbe_initialize_transmit_units(struct i
int  i;
uint64_t tdba;
uint32_t txctrl;
+   uint32_t hlreg;
 
/* Setup the Base and Length of the Tx Descriptor Ring */
 
@@ -2405,6 +2407,11 @@ ixgbe_initialize_transmit_units(struct i
rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
}
+
+   /* Enable TCP/UDP padding when using TSO */
+   hlreg = IXGBE_READ_REG(hw, IXGBE_HLREG0);
+   hlreg |= IXGBE_HLREG0_TXPADEN;
+   IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg);
 }
 
 /*
@@ -2473,16 +2480,18 @@ ixgbe_free_transmit_buffers(struct tx_ri
  **/
 
 static inline int
-ixgbe_csum_offload(struct mbuf *mp, uint32_t *vlan_macip_lens,
-uint32_t *type_tucmd_mlhl, uint32_t *olinfo_status)
+ixgbe_tx_offload(struct mbuf *mp, uint32_t *vlan_macip_lens,
+uint32_t *type_tucmd_mlhl, uint32_t *olinfo_status, uint32_t *cmd_type_len,
+uint32_t *mss_l4len_idx)
 {
struct ether_extracted ext;
int offload = 0;
-   uint32_t iphlen;
+   uint32_t ethlen, iphlen;
 
ether_extract_headers(mp, );
+   ethlen = sizeof(*ext.eh);
 
-   *vlan_macip_lens |= (sizeof(*ext.eh) << IXGBE_ADVTXD_MACLEN_SHIFT);
+   *vlan_macip_lens |= (ethlen << IXGBE_ADVTXD_MACLEN_SHIFT);
 
if (ext.ip4) {
iphlen = ext.ip4->ip_hl << 2;
@@ -2500,6 +2509,8 @@ ixgbe_csum_offload(struct mbuf *mp, uint
*type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV6;
 #endif
} else {
+   if (mp->m_pkthdr.csum_flags & M_TCP_TSO)
+   tcpstat_inc(tcps_outbadtso);
return offload;
}
 
@@ -2519,6 +2530,31 @@ ixgbe_csum_offload(struct mbuf *mp, uint
}
}
 
+   if (mp->m_pkthdr.csum_flags & M_TCP_TSO) {
+   if (ext.tcp) {
+   uint32_t hdrlen, thlen, paylen, outlen;
+
+   thlen = ext.tcp->th_off << 2;
+
+   outlen = mp->m_pkthdr.ph_mss;
+   *mss_l4len_idx |= outlen << IXGBE_ADVTXD_MSS_SHIFT;
+   *mss_l4len_idx |= thlen << IXGBE_ADVTXD_L4LEN_SHIFT;
+
+   hdrlen = ethlen + iphlen + thlen;
+   paylen = mp->m_pkthdr.len - hdrlen;
+   CLR(*olinfo_status, IXGBE_ADVTXD_PAYLEN_MASK
+   << IXGBE_ADVTXD_PAYLEN_SHIFT);
+   *olinfo_status |= paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
+
+   *cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
+   offload = 1;
+
+   tcpstat_add(tcps_outpkttso,
+   (paylen + outlen - 1) / outlen);
+   } else
+   tcpstat_inc(tcps_outbadtso);
+   }
+
return offload;
 }
 
@@ -2529,6 +2565,7 @@ ixgbe_tx_ctx_setup(struct tx_ring *txr, 
struct ixgbe_adv_tx_context_desc *TXD;
struct ixgbe_tx_buf *tx_buffer;
uint32_t vlan_macip_lens = 0, type_tucmd_mlhl = 0;
+   uint32_t mss_l4len_idx = 0;
int ctxd = txr->next_avail_desc;
int offload = 0;
 
@@ -2544,8 +2581,8 @@ ixgbe_tx_ctx_setup(struct tx_ring *txr, 
}
 #endif
 
-   offload |= ixgbe_csum_offload(mp, _macip_lens, _tucmd_mlhl,
-   olinfo_status);
+   offload |= ixgbe_tx_offload(mp, _macip_lens, _tucmd_mlhl,
+   olinfo_status, cmd_type_len, _l4len_idx);
 
if (!offload)
return (0);
@@ -2559,7 +2596,7 @@ ixgbe_tx_ctx_setup(struct tx_ring *txr, 
TXD->vlan_macip_lens = htole32(vlan_macip_lens);
TXD->type_tucmd_mlhl = htole32(type_tucmd_mlhl);
TXD->seqnum_seed = htole32(0);
-   TXD->mss_l4len_idx = htole32(0);
+   TXD->mss_l4len_idx = htole32(mss_l4len_idx);
 
tx_buffer->m_head = NULL;
tx_buffer->eop_index = -1;
@@ -2868,9 +2905,11 @@ 

Re: ix hardware tso

2023-05-16 Thread Alexander Bluhm
On Tue, May 16, 2023 at 10:48:24AM +0200, Hrvoje Popovski wrote:
> I've tested this diff with x552 and it's working as expected.
> 
> ix0 at pci5 dev 0 function 0 "Intel X552 SFP+" rev 0x00, msix, 4 queues,
> ix1 at pci5 dev 0 function 1 "Intel X552 SFP+" rev 0x00, msix, 4 queues,

My test setup has these.  Automatic test do not cover X540T, will
do manual test.

ix0 at pci3 dev 0 function 0 "Intel 82598AF" rev 0x01, msix, 4 queues,
ix1 at pci4 dev 0 function 0 "Intel 82599" rev 0x01, msix, 4 queues,
ix2 at pci4 dev 0 function 1 "Intel 82599" rev 0x01, msix, 4 queues,
ix3 at pci10 dev 0 function 0 "Intel X540T" rev 0x01, msix, 4 queues,
ix4 at pci10 dev 0 function 1 "Intel X540T" rev 0x01, msix, 4 queues,
ix5 at pci13 dev 0 function 0 "Intel 82599" rev 0x01, msix, 4 queues,
ix6 at pci13 dev 0 function 1 "Intel 82599" rev 0x01, msix, 4 queues,

> netstat -sp tcp | grep TSO
>   46 output TSO packets software chopped
>   772398947 output TSO packets hardware processed
>   4005484521 output TSO packets generated
>   0 output TSO packets dropped

I rebased to current after jan@'s commit and I fixed the "output
TSO packets generated" counter.  There was a small error.

Basically it is jan@'s diff with some counters and cleanup from me.

The additional includes are necessary as TSO is a layer violation.
We need TCP counter in a driver.

ok?

bluhm

Index: dev/pci/if_ix.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/dev/pci/if_ix.c,v
retrieving revision 1.194
diff -u -p -r1.194 if_ix.c
--- dev/pci/if_ix.c 16 May 2023 14:32:54 -  1.194
+++ dev/pci/if_ix.c 16 May 2023 16:07:53 -
@@ -1924,6 +1924,7 @@ ixgbe_setup_interface(struct ix_softc *s
ifp->if_capabilities |= IFCAP_CSUM_TCPv6 | IFCAP_CSUM_UDPv6;
ifp->if_capabilities |= IFCAP_CSUM_IPv4;
 
+   ifp->if_capabilities |= IFCAP_TSOv4 | IFCAP_TSOv6;
if (sc->hw.mac.type != ixgbe_mac_82598EB)
ifp->if_capabilities |= IFCAP_LRO;
 
@@ -2344,6 +2345,7 @@ ixgbe_initialize_transmit_units(struct i
int  i;
uint64_t tdba;
uint32_t txctrl;
+   uint32_t hlreg;
 
/* Setup the Base and Length of the Tx Descriptor Ring */
 
@@ -2405,6 +2407,11 @@ ixgbe_initialize_transmit_units(struct i
rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
}
+
+   /* Enable TCP/UDP padding when using TSO */
+   hlreg = IXGBE_READ_REG(hw, IXGBE_HLREG0);
+   hlreg |= IXGBE_HLREG0_TXPADEN;
+   IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg);
 }
 
 /*
@@ -2473,16 +2480,18 @@ ixgbe_free_transmit_buffers(struct tx_ri
  **/
 
 static inline int
-ixgbe_csum_offload(struct mbuf *mp, uint32_t *vlan_macip_lens,
-uint32_t *type_tucmd_mlhl, uint32_t *olinfo_status)
+ixgbe_tx_offload(struct mbuf *mp, uint32_t *vlan_macip_lens,
+uint32_t *type_tucmd_mlhl, uint32_t *olinfo_status, uint32_t *cmd_type_len,
+uint32_t *mss_l4len_idx)
 {
struct ether_extracted ext;
int offload = 0;
-   uint32_t iphlen;
+   uint32_t ethlen, iphlen;
 
ether_extract_headers(mp, );
+   ethlen = sizeof(*ext.eh);
 
-   *vlan_macip_lens |= (sizeof(*ext.eh) << IXGBE_ADVTXD_MACLEN_SHIFT);
+   *vlan_macip_lens |= (ethlen << IXGBE_ADVTXD_MACLEN_SHIFT);
 
if (ext.ip4) {
iphlen = ext.ip4->ip_hl << 2;
@@ -2500,6 +2509,8 @@ ixgbe_csum_offload(struct mbuf *mp, uint
*type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV6;
 #endif
} else {
+   if (mp->m_pkthdr.csum_flags & M_TCP_TSO)
+   tcpstat_inc(tcps_outbadtso);
return offload;
}
 
@@ -2519,6 +2530,31 @@ ixgbe_csum_offload(struct mbuf *mp, uint
}
}
 
+   if (mp->m_pkthdr.csum_flags & M_TCP_TSO) {
+   if (ext.tcp) {
+   uint32_t hdrlen, thlen, paylen, outlen;
+
+   thlen = ext.tcp->th_off << 2;
+
+   outlen = mp->m_pkthdr.ph_mss;
+   *mss_l4len_idx |= outlen << IXGBE_ADVTXD_MSS_SHIFT;
+   *mss_l4len_idx |= thlen << IXGBE_ADVTXD_L4LEN_SHIFT;
+
+   hdrlen = ethlen + iphlen + thlen;
+   paylen = mp->m_pkthdr.len - hdrlen;
+   CLR(*olinfo_status, IXGBE_ADVTXD_PAYLEN_MASK
+   << IXGBE_ADVTXD_PAYLEN_SHIFT);
+   *olinfo_status |= paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
+
+   *cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
+   offload = 1;
+
+   tcpstat_add(tcps_outpkttso,
+   (paylen + outlen - 1) / outlen);
+   } else
+  

Re: ix hardware tso

2023-05-16 Thread Hrvoje Popovski
On 15.5.2023. 19:39, Alexander Bluhm wrote:
> On Sun, May 14, 2023 at 11:39:01PM +0200, Hrvoje Popovski wrote:
>> I've tested this on openbsd box with 4 iperf3's. 2 for ip4 and 2 for ip6
>> and with 16 tcp streams per iperf.  When testing over ix(4) there is big
>> differences in output performance. When testing ix/veb/vport there is
>> differences in output performance but not that big.
> Thanks a lot for testing.  I have also created some numbers which
> can be seen here.
> 
> http://bluhm.genua.de/perform/results/2023-05-14T09:14:59Z/perform.html
> 
> Sending TCP to Linux host and socket splicing gets faster.
> 
>> When testing over vport I'm getting "software chopped" which should be
>> expected.
> Yes, we cannot do hardware TSO in a bridge.  Maybe we could if all
> bridge members support it.
> 
> Next diff that should go in is where jan@ renames flags, cleans up
> ifconfig(8),. and fixes pseudo interface devices
> 
> Updated ix(4) driver diff after TCP/IP commit is below.

Hi,

I've tested this diff with x552 and it's working as expected.

ix0 at pci5 dev 0 function 0 "Intel X552 SFP+" rev 0x00, msix, 4 queues,
ix1 at pci5 dev 0 function 1 "Intel X552 SFP+" rev 0x00, msix, 4 queues,


netstat -sp tcp | grep TSO
46 output TSO packets software chopped
772398947 output TSO packets hardware processed
4005484521 output TSO packets generated
0 output TSO packets dropped



Re: ix hardware tso

2023-05-15 Thread Alexander Bluhm
On Sun, May 14, 2023 at 11:39:01PM +0200, Hrvoje Popovski wrote:
> I've tested this on openbsd box with 4 iperf3's. 2 for ip4 and 2 for ip6
> and with 16 tcp streams per iperf.  When testing over ix(4) there is big
> differences in output performance. When testing ix/veb/vport there is
> differences in output performance but not that big.

Thanks a lot for testing.  I have also created some numbers which
can be seen here.

http://bluhm.genua.de/perform/results/2023-05-14T09:14:59Z/perform.html

Sending TCP to Linux host and socket splicing gets faster.

> When testing over vport I'm getting "software chopped" which should be
> expected.

Yes, we cannot do hardware TSO in a bridge.  Maybe we could if all
bridge members support it.

Next diff that should go in is where jan@ renames flags, cleans up
ifconfig(8), and fixes pseudo interface devices.

Updated ix(4) driver diff after TCP/IP commit is below.

bluhm

Index: dev/pci/if_ix.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/dev/pci/if_ix.c,v
retrieving revision 1.193
diff -u -p -r1.193 if_ix.c
--- dev/pci/if_ix.c 28 Apr 2023 10:18:57 -  1.193
+++ dev/pci/if_ix.c 15 May 2023 17:27:09 -
@@ -1924,8 +1924,9 @@ ixgbe_setup_interface(struct ix_softc *s
ifp->if_capabilities |= IFCAP_CSUM_TCPv6 | IFCAP_CSUM_UDPv6;
ifp->if_capabilities |= IFCAP_CSUM_IPv4;
 
+   ifp->if_capabilities |= IFCAP_TSOv4 | IFCAP_TSOv6;
if (sc->hw.mac.type != ixgbe_mac_82598EB)
-   ifp->if_capabilities |= IFCAP_TSO;
+   ifp->if_capabilities |= IFCAP_LRO;
 
/*
 * Specify the media types supported by this sc and register
@@ -2344,6 +2345,7 @@ ixgbe_initialize_transmit_units(struct i
int  i;
uint64_t tdba;
uint32_t txctrl;
+   uint32_t hlreg;
 
/* Setup the Base and Length of the Tx Descriptor Ring */
 
@@ -2405,6 +2407,11 @@ ixgbe_initialize_transmit_units(struct i
rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
}
+
+   /* Enable TCP/UDP padding when using TSO */
+   hlreg = IXGBE_READ_REG(hw, IXGBE_HLREG0);
+   hlreg |= IXGBE_HLREG0_TXPADEN;
+   IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg);
 }
 
 /*
@@ -2473,16 +2480,18 @@ ixgbe_free_transmit_buffers(struct tx_ri
  **/
 
 static inline int
-ixgbe_csum_offload(struct mbuf *mp, uint32_t *vlan_macip_lens,
-uint32_t *type_tucmd_mlhl, uint32_t *olinfo_status)
+ixgbe_tx_offload(struct mbuf *mp, uint32_t *vlan_macip_lens,
+uint32_t *type_tucmd_mlhl, uint32_t *olinfo_status, uint32_t *cmd_type_len,
+uint32_t *mss_l4len_idx)
 {
struct ether_extracted ext;
int offload = 0;
-   uint32_t iphlen;
+   uint32_t ethlen, iphlen;
 
ether_extract_headers(mp, );
+   ethlen = sizeof(*ext.eh);
 
-   *vlan_macip_lens |= (sizeof(*ext.eh) << IXGBE_ADVTXD_MACLEN_SHIFT);
+   *vlan_macip_lens |= (ethlen << IXGBE_ADVTXD_MACLEN_SHIFT);
 
if (ext.ip4) {
iphlen = ext.ip4->ip_hl << 2;
@@ -2500,6 +2509,8 @@ ixgbe_csum_offload(struct mbuf *mp, uint
*type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV6;
 #endif
} else {
+   if (mp->m_pkthdr.csum_flags & M_TCP_TSO)
+   tcpstat_inc(tcps_outbadtso);
return offload;
}
 
@@ -2519,6 +2530,32 @@ ixgbe_csum_offload(struct mbuf *mp, uint
}
}
 
+   if (mp->m_pkthdr.csum_flags & M_TCP_TSO) {
+   if (ext.tcp) {
+   uint32_t pktlen, hdrlen, thlen, outlen;
+
+   thlen = ext.tcp->th_off << 2;
+
+   *mss_l4len_idx |= (uint32_t)(mp->m_pkthdr.ph_mss
+   << IXGBE_ADVTXD_MSS_SHIFT);
+   *mss_l4len_idx |= thlen << IXGBE_ADVTXD_L4LEN_SHIFT;
+
+   hdrlen = ethlen + iphlen + thlen;
+   pktlen = mp->m_pkthdr.len - hdrlen;
+   CLR(*olinfo_status, IXGBE_ADVTXD_PAYLEN_MASK
+   << IXGBE_ADVTXD_PAYLEN_SHIFT);
+   *olinfo_status |= pktlen << IXGBE_ADVTXD_PAYLEN_SHIFT;
+
+   *cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
+   offload = 1;
+
+   outlen = hdrlen + mp->m_pkthdr.ph_mss;
+   tcpstat_add(tcps_outpkttso,
+   (pktlen + outlen - 1) / outlen);
+   } else
+   tcpstat_inc(tcps_outbadtso);
+   }
+
return offload;
 }
 
@@ -2529,6 +2566,7 @@ ixgbe_tx_ctx_setup(struct tx_ring *txr, 
struct ixgbe_adv_tx_context_desc *TXD;
struct ixgbe_tx_buf *tx_buffer;
uint32_t 

Re: ix hardware tso

2023-05-15 Thread Peter Stuge
Claudio Jeker wrote:
> > > Do not set ifconfig ix tso, this flag does not work correctly.
> > 
> > Are there plans for that flag? Remove it? Use it? Only document as
> > deprecated? Also print a deprecation message if used?
> 
> It will be removed. No need to overcomplicate it with deprecation message.

Perfect - thanks! I just found the removal in Jan's patch.


//Peter



Re: ix hardware tso

2023-05-15 Thread Claudio Jeker
On Mon, May 15, 2023 at 08:42:20AM +, Peter Stuge wrote:
> Alexander Bluhm wrote:
> > Do not set ifconfig ix tso, this flag does not work correctly.
> 
> Are there plans for that flag? Remove it? Use it? Only document as
> deprecated? Also print a deprecation message if used?

It will be removed. No need to overcomplicate it with deprecation message.

-- 
:wq Claudio



Re: ix hardware tso

2023-05-15 Thread Peter Stuge
Alexander Bluhm wrote:
> Do not set ifconfig ix tso, this flag does not work correctly.

Are there plans for that flag? Remove it? Use it? Only document as
deprecated? Also print a deprecation message if used?


Thanks

//Peter



Re: ix hardware tso

2023-05-14 Thread Hrvoje Popovski
On 14.5.2023. 11:24, Alexander Bluhm wrote:
> On Sat, May 13, 2023 at 01:32:07AM +0200, Alexander Bluhm wrote:
>> I have not yet investigated where the dropped counter 83 comes from.
>> If you see that also, please report what you did.
> This is an ENOBUFS error in this chunk.
> 
> /* network interface hardware will do TSO */
> if (in_ifcap_cksum(*mp, ifp, ifcap)) {
> if (ISSET(ifcap, IFCAP_TSOv4)) {
> in_hdr_cksum_out(*mp, ifp);
> in_proto_cksum_out(*mp, ifp);
> }
> if (ISSET(ifcap, IFCAP_TSOv6))
> in6_proto_cksum_out(*mp, ifp);
> if ((error = ifp->if_output(ifp, *mp, dst, rt))) {
> tcpstat_inc(tcps_outbadtso);
> goto done;
> }
> tcpstat_inc(tcps_outhwtso);
> goto done;
> }
> 
> As the error from ifp->if_output() has nothing todo with TSO, I
> remove the counting there.
> 
> Updated diff, please test if you have ix(4) interfaces doing TCP
> output.


Hi,

I've tested this on openbsd box with 4 iperf3's. 2 for ip4 and 2 for ip6
and with 16 tcp streams per iperf.  When testing over ix(4) there is big
differences in output performance. When testing ix/veb/vport there is
differences in output performance but not that big.

When testing over vport I'm getting "software chopped" which should be
expected.

r620-1# netstat -sp tcp | grep TSO
7921175 output TSO packets software chopped
3739630121 output TSO packets hardware processed
915829954 output TSO packets generated
0 output TSO packets dropped

With previous diff I could easily trigger "TSO packet dropped" but with
this one I couldn't.




Re: ix hardware tso

2023-05-14 Thread Alexander Bluhm
On Sat, May 13, 2023 at 01:32:07AM +0200, Alexander Bluhm wrote:
> I have not yet investigated where the dropped counter 83 comes from.
> If you see that also, please report what you did.

This is an ENOBUFS error in this chunk.

/* network interface hardware will do TSO */
if (in_ifcap_cksum(*mp, ifp, ifcap)) {
if (ISSET(ifcap, IFCAP_TSOv4)) {
in_hdr_cksum_out(*mp, ifp);
in_proto_cksum_out(*mp, ifp);
}
if (ISSET(ifcap, IFCAP_TSOv6))
in6_proto_cksum_out(*mp, ifp);
if ((error = ifp->if_output(ifp, *mp, dst, rt))) {
tcpstat_inc(tcps_outbadtso);
goto done;
}
tcpstat_inc(tcps_outhwtso);
goto done;
}

As the error from ifp->if_output() has nothing todo with TSO, I
remove the counting there.

Updated diff, please test if you have ix(4) interfaces doing TCP
output.

bluhm

Index: dev/pci/if_ix.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/dev/pci/if_ix.c,v
retrieving revision 1.193
diff -u -p -r1.193 if_ix.c
--- dev/pci/if_ix.c 28 Apr 2023 10:18:57 -  1.193
+++ dev/pci/if_ix.c 14 May 2023 09:11:33 -
@@ -1924,8 +1924,9 @@ ixgbe_setup_interface(struct ix_softc *s
ifp->if_capabilities |= IFCAP_CSUM_TCPv6 | IFCAP_CSUM_UDPv6;
ifp->if_capabilities |= IFCAP_CSUM_IPv4;
 
+   ifp->if_capabilities |= IFCAP_TSOv4 | IFCAP_TSOv6;
if (sc->hw.mac.type != ixgbe_mac_82598EB)
-   ifp->if_capabilities |= IFCAP_TSO;
+   ifp->if_capabilities |= IFCAP_LRO;
 
/*
 * Specify the media types supported by this sc and register
@@ -2344,6 +2345,7 @@ ixgbe_initialize_transmit_units(struct i
int  i;
uint64_t tdba;
uint32_t txctrl;
+   uint32_t hlreg;
 
/* Setup the Base and Length of the Tx Descriptor Ring */
 
@@ -2405,6 +2407,11 @@ ixgbe_initialize_transmit_units(struct i
rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
}
+
+   /* Enable TCP/UDP padding when using TSO */
+   hlreg = IXGBE_READ_REG(hw, IXGBE_HLREG0);
+   hlreg |= IXGBE_HLREG0_TXPADEN;
+   IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg);
 }
 
 /*
@@ -2473,16 +2480,18 @@ ixgbe_free_transmit_buffers(struct tx_ri
  **/
 
 static inline int
-ixgbe_csum_offload(struct mbuf *mp, uint32_t *vlan_macip_lens,
-uint32_t *type_tucmd_mlhl, uint32_t *olinfo_status)
+ixgbe_tx_offload(struct mbuf *mp, uint32_t *vlan_macip_lens,
+uint32_t *type_tucmd_mlhl, uint32_t *olinfo_status, uint32_t *cmd_type_len,
+uint32_t *mss_l4len_idx)
 {
struct ether_extracted ext;
int offload = 0;
-   uint32_t iphlen;
+   uint32_t ethlen, iphlen;
 
ether_extract_headers(mp, );
+   ethlen = sizeof(*ext.eh);
 
-   *vlan_macip_lens |= (sizeof(*ext.eh) << IXGBE_ADVTXD_MACLEN_SHIFT);
+   *vlan_macip_lens |= (ethlen << IXGBE_ADVTXD_MACLEN_SHIFT);
 
if (ext.ip4) {
iphlen = ext.ip4->ip_hl << 2;
@@ -2500,6 +2509,8 @@ ixgbe_csum_offload(struct mbuf *mp, uint
*type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV6;
 #endif
} else {
+   if (mp->m_pkthdr.csum_flags & M_TCP_TSO)
+   tcpstat_inc(tcps_outbadtso);
return offload;
}
 
@@ -2519,6 +2530,32 @@ ixgbe_csum_offload(struct mbuf *mp, uint
}
}
 
+   if (mp->m_pkthdr.csum_flags & M_TCP_TSO) {
+   if (ext.tcp) {
+   uint32_t pktlen, hdrlen, thlen, outlen;
+
+   thlen = ext.tcp->th_off << 2;
+
+   *mss_l4len_idx |= (uint32_t)(mp->m_pkthdr.ph_mss
+   << IXGBE_ADVTXD_MSS_SHIFT);
+   *mss_l4len_idx |= thlen << IXGBE_ADVTXD_L4LEN_SHIFT;
+
+   hdrlen = ethlen + iphlen + thlen;
+   pktlen = mp->m_pkthdr.len - hdrlen;
+   CLR(*olinfo_status, IXGBE_ADVTXD_PAYLEN_MASK
+   << IXGBE_ADVTXD_PAYLEN_SHIFT);
+   *olinfo_status |= pktlen << IXGBE_ADVTXD_PAYLEN_SHIFT;
+
+   *cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
+   offload = 1;
+
+   outlen = hdrlen + mp->m_pkthdr.ph_mss;
+   tcpstat_add(tcps_outpkttso,
+   (pktlen + outlen - 1) / outlen);
+   } else
+   tcpstat_inc(tcps_outbadtso);
+   }
+
return offload;
 }
 
@@ -2529,6 +2566,7 @@ ixgbe_tx_ctx_setup(struct tx_ring *txr, 

ix hardware tso

2023-05-12 Thread Alexander Bluhm
Hi,

I merged jan@'s ix(4) TSO diff with my software TSO diff.  It seems
to work.

# netstat -s -p tcp | grep TSO
1 output TSO packet software chopped
1824861 output TSO packets hardware processed
31668597 output TSO packets generated
83 output TSO packets dropped

Do not set ifconfig ix tso, this flag does not work correctly.
Hardware TSO is enabled if the hardware interface supports it.  To
disable TSO globally, use sysctl net.inet.tcp.tso=0.

I have tested it with this interface types.
ix0 at pci3 dev 0 function 0 "Intel 82598AF" rev 0x01, msix, 4 queues, address 
00:1b:21:0d:db:8f
ix1 at pci4 dev 0 function 0 "Intel 82599" rev 0x01, msix, 4 queues, address 
00:1b:21:c5:19:50
ix5 at pci13 dev 0 function 0 "Intel 82599" rev 0x01, msix, 4 queues, address 
90:e2:ba:d6:28:ac

Feel free to try other ix interfaces.  pf route-to should work, but
I have not tested it.

I have not yet investigated where the dropped counter 83 comes from.
If you see that also, please report what you did.

bluhm

Index: dev/pci/if_ix.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/dev/pci/if_ix.c,v
retrieving revision 1.193
diff -u -p -r1.193 if_ix.c
--- dev/pci/if_ix.c 28 Apr 2023 10:18:57 -  1.193
+++ dev/pci/if_ix.c 12 May 2023 22:43:04 -
@@ -1924,8 +1924,9 @@ ixgbe_setup_interface(struct ix_softc *s
ifp->if_capabilities |= IFCAP_CSUM_TCPv6 | IFCAP_CSUM_UDPv6;
ifp->if_capabilities |= IFCAP_CSUM_IPv4;
 
+   ifp->if_capabilities |= IFCAP_TSOv4 | IFCAP_TSOv6;
if (sc->hw.mac.type != ixgbe_mac_82598EB)
-   ifp->if_capabilities |= IFCAP_TSO;
+   ifp->if_capabilities |= IFCAP_LRO;
 
/*
 * Specify the media types supported by this sc and register
@@ -2344,6 +2345,7 @@ ixgbe_initialize_transmit_units(struct i
int  i;
uint64_t tdba;
uint32_t txctrl;
+   uint32_t hlreg;
 
/* Setup the Base and Length of the Tx Descriptor Ring */
 
@@ -2405,6 +2407,11 @@ ixgbe_initialize_transmit_units(struct i
rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
}
+
+   /* Enable TCP/UDP padding when using TSO */
+   hlreg = IXGBE_READ_REG(hw, IXGBE_HLREG0);
+   hlreg |= IXGBE_HLREG0_TXPADEN;
+   IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg);
 }
 
 /*
@@ -2473,16 +2480,18 @@ ixgbe_free_transmit_buffers(struct tx_ri
  **/
 
 static inline int
-ixgbe_csum_offload(struct mbuf *mp, uint32_t *vlan_macip_lens,
-uint32_t *type_tucmd_mlhl, uint32_t *olinfo_status)
+ixgbe_tx_offload(struct mbuf *mp, uint32_t *vlan_macip_lens,
+uint32_t *type_tucmd_mlhl, uint32_t *olinfo_status, uint32_t *cmd_type_len,
+uint32_t *mss_l4len_idx)
 {
struct ether_extracted ext;
int offload = 0;
-   uint32_t iphlen;
+   uint32_t ethlen, iphlen;
 
ether_extract_headers(mp, );
+   ethlen = sizeof(*ext.eh);
 
-   *vlan_macip_lens |= (sizeof(*ext.eh) << IXGBE_ADVTXD_MACLEN_SHIFT);
+   *vlan_macip_lens |= (ethlen << IXGBE_ADVTXD_MACLEN_SHIFT);
 
if (ext.ip4) {
iphlen = ext.ip4->ip_hl << 2;
@@ -2500,6 +2509,8 @@ ixgbe_csum_offload(struct mbuf *mp, uint
*type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV6;
 #endif
} else {
+   if (mp->m_pkthdr.csum_flags & M_TCP_TSO)
+   tcpstat_inc(tcps_outbadtso);
return offload;
}
 
@@ -2519,6 +2530,32 @@ ixgbe_csum_offload(struct mbuf *mp, uint
}
}
 
+   if (mp->m_pkthdr.csum_flags & M_TCP_TSO) {
+   if (ext.tcp) {
+   uint32_t pktlen, hdrlen, thlen, outlen;
+
+   thlen = ext.tcp->th_off << 2;
+
+   *mss_l4len_idx |= (uint32_t)(mp->m_pkthdr.ph_mss
+   << IXGBE_ADVTXD_MSS_SHIFT);
+   *mss_l4len_idx |= thlen << IXGBE_ADVTXD_L4LEN_SHIFT;
+
+   hdrlen = ethlen + iphlen + thlen;
+   pktlen = mp->m_pkthdr.len - hdrlen;
+   CLR(*olinfo_status, IXGBE_ADVTXD_PAYLEN_MASK
+   << IXGBE_ADVTXD_PAYLEN_SHIFT);
+   *olinfo_status |= pktlen << IXGBE_ADVTXD_PAYLEN_SHIFT;
+
+   *cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
+   offload = 1;
+
+   outlen = hdrlen + mp->m_pkthdr.ph_mss;
+   tcpstat_add(tcps_outpkttso,
+   (pktlen + outlen - 1) / outlen);
+   } else
+   tcpstat_inc(tcps_outbadtso);
+   }
+
return offload;
 }
 
@@ -2529,6 +2566,7 @@