Commit 1110318d authored by Ioana Ciornei's avatar Ioana Ciornei Committed by David S. Miller

dpaa2-switch: add tc flower hardware offload on ingress traffic

This patch adds support for tc flower hardware offload on the ingress
path. Shared filter blocks are supported by sharing a single ACL table
between multiple ports.

The following flow keys are supported:
 - Ethernet: dst_mac/src_mac
 - IPv4: dst_ip/src_ip/ip_proto/tos
 - VLAN: vlan_id/vlan_prio/vlan_tpid/vlan_dei
 - L4: dst_port/src_port

As per flow actions, the following are supported:
 - drop
 - mirred egress redirect
 - trap
Each ACL entry (filter) can be setup with only one of the listed
actions.

A sorted single linked list is used to keep the ACL entries by their
order of priority. When adding a new filter, this enables us to quickly
ascertain if the new entry has the highest priority of the entire block
or if we should make some space in the ACL table by increasing the
priority of the filters already in the table.
Signed-off-by: default avatarIoana Ciornei <ioana.ciornei@nxp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2bf90ba5
......@@ -11,7 +11,7 @@ fsl-dpaa2-eth-objs := dpaa2-eth.o dpaa2-ethtool.o dpni.o dpaa2-mac.o dpmac.o dpa
fsl-dpaa2-eth-${CONFIG_FSL_DPAA2_ETH_DCB} += dpaa2-eth-dcb.o
fsl-dpaa2-eth-${CONFIG_DEBUG_FS} += dpaa2-eth-debugfs.o
fsl-dpaa2-ptp-objs := dpaa2-ptp.o dprtc.o
fsl-dpaa2-switch-objs := dpaa2-switch.o dpaa2-switch-ethtool.o dpsw.o
fsl-dpaa2-switch-objs := dpaa2-switch.o dpaa2-switch-ethtool.o dpsw.o dpaa2-switch-flower.o
# Needed by the tracing framework
CFLAGS_dpaa2-eth.o := -I$(src)
This diff is collapsed.
......@@ -14,6 +14,7 @@
#include <linux/kthread.h>
#include <linux/workqueue.h>
#include <linux/iommu.h>
#include <net/pkt_cls.h>
#include <linux/fsl/mc.h>
......@@ -1125,6 +1126,243 @@ static netdev_tx_t dpaa2_switch_port_tx(struct sk_buff *skb,
return NETDEV_TX_OK;
}
static int
dpaa2_switch_setup_tc_cls_flower(struct dpaa2_switch_acl_tbl *acl_tbl,
struct flow_cls_offload *f)
{
switch (f->command) {
case FLOW_CLS_REPLACE:
return dpaa2_switch_cls_flower_replace(acl_tbl, f);
case FLOW_CLS_DESTROY:
return dpaa2_switch_cls_flower_destroy(acl_tbl, f);
default:
return -EOPNOTSUPP;
}
}
static int dpaa2_switch_port_setup_tc_block_cb_ig(enum tc_setup_type type,
void *type_data,
void *cb_priv)
{
switch (type) {
case TC_SETUP_CLSFLOWER:
return dpaa2_switch_setup_tc_cls_flower(cb_priv, type_data);
default:
return -EOPNOTSUPP;
}
}
static LIST_HEAD(dpaa2_switch_block_cb_list);
static int dpaa2_switch_port_acl_tbl_bind(struct ethsw_port_priv *port_priv,
struct dpaa2_switch_acl_tbl *acl_tbl)
{
struct ethsw_core *ethsw = port_priv->ethsw_data;
struct net_device *netdev = port_priv->netdev;
struct dpsw_acl_if_cfg acl_if_cfg;
int err;
if (port_priv->acl_tbl)
return -EINVAL;
acl_if_cfg.if_id[0] = port_priv->idx;
acl_if_cfg.num_ifs = 1;
err = dpsw_acl_add_if(ethsw->mc_io, 0, ethsw->dpsw_handle,
acl_tbl->id, &acl_if_cfg);
if (err) {
netdev_err(netdev, "dpsw_acl_add_if err %d\n", err);
return err;
}
acl_tbl->ports |= BIT(port_priv->idx);
port_priv->acl_tbl = acl_tbl;
return 0;
}
static int
dpaa2_switch_port_acl_tbl_unbind(struct ethsw_port_priv *port_priv,
struct dpaa2_switch_acl_tbl *acl_tbl)
{
struct ethsw_core *ethsw = port_priv->ethsw_data;
struct net_device *netdev = port_priv->netdev;
struct dpsw_acl_if_cfg acl_if_cfg;
int err;
if (port_priv->acl_tbl != acl_tbl)
return -EINVAL;
acl_if_cfg.if_id[0] = port_priv->idx;
acl_if_cfg.num_ifs = 1;
err = dpsw_acl_remove_if(ethsw->mc_io, 0, ethsw->dpsw_handle,
acl_tbl->id, &acl_if_cfg);
if (err) {
netdev_err(netdev, "dpsw_acl_add_if err %d\n", err);
return err;
}
acl_tbl->ports &= ~BIT(port_priv->idx);
port_priv->acl_tbl = NULL;
return 0;
}
static int dpaa2_switch_port_block_bind(struct ethsw_port_priv *port_priv,
struct dpaa2_switch_acl_tbl *acl_tbl)
{
struct dpaa2_switch_acl_tbl *old_acl_tbl = port_priv->acl_tbl;
int err;
/* If the port is already bound to this ACL table then do nothing. This
* can happen when this port is the first one to join a tc block
*/
if (port_priv->acl_tbl == acl_tbl)
return 0;
err = dpaa2_switch_port_acl_tbl_unbind(port_priv, old_acl_tbl);
if (err)
return err;
/* Mark the previous ACL table as being unused if this was the last
* port that was using it.
*/
if (old_acl_tbl->ports == 0)
old_acl_tbl->in_use = false;
return dpaa2_switch_port_acl_tbl_bind(port_priv, acl_tbl);
}
static int dpaa2_switch_port_block_unbind(struct ethsw_port_priv *port_priv,
struct dpaa2_switch_acl_tbl *acl_tbl)
{
struct ethsw_core *ethsw = port_priv->ethsw_data;
struct dpaa2_switch_acl_tbl *new_acl_tbl;
int err;
/* We are the last port that leaves a block (an ACL table).
* We'll continue to use this table.
*/
if (acl_tbl->ports == BIT(port_priv->idx))
return 0;
err = dpaa2_switch_port_acl_tbl_unbind(port_priv, acl_tbl);
if (err)
return err;
if (acl_tbl->ports == 0)
acl_tbl->in_use = false;
new_acl_tbl = dpaa2_switch_acl_tbl_get_unused(ethsw);
new_acl_tbl->in_use = true;
return dpaa2_switch_port_acl_tbl_bind(port_priv, new_acl_tbl);
}
static int dpaa2_switch_setup_tc_block_bind(struct net_device *netdev,
struct flow_block_offload *f)
{
struct ethsw_port_priv *port_priv = netdev_priv(netdev);
struct ethsw_core *ethsw = port_priv->ethsw_data;
struct dpaa2_switch_acl_tbl *acl_tbl;
struct flow_block_cb *block_cb;
bool register_block = false;
int err;
block_cb = flow_block_cb_lookup(f->block,
dpaa2_switch_port_setup_tc_block_cb_ig,
ethsw);
if (!block_cb) {
/* If the ACL table is not already known, then this port must
* be the first to join it. In this case, we can just continue
* to use our private table
*/
acl_tbl = port_priv->acl_tbl;
block_cb = flow_block_cb_alloc(dpaa2_switch_port_setup_tc_block_cb_ig,
ethsw, acl_tbl, NULL);
if (IS_ERR(block_cb))
return PTR_ERR(block_cb);
register_block = true;
} else {
acl_tbl = flow_block_cb_priv(block_cb);
}
flow_block_cb_incref(block_cb);
err = dpaa2_switch_port_block_bind(port_priv, acl_tbl);
if (err)
goto err_block_bind;
if (register_block) {
flow_block_cb_add(block_cb, f);
list_add_tail(&block_cb->driver_list,
&dpaa2_switch_block_cb_list);
}
return 0;
err_block_bind:
if (!flow_block_cb_decref(block_cb))
flow_block_cb_free(block_cb);
return err;
}
static void dpaa2_switch_setup_tc_block_unbind(struct net_device *netdev,
struct flow_block_offload *f)
{
struct ethsw_port_priv *port_priv = netdev_priv(netdev);
struct ethsw_core *ethsw = port_priv->ethsw_data;
struct dpaa2_switch_acl_tbl *acl_tbl;
struct flow_block_cb *block_cb;
int err;
block_cb = flow_block_cb_lookup(f->block,
dpaa2_switch_port_setup_tc_block_cb_ig,
ethsw);
if (!block_cb)
return;
acl_tbl = flow_block_cb_priv(block_cb);
err = dpaa2_switch_port_block_unbind(port_priv, acl_tbl);
if (!err && !flow_block_cb_decref(block_cb)) {
flow_block_cb_remove(block_cb, f);
list_del(&block_cb->driver_list);
}
}
static int dpaa2_switch_setup_tc_block(struct net_device *netdev,
struct flow_block_offload *f)
{
if (f->binder_type != FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
return -EOPNOTSUPP;
f->driver_block_list = &dpaa2_switch_block_cb_list;
switch (f->command) {
case FLOW_BLOCK_BIND:
return dpaa2_switch_setup_tc_block_bind(netdev, f);
case FLOW_BLOCK_UNBIND:
dpaa2_switch_setup_tc_block_unbind(netdev, f);
return 0;
default:
return -EOPNOTSUPP;
}
}
static int dpaa2_switch_port_setup_tc(struct net_device *netdev,
enum tc_setup_type type,
void *type_data)
{
switch (type) {
case TC_SETUP_BLOCK: {
return dpaa2_switch_setup_tc_block(netdev, type_data);
}
default:
return -EOPNOTSUPP;
}
return 0;
}
static const struct net_device_ops dpaa2_switch_port_ops = {
.ndo_open = dpaa2_switch_port_open,
.ndo_stop = dpaa2_switch_port_stop,
......@@ -1141,6 +1379,7 @@ static const struct net_device_ops dpaa2_switch_port_ops = {
.ndo_start_xmit = dpaa2_switch_port_tx,
.ndo_get_port_parent_id = dpaa2_switch_port_parent_id,
.ndo_get_phys_port_name = dpaa2_switch_port_get_phys_name,
.ndo_setup_tc = dpaa2_switch_port_setup_tc,
};
bool dpaa2_switch_port_dev_check(const struct net_device *netdev)
......@@ -2749,7 +2988,6 @@ static int dpaa2_switch_port_init(struct ethsw_port_priv *port_priv, u16 port)
struct ethsw_core *ethsw = port_priv->ethsw_data;
struct dpaa2_switch_acl_tbl *acl_tbl;
struct dpsw_fdb_cfg fdb_cfg = {0};
struct dpsw_acl_if_cfg acl_if_cfg;
struct dpsw_if_attr dpsw_if_attr;
struct dpaa2_switch_fdb *fdb;
struct dpsw_acl_cfg acl_cfg;
......@@ -2803,21 +3041,16 @@ static int dpaa2_switch_port_init(struct ethsw_port_priv *port_priv, u16 port)
return err;
}
acl_if_cfg.if_id[0] = port_priv->idx;
acl_if_cfg.num_ifs = 1;
err = dpsw_acl_add_if(ethsw->mc_io, 0, ethsw->dpsw_handle,
acl_tbl_id, &acl_if_cfg);
if (err) {
netdev_err(netdev, "dpsw_acl_add_if err %d\n", err);
dpsw_acl_remove(ethsw->mc_io, 0, ethsw->dpsw_handle,
acl_tbl_id);
}
acl_tbl = dpaa2_switch_acl_tbl_get_unused(ethsw);
acl_tbl->ethsw = ethsw;
acl_tbl->id = acl_tbl_id;
acl_tbl->in_use = true;
acl_tbl->num_rules = 0;
port_priv->acl_tbl = acl_tbl;
INIT_LIST_HEAD(&acl_tbl->entries);
err = dpaa2_switch_port_acl_tbl_bind(port_priv, acl_tbl);
if (err)
return err;
err = dpaa2_switch_port_trap_mac_addr(port_priv, stpa);
if (err)
......@@ -2927,7 +3160,9 @@ static int dpaa2_switch_probe_port(struct ethsw_core *ethsw,
/* The DPAA2 switch's ingress path depends on the VLAN table,
* thus we are not able to disable VLAN filtering.
*/
port_netdev->features = NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_STAG_FILTER;
port_netdev->features = NETIF_F_HW_VLAN_CTAG_FILTER |
NETIF_F_HW_VLAN_STAG_FILTER |
NETIF_F_HW_TC;
err = dpaa2_switch_port_init(port_priv, port_idx);
if (err)
......
......@@ -80,6 +80,8 @@
(DPAA2_SWITCH_TX_DATA_OFFSET + DPAA2_SWITCH_TX_BUF_ALIGN)
#define DPAA2_ETHSW_PORT_MAX_ACL_ENTRIES 16
#define DPAA2_ETHSW_PORT_DEFAULT_TRAPS 1
#define DPAA2_ETHSW_PORT_ACL_CMD_BUF_SIZE 256
extern const struct ethtool_ops dpaa2_switch_port_ethtool_ops;
......@@ -101,12 +103,34 @@ struct dpaa2_switch_fdb {
bool in_use;
};
struct dpaa2_switch_acl_entry {
struct list_head list;
u16 prio;
unsigned long cookie;
struct dpsw_acl_entry_cfg cfg;
struct dpsw_acl_key key;
};
struct dpaa2_switch_acl_tbl {
struct list_head entries;
struct ethsw_core *ethsw;
u64 ports;
u16 id;
u8 num_rules;
bool in_use;
};
static inline bool
dpaa2_switch_acl_tbl_is_full(struct dpaa2_switch_acl_tbl *acl_tbl)
{
if ((acl_tbl->num_rules + DPAA2_ETHSW_PORT_DEFAULT_TRAPS) >=
DPAA2_ETHSW_PORT_MAX_ACL_ENTRIES)
return true;
return false;
}
/* Per port private data */
struct ethsw_port_priv {
struct net_device *netdev;
......@@ -153,6 +177,18 @@ struct ethsw_core {
struct dpaa2_switch_acl_tbl *acls;
};
static inline int dpaa2_switch_get_index(struct ethsw_core *ethsw,
struct net_device *netdev)
{
int i;
for (i = 0; i < ethsw->sw_attr.num_ifs; i++)
if (ethsw->ports[i]->netdev == netdev)
return ethsw->ports[i]->idx;
return -EINVAL;
}
static inline bool dpaa2_switch_supports_cpu_traffic(struct ethsw_core *ethsw)
{
if (ethsw->sw_attr.options & DPSW_OPT_CTRL_IF_DIS) {
......@@ -189,4 +225,12 @@ int dpaa2_switch_port_vlans_del(struct net_device *netdev,
typedef int dpaa2_switch_fdb_cb_t(struct ethsw_port_priv *port_priv,
struct fdb_dump_entry *fdb_entry,
void *data);
/* TC offload */
int dpaa2_switch_cls_flower_replace(struct dpaa2_switch_acl_tbl *acl_tbl,
struct flow_cls_offload *cls);
int dpaa2_switch_cls_flower_destroy(struct dpaa2_switch_acl_tbl *acl_tbl,
struct flow_cls_offload *cls);
#endif /* __ETHSW_H */
......@@ -77,6 +77,7 @@
#define DPSW_CMDID_ACL_ADD DPSW_CMD_ID(0x090)
#define DPSW_CMDID_ACL_REMOVE DPSW_CMD_ID(0x091)
#define DPSW_CMDID_ACL_ADD_ENTRY DPSW_CMD_ID(0x092)
#define DPSW_CMDID_ACL_REMOVE_ENTRY DPSW_CMD_ID(0x093)
#define DPSW_CMDID_ACL_ADD_IF DPSW_CMD_ID(0x094)
#define DPSW_CMDID_ACL_REMOVE_IF DPSW_CMD_ID(0x095)
......
......@@ -1544,3 +1544,38 @@ int dpsw_acl_add_entry(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
return mc_send_command(mc_io, &cmd);
}
/**
* dpsw_acl_remove_entry() - Removes an entry from ACL.
* @mc_io: Pointer to MC portal's I/O object
* @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
* @token: Token of DPSW object
* @acl_id: ACL ID
* @cfg: Entry configuration
*
* warning: This function has to be called after dpsw_acl_set_entry_cfg()
*
* Return: '0' on Success; Error code otherwise.
*/
int dpsw_acl_remove_entry(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
u16 acl_id, const struct dpsw_acl_entry_cfg *cfg)
{
struct dpsw_cmd_acl_entry *cmd_params;
struct fsl_mc_command cmd = { 0 };
/* prepare command */
cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_REMOVE_ENTRY,
cmd_flags,
token);
cmd_params = (struct dpsw_cmd_acl_entry *)cmd.params;
cmd_params->acl_id = cpu_to_le16(acl_id);
cmd_params->result_if_id = cpu_to_le16(cfg->result.if_id);
cmd_params->precedence = cpu_to_le32(cfg->precedence);
cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
dpsw_set_field(cmd_params->result_action,
RESULT_ACTION,
cfg->result.action);
/* send command to mc*/
return mc_send_command(mc_io, &cmd);
}
......@@ -749,4 +749,7 @@ void dpsw_acl_prepare_entry_cfg(const struct dpsw_acl_key *key,
int dpsw_acl_add_entry(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
u16 acl_id, const struct dpsw_acl_entry_cfg *cfg);
int dpsw_acl_remove_entry(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
u16 acl_id, const struct dpsw_acl_entry_cfg *cfg);
#endif /* __FSL_DPSW_H */
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