bfa_sm.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. * @file bfasm.h State machine defines
  20. */
  21. #ifndef __BFA_SM_H__
  22. #define __BFA_SM_H__
  23. #include "cna.h"
  24. typedef void (*bfa_sm_t)(void *sm, int event);
  25. /**
  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_sm_state_decl(oc, st, otype, etype) \
  32. static void oc ## _sm_ ## st(otype * fsm, etype event)
  33. #define bfa_sm_set_state(_sm, _state) ((_sm)->sm = (bfa_sm_t)(_state))
  34. #define bfa_sm_send_event(_sm, _event) ((_sm)->sm((_sm), (_event)))
  35. #define bfa_sm_get_state(_sm) ((_sm)->sm)
  36. #define bfa_sm_cmp_state(_sm, _state) ((_sm)->sm == (bfa_sm_t)(_state))
  37. /**
  38. * For converting from state machine function to state encoding.
  39. */
  40. struct bfa_sm_table {
  41. bfa_sm_t sm; /*!< state machine function */
  42. int state; /*!< state machine encoding */
  43. char *name; /*!< state name for display */
  44. };
  45. #define BFA_SM(_sm) ((bfa_sm_t)(_sm))
  46. /**
  47. * State machine with entry actions.
  48. */
  49. typedef void (*bfa_fsm_t)(void *fsm, int event);
  50. /**
  51. * oc - object class eg. bfa_ioc
  52. * st - state, eg. reset
  53. * otype - object type, eg. struct bfa_ioc
  54. * etype - object type, eg. enum ioc_event
  55. */
  56. #define bfa_fsm_state_decl(oc, st, otype, etype) \
  57. static void oc ## _sm_ ## st(otype * fsm, etype event); \
  58. static void oc ## _sm_ ## st ## _entry(otype * fsm)
  59. #define bfa_fsm_set_state(_fsm, _state) do { \
  60. (_fsm)->fsm = (bfa_fsm_t)(_state); \
  61. _state ## _entry(_fsm); \
  62. } while (0)
  63. #define bfa_fsm_send_event(_fsm, _event) ((_fsm)->fsm((_fsm), (_event)))
  64. #define bfa_fsm_get_state(_fsm) ((_fsm)->fsm)
  65. #define bfa_fsm_cmp_state(_fsm, _state) \
  66. ((_fsm)->fsm == (bfa_fsm_t)(_state))
  67. static inline int
  68. bfa_sm_to_state(const struct bfa_sm_table *smt, bfa_sm_t sm)
  69. {
  70. int i = 0;
  71. while (smt[i].sm && smt[i].sm != sm)
  72. i++;
  73. return smt[i].state;
  74. }
  75. #endif