1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Huawei HiNIC PCI Express Linux driver
4 * Copyright(c) 2017 Huawei Technologies Co., Ltd
10 #include <linux/types.h>
11 #include <linux/ethtool.h>
12 #include <linux/etherdevice.h>
13 #include <linux/bitops.h>
15 #include "hinic_dev.h"
17 #define HINIC_RSS_KEY_SIZE 40
18 #define HINIC_RSS_INDIR_SIZE 256
19 #define HINIC_PORT_STATS_VERSION 0
20 #define HINIC_FW_VERSION_NAME 16
21 #define HINIC_COMPILE_TIME_LEN 20
22 #define HINIC_MGMT_VERSION_MAX_LEN 32
24 struct hinic_version_info {
29 u8 ver[HINIC_FW_VERSION_NAME];
30 u8 time[HINIC_COMPILE_TIME_LEN];
34 HINIC_RX_MODE_UC = BIT(0),
35 HINIC_RX_MODE_MC = BIT(1),
36 HINIC_RX_MODE_BC = BIT(2),
37 HINIC_RX_MODE_MC_ALL = BIT(3),
38 HINIC_RX_MODE_PROMISC = BIT(4),
41 enum hinic_port_link_state {
42 HINIC_LINK_STATE_DOWN,
46 enum hinic_port_state {
47 HINIC_PORT_DISABLE = 0,
48 HINIC_PORT_ENABLE = 3,
51 enum hinic_func_port_state {
52 HINIC_FUNC_PORT_DISABLE = 0,
53 HINIC_FUNC_PORT_ENABLE = 2,
56 enum hinic_autoneg_cap {
57 HINIC_AUTONEG_UNSUPPORTED,
58 HINIC_AUTONEG_SUPPORTED,
61 enum hinic_autoneg_state {
62 HINIC_AUTONEG_DISABLED,
72 HINIC_SPEED_10MB_LINK = 0,
73 HINIC_SPEED_100MB_LINK,
74 HINIC_SPEED_1000MB_LINK,
75 HINIC_SPEED_10GB_LINK,
76 HINIC_SPEED_25GB_LINK,
77 HINIC_SPEED_40GB_LINK,
78 HINIC_SPEED_100GB_LINK,
80 HINIC_SPEED_UNKNOWN = 0xFF,
83 enum hinic_link_mode {
84 HINIC_10GE_BASE_KR = 0,
85 HINIC_40GE_BASE_KR4 = 1,
86 HINIC_40GE_BASE_CR4 = 2,
87 HINIC_100GE_BASE_KR4 = 3,
88 HINIC_100GE_BASE_CR4 = 4,
89 HINIC_25GE_BASE_KR_S = 5,
90 HINIC_25GE_BASE_CR_S = 6,
91 HINIC_25GE_BASE_KR = 7,
92 HINIC_25GE_BASE_CR = 8,
94 HINIC_LINK_MODE_NUMBERS,
96 HINIC_SUPPORTED_UNKNOWN = 0xFFFF,
99 enum hinic_port_type {
100 HINIC_PORT_TP, /* BASET */
103 HINIC_PORT_FIBRE, /* OPTICAL */
106 HINIC_PORT_COPPER, /* PORT_DA */
108 HINIC_PORT_BACKPLANE,
109 HINIC_PORT_NONE = 0xEF,
110 HINIC_PORT_OTHER = 0xFF,
113 enum hinic_valid_link_settings {
114 HILINK_LINK_SET_SPEED = 0x1,
115 HILINK_LINK_SET_AUTONEG = 0x2,
116 HILINK_LINK_SET_FEC = 0x4,
119 enum hinic_tso_state {
120 HINIC_TSO_DISABLE = 0,
121 HINIC_TSO_ENABLE = 1,
124 struct hinic_port_mac_cmd {
132 unsigned char mac[ETH_ALEN];
135 struct hinic_port_mtu_cmd {
145 struct hinic_port_vlan_cmd {
154 struct hinic_port_rx_mode_cmd {
164 struct hinic_port_link_cmd {
174 struct hinic_port_state_cmd {
183 struct hinic_port_link_status {
193 struct hinic_cable_plug_event {
199 u8 plugged; /* 0: unplugged, 1: plugged */
204 LINK_ERR_MODULE_UNRECOGENIZED,
208 struct hinic_link_err_event {
218 struct hinic_port_func_state_cmd {
229 struct hinic_port_cap {
244 struct hinic_link_mode_cmd {
251 u16 supported; /* 0xFFFF represents invalid value */
255 struct hinic_speed_cmd {
264 struct hinic_set_autoneg_cmd {
270 u16 enable; /* 1: enable , 0: disable */
273 struct hinic_link_ksettings_info {
282 u32 speed; /* enum nic_speed_level */
283 u8 autoneg; /* 0 - off; 1 - on */
284 u8 fec; /* 0 - RSFEC; 1 - BASEFEC; 2 - NOFEC */
285 u8 rsvd2[18]; /* reserved for duplex, port, etc. */
288 struct hinic_tso_config {
299 struct hinic_checksum_offload {
309 struct hinic_rq_num {
320 struct hinic_lro_config {
333 struct hinic_lro_timer {
338 u8 type; /* 0: set timer value, 1: get timer value */
339 u8 enable; /* when set lro time, enable should be 1 */
344 struct hinic_vlan_cfg {
354 struct hinic_vlan_filter {
364 struct hinic_rss_template_mgmt {
375 struct hinic_rss_template_key {
383 u8 key[HINIC_RSS_KEY_SIZE];
386 struct hinic_rss_context_tbl {
394 struct hinic_rss_context_table {
405 struct hinic_rss_indirect_tbl {
410 u8 entry[HINIC_RSS_INDIR_SIZE];
413 struct hinic_rss_indir_table {
421 u8 indir[HINIC_RSS_INDIR_SIZE];
424 struct hinic_rss_key {
432 u8 key[HINIC_RSS_KEY_SIZE];
435 struct hinic_rss_engine_type {
446 struct hinic_rss_config {
454 u8 rq_priority_number;
459 char name[ETH_GSTRING_LEN];
464 struct hinic_vport_stats {
465 u64 tx_unicast_pkts_vport;
466 u64 tx_unicast_bytes_vport;
467 u64 tx_multicast_pkts_vport;
468 u64 tx_multicast_bytes_vport;
469 u64 tx_broadcast_pkts_vport;
470 u64 tx_broadcast_bytes_vport;
472 u64 rx_unicast_pkts_vport;
473 u64 rx_unicast_bytes_vport;
474 u64 rx_multicast_pkts_vport;
475 u64 rx_multicast_bytes_vport;
476 u64 rx_broadcast_pkts_vport;
477 u64 rx_broadcast_bytes_vport;
479 u64 tx_discard_vport;
480 u64 rx_discard_vport;
485 struct hinic_phy_port_stats {
486 u64 mac_rx_total_pkt_num;
487 u64 mac_rx_total_oct_num;
488 u64 mac_rx_bad_pkt_num;
489 u64 mac_rx_bad_oct_num;
490 u64 mac_rx_good_pkt_num;
491 u64 mac_rx_good_oct_num;
492 u64 mac_rx_uni_pkt_num;
493 u64 mac_rx_multi_pkt_num;
494 u64 mac_rx_broad_pkt_num;
496 u64 mac_tx_total_pkt_num;
497 u64 mac_tx_total_oct_num;
498 u64 mac_tx_bad_pkt_num;
499 u64 mac_tx_bad_oct_num;
500 u64 mac_tx_good_pkt_num;
501 u64 mac_tx_good_oct_num;
502 u64 mac_tx_uni_pkt_num;
503 u64 mac_tx_multi_pkt_num;
504 u64 mac_tx_broad_pkt_num;
506 u64 mac_rx_fragment_pkt_num;
507 u64 mac_rx_undersize_pkt_num;
508 u64 mac_rx_undermin_pkt_num;
509 u64 mac_rx_64_oct_pkt_num;
510 u64 mac_rx_65_127_oct_pkt_num;
511 u64 mac_rx_128_255_oct_pkt_num;
512 u64 mac_rx_256_511_oct_pkt_num;
513 u64 mac_rx_512_1023_oct_pkt_num;
514 u64 mac_rx_1024_1518_oct_pkt_num;
515 u64 mac_rx_1519_2047_oct_pkt_num;
516 u64 mac_rx_2048_4095_oct_pkt_num;
517 u64 mac_rx_4096_8191_oct_pkt_num;
518 u64 mac_rx_8192_9216_oct_pkt_num;
519 u64 mac_rx_9217_12287_oct_pkt_num;
520 u64 mac_rx_12288_16383_oct_pkt_num;
521 u64 mac_rx_1519_max_bad_pkt_num;
522 u64 mac_rx_1519_max_good_pkt_num;
523 u64 mac_rx_oversize_pkt_num;
524 u64 mac_rx_jabber_pkt_num;
526 u64 mac_rx_pause_num;
527 u64 mac_rx_pfc_pkt_num;
528 u64 mac_rx_pfc_pri0_pkt_num;
529 u64 mac_rx_pfc_pri1_pkt_num;
530 u64 mac_rx_pfc_pri2_pkt_num;
531 u64 mac_rx_pfc_pri3_pkt_num;
532 u64 mac_rx_pfc_pri4_pkt_num;
533 u64 mac_rx_pfc_pri5_pkt_num;
534 u64 mac_rx_pfc_pri6_pkt_num;
535 u64 mac_rx_pfc_pri7_pkt_num;
536 u64 mac_rx_control_pkt_num;
537 u64 mac_rx_y1731_pkt_num;
538 u64 mac_rx_sym_err_pkt_num;
539 u64 mac_rx_fcs_err_pkt_num;
540 u64 mac_rx_send_app_good_pkt_num;
541 u64 mac_rx_send_app_bad_pkt_num;
543 u64 mac_tx_fragment_pkt_num;
544 u64 mac_tx_undersize_pkt_num;
545 u64 mac_tx_undermin_pkt_num;
546 u64 mac_tx_64_oct_pkt_num;
547 u64 mac_tx_65_127_oct_pkt_num;
548 u64 mac_tx_128_255_oct_pkt_num;
549 u64 mac_tx_256_511_oct_pkt_num;
550 u64 mac_tx_512_1023_oct_pkt_num;
551 u64 mac_tx_1024_1518_oct_pkt_num;
552 u64 mac_tx_1519_2047_oct_pkt_num;
553 u64 mac_tx_2048_4095_oct_pkt_num;
554 u64 mac_tx_4096_8191_oct_pkt_num;
555 u64 mac_tx_8192_9216_oct_pkt_num;
556 u64 mac_tx_9217_12287_oct_pkt_num;
557 u64 mac_tx_12288_16383_oct_pkt_num;
558 u64 mac_tx_1519_max_bad_pkt_num;
559 u64 mac_tx_1519_max_good_pkt_num;
560 u64 mac_tx_oversize_pkt_num;
561 u64 mac_tx_jabber_pkt_num;
563 u64 mac_tx_pause_num;
564 u64 mac_tx_pfc_pkt_num;
565 u64 mac_tx_pfc_pri0_pkt_num;
566 u64 mac_tx_pfc_pri1_pkt_num;
567 u64 mac_tx_pfc_pri2_pkt_num;
568 u64 mac_tx_pfc_pri3_pkt_num;
569 u64 mac_tx_pfc_pri4_pkt_num;
570 u64 mac_tx_pfc_pri5_pkt_num;
571 u64 mac_tx_pfc_pri6_pkt_num;
572 u64 mac_tx_pfc_pri7_pkt_num;
573 u64 mac_tx_control_pkt_num;
574 u64 mac_tx_y1731_pkt_num;
575 u64 mac_tx_1588_pkt_num;
576 u64 mac_tx_err_all_pkt_num;
577 u64 mac_tx_from_app_good_pkt_num;
578 u64 mac_tx_from_app_bad_pkt_num;
580 u64 mac_rx_higig2_ext_pkt_num;
581 u64 mac_rx_higig2_message_pkt_num;
582 u64 mac_rx_higig2_error_pkt_num;
583 u64 mac_rx_higig2_cpu_ctrl_pkt_num;
584 u64 mac_rx_higig2_unicast_pkt_num;
585 u64 mac_rx_higig2_broadcast_pkt_num;
586 u64 mac_rx_higig2_l2_multicast_pkt_num;
587 u64 mac_rx_higig2_l3_multicast_pkt_num;
589 u64 mac_tx_higig2_message_pkt_num;
590 u64 mac_tx_higig2_ext_pkt_num;
591 u64 mac_tx_higig2_cpu_ctrl_pkt_num;
592 u64 mac_tx_higig2_unicast_pkt_num;
593 u64 mac_tx_higig2_broadcast_pkt_num;
594 u64 mac_tx_higig2_l2_multicast_pkt_num;
595 u64 mac_tx_higig2_l3_multicast_pkt_num;
598 struct hinic_port_stats_info {
609 struct hinic_port_stats {
614 struct hinic_phy_port_stats stats;
617 struct hinic_cmd_vport_stats {
622 struct hinic_vport_stats stats;
625 struct hinic_tx_rate_cfg_max_min {
637 struct hinic_tx_rate_cfg {
647 enum nic_speed_level {
658 struct hinic_spoofchk_set {
668 struct hinic_pause_config {
680 struct hinic_set_pfc {
691 /* get or set loopback mode, need to modify by base API */
692 #define HINIC_INTERNAL_LP_MODE 5
693 #define LOOP_MODE_MIN 1
694 #define LOOP_MODE_MAX 6
696 struct hinic_port_loopback {
705 struct hinic_led_info {
716 #define STD_SFP_INFO_MAX_SIZE 640
718 struct hinic_cmd_get_light_module_abs {
724 u8 abs_status; /* 0:present, 1:absent */
728 #define STD_SFP_INFO_MAX_SIZE 640
730 struct hinic_cmd_get_std_sfp_info {
739 u8 sfp_info[STD_SFP_INFO_MAX_SIZE];
742 struct hinic_cmd_update_fw {
761 u32 setion_total_len;
762 u32 fw_section_version;
767 int hinic_port_add_mac(struct hinic_dev *nic_dev, const u8 *addr,
770 int hinic_port_del_mac(struct hinic_dev *nic_dev, const u8 *addr,
773 int hinic_port_get_mac(struct hinic_dev *nic_dev, u8 *addr);
775 int hinic_port_set_mtu(struct hinic_dev *nic_dev, int new_mtu);
777 int hinic_port_add_vlan(struct hinic_dev *nic_dev, u16 vlan_id);
779 int hinic_port_del_vlan(struct hinic_dev *nic_dev, u16 vlan_id);
781 int hinic_port_set_rx_mode(struct hinic_dev *nic_dev, u32 rx_mode);
783 int hinic_port_link_state(struct hinic_dev *nic_dev,
784 enum hinic_port_link_state *link_state);
786 int hinic_port_set_state(struct hinic_dev *nic_dev,
787 enum hinic_port_state state);
789 int hinic_port_set_func_state(struct hinic_dev *nic_dev,
790 enum hinic_func_port_state state);
792 int hinic_port_get_cap(struct hinic_dev *nic_dev,
793 struct hinic_port_cap *port_cap);
795 int hinic_set_max_qnum(struct hinic_dev *nic_dev, u8 num_rqs);
797 int hinic_port_set_tso(struct hinic_dev *nic_dev, enum hinic_tso_state state);
799 int hinic_set_rx_csum_offload(struct hinic_dev *nic_dev, u32 en);
801 int hinic_set_rx_lro_state(struct hinic_dev *nic_dev, u8 lro_en,
802 u32 lro_timer, u32 wqe_num);
804 int hinic_set_rss_type(struct hinic_dev *nic_dev, u32 tmpl_idx,
805 struct hinic_rss_type rss_type);
807 int hinic_rss_set_indir_tbl(struct hinic_dev *nic_dev, u32 tmpl_idx,
808 const u32 *indir_table);
810 int hinic_rss_set_template_tbl(struct hinic_dev *nic_dev, u32 template_id,
813 int hinic_rss_set_hash_engine(struct hinic_dev *nic_dev, u8 template_id,
816 int hinic_rss_cfg(struct hinic_dev *nic_dev, u8 rss_en, u8 template_id);
818 int hinic_rss_template_alloc(struct hinic_dev *nic_dev, u8 *tmpl_idx);
820 int hinic_rss_template_free(struct hinic_dev *nic_dev, u8 tmpl_idx);
822 void hinic_set_ethtool_ops(struct net_device *netdev);
824 int hinic_get_rss_type(struct hinic_dev *nic_dev, u32 tmpl_idx,
825 struct hinic_rss_type *rss_type);
827 int hinic_rss_get_indir_tbl(struct hinic_dev *nic_dev, u32 tmpl_idx,
830 int hinic_rss_get_template_tbl(struct hinic_dev *nic_dev, u32 tmpl_idx,
833 int hinic_rss_get_hash_engine(struct hinic_dev *nic_dev, u8 tmpl_idx,
836 int hinic_get_phy_port_stats(struct hinic_dev *nic_dev,
837 struct hinic_phy_port_stats *stats);
839 int hinic_get_vport_stats(struct hinic_dev *nic_dev,
840 struct hinic_vport_stats *stats);
842 int hinic_set_rx_vlan_offload(struct hinic_dev *nic_dev, u8 en);
844 int hinic_set_vlan_fliter(struct hinic_dev *nic_dev, u32 en);
846 int hinic_get_mgmt_version(struct hinic_dev *nic_dev, u8 *mgmt_ver);
848 int hinic_set_link_settings(struct hinic_hwdev *hwdev,
849 struct hinic_link_ksettings_info *info);
851 int hinic_get_link_mode(struct hinic_hwdev *hwdev,
852 struct hinic_link_mode_cmd *link_mode);
854 int hinic_set_autoneg(struct hinic_hwdev *hwdev, bool enable);
856 int hinic_set_speed(struct hinic_hwdev *hwdev, enum nic_speed_level speed);
858 int hinic_get_hw_pause_info(struct hinic_hwdev *hwdev,
859 struct hinic_pause_config *pause_info);
861 int hinic_set_hw_pause_info(struct hinic_hwdev *hwdev,
862 struct hinic_pause_config *pause_info);
864 int hinic_dcb_set_pfc(struct hinic_hwdev *hwdev, u8 pfc_en, u8 pfc_bitmap);
866 int hinic_set_loopback_mode(struct hinic_hwdev *hwdev, u32 mode, u32 enable);
868 enum hinic_led_mode {
871 HINIC_LED_MODE_FORCE_1HZ,
872 HINIC_LED_MODE_FORCE_2HZ,
873 HINIC_LED_MODE_FORCE_4HZ,
877 HINIC_LED_MODE_INVALID,
880 enum hinic_led_type {
882 HINIC_LED_TYPE_LOW_SPEED,
883 HINIC_LED_TYPE_HIGH_SPEED,
884 HINIC_LED_TYPE_INVALID,
887 int hinic_reset_led_status(struct hinic_hwdev *hwdev, u8 port);
889 int hinic_set_led_status(struct hinic_hwdev *hwdev, u8 port,
890 enum hinic_led_type type, enum hinic_led_mode mode);
892 int hinic_get_sfp_type(struct hinic_hwdev *hwdev, u8 *data0, u8 *data1);
894 int hinic_get_sfp_eeprom(struct hinic_hwdev *hwdev, u8 *data, u16 *len);
896 int hinic_open(struct net_device *netdev);
898 int hinic_close(struct net_device *netdev);