Commit ae404c21 authored by David S. Miller's avatar David S. Miller

Merge branch 'net-tsnep-multiqueue'

Gerhard Engleder says:

====================
tsnep: multi queue support and some other improvements

Add support for additional TX/RX queues along with RX flow classification
support.

Binding is extended to allow additional interrupts for additional TX/RX
queues. Also dma-coherent is allowed as minor improvement.

RX path optimisation is done by using page pool as preparations for future
XDP support.

v4:
- rework dma-coherent commit message (Krzysztof Kozlowski)
- fixed order of interrupt-names in binding (Krzysztof Kozlowski)
- add line break between examples in binding (Krzysztof Kozlowski)
- add RX_CLS_LOC_ANY support to RX flow classification

v3:
- now with changes in cover letter

v2:
- use netdev_name() (Jakub Kicinski)
- use ENOENT if RX flow rule is not found (Jakub Kicinski)
- eliminate return code of tsnep_add_rule() (Jakub Kicinski)
- remove commit with lazy refill due to depletion problem (Jakub Kicinski)
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents d742ea6b bb837a37
......@@ -20,7 +20,26 @@ properties:
maxItems: 1
interrupts:
maxItems: 1
minItems: 1
maxItems: 8
interrupt-names:
minItems: 1
items:
- const: mac
- const: txrx-1
- const: txrx-2
- const: txrx-3
- const: txrx-4
- const: txrx-5
- const: txrx-6
- const: txrx-7
description:
The main interrupt for basic MAC features and the first TX/RX queue pair
is named "mac". "txrx-[1-7]" are the interrupts for additional TX/RX
queue pairs.
dma-coherent: true
local-mac-address: true
......@@ -58,7 +77,7 @@ examples:
axi {
#address-cells = <2>;
#size-cells = <2>;
tnsep0: ethernet@a0000000 {
tsnep0: ethernet@a0000000 {
compatible = "engleder,tsnep";
reg = <0x0 0xa0000000 0x0 0x10000>;
interrupts = <0 89 1>;
......@@ -76,4 +95,24 @@ examples:
};
};
};
tsnep1: ethernet@a0010000 {
compatible = "engleder,tsnep";
reg = <0x0 0xa0010000 0x0 0x10000>;
interrupts = <0 93 1>, <0 94 1>, <0 95 1>, <0 96 1>;
interrupt-names = "mac", "txrx-1", "txrx-2", "txrx-3";
interrupt-parent = <&gic>;
local-mac-address = [00 00 00 00 00 00];
phy-mode = "rgmii";
phy-handle = <&phy1>;
mdio {
#address-cells = <1>;
#size-cells = <0>;
suppress-preamble;
phy1: ethernet-phy@1 {
reg = <1>;
rxc-skew-ps = <1080>;
};
};
};
};
......@@ -21,6 +21,7 @@ config TSNEP
depends on HAS_IOMEM && HAS_DMA
depends on PTP_1588_CLOCK_OPTIONAL
select PHYLIB
select PAGE_POOL
help
Support for the Engleder TSN endpoint Ethernet MAC IP Core.
......
......@@ -6,5 +6,5 @@
obj-$(CONFIG_TSNEP) += tsnep.o
tsnep-objs := tsnep_main.o tsnep_ethtool.o tsnep_ptp.o tsnep_tc.o \
$(tsnep-y)
tsnep_rxnfc.o $(tsnep-y)
tsnep-$(CONFIG_TSNEP_SELFTESTS) += tsnep_selftests.o
......@@ -21,8 +21,6 @@
#define TSNEP_RING_ENTRIES_PER_PAGE (PAGE_SIZE / TSNEP_DESC_SIZE)
#define TSNEP_RING_PAGE_COUNT (TSNEP_RING_SIZE / TSNEP_RING_ENTRIES_PER_PAGE)
#define TSNEP_QUEUES 1
struct tsnep_gcl {
void __iomem *addr;
......@@ -39,6 +37,24 @@ struct tsnep_gcl {
bool change;
};
enum tsnep_rxnfc_filter_type {
TSNEP_RXNFC_ETHER_TYPE,
};
struct tsnep_rxnfc_filter {
enum tsnep_rxnfc_filter_type type;
union {
u16 ether_type;
};
};
struct tsnep_rxnfc_rule {
struct list_head list;
struct tsnep_rxnfc_filter filter;
int queue_index;
int location;
};
struct tsnep_tx_entry {
struct tsnep_tx_desc *desc;
struct tsnep_tx_desc_wb *desc_wb;
......@@ -55,6 +71,7 @@ struct tsnep_tx_entry {
struct tsnep_tx {
struct tsnep_adapter *adapter;
void __iomem *addr;
int queue_index;
void *page[TSNEP_RING_PAGE_COUNT];
dma_addr_t page_dma[TSNEP_RING_PAGE_COUNT];
......@@ -79,9 +96,9 @@ struct tsnep_rx_entry {
u32 properties;
struct sk_buff *skb;
struct page *page;
size_t len;
DEFINE_DMA_UNMAP_ADDR(dma);
dma_addr_t dma;
};
struct tsnep_rx {
......@@ -96,6 +113,7 @@ struct tsnep_rx {
int read;
u32 owner_counter;
int increment_owner_counter;
struct page_pool *page_pool;
u32 packets;
u32 bytes;
......@@ -105,12 +123,14 @@ struct tsnep_rx {
struct tsnep_queue {
struct tsnep_adapter *adapter;
char name[IFNAMSIZ + 9];
struct tsnep_tx *tx;
struct tsnep_rx *rx;
struct napi_struct napi;
int irq;
u32 irq_mask;
};
......@@ -126,7 +146,6 @@ struct tsnep_adapter {
struct platform_device *pdev;
struct device *dmadev;
void __iomem *addr;
int irq;
bool gate_control;
/* gate control lock */
......@@ -141,6 +160,12 @@ struct tsnep_adapter {
/* ptp clock lock */
spinlock_t ptp_lock;
/* RX flow classification rules lock */
struct mutex rxnfc_lock;
struct list_head rxnfc_rules;
int rxnfc_count;
int rxnfc_max;
int num_tx_queues;
struct tsnep_tx tx[TSNEP_MAX_QUEUES];
int num_rx_queues;
......@@ -161,6 +186,18 @@ void tsnep_tc_cleanup(struct tsnep_adapter *adapter);
int tsnep_tc_setup(struct net_device *netdev, enum tc_setup_type type,
void *type_data);
int tsnep_rxnfc_init(struct tsnep_adapter *adapter);
void tsnep_rxnfc_cleanup(struct tsnep_adapter *adapter);
int tsnep_rxnfc_get_rule(struct tsnep_adapter *adapter,
struct ethtool_rxnfc *cmd);
int tsnep_rxnfc_get_all(struct tsnep_adapter *adapter,
struct ethtool_rxnfc *cmd,
u32 *rule_locs);
int tsnep_rxnfc_add_rule(struct tsnep_adapter *adapter,
struct ethtool_rxnfc *cmd);
int tsnep_rxnfc_del_rule(struct tsnep_adapter *adapter,
struct ethtool_rxnfc *cmd);
#if IS_ENABLED(CONFIG_TSNEP_SELFTESTS)
int tsnep_ethtool_get_test_count(void);
void tsnep_ethtool_get_test_strings(u8 *data);
......
......@@ -250,6 +250,44 @@ static int tsnep_ethtool_get_sset_count(struct net_device *netdev, int sset)
}
}
static int tsnep_ethtool_get_rxnfc(struct net_device *dev,
struct ethtool_rxnfc *cmd, u32 *rule_locs)
{
struct tsnep_adapter *adapter = netdev_priv(dev);
switch (cmd->cmd) {
case ETHTOOL_GRXRINGS:
cmd->data = adapter->num_rx_queues;
return 0;
case ETHTOOL_GRXCLSRLCNT:
cmd->rule_cnt = adapter->rxnfc_count;
cmd->data = adapter->rxnfc_max;
cmd->data |= RX_CLS_LOC_SPECIAL;
return 0;
case ETHTOOL_GRXCLSRULE:
return tsnep_rxnfc_get_rule(adapter, cmd);
case ETHTOOL_GRXCLSRLALL:
return tsnep_rxnfc_get_all(adapter, cmd, rule_locs);
default:
return -EOPNOTSUPP;
}
}
static int tsnep_ethtool_set_rxnfc(struct net_device *dev,
struct ethtool_rxnfc *cmd)
{
struct tsnep_adapter *adapter = netdev_priv(dev);
switch (cmd->cmd) {
case ETHTOOL_SRXCLSRLINS:
return tsnep_rxnfc_add_rule(adapter, cmd);
case ETHTOOL_SRXCLSRLDEL:
return tsnep_rxnfc_del_rule(adapter, cmd);
default:
return -EOPNOTSUPP;
}
}
static int tsnep_ethtool_get_ts_info(struct net_device *dev,
struct ethtool_ts_info *info)
{
......@@ -287,6 +325,8 @@ const struct ethtool_ops tsnep_ethtool_ops = {
.get_strings = tsnep_ethtool_get_strings,
.get_ethtool_stats = tsnep_ethtool_get_ethtool_stats,
.get_sset_count = tsnep_ethtool_get_sset_count,
.get_rxnfc = tsnep_ethtool_get_rxnfc,
.set_rxnfc = tsnep_ethtool_set_rxnfc,
.get_ts_info = tsnep_ethtool_get_ts_info,
.get_link_ksettings = phy_ethtool_get_link_ksettings,
.set_link_ksettings = phy_ethtool_set_link_ksettings,
......
......@@ -34,6 +34,7 @@
#define ECM_INT_LINK 0x00000020
#define ECM_INT_TX_0 0x00000100
#define ECM_INT_RX_0 0x00000200
#define ECM_INT_TXRX_SHIFT 2
#define ECM_INT_ALL 0x7FFFFFFF
#define ECM_INT_DISABLE 0x80000000
......@@ -121,10 +122,6 @@
#define TSNEP_RX_STATISTIC_BUFFER_TOO_SMALL 0x0191
#define TSNEP_RX_STATISTIC_FIFO_OVERFLOW 0x0192
#define TSNEP_RX_STATISTIC_INVALID_FRAME 0x0193
#define TSNEP_RX_ASSIGN 0x01A0
#define TSNEP_RX_ASSIGN_ETHER_TYPE_ACTIVE 0x00000001
#define TSNEP_RX_ASSIGN_ETHER_TYPE_MASK 0xFFFF0000
#define TSNEP_RX_ASSIGN_ETHER_TYPE_SHIFT 16
#define TSNEP_MAC_ADDRESS_LOW 0x0800
#define TSNEP_MAC_ADDRESS_HIGH 0x0804
#define TSNEP_RX_FILTER 0x0806
......@@ -151,6 +148,14 @@
#define TSNEP_GCL_A 0x2000
#define TSNEP_GCL_B 0x2800
#define TSNEP_GCL_SIZE SZ_2K
#define TSNEP_RX_ASSIGN 0x0840
#define TSNEP_RX_ASSIGN_ACTIVE 0x00000001
#define TSNEP_RX_ASSIGN_QUEUE_MASK 0x00000006
#define TSNEP_RX_ASSIGN_QUEUE_SHIFT 1
#define TSNEP_RX_ASSIGN_OFFSET 1
#define TSNEP_RX_ASSIGN_ETHER_TYPE 0x0880
#define TSNEP_RX_ASSIGN_ETHER_TYPE_OFFSET 2
#define TSNEP_RX_ASSIGN_ETHER_TYPE_COUNT 2
/* tsnep gate control list operation */
struct tsnep_gcl_operation {
......
This diff is collapsed.
// SPDX-License-Identifier: GPL-2.0
/* Copyright (C) 2022 Gerhard Engleder <gerhard@engleder-embedded.com> */
#include "tsnep.h"
#define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
static void tsnep_enable_rule(struct tsnep_adapter *adapter,
struct tsnep_rxnfc_rule *rule)
{
u8 rx_assign;
void __iomem *addr;
rx_assign = TSNEP_RX_ASSIGN_ACTIVE;
rx_assign |= (rule->queue_index << TSNEP_RX_ASSIGN_QUEUE_SHIFT) &
TSNEP_RX_ASSIGN_QUEUE_MASK;
addr = adapter->addr + TSNEP_RX_ASSIGN_ETHER_TYPE +
TSNEP_RX_ASSIGN_ETHER_TYPE_OFFSET * rule->location;
iowrite16(rule->filter.ether_type, addr);
/* enable rule after all settings are done */
addr = adapter->addr + TSNEP_RX_ASSIGN +
TSNEP_RX_ASSIGN_OFFSET * rule->location;
iowrite8(rx_assign, addr);
}
static void tsnep_disable_rule(struct tsnep_adapter *adapter,
struct tsnep_rxnfc_rule *rule)
{
void __iomem *addr;
addr = adapter->addr + TSNEP_RX_ASSIGN +
TSNEP_RX_ASSIGN_OFFSET * rule->location;
iowrite8(0, addr);
}
static struct tsnep_rxnfc_rule *tsnep_get_rule(struct tsnep_adapter *adapter,
int location)
{
struct tsnep_rxnfc_rule *rule;
list_for_each_entry(rule, &adapter->rxnfc_rules, list) {
if (rule->location == location)
return rule;
if (rule->location > location)
break;
}
return NULL;
}
static void tsnep_add_rule(struct tsnep_adapter *adapter,
struct tsnep_rxnfc_rule *rule)
{
struct tsnep_rxnfc_rule *pred, *cur;
tsnep_enable_rule(adapter, rule);
pred = NULL;
list_for_each_entry(cur, &adapter->rxnfc_rules, list) {
if (cur->location >= rule->location)
break;
pred = cur;
}
list_add(&rule->list, pred ? &pred->list : &adapter->rxnfc_rules);
adapter->rxnfc_count++;
}
static void tsnep_delete_rule(struct tsnep_adapter *adapter,
struct tsnep_rxnfc_rule *rule)
{
tsnep_disable_rule(adapter, rule);
list_del(&rule->list);
adapter->rxnfc_count--;
kfree(rule);
}
static void tsnep_flush_rules(struct tsnep_adapter *adapter)
{
struct tsnep_rxnfc_rule *rule, *tmp;
mutex_lock(&adapter->rxnfc_lock);
list_for_each_entry_safe(rule, tmp, &adapter->rxnfc_rules, list)
tsnep_delete_rule(adapter, rule);
mutex_unlock(&adapter->rxnfc_lock);
}
int tsnep_rxnfc_get_rule(struct tsnep_adapter *adapter,
struct ethtool_rxnfc *cmd)
{
struct ethtool_rx_flow_spec *fsp = &cmd->fs;
struct tsnep_rxnfc_rule *rule = NULL;
cmd->data = adapter->rxnfc_max;
mutex_lock(&adapter->rxnfc_lock);
rule = tsnep_get_rule(adapter, fsp->location);
if (!rule) {
mutex_unlock(&adapter->rxnfc_lock);
return -ENOENT;
}
fsp->flow_type = ETHER_FLOW;
fsp->ring_cookie = rule->queue_index;
if (rule->filter.type == TSNEP_RXNFC_ETHER_TYPE) {
fsp->h_u.ether_spec.h_proto = htons(rule->filter.ether_type);
fsp->m_u.ether_spec.h_proto = ETHER_TYPE_FULL_MASK;
}
mutex_unlock(&adapter->rxnfc_lock);
return 0;
}
int tsnep_rxnfc_get_all(struct tsnep_adapter *adapter,
struct ethtool_rxnfc *cmd,
u32 *rule_locs)
{
struct tsnep_rxnfc_rule *rule;
int count = 0;
cmd->data = adapter->rxnfc_max;
mutex_lock(&adapter->rxnfc_lock);
list_for_each_entry(rule, &adapter->rxnfc_rules, list) {
if (count == cmd->rule_cnt) {
mutex_unlock(&adapter->rxnfc_lock);
return -EMSGSIZE;
}
rule_locs[count] = rule->location;
count++;
}
mutex_unlock(&adapter->rxnfc_lock);
cmd->rule_cnt = count;
return 0;
}
static int tsnep_rxnfc_find_location(struct tsnep_adapter *adapter)
{
struct tsnep_rxnfc_rule *tmp;
int location = 0;
list_for_each_entry(tmp, &adapter->rxnfc_rules, list) {
if (tmp->location == location)
location++;
else
return location;
}
if (location >= adapter->rxnfc_max)
return -ENOSPC;
return location;
}
static void tsnep_rxnfc_init_rule(struct tsnep_rxnfc_rule *rule,
const struct ethtool_rx_flow_spec *fsp)
{
INIT_LIST_HEAD(&rule->list);
rule->queue_index = fsp->ring_cookie;
rule->location = fsp->location;
rule->filter.type = TSNEP_RXNFC_ETHER_TYPE;
rule->filter.ether_type = ntohs(fsp->h_u.ether_spec.h_proto);
}
static int tsnep_rxnfc_check_rule(struct tsnep_adapter *adapter,
struct tsnep_rxnfc_rule *rule)
{
struct net_device *dev = adapter->netdev;
struct tsnep_rxnfc_rule *tmp;
list_for_each_entry(tmp, &adapter->rxnfc_rules, list) {
if (!memcmp(&rule->filter, &tmp->filter, sizeof(rule->filter)) &&
tmp->location != rule->location) {
netdev_dbg(dev, "rule already exists\n");
return -EEXIST;
}
}
return 0;
}
int tsnep_rxnfc_add_rule(struct tsnep_adapter *adapter,
struct ethtool_rxnfc *cmd)
{
struct net_device *netdev = adapter->netdev;
struct ethtool_rx_flow_spec *fsp =
(struct ethtool_rx_flow_spec *)&cmd->fs;
struct tsnep_rxnfc_rule *rule, *old_rule;
int retval;
/* only EtherType is supported */
if (fsp->flow_type != ETHER_FLOW ||
!is_zero_ether_addr(fsp->m_u.ether_spec.h_dest) ||
!is_zero_ether_addr(fsp->m_u.ether_spec.h_source) ||
fsp->m_u.ether_spec.h_proto != ETHER_TYPE_FULL_MASK) {
netdev_dbg(netdev, "only ethernet protocol is supported\n");
return -EOPNOTSUPP;
}
if (fsp->ring_cookie >
(TSNEP_RX_ASSIGN_QUEUE_MASK >> TSNEP_RX_ASSIGN_QUEUE_SHIFT)) {
netdev_dbg(netdev, "invalid action\n");
return -EINVAL;
}
if (fsp->location != RX_CLS_LOC_ANY &&
fsp->location >= adapter->rxnfc_max) {
netdev_dbg(netdev, "invalid location\n");
return -EINVAL;
}
rule = kzalloc(sizeof(*rule), GFP_KERNEL);
if (!rule)
return -ENOMEM;
mutex_lock(&adapter->rxnfc_lock);
if (fsp->location == RX_CLS_LOC_ANY) {
retval = tsnep_rxnfc_find_location(adapter);
if (retval < 0)
goto failed;
fsp->location = retval;
}
tsnep_rxnfc_init_rule(rule, fsp);
retval = tsnep_rxnfc_check_rule(adapter, rule);
if (retval)
goto failed;
old_rule = tsnep_get_rule(adapter, fsp->location);
if (old_rule)
tsnep_delete_rule(adapter, old_rule);
tsnep_add_rule(adapter, rule);
mutex_unlock(&adapter->rxnfc_lock);
return 0;
failed:
mutex_unlock(&adapter->rxnfc_lock);
kfree(rule);
return retval;
}
int tsnep_rxnfc_del_rule(struct tsnep_adapter *adapter,
struct ethtool_rxnfc *cmd)
{
struct ethtool_rx_flow_spec *fsp =
(struct ethtool_rx_flow_spec *)&cmd->fs;
struct tsnep_rxnfc_rule *rule;
mutex_lock(&adapter->rxnfc_lock);
rule = tsnep_get_rule(adapter, fsp->location);
if (!rule) {
mutex_unlock(&adapter->rxnfc_lock);
return -ENOENT;
}
tsnep_delete_rule(adapter, rule);
mutex_unlock(&adapter->rxnfc_lock);
return 0;
}
int tsnep_rxnfc_init(struct tsnep_adapter *adapter)
{
int i;
/* disable all rules */
for (i = 0; i < adapter->rxnfc_max;
i += sizeof(u32) / TSNEP_RX_ASSIGN_OFFSET)
iowrite32(0, adapter->addr + TSNEP_RX_ASSIGN + i);
return 0;
}
void tsnep_rxnfc_cleanup(struct tsnep_adapter *adapter)
{
tsnep_flush_rules(adapter);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment