@@ -951,6 +951,7 @@ eth_hn_dev_init(struct rte_eth_dev *eth_dev)
hv->latency = HN_CHAN_LATENCY_NS;
hv->max_queues = 1;
rte_spinlock_init(&hv->vf_lock);
+ rte_spinlock_init(&hv->nvs_lock);
hv->vf_port = HN_INVALID_PORT;
err = hn_parse_args(eth_dev);
@@ -54,7 +54,7 @@ static int hn_nvs_req_send(struct hn_data *hv,
}
static int
-hn_nvs_execute(struct hn_data *hv,
+__hn_nvs_execute(struct hn_data *hv,
void *req, uint32_t reqlen,
void *resp, uint32_t resplen,
uint32_t type)
@@ -62,6 +62,7 @@ hn_nvs_execute(struct hn_data *hv,
struct vmbus_channel *chan = hn_primary_chan(hv);
char buffer[NVS_RESPSIZE_MAX];
const struct hn_nvs_hdr *hdr;
+ uint64_t xactid;
uint32_t len;
int ret;
@@ -77,7 +78,7 @@ hn_nvs_execute(struct hn_data *hv,
retry:
len = sizeof(buffer);
- ret = rte_vmbus_chan_recv(chan, buffer, &len, NULL);
+ ret = rte_vmbus_chan_recv(chan, buffer, &len, &xactid);
if (ret == -EAGAIN) {
rte_delay_us(HN_CHAN_INTERVAL_US);
goto retry;
@@ -88,7 +89,20 @@ hn_nvs_execute(struct hn_data *hv,
return ret;
}
+ if (len < sizeof(*hdr)) {
+ PMD_DRV_LOG(ERR, "response missing NVS header");
+ return -EINVAL;
+ }
+
hdr = (struct hn_nvs_hdr *)buffer;
+
+ /* Silently drop received packets while waiting for response */
+ if (hdr->type == NVS_TYPE_RNDIS) {
+ hn_nvs_ack_rxbuf(chan, xactid);
+ --hv->rxbuf_outstanding;
+ goto retry;
+ }
+
if (hdr->type != type) {
PMD_DRV_LOG(ERR, "unexpected NVS resp %#x, expect %#x",
hdr->type, type);
@@ -108,6 +122,28 @@ hn_nvs_execute(struct hn_data *hv,
return 0;
}
+
+/*
+ * Execute one control command and get the response.
+ * Only one command can be active on a channel at once
+ * Unlike BSD, DPDK does not have an interrupt context
+ * so the polling is required to wait for response.
+ */
+static int
+hn_nvs_execute(struct hn_data *hv,
+ void *req, uint32_t reqlen,
+ void *resp, uint32_t resplen,
+ uint32_t type)
+{
+ int ret;
+
+ rte_spinlock_lock(&hv->nvs_lock);
+ ret = __hn_nvs_execute(hv, req, reqlen, resp, resplen, type);
+ rte_spinlock_unlock(&hv->nvs_lock);
+
+ return ret;
+}
+
static int
hn_nvs_doinit(struct hn_data *hv, uint32_t nvs_ver)
{
@@ -97,6 +97,7 @@ struct hn_data {
struct rte_vmbus_device *vmbus;
struct hn_rx_queue *primary;
rte_spinlock_t vf_lock;
+ rte_spinlock_t nvs_lock;
uint16_t port_id;
uint16_t vf_port;