Skip to content

Commit 423d932

Browse files
committed
implement MTU change for netvsc driver
1 parent 33d6694 commit 423d932

File tree

5 files changed

+148
-34
lines changed

5 files changed

+148
-34
lines changed

drivers/bus/vmbus/vmbus_common.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ vmbus_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
3939
"mmap(%d, %p, %zu, %ld) failed: %s",
4040
fd, requested_addr, size, (long)offset,
4141
strerror(errno));
42-
}
42+
} else
43+
VMBUS_LOG(DEBUG, " VMBUS memory mapped at %p",
44+
mapaddr);
4345
return mapaddr;
4446
}
4547

drivers/net/netvsc/hn_ethdev.c

Lines changed: 136 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,37 +1059,6 @@ hn_dev_close(struct rte_eth_dev *dev)
10591059
return ret;
10601060
}
10611061

1062-
static const struct eth_dev_ops hn_eth_dev_ops = {
1063-
.dev_configure = hn_dev_configure,
1064-
.dev_start = hn_dev_start,
1065-
.dev_stop = hn_dev_stop,
1066-
.dev_close = hn_dev_close,
1067-
.dev_infos_get = hn_dev_info_get,
1068-
.txq_info_get = hn_dev_tx_queue_info,
1069-
.rxq_info_get = hn_dev_rx_queue_info,
1070-
.dev_supported_ptypes_get = hn_vf_supported_ptypes,
1071-
.promiscuous_enable = hn_dev_promiscuous_enable,
1072-
.promiscuous_disable = hn_dev_promiscuous_disable,
1073-
.allmulticast_enable = hn_dev_allmulticast_enable,
1074-
.allmulticast_disable = hn_dev_allmulticast_disable,
1075-
.set_mc_addr_list = hn_dev_mc_addr_list,
1076-
.reta_update = hn_rss_reta_update,
1077-
.reta_query = hn_rss_reta_query,
1078-
.rss_hash_update = hn_rss_hash_update,
1079-
.rss_hash_conf_get = hn_rss_hash_conf_get,
1080-
.tx_queue_setup = hn_dev_tx_queue_setup,
1081-
.tx_queue_release = hn_dev_tx_queue_release,
1082-
.tx_done_cleanup = hn_dev_tx_done_cleanup,
1083-
.rx_queue_setup = hn_dev_rx_queue_setup,
1084-
.rx_queue_release = hn_dev_rx_queue_release,
1085-
.link_update = hn_dev_link_update,
1086-
.stats_get = hn_dev_stats_get,
1087-
.stats_reset = hn_dev_stats_reset,
1088-
.xstats_get = hn_dev_xstats_get,
1089-
.xstats_get_names = hn_dev_xstats_get_names,
1090-
.xstats_reset = hn_dev_xstats_reset,
1091-
};
1092-
10931062
/*
10941063
* Setup connection between PMD and kernel.
10951064
*/
@@ -1129,12 +1098,141 @@ hn_detach(struct hn_data *hv)
11291098
hn_rndis_detach(hv);
11301099
}
11311100

