Commit 3ce406bd authored by David S. Miller's avatar David S. Miller

Merge branch...

Merge branch 'net-marvell-prestera-Add-Switchdev-driver-for-Prestera-family-ASIC-device-98DX3255-AC3x'

Vadym Kochan says:

====================
net: marvell: prestera: Add Switchdev driver for Prestera family ASIC device 98DX3255 (AC3x)

Marvell Prestera 98DX3255 integrates up to 24 ports of 1GbE with 8
ports of 10GbE uplinks or 2 ports of 40Gbps stacking for a largely
wireless SMB deployment.

Prestera Switchdev is a firmware based driver that operates via PCI bus.  The
current implementation supports only boards designed for the Marvell Switchdev
solution and requires special firmware.

This driver implementation includes only L1, basic L2 support, and RX/TX.

The core Prestera switching logic is implemented in prestera_main.c, there is
an intermediate hw layer between core logic and firmware. It is
implemented in prestera_hw.c, the purpose of it is to encapsulate hw
related logic, in future there is a plan to support more devices with
different HW related configurations.

The following Switchdev features are supported:

    - VLAN-aware bridge offloading
    - VLAN-unaware bridge offloading
    - FDB offloading (learning, ageing)
    - Switchport configuration

The original firmware image is uploaded to the linux-firmware repository.

PATCH v9:
    1) Replace read_poll_timeout_atomic() by original 'do {} while()' loop
       because it works much better than read_poll_timeout_atomic()
       considering the TX rate. Also it fixes warning reported on v8.

    2) Use ENOENT instead of EEXIST when item is not found in few
       places - prestera_hw.c and prestera_rxtx.c

    Patches updated:
        [1] net: marvell: prestera: Add driver for Prestera family ASIC devices

PATCH v8:
    1) Put license in one line.

    2) Sort includes.

    3) Add missing comma for last enum member

    4) Return original error code from last called func
       in places where instead other error code was used.

    5) Add comma for last member in initialized struct in prestera_hw.c

    6) Do not initialize 'int err = 0' where it is not needed.

    7) Simplify device-tree "marvell,prestera" node parsing by removing not
       needed checking on 'np == NULL'.

    8) Use u32p_replace_bits() instead of open-coded ((word & ~mask) | val)

    9) Use dev_warn_ratelimited() instead of pr_warn_ratelimited to indicate the device
        instance in prestera_rxtx.c

    10) Simplify circular buffer list creation in prestera_sdma_{rx,tx}_init() by using
        do { } while (prev != tail) construction.

    11) Use MSEC_PER_SEC instead of hard-coded 1000.

    12) Use traditional error handling pattern:

       err = F();
       if (err)
           return err;

    13) Use ether_addr_copy() instead of memcpy() for mac FDB copying in prestera_hw.c

    14) Drop swdev->ageing_time member which is not used.

    15) Fix ageing macro to be in ms instead of seconds.

    Patches updated:
        [1] net: marvell: prestera: Add driver for Prestera family ASIC devices
	[2] net: marvell: prestera: Add PCI interface support
        [3] net: marvell: prestera: Add basic devlink support
	[4] net: marvell: prestera: Add ethtool interface support
	[5] net: marvell: prestera: Add Switchdev driver implementation

PATCH v7:
    1) Use ether_addr_copy() in prestera_main.c:prestera_port_set_mac_address()
       instead of memcpy().

    2) Removed not needed device's DMA address range check on
       dma_pool_alloc() in prestera_rxtx.c:prestera_sdma_buf_init(),
       this should be handled by dma_xxx() API considerig device's DMA mask.

    3) Removed not needed device's DMA address range check on
       dma_map_single() in prestera_rxtx.c:prestera_sdma_rx_skb_alloc(),
       this should be handled by dma_xxx() API considerig device's DMA mask.

    4) Add comment about port mac address limitation in the code where
       it is used and checked - prestera_main.c:

           - prestera_is_valid_mac_addr()
           - prestera_port_create()

    5) Add missing destroy_workqueue(swdev_wq) in prestera_switchdev.c:prestera_switchdev_init()
       on error path handling.

    Patches updated:
        [1] net: marvell: prestera: Add driver for Prestera family ASIC devices
        [5] net: marvell: prestera: Add Switchdev driver implementation

PATCH v6:
    1) Use rwlock to protect port list on create/delete stages. The list
       is mostly readable by fw event handler or packets receiver, but
       updated only on create/delete port which are performed on switch init/fini
       stages.

    2) Remove not needed variable initialization in prestera_dsa.c:prestera_dsa_parse()

    3) Get rid of bounce buffer used by tx handler in prestera_rxtx.c,
       the bounce buffer should be handled by dma_xxx API via swiotlb.

    4) Fix PRESTERA_SDMA_RX_DESC_PKT_LEN macro by using correct GENMASK(13, 0) in prestera_rxtx.c

    Patches updated:
        [1] net: marvell: prestera: Add driver for Prestera family ASIC devices

