bfa_sm.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #define bfa_sm_set_state(_sm, _state) ((_sm)->sm = (bfa_sm_t)(_state))
  24. #define bfa_sm_send_event(_sm, _event) ((_sm)->sm((_sm), (_event)))
  25. #define bfa_sm_get_state(_sm) ((_sm)->sm)
  26. #define bfa_sm_cmp_state(_sm, _state) ((_sm)->sm == (bfa_sm_t)(_state))
  27. /**
  28. * For converting from state machine function to state encoding.
  29. */
  30. struct bfa_sm_table_s {
  31. bfa_sm_t sm; /* state machine function */
  32. int state; /* state machine encoding */
  33. char *name; /* state name for display */
  34. };
  35. #define BFA_SM(_sm) ((bfa_sm_t)(_sm))
  36. int bfa_sm_to_state(struct bfa_sm_table_s *smt, bfa_sm_t sm);
  37. /**
  38. * State machine with entry actions.
  39. */
  40. typedef void (*bfa_fsm_t)(void *fsm, int event);
  41. /**
  42. * oc - object class eg. bfa_ioc
  43. * st - state, eg. reset
  44. * otype - object type, eg. struct bfa_ioc_s
  45. * etype - object type, eg. enum ioc_event
  46. */
  47. #define bfa_fsm_state_decl(oc, st, otype, etype) \
  48. static void oc ## _sm_ ## st(otype * fsm, etype event); \
  49. static void oc ## _sm_ ## st ## _entry(otype * fsm)
  50. #define bfa_fsm_set_state(_fsm, _state) do { \
  51. (_fsm)->fsm = (bfa_fsm_t)(_state); \
  52. _state ## _entry(_fsm); \
  53. } while (0)
  54. #define bfa_fsm_send_event(_fsm, _event) \
  55. ((_fsm)->fsm((_fsm), (_event)))
  56. #define bfa_fsm_cmp_state(_fsm, _state) \
  57. ((_fsm)->fsm == (bfa_fsm_t)(_state))
  58. #endif