switchdev.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * include/net/switchdev.h - Switch device API
  3. * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
  4. * Copyright (c) 2014-2015 Scott Feldman <sfeldma@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #ifndef _LINUX_SWITCHDEV_H_
  12. #define _LINUX_SWITCHDEV_H_
  13. #include <linux/netdevice.h>
  14. #include <linux/notifier.h>
  15. struct fib_info;
  16. /**
  17. * struct switchdev_ops - switchdev operations
  18. *
  19. * @swdev_parent_id_get: Called to get an ID of the switch chip this port
  20. * is part of. If driver implements this, it indicates that it
  21. * represents a port of a switch chip.
  22. *
  23. * @swdev_port_stp_update: Called to notify switch device port of bridge
  24. * port STP state change.
  25. *
  26. * @swdev_fib_ipv4_add: Called to add/modify IPv4 route to switch device.
  27. *
  28. * @swdev_fib_ipv4_del: Called to delete IPv4 route from switch device.
  29. */
  30. struct swdev_ops {
  31. int (*swdev_parent_id_get)(struct net_device *dev,
  32. struct netdev_phys_item_id *psid);
  33. int (*swdev_port_stp_update)(struct net_device *dev, u8 state);
  34. int (*swdev_fib_ipv4_add)(struct net_device *dev, __be32 dst,
  35. int dst_len, struct fib_info *fi,
  36. u8 tos, u8 type, u32 nlflags,
  37. u32 tb_id);
  38. int (*swdev_fib_ipv4_del)(struct net_device *dev, __be32 dst,
  39. int dst_len, struct fib_info *fi,
  40. u8 tos, u8 type, u32 tb_id);
  41. };
  42. enum netdev_switch_notifier_type {
  43. NETDEV_SWITCH_FDB_ADD = 1,
  44. NETDEV_SWITCH_FDB_DEL,
  45. };
  46. struct netdev_switch_notifier_info {
  47. struct net_device *dev;
  48. };
  49. struct netdev_switch_notifier_fdb_info {
  50. struct netdev_switch_notifier_info info; /* must be first */
  51. const unsigned char *addr;
  52. u16 vid;
  53. };
  54. static inline struct net_device *
  55. netdev_switch_notifier_info_to_dev(const struct netdev_switch_notifier_info *info)
  56. {
  57. return info->dev;
  58. }
  59. #ifdef CONFIG_NET_SWITCHDEV
  60. int netdev_switch_parent_id_get(struct net_device *dev,
  61. struct netdev_phys_item_id *psid);
  62. int netdev_switch_port_stp_update(struct net_device *dev, u8 state);
  63. int register_netdev_switch_notifier(struct notifier_block *nb);
  64. int unregister_netdev_switch_notifier(struct notifier_block *nb);
  65. int call_netdev_switch_notifiers(unsigned long val, struct net_device *dev,
  66. struct netdev_switch_notifier_info *info);
  67. int netdev_switch_port_bridge_setlink(struct net_device *dev,
  68. struct nlmsghdr *nlh, u16 flags);
  69. int netdev_switch_port_bridge_dellink(struct net_device *dev,
  70. struct nlmsghdr *nlh, u16 flags);
  71. int ndo_dflt_netdev_switch_port_bridge_dellink(struct net_device *dev,
  72. struct nlmsghdr *nlh, u16 flags);
  73. int ndo_dflt_netdev_switch_port_bridge_setlink(struct net_device *dev,
  74. struct nlmsghdr *nlh, u16 flags);
  75. int netdev_switch_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
  76. u8 tos, u8 type, u32 nlflags, u32 tb_id);
  77. int netdev_switch_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
  78. u8 tos, u8 type, u32 tb_id);
  79. void netdev_switch_fib_ipv4_abort(struct fib_info *fi);
  80. #else
  81. static inline int netdev_switch_parent_id_get(struct net_device *dev,
  82. struct netdev_phys_item_id *psid)
  83. {
  84. return -EOPNOTSUPP;
  85. }
  86. static inline int netdev_switch_port_stp_update(struct net_device *dev,
  87. u8 state)
  88. {
  89. return -EOPNOTSUPP;
  90. }
  91. static inline int register_netdev_switch_notifier(struct notifier_block *nb)
  92. {
  93. return 0;
  94. }
  95. static inline int unregister_netdev_switch_notifier(struct notifier_block *nb)
  96. {
  97. return 0;
  98. }
  99. static inline int call_netdev_switch_notifiers(unsigned long val, struct net_device *dev,
  100. struct netdev_switch_notifier_info *info)
  101. {
  102. return NOTIFY_DONE;
  103. }
  104. static inline int netdev_switch_port_bridge_setlink(struct net_device *dev,
  105. struct nlmsghdr *nlh,
  106. u16 flags)
  107. {
  108. return -EOPNOTSUPP;
  109. }
  110. static inline int netdev_switch_port_bridge_dellink(struct net_device *dev,
  111. struct nlmsghdr *nlh,
  112. u16 flags)
  113. {
  114. return -EOPNOTSUPP;
  115. }
  116. static inline int ndo_dflt_netdev_switch_port_bridge_dellink(struct net_device *dev,
  117. struct nlmsghdr *nlh,
  118. u16 flags)
  119. {
  120. return 0;
  121. }
  122. static inline int ndo_dflt_netdev_switch_port_bridge_setlink(struct net_device *dev,
  123. struct nlmsghdr *nlh,
  124. u16 flags)
  125. {
  126. return 0;
  127. }
  128. static inline int netdev_switch_fib_ipv4_add(u32 dst, int dst_len,
  129. struct fib_info *fi,
  130. u8 tos, u8 type,
  131. u32 nlflags, u32 tb_id)
  132. {
  133. return 0;
  134. }
  135. static inline int netdev_switch_fib_ipv4_del(u32 dst, int dst_len,
  136. struct fib_info *fi,
  137. u8 tos, u8 type, u32 tb_id)
  138. {
  139. return 0;
  140. }
  141. static inline void netdev_switch_fib_ipv4_abort(struct fib_info *fi)
  142. {
  143. }
  144. #endif
  145. #endif /* _LINUX_SWITCHDEV_H_ */