1
2
3
4
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
26
27
28
29
30int
31tfp_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
58
59
60
61
62int
63tfp_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
91
92
93
94
95int
96tfp_calloc(struct tfp_calloc_parms *parms)
97{
98 if (parms == NULL)
99 return -EINVAL;
100
101 parms->mem_va = rte_zmalloc("tf",
102 (parms->nitems * parms->size),
103 parms->alignment);
104 if (parms->mem_va == NULL) {
105 TFP_DRV_LOG(ERR, "Allocate failed mem_va\n");
106 return -ENOMEM;
107 }
108
109 parms->mem_pa = (void *)((uintptr_t)rte_mem_virt2iova(parms->mem_va));
110 if (parms->mem_pa == (void *)((uintptr_t)RTE_BAD_IOVA)) {
111 TFP_DRV_LOG(ERR, "Allocate failed mem_pa\n");
112 return -ENOMEM;
113 }
114
115 return 0;
116}
117
118
119
120
121
122void
123tfp_free(void *addr)
124{
125 rte_free(addr);
126}
127
128
129
130
131
132void
133tfp_memcpy(void *dest, void *src, size_t n)
134{
135 rte_memcpy(dest, src, n);
136}
137
138
139
140
141void
142tfp_spinlock_init(struct tfp_spinlock_parms *parms)
143{
144 rte_spinlock_init(&parms->slock);
145}
146
147
148
149
150void
151tfp_spinlock_lock(struct tfp_spinlock_parms *parms)
152{
153 rte_spinlock_lock(&parms->slock);
154}
155
156
157
158
159void
160tfp_spinlock_unlock(struct tfp_spinlock_parms *parms)
161{
162 rte_spinlock_unlock(&parms->slock);
163}
164
165int
166tfp_get_fid(struct tf *tfp, uint16_t *fw_fid)
167{
168 struct bnxt *bp = NULL;
169
170 if (tfp == NULL || fw_fid == NULL)
171 return -EINVAL;
172
173 bp = container_of(tfp, struct bnxt, tfp);
174 if (bp == NULL)
175 return -EINVAL;
176
177 *fw_fid = bp->fw_fid;
178
179 return 0;
180}
181
182int
183tfp_get_pf(struct tf *tfp, uint16_t *pf)
184{
185 struct bnxt *bp = NULL;
186
187 if (tfp == NULL || pf == NULL)
188 return -EINVAL;
189
190 bp = container_of(tfp, struct bnxt, tfp);
191 if (BNXT_VF(bp) && bp->parent) {
192 *pf = bp->parent->fid - 1;
193 return 0;
194 } else if (BNXT_PF(bp)) {
195 *pf = bp->fw_fid - 1;
196 return 0;
197 }
198 return -EINVAL;
199}
200