1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * include/net/dsa.h - Driver for Distributed Switch Architecture switch chips 4 * Copyright (c) 2008-2009 Marvell Semiconductor 5 */ 6 7 #ifndef __LINUX_NET_DSA_H 8 #define __LINUX_NET_DSA_H 9 10 #include <linux/if.h> 11 #include <linux/if_ether.h> 12 #include <linux/list.h> 13 #include <linux/notifier.h> 14 #include <linux/timer.h> 15 #include <linux/workqueue.h> 16 #include <linux/of.h> 17 #include <linux/ethtool.h> 18 #include <linux/net_tstamp.h> 19 #include <linux/phy.h> 20 #include <linux/platform_data/dsa.h> 21 #include <linux/phylink.h> 22 #include <net/devlink.h> 23 #include <net/switchdev.h> 24 25 struct tc_action; 26 struct phy_device; 27 struct fixed_phy_status; 28 struct phylink_link_state; 29 30 #define DSA_TAG_PROTO_NONE_VALUE 0 31 #define DSA_TAG_PROTO_BRCM_VALUE 1 32 #define DSA_TAG_PROTO_BRCM_PREPEND_VALUE 2 33 #define DSA_TAG_PROTO_DSA_VALUE 3 34 #define DSA_TAG_PROTO_EDSA_VALUE 4 35 #define DSA_TAG_PROTO_GSWIP_VALUE 5 36 #define DSA_TAG_PROTO_KSZ9477_VALUE 6 37 #define DSA_TAG_PROTO_KSZ9893_VALUE 7 38 #define DSA_TAG_PROTO_LAN9303_VALUE 8 39 #define DSA_TAG_PROTO_MTK_VALUE 9 40 #define DSA_TAG_PROTO_QCA_VALUE 10 41 #define DSA_TAG_PROTO_TRAILER_VALUE 11 42 #define DSA_TAG_PROTO_8021Q_VALUE 12 43 #define DSA_TAG_PROTO_SJA1105_VALUE 13 44 #define DSA_TAG_PROTO_KSZ8795_VALUE 14 45 #define DSA_TAG_PROTO_OCELOT_VALUE 15 46 #define DSA_TAG_PROTO_AR9331_VALUE 16 47 #define DSA_TAG_PROTO_RTL4_A_VALUE 17 48 #define DSA_TAG_PROTO_HELLCREEK_VALUE 18 49 #define DSA_TAG_PROTO_XRS700X_VALUE 19 50 #define DSA_TAG_PROTO_OCELOT_8021Q_VALUE 20 51 #define DSA_TAG_PROTO_SEVILLE_VALUE 21 52 #define DSA_TAG_PROTO_BRCM_LEGACY_VALUE 22 53 #define DSA_TAG_PROTO_SJA1110_VALUE 23 54 #define DSA_TAG_PROTO_RTL8_4_VALUE 24 55 56 enum dsa_tag_protocol { 57 DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE, 58 DSA_TAG_PROTO_BRCM = DSA_TAG_PROTO_BRCM_VALUE, 59 DSA_TAG_PROTO_BRCM_LEGACY = DSA_TAG_PROTO_BRCM_LEGACY_VALUE, 60 DSA_TAG_PROTO_BRCM_PREPEND = DSA_TAG_PROTO_BRCM_PREPEND_VALUE, 61 DSA_TAG_PROTO_DSA = DSA_TAG_PROTO_DSA_VALUE, 62 DSA_TAG_PROTO_EDSA = DSA_TAG_PROTO_EDSA_VALUE, 63 DSA_TAG_PROTO_GSWIP = DSA_TAG_PROTO_GSWIP_VALUE, 64 DSA_TAG_PROTO_KSZ9477 = DSA_TAG_PROTO_KSZ9477_VALUE, 65 DSA_TAG_PROTO_KSZ9893 = DSA_TAG_PROTO_KSZ9893_VALUE, 66 DSA_TAG_PROTO_LAN9303 = DSA_TAG_PROTO_LAN9303_VALUE, 67 DSA_TAG_PROTO_MTK = DSA_TAG_PROTO_MTK_VALUE, 68 DSA_TAG_PROTO_QCA = DSA_TAG_PROTO_QCA_VALUE, 69 DSA_TAG_PROTO_TRAILER = DSA_TAG_PROTO_TRAILER_VALUE, 70 DSA_TAG_PROTO_8021Q = DSA_TAG_PROTO_8021Q_VALUE, 71 DSA_TAG_PROTO_SJA1105 = DSA_TAG_PROTO_SJA1105_VALUE, 72 DSA_TAG_PROTO_KSZ8795 = DSA_TAG_PROTO_KSZ8795_VALUE, 73 DSA_TAG_PROTO_OCELOT = DSA_TAG_PROTO_OCELOT_VALUE, 74 DSA_TAG_PROTO_AR9331 = DSA_TAG_PROTO_AR9331_VALUE, 75 DSA_TAG_PROTO_RTL4_A = DSA_TAG_PROTO_RTL4_A_VALUE, 76 DSA_TAG_PROTO_HELLCREEK = DSA_TAG_PROTO_HELLCREEK_VALUE, 77 DSA_TAG_PROTO_XRS700X = DSA_TAG_PROTO_XRS700X_VALUE, 78 DSA_TAG_PROTO_OCELOT_8021Q = DSA_TAG_PROTO_OCELOT_8021Q_VALUE, 79 DSA_TAG_PROTO_SEVILLE = DSA_TAG_PROTO_SEVILLE_VALUE, 80 DSA_TAG_PROTO_SJA1110 = DSA_TAG_PROTO_SJA1110_VALUE, 81 DSA_TAG_PROTO_RTL8_4 = DSA_TAG_PROTO_RTL8_4_VALUE, 82 }; 83 84 struct dsa_switch; 85 86 struct dsa_device_ops { 87 struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev); 88 struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev); 89 void (*flow_dissect)(const struct sk_buff *skb, __be16 *proto, 90 int *offset); 91 unsigned int needed_headroom; 92 unsigned int needed_tailroom; 93 const char *name; 94 enum dsa_tag_protocol proto; 95 /* Some tagging protocols either mangle or shift the destination MAC 96 * address, in which case the DSA master would drop packets on ingress 97 * if what it understands out of the destination MAC address is not in 98 * its RX filter. 99 */ 100 bool promisc_on_master; 101 }; 102 103 /* This structure defines the control interfaces that are overlayed by the 104 * DSA layer on top of the DSA CPU/management net_device instance. This is 105 * used by the core net_device layer while calling various net_device_ops 106 * function pointers. 107 */ 108 struct dsa_netdevice_ops { 109 int (*ndo_eth_ioctl)(struct net_device *dev, struct ifreq *ifr, 110 int cmd); 111 }; 112 113 #define DSA_TAG_DRIVER_ALIAS "dsa_tag-" 114 #define MODULE_ALIAS_DSA_TAG_DRIVER(__proto) \ 115 MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS __stringify(__proto##_VALUE)) 116 117 struct dsa_switch_tree { 118 struct list_head list; 119 120 /* Notifier chain for switch-wide events */ 121 struct raw_notifier_head nh; 122 123 /* Tree identifier */ 124 unsigned int index; 125 126 /* Number of switches attached to this tree */ 127 struct kref refcount; 128 129 /* Has this tree been applied to the hardware? */ 130 bool setup; 131 132 /* Tagging protocol operations */ 133 const struct dsa_device_ops *tag_ops; 134 135 /* Default tagging protocol preferred by the switches in this 136 * tree. 137 */ 138 enum dsa_tag_protocol default_proto; 139 140 /* 141 * Configuration data for the platform device that owns 142 * this dsa switch tree instance. 143 */ 144 struct dsa_platform_data *pd; 145 146 /* List of switch ports */ 147 struct list_head ports; 148 149 /* List of DSA links composing the routing table */ 150 struct list_head rtable; 151 152 /* Maps offloaded LAG netdevs to a zero-based linear ID for 153 * drivers that need it. 154 */ 155 struct net_device **lags; 156 unsigned int lags_len; 157 158 /* Track the largest switch index within a tree */ 159 unsigned int last_switch; 160 }; 161 162 #define dsa_lags_foreach_id(_id, _dst) \ 163 for ((_id) = 0; (_id) < (_dst)->lags_len; (_id)++) \ 164 if ((_dst)->lags[(_id)]) 165 166 #define dsa_lag_foreach_port(_dp, _dst, _lag) \ 167 list_for_each_entry((_dp), &(_dst)->ports, list) \ 168 if ((_dp)->lag_dev == (_lag)) 169 170 #define dsa_hsr_foreach_port(_dp, _ds, _hsr) \ 171 list_for_each_entry((_dp), &(_ds)->dst->ports, list) \ 172 if ((_dp)->ds == (_ds) && (_dp)->hsr_dev == (_hsr)) 173 174 static inline struct net_device *dsa_lag_dev(struct dsa_switch_tree *dst, 175 unsigned int id) 176 { 177 return dst->lags[id]; 178 } 179 180 static inline int dsa_lag_id(struct dsa_switch_tree *dst, 181 struct net_device *lag) 182 { 183 unsigned int id; 184 185 dsa_lags_foreach_id(id, dst) { 186 if (dsa_lag_dev(dst, id) == lag) 187 return id; 188 } 189 190 return -ENODEV; 191 } 192 193 /* TC matchall action types */ 194 enum dsa_port_mall_action_type { 195 DSA_PORT_MALL_MIRROR, 196 DSA_PORT_MALL_POLICER, 197 }; 198 199 /* TC mirroring entry */ 200 struct dsa_mall_mirror_tc_entry { 201 u8 to_local_port; 202 bool ingress; 203 }; 204 205 /* TC port policer entry */ 206 struct dsa_mall_policer_tc_entry { 207 u32 burst; 208 u64 rate_bytes_per_sec; 209 }; 210 211 /* TC matchall entry */ 212 struct dsa_mall_tc_entry { 213 struct list_head list; 214 unsigned long cookie; 215 enum dsa_port_mall_action_type type; 216 union { 217 struct dsa_mall_mirror_tc_entry mirror; 218 struct dsa_mall_policer_tc_entry policer; 219 }; 220 }; 221 222 223 struct dsa_port { 224 /* A CPU port is physically connected to a master device. 225 * A user port exposed to userspace has a slave device. 226 */ 227 union { 228 struct net_device *master; 229 struct net_device *slave; 230 }; 231 232 /* Copy of the tagging protocol operations, for quicker access 233 * in the data path. Valid only for the CPU ports. 234 */ 235 const struct dsa_device_ops *tag_ops; 236 237 /* Copies for faster access in master receive hot path */ 238 struct dsa_switch_tree *dst; 239 struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev); 240 241 enum { 242 DSA_PORT_TYPE_UNUSED = 0, 243 DSA_PORT_TYPE_CPU, 244 DSA_PORT_TYPE_DSA, 245 DSA_PORT_TYPE_USER, 246 } type; 247 248 struct dsa_switch *ds; 249 unsigned int index; 250 const char *name; 251 struct dsa_port *cpu_dp; 252 u8 mac[ETH_ALEN]; 253 struct device_node *dn; 254 unsigned int ageing_time; 255 bool vlan_filtering; 256 /* Managed by DSA on user ports and by drivers on CPU and DSA ports */ 257 bool learning; 258 u8 stp_state; 259 struct net_device *bridge_dev; 260 unsigned int bridge_num; 261 struct devlink_port devlink_port; 262 bool devlink_port_setup; 263 struct phylink *pl; 264 struct phylink_config pl_config; 265 struct net_device *lag_dev; 266 bool lag_tx_enabled; 267 struct net_device *hsr_dev; 268 269 struct list_head list; 270 271 /* 272 * Give the switch driver somewhere to hang its per-port private data 273 * structures (accessible from the tagger). 274 */ 275 void *priv; 276 277 /* 278 * Original copy of the master netdev ethtool_ops 279 */ 280 const struct ethtool_ops *orig_ethtool_ops; 281 282 /* 283 * Original copy of the master netdev net_device_ops 284 */ 285 const struct dsa_netdevice_ops *netdev_ops; 286 287 /* List of MAC addresses that must be forwarded on this port. 288 * These are only valid on CPU ports and DSA links. 289 */ 290 struct mutex addr_lists_lock; 291 struct list_head fdbs; 292 struct list_head mdbs; 293 294 bool setup; 295 }; 296 297 /* TODO: ideally DSA ports would have a single dp->link_dp member, 298 * and no dst->rtable nor this struct dsa_link would be needed, 299 * but this would require some more complex tree walking, 300 * so keep it stupid at the moment and list them all. 301 */ 302 struct dsa_link { 303 struct dsa_port *dp; 304 struct dsa_port *link_dp; 305 struct list_head list; 306 }; 307 308 struct dsa_mac_addr { 309 unsigned char addr[ETH_ALEN]; 310 u16 vid; 311 refcount_t refcount; 312 struct list_head list; 313 }; 314 315 struct dsa_switch { 316 bool setup; 317 318 struct device *dev; 319 320 /* 321 * Parent switch tree, and switch index. 322 */ 323 struct dsa_switch_tree *dst; 324 unsigned int index; 325 326 /* Listener for switch fabric events */ 327 struct notifier_block nb; 328 329 /* 330 * Give the switch driver somewhere to hang its private data 331 * structure. 332 */ 333 void *priv; 334 335 /* 336 * Configuration data for this switch. 337 */ 338 struct dsa_chip_data *cd; 339 340 /* 341 * The switch operations. 342 */ 343 const struct dsa_switch_ops *ops; 344 345 /* 346 * Slave mii_bus and devices for the individual ports. 347 */ 348 u32 phys_mii_mask; 349 struct mii_bus *slave_mii_bus; 350 351 /* Ageing Time limits in msecs */ 352 unsigned int ageing_time_min; 353 unsigned int ageing_time_max; 354 355 /* Storage for drivers using tag_8021q */ 356 struct dsa_8021q_context *tag_8021q_ctx; 357 358 /* devlink used to represent this switch device */ 359 struct devlink *devlink; 360 361 /* Number of switch port queues */ 362 unsigned int num_tx_queues; 363 364 /* Disallow bridge core from requesting different VLAN awareness 365 * settings on ports if not hardware-supported 366 */ 367 bool vlan_filtering_is_global; 368 369 /* Keep VLAN filtering enabled on ports not offloading any upper. */ 370 bool needs_standalone_vlan_filtering; 371 372 /* Pass .port_vlan_add and .port_vlan_del to drivers even for bridges 373 * that have vlan_filtering=0. All drivers should ideally set this (and 374 * then the option would get removed), but it is unknown whether this 375 * would break things or not. 376 */ 377 bool configure_vlan_while_not_filtering; 378 379 /* If the switch driver always programs the CPU port as egress tagged 380 * despite the VLAN configuration indicating otherwise, then setting 381 * @untag_bridge_pvid will force the DSA receive path to pop the bridge's 382 * default_pvid VLAN tagged frames to offer a consistent behavior 383 * between a vlan_filtering=0 and vlan_filtering=1 bridge device. 384 */ 385 bool untag_bridge_pvid; 386 387 /* Let DSA manage the FDB entries towards the CPU, based on the 388 * software bridge database. 389 */ 390 bool assisted_learning_on_cpu_port; 391 392 /* In case vlan_filtering_is_global is set, the VLAN awareness state 393 * should be retrieved from here and not from the per-port settings. 394 */ 395 bool vlan_filtering; 396 397 /* MAC PCS does not provide link state change interrupt, and requires 398 * polling. Flag passed on to PHYLINK. 399 */ 400 bool pcs_poll; 401 402 /* For switches that only have the MRU configurable. To ensure the 403 * configured MTU is not exceeded, normalization of MRU on all bridged 404 * interfaces is needed. 405 */ 406 bool mtu_enforcement_ingress; 407 408 /* Drivers that benefit from having an ID associated with each 409 * offloaded LAG should set this to the maximum number of 410 * supported IDs. DSA will then maintain a mapping of _at 411 * least_ these many IDs, accessible to drivers via 412 * dsa_lag_id(). 413 */ 414 unsigned int num_lag_ids; 415 416 /* Drivers that support bridge forwarding offload or FDB isolation 417 * should set this to the maximum number of bridges spanning the same 418 * switch tree (or all trees, in the case of cross-tree bridging 419 * support) that can be offloaded. 420 */ 421 unsigned int max_num_bridges; 422 423 size_t num_ports; 424 }; 425 426 static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p) 427 { 428 struct dsa_switch_tree *dst = ds->dst; 429 struct dsa_port *dp; 430 431 list_for_each_entry(dp, &dst->ports, list) 432 if (dp->ds == ds && dp->index == p) 433 return dp; 434 435 return NULL; 436 } 437 438 static inline bool dsa_port_is_dsa(struct dsa_port *port) 439 { 440 return port->type == DSA_PORT_TYPE_DSA; 441 } 442 443 static inline bool dsa_port_is_cpu(struct dsa_port *port) 444 { 445 return port->type == DSA_PORT_TYPE_CPU; 446 } 447 448 static inline bool dsa_port_is_user(struct dsa_port *dp) 449 { 450 return dp->type == DSA_PORT_TYPE_USER; 451 } 452 453 static inline bool dsa_port_is_unused(struct dsa_port *dp) 454 { 455 return dp->type == DSA_PORT_TYPE_UNUSED; 456 } 457 458 static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p) 459 { 460 return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_UNUSED; 461 } 462 463 static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p) 464 { 465 return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_CPU; 466 } 467 468 static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p) 469 { 470 return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_DSA; 471 } 472 473 static inline bool dsa_is_user_port(struct dsa_switch *ds, int p) 474 { 475 return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER; 476 } 477 478 #define dsa_tree_for_each_user_port(_dp, _dst) \ 479 list_for_each_entry((_dp), &(_dst)->ports, list) \ 480 if (dsa_port_is_user((_dp))) 481 482 #define dsa_switch_for_each_port(_dp, _ds) \ 483 list_for_each_entry((_dp), &(_ds)->dst->ports, list) \ 484 if ((_dp)->ds == (_ds)) 485 486 #define dsa_switch_for_each_port_safe(_dp, _next, _ds) \ 487 list_for_each_entry_safe((_dp), (_next), &(_ds)->dst->ports, list) \ 488 if ((_dp)->ds == (_ds)) 489 490 #define dsa_switch_for_each_port_continue_reverse(_dp, _ds) \ 491 list_for_each_entry_continue_reverse((_dp), &(_ds)->dst->ports, list) \ 492 if ((_dp)->ds == (_ds)) 493 494 #define dsa_switch_for_each_available_port(_dp, _ds) \ 495 dsa_switch_for_each_port((_dp), (_ds)) \ 496 if (!dsa_port_is_unused((_dp))) 497 498 #define dsa_switch_for_each_user_port(_dp, _ds) \ 499 dsa_switch_for_each_port((_dp), (_ds)) \ 500 if (dsa_port_is_user((_dp))) 501 502 #define dsa_switch_for_each_cpu_port(_dp, _ds) \ 503 dsa_switch_for_each_port((_dp), (_ds)) \ 504 if (dsa_port_is_cpu((_dp))) 505 506 static inline u32 dsa_user_ports(struct dsa_switch *ds) 507 { 508 struct dsa_port *dp; 509 u32 mask = 0; 510 511 dsa_switch_for_each_user_port(dp, ds) 512 mask |= BIT(dp->index); 513 514 return mask; 515 } 516 517 /* Return the local port used to reach an arbitrary switch device */ 518 static inline unsigned int dsa_routing_port(struct dsa_switch *ds, int device) 519 { 520 struct dsa_switch_tree *dst = ds->dst; 521 struct dsa_link *dl; 522 523 list_for_each_entry(dl, &dst->rtable, list) 524 if (dl->dp->ds == ds && dl->link_dp->ds->index == device) 525 return dl->dp->index; 526 527 return ds->num_ports; 528 } 529 530 /* Return the local port used to reach an arbitrary switch port */ 531 static inline unsigned int dsa_towards_port(struct dsa_switch *ds, int device, 532 int port) 533 { 534 if (device == ds->index) 535 return port; 536 else 537 return dsa_routing_port(ds, device); 538 } 539 540 /* Return the local port used to reach the dedicated CPU port */ 541 static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port) 542 { 543 const struct dsa_port *dp = dsa_to_port(ds, port); 544 const struct dsa_port *cpu_dp = dp->cpu_dp; 545 546 if (!cpu_dp) 547 return port; 548 549 return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index); 550 } 551 552 /* Return true if this is the local port used to reach the CPU port */ 553 static inline bool dsa_is_upstream_port(struct dsa_switch *ds, int port) 554 { 555 if (dsa_is_unused_port(ds, port)) 556 return false; 557 558 return port == dsa_upstream_port(ds, port); 559 } 560 561 /* Return true if @upstream_ds is an upstream switch of @downstream_ds, meaning 562 * that the routing port from @downstream_ds to @upstream_ds is also the port 563 * which @downstream_ds uses to reach its dedicated CPU. 564 */ 565 static inline bool dsa_switch_is_upstream_of(struct dsa_switch *upstream_ds, 566 struct dsa_switch *downstream_ds) 567 { 568 int routing_port; 569 570 if (upstream_ds == downstream_ds) 571 return true; 572 573 routing_port = dsa_routing_port(downstream_ds, upstream_ds->index); 574 575 return dsa_is_upstream_port(downstream_ds, routing_port); 576 } 577 578 static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp) 579 { 580 const struct dsa_switch *ds = dp->ds; 581 582 if (ds->vlan_filtering_is_global) 583 return ds->vlan_filtering; 584 else 585 return dp->vlan_filtering; 586 } 587 588 static inline 589 struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp) 590 { 591 if (!dp->bridge_dev) 592 return NULL; 593 594 if (dp->lag_dev) 595 return dp->lag_dev; 596 else if (dp->hsr_dev) 597 return dp->hsr_dev; 598 599 return dp->slave; 600 } 601 602 static inline struct net_device * 603 dsa_port_bridge_dev_get(const struct dsa_port *dp) 604 { 605 return dp->bridge_dev; 606 } 607 608 static inline unsigned int dsa_port_bridge_num_get(struct dsa_port *dp) 609 { 610 return dp->bridge_num; 611 } 612 613 static inline bool dsa_port_bridge_same(const struct dsa_port *a, 614 const struct dsa_port *b) 615 { 616 struct net_device *br_a = dsa_port_bridge_dev_get(a); 617 struct net_device *br_b = dsa_port_bridge_dev_get(b); 618 619 /* Standalone ports are not in the same bridge with one another */ 620 return (!br_a || !br_b) ? false : (br_a == br_b); 621 } 622 623 static inline bool dsa_port_offloads_bridge_port(struct dsa_port *dp, 624 const struct net_device *dev) 625 { 626 return dsa_port_to_bridge_port(dp) == dev; 627 } 628 629 static inline bool 630 dsa_port_offloads_bridge_dev(struct dsa_port *dp, 631 const struct net_device *bridge_dev) 632 { 633 /* DSA ports connected to a bridge, and event was emitted 634 * for the bridge. 635 */ 636 return dsa_port_bridge_dev_get(dp) == bridge_dev; 637 } 638 639 /* Returns true if any port of this tree offloads the given net_device */ 640 static inline bool dsa_tree_offloads_bridge_port(struct dsa_switch_tree *dst, 641 const struct net_device *dev) 642 { 643 struct dsa_port *dp; 644 645 list_for_each_entry(dp, &dst->ports, list) 646 if (dsa_port_offloads_bridge_port(dp, dev)) 647 return true; 648 649 return false; 650 } 651 652 /* Returns true if any port of this tree offloads the given bridge */ 653 static inline bool 654 dsa_tree_offloads_bridge_dev(struct dsa_switch_tree *dst, 655 const struct net_device *bridge_dev) 656 { 657 struct dsa_port *dp; 658 659 list_for_each_entry(dp, &dst->ports, list) 660 if (dsa_port_offloads_bridge_dev(dp, bridge_dev)) 661 return true; 662 663 return false; 664 } 665 666 typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid, 667 bool is_static, void *data); 668 struct dsa_switch_ops { 669 /* 670 * Tagging protocol helpers called for the CPU ports and DSA links. 671 * @get_tag_protocol retrieves the initial tagging protocol and is 672 * mandatory. Switches which can operate using multiple tagging 673 * protocols should implement @change_tag_protocol and report in 674 * @get_tag_protocol the tagger in current use. 675 */ 676 enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds, 677 int port, 678 enum dsa_tag_protocol mprot); 679 int (*change_tag_protocol)(struct dsa_switch *ds, int port, 680 enum dsa_tag_protocol proto); 681 682 /* Optional switch-wide initialization and destruction methods */ 683 int (*setup)(struct dsa_switch *ds); 684 void (*teardown)(struct dsa_switch *ds); 685 686 /* Per-port initialization and destruction methods. Mandatory if the 687 * driver registers devlink port regions, optional otherwise. 688 */ 689 int (*port_setup)(struct dsa_switch *ds, int port); 690 void (*port_teardown)(struct dsa_switch *ds, int port); 691 692 u32 (*get_phy_flags)(struct dsa_switch *ds, int port); 693 694 /* 695 * Access to the switch's PHY registers. 696 */ 697 int (*phy_read)(struct dsa_switch *ds, int port, int regnum); 698 int (*phy_write)(struct dsa_switch *ds, int port, 699 int regnum, u16 val); 700 701 /* 702 * Link state adjustment (called from libphy) 703 */ 704 void (*adjust_link)(struct dsa_switch *ds, int port, 705 struct phy_device *phydev); 706 void (*fixed_link_update)(struct dsa_switch *ds, int port, 707 struct fixed_phy_status *st); 708 709 /* 710 * PHYLINK integration 711 */ 712 void (*phylink_get_caps)(struct dsa_switch *ds, int port, 713 struct phylink_config *config); 714 void (*phylink_validate)(struct dsa_switch *ds, int port, 715 unsigned long *supported, 716 struct phylink_link_state *state); 717 int (*phylink_mac_link_state)(struct dsa_switch *ds, int port, 718 struct phylink_link_state *state); 719 void (*phylink_mac_config)(struct dsa_switch *ds, int port, 720 unsigned int mode, 721 const struct phylink_link_state *state); 722 void (*phylink_mac_an_restart)(struct dsa_switch *ds, int port); 723 void (*phylink_mac_link_down)(struct dsa_switch *ds, int port, 724 unsigned int mode, 725 phy_interface_t interface); 726 void (*phylink_mac_link_up)(struct dsa_switch *ds, int port, 727 unsigned int mode, 728 phy_interface_t interface, 729 struct phy_device *phydev, 730 int speed, int duplex, 731 bool tx_pause, bool rx_pause); 732 void (*phylink_fixed_state)(struct dsa_switch *ds, int port, 733 struct phylink_link_state *state); 734 /* 735 * Port statistics counters. 736 */ 737 void (*get_strings)(struct dsa_switch *ds, int port, 738 u32 stringset, uint8_t *data); 739 void (*get_ethtool_stats)(struct dsa_switch *ds, 740 int port, uint64_t *data); 741 int (*get_sset_count)(struct dsa_switch *ds, int port, int sset); 742 void (*get_ethtool_phy_stats)(struct dsa_switch *ds, 743 int port, uint64_t *data); 744 void (*get_eth_phy_stats)(struct dsa_switch *ds, int port, 745 struct ethtool_eth_phy_stats *phy_stats); 746 void (*get_eth_mac_stats)(struct dsa_switch *ds, int port, 747 struct ethtool_eth_mac_stats *mac_stats); 748 void (*get_eth_ctrl_stats)(struct dsa_switch *ds, int port, 749 struct ethtool_eth_ctrl_stats *ctrl_stats); 750 void (*get_stats64)(struct dsa_switch *ds, int port, 751 struct rtnl_link_stats64 *s); 752 void (*self_test)(struct dsa_switch *ds, int port, 753 struct ethtool_test *etest, u64 *data); 754 755 /* 756 * ethtool Wake-on-LAN 757 */ 758 void (*get_wol)(struct dsa_switch *ds, int port, 759 struct ethtool_wolinfo *w); 760 int (*set_wol)(struct dsa_switch *ds, int port, 761 struct ethtool_wolinfo *w); 762 763 /* 764 * ethtool timestamp info 765 */ 766 int (*get_ts_info)(struct dsa_switch *ds, int port, 767 struct ethtool_ts_info *ts); 768 769 /* 770 * Suspend and resume 771 */ 772 int (*suspend)(struct dsa_switch *ds); 773 int (*resume)(struct dsa_switch *ds); 774 775 /* 776 * Port enable/disable 777 */ 778 int (*port_enable)(struct dsa_switch *ds, int port, 779 struct phy_device *phy); 780 void (*port_disable)(struct dsa_switch *ds, int port); 781 782 /* 783 * Port's MAC EEE settings 784 */ 785 int (*set_mac_eee)(struct dsa_switch *ds, int port, 786 struct ethtool_eee *e); 787 int (*get_mac_eee)(struct dsa_switch *ds, int port, 788 struct ethtool_eee *e); 789 790 /* EEPROM access */ 791 int (*get_eeprom_len)(struct dsa_switch *ds); 792 int (*get_eeprom)(struct dsa_switch *ds, 793 struct ethtool_eeprom *eeprom, u8 *data); 794 int (*set_eeprom)(struct dsa_switch *ds, 795 struct ethtool_eeprom *eeprom, u8 *data); 796 797 /* 798 * Register access. 799 */ 800 int (*get_regs_len)(struct dsa_switch *ds, int port); 801 void (*get_regs)(struct dsa_switch *ds, int port, 802 struct ethtool_regs *regs, void *p); 803 804 /* 805 * Upper device tracking. 806 */ 807 int (*port_prechangeupper)(struct dsa_switch *ds, int port, 808 struct netdev_notifier_changeupper_info *info); 809 810 /* 811 * Bridge integration 812 */ 813 int (*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs); 814 int (*port_bridge_join)(struct dsa_switch *ds, int port, 815 struct net_device *bridge); 816 void (*port_bridge_leave)(struct dsa_switch *ds, int port, 817 struct net_device *bridge); 818 /* Called right after .port_bridge_join() */ 819 int (*port_bridge_tx_fwd_offload)(struct dsa_switch *ds, int port, 820 struct net_device *bridge, 821 unsigned int bridge_num); 822 /* Called right before .port_bridge_leave() */ 823 void (*port_bridge_tx_fwd_unoffload)(struct dsa_switch *ds, int port, 824 struct net_device *bridge, 825 unsigned int bridge_num); 826 void (*port_stp_state_set)(struct dsa_switch *ds, int port, 827 u8 state); 828 void (*port_fast_age)(struct dsa_switch *ds, int port); 829 int (*port_pre_bridge_flags)(struct dsa_switch *ds, int port, 830 struct switchdev_brport_flags flags, 831 struct netlink_ext_ack *extack); 832 int (*port_bridge_flags)(struct dsa_switch *ds, int port, 833 struct switchdev_brport_flags flags, 834 struct netlink_ext_ack *extack); 835 836 /* 837 * VLAN support 838 */ 839 int (*port_vlan_filtering)(struct dsa_switch *ds, int port, 840 bool vlan_filtering, 841 struct netlink_ext_ack *extack); 842 int (*port_vlan_add)(struct dsa_switch *ds, int port, 843 const struct switchdev_obj_port_vlan *vlan, 844 struct netlink_ext_ack *extack); 845 int (*port_vlan_del)(struct dsa_switch *ds, int port, 846 const struct switchdev_obj_port_vlan *vlan); 847 /* 848 * Forwarding database 849 */ 850 int (*port_fdb_add)(struct dsa_switch *ds, int port, 851 const unsigned char *addr, u16 vid); 852 int (*port_fdb_del)(struct dsa_switch *ds, int port, 853 const unsigned char *addr, u16 vid); 854 int (*port_fdb_dump)(struct dsa_switch *ds, int port, 855 dsa_fdb_dump_cb_t *cb, void *data); 856 857 /* 858 * Multicast database 859 */ 860 int (*port_mdb_add)(struct dsa_switch *ds, int port, 861 const struct switchdev_obj_port_mdb *mdb); 862 int (*port_mdb_del)(struct dsa_switch *ds, int port, 863 const struct switchdev_obj_port_mdb *mdb); 864 /* 865 * RXNFC 866 */ 867 int (*get_rxnfc)(struct dsa_switch *ds, int port, 868 struct ethtool_rxnfc *nfc, u32 *rule_locs); 869 int (*set_rxnfc)(struct dsa_switch *ds, int port, 870 struct ethtool_rxnfc *nfc); 871 872 /* 873 * TC integration 874 */ 875 int (*cls_flower_add)(struct dsa_switch *ds, int port, 876 struct flow_cls_offload *cls, bool ingress); 877 int (*cls_flower_del)(struct dsa_switch *ds, int port, 878 struct flow_cls_offload *cls, bool ingress); 879 int (*cls_flower_stats)(struct dsa_switch *ds, int port, 880 struct flow_cls_offload *cls, bool ingress); 881 int (*port_mirror_add)(struct dsa_switch *ds, int port, 882 struct dsa_mall_mirror_tc_entry *mirror, 883 bool ingress); 884 void (*port_mirror_del)(struct dsa_switch *ds, int port, 885 struct dsa_mall_mirror_tc_entry *mirror); 886 int (*port_policer_add)(struct dsa_switch *ds, int port, 887 struct dsa_mall_policer_tc_entry *policer); 888 void (*port_policer_del)(struct dsa_switch *ds, int port); 889 int (*port_setup_tc)(struct dsa_switch *ds, int port, 890 enum tc_setup_type type, void *type_data); 891 892 /* 893 * Cross-chip operations 894 */ 895 int (*crosschip_bridge_join)(struct dsa_switch *ds, int tree_index, 896 int sw_index, int port, 897 struct net_device *br); 898 void (*crosschip_bridge_leave)(struct dsa_switch *ds, int tree_index, 899 int sw_index, int port, 900 struct net_device *br); 901 int (*crosschip_lag_change)(struct dsa_switch *ds, int sw_index, 902 int port); 903 int (*crosschip_lag_join)(struct dsa_switch *ds, int sw_index, 904 int port, struct net_device *lag, 905 struct netdev_lag_upper_info *info); 906 int (*crosschip_lag_leave)(struct dsa_switch *ds, int sw_index, 907 int port, struct net_device *lag); 908 909 /* 910 * PTP functionality 911 */ 912 int (*port_hwtstamp_get)(struct dsa_switch *ds, int port, 913 struct ifreq *ifr); 914 int (*port_hwtstamp_set)(struct dsa_switch *ds, int port, 915 struct ifreq *ifr); 916 void (*port_txtstamp)(struct dsa_switch *ds, int port, 917 struct sk_buff *skb); 918 bool (*port_rxtstamp)(struct dsa_switch *ds, int port, 919 struct sk_buff *skb, unsigned int type); 920 921 /* Devlink parameters, etc */ 922 int (*devlink_param_get)(struct dsa_switch *ds, u32 id, 923 struct devlink_param_gset_ctx *ctx); 924 int (*devlink_param_set)(struct dsa_switch *ds, u32 id, 925 struct devlink_param_gset_ctx *ctx); 926 int (*devlink_info_get)(struct dsa_switch *ds, 927 struct devlink_info_req *req, 928 struct netlink_ext_ack *extack); 929 int (*devlink_sb_pool_get)(struct dsa_switch *ds, 930 unsigned int sb_index, u16 pool_index, 931 struct devlink_sb_pool_info *pool_info); 932 int (*devlink_sb_pool_set)(struct dsa_switch *ds, unsigned int sb_index, 933 u16 pool_index, u32 size, 934 enum devlink_sb_threshold_type threshold_type, 935 struct netlink_ext_ack *extack); 936 int (*devlink_sb_port_pool_get)(struct dsa_switch *ds, int port, 937 unsigned int sb_index, u16 pool_index, 938 u32 *p_threshold); 939 int (*devlink_sb_port_pool_set)(struct dsa_switch *ds, int port, 940 unsigned int sb_index, u16 pool_index, 941 u32 threshold, 942 struct netlink_ext_ack *extack); 943 int (*devlink_sb_tc_pool_bind_get)(struct dsa_switch *ds, int port, 944 unsigned int sb_index, u16 tc_index, 945 enum devlink_sb_pool_type pool_type, 946 u16 *p_pool_index, u32 *p_threshold); 947 int (*devlink_sb_tc_pool_bind_set)(struct dsa_switch *ds, int port, 948 unsigned int sb_index, u16 tc_index, 949 enum devlink_sb_pool_type pool_type, 950 u16 pool_index, u32 threshold, 951 struct netlink_ext_ack *extack); 952 int (*devlink_sb_occ_snapshot)(struct dsa_switch *ds, 953 unsigned int sb_index); 954 int (*devlink_sb_occ_max_clear)(struct dsa_switch *ds, 955 unsigned int sb_index); 956 int (*devlink_sb_occ_port_pool_get)(struct dsa_switch *ds, int port, 957 unsigned int sb_index, u16 pool_index, 958 u32 *p_cur, u32 *p_max); 959 int (*devlink_sb_occ_tc_port_bind_get)(struct dsa_switch *ds, int port, 960 unsigned int sb_index, u16 tc_index, 961 enum devlink_sb_pool_type pool_type, 962 u32 *p_cur, u32 *p_max); 963 964 /* 965 * MTU change functionality. Switches can also adjust their MRU through 966 * this method. By MTU, one understands the SDU (L2 payload) length. 967 * If the switch needs to account for the DSA tag on the CPU port, this 968 * method needs to do so privately. 969 */ 970 int (*port_change_mtu)(struct dsa_switch *ds, int port, 971 int new_mtu); 972 int (*port_max_mtu)(struct dsa_switch *ds, int port); 973 974 /* 975 * LAG integration 976 */ 977 int (*port_lag_change)(struct dsa_switch *ds, int port); 978 int (*port_lag_join)(struct dsa_switch *ds, int port, 979 struct net_device *lag, 980 struct netdev_lag_upper_info *info); 981 int (*port_lag_leave)(struct dsa_switch *ds, int port, 982 struct net_device *lag); 983 984 /* 985 * HSR integration 986 */ 987 int (*port_hsr_join)(struct dsa_switch *ds, int port, 988 struct net_device *hsr); 989 int (*port_hsr_leave)(struct dsa_switch *ds, int port, 990 struct net_device *hsr); 991 992 /* 993 * MRP integration 994 */ 995 int (*port_mrp_add)(struct dsa_switch *ds, int port, 996 const struct switchdev_obj_mrp *mrp); 997 int (*port_mrp_del)(struct dsa_switch *ds, int port, 998 const struct switchdev_obj_mrp *mrp); 999 int (*port_mrp_add_ring_role)(struct dsa_switch *ds, int port, 1000 const struct switchdev_obj_ring_role_mrp *mrp); 1001 int (*port_mrp_del_ring_role)(struct dsa_switch *ds, int port, 1002 const struct switchdev_obj_ring_role_mrp *mrp); 1003 1004 /* 1005 * tag_8021q operations 1006 */ 1007 int (*tag_8021q_vlan_add)(struct dsa_switch *ds, int port, u16 vid, 1008 u16 flags); 1009 int (*tag_8021q_vlan_del)(struct dsa_switch *ds, int port, u16 vid); 1010 }; 1011 1012 #define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes) \ 1013 DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, \ 1014 dsa_devlink_param_get, dsa_devlink_param_set, NULL) 1015 1016 int dsa_devlink_param_get(struct devlink *dl, u32 id, 1017 struct devlink_param_gset_ctx *ctx); 1018 int dsa_devlink_param_set(struct devlink *dl, u32 id, 1019 struct devlink_param_gset_ctx *ctx); 1020 int dsa_devlink_params_register(struct dsa_switch *ds, 1021 const struct devlink_param *params, 1022 size_t params_count); 1023 void dsa_devlink_params_unregister(struct dsa_switch *ds, 1024 const struct devlink_param *params, 1025 size_t params_count); 1026 int dsa_devlink_resource_register(struct dsa_switch *ds, 1027 const char *resource_name, 1028 u64 resource_size, 1029 u64 resource_id, 1030 u64 parent_resource_id, 1031 const struct devlink_resource_size_params *size_params); 1032 1033 void dsa_devlink_resources_unregister(struct dsa_switch *ds); 1034 1035 void dsa_devlink_resource_occ_get_register(struct dsa_switch *ds, 1036 u64 resource_id, 1037 devlink_resource_occ_get_t *occ_get, 1038 void *occ_get_priv); 1039 void dsa_devlink_resource_occ_get_unregister(struct dsa_switch *ds, 1040 u64 resource_id); 1041 struct devlink_region * 1042 dsa_devlink_region_create(struct dsa_switch *ds, 1043 const struct devlink_region_ops *ops, 1044 u32 region_max_snapshots, u64 region_size); 1045 struct devlink_region * 1046 dsa_devlink_port_region_create(struct dsa_switch *ds, 1047 int port, 1048 const struct devlink_port_region_ops *ops, 1049 u32 region_max_snapshots, u64 region_size); 1050 void dsa_devlink_region_destroy(struct devlink_region *region); 1051 1052 struct dsa_port *dsa_port_from_netdev(struct net_device *netdev); 1053 1054 struct dsa_devlink_priv { 1055 struct dsa_switch *ds; 1056 }; 1057 1058 static inline struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl) 1059 { 1060 struct dsa_devlink_priv *dl_priv = devlink_priv(dl); 1061 1062 return dl_priv->ds; 1063 } 1064 1065 static inline 1066 struct dsa_switch *dsa_devlink_port_to_ds(struct devlink_port *port) 1067 { 1068 struct devlink *dl = port->devlink; 1069 struct dsa_devlink_priv *dl_priv = devlink_priv(dl); 1070 1071 return dl_priv->ds; 1072 } 1073 1074 static inline int dsa_devlink_port_to_port(struct devlink_port *port) 1075 { 1076 return port->index; 1077 } 1078 1079 struct dsa_switch_driver { 1080 struct list_head list; 1081 const struct dsa_switch_ops *ops; 1082 }; 1083 1084 struct net_device *dsa_dev_to_net_device(struct device *dev); 1085 1086 /* Keep inline for faster access in hot path */ 1087 static inline bool netdev_uses_dsa(const struct net_device *dev) 1088 { 1089 #if IS_ENABLED(CONFIG_NET_DSA) 1090 return dev->dsa_ptr && dev->dsa_ptr->rcv; 1091 #endif 1092 return false; 1093 } 1094 1095 /* All DSA tags that push the EtherType to the right (basically all except tail 1096 * tags, which don't break dissection) can be treated the same from the 1097 * perspective of the flow dissector. 1098 * 1099 * We need to return: 1100 * - offset: the (B - A) difference between: 1101 * A. the position of the real EtherType and 1102 * B. the current skb->data (aka ETH_HLEN bytes into the frame, aka 2 bytes 1103 * after the normal EtherType was supposed to be) 1104 * The offset in bytes is exactly equal to the tagger overhead (and half of 1105 * that, in __be16 shorts). 1106 * 1107 * - proto: the value of the real EtherType. 1108 */ 1109 static inline void dsa_tag_generic_flow_dissect(const struct sk_buff *skb, 1110 __be16 *proto, int *offset) 1111 { 1112 #if IS_ENABLED(CONFIG_NET_DSA) 1113 const struct dsa_device_ops *ops = skb->dev->dsa_ptr->tag_ops; 1114 int tag_len = ops->needed_headroom; 1115 1116 *offset = tag_len; 1117 *proto = ((__be16 *)skb->data)[(tag_len / 2) - 1]; 1118 #endif 1119 } 1120 1121 #if IS_ENABLED(CONFIG_NET_DSA) 1122 static inline int __dsa_netdevice_ops_check(struct net_device *dev) 1123 { 1124 int err = -EOPNOTSUPP; 1125 1126 if (!dev->dsa_ptr) 1127 return err; 1128 1129 if (!dev->dsa_ptr->netdev_ops) 1130 return err; 1131 1132 return 0; 1133 } 1134 1135 static inline int dsa_ndo_eth_ioctl(struct net_device *dev, struct ifreq *ifr, 1136 int cmd) 1137 { 1138 const struct dsa_netdevice_ops *ops; 1139 int err; 1140 1141 err = __dsa_netdevice_ops_check(dev); 1142 if (err) 1143 return err; 1144 1145 ops = dev->dsa_ptr->netdev_ops; 1146 1147 return ops->ndo_eth_ioctl(dev, ifr, cmd); 1148 } 1149 #else 1150 static inline int dsa_ndo_eth_ioctl(struct net_device *dev, struct ifreq *ifr, 1151 int cmd) 1152 { 1153 return -EOPNOTSUPP; 1154 } 1155 #endif 1156 1157 void dsa_unregister_switch(struct dsa_switch *ds); 1158 int dsa_register_switch(struct dsa_switch *ds); 1159 void dsa_switch_shutdown(struct dsa_switch *ds); 1160 struct dsa_switch *dsa_switch_find(int tree_index, int sw_index); 1161 #ifdef CONFIG_PM_SLEEP 1162 int dsa_switch_suspend(struct dsa_switch *ds); 1163 int dsa_switch_resume(struct dsa_switch *ds); 1164 #else 1165 static inline int dsa_switch_suspend(struct dsa_switch *ds) 1166 { 1167 return 0; 1168 } 1169 static inline int dsa_switch_resume(struct dsa_switch *ds) 1170 { 1171 return 0; 1172 } 1173 #endif /* CONFIG_PM_SLEEP */ 1174 1175 #if IS_ENABLED(CONFIG_NET_DSA) 1176 bool dsa_slave_dev_check(const struct net_device *dev); 1177 #else 1178 static inline bool dsa_slave_dev_check(const struct net_device *dev) 1179 { 1180 return false; 1181 } 1182 #endif 1183 1184 netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev); 1185 int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data); 1186 int dsa_port_get_ethtool_phy_stats(struct dsa_port *dp, uint64_t *data); 1187 int dsa_port_get_phy_sset_count(struct dsa_port *dp); 1188 void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up); 1189 1190 struct dsa_tag_driver { 1191 const struct dsa_device_ops *ops; 1192 struct list_head list; 1193 struct module *owner; 1194 }; 1195 1196 void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[], 1197 unsigned int count, 1198 struct module *owner); 1199 void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[], 1200 unsigned int count); 1201 1202 #define dsa_tag_driver_module_drivers(__dsa_tag_drivers_array, __count) \ 1203 static int __init dsa_tag_driver_module_init(void) \ 1204 { \ 1205 dsa_tag_drivers_register(__dsa_tag_drivers_array, __count, \ 1206 THIS_MODULE); \ 1207 return 0; \ 1208 } \ 1209 module_init(dsa_tag_driver_module_init); \ 1210 \ 1211 static void __exit dsa_tag_driver_module_exit(void) \ 1212 { \ 1213 dsa_tag_drivers_unregister(__dsa_tag_drivers_array, __count); \ 1214 } \ 1215 module_exit(dsa_tag_driver_module_exit) 1216 1217 /** 1218 * module_dsa_tag_drivers() - Helper macro for registering DSA tag 1219 * drivers 1220 * @__ops_array: Array of tag driver strucutres 1221 * 1222 * Helper macro for DSA tag drivers which do not do anything special 1223 * in module init/exit. Each module may only use this macro once, and 1224 * calling it replaces module_init() and module_exit(). 1225 */ 1226 #define module_dsa_tag_drivers(__ops_array) \ 1227 dsa_tag_driver_module_drivers(__ops_array, ARRAY_SIZE(__ops_array)) 1228 1229 #define DSA_TAG_DRIVER_NAME(__ops) dsa_tag_driver ## _ ## __ops 1230 1231 /* Create a static structure we can build a linked list of dsa_tag 1232 * drivers 1233 */ 1234 #define DSA_TAG_DRIVER(__ops) \ 1235 static struct dsa_tag_driver DSA_TAG_DRIVER_NAME(__ops) = { \ 1236 .ops = &__ops, \ 1237 } 1238 1239 /** 1240 * module_dsa_tag_driver() - Helper macro for registering a single DSA tag 1241 * driver 1242 * @__ops: Single tag driver structures 1243 * 1244 * Helper macro for DSA tag drivers which do not do anything special 1245 * in module init/exit. Each module may only use this macro once, and 1246 * calling it replaces module_init() and module_exit(). 1247 */ 1248 #define module_dsa_tag_driver(__ops) \ 1249 DSA_TAG_DRIVER(__ops); \ 1250 \ 1251 static struct dsa_tag_driver *dsa_tag_driver_array[] = { \ 1252 &DSA_TAG_DRIVER_NAME(__ops) \ 1253 }; \ 1254 module_dsa_tag_drivers(dsa_tag_driver_array) 1255 #endif 1256 1257