bfa_msgq.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #ifndef __BFA_MSGQ_H__
  12. #define __BFA_MSGQ_H__
  13. #include "bfa_defs.h"
  14. #include "bfi.h"
  15. #include "bfa_ioc.h"
  16. #include "bfa_cs.h"
  17. #define BFA_MSGQ_FREE_CNT(_q) \
  18. (((_q)->consumer_index - (_q)->producer_index - 1) & ((_q)->depth - 1))
  19. #define BFA_MSGQ_INDX_ADD(_q_indx, _qe_num, _q_depth) \
  20. ((_q_indx) = (((_q_indx) + (_qe_num)) & ((_q_depth) - 1)))
  21. #define BFA_MSGQ_CMDQ_NUM_ENTRY 128
  22. #define BFA_MSGQ_CMDQ_SIZE \
  23. (BFI_MSGQ_CMD_ENTRY_SIZE * BFA_MSGQ_CMDQ_NUM_ENTRY)
  24. #define BFA_MSGQ_RSPQ_NUM_ENTRY 128
  25. #define BFA_MSGQ_RSPQ_SIZE \
  26. (BFI_MSGQ_RSP_ENTRY_SIZE * BFA_MSGQ_RSPQ_NUM_ENTRY)
  27. #define bfa_msgq_cmd_set(_cmd, _cbfn, _cbarg, _msg_size, _msg_hdr) \
  28. do { \
  29. (_cmd)->cbfn = (_cbfn); \
  30. (_cmd)->cbarg = (_cbarg); \
  31. (_cmd)->msg_size = (_msg_size); \
  32. (_cmd)->msg_hdr = (_msg_hdr); \
  33. } while (0)
  34. struct bfa_msgq;
  35. typedef void (*bfa_msgq_cmdcbfn_t)(void *cbarg, enum bfa_status status);
  36. struct bfa_msgq_cmd_entry {
  37. struct list_head qe;
  38. bfa_msgq_cmdcbfn_t cbfn;
  39. void *cbarg;
  40. size_t msg_size;
  41. struct bfi_msgq_mhdr *msg_hdr;
  42. };
  43. enum bfa_msgq_cmdq_flags {
  44. BFA_MSGQ_CMDQ_F_DB_UPDATE = 1,
  45. };
  46. enum cmdq_event;
  47. struct bfa_msgq_cmdq {
  48. void (*fsm)(struct bfa_msgq_cmdq *s, enum cmdq_event e);
  49. enum bfa_msgq_cmdq_flags flags;
  50. u16 producer_index;
  51. u16 consumer_index;
  52. u16 depth; /* FW Q depth is 16 bits */
  53. struct bfa_dma addr;
  54. struct bfa_mbox_cmd dbell_mb;
  55. u16 token;
  56. int offset;
  57. int bytes_to_copy;
  58. struct bfa_mbox_cmd copy_mb;
  59. struct list_head pending_q; /* pending command queue */
  60. struct bfa_msgq *msgq;
  61. };
  62. enum bfa_msgq_rspq_flags {
  63. BFA_MSGQ_RSPQ_F_DB_UPDATE = 1,
  64. };
  65. typedef void (*bfa_msgq_mcfunc_t)(void *cbarg, struct bfi_msgq_mhdr *mhdr);
  66. enum rspq_event;
  67. struct bfa_msgq_rspq {
  68. void (*fsm)(struct bfa_msgq_rspq *s, enum rspq_event e);
  69. enum bfa_msgq_rspq_flags flags;
  70. u16 producer_index;
  71. u16 consumer_index;
  72. u16 depth; /* FW Q depth is 16 bits */
  73. struct bfa_dma addr;
  74. struct bfa_mbox_cmd dbell_mb;
  75. int nmclass;
  76. struct {
  77. bfa_msgq_mcfunc_t cbfn;
  78. void *cbarg;
  79. } rsphdlr[BFI_MC_MAX];
  80. struct bfa_msgq *msgq;
  81. };
  82. struct bfa_msgq {
  83. struct bfa_msgq_cmdq cmdq;
  84. struct bfa_msgq_rspq rspq;
  85. struct bfa_wc init_wc;
  86. struct bfa_mbox_cmd init_mb;
  87. struct bfa_ioc_notify ioc_notify;
  88. struct bfa_ioc *ioc;
  89. };
  90. u32 bfa_msgq_meminfo(void);
  91. void bfa_msgq_memclaim(struct bfa_msgq *msgq, u8 *kva, u64 pa);
  92. void bfa_msgq_attach(struct bfa_msgq *msgq, struct bfa_ioc *ioc);
  93. void bfa_msgq_regisr(struct bfa_msgq *msgq, enum bfi_mclass mc,
  94. bfa_msgq_mcfunc_t cbfn, void *cbarg);
  95. void bfa_msgq_cmd_post(struct bfa_msgq *msgq,
  96. struct bfa_msgq_cmd_entry *cmd);
  97. void bfa_msgq_rsp_copy(struct bfa_msgq *msgq, u8 *buf, size_t buf_len);
  98. #endif