1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright 2019 NXP Semiconductors 3 * 4 * This is an umbrella module for all network switches that are 5 * register-compatible with Ocelot and that perform I/O to their host CPU 6 * through an NPI (Node Processor Interface) Ethernet port. 7 */ 8 #include <uapi/linux/if_bridge.h> 9 #include <soc/mscc/ocelot_vcap.h> 10 #include <soc/mscc/ocelot_qsys.h> 11 #include <soc/mscc/ocelot_sys.h> 12 #include <soc/mscc/ocelot_dev.h> 13 #include <soc/mscc/ocelot_ana.h> 14 #include <soc/mscc/ocelot_ptp.h> 15 #include <soc/mscc/ocelot.h> 16 #include <linux/platform_device.h> 17 #include <linux/packing.h> 18 #include <linux/module.h> 19 #include <linux/of_net.h> 20 #include <linux/pci.h> 21 #include <linux/of.h> 22 #include <linux/pcs-lynx.h> 23 #include <net/pkt_sched.h> 24 #include <net/dsa.h> 25 #include "felix.h" 26 27 static enum dsa_tag_protocol felix_get_tag_protocol(struct dsa_switch *ds, 28 int port, 29 enum dsa_tag_protocol mp) 30 { 31 return DSA_TAG_PROTO_OCELOT; 32 } 33 34 static int felix_set_ageing_time(struct dsa_switch *ds, 35 unsigned int ageing_time) 36 { 37 struct ocelot *ocelot = ds->priv; 38 39 ocelot_set_ageing_time(ocelot, ageing_time); 40 41 return 0; 42 } 43 44 static int felix_fdb_dump(struct dsa_switch *ds, int port, 45 dsa_fdb_dump_cb_t *cb, void *data) 46 { 47 struct ocelot *ocelot = ds->priv; 48 49 return ocelot_fdb_dump(ocelot, port, cb, data); 50 } 51 52 static int felix_fdb_add(struct dsa_switch *ds, int port, 53 const unsigned char *addr, u16 vid) 54 { 55 struct ocelot *ocelot = ds->priv; 56 57 return ocelot_fdb_add(ocelot, port, addr, vid); 58 } 59 60 static int felix_fdb_del(struct dsa_switch *ds, int port, 61 const unsigned char *addr, u16 vid) 62 { 63 struct ocelot *ocelot = ds->priv; 64 65 return ocelot_fdb_del(ocelot, port, addr, vid); 66 } 67 68 /* This callback needs to be present */ 69 static int felix_mdb_prepare(struct dsa_switch *ds, int port, 70 const struct switchdev_obj_port_mdb *mdb) 71 { 72 return 0; 73 } 74 75 static void felix_mdb_add(struct dsa_switch *ds, int port, 76 const struct switchdev_obj_port_mdb *mdb) 77 { 78 struct ocelot *ocelot = ds->priv; 79 80 ocelot_port_mdb_add(ocelot, port, mdb); 81 } 82 83 static int felix_mdb_del(struct dsa_switch *ds, int port, 84 const struct switchdev_obj_port_mdb *mdb) 85 { 86 struct ocelot *ocelot = ds->priv; 87 88 return ocelot_port_mdb_del(ocelot, port, mdb); 89 } 90 91 static void felix_bridge_stp_state_set(struct dsa_switch *ds, int port, 92 u8 state) 93 { 94 struct ocelot *ocelot = ds->priv; 95 96 return ocelot_bridge_stp_state_set(ocelot, port, state); 97 } 98 99 static int felix_bridge_join(struct dsa_switch *ds, int port, 100 struct net_device *br) 101 { 102 struct ocelot *ocelot = ds->priv; 103 104 return ocelot_port_bridge_join(ocelot, port, br); 105 } 106 107 static void felix_bridge_leave(struct dsa_switch *ds, int port, 108 struct net_device *br) 109 { 110 struct ocelot *ocelot = ds->priv; 111 112 ocelot_port_bridge_leave(ocelot, port, br); 113 } 114 115 /* This callback needs to be present */ 116 static int felix_vlan_prepare(struct dsa_switch *ds, int port, 117 const struct switchdev_obj_port_vlan *vlan) 118 { 119 return 0; 120 } 121 122 static int felix_vlan_filtering(struct dsa_switch *ds, int port, bool enabled) 123 { 124 struct ocelot *ocelot = ds->priv; 125 126 ocelot_port_vlan_filtering(ocelot, port, enabled); 127 128 return 0; 129 } 130 131 static void felix_vlan_add(struct dsa_switch *ds, int port, 132 const struct switchdev_obj_port_vlan *vlan) 133 { 134 struct ocelot *ocelot = ds->priv; 135 u16 flags = vlan->flags; 136 u16 vid; 137 int err; 138 139 if (dsa_is_cpu_port(ds, port)) 140 flags &= ~BRIDGE_VLAN_INFO_UNTAGGED; 141 142 for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) { 143 err = ocelot_vlan_add(ocelot, port, vid, 144 flags & BRIDGE_VLAN_INFO_PVID, 145 flags & BRIDGE_VLAN_INFO_UNTAGGED); 146 if (err) { 147 dev_err(ds->dev, "Failed to add VLAN %d to port %d: %d\n", 148 vid, port, err); 149 return; 150 } 151 } 152 } 153 154 static int felix_vlan_del(struct dsa_switch *ds, int port, 155 const struct switchdev_obj_port_vlan *vlan) 156 { 157 struct ocelot *ocelot = ds->priv; 158 u16 vid; 159 int err; 160 161 for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) { 162 err = ocelot_vlan_del(ocelot, port, vid); 163 if (err) { 164 dev_err(ds->dev, "Failed to remove VLAN %d from port %d: %d\n", 165 vid, port, err); 166 return err; 167 } 168 } 169 return 0; 170 } 171 172 static int felix_port_enable(struct dsa_switch *ds, int port, 173 struct phy_device *phy) 174 { 175 struct ocelot *ocelot = ds->priv; 176 177 ocelot_port_enable(ocelot, port, phy); 178 179 return 0; 180 } 181 182 static void felix_port_disable(struct dsa_switch *ds, int port) 183 { 184 struct ocelot *ocelot = ds->priv; 185 186 return ocelot_port_disable(ocelot, port); 187 } 188 189 static void felix_phylink_validate(struct dsa_switch *ds, int port, 190 unsigned long *supported, 191 struct phylink_link_state *state) 192 { 193 struct ocelot *ocelot = ds->priv; 194 struct felix *felix = ocelot_to_felix(ocelot); 195 196 if (felix->info->phylink_validate) 197 felix->info->phylink_validate(ocelot, port, supported, state); 198 } 199 200 static void felix_phylink_mac_config(struct dsa_switch *ds, int port, 201 unsigned int link_an_mode, 202 const struct phylink_link_state *state) 203 { 204 struct ocelot *ocelot = ds->priv; 205 struct felix *felix = ocelot_to_felix(ocelot); 206 struct dsa_port *dp = dsa_to_port(ds, port); 207 208 if (felix->pcs[port]) 209 phylink_set_pcs(dp->pl, &felix->pcs[port]->pcs); 210 } 211 212 static void felix_phylink_mac_link_down(struct dsa_switch *ds, int port, 213 unsigned int link_an_mode, 214 phy_interface_t interface) 215 { 216 struct ocelot *ocelot = ds->priv; 217 struct ocelot_port *ocelot_port = ocelot->ports[port]; 218 219 ocelot_port_writel(ocelot_port, 0, DEV_MAC_ENA_CFG); 220 ocelot_fields_write(ocelot, port, QSYS_SWITCH_PORT_MODE_PORT_ENA, 0); 221 } 222 223 static void felix_phylink_mac_link_up(struct dsa_switch *ds, int port, 224 unsigned int link_an_mode, 225 phy_interface_t interface, 226 struct phy_device *phydev, 227 int speed, int duplex, 228 bool tx_pause, bool rx_pause) 229 { 230 struct ocelot *ocelot = ds->priv; 231 struct ocelot_port *ocelot_port = ocelot->ports[port]; 232 struct felix *felix = ocelot_to_felix(ocelot); 233 u32 mac_fc_cfg; 234 235 /* Take port out of reset by clearing the MAC_TX_RST, MAC_RX_RST and 236 * PORT_RST bits in DEV_CLOCK_CFG. Note that the way this system is 237 * integrated is that the MAC speed is fixed and it's the PCS who is 238 * performing the rate adaptation, so we have to write "1000Mbps" into 239 * the LINK_SPEED field of DEV_CLOCK_CFG (which is also its default 240 * value). 241 */ 242 ocelot_port_writel(ocelot_port, 243 DEV_CLOCK_CFG_LINK_SPEED(OCELOT_SPEED_1000), 244 DEV_CLOCK_CFG); 245 246 switch (speed) { 247 case SPEED_10: 248 mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(3); 249 break; 250 case SPEED_100: 251 mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(2); 252 break; 253 case SPEED_1000: 254 case SPEED_2500: 255 mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(1); 256 break; 257 default: 258 dev_err(ocelot->dev, "Unsupported speed on port %d: %d\n", 259 port, speed); 260 return; 261 } 262 263 /* handle Rx pause in all cases, with 2500base-X this is used for rate 264 * adaptation. 265 */ 266 mac_fc_cfg |= SYS_MAC_FC_CFG_RX_FC_ENA; 267 268 if (tx_pause) 269 mac_fc_cfg |= SYS_MAC_FC_CFG_TX_FC_ENA | 270 SYS_MAC_FC_CFG_PAUSE_VAL_CFG(0xffff) | 271 SYS_MAC_FC_CFG_FC_LATENCY_CFG(0x7) | 272 SYS_MAC_FC_CFG_ZERO_PAUSE_ENA; 273 274 /* Flow control. Link speed is only used here to evaluate the time 275 * specification in incoming pause frames. 276 */ 277 ocelot_write_rix(ocelot, mac_fc_cfg, SYS_MAC_FC_CFG, port); 278 279 ocelot_write_rix(ocelot, 0, ANA_POL_FLOWC, port); 280 281 /* Undo the effects of felix_phylink_mac_link_down: 282 * enable MAC module 283 */ 284 ocelot_port_writel(ocelot_port, DEV_MAC_ENA_CFG_RX_ENA | 285 DEV_MAC_ENA_CFG_TX_ENA, DEV_MAC_ENA_CFG); 286 287 /* Enable receiving frames on the port, and activate auto-learning of 288 * MAC addresses. 289 */ 290 ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_LEARNAUTO | 291 ANA_PORT_PORT_CFG_RECV_ENA | 292 ANA_PORT_PORT_CFG_PORTID_VAL(port), 293 ANA_PORT_PORT_CFG, port); 294 295 /* Core: Enable port for frame transfer */ 296 ocelot_fields_write(ocelot, port, 297 QSYS_SWITCH_PORT_MODE_PORT_ENA, 1); 298 299 if (felix->info->port_sched_speed_set) 300 felix->info->port_sched_speed_set(ocelot, port, speed); 301 } 302 303 static void felix_port_qos_map_init(struct ocelot *ocelot, int port) 304 { 305 int i; 306 307 ocelot_rmw_gix(ocelot, 308 ANA_PORT_QOS_CFG_QOS_PCP_ENA, 309 ANA_PORT_QOS_CFG_QOS_PCP_ENA, 310 ANA_PORT_QOS_CFG, 311 port); 312 313 for (i = 0; i < FELIX_NUM_TC * 2; i++) { 314 ocelot_rmw_ix(ocelot, 315 (ANA_PORT_PCP_DEI_MAP_DP_PCP_DEI_VAL & i) | 316 ANA_PORT_PCP_DEI_MAP_QOS_PCP_DEI_VAL(i), 317 ANA_PORT_PCP_DEI_MAP_DP_PCP_DEI_VAL | 318 ANA_PORT_PCP_DEI_MAP_QOS_PCP_DEI_VAL_M, 319 ANA_PORT_PCP_DEI_MAP, 320 port, i); 321 } 322 } 323 324 static void felix_get_strings(struct dsa_switch *ds, int port, 325 u32 stringset, u8 *data) 326 { 327 struct ocelot *ocelot = ds->priv; 328 329 return ocelot_get_strings(ocelot, port, stringset, data); 330 } 331 332 static void felix_get_ethtool_stats(struct dsa_switch *ds, int port, u64 *data) 333 { 334 struct ocelot *ocelot = ds->priv; 335 336 ocelot_get_ethtool_stats(ocelot, port, data); 337 } 338 339 static int felix_get_sset_count(struct dsa_switch *ds, int port, int sset) 340 { 341 struct ocelot *ocelot = ds->priv; 342 343 return ocelot_get_sset_count(ocelot, port, sset); 344 } 345 346 static int felix_get_ts_info(struct dsa_switch *ds, int port, 347 struct ethtool_ts_info *info) 348 { 349 struct ocelot *ocelot = ds->priv; 350 351 return ocelot_get_ts_info(ocelot, port, info); 352 } 353 354 static int felix_parse_ports_node(struct felix *felix, 355 struct device_node *ports_node, 356 phy_interface_t *port_phy_modes) 357 { 358 struct ocelot *ocelot = &felix->ocelot; 359 struct device *dev = felix->ocelot.dev; 360 struct device_node *child; 361 362 for_each_available_child_of_node(ports_node, child) { 363 phy_interface_t phy_mode; 364 u32 port; 365 int err; 366 367 /* Get switch port number from DT */ 368 if (of_property_read_u32(child, "reg", &port) < 0) { 369 dev_err(dev, "Port number not defined in device tree " 370 "(property \"reg\")\n"); 371 of_node_put(child); 372 return -ENODEV; 373 } 374 375 /* Get PHY mode from DT */ 376 err = of_get_phy_mode(child, &phy_mode); 377 if (err) { 378 dev_err(dev, "Failed to read phy-mode or " 379 "phy-interface-type property for port %d\n", 380 port); 381 of_node_put(child); 382 return -ENODEV; 383 } 384 385 err = felix->info->prevalidate_phy_mode(ocelot, port, phy_mode); 386 if (err < 0) { 387 dev_err(dev, "Unsupported PHY mode %s on port %d\n", 388 phy_modes(phy_mode), port); 389 return err; 390 } 391 392 port_phy_modes[port] = phy_mode; 393 } 394 395 return 0; 396 } 397 398 static int felix_parse_dt(struct felix *felix, phy_interface_t *port_phy_modes) 399 { 400 struct device *dev = felix->ocelot.dev; 401 struct device_node *switch_node; 402 struct device_node *ports_node; 403 int err; 404 405 switch_node = dev->of_node; 406 407 ports_node = of_get_child_by_name(switch_node, "ports"); 408 if (!ports_node) { 409 dev_err(dev, "Incorrect bindings: absent \"ports\" node\n"); 410 return -ENODEV; 411 } 412 413 err = felix_parse_ports_node(felix, ports_node, port_phy_modes); 414 of_node_put(ports_node); 415 416 return err; 417 } 418 419 static int felix_init_structs(struct felix *felix, int num_phys_ports) 420 { 421 struct ocelot *ocelot = &felix->ocelot; 422 phy_interface_t *port_phy_modes; 423 struct resource res; 424 int port, i, err; 425 426 ocelot->num_phys_ports = num_phys_ports; 427 ocelot->ports = devm_kcalloc(ocelot->dev, num_phys_ports, 428 sizeof(struct ocelot_port *), GFP_KERNEL); 429 if (!ocelot->ports) 430 return -ENOMEM; 431 432 ocelot->map = felix->info->map; 433 ocelot->stats_layout = felix->info->stats_layout; 434 ocelot->num_stats = felix->info->num_stats; 435 ocelot->shared_queue_sz = felix->info->shared_queue_sz; 436 ocelot->num_mact_rows = felix->info->num_mact_rows; 437 ocelot->vcap_is2_keys = felix->info->vcap_is2_keys; 438 ocelot->vcap_is2_actions= felix->info->vcap_is2_actions; 439 ocelot->vcap = felix->info->vcap; 440 ocelot->ops = felix->info->ops; 441 442 port_phy_modes = kcalloc(num_phys_ports, sizeof(phy_interface_t), 443 GFP_KERNEL); 444 if (!port_phy_modes) 445 return -ENOMEM; 446 447 err = felix_parse_dt(felix, port_phy_modes); 448 if (err) { 449 kfree(port_phy_modes); 450 return err; 451 } 452 453 for (i = 0; i < TARGET_MAX; i++) { 454 struct regmap *target; 455 456 if (!felix->info->target_io_res[i].name) 457 continue; 458 459 memcpy(&res, &felix->info->target_io_res[i], sizeof(res)); 460 res.flags = IORESOURCE_MEM; 461 res.start += felix->switch_base; 462 res.end += felix->switch_base; 463 464 target = ocelot_regmap_init(ocelot, &res); 465 if (IS_ERR(target)) { 466 dev_err(ocelot->dev, 467 "Failed to map device memory space\n"); 468 kfree(port_phy_modes); 469 return PTR_ERR(target); 470 } 471 472 ocelot->targets[i] = target; 473 } 474 475 err = ocelot_regfields_init(ocelot, felix->info->regfields); 476 if (err) { 477 dev_err(ocelot->dev, "failed to init reg fields map\n"); 478 kfree(port_phy_modes); 479 return err; 480 } 481 482 for (port = 0; port < num_phys_ports; port++) { 483 struct ocelot_port *ocelot_port; 484 struct regmap *target; 485 u8 *template; 486 487 ocelot_port = devm_kzalloc(ocelot->dev, 488 sizeof(struct ocelot_port), 489 GFP_KERNEL); 490 if (!ocelot_port) { 491 dev_err(ocelot->dev, 492 "failed to allocate port memory\n"); 493 kfree(port_phy_modes); 494 return -ENOMEM; 495 } 496 497 memcpy(&res, &felix->info->port_io_res[port], sizeof(res)); 498 res.flags = IORESOURCE_MEM; 499 res.start += felix->switch_base; 500 res.end += felix->switch_base; 501 502 target = ocelot_regmap_init(ocelot, &res); 503 if (IS_ERR(target)) { 504 dev_err(ocelot->dev, 505 "Failed to map memory space for port %d\n", 506 port); 507 kfree(port_phy_modes); 508 return PTR_ERR(target); 509 } 510 511 template = devm_kzalloc(ocelot->dev, OCELOT_TAG_LEN, 512 GFP_KERNEL); 513 if (!template) { 514 dev_err(ocelot->dev, 515 "Failed to allocate memory for DSA tag\n"); 516 kfree(port_phy_modes); 517 return -ENOMEM; 518 } 519 520 ocelot_port->phy_mode = port_phy_modes[port]; 521 ocelot_port->ocelot = ocelot; 522 ocelot_port->target = target; 523 ocelot_port->xmit_template = template; 524 ocelot->ports[port] = ocelot_port; 525 526 felix->info->xmit_template_populate(ocelot, port); 527 } 528 529 kfree(port_phy_modes); 530 531 if (felix->info->mdio_bus_alloc) { 532 err = felix->info->mdio_bus_alloc(ocelot); 533 if (err < 0) 534 return err; 535 } 536 537 return 0; 538 } 539 540 static struct ptp_clock_info ocelot_ptp_clock_info = { 541 .owner = THIS_MODULE, 542 .name = "felix ptp", 543 .max_adj = 0x7fffffff, 544 .n_alarm = 0, 545 .n_ext_ts = 0, 546 .n_per_out = OCELOT_PTP_PINS_NUM, 547 .n_pins = OCELOT_PTP_PINS_NUM, 548 .pps = 0, 549 .gettime64 = ocelot_ptp_gettime64, 550 .settime64 = ocelot_ptp_settime64, 551 .adjtime = ocelot_ptp_adjtime, 552 .adjfine = ocelot_ptp_adjfine, 553 .verify = ocelot_ptp_verify, 554 .enable = ocelot_ptp_enable, 555 }; 556 557 /* Hardware initialization done here so that we can allocate structures with 558 * devm without fear of dsa_register_switch returning -EPROBE_DEFER and causing 559 * us to allocate structures twice (leak memory) and map PCI memory twice 560 * (which will not work). 561 */ 562 static int felix_setup(struct dsa_switch *ds) 563 { 564 struct ocelot *ocelot = ds->priv; 565 struct felix *felix = ocelot_to_felix(ocelot); 566 int port, err; 567 int tc; 568 569 err = felix_init_structs(felix, ds->num_ports); 570 if (err) 571 return err; 572 573 ocelot_init(ocelot); 574 if (ocelot->ptp) { 575 err = ocelot_init_timestamp(ocelot, &ocelot_ptp_clock_info); 576 if (err) { 577 dev_err(ocelot->dev, 578 "Timestamp initialization failed\n"); 579 ocelot->ptp = 0; 580 } 581 } 582 583 for (port = 0; port < ds->num_ports; port++) { 584 ocelot_init_port(ocelot, port); 585 586 /* Bring up the CPU port module and configure the NPI port */ 587 if (dsa_is_cpu_port(ds, port)) 588 ocelot_configure_cpu(ocelot, port, 589 OCELOT_TAG_PREFIX_NONE, 590 OCELOT_TAG_PREFIX_LONG); 591 592 /* Set the default QoS Classification based on PCP and DEI 593 * bits of vlan tag. 594 */ 595 felix_port_qos_map_init(ocelot, port); 596 } 597 598 /* Include the CPU port module in the forwarding mask for unknown 599 * unicast - the hardware default value for ANA_FLOODING_FLD_UNICAST 600 * excludes BIT(ocelot->num_phys_ports), and so does ocelot_init, since 601 * Ocelot relies on whitelisting MAC addresses towards PGID_CPU. 602 */ 603 ocelot_write_rix(ocelot, 604 ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports, 0)), 605 ANA_PGID_PGID, PGID_UC); 606 /* Setup the per-traffic class flooding PGIDs */ 607 for (tc = 0; tc < FELIX_NUM_TC; tc++) 608 ocelot_write_rix(ocelot, ANA_FLOODING_FLD_MULTICAST(PGID_MC) | 609 ANA_FLOODING_FLD_BROADCAST(PGID_MC) | 610 ANA_FLOODING_FLD_UNICAST(PGID_UC), 611 ANA_FLOODING, tc); 612 613 ds->mtu_enforcement_ingress = true; 614 ds->configure_vlan_while_not_filtering = true; 615 616 return 0; 617 } 618 619 static void felix_teardown(struct dsa_switch *ds) 620 { 621 struct ocelot *ocelot = ds->priv; 622 struct felix *felix = ocelot_to_felix(ocelot); 623 624 if (felix->info->mdio_bus_free) 625 felix->info->mdio_bus_free(ocelot); 626 627 ocelot_deinit_timestamp(ocelot); 628 /* stop workqueue thread */ 629 ocelot_deinit(ocelot); 630 } 631 632 static int felix_hwtstamp_get(struct dsa_switch *ds, int port, 633 struct ifreq *ifr) 634 { 635 struct ocelot *ocelot = ds->priv; 636 637 return ocelot_hwstamp_get(ocelot, port, ifr); 638 } 639 640 static int felix_hwtstamp_set(struct dsa_switch *ds, int port, 641 struct ifreq *ifr) 642 { 643 struct ocelot *ocelot = ds->priv; 644 645 return ocelot_hwstamp_set(ocelot, port, ifr); 646 } 647 648 static bool felix_rxtstamp(struct dsa_switch *ds, int port, 649 struct sk_buff *skb, unsigned int type) 650 { 651 struct skb_shared_hwtstamps *shhwtstamps; 652 struct ocelot *ocelot = ds->priv; 653 u8 *extraction = skb->data - ETH_HLEN - OCELOT_TAG_LEN; 654 u32 tstamp_lo, tstamp_hi; 655 struct timespec64 ts; 656 u64 tstamp, val; 657 658 ocelot_ptp_gettime64(&ocelot->ptp_info, &ts); 659 tstamp = ktime_set(ts.tv_sec, ts.tv_nsec); 660 661 packing(extraction, &val, 116, 85, OCELOT_TAG_LEN, UNPACK, 0); 662 tstamp_lo = (u32)val; 663 664 tstamp_hi = tstamp >> 32; 665 if ((tstamp & 0xffffffff) < tstamp_lo) 666 tstamp_hi--; 667 668 tstamp = ((u64)tstamp_hi << 32) | tstamp_lo; 669 670 shhwtstamps = skb_hwtstamps(skb); 671 memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps)); 672 shhwtstamps->hwtstamp = tstamp; 673 return false; 674 } 675 676 static bool felix_txtstamp(struct dsa_switch *ds, int port, 677 struct sk_buff *clone, unsigned int type) 678 { 679 struct ocelot *ocelot = ds->priv; 680 struct ocelot_port *ocelot_port = ocelot->ports[port]; 681 682 if (!ocelot_port_add_txtstamp_skb(ocelot_port, clone)) 683 return true; 684 685 return false; 686 } 687 688 static int felix_change_mtu(struct dsa_switch *ds, int port, int new_mtu) 689 { 690 struct ocelot *ocelot = ds->priv; 691 692 ocelot_port_set_maxlen(ocelot, port, new_mtu); 693 694 return 0; 695 } 696 697 static int felix_get_max_mtu(struct dsa_switch *ds, int port) 698 { 699 struct ocelot *ocelot = ds->priv; 700 701 return ocelot_get_max_mtu(ocelot, port); 702 } 703 704 static int felix_cls_flower_add(struct dsa_switch *ds, int port, 705 struct flow_cls_offload *cls, bool ingress) 706 { 707 struct ocelot *ocelot = ds->priv; 708 709 return ocelot_cls_flower_replace(ocelot, port, cls, ingress); 710 } 711 712 static int felix_cls_flower_del(struct dsa_switch *ds, int port, 713 struct flow_cls_offload *cls, bool ingress) 714 { 715 struct ocelot *ocelot = ds->priv; 716 717 return ocelot_cls_flower_destroy(ocelot, port, cls, ingress); 718 } 719 720 static int felix_cls_flower_stats(struct dsa_switch *ds, int port, 721 struct flow_cls_offload *cls, bool ingress) 722 { 723 struct ocelot *ocelot = ds->priv; 724 725 return ocelot_cls_flower_stats(ocelot, port, cls, ingress); 726 } 727 728 static int felix_port_policer_add(struct dsa_switch *ds, int port, 729 struct dsa_mall_policer_tc_entry *policer) 730 { 731 struct ocelot *ocelot = ds->priv; 732 struct ocelot_policer pol = { 733 .rate = div_u64(policer->rate_bytes_per_sec, 1000) * 8, 734 .burst = policer->burst, 735 }; 736 737 return ocelot_port_policer_add(ocelot, port, &pol); 738 } 739 740 static void felix_port_policer_del(struct dsa_switch *ds, int port) 741 { 742 struct ocelot *ocelot = ds->priv; 743 744 ocelot_port_policer_del(ocelot, port); 745 } 746 747 static int felix_port_setup_tc(struct dsa_switch *ds, int port, 748 enum tc_setup_type type, 749 void *type_data) 750 { 751 struct ocelot *ocelot = ds->priv; 752 struct felix *felix = ocelot_to_felix(ocelot); 753 754 if (felix->info->port_setup_tc) 755 return felix->info->port_setup_tc(ds, port, type, type_data); 756 else 757 return -EOPNOTSUPP; 758 } 759 760 const struct dsa_switch_ops felix_switch_ops = { 761 .get_tag_protocol = felix_get_tag_protocol, 762 .setup = felix_setup, 763 .teardown = felix_teardown, 764 .set_ageing_time = felix_set_ageing_time, 765 .get_strings = felix_get_strings, 766 .get_ethtool_stats = felix_get_ethtool_stats, 767 .get_sset_count = felix_get_sset_count, 768 .get_ts_info = felix_get_ts_info, 769 .phylink_validate = felix_phylink_validate, 770 .phylink_mac_config = felix_phylink_mac_config, 771 .phylink_mac_link_down = felix_phylink_mac_link_down, 772 .phylink_mac_link_up = felix_phylink_mac_link_up, 773 .port_enable = felix_port_enable, 774 .port_disable = felix_port_disable, 775 .port_fdb_dump = felix_fdb_dump, 776 .port_fdb_add = felix_fdb_add, 777 .port_fdb_del = felix_fdb_del, 778 .port_mdb_prepare = felix_mdb_prepare, 779 .port_mdb_add = felix_mdb_add, 780 .port_mdb_del = felix_mdb_del, 781 .port_bridge_join = felix_bridge_join, 782 .port_bridge_leave = felix_bridge_leave, 783 .port_stp_state_set = felix_bridge_stp_state_set, 784 .port_vlan_prepare = felix_vlan_prepare, 785 .port_vlan_filtering = felix_vlan_filtering, 786 .port_vlan_add = felix_vlan_add, 787 .port_vlan_del = felix_vlan_del, 788 .port_hwtstamp_get = felix_hwtstamp_get, 789 .port_hwtstamp_set = felix_hwtstamp_set, 790 .port_rxtstamp = felix_rxtstamp, 791 .port_txtstamp = felix_txtstamp, 792 .port_change_mtu = felix_change_mtu, 793 .port_max_mtu = felix_get_max_mtu, 794 .port_policer_add = felix_port_policer_add, 795 .port_policer_del = felix_port_policer_del, 796 .cls_flower_add = felix_cls_flower_add, 797 .cls_flower_del = felix_cls_flower_del, 798 .cls_flower_stats = felix_cls_flower_stats, 799 .port_setup_tc = felix_port_setup_tc, 800 }; 801 802 static int __init felix_init(void) 803 { 804 int err; 805 806 err = pci_register_driver(&felix_vsc9959_pci_driver); 807 if (err) 808 return err; 809 810 err = platform_driver_register(&seville_vsc9953_driver); 811 if (err) 812 return err; 813 814 return 0; 815 } 816 module_init(felix_init); 817 818 static void __exit felix_exit(void) 819 { 820 pci_unregister_driver(&felix_vsc9959_pci_driver); 821 platform_driver_unregister(&seville_vsc9953_driver); 822 } 823 module_exit(felix_exit); 824 825 MODULE_DESCRIPTION("Felix Switch driver"); 826 MODULE_LICENSE("GPL v2"); 827