From patchwork Wed Jul 4 14:53:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moti Haimovsky X-Patchwork-Id: 42236 X-Patchwork-Delegate: shahafs@mellanox.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8645D1BF45; Wed, 4 Jul 2018 16:53:41 +0200 (CEST) Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-eopbgr50054.outbound.protection.outlook.com [40.107.5.54]) by dpdk.org (Postfix) with ESMTP id F40201BF40 for ; Wed, 4 Jul 2018 16:53:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fPx2vVr3L1eheI7YiOxzSxpOWLTIBWgWyCauk4HRZu8=; b=H/loujr2TslH5I0Pu7AOge+4+QuZR8idGsueOJN7Im3wly7aRCHcIGb2seHXfx/0NDS9+XemvZZZ28GC0dETFfQ125LyBnneiqS7JKbHexjA0Rr140igEleethsNv+Wnw/+XO+Mf+bl5Pi2lONfMRGmbYZdQWE+1TAiKSAUVUNU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=motih@mellanox.com; Received: from localhost.localdomain (37.142.13.130) by DB7PR05MB4441.eurprd05.prod.outlook.com (2603:10a6:5:1b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.906.26; Wed, 4 Jul 2018 14:53:37 +0000 From: Moti Haimovsky To: adrien.mazarguil@6wind.com, matan@mellanox.com Cc: dev@dpdk.org, Moti Haimovsky Date: Wed, 4 Jul 2018 17:53:18 +0300 Message-Id: <1530715998-15703-1-git-send-email-motih@mellanox.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1530190137-17848-1-git-send-email-motih@mellanox.com> References: <1530190137-17848-1-git-send-email-motih@mellanox.com> MIME-Version: 1.0 X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: DB6PR07CA0020.eurprd07.prod.outlook.com (2603:10a6:6:2d::30) To DB7PR05MB4441.eurprd05.prod.outlook.com (2603:10a6:5:1b::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c898cc75-03af-424e-774d-08d5e1bded09 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600053)(711020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020); SRVR:DB7PR05MB4441; X-Microsoft-Exchange-Diagnostics: 1; DB7PR05MB4441; 3:puUV9EVxdhi0TofUPhuUPZJPYx7pqFRwOkbdW+MDdHLijO7cqb8CdqXrgA4FF79Ih17jAWieQ40XlKR08q6cDYwKnM43UdUK7it/WX237wZqorQjo5UgxMlKlYsPnJGjlwQPmbPR5glXBJznAgqS/edel7264KU/8o9c8NumvBKrYrfvqJUn82SC0tUflSCafLuu+HS61WJRbUSqy7zuFCYW0vz0kmclZYu/+6ZsqDFfMgIHE1o+rbx24Wg4Sl8M; 25:GALvXEyWQbUflxChTbc+ZOSeNXNWixPpDeu6BKtFw1fBFnDtPcoVETFOV0Qiesq8u8vQVYtnVW9BP3Z635BWTC8cEBhs9urqwFUB2IILEQ6/j7SnpvLJbmC0tbIBQ08UwSdM650lGehE8wa2KatsOa8TPjenzZv9er2QynOWR5UTM7M2G2KusFBB+GhmO2ITl6vNhj0reerVdrARJWUY7JvprQpl3+emtuvuKHmVO8HrZo44xJjs/uIfaEqfWVjG4fCSQNNuGdIB47f40sZiYfSaN9ynkXL/M8FandGV1m2k6IYLPRO1PQGtpPyQBOa+IOFmnmIsKWsrfAjHlFptng==; 31:OUWEy4vhsoqO932J7jBCNzTPwQU67kRYbeBwp7qWpWokMV8NQGvqiLZOZBcTPIIIyWN9BZfPq6BZl9jSzCidIYzJrxL8ExCI1G2MNrWxw8jpZy04rWEY8lvkp0xGhWRXEcMO0lMUrz7cHdBfGIBZQHl8MbaMIywXuglQxMHsINsT9Mi8bZQ18ODwokYZdAUL9HRAeW+cKsYIKcR9RlTCweulN7hSYAG8cmvpSI38ohU= X-MS-TrafficTypeDiagnostic: DB7PR05MB4441: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; DB7PR05MB4441; 20:I6+cQ+Funws67YvkLfkuMGVrdVgah2SyOK80MaXCiuFlNj9zfQrxPGgaRXS+nScj50UT2f1isHDe8zAN958lE9mgMRXWWNeHLl3TCXPWtVHRaxguK7qlnGI2hvogKxvde0IZhB0noIiZnSZr4JsFVKO7z/UtYSPxa5Nh1qNLDeX2w0BsxLlDUQeTUh/0LO/1MlWQ2gmkVnBt3zpv7d92URCKyRz5Mvg4epnl9uQBbCZnCydEgeTbdg8IyK3xJyLY7OypMEEVmoCmVKevWUOUtYx2mzsYUGdKDpPYI4MN67nBRCp24B+glyH1ftsqulhNdmTtnyqM3Ei3E5A8f1mXKgxQ2Tn+QRF+zjHHVvPHa/MLPfdh8vlhTzuYIzG+rl0GCXCnL/2ZvTz5A/EzhmmHVJ9WB0fl+PKFHDX0eJ1iMtOXxTCStnxQCq4Iz1DFjDereWLsrETzQsaou5mFz2CsKaeQHj15dgWjZnlQQoz7adjHVtxVDJhITNFvi39AW9Ee; 4:8ot+yuaPspYArkv+LtwMe5dUCjWCtVVZt3McoFR8Sml4uuHU13iaudmtgrgK/vKIuPVngZ6sIMfSiHUvPokt4lPrzDskDEjcFY4pporjMXTWwJmgSKvZdLrIH01Wtz8WR2+m5UFbJfYstSZW0e36FfBFUMiSYsLspOr+tfcjzcqc/jowyubmOI5hSSf4lwL51Q5IBGwTPorjOdfDQda74IIZcrY0wgjXV8aavQbkiebLjEn7csf010ULPLZXv8UacD7gNkElmBsxg48dsfRXhA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(3231254)(944501410)(52105095)(10201501046)(6055026)(149027)(150027)(6041310)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(6072148)(201708071742011)(7699016); SRVR:DB7PR05MB4441; BCL:0; PCL:0; RULEID:; SRVR:DB7PR05MB4441; X-Forefront-PRVS: 0723A02764 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(346002)(136003)(366004)(39860400002)(396003)(376002)(189003)(199004)(6116002)(478600001)(105586002)(6486002)(106356001)(86362001)(3846002)(16586007)(316002)(97736004)(6666003)(6636002)(66066001)(8936002)(305945005)(186003)(7736002)(8676002)(50466002)(2906002)(4326008)(25786009)(48376002)(26005)(6506007)(386003)(107886003)(14444005)(81166006)(47776003)(76176011)(16526019)(68736007)(5660300001)(36756003)(52116002)(2616005)(446003)(11346002)(53936002)(50226002)(476003)(956004)(486006)(51416003)(81156014)(6512007); DIR:OUT; SFP:1101; SCL:1; SRVR:DB7PR05MB4441; H:localhost.localdomain; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB7PR05MB4441; 23:2DKmtNhQIKwexoCNPnFVXXx8xzH2mcStvEaya0jOZ?= /aKP4FVJXRhCJJMyy0VZdRMAHN8Y1H4KYmOBlxfi8GCrhkxvBvL1F7wKSlJ0oLZo09NAoMO+c7C8MjQWvYBvfR1xS+azN94AhCVPQ0rLUM0BILS0JIHFuD89xfxGXXwHPaoJUje9yRcj+3P3oD7QIENLJtFXVxulYj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EsO79Y9EArye8C8Fyglrn4FELrWP0I81llhtvMMuNhBv2MCZu4vLdDB5sGyjPq8LhU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB7PR05MB4441; 7:QADov6Xtv6RsLUQ1EpTkKgwF8iEIWrnU+zfa/adEB4da+Uv2cSKtL/FGcGO7abYZ5yCbRVAwsSWBFdSvW1TkFWluPDXi0V3ywqGCXGnYAxRUFjaRu7dTS/zC2Noa5SHGtbmh/F2jTy0Sf7DVCHLOqNNKUpFfKm9Yahz5E89npaloLVD4iBY4ZlEeC7Dg2Qzf2EDB4lUMGUuf8rbr0TUcT+tFrmURb5lR7kbNjUaTCy8LwWfe7obqKSn5lAz85+L/ X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jul 2018 14:53:37.7176 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c898cc75-03af-424e-774d-08d5e1bded09 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR05MB4441 Subject: [dpdk-dev] [PATCH v4] net/mlx4: support hardware TSO X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Implement support for hardware TSO. Signed-off-by: Moti Haimovsky --- v4: * Bug fixes in filling TSO data segments. * Modifications according to review inputs from Adrien Mazarguil and Matan Azrad. in reply to 1530190137-17848-1-git-send-email-motih@mellanox.com v3: * Fixed compilation errors in compilers without GNU C extensions caused by a declaration of zero-length array in the code. in reply to 1530187032-6489-1-git-send-email-motih@mellanox.com v2: * Fixed coding style warning. in reply to 1530184583-30166-1-git-send-email-motih@mellanox.com v1: * Fixed coding style warnings. in reply to 1530181779-19716-1-git-send-email-motih@mellanox.com --- doc/guides/nics/features/mlx4.ini | 1 + doc/guides/nics/mlx4.rst | 3 + drivers/net/mlx4/Makefile | 5 + drivers/net/mlx4/mlx4.c | 9 + drivers/net/mlx4/mlx4.h | 5 + drivers/net/mlx4/mlx4_prm.h | 15 ++ drivers/net/mlx4/mlx4_rxtx.c | 362 +++++++++++++++++++++++++++++++++++++- drivers/net/mlx4/mlx4_rxtx.h | 2 +- drivers/net/mlx4/mlx4_txq.c | 8 +- 9 files changed, 406 insertions(+), 4 deletions(-) diff --git a/doc/guides/nics/features/mlx4.ini b/doc/guides/nics/features/mlx4.ini index f6efd21..98a3f61 100644 --- a/doc/guides/nics/features/mlx4.ini +++ b/doc/guides/nics/features/mlx4.ini @@ -13,6 +13,7 @@ Queue start/stop = Y MTU update = Y Jumbo frame = Y Scattered Rx = Y +TSO = Y Promiscuous mode = Y Allmulticast mode = Y Unicast MAC filter = Y diff --git a/doc/guides/nics/mlx4.rst b/doc/guides/nics/mlx4.rst index 491106a..12adaeb 100644 --- a/doc/guides/nics/mlx4.rst +++ b/doc/guides/nics/mlx4.rst @@ -142,6 +142,9 @@ Limitations The ability to enable/disable CRC stripping requires OFED version 4.3-1.5.0.0 and above or rdma-core version v18 and above. +- TSO (Transmit Segmentation Offload) is supported in OFED version + 4.4 and above or in rdma-core version v18 and above. + Prerequisites ------------- diff --git a/drivers/net/mlx4/Makefile b/drivers/net/mlx4/Makefile index 73f9d40..63bc003 100644 --- a/drivers/net/mlx4/Makefile +++ b/drivers/net/mlx4/Makefile @@ -85,6 +85,11 @@ mlx4_autoconf.h.new: FORCE mlx4_autoconf.h.new: $(RTE_SDK)/buildtools/auto-config-h.sh $Q $(RM) -f -- '$@' $Q : > '$@' + $Q sh -- '$<' '$@' \ + HAVE_IBV_MLX4_WQE_LSO_SEG \ + infiniband/mlx4dv.h \ + type 'struct mlx4_wqe_lso_seg' \ + $(AUTOCONF_OUTPUT) # Create mlx4_autoconf.h or update it in case it differs from the new one. diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c index d151a90..5d8c76d 100644 --- a/drivers/net/mlx4/mlx4.c +++ b/drivers/net/mlx4/mlx4.c @@ -677,6 +677,15 @@ struct mlx4_conf { IBV_RAW_PACKET_CAP_SCATTER_FCS); DEBUG("FCS stripping toggling is %ssupported", priv->hw_fcs_strip ? "" : "not "); + priv->tso = + ((device_attr_ex.tso_caps.max_tso > 0) && + (device_attr_ex.tso_caps.supported_qpts & + (1 << IBV_QPT_RAW_PACKET))); + if (priv->tso) + priv->tso_max_payload_sz = + device_attr_ex.tso_caps.max_tso; + DEBUG("TSO is %ssupported", + priv->tso ? "" : "not "); /* Configure the first MAC address by default. */ err = mlx4_get_mac(priv, &mac.addr_bytes); if (err) { diff --git a/drivers/net/mlx4/mlx4.h b/drivers/net/mlx4/mlx4.h index 300cb4d..89d8c38 100644 --- a/drivers/net/mlx4/mlx4.h +++ b/drivers/net/mlx4/mlx4.h @@ -47,6 +47,9 @@ /** Interrupt alarm timeout value in microseconds. */ #define MLX4_INTR_ALARM_TIMEOUT 100000 +/* Maximum packet headers size (L2+L3+L4) for TSO. */ +#define MLX4_MAX_TSO_HEADER 192 + /** Port parameter. */ #define MLX4_PMD_PORT_KVARG "port" @@ -90,6 +93,8 @@ struct priv { uint32_t hw_csum:1; /**< Checksum offload is supported. */ uint32_t hw_csum_l2tun:1; /**< Checksum support for L2 tunnels. */ uint32_t hw_fcs_strip:1; /**< FCS stripping toggling is supported. */ + uint32_t tso:1; /**< Transmit segmentation offload is supported. */ + uint32_t tso_max_payload_sz; /**< Max supported TSO payload size. */ uint64_t hw_rss_sup; /**< Supported RSS hash fields (Verbs format). */ struct rte_intr_handle intr_handle; /**< Port interrupt handle. */ struct mlx4_drop *drop; /**< Shared resources for drop flow rules. */ diff --git a/drivers/net/mlx4/mlx4_prm.h b/drivers/net/mlx4/mlx4_prm.h index b771d8c..aef77ba 100644 --- a/drivers/net/mlx4/mlx4_prm.h +++ b/drivers/net/mlx4/mlx4_prm.h @@ -19,6 +19,7 @@ #ifdef PEDANTIC #pragma GCC diagnostic error "-Wpedantic" #endif +#include "mlx4_autoconf.h" /* ConnectX-3 Tx queue basic block. */ #define MLX4_TXBB_SHIFT 6 @@ -40,6 +41,7 @@ /* Work queue element (WQE) flags. */ #define MLX4_WQE_CTRL_IIP_HDR_CSUM (1 << 28) #define MLX4_WQE_CTRL_IL4_HDR_CSUM (1 << 27) +#define MLX4_WQE_CTRL_RR (1 << 6) /* CQE checksum flags. */ enum { @@ -98,6 +100,19 @@ struct mlx4_cq { int arm_sn; /**< Rx event counter. */ }; +#ifndef HAVE_IBV_MLX4_WQE_LSO_SEG +/* + * WQE LSO segment structure. + * Defined here as backward compatibility for rdma-core v17 and below. + * Similar definition is found in infiniband/mlx4dv.h in rdma-core v18 + * and above. + */ +struct mlx4_wqe_lso_seg { + rte_be32_t mss_hdr_size; + rte_be32_t header[]; +}; +#endif + /** * Retrieve a CQE entry from a CQ. * diff --git a/drivers/net/mlx4/mlx4_rxtx.c b/drivers/net/mlx4/mlx4_rxtx.c index 78b6dd5..750ad6d 100644 --- a/drivers/net/mlx4/mlx4_rxtx.c +++ b/drivers/net/mlx4/mlx4_rxtx.c @@ -38,10 +38,29 @@ * DWORD (32 byte) of a TXBB. */ struct pv { - volatile struct mlx4_wqe_data_seg *dseg; + union { + volatile struct mlx4_wqe_data_seg *dseg; + volatile uint32_t *dst; + }; uint32_t val; }; +/** A helper structure for TSO packet handling. */ +struct tso_info { + /** Pointer to the array of saved first DWORD (32 byte) of a TXBB. */ + struct pv *pv; + /** Current entry in the pv array. */ + int pv_counter; + /** Total size of the WQE including padding. */ + uint32_t wqe_size; + /** size of TSO header to prepend to each packet to send. */ + uint16_t tso_header_sz; + /** Total size of the TSO segment in the WQE. */ + uint16_t wqe_tso_seg_size; + /** Raw WQE size in units of 16 Bytes and without padding. */ + uint8_t fence_size; +}; + /** A table to translate Rx completion flags to packet type. */ uint32_t mlx4_ptype_table[0x100] __rte_cache_aligned = { /* @@ -368,6 +387,335 @@ struct pv { } /** + * Obtain and calculate TSO information needed for assembling a TSO WQE. + * + * @param buf + * Pointer to the first packet mbuf. + * @param txq + * Pointer to Tx queue structure. + * @param tinfo + * Pointer to a structure to fill the info with. + * + * @return + * 0 on success, negative value upon error. + */ +static inline int +mlx4_tx_burst_tso_get_params(struct rte_mbuf *buf, + struct txq *txq, + struct tso_info *tinfo) +{ + struct mlx4_sq *sq = &txq->msq; + const uint8_t tunneled = txq->priv->hw_csum_l2tun && + (buf->ol_flags & PKT_TX_TUNNEL_MASK); + + tinfo->tso_header_sz = buf->l2_len + buf->l3_len + buf->l4_len; + if (tunneled) + tinfo->tso_header_sz += buf->outer_l2_len + buf->outer_l3_len; + if (unlikely(buf->tso_segsz == 0 || + tinfo->tso_header_sz == 0 || + tinfo->tso_header_sz > MLX4_MAX_TSO_HEADER || + tinfo->tso_header_sz > buf->data_len)) + return -EINVAL; + /* + * Calculate the WQE TSO segment size + * Note: + * 1. An LSO segment must be padded such that the subsequent data + * segment is 16-byte aligned. + * 2. The start address of the TSO segment is always 16 Bytes aligned. + */ + tinfo->wqe_tso_seg_size = RTE_ALIGN(sizeof(struct mlx4_wqe_lso_seg) + + tinfo->tso_header_sz, + sizeof(struct mlx4_wqe_data_seg)); + tinfo->fence_size = ((sizeof(struct mlx4_wqe_ctrl_seg) + + tinfo->wqe_tso_seg_size) >> MLX4_SEG_SHIFT) + + buf->nb_segs; + tinfo->wqe_size = + RTE_ALIGN((uint32_t)(tinfo->fence_size << MLX4_SEG_SHIFT), + MLX4_TXBB_SIZE); + /* Validate WQE size and WQE space in the send queue. */ + if (sq->remain_size < tinfo->wqe_size || + tinfo->wqe_size > MLX4_MAX_WQE_SIZE) + return -ENOMEM; + /* Init pv. */ + tinfo->pv = (struct pv *)txq->bounce_buf; + tinfo->pv_counter = 0; + return 0; +} + +/** + * Fill the TSO WQE data segments with info on buffers to transmit . + * + * @param buf + * Pointer to the first packet mbuf. + * @param txq + * Pointer to Tx queue structure. + * @param tinfo + * Pointer to TSO info to use. + * @param dseg + * Pointer to the first data segment in the TSO WQE. + * + * @return + * 0 on success, negative value upon error. + */ +static inline volatile struct mlx4_wqe_ctrl_seg * +mlx4_tx_burst_fill_tso_dsegs(struct rte_mbuf *buf, + struct txq *txq, + struct tso_info *tinfo, + volatile struct mlx4_wqe_data_seg *dseg, + volatile struct mlx4_wqe_ctrl_seg *ctrl) +{ + uint32_t lkey; + int nb_segs = buf->nb_segs; + int nb_segs_txbb; + struct mlx4_sq *sq = &txq->msq; + struct rte_mbuf *sbuf = buf; + struct pv *pv = tinfo->pv; + int *pv_counter = &tinfo->pv_counter; + uint16_t sb_of = tinfo->tso_header_sz; + uint16_t data_len; + + while (nb_segs > 0) { + /* how many dseg entries do we have in the current TXBB ? */ + nb_segs_txbb = + (MLX4_TXBB_SIZE / sizeof(struct mlx4_wqe_data_seg)) - + ((uintptr_t)dseg & (MLX4_TXBB_SIZE - 1)) / + sizeof(struct mlx4_wqe_data_seg); + switch (nb_segs_txbb) { + case 4: + /* Memory region key for this memory pool. */ + lkey = mlx4_tx_mb2mr(txq, sbuf); + if (unlikely(lkey == (uint32_t)-1)) + goto lkey_err; + dseg->addr = + rte_cpu_to_be_64(rte_pktmbuf_mtod_offset(sbuf, + uintptr_t, + sb_of)); + dseg->lkey = lkey; + /* + * This data segment starts at the beginning of a new + * TXBB, so we need to postpone its byte_count writing + * for later. + */ + pv[*pv_counter].dseg = dseg; + /* + * Zero length segment is treated as inline segment + * with zero data. + */ + data_len = sbuf->data_len - sb_of; + pv[(*pv_counter)++].val = + rte_cpu_to_be_32(data_len ? + data_len : + 0x80000000); + sb_of = 0; + sbuf = sbuf->next; + dseg++; + if (--nb_segs == 0) + break; + /* fallthrough */ + case 3: + lkey = mlx4_tx_mb2mr(txq, sbuf); + if (unlikely(lkey == (uint32_t)-1)) + goto lkey_err; + data_len = sbuf->data_len - sb_of; + mlx4_fill_tx_data_seg(dseg, + lkey, + rte_pktmbuf_mtod_offset(sbuf, + uintptr_t, + sb_of), + rte_cpu_to_be_32(data_len ? + data_len : + 0x80000000)); + sb_of = 0; + sbuf = sbuf->next; + dseg++; + if (--nb_segs == 0) + break; + /* fallthrough */ + case 2: + lkey = mlx4_tx_mb2mr(txq, sbuf); + if (unlikely(lkey == (uint32_t)-1)) + goto lkey_err; + data_len = sbuf->data_len - sb_of; + mlx4_fill_tx_data_seg(dseg, + lkey, + rte_pktmbuf_mtod_offset(sbuf, + uintptr_t, + sb_of), + rte_cpu_to_be_32(data_len ? + data_len : + 0x80000000)); + sb_of = 0; + sbuf = sbuf->next; + dseg++; + if (--nb_segs == 0) + break; + /* fallthrough */ + case 1: + lkey = mlx4_tx_mb2mr(txq, sbuf); + if (unlikely(lkey == (uint32_t)-1)) + goto lkey_err; + data_len = sbuf->data_len - sb_of; + mlx4_fill_tx_data_seg(dseg, + lkey, + rte_pktmbuf_mtod_offset(sbuf, + uintptr_t, + sb_of), + rte_cpu_to_be_32(data_len ? + data_len : + 0x80000000)); + sb_of = 0; + sbuf = sbuf->next; + dseg++; + --nb_segs; + break; + default: + /* Should never happen */ + rte_panic("%p: Invalid number of SGEs(%d) for a TXBB", + (void *)txq, nb_segs_txbb); + } + /* Wrap dseg if it points at the end of the queue. */ + if ((volatile uint8_t *)dseg >= sq->eob) + dseg = (volatile struct mlx4_wqe_data_seg *) + ((volatile uint8_t *)dseg - sq->size); + } + /* Align next WQE address to the next TXBB. */ + return (volatile struct mlx4_wqe_ctrl_seg *) + ((volatile uint8_t *)ctrl + tinfo->wqe_size); +lkey_err: + return NULL; +} + +/** + * Fill the packet's l2, l3 and l4 headers to the WQE. + * + * This will be used as the header for each TSO segment that is transmitted. + * + * @param buf + * Pointer to the first packet mbuf. + * @param txq + * Pointer to Tx queue structure. + * @param tinfo + * Pointer to TSO info to use. + * @param ctrl + * Pointer to the control segment in the TSO WQE. + * + * @return + * 0 on success, negative value upon error. + */ +static inline volatile struct mlx4_wqe_data_seg * +mlx4_tx_burst_fill_tso_hdr(struct rte_mbuf *buf, + struct txq *txq, + struct tso_info *tinfo, + volatile struct mlx4_wqe_ctrl_seg *ctrl) +{ + volatile struct mlx4_wqe_lso_seg *tseg = + (volatile struct mlx4_wqe_lso_seg *)(ctrl + 1); + struct mlx4_sq *sq = &txq->msq; + struct pv *pv = tinfo->pv; + int *pv_counter = &tinfo->pv_counter; + int remain_sz = tinfo->tso_header_sz; + char *from = rte_pktmbuf_mtod(buf, char *); + uint16_t txbb_avail_space; + int copy_sz; + /* Union to overcome volatile constraints when copying TSO header. */ + union { + volatile uint8_t *vto; + uint8_t *to; + } thdr = { .vto = (volatile uint8_t *)tseg->header, }; + + /* + * TSO data always starts at offset 20 from the beginning of the TXBB + * (16 byte ctrl + 4byte TSO desc). Since each TXBB is 64Byte aligned + * we can write the first 44 TSO header bytes without worry for TxQ + * wrapping or overwriting the first TXBB 32bit word. + */ + txbb_avail_space = MLX4_TXBB_SIZE - + (sizeof(struct mlx4_wqe_ctrl_seg) + + sizeof(struct mlx4_wqe_lso_seg)); + do { + copy_sz = RTE_MIN(txbb_avail_space, remain_sz); + rte_memcpy(thdr.to, from, copy_sz); + remain_sz -= copy_sz; + if (remain_sz <= 0) + break; + from += copy_sz; + thdr.to += copy_sz; + /* New TXBB, Check for TxQ wrap. */ + if (thdr.to >= sq->eob) + thdr.vto = sq->buf; + /* New TXBB, stash the first 32bits for later use. */ + pv[*pv_counter].dst = (volatile uint32_t *)thdr.vto; + rte_memcpy(&pv[*pv_counter].val, from, + RTE_MIN((size_t)remain_sz, sizeof(uint32_t))); + (*pv_counter)++; + from += sizeof(uint32_t); + thdr.to += sizeof(uint32_t); + remain_sz -= sizeof(uint32_t); + /* Space in current TXBB is TXBB size - 4 */ + txbb_avail_space = MLX4_TXBB_SIZE - sizeof(uint32_t); + } while (remain_sz > 0); + tseg->mss_hdr_size = rte_cpu_to_be_32((buf->tso_segsz << 16) | + tinfo->tso_header_sz); + /* Calculate data segment location */ + return (volatile struct mlx4_wqe_data_seg *) + ((uintptr_t)tseg + tinfo->wqe_tso_seg_size); +} + +/** + * Write data segments and header for TSO uni/multi segment packet. + * + * @param buf + * Pointer to the first packet mbuf. + * @param txq + * Pointer to Tx queue structure. + * @param ctrl + * Pointer to the WQE control segment. + * + * @return + * Pointer to the next WQE control segment on success, NULL otherwise. + */ +static volatile struct mlx4_wqe_ctrl_seg * +mlx4_tx_burst_tso(struct rte_mbuf *buf, struct txq *txq, + volatile struct mlx4_wqe_ctrl_seg *ctrl) +{ + volatile struct mlx4_wqe_data_seg *dseg; + volatile struct mlx4_wqe_ctrl_seg *ctrl_next; + struct mlx4_sq *sq = &txq->msq; + struct tso_info tinfo; + struct pv *pv; + int pv_counter; + int ret; + + ret = mlx4_tx_burst_tso_get_params(buf, txq, &tinfo); + if (unlikely(ret)) + goto error; + dseg = mlx4_tx_burst_fill_tso_hdr(buf, txq, &tinfo, ctrl); + if (unlikely(dseg == NULL)) + goto error; + if ((uintptr_t)dseg >= (uintptr_t)sq->eob) + dseg = (volatile struct mlx4_wqe_data_seg *) + ((uintptr_t)dseg - sq->size); + ctrl_next = mlx4_tx_burst_fill_tso_dsegs(buf, txq, &tinfo, dseg, ctrl); + if (unlikely(ctrl_next == NULL)) + goto error; + /* Write the first DWORD of each TXBB save earlier. */ + if (tinfo.pv_counter) { + pv = tinfo.pv; + pv_counter = tinfo.pv_counter; + /* Need a barrier here before writing the first TXBB word. */ + rte_io_wmb(); + for (--pv_counter; pv_counter >= 0; pv_counter--) + *pv[pv_counter].dst = pv[pv_counter].val; + } + ctrl->fence_size = tinfo.fence_size; + sq->remain_size -= tinfo.wqe_size; + return ctrl_next; +error: + txq->stats.odropped++; + return NULL; +} + +/** * Write data segments of multi-segment packet. * * @param buf @@ -560,6 +908,7 @@ struct pv { uint16_t flags16[2]; } srcrb; uint32_t lkey; + bool tso = txq->priv->tso && (buf->ol_flags & PKT_TX_TCP_SEG); /* Clean up old buffer. */ if (likely(elt->buf != NULL)) { @@ -578,7 +927,16 @@ struct pv { } while (tmp != NULL); } RTE_MBUF_PREFETCH_TO_FREE(elt_next->buf); - if (buf->nb_segs == 1) { + if (tso) { + /* Change opcode to TSO */ + owner_opcode &= ~MLX4_OPCODE_CONFIG_CMD; + owner_opcode |= MLX4_OPCODE_LSO | MLX4_WQE_CTRL_RR; + ctrl_next = mlx4_tx_burst_tso(buf, txq, ctrl); + if (!ctrl_next) { + elt->buf = NULL; + break; + } + } else if (buf->nb_segs == 1) { /* Validate WQE space in the send queue. */ if (sq->remain_size < MLX4_TXBB_SIZE) { elt->buf = NULL; diff --git a/drivers/net/mlx4/mlx4_rxtx.h b/drivers/net/mlx4/mlx4_rxtx.h index 4c025e3..ffa8abf 100644 --- a/drivers/net/mlx4/mlx4_rxtx.h +++ b/drivers/net/mlx4/mlx4_rxtx.h @@ -90,7 +90,7 @@ struct mlx4_txq_stats { unsigned int idx; /**< Mapping index. */ uint64_t opackets; /**< Total of successfully sent packets. */ uint64_t obytes; /**< Total of successfully sent bytes. */ - uint64_t odropped; /**< Total of packets not sent when Tx ring full. */ + uint64_t odropped; /**< Total number of packets failed to transmit. */ }; /** Tx queue descriptor. */ diff --git a/drivers/net/mlx4/mlx4_txq.c b/drivers/net/mlx4/mlx4_txq.c index 6edaadb..9aa7440 100644 --- a/drivers/net/mlx4/mlx4_txq.c +++ b/drivers/net/mlx4/mlx4_txq.c @@ -116,8 +116,14 @@ DEV_TX_OFFLOAD_UDP_CKSUM | DEV_TX_OFFLOAD_TCP_CKSUM); } - if (priv->hw_csum_l2tun) + if (priv->tso) + offloads |= DEV_TX_OFFLOAD_TCP_TSO; + if (priv->hw_csum_l2tun) { offloads |= DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM; + if (priv->tso) + offloads |= (DEV_TX_OFFLOAD_VXLAN_TNL_TSO | + DEV_TX_OFFLOAD_GRE_TNL_TSO); + } return offloads; }