aboutsummaryrefslogtreecommitdiff
path: root/include/net/switchdev.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/net/switchdev.h')
-rw-r--r--include/net/switchdev.h118
1 files changed, 73 insertions, 45 deletions
diff --git a/include/net/switchdev.h b/include/net/switchdev.h
index 319baab3b48e..e11425eb0735 100644
--- a/include/net/switchdev.h
+++ b/include/net/switchdev.h
@@ -1,6 +1,6 @@
/*
* include/net/switchdev.h - Switch device API
- * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
+ * Copyright (c) 2014-2015 Jiri Pirko <jiri@resnulli.us>
* Copyright (c) 2014-2015 Scott Feldman <sfeldma@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
@@ -13,16 +13,31 @@
#include <linux/netdevice.h>
#include <linux/notifier.h>
+#include <linux/list.h>
#define SWITCHDEV_F_NO_RECURSE BIT(0)
-enum switchdev_trans {
- SWITCHDEV_TRANS_NONE,
- SWITCHDEV_TRANS_PREPARE,
- SWITCHDEV_TRANS_ABORT,
- SWITCHDEV_TRANS_COMMIT,
+struct switchdev_trans_item {
+ struct list_head list;
+ void *data;
+ void (*destructor)(const void *data);
};
+struct switchdev_trans {
+ struct list_head item_list;
+ bool ph_prepare;
+};
+
+static inline bool switchdev_trans_ph_prepare(struct switchdev_trans *trans)
+{
+ return trans && trans->ph_prepare;
+}
+
+static inline bool switchdev_trans_ph_commit(struct switchdev_trans *trans)
+{
+ return trans && !trans->ph_prepare;
+}
+
enum switchdev_attr_id {
SWITCHDEV_ATTR_UNDEFINED,
SWITCHDEV_ATTR_PORT_PARENT_ID,
@@ -32,7 +47,6 @@ enum switchdev_attr_id {
struct switchdev_attr {
enum switchdev_attr_id id;
- enum switchdev_trans trans;
u32 flags;
union {
struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
@@ -50,33 +64,36 @@ enum switchdev_obj_id {
SWITCHDEV_OBJ_PORT_FDB,
};
-struct switchdev_obj {
- enum switchdev_obj_id id;
- enum switchdev_trans trans;
- int (*cb)(struct net_device *dev, struct switchdev_obj *obj);
- union {
- struct switchdev_obj_vlan { /* PORT_VLAN */
- u16 flags;
- u16 vid_begin;
- u16 vid_end;
- } vlan;
- struct switchdev_obj_ipv4_fib { /* IPV4_FIB */
- u32 dst;
- int dst_len;
- struct fib_info *fi;
- u8 tos;
- u8 type;
- u32 nlflags;
- u32 tb_id;
- } ipv4_fib;
- struct switchdev_obj_fdb { /* PORT_FDB */
- const unsigned char *addr;
- u16 vid;
- u16 ndm_state;
- } fdb;
- } u;
+/* SWITCHDEV_OBJ_PORT_VLAN */
+struct switchdev_obj_vlan {
+ u16 flags;
+ u16 vid_begin;
+ u16 vid_end;
+};
+
+/* SWITCHDEV_OBJ_IPV4_FIB */
+struct switchdev_obj_ipv4_fib {
+ u32 dst;
+ int dst_len;
+ struct fib_info *fi;
+ u8 tos;
+ u8 type;
+ u32 nlflags;
+ u32 tb_id;
};
+/* SWITCHDEV_OBJ_PORT_FDB */
+struct switchdev_obj_fdb {
+ const unsigned char *addr;
+ u16 vid;
+ u16 ndm_state;
+};
+
+void switchdev_trans_item_enqueue(struct switchdev_trans *trans,
+ void *data, void (*destructor)(void const *),
+ struct switchdev_trans_item *tritem);
+void *switchdev_trans_item_dequeue(struct switchdev_trans *trans);
+
/**
* struct switchdev_ops - switchdev operations
*
@@ -84,23 +101,28 @@ struct switchdev_obj {
*
* @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
*
- * @switchdev_port_obj_add: Add an object to port (see switchdev_obj).
+ * @switchdev_port_obj_add: Add an object to port (see switchdev_obj_*).
*
- * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj).
+ * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj_*).
*
- * @switchdev_port_obj_dump: Dump port objects (see switchdev_obj).
+ * @switchdev_port_obj_dump: Dump port objects (see switchdev_obj_*).
*/
struct switchdev_ops {
int (*switchdev_port_attr_get)(struct net_device *dev,
struct switchdev_attr *attr);
int (*switchdev_port_attr_set)(struct net_device *dev,
- struct switchdev_attr *attr);
+ struct switchdev_attr *attr,
+ struct switchdev_trans *trans);
int (*switchdev_port_obj_add)(struct net_device *dev,
- struct switchdev_obj *obj);
+ enum switchdev_obj_id id,
+ const void *obj,
+ struct switchdev_trans *trans);
int (*switchdev_port_obj_del)(struct net_device *dev,
- struct switchdev_obj *obj);
+ enum switchdev_obj_id id,
+ const void *obj);
int (*switchdev_port_obj_dump)(struct net_device *dev,
- struct switchdev_obj *obj);
+ enum switchdev_obj_id id, void *obj,
+ int (*cb)(void *obj));
};
enum switchdev_notifier_type {
@@ -130,9 +152,12 @@ int switchdev_port_attr_get(struct net_device *dev,
struct switchdev_attr *attr);
int switchdev_port_attr_set(struct net_device *dev,
struct switchdev_attr *attr);
-int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj);
-int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj);
-int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj);
+int switchdev_port_obj_add(struct net_device *dev, enum switchdev_obj_id id,
+ const void *obj);
+int switchdev_port_obj_del(struct net_device *dev, enum switchdev_obj_id id,
+ const void *obj);
+int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id,
+ void *obj, int (*cb)(void *obj));
int register_switchdev_notifier(struct notifier_block *nb);
int unregister_switchdev_notifier(struct notifier_block *nb);
int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
@@ -177,19 +202,22 @@ static inline int switchdev_port_attr_set(struct net_device *dev,
}
static inline int switchdev_port_obj_add(struct net_device *dev,
- struct switchdev_obj *obj)
+ enum switchdev_obj_id id,
+ const void *obj)
{
return -EOPNOTSUPP;
}
static inline int switchdev_port_obj_del(struct net_device *dev,
- struct switchdev_obj *obj)
+ enum switchdev_obj_id id,
+ const void *obj)
{
return -EOPNOTSUPP;
}
static inline int switchdev_port_obj_dump(struct net_device *dev,
- struct switchdev_obj *obj)
+ enum switchdev_obj_id id, void *obj,
+ int (*cb)(void *obj))
{
return -EOPNOTSUPP;
}