-static int
-do_vport_add(struct odp_vport_add *vport_config)
-{
- struct vport *vport;
- int err = 0;
-
- vport_config->port_type[VPORT_TYPE_SIZE - 1] = '\0';
- vport_config->devname[IFNAMSIZ - 1] = '\0';
-
- rtnl_lock();
-
- vport = vport_locate(vport_config->devname);
- if (vport) {
- err = -EEXIST;
- goto out;
- }
-
- vport_lock();
- vport = vport_add(vport_config->devname, vport_config->port_type,
- vport_config->config);
- vport_unlock();
-
- if (IS_ERR(vport))
- err = PTR_ERR(vport);
-
-out:
- rtnl_unlock();
- return err;
-}
-
-/**
- * vport_user_add - add vport device (for userspace callers)
- *
- * @uvport_config: New port configuration.
- *
- * Creates a new vport with the specified configuration (which is dependent
- * on device type). This function is for userspace callers and assumes no
- * locks are held.
- */
-int
-vport_user_add(const struct odp_vport_add __user *uvport_config)
-{
- struct odp_vport_add vport_config;
-
- if (copy_from_user(&vport_config, uvport_config, sizeof(struct odp_vport_add)))
- return -EFAULT;
-
- return do_vport_add(&vport_config);
-}
-
-#ifdef CONFIG_COMPAT
-int
-compat_vport_user_add(struct compat_odp_vport_add *ucompat)
-{
- struct compat_odp_vport_add compat;
- struct odp_vport_add vport_config;
-
- if (copy_from_user(&compat, ucompat, sizeof(struct compat_odp_vport_add)))
- return -EFAULT;
-
- memcpy(vport_config.port_type, compat.port_type, VPORT_TYPE_SIZE);
- memcpy(vport_config.devname, compat.devname, IFNAMSIZ);
- vport_config.config = compat_ptr(compat.config);
-
- return do_vport_add(&vport_config);
-}
-#endif
-
-static int
-do_vport_mod(struct odp_vport_mod *vport_config)
-{
- struct vport *vport;
- int err;
-
- vport_config->devname[IFNAMSIZ - 1] = '\0';
-
- rtnl_lock();
-
- vport = vport_locate(vport_config->devname);
- if (!vport) {
- err = -ENODEV;
- goto out;
- }
-
- vport_lock();
- err = vport_mod(vport, vport_config->config);
- vport_unlock();
-
-out:
- rtnl_unlock();
- return err;
-}
-
-/**
- * vport_user_mod - modify existing vport device (for userspace callers)
- *
- * @uvport_config: New configuration for vport
- *
- * Modifies an existing device with the specified configuration (which is
- * dependent on device type). This function is for userspace callers and
- * assumes no locks are held.
- */
-int
-vport_user_mod(const struct odp_vport_mod __user *uvport_config)
-{
- struct odp_vport_mod vport_config;
-
- if (copy_from_user(&vport_config, uvport_config, sizeof(struct odp_vport_mod)))
- return -EFAULT;
-
- return do_vport_mod(&vport_config);
-}
-
-#ifdef CONFIG_COMPAT
-int
-compat_vport_user_mod(struct compat_odp_vport_mod *ucompat)
-{
- struct compat_odp_vport_mod compat;
- struct odp_vport_mod vport_config;
-
- if (copy_from_user(&compat, ucompat, sizeof(struct compat_odp_vport_mod)))
- return -EFAULT;
-
- memcpy(vport_config.devname, compat.devname, IFNAMSIZ);
- vport_config.config = compat_ptr(compat.config);
-
- return do_vport_mod(&vport_config);
-}
-#endif
-
-/**
- * vport_user_del - delete existing vport device (for userspace callers)
- *
- * @udevname: Name of device to delete
- *
- * Deletes the specified device. Detaches the device from a datapath first
- * if it is attached. Deleting the device will fail if it does not exist or it
- * is the datapath local port. It is also possible to fail for less obvious
- * reasons, such as lack of memory. This function is for userspace callers and
- * assumes no locks are held.
- */
-int
-vport_user_del(const char __user *udevname)
-{
- char devname[IFNAMSIZ];
- struct vport *vport;
- struct dp_port *dp_port;
- int err = 0;
- int retval;
-
- retval = strncpy_from_user(devname, udevname, IFNAMSIZ);
- if (retval < 0)
- return -EFAULT;
- else if (retval >= IFNAMSIZ)
- return -ENAMETOOLONG;
-
- rtnl_lock();
-
- vport = vport_locate(devname);
- if (!vport) {
- err = -ENODEV;
- goto out;
- }
-
- dp_port = vport_get_dp_port(vport);
- if (dp_port) {
- struct datapath *dp = dp_port->dp;
-
- mutex_lock(&dp->mutex);
-
- if (!strcmp(dp_name(dp), devname)) {
- err = -EINVAL;
- goto dp_port_out;
- }
-
- err = dp_detach_port(dp_port, 0);
-
-dp_port_out:
- mutex_unlock(&dp->mutex);
-
- if (err)
- goto out;
- }
-
- vport_lock();
- err = vport_del(vport);
- vport_unlock();
-
-out:
- rtnl_unlock();
- return err;
-}
-
-/**
- * vport_user_stats_get - retrieve device stats (for userspace callers)
- *
- * @ustats_req: Stats request parameters.
- *
- * Retrieves transmit, receive, and error stats for the given device. This
- * function is for userspace callers and assumes no locks are held.
- */
-int
-vport_user_stats_get(struct odp_vport_stats_req __user *ustats_req)
-{
- struct odp_vport_stats_req stats_req;
- struct vport *vport;
- int err;
-
- if (copy_from_user(&stats_req, ustats_req, sizeof(struct odp_vport_stats_req)))
- return -EFAULT;
-
- stats_req.devname[IFNAMSIZ - 1] = '\0';
-
- vport_lock();
-
- vport = vport_locate(stats_req.devname);
- if (!vport) {
- err = -ENODEV;
- goto out;
- }
-
- err = vport_get_stats(vport, &stats_req.stats);
-
-out:
- vport_unlock();
-
- if (!err)
- if (copy_to_user(ustats_req, &stats_req, sizeof(struct odp_vport_stats_req)))
- err = -EFAULT;
-
- return err;
-}
-
-/**
- * vport_user_stats_set - sets offset device stats (for userspace callers)
- *
- * @ustats_req: Stats set parameters.
- *
- * Provides a set of transmit, receive, and error stats to be added as an
- * offset to the collect data when stats are retreived. Some devices may not
- * support setting the stats, in which case the result will always be
- * -EOPNOTSUPP. This function is for userspace callers and assumes no locks
- * are held.
- */
-int
-vport_user_stats_set(struct odp_vport_stats_req __user *ustats_req)
-{
- struct odp_vport_stats_req stats_req;
- struct vport *vport;
- int err;
-
- if (copy_from_user(&stats_req, ustats_req, sizeof(struct odp_vport_stats_req)))
- return -EFAULT;
-
- stats_req.devname[IFNAMSIZ - 1] = '\0';
-
- rtnl_lock();
- vport_lock();
-
- vport = vport_locate(stats_req.devname);
- if (!vport) {
- err = -ENODEV;
- goto out;
- }
-
- err = vport_set_stats(vport, &stats_req.stats);
-
-out:
- vport_unlock();
- rtnl_unlock();
- return err;
-}
-
-
-/**
- * vport_user_ether_get - retrieve device Ethernet address (for userspace callers)
- *
- * @uvport_ether: Ethernet address request parameters.
- *
- * Retrieves the Ethernet address of the given device. This function is for
- * userspace callers and assumes no locks are held.
- */
-int
-vport_user_ether_get(struct odp_vport_ether __user *uvport_ether)
-{
- struct odp_vport_ether vport_ether;
- struct vport *vport;
- int err = 0;
-
- if (copy_from_user(&vport_ether, uvport_ether, sizeof(struct odp_vport_ether)))
- return -EFAULT;
-
- vport_ether.devname[IFNAMSIZ - 1] = '\0';
-
- vport_lock();
-
- vport = vport_locate(vport_ether.devname);
- if (!vport) {
- err = -ENODEV;
- goto out;
- }
-
- rcu_read_lock();
- memcpy(vport_ether.ether_addr, vport_get_addr(vport), ETH_ALEN);
- rcu_read_unlock();
-
-out:
- vport_unlock();
-
- if (!err)
- if (copy_to_user(uvport_ether, &vport_ether, sizeof(struct odp_vport_ether)))
- err = -EFAULT;
-
- return err;
-}
-
-/**
- * vport_user_ether_set - set device Ethernet address (for userspace callers)
- *
- * @uvport_ether: Ethernet address request parameters.
- *
- * Sets the Ethernet address of the given device. Some devices may not support
- * setting the Ethernet address, in which case the result will always be
- * -EOPNOTSUPP. This function is for userspace callers and assumes no locks
- * are held.
- */
-int
-vport_user_ether_set(struct odp_vport_ether __user *uvport_ether)
-{
- struct odp_vport_ether vport_ether;
- struct vport *vport;
- int err;
-
- if (copy_from_user(&vport_ether, uvport_ether, sizeof(struct odp_vport_ether)))
- return -EFAULT;
-
- vport_ether.devname[IFNAMSIZ - 1] = '\0';
-
- rtnl_lock();
- vport_lock();
-
- vport = vport_locate(vport_ether.devname);
- if (!vport) {
- err = -ENODEV;
- goto out;
- }
-
- err = vport_set_addr(vport, vport_ether.ether_addr);
-
-out:
- vport_unlock();
- rtnl_unlock();
- return err;
-}
-
-/**
- * vport_user_mtu_get - retrieve device MTU (for userspace callers)
- *
- * @uvport_mtu: MTU request parameters.
- *
- * Retrieves the MTU of the given device. This function is for userspace
- * callers and assumes no locks are held.
- */
-int
-vport_user_mtu_get(struct odp_vport_mtu __user *uvport_mtu)
-{
- struct odp_vport_mtu vport_mtu;
- struct vport *vport;
- int err = 0;
-
- if (copy_from_user(&vport_mtu, uvport_mtu, sizeof(struct odp_vport_mtu)))
- return -EFAULT;
-
- vport_mtu.devname[IFNAMSIZ - 1] = '\0';
-
- vport_lock();
-
- vport = vport_locate(vport_mtu.devname);
- if (!vport) {
- err = -ENODEV;
- goto out;
- }
-
- vport_mtu.mtu = vport_get_mtu(vport);
-
-out:
- vport_unlock();
-
- if (!err)
- if (copy_to_user(uvport_mtu, &vport_mtu, sizeof(struct odp_vport_mtu)))
- err = -EFAULT;
-
- return err;
-}
-
-/**
- * vport_user_mtu_set - set device MTU (for userspace callers)
- *
- * @uvport_mtu: MTU request parameters.
- *
- * Sets the MTU of the given device. Some devices may not support setting the
- * MTU, in which case the result will always be -EOPNOTSUPP. This function is
- * for userspace callers and assumes no locks are held.
- */
-int
-vport_user_mtu_set(struct odp_vport_mtu __user *uvport_mtu)
-{
- struct odp_vport_mtu vport_mtu;
- struct vport *vport;
- int err;
-
- if (copy_from_user(&vport_mtu, uvport_mtu, sizeof(struct odp_vport_mtu)))
- return -EFAULT;
-
- vport_mtu.devname[IFNAMSIZ - 1] = '\0';
-
- rtnl_lock();
- vport_lock();
-
- vport = vport_locate(vport_mtu.devname);
- if (!vport) {
- err = -ENODEV;
- goto out;
- }
-
- err = vport_set_mtu(vport, vport_mtu.mtu);
-
-out:
- vport_unlock();
- rtnl_unlock();
- return err;
-}
-
-static struct hlist_head *
-hash_bucket(const char *name)