Skip to contentSkip to conversation

Support TCP/IPv4, VxLAN and GRE GSO in DPDK

PATCH Superseded Jiayu Hu 7 participants 157 messages Aug 24, 2017 – Oct 8, 2017 Library code Page 3 of 3

lore
Share & tools
lore
#123 lore raw

v9 cover Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

In reply to Mark Kavanagh

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. This patch adds GSO support to DPDK for specific packet types: specifically, TCP/IPv4, VxLAN, and GRE.

The first patch introduces the GSO API framework. The second patch adds GSO support for TCP/IPv4 packets (containing an optional VLAN tag). The third patch adds GSO support for VxLAN packets that contain outer IPv4, and inner TCP/IPv4 headers (plus optional inner and/or outer VLAN tags). The fourth patch adds GSO support for GRE packets that contain outer IPv4, and inner TCP/IPv4 headers (with optional outer VLAN tag). The fifth patch in the series enables TCP/IPv4, VxLAN, and GRE GSO in testpmd's checksum forwarding engine. The final patch in the series adds GSO documentation to the programmer's guide.

Performance Testing
===================
The performance of TCP/IPv4 GSO on a 10Gbps link is demonstrated using iperf. Setup for the test is described as follows:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine with "retry".
c. Select IP and TCP HW checksum calculation for P0; select TCP HW
checksum calculation for vhost-user port.
d. Launch a VM with csum and tso offloading enabled.
e. Run iperf-client on virtio-net port in the VM to send TCP packets.
With enabling csum and tso, the VM can send large TCP/IPv4 packets (mss is up to 64KB).
f. P1 is assigned to linux kernel and enabled kernel GRO. Run
iperf-server on P1.

We conduct three iperf tests:

test-1: enable GSO for P0 in testpmd, and set max GSO segment length
to 1518B. Run two iperf-client in the VM.
test-2: enable TSO for P0 in testpmd, and set TSO segsz to 1518B. Run
two iperf-client in the VM.
test-3: disable GSO and TSO in testpmd. Run two iperf-client in the VM.

Throughput of the above three tests:

test-1: 9.4Gbps
test-2: 9.5Gbps
test-3: 3Mbps

Functional Testing
==================
Unlike TCP packets, VMs can't send large VxLAN or GRE packets. The max length of tunneled packets from VMs is 1514B. So current experiment method can't be used to measure VxLAN and GRE GSO performance, but simply test the functionality via setting small GSO segment length (e.g. 500B).

VxLAN
-----
To test VxLAN GSO functionality, we use the following setup:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum forwarding
engine with "retry".
c. Testpmd commands:
- csum parse_tunnel on "P0"
- csum parse_tunnel on "vhost-user port"
- csum set outer-ip hw "P0"
- csum set ip hw "P0"
- csum set tcp hw "P0"
- csum set tcp hw "vhost-user port"
- set port "P0" gso on
- set gso segsz 500
d. Launch a VM with csum and tso offloading enabled.
e. Create a vxlan port for the virtio-net port in the VM. Run iperf-client
on the VxLAN port, so TCP packets are VxLAN encapsulated. However, the max packet length is 1514B.
f. P1 is assigned to linux kernel and kernel GRO is disabled. Similarly,
create a VxLAN port for P1, and run iperf-server on the VxLAN port.

In testpmd, we can see the length of all packets sent from P0 is smaller than or equal to 500B. Additionally, the packets arriving in P1 is encapsulated and is smaller than or equal to 500B.

GRE
---
The same process may be used to test GRE functionality, with the exception that the tunnel type created for both the guest's virtio-net, and the host's kernel interfaces is GRE:
ip tunnel add <gre tunnel> mode gre remote <remote IP> local <local_ip>

As in the VxLAN testcase, the length of packets sent from P0, and received on P1, is less than 500B.

Change log
==========
v9:
- fix testpmd build for i686 target
- change log level from WARNING to DEBUG in the case of unsupported packet (rte_gso_segment())

v8:
- resolve coding style infractions (indentation).
- centralize invalid parameter checking for rte_gso_segment() into a single 'if' statement.
- don't clear PKT_TX_TCP_SEG flag for packets that don't qualify for GSO on account of invalid params.
- allow GSO for tunneled packets only via gso_ctx (by correcting 'if' statement condition).

v7:
- add RTE_GSO_SEG_SIZE_MIN macro; use this to validate gso_ctx.gso_segsz.
- rename 'ipid_flag' member of gso_ctx to 'flag'.
- remove mention of VLAN tags in supported packet types.
- don't clear PKT_TX_TCP_SEG flag if GSO fails.
- take all packet overhead into account when checking for empty packet.
- ensure that only enabled GSO types are enacted upon (i.e. no fall-through to TCP/IPv4 case from tunneled case).
- validate user-supplied gso segsz arg against RTE_GSO_SEG_SIZE_MIN in testpmd.
- simplify error-checking/handling for GSO failure case in testpmd csum engine.
- use 0 instead of !RTE_GSO_IPID_FIXED in testpmd.

v6:
- rebase to HEAD of master (i5dce9fcA)
- remove 'l3_offset' parameter from 'update_ipv4_tcp_headers'

v5:
- add GSO section to the programmer's guide.
- use MF or (previously 'and') offset to check if a packet is IP fragmented.
- move 'update_header' helper functions to gso_common.h.
- move txp/ipv4 'update_header' function to gso_tcp4.c.
- move tunnel 'update_header' function to gso_tunnel_tcp4.c.
- add offset parameter to 'update_header' functions.
- combine GRE and VxLAN tunnel header update functions into a single function.
- correct typos and errors in comments/commit messages.

v4:
- use ol_flags instead of packet_type to decide which segmentation function to use.
- use MF and offset to check if a packet is IP fragmented, instead of using DF.
- remove ETHER_CRC_LEN from gso segment payload length calculation.
- refactor internal header update and other functions.
- remove RTE_GSO_IPID_INCREASE.
- add some of GSO documents.
- set the default GSO length to 1514 and fill PKT_TX_TCP_SEG for the packets sent from GSO-enabled ports in testpmd.
v3:
- support all IPv4 header flags, including RTE_PTYPE_(INNER_)L3_IPV4, RTE_PTYPE_(INNER_)L3_IPV4_EXT and RTE_PTYPE_(INNER_)L3_IPV4_EXT_ UNKNOWN.
- fill mbuf->packet_type instead of using rte_net_get_ptype() in csumonly.c, since rte_net_get_ptype() doesn't support vxlan.
- store the input packet into pkts_out inside gso_tcp4_segment() and gso_tunnel_tcp4_segment() instead of rte_gso_segment(), when no GSO is performed.
- add missing incldues.
- optimize file names, function names and function description.
- fix one bug in testpmd.
v2:
- merge data segments whose data_len is less than mss into a large data segment in gso_do_segment().
- use mbuf->packet_type/l2_len/l3_len etc. instead of parsing the packet header in rte_gso_segment().
- provide IP id macros for applications to select fixed or incremental IP ids.

Jiayu Hu (3):
gso: add Generic Segmentation Offload API framework
gso: add TCP/IPv4 GSO support
app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Mark Kavanagh (3):
gso: add VxLAN GSO support
gso: add GRE GSO support
doc: add GSO programmer's guide

 MAINTAINERS                                        |   6 +
 app/test-pmd/cmdline.c                             | 179 ++++++++
 app/test-pmd/config.c                              |  24 ++
 app/test-pmd/csumonly.c                            |  42 +-
 app/test-pmd/testpmd.c                             |  13 +
 app/test-pmd/testpmd.h                             |  10 +
 config/common_base                                 |   5 +
 doc/api/doxy-api-index.md                          |   1 +
 doc/api/doxy-api.conf                              |   1 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477 +++++++++++++++++++++
 doc/guides/prog_guide/index.rst                    |   1 +
 doc/guides/rel_notes/release_17_11.rst             |  17 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst        |  46 ++
 lib/Makefile                                       |   2 +
 lib/librte_eal/common/include/rte_log.h            |   1 +
 lib/librte_gso/Makefile                            |  52 +++
 lib/librte_gso/gso_common.c                        | 153 +++++++
 lib/librte_gso/gso_common.h                        | 171 ++++++++
 lib/librte_gso/gso_tcp4.c                          | 104 +++++
 lib/librte_gso/gso_tcp4.h                          |  74 ++++
 lib/librte_gso/gso_tunnel_tcp4.c                   | 126 ++++++
 lib/librte_gso/gso_tunnel_tcp4.h                   |  75 ++++
 lib/librte_gso/rte_gso.c                           | 110 +++++
 lib/librte_gso/rte_gso.h                           | 148 +++++++
 lib/librte_gso/rte_gso_version.map                 |   7 +
 mk/rte.app.mk                                      |   1 +
 28 files changed, 2411 insertions(+), 4 deletions(-)
 create mode 100644 doc/guides/prog_guide/generic_segmentation_offload_lib.rst
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
Signature · 1 line
1.9.3
#124 lore raw

