1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Huawei Technologies Co., Ltd
5 #ifndef _HINIC_PMD_ETHDEV_H_
6 #define _HINIC_PMD_ETHDEV_H_
8 #include <rte_ethdev.h>
9 #include <rte_ethdev_core.h>
11 #include "base/hinic_compat.h"
12 #include "base/hinic_pmd_cfg.h"
14 #define HINIC_DEV_NAME_LEN 32
15 #define HINIC_MAX_RX_QUEUES 64
17 /* mbuf pool for copy invalid mbuf segs */
18 #define HINIC_COPY_MEMPOOL_DEPTH 128
19 #define HINIC_COPY_MBUF_SIZE 4096
21 #define SIZE_8BYTES(size) (ALIGN((u32)(size), 8) >> 3)
23 #define HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev) \
24 ((struct hinic_nic_dev *)(dev)->data->dev_private)
26 #define HINIC_MAX_QUEUE_DEPTH 4096
27 #define HINIC_MIN_QUEUE_DEPTH 128
28 #define HINIC_TXD_ALIGN 1
29 #define HINIC_RXD_ALIGN 1
31 #define HINIC_UINT32_BIT_SIZE (CHAR_BIT * sizeof(uint32_t))
32 #define HINIC_VFTA_SIZE (4096 / HINIC_UINT32_BIT_SIZE)
34 enum hinic_dev_status {
41 #define HINIC_MAX_Q_FILTERS 64 /* hinic just support 64 filter types */
42 #define HINIC_PKT_TYPE_FIND_ID(pkt_type) ((pkt_type) - HINIC_MAX_Q_FILTERS)
44 /* 5tuple filter info */
45 struct hinic_5tuple_filter_info {
50 uint8_t proto; /* l4 protocol. */
52 * seven levels (001b-111b), 111b is highest,
53 * used when more than one filter matches.
56 uint8_t dst_ip_mask:1, /* if mask is 1b, do not compare dst ip. */
57 src_ip_mask:1, /* if mask is 1b, do not compare src ip. */
58 dst_port_mask:1, /* if mask is 1b, do not compare dst port. */
59 src_port_mask:1, /* if mask is 1b, do not compare src port. */
60 proto_mask:1; /* if mask is 1b, do not compare protocol. */
63 /* 5tuple filter structure */
64 struct hinic_5tuple_filter {
65 TAILQ_ENTRY(hinic_5tuple_filter) entries;
66 uint16_t index; /* the index of 5tuple filter */
67 struct hinic_5tuple_filter_info filter_info;
68 uint16_t queue; /* rx queue assigned to */
71 TAILQ_HEAD(hinic_5tuple_filter_list, hinic_5tuple_filter);
74 * If this filter is added by configuration,
75 * it should not be removed.
77 struct hinic_pkt_filter {
83 /* Structure to store filters' info. */
84 struct hinic_filter_info {
87 uint64_t type_mask; /* Bit mask for every used filter */
88 struct hinic_5tuple_filter_list fivetuple_list;
89 struct hinic_pkt_filter pkt_filters[HINIC_MAX_Q_FILTERS];
92 /* Information about the fdir mode. */
93 struct hinic_hw_fdir_mask {
94 uint32_t src_ipv4_mask;
95 uint32_t dst_ipv4_mask;
96 uint16_t src_port_mask;
97 uint16_t dst_port_mask;
100 uint16_t tunnel_inner_src_port_mask;
101 uint16_t tunnel_inner_dst_port_mask;
104 /* Flow Director attribute */
105 struct hinic_atr_input {
111 uint16_t tunnel_flag;
112 uint16_t tunnel_inner_src_port;
113 uint16_t tunnel_inner_dst_port;
116 enum hinic_fdir_mode {
117 HINIC_FDIR_MODE_NORMAL = 0,
118 HINIC_FDIR_MODE_TCAM = 1,
121 #define HINIC_PF_MAX_TCAM_FILTERS 1024
122 #define HINIC_VF_MAX_TCAM_FILTERS 128
123 #define HINIC_SUPPORT_PF_MAX_NUM 4
124 #define HINIC_TOTAL_PF_MAX_NUM 16
125 #define HINIC_SUPPORT_VF_MAX_NUM 32
126 #define HINIC_TCAM_BLOCK_TYPE_PF 0 /* 1024 tcam index of a block */
127 #define HINIC_TCAM_BLOCK_TYPE_VF 1 /* 128 tcam index of a block */
129 #define HINIC_PKT_VF_TCAM_INDEX_START(block_index) \
130 (HINIC_PF_MAX_TCAM_FILTERS * HINIC_SUPPORT_PF_MAX_NUM + \
131 HINIC_VF_MAX_TCAM_FILTERS * (block_index))
133 TAILQ_HEAD(hinic_tcam_filter_list, hinic_tcam_filter);
135 struct hinic_tcam_info {
136 struct hinic_tcam_filter_list tcam_list;
137 u8 tcam_index_array[HINIC_PF_MAX_TCAM_FILTERS];
138 u16 tcam_block_index;
142 struct tag_tcam_key_mem {
143 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN)
150 * tunnel packet, mask must be 0xff, spec value is 1;
151 * normal packet, mask must be 0, spec value is 0;
152 * if tunnal packet, ucode use
153 * sip/dip/protocol/src_port/dst_dport from inner packet
166 * tunnel packet and normal packet,
167 * ext_dip mask must be 0xffffffff
194 struct tag_tcam_key {
195 struct tag_tcam_key_mem key_info;
196 struct tag_tcam_key_mem key_mask;
199 struct hinic_fdir_rule {
200 struct hinic_hw_fdir_mask mask;
201 struct hinic_atr_input hinic_fdir; /* key of fdir filter */
202 uint8_t queue; /* queue assigned when matched */
203 enum hinic_fdir_mode mode; /* fdir type */
207 /* ntuple filter list structure */
208 struct hinic_ntuple_filter_ele {
209 TAILQ_ENTRY(hinic_ntuple_filter_ele) entries;
210 struct rte_eth_ntuple_filter filter_info;
213 /* ethertype filter list structure */
214 struct hinic_ethertype_filter_ele {
215 TAILQ_ENTRY(hinic_ethertype_filter_ele) entries;
216 struct rte_eth_ethertype_filter filter_info;
219 /* fdir filter list structure */
220 struct hinic_fdir_rule_ele {
221 TAILQ_ENTRY(hinic_fdir_rule_ele) entries;
222 struct hinic_fdir_rule filter_info;
225 struct hinic_tcam_filter {
226 TAILQ_ENTRY(hinic_tcam_filter) entries;
227 uint16_t index; /* tcam index */
228 struct tag_tcam_key tcam_key;
229 uint16_t queue; /* rx queue assigned to */
233 enum rte_filter_type filter_type;
237 /* hinic_flow memory list structure */
238 struct hinic_flow_mem {
239 TAILQ_ENTRY(hinic_flow_mem) entries;
240 struct rte_flow *flow;
243 TAILQ_HEAD(hinic_ntuple_filter_list, hinic_ntuple_filter_ele);
244 TAILQ_HEAD(hinic_ethertype_filter_list, hinic_ethertype_filter_ele);
245 TAILQ_HEAD(hinic_fdir_rule_filter_list, hinic_fdir_rule_ele);
246 TAILQ_HEAD(hinic_flow_mem_list, hinic_flow_mem);
248 extern const struct rte_flow_ops hinic_flow_ops;
250 /* hinic nic_device */
251 struct hinic_nic_dev {
252 /* hardware device */
253 struct hinic_hwdev *hwdev;
254 struct hinic_txq **txqs;
255 struct hinic_rxq **rxqs;
256 struct rte_mempool *cpy_mpool;
264 u8 rx_queue_list[HINIC_MAX_RX_QUEUES];
267 struct nic_pause_config nic_pause;
269 u32 vfta[HINIC_VFTA_SIZE]; /* VLAN bitmap */
271 struct rte_ether_addr default_addr;
272 struct rte_ether_addr *mc_list;
275 struct nic_service_cap nic_cap;
276 u32 rx_mode_status; /* promisc or allmulticast */
277 unsigned long dev_status;
279 char proc_dev_name[HINIC_DEV_NAME_LEN];
280 /* PF0->COS4, PF1->COS5, PF2->COS6, PF3->COS7,
281 * vf: the same with associate pf
286 struct hinic_filter_info filter;
287 struct hinic_tcam_info tcam;
288 struct hinic_ntuple_filter_list filter_ntuple_list;
289 struct hinic_ethertype_filter_list filter_ethertype_list;
290 struct hinic_fdir_rule_filter_list filter_fdir_rule_list;
291 struct hinic_flow_mem_list hinic_flow_list;
294 void hinic_free_fdir_filter(struct hinic_nic_dev *nic_dev);
296 void hinic_destroy_fdir_filter(struct rte_eth_dev *dev);
297 #endif /* _HINIC_PMD_ETHDEV_H_ */