[SCSI] bfa: Added HBA diagnostics support.
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / scsi / bfa / bfa_port.c
CommitLineData
7725ccfd 1/*
a36c61f9 2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
7725ccfd
JH
3 * All rights reserved
4 * www.brocade.com
5 *
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 */
17
f16a1750 18#include "bfad_drv.h"
a36c61f9
KG
19#include "bfa_defs_svc.h"
20#include "bfa_port.h"
21#include "bfi.h"
22#include "bfa_ioc.h"
23
7725ccfd
JH
24
25BFA_TRC_FILE(CNA, PORT);
26
7725ccfd 27static void
a36c61f9 28bfa_port_stats_swap(struct bfa_port_s *port, union bfa_port_stats_u *stats)
7725ccfd 29{
a36c61f9 30 u32 *dip = (u32 *) stats;
50444a34 31 __be32 t0, t1;
a36c61f9 32 int i;
7725ccfd 33
a36c61f9
KG
34 for (i = 0; i < sizeof(union bfa_port_stats_u)/sizeof(u32);
35 i += 2) {
7725ccfd
JH
36 t0 = dip[i];
37 t1 = dip[i + 1];
f16a1750 38#ifdef __BIG_ENDIAN
ba816ea8
JH
39 dip[i] = be32_to_cpu(t0);
40 dip[i + 1] = be32_to_cpu(t1);
7725ccfd 41#else
ba816ea8
JH
42 dip[i] = be32_to_cpu(t1);
43 dip[i + 1] = be32_to_cpu(t0);
7725ccfd
JH
44#endif
45 }
7725ccfd
JH
46}
47
5fbe25c7 48/*
7725ccfd
JH
49 * bfa_port_enable_isr()
50 *
51 *
52 * @param[in] port - Pointer to the port module
53 * status - Return status from the f/w
54 *
55 * @return void
56 */
57static void
58bfa_port_enable_isr(struct bfa_port_s *port, bfa_status_t status)
59{
a36c61f9
KG
60 bfa_trc(port, status);
61 port->endis_pending = BFA_FALSE;
62 port->endis_cbfn(port->endis_cbarg, status);
7725ccfd
JH
63}
64
5fbe25c7 65/*
7725ccfd
JH
66 * bfa_port_disable_isr()
67 *
68 *
69 * @param[in] port - Pointer to the port module
70 * status - Return status from the f/w
71 *
72 * @return void
73 */
74static void
75bfa_port_disable_isr(struct bfa_port_s *port, bfa_status_t status)
76{
a36c61f9
KG
77 bfa_trc(port, status);
78 port->endis_pending = BFA_FALSE;
79 port->endis_cbfn(port->endis_cbarg, status);
7725ccfd
JH
80}
81
5fbe25c7 82/*
7725ccfd
JH
83 * bfa_port_get_stats_isr()
84 *
85 *
86 * @param[in] port - Pointer to the Port module
87 * status - Return status from the f/w
88 *
89 * @return void
90 */
91static void
92bfa_port_get_stats_isr(struct bfa_port_s *port, bfa_status_t status)
93{
94 port->stats_status = status;
95 port->stats_busy = BFA_FALSE;
96
97 if (status == BFA_STATUS_OK) {
f16a1750 98 struct timeval tv;
b85d045e 99
7725ccfd 100 memcpy(port->stats, port->stats_dma.kva,
a36c61f9 101 sizeof(union bfa_port_stats_u));
7725ccfd 102 bfa_port_stats_swap(port, port->stats);
b85d045e 103
f16a1750 104 do_gettimeofday(&tv);
b85d045e 105 port->stats->fc.secs_reset = tv.tv_sec - port->stats_reset_time;
7725ccfd
JH
106 }
107
108 if (port->stats_cbfn) {
109 port->stats_cbfn(port->stats_cbarg, status);
110 port->stats_cbfn = NULL;
111 }
112}
113
5fbe25c7 114/*
7725ccfd
JH
115 * bfa_port_clear_stats_isr()
116 *
117 *
118 * @param[in] port - Pointer to the Port module
119 * status - Return status from the f/w
120 *
121 * @return void
122 */
123static void
124bfa_port_clear_stats_isr(struct bfa_port_s *port, bfa_status_t status)
125{
f16a1750 126 struct timeval tv;
b85d045e 127
7725ccfd 128 port->stats_status = status;
a36c61f9 129 port->stats_busy = BFA_FALSE;
7725ccfd 130
5fbe25c7 131 /*
a36c61f9
KG
132 * re-initialize time stamp for stats reset
133 */
f16a1750 134 do_gettimeofday(&tv);
b85d045e
JH
135 port->stats_reset_time = tv.tv_sec;
136
7725ccfd
JH
137 if (port->stats_cbfn) {
138 port->stats_cbfn(port->stats_cbarg, status);
139 port->stats_cbfn = NULL;
140 }
141}
142
5fbe25c7 143/*
7725ccfd
JH
144 * bfa_port_isr()
145 *
146 *
147 * @param[in] Pointer to the Port module data structure.
148 *
149 * @return void
150 */
151static void
152bfa_port_isr(void *cbarg, struct bfi_mbmsg_s *m)
153{
a36c61f9 154 struct bfa_port_s *port = (struct bfa_port_s *) cbarg;
7725ccfd
JH
155 union bfi_port_i2h_msg_u *i2hmsg;
156
a36c61f9 157 i2hmsg = (union bfi_port_i2h_msg_u *) m;
7725ccfd
JH
158 bfa_trc(port, m->mh.msg_id);
159
160 switch (m->mh.msg_id) {
161 case BFI_PORT_I2H_ENABLE_RSP:
162 if (port->endis_pending == BFA_FALSE)
163 break;
164 bfa_port_enable_isr(port, i2hmsg->enable_rsp.status);
165 break;
166
167 case BFI_PORT_I2H_DISABLE_RSP:
168 if (port->endis_pending == BFA_FALSE)
169 break;
170 bfa_port_disable_isr(port, i2hmsg->disable_rsp.status);
171 break;
172
173 case BFI_PORT_I2H_GET_STATS_RSP:
a36c61f9 174 /* Stats busy flag is still set? (may be cmd timed out) */
7725ccfd
JH
175 if (port->stats_busy == BFA_FALSE)
176 break;
177 bfa_port_get_stats_isr(port, i2hmsg->getstats_rsp.status);
178 break;
179
180 case BFI_PORT_I2H_CLEAR_STATS_RSP:
181 if (port->stats_busy == BFA_FALSE)
182 break;
183 bfa_port_clear_stats_isr(port, i2hmsg->clearstats_rsp.status);
184 break;
185
186 default:
d4b671c5 187 WARN_ON(1);
7725ccfd
JH
188 }
189}
190
5fbe25c7 191/*
7725ccfd
JH
192 * bfa_port_meminfo()
193 *
194 *
195 * @param[in] void
196 *
197 * @return Size of DMA region
198 */
199u32
200bfa_port_meminfo(void)
201{
a36c61f9 202 return BFA_ROUNDUP(sizeof(union bfa_port_stats_u), BFA_DMA_ALIGN_SZ);
7725ccfd
JH
203}
204
5fbe25c7 205/*
7725ccfd
JH
206 * bfa_port_mem_claim()
207 *
208 *
209 * @param[in] port Port module pointer
a36c61f9
KG
210 * dma_kva Kernel Virtual Address of Port DMA Memory
211 * dma_pa Physical Address of Port DMA Memory
7725ccfd
JH
212 *
213 * @return void
214 */
215void
216bfa_port_mem_claim(struct bfa_port_s *port, u8 *dma_kva, u64 dma_pa)
217{
218 port->stats_dma.kva = dma_kva;
a36c61f9 219 port->stats_dma.pa = dma_pa;
7725ccfd
JH
220}
221
5fbe25c7 222/*
7725ccfd
JH
223 * bfa_port_enable()
224 *
225 * Send the Port enable request to the f/w
226 *
227 * @param[in] Pointer to the Port module data structure.
228 *
229 * @return Status
230 */
231bfa_status_t
232bfa_port_enable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
a36c61f9 233 void *cbarg)
7725ccfd
JH
234{
235 struct bfi_port_generic_req_s *m;
236
43ffdf4d
KG
237 /* If port is PBC disabled, return error */
238 if (port->pbc_disabled) {
239 bfa_trc(port, BFA_STATUS_PBC);
240 return BFA_STATUS_PBC;
241 }
242
a36c61f9
KG
243 if (bfa_ioc_is_disabled(port->ioc)) {
244 bfa_trc(port, BFA_STATUS_IOC_DISABLED);
245 return BFA_STATUS_IOC_DISABLED;
246 }
7725ccfd
JH
247
248 if (!bfa_ioc_is_operational(port->ioc)) {
249 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
250 return BFA_STATUS_IOC_FAILURE;
251 }
252
253 if (port->endis_pending) {
254 bfa_trc(port, BFA_STATUS_DEVBUSY);
255 return BFA_STATUS_DEVBUSY;
256 }
257
a36c61f9 258 m = (struct bfi_port_generic_req_s *) port->endis_mb.msg;
7725ccfd
JH
259
260 port->msgtag++;
a36c61f9
KG
261 port->endis_cbfn = cbfn;
262 port->endis_cbarg = cbarg;
7725ccfd
JH
263 port->endis_pending = BFA_TRUE;
264
265 bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_ENABLE_REQ,
266 bfa_ioc_portid(port->ioc));
267 bfa_ioc_mbox_queue(port->ioc, &port->endis_mb);
268
269 return BFA_STATUS_OK;
270}
271
5fbe25c7 272/*
7725ccfd
JH
273 * bfa_port_disable()
274 *
275 * Send the Port disable request to the f/w
276 *
277 * @param[in] Pointer to the Port module data structure.
278 *
279 * @return Status
280 */
281bfa_status_t
282bfa_port_disable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
a36c61f9 283 void *cbarg)
7725ccfd
JH
284{
285 struct bfi_port_generic_req_s *m;
286
43ffdf4d
KG
287 /* If port is PBC disabled, return error */
288 if (port->pbc_disabled) {
289 bfa_trc(port, BFA_STATUS_PBC);
290 return BFA_STATUS_PBC;
291 }
292
a36c61f9
KG
293 if (bfa_ioc_is_disabled(port->ioc)) {
294 bfa_trc(port, BFA_STATUS_IOC_DISABLED);
295 return BFA_STATUS_IOC_DISABLED;
296 }
7725ccfd
JH
297
298 if (!bfa_ioc_is_operational(port->ioc)) {
299 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
300 return BFA_STATUS_IOC_FAILURE;
301 }
302
303 if (port->endis_pending) {
304 bfa_trc(port, BFA_STATUS_DEVBUSY);
305 return BFA_STATUS_DEVBUSY;
306 }
307
a36c61f9 308 m = (struct bfi_port_generic_req_s *) port->endis_mb.msg;
7725ccfd
JH
309
310 port->msgtag++;
a36c61f9
KG
311 port->endis_cbfn = cbfn;
312 port->endis_cbarg = cbarg;
7725ccfd
JH
313 port->endis_pending = BFA_TRUE;
314
315 bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_DISABLE_REQ,
316 bfa_ioc_portid(port->ioc));
317 bfa_ioc_mbox_queue(port->ioc, &port->endis_mb);
318
319 return BFA_STATUS_OK;
320}
321
5fbe25c7 322/*
7725ccfd
JH
323 * bfa_port_get_stats()
324 *
325 * Send the request to the f/w to fetch Port statistics.
326 *
327 * @param[in] Pointer to the Port module data structure.
328 *
329 * @return Status
330 */
331bfa_status_t
a36c61f9
KG
332bfa_port_get_stats(struct bfa_port_s *port, union bfa_port_stats_u *stats,
333 bfa_port_stats_cbfn_t cbfn, void *cbarg)
7725ccfd
JH
334{
335 struct bfi_port_get_stats_req_s *m;
336
337 if (!bfa_ioc_is_operational(port->ioc)) {
338 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
339 return BFA_STATUS_IOC_FAILURE;
340 }
341
342 if (port->stats_busy) {
343 bfa_trc(port, BFA_STATUS_DEVBUSY);
344 return BFA_STATUS_DEVBUSY;
345 }
346
a36c61f9 347 m = (struct bfi_port_get_stats_req_s *) port->stats_mb.msg;
7725ccfd 348
a36c61f9
KG
349 port->stats = stats;
350 port->stats_cbfn = cbfn;
7725ccfd 351 port->stats_cbarg = cbarg;
a36c61f9 352 port->stats_busy = BFA_TRUE;
7725ccfd
JH
353 bfa_dma_be_addr_set(m->dma_addr, port->stats_dma.pa);
354
355 bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_GET_STATS_REQ,
356 bfa_ioc_portid(port->ioc));
357 bfa_ioc_mbox_queue(port->ioc, &port->stats_mb);
358
359 return BFA_STATUS_OK;
360}
361
5fbe25c7 362/*
7725ccfd
JH
363 * bfa_port_clear_stats()
364 *
365 *
366 * @param[in] Pointer to the Port module data structure.
367 *
368 * @return Status
369 */
370bfa_status_t
371bfa_port_clear_stats(struct bfa_port_s *port, bfa_port_stats_cbfn_t cbfn,
a36c61f9 372 void *cbarg)
7725ccfd
JH
373{
374 struct bfi_port_generic_req_s *m;
375
376 if (!bfa_ioc_is_operational(port->ioc)) {
377 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
378 return BFA_STATUS_IOC_FAILURE;
379 }
380
381 if (port->stats_busy) {
382 bfa_trc(port, BFA_STATUS_DEVBUSY);
383 return BFA_STATUS_DEVBUSY;
384 }
385
a36c61f9 386 m = (struct bfi_port_generic_req_s *) port->stats_mb.msg;
7725ccfd 387
a36c61f9 388 port->stats_cbfn = cbfn;
7725ccfd 389 port->stats_cbarg = cbarg;
a36c61f9 390 port->stats_busy = BFA_TRUE;
7725ccfd
JH
391
392 bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_CLEAR_STATS_REQ,
393 bfa_ioc_portid(port->ioc));
394 bfa_ioc_mbox_queue(port->ioc, &port->stats_mb);
395
396 return BFA_STATUS_OK;
397}
398
5fbe25c7 399/*
d37779f8 400 * bfa_port_notify()
7725ccfd 401 *
d37779f8 402 * Port module IOC event handler
7725ccfd
JH
403 *
404 * @param[in] Pointer to the Port module data structure.
d37779f8 405 * @param[in] IOC event structure
7725ccfd
JH
406 *
407 * @return void
408 */
409void
d37779f8 410bfa_port_notify(void *arg, enum bfa_ioc_event_e event)
7725ccfd 411{
a36c61f9 412 struct bfa_port_s *port = (struct bfa_port_s *) arg;
7725ccfd 413
d37779f8
KG
414 switch (event) {
415 case BFA_IOC_E_DISABLED:
416 case BFA_IOC_E_FAILED:
417 /* Fail any pending get_stats/clear_stats requests */
418 if (port->stats_busy) {
419 if (port->stats_cbfn)
420 port->stats_cbfn(port->stats_cbarg,
421 BFA_STATUS_FAILED);
422 port->stats_cbfn = NULL;
423 port->stats_busy = BFA_FALSE;
424 }
425
426 /* Clear any enable/disable is pending */
427 if (port->endis_pending) {
428 if (port->endis_cbfn)
429 port->endis_cbfn(port->endis_cbarg,
430 BFA_STATUS_FAILED);
431 port->endis_cbfn = NULL;
432 port->endis_pending = BFA_FALSE;
433 }
434 break;
435 default:
436 break;
7725ccfd
JH
437 }
438}
439
5fbe25c7 440/*
7725ccfd
JH
441 * bfa_port_attach()
442 *
443 *
444 * @param[in] port - Pointer to the Port module data structure
445 * ioc - Pointer to the ioc module data structure
446 * dev - Pointer to the device driver module data structure
447 * The device driver specific mbox ISR functions have
448 * this pointer as one of the parameters.
449 * trcmod -
7725ccfd
JH
450 *
451 * @return void
452 */
453void
a36c61f9
KG
454bfa_port_attach(struct bfa_port_s *port, struct bfa_ioc_s *ioc,
455 void *dev, struct bfa_trc_mod_s *trcmod)
7725ccfd 456{
f16a1750 457 struct timeval tv;
b85d045e 458
d4b671c5 459 WARN_ON(!port);
7725ccfd 460
a36c61f9
KG
461 port->dev = dev;
462 port->ioc = ioc;
7725ccfd 463 port->trcmod = trcmod;
7725ccfd 464
b85d045e
JH
465 port->stats_busy = BFA_FALSE;
466 port->endis_pending = BFA_FALSE;
467 port->stats_cbfn = NULL;
468 port->endis_cbfn = NULL;
43ffdf4d 469 port->pbc_disabled = BFA_FALSE;
7725ccfd
JH
470
471 bfa_ioc_mbox_regisr(port->ioc, BFI_MC_PORT, bfa_port_isr, port);
d37779f8
KG
472 bfa_ioc_notify_init(&port->ioc_notify, bfa_port_notify, port);
473 list_add_tail(&port->ioc_notify.qe, &port->ioc->notify_q);
7725ccfd 474
5fbe25c7 475 /*
b85d045e
JH
476 * initialize time stamp for stats reset
477 */
f16a1750 478 do_gettimeofday(&tv);
b85d045e
JH
479 port->stats_reset_time = tv.tv_sec;
480
7725ccfd
JH
481 bfa_trc(port, 0);
482}
148d6103
KG
483
484/*
485 * CEE module specific definitions
486 */
487
488/*
489 * bfa_cee_get_attr_isr()
490 *
491 * @brief CEE ISR for get-attributes responses from f/w
492 *
493 * @param[in] cee - Pointer to the CEE module
494 * status - Return status from the f/w
495 *
496 * @return void
497 */
498static void
499bfa_cee_get_attr_isr(struct bfa_cee_s *cee, bfa_status_t status)
500{
501 struct bfa_cee_lldp_cfg_s *lldp_cfg = &cee->attr->lldp_remote;
502
503 cee->get_attr_status = status;
504 bfa_trc(cee, 0);
505 if (status == BFA_STATUS_OK) {
506 bfa_trc(cee, 0);
507 memcpy(cee->attr, cee->attr_dma.kva,
508 sizeof(struct bfa_cee_attr_s));
509 lldp_cfg->time_to_live = be16_to_cpu(lldp_cfg->time_to_live);
510 lldp_cfg->enabled_system_cap =
511 be16_to_cpu(lldp_cfg->enabled_system_cap);
512 }
513 cee->get_attr_pending = BFA_FALSE;
514 if (cee->cbfn.get_attr_cbfn) {
515 bfa_trc(cee, 0);
516 cee->cbfn.get_attr_cbfn(cee->cbfn.get_attr_cbarg, status);
517 }
518}
519
520/*
521 * bfa_cee_get_stats_isr()
522 *
523 * @brief CEE ISR for get-stats responses from f/w
524 *
525 * @param[in] cee - Pointer to the CEE module
526 * status - Return status from the f/w
527 *
528 * @return void
529 */
530static void
531bfa_cee_get_stats_isr(struct bfa_cee_s *cee, bfa_status_t status)
532{
533 u32 *buffer;
534 int i;
535
536 cee->get_stats_status = status;
537 bfa_trc(cee, 0);
538 if (status == BFA_STATUS_OK) {
539 bfa_trc(cee, 0);
540 memcpy(cee->stats, cee->stats_dma.kva,
541 sizeof(struct bfa_cee_stats_s));
542 /* swap the cee stats */
543 buffer = (u32 *)cee->stats;
544 for (i = 0; i < (sizeof(struct bfa_cee_stats_s) /
545 sizeof(u32)); i++)
546 buffer[i] = cpu_to_be32(buffer[i]);
547 }
548 cee->get_stats_pending = BFA_FALSE;
549 bfa_trc(cee, 0);
550 if (cee->cbfn.get_stats_cbfn) {
551 bfa_trc(cee, 0);
552 cee->cbfn.get_stats_cbfn(cee->cbfn.get_stats_cbarg, status);
553 }
554}
555
556/*
557 * bfa_cee_reset_stats_isr()
558 *
559 * @brief CEE ISR for reset-stats responses from f/w
560 *
561 * @param[in] cee - Pointer to the CEE module
562 * status - Return status from the f/w
563 *
564 * @return void
565 */
566static void
567bfa_cee_reset_stats_isr(struct bfa_cee_s *cee, bfa_status_t status)
568{
569 cee->reset_stats_status = status;
570 cee->reset_stats_pending = BFA_FALSE;
571 if (cee->cbfn.reset_stats_cbfn)
572 cee->cbfn.reset_stats_cbfn(cee->cbfn.reset_stats_cbarg, status);
573}
574
575/*
576 * bfa_cee_meminfo()
577 *
578 * @brief Returns the size of the DMA memory needed by CEE module
579 *
580 * @param[in] void
581 *
582 * @return Size of DMA region
583 */
584u32
585bfa_cee_meminfo(void)
586{
587 return BFA_ROUNDUP(sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ) +
588 BFA_ROUNDUP(sizeof(struct bfa_cee_stats_s), BFA_DMA_ALIGN_SZ);
589}
590
591/*
592 * bfa_cee_mem_claim()
593 *
594 * @brief Initialized CEE DMA Memory
595 *
596 * @param[in] cee CEE module pointer
597 * dma_kva Kernel Virtual Address of CEE DMA Memory
598 * dma_pa Physical Address of CEE DMA Memory
599 *
600 * @return void
601 */
602void
603bfa_cee_mem_claim(struct bfa_cee_s *cee, u8 *dma_kva, u64 dma_pa)
604{
605 cee->attr_dma.kva = dma_kva;
606 cee->attr_dma.pa = dma_pa;
607 cee->stats_dma.kva = dma_kva + BFA_ROUNDUP(
608 sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ);
609 cee->stats_dma.pa = dma_pa + BFA_ROUNDUP(
610 sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ);
611 cee->attr = (struct bfa_cee_attr_s *) dma_kva;
612 cee->stats = (struct bfa_cee_stats_s *) (dma_kva + BFA_ROUNDUP(
613 sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ));
614}
615
616/*
617 * bfa_cee_get_attr()
618 *
619 * @brief
620 * Send the request to the f/w to fetch CEE attributes.
621 *
622 * @param[in] Pointer to the CEE module data structure.
623 *
624 * @return Status
625 */
626
627bfa_status_t
628bfa_cee_get_attr(struct bfa_cee_s *cee, struct bfa_cee_attr_s *attr,
629 bfa_cee_get_attr_cbfn_t cbfn, void *cbarg)
630{
631 struct bfi_cee_get_req_s *cmd;
632
633 WARN_ON((cee == NULL) || (cee->ioc == NULL));
634 bfa_trc(cee, 0);
635 if (!bfa_ioc_is_operational(cee->ioc)) {
636 bfa_trc(cee, 0);
637 return BFA_STATUS_IOC_FAILURE;
638 }
639 if (cee->get_attr_pending == BFA_TRUE) {
640 bfa_trc(cee, 0);
641 return BFA_STATUS_DEVBUSY;
642 }
643 cee->get_attr_pending = BFA_TRUE;
644 cmd = (struct bfi_cee_get_req_s *) cee->get_cfg_mb.msg;
645 cee->attr = attr;
646 cee->cbfn.get_attr_cbfn = cbfn;
647 cee->cbfn.get_attr_cbarg = cbarg;
648 bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_CFG_REQ,
649 bfa_ioc_portid(cee->ioc));
650 bfa_dma_be_addr_set(cmd->dma_addr, cee->attr_dma.pa);
651 bfa_ioc_mbox_queue(cee->ioc, &cee->get_cfg_mb);
652
653 return BFA_STATUS_OK;
654}
655
656/*
657 * bfa_cee_get_stats()
658 *
659 * @brief
660 * Send the request to the f/w to fetch CEE statistics.
661 *
662 * @param[in] Pointer to the CEE module data structure.
663 *
664 * @return Status
665 */
666
667bfa_status_t
668bfa_cee_get_stats(struct bfa_cee_s *cee, struct bfa_cee_stats_s *stats,
669 bfa_cee_get_stats_cbfn_t cbfn, void *cbarg)
670{
671 struct bfi_cee_get_req_s *cmd;
672
673 WARN_ON((cee == NULL) || (cee->ioc == NULL));
674
675 if (!bfa_ioc_is_operational(cee->ioc)) {
676 bfa_trc(cee, 0);
677 return BFA_STATUS_IOC_FAILURE;
678 }
679 if (cee->get_stats_pending == BFA_TRUE) {
680 bfa_trc(cee, 0);
681 return BFA_STATUS_DEVBUSY;
682 }
683 cee->get_stats_pending = BFA_TRUE;
684 cmd = (struct bfi_cee_get_req_s *) cee->get_stats_mb.msg;
685 cee->stats = stats;
686 cee->cbfn.get_stats_cbfn = cbfn;
687 cee->cbfn.get_stats_cbarg = cbarg;
688 bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_STATS_REQ,
689 bfa_ioc_portid(cee->ioc));
690 bfa_dma_be_addr_set(cmd->dma_addr, cee->stats_dma.pa);
691 bfa_ioc_mbox_queue(cee->ioc, &cee->get_stats_mb);
692
693 return BFA_STATUS_OK;
694}
695
696/*
697 * bfa_cee_reset_stats()
698 *
699 * @brief Clears CEE Stats in the f/w.
700 *
701 * @param[in] Pointer to the CEE module data structure.
702 *
703 * @return Status
704 */
705
706bfa_status_t
707bfa_cee_reset_stats(struct bfa_cee_s *cee,
708 bfa_cee_reset_stats_cbfn_t cbfn, void *cbarg)
709{
710 struct bfi_cee_reset_stats_s *cmd;
711
712 WARN_ON((cee == NULL) || (cee->ioc == NULL));
713 if (!bfa_ioc_is_operational(cee->ioc)) {
714 bfa_trc(cee, 0);
715 return BFA_STATUS_IOC_FAILURE;
716 }
717 if (cee->reset_stats_pending == BFA_TRUE) {
718 bfa_trc(cee, 0);
719 return BFA_STATUS_DEVBUSY;
720 }
721 cee->reset_stats_pending = BFA_TRUE;
722 cmd = (struct bfi_cee_reset_stats_s *) cee->reset_stats_mb.msg;
723 cee->cbfn.reset_stats_cbfn = cbfn;
724 cee->cbfn.reset_stats_cbarg = cbarg;
725 bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_RESET_STATS,
726 bfa_ioc_portid(cee->ioc));
727 bfa_ioc_mbox_queue(cee->ioc, &cee->reset_stats_mb);
728
729 return BFA_STATUS_OK;
730}
731
732/*
733 * bfa_cee_isrs()
734 *
735 * @brief Handles Mail-box interrupts for CEE module.
736 *
737 * @param[in] Pointer to the CEE module data structure.
738 *
739 * @return void
740 */
741
742void
743bfa_cee_isr(void *cbarg, struct bfi_mbmsg_s *m)
744{
745 union bfi_cee_i2h_msg_u *msg;
746 struct bfi_cee_get_rsp_s *get_rsp;
747 struct bfa_cee_s *cee = (struct bfa_cee_s *) cbarg;
748 msg = (union bfi_cee_i2h_msg_u *) m;
749 get_rsp = (struct bfi_cee_get_rsp_s *) m;
750 bfa_trc(cee, msg->mh.msg_id);
751 switch (msg->mh.msg_id) {
752 case BFI_CEE_I2H_GET_CFG_RSP:
753 bfa_trc(cee, get_rsp->cmd_status);
754 bfa_cee_get_attr_isr(cee, get_rsp->cmd_status);
755 break;
756 case BFI_CEE_I2H_GET_STATS_RSP:
757 bfa_cee_get_stats_isr(cee, get_rsp->cmd_status);
758 break;
759 case BFI_CEE_I2H_RESET_STATS_RSP:
760 bfa_cee_reset_stats_isr(cee, get_rsp->cmd_status);
761 break;
762 default:
763 WARN_ON(1);
764 }
765}
766
767/*
768 * bfa_cee_notify()
769 *
770 * @brief CEE module IOC event handler.
771 *
772 * @param[in] Pointer to the CEE module data structure.
773 * @param[in] IOC event type
774 *
775 * @return void
776 */
777
778void
779bfa_cee_notify(void *arg, enum bfa_ioc_event_e event)
780{
781 struct bfa_cee_s *cee = (struct bfa_cee_s *) arg;
782
783 bfa_trc(cee, event);
784
785 switch (event) {
786 case BFA_IOC_E_DISABLED:
787 case BFA_IOC_E_FAILED:
788 if (cee->get_attr_pending == BFA_TRUE) {
789 cee->get_attr_status = BFA_STATUS_FAILED;
790 cee->get_attr_pending = BFA_FALSE;
791 if (cee->cbfn.get_attr_cbfn) {
792 cee->cbfn.get_attr_cbfn(
793 cee->cbfn.get_attr_cbarg,
794 BFA_STATUS_FAILED);
795 }
796 }
797 if (cee->get_stats_pending == BFA_TRUE) {
798 cee->get_stats_status = BFA_STATUS_FAILED;
799 cee->get_stats_pending = BFA_FALSE;
800 if (cee->cbfn.get_stats_cbfn) {
801 cee->cbfn.get_stats_cbfn(
802 cee->cbfn.get_stats_cbarg,
803 BFA_STATUS_FAILED);
804 }
805 }
806 if (cee->reset_stats_pending == BFA_TRUE) {
807 cee->reset_stats_status = BFA_STATUS_FAILED;
808 cee->reset_stats_pending = BFA_FALSE;
809 if (cee->cbfn.reset_stats_cbfn) {
810 cee->cbfn.reset_stats_cbfn(
811 cee->cbfn.reset_stats_cbarg,
812 BFA_STATUS_FAILED);
813 }
814 }
815 break;
816
817 default:
818 break;
819 }
820}
821
822/*
823 * bfa_cee_attach()
824 *
825 * @brief CEE module-attach API
826 *
827 * @param[in] cee - Pointer to the CEE module data structure
828 * ioc - Pointer to the ioc module data structure
829 * dev - Pointer to the device driver module data structure
830 * The device driver specific mbox ISR functions have
831 * this pointer as one of the parameters.
832 *
833 * @return void
834 */
835void
836bfa_cee_attach(struct bfa_cee_s *cee, struct bfa_ioc_s *ioc,
837 void *dev)
838{
839 WARN_ON(cee == NULL);
840 cee->dev = dev;
841 cee->ioc = ioc;
842
843 bfa_ioc_mbox_regisr(cee->ioc, BFI_MC_CEE, bfa_cee_isr, cee);
844 bfa_q_qe_init(&cee->ioc_notify);
845 bfa_ioc_notify_init(&cee->ioc_notify, bfa_cee_notify, cee);
846 list_add_tail(&cee->ioc_notify.qe, &cee->ioc->notify_q);
847}