blob: a4ab71d43e4e9d521e2a58f75aca4a4dff3f9c30 [file] [log] [blame]
/*
* drivers/net/ethernet/rocker/rocker.c - Rocker switch device driver
* Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
* Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/interrupt.h>
#include <linux/sched.h>
#include <linux/wait.h>
#include <linux/spinlock.h>
#include <linux/hashtable.h>
#include <linux/crc32.h>
#include <linux/sort.h>
#include <linux/random.h>
#include <linux/netdevice.h>
#include <linux/inetdevice.h>
#include <linux/skbuff.h>
#include <linux/socket.h>
#include <linux/etherdevice.h>
#include <linux/ethtool.h>
#include <linux/if_ether.h>
#include <linux/if_vlan.h>
#include <linux/if_bridge.h>
#include <linux/bitops.h>
#include <linux/ctype.h>
#include <net/switchdev.h>
#include <net/rtnetlink.h>
#include <net/ip_fib.h>
#include <net/netevent.h>
#include <net/arp.h>
#include <linux/io-64-nonatomic-lo-hi.h>
#include <generated/utsrelease.h>
#include "rocker.h"
static const char rocker_driver_name[] = "rocker";
static const struct pci_device_id rocker_pci_id_table[] = {
{PCI_VDEVICE(REDHAT, PCI_DEVICE_ID_REDHAT_ROCKER), 0},
{0, }
};
struct rocker_flow_tbl_key {
u32 priority;
enum rocker_of_dpa_table_id tbl_id;
union {
struct {
u32 in_pport;
u32 in_pport_mask;
enum rocker_of_dpa_table_id goto_tbl;
} ig_port;
struct {
u32 in_pport;
__be16 vlan_id;
__be16 vlan_id_mask;
enum rocker_of_dpa_table_id goto_tbl;
bool untagged;
__be16 new_vlan_id;
} vlan;
struct {
u32 in_pport;
u32 in_pport_mask;
__be16 eth_type;
u8 eth_dst[ETH_ALEN];
u8 eth_dst_mask[ETH_ALEN];
__be16 vlan_id;
__be16 vlan_id_mask;
enum rocker_of_dpa_table_id goto_tbl;
bool copy_to_cpu;
} term_mac;
struct {
__be16 eth_type;
__be32 dst4;
__be32 dst4_mask;
enum rocker_of_dpa_table_id goto_tbl;
u32 group_id;
} ucast_routing;
struct {
u8 eth_dst[ETH_ALEN];
u8 eth_dst_mask[ETH_ALEN];
int has_eth_dst;
int has_eth_dst_mask;
__be16 vlan_id;
u32 tunnel_id;
enum rocker_of_dpa_table_id goto_tbl;
u32 group_id;
bool copy_to_cpu;
} bridge;
struct {
u32 in_pport;
u32 in_pport_mask;
u8 eth_src[ETH_ALEN];
u8 eth_src_mask[ETH_ALEN];
u8 eth_dst[ETH_ALEN];
u8 eth_dst_mask[ETH_ALEN];
__be16 eth_type;
__be16 vlan_id;
__be16 vlan_id_mask;
u8 ip_proto;
u8 ip_proto_mask;
u8 ip_tos;
u8 ip_tos_mask;
u32 group_id;
} acl;
};
};
struct rocker_flow_tbl_entry {
struct hlist_node entry;
u32 cmd;
u64 cookie;
struct rocker_flow_tbl_key key;
size_t key_len;
u32 key_crc32; /* key */
};
struct rocker_group_tbl_entry {
struct hlist_node entry;
u32 cmd;
u32 group_id; /* key */
u16 group_count;
u32 *group_ids;
union {
struct {
u8 pop_vlan;
} l2_interface;
struct {
u8 eth_src[ETH_ALEN];
u8 eth_dst[ETH_ALEN];
__be16 vlan_id;
u32 group_id;
} l2_rewrite;
struct {
u8 eth_src[ETH_ALEN];
u8 eth_dst[ETH_ALEN];
__be16 vlan_id;
bool ttl_check;
u32 group_id;
} l3_unicast;
};
};
struct rocker_fdb_tbl_entry {
struct hlist_node entry;
u32 key_crc32; /* key */
bool learned;
unsigned long touched;
struct rocker_fdb_tbl_key {
struct rocker_port *rocker_port;
u8 addr[ETH_ALEN];
__be16 vlan_id;
} key;
};
struct rocker_internal_vlan_tbl_entry {
struct hlist_node entry;
int ifindex; /* key */
u32 ref_count;
__be16 vlan_id;
};
struct rocker_neigh_tbl_entry {
struct hlist_node entry;
__be32 ip_addr; /* key */
struct net_device *dev;
u32 ref_count;
u32 index;
u8 eth_dst[ETH_ALEN];
bool ttl_check;
};
struct rocker_desc_info {
char *data; /* mapped */
size_t data_size;
size_t tlv_size;
struct rocker_desc *desc;
dma_addr_t mapaddr;
};
struct rocker_dma_ring_info {
size_t size;
u32 head;
u32 tail;
struct rocker_desc *desc; /* mapped */
dma_addr_t mapaddr;
struct rocker_desc_info *desc_info;
unsigned int type;
};
struct rocker;
enum {
ROCKER_CTRL_LINK_LOCAL_MCAST,
ROCKER_CTRL_LOCAL_ARP,
ROCKER_CTRL_IPV4_MCAST,
ROCKER_CTRL_IPV6_MCAST,
ROCKER_CTRL_DFLT_BRIDGING,
ROCKER_CTRL_DFLT_OVS,
ROCKER_CTRL_MAX,
};
#define ROCKER_INTERNAL_VLAN_ID_BASE 0x0f00
#define ROCKER_N_INTERNAL_VLANS 255
#define ROCKER_VLAN_BITMAP_LEN BITS_TO_LONGS(VLAN_N_VID)
#define ROCKER_INTERNAL_VLAN_BITMAP_LEN BITS_TO_LONGS(ROCKER_N_INTERNAL_VLANS)
struct rocker_port {
struct net_device *dev;
struct net_device *bridge_dev;
struct rocker *rocker;
unsigned int port_number;
u32 pport;
__be16 internal_vlan_id;
int stp_state;
u32 brport_flags;
unsigned long ageing_time;
bool ctrls[ROCKER_CTRL_MAX];
unsigned long vlan_bitmap[ROCKER_VLAN_BITMAP_LEN];
struct napi_struct napi_tx;
struct napi_struct napi_rx;
struct rocker_dma_ring_info tx_ring;
struct rocker_dma_ring_info rx_ring;
};
struct rocker {
struct pci_dev *pdev;
u8 __iomem *hw_addr;
struct msix_entry *msix_entries;
unsigned int port_count;
struct rocker_port **ports;
struct {
u64 id;
} hw;
spinlock_t cmd_ring_lock; /* for cmd ring accesses */
struct rocker_dma_ring_info cmd_ring;
struct rocker_dma_ring_info event_ring;
DECLARE_HASHTABLE(flow_tbl, 16);
spinlock_t flow_tbl_lock; /* for flow tbl accesses */
u64 flow_tbl_next_cookie;
DECLARE_HASHTABLE(group_tbl, 16);
spinlock_t group_tbl_lock; /* for group tbl accesses */
struct timer_list fdb_cleanup_timer;
DECLARE_HASHTABLE(fdb_tbl, 16);
spinlock_t fdb_tbl_lock; /* for fdb tbl accesses */
unsigned long internal_vlan_bitmap[ROCKER_INTERNAL_VLAN_BITMAP_LEN];
DECLARE_HASHTABLE(internal_vlan_tbl, 8);
spinlock_t internal_vlan_tbl_lock; /* for vlan tbl accesses */
DECLARE_HASHTABLE(neigh_tbl, 16);
spinlock_t neigh_tbl_lock; /* for neigh tbl accesses */
u32 neigh_tbl_next_index;
};
static const u8 zero_mac[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static const u8 ff_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
static const u8 ll_mac[ETH_ALEN] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
static const u8 ll_mask[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0 };
static const u8 mcast_mac[ETH_ALEN] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 };
static const u8 ipv4_mcast[ETH_ALEN] = { 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 };
static const u8 ipv4_mask[ETH_ALEN] = { 0xff, 0xff, 0xff, 0x80, 0x00, 0x00 };
static const u8 ipv6_mcast[ETH_ALEN] = { 0x33, 0x33, 0x00, 0x00, 0x00, 0x00 };
static const u8 ipv6_mask[ETH_ALEN] = { 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 };
/* Rocker priority levels for flow table entries. Higher
* priority match takes precedence over lower priority match.
*/
enum {
ROCKER_PRIORITY_UNKNOWN = 0,
ROCKER_PRIORITY_IG_PORT = 1,
ROCKER_PRIORITY_VLAN = 1,
ROCKER_PRIORITY_TERM_MAC_UCAST = 0,
ROCKER_PRIORITY_TERM_MAC_MCAST = 1,
ROCKER_PRIORITY_BRIDGING_VLAN_DFLT_EXACT = 1,
ROCKER_PRIORITY_BRIDGING_VLAN_DFLT_WILD = 2,
ROCKER_PRIORITY_BRIDGING_VLAN = 3,
ROCKER_PRIORITY_BRIDGING_TENANT_DFLT_EXACT = 1,
ROCKER_PRIORITY_BRIDGING_TENANT_DFLT_WILD = 2,
ROCKER_PRIORITY_BRIDGING_TENANT = 3,
ROCKER_PRIORITY_ACL_CTRL = 3,
ROCKER_PRIORITY_ACL_NORMAL = 2,
ROCKER_PRIORITY_ACL_DFLT = 1,
};
static bool rocker_vlan_id_is_internal(__be16 vlan_id)
{
u16 start = ROCKER_INTERNAL_VLAN_ID_BASE;
u16 end = 0xffe;
u16 _vlan_id = ntohs(vlan_id);
return (_vlan_id >= start && _vlan_id <= end);
}
static __be16 rocker_port_vid_to_vlan(const struct rocker_port *rocker_port,
u16 vid, bool *pop_vlan)
{
__be16 vlan_id;
if (pop_vlan)
*pop_vlan = false;
vlan_id = htons(vid);
if (!vlan_id) {
vlan_id = rocker_port->internal_vlan_id;
if (pop_vlan)
*pop_vlan = true;
}
return vlan_id;
}
static u16 rocker_port_vlan_to_vid(const struct rocker_port *rocker_port,
__be16 vlan_id)
{
if (rocker_vlan_id_is_internal(vlan_id))
return 0;
return ntohs(vlan_id);
}
static bool rocker_port_is_bridged(const struct rocker_port *rocker_port)
{
return rocker_port->bridge_dev &&
netif_is_bridge_master(rocker_port->bridge_dev);
}
static bool rocker_port_is_ovsed(const struct rocker_port *rocker_port)
{
return rocker_port->bridge_dev &&
netif_is_ovs_master(rocker_port->bridge_dev);
}
#define ROCKER_OP_FLAG_REMOVE BIT(0)
#define ROCKER_OP_FLAG_NOWAIT BIT(1)
#define ROCKER_OP_FLAG_LEARNED BIT(2)
#define ROCKER_OP_FLAG_REFRESH BIT(3)
static void *__rocker_port_mem_alloc(struct rocker_port *rocker_port,
struct switchdev_trans *trans, int flags,
size_t size)
{
struct switchdev_trans_item *elem = NULL;
gfp_t gfp_flags = (flags & ROCKER_OP_FLAG_NOWAIT) ?
GFP_ATOMIC : GFP_KERNEL;
/* If in transaction prepare phase, allocate the memory
* and enqueue it on a transaction. If in transaction
* commit phase, dequeue the memory from the transaction
* rather than re-allocating the memory. The idea is the
* driver code paths for prepare and commit are identical
* so the memory allocated in the prepare phase is the
* memory used in the commit phase.
*/
if (!trans) {
elem = kzalloc(size + sizeof(*elem), gfp_flags);
} else if (switchdev_trans_ph_prepare(trans)) {
elem = kzalloc(size + sizeof(*elem), gfp_flags);
if (!elem)
return NULL;
switchdev_trans_item_enqueue(trans, elem, kfree, elem);
} else {
elem = switchdev_trans_item_dequeue(trans);
}
return elem ? elem + 1 : NULL;
}
static void *rocker_port_kzalloc(struct rocker_port *rocker_port,
struct switchdev_trans *trans, int flags,
size_t size)
{
return __rocker_port_mem_alloc(rocker_port, trans, flags, size);
}
static void *rocker_port_kcalloc(struct rocker_port *rocker_port,
struct switchdev_trans *trans, int flags,
size_t n, size_t size)
{
return __rocker_port_mem_alloc(rocker_port, trans, flags, n * size);
}
static void rocker_port_kfree(struct switchdev_trans *trans, const void *mem)
{
struct switchdev_trans_item *elem;
/* Frees are ignored if in transaction prepare phase. The
* memory remains on the per-port list until freed in the
* commit phase.
*/
if (switchdev_trans_ph_prepare(trans))
return;
elem = (struct switchdev_trans_item *) mem - 1;
kfree(elem);
}
struct rocker_wait {
wait_queue_head_t wait;
bool done;
bool nowait;
};
static void rocker_wait_reset(struct rocker_wait *wait)
{
wait->done = false;
wait->nowait = false;
}
static void rocker_wait_init(struct rocker_wait *wait)
{
init_waitqueue_head(&wait->wait);
rocker_wait_reset(wait);
}
static struct rocker_wait *rocker_wait_create(struct rocker_port *rocker_port,
struct switchdev_trans *trans,
int flags)
{
struct rocker_wait *wait;
wait = rocker_port_kzalloc(rocker_port, trans, flags, sizeof(*wait));
if (!wait)
return NULL;
rocker_wait_init(wait);
return wait;
}
static void rocker_wait_destroy(struct switchdev_trans *trans,
struct rocker_wait *wait)
{
rocker_port_kfree(trans, wait);
}
static bool rocker_wait_event_timeout(struct rocker_wait *wait,
unsigned long timeout)
{
wait_event_timeout(wait->wait, wait->done, HZ / 10);
if (!wait->done)
return false;
return true;
}
static void rocker_wait_wake_up(struct rocker_wait *wait)
{
wait->done = true;
wake_up(&wait->wait);
}
static u32 rocker_msix_vector(const struct rocker *rocker, unsigned int vector)
{
return rocker->msix_entries[vector].vector;
}
static u32 rocker_msix_tx_vector(const struct rocker_port *rocker_port)
{
return rocker_msix_vector(rocker_port->rocker,
ROCKER_MSIX_VEC_TX(rocker_port->port_number));
}
static u32 rocker_msix_rx_vector(const struct rocker_port *rocker_port)
{
return rocker_msix_vector(rocker_port->rocker,
ROCKER_MSIX_VEC_RX(rocker_port->port_number));
}
#define rocker_write32(rocker, reg, val) \
writel((val), (rocker)->hw_addr + (ROCKER_ ## reg))
#define rocker_read32(rocker, reg) \
readl((rocker)->hw_addr + (ROCKER_ ## reg))
#define rocker_write64(rocker, reg, val) \
writeq((val), (rocker)->hw_addr + (ROCKER_ ## reg))
#define rocker_read64(rocker, reg) \
readq((rocker)->hw_addr + (ROCKER_ ## reg))
/*****************************
* HW basic testing functions
*****************************/
static int rocker_reg_test(const struct rocker *rocker)
{
const struct pci_dev *pdev = rocker->pdev;
u64 test_reg;
u64 rnd;
rnd = prandom_u32();
rnd >>= 1;
rocker_write32(rocker, TEST_REG, rnd);
test_reg = rocker_read32(rocker, TEST_REG);
if (test_reg != rnd * 2) {
dev_err(&pdev->dev, "unexpected 32bit register value %08llx, expected %08llx\n",
test_reg, rnd * 2);
return -EIO;
}
rnd = prandom_u32();
rnd <<= 31;
rnd |= prandom_u32();
rocker_write64(rocker, TEST_REG64, rnd);
test_reg = rocker_read64(rocker, TEST_REG64);
if (test_reg != rnd * 2) {
dev_err(&pdev->dev, "unexpected 64bit register value %16llx, expected %16llx\n",
test_reg, rnd * 2);
return -EIO;
}
return 0;
}
static int rocker_dma_test_one(const struct rocker *rocker,
struct rocker_wait *wait, u32 test_type,
dma_addr_t dma_handle, const unsigned char *buf,
const unsigned char *expect, size_t size)
{
const struct pci_dev *pdev = rocker->pdev;
int i;
rocker_wait_reset(wait);
rocker_write32(rocker, TEST_DMA_CTRL, test_type);
if (!rocker_wait_event_timeout(wait, HZ / 10)) {
dev_err(&pdev->dev, "no interrupt received within a timeout\n");
return -EIO;
}
for (i = 0; i < size; i++) {
if (buf[i] != expect[i]) {
dev_err(&pdev->dev, "unexpected memory content %02x at byte %x\n, %02x expected",
buf[i], i, expect[i]);
return -EIO;
}
}
return 0;
}
#define ROCKER_TEST_DMA_BUF_SIZE (PAGE_SIZE * 4)
#define ROCKER_TEST_DMA_FILL_PATTERN 0x96
static int rocker_dma_test_offset(const struct rocker *rocker,
struct rocker_wait *wait, int offset)
{
struct pci_dev *pdev = rocker->pdev;
unsigned char *alloc;
unsigned char *buf;
unsigned char *expect;
dma_addr_t dma_handle;
int i;
int err;
alloc = kzalloc(ROCKER_TEST_DMA_BUF_SIZE * 2 + offset,
GFP_KERNEL | GFP_DMA);
if (!alloc)
return -ENOMEM;
buf = alloc + offset;
expect = buf + ROCKER_TEST_DMA_BUF_SIZE;
dma_handle = pci_map_single(pdev, buf, ROCKER_TEST_DMA_BUF_SIZE,
PCI_DMA_BIDIRECTIONAL);
if (pci_dma_mapping_error(pdev, dma_handle)) {
err = -EIO;
goto free_alloc;
}
rocker_write64(rocker, TEST_DMA_ADDR, dma_handle);
rocker_write32(rocker, TEST_DMA_SIZE, ROCKER_TEST_DMA_BUF_SIZE);
memset(expect, ROCKER_TEST_DMA_FILL_PATTERN, ROCKER_TEST_DMA_BUF_SIZE);
err = rocker_dma_test_one(rocker, wait, ROCKER_TEST_DMA_CTRL_FILL,
dma_handle, buf, expect,
ROCKER_TEST_DMA_BUF_SIZE);
if (err)
goto unmap;
memset(expect, 0, ROCKER_TEST_DMA_BUF_SIZE);
err = rocker_dma_test_one(rocker, wait, ROCKER_TEST_DMA_CTRL_CLEAR,
dma_handle, buf, expect,
ROCKER_TEST_DMA_BUF_SIZE);
if (err)
goto unmap;
prandom_bytes(buf, ROCKER_TEST_DMA_BUF_SIZE);
for (i = 0; i < ROCKER_TEST_DMA_BUF_SIZE; i++)
expect[i] = ~buf[i];
err = rocker_dma_test_one(rocker, wait, ROCKER_TEST_DMA_CTRL_INVERT,
dma_handle, buf, expect,
ROCKER_TEST_DMA_BUF_SIZE);
if (err)
goto unmap;
unmap:
pci_unmap_single(pdev, dma_handle, ROCKER_TEST_DMA_BUF_SIZE,
PCI_DMA_BIDIRECTIONAL);
free_alloc:
kfree(alloc);
return err;
}
static int rocker_dma_test(const struct rocker *rocker,
struct rocker_wait *wait)
{
int i;
int err;
for (i = 0; i < 8; i++) {
err = rocker_dma_test_offset(rocker, wait, i);
if (err)
return err;
}
return 0;
}
static irqreturn_t rocker_test_irq_handler(int irq, void *dev_id)
{
struct rocker_wait *wait = dev_id;
rocker_wait_wake_up(wait);
return IRQ_HANDLED;
}
static int rocker_basic_hw_test(const struct rocker *rocker)
{
const struct pci_dev *pdev = rocker->pdev;
struct rocker_wait wait;
int err;
err = rocker_reg_test(rocker);
if (err) {
dev_err(&pdev->dev, "reg test failed\n");
return err;
}
err = request_irq(rocker_msix_vector(rocker, ROCKER_MSIX_VEC_TEST),
rocker_test_irq_handler, 0,
rocker_driver_name, &wait);
if (err) {
dev_err(&pdev->dev, "cannot assign test irq\n");
return err;
}
rocker_wait_init(&wait);
rocker_write32(rocker, TEST_IRQ, ROCKER_MSIX_VEC_TEST);
if (!rocker_wait_event_timeout(&wait, HZ / 10)) {
dev_err(&pdev->dev, "no interrupt received within a timeout\n");
err = -EIO;
goto free_irq;
}
err = rocker_dma_test(rocker, &wait);
if (err)
dev_err(&pdev->dev, "dma test failed\n");
free_irq:
free_irq(rocker_msix_vector(rocker, ROCKER_MSIX_VEC_TEST), &wait);
return err;
}
/******
* TLV
******/
#define ROCKER_TLV_ALIGNTO 8U
#define ROCKER_TLV_ALIGN(len) \
(((len) + ROCKER_TLV_ALIGNTO - 1) & ~(ROCKER_TLV_ALIGNTO - 1))
#define ROCKER_TLV_HDRLEN ROCKER_TLV_ALIGN(sizeof(struct rocker_tlv))
/* <------- ROCKER_TLV_HDRLEN -------> <--- ROCKER_TLV_ALIGN(payload) --->
* +-----------------------------+- - -+- - - - - - - - - - - - - - -+- - -+
* | Header | Pad | Payload | Pad |
* | (struct rocker_tlv) | ing | | ing |
* +-----------------------------+- - -+- - - - - - - - - - - - - - -+- - -+
* <--------------------------- tlv->len -------------------------->
*/
static struct rocker_tlv *rocker_tlv_next(const struct rocker_tlv *tlv,
int *remaining)
{
int totlen = ROCKER_TLV_ALIGN(tlv->len);
*remaining -= totlen;
return (struct rocker_tlv *) ((char *) tlv + totlen);
}
static int rocker_tlv_ok(const struct rocker_tlv *tlv, int remaining)
{
return remaining >= (int) ROCKER_TLV_HDRLEN &&
tlv->len >= ROCKER_TLV_HDRLEN &&
tlv->len <= remaining;
}
#define rocker_tlv_for_each(pos, head, len, rem) \
for (pos = head, rem = len; \
rocker_tlv_ok(pos, rem); \
pos = rocker_tlv_next(pos, &(rem)))
#define rocker_tlv_for_each_nested(pos, tlv, rem) \
rocker_tlv_for_each(pos, rocker_tlv_data(tlv), \
rocker_tlv_len(tlv), rem)
static int rocker_tlv_attr_size(int payload)
{
return ROCKER_TLV_HDRLEN + payload;
}
static int rocker_tlv_total_size(int payload)
{
return ROCKER_TLV_ALIGN(rocker_tlv_attr_size(payload));
}
static int rocker_tlv_padlen(int payload)
{
return rocker_tlv_total_size(payload) - rocker_tlv_attr_size(payload);
}
static int rocker_tlv_type(const struct rocker_tlv *tlv)
{
return tlv->type;
}
static void *rocker_tlv_data(const struct rocker_tlv *tlv)
{
return (char *) tlv + ROCKER_TLV_HDRLEN;
}
static int rocker_tlv_len(const struct rocker_tlv *tlv)
{
return tlv->len - ROCKER_TLV_HDRLEN;
}
static u8 rocker_tlv_get_u8(const struct rocker_tlv *tlv)
{
return *(u8 *) rocker_tlv_data(tlv);
}
static u16 rocker_tlv_get_u16(const struct rocker_tlv *tlv)
{
return *(u16 *) rocker_tlv_data(tlv);
}
static __be16 rocker_tlv_get_be16(const struct rocker_tlv *tlv)
{
return *(__be16 *) rocker_tlv_data(tlv);
}
static u32 rocker_tlv_get_u32(const struct rocker_tlv *tlv)
{
return *(u32 *) rocker_tlv_data(tlv);
}
static u64 rocker_tlv_get_u64(const struct rocker_tlv *tlv)
{
return *(u64 *) rocker_tlv_data(tlv);
}
static void rocker_tlv_parse(const struct rocker_tlv **tb, int maxtype,
const char *buf, int buf_len)
{
const struct rocker_tlv *tlv;
const struct rocker_tlv *head = (const struct rocker_tlv *) buf;
int rem;
memset(tb, 0, sizeof(struct rocker_tlv *) * (maxtype + 1));
rocker_tlv_for_each(tlv, head, buf_len, rem) {
u32 type = rocker_tlv_type(tlv);
if (type > 0 && type <= maxtype)
tb[type] = tlv;
}
}
static void rocker_tlv_parse_nested(const struct rocker_tlv **tb, int maxtype,
const struct rocker_tlv *tlv)
{
rocker_tlv_parse(tb, maxtype, rocker_tlv_data(tlv),
rocker_tlv_len(tlv));
}
static void rocker_tlv_parse_desc(const struct rocker_tlv **tb, int maxtype,
const struct rocker_desc_info *desc_info)
{
rocker_tlv_parse(tb, maxtype, desc_info->data,
desc_info->desc->tlv_size);
}
static struct rocker_tlv *rocker_tlv_start(struct rocker_desc_info *desc_info)
{
return (struct rocker_tlv *) ((char *) desc_info->data +
desc_info->tlv_size);
}
static int rocker_tlv_put(struct rocker_desc_info *desc_info,
int attrtype, int attrlen, const void *data)
{
int tail_room = desc_info->data_size - desc_info->tlv_size;
int total_size = rocker_tlv_total_size(attrlen);
struct rocker_tlv *tlv;
if (unlikely(tail_room < total_size))
return -EMSGSIZE;
tlv = rocker_tlv_start(desc_info);
desc_info->tlv_size += total_size;
tlv->type = attrtype;
tlv->len = rocker_tlv_attr_size(attrlen);
memcpy(rocker_tlv_data(tlv), data, attrlen);
memset((char *) tlv + tlv->len, 0, rocker_tlv_padlen(attrlen));
return 0;
}
static int rocker_tlv_put_u8(struct rocker_desc_info *desc_info,
int attrtype, u8 value)
{
return rocker_tlv_put(desc_info, attrtype, sizeof(u8), &value);
}
static int rocker_tlv_put_u16(struct rocker_desc_info *desc_info,
int attrtype, u16 value)
{
return rocker_tlv_put(desc_info, attrtype, sizeof(u16), &value);
}
static int rocker_tlv_put_be16(struct rocker_desc_info *desc_info,
int attrtype, __be16 value)
{
return rocker_tlv_put(desc_info, attrtype, sizeof(__be16), &value);
}
static int rocker_tlv_put_u32(struct rocker_desc_info *desc_info,
int attrtype, u32 value)
{
return rocker_tlv_put(desc_info, attrtype, sizeof(u32), &value);
}
static int rocker_tlv_put_be32(struct rocker_desc_info *desc_info,
int attrtype, __be32 value)
{
return rocker_tlv_put(desc_info, attrtype, sizeof(__be32), &value);
}
static int rocker_tlv_put_u64(struct rocker_desc_info *desc_info,
int attrtype, u64 value)
{
return rocker_tlv_put(desc_info, attrtype, sizeof(u64), &value);
}
static struct rocker_tlv *
rocker_tlv_nest_start(struct rocker_desc_info *desc_info, int attrtype)
{
struct rocker_tlv *start = rocker_tlv_start(desc_info);
if (rocker_tlv_put(desc_info, attrtype, 0, NULL) < 0)
return NULL;
return start;
}
static void rocker_tlv_nest_end(struct rocker_desc_info *desc_info,
struct rocker_tlv *start)
{
start->len = (char *) rocker_tlv_start(desc_info) - (char *) start;
}
static void rocker_tlv_nest_cancel(struct rocker_desc_info *desc_info,
const struct rocker_tlv *start)
{
desc_info->tlv_size = (const char *) start - desc_info->data;
}
/******************************************
* DMA rings and descriptors manipulations
******************************************/
static u32 __pos_inc(u32 pos, size_t limit)
{
return ++pos == limit ? 0 : pos;
}
static int rocker_desc_err(const struct rocker_desc_info *desc_info)
{
int err = desc_info->desc->comp_err & ~ROCKER_DMA_DESC_COMP_ERR_GEN;
switch (err) {
case ROCKER_OK:
return 0;
case -ROCKER_ENOENT:
return -ENOENT;
case -ROCKER_ENXIO:
return -ENXIO;
case -ROCKER_ENOMEM:
return -ENOMEM;
case -ROCKER_EEXIST:
return -EEXIST;
case -ROCKER_EINVAL:
return -EINVAL;
case -ROCKER_EMSGSIZE:
return -EMSGSIZE;
case -ROCKER_ENOTSUP:
return -EOPNOTSUPP;
case -ROCKER_ENOBUFS:
return -ENOBUFS;
}
return -EINVAL;
}
static void rocker_desc_gen_clear(const struct rocker_desc_info *desc_info)
{
desc_info->desc->comp_err &= ~ROCKER_DMA_DESC_COMP_ERR_GEN;
}
static bool rocker_desc_gen(const struct rocker_desc_info *desc_info)
{
u32 comp_err = desc_info->desc->comp_err;
return comp_err & ROCKER_DMA_DESC_COMP_ERR_GEN ? true : false;
}
static void *rocker_desc_cookie_ptr_get(const struct rocker_desc_info *desc_info)
{
return (void *)(uintptr_t)desc_info->desc->cookie;
}
static void rocker_desc_cookie_ptr_set(const struct rocker_desc_info *desc_info,
void *ptr)
{
desc_info->desc->cookie = (uintptr_t) ptr;
}
static struct rocker_desc_info *
rocker_desc_head_get(const struct rocker_dma_ring_info *info)
{
static struct rocker_desc_info *desc_info;
u32 head = __pos_inc(info->head, info->size);
desc_info = &info->desc_info[info->head];
if (head == info->tail)
return NULL; /* ring full */
desc_info->tlv_size = 0;
return desc_info;
}
static void rocker_desc_commit(const struct rocker_desc_info *desc_info)
{
desc_info->desc->buf_size = desc_info->data_size;
desc_info->desc->tlv_size = desc_info->tlv_size;
}
static void rocker_desc_head_set(const struct rocker *rocker,
struct rocker_dma_ring_info *info,
const struct rocker_desc_info *desc_info)
{
u32 head = __pos_inc(info->head, info->size);
BUG_ON(head == info->tail);
rocker_desc_commit(desc_info);
info->head = head;
rocker_write32(rocker, DMA_DESC_HEAD(info->type), head);
}
static struct rocker_desc_info *
rocker_desc_tail_get(struct rocker_dma_ring_info *info)
{
static struct rocker_desc_info *desc_info;
if (info->tail == info->head)
return NULL; /* nothing to be done between head and tail */
desc_info = &info->desc_info[info->tail];
if (!rocker_desc_gen(desc_info))
return NULL; /* gen bit not set, desc is not ready yet */
info->tail = __pos_inc(info->tail, info->size);
desc_info->tlv_size = desc_info->desc->tlv_size;
return desc_info;
}
static void rocker_dma_ring_credits_set(const struct rocker *rocker,
const struct rocker_dma_ring_info *info,
u32 credits)
{
if (credits)
rocker_write32(rocker, DMA_DESC_CREDITS(info->type), credits);
}
static unsigned long rocker_dma_ring_size_fix(size_t size)
{
return max(ROCKER_DMA_SIZE_MIN,
min(roundup_pow_of_two(size), ROCKER_DMA_SIZE_MAX));
}
static int rocker_dma_ring_create(const struct rocker *rocker,
unsigned int type,
size_t size,
struct rocker_dma_ring_info *info)
{
int i;
BUG_ON(size != rocker_dma_ring_size_fix(size));
info->size = size;
info->type = type;
info->head = 0;
info->tail = 0;
info->desc_info = kcalloc(info->size, sizeof(*info->desc_info),
GFP_KERNEL);
if (!info->desc_info)
return -ENOMEM;
info->desc = pci_alloc_consistent(rocker->pdev,
info->size * sizeof(*info->desc),
&info->mapaddr);
if (!info->desc) {
kfree(info->desc_info);
return -ENOMEM;
}
for (i = 0; i < info->size; i++)
info->desc_info[i].desc = &info->desc[i];
rocker_write32(rocker, DMA_DESC_CTRL(info->type),
ROCKER_DMA_DESC_CTRL_RESET);
rocker_write64(rocker, DMA_DESC_ADDR(info->type), info->mapaddr);
rocker_write32(rocker, DMA_DESC_SIZE(info->type), info->size);
return 0;
}
static void rocker_dma_ring_destroy(const struct rocker *rocker,
const struct rocker_dma_ring_info *info)
{
rocker_write64(rocker, DMA_DESC_ADDR(info->type), 0);
pci_free_consistent(rocker->pdev,
info->size * sizeof(struct rocker_desc),
info->desc, info->mapaddr);
kfree(info->desc_info);
}
static void rocker_dma_ring_pass_to_producer(const struct rocker *rocker,
struct rocker_dma_ring_info *info)
{
int i;
BUG_ON(info->head || info->tail);
/* When ring is consumer, we need to advance head for each desc.
* That tells hw that the desc is ready to be used by it.
*/
for (i = 0; i < info->size - 1; i++)
rocker_desc_head_set(rocker, info, &info->desc_info[i]);
rocker_desc_commit(&info->desc_info[i]);
}
static int rocker_dma_ring_bufs_alloc(const struct rocker *rocker,
const struct rocker_dma_ring_info *info,
int direction, size_t buf_size)
{
struct pci_dev *pdev = rocker->pdev;
int i;
int err;
for (i = 0; i < info->size; i++) {
struct rocker_desc_info *desc_info = &info->desc_info[i];
struct rocker_desc *desc = &info->desc[i];
dma_addr_t dma_handle;
char *buf;
buf = kzalloc(buf_size, GFP_KERNEL | GFP_DMA);
if (!buf) {
err = -ENOMEM;
goto rollback;
}
dma_handle = pci_map_single(pdev, buf, buf_size, direction);
if (pci_dma_mapping_error(pdev, dma_handle)) {
kfree(buf);
err = -EIO;
goto rollback;
}
desc_info->data = buf;
desc_info->data_size = buf_size;
dma_unmap_addr_set(desc_info, mapaddr, dma_handle);
desc->buf_addr = dma_handle;
desc->buf_size = buf_size;
}
return 0;
rollback:
for (i--; i >= 0; i--) {
const struct rocker_desc_info *desc_info = &info->desc_info[i];
pci_unmap_single(pdev, dma_unmap_addr(desc_info, mapaddr),
desc_info->data_size, direction);
kfree(desc_info->data);
}
return err;
}
static void rocker_dma_ring_bufs_free(const struct rocker *rocker,
const struct rocker_dma_ring_info *info,
int direction)
{
struct pci_dev *pdev = rocker->pdev;
int i;
for (i = 0; i < info->size; i++) {
const struct rocker_desc_info *desc_info = &info->desc_info[i];
struct rocker_desc *desc = &info->desc[i];
desc->buf_addr = 0;
desc->buf_size = 0;
pci_unmap_single(pdev, dma_unmap_addr(desc_info, mapaddr),
desc_info->data_size, direction);
kfree(desc_info->data);
}
}
static int rocker_dma_rings_init(struct rocker *rocker)
{
const struct pci_dev *pdev = rocker->pdev;
int err;
err = rocker_dma_ring_create(rocker, ROCKER_DMA_CMD,
ROCKER_DMA_CMD_DEFAULT_SIZE,
&rocker->cmd_ring);
if (err) {
dev_err(&pdev->dev, "failed to create command dma ring\n");
return err;
}
spin_lock_init(&rocker->cmd_ring_lock);
err = rocker_dma_ring_bufs_alloc(rocker, &rocker->cmd_ring,
PCI_DMA_BIDIRECTIONAL, PAGE_SIZE);
if (err) {
dev_err(&pdev->dev, "failed to alloc command dma ring buffers\n");
goto err_dma_cmd_ring_bufs_alloc;
}
err = rocker_dma_ring_create(rocker, ROCKER_DMA_EVENT,
ROCKER_DMA_EVENT_DEFAULT_SIZE,
&rocker->event_ring);
if (err) {
dev_err(&pdev->dev, "failed to create event dma ring\n");
goto err_dma_event_ring_create;
}
err = rocker_dma_ring_bufs_alloc(rocker, &rocker->event_ring,
PCI_DMA_FROMDEVICE, PAGE_SIZE);
if (err) {
dev_err(&pdev->dev, "failed to alloc event dma ring buffers\n");
goto err_dma_event_ring_bufs_alloc;
}
rocker_dma_ring_pass_to_producer(rocker, &rocker->event_ring);
return 0;
err_dma_event_ring_bufs_alloc:
rocker_dma_ring_destroy(rocker, &rocker->event_ring);
err_dma_event_ring_create:
rocker_dma_ring_bufs_free(rocker, &rocker->cmd_ring,
PCI_DMA_BIDIRECTIONAL);
err_dma_cmd_ring_bufs_alloc:
rocker_dma_ring_destroy(rocker, &rocker->cmd_ring);
return err;
}
static void rocker_dma_rings_fini(struct rocker *rocker)
{
rocker_dma_ring_bufs_free(rocker, &rocker->event_ring,
PCI_DMA_BIDIRECTIONAL);
rocker_dma_ring_destroy(rocker, &rocker->event_ring);
rocker_dma_ring_bufs_free(rocker, &rocker->cmd_ring,
PCI_DMA_BIDIRECTIONAL);
rocker_dma_ring_destroy(rocker, &rocker->cmd_ring);
}
static int rocker_dma_rx_ring_skb_map(const struct rocker_port *rocker_port,
struct rocker_desc_info *desc_info,
struct sk_buff *skb, size_t buf_len)
{
const struct rocker *rocker = rocker_port->rocker;
struct pci_dev *pdev = rocker->pdev;
dma_addr_t dma_handle;
dma_handle = pci_map_single(pdev, skb->data, buf_len,
PCI_DMA_FROMDEVICE);
if (pci_dma_mapping_error(pdev, dma_handle))
return -EIO;
if (rocker_tlv_put_u64(desc_info, ROCKER_TLV_RX_FRAG_ADDR, dma_handle))
goto tlv_put_failure;
if (rocker_tlv_put_u16(desc_info, ROCKER_TLV_RX_FRAG_MAX_LEN, buf_len))
goto tlv_put_failure;
return 0;
tlv_put_failure:
pci_unmap_single(pdev, dma_handle, buf_len, PCI_DMA_FROMDEVICE);
desc_info->tlv_size = 0;
return -EMSGSIZE;
}
static size_t rocker_port_rx_buf_len(const struct rocker_port *rocker_port)
{
return rocker_port->dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
}
static int rocker_dma_rx_ring_skb_alloc(const struct rocker_port *rocker_port,
struct rocker_desc_info *desc_info)
{
struct net_device *dev = rocker_port->dev;
struct sk_buff *skb;
size_t buf_len = rocker_port_rx_buf_len(rocker_port);
int err;
/* Ensure that hw will see tlv_size zero in case of an error.
* That tells hw to use another descriptor.
*/
rocker_desc_cookie_ptr_set(desc_info, NULL);
desc_info->tlv_size = 0;
skb = netdev_alloc_skb_ip_align(dev, buf_len);
if (!skb)
return -ENOMEM;
err = rocker_dma_rx_ring_skb_map(rocker_port, desc_info, skb, buf_len);
if (err) {
dev_kfree_skb_any(skb);
return err;
}
rocker_desc_cookie_ptr_set(desc_info, skb);
return 0;
}
static void rocker_dma_rx_ring_skb_unmap(const struct rocker *rocker,
const struct rocker_tlv **attrs)
{
struct pci_dev *pdev = rocker->pdev;
dma_addr_t dma_handle;
size_t len;
if (!attrs[ROCKER_TLV_RX_FRAG_ADDR] ||
!attrs[ROCKER_TLV_RX_FRAG_MAX_LEN])
return;
dma_handle = rocker_tlv_get_u64(attrs[ROCKER_TLV_RX_FRAG_ADDR]);
len = rocker_tlv_get_u16(attrs[ROCKER_TLV_RX_FRAG_MAX_LEN]);
pci_unmap_single(pdev, dma_handle, len, PCI_DMA_FROMDEVICE);
}
static void rocker_dma_rx_ring_skb_free(const struct rocker *rocker,
const struct rocker_desc_info *desc_info)
{
const struct rocker_tlv *attrs[ROCKER_TLV_RX_MAX + 1];
struct sk_buff *skb = rocker_desc_cookie_ptr_get(desc_info);
if (!skb)
return;
rocker_tlv_parse_desc(attrs, ROCKER_TLV_RX_MAX, desc_info);
rocker_dma_rx_ring_skb_unmap(rocker, attrs);
dev_kfree_skb_any(skb);
}
static int rocker_dma_rx_ring_skbs_alloc(const struct rocker_port *rocker_port)
{
const struct rocker_dma_ring_info *rx_ring = &rocker_port->rx_ring;
const struct rocker *rocker = rocker_port->rocker;
int i;
int err;
for (i = 0; i < rx_ring->size; i++) {
err = rocker_dma_rx_ring_skb_alloc(rocker_port,
&rx_ring->desc_info[i]);
if (err)
goto rollback;
}
return 0;
rollback:
for (i--; i >= 0; i--)
rocker_dma_rx_ring_skb_free(rocker, &rx_ring->desc_info[i]);
return err;
}
static void rocker_dma_rx_ring_skbs_free(const struct rocker_port *rocker_port)
{
const struct rocker_dma_ring_info *rx_ring = &rocker_port->rx_ring;
const struct rocker *rocker = rocker_port->rocker;
int i;
for (i = 0; i < rx_ring->size; i++)
rocker_dma_rx_ring_skb_free(rocker, &rx_ring->desc_info[i]);
}
static int rocker_port_dma_rings_init(struct rocker_port *rocker_port)
{
struct rocker *rocker = rocker_port->rocker;
int err;
err = rocker_dma_ring_create(rocker,
ROCKER_DMA_TX(rocker_port->port_number),
ROCKER_DMA_TX_DEFAULT_SIZE,
&rocker_port->tx_ring);
if (err) {
netdev_err(rocker_port->dev, "failed to create tx dma ring\n");
return err;
}
err = rocker_dma_ring_bufs_alloc(rocker, &rocker_port->tx_ring,
PCI_DMA_TODEVICE,
ROCKER_DMA_TX_DESC_SIZE);
if (err) {
netdev_err(rocker_port->dev, "failed to alloc tx dma ring buffers\n");
goto err_dma_tx_ring_bufs_alloc;
}
err = rocker_dma_ring_create(rocker,
ROCKER_DMA_RX(rocker_port->port_number),
ROCKER_DMA_RX_DEFAULT_SIZE,
&rocker_port->rx_ring);
if (err) {
netdev_err(rocker_port->dev, "failed to create rx dma ring\n");
goto err_dma_rx_ring_create;
}
err = rocker_dma_ring_bufs_alloc(rocker, &rocker_port->rx_ring,
PCI_DMA_BIDIRECTIONAL,
ROCKER_DMA_RX_DESC_SIZE);
if (err) {
netdev_err(rocker_port->dev, "failed to alloc rx dma ring buffers\n");
goto err_dma_rx_ring_bufs_alloc;
}
err = rocker_dma_rx_ring_skbs_alloc(rocker_port);
if (err) {
netdev_err(rocker_port->dev, "failed to alloc rx dma ring skbs\n");
goto err_dma_rx_ring_skbs_alloc;
}
rocker_dma_ring_pass_to_producer(rocker, &rocker_port->rx_ring);
return 0;
err_dma_rx_ring_skbs_alloc:
rocker_dma_ring_bufs_free(rocker, &rocker_port->rx_ring,
PCI_DMA_BIDIRECTIONAL);
err_dma_rx_ring_bufs_alloc:
rocker_dma_ring_destroy(rocker, &rocker_port->rx_ring);
err_dma_rx_ring_create:
rocker_dma_ring_bufs_free(rocker, &rocker_port->tx_ring,
PCI_DMA_TODEVICE);
err_dma_tx_ring_bufs_alloc:
rocker_dma_ring_destroy(rocker, &rocker_port->tx_ring);
return err;
}
static void rocker_port_dma_rings_fini(struct rocker_port *rocker_port)
{
struct rocker *rocker = rocker_port->rocker;
rocker_dma_rx_ring_skbs_free(rocker_port);
rocker_dma_ring_bufs_free(rocker, &rocker_port->rx_ring,
PCI_DMA_BIDIRECTIONAL);
rocker_dma_ring_destroy(rocker, &rocker_port->rx_ring);
rocker_dma_ring_bufs_free(rocker, &rocker_port->tx_ring,
PCI_DMA_TODEVICE);
rocker_dma_ring_destroy(rocker, &rocker_port->tx_ring);
}
static void rocker_port_set_enable(const struct rocker_port *rocker_port,
bool enable)
{
u64 val = rocker_read64(rocker_port->rocker, PORT_PHYS_ENABLE);
if (enable)
val |= 1ULL << rocker_port->pport;
else
val &= ~(1ULL << rocker_port->pport);
rocker_write64(rocker_port->rocker, PORT_PHYS_ENABLE, val);
}
/********************************
* Interrupt handler and helpers
********************************/
static irqreturn_t rocker_cmd_irq_handler(int irq, void *dev_id)
{
struct rocker *rocker = dev_id;
const struct rocker_desc_info *desc_info;
struct rocker_wait *wait;
u32 credits = 0;
spin_lock(&rocker->cmd_ring_lock);
while ((desc_info = rocker_desc_tail_get(&rocker->cmd_ring))) {
wait = rocker_desc_cookie_ptr_get(desc_info);
if (wait->nowait) {
rocker_desc_gen_clear(desc_info);
rocker_wait_destroy(NULL, wait);
} else {
rocker_wait_wake_up(wait);
}
credits++;
}
spin_unlock(&rocker->cmd_ring_lock);
rocker_dma_ring_credits_set(rocker, &rocker->cmd_ring, credits);
return IRQ_HANDLED;
}
static void rocker_port_link_up(const struct rocker_port *rocker_port)
{
netif_carrier_on(rocker_port->dev);
netdev_info(rocker_port->dev, "Link is up\n");
}
static void rocker_port_link_down(const struct rocker_port *rocker_port)
{
netif_carrier_off(rocker_port->dev);
netdev_info(rocker_port->dev, "Link is down\n");
}
static int rocker_event_link_change(const struct rocker *rocker,
const struct rocker_tlv *info)
{
const struct rocker_tlv *attrs[ROCKER_TLV_EVENT_LINK_CHANGED_MAX + 1];
unsigned int port_number;
bool link_up;
struct rocker_port *rocker_port;
rocker_tlv_parse_nested(attrs, ROCKER_TLV_EVENT_LINK_CHANGED_MAX, info);
if (!attrs[ROCKER_TLV_EVENT_LINK_CHANGED_PPORT] ||
!attrs[ROCKER_TLV_EVENT_LINK_CHANGED_LINKUP])
return -EIO;
port_number =
rocker_tlv_get_u32(attrs[ROCKER_TLV_EVENT_LINK_CHANGED_PPORT]) - 1;
link_up = rocker_tlv_get_u8(attrs[ROCKER_TLV_EVENT_LINK_CHANGED_LINKUP]);
if (port_number >= rocker->port_count)
return -EINVAL;
rocker_port = rocker->ports[port_number];
if (netif_carrier_ok(rocker_port->dev) != link_up) {
if (link_up)
rocker_port_link_up(rocker_port);
else
rocker_port_link_down(rocker_port);
}
return 0;
}
static int rocker_port_fdb(struct rocker_port *rocker_port,
struct switchdev_trans *trans,
const unsigned char *addr,
__be16 vlan_id, int flags);
static int rocker_event_mac_vlan_seen(const struct rocker *rocker,
const struct rocker_tlv *info)
{
const struct rocker_tlv *attrs[ROCKER_TLV_EVENT_MAC_VLAN_MAX + 1];
unsigned int port_number;
struct rocker_port *rocker_port;
const unsigned char *addr;
int flags = ROCKER_OP_FLAG_NOWAIT | ROCKER_OP_FLAG_LEARNED;
__be16 vlan_id;
rocker_tlv_parse_nested(attrs, ROCKER_TLV_EVENT_MAC_VLAN_MAX, info);
if (!attrs[ROCKER_TLV_EVENT_MAC_VLAN_PPORT] ||
!attrs[ROCKER_TLV_EVENT_MAC_VLAN_MAC] ||
!attrs[ROCKER_TLV_EVENT_MAC_VLAN_VLAN_ID])
return -EIO;
port_number =
rocker_tlv_get_u32(attrs[ROCKER_TLV_EVENT_MAC_VLAN_PPORT]) - 1;
addr = rocker_tlv_data(attrs[ROCKER_TLV_EVENT_MAC_VLAN_MAC]);
vlan_id = rocker_tlv_get_be16(attrs[ROCKER_TLV_EVENT_MAC_VLAN_VLAN_ID]);
if (port_number >= rocker->port_count)
return -EINVAL;
rocker_port = rocker->ports[port_number];
if (rocker_port->stp_state != BR_STATE_LEARNING &&
rocker_port->stp_state != BR_STATE_FORWARDING)
return 0;
return rocker_port_fdb(rocker_port, NULL, addr, vlan_id, flags);
}
static int rocker_event_process(const struct rocker *rocker,
const struct rocker_desc_info *desc_info)
{
const struct rocker_tlv *attrs[ROCKER_TLV_EVENT_MAX + 1];
const struct rocker_tlv *info;
u16 type;
rocker_tlv_parse_desc(attrs, ROCKER_TLV_EVENT_MAX, desc_info);
if (!attrs[ROCKER_TLV_EVENT_TYPE] ||
!attrs[ROCKER_TLV_EVENT_INFO])
return -EIO;
type = rocker_tlv_get_u16(attrs[ROCKER_TLV_EVENT_TYPE]);
info = attrs[ROCKER_TLV_EVENT_INFO];
switch (type) {
case ROCKER_TLV_EVENT_TYPE_LINK_CHANGED:
return rocker_event_link_change(rocker, info);
case ROCKER_TLV_EVENT_TYPE_MAC_VLAN_SEEN:
return rocker_event_mac_vlan_seen(rocker, info);
}
return -EOPNOTSUPP;
}
static irqreturn_t rocker_event_irq_handler(int irq, void *dev_id)
{
struct rocker *rocker = dev_id;
const struct pci_dev *pdev = rocker->pdev;
const struct rocker_desc_info *desc_info;
u32 credits = 0;
int err;
while ((desc_info = rocker_desc_tail_get(&rocker->event_ring))) {
err = rocker_desc_err(desc_info);
if (err) {
dev_err(&pdev->dev, "event desc received with err %d\n",
err);
} else {
err = rocker_event_process(rocker, desc_info);
if (err)
dev_err(&pdev->dev, "event processing failed with err %d\n",
err);
}
rocker_desc_gen_clear(desc_info);
rocker_desc_head_set(rocker, &rocker->event_ring, desc_info);
credits++;
}
rocker_dma_ring_credits_set(rocker, &rocker->event_ring, credits);
return IRQ_HANDLED;
}
static irqreturn_t rocker_tx_irq_handler(int irq, void *dev_id)
{
struct rocker_port *rocker_port = dev_id;
napi_schedule(&rocker_port->napi_tx);
return IRQ_HANDLED;
}
static irqreturn_t rocker_rx_irq_handler(int irq, void *dev_id)
{
struct rocker_port *rocker_port = dev_id;
napi_schedule(&rocker_port->napi_rx);
return IRQ_HANDLED;
}
/********************
* Command interface
********************/
typedef int (*rocker_cmd_prep_cb_t)(const struct rocker_port *rocker_port,
struct rocker_desc_info *desc_info,
void *priv);
typedef int (*rocker_cmd_proc_cb_t)(const struct rocker_port *rocker_port,
const struct rocker_desc_info *desc_info,
void *priv);
static int rocker_cmd_exec(struct rocker_port *rocker_port,
struct switchdev_trans *trans, int flags,
rocker_cmd_prep_cb_t prepare, void *prepare_priv,
rocker_cmd_proc_cb_t process, void *process_priv)
{
struct rocker *rocker = rocker_port->rocker;
struct rocker_desc_info *desc_info;
struct rocker_wait *wait;
bool nowait = !!(flags & ROCKER_OP_FLAG_NOWAIT);
unsigned long lock_flags;
int err;
wait = rocker_wait_create(rocker_port, trans, flags);
if (!wait)
return -ENOMEM;
wait->nowait = nowait;
spin_lock_irqsave(&rocker->cmd_ring_lock, lock_flags);
desc_info = rocker_desc_head_get(&rocker->cmd_ring);
if (!desc_info) {
spin_unlock_irqrestore(&rocker->cmd_ring_lock, lock_flags);
err = -EAGAIN;
goto out;
}
err = prepare(rocker_port, desc_info, prepare_priv);
if (err) {
spin_unlock_irqrestore(&rocker->cmd_ring_lock, lock_flags);
goto out;
}
rocker_desc_cookie_ptr_set(desc_info, wait);
if (!switchdev_trans_ph_prepare(trans))
rocker_desc_head_set(rocker, &rocker->cmd_ring, desc_info);
spin_unlock_irqrestore(&rocker->cmd_ring_lock, lock_flags);
if (nowait)
return 0;
if (!switchdev_trans_ph_prepare(trans))
if (!rocker_wait_event_timeout(wait, HZ / 10))
return -EIO;
err = rocker_desc_err(desc_info);
if (err)
return err;
if (process)
err = process(rocker_port, desc_info, process_priv);
rocker_desc_gen_clear(desc_info);
out:
rocker_wait_destroy(trans, wait);
return err;
}
static int
rocker_cmd_get_port_settings_prep(const struct rocker_port *rocker_port,
struct rocker_desc_info *desc_info,
void *priv)
{
struct rocker_tlv *cmd_info;
if (rocker_tlv_put_u16(desc_info, ROCKER_TLV_CMD_TYPE,
ROCKER_TLV_CMD_TYPE_GET_PORT_SETTINGS))
return -EMSGSIZE;
cmd_info = rocker_tlv_nest_start(desc_info, ROCKER_TLV_CMD_INFO);
if (!cmd_info)
return -EMSGSIZE;
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_CMD_PORT_SETTINGS_PPORT,
rocker_port->pport))
return -EMSGSIZE;
rocker_tlv_nest_end(desc_info, cmd_info);
return 0;
}
static int
rocker_cmd_get_port_settings_ethtool_proc(const struct rocker_port *rocker_port,
const struct rocker_desc_info *desc_info,
void *priv)
{
struct ethtool_cmd *ecmd = priv;
const struct rocker_tlv *attrs[ROCKER_TLV_CMD_MAX + 1];
const struct rocker_tlv *info_attrs[ROCKER_TLV_CMD_PORT_SETTINGS_MAX + 1];
u32 speed;
u8 duplex;
u8 autoneg;
rocker_tlv_parse_desc(attrs, ROCKER_TLV_CMD_MAX, desc_info);
if (!attrs[ROCKER_TLV_CMD_INFO])
return -EIO;
rocker_tlv_parse_nested(info_attrs, ROCKER_TLV_CMD_PORT_SETTINGS_MAX,
attrs[ROCKER_TLV_CMD_INFO]);
if (!info_attrs[ROCKER_TLV_CMD_PORT_SETTINGS_SPEED] ||
!info_attrs[ROCKER_TLV_CMD_PORT_SETTINGS_DUPLEX] ||
!info_attrs[ROCKER_TLV_CMD_PORT_SETTINGS_AUTONEG])
return -EIO;
speed = rocker_tlv_get_u32(info_attrs[ROCKER_TLV_CMD_PORT_SETTINGS_SPEED]);
duplex = rocker_tlv_get_u8(info_attrs[ROCKER_TLV_CMD_PORT_SETTINGS_DUPLEX]);
autoneg = rocker_tlv_get_u8(info_attrs[ROCKER_TLV_CMD_PORT_SETTINGS_AUTONEG]);
ecmd->transceiver = XCVR_INTERNAL;
ecmd->supported = SUPPORTED_TP;
ecmd->phy_address = 0xff;
ecmd->port = PORT_TP;
ethtool_cmd_speed_set(ecmd, speed);
ecmd->duplex = duplex ? DUPLEX_FULL : DUPLEX_HALF;
ecmd->autoneg = autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE;
return 0;
}
static int
rocker_cmd_get_port_settings_macaddr_proc(const struct rocker_port *rocker_port,
const struct rocker_desc_info *desc_info,
void *priv)
{
unsigned char *macaddr = priv;
const struct rocker_tlv *attrs[ROCKER_TLV_CMD_MAX + 1];
const struct rocker_tlv *info_attrs[ROCKER_TLV_CMD_PORT_SETTINGS_MAX + 1];
const struct rocker_tlv *attr;
rocker_tlv_parse_desc(attrs, ROCKER_TLV_CMD_MAX, desc_info);
if (!attrs[ROCKER_TLV_CMD_INFO])
return -EIO;
rocker_tlv_parse_nested(info_attrs, ROCKER_TLV_CMD_PORT_SETTINGS_MAX,
attrs[ROCKER_TLV_CMD_INFO]);
attr = info_attrs[ROCKER_TLV_CMD_PORT_SETTINGS_MACADDR];
if (!attr)
return -EIO;
if (rocker_tlv_len(attr) != ETH_ALEN)
return -EINVAL;
ether_addr_copy(macaddr, rocker_tlv_data(attr));
return 0;
}
struct port_name {
char *buf;
size_t len;
};
static int
rocker_cmd_get_port_settings_phys_name_proc(const struct rocker_port *rocker_port,
const struct rocker_desc_info *desc_info,
void *priv)
{
const struct rocker_tlv *info_attrs[ROCKER_TLV_CMD_PORT_SETTINGS_MAX + 1];
const struct rocker_tlv *attrs[ROCKER_TLV_CMD_MAX + 1];
struct port_name *name = priv;
const struct rocker_tlv *attr;
size_t i, j, len;
const char *str;
rocker_tlv_parse_desc(attrs, ROCKER_TLV_CMD_MAX, desc_info);
if (!attrs[ROCKER_TLV_CMD_INFO])
return -EIO;
rocker_tlv_parse_nested(info_attrs, ROCKER_TLV_CMD_PORT_SETTINGS_MAX,
attrs[ROCKER_TLV_CMD_INFO]);
attr = info_attrs[ROCKER_TLV_CMD_PORT_SETTINGS_PHYS_NAME];
if (!attr)
return -EIO;
len = min_t(size_t, rocker_tlv_len(attr), name->len);
str = rocker_tlv_data(attr);
/* make sure name only contains alphanumeric characters */
for (i = j = 0; i < len; ++i) {
if (isalnum(str[i])) {
name->buf[j] = str[i];
j++;
}
}
if (j == 0)
return -EIO;
name->buf[j] = '\0';
return 0;
}
static int
rocker_cmd_set_port_settings_ethtool_prep(const struct rocker_port *rocker_port,
struct rocker_desc_info *desc_info,
void *priv)
{
struct ethtool_cmd *ecmd = priv;
struct rocker_tlv *cmd_info;
if (rocker_tlv_put_u16(desc_info, ROCKER_TLV_CMD_TYPE,
ROCKER_TLV_CMD_TYPE_SET_PORT_SETTINGS))
return -EMSGSIZE;
cmd_info = rocker_tlv_nest_start(desc_info, ROCKER_TLV_CMD_INFO);
if (!cmd_info)
return -EMSGSIZE;
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_CMD_PORT_SETTINGS_PPORT,
rocker_port->pport))
return -EMSGSIZE;
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_CMD_PORT_SETTINGS_SPEED,
ethtool_cmd_speed(ecmd)))
return -EMSGSIZE;
if (rocker_tlv_put_u8(desc_info, ROCKER_TLV_CMD_PORT_SETTINGS_DUPLEX,
ecmd->duplex))
return -EMSGSIZE;
if (rocker_tlv_put_u8(desc_info, ROCKER_TLV_CMD_PORT_SETTINGS_AUTONEG,
ecmd->autoneg))
return -EMSGSIZE;
rocker_tlv_nest_end(desc_info, cmd_info);
return 0;
}
static int
rocker_cmd_set_port_settings_macaddr_prep(const struct rocker_port *rocker_port,
struct rocker_desc_info *desc_info,
void *priv)
{
const unsigned char *macaddr = priv;
struct rocker_tlv *cmd_info;
if (rocker_tlv_put_u16(desc_info, ROCKER_TLV_CMD_TYPE,
ROCKER_TLV_CMD_TYPE_SET_PORT_SETTINGS))
return -EMSGSIZE;
cmd_info = rocker_tlv_nest_start(desc_info, ROCKER_TLV_CMD_INFO);
if (!cmd_info)
return -EMSGSIZE;
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_CMD_PORT_SETTINGS_PPORT,
rocker_port->pport))
return -EMSGSIZE;
if (rocker_tlv_put(desc_info, ROCKER_TLV_CMD_PORT_SETTINGS_MACADDR,
ETH_ALEN, macaddr))
return -EMSGSIZE;
rocker_tlv_nest_end(desc_info, cmd_info);
return 0;
}
static int
rocker_cmd_set_port_settings_mtu_prep(const struct rocker_port *rocker_port,
struct rocker_desc_info *desc_info,
void *priv)
{
int mtu = *(int *)priv;
struct rocker_tlv *cmd_info;
if (rocker_tlv_put_u16(desc_info, ROCKER_TLV_CMD_TYPE,
ROCKER_TLV_CMD_TYPE_SET_PORT_SETTINGS))
return -EMSGSIZE;
cmd_info = rocker_tlv_nest_start(desc_info, ROCKER_TLV_CMD_INFO);
if (!cmd_info)
return -EMSGSIZE;
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_CMD_PORT_SETTINGS_PPORT,
rocker_port->pport))
return -EMSGSIZE;
if (rocker_tlv_put_u16(desc_info, ROCKER_TLV_CMD_PORT_SETTINGS_MTU,
mtu))
return -EMSGSIZE;
rocker_tlv_nest_end(desc_info, cmd_info);
return 0;
}
static int
rocker_cmd_set_port_learning_prep(const struct rocker_port *rocker_port,
struct rocker_desc_info *desc_info,
void *priv)
{
struct rocker_tlv *cmd_info;
if (rocker_tlv_put_u16(desc_info, ROCKER_TLV_CMD_TYPE,
ROCKER_TLV_CMD_TYPE_SET_PORT_SETTINGS))
return -EMSGSIZE;
cmd_info = rocker_tlv_nest_start(desc_info, ROCKER_TLV_CMD_INFO);
if (!cmd_info)
return -EMSGSIZE;
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_CMD_PORT_SETTINGS_PPORT,
rocker_port->pport))
return -EMSGSIZE;
if (rocker_tlv_put_u8(desc_info, ROCKER_TLV_CMD_PORT_SETTINGS_LEARNING,
!!(rocker_port->brport_flags & BR_LEARNING)))
return -EMSGSIZE;
rocker_tlv_nest_end(desc_info, cmd_info);
return 0;
}
static int rocker_cmd_get_port_settings_ethtool(struct rocker_port *rocker_port,
struct ethtool_cmd *ecmd)
{
return rocker_cmd_exec(rocker_port, NULL, 0,
rocker_cmd_get_port_settings_prep, NULL,
rocker_cmd_get_port_settings_ethtool_proc,
ecmd);
}
static int rocker_cmd_get_port_settings_macaddr(struct rocker_port *rocker_port,
unsigned char *macaddr)
{
return rocker_cmd_exec(rocker_port, NULL, 0,
rocker_cmd_get_port_settings_prep, NULL,
rocker_cmd_get_port_settings_macaddr_proc,
macaddr);
}
static int rocker_cmd_set_port_settings_ethtool(struct rocker_port *rocker_port,
struct ethtool_cmd *ecmd)
{
return rocker_cmd_exec(rocker_port, NULL, 0,
rocker_cmd_set_port_settings_ethtool_prep,
ecmd, NULL, NULL);
}
static int rocker_cmd_set_port_settings_macaddr(struct rocker_port *rocker_port,
unsigned char *macaddr)
{
return rocker_cmd_exec(rocker_port, NULL, 0,
rocker_cmd_set_port_settings_macaddr_prep,
macaddr, NULL, NULL);
}
static int rocker_cmd_set_port_settings_mtu(struct rocker_port *rocker_port,
int mtu)
{
return rocker_cmd_exec(rocker_port, NULL, 0,
rocker_cmd_set_port_settings_mtu_prep,
&mtu, NULL, NULL);
}
static int rocker_port_set_learning(struct rocker_port *rocker_port,
struct switchdev_trans *trans)
{
return rocker_cmd_exec(rocker_port, trans, 0,
rocker_cmd_set_port_learning_prep,
NULL, NULL, NULL);
}
static int
rocker_cmd_flow_tbl_add_ig_port(struct rocker_desc_info *desc_info,
const struct rocker_flow_tbl_entry *entry)
{
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_OF_DPA_IN_PPORT,
entry->key.ig_port.in_pport))
return -EMSGSIZE;
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_OF_DPA_IN_PPORT_MASK,
entry->key.ig_port.in_pport_mask))
return -EMSGSIZE;
if (rocker_tlv_put_u16(desc_info, ROCKER_TLV_OF_DPA_GOTO_TABLE_ID,
entry->key.ig_port.goto_tbl))
return -EMSGSIZE;
return 0;
}
static int
rocker_cmd_flow_tbl_add_vlan(struct rocker_desc_info *desc_info,
const struct rocker_flow_tbl_entry *entry)
{
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_OF_DPA_IN_PPORT,
entry->key.vlan.in_pport))
return -EMSGSIZE;
if (rocker_tlv_put_be16(desc_info, ROCKER_TLV_OF_DPA_VLAN_ID,
entry->key.vlan.vlan_id))
return -EMSGSIZE;
if (rocker_tlv_put_be16(desc_info, ROCKER_TLV_OF_DPA_VLAN_ID_MASK,
entry->key.vlan.vlan_id_mask))
return -EMSGSIZE;
if (rocker_tlv_put_u16(desc_info, ROCKER_TLV_OF_DPA_GOTO_TABLE_ID,
entry->key.vlan.goto_tbl))
return -EMSGSIZE;
if (entry->key.vlan.untagged &&
rocker_tlv_put_be16(desc_info, ROCKER_TLV_OF_DPA_NEW_VLAN_ID,
entry->key.vlan.new_vlan_id))
return -EMSGSIZE;
return 0;
}
static int
rocker_cmd_flow_tbl_add_term_mac(struct rocker_desc_info *desc_info,
const struct rocker_flow_tbl_entry *entry)
{
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_OF_DPA_IN_PPORT,
entry->key.term_mac.in_pport))
return -EMSGSIZE;
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_OF_DPA_IN_PPORT_MASK,
entry->key.term_mac.in_pport_mask))
return -EMSGSIZE;
if (rocker_tlv_put_be16(desc_info, ROCKER_TLV_OF_DPA_ETHERTYPE,
entry->key.term_mac.eth_type))
return -EMSGSIZE;
if (rocker_tlv_put(desc_info, ROCKER_TLV_OF_DPA_DST_MAC,
ETH_ALEN, entry->key.term_mac.eth_dst))
return -EMSGSIZE;
if (rocker_tlv_put(desc_info, ROCKER_TLV_OF_DPA_DST_MAC_MASK,
ETH_ALEN, entry->key.term_mac.eth_dst_mask))
return -EMSGSIZE;
if (rocker_tlv_put_be16(desc_info, ROCKER_TLV_OF_DPA_VLAN_ID,
entry->key.term_mac.vlan_id))
return -EMSGSIZE;
if (rocker_tlv_put_be16(desc_info, ROCKER_TLV_OF_DPA_VLAN_ID_MASK,
entry->key.term_mac.vlan_id_mask))
return -EMSGSIZE;
if (rocker_tlv_put_u16(desc_info, ROCKER_TLV_OF_DPA_GOTO_TABLE_ID,
entry->key.term_mac.goto_tbl))
return -EMSGSIZE;
if (entry->key.term_mac.copy_to_cpu &&
rocker_tlv_put_u8(desc_info, ROCKER_TLV_OF_DPA_COPY_CPU_ACTION,
entry->key.term_mac.copy_to_cpu))
return -EMSGSIZE;
return 0;
}
static int
rocker_cmd_flow_tbl_add_ucast_routing(struct rocker_desc_info *desc_info,
const struct rocker_flow_tbl_entry *entry)
{
if (rocker_tlv_put_be16(desc_info, ROCKER_TLV_OF_DPA_ETHERTYPE,
entry->key.ucast_routing.eth_type))
return -EMSGSIZE;
if (rocker_tlv_put_be32(desc_info, ROCKER_TLV_OF_DPA_DST_IP,
entry->key.ucast_routing.dst4))
return -EMSGSIZE;
if (rocker_tlv_put_be32(desc_info, ROCKER_TLV_OF_DPA_DST_IP_MASK,
entry->key.ucast_routing.dst4_mask))
return -EMSGSIZE;
if (rocker_tlv_put_u16(desc_info, ROCKER_TLV_OF_DPA_GOTO_TABLE_ID,
entry->key.ucast_routing.goto_tbl))
return -EMSGSIZE;
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_OF_DPA_GROUP_ID,
entry->key.ucast_routing.group_id))
return -EMSGSIZE;
return 0;
}
static int
rocker_cmd_flow_tbl_add_bridge(struct rocker_desc_info *desc_info,
const struct rocker_flow_tbl_entry *entry)
{
if (entry->key.bridge.has_eth_dst &&
rocker_tlv_put(desc_info, ROCKER_TLV_OF_DPA_DST_MAC,
ETH_ALEN, entry->key.bridge.eth_dst))
return -EMSGSIZE;
if (entry->key.bridge.has_eth_dst_mask &&
rocker_tlv_put(desc_info, ROCKER_TLV_OF_DPA_DST_MAC_MASK,
ETH_ALEN, entry->key.bridge.eth_dst_mask))
return -EMSGSIZE;
if (entry->key.bridge.vlan_id &&
rocker_tlv_put_be16(desc_info, ROCKER_TLV_OF_DPA_VLAN_ID,
entry->key.bridge.vlan_id))
return -EMSGSIZE;
if (entry->key.bridge.tunnel_id &&
rocker_tlv_put_u32(desc_info, ROCKER_TLV_OF_DPA_TUNNEL_ID,
entry->key.bridge.tunnel_id))
return -EMSGSIZE;
if (rocker_tlv_put_u16(desc_info, ROCKER_TLV_OF_DPA_GOTO_TABLE_ID,
entry->key.bridge.goto_tbl))
return -EMSGSIZE;
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_OF_DPA_GROUP_ID,
entry->key.bridge.group_id))
return -EMSGSIZE;
if (entry->key.bridge.copy_to_cpu &&
rocker_tlv_put_u8(desc_info, ROCKER_TLV_OF_DPA_COPY_CPU_ACTION,
entry->key.bridge.copy_to_cpu))
return -EMSGSIZE;
return 0;
}
static int
rocker_cmd_flow_tbl_add_acl(struct rocker_desc_info *desc_info,
const struct rocker_flow_tbl_entry *entry)
{
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_OF_DPA_IN_PPORT,
entry->key.acl.in_pport))
return -EMSGSIZE;
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_OF_DPA_IN_PPORT_MASK,
entry->key.acl.in_pport_mask))
return -EMSGSIZE;
if (rocker_tlv_put(desc_info, ROCKER_TLV_OF_DPA_SRC_MAC,
ETH_ALEN, entry->key.acl.eth_src))
return -EMSGSIZE;
if (rocker_tlv_put(desc_info, ROCKER_TLV_OF_DPA_SRC_MAC_MASK,
ETH_ALEN, entry->key.acl.eth_src_mask))
return -EMSGSIZE;
if (rocker_tlv_put(desc_info, ROCKER_TLV_OF_DPA_DST_MAC,
ETH_ALEN, entry->key.acl.eth_dst))
return -EMSGSIZE;
if (rocker_tlv_put(desc_info, ROCKER_TLV_OF_DPA_DST_MAC_MASK,
ETH_ALEN, entry->key.acl.eth_dst_mask))
return -EMSGSIZE;
if (rocker_tlv_put_be16(desc_info, ROCKER_TLV_OF_DPA_ETHERTYPE,
entry->key.acl.eth_type))
return -EMSGSIZE;
if (rocker_tlv_put_be16(desc_info, ROCKER_TLV_OF_DPA_VLAN_ID,
entry->key.acl.vlan_id))
return -EMSGSIZE;
if (rocker_tlv_put_be16(desc_info, ROCKER_TLV_OF_DPA_VLAN_ID_MASK,
entry->key.acl.vlan_id_mask))
return -EMSGSIZE;
switch (ntohs(entry->key.acl.eth_type)) {
case ETH_P_IP:
case ETH_P_IPV6:
if (rocker_tlv_put_u8(desc_info, ROCKER_TLV_OF_DPA_IP_PROTO,
entry->key.acl.ip_proto))
return -EMSGSIZE;
if (rocker_tlv_put_u8(desc_info,
ROCKER_TLV_OF_DPA_IP_PROTO_MASK,
entry->key.acl.ip_proto_mask))
return -EMSGSIZE;
if (rocker_tlv_put_u8(desc_info, ROCKER_TLV_OF_DPA_IP_DSCP,
entry->key.acl.ip_tos & 0x3f))
return -EMSGSIZE;
if (rocker_tlv_put_u8(desc_info,
ROCKER_TLV_OF_DPA_IP_DSCP_MASK,
entry->key.acl.ip_tos_mask & 0x3f))
return -EMSGSIZE;
if (rocker_tlv_put_u8(desc_info, ROCKER_TLV_OF_DPA_IP_ECN,
(entry->key.acl.ip_tos & 0xc0) >> 6))
return -EMSGSIZE;
if (rocker_tlv_put_u8(desc_info,
ROCKER_TLV_OF_DPA_IP_ECN_MASK,
(entry->key.acl.ip_tos_mask & 0xc0) >> 6))
return -EMSGSIZE;
break;
}
if (entry->key.acl.group_id != ROCKER_GROUP_NONE &&
rocker_tlv_put_u32(desc_info, ROCKER_TLV_OF_DPA_GROUP_ID,
entry->key.acl.group_id))
return -EMSGSIZE;
return 0;
}
static int rocker_cmd_flow_tbl_add(const struct rocker_port *rocker_port,
struct rocker_desc_info *desc_info,
void *priv)
{
const struct rocker_flow_tbl_entry *entry = priv;
struct rocker_tlv *cmd_info;
int err = 0;
if (rocker_tlv_put_u16(desc_info, ROCKER_TLV_CMD_TYPE, entry->cmd))
return -EMSGSIZE;
cmd_info = rocker_tlv_nest_start(desc_info, ROCKER_TLV_CMD_INFO);
if (!cmd_info)
return -EMSGSIZE;
if (rocker_tlv_put_u16(desc_info, ROCKER_TLV_OF_DPA_TABLE_ID,
entry->key.tbl_id))
return -EMSGSIZE;
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_OF_DPA_PRIORITY,
entry->key.priority))
return -EMSGSIZE;
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_OF_DPA_HARDTIME, 0))
return -EMSGSIZE;
if (rocker_tlv_put_u64(desc_info, ROCKER_TLV_OF_DPA_COOKIE,
entry->cookie))
return -EMSGSIZE;
switch (entry->key.tbl_id) {
case ROCKER_OF_DPA_TABLE_ID_INGRESS_PORT:
err = rocker_cmd_flow_tbl_add_ig_port(desc_info, entry);
break;
case ROCKER_OF_DPA_TABLE_ID_VLAN:
err = rocker_cmd_flow_tbl_add_vlan(desc_info, entry);
break;
case ROCKER_OF_DPA_TABLE_ID_TERMINATION_MAC:
err = rocker_cmd_flow_tbl_add_term_mac(desc_info, entry);
break;
case ROCKER_OF_DPA_TABLE_ID_UNICAST_ROUTING:
err = rocker_cmd_flow_tbl_add_ucast_routing(desc_info, entry);
break;
case ROCKER_OF_DPA_TABLE_ID_BRIDGING:
err = rocker_cmd_flow_tbl_add_bridge(desc_info, entry);
break;
case ROCKER_OF_DPA_TABLE_ID_ACL_POLICY:
err = rocker_cmd_flow_tbl_add_acl(desc_info, entry);
break;
default:
err = -ENOTSUPP;
break;
}
if (err)
return err;
rocker_tlv_nest_end(desc_info, cmd_info);
return 0;
}
static int rocker_cmd_flow_tbl_del(const struct rocker_port *rocker_port,
struct rocker_desc_info *desc_info,
void *priv)
{
const struct rocker_flow_tbl_entry *entry = priv;
struct rocker_tlv *cmd_info;
if (rocker_tlv_put_u16(desc_info, ROCKER_TLV_CMD_TYPE, entry->cmd))
return -EMSGSIZE;
cmd_info = rocker_tlv_nest_start(desc_info, ROCKER_TLV_CMD_INFO);
if (!cmd_info)
return -EMSGSIZE;
if (rocker_tlv_put_u64(desc_info, ROCKER_TLV_OF_DPA_COOKIE,
entry->cookie))
return -EMSGSIZE;
rocker_tlv_nest_end(desc_info, cmd_info);
return 0;
}
static int
rocker_cmd_group_tbl_add_l2_interface(struct rocker_desc_info *desc_info,
struct rocker_group_tbl_entry *entry)
{
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_OF_DPA_OUT_PPORT,
ROCKER_GROUP_PORT_GET(entry->group_id)))
return -EMSGSIZE;
if (rocker_tlv_put_u8(desc_info, ROCKER_TLV_OF_DPA_POP_VLAN,
entry->l2_interface.pop_vlan))
return -EMSGSIZE;
return 0;
}
static int
rocker_cmd_group_tbl_add_l2_rewrite(struct rocker_desc_info *desc_info,
const struct rocker_group_tbl_entry *entry)
{
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_OF_DPA_GROUP_ID_LOWER,
entry->l2_rewrite.group_id))
return -EMSGSIZE;
if (!is_zero_ether_addr(entry->l2_rewrite.eth_src) &&
rocker_tlv_put(desc_info, ROCKER_TLV_OF_DPA_SRC_MAC,
ETH_ALEN, entry->l2_rewrite.eth_src))
return -EMSGSIZE;
if (!is_zero_ether_addr(entry->l2_rewrite.eth_dst) &&
rocker_tlv_put(desc_info, ROCKER_TLV_OF_DPA_DST_MAC,
ETH_ALEN, entry->l2_rewrite.eth_dst))
return -EMSGSIZE;
if (entry->l2_rewrite.vlan_id &&
rocker_tlv_put_be16(desc_info, ROCKER_TLV_OF_DPA_VLAN_ID,
entry->l2_rewrite.vlan_id))
return -EMSGSIZE;
return 0;
}
static int
rocker_cmd_group_tbl_add_group_ids(struct rocker_desc_info *desc_info,
const struct rocker_group_tbl_entry *entry)
{
int i;
struct rocker_tlv *group_ids;
if (rocker_tlv_put_u16(desc_info, ROCKER_TLV_OF_DPA_GROUP_COUNT,
entry->group_count))
return -EMSGSIZE;
group_ids = rocker_tlv_nest_start(desc_info,
ROCKER_TLV_OF_DPA_GROUP_IDS);
if (!group_ids)
return -EMSGSIZE;
for (i = 0; i < entry->group_count; i++)
/* Note TLV array is 1-based */
if (rocker_tlv_put_u32(desc_info, i + 1, entry->group_ids[i]))
return -EMSGSIZE;
rocker_tlv_nest_end(desc_info, group_ids);
return 0;
}
static int
rocker_cmd_group_tbl_add_l3_unicast(struct rocker_desc_info *desc_info,
const struct rocker_group_tbl_entry *entry)
{
if (!is_zero_ether_addr(entry->l3_unicast.eth_src) &&
rocker_tlv_put(desc_info, ROCKER_TLV_OF_DPA_SRC_MAC,
ETH_ALEN, entry->l3_unicast.eth_src))
return -EMSGSIZE;
if (!is_zero_ether_addr(entry->l3_unicast.eth_dst) &&
rocker_tlv_put(desc_info, ROCKER_TLV_OF_DPA_DST_MAC,
ETH_ALEN, entry->l3_unicast.eth_dst))
return -EMSGSIZE;
if (entry->l3_unicast.vlan_id &&
rocker_tlv_put_be16(desc_info, ROCKER_TLV_OF_DPA_VLAN_ID,
entry->l3_unicast.vlan_id))
return -EMSGSIZE;
if (rocker_tlv_put_u8(desc_info, ROCKER_TLV_OF_DPA_TTL_CHECK,
entry->l3_unicast.ttl_check))
return -EMSGSIZE;
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_OF_DPA_GROUP_ID_LOWER,
entry->l3_unicast.group_id))
return -EMSGSIZE;
return 0;
}
static int rocker_cmd_group_tbl_add(const struct rocker_port *rocker_port,
struct rocker_desc_info *desc_info,
void *priv)
{
struct rocker_group_tbl_entry *entry = priv;
struct rocker_tlv *cmd_info;
int err = 0;
if (rocker_tlv_put_u16(desc_info, ROCKER_TLV_CMD_TYPE, entry->cmd))
return -EMSGSIZE;
cmd_info = rocker_tlv_nest_start(desc_info, ROCKER_TLV_CMD_INFO);
if (!cmd_info)
return -EMSGSIZE;
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_OF_DPA_GROUP_ID,
entry->group_id))
return -EMSGSIZE;
switch (ROCKER_GROUP_TYPE_GET(entry->group_id)) {
case ROCKER_OF_DPA_GROUP_TYPE_L2_INTERFACE:
err = rocker_cmd_group_tbl_add_l2_interface(desc_info, entry);
break;
case ROCKER_OF_DPA_GROUP_TYPE_L2_REWRITE:
err = rocker_cmd_group_tbl_add_l2_rewrite(desc_info, entry);
break;
case ROCKER_OF_DPA_GROUP_TYPE_L2_FLOOD:
case ROCKER_OF_DPA_GROUP_TYPE_L2_MCAST:
err = rocker_cmd_group_tbl_add_group_ids(desc_info, entry);
break;
case ROCKER_OF_DPA_GROUP_TYPE_L3_UCAST:
err = rocker_cmd_group_tbl_add_l3_unicast(desc_info, entry);
break;
default:
err = -ENOTSUPP;
break;
}
if (err)
return err;
rocker_tlv_nest_end(desc_info, cmd_info);
return 0;
}
static int rocker_cmd_group_tbl_del(const struct rocker_port *rocker_port,
struct rocker_desc_info *desc_info,
void *priv)
{
const struct rocker_group_tbl_entry *entry = priv;
struct rocker_tlv *cmd_info;
if (rocker_tlv_put_u16(desc_info, ROCKER_TLV_CMD_TYPE, entry->cmd))
return -EMSGSIZE;
cmd_info = rocker_tlv_nest_start(desc_info, ROCKER_TLV_CMD_INFO);
if (!cmd_info)
return -EMSGSIZE;
if (rocker_tlv_put_u32(desc_info, ROCKER_TLV_OF_DPA_GROUP_ID,
entry->group_id))
return -EMSGSIZE;
rocker_tlv_nest_end(desc_info, cmd_info);
return 0;
}
/***************************************************
* Flow, group, FDB, internal VLAN and neigh tables
***************************************************/
static int rocker_init_tbls(struct rocker *rocker)
{
hash_init(rocker->flow_tbl);
spin_lock_init(&rocker->flow_tbl_lock);
hash_init(rocker->group_tbl);
spin_lock_init(&rocker->group_tbl_lock);
hash_init(rocker->fdb_tbl);
spin_lock_init(&rocker->fdb_tbl_lock);
hash_init(rocker->internal_vlan_tbl);
spin_lock_init(&rocker->internal_vlan_tbl_lock);
hash_init(rocker->neigh_tbl);
spin_lock_init(&rocker->neigh_tbl_lock);
return 0;
}
static void rocker_free_tbls(struct rocker *rocker)
{
unsigned long flags;
struct rocker_flow_tbl_entry *flow_entry;
struct rocker_group_tbl_entry *group_entry;
struct rocker_fdb_tbl_entry *fdb_entry;
struct rocker_internal_vlan_tbl_entry *internal_vlan_entry;
struct rocker_neigh_tbl_entry *neigh_entry;
struct hlist_node *tmp;
int bkt;
spin_lock_irqsave(&rocker->flow_tbl_lock, flags);
hash_for_each_safe(rocker->flow_tbl, bkt, tmp, flow_entry, entry)
hash_del(&flow_entry->entry);
spin_unlock_irqrestore(&rocker->flow_tbl_lock, flags);
spin_lock_irqsave(&rocker->group_tbl_lock, flags);
hash_for_each_safe(rocker->group_tbl, bkt, tmp, group_entry, entry)
hash_del(&group_entry->entry);
spin_unlock_irqrestore(&rocker->group_tbl_lock, flags);
spin_lock_irqsave(&rocker->fdb_tbl_lock, flags);
hash_for_each_safe(rocker->fdb_tbl, bkt, tmp, fdb_entry, entry)
hash_del(&fdb_entry->entry);
spin_unlock_irqrestore(&rocker->fdb_tbl_lock, flags);
spin_lock_irqsave(&rocker->internal_vlan_tbl_lock, flags);
hash_for_each_safe(rocker->internal_vlan_tbl, bkt,
tmp, internal_vlan_entry, entry)
hash_del(&internal_vlan_entry->entry);
spin_unlock_irqrestore(&rocker->internal_vlan_tbl_lock, flags);
spin_lock_irqsave(&rocker->neigh_tbl_lock, flags);
hash_for_each_safe(rocker->neigh_tbl, bkt, tmp, neigh_entry, entry)
hash_del(&neigh_entry->entry);
spin_unlock_irqrestore(&rocker->neigh_tbl_lock, flags);
}
static struct rocker_flow_tbl_entry *
rocker_flow_tbl_find(const struct rocker *rocker,
const struct rocker_flow_tbl_entry *match)
{
struct rocker_flow_tbl_entry *found;
size_t key_len = match->key_len ? match->key_len : sizeof(found->key);
hash_for_each_possible(rocker->flow_tbl, found,
entry, match->key_crc32) {
if (memcmp(&found->key, &match->key, key_len) == 0)
return found;
}
return NULL;
}
static int rocker_flow_tbl_add(struct rocker_port *rocker_port,
struct switchdev_trans *trans, int flags,
struct rocker_flow_tbl_entry *match)
{
struct rocker *rocker = rocker_port->rocker;
struct rocker_flow_tbl_entry *found;
size_t key_len = match->key_len ? match->key_len : sizeof(found->key);
unsigned long lock_flags;
match->key_crc32 = crc32(~0, &match->key, key_len);
spin_lock_irqsave(&rocker->flow_tbl_lock, lock_flags);
found = rocker_flow_tbl_find(rocker, match);
if (found) {
match->cookie = found->cookie;
if (!switchdev_trans_ph_prepare(trans))
hash_del(&found->entry);
rocker_port_kfree(trans, found);
found = match;
found->cmd = ROCKER_TLV_CMD_TYPE_OF_DPA_FLOW_MOD;
} else {
found = match;
found->cookie = rocker->flow_tbl_next_cookie++;
found->cmd = ROCKER_TLV_CMD_TYPE_OF_DPA_FLOW_ADD;
}
if (!switchdev_trans_ph_prepare(trans))
hash_add(rocker->flow_tbl, &found->entry, found->key_crc32);
spin_unlock_irqrestore(&rocker->flow_tbl_lock, lock_flags);
return rocker_cmd_exec(rocker_port, trans, flags,
rocker_cmd_flow_tbl_add, found, NULL, NULL);
}
static int rocker_flow_tbl_del(struct rocker_port *rocker_port,
struct switchdev_trans *trans, int flags,
struct rocker_flow_tbl_entry *match)
{
struct rocker *rocker = rocker_port->rocker;
struct rocker_flow_tbl_entry *found;
size_t key_len = match->key_len ? match->key_len : sizeof(found->key);
unsigned long lock_flags;
int err = 0;
match->key_crc32 = crc32(~0, &match->key, key_len);
spin_lock_irqsave(&rocker->flow_tbl_lock, lock_flags);
found = rocker_flow_tbl_find(rocker, match);
if (found) {
if (!switchdev_trans_ph_prepare(trans))
hash_del(&found->entry);
found->cmd = ROCKER_TLV_CMD_TYPE_OF_DPA_FLOW_DEL;
}
spin_unlock_irqrestore(&rocker->flow_tbl_lock, lock_flags);
rocker_port_kfree(trans, match);
if (found) {
err = rocker_cmd_exec(rocker_port, trans, flags,
rocker_cmd_flow_tbl_del,
found, NULL, NULL);
rocker_port_kfree(trans, found);
}
return err;
}
static int rocker_flow_tbl_do(struct rocker_port *rocker_port,
struct switchdev_trans *trans, int flags,
struct rocker_flow_tbl_entry *entry)
{
if (flags & ROCKER_OP_FLAG_REMOVE)
return rocker_flow_tbl_del(rocker_port, trans, flags, entry);
else
return rocker_flow_tbl_add(rocker_port, trans, flags, entry);
}
static int rocker_flow_tbl_ig_port(struct rocker_port *rocker_port,
struct switchdev_trans *trans, int flags,
u32 in_pport, u32 in_pport_mask,
enum rocker_of_dpa_table_id goto_tbl)
{
struct rocker_flow_tbl_entry *entry;
entry = rocker_port_kzalloc(rocker_port, trans, flags, sizeof(*entry));
if (!entry)
return -ENOMEM;
entry->key.priority = ROCKER_PRIORITY_IG_PORT;
entry->key.tbl_id = ROCKER_OF_DPA_TABLE_ID_INGRESS_PORT;
entry->key.ig_port.in_pport = in_pport;
entry->key.ig_port.in_pport_mask = in_pport_mask;
entry->key.ig_port.goto_tbl = goto_tbl;
return rocker_flow_tbl_do(rocker_port, trans, flags, entry);
}
static int rocker_flow_tbl_vlan(struct rocker_port *rocker_port,
struct switchdev_trans *trans, int flags,
u32 in_pport, __be16 vlan_id,
__be16 vlan_id_mask,
enum rocker_of_dpa_table_id goto_tbl,
bool untagged, __be16 new_vlan_id)
{
struct rocker_flow_tbl_entry *entry;
entry = rocker_port_kzalloc(rocker_port, trans, flags, sizeof(*entry));
if (!entry)
return -ENOMEM;
entry->key.priority = ROCKER_PRIORITY_VLAN;
entry->key.tbl_id = ROCKER_OF_DPA_TABLE_ID_VLAN;
entry->key.vlan.in_pport = in_pport;
entry->key.vlan.vlan_id = vlan_id;
entry->key.vlan.vlan_id_mask = vlan_id_mask;
entry->key.vlan.goto_tbl = goto_tbl;
entry->key.vlan.untagged = untagged;
entry->key.vlan.new_vlan_id = new_vlan_id;
return rocker_flow_tbl_do(rocker_port, trans, flags, entry);
}
static int rocker_flow_tbl_term_mac(struct rocker_port *rocker_port,
struct switchdev_trans *trans,
u32 in_pport, u32 in_pport_mask,
__be16 eth_type, const u8 *eth_dst,
const u8 *eth_dst_mask, __be16 vlan_id,
__be16 vlan_id_mask, bool copy_to_cpu,
int flags)
{
struct rocker_flow_tbl_entry *entry;
entry = rocker_port_kzalloc(rocker_port, trans, flags, sizeof(*entry));
if (!entry)
return -ENOMEM;
if (is_multicast_ether_addr(eth_dst)) {
entry->key.priority = ROCKER_PRIORITY_TERM_MAC_MCAST;
entry->key.term_mac.goto_tbl =
ROCKER_OF_DPA_TABLE_ID_MULTICAST_ROUTING;
} else {
entry->key.priority = ROCKER_PRIORITY_TERM_MAC_UCAST;
entry->key.term_mac.goto_tbl =
ROCKER_OF_DPA_TABLE_ID_UNICAST_ROUTING;
}
entry->key.tbl_id = ROCKER_OF_DPA_TABLE_ID_TERMINATION_MAC;
entry->key.term_mac.in_pport = in_pport;
entry->key.term_mac.in_pport_mask = in_pport_mask;
entry->key.term_mac.eth_type = eth_type;
ether_addr_copy(entry->key.term_mac.eth_dst, eth_dst);
ether_addr_copy(entry->key.term_mac.eth_dst_mask, eth_dst_mask);
entry->key.term_mac.vlan_id = vlan_id;
entry->key.term_mac.vlan_id_mask = vlan_id_mask;
entry->key.term_mac.copy_to_cpu = copy_to_cpu;
return rocker_flow_tbl_do(rocker_port, trans, flags, entry);
}
static int rocker_flow_tbl_bridge(struct rocker_port *rocker_port,
struct switchdev_trans *trans, int flags,
const u8 *eth_dst, const u8 *eth_dst_mask,
__be16 vlan_id, u32 tunnel_id,
enum rocker_of_dpa_table_id goto_tbl,
u32 group_id, bool copy_to_cpu)
{
struct rocker_flow_tbl_entry *entry;
u32 priority;
bool vlan_bridging = !!vlan_id;
bool dflt = !eth_dst || (eth_dst && eth_dst_mask);
bool wild = false;
entry = rocker_port_kzalloc(rocker_port, trans, flags, sizeof(*entry));
if (!entry)
return -ENOMEM;
entry->key.tbl_id = ROCKER_OF_DPA_TABLE_ID_BRIDGING;
if (eth_dst) {
entry->key.bridge.has_eth_dst = 1;
ether_addr_copy(entry->key.bridge.eth_dst, eth_dst);
}
if (eth_dst_mask) {
entry->key.bridge.has_eth_dst_mask = 1;
ether_addr_copy(entry->key.bridge.eth_dst_mask, eth_dst_mask);
if (!ether_addr_equal(eth_dst_mask, ff_mac))
wild = true;
}
priority = ROCKER_PRIORITY_UNKNOWN;
if (vlan_bridging && dflt && wild)
priority = ROCKER_PRIORITY_BRIDGING_VLAN_DFLT_WILD;
else if (vlan_bridging && dflt && !wild)
priority = ROCKER_PRIORITY_BRIDGING_VLAN_DFLT_EXACT;
else if (vlan_bridging && !dflt)
priority = ROCKER_PRIORITY_BRIDGING_VLAN;
else if (!vlan_bridging && dflt && wild)
priority = ROCKER_PRIORITY_BRIDGING_TENANT_DFLT_WILD;
else if (!vlan_bridging && dflt && !wild)
priority = ROCKER_PRIORITY_BRIDGING_TENANT_DFLT_EXACT;
else if (!vlan_bridging && !dflt)
priority = ROCKER_PRIORITY_BRIDGING_TENANT;
entry->key.priority = priority;
entry->key.bridge.vlan_id = vlan_id;
entry->key.bridge.tunnel_id = tunnel_id;
entry->key.bridge.goto_tbl = goto_tbl;
entry->key.bridge.group_id = group_id;
entry->key.bridge.copy_to_cpu = copy_to_cpu;
return rocker_flow_tbl_do(rocker_port, trans, flags, entry);
}
static int rocker_flow_tbl_ucast4_routing(struct rocker_port *rocker_port,
struct switchdev_trans *trans,
__be16 eth_type, __be32 dst,
__be32 dst_mask, u32 priority,
enum rocker_of_dpa_table_id goto_tbl,
u32 group_id, int flags)
{
struct rocker_flow_tbl_entry *entry;
entry = rocker_port_kzalloc(rocker_port, trans, flags, sizeof(*entry));
if (!entry)
return -ENOMEM;
entry->key.tbl_id = ROCKER_OF_DPA_TABLE_ID_UNICAST_ROUTING;
entry->key.priority = priority;
entry->key.ucast_routing.eth_type = eth_type;
entry->key.ucast_routing.dst4 = dst;
entry->key.ucast_routing.dst4_mask = dst_mask;
entry->key.ucast_routing.goto_tbl = goto_tbl;
entry->key.ucast_routing.group_id = group_id;
entry->key_len = offsetof(struct rocker_flow_tbl_key,
ucast_routing.group_id);
return rocker_flow_tbl_do(rocker_port, trans, flags, entry);
}
static int rocker_flow_tbl_acl(struct rocker_port *rocker_port,
struct switchdev_trans *trans, int flags,
u32 in_pport, u32 in_pport_mask,
const u8 *eth_src, const u8 *eth_src_mask,
const u8 *eth_dst, const u8 *eth_dst_mask,
__be16 eth_type, __be16 vlan_id,
__be16 vlan_id_mask, u8 ip_proto,
u8 ip_proto_mask, u8 ip_tos, u8 ip_tos_mask,
u32 group_id)
{