PATCH v5:
    0) add Co-developed tags for people who was involved in development.

    1) Make SPDX license as separate comment

    2) Change 'u8 *' -> 'void *', It allows to avoid not-needed u8* casting.

    3) Remove "," in terminated enum's.

    4) Use GENMASK(end, start) where it is applicable in.

    5) Remove not-needed 'u8 *' casting.

    6) Apply common error-check pattern

    7) Use ether_addr_copy instead of memcpy

    8) Use define for maximum MAC address range (255)

    9) Simplify prestera_port_state_set() in prestera_main.c by
       using separate if-blocks for state setting:

        if (is_up) {
        ...
        } else {
        ...
        }

      which makes logic more understandable.

    10) Simplify sdma tx wait logic when checking/updating tx_ring->burst.

    11) Remove not-needed packed & aligned attributes

    12) Use USEC_PER_MSEC as multiplier when converting ms -> usec on calling
        readl_poll_timeout.

    13) Simplified some error path handling by simple return error code in.

    14) Remove not-needed err assignment in.

    15) Use dev_err() in prestera_devlink_register(...).

    Patches updated:
        [1] net: marvell: prestera: Add driver for Prestera family ASIC devices
	[2] net: marvell: prestera: Add PCI interface support
        [3] net: marvell: prestera: Add basic devlink support
	[4] net: marvell: prestera: Add ethtool interface support
	[5] net: marvell: prestera: Add Switchdev driver implementation

PATCH v4:
    1) Use prestera_ prefix in netdev_ops variable.

    2) Kconfig: use 'default PRESTERA' build type for CONFIG_PRESTERA_PCI to be
       synced by default with prestera core module.

    3) Use memcpy_xxio helpers in prestera_pci.c for IO buffer copying.

    4) Generate fw image path via snprintf() instead of macroses.

    5) Use pcim_ helpers in prestera_pci.c which simplified the
       probe/remove logic.

    6) Removed not needed initializations of variables which are used in
       readl_poll_xxx() helpers.

    7) Fixed few grammar mistakes in patch[2] description.

    8) Export only prestera_ethtool_ops struct instead of each
       ethtool handler.

    9) Add check for prestera_dev_check() in switchdev event handling to
       make sure there is no wrong topology.

    Patches updated:
        [1] net: marvell: prestera: Add driver for Prestera family ASIC devices
	[2] net: marvell: prestera: Add PCI interface support
	[4] net: marvell: prestera: Add ethtool interface support
	[5] net: marvell: prestera: Add Switchdev driver implementation

PATCH v3:
    1) Simplify __be32 type casting in prestera_dsa.c

    2) Added per-patch changelog under "---" line.

PATCH v2:
    1) Use devlink_port_type_clear()

    2) Add _MS prefix to timeout defines.

    3) Remove not-needed packed attribute from the firmware ipc structs,
       also the firmware image needs to be uploaded too (will do it soon).

    4) Introduce prestera_hw_switch_fini(), to be mirrored with init and
       do simple validation if the event handlers are unregistered.

    5) Use kfree_rcu() for event handler unregistering.

    6) Get rid of rcu-list usage when dealing with ports, not needed for
       now.

    7) Little spelling corrections in the error/info messages.

    8) Make pci probe & remove logic mirrored.

    9) Get rid of ETH_FCS_LEN in headroom setting, not needed.

PATCH:
    1) Fixed W=1 warnings

    2) Renamed PCI driver name to be more generic "Prestera DX" because
       there will be more devices supported.

    3) Changed firmware image dir path: marvell/ -> mrvl/prestera/
       to be aligned with location in linux-firmware.git (if such
       will be accepted).

RFC v3:
    1) Fix prestera prefix in prestera_rxtx.c

    2) Protect concurrent access from multiple ports on multiple CPU system
       on tx path by spinlock in prestera_rxtx.c

    3) Try to get base mac address from device-tree, otherwise use a random generated one.

    4) Move ethtool interface support into separate prestera_ethtool.c file.

    5) Add basic devlink support and get rid of physical port naming ops.

    6) Add STP support in Switchdev driver.

    7) Removed MODULE_AUTHOR

    8) Renamed prestera.c -> prestera_main.c, and kernel module to
       prestera.ko

RFC v2:
    1) Use "pestera_" prefix in struct's and functions instead of mvsw_pr_

    2) Original series split into additional patches for Switchdev ethtool support.

    3) Use major and minor firmware version numbers in the firmware image filename.

    4) Removed not needed prints.

    5) Use iopoll API for waiting on register's value in prestera_pci.c

    6) Use standart approach for describing PCI ID matching section instead of using
       custom wrappers in prestera_pci.c

    7) Add RX/TX support in prestera_rxtx.c.

    8) Rewritten prestera_switchdev.c with following changes:
       - handle netdev events from prestera.c

       - use struct prestera_bridge for bridge objects, and get rid of
         struct prestera_bridge_device which may confuse.

       - use refcount_t

    9) Get rid of macro usage for sending fw requests in prestera_hw.c

    10) Add base_mac setting as module parameter. base_mac is required for
        generation default port's mac.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 5114b331 40acc052
