switchdev.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. * int (*swdev_parent_id_get)(struct net_device *dev,
  20. * struct netdev_phys_item_id *psid);
  21. * Called to get an ID of the switch chip this port is part of.
  22. * If driver implements this, it indicates that it represents a port
  23. * of a switch chip.
  24. *
  25. * int (*swdev_port_stp_update)(struct net_device *dev, u8 state);
  26. * Called to notify switch device port of bridge port STP
  27. * state change.
  28. *
  29. * int (*swdev_fib_ipv4_add)(struct net_device *dev, __be32 dst,
  30. * int dst_len, struct fib_info *fi,
  31. * u8 tos, u8 type, u32 nlflags, u32 tb_id);
  32. * Called to add/modify IPv4 route to switch device.
  33. *
  34. * int (*swdev_fib_ipv4_del)(struct net_device *dev, __be32 dst,
  35. * int dst_len, struct fib_info *fi,
  36. * u8 tos, u8 type, u32 tb_id);
  37. * Called to delete IPv4 route from switch device.
  38. */
  39. struct swdev_ops {
  40. int (*swdev_parent_id_get)(struct net_device *dev,
  41. struct netdev_phys_item_id *psid);
  42. int (*swdev_port_stp_update)(struct net_device *dev, u8 state);
  43. int (*swdev_fib_ipv4_add)(struct net_device *dev, __be32 dst,
  44. int dst_len, struct fib_info *fi,
  45. u8 tos, u8 type, u32 nlflags,
  46. u32 tb_id);
  47. int (*swdev_fib_ipv4_del)(struct net_device *dev, __be32 dst,
  48. int dst_len, struct fib_info *fi,
  49. u8 tos, u8 type, u32 tb_id);
  50. };
  51. enum netdev_switch_notifier_type {
  52. NETDEV_SWITCH_FDB_ADD = 1,
  53. NETDEV_SWITCH_FDB_DEL,
  54. };
  55. struct netdev_switch_notifier_info {
  56. struct net_device *dev;
  57. };
  58. struct netdev_switch_notifier_fdb_info {
  59. struct netdev_switch_notifier_info info; /* must be first */
  60. const unsigned char *addr;
  61. u16 vid;
  62. };
  63. static inline struct net_device *
  64. netdev_switch_notifier_info_to_dev(const struct netdev_switch_notifier_info *info)
  65. {
  66. return info->dev;
  67. }
  68. #ifdef CONFIG_NET_SWITCHDEV
  69. int netdev_switch_parent_id_get(struct net_device *dev,
  70. struct netdev_phys_item_id *psid);
  71. int netdev_switch_port_stp_update(struct net_device *dev, u8 state);
  72. int register_netdev_switch_notifier(struct notifier_block *nb);
  73. int unregister_netdev_switch_notifier(struct notifier_block *nb);
  74. int call_netdev_switch_notifiers(unsigned long val, struct net_device *dev,
  75. struct netdev_switch_notifier_info *info);
  76. int netdev_switch_port_bridge_setlink(struct net_device *dev,
  77. struct nlmsghdr *nlh, u16 flags);
  78. int netdev_switch_port_bridge_dellink(struct net_device *dev,
  79. struct nlmsghdr *nlh, u16 flags);
  80. int ndo_dflt_netdev_switch_port_bridge_dellink(struct net_device *dev,
  81. struct nlmsghdr *nlh, u16 flags);
  82. int ndo_dflt_netdev_switch_port_bridge_setlink(struct net_device *dev,
  83. struct nlmsghdr *nlh, u16 flags);
  84. int netdev_switch_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
  85. u8 tos, u8 type, u32 nlflags, u32 tb_id);
  86. int netdev_switch_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
  87. u8 tos, u8 type, u32 tb_id);
  88. void netdev_switch_fib_ipv4_abort(struct fib_info *fi);
  89. #else
  90. static inline int netdev_switch_parent_id_get(struct net_device *dev,
  91. struct netdev_phys_item_id *psid)
  92. {
  93. return -EOPNOTSUPP;
  94. }
  95. static inline int netdev_switch_port_stp_update(struct net_device *dev,
  96. u8 state)
  97. {
  98. return -EOPNOTSUPP;
  99. }
  100. static inline int register_netdev_switch_notifier(struct notifier_block *nb)
  101. {
  102. return 0;
  103. }
  104. static inline int unregister_netdev_switch_notifier(struct notifier_block *nb)
  105. {
  106. return 0;
  107. }
  108. static inline int call_netdev_switch_notifiers(unsigned long val, struct net_device *dev,
  109. struct netdev_switch_notifier_info *info)
  110. {
  111. return NOTIFY_DONE;
  112. }
  113. static inline int netdev_switch_port_bridge_setlink(struct net_device *dev,
  114. struct nlmsghdr *nlh,
  115. u16 flags)
  116. {
  117. return -EOPNOTSUPP;
  118. }
  119. static inline int netdev_switch_port_bridge_dellink(struct net_device *dev,
  120. struct nlmsghdr *nlh,
  121. u16 flags)
  122. {
  123. return -EOPNOTSUPP;
  124. }
  125. static inline int ndo_dflt_netdev_switch_port_bridge_dellink(struct net_device *dev,
  126. struct nlmsghdr *nlh,
  127. u16 flags)
  128. {
  129. return 0;
  130. }
  131. static inline int ndo_dflt_netdev_switch_port_bridge_setlink(struct net_device *dev,
  132. struct nlmsghdr *nlh,
  133. u16 flags)
  134. {
  135. return 0;
  136. }
  137. static inline int netdev_switch_fib_ipv4_add(u32 dst, int dst_len,
  138. struct fib_info *fi,
  139. u8 tos, u8 type,
  140. u32 nlflags, u32 tb_id)
  141. {
  142. return 0;
  143. }
  144. static inline int netdev_switch_fib_ipv4_del(u32 dst, int dst_len,
  145. struct fib_info *fi,
  146. u8 tos, u8 type, u32 tb_id)
  147. {
  148. return 0;
  149. }
  150. static inline void netdev_switch_fib_ipv4_abort(struct fib_info *fi)
  151. {
  152. }
  153. #endif
  154. #endif /* _LINUX_SWITCHDEV_H_ */