|
16 | 16 | #include <linux/vringh.h>
|
17 | 17 | #include <linux/vdpa.h>
|
18 | 18 | #include <uapi/linux/virtio_net.h>
|
| 19 | +#include <uapi/linux/vdpa.h> |
19 | 20 |
|
20 | 21 | #include "vdpa_sim.h"
|
21 | 22 |
|
|
29 | 30 |
|
30 | 31 | #define VDPASIM_NET_VQ_NUM 2
|
31 | 32 |
|
32 |
| -static char *macaddr; |
33 |
| -module_param(macaddr, charp, 0); |
34 |
| -MODULE_PARM_DESC(macaddr, "Ethernet MAC address"); |
35 |
| - |
36 |
| -static u8 macaddr_buf[ETH_ALEN]; |
37 |
| - |
38 | 33 | static void vdpasim_net_work(struct work_struct *work)
|
39 | 34 | {
|
40 | 35 | struct vdpasim *vdpasim = container_of(work, struct vdpasim, work);
|
@@ -112,9 +107,21 @@ static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *config)
|
112 | 107 | {
|
113 | 108 | struct virtio_net_config *net_config = config;
|
114 | 109 |
|
115 |
| - net_config->mtu = cpu_to_vdpasim16(vdpasim, 1500); |
116 | 110 | net_config->status = cpu_to_vdpasim16(vdpasim, VIRTIO_NET_S_LINK_UP);
|
117 |
| - memcpy(net_config->mac, macaddr_buf, ETH_ALEN); |
| 111 | +} |
| 112 | + |
| 113 | +static void vdpasim_net_setup_config(struct vdpasim *vdpasim, |
| 114 | + const struct vdpa_dev_set_config *config) |
| 115 | +{ |
| 116 | + struct virtio_net_config *vio_config = vdpasim->config; |
| 117 | + |
| 118 | + if (config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) |
| 119 | + memcpy(vio_config->mac, config->net.mac, ETH_ALEN); |
| 120 | + if (config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MTU)) |
| 121 | + vio_config->mtu = cpu_to_vdpasim16(vdpasim, config->net.mtu); |
| 122 | + else |
| 123 | + /* Setup default MTU to be 1500 */ |
| 124 | + vio_config->mtu = cpu_to_vdpasim16(vdpasim, 1500); |
118 | 125 | }
|
119 | 126 |
|
120 | 127 | static void vdpasim_net_mgmtdev_release(struct device *dev)
|
@@ -147,6 +154,8 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
|
147 | 154 | if (IS_ERR(simdev))
|
148 | 155 | return PTR_ERR(simdev);
|
149 | 156 |
|
| 157 | + vdpasim_net_setup_config(simdev, config); |
| 158 | + |
150 | 159 | ret = _vdpa_register_device(&simdev->vdpa, VDPASIM_NET_VQ_NUM);
|
151 | 160 | if (ret)
|
152 | 161 | goto reg_err;
|
@@ -180,20 +189,14 @@ static struct vdpa_mgmt_dev mgmt_dev = {
|
180 | 189 | .device = &vdpasim_net_mgmtdev,
|
181 | 190 | .id_table = id_table,
|
182 | 191 | .ops = &vdpasim_net_mgmtdev_ops,
|
| 192 | + .config_attr_mask = (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR | |
| 193 | + 1 << VDPA_ATTR_DEV_NET_CFG_MTU), |
183 | 194 | };
|
184 | 195 |
|
185 | 196 | static int __init vdpasim_net_init(void)
|
186 | 197 | {
|
187 | 198 | int ret;
|
188 | 199 |
|
189 |
| - if (macaddr) { |
190 |
| - mac_pton(macaddr, macaddr_buf); |
191 |
| - if (!is_valid_ether_addr(macaddr_buf)) |
192 |
| - return -EADDRNOTAVAIL; |
193 |
| - } else { |
194 |
| - eth_random_addr(macaddr_buf); |
195 |
| - } |
196 |
| - |
197 | 200 | ret = device_register(&vdpasim_net_mgmtdev);
|
198 | 201 | if (ret)
|
199 | 202 | return ret;
|
|
0 commit comments