4 * Copyright(c) Broadcom Limited.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Broadcom Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <rte_memzone.h>
38 #include "bnxt_ring.h"
41 #include "hsi_struct_def_dpdk.h"
44 * Generic ring handling
47 void bnxt_free_ring(struct bnxt_ring *ring)
49 if (ring->vmem_size && *ring->vmem) {
50 memset((char *)*ring->vmem, 0, ring->vmem_size);
56 * Allocates a completion ring with vmem and stats optionally also allocating
57 * a TX and/or RX ring. Passing NULL as tx_ring_info and/or rx_ring_info
58 * to not allocate them.
60 * Order in the allocation is:
61 * stats - Always non-zero length
62 * cp vmem - Always zero-length, supported for the bnxt_ring abstraction
63 * tx vmem - Only non-zero length if tx_ring_info is not NULL
64 * rx vmem - Only non-zero length if rx_ring_info is not NULL
65 * cp bd ring - Always non-zero length
66 * tx bd ring - Only non-zero length if tx_ring_info is not NULL
67 * rx bd ring - Only non-zero length if rx_ring_info is not NULL
69 int bnxt_alloc_rings(struct bnxt *bp, uint16_t qidx,
70 struct bnxt_tx_ring_info *tx_ring_info,
71 struct bnxt_rx_ring_info *rx_ring_info,
72 struct bnxt_cp_ring_info *cp_ring_info,
75 struct bnxt_ring *cp_ring = cp_ring_info->cp_ring_struct;
76 struct bnxt_ring *tx_ring;
78 /* struct bnxt_ring *rx_ring; */
79 struct rte_pci_device *pdev = bp->pdev;
80 const struct rte_memzone *mz = NULL;
81 char mz_name[RTE_MEMZONE_NAMESIZE];
83 int stats_len = (tx_ring_info || rx_ring_info) ?
84 RTE_CACHE_LINE_ROUNDUP(sizeof(struct ctx_hw_stats64)) : 0;
86 int cp_vmem_start = stats_len;
87 int cp_vmem_len = RTE_CACHE_LINE_ROUNDUP(cp_ring->vmem_size);
89 int tx_vmem_start = cp_vmem_start + cp_vmem_len;
91 tx_ring_info ? RTE_CACHE_LINE_ROUNDUP(tx_ring_info->
92 tx_ring_struct->vmem_size) : 0;
94 int rx_vmem_start = tx_vmem_start + tx_vmem_len;
98 * rx_ring_info ? RTE_CACHE_LINE_ROUNDUP(rx_ring_info->
99 * rx_ring_struct->vmem_size) : 0;
102 int cp_ring_start = rx_vmem_start + rx_vmem_len;
103 int cp_ring_len = RTE_CACHE_LINE_ROUNDUP(cp_ring->ring_size *
104 sizeof(struct cmpl_base));
106 int tx_ring_start = cp_ring_start + cp_ring_len;
107 int tx_ring_len = tx_ring_info ?
108 RTE_CACHE_LINE_ROUNDUP(tx_ring_info->tx_ring_struct->ring_size *
109 sizeof(struct tx_bd_long)) : 0;
111 int rx_ring_start = tx_ring_start + tx_ring_len;
116 * RTE_CACHE_LINE_ROUNDUP(rx_ring_info->rx_ring_struct->ring_size *
117 * sizeof(struct rx_prod_pkt_bd)) : 0;
120 int total_alloc_len = rx_ring_start + rx_ring_len;
122 snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
123 "bnxt_%04x:%02x:%02x:%02x-%04x_%s", pdev->addr.domain,
124 pdev->addr.bus, pdev->addr.devid, pdev->addr.function, qidx,
126 mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
127 mz = rte_memzone_lookup(mz_name);
129 mz = rte_memzone_reserve(mz_name, total_alloc_len,
132 RTE_MEMZONE_SIZE_HINT_ONLY);
136 memset(mz->addr, 0, mz->len);
139 tx_ring = tx_ring_info->tx_ring_struct;
141 tx_ring->bd = ((char *)mz->addr + tx_ring_start);
142 tx_ring_info->tx_desc_ring = (struct tx_bd_long *)tx_ring->bd;
143 tx_ring->bd_dma = mz->phys_addr + tx_ring_start;
144 tx_ring_info->tx_desc_mapping = tx_ring->bd_dma;
148 if (tx_ring->vmem_size) {
150 (void **)((char *)mz->addr + tx_vmem_start);
151 tx_ring_info->tx_buf_ring =
152 (struct bnxt_sw_tx_bd *)tx_ring->vmem;
157 * if (rx_ring_info) {
158 * rx_ring = &rx_ring_info->rx_ring_struct;
160 * rx_ring->bd = ((char *)mz->addr + rx_ring_start);
161 * rx_ring_info->rx_desc_ring =
162 * (struct rx_prod_pkt_bd *)rx_ring->bd;
163 * rx_ring->bd_dma = mz->phys_addr + rx_ring_start;
164 * rx_ring_info->rx_desc_mapping = rx_ring->bd_dma;
168 * if (rx_ring->vmem_size) {
170 * (void **)((char *)mz->addr + rx_vmem_start);
171 * rx_ring_info->rx_buf_ring =
172 * (struct bnxt_sw_rx_bd *)rx_ring->vmem;
177 cp_ring->bd = ((char *)mz->addr + cp_ring_start);
178 cp_ring->bd_dma = mz->phys_addr + cp_ring_start;
179 cp_ring_info->cp_desc_ring = cp_ring->bd;
180 cp_ring_info->cp_desc_mapping = cp_ring->bd_dma;
184 if (cp_ring->vmem_size)
185 *cp_ring->vmem = ((char *)mz->addr + stats_len);
187 cp_ring_info->hw_stats = mz->addr;
188 cp_ring_info->hw_stats_map = mz->phys_addr;
190 cp_ring_info->hw_stats_ctx_id = HWRM_NA_SIGNATURE;