Re: [PATCH v9 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

Quoted 234 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Thursday, October 5, 2017 9:37 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Ananyev, Konstantin <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B <[email protected]>
Subject: [PATCH v9 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. This patch adds GSO support to DPDK for specific packet types: specifically, TCP/IPv4, VxLAN, and GRE.

The first patch introduces the GSO API framework. The second patch adds GSO support for TCP/IPv4 packets (containing an optional VLAN tag). The third patch adds GSO support for VxLAN packets that contain outer IPv4, and inner TCP/IPv4 headers (plus optional inner and/or outer VLAN tags). The fourth patch adds GSO support for GRE packets that contain outer IPv4, and inner TCP/IPv4 headers (with optional outer VLAN tag). The fifth patch in the series enables TCP/IPv4, VxLAN, and GRE GSO in testpmd's checksum forwarding engine. The final patch in the series adds GSO documentation to the programmer's guide.

Performance Testing
===================
The performance of TCP/IPv4 GSO on a 10Gbps link is demonstrated using iperf. Setup for the test is described as follows:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine with "retry".
c. Select IP and TCP HW checksum calculation for P0; select TCP HW
checksum calculation for vhost-user port.
d. Launch a VM with csum and tso offloading enabled.
e. Run iperf-client on virtio-net port in the VM to send TCP packets.
With enabling csum and tso, the VM can send large TCP/IPv4 packets (mss is up to 64KB).
f. P1 is assigned to linux kernel and enabled kernel GRO. Run
iperf-server on P1.

We conduct three iperf tests:

test-1: enable GSO for P0 in testpmd, and set max GSO segment length
to 1518B. Run two iperf-client in the VM.
test-2: enable TSO for P0 in testpmd, and set TSO segsz to 1518B. Run
two iperf-client in the VM.
test-3: disable GSO and TSO in testpmd. Run two iperf-client in the VM.

Throughput of the above three tests:

test-1: 9.4Gbps
test-2: 9.5Gbps
test-3: 3Mbps

Functional Testing
==================
Unlike TCP packets, VMs can't send large VxLAN or GRE packets. The max length of tunneled packets from VMs is 1514B. So current experiment method can't be used to measure VxLAN and GRE GSO performance, but simply test the functionality via setting small GSO segment length (e.g. 500B).

VxLAN
-----
To test VxLAN GSO functionality, we use the following setup:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum forwarding
engine with "retry".
c. Testpmd commands:
- csum parse_tunnel on "P0"
- csum parse_tunnel on "vhost-user port"
- csum set outer-ip hw "P0"
- csum set ip hw "P0"
- csum set tcp hw "P0"
- csum set tcp hw "vhost-user port"
- set port "P0" gso on
- set gso segsz 500
d. Launch a VM with csum and tso offloading enabled.
e. Create a vxlan port for the virtio-net port in the VM. Run iperf-client
on the VxLAN port, so TCP packets are VxLAN encapsulated. However, the max packet length is 1514B.
f. P1 is assigned to linux kernel and kernel GRO is disabled. Similarly,
create a VxLAN port for P1, and run iperf-server on the VxLAN port.

In testpmd, we can see the length of all packets sent from P0 is smaller than or equal to 500B. Additionally, the packets arriving in P1 is encapsulated and is smaller than or equal to 500B.

GRE
---
The same process may be used to test GRE functionality, with the exception that the tunnel type created for both the guest's virtio-net, and the host's kernel interfaces is GRE:
ip tunnel add <gre tunnel> mode gre remote <remote IP> local <local_ip>

As in the VxLAN testcase, the length of packets sent from P0, and received on P1, is less than 500B.

Change log
==========
v9:
- fix testpmd build for i686 target
- change log level from WARNING to DEBUG in the case of unsupported packet (rte_gso_segment())

v8:
- resolve coding style infractions (indentation).
- centralize invalid parameter checking for rte_gso_segment() into a single 'if' statement.
- don't clear PKT_TX_TCP_SEG flag for packets that don't qualify for GSO on account of invalid params.
- allow GSO for tunneled packets only via gso_ctx (by correcting 'if' statement condition).

v7:
- add RTE_GSO_SEG_SIZE_MIN macro; use this to validate gso_ctx.gso_segsz.
- rename 'ipid_flag' member of gso_ctx to 'flag'.
- remove mention of VLAN tags in supported packet types.
- don't clear PKT_TX_TCP_SEG flag if GSO fails.
- take all packet overhead into account when checking for empty packet.
- ensure that only enabled GSO types are enacted upon (i.e. no fall-through to TCP/IPv4 case from tunneled case).
- validate user-supplied gso segsz arg against RTE_GSO_SEG_SIZE_MIN in testpmd.
- simplify error-checking/handling for GSO failure case in testpmd csum engine.
- use 0 instead of !RTE_GSO_IPID_FIXED in testpmd.

v6:
- rebase to HEAD of master (i5dce9fcA)
- remove 'l3_offset' parameter from 'update_ipv4_tcp_headers'

v5:
- add GSO section to the programmer's guide.
- use MF or (previously 'and') offset to check if a packet is IP fragmented.
- move 'update_header' helper functions to gso_common.h.
- move txp/ipv4 'update_header' function to gso_tcp4.c.
- move tunnel 'update_header' function to gso_tunnel_tcp4.c.
- add offset parameter to 'update_header' functions.
- combine GRE and VxLAN tunnel header update functions into a single function.
- correct typos and errors in comments/commit messages.

v4:
- use ol_flags instead of packet_type to decide which segmentation function to use.
- use MF and offset to check if a packet is IP fragmented, instead of using DF.
- remove ETHER_CRC_LEN from gso segment payload length calculation.
- refactor internal header update and other functions.
- remove RTE_GSO_IPID_INCREASE.
- add some of GSO documents.
- set the default GSO length to 1514 and fill PKT_TX_TCP_SEG for the packets sent from GSO-enabled ports in testpmd.
v3:
- support all IPv4 header flags, including RTE_PTYPE_(INNER_)L3_IPV4, RTE_PTYPE_(INNER_)L3_IPV4_EXT and RTE_PTYPE_(INNER_)L3_IPV4_EXT_ UNKNOWN.
- fill mbuf->packet_type instead of using rte_net_get_ptype() in csumonly.c, since rte_net_get_ptype() doesn't support vxlan.
- store the input packet into pkts_out inside gso_tcp4_segment() and gso_tunnel_tcp4_segment() instead of rte_gso_segment(), when no GSO is performed.
- add missing incldues.
- optimize file names, function names and function description.
- fix one bug in testpmd.
v2:
- merge data segments whose data_len is less than mss into a large data segment in gso_do_segment().
- use mbuf->packet_type/l2_len/l3_len etc. instead of parsing the packet header in rte_gso_segment().
- provide IP id macros for applications to select fixed or incremental IP ids.

Jiayu Hu (3):
gso: add Generic Segmentation Offload API framework
gso: add TCP/IPv4 GSO support
app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Mark Kavanagh (3):
gso: add VxLAN GSO support
gso: add GRE GSO support
doc: add GSO programmer's guide

 MAINTAINERS                                        |   6 +
 app/test-pmd/cmdline.c                             | 179 ++++++++
 app/test-pmd/config.c                              |  24 ++
 app/test-pmd/csumonly.c                            |  42 +-
 app/test-pmd/testpmd.c                             |  13 +
 app/test-pmd/testpmd.h                             |  10 +
 config/common_base                                 |   5 +
 doc/api/doxy-api-index.md                          |   1 +
 doc/api/doxy-api.conf                              |   1 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477 +++++++++++++++++++++
 doc/guides/prog_guide/index.rst                    |   1 +
 doc/guides/rel_notes/release_17_11.rst             |  17 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst        |  46 ++
 lib/Makefile                                       |   2 +
 lib/librte_eal/common/include/rte_log.h            |   1 +
 lib/librte_gso/Makefile                            |  52 +++
 lib/librte_gso/gso_common.c                        | 153 +++++++
 lib/librte_gso/gso_common.h                        | 171 ++++++++
 lib/librte_gso/gso_tcp4.c                          | 104 +++++
 lib/librte_gso/gso_tcp4.h                          |  74 ++++
 lib/librte_gso/gso_tunnel_tcp4.c                   | 126 ++++++
 lib/librte_gso/gso_tunnel_tcp4.h                   |  75 ++++
 lib/librte_gso/rte_gso.c                           | 110 +++++
 lib/librte_gso/rte_gso.h                           | 148 +++++++
 lib/librte_gso/rte_gso_version.map                 |   7 +
 mk/rte.app.mk                                      |   1 +
 28 files changed, 2411 insertions(+), 4 deletions(-)
 create mode 100644 doc/guides/prog_guide/generic_segmentation_offload_lib.rst
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
Quoted 1 line

--

Quoted 1 line

1.9.3

#125 lore raw

v9 cover Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

FYI - GSO series has been acked, so it will be included in DPDK v17.11 release. -Mark

Quoted 257 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, October 5, 2017 11:24 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v9 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

Quoted 5 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Thursday, October 5, 2017 9:37 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>;

Ananyev, Konstantin <[email protected]>; Yigit,

Quoted 1 line

Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B

<[email protected]>

Quoted 84 lines

Subject: [PATCH v9 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. This patch adds GSO support to DPDK for specific packet types: specifically, TCP/IPv4, VxLAN, and GRE.

The first patch introduces the GSO API framework. The second patch adds GSO support for TCP/IPv4 packets (containing an optional VLAN tag). The third patch adds GSO support for VxLAN packets that contain outer IPv4, and inner TCP/IPv4 headers (plus optional inner and/or outer VLAN tags). The fourth patch adds GSO support for GRE packets that contain outer IPv4, and inner TCP/IPv4 headers (with optional outer VLAN tag). The fifth patch in the series enables TCP/IPv4, VxLAN, and GRE GSO in testpmd's checksum forwarding engine. The final patch in the series adds GSO documentation to the programmer's guide.

Performance Testing
===================
The performance of TCP/IPv4 GSO on a 10Gbps link is demonstrated using iperf. Setup for the test is described as follows:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine with "retry".
c. Select IP and TCP HW checksum calculation for P0; select TCP HW
checksum calculation for vhost-user port.
d. Launch a VM with csum and tso offloading enabled.
e. Run iperf-client on virtio-net port in the VM to send TCP packets.
With enabling csum and tso, the VM can send large TCP/IPv4 packets (mss is up to 64KB).
f. P1 is assigned to linux kernel and enabled kernel GRO. Run
iperf-server on P1.

We conduct three iperf tests:

test-1: enable GSO for P0 in testpmd, and set max GSO segment length
to 1518B. Run two iperf-client in the VM.
test-2: enable TSO for P0 in testpmd, and set TSO segsz to 1518B. Run
two iperf-client in the VM.
test-3: disable GSO and TSO in testpmd. Run two iperf-client in the VM.

Throughput of the above three tests:

test-1: 9.4Gbps
test-2: 9.5Gbps
test-3: 3Mbps

Functional Testing
==================
Unlike TCP packets, VMs can't send large VxLAN or GRE packets. The max length of tunneled packets from VMs is 1514B. So current experiment method can't be used to measure VxLAN and GRE GSO performance, but simply test the functionality via setting small GSO segment length (e.g. 500B).

VxLAN
-----
To test VxLAN GSO functionality, we use the following setup:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum forwarding
engine with "retry".
c. Testpmd commands:
- csum parse_tunnel on "P0"
- csum parse_tunnel on "vhost-user port"
- csum set outer-ip hw "P0"
- csum set ip hw "P0"
- csum set tcp hw "P0"
- csum set tcp hw "vhost-user port"
- set port "P0" gso on
- set gso segsz 500
d. Launch a VM with csum and tso offloading enabled.
e. Create a vxlan port for the virtio-net port in the VM. Run iperf-client
on the VxLAN port, so TCP packets are VxLAN encapsulated. However, the max packet length is 1514B.
f. P1 is assigned to linux kernel and kernel GRO is disabled. Similarly,
create a VxLAN port for P1, and run iperf-server on the VxLAN port.

Quoted 7 lines

In testpmd, we can see the length of all packets sent from P0 is smaller than or equal to 500B. Additionally, the packets arriving in P1 is encapsulated and is smaller than or equal to 500B.

GRE
---
The same process may be used to test GRE functionality, with the exception

that

Quoted 1 line

the tunnel type created for both the guest's virtio-net, and the host's

kernel

Quoted 4 lines

interfaces is GRE:
ip tunnel add <gre tunnel> mode gre remote <remote IP> local <local_ip>

As in the VxLAN testcase, the length of packets sent from P0, and received

on

Quoted 18 lines

P1, is less than 500B.

Change log
==========
v9:
- fix testpmd build for i686 target
- change log level from WARNING to DEBUG in the case of unsupported packet (rte_gso_segment())

v8:
- resolve coding style infractions (indentation).
- centralize invalid parameter checking for rte_gso_segment() into a single 'if' statement.
- don't clear PKT_TX_TCP_SEG flag for packets that don't qualify for GSO on account of invalid params.
- allow GSO for tunneled packets only via gso_ctx (by correcting 'if' statement condition).

Quoted 7 lines

v7:
- add RTE_GSO_SEG_SIZE_MIN macro; use this to validate gso_ctx.gso_segsz.
- rename 'ipid_flag' member of gso_ctx to 'flag'.
- remove mention of VLAN tags in supported packet types.
- don't clear PKT_TX_TCP_SEG flag if GSO fails.
- take all packet overhead into account when checking for empty packet.
- ensure that only enabled GSO types are enacted upon (i.e. no fall-through

to

Quoted 2 lines

TCP/IPv4 case from tunneled case).
- validate user-supplied gso segsz arg against RTE_GSO_SEG_SIZE_MIN in

testpmd.

Quoted 1 line

- simplify error-checking/handling for GSO failure case in testpmd csum

engine.

Quoted 59 lines

- use 0 instead of !RTE_GSO_IPID_FIXED in testpmd.

v6:
- rebase to HEAD of master (i5dce9fcA)
- remove 'l3_offset' parameter from 'update_ipv4_tcp_headers'

v5:
- add GSO section to the programmer's guide.
- use MF or (previously 'and') offset to check if a packet is IP fragmented.
- move 'update_header' helper functions to gso_common.h.
- move txp/ipv4 'update_header' function to gso_tcp4.c.
- move tunnel 'update_header' function to gso_tunnel_tcp4.c.
- add offset parameter to 'update_header' functions.
- combine GRE and VxLAN tunnel header update functions into a single function.
- correct typos and errors in comments/commit messages.

v4:
- use ol_flags instead of packet_type to decide which segmentation function to use.
- use MF and offset to check if a packet is IP fragmented, instead of using DF.
- remove ETHER_CRC_LEN from gso segment payload length calculation.
- refactor internal header update and other functions.
- remove RTE_GSO_IPID_INCREASE.
- add some of GSO documents.
- set the default GSO length to 1514 and fill PKT_TX_TCP_SEG for the packets sent from GSO-enabled ports in testpmd.
v3:
- support all IPv4 header flags, including RTE_PTYPE_(INNER_)L3_IPV4, RTE_PTYPE_(INNER_)L3_IPV4_EXT and RTE_PTYPE_(INNER_)L3_IPV4_EXT_ UNKNOWN.
- fill mbuf->packet_type instead of using rte_net_get_ptype() in csumonly.c, since rte_net_get_ptype() doesn't support vxlan.
- store the input packet into pkts_out inside gso_tcp4_segment() and gso_tunnel_tcp4_segment() instead of rte_gso_segment(), when no GSO is performed.
- add missing incldues.
- optimize file names, function names and function description.
- fix one bug in testpmd.
v2:
- merge data segments whose data_len is less than mss into a large data segment in gso_do_segment().
- use mbuf->packet_type/l2_len/l3_len etc. instead of parsing the packet header in rte_gso_segment().
- provide IP id macros for applications to select fixed or incremental IP ids.

Jiayu Hu (3):
gso: add Generic Segmentation Offload API framework
gso: add TCP/IPv4 GSO support
app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Mark Kavanagh (3):
gso: add VxLAN GSO support
gso: add GRE GSO support
doc: add GSO programmer's guide

Quoted 12 lines
 MAINTAINERS                                        |   6 +
 app/test-pmd/cmdline.c                             | 179 ++++++++
 app/test-pmd/config.c                              |  24 ++
 app/test-pmd/csumonly.c                            |  42 +-
 app/test-pmd/testpmd.c                             |  13 +
 app/test-pmd/testpmd.h                             |  10 +
 config/common_base                                 |   5 +
 doc/api/doxy-api-index.md                          |   1 +
 doc/api/doxy-api.conf                              |   1 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477

+++++++++++++++++++++

Quoted 10 lines
 doc/guides/prog_guide/index.rst                    |   1 +
 doc/guides/rel_notes/release_17_11.rst             |  17 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst        |  46 ++
 lib/Makefile                                       |   2 +
 lib/librte_eal/common/include/rte_log.h            |   1 +
 lib/librte_gso/Makefile                            |  52 +++
 lib/librte_gso/gso_common.c                        | 153 +++++++
 lib/librte_gso/gso_common.h                        | 171 ++++++++
 lib/librte_gso/gso_tcp4.c                          | 104 +++++
 lib/librte_gso/gso_tcp4.h                          |  74 ++++
Quoted 8 lines
 lib/librte_gso/gso_tunnel_tcp4.c                   | 126 ++++++
 lib/librte_gso/gso_tunnel_tcp4.h                   |  75 ++++
 lib/librte_gso/rte_gso.c                           | 110 +++++
 lib/librte_gso/rte_gso.h                           | 148 +++++++
 lib/librte_gso/rte_gso_version.map                 |   7 +
 mk/rte.app.mk                                      |   1 +
 28 files changed, 2411 insertions(+), 4 deletions(-)
 create mode 100644

doc/guides/prog_guide/generic_segmentation_offload_lib.rst

Quoted 13 lines
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
Quoted 1 line

--

Quoted 1 line

1.9.3

#126 lore raw

Re: [PATCH v9 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

In reply to Ananyev, Konstantin
Quoted 254 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, October 5, 2017 11:24 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v9 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

Quoted 5 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Thursday, October 5, 2017 9:37 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>;

Ananyev, Konstantin <[email protected]>; Yigit,

Quoted 1 line

Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B

<[email protected]>

Quoted 84 lines

Subject: [PATCH v9 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. This patch adds GSO support to DPDK for specific packet types: specifically, TCP/IPv4, VxLAN, and GRE.

The first patch introduces the GSO API framework. The second patch adds GSO support for TCP/IPv4 packets (containing an optional VLAN tag). The third patch adds GSO support for VxLAN packets that contain outer IPv4, and inner TCP/IPv4 headers (plus optional inner and/or outer VLAN tags). The fourth patch adds GSO support for GRE packets that contain outer IPv4, and inner TCP/IPv4 headers (with optional outer VLAN tag). The fifth patch in the series enables TCP/IPv4, VxLAN, and GRE GSO in testpmd's checksum forwarding engine. The final patch in the series adds GSO documentation to the programmer's guide.

Performance Testing
===================
The performance of TCP/IPv4 GSO on a 10Gbps link is demonstrated using iperf. Setup for the test is described as follows:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine with "retry".
c. Select IP and TCP HW checksum calculation for P0; select TCP HW
checksum calculation for vhost-user port.
d. Launch a VM with csum and tso offloading enabled.
e. Run iperf-client on virtio-net port in the VM to send TCP packets.
With enabling csum and tso, the VM can send large TCP/IPv4 packets (mss is up to 64KB).
f. P1 is assigned to linux kernel and enabled kernel GRO. Run
iperf-server on P1.

We conduct three iperf tests:

test-1: enable GSO for P0 in testpmd, and set max GSO segment length
to 1518B. Run two iperf-client in the VM.
test-2: enable TSO for P0 in testpmd, and set TSO segsz to 1518B. Run
two iperf-client in the VM.
test-3: disable GSO and TSO in testpmd. Run two iperf-client in the VM.

Throughput of the above three tests:

test-1: 9.4Gbps
test-2: 9.5Gbps
test-3: 3Mbps

Functional Testing
==================
Unlike TCP packets, VMs can't send large VxLAN or GRE packets. The max length of tunneled packets from VMs is 1514B. So current experiment method can't be used to measure VxLAN and GRE GSO performance, but simply test the functionality via setting small GSO segment length (e.g. 500B).

VxLAN
-----
To test VxLAN GSO functionality, we use the following setup:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum forwarding
engine with "retry".
c. Testpmd commands:
- csum parse_tunnel on "P0"
- csum parse_tunnel on "vhost-user port"
- csum set outer-ip hw "P0"
- csum set ip hw "P0"
- csum set tcp hw "P0"
- csum set tcp hw "vhost-user port"
- set port "P0" gso on
- set gso segsz 500
d. Launch a VM with csum and tso offloading enabled.
e. Create a vxlan port for the virtio-net port in the VM. Run iperf-client
on the VxLAN port, so TCP packets are VxLAN encapsulated. However, the max packet length is 1514B.
f. P1 is assigned to linux kernel and kernel GRO is disabled. Similarly,
create a VxLAN port for P1, and run iperf-server on the VxLAN port.

Quoted 7 lines

In testpmd, we can see the length of all packets sent from P0 is smaller than or equal to 500B. Additionally, the packets arriving in P1 is encapsulated and is smaller than or equal to 500B.

GRE
---
The same process may be used to test GRE functionality, with the exception

that

Quoted 1 line

the tunnel type created for both the guest's virtio-net, and the host's

kernel

Quoted 4 lines

interfaces is GRE:
ip tunnel add <gre tunnel> mode gre remote <remote IP> local <local_ip>

As in the VxLAN testcase, the length of packets sent from P0, and received

on

Quoted 18 lines

P1, is less than 500B.

Change log
==========
v9:
- fix testpmd build for i686 target
- change log level from WARNING to DEBUG in the case of unsupported packet (rte_gso_segment())

v8:
- resolve coding style infractions (indentation).
- centralize invalid parameter checking for rte_gso_segment() into a single 'if' statement.
- don't clear PKT_TX_TCP_SEG flag for packets that don't qualify for GSO on account of invalid params.
- allow GSO for tunneled packets only via gso_ctx (by correcting 'if' statement condition).

Quoted 7 lines

v7:
- add RTE_GSO_SEG_SIZE_MIN macro; use this to validate gso_ctx.gso_segsz.
- rename 'ipid_flag' member of gso_ctx to 'flag'.
- remove mention of VLAN tags in supported packet types.
- don't clear PKT_TX_TCP_SEG flag if GSO fails.
- take all packet overhead into account when checking for empty packet.
- ensure that only enabled GSO types are enacted upon (i.e. no fall-through

to

Quoted 2 lines

TCP/IPv4 case from tunneled case).
- validate user-supplied gso segsz arg against RTE_GSO_SEG_SIZE_MIN in

testpmd.

Quoted 1 line

- simplify error-checking/handling for GSO failure case in testpmd csum

engine.

Quoted 59 lines

- use 0 instead of !RTE_GSO_IPID_FIXED in testpmd.

v6:
- rebase to HEAD of master (i5dce9fcA)
- remove 'l3_offset' parameter from 'update_ipv4_tcp_headers'

v5:
- add GSO section to the programmer's guide.
- use MF or (previously 'and') offset to check if a packet is IP fragmented.
- move 'update_header' helper functions to gso_common.h.
- move txp/ipv4 'update_header' function to gso_tcp4.c.
- move tunnel 'update_header' function to gso_tunnel_tcp4.c.
- add offset parameter to 'update_header' functions.
- combine GRE and VxLAN tunnel header update functions into a single function.
- correct typos and errors in comments/commit messages.

v4:
- use ol_flags instead of packet_type to decide which segmentation function to use.
- use MF and offset to check if a packet is IP fragmented, instead of using DF.
- remove ETHER_CRC_LEN from gso segment payload length calculation.
- refactor internal header update and other functions.
- remove RTE_GSO_IPID_INCREASE.
- add some of GSO documents.
- set the default GSO length to 1514 and fill PKT_TX_TCP_SEG for the packets sent from GSO-enabled ports in testpmd.
v3:
- support all IPv4 header flags, including RTE_PTYPE_(INNER_)L3_IPV4, RTE_PTYPE_(INNER_)L3_IPV4_EXT and RTE_PTYPE_(INNER_)L3_IPV4_EXT_ UNKNOWN.
- fill mbuf->packet_type instead of using rte_net_get_ptype() in csumonly.c, since rte_net_get_ptype() doesn't support vxlan.
- store the input packet into pkts_out inside gso_tcp4_segment() and gso_tunnel_tcp4_segment() instead of rte_gso_segment(), when no GSO is performed.
- add missing incldues.
- optimize file names, function names and function description.
- fix one bug in testpmd.
v2:
- merge data segments whose data_len is less than mss into a large data segment in gso_do_segment().
- use mbuf->packet_type/l2_len/l3_len etc. instead of parsing the packet header in rte_gso_segment().
- provide IP id macros for applications to select fixed or incremental IP ids.

Jiayu Hu (3):
gso: add Generic Segmentation Offload API framework
gso: add TCP/IPv4 GSO support
app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Mark Kavanagh (3):
gso: add VxLAN GSO support
gso: add GRE GSO support
doc: add GSO programmer's guide

Quoted 12 lines
 MAINTAINERS                                        |   6 +
 app/test-pmd/cmdline.c                             | 179 ++++++++
 app/test-pmd/config.c                              |  24 ++
 app/test-pmd/csumonly.c                            |  42 +-
 app/test-pmd/testpmd.c                             |  13 +
 app/test-pmd/testpmd.h                             |  10 +
 config/common_base                                 |   5 +
 doc/api/doxy-api-index.md                          |   1 +
 doc/api/doxy-api.conf                              |   1 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477

+++++++++++++++++++++

Quoted 10 lines
 doc/guides/prog_guide/index.rst                    |   1 +
 doc/guides/rel_notes/release_17_11.rst             |  17 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst        |  46 ++
 lib/Makefile                                       |   2 +
 lib/librte_eal/common/include/rte_log.h            |   1 +
 lib/librte_gso/Makefile                            |  52 +++
 lib/librte_gso/gso_common.c                        | 153 +++++++
 lib/librte_gso/gso_common.h                        | 171 ++++++++
 lib/librte_gso/gso_tcp4.c                          | 104 +++++
 lib/librte_gso/gso_tcp4.h                          |  74 ++++
Quoted 8 lines
 lib/librte_gso/gso_tunnel_tcp4.c                   | 126 ++++++
 lib/librte_gso/gso_tunnel_tcp4.h                   |  75 ++++
 lib/librte_gso/rte_gso.c                           | 110 +++++
 lib/librte_gso/rte_gso.h                           | 148 +++++++
 lib/librte_gso/rte_gso_version.map                 |   7 +
 mk/rte.app.mk                                      |   1 +
 28 files changed, 2411 insertions(+), 4 deletions(-)
 create mode 100644

doc/guides/prog_guide/generic_segmentation_offload_lib.rst

Quoted 13 lines
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
Quoted 3 lines
Quoted 1 line

--

Many thanks once again for your review comments and help Konstantin! -Mark

Quoted 2 lines
Quoted 2 lines

1.9.3

#127 lore raw

Re: [PATCH v9 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

In reply to Mark Kavanagh
Quoted 176 lines · Mark Kavanagh

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. This patch adds GSO support to DPDK for specific packet types: specifically, TCP/IPv4, VxLAN, and GRE.

The first patch introduces the GSO API framework. The second patch adds GSO support for TCP/IPv4 packets (containing an optional VLAN tag). The third patch adds GSO support for VxLAN packets that contain outer IPv4, and inner TCP/IPv4 headers (plus optional inner and/or outer VLAN tags). The fourth patch adds GSO support for GRE packets that contain outer IPv4, and inner TCP/IPv4 headers (with optional outer VLAN tag). The fifth patch in the series enables TCP/IPv4, VxLAN, and GRE GSO in testpmd's checksum forwarding engine. The final patch in the series adds GSO documentation to the programmer's guide.

Performance Testing
===================
The performance of TCP/IPv4 GSO on a 10Gbps link is demonstrated using iperf. Setup for the test is described as follows:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine with "retry".
c. Select IP and TCP HW checksum calculation for P0; select TCP HW
checksum calculation for vhost-user port.
d. Launch a VM with csum and tso offloading enabled.
e. Run iperf-client on virtio-net port in the VM to send TCP packets.
With enabling csum and tso, the VM can send large TCP/IPv4 packets (mss is up to 64KB).
f. P1 is assigned to linux kernel and enabled kernel GRO. Run
iperf-server on P1.

We conduct three iperf tests:

test-1: enable GSO for P0 in testpmd, and set max GSO segment length
to 1518B. Run two iperf-client in the VM.
test-2: enable TSO for P0 in testpmd, and set TSO segsz to 1518B. Run
two iperf-client in the VM.
test-3: disable GSO and TSO in testpmd. Run two iperf-client in the VM.

Throughput of the above three tests:

test-1: 9.4Gbps
test-2: 9.5Gbps
test-3: 3Mbps

Functional Testing
==================
Unlike TCP packets, VMs can't send large VxLAN or GRE packets. The max length of tunneled packets from VMs is 1514B. So current experiment method can't be used to measure VxLAN and GRE GSO performance, but simply test the functionality via setting small GSO segment length (e.g. 500B).

VxLAN
-----
To test VxLAN GSO functionality, we use the following setup:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum forwarding
engine with "retry".
c. Testpmd commands:
- csum parse_tunnel on "P0"
- csum parse_tunnel on "vhost-user port"
- csum set outer-ip hw "P0"
- csum set ip hw "P0"
- csum set tcp hw "P0"
- csum set tcp hw "vhost-user port"
- set port "P0" gso on
- set gso segsz 500
d. Launch a VM with csum and tso offloading enabled.
e. Create a vxlan port for the virtio-net port in the VM. Run iperf-client
on the VxLAN port, so TCP packets are VxLAN encapsulated. However, the max packet length is 1514B.
f. P1 is assigned to linux kernel and kernel GRO is disabled. Similarly,
create a VxLAN port for P1, and run iperf-server on the VxLAN port.

In testpmd, we can see the length of all packets sent from P0 is smaller than or equal to 500B. Additionally, the packets arriving in P1 is encapsulated and is smaller than or equal to 500B.

GRE
---
The same process may be used to test GRE functionality, with the exception that the tunnel type created for both the guest's virtio-net, and the host's kernel interfaces is GRE:
ip tunnel add <gre tunnel> mode gre remote <remote IP> local <local_ip>

As in the VxLAN testcase, the length of packets sent from P0, and received on P1, is less than 500B.

Change log
==========
v9:
- fix testpmd build for i686 target
- change log level from WARNING to DEBUG in the case of unsupported packet (rte_gso_segment())

v8:
- resolve coding style infractions (indentation).
- centralize invalid parameter checking for rte_gso_segment() into a single 'if' statement.
- don't clear PKT_TX_TCP_SEG flag for packets that don't qualify for GSO on account of invalid params.
- allow GSO for tunneled packets only via gso_ctx (by correcting 'if' statement condition).

v7:
- add RTE_GSO_SEG_SIZE_MIN macro; use this to validate gso_ctx.gso_segsz.
- rename 'ipid_flag' member of gso_ctx to 'flag'.
- remove mention of VLAN tags in supported packet types.
- don't clear PKT_TX_TCP_SEG flag if GSO fails.
- take all packet overhead into account when checking for empty packet.
- ensure that only enabled GSO types are enacted upon (i.e. no fall-through to TCP/IPv4 case from tunneled case).
- validate user-supplied gso segsz arg against RTE_GSO_SEG_SIZE_MIN in testpmd.
- simplify error-checking/handling for GSO failure case in testpmd csum engine.
- use 0 instead of !RTE_GSO_IPID_FIXED in testpmd.

v6:
- rebase to HEAD of master (i5dce9fcA)
- remove 'l3_offset' parameter from 'update_ipv4_tcp_headers'

v5:
- add GSO section to the programmer's guide.
- use MF or (previously 'and') offset to check if a packet is IP fragmented.
- move 'update_header' helper functions to gso_common.h.
- move txp/ipv4 'update_header' function to gso_tcp4.c.
- move tunnel 'update_header' function to gso_tunnel_tcp4.c.
- add offset parameter to 'update_header' functions.
- combine GRE and VxLAN tunnel header update functions into a single function.
- correct typos and errors in comments/commit messages.

v4:
- use ol_flags instead of packet_type to decide which segmentation function to use.
- use MF and offset to check if a packet is IP fragmented, instead of using DF.
- remove ETHER_CRC_LEN from gso segment payload length calculation.
- refactor internal header update and other functions.
- remove RTE_GSO_IPID_INCREASE.
- add some of GSO documents.
- set the default GSO length to 1514 and fill PKT_TX_TCP_SEG for the packets sent from GSO-enabled ports in testpmd.
v3:
- support all IPv4 header flags, including RTE_PTYPE_(INNER_)L3_IPV4, RTE_PTYPE_(INNER_)L3_IPV4_EXT and RTE_PTYPE_(INNER_)L3_IPV4_EXT_ UNKNOWN.
- fill mbuf->packet_type instead of using rte_net_get_ptype() in csumonly.c, since rte_net_get_ptype() doesn't support vxlan.
- store the input packet into pkts_out inside gso_tcp4_segment() and gso_tunnel_tcp4_segment() instead of rte_gso_segment(), when no GSO is performed.
- add missing incldues.
- optimize file names, function names and function description.
- fix one bug in testpmd.
v2:
- merge data segments whose data_len is less than mss into a large data segment in gso_do_segment().
- use mbuf->packet_type/l2_len/l3_len etc. instead of parsing the packet header in rte_gso_segment().
- provide IP id macros for applications to select fixed or incremental IP ids.

Jiayu Hu (3):
gso: add Generic Segmentation Offload API framework
gso: add TCP/IPv4 GSO support
app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Quoted 4 lines

Mark Kavanagh (3):
gso: add VxLAN GSO support
gso: add GRE GSO support
doc: add GSO programmer's guide

Hi Mark, Jiayu,

I was about the get this to next-net, but recognized same problem with gro patch. There are uint8_t storage type usage for port_id. Port id is now 16bits. And for testpmd you can prefer "portid_t" storage type as well.

Another thing is this patch and GRO patch conflicts, because both touches same parts. Since Jiayu is the author of the gro patch, is it possible to define order between these two patches and it doesn't conflict while applying. Order doesn't matter as long as dependency defined in cover letter of the patch.

Can you please send a new version with above two items addressed?

Thanks,
ferruh

#128 lore raw

Re: [PATCH v9 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

Quoted 188 lines · Ferruh Yigit
Quoted 176 lines · Mark Kavanagh

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. This patch adds GSO support to DPDK for specific packet types: specifically, TCP/IPv4, VxLAN, and GRE.

The first patch introduces the GSO API framework. The second patch adds GSO support for TCP/IPv4 packets (containing an optional VLAN tag). The third patch adds GSO support for VxLAN packets that contain outer IPv4, and inner TCP/IPv4 headers (plus optional inner and/or outer VLAN tags). The fourth patch adds GSO support for GRE packets that contain outer IPv4, and inner TCP/IPv4 headers (with optional outer VLAN tag). The fifth patch in the series enables TCP/IPv4, VxLAN, and GRE GSO in testpmd's checksum forwarding engine. The final patch in the series adds GSO documentation to the programmer's guide.

Performance Testing
===================
The performance of TCP/IPv4 GSO on a 10Gbps link is demonstrated using iperf. Setup for the test is described as follows:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine with "retry".
c. Select IP and TCP HW checksum calculation for P0; select TCP HW
checksum calculation for vhost-user port.
d. Launch a VM with csum and tso offloading enabled.
e. Run iperf-client on virtio-net port in the VM to send TCP packets.
With enabling csum and tso, the VM can send large TCP/IPv4 packets (mss is up to 64KB).
f. P1 is assigned to linux kernel and enabled kernel GRO. Run
iperf-server on P1.

We conduct three iperf tests:

test-1: enable GSO for P0 in testpmd, and set max GSO segment length
to 1518B. Run two iperf-client in the VM.
test-2: enable TSO for P0 in testpmd, and set TSO segsz to 1518B. Run
two iperf-client in the VM.
test-3: disable GSO and TSO in testpmd. Run two iperf-client in the VM.

Throughput of the above three tests:

test-1: 9.4Gbps
test-2: 9.5Gbps
test-3: 3Mbps

Functional Testing
==================
Unlike TCP packets, VMs can't send large VxLAN or GRE packets. The max length of tunneled packets from VMs is 1514B. So current experiment method can't be used to measure VxLAN and GRE GSO performance, but simply test the functionality via setting small GSO segment length (e.g. 500B).

VxLAN
-----
To test VxLAN GSO functionality, we use the following setup:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum forwarding
engine with "retry".
c. Testpmd commands:
- csum parse_tunnel on "P0"
- csum parse_tunnel on "vhost-user port"
- csum set outer-ip hw "P0"
- csum set ip hw "P0"
- csum set tcp hw "P0"
- csum set tcp hw "vhost-user port"
- set port "P0" gso on
- set gso segsz 500
d. Launch a VM with csum and tso offloading enabled.
e. Create a vxlan port for the virtio-net port in the VM. Run iperf-client
on the VxLAN port, so TCP packets are VxLAN encapsulated. However, the max packet length is 1514B.
f. P1 is assigned to linux kernel and kernel GRO is disabled. Similarly,
create a VxLAN port for P1, and run iperf-server on the VxLAN port.

In testpmd, we can see the length of all packets sent from P0 is smaller than or equal to 500B. Additionally, the packets arriving in P1 is encapsulated and is smaller than or equal to 500B.

GRE
---
The same process may be used to test GRE functionality, with the exception that the tunnel type created for both the guest's virtio-net, and the host's kernel interfaces is GRE:
ip tunnel add <gre tunnel> mode gre remote <remote IP> local <local_ip>

As in the VxLAN testcase, the length of packets sent from P0, and received on P1, is less than 500B.

Change log
==========
v9:
- fix testpmd build for i686 target
- change log level from WARNING to DEBUG in the case of unsupported packet (rte_gso_segment())

v8:
- resolve coding style infractions (indentation).
- centralize invalid parameter checking for rte_gso_segment() into a single 'if' statement.
- don't clear PKT_TX_TCP_SEG flag for packets that don't qualify for GSO on account of invalid params.
- allow GSO for tunneled packets only via gso_ctx (by correcting 'if' statement condition).

v7:
- add RTE_GSO_SEG_SIZE_MIN macro; use this to validate gso_ctx.gso_segsz.
- rename 'ipid_flag' member of gso_ctx to 'flag'.
- remove mention of VLAN tags in supported packet types.
- don't clear PKT_TX_TCP_SEG flag if GSO fails.
- take all packet overhead into account when checking for empty packet.
- ensure that only enabled GSO types are enacted upon (i.e. no fall-through to TCP/IPv4 case from tunneled case).
- validate user-supplied gso segsz arg against RTE_GSO_SEG_SIZE_MIN in testpmd.
- simplify error-checking/handling for GSO failure case in testpmd csum engine.
- use 0 instead of !RTE_GSO_IPID_FIXED in testpmd.

v6:
- rebase to HEAD of master (i5dce9fcA)
- remove 'l3_offset' parameter from 'update_ipv4_tcp_headers'

v5:
- add GSO section to the programmer's guide.
- use MF or (previously 'and') offset to check if a packet is IP fragmented.
- move 'update_header' helper functions to gso_common.h.
- move txp/ipv4 'update_header' function to gso_tcp4.c.
- move tunnel 'update_header' function to gso_tunnel_tcp4.c.
- add offset parameter to 'update_header' functions.
- combine GRE and VxLAN tunnel header update functions into a single function.
- correct typos and errors in comments/commit messages.

v4:
- use ol_flags instead of packet_type to decide which segmentation function to use.
- use MF and offset to check if a packet is IP fragmented, instead of using DF.
- remove ETHER_CRC_LEN from gso segment payload length calculation.
- refactor internal header update and other functions.
- remove RTE_GSO_IPID_INCREASE.
- add some of GSO documents.
- set the default GSO length to 1514 and fill PKT_TX_TCP_SEG for the packets sent from GSO-enabled ports in testpmd.
v3:
- support all IPv4 header flags, including RTE_PTYPE_(INNER_)L3_IPV4, RTE_PTYPE_(INNER_)L3_IPV4_EXT and RTE_PTYPE_(INNER_)L3_IPV4_EXT_ UNKNOWN.
- fill mbuf->packet_type instead of using rte_net_get_ptype() in csumonly.c, since rte_net_get_ptype() doesn't support vxlan.
- store the input packet into pkts_out inside gso_tcp4_segment() and gso_tunnel_tcp4_segment() instead of rte_gso_segment(), when no GSO is performed.
- add missing incldues.
- optimize file names, function names and function description.
- fix one bug in testpmd.
v2:
- merge data segments whose data_len is less than mss into a large data segment in gso_do_segment().
- use mbuf->packet_type/l2_len/l3_len etc. instead of parsing the packet header in rte_gso_segment().
- provide IP id macros for applications to select fixed or incremental IP ids.

Jiayu Hu (3):
gso: add Generic Segmentation Offload API framework
gso: add TCP/IPv4 GSO support
app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Quoted 4 lines

Mark Kavanagh (3):
gso: add VxLAN GSO support
gso: add GRE GSO support
doc: add GSO programmer's guide

Hi Mark, Jiayu,

I was about the get this to next-net, but recognized same problem with gro patch. There are uint8_t storage type usage for port_id. Port id is now 16bits. And for testpmd you can prefer "portid_t" storage type as well.

Quoted 7 lines

Another thing is this patch and GRO patch conflicts, because both touches same parts. Since Jiayu is the author of the gro patch, is it possible to define order between these two patches and it doesn't conflict while applying. Order doesn't matter as long as dependency defined in cover letter of the patch.

Can you please send a new version with above two items addressed?

btw, please keep Konstantin's and others Acks in next version of the patches.

Quoted 4 lines

Thanks,
ferruh

author
#129 lore raw

v10 cover Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

In reply to Mark Kavanagh

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. This patch adds GSO support to DPDK for specific packet types: specifically, TCP/IPv4, VxLAN, and GRE.

The first patch introduces the GSO API framework. The second patch adds GSO support for TCP/IPv4 packets (containing an optional VLAN tag). The third patch adds GSO support for VxLAN packets that contain outer IPv4, and inner TCP/IPv4 headers (plus optional inner and/or outer VLAN tags). The fourth patch adds GSO support for GRE packets that contain outer IPv4, and inner TCP/IPv4 headers (with optional outer VLAN tag). The fifth patch in the series enables TCP/IPv4, VxLAN, and GRE GSO in testpmd's checksum forwarding engine. The final patch in the series adds GSO documentation to the programmer's guide.

Note that this patch set has dependency on the patch "app/testpmd: enable the heavyweight mode TCP/IPv4 GRO".
http://dpdk.org/dev/patchwork/patch/29867/

Performance Testing
===================
The performance of TCP/IPv4 GSO on a 10Gbps link is demonstrated using iperf. Setup for the test is described as follows:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine with "retry".
c. Select IP and TCP HW checksum calculation for P0; select TCP HW
checksum calculation for vhost-user port.
d. Launch a VM with csum and tso offloading enabled.
e. Run iperf-client on virtio-net port in the VM to send TCP packets.
With enabling csum and tso, the VM can send large TCP/IPv4 packets (mss is up to 64KB).
f. P1 is assigned to linux kernel and enabled kernel GRO. Run
iperf-server on P1.

We conduct three iperf tests:

test-1: enable GSO for P0 in testpmd, and set max GSO segment length
to 1514B. Run four iperf-client in the VM.
test-2: enable TSO for P0 in testpmd, and set TSO segsz to 1514B. Run
four iperf-client in the VM.
test-3: disable GSO and TSO in testpmd. Run two iperf-client in the VM.

Throughput of the above three tests:

test-1: 9Gbps
test-2: 9.5Gbps
test-3: 3Mbps

Functional Testing
==================
Unlike TCP packets, VMs can't send large VxLAN or GRE packets. The max length of tunneled packets from VMs is 1514B. So current experiment method can't be used to measure VxLAN and GRE GSO performance, but simply test the functionality via setting small GSO segment length (e.g. 500B).

VxLAN
-----
To test VxLAN GSO functionality, we use the following setup:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum forwarding
engine with "retry".
c. Testpmd commands:
- csum parse_tunnel on "P0"
- csum parse_tunnel on "vhost-user port"
- csum set outer-ip hw "P0"
- csum set ip hw "P0"
- csum set tcp hw "P0"
- csum set tcp hw "vhost-user port"
- set port "P0" gso on
- set gso segsz 500
d. Launch a VM with csum and tso offloading enabled.
e. Create a vxlan port for the virtio-net port in the VM. Run iperf-client
on the VxLAN port, so TCP packets are VxLAN encapsulated. However, the max packet length is 1514B.
f. P1 is assigned to linux kernel and kernel GRO is disabled. Similarly,
create a VxLAN port for P1, and run iperf-server on the VxLAN port.

In testpmd, we can see the length of all packets sent from P0 is smaller than or equal to 500B. Additionally, the packets arriving in P1 is encapsulated and is smaller than or equal to 500B.

GRE
---
The same process may be used to test GRE functionality, with the exception that the tunnel type created for both the guest's virtio-net, and the host's kernel interfaces is GRE:
ip tunnel add <gre tunnel> mode gre remote <remote IP> local <local_ip>

As in the VxLAN testcase, the length of packets sent from P0, and received on P1, is less than 500B.

Change log
==========
v10:
- fix portid type conflict (uint8_t -> uint16_t) in testpmd.
- correct the RTE_GSO_FLAG_IPID_FIXED description: use 0 rather than !RTE_GSO_FLAG_IPID_FIXED to indicate using incremental IP ids.
- rebase the GSO codes upon the patch "app/testpmd: enable the heavyweight mode TCP/IPv4 GRO" to fix the conflict issue in testpmd.

v9:
- fix testpmd build for i686 target
- change log level from WARNING to DEBUG in the case of unsupported packet (rte_gso_segment())

v8:
- resolve coding style infractions (indentation).
- centralize invalid parameter checking for rte_gso_segment() into a single 'if' statement.
- don't clear PKT_TX_TCP_SEG flag for packets that don't qualify for GSO on account of invalid params.
- allow GSO for tunneled packets only via gso_ctx (by correcting 'if' statement condition).

v7:
- add RTE_GSO_SEG_SIZE_MIN macro; use this to validate gso_ctx.gso_segsz.
- rename 'ipid_flag' member of gso_ctx to 'flag'.
- remove mention of VLAN tags in supported packet types.
- don't clear PKT_TX_TCP_SEG flag if GSO fails.
- take all packet overhead into account when checking for empty packet.
- ensure that only enabled GSO types are enacted upon (i.e. no fall-through to TCP/IPv4 case from tunneled case).
- validate user-supplied gso segsz arg against RTE_GSO_SEG_SIZE_MIN in testpmd.
- simplify error-checking/handling for GSO failure case in testpmd csum engine.
- use 0 instead of !RTE_GSO_IPID_FIXED in testpmd.

v6:
- rebase to HEAD of master (i5dce9fcA)
- remove 'l3_offset' parameter from 'update_ipv4_tcp_headers'

v5:
- add GSO section to the programmer's guide.
- use MF or (previously 'and') offset to check if a packet is IP fragmented.
- move 'update_header' helper functions to gso_common.h.
- move txp/ipv4 'update_header' function to gso_tcp4.c.
- move tunnel 'update_header' function to gso_tunnel_tcp4.c.
- add offset parameter to 'update_header' functions.
- combine GRE and VxLAN tunnel header update functions into a single function.
- correct typos and errors in comments/commit messages.

v4:
- use ol_flags instead of packet_type to decide which segmentation function to use.
- use MF and offset to check if a packet is IP fragmented, instead of using DF.
- remove ETHER_CRC_LEN from gso segment payload length calculation.
- refactor internal header update and other functions.
- remove RTE_GSO_IPID_INCREASE.
- add some of GSO documents.
- set the default GSO length to 1514 and fill PKT_TX_TCP_SEG for the packets sent from GSO-enabled ports in testpmd.
v3:
- support all IPv4 header flags, including RTE_PTYPE_(INNER_)L3_IPV4, RTE_PTYPE_(INNER_)L3_IPV4_EXT and RTE_PTYPE_(INNER_)L3_IPV4_EXT_ UNKNOWN.
- fill mbuf->packet_type instead of using rte_net_get_ptype() in csumonly.c, since rte_net_get_ptype() doesn't support vxlan.
- store the input packet into pkts_out inside gso_tcp4_segment() and gso_tunnel_tcp4_segment() instead of rte_gso_segment(), when no GSO is performed.
- add missing incldues.
- optimize file names, function names and function description.
- fix one bug in testpmd.
v2:
- merge data segments whose data_len is less than mss into a large data segment in gso_do_segment().
- use mbuf->packet_type/l2_len/l3_len etc. instead of parsing the packet header in rte_gso_segment().
- provide IP id macros for applications to select fixed or incremental IP ids.

Jiayu Hu (3):
gso: add Generic Segmentation Offload API framework
gso: add TCP/IPv4 GSO support
app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Mark Kavanagh (3):
gso: add VxLAN GSO support
gso: add GRE GSO support
doc: add GSO programmer's guide

 MAINTAINERS                                        |   6 +
 app/test-pmd/cmdline.c                             | 180 ++++++++
 app/test-pmd/config.c                              |  24 ++
 app/test-pmd/csumonly.c                            |  43 +-
 app/test-pmd/testpmd.c                             |  13 +
 app/test-pmd/testpmd.h                             |  10 +
 config/common_base                                 |   5 +
 doc/api/doxy-api-index.md                          |   1 +
 doc/api/doxy-api.conf                              |   1 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477 +++++++++++++++++++++
 doc/guides/prog_guide/index.rst                    |   1 +
 doc/guides/rel_notes/release_17_11.rst             |  17 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst        |  46 ++
 lib/Makefile                                       |   2 +
 lib/librte_eal/common/include/rte_log.h            |   1 +
 lib/librte_gso/Makefile                            |  52 +++
 lib/librte_gso/gso_common.c                        | 153 +++++++
 lib/librte_gso/gso_common.h                        | 171 ++++++++
 lib/librte_gso/gso_tcp4.c                          | 102 +++++
 lib/librte_gso/gso_tcp4.h                          |  74 ++++
 lib/librte_gso/gso_tunnel_tcp4.c                   | 126 ++++++
 lib/librte_gso/gso_tunnel_tcp4.h                   |  75 ++++
 lib/librte_gso/rte_gso.c                           | 110 +++++
 lib/librte_gso/rte_gso.h                           | 148 +++++++
 lib/librte_gso/rte_gso_version.map                 |   7 +
 mk/rte.app.mk                                      |   1 +
 28 files changed, 2411 insertions(+), 4 deletions(-)
 create mode 100644 doc/guides/prog_guide/generic_segmentation_offload_lib.rst
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
Signature · 1 line
2.7.4
author
#130 lore raw

PATCH v10 1/6 gso: add Generic Segmentation Offload API framework

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. To segment a packet requires two steps. The first is to set proper flags to mbuf->ol_flags, where the flags are the same as that of TSO. The second is to call the segmentation API, rte_gso_segment(). This patch introduces the GSO API framework to DPDK.

rte_gso_segment() splits an input packet into small ones in each invocation. The GSO library refers to these small packets generated by rte_gso_segment() as GSO segments. Each of the newly-created GSO segments is organized as a two-segment MBUF, where the first segment is a standard MBUF, which stores a copy of packet header, and the second is an indirect MBUF which points to a section of data in the input packet. rte_gso_segment() reduces the refcnt of the input packet by 1. Therefore, when all GSO segments are freed, the input packet is freed automatically. Additionally, since each GSO segment has multiple MBUFs (i.e. 2 MBUFs), the driver of the interface which the GSO segments are sent to should support to transmit multi-segment packets.

The GSO framework clears the PKT_TX_TCP_SEG flag for both the input packet, and all produced GSO segments in the event of success, since segmentation in hardware is no longer required at that point.

---
 config/common_base                     |   5 ++
 doc/api/doxy-api-index.md              |   1 +
 doc/api/doxy-api.conf                  |   1 +
 doc/guides/rel_notes/release_17_11.rst |   1 +
 lib/Makefile                           |   2 +
 lib/librte_gso/Makefile                |  49 +++++++++++
 lib/librte_gso/rte_gso.c               |  52 ++++++++++++
 lib/librte_gso/rte_gso.h               | 143 +++++++++++++++++++++++++++++++++
 lib/librte_gso/rte_gso_version.map     |   7 ++
 mk/rte.app.mk                          |   1 +
 10 files changed, 262 insertions(+)
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
config/common_base +5 -0
index ca47615..65c5e75 100644
@@ -655,6 +655,11 @@ CONFIG_RTE_LIBRTE_IP_FRAG_TBL_STAT=n
 CONFIG_RTE_LIBRTE_GRO=y
 
 #
+# Compile GSO library
+#
+CONFIG_RTE_LIBRTE_GSO=y
+
+#
 # Compile librte_meter
 #
 CONFIG_RTE_LIBRTE_METER=y
doc/api/doxy-api-index.md +1 -0
index 19e0d4f..6512918 100644
@@ -101,6 +101,7 @@ The public API headers are grouped by topics:
   [TCP]                (@ref rte_tcp.h),
   [UDP]                (@ref rte_udp.h),
   [GRO]                (@ref rte_gro.h),
+  [GSO]                (@ref rte_gso.h),
   [frag/reass]         (@ref rte_ip_frag.h),
   [LPM IPv4 route]     (@ref rte_lpm.h),
   [LPM IPv6 route]     (@ref rte_lpm6.h),
doc/api/doxy-api.conf +1 -0
index 823554f..408f2e6 100644
@@ -47,6 +47,7 @@ INPUT                   = doc/api/doxy-api-index.md \
                           lib/librte_ether \
                           lib/librte_eventdev \
                           lib/librte_gro \
+                          lib/librte_gso \
                           lib/librte_hash \
                           lib/librte_ip_frag \
                           lib/librte_jobstats \
doc/guides/rel_notes/release_17_11.rst +1 -0
index 4f92912..d75fec2 100644
@@ -208,6 +208,7 @@ The libraries prepended with a plus sign were incremented in this version.
      librte_ethdev.so.8
      librte_eventdev.so.2
      librte_gro.so.1
+     librte_gso.so.1
      librte_hash.so.2
      librte_ip_frag.so.1
      librte_jobstats.so.1
lib/Makefile +2 -0
index 86caba1..3d123f4 100644
@@ -108,6 +108,8 @@ DIRS-$(CONFIG_RTE_LIBRTE_REORDER) += librte_reorder
 DEPDIRS-librte_reorder := librte_eal librte_mempool librte_mbuf
 DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += librte_pdump
 DEPDIRS-librte_pdump := librte_eal librte_mempool librte_mbuf librte_ether
+DIRS-$(CONFIG_RTE_LIBRTE_GSO) += librte_gso
+DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net
 
 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
 DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni
lib/librte_gso/Makefile new file +49 -0

49 lines not on this page · raw message

lib/librte_gso/rte_gso.c new file +52 -0

52 lines not on this page · raw message

lib/librte_gso/rte_gso.h new file +143 -0

143 lines not on this page · raw message

lib/librte_gso/rte_gso_version.map new file +7 -0
new file mode 100644
index 0000000..e1fd453
@@ -0,0 +1,7 @@
+DPDK_17.11 {
+	global:
+
+	rte_gso_segment;
+
+	local: *;
+};
mk/rte.app.mk +1 -0
index 29507dc..6df402c 100644
@@ -66,6 +66,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PDUMP)          += -lrte_pdump
 _LDLIBS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR)    += -lrte_distributor
 _LDLIBS-$(CONFIG_RTE_LIBRTE_IP_FRAG)        += -lrte_ip_frag
 _LDLIBS-$(CONFIG_RTE_LIBRTE_GRO)            += -lrte_gro
+_LDLIBS-$(CONFIG_RTE_LIBRTE_GSO)            += -lrte_gso
 _LDLIBS-$(CONFIG_RTE_LIBRTE_METER)          += -lrte_meter
 _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED)          += -lrte_sched
 _LDLIBS-$(CONFIG_RTE_LIBRTE_LPM)            += -lrte_lpm
Signature · 1 line
2.7.4
author
#131 lore raw

PATCH v10 2/6 gso: add TCP/IPv4 GSO support

In reply to Jiayu Hu

This patch adds GSO support for TCP/IPv4 packets. Supported packets may include a single VLAN tag. TCP/IPv4 GSO doesn't check if input packets have correct checksums, and doesn't update checksums for output packets (the responsibility for this lies with the application). Additionally, TCP/IPv4 GSO doesn't process IP fragmented packets.

TCP/IPv4 GSO uses two chained MBUFs, one direct MBUF and one indrect MBUF, to organize an output packet. Note that we refer to these two chained MBUFs as a two-segment MBUF. The direct MBUF stores the packet header, while the indirect mbuf simply points to a location within the original packet's payload. Consequently, use of the GSO library requires multi-segment MBUF support in the TX functions of the NIC driver.

If a packet is GSO'd, TCP/IPv4 GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst  |  12 +++
 lib/Makefile                            |   2 +-
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 153 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 141 +++++++++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.c               | 102 +++++++++++++++++++++
 lib/librte_gso/gso_tcp4.h               |  74 +++++++++++++++
 lib/librte_gso/rte_gso.c                |  53 ++++++++++-
 lib/librte_gso/rte_gso.h                |   7 +-
 10 files changed, 541 insertions(+), 6 deletions(-)
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
doc/guides/rel_notes/release_17_11.rst +12 -0
index d75fec2..8f4a1e0 100644
@@ -64,6 +64,18 @@ New Features
    * Support for Flow API
    * Support for Tx and Rx descriptor status functions
 
+* **Added the Generic Segmentation Offload Library.**
+
+  Added the Generic Segmentation Offload (GSO) library to enable
+  applications to split large packets (e.g. MTU is 64KB) into small
+  ones (e.g. MTU is 1500B). Supported packet types are:
+
+  * TCP/IPv4 packets.
+
+  The GSO library doesn't check if the input packets have correct
+  checksums, and doesn't update checksums for output packets.
+  Additionally, the GSO library doesn't process IP fragmented packets.
+
 
 Resolved Issues
 ---------------
lib/Makefile +1 -1
index 3d123f4..5ecd1b3 100644
@@ -109,7 +109,7 @@ DEPDIRS-librte_reorder := librte_eal librte_mempool librte_mbuf
 DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += librte_pdump
 DEPDIRS-librte_pdump := librte_eal librte_mempool librte_mbuf librte_ether
 DIRS-$(CONFIG_RTE_LIBRTE_GSO) += librte_gso
-DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net
+DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net librte_mempool
 
 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
 DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni
lib/librte_eal/common/include/rte_log.h +1 -0
index ec8dba7..2fa1199 100644
@@ -87,6 +87,7 @@ extern struct rte_logs rte_logs;
 #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
 #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
 #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
+#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
 
 /* these log types can be used in an application */
 #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
lib/librte_gso/Makefile +2 -0
index aeaacbc..2be64d1 100644
@@ -42,6 +42,8 @@ LIBABIVER := 1
 
 #source files
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c new file +153 -0

153 lines not on this page · raw message

lib/librte_gso/gso_common.h new file +141 -0

141 lines not on this page · raw message

lib/librte_gso/gso_tcp4.c new file +102 -0

102 lines not on this page · raw message

lib/librte_gso/gso_tcp4.h new file +74 -0

74 lines not on this page · raw message

lib/librte_gso/rte_gso.c +49 -4

68 lines not on this page · raw message

lib/librte_gso/rte_gso.h +6 -1
index 9d3b4fc..4b77176 100644
@@ -46,6 +46,10 @@ extern "C" {
 #include <stdint.h>
 #include <rte_mbuf.h>
 
+/* Minimum GSO segment size. */
+#define RTE_GSO_SEG_SIZE_MIN (sizeof(struct ether_hdr) + \
+		sizeof(struct ipv4_hdr) + sizeof(struct tcp_hdr) + 1)
+
 /* GSO flags for rte_gso_ctx. */
 #define RTE_GSO_FLAG_IPID_FIXED (1ULL << 0)
 /**< Use fixed IP ids for output GSO segments. Setting
@@ -81,7 +85,8 @@ struct rte_gso_ctx {
 	 */
 	uint16_t gso_size;
 	/**< maximum size of an output GSO segment, including packet
-	 * header and payload, measured in bytes.
+	 * header and payload, measured in bytes. Must exceed
+	 * RTE_GSO_SEG_SIZE_MIN.
 	 */
 };
 
Signature · 1 line
2.7.4
author
#132 lore raw

PATCH v10 3/6 gso: add VxLAN GSO support

In reply to Jiayu Hu

From: Mark Kavanagh <[email protected]>

This patch adds a framework that allows GSO on tunneled packets. Furthermore, it leverages that framework to provide GSO support for VxLAN-encapsulated packets.

Supported VxLAN packets must have an outer IPv4 header (prepended by an optional VLAN tag), and contain an inner TCP/IPv4 packet (with an optional inner VLAN tag).

VxLAN GSO doesn't check if input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with TCP/IPv4 GSO, VxLAN GSO uses a two-segment MBUF to organize each output packet, which mandates support for multi-segment mbufs in the TX functions of the NIC driver. Also, if a packet is GSOed, VxLAN GSO reduces its MBUF refcnt by 1. As a result, when all of its GSO'd segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst |   2 +
 lib/librte_gso/Makefile                |   1 +
 lib/librte_gso/gso_common.h            |  25 +++++++
 lib/librte_gso/gso_tunnel_tcp4.c       | 120 +++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_tunnel_tcp4.h       |  75 +++++++++++++++++++++
 lib/librte_gso/rte_gso.c               |  14 +++-
 6 files changed, 235 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
doc/guides/rel_notes/release_17_11.rst +2 -0
index 8f4a1e0..4c17207 100644
@@ -71,6 +71,8 @@ New Features
   ones (e.g. MTU is 1500B). Supported packet types are:
 
   * TCP/IPv4 packets.
+  * VxLAN packets, which must have an outer IPv4 header, and contain
+    an inner TCP/IPv4 packet.
 
   The GSO library doesn't check if the input packets have correct
   checksums, and doesn't update checksums for output packets.
lib/librte_gso/Makefile +1 -0
index 2be64d1..e6d41df 100644
@@ -44,6 +44,7 @@ LIBABIVER := 1
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tunnel_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.h +25 -0
index a8ad638..95d54e7 100644
@@ -39,6 +39,7 @@
 #include <rte_mbuf.h>
 #include <rte_ip.h>
 #include <rte_tcp.h>
+#include <rte_udp.h>
 
 #define IS_FRAGMENTED(frag_off) (((frag_off) & IPV4_HDR_OFFSET_MASK) != 0 \
 		|| ((frag_off) & IPV4_HDR_MF_FLAG) == IPV4_HDR_MF_FLAG)
@@ -49,6 +50,30 @@
 #define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
 		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
 
+#define IS_IPV4_VXLAN_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_VXLAN))
+
+/**
+ * Internal function which updates the UDP header of a packet, following
+ * segmentation. This is required to update the header's datagram length field.
+ *
+ * @param pkt
+ *  The packet containing the UDP header.
+ * @param udp_offset
+ *  The offset of the UDP header from the start of the packet.
+ */
+static inline void
+update_udp_header(struct rte_mbuf *pkt, uint16_t udp_offset)
+{
+	struct udp_hdr *udp_hdr;
+
+	udp_hdr = (struct udp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			udp_offset);
+	udp_hdr->dgram_len = rte_cpu_to_be_16(pkt->pkt_len - udp_offset);
+}
+
 /**
  * Internal function which updates the TCP header of a packet, following
  * segmentation. This is required to update the header's 'sent' sequence
lib/librte_gso/gso_tunnel_tcp4.c new file +120 -0

120 lines not on this page · raw message

lib/librte_gso/gso_tunnel_tcp4.h new file +75 -0

75 lines not on this page · raw message

lib/librte_gso/rte_gso.c +12 -2
index 822693f..0a3ef11 100644
@@ -39,6 +39,7 @@
 #include "rte_gso.h"
 #include "gso_common.h"
 #include "gso_tcp4.h"
+#include "gso_tunnel_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -56,7 +57,8 @@ rte_gso_segment(struct rte_mbuf *pkt,
 	if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
 			nb_pkts_out < 1 ||
 			gso_ctx->gso_size < RTE_GSO_SEG_SIZE_MIN ||
-			gso_ctx->gso_types != DEV_TX_OFFLOAD_TCP_TSO)
+			((gso_ctx->gso_types & (DEV_TX_OFFLOAD_TCP_TSO |
+			DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) == 0))
 		return -EINVAL;
 
 	if (gso_ctx->gso_size >= pkt->pkt_len) {
@@ -71,12 +73,20 @@ rte_gso_segment(struct rte_mbuf *pkt,
 	ipid_delta = (gso_ctx->flag != RTE_GSO_FLAG_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_TCP(pkt->ol_flags)) {
+	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)
+		&& (gso_ctx->gso_types & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else if (IS_IPV4_TCP(pkt->ol_flags) &&
+			(gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO)) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
 				pkts_out, nb_pkts_out);
 	} else {
+		/* unsupported packet, skip */
 		pkts_out[0] = pkt;
 		RTE_LOG(DEBUG, GSO, "Unsupported packet type\n");
 		return 1;
Signature · 1 line
2.7.4
author
#133 lore raw

PATCH v10 4/6 gso: add GRE GSO support

In reply to Jiayu Hu

From: Mark Kavanagh <[email protected]>

This patch adds GSO support for GRE-tunneled packets. Supported GRE packets must contain an outer IPv4 header, and inner TCP/IPv4 headers. They may also contain a single VLAN tag. GRE GSO doesn't check if all input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with VxLAN GSO, GRE GSO uses a two-segment MBUF to organize each output packet, which requires multi-segment mbuf support in the TX functions of the NIC driver. Also, if a packet is GSOed, GRE GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst |  2 ++
 lib/librte_gso/gso_common.h            |  5 +++++
 lib/librte_gso/gso_tunnel_tcp4.c       | 14 ++++++++++----
 lib/librte_gso/rte_gso.c               |  9 ++++++---
 4 files changed, 23 insertions(+), 7 deletions(-)
doc/guides/rel_notes/release_17_11.rst +2 -0
index 4c17207..6ab725f 100644
@@ -73,6 +73,8 @@ New Features
   * TCP/IPv4 packets.
   * VxLAN packets, which must have an outer IPv4 header, and contain
     an inner TCP/IPv4 packet.
+  * GRE packets, which must contain an outer IPv4 header, and inner
+    TCP/IPv4 headers.
 
   The GSO library doesn't check if the input packets have correct
   checksums, and doesn't update checksums for output packets.
lib/librte_gso/gso_common.h +5 -0
index 95d54e7..145ea49 100644
@@ -55,6 +55,11 @@
 		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
 		 PKT_TX_TUNNEL_VXLAN))
 