1101+
static int
1102+
hn_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1103+
{
1104+
struct hn_data *hv = dev->data->dev_private;
1105+
struct rte_eth_dev *vf_dev;
1106+
unsigned int orig_mtu = dev->data->mtu;
1107+
uint32_t rndis_mtu;
1108+
int ret = 0;
1109+
1110+
if (dev->data->dev_started) {
1111+
PMD_DRV_LOG(ERR, "Device must be stopped before changing MTU");
1112+
return -EIO;
1113+
}
1114+
1115+
ret = hn_dev_close(dev);
1116+
if (ret)
1117+
return ret;
1118+
1119+
/* Change MTU of underlying VF netdev first, if it exists */
1120+
rte_rwlock_read_lock(&hv->vf_lock);
1121+
vf_dev = hn_get_vf_dev(hv);
1122+
if (hv->vf_ctx.vf_vsc_switched && vf_dev) {
1123+
ret = vf_dev->dev_ops->mtu_set(vf_dev, mtu);
1124+
if (ret) {
1125+
rte_rwlock_read_unlock(&hv->vf_lock);
1126+
goto out;
1127+
}
1128+
}
1129+
rte_rwlock_read_unlock(&hv->vf_lock);
1130+
1131+
/* Release channel resources */
1132+
hn_detach(hv);
1133+
hn_chim_uninit(dev);
1134+
rte_vmbus_chan_close(hv->channels[0]);
1135+
1136+
/* Unmap and re-map vmbus device */
1137+
rte_vmbus_unmap_device(hv->vmbus);
1138+
ret = rte_vmbus_map_device(hv->vmbus);
1139+
if (ret) {
1140+
/* This is a catastrophic error - the device is unusable */
1141+
PMD_DRV_LOG(ERR, "Could not re-map vmbus device!");
1142+
return ret;
1143+
}
1144+
1145+
/* Update pointers to re-mapped memory */
1146+
hv->rxbuf_res = hv->vmbus->resource[HV_RECV_BUF_MAP];
1147+
hv->chim_res = hv->vmbus->resource[HV_SEND_BUF_MAP];
1148+
1149+
/* Re-open the vmbus channel */
1150+
ret = rte_vmbus_chan_open(hv->vmbus, &hv->channels[0]);
1151+
if (ret) {
1152+
/* This is a catastrophic error - the device is unusable */
1153+
PMD_DRV_LOG(ERR, "Could not re-open vmbus channel!");
1154+
}
1155+
1156+
rte_vmbus_set_latency(hv->vmbus, hv->channels[0], hv->latency);
1157+
1158+
hv->primary = hn_rx_queue_alloc(hv, 0,
1159+
dev->device->numa_node);
1160+
1161+
if (!hv->primary) {
1162+
/* This is a catastrophic error - the device is unusable */
1163+
PMD_DRV_LOG(ERR, "No memory to allocate rx queue!");
1164+
return -ENOMEM;
1165+
}
1166+
1167+
ret = hn_attach(hv, mtu);
1168+
if (ret)
1169+
goto error;
1170+
1171+
ret = hn_chim_init(dev);
1172+
if (!ret)
1173+
goto out;
1174+
1175+
error:
1176+
/* In case of error, attempt rollback to original MTU */
1177+
if (hn_attach(hv, orig_mtu))
1178+
PMD_DRV_LOG(ERR, "Restoring original MTU failed");
1179+
1180+
rte_rwlock_read_lock(&hv->vf_lock);
1181+
vf_dev = hn_get_vf_dev(hv);
1182+
if (hv->vf_ctx.vf_vsc_switched && vf_dev)
1183+
vf_dev->dev_ops->mtu_set(vf_dev, orig_mtu);
1184+
rte_rwlock_read_unlock(&hv->vf_lock);
1185+
1186+
out:
1187+
if (hn_rndis_get_mtu(hv, &rndis_mtu))
1188+
PMD_DRV_LOG(ERR, "Could not get MTU via RNDIS");
1189+
else {
1190+
dev->data->mtu = (uint16_t)rndis_mtu;
1191+
PMD_DRV_LOG(DEBUG, "RNDIS MTU is %u", dev->data->mtu);
1192+
}
1193+
1194+
return ret;
1195+
}
1196+
1197+
static const struct eth_dev_ops hn_eth_dev_ops = {
1198+
.dev_configure = hn_dev_configure,
1199+
.dev_start = hn_dev_start,
1200+
.dev_stop = hn_dev_stop,
1201+
.dev_close = hn_dev_close,
1202+
.dev_infos_get = hn_dev_info_get,
1203+
.txq_info_get = hn_dev_tx_queue_info,
1204+
.rxq_info_get = hn_dev_rx_queue_info,
1205+
.dev_supported_ptypes_get = hn_vf_supported_ptypes,
1206+
.promiscuous_enable = hn_dev_promiscuous_enable,
1207+
.promiscuous_disable = hn_dev_promiscuous_disable,
1208+
.allmulticast_enable = hn_dev_allmulticast_enable,
1209+
.allmulticast_disable = hn_dev_allmulticast_disable,
1210+
.set_mc_addr_list = hn_dev_mc_addr_list,
1211+
.mtu_set = hn_dev_mtu_set,
1212+
.reta_update = hn_rss_reta_update,
1213+
.reta_query = hn_rss_reta_query,
1214+
.rss_hash_update = hn_rss_hash_update,
1215+
.rss_hash_conf_get = hn_rss_hash_conf_get,
1216+
.tx_queue_setup = hn_dev_tx_queue_setup,
1217+
.tx_queue_release = hn_dev_tx_queue_release,
1218+
.tx_done_cleanup = hn_dev_tx_done_cleanup,
1219+
.rx_queue_setup = hn_dev_rx_queue_setup,
1220+
.rx_queue_release = hn_dev_rx_queue_release,
1221+
.link_update = hn_dev_link_update,
1222+
.stats_get = hn_dev_stats_get,
1223+
.stats_reset = hn_dev_stats_reset,
1224+
.xstats_get = hn_dev_xstats_get,
1225+
.xstats_get_names = hn_dev_xstats_get_names,
1226+
.xstats_reset = hn_dev_xstats_reset,
1227+
};
1228+
11321229
static int
11331230
eth_hn_dev_init(struct rte_eth_dev *eth_dev)
11341231
{
11351232
struct hn_data *hv = eth_dev->data->dev_private;
11361233
struct rte_device *device = eth_dev->device;
11371234
struct rte_vmbus_device *vmbus;
1235+
uint32_t mtu;
11381236
unsigned int rxr_cnt;
11391237
int err, max_chan;
11401238

@@ -1218,6 +1316,12 @@ eth_hn_dev_init(struct rte_eth_dev *eth_dev)
12181316
if (err)
12191317
goto failed;
12201318

1319+
err = hn_rndis_get_mtu(hv, &mtu);
1320+
if (err)
1321+
goto failed;
1322+
eth_dev->data->mtu = (uint16_t)mtu;
1323+
PMD_INIT_LOG(DEBUG, "RNDIS MTU is %u", eth_dev->data->mtu);
1324+
12211325
err = hn_rndis_get_eaddr(hv, eth_dev->data->mac_addrs->addr_bytes);
12221326
if (err)
12231327
goto failed;
@@ -1272,7 +1376,7 @@ eth_hn_dev_uninit(struct rte_eth_dev *eth_dev)
12721376

12731377
hn_detach(hv);
12741378
hn_chim_uninit(eth_dev);
1275-
rte_vmbus_chan_close(hv->primary->chan);
1379+
rte_vmbus_chan_close(hv->channels[0]);
12761380
rte_free(hv->primary);
12771381
ret = rte_eth_dev_owner_delete(hv->owner.id);
12781382
if (ret != 0)

drivers/net/netvsc/hn_rndis.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,13 @@ hn_rndis_get_eaddr(struct hn_data *hv, uint8_t *eaddr)
11111111
return 0;
11121112
}
11131113

