bfa_sm.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
  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. /**
  18. * bfasm.h State machine defines
  19. */
  20. #ifndef __BFA_SM_H__
  21. #define __BFA_SM_H__
  22. typedef void (*bfa_sm_t)(void *sm, int event);
  23. /**
  24. * oc - object class eg. bfa_ioc
  25. * st - state, eg. reset
  26. * otype - object type, eg. struct bfa_ioc_s
  27. * etype - object type, eg. enum ioc_event
  28. */
  29. #define bfa_sm_state_decl(oc, st, otype, etype) \
  30. static void oc ## _sm_ ## st(otype * fsm, etype event)
  31. #define bfa_sm_set_state(_sm, _state) ((_sm)->sm = (bfa_sm_t)(_state))
  32. #define bfa_sm_send_event(_sm, _event) ((_sm)->sm((_sm), (_event)))
  33. #define bfa_sm_get_state(_sm) ((_sm)->sm)
  34. #define bfa_sm_cmp_state(_sm, _state) ((_sm)->sm == (bfa_sm_t)(_state))
  35. /**
  36. * For converting from state machine function to state encoding.
  37. */
  38. struct bfa_sm_table_s {
  39. bfa_sm_t sm; /* state machine function */
  40. int state; /* state machine encoding */
  41. char *name; /* state name for display */
  42. };
  43. #define BFA_SM(_sm) ((bfa_sm_t)(_sm))
  44. int bfa_sm_to_state(struct bfa_sm_table_s *smt, bfa_sm_t sm);
  45. /**
  46. * State machine with entry actions.
  47. */
  48. typedef void (*bfa_fsm_t)(void *fsm, int event);
  49. /**
  50. * oc - object class eg. bfa_ioc
  51. * st - state, eg. reset
  52. * otype - object type, eg. struct bfa_ioc_s
  53. * etype - object type, eg. enum ioc_event
  54. */
  55. #define bfa_fsm_state_decl(oc, st, otype, etype) \
  56. static void oc ## _sm_ ## st(otype * fsm, etype event); \
  57. static void oc ## _sm_ ## st ## _entry(otype * fsm)
  58. #define bfa_fsm_set_state(_fsm, _state) do { \
  59. (_fsm)->fsm = (bfa_fsm_t)(_state); \
  60. _state ## _entry(_fsm); \
  61. } while (0)
  62. #define bfa_fsm_send_event(_fsm, _event) \
  63. ((_fsm)->fsm((_fsm), (_event)))
  64. #define bfa_fsm_cmp_state(_fsm, _state) \
  65. ((_fsm)->fsm == (bfa_fsm_t)(_state))
  66. #endif