+#define IS_IPV4_GRE_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_GRE)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_GRE))
+
 /**
  * Internal function which updates the UDP header of a packet, following
  * segmentation. This is required to update the header's datagram length field.
lib/librte_gso/gso_tunnel_tcp4.c +10 -4
index 5e8c8e5..8d0cfd7 100644
@@ -42,11 +42,13 @@ update_tunnel_ipv4_tcp_headers(struct rte_mbuf *pkt, uint8_t ipid_delta,
 	struct tcp_hdr *tcp_hdr;
 	uint32_t sent_seq;
 	uint16_t outer_id, inner_id, tail_idx, i;
-	uint16_t outer_ipv4_offset, inner_ipv4_offset, udp_offset, tcp_offset;
+	uint16_t outer_ipv4_offset, inner_ipv4_offset;
+	uint16_t udp_gre_offset, tcp_offset;
+	uint8_t update_udp_hdr;
 
 	outer_ipv4_offset = pkt->outer_l2_len;
-	udp_offset = outer_ipv4_offset + pkt->outer_l3_len;
-	inner_ipv4_offset = udp_offset + pkt->l2_len;
+	udp_gre_offset = outer_ipv4_offset + pkt->outer_l3_len;
+	inner_ipv4_offset = udp_gre_offset + pkt->l2_len;
 	tcp_offset = inner_ipv4_offset + pkt->l3_len;
 
 	/* Outer IPv4 header. */
