hnae3.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. // Copyright (c) 2016-2017 Hisilicon Limited.
  3. #ifndef __HNAE3_H
  4. #define __HNAE3_H
  5. /* Names used in this framework:
  6. * ae handle (handle):
  7. * a set of queues provided by AE
  8. * ring buffer queue (rbq):
  9. * the channel between upper layer and the AE, can do tx and rx
  10. * ring:
  11. * a tx or rx channel within a rbq
  12. * ring description (desc):
  13. * an element in the ring with packet information
  14. * buffer:
  15. * a memory region referred by desc with the full packet payload
  16. *
  17. * "num" means a static number set as a parameter, "count" mean a dynamic
  18. * number set while running
  19. * "cb" means control block
  20. */
  21. #include <linux/acpi.h>
  22. #include <linux/dcbnl.h>
  23. #include <linux/delay.h>
  24. #include <linux/device.h>
  25. #include <linux/ethtool.h>
  26. #include <linux/module.h>
  27. #include <linux/netdevice.h>
  28. #include <linux/pci.h>
  29. #include <linux/pkt_sched.h>
  30. #include <linux/types.h>
  31. #include <linux/bitmap.h>
  32. #include <net/pkt_cls.h>
  33. #define HNAE3_MOD_VERSION "1.0"
  34. #define HNAE3_MIN_VECTOR_NUM 2 /* first one for misc, another for IO */
  35. /* Device version */
  36. #define HNAE3_DEVICE_VERSION_V1 0x00020
  37. #define HNAE3_DEVICE_VERSION_V2 0x00021
  38. #define HNAE3_DEVICE_VERSION_V3 0x00030
  39. #define HNAE3_PCI_REVISION_BIT_SIZE 8
  40. /* Device IDs */
  41. #define HNAE3_DEV_ID_GE 0xA220
  42. #define HNAE3_DEV_ID_25GE 0xA221
  43. #define HNAE3_DEV_ID_25GE_RDMA 0xA222
  44. #define HNAE3_DEV_ID_25GE_RDMA_MACSEC 0xA223
  45. #define HNAE3_DEV_ID_50GE_RDMA 0xA224
  46. #define HNAE3_DEV_ID_50GE_RDMA_MACSEC 0xA225
  47. #define HNAE3_DEV_ID_100G_RDMA_MACSEC 0xA226
  48. #define HNAE3_DEV_ID_200G_RDMA 0xA228
  49. #define HNAE3_DEV_ID_VF 0xA22E
  50. #define HNAE3_DEV_ID_RDMA_DCB_PFC_VF 0xA22F
  51. #define HNAE3_CLASS_NAME_SIZE 16
  52. #define HNAE3_DEV_INITED_B 0x0
  53. #define HNAE3_DEV_SUPPORT_ROCE_B 0x1
  54. #define HNAE3_DEV_SUPPORT_DCB_B 0x2
  55. #define HNAE3_KNIC_CLIENT_INITED_B 0x3
  56. #define HNAE3_UNIC_CLIENT_INITED_B 0x4
  57. #define HNAE3_ROCE_CLIENT_INITED_B 0x5
  58. #define HNAE3_DEV_SUPPORT_ROCE_DCB_BITS (BIT(HNAE3_DEV_SUPPORT_DCB_B) | \
  59. BIT(HNAE3_DEV_SUPPORT_ROCE_B))
  60. #define hnae3_dev_roce_supported(hdev) \
  61. hnae3_get_bit((hdev)->ae_dev->flag, HNAE3_DEV_SUPPORT_ROCE_B)
  62. #define hnae3_dev_dcb_supported(hdev) \
  63. hnae3_get_bit((hdev)->ae_dev->flag, HNAE3_DEV_SUPPORT_DCB_B)
  64. enum HNAE3_DEV_CAP_BITS {
  65. HNAE3_DEV_SUPPORT_FD_B,
  66. HNAE3_DEV_SUPPORT_GRO_B,
  67. HNAE3_DEV_SUPPORT_FEC_B,
  68. HNAE3_DEV_SUPPORT_UDP_GSO_B,
  69. HNAE3_DEV_SUPPORT_QB_B,
  70. HNAE3_DEV_SUPPORT_FD_FORWARD_TC_B,
  71. HNAE3_DEV_SUPPORT_PTP_B,
  72. HNAE3_DEV_SUPPORT_INT_QL_B,
  73. HNAE3_DEV_SUPPORT_HW_TX_CSUM_B,
  74. HNAE3_DEV_SUPPORT_TX_PUSH_B,
  75. HNAE3_DEV_SUPPORT_PHY_IMP_B,
  76. HNAE3_DEV_SUPPORT_TQP_TXRX_INDEP_B,
  77. HNAE3_DEV_SUPPORT_HW_PAD_B,
  78. HNAE3_DEV_SUPPORT_STASH_B,
  79. HNAE3_DEV_SUPPORT_UDP_TUNNEL_CSUM_B,
  80. HNAE3_DEV_SUPPORT_PAUSE_B,
  81. HNAE3_DEV_SUPPORT_RAS_IMP_B,
  82. HNAE3_DEV_SUPPORT_RXD_ADV_LAYOUT_B,
  83. HNAE3_DEV_SUPPORT_PORT_VLAN_BYPASS_B,
  84. HNAE3_DEV_SUPPORT_VLAN_FLTR_MDF_B,
  85. HNAE3_DEV_SUPPORT_MC_MAC_MNG_B,
  86. HNAE3_DEV_SUPPORT_CQ_B,
  87. HNAE3_DEV_SUPPORT_FEC_STATS_B,
  88. HNAE3_DEV_SUPPORT_LANE_NUM_B,
  89. };
  90. #define hnae3_ae_dev_fd_supported(ae_dev) \
  91. test_bit(HNAE3_DEV_SUPPORT_FD_B, (ae_dev)->caps)
  92. #define hnae3_ae_dev_gro_supported(ae_dev) \
  93. test_bit(HNAE3_DEV_SUPPORT_GRO_B, (ae_dev)->caps)
  94. #define hnae3_dev_fec_supported(hdev) \
  95. test_bit(HNAE3_DEV_SUPPORT_FEC_B, (hdev)->ae_dev->caps)
  96. #define hnae3_dev_udp_gso_supported(hdev) \
  97. test_bit(HNAE3_DEV_SUPPORT_UDP_GSO_B, (hdev)->ae_dev->caps)
  98. #define hnae3_dev_qb_supported(hdev) \
  99. test_bit(HNAE3_DEV_SUPPORT_QB_B, (hdev)->ae_dev->caps)
  100. #define hnae3_dev_fd_forward_tc_supported(hdev) \
  101. test_bit(HNAE3_DEV_SUPPORT_FD_FORWARD_TC_B, (hdev)->ae_dev->caps)
  102. #define hnae3_dev_ptp_supported(hdev) \
  103. test_bit(HNAE3_DEV_SUPPORT_PTP_B, (hdev)->ae_dev->caps)
  104. #define hnae3_dev_int_ql_supported(hdev) \
  105. test_bit(HNAE3_DEV_SUPPORT_INT_QL_B, (hdev)->ae_dev->caps)
  106. #define hnae3_dev_hw_csum_supported(hdev) \
  107. test_bit(HNAE3_DEV_SUPPORT_HW_TX_CSUM_B, (hdev)->ae_dev->caps)
  108. #define hnae3_dev_tx_push_supported(hdev) \
  109. test_bit(HNAE3_DEV_SUPPORT_TX_PUSH_B, (hdev)->ae_dev->caps)
  110. #define hnae3_dev_phy_imp_supported(hdev) \
  111. test_bit(HNAE3_DEV_SUPPORT_PHY_IMP_B, (hdev)->ae_dev->caps)
  112. #define hnae3_dev_ras_imp_supported(hdev) \
  113. test_bit(HNAE3_DEV_SUPPORT_RAS_IMP_B, (hdev)->ae_dev->caps)
  114. #define hnae3_dev_tqp_txrx_indep_supported(hdev) \
  115. test_bit(HNAE3_DEV_SUPPORT_TQP_TXRX_INDEP_B, (hdev)->ae_dev->caps)
  116. #define hnae3_dev_hw_pad_supported(hdev) \
  117. test_bit(HNAE3_DEV_SUPPORT_HW_PAD_B, (hdev)->ae_dev->caps)
  118. #define hnae3_dev_stash_supported(hdev) \
  119. test_bit(HNAE3_DEV_SUPPORT_STASH_B, (hdev)->ae_dev->caps)
  120. #define hnae3_dev_pause_supported(hdev) \
  121. test_bit(HNAE3_DEV_SUPPORT_PAUSE_B, (hdev)->ae_dev->caps)
  122. #define hnae3_ae_dev_tqp_txrx_indep_supported(ae_dev) \
  123. test_bit(HNAE3_DEV_SUPPORT_TQP_TXRX_INDEP_B, (ae_dev)->caps)
  124. #define hnae3_ae_dev_rxd_adv_layout_supported(ae_dev) \
  125. test_bit(HNAE3_DEV_SUPPORT_RXD_ADV_LAYOUT_B, (ae_dev)->caps)
  126. #define hnae3_ae_dev_mc_mac_mng_supported(ae_dev) \
  127. test_bit(HNAE3_DEV_SUPPORT_MC_MAC_MNG_B, (ae_dev)->caps)
  128. #define hnae3_ae_dev_cq_supported(ae_dev) \
  129. test_bit(HNAE3_DEV_SUPPORT_CQ_B, (ae_dev)->caps)
  130. #define hnae3_ae_dev_fec_stats_supported(ae_dev) \
  131. test_bit(HNAE3_DEV_SUPPORT_FEC_STATS_B, (ae_dev)->caps)
  132. #define hnae3_ae_dev_lane_num_supported(ae_dev) \
  133. test_bit(HNAE3_DEV_SUPPORT_LANE_NUM_B, (ae_dev)->caps)
  134. enum HNAE3_PF_CAP_BITS {
  135. HNAE3_PF_SUPPORT_VLAN_FLTR_MDF_B = 0,
  136. };
  137. #define ring_ptr_move_fw(ring, p) \
  138. ((ring)->p = ((ring)->p + 1) % (ring)->desc_num)
  139. #define ring_ptr_move_bw(ring, p) \
  140. ((ring)->p = ((ring)->p - 1 + (ring)->desc_num) % (ring)->desc_num)
  141. struct hnae3_handle;
  142. struct hnae3_queue {
  143. void __iomem *io_base;
  144. void __iomem *mem_base;
  145. struct hnae3_ae_algo *ae_algo;
  146. struct hnae3_handle *handle;
  147. int tqp_index; /* index in a handle */
  148. u32 buf_size; /* size for hnae_desc->addr, preset by AE */
  149. u16 tx_desc_num; /* total number of tx desc */
  150. u16 rx_desc_num; /* total number of rx desc */
  151. };
  152. struct hns3_mac_stats {
  153. u64 tx_pause_cnt;
  154. u64 rx_pause_cnt;
  155. };
  156. /* hnae3 loop mode */
  157. enum hnae3_loop {
  158. HNAE3_LOOP_EXTERNAL,
  159. HNAE3_LOOP_APP,
  160. HNAE3_LOOP_SERIAL_SERDES,
  161. HNAE3_LOOP_PARALLEL_SERDES,
  162. HNAE3_LOOP_PHY,
  163. HNAE3_LOOP_NONE,
  164. };
  165. enum hnae3_client_type {
  166. HNAE3_CLIENT_KNIC,
  167. HNAE3_CLIENT_ROCE,
  168. };
  169. /* mac media type */
  170. enum hnae3_media_type {
  171. HNAE3_MEDIA_TYPE_UNKNOWN,
  172. HNAE3_MEDIA_TYPE_FIBER,
  173. HNAE3_MEDIA_TYPE_COPPER,
  174. HNAE3_MEDIA_TYPE_BACKPLANE,
  175. HNAE3_MEDIA_TYPE_NONE,
  176. };
  177. /* must be consistent with definition in firmware */
  178. enum hnae3_module_type {
  179. HNAE3_MODULE_TYPE_UNKNOWN = 0x00,
  180. HNAE3_MODULE_TYPE_FIBRE_LR = 0x01,
  181. HNAE3_MODULE_TYPE_FIBRE_SR = 0x02,
  182. HNAE3_MODULE_TYPE_AOC = 0x03,
  183. HNAE3_MODULE_TYPE_CR = 0x04,
  184. HNAE3_MODULE_TYPE_KR = 0x05,
  185. HNAE3_MODULE_TYPE_TP = 0x06,
  186. };
  187. enum hnae3_fec_mode {
  188. HNAE3_FEC_AUTO = 0,
  189. HNAE3_FEC_BASER,
  190. HNAE3_FEC_RS,
  191. HNAE3_FEC_LLRS,
  192. HNAE3_FEC_NONE,
  193. HNAE3_FEC_USER_DEF,
  194. };
  195. enum hnae3_reset_notify_type {
  196. HNAE3_UP_CLIENT,
  197. HNAE3_DOWN_CLIENT,
  198. HNAE3_INIT_CLIENT,
  199. HNAE3_UNINIT_CLIENT,
  200. };
  201. enum hnae3_hw_error_type {
  202. HNAE3_PPU_POISON_ERROR,
  203. HNAE3_CMDQ_ECC_ERROR,
  204. HNAE3_IMP_RD_POISON_ERROR,
  205. HNAE3_ROCEE_AXI_RESP_ERROR,
  206. };
  207. enum hnae3_reset_type {
  208. HNAE3_VF_RESET,
  209. HNAE3_VF_FUNC_RESET,
  210. HNAE3_VF_PF_FUNC_RESET,
  211. HNAE3_VF_FULL_RESET,
  212. HNAE3_FLR_RESET,
  213. HNAE3_FUNC_RESET,
  214. HNAE3_GLOBAL_RESET,
  215. HNAE3_IMP_RESET,
  216. HNAE3_NONE_RESET,
  217. HNAE3_MAX_RESET,
  218. };
  219. enum hnae3_port_base_vlan_state {
  220. HNAE3_PORT_BASE_VLAN_DISABLE,
  221. HNAE3_PORT_BASE_VLAN_ENABLE,
  222. HNAE3_PORT_BASE_VLAN_MODIFY,
  223. HNAE3_PORT_BASE_VLAN_NOCHANGE,
  224. };
  225. enum hnae3_dbg_cmd {
  226. HNAE3_DBG_CMD_TM_NODES,
  227. HNAE3_DBG_CMD_TM_PRI,
  228. HNAE3_DBG_CMD_TM_QSET,
  229. HNAE3_DBG_CMD_TM_MAP,
  230. HNAE3_DBG_CMD_TM_PG,
  231. HNAE3_DBG_CMD_TM_PORT,
  232. HNAE3_DBG_CMD_TC_SCH_INFO,
  233. HNAE3_DBG_CMD_QOS_PAUSE_CFG,
  234. HNAE3_DBG_CMD_QOS_PRI_MAP,
  235. HNAE3_DBG_CMD_QOS_DSCP_MAP,
  236. HNAE3_DBG_CMD_QOS_BUF_CFG,
  237. HNAE3_DBG_CMD_DEV_INFO,
  238. HNAE3_DBG_CMD_TX_BD,
  239. HNAE3_DBG_CMD_RX_BD,
  240. HNAE3_DBG_CMD_MAC_UC,
  241. HNAE3_DBG_CMD_MAC_MC,
  242. HNAE3_DBG_CMD_MNG_TBL,
  243. HNAE3_DBG_CMD_LOOPBACK,
  244. HNAE3_DBG_CMD_PTP_INFO,
  245. HNAE3_DBG_CMD_INTERRUPT_INFO,
  246. HNAE3_DBG_CMD_RESET_INFO,
  247. HNAE3_DBG_CMD_IMP_INFO,
  248. HNAE3_DBG_CMD_NCL_CONFIG,
  249. HNAE3_DBG_CMD_REG_BIOS_COMMON,
  250. HNAE3_DBG_CMD_REG_SSU,
  251. HNAE3_DBG_CMD_REG_IGU_EGU,
  252. HNAE3_DBG_CMD_REG_RPU,
  253. HNAE3_DBG_CMD_REG_NCSI,
  254. HNAE3_DBG_CMD_REG_RTC,
  255. HNAE3_DBG_CMD_REG_PPP,
  256. HNAE3_DBG_CMD_REG_RCB,
  257. HNAE3_DBG_CMD_REG_TQP,
  258. HNAE3_DBG_CMD_REG_MAC,
  259. HNAE3_DBG_CMD_REG_DCB,
  260. HNAE3_DBG_CMD_VLAN_CONFIG,
  261. HNAE3_DBG_CMD_QUEUE_MAP,
  262. HNAE3_DBG_CMD_RX_QUEUE_INFO,
  263. HNAE3_DBG_CMD_TX_QUEUE_INFO,
  264. HNAE3_DBG_CMD_FD_TCAM,
  265. HNAE3_DBG_CMD_FD_COUNTER,
  266. HNAE3_DBG_CMD_MAC_TNL_STATUS,
  267. HNAE3_DBG_CMD_SERV_INFO,
  268. HNAE3_DBG_CMD_UMV_INFO,
  269. HNAE3_DBG_CMD_PAGE_POOL_INFO,
  270. HNAE3_DBG_CMD_COAL_INFO,
  271. HNAE3_DBG_CMD_UNKNOWN,
  272. };
  273. enum hnae3_tc_map_mode {
  274. HNAE3_TC_MAP_MODE_PRIO,
  275. HNAE3_TC_MAP_MODE_DSCP,
  276. };
  277. struct hnae3_vector_info {
  278. u8 __iomem *io_addr;
  279. int vector;
  280. };
  281. #define HNAE3_RING_TYPE_B 0
  282. #define HNAE3_RING_TYPE_TX 0
  283. #define HNAE3_RING_TYPE_RX 1
  284. #define HNAE3_RING_GL_IDX_S 0
  285. #define HNAE3_RING_GL_IDX_M GENMASK(1, 0)
  286. #define HNAE3_RING_GL_RX 0
  287. #define HNAE3_RING_GL_TX 1
  288. #define HNAE3_FW_VERSION_BYTE3_SHIFT 24
  289. #define HNAE3_FW_VERSION_BYTE3_MASK GENMASK(31, 24)
  290. #define HNAE3_FW_VERSION_BYTE2_SHIFT 16
  291. #define HNAE3_FW_VERSION_BYTE2_MASK GENMASK(23, 16)
  292. #define HNAE3_FW_VERSION_BYTE1_SHIFT 8
  293. #define HNAE3_FW_VERSION_BYTE1_MASK GENMASK(15, 8)
  294. #define HNAE3_FW_VERSION_BYTE0_SHIFT 0
  295. #define HNAE3_FW_VERSION_BYTE0_MASK GENMASK(7, 0)
  296. struct hnae3_ring_chain_node {
  297. struct hnae3_ring_chain_node *next;
  298. u32 tqp_index;
  299. u32 flag;
  300. u32 int_gl_idx;
  301. };
  302. #define HNAE3_IS_TX_RING(node) \
  303. (((node)->flag & 1 << HNAE3_RING_TYPE_B) == HNAE3_RING_TYPE_TX)
  304. /* device specification info from firmware */
  305. struct hnae3_dev_specs {
  306. u32 mac_entry_num; /* number of mac-vlan table entry */
  307. u32 mng_entry_num; /* number of manager table entry */
  308. u32 max_tm_rate;
  309. u16 rss_ind_tbl_size;
  310. u16 rss_key_size;
  311. u16 int_ql_max; /* max value of interrupt coalesce based on INT_QL */
  312. u16 max_int_gl; /* max value of interrupt coalesce based on INT_GL */
  313. u8 max_non_tso_bd_num; /* max BD number of one non-TSO packet */
  314. u16 max_frm_size;
  315. u16 max_qset_num;
  316. u16 umv_size;
  317. u16 mc_mac_size;
  318. u32 mac_stats_num;
  319. };
  320. struct hnae3_client_ops {
  321. int (*init_instance)(struct hnae3_handle *handle);
  322. void (*uninit_instance)(struct hnae3_handle *handle, bool reset);
  323. void (*link_status_change)(struct hnae3_handle *handle, bool state);
  324. int (*reset_notify)(struct hnae3_handle *handle,
  325. enum hnae3_reset_notify_type type);
  326. void (*process_hw_error)(struct hnae3_handle *handle,
  327. enum hnae3_hw_error_type);
  328. };
  329. #define HNAE3_CLIENT_NAME_LENGTH 16
  330. struct hnae3_client {
  331. char name[HNAE3_CLIENT_NAME_LENGTH];
  332. unsigned long state;
  333. enum hnae3_client_type type;
  334. const struct hnae3_client_ops *ops;
  335. struct list_head node;
  336. };
  337. #define HNAE3_DEV_CAPS_MAX_NUM 96
  338. struct hnae3_ae_dev {
  339. struct pci_dev *pdev;
  340. const struct hnae3_ae_ops *ops;
  341. struct list_head node;
  342. u32 flag;
  343. unsigned long hw_err_reset_req;
  344. struct hnae3_dev_specs dev_specs;
  345. u32 dev_version;
  346. DECLARE_BITMAP(caps, HNAE3_DEV_CAPS_MAX_NUM);
  347. void *priv;
  348. };
  349. /* This struct defines the operation on the handle.
  350. *
  351. * init_ae_dev(): (mandatory)
  352. * Get PF configure from pci_dev and initialize PF hardware
  353. * uninit_ae_dev()
  354. * Disable PF device and release PF resource
  355. * register_client
  356. * Register client to ae_dev
  357. * unregister_client()
  358. * Unregister client from ae_dev
  359. * start()
  360. * Enable the hardware
  361. * stop()
  362. * Disable the hardware
  363. * start_client()
  364. * Inform the hclge that client has been started
  365. * stop_client()
  366. * Inform the hclge that client has been stopped
  367. * get_status()
  368. * Get the carrier state of the back channel of the handle, 1 for ok, 0 for
  369. * non-ok
  370. * get_ksettings_an_result()
  371. * Get negotiation status,speed and duplex
  372. * get_media_type()
  373. * Get media type of MAC
  374. * check_port_speed()
  375. * Check target speed whether is supported
  376. * adjust_link()
  377. * Adjust link status
  378. * set_loopback()
  379. * Set loopback
  380. * set_promisc_mode
  381. * Set promisc mode
  382. * request_update_promisc_mode
  383. * request to hclge(vf) to update promisc mode
  384. * set_mtu()
  385. * set mtu
  386. * get_pauseparam()
  387. * get tx and rx of pause frame use
  388. * set_pauseparam()
  389. * set tx and rx of pause frame use
  390. * set_autoneg()
  391. * set auto autonegotiation of pause frame use
  392. * get_autoneg()
  393. * get auto autonegotiation of pause frame use
  394. * restart_autoneg()
  395. * restart autonegotiation
  396. * halt_autoneg()
  397. * halt/resume autonegotiation when autonegotiation on
  398. * get_coalesce_usecs()
  399. * get usecs to delay a TX interrupt after a packet is sent
  400. * get_rx_max_coalesced_frames()
  401. * get Maximum number of packets to be sent before a TX interrupt.
  402. * set_coalesce_usecs()
  403. * set usecs to delay a TX interrupt after a packet is sent
  404. * set_coalesce_frames()
  405. * set Maximum number of packets to be sent before a TX interrupt.
  406. * get_mac_addr()
  407. * get mac address
  408. * set_mac_addr()
  409. * set mac address
  410. * add_uc_addr
  411. * Add unicast addr to mac table
  412. * rm_uc_addr
  413. * Remove unicast addr from mac table
  414. * set_mc_addr()
  415. * Set multicast address
  416. * add_mc_addr
  417. * Add multicast address to mac table
  418. * rm_mc_addr
  419. * Remove multicast address from mac table
  420. * update_stats()
  421. * Update Old network device statistics
  422. * get_mac_stats()
  423. * get mac pause statistics including tx_cnt and rx_cnt
  424. * get_ethtool_stats()
  425. * Get ethtool network device statistics
  426. * get_strings()
  427. * Get a set of strings that describe the requested objects
  428. * get_sset_count()
  429. * Get number of strings that @get_strings will write
  430. * update_led_status()
  431. * Update the led status
  432. * set_led_id()
  433. * Set led id
  434. * get_regs()
  435. * Get regs dump
  436. * get_regs_len()
  437. * Get the len of the regs dump
  438. * get_rss_key_size()
  439. * Get rss key size
  440. * get_rss()
  441. * Get rss table
  442. * set_rss()
  443. * Set rss table
  444. * get_tc_size()
  445. * Get tc size of handle
  446. * get_vector()
  447. * Get vector number and vector information
  448. * put_vector()
  449. * Put the vector in hdev
  450. * map_ring_to_vector()
  451. * Map rings to vector
  452. * unmap_ring_from_vector()
  453. * Unmap rings from vector
  454. * reset_queue()
  455. * Reset queue
  456. * get_fw_version()
  457. * Get firmware version
  458. * get_mdix_mode()
  459. * Get media typr of phy
  460. * enable_vlan_filter()
  461. * Enable vlan filter
  462. * set_vlan_filter()
  463. * Set vlan filter config of Ports
  464. * set_vf_vlan_filter()
  465. * Set vlan filter config of vf
  466. * enable_hw_strip_rxvtag()
  467. * Enable/disable hardware strip vlan tag of packets received
  468. * set_gro_en
  469. * Enable/disable HW GRO
  470. * add_arfs_entry
  471. * Check the 5-tuples of flow, and create flow director rule
  472. * get_vf_config
  473. * Get the VF configuration setting by the host
  474. * set_vf_link_state
  475. * Set VF link status
  476. * set_vf_spoofchk
  477. * Enable/disable spoof check for specified vf
  478. * set_vf_trust
  479. * Enable/disable trust for specified vf, if the vf being trusted, then
  480. * it can enable promisc mode
  481. * set_vf_rate
  482. * Set the max tx rate of specified vf.
  483. * set_vf_mac
  484. * Configure the default MAC for specified VF
  485. * get_module_eeprom
  486. * Get the optical module eeprom info.
  487. * add_cls_flower
  488. * Add clsflower rule
  489. * del_cls_flower
  490. * Delete clsflower rule
  491. * cls_flower_active
  492. * Check if any cls flower rule exist
  493. * dbg_read_cmd
  494. * Execute debugfs read command.
  495. * set_tx_hwts_info
  496. * Save information for 1588 tx packet
  497. * get_rx_hwts
  498. * Get 1588 rx hwstamp
  499. * get_ts_info
  500. * Get phc info
  501. * clean_vf_config
  502. * Clean residual vf info after disable sriov
  503. */
  504. struct hnae3_ae_ops {
  505. int (*init_ae_dev)(struct hnae3_ae_dev *ae_dev);
  506. void (*uninit_ae_dev)(struct hnae3_ae_dev *ae_dev);
  507. void (*reset_prepare)(struct hnae3_ae_dev *ae_dev,
  508. enum hnae3_reset_type rst_type);
  509. void (*reset_done)(struct hnae3_ae_dev *ae_dev);
  510. int (*init_client_instance)(struct hnae3_client *client,
  511. struct hnae3_ae_dev *ae_dev);
  512. void (*uninit_client_instance)(struct hnae3_client *client,
  513. struct hnae3_ae_dev *ae_dev);
  514. int (*start)(struct hnae3_handle *handle);
  515. void (*stop)(struct hnae3_handle *handle);
  516. int (*client_start)(struct hnae3_handle *handle);
  517. void (*client_stop)(struct hnae3_handle *handle);
  518. int (*get_status)(struct hnae3_handle *handle);
  519. void (*get_ksettings_an_result)(struct hnae3_handle *handle,
  520. u8 *auto_neg, u32 *speed, u8 *duplex,
  521. u32 *lane_num);
  522. int (*cfg_mac_speed_dup_h)(struct hnae3_handle *handle, int speed,
  523. u8 duplex, u8 lane_num);
  524. void (*get_media_type)(struct hnae3_handle *handle, u8 *media_type,
  525. u8 *module_type);
  526. int (*check_port_speed)(struct hnae3_handle *handle, u32 speed);
  527. void (*get_fec_stats)(struct hnae3_handle *handle,
  528. struct ethtool_fec_stats *fec_stats);
  529. void (*get_fec)(struct hnae3_handle *handle, u8 *fec_ability,
  530. u8 *fec_mode);
  531. int (*set_fec)(struct hnae3_handle *handle, u32 fec_mode);
  532. void (*adjust_link)(struct hnae3_handle *handle, int speed, int duplex);
  533. int (*set_loopback)(struct hnae3_handle *handle,
  534. enum hnae3_loop loop_mode, bool en);
  535. int (*set_promisc_mode)(struct hnae3_handle *handle, bool en_uc_pmc,
  536. bool en_mc_pmc);
  537. void (*request_update_promisc_mode)(struct hnae3_handle *handle);
  538. int (*set_mtu)(struct hnae3_handle *handle, int new_mtu);
  539. void (*get_pauseparam)(struct hnae3_handle *handle,
  540. u32 *auto_neg, u32 *rx_en, u32 *tx_en);
  541. int (*set_pauseparam)(struct hnae3_handle *handle,
  542. u32 auto_neg, u32 rx_en, u32 tx_en);
  543. int (*set_autoneg)(struct hnae3_handle *handle, bool enable);
  544. int (*get_autoneg)(struct hnae3_handle *handle);
  545. int (*restart_autoneg)(struct hnae3_handle *handle);
  546. int (*halt_autoneg)(struct hnae3_handle *handle, bool halt);
  547. void (*get_coalesce_usecs)(struct hnae3_handle *handle,
  548. u32 *tx_usecs, u32 *rx_usecs);
  549. void (*get_rx_max_coalesced_frames)(struct hnae3_handle *handle,
  550. u32 *tx_frames, u32 *rx_frames);
  551. int (*set_coalesce_usecs)(struct hnae3_handle *handle, u32 timeout);
  552. int (*set_coalesce_frames)(struct hnae3_handle *handle,
  553. u32 coalesce_frames);
  554. void (*get_coalesce_range)(struct hnae3_handle *handle,
  555. u32 *tx_frames_low, u32 *rx_frames_low,
  556. u32 *tx_frames_high, u32 *rx_frames_high,
  557. u32 *tx_usecs_low, u32 *rx_usecs_low,
  558. u32 *tx_usecs_high, u32 *rx_usecs_high);
  559. void (*get_mac_addr)(struct hnae3_handle *handle, u8 *p);
  560. int (*set_mac_addr)(struct hnae3_handle *handle, const void *p,
  561. bool is_first);
  562. int (*do_ioctl)(struct hnae3_handle *handle,
  563. struct ifreq *ifr, int cmd);
  564. int (*add_uc_addr)(struct hnae3_handle *handle,
  565. const unsigned char *addr);
  566. int (*rm_uc_addr)(struct hnae3_handle *handle,
  567. const unsigned char *addr);
  568. int (*set_mc_addr)(struct hnae3_handle *handle, void *addr);
  569. int (*add_mc_addr)(struct hnae3_handle *handle,
  570. const unsigned char *addr);
  571. int (*rm_mc_addr)(struct hnae3_handle *handle,
  572. const unsigned char *addr);
  573. void (*set_tso_stats)(struct hnae3_handle *handle, int enable);
  574. void (*update_stats)(struct hnae3_handle *handle,
  575. struct net_device_stats *net_stats);
  576. void (*get_stats)(struct hnae3_handle *handle, u64 *data);
  577. void (*get_mac_stats)(struct hnae3_handle *handle,
  578. struct hns3_mac_stats *mac_stats);
  579. void (*get_strings)(struct hnae3_handle *handle,
  580. u32 stringset, u8 *data);
  581. int (*get_sset_count)(struct hnae3_handle *handle, int stringset);
  582. void (*get_regs)(struct hnae3_handle *handle, u32 *version,
  583. void *data);
  584. int (*get_regs_len)(struct hnae3_handle *handle);
  585. u32 (*get_rss_key_size)(struct hnae3_handle *handle);
  586. int (*get_rss)(struct hnae3_handle *handle, u32 *indir, u8 *key,
  587. u8 *hfunc);
  588. int (*set_rss)(struct hnae3_handle *handle, const u32 *indir,
  589. const u8 *key, const u8 hfunc);
  590. int (*set_rss_tuple)(struct hnae3_handle *handle,
  591. struct ethtool_rxnfc *cmd);
  592. int (*get_rss_tuple)(struct hnae3_handle *handle,
  593. struct ethtool_rxnfc *cmd);
  594. int (*get_tc_size)(struct hnae3_handle *handle);
  595. int (*get_vector)(struct hnae3_handle *handle, u16 vector_num,
  596. struct hnae3_vector_info *vector_info);
  597. int (*put_vector)(struct hnae3_handle *handle, int vector_num);
  598. int (*map_ring_to_vector)(struct hnae3_handle *handle,
  599. int vector_num,
  600. struct hnae3_ring_chain_node *vr_chain);
  601. int (*unmap_ring_from_vector)(struct hnae3_handle *handle,
  602. int vector_num,
  603. struct hnae3_ring_chain_node *vr_chain);
  604. int (*reset_queue)(struct hnae3_handle *handle);
  605. u32 (*get_fw_version)(struct hnae3_handle *handle);
  606. void (*get_mdix_mode)(struct hnae3_handle *handle,
  607. u8 *tp_mdix_ctrl, u8 *tp_mdix);
  608. int (*enable_vlan_filter)(struct hnae3_handle *handle, bool enable);
  609. int (*set_vlan_filter)(struct hnae3_handle *handle, __be16 proto,
  610. u16 vlan_id, bool is_kill);
  611. int (*set_vf_vlan_filter)(struct hnae3_handle *handle, int vfid,
  612. u16 vlan, u8 qos, __be16 proto);
  613. int (*enable_hw_strip_rxvtag)(struct hnae3_handle *handle, bool enable);
  614. void (*reset_event)(struct pci_dev *pdev, struct hnae3_handle *handle);
  615. enum hnae3_reset_type (*get_reset_level)(struct hnae3_ae_dev *ae_dev,
  616. unsigned long *addr);
  617. void (*set_default_reset_request)(struct hnae3_ae_dev *ae_dev,
  618. enum hnae3_reset_type rst_type);
  619. void (*get_channels)(struct hnae3_handle *handle,
  620. struct ethtool_channels *ch);
  621. void (*get_tqps_and_rss_info)(struct hnae3_handle *h,
  622. u16 *alloc_tqps, u16 *max_rss_size);
  623. int (*set_channels)(struct hnae3_handle *handle, u32 new_tqps_num,
  624. bool rxfh_configured);
  625. void (*get_flowctrl_adv)(struct hnae3_handle *handle,
  626. u32 *flowctrl_adv);
  627. int (*set_led_id)(struct hnae3_handle *handle,
  628. enum ethtool_phys_id_state status);
  629. void (*get_link_mode)(struct hnae3_handle *handle,
  630. unsigned long *supported,
  631. unsigned long *advertising);
  632. int (*add_fd_entry)(struct hnae3_handle *handle,
  633. struct ethtool_rxnfc *cmd);
  634. int (*del_fd_entry)(struct hnae3_handle *handle,
  635. struct ethtool_rxnfc *cmd);
  636. int (*get_fd_rule_cnt)(struct hnae3_handle *handle,
  637. struct ethtool_rxnfc *cmd);
  638. int (*get_fd_rule_info)(struct hnae3_handle *handle,
  639. struct ethtool_rxnfc *cmd);
  640. int (*get_fd_all_rules)(struct hnae3_handle *handle,
  641. struct ethtool_rxnfc *cmd, u32 *rule_locs);
  642. void (*enable_fd)(struct hnae3_handle *handle, bool enable);
  643. int (*add_arfs_entry)(struct hnae3_handle *handle, u16 queue_id,
  644. u16 flow_id, struct flow_keys *fkeys);
  645. int (*dbg_read_cmd)(struct hnae3_handle *handle, enum hnae3_dbg_cmd cmd,
  646. char *buf, int len);
  647. pci_ers_result_t (*handle_hw_ras_error)(struct hnae3_ae_dev *ae_dev);
  648. bool (*get_hw_reset_stat)(struct hnae3_handle *handle);
  649. bool (*ae_dev_resetting)(struct hnae3_handle *handle);
  650. unsigned long (*ae_dev_reset_cnt)(struct hnae3_handle *handle);
  651. int (*set_gro_en)(struct hnae3_handle *handle, bool enable);
  652. u16 (*get_global_queue_id)(struct hnae3_handle *handle, u16 queue_id);
  653. void (*set_timer_task)(struct hnae3_handle *handle, bool enable);
  654. int (*mac_connect_phy)(struct hnae3_handle *handle);
  655. void (*mac_disconnect_phy)(struct hnae3_handle *handle);
  656. int (*get_vf_config)(struct hnae3_handle *handle, int vf,
  657. struct ifla_vf_info *ivf);
  658. int (*set_vf_link_state)(struct hnae3_handle *handle, int vf,
  659. int link_state);
  660. int (*set_vf_spoofchk)(struct hnae3_handle *handle, int vf,
  661. bool enable);
  662. int (*set_vf_trust)(struct hnae3_handle *handle, int vf, bool enable);
  663. int (*set_vf_rate)(struct hnae3_handle *handle, int vf,
  664. int min_tx_rate, int max_tx_rate, bool force);
  665. int (*set_vf_mac)(struct hnae3_handle *handle, int vf, u8 *p);
  666. int (*get_module_eeprom)(struct hnae3_handle *handle, u32 offset,
  667. u32 len, u8 *data);
  668. bool (*get_cmdq_stat)(struct hnae3_handle *handle);
  669. int (*add_cls_flower)(struct hnae3_handle *handle,
  670. struct flow_cls_offload *cls_flower, int tc);
  671. int (*del_cls_flower)(struct hnae3_handle *handle,
  672. struct flow_cls_offload *cls_flower);
  673. bool (*cls_flower_active)(struct hnae3_handle *handle);
  674. int (*get_phy_link_ksettings)(struct hnae3_handle *handle,
  675. struct ethtool_link_ksettings *cmd);
  676. int (*set_phy_link_ksettings)(struct hnae3_handle *handle,
  677. const struct ethtool_link_ksettings *cmd);
  678. bool (*set_tx_hwts_info)(struct hnae3_handle *handle,
  679. struct sk_buff *skb);
  680. void (*get_rx_hwts)(struct hnae3_handle *handle, struct sk_buff *skb,
  681. u32 nsec, u32 sec);
  682. int (*get_ts_info)(struct hnae3_handle *handle,
  683. struct ethtool_ts_info *info);
  684. int (*get_link_diagnosis_info)(struct hnae3_handle *handle,
  685. u32 *status_code);
  686. void (*clean_vf_config)(struct hnae3_ae_dev *ae_dev, int num_vfs);
  687. int (*get_dscp_prio)(struct hnae3_handle *handle, u8 dscp,
  688. u8 *tc_map_mode, u8 *priority);
  689. };
  690. struct hnae3_dcb_ops {
  691. /* IEEE 802.1Qaz std */
  692. int (*ieee_getets)(struct hnae3_handle *, struct ieee_ets *);
  693. int (*ieee_setets)(struct hnae3_handle *, struct ieee_ets *);
  694. int (*ieee_getpfc)(struct hnae3_handle *, struct ieee_pfc *);
  695. int (*ieee_setpfc)(struct hnae3_handle *, struct ieee_pfc *);
  696. int (*ieee_setapp)(struct hnae3_handle *h, struct dcb_app *app);
  697. int (*ieee_delapp)(struct hnae3_handle *h, struct dcb_app *app);
  698. /* DCBX configuration */
  699. u8 (*getdcbx)(struct hnae3_handle *);
  700. u8 (*setdcbx)(struct hnae3_handle *, u8);
  701. int (*setup_tc)(struct hnae3_handle *handle,
  702. struct tc_mqprio_qopt_offload *mqprio_qopt);
  703. };
  704. struct hnae3_ae_algo {
  705. const struct hnae3_ae_ops *ops;
  706. struct list_head node;
  707. const struct pci_device_id *pdev_id_table;
  708. };
  709. #define HNAE3_INT_NAME_LEN 32
  710. #define HNAE3_ITR_COUNTDOWN_START 100
  711. #define HNAE3_MAX_TC 8
  712. #define HNAE3_MAX_USER_PRIO 8
  713. struct hnae3_tc_info {
  714. u8 prio_tc[HNAE3_MAX_USER_PRIO]; /* TC indexed by prio */
  715. u16 tqp_count[HNAE3_MAX_TC];
  716. u16 tqp_offset[HNAE3_MAX_TC];
  717. u8 max_tc; /* Total number of TCs */
  718. u8 num_tc; /* Total number of enabled TCs */
  719. bool mqprio_active;
  720. bool dcb_ets_active;
  721. };
  722. #define HNAE3_MAX_DSCP 64
  723. #define HNAE3_PRIO_ID_INVALID 0xff
  724. struct hnae3_knic_private_info {
  725. struct net_device *netdev; /* Set by KNIC client when init instance */
  726. u16 rss_size; /* Allocated RSS queues */
  727. u16 req_rss_size;
  728. u16 rx_buf_len;
  729. u16 num_tx_desc;
  730. u16 num_rx_desc;
  731. u32 tx_spare_buf_size;
  732. struct hnae3_tc_info tc_info;
  733. u8 tc_map_mode;
  734. u8 dscp_app_cnt;
  735. u8 dscp_prio[HNAE3_MAX_DSCP];
  736. u16 num_tqps; /* total number of TQPs in this handle */
  737. struct hnae3_queue **tqp; /* array base of all TQPs in this instance */
  738. const struct hnae3_dcb_ops *dcb_ops;
  739. u16 int_rl_setting;
  740. void __iomem *io_base;
  741. };
  742. struct hnae3_roce_private_info {
  743. struct net_device *netdev;
  744. void __iomem *roce_io_base;
  745. void __iomem *roce_mem_base;
  746. int base_vector;
  747. int num_vectors;
  748. /* The below attributes defined for RoCE client, hnae3 gives
  749. * initial values to them, and RoCE client can modify and use
  750. * them.
  751. */
  752. unsigned long reset_state;
  753. unsigned long instance_state;
  754. unsigned long state;
  755. };
  756. #define HNAE3_SUPPORT_APP_LOOPBACK BIT(0)
  757. #define HNAE3_SUPPORT_PHY_LOOPBACK BIT(1)
  758. #define HNAE3_SUPPORT_SERDES_SERIAL_LOOPBACK BIT(2)
  759. #define HNAE3_SUPPORT_VF BIT(3)
  760. #define HNAE3_SUPPORT_SERDES_PARALLEL_LOOPBACK BIT(4)
  761. #define HNAE3_SUPPORT_EXTERNAL_LOOPBACK BIT(5)
  762. #define HNAE3_USER_UPE BIT(0) /* unicast promisc enabled by user */
  763. #define HNAE3_USER_MPE BIT(1) /* mulitcast promisc enabled by user */
  764. #define HNAE3_BPE BIT(2) /* broadcast promisc enable */
  765. #define HNAE3_OVERFLOW_UPE BIT(3) /* unicast mac vlan overflow */
  766. #define HNAE3_OVERFLOW_MPE BIT(4) /* multicast mac vlan overflow */
  767. #define HNAE3_UPE (HNAE3_USER_UPE | HNAE3_OVERFLOW_UPE)
  768. #define HNAE3_MPE (HNAE3_USER_MPE | HNAE3_OVERFLOW_MPE)
  769. enum hnae3_pflag {
  770. HNAE3_PFLAG_LIMIT_PROMISC,
  771. HNAE3_PFLAG_MAX
  772. };
  773. struct hnae3_handle {
  774. struct hnae3_client *client;
  775. struct pci_dev *pdev;
  776. void *priv;
  777. struct hnae3_ae_algo *ae_algo; /* the class who provides this handle */
  778. u64 flags; /* Indicate the capabilities for this handle */
  779. union {
  780. struct net_device *netdev; /* first member */
  781. struct hnae3_knic_private_info kinfo;
  782. struct hnae3_roce_private_info rinfo;
  783. };
  784. u32 numa_node_mask; /* for multi-chip support */
  785. enum hnae3_port_base_vlan_state port_base_vlan_state;
  786. u8 netdev_flags;
  787. struct dentry *hnae3_dbgfs;
  788. /* protects concurrent contention between debugfs commands */
  789. struct mutex dbgfs_lock;
  790. char **dbgfs_buf;
  791. /* Network interface message level enabled bits */
  792. u32 msg_enable;
  793. unsigned long supported_pflags;
  794. unsigned long priv_flags;
  795. };
  796. #define hnae3_set_field(origin, mask, shift, val) \
  797. do { \
  798. (origin) &= (~(mask)); \
  799. (origin) |= ((val) << (shift)) & (mask); \
  800. } while (0)
  801. #define hnae3_get_field(origin, mask, shift) (((origin) & (mask)) >> (shift))
  802. #define hnae3_set_bit(origin, shift, val) \
  803. hnae3_set_field(origin, 0x1 << (shift), shift, val)
  804. #define hnae3_get_bit(origin, shift) \
  805. hnae3_get_field(origin, 0x1 << (shift), shift)
  806. #define HNAE3_FORMAT_MAC_ADDR_LEN 18
  807. #define HNAE3_FORMAT_MAC_ADDR_OFFSET_0 0
  808. #define HNAE3_FORMAT_MAC_ADDR_OFFSET_4 4
  809. #define HNAE3_FORMAT_MAC_ADDR_OFFSET_5 5
  810. static inline void hnae3_format_mac_addr(char *format_mac_addr,
  811. const u8 *mac_addr)
  812. {
  813. snprintf(format_mac_addr, HNAE3_FORMAT_MAC_ADDR_LEN, "%02x:**:**:**:%02x:%02x",
  814. mac_addr[HNAE3_FORMAT_MAC_ADDR_OFFSET_0],
  815. mac_addr[HNAE3_FORMAT_MAC_ADDR_OFFSET_4],
  816. mac_addr[HNAE3_FORMAT_MAC_ADDR_OFFSET_5]);
  817. }
  818. int hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev);
  819. void hnae3_unregister_ae_dev(struct hnae3_ae_dev *ae_dev);
  820. void hnae3_unregister_ae_algo_prepare(struct hnae3_ae_algo *ae_algo);
  821. void hnae3_unregister_ae_algo(struct hnae3_ae_algo *ae_algo);
  822. void hnae3_register_ae_algo(struct hnae3_ae_algo *ae_algo);
  823. void hnae3_unregister_client(struct hnae3_client *client);
  824. int hnae3_register_client(struct hnae3_client *client);
  825. void hnae3_set_client_init_flag(struct hnae3_client *client,
  826. struct hnae3_ae_dev *ae_dev,
  827. unsigned int inited);
  828. #endif