switchdev.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 switchdev_notifier_type {
  43. SWITCHDEV_FDB_ADD = 1,
  44. SWITCHDEV_FDB_DEL,
  45. };
  46. struct switchdev_notifier_info {
  47. struct net_device *dev;
  48. };
  49. struct switchdev_notifier_fdb_info {
  50. struct switchdev_notifier_info info; /* must be first */
  51. const unsigned char *addr;
  52. u16 vid;
  53. };
  54. static inline struct net_device *
  55. switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
  56. {
  57. return info->dev;
  58. }
  59. #ifdef CONFIG_NET_SWITCHDEV
  60. int switchdev_parent_id_get(struct net_device *dev,
  61. struct netdev_phys_item_id *psid);
  62. int switchdev_port_stp_update(struct net_device *dev, u8 state);
  63. int register_switchdev_notifier(struct notifier_block *nb);
  64. int unregister_switchdev_notifier(struct notifier_block *nb);
  65. int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
  66. struct switchdev_notifier_info *info);
  67. int switchdev_port_bridge_setlink(struct net_device *dev,
  68. struct nlmsghdr *nlh, u16 flags);
  69. int switchdev_port_bridge_dellink(struct net_device *dev,
  70. struct nlmsghdr *nlh, u16 flags);
  71. int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
  72. struct nlmsghdr *nlh, u16 flags);
  73. int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
  74. struct nlmsghdr *nlh, u16 flags);
  75. int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
  76. u8 tos, u8 type, u32 nlflags, u32 tb_id);
  77. int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
  78. u8 tos, u8 type, u32 tb_id);
  79. void switchdev_fib_ipv4_abort(struct fib_info *fi);
  80. #else
  81. static inline int switchdev_parent_id_get(struct net_device *dev,
  82. struct netdev_phys_item_id *psid)
  83. {
  84. return -EOPNOTSUPP;
  85. }
  86. static inline int switchdev_port_stp_update(struct net_device *dev,
  87. u8 state)
  88. {
  89. return -EOPNOTSUPP;
  90. }
  91. static inline int register_switchdev_notifier(struct notifier_block *nb)
  92. {
  93. return 0;
  94. }
  95. static inline int unregister_switchdev_notifier(struct notifier_block *nb)
  96. {
  97. return 0;
  98. }
  99. static inline int call_switchdev_notifiers(unsigned long val,
  100. struct net_device *dev,
  101. struct switchdev_notifier_info *info)
  102. {
  103. return NOTIFY_DONE;
  104. }
  105. static inline int switchdev_port_bridge_setlink(struct net_device *dev,
  106. struct nlmsghdr *nlh,
  107. u16 flags)
  108. {
  109. return -EOPNOTSUPP;
  110. }
  111. static inline int switchdev_port_bridge_dellink(struct net_device *dev,
  112. struct nlmsghdr *nlh,
  113. u16 flags)
  114. {
  115. return -EOPNOTSUPP;
  116. }
  117. static inline int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
  118. struct nlmsghdr *nlh,
  119. u16 flags)
  120. {
  121. return 0;
  122. }
  123. static inline int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
  124. struct nlmsghdr *nlh,
  125. u16 flags)
  126. {
  127. return 0;
  128. }
  129. static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
  130. struct fib_info *fi,
  131. u8 tos, u8 type,
  132. u32 nlflags, u32 tb_id)
  133. {
  134. return 0;
  135. }
  136. static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
  137. struct fib_info *fi,
  138. u8 tos, u8 type, u32 tb_id)
  139. {
  140. return 0;
  141. }
  142. static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
  143. {
  144. }
  145. #endif
  146. #endif /* _LINUX_SWITCHDEV_H_ */