From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on0064.outbound.protection.outlook.com [104.47.0.64]) by dpdk.org (Postfix) with ESMTP id D19271B270 for ; Tue, 31 Oct 2017 19:21:58 +0100 (CET) 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=BxeHt6uA0CAWFi913902XnIINSGp4WktONVbhW5s0Zk=; b=QKxE9p9LEimyaJjv7hHhk8xcZCXFeC8Kjt0SEcSr0O9gCKSyYJns5Yj3rb/WfI726yIinjjnHiIe3upv6ZtEMhc5qC63p0GcNAyJDlejas9amoSp9D2vXGh6QDojTM0/r1YaCM2DIZpDLBy2kYIc9BruAh+chp0MaE9gFP77Xbw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; Received: from mellanox.com (37.142.13.130) by VI1PR0502MB3664.eurprd05.prod.outlook.com (2603:10a6:803:f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.178.6; Tue, 31 Oct 2017 18:21:56 +0000 From: Matan Azrad To: Adrien Mazarguil Cc: dev@dpdk.org, Ophir Munk Date: Tue, 31 Oct 2017 18:21:29 +0000 Message-Id: <1509474093-31388-5-git-send-email-matan@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1509474093-31388-1-git-send-email-matan@mellanox.com> References: <1509358049-18854-1-git-send-email-matan@mellanox.com> <1509474093-31388-1-git-send-email-matan@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: VI1PR0801CA0074.eurprd08.prod.outlook.com (2603:10a6:800:7d::18) To VI1PR0502MB3664.eurprd05.prod.outlook.com (2603:10a6:803:f::23) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 284c9710-6cb9-49d0-888c-08d5208c455b X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(4534020)(4602075)(2017052603199); SRVR:VI1PR0502MB3664; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0502MB3664; 3:KsD49C9Q/U52icaIPa4QuBZsAjILn+poDYlDGcwN60ezXjQSmfpEPWH7aqLzpcE8HsNMmQ6/svLyjBaN/8bTifQGCGRFQQ5B86hpAciYS+OB8qLqxuwt4lMsYXdiKcUkZl9myMSVaL8fjdw6UFMetTHz/o7CWNLVhk1gvOsn8B3jLaXi4Ie4R7FPLqvUCvQSeqAmFrBFNnG7uSX5SIlXFRmjIIecbj3IDgzJla0VOyotErKfXKPmm7lxt0+8p1Iu; 25:fVFKTqx9pqweEXi1oiZ4nb6mJ0Om4HHoYyMHlKu6WK5AqrIvQG6x4L3k6Svb31aj9nj3jlyithKBQB9+0UoKDraGL7MC6rCYfUee3pnCSCosPPVHyeWlS1pBFPMZT5Ue9Q1L1V/0neOwIEPhUWVa+wT+Ps3wps7rgvBbdYDz9R6BA3wjYfgC/PWFtmKwskj0mRmRzx2ao8f+lzrwVijWyOD8duw9N2IARztXXM6l6BDvwmMMUkZ1WF+uO4ezMOD7yMNX8ppNNEeY4QSu8yZPRMJylbIpCDTDS1ZYG1xKaWJ7NmBcbAukvdG6cdUgu4Sgy0TWRV4Ktpg8ZhphTBBvfQ==; 31:ggMgCwHj6OmN/IYNEH1F0fUEw3Lh/FA4dIhRm7BjEUqR+Lwuul6Pt6QjQCpil5hRlfaivzHOyQ3FJngCr7ytCmDfvmW5UownaqsasRd3HylYxGPL+Ew574aHYkUNYDt3cSonrD9g3gs9ij6ledoKkTGN/zP65WLHpAM/vAKBwRFd+8V3y5Tcz4k24KFYCHyIF+7P+su/6GulqHNJ3zrk0C9G+v1U6QoVJb+cnL18sAk= X-MS-TrafficTypeDiagnostic: VI1PR0502MB3664: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; VI1PR0502MB3664; 20:bpFRjKWvZ6lHOkoUIIHVf+oHBmbC8mSbcTMKMnxxvDFA0xECnzA4rGP45H/xV0YWdRJyLo94m+N9hqVjUHMK7tNRG+723wKojubTJC6PYjzj3Moygk4ystgr/pL6Q/aFK08OnB49A0ujJJGfHI3xDQfQnswyCq7VcIv0yLbcZg+J3++0gtYytNFwFc2GfHz8D5wvt4P2Abw5tKOQUlEfzaWgVJjXaiDxgLbrlXaYJOvkCwVfpYrq3P43AoC4zDSTuEOIwpSFOqCjEfVjjKB8Aas6pjaolSWICktLsXWR/bWsx8jPyRV+zV/Di+rgt9/hYVqr3hDLDjOGCKxTSVx+wERR8y+lz4yF/IyXpLiRK/N9RQbGPFioP0exCFSs+6JMsy0j1BVW7lhjAM9BrU8zb+CdIQY1Y0LUA9ijsoehZo3WqJ7ZeXgqXPI0YIyUKeYEdcfS4BgSZCWfzZ9EPr6CFz0L2DPSJQC1K99gXOGyEIT4UOKIO2T07xYo7y530zOG; 4:JAaC7a2Ht7xzG+foaaXEdje7NOR5wmzTWi66WdXOdaW1cU7vUL2mYyVTNVSNosRbbNUYzqut0V0+jDSl+mt5IroPLFDR7pfPzrVqXXvj3Wz5tfv3qGfmTcyoCZeHsQ0bWWj8JZrMkso2gJQLWdcDWoZt/tTHCx25Bc/SsjJNwGDTHJncBHhR+dbwTRS5+x7EUp3BtWEtNziO1XFacZPe2RnwZJVI00oTPca4t9E6z+/bov3jZQSPcoKyshbGo1D0chOKeurqEsIdv/dYSYm3OhO2x/9Ly09XKDENlTRL3Ufhil+5QoDMSIs3TC2RBy4v X-Exchange-Antispam-Report-Test: UriScan:(60795455431006); 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)(3002001)(93006095)(93001095)(3231020)(10201501046)(100000703101)(100105400095)(6055026)(6041248)(20161123555025)(20161123558100)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:VI1PR0502MB3664; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:VI1PR0502MB3664; X-Forefront-PRVS: 04772EA191 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(346002)(39860400002)(376002)(189002)(199003)(50466002)(97736004)(66066001)(478600001)(189998001)(36756003)(33026002)(25786009)(7736002)(316002)(107886003)(16586007)(4326008)(86362001)(50226002)(53936002)(16526018)(101416001)(106356001)(5660300001)(2906002)(5003940100001)(69596002)(47776003)(6116002)(3846002)(68736007)(105586002)(81156014)(8936002)(81166006)(21086003)(305945005)(55016002)(4720700003)(2950100002)(76176999)(50986999)(6916009)(6666003)(48376002)(8676002)(33646002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0502MB3664; 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; VI1PR0502MB3664; 23:38W9aYMlmuJGkigLNBgBX5wi8jKOJ0uJM03lLP+?= =?us-ascii?Q?/fVzH57yacOL4dEtMnOPG/VGfZGhHPFOZrNGsAcipm3D7jthqXLtbiik9ea8?= =?us-ascii?Q?aedbfCXTVEOolzZp8zaBpKptcDLPU6fmZOfOd1ZqAG2DmAIUoUloE6ipX8ZT?= =?us-ascii?Q?ZBE6zomktckvNLlu2pIHRCWjPSaJF5zk8C1WPu+/SZ8IrD6WjZnFloPEcXJL?= =?us-ascii?Q?8Bc2t6GbEF42iHPJTvjk0xupyLLGxqIYr9F9EmATazdoKQg8FN0o9JwW4hVc?= =?us-ascii?Q?Vxl5nwBnM7WnYEU9V95vbY+PfuA8qg2A2GPCNJeTXn351TlkIZFYBehIIjHF?= =?us-ascii?Q?Snk9nsTJhjSMCIIqZ9Jw+dbyOpQgQJAARnTV5nx82JdaRycDdrgc1+eEdONE?= =?us-ascii?Q?81MRtjFwIPfRs0H/sSwidfCejqr9QngMx77RS1xm4apF87Zxk5VUi93+MKx4?= =?us-ascii?Q?W21MNWBCBqU/zmCe8nopdnSfkKT4bYtucpXxFMNHyZnJgWlLqfRtWEXECouZ?= =?us-ascii?Q?CMyjOd3e/1vrF4OfidyNsQcO43Op0m5JrKPM0GzmW/QEP0rjo5S9JL68wWF3?= =?us-ascii?Q?cH2W72SLtztpk/lWl3ophvxZbyXyxtfGNeWuzRmrz8xnlNN+tEbQLChUF36y?= =?us-ascii?Q?epZNltX02NXKmi3jupRdkcScRKYDLZr9M02hpjtd3GWes9eynHcJ4G4fGpj8?= =?us-ascii?Q?5a01awPG++hqZzNcq7K3LO9BvBGnmzEWVj8Ab0b7NuDpkztWcqbzGuCp1X6s?= =?us-ascii?Q?o4ILLAsOHpRhZAmtTafICr9EELmDWM/f+9TSceuga9yW86YbDDO90mj1R/hk?= =?us-ascii?Q?jXuYYblBi6xo2A7Wo8FO/1klzSyiDHWuoMIbKdNG2UHeuq8OiuRwRBfbv9dA?= =?us-ascii?Q?/qjyn8t1Ai1Y8Nwk1lhhJvCNf8THN98EqWAO6A9mpPOrBy75kL0854er/COI?= =?us-ascii?Q?YvAus518mO1ouA87YcVCA3jTQqxKtgo54rg70Kd+qMe3z+bmXswsb5ymLmgQ?= =?us-ascii?Q?X9qEdwgw31+cTz2R+lC5b0sG8yCE0rnNHbtT+TPizQs/4s5Si3M96GstJHst?= =?us-ascii?Q?mYOGaMriyxV4ot3tFIYI8+ko2VUW9CDY96claLCE2BJXD+KKBmeEz3Sff4Bh?= =?us-ascii?Q?95BaF9RPOuljmDEUiW/H3zLLwybq4P7FioOimNr2r2ufBXkjfquWyLA=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; VI1PR0502MB3664; 6:PO+AQowmg+gW+sM1/1vN4bq/I0OvoQLulrJTraTyxIz5bB+Qqsma1iWEzkLVYTrr0ntcWDRZuqybbIkn/AIOj7vqOeslZxSwnRE3HniyvSyh9CXhHM34WArSG7xTjXp8KfR10q2/QaOhbx+R3PyVuYTFjfVAUKqWX1uqWeUnfyxzLKj3BJTYKRqKRDkuA74+Wvm6qFB2KtO3d3x/AQC9wzIdIMk0doLkmUd2X3uEysHMQWR+uMA1IXOA6P//3RC68HB9ZxVSxgaYwsNYl7/89HdXW3CZGcMzIc1kACwG/0/mlMKbBGRXXnW96Yput1zfgDBd8jo21asB1uoJlFje5U/YXDS47cFbQ41bEaRM6a4=; 5:pqG9G4Br4NgWbJodiBR3ZuLbs9ny5HCWMswqHnL2eZR19tyv9rp356AjVkKmMO+u3RiRd0biRWh9/Awe+vGRAJpSGP8Zy6L4x7eXiPjqVYNGDwNTqksmogM/6o05G3DwOKj5Yl39QhKK6tOr6Y2l5B7tsQ9EZR0vIxyy8lOBuVY=; 24:98ILRv1x2F3gDk17R+b1EpmoaoZs4X2/6jjYelHvCYKqXIJFA0SfZMXxs8/Om6GvVRdKpWzdPxgLhnOmKvdPPrZ8kh4ZjpEq7hXr49610pA=; 7:nDiOXkPNluyM99z6ISinIy4kE0XNbzY9uU5WutSz2RKlmByuHLiILHPavu//CdItt345ErLlG8k+RME8as1EdhVB12fvU8KfxM9ocpmKo6ICL1f0rmTLKVuH/5KPLiM1v28mQCYZPF0P+4gO98QDztrffwUCasPTcF4QdsdRb15/0hrGoRtOcK+/1N+7ZC+FgfbrVCJs62rBPjsI87VbPKTdzojWtUSoZCUSSjOnvT9ZM0J4bc4miRyiKcfdFI/r SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2017 18:21:56.8148 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 284c9710-6cb9-49d0-888c-08d5208c455b X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0502MB3664 Subject: [dpdk-dev] [PATCH v4 4/8] net/mlx4: merge Tx path functions 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, 31 Oct 2017 18:21:59 -0000 Merge tx_burst and mlx4_post_send functions to prevent double asking about WQ remain space. Signed-off-by: Matan Azrad --- drivers/net/mlx4/mlx4_rxtx.c | 355 +++++++++++++++++++++---------------------- 1 file changed, 170 insertions(+), 185 deletions(-) diff --git a/drivers/net/mlx4/mlx4_rxtx.c b/drivers/net/mlx4/mlx4_rxtx.c index eddce82..0759e51 100644 --- a/drivers/net/mlx4/mlx4_rxtx.c +++ b/drivers/net/mlx4/mlx4_rxtx.c @@ -239,185 +239,6 @@ struct pv { } /** - * Posts a single work request to a send queue. - * - * @param txq - * Target Tx queue. - * @param pkt - * Packet to transmit. - * - * @return - * 0 on success, negative errno value otherwise. - */ -static inline int -mlx4_post_send(struct txq *txq, struct rte_mbuf *pkt) -{ - struct mlx4_wqe_ctrl_seg *ctrl; - struct mlx4_wqe_data_seg *dseg; - struct mlx4_sq *sq = &txq->msq; - struct rte_mbuf *buf; - union { - uint32_t flags; - uint16_t flags16[2]; - } srcrb; - uint32_t head_idx = sq->head & sq->txbb_cnt_mask; - uint32_t lkey; - uintptr_t addr; - uint32_t owner_opcode = MLX4_OPCODE_SEND; - uint32_t byte_count; - int wqe_real_size; - int nr_txbbs; - struct pv *pv = (struct pv *)txq->bounce_buf; - int pv_counter = 0; - - /* Calculate the needed work queue entry size for this packet. */ - wqe_real_size = sizeof(struct mlx4_wqe_ctrl_seg) + - pkt->nb_segs * sizeof(struct mlx4_wqe_data_seg); - nr_txbbs = MLX4_SIZE_TO_TXBBS(wqe_real_size); - /* - * Check that there is room for this WQE in the send queue and that - * the WQE size is legal. - */ - if (((sq->head - sq->tail) + nr_txbbs + - sq->headroom_txbbs) >= sq->txbb_cnt || - nr_txbbs > MLX4_MAX_WQE_TXBBS) { - return -ENOSPC; - } - /* Get the control and data entries of the WQE. */ - ctrl = (struct mlx4_wqe_ctrl_seg *)mlx4_get_send_wqe(sq, head_idx); - dseg = (struct mlx4_wqe_data_seg *)((uintptr_t)ctrl + - sizeof(struct mlx4_wqe_ctrl_seg)); - /* Fill the data segments with buffer information. */ - for (buf = pkt; buf != NULL; buf = buf->next, dseg++) { - addr = rte_pktmbuf_mtod(buf, uintptr_t); - rte_prefetch0((volatile void *)addr); - /* Handle WQE wraparound. */ - if (dseg >= (struct mlx4_wqe_data_seg *)sq->eob) - dseg = (struct mlx4_wqe_data_seg *)sq->buf; - dseg->addr = rte_cpu_to_be_64(addr); - /* Memory region key for this memory pool. */ - lkey = mlx4_txq_mp2mr(txq, mlx4_txq_mb2mp(buf)); -#ifndef NDEBUG - if (unlikely(lkey == (uint32_t)-1)) { - /* MR does not exist. */ - DEBUG("%p: unable to get MP <-> MR association", - (void *)txq); - /* - * Restamp entry in case of failure. - * Make sure that size is written correctly - * Note that we give ownership to the SW, not the HW. - */ - ctrl->fence_size = (wqe_real_size >> 4) & 0x3f; - mlx4_txq_stamp_freed_wqe(sq, head_idx, - (sq->head & sq->txbb_cnt) ? 0 : 1); - return -EFAULT; - } -#endif /* NDEBUG */ - dseg->lkey = rte_cpu_to_be_32(lkey); - if (likely(buf->data_len)) { - byte_count = rte_cpu_to_be_32(buf->data_len); - } else { - /* - * Zero length segment is treated as inline segment - * with zero data. - */ - byte_count = RTE_BE32(0x80000000); - } - /* - * If the data segment is not at the beginning of a - * Tx basic block (TXBB) then write the byte count, - * else postpone the writing to just before updating the - * control segment. - */ - if ((uintptr_t)dseg & (uintptr_t)(MLX4_TXBB_SIZE - 1)) { - /* - * Need a barrier here before writing the byte_count - * fields to make sure that all the data is visible - * before the byte_count field is set. - * Otherwise, if the segment begins a new cacheline, - * the HCA prefetcher could grab the 64-byte chunk and - * get a valid (!= 0xffffffff) byte count but stale - * data, and end up sending the wrong data. - */ - rte_io_wmb(); - dseg->byte_count = byte_count; - } else { - /* - * 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; - pv[pv_counter++].val = byte_count; - } - } - /* Write the first DWORD of each TXBB save earlier. */ - if (pv_counter) { - /* Need a barrier here before writing the byte_count. */ - rte_io_wmb(); - for (--pv_counter; pv_counter >= 0; pv_counter--) - pv[pv_counter].dseg->byte_count = pv[pv_counter].val; - } - /* Fill the control parameters for this packet. */ - ctrl->fence_size = (wqe_real_size >> 4) & 0x3f; - /* - * For raw Ethernet, the SOLICIT flag is used to indicate that no ICRC - * should be calculated. - */ - txq->elts_comp_cd -= nr_txbbs; - if (unlikely(txq->elts_comp_cd <= 0)) { - txq->elts_comp_cd = txq->elts_comp_cd_init; - srcrb.flags = RTE_BE32(MLX4_WQE_CTRL_SOLICIT | - MLX4_WQE_CTRL_CQ_UPDATE); - } else { - srcrb.flags = RTE_BE32(MLX4_WQE_CTRL_SOLICIT); - } - /* Enable HW checksum offload if requested */ - if (txq->csum && - (pkt->ol_flags & - (PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM | PKT_TX_UDP_CKSUM))) { - const uint64_t is_tunneled = (pkt->ol_flags & - (PKT_TX_TUNNEL_GRE | - PKT_TX_TUNNEL_VXLAN)); - - if (is_tunneled && txq->csum_l2tun) { - owner_opcode |= MLX4_WQE_CTRL_IIP_HDR_CSUM | - MLX4_WQE_CTRL_IL4_HDR_CSUM; - if (pkt->ol_flags & PKT_TX_OUTER_IP_CKSUM) - srcrb.flags |= - RTE_BE32(MLX4_WQE_CTRL_IP_HDR_CSUM); - } else { - srcrb.flags |= RTE_BE32(MLX4_WQE_CTRL_IP_HDR_CSUM | - MLX4_WQE_CTRL_TCP_UDP_CSUM); - } - } - if (txq->lb) { - /* - * Copy destination MAC address to the WQE, this allows - * loopback in eSwitch, so that VFs and PF can communicate - * with each other. - */ - srcrb.flags16[0] = *(rte_pktmbuf_mtod(pkt, uint16_t *)); - ctrl->imm = *(rte_pktmbuf_mtod_offset(pkt, uint32_t *, - sizeof(uint16_t))); - } else { - ctrl->imm = 0; - } - ctrl->srcrb_flags = srcrb.flags; - /* - * Make sure descriptor is fully written before - * setting ownership bit (because HW can start - * executing as soon as we do). - */ - rte_wmb(); - ctrl->owner_opcode = rte_cpu_to_be_32(owner_opcode | - ((sq->head & sq->txbb_cnt) ? - MLX4_BIT_WQE_OWN : 0)); - sq->head += nr_txbbs; - return 0; -} - -/** * DPDK callback for Tx. * * @param dpdk_txq @@ -440,7 +261,8 @@ struct pv { unsigned int bytes_sent = 0; unsigned int i; unsigned int max; - int err; + struct mlx4_sq *sq = &txq->msq; + struct pv *pv = (struct pv *)txq->bounce_buf; assert(txq->elts_comp_cd != 0); mlx4_txq_complete(txq); @@ -461,6 +283,21 @@ struct pv { (((elts_head + 1) == elts_n) ? 0 : elts_head + 1); struct txq_elt *elt_next = &(*txq->elts)[elts_head_next]; struct txq_elt *elt = &(*txq->elts)[elts_head]; + uint32_t owner_opcode = MLX4_OPCODE_SEND; + struct mlx4_wqe_ctrl_seg *ctrl; + struct mlx4_wqe_data_seg *dseg; + struct rte_mbuf *sbuf; + union { + uint32_t flags; + uint16_t flags16[2]; + } srcrb; + uint32_t head_idx = sq->head & sq->txbb_cnt_mask; + uint32_t lkey; + uintptr_t addr; + uint32_t byte_count; + int wqe_real_size; + int nr_txbbs; + int pv_counter = 0; /* Clean up old buffer. */ if (likely(elt->buf != NULL)) { @@ -479,18 +316,166 @@ struct pv { } while (tmp != NULL); } RTE_MBUF_PREFETCH_TO_FREE(elt_next->buf); - /* Post the packet for sending. */ - err = mlx4_post_send(txq, buf); - if (unlikely(err)) { + /* + * Calculate the needed work queue entry size + * for this packet. + */ + wqe_real_size = sizeof(struct mlx4_wqe_ctrl_seg) + + buf->nb_segs * sizeof(struct mlx4_wqe_data_seg); + nr_txbbs = MLX4_SIZE_TO_TXBBS(wqe_real_size); + /* + * Check that there is room for this WQE in the send + * queue and that the WQE size is legal. + */ + if (((sq->head - sq->tail) + nr_txbbs + + sq->headroom_txbbs) >= sq->txbb_cnt || + nr_txbbs > MLX4_MAX_WQE_TXBBS) { elt->buf = NULL; - goto stop; + break; } + /* Get the control and data entries of the WQE. */ + ctrl = (struct mlx4_wqe_ctrl_seg *) + mlx4_get_send_wqe(sq, head_idx); + dseg = (struct mlx4_wqe_data_seg *)((uintptr_t)ctrl + + sizeof(struct mlx4_wqe_ctrl_seg)); + /* Fill the data segments with buffer information. */ + for (sbuf = buf; sbuf != NULL; sbuf = sbuf->next, dseg++) { + addr = rte_pktmbuf_mtod(sbuf, uintptr_t); + rte_prefetch0((volatile void *)addr); + /* Handle WQE wraparound. */ + if (dseg >= (struct mlx4_wqe_data_seg *)sq->eob) + dseg = (struct mlx4_wqe_data_seg *)sq->buf; + dseg->addr = rte_cpu_to_be_64(addr); + /* Memory region key (big endian). */ + lkey = mlx4_txq_mp2mr(txq, mlx4_txq_mb2mp(sbuf)); + dseg->lkey = rte_cpu_to_be_32(lkey); +#ifndef NDEBUG + if (unlikely(dseg->lkey == + rte_cpu_to_be_32((uint32_t)-1))) { + /* MR does not exist. */ + DEBUG("%p: unable to get MP <-> MR association", + (void *)txq); + /* + * Restamp entry in case of failure. + * Make sure that size is written correctly + * Note that we give ownership to the SW, + * not the HW. + */ + ctrl->fence_size = (wqe_real_size >> 4) & 0x3f; + mlx4_txq_stamp_freed_wqe(sq, head_idx, + (sq->head & sq->txbb_cnt) ? 0 : 1); + elt->buf = NULL; + break; + } +#endif /* NDEBUG */ + if (likely(sbuf->data_len)) { + byte_count = rte_cpu_to_be_32(sbuf->data_len); + } else { + /* + * Zero length segment is treated as inline + * segment with zero data. + */ + byte_count = RTE_BE32(0x80000000); + } + /* + * If the data segment is not at the beginning + * of a Tx basic block (TXBB) then write the + * byte count, else postpone the writing to + * just before updating the control segment. + */ + if ((uintptr_t)dseg & (uintptr_t)(MLX4_TXBB_SIZE - 1)) { + /* + * Need a barrier here before writing the + * byte_count fields to make sure that all the + * data is visible before the byte_count field + * is set. otherwise, if the segment begins a + * new cacheline, the HCA prefetcher could grab + * the 64-byte chunk and get a valid + * (!= 0xffffffff) byte count but stale data, + * and end up sending the wrong data. + */ + rte_io_wmb(); + dseg->byte_count = byte_count; + } else { + /* + * 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; + pv[pv_counter++].val = byte_count; + } + } + /* Write the first DWORD of each TXBB save earlier. */ + if (pv_counter) { + /* Need a barrier before writing the byte_count. */ + rte_io_wmb(); + for (--pv_counter; pv_counter >= 0; pv_counter--) + pv[pv_counter].dseg->byte_count = + pv[pv_counter].val; + } + /* Fill the control parameters for this packet. */ + ctrl->fence_size = (wqe_real_size >> 4) & 0x3f; + /* + * For raw Ethernet, the SOLICIT flag is used to indicate + * that no ICRC should be calculated. + */ + txq->elts_comp_cd -= nr_txbbs; + if (unlikely(txq->elts_comp_cd <= 0)) { + txq->elts_comp_cd = txq->elts_comp_cd_init; + srcrb.flags = RTE_BE32(MLX4_WQE_CTRL_SOLICIT | + MLX4_WQE_CTRL_CQ_UPDATE); + } else { + srcrb.flags = RTE_BE32(MLX4_WQE_CTRL_SOLICIT); + } + /* Enable HW checksum offload if requested */ + if (txq->csum && + (buf->ol_flags & + (PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM | PKT_TX_UDP_CKSUM))) { + const uint64_t is_tunneled = (buf->ol_flags & + (PKT_TX_TUNNEL_GRE | + PKT_TX_TUNNEL_VXLAN)); + + if (is_tunneled && txq->csum_l2tun) { + owner_opcode |= MLX4_WQE_CTRL_IIP_HDR_CSUM | + MLX4_WQE_CTRL_IL4_HDR_CSUM; + if (buf->ol_flags & PKT_TX_OUTER_IP_CKSUM) + srcrb.flags |= + RTE_BE32(MLX4_WQE_CTRL_IP_HDR_CSUM); + } else { + srcrb.flags |= + RTE_BE32(MLX4_WQE_CTRL_IP_HDR_CSUM | + MLX4_WQE_CTRL_TCP_UDP_CSUM); + } + } + if (txq->lb) { + /* + * Copy destination MAC address to the WQE, this allows + * loopback in eSwitch, so that VFs and PF can + * communicate with each other. + */ + srcrb.flags16[0] = *(rte_pktmbuf_mtod(buf, uint16_t *)); + ctrl->imm = *(rte_pktmbuf_mtod_offset(buf, uint32_t *, + sizeof(uint16_t))); + } else { + ctrl->imm = 0; + } + ctrl->srcrb_flags = srcrb.flags; + /* + * Make sure descriptor is fully written before + * setting ownership bit (because HW can start + * executing as soon as we do). + */ + rte_wmb(); + ctrl->owner_opcode = rte_cpu_to_be_32(owner_opcode | + ((sq->head & sq->txbb_cnt) ? + MLX4_BIT_WQE_OWN : 0)); + sq->head += nr_txbbs; elt->buf = buf; bytes_sent += buf->pkt_len; ++elts_comp; elts_head = elts_head_next; } -stop: /* Take a shortcut if nothing must be sent. */ if (unlikely(i == 0)) return 0; -- 1.8.3.1