net/bnxt: remove unused macro
[dpdk.git] / drivers / net / bnxt / tf_core / tfp.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * see the individual elements.
3  * Copyright(c) 2019-2020 Broadcom
4  * All rights reserved.
5  */
6
7 #include <rte_memcpy.h>
8 #include <rte_byteorder.h>
9 #include <rte_config.h>
10 #include <rte_mbuf.h>
11 #include <rte_ethdev.h>
12 #include <rte_lcore.h>
13 #include <rte_log.h>
14 #include <rte_errno.h>
15 #include <rte_malloc.h>
16 #include <rte_spinlock.h>
17
18 #include "tf_core.h"
19 #include "tfp.h"
20 #include "bnxt.h"
21 #include "bnxt_hwrm.h"
22 #include "tf_msg_common.h"
23
24 /**
25  * Sends TruFlow msg to the TruFlow Firmware using
26  * a message specific HWRM message type.
27  *
28  * Returns success or failure code.
29  */
30 int
31 tfp_send_msg_direct(struct tf *tfp,
32                     struct tfp_send_msg_parms *parms)
33 {
34         int      rc = 0;
35         uint8_t  use_kong_mb = 1;
36
37         if (parms == NULL)
38                 return -EINVAL;
39
40         if (parms->mailbox == TF_CHIMP_MB)
41                 use_kong_mb = 0;
42
43         rc = bnxt_hwrm_tf_message_direct(container_of(tfp,
44                                                struct bnxt,
45                                                tfp),
46                                          use_kong_mb,
47                                          parms->tf_type,
48                                          parms->req_data,
49                                          parms->req_size,
50                                          parms->resp_data,
51                                          parms->resp_size);
52
53         return rc;
54 }
55
56 /**
57  * Sends preformatted TruFlow msg to the TruFlow Firmware using
58  * the Truflow tunnel HWRM message type.
59  *
60  * Returns success or failure code.
61  */
62 int
63 tfp_send_msg_tunneled(struct tf *tfp,
64                       struct tfp_send_msg_parms *parms)
65 {
66         int      rc = 0;
67         uint8_t  use_kong_mb = 1;
68
69         if (parms == NULL)
70                 return -EINVAL;
71
72         if (parms->mailbox == TF_CHIMP_MB)
73                 use_kong_mb = 0;
74
75         rc = bnxt_hwrm_tf_message_tunneled(container_of(tfp,
76                                                   struct bnxt,
77                                                   tfp),
78                                            use_kong_mb,
79                                            parms->tf_type,
80                                            parms->tf_subtype,
81                                            &parms->tf_resp_code,
82                                            parms->req_data,
83                                            parms->req_size,
84                                            parms->resp_data,
85                                            parms->resp_size);
86
87         return rc;
88 }
89
90 #ifdef TF_USE_SYSTEM_MEM
91 int
92 tfp_msg_hwrm_oem_cmd(struct tf *tfp,
93                      uint32_t max_flows)
94 {
95         return bnxt_hwrm_oem_cmd(container_of(tfp,
96                                               struct bnxt,
97                                               tfp),
98                                  max_flows);
99 }
100 #endif /* TF_USE_SYSTEM_MEM */
101
102 /**
103  * Allocates zero'ed memory from the heap.
104  *
105  * Returns success or failure code.
106  */
107 int
108 tfp_calloc(struct tfp_calloc_parms *parms)
109 {
110         if (parms == NULL)
111                 return -EINVAL;
112
113         parms->mem_va = rte_zmalloc("tf",
114                                     (parms->nitems * parms->size),
115                                     parms->alignment);
116         if (parms->mem_va == NULL) {
117                 TFP_DRV_LOG(ERR, "Allocate failed mem_va\n");
118                 return -ENOMEM;
119         }
120
121         parms->mem_pa = (void *)((uintptr_t)rte_mem_virt2iova(parms->mem_va));
122         if (parms->mem_pa == (void *)((uintptr_t)RTE_BAD_IOVA)) {
123                 TFP_DRV_LOG(ERR, "Allocate failed mem_pa\n");
124                 return -ENOMEM;
125         }
126
127         return 0;
128 }
129
130 /**
131  * Frees the memory space pointed to by the provided pointer. The
132  * pointer must have been returned from the tfp_calloc().
133  */
134 void
135 tfp_free(void *addr)
136 {
137         rte_free(addr);
138 }
139
140 /**
141  * Copies n bytes from src memory to dest memory. The memory areas
142  * must not overlap.
143  */
144 void
145 tfp_memcpy(void *dest, void *src, size_t n)
146 {
147         rte_memcpy(dest, src, n);
148 }
149
150 /**
151  * Used to initialize portable spin lock
152  */
153 void
154 tfp_spinlock_init(struct tfp_spinlock_parms *parms)
155 {
156         rte_spinlock_init(&parms->slock);
157 }
158
159 /**
160  * Used to lock portable spin lock
161  */
162 void
163 tfp_spinlock_lock(struct tfp_spinlock_parms *parms)
164 {
165         rte_spinlock_lock(&parms->slock);
166 }
167
168 /**
169  * Used to unlock portable spin lock
170  */
171 void
172 tfp_spinlock_unlock(struct tfp_spinlock_parms *parms)
173 {
174         rte_spinlock_unlock(&parms->slock);
175 }
176
177 int
178 tfp_get_fid(struct tf *tfp, uint16_t *fw_fid)
179 {
180         struct bnxt *bp = NULL;
181
182         if (tfp == NULL || fw_fid == NULL)
183                 return -EINVAL;
184
185         bp = container_of(tfp, struct bnxt, tfp);
186         if (bp == NULL)
187                 return -EINVAL;
188
189         *fw_fid = bp->fw_fid;
190
191         return 0;
192 }