bae33f2b5a
Since the introduction of the switchdev API, port attributes were transmitted to drivers for offloading using a two-step transactional model, with a prepare phase that was supposed to catch all errors, and a commit phase that was supposed to never fail. Some classes of failures can never be avoided, like hardware access, or memory allocation. In the latter case, merely attempting to move the memory allocation to the preparation phase makes it impossible to avoid memory leaks, since commit91cf8eceff
("switchdev: Remove unused transaction item queue") which has removed the unused mechanism of passing on the allocated memory between one phase and another. It is time we admit that separating the preparation from the commit phase is something that is best left for the driver to decide, and not something that should be baked into the API, especially since there are no switchdev callers that depend on this. This patch removes the struct switchdev_trans member from switchdev port attribute notifier structures, and converts drivers to not look at this member. In part, this patch contains a revert of my previous commit2e554a7a5d
("net: dsa: propagate switchdev vlan_filtering prepare phase to drivers"). For the most part, the conversion was trivial except for: - Rocker's world implementation based on Broadcom OF-DPA had an odd implementation of ofdpa_port_attr_bridge_flags_set. The conversion was done mechanically, by pasting the implementation twice, then only keeping the code that would get executed during prepare phase on top, then only keeping the code that gets executed during the commit phase on bottom, then simplifying the resulting code until this was obtained. - DSA's offloading of STP state, bridge flags, VLAN filtering and multicast router could be converted right away. But the ageing time could not, so a shim was introduced and this was left for a further commit. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Jiri Pirko <jiri@nvidia.com> Reviewed-by: Kurt Kanzenbach <kurt@linutronix.de> # hellcreek Reviewed-by: Linus Walleij <linus.walleij@linaro.org> # RTL8366RB Reviewed-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
149 lines
4.3 KiB
C
149 lines
4.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0+ */
|
|
/* Realtek SMI interface driver defines
|
|
*
|
|
* Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org>
|
|
* Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
|
|
*/
|
|
|
|
#ifndef _REALTEK_SMI_H
|
|
#define _REALTEK_SMI_H
|
|
|
|
#include <linux/phy.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/gpio/consumer.h>
|
|
#include <net/dsa.h>
|
|
|
|
struct realtek_smi_ops;
|
|
struct dentry;
|
|
struct inode;
|
|
struct file;
|
|
|
|
struct rtl8366_mib_counter {
|
|
unsigned int base;
|
|
unsigned int offset;
|
|
unsigned int length;
|
|
const char *name;
|
|
};
|
|
|
|
/**
|
|
* struct rtl8366_vlan_mc - Virtual LAN member configuration
|
|
*/
|
|
struct rtl8366_vlan_mc {
|
|
u16 vid;
|
|
u16 untag;
|
|
u16 member;
|
|
u8 fid;
|
|
u8 priority;
|
|
};
|
|
|
|
struct rtl8366_vlan_4k {
|
|
u16 vid;
|
|
u16 untag;
|
|
u16 member;
|
|
u8 fid;
|
|
};
|
|
|
|
struct realtek_smi {
|
|
struct device *dev;
|
|
struct gpio_desc *reset;
|
|
struct gpio_desc *mdc;
|
|
struct gpio_desc *mdio;
|
|
struct regmap *map;
|
|
struct mii_bus *slave_mii_bus;
|
|
|
|
unsigned int clk_delay;
|
|
u8 cmd_read;
|
|
u8 cmd_write;
|
|
spinlock_t lock; /* Locks around command writes */
|
|
struct dsa_switch *ds;
|
|
struct irq_domain *irqdomain;
|
|
bool leds_disabled;
|
|
|
|
unsigned int cpu_port;
|
|
unsigned int num_ports;
|
|
unsigned int num_vlan_mc;
|
|
unsigned int num_mib_counters;
|
|
struct rtl8366_mib_counter *mib_counters;
|
|
|
|
const struct realtek_smi_ops *ops;
|
|
|
|
int vlan_enabled;
|
|
int vlan4k_enabled;
|
|
|
|
char buf[4096];
|
|
void *chip_data; /* Per-chip extra variant data */
|
|
};
|
|
|
|
/**
|
|
* struct realtek_smi_ops - vtable for the per-SMI-chiptype operations
|
|
* @detect: detects the chiptype
|
|
*/
|
|
struct realtek_smi_ops {
|
|
int (*detect)(struct realtek_smi *smi);
|
|
int (*reset_chip)(struct realtek_smi *smi);
|
|
int (*setup)(struct realtek_smi *smi);
|
|
void (*cleanup)(struct realtek_smi *smi);
|
|
int (*get_mib_counter)(struct realtek_smi *smi,
|
|
int port,
|
|
struct rtl8366_mib_counter *mib,
|
|
u64 *mibvalue);
|
|
int (*get_vlan_mc)(struct realtek_smi *smi, u32 index,
|
|
struct rtl8366_vlan_mc *vlanmc);
|
|
int (*set_vlan_mc)(struct realtek_smi *smi, u32 index,
|
|
const struct rtl8366_vlan_mc *vlanmc);
|
|
int (*get_vlan_4k)(struct realtek_smi *smi, u32 vid,
|
|
struct rtl8366_vlan_4k *vlan4k);
|
|
int (*set_vlan_4k)(struct realtek_smi *smi,
|
|
const struct rtl8366_vlan_4k *vlan4k);
|
|
int (*get_mc_index)(struct realtek_smi *smi, int port, int *val);
|
|
int (*set_mc_index)(struct realtek_smi *smi, int port, int index);
|
|
bool (*is_vlan_valid)(struct realtek_smi *smi, unsigned int vlan);
|
|
int (*enable_vlan)(struct realtek_smi *smi, bool enable);
|
|
int (*enable_vlan4k)(struct realtek_smi *smi, bool enable);
|
|
int (*enable_port)(struct realtek_smi *smi, int port, bool enable);
|
|
int (*phy_read)(struct realtek_smi *smi, int phy, int regnum);
|
|
int (*phy_write)(struct realtek_smi *smi, int phy, int regnum,
|
|
u16 val);
|
|
};
|
|
|
|
struct realtek_smi_variant {
|
|
const struct dsa_switch_ops *ds_ops;
|
|
const struct realtek_smi_ops *ops;
|
|
unsigned int clk_delay;
|
|
u8 cmd_read;
|
|
u8 cmd_write;
|
|
size_t chip_data_sz;
|
|
};
|
|
|
|
/* SMI core calls */
|
|
int realtek_smi_write_reg_noack(struct realtek_smi *smi, u32 addr,
|
|
u32 data);
|
|
int realtek_smi_setup_mdio(struct realtek_smi *smi);
|
|
|
|
/* RTL8366 library helpers */
|
|
int rtl8366_mc_is_used(struct realtek_smi *smi, int mc_index, int *used);
|
|
int rtl8366_set_vlan(struct realtek_smi *smi, int vid, u32 member,
|
|
u32 untag, u32 fid);
|
|
int rtl8366_set_pvid(struct realtek_smi *smi, unsigned int port,
|
|
unsigned int vid);
|
|
int rtl8366_enable_vlan4k(struct realtek_smi *smi, bool enable);
|
|
int rtl8366_enable_vlan(struct realtek_smi *smi, bool enable);
|
|
int rtl8366_reset_vlan(struct realtek_smi *smi);
|
|
int rtl8366_init_vlan(struct realtek_smi *smi);
|
|
int rtl8366_vlan_filtering(struct dsa_switch *ds, int port,
|
|
bool vlan_filtering);
|
|
int rtl8366_vlan_prepare(struct dsa_switch *ds, int port,
|
|
const struct switchdev_obj_port_vlan *vlan);
|
|
void rtl8366_vlan_add(struct dsa_switch *ds, int port,
|
|
const struct switchdev_obj_port_vlan *vlan);
|
|
int rtl8366_vlan_del(struct dsa_switch *ds, int port,
|
|
const struct switchdev_obj_port_vlan *vlan);
|
|
void rtl8366_get_strings(struct dsa_switch *ds, int port, u32 stringset,
|
|
uint8_t *data);
|
|
int rtl8366_get_sset_count(struct dsa_switch *ds, int port, int sset);
|
|
void rtl8366_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data);
|
|
|
|
extern const struct realtek_smi_variant rtl8366rb_variant;
|
|
|
|
#endif /* _REALTEK_SMI_H */
|