Commit b501d261 authored by Jiawen Wu's avatar Jiawen Wu Committed by Paolo Abeni
Browse files

net: txgbe: add FDIR ATR support



Add flow director ATR filter. ATR mode is enabled by default to filter
TCP packets.

Signed-off-by: default avatarJiawen Wu <jiawenwu@trustnetic.com>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 7e8fcb81
Loading
Loading
Loading
Loading
+23 −4
Original line number Diff line number Diff line
@@ -1147,8 +1147,15 @@ static void wx_enable_rx(struct wx *wx)
static void wx_set_rxpba(struct wx *wx)
{
	u32 rxpktsize, txpktsize, txpbthresh;
	u32 pbsize = wx->mac.rx_pb_size;

	rxpktsize = wx->mac.rx_pb_size << WX_RDB_PB_SZ_SHIFT;
	if (test_bit(WX_FLAG_FDIR_CAPABLE, wx->flags)) {
		if (test_bit(WX_FLAG_FDIR_HASH, wx->flags) ||
		    test_bit(WX_FLAG_FDIR_PERFECT, wx->flags))
			pbsize -= 64; /* Default 64KB */
	}

	rxpktsize = pbsize << WX_RDB_PB_SZ_SHIFT;
	wr32(wx, WX_RDB_PB_SZ(0), rxpktsize);

	/* Only support an equally distributed Tx packet buffer strategy. */
@@ -1261,7 +1268,7 @@ static void wx_configure_port(struct wx *wx)
 *  Stops the receive data path and waits for the HW to internally empty
 *  the Rx security block
 **/
static int wx_disable_sec_rx_path(struct wx *wx)
int wx_disable_sec_rx_path(struct wx *wx)
{
	u32 secrx;

@@ -1271,6 +1278,7 @@ static int wx_disable_sec_rx_path(struct wx *wx)
	return read_poll_timeout(rd32, secrx, secrx & WX_RSC_ST_RSEC_RDY,
				 1000, 40000, false, wx, WX_RSC_ST);
}
EXPORT_SYMBOL(wx_disable_sec_rx_path);

/**
 *  wx_enable_sec_rx_path - Enables the receive data path
@@ -1278,11 +1286,12 @@ static int wx_disable_sec_rx_path(struct wx *wx)
 *
 *  Enables the receive data path.
 **/
static void wx_enable_sec_rx_path(struct wx *wx)
void wx_enable_sec_rx_path(struct wx *wx)
{
	wr32m(wx, WX_RSC_CTL, WX_RSC_CTL_RX_DIS, 0);
	WX_WRITE_FLUSH(wx);
}
EXPORT_SYMBOL(wx_enable_sec_rx_path);

static void wx_vlan_strip_control(struct wx *wx, bool enable)
{
@@ -1499,6 +1508,13 @@ static void wx_configure_tx_ring(struct wx *wx,
		txdctl |= ring->count / 128 << WX_PX_TR_CFG_TR_SIZE_SHIFT;
	txdctl |= 0x20 << WX_PX_TR_CFG_WTHRESH_SHIFT;

	ring->atr_count = 0;
	if (test_bit(WX_FLAG_FDIR_CAPABLE, wx->flags) &&
	    test_bit(WX_FLAG_FDIR_HASH, wx->flags))
		ring->atr_sample_rate = wx->atr_sample_rate;
	else
		ring->atr_sample_rate = 0;

	/* reinitialize tx_buffer_info */
	memset(ring->tx_buffer_info, 0,
	       sizeof(struct wx_tx_buffer) * ring->count);
@@ -1732,7 +1748,9 @@ void wx_configure(struct wx *wx)

	wx_set_rx_mode(wx->netdev);
	wx_restore_vlan(wx);
	wx_enable_sec_rx_path(wx);

	if (test_bit(WX_FLAG_FDIR_CAPABLE, wx->flags))
		wx->configure_fdir(wx);

	wx_configure_tx(wx);
	wx_configure_rx(wx);
@@ -1959,6 +1977,7 @@ int wx_sw_init(struct wx *wx)
	}

	bitmap_zero(wx->state, WX_STATE_NBITS);
	bitmap_zero(wx->flags, WX_PF_FLAGS_NBITS);

	return 0;
}
+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ void wx_mac_set_default_filter(struct wx *wx, u8 *addr);
void wx_flush_sw_mac_table(struct wx *wx);
int wx_set_mac(struct net_device *netdev, void *p);
void wx_disable_rx(struct wx *wx);
int wx_disable_sec_rx_path(struct wx *wx);
void wx_enable_sec_rx_path(struct wx *wx);
void wx_set_rx_mode(struct net_device *netdev);
int wx_change_mtu(struct net_device *netdev, int new_mtu);
void wx_disable_rx_queue(struct wx *wx, struct wx_ring *ring);
+28 −3
Original line number Diff line number Diff line
@@ -148,10 +148,11 @@ static struct wx_dec_ptype wx_ptype_lookup[256] = {
	[0xFD] = WX_PTT(IP, IPV6, IGMV, IPV6, SCTP, PAY4),
};

static struct wx_dec_ptype wx_decode_ptype(const u8 ptype)
struct wx_dec_ptype wx_decode_ptype(const u8 ptype)
{
	return wx_ptype_lookup[ptype];
}
EXPORT_SYMBOL(wx_decode_ptype);

/* wx_test_staterr - tests bits in Rx descriptor status and error fields */
static __le32 wx_test_staterr(union wx_rx_desc *rx_desc,
@@ -1453,6 +1454,7 @@ static void wx_tx_csum(struct wx_ring *tx_ring, struct wx_tx_buffer *first,
static netdev_tx_t wx_xmit_frame_ring(struct sk_buff *skb,
				      struct wx_ring *tx_ring)
{
	struct wx *wx = netdev_priv(tx_ring->netdev);
	u16 count = TXD_USE_COUNT(skb_headlen(skb));
	struct wx_tx_buffer *first;
	u8 hdr_len = 0, ptype;
@@ -1498,6 +1500,10 @@ static netdev_tx_t wx_xmit_frame_ring(struct sk_buff *skb,
		goto out_drop;
	else if (!tso)
		wx_tx_csum(tx_ring, first, ptype);

	if (test_bit(WX_FLAG_FDIR_CAPABLE, wx->flags) && tx_ring->atr_sample_rate)
		wx->atr(tx_ring, first, ptype);

	wx_tx_map(tx_ring, first, hdr_len);

	return NETDEV_TX_OK;
@@ -1574,8 +1580,27 @@ static void wx_set_rss_queues(struct wx *wx)
	f = &wx->ring_feature[RING_F_RSS];
	f->indices = f->limit;

	wx->num_rx_queues = f->limit;
	wx->num_tx_queues = f->limit;
	if (!(test_bit(WX_FLAG_FDIR_CAPABLE, wx->flags)))
		goto out;

	clear_bit(WX_FLAG_FDIR_HASH, wx->flags);

	/* Use Flow Director in addition to RSS to ensure the best
	 * distribution of flows across cores, even when an FDIR flow
	 * isn't matched.
	 */
	if (f->indices > 1) {
		f = &wx->ring_feature[RING_F_FDIR];

		f->indices = f->limit;

		if (!(test_bit(WX_FLAG_FDIR_PERFECT, wx->flags)))
			set_bit(WX_FLAG_FDIR_HASH, wx->flags);
	}

out:
	wx->num_rx_queues = f->indices;
	wx->num_tx_queues = f->indices;
}

static void wx_set_num_queues(struct wx *wx)
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
#ifndef _WX_LIB_H_
#define _WX_LIB_H_

struct wx_dec_ptype wx_decode_ptype(const u8 ptype);
void wx_alloc_rx_buffers(struct wx_ring *rx_ring, u16 cleaned_count);
u16 wx_desc_unused(struct wx_ring *ring);
netdev_tx_t wx_xmit_frame(struct sk_buff *skb,
+51 −1
Original line number Diff line number Diff line
@@ -503,6 +503,34 @@ enum WX_MSCA_CMD_value {
#define WX_PTYPE_TYP_TCP             0x04
#define WX_PTYPE_TYP_SCTP            0x05

/* Packet type non-ip values */
enum wx_l2_ptypes {
	WX_PTYPE_L2_ABORTED = (WX_PTYPE_PKT_MAC),
	WX_PTYPE_L2_MAC = (WX_PTYPE_PKT_MAC | WX_PTYPE_TYP_MAC),

	WX_PTYPE_L2_IPV4_FRAG = (WX_PTYPE_PKT_IP | WX_PTYPE_TYP_IPFRAG),
	WX_PTYPE_L2_IPV4 = (WX_PTYPE_PKT_IP | WX_PTYPE_TYP_IP),
	WX_PTYPE_L2_IPV4_UDP = (WX_PTYPE_PKT_IP | WX_PTYPE_TYP_UDP),
	WX_PTYPE_L2_IPV4_TCP = (WX_PTYPE_PKT_IP | WX_PTYPE_TYP_TCP),
	WX_PTYPE_L2_IPV4_SCTP = (WX_PTYPE_PKT_IP | WX_PTYPE_TYP_SCTP),
	WX_PTYPE_L2_IPV6_FRAG = (WX_PTYPE_PKT_IP | WX_PTYPE_PKT_IPV6 |
				 WX_PTYPE_TYP_IPFRAG),
	WX_PTYPE_L2_IPV6 = (WX_PTYPE_PKT_IP | WX_PTYPE_PKT_IPV6 |
			    WX_PTYPE_TYP_IP),
	WX_PTYPE_L2_IPV6_UDP = (WX_PTYPE_PKT_IP | WX_PTYPE_PKT_IPV6 |
				WX_PTYPE_TYP_UDP),
	WX_PTYPE_L2_IPV6_TCP = (WX_PTYPE_PKT_IP | WX_PTYPE_PKT_IPV6 |
				WX_PTYPE_TYP_TCP),
	WX_PTYPE_L2_IPV6_SCTP = (WX_PTYPE_PKT_IP | WX_PTYPE_PKT_IPV6 |
				 WX_PTYPE_TYP_SCTP),

	WX_PTYPE_L2_TUN4_MAC = (WX_PTYPE_TUN_IPV4 | WX_PTYPE_PKT_IGM),
	WX_PTYPE_L2_TUN6_MAC = (WX_PTYPE_TUN_IPV6 | WX_PTYPE_PKT_IGM),
};

#define WX_PTYPE_PKT(_pt)            ((_pt) & 0x30)
#define WX_PTYPE_TYPL4(_pt)          ((_pt) & 0x07)

#define WX_RXD_PKTTYPE(_rxd) \
	((le32_to_cpu((_rxd)->wb.lower.lo_dword.data) >> 9) & 0xFF)
#define WX_RXD_IPV6EX(_rxd) \
@@ -552,6 +580,9 @@ enum wx_tx_flags {
	WX_TX_FLAGS_OUTER_IPV4	= 0x100,
	WX_TX_FLAGS_LINKSEC	= 0x200,
	WX_TX_FLAGS_IPSEC	= 0x400,

	/* software defined flags */
	WX_TX_FLAGS_SW_VLAN	= 0x40,
};

/* VLAN info */
@@ -900,7 +931,13 @@ struct wx_ring {
					 */
	u16 next_to_use;
	u16 next_to_clean;
	union {
		u16 next_to_alloc;
		struct {
			u8 atr_sample_rate;
			u8 atr_count;
		};
	};

	struct wx_queue_stats stats;
	struct u64_stats_sync syncp;
@@ -939,6 +976,7 @@ struct wx_ring_feature {
enum wx_ring_f_enum {
	RING_F_NONE = 0,
	RING_F_RSS,
	RING_F_FDIR,
	RING_F_ARRAY_SIZE  /* must be last in enum set */
};

@@ -986,9 +1024,18 @@ enum wx_state {
	WX_STATE_RESETTING,
	WX_STATE_NBITS,		/* must be last */
};

enum wx_pf_flags {
	WX_FLAG_FDIR_CAPABLE,
	WX_FLAG_FDIR_HASH,
	WX_FLAG_FDIR_PERFECT,
	WX_PF_FLAGS_NBITS               /* must be last */
};

struct wx {
	unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
	DECLARE_BITMAP(state, WX_STATE_NBITS);
	DECLARE_BITMAP(flags, WX_PF_FLAGS_NBITS);

	void *priv;
	u8 __iomem *hw_addr;
@@ -1077,6 +1124,9 @@ struct wx {
	u64 hw_csum_rx_error;
	u64 alloc_rx_buff_failed;

	u32 atr_sample_rate;
	void (*atr)(struct wx_ring *ring, struct wx_tx_buffer *first, u8 ptype);
	void (*configure_fdir)(struct wx *wx);
	void (*do_reset)(struct net_device *netdev);
};

Loading