dpdk: ENA PMD patch for failure on port restart
[vpp.git] / build / external / patches / dpdk_18.08 / 0005-net-ena-recreate-HW-IO-rings-on-start-and-stop.patch
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
5
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.
9
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
12 descriptors.
13
14 Furthermore, there was also memory leak for the Rx mbufs, which were
15 created on start and not destroyed on stop.
16
17 Change-Id: I01dfd036d0bff517e42e35257481de4983679763
18 ---
19  drivers/net/ena/ena_ethdev.c | 196 ++++++++++++++++++++-----------------------
20  1 file changed, 91 insertions(+), 105 deletions(-)
21
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);
38  
39 -       ena_stop(dev);
40 +       if (adapter->state == ENA_ADAPTER_STATE_RUNNING)
41 +               ena_stop(dev);
42         adapter->state = ENA_ADAPTER_STATE_CLOSED;
43  
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)
47  {
48         struct ena_ring *ring = (struct ena_ring *)queue;
49 -       struct ena_adapter *adapter = ring->adapter;
50 -       int ena_qid;
51  
52         ena_assert_msg(ring->configured,
53                        "API violation - releasing not configured queue");
54         ena_assert_msg(ring->adapter->state != ENA_ADAPTER_STATE_RUNNING,
55                        "API violation");
56  
57 -       /* Destroy HW queue */
58 -       ena_qid = ENA_IO_RXQ_IDX(ring->id);
59 -       ena_com_destroy_io_queue(&adapter->ena_dev, ena_qid);
60 -
61 -       /* Free all bufs */
62 -       ena_rx_queue_release_bufs(ring);
63 -
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)
69  {
70         struct ena_ring *ring = (struct ena_ring *)queue;
71 -       struct ena_adapter *adapter = ring->adapter;
72 -       int ena_qid;
73  
74         ena_assert_msg(ring->configured,
75                        "API violation. Releasing not configured queue");
76         ena_assert_msg(ring->adapter->state != ENA_ADAPTER_STATE_RUNNING,
77                        "API violation");
78  
79 -       /* Destroy HW queue */
80 -       ena_qid = ENA_IO_TXQ_IDX(ring->id);
81 -       ena_com_destroy_io_queue(&adapter->ena_dev, ena_qid);
82 -
83         /* Free all bufs */
84         ena_tx_queue_release_bufs(ring);
85  
86 @@ -1078,10 +1066,86 @@ static void ena_stop(struct rte_eth_dev *dev)
87                 (struct ena_adapter *)(dev->data->dev_private);
88  
89         rte_timer_stop_sync(&adapter->timer_wd);
90 +       ena_free_io_queues_all(adapter);
91  
92         adapter->state = ENA_ADAPTER_STATE_STOPPED;
93  }
94  
95 +static int ena_create_io_queue(struct ena_ring *ring)
96 +{
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,
102 +                 0, 0, 0, 0, 0 };
103 +       uint16_t ena_qid;
104 +       int rc;
105 +
106 +       adapter = ring->adapter;
107 +       ena_dev = &adapter->ena_dev;
108 +
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;
114 +       } else {
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;
118 +       }
119 +       ctx.qid = ena_qid;
120 +       ctx.msix_vector = -1; /* interrupts not used */
121 +       ctx.numa_node = ena_cpu_to_node(ring->id);
122 +
123 +       rc = ena_com_create_io_queue(ena_dev, &ctx);
124 +       if (rc) {
125 +               RTE_LOG(ERR, PMD,
126 +                       "failed to create io queue #%d (qid:%d) rc: %d\n",
127 +                       ring->id, ena_qid, rc);
128 +               return rc;
129 +       }
130 +
131 +       rc = ena_com_get_io_handlers(ena_dev, ena_qid,
132 +                                    &ring->ena_com_io_sq,
133 +                                    &ring->ena_com_io_cq);
134 +       if (rc) {
135 +               RTE_LOG(ERR, PMD,
136 +                       "Failed to get io queue handlers. queue num %d rc: %d\n",
137 +                       ring->id, rc);
138 +               ena_com_destroy_io_queue(ena_dev, ena_qid);
139 +               return rc;
140 +       }
141 +
142 +       if (ring->type == ENA_RING_TYPE_TX)
143 +               ena_com_update_numa_node(ring->ena_com_io_cq, ctx.numa_node);
144 +
145 +       return 0;
146 +}
147 +
148 +static void ena_free_io_queues_all(struct ena_adapter *adapter)
149 +{
150 +       struct rte_eth_dev *eth_dev = adapter->rte_dev;
151 +       struct ena_com_dev *ena_dev = &adapter->ena_dev;
152 +       int i;
153 +       uint16_t ena_qid;
154 +       uint16_t nb_rxq = eth_dev->data->nb_rx_queues;
155 +       uint16_t nb_txq = eth_dev->data->nb_tx_queues;
156 +
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);
160 +       }
161 +
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);
165 +
166 +               ena_rx_queue_release_bufs(&adapter->rx_ring[i]);
167 +       }
168 +}
169 +
170  static int ena_queue_restart(struct ena_ring *ring)
171  {
172         int rc, bufs_num;
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");
176  
177 +       rc = ena_create_io_queue(ring);
178 +       if (rc) {
179 +               PMD_INIT_LOG(ERR, "Failed to create IO queue!\n");
180 +               return rc;
181 +       }
182 +
183         ring->next_to_clean = 0;
184         ring->next_to_use = 0;
185  
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)
189  {
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);
197         unsigned int i;
198 -       int ena_qid;
199 -       int rc;
200 -       struct ena_com_dev *ena_dev = &adapter->ena_dev;
201  
202         txq = &adapter->tx_ring[queue_idx];
203  
204 @@ -1146,37 +1209,6 @@ static int ena_tx_queue_setup(struct rte_eth_dev *dev,
205                 return -EINVAL;
206         }
207  
208 -       ena_qid = ENA_IO_TXQ_IDX(queue_idx);
209 -
210 -       ctx.direction = ENA_COM_IO_QUEUE_DIRECTION_TX;
211 -       ctx.qid = ena_qid;
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);
216 -
217 -       rc = ena_com_create_io_queue(ena_dev, &ctx);
218 -       if (rc) {
219 -               RTE_LOG(ERR, PMD,
220 -                       "failed to create io TX queue #%d (qid:%d) rc: %d\n",
221 -                       queue_idx, ena_qid, rc);
222 -               return rc;
223 -       }
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];
226 -
227 -       rc = ena_com_get_io_handlers(ena_dev, ena_qid,
228 -                                    &txq->ena_com_io_sq,
229 -                                    &txq->ena_com_io_cq);
230 -       if (rc) {
231 -               RTE_LOG(ERR, PMD,
232 -                       "Failed to get TX queue handlers. TX queue num %d rc: %d\n",
233 -                       queue_idx, rc);
234 -               goto err_destroy_io_queue;
235 -       }
236 -
237 -       ena_com_update_numa_node(txq->ena_com_io_cq, ctx.numa_node);
238 -
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");
246 -               rc = -ENOMEM;
247 -               goto err_destroy_io_queue;
248 +               return -ENOMEM;
249         }
250  
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");
256 -               rc = -ENOMEM;
257 -               goto err_free;
258 +               rte_free(txq->tx_buffer_info);
259 +               return -ENOMEM;
260         }
261  
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;
265  
266         return 0;
267 -
268 -err_free:
269 -       rte_free(txq->tx_buffer_info);
270 -
271 -err_destroy_io_queue:
272 -       ena_com_destroy_io_queue(ena_dev, ena_qid);
273 -       return rc;
274  }
275  
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)
280  {
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;
289 -       int i, rc = 0;
290 -       struct ena_com_dev *ena_dev = &adapter->ena_dev;
291 +       int i;
292  
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,
296                 return -EINVAL;
297         }
298  
299 -       ena_qid = ENA_IO_RXQ_IDX(queue_idx);
300 -
301 -       ctx.qid = ena_qid;
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);
307 -
308 -       rc = ena_com_create_io_queue(ena_dev, &ctx);
309 -       if (rc) {
310 -               RTE_LOG(ERR, PMD, "failed to create io RX queue #%d rc: %d\n",
311 -                       queue_idx, rc);
312 -               return rc;
313 -       }
314 -
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];
317 -
318 -       rc = ena_com_get_io_handlers(ena_dev, ena_qid,
319 -                                    &rxq->ena_com_io_sq,
320 -                                    &rxq->ena_com_io_cq);
321 -       if (rc) {
322 -               RTE_LOG(ERR, PMD,
323 -                       "Failed to get RX queue handlers. RX queue num %d rc: %d\n",
324 -                       queue_idx, rc);
325 -               ena_com_destroy_io_queue(ena_dev, ena_qid);
326 -               return rc;
327 -       }
328 -
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);
337                 return -ENOMEM;
338         }
339  
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);
345                 return -ENOMEM;
346         }
347  
348 @@ -1326,7 +1312,7 @@ static int ena_rx_queue_setup(struct rte_eth_dev *dev,
349         rxq->configured = 1;
350         dev->data->rx_queues[queue_idx] = rxq;
351  
352 -       return rc;
353 +       return 0;
354  }
355  
356  static int ena_populate_rx_queue(struct ena_ring *rxq, unsigned int count)
357 -- 
358 2.7.4
359