@@ -63,9 +65,13 @@ update_tunnel_ipv4_tcp_headers(struct rte_mbuf *pkt, uint8_t ipid_delta,
 	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
 	tail_idx = nb_segs - 1;
 
+	/* Only update UDP header for VxLAN packets. */
+	update_udp_hdr = (pkt->ol_flags & PKT_TX_TUNNEL_VXLAN) ? 1 : 0;
+
 	for (i = 0; i < nb_segs; i++) {
 		update_ipv4_header(segs[i], outer_ipv4_offset, outer_id);
-		update_udp_header(segs[i], udp_offset);
+		if (update_udp_hdr)
+			update_udp_header(segs[i], udp_gre_offset);
 		update_ipv4_header(segs[i], inner_ipv4_offset, inner_id);
 		update_tcp_header(segs[i], tcp_offset, sent_seq, i < tail_idx);
 		outer_id++;
lib/librte_gso/rte_gso.c +6 -3
index 0a3ef11..f86e654 100644
@@ -58,7 +58,8 @@ rte_gso_segment(struct rte_mbuf *pkt,
 			nb_pkts_out < 1 ||
 			gso_ctx->gso_size < RTE_GSO_SEG_SIZE_MIN ||
 			((gso_ctx->gso_types & (DEV_TX_OFFLOAD_TCP_TSO |
-			DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) == 0))
+			DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+			DEV_TX_OFFLOAD_GRE_TNL_TSO)) == 0))
 		return -EINVAL;
 
 	if (gso_ctx->gso_size >= pkt->pkt_len) {
@@ -73,8 +74,10 @@ rte_gso_segment(struct rte_mbuf *pkt,
 	ipid_delta = (gso_ctx->flag != RTE_GSO_FLAG_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)
-		&& (gso_ctx->gso_types & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) {
+	if ((IS_IPV4_VXLAN_TCP4(pkt->ol_flags) &&
+			(gso_ctx->gso_types & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) ||
+			((IS_IPV4_GRE_TCP4(pkt->ol_flags) &&
+			 (gso_ctx->gso_types & DEV_TX_OFFLOAD_GRE_TNL_TSO)))) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
Signature · 1 line
2.7.4
author
#134 lore raw

PATCH v10 5/6 app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

In reply to Jiayu Hu

This patch adds GSO support to the csum forwarding engine. Oversized packets transmitted over a GSO-enabled port will undergo segmentation (with the exception of packet-types unsupported by the GSO library). GSO support is disabled by default.

GSO support may be toggled on a per-port basis, using the command:

"set port <port_id> gso on|off"

The maximum packet length (including the packet header and payload) for GSO segments may be set with the command:

"set gso segsz <length>"

Show GSO configuration for a given port with the command:

"show port <port_id> gso"

---
 app/test-pmd/cmdline.c                      | 180 ++++++++++++++++++++++++++++
 app/test-pmd/config.c                       |  24 ++++
 app/test-pmd/csumonly.c                     |  43 ++++++-
 app/test-pmd/testpmd.c                      |  13 ++
 app/test-pmd/testpmd.h                      |  10 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  46 +++++++
 6 files changed, 312 insertions(+), 4 deletions(-)
app/test-pmd/cmdline.c +180 -0
index 516fc89..b2d5284 100644
@@ -438,6 +438,17 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"    Set the cycle to flush GROed packets from"
 			" reassembly tables.\n\n"
 
+			"set port (port_id) gso (on|off)"
+			"    Enable or disable Generic Segmentation Offload in"
+			" csum forwarding engine.\n\n"
+
+			"set gso segsz (length)\n"
+			"    Set max packet length for output GSO segments,"
+			" including packet header and payload.\n\n"
+
+			"show port (port_id) gso\n"
+			"    Show GSO configuration.\n\n"
+
 			"set fwd (%s)\n"
 			"    Set packet forwarding mode.\n\n"
 
@@ -4014,6 +4025,172 @@ cmdline_parse_inst_t cmd_gro_flush = {
 	},
 };
 
+/* *** ENABLE/DISABLE GSO *** */
+struct cmd_gso_enable_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_mode;
+	portid_t cmd_pid;
+};
+
+static void
+cmd_gso_enable_parsed(void *parsed_result,
+		__attribute__((unused)) struct cmdline *cl,
+		__attribute__((unused)) void *data)
+{
+	struct cmd_gso_enable_result *res;
+
+	res = parsed_result;
+	if (!strcmp(res->cmd_keyword, "gso"))
+		setup_gso(res->cmd_mode, res->cmd_pid);
+}
+
+cmdline_parse_token_string_t cmd_gso_enable_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_enable_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_enable_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_enable_mode =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_mode, "on#off");
+cmdline_parse_token_num_t cmd_gso_enable_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_pid, UINT16);
+
+cmdline_parse_inst_t cmd_gso_enable = {
+	.f = cmd_gso_enable_parsed,
+	.data = NULL,
+	.help_str = "set port <port_id> gso on|off",
+	.tokens = {
+		(void *)&cmd_gso_enable_set,
+		(void *)&cmd_gso_enable_port,
+		(void *)&cmd_gso_enable_pid,
+		(void *)&cmd_gso_enable_keyword,
+		(void *)&cmd_gso_enable_mode,
+		NULL,
+	},
+};
+
+/* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
+struct cmd_gso_size_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_segsz;
+	uint16_t cmd_size;
+};
+
+static void
+cmd_gso_size_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_size_result *res = parsed_result;
+
+	if (test_done == 0) {
+		printf("Before setting GSO segsz, please first"
+				" stop fowarding\n");
+		return;
+	}
+
+	if (!strcmp(res->cmd_keyword, "gso") &&
+			!strcmp(res->cmd_segsz, "segsz")) {
+		if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
+			printf("gso_size should be larger than %zu."
+					" Please input a legal value\n",
+					RTE_GSO_SEG_SIZE_MIN);
+		else
+			gso_max_segment_size = res->cmd_size;
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_size_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_size_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_size_segsz =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_segsz, "segsz");
+cmdline_parse_token_num_t cmd_gso_size_size =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
+				cmd_size, UINT16);
+
+cmdline_parse_inst_t cmd_gso_size = {
+	.f = cmd_gso_size_parsed,
+	.data = NULL,
+	.help_str = "set gso segsz <length>",
+	.tokens = {
+		(void *)&cmd_gso_size_set,
+		(void *)&cmd_gso_size_keyword,
+		(void *)&cmd_gso_size_segsz,
+		(void *)&cmd_gso_size_size,
+		NULL,
+	},
+};
+
+/* *** SHOW GSO CONFIGURATION *** */
+struct cmd_gso_show_result {
+	cmdline_fixed_string_t cmd_show;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	portid_t cmd_pid;
+};
+
+static void
+cmd_gso_show_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_show_result *res = parsed_result;
+
+	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
+		printf("invalid port id %u\n", res->cmd_pid);
+		return;
+	}
+	if (!strcmp(res->cmd_keyword, "gso")) {
+		if (gso_ports[res->cmd_pid].enable) {
+			printf("Max GSO'd packet size: %uB\n"
+					"Supported GSO types: TCP/IPv4, "
+					"VxLAN with inner TCP/IPv4 packet, "
+					"GRE with inner TCP/IPv4  packet\n",
+					gso_max_segment_size);
+		} else
+			printf("GSO is not enabled on Port %u\n", res->cmd_pid);
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_show_show =
+TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+		cmd_show, "show");
+cmdline_parse_token_string_t cmd_gso_show_port =
+TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+		cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_show_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_num_t cmd_gso_show_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
+				cmd_pid, UINT16);
+
+cmdline_parse_inst_t cmd_gso_show = {
+	.f = cmd_gso_show_parsed,
+	.data = NULL,
+	.help_str = "show port <port_id> gso",
+	.tokens = {
+		(void *)&cmd_gso_show_show,
+		(void *)&cmd_gso_show_port,
+		(void *)&cmd_gso_show_pid,
+		(void *)&cmd_gso_show_keyword,
+		NULL,
+	},
+};
+
 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
 struct cmd_set_flush_rx {
 	cmdline_fixed_string_t set;
@@ -14723,6 +14900,9 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_gro_enable,
 	(cmdline_parse_inst_t *)&cmd_gro_flush,
 	(cmdline_parse_inst_t *)&cmd_gro_show,
+	(cmdline_parse_inst_t *)&cmd_gso_enable,
+	(cmdline_parse_inst_t *)&cmd_gso_size,
+	(cmdline_parse_inst_t *)&cmd_gso_show,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
app/test-pmd/config.c +24 -0
index 90e4f19..d04940c 100644
@@ -2510,6 +2510,30 @@ show_gro(portid_t port_id)
 		printf("Port %u doesn't enable GRO.\n", port_id);
 }
 
