From patchwork Mon Jul 13 09:42:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Somnath Kotur X-Patchwork-Id: 73896 X-Patchwork-Delegate: ajit.khaparde@broadcom.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E2A15A0540; Mon, 13 Jul 2020 11:48:16 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7D2FC1D5C2; Mon, 13 Jul 2020 11:47:36 +0200 (CEST) Received: from relay.smtp.broadcom.com (relay.smtp.broadcom.com [192.19.232.149]) by dpdk.org (Postfix) with ESMTP id 090AF1D58A for ; Mon, 13 Jul 2020 11:47:31 +0200 (CEST) Received: from dhcp-10-123-153-55.dhcp.broadcom.net (dhcp-10-123-153-55.dhcp.broadcom.net [10.123.153.55]) by relay.smtp.broadcom.com (Postfix) with ESMTP id 9A8D81BBBE6; Mon, 13 Jul 2020 02:47:30 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.10.3 relay.smtp.broadcom.com 9A8D81BBBE6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1594633651; bh=8dxShUVk0C5pAAsJVQcu9rI0ANnBp0inpXHNwh5rhwY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J1AuboVi0iOhloW6fAN5pZKxlVEgFzCShLfsvkZAVusVLZLt0TuQmTRen5zHGbGEI YW8IPnp2PBgX94Pe+vR9ZmwXdSXoqey4LApqMfxxm7KrWqK15kHtBP567cDGDFDOj7 TU6SXEjNTkdzqH6mQCZyjMYY7s42F1gUz/haVmls= From: Somnath Kotur To: dev@dpdk.org Cc: ferruh.yigit@intel.com Date: Mon, 13 Jul 2020 15:12:08 +0530 Message-Id: <20200713094213.21410-6-somnath.kotur@broadcom.com> X-Mailer: git-send-email 2.10.1.613.g2cc2e70 In-Reply-To: <20200713094213.21410-1-somnath.kotur@broadcom.com> References: <20200713061600.19456-1-somnath.kotur@broadcom.com> <20200713094213.21410-1-somnath.kotur@broadcom.com> Subject: [dpdk-dev] [PATCH 05/10] net/bnxt: add support to extract data from the ulp blob 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" From: Kishore Padmanabha Extended the ulp blob to extract data from the blob for a given offset and length. The support is added only for little endian format. Signed-off-by: Kishore Padmanabha Reviewed-by: Randy Schacher Signed-off-by: Somnath Kotur --- drivers/net/bnxt/tf_ulp/ulp_utils.c | 76 +++++++++++++++++++++++++++++++++++++ drivers/net/bnxt/tf_ulp/ulp_utils.h | 17 +++++++++ 2 files changed, 93 insertions(+) diff --git a/drivers/net/bnxt/tf_ulp/ulp_utils.c b/drivers/net/bnxt/tf_ulp/ulp_utils.c index 3afaac6..a923da8 100644 --- a/drivers/net/bnxt/tf_ulp/ulp_utils.c +++ b/drivers/net/bnxt/tf_ulp/ulp_utils.c @@ -418,6 +418,82 @@ ulp_blob_pad_push(struct ulp_blob *blob, return datalen; } +/* Get data from src and put into dst using little-endian format */ +static void +ulp_bs_get_lsb(uint8_t *src, uint16_t bitpos, uint8_t bitlen, uint8_t *dst) +{ + uint8_t bitoffs = bitpos % ULP_BLOB_BYTE; + uint16_t index = ULP_BITS_2_BYTE_NR(bitpos); + uint8_t mask, partial, shift; + + shift = bitoffs; + partial = ULP_BLOB_BYTE - bitoffs; + if (bitoffs + bitlen <= ULP_BLOB_BYTE) { + mask = ((1 << bitlen) - 1) << shift; + *dst = (src[index] & mask) >> shift; + } else { + mask = ((1 << partial) - 1) << shift; + *dst = (src[index] & mask) >> shift; + index++; + partial = bitlen - partial; + mask = ((1 << partial) - 1); + *dst |= (src[index] & mask) << (ULP_BLOB_BYTE - bitoffs); + } +} + +/* Assuming that src is in little-Endian Format */ +static void +ulp_bs_pull_lsb(uint8_t *src, uint8_t *dst, uint32_t size, + uint32_t offset, uint32_t len) +{ + uint32_t idx; + uint32_t cnt = ULP_BITS_2_BYTE_NR(len); + + /* iterate bytewise to get data */ + for (idx = 0; idx < cnt; idx++) { + ulp_bs_get_lsb(src, offset, ULP_BLOB_BYTE, + &dst[size - 1 - idx]); + offset += ULP_BLOB_BYTE; + len -= ULP_BLOB_BYTE; + } + + /* Extract the last reminder data that is not 8 byte boundary */ + if (len) + ulp_bs_get_lsb(src, offset, len, &dst[size - 1 - idx]); +} + +/* + * Extract data from the binary blob using given offset. + * + * blob [in] The blob that data is extracted from. The blob must + * be initialized prior to pulling data. + * + * data [in] A pointer to put the data. + * data_size [in] size of the data buffer in bytes. + *offset [in] - Offset in the blob to extract the data in bits format. + * len [in] The number of bits to be pulled from the blob. + * + * Output: zero on success, -1 on failure + */ +int32_t +ulp_blob_pull(struct ulp_blob *blob, uint8_t *data, uint32_t data_size, + uint16_t offset, uint16_t len) +{ + /* validate the arguments */ + if (!blob || (offset + len) > blob->bitlen || + ULP_BYTE_2_BITS(data_size) < len) { + BNXT_TF_DBG(ERR, "invalid argument\n"); + return -1; /* failure */ + } + + if (blob->byte_order == BNXT_ULP_BYTE_ORDER_BE) { + BNXT_TF_DBG(ERR, "Big endian pull not implemented\n"); + return -1; /* failure */ + } + ulp_bs_pull_lsb(blob->data, data, data_size, offset, len); + return 0; +} + /* * Get the data portion of the binary blob. * diff --git a/drivers/net/bnxt/tf_ulp/ulp_utils.h b/drivers/net/bnxt/tf_ulp/ulp_utils.h index 97c7750..22dfb17 100644 --- a/drivers/net/bnxt/tf_ulp/ulp_utils.h +++ b/drivers/net/bnxt/tf_ulp/ulp_utils.h @@ -229,6 +229,23 @@ ulp_blob_data_get(struct ulp_blob *blob, uint16_t *datalen); /* + * Extract data from the binary blob using given offset. + * + * blob [in] The blob that data is extracted from. The blob must + * be initialized prior to pulling data. + * + * data [in] A pointer to put the data. + * data_size [in] size of the data buffer in bytes. + *offset [in] - Offset in the blob to extract the data in bits format. + * len [in] The number of bits to be pulled from the blob. + * + * Output: zero on success, -1 on failure + */ +int32_t +ulp_blob_pull(struct ulp_blob *blob, uint8_t *data, uint32_t data_size, + uint16_t offset, uint16_t len); + +/* * Adds pad to an initialized blob at the current offset * * blob [in] The blob that data is added to. The blob must