1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /* Copyright (c) 2019-2020 Marvell International Ltd. All rights reserved */
4 #include <linux/etherdevice.h>
5 #include <linux/jiffies.h>
6 #include <linux/list.h>
7 #include <linux/module.h>
8 #include <linux/netdev_features.h>
10 #include <linux/of_net.h>
11 #include <linux/if_vlan.h>
14 #include "prestera_hw.h"
15 #include "prestera_acl.h"
16 #include "prestera_flow.h"
17 #include "prestera_span.h"
18 #include "prestera_rxtx.h"
19 #include "prestera_devlink.h"
20 #include "prestera_ethtool.h"
21 #include "prestera_counter.h"
22 #include "prestera_switchdev.h"
24 #define PRESTERA_MTU_DEFAULT 1536
26 #define PRESTERA_STATS_DELAY_MS 1000
28 #define PRESTERA_MAC_ADDR_NUM_MAX 255
30 static struct workqueue_struct *prestera_wq;
31 static struct workqueue_struct *prestera_owq;
33 void prestera_queue_work(struct work_struct *work)
35 queue_work(prestera_owq, work);
38 int prestera_port_pvid_set(struct prestera_port *port, u16 vid)
40 enum prestera_accept_frm_type frm_type;
43 frm_type = PRESTERA_ACCEPT_FRAME_TYPE_TAGGED;
46 err = prestera_hw_vlan_port_vid_set(port, vid);
50 frm_type = PRESTERA_ACCEPT_FRAME_TYPE_ALL;
53 err = prestera_hw_port_accept_frm_type(port, frm_type);
54 if (err && frm_type == PRESTERA_ACCEPT_FRAME_TYPE_ALL)
55 prestera_hw_vlan_port_vid_set(port, port->pvid);
61 struct prestera_port *prestera_port_find_by_hwid(struct prestera_switch *sw,
62 u32 dev_id, u32 hw_id)
64 struct prestera_port *port = NULL, *tmp;
66 read_lock(&sw->port_list_lock);
67 list_for_each_entry(tmp, &sw->port_list, list) {
68 if (tmp->dev_id == dev_id && tmp->hw_id == hw_id) {
73 read_unlock(&sw->port_list_lock);
78 struct prestera_port *prestera_find_port(struct prestera_switch *sw, u32 id)
80 struct prestera_port *port = NULL, *tmp;
82 read_lock(&sw->port_list_lock);
83 list_for_each_entry(tmp, &sw->port_list, list) {
89 read_unlock(&sw->port_list_lock);
94 int prestera_port_cfg_mac_read(struct prestera_port *port,
95 struct prestera_port_mac_config *cfg)
101 int prestera_port_cfg_mac_write(struct prestera_port *port,
102 struct prestera_port_mac_config *cfg)
106 err = prestera_hw_port_mac_mode_set(port, cfg->admin,
107 cfg->mode, cfg->inband, cfg->speed,
108 cfg->duplex, cfg->fec);
112 port->cfg_mac = *cfg;
116 static int prestera_port_open(struct net_device *dev)
118 struct prestera_port *port = netdev_priv(dev);
119 struct prestera_port_mac_config cfg_mac;
122 if (port->caps.transceiver == PRESTERA_PORT_TCVR_SFP) {
123 err = prestera_port_cfg_mac_read(port, &cfg_mac);
125 cfg_mac.admin = true;
126 err = prestera_port_cfg_mac_write(port, &cfg_mac);
129 port->cfg_phy.admin = true;
130 err = prestera_hw_port_phy_mode_set(port, true, port->autoneg,
132 port->adver_link_modes,
136 netif_start_queue(dev);
141 static int prestera_port_close(struct net_device *dev)
143 struct prestera_port *port = netdev_priv(dev);
144 struct prestera_port_mac_config cfg_mac;
147 netif_stop_queue(dev);
149 if (port->caps.transceiver == PRESTERA_PORT_TCVR_SFP) {
150 err = prestera_port_cfg_mac_read(port, &cfg_mac);
152 cfg_mac.admin = false;
153 prestera_port_cfg_mac_write(port, &cfg_mac);
156 port->cfg_phy.admin = false;
157 err = prestera_hw_port_phy_mode_set(port, false, port->autoneg,
159 port->adver_link_modes,
166 static netdev_tx_t prestera_port_xmit(struct sk_buff *skb,
167 struct net_device *dev)
169 return prestera_rxtx_xmit(netdev_priv(dev), skb);
172 int prestera_is_valid_mac_addr(struct prestera_port *port, const u8 *addr)
174 if (!is_valid_ether_addr(addr))
175 return -EADDRNOTAVAIL;
177 /* firmware requires that port's MAC address contains first 5 bytes
178 * of the base MAC address
180 if (memcmp(port->sw->base_mac, addr, ETH_ALEN - 1))
186 static int prestera_port_set_mac_address(struct net_device *dev, void *p)
188 struct prestera_port *port = netdev_priv(dev);
189 struct sockaddr *addr = p;
192 err = prestera_is_valid_mac_addr(port, addr->sa_data);
196 err = prestera_hw_port_mac_set(port, addr->sa_data);
200 eth_hw_addr_set(dev, addr->sa_data);
205 static int prestera_port_change_mtu(struct net_device *dev, int mtu)
207 struct prestera_port *port = netdev_priv(dev);
210 err = prestera_hw_port_mtu_set(port, mtu);
219 static void prestera_port_get_stats64(struct net_device *dev,
220 struct rtnl_link_stats64 *stats)
222 struct prestera_port *port = netdev_priv(dev);
223 struct prestera_port_stats *port_stats = &port->cached_hw_stats.stats;
225 stats->rx_packets = port_stats->broadcast_frames_received +
226 port_stats->multicast_frames_received +
227 port_stats->unicast_frames_received;
229 stats->tx_packets = port_stats->broadcast_frames_sent +
230 port_stats->multicast_frames_sent +
231 port_stats->unicast_frames_sent;
233 stats->rx_bytes = port_stats->good_octets_received;
235 stats->tx_bytes = port_stats->good_octets_sent;
237 stats->rx_errors = port_stats->rx_error_frame_received;
238 stats->tx_errors = port_stats->mac_trans_error;
240 stats->rx_dropped = port_stats->buffer_overrun;
241 stats->tx_dropped = 0;
243 stats->multicast = port_stats->multicast_frames_received;
244 stats->collisions = port_stats->excessive_collision;
246 stats->rx_crc_errors = port_stats->bad_crc;
249 static void prestera_port_get_hw_stats(struct prestera_port *port)
251 prestera_hw_port_stats_get(port, &port->cached_hw_stats.stats);
254 static void prestera_port_stats_update(struct work_struct *work)
256 struct prestera_port *port =
257 container_of(work, struct prestera_port,
258 cached_hw_stats.caching_dw.work);
260 prestera_port_get_hw_stats(port);
262 queue_delayed_work(prestera_wq, &port->cached_hw_stats.caching_dw,
263 msecs_to_jiffies(PRESTERA_STATS_DELAY_MS));
266 static int prestera_port_setup_tc(struct net_device *dev,
267 enum tc_setup_type type,
270 struct prestera_port *port = netdev_priv(dev);
274 return prestera_flow_block_setup(port, type_data);
280 static const struct net_device_ops prestera_netdev_ops = {
281 .ndo_open = prestera_port_open,
282 .ndo_stop = prestera_port_close,
283 .ndo_start_xmit = prestera_port_xmit,
284 .ndo_setup_tc = prestera_port_setup_tc,
285 .ndo_change_mtu = prestera_port_change_mtu,
286 .ndo_get_stats64 = prestera_port_get_stats64,
287 .ndo_set_mac_address = prestera_port_set_mac_address,
288 .ndo_get_devlink_port = prestera_devlink_get_port,
291 int prestera_port_autoneg_set(struct prestera_port *port, u64 link_modes)
295 if (port->autoneg && port->adver_link_modes == link_modes)
298 err = prestera_hw_port_phy_mode_set(port, port->cfg_phy.admin,
304 port->adver_fec = BIT(PRESTERA_PORT_FEC_OFF);
305 port->adver_link_modes = link_modes;
306 port->cfg_phy.mode = 0;
307 port->autoneg = true;
312 static void prestera_port_list_add(struct prestera_port *port)
314 write_lock(&port->sw->port_list_lock);
315 list_add(&port->list, &port->sw->port_list);
316 write_unlock(&port->sw->port_list_lock);
319 static void prestera_port_list_del(struct prestera_port *port)
321 write_lock(&port->sw->port_list_lock);
322 list_del(&port->list);
323 write_unlock(&port->sw->port_list_lock);
326 static int prestera_port_create(struct prestera_switch *sw, u32 id)
328 struct prestera_port_mac_config cfg_mac;
329 struct prestera_port *port;
330 struct net_device *dev;
333 dev = alloc_etherdev(sizeof(*port));
337 port = netdev_priv(dev);
339 INIT_LIST_HEAD(&port->vlans_list);
340 port->pvid = PRESTERA_DEFAULT_VID;
346 err = prestera_hw_port_info_get(port, &port->dev_id, &port->hw_id,
349 dev_err(prestera_dev(sw), "Failed to get port(%u) info\n", id);
350 goto err_port_info_get;
353 err = prestera_devlink_port_register(port);
355 goto err_dl_port_register;
357 dev->features |= NETIF_F_NETNS_LOCAL | NETIF_F_HW_TC;
358 dev->netdev_ops = &prestera_netdev_ops;
359 dev->ethtool_ops = &prestera_ethtool_ops;
361 netif_carrier_off(dev);
363 dev->mtu = min_t(unsigned int, sw->mtu_max, PRESTERA_MTU_DEFAULT);
364 dev->min_mtu = sw->mtu_min;
365 dev->max_mtu = sw->mtu_max;
367 err = prestera_hw_port_mtu_set(port, dev->mtu);
369 dev_err(prestera_dev(sw), "Failed to set port(%u) mtu(%d)\n",
374 if (port->fp_id >= PRESTERA_MAC_ADDR_NUM_MAX) {
379 eth_hw_addr_gen(dev, sw->base_mac, port->fp_id);
380 /* firmware requires that port's MAC address consist of the first
381 * 5 bytes of the base MAC address
383 if (memcmp(dev->dev_addr, sw->base_mac, ETH_ALEN - 1)) {
384 dev_warn(prestera_dev(sw), "Port MAC address wraps for port(%u)\n", id);
385 dev_addr_mod(dev, 0, sw->base_mac, ETH_ALEN - 1);
388 err = prestera_hw_port_mac_set(port, dev->dev_addr);
390 dev_err(prestera_dev(sw), "Failed to set port(%u) mac addr\n", id);
394 err = prestera_hw_port_cap_get(port, &port->caps);
396 dev_err(prestera_dev(sw), "Failed to get port(%u) caps\n", id);
400 port->adver_link_modes = port->caps.supp_link_modes;
402 port->autoneg = true;
404 /* initialize config mac */
405 if (port->caps.transceiver != PRESTERA_PORT_TCVR_SFP) {
406 cfg_mac.admin = true;
407 cfg_mac.mode = PRESTERA_MAC_MODE_INTERNAL;
409 cfg_mac.admin = false;
410 cfg_mac.mode = PRESTERA_MAC_MODE_MAX;
412 cfg_mac.inband = false;
414 cfg_mac.duplex = DUPLEX_UNKNOWN;
415 cfg_mac.fec = PRESTERA_PORT_FEC_OFF;
417 err = prestera_port_cfg_mac_write(port, &cfg_mac);
419 dev_err(prestera_dev(sw),
420 "Failed to set port(%u) mac mode\n", id);
424 /* initialize config phy (if this is inegral) */
425 if (port->caps.transceiver != PRESTERA_PORT_TCVR_SFP) {
426 port->cfg_phy.mdix = ETH_TP_MDI_AUTO;
427 port->cfg_phy.admin = false;
428 err = prestera_hw_port_phy_mode_set(port,
433 dev_err(prestera_dev(sw),
434 "Failed to set port(%u) phy mode\n", id);
439 err = prestera_rxtx_port_init(port);
443 INIT_DELAYED_WORK(&port->cached_hw_stats.caching_dw,
444 &prestera_port_stats_update);
446 prestera_port_list_add(port);
448 err = register_netdev(dev);
450 goto err_register_netdev;
452 prestera_devlink_port_set(port);
457 prestera_port_list_del(port);
459 prestera_devlink_port_unregister(port);
460 err_dl_port_register:
466 static void prestera_port_destroy(struct prestera_port *port)
468 struct net_device *dev = port->dev;
470 cancel_delayed_work_sync(&port->cached_hw_stats.caching_dw);
471 prestera_devlink_port_clear(port);
472 unregister_netdev(dev);
473 prestera_port_list_del(port);
474 prestera_devlink_port_unregister(port);
478 static void prestera_destroy_ports(struct prestera_switch *sw)
480 struct prestera_port *port, *tmp;
482 list_for_each_entry_safe(port, tmp, &sw->port_list, list)
483 prestera_port_destroy(port);
486 static int prestera_create_ports(struct prestera_switch *sw)
488 struct prestera_port *port, *tmp;
492 for (port_idx = 0; port_idx < sw->port_count; port_idx++) {
493 err = prestera_port_create(sw, port_idx);
495 goto err_port_create;
501 list_for_each_entry_safe(port, tmp, &sw->port_list, list)
502 prestera_port_destroy(port);
507 static void prestera_port_handle_event(struct prestera_switch *sw,
508 struct prestera_event *evt, void *arg)
510 struct delayed_work *caching_dw;
511 struct prestera_port *port;
513 port = prestera_find_port(sw, evt->port_evt.port_id);
514 if (!port || !port->dev)
517 caching_dw = &port->cached_hw_stats.caching_dw;
519 prestera_ethtool_port_state_changed(port, &evt->port_evt);
521 if (evt->id == PRESTERA_PORT_EVENT_MAC_STATE_CHANGED) {
522 if (port->state_mac.oper) {
523 netif_carrier_on(port->dev);
524 if (!delayed_work_pending(caching_dw))
525 queue_delayed_work(prestera_wq, caching_dw, 0);
526 } else if (netif_running(port->dev) &&
527 netif_carrier_ok(port->dev)) {
528 netif_carrier_off(port->dev);
529 if (delayed_work_pending(caching_dw))
530 cancel_delayed_work(caching_dw);
535 static int prestera_event_handlers_register(struct prestera_switch *sw)
537 return prestera_hw_event_handler_register(sw, PRESTERA_EVENT_TYPE_PORT,
538 prestera_port_handle_event,
542 static void prestera_event_handlers_unregister(struct prestera_switch *sw)
544 prestera_hw_event_handler_unregister(sw, PRESTERA_EVENT_TYPE_PORT,
545 prestera_port_handle_event);
548 static int prestera_switch_set_base_mac_addr(struct prestera_switch *sw)
550 struct device_node *base_mac_np;
551 struct device_node *np;
554 np = of_find_compatible_node(NULL, NULL, "marvell,prestera");
555 base_mac_np = of_parse_phandle(np, "base-mac-provider", 0);
557 ret = of_get_mac_address(base_mac_np, sw->base_mac);
559 eth_random_addr(sw->base_mac);
560 dev_info(prestera_dev(sw), "using random base mac address\n");
562 of_node_put(base_mac_np);
565 return prestera_hw_switch_mac_set(sw, sw->base_mac);
568 struct prestera_lag *prestera_lag_by_id(struct prestera_switch *sw, u16 id)
570 return id < sw->lag_max ? &sw->lags[id] : NULL;
573 static struct prestera_lag *prestera_lag_by_dev(struct prestera_switch *sw,
574 struct net_device *dev)
576 struct prestera_lag *lag;
579 for (id = 0; id < sw->lag_max; id++) {
588 static struct prestera_lag *prestera_lag_create(struct prestera_switch *sw,
589 struct net_device *lag_dev)
591 struct prestera_lag *lag = NULL;
594 for (id = 0; id < sw->lag_max; id++) {
600 INIT_LIST_HEAD(&lag->members);
607 static void prestera_lag_destroy(struct prestera_switch *sw,
608 struct prestera_lag *lag)
610 WARN_ON(!list_empty(&lag->members));
611 lag->member_count = 0;
615 static int prestera_lag_port_add(struct prestera_port *port,
616 struct net_device *lag_dev)
618 struct prestera_switch *sw = port->sw;
619 struct prestera_lag *lag;
622 lag = prestera_lag_by_dev(sw, lag_dev);
624 lag = prestera_lag_create(sw, lag_dev);
629 if (lag->member_count >= sw->lag_member_max)
632 err = prestera_hw_lag_member_add(port, lag->lag_id);
634 if (!lag->member_count)
635 prestera_lag_destroy(sw, lag);
639 list_add(&port->lag_member, &lag->members);
646 static int prestera_lag_port_del(struct prestera_port *port)
648 struct prestera_switch *sw = port->sw;
649 struct prestera_lag *lag = port->lag;
652 if (!lag || !lag->member_count)
655 err = prestera_hw_lag_member_del(port, lag->lag_id);
659 list_del(&port->lag_member);
663 if (netif_is_bridge_port(lag->dev)) {
664 struct net_device *br_dev;
666 br_dev = netdev_master_upper_dev_get(lag->dev);
668 prestera_bridge_port_leave(br_dev, port);
671 if (!lag->member_count)
672 prestera_lag_destroy(sw, lag);
677 bool prestera_port_is_lag_member(const struct prestera_port *port)
682 u16 prestera_port_lag_id(const struct prestera_port *port)
684 return port->lag->lag_id;
687 static int prestera_lag_init(struct prestera_switch *sw)
691 sw->lags = kcalloc(sw->lag_max, sizeof(*sw->lags), GFP_KERNEL);
695 for (id = 0; id < sw->lag_max; id++)
696 sw->lags[id].lag_id = id;
701 static void prestera_lag_fini(struct prestera_switch *sw)
705 for (idx = 0; idx < sw->lag_max; idx++)
706 WARN_ON(sw->lags[idx].member_count);
711 bool prestera_netdev_check(const struct net_device *dev)
713 return dev->netdev_ops == &prestera_netdev_ops;
716 static int prestera_lower_dev_walk(struct net_device *dev,
717 struct netdev_nested_priv *priv)
719 struct prestera_port **pport = (struct prestera_port **)priv->data;
721 if (prestera_netdev_check(dev)) {
722 *pport = netdev_priv(dev);
729 struct prestera_port *prestera_port_dev_lower_find(struct net_device *dev)
731 struct prestera_port *port = NULL;
732 struct netdev_nested_priv priv = {
733 .data = (void *)&port,
736 if (prestera_netdev_check(dev))
737 return netdev_priv(dev);
739 netdev_walk_all_lower_dev(dev, prestera_lower_dev_walk, &priv);
744 static int prestera_netdev_port_lower_event(struct net_device *dev,
745 unsigned long event, void *ptr)
747 struct netdev_notifier_changelowerstate_info *info = ptr;
748 struct netdev_lag_lower_state_info *lower_state_info;
749 struct prestera_port *port = netdev_priv(dev);
752 if (!netif_is_lag_port(dev))
754 if (!prestera_port_is_lag_member(port))
757 lower_state_info = info->lower_state_info;
758 enabled = lower_state_info->link_up && lower_state_info->tx_enabled;
760 return prestera_hw_lag_member_enable(port, port->lag->lag_id, enabled);
763 static bool prestera_lag_master_check(struct net_device *lag_dev,
764 struct netdev_lag_upper_info *info,
765 struct netlink_ext_ack *ext_ack)
767 if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH) {
768 NL_SET_ERR_MSG_MOD(ext_ack, "Unsupported LAG Tx type");
775 static int prestera_netdev_port_event(struct net_device *lower,
776 struct net_device *dev,
777 unsigned long event, void *ptr)
779 struct netdev_notifier_info *info = ptr;
780 struct netdev_notifier_changeupper_info *cu_info;
781 struct prestera_port *port = netdev_priv(dev);
782 struct netlink_ext_ack *extack;
783 struct net_device *upper;
785 extack = netdev_notifier_info_to_extack(info);
786 cu_info = container_of(info,
787 struct netdev_notifier_changeupper_info,
791 case NETDEV_PRECHANGEUPPER:
792 upper = cu_info->upper_dev;
793 if (!netif_is_bridge_master(upper) &&
794 !netif_is_lag_master(upper)) {
795 NL_SET_ERR_MSG_MOD(extack, "Unknown upper device type");
799 if (!cu_info->linking)
802 if (netdev_has_any_upper_dev(upper)) {
803 NL_SET_ERR_MSG_MOD(extack, "Upper device is already enslaved");
807 if (netif_is_lag_master(upper) &&
808 !prestera_lag_master_check(upper, cu_info->upper_info, extack))
810 if (netif_is_lag_master(upper) && vlan_uses_dev(dev)) {
811 NL_SET_ERR_MSG_MOD(extack,
812 "Master device is a LAG master and port has a VLAN");
815 if (netif_is_lag_port(dev) && is_vlan_dev(upper) &&
816 !netif_is_lag_master(vlan_dev_real_dev(upper))) {
817 NL_SET_ERR_MSG_MOD(extack,
818 "Can not put a VLAN on a LAG port");
823 case NETDEV_CHANGEUPPER:
824 upper = cu_info->upper_dev;
825 if (netif_is_bridge_master(upper)) {
826 if (cu_info->linking)
827 return prestera_bridge_port_join(upper, port,
830 prestera_bridge_port_leave(upper, port);
831 } else if (netif_is_lag_master(upper)) {
832 if (cu_info->linking)
833 return prestera_lag_port_add(port, upper);
835 prestera_lag_port_del(port);
839 case NETDEV_CHANGELOWERSTATE:
840 return prestera_netdev_port_lower_event(dev, event, ptr);
846 static int prestera_netdevice_lag_event(struct net_device *lag_dev,
847 unsigned long event, void *ptr)
849 struct net_device *dev;
850 struct list_head *iter;
853 netdev_for_each_lower_dev(lag_dev, dev, iter) {
854 if (prestera_netdev_check(dev)) {
855 err = prestera_netdev_port_event(lag_dev, dev, event,
865 static int prestera_netdev_event_handler(struct notifier_block *nb,
866 unsigned long event, void *ptr)
868 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
871 if (prestera_netdev_check(dev))
872 err = prestera_netdev_port_event(dev, dev, event, ptr);
873 else if (netif_is_lag_master(dev))
874 err = prestera_netdevice_lag_event(dev, event, ptr);
876 return notifier_from_errno(err);
879 static int prestera_netdev_event_handler_register(struct prestera_switch *sw)
881 sw->netdev_nb.notifier_call = prestera_netdev_event_handler;
883 return register_netdevice_notifier(&sw->netdev_nb);
886 static void prestera_netdev_event_handler_unregister(struct prestera_switch *sw)
888 unregister_netdevice_notifier(&sw->netdev_nb);
891 static int prestera_switch_init(struct prestera_switch *sw)
895 err = prestera_hw_switch_init(sw);
897 dev_err(prestera_dev(sw), "Failed to init Switch device\n");
901 rwlock_init(&sw->port_list_lock);
902 INIT_LIST_HEAD(&sw->port_list);
904 err = prestera_switch_set_base_mac_addr(sw);
908 err = prestera_netdev_event_handler_register(sw);
912 err = prestera_router_init(sw);
914 goto err_router_init;
916 err = prestera_switchdev_init(sw);
918 goto err_swdev_register;
920 err = prestera_rxtx_switch_init(sw);
922 goto err_rxtx_register;
924 err = prestera_event_handlers_register(sw);
926 goto err_handlers_register;
928 err = prestera_counter_init(sw);
930 goto err_counter_init;
932 err = prestera_acl_init(sw);
936 err = prestera_span_init(sw);
940 err = prestera_devlink_traps_register(sw);
942 goto err_dl_register;
944 err = prestera_lag_init(sw);
948 err = prestera_create_ports(sw);
950 goto err_ports_create;
952 prestera_devlink_register(sw);
956 prestera_lag_fini(sw);
958 prestera_devlink_traps_unregister(sw);
960 prestera_span_fini(sw);
962 prestera_acl_fini(sw);
964 prestera_counter_fini(sw);
966 prestera_event_handlers_unregister(sw);
967 err_handlers_register:
968 prestera_rxtx_switch_fini(sw);
970 prestera_switchdev_fini(sw);
972 prestera_router_fini(sw);
974 prestera_netdev_event_handler_unregister(sw);
975 prestera_hw_switch_fini(sw);
980 static void prestera_switch_fini(struct prestera_switch *sw)
982 prestera_devlink_unregister(sw);
983 prestera_destroy_ports(sw);
984 prestera_lag_fini(sw);
985 prestera_devlink_traps_unregister(sw);
986 prestera_span_fini(sw);
987 prestera_acl_fini(sw);
988 prestera_counter_fini(sw);
989 prestera_event_handlers_unregister(sw);
990 prestera_rxtx_switch_fini(sw);
991 prestera_switchdev_fini(sw);
992 prestera_router_fini(sw);
993 prestera_netdev_event_handler_unregister(sw);
994 prestera_hw_switch_fini(sw);
997 int prestera_device_register(struct prestera_device *dev)
999 struct prestera_switch *sw;
1002 sw = prestera_devlink_alloc(dev);
1009 err = prestera_switch_init(sw);
1011 prestera_devlink_free(sw);
1017 EXPORT_SYMBOL(prestera_device_register);
1019 void prestera_device_unregister(struct prestera_device *dev)
1021 struct prestera_switch *sw = dev->priv;
1023 prestera_switch_fini(sw);
1024 prestera_devlink_free(sw);
1026 EXPORT_SYMBOL(prestera_device_unregister);
1028 static int __init prestera_module_init(void)
1030 prestera_wq = alloc_workqueue("prestera", 0, 0);
1034 prestera_owq = alloc_ordered_workqueue("prestera_ordered", 0);
1035 if (!prestera_owq) {
1036 destroy_workqueue(prestera_wq);
1043 static void __exit prestera_module_exit(void)
1045 destroy_workqueue(prestera_wq);
1046 destroy_workqueue(prestera_owq);
1049 module_init(prestera_module_init);
1050 module_exit(prestera_module_exit);
1052 MODULE_LICENSE("Dual BSD/GPL");
1053 MODULE_DESCRIPTION("Marvell Prestera switch driver");