1545fc9720f81d8b2b97cc6b6ecd4c41b74726b3
[deliverable/linux.git] / drivers / net / bna / bfa_cee.c
1 /*
2 * Linux network driver for Brocade Converged Network Adapter.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License (GPL) Version 2 as
6 * published by the Free Software Foundation
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13 /*
14 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
15 * All rights reserved
16 * www.brocade.com
17 */
18
19 #include "bfa_defs_cna.h"
20 #include "cna.h"
21 #include "bfa_cee.h"
22 #include "bfi_cna.h"
23 #include "bfa_ioc.h"
24
25 #define bfa_ioc_portid(__ioc) ((__ioc)->port_id)
26 #define bfa_lpuid(__arg) bfa_ioc_portid(&(__arg)->ioc)
27
28 static void bfa_cee_format_lldp_cfg(struct bfa_cee_lldp_cfg *lldp_cfg);
29 static void bfa_cee_format_cee_cfg(void *buffer);
30
31 static void
32 bfa_cee_format_cee_cfg(void *buffer)
33 {
34 struct bfa_cee_attr *cee_cfg = buffer;
35 bfa_cee_format_lldp_cfg(&cee_cfg->lldp_remote);
36 }
37
38 static void
39 bfa_cee_stats_swap(struct bfa_cee_stats *stats)
40 {
41 u32 *buffer = (u32 *)stats;
42 int i;
43
44 for (i = 0; i < (sizeof(struct bfa_cee_stats) / sizeof(u32));
45 i++) {
46 buffer[i] = ntohl(buffer[i]);
47 }
48 }
49
50 static void
51 bfa_cee_format_lldp_cfg(struct bfa_cee_lldp_cfg *lldp_cfg)
52 {
53 lldp_cfg->time_to_live =
54 ntohs(lldp_cfg->time_to_live);
55 lldp_cfg->enabled_system_cap =
56 ntohs(lldp_cfg->enabled_system_cap);
57 }
58
59 /**
60 * bfa_cee_attr_meminfo()
61 *
62 * @brief Returns the size of the DMA memory needed by CEE attributes
63 *
64 * @param[in] void
65 *
66 * @return Size of DMA region
67 */
68 static u32
69 bfa_cee_attr_meminfo(void)
70 {
71 return roundup(sizeof(struct bfa_cee_attr), BFA_DMA_ALIGN_SZ);
72 }
73 /**
74 * bfa_cee_stats_meminfo()
75 *
76 * @brief Returns the size of the DMA memory needed by CEE stats
77 *
78 * @param[in] void
79 *
80 * @return Size of DMA region
81 */
82 static u32
83 bfa_cee_stats_meminfo(void)
84 {
85 return roundup(sizeof(struct bfa_cee_stats), BFA_DMA_ALIGN_SZ);
86 }
87
88 /**
89 * bfa_cee_get_attr_isr()
90 *
91 * @brief CEE ISR for get-attributes responses from f/w
92 *
93 * @param[in] cee - Pointer to the CEE module
94 * status - Return status from the f/w
95 *
96 * @return void
97 */
98 static void
99 bfa_cee_get_attr_isr(struct bfa_cee *cee, enum bfa_status status)
100 {
101 cee->get_attr_status = status;
102 if (status == BFA_STATUS_OK) {
103 memcpy(cee->attr, cee->attr_dma.kva,
104 sizeof(struct bfa_cee_attr));
105 bfa_cee_format_cee_cfg(cee->attr);
106 }
107 cee->get_attr_pending = false;
108 if (cee->cbfn.get_attr_cbfn)
109 cee->cbfn.get_attr_cbfn(cee->cbfn.get_attr_cbarg, status);
110 }
111
112 /**
113 * bfa_cee_get_attr_isr()
114 *
115 * @brief CEE ISR for get-stats responses from f/w
116 *
117 * @param[in] cee - Pointer to the CEE module
118 * status - Return status from the f/w
119 *
120 * @return void
121 */
122 static void
123 bfa_cee_get_stats_isr(struct bfa_cee *cee, enum bfa_status status)
124 {
125 cee->get_stats_status = status;
126 if (status == BFA_STATUS_OK) {
127 memcpy(cee->stats, cee->stats_dma.kva,
128 sizeof(struct bfa_cee_stats));
129 bfa_cee_stats_swap(cee->stats);
130 }
131 cee->get_stats_pending = false;
132 if (cee->cbfn.get_stats_cbfn)
133 cee->cbfn.get_stats_cbfn(cee->cbfn.get_stats_cbarg, status);
134 }
135
136 /**
137 * bfa_cee_get_attr_isr()
138 *
139 * @brief CEE ISR for reset-stats responses from f/w
140 *
141 * @param[in] cee - Pointer to the CEE module
142 * status - Return status from the f/w
143 *
144 * @return void
145 */
146 static void
147 bfa_cee_reset_stats_isr(struct bfa_cee *cee, enum bfa_status status)
148 {
149 cee->reset_stats_status = status;
150 cee->reset_stats_pending = false;
151 if (cee->cbfn.reset_stats_cbfn)
152 cee->cbfn.reset_stats_cbfn(cee->cbfn.reset_stats_cbarg, status);
153 }
154 /**
155 * bfa_cee_meminfo()
156 *
157 * @brief Returns the size of the DMA memory needed by CEE module
158 *
159 * @param[in] void
160 *
161 * @return Size of DMA region
162 */
163 u32
164 bfa_cee_meminfo(void)
165 {
166 return bfa_cee_attr_meminfo() + bfa_cee_stats_meminfo();
167 }
168
169 /**
170 * bfa_cee_mem_claim()
171 *
172 * @brief Initialized CEE DMA Memory
173 *
174 * @param[in] cee CEE module pointer
175 * dma_kva Kernel Virtual Address of CEE DMA Memory
176 * dma_pa Physical Address of CEE DMA Memory
177 *
178 * @return void
179 */
180 void
181 bfa_cee_mem_claim(struct bfa_cee *cee, u8 *dma_kva, u64 dma_pa)
182 {
183 cee->attr_dma.kva = dma_kva;
184 cee->attr_dma.pa = dma_pa;
185 cee->stats_dma.kva = dma_kva + bfa_cee_attr_meminfo();
186 cee->stats_dma.pa = dma_pa + bfa_cee_attr_meminfo();
187 cee->attr = (struct bfa_cee_attr *) dma_kva;
188 cee->stats = (struct bfa_cee_stats *)
189 (dma_kva + bfa_cee_attr_meminfo());
190 }
191
192 /**
193 * bfa_cee_get_attr()
194 *
195 * @brief
196 * Send the request to the f/w to fetch CEE attributes.
197 *
198 * @param[in] Pointer to the CEE module data structure.
199 *
200 * @return Status
201 */
202
203 enum bfa_status
204 bfa_cee_get_attr(struct bfa_cee *cee, struct bfa_cee_attr *attr,
205 bfa_cee_get_attr_cbfn_t cbfn, void *cbarg)
206 {
207 struct bfi_cee_get_req *cmd;
208
209 BUG_ON(!((cee != NULL) && (cee->ioc != NULL)));
210 if (!bfa_ioc_is_operational(cee->ioc))
211 return BFA_STATUS_IOC_FAILURE;
212 if (cee->get_attr_pending == true)
213 return BFA_STATUS_DEVBUSY;
214 cee->get_attr_pending = true;
215 cmd = (struct bfi_cee_get_req *) cee->get_cfg_mb.msg;
216 cee->attr = attr;
217 cee->cbfn.get_attr_cbfn = cbfn;
218 cee->cbfn.get_attr_cbarg = cbarg;
219 bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_CFG_REQ,
220 bfa_ioc_portid(cee->ioc));
221 bfa_dma_be_addr_set(cmd->dma_addr, cee->attr_dma.pa);
222 bfa_ioc_mbox_queue(cee->ioc, &cee->get_cfg_mb);
223
224 return BFA_STATUS_OK;
225 }
226
227 /**
228 * bfa_cee_get_stats()
229 *
230 * @brief
231 * Send the request to the f/w to fetch CEE statistics.
232 *
233 * @param[in] Pointer to the CEE module data structure.
234 *
235 * @return Status
236 */
237
238 enum bfa_status
239 bfa_cee_get_stats(struct bfa_cee *cee, struct bfa_cee_stats *stats,
240 bfa_cee_get_stats_cbfn_t cbfn, void *cbarg)
241 {
242 struct bfi_cee_get_req *cmd;
243
244 BUG_ON(!((cee != NULL) && (cee->ioc != NULL)));
245
246 if (!bfa_ioc_is_operational(cee->ioc))
247 return BFA_STATUS_IOC_FAILURE;
248 if (cee->get_stats_pending == true)
249 return BFA_STATUS_DEVBUSY;
250 cee->get_stats_pending = true;
251 cmd = (struct bfi_cee_get_req *) cee->get_stats_mb.msg;
252 cee->stats = stats;
253 cee->cbfn.get_stats_cbfn = cbfn;
254 cee->cbfn.get_stats_cbarg = cbarg;
255 bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_STATS_REQ,
256 bfa_ioc_portid(cee->ioc));
257 bfa_dma_be_addr_set(cmd->dma_addr, cee->stats_dma.pa);
258 bfa_ioc_mbox_queue(cee->ioc, &cee->get_stats_mb);
259
260 return BFA_STATUS_OK;
261 }
262
263 /**
264 * bfa_cee_reset_stats()
265 *
266 * @brief Clears CEE Stats in the f/w.
267 *
268 * @param[in] Pointer to the CEE module data structure.
269 *
270 * @return Status
271 */
272
273 enum bfa_status
274 bfa_cee_reset_stats(struct bfa_cee *cee, bfa_cee_reset_stats_cbfn_t cbfn,
275 void *cbarg)
276 {
277 struct bfi_cee_reset_stats *cmd;
278
279 BUG_ON(!((cee != NULL) && (cee->ioc != NULL)));
280 if (!bfa_ioc_is_operational(cee->ioc))
281 return BFA_STATUS_IOC_FAILURE;
282 if (cee->reset_stats_pending == true)
283 return BFA_STATUS_DEVBUSY;
284 cee->reset_stats_pending = true;
285 cmd = (struct bfi_cee_reset_stats *) cee->reset_stats_mb.msg;
286 cee->cbfn.reset_stats_cbfn = cbfn;
287 cee->cbfn.reset_stats_cbarg = cbarg;
288 bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_RESET_STATS,
289 bfa_ioc_portid(cee->ioc));
290 bfa_ioc_mbox_queue(cee->ioc, &cee->reset_stats_mb);
291 return BFA_STATUS_OK;
292 }
293
294 /**
295 * bfa_cee_isrs()
296 *
297 * @brief Handles Mail-box interrupts for CEE module.
298 *
299 * @param[in] Pointer to the CEE module data structure.
300 *
301 * @return void
302 */
303
304 void
305 bfa_cee_isr(void *cbarg, struct bfi_mbmsg *m)
306 {
307 union bfi_cee_i2h_msg_u *msg;
308 struct bfi_cee_get_rsp *get_rsp;
309 struct bfa_cee *cee = (struct bfa_cee *) cbarg;
310 msg = (union bfi_cee_i2h_msg_u *) m;
311 get_rsp = (struct bfi_cee_get_rsp *) m;
312 switch (msg->mh.msg_id) {
313 case BFI_CEE_I2H_GET_CFG_RSP:
314 bfa_cee_get_attr_isr(cee, get_rsp->cmd_status);
315 break;
316 case BFI_CEE_I2H_GET_STATS_RSP:
317 bfa_cee_get_stats_isr(cee, get_rsp->cmd_status);
318 break;
319 case BFI_CEE_I2H_RESET_STATS_RSP:
320 bfa_cee_reset_stats_isr(cee, get_rsp->cmd_status);
321 break;
322 default:
323 BUG_ON(1);
324 }
325 }
326
327 /**
328 * bfa_cee_hbfail()
329 *
330 * @brief CEE module heart-beat failure handler.
331 *
332 * @param[in] Pointer to the CEE module data structure.
333 *
334 * @return void
335 */
336
337 void
338 bfa_cee_hbfail(void *arg)
339 {
340 struct bfa_cee *cee;
341 cee = (struct bfa_cee *) arg;
342
343 if (cee->get_attr_pending == true) {
344 cee->get_attr_status = BFA_STATUS_FAILED;
345 cee->get_attr_pending = false;
346 if (cee->cbfn.get_attr_cbfn) {
347 cee->cbfn.get_attr_cbfn(cee->cbfn.get_attr_cbarg,
348 BFA_STATUS_FAILED);
349 }
350 }
351 if (cee->get_stats_pending == true) {
352 cee->get_stats_status = BFA_STATUS_FAILED;
353 cee->get_stats_pending = false;
354 if (cee->cbfn.get_stats_cbfn) {
355 cee->cbfn.get_stats_cbfn(cee->cbfn.get_stats_cbarg,
356 BFA_STATUS_FAILED);
357 }
358 }
359 if (cee->reset_stats_pending == true) {
360 cee->reset_stats_status = BFA_STATUS_FAILED;
361 cee->reset_stats_pending = false;
362 if (cee->cbfn.reset_stats_cbfn) {
363 cee->cbfn.reset_stats_cbfn(cee->cbfn.reset_stats_cbarg,
364 BFA_STATUS_FAILED);
365 }
366 }
367 }
368
369 /**
370 * bfa_cee_attach()
371 *
372 * @brief CEE module-attach API
373 *
374 * @param[in] cee - Pointer to the CEE module data structure
375 * ioc - Pointer to the ioc module data structure
376 * dev - Pointer to the device driver module data structure
377 * The device driver specific mbox ISR functions have
378 * this pointer as one of the parameters.
379 *
380 * @return void
381 */
382 void
383 bfa_cee_attach(struct bfa_cee *cee, struct bfa_ioc *ioc,
384 void *dev)
385 {
386 BUG_ON(!(cee != NULL));
387 cee->dev = dev;
388 cee->ioc = ioc;
389
390 bfa_ioc_mbox_regisr(cee->ioc, BFI_MC_CEE, bfa_cee_isr, cee);
391 bfa_ioc_hbfail_init(&cee->hbfail, bfa_cee_hbfail, cee);
392 bfa_ioc_hbfail_register(cee->ioc, &cee->hbfail);
393 }
394
395 /**
396 * bfa_cee_detach()
397 *
398 * @brief CEE module-detach API
399 *
400 * @param[in] cee - Pointer to the CEE module data structure
401 *
402 * @return void
403 */
404 void
405 bfa_cee_detach(struct bfa_cee *cee)
406 {
407 }
This page took 0.039906 seconds and 4 git commands to generate.