slave.c (0ce096db719ebaf46d4faf93e1ed1341c1853919) slave.c (022bba63c3ca02fc074c68b4e7b949bddcf320d6)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * net/dsa/slave.c - Slave device handling
4 * Copyright (c) 2008-2009 Marvell Semiconductor
5 */
6
7#include <linux/list.h>
8#include <linux/etherdevice.h>

--- 9 unchanged lines hidden (view full) ---

18#include <net/selftests.h>
19#include <net/tc_act/tc_mirred.h>
20#include <linux/if_bridge.h>
21#include <linux/if_hsr.h>
22#include <net/dcbnl.h>
23#include <linux/netpoll.h>
24
25#include "dsa_priv.h"
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * net/dsa/slave.c - Slave device handling
4 * Copyright (c) 2008-2009 Marvell Semiconductor
5 */
6
7#include <linux/list.h>
8#include <linux/etherdevice.h>

--- 9 unchanged lines hidden (view full) ---

18#include <net/selftests.h>
19#include <net/tc_act/tc_mirred.h>
20#include <linux/if_bridge.h>
21#include <linux/if_hsr.h>
22#include <net/dcbnl.h>
23#include <linux/netpoll.h>
24
25#include "dsa_priv.h"
26#include "port.h"
26
27static void dsa_slave_standalone_event_work(struct work_struct *work)
28{
29 struct dsa_standalone_event_work *standalone_work =
30 container_of(work, struct dsa_standalone_event_work, work);
31 const unsigned char *addr = standalone_work->addr;
32 struct net_device *dev = standalone_work->dev;
33 struct dsa_port *dp = dsa_slave_to_port(dev);

--- 937 unchanged lines hidden (view full) ---

971 unsigned int start;
972 int i;
973
974 for_each_possible_cpu(i) {
975 u64 tx_packets, tx_bytes, rx_packets, rx_bytes;
976
977 s = per_cpu_ptr(dev->tstats, i);
978 do {
27
28static void dsa_slave_standalone_event_work(struct work_struct *work)
29{
30 struct dsa_standalone_event_work *standalone_work =
31 container_of(work, struct dsa_standalone_event_work, work);
32 const unsigned char *addr = standalone_work->addr;
33 struct net_device *dev = standalone_work->dev;
34 struct dsa_port *dp = dsa_slave_to_port(dev);

--- 937 unchanged lines hidden (view full) ---

972 unsigned int start;
973 int i;
974
975 for_each_possible_cpu(i) {
976 u64 tx_packets, tx_bytes, rx_packets, rx_bytes;
977
978 s = per_cpu_ptr(dev->tstats, i);
979 do {
979 start = u64_stats_fetch_begin_irq(&s->syncp);
980 start = u64_stats_fetch_begin(&s->syncp);
980 tx_packets = u64_stats_read(&s->tx_packets);
981 tx_bytes = u64_stats_read(&s->tx_bytes);
982 rx_packets = u64_stats_read(&s->rx_packets);
983 rx_bytes = u64_stats_read(&s->rx_bytes);
981 tx_packets = u64_stats_read(&s->tx_packets);
982 tx_bytes = u64_stats_read(&s->tx_bytes);
983 rx_packets = u64_stats_read(&s->rx_packets);
984 rx_bytes = u64_stats_read(&s->rx_bytes);
984 } while (u64_stats_fetch_retry_irq(&s->syncp, start));
985 } while (u64_stats_fetch_retry(&s->syncp, start));
985 data[0] += tx_packets;
986 data[1] += tx_bytes;
987 data[2] += rx_packets;
988 data[3] += rx_bytes;
989 }
990 if (ds->ops->get_ethtool_stats)
991 ds->ops->get_ethtool_stats(ds, dp->index, data + 4);
992}

--- 1167 unchanged lines hidden (view full) ---

2160 .self_test = dsa_slave_net_selftest,
2161};
2162
2163static const struct dcbnl_rtnl_ops __maybe_unused dsa_slave_dcbnl_ops = {
2164 .ieee_setapp = dsa_slave_dcbnl_ieee_setapp,
2165 .ieee_delapp = dsa_slave_dcbnl_ieee_delapp,
2166};
2167
986 data[0] += tx_packets;
987 data[1] += tx_bytes;
988 data[2] += rx_packets;
989 data[3] += rx_bytes;
990 }
991 if (ds->ops->get_ethtool_stats)
992 ds->ops->get_ethtool_stats(ds, dp->index, data + 4);
993}

