.get_sset_count = ksz_sset_count,
.port_bridge_join = ksz_port_bridge_join,
.port_bridge_leave = ksz_port_bridge_leave,
- .port_hsr_join = ksz_hsr_join,
- .port_hsr_leave = ksz_hsr_leave,
.port_set_mac_address = ksz_port_set_mac_address,
.port_stp_state_set = ksz_port_stp_state_set,
.port_teardown = ksz_port_teardown,
.get_sset_count = ksz_sset_count,
.port_bridge_join = ksz_port_bridge_join,
.port_bridge_leave = ksz_port_bridge_leave,
- .port_hsr_join = ksz_hsr_join,
- .port_hsr_leave = ksz_hsr_leave,
.port_set_mac_address = ksz_port_set_mac_address,
.port_stp_state_set = ksz_port_stp_state_set,
.port_teardown = ksz_port_teardown,
.get_sset_count = ksz_sset_count,
.port_bridge_join = ksz_port_bridge_join,
.port_bridge_leave = ksz_port_bridge_leave,
- .port_hsr_join = ksz_hsr_join,
- .port_hsr_leave = ksz_hsr_leave,
.port_set_mac_address = ksz_port_set_mac_address,
.port_stp_state_set = ksz_port_stp_state_set,
.port_teardown = ksz_port_teardown,
#include <linux/platform_data/microchip-ksz.h>
#include <linux/phy.h>
#include <linux/if_bridge.h>
+#include <linux/if_hsr.h>
#include <linux/if_vlan.h>
#include <net/dsa.h>
#include <net/switchdev.h>
*/
#define KSZ9477_SUPPORTED_HSR_FEATURES (NETIF_F_HW_HSR_DUP | NETIF_F_HW_HSR_FWD)
-void ksz9477_hsr_join(struct dsa_switch *ds, int port, struct net_device *hsr)
+static int ksz9477_hsr_join(struct dsa_switch *ds, int port,
+ struct net_device *hsr,
+ struct netlink_ext_ack *extack)
{
struct ksz_device *dev = ds->priv;
struct net_device *user;
struct dsa_port *hsr_dp;
u8 data, hsr_ports = 0;
+ enum hsr_version ver;
+ int ret;
+
+ ret = hsr_get_version(hsr, &ver);
+ if (ret)
+ return ret;
+
+ if (dev->chip_id != KSZ9477_CHIP_ID) {
+ NL_SET_ERR_MSG_MOD(extack, "Chip does not support HSR offload");
+ return -EOPNOTSUPP;
+ }
+
+ /* KSZ9477 can support HW offloading of only 1 HSR device */
+ if (dev->hsr_dev && hsr != dev->hsr_dev) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Offload supported for a single HSR");
+ return -EOPNOTSUPP;
+ }
+
+ /* KSZ9477 only supports HSR v0 and v1 */
+ if (!(ver == HSR_V0 || ver == HSR_V1)) {
+ NL_SET_ERR_MSG_MOD(extack, "Only HSR v0 and v1 supported");
+ return -EOPNOTSUPP;
+ }
+
+ /* KSZ9477 can only perform HSR offloading for up to two ports */
+ if (hweight8(dev->hsr_ports) >= 2) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Cannot offload more than two ports - using software HSR");
+ return -EOPNOTSUPP;
+ }
+
+ /* Self MAC address filtering, to avoid frames traversing
+ * the HSR ring more than once.
+ */
+ ret = ksz_switch_macaddr_get(ds, port, extack);
+ if (ret)
+ return ret;
/* Program which port(s) shall support HSR */
ksz_rmw32(dev, REG_HSR_PORT_MAP__4, BIT(port), BIT(port));
/* Setup HW supported features for lan HSR ports */
user = dsa_to_port(ds, port)->user;
user->features |= KSZ9477_SUPPORTED_HSR_FEATURES;
+
+ dev->hsr_dev = hsr;
+ dev->hsr_ports |= BIT(port);
+
+ return 0;
}
-void ksz9477_hsr_leave(struct dsa_switch *ds, int port, struct net_device *hsr)
+static int ksz9477_hsr_leave(struct dsa_switch *ds, int port,
+ struct net_device *hsr)
{
struct ksz_device *dev = ds->priv;
+ WARN_ON(dev->chip_id != KSZ9477_CHIP_ID);
+
/* Clear port HSR support */
ksz_rmw32(dev, REG_HSR_PORT_MAP__4, BIT(port), 0);
/* Disable per port self-address filtering */
ksz_port_cfg(dev, port, REG_PORT_LUE_CTRL, PORT_SRC_ADDR_FILTER, false);
+
+ dev->hsr_ports &= ~BIT(port);
+ if (!dev->hsr_ports)
+ dev->hsr_dev = NULL;
+
+ ksz_switch_macaddr_put(ds);
+
+ return 0;
}
static int ksz9477_switch_init(struct ksz_device *dev)
.get_sset_count = ksz_sset_count,
.port_bridge_join = ksz_port_bridge_join,
.port_bridge_leave = ksz_port_bridge_leave,
- .port_hsr_join = ksz_hsr_join,
- .port_hsr_leave = ksz_hsr_leave,
+ .port_hsr_join = ksz9477_hsr_join,
+ .port_hsr_leave = ksz9477_hsr_leave,
.port_set_mac_address = ksz_port_set_mac_address,
.port_stp_state_set = ksz_port_stp_state_set,
.port_teardown = ksz_port_teardown,
const struct switchdev_obj_port_mdb *mdb, struct dsa_db db);
int ksz9477_enable_stp_addr(struct ksz_device *dev);
void ksz9477_port_queue_split(struct ksz_device *dev, int port);
-void ksz9477_hsr_join(struct dsa_switch *ds, int port, struct net_device *hsr);
-void ksz9477_hsr_leave(struct dsa_switch *ds, int port, struct net_device *hsr);
int ksz9477_port_acl_init(struct ksz_device *dev, int port);
void ksz9477_port_acl_free(struct ksz_device *dev, int port);
#include <linux/etherdevice.h>
#include <linux/if_bridge.h>
#include <linux/if_vlan.h>
-#include <linux/if_hsr.h>
#include <linux/irq.h>
#include <linux/irqdomain.h>
#include <linux/of.h>
kfree(switch_macaddr);
}
-int ksz_hsr_join(struct dsa_switch *ds, int port, struct net_device *hsr,
- struct netlink_ext_ack *extack)
-{
- struct ksz_device *dev = ds->priv;
- enum hsr_version ver;
- int ret;
-
- ret = hsr_get_version(hsr, &ver);
- if (ret)
- return ret;
-
- if (dev->chip_id != KSZ9477_CHIP_ID) {
- NL_SET_ERR_MSG_MOD(extack, "Chip does not support HSR offload");
- return -EOPNOTSUPP;
- }
-
- /* KSZ9477 can support HW offloading of only 1 HSR device */
- if (dev->hsr_dev && hsr != dev->hsr_dev) {
- NL_SET_ERR_MSG_MOD(extack, "Offload supported for a single HSR");
- return -EOPNOTSUPP;
- }
-
- /* KSZ9477 only supports HSR v0 and v1 */
- if (!(ver == HSR_V0 || ver == HSR_V1)) {
- NL_SET_ERR_MSG_MOD(extack, "Only HSR v0 and v1 supported");
- return -EOPNOTSUPP;
- }
-
- /* KSZ9477 can only perform HSR offloading for up to two ports */
- if (hweight8(dev->hsr_ports) >= 2) {
- NL_SET_ERR_MSG_MOD(extack,
- "Cannot offload more than two ports - using software HSR");
- return -EOPNOTSUPP;
- }
-
- /* Self MAC address filtering, to avoid frames traversing
- * the HSR ring more than once.
- */
- ret = ksz_switch_macaddr_get(ds, port, extack);
- if (ret)
- return ret;
-
- ksz9477_hsr_join(ds, port, hsr);
- dev->hsr_dev = hsr;
- dev->hsr_ports |= BIT(port);
-
- return 0;
-}
-
-int ksz_hsr_leave(struct dsa_switch *ds, int port,
- struct net_device *hsr)
-{
- struct ksz_device *dev = ds->priv;
-
- WARN_ON(dev->chip_id != KSZ9477_CHIP_ID);
-
- ksz9477_hsr_leave(ds, port, hsr);
- dev->hsr_ports &= ~BIT(port);
- if (!dev->hsr_ports)
- dev->hsr_dev = NULL;
-
- ksz_switch_macaddr_put(ds);
-
- return 0;
-}
-
int ksz_suspend(struct dsa_switch *ds)
{
struct ksz_device *dev = ds->priv;
struct ethtool_wolinfo *wol);
int ksz_port_set_mac_address(struct dsa_switch *ds, int port,
const unsigned char *addr);
-int ksz_hsr_join(struct dsa_switch *ds, int port, struct net_device *hsr,
- struct netlink_ext_ack *extack);
-int ksz_hsr_leave(struct dsa_switch *ds, int port,
- struct net_device *hsr);
int ksz_suspend(struct dsa_switch *ds);
int ksz_resume(struct dsa_switch *ds);
.get_sset_count = ksz_sset_count,
.port_bridge_join = ksz_port_bridge_join,
.port_bridge_leave = ksz_port_bridge_leave,
- .port_hsr_join = ksz_hsr_join,
- .port_hsr_leave = ksz_hsr_leave,
.port_set_mac_address = ksz_port_set_mac_address,
.port_stp_state_set = ksz_port_stp_state_set,
.port_teardown = ksz_port_teardown,