switchdev.h 5.8 KB

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