1
2
3
4
5
6
7
8
9
10
11
12#include "bfa_cee.h"
13#include "bfi_cna.h"
14#include "bfa_ioc.h"
15
16static void bfa_cee_format_lldp_cfg(struct bfa_cee_lldp_cfg *lldp_cfg);
17static void bfa_cee_format_cee_cfg(void *buffer);
18
19static void
20bfa_cee_format_cee_cfg(void *buffer)
21{
22 struct bfa_cee_attr *cee_cfg = buffer;
23 bfa_cee_format_lldp_cfg(&cee_cfg->lldp_remote);
24}
25
26static void
27bfa_cee_stats_swap(struct bfa_cee_stats *stats)
28{
29 u32 *buffer = (u32 *)stats;
30 int i;
31
32 for (i = 0; i < (sizeof(struct bfa_cee_stats) / sizeof(u32));
33 i++) {
34 buffer[i] = ntohl(buffer[i]);
35 }
36}
37
38static void
39bfa_cee_format_lldp_cfg(struct bfa_cee_lldp_cfg *lldp_cfg)
40{
41 lldp_cfg->time_to_live =
42 ntohs(lldp_cfg->time_to_live);
43 lldp_cfg->enabled_system_cap =
44 ntohs(lldp_cfg->enabled_system_cap);
45}
46
47
48
49
50static u32
51bfa_cee_attr_meminfo(void)
52{
53 return roundup(sizeof(struct bfa_cee_attr), BFA_DMA_ALIGN_SZ);
54}
55
56
57
58static u32
59bfa_cee_stats_meminfo(void)
60{
61 return roundup(sizeof(struct bfa_cee_stats), BFA_DMA_ALIGN_SZ);
62}
63
64
65
66
67
68
69
70static void
71bfa_cee_get_attr_isr(struct bfa_cee *cee, enum bfa_status status)
72{
73 cee->get_attr_status = status;
74 if (status == BFA_STATUS_OK) {
75 memcpy(cee->attr, cee->attr_dma.kva,
76 sizeof(struct bfa_cee_attr));
77 bfa_cee_format_cee_cfg(cee->attr);
78 }
79 cee->get_attr_pending = false;
80 if (cee->cbfn.get_attr_cbfn)
81 cee->cbfn.get_attr_cbfn(cee->cbfn.get_attr_cbarg, status);
82}
83
84
85
86
87
88
89
90static void
91bfa_cee_get_stats_isr(struct bfa_cee *cee, enum bfa_status status)
92{
93 cee->get_stats_status = status;
94 if (status == BFA_STATUS_OK) {
95 memcpy(cee->stats, cee->stats_dma.kva,
96 sizeof(struct bfa_cee_stats));
97 bfa_cee_stats_swap(cee->stats);
98 }
99 cee->get_stats_pending = false;
100 if (cee->cbfn.get_stats_cbfn)
101 cee->cbfn.get_stats_cbfn(cee->cbfn.get_stats_cbarg, status);
102}
103
104
105
106
107
108
109
110
111
112
113
114static void
115bfa_cee_reset_stats_isr(struct bfa_cee *cee, enum bfa_status status)
116{
117 cee->reset_stats_status = status;
118 cee->reset_stats_pending = false;
119 if (cee->cbfn.reset_stats_cbfn)
120 cee->cbfn.reset_stats_cbfn(cee->cbfn.reset_stats_cbarg, status);
121}
122
123
124
125u32
126bfa_nw_cee_meminfo(void)
127{
128 return bfa_cee_attr_meminfo() + bfa_cee_stats_meminfo();
129}
130
131
132
133
134
135
136
137
138void
139bfa_nw_cee_mem_claim(struct bfa_cee *cee, u8 *dma_kva, u64 dma_pa)
140{
141 cee->attr_dma.kva = dma_kva;
142 cee->attr_dma.pa = dma_pa;
143 cee->stats_dma.kva = dma_kva + bfa_cee_attr_meminfo();
144 cee->stats_dma.pa = dma_pa + bfa_cee_attr_meminfo();
145 cee->attr = (struct bfa_cee_attr *) dma_kva;
146 cee->stats = (struct bfa_cee_stats *)
147 (dma_kva + bfa_cee_attr_meminfo());
148}
149
150
151
152
153
154
155
156
157enum bfa_status
158bfa_nw_cee_get_attr(struct bfa_cee *cee, struct bfa_cee_attr *attr,
159 bfa_cee_get_attr_cbfn_t cbfn, void *cbarg)
160{
161 struct bfi_cee_get_req *cmd;
162
163 BUG_ON(!((cee != NULL) && (cee->ioc != NULL)));
164 if (!bfa_nw_ioc_is_operational(cee->ioc))
165 return BFA_STATUS_IOC_FAILURE;
166
167 if (cee->get_attr_pending)
168 return BFA_STATUS_DEVBUSY;
169
170 cee->get_attr_pending = true;
171 cmd = (struct bfi_cee_get_req *) cee->get_cfg_mb.msg;
172 cee->attr = attr;
173 cee->cbfn.get_attr_cbfn = cbfn;
174 cee->cbfn.get_attr_cbarg = cbarg;
175 bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_CFG_REQ,
176 bfa_ioc_portid(cee->ioc));
177 bfa_dma_be_addr_set(cmd->dma_addr, cee->attr_dma.pa);
178 bfa_nw_ioc_mbox_queue(cee->ioc, &cee->get_cfg_mb, NULL, NULL);
179
180 return BFA_STATUS_OK;
181}
182
183
184
185
186
187static void
188bfa_cee_isr(void *cbarg, struct bfi_mbmsg *m)
189{
190 union bfi_cee_i2h_msg_u *msg;
191 struct bfi_cee_get_rsp *get_rsp;
192 struct bfa_cee *cee = (struct bfa_cee *) cbarg;
193 msg = (union bfi_cee_i2h_msg_u *) m;
194 get_rsp = (struct bfi_cee_get_rsp *) m;
195 switch (msg->mh.msg_id) {
196 case BFI_CEE_I2H_GET_CFG_RSP:
197 bfa_cee_get_attr_isr(cee, get_rsp->cmd_status);
198 break;
199 case BFI_CEE_I2H_GET_STATS_RSP:
200 bfa_cee_get_stats_isr(cee, get_rsp->cmd_status);
201 break;
202 case BFI_CEE_I2H_RESET_STATS_RSP:
203 bfa_cee_reset_stats_isr(cee, get_rsp->cmd_status);
204 break;
205 default:
206 BUG_ON(1);
207 }
208}
209
210
211
212
213
214
215
216static void
217bfa_cee_notify(void *arg, enum bfa_ioc_event event)
218{
219 struct bfa_cee *cee;
220 cee = (struct bfa_cee *) arg;
221
222 switch (event) {
223 case BFA_IOC_E_DISABLED:
224 case BFA_IOC_E_FAILED:
225 if (cee->get_attr_pending) {
226 cee->get_attr_status = BFA_STATUS_FAILED;
227 cee->get_attr_pending = false;
228 if (cee->cbfn.get_attr_cbfn) {
229 cee->cbfn.get_attr_cbfn(
230 cee->cbfn.get_attr_cbarg,
231 BFA_STATUS_FAILED);
232 }
233 }
234 if (cee->get_stats_pending) {
235 cee->get_stats_status = BFA_STATUS_FAILED;
236 cee->get_stats_pending = false;
237 if (cee->cbfn.get_stats_cbfn) {
238 cee->cbfn.get_stats_cbfn(
239 cee->cbfn.get_stats_cbarg,
240 BFA_STATUS_FAILED);
241 }
242 }
243 if (cee->reset_stats_pending) {
244 cee->reset_stats_status = BFA_STATUS_FAILED;
245 cee->reset_stats_pending = false;
246 if (cee->cbfn.reset_stats_cbfn) {
247 cee->cbfn.reset_stats_cbfn(
248 cee->cbfn.reset_stats_cbarg,
249 BFA_STATUS_FAILED);
250 }
251 }
252 break;
253
254 default:
255 break;
256 }
257}
258
259
260
261
262
263
264
265
266
267
268void
269bfa_nw_cee_attach(struct bfa_cee *cee, struct bfa_ioc *ioc,
270 void *dev)
271{
272 BUG_ON(!(cee != NULL));
273 cee->dev = dev;
274 cee->ioc = ioc;
275
276 bfa_nw_ioc_mbox_regisr(cee->ioc, BFI_MC_CEE, bfa_cee_isr, cee);
277 bfa_ioc_notify_init(&cee->ioc_notify, bfa_cee_notify, cee);
278 bfa_nw_ioc_notify_register(cee->ioc, &cee->ioc_notify);
279}
280