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_rss_template_mgmt
{
365 struct hinic_rss_template_key
{
373 u8 key
[HINIC_RSS_KEY_SIZE
];
376 struct hinic_rss_context_tbl
{
384 struct hinic_rss_context_table
{
395 struct hinic_rss_indirect_tbl
{
400 u8 entry
[HINIC_RSS_INDIR_SIZE
];
403 struct hinic_rss_indir_table
{
411 u8 indir
[HINIC_RSS_INDIR_SIZE
];
414 struct hinic_rss_key
{
422 u8 key
[HINIC_RSS_KEY_SIZE
];
425 struct hinic_rss_engine_type
{
436 struct hinic_rss_config
{
444 u8 rq_priority_number
;
449 char name
[ETH_GSTRING_LEN
];
454 struct hinic_vport_stats
{
455 u64 tx_unicast_pkts_vport
;
456 u64 tx_unicast_bytes_vport
;
457 u64 tx_multicast_pkts_vport
;
458 u64 tx_multicast_bytes_vport
;
459 u64 tx_broadcast_pkts_vport
;
460 u64 tx_broadcast_bytes_vport
;
462 u64 rx_unicast_pkts_vport
;
463 u64 rx_unicast_bytes_vport
;
464 u64 rx_multicast_pkts_vport
;
465 u64 rx_multicast_bytes_vport
;
466 u64 rx_broadcast_pkts_vport
;
467 u64 rx_broadcast_bytes_vport
;
469 u64 tx_discard_vport
;
470 u64 rx_discard_vport
;
475 struct hinic_phy_port_stats
{
476 u64 mac_rx_total_pkt_num
;
477 u64 mac_rx_total_oct_num
;
478 u64 mac_rx_bad_pkt_num
;
479 u64 mac_rx_bad_oct_num
;
480 u64 mac_rx_good_pkt_num
;
481 u64 mac_rx_good_oct_num
;
482 u64 mac_rx_uni_pkt_num
;
483 u64 mac_rx_multi_pkt_num
;
484 u64 mac_rx_broad_pkt_num
;
486 u64 mac_tx_total_pkt_num
;
487 u64 mac_tx_total_oct_num
;
488 u64 mac_tx_bad_pkt_num
;
489 u64 mac_tx_bad_oct_num
;
490 u64 mac_tx_good_pkt_num
;
491 u64 mac_tx_good_oct_num
;
492 u64 mac_tx_uni_pkt_num
;
493 u64 mac_tx_multi_pkt_num
;
494 u64 mac_tx_broad_pkt_num
;
496 u64 mac_rx_fragment_pkt_num
;
497 u64 mac_rx_undersize_pkt_num
;
498 u64 mac_rx_undermin_pkt_num
;
499 u64 mac_rx_64_oct_pkt_num
;
500 u64 mac_rx_65_127_oct_pkt_num
;
501 u64 mac_rx_128_255_oct_pkt_num
;
502 u64 mac_rx_256_511_oct_pkt_num
;
503 u64 mac_rx_512_1023_oct_pkt_num
;
504 u64 mac_rx_1024_1518_oct_pkt_num
;
505 u64 mac_rx_1519_2047_oct_pkt_num
;
506 u64 mac_rx_2048_4095_oct_pkt_num
;
507 u64 mac_rx_4096_8191_oct_pkt_num
;
508 u64 mac_rx_8192_9216_oct_pkt_num
;
509 u64 mac_rx_9217_12287_oct_pkt_num
;
510 u64 mac_rx_12288_16383_oct_pkt_num
;
511 u64 mac_rx_1519_max_bad_pkt_num
;
512 u64 mac_rx_1519_max_good_pkt_num
;
513 u64 mac_rx_oversize_pkt_num
;
514 u64 mac_rx_jabber_pkt_num
;
516 u64 mac_rx_pause_num
;
517 u64 mac_rx_pfc_pkt_num
;
518 u64 mac_rx_pfc_pri0_pkt_num
;
519 u64 mac_rx_pfc_pri1_pkt_num
;
520 u64 mac_rx_pfc_pri2_pkt_num
;
521 u64 mac_rx_pfc_pri3_pkt_num
;
522 u64 mac_rx_pfc_pri4_pkt_num
;
523 u64 mac_rx_pfc_pri5_pkt_num
;
524 u64 mac_rx_pfc_pri6_pkt_num
;
525 u64 mac_rx_pfc_pri7_pkt_num
;
526 u64 mac_rx_control_pkt_num
;
527 u64 mac_rx_y1731_pkt_num
;
528 u64 mac_rx_sym_err_pkt_num
;
529 u64 mac_rx_fcs_err_pkt_num
;
530 u64 mac_rx_send_app_good_pkt_num
;
531 u64 mac_rx_send_app_bad_pkt_num
;
533 u64 mac_tx_fragment_pkt_num
;
534 u64 mac_tx_undersize_pkt_num
;
535 u64 mac_tx_undermin_pkt_num
;
536 u64 mac_tx_64_oct_pkt_num
;
537 u64 mac_tx_65_127_oct_pkt_num
;
538 u64 mac_tx_128_255_oct_pkt_num
;
539 u64 mac_tx_256_511_oct_pkt_num
;
540 u64 mac_tx_512_1023_oct_pkt_num
;
541 u64 mac_tx_1024_1518_oct_pkt_num
;
542 u64 mac_tx_1519_2047_oct_pkt_num
;
543 u64 mac_tx_2048_4095_oct_pkt_num
;
544 u64 mac_tx_4096_8191_oct_pkt_num
;
545 u64 mac_tx_8192_9216_oct_pkt_num
;
546 u64 mac_tx_9217_12287_oct_pkt_num
;
547 u64 mac_tx_12288_16383_oct_pkt_num
;
548 u64 mac_tx_1519_max_bad_pkt_num
;
549 u64 mac_tx_1519_max_good_pkt_num
;
550 u64 mac_tx_oversize_pkt_num
;
551 u64 mac_tx_jabber_pkt_num
;
553 u64 mac_tx_pause_num
;
554 u64 mac_tx_pfc_pkt_num
;
555 u64 mac_tx_pfc_pri0_pkt_num
;
556 u64 mac_tx_pfc_pri1_pkt_num
;
557 u64 mac_tx_pfc_pri2_pkt_num
;
558 u64 mac_tx_pfc_pri3_pkt_num
;
559 u64 mac_tx_pfc_pri4_pkt_num
;
560 u64 mac_tx_pfc_pri5_pkt_num
;
561 u64 mac_tx_pfc_pri6_pkt_num
;
562 u64 mac_tx_pfc_pri7_pkt_num
;
563 u64 mac_tx_control_pkt_num
;
564 u64 mac_tx_y1731_pkt_num
;
565 u64 mac_tx_1588_pkt_num
;
566 u64 mac_tx_err_all_pkt_num
;
567 u64 mac_tx_from_app_good_pkt_num
;
568 u64 mac_tx_from_app_bad_pkt_num
;
570 u64 mac_rx_higig2_ext_pkt_num
;
571 u64 mac_rx_higig2_message_pkt_num
;
572 u64 mac_rx_higig2_error_pkt_num
;
573 u64 mac_rx_higig2_cpu_ctrl_pkt_num
;
574 u64 mac_rx_higig2_unicast_pkt_num
;
575 u64 mac_rx_higig2_broadcast_pkt_num
;
576 u64 mac_rx_higig2_l2_multicast_pkt_num
;
577 u64 mac_rx_higig2_l3_multicast_pkt_num
;
579 u64 mac_tx_higig2_message_pkt_num
;
580 u64 mac_tx_higig2_ext_pkt_num
;
581 u64 mac_tx_higig2_cpu_ctrl_pkt_num
;
582 u64 mac_tx_higig2_unicast_pkt_num
;
583 u64 mac_tx_higig2_broadcast_pkt_num
;
584 u64 mac_tx_higig2_l2_multicast_pkt_num
;
585 u64 mac_tx_higig2_l3_multicast_pkt_num
;
588 struct hinic_port_stats_info
{
599 struct hinic_port_stats
{
604 struct hinic_phy_port_stats stats
;
607 struct hinic_cmd_vport_stats
{
612 struct hinic_vport_stats stats
;
615 struct hinic_tx_rate_cfg_max_min
{
627 struct hinic_tx_rate_cfg
{
637 enum nic_speed_level
{
648 struct hinic_spoofchk_set
{
658 struct hinic_pause_config
{
670 struct hinic_set_pfc
{
681 /* get or set loopback mode, need to modify by base API */
682 #define HINIC_INTERNAL_LP_MODE 5
683 #define LOOP_MODE_MIN 1
684 #define LOOP_MODE_MAX 6
686 struct hinic_port_loopback
{
695 struct hinic_led_info
{
706 #define STD_SFP_INFO_MAX_SIZE 640
708 struct hinic_cmd_get_light_module_abs
{
714 u8 abs_status
; /* 0:present, 1:absent */
718 #define STD_SFP_INFO_MAX_SIZE 640
720 struct hinic_cmd_get_std_sfp_info
{
729 u8 sfp_info
[STD_SFP_INFO_MAX_SIZE
];
732 struct hinic_cmd_update_fw
{
751 u32 setion_total_len
;
752 u32 fw_section_version
;
757 int hinic_port_add_mac(struct hinic_dev
*nic_dev
, const u8
*addr
,
760 int hinic_port_del_mac(struct hinic_dev
*nic_dev
, const u8
*addr
,
763 int hinic_port_get_mac(struct hinic_dev
*nic_dev
, u8
*addr
);
765 int hinic_port_set_mtu(struct hinic_dev
*nic_dev
, int new_mtu
);
767 int hinic_port_add_vlan(struct hinic_dev
*nic_dev
, u16 vlan_id
);
769 int hinic_port_del_vlan(struct hinic_dev
*nic_dev
, u16 vlan_id
);
771 int hinic_port_set_rx_mode(struct hinic_dev
*nic_dev
, u32 rx_mode
);
773 int hinic_port_link_state(struct hinic_dev
*nic_dev
,
774 enum hinic_port_link_state
*link_state
);
776 int hinic_port_set_state(struct hinic_dev
*nic_dev
,
777 enum hinic_port_state state
);
779 int hinic_port_set_func_state(struct hinic_dev
*nic_dev
,
780 enum hinic_func_port_state state
);
782 int hinic_port_get_cap(struct hinic_dev
*nic_dev
,
783 struct hinic_port_cap
*port_cap
);
785 int hinic_set_max_qnum(struct hinic_dev
*nic_dev
, u8 num_rqs
);
787 int hinic_port_set_tso(struct hinic_dev
*nic_dev
, enum hinic_tso_state state
);
789 int hinic_set_rx_csum_offload(struct hinic_dev
*nic_dev
, u32 en
);
791 int hinic_set_rx_lro_state(struct hinic_dev
*nic_dev
, u8 lro_en
,
792 u32 lro_timer
, u32 wqe_num
);
794 int hinic_set_rss_type(struct hinic_dev
*nic_dev
, u32 tmpl_idx
,
795 struct hinic_rss_type rss_type
);
797 int hinic_rss_set_indir_tbl(struct hinic_dev
*nic_dev
, u32 tmpl_idx
,
798 const u32
*indir_table
);
800 int hinic_rss_set_template_tbl(struct hinic_dev
*nic_dev
, u32 template_id
,
803 int hinic_rss_set_hash_engine(struct hinic_dev
*nic_dev
, u8 template_id
,
806 int hinic_rss_cfg(struct hinic_dev
*nic_dev
, u8 rss_en
, u8 template_id
);
808 int hinic_rss_template_alloc(struct hinic_dev
*nic_dev
, u8
*tmpl_idx
);
810 int hinic_rss_template_free(struct hinic_dev
*nic_dev
, u8 tmpl_idx
);
812 void hinic_set_ethtool_ops(struct net_device
*netdev
);
814 int hinic_get_rss_type(struct hinic_dev
*nic_dev
, u32 tmpl_idx
,
815 struct hinic_rss_type
*rss_type
);
817 int hinic_rss_get_indir_tbl(struct hinic_dev
*nic_dev
, u32 tmpl_idx
,
820 int hinic_rss_get_template_tbl(struct hinic_dev
*nic_dev
, u32 tmpl_idx
,
823 int hinic_rss_get_hash_engine(struct hinic_dev
*nic_dev
, u8 tmpl_idx
,
826 int hinic_get_phy_port_stats(struct hinic_dev
*nic_dev
,
827 struct hinic_phy_port_stats
*stats
);
829 int hinic_get_vport_stats(struct hinic_dev
*nic_dev
,
830 struct hinic_vport_stats
*stats
);
832 int hinic_set_rx_vlan_offload(struct hinic_dev
*nic_dev
, u8 en
);
834 int hinic_get_mgmt_version(struct hinic_dev
*nic_dev
, u8
*mgmt_ver
);
836 int hinic_set_link_settings(struct hinic_hwdev
*hwdev
,
837 struct hinic_link_ksettings_info
*info
);
839 int hinic_get_link_mode(struct hinic_hwdev
*hwdev
,
840 struct hinic_link_mode_cmd
*link_mode
);
842 int hinic_set_autoneg(struct hinic_hwdev
*hwdev
, bool enable
);
844 int hinic_set_speed(struct hinic_hwdev
*hwdev
, enum nic_speed_level speed
);
846 int hinic_get_hw_pause_info(struct hinic_hwdev
*hwdev
,
847 struct hinic_pause_config
*pause_info
);
849 int hinic_set_hw_pause_info(struct hinic_hwdev
*hwdev
,
850 struct hinic_pause_config
*pause_info
);
852 int hinic_dcb_set_pfc(struct hinic_hwdev
*hwdev
, u8 pfc_en
, u8 pfc_bitmap
);
854 int hinic_set_loopback_mode(struct hinic_hwdev
*hwdev
, u32 mode
, u32 enable
);
856 enum hinic_led_mode
{
859 HINIC_LED_MODE_FORCE_1HZ
,
860 HINIC_LED_MODE_FORCE_2HZ
,
861 HINIC_LED_MODE_FORCE_4HZ
,
865 HINIC_LED_MODE_INVALID
,
868 enum hinic_led_type
{
870 HINIC_LED_TYPE_LOW_SPEED
,
871 HINIC_LED_TYPE_HIGH_SPEED
,
872 HINIC_LED_TYPE_INVALID
,
875 int hinic_reset_led_status(struct hinic_hwdev
*hwdev
, u8 port
);
877 int hinic_set_led_status(struct hinic_hwdev
*hwdev
, u8 port
,
878 enum hinic_led_type type
, enum hinic_led_mode mode
);
880 int hinic_get_sfp_type(struct hinic_hwdev
*hwdev
, u8
*data0
, u8
*data1
);
882 int hinic_get_sfp_eeprom(struct hinic_hwdev
*hwdev
, u8
*data
, u16
*len
);
884 int hinic_open(struct net_device
*netdev
);
886 int hinic_close(struct net_device
*netdev
);