1 From 792dd52ca1a513fc16ee56b789c7e3177cb782f7 Mon Sep 17 00:00:00 2001
2 From: Michal Krawczyk <mk@semihalf.com>
3 Date: Wed, 24 Oct 2018 11:37:17 +0200
4 Subject: [PATCH] net/ena: recreate HW IO rings on start and stop
6 On the start the driver was refilling all Rx buffs, but the old ones
7 were not released. That way running start/stop for a few times was
8 causing device to run out of descriptors.
10 To fix the issue, IO rings are now being destroyed on stop, and
11 recreated on start. That is way the device is not losing any
14 Furthermore, there was also memory leak for the Rx mbufs, which were
15 created on start and not destroyed on stop.
17 Change-Id: I01dfd036d0bff517e42e35257481de4983679763
19 drivers/net/ena/ena_ethdev.c | 196 ++++++++++++++++++++-----------------------
20 1 file changed, 91 insertions(+), 105 deletions(-)
22 diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c
23 index c255dc6..de5d2ed 100644
24 --- a/drivers/net/ena/ena_ethdev.c
25 +++ b/drivers/net/ena/ena_ethdev.c
26 @@ -239,6 +239,8 @@ static void ena_rx_queue_release_bufs(struct ena_ring *ring);
27 static void ena_tx_queue_release_bufs(struct ena_ring *ring);
28 static int ena_link_update(struct rte_eth_dev *dev,
29 int wait_to_complete);
30 +static int ena_create_io_queue(struct ena_ring *ring);
31 +static void ena_free_io_queues_all(struct ena_adapter *adapter);
32 static int ena_queue_restart(struct ena_ring *ring);
33 static int ena_queue_restart_all(struct rte_eth_dev *dev,
34 enum ena_ring_type ring_type);
35 @@ -510,7 +512,8 @@ static void ena_close(struct rte_eth_dev *dev)
36 struct ena_adapter *adapter =
37 (struct ena_adapter *)(dev->data->dev_private);
40 + if (adapter->state == ENA_ADAPTER_STATE_RUNNING)
42 adapter->state = ENA_ADAPTER_STATE_CLOSED;
44 ena_rx_queue_release_all(dev);
45 @@ -746,21 +749,12 @@ static void ena_tx_queue_release_all(struct rte_eth_dev *dev)
46 static void ena_rx_queue_release(void *queue)
48 struct ena_ring *ring = (struct ena_ring *)queue;
49 - struct ena_adapter *adapter = ring->adapter;
52 ena_assert_msg(ring->configured,
53 "API violation - releasing not configured queue");
54 ena_assert_msg(ring->adapter->state != ENA_ADAPTER_STATE_RUNNING,
57 - /* Destroy HW queue */
58 - ena_qid = ENA_IO_RXQ_IDX(ring->id);
59 - ena_com_destroy_io_queue(&adapter->ena_dev, ena_qid);
62 - ena_rx_queue_release_bufs(ring);
64 /* Free ring resources */
65 if (ring->rx_buffer_info)
66 rte_free(ring->rx_buffer_info);
67 @@ -779,18 +773,12 @@ static void ena_rx_queue_release(void *queue)
68 static void ena_tx_queue_release(void *queue)
70 struct ena_ring *ring = (struct ena_ring *)queue;
71 - struct ena_adapter *adapter = ring->adapter;
74 ena_assert_msg(ring->configured,
75 "API violation. Releasing not configured queue");
76 ena_assert_msg(ring->adapter->state != ENA_ADAPTER_STATE_RUNNING,
79 - /* Destroy HW queue */
80 - ena_qid = ENA_IO_TXQ_IDX(ring->id);
81 - ena_com_destroy_io_queue(&adapter->ena_dev, ena_qid);
84 ena_tx_queue_release_bufs(ring);
86 @@ -1078,10 +1066,86 @@ static void ena_stop(struct rte_eth_dev *dev)
87 (struct ena_adapter *)(dev->data->dev_private);
89 rte_timer_stop_sync(&adapter->timer_wd);
90 + ena_free_io_queues_all(adapter);
92 adapter->state = ENA_ADAPTER_STATE_STOPPED;
95 +static int ena_create_io_queue(struct ena_ring *ring)
97 + struct ena_adapter *adapter;
98 + struct ena_com_dev *ena_dev;
99 + struct ena_com_create_io_ctx ctx =
100 + /* policy set to _HOST just to satisfy icc compiler */
101 + { ENA_ADMIN_PLACEMENT_POLICY_HOST,
106 + adapter = ring->adapter;
107 + ena_dev = &adapter->ena_dev;
109 + if (ring->type == ENA_RING_TYPE_TX) {
110 + ena_qid = ENA_IO_TXQ_IDX(ring->id);
111 + ctx.direction = ENA_COM_IO_QUEUE_DIRECTION_TX;
112 + ctx.mem_queue_type = ena_dev->tx_mem_queue_type;
113 + ctx.queue_size = adapter->tx_ring_size;
115 + ena_qid = ENA_IO_RXQ_IDX(ring->id);
116 + ctx.direction = ENA_COM_IO_QUEUE_DIRECTION_RX;
117 + ctx.queue_size = adapter->rx_ring_size;
120 + ctx.msix_vector = -1; /* interrupts not used */
121 + ctx.numa_node = ena_cpu_to_node(ring->id);
123 + rc = ena_com_create_io_queue(ena_dev, &ctx);
126 + "failed to create io queue #%d (qid:%d) rc: %d\n",
127 + ring->id, ena_qid, rc);
131 + rc = ena_com_get_io_handlers(ena_dev, ena_qid,
132 + &ring->ena_com_io_sq,
133 + &ring->ena_com_io_cq);
136 + "Failed to get io queue handlers. queue num %d rc: %d\n",
138 + ena_com_destroy_io_queue(ena_dev, ena_qid);
142 + if (ring->type == ENA_RING_TYPE_TX)
143 + ena_com_update_numa_node(ring->ena_com_io_cq, ctx.numa_node);
148 +static void ena_free_io_queues_all(struct ena_adapter *adapter)
150 + struct rte_eth_dev *eth_dev = adapter->rte_dev;
151 + struct ena_com_dev *ena_dev = &adapter->ena_dev;
154 + uint16_t nb_rxq = eth_dev->data->nb_rx_queues;
155 + uint16_t nb_txq = eth_dev->data->nb_tx_queues;
157 + for (i = 0; i < nb_txq; ++i) {
158 + ena_qid = ENA_IO_TXQ_IDX(i);
159 + ena_com_destroy_io_queue(ena_dev, ena_qid);
162 + for (i = 0; i < nb_rxq; ++i) {
163 + ena_qid = ENA_IO_RXQ_IDX(i);
164 + ena_com_destroy_io_queue(ena_dev, ena_qid);
166 + ena_rx_queue_release_bufs(&adapter->rx_ring[i]);
170 static int ena_queue_restart(struct ena_ring *ring)
173 @@ -1089,6 +1153,12 @@ static int ena_queue_restart(struct ena_ring *ring)
174 ena_assert_msg(ring->configured == 1,
175 "Trying to restart unconfigured queue\n");
177 + rc = ena_create_io_queue(ring);
179 + PMD_INIT_LOG(ERR, "Failed to create IO queue!\n");
183 ring->next_to_clean = 0;
184 ring->next_to_use = 0;
186 @@ -1111,17 +1181,10 @@ static int ena_tx_queue_setup(struct rte_eth_dev *dev,
187 __rte_unused unsigned int socket_id,
188 const struct rte_eth_txconf *tx_conf)
190 - struct ena_com_create_io_ctx ctx =
191 - /* policy set to _HOST just to satisfy icc compiler */
192 - { ENA_ADMIN_PLACEMENT_POLICY_HOST,
193 - ENA_COM_IO_QUEUE_DIRECTION_TX, 0, 0, 0, 0 };
194 struct ena_ring *txq = NULL;
195 struct ena_adapter *adapter =
196 (struct ena_adapter *)(dev->data->dev_private);
200 - struct ena_com_dev *ena_dev = &adapter->ena_dev;
202 txq = &adapter->tx_ring[queue_idx];
204 @@ -1146,37 +1209,6 @@ static int ena_tx_queue_setup(struct rte_eth_dev *dev,
208 - ena_qid = ENA_IO_TXQ_IDX(queue_idx);
210 - ctx.direction = ENA_COM_IO_QUEUE_DIRECTION_TX;
212 - ctx.msix_vector = -1; /* admin interrupts not used */
213 - ctx.mem_queue_type = ena_dev->tx_mem_queue_type;
214 - ctx.queue_size = adapter->tx_ring_size;
215 - ctx.numa_node = ena_cpu_to_node(queue_idx);
217 - rc = ena_com_create_io_queue(ena_dev, &ctx);
220 - "failed to create io TX queue #%d (qid:%d) rc: %d\n",
221 - queue_idx, ena_qid, rc);
224 - txq->ena_com_io_cq = &ena_dev->io_cq_queues[ena_qid];
225 - txq->ena_com_io_sq = &ena_dev->io_sq_queues[ena_qid];
227 - rc = ena_com_get_io_handlers(ena_dev, ena_qid,
228 - &txq->ena_com_io_sq,
229 - &txq->ena_com_io_cq);
232 - "Failed to get TX queue handlers. TX queue num %d rc: %d\n",
234 - goto err_destroy_io_queue;
237 - ena_com_update_numa_node(txq->ena_com_io_cq, ctx.numa_node);
239 txq->port_id = dev->data->port_id;
240 txq->next_to_clean = 0;
241 txq->next_to_use = 0;
242 @@ -1188,8 +1220,7 @@ static int ena_tx_queue_setup(struct rte_eth_dev *dev,
243 RTE_CACHE_LINE_SIZE);
244 if (!txq->tx_buffer_info) {
245 RTE_LOG(ERR, PMD, "failed to alloc mem for tx buffer info\n");
247 - goto err_destroy_io_queue;
251 txq->empty_tx_reqs = rte_zmalloc("txq->empty_tx_reqs",
252 @@ -1197,8 +1228,8 @@ static int ena_tx_queue_setup(struct rte_eth_dev *dev,
253 RTE_CACHE_LINE_SIZE);
254 if (!txq->empty_tx_reqs) {
255 RTE_LOG(ERR, PMD, "failed to alloc mem for tx reqs\n");
258 + rte_free(txq->tx_buffer_info);
262 for (i = 0; i < txq->ring_size; i++)
263 @@ -1214,13 +1245,6 @@ static int ena_tx_queue_setup(struct rte_eth_dev *dev,
264 dev->data->tx_queues[queue_idx] = txq;
269 - rte_free(txq->tx_buffer_info);
271 -err_destroy_io_queue:
272 - ena_com_destroy_io_queue(ena_dev, ena_qid);
276 static int ena_rx_queue_setup(struct rte_eth_dev *dev,
277 @@ -1230,16 +1254,10 @@ static int ena_rx_queue_setup(struct rte_eth_dev *dev,
278 __rte_unused const struct rte_eth_rxconf *rx_conf,
279 struct rte_mempool *mp)
281 - struct ena_com_create_io_ctx ctx =
282 - /* policy set to _HOST just to satisfy icc compiler */
283 - { ENA_ADMIN_PLACEMENT_POLICY_HOST,
284 - ENA_COM_IO_QUEUE_DIRECTION_RX, 0, 0, 0, 0 };
285 struct ena_adapter *adapter =
286 (struct ena_adapter *)(dev->data->dev_private);
287 struct ena_ring *rxq = NULL;
288 - uint16_t ena_qid = 0;
290 - struct ena_com_dev *ena_dev = &adapter->ena_dev;
293 rxq = &adapter->rx_ring[queue_idx];
294 if (rxq->configured) {
295 @@ -1263,36 +1281,6 @@ static int ena_rx_queue_setup(struct rte_eth_dev *dev,
299 - ena_qid = ENA_IO_RXQ_IDX(queue_idx);
302 - ctx.direction = ENA_COM_IO_QUEUE_DIRECTION_RX;
303 - ctx.mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_HOST;
304 - ctx.msix_vector = -1; /* admin interrupts not used */
305 - ctx.queue_size = adapter->rx_ring_size;
306 - ctx.numa_node = ena_cpu_to_node(queue_idx);
308 - rc = ena_com_create_io_queue(ena_dev, &ctx);
310 - RTE_LOG(ERR, PMD, "failed to create io RX queue #%d rc: %d\n",
315 - rxq->ena_com_io_cq = &ena_dev->io_cq_queues[ena_qid];
316 - rxq->ena_com_io_sq = &ena_dev->io_sq_queues[ena_qid];
318 - rc = ena_com_get_io_handlers(ena_dev, ena_qid,
319 - &rxq->ena_com_io_sq,
320 - &rxq->ena_com_io_cq);
323 - "Failed to get RX queue handlers. RX queue num %d rc: %d\n",
325 - ena_com_destroy_io_queue(ena_dev, ena_qid);
329 rxq->port_id = dev->data->port_id;
330 rxq->next_to_clean = 0;
331 rxq->next_to_use = 0;
332 @@ -1304,7 +1292,6 @@ static int ena_rx_queue_setup(struct rte_eth_dev *dev,
333 RTE_CACHE_LINE_SIZE);
334 if (!rxq->rx_buffer_info) {
335 RTE_LOG(ERR, PMD, "failed to alloc mem for rx buffer info\n");
336 - ena_com_destroy_io_queue(ena_dev, ena_qid);
340 @@ -1315,7 +1302,6 @@ static int ena_rx_queue_setup(struct rte_eth_dev *dev,
341 RTE_LOG(ERR, PMD, "failed to alloc mem for empty rx reqs\n");
342 rte_free(rxq->rx_buffer_info);
343 rxq->rx_buffer_info = NULL;
344 - ena_com_destroy_io_queue(ena_dev, ena_qid);
348 @@ -1326,7 +1312,7 @@ static int ena_rx_queue_setup(struct rte_eth_dev *dev,
350 dev->data->rx_queues[queue_idx] = rxq;
356 static int ena_populate_rx_queue(struct ena_ring *rxq, unsigned int count)