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