0001
0002
0003
0004 #ifndef __HNS3_ENET_H
0005 #define __HNS3_ENET_H
0006
0007 #include <linux/dim.h>
0008 #include <linux/if_vlan.h>
0009 #include <net/page_pool.h>
0010 #include <asm/barrier.h>
0011
0012 #include "hnae3.h"
0013
0014 struct iphdr;
0015 struct ipv6hdr;
0016
0017 enum hns3_nic_state {
0018 HNS3_NIC_STATE_TESTING,
0019 HNS3_NIC_STATE_RESETTING,
0020 HNS3_NIC_STATE_INITED,
0021 HNS3_NIC_STATE_DOWN,
0022 HNS3_NIC_STATE_DISABLED,
0023 HNS3_NIC_STATE_REMOVING,
0024 HNS3_NIC_STATE_SERVICE_INITED,
0025 HNS3_NIC_STATE_SERVICE_SCHED,
0026 HNS3_NIC_STATE2_RESET_REQUESTED,
0027 HNS3_NIC_STATE_HW_TX_CSUM_ENABLE,
0028 HNS3_NIC_STATE_RXD_ADV_LAYOUT_ENABLE,
0029 HNS3_NIC_STATE_TX_PUSH_ENABLE,
0030 HNS3_NIC_STATE_MAX
0031 };
0032
0033 #define HNS3_MAX_PUSH_BD_NUM 2
0034
0035 #define HNS3_RING_RX_RING_BASEADDR_L_REG 0x00000
0036 #define HNS3_RING_RX_RING_BASEADDR_H_REG 0x00004
0037 #define HNS3_RING_RX_RING_BD_NUM_REG 0x00008
0038 #define HNS3_RING_RX_RING_BD_LEN_REG 0x0000C
0039 #define HNS3_RING_RX_RING_TAIL_REG 0x00018
0040 #define HNS3_RING_RX_RING_HEAD_REG 0x0001C
0041 #define HNS3_RING_RX_RING_FBDNUM_REG 0x00020
0042 #define HNS3_RING_RX_RING_PKTNUM_RECORD_REG 0x0002C
0043
0044 #define HNS3_RING_TX_RING_BASEADDR_L_REG 0x00040
0045 #define HNS3_RING_TX_RING_BASEADDR_H_REG 0x00044
0046 #define HNS3_RING_TX_RING_BD_NUM_REG 0x00048
0047 #define HNS3_RING_TX_RING_TC_REG 0x00050
0048 #define HNS3_RING_TX_RING_TAIL_REG 0x00058
0049 #define HNS3_RING_TX_RING_HEAD_REG 0x0005C
0050 #define HNS3_RING_TX_RING_FBDNUM_REG 0x00060
0051 #define HNS3_RING_TX_RING_OFFSET_REG 0x00064
0052 #define HNS3_RING_TX_RING_EBDNUM_REG 0x00068
0053 #define HNS3_RING_TX_RING_PKTNUM_RECORD_REG 0x0006C
0054 #define HNS3_RING_TX_RING_EBD_OFFSET_REG 0x00070
0055 #define HNS3_RING_TX_RING_BD_ERR_REG 0x00074
0056 #define HNS3_RING_EN_REG 0x00090
0057 #define HNS3_RING_RX_EN_REG 0x00098
0058 #define HNS3_RING_TX_EN_REG 0x000D4
0059
0060 #define HNS3_RX_HEAD_SIZE 256
0061
0062 #define HNS3_TX_TIMEOUT (5 * HZ)
0063 #define HNS3_RING_NAME_LEN 16
0064 #define HNS3_BUFFER_SIZE_2048 2048
0065 #define HNS3_RING_MAX_PENDING 32760
0066 #define HNS3_RING_MIN_PENDING 72
0067 #define HNS3_RING_BD_MULTIPLE 8
0068
0069 #define HNS3_MAX_MTU(max_frm_size) \
0070 ((max_frm_size) - (ETH_HLEN + ETH_FCS_LEN + 2 * VLAN_HLEN))
0071
0072 #define HNS3_BD_SIZE_512_TYPE 0
0073 #define HNS3_BD_SIZE_1024_TYPE 1
0074 #define HNS3_BD_SIZE_2048_TYPE 2
0075 #define HNS3_BD_SIZE_4096_TYPE 3
0076
0077 #define HNS3_RX_FLAG_VLAN_PRESENT 0x1
0078 #define HNS3_RX_FLAG_L3ID_IPV4 0x0
0079 #define HNS3_RX_FLAG_L3ID_IPV6 0x1
0080 #define HNS3_RX_FLAG_L4ID_UDP 0x0
0081 #define HNS3_RX_FLAG_L4ID_TCP 0x1
0082
0083 #define HNS3_RXD_DMAC_S 0
0084 #define HNS3_RXD_DMAC_M (0x3 << HNS3_RXD_DMAC_S)
0085 #define HNS3_RXD_VLAN_S 2
0086 #define HNS3_RXD_VLAN_M (0x3 << HNS3_RXD_VLAN_S)
0087 #define HNS3_RXD_L3ID_S 4
0088 #define HNS3_RXD_L3ID_M (0xf << HNS3_RXD_L3ID_S)
0089 #define HNS3_RXD_L4ID_S 8
0090 #define HNS3_RXD_L4ID_M (0xf << HNS3_RXD_L4ID_S)
0091 #define HNS3_RXD_FRAG_B 12
0092 #define HNS3_RXD_STRP_TAGP_S 13
0093 #define HNS3_RXD_STRP_TAGP_M (0x3 << HNS3_RXD_STRP_TAGP_S)
0094
0095 #define HNS3_RXD_L2E_B 16
0096 #define HNS3_RXD_L3E_B 17
0097 #define HNS3_RXD_L4E_B 18
0098 #define HNS3_RXD_TRUNCAT_B 19
0099 #define HNS3_RXD_HOI_B 20
0100 #define HNS3_RXD_DOI_B 21
0101 #define HNS3_RXD_OL3E_B 22
0102 #define HNS3_RXD_OL4E_B 23
0103 #define HNS3_RXD_GRO_COUNT_S 24
0104 #define HNS3_RXD_GRO_COUNT_M (0x3f << HNS3_RXD_GRO_COUNT_S)
0105 #define HNS3_RXD_GRO_FIXID_B 30
0106 #define HNS3_RXD_GRO_ECN_B 31
0107
0108 #define HNS3_RXD_ODMAC_S 0
0109 #define HNS3_RXD_ODMAC_M (0x3 << HNS3_RXD_ODMAC_S)
0110 #define HNS3_RXD_OVLAN_S 2
0111 #define HNS3_RXD_OVLAN_M (0x3 << HNS3_RXD_OVLAN_S)
0112 #define HNS3_RXD_OL3ID_S 4
0113 #define HNS3_RXD_OL3ID_M (0xf << HNS3_RXD_OL3ID_S)
0114 #define HNS3_RXD_OL4ID_S 8
0115 #define HNS3_RXD_OL4ID_M (0xf << HNS3_RXD_OL4ID_S)
0116 #define HNS3_RXD_FBHI_S 12
0117 #define HNS3_RXD_FBHI_M (0x3 << HNS3_RXD_FBHI_S)
0118 #define HNS3_RXD_FBLI_S 14
0119 #define HNS3_RXD_FBLI_M (0x3 << HNS3_RXD_FBLI_S)
0120
0121 #define HNS3_RXD_PTYPE_S 4
0122 #define HNS3_RXD_PTYPE_M GENMASK(11, 4)
0123
0124 #define HNS3_RXD_BDTYPE_S 0
0125 #define HNS3_RXD_BDTYPE_M (0xf << HNS3_RXD_BDTYPE_S)
0126 #define HNS3_RXD_VLD_B 4
0127 #define HNS3_RXD_UDP0_B 5
0128 #define HNS3_RXD_EXTEND_B 7
0129 #define HNS3_RXD_FE_B 8
0130 #define HNS3_RXD_LUM_B 9
0131 #define HNS3_RXD_CRCP_B 10
0132 #define HNS3_RXD_L3L4P_B 11
0133 #define HNS3_RXD_TSIDX_S 12
0134 #define HNS3_RXD_TSIDX_M (0x3 << HNS3_RXD_TSIDX_S)
0135 #define HNS3_RXD_TS_VLD_B 14
0136 #define HNS3_RXD_LKBK_B 15
0137 #define HNS3_RXD_GRO_SIZE_S 16
0138 #define HNS3_RXD_GRO_SIZE_M (0x3fff << HNS3_RXD_GRO_SIZE_S)
0139
0140 #define HNS3_TXD_L3T_S 0
0141 #define HNS3_TXD_L3T_M (0x3 << HNS3_TXD_L3T_S)
0142 #define HNS3_TXD_L4T_S 2
0143 #define HNS3_TXD_L4T_M (0x3 << HNS3_TXD_L4T_S)
0144 #define HNS3_TXD_L3CS_B 4
0145 #define HNS3_TXD_L4CS_B 5
0146 #define HNS3_TXD_VLAN_B 6
0147 #define HNS3_TXD_TSO_B 7
0148
0149 #define HNS3_TXD_L2LEN_S 8
0150 #define HNS3_TXD_L2LEN_M (0xff << HNS3_TXD_L2LEN_S)
0151 #define HNS3_TXD_L3LEN_S 16
0152 #define HNS3_TXD_L3LEN_M (0xff << HNS3_TXD_L3LEN_S)
0153 #define HNS3_TXD_L4LEN_S 24
0154 #define HNS3_TXD_L4LEN_M (0xff << HNS3_TXD_L4LEN_S)
0155
0156 #define HNS3_TXD_CSUM_START_S 8
0157 #define HNS3_TXD_CSUM_START_M (0xffff << HNS3_TXD_CSUM_START_S)
0158
0159 #define HNS3_TXD_OL3T_S 0
0160 #define HNS3_TXD_OL3T_M (0x3 << HNS3_TXD_OL3T_S)
0161 #define HNS3_TXD_OVLAN_B 2
0162 #define HNS3_TXD_MACSEC_B 3
0163 #define HNS3_TXD_TUNTYPE_S 4
0164 #define HNS3_TXD_TUNTYPE_M (0xf << HNS3_TXD_TUNTYPE_S)
0165
0166 #define HNS3_TXD_CSUM_OFFSET_S 8
0167 #define HNS3_TXD_CSUM_OFFSET_M (0xffff << HNS3_TXD_CSUM_OFFSET_S)
0168
0169 #define HNS3_TXD_BDTYPE_S 0
0170 #define HNS3_TXD_BDTYPE_M (0xf << HNS3_TXD_BDTYPE_S)
0171 #define HNS3_TXD_FE_B 4
0172 #define HNS3_TXD_SC_S 5
0173 #define HNS3_TXD_SC_M (0x3 << HNS3_TXD_SC_S)
0174 #define HNS3_TXD_EXTEND_B 7
0175 #define HNS3_TXD_VLD_B 8
0176 #define HNS3_TXD_RI_B 9
0177 #define HNS3_TXD_RA_B 10
0178 #define HNS3_TXD_TSYN_B 11
0179 #define HNS3_TXD_DECTTL_S 12
0180 #define HNS3_TXD_DECTTL_M (0xf << HNS3_TXD_DECTTL_S)
0181
0182 #define HNS3_TXD_OL4CS_B 22
0183
0184 #define HNS3_TXD_MSS_S 0
0185 #define HNS3_TXD_MSS_M (0x3fff << HNS3_TXD_MSS_S)
0186 #define HNS3_TXD_HW_CS_B 14
0187
0188 #define HNS3_VECTOR_TX_IRQ BIT_ULL(0)
0189 #define HNS3_VECTOR_RX_IRQ BIT_ULL(1)
0190
0191 #define HNS3_VECTOR_NOT_INITED 0
0192 #define HNS3_VECTOR_INITED 1
0193
0194 #define HNS3_MAX_BD_SIZE 65535
0195 #define HNS3_MAX_TSO_BD_NUM 63U
0196 #define HNS3_MAX_TSO_SIZE 1048576U
0197 #define HNS3_MAX_NON_TSO_SIZE 9728U
0198
0199 #define HNS3_VECTOR_GL_MASK GENMASK(11, 0)
0200 #define HNS3_VECTOR_GL0_OFFSET 0x100
0201 #define HNS3_VECTOR_GL1_OFFSET 0x200
0202 #define HNS3_VECTOR_GL2_OFFSET 0x300
0203 #define HNS3_VECTOR_RL_OFFSET 0x900
0204 #define HNS3_VECTOR_RL_EN_B 6
0205 #define HNS3_VECTOR_QL_MASK GENMASK(9, 0)
0206 #define HNS3_VECTOR_TX_QL_OFFSET 0xe00
0207 #define HNS3_VECTOR_RX_QL_OFFSET 0xf00
0208
0209 #define HNS3_RING_EN_B 0
0210
0211 #define HNS3_GL0_CQ_MODE_REG 0x20d00
0212 #define HNS3_GL1_CQ_MODE_REG 0x20d04
0213 #define HNS3_GL2_CQ_MODE_REG 0x20d08
0214 #define HNS3_CQ_MODE_EQE 1U
0215 #define HNS3_CQ_MODE_CQE 0U
0216
0217 enum hns3_pkt_l2t_type {
0218 HNS3_L2_TYPE_UNICAST,
0219 HNS3_L2_TYPE_MULTICAST,
0220 HNS3_L2_TYPE_BROADCAST,
0221 HNS3_L2_TYPE_INVALID,
0222 };
0223
0224 enum hns3_pkt_l3t_type {
0225 HNS3_L3T_NONE,
0226 HNS3_L3T_IPV6,
0227 HNS3_L3T_IPV4,
0228 HNS3_L3T_RESERVED
0229 };
0230
0231 enum hns3_pkt_l4t_type {
0232 HNS3_L4T_UNKNOWN,
0233 HNS3_L4T_TCP,
0234 HNS3_L4T_UDP,
0235 HNS3_L4T_SCTP
0236 };
0237
0238 enum hns3_pkt_ol3t_type {
0239 HNS3_OL3T_NONE,
0240 HNS3_OL3T_IPV6,
0241 HNS3_OL3T_IPV4_NO_CSUM,
0242 HNS3_OL3T_IPV4_CSUM
0243 };
0244
0245 enum hns3_pkt_tun_type {
0246 HNS3_TUN_NONE,
0247 HNS3_TUN_MAC_IN_UDP,
0248 HNS3_TUN_NVGRE,
0249 HNS3_TUN_OTHER
0250 };
0251
0252
0253 struct __packed hns3_desc {
0254 union {
0255 __le64 addr;
0256 __le16 csum;
0257 struct {
0258 __le32 ts_nsec;
0259 __le32 ts_sec;
0260 };
0261 };
0262 union {
0263 struct {
0264 __le16 vlan_tag;
0265 __le16 send_size;
0266 union {
0267 __le32 type_cs_vlan_tso_len;
0268 struct {
0269 __u8 type_cs_vlan_tso;
0270 __u8 l2_len;
0271 __u8 l3_len;
0272 __u8 l4_len;
0273 };
0274 };
0275 __le16 outer_vlan_tag;
0276 __le16 tv;
0277
0278 union {
0279 __le32 ol_type_vlan_len_msec;
0280 struct {
0281 __u8 ol_type_vlan_msec;
0282 __u8 ol2_len;
0283 __u8 ol3_len;
0284 __u8 ol4_len;
0285 };
0286 };
0287
0288 __le32 paylen_ol4cs;
0289 __le16 bdtp_fe_sc_vld_ra_ri;
0290 __le16 mss_hw_csum;
0291 } tx;
0292
0293 struct {
0294 __le32 l234_info;
0295 __le16 pkt_len;
0296 __le16 size;
0297
0298 __le32 rss_hash;
0299 __le16 fd_id;
0300 __le16 vlan_tag;
0301
0302 union {
0303 __le32 ol_info;
0304 struct {
0305 __le16 o_dm_vlan_id_fb;
0306 __le16 ot_vlan_tag;
0307 };
0308 };
0309
0310 __le32 bd_base_info;
0311 } rx;
0312 };
0313 };
0314
0315 enum hns3_desc_type {
0316 DESC_TYPE_UNKNOWN = 0,
0317 DESC_TYPE_SKB = 1 << 0,
0318 DESC_TYPE_FRAGLIST_SKB = 1 << 1,
0319 DESC_TYPE_PAGE = 1 << 2,
0320 DESC_TYPE_BOUNCE_ALL = 1 << 3,
0321 DESC_TYPE_BOUNCE_HEAD = 1 << 4,
0322 DESC_TYPE_SGL_SKB = 1 << 5,
0323 DESC_TYPE_PP_FRAG = 1 << 6,
0324 };
0325
0326 struct hns3_desc_cb {
0327 dma_addr_t dma;
0328 void *buf;
0329
0330
0331 void *priv;
0332
0333 union {
0334 u32 page_offset;
0335 u32 send_bytes;
0336 };
0337
0338 u32 length;
0339
0340 u16 reuse_flag;
0341 u16 refill;
0342
0343
0344 u16 type;
0345 u16 pagecnt_bias;
0346 };
0347
0348 enum hns3_pkt_l3type {
0349 HNS3_L3_TYPE_IPV4,
0350 HNS3_L3_TYPE_IPV6,
0351 HNS3_L3_TYPE_ARP,
0352 HNS3_L3_TYPE_RARP,
0353 HNS3_L3_TYPE_IPV4_OPT,
0354 HNS3_L3_TYPE_IPV6_EXT,
0355 HNS3_L3_TYPE_LLDP,
0356 HNS3_L3_TYPE_BPDU,
0357 HNS3_L3_TYPE_MAC_PAUSE,
0358 HNS3_L3_TYPE_PFC_PAUSE,
0359
0360
0361
0362 HNS3_L3_TYPE_CNM = 0xc,
0363
0364
0365
0366 HNS3_L3_TYPE_PARSE_FAIL = 0xf
0367 };
0368
0369 enum hns3_pkt_l4type {
0370 HNS3_L4_TYPE_UDP,
0371 HNS3_L4_TYPE_TCP,
0372 HNS3_L4_TYPE_GRE,
0373 HNS3_L4_TYPE_SCTP,
0374 HNS3_L4_TYPE_IGMP,
0375 HNS3_L4_TYPE_ICMP,
0376
0377
0378
0379 HNS3_L4_TYPE_PARSE_FAIL = 0xf
0380 };
0381
0382 enum hns3_pkt_ol3type {
0383 HNS3_OL3_TYPE_IPV4 = 0,
0384 HNS3_OL3_TYPE_IPV6,
0385
0386 HNS3_OL3_TYPE_IPV4_OPT = 4,
0387 HNS3_OL3_TYPE_IPV6_EXT,
0388
0389
0390
0391 HNS3_OL3_TYPE_PARSE_FAIL = 0xf
0392 };
0393
0394 enum hns3_pkt_ol4type {
0395 HNS3_OL4_TYPE_NO_TUN,
0396 HNS3_OL4_TYPE_MAC_IN_UDP,
0397 HNS3_OL4_TYPE_NVGRE,
0398 HNS3_OL4_TYPE_UNKNOWN
0399 };
0400
0401 struct hns3_rx_ptype {
0402 u32 ptype : 8;
0403 u32 csum_level : 2;
0404 u32 ip_summed : 2;
0405 u32 l3_type : 4;
0406 u32 valid : 1;
0407 };
0408
0409 struct ring_stats {
0410 u64 sw_err_cnt;
0411 u64 seg_pkt_cnt;
0412 union {
0413 struct {
0414 u64 tx_pkts;
0415 u64 tx_bytes;
0416 u64 tx_more;
0417 u64 tx_push;
0418 u64 tx_mem_doorbell;
0419 u64 restart_queue;
0420 u64 tx_busy;
0421 u64 tx_copy;
0422 u64 tx_vlan_err;
0423 u64 tx_l4_proto_err;
0424 u64 tx_l2l3l4_err;
0425 u64 tx_tso_err;
0426 u64 over_max_recursion;
0427 u64 hw_limitation;
0428 u64 tx_bounce;
0429 u64 tx_spare_full;
0430 u64 copy_bits_err;
0431 u64 tx_sgl;
0432 u64 skb2sgl_err;
0433 u64 map_sg_err;
0434 };
0435 struct {
0436 u64 rx_pkts;
0437 u64 rx_bytes;
0438 u64 rx_err_cnt;
0439 u64 reuse_pg_cnt;
0440 u64 err_pkt_len;
0441 u64 err_bd_num;
0442 u64 l2_err;
0443 u64 l3l4_csum_err;
0444 u64 csum_complete;
0445 u64 rx_multicast;
0446 u64 non_reuse_pg;
0447 u64 frag_alloc_err;
0448 u64 frag_alloc;
0449 };
0450 __le16 csum;
0451 };
0452 };
0453
0454 struct hns3_tx_spare {
0455 dma_addr_t dma;
0456 void *buf;
0457 u32 next_to_use;
0458 u32 next_to_clean;
0459 u32 last_to_clean;
0460 u32 len;
0461 };
0462
0463 struct hns3_enet_ring {
0464 struct hns3_desc *desc;
0465 struct hns3_desc_cb *desc_cb;
0466 struct hns3_enet_ring *next;
0467 struct hns3_enet_tqp_vector *tqp_vector;
0468 struct hnae3_queue *tqp;
0469 int queue_index;
0470 struct device *dev;
0471 struct page_pool *page_pool;
0472
0473
0474 struct ring_stats stats;
0475 struct u64_stats_sync syncp;
0476
0477 dma_addr_t desc_dma_addr;
0478 u32 buf_size;
0479 u16 desc_num;
0480 int next_to_use;
0481
0482
0483
0484
0485 int next_to_clean;
0486 u32 flag;
0487
0488 int pending_buf;
0489 union {
0490
0491 struct {
0492 u32 fd_qb_tx_sample;
0493 int last_to_use;
0494 u32 tx_copybreak;
0495 struct hns3_tx_spare *tx_spare;
0496 };
0497
0498
0499 struct {
0500 u32 pull_len;
0501 u32 rx_copybreak;
0502 u32 frag_num;
0503
0504 unsigned char *va;
0505 struct sk_buff *skb;
0506 struct sk_buff *tail_skb;
0507 };
0508 };
0509 } ____cacheline_internodealigned_in_smp;
0510
0511 enum hns3_flow_level_range {
0512 HNS3_FLOW_LOW = 0,
0513 HNS3_FLOW_MID = 1,
0514 HNS3_FLOW_HIGH = 2,
0515 HNS3_FLOW_ULTRA = 3,
0516 };
0517
0518 #define HNS3_INT_GL_50K 0x0014
0519 #define HNS3_INT_GL_20K 0x0032
0520 #define HNS3_INT_GL_18K 0x0036
0521 #define HNS3_INT_GL_8K 0x007C
0522
0523 #define HNS3_INT_GL_1US BIT(31)
0524
0525 #define HNS3_INT_RL_MAX 0x00EC
0526 #define HNS3_INT_RL_ENABLE_MASK 0x40
0527
0528 #define HNS3_INT_QL_DEFAULT_CFG 0x20
0529
0530 struct hns3_enet_coalesce {
0531 u16 int_gl;
0532 u16 int_ql;
0533 u16 int_ql_max;
0534 u8 adapt_enable : 1;
0535 u8 ql_enable : 1;
0536 u8 unit_1us : 1;
0537 enum hns3_flow_level_range flow_level;
0538 };
0539
0540 struct hns3_enet_ring_group {
0541
0542 struct hns3_enet_ring *ring;
0543 u64 total_bytes;
0544 u64 total_packets;
0545 u16 count;
0546 struct hns3_enet_coalesce coal;
0547 struct dim dim;
0548 };
0549
0550 struct hns3_enet_tqp_vector {
0551 struct hnae3_handle *handle;
0552 u8 __iomem *mask_addr;
0553 int vector_irq;
0554 int irq_init_flag;
0555
0556 u16 idx;
0557
0558 struct napi_struct napi;
0559
0560 struct hns3_enet_ring_group rx_group;
0561 struct hns3_enet_ring_group tx_group;
0562
0563 cpumask_t affinity_mask;
0564 u16 num_tqps;
0565 struct irq_affinity_notify affinity_notify;
0566
0567 char name[HNAE3_INT_NAME_LEN];
0568
0569 u64 event_cnt;
0570 } ____cacheline_internodealigned_in_smp;
0571
0572 struct hns3_nic_priv {
0573 struct hnae3_handle *ae_handle;
0574 struct net_device *netdev;
0575 struct device *dev;
0576
0577
0578
0579
0580
0581 struct hns3_enet_ring *ring;
0582 struct hns3_enet_tqp_vector *tqp_vector;
0583 u16 vector_num;
0584 u8 max_non_tso_bd_num;
0585
0586 u64 tx_timeout_count;
0587
0588 unsigned long state;
0589
0590 enum dim_cq_period_mode tx_cqe_mode;
0591 enum dim_cq_period_mode rx_cqe_mode;
0592 struct hns3_enet_coalesce tx_coal;
0593 struct hns3_enet_coalesce rx_coal;
0594 u32 tx_copybreak;
0595 u32 rx_copybreak;
0596 };
0597
0598 union l3_hdr_info {
0599 struct iphdr *v4;
0600 struct ipv6hdr *v6;
0601 unsigned char *hdr;
0602 };
0603
0604 union l4_hdr_info {
0605 struct tcphdr *tcp;
0606 struct udphdr *udp;
0607 struct gre_base_hdr *gre;
0608 unsigned char *hdr;
0609 };
0610
0611 struct hns3_hw_error_info {
0612 enum hnae3_hw_error_type type;
0613 const char *msg;
0614 };
0615
0616 struct hns3_reset_type_map {
0617 enum ethtool_reset_flags rst_flags;
0618 enum hnae3_reset_type rst_type;
0619 };
0620
0621 static inline int ring_space(struct hns3_enet_ring *ring)
0622 {
0623
0624
0625
0626 int begin = smp_load_acquire(&ring->next_to_clean);
0627 int end = READ_ONCE(ring->next_to_use);
0628
0629 return ((end >= begin) ? (ring->desc_num - end + begin) :
0630 (begin - end)) - 1;
0631 }
0632
0633 static inline u32 hns3_tqp_read_reg(struct hns3_enet_ring *ring, u32 reg)
0634 {
0635 return readl_relaxed(ring->tqp->io_base + reg);
0636 }
0637
0638 static inline u32 hns3_read_reg(void __iomem *base, u32 reg)
0639 {
0640 return readl(base + reg);
0641 }
0642
0643 static inline void hns3_write_reg(void __iomem *base, u32 reg, u32 value)
0644 {
0645 u8 __iomem *reg_addr = READ_ONCE(base);
0646
0647 writel(value, reg_addr + reg);
0648 }
0649
0650 #define hns3_read_dev(a, reg) \
0651 hns3_read_reg((a)->io_base, reg)
0652
0653 static inline bool hns3_nic_resetting(struct net_device *netdev)
0654 {
0655 struct hns3_nic_priv *priv = netdev_priv(netdev);
0656
0657 return test_bit(HNS3_NIC_STATE_RESETTING, &priv->state);
0658 }
0659
0660 #define hns3_write_dev(a, reg, value) \
0661 hns3_write_reg((a)->io_base, reg, value)
0662
0663 #define ring_to_dev(ring) ((ring)->dev)
0664
0665 #define ring_to_netdev(ring) ((ring)->tqp_vector->napi.dev)
0666
0667 #define ring_to_dma_dir(ring) (HNAE3_IS_TX_RING(ring) ? \
0668 DMA_TO_DEVICE : DMA_FROM_DEVICE)
0669
0670 #define hns3_buf_size(_ring) ((_ring)->buf_size)
0671
0672 #define hns3_ring_stats_update(ring, cnt) do { \
0673 typeof(ring) (tmp) = (ring); \
0674 u64_stats_update_begin(&(tmp)->syncp); \
0675 ((tmp)->stats.cnt)++; \
0676 u64_stats_update_end(&(tmp)->syncp); \
0677 } while (0) \
0678
0679 static inline unsigned int hns3_page_order(struct hns3_enet_ring *ring)
0680 {
0681 #if (PAGE_SIZE < 8192)
0682 if (ring->buf_size > (PAGE_SIZE / 2))
0683 return 1;
0684 #endif
0685 return 0;
0686 }
0687
0688 #define hns3_page_size(_ring) (PAGE_SIZE << hns3_page_order(_ring))
0689
0690
0691 #define hns3_for_each_ring(pos, head) \
0692 for (pos = (head).ring; (pos); pos = (pos)->next)
0693
0694 #define hns3_get_handle(ndev) \
0695 (((struct hns3_nic_priv *)netdev_priv(ndev))->ae_handle)
0696
0697 #define hns3_gl_usec_to_reg(int_gl) ((int_gl) >> 1)
0698 #define hns3_gl_round_down(int_gl) round_down(int_gl, 2)
0699
0700 #define hns3_rl_usec_to_reg(int_rl) ((int_rl) >> 2)
0701 #define hns3_rl_round_down(int_rl) round_down(int_rl, 4)
0702
0703 void hns3_ethtool_set_ops(struct net_device *netdev);
0704 int hns3_set_channels(struct net_device *netdev,
0705 struct ethtool_channels *ch);
0706
0707 void hns3_clean_tx_ring(struct hns3_enet_ring *ring, int budget);
0708 int hns3_init_all_ring(struct hns3_nic_priv *priv);
0709 int hns3_nic_reset_all_ring(struct hnae3_handle *h);
0710 void hns3_fini_ring(struct hns3_enet_ring *ring);
0711 netdev_tx_t hns3_nic_net_xmit(struct sk_buff *skb, struct net_device *netdev);
0712 bool hns3_is_phys_func(struct pci_dev *pdev);
0713 int hns3_clean_rx_ring(
0714 struct hns3_enet_ring *ring, int budget,
0715 void (*rx_fn)(struct hns3_enet_ring *, struct sk_buff *));
0716
0717 void hns3_set_vector_coalesce_rx_gl(struct hns3_enet_tqp_vector *tqp_vector,
0718 u32 gl_value);
0719 void hns3_set_vector_coalesce_tx_gl(struct hns3_enet_tqp_vector *tqp_vector,
0720 u32 gl_value);
0721 void hns3_set_vector_coalesce_rl(struct hns3_enet_tqp_vector *tqp_vector,
0722 u32 rl_value);
0723 void hns3_set_vector_coalesce_rx_ql(struct hns3_enet_tqp_vector *tqp_vector,
0724 u32 ql_value);
0725 void hns3_set_vector_coalesce_tx_ql(struct hns3_enet_tqp_vector *tqp_vector,
0726 u32 ql_value);
0727
0728 void hns3_request_update_promisc_mode(struct hnae3_handle *handle);
0729 int hns3_reset_notify(struct hnae3_handle *handle,
0730 enum hnae3_reset_notify_type type);
0731
0732 #ifdef CONFIG_HNS3_DCB
0733 void hns3_dcbnl_setup(struct hnae3_handle *handle);
0734 #else
0735 static inline void hns3_dcbnl_setup(struct hnae3_handle *handle) {}
0736 #endif
0737
0738 int hns3_dbg_init(struct hnae3_handle *handle);
0739 void hns3_dbg_uninit(struct hnae3_handle *handle);
0740 void hns3_dbg_register_debugfs(const char *debugfs_dir_name);
0741 void hns3_dbg_unregister_debugfs(void);
0742 void hns3_shinfo_pack(struct skb_shared_info *shinfo, __u32 *size);
0743 u16 hns3_get_max_available_channels(struct hnae3_handle *h);
0744 void hns3_cq_period_mode_init(struct hns3_nic_priv *priv,
0745 enum dim_cq_period_mode tx_mode,
0746 enum dim_cq_period_mode rx_mode);
0747 #endif