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/module.h> 29 #include <linux/netdevice.h> 30 #include <linux/pci.h> 31 #include <linux/types.h> 32 33 #define HNAE3_MOD_VERSION "1.0" 34 35 /* Device IDs */ 36 #define HNAE3_DEV_ID_GE 0xA220 37 #define HNAE3_DEV_ID_25GE 0xA221 38 #define HNAE3_DEV_ID_25GE_RDMA 0xA222 39 #define HNAE3_DEV_ID_25GE_RDMA_MACSEC 0xA223 40 #define HNAE3_DEV_ID_50GE_RDMA 0xA224 41 #define HNAE3_DEV_ID_50GE_RDMA_MACSEC 0xA225 42 #define HNAE3_DEV_ID_100G_RDMA_MACSEC 0xA226 43 #define HNAE3_DEV_ID_100G_VF 0xA22E 44 #define HNAE3_DEV_ID_100G_RDMA_DCB_PFC_VF 0xA22F 45 46 #define HNAE3_CLASS_NAME_SIZE 16 47 48 #define HNAE3_DEV_INITED_B 0x0 49 #define HNAE3_DEV_SUPPORT_ROCE_B 0x1 50 #define HNAE3_DEV_SUPPORT_DCB_B 0x2 51 #define HNAE3_KNIC_CLIENT_INITED_B 0x3 52 #define HNAE3_UNIC_CLIENT_INITED_B 0x4 53 #define HNAE3_ROCE_CLIENT_INITED_B 0x5 54 #define HNAE3_DEV_SUPPORT_FD_B 0x6 55 #define HNAE3_DEV_SUPPORT_GRO_B 0x7 56 57 #define HNAE3_DEV_SUPPORT_ROCE_DCB_BITS (BIT(HNAE3_DEV_SUPPORT_DCB_B) |\ 58 BIT(HNAE3_DEV_SUPPORT_ROCE_B)) 59 60 #define hnae3_dev_roce_supported(hdev) \ 61 hnae3_get_bit(hdev->ae_dev->flag, HNAE3_DEV_SUPPORT_ROCE_B) 62 63 #define hnae3_dev_dcb_supported(hdev) \ 64 hnae3_get_bit(hdev->ae_dev->flag, HNAE3_DEV_SUPPORT_DCB_B) 65 66 #define hnae3_dev_fd_supported(hdev) \ 67 hnae3_get_bit((hdev)->ae_dev->flag, HNAE3_DEV_SUPPORT_FD_B) 68 69 #define hnae3_dev_gro_supported(hdev) \ 70 hnae3_get_bit((hdev)->ae_dev->flag, HNAE3_DEV_SUPPORT_GRO_B) 71 72 #define ring_ptr_move_fw(ring, p) \ 73 ((ring)->p = ((ring)->p + 1) % (ring)->desc_num) 74 #define ring_ptr_move_bw(ring, p) \ 75 ((ring)->p = ((ring)->p - 1 + (ring)->desc_num) % (ring)->desc_num) 76 77 enum hns_desc_type { 78 DESC_TYPE_SKB, 79 DESC_TYPE_PAGE, 80 }; 81 82 struct hnae3_handle; 83 84 struct hnae3_queue { 85 void __iomem *io_base; 86 struct hnae3_ae_algo *ae_algo; 87 struct hnae3_handle *handle; 88 int tqp_index; /* index in a handle */ 89 u32 buf_size; /* size for hnae_desc->addr, preset by AE */ 90 u16 tx_desc_num;/* total number of tx desc */ 91 u16 rx_desc_num;/* total number of rx desc */ 92 }; 93 94 /*hnae3 loop mode*/ 95 enum hnae3_loop { 96 HNAE3_LOOP_APP, 97 HNAE3_LOOP_SERIAL_SERDES, 98 HNAE3_LOOP_PARALLEL_SERDES, 99 HNAE3_LOOP_PHY, 100 HNAE3_LOOP_NONE, 101 }; 102 103 enum hnae3_client_type { 104 HNAE3_CLIENT_KNIC, 105 HNAE3_CLIENT_ROCE, 106 }; 107 108 /* mac media type */ 109 enum hnae3_media_type { 110 HNAE3_MEDIA_TYPE_UNKNOWN, 111 HNAE3_MEDIA_TYPE_FIBER, 112 HNAE3_MEDIA_TYPE_COPPER, 113 HNAE3_MEDIA_TYPE_BACKPLANE, 114 HNAE3_MEDIA_TYPE_NONE, 115 }; 116 117 /* must be consistent with definition in firmware */ 118 enum hnae3_module_type { 119 HNAE3_MODULE_TYPE_UNKNOWN = 0x00, 120 HNAE3_MODULE_TYPE_FIBRE_LR = 0x01, 121 HNAE3_MODULE_TYPE_FIBRE_SR = 0x02, 122 HNAE3_MODULE_TYPE_AOC = 0x03, 123 HNAE3_MODULE_TYPE_CR = 0x04, 124 HNAE3_MODULE_TYPE_KR = 0x05, 125 HNAE3_MODULE_TYPE_TP = 0x06, 126 127 }; 128 129 enum hnae3_fec_mode { 130 HNAE3_FEC_AUTO = 0, 131 HNAE3_FEC_BASER, 132 HNAE3_FEC_RS, 133 HNAE3_FEC_USER_DEF, 134 }; 135 136 enum hnae3_reset_notify_type { 137 HNAE3_UP_CLIENT, 138 HNAE3_DOWN_CLIENT, 139 HNAE3_INIT_CLIENT, 140 HNAE3_UNINIT_CLIENT, 141 HNAE3_RESTORE_CLIENT, 142 }; 143 144 enum hnae3_reset_type { 145 HNAE3_VF_RESET, 146 HNAE3_VF_FUNC_RESET, 147 HNAE3_VF_PF_FUNC_RESET, 148 HNAE3_VF_FULL_RESET, 149 HNAE3_FLR_RESET, 150 HNAE3_FUNC_RESET, 151 HNAE3_GLOBAL_RESET, 152 HNAE3_IMP_RESET, 153 HNAE3_UNKNOWN_RESET, 154 HNAE3_NONE_RESET, 155 }; 156 157 enum hnae3_flr_state { 158 HNAE3_FLR_DOWN, 159 HNAE3_FLR_DONE, 160 }; 161 162 enum hnae3_port_base_vlan_state { 163 HNAE3_PORT_BASE_VLAN_DISABLE, 164 HNAE3_PORT_BASE_VLAN_ENABLE, 165 HNAE3_PORT_BASE_VLAN_MODIFY, 166 HNAE3_PORT_BASE_VLAN_NOCHANGE, 167 }; 168 169 struct hnae3_vector_info { 170 u8 __iomem *io_addr; 171 int vector; 172 }; 173 174 #define HNAE3_RING_TYPE_B 0 175 #define HNAE3_RING_TYPE_TX 0 176 #define HNAE3_RING_TYPE_RX 1 177 #define HNAE3_RING_GL_IDX_S 0 178 #define HNAE3_RING_GL_IDX_M GENMASK(1, 0) 179 #define HNAE3_RING_GL_RX 0 180 #define HNAE3_RING_GL_TX 1 181 182 #define HNAE3_FW_VERSION_BYTE3_SHIFT 24 183 #define HNAE3_FW_VERSION_BYTE3_MASK GENMASK(31, 24) 184 #define HNAE3_FW_VERSION_BYTE2_SHIFT 16 185 #define HNAE3_FW_VERSION_BYTE2_MASK GENMASK(23, 16) 186 #define HNAE3_FW_VERSION_BYTE1_SHIFT 8 187 #define HNAE3_FW_VERSION_BYTE1_MASK GENMASK(15, 8) 188 #define HNAE3_FW_VERSION_BYTE0_SHIFT 0 189 #define HNAE3_FW_VERSION_BYTE0_MASK GENMASK(7, 0) 190 191 struct hnae3_ring_chain_node { 192 struct hnae3_ring_chain_node *next; 193 u32 tqp_index; 194 u32 flag; 195 u32 int_gl_idx; 196 }; 197 198 #define HNAE3_IS_TX_RING(node) \ 199 (((node)->flag & (1 << HNAE3_RING_TYPE_B)) == HNAE3_RING_TYPE_TX) 200 201 struct hnae3_client_ops { 202 int (*init_instance)(struct hnae3_handle *handle); 203 void (*uninit_instance)(struct hnae3_handle *handle, bool reset); 204 void (*link_status_change)(struct hnae3_handle *handle, bool state); 205 int (*setup_tc)(struct hnae3_handle *handle, u8 tc); 206 int (*reset_notify)(struct hnae3_handle *handle, 207 enum hnae3_reset_notify_type type); 208 enum hnae3_reset_type (*process_hw_error)(struct hnae3_handle *handle); 209 }; 210 211 #define HNAE3_CLIENT_NAME_LENGTH 16 212 struct hnae3_client { 213 char name[HNAE3_CLIENT_NAME_LENGTH]; 214 unsigned long state; 215 enum hnae3_client_type type; 216 const struct hnae3_client_ops *ops; 217 struct list_head node; 218 }; 219 220 struct hnae3_ae_dev { 221 struct pci_dev *pdev; 222 const struct hnae3_ae_ops *ops; 223 struct list_head node; 224 u32 flag; 225 unsigned long hw_err_reset_req; 226 enum hnae3_reset_type reset_type; 227 void *priv; 228 }; 229 230 /* This struct defines the operation on the handle. 231 * 232 * init_ae_dev(): (mandatory) 233 * Get PF configure from pci_dev and initialize PF hardware 234 * uninit_ae_dev() 235 * Disable PF device and release PF resource 236 * register_client 237 * Register client to ae_dev 238 * unregister_client() 239 * Unregister client from ae_dev 240 * start() 241 * Enable the hardware 242 * stop() 243 * Disable the hardware 244 * start_client() 245 * Inform the hclge that client has been started 246 * stop_client() 247 * Inform the hclge that client has been stopped 248 * get_status() 249 * Get the carrier state of the back channel of the handle, 1 for ok, 0 for 250 * non-ok 251 * get_ksettings_an_result() 252 * Get negotiation status,speed and duplex 253 * get_media_type() 254 * Get media type of MAC 255 * check_port_speed() 256 * Check target speed whether is supported 257 * adjust_link() 258 * Adjust link status 259 * set_loopback() 260 * Set loopback 261 * set_promisc_mode 262 * Set promisc mode 263 * set_mtu() 264 * set mtu 265 * get_pauseparam() 266 * get tx and rx of pause frame use 267 * set_pauseparam() 268 * set tx and rx of pause frame use 269 * set_autoneg() 270 * set auto autonegotiation of pause frame use 271 * get_autoneg() 272 * get auto autonegotiation of pause frame use 273 * restart_autoneg() 274 * restart autonegotiation 275 * halt_autoneg() 276 * halt/resume autonegotiation when autonegotiation on 277 * get_coalesce_usecs() 278 * get usecs to delay a TX interrupt after a packet is sent 279 * get_rx_max_coalesced_frames() 280 * get Maximum number of packets to be sent before a TX interrupt. 281 * set_coalesce_usecs() 282 * set usecs to delay a TX interrupt after a packet is sent 283 * set_coalesce_frames() 284 * set Maximum number of packets to be sent before a TX interrupt. 285 * get_mac_addr() 286 * get mac address 287 * set_mac_addr() 288 * set mac address 289 * add_uc_addr 290 * Add unicast addr to mac table 291 * rm_uc_addr 292 * Remove unicast addr from mac table 293 * set_mc_addr() 294 * Set multicast address 295 * add_mc_addr 296 * Add multicast address to mac table 297 * rm_mc_addr 298 * Remove multicast address from mac table 299 * update_stats() 300 * Update Old network device statistics 301 * get_ethtool_stats() 302 * Get ethtool network device statistics 303 * get_strings() 304 * Get a set of strings that describe the requested objects 305 * get_sset_count() 306 * Get number of strings that @get_strings will write 307 * update_led_status() 308 * Update the led status 309 * set_led_id() 310 * Set led id 311 * get_regs() 312 * Get regs dump 313 * get_regs_len() 314 * Get the len of the regs dump 315 * get_rss_key_size() 316 * Get rss key size 317 * get_rss_indir_size() 318 * Get rss indirection table size 319 * get_rss() 320 * Get rss table 321 * set_rss() 322 * Set rss table 323 * get_tc_size() 324 * Get tc size of handle 325 * get_vector() 326 * Get vector number and vector information 327 * put_vector() 328 * Put the vector in hdev 329 * map_ring_to_vector() 330 * Map rings to vector 331 * unmap_ring_from_vector() 332 * Unmap rings from vector 333 * reset_queue() 334 * Reset queue 335 * get_fw_version() 336 * Get firmware version 337 * get_mdix_mode() 338 * Get media typr of phy 339 * enable_vlan_filter() 340 * Enable vlan filter 341 * set_vlan_filter() 342 * Set vlan filter config of Ports 343 * set_vf_vlan_filter() 344 * Set vlan filter config of vf 345 * restore_vlan_table() 346 * Restore vlan filter entries after reset 347 * enable_hw_strip_rxvtag() 348 * Enable/disable hardware strip vlan tag of packets received 349 * set_gro_en 350 * Enable/disable HW GRO 351 * add_arfs_entry 352 * Check the 5-tuples of flow, and create flow director rule 353 */ 354 struct hnae3_ae_ops { 355 int (*init_ae_dev)(struct hnae3_ae_dev *ae_dev); 356 void (*uninit_ae_dev)(struct hnae3_ae_dev *ae_dev); 357 void (*flr_prepare)(struct hnae3_ae_dev *ae_dev); 358 void (*flr_done)(struct hnae3_ae_dev *ae_dev); 359 int (*init_client_instance)(struct hnae3_client *client, 360 struct hnae3_ae_dev *ae_dev); 361 void (*uninit_client_instance)(struct hnae3_client *client, 362 struct hnae3_ae_dev *ae_dev); 363 int (*start)(struct hnae3_handle *handle); 364 void (*stop)(struct hnae3_handle *handle); 365 int (*client_start)(struct hnae3_handle *handle); 366 void (*client_stop)(struct hnae3_handle *handle); 367 int (*get_status)(struct hnae3_handle *handle); 368 void (*get_ksettings_an_result)(struct hnae3_handle *handle, 369 u8 *auto_neg, u32 *speed, u8 *duplex); 370 371 int (*cfg_mac_speed_dup_h)(struct hnae3_handle *handle, int speed, 372 u8 duplex); 373 374 void (*get_media_type)(struct hnae3_handle *handle, u8 *media_type, 375 u8 *module_type); 376 int (*check_port_speed)(struct hnae3_handle *handle, u32 speed); 377 void (*get_fec)(struct hnae3_handle *handle, u8 *fec_ability, 378 u8 *fec_mode); 379 int (*set_fec)(struct hnae3_handle *handle, u32 fec_mode); 380 void (*adjust_link)(struct hnae3_handle *handle, int speed, int duplex); 381 int (*set_loopback)(struct hnae3_handle *handle, 382 enum hnae3_loop loop_mode, bool en); 383 384 int (*set_promisc_mode)(struct hnae3_handle *handle, bool en_uc_pmc, 385 bool en_mc_pmc); 386 int (*set_mtu)(struct hnae3_handle *handle, int new_mtu); 387 388 void (*get_pauseparam)(struct hnae3_handle *handle, 389 u32 *auto_neg, u32 *rx_en, u32 *tx_en); 390 int (*set_pauseparam)(struct hnae3_handle *handle, 391 u32 auto_neg, u32 rx_en, u32 tx_en); 392 393 int (*set_autoneg)(struct hnae3_handle *handle, bool enable); 394 int (*get_autoneg)(struct hnae3_handle *handle); 395 int (*restart_autoneg)(struct hnae3_handle *handle); 396 int (*halt_autoneg)(struct hnae3_handle *handle, bool halt); 397 398 void (*get_coalesce_usecs)(struct hnae3_handle *handle, 399 u32 *tx_usecs, u32 *rx_usecs); 400 void (*get_rx_max_coalesced_frames)(struct hnae3_handle *handle, 401 u32 *tx_frames, u32 *rx_frames); 402 int (*set_coalesce_usecs)(struct hnae3_handle *handle, u32 timeout); 403 int (*set_coalesce_frames)(struct hnae3_handle *handle, 404 u32 coalesce_frames); 405 void (*get_coalesce_range)(struct hnae3_handle *handle, 406 u32 *tx_frames_low, u32 *rx_frames_low, 407 u32 *tx_frames_high, u32 *rx_frames_high, 408 u32 *tx_usecs_low, u32 *rx_usecs_low, 409 u32 *tx_usecs_high, u32 *rx_usecs_high); 410 411 void (*get_mac_addr)(struct hnae3_handle *handle, u8 *p); 412 int (*set_mac_addr)(struct hnae3_handle *handle, void *p, 413 bool is_first); 414 int (*do_ioctl)(struct hnae3_handle *handle, 415 struct ifreq *ifr, int cmd); 416 int (*add_uc_addr)(struct hnae3_handle *handle, 417 const unsigned char *addr); 418 int (*rm_uc_addr)(struct hnae3_handle *handle, 419 const unsigned char *addr); 420 int (*set_mc_addr)(struct hnae3_handle *handle, void *addr); 421 int (*add_mc_addr)(struct hnae3_handle *handle, 422 const unsigned char *addr); 423 int (*rm_mc_addr)(struct hnae3_handle *handle, 424 const unsigned char *addr); 425 void (*set_tso_stats)(struct hnae3_handle *handle, int enable); 426 void (*update_stats)(struct hnae3_handle *handle, 427 struct net_device_stats *net_stats); 428 void (*get_stats)(struct hnae3_handle *handle, u64 *data); 429 void (*get_mac_pause_stats)(struct hnae3_handle *handle, u64 *tx_cnt, 430 u64 *rx_cnt); 431 void (*get_strings)(struct hnae3_handle *handle, 432 u32 stringset, u8 *data); 433 int (*get_sset_count)(struct hnae3_handle *handle, int stringset); 434 435 void (*get_regs)(struct hnae3_handle *handle, u32 *version, 436 void *data); 437 int (*get_regs_len)(struct hnae3_handle *handle); 438 439 u32 (*get_rss_key_size)(struct hnae3_handle *handle); 440 u32 (*get_rss_indir_size)(struct hnae3_handle *handle); 441 int (*get_rss)(struct hnae3_handle *handle, u32 *indir, u8 *key, 442 u8 *hfunc); 443 int (*set_rss)(struct hnae3_handle *handle, const u32 *indir, 444 const u8 *key, const u8 hfunc); 445 int (*set_rss_tuple)(struct hnae3_handle *handle, 446 struct ethtool_rxnfc *cmd); 447 int (*get_rss_tuple)(struct hnae3_handle *handle, 448 struct ethtool_rxnfc *cmd); 449 450 int (*get_tc_size)(struct hnae3_handle *handle); 451 452 int (*get_vector)(struct hnae3_handle *handle, u16 vector_num, 453 struct hnae3_vector_info *vector_info); 454 int (*put_vector)(struct hnae3_handle *handle, int vector_num); 455 int (*map_ring_to_vector)(struct hnae3_handle *handle, 456 int vector_num, 457 struct hnae3_ring_chain_node *vr_chain); 458 int (*unmap_ring_from_vector)(struct hnae3_handle *handle, 459 int vector_num, 460 struct hnae3_ring_chain_node *vr_chain); 461 462 int (*reset_queue)(struct hnae3_handle *handle, u16 queue_id); 463 u32 (*get_fw_version)(struct hnae3_handle *handle); 464 void (*get_mdix_mode)(struct hnae3_handle *handle, 465 u8 *tp_mdix_ctrl, u8 *tp_mdix); 466 467 void (*enable_vlan_filter)(struct hnae3_handle *handle, bool enable); 468 int (*set_vlan_filter)(struct hnae3_handle *handle, __be16 proto, 469 u16 vlan_id, bool is_kill); 470 int (*set_vf_vlan_filter)(struct hnae3_handle *handle, int vfid, 471 u16 vlan, u8 qos, __be16 proto); 472 int (*enable_hw_strip_rxvtag)(struct hnae3_handle *handle, bool enable); 473 void (*reset_event)(struct pci_dev *pdev, struct hnae3_handle *handle); 474 enum hnae3_reset_type (*get_reset_level)(struct hnae3_ae_dev *ae_dev, 475 unsigned long *addr); 476 void (*set_default_reset_request)(struct hnae3_ae_dev *ae_dev, 477 enum hnae3_reset_type rst_type); 478 void (*get_channels)(struct hnae3_handle *handle, 479 struct ethtool_channels *ch); 480 void (*get_tqps_and_rss_info)(struct hnae3_handle *h, 481 u16 *alloc_tqps, u16 *max_rss_size); 482 int (*set_channels)(struct hnae3_handle *handle, u32 new_tqps_num, 483 bool rxfh_configured); 484 void (*get_flowctrl_adv)(struct hnae3_handle *handle, 485 u32 *flowctrl_adv); 486 int (*set_led_id)(struct hnae3_handle *handle, 487 enum ethtool_phys_id_state status); 488 void (*get_link_mode)(struct hnae3_handle *handle, 489 unsigned long *supported, 490 unsigned long *advertising); 491 int (*add_fd_entry)(struct hnae3_handle *handle, 492 struct ethtool_rxnfc *cmd); 493 int (*del_fd_entry)(struct hnae3_handle *handle, 494 struct ethtool_rxnfc *cmd); 495 void (*del_all_fd_entries)(struct hnae3_handle *handle, 496 bool clear_list); 497 int (*get_fd_rule_cnt)(struct hnae3_handle *handle, 498 struct ethtool_rxnfc *cmd); 499 int (*get_fd_rule_info)(struct hnae3_handle *handle, 500 struct ethtool_rxnfc *cmd); 501 int (*get_fd_all_rules)(struct hnae3_handle *handle, 502 struct ethtool_rxnfc *cmd, u32 *rule_locs); 503 int (*restore_fd_rules)(struct hnae3_handle *handle); 504 void (*enable_fd)(struct hnae3_handle *handle, bool enable); 505 int (*add_arfs_entry)(struct hnae3_handle *handle, u16 queue_id, 506 u16 flow_id, struct flow_keys *fkeys); 507 int (*dbg_run_cmd)(struct hnae3_handle *handle, const char *cmd_buf); 508 pci_ers_result_t (*handle_hw_ras_error)(struct hnae3_ae_dev *ae_dev); 509 bool (*get_hw_reset_stat)(struct hnae3_handle *handle); 510 bool (*ae_dev_resetting)(struct hnae3_handle *handle); 511 unsigned long (*ae_dev_reset_cnt)(struct hnae3_handle *handle); 512 int (*set_gro_en)(struct hnae3_handle *handle, bool enable); 513 u16 (*get_global_queue_id)(struct hnae3_handle *handle, u16 queue_id); 514 void (*set_timer_task)(struct hnae3_handle *handle, bool enable); 515 int (*mac_connect_phy)(struct hnae3_handle *handle); 516 void (*mac_disconnect_phy)(struct hnae3_handle *handle); 517 void (*restore_vlan_table)(struct hnae3_handle *handle); 518 }; 519 520 struct hnae3_dcb_ops { 521 /* IEEE 802.1Qaz std */ 522 int (*ieee_getets)(struct hnae3_handle *, struct ieee_ets *); 523 int (*ieee_setets)(struct hnae3_handle *, struct ieee_ets *); 524 int (*ieee_getpfc)(struct hnae3_handle *, struct ieee_pfc *); 525 int (*ieee_setpfc)(struct hnae3_handle *, struct ieee_pfc *); 526 527 /* DCBX configuration */ 528 u8 (*getdcbx)(struct hnae3_handle *); 529 u8 (*setdcbx)(struct hnae3_handle *, u8); 530 531 int (*setup_tc)(struct hnae3_handle *, u8, u8 *); 532 }; 533 534 struct hnae3_ae_algo { 535 const struct hnae3_ae_ops *ops; 536 struct list_head node; 537 const struct pci_device_id *pdev_id_table; 538 }; 539 540 #define HNAE3_INT_NAME_LEN (IFNAMSIZ + 16) 541 #define HNAE3_ITR_COUNTDOWN_START 100 542 543 struct hnae3_tc_info { 544 u16 tqp_offset; /* TQP offset from base TQP */ 545 u16 tqp_count; /* Total TQPs */ 546 u8 tc; /* TC index */ 547 bool enable; /* If this TC is enable or not */ 548 }; 549 550 #define HNAE3_MAX_TC 8 551 #define HNAE3_MAX_USER_PRIO 8 552 struct hnae3_knic_private_info { 553 struct net_device *netdev; /* Set by KNIC client when init instance */ 554 u16 rss_size; /* Allocated RSS queues */ 555 u16 req_rss_size; 556 u16 rx_buf_len; 557 u16 num_tx_desc; 558 u16 num_rx_desc; 559 560 u8 num_tc; /* Total number of enabled TCs */ 561 u8 prio_tc[HNAE3_MAX_USER_PRIO]; /* TC indexed by prio */ 562 struct hnae3_tc_info tc_info[HNAE3_MAX_TC]; /* Idx of array is HW TC */ 563 564 u16 num_tqps; /* total number of TQPs in this handle */ 565 struct hnae3_queue **tqp; /* array base of all TQPs in this instance */ 566 const struct hnae3_dcb_ops *dcb_ops; 567 568 u16 int_rl_setting; 569 enum pkt_hash_types rss_type; 570 }; 571 572 struct hnae3_roce_private_info { 573 struct net_device *netdev; 574 void __iomem *roce_io_base; 575 int base_vector; 576 int num_vectors; 577 578 /* The below attributes defined for RoCE client, hnae3 gives 579 * initial values to them, and RoCE client can modify and use 580 * them. 581 */ 582 unsigned long reset_state; 583 unsigned long instance_state; 584 unsigned long state; 585 }; 586 587 struct hnae3_unic_private_info { 588 struct net_device *netdev; 589 u16 rx_buf_len; 590 u16 num_tx_desc; 591 u16 num_rx_desc; 592 593 u16 num_tqps; /* total number of tqps in this handle */ 594 struct hnae3_queue **tqp; /* array base of all TQPs of this instance */ 595 }; 596 597 #define HNAE3_SUPPORT_APP_LOOPBACK BIT(0) 598 #define HNAE3_SUPPORT_PHY_LOOPBACK BIT(1) 599 #define HNAE3_SUPPORT_SERDES_SERIAL_LOOPBACK BIT(2) 600 #define HNAE3_SUPPORT_VF BIT(3) 601 #define HNAE3_SUPPORT_SERDES_PARALLEL_LOOPBACK BIT(4) 602 603 #define HNAE3_USER_UPE BIT(0) /* unicast promisc enabled by user */ 604 #define HNAE3_USER_MPE BIT(1) /* mulitcast promisc enabled by user */ 605 #define HNAE3_BPE BIT(2) /* broadcast promisc enable */ 606 #define HNAE3_OVERFLOW_UPE BIT(3) /* unicast mac vlan overflow */ 607 #define HNAE3_OVERFLOW_MPE BIT(4) /* multicast mac vlan overflow */ 608 #define HNAE3_VLAN_FLTR BIT(5) /* enable vlan filter */ 609 #define HNAE3_UPE (HNAE3_USER_UPE | HNAE3_OVERFLOW_UPE) 610 #define HNAE3_MPE (HNAE3_USER_MPE | HNAE3_OVERFLOW_MPE) 611 612 struct hnae3_handle { 613 struct hnae3_client *client; 614 struct pci_dev *pdev; 615 void *priv; 616 struct hnae3_ae_algo *ae_algo; /* the class who provides this handle */ 617 u64 flags; /* Indicate the capabilities for this handle*/ 618 619 union { 620 struct net_device *netdev; /* first member */ 621 struct hnae3_knic_private_info kinfo; 622 struct hnae3_unic_private_info uinfo; 623 struct hnae3_roce_private_info rinfo; 624 }; 625 626 u32 numa_node_mask; /* for multi-chip support */ 627 628 enum hnae3_port_base_vlan_state port_base_vlan_state; 629 630 u8 netdev_flags; 631 struct dentry *hnae3_dbgfs; 632 633 /* Network interface message level enabled bits */ 634 u32 msg_enable; 635 }; 636 637 #define hnae3_set_field(origin, mask, shift, val) \ 638 do { \ 639 (origin) &= (~(mask)); \ 640 (origin) |= ((val) << (shift)) & (mask); \ 641 } while (0) 642 #define hnae3_get_field(origin, mask, shift) (((origin) & (mask)) >> (shift)) 643 644 #define hnae3_set_bit(origin, shift, val) \ 645 hnae3_set_field((origin), (0x1 << (shift)), (shift), (val)) 646 #define hnae3_get_bit(origin, shift) \ 647 hnae3_get_field((origin), (0x1 << (shift)), (shift)) 648 649 int hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev); 650 void hnae3_unregister_ae_dev(struct hnae3_ae_dev *ae_dev); 651 652 void hnae3_unregister_ae_algo(struct hnae3_ae_algo *ae_algo); 653 void hnae3_register_ae_algo(struct hnae3_ae_algo *ae_algo); 654 655 void hnae3_unregister_client(struct hnae3_client *client); 656 int hnae3_register_client(struct hnae3_client *client); 657 658 void hnae3_set_client_init_flag(struct hnae3_client *client, 659 struct hnae3_ae_dev *ae_dev, 660 unsigned int inited); 661 #endif 662