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 bnxt *bp,
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(bp,
44 use_kong_mb,
45 parms->tf_type,
46 parms->req_data,
47 parms->req_size,
48 parms->resp_data,
49 parms->resp_size);
50
51 return rc;
52}
53
54
55
56
57
58
59int
60tfp_calloc(struct tfp_calloc_parms *parms)
61{
62 if (parms == NULL)
63 return -EINVAL;
64
65 parms->mem_va = rte_zmalloc("tf",
66 (parms->nitems * parms->size),
67 parms->alignment);
68 if (parms->mem_va == NULL) {
69 TFP_DRV_LOG(ERR, "Allocate failed mem_va\n");
70 return -ENOMEM;
71 }
72
73 parms->mem_pa = (void *)((uintptr_t)rte_mem_virt2iova(parms->mem_va));
74 if (parms->mem_pa == (void *)((uintptr_t)RTE_BAD_IOVA)) {
75 TFP_DRV_LOG(ERR, "Allocate failed mem_pa\n");
76 return -ENOMEM;
77 }
78
79 return 0;
80}
81
82
83
84
85
86void
87tfp_free(void *addr)
88{
89 rte_free(addr);
90}
91
92
93
94
95
96void
97tfp_memcpy(void *dest, void *src, size_t n)
98{
99 rte_memcpy(dest, src, n);
100}
101
102
103
104
105void
106tfp_spinlock_init(struct tfp_spinlock_parms *parms)
107{
108 rte_spinlock_init(&parms->slock);
109}
110
111
112
113
114void
115tfp_spinlock_lock(struct tfp_spinlock_parms *parms)
116{
117 rte_spinlock_lock(&parms->slock);
118}
119
120
121
122
123void
124tfp_spinlock_unlock(struct tfp_spinlock_parms *parms)
125{
126 rte_spinlock_unlock(&parms->slock);
127}
128
129int
130tfp_get_fid(struct tf *tfp, uint16_t *fw_fid)
131{
132 struct bnxt *bp = NULL;
133
134 if (tfp == NULL || fw_fid == NULL)
135 return -EINVAL;
136
137 bp = (struct bnxt *)tfp->bp;
138 if (bp == NULL)
139 return -EINVAL;
140
141 *fw_fid = bp->fw_fid;
142
143 return 0;
144}
145
146int
147tfp_get_pf(struct tf *tfp, uint16_t *pf)
148{
149 struct bnxt *bp = NULL;
150
151 if (tfp == NULL || pf == NULL)
152 return -EINVAL;
153
154 bp = (struct bnxt *)tfp->bp;
155 if (BNXT_VF(bp) && bp->parent) {
156 *pf = bp->parent->fid - 1;
157 return 0;
158 } else if (BNXT_PF(bp)) {
159 *pf = bp->fw_fid - 1;
160 return 0;
161 }
162 return -EINVAL;
163}
164