Lines Matching +full:static +full:- +full:config
1 // SPDX-License-Identifier: GPL-2.0-only
19 static LIST_HEAD(mdev_head);
21 static DECLARE_RWSEM(vdpa_dev_lock);
22 static DEFINE_IDA(vdpa_index_ida);
26 down_write(&vdev->cf_lock); in vdpa_set_status()
27 vdev->config->set_status(vdev, status); in vdpa_set_status()
28 up_write(&vdev->cf_lock); in vdpa_set_status()
32 static struct genl_family vdpa_nl_family;
34 static int vdpa_dev_probe(struct device *d) in vdpa_dev_probe()
37 struct vdpa_driver *drv = drv_to_vdpa(vdev->dev.driver); in vdpa_dev_probe()
38 const struct vdpa_config_ops *ops = vdev->config; in vdpa_dev_probe()
42 d->dma_mask = &d->coherent_dma_mask; in vdpa_dev_probe()
47 max_num = ops->get_vq_num_max(vdev); in vdpa_dev_probe()
48 if (ops->get_vq_num_min) in vdpa_dev_probe()
49 min_num = ops->get_vq_num_min(vdev); in vdpa_dev_probe()
51 return -EINVAL; in vdpa_dev_probe()
53 if (drv && drv->probe) in vdpa_dev_probe()
54 ret = drv->probe(vdev); in vdpa_dev_probe()
59 static void vdpa_dev_remove(struct device *d) in vdpa_dev_remove()
62 struct vdpa_driver *drv = drv_to_vdpa(vdev->dev.driver); in vdpa_dev_remove()
64 if (drv && drv->remove) in vdpa_dev_remove()
65 drv->remove(vdev); in vdpa_dev_remove()
68 static int vdpa_dev_match(struct device *dev, const struct device_driver *drv) in vdpa_dev_match()
73 if (vdev->driver_override) in vdpa_dev_match()
74 return strcmp(vdev->driver_override, drv->name) == 0; in vdpa_dev_match()
80 static ssize_t driver_override_store(struct device *dev, in driver_override_store()
87 ret = driver_set_override(dev, &vdev->driver_override, buf, count); in driver_override_store()
94 static ssize_t driver_override_show(struct device *dev, in driver_override_show()
101 len = sysfs_emit(buf, "%s\n", vdev->driver_override); in driver_override_show()
106 static DEVICE_ATTR_RW(driver_override);
108 static struct attribute *vdpa_dev_attrs[] = {
113 static const struct attribute_group vdpa_dev_group = {
118 static const struct bus_type vdpa_bus = {
126 static void vdpa_release_dev(struct device *d) in vdpa_release_dev()
129 const struct vdpa_config_ops *ops = vdev->config; in vdpa_release_dev()
131 if (ops->free) in vdpa_release_dev()
132 ops->free(vdev); in vdpa_release_dev()
134 ida_free(&vdpa_index_ida, vdev->index); in vdpa_release_dev()
135 kfree(vdev->driver_override); in vdpa_release_dev()
140 * __vdpa_alloc_device - allocate and initilaize a vDPA device
144 * @config: the bus operations that is supported by this device
154 * Return: Returns an error when parent/config/dma_dev is not set or fail to get
158 const struct vdpa_config_ops *config, in __vdpa_alloc_device() argument
164 int err = -EINVAL; in __vdpa_alloc_device()
166 if (!config) in __vdpa_alloc_device()
169 if (!!config->dma_map != !!config->dma_unmap) in __vdpa_alloc_device()
172 /* It should only work for the device that use on-chip IOMMU */ in __vdpa_alloc_device()
173 if (use_va && !(config->dma_map || config->set_map)) in __vdpa_alloc_device()
176 err = -ENOMEM; in __vdpa_alloc_device()
185 vdev->dev.bus = &vdpa_bus; in __vdpa_alloc_device()
186 vdev->dev.parent = parent; in __vdpa_alloc_device()
187 vdev->dev.release = vdpa_release_dev; in __vdpa_alloc_device()
188 vdev->index = err; in __vdpa_alloc_device()
189 vdev->config = config; in __vdpa_alloc_device()
190 vdev->features_valid = false; in __vdpa_alloc_device()
191 vdev->use_va = use_va; in __vdpa_alloc_device()
192 vdev->ngroups = ngroups; in __vdpa_alloc_device()
193 vdev->nas = nas; in __vdpa_alloc_device()
196 err = dev_set_name(&vdev->dev, "%s", name); in __vdpa_alloc_device()
198 err = dev_set_name(&vdev->dev, "vdpa%u", vdev->index); in __vdpa_alloc_device()
202 init_rwsem(&vdev->cf_lock); in __vdpa_alloc_device()
203 device_initialize(&vdev->dev); in __vdpa_alloc_device()
208 ida_free(&vdpa_index_ida, vdev->index); in __vdpa_alloc_device()
216 static int vdpa_name_match(struct device *dev, const void *data) in vdpa_name_match()
220 return (strcmp(dev_name(&vdev->dev), data) == 0); in vdpa_name_match()
223 static int __vdpa_register_device(struct vdpa_device *vdev, u32 nvqs) in __vdpa_register_device()
227 vdev->nvqs = nvqs; in __vdpa_register_device()
230 dev = bus_find_device(&vdpa_bus, NULL, dev_name(&vdev->dev), vdpa_name_match); in __vdpa_register_device()
233 return -EEXIST; in __vdpa_register_device()
235 return device_add(&vdev->dev); in __vdpa_register_device()
239 * _vdpa_register_device - register a vDPA device with vdpa lock held
250 if (!vdev->mdev) in _vdpa_register_device()
251 return -EINVAL; in _vdpa_register_device()
258 * vdpa_register_device - register a vDPA device
277 * _vdpa_unregister_device - unregister a vDPA device
285 WARN_ON(!vdev->mdev); in _vdpa_unregister_device()
286 device_unregister(&vdev->dev); in _vdpa_unregister_device()
291 * vdpa_unregister_device - unregister a vDPA device
297 device_unregister(&vdev->dev); in vdpa_unregister_device()
303 * __vdpa_register_driver - register a vDPA device driver
311 drv->driver.bus = &vdpa_bus; in __vdpa_register_driver()
312 drv->driver.owner = owner; in __vdpa_register_driver()
314 return driver_register(&drv->driver); in __vdpa_register_driver()
319 * vdpa_unregister_driver - unregister a vDPA device driver
324 driver_unregister(&drv->driver); in vdpa_unregister_driver()
329 * vdpa_mgmtdev_register - register a vdpa management device
339 if (!mdev->device || !mdev->ops || !mdev->ops->dev_add || !mdev->ops->dev_del) in vdpa_mgmtdev_register()
340 return -EINVAL; in vdpa_mgmtdev_register()
342 INIT_LIST_HEAD(&mdev->list); in vdpa_mgmtdev_register()
344 list_add_tail(&mdev->list, &mdev_head); in vdpa_mgmtdev_register()
350 static int vdpa_match_remove(struct device *dev, void *data) in vdpa_match_remove()
353 struct vdpa_mgmt_dev *mdev = vdev->mdev; in vdpa_match_remove()
356 mdev->ops->dev_del(mdev, vdev); in vdpa_match_remove()
364 list_del(&mdev->list); in vdpa_mgmtdev_unregister()
373 static void vdpa_get_config_unlocked(struct vdpa_device *vdev, in vdpa_get_config_unlocked()
377 const struct vdpa_config_ops *ops = vdev->config; in vdpa_get_config_unlocked()
380 * Config accesses aren't supposed to trigger before features are set. in vdpa_get_config_unlocked()
383 if (!vdev->features_valid) in vdpa_get_config_unlocked()
385 ops->get_config(vdev, offset, buf, len); in vdpa_get_config_unlocked()
389 * vdpa_get_config - Get one or more device configuration fields.
398 down_read(&vdev->cf_lock); in vdpa_get_config()
400 up_read(&vdev->cf_lock); in vdpa_get_config()
405 * vdpa_set_config - Set one or more device configuration fields.
414 down_write(&vdev->cf_lock); in vdpa_set_config()
415 vdev->config->set_config(vdev, offset, buf, length); in vdpa_set_config()
416 up_write(&vdev->cf_lock); in vdpa_set_config()
420 static bool mgmtdev_handle_match(const struct vdpa_mgmt_dev *mdev, in mgmtdev_handle_match()
426 if ((busname && !mdev->device->bus) || (!busname && mdev->device->bus)) in mgmtdev_handle_match()
429 if (!busname && strcmp(dev_name(mdev->device), devname) == 0) in mgmtdev_handle_match()
432 if (busname && (strcmp(mdev->device->bus->name, busname) == 0) && in mgmtdev_handle_match()
433 (strcmp(dev_name(mdev->device), devname) == 0)) in mgmtdev_handle_match()
439 static struct vdpa_mgmt_dev *vdpa_mgmtdev_get_from_attr(struct nlattr **attrs) in vdpa_mgmtdev_get_from_attr()
446 return ERR_PTR(-EINVAL); in vdpa_mgmtdev_get_from_attr()
455 return ERR_PTR(-ENODEV); in vdpa_mgmtdev_get_from_attr()
458 static int vdpa_nl_mgmtdev_handle_fill(struct sk_buff *msg, const struct vdpa_mgmt_dev *mdev) in vdpa_nl_mgmtdev_handle_fill()
460 if (mdev->device->bus && in vdpa_nl_mgmtdev_handle_fill()
461 nla_put_string(msg, VDPA_ATTR_MGMTDEV_BUS_NAME, mdev->device->bus->name)) in vdpa_nl_mgmtdev_handle_fill()
462 return -EMSGSIZE; in vdpa_nl_mgmtdev_handle_fill()
463 if (nla_put_string(msg, VDPA_ATTR_MGMTDEV_DEV_NAME, dev_name(mdev->device))) in vdpa_nl_mgmtdev_handle_fill()
464 return -EMSGSIZE; in vdpa_nl_mgmtdev_handle_fill()
468 static u64 vdpa_mgmtdev_get_classes(const struct vdpa_mgmt_dev *mdev, in vdpa_mgmtdev_get_classes()
474 for (int i = 0; mdev->id_table[i].device; i++) { in vdpa_mgmtdev_get_classes()
475 if (mdev->id_table[i].device > 63) in vdpa_mgmtdev_get_classes()
477 supported_classes |= BIT_ULL(mdev->id_table[i].device); in vdpa_mgmtdev_get_classes()
486 static int vdpa_mgmtdev_fill(const struct vdpa_mgmt_dev *mdev, struct sk_buff *msg, in vdpa_mgmtdev_fill()
494 return -EMSGSIZE; in vdpa_mgmtdev_fill()
502 err = -EMSGSIZE; in vdpa_mgmtdev_fill()
506 mdev->max_supported_vqs)) { in vdpa_mgmtdev_fill()
507 err = -EMSGSIZE; in vdpa_mgmtdev_fill()
511 mdev->supported_features, VDPA_ATTR_PAD)) { in vdpa_mgmtdev_fill()
512 err = -EMSGSIZE; in vdpa_mgmtdev_fill()
524 static int vdpa_nl_cmd_mgmtdev_get_doit(struct sk_buff *skb, struct genl_info *info) in vdpa_nl_cmd_mgmtdev_get_doit()
532 return -ENOMEM; in vdpa_nl_cmd_mgmtdev_get_doit()
535 mdev = vdpa_mgmtdev_get_from_attr(info->attrs); in vdpa_nl_cmd_mgmtdev_get_doit()
538 NL_SET_ERR_MSG_MOD(info->extack, "Fail to find the specified mgmt device"); in vdpa_nl_cmd_mgmtdev_get_doit()
543 err = vdpa_mgmtdev_fill(mdev, msg, info->snd_portid, info->snd_seq, 0); in vdpa_nl_cmd_mgmtdev_get_doit()
555 static int
559 int start = cb->args[0]; in vdpa_nl_cmd_mgmtdev_get_dumpit()
569 err = vdpa_mgmtdev_fill(mdev, msg, NETLINK_CB(cb->skb).portid, in vdpa_nl_cmd_mgmtdev_get_dumpit()
570 cb->nlh->nlmsg_seq, NLM_F_MULTI); in vdpa_nl_cmd_mgmtdev_get_dumpit()
577 cb->args[0] = idx; in vdpa_nl_cmd_mgmtdev_get_dumpit()
578 return msg->len; in vdpa_nl_cmd_mgmtdev_get_dumpit()
586 * Bitmask for all per-device features: feature bits VIRTIO_TRANSPORT_F_START
589 * "holes" are reserved for other type of features than per-device, this
593 ((1ULL << VIRTIO_TRANSPORT_F_START) - 1))
595 static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *info) in vdpa_nl_cmd_dev_add_set_doit()
597 struct vdpa_dev_set_config config = {}; in vdpa_nl_cmd_dev_add_set_doit() local
598 struct nlattr **nl_attrs = info->attrs; in vdpa_nl_cmd_dev_add_set_doit()
606 if (!info->attrs[VDPA_ATTR_DEV_NAME]) in vdpa_nl_cmd_dev_add_set_doit()
607 return -EINVAL; in vdpa_nl_cmd_dev_add_set_doit()
609 name = nla_data(info->attrs[VDPA_ATTR_DEV_NAME]); in vdpa_nl_cmd_dev_add_set_doit()
613 memcpy(config.net.mac, macaddr, sizeof(config.net.mac)); in vdpa_nl_cmd_dev_add_set_doit()
614 config.mask |= BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MACADDR); in vdpa_nl_cmd_dev_add_set_doit()
617 config.net.mtu = in vdpa_nl_cmd_dev_add_set_doit()
619 config.mask |= BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU); in vdpa_nl_cmd_dev_add_set_doit()
622 config.net.max_vq_pairs = in vdpa_nl_cmd_dev_add_set_doit()
624 if (!config.net.max_vq_pairs) { in vdpa_nl_cmd_dev_add_set_doit()
625 NL_SET_ERR_MSG_MOD(info->extack, in vdpa_nl_cmd_dev_add_set_doit()
627 return -EINVAL; in vdpa_nl_cmd_dev_add_set_doit()
629 config.mask |= BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP); in vdpa_nl_cmd_dev_add_set_doit()
634 config.device_features = in vdpa_nl_cmd_dev_add_set_doit()
637 !(config.device_features & BIT_ULL(VIRTIO_NET_F_MAC))) in vdpa_nl_cmd_dev_add_set_doit()
640 !(config.device_features & BIT_ULL(VIRTIO_NET_F_MTU))) in vdpa_nl_cmd_dev_add_set_doit()
643 config.net.max_vq_pairs > 1 && in vdpa_nl_cmd_dev_add_set_doit()
644 !(config.device_features & BIT_ULL(VIRTIO_NET_F_MQ))) in vdpa_nl_cmd_dev_add_set_doit()
647 NL_SET_ERR_MSG_FMT_MOD(info->extack, in vdpa_nl_cmd_dev_add_set_doit()
650 return -EINVAL; in vdpa_nl_cmd_dev_add_set_doit()
652 config.mask |= BIT_ULL(VDPA_ATTR_DEV_FEATURES); in vdpa_nl_cmd_dev_add_set_doit()
660 if ((config.mask & VDPA_DEV_NET_ATTRS_MASK) && in vdpa_nl_cmd_dev_add_set_doit()
662 return -EPERM; in vdpa_nl_cmd_dev_add_set_doit()
665 mdev = vdpa_mgmtdev_get_from_attr(info->attrs); in vdpa_nl_cmd_dev_add_set_doit()
667 NL_SET_ERR_MSG_MOD(info->extack, "Fail to find the specified management device"); in vdpa_nl_cmd_dev_add_set_doit()
672 if ((config.mask & mdev->config_attr_mask) != config.mask) { in vdpa_nl_cmd_dev_add_set_doit()
673 NL_SET_ERR_MSG_FMT_MOD(info->extack, in vdpa_nl_cmd_dev_add_set_doit()
675 config.mask & ~mdev->config_attr_mask); in vdpa_nl_cmd_dev_add_set_doit()
676 err = -EOPNOTSUPP; in vdpa_nl_cmd_dev_add_set_doit()
681 if (config.mask & VDPA_DEV_NET_ATTRS_MASK && in vdpa_nl_cmd_dev_add_set_doit()
683 NL_SET_ERR_MSG_MOD(info->extack, in vdpa_nl_cmd_dev_add_set_doit()
685 err = -EINVAL; in vdpa_nl_cmd_dev_add_set_doit()
688 if (!(config.mask & VDPA_DEV_NET_ATTRS_MASK) && in vdpa_nl_cmd_dev_add_set_doit()
689 config.mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES) && in vdpa_nl_cmd_dev_add_set_doit()
691 config.device_features & VIRTIO_DEVICE_F_MASK) { in vdpa_nl_cmd_dev_add_set_doit()
692 NL_SET_ERR_MSG_MOD(info->extack, in vdpa_nl_cmd_dev_add_set_doit()
693 "Management device supports multi-class while device features specified are ambiguous"); in vdpa_nl_cmd_dev_add_set_doit()
694 err = -EINVAL; in vdpa_nl_cmd_dev_add_set_doit()
698 err = mdev->ops->dev_add(mdev, name, &config); in vdpa_nl_cmd_dev_add_set_doit()
704 static int vdpa_nl_cmd_dev_del_set_doit(struct sk_buff *skb, struct genl_info *info) in vdpa_nl_cmd_dev_del_set_doit()
712 if (!info->attrs[VDPA_ATTR_DEV_NAME]) in vdpa_nl_cmd_dev_del_set_doit()
713 return -EINVAL; in vdpa_nl_cmd_dev_del_set_doit()
714 name = nla_data(info->attrs[VDPA_ATTR_DEV_NAME]); in vdpa_nl_cmd_dev_del_set_doit()
719 NL_SET_ERR_MSG_MOD(info->extack, "device not found"); in vdpa_nl_cmd_dev_del_set_doit()
720 err = -ENODEV; in vdpa_nl_cmd_dev_del_set_doit()
724 if (!vdev->mdev) { in vdpa_nl_cmd_dev_del_set_doit()
725 NL_SET_ERR_MSG_MOD(info->extack, "Only user created device can be deleted by user"); in vdpa_nl_cmd_dev_del_set_doit()
726 err = -EINVAL; in vdpa_nl_cmd_dev_del_set_doit()
729 mdev = vdev->mdev; in vdpa_nl_cmd_dev_del_set_doit()
730 mdev->ops->dev_del(mdev, vdev); in vdpa_nl_cmd_dev_del_set_doit()
738 static int
751 return -EMSGSIZE; in vdpa_dev_fill()
753 err = vdpa_nl_mgmtdev_handle_fill(msg, vdev->mdev); in vdpa_dev_fill()
757 device_id = vdev->config->get_device_id(vdev); in vdpa_dev_fill()
758 vendor_id = vdev->config->get_vendor_id(vdev); in vdpa_dev_fill()
759 max_vq_size = vdev->config->get_vq_num_max(vdev); in vdpa_dev_fill()
760 if (vdev->config->get_vq_num_min) in vdpa_dev_fill()
761 min_vq_size = vdev->config->get_vq_num_min(vdev); in vdpa_dev_fill()
763 err = -EMSGSIZE; in vdpa_dev_fill()
764 if (nla_put_string(msg, VDPA_ATTR_DEV_NAME, dev_name(&vdev->dev))) in vdpa_dev_fill()
770 if (nla_put_u32(msg, VDPA_ATTR_DEV_MAX_VQS, vdev->nvqs)) in vdpa_dev_fill()
785 static int vdpa_nl_cmd_dev_get_doit(struct sk_buff *skb, struct genl_info *info) in vdpa_nl_cmd_dev_get_doit()
793 if (!info->attrs[VDPA_ATTR_DEV_NAME]) in vdpa_nl_cmd_dev_get_doit()
794 return -EINVAL; in vdpa_nl_cmd_dev_get_doit()
795 devname = nla_data(info->attrs[VDPA_ATTR_DEV_NAME]); in vdpa_nl_cmd_dev_get_doit()
798 return -ENOMEM; in vdpa_nl_cmd_dev_get_doit()
803 NL_SET_ERR_MSG_MOD(info->extack, "device not found"); in vdpa_nl_cmd_dev_get_doit()
804 err = -ENODEV; in vdpa_nl_cmd_dev_get_doit()
808 if (!vdev->mdev) { in vdpa_nl_cmd_dev_get_doit()
809 err = -EINVAL; in vdpa_nl_cmd_dev_get_doit()
812 err = vdpa_dev_fill(vdev, msg, info->snd_portid, info->snd_seq, 0, info->extack); in vdpa_nl_cmd_dev_get_doit()
836 static int vdpa_dev_dump(struct device *dev, void *data) in vdpa_dev_dump()
842 if (!vdev->mdev) in vdpa_dev_dump()
844 if (info->idx < info->start_idx) { in vdpa_dev_dump()
845 info->idx++; in vdpa_dev_dump()
848 err = vdpa_dev_fill(vdev, info->msg, NETLINK_CB(info->cb->skb).portid, in vdpa_dev_dump()
849 info->cb->nlh->nlmsg_seq, NLM_F_MULTI, info->cb->extack); in vdpa_dev_dump()
853 info->idx++; in vdpa_dev_dump()
857 static int vdpa_nl_cmd_dev_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb) in vdpa_nl_cmd_dev_get_dumpit()
863 info.start_idx = cb->args[0]; in vdpa_nl_cmd_dev_get_dumpit()
869 cb->args[0] = info.idx; in vdpa_nl_cmd_dev_get_dumpit()
870 return msg->len; in vdpa_nl_cmd_dev_get_dumpit()
873 static int vdpa_dev_net_mq_config_fill(struct sk_buff *msg, u64 features, in vdpa_dev_net_mq_config_fill()
874 const struct virtio_net_config *config) in vdpa_dev_net_mq_config_fill() argument
882 val_u16 = __virtio16_to_cpu(true, config->max_virtqueue_pairs); in vdpa_dev_net_mq_config_fill()
887 static int vdpa_dev_net_mtu_config_fill(struct sk_buff *msg, u64 features, in vdpa_dev_net_mtu_config_fill()
888 const struct virtio_net_config *config) in vdpa_dev_net_mtu_config_fill() argument
895 val_u16 = __virtio16_to_cpu(true, config->mtu); in vdpa_dev_net_mtu_config_fill()
900 static int vdpa_dev_net_mac_config_fill(struct sk_buff *msg, u64 features, in vdpa_dev_net_mac_config_fill()
901 const struct virtio_net_config *config) in vdpa_dev_net_mac_config_fill() argument
907 sizeof(config->mac), config->mac); in vdpa_dev_net_mac_config_fill()
910 static int vdpa_dev_net_status_config_fill(struct sk_buff *msg, u64 features, in vdpa_dev_net_status_config_fill()
911 const struct virtio_net_config *config) in vdpa_dev_net_status_config_fill() argument
918 val_u16 = __virtio16_to_cpu(true, config->status); in vdpa_dev_net_status_config_fill()
922 static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg) in vdpa_dev_net_config_fill()
924 struct virtio_net_config config = {}; in vdpa_dev_net_config_fill() local
927 vdev->config->get_config(vdev, 0, &config, sizeof(config)); in vdpa_dev_net_config_fill()
929 features_device = vdev->config->get_device_features(vdev); in vdpa_dev_net_config_fill()
933 return -EMSGSIZE; in vdpa_dev_net_config_fill()
935 if (vdpa_dev_net_mtu_config_fill(msg, features_device, &config)) in vdpa_dev_net_config_fill()
936 return -EMSGSIZE; in vdpa_dev_net_config_fill()
938 if (vdpa_dev_net_mac_config_fill(msg, features_device, &config)) in vdpa_dev_net_config_fill()
939 return -EMSGSIZE; in vdpa_dev_net_config_fill()
941 if (vdpa_dev_net_status_config_fill(msg, features_device, &config)) in vdpa_dev_net_config_fill()
942 return -EMSGSIZE; in vdpa_dev_net_config_fill()
944 return vdpa_dev_net_mq_config_fill(msg, features_device, &config); in vdpa_dev_net_config_fill()
947 static int
949 const struct virtio_blk_config *config) in vdpa_dev_blk_capacity_config_fill() argument
953 val_u64 = __virtio64_to_cpu(true, config->capacity); in vdpa_dev_blk_capacity_config_fill()
959 static int
961 const struct virtio_blk_config *config) in vdpa_dev_blk_seg_size_config_fill() argument
968 val_u32 = __virtio32_to_cpu(true, config->size_max); in vdpa_dev_blk_seg_size_config_fill()
974 static int
976 const struct virtio_blk_config *config) in vdpa_dev_blk_block_size_config_fill() argument
983 val_u32 = __virtio32_to_cpu(true, config->blk_size); in vdpa_dev_blk_block_size_config_fill()
988 static int
990 const struct virtio_blk_config *config) in vdpa_dev_blk_seg_max_config_fill() argument
997 val_u32 = __virtio32_to_cpu(true, config->seg_max); in vdpa_dev_blk_seg_max_config_fill()
1002 static int vdpa_dev_blk_mq_config_fill(struct sk_buff *msg, u64 features, in vdpa_dev_blk_mq_config_fill()
1003 const struct virtio_blk_config *config) in vdpa_dev_blk_mq_config_fill() argument
1010 val_u16 = __virtio16_to_cpu(true, config->num_queues); in vdpa_dev_blk_mq_config_fill()
1015 static int vdpa_dev_blk_topology_config_fill(struct sk_buff *msg, u64 features, in vdpa_dev_blk_topology_config_fill()
1016 const struct virtio_blk_config *config) in vdpa_dev_blk_topology_config_fill() argument
1024 min_io_size = __virtio16_to_cpu(true, config->min_io_size); in vdpa_dev_blk_topology_config_fill()
1025 opt_io_size = __virtio32_to_cpu(true, config->opt_io_size); in vdpa_dev_blk_topology_config_fill()
1028 config->physical_block_exp)) in vdpa_dev_blk_topology_config_fill()
1029 return -EMSGSIZE; in vdpa_dev_blk_topology_config_fill()
1032 config->alignment_offset)) in vdpa_dev_blk_topology_config_fill()
1033 return -EMSGSIZE; in vdpa_dev_blk_topology_config_fill()
1036 return -EMSGSIZE; in vdpa_dev_blk_topology_config_fill()
1039 return -EMSGSIZE; in vdpa_dev_blk_topology_config_fill()
1044 static int vdpa_dev_blk_discard_config_fill(struct sk_buff *msg, u64 features, in vdpa_dev_blk_discard_config_fill()
1045 const struct virtio_blk_config *config) in vdpa_dev_blk_discard_config_fill() argument
1052 val_u32 = __virtio32_to_cpu(true, config->max_discard_sectors); in vdpa_dev_blk_discard_config_fill()
1054 return -EMSGSIZE; in vdpa_dev_blk_discard_config_fill()
1056 val_u32 = __virtio32_to_cpu(true, config->max_discard_seg); in vdpa_dev_blk_discard_config_fill()
1058 return -EMSGSIZE; in vdpa_dev_blk_discard_config_fill()
1060 val_u32 = __virtio32_to_cpu(true, config->discard_sector_alignment); in vdpa_dev_blk_discard_config_fill()
1062 return -EMSGSIZE; in vdpa_dev_blk_discard_config_fill()
1067 static int
1069 const struct virtio_blk_config *config) in vdpa_dev_blk_write_zeroes_config_fill() argument
1076 val_u32 = __virtio32_to_cpu(true, config->max_write_zeroes_sectors); in vdpa_dev_blk_write_zeroes_config_fill()
1078 return -EMSGSIZE; in vdpa_dev_blk_write_zeroes_config_fill()
1080 val_u32 = __virtio32_to_cpu(true, config->max_write_zeroes_seg); in vdpa_dev_blk_write_zeroes_config_fill()
1082 return -EMSGSIZE; in vdpa_dev_blk_write_zeroes_config_fill()
1087 static int vdpa_dev_blk_ro_config_fill(struct sk_buff *msg, u64 features) in vdpa_dev_blk_ro_config_fill()
1093 return -EMSGSIZE; in vdpa_dev_blk_ro_config_fill()
1098 static int vdpa_dev_blk_flush_config_fill(struct sk_buff *msg, u64 features) in vdpa_dev_blk_flush_config_fill()
1104 return -EMSGSIZE; in vdpa_dev_blk_flush_config_fill()
1109 static int vdpa_dev_blk_config_fill(struct vdpa_device *vdev, in vdpa_dev_blk_config_fill()
1112 struct virtio_blk_config config = {}; in vdpa_dev_blk_config_fill() local
1115 vdev->config->get_config(vdev, 0, &config, sizeof(config)); in vdpa_dev_blk_config_fill()
1117 features_device = vdev->config->get_device_features(vdev); in vdpa_dev_blk_config_fill()
1121 return -EMSGSIZE; in vdpa_dev_blk_config_fill()
1123 if (vdpa_dev_blk_capacity_config_fill(msg, &config)) in vdpa_dev_blk_config_fill()
1124 return -EMSGSIZE; in vdpa_dev_blk_config_fill()
1126 if (vdpa_dev_blk_seg_size_config_fill(msg, features_device, &config)) in vdpa_dev_blk_config_fill()
1127 return -EMSGSIZE; in vdpa_dev_blk_config_fill()
1129 if (vdpa_dev_blk_block_size_config_fill(msg, features_device, &config)) in vdpa_dev_blk_config_fill()
1130 return -EMSGSIZE; in vdpa_dev_blk_config_fill()
1132 if (vdpa_dev_blk_seg_max_config_fill(msg, features_device, &config)) in vdpa_dev_blk_config_fill()
1133 return -EMSGSIZE; in vdpa_dev_blk_config_fill()
1135 if (vdpa_dev_blk_mq_config_fill(msg, features_device, &config)) in vdpa_dev_blk_config_fill()
1136 return -EMSGSIZE; in vdpa_dev_blk_config_fill()
1138 if (vdpa_dev_blk_topology_config_fill(msg, features_device, &config)) in vdpa_dev_blk_config_fill()
1139 return -EMSGSIZE; in vdpa_dev_blk_config_fill()
1141 if (vdpa_dev_blk_discard_config_fill(msg, features_device, &config)) in vdpa_dev_blk_config_fill()
1142 return -EMSGSIZE; in vdpa_dev_blk_config_fill()
1144 if (vdpa_dev_blk_write_zeroes_config_fill(msg, features_device, &config)) in vdpa_dev_blk_config_fill()
1145 return -EMSGSIZE; in vdpa_dev_blk_config_fill()
1148 return -EMSGSIZE; in vdpa_dev_blk_config_fill()
1151 return -EMSGSIZE; in vdpa_dev_blk_config_fill()
1156 static int
1166 down_read(&vdev->cf_lock); in vdpa_dev_config_fill()
1170 err = -EMSGSIZE; in vdpa_dev_config_fill()
1174 if (nla_put_string(msg, VDPA_ATTR_DEV_NAME, dev_name(&vdev->dev))) { in vdpa_dev_config_fill()
1175 err = -EMSGSIZE; in vdpa_dev_config_fill()
1179 device_id = vdev->config->get_device_id(vdev); in vdpa_dev_config_fill()
1181 err = -EMSGSIZE; in vdpa_dev_config_fill()
1186 status = vdev->config->get_status(vdev); in vdpa_dev_config_fill()
1188 features_driver = vdev->config->get_driver_features(vdev); in vdpa_dev_config_fill()
1191 err = -EMSGSIZE; in vdpa_dev_config_fill()
1204 err = -EOPNOTSUPP; in vdpa_dev_config_fill()
1210 up_read(&vdev->cf_lock); in vdpa_dev_config_fill()
1217 up_read(&vdev->cf_lock); in vdpa_dev_config_fill()
1221 static int vdpa_fill_stats_rec(struct vdpa_device *vdev, struct sk_buff *msg, in vdpa_fill_stats_rec()
1224 struct virtio_net_config config = {}; in vdpa_fill_stats_rec() local
1229 status = vdev->config->get_status(vdev); in vdpa_fill_stats_rec()
1231 NL_SET_ERR_MSG_MOD(info->extack, "feature negotiation not complete"); in vdpa_fill_stats_rec()
1232 return -EAGAIN; in vdpa_fill_stats_rec()
1234 vdpa_get_config_unlocked(vdev, 0, &config, sizeof(config)); in vdpa_fill_stats_rec()
1236 features = vdev->config->get_driver_features(vdev); in vdpa_fill_stats_rec()
1239 return -EMSGSIZE; in vdpa_fill_stats_rec()
1241 err = vdpa_dev_net_mq_config_fill(msg, features, &config); in vdpa_fill_stats_rec()
1246 return -EMSGSIZE; in vdpa_fill_stats_rec()
1248 err = vdev->config->get_vendor_vq_stats(vdev, index, msg, info->extack); in vdpa_fill_stats_rec()
1255 static int vendor_stats_fill(struct vdpa_device *vdev, struct sk_buff *msg, in vendor_stats_fill()
1260 down_read(&vdev->cf_lock); in vendor_stats_fill()
1261 if (!vdev->config->get_vendor_vq_stats) { in vendor_stats_fill()
1262 err = -EOPNOTSUPP; in vendor_stats_fill()
1268 up_read(&vdev->cf_lock); in vendor_stats_fill()
1272 static int vdpa_dev_vendor_stats_fill(struct vdpa_device *vdev, in vdpa_dev_vendor_stats_fill()
1279 u32 portid = info->snd_portid; in vdpa_dev_vendor_stats_fill()
1280 u32 seq = info->snd_seq; in vdpa_dev_vendor_stats_fill()
1286 return -EMSGSIZE; in vdpa_dev_vendor_stats_fill()
1288 if (nla_put_string(msg, VDPA_ATTR_DEV_NAME, dev_name(&vdev->dev))) { in vdpa_dev_vendor_stats_fill()
1289 err = -EMSGSIZE; in vdpa_dev_vendor_stats_fill()
1293 device_id = vdev->config->get_device_id(vdev); in vdpa_dev_vendor_stats_fill()
1295 err = -EMSGSIZE; in vdpa_dev_vendor_stats_fill()
1302 NL_SET_ERR_MSG_MOD(info->extack, "queue index exceeds max value"); in vdpa_dev_vendor_stats_fill()
1303 err = -ERANGE; in vdpa_dev_vendor_stats_fill()
1310 err = -EOPNOTSUPP; in vdpa_dev_vendor_stats_fill()
1322 static int vdpa_nl_cmd_dev_config_get_doit(struct sk_buff *skb, struct genl_info *info) in vdpa_nl_cmd_dev_config_get_doit()
1330 if (!info->attrs[VDPA_ATTR_DEV_NAME]) in vdpa_nl_cmd_dev_config_get_doit()
1331 return -EINVAL; in vdpa_nl_cmd_dev_config_get_doit()
1332 devname = nla_data(info->attrs[VDPA_ATTR_DEV_NAME]); in vdpa_nl_cmd_dev_config_get_doit()
1335 return -ENOMEM; in vdpa_nl_cmd_dev_config_get_doit()
1340 NL_SET_ERR_MSG_MOD(info->extack, "device not found"); in vdpa_nl_cmd_dev_config_get_doit()
1341 err = -ENODEV; in vdpa_nl_cmd_dev_config_get_doit()
1345 if (!vdev->mdev) { in vdpa_nl_cmd_dev_config_get_doit()
1346 NL_SET_ERR_MSG_MOD(info->extack, "unmanaged vdpa device"); in vdpa_nl_cmd_dev_config_get_doit()
1347 err = -EINVAL; in vdpa_nl_cmd_dev_config_get_doit()
1350 err = vdpa_dev_config_fill(vdev, msg, info->snd_portid, info->snd_seq, in vdpa_nl_cmd_dev_config_get_doit()
1351 0, info->extack); in vdpa_nl_cmd_dev_config_get_doit()
1364 static int vdpa_dev_net_device_attr_set(struct vdpa_device *vdev, in vdpa_dev_net_device_attr_set()
1368 struct vdpa_mgmt_dev *mdev = vdev->mdev; in vdpa_dev_net_device_attr_set()
1369 struct nlattr **nl_attrs = info->attrs; in vdpa_dev_net_device_attr_set()
1371 int err = -EOPNOTSUPP; in vdpa_dev_net_device_attr_set()
1373 down_write(&vdev->cf_lock); in vdpa_dev_net_device_attr_set()
1380 if (mdev->ops->dev_set_attr) { in vdpa_dev_net_device_attr_set()
1381 err = mdev->ops->dev_set_attr(mdev, vdev, in vdpa_dev_net_device_attr_set()
1384 NL_SET_ERR_MSG_FMT_MOD(info->extack, in vdpa_dev_net_device_attr_set()
1388 NL_SET_ERR_MSG_FMT_MOD(info->extack, in vdpa_dev_net_device_attr_set()
1392 up_write(&vdev->cf_lock); in vdpa_dev_net_device_attr_set()
1396 static int vdpa_nl_cmd_dev_attr_set_doit(struct sk_buff *skb, in vdpa_nl_cmd_dev_attr_set_doit()
1405 if (!info->attrs[VDPA_ATTR_DEV_NAME]) in vdpa_nl_cmd_dev_attr_set_doit()
1406 return -EINVAL; in vdpa_nl_cmd_dev_attr_set_doit()
1408 name = nla_data(info->attrs[VDPA_ATTR_DEV_NAME]); in vdpa_nl_cmd_dev_attr_set_doit()
1413 NL_SET_ERR_MSG_MOD(info->extack, "device not found"); in vdpa_nl_cmd_dev_attr_set_doit()
1414 err = -ENODEV; in vdpa_nl_cmd_dev_attr_set_doit()
1418 if (!vdev->mdev) { in vdpa_nl_cmd_dev_attr_set_doit()
1419 NL_SET_ERR_MSG_MOD(info->extack, "unmanaged vdpa device"); in vdpa_nl_cmd_dev_attr_set_doit()
1420 err = -EINVAL; in vdpa_nl_cmd_dev_attr_set_doit()
1423 classes = vdpa_mgmtdev_get_classes(vdev->mdev, NULL); in vdpa_nl_cmd_dev_attr_set_doit()
1427 NL_SET_ERR_MSG_FMT_MOD(info->extack, "%s device not supported", in vdpa_nl_cmd_dev_attr_set_doit()
1438 static int vdpa_dev_config_dump(struct device *dev, void *data) in vdpa_dev_config_dump()
1444 if (!vdev->mdev) in vdpa_dev_config_dump()
1446 if (info->idx < info->start_idx) { in vdpa_dev_config_dump()
1447 info->idx++; in vdpa_dev_config_dump()
1450 err = vdpa_dev_config_fill(vdev, info->msg, NETLINK_CB(info->cb->skb).portid, in vdpa_dev_config_dump()
1451 info->cb->nlh->nlmsg_seq, NLM_F_MULTI, in vdpa_dev_config_dump()
1452 info->cb->extack); in vdpa_dev_config_dump()
1456 info->idx++; in vdpa_dev_config_dump()
1460 static int
1467 info.start_idx = cb->args[0]; in vdpa_nl_cmd_dev_config_get_dumpit()
1473 cb->args[0] = info.idx; in vdpa_nl_cmd_dev_config_get_dumpit()
1474 return msg->len; in vdpa_nl_cmd_dev_config_get_dumpit()
1477 static int vdpa_nl_cmd_dev_stats_get_doit(struct sk_buff *skb, in vdpa_nl_cmd_dev_stats_get_doit()
1487 if (!info->attrs[VDPA_ATTR_DEV_NAME]) in vdpa_nl_cmd_dev_stats_get_doit()
1488 return -EINVAL; in vdpa_nl_cmd_dev_stats_get_doit()
1490 if (!info->attrs[VDPA_ATTR_DEV_QUEUE_INDEX]) in vdpa_nl_cmd_dev_stats_get_doit()
1491 return -EINVAL; in vdpa_nl_cmd_dev_stats_get_doit()
1493 devname = nla_data(info->attrs[VDPA_ATTR_DEV_NAME]); in vdpa_nl_cmd_dev_stats_get_doit()
1496 return -ENOMEM; in vdpa_nl_cmd_dev_stats_get_doit()
1498 index = nla_get_u32(info->attrs[VDPA_ATTR_DEV_QUEUE_INDEX]); in vdpa_nl_cmd_dev_stats_get_doit()
1502 NL_SET_ERR_MSG_MOD(info->extack, "device not found"); in vdpa_nl_cmd_dev_stats_get_doit()
1503 err = -ENODEV; in vdpa_nl_cmd_dev_stats_get_doit()
1507 if (!vdev->mdev) { in vdpa_nl_cmd_dev_stats_get_doit()
1508 NL_SET_ERR_MSG_MOD(info->extack, "unmanaged vdpa device"); in vdpa_nl_cmd_dev_stats_get_doit()
1509 err = -EINVAL; in vdpa_nl_cmd_dev_stats_get_doit()
1531 static const struct nla_policy vdpa_nl_policy[VDPA_ATTR_MAX + 1] = {
1543 static const struct genl_ops vdpa_nl_ops[] = {
1581 static struct genl_family vdpa_nl_family __ro_after_init = {
1593 static int vdpa_init(void) in vdpa_init()
1610 static void __exit vdpa_exit(void) in vdpa_exit()