/drivers/net/ethernet/brocade/bna/bfa_cs.h

http://github.com/mirrors/linux · C Header · 103 lines · 61 code · 20 blank · 22 comment · 7 complexity · 55bddb85b52d28a8ff8383293c497426 MD5 · raw file

  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Linux network driver for QLogic BR-series Converged Network Adapter.
  4. */
  5. /*
  6. * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
  7. * Copyright (c) 2014-2015 QLogic Corporation
  8. * All rights reserved
  9. * www.qlogic.com
  10. */
  11. /* BFA common services */
  12. #ifndef __BFA_CS_H__
  13. #define __BFA_CS_H__
  14. #include "cna.h"
  15. /* BFA state machine interfaces */
  16. typedef void (*bfa_sm_t)(void *sm, int event);
  17. /* For converting from state machine function to state encoding. */
  18. struct bfa_sm_table {
  19. bfa_sm_t sm; /*!< state machine function */
  20. int state; /*!< state machine encoding */
  21. char *name; /*!< state name for display */
  22. };
  23. #define BFA_SM(_sm) ((bfa_sm_t)(_sm))
  24. /* State machine with entry actions. */
  25. typedef void (*bfa_fsm_t)(void *fsm, int event);
  26. /* oc - object class eg. bfa_ioc
  27. * st - state, eg. reset
  28. * otype - object type, eg. struct bfa_ioc
  29. * etype - object type, eg. enum ioc_event
  30. */
  31. #define bfa_fsm_state_decl(oc, st, otype, etype) \
  32. static void oc ## _sm_ ## st(otype * fsm, etype event); \
  33. static void oc ## _sm_ ## st ## _entry(otype * fsm)
  34. #define bfa_fsm_set_state(_fsm, _state) do { \
  35. (_fsm)->fsm = (bfa_fsm_t)(_state); \
  36. _state ## _entry(_fsm); \
  37. } while (0)
  38. #define bfa_fsm_send_event(_fsm, _event) ((_fsm)->fsm((_fsm), (_event)))
  39. #define bfa_fsm_cmp_state(_fsm, _state) \
  40. ((_fsm)->fsm == (bfa_fsm_t)(_state))
  41. static inline int
  42. bfa_sm_to_state(const struct bfa_sm_table *smt, bfa_sm_t sm)
  43. {
  44. int i = 0;
  45. while (smt[i].sm && smt[i].sm != sm)
  46. i++;
  47. return smt[i].state;
  48. }
  49. /* Generic wait counter. */
  50. typedef void (*bfa_wc_resume_t) (void *cbarg);
  51. struct bfa_wc {
  52. bfa_wc_resume_t wc_resume;
  53. void *wc_cbarg;
  54. int wc_count;
  55. };
  56. static inline void
  57. bfa_wc_up(struct bfa_wc *wc)
  58. {
  59. wc->wc_count++;
  60. }
  61. static inline void
  62. bfa_wc_down(struct bfa_wc *wc)
  63. {
  64. wc->wc_count--;
  65. if (wc->wc_count == 0)
  66. wc->wc_resume(wc->wc_cbarg);
  67. }
  68. /* Initialize a waiting counter. */
  69. static inline void
  70. bfa_wc_init(struct bfa_wc *wc, bfa_wc_resume_t wc_resume, void *wc_cbarg)
  71. {
  72. wc->wc_resume = wc_resume;
  73. wc->wc_cbarg = wc_cbarg;
  74. wc->wc_count = 0;
  75. bfa_wc_up(wc);
  76. }
  77. /* Wait for counter to reach zero */
  78. static inline void
  79. bfa_wc_wait(struct bfa_wc *wc)
  80. {
  81. bfa_wc_down(wc);
  82. }
  83. #endif /* __BFA_CS_H__ */