hinic_hw_mgmt.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Huawei HiNIC PCI Express Linux driver
  3. * Copyright(c) 2017 Huawei Technologies Co., Ltd
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. */
  15. #ifndef HINIC_HW_MGMT_H
  16. #define HINIC_HW_MGMT_H
  17. #include <linux/types.h>
  18. #include <linux/semaphore.h>
  19. #include <linux/completion.h>
  20. #include <linux/bitops.h>
  21. #include "hinic_hw_if.h"
  22. #include "hinic_hw_api_cmd.h"
  23. #define HINIC_MSG_HEADER_MSG_LEN_SHIFT 0
  24. #define HINIC_MSG_HEADER_MODULE_SHIFT 11
  25. #define HINIC_MSG_HEADER_SEG_LEN_SHIFT 16
  26. #define HINIC_MSG_HEADER_NO_ACK_SHIFT 22
  27. #define HINIC_MSG_HEADER_ASYNC_MGMT_TO_PF_SHIFT 23
  28. #define HINIC_MSG_HEADER_SEQID_SHIFT 24
  29. #define HINIC_MSG_HEADER_LAST_SHIFT 30
  30. #define HINIC_MSG_HEADER_DIRECTION_SHIFT 31
  31. #define HINIC_MSG_HEADER_CMD_SHIFT 32
  32. #define HINIC_MSG_HEADER_ZEROS_SHIFT 40
  33. #define HINIC_MSG_HEADER_PCI_INTF_SHIFT 48
  34. #define HINIC_MSG_HEADER_PF_IDX_SHIFT 50
  35. #define HINIC_MSG_HEADER_MSG_ID_SHIFT 54
  36. #define HINIC_MSG_HEADER_MSG_LEN_MASK 0x7FF
  37. #define HINIC_MSG_HEADER_MODULE_MASK 0x1F
  38. #define HINIC_MSG_HEADER_SEG_LEN_MASK 0x3F
  39. #define HINIC_MSG_HEADER_NO_ACK_MASK 0x1
  40. #define HINIC_MSG_HEADER_ASYNC_MGMT_TO_PF_MASK 0x1
  41. #define HINIC_MSG_HEADER_SEQID_MASK 0x3F
  42. #define HINIC_MSG_HEADER_LAST_MASK 0x1
  43. #define HINIC_MSG_HEADER_DIRECTION_MASK 0x1
  44. #define HINIC_MSG_HEADER_CMD_MASK 0xFF
  45. #define HINIC_MSG_HEADER_ZEROS_MASK 0xFF
  46. #define HINIC_MSG_HEADER_PCI_INTF_MASK 0x3
  47. #define HINIC_MSG_HEADER_PF_IDX_MASK 0xF
  48. #define HINIC_MSG_HEADER_MSG_ID_MASK 0x3FF
  49. #define HINIC_MSG_HEADER_SET(val, member) \
  50. ((u64)((val) & HINIC_MSG_HEADER_##member##_MASK) << \
  51. HINIC_MSG_HEADER_##member##_SHIFT)
  52. #define HINIC_MSG_HEADER_GET(val, member) \
  53. (((val) >> HINIC_MSG_HEADER_##member##_SHIFT) & \
  54. HINIC_MSG_HEADER_##member##_MASK)
  55. enum hinic_mgmt_msg_type {
  56. HINIC_MGMT_MSG_SYNC = 1,
  57. };
  58. enum hinic_cfg_cmd {
  59. HINIC_CFG_NIC_CAP = 0,
  60. };
  61. enum hinic_comm_cmd {
  62. HINIC_COMM_CMD_IO_STATUS_GET = 0x3,
  63. HINIC_COMM_CMD_CMDQ_CTXT_SET = 0x10,
  64. HINIC_COMM_CMD_CMDQ_CTXT_GET = 0x11,
  65. HINIC_COMM_CMD_HWCTXT_SET = 0x12,
  66. HINIC_COMM_CMD_HWCTXT_GET = 0x13,
  67. HINIC_COMM_CMD_SQ_HI_CI_SET = 0x14,
  68. HINIC_COMM_CMD_RES_STATE_SET = 0x24,
  69. HINIC_COMM_CMD_IO_RES_CLEAR = 0x29,
  70. HINIC_COMM_CMD_MAX = 0x32,
  71. };
  72. enum hinic_mgmt_cb_state {
  73. HINIC_MGMT_CB_ENABLED = BIT(0),
  74. HINIC_MGMT_CB_RUNNING = BIT(1),
  75. };
  76. struct hinic_recv_msg {
  77. u8 *msg;
  78. u8 *buf_out;
  79. struct completion recv_done;
  80. u16 cmd;
  81. enum hinic_mod_type mod;
  82. int async_mgmt_to_pf;
  83. u16 msg_len;
  84. u16 msg_id;
  85. };
  86. struct hinic_mgmt_cb {
  87. void (*cb)(void *handle, u8 cmd,
  88. void *buf_in, u16 in_size,
  89. void *buf_out, u16 *out_size);
  90. void *handle;
  91. unsigned long state;
  92. };
  93. struct hinic_pf_to_mgmt {
  94. struct hinic_hwif *hwif;
  95. struct semaphore sync_msg_lock;
  96. u16 sync_msg_id;
  97. u8 *sync_msg_buf;
  98. struct hinic_recv_msg recv_resp_msg_from_mgmt;
  99. struct hinic_recv_msg recv_msg_from_mgmt;
  100. struct hinic_api_cmd_chain *cmd_chain[HINIC_API_CMD_MAX];
  101. struct hinic_mgmt_cb mgmt_cb[HINIC_MOD_MAX];
  102. };
  103. void hinic_register_mgmt_msg_cb(struct hinic_pf_to_mgmt *pf_to_mgmt,
  104. enum hinic_mod_type mod,
  105. void *handle,
  106. void (*callback)(void *handle,
  107. u8 cmd, void *buf_in,
  108. u16 in_size, void *buf_out,
  109. u16 *out_size));
  110. void hinic_unregister_mgmt_msg_cb(struct hinic_pf_to_mgmt *pf_to_mgmt,
  111. enum hinic_mod_type mod);
  112. int hinic_msg_to_mgmt(struct hinic_pf_to_mgmt *pf_to_mgmt,
  113. enum hinic_mod_type mod, u8 cmd,
  114. void *buf_in, u16 in_size, void *buf_out, u16 *out_size,
  115. enum hinic_mgmt_msg_type sync);
  116. int hinic_pf_to_mgmt_init(struct hinic_pf_to_mgmt *pf_to_mgmt,
  117. struct hinic_hwif *hwif);
  118. void hinic_pf_to_mgmt_free(struct hinic_pf_to_mgmt *pf_to_mgmt);
  119. #endif