blob: d2e69ee3019a06308dbf2951283d6db663d0ad78 [file] [log] [blame]
Jiri Pirko007f7902014-11-28 14:34:17 +01001/*
2 * include/net/switchdev.h - Switch device API
3 * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
Scott Feldmanf8f21472015-03-09 13:59:09 -07004 * Copyright (c) 2014-2015 Scott Feldman <sfeldma@gmail.com>
Jiri Pirko007f7902014-11-28 14:34:17 +01005 *
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
14#include <linux/netdevice.h>
Jiri Pirko03bf0c22015-01-15 23:49:36 +010015#include <linux/notifier.h>
16
Scott Feldman41706042015-03-15 21:07:14 -070017struct fib_info;
18
19/**
20 * struct switchdev_ops - switchdev operations
21 *
Scott Feldman13bb8e22015-03-20 17:42:46 -070022 * @swdev_parent_id_get: Called to get an ID of the switch chip this port
23 * is part of. If driver implements this, it indicates that it
24 * represents a port of a switch chip.
Scott Feldman41706042015-03-15 21:07:14 -070025 *
Scott Feldman13bb8e22015-03-20 17:42:46 -070026 * @swdev_port_stp_update: Called to notify switch device port of bridge
27 * port STP state change.
Scott Feldman41706042015-03-15 21:07:14 -070028 *
Scott Feldman13bb8e22015-03-20 17:42:46 -070029 * @swdev_fib_ipv4_add: Called to add/modify IPv4 route to switch device.
Scott Feldman41706042015-03-15 21:07:14 -070030 *
Scott Feldman13bb8e22015-03-20 17:42:46 -070031 * @swdev_fib_ipv4_del: Called to delete IPv4 route from switch device.
Scott Feldman41706042015-03-15 21:07:14 -070032 */
33struct swdev_ops {
34 int (*swdev_parent_id_get)(struct net_device *dev,
35 struct netdev_phys_item_id *psid);
36 int (*swdev_port_stp_update)(struct net_device *dev, u8 state);
37 int (*swdev_fib_ipv4_add)(struct net_device *dev, __be32 dst,
38 int dst_len, struct fib_info *fi,
39 u8 tos, u8 type, u32 nlflags,
40 u32 tb_id);
41 int (*swdev_fib_ipv4_del)(struct net_device *dev, __be32 dst,
42 int dst_len, struct fib_info *fi,
43 u8 tos, u8 type, u32 tb_id);
44};
45
Jiri Pirko3aeb6612015-01-15 23:49:37 +010046enum netdev_switch_notifier_type {
47 NETDEV_SWITCH_FDB_ADD = 1,
48 NETDEV_SWITCH_FDB_DEL,
49};
50
Jiri Pirko03bf0c22015-01-15 23:49:36 +010051struct netdev_switch_notifier_info {
52 struct net_device *dev;
53};
54
Jiri Pirko3aeb6612015-01-15 23:49:37 +010055struct netdev_switch_notifier_fdb_info {
56 struct netdev_switch_notifier_info info; /* must be first */
57 const unsigned char *addr;
58 u16 vid;
59};
60
Jiri Pirko03bf0c22015-01-15 23:49:36 +010061static inline struct net_device *
62netdev_switch_notifier_info_to_dev(const struct netdev_switch_notifier_info *info)
63{
64 return info->dev;
65}
Jiri Pirko007f7902014-11-28 14:34:17 +010066
67#ifdef CONFIG_NET_SWITCHDEV
68
69int netdev_switch_parent_id_get(struct net_device *dev,
70 struct netdev_phys_item_id *psid);
Scott Feldman38dcf352014-11-28 14:34:20 +010071int netdev_switch_port_stp_update(struct net_device *dev, u8 state);
Jiri Pirko03bf0c22015-01-15 23:49:36 +010072int register_netdev_switch_notifier(struct notifier_block *nb);
73int unregister_netdev_switch_notifier(struct notifier_block *nb);
74int call_netdev_switch_notifiers(unsigned long val, struct net_device *dev,
75 struct netdev_switch_notifier_info *info);
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -080076int netdev_switch_port_bridge_setlink(struct net_device *dev,
77 struct nlmsghdr *nlh, u16 flags);
78int netdev_switch_port_bridge_dellink(struct net_device *dev,
79 struct nlmsghdr *nlh, u16 flags);
80int ndo_dflt_netdev_switch_port_bridge_dellink(struct net_device *dev,
81 struct nlmsghdr *nlh, u16 flags);
82int ndo_dflt_netdev_switch_port_bridge_setlink(struct net_device *dev,
83 struct nlmsghdr *nlh, u16 flags);
Scott Feldman5e8d9042015-03-05 21:21:15 -080084int netdev_switch_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
Scott Feldmanf8f21472015-03-09 13:59:09 -070085 u8 tos, u8 type, u32 nlflags, u32 tb_id);
Scott Feldman5e8d9042015-03-05 21:21:15 -080086int netdev_switch_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
87 u8 tos, u8 type, u32 tb_id);
Scott Feldman8e05fd72015-03-05 21:21:19 -080088void netdev_switch_fib_ipv4_abort(struct fib_info *fi);
Scott Feldman5e8d9042015-03-05 21:21:15 -080089
Jiri Pirko007f7902014-11-28 14:34:17 +010090#else
91
92static inline int netdev_switch_parent_id_get(struct net_device *dev,
93 struct netdev_phys_item_id *psid)
94{
95 return -EOPNOTSUPP;
96}
97
Scott Feldman38dcf352014-11-28 14:34:20 +010098static inline int netdev_switch_port_stp_update(struct net_device *dev,
99 u8 state)
100{
101 return -EOPNOTSUPP;
102}
103
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100104static inline int register_netdev_switch_notifier(struct notifier_block *nb)
105{
106 return 0;
107}
108
109static inline int unregister_netdev_switch_notifier(struct notifier_block *nb)
110{
111 return 0;
112}
113
114static inline int call_netdev_switch_notifiers(unsigned long val, struct net_device *dev,
Jiri Pirko27c00132015-01-18 10:25:56 +0100115 struct netdev_switch_notifier_info *info)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100116{
117 return NOTIFY_DONE;
118}
119
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800120static inline int netdev_switch_port_bridge_setlink(struct net_device *dev,
121 struct nlmsghdr *nlh,
122 u16 flags)
123{
124 return -EOPNOTSUPP;
125}
126
127static inline int netdev_switch_port_bridge_dellink(struct net_device *dev,
128 struct nlmsghdr *nlh,
129 u16 flags)
130{
131 return -EOPNOTSUPP;
132}
133
134static inline int ndo_dflt_netdev_switch_port_bridge_dellink(struct net_device *dev,
135 struct nlmsghdr *nlh,
136 u16 flags)
137{
138 return 0;
139}
140
141static inline int ndo_dflt_netdev_switch_port_bridge_setlink(struct net_device *dev,
142 struct nlmsghdr *nlh,
143 u16 flags)
144{
145 return 0;
146}
147
Scott Feldman5e8d9042015-03-05 21:21:15 -0800148static inline int netdev_switch_fib_ipv4_add(u32 dst, int dst_len,
149 struct fib_info *fi,
Scott Feldmanf8f21472015-03-09 13:59:09 -0700150 u8 tos, u8 type,
151 u32 nlflags, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800152{
153 return 0;
154}
155
156static inline int netdev_switch_fib_ipv4_del(u32 dst, int dst_len,
157 struct fib_info *fi,
158 u8 tos, u8 type, u32 tb_id)
159{
160 return 0;
161}
162
Willem de Bruijn89650ad2015-03-06 11:44:28 -0500163static inline void netdev_switch_fib_ipv4_abort(struct fib_info *fi)
Scott Feldman8e05fd72015-03-05 21:21:19 -0800164{
165}
166
Jiri Pirko007f7902014-11-28 14:34:17 +0100167#endif
168
169#endif /* _LINUX_SWITCHDEV_H_ */