-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add set mtu device operation to netvsc #68
base: main
Are you sure you want to change the base?
Changes from 4 commits
423d932
5f2675d
b590c76
96c5772
16da2e8
2f6584f
b8cbd69
d64b9ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1059,37 +1059,6 @@ hn_dev_close(struct rte_eth_dev *dev) | |
return ret; | ||
} | ||
|
||
static const struct eth_dev_ops hn_eth_dev_ops = { | ||
.dev_configure = hn_dev_configure, | ||
.dev_start = hn_dev_start, | ||
.dev_stop = hn_dev_stop, | ||
.dev_close = hn_dev_close, | ||
.dev_infos_get = hn_dev_info_get, | ||
.txq_info_get = hn_dev_tx_queue_info, | ||
.rxq_info_get = hn_dev_rx_queue_info, | ||
.dev_supported_ptypes_get = hn_vf_supported_ptypes, | ||
.promiscuous_enable = hn_dev_promiscuous_enable, | ||
.promiscuous_disable = hn_dev_promiscuous_disable, | ||
.allmulticast_enable = hn_dev_allmulticast_enable, | ||
.allmulticast_disable = hn_dev_allmulticast_disable, | ||
.set_mc_addr_list = hn_dev_mc_addr_list, | ||
.reta_update = hn_rss_reta_update, | ||
.reta_query = hn_rss_reta_query, | ||
.rss_hash_update = hn_rss_hash_update, | ||
.rss_hash_conf_get = hn_rss_hash_conf_get, | ||
.tx_queue_setup = hn_dev_tx_queue_setup, | ||
.tx_queue_release = hn_dev_tx_queue_release, | ||
.tx_done_cleanup = hn_dev_tx_done_cleanup, | ||
.rx_queue_setup = hn_dev_rx_queue_setup, | ||
.rx_queue_release = hn_dev_rx_queue_release, | ||
.link_update = hn_dev_link_update, | ||
.stats_get = hn_dev_stats_get, | ||
.stats_reset = hn_dev_stats_reset, | ||
.xstats_get = hn_dev_xstats_get, | ||
.xstats_get_names = hn_dev_xstats_get_names, | ||
.xstats_reset = hn_dev_xstats_reset, | ||
}; | ||
|
||
/* | ||
* Setup connection between PMD and kernel. | ||
*/ | ||
|
@@ -1129,12 +1098,146 @@ hn_detach(struct hn_data *hv) | |
hn_rndis_detach(hv); | ||
} | ||
|
||
static int | ||
hn_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) | ||
{ | ||
struct hn_data *hv = dev->data->dev_private; | ||
struct hn_rx_queue **rxqs = (struct hn_rx_queue **)dev->data->rx_queues; | ||
struct hn_tx_queue **txqs = (struct hn_tx_queue **)dev->data->tx_queues; | ||
struct rte_eth_dev *vf_dev; | ||
unsigned int orig_mtu = dev->data->mtu; | ||
uint32_t rndis_mtu; | ||
int ret = 0; | ||
int i; | ||
|
||
if (dev->data->dev_started) { | ||
PMD_DRV_LOG(ERR, "Device must be stopped before changing MTU"); | ||
return -EIO; | ||
} | ||
|
||
/* Change MTU of underlying VF netdev first, if it exists */ | ||
rte_rwlock_read_lock(&hv->vf_lock); | ||
vf_dev = hn_get_vf_dev(hv); | ||
if (hv->vf_ctx.vf_vsc_switched && vf_dev) { | ||
ret = vf_dev->dev_ops->mtu_set(vf_dev, mtu); | ||
if (ret) { | ||
rte_rwlock_read_unlock(&hv->vf_lock); | ||
goto out; | ||
} | ||
} | ||
rte_rwlock_read_unlock(&hv->vf_lock); | ||
|
||
/* Release channel resources */ | ||
hn_detach(hv); | ||
|
||
/* Close vmbus channels */ | ||
for (i = 0; i < hv->num_queues; i++) | ||
rte_vmbus_chan_close(hv->channels[i]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to deal separately with the primary channel, as rte_vmbus_chan_close() doesn't delete it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is currently used in 3 other places: in 2 of those 3, it is directly passed the primary channel. That makes it a no-op in those cases as well as the 0 index case here, as you point out. I could either (1) just call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ended up just calling |
||
|
||
/* Unmap and re-map vmbus device */ | ||
rte_vmbus_unmap_device(hv->vmbus); | ||
ret = rte_vmbus_map_device(hv->vmbus); | ||
if (ret) { | ||
/* This is a catastrophic error - the device is unusable */ | ||
PMD_DRV_LOG(ERR, "Could not re-map vmbus device!"); | ||
return ret; | ||
} | ||
|
||
/* Update pointers to re-mapped UIO resources */ | ||
hv->rxbuf_res = hv->vmbus->resource[HV_RECV_BUF_MAP]; | ||
hv->chim_res = hv->vmbus->resource[HV_SEND_BUF_MAP]; | ||
|
||
/* Re-open the vmbus channel */ | ||
ret = rte_vmbus_chan_open(hv->vmbus, &hv->channels[0]); | ||
if (ret) { | ||
/* This is a catastrophic error - the device is unusable */ | ||
PMD_DRV_LOG(ERR, "Could not re-open vmbus channel!"); | ||
} | ||
|
||
rte_vmbus_set_latency(hv->vmbus, hv->channels[0], hv->latency); | ||
|
||
/* Point primary queues at new primary channel */ | ||
rxqs[0]->chan = hv->channels[0]; | ||
txqs[0]->chan = hv->channels[0]; | ||
|
||
ret = hn_attach(hv, mtu); | ||
if (ret) | ||
goto error; | ||
|
||
/* Create vmbus subchannels, additional RNDIS configuration */ | ||
ret = hn_dev_configure(dev); | ||
if (ret) | ||
goto error; | ||
|
||
/* Point any additional queues at new subchannels */ | ||
for (i = 1; i < dev->data->nb_rx_queues; i++) | ||
rxqs[i]->chan = hv->channels[i]; | ||
for (i = 1; i < dev->data->nb_tx_queues; i++) | ||
txqs[i]->chan = hv->channels[i]; | ||
|
||
out: | ||
if (hn_rndis_get_mtu(hv, &rndis_mtu)) | ||
PMD_DRV_LOG(ERR, "Could not get MTU via RNDIS"); | ||
else { | ||
dev->data->mtu = (uint16_t)rndis_mtu; | ||
PMD_DRV_LOG(DEBUG, "RNDIS MTU is %u", dev->data->mtu); | ||
} | ||
|
||
return ret; | ||
|
||
error: | ||
/* In case of error, attempt to restore original MTU */ | ||
if (hn_attach(hv, orig_mtu)) | ||
PMD_DRV_LOG(ERR, "Restoring original MTU failed"); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case of error, need to restore all subchannels on original mtu There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've refactored this so all subchannels would be restored if we are attempting to rollback to the original MTU. |
||
rte_rwlock_read_lock(&hv->vf_lock); | ||
vf_dev = hn_get_vf_dev(hv); | ||
if (hv->vf_ctx.vf_vsc_switched && vf_dev) | ||
vf_dev->dev_ops->mtu_set(vf_dev, orig_mtu); | ||
rte_rwlock_read_unlock(&hv->vf_lock); | ||
|
||
return ret; | ||
} | ||
|
||
static const struct eth_dev_ops hn_eth_dev_ops = { | ||
.dev_configure = hn_dev_configure, | ||
.dev_start = hn_dev_start, | ||
.dev_stop = hn_dev_stop, | ||
.dev_close = hn_dev_close, | ||
.dev_infos_get = hn_dev_info_get, | ||
.txq_info_get = hn_dev_tx_queue_info, | ||
.rxq_info_get = hn_dev_rx_queue_info, | ||
.dev_supported_ptypes_get = hn_vf_supported_ptypes, | ||
.promiscuous_enable = hn_dev_promiscuous_enable, | ||
.promiscuous_disable = hn_dev_promiscuous_disable, | ||
.allmulticast_enable = hn_dev_allmulticast_enable, | ||
.allmulticast_disable = hn_dev_allmulticast_disable, | ||
.set_mc_addr_list = hn_dev_mc_addr_list, | ||
.mtu_set = hn_dev_mtu_set, | ||
.reta_update = hn_rss_reta_update, | ||
.reta_query = hn_rss_reta_query, | ||
.rss_hash_update = hn_rss_hash_update, | ||
.rss_hash_conf_get = hn_rss_hash_conf_get, | ||
.tx_queue_setup = hn_dev_tx_queue_setup, | ||
.tx_queue_release = hn_dev_tx_queue_release, | ||
.tx_done_cleanup = hn_dev_tx_done_cleanup, | ||
.rx_queue_setup = hn_dev_rx_queue_setup, | ||
.rx_queue_release = hn_dev_rx_queue_release, | ||
.link_update = hn_dev_link_update, | ||
.stats_get = hn_dev_stats_get, | ||
.stats_reset = hn_dev_stats_reset, | ||
.xstats_get = hn_dev_xstats_get, | ||
.xstats_get_names = hn_dev_xstats_get_names, | ||
.xstats_reset = hn_dev_xstats_reset, | ||
}; | ||
|
||
static int | ||
eth_hn_dev_init(struct rte_eth_dev *eth_dev) | ||
{ | ||
struct hn_data *hv = eth_dev->data->dev_private; | ||
struct rte_device *device = eth_dev->device; | ||
struct rte_vmbus_device *vmbus; | ||
uint32_t mtu; | ||
unsigned int rxr_cnt; | ||
int err, max_chan; | ||
|
||
|
@@ -1218,6 +1321,12 @@ eth_hn_dev_init(struct rte_eth_dev *eth_dev) | |
if (err) | ||
goto failed; | ||
|
||
err = hn_rndis_get_mtu(hv, &mtu); | ||
if (err) | ||
goto failed; | ||
eth_dev->data->mtu = (uint16_t)mtu; | ||
PMD_INIT_LOG(DEBUG, "RNDIS MTU is %u", eth_dev->data->mtu); | ||
|
||
err = hn_rndis_get_eaddr(hv, eth_dev->data->mac_addrs->addr_bytes); | ||
if (err) | ||
goto failed; | ||
|
@@ -1272,7 +1381,7 @@ eth_hn_dev_uninit(struct rte_eth_dev *eth_dev) | |
|
||
hn_detach(hv); | ||
hn_chim_uninit(eth_dev); | ||
rte_vmbus_chan_close(hv->primary->chan); | ||
rte_vmbus_chan_close(hv->channels[0]); | ||
rte_free(hv->primary); | ||
ret = rte_eth_dev_owner_delete(hv->owner.id); | ||
if (ret != 0) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A VF device can be hot added or removed. Look at hn_vf_add() on setting the mtu if VF is hot added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added code to set the VF MTU on a hot add.