2 * Copyright (c) 2010 Nicira Networks.
3 * Distributed under the terms of the GNU GPL version 2.
5 * Significant portions of this file may be copied from parts of the Linux
6 * kernel, by Linus Torvalds and others.
9 #include <linux/dcache.h>
10 #include <linux/etherdevice.h>
12 #include <linux/kernel.h>
13 #include <linux/list.h>
14 #include <linux/mutex.h>
15 #include <linux/percpu.h>
16 #include <linux/rtnetlink.h>
17 #include <linux/compat.h>
20 #include "vport-internal_dev.h"
22 extern struct vport_ops netdev_vport_ops;
23 extern struct vport_ops internal_vport_ops;
24 extern struct vport_ops patch_vport_ops;
25 extern struct vport_ops gre_vport_ops;
27 static struct vport_ops *base_vport_ops_list[] = {
34 static const struct vport_ops **vport_ops_list;
35 static int n_vport_types;
37 static struct hlist_head *dev_table;
38 #define VPORT_HASH_BUCKETS 1024
40 /* Both RTNL lock and vport_mutex need to be held when updating dev_table.
42 * If you use vport_locate and then perform some operations, you need to hold
43 * one of these locks if you don't want the vport to be deleted out from under
46 * If you get a reference to a vport through a dp_port, it is protected
47 * by RCU and you need to hold rcu_read_lock instead when reading.
49 * If multiple locks are taken, the hierarchy is:
54 static DEFINE_MUTEX(vport_mutex);
57 * vport_lock - acquire vport lock
59 * Acquire global vport lock. See above comment about locking requirements
60 * and specific function definitions. May sleep.
65 mutex_lock(&vport_mutex);
69 * vport_unlock - release vport lock
71 * Release lock acquired with vport_lock.
76 mutex_unlock(&vport_mutex);
79 #define ASSERT_VPORT() do { \
80 if (unlikely(!mutex_is_locked(&vport_mutex))) { \
81 printk(KERN_ERR "openvswitch: vport lock not held at %s (%d)\n", \
82 __FILE__, __LINE__); \
88 * vport_init - initialize vport subsystem
90 * Called at module load time to initialize the vport subsystem and any
91 * compiled in vport types.
99 dev_table = kzalloc(VPORT_HASH_BUCKETS * sizeof(struct hlist_head),
106 vport_ops_list = kmalloc(ARRAY_SIZE(base_vport_ops_list) *
107 sizeof(struct vport_ops *), GFP_KERNEL);
108 if (!vport_ops_list) {
110 goto error_dev_table;
113 for (i = 0; i < ARRAY_SIZE(base_vport_ops_list); i++) {
114 struct vport_ops *new_ops = base_vport_ops_list[i];
116 if (new_ops->get_stats && new_ops->flags & VPORT_F_GEN_STATS) {
117 printk(KERN_INFO "openvswitch: both get_stats() and VPORT_F_GEN_STATS defined on vport %s, dropping VPORT_F_GEN_STATS\n", new_ops->type);
118 new_ops->flags &= ~VPORT_F_GEN_STATS;
122 err = new_ops->init();
127 vport_ops_list[n_vport_types++] = new_ops;
128 else if (new_ops->flags & VPORT_F_REQUIRED) {
150 for (i = 0; i < VPORT_HASH_BUCKETS; i++) {
151 struct hlist_head *bucket = &dev_table[i];
153 struct hlist_node *node, *next;
155 hlist_for_each_entry_safe(vport, node, next, bucket, hash_node)
164 * vport_exit - shutdown vport subsystem
166 * Called at module exit time to shutdown the vport subsystem and any
167 * initialized vport types.
176 for (i = 0; i < n_vport_types; i++) {
177 if (vport_ops_list[i]->exit)
178 vport_ops_list[i]->exit();
181 kfree(vport_ops_list);
186 * vport_add - add vport device (for userspace callers)
188 * @uvport_config: New port configuration.
190 * Creates a new vport with the specified configuration (which is dependent
191 * on device type). This function is for userspace callers and assumes no
195 do_vport_add(struct odp_vport_add *vport_config)
200 vport_config->port_type[VPORT_TYPE_SIZE - 1] = '\0';
201 vport_config->devname[IFNAMSIZ - 1] = '\0';
205 vport = vport_locate(vport_config->devname);
212 vport = __vport_add(vport_config->devname, vport_config->port_type,
213 vport_config->config);
217 err = PTR_ERR(vport);
225 vport_add(const struct odp_vport_add __user *uvport_config)
227 struct odp_vport_add vport_config;
229 if (copy_from_user(&vport_config, uvport_config, sizeof(struct odp_vport_add)))
232 return do_vport_add(&vport_config);
237 compat_vport_add(struct compat_odp_vport_add *ucompat)
239 struct compat_odp_vport_add compat;
240 struct odp_vport_add vport_config;
242 if (copy_from_user(&compat, ucompat, sizeof(struct compat_odp_vport_add)))
245 memcpy(vport_config.port_type, compat.port_type, VPORT_TYPE_SIZE);
246 memcpy(vport_config.devname, compat.devname, IFNAMSIZ);
247 vport_config.config = compat_ptr(compat.config);
249 return do_vport_add(&vport_config);
254 * vport_mod - modify existing vport device (for userspace callers)
256 * @uvport_config: New configuration for vport
258 * Modifies an existing device with the specified configuration (which is
259 * dependent on device type). This function is for userspace callers and
260 * assumes no locks are held.
263 do_vport_mod(struct odp_vport_mod *vport_config)
268 vport_config->devname[IFNAMSIZ - 1] = '\0';
272 vport = vport_locate(vport_config->devname);
279 err = __vport_mod(vport, vport_config->config);
288 vport_mod(const struct odp_vport_mod __user *uvport_config)
290 struct odp_vport_mod vport_config;
292 if (copy_from_user(&vport_config, uvport_config, sizeof(struct odp_vport_mod)))
295 return do_vport_mod(&vport_config);
300 compat_vport_mod(struct compat_odp_vport_mod *ucompat)
302 struct compat_odp_vport_mod compat;
303 struct odp_vport_mod vport_config;
305 if (copy_from_user(&compat, ucompat, sizeof(struct compat_odp_vport_mod)))
308 memcpy(vport_config.devname, compat.devname, IFNAMSIZ);
309 vport_config.config = compat_ptr(compat.config);
311 return do_vport_mod(&vport_config);
316 * vport_del - delete existing vport device (for userspace callers)
318 * @udevname: Name of device to delete
320 * Deletes the specified device. Detaches the device from a datapath first
321 * if it is attached. Deleting the device will fail if it does not exist or it
322 * is the datapath local port. It is also possible to fail for less obvious
323 * reasons, such as lack of memory. This function is for userspace callers and
324 * assumes no locks are held.
327 vport_del(const char __user *udevname)
329 char devname[IFNAMSIZ];
331 struct dp_port *dp_port;
335 retval = strncpy_from_user(devname, udevname, IFNAMSIZ);
338 else if (retval >= IFNAMSIZ)
339 return -ENAMETOOLONG;
343 vport = vport_locate(devname);
349 dp_port = vport_get_dp_port(vport);
351 struct datapath *dp = dp_port->dp;
353 mutex_lock(&dp->mutex);
355 if (!strcmp(dp_name(dp), devname)) {
360 err = dp_detach_port(dp_port, 0);
363 mutex_unlock(&dp->mutex);
370 err = __vport_del(vport);
379 * vport_stats_get - retrieve device stats (for userspace callers)
381 * @ustats_req: Stats request parameters.
383 * Retrieves transmit, receive, and error stats for the given device. This
384 * function is for userspace callers and assumes no locks are held.
387 vport_stats_get(struct odp_vport_stats_req __user *ustats_req)
389 struct odp_vport_stats_req stats_req;
393 if (copy_from_user(&stats_req, ustats_req, sizeof(struct odp_vport_stats_req)))
396 stats_req.devname[IFNAMSIZ - 1] = '\0';
400 vport = vport_locate(stats_req.devname);
406 if (vport->ops->get_stats) {
408 err = vport->ops->get_stats(vport, &stats_req.stats);
411 } else if (vport->ops->flags & VPORT_F_GEN_STATS) {
414 memset(&stats_req.stats, 0, sizeof(struct odp_vport_stats));
416 for_each_possible_cpu(i) {
417 const struct vport_percpu_stats *percpu_stats;
419 percpu_stats = per_cpu_ptr(vport->percpu_stats, i);
420 stats_req.stats.rx_bytes += percpu_stats->rx_bytes;
421 stats_req.stats.rx_packets += percpu_stats->rx_packets;
422 stats_req.stats.tx_bytes += percpu_stats->tx_bytes;
423 stats_req.stats.tx_packets += percpu_stats->tx_packets;
426 spin_lock_bh(&vport->err_stats.lock);
428 stats_req.stats.rx_dropped = vport->err_stats.rx_dropped;
429 stats_req.stats.rx_errors = vport->err_stats.rx_errors
430 + vport->err_stats.rx_frame_err
431 + vport->err_stats.rx_over_err
432 + vport->err_stats.rx_crc_err;
433 stats_req.stats.rx_frame_err = vport->err_stats.rx_frame_err;
434 stats_req.stats.rx_over_err = vport->err_stats.rx_over_err;
435 stats_req.stats.rx_crc_err = vport->err_stats.rx_crc_err;
436 stats_req.stats.tx_dropped = vport->err_stats.tx_dropped;
437 stats_req.stats.tx_errors = vport->err_stats.tx_errors;
438 stats_req.stats.collisions = vport->err_stats.collisions;
440 spin_unlock_bh(&vport->err_stats.lock);
450 if (copy_to_user(ustats_req, &stats_req, sizeof(struct odp_vport_stats_req)))
457 * vport_ether_get - retrieve device Ethernet address (for userspace callers)
459 * @uvport_ether: Ethernet address request parameters.
461 * Retrieves the Ethernet address of the given device. This function is for
462 * userspace callers and assumes no locks are held.
465 vport_ether_get(struct odp_vport_ether __user *uvport_ether)
467 struct odp_vport_ether vport_ether;
471 if (copy_from_user(&vport_ether, uvport_ether, sizeof(struct odp_vport_ether)))
474 vport_ether.devname[IFNAMSIZ - 1] = '\0';
478 vport = vport_locate(vport_ether.devname);
485 memcpy(vport_ether.ether_addr, vport_get_addr(vport), ETH_ALEN);
492 if (copy_to_user(uvport_ether, &vport_ether, sizeof(struct odp_vport_ether)))
499 * vport_ether_set - set device Ethernet address (for userspace callers)
501 * @uvport_ether: Ethernet address request parameters.
503 * Sets the Ethernet address of the given device. Some devices may not support
504 * setting the Ethernet address, in which case the result will always be
505 * -EOPNOTSUPP. This function is for userspace callers and assumes no locks
509 vport_ether_set(struct odp_vport_ether __user *uvport_ether)
511 struct odp_vport_ether vport_ether;
515 if (copy_from_user(&vport_ether, uvport_ether, sizeof(struct odp_vport_ether)))
518 vport_ether.devname[IFNAMSIZ - 1] = '\0';
523 vport = vport_locate(vport_ether.devname);
529 err = vport_set_addr(vport, vport_ether.ether_addr);
538 * vport_mut_get - retrieve device MTU (for userspace callers)
540 * @uvport_mtu: MTU request parameters.
542 * Retrieves the MTU of the given device. This function is for userspace
543 * callers and assumes no locks are held.
546 vport_mtu_get(struct odp_vport_mtu __user *uvport_mtu)
548 struct odp_vport_mtu vport_mtu;
552 if (copy_from_user(&vport_mtu, uvport_mtu, sizeof(struct odp_vport_mtu)))
555 vport_mtu.devname[IFNAMSIZ - 1] = '\0';
559 vport = vport_locate(vport_mtu.devname);
565 vport_mtu.mtu = vport_get_mtu(vport);
571 if (copy_to_user(uvport_mtu, &vport_mtu, sizeof(struct odp_vport_mtu)))
578 * vport_mtu_set - set device MTU (for userspace callers)
580 * @uvport_mtu: MTU request parameters.
582 * Sets the MTU of the given device. Some devices may not support setting the
583 * MTU, in which case the result will always be -EOPNOTSUPP. This function is
584 * for userspace callers and assumes no locks are held.
587 vport_mtu_set(struct odp_vport_mtu __user *uvport_mtu)
589 struct odp_vport_mtu vport_mtu;
593 if (copy_from_user(&vport_mtu, uvport_mtu, sizeof(struct odp_vport_mtu)))
596 vport_mtu.devname[IFNAMSIZ - 1] = '\0';
601 vport = vport_locate(vport_mtu.devname);
607 err = vport_set_mtu(vport, vport_mtu.mtu);
615 static struct hlist_head *
616 hash_bucket(const char *name)
618 unsigned int hash = full_name_hash(name, strlen(name));
619 return &dev_table[hash & (VPORT_HASH_BUCKETS - 1)];
623 * vport_locate - find a port that has already been created
625 * @name: name of port to find
627 * Either RTNL or vport lock must be acquired before calling this function
628 * and held while using the found port. See the locking comments at the
632 vport_locate(const char *name)
634 struct hlist_head *bucket = hash_bucket(name);
636 struct hlist_node *node;
638 if (unlikely(!mutex_is_locked(&vport_mutex) && !rtnl_is_locked())) {
639 printk(KERN_ERR "openvswitch: neither RTNL nor vport lock held in vport_locate\n");
645 hlist_for_each_entry(vport, node, bucket, hash_node)
646 if (!strcmp(name, vport_get_name(vport)))
657 register_vport(struct vport *vport)
659 hlist_add_head(&vport->hash_node, hash_bucket(vport_get_name(vport)));
663 unregister_vport(struct vport *vport)
665 hlist_del(&vport->hash_node);
669 * vport_alloc - allocate and initialize new vport
671 * @priv_size: Size of private data area to allocate.
672 * @ops: vport device ops
674 * Allocate and initialize a new vport defined by @ops. The vport will contain
675 * a private data area of size @priv_size that can be accessed using
676 * vport_priv(). vports that are no longer needed should be released with
680 vport_alloc(int priv_size, const struct vport_ops *ops)
685 alloc_size = sizeof(struct vport);
687 alloc_size = ALIGN(alloc_size, VPORT_ALIGN);
688 alloc_size += priv_size;
691 vport = kzalloc(alloc_size, GFP_KERNEL);
693 return ERR_PTR(-ENOMEM);
697 if (vport->ops->flags & VPORT_F_GEN_STATS) {
698 vport->percpu_stats = alloc_percpu(struct vport_percpu_stats);
699 if (!vport->percpu_stats)
700 return ERR_PTR(-ENOMEM);
702 spin_lock_init(&vport->err_stats.lock);
709 * vport_free - uninitialize and free vport
711 * @vport: vport to free
713 * Frees a vport allocated with vport_alloc() when it is no longer needed.
716 vport_free(struct vport *vport)
718 if (vport->ops->flags & VPORT_F_GEN_STATS)
719 free_percpu(vport->percpu_stats);
725 * __vport_add - add vport device (for kernel callers)
727 * @name: Name of new device.
728 * @type: Type of new device (to be matched against types in registered vport
730 * @config: Device type specific configuration. Userspace pointer.
732 * Creates a new vport with the specified configuration (which is dependent
733 * on device type). Both RTNL and vport locks must be held.
736 __vport_add(const char *name, const char *type, const void __user *config)
745 for (i = 0; i < n_vport_types; i++) {
746 if (!strcmp(vport_ops_list[i]->type, type)) {
747 vport = vport_ops_list[i]->create(name, config);
749 err = PTR_ERR(vport);
753 register_vport(vport);
765 * __vport_mod - modify existing vport device (for kernel callers)
767 * @vport: vport to modify.
768 * @config: Device type specific configuration. Userspace pointer.
770 * Modifies an existing device with the specified configuration (which is
771 * dependent on device type). Both RTNL and vport locks must be held.
774 __vport_mod(struct vport *vport, const void __user *config)
779 if (vport->ops->modify)
780 return vport->ops->modify(vport, config);
786 * __vport_del - delete existing vport device (for kernel callers)
788 * @vport: vport to delete.
790 * Deletes the specified device. The device must not be currently attached to
791 * a datapath. It is possible to fail for reasons such as lack of memory.
792 * Both RTNL and vport locks must be held.
795 __vport_del(struct vport *vport)
799 BUG_ON(vport_get_dp_port(vport));
801 unregister_vport(vport);
803 return vport->ops->destroy(vport);
807 * vport_attach - attach a vport to a datapath
809 * @vport: vport to attach.
810 * @dp_port: Datapath port to attach the vport to.
812 * Attaches a vport to a specific datapath so that packets may be exchanged.
813 * Both ports must be currently unattached. @dp_port must be successfully
814 * attached to a vport before it is connected to a datapath and must not be
815 * modified while connected. RTNL lock and the appropriate DP mutex must be held.
818 vport_attach(struct vport *vport, struct dp_port *dp_port)
825 if (vport_get_dp_port(vport))
828 if (vport->ops->attach) {
831 err = vport->ops->attach(vport);
836 dp_port->vport = vport;
837 rcu_assign_pointer(vport->dp_port, dp_port);
843 * vport_detach - detach a vport from a datapath
845 * @vport: vport to detach.
847 * Detaches a vport from a datapath. May fail for a variety of reasons,
848 * including lack of memory. RTNL lock and the appropriate DP mutex must be held.
851 vport_detach(struct vport *vport)
853 struct dp_port *dp_port;
857 dp_port = vport_get_dp_port(vport);
861 dp_port->vport = NULL;
862 rcu_assign_pointer(vport->dp_port, NULL);
864 if (vport->ops->detach)
865 return vport->ops->detach(vport);
871 * vport_set_mtu - set device MTU (for kernel callers)
873 * @vport: vport on which to set MTU.
876 * Sets the MTU of the given device. Some devices may not support setting the
877 * MTU, in which case the result will always be -EOPNOTSUPP. RTNL lock must
881 vport_set_mtu(struct vport *vport, int mtu)
888 if (vport->ops->set_mtu) {
891 ret = vport->ops->set_mtu(vport, mtu);
893 if (!ret && !is_internal_vport(vport)) {
894 struct dp_port *dp_port = vport_get_dp_port(vport);
897 set_internal_devs_mtu(dp_port->dp);
906 * vport_set_addr - set device Ethernet address (for kernel callers)
908 * @vport: vport on which to set Ethernet address.
909 * @addr: New address.
911 * Sets the Ethernet address of the given device. Some devices may not support
912 * setting the Ethernet address, in which case the result will always be
913 * -EOPNOTSUPP. RTNL lock must be held.
916 vport_set_addr(struct vport *vport, const unsigned char *addr)
920 if (!is_valid_ether_addr(addr))
921 return -EADDRNOTAVAIL;
923 if (vport->ops->set_addr)
924 return vport->ops->set_addr(vport, addr);
930 * vport_get_name - retrieve device name
932 * @vport: vport from which to retrieve the name.
934 * Retrieves the name of the given device. Either RTNL lock or rcu_read_lock
935 * must be held for the entire duration that the name is in use.
938 vport_get_name(const struct vport *vport)
940 return vport->ops->get_name(vport);
944 * vport_get_type - retrieve device type
946 * @vport: vport from which to retrieve the type.
948 * Retrieves the type of the given device. Either RTNL lock or rcu_read_lock
949 * must be held for the entire duration that the type is in use.
952 vport_get_type(const struct vport *vport)
954 return vport->ops->type;
958 * vport_get_addr - retrieve device Ethernet address (for kernel callers)
960 * @vport: vport from which to retrieve the Ethernet address.
962 * Retrieves the Ethernet address of the given device. Either RTNL lock or
963 * rcu_read_lock must be held for the entire duration that the Ethernet address
966 const unsigned char *
967 vport_get_addr(const struct vport *vport)
969 return vport->ops->get_addr(vport);
973 * vport_get_dp_port - retrieve attached datapath port
975 * @vport: vport from which to retrieve the datapath port.
977 * Retrieves the attached datapath port or null if not attached. Either RTNL
978 * lock or rcu_read_lock must be held for the entire duration that the datapath
979 * port is being accessed.
982 vport_get_dp_port(const struct vport *vport)
984 return rcu_dereference(vport->dp_port);
988 * vport_get_kobj - retrieve associated kobj
990 * @vport: vport from which to retrieve the associated kobj
992 * Retrieves the associated kobj or null if no kobj. The returned kobj is
993 * valid for as long as the vport exists.
996 vport_get_kobj(const struct vport *vport)
998 if (vport->ops->get_kobj)
999 return vport->ops->get_kobj(vport);
1005 * vport_get_flags - retrieve device flags
1007 * @vport: vport from which to retrieve the flags
1009 * Retrieves the flags of the given device. Either RTNL lock or rcu_read_lock
1013 vport_get_flags(const struct vport *vport)
1015 return vport->ops->get_dev_flags(vport);
1019 * vport_get_flags - check whether device is running
1021 * @vport: vport on which to check status.
1023 * Checks whether the given device is running. Either RTNL lock or
1024 * rcu_read_lock must be held.
1027 vport_is_running(const struct vport *vport)
1029 return vport->ops->is_running(vport);
1033 * vport_get_flags - retrieve device operating state
1035 * @vport: vport from which to check status
1037 * Retrieves the RFC2863 operstate of the given device. Either RTNL lock or
1038 * rcu_read_lock must be held.
1041 vport_get_operstate(const struct vport *vport)
1043 return vport->ops->get_operstate(vport);
1047 * vport_get_ifindex - retrieve device system interface index
1049 * @vport: vport from which to retrieve index
1051 * Retrieves the system interface index of the given device. Not all devices
1052 * will have system indexes, in which case the index of the datapath local
1053 * port is returned. Returns a negative index on error. Either RTNL lock or
1054 * rcu_read_lock must be held.
1057 vport_get_ifindex(const struct vport *vport)
1059 const struct dp_port *dp_port;
1061 if (vport->ops->get_ifindex)
1062 return vport->ops->get_ifindex(vport);
1064 /* If we don't actually have an ifindex, use the local port's.
1065 * Userspace doesn't check it anyways. */
1066 dp_port = vport_get_dp_port(vport);
1070 return vport_get_ifindex(dp_port->dp->ports[ODPP_LOCAL]->vport);
1074 * vport_get_iflink - retrieve device system link index
1076 * @vport: vport from which to retrieve index
1078 * Retrieves the system link index of the given device. The link is the index
1079 * of the interface on which the packet will actually be sent. In most cases
1080 * this is the same as the ifindex but may be different for tunnel devices.
1081 * Returns a negative index on error. Either RTNL lock or rcu_read_lock must
1085 vport_get_iflink(const struct vport *vport)
1087 if (vport->ops->get_iflink)
1088 return vport->ops->get_iflink(vport);
1090 /* If we don't have an iflink, use the ifindex. In most cases they
1092 return vport_get_ifindex(vport);
1096 * vport_get_mtu - retrieve device MTU (for kernel callers)
1098 * @vport: vport from which to retrieve MTU
1100 * Retrieves the MTU of the given device. Either RTNL lock or rcu_read_lock
1104 vport_get_mtu(const struct vport *vport)
1106 return vport->ops->get_mtu(vport);
1110 * vport_receive - pass up received packet to the datapath for processing
1112 * @vport: vport that received the packet
1113 * @skb: skb that was received
1115 * Must be called with rcu_read_lock. The packet cannot be shared and
1116 * skb->data should point to the Ethernet header. The caller must have already
1117 * called compute_ip_summed() to initialize the checksumming fields.
1120 vport_receive(struct vport *vport, struct sk_buff *skb)
1122 struct dp_port *dp_port = vport_get_dp_port(vport);
1125 vport_record_error(vport, VPORT_E_RX_DROPPED);
1131 if (vport->ops->flags & VPORT_F_GEN_STATS) {
1132 struct vport_percpu_stats *stats;
1136 stats = per_cpu_ptr(vport->percpu_stats, smp_processor_id());
1137 stats->rx_packets++;
1138 stats->rx_bytes += skb->len;
1143 if (!(vport->ops->flags & VPORT_F_TUN_ID))
1144 OVS_CB(skb)->tun_id = 0;
1146 dp_process_received_packet(dp_port, skb);
1150 * vport_send - send a packet on a device
1152 * @vport: vport on which to send the packet
1155 * Sends the given packet and returns the length of data sent. Either RTNL
1156 * lock or rcu_read_lock must be held.
1159 vport_send(struct vport *vport, struct sk_buff *skb)
1163 sent = vport->ops->send(vport, skb);
1165 if (vport->ops->flags & VPORT_F_GEN_STATS && sent > 0) {
1166 struct vport_percpu_stats *stats;
1170 stats = per_cpu_ptr(vport->percpu_stats, smp_processor_id());
1171 stats->tx_packets++;
1172 stats->tx_bytes += sent;
1181 * vport_record_error - indicate device error to generic stats layer
1183 * @vport: vport that encountered the error
1184 * @err_type: one of enum vport_err_type types to indicate the error type
1186 * If using the vport generic stats layer indicate that an error of the given
1190 vport_record_error(struct vport *vport, enum vport_err_type err_type)
1192 if (vport->ops->flags & VPORT_F_GEN_STATS) {
1194 spin_lock_bh(&vport->err_stats.lock);
1197 case VPORT_E_RX_DROPPED:
1198 vport->err_stats.rx_dropped++;
1201 case VPORT_E_RX_ERROR:
1202 vport->err_stats.rx_errors++;
1205 case VPORT_E_RX_FRAME:
1206 vport->err_stats.rx_frame_err++;
1209 case VPORT_E_RX_OVER:
1210 vport->err_stats.rx_over_err++;
1213 case VPORT_E_RX_CRC:
1214 vport->err_stats.rx_crc_err++;
1217 case VPORT_E_TX_DROPPED:
1218 vport->err_stats.tx_dropped++;
1221 case VPORT_E_TX_ERROR:
1222 vport->err_stats.tx_errors++;
1225 case VPORT_E_COLLISION:
1226 vport->err_stats.collisions++;
1230 spin_unlock_bh(&vport->err_stats.lock);