1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 2 /* Copyright (c) 2019-2020 Marvell International Ltd. All rights reserved */ 3 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> 9 #include <linux/of.h> 10 #include <linux/of_net.h> 11 #include <linux/if_vlan.h> 12 #include <linux/phylink.h> 13 14 #include "prestera.h" 15 #include "prestera_hw.h" 16 #include "prestera_acl.h" 17 #include "prestera_flow.h" 18 #include "prestera_span.h" 19 #include "prestera_rxtx.h" 20 #include "prestera_devlink.h" 21 #include "prestera_ethtool.h" 22 #include "prestera_counter.h" 23 #include "prestera_switchdev.h" 24 25 #define PRESTERA_MTU_DEFAULT 1536 26 27 #define PRESTERA_STATS_DELAY_MS 1000 28 29 #define PRESTERA_MAC_ADDR_NUM_MAX 255 30 31 static struct workqueue_struct *prestera_wq; 32 static struct workqueue_struct *prestera_owq; 33 34 void prestera_queue_work(struct work_struct *work) 35 { 36 queue_work(prestera_owq, work); 37 } 38 39 int prestera_port_learning_set(struct prestera_port *port, bool learn) 40 { 41 return prestera_hw_port_learning_set(port, learn); 42 } 43 44 int prestera_port_uc_flood_set(struct prestera_port *port, bool flood) 45 { 46 return prestera_hw_port_uc_flood_set(port, flood); 47 } 48 49 int prestera_port_mc_flood_set(struct prestera_port *port, bool flood) 50 { 51 return prestera_hw_port_mc_flood_set(port, flood); 52 } 53 54 int prestera_port_br_locked_set(struct prestera_port *port, bool br_locked) 55 { 56 return prestera_hw_port_br_locked_set(port, br_locked); 57 } 58 59 int prestera_port_pvid_set(struct prestera_port *port, u16 vid) 60 { 61 enum prestera_accept_frm_type frm_type; 62 int err; 63 64 frm_type = PRESTERA_ACCEPT_FRAME_TYPE_TAGGED; 65 66 if (vid) { 67 err = prestera_hw_vlan_port_vid_set(port, vid); 68 if (err) 69 return err; 70 71 frm_type = PRESTERA_ACCEPT_FRAME_TYPE_ALL; 72 } 73 74 err = prestera_hw_port_accept_frm_type(port, frm_type); 75 if (err && frm_type == PRESTERA_ACCEPT_FRAME_TYPE_ALL) 76 prestera_hw_vlan_port_vid_set(port, port->pvid); 77 78 port->pvid = vid; 79 return 0; 80 } 81 82 struct prestera_port *prestera_port_find_by_hwid(struct prestera_switch *sw, 83 u32 dev_id, u32 hw_id) 84 { 85 struct prestera_port *port = NULL, *tmp; 86 87 read_lock(&sw->port_list_lock); 88 list_for_each_entry(tmp, &sw->port_list, list) { 89 if (tmp->dev_id == dev_id && tmp->hw_id == hw_id) { 90 port = tmp; 91 break; 92 } 93 } 94 read_unlock(&sw->port_list_lock); 95 96 return port; 97 } 98 99 struct prestera_port *prestera_find_port(struct prestera_switch *sw, u32 id) 100 { 101 struct prestera_port *port = NULL, *tmp; 102 103 read_lock(&sw->port_list_lock); 104 list_for_each_entry(tmp, &sw->port_list, list) { 105 if (tmp->id == id) { 106 port = tmp; 107 break; 108 } 109 } 110 read_unlock(&sw->port_list_lock); 111 112 return port; 113 } 114 115 struct prestera_switch *prestera_switch_get(struct net_device *dev) 116 { 117 struct prestera_port *port; 118 119 port = prestera_port_dev_lower_find(dev); 120 return port ? port->sw : NULL; 121 } 122 123 int prestera_port_cfg_mac_read(struct prestera_port *port, 124 struct prestera_port_mac_config *cfg) 125 { 126 *cfg = port->cfg_mac; 127 return 0; 128 } 129 130 int prestera_port_cfg_mac_write(struct prestera_port *port, 131 struct prestera_port_mac_config *cfg) 132 { 133 int err; 134 135 err = prestera_hw_port_mac_mode_set(port, cfg->admin, 136 cfg->mode, cfg->inband, cfg->speed, 137 cfg->duplex, cfg->fec); 138 if (err) 139 return err; 140 141 port->cfg_mac = *cfg; 142 return 0; 143 } 144 145 static int prestera_port_open(struct net_device *dev) 146 { 147 struct prestera_port *port = netdev_priv(dev); 148 struct prestera_port_mac_config cfg_mac; 149 int err = 0; 150 151 if (port->phy_link) { 152 phylink_start(port->phy_link); 153 } else { 154 if (port->caps.transceiver == PRESTERA_PORT_TCVR_SFP) { 155 err = prestera_port_cfg_mac_read(port, &cfg_mac); 156 if (!err) { 157 cfg_mac.admin = true; 158 err = prestera_port_cfg_mac_write(port, 159 &cfg_mac); 160 } 161 } else { 162 port->cfg_phy.admin = true; 163 err = prestera_hw_port_phy_mode_set(port, true, 164 port->autoneg, 165 port->cfg_phy.mode, 166 port->adver_link_modes, 167 port->cfg_phy.mdix); 168 } 169 } 170 171 netif_start_queue(dev); 172 173 return err; 174 } 175 176 static int prestera_port_close(struct net_device *dev) 177 { 178 struct prestera_port *port = netdev_priv(dev); 179 struct prestera_port_mac_config cfg_mac; 180 int err = 0; 181 182 netif_stop_queue(dev); 183 184 if (port->phy_link) { 185 phylink_stop(port->phy_link); 186 phylink_disconnect_phy(port->phy_link); 187 err = prestera_port_cfg_mac_read(port, &cfg_mac); 188 if (!err) { 189 cfg_mac.admin = false; 190 prestera_port_cfg_mac_write(port, &cfg_mac); 191 } 192 } else { 193 if (port->caps.transceiver == PRESTERA_PORT_TCVR_SFP) { 194 err = prestera_port_cfg_mac_read(port, &cfg_mac); 195 if (!err) { 196 cfg_mac.admin = false; 197 prestera_port_cfg_mac_write(port, &cfg_mac); 198 } 199 } else { 200 port->cfg_phy.admin = false; 201 err = prestera_hw_port_phy_mode_set(port, false, port->autoneg, 202 port->cfg_phy.mode, 203 port->adver_link_modes, 204 port->cfg_phy.mdix); 205 } 206 } 207 208 return err; 209 } 210 211 static void 212 prestera_port_mac_state_cache_read(struct prestera_port *port, 213 struct prestera_port_mac_state *state) 214 { 215 spin_lock(&port->state_mac_lock); 216 *state = port->state_mac; 217 spin_unlock(&port->state_mac_lock); 218 } 219 220 static void 221 prestera_port_mac_state_cache_write(struct prestera_port *port, 222 struct prestera_port_mac_state *state) 223 { 224 spin_lock(&port->state_mac_lock); 225 port->state_mac = *state; 226 spin_unlock(&port->state_mac_lock); 227 } 228 229 static struct prestera_port *prestera_pcs_to_port(struct phylink_pcs *pcs) 230 { 231 return container_of(pcs, struct prestera_port, phylink_pcs); 232 } 233 234 static void prestera_mac_config(struct phylink_config *config, 235 unsigned int an_mode, 236 const struct phylink_link_state *state) 237 { 238 } 239 240 static void prestera_mac_link_down(struct phylink_config *config, 241 unsigned int mode, phy_interface_t interface) 242 { 243 struct net_device *ndev = to_net_dev(config->dev); 244 struct prestera_port *port = netdev_priv(ndev); 245 struct prestera_port_mac_state state_mac; 246 247 /* Invalidate. Parameters will update on next link event. */ 248 memset(&state_mac, 0, sizeof(state_mac)); 249 state_mac.valid = false; 250 prestera_port_mac_state_cache_write(port, &state_mac); 251 } 252 253 static void prestera_mac_link_up(struct phylink_config *config, 254 struct phy_device *phy, 255 unsigned int mode, phy_interface_t interface, 256 int speed, int duplex, 257 bool tx_pause, bool rx_pause) 258 { 259 } 260 261 static struct phylink_pcs * 262 prestera_mac_select_pcs(struct phylink_config *config, 263 phy_interface_t interface) 264 { 265 struct net_device *dev = to_net_dev(config->dev); 266 struct prestera_port *port = netdev_priv(dev); 267 268 return &port->phylink_pcs; 269 } 270 271 static void prestera_pcs_get_state(struct phylink_pcs *pcs, 272 struct phylink_link_state *state) 273 { 274 struct prestera_port *port = container_of(pcs, struct prestera_port, 275 phylink_pcs); 276 struct prestera_port_mac_state smac; 277 278 prestera_port_mac_state_cache_read(port, &smac); 279 280 if (smac.valid) { 281 state->link = smac.oper ? 1 : 0; 282 /* AN is completed, when port is up */ 283 state->an_complete = (smac.oper && port->autoneg) ? 1 : 0; 284 state->speed = smac.speed; 285 state->duplex = smac.duplex; 286 } else { 287 state->link = 0; 288 state->an_complete = 0; 289 } 290 } 291 292 static int prestera_pcs_config(struct phylink_pcs *pcs, 293 unsigned int mode, 294 phy_interface_t interface, 295 const unsigned long *advertising, 296 bool permit_pause_to_mac) 297 { 298 struct prestera_port *port = prestera_pcs_to_port(pcs); 299 struct prestera_port_mac_config cfg_mac; 300 int err; 301 302 err = prestera_port_cfg_mac_read(port, &cfg_mac); 303 if (err) 304 return err; 305 306 cfg_mac.admin = true; 307 cfg_mac.fec = PRESTERA_PORT_FEC_OFF; 308 309 switch (interface) { 310 case PHY_INTERFACE_MODE_10GBASER: 311 cfg_mac.speed = SPEED_10000; 312 cfg_mac.inband = 0; 313 cfg_mac.mode = PRESTERA_MAC_MODE_SR_LR; 314 break; 315 case PHY_INTERFACE_MODE_2500BASEX: 316 cfg_mac.speed = SPEED_2500; 317 cfg_mac.duplex = DUPLEX_FULL; 318 cfg_mac.inband = test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, 319 advertising); 320 cfg_mac.mode = PRESTERA_MAC_MODE_SGMII; 321 break; 322 case PHY_INTERFACE_MODE_SGMII: 323 cfg_mac.inband = 1; 324 cfg_mac.mode = PRESTERA_MAC_MODE_SGMII; 325 break; 326 case PHY_INTERFACE_MODE_1000BASEX: 327 default: 328 cfg_mac.speed = SPEED_1000; 329 cfg_mac.duplex = DUPLEX_FULL; 330 cfg_mac.inband = test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, 331 advertising); 332 cfg_mac.mode = PRESTERA_MAC_MODE_1000BASE_X; 333 break; 334 } 335 336 err = prestera_port_cfg_mac_write(port, &cfg_mac); 337 if (err) 338 return err; 339 340 return 0; 341 } 342 343 static void prestera_pcs_an_restart(struct phylink_pcs *pcs) 344 { 345 /* TODO: add 1000basex AN restart support 346 * (Currently FW has no support for 1000baseX AN restart, but it will in the future, 347 * so as for now the function would stay empty.) 348 */ 349 } 350 351 static const struct phylink_mac_ops prestera_mac_ops = { 352 .validate = phylink_generic_validate, 353 .mac_select_pcs = prestera_mac_select_pcs, 354 .mac_config = prestera_mac_config, 355 .mac_link_down = prestera_mac_link_down, 356 .mac_link_up = prestera_mac_link_up, 357 }; 358 359 static const struct phylink_pcs_ops prestera_pcs_ops = { 360 .pcs_get_state = prestera_pcs_get_state, 361 .pcs_config = prestera_pcs_config, 362 .pcs_an_restart = prestera_pcs_an_restart, 363 }; 364 365 static int prestera_port_sfp_bind(struct prestera_port *port) 366 { 367 struct prestera_switch *sw = port->sw; 368 struct device_node *ports, *node; 369 struct fwnode_handle *fwnode; 370 struct phylink *phy_link; 371 int err; 372 373 if (!sw->np) 374 return 0; 375 376 ports = of_find_node_by_name(sw->np, "ports"); 377 378 for_each_child_of_node(ports, node) { 379 int num; 380 381 err = of_property_read_u32(node, "prestera,port-num", &num); 382 if (err) { 383 dev_err(sw->dev->dev, 384 "device node %pOF has no valid reg property: %d\n", 385 node, err); 386 goto out; 387 } 388 389 if (port->fp_id != num) 390 continue; 391 392 port->phylink_pcs.ops = &prestera_pcs_ops; 393 394 port->phy_config.dev = &port->dev->dev; 395 port->phy_config.type = PHYLINK_NETDEV; 396 397 fwnode = of_fwnode_handle(node); 398 399 __set_bit(PHY_INTERFACE_MODE_10GBASER, 400 port->phy_config.supported_interfaces); 401 __set_bit(PHY_INTERFACE_MODE_2500BASEX, 402 port->phy_config.supported_interfaces); 403 __set_bit(PHY_INTERFACE_MODE_SGMII, 404 port->phy_config.supported_interfaces); 405 __set_bit(PHY_INTERFACE_MODE_1000BASEX, 406 port->phy_config.supported_interfaces); 407 408 port->phy_config.mac_capabilities = 409 MAC_1000 | MAC_2500FD | MAC_10000FD; 410 411 phy_link = phylink_create(&port->phy_config, fwnode, 412 PHY_INTERFACE_MODE_INTERNAL, 413 &prestera_mac_ops); 414 if (IS_ERR(phy_link)) { 415 netdev_err(port->dev, "failed to create phylink\n"); 416 err = PTR_ERR(phy_link); 417 goto out; 418 } 419 420 port->phy_link = phy_link; 421 break; 422 } 423 424 out: 425 of_node_put(ports); 426 return err; 427 } 428 429 static int prestera_port_sfp_unbind(struct prestera_port *port) 430 { 431 if (port->phy_link) 432 phylink_destroy(port->phy_link); 433 434 return 0; 435 } 436 437 static netdev_tx_t prestera_port_xmit(struct sk_buff *skb, 438 struct net_device *dev) 439 { 440 return prestera_rxtx_xmit(netdev_priv(dev), skb); 441 } 442 443 int prestera_is_valid_mac_addr(struct prestera_port *port, const u8 *addr) 444 { 445 if (!is_valid_ether_addr(addr)) 446 return -EADDRNOTAVAIL; 447 448 /* firmware requires that port's MAC address contains first 5 bytes 449 * of the base MAC address 450 */ 451 if (memcmp(port->sw->base_mac, addr, ETH_ALEN - 1)) 452 return -EINVAL; 453 454 return 0; 455 } 456 457 static int prestera_port_set_mac_address(struct net_device *dev, void *p) 458 { 459 struct prestera_port *port = netdev_priv(dev); 460 struct sockaddr *addr = p; 461 int err; 462 463 err = prestera_is_valid_mac_addr(port, addr->sa_data); 464 if (err) 465 return err; 466 467 err = prestera_hw_port_mac_set(port, addr->sa_data); 468 if (err) 469 return err; 470 471 eth_hw_addr_set(dev, addr->sa_data); 472 473 return 0; 474 } 475 476 static int prestera_port_change_mtu(struct net_device *dev, int mtu) 477 { 478 struct prestera_port *port = netdev_priv(dev); 479 int err; 480 481 err = prestera_hw_port_mtu_set(port, mtu); 482 if (err) 483 return err; 484 485 dev->mtu = mtu; 486 487 return 0; 488 } 489 490 static void prestera_port_get_stats64(struct net_device *dev, 491 struct rtnl_link_stats64 *stats) 492 { 493 struct prestera_port *port = netdev_priv(dev); 494 struct prestera_port_stats *port_stats = &port->cached_hw_stats.stats; 495 496 stats->rx_packets = port_stats->broadcast_frames_received + 497 port_stats->multicast_frames_received + 498 port_stats->unicast_frames_received; 499 500 stats->tx_packets = port_stats->broadcast_frames_sent + 501 port_stats->multicast_frames_sent + 502 port_stats->unicast_frames_sent; 503 504 stats->rx_bytes = port_stats->good_octets_received; 505 506 stats->tx_bytes = port_stats->good_octets_sent; 507 508 stats->rx_errors = port_stats->rx_error_frame_received; 509 stats->tx_errors = port_stats->mac_trans_error; 510 511 stats->rx_dropped = port_stats->buffer_overrun; 512 stats->tx_dropped = 0; 513 514 stats->multicast = port_stats->multicast_frames_received; 515 stats->collisions = port_stats->excessive_collision; 516 517 stats->rx_crc_errors = port_stats->bad_crc; 518 } 519 520 static void prestera_port_get_hw_stats(struct prestera_port *port) 521 { 522 prestera_hw_port_stats_get(port, &port->cached_hw_stats.stats); 523 } 524 525 static void prestera_port_stats_update(struct work_struct *work) 526 { 527 struct prestera_port *port = 528 container_of(work, struct prestera_port, 529 cached_hw_stats.caching_dw.work); 530 531 prestera_port_get_hw_stats(port); 532 533 queue_delayed_work(prestera_wq, &port->cached_hw_stats.caching_dw, 534 msecs_to_jiffies(PRESTERA_STATS_DELAY_MS)); 535 } 536 537 static int prestera_port_setup_tc(struct net_device *dev, 538 enum tc_setup_type type, 539 void *type_data) 540 { 541 struct prestera_port *port = netdev_priv(dev); 542 543 switch (type) { 544 case TC_SETUP_BLOCK: 545 return prestera_flow_block_setup(port, type_data); 546 default: 547 return -EOPNOTSUPP; 548 } 549 } 550 551 static const struct net_device_ops prestera_netdev_ops = { 552 .ndo_open = prestera_port_open, 553 .ndo_stop = prestera_port_close, 554 .ndo_start_xmit = prestera_port_xmit, 555 .ndo_setup_tc = prestera_port_setup_tc, 556 .ndo_change_mtu = prestera_port_change_mtu, 557 .ndo_get_stats64 = prestera_port_get_stats64, 558 .ndo_set_mac_address = prestera_port_set_mac_address, 559 .ndo_get_devlink_port = prestera_devlink_get_port, 560 }; 561 562 int prestera_port_autoneg_set(struct prestera_port *port, u64 link_modes) 563 { 564 int err; 565 566 if (port->autoneg && port->adver_link_modes == link_modes) 567 return 0; 568 569 err = prestera_hw_port_phy_mode_set(port, port->cfg_phy.admin, 570 true, 0, link_modes, 571 port->cfg_phy.mdix); 572 if (err) 573 return err; 574 575 port->adver_fec = BIT(PRESTERA_PORT_FEC_OFF); 576 port->adver_link_modes = link_modes; 577 port->cfg_phy.mode = 0; 578 port->autoneg = true; 579 580 return 0; 581 } 582 583 static void prestera_port_list_add(struct prestera_port *port) 584 { 585 write_lock(&port->sw->port_list_lock); 586 list_add(&port->list, &port->sw->port_list); 587 write_unlock(&port->sw->port_list_lock); 588 } 589 590 static void prestera_port_list_del(struct prestera_port *port) 591 { 592 write_lock(&port->sw->port_list_lock); 593 list_del(&port->list); 594 write_unlock(&port->sw->port_list_lock); 595 } 596 597 static int prestera_port_create(struct prestera_switch *sw, u32 id) 598 { 599 struct prestera_port_mac_config cfg_mac; 600 struct prestera_port *port; 601 struct net_device *dev; 602 int err; 603 604 dev = alloc_etherdev(sizeof(*port)); 605 if (!dev) 606 return -ENOMEM; 607 608 port = netdev_priv(dev); 609 610 INIT_LIST_HEAD(&port->vlans_list); 611 port->pvid = PRESTERA_DEFAULT_VID; 612 port->lag = NULL; 613 port->dev = dev; 614 port->id = id; 615 port->sw = sw; 616 617 spin_lock_init(&port->state_mac_lock); 618 619 err = prestera_hw_port_info_get(port, &port->dev_id, &port->hw_id, 620 &port->fp_id); 621 if (err) { 622 dev_err(prestera_dev(sw), "Failed to get port(%u) info\n", id); 623 goto err_port_info_get; 624 } 625 626 err = prestera_devlink_port_register(port); 627 if (err) 628 goto err_dl_port_register; 629 630 dev->features |= NETIF_F_NETNS_LOCAL | NETIF_F_HW_TC; 631 dev->netdev_ops = &prestera_netdev_ops; 632 dev->ethtool_ops = &prestera_ethtool_ops; 633 SET_NETDEV_DEV(dev, sw->dev->dev); 634 635 if (port->caps.transceiver != PRESTERA_PORT_TCVR_SFP) 636 netif_carrier_off(dev); 637 638 dev->mtu = min_t(unsigned int, sw->mtu_max, PRESTERA_MTU_DEFAULT); 639 dev->min_mtu = sw->mtu_min; 640 dev->max_mtu = sw->mtu_max; 641 642 err = prestera_hw_port_mtu_set(port, dev->mtu); 643 if (err) { 644 dev_err(prestera_dev(sw), "Failed to set port(%u) mtu(%d)\n", 645 id, dev->mtu); 646 goto err_port_init; 647 } 648 649 if (port->fp_id >= PRESTERA_MAC_ADDR_NUM_MAX) { 650 err = -EINVAL; 651 goto err_port_init; 652 } 653 654 eth_hw_addr_gen(dev, sw->base_mac, port->fp_id); 655 /* firmware requires that port's MAC address consist of the first 656 * 5 bytes of the base MAC address 657 */ 658 if (memcmp(dev->dev_addr, sw->base_mac, ETH_ALEN - 1)) { 659 dev_warn(prestera_dev(sw), "Port MAC address wraps for port(%u)\n", id); 660 dev_addr_mod(dev, 0, sw->base_mac, ETH_ALEN - 1); 661 } 662 663 err = prestera_hw_port_mac_set(port, dev->dev_addr); 664 if (err) { 665 dev_err(prestera_dev(sw), "Failed to set port(%u) mac addr\n", id); 666 goto err_port_init; 667 } 668 669 err = prestera_hw_port_cap_get(port, &port->caps); 670 if (err) { 671 dev_err(prestera_dev(sw), "Failed to get port(%u) caps\n", id); 672 goto err_port_init; 673 } 674 675 port->adver_link_modes = port->caps.supp_link_modes; 676 port->adver_fec = 0; 677 port->autoneg = true; 678 679 /* initialize config mac */ 680 if (port->caps.transceiver != PRESTERA_PORT_TCVR_SFP) { 681 cfg_mac.admin = true; 682 cfg_mac.mode = PRESTERA_MAC_MODE_INTERNAL; 683 } else { 684 cfg_mac.admin = false; 685 cfg_mac.mode = PRESTERA_MAC_MODE_MAX; 686 } 687 cfg_mac.inband = 0; 688 cfg_mac.speed = 0; 689 cfg_mac.duplex = DUPLEX_UNKNOWN; 690 cfg_mac.fec = PRESTERA_PORT_FEC_OFF; 691 692 err = prestera_port_cfg_mac_write(port, &cfg_mac); 693 if (err) { 694 dev_err(prestera_dev(sw), 695 "Failed to set port(%u) mac mode\n", id); 696 goto err_port_init; 697 } 698 699 /* initialize config phy (if this is inegral) */ 700 if (port->caps.transceiver != PRESTERA_PORT_TCVR_SFP) { 701 port->cfg_phy.mdix = ETH_TP_MDI_AUTO; 702 port->cfg_phy.admin = false; 703 err = prestera_hw_port_phy_mode_set(port, 704 port->cfg_phy.admin, 705 false, 0, 0, 706 port->cfg_phy.mdix); 707 if (err) { 708 dev_err(prestera_dev(sw), 709 "Failed to set port(%u) phy mode\n", id); 710 goto err_port_init; 711 } 712 } 713 714 err = prestera_rxtx_port_init(port); 715 if (err) 716 goto err_port_init; 717 718 INIT_DELAYED_WORK(&port->cached_hw_stats.caching_dw, 719 &prestera_port_stats_update); 720 721 prestera_port_list_add(port); 722 723 err = register_netdev(dev); 724 if (err) 725 goto err_register_netdev; 726 727 prestera_devlink_port_set(port); 728 729 err = prestera_port_sfp_bind(port); 730 if (err) 731 goto err_sfp_bind; 732 733 return 0; 734 735 err_sfp_bind: 736 err_register_netdev: 737 prestera_port_list_del(port); 738 err_port_init: 739 prestera_devlink_port_unregister(port); 740 err_dl_port_register: 741 err_port_info_get: 742 free_netdev(dev); 743 return err; 744 } 745 746 static void prestera_port_destroy(struct prestera_port *port) 747 { 748 struct net_device *dev = port->dev; 749 750 cancel_delayed_work_sync(&port->cached_hw_stats.caching_dw); 751 prestera_devlink_port_clear(port); 752 unregister_netdev(dev); 753 prestera_port_list_del(port); 754 prestera_devlink_port_unregister(port); 755 free_netdev(dev); 756 } 757 758 static void prestera_destroy_ports(struct prestera_switch *sw) 759 { 760 struct prestera_port *port, *tmp; 761 762 list_for_each_entry_safe(port, tmp, &sw->port_list, list) 763 prestera_port_destroy(port); 764 } 765 766 static int prestera_create_ports(struct prestera_switch *sw) 767 { 768 struct prestera_port *port, *tmp; 769 u32 port_idx; 770 int err; 771 772 for (port_idx = 0; port_idx < sw->port_count; port_idx++) { 773 err = prestera_port_create(sw, port_idx); 774 if (err) 775 goto err_port_create; 776 } 777 778 return 0; 779 780 err_port_create: 781 list_for_each_entry_safe(port, tmp, &sw->port_list, list) { 782 prestera_port_sfp_unbind(port); 783 prestera_port_destroy(port); 784 } 785 786 return err; 787 } 788 789 static void prestera_port_handle_event(struct prestera_switch *sw, 790 struct prestera_event *evt, void *arg) 791 { 792 struct prestera_port_mac_state smac; 793 struct prestera_port_event *pevt; 794 struct delayed_work *caching_dw; 795 struct prestera_port *port; 796 797 if (evt->id == PRESTERA_PORT_EVENT_MAC_STATE_CHANGED) { 798 pevt = &evt->port_evt; 799 port = prestera_find_port(sw, pevt->port_id); 800 if (!port || !port->dev) 801 return; 802 803 caching_dw = &port->cached_hw_stats.caching_dw; 804 805 memset(&smac, 0, sizeof(smac)); 806 smac.valid = true; 807 smac.oper = pevt->data.mac.oper; 808 if (smac.oper) { 809 smac.mode = pevt->data.mac.mode; 810 smac.speed = pevt->data.mac.speed; 811 smac.duplex = pevt->data.mac.duplex; 812 smac.fc = pevt->data.mac.fc; 813 smac.fec = pevt->data.mac.fec; 814 } 815 prestera_port_mac_state_cache_write(port, &smac); 816 817 if (port->state_mac.oper) { 818 if (port->phy_link) 819 phylink_mac_change(port->phy_link, true); 820 else 821 netif_carrier_on(port->dev); 822 823 if (!delayed_work_pending(caching_dw)) 824 queue_delayed_work(prestera_wq, caching_dw, 0); 825 } else { 826 if (port->phy_link) 827 phylink_mac_change(port->phy_link, false); 828 else if (netif_running(port->dev) && netif_carrier_ok(port->dev)) 829 netif_carrier_off(port->dev); 830 831 if (delayed_work_pending(caching_dw)) 832 cancel_delayed_work(caching_dw); 833 } 834 } 835 } 836 837 static int prestera_event_handlers_register(struct prestera_switch *sw) 838 { 839 return prestera_hw_event_handler_register(sw, PRESTERA_EVENT_TYPE_PORT, 840 prestera_port_handle_event, 841 NULL); 842 } 843 844 static void prestera_event_handlers_unregister(struct prestera_switch *sw) 845 { 846 prestera_hw_event_handler_unregister(sw, PRESTERA_EVENT_TYPE_PORT, 847 prestera_port_handle_event); 848 } 849 850 static int prestera_switch_set_base_mac_addr(struct prestera_switch *sw) 851 { 852 struct device_node *base_mac_np; 853 int ret = 0; 854 855 if (sw->np) { 856 base_mac_np = of_parse_phandle(sw->np, "base-mac-provider", 0); 857 if (base_mac_np) { 858 ret = of_get_mac_address(base_mac_np, sw->base_mac); 859 of_node_put(base_mac_np); 860 } 861 } 862 863 if (!is_valid_ether_addr(sw->base_mac) || ret) { 864 eth_random_addr(sw->base_mac); 865 dev_info(prestera_dev(sw), "using random base mac address\n"); 866 } 867 868 return prestera_hw_switch_mac_set(sw, sw->base_mac); 869 } 870 871 struct prestera_lag *prestera_lag_by_id(struct prestera_switch *sw, u16 id) 872 { 873 return id < sw->lag_max ? &sw->lags[id] : NULL; 874 } 875 876 static struct prestera_lag *prestera_lag_by_dev(struct prestera_switch *sw, 877 struct net_device *dev) 878 { 879 struct prestera_lag *lag; 880 u16 id; 881 882 for (id = 0; id < sw->lag_max; id++) { 883 lag = &sw->lags[id]; 884 if (lag->dev == dev) 885 return lag; 886 } 887 888 return NULL; 889 } 890 891 int prestera_lag_id(struct prestera_switch *sw, 892 struct net_device *lag_dev, u16 *lag_id) 893 { 894 struct prestera_lag *lag; 895 int free_id = -1; 896 int id; 897 898 for (id = 0; id < sw->lag_max; id++) { 899 lag = prestera_lag_by_id(sw, id); 900 if (lag->member_count) { 901 if (lag->dev == lag_dev) { 902 *lag_id = id; 903 return 0; 904 } 905 } else if (free_id < 0) { 906 free_id = id; 907 } 908 } 909 if (free_id < 0) 910 return -ENOSPC; 911 *lag_id = free_id; 912 return 0; 913 } 914 915 static struct prestera_lag *prestera_lag_create(struct prestera_switch *sw, 916 struct net_device *lag_dev) 917 { 918 struct prestera_lag *lag = NULL; 919 u16 id; 920 921 for (id = 0; id < sw->lag_max; id++) { 922 lag = &sw->lags[id]; 923 if (!lag->dev) 924 break; 925 } 926 if (lag) { 927 INIT_LIST_HEAD(&lag->members); 928 lag->dev = lag_dev; 929 } 930 931 return lag; 932 } 933 934 static void prestera_lag_destroy(struct prestera_switch *sw, 935 struct prestera_lag *lag) 936 { 937 WARN_ON(!list_empty(&lag->members)); 938 lag->member_count = 0; 939 lag->dev = NULL; 940 } 941 942 static int prestera_lag_port_add(struct prestera_port *port, 943 struct net_device *lag_dev) 944 { 945 struct prestera_switch *sw = port->sw; 946 struct prestera_lag *lag; 947 int err; 948 949 lag = prestera_lag_by_dev(sw, lag_dev); 950 if (!lag) { 951 lag = prestera_lag_create(sw, lag_dev); 952 if (!lag) 953 return -ENOSPC; 954 } 955 956 if (lag->member_count >= sw->lag_member_max) 957 return -ENOSPC; 958 959 err = prestera_hw_lag_member_add(port, lag->lag_id); 960 if (err) { 961 if (!lag->member_count) 962 prestera_lag_destroy(sw, lag); 963 return err; 964 } 965 966 list_add(&port->lag_member, &lag->members); 967 lag->member_count++; 968 port->lag = lag; 969 970 return 0; 971 } 972 973 static int prestera_lag_port_del(struct prestera_port *port) 974 { 975 struct prestera_switch *sw = port->sw; 976 struct prestera_lag *lag = port->lag; 977 int err; 978 979 if (!lag || !lag->member_count) 980 return -EINVAL; 981 982 err = prestera_hw_lag_member_del(port, lag->lag_id); 983 if (err) 984 return err; 985 986 list_del(&port->lag_member); 987 lag->member_count--; 988 port->lag = NULL; 989 990 if (netif_is_bridge_port(lag->dev)) { 991 struct net_device *br_dev; 992 993 br_dev = netdev_master_upper_dev_get(lag->dev); 994 995 prestera_bridge_port_leave(br_dev, port); 996 } 997 998 if (!lag->member_count) 999 prestera_lag_destroy(sw, lag); 1000 1001 return 0; 1002 } 1003 1004 bool prestera_port_is_lag_member(const struct prestera_port *port) 1005 { 1006 return !!port->lag; 1007 } 1008 1009 u16 prestera_port_lag_id(const struct prestera_port *port) 1010 { 1011 return port->lag->lag_id; 1012 } 1013 1014 static int prestera_lag_init(struct prestera_switch *sw) 1015 { 1016 u16 id; 1017 1018 sw->lags = kcalloc(sw->lag_max, sizeof(*sw->lags), GFP_KERNEL); 1019 if (!sw->lags) 1020 return -ENOMEM; 1021 1022 for (id = 0; id < sw->lag_max; id++) 1023 sw->lags[id].lag_id = id; 1024 1025 return 0; 1026 } 1027 1028 static void prestera_lag_fini(struct prestera_switch *sw) 1029 { 1030 u8 idx; 1031 1032 for (idx = 0; idx < sw->lag_max; idx++) 1033 WARN_ON(sw->lags[idx].member_count); 1034 1035 kfree(sw->lags); 1036 } 1037 1038 bool prestera_netdev_check(const struct net_device *dev) 1039 { 1040 return dev->netdev_ops == &prestera_netdev_ops; 1041 } 1042 1043 static int prestera_lower_dev_walk(struct net_device *dev, 1044 struct netdev_nested_priv *priv) 1045 { 1046 struct prestera_port **pport = (struct prestera_port **)priv->data; 1047 1048 if (prestera_netdev_check(dev)) { 1049 *pport = netdev_priv(dev); 1050 return 1; 1051 } 1052 1053 return 0; 1054 } 1055 1056 struct prestera_port *prestera_port_dev_lower_find(struct net_device *dev) 1057 { 1058 struct prestera_port *port = NULL; 1059 struct netdev_nested_priv priv = { 1060 .data = (void *)&port, 1061 }; 1062 1063 if (prestera_netdev_check(dev)) 1064 return netdev_priv(dev); 1065 1066 netdev_walk_all_lower_dev(dev, prestera_lower_dev_walk, &priv); 1067 1068 return port; 1069 } 1070 1071 static int prestera_netdev_port_lower_event(struct net_device *dev, 1072 unsigned long event, void *ptr) 1073 { 1074 struct netdev_notifier_changelowerstate_info *info = ptr; 1075 struct netdev_lag_lower_state_info *lower_state_info; 1076 struct prestera_port *port = netdev_priv(dev); 1077 bool enabled; 1078 1079 if (!netif_is_lag_port(dev)) 1080 return 0; 1081 if (!prestera_port_is_lag_member(port)) 1082 return 0; 1083 1084 lower_state_info = info->lower_state_info; 1085 enabled = lower_state_info->link_up && lower_state_info->tx_enabled; 1086 1087 return prestera_hw_lag_member_enable(port, port->lag->lag_id, enabled); 1088 } 1089 1090 static bool prestera_lag_master_check(struct net_device *lag_dev, 1091 struct netdev_lag_upper_info *info, 1092 struct netlink_ext_ack *ext_ack) 1093 { 1094 if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH) { 1095 NL_SET_ERR_MSG_MOD(ext_ack, "Unsupported LAG Tx type"); 1096 return false; 1097 } 1098 1099 return true; 1100 } 1101 1102 static int prestera_netdev_port_event(struct net_device *lower, 1103 struct net_device *dev, 1104 unsigned long event, void *ptr) 1105 { 1106 struct netdev_notifier_info *info = ptr; 1107 struct netdev_notifier_changeupper_info *cu_info; 1108 struct prestera_port *port = netdev_priv(dev); 1109 struct netlink_ext_ack *extack; 1110 struct net_device *upper; 1111 1112 extack = netdev_notifier_info_to_extack(info); 1113 cu_info = container_of(info, 1114 struct netdev_notifier_changeupper_info, 1115 info); 1116 1117 switch (event) { 1118 case NETDEV_PRECHANGEUPPER: 1119 upper = cu_info->upper_dev; 1120 if (!netif_is_bridge_master(upper) && 1121 !netif_is_lag_master(upper)) { 1122 NL_SET_ERR_MSG_MOD(extack, "Unknown upper device type"); 1123 return -EINVAL; 1124 } 1125 1126 if (!cu_info->linking) 1127 break; 1128 1129 if (netdev_has_any_upper_dev(upper)) { 1130 NL_SET_ERR_MSG_MOD(extack, "Upper device is already enslaved"); 1131 return -EINVAL; 1132 } 1133 1134 if (netif_is_lag_master(upper) && 1135 !prestera_lag_master_check(upper, cu_info->upper_info, extack)) 1136 return -EOPNOTSUPP; 1137 if (netif_is_lag_master(upper) && vlan_uses_dev(dev)) { 1138 NL_SET_ERR_MSG_MOD(extack, 1139 "Master device is a LAG master and port has a VLAN"); 1140 return -EINVAL; 1141 } 1142 if (netif_is_lag_port(dev) && is_vlan_dev(upper) && 1143 !netif_is_lag_master(vlan_dev_real_dev(upper))) { 1144 NL_SET_ERR_MSG_MOD(extack, 1145 "Can not put a VLAN on a LAG port"); 1146 return -EINVAL; 1147 } 1148 break; 1149 1150 case NETDEV_CHANGEUPPER: 1151 upper = cu_info->upper_dev; 1152 if (netif_is_bridge_master(upper)) { 1153 if (cu_info->linking) 1154 return prestera_bridge_port_join(upper, port, 1155 extack); 1156 else 1157 prestera_bridge_port_leave(upper, port); 1158 } else if (netif_is_lag_master(upper)) { 1159 if (cu_info->linking) 1160 return prestera_lag_port_add(port, upper); 1161 else 1162 prestera_lag_port_del(port); 1163 } 1164 break; 1165 1166 case NETDEV_CHANGELOWERSTATE: 1167 return prestera_netdev_port_lower_event(dev, event, ptr); 1168 } 1169 1170 return 0; 1171 } 1172 1173 static int prestera_netdevice_lag_event(struct net_device *lag_dev, 1174 unsigned long event, void *ptr) 1175 { 1176 struct net_device *dev; 1177 struct list_head *iter; 1178 int err; 1179 1180 netdev_for_each_lower_dev(lag_dev, dev, iter) { 1181 if (prestera_netdev_check(dev)) { 1182 err = prestera_netdev_port_event(lag_dev, dev, event, 1183 ptr); 1184 if (err) 1185 return err; 1186 } 1187 } 1188 1189 return 0; 1190 } 1191 1192 static int prestera_netdev_event_handler(struct notifier_block *nb, 1193 unsigned long event, void *ptr) 1194 { 1195 struct net_device *dev = netdev_notifier_info_to_dev(ptr); 1196 int err = 0; 1197 1198 if (prestera_netdev_check(dev)) 1199 err = prestera_netdev_port_event(dev, dev, event, ptr); 1200 else if (netif_is_lag_master(dev)) 1201 err = prestera_netdevice_lag_event(dev, event, ptr); 1202 1203 return notifier_from_errno(err); 1204 } 1205 1206 struct prestera_mdb_entry * 1207 prestera_mdb_entry_create(struct prestera_switch *sw, 1208 const unsigned char *addr, u16 vid) 1209 { 1210 struct prestera_flood_domain *flood_domain; 1211 struct prestera_mdb_entry *mdb_entry; 1212 1213 mdb_entry = kzalloc(sizeof(*mdb_entry), GFP_KERNEL); 1214 if (!mdb_entry) 1215 goto err_mdb_alloc; 1216 1217 flood_domain = prestera_flood_domain_create(sw); 1218 if (!flood_domain) 1219 goto err_flood_domain_create; 1220 1221 mdb_entry->sw = sw; 1222 mdb_entry->vid = vid; 1223 mdb_entry->flood_domain = flood_domain; 1224 ether_addr_copy(mdb_entry->addr, addr); 1225 1226 if (prestera_hw_mdb_create(mdb_entry)) 1227 goto err_mdb_hw_create; 1228 1229 return mdb_entry; 1230 1231 err_mdb_hw_create: 1232 prestera_flood_domain_destroy(flood_domain); 1233 err_flood_domain_create: 1234 kfree(mdb_entry); 1235 err_mdb_alloc: 1236 return NULL; 1237 } 1238 1239 void prestera_mdb_entry_destroy(struct prestera_mdb_entry *mdb_entry) 1240 { 1241 prestera_hw_mdb_destroy(mdb_entry); 1242 prestera_flood_domain_destroy(mdb_entry->flood_domain); 1243 kfree(mdb_entry); 1244 } 1245 1246 struct prestera_flood_domain * 1247 prestera_flood_domain_create(struct prestera_switch *sw) 1248 { 1249 struct prestera_flood_domain *domain; 1250 1251 domain = kzalloc(sizeof(*domain), GFP_KERNEL); 1252 if (!domain) 1253 return NULL; 1254 1255 domain->sw = sw; 1256 1257 if (prestera_hw_flood_domain_create(domain)) { 1258 kfree(domain); 1259 return NULL; 1260 } 1261 1262 INIT_LIST_HEAD(&domain->flood_domain_port_list); 1263 1264 return domain; 1265 } 1266 1267 void prestera_flood_domain_destroy(struct prestera_flood_domain *flood_domain) 1268 { 1269 WARN_ON(!list_empty(&flood_domain->flood_domain_port_list)); 1270 WARN_ON_ONCE(prestera_hw_flood_domain_destroy(flood_domain)); 1271 kfree(flood_domain); 1272 } 1273 1274 int 1275 prestera_flood_domain_port_create(struct prestera_flood_domain *flood_domain, 1276 struct net_device *dev, 1277 u16 vid) 1278 { 1279 struct prestera_flood_domain_port *flood_domain_port; 1280 bool is_first_port_in_list = false; 1281 int err; 1282 1283 flood_domain_port = kzalloc(sizeof(*flood_domain_port), GFP_KERNEL); 1284 if (!flood_domain_port) { 1285 err = -ENOMEM; 1286 goto err_port_alloc; 1287 } 1288 1289 flood_domain_port->vid = vid; 1290 1291 if (list_empty(&flood_domain->flood_domain_port_list)) 1292 is_first_port_in_list = true; 1293 1294 list_add(&flood_domain_port->flood_domain_port_node, 1295 &flood_domain->flood_domain_port_list); 1296 1297 flood_domain_port->flood_domain = flood_domain; 1298 flood_domain_port->dev = dev; 1299 1300 if (!is_first_port_in_list) { 1301 err = prestera_hw_flood_domain_ports_reset(flood_domain); 1302 if (err) 1303 goto err_prestera_mdb_port_create_hw; 1304 } 1305 1306 err = prestera_hw_flood_domain_ports_set(flood_domain); 1307 if (err) 1308 goto err_prestera_mdb_port_create_hw; 1309 1310 return 0; 1311 1312 err_prestera_mdb_port_create_hw: 1313 list_del(&flood_domain_port->flood_domain_port_node); 1314 kfree(flood_domain_port); 1315 err_port_alloc: 1316 return err; 1317 } 1318 1319 void 1320 prestera_flood_domain_port_destroy(struct prestera_flood_domain_port *port) 1321 { 1322 struct prestera_flood_domain *flood_domain = port->flood_domain; 1323 1324 list_del(&port->flood_domain_port_node); 1325 1326 WARN_ON_ONCE(prestera_hw_flood_domain_ports_reset(flood_domain)); 1327 1328 if (!list_empty(&flood_domain->flood_domain_port_list)) 1329 WARN_ON_ONCE(prestera_hw_flood_domain_ports_set(flood_domain)); 1330 1331 kfree(port); 1332 } 1333 1334 struct prestera_flood_domain_port * 1335 prestera_flood_domain_port_find(struct prestera_flood_domain *flood_domain, 1336 struct net_device *dev, u16 vid) 1337 { 1338 struct prestera_flood_domain_port *flood_domain_port; 1339 1340 list_for_each_entry(flood_domain_port, 1341 &flood_domain->flood_domain_port_list, 1342 flood_domain_port_node) 1343 if (flood_domain_port->dev == dev && 1344 vid == flood_domain_port->vid) 1345 return flood_domain_port; 1346 1347 return NULL; 1348 } 1349 1350 static int prestera_netdev_event_handler_register(struct prestera_switch *sw) 1351 { 1352 sw->netdev_nb.notifier_call = prestera_netdev_event_handler; 1353 1354 return register_netdevice_notifier(&sw->netdev_nb); 1355 } 1356 1357 static void prestera_netdev_event_handler_unregister(struct prestera_switch *sw) 1358 { 1359 unregister_netdevice_notifier(&sw->netdev_nb); 1360 } 1361 1362 static int prestera_switch_init(struct prestera_switch *sw) 1363 { 1364 int err; 1365 1366 sw->np = of_find_compatible_node(NULL, NULL, "marvell,prestera"); 1367 1368 err = prestera_hw_switch_init(sw); 1369 if (err) { 1370 dev_err(prestera_dev(sw), "Failed to init Switch device\n"); 1371 return err; 1372 } 1373 1374 rwlock_init(&sw->port_list_lock); 1375 INIT_LIST_HEAD(&sw->port_list); 1376 1377 err = prestera_switch_set_base_mac_addr(sw); 1378 if (err) 1379 return err; 1380 1381 err = prestera_netdev_event_handler_register(sw); 1382 if (err) 1383 return err; 1384 1385 err = prestera_router_init(sw); 1386 if (err) 1387 goto err_router_init; 1388 1389 err = prestera_switchdev_init(sw); 1390 if (err) 1391 goto err_swdev_register; 1392 1393 err = prestera_rxtx_switch_init(sw); 1394 if (err) 1395 goto err_rxtx_register; 1396 1397 err = prestera_event_handlers_register(sw); 1398 if (err) 1399 goto err_handlers_register; 1400 1401 err = prestera_counter_init(sw); 1402 if (err) 1403 goto err_counter_init; 1404 1405 err = prestera_acl_init(sw); 1406 if (err) 1407 goto err_acl_init; 1408 1409 err = prestera_span_init(sw); 1410 if (err) 1411 goto err_span_init; 1412 1413 err = prestera_devlink_traps_register(sw); 1414 if (err) 1415 goto err_dl_register; 1416 1417 err = prestera_lag_init(sw); 1418 if (err) 1419 goto err_lag_init; 1420 1421 err = prestera_create_ports(sw); 1422 if (err) 1423 goto err_ports_create; 1424 1425 prestera_devlink_register(sw); 1426 return 0; 1427 1428 err_ports_create: 1429 prestera_lag_fini(sw); 1430 err_lag_init: 1431 prestera_devlink_traps_unregister(sw); 1432 err_dl_register: 1433 prestera_span_fini(sw); 1434 err_span_init: 1435 prestera_acl_fini(sw); 1436 err_acl_init: 1437 prestera_counter_fini(sw); 1438 err_counter_init: 1439 prestera_event_handlers_unregister(sw); 1440 err_handlers_register: 1441 prestera_rxtx_switch_fini(sw); 1442 err_rxtx_register: 1443 prestera_switchdev_fini(sw); 1444 err_swdev_register: 1445 prestera_router_fini(sw); 1446 err_router_init: 1447 prestera_netdev_event_handler_unregister(sw); 1448 prestera_hw_switch_fini(sw); 1449 1450 return err; 1451 } 1452 1453 static void prestera_switch_fini(struct prestera_switch *sw) 1454 { 1455 prestera_devlink_unregister(sw); 1456 prestera_destroy_ports(sw); 1457 prestera_lag_fini(sw); 1458 prestera_devlink_traps_unregister(sw); 1459 prestera_span_fini(sw); 1460 prestera_acl_fini(sw); 1461 prestera_counter_fini(sw); 1462 prestera_event_handlers_unregister(sw); 1463 prestera_rxtx_switch_fini(sw); 1464 prestera_switchdev_fini(sw); 1465 prestera_router_fini(sw); 1466 prestera_netdev_event_handler_unregister(sw); 1467 prestera_hw_switch_fini(sw); 1468 of_node_put(sw->np); 1469 } 1470 1471 int prestera_device_register(struct prestera_device *dev) 1472 { 1473 struct prestera_switch *sw; 1474 int err; 1475 1476 sw = prestera_devlink_alloc(dev); 1477 if (!sw) 1478 return -ENOMEM; 1479 1480 dev->priv = sw; 1481 sw->dev = dev; 1482 1483 err = prestera_switch_init(sw); 1484 if (err) { 1485 prestera_devlink_free(sw); 1486 return err; 1487 } 1488 1489 return 0; 1490 } 1491 EXPORT_SYMBOL(prestera_device_register); 1492 1493 void prestera_device_unregister(struct prestera_device *dev) 1494 { 1495 struct prestera_switch *sw = dev->priv; 1496 1497 prestera_switch_fini(sw); 1498 prestera_devlink_free(sw); 1499 } 1500 EXPORT_SYMBOL(prestera_device_unregister); 1501 1502 static int __init prestera_module_init(void) 1503 { 1504 prestera_wq = alloc_workqueue("prestera", 0, 0); 1505 if (!prestera_wq) 1506 return -ENOMEM; 1507 1508 prestera_owq = alloc_ordered_workqueue("prestera_ordered", 0); 1509 if (!prestera_owq) { 1510 destroy_workqueue(prestera_wq); 1511 return -ENOMEM; 1512 } 1513 1514 return 0; 1515 } 1516 1517 static void __exit prestera_module_exit(void) 1518 { 1519 destroy_workqueue(prestera_wq); 1520 destroy_workqueue(prestera_owq); 1521 } 1522 1523 module_init(prestera_module_init); 1524 module_exit(prestera_module_exit); 1525 1526 MODULE_LICENSE("Dual BSD/GPL"); 1527 MODULE_DESCRIPTION("Marvell Prestera switch driver"); 1528