Merge tag 'wireless-drivers-2021-09-07' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-microblaze.git] / drivers / net / ethernet / hisilicon / hns3 / hns3_enet.h
index daa04ae..6162d9f 100644 (file)
@@ -4,7 +4,9 @@
 #ifndef __HNS3_ENET_H
 #define __HNS3_ENET_H
 
+#include <linux/dim.h>
 #include <linux/if_vlan.h>
+#include <net/page_pool.h>
 
 #include "hnae3.h"
 
@@ -19,6 +21,7 @@ enum hns3_nic_state {
        HNS3_NIC_STATE_SERVICE_SCHED,
        HNS3_NIC_STATE2_RESET_REQUESTED,
        HNS3_NIC_STATE_HW_TX_CSUM_ENABLE,
+       HNS3_NIC_STATE_RXD_ADV_LAYOUT_ENABLE,
        HNS3_NIC_STATE_MAX
 };
 
@@ -82,12 +85,6 @@ enum hns3_nic_state {
 #define HNS3_RXD_STRP_TAGP_S                   13
 #define HNS3_RXD_STRP_TAGP_M                   (0x3 << HNS3_RXD_STRP_TAGP_S)
 
-#define HNS3_RXD_L2_CSUM_B                     15
-#define HNS3_RXD_L2_CSUM_L_S                   4
-#define HNS3_RXD_L2_CSUM_L_M                   (0xff << HNS3_RXD_L2_CSUM_L_S)
-#define HNS3_RXD_L2_CSUM_H_S                   24
-#define HNS3_RXD_L2_CSUM_H_M                   (0xff << HNS3_RXD_L2_CSUM_H_S)
-
 #define HNS3_RXD_L2E_B                         16
 #define HNS3_RXD_L3E_B                         17
 #define HNS3_RXD_L4E_B                         18
@@ -114,6 +111,9 @@ enum hns3_nic_state {
 #define HNS3_RXD_FBLI_S                                14
 #define HNS3_RXD_FBLI_M                                (0x3 << HNS3_RXD_FBLI_S)
 
+#define HNS3_RXD_PTYPE_S                       4
+#define HNS3_RXD_PTYPE_M                       GENMASK(11, 4)
+
 #define HNS3_RXD_BDTYPE_S                      0
 #define HNS3_RXD_BDTYPE_M                      (0xf << HNS3_RXD_BDTYPE_S)
 #define HNS3_RXD_VLD_B                         4
@@ -123,8 +123,9 @@ enum hns3_nic_state {
 #define HNS3_RXD_LUM_B                         9
 #define HNS3_RXD_CRCP_B                                10
 #define HNS3_RXD_L3L4P_B                       11
-#define HNS3_RXD_TSIND_S                       12
-#define HNS3_RXD_TSIND_M                       (0x7 << HNS3_RXD_TSIND_S)
+#define HNS3_RXD_TSIDX_S                       12
+#define HNS3_RXD_TSIDX_M                       (0x3 << HNS3_RXD_TSIDX_S)
+#define HNS3_RXD_TS_VLD_B                      14
 #define HNS3_RXD_LKBK_B                                15
 #define HNS3_RXD_GRO_SIZE_S                    16
 #define HNS3_RXD_GRO_SIZE_M                    (0x3fff << HNS3_RXD_GRO_SIZE_S)
@@ -201,6 +202,12 @@ enum hns3_nic_state {
 
 #define HNS3_RING_EN_B                         0
 
+#define HNS3_GL0_CQ_MODE_REG                   0x20d00
+#define HNS3_GL1_CQ_MODE_REG                   0x20d04
+#define HNS3_GL2_CQ_MODE_REG                   0x20d08
+#define HNS3_CQ_MODE_EQE                       1U
+#define HNS3_CQ_MODE_CQE                       0U
+
 enum hns3_pkt_l2t_type {
        HNS3_L2_TYPE_UNICAST,
        HNS3_L2_TYPE_MULTICAST,
@@ -238,7 +245,14 @@ enum hns3_pkt_tun_type {
 
 /* hardware spec ring buffer format */
 struct __packed hns3_desc {
-       __le64 addr;
+       union {
+               __le64 addr;
+               __le16 csum;
+               struct {
+                       __le32 ts_nsec;
+                       __le32 ts_sec;
+               };
+       };
        union {
                struct {
                        __le16 vlan_tag;
@@ -292,6 +306,17 @@ struct __packed hns3_desc {
        };
 };
 
+enum hns3_desc_type {
+       DESC_TYPE_UNKNOWN               = 0,
+       DESC_TYPE_SKB                   = 1 << 0,
+       DESC_TYPE_FRAGLIST_SKB          = 1 << 1,
+       DESC_TYPE_PAGE                  = 1 << 2,
+       DESC_TYPE_BOUNCE_ALL            = 1 << 3,
+       DESC_TYPE_BOUNCE_HEAD           = 1 << 4,
+       DESC_TYPE_SGL_SKB               = 1 << 5,
+       DESC_TYPE_PP_FRAG               = 1 << 6,
+};
+
 struct hns3_desc_cb {
        dma_addr_t dma; /* dma address of this desc */
        void *buf;      /* cpu addr for a desc */
@@ -323,7 +348,7 @@ enum hns3_pkt_l3type {
        HNS3_L3_TYPE_LLDP,
        HNS3_L3_TYPE_BPDU,
        HNS3_L3_TYPE_MAC_PAUSE,
-       HNS3_L3_TYPE_PFC_PAUSE,/* 0x9*/
+       HNS3_L3_TYPE_PFC_PAUSE, /* 0x9 */
 
        /* reserved for 0xA~0xB */
 
@@ -366,6 +391,14 @@ enum hns3_pkt_ol4type {
        HNS3_OL4_TYPE_UNKNOWN
 };
 
+struct hns3_rx_ptype {
+       u32 ptype : 8;
+       u32 csum_level : 2;
+       u32 ip_summed : 2;
+       u32 l3_type : 4;
+       u32 valid : 1;
+};
+
 struct ring_stats {
        u64 sw_err_cnt;
        u64 seg_pkt_cnt;
@@ -383,6 +416,12 @@ struct ring_stats {
                        u64 tx_tso_err;
                        u64 over_max_recursion;
                        u64 hw_limitation;
+                       u64 tx_bounce;
+                       u64 tx_spare_full;
+                       u64 copy_bits_err;
+                       u64 tx_sgl;
+                       u64 skb2sgl_err;
+                       u64 map_sg_err;
                };
                struct {
                        u64 rx_pkts;
@@ -396,10 +435,22 @@ struct ring_stats {
                        u64 csum_complete;
                        u64 rx_multicast;
                        u64 non_reuse_pg;
+                       u64 frag_alloc_err;
+                       u64 frag_alloc;
                };
+               __le16 csum;
        };
 };
 
+struct hns3_tx_spare {
+       dma_addr_t dma;
+       void *buf;
+       u32 next_to_use;
+       u32 next_to_clean;
+       u32 last_to_clean;
+       u32 len;
+};
+
 struct hns3_enet_ring {
        struct hns3_desc *desc; /* dma map address space */
        struct hns3_desc_cb *desc_cb;
@@ -408,6 +459,7 @@ struct hns3_enet_ring {
        struct hnae3_queue *tqp;
        int queue_index;
        struct device *dev; /* will be used for DMA mapping of descriptors */
+       struct page_pool *page_pool;
 
        /* statistic */
        struct ring_stats stats;
@@ -422,18 +474,29 @@ struct hns3_enet_ring {
         * next_to_use
         */
        int next_to_clean;
-       union {
-               int last_to_use;        /* last idx used by xmit */
-               u32 pull_len;           /* memcpy len for current rx packet */
-       };
-       u32 frag_num;
-       void *va; /* first buffer address for current packet */
-
        u32 flag;          /* ring attribute */
 
        int pending_buf;
-       struct sk_buff *skb;
-       struct sk_buff *tail_skb;
+       union {
+               /* for Tx ring */
+               struct {
+                       u32 fd_qb_tx_sample;
+                       int last_to_use;        /* last idx used by xmit */
+                       u32 tx_copybreak;
+                       struct hns3_tx_spare *tx_spare;
+               };
+
+               /* for Rx ring */
+               struct {
+                       u32 pull_len;   /* memcpy len for current rx packet */
+                       u32 rx_copybreak;
+                       u32 frag_num;
+                       /* first buffer address for current packet */
+                       unsigned char *va;
+                       struct sk_buff *skb;
+                       struct sk_buff *tail_skb;
+               };
+       };
 } ____cacheline_internodealigned_in_smp;
 
 enum hns3_flow_level_range {
@@ -459,9 +522,9 @@ struct hns3_enet_coalesce {
        u16 int_gl;
        u16 int_ql;
        u16 int_ql_max;
-       u8 adapt_enable:1;
-       u8 ql_enable:1;
-       u8 unit_1us:1;
+       u8 adapt_enable : 1;
+       u8 ql_enable : 1;
+       u8 unit_1us : 1;
        enum hns3_flow_level_range flow_level;
 };
 
@@ -472,6 +535,7 @@ struct hns3_enet_ring_group {
        u64 total_packets;      /* total packets processed this group */
        u16 count;
        struct hns3_enet_coalesce coal;
+       struct dim dim;
 };
 
 struct hns3_enet_tqp_vector {
@@ -493,7 +557,7 @@ struct hns3_enet_tqp_vector {
 
        char name[HNAE3_INT_NAME_LEN];
 
-       unsigned long last_jiffies;
+       u64 event_cnt;
 } ____cacheline_internodealigned_in_smp;
 
 struct hns3_nic_priv {
@@ -514,8 +578,12 @@ struct hns3_nic_priv {
 
        unsigned long state;
 
+       enum dim_cq_period_mode tx_cqe_mode;
+       enum dim_cq_period_mode rx_cqe_mode;
        struct hns3_enet_coalesce tx_coal;
        struct hns3_enet_coalesce rx_coal;
+       u32 tx_copybreak;
+       u32 rx_copybreak;
 };
 
 union l3_hdr_info {
@@ -536,6 +604,11 @@ struct hns3_hw_error_info {
        const char *msg;
 };
 
+struct hns3_reset_type_map {
+       enum ethtool_reset_flags rst_flags;
+       enum hnae3_reset_type rst_type;
+};
+
 static inline int ring_space(struct hns3_enet_ring *ring)
 {
        /* This smp_load_acquire() pairs with smp_store_release() in
@@ -631,7 +704,6 @@ void hns3_set_vector_coalesce_rx_ql(struct hns3_enet_tqp_vector *tqp_vector,
 void hns3_set_vector_coalesce_tx_ql(struct hns3_enet_tqp_vector *tqp_vector,
                                    u32 ql_value);
 
-void hns3_enable_vlan_filter(struct net_device *netdev, bool enable);
 void hns3_request_update_promisc_mode(struct hnae3_handle *handle);
 
 #ifdef CONFIG_HNS3_DCB
@@ -640,9 +712,13 @@ void hns3_dcbnl_setup(struct hnae3_handle *handle);
 static inline void hns3_dcbnl_setup(struct hnae3_handle *handle) {}
 #endif
 
-void hns3_dbg_init(struct hnae3_handle *handle);
+int hns3_dbg_init(struct hnae3_handle *handle);
 void hns3_dbg_uninit(struct hnae3_handle *handle);
 void hns3_dbg_register_debugfs(const char *debugfs_dir_name);
 void hns3_dbg_unregister_debugfs(void);
 void hns3_shinfo_pack(struct skb_shared_info *shinfo, __u32 *size);
+u16 hns3_get_max_available_channels(struct hnae3_handle *h);
+void hns3_cq_period_mode_init(struct hns3_nic_priv *priv,
+                             enum dim_cq_period_mode tx_mode,
+                             enum dim_cq_period_mode rx_mode);
 #endif