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