switchdev.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. SWITCHDEV_ATTR_PORT_PARENT_ID,
  25. SWITCHDEV_ATTR_PORT_STP_STATE,
  26. };
  27. struct switchdev_attr {
  28. enum switchdev_attr_id id;
  29. enum switchdev_trans trans;
  30. u32 flags;
  31. union {
  32. struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
  33. u8 stp_state; /* PORT_STP_STATE */
  34. };
  35. };
  36. struct fib_info;
  37. enum switchdev_obj_id {
  38. SWITCHDEV_OBJ_UNDEFINED,
  39. };
  40. struct switchdev_obj {
  41. enum switchdev_obj_id id;
  42. enum switchdev_trans trans;
  43. };
  44. /**
  45. * struct switchdev_ops - switchdev operations
  46. *
  47. * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
  48. *
  49. * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
  50. *
  51. * @switchdev_port_obj_add: Add an object to port (see switchdev_obj).
  52. *
  53. * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj).
  54. *
  55. * @switchdev_fib_ipv4_add: Called to add/modify IPv4 route to switch device.
  56. *
  57. * @switchdev_fib_ipv4_del: Called to delete IPv4 route from switch device.
  58. */
  59. struct switchdev_ops {
  60. int (*switchdev_port_attr_get)(struct net_device *dev,
  61. struct switchdev_attr *attr);
  62. int (*switchdev_port_attr_set)(struct net_device *dev,
  63. struct switchdev_attr *attr);
  64. int (*switchdev_port_obj_add)(struct net_device *dev,
  65. struct switchdev_obj *obj);
  66. int (*switchdev_port_obj_del)(struct net_device *dev,
  67. struct switchdev_obj *obj);
  68. int (*switchdev_fib_ipv4_add)(struct net_device *dev, __be32 dst,
  69. int dst_len, struct fib_info *fi,
  70. u8 tos, u8 type, u32 nlflags,
  71. u32 tb_id);
  72. int (*switchdev_fib_ipv4_del)(struct net_device *dev, __be32 dst,
  73. int dst_len, struct fib_info *fi,
  74. u8 tos, u8 type, u32 tb_id);
  75. };
  76. enum switchdev_notifier_type {
  77. SWITCHDEV_FDB_ADD = 1,
  78. SWITCHDEV_FDB_DEL,
  79. };
  80. struct switchdev_notifier_info {
  81. struct net_device *dev;
  82. };
  83. struct switchdev_notifier_fdb_info {
  84. struct switchdev_notifier_info info; /* must be first */
  85. const unsigned char *addr;
  86. u16 vid;
  87. };
  88. static inline struct net_device *
  89. switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
  90. {
  91. return info->dev;
  92. }
  93. #ifdef CONFIG_NET_SWITCHDEV
  94. int switchdev_port_attr_get(struct net_device *dev,
  95. struct switchdev_attr *attr);
  96. int switchdev_port_attr_set(struct net_device *dev,
  97. struct switchdev_attr *attr);
  98. int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj);
  99. int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj);
  100. int register_switchdev_notifier(struct notifier_block *nb);
  101. int unregister_switchdev_notifier(struct notifier_block *nb);
  102. int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
  103. struct switchdev_notifier_info *info);
  104. int switchdev_port_bridge_setlink(struct net_device *dev,
  105. struct nlmsghdr *nlh, u16 flags);
  106. int switchdev_port_bridge_dellink(struct net_device *dev,
  107. struct nlmsghdr *nlh, u16 flags);
  108. int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
  109. struct nlmsghdr *nlh, u16 flags);
  110. int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
  111. struct nlmsghdr *nlh, u16 flags);
  112. int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
  113. u8 tos, u8 type, u32 nlflags, u32 tb_id);
  114. int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
  115. u8 tos, u8 type, u32 tb_id);
  116. void switchdev_fib_ipv4_abort(struct fib_info *fi);
  117. #else
  118. static inline int switchdev_port_attr_get(struct net_device *dev,
  119. struct switchdev_attr *attr)
  120. {
  121. return -EOPNOTSUPP;
  122. }
  123. static inline int switchdev_port_attr_set(struct net_device *dev,
  124. struct switchdev_attr *attr)
  125. {
  126. return -EOPNOTSUPP;
  127. }
  128. static inline int switchdev_port_obj_add(struct net_device *dev,
  129. struct switchdev_obj *obj)
  130. {
  131. return -EOPNOTSUPP;
  132. }
  133. static inline int switchdev_port_obj_del(struct net_device *dev,
  134. struct switchdev_obj *obj)
  135. {
  136. return -EOPNOTSUPP;
  137. }
  138. static inline int register_switchdev_notifier(struct notifier_block *nb)
  139. {
  140. return 0;
  141. }
  142. static inline int unregister_switchdev_notifier(struct notifier_block *nb)
  143. {
  144. return 0;
  145. }
  146. static inline int call_switchdev_notifiers(unsigned long val,
  147. struct net_device *dev,
  148. struct switchdev_notifier_info *info)
  149. {
  150. return NOTIFY_DONE;
  151. }
  152. static inline int switchdev_port_bridge_setlink(struct net_device *dev,
  153. struct nlmsghdr *nlh,
  154. u16 flags)
  155. {
  156. return -EOPNOTSUPP;
  157. }
  158. static inline int switchdev_port_bridge_dellink(struct net_device *dev,
  159. struct nlmsghdr *nlh,
  160. u16 flags)
  161. {
  162. return -EOPNOTSUPP;
  163. }
  164. static inline int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
  165. struct nlmsghdr *nlh,
  166. u16 flags)
  167. {
  168. return 0;
  169. }
  170. static inline int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
  171. struct nlmsghdr *nlh,
  172. u16 flags)
  173. {
  174. return 0;
  175. }
  176. static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
  177. struct fib_info *fi,
  178. u8 tos, u8 type,
  179. u32 nlflags, u32 tb_id)
  180. {
  181. return 0;
  182. }
  183. static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
  184. struct fib_info *fi,
  185. u8 tos, u8 type, u32 tb_id)
  186. {
  187. return 0;
  188. }
  189. static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
  190. {
  191. }
  192. #endif
  193. #endif /* _LINUX_SWITCHDEV_H_ */