--- 1167 unchanged lines hidden (view full) ---

2161 .self_test = dsa_slave_net_selftest,
2162};
2163
2164static const struct dcbnl_rtnl_ops __maybe_unused dsa_slave_dcbnl_ops = {
2165 .ieee_setapp = dsa_slave_dcbnl_ieee_setapp,
2166 .ieee_delapp = dsa_slave_dcbnl_ieee_delapp,
2167};
2168
2168static struct devlink_port *dsa_slave_get_devlink_port(struct net_device *dev)
2169{
2170 struct dsa_port *dp = dsa_slave_to_port(dev);
2171
2172 return &dp->devlink_port;
2173}
2174
2175static void dsa_slave_get_stats64(struct net_device *dev,
2176 struct rtnl_link_stats64 *s)
2177{
2178 struct dsa_port *dp = dsa_slave_to_port(dev);
2179 struct dsa_switch *ds = dp->ds;
2180
2181 if (ds->ops->get_stats64)
2182 ds->ops->get_stats64(ds, dp->index, s);

--- 31 unchanged lines hidden (view full) ---

2214 .ndo_netpoll_setup = dsa_slave_netpoll_setup,
2215 .ndo_netpoll_cleanup = dsa_slave_netpoll_cleanup,
2216 .ndo_poll_controller = dsa_slave_poll_controller,
2217#endif
2218 .ndo_setup_tc = dsa_slave_setup_tc,
2219 .ndo_get_stats64 = dsa_slave_get_stats64,
2220 .ndo_vlan_rx_add_vid = dsa_slave_vlan_rx_add_vid,
2221 .ndo_vlan_rx_kill_vid = dsa_slave_vlan_rx_kill_vid,
2169static void dsa_slave_get_stats64(struct net_device *dev,
2170 struct rtnl_link_stats64 *s)
2171{
2172 struct dsa_port *dp = dsa_slave_to_port(dev);
2173 struct dsa_switch *ds = dp->ds;
2174
2175 if (ds->ops->get_stats64)
2176 ds->ops->get_stats64(ds, dp->index, s);

--- 31 unchanged lines hidden (view full) ---

2208 .ndo_netpoll_setup = dsa_slave_netpoll_setup,
2209 .ndo_netpoll_cleanup = dsa_slave_netpoll_cleanup,
2210 .ndo_poll_controller = dsa_slave_poll_controller,
2211#endif
2212 .ndo_setup_tc = dsa_slave_setup_tc,
2213 .ndo_get_stats64 = dsa_slave_get_stats64,
2214 .ndo_vlan_rx_add_vid = dsa_slave_vlan_rx_add_vid,
2215 .ndo_vlan_rx_kill_vid = dsa_slave_vlan_rx_kill_vid,
2222 .ndo_get_devlink_port = dsa_slave_get_devlink_port,
2223 .ndo_change_mtu = dsa_slave_change_mtu,
2224 .ndo_fill_forward_path = dsa_slave_fill_forward_path,
2225};
2226
2227static struct device_type dsa_type = {
2228 .name = "dsa",
2229};
2230

--- 138 unchanged lines hidden (view full) ---

2369
2370 return 0;
2371}
2372
2373int dsa_slave_create(struct dsa_port *port)
2374{
2375 struct net_device *master = dsa_port_to_master(port);
2376 struct dsa_switch *ds = port->ds;
2216 .ndo_change_mtu = dsa_slave_change_mtu,
2217 .ndo_fill_forward_path = dsa_slave_fill_forward_path,
2218};
2219
2220static struct device_type dsa_type = {
2221 .name = "dsa",
2222};
2223

--- 138 unchanged lines hidden (view full) ---

