switchdev.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. #define SWITCHDEV_F_NO_RECURSE BIT(0)
  16. enum switchdev_trans {
  17. SWITCHDEV_TRANS_NONE,
  18. SWITCHDEV_TRANS_PREPARE,
  19. SWITCHDEV_TRANS_ABORT,
  20. SWITCHDEV_TRANS_COMMIT,
  21. };
  22. enum switchdev_attr_id {
  23. SWITCHDEV_ATTR_UNDEFINED,
  24. };
  25. struct switchdev_attr {
  26. enum switchdev_attr_id id;
  27. enum switchdev_trans trans;
  28. u32 flags;
  29. };
  30. struct fib_info;
  31. /**
  32. * struct switchdev_ops - switchdev operations
  33. *
  34. * @switchdev_parent_id_get: Called to get an ID of the switch chip this port
  35. * is part of. If driver implements this, it indicates that it
  36. * represents a port of a switch chip.
  37. *
  38. * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
  39. *
  40. * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
  41. *
  42. * @switchdev_port_stp_update: Called to notify switch device port of bridge
  43. * port STP state change.
  44. *
  45. * @switchdev_fib_ipv4_add: Called to add/modify IPv4 route to switch device.
  46. *
  47. * @switchdev_fib_ipv4_del: Called to delete IPv4 route from switch device.
  48. */
  49. struct switchdev_ops {
  50. int (*switchdev_parent_id_get)(struct net_device *dev,
  51. struct netdev_phys_item_id *psid);
  52. int (*switchdev_port_attr_get)(struct net_device *dev,
  53. struct switchdev_attr *attr);
  54. int (*switchdev_port_attr_set)(struct net_device *dev,
  55. struct switchdev_attr *attr);
  56. int (*switchdev_port_stp_update)(struct net_device *dev, u8 state);
  57. int (*switchdev_fib_ipv4_add)(struct net_device *dev, __be32 dst,
  58. int dst_len, struct fib_info *fi,
  59. u8 tos, u8 type, u32 nlflags,
  60. u32 tb_id);
  61. int (*switchdev_fib_ipv4_del)(struct net_device *dev, __be32 dst,
  62. int dst_len, struct fib_info *fi,
  63. u8 tos, u8 type, u32 tb_id);
  64. };
  65. enum switchdev_notifier_type {
  66. SWITCHDEV_FDB_ADD = 1,
  67. SWITCHDEV_FDB_DEL,
  68. };
  69. struct switchdev_notifier_info {
  70. struct net_device *dev;
  71. };
  72. struct switchdev_notifier_fdb_info {
  73. struct switchdev_notifier_info info; /* must be first */
  74. const unsigned char *addr;
  75. u16 vid;
  76. };
  77. static inline struct net_device *
  78. switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
  79. {
  80. return info->dev;
  81. }
  82. #ifdef CONFIG_NET_SWITCHDEV
  83. int switchdev_parent_id_get(struct net_device *dev,
  84. struct netdev_phys_item_id *psid);
  85. int switchdev_port_attr_get(struct net_device *dev,
  86. struct switchdev_attr *attr);
  87. int switchdev_port_attr_set(struct net_device *dev,
  88. struct switchdev_attr *attr);
  89. int switchdev_port_stp_update(struct net_device *dev, u8 state);
  90. int register_switchdev_notifier(struct notifier_block *nb);
  91. int unregister_switchdev_notifier(struct notifier_block *nb);
  92. int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
  93. struct switchdev_notifier_info *info);
  94. int switchdev_port_bridge_setlink(struct net_device *dev,
  95. struct nlmsghdr *nlh, u16 flags);
  96. int switchdev_port_bridge_dellink(struct net_device *dev,
  97. struct nlmsghdr *nlh, u16 flags);
  98. int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
  99. struct nlmsghdr *nlh, u16 flags);
  100. int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
  101. struct nlmsghdr *nlh, u16 flags);
  102. int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
  103. u8 tos, u8 type, u32 nlflags, u32 tb_id);
  104. int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
  105. u8 tos, u8 type, u32 tb_id);
  106. void switchdev_fib_ipv4_abort(struct fib_info *fi);
  107. #else
  108. static inline int switchdev_parent_id_get(struct net_device *dev,
  109. struct netdev_phys_item_id *psid)
  110. {
  111. return -EOPNOTSUPP;
  112. }
  113. static inline int switchdev_port_attr_get(struct net_device *dev,
  114. struct switchdev_attr *attr)
  115. {
  116. return -EOPNOTSUPP;
  117. }
  118. static inline int switchdev_port_attr_set(struct net_device *dev,
  119. struct switchdev_attr *attr)
  120. {
  121. return -EOPNOTSUPP;
  122. }
  123. static inline int switchdev_port_stp_update(struct net_device *dev,
  124. u8 state)
  125. {
  126. return -EOPNOTSUPP;
  127. }
  128. static inline int register_switchdev_notifier(struct notifier_block *nb)
  129. {
  130. return 0;
  131. }
  132. static inline int unregister_switchdev_notifier(struct notifier_block *nb)
  133. {
  134. return 0;
  135. }
  136. static inline int call_switchdev_notifiers(unsigned long val,
  137. struct net_device *dev,
  138. struct switchdev_notifier_info *info)
  139. {
  140. return NOTIFY_DONE;
  141. }
  142. static inline int switchdev_port_bridge_setlink(struct net_device *dev,
  143. struct nlmsghdr *nlh,
  144. u16 flags)
  145. {
  146. return -EOPNOTSUPP;
  147. }
  148. static inline int switchdev_port_bridge_dellink(struct net_device *dev,
  149. struct nlmsghdr *nlh,
  150. u16 flags)
  151. {
  152. return -EOPNOTSUPP;
  153. }
  154. static inline int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
  155. struct nlmsghdr *nlh,
  156. u16 flags)
  157. {
  158. return 0;
  159. }
  160. static inline int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
  161. struct nlmsghdr *nlh,
  162. u16 flags)
  163. {
  164. return 0;
  165. }
  166. static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
  167. struct fib_info *fi,
  168. u8 tos, u8 type,
  169. u32 nlflags, u32 tb_id)
  170. {
  171. return 0;
  172. }
  173. static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
  174. struct fib_info *fi,
  175. u8 tos, u8 type, u32 tb_id)
  176. {
  177. return 0;
  178. }
  179. static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
  180. {
  181. }
  182. #endif
  183. #endif /* _LINUX_SWITCHDEV_H_ */