1114+
int
1115+
hn_rndis_get_mtu(struct hn_data *hv, uint32_t *mtu)
1116+
{
1117+
return hn_rndis_query(hv, OID_GEN_MAXIMUM_FRAME_SIZE, NULL, 0,
1118+
mtu, sizeof(uint32_t));
1119+
}
1120+
11141121
int
11151122
hn_rndis_get_linkstatus(struct hn_data *hv)
11161123
{

drivers/net/netvsc/hn_rndis.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ void hn_rndis_link_status(struct rte_eth_dev *dev, const void *msg);
1010
int hn_rndis_attach(struct hn_data *hv);
1111
void hn_rndis_detach(struct hn_data *hv);
1212
int hn_rndis_get_eaddr(struct hn_data *hv, uint8_t *eaddr);
13+
int hn_rndis_get_mtu(struct hn_data *hv, uint32_t *mtu);
1314
int hn_rndis_get_linkstatus(struct hn_data *hv);
1415
int hn_rndis_get_linkspeed(struct hn_data *hv);
1516
int hn_rndis_set_rxfilter(struct hn_data *hv, uint32_t filter);

drivers/net/netvsc/hn_var.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Tunable ethdev params
1414
*/
1515
#define HN_MIN_RX_BUF_SIZE 1024
16-
#define HN_MAX_XFER_LEN 2048
16+
#define HN_MAX_XFER_LEN RTE_ETHER_MAX_JUMBO_FRAME_LEN
1717
#define HN_MAX_MAC_ADDRS 1
1818
#define HN_MAX_CHANNELS 64
1919

0 commit comments

Comments
 (0)