1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020
12 #include "txgbe_logs.h"
13 #include "base/txgbe.h"
14 #include "txgbe_ethdev.h"
16 #define TXGBE_DEFAULT_FLEXBYTES_OFFSET 12 /*default flexbytes offset in bytes*/
17 #define TXGBE_MAX_FLX_SOURCE_OFF 62
19 #define IPV6_ADDR_TO_MASK(ipaddr, ipv6m) do { \
20 uint8_t ipv6_addr[16]; \
22 rte_memcpy(ipv6_addr, (ipaddr), sizeof(ipv6_addr));\
24 for (i = 0; i < sizeof(ipv6_addr); i++) { \
25 if (ipv6_addr[i] == UINT8_MAX) \
27 else if (ipv6_addr[i] != 0) { \
28 PMD_DRV_LOG(ERR, " invalid IPv6 address mask."); \
34 #define IPV6_MASK_TO_ADDR(ipv6m, ipaddr) do { \
35 uint8_t ipv6_addr[16]; \
37 for (i = 0; i < sizeof(ipv6_addr); i++) { \
38 if ((ipv6m) & (1 << i)) \
39 ipv6_addr[i] = UINT8_MAX; \
43 rte_memcpy((ipaddr), ipv6_addr, sizeof(ipv6_addr));\
47 * Initialize Flow Director control registers
48 * @hw: pointer to hardware structure
49 * @fdirctrl: value to write to flow director control register
52 txgbe_fdir_enable(struct txgbe_hw *hw, uint32_t fdirctrl)
56 PMD_INIT_FUNC_TRACE();
58 /* Prime the keys for hashing */
59 wr32(hw, TXGBE_FDIRBKTHKEY, TXGBE_ATR_BUCKET_HASH_KEY);
60 wr32(hw, TXGBE_FDIRSIGHKEY, TXGBE_ATR_SIGNATURE_HASH_KEY);
63 * Continue setup of fdirctrl register bits:
64 * Set the maximum length per hash bucket to 0xA filters
65 * Send interrupt when 64 filters are left
67 fdirctrl |= TXGBE_FDIRCTL_MAXLEN(0xA) |
68 TXGBE_FDIRCTL_FULLTHR(4);
71 * Poll init-done after we write the register. Estimated times:
72 * 10G: PBALLOC = 11b, timing is 60us
73 * 1G: PBALLOC = 11b, timing is 600us
74 * 100M: PBALLOC = 11b, timing is 6ms
76 * Multiple these timings by 4 if under full Rx load
78 * So we'll poll for TXGBE_FDIR_INIT_DONE_POLL times, sleeping for
79 * 1 msec per poll time. If we're at line rate and drop to 100M, then
80 * this might not finish in our poll time, but we can live with that
83 wr32(hw, TXGBE_FDIRCTL, fdirctrl);
85 for (i = 0; i < TXGBE_FDIR_INIT_DONE_POLL; i++) {
86 if (rd32(hw, TXGBE_FDIRCTL) & TXGBE_FDIRCTL_INITDONE)
91 if (i >= TXGBE_FDIR_INIT_DONE_POLL) {
92 PMD_INIT_LOG(ERR, "Flow Director poll time exceeded during enabling!");
99 * Set appropriate bits in fdirctrl for: variable reporting levels, moving
100 * flexbytes matching field, and drop queue (only for perfect matching mode).
103 configure_fdir_flags(const struct rte_fdir_conf *conf,
104 uint32_t *fdirctrl, uint32_t *flex)
109 switch (conf->pballoc) {
110 case RTE_FDIR_PBALLOC_64K:
111 /* 8k - 1 signature filters */
112 *fdirctrl |= TXGBE_FDIRCTL_BUF_64K;
114 case RTE_FDIR_PBALLOC_128K:
115 /* 16k - 1 signature filters */
116 *fdirctrl |= TXGBE_FDIRCTL_BUF_128K;
118 case RTE_FDIR_PBALLOC_256K:
119 /* 32k - 1 signature filters */
120 *fdirctrl |= TXGBE_FDIRCTL_BUF_256K;
124 PMD_INIT_LOG(ERR, "Invalid fdir_conf->pballoc value");
128 /* status flags: write hash & swindex in the rx descriptor */
129 switch (conf->status) {
130 case RTE_FDIR_NO_REPORT_STATUS:
131 /* do nothing, default mode */
133 case RTE_FDIR_REPORT_STATUS:
134 /* report status when the packet matches a fdir rule */
135 *fdirctrl |= TXGBE_FDIRCTL_REPORT_MATCH;
137 case RTE_FDIR_REPORT_STATUS_ALWAYS:
138 /* always report status */
139 *fdirctrl |= TXGBE_FDIRCTL_REPORT_ALWAYS;
143 PMD_INIT_LOG(ERR, "Invalid fdir_conf->status value");
147 *flex |= TXGBE_FDIRFLEXCFG_BASE_MAC;
148 *flex |= TXGBE_FDIRFLEXCFG_OFST(TXGBE_DEFAULT_FLEXBYTES_OFFSET / 2);
150 switch (conf->mode) {
151 case RTE_FDIR_MODE_SIGNATURE:
153 case RTE_FDIR_MODE_PERFECT:
154 *fdirctrl |= TXGBE_FDIRCTL_PERFECT;
155 *fdirctrl |= TXGBE_FDIRCTL_DROPQP(conf->drop_queue);
159 PMD_INIT_LOG(ERR, "Invalid fdir_conf->mode value");
166 static inline uint32_t
167 reverse_fdir_bmks(uint16_t hi_dword, uint16_t lo_dword)
169 uint32_t mask = hi_dword << 16;
172 mask = ((mask & 0x55555555) << 1) | ((mask & 0xAAAAAAAA) >> 1);
173 mask = ((mask & 0x33333333) << 2) | ((mask & 0xCCCCCCCC) >> 2);
174 mask = ((mask & 0x0F0F0F0F) << 4) | ((mask & 0xF0F0F0F0) >> 4);
175 return ((mask & 0x00FF00FF) << 8) | ((mask & 0xFF00FF00) >> 8);
179 txgbe_fdir_set_input_mask(struct rte_eth_dev *dev)
181 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
182 struct txgbe_hw_fdir_info *info = TXGBE_DEV_FDIR(dev);
183 enum rte_fdir_mode mode = dev->data->dev_conf.fdir_conf.mode;
185 * mask VM pool and DIPv6 since there are currently not supported
186 * mask FLEX byte, it will be set in flex_conf
188 uint32_t fdirm = TXGBE_FDIRMSK_POOL;
189 uint32_t fdirtcpm; /* TCP source and destination port masks. */
190 uint32_t fdiripv6m; /* IPv6 source and destination masks. */
192 PMD_INIT_FUNC_TRACE();
194 if (mode != RTE_FDIR_MODE_SIGNATURE &&
195 mode != RTE_FDIR_MODE_PERFECT) {
196 PMD_DRV_LOG(ERR, "Not supported fdir mode - %d!", mode);
201 * Program the relevant mask registers. If src/dst_port or src/dst_addr
202 * are zero, then assume a full mask for that field. Also assume that
203 * a VLAN of 0 is unspecified, so mask that out as well. L4type
204 * cannot be masked out in this implementation.
206 if (info->mask.dst_port_mask == 0 && info->mask.src_port_mask == 0) {
207 /* use the L4 protocol mask for raw IPv4/IPv6 traffic */
208 fdirm |= TXGBE_FDIRMSK_L4P;
211 /* TBD: don't support encapsulation yet */
212 wr32(hw, TXGBE_FDIRMSK, fdirm);
214 /* store the TCP/UDP port masks, bit reversed from port layout */
215 fdirtcpm = reverse_fdir_bmks(rte_be_to_cpu_16(info->mask.dst_port_mask),
216 rte_be_to_cpu_16(info->mask.src_port_mask));
218 /* write all the same so that UDP, TCP and SCTP use the same mask
221 wr32(hw, TXGBE_FDIRTCPMSK, ~fdirtcpm);
222 wr32(hw, TXGBE_FDIRUDPMSK, ~fdirtcpm);
223 wr32(hw, TXGBE_FDIRSCTPMSK, ~fdirtcpm);
225 /* Store source and destination IPv4 masks (big-endian) */
226 wr32(hw, TXGBE_FDIRSIP4MSK, ~info->mask.src_ipv4_mask);
227 wr32(hw, TXGBE_FDIRDIP4MSK, ~info->mask.dst_ipv4_mask);
229 if (mode == RTE_FDIR_MODE_SIGNATURE) {
231 * Store source and destination IPv6 masks (bit reversed)
233 fdiripv6m = TXGBE_FDIRIP6MSK_DST(info->mask.dst_ipv6_mask) |
234 TXGBE_FDIRIP6MSK_SRC(info->mask.src_ipv6_mask);
236 wr32(hw, TXGBE_FDIRIP6MSK, ~fdiripv6m);
243 txgbe_fdir_store_input_mask(struct rte_eth_dev *dev)
245 struct rte_eth_fdir_masks *input_mask =
246 &dev->data->dev_conf.fdir_conf.mask;
247 enum rte_fdir_mode mode = dev->data->dev_conf.fdir_conf.mode;
248 struct txgbe_hw_fdir_info *info = TXGBE_DEV_FDIR(dev);
249 uint16_t dst_ipv6m = 0;
250 uint16_t src_ipv6m = 0;
252 if (mode != RTE_FDIR_MODE_SIGNATURE &&
253 mode != RTE_FDIR_MODE_PERFECT) {
254 PMD_DRV_LOG(ERR, "Not supported fdir mode - %d!", mode);
258 memset(&info->mask, 0, sizeof(struct txgbe_hw_fdir_mask));
259 info->mask.vlan_tci_mask = input_mask->vlan_tci_mask;
260 info->mask.src_port_mask = input_mask->src_port_mask;
261 info->mask.dst_port_mask = input_mask->dst_port_mask;
262 info->mask.src_ipv4_mask = input_mask->ipv4_mask.src_ip;
263 info->mask.dst_ipv4_mask = input_mask->ipv4_mask.dst_ip;
264 IPV6_ADDR_TO_MASK(input_mask->ipv6_mask.src_ip, src_ipv6m);
265 IPV6_ADDR_TO_MASK(input_mask->ipv6_mask.dst_ip, dst_ipv6m);
266 info->mask.src_ipv6_mask = src_ipv6m;
267 info->mask.dst_ipv6_mask = dst_ipv6m;
273 txgbe_fdir_set_flexbytes_offset(struct rte_eth_dev *dev,
276 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
279 for (i = 0; i < 64; i++) {
280 uint32_t flexreg, flex;
281 flexreg = rd32(hw, TXGBE_FDIRFLEXCFG(i / 4));
282 flex = TXGBE_FDIRFLEXCFG_BASE_MAC;
283 flex |= TXGBE_FDIRFLEXCFG_OFST(offset / 2);
284 flexreg &= ~(TXGBE_FDIRFLEXCFG_ALL(~0UL, i % 4));
285 flexreg |= TXGBE_FDIRFLEXCFG_ALL(flex, i % 4);
286 wr32(hw, TXGBE_FDIRFLEXCFG(i / 4), flexreg);
290 for (i = 0; i < TXGBE_FDIR_INIT_DONE_POLL; i++) {
291 if (rd32(hw, TXGBE_FDIRCTL) &
292 TXGBE_FDIRCTL_INITDONE)
300 * txgbe_check_fdir_flex_conf -check if the flex payload and mask configuration
301 * arguments are valid
304 txgbe_set_fdir_flex_conf(struct rte_eth_dev *dev, uint32_t flex)
306 const struct rte_eth_fdir_flex_conf *conf =
307 &dev->data->dev_conf.fdir_conf.flex_conf;
308 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
309 struct txgbe_hw_fdir_info *info = TXGBE_DEV_FDIR(dev);
310 const struct rte_eth_flex_payload_cfg *flex_cfg;
311 const struct rte_eth_fdir_flex_mask *flex_mask;
312 uint16_t flexbytes = 0;
316 PMD_DRV_LOG(ERR, "NULL pointer.");
320 flex |= TXGBE_FDIRFLEXCFG_DIA;
322 for (i = 0; i < conf->nb_payloads; i++) {
323 flex_cfg = &conf->flex_set[i];
324 if (flex_cfg->type != RTE_ETH_RAW_PAYLOAD) {
325 PMD_DRV_LOG(ERR, "unsupported payload type.");
328 if (((flex_cfg->src_offset[0] & 0x1) == 0) &&
329 (flex_cfg->src_offset[1] == flex_cfg->src_offset[0] + 1) &&
330 flex_cfg->src_offset[0] <= TXGBE_MAX_FLX_SOURCE_OFF) {
331 flex &= ~TXGBE_FDIRFLEXCFG_OFST_MASK;
333 TXGBE_FDIRFLEXCFG_OFST(flex_cfg->src_offset[0] / 2);
335 PMD_DRV_LOG(ERR, "invalid flexbytes arguments.");
340 for (i = 0; i < conf->nb_flexmasks; i++) {
341 flex_mask = &conf->flex_mask[i];
342 if (flex_mask->flow_type != RTE_ETH_FLOW_UNKNOWN) {
343 PMD_DRV_LOG(ERR, "flexmask should be set globally.");
346 flexbytes = (uint16_t)(((flex_mask->mask[1] << 8) & 0xFF00) |
347 ((flex_mask->mask[0]) & 0xFF));
348 if (flexbytes == UINT16_MAX) {
349 flex &= ~TXGBE_FDIRFLEXCFG_DIA;
350 } else if (flexbytes != 0) {
351 /* TXGBE_FDIRFLEXCFG_DIA is set by default when set mask */
352 PMD_DRV_LOG(ERR, " invalid flexbytes mask arguments.");
357 info->mask.flex_bytes_mask = flexbytes ? UINT16_MAX : 0;
358 info->flex_bytes_offset = (uint8_t)(TXGBD_FDIRFLEXCFG_OFST(flex) * 2);
360 for (i = 0; i < 64; i++) {
362 flexreg = rd32(hw, TXGBE_FDIRFLEXCFG(i / 4));
363 flexreg &= ~(TXGBE_FDIRFLEXCFG_ALL(~0UL, i % 4));
364 flexreg |= TXGBE_FDIRFLEXCFG_ALL(flex, i % 4);
365 wr32(hw, TXGBE_FDIRFLEXCFG(i / 4), flexreg);
371 txgbe_fdir_configure(struct rte_eth_dev *dev)
373 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
375 uint32_t fdirctrl, flex, pbsize;
377 enum rte_fdir_mode mode = dev->data->dev_conf.fdir_conf.mode;
379 PMD_INIT_FUNC_TRACE();
381 /* supports mac-vlan and tunnel mode */
382 if (mode != RTE_FDIR_MODE_SIGNATURE &&
383 mode != RTE_FDIR_MODE_PERFECT)
386 err = configure_fdir_flags(&dev->data->dev_conf.fdir_conf,
392 * Before enabling Flow Director, the Rx Packet Buffer size
393 * must be reduced. The new value is the current size minus
394 * flow director memory usage size.
396 pbsize = rd32(hw, TXGBE_PBRXSIZE(0));
397 pbsize -= TXGBD_FDIRCTL_BUF_BYTE(fdirctrl);
398 wr32(hw, TXGBE_PBRXSIZE(0), pbsize);
401 * The defaults in the HW for RX PB 1-7 are not zero and so should be
402 * initialized to zero for non DCB mode otherwise actual total RX PB
403 * would be bigger than programmed and filter space would run into
406 for (i = 1; i < 8; i++)
407 wr32(hw, TXGBE_PBRXSIZE(i), 0);
409 err = txgbe_fdir_store_input_mask(dev);
411 PMD_INIT_LOG(ERR, " Error on setting FD mask");
415 err = txgbe_fdir_set_input_mask(dev);
417 PMD_INIT_LOG(ERR, " Error on setting FD mask");
421 err = txgbe_set_fdir_flex_conf(dev, flex);
423 PMD_INIT_LOG(ERR, " Error on setting FD flexible arguments.");
427 err = txgbe_fdir_enable(hw, fdirctrl);
429 PMD_INIT_LOG(ERR, " Error on enabling FD.");