2362
2363 return 0;
2364}
2365
2366int dsa_slave_create(struct dsa_port *port)
2367{
2368 struct net_device *master = dsa_port_to_master(port);
2369 struct dsa_switch *ds = port->ds;
2377 const char *name = port->name;
2378 struct net_device *slave_dev;
2379 struct dsa_slave_priv *p;
2370 struct net_device *slave_dev;
2371 struct dsa_slave_priv *p;
2372 const char *name;
2373 int assign_type;
2380 int ret;
2381
2382 if (!ds->num_tx_queues)
2383 ds->num_tx_queues = 1;
2384
2374 int ret;
2375
2376 if (!ds->num_tx_queues)
2377 ds->num_tx_queues = 1;
2378
2379 if (port->name) {
2380 name = port->name;
2381 assign_type = NET_NAME_PREDICTABLE;
2382 } else {
2383 name = "eth%d";
2384 assign_type = NET_NAME_ENUM;
2385 }
2386
2385 slave_dev = alloc_netdev_mqs(sizeof(struct dsa_slave_priv), name,
2387 slave_dev = alloc_netdev_mqs(sizeof(struct dsa_slave_priv), name,
2386 NET_NAME_UNKNOWN, ether_setup,
2388 assign_type, ether_setup,
2387 ds->num_tx_queues, 1);
2388 if (slave_dev == NULL)
2389 return -ENOMEM;
2390
2391 slave_dev->rtnl_link_ops = &dsa_link_ops;
2392 slave_dev->ethtool_ops = &dsa_slave_ethtool_ops;
2393#if IS_ENABLED(CONFIG_DCB)
2394 slave_dev->dcbnl_ops = &dsa_slave_dcbnl_ops;

--- 6 unchanged lines hidden (view full) ---

2401 if (dsa_switch_supports_uc_filtering(ds))
2402 slave_dev->priv_flags |= IFF_UNICAST_FLT;
2403 slave_dev->netdev_ops = &dsa_slave_netdev_ops;
2404 if (ds->ops->port_max_mtu)
2405 slave_dev->max_mtu = ds->ops->port_max_mtu(ds, port->index);
2406 SET_NETDEV_DEVTYPE(slave_dev, &dsa_type);
2407
2408 SET_NETDEV_DEV(slave_dev, port->ds->dev);
2389 ds->num_tx_queues, 1);
2390 if (slave_dev == NULL)
2391 return -ENOMEM;
2392
2393 slave_dev->rtnl_link_ops = &dsa_link_ops;
2394 slave_dev->ethtool_ops = &dsa_slave_ethtool_ops;
2395#if IS_ENABLED(CONFIG_DCB)
2396 slave_dev->dcbnl_ops = &dsa_slave_dcbnl_ops;

--- 6 unchanged lines hidden (view full) ---

2403 if (dsa_switch_supports_uc_filtering(ds))
2404 slave_dev->priv_flags |= IFF_UNICAST_FLT;
2405 slave_dev->netdev_ops = &dsa_slave_netdev_ops;
2406 if (ds->ops->port_max_mtu)
2407 slave_dev->max_mtu = ds->ops->port_max_mtu(ds, port->index);
2408 SET_NETDEV_DEVTYPE(slave_dev, &dsa_type);
2409
2410 SET_NETDEV_DEV(slave_dev, port->ds->dev);
2411 SET_NETDEV_DEVLINK_PORT(slave_dev, &port->devlink_port);
2409 slave_dev->dev.of_node = port->dn;
2410 slave_dev->vlan_features = master->vlan_features;
2411
2412 p = netdev_priv(slave_dev);
2413 slave_dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
2414 if (!slave_dev->tstats) {
2415 free_netdev(slave_dev);
2416 return -ENOMEM;

--- 1074 unchanged lines hidden ---
2412 slave_dev->dev.of_node = port->dn;
2413 slave_dev->vlan_features = master->vlan_features;
2414
2415 p = netdev_priv(slave_dev);
2416 slave_dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
2417 if (!slave_dev->tstats) {
2418 free_netdev(slave_dev);
2419 return -ENOMEM;

--- 1074 unchanged lines hidden ---