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