datpath: Avoid reporting half updated statistics.
[sliver-openvswitch.git] / datapath / vport.h
index baa9432..0a6801d 100644 (file)
@@ -10,6 +10,7 @@
 #define VPORT_H 1
 
 #include <linux/list.h>
+#include <linux/seqlock.h>
 #include <linux/skbuff.h>
 #include <linux/spinlock.h>
 
@@ -22,30 +23,31 @@ struct dp_port;
 
 /* The following definitions are for users of the vport subsytem: */
 
+int vport_user_add(const struct odp_vport_add __user *);
+int vport_user_mod(const struct odp_vport_mod __user *);
+int vport_user_del(const char __user *udevname);
+
+#ifdef CONFIG_COMPAT
+int compat_vport_user_add(struct compat_odp_vport_add __user *);
+int compat_vport_user_mod(struct compat_odp_vport_mod __user *);
+#endif
+
+int vport_user_stats_get(struct odp_vport_stats_req __user *);
+int vport_user_stats_set(struct odp_vport_stats_req __user *);
+int vport_user_ether_get(struct odp_vport_ether __user *);
+int vport_user_ether_set(struct odp_vport_ether __user *);
+int vport_user_mtu_get(struct odp_vport_mtu __user *);
+int vport_user_mtu_set(struct odp_vport_mtu __user *);
+
 void vport_lock(void);
 void vport_unlock(void);
 
 int vport_init(void);
 void vport_exit(void);
 
-int vport_add(const struct odp_vport_add __user *);
-int vport_mod(const struct odp_vport_mod __user *);
-int vport_del(const char __user *udevname);
-
-#ifdef CONFIG_COMPAT
-int compat_vport_add(struct compat_odp_vport_add __user *);
-int compat_vport_mod(struct compat_odp_vport_mod __user *);
-#endif
-
-int vport_stats_get(struct odp_vport_stats_req __user *);
-int vport_ether_get(struct odp_vport_ether __user *);
-int vport_ether_set(struct odp_vport_ether __user *);
-int vport_mtu_get(struct odp_vport_mtu __user *);
-int vport_mtu_set(struct odp_vport_mtu __user *);
-
-struct vport *__vport_add(const char *name, const char *type, const void __user *config);
-int __vport_mod(struct vport *, const void __user *config);
-int __vport_del(struct vport *);
+struct vport *vport_add(const char *name, const char *type, const void __user *config);
+int vport_mod(struct vport *, const void __user *config);
+int vport_del(struct vport *);
 
 struct vport *vport_locate(const char *name);
 
@@ -54,14 +56,15 @@ int vport_detach(struct vport *);
 
 int vport_set_mtu(struct vport *, int mtu);
 int vport_set_addr(struct vport *, const unsigned char *);
+int vport_set_stats(struct vport *, struct odp_vport_stats *);
 
 const char *vport_get_name(const struct vport *);
 const char *vport_get_type(const struct vport *);
 const unsigned char *vport_get_addr(const struct vport *);
 
 struct dp_port *vport_get_dp_port(const struct vport *);
-
 struct kobject *vport_get_kobj(const struct vport *);
+int vport_get_stats(struct vport *, struct odp_vport_stats *);
 
 unsigned vport_get_flags(const struct vport *);
 int vport_is_running(const struct vport *);
@@ -81,11 +84,10 @@ struct vport_percpu_stats {
        u64 rx_packets;
        u64 tx_bytes;
        u64 tx_packets;
+       seqcount_t seqlock;
 };
 
 struct vport_err_stats {
-       spinlock_t lock;
-
        u64 rx_dropped;
        u64 rx_errors;
        u64 rx_frame_err;
@@ -102,7 +104,10 @@ struct vport {
        struct dp_port *dp_port;
 
        struct vport_percpu_stats *percpu_stats;
+
+       spinlock_t stats_lock;
        struct vport_err_stats err_stats;
+       struct odp_vport_stats offset_stats;
 };
 
 #define VPORT_F_REQUIRED       (1 << 0) /* If init fails, module loading fails. */
@@ -133,12 +138,15 @@ struct vport {
  * @detach: Detach a vport from a datapath.  May be null if not needed.
  * @set_mtu: Set the device's MTU.  May be null if not supported.
  * @set_addr: Set the device's MAC address.  May be null if not supported.
+ * @set_stats: Provides stats as an offset to be added to the device stats.
+ * May be null if not supported.
  * @get_name: Get the device's name.
  * @get_addr: Get the device's MAC address.
  * @get_kobj: Get the kobj associated with the device (may return null).
  * @get_stats: Fill in the transmit/receive stats.  May be null if stats are
- * not supported or if generic stats are in use.  If defined overrides
- * VPORT_F_GEN_STATS.
+ * not supported or if generic stats are in use.  If defined and
+ * VPORT_F_GEN_STATS is also set, the error stats are added to those already
+ * collected.
  * @get_dev_flags: Get the device's flags.
  * @is_running: Checks whether the device is running.
  * @get_operstate: Get the device's operating state.
@@ -168,6 +176,7 @@ struct vport_ops {
 
        int (*set_mtu)(struct vport *, int mtu);
        int (*set_addr)(struct vport *, const unsigned char *);
+       int (*set_stats)(const struct vport *, struct odp_vport_stats *);
 
        /* Called with rcu_read_lock or RTNL lock. */
        const char *(*get_name)(const struct vport *);
@@ -212,8 +221,7 @@ void vport_free(struct vport *);
  * area was allocated on creation.  This allows that area to be accessed and
  * used for any purpose needed by the vport implementer.
  */
-static inline void *
-vport_priv(const struct vport *vport)
+static inline void *vport_priv(const struct vport *vport)
 {
        return (u8 *)vport + ALIGN(sizeof(struct vport), VPORT_ALIGN);
 }
@@ -228,8 +236,7 @@ vport_priv(const struct vport *vport)
  * the result of a hash table lookup.  @priv must point to the start of the
  * private data area.
  */
-static inline struct vport *
-vport_from_priv(const void *priv)
+static inline struct vport *vport_from_priv(const void *priv)
 {
        return (struct vport *)(priv - ALIGN(sizeof(struct vport), VPORT_ALIGN));
 }
@@ -237,4 +244,11 @@ vport_from_priv(const void *priv)
 void vport_receive(struct vport *, struct sk_buff *);
 void vport_record_error(struct vport *, enum vport_err_type err_type);
 
+/* List of statically compiled vport implementations.  Don't forget to also
+ * add yours to the list at the top of vport.c. */
+extern struct vport_ops netdev_vport_ops;
+extern struct vport_ops internal_vport_ops;
+extern struct vport_ops patch_vport_ops;
+extern struct vport_ops gre_vport_ops;
+
 #endif /* vport.h */