......@@ -45,3 +45,37 @@ dfx-server {
ranges = <0 MBUS_ID(0x08, 0x00) 0 0x100000>;
reg = <MBUS_ID(0x08, 0x00) 0 0x100000>;
};
Marvell Prestera SwitchDev bindings
-----------------------------------
Optional properties:
- compatible: must be "marvell,prestera"
- base-mac-provider: describes handle to node which provides base mac address,
might be a static base mac address or nvme cell provider.
Example:
eeprom_mac_addr: eeprom-mac-addr {
compatible = "eeprom,mac-addr-cell";
status = "okay";
nvmem = <&eeprom_at24>;
};
prestera {
compatible = "marvell,prestera";
status = "okay";
base-mac-provider = <&eeprom_mac_addr>;
};
The current implementation of Prestera Switchdev PCI interface driver requires
that BAR2 is assigned to 0xf6000000 as base address from the PCI IO range:
&cp0_pcie0 {
ranges = <0x81000000 0x0 0xfb000000 0x0 0xfb000000 0x0 0xf0000
0x82000000 0x0 0xf6000000 0x0 0xf6000000 0x0 0x2000000
0x82000000 0x0 0xf9000000 0x0 0xf9000000 0x0 0x100000>;
phys = <&cp0_comphy0 0>;
status = "okay";
};
......@@ -178,5 +178,6 @@ config SKY2_DEBUG
source "drivers/net/ethernet/marvell/octeontx2/Kconfig"
source "drivers/net/ethernet/marvell/prestera/Kconfig"
endif # NET_VENDOR_MARVELL
......@@ -12,3 +12,4 @@ obj-$(CONFIG_PXA168_ETH) += pxa168_eth.o
obj-$(CONFIG_SKGE) += skge.o
obj-$(CONFIG_SKY2) += sky2.o
obj-y += octeontx2/
obj-y += prestera/
# SPDX-License-Identifier: GPL-2.0-only
#
# Marvell Prestera drivers configuration
#
config PRESTERA
tristate "Marvell Prestera Switch ASICs support"
depends on NET_SWITCHDEV && VLAN_8021Q
select NET_DEVLINK
help
This driver supports Marvell Prestera Switch ASICs family.
To compile this driver as a module, choose M here: the
module will be called prestera.
config PRESTERA_PCI
tristate "PCI interface driver for Marvell Prestera Switch ASICs family"
depends on PCI && HAS_IOMEM && PRESTERA
default PRESTERA
help
This is implementation of PCI interface support for Marvell Prestera
Switch ASICs family.
To compile this driver as a module, choose M here: the
module will be called prestera_pci.
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_PRESTERA) += prestera.o
prestera-objs := prestera_main.o prestera_hw.o prestera_dsa.o \
prestera_rxtx.o prestera_devlink.o prestera_ethtool.o \
prestera_switchdev.o
obj-$(CONFIG_PRESTERA_PCI) += prestera_pci.o
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
/* Copyright (c) 2019-2020 Marvell International Ltd. All rights reserved. */
#ifndef _PRESTERA_H_
#define _PRESTERA_H_
#include <linux/notifier.h>
#include <linux/skbuff.h>
#include <linux/workqueue.h>
#include <net/devlink.h>
#include <uapi/linux/if_ether.h>
#define PRESTERA_DRV_NAME "prestera"
#define PRESTERA_DEFAULT_VID 1
struct prestera_fw_rev {
u16 maj;
u16 min;
u16 sub;
};
struct prestera_port_stats {
u64 good_octets_received;
u64 bad_octets_received;
u64 mac_trans_error;
u64 broadcast_frames_received;
u64 multicast_frames_received;
u64 frames_64_octets;
u64 frames_65_to_127_octets;
u64 frames_128_to_255_octets;
u64 frames_256_to_511_octets;
u64 frames_512_to_1023_octets;
u64 frames_1024_to_max_octets;
u64 excessive_collision;
u64 multicast_frames_sent;
u64 broadcast_frames_sent;
u64 fc_sent;
u64 fc_received;
u64 buffer_overrun;
u64 undersize;
u64 fragments;
u64 oversize;
u64 jabber;
u64 rx_error_frame_received;
u64 bad_crc;
u64 collisions;
u64 late_collision;
u64 unicast_frames_received;
u64 unicast_frames_sent;
u64 sent_multiple;
u64 sent_deferred;
u64 good_octets_sent;
};
struct prestera_port_caps {
u64 supp_link_modes;
u8 supp_fec;
u8 type;
u8 transceiver;
};
struct prestera_port {
struct net_device *dev;
struct prestera_switch *sw;
struct devlink_port dl_port;
u32 id;
u32 hw_id;
u32 dev_id;
u16 fp_id;
u16 pvid;
bool autoneg;
u64 adver_link_modes;
u8 adver_fec;
struct prestera_port_caps caps;
struct list_head list;
struct list_head vlans_list;
struct {
struct prestera_port_stats stats;
struct delayed_work caching_dw;
} cached_hw_stats;
};
struct prestera_device {
struct device *dev;
u8 __iomem *ctl_regs;
u8 __iomem *pp_regs;
struct prestera_fw_rev fw_rev;
void *priv;
/* called by device driver to handle received packets */
void (*recv_pkt)(struct prestera_device *dev);
/* called by device driver to pass event up to the higher layer */
int (*recv_msg)(struct prestera_device *dev, void *msg, size_t size);
/* called by higher layer to send request to the firmware */
int (*send_req)(struct prestera_device *dev, void *in_msg,
size_t in_size, void *out_msg, size_t out_size,
unsigned int wait);
};
enum prestera_event_type {
PRESTERA_EVENT_TYPE_UNSPEC,
PRESTERA_EVENT_TYPE_PORT,
PRESTERA_EVENT_TYPE_FDB,
PRESTERA_EVENT_TYPE_RXTX,
PRESTERA_EVENT_TYPE_MAX
};
enum prestera_rxtx_event_id {
PRESTERA_RXTX_EVENT_UNSPEC,
PRESTERA_RXTX_EVENT_RCV_PKT,
};
enum prestera_port_event_id {
PRESTERA_PORT_EVENT_UNSPEC,
PRESTERA_PORT_EVENT_STATE_CHANGED,
};
struct prestera_port_event {
u32 port_id;
union {
u32 oper_state;
} data;
};
enum prestera_fdb_event_id {
PRESTERA_FDB_EVENT_UNSPEC,
PRESTERA_FDB_EVENT_LEARNED,
PRESTERA_FDB_EVENT_AGED,
};
struct prestera_fdb_event {
u32 port_id;
u32 vid;
union {
u8 mac[ETH_ALEN];
} data;
};
struct prestera_event {
u16 id;
union {
struct prestera_port_event port_evt;
struct prestera_fdb_event fdb_evt;
};
};
struct prestera_switchdev;
struct prestera_rxtx;
struct prestera_switch {
struct prestera_device *dev;
struct prestera_switchdev *swdev;
struct prestera_rxtx *rxtx;
struct list_head event_handlers;
struct notifier_block netdev_nb;
char base_mac[ETH_ALEN];
struct list_head port_list;
rwlock_t port_list_lock;
u32 port_count;
u32 mtu_min;
u32 mtu_max;
u8 id;
};
struct prestera_rxtx_params {
bool use_sdma;
u32 map_addr;
};
#define prestera_dev(sw) ((sw)->dev->dev)
static inline void prestera_write(const struct prestera_switch *sw,
unsigned int reg, u32 val)
{
writel(val, sw->dev->pp_regs + reg);
}
static inline u32 prestera_read(const struct prestera_switch *sw,
unsigned int reg)
{
return readl(sw->dev->pp_regs + reg);
}
int prestera_device_register(struct prestera_device *dev);
void prestera_device_unregister(struct prestera_device *dev);
struct prestera_port *prestera_port_find_by_hwid(struct prestera_switch *sw,
u32 dev_id, u32 hw_id);
int prestera_port_autoneg_set(struct prestera_port *port, bool enable,
u64 adver_link_modes, u8 adver_fec);
struct prestera_port *prestera_find_port(struct prestera_switch *sw, u32 id);
struct prestera_port *prestera_port_dev_lower_find(struct net_device *dev);
int prestera_port_pvid_set(struct prestera_port *port, u16 vid);
bool prestera_netdev_check(const struct net_device *dev);
#endif /* _PRESTERA_H_ */
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
/* Copyright (c) 2019-2020 Marvell International Ltd. All rights reserved */
#include <net/devlink.h>
#include "prestera_devlink.h"
static int prestera_dl_info_get(struct devlink *dl,
struct devlink_info_req *req,
struct netlink_ext_ack *extack)
{
struct prestera_switch *sw = devlink_priv(dl);
char buf[16];
int err;
err = devlink_info_driver_name_put(req, PRESTERA_DRV_NAME);
if (err)
return err;
snprintf(buf, sizeof(buf), "%d.%d.%d",
sw->dev->fw_rev.maj,
sw->dev->fw_rev.min,
sw->dev->fw_rev.sub);
return devlink_info_version_running_put(req,
DEVLINK_INFO_VERSION_GENERIC_FW,
buf);
}
static const struct devlink_ops prestera_dl_ops = {
.info_get = prestera_dl_info_get,
};
struct prestera_switch *prestera_devlink_alloc(void)
{
struct devlink *dl;
dl = devlink_alloc(&prestera_dl_ops, sizeof(struct prestera_switch));
return devlink_priv(dl);
}
void prestera_devlink_free(struct prestera_switch *sw)
{
struct devlink *dl = priv_to_devlink(sw);
devlink_free(dl);
}
int prestera_devlink_register(struct prestera_switch *sw)
{
struct devlink *dl = priv_to_devlink(sw);
int err;
err = devlink_register(dl, sw->dev->dev);
if (err)
dev_err(prestera_dev(sw), "devlink_register failed: %d\n", err);
return err;
}
void prestera_devlink_unregister(struct prestera_switch *sw)
{
struct devlink *dl = priv_to_devlink(sw);
devlink_unregister(dl);
}
int prestera_devlink_port_register(struct prestera_port *port)
{
struct prestera_switch *sw = port->sw;
struct devlink *dl = priv_to_devlink(sw);
struct devlink_port_attrs attrs = {};
int err;
attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
attrs.phys.port_number = port->fp_id;
attrs.switch_id.id_len = sizeof(sw->id);
memcpy(attrs.switch_id.id, &sw->id, attrs.switch_id.id_len);
devlink_port_attrs_set(&port->dl_port, &attrs);
err = devlink_port_register(dl, &port->dl_port, port->fp_id);
if (err) {
dev_err(prestera_dev(sw), "devlink_port_register failed: %d\n", err);
return err;
}
return 0;
}
void prestera_devlink_port_unregister(struct prestera_port *port)
{
devlink_port_unregister(&port->dl_port);
}
void prestera_devlink_port_set(struct prestera_port *port)
{
devlink_port_type_eth_set(&port->dl_port, port->dev);
}
void prestera_devlink_port_clear(struct prestera_port *port)
{
devlink_port_type_clear(&port->dl_port);
}
struct devlink_port *prestera_devlink_get_port(struct net_device *dev)
{
struct prestera_port *port = netdev_priv(dev);
return &port->dl_port;
}
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
/* Copyright (c) 2019-2020 Marvell International Ltd. All rights reserved. */
#ifndef _PRESTERA_DEVLINK_H_
#define _PRESTERA_DEVLINK_H_
#include "prestera.h"
struct prestera_switch *prestera_devlink_alloc(void);
void prestera_devlink_free(struct prestera_switch *sw);
int prestera_devlink_register(struct prestera_switch *sw);
void prestera_devlink_unregister(struct prestera_switch *sw);
int prestera_devlink_port_register(struct prestera_port *port);
void prestera_devlink_port_unregister(struct prestera_port *port);
void prestera_devlink_port_set(struct prestera_port *port);
void prestera_devlink_port_clear(struct prestera_port *port);
struct devlink_port *prestera_devlink_get_port(struct net_device *dev);
#endif /* _PRESTERA_DEVLINK_H_ */
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
/* Copyright (c) 2020 Marvell International Ltd. All rights reserved */
#include <linux/bitfield.h>
#include <linux/bitops.h>
#include <linux/errno.h>
#include <linux/string.h>
#include "prestera_dsa.h"
#define PRESTERA_DSA_W0_CMD GENMASK(31, 30)
#define PRESTERA_DSA_W0_IS_TAGGED BIT(29)
#define PRESTERA_DSA_W0_DEV_NUM GENMASK(28, 24)
#define PRESTERA_DSA_W0_PORT_NUM GENMASK(23, 19)
#define PRESTERA_DSA_W0_VPT GENMASK(15, 13)
#define PRESTERA_DSA_W0_EXT_BIT BIT(12)
#define PRESTERA_DSA_W0_VID GENMASK(11, 0)
#define PRESTERA_DSA_W1_EXT_BIT BIT(31)
#define PRESTERA_DSA_W1_CFI_BIT BIT(30)
#define PRESTERA_DSA_W1_PORT_NUM GENMASK(11, 10)
#define PRESTERA_DSA_W2_EXT_BIT BIT(31)
#define PRESTERA_DSA_W2_PORT_NUM BIT(20)
#define PRESTERA_DSA_W3_VID GENMASK(30, 27)
#define PRESTERA_DSA_W3_DST_EPORT GENMASK(23, 7)
#define PRESTERA_DSA_W3_DEV_NUM GENMASK(6, 0)
#define PRESTERA_DSA_VID GENMASK(15, 12)
#define PRESTERA_DSA_DEV_NUM GENMASK(11, 5)
int prestera_dsa_parse(struct prestera_dsa *dsa, const u8 *dsa_buf)
{
__be32 *dsa_words = (__be32 *)dsa_buf;
enum prestera_dsa_cmd cmd;
u32 words[4];
u32 field;
words[0] = ntohl(dsa_words[0]);
words[1] = ntohl(dsa_words[1]);
words[2] = ntohl(dsa_words[2]);
words[3] = ntohl(dsa_words[3]);
/* set the common parameters */
cmd = (enum prestera_dsa_cmd)FIELD_GET(PRESTERA_DSA_W0_CMD, words[0]);
/* only to CPU is supported */
if (unlikely(cmd != PRESTERA_DSA_CMD_TO_CPU))
return -EINVAL;
if (FIELD_GET(PRESTERA_DSA_W0_EXT_BIT, words[0]) == 0)
return -EINVAL;
if (FIELD_GET(PRESTERA_DSA_W1_EXT_BIT, words[1]) == 0)
return -EINVAL;
if (FIELD_GET(PRESTERA_DSA_W2_EXT_BIT, words[2]) == 0)
return -EINVAL;
field = FIELD_GET(PRESTERA_DSA_W3_VID, words[3]);
dsa->vlan.is_tagged = FIELD_GET(PRESTERA_DSA_W0_IS_TAGGED, words[0]);
dsa->vlan.cfi_bit = FIELD_GET(PRESTERA_DSA_W1_CFI_BIT, words[1]);
dsa->vlan.vpt = FIELD_GET(PRESTERA_DSA_W0_VPT, words[0]);
dsa->vlan.vid = FIELD_GET(PRESTERA_DSA_W0_VID, words[0]);
dsa->vlan.vid &= ~PRESTERA_DSA_VID;
dsa->vlan.vid |= FIELD_PREP(PRESTERA_DSA_VID, field);
field = FIELD_GET(PRESTERA_DSA_W3_DEV_NUM, words[3]);
dsa->hw_dev_num = FIELD_GET(PRESTERA_DSA_W0_DEV_NUM, words[0]);
dsa->hw_dev_num |= FIELD_PREP(PRESTERA_DSA_DEV_NUM, field);
dsa->port_num = (FIELD_GET(PRESTERA_DSA_W0_PORT_NUM, words[0]) << 0) |
(FIELD_GET(PRESTERA_DSA_W1_PORT_NUM, words[1]) << 5) |
(FIELD_GET(PRESTERA_DSA_W2_PORT_NUM, words[2]) << 7);
return 0;
}
int prestera_dsa_build(const struct prestera_dsa *dsa, u8 *dsa_buf)
{
__be32 *dsa_words = (__be32 *)dsa_buf;
u32 dev_num = dsa->hw_dev_num;
u32 words[4] = { 0 };
words[0] |= FIELD_PREP(PRESTERA_DSA_W0_CMD, PRESTERA_DSA_CMD_FROM_CPU);
words[0] |= FIELD_PREP(PRESTERA_DSA_W0_DEV_NUM, dev_num);
dev_num = FIELD_GET(PRESTERA_DSA_DEV_NUM, dev_num);
words[3] |= FIELD_PREP(PRESTERA_DSA_W3_DEV_NUM, dev_num);
words[3] |= FIELD_PREP(PRESTERA_DSA_W3_DST_EPORT, dsa->port_num);
words[0] |= FIELD_PREP(PRESTERA_DSA_W0_EXT_BIT, 1);
words[1] |= FIELD_PREP(PRESTERA_DSA_W1_EXT_BIT, 1);
words[2] |= FIELD_PREP(PRESTERA_DSA_W2_EXT_BIT, 1);
dsa_words[0] = htonl(words[0]);
dsa_words[1] = htonl(words[1]);
dsa_words[2] = htonl(words[2]);
dsa_words[3] = htonl(words[3]);
return 0;
}
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
/* Copyright (c) 2020 Marvell International Ltd. All rights reserved. */
#ifndef __PRESTERA_DSA_H_
#define __PRESTERA_DSA_H_
#include <linux/types.h>
#define PRESTERA_DSA_HLEN 16
enum prestera_dsa_cmd {
/* DSA command is "To CPU" */
PRESTERA_DSA_CMD_TO_CPU = 0,
/* DSA command is "From CPU" */
PRESTERA_DSA_CMD_FROM_CPU,
};
struct prestera_dsa_vlan {
u16 vid;
u8 vpt;
u8 cfi_bit;
bool is_tagged;
};
struct prestera_dsa {
struct prestera_dsa_vlan vlan;
u32 hw_dev_num;
u32 port_num;
};
int prestera_dsa_parse(struct prestera_dsa *dsa, const u8 *dsa_buf);
int prestera_dsa_build(const struct prestera_dsa *dsa, u8 *dsa_buf);
#endif /* _PRESTERA_DSA_H_ */
This diff is collapsed.
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
/* Copyright (c) 2019-2020 Marvell International Ltd. All rights reserved. */
#ifndef __PRESTERA_ETHTOOL_H_
#define __PRESTERA_ETHTOOL_H_
#include <linux/ethtool.h>
extern const struct ethtool_ops prestera_ethtool_ops;
#endif /* _PRESTERA_ETHTOOL_H_ */
This diff is collapsed.
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
/* Copyright (c) 2019-2020 Marvell International Ltd. All rights reserved. */
#ifndef _PRESTERA_HW_H_
#define _PRESTERA_HW_H_
#include <linux/types.h>
enum prestera_accept_frm_type {
PRESTERA_ACCEPT_FRAME_TYPE_TAGGED,
PRESTERA_ACCEPT_FRAME_TYPE_UNTAGGED,
PRESTERA_ACCEPT_FRAME_TYPE_ALL,
};
enum prestera_fdb_flush_mode {
PRESTERA_FDB_FLUSH_MODE_DYNAMIC = BIT(0),
PRESTERA_FDB_FLUSH_MODE_STATIC = BIT(1),
PRESTERA_FDB_FLUSH_MODE_ALL = PRESTERA_FDB_FLUSH_MODE_DYNAMIC
| PRESTERA_FDB_FLUSH_MODE_STATIC,
};
enum {
PRESTERA_LINK_MODE_10baseT_Half,
PRESTERA_LINK_MODE_10baseT_Full,
PRESTERA_LINK_MODE_100baseT_Half,
PRESTERA_LINK_MODE_100baseT_Full,
PRESTERA_LINK_MODE_1000baseT_Half,
PRESTERA_LINK_MODE_1000baseT_Full,
PRESTERA_LINK_MODE_1000baseX_Full,
PRESTERA_LINK_MODE_1000baseKX_Full,
PRESTERA_LINK_MODE_2500baseX_Full,
PRESTERA_LINK_MODE_10GbaseKR_Full,
PRESTERA_LINK_MODE_10GbaseSR_Full,
PRESTERA_LINK_MODE_10GbaseLR_Full,
PRESTERA_LINK_MODE_20GbaseKR2_Full,
PRESTERA_LINK_MODE_25GbaseCR_Full,
PRESTERA_LINK_MODE_25GbaseKR_Full,
PRESTERA_LINK_MODE_25GbaseSR_Full,
PRESTERA_LINK_MODE_40GbaseKR4_Full,
PRESTERA_LINK_MODE_40GbaseCR4_Full,
PRESTERA_LINK_MODE_40GbaseSR4_Full,
PRESTERA_LINK_MODE_50GbaseCR2_Full,
PRESTERA_LINK_MODE_50GbaseKR2_Full,
PRESTERA_LINK_MODE_50GbaseSR2_Full,
PRESTERA_LINK_MODE_100GbaseKR4_Full,
PRESTERA_LINK_MODE_100GbaseSR4_Full,
PRESTERA_LINK_MODE_100GbaseCR4_Full,
PRESTERA_LINK_MODE_MAX
};
enum {
PRESTERA_PORT_TYPE_NONE,
PRESTERA_PORT_TYPE_TP,
PRESTERA_PORT_TYPE_AUI,
PRESTERA_PORT_TYPE_MII,
PRESTERA_PORT_TYPE_FIBRE,
PRESTERA_PORT_TYPE_BNC,
PRESTERA_PORT_TYPE_DA,
PRESTERA_PORT_TYPE_OTHER,
PRESTERA_PORT_TYPE_MAX
};
enum {
PRESTERA_PORT_TCVR_COPPER,
PRESTERA_PORT_TCVR_SFP,
PRESTERA_PORT_TCVR_MAX
};
enum {
PRESTERA_PORT_FEC_OFF,
PRESTERA_PORT_FEC_BASER,
PRESTERA_PORT_FEC_RS,
PRESTERA_PORT_FEC_MAX
};
enum {
PRESTERA_PORT_DUPLEX_HALF,
PRESTERA_PORT_DUPLEX_FULL,
};
enum {
PRESTERA_STP_DISABLED,
PRESTERA_STP_BLOCK_LISTEN,
PRESTERA_STP_LEARN,
PRESTERA_STP_FORWARD,
};
struct prestera_switch;
struct prestera_port;
struct prestera_port_stats;
struct prestera_port_caps;
enum prestera_event_type;
struct prestera_event;
typedef void (*prestera_event_cb_t)
(struct prestera_switch *sw, struct prestera_event *evt, void *arg);
struct prestera_rxtx_params;
/* Switch API */
int prestera_hw_switch_init(struct prestera_switch *sw);
void prestera_hw_switch_fini(struct prestera_switch *sw);
int prestera_hw_switch_ageing_set(struct prestera_switch *sw, u32 ageing_ms);
int prestera_hw_switch_mac_set(struct prestera_switch *sw, const char *mac);
/* Port API */
int prestera_hw_port_info_get(const struct prestera_port *port,
u32 *dev_id, u32 *hw_id, u16 *fp_id);
int prestera_hw_port_state_set(const struct prestera_port *port,
bool admin_state);
int prestera_hw_port_mtu_set(const struct prestera_port *port, u32 mtu);
int prestera_hw_port_mtu_get(const struct prestera_port *port, u32 *mtu);
int prestera_hw_port_mac_set(const struct prestera_port *port, const char *mac);
int prestera_hw_port_mac_get(const struct prestera_port *port, char *mac);
int prestera_hw_port_cap_get(const struct prestera_port *port,
struct prestera_port_caps *caps);
int prestera_hw_port_remote_cap_get(const struct prestera_port *port,
u64 *link_mode_bitmap);
int prestera_hw_port_remote_fc_get(const struct prestera_port *port,
bool *pause, bool *asym_pause);
int prestera_hw_port_type_get(const struct prestera_port *port, u8 *type);
int prestera_hw_port_fec_get(const struct prestera_port *port, u8 *fec);
int prestera_hw_port_fec_set(const struct prestera_port *port, u8 fec);
int prestera_hw_port_autoneg_set(const struct prestera_port *port,
bool autoneg, u64 link_modes, u8 fec);
int prestera_hw_port_autoneg_restart(struct prestera_port *port);
int prestera_hw_port_duplex_get(const struct prestera_port *port, u8 *duplex);
int prestera_hw_port_stats_get(const struct prestera_port *port,
struct prestera_port_stats *stats);
int prestera_hw_port_link_mode_set(const struct prestera_port *port, u32 mode);
int prestera_hw_port_link_mode_get(const struct prestera_port *port, u32 *mode);
int prestera_hw_port_mdix_get(const struct prestera_port *port, u8 *status,
u8 *admin_mode);
int prestera_hw_port_mdix_set(const struct prestera_port *port, u8 mode);
int prestera_hw_port_speed_get(const struct prestera_port *port, u32 *speed);
int prestera_hw_port_learning_set(struct prestera_port *port, bool enable);
int prestera_hw_port_flood_set(struct prestera_port *port, bool flood);
int prestera_hw_port_accept_frm_type(struct prestera_port *port,
enum prestera_accept_frm_type type);
/* Vlan API */
int prestera_hw_vlan_create(struct prestera_switch *sw, u16 vid);
int prestera_hw_vlan_delete(struct prestera_switch *sw, u16 vid);
int prestera_hw_vlan_port_set(struct prestera_port *port, u16 vid,
bool is_member, bool untagged);
int prestera_hw_vlan_port_vid_set(struct prestera_port *port, u16 vid);
int prestera_hw_vlan_port_stp_set(struct prestera_port *port, u16 vid, u8 state);
/* FDB API */
int prestera_hw_fdb_add(struct prestera_port *port, const unsigned char *mac,
u16 vid, bool dynamic);
int prestera_hw_fdb_del(struct prestera_port *port, const unsigned char *mac,
u16 vid);
int prestera_hw_fdb_flush_port(struct prestera_port *port, u32 mode);
int prestera_hw_fdb_flush_vlan(struct prestera_switch *sw, u16 vid, u32 mode);
int prestera_hw_fdb_flush_port_vlan(struct prestera_port *port, u16 vid,
u32 mode);
/* Bridge API */
int prestera_hw_bridge_create(struct prestera_switch *sw, u16 *bridge_id);
int prestera_hw_bridge_delete(struct prestera_switch *sw, u16 bridge_id);
int prestera_hw_bridge_port_add(struct prestera_port *port, u16 bridge_id);
int prestera_hw_bridge_port_delete(struct prestera_port *port, u16 bridge_id);
/* Event handlers */
int prestera_hw_event_handler_register(struct prestera_switch *sw,
enum prestera_event_type type,
prestera_event_cb_t fn,
void *arg);
void prestera_hw_event_handler_unregister(struct prestera_switch *sw,
enum prestera_event_type type,
prestera_event_cb_t fn);
/* RX/TX */
int prestera_hw_rxtx_init(struct prestera_switch *sw,
struct prestera_rxtx_params *params);
int prestera_hw_rxtx_port_init(struct prestera_port *port);
#endif /* _PRESTERA_HW_H_ */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
/* Copyright (c) 2019-2020 Marvell International Ltd. All rights reserved. */
#ifndef _PRESTERA_RXTX_H_
#define _PRESTERA_RXTX_H_
#include <linux/netdevice.h>
struct prestera_switch;
struct prestera_port;
int prestera_rxtx_switch_init(struct prestera_switch *sw);
void prestera_rxtx_switch_fini(struct prestera_switch *sw);
int prestera_rxtx_port_init(struct prestera_port *port);
netdev_tx_t prestera_rxtx_xmit(struct prestera_port *port, struct sk_buff *skb);
#endif /* _PRESTERA_RXTX_H_ */
This diff is collapsed.
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
/* Copyright (c) 2019-2020 Marvell International Ltd. All rights reserved. */
#ifndef _PRESTERA_SWITCHDEV_H_
#define _PRESTERA_SWITCHDEV_H_
int prestera_switchdev_init(struct prestera_switch *sw);
void prestera_switchdev_fini(struct prestera_switch *sw);
int prestera_bridge_port_event(struct net_device *dev, unsigned long event,
void *ptr);
#endif /* _PRESTERA_SWITCHDEV_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