hinic_hw_dev.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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_DEV_H
  16. #define HINIC_HW_DEV_H
  17. #include <linux/pci.h>
  18. #include <linux/types.h>
  19. #include <linux/bitops.h>
  20. #include "hinic_hw_if.h"
  21. #include "hinic_hw_eqs.h"
  22. #include "hinic_hw_mgmt.h"
  23. #include "hinic_hw_qp.h"
  24. #include "hinic_hw_io.h"
  25. #define HINIC_MAX_QPS 32
  26. #define HINIC_MGMT_NUM_MSG_CMD (HINIC_MGMT_MSG_CMD_MAX - \
  27. HINIC_MGMT_MSG_CMD_BASE)
  28. struct hinic_cap {
  29. u16 max_qps;
  30. u16 num_qps;
  31. };
  32. enum hinic_port_cmd {
  33. HINIC_PORT_CMD_CHANGE_MTU = 2,
  34. HINIC_PORT_CMD_ADD_VLAN = 3,
  35. HINIC_PORT_CMD_DEL_VLAN = 4,
  36. HINIC_PORT_CMD_SET_MAC = 9,
  37. HINIC_PORT_CMD_GET_MAC = 10,
  38. HINIC_PORT_CMD_DEL_MAC = 11,
  39. HINIC_PORT_CMD_SET_RX_MODE = 12,
  40. HINIC_PORT_CMD_GET_LINK_STATE = 24,
  41. HINIC_PORT_CMD_SET_PORT_STATE = 41,
  42. HINIC_PORT_CMD_FWCTXT_INIT = 69,
  43. HINIC_PORT_CMD_SET_FUNC_STATE = 93,
  44. HINIC_PORT_CMD_GET_GLOBAL_QPN = 102,
  45. HINIC_PORT_CMD_GET_CAP = 170,
  46. };
  47. enum hinic_mgmt_msg_cmd {
  48. HINIC_MGMT_MSG_CMD_BASE = 160,
  49. HINIC_MGMT_MSG_CMD_LINK_STATUS = 160,
  50. HINIC_MGMT_MSG_CMD_MAX,
  51. };
  52. enum hinic_cb_state {
  53. HINIC_CB_ENABLED = BIT(0),
  54. HINIC_CB_RUNNING = BIT(1),
  55. };
  56. enum hinic_res_state {
  57. HINIC_RES_CLEAN = 0,
  58. HINIC_RES_ACTIVE = 1,
  59. };
  60. struct hinic_cmd_fw_ctxt {
  61. u8 status;
  62. u8 version;
  63. u8 rsvd0[6];
  64. u16 func_idx;
  65. u16 rx_buf_sz;
  66. u32 rsvd1;
  67. };
  68. struct hinic_cmd_hw_ioctxt {
  69. u8 status;
  70. u8 version;
  71. u8 rsvd0[6];
  72. u16 func_idx;
  73. u16 rsvd1;
  74. u8 set_cmdq_depth;
  75. u8 cmdq_depth;
  76. u8 rsvd2;
  77. u8 rsvd3;
  78. u8 ppf_idx;
  79. u8 rsvd4;
  80. u16 rq_depth;
  81. u16 rx_buf_sz_idx;
  82. u16 sq_depth;
  83. };
  84. struct hinic_cmd_io_status {
  85. u8 status;
  86. u8 version;
  87. u8 rsvd0[6];
  88. u16 func_idx;
  89. u8 rsvd1;
  90. u8 rsvd2;
  91. u32 io_status;
  92. };
  93. struct hinic_cmd_clear_io_res {
  94. u8 status;
  95. u8 version;
  96. u8 rsvd0[6];
  97. u16 func_idx;
  98. u8 rsvd1;
  99. u8 rsvd2;
  100. };
  101. struct hinic_cmd_set_res_state {
  102. u8 status;
  103. u8 version;
  104. u8 rsvd0[6];
  105. u16 func_idx;
  106. u8 state;
  107. u8 rsvd1;
  108. u32 rsvd2;
  109. };
  110. struct hinic_cmd_base_qpn {
  111. u8 status;
  112. u8 version;
  113. u8 rsvd0[6];
  114. u16 func_idx;
  115. u16 qpn;
  116. };
  117. struct hinic_cmd_hw_ci {
  118. u8 status;
  119. u8 version;
  120. u8 rsvd0[6];
  121. u16 func_idx;
  122. u8 dma_attr_off;
  123. u8 pending_limit;
  124. u8 coalesc_timer;
  125. u8 msix_en;
  126. u16 msix_entry_idx;
  127. u32 sq_id;
  128. u32 rsvd1;
  129. u64 ci_addr;
  130. };
  131. struct hinic_hwdev {
  132. struct hinic_hwif *hwif;
  133. struct msix_entry *msix_entries;
  134. struct hinic_aeqs aeqs;
  135. struct hinic_func_to_io func_to_io;
  136. struct hinic_cap nic_cap;
  137. };
  138. struct hinic_nic_cb {
  139. void (*handler)(void *handle, void *buf_in,
  140. u16 in_size, void *buf_out,
  141. u16 *out_size);
  142. void *handle;
  143. unsigned long cb_state;
  144. };
  145. struct hinic_pfhwdev {
  146. struct hinic_hwdev hwdev;
  147. struct hinic_pf_to_mgmt pf_to_mgmt;
  148. struct hinic_nic_cb nic_cb[HINIC_MGMT_NUM_MSG_CMD];
  149. };
  150. void hinic_hwdev_cb_register(struct hinic_hwdev *hwdev,
  151. enum hinic_mgmt_msg_cmd cmd, void *handle,
  152. void (*handler)(void *handle, void *buf_in,
  153. u16 in_size, void *buf_out,
  154. u16 *out_size));
  155. void hinic_hwdev_cb_unregister(struct hinic_hwdev *hwdev,
  156. enum hinic_mgmt_msg_cmd cmd);
  157. int hinic_port_msg_cmd(struct hinic_hwdev *hwdev, enum hinic_port_cmd cmd,
  158. void *buf_in, u16 in_size, void *buf_out,
  159. u16 *out_size);
  160. int hinic_hwdev_ifup(struct hinic_hwdev *hwdev);
  161. void hinic_hwdev_ifdown(struct hinic_hwdev *hwdev);
  162. struct hinic_hwdev *hinic_init_hwdev(struct pci_dev *pdev);
  163. void hinic_free_hwdev(struct hinic_hwdev *hwdev);
  164. int hinic_hwdev_num_qps(struct hinic_hwdev *hwdev);
  165. struct hinic_sq *hinic_hwdev_get_sq(struct hinic_hwdev *hwdev, int i);
  166. struct hinic_rq *hinic_hwdev_get_rq(struct hinic_hwdev *hwdev, int i);
  167. int hinic_hwdev_msix_cnt_set(struct hinic_hwdev *hwdev, u16 msix_index);
  168. int hinic_hwdev_msix_set(struct hinic_hwdev *hwdev, u16 msix_index,
  169. u8 pending_limit, u8 coalesc_timer,
  170. u8 lli_timer_cfg, u8 lli_credit_limit,
  171. u8 resend_timer);
  172. int hinic_hwdev_hw_ci_addr_set(struct hinic_hwdev *hwdev, struct hinic_sq *sq,
  173. u8 pending_limit, u8 coalesc_timer);
  174. #endif