From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00067.outbound.protection.outlook.com [40.107.0.67]) by dpdk.org (Postfix) with ESMTP id 82F091B32C for ; Tue, 3 Oct 2017 12:50:04 +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; bh=r+CpYyVQaxGiFDlgUXgaIBtGufGXE7JvxSrA7O3WZO8=; b=AqBHwPuGLtl+ZEHV5lSMYrOt1Q9nCgEr+/6ayvNSbcSg28ZzgE1tJndrdBwxX2aRQRNkjQiSIqROHVZwhksnQX2MdmzxfarxHaruVl7l8i2X2lu+nHO9Gii/a2lWABOCnwipRPHzeT+Fx392JhrrNSf924gnnF3+ruJii8jutOQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; Received: from mellanox.com (37.142.13.130) by AM5PR0502MB3042.eurprd05.prod.outlook.com (2603:10a6:203:a1::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Tue, 3 Oct 2017 10:50:01 +0000 From: Matan Azrad To: Adrien Mazarguil Cc: dev@dpdk.org, Moti Haimovsky , Vasily Philipov Date: Tue, 3 Oct 2017 10:48:27 +0000 Message-Id: <1507027711-879-3-git-send-email-matan@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1507027711-879-1-git-send-email-matan@mellanox.com> References: <1503590050-196143-1-git-send-email-motih@mellanox.com> <1507027711-879-1-git-send-email-matan@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: HE1PR09CA0085.eurprd09.prod.outlook.com (2603:10a6:7:3d::29) To AM5PR0502MB3042.eurprd05.prod.outlook.com (2603:10a6:203:a1::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 39c406a6-2b64-4597-7c8a-08d50a4c804b X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(48565401081)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:AM5PR0502MB3042; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0502MB3042; 3:YzZY6Q30kBjozi9sqPIWLZA/128SKQsTDVbWVBG9GakDB3XVkOJIutIytMp7ztAsU2tmPXGEX9IMVnPpHkqnf2MV4WNHGgMzuyPye5sEHglTAI3FkiNIT74/UByRrUjPR9oYCssVdjqodUyYVishOLAqqTGaPbgWVbF2nrxNgREnyVgkFYQSJeZBnMmRX2WvZeGwZYvoUxE3iM7rotA+a9Cn/QcRWP/XXvxGmMHC6XU9NfES29JTNY+HbJ1VcPYB; 25:uJjjeQXwDN/0GkwLuBpSZ/eBhDxKHCuayJrZApIG2GiB/F38Hu4lbfVcdaUmdjfCtN8xr8B00rjDMSsqeDnSCjmawBxWRwQK6b2W6OWdePLJXWyzqoZu1r0cznNT7ph7ckxPaqaiSVMhV6K5yVIZuDsoTqqbakpg+Zca57NHzBGcorRr6bcGxKppBnchRbU/CtgmT0COhZrslvfAc+pne16gymrn331HBNaF+Pd23qkLMWC2fmQ+6KlVxo74mE6PoeRm2ExqYYcGV0Jn7SAtBsDPFbBrRZiYd4RfqYpMskiyuSwWnzz7b52Z9i/Y0w4GMbBjlwrn0YXhT582DGoiPA==; 31:ycKMY12QhrrKIFouLbeL2vSgClKg0vPJAUGzSQn0P2g9xmBySOZZhBIw8O9JhQCtupl1ZIcuXEaK0wbKtTZumR3hzehrq1eZAf3tceaQmsPSOk7eFzPpCt7NG5pprAC+r2HZyqJlwc5AS3cC0X7neVnWFWrQsQL9MSw0F+htbF+5IK06h6SI3WbpIOx5TEzqaz0n1Pfaa+KvVqxYgBsqsNihbp0ZT34BmpDiDH//Y7k= X-MS-TrafficTypeDiagnostic: AM5PR0502MB3042: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; AM5PR0502MB3042; 20:9+9+OuQVwpobXtfgLfbifoOic7YFTN6mY8FNeJ00vy0sJZsPkMj41DpAeV66lbC5HX2M/Puzrv4ul04IwsEV7a/au6wZ7lTefEqgPyvqaAuAS4owhhzmco2c8pVqPhkeU8jS2UUD3vgzT+SigV6vmdDBGWU1m9/k+l08shKNjietnH6j8ao2n5PncN2YEBrr8BmN7X4DEZEdwZY8d8dbOWJ+ob/pYMeNptzsVzKCRJEAgPoByGRs1f+rtwrSCcZvoWTzeDFmfxfnOLAup1fIl9J5zKXBSXi/LDo6psEbOC4NEWS+18cUScP+O5AjLXky332zVot1pNoJJZcv2F2UEEYCfagNCRc8S2HfPdRWho4Vy4KXK4Qc4IwHfeWxz7Q45jBmO+E1RAK5bzIOE1wHHLTBh5g74zoti7rUzXCxCOXFcOc9vOF5woA0L/DBZYDCrvxEZz2UhggaBsG18BRzgEKlNrW/pmnPw4VEh1Le16T1HiGHOsUrWox3QLtERiIc; 4:Xh7owkOHPIOfp6kGOrw/XFymMos5cLOjJLIkgRemQU/k+wMfsHYU7qcnzK6YC20Gst/nPKjcBeRFm7v4rIDcoU/mS1UEyCzaEgypOSiBQj8/crFf7tH9aTPZpc3Af7xbjEGq4tUbSfgjNtEXr5pPMNggMlIWO6qY9qyzZH0xyFhS2xUrvt2CrJZZP87EmEQxca3lCmrQFd3W8A1VqndOpZWkyzqjUgb+Odqk325/rfCWrt9VxJZ7frsmcqhjnkaQ2KffVe0pEpT7GajDLBT4lJimLk4fa/CkSV2VqVTZslc+NrKcQoxNOcVj0Ac9qjs6yt2DajIMVo9bysusqvfrOg== X-Exchange-Antispam-Report-Test: UriScan:(60795455431006)(131327999870524); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(100000703101)(100105400095)(6055026)(6041248)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123558100)(20161123562025)(20161123564025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM5PR0502MB3042; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM5PR0502MB3042; X-Forefront-PRVS: 044968D9E1 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(376002)(346002)(189002)(199003)(33646002)(107886003)(5660300001)(55016002)(105586002)(47776003)(3846002)(53936002)(2906002)(66066001)(50986999)(76176999)(16586007)(86362001)(316002)(101416001)(81156014)(305945005)(8936002)(81166006)(54906003)(8676002)(33026002)(50226002)(7736002)(16526017)(97736004)(48376002)(69596002)(25786009)(478600001)(50466002)(6116002)(4326008)(106356001)(5003940100001)(36756003)(6916009)(6666003)(4720700003)(21086003)(2950100002)(68736007)(189998001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM5PR0502MB3042; H:mellanox.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM5PR0502MB3042; 23:f9j3IWTXeaOVEJmvx+2MxDv4ndL8oVffUo/tg0d?= =?us-ascii?Q?rQ0IV7f5X9BGc9vwS5ct33Ce1ShpmPw2HtvdRaZbGDQFGGp8oFqC8DtWq3SO?= =?us-ascii?Q?8ghvcpAm2bxw6Mcjy8jzOtgjaBnMxJhaDnx+IGRQA8HMNXW66pDCp9HvltNh?= =?us-ascii?Q?7gQ8RsJ7Xw4xsQ3hNweF68WX64iDwzpamlekHad2K2fzeVFvs6yJZjL+wvgH?= =?us-ascii?Q?9uXef75f1RHRZ/2KKw6U3Qk/LZk8Sb9G9RgMHeTPqExY48gDIRGk5OV77ESg?= =?us-ascii?Q?zeeGtuNkq3PtR78SNXQNKQlrVtYysgoozQEFb5W5zAwwCNESkSUQANb4wBSx?= =?us-ascii?Q?xFpraxoTJjXVtyBhP4QOV5aTioh5HQZoin0Z6L1Tt0uMaKlfHCpMzKjCurF0?= =?us-ascii?Q?JLRbKfiOfYQlmbm5+iwS1QFqAwe8LMleU8H5gZ6v6ft9rJjc2D61IWLJCsdQ?= =?us-ascii?Q?L3RReEeaE5gylsTOjA3IO6ltVinJxL4JXav677t1wF81qZ6crNc/BWcHE2yC?= =?us-ascii?Q?N7jWfkoJIjeCPNI36l0ox1eBUqzJZc0/qeoFd8XdLRXtGos70i4HdX1F7zO4?= =?us-ascii?Q?OjD4QnnBB721HKTCbikyNwsLQt5Lb9zdB0tAw9As6ZD8ZqdLyX5wkyy7u/2B?= =?us-ascii?Q?fax0bQEeXwsIH/UOhXs+oT8ZPIHeJb3AG41ZyHUtQJV63EF2j4UxELnumCay?= =?us-ascii?Q?49LZ/s6yIiBg1SGCCiG+lasWsh4fY95JKVnh+0i4Oxds0xhChTy5KxfXpWzk?= =?us-ascii?Q?hchViMrRC888+MYjGETJ8lUj/rhKyq3Qxf7SJCGNWq3eRUMekgKsIY1ZoABe?= =?us-ascii?Q?+D5YiiZG1J1I+Y06je8ux3A+Y6HI3zbfQKoAabVWjT9bSZiaDP56irmH23AZ?= =?us-ascii?Q?lj9e3KWDCvpXP/a7lLJz8/XmZQ7hfCAFwt0s26x63xvgsYIVie7cnk6c5Jh5?= =?us-ascii?Q?koO0Sg/gwwrVoc4XUPiPzdbGclHSTGUUZCZCqwrlmEhPz1ouDsY8wAZeXFG1?= =?us-ascii?Q?gvTnQj47Cw7Xd/hXkDEJ00mgsNLtJQIkTk/vdUWr5Mu4Jb4UF+VRpBqdYDfg?= =?us-ascii?Q?XiRmJhg551/qnreO6IUmrU+gMjfdErHfqmz4lHMQy4WxCot3xYtSdu0UsDXI?= =?us-ascii?Q?+X3/hqsqLgAxLATVApqJ531lkp1dTG6s4ZFgXZ87DQllje9gimH619g=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; AM5PR0502MB3042; 6:6Flqqta/l2Br1PGj5LIhPBzDVh1wPgjbDptDKnHQvisqX5L+24+azSSKAmh4t8I1SHMyIsesX2izVKQG/25NrhrljcyMhTUuQh7/6OY7CziSyvW0JGuuvVP/LHKKLlccWt8QgIUm4WjMmL9oZxNclRZObMevUEKl4waLxcPDUKCEjI4ewJDDv79raUaiLq/4wRXDRw9LfDJdk6nzYUadjsu3uMuDfechmtOc73hFjuS+6RB/525hRNNqNUPm29PeS79xsgKFbyE1hp9KmdZwGqQRaN9BV0eWa1VBQa8N+RZoxmN8WzHy4qiMEzIOGf/IIh4KkoTv5Ya6WWRMgD+46A==; 5:3/BfazdKHlo2Expe50qucGvAUxdDTgBwi3vX6DbzP7bxFkUmPyb/opQYjeCM14N9j4nmGrkuHRF/ab75Dv0/+33ULQof6ccvd9wAjNVblPWL5bscRwu0sKGtRfR/MMrTu/DWoWn3M9gaoXBhqT1XZglCw8UqyZ3fGnd9bDjeX+A=; 24:F7YqDgJgWBQBuTEQYJ0z1T5GSzrLRV91ZdDWqCDUmKIOFmfY7+S2+fl/zQ2YnvYw4e/2thjVzby7wV901YkyeIbxyy6Qp0SSyZ7CfAdIImw=; 7:aBeEQhNZeycJFa14LA+PN3zSXOBO3lA4gYKuKGh8uJILhz19BPxkIpBQtAUZFxbJXH/32VpvHmUG2lmDIAibLtjvEWpwhtnYEo56eFoALJ2xddqOq6LfVMDHtRny7hDRMkhOU4QpMo4DyAbmEOzHqSpmKrYieOz3OSox6rvPIYSzk0XYkp9jTZCkPQWJLh3rVnKZ7EJNhVD+aB5F75hQFRUZxTt1HdrYTzXWW+EH924= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2017 10:50:01.7922 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0502MB3042 Subject: [dpdk-dev] [PATCH v2 2/6] net/mlx4: get back Rx flow functionality 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: , X-List-Received-Date: Tue, 03 Oct 2017 10:50:04 -0000 From: Moti Haimovsky This patch adds support for accessing the hardware directly when handling Rx packets eliminating the need to use verbs in the Rx datapath. Now the number of scatters is calculated on the fly, according to the maximum expected packet size. Signed-off-by: Vasily Philipov --- drivers/net/mlx4/mlx4.h | 11 -- drivers/net/mlx4/mlx4_rxq.c | 176 +++++++++++++++++++------------- drivers/net/mlx4/mlx4_rxtx.c | 229 ++++++++++++++++++++++++------------------ drivers/net/mlx4/mlx4_rxtx.h | 19 ++-- drivers/net/mlx4/mlx4_utils.h | 20 ++++ 5 files changed, 268 insertions(+), 187 deletions(-) diff --git a/drivers/net/mlx4/mlx4.h b/drivers/net/mlx4/mlx4.h index 93e5502..b6e1ef2 100644 --- a/drivers/net/mlx4/mlx4.h +++ b/drivers/net/mlx4/mlx4.h @@ -57,17 +57,6 @@ /* Maximum size for inline data. */ #define MLX4_PMD_MAX_INLINE 0 -/* - * Maximum number of cached Memory Pools (MPs) per TX queue. Each RTE MP - * from which buffers are to be transmitted will have to be mapped by this - * driver to their own Memory Region (MR). This is a slow operation. - * - * This value is always 1 for RX queues. - */ -#ifndef MLX4_PMD_TX_MP_CACHE -#define MLX4_PMD_TX_MP_CACHE 8 -#endif - /* Interrupt alarm timeout value in microseconds. */ #define MLX4_INTR_ALARM_TIMEOUT 100000 diff --git a/drivers/net/mlx4/mlx4_rxq.c b/drivers/net/mlx4/mlx4_rxq.c index 409983f..d7447c4 100644 --- a/drivers/net/mlx4/mlx4_rxq.c +++ b/drivers/net/mlx4/mlx4_rxq.c @@ -51,6 +51,7 @@ #pragma GCC diagnostic error "-Wpedantic" #endif +#include #include #include #include @@ -77,60 +78,63 @@ mlx4_rxq_alloc_elts(struct rxq *rxq, unsigned int elts_n) { unsigned int i; - struct rxq_elt (*elts)[elts_n] = - rte_calloc_socket("RXQ elements", 1, sizeof(*elts), 0, - rxq->socket); + const unsigned int sge_n = 1 << rxq->sge_n; + struct rte_mbuf *(*elts)[elts_n] = + rte_calloc_socket("RXQ", 1, sizeof(*elts), 0, rxq->socket); if (elts == NULL) { + elts_n = 0; rte_errno = ENOMEM; ERROR("%p: can't allocate packets array", (void *)rxq); goto error; } - /* For each WR (packet). */ - for (i = 0; (i != elts_n); ++i) { - struct rxq_elt *elt = &(*elts)[i]; - struct ibv_recv_wr *wr = &elt->wr; - struct ibv_sge *sge = &(*elts)[i].sge; - struct rte_mbuf *buf = rte_pktmbuf_alloc(rxq->mp); + rxq->elts = elts; + for (i = 0; i != elts_n; ++i) { + struct rte_mbuf *buf; + volatile struct mlx4_wqe_data_seg *scat = + &(*rxq->hw.wqes)[i]; + buf = rte_pktmbuf_alloc(rxq->mp); if (buf == NULL) { rte_errno = ENOMEM; ERROR("%p: empty mbuf pool", (void *)rxq); goto error; } - elt->buf = buf; - wr->next = &(*elts)[(i + 1)].wr; - wr->sg_list = sge; - wr->num_sge = 1; /* Headroom is reserved by rte_pktmbuf_alloc(). */ assert(buf->data_off == RTE_PKTMBUF_HEADROOM); /* Buffer is supposed to be empty. */ assert(rte_pktmbuf_data_len(buf) == 0); assert(rte_pktmbuf_pkt_len(buf) == 0); - /* sge->addr must be able to store a pointer. */ - assert(sizeof(sge->addr) >= sizeof(uintptr_t)); - /* SGE keeps its headroom. */ - sge->addr = (uintptr_t) - ((uint8_t *)buf->buf_addr + RTE_PKTMBUF_HEADROOM); - sge->length = (buf->buf_len - RTE_PKTMBUF_HEADROOM); - sge->lkey = rxq->mr->lkey; - /* Redundant check for tailroom. */ - assert(sge->length == rte_pktmbuf_tailroom(buf)); + assert(!buf->next); + /* Only the first segment keeps headroom. */ + if (i % sge_n) + buf->data_off = 0; + buf->port = rxq->port_id; + buf->data_len = rte_pktmbuf_tailroom(buf); + buf->pkt_len = rte_pktmbuf_tailroom(buf); + buf->nb_segs = 1; + /* scat->addr must be able to store a pointer. */ + assert(sizeof(scat->addr) >= sizeof(uintptr_t)); + *scat = (struct mlx4_wqe_data_seg){ + .addr = + rte_cpu_to_be_64(rte_pktmbuf_mtod(buf, uintptr_t)), + .byte_count = rte_cpu_to_be_32(buf->data_len), + .lkey = rte_cpu_to_be_32(rxq->mr->lkey), + }; + (*rxq->elts)[i] = buf; } - /* The last WR pointer must be NULL. */ - (*elts)[(i - 1)].wr.next = NULL; - DEBUG("%p: allocated and configured %u single-segment WRs", - (void *)rxq, elts_n); - rxq->elts_n = elts_n; - rxq->elts_head = 0; - rxq->elts = elts; + DEBUG("%p: allocated and configured %u segments (max %u packets)", + (void *)rxq, elts_n, elts_n >> rxq->sge_n); + rxq->elts_n = log2above(elts_n); return 0; error: - if (elts != NULL) { - for (i = 0; (i != RTE_DIM(*elts)); ++i) - rte_pktmbuf_free_seg((*elts)[i].buf); - rte_free(elts); + for (i = 0; i != elts_n; ++i) { + if ((*rxq->elts)[i] != NULL) + rte_pktmbuf_free_seg((*rxq->elts)[i]); + (*rxq->elts)[i] = NULL; } + rte_free(rxq->elts); + rxq->elts = NULL; DEBUG("%p: failed, freed everything", (void *)rxq); assert(rte_errno > 0); return -rte_errno; @@ -146,17 +150,18 @@ mlx4_rxq_free_elts(struct rxq *rxq) { unsigned int i; - unsigned int elts_n = rxq->elts_n; - struct rxq_elt (*elts)[elts_n] = rxq->elts; DEBUG("%p: freeing WRs", (void *)rxq); + if (rxq->elts == NULL) + return; + + for (i = 0; i != (1u << rxq->elts_n); ++i) { + if ((*rxq->elts)[i] != NULL) + rte_pktmbuf_free_seg((*rxq->elts)[i]); + } + rte_free(rxq->elts); rxq->elts_n = 0; rxq->elts = NULL; - if (elts == NULL) - return; - for (i = 0; (i != RTE_DIM(*elts)); ++i) - rte_pktmbuf_free_seg((*elts)[i].buf); - rte_free(elts); } /** @@ -198,7 +203,8 @@ * QP pointer or NULL in case of error and rte_errno is set. */ static struct ibv_qp * -mlx4_rxq_setup_qp(struct priv *priv, struct ibv_cq *cq, uint16_t desc) +mlx4_rxq_setup_qp(struct priv *priv, struct ibv_cq *cq, + uint16_t desc, unsigned int sge_n) { struct ibv_qp *qp; struct ibv_qp_init_attr attr = { @@ -212,7 +218,7 @@ priv->device_attr.max_qp_wr : desc), /* Max number of scatter/gather elements in a WR. */ - .max_recv_sge = 1, + .max_recv_sge = sge_n, }, .qp_type = IBV_QPT_RAW_PACKET, }; @@ -248,32 +254,43 @@ struct rte_mempool *mp) { struct priv *priv = dev->data->dev_private; + struct mlx4dv_obj mlxdv; + struct mlx4dv_qp dv_qp; + struct mlx4dv_cq dv_cq; struct rxq tmpl = { .priv = priv, .mp = mp, .socket = socket }; struct ibv_qp_attr mod; - struct ibv_recv_wr *bad_wr; unsigned int mb_len; int ret; (void)conf; /* Thresholds configuration (ignored). */ mb_len = rte_pktmbuf_data_room_size(mp); - if (desc == 0) { - rte_errno = EINVAL; - ERROR("%p: invalid number of Rx descriptors", (void *)dev); - goto error; - } /* Enable scattered packets support for this queue if necessary. */ assert(mb_len >= RTE_PKTMBUF_HEADROOM); if (dev->data->dev_conf.rxmode.max_rx_pkt_len <= (mb_len - RTE_PKTMBUF_HEADROOM)) { - ; + tmpl.sge_n = 0; } else if (dev->data->dev_conf.rxmode.enable_scatter) { - WARN("%p: scattered mode has been requested but is" - " not supported, this may lead to packet loss", - (void *)dev); + unsigned int sges_n; + unsigned int rx_pkt_len = + dev->data->dev_conf.rxmode.jumbo_frame ? + dev->data->dev_conf.rxmode.max_rx_pkt_len : + ETHER_MTU; + + if (rx_pkt_len < ETHER_MTU) + rx_pkt_len = ETHER_MTU; + /* Only the first mbuf has a headroom */ + rx_pkt_len = rx_pkt_len - mb_len + RTE_PKTMBUF_HEADROOM; + /* + * Determine the number of SGEs needed for a full packet + * and round it to the next power of two. + */ + sges_n = (rx_pkt_len / mb_len) + !!(rx_pkt_len % mb_len) + 1; + tmpl.sge_n = log2above(sges_n); + desc >>= tmpl.sge_n; } else { WARN("%p: the requested maximum Rx packet size (%u) is" " larger than a single mbuf (%u) and scattered" @@ -282,6 +299,8 @@ dev->data->dev_conf.rxmode.max_rx_pkt_len, mb_len - RTE_PKTMBUF_HEADROOM); } + DEBUG("%p: number of sges %u (%u WRs)", + (void *)dev, 1 << tmpl.sge_n, desc); /* Use the entire Rx mempool as the memory region. */ tmpl.mr = mlx4_mp2mr(priv->pd, mp); if (tmpl.mr == NULL) { @@ -317,7 +336,7 @@ priv->device_attr.max_qp_wr); DEBUG("priv->device_attr.max_sge is %d", priv->device_attr.max_sge); - tmpl.qp = mlx4_rxq_setup_qp(priv, tmpl.cq, desc); + tmpl.qp = mlx4_rxq_setup_qp(priv, tmpl.cq, desc, 1 << tmpl.sge_n); if (tmpl.qp == NULL) { ERROR("%p: QP creation failure: %s", (void *)dev, strerror(rte_errno)); @@ -336,21 +355,6 @@ (void *)dev, strerror(rte_errno)); goto error; } - ret = mlx4_rxq_alloc_elts(&tmpl, desc); - if (ret) { - ERROR("%p: RXQ allocation failed: %s", - (void *)dev, strerror(rte_errno)); - goto error; - } - ret = ibv_post_recv(tmpl.qp, &(*tmpl.elts)[0].wr, &bad_wr); - if (ret) { - rte_errno = ret; - ERROR("%p: ibv_post_recv() failed for WR %p: %s", - (void *)dev, - (void *)bad_wr, - strerror(rte_errno)); - goto error; - } mod = (struct ibv_qp_attr){ .qp_state = IBV_QPS_RTR }; @@ -361,14 +365,44 @@ (void *)dev, strerror(rte_errno)); goto error; } + /* Get HW depended info */ + mlxdv.cq.in = tmpl.cq; + mlxdv.cq.out = &dv_cq; + mlxdv.qp.in = tmpl.qp; + mlxdv.qp.out = &dv_qp; + ret = mlx4dv_init_obj(&mlxdv, MLX4DV_OBJ_QP | MLX4DV_OBJ_CQ); + if (ret) { + ERROR("%p: Failed to retrieve device obj info", (void *)dev); + goto error; + } + /* Init HW depended fields */ + tmpl.hw.wqes = + (volatile struct mlx4_wqe_data_seg (*)[]) + ((char *)dv_qp.buf.buf + dv_qp.rq.offset); + tmpl.hw.rq_db = dv_qp.rdb; + tmpl.hw.rq_ci = 0; + tmpl.mcq.buf = dv_cq.buf.buf; + tmpl.mcq.cqe_cnt = dv_cq.cqe_cnt; + tmpl.mcq.set_ci_db = dv_cq.set_ci_db; + tmpl.mcq.cqe_64 = (dv_cq.cqe_size & 64) ? 1 : 0; /* Save port ID. */ tmpl.port_id = dev->data->port_id; DEBUG("%p: RTE port ID: %u", (void *)rxq, tmpl.port_id); + ret = mlx4_rxq_alloc_elts(&tmpl, desc << tmpl.sge_n); + if (ret) { + ERROR("%p: RXQ allocation failed: %s", + (void *)dev, strerror(rte_errno)); + goto error; + } /* Clean up rxq in case we're reinitializing it. */ DEBUG("%p: cleaning-up old rxq just in case", (void *)rxq); mlx4_rxq_cleanup(rxq); *rxq = tmpl; DEBUG("%p: rxq updated with %p", (void *)rxq, (void *)&tmpl); + /* Update doorbell counter. */ + rxq->hw.rq_ci = desc; + rte_wmb(); + *rxq->hw.rq_db = rte_cpu_to_be_32(rxq->hw.rq_ci); return 0; error: ret = rte_errno; @@ -406,6 +440,12 @@ struct rxq *rxq = dev->data->rx_queues[idx]; int ret; + if (!rte_is_power_of_2(desc)) { + desc = 1 << log2above(desc); + WARN("%p: increased number of descriptors in RX queue %u" + " to the next power of two (%d)", + (void *)dev, idx, desc); + } DEBUG("%p: configuring queue %u for %u descriptors", (void *)dev, idx, desc); if (idx >= dev->data->nb_rx_queues) { diff --git a/drivers/net/mlx4/mlx4_rxtx.c b/drivers/net/mlx4/mlx4_rxtx.c index 55c8e9a..e45bb3b 100644 --- a/drivers/net/mlx4/mlx4_rxtx.c +++ b/drivers/net/mlx4/mlx4_rxtx.c @@ -521,9 +521,45 @@ } /** - * DPDK callback for Rx. + * Poll one CQE from CQ. * - * The following function doesn't manage scattered packets. + * @param rxq + * Pointer to the receive queue structure. + * @param[out] out + * Just polled CQE. + * + * @return + * Number of bytes of the CQE, 0 in case there is no completion. + */ +static unsigned int +mlx4_cq_poll_one(struct rxq *rxq, + struct mlx4_cqe **out) +{ + int ret = 0; + struct mlx4_cqe *cqe = NULL; + struct mlx4_cq *cq = &rxq->mcq; + + cqe = (struct mlx4_cqe *)mlx4_get_cqe(cq, cq->cons_index); + if (!!(cqe->owner_sr_opcode & MLX4_CQE_OWNER_MASK) ^ + !!(cq->cons_index & cq->cqe_cnt)) + goto out; + /* + * Make sure we read CQ entry contents after we've checked the + * ownership bit. + */ + rte_rmb(); + assert(!(cqe->owner_sr_opcode & MLX4_CQE_IS_SEND_MASK)); + assert((cqe->owner_sr_opcode & MLX4_CQE_OPCODE_MASK) != + MLX4_CQE_OPCODE_ERROR); + ret = rte_be_to_cpu_32(cqe->byte_cnt); + ++cq->cons_index; +out: + *out = cqe; + return ret; +} + +/** + * DPDK callback for RX with scattered packets support. * * @param dpdk_rxq * Generic pointer to Rx queue structure. @@ -538,112 +574,109 @@ uint16_t mlx4_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n) { - struct rxq *rxq = (struct rxq *)dpdk_rxq; - struct rxq_elt (*elts)[rxq->elts_n] = rxq->elts; - const unsigned int elts_n = rxq->elts_n; - unsigned int elts_head = rxq->elts_head; - struct ibv_wc wcs[pkts_n]; - struct ibv_recv_wr *wr_head = NULL; - struct ibv_recv_wr **wr_next = &wr_head; - struct ibv_recv_wr *wr_bad = NULL; - unsigned int i; - unsigned int pkts_ret = 0; - int ret; + struct rxq *rxq = dpdk_rxq; + const unsigned int wr_cnt = (1 << rxq->elts_n) - 1; + const unsigned int sge_n = rxq->sge_n; + struct rte_mbuf *pkt = NULL; + struct rte_mbuf *seg = NULL; + unsigned int i = 0; + unsigned int rq_ci = (rxq->hw.rq_ci << sge_n); + int len = 0; - ret = ibv_poll_cq(rxq->cq, pkts_n, wcs); - if (unlikely(ret == 0)) - return 0; - if (unlikely(ret < 0)) { - DEBUG("rxq=%p, ibv_poll_cq() failed (wc_n=%d)", - (void *)rxq, ret); - return 0; - } - assert(ret <= (int)pkts_n); - /* For each work completion. */ - for (i = 0; i != (unsigned int)ret; ++i) { - struct ibv_wc *wc = &wcs[i]; - struct rxq_elt *elt = &(*elts)[elts_head]; - struct ibv_recv_wr *wr = &elt->wr; - uint32_t len = wc->byte_len; - struct rte_mbuf *seg = elt->buf; - struct rte_mbuf *rep; + while (pkts_n) { + struct mlx4_cqe *cqe; + unsigned int idx = rq_ci & wr_cnt; + struct rte_mbuf *rep = (*rxq->elts)[idx]; + volatile struct mlx4_wqe_data_seg *scat = + &(*rxq->hw.wqes)[idx]; - /* Sanity checks. */ - assert(wr->sg_list == &elt->sge); - assert(wr->num_sge == 1); - assert(elts_head < rxq->elts_n); - assert(rxq->elts_head < rxq->elts_n); - /* - * Fetch initial bytes of packet descriptor into a - * cacheline while allocating rep. - */ - rte_mbuf_prefetch_part1(seg); - rte_mbuf_prefetch_part2(seg); - /* Link completed WRs together for repost. */ - *wr_next = wr; - wr_next = &wr->next; - if (unlikely(wc->status != IBV_WC_SUCCESS)) { - /* Whatever, just repost the offending WR. */ - DEBUG("rxq=%p: bad work completion status (%d): %s", - (void *)rxq, wc->status, - ibv_wc_status_str(wc->status)); - /* Increment dropped packets counter. */ - ++rxq->stats.idropped; - goto repost; - } + /* Update the 'next' pointer of the previous segment. */ + if (pkt) + seg->next = rep; + seg = rep; + rte_prefetch0(seg); + rte_prefetch0(scat); rep = rte_mbuf_raw_alloc(rxq->mp); if (unlikely(rep == NULL)) { - /* - * Unable to allocate a replacement mbuf, - * repost WR. - */ - DEBUG("rxq=%p: can't allocate a new mbuf", - (void *)rxq); - /* Increase out of memory counters. */ ++rxq->stats.rx_nombuf; - ++rxq->priv->dev->data->rx_mbuf_alloc_failed; - goto repost; + if (!pkt) { + /* + * No buffers before we even started, + * bail out silently. + */ + break; + } + while (pkt != seg) { + assert(pkt != (*rxq->elts)[idx]); + rep = pkt->next; + pkt->next = NULL; + pkt->nb_segs = 1; + rte_mbuf_raw_free(pkt); + pkt = rep; + } + break; + } + if (!pkt) { + /* Looking for the new packet */ + len = mlx4_cq_poll_one(rxq, &cqe); + if (!len) { + rte_mbuf_raw_free(rep); + break; + } + if (unlikely(len < 0)) { + /* RX error, packet is likely too large. */ + rte_mbuf_raw_free(rep); + ++rxq->stats.idropped; + goto skip; + } + pkt = seg; + pkt->packet_type = 0; + pkt->ol_flags = 0; + pkt->pkt_len = len; } - /* Reconfigure sge to use rep instead of seg. */ - elt->sge.addr = (uintptr_t)rep->buf_addr + RTE_PKTMBUF_HEADROOM; - assert(elt->sge.lkey == rxq->mr->lkey); - elt->buf = rep; - /* Update seg information. */ - seg->data_off = RTE_PKTMBUF_HEADROOM; - seg->nb_segs = 1; - seg->port = rxq->port_id; - seg->next = NULL; - seg->pkt_len = len; + rep->nb_segs = 1; + rep->port = rxq->port_id; + rep->data_len = seg->data_len; + rep->data_off = seg->data_off; + (*rxq->elts)[idx] = rep; + /* + * Fill NIC descriptor with the new buffer. The lkey and size + * of the buffers are already known, only the buffer address + * changes. + */ + scat->addr = rte_cpu_to_be_64(rte_pktmbuf_mtod(rep, uintptr_t)); + if (len > seg->data_len) { + len -= seg->data_len; + ++pkt->nb_segs; + ++rq_ci; + continue; + } + /* The last segment. */ seg->data_len = len; - seg->packet_type = 0; - seg->ol_flags = 0; + /* Increment bytes counter. */ + rxq->stats.ibytes += pkt->pkt_len; /* Return packet. */ - *(pkts++) = seg; - ++pkts_ret; - /* Increase bytes counter. */ - rxq->stats.ibytes += len; -repost: - if (++elts_head >= elts_n) - elts_head = 0; - continue; + *(pkts++) = pkt; + pkt = NULL; + --pkts_n; + ++i; +skip: + /* Align consumer index to the next stride. */ + rq_ci >>= sge_n; + ++rq_ci; + rq_ci <<= sge_n; } - if (unlikely(i == 0)) + if (unlikely((i == 0) && ((rq_ci >> sge_n) == rxq->hw.rq_ci))) return 0; - /* Repost WRs. */ - *wr_next = NULL; - assert(wr_head); - ret = ibv_post_recv(rxq->qp, wr_head, &wr_bad); - if (unlikely(ret)) { - /* Inability to repost WRs is fatal. */ - DEBUG("%p: recv_burst(): failed (ret=%d)", - (void *)rxq->priv, - ret); - abort(); - } - rxq->elts_head = elts_head; - /* Increase packets counter. */ - rxq->stats.ipackets += pkts_ret; - return pkts_ret; + /* Update the consumer index. */ + rxq->hw.rq_ci = rq_ci >> sge_n; + rte_wmb(); + *rxq->hw.rq_db = rte_cpu_to_be_32(rxq->hw.rq_ci); + *rxq->mcq.set_ci_db = + rte_cpu_to_be_32(rxq->mcq.cons_index & 0xffffff); + /* Increment packets counter. */ + rxq->stats.ipackets += i; + return i; } /** diff --git a/drivers/net/mlx4/mlx4_rxtx.h b/drivers/net/mlx4/mlx4_rxtx.h index b515472..df83552 100644 --- a/drivers/net/mlx4/mlx4_rxtx.h +++ b/drivers/net/mlx4/mlx4_rxtx.h @@ -62,13 +62,6 @@ struct mlx4_rxq_stats { uint64_t rx_nombuf; /**< Total of Rx mbuf allocation failures. */ }; -/** Rx element. */ -struct rxq_elt { - struct ibv_recv_wr wr; /**< Work request. */ - struct ibv_sge sge; /**< Scatter/gather element. */ - struct rte_mbuf *buf; /**< Buffer. */ -}; - /** Rx queue descriptor. */ struct rxq { struct priv *priv; /**< Back pointer to private data. */ @@ -78,9 +71,15 @@ struct rxq { struct ibv_qp *qp; /**< Queue pair. */ struct ibv_comp_channel *channel; /**< Rx completion channel. */ unsigned int port_id; /**< Port ID for incoming packets. */ - unsigned int elts_n; /**< (*elts)[] length. */ - unsigned int elts_head; /**< Current index in (*elts)[]. */ - struct rxq_elt (*elts)[]; /**< Rx elements. */ + unsigned int elts_n; /**< Log 2 of Mbufs. */ + struct rte_mbuf *(*elts)[]; /**< Rx elements. */ + struct { + volatile struct mlx4_wqe_data_seg(*wqes)[]; + volatile uint32_t *rq_db; + uint16_t rq_ci; + } hw; + struct mlx4_cq mcq; /**< Info for directly manipulating the CQ. */ + unsigned int sge_n; /**< Log 2 of SGEs number. */ struct mlx4_rxq_stats stats; /**< Rx queue counters. */ unsigned int socket; /**< CPU socket ID for allocations. */ }; diff --git a/drivers/net/mlx4/mlx4_utils.h b/drivers/net/mlx4/mlx4_utils.h index 0fbdc71..d6f729f 100644 --- a/drivers/net/mlx4/mlx4_utils.h +++ b/drivers/net/mlx4/mlx4_utils.h @@ -108,4 +108,24 @@ int mlx4_fd_set_non_blocking(int fd); +/** + * Return nearest power of two above input value. + * + * @param v + * Input value. + * + * @return + * Nearest power of two above input value. + */ +static inline unsigned int +log2above(unsigned int v) +{ + unsigned int l; + unsigned int r; + + for (l = 0, r = 0; (v >> 1); ++l, v >>= 1) + r |= (v & 1); + return l + r; +} + #endif /* MLX4_UTILS_H_ */ -- 1.8.3.1