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