+void
+setup_gso(const char *mode, portid_t port_id)
+{
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		printf("invalid port id %u\n", port_id);
+		return;
+	}
+	if (strcmp(mode, "on") == 0) {
+		if (test_done == 0) {
+			printf("before enabling GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 1;
+	} else if (strcmp(mode, "off") == 0) {
+		if (test_done == 0) {
+			printf("before disabling GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 0;
+	}
+}
+
 char*
 list_pkt_forwarding_modes(void)
 {
app/test-pmd/csumonly.c +39 -4

104 lines not on this page · raw message

app/test-pmd/testpmd.c +13 -0
index 408db9f..037eb8e 100644
@@ -400,6 +400,9 @@ static int eth_event_callback(portid_t port_id,
  */
 static int all_ports_started(void);
 
+struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+uint16_t gso_max_segment_size = ETHER_MAX_LEN - ETHER_CRC_LEN;
+
 /*
  * Helper function to check if socket is already discovered.
  * If yes, return positive value. If not, return zero.
@@ -571,6 +574,7 @@ init_config(void)
 	lcoreid_t  lc_id;
 	uint8_t port_per_socket[RTE_MAX_NUMA_NODES];
 	struct rte_gro_param gro_param;
+	uint32_t gso_types;
 
 	memset(port_per_socket,0,RTE_MAX_NUMA_NODES);
 
@@ -655,6 +659,8 @@ init_config(void)
 
 	init_port_config();
 
+	gso_types = DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+		DEV_TX_OFFLOAD_GRE_TNL_TSO;
 	/*
 	 * Records which Mbuf pool to use by each logical core, if needed.
 	 */
@@ -665,6 +671,13 @@ init_config(void)
 		if (mbp == NULL)
 			mbp = mbuf_pool_find(0);
 		fwd_lcores[lc_id]->mbp = mbp;
+		/* initialize GSO context */
+		fwd_lcores[lc_id]->gso_ctx.direct_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.indirect_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.gso_types = gso_types;
+		fwd_lcores[lc_id]->gso_ctx.gso_size = ETHER_MAX_LEN -
+			ETHER_CRC_LEN;
+		fwd_lcores[lc_id]->gso_ctx.flag = 0;
 	}
 
 	/* Configuration of packet forwarding streams. */
app/test-pmd/testpmd.h +10 -0
index 2dc3b74..e2d9e34 100644
@@ -36,6 +36,7 @@
 
 #include <rte_pci.h>
 #include <rte_gro.h>
+#include <rte_gso.h>
 
 #define RTE_PORT_ALL            (~(portid_t)0x0)
 
@@ -206,6 +207,7 @@ struct rte_port {
  * CPU id. configuration table.
  */
 struct fwd_lcore {
+	struct rte_gso_ctx gso_ctx;     /**< GSO context */
 	struct rte_mempool *mbp; /**< The mbuf pool to use by this core */
 	void *gro_ctx;		/**< GRO context */
 	streamid_t stream_idx;   /**< index of 1st stream in "fwd_streams" */
@@ -450,6 +452,13 @@ struct gro_status {
 extern struct gro_status gro_ports[RTE_MAX_ETHPORTS];
 extern uint8_t gro_flush_cycles;
 
+#define GSO_MAX_PKT_BURST 2048
+struct gso_status {
+	uint8_t enable;
+};
+extern struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+extern uint16_t gso_max_segment_size;
+
 static inline unsigned int
 lcore_num(void)
 {
@@ -652,6 +661,7 @@ int tx_queue_id_is_invalid(queueid_t txq_id);
 void setup_gro(const char *onoff, portid_t port_id);
 void setup_gro_flush_cycles(uint8_t cycles);
 void show_gro(portid_t port_id);
+void setup_gso(const char *mode, portid_t port_id);
 
 /* Functions to manage the set of filtered Multicast MAC addresses */
 void mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr);
doc/guides/testpmd_app_ug/testpmd_funcs.rst +46 -0

52 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#135 lore raw

PATCH v10 6/6 doc: add GSO programmer's guide

In reply to Jiayu Hu

From: Mark Kavanagh <[email protected]>

Add programmer's guide doc to explain the design and use of the GSO library.

---
 MAINTAINERS                                        |   6 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477 +++++++++++++++++++++
 doc/guides/prog_guide/index.rst                    |   1 +
 5 files changed, 1053 insertions(+)
 create mode 100644 doc/guides/prog_guide/generic_segmentation_offload_lib.rst
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
MAINTAINERS +6 -0
index cd0d6bc..950ef5c 100644
@@ -654,6 +654,12 @@ M: Jiayu Hu <[email protected]>
 F: lib/librte_gro/
 F: doc/guides/prog_guide/generic_receive_offload_lib.rst
 
+Generic Segmentation Offload
+M: Jiayu Hu <[email protected]>
+M: Mark Kavanagh <[email protected]>
+F: lib/librte_gso/
+F: doc/guides/prog_guide/generic_segmentation_offload_lib.rst
+
 Distributor
 M: Bruce Richardson <[email protected]>
 M: David Hunt <[email protected]>
doc/guides/prog_guide/generic_segmentation_offload_lib.rst new file +256 -0

256 lines not on this page · raw message

doc/guides/prog_guide/img/gso-output-segment-format.svg new file +313 -0

313 lines not on this page · raw message

doc/guides/prog_guide/img/gso-three-seg-mbuf.svg new file +477 -0

477 lines not on this page · raw message

doc/guides/prog_guide/index.rst +1 -0
index 40f04a1..c7c8b17 100644
@@ -56,6 +56,7 @@ Programmer's Guide
     reorder_lib
     ip_fragment_reassembly_lib
     generic_receive_offload_lib
+    generic_segmentation_offload_lib
     pdump_lib
     multi_proc_support
     kernel_nic_interface
Signature · 1 line
2.7.4
#136 lore raw

Re: [PATCH v10 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

In reply to Jiayu Hu
Quoted 100 lines · Jiayu Hu

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. This patch adds GSO support to DPDK for specific packet types: specifically, TCP/IPv4, VxLAN, and GRE.

The first patch introduces the GSO API framework. The second patch adds GSO support for TCP/IPv4 packets (containing an optional VLAN tag). The third patch adds GSO support for VxLAN packets that contain outer IPv4, and inner TCP/IPv4 headers (plus optional inner and/or outer VLAN tags). The fourth patch adds GSO support for GRE packets that contain outer IPv4, and inner TCP/IPv4 headers (with optional outer VLAN tag). The fifth patch in the series enables TCP/IPv4, VxLAN, and GRE GSO in testpmd's checksum forwarding engine. The final patch in the series adds GSO documentation to the programmer's guide.

Note that this patch set has dependency on the patch "app/testpmd: enable the heavyweight mode TCP/IPv4 GRO".
http://dpdk.org/dev/patchwork/patch/29867/

Performance Testing
===================
The performance of TCP/IPv4 GSO on a 10Gbps link is demonstrated using iperf. Setup for the test is described as follows:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine with "retry".
c. Select IP and TCP HW checksum calculation for P0; select TCP HW
checksum calculation for vhost-user port.
d. Launch a VM with csum and tso offloading enabled.
e. Run iperf-client on virtio-net port in the VM to send TCP packets.
With enabling csum and tso, the VM can send large TCP/IPv4 packets (mss is up to 64KB).
f. P1 is assigned to linux kernel and enabled kernel GRO. Run
iperf-server on P1.

We conduct three iperf tests:

test-1: enable GSO for P0 in testpmd, and set max GSO segment length
to 1514B. Run four iperf-client in the VM.
test-2: enable TSO for P0 in testpmd, and set TSO segsz to 1514B. Run
four iperf-client in the VM.
test-3: disable GSO and TSO in testpmd. Run two iperf-client in the VM.

Throughput of the above three tests:

test-1: 9Gbps
test-2: 9.5Gbps
test-3: 3Mbps

Functional Testing
==================
Unlike TCP packets, VMs can't send large VxLAN or GRE packets. The max length of tunneled packets from VMs is 1514B. So current experiment method can't be used to measure VxLAN and GRE GSO performance, but simply test the functionality via setting small GSO segment length (e.g. 500B).

VxLAN
-----
To test VxLAN GSO functionality, we use the following setup:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum forwarding
engine with "retry".
c. Testpmd commands:
- csum parse_tunnel on "P0"
- csum parse_tunnel on "vhost-user port"
- csum set outer-ip hw "P0"
- csum set ip hw "P0"
- csum set tcp hw "P0"
- csum set tcp hw "vhost-user port"
- set port "P0" gso on
- set gso segsz 500
d. Launch a VM with csum and tso offloading enabled.
e. Create a vxlan port for the virtio-net port in the VM. Run iperf-client
on the VxLAN port, so TCP packets are VxLAN encapsulated. However, the max packet length is 1514B.
f. P1 is assigned to linux kernel and kernel GRO is disabled. Similarly,
create a VxLAN port for P1, and run iperf-server on the VxLAN port.

In testpmd, we can see the length of all packets sent from P0 is smaller than or equal to 500B. Additionally, the packets arriving in P1 is encapsulated and is smaller than or equal to 500B.

GRE
---
The same process may be used to test GRE functionality, with the exception that the tunnel type created for both the guest's virtio-net, and the host's kernel interfaces is GRE:
ip tunnel add <gre tunnel> mode gre remote <remote IP> local <local_ip>

As in the VxLAN testcase, the length of packets sent from P0, and received on P1, is less than 500B.

<...>

Quoted 9 lines

Jiayu Hu (3):
gso: add Generic Segmentation Offload API framework
gso: add TCP/IPv4 GSO support
app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Mark Kavanagh (3):
gso: add VxLAN GSO support
gso: add GRE GSO support
doc: add GSO programmer's guide

Series applied to dpdk-next-net/master, thanks.

#137 lore raw

PATCH v9 1/6 gso: add Generic Segmentation Offload API framework

In reply to Mark Kavanagh

From: Jiayu Hu <[email protected]>

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. To segment a packet requires two steps. The first is to set proper flags to mbuf->ol_flags, where the flags are the same as that of TSO. The second is to call the segmentation API, rte_gso_segment(). This patch introduces the GSO API framework to DPDK.

rte_gso_segment() splits an input packet into small ones in each invocation. The GSO library refers to these small packets generated by rte_gso_segment() as GSO segments. Each of the newly-created GSO segments is organized as a two-segment MBUF, where the first segment is a standard MBUF, which stores a copy of packet header, and the second is an indirect MBUF which points to a section of data in the input packet. rte_gso_segment() reduces the refcnt of the input packet by 1. Therefore, when all GSO segments are freed, the input packet is freed automatically. Additionally, since each GSO segment has multiple MBUFs (i.e. 2 MBUFs), the driver of the interface which the GSO segments are sent to should support to transmit multi-segment packets.

The GSO framework clears the PKT_TX_TCP_SEG flag for both the input packet, and all produced GSO segments in the event of success, since segmentation in hardware is no longer required at that point.

---
 config/common_base                     |   5 ++
 doc/api/doxy-api-index.md              |   1 +
 doc/api/doxy-api.conf                  |   1 +
 doc/guides/rel_notes/release_17_11.rst |   1 +
 lib/Makefile                           |   2 +
 lib/librte_gso/Makefile                |  49 +++++++++++
 lib/librte_gso/rte_gso.c               |  52 ++++++++++++
 lib/librte_gso/rte_gso.h               | 143 +++++++++++++++++++++++++++++++++
 lib/librte_gso/rte_gso_version.map     |   7 ++
 mk/rte.app.mk                          |   1 +
 10 files changed, 262 insertions(+)
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
config/common_base +5 -0
index 12f6be9..58ca5c0 100644
@@ -653,6 +653,11 @@ CONFIG_RTE_LIBRTE_IP_FRAG_TBL_STAT=n
 CONFIG_RTE_LIBRTE_GRO=y
 
 #
+# Compile GSO library
+#
+CONFIG_RTE_LIBRTE_GSO=y
+
+#
 # Compile librte_meter
 #
 CONFIG_RTE_LIBRTE_METER=y
doc/api/doxy-api-index.md +1 -0
index 19e0d4f..6512918 100644
@@ -101,6 +101,7 @@ The public API headers are grouped by topics:
   [TCP]                (@ref rte_tcp.h),
   [UDP]                (@ref rte_udp.h),
   [GRO]                (@ref rte_gro.h),
+  [GSO]                (@ref rte_gso.h),
   [frag/reass]         (@ref rte_ip_frag.h),
   [LPM IPv4 route]     (@ref rte_lpm.h),
   [LPM IPv6 route]     (@ref rte_lpm6.h),
doc/api/doxy-api.conf +1 -0
index 823554f..408f2e6 100644
@@ -47,6 +47,7 @@ INPUT                   = doc/api/doxy-api-index.md \
                           lib/librte_ether \
                           lib/librte_eventdev \
                           lib/librte_gro \
+                          lib/librte_gso \
                           lib/librte_hash \
                           lib/librte_ip_frag \
                           lib/librte_jobstats \
doc/guides/rel_notes/release_17_11.rst +1 -0
index f6f9169..5bb36b7 100644
@@ -174,6 +174,7 @@ The libraries prepended with a plus sign were incremented in this version.
      librte_ethdev.so.7
      librte_eventdev.so.2
      librte_gro.so.1
+   + librte_gso.so.1
      librte_hash.so.2
      librte_ip_frag.so.1
      librte_jobstats.so.1
lib/Makefile +2 -0
index 86caba1..3d123f4 100644
@@ -108,6 +108,8 @@ DIRS-$(CONFIG_RTE_LIBRTE_REORDER) += librte_reorder
 DEPDIRS-librte_reorder := librte_eal librte_mempool librte_mbuf
 DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += librte_pdump
 DEPDIRS-librte_pdump := librte_eal librte_mempool librte_mbuf librte_ether
+DIRS-$(CONFIG_RTE_LIBRTE_GSO) += librte_gso
+DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net
 
 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
 DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni
lib/librte_gso/Makefile new file +49 -0

49 lines not on this page · raw message

lib/librte_gso/rte_gso.c new file +52 -0

52 lines not on this page · raw message

lib/librte_gso/rte_gso.h new file +143 -0

143 lines not on this page · raw message

lib/librte_gso/rte_gso_version.map new file +7 -0
new file mode 100644
index 0000000..e1fd453
@@ -0,0 +1,7 @@
+DPDK_17.11 {
+	global:
+
+	rte_gso_segment;
+
+	local: *;
+};
mk/rte.app.mk +1 -0
index c25fdd9..d4c9873 100644
@@ -66,6 +66,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PDUMP)          += -lrte_pdump
 _LDLIBS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR)    += -lrte_distributor
 _LDLIBS-$(CONFIG_RTE_LIBRTE_IP_FRAG)        += -lrte_ip_frag
 _LDLIBS-$(CONFIG_RTE_LIBRTE_GRO)            += -lrte_gro
+_LDLIBS-$(CONFIG_RTE_LIBRTE_GSO)            += -lrte_gso
 _LDLIBS-$(CONFIG_RTE_LIBRTE_METER)          += -lrte_meter
 _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED)          += -lrte_sched
 _LDLIBS-$(CONFIG_RTE_LIBRTE_LPM)            += -lrte_lpm
Signature · 1 line
1.9.3
#138 lore raw

PATCH v9 2/6 gso: add TCP/IPv4 GSO support

In reply to Mark Kavanagh

From: Jiayu Hu <[email protected]>

This patch adds GSO support for TCP/IPv4 packets. Supported packets may include a single VLAN tag. TCP/IPv4 GSO doesn't check if input packets have correct checksums, and doesn't update checksums for output packets (the responsibility for this lies with the application). Additionally, TCP/IPv4 GSO doesn't process IP fragmented packets.

TCP/IPv4 GSO uses two chained MBUFs, one direct MBUF and one indrect MBUF, to organize an output packet. Note that we refer to these two chained MBUFs as a two-segment MBUF. The direct MBUF stores the packet header, while the indirect mbuf simply points to a location within the original packet's payload. Consequently, use of the GSO library requires multi-segment MBUF support in the TX functions of the NIC driver.

If a packet is GSO'd, TCP/IPv4 GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst  |  12 +++
 lib/Makefile                            |   2 +-
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 153 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 141 +++++++++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.c               | 104 ++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.h               |  74 +++++++++++++++
 lib/librte_gso/rte_gso.c                |  53 ++++++++++-
 lib/librte_gso/rte_gso.h                |   7 +-
 10 files changed, 543 insertions(+), 6 deletions(-)
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
doc/guides/rel_notes/release_17_11.rst +12 -0
index 5bb36b7..dd37169 100644
@@ -41,6 +41,18 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Added the Generic Segmentation Offload Library.**
+
+  Added the Generic Segmentation Offload (GSO) library to enable
+  applications to split large packets (e.g. MTU is 64KB) into small
+  ones (e.g. MTU is 1500B). Supported packet types are:
+
+  * TCP/IPv4 packets.
+
+  The GSO library doesn't check if the input packets have correct
+  checksums, and doesn't update checksums for output packets.
+  Additionally, the GSO library doesn't process IP fragmented packets.
+
 
 Resolved Issues
 ---------------
lib/Makefile +1 -1
index 3d123f4..5ecd1b3 100644
@@ -109,7 +109,7 @@ DEPDIRS-librte_reorder := librte_eal librte_mempool librte_mbuf
 DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += librte_pdump
 DEPDIRS-librte_pdump := librte_eal librte_mempool librte_mbuf librte_ether
 DIRS-$(CONFIG_RTE_LIBRTE_GSO) += librte_gso
-DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net
+DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net librte_mempool
 
 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
 DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni
lib/librte_eal/common/include/rte_log.h +1 -0
index ec8dba7..2fa1199 100644
@@ -87,6 +87,7 @@ struct rte_logs {
 #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
 #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
 #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
+#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
 
 /* these log types can be used in an application */
 #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
lib/librte_gso/Makefile +2 -0
index aeaacbc..2be64d1 100644
@@ -42,6 +42,8 @@ LIBABIVER := 1
 
 #source files
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c new file +153 -0

153 lines not on this page · raw message

lib/librte_gso/gso_common.h new file +141 -0

141 lines not on this page · raw message

lib/librte_gso/gso_tcp4.c new file +104 -0

104 lines not on this page · raw message

lib/librte_gso/gso_tcp4.h new file +74 -0

74 lines not on this page · raw message

lib/librte_gso/rte_gso.c +49 -4

68 lines not on this page · raw message

lib/librte_gso/rte_gso.h +6 -1
index 7d343d7..7ca2d81 100644
@@ -46,6 +46,10 @@
 #include <stdint.h>
 #include <rte_mbuf.h>
 
+/* Minimum GSO segment size. */
+#define RTE_GSO_SEG_SIZE_MIN (sizeof(struct ether_hdr) + \
+		sizeof(struct ipv4_hdr) + sizeof(struct tcp_hdr) + 1)
+
 /* GSO flags for rte_gso_ctx. */
 #define RTE_GSO_FLAG_IPID_FIXED (1ULL << 0)
 /**< Use fixed IP ids for output GSO segments. Setting
@@ -81,7 +85,8 @@ struct rte_gso_ctx {
 	 */
 	uint16_t gso_size;
 	/**< maximum size of an output GSO segment, including packet
-	 * header and payload, measured in bytes.
+	 * header and payload, measured in bytes. Must exceed
+	 * RTE_GSO_SEG_SIZE_MIN.
 	 */
 };
 
Signature · 1 line
1.9.3
#139 lore raw

PATCH v9 3/6 gso: add VxLAN GSO support

In reply to Mark Kavanagh

This patch adds a framework that allows GSO on tunneled packets. Furthermore, it leverages that framework to provide GSO support for VxLAN-encapsulated packets.

Supported VxLAN packets must have an outer IPv4 header (prepended by an optional VLAN tag), and contain an inner TCP/IPv4 packet (with an optional inner VLAN tag).

VxLAN GSO doesn't check if input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with TCP/IPv4 GSO, VxLAN GSO uses a two-segment MBUF to organize each output packet, which mandates support for multi-segment mbufs in the TX functions of the NIC driver. Also, if a packet is GSOed, VxLAN GSO reduces its MBUF refcnt by 1. As a result, when all of its GSO'd segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst |   2 +
 lib/librte_gso/Makefile                |   1 +
 lib/librte_gso/gso_common.h            |  25 +++++++
 lib/librte_gso/gso_tunnel_tcp4.c       | 120 +++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_tunnel_tcp4.h       |  75 +++++++++++++++++++++
 lib/librte_gso/rte_gso.c               |  14 +++-
 6 files changed, 235 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
doc/guides/rel_notes/release_17_11.rst +2 -0
index dd37169..c58eeb1 100644
@@ -48,6 +48,8 @@ New Features
   ones (e.g. MTU is 1500B). Supported packet types are:
 
   * TCP/IPv4 packets.
+  * VxLAN packets, which must have an outer IPv4 header, and contain
+    an inner TCP/IPv4 packet.
 
   The GSO library doesn't check if the input packets have correct
   checksums, and doesn't update checksums for output packets.
lib/librte_gso/Makefile +1 -0
index 2be64d1..e6d41df 100644
@@ -44,6 +44,7 @@ LIBABIVER := 1
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tunnel_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.h +25 -0
index a8ad638..95d54e7 100644
@@ -39,6 +39,7 @@
 #include <rte_mbuf.h>
 #include <rte_ip.h>
 #include <rte_tcp.h>
+#include <rte_udp.h>
 
 #define IS_FRAGMENTED(frag_off) (((frag_off) & IPV4_HDR_OFFSET_MASK) != 0 \
 		|| ((frag_off) & IPV4_HDR_MF_FLAG) == IPV4_HDR_MF_FLAG)
@@ -49,6 +50,30 @@
 #define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
 		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
 
+#define IS_IPV4_VXLAN_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_VXLAN))
+
+/**
+ * Internal function which updates the UDP header of a packet, following
+ * segmentation. This is required to update the header's datagram length field.
+ *
+ * @param pkt
+ *  The packet containing the UDP header.
+ * @param udp_offset
+ *  The offset of the UDP header from the start of the packet.
+ */
+static inline void
+update_udp_header(struct rte_mbuf *pkt, uint16_t udp_offset)
+{
+	struct udp_hdr *udp_hdr;
+
+	udp_hdr = (struct udp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			udp_offset);
+	udp_hdr->dgram_len = rte_cpu_to_be_16(pkt->pkt_len - udp_offset);
+}
+
 /**
  * Internal function which updates the TCP header of a packet, following
  * segmentation. This is required to update the header's 'sent' sequence
lib/librte_gso/gso_tunnel_tcp4.c new file +120 -0

120 lines not on this page · raw message

lib/librte_gso/gso_tunnel_tcp4.h new file +75 -0

75 lines not on this page · raw message

lib/librte_gso/rte_gso.c +12 -2
index 822693f..0a3ef11 100644
@@ -39,6 +39,7 @@
 #include "rte_gso.h"
 #include "gso_common.h"
 #include "gso_tcp4.h"
+#include "gso_tunnel_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -56,7 +57,8 @@
 	if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
 			nb_pkts_out < 1 ||
 			gso_ctx->gso_size < RTE_GSO_SEG_SIZE_MIN ||
-			gso_ctx->gso_types != DEV_TX_OFFLOAD_TCP_TSO)
+			((gso_ctx->gso_types & (DEV_TX_OFFLOAD_TCP_TSO |
+			DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) == 0))
 		return -EINVAL;
 
 	if (gso_ctx->gso_size >= pkt->pkt_len) {
@@ -71,12 +73,20 @@
 	ipid_delta = (gso_ctx->flag != RTE_GSO_FLAG_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_TCP(pkt->ol_flags)) {
+	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)
+		&& (gso_ctx->gso_types & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else if (IS_IPV4_TCP(pkt->ol_flags) &&
+			(gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO)) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
 				pkts_out, nb_pkts_out);
 	} else {
+		/* unsupported packet, skip */
 		pkts_out[0] = pkt;
 		RTE_LOG(DEBUG, GSO, "Unsupported packet type\n");
 		return 1;
Signature · 1 line
1.9.3
#140 lore raw

PATCH v9 4/6 gso: add GRE GSO support

In reply to Mark Kavanagh

This patch adds GSO support for GRE-tunneled packets. Supported GRE packets must contain an outer IPv4 header, and inner TCP/IPv4 headers. They may also contain a single VLAN tag. GRE GSO doesn't check if all input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with VxLAN GSO, GRE GSO uses a two-segment MBUF to organize each output packet, which requires multi-segment mbuf support in the TX functions of the NIC driver. Also, if a packet is GSOed, GRE GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst |  2 ++
 lib/librte_gso/gso_common.h            |  5 +++++
 lib/librte_gso/gso_tunnel_tcp4.c       | 14 ++++++++++----
 lib/librte_gso/rte_gso.c               |  9 ++++++---
 4 files changed, 23 insertions(+), 7 deletions(-)
doc/guides/rel_notes/release_17_11.rst +2 -0
index c58eeb1..2faa630 100644
@@ -50,6 +50,8 @@ New Features
   * TCP/IPv4 packets.
   * VxLAN packets, which must have an outer IPv4 header, and contain
     an inner TCP/IPv4 packet.
+  * GRE packets, which must contain an outer IPv4 header, and inner
+    TCP/IPv4 headers.
 
   The GSO library doesn't check if the input packets have correct
   checksums, and doesn't update checksums for output packets.
lib/librte_gso/gso_common.h +5 -0
index 95d54e7..145ea49 100644
@@ -55,6 +55,11 @@
 		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
 		 PKT_TX_TUNNEL_VXLAN))
 
+#define IS_IPV4_GRE_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_GRE)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_GRE))
+
 /**
  * Internal function which updates the UDP header of a packet, following
  * segmentation. This is required to update the header's datagram length field.
lib/librte_gso/gso_tunnel_tcp4.c +10 -4
index 5e8c8e5..8d0cfd7 100644
@@ -42,11 +42,13 @@
 	struct tcp_hdr *tcp_hdr;
 	uint32_t sent_seq;
 	uint16_t outer_id, inner_id, tail_idx, i;
-	uint16_t outer_ipv4_offset, inner_ipv4_offset, udp_offset, tcp_offset;
+	uint16_t outer_ipv4_offset, inner_ipv4_offset;
+	uint16_t udp_gre_offset, tcp_offset;
+	uint8_t update_udp_hdr;
 
 	outer_ipv4_offset = pkt->outer_l2_len;
-	udp_offset = outer_ipv4_offset + pkt->outer_l3_len;
-	inner_ipv4_offset = udp_offset + pkt->l2_len;
+	udp_gre_offset = outer_ipv4_offset + pkt->outer_l3_len;
+	inner_ipv4_offset = udp_gre_offset + pkt->l2_len;
 	tcp_offset = inner_ipv4_offset + pkt->l3_len;
 
 	/* Outer IPv4 header. */
@@ -63,9 +65,13 @@
 	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
 	tail_idx = nb_segs - 1;
 
+	/* Only update UDP header for VxLAN packets. */
+	update_udp_hdr = (pkt->ol_flags & PKT_TX_TUNNEL_VXLAN) ? 1 : 0;
+
 	for (i = 0; i < nb_segs; i++) {
 		update_ipv4_header(segs[i], outer_ipv4_offset, outer_id);
-		update_udp_header(segs[i], udp_offset);
+		if (update_udp_hdr)
+			update_udp_header(segs[i], udp_gre_offset);
 		update_ipv4_header(segs[i], inner_ipv4_offset, inner_id);
 		update_tcp_header(segs[i], tcp_offset, sent_seq, i < tail_idx);
 		outer_id++;
lib/librte_gso/rte_gso.c +6 -3
index 0a3ef11..f86e654 100644
@@ -58,7 +58,8 @@
 			nb_pkts_out < 1 ||
 			gso_ctx->gso_size < RTE_GSO_SEG_SIZE_MIN ||
 			((gso_ctx->gso_types & (DEV_TX_OFFLOAD_TCP_TSO |
-			DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) == 0))
+			DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+			DEV_TX_OFFLOAD_GRE_TNL_TSO)) == 0))
 		return -EINVAL;
 
 	if (gso_ctx->gso_size >= pkt->pkt_len) {
@@ -73,8 +74,10 @@
 	ipid_delta = (gso_ctx->flag != RTE_GSO_FLAG_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)
-		&& (gso_ctx->gso_types & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) {
+	if ((IS_IPV4_VXLAN_TCP4(pkt->ol_flags) &&
+			(gso_ctx->gso_types & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) ||
+			((IS_IPV4_GRE_TCP4(pkt->ol_flags) &&
+			 (gso_ctx->gso_types & DEV_TX_OFFLOAD_GRE_TNL_TSO)))) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
Signature · 1 line
1.9.3
#141 lore raw

PATCH v9 5/6 app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

In reply to Mark Kavanagh

From: Jiayu Hu <[email protected]>

This patch adds GSO support to the csum forwarding engine. Oversized packets transmitted over a GSO-enabled port will undergo segmentation (with the exception of packet-types unsupported by the GSO library). GSO support is disabled by default.

GSO support may be toggled on a per-port basis, using the command:

"set port <port_id> gso on|off"

The maximum packet length (including the packet header and payload) for GSO segments may be set with the command:

"set gso segsz <length>"

Show GSO configuration for a given port with the command:

"show port <port_id> gso"

---
 app/test-pmd/cmdline.c                      | 179 ++++++++++++++++++++++++++++
 app/test-pmd/config.c                       |  24 ++++
 app/test-pmd/csumonly.c                     |  42 ++++++-
 app/test-pmd/testpmd.c                      |  13 ++
 app/test-pmd/testpmd.h                      |  10 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  46 +++++++
 6 files changed, 310 insertions(+), 4 deletions(-)
app/test-pmd/cmdline.c +179 -0
index ccdf239..e92cd59 100644
@@ -431,6 +431,17 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"    Set max flow number and max packet number per-flow"
 			" for GRO.\n\n"
 
+			"set port (port_id) gso (on|off)"
+			"    Enable or disable Generic Segmentation Offload in"
+			" csum forwarding engine.\n\n"
+
+			"set gso segsz (length)\n"
+			"    Set max packet length for output GSO segments,"
+			" including packet header and payload.\n\n"
+
+			"show port (port_id) gso\n"
+			"    Show GSO configuration.\n\n"
+
 			"set fwd (%s)\n"
 			"    Set packet forwarding mode.\n\n"
 
@@ -3967,6 +3978,171 @@ struct cmd_gro_set_result {
 	},
 };
 
+/* *** ENABLE/DISABLE GSO *** */
+struct cmd_gso_enable_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_mode;
+	uint8_t cmd_pid;
+};
+
+static void
+cmd_gso_enable_parsed(void *parsed_result,
+		__attribute__((unused)) struct cmdline *cl,
+		__attribute__((unused)) void *data)
+{
+	struct cmd_gso_enable_result *res;
+
+	res = parsed_result;
+	if (!strcmp(res->cmd_keyword, "gso"))
+		setup_gso(res->cmd_mode, res->cmd_pid);
+}
+
+cmdline_parse_token_string_t cmd_gso_enable_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_enable_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_enable_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_enable_mode =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_mode, "on#off");
+cmdline_parse_token_num_t cmd_gso_enable_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_enable = {
+	.f = cmd_gso_enable_parsed,
+	.data = NULL,
+	.help_str = "set port <port_id> gso on|off",
+	.tokens = {
+		(void *)&cmd_gso_enable_set,
+		(void *)&cmd_gso_enable_port,
+		(void *)&cmd_gso_enable_pid,
+		(void *)&cmd_gso_enable_keyword,
+		(void *)&cmd_gso_enable_mode,
+		NULL,
+	},
+};
+
+/* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
+struct cmd_gso_size_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_segsz;
+	uint16_t cmd_size;
+};
+
+static void
+cmd_gso_size_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_size_result *res = parsed_result;
+
+	if (test_done == 0) {
+		printf("Before setting GSO segsz, please first stop fowarding\n");
+		return;
+	}
+
+	if (!strcmp(res->cmd_keyword, "gso") &&
+			!strcmp(res->cmd_segsz, "segsz")) {
+		if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
+			printf("gso_size should be larger than %zu."
+					" Please input a legal value\n",
+					RTE_GSO_SEG_SIZE_MIN);
+		else
+			gso_max_segment_size = res->cmd_size;
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_size_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_size_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_size_segsz =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_segsz, "segsz");
+cmdline_parse_token_num_t cmd_gso_size_size =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
+				cmd_size, UINT16);
+
+cmdline_parse_inst_t cmd_gso_size = {
+	.f = cmd_gso_size_parsed,
+	.data = NULL,
+	.help_str = "set gso segsz <length>",
+	.tokens = {
+		(void *)&cmd_gso_size_set,
+		(void *)&cmd_gso_size_keyword,
+		(void *)&cmd_gso_size_segsz,
+		(void *)&cmd_gso_size_size,
+		NULL,
+	},
+};
+
+/* *** SHOW GSO CONFIGURATION *** */
+struct cmd_gso_show_result {
+	cmdline_fixed_string_t cmd_show;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	uint8_t cmd_pid;
+};
+
+static void
+cmd_gso_show_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_show_result *res = parsed_result;
+
+	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
+		printf("invalid port id %u\n", res->cmd_pid);
+		return;
+	}
+	if (!strcmp(res->cmd_keyword, "gso")) {
+		if (gso_ports[res->cmd_pid].enable) {
+			printf("Max GSO'd packet size: %uB\n"
+					"Supported GSO types: TCP/IPv4, "
+					"VxLAN with inner TCP/IPv4 packet, "
+					"GRE with inner TCP/IPv4  packet\n",
+					gso_max_segment_size);
+		} else
+			printf("GSO is not enabled on Port %u\n", res->cmd_pid);
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_show_show =
+TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+		cmd_show, "show");
+cmdline_parse_token_string_t cmd_gso_show_port =
+TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+		cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_show_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_num_t cmd_gso_show_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
+				cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_show = {
+	.f = cmd_gso_show_parsed,
+	.data = NULL,
+	.help_str = "show port <port_id> gso",
+	.tokens = {
+		(void *)&cmd_gso_show_show,
+		(void *)&cmd_gso_show_port,
+		(void *)&cmd_gso_show_pid,
+		(void *)&cmd_gso_show_keyword,
+		NULL,
+	},
+};
+
 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
 struct cmd_set_flush_rx {
 	cmdline_fixed_string_t set;
@@ -14255,6 +14431,9 @@ struct cmd_cmdfile_result {
 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
 	(cmdline_parse_inst_t *)&cmd_enable_gro,
 	(cmdline_parse_inst_t *)&cmd_gro_set,
+	(cmdline_parse_inst_t *)&cmd_gso_enable,
+	(cmdline_parse_inst_t *)&cmd_gso_size,
+	(cmdline_parse_inst_t *)&cmd_gso_show,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
app/test-pmd/config.c +24 -0
index 3ae3e1c..88d09d0 100644
@@ -2454,6 +2454,30 @@ struct igb_ring_desc_16_bytes {
 	}
 }
 
+void
+setup_gso(const char *mode, uint8_t port_id)
+{
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		printf("invalid port id %u\n", port_id);
+		return;
+	}
+	if (strcmp(mode, "on") == 0) {
+		if (test_done == 0) {
+			printf("before enabling GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 1;
+	} else if (strcmp(mode, "off") == 0) {
+		if (test_done == 0) {
+			printf("before disabling GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 0;
+	}
+}
+
 char*
 list_pkt_forwarding_modes(void)
 {
app/test-pmd/csumonly.c +38 -4

103 lines not on this page · raw message

app/test-pmd/testpmd.c +13 -0
index e097ee0..b9ee77c 100644
@@ -400,6 +400,9 @@ static int eth_event_callback(uint8_t port_id,
  */
 static int all_ports_started(void);
 
+struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+uint16_t gso_max_segment_size = ETHER_MAX_LEN - ETHER_CRC_LEN;
+
 /*
  * Helper function to check if socket is already discovered.
  * If yes, return positive value. If not, return zero.
@@ -570,6 +573,7 @@ static int eth_event_callback(uint8_t port_id,
 	unsigned int nb_mbuf_per_pool;
 	lcoreid_t  lc_id;
 	uint8_t port_per_socket[RTE_MAX_NUMA_NODES];
+	uint32_t gso_types = 0;
 
 	memset(port_per_socket,0,RTE_MAX_NUMA_NODES);
 
@@ -654,6 +658,8 @@ static int eth_event_callback(uint8_t port_id,
 
 	init_port_config();
 
+	gso_types = DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+		DEV_TX_OFFLOAD_GRE_TNL_TSO;
 	/*
 	 * Records which Mbuf pool to use by each logical core, if needed.
 	 */
@@ -664,6 +670,13 @@ static int eth_event_callback(uint8_t port_id,
 		if (mbp == NULL)
 			mbp = mbuf_pool_find(0);
 		fwd_lcores[lc_id]->mbp = mbp;
+		/* initialize GSO context */
+		fwd_lcores[lc_id]->gso_ctx.direct_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.indirect_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.gso_types = gso_types;
+		fwd_lcores[lc_id]->gso_ctx.gso_size = ETHER_MAX_LEN -
+			ETHER_CRC_LEN;
+		fwd_lcores[lc_id]->gso_ctx.flag = 0;
 	}
 
 	/* Configuration of packet forwarding streams. */
app/test-pmd/testpmd.h +10 -0
index 1d1ee75..ff842a1 100644
@@ -36,6 +36,7 @@
 
 #include <rte_pci.h>
 #include <rte_gro.h>
+#include <rte_gso.h>
 
 #define RTE_PORT_ALL            (~(portid_t)0x0)
 
@@ -205,6 +206,7 @@ struct rte_port {
  * CPU id. configuration table.
  */
 struct fwd_lcore {
+	struct rte_gso_ctx gso_ctx;     /**< GSO context */
 	struct rte_mempool *mbp; /**< The mbuf pool to use by this core */
 	streamid_t stream_idx;   /**< index of 1st stream in "fwd_streams" */
 	streamid_t stream_nb;    /**< number of streams in "fwd_streams" */
@@ -442,6 +444,13 @@ struct gro_status {
 };
 extern struct gro_status gro_ports[RTE_MAX_ETHPORTS];
 
+#define GSO_MAX_PKT_BURST 2048
+struct gso_status {
+	uint8_t enable;
+};
+extern struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+extern uint16_t gso_max_segment_size;
+
 static inline unsigned int
 lcore_num(void)
 {
@@ -642,6 +651,7 @@ void port_rss_hash_key_update(portid_t port_id, char rss_type[],
 int rx_queue_id_is_invalid(queueid_t rxq_id);
 int tx_queue_id_is_invalid(queueid_t txq_id);
 void setup_gro(const char *mode, uint8_t port_id);
+void setup_gso(const char *mode, uint8_t port_id);
 
 /* Functions to manage the set of filtered Multicast MAC addresses */
 void mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr);
doc/guides/testpmd_app_ug/testpmd_funcs.rst +46 -0

52 lines not on this page · raw message

Signature · 1 line
1.9.3
#142 lore raw

PATCH v9 6/6 doc: add GSO programmer's guide

In reply to Mark Kavanagh

Add programmer's guide doc to explain the design and use of the GSO library.

---
 MAINTAINERS                                        |   6 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477 +++++++++++++++++++++
 doc/guides/prog_guide/index.rst                    |   1 +
 5 files changed, 1053 insertions(+)
 create mode 100644 doc/guides/prog_guide/generic_segmentation_offload_lib.rst
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
MAINTAINERS +6 -0
index 8df2a7f..8f0a4bd 100644
@@ -644,6 +644,12 @@ M: Jiayu Hu <[email protected]>
 F: lib/librte_gro/
 F: doc/guides/prog_guide/generic_receive_offload_lib.rst
 
+Generic Segmentation Offload
+M: Jiayu Hu <[email protected]>
+M: Mark Kavanagh <[email protected]>
+F: lib/librte_gso/
+F: doc/guides/prog_guide/generic_segmentation_offload_lib.rst
+
 Distributor
 M: Bruce Richardson <[email protected]>
 M: David Hunt <[email protected]>
doc/guides/prog_guide/generic_segmentation_offload_lib.rst new file +256 -0

256 lines not on this page · raw message

doc/guides/prog_guide/img/gso-output-segment-format.svg new file +313 -0

313 lines not on this page · raw message

doc/guides/prog_guide/img/gso-three-seg-mbuf.svg new file +477 -0

477 lines not on this page · raw message

doc/guides/prog_guide/index.rst +1 -0
index 40f04a1..c7c8b17 100644
@@ -56,6 +56,7 @@ Programmer's Guide
     reorder_lib
     ip_fragment_reassembly_lib
     generic_receive_offload_lib
+    generic_segmentation_offload_lib
     pdump_lib
     multi_proc_support
     kernel_nic_interface
Signature · 1 line
1.9.3
Acked-by on v9 6/6
#143 lore raw

Re: [PATCH v9 6/6] doc: add GSO programmer's guide

Quoted 12 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Mark Kavanagh
Sent: Thursday, October 5, 2017 9:37 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Ananyev, Konstantin <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B <[email protected]>
Subject: [dpdk-dev] [PATCH v9 6/6] doc: add GSO programmer's guide

Quoted 5 lines

Add programmer's guide doc to explain the design and use of the GSO library.

Hi Mark,

If the docs (or another part of the patchset) were previously acked but not changed in a new patchset then it is okay to include the previous ack line.

#144 lore raw

Re: [PATCH v9 6/6] doc: add GSO programmer's guide

Quoted 31 lines

-----Original Message-----
From: Mcnamara, John
Sent: Friday, October 6, 2017 2:35 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Ananyev, Konstantin <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B <[email protected]>
Subject: RE: [dpdk-dev] [PATCH v9 6/6] doc: add GSO programmer's guide

Quoted 10 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Mark Kavanagh
Sent: Thursday, October 5, 2017 9:37 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Ananyev, Konstantin <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B <[email protected]>
Subject: [dpdk-dev] [PATCH v9 6/6] doc: add GSO programmer's guide

Quoted 5 lines

Add programmer's guide doc to explain the design and use of the GSO library.

Quoted 5 lines

Hi Mark,

If the docs (or another part of the patchset) were previously acked but not changed in a new patchset then it is okay to include the previous ack line.

Of course - apologies John.

Quoted 2 lines
#145 lore raw

PATCH v8 5/6 app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

In reply to Mark Kavanagh

From: Jiayu Hu <[email protected]>

This patch adds GSO support to the csum forwarding engine. Oversized packets transmitted over a GSO-enabled port will undergo segmentation (with the exception of packet-types unsupported by the GSO library). GSO support is disabled by default.

GSO support may be toggled on a per-port basis, using the command:

"set port <port_id> gso on|off"

The maximum packet length (including the packet header and payload) for GSO segments may be set with the command:

"set gso segsz <length>"

Show GSO configuration for a given port with the command:

"show port <port_id> gso"

---
 app/test-pmd/cmdline.c                      | 179 ++++++++++++++++++++++++++++
 app/test-pmd/config.c                       |  24 ++++
 app/test-pmd/csumonly.c                     |  42 ++++++-
 app/test-pmd/testpmd.c                      |  13 ++
 app/test-pmd/testpmd.h                      |  10 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  46 +++++++
 6 files changed, 310 insertions(+), 4 deletions(-)
app/test-pmd/cmdline.c +179 -0
index ccdf239..92e6171 100644
@@ -431,6 +431,17 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"    Set max flow number and max packet number per-flow"
 			" for GRO.\n\n"
 
+			"set port (port_id) gso (on|off)"
+			"    Enable or disable Generic Segmentation Offload in"
+			" csum forwarding engine.\n\n"
+
+			"set gso segsz (length)\n"
+			"    Set max packet length for output GSO segments,"
+			" including packet header and payload.\n\n"
+
+			"show port (port_id) gso\n"
+			"    Show GSO configuration.\n\n"
+
 			"set fwd (%s)\n"
 			"    Set packet forwarding mode.\n\n"
 
@@ -3967,6 +3978,171 @@ struct cmd_gro_set_result {
 	},
 };
 
+/* *** ENABLE/DISABLE GSO *** */
+struct cmd_gso_enable_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_mode;
+	uint8_t cmd_pid;
+};
+
+static void
+cmd_gso_enable_parsed(void *parsed_result,
+		__attribute__((unused)) struct cmdline *cl,
+		__attribute__((unused)) void *data)
+{
+	struct cmd_gso_enable_result *res;
+
+	res = parsed_result;
+	if (!strcmp(res->cmd_keyword, "gso"))
+		setup_gso(res->cmd_mode, res->cmd_pid);
+}
+
+cmdline_parse_token_string_t cmd_gso_enable_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_enable_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_enable_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_enable_mode =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_mode, "on#off");
+cmdline_parse_token_num_t cmd_gso_enable_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_enable = {
+	.f = cmd_gso_enable_parsed,
+	.data = NULL,
+	.help_str = "set port <port_id> gso on|off",
+	.tokens = {
+		(void *)&cmd_gso_enable_set,
+		(void *)&cmd_gso_enable_port,
+		(void *)&cmd_gso_enable_pid,
+		(void *)&cmd_gso_enable_keyword,
+		(void *)&cmd_gso_enable_mode,
+		NULL,
+	},
+};
+
+/* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
+struct cmd_gso_size_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_segsz;
+	uint16_t cmd_size;
+};
+
+static void
+cmd_gso_size_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_size_result *res = parsed_result;
+
+	if (test_done == 0) {
+		printf("Before setting GSO segsz, please first stop fowarding\n");
+		return;
+	}
+
+	if (!strcmp(res->cmd_keyword, "gso") &&
+			!strcmp(res->cmd_segsz, "segsz")) {
+		if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
+			printf("gso_size should be larger than %lu."
+					" Please input a legal value\n",
+					RTE_GSO_SEG_SIZE_MIN);
+		else
+			gso_max_segment_size = res->cmd_size;
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_size_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_size_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_size_segsz =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_segsz, "segsz");
+cmdline_parse_token_num_t cmd_gso_size_size =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
+				cmd_size, UINT16);
+
+cmdline_parse_inst_t cmd_gso_size = {
+	.f = cmd_gso_size_parsed,
+	.data = NULL,
+	.help_str = "set gso segsz <length>",
+	.tokens = {
+		(void *)&cmd_gso_size_set,
+		(void *)&cmd_gso_size_keyword,
+		(void *)&cmd_gso_size_segsz,
+		(void *)&cmd_gso_size_size,
+		NULL,
+	},
+};
+
+/* *** SHOW GSO CONFIGURATION *** */
+struct cmd_gso_show_result {
+	cmdline_fixed_string_t cmd_show;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	uint8_t cmd_pid;
+};
+
+static void
+cmd_gso_show_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_show_result *res = parsed_result;
+
+	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
+		printf("invalid port id %u\n", res->cmd_pid);
+		return;
+	}
+	if (!strcmp(res->cmd_keyword, "gso")) {
+		if (gso_ports[res->cmd_pid].enable) {
+			printf("Max GSO'd packet size: %uB\n"
+					"Supported GSO types: TCP/IPv4, "
+					"VxLAN with inner TCP/IPv4 packet, "
+					"GRE with inner TCP/IPv4  packet\n",
+					gso_max_segment_size);
+		} else
+			printf("GSO is not enabled on Port %u\n", res->cmd_pid);
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_show_show =
+TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+		cmd_show, "show");
+cmdline_parse_token_string_t cmd_gso_show_port =
+TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+		cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_show_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_num_t cmd_gso_show_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
+				cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_show = {
+	.f = cmd_gso_show_parsed,
+	.data = NULL,
+	.help_str = "show port <port_id> gso",
+	.tokens = {
+		(void *)&cmd_gso_show_show,
+		(void *)&cmd_gso_show_port,
+		(void *)&cmd_gso_show_pid,
+		(void *)&cmd_gso_show_keyword,
+		NULL,
+	},
+};
+
 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
 struct cmd_set_flush_rx {
 	cmdline_fixed_string_t set;
@@ -14255,6 +14431,9 @@ struct cmd_cmdfile_result {
 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
 	(cmdline_parse_inst_t *)&cmd_enable_gro,
 	(cmdline_parse_inst_t *)&cmd_gro_set,
+	(cmdline_parse_inst_t *)&cmd_gso_enable,
+	(cmdline_parse_inst_t *)&cmd_gso_size,
+	(cmdline_parse_inst_t *)&cmd_gso_show,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
app/test-pmd/config.c +24 -0
index 3ae3e1c..88d09d0 100644
@@ -2454,6 +2454,30 @@ struct igb_ring_desc_16_bytes {
 	}
 }
 
+void
+setup_gso(const char *mode, uint8_t port_id)
+{
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		printf("invalid port id %u\n", port_id);
+		return;
+	}
+	if (strcmp(mode, "on") == 0) {
+		if (test_done == 0) {
+			printf("before enabling GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 1;
+	} else if (strcmp(mode, "off") == 0) {
+		if (test_done == 0) {
+			printf("before disabling GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 0;
+	}
+}
+
 char*
 list_pkt_forwarding_modes(void)
 {
app/test-pmd/csumonly.c +38 -4

103 lines not on this page · raw message

app/test-pmd/testpmd.c +13 -0
index e097ee0..b9ee77c 100644
@@ -400,6 +400,9 @@ static int eth_event_callback(uint8_t port_id,
  */
 static int all_ports_started(void);
 
+struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+uint16_t gso_max_segment_size = ETHER_MAX_LEN - ETHER_CRC_LEN;
+
 /*
  * Helper function to check if socket is already discovered.
  * If yes, return positive value. If not, return zero.
@@ -570,6 +573,7 @@ static int eth_event_callback(uint8_t port_id,
 	unsigned int nb_mbuf_per_pool;
 	lcoreid_t  lc_id;
 	uint8_t port_per_socket[RTE_MAX_NUMA_NODES];
+	uint32_t gso_types = 0;
 
 	memset(port_per_socket,0,RTE_MAX_NUMA_NODES);
 
@@ -654,6 +658,8 @@ static int eth_event_callback(uint8_t port_id,
 
 	init_port_config();
 
+	gso_types = DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+		DEV_TX_OFFLOAD_GRE_TNL_TSO;
 	/*
 	 * Records which Mbuf pool to use by each logical core, if needed.
 	 */
@@ -664,6 +670,13 @@ static int eth_event_callback(uint8_t port_id,
 		if (mbp == NULL)
 			mbp = mbuf_pool_find(0);
 		fwd_lcores[lc_id]->mbp = mbp;
+		/* initialize GSO context */
+		fwd_lcores[lc_id]->gso_ctx.direct_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.indirect_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.gso_types = gso_types;
+		fwd_lcores[lc_id]->gso_ctx.gso_size = ETHER_MAX_LEN -
+			ETHER_CRC_LEN;
+		fwd_lcores[lc_id]->gso_ctx.flag = 0;
 	}
 
 	/* Configuration of packet forwarding streams. */
app/test-pmd/testpmd.h +10 -0
index 1d1ee75..ff842a1 100644
@@ -36,6 +36,7 @@
 
 #include <rte_pci.h>
 #include <rte_gro.h>
+#include <rte_gso.h>
 
 #define RTE_PORT_ALL            (~(portid_t)0x0)
 
@@ -205,6 +206,7 @@ struct rte_port {
  * CPU id. configuration table.
  */
 struct fwd_lcore {
+	struct rte_gso_ctx gso_ctx;     /**< GSO context */
 	struct rte_mempool *mbp; /**< The mbuf pool to use by this core */
 	streamid_t stream_idx;   /**< index of 1st stream in "fwd_streams" */
 	streamid_t stream_nb;    /**< number of streams in "fwd_streams" */
@@ -442,6 +444,13 @@ struct gro_status {
 };
 extern struct gro_status gro_ports[RTE_MAX_ETHPORTS];
 
+#define GSO_MAX_PKT_BURST 2048
+struct gso_status {
+	uint8_t enable;
+};
+extern struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+extern uint16_t gso_max_segment_size;
+
 static inline unsigned int
 lcore_num(void)
 {
@@ -642,6 +651,7 @@ void port_rss_hash_key_update(portid_t port_id, char rss_type[],
 int rx_queue_id_is_invalid(queueid_t rxq_id);
 int tx_queue_id_is_invalid(queueid_t txq_id);
 void setup_gro(const char *mode, uint8_t port_id);
+void setup_gso(const char *mode, uint8_t port_id);
 
 /* Functions to manage the set of filtered Multicast MAC addresses */
 void mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr);
doc/guides/testpmd_app_ug/testpmd_funcs.rst +46 -0

52 lines not on this page · raw message

Signature · 1 line
1.9.3
#146 lore raw

PATCH v8 6/6 doc: add GSO programmer's guide

In reply to Mark Kavanagh

Add programmer's guide doc to explain the design and use of the GSO library.

---
 MAINTAINERS                                        |   6 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477 +++++++++++++++++++++
 doc/guides/prog_guide/index.rst                    |   1 +
 5 files changed, 1053 insertions(+)
 create mode 100644 doc/guides/prog_guide/generic_segmentation_offload_lib.rst
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
MAINTAINERS +6 -0
index 8df2a7f..8f0a4bd 100644
@@ -644,6 +644,12 @@ M: Jiayu Hu <[email protected]>
 F: lib/librte_gro/
 F: doc/guides/prog_guide/generic_receive_offload_lib.rst
 
+Generic Segmentation Offload
+M: Jiayu Hu <[email protected]>
+M: Mark Kavanagh <[email protected]>
+F: lib/librte_gso/
+F: doc/guides/prog_guide/generic_segmentation_offload_lib.rst
+
 Distributor
 M: Bruce Richardson <[email protected]>
 M: David Hunt <[email protected]>
doc/guides/prog_guide/generic_segmentation_offload_lib.rst new file +256 -0

256 lines not on this page · raw message

doc/guides/prog_guide/img/gso-output-segment-format.svg new file +313 -0

313 lines not on this page · raw message

doc/guides/prog_guide/img/gso-three-seg-mbuf.svg new file +477 -0

477 lines not on this page · raw message

doc/guides/prog_guide/index.rst +1 -0
index 40f04a1..c7c8b17 100644
@@ -56,6 +56,7 @@ Programmer's Guide
     reorder_lib
     ip_fragment_reassembly_lib
     generic_receive_offload_lib
+    generic_segmentation_offload_lib
     pdump_lib
     multi_proc_support
     kernel_nic_interface
Signature · 1 line
1.9.3
Acked-by on v8 6/6
#147 lore raw

Re: [PATCH v8 6/6] doc: add GSO programmer's guide

Quoted 12 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Mark Kavanagh
Sent: Thursday, October 5, 2017 4:44 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Ananyev, Konstantin <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B <[email protected]>
Subject: [dpdk-dev] [PATCH v8 6/6] doc: add GSO programmer's guide

Quoted 5 lines

Add programmer's guide doc to explain the design and use of the GSO library.

#148 lore raw

PATCH v5 1/6 gso: add Generic Segmentation Offload API framework

In reply to Jiayu Hu

From: Jiayu Hu <[email protected]>

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. To segment a packet requires two steps. The first is to set proper flags to mbuf->ol_flags, where the flags are the same as that of TSO. The second is to call the segmentation API, rte_gso_segment(). This patch introduces the GSO API framework to DPDK.

rte_gso_segment() splits an input packet into small ones in each invocation. The GSO library refers to these small packets generated by rte_gso_segment() as GSO segments. Each of the newly-created GSO segments is organized as a two-segment MBUF, where the first segment is a standard MBUF, which stores a copy of packet header, and the second is an indirect MBUF which points to a section of data in the input packet. rte_gso_segment() reduces the refcnt of the input packet by 1. Therefore, when all GSO segments are freed, the input packet is freed automatically. Additionally, since each GSO segment has multiple MBUFs (i.e. 2 MBUFs), the driver of the interface which the GSO segments are sent to should support to transmit multi-segment packets.

The GSO framework clears the PKT_TX_TCP_SEG flag for both the input packet, and all produced GSO segments in the event of success, since segmentation in hardware is no longer required at that point.

---
 config/common_base                     |   5 ++
 doc/api/doxy-api-index.md              |   1 +
 doc/api/doxy-api.conf                  |   1 +
 doc/guides/rel_notes/release_17_11.rst |   1 +
 lib/Makefile                           |   2 +
 lib/librte_gso/Makefile                |  49 +++++++++++
 lib/librte_gso/rte_gso.c               |  52 ++++++++++++
 lib/librte_gso/rte_gso.h               | 145 +++++++++++++++++++++++++++++++++
 lib/librte_gso/rte_gso_version.map     |   7 ++
 mk/rte.app.mk                          |   1 +
 10 files changed, 264 insertions(+)
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
config/common_base +5 -0
index 5e97a08..603e340 100644
@@ -652,6 +652,11 @@ CONFIG_RTE_LIBRTE_IP_FRAG_TBL_STAT=n
 CONFIG_RTE_LIBRTE_GRO=y
 
 #
+# Compile GSO library
+#
+CONFIG_RTE_LIBRTE_GSO=y
+
+#
 # Compile librte_meter
 #
 CONFIG_RTE_LIBRTE_METER=y
doc/api/doxy-api-index.md +1 -0
index 19e0d4f..6512918 100644
@@ -101,6 +101,7 @@ The public API headers are grouped by topics:
   [TCP]                (@ref rte_tcp.h),
   [UDP]                (@ref rte_udp.h),
   [GRO]                (@ref rte_gro.h),
+  [GSO]                (@ref rte_gso.h),
   [frag/reass]         (@ref rte_ip_frag.h),
   [LPM IPv4 route]     (@ref rte_lpm.h),
   [LPM IPv6 route]     (@ref rte_lpm6.h),
doc/api/doxy-api.conf +1 -0
index 823554f..408f2e6 100644
@@ -47,6 +47,7 @@ INPUT                   = doc/api/doxy-api-index.md \
                           lib/librte_ether \
                           lib/librte_eventdev \
                           lib/librte_gro \
+                          lib/librte_gso \
                           lib/librte_hash \
                           lib/librte_ip_frag \
                           lib/librte_jobstats \
doc/guides/rel_notes/release_17_11.rst +1 -0
index 8bf91bd..7508be7 100644
@@ -174,6 +174,7 @@ The libraries prepended with a plus sign were incremented in this version.
      librte_ethdev.so.7
      librte_eventdev.so.2
      librte_gro.so.1
+   + librte_gso.so.1
      librte_hash.so.2
      librte_ip_frag.so.1
      librte_jobstats.so.1
lib/Makefile +2 -0
index 86caba1..3d123f4 100644
@@ -108,6 +108,8 @@ DIRS-$(CONFIG_RTE_LIBRTE_REORDER) += librte_reorder
 DEPDIRS-librte_reorder := librte_eal librte_mempool librte_mbuf
 DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += librte_pdump
 DEPDIRS-librte_pdump := librte_eal librte_mempool librte_mbuf librte_ether
+DIRS-$(CONFIG_RTE_LIBRTE_GSO) += librte_gso
+DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net
 
 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
 DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni
lib/librte_gso/Makefile new file +49 -0

49 lines not on this page · raw message

lib/librte_gso/rte_gso.c new file +52 -0

52 lines not on this page · raw message

lib/librte_gso/rte_gso.h new file +145 -0

145 lines not on this page · raw message

lib/librte_gso/rte_gso_version.map new file +7 -0
new file mode 100644
index 0000000..e1fd453
@@ -0,0 +1,7 @@
+DPDK_17.11 {
+	global:
+
+	rte_gso_segment;
+
+	local: *;
+};
mk/rte.app.mk +1 -0
index c25fdd9..d4c9873 100644
@@ -66,6 +66,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PDUMP)          += -lrte_pdump
 _LDLIBS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR)    += -lrte_distributor
 _LDLIBS-$(CONFIG_RTE_LIBRTE_IP_FRAG)        += -lrte_ip_frag
 _LDLIBS-$(CONFIG_RTE_LIBRTE_GRO)            += -lrte_gro
+_LDLIBS-$(CONFIG_RTE_LIBRTE_GSO)            += -lrte_gso
 _LDLIBS-$(CONFIG_RTE_LIBRTE_METER)          += -lrte_meter
 _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED)          += -lrte_sched
 _LDLIBS-$(CONFIG_RTE_LIBRTE_LPM)            += -lrte_lpm
Signature · 1 line
1.9.3
#149 lore raw

PATCH v5 2/6 gso: add TCP/IPv4 GSO support

In reply to Jiayu Hu

From: Jiayu Hu <[email protected]>

This patch adds GSO support for TCP/IPv4 packets. Supported packets may include a single VLAN tag. TCP/IPv4 GSO doesn't check if input packets have correct checksums, and doesn't update checksums for output packets (the responsibility for this lies with the application). Additionally, TCP/IPv4 GSO doesn't process IP fragmented packets.

TCP/IPv4 GSO uses two chained MBUFs, one direct MBUF and one indrect MBUF, to organize an output packet. Note that we refer to these two chained MBUFs as a two-segment MBUF. The direct MBUF stores the packet header, while the indirect mbuf simply points to a location within the original packet's payload. Consequently, use of the GSO library requires multi-segment MBUF support in the TX functions of the NIC driver.

If a packet is GSO'd, TCP/IPv4 GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst  |  12 +++
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 153 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 141 +++++++++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.c               | 106 ++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.h               |  74 +++++++++++++++
 lib/librte_gso/rte_gso.c                |  52 ++++++++++-
 8 files changed, 538 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
doc/guides/rel_notes/release_17_11.rst +12 -0
index 7508be7..c414f73 100644
@@ -41,6 +41,18 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Added the Generic Segmentation Offload Library.**
+
+  Added the Generic Segmentation Offload (GSO) library to enable
+  applications to split large packets (e.g. MTU is 64KB) into small
+  ones (e.g. MTU is 1500B). Supported packet types are:
+
+  * TCP/IPv4 packets, which may include a single VLAN tag.
+
+  The GSO library doesn't check if the input packets have correct
+  checksums, and doesn't update checksums for output packets.
+  Additionally, the GSO library doesn't process IP fragmented packets.
+
 
 Resolved Issues
 ---------------
lib/librte_eal/common/include/rte_log.h +1 -0
index ec8dba7..2fa1199 100644
@@ -87,6 +87,7 @@ struct rte_logs {
 #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
 #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
 #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
+#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
 
 /* these log types can be used in an application */
 #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
lib/librte_gso/Makefile +2 -0
index aeaacbc..2be64d1 100644
@@ -42,6 +42,8 @@ LIBABIVER := 1
 
 #source files
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c new file +153 -0

153 lines not on this page · raw message

lib/librte_gso/gso_common.h new file +141 -0

141 lines not on this page · raw message

lib/librte_gso/gso_tcp4.c new file +106 -0

106 lines not on this page · raw message

lib/librte_gso/gso_tcp4.h new file +74 -0

74 lines not on this page · raw message

lib/librte_gso/rte_gso.c +49 -3

68 lines not on this page · raw message

Signature · 1 line
1.9.3
author
#150 lore raw

Re: [PATCH v5 2/6] gso: add TCP/IPv4 GSO support

Hi Mark,

One comment is inline.

Thanks,
Jiayu

Quoted 427 lines · Mark Kavanagh

From: Jiayu Hu <[email protected]>

This patch adds GSO support for TCP/IPv4 packets. Supported packets may include a single VLAN tag. TCP/IPv4 GSO doesn't check if input packets have correct checksums, and doesn't update checksums for output packets (the responsibility for this lies with the application). Additionally, TCP/IPv4 GSO doesn't process IP fragmented packets.

TCP/IPv4 GSO uses two chained MBUFs, one direct MBUF and one indrect MBUF, to organize an output packet. Note that we refer to these two chained MBUFs as a two-segment MBUF. The direct MBUF stores the packet header, while the indirect mbuf simply points to a location within the original packet's payload. Consequently, use of the GSO library requires multi-segment MBUF support in the TX functions of the NIC driver.

If a packet is GSO'd, TCP/IPv4 GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst  |  12 +++
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 153 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 141 +++++++++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.c               | 106 ++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.h               |  74 +++++++++++++++
 lib/librte_gso/rte_gso.c                |  52 ++++++++++-
 8 files changed, 538 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
doc/guides/rel_notes/release_17_11.rst +12 -0
index 7508be7..c414f73 100644
@@ -41,6 +41,18 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Added the Generic Segmentation Offload Library.**
+
+  Added the Generic Segmentation Offload (GSO) library to enable
+  applications to split large packets (e.g. MTU is 64KB) into small
+  ones (e.g. MTU is 1500B). Supported packet types are:
+
+  * TCP/IPv4 packets, which may include a single VLAN tag.
+
+  The GSO library doesn't check if the input packets have correct
+  checksums, and doesn't update checksums for output packets.
+  Additionally, the GSO library doesn't process IP fragmented packets.
+
 
 Resolved Issues
 ---------------
lib/librte_eal/common/include/rte_log.h +1 -0
index ec8dba7..2fa1199 100644
@@ -87,6 +87,7 @@ struct rte_logs {
 #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
 #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
 #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
+#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
 
 /* these log types can be used in an application */
 #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
lib/librte_gso/Makefile +2 -0
index aeaacbc..2be64d1 100644
@@ -42,6 +42,8 @@ LIBABIVER := 1
 
 #source files
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c new file +153 -0
new file mode 100644
index 0000000..ee75d4c
@@ -0,0 +1,153 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdbool.h>
+#include <errno.h>
+
+#include <rte_memcpy.h>
+#include <rte_mempool.h>
+
+#include "gso_common.h"
+
+static inline void
+hdr_segment_init(struct rte_mbuf *hdr_segment, struct rte_mbuf *pkt,
+		uint16_t pkt_hdr_offset)
+{
+	/* Copy MBUF metadata */
+	hdr_segment->nb_segs = 1;
+	hdr_segment->port = pkt->port;
+	hdr_segment->ol_flags = pkt->ol_flags;
+	hdr_segment->packet_type = pkt->packet_type;
+	hdr_segment->pkt_len = pkt_hdr_offset;
+	hdr_segment->data_len = pkt_hdr_offset;
+	hdr_segment->tx_offload = pkt->tx_offload;
+
+	/* Copy the packet header */
+	rte_memcpy(rte_pktmbuf_mtod(hdr_segment, char *),
+			rte_pktmbuf_mtod(pkt, char *),
+			pkt_hdr_offset);
+}
+
+static inline void
+free_gso_segment(struct rte_mbuf **pkts, uint16_t nb_pkts)
+{
+	uint16_t i;
+
+	for (i = 0; i < nb_pkts; i++)
+		rte_pktmbuf_free(pkts[i]);
+}
+
+int
+gso_do_segment(struct rte_mbuf *pkt,
+		uint16_t pkt_hdr_offset,
+		uint16_t pyld_unit_size,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct rte_mbuf *pkt_in;
+	struct rte_mbuf *hdr_segment, *pyld_segment, *prev_segment;
+	uint16_t pkt_in_data_pos, segment_bytes_remaining;
+	uint16_t pyld_len, nb_segs;
+	bool more_in_pkt, more_out_segs;
+
+	pkt_in = pkt;
+	nb_segs = 0;
+	more_in_pkt = 1;
+	pkt_in_data_pos = pkt_hdr_offset;
+
+	while (more_in_pkt) {
+		if (unlikely(nb_segs >= nb_pkts_out)) {
+			free_gso_segment(pkts_out, nb_segs);
+			return -EINVAL;
+		}
+
+		/* Allocate a direct MBUF */
+		hdr_segment = rte_pktmbuf_alloc(direct_pool);
+		if (unlikely(hdr_segment == NULL)) {
+			free_gso_segment(pkts_out, nb_segs);
+			return -ENOMEM;
+		}
+		/* Fill the packet header */
+		hdr_segment_init(hdr_segment, pkt, pkt_hdr_offset);
+
+		prev_segment = hdr_segment;
+		segment_bytes_remaining = pyld_unit_size;
+		more_out_segs = 1;
+
+		while (more_out_segs && more_in_pkt) {
+			/* Allocate an indirect MBUF */
+			pyld_segment = rte_pktmbuf_alloc(indirect_pool);
+			if (unlikely(pyld_segment == NULL)) {
+				rte_pktmbuf_free(hdr_segment);
+				free_gso_segment(pkts_out, nb_segs);
+				return -ENOMEM;
+			}
+			/* Attach to current MBUF segment of pkt */
+			rte_pktmbuf_attach(pyld_segment, pkt_in);
+
+			prev_segment->next = pyld_segment;
+			prev_segment = pyld_segment;
+
+			pyld_len = segment_bytes_remaining;
+			if (pyld_len + pkt_in_data_pos > pkt_in->data_len)
+				pyld_len = pkt_in->data_len - pkt_in_data_pos;
+
+			pyld_segment->data_off = pkt_in_data_pos +
+				pkt_in->data_off;
+			pyld_segment->data_len = pyld_len;
+
+			/* Update header segment */
+			hdr_segment->pkt_len += pyld_len;
+			hdr_segment->nb_segs++;
+
+			pkt_in_data_pos += pyld_len;
+			segment_bytes_remaining -= pyld_len;
+
+			/* Finish processing a MBUF segment of pkt */
+			if (pkt_in_data_pos == pkt_in->data_len) {
+				pkt_in = pkt_in->next;
+				pkt_in_data_pos = 0;
+				if (pkt_in == NULL)
+					more_in_pkt = 0;
+			}
+
+			/* Finish generating a GSO segment */
+			if (segment_bytes_remaining == 0)
+				more_out_segs = 0;
+		}
+		pkts_out[nb_segs++] = hdr_segment;
+	}
+	return nb_segs;
+}
lib/librte_gso/gso_common.h new file +141 -0
new file mode 100644
index 0000000..8d9b94e
@@ -0,0 +1,141 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _GSO_COMMON_H_
+#define _GSO_COMMON_H_
+
+#include <stdint.h>
+
+#include <rte_mbuf.h>
+#include <rte_ip.h>
+#include <rte_tcp.h>
+
+#define IS_FRAGMENTED(frag_off) (((frag_off) & IPV4_HDR_OFFSET_MASK) != 0 \
+		|| ((frag_off) & IPV4_HDR_MF_FLAG) == IPV4_HDR_MF_FLAG)
+
+#define TCP_HDR_PSH_MASK ((uint8_t)0x08)
+#define TCP_HDR_FIN_MASK ((uint8_t)0x01)
+
+#define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
+
+/**
+ * Internal function which updates the TCP header of a packet, following
+ * segmentation. This is required to update the header's 'sent' sequence
+ * number, and also to clear 'PSH' and 'FIN' flags for non-tail segments.
+ *
+ * @param pkt
+ *  The packet containing the TCP header.
+ * @param l4_offset
+ *  The offset of the TCP header from the start of the packet.
+ * @param sent_seq
+ *  The sent sequence number.
+ * @param non-tail
+ *  Indicates whether or not this is a tail segment.
+ */
+static inline void
+update_tcp_header(struct rte_mbuf *pkt, uint16_t l4_offset, uint32_t sent_seq,
+		uint8_t non_tail)
+{
+	struct tcp_hdr *tcp_hdr;
+
+	tcp_hdr = (struct tcp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			l4_offset);
+	tcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq);
+	if (likely(non_tail))
+		tcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK |
+					TCP_HDR_FIN_MASK));
+}
+
+/**
+ * Internal function which updates the IPv4 header of a packet, following
+ * segmentation. This is required to update the header's 'total_length' field,
+ * to reflect the reduced length of the now-segmented packet. Furthermore, the
+ * header's 'packet_id' field must be updated to reflect the new ID of the
+ * now-segmented packet.
+ *
+ * @param pkt
+ *  The packet containing the IPv4 header.
+ * @param l3_offset
+ *  The offset of the IPv4 header from the start of the packet.
+ * @param id
+ *  The new ID of the packet.
+  */
+static inline void
+update_ipv4_header(struct rte_mbuf *pkt, uint16_t l3_offset, uint16_t id)
+{
+	struct ipv4_hdr *ipv4_hdr;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			l3_offset);
+	ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len - l3_offset);
+	ipv4_hdr->packet_id = rte_cpu_to_be_16(id);
+}
+
+/**
+ * Internal function which divides the input packet into small segments.
+ * Each of the newly-created segments is organized as a two-segment MBUF,
+ * where the first segment is a standard mbuf, which stores a copy of
+ * packet header, and the second is an indirect mbuf which points to a
+ * section of data in the input packet.
+ *
+ * @param pkt
+ *  Packet to segment.
+ * @param pkt_hdr_offset
+ *  Packet header offset, measured in bytes.
+ * @param pyld_unit_size
+ *  The max payload length of a GSO segment.
+ * @param direct_pool
+ *  MBUF pool used for allocating direct buffers for output segments.
+ * @param indirect_pool
+ *  MBUF pool used for allocating indirect buffers for output segments.
+ * @param pkts_out
+ *  Pointer array used to keep the mbuf addresses of output segments. If
+ *  the memory space in pkts_out is insufficient, gso_do_segment() fails
+ *  and returns -EINVAL.
+ * @param nb_pkts_out
+ *  The max number of items that pkts_out can keep.
+ *
+ * @return
+ *  - The number of segments created in the event of success.
+ *  - Return -ENOMEM if run out of memory in MBUF pools.
+ *  - Return -EINVAL for invalid parameters.
+ */
+int gso_do_segment(struct rte_mbuf *pkt,
+		uint16_t pkt_hdr_offset,
+		uint16_t pyld_unit_size,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out);
+#endif
lib/librte_gso/gso_tcp4.c new file +30 -0
new file mode 100644
index 0000000..584a77d
@@ -0,0 +1,106 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

lib/librte_gso/gso_tcp4.c line 40

Quoted 10 lines
lib/librte_gso/gso_tcp4.c new file +10 -0
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "gso_common.h"
+#include "gso_tcp4.h"
+
+static void
+update_ipv4_tcp_headers(struct rte_mbuf *pkt, uint64_t l3_offset,
+		uint8_t ipid_delta, struct rte_mbuf **segs, uint16_t nb_segs)
+{

No need to add "uint64_t l3_offset" as one parameter. We can directly get l3_offset inside update_ipv4_tcp_headers().

Additionally, the type of l3_offset should be "uint16_t" instead of "uint64_t". But if we change the prototype of update_ipv4_tcp_headers(), this issue doesn't need to fix.

Quoted 222 lines
lib/librte_gso/gso_tcp4.c new file +66 -0
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	uint32_t sent_seq;
+	uint16_t id, tail_idx, i;
+	uint16_t l4_offset;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char*) +
+			l3_offset);
+	tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
+	id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
+	tail_idx = nb_segs - 1;
+	l4_offset = l3_offset + pkt->l3_len;
+
+	for (i = 0; i < nb_segs; i++) {
+		update_ipv4_header(segs[i], l3_offset, id);
+		update_tcp_header(segs[i], l4_offset, sent_seq, i < tail_idx);
+		id += ipid_delta;
+		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
+	}
+}
+
+int
+gso_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ipid_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	uint16_t tcp_dl;
+	uint16_t pyld_unit_size, hdr_offset;
+	uint16_t frag_off;
+	int ret;
+
+	/* Don't process the fragmented packet */
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->l2_len);
+	frag_off = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
+	if (unlikely(IS_FRAGMENTED(frag_off))) {
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	/* Don't process the packet without data */
+	tcp_dl = pkt->pkt_len - pkt->l2_len - pkt->l3_len - pkt->l4_len;
+	if (unlikely(tcp_dl == 0)) {
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	hdr_offset = pkt->l2_len + pkt->l3_len + pkt->l4_len;
+	pyld_unit_size = gso_size - hdr_offset;
+
+	/* Segment the payload */
+	ret = gso_do_segment(pkt, hdr_offset, pyld_unit_size, direct_pool,
+			indirect_pool, pkts_out, nb_pkts_out);
+	if (ret > 1) {
+		update_ipv4_tcp_headers(pkt, pkt->l2_len, ipid_delta,
+				pkts_out, ret);
+	}
+
+	return ret;
+}
lib/librte_gso/gso_tcp4.h new file +74 -0
new file mode 100644
index 0000000..1c57441
@@ -0,0 +1,74 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _GSO_TCP4_H_
+#define _GSO_TCP4_H_
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/**
+ * Segment an IPv4/TCP packet. This function doesn't check if the input
+ * packet has correct checksums, and doesn't update checksums for output
+ * GSO segments. Furthermore, it doesn't process IP fragment packets.
+ *
+ * @param pkt
+ *  The packet mbuf to segment.
+ * @param gso_size
+ *  The max length of a GSO segment, measured in bytes.
+ * @param ipid_delta
+ *  The increasing unit of IP ids.
+ * @param direct_pool
+ *  MBUF pool used for allocating direct buffers for output segments.
+ * @param indirect_pool
+ *  MBUF pool used for allocating indirect buffers for output segments.
+ * @param pkts_out
+ *  Pointer array used to store the MBUF addresses of output GSO
+ *  segments, when the function succeeds. If the memory space in
+ *  pkts_out is insufficient, it fails and returns -EINVAL.
+ * @param nb_pkts_out
+ *  The max number of items that 'pkts_out' can keep.
+ *
+ * @return
+ *   - The number of GSO segments filled in pkts_out on success.
+ *   - Return -ENOMEM if run out of memory in MBUF pools.
+ *   - Return -EINVAL for invalid parameters.
+ */
+int gso_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ip_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out);
+#endif
lib/librte_gso/rte_gso.c +49 -3
index b773636..a4fce50 100644
@@ -33,7 +33,12 @@
 
 #include <errno.h>
 
+#include <rte_log.h>
+#include <rte_ethdev.h>
+
 #include "rte_gso.h"
+#include "gso_common.h"
+#include "gso_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -41,12 +46,53 @@
 		struct rte_mbuf **pkts_out,
 		uint16_t nb_pkts_out)
 {
+	struct rte_mempool *direct_pool, *indirect_pool;
+	struct rte_mbuf *pkt_seg;
+	uint64_t ol_flags;
+	uint16_t gso_size;
+	uint8_t ipid_delta;
+	int ret = 1;
+
 	if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
 			nb_pkts_out < 1)
 		return -EINVAL;
 
-	pkt->ol_flags &= (~PKT_TX_TCP_SEG);
-	pkts_out[0] = pkt;
+	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
+				DEV_TX_OFFLOAD_TCP_TSO) !=
+			gso_ctx->gso_types) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	direct_pool = gso_ctx->direct_pool;
+	indirect_pool = gso_ctx->indirect_pool;
+	gso_size = gso_ctx->gso_size;
+	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
+	ol_flags = pkt->ol_flags;
+
+	if (IS_IPV4_TCP(pkt->ol_flags)) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		pkts_out[0] = pkt;
+		RTE_LOG(WARNING, GSO, "Unsupported packet type\n");
+		return 1;
+	}
+
+	if (ret > 1) {
+		pkt_seg = pkt;
+		while (pkt_seg) {
+			rte_mbuf_refcnt_update(pkt_seg, -1);
+			pkt_seg = pkt_seg->next;
+		}
+	} else if (ret < 0) {
+		/* Revert the ol_flags in the event of failure. */
+		pkt->ol_flags = ol_flags;
+	}
 
-	return 1;
+	return ret;
 }
Signature · 1 line
1.9.3
#151 lore raw

Re: [PATCH v5 2/6] gso: add TCP/IPv4 GSO support

Thanks for your comments Jiayu - please find responses inline.

Thanks,
Mark

From: Hu, Jiayu

Quoted 453 lines

Sent: Friday, September 29, 2017 4:13 AM
To: Kavanagh, Mark B <[email protected]>
Cc: [email protected]; Tan, Jianfeng <[email protected]>; Ananyev, Konstantin <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: Re: [PATCH v5 2/6] gso: add TCP/IPv4 GSO support

Hi Mark,

One comment is inline.

Thanks,
Jiayu

Quoted 19 lines · Mark Kavanagh

From: Jiayu Hu <[email protected]>

This patch adds GSO support for TCP/IPv4 packets. Supported packets may include a single VLAN tag. TCP/IPv4 GSO doesn't check if input packets have correct checksums, and doesn't update checksums for output packets (the responsibility for this lies with the application). Additionally, TCP/IPv4 GSO doesn't process IP fragmented packets.

TCP/IPv4 GSO uses two chained MBUFs, one direct MBUF and one indrect MBUF, to organize an output packet. Note that we refer to these two chained MBUFs as a two-segment MBUF. The direct MBUF stores the packet header, while the indirect mbuf simply points to a location within the original packet's payload. Consequently, use of the GSO library requires multi-segment MBUF support in the TX functions of the NIC driver.

If a packet is GSO'd, TCP/IPv4 GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

Quoted 8 lines
---
 doc/guides/rel_notes/release_17_11.rst  |  12 +++
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 153

++++++++++++++++++++++++++++++++

Review

Quoted 11 lines
 lib/librte_gso/gso_common.h             | 141 +++++++++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.c               | 106 ++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.h               |  74 +++++++++++++++
 lib/librte_gso/rte_gso.c                |  52 ++++++++++-
 8 files changed, 538 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
(quoted diff) +0 -0

b/doc/guides/rel_notes/release_17_11.rst

Review

Quoted 23 lines

index 7508be7..c414f73 100644

doc/guides/rel_notes/release_17_11.rst +12 -0
@@ -41,6 +41,18 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Added the Generic Segmentation Offload Library.**
+
+  Added the Generic Segmentation Offload (GSO) library to enable
+  applications to split large packets (e.g. MTU is 64KB) into small
+  ones (e.g. MTU is 1500B). Supported packet types are:
+
+  * TCP/IPv4 packets, which may include a single VLAN tag.
+
+  The GSO library doesn't check if the input packets have correct
+  checksums, and doesn't update checksums for output packets.
+  Additionally, the GSO library doesn't process IP fragmented packets.
+
 
 Resolved Issues
 ---------------
(quoted diff) +0 -0

b/lib/librte_eal/common/include/rte_log.h

Quoted 246 lines

index ec8dba7..2fa1199 100644

lib/librte_eal/common/include/rte_log.h +1 -0
@@ -87,6 +87,7 @@ struct rte_logs {
 #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
 #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
 #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
+#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
 
 /* these log types can be used in an application */
 #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
lib/librte_gso/Makefile +2 -0
index aeaacbc..2be64d1 100644
@@ -42,6 +42,8 @@ LIBABIVER := 1
 
 #source files
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c new file +153 -0
new file mode 100644
index 0000000..ee75d4c
@@ -0,0 +1,153 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdbool.h>
+#include <errno.h>
+
+#include <rte_memcpy.h>
+#include <rte_mempool.h>
+
+#include "gso_common.h"
+
+static inline void
+hdr_segment_init(struct rte_mbuf *hdr_segment, struct rte_mbuf *pkt,
+		uint16_t pkt_hdr_offset)
+{
+	/* Copy MBUF metadata */
+	hdr_segment->nb_segs = 1;
+	hdr_segment->port = pkt->port;
+	hdr_segment->ol_flags = pkt->ol_flags;
+	hdr_segment->packet_type = pkt->packet_type;
+	hdr_segment->pkt_len = pkt_hdr_offset;
+	hdr_segment->data_len = pkt_hdr_offset;
+	hdr_segment->tx_offload = pkt->tx_offload;
+
+	/* Copy the packet header */
+	rte_memcpy(rte_pktmbuf_mtod(hdr_segment, char *),
+			rte_pktmbuf_mtod(pkt, char *),
+			pkt_hdr_offset);
+}
+
+static inline void
+free_gso_segment(struct rte_mbuf **pkts, uint16_t nb_pkts)
+{
+	uint16_t i;
+
+	for (i = 0; i < nb_pkts; i++)
+		rte_pktmbuf_free(pkts[i]);
+}
+
+int
+gso_do_segment(struct rte_mbuf *pkt,
+		uint16_t pkt_hdr_offset,
+		uint16_t pyld_unit_size,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct rte_mbuf *pkt_in;
+	struct rte_mbuf *hdr_segment, *pyld_segment, *prev_segment;
+	uint16_t pkt_in_data_pos, segment_bytes_remaining;
+	uint16_t pyld_len, nb_segs;
+	bool more_in_pkt, more_out_segs;
+
+	pkt_in = pkt;
+	nb_segs = 0;
+	more_in_pkt = 1;
+	pkt_in_data_pos = pkt_hdr_offset;
+
+	while (more_in_pkt) {
+		if (unlikely(nb_segs >= nb_pkts_out)) {
+			free_gso_segment(pkts_out, nb_segs);
+			return -EINVAL;
+		}
+
+		/* Allocate a direct MBUF */
+		hdr_segment = rte_pktmbuf_alloc(direct_pool);
+		if (unlikely(hdr_segment == NULL)) {
+			free_gso_segment(pkts_out, nb_segs);
+			return -ENOMEM;
+		}
+		/* Fill the packet header */
+		hdr_segment_init(hdr_segment, pkt, pkt_hdr_offset);
+
+		prev_segment = hdr_segment;
+		segment_bytes_remaining = pyld_unit_size;
+		more_out_segs = 1;
+
+		while (more_out_segs && more_in_pkt) {
+			/* Allocate an indirect MBUF */
+			pyld_segment = rte_pktmbuf_alloc(indirect_pool);
+			if (unlikely(pyld_segment == NULL)) {
+				rte_pktmbuf_free(hdr_segment);
+				free_gso_segment(pkts_out, nb_segs);
+				return -ENOMEM;
+			}
+			/* Attach to current MBUF segment of pkt */
+			rte_pktmbuf_attach(pyld_segment, pkt_in);
+
+			prev_segment->next = pyld_segment;
+			prev_segment = pyld_segment;
+
+			pyld_len = segment_bytes_remaining;
+			if (pyld_len + pkt_in_data_pos > pkt_in->data_len)
+				pyld_len = pkt_in->data_len - pkt_in_data_pos;
+
+			pyld_segment->data_off = pkt_in_data_pos +
+				pkt_in->data_off;
+			pyld_segment->data_len = pyld_len;
+
+			/* Update header segment */
+			hdr_segment->pkt_len += pyld_len;
+			hdr_segment->nb_segs++;
+
+			pkt_in_data_pos += pyld_len;
+			segment_bytes_remaining -= pyld_len;
+
+			/* Finish processing a MBUF segment of pkt */
+			if (pkt_in_data_pos == pkt_in->data_len) {
+				pkt_in = pkt_in->next;
+				pkt_in_data_pos = 0;
+				if (pkt_in == NULL)
+					more_in_pkt = 0;
+			}
+
+			/* Finish generating a GSO segment */
+			if (segment_bytes_remaining == 0)
+				more_out_segs = 0;
+		}
+		pkts_out[nb_segs++] = hdr_segment;
+	}
+	return nb_segs;
+}
lib/librte_gso/gso_common.h new file +57 -0
new file mode 100644
index 0000000..8d9b94e
@@ -0,0 +1,141 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _GSO_COMMON_H_
+#define _GSO_COMMON_H_
+
+#include <stdint.h>
+
+#include <rte_mbuf.h>
+#include <rte_ip.h>
+#include <rte_tcp.h>
+
+#define IS_FRAGMENTED(frag_off) (((frag_off) & IPV4_HDR_OFFSET_MASK) != 0 \
+		|| ((frag_off) & IPV4_HDR_MF_FLAG) == IPV4_HDR_MF_FLAG)
+
+#define TCP_HDR_PSH_MASK ((uint8_t)0x08)
+#define TCP_HDR_FIN_MASK ((uint8_t)0x01)
+
+#define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
+
+/**
+ * Internal function which updates the TCP header of a packet, following
+ * segmentation. This is required to update the header's 'sent' sequence
+ * number, and also to clear 'PSH' and 'FIN' flags for non-tail segments.
+ *
+ * @param pkt

lib/librte_gso/gso_common.h line 67

Quoted 10 lines
lib/librte_gso/gso_common.h new file +10 -0
+ *  The packet containing the TCP header.
+ * @param l4_offset
+ *  The offset of the TCP header from the start of the packet.
+ * @param sent_seq
+ *  The sent sequence number.
+ * @param non-tail
+ *  Indicates whether or not this is a tail segment.
+ */
+static inline void
+update_tcp_header(struct rte_mbuf *pkt, uint16_t l4_offset, uint32_t

sent_seq,

Quoted 5 lines
lib/librte_gso/gso_common.h new file +5 -0
+		uint8_t non_tail)
+{
+	struct tcp_hdr *tcp_hdr;
+
+	tcp_hdr = (struct tcp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +

lib/librte_gso/gso_common.h

Quoted 10 lines
lib/librte_gso/gso_common.h new file +10 -0
+			l4_offset);
+	tcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq);
+	if (likely(non_tail))
+		tcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK |
+					TCP_HDR_FIN_MASK));
+}
+
+/**
+ * Internal function which updates the IPv4 header of a packet, following
+ * segmentation. This is required to update the header's 'total_length'

field,

lib/librte_gso/gso_common.h line 83

Quoted 1 line
lib/librte_gso/gso_common.h new file +1 -0
+ * to reflect the reduced length of the now-segmented packet. Furthermore,

the

Quoted 99 lines
lib/librte_gso/gso_common.h new file +58 -0
+ * header's 'packet_id' field must be updated to reflect the new ID of the
+ * now-segmented packet.
+ *
+ * @param pkt
+ *  The packet containing the IPv4 header.
+ * @param l3_offset
+ *  The offset of the IPv4 header from the start of the packet.
+ * @param id
+ *  The new ID of the packet.
+  */
+static inline void
+update_ipv4_header(struct rte_mbuf *pkt, uint16_t l3_offset, uint16_t id)
+{
+	struct ipv4_hdr *ipv4_hdr;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			l3_offset);
+	ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len - l3_offset);
+	ipv4_hdr->packet_id = rte_cpu_to_be_16(id);
+}
+
+/**
+ * Internal function which divides the input packet into small segments.
+ * Each of the newly-created segments is organized as a two-segment MBUF,
+ * where the first segment is a standard mbuf, which stores a copy of
+ * packet header, and the second is an indirect mbuf which points to a
+ * section of data in the input packet.
+ *
+ * @param pkt
+ *  Packet to segment.
+ * @param pkt_hdr_offset
+ *  Packet header offset, measured in bytes.
+ * @param pyld_unit_size
+ *  The max payload length of a GSO segment.
+ * @param direct_pool
+ *  MBUF pool used for allocating direct buffers for output segments.
+ * @param indirect_pool
+ *  MBUF pool used for allocating indirect buffers for output segments.
+ * @param pkts_out
+ *  Pointer array used to keep the mbuf addresses of output segments. If
+ *  the memory space in pkts_out is insufficient, gso_do_segment() fails
+ *  and returns -EINVAL.
+ * @param nb_pkts_out
+ *  The max number of items that pkts_out can keep.
+ *
+ * @return
+ *  - The number of segments created in the event of success.
+ *  - Return -ENOMEM if run out of memory in MBUF pools.
+ *  - Return -EINVAL for invalid parameters.
+ */
+int gso_do_segment(struct rte_mbuf *pkt,
+		uint16_t pkt_hdr_offset,
+		uint16_t pyld_unit_size,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out);
+#endif
lib/librte_gso/gso_tcp4.c new file +35 -0
new file mode 100644
index 0000000..584a77d
@@ -0,0 +1,106 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "gso_common.h"
+#include "gso_tcp4.h"
Quoted 8 lines

lib/librte_gso/gso_tcp4.c line 40

Quoted 5 lines
lib/librte_gso/gso_tcp4.c new file +5 -0
+
+static void
+update_ipv4_tcp_headers(struct rte_mbuf *pkt, uint64_t l3_offset,
+		uint8_t ipid_delta, struct rte_mbuf **segs, uint16_t nb_segs)
+{

No need to add "uint64_t l3_offset" as one parameter. We can directly get l3_offset inside update_ipv4_tcp_headers().

Yes, of course - thanks Jiayu.

Quoted 3 lines

Additionally, the type of l3_offset should be "uint16_t" instead of "uint64_t".

That is a rebase artifact - please disregard.

Quoted 3 lines

But if we change the prototype of update_ipv4_tcp_headers(), this issue doesn't
need to fix.

Agreed.

Quoted 223 lines
Quoted 223 lines
lib/librte_gso/gso_tcp4.c new file +66 -0
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	uint32_t sent_seq;
+	uint16_t id, tail_idx, i;
+	uint16_t l4_offset;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char*) +
+			l3_offset);
+	tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
+	id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
+	tail_idx = nb_segs - 1;
+	l4_offset = l3_offset + pkt->l3_len;
+
+	for (i = 0; i < nb_segs; i++) {
+		update_ipv4_header(segs[i], l3_offset, id);
+		update_tcp_header(segs[i], l4_offset, sent_seq, i < tail_idx);
+		id += ipid_delta;
+		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
+	}
+}
+
+int
+gso_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ipid_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	uint16_t tcp_dl;
+	uint16_t pyld_unit_size, hdr_offset;
+	uint16_t frag_off;
+	int ret;
+
+	/* Don't process the fragmented packet */
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->l2_len);
+	frag_off = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
+	if (unlikely(IS_FRAGMENTED(frag_off))) {
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	/* Don't process the packet without data */
+	tcp_dl = pkt->pkt_len - pkt->l2_len - pkt->l3_len - pkt->l4_len;
+	if (unlikely(tcp_dl == 0)) {
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	hdr_offset = pkt->l2_len + pkt->l3_len + pkt->l4_len;
+	pyld_unit_size = gso_size - hdr_offset;
+
+	/* Segment the payload */
+	ret = gso_do_segment(pkt, hdr_offset, pyld_unit_size, direct_pool,
+			indirect_pool, pkts_out, nb_pkts_out);
+	if (ret > 1) {
+		update_ipv4_tcp_headers(pkt, pkt->l2_len, ipid_delta,
+				pkts_out, ret);
+	}
+
+	return ret;
+}
lib/librte_gso/gso_tcp4.h new file +74 -0
new file mode 100644
index 0000000..1c57441
@@ -0,0 +1,74 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _GSO_TCP4_H_
+#define _GSO_TCP4_H_
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/**
+ * Segment an IPv4/TCP packet. This function doesn't check if the input
+ * packet has correct checksums, and doesn't update checksums for output
+ * GSO segments. Furthermore, it doesn't process IP fragment packets.
+ *
+ * @param pkt
+ *  The packet mbuf to segment.
+ * @param gso_size
+ *  The max length of a GSO segment, measured in bytes.
+ * @param ipid_delta
+ *  The increasing unit of IP ids.
+ * @param direct_pool
+ *  MBUF pool used for allocating direct buffers for output segments.
+ * @param indirect_pool
+ *  MBUF pool used for allocating indirect buffers for output segments.
+ * @param pkts_out
+ *  Pointer array used to store the MBUF addresses of output GSO
+ *  segments, when the function succeeds. If the memory space in
+ *  pkts_out is insufficient, it fails and returns -EINVAL.
+ * @param nb_pkts_out
+ *  The max number of items that 'pkts_out' can keep.
+ *
+ * @return
+ *   - The number of GSO segments filled in pkts_out on success.
+ *   - Return -ENOMEM if run out of memory in MBUF pools.
+ *   - Return -EINVAL for invalid parameters.
+ */
+int gso_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ip_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out);
+#endif
lib/librte_gso/rte_gso.c +49 -4
index b773636..a4fce50 100644
@@ -33,7 +33,12 @@
 
 #include <errno.h>
 
+#include <rte_log.h>
+#include <rte_ethdev.h>
+
 #include "rte_gso.h"
+#include "gso_common.h"
+#include "gso_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -41,12 +46,53 @@
 		struct rte_mbuf **pkts_out,
 		uint16_t nb_pkts_out)
 {
+	struct rte_mempool *direct_pool, *indirect_pool;
+	struct rte_mbuf *pkt_seg;
+	uint64_t ol_flags;
+	uint16_t gso_size;
+	uint8_t ipid_delta;
+	int ret = 1;
+
 	if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
 			nb_pkts_out < 1)
 		return -EINVAL;
 
-	pkt->ol_flags &= (~PKT_TX_TCP_SEG);
-	pkts_out[0] = pkt;
+	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
+				DEV_TX_OFFLOAD_TCP_TSO) !=
+			gso_ctx->gso_types) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	direct_pool = gso_ctx->direct_pool;
+	indirect_pool = gso_ctx->indirect_pool;
+	gso_size = gso_ctx->gso_size;
+	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
+	ol_flags = pkt->ol_flags;
+
+	if (IS_IPV4_TCP(pkt->ol_flags)) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		pkts_out[0] = pkt;
+		RTE_LOG(WARNING, GSO, "Unsupported packet type\n");
+		return 1;
+	}
+
+	if (ret > 1) {
+		pkt_seg = pkt;
+		while (pkt_seg) {
+			rte_mbuf_refcnt_update(pkt_seg, -1);
+			pkt_seg = pkt_seg->next;
+		}
+	} else if (ret < 0) {
+		/* Revert the ol_flags in the event of failure. */
+		pkt->ol_flags = ol_flags;
+	}
 
-	return 1;
+	return ret;
 }
--

1.9.3

#152 lore raw

PATCH v5 2/6 gso: add TCP/IPv4 GSO support

In reply to Jiayu Hu

From: Jiayu Hu <[email protected]>

This patch adds GSO support for TCP/IPv4 packets. Supported packets may include a single VLAN tag. TCP/IPv4 GSO doesn't check if input packets have correct checksums, and doesn't update checksums for output packets (the responsibility for this lies with the application). Additionally, TCP/IPv4 GSO doesn't process IP fragmented packets.

TCP/IPv4 GSO uses two chained MBUFs, one direct MBUF and one indrect MBUF, to organize an output packet. Note that we refer to these two chained MBUFs as a two-segment MBUF. The direct MBUF stores the packet header, while the indirect mbuf simply points to a location within the original packet's payload. Consequently, use of the GSO library requires multi-segment MBUF support in the TX functions of the NIC driver.

If a packet is GSO'd, TCP/IPv4 GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst  |  12 +++
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 153 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 141 +++++++++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.c               | 106 ++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.h               |  74 +++++++++++++++
 lib/librte_gso/rte_gso.c                |  52 ++++++++++-
 8 files changed, 538 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
doc/guides/rel_notes/release_17_11.rst +12 -0
index 7508be7..c414f73 100644
@@ -41,6 +41,18 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Added the Generic Segmentation Offload Library.**
+
+  Added the Generic Segmentation Offload (GSO) library to enable
+  applications to split large packets (e.g. MTU is 64KB) into small
+  ones (e.g. MTU is 1500B). Supported packet types are:
+
+  * TCP/IPv4 packets, which may include a single VLAN tag.
+
+  The GSO library doesn't check if the input packets have correct
+  checksums, and doesn't update checksums for output packets.
+  Additionally, the GSO library doesn't process IP fragmented packets.
+
 
 Resolved Issues
 ---------------
lib/librte_eal/common/include/rte_log.h +1 -0
index ec8dba7..2fa1199 100644
@@ -87,6 +87,7 @@ struct rte_logs {
 #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
 #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
 #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
+#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
 
 /* these log types can be used in an application */
 #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
lib/librte_gso/Makefile +2 -0
index aeaacbc..2be64d1 100644
@@ -42,6 +42,8 @@ LIBABIVER := 1
 
 #source files
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c new file +153 -0

153 lines not on this page · raw message

lib/librte_gso/gso_common.h new file +141 -0

141 lines not on this page · raw message

lib/librte_gso/gso_tcp4.c new file +106 -0

106 lines not on this page · raw message

lib/librte_gso/gso_tcp4.h new file +74 -0

74 lines not on this page · raw message

lib/librte_gso/rte_gso.c +49 -3

68 lines not on this page · raw message

Signature · 1 line
1.9.3
#153 lore raw

PATCH v5 3/6 gso: add VxLAN GSO support

In reply to Jiayu Hu

This patch adds a framework that allows GSO on tunneled packets. Furthermore, it leverages that framework to provide GSO support for VxLAN-encapsulated packets.

Supported VxLAN packets must have an outer IPv4 header (prepended by an optional VLAN tag), and contain an inner TCP/IPv4 packet (with an optional inner VLAN tag).

VxLAN GSO doesn't check if input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with TCP/IPv4 GSO, VxLAN GSO uses a two-segment MBUF to organize each output packet, which mandates support for multi-segment mbufs in the TX functions of the NIC driver. Also, if a packet is GSOed, VxLAN GSO reduces its MBUF refcnt by 1. As a result, when all of its GSO'd segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst |   3 +
 lib/librte_gso/Makefile                |   1 +
 lib/librte_gso/gso_common.h            |  25 +++++++
 lib/librte_gso/gso_tcp4.c              |   2 +-
 lib/librte_gso/gso_tunnel_tcp4.c       | 123 +++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_tunnel_tcp4.h       |  75 ++++++++++++++++++++
 lib/librte_gso/rte_gso.c               |  13 +++-
 7 files changed, 238 insertions(+), 4 deletions(-)
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
doc/guides/rel_notes/release_17_11.rst +3 -0
index c414f73..25b8a78 100644
@@ -48,6 +48,9 @@ New Features
   ones (e.g. MTU is 1500B). Supported packet types are:
 
   * TCP/IPv4 packets, which may include a single VLAN tag.
+  * VxLAN packets, which must have an outer IPv4 header (prepended by
+    an optional VLAN tag), and contain an inner TCP/IPv4 packet (with
+    an optional VLAN tag).
 
   The GSO library doesn't check if the input packets have correct
   checksums, and doesn't update checksums for output packets.
lib/librte_gso/Makefile +1 -0
index 2be64d1..e6d41df 100644
@@ -44,6 +44,7 @@ LIBABIVER := 1
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tunnel_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.h +25 -0
index 8d9b94e..c051295 100644
@@ -39,6 +39,7 @@
 #include <rte_mbuf.h>
 #include <rte_ip.h>
 #include <rte_tcp.h>
+#include <rte_udp.h>
 
 #define IS_FRAGMENTED(frag_off) (((frag_off) & IPV4_HDR_OFFSET_MASK) != 0 \
 		|| ((frag_off) & IPV4_HDR_MF_FLAG) == IPV4_HDR_MF_FLAG)
@@ -49,6 +50,30 @@
 #define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
 		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
 
+#define IS_IPV4_VXLAN_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_VXLAN))
+
+/**
+ * Internal function which updates the UDP header of a packet, following
+ * segmentation. This is required to update the header's datagram length field.
+ *
+ * @param pkt
+ *  The packet containing the UDP header.
+ * @param udp_offset
+ *  The offset of the UDP header from the start of the packet.
+ */
+static inline void
+update_udp_header(struct rte_mbuf *pkt, uint16_t udp_offset)
+{
+	struct udp_hdr *udp_hdr;
+
+	udp_hdr = (struct udp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			udp_offset);
+	udp_hdr->dgram_len = rte_cpu_to_be_16(pkt->pkt_len - udp_offset);
+}
+
 /**
  * Internal function which updates the TCP header of a packet, following
  * segmentation. This is required to update the header's 'sent' sequence
lib/librte_gso/gso_tcp4.c +1 -1
index 584a77d..fe0b7dd 100644
@@ -35,7 +35,7 @@
 #include "gso_tcp4.h"
 
 static void
-update_ipv4_tcp_headers(struct rte_mbuf *pkt, uint64_t l3_offset,
+update_ipv4_tcp_headers(struct rte_mbuf *pkt, uint16_t l3_offset,
 		uint8_t ipid_delta, struct rte_mbuf **segs, uint16_t nb_segs)
 {
 	struct ipv4_hdr *ipv4_hdr;
lib/librte_gso/gso_tunnel_tcp4.c new file +123 -0

123 lines not on this page · raw message

lib/librte_gso/gso_tunnel_tcp4.h new file +75 -0

75 lines not on this page · raw message

lib/librte_gso/rte_gso.c +10 -3
index a4fce50..6095689 100644
@@ -39,6 +39,7 @@
 #include "rte_gso.h"
 #include "gso_common.h"
 #include "gso_tcp4.h"
+#include "gso_tunnel_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -58,8 +59,9 @@
 		return -EINVAL;
 
 	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
-				DEV_TX_OFFLOAD_TCP_TSO) !=
-			gso_ctx->gso_types) {
+				(DEV_TX_OFFLOAD_TCP_TSO |
+				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) !=
+				gso_ctx->gso_types) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		pkts_out[0] = pkt;
 		return 1;
@@ -71,7 +73,12 @@
 	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_TCP(pkt->ol_flags)) {
+	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else if (IS_IPV4_TCP(pkt->ol_flags)) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
Signature · 1 line
1.9.3
#154 lore raw

PATCH v5 4/6 gso: add GRE GSO support

In reply to Jiayu Hu

This patch adds GSO support for GRE-tunneled packets. Supported GRE packets must contain an outer IPv4 header, and inner TCP/IPv4 headers. They may also contain a single VLAN tag. GRE GSO doesn't check if all input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with VxLAN GSO, GRE GSO uses a two-segment MBUF to organize each output packet, which requires multi-segment mbuf support in the TX functions of the NIC driver. Also, if a packet is GSOed, GRE GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst |  3 +++
 lib/librte_gso/gso_common.h            |  5 +++++
 lib/librte_gso/gso_tunnel_tcp4.c       | 14 ++++++++++----
 lib/librte_gso/rte_gso.c               |  8 +++++---
 4 files changed, 23 insertions(+), 7 deletions(-)
doc/guides/rel_notes/release_17_11.rst +3 -0
index 25b8a78..808f537 100644
@@ -51,6 +51,9 @@ New Features
   * VxLAN packets, which must have an outer IPv4 header (prepended by
     an optional VLAN tag), and contain an inner TCP/IPv4 packet (with
     an optional VLAN tag).
+  * GRE packets, which must contain an outer IPv4 header (prepended by
+    an optional VLAN tag), and inner TCP/IPv4 headers (with an optional
+    VLAN tag).
 
   The GSO library doesn't check if the input packets have correct
   checksums, and doesn't update checksums for output packets.
lib/librte_gso/gso_common.h +5 -0
index c051295..1e99cc0 100644
@@ -55,6 +55,11 @@
 		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
 		 PKT_TX_TUNNEL_VXLAN))
 
+#define IS_IPV4_GRE_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_GRE)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_GRE))
+
 /**
  * Internal function which updates the UDP header of a packet, following
  * segmentation. This is required to update the header's datagram length field.
lib/librte_gso/gso_tunnel_tcp4.c +10 -4
index 34bbbd7..d79fc6b 100644
@@ -42,11 +42,13 @@
 	struct tcp_hdr *tcp_hdr;
 	uint32_t sent_seq;
 	uint16_t outer_id, inner_id, tail_idx, i;
-	uint16_t outer_ipv4_offset, inner_ipv4_offset, udp_offset, tcp_offset;
+	uint16_t outer_ipv4_offset, inner_ipv4_offset;
+	uint16_t udp_gre_offset, tcp_offset;
+	uint8_t update_udp_hdr;
 
 	outer_ipv4_offset = pkt->outer_l2_len;
-	udp_offset = outer_ipv4_offset + pkt->outer_l3_len;
-	inner_ipv4_offset = udp_offset + pkt->l2_len;
+	udp_gre_offset = outer_ipv4_offset + pkt->outer_l3_len;
+	inner_ipv4_offset = udp_gre_offset + pkt->l2_len;
 	tcp_offset = inner_ipv4_offset + pkt->l3_len;
 
 	/* Outer IPv4 header. */
@@ -63,9 +65,13 @@
 	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
 	tail_idx = nb_segs - 1;
 
+	/* Only update UDP header for VxLAN packets. */
+	update_udp_hdr = (pkt->ol_flags & PKT_TX_TUNNEL_VXLAN) ? 1 : 0;
+
 	for (i = 0; i < nb_segs; i++) {
 		update_ipv4_header(segs[i], outer_ipv4_offset, outer_id);
-		update_udp_header(segs[i], udp_offset);
+		if (update_udp_hdr)
+			update_udp_header(segs[i], udp_gre_offset);
 		update_ipv4_header(segs[i], inner_ipv4_offset, inner_id);
 		update_tcp_header(segs[i], tcp_offset, sent_seq, i < tail_idx);
 		outer_id++;
lib/librte_gso/rte_gso.c +5 -3
index 6095689..b748ab1 100644
@@ -60,8 +60,9 @@
 
 	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
 				(DEV_TX_OFFLOAD_TCP_TSO |
-				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) !=
-				gso_ctx->gso_types) {
+				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+				 DEV_TX_OFFLOAD_GRE_TNL_TSO)) !=
+				 gso_ctx->gso_types) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		pkts_out[0] = pkt;
 		return 1;
@@ -73,7 +74,8 @@
 	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)) {
+	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags) ||
+			IS_IPV4_GRE_TCP4(pkt->ol_flags)) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
Signature · 1 line
1.9.3
#155 lore raw

PATCH v5 5/6 app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

In reply to Jiayu Hu

From: Jiayu Hu <[email protected]>

This patch adds GSO support to the csum forwarding engine. Oversized packets transmitted over a GSO-enabled port will undergo segmentation (with the exception of packet-types unsupported by the GSO library). GSO support is disabled by default.

GSO support may be toggled on a per-port basis, using the command:

"set port <port_id> gso on|off"

The maximum packet length (including the packet header and payload) for GSO segments may be set with the command:

"set gso segsz <length>"

Show GSO configuration for a given port with the command:

"show port <port_id> gso"

---
 app/test-pmd/cmdline.c                      | 178 ++++++++++++++++++++++++++++
 app/test-pmd/config.c                       |  24 ++++
 app/test-pmd/csumonly.c                     |  69 ++++++++++-
 app/test-pmd/testpmd.c                      |  13 ++
 app/test-pmd/testpmd.h                      |  10 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  46 +++++++
 6 files changed, 335 insertions(+), 5 deletions(-)
app/test-pmd/cmdline.c +178 -0
index ccdf239..05b0ce8 100644
@@ -431,6 +431,17 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"    Set max flow number and max packet number per-flow"
 			" for GRO.\n\n"
 
+			"set port (port_id) gso (on|off)"
+			"    Enable or disable Generic Segmentation Offload in"
+			" csum forwarding engine.\n\n"
+
+			"set gso segsz (length)\n"
+			"    Set max packet length for output GSO segments,"
+			" including packet header and payload.\n\n"
+
+			"show port (port_id) gso\n"
+			"    Show GSO configuration.\n\n"
+
 			"set fwd (%s)\n"
 			"    Set packet forwarding mode.\n\n"
 
@@ -3967,6 +3978,170 @@ struct cmd_gro_set_result {
 	},
 };
 
+/* *** ENABLE/DISABLE GSO *** */
+struct cmd_gso_enable_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_mode;
+	uint8_t cmd_pid;
+};
+
+static void
+cmd_gso_enable_parsed(void *parsed_result,
+		__attribute__((unused)) struct cmdline *cl,
+		__attribute__((unused)) void *data)
+{
+	struct cmd_gso_enable_result *res;
+
+	res = parsed_result;
+	if (!strcmp(res->cmd_keyword, "gso"))
+		setup_gso(res->cmd_mode, res->cmd_pid);
+}
+
+cmdline_parse_token_string_t cmd_gso_enable_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_enable_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_enable_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_enable_mode =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_mode, "on#off");
+cmdline_parse_token_num_t cmd_gso_enable_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_enable = {
+	.f = cmd_gso_enable_parsed,
+	.data = NULL,
+	.help_str = "set port <port_id> gso on|off",
+	.tokens = {
+		(void *)&cmd_gso_enable_set,
+		(void *)&cmd_gso_enable_port,
+		(void *)&cmd_gso_enable_pid,
+		(void *)&cmd_gso_enable_keyword,
+		(void *)&cmd_gso_enable_mode,
+		NULL,
+	},
+};
+
+/* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
+struct cmd_gso_size_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_segsz;
+	uint16_t cmd_size;
+};
+
+static void
+cmd_gso_size_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_size_result *res = parsed_result;
+
+	if (test_done == 0) {
+		printf("Before setting GSO segsz, please first stop fowarding\n");
+		return;
+	}
+
+	if (!strcmp(res->cmd_keyword, "gso") &&
+			!strcmp(res->cmd_segsz, "segsz")) {
+		if (res->cmd_size == 0) {
+			printf("gso_size should be larger than 0."
+					" Please input a legal value\n");
+		} else
+			gso_max_segment_size = res->cmd_size;
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_size_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_size_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_size_segsz =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_segsz, "segsz");
+cmdline_parse_token_num_t cmd_gso_size_size =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
+				cmd_size, UINT16);
+
+cmdline_parse_inst_t cmd_gso_size = {
+	.f = cmd_gso_size_parsed,
+	.data = NULL,
+	.help_str = "set gso segsz <length>",
+	.tokens = {
+		(void *)&cmd_gso_size_set,
+		(void *)&cmd_gso_size_keyword,
+		(void *)&cmd_gso_size_segsz,
+		(void *)&cmd_gso_size_size,
+		NULL,
+	},
+};
+
+/* *** SHOW GSO CONFIGURATION *** */
+struct cmd_gso_show_result {
+	cmdline_fixed_string_t cmd_show;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	uint8_t cmd_pid;
+};
+
+static void
+cmd_gso_show_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_show_result *res = parsed_result;
+
+	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
+		printf("invalid port id %u\n", res->cmd_pid);
+		return;
+	}
+	if (!strcmp(res->cmd_keyword, "gso")) {
+		if (gso_ports[res->cmd_pid].enable) {
+			printf("Max GSO'd packet size: %uB\n"
+					"Supported GSO types: TCP/IPv4, "
+					"VxLAN with inner TCP/IPv4 packet, "
+					"GRE with inner TCP/IPv4  packet\n",
+					gso_max_segment_size);
+		} else
+			printf("GSO is not enabled on Port %u\n", res->cmd_pid);
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_show_show =
+TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+		cmd_show, "show");
+cmdline_parse_token_string_t cmd_gso_show_port =
+TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+		cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_show_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_num_t cmd_gso_show_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
+				cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_show = {
+	.f = cmd_gso_show_parsed,
+	.data = NULL,
+	.help_str = "show port <port_id> gso",
+	.tokens = {
+		(void *)&cmd_gso_show_show,
+		(void *)&cmd_gso_show_port,
+		(void *)&cmd_gso_show_pid,
+		(void *)&cmd_gso_show_keyword,
+		NULL,
+	},
+};
+
 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
 struct cmd_set_flush_rx {
 	cmdline_fixed_string_t set;
@@ -14255,6 +14430,9 @@ struct cmd_cmdfile_result {
 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
 	(cmdline_parse_inst_t *)&cmd_enable_gro,
 	(cmdline_parse_inst_t *)&cmd_gro_set,
+	(cmdline_parse_inst_t *)&cmd_gso_enable,
+	(cmdline_parse_inst_t *)&cmd_gso_size,
+	(cmdline_parse_inst_t *)&cmd_gso_show,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
app/test-pmd/config.c +24 -0
index 3ae3e1c..88d09d0 100644
@@ -2454,6 +2454,30 @@ struct igb_ring_desc_16_bytes {
 	}
 }
 
+void
+setup_gso(const char *mode, uint8_t port_id)
+{
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		printf("invalid port id %u\n", port_id);
+		return;
+	}
+	if (strcmp(mode, "on") == 0) {
+		if (test_done == 0) {
+			printf("before enabling GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 1;
+	} else if (strcmp(mode, "off") == 0) {
+		if (test_done == 0) {
+			printf("before disabling GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 0;
+	}
+}
+
 char*
 list_pkt_forwarding_modes(void)
 {
app/test-pmd/csumonly.c +64 -5

136 lines not on this page · raw message

app/test-pmd/testpmd.c +13 -0
index e097ee0..97e349d 100644
@@ -400,6 +400,9 @@ static int eth_event_callback(uint8_t port_id,
  */
 static int all_ports_started(void);
 
+struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+uint16_t gso_max_segment_size = ETHER_MAX_LEN - ETHER_CRC_LEN;
+
 /*
  * Helper function to check if socket is already discovered.
  * If yes, return positive value. If not, return zero.
@@ -570,6 +573,7 @@ static int eth_event_callback(uint8_t port_id,
 	unsigned int nb_mbuf_per_pool;
 	lcoreid_t  lc_id;
 	uint8_t port_per_socket[RTE_MAX_NUMA_NODES];
+	uint32_t gso_types = 0;
 
 	memset(port_per_socket,0,RTE_MAX_NUMA_NODES);
 
@@ -654,6 +658,8 @@ static int eth_event_callback(uint8_t port_id,
 
 	init_port_config();
 
+	gso_types = DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+		DEV_TX_OFFLOAD_GRE_TNL_TSO;
 	/*
 	 * Records which Mbuf pool to use by each logical core, if needed.
 	 */
@@ -664,6 +670,13 @@ static int eth_event_callback(uint8_t port_id,
 		if (mbp == NULL)
 			mbp = mbuf_pool_find(0);
 		fwd_lcores[lc_id]->mbp = mbp;
+		/* initialize GSO context */
+		fwd_lcores[lc_id]->gso_ctx.direct_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.indirect_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.gso_types = gso_types;
+		fwd_lcores[lc_id]->gso_ctx.gso_size = ETHER_MAX_LEN -
+			ETHER_CRC_LEN;
+		fwd_lcores[lc_id]->gso_ctx.ipid_flag = !RTE_GSO_IPID_FIXED;
 	}
 
 	/* Configuration of packet forwarding streams. */
app/test-pmd/testpmd.h +10 -0
index 1d1ee75..ff842a1 100644
@@ -36,6 +36,7 @@
 
 #include <rte_pci.h>
 #include <rte_gro.h>
+#include <rte_gso.h>
 
 #define RTE_PORT_ALL            (~(portid_t)0x0)
 
@@ -205,6 +206,7 @@ struct rte_port {
  * CPU id. configuration table.
  */
 struct fwd_lcore {
+	struct rte_gso_ctx gso_ctx;     /**< GSO context */
 	struct rte_mempool *mbp; /**< The mbuf pool to use by this core */
 	streamid_t stream_idx;   /**< index of 1st stream in "fwd_streams" */
 	streamid_t stream_nb;    /**< number of streams in "fwd_streams" */
@@ -442,6 +444,13 @@ struct gro_status {
 };
 extern struct gro_status gro_ports[RTE_MAX_ETHPORTS];
 
+#define GSO_MAX_PKT_BURST 2048
+struct gso_status {
+	uint8_t enable;
+};
+extern struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+extern uint16_t gso_max_segment_size;
+
 static inline unsigned int
 lcore_num(void)
 {
@@ -642,6 +651,7 @@ void port_rss_hash_key_update(portid_t port_id, char rss_type[],
 int rx_queue_id_is_invalid(queueid_t rxq_id);
 int tx_queue_id_is_invalid(queueid_t txq_id);
 void setup_gro(const char *mode, uint8_t port_id);
+void setup_gso(const char *mode, uint8_t port_id);
 
 /* Functions to manage the set of filtered Multicast MAC addresses */
 void mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr);
doc/guides/testpmd_app_ug/testpmd_funcs.rst +46 -0

52 lines not on this page · raw message

Signature · 1 line
1.9.3
#156 lore raw

PATCH v5 6/6 doc: add GSO programmer's guide

In reply to Jiayu Hu

Add programmer's guide doc to explain the design and use of the GSO library.

---
 MAINTAINERS                                        |   6 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477 +++++++++++++++++++++
 doc/guides/prog_guide/index.rst                    |   1 +
 5 files changed, 1053 insertions(+)
 create mode 100644 doc/guides/prog_guide/generic_segmentation_offload_lib.rst
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
MAINTAINERS +6 -0
index a0cd75e..f18e463 100644
@@ -641,6 +641,12 @@ M: Jiayu Hu <[email protected]>
 F: lib/librte_gro/
 F: doc/guides/prog_guide/generic_receive_offload_lib.rst
 
+Generic Segmentation Offload
+M: Jiayu Hu <[email protected]>
+M: Mark Kavanagh <[email protected]>
+F: lib/librte_gso/
+F: doc/guides/prog_guide/generic_segmentation_offload_lib.rst
+
 Distributor
 M: Bruce Richardson <[email protected]>
 M: David Hunt <[email protected]>
doc/guides/prog_guide/generic_segmentation_offload_lib.rst new file +256 -0

256 lines not on this page · raw message

doc/guides/prog_guide/img/gso-output-segment-format.svg new file +313 -0

313 lines not on this page · raw message

doc/guides/prog_guide/img/gso-three-seg-mbuf.svg new file +477 -0

477 lines not on this page · raw message

doc/guides/prog_guide/index.rst +1 -0
index 40f04a1..c7c8b17 100644
@@ -56,6 +56,7 @@ Programmer's Guide
     reorder_lib
     ip_fragment_reassembly_lib
     generic_receive_offload_lib
+    generic_segmentation_offload_lib
     pdump_lib
     multi_proc_support
     kernel_nic_interface
Signature · 1 line
1.9.3