Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2018-2022 Advanced Micro Devices, Inc.
3 : : */
4 : :
5 : : #include <rte_malloc.h>
6 : : #include <ethdev_driver.h>
7 : :
8 : : #include "ionic.h"
9 : : #include "ionic_logs.h"
10 : : #include "ionic_lif.h"
11 : : #include "ionic_ethdev.h"
12 : : #include "ionic_rx_filter.h"
13 : : #include "ionic_rxtx.h"
14 : :
15 : : /* queuetype support level */
16 : : static const uint8_t ionic_qtype_vers[IONIC_QTYPE_MAX] = {
17 : : [IONIC_QTYPE_ADMINQ] = 0, /* 0 = Base version with CQ support */
18 : : [IONIC_QTYPE_NOTIFYQ] = 0, /* 0 = Base version */
19 : : [IONIC_QTYPE_RXQ] = 2, /* 0 = Base version with CQ+SG support
20 : : * 1 = ... with EQ
21 : : * 2 = ... with CMB
22 : : */
23 : : [IONIC_QTYPE_TXQ] = 3, /* 0 = Base version with CQ+SG support
24 : : * 1 = ... with Tx SG version 1
25 : : * 2 = ... with EQ
26 : : * 3 = ... with CMB
27 : : */
28 : : };
29 : :
30 : : static int ionic_lif_addr_add(struct ionic_lif *lif, const uint8_t *addr);
31 : : static int ionic_lif_addr_del(struct ionic_lif *lif, const uint8_t *addr);
32 : :
33 : : static int
34 : 0 : ionic_qcq_disable_nowait(struct ionic_qcq *qcq,
35 : : struct ionic_admin_ctx *ctx)
36 : : {
37 : : int err;
38 : :
39 : : struct ionic_queue *q = &qcq->q;
40 : 0 : struct ionic_lif *lif = qcq->lif;
41 : :
42 : 0 : *ctx = (struct ionic_admin_ctx) {
43 : : .pending_work = true,
44 : : .cmd.q_control = {
45 : : .opcode = IONIC_CMD_Q_CONTROL,
46 : 0 : .type = q->type,
47 : 0 : .index = rte_cpu_to_le_32(q->index),
48 : : .oper = IONIC_Q_DISABLE,
49 : : },
50 : : };
51 : :
52 : : /* Does not wait for command completion */
53 : 0 : err = ionic_adminq_post(lif, ctx);
54 [ # # ]: 0 : if (err)
55 : 0 : ctx->pending_work = false;
56 : 0 : return err;
57 : : }
58 : :
59 : : void
60 : 0 : ionic_lif_stop(struct ionic_lif *lif)
61 : : {
62 : 0 : struct rte_eth_dev *dev = lif->eth_dev;
63 : : uint32_t i, j, chunk;
64 : :
65 : 0 : IONIC_PRINT_CALL();
66 : :
67 : 0 : lif->state &= ~IONIC_LIF_F_UP;
68 : :
69 : 0 : chunk = ionic_adminq_space_avail(lif);
70 : :
71 [ # # ]: 0 : for (i = 0; i < lif->nrxqcqs; i += chunk) {
72 [ # # # # ]: 0 : for (j = 0; j < chunk && i + j < lif->nrxqcqs; j++)
73 : 0 : ionic_dev_rx_queue_stop_firsthalf(dev, i + j);
74 : :
75 [ # # # # ]: 0 : for (j = 0; j < chunk && i + j < lif->nrxqcqs; j++)
76 : 0 : ionic_dev_rx_queue_stop_secondhalf(dev, i + j);
77 : : }
78 : :
79 [ # # ]: 0 : for (i = 0; i < lif->ntxqcqs; i += chunk) {
80 [ # # # # ]: 0 : for (j = 0; j < chunk && i + j < lif->ntxqcqs; j++)
81 : 0 : ionic_dev_tx_queue_stop_firsthalf(dev, i + j);
82 : :
83 [ # # # # ]: 0 : for (j = 0; j < chunk && i + j < lif->ntxqcqs; j++)
84 : 0 : ionic_dev_tx_queue_stop_secondhalf(dev, i + j);
85 : : }
86 : 0 : }
87 : :
88 : : void
89 : 0 : ionic_lif_reset(struct ionic_lif *lif)
90 : : {
91 : 0 : struct ionic_dev *idev = &lif->adapter->idev;
92 : : int err;
93 : :
94 : 0 : IONIC_PRINT_CALL();
95 : :
96 : 0 : ionic_dev_cmd_lif_reset(idev);
97 : 0 : err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
98 [ # # ]: 0 : if (err)
99 : 0 : IONIC_PRINT(WARNING, "Failed to reset %s", lif->name);
100 : 0 : }
101 : :
102 : : static void
103 : 0 : ionic_lif_get_abs_stats(const struct ionic_lif *lif, struct rte_eth_stats *stats)
104 : : {
105 : 0 : struct ionic_lif_stats *ls = &lif->info->stats;
106 : : uint32_t i;
107 : 0 : uint32_t num_rx_q_counters = RTE_MIN(lif->nrxqcqs, (uint32_t)
108 : : RTE_ETHDEV_QUEUE_STAT_CNTRS);
109 : 0 : uint32_t num_tx_q_counters = RTE_MIN(lif->ntxqcqs, (uint32_t)
110 : : RTE_ETHDEV_QUEUE_STAT_CNTRS);
111 : :
112 : : memset(stats, 0, sizeof(*stats));
113 : :
114 : : if (ls == NULL) {
115 : : IONIC_PRINT(DEBUG, "Stats on port %u not yet initialized",
116 : : lif->port_id);
117 : : return;
118 : : }
119 : :
120 : : /* RX */
121 : :
122 : 0 : stats->ipackets = ls->rx_ucast_packets +
123 : 0 : ls->rx_mcast_packets +
124 : 0 : ls->rx_bcast_packets;
125 : :
126 : 0 : stats->ibytes = ls->rx_ucast_bytes +
127 : 0 : ls->rx_mcast_bytes +
128 : 0 : ls->rx_bcast_bytes;
129 : :
130 [ # # ]: 0 : for (i = 0; i < lif->nrxqcqs; i++) {
131 : 0 : struct ionic_rx_stats *rx_stats = &lif->rxqcqs[i]->stats;
132 : 0 : stats->ierrors +=
133 : 0 : rx_stats->bad_cq_status +
134 : 0 : rx_stats->bad_len;
135 : : }
136 : :
137 : 0 : stats->imissed +=
138 : 0 : ls->rx_ucast_drop_packets +
139 : 0 : ls->rx_mcast_drop_packets +
140 : 0 : ls->rx_bcast_drop_packets;
141 : :
142 : 0 : stats->ierrors +=
143 : 0 : ls->rx_dma_error +
144 : 0 : ls->rx_desc_fetch_error +
145 : 0 : ls->rx_desc_data_error;
146 : :
147 [ # # ]: 0 : for (i = 0; i < num_rx_q_counters; i++) {
148 : 0 : struct ionic_rx_stats *rx_stats = &lif->rxqcqs[i]->stats;
149 : 0 : stats->q_ipackets[i] = rx_stats->packets;
150 : 0 : stats->q_ibytes[i] = rx_stats->bytes;
151 : 0 : stats->q_errors[i] =
152 : 0 : rx_stats->bad_cq_status +
153 : 0 : rx_stats->bad_len;
154 : : }
155 : :
156 : : /* TX */
157 : :
158 : 0 : stats->opackets = ls->tx_ucast_packets +
159 : 0 : ls->tx_mcast_packets +
160 : 0 : ls->tx_bcast_packets;
161 : :
162 : 0 : stats->obytes = ls->tx_ucast_bytes +
163 : 0 : ls->tx_mcast_bytes +
164 : 0 : ls->tx_bcast_bytes;
165 : :
166 [ # # ]: 0 : for (i = 0; i < lif->ntxqcqs; i++) {
167 : 0 : struct ionic_tx_stats *tx_stats = &lif->txqcqs[i]->stats;
168 : 0 : stats->oerrors += tx_stats->drop;
169 : : }
170 : :
171 : 0 : stats->oerrors +=
172 : 0 : ls->tx_ucast_drop_packets +
173 : 0 : ls->tx_mcast_drop_packets +
174 : 0 : ls->tx_bcast_drop_packets;
175 : :
176 : 0 : stats->oerrors +=
177 : 0 : ls->tx_dma_error +
178 : 0 : ls->tx_queue_disabled +
179 : 0 : ls->tx_desc_fetch_error +
180 : 0 : ls->tx_desc_data_error;
181 : :
182 [ # # ]: 0 : for (i = 0; i < num_tx_q_counters; i++) {
183 : 0 : struct ionic_tx_stats *tx_stats = &lif->txqcqs[i]->stats;
184 : 0 : stats->q_opackets[i] = tx_stats->packets;
185 : 0 : stats->q_obytes[i] = tx_stats->bytes;
186 : : }
187 : : }
188 : :
189 : : void
190 : 0 : ionic_lif_get_stats(const struct ionic_lif *lif,
191 : : struct rte_eth_stats *stats)
192 : : {
193 : 0 : ionic_lif_get_abs_stats(lif, stats);
194 : :
195 : 0 : stats->ipackets -= lif->stats_base.ipackets;
196 : 0 : stats->opackets -= lif->stats_base.opackets;
197 : 0 : stats->ibytes -= lif->stats_base.ibytes;
198 : 0 : stats->obytes -= lif->stats_base.obytes;
199 : 0 : stats->imissed -= lif->stats_base.imissed;
200 : 0 : stats->ierrors -= lif->stats_base.ierrors;
201 : 0 : stats->oerrors -= lif->stats_base.oerrors;
202 : 0 : stats->rx_nombuf -= lif->stats_base.rx_nombuf;
203 : 0 : }
204 : :
205 : : void
206 : 0 : ionic_lif_reset_stats(struct ionic_lif *lif)
207 : : {
208 : : uint32_t i;
209 : :
210 [ # # ]: 0 : for (i = 0; i < lif->nrxqcqs; i++) {
211 : 0 : memset(&lif->rxqcqs[i]->stats, 0,
212 : : sizeof(struct ionic_rx_stats));
213 : 0 : memset(&lif->txqcqs[i]->stats, 0,
214 : : sizeof(struct ionic_tx_stats));
215 : : }
216 : :
217 : 0 : ionic_lif_get_abs_stats(lif, &lif->stats_base);
218 : 0 : }
219 : :
220 : : void
221 : 0 : ionic_lif_get_hw_stats(struct ionic_lif *lif, struct ionic_lif_stats *stats)
222 : : {
223 : : uint16_t i, count = sizeof(struct ionic_lif_stats) / sizeof(uint64_t);
224 : : uint64_t *stats64 = (uint64_t *)stats;
225 : 0 : uint64_t *lif_stats64 = (uint64_t *)&lif->info->stats;
226 : 0 : uint64_t *lif_stats64_base = (uint64_t *)&lif->lif_stats_base;
227 : :
228 [ # # ]: 0 : for (i = 0; i < count; i++)
229 : 0 : stats64[i] = lif_stats64[i] - lif_stats64_base[i];
230 : 0 : }
231 : :
232 : : void
233 : 0 : ionic_lif_reset_hw_stats(struct ionic_lif *lif)
234 : : {
235 : : uint16_t i, count = sizeof(struct ionic_lif_stats) / sizeof(uint64_t);
236 : 0 : uint64_t *lif_stats64 = (uint64_t *)&lif->info->stats;
237 : 0 : uint64_t *lif_stats64_base = (uint64_t *)&lif->lif_stats_base;
238 : :
239 [ # # ]: 0 : for (i = 0; i < count; i++)
240 : 0 : lif_stats64_base[i] = lif_stats64[i];
241 : 0 : }
242 : :
243 : : static int
244 : 0 : ionic_lif_addr_add(struct ionic_lif *lif, const uint8_t *addr)
245 : : {
246 : 0 : struct ionic_admin_ctx ctx = {
247 : : .pending_work = true,
248 : : .cmd.rx_filter_add = {
249 : : .opcode = IONIC_CMD_RX_FILTER_ADD,
250 : : .match = rte_cpu_to_le_16(IONIC_RX_FILTER_MATCH_MAC),
251 : : },
252 : : };
253 : : int err;
254 : :
255 : : memcpy(ctx.cmd.rx_filter_add.mac.addr, addr, RTE_ETHER_ADDR_LEN);
256 : :
257 : 0 : err = ionic_adminq_post_wait(lif, &ctx);
258 [ # # ]: 0 : if (err)
259 : : return err;
260 : :
261 : 0 : IONIC_PRINT(INFO, "rx_filter add (id %d)",
262 : : rte_le_to_cpu_32(ctx.comp.rx_filter_add.filter_id));
263 : :
264 : 0 : return ionic_rx_filter_save(lif, 0, IONIC_RXQ_INDEX_ANY, &ctx);
265 : : }
266 : :
267 : : static int
268 : 0 : ionic_lif_addr_del(struct ionic_lif *lif, const uint8_t *addr)
269 : : {
270 : 0 : struct ionic_admin_ctx ctx = {
271 : : .pending_work = true,
272 : : .cmd.rx_filter_del = {
273 : : .opcode = IONIC_CMD_RX_FILTER_DEL,
274 : : },
275 : : };
276 : : struct ionic_rx_filter *f;
277 : : int err;
278 : :
279 : 0 : IONIC_PRINT_CALL();
280 : :
281 : 0 : rte_spinlock_lock(&lif->rx_filters.lock);
282 : :
283 : 0 : f = ionic_rx_filter_by_addr(lif, addr);
284 [ # # ]: 0 : if (!f) {
285 : : rte_spinlock_unlock(&lif->rx_filters.lock);
286 : 0 : return -ENOENT;
287 : : }
288 : :
289 : 0 : ctx.cmd.rx_filter_del.filter_id = rte_cpu_to_le_32(f->filter_id);
290 : 0 : ionic_rx_filter_free(f);
291 : :
292 : : rte_spinlock_unlock(&lif->rx_filters.lock);
293 : :
294 : 0 : err = ionic_adminq_post_wait(lif, &ctx);
295 [ # # ]: 0 : if (err)
296 : : return err;
297 : :
298 : 0 : IONIC_PRINT(INFO, "rx_filter del (id %d)",
299 : : rte_le_to_cpu_32(ctx.cmd.rx_filter_del.filter_id));
300 : :
301 : 0 : return 0;
302 : : }
303 : :
304 : : int
305 : 0 : ionic_dev_add_mac(struct rte_eth_dev *eth_dev,
306 : : struct rte_ether_addr *mac_addr,
307 : : uint32_t index __rte_unused, uint32_t pool __rte_unused)
308 : : {
309 : 0 : struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
310 : :
311 : 0 : IONIC_PRINT_CALL();
312 : :
313 : 0 : return ionic_lif_addr_add(lif, (const uint8_t *)mac_addr);
314 : : }
315 : :
316 : : void
317 : 0 : ionic_dev_remove_mac(struct rte_eth_dev *eth_dev, uint32_t index)
318 : : {
319 : 0 : struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
320 : 0 : struct ionic_adapter *adapter = lif->adapter;
321 : : struct rte_ether_addr *mac_addr;
322 : :
323 : 0 : IONIC_PRINT_CALL();
324 : :
325 [ # # ]: 0 : if (index >= adapter->max_mac_addrs) {
326 : 0 : IONIC_PRINT(WARNING,
327 : : "Index %u is above MAC filter limit %u",
328 : : index, adapter->max_mac_addrs);
329 : 0 : return;
330 : : }
331 : :
332 [ # # ]: 0 : mac_addr = ð_dev->data->mac_addrs[index];
333 : :
334 : : if (!rte_is_valid_assigned_ether_addr(mac_addr))
335 : : return;
336 : :
337 : 0 : ionic_lif_addr_del(lif, (const uint8_t *)mac_addr);
338 : : }
339 : :
340 : : int
341 : 0 : ionic_dev_set_mac(struct rte_eth_dev *eth_dev, struct rte_ether_addr *mac_addr)
342 : : {
343 : 0 : struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
344 : :
345 : 0 : IONIC_PRINT_CALL();
346 : :
347 [ # # ]: 0 : if (mac_addr == NULL) {
348 : 0 : IONIC_PRINT(NOTICE, "New mac is null");
349 : 0 : return -1;
350 : : }
351 : :
352 [ # # ]: 0 : if (!rte_is_zero_ether_addr((struct rte_ether_addr *)lif->mac_addr)) {
353 : 0 : IONIC_PRINT(INFO, "Deleting mac addr %pM",
354 : : lif->mac_addr);
355 : 0 : ionic_lif_addr_del(lif, lif->mac_addr);
356 : : memset(lif->mac_addr, 0, RTE_ETHER_ADDR_LEN);
357 : : }
358 : :
359 : 0 : IONIC_PRINT(INFO, "Updating mac addr");
360 : :
361 : : rte_ether_addr_copy(mac_addr, (struct rte_ether_addr *)lif->mac_addr);
362 : :
363 : 0 : return ionic_lif_addr_add(lif, (const uint8_t *)mac_addr);
364 : : }
365 : :
366 : : static int
367 : 0 : ionic_vlan_rx_add_vid(struct ionic_lif *lif, uint16_t vid)
368 : : {
369 : 0 : struct ionic_admin_ctx ctx = {
370 : : .pending_work = true,
371 : : .cmd.rx_filter_add = {
372 : : .opcode = IONIC_CMD_RX_FILTER_ADD,
373 : : .match = rte_cpu_to_le_16(IONIC_RX_FILTER_MATCH_VLAN),
374 : : .vlan.vlan = rte_cpu_to_le_16(vid),
375 : : },
376 : : };
377 : : int err;
378 : :
379 : 0 : err = ionic_adminq_post_wait(lif, &ctx);
380 [ # # ]: 0 : if (err)
381 : : return err;
382 : :
383 : 0 : IONIC_PRINT(INFO, "rx_filter add VLAN %d (id %d)", vid,
384 : : rte_le_to_cpu_32(ctx.comp.rx_filter_add.filter_id));
385 : :
386 : 0 : return ionic_rx_filter_save(lif, 0, IONIC_RXQ_INDEX_ANY, &ctx);
387 : : }
388 : :
389 : : static int
390 : 0 : ionic_vlan_rx_kill_vid(struct ionic_lif *lif, uint16_t vid)
391 : : {
392 : 0 : struct ionic_admin_ctx ctx = {
393 : : .pending_work = true,
394 : : .cmd.rx_filter_del = {
395 : : .opcode = IONIC_CMD_RX_FILTER_DEL,
396 : : },
397 : : };
398 : : struct ionic_rx_filter *f;
399 : : int err;
400 : :
401 : 0 : IONIC_PRINT_CALL();
402 : :
403 : 0 : rte_spinlock_lock(&lif->rx_filters.lock);
404 : :
405 : 0 : f = ionic_rx_filter_by_vlan(lif, vid);
406 [ # # ]: 0 : if (!f) {
407 : : rte_spinlock_unlock(&lif->rx_filters.lock);
408 : 0 : return -ENOENT;
409 : : }
410 : :
411 : 0 : ctx.cmd.rx_filter_del.filter_id = rte_cpu_to_le_32(f->filter_id);
412 : 0 : ionic_rx_filter_free(f);
413 : : rte_spinlock_unlock(&lif->rx_filters.lock);
414 : :
415 : 0 : err = ionic_adminq_post_wait(lif, &ctx);
416 [ # # ]: 0 : if (err)
417 : : return err;
418 : :
419 : 0 : IONIC_PRINT(INFO, "rx_filter del VLAN %d (id %d)", vid,
420 : : rte_le_to_cpu_32(ctx.cmd.rx_filter_del.filter_id));
421 : :
422 : 0 : return 0;
423 : : }
424 : :
425 : : int
426 : 0 : ionic_dev_vlan_filter_set(struct rte_eth_dev *eth_dev, uint16_t vlan_id,
427 : : int on)
428 : : {
429 : 0 : struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
430 : : int err;
431 : :
432 [ # # ]: 0 : if (on)
433 : 0 : err = ionic_vlan_rx_add_vid(lif, vlan_id);
434 : : else
435 : 0 : err = ionic_vlan_rx_kill_vid(lif, vlan_id);
436 : :
437 : 0 : return err;
438 : : }
439 : :
440 : : static void
441 : 0 : ionic_lif_rx_mode(struct ionic_lif *lif, uint32_t rx_mode)
442 : : {
443 : 0 : struct ionic_admin_ctx ctx = {
444 : : .pending_work = true,
445 : : .cmd.rx_mode_set = {
446 : : .opcode = IONIC_CMD_RX_MODE_SET,
447 : : .rx_mode = rte_cpu_to_le_16(rx_mode),
448 : : },
449 : : };
450 : : int err;
451 : :
452 [ # # ]: 0 : if (rx_mode & IONIC_RX_MODE_F_UNICAST)
453 : 0 : IONIC_PRINT(DEBUG, "rx_mode IONIC_RX_MODE_F_UNICAST");
454 [ # # ]: 0 : if (rx_mode & IONIC_RX_MODE_F_MULTICAST)
455 : 0 : IONIC_PRINT(DEBUG, "rx_mode IONIC_RX_MODE_F_MULTICAST");
456 [ # # ]: 0 : if (rx_mode & IONIC_RX_MODE_F_BROADCAST)
457 : 0 : IONIC_PRINT(DEBUG, "rx_mode IONIC_RX_MODE_F_BROADCAST");
458 [ # # ]: 0 : if (rx_mode & IONIC_RX_MODE_F_PROMISC)
459 : 0 : IONIC_PRINT(DEBUG, "rx_mode IONIC_RX_MODE_F_PROMISC");
460 [ # # ]: 0 : if (rx_mode & IONIC_RX_MODE_F_ALLMULTI)
461 : 0 : IONIC_PRINT(DEBUG, "rx_mode IONIC_RX_MODE_F_ALLMULTI");
462 : :
463 : 0 : err = ionic_adminq_post_wait(lif, &ctx);
464 [ # # ]: 0 : if (err)
465 : 0 : IONIC_PRINT(ERR, "Failure setting RX mode");
466 : 0 : }
467 : :
468 : : static void
469 : : ionic_set_rx_mode(struct ionic_lif *lif, uint32_t rx_mode)
470 : : {
471 [ # # ]: 0 : if (lif->rx_mode != rx_mode) {
472 : 0 : lif->rx_mode = rx_mode;
473 : 0 : ionic_lif_rx_mode(lif, rx_mode);
474 : : }
475 : : }
476 : :
477 : : int
478 : 0 : ionic_dev_promiscuous_enable(struct rte_eth_dev *eth_dev)
479 : : {
480 : 0 : struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
481 : 0 : uint32_t rx_mode = lif->rx_mode;
482 : :
483 : 0 : IONIC_PRINT_CALL();
484 : :
485 [ # # ]: 0 : rx_mode |= IONIC_RX_MODE_F_PROMISC;
486 : :
487 : : ionic_set_rx_mode(lif, rx_mode);
488 : :
489 : 0 : return 0;
490 : : }
491 : :
492 : : int
493 : 0 : ionic_dev_promiscuous_disable(struct rte_eth_dev *eth_dev)
494 : : {
495 : 0 : struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
496 : 0 : uint32_t rx_mode = lif->rx_mode;
497 : :
498 [ # # ]: 0 : rx_mode &= ~IONIC_RX_MODE_F_PROMISC;
499 : :
500 : : ionic_set_rx_mode(lif, rx_mode);
501 : :
502 : 0 : return 0;
503 : : }
504 : :
505 : : int
506 : 0 : ionic_dev_allmulticast_enable(struct rte_eth_dev *eth_dev)
507 : : {
508 : 0 : struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
509 : 0 : uint32_t rx_mode = lif->rx_mode;
510 : :
511 [ # # ]: 0 : rx_mode |= IONIC_RX_MODE_F_ALLMULTI;
512 : :
513 : : ionic_set_rx_mode(lif, rx_mode);
514 : :
515 : 0 : return 0;
516 : : }
517 : :
518 : : int
519 : 0 : ionic_dev_allmulticast_disable(struct rte_eth_dev *eth_dev)
520 : : {
521 : 0 : struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
522 : 0 : uint32_t rx_mode = lif->rx_mode;
523 : :
524 [ # # ]: 0 : rx_mode &= ~IONIC_RX_MODE_F_ALLMULTI;
525 : :
526 : : ionic_set_rx_mode(lif, rx_mode);
527 : :
528 : 0 : return 0;
529 : : }
530 : :
531 : : int
532 : 0 : ionic_lif_change_mtu(struct ionic_lif *lif, uint32_t new_mtu)
533 : : {
534 : 0 : struct ionic_admin_ctx ctx = {
535 : : .pending_work = true,
536 : : .cmd.lif_setattr = {
537 : : .opcode = IONIC_CMD_LIF_SETATTR,
538 : : .attr = IONIC_LIF_ATTR_MTU,
539 : : .mtu = rte_cpu_to_le_32(new_mtu),
540 : : },
541 : : };
542 : :
543 : 0 : return ionic_adminq_post_wait(lif, &ctx);
544 : : }
545 : :
546 : : int
547 : 0 : ionic_intr_alloc(struct ionic_lif *lif, struct ionic_intr_info *intr)
548 : : {
549 : 0 : struct ionic_adapter *adapter = lif->adapter;
550 : 0 : struct ionic_dev *idev = &adapter->idev;
551 : : unsigned long index;
552 : :
553 : : /*
554 : : * Note: interrupt handler is called for index = 0 only
555 : : * (we use interrupts for the notifyq only anyway,
556 : : * which has index = 0)
557 : : */
558 : :
559 [ # # ]: 0 : for (index = 0; index < adapter->nintrs; index++)
560 [ # # ]: 0 : if (!adapter->intrs[index])
561 : : break;
562 : :
563 [ # # ]: 0 : if (index == adapter->nintrs)
564 : : return -ENOSPC;
565 : :
566 : 0 : adapter->intrs[index] = true;
567 : :
568 : 0 : ionic_intr_init(idev, intr, index);
569 : :
570 : 0 : return 0;
571 : : }
572 : :
573 : : static int
574 : 0 : ionic_qcq_alloc(struct ionic_lif *lif,
575 : : uint8_t type,
576 : : size_t struct_size,
577 : : uint32_t socket_id,
578 : : uint32_t index,
579 : : const char *type_name,
580 : : uint16_t flags,
581 : : uint16_t num_descs,
582 : : uint16_t num_segs,
583 : : uint16_t desc_size,
584 : : uint16_t cq_desc_size,
585 : : uint16_t sg_desc_size,
586 : : struct ionic_qcq **qcq)
587 : : {
588 : : struct ionic_qcq *new;
589 : : uint32_t q_size, cq_size, sg_size, total_size;
590 : : void *q_base, *cmb_q_base, *cq_base, *sg_base;
591 : : rte_iova_t q_base_pa = 0;
592 : : rte_iova_t cq_base_pa = 0;
593 : : rte_iova_t sg_base_pa = 0;
594 : : rte_iova_t cmb_q_base_pa = 0;
595 : 0 : size_t page_size = rte_mem_page_size();
596 : : int err;
597 : :
598 : 0 : *qcq = NULL;
599 : :
600 : 0 : q_size = num_descs * desc_size;
601 : 0 : cq_size = num_descs * cq_desc_size;
602 : 0 : sg_size = num_descs * sg_desc_size;
603 : :
604 : 0 : total_size = RTE_ALIGN(q_size, page_size) +
605 : 0 : RTE_ALIGN(cq_size, page_size);
606 : : /*
607 : : * Note: aligning q_size/cq_size is not enough due to cq_base address
608 : : * aligning as q_base could be not aligned to the page.
609 : : * Adding page_size.
610 : : */
611 : 0 : total_size += page_size;
612 : :
613 [ # # ]: 0 : if (flags & IONIC_QCQ_F_SG) {
614 : 0 : total_size += RTE_ALIGN(sg_size, page_size);
615 : 0 : total_size += page_size;
616 : : }
617 : :
618 : 0 : new = rte_zmalloc_socket("ionic", struct_size,
619 : : RTE_CACHE_LINE_SIZE, socket_id);
620 [ # # ]: 0 : if (!new) {
621 : 0 : IONIC_PRINT(ERR, "Cannot allocate queue structure");
622 : 0 : return -ENOMEM;
623 : : }
624 : :
625 : 0 : new->lif = lif;
626 : :
627 : : /* Most queue types will store 1 ptr per descriptor */
628 : 0 : new->q.info = rte_calloc_socket("ionic",
629 : 0 : (uint64_t)num_descs * num_segs,
630 : : sizeof(void *), page_size, socket_id);
631 [ # # ]: 0 : if (!new->q.info) {
632 : 0 : IONIC_PRINT(ERR, "Cannot allocate queue info");
633 : : err = -ENOMEM;
634 : 0 : goto err_out_free_qcq;
635 : : }
636 : :
637 : 0 : new->q.num_segs = num_segs;
638 : 0 : new->q.type = type;
639 : :
640 : 0 : err = ionic_q_init(&new->q, index, num_descs);
641 [ # # ]: 0 : if (err) {
642 : 0 : IONIC_PRINT(ERR, "Queue initialization failed");
643 : 0 : goto err_out_free_info;
644 : : }
645 : :
646 : 0 : err = ionic_cq_init(&new->cq, num_descs);
647 [ # # ]: 0 : if (err) {
648 : 0 : IONIC_PRINT(ERR, "Completion queue initialization failed");
649 : 0 : goto err_out_free_info;
650 : : }
651 : :
652 : 0 : new->base_z = rte_eth_dma_zone_reserve(lif->eth_dev,
653 : : type_name, index /* queue_idx */,
654 : : total_size, IONIC_ALIGN, socket_id);
655 : :
656 [ # # ]: 0 : if (!new->base_z) {
657 : 0 : IONIC_PRINT(ERR, "Cannot reserve queue DMA memory");
658 : : err = -ENOMEM;
659 : 0 : goto err_out_free_info;
660 : : }
661 : :
662 : 0 : new->base = new->base_z->addr;
663 : 0 : new->base_pa = new->base_z->iova;
664 : :
665 : : q_base = new->base;
666 : : q_base_pa = new->base_pa;
667 : :
668 : 0 : cq_base = (void *)RTE_ALIGN((uintptr_t)q_base + q_size, page_size);
669 : 0 : cq_base_pa = RTE_ALIGN(q_base_pa + q_size, page_size);
670 : :
671 [ # # ]: 0 : if (flags & IONIC_QCQ_F_SG) {
672 : 0 : sg_base = (void *)RTE_ALIGN((uintptr_t)cq_base + cq_size,
673 : : page_size);
674 : 0 : sg_base_pa = RTE_ALIGN(cq_base_pa + cq_size, page_size);
675 : 0 : ionic_q_sg_map(&new->q, sg_base, sg_base_pa);
676 : : }
677 : :
678 [ # # ]: 0 : if (flags & IONIC_QCQ_F_CMB) {
679 : : /* alloc descriptor ring from nic memory */
680 : 0 : if (lif->adapter->cmb_offset + q_size >
681 [ # # ]: 0 : lif->adapter->bars.bar[2].len) {
682 : 0 : IONIC_PRINT(ERR, "Cannot reserve queue from NIC mem");
683 : 0 : return -ENOMEM;
684 : : }
685 : 0 : cmb_q_base = (void *)
686 : 0 : ((uintptr_t)lif->adapter->bars.bar[2].vaddr +
687 : : (uintptr_t)lif->adapter->cmb_offset);
688 : : /* CMB PA is a relative address */
689 : : cmb_q_base_pa = lif->adapter->cmb_offset;
690 : 0 : lif->adapter->cmb_offset += q_size;
691 : : } else {
692 : : cmb_q_base = NULL;
693 : : cmb_q_base_pa = 0;
694 : : }
695 : :
696 : 0 : IONIC_PRINT(DEBUG, "Q-Base-PA = %#jx CQ-Base-PA = %#jx "
697 : : "SG-base-PA = %#jx",
698 : : q_base_pa, cq_base_pa, sg_base_pa);
699 : :
700 : 0 : ionic_q_map(&new->q, q_base, q_base_pa, cmb_q_base, cmb_q_base_pa);
701 : 0 : ionic_cq_map(&new->cq, cq_base, cq_base_pa);
702 : :
703 : 0 : *qcq = new;
704 : :
705 : 0 : return 0;
706 : :
707 : 0 : err_out_free_info:
708 : 0 : rte_free(new->q.info);
709 : 0 : err_out_free_qcq:
710 : 0 : rte_free(new);
711 : :
712 : 0 : return err;
713 : : }
714 : :
715 : : void
716 : 0 : ionic_qcq_free(struct ionic_qcq *qcq)
717 : : {
718 [ # # ]: 0 : if (qcq->base_z) {
719 : 0 : qcq->base = NULL;
720 : 0 : qcq->base_pa = 0;
721 : 0 : rte_memzone_free(qcq->base_z);
722 : 0 : qcq->base_z = NULL;
723 : : }
724 : :
725 [ # # ]: 0 : if (qcq->q.info) {
726 : 0 : rte_free(qcq->q.info);
727 : 0 : qcq->q.info = NULL;
728 : : }
729 : :
730 : 0 : rte_free(qcq);
731 : 0 : }
732 : :
733 : : static uint64_t
734 : 0 : ionic_rx_rearm_data(struct ionic_lif *lif)
735 : : {
736 : : struct rte_mbuf rxm;
737 : :
738 : : memset(&rxm, 0, sizeof(rxm));
739 : :
740 : : rte_mbuf_refcnt_set(&rxm, 1);
741 : 0 : rxm.data_off = RTE_PKTMBUF_HEADROOM;
742 : 0 : rxm.nb_segs = 1;
743 : 0 : rxm.port = lif->port_id;
744 : :
745 : 0 : rte_compiler_barrier();
746 : :
747 : : RTE_BUILD_BUG_ON(sizeof(rxm.rearm_data[0]) != sizeof(uint64_t));
748 : 0 : return rxm.rearm_data[0];
749 : : }
750 : :
751 : : static uint64_t
752 : 0 : ionic_rx_seg_rearm_data(struct ionic_lif *lif)
753 : : {
754 : : struct rte_mbuf rxm;
755 : :
756 : : memset(&rxm, 0, sizeof(rxm));
757 : :
758 : : rte_mbuf_refcnt_set(&rxm, 1);
759 : 0 : rxm.data_off = 0; /* no headroom */
760 : 0 : rxm.nb_segs = 1;
761 : 0 : rxm.port = lif->port_id;
762 : :
763 : 0 : rte_compiler_barrier();
764 : :
765 : : RTE_BUILD_BUG_ON(sizeof(rxm.rearm_data[0]) != sizeof(uint64_t));
766 : 0 : return rxm.rearm_data[0];
767 : : }
768 : :
769 : : int
770 : 0 : ionic_rx_qcq_alloc(struct ionic_lif *lif, uint32_t socket_id, uint32_t index,
771 : : uint16_t nrxq_descs, struct rte_mempool *mb_pool,
772 : : struct ionic_rx_qcq **rxq_out)
773 : : {
774 : : struct ionic_rx_qcq *rxq;
775 : : uint16_t flags = 0, seg_size, hdr_seg_size, max_segs, max_segs_fw = 1;
776 : : uint32_t max_mtu;
777 : : int err;
778 : :
779 [ # # ]: 0 : if (lif->state & IONIC_LIF_F_Q_IN_CMB)
780 : : flags |= IONIC_QCQ_F_CMB;
781 : :
782 : : seg_size = rte_pktmbuf_data_room_size(mb_pool);
783 : :
784 : : /* The first mbuf needs to leave headroom */
785 : 0 : hdr_seg_size = seg_size - RTE_PKTMBUF_HEADROOM;
786 : :
787 : 0 : max_mtu = rte_le_to_cpu_32(lif->adapter->ident.lif.eth.max_mtu);
788 : :
789 : : /* If mbufs are too small to hold received packets, enable SG */
790 [ # # ]: 0 : if (max_mtu > hdr_seg_size &&
791 [ # # ]: 0 : !(lif->features & IONIC_ETH_HW_RX_SG)) {
792 : 0 : IONIC_PRINT(NOTICE, "Enabling RX_OFFLOAD_SCATTER");
793 : 0 : lif->eth_dev->data->dev_conf.rxmode.offloads |=
794 : : RTE_ETH_RX_OFFLOAD_SCATTER;
795 : 0 : ionic_lif_configure_rx_sg_offload(lif);
796 : : }
797 : :
798 [ # # ]: 0 : if (lif->features & IONIC_ETH_HW_RX_SG) {
799 : 0 : flags |= IONIC_QCQ_F_SG;
800 : : max_segs_fw = IONIC_RX_MAX_SG_ELEMS + 1;
801 : : }
802 : :
803 : : /*
804 : : * Calculate how many fragment pointers might be stored in queue.
805 : : * This is the worst-case number, so that there's enough room in
806 : : * the info array.
807 : : */
808 : 0 : max_segs = 1 + (max_mtu + RTE_PKTMBUF_HEADROOM - 1) / seg_size;
809 : :
810 : 0 : IONIC_PRINT(DEBUG, "rxq %u max_mtu %u seg_size %u max_segs %u",
811 : : index, max_mtu, seg_size, max_segs);
812 [ # # ]: 0 : if (max_segs > max_segs_fw) {
813 : 0 : IONIC_PRINT(ERR, "Rx mbuf size insufficient (%d > %d avail)",
814 : : max_segs, max_segs_fw);
815 : 0 : return -EINVAL;
816 : : }
817 : :
818 : 0 : err = ionic_qcq_alloc(lif,
819 : : IONIC_QTYPE_RXQ,
820 : : sizeof(struct ionic_rx_qcq),
821 : : socket_id,
822 : : index,
823 : : "rx",
824 : : flags,
825 : : nrxq_descs,
826 : : max_segs,
827 : : sizeof(struct ionic_rxq_desc),
828 : : sizeof(struct ionic_rxq_comp),
829 : : sizeof(struct ionic_rxq_sg_desc),
830 : : (struct ionic_qcq **)&rxq);
831 [ # # ]: 0 : if (err)
832 : : return err;
833 : :
834 : 0 : rxq->flags = flags;
835 : 0 : rxq->seg_size = seg_size;
836 : 0 : rxq->hdr_seg_size = hdr_seg_size;
837 : 0 : rxq->rearm_data = ionic_rx_rearm_data(lif);
838 : 0 : rxq->rearm_seg_data = ionic_rx_seg_rearm_data(lif);
839 : :
840 : 0 : lif->rxqcqs[index] = rxq;
841 : 0 : *rxq_out = rxq;
842 : :
843 : 0 : return 0;
844 : : }
845 : :
846 : : int
847 : 0 : ionic_tx_qcq_alloc(struct ionic_lif *lif, uint32_t socket_id, uint32_t index,
848 : : uint16_t ntxq_descs, struct ionic_tx_qcq **txq_out)
849 : : {
850 : : struct ionic_tx_qcq *txq;
851 : : uint16_t flags = 0, num_segs_fw = 1;
852 : : int err;
853 : :
854 [ # # ]: 0 : if (lif->features & IONIC_ETH_HW_TX_SG) {
855 : : flags |= IONIC_QCQ_F_SG;
856 : : num_segs_fw = IONIC_TX_MAX_SG_ELEMS_V1 + 1;
857 : : }
858 [ # # ]: 0 : if (lif->state & IONIC_LIF_F_Q_IN_CMB)
859 : 0 : flags |= IONIC_QCQ_F_CMB;
860 : :
861 : 0 : IONIC_PRINT(DEBUG, "txq %u num_segs %u", index, num_segs_fw);
862 : :
863 : 0 : err = ionic_qcq_alloc(lif,
864 : : IONIC_QTYPE_TXQ,
865 : : sizeof(struct ionic_tx_qcq),
866 : : socket_id,
867 : : index,
868 : : "tx",
869 : : flags,
870 : : ntxq_descs,
871 : : num_segs_fw,
872 : : sizeof(struct ionic_txq_desc),
873 : : sizeof(struct ionic_txq_comp),
874 : : sizeof(struct ionic_txq_sg_desc_v1),
875 : : (struct ionic_qcq **)&txq);
876 [ # # ]: 0 : if (err)
877 : : return err;
878 : :
879 : 0 : txq->flags = flags;
880 : 0 : txq->num_segs_fw = num_segs_fw;
881 : :
882 : 0 : lif->txqcqs[index] = txq;
883 : 0 : *txq_out = txq;
884 : :
885 : 0 : return 0;
886 : : }
887 : :
888 : : static int
889 : 0 : ionic_admin_qcq_alloc(struct ionic_lif *lif)
890 : : {
891 : : uint16_t flags = 0;
892 : : int err;
893 : :
894 : 0 : err = ionic_qcq_alloc(lif,
895 : : IONIC_QTYPE_ADMINQ,
896 : : sizeof(struct ionic_admin_qcq),
897 : : rte_socket_id(),
898 : : 0,
899 : : "admin",
900 : : flags,
901 : : IONIC_ADMINQ_LENGTH,
902 : : 1,
903 : : sizeof(struct ionic_admin_cmd),
904 : : sizeof(struct ionic_admin_comp),
905 : : 0,
906 : 0 : (struct ionic_qcq **)&lif->adminqcq);
907 [ # # ]: 0 : if (err)
908 : 0 : return err;
909 : :
910 : : return 0;
911 : : }
912 : :
913 : : static int
914 : 0 : ionic_notify_qcq_alloc(struct ionic_lif *lif)
915 : : {
916 : : struct ionic_notify_qcq *nqcq;
917 : 0 : struct ionic_dev *idev = &lif->adapter->idev;
918 : : uint16_t flags = 0;
919 : : int err;
920 : :
921 : 0 : err = ionic_qcq_alloc(lif,
922 : : IONIC_QTYPE_NOTIFYQ,
923 : : sizeof(struct ionic_notify_qcq),
924 : : rte_socket_id(),
925 : : 0,
926 : : "notify",
927 : : flags,
928 : : IONIC_NOTIFYQ_LENGTH,
929 : : 1,
930 : : sizeof(struct ionic_notifyq_cmd),
931 : : sizeof(union ionic_notifyq_comp),
932 : : 0,
933 : : (struct ionic_qcq **)&nqcq);
934 [ # # ]: 0 : if (err)
935 : : return err;
936 : :
937 : 0 : err = ionic_intr_alloc(lif, &nqcq->intr);
938 [ # # ]: 0 : if (err) {
939 : 0 : ionic_qcq_free(&nqcq->qcq);
940 : 0 : return err;
941 : : }
942 : :
943 : 0 : ionic_intr_mask_assert(idev->intr_ctrl, nqcq->intr.index,
944 : : IONIC_INTR_MASK_SET);
945 : :
946 : 0 : lif->notifyqcq = nqcq;
947 : :
948 : 0 : return 0;
949 : : }
950 : :
951 : : static void
952 : 0 : ionic_lif_queue_identify(struct ionic_lif *lif)
953 : : {
954 : 0 : struct ionic_adapter *adapter = lif->adapter;
955 : 0 : struct ionic_dev *idev = &adapter->idev;
956 : : union ionic_q_identity *q_ident = &adapter->ident.txq;
957 : : uint32_t q_words = RTE_DIM(q_ident->words);
958 : : uint32_t cmd_words = RTE_DIM(idev->dev_cmd->data);
959 : : uint32_t i, nwords, qtype;
960 : : int err;
961 : :
962 [ # # ]: 0 : for (qtype = 0; qtype < RTE_DIM(ionic_qtype_vers); qtype++) {
963 : 0 : struct ionic_qtype_info *qti = &lif->qtype_info[qtype];
964 : :
965 : : /* Filter out the types this driver knows about */
966 [ # # ]: 0 : switch (qtype) {
967 : : case IONIC_QTYPE_ADMINQ:
968 : : case IONIC_QTYPE_NOTIFYQ:
969 : : case IONIC_QTYPE_RXQ:
970 : : case IONIC_QTYPE_TXQ:
971 : : break;
972 : 0 : default:
973 : 0 : continue;
974 : : }
975 : :
976 : : memset(qti, 0, sizeof(*qti));
977 : :
978 : 0 : ionic_dev_cmd_queue_identify(idev, IONIC_LIF_TYPE_CLASSIC,
979 : 0 : qtype, ionic_qtype_vers[qtype]);
980 : 0 : err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
981 [ # # ]: 0 : if (err == -EINVAL) {
982 : 0 : IONIC_PRINT(ERR, "qtype %d not supported\n", qtype);
983 : 0 : continue;
984 [ # # ]: 0 : } else if (err == -EIO) {
985 : 0 : IONIC_PRINT(ERR, "q_ident failed, older FW\n");
986 : 0 : return;
987 [ # # ]: 0 : } else if (err) {
988 : 0 : IONIC_PRINT(ERR, "q_ident failed, qtype %d: %d\n",
989 : : qtype, err);
990 : 0 : return;
991 : : }
992 : :
993 : : nwords = RTE_MIN(q_words, cmd_words);
994 [ # # ]: 0 : for (i = 0; i < nwords; i++)
995 : 0 : q_ident->words[i] = ioread32(&idev->dev_cmd->data[i]);
996 : :
997 : 0 : qti->version = q_ident->version;
998 : 0 : qti->supported = q_ident->supported;
999 : 0 : qti->features = rte_le_to_cpu_64(q_ident->features);
1000 : 0 : qti->desc_sz = rte_le_to_cpu_16(q_ident->desc_sz);
1001 : 0 : qti->comp_sz = rte_le_to_cpu_16(q_ident->comp_sz);
1002 : 0 : qti->sg_desc_sz = rte_le_to_cpu_16(q_ident->sg_desc_sz);
1003 : 0 : qti->max_sg_elems = rte_le_to_cpu_16(q_ident->max_sg_elems);
1004 : 0 : qti->sg_desc_stride =
1005 : 0 : rte_le_to_cpu_16(q_ident->sg_desc_stride);
1006 : :
1007 : 0 : IONIC_PRINT(DEBUG, " qtype[%d].version = %d",
1008 : : qtype, qti->version);
1009 : 0 : IONIC_PRINT(DEBUG, " qtype[%d].supported = %#x",
1010 : : qtype, qti->supported);
1011 : 0 : IONIC_PRINT(DEBUG, " qtype[%d].features = %#jx",
1012 : : qtype, qti->features);
1013 : 0 : IONIC_PRINT(DEBUG, " qtype[%d].desc_sz = %d",
1014 : : qtype, qti->desc_sz);
1015 : 0 : IONIC_PRINT(DEBUG, " qtype[%d].comp_sz = %d",
1016 : : qtype, qti->comp_sz);
1017 : 0 : IONIC_PRINT(DEBUG, " qtype[%d].sg_desc_sz = %d",
1018 : : qtype, qti->sg_desc_sz);
1019 : 0 : IONIC_PRINT(DEBUG, " qtype[%d].max_sg_elems = %d",
1020 : : qtype, qti->max_sg_elems);
1021 : 0 : IONIC_PRINT(DEBUG, " qtype[%d].sg_desc_stride = %d",
1022 : : qtype, qti->sg_desc_stride);
1023 : : }
1024 : : }
1025 : :
1026 : : int
1027 : 0 : ionic_lif_alloc(struct ionic_lif *lif)
1028 : : {
1029 : 0 : struct ionic_adapter *adapter = lif->adapter;
1030 : 0 : uint32_t socket_id = rte_socket_id();
1031 : : int err;
1032 : :
1033 : : /*
1034 : : * lif->name was zeroed on allocation.
1035 : : * Copy (sizeof() - 1) bytes to ensure that it is NULL terminated.
1036 : : */
1037 : 0 : memcpy(lif->name, lif->eth_dev->data->name, sizeof(lif->name) - 1);
1038 : :
1039 : 0 : IONIC_PRINT(DEBUG, "LIF: %s", lif->name);
1040 : :
1041 : 0 : ionic_lif_queue_identify(lif);
1042 : :
1043 [ # # ]: 0 : if (lif->qtype_info[IONIC_QTYPE_TXQ].version < 1) {
1044 : 0 : IONIC_PRINT(ERR, "FW too old, please upgrade");
1045 : 0 : return -ENXIO;
1046 : : }
1047 : :
1048 [ # # ]: 0 : if (adapter->q_in_cmb) {
1049 [ # # ]: 0 : if (adapter->bars.num_bars >= 3 &&
1050 [ # # # # ]: 0 : lif->qtype_info[IONIC_QTYPE_RXQ].version >= 2 &&
1051 : : lif->qtype_info[IONIC_QTYPE_TXQ].version >= 3) {
1052 : 0 : IONIC_PRINT(INFO, "%s enabled on %s",
1053 : : PMD_IONIC_CMB_KVARG, lif->name);
1054 : 0 : lif->state |= IONIC_LIF_F_Q_IN_CMB;
1055 : : } else {
1056 : 0 : IONIC_PRINT(ERR, "%s not supported on %s, disabled",
1057 : : PMD_IONIC_CMB_KVARG, lif->name);
1058 : : }
1059 : : }
1060 : :
1061 : 0 : IONIC_PRINT(DEBUG, "Allocating Lif Info");
1062 : :
1063 : : rte_spinlock_init(&lif->adminq_lock);
1064 : : rte_spinlock_init(&lif->adminq_service_lock);
1065 : :
1066 : 0 : lif->kern_dbpage = adapter->idev.db_pages;
1067 [ # # ]: 0 : if (!lif->kern_dbpage) {
1068 : 0 : IONIC_PRINT(ERR, "Cannot map dbpage, aborting");
1069 : 0 : return -ENOMEM;
1070 : : }
1071 : :
1072 : 0 : lif->txqcqs = rte_calloc_socket("ionic",
1073 : 0 : adapter->max_ntxqs_per_lif,
1074 : : sizeof(*lif->txqcqs),
1075 : : RTE_CACHE_LINE_SIZE, socket_id);
1076 [ # # ]: 0 : if (!lif->txqcqs) {
1077 : 0 : IONIC_PRINT(ERR, "Cannot allocate tx queues array");
1078 : 0 : return -ENOMEM;
1079 : : }
1080 : :
1081 : 0 : lif->rxqcqs = rte_calloc_socket("ionic",
1082 : 0 : adapter->max_nrxqs_per_lif,
1083 : : sizeof(*lif->rxqcqs),
1084 : : RTE_CACHE_LINE_SIZE, socket_id);
1085 [ # # ]: 0 : if (!lif->rxqcqs) {
1086 : 0 : IONIC_PRINT(ERR, "Cannot allocate rx queues array");
1087 : 0 : return -ENOMEM;
1088 : : }
1089 : :
1090 : 0 : IONIC_PRINT(DEBUG, "Allocating Notify Queue");
1091 : :
1092 : 0 : err = ionic_notify_qcq_alloc(lif);
1093 [ # # ]: 0 : if (err) {
1094 : 0 : IONIC_PRINT(ERR, "Cannot allocate notify queue");
1095 : 0 : return err;
1096 : : }
1097 : :
1098 : 0 : IONIC_PRINT(DEBUG, "Allocating Admin Queue");
1099 : :
1100 : 0 : err = ionic_admin_qcq_alloc(lif);
1101 [ # # ]: 0 : if (err) {
1102 : 0 : IONIC_PRINT(ERR, "Cannot allocate admin queue");
1103 : 0 : return err;
1104 : : }
1105 : :
1106 : 0 : IONIC_PRINT(DEBUG, "Allocating Lif Info");
1107 : :
1108 : 0 : lif->info_sz = RTE_ALIGN(sizeof(*lif->info), rte_mem_page_size());
1109 : :
1110 : 0 : lif->info_z = rte_eth_dma_zone_reserve(lif->eth_dev,
1111 : : "lif_info", 0 /* queue_idx*/,
1112 : : lif->info_sz, IONIC_ALIGN, socket_id);
1113 [ # # ]: 0 : if (!lif->info_z) {
1114 : 0 : IONIC_PRINT(ERR, "Cannot allocate lif info memory");
1115 : 0 : return -ENOMEM;
1116 : : }
1117 : :
1118 : 0 : lif->info = lif->info_z->addr;
1119 : 0 : lif->info_pa = lif->info_z->iova;
1120 : :
1121 : 0 : return 0;
1122 : : }
1123 : :
1124 : : void
1125 : 0 : ionic_lif_free(struct ionic_lif *lif)
1126 : : {
1127 [ # # ]: 0 : if (lif->notifyqcq) {
1128 : 0 : ionic_qcq_free(&lif->notifyqcq->qcq);
1129 : 0 : lif->notifyqcq = NULL;
1130 : : }
1131 : :
1132 [ # # ]: 0 : if (lif->adminqcq) {
1133 : 0 : ionic_qcq_free(&lif->adminqcq->qcq);
1134 : 0 : lif->adminqcq = NULL;
1135 : : }
1136 : :
1137 [ # # ]: 0 : if (lif->txqcqs) {
1138 : 0 : rte_free(lif->txqcqs);
1139 : 0 : lif->txqcqs = NULL;
1140 : : }
1141 : :
1142 [ # # ]: 0 : if (lif->rxqcqs) {
1143 : 0 : rte_free(lif->rxqcqs);
1144 : 0 : lif->rxqcqs = NULL;
1145 : : }
1146 : :
1147 [ # # ]: 0 : if (lif->info) {
1148 : 0 : rte_memzone_free(lif->info_z);
1149 : 0 : lif->info = NULL;
1150 : : }
1151 : 0 : }
1152 : :
1153 : : void
1154 : 0 : ionic_lif_free_queues(struct ionic_lif *lif)
1155 : : {
1156 : : uint32_t i;
1157 : :
1158 [ # # ]: 0 : for (i = 0; i < lif->ntxqcqs; i++) {
1159 : 0 : ionic_dev_tx_queue_release(lif->eth_dev, i);
1160 : 0 : lif->eth_dev->data->tx_queues[i] = NULL;
1161 : : }
1162 [ # # ]: 0 : for (i = 0; i < lif->nrxqcqs; i++) {
1163 : 0 : ionic_dev_rx_queue_release(lif->eth_dev, i);
1164 : 0 : lif->eth_dev->data->rx_queues[i] = NULL;
1165 : : }
1166 : 0 : }
1167 : :
1168 : : int
1169 : 0 : ionic_lif_rss_config(struct ionic_lif *lif,
1170 : : const uint16_t types, const uint8_t *key, const uint32_t *indir)
1171 : : {
1172 : 0 : struct ionic_adapter *adapter = lif->adapter;
1173 : 0 : struct ionic_admin_ctx ctx = {
1174 : : .pending_work = true,
1175 : : .cmd.lif_setattr = {
1176 : : .opcode = IONIC_CMD_LIF_SETATTR,
1177 : : .attr = IONIC_LIF_ATTR_RSS,
1178 : : .rss.types = rte_cpu_to_le_16(types),
1179 : 0 : .rss.addr = rte_cpu_to_le_64(lif->rss_ind_tbl_pa),
1180 : : },
1181 : : };
1182 : : unsigned int i;
1183 : 0 : uint16_t tbl_sz =
1184 : : rte_le_to_cpu_16(adapter->ident.lif.eth.rss_ind_tbl_sz);
1185 : :
1186 : 0 : IONIC_PRINT_CALL();
1187 : :
1188 : 0 : lif->rss_types = types;
1189 : :
1190 [ # # ]: 0 : if (key)
1191 : 0 : memcpy(lif->rss_hash_key, key, IONIC_RSS_HASH_KEY_SIZE);
1192 : :
1193 [ # # ]: 0 : if (indir)
1194 [ # # ]: 0 : for (i = 0; i < tbl_sz; i++)
1195 : 0 : lif->rss_ind_tbl[i] = indir[i];
1196 : :
1197 : : memcpy(ctx.cmd.lif_setattr.rss.key, lif->rss_hash_key,
1198 : : IONIC_RSS_HASH_KEY_SIZE);
1199 : :
1200 : 0 : return ionic_adminq_post_wait(lif, &ctx);
1201 : : }
1202 : :
1203 : : static int
1204 : 0 : ionic_lif_rss_setup(struct ionic_lif *lif)
1205 : : {
1206 : 0 : struct ionic_adapter *adapter = lif->adapter;
1207 : : static const uint8_t toeplitz_symmetric_key[] = {
1208 : : 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A,
1209 : : 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A,
1210 : : 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A,
1211 : : 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A,
1212 : : 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A,
1213 : : };
1214 : : uint32_t i;
1215 : 0 : uint16_t tbl_sz =
1216 : : rte_le_to_cpu_16(adapter->ident.lif.eth.rss_ind_tbl_sz);
1217 : :
1218 : 0 : IONIC_PRINT_CALL();
1219 : :
1220 [ # # ]: 0 : if (!lif->rss_ind_tbl_z) {
1221 : 0 : lif->rss_ind_tbl_z = rte_eth_dma_zone_reserve(lif->eth_dev,
1222 : : "rss_ind_tbl", 0 /* queue_idx */,
1223 : : sizeof(*lif->rss_ind_tbl) * tbl_sz,
1224 : 0 : IONIC_ALIGN, rte_socket_id());
1225 [ # # ]: 0 : if (!lif->rss_ind_tbl_z) {
1226 : 0 : IONIC_PRINT(ERR, "OOM");
1227 : 0 : return -ENOMEM;
1228 : : }
1229 : :
1230 : 0 : lif->rss_ind_tbl = lif->rss_ind_tbl_z->addr;
1231 : 0 : lif->rss_ind_tbl_pa = lif->rss_ind_tbl_z->iova;
1232 : : }
1233 : :
1234 [ # # ]: 0 : if (lif->rss_ind_tbl_nrxqcqs != lif->nrxqcqs) {
1235 : 0 : lif->rss_ind_tbl_nrxqcqs = lif->nrxqcqs;
1236 : :
1237 : : /* Fill indirection table with 'default' values */
1238 [ # # ]: 0 : for (i = 0; i < tbl_sz; i++)
1239 : 0 : lif->rss_ind_tbl[i] = i % lif->nrxqcqs;
1240 : : }
1241 : :
1242 : 0 : return ionic_lif_rss_config(lif, IONIC_RSS_OFFLOAD_ALL,
1243 : : toeplitz_symmetric_key, NULL);
1244 : : }
1245 : :
1246 : : static void
1247 : : ionic_lif_rss_teardown(struct ionic_lif *lif)
1248 : : {
1249 [ # # ]: 0 : if (lif->rss_ind_tbl) {
1250 : 0 : lif->rss_ind_tbl = NULL;
1251 : 0 : lif->rss_ind_tbl_pa = 0;
1252 : 0 : rte_memzone_free(lif->rss_ind_tbl_z);
1253 : 0 : lif->rss_ind_tbl_z = NULL;
1254 : : }
1255 : : }
1256 : :
1257 : : void
1258 : 0 : ionic_lif_txq_deinit_nowait(struct ionic_tx_qcq *txq)
1259 : : {
1260 : 0 : ionic_qcq_disable_nowait(&txq->qcq, &txq->admin_ctx);
1261 : :
1262 : 0 : txq->flags &= ~IONIC_QCQ_F_INITED;
1263 : 0 : }
1264 : :
1265 : : void
1266 : 0 : ionic_lif_txq_stats(struct ionic_tx_qcq *txq)
1267 : : {
1268 : : struct ionic_tx_stats *stats = &txq->stats;
1269 : :
1270 : 0 : IONIC_PRINT(DEBUG, "TX queue %u pkts %ju tso %ju",
1271 : : txq->qcq.q.index, stats->packets, stats->tso);
1272 [ # # ]: 0 : IONIC_PRINT(DEBUG, "TX queue %u comps %ju (%ju per)",
1273 : : txq->qcq.q.index, stats->comps,
1274 : : stats->comps ? stats->packets / stats->comps : 0);
1275 : 0 : }
1276 : :
1277 : : void
1278 : 0 : ionic_lif_rxq_deinit_nowait(struct ionic_rx_qcq *rxq)
1279 : : {
1280 : 0 : ionic_qcq_disable_nowait(&rxq->qcq, &rxq->admin_ctx);
1281 : :
1282 : 0 : rxq->flags &= ~IONIC_QCQ_F_INITED;
1283 : 0 : }
1284 : :
1285 : : void
1286 : 0 : ionic_lif_rxq_stats(struct ionic_rx_qcq *rxq)
1287 : : {
1288 : : struct ionic_rx_stats *stats = &rxq->stats;
1289 : :
1290 : 0 : IONIC_PRINT(DEBUG, "RX queue %u pkts %ju mtod %ju",
1291 : : rxq->qcq.q.index, stats->packets, stats->mtods);
1292 : 0 : }
1293 : :
1294 : : static void
1295 : : ionic_lif_adminq_deinit(struct ionic_lif *lif)
1296 : : {
1297 : 0 : lif->adminqcq->flags &= ~IONIC_QCQ_F_INITED;
1298 : : }
1299 : :
1300 : : static void
1301 : : ionic_lif_notifyq_deinit(struct ionic_lif *lif)
1302 : : {
1303 : 0 : struct ionic_notify_qcq *nqcq = lif->notifyqcq;
1304 : 0 : struct ionic_dev *idev = &lif->adapter->idev;
1305 : :
1306 [ # # ]: 0 : if (!(nqcq->flags & IONIC_QCQ_F_INITED))
1307 : : return;
1308 : :
1309 : 0 : ionic_intr_mask(idev->intr_ctrl, nqcq->intr.index,
1310 : : IONIC_INTR_MASK_SET);
1311 : :
1312 : 0 : nqcq->flags &= ~IONIC_QCQ_F_INITED;
1313 : : }
1314 : :
1315 : : /* This acts like ionic_napi */
1316 : : int
1317 : 0 : ionic_qcq_service(struct ionic_qcq *qcq, int budget, ionic_cq_cb cb,
1318 : : void *cb_arg)
1319 : : {
1320 : 0 : struct ionic_cq *cq = &qcq->cq;
1321 : : uint32_t work_done;
1322 : :
1323 : 0 : work_done = ionic_cq_service(cq, budget, cb, cb_arg);
1324 : :
1325 : 0 : return work_done;
1326 : : }
1327 : :
1328 : : static void
1329 : 0 : ionic_link_status_check(struct ionic_lif *lif)
1330 : : {
1331 : 0 : struct ionic_adapter *adapter = lif->adapter;
1332 : : bool link_up;
1333 : :
1334 : 0 : lif->state &= ~IONIC_LIF_F_LINK_CHECK_NEEDED;
1335 : :
1336 [ # # ]: 0 : if (!lif->info)
1337 : : return;
1338 : :
1339 : 0 : link_up = (lif->info->status.link_status == IONIC_PORT_OPER_STATUS_UP);
1340 : :
1341 [ # # # # : 0 : if ((link_up && adapter->link_up) ||
# # ]
1342 [ # # ]: 0 : (!link_up && !adapter->link_up))
1343 : : return;
1344 : :
1345 [ # # ]: 0 : if (link_up) {
1346 : 0 : adapter->link_speed =
1347 : 0 : rte_le_to_cpu_32(lif->info->status.link_speed);
1348 : 0 : IONIC_PRINT(DEBUG, "Link up - %d Gbps",
1349 : : adapter->link_speed);
1350 : : } else {
1351 : 0 : IONIC_PRINT(DEBUG, "Link down");
1352 : : }
1353 : :
1354 : 0 : adapter->link_up = link_up;
1355 : 0 : ionic_dev_link_update(lif->eth_dev, 0);
1356 : : }
1357 : :
1358 : : static void
1359 : 0 : ionic_lif_handle_fw_down(struct ionic_lif *lif)
1360 : : {
1361 [ # # ]: 0 : if (lif->state & IONIC_LIF_F_FW_RESET)
1362 : : return;
1363 : :
1364 : 0 : lif->state |= IONIC_LIF_F_FW_RESET;
1365 : :
1366 [ # # ]: 0 : if (lif->state & IONIC_LIF_F_UP) {
1367 : 0 : IONIC_PRINT(NOTICE,
1368 : : "Surprise FW stop, stopping %s\n", lif->name);
1369 : 0 : ionic_lif_stop(lif);
1370 : : }
1371 : :
1372 : 0 : IONIC_PRINT(NOTICE, "FW down, %s stopped", lif->name);
1373 : : }
1374 : :
1375 : : static bool
1376 : 0 : ionic_notifyq_cb(struct ionic_cq *cq, uint16_t cq_desc_index, void *cb_arg)
1377 : : {
1378 : 0 : union ionic_notifyq_comp *cq_desc_base = cq->base;
1379 : 0 : union ionic_notifyq_comp *cq_desc = &cq_desc_base[cq_desc_index];
1380 : : struct ionic_lif *lif = cb_arg;
1381 : :
1382 : 0 : IONIC_PRINT(DEBUG, "Notifyq callback eid = %jd ecode = %d",
1383 : : cq_desc->event.eid, cq_desc->event.ecode);
1384 : :
1385 : : /* Have we run out of new completions to process? */
1386 [ # # ]: 0 : if (!(cq_desc->event.eid > lif->last_eid))
1387 : : return false;
1388 : :
1389 : 0 : lif->last_eid = cq_desc->event.eid;
1390 : :
1391 [ # # # ]: 0 : switch (cq_desc->event.ecode) {
1392 : 0 : case IONIC_EVENT_LINK_CHANGE:
1393 : 0 : IONIC_PRINT(DEBUG,
1394 : : "Notifyq IONIC_EVENT_LINK_CHANGE %s "
1395 : : "eid=%jd link_status=%d link_speed=%d",
1396 : : lif->name,
1397 : : cq_desc->event.eid,
1398 : : cq_desc->link_change.link_status,
1399 : : cq_desc->link_change.link_speed);
1400 : :
1401 : 0 : lif->state |= IONIC_LIF_F_LINK_CHECK_NEEDED;
1402 : 0 : break;
1403 : :
1404 : 0 : case IONIC_EVENT_RESET:
1405 : 0 : IONIC_PRINT(NOTICE,
1406 : : "Notifyq IONIC_EVENT_RESET %s "
1407 : : "eid=%jd, reset_code=%d state=%d",
1408 : : lif->name,
1409 : : cq_desc->event.eid,
1410 : : cq_desc->reset.reset_code,
1411 : : cq_desc->reset.state);
1412 : 0 : ionic_lif_handle_fw_down(lif);
1413 : 0 : break;
1414 : :
1415 : 0 : default:
1416 : 0 : IONIC_PRINT(WARNING, "Notifyq bad event ecode=%d eid=%jd",
1417 : : cq_desc->event.ecode, cq_desc->event.eid);
1418 : 0 : break;
1419 : : }
1420 : :
1421 : : return true;
1422 : : }
1423 : :
1424 : : int
1425 : 0 : ionic_notifyq_handler(struct ionic_lif *lif, int budget)
1426 : : {
1427 : 0 : struct ionic_dev *idev = &lif->adapter->idev;
1428 : 0 : struct ionic_notify_qcq *nqcq = lif->notifyqcq;
1429 : : uint32_t work_done;
1430 : :
1431 [ # # ]: 0 : if (!(nqcq->flags & IONIC_QCQ_F_INITED)) {
1432 : 0 : IONIC_PRINT(DEBUG, "Notifyq not yet initialized");
1433 : 0 : return -1;
1434 : : }
1435 : :
1436 : 0 : ionic_intr_mask(idev->intr_ctrl, nqcq->intr.index,
1437 : : IONIC_INTR_MASK_SET);
1438 : :
1439 : 0 : work_done = ionic_qcq_service(&nqcq->qcq, budget,
1440 : : ionic_notifyq_cb, lif);
1441 : :
1442 [ # # ]: 0 : if (lif->state & IONIC_LIF_F_LINK_CHECK_NEEDED)
1443 : 0 : ionic_link_status_check(lif);
1444 : :
1445 : 0 : ionic_intr_credits(idev->intr_ctrl, nqcq->intr.index,
1446 : : work_done, IONIC_INTR_CRED_RESET_COALESCE);
1447 : :
1448 : 0 : ionic_intr_mask(idev->intr_ctrl, nqcq->intr.index,
1449 : : IONIC_INTR_MASK_CLEAR);
1450 : :
1451 : 0 : return 0;
1452 : : }
1453 : :
1454 : : static int
1455 : 0 : ionic_lif_adminq_init(struct ionic_lif *lif)
1456 : : {
1457 : 0 : struct ionic_dev *idev = &lif->adapter->idev;
1458 : 0 : struct ionic_admin_qcq *aqcq = lif->adminqcq;
1459 : 0 : struct ionic_queue *q = &aqcq->qcq.q;
1460 : : struct ionic_q_init_comp comp;
1461 : : uint32_t retries = 5;
1462 : : int err;
1463 : :
1464 : 0 : retry_adminq_init:
1465 : 0 : ionic_dev_cmd_adminq_init(idev, &aqcq->qcq);
1466 : 0 : err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
1467 [ # # ]: 0 : if (err == -EAGAIN && retries > 0) {
1468 : 0 : retries--;
1469 : 0 : rte_delay_us_block(IONIC_DEVCMD_RETRY_WAIT_US);
1470 : 0 : goto retry_adminq_init;
1471 : : }
1472 [ # # ]: 0 : if (err)
1473 : : return err;
1474 : :
1475 : 0 : ionic_dev_cmd_comp(idev, &comp);
1476 : :
1477 : 0 : q->hw_type = comp.hw_type;
1478 : 0 : q->hw_index = rte_le_to_cpu_32(comp.hw_index);
1479 : 0 : q->db = ionic_db_map(lif, q);
1480 : :
1481 : 0 : IONIC_PRINT(DEBUG, "adminq->hw_type %d", q->hw_type);
1482 : 0 : IONIC_PRINT(DEBUG, "adminq->hw_index %d", q->hw_index);
1483 : 0 : IONIC_PRINT(DEBUG, "adminq->db %p", q->db);
1484 : :
1485 : 0 : aqcq->flags |= IONIC_QCQ_F_INITED;
1486 : :
1487 : 0 : return 0;
1488 : : }
1489 : :
1490 : : static int
1491 : 0 : ionic_lif_notifyq_init(struct ionic_lif *lif)
1492 : : {
1493 : 0 : struct ionic_dev *idev = &lif->adapter->idev;
1494 : 0 : struct ionic_notify_qcq *nqcq = lif->notifyqcq;
1495 : : struct ionic_queue *q = &nqcq->qcq.q;
1496 : : uint16_t flags = IONIC_QINIT_F_ENA;
1497 : : int err;
1498 : :
1499 : 0 : struct ionic_admin_ctx ctx = {
1500 : : .pending_work = true,
1501 : : .cmd.q_init = {
1502 : : .opcode = IONIC_CMD_Q_INIT,
1503 : 0 : .type = q->type,
1504 : 0 : .ver = lif->qtype_info[q->type].version,
1505 : 0 : .index = rte_cpu_to_le_32(q->index),
1506 : : .intr_index = rte_cpu_to_le_16(IONIC_INTR_NONE),
1507 [ # # ]: 0 : .ring_size = rte_log2_u32(q->num_descs),
1508 : 0 : .ring_base = rte_cpu_to_le_64(q->base_pa),
1509 : : }
1510 : : };
1511 : :
1512 : : /* Only enable an interrupt if the device supports them */
1513 [ # # ]: 0 : if (lif->adapter->intf->configure_intr != NULL) {
1514 : : flags |= IONIC_QINIT_F_IRQ;
1515 : 0 : ctx.cmd.q_init.intr_index = rte_cpu_to_le_16(nqcq->intr.index);
1516 : : }
1517 : 0 : ctx.cmd.q_init.flags = rte_cpu_to_le_16(flags);
1518 : :
1519 : 0 : IONIC_PRINT(DEBUG, "notifyq_init.index %d", q->index);
1520 : 0 : IONIC_PRINT(DEBUG, "notifyq_init.ring_base 0x%" PRIx64 "", q->base_pa);
1521 : 0 : IONIC_PRINT(DEBUG, "notifyq_init.ring_size %d",
1522 : : ctx.cmd.q_init.ring_size);
1523 : 0 : IONIC_PRINT(DEBUG, "notifyq_init.ver %u", ctx.cmd.q_init.ver);
1524 : :
1525 : 0 : err = ionic_adminq_post_wait(lif, &ctx);
1526 [ # # ]: 0 : if (err)
1527 : : return err;
1528 : :
1529 : 0 : q->hw_type = ctx.comp.q_init.hw_type;
1530 : 0 : q->hw_index = rte_le_to_cpu_32(ctx.comp.q_init.hw_index);
1531 : 0 : q->db = NULL;
1532 : :
1533 : 0 : IONIC_PRINT(DEBUG, "notifyq->hw_type %d", q->hw_type);
1534 : 0 : IONIC_PRINT(DEBUG, "notifyq->hw_index %d", q->hw_index);
1535 : 0 : IONIC_PRINT(DEBUG, "notifyq->db %p", q->db);
1536 : :
1537 : 0 : ionic_intr_mask(idev->intr_ctrl, nqcq->intr.index,
1538 : : IONIC_INTR_MASK_CLEAR);
1539 : :
1540 : 0 : nqcq->flags |= IONIC_QCQ_F_INITED;
1541 : :
1542 : 0 : return 0;
1543 : : }
1544 : :
1545 : : int
1546 : 0 : ionic_lif_set_features(struct ionic_lif *lif)
1547 : : {
1548 : 0 : struct ionic_admin_ctx ctx = {
1549 : : .pending_work = true,
1550 : : .cmd.lif_setattr = {
1551 : : .opcode = IONIC_CMD_LIF_SETATTR,
1552 : : .attr = IONIC_LIF_ATTR_FEATURES,
1553 : 0 : .features = rte_cpu_to_le_64(lif->features),
1554 : : },
1555 : : };
1556 : : int err;
1557 : :
1558 : 0 : err = ionic_adminq_post_wait(lif, &ctx);
1559 [ # # ]: 0 : if (err)
1560 : : return err;
1561 : :
1562 : 0 : lif->hw_features = rte_le_to_cpu_64(ctx.cmd.lif_setattr.features &
1563 : : ctx.comp.lif_setattr.features);
1564 : :
1565 [ # # ]: 0 : if (lif->hw_features & IONIC_ETH_HW_VLAN_TX_TAG)
1566 : 0 : IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_VLAN_TX_TAG");
1567 [ # # ]: 0 : if (lif->hw_features & IONIC_ETH_HW_VLAN_RX_STRIP)
1568 : 0 : IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_VLAN_RX_STRIP");
1569 [ # # ]: 0 : if (lif->hw_features & IONIC_ETH_HW_VLAN_RX_FILTER)
1570 : 0 : IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_VLAN_RX_FILTER");
1571 [ # # ]: 0 : if (lif->hw_features & IONIC_ETH_HW_RX_HASH)
1572 : 0 : IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_RX_HASH");
1573 [ # # ]: 0 : if (lif->hw_features & IONIC_ETH_HW_TX_SG)
1574 : 0 : IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TX_SG");
1575 [ # # ]: 0 : if (lif->hw_features & IONIC_ETH_HW_RX_SG)
1576 : 0 : IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_RX_SG");
1577 [ # # ]: 0 : if (lif->hw_features & IONIC_ETH_HW_TX_CSUM)
1578 : 0 : IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TX_CSUM");
1579 [ # # ]: 0 : if (lif->hw_features & IONIC_ETH_HW_RX_CSUM)
1580 : 0 : IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_RX_CSUM");
1581 [ # # ]: 0 : if (lif->hw_features & IONIC_ETH_HW_TSO)
1582 : 0 : IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TSO");
1583 [ # # ]: 0 : if (lif->hw_features & IONIC_ETH_HW_TSO_IPV6)
1584 : 0 : IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TSO_IPV6");
1585 [ # # ]: 0 : if (lif->hw_features & IONIC_ETH_HW_TSO_ECN)
1586 : 0 : IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TSO_ECN");
1587 [ # # ]: 0 : if (lif->hw_features & IONIC_ETH_HW_TSO_GRE)
1588 : 0 : IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TSO_GRE");
1589 [ # # ]: 0 : if (lif->hw_features & IONIC_ETH_HW_TSO_GRE_CSUM)
1590 : 0 : IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TSO_GRE_CSUM");
1591 [ # # ]: 0 : if (lif->hw_features & IONIC_ETH_HW_TSO_IPXIP4)
1592 : 0 : IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TSO_IPXIP4");
1593 [ # # ]: 0 : if (lif->hw_features & IONIC_ETH_HW_TSO_IPXIP6)
1594 : 0 : IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TSO_IPXIP6");
1595 [ # # ]: 0 : if (lif->hw_features & IONIC_ETH_HW_TSO_UDP)
1596 : 0 : IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TSO_UDP");
1597 [ # # ]: 0 : if (lif->hw_features & IONIC_ETH_HW_TSO_UDP_CSUM)
1598 : 0 : IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TSO_UDP_CSUM");
1599 : :
1600 : : return 0;
1601 : : }
1602 : :
1603 : : int
1604 : 0 : ionic_lif_txq_init_nowait(struct ionic_tx_qcq *txq)
1605 : : {
1606 : : struct ionic_qcq *qcq = &txq->qcq;
1607 : 0 : struct ionic_queue *q = &qcq->q;
1608 : 0 : struct ionic_lif *lif = qcq->lif;
1609 : 0 : struct ionic_cq *cq = &qcq->cq;
1610 : 0 : struct ionic_admin_ctx *ctx = &txq->admin_ctx;
1611 : : int err;
1612 : :
1613 : 0 : *ctx = (struct ionic_admin_ctx) {
1614 : : .pending_work = true,
1615 : : .cmd.q_init = {
1616 : : .opcode = IONIC_CMD_Q_INIT,
1617 : 0 : .type = q->type,
1618 : 0 : .ver = lif->qtype_info[q->type].version,
1619 : 0 : .index = rte_cpu_to_le_32(q->index),
1620 : : .flags = rte_cpu_to_le_16(IONIC_QINIT_F_ENA),
1621 : : .intr_index = rte_cpu_to_le_16(IONIC_INTR_NONE),
1622 [ # # ]: 0 : .ring_size = rte_log2_u32(q->num_descs),
1623 : 0 : .cq_ring_base = rte_cpu_to_le_64(cq->base_pa),
1624 : 0 : .sg_ring_base = rte_cpu_to_le_64(q->sg_base_pa),
1625 : : },
1626 : : };
1627 : :
1628 [ # # ]: 0 : if (txq->flags & IONIC_QCQ_F_SG)
1629 : 0 : ctx->cmd.q_init.flags |= rte_cpu_to_le_16(IONIC_QINIT_F_SG);
1630 [ # # ]: 0 : if (txq->flags & IONIC_QCQ_F_CMB) {
1631 : 0 : ctx->cmd.q_init.flags |= rte_cpu_to_le_16(IONIC_QINIT_F_CMB);
1632 : 0 : ctx->cmd.q_init.ring_base = rte_cpu_to_le_64(q->cmb_base_pa);
1633 : : } else {
1634 : 0 : ctx->cmd.q_init.ring_base = rte_cpu_to_le_64(q->base_pa);
1635 : : }
1636 : :
1637 : 0 : IONIC_PRINT(DEBUG, "txq_init.index %d", q->index);
1638 : 0 : IONIC_PRINT(DEBUG, "txq_init.ring_base 0x%" PRIx64 "", q->base_pa);
1639 : 0 : IONIC_PRINT(DEBUG, "txq_init.ring_size %d",
1640 : : ctx->cmd.q_init.ring_size);
1641 : 0 : IONIC_PRINT(DEBUG, "txq_init.ver %u", ctx->cmd.q_init.ver);
1642 : :
1643 : 0 : ionic_q_reset(q);
1644 : 0 : ionic_cq_reset(cq);
1645 : :
1646 : : /* Caller responsible for calling ionic_lif_txq_init_done() */
1647 : 0 : err = ionic_adminq_post(lif, ctx);
1648 [ # # ]: 0 : if (err)
1649 : 0 : ctx->pending_work = false;
1650 : 0 : return err;
1651 : : }
1652 : :
1653 : : void
1654 : 0 : ionic_lif_txq_init_done(struct ionic_tx_qcq *txq)
1655 : : {
1656 : 0 : struct ionic_lif *lif = txq->qcq.lif;
1657 : 0 : struct ionic_queue *q = &txq->qcq.q;
1658 : : struct ionic_admin_ctx *ctx = &txq->admin_ctx;
1659 : :
1660 : 0 : q->hw_type = ctx->comp.q_init.hw_type;
1661 : 0 : q->hw_index = rte_le_to_cpu_32(ctx->comp.q_init.hw_index);
1662 : 0 : q->db = ionic_db_map(lif, q);
1663 : :
1664 : 0 : IONIC_PRINT(DEBUG, "txq->hw_type %d", q->hw_type);
1665 : 0 : IONIC_PRINT(DEBUG, "txq->hw_index %d", q->hw_index);
1666 : 0 : IONIC_PRINT(DEBUG, "txq->db %p", q->db);
1667 : :
1668 : 0 : txq->flags |= IONIC_QCQ_F_INITED;
1669 : 0 : }
1670 : :
1671 : : int
1672 : 0 : ionic_lif_rxq_init_nowait(struct ionic_rx_qcq *rxq)
1673 : : {
1674 : : struct ionic_qcq *qcq = &rxq->qcq;
1675 : 0 : struct ionic_queue *q = &qcq->q;
1676 : 0 : struct ionic_lif *lif = qcq->lif;
1677 : 0 : struct ionic_cq *cq = &qcq->cq;
1678 : 0 : struct ionic_admin_ctx *ctx = &rxq->admin_ctx;
1679 : : int err;
1680 : :
1681 : 0 : *ctx = (struct ionic_admin_ctx) {
1682 : : .pending_work = true,
1683 : : .cmd.q_init = {
1684 : : .opcode = IONIC_CMD_Q_INIT,
1685 : 0 : .type = q->type,
1686 : 0 : .ver = lif->qtype_info[q->type].version,
1687 : 0 : .index = rte_cpu_to_le_32(q->index),
1688 : : .flags = rte_cpu_to_le_16(IONIC_QINIT_F_ENA),
1689 : : .intr_index = rte_cpu_to_le_16(IONIC_INTR_NONE),
1690 [ # # ]: 0 : .ring_size = rte_log2_u32(q->num_descs),
1691 : 0 : .cq_ring_base = rte_cpu_to_le_64(cq->base_pa),
1692 : 0 : .sg_ring_base = rte_cpu_to_le_64(q->sg_base_pa),
1693 : : },
1694 : : };
1695 : :
1696 [ # # ]: 0 : if (rxq->flags & IONIC_QCQ_F_SG)
1697 : 0 : ctx->cmd.q_init.flags |= rte_cpu_to_le_16(IONIC_QINIT_F_SG);
1698 [ # # ]: 0 : if (rxq->flags & IONIC_QCQ_F_CMB) {
1699 : 0 : ctx->cmd.q_init.flags |= rte_cpu_to_le_16(IONIC_QINIT_F_CMB);
1700 : 0 : ctx->cmd.q_init.ring_base = rte_cpu_to_le_64(q->cmb_base_pa);
1701 : : } else {
1702 : 0 : ctx->cmd.q_init.ring_base = rte_cpu_to_le_64(q->base_pa);
1703 : : }
1704 : :
1705 : 0 : IONIC_PRINT(DEBUG, "rxq_init.index %d", q->index);
1706 : 0 : IONIC_PRINT(DEBUG, "rxq_init.ring_base 0x%" PRIx64 "", q->base_pa);
1707 : 0 : IONIC_PRINT(DEBUG, "rxq_init.ring_size %d",
1708 : : ctx->cmd.q_init.ring_size);
1709 : 0 : IONIC_PRINT(DEBUG, "rxq_init.ver %u", ctx->cmd.q_init.ver);
1710 : :
1711 : 0 : ionic_q_reset(q);
1712 : 0 : ionic_cq_reset(cq);
1713 : :
1714 : : /* Caller responsible for calling ionic_lif_rxq_init_done() */
1715 : 0 : err = ionic_adminq_post(lif, ctx);
1716 [ # # ]: 0 : if (err)
1717 : 0 : ctx->pending_work = false;
1718 : 0 : return err;
1719 : : }
1720 : :
1721 : : void
1722 : 0 : ionic_lif_rxq_init_done(struct ionic_rx_qcq *rxq)
1723 : : {
1724 : 0 : struct ionic_lif *lif = rxq->qcq.lif;
1725 : 0 : struct ionic_queue *q = &rxq->qcq.q;
1726 : : struct ionic_admin_ctx *ctx = &rxq->admin_ctx;
1727 : :
1728 : 0 : q->hw_type = ctx->comp.q_init.hw_type;
1729 : 0 : q->hw_index = rte_le_to_cpu_32(ctx->comp.q_init.hw_index);
1730 : 0 : q->db = ionic_db_map(lif, q);
1731 : :
1732 : 0 : rxq->flags |= IONIC_QCQ_F_INITED;
1733 : :
1734 : 0 : IONIC_PRINT(DEBUG, "rxq->hw_type %d", q->hw_type);
1735 : 0 : IONIC_PRINT(DEBUG, "rxq->hw_index %d", q->hw_index);
1736 : 0 : IONIC_PRINT(DEBUG, "rxq->db %p", q->db);
1737 : 0 : }
1738 : :
1739 : : static int
1740 : 0 : ionic_station_set(struct ionic_lif *lif)
1741 : : {
1742 : 0 : struct ionic_admin_ctx ctx = {
1743 : : .pending_work = true,
1744 : : .cmd.lif_getattr = {
1745 : : .opcode = IONIC_CMD_LIF_GETATTR,
1746 : : .attr = IONIC_LIF_ATTR_MAC,
1747 : : },
1748 : : };
1749 : : int err;
1750 : :
1751 : 0 : IONIC_PRINT_CALL();
1752 : :
1753 : 0 : err = ionic_adminq_post_wait(lif, &ctx);
1754 [ # # ]: 0 : if (err)
1755 : : return err;
1756 : :
1757 : 0 : memcpy(lif->mac_addr, ctx.comp.lif_getattr.mac, RTE_ETHER_ADDR_LEN);
1758 : :
1759 : 0 : return 0;
1760 : : }
1761 : :
1762 : : static void
1763 : 0 : ionic_lif_set_name(struct ionic_lif *lif)
1764 : : {
1765 : 0 : struct ionic_admin_ctx ctx = {
1766 : : .pending_work = true,
1767 : : .cmd.lif_setattr = {
1768 : : .opcode = IONIC_CMD_LIF_SETATTR,
1769 : : .attr = IONIC_LIF_ATTR_NAME,
1770 : : },
1771 : : };
1772 : :
1773 : 0 : memcpy(ctx.cmd.lif_setattr.name, lif->name,
1774 : : sizeof(ctx.cmd.lif_setattr.name) - 1);
1775 : :
1776 : 0 : ionic_adminq_post_wait(lif, &ctx);
1777 : 0 : }
1778 : :
1779 : : int
1780 : 0 : ionic_lif_init(struct ionic_lif *lif)
1781 : : {
1782 : 0 : struct ionic_dev *idev = &lif->adapter->idev;
1783 : : struct ionic_lif_init_comp comp;
1784 : : uint32_t retries = 5;
1785 : : int err;
1786 : :
1787 : 0 : memset(&lif->stats_base, 0, sizeof(lif->stats_base));
1788 : :
1789 : 0 : retry_lif_init:
1790 : 0 : ionic_dev_cmd_lif_init(idev, lif->info_pa);
1791 : 0 : err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
1792 [ # # ]: 0 : if (err == -EAGAIN && retries > 0) {
1793 : 0 : retries--;
1794 : 0 : rte_delay_us_block(IONIC_DEVCMD_RETRY_WAIT_US);
1795 : 0 : goto retry_lif_init;
1796 : : }
1797 [ # # ]: 0 : if (err)
1798 : : return err;
1799 : :
1800 : 0 : ionic_dev_cmd_comp(idev, &comp);
1801 : :
1802 : 0 : lif->hw_index = rte_cpu_to_le_16(comp.hw_index);
1803 : :
1804 : 0 : err = ionic_lif_adminq_init(lif);
1805 [ # # ]: 0 : if (err)
1806 : : return err;
1807 : :
1808 : 0 : err = ionic_lif_notifyq_init(lif);
1809 [ # # ]: 0 : if (err)
1810 : 0 : goto err_out_adminq_deinit;
1811 : :
1812 : : /*
1813 : : * Configure initial feature set
1814 : : * This will be updated later by the dev_configure() step
1815 : : */
1816 : 0 : lif->features = IONIC_ETH_HW_RX_HASH | IONIC_ETH_HW_VLAN_RX_FILTER;
1817 : :
1818 : 0 : err = ionic_lif_set_features(lif);
1819 [ # # ]: 0 : if (err)
1820 : 0 : goto err_out_notifyq_deinit;
1821 : :
1822 : 0 : err = ionic_rx_filters_init(lif);
1823 [ # # ]: 0 : if (err)
1824 : 0 : goto err_out_notifyq_deinit;
1825 : :
1826 : 0 : err = ionic_station_set(lif);
1827 [ # # ]: 0 : if (err)
1828 : 0 : goto err_out_rx_filter_deinit;
1829 : :
1830 : 0 : ionic_lif_set_name(lif);
1831 : :
1832 : 0 : lif->state |= IONIC_LIF_F_INITED;
1833 : :
1834 : 0 : return 0;
1835 : :
1836 : : err_out_rx_filter_deinit:
1837 : 0 : ionic_rx_filters_deinit(lif);
1838 : :
1839 [ # # ]: 0 : err_out_notifyq_deinit:
1840 : : ionic_lif_notifyq_deinit(lif);
1841 : :
1842 : 0 : err_out_adminq_deinit:
1843 : : ionic_lif_adminq_deinit(lif);
1844 : :
1845 : 0 : return err;
1846 : : }
1847 : :
1848 : : void
1849 : 0 : ionic_lif_deinit(struct ionic_lif *lif)
1850 : : {
1851 [ # # ]: 0 : if (!(lif->state & IONIC_LIF_F_INITED))
1852 : : return;
1853 : :
1854 : 0 : ionic_rx_filters_deinit(lif);
1855 : : ionic_lif_rss_teardown(lif);
1856 : : ionic_lif_notifyq_deinit(lif);
1857 : : ionic_lif_adminq_deinit(lif);
1858 : :
1859 : 0 : lif->state &= ~IONIC_LIF_F_INITED;
1860 : : }
1861 : :
1862 : : void
1863 : 0 : ionic_lif_configure_vlan_offload(struct ionic_lif *lif, int mask)
1864 : : {
1865 : 0 : struct rte_eth_dev *eth_dev = lif->eth_dev;
1866 : 0 : struct rte_eth_rxmode *rxmode = ð_dev->data->dev_conf.rxmode;
1867 : :
1868 : : /*
1869 : : * IONIC_ETH_HW_VLAN_RX_FILTER cannot be turned off, so
1870 : : * set RTE_ETH_RX_OFFLOAD_VLAN_FILTER and ignore RTE_ETH_VLAN_FILTER_MASK
1871 : : */
1872 : 0 : rxmode->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
1873 : :
1874 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
1875 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
1876 : 0 : lif->features |= IONIC_ETH_HW_VLAN_RX_STRIP;
1877 : : else
1878 : 0 : lif->features &= ~IONIC_ETH_HW_VLAN_RX_STRIP;
1879 : : }
1880 : 0 : }
1881 : :
1882 : : void
1883 : 0 : ionic_lif_configure_rx_sg_offload(struct ionic_lif *lif)
1884 : : {
1885 : 0 : struct rte_eth_rxmode *rxmode = &lif->eth_dev->data->dev_conf.rxmode;
1886 : :
1887 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_SCATTER) {
1888 : 0 : lif->features |= IONIC_ETH_HW_RX_SG;
1889 : 0 : lif->eth_dev->data->scattered_rx = 1;
1890 : : } else {
1891 : 0 : lif->features &= ~IONIC_ETH_HW_RX_SG;
1892 : 0 : lif->eth_dev->data->scattered_rx = 0;
1893 : : }
1894 : 0 : }
1895 : :
1896 : : void
1897 : 0 : ionic_lif_configure(struct ionic_lif *lif)
1898 : : {
1899 : 0 : struct rte_eth_rxmode *rxmode = &lif->eth_dev->data->dev_conf.rxmode;
1900 : : struct rte_eth_txmode *txmode = &lif->eth_dev->data->dev_conf.txmode;
1901 : 0 : struct ionic_identity *ident = &lif->adapter->ident;
1902 : : union ionic_lif_config *cfg = &ident->lif.eth.config;
1903 : 0 : uint32_t ntxqs_per_lif =
1904 : : rte_le_to_cpu_32(cfg->queue_count[IONIC_QTYPE_TXQ]);
1905 : 0 : uint32_t nrxqs_per_lif =
1906 : : rte_le_to_cpu_32(cfg->queue_count[IONIC_QTYPE_RXQ]);
1907 : 0 : uint32_t nrxqs = lif->eth_dev->data->nb_rx_queues;
1908 : 0 : uint32_t ntxqs = lif->eth_dev->data->nb_tx_queues;
1909 : :
1910 : 0 : lif->port_id = lif->eth_dev->data->port_id;
1911 : :
1912 : 0 : IONIC_PRINT(DEBUG, "Configuring LIF on port %u",
1913 : : lif->port_id);
1914 : :
1915 [ # # ]: 0 : if (nrxqs > 0)
1916 : 0 : nrxqs_per_lif = RTE_MIN(nrxqs_per_lif, nrxqs);
1917 : :
1918 [ # # ]: 0 : if (ntxqs > 0)
1919 : 0 : ntxqs_per_lif = RTE_MIN(ntxqs_per_lif, ntxqs);
1920 : :
1921 : 0 : lif->nrxqcqs = nrxqs_per_lif;
1922 : 0 : lif->ntxqcqs = ntxqs_per_lif;
1923 : :
1924 : : /* Update the LIF configuration based on the eth_dev */
1925 : :
1926 : : /*
1927 : : * NB: While it is true that RSS_HASH is always enabled on ionic,
1928 : : * setting this flag unconditionally causes problems in DTS.
1929 : : * rxmode->offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
1930 : : */
1931 : :
1932 : : /* RX per-port */
1933 : :
1934 : 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM ||
1935 [ # # ]: 0 : rxmode->offloads & RTE_ETH_RX_OFFLOAD_UDP_CKSUM ||
1936 : : rxmode->offloads & RTE_ETH_RX_OFFLOAD_TCP_CKSUM)
1937 : 0 : lif->features |= IONIC_ETH_HW_RX_CSUM;
1938 : : else
1939 : 0 : lif->features &= ~IONIC_ETH_HW_RX_CSUM;
1940 : :
1941 : : /*
1942 : : * NB: RX_SG may be enabled later during rx_queue_setup() if
1943 : : * required by the mbuf/mtu configuration
1944 : : */
1945 : 0 : ionic_lif_configure_rx_sg_offload(lif);
1946 : :
1947 : : /* Covers VLAN_STRIP */
1948 : 0 : ionic_lif_configure_vlan_offload(lif, RTE_ETH_VLAN_STRIP_MASK);
1949 : :
1950 : : /* TX per-port */
1951 : :
1952 : 0 : if (txmode->offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM ||
1953 : : txmode->offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM ||
1954 : : txmode->offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM ||
1955 [ # # ]: 0 : txmode->offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM ||
1956 : : txmode->offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)
1957 : 0 : lif->features |= IONIC_ETH_HW_TX_CSUM;
1958 : : else
1959 : 0 : lif->features &= ~IONIC_ETH_HW_TX_CSUM;
1960 : :
1961 [ # # ]: 0 : if (txmode->offloads & RTE_ETH_TX_OFFLOAD_VLAN_INSERT)
1962 : 0 : lif->features |= IONIC_ETH_HW_VLAN_TX_TAG;
1963 : : else
1964 : 0 : lif->features &= ~IONIC_ETH_HW_VLAN_TX_TAG;
1965 : :
1966 [ # # ]: 0 : if (txmode->offloads & RTE_ETH_TX_OFFLOAD_MULTI_SEGS)
1967 : 0 : lif->features |= IONIC_ETH_HW_TX_SG;
1968 : : else
1969 : 0 : lif->features &= ~IONIC_ETH_HW_TX_SG;
1970 : :
1971 [ # # ]: 0 : if (txmode->offloads & RTE_ETH_TX_OFFLOAD_TCP_TSO) {
1972 : 0 : lif->features |= IONIC_ETH_HW_TSO;
1973 : 0 : lif->features |= IONIC_ETH_HW_TSO_IPV6;
1974 : 0 : lif->features |= IONIC_ETH_HW_TSO_ECN;
1975 : : } else {
1976 : 0 : lif->features &= ~IONIC_ETH_HW_TSO;
1977 : 0 : lif->features &= ~IONIC_ETH_HW_TSO_IPV6;
1978 : 0 : lif->features &= ~IONIC_ETH_HW_TSO_ECN;
1979 : : }
1980 : 0 : }
1981 : :
1982 : : int
1983 : 0 : ionic_lif_start(struct ionic_lif *lif)
1984 : : {
1985 : 0 : struct rte_eth_dev *dev = lif->eth_dev;
1986 : : uint32_t rx_mode;
1987 : : uint32_t i, j, chunk;
1988 : : int err;
1989 : : bool fatal = false;
1990 : :
1991 : 0 : err = ionic_lif_rss_setup(lif);
1992 [ # # ]: 0 : if (err)
1993 : : return err;
1994 : :
1995 [ # # ]: 0 : if (!lif->rx_mode) {
1996 : 0 : IONIC_PRINT(DEBUG, "Setting RX mode on %s",
1997 : : lif->name);
1998 : :
1999 : : rx_mode = IONIC_RX_MODE_F_UNICAST;
2000 : : rx_mode |= IONIC_RX_MODE_F_MULTICAST;
2001 : : rx_mode |= IONIC_RX_MODE_F_BROADCAST;
2002 : :
2003 : : ionic_set_rx_mode(lif, rx_mode);
2004 : : }
2005 : :
2006 : 0 : IONIC_PRINT(DEBUG, "Starting %u RX queues and %u TX queues "
2007 : : "on port %u",
2008 : : lif->nrxqcqs, lif->ntxqcqs, lif->port_id);
2009 : :
2010 : 0 : chunk = ionic_adminq_space_avail(lif);
2011 : :
2012 [ # # ]: 0 : for (i = 0; i < lif->nrxqcqs; i += chunk) {
2013 [ # # ]: 0 : if (lif->rxqcqs[0]->flags & IONIC_QCQ_F_DEFERRED) {
2014 : 0 : IONIC_PRINT(DEBUG, "Rx queue start deferred");
2015 : 0 : break;
2016 : : }
2017 : :
2018 [ # # # # ]: 0 : for (j = 0; j < chunk && i + j < lif->nrxqcqs; j++) {
2019 : 0 : err = ionic_dev_rx_queue_start_firsthalf(dev, i + j);
2020 [ # # ]: 0 : if (err) {
2021 : : fatal = true;
2022 : : break;
2023 : : }
2024 : : }
2025 : :
2026 [ # # # # ]: 0 : for (j = 0; j < chunk && i + j < lif->nrxqcqs; j++) {
2027 : : /* Commands that failed to post return immediately */
2028 : 0 : err = ionic_dev_rx_queue_start_secondhalf(dev, i + j);
2029 [ # # ]: 0 : if (err)
2030 : : /* Don't break */
2031 : : fatal = true;
2032 : : }
2033 : : }
2034 [ # # ]: 0 : if (fatal)
2035 : : return -EIO;
2036 : :
2037 [ # # ]: 0 : for (i = 0; i < lif->ntxqcqs; i += chunk) {
2038 [ # # ]: 0 : if (lif->txqcqs[0]->flags & IONIC_QCQ_F_DEFERRED) {
2039 : 0 : IONIC_PRINT(DEBUG, "Tx queue start deferred");
2040 : 0 : break;
2041 : : }
2042 : :
2043 [ # # # # ]: 0 : for (j = 0; j < chunk && i + j < lif->ntxqcqs; j++) {
2044 : 0 : err = ionic_dev_tx_queue_start_firsthalf(dev, i + j);
2045 [ # # ]: 0 : if (err) {
2046 : : fatal = true;
2047 : : break;
2048 : : }
2049 : : }
2050 : :
2051 [ # # # # ]: 0 : for (j = 0; j < chunk && i + j < lif->ntxqcqs; j++) {
2052 : : /* Commands that failed to post return immediately */
2053 : 0 : err = ionic_dev_tx_queue_start_secondhalf(dev, i + j);
2054 [ # # ]: 0 : if (err)
2055 : : /* Don't break */
2056 : : fatal = true;
2057 : : }
2058 : : }
2059 [ # # ]: 0 : if (fatal)
2060 : : return -EIO;
2061 : :
2062 : : /* Carrier ON here */
2063 : 0 : lif->state |= IONIC_LIF_F_UP;
2064 : :
2065 : 0 : ionic_link_status_check(lif);
2066 : :
2067 : 0 : return 0;
2068 : : }
2069 : :
2070 : : int
2071 : 0 : ionic_lif_identify(struct ionic_adapter *adapter)
2072 : : {
2073 : 0 : struct ionic_dev *idev = &adapter->idev;
2074 : : struct ionic_identity *ident = &adapter->ident;
2075 : : union ionic_lif_config *cfg = &ident->lif.eth.config;
2076 : : uint32_t lif_words = RTE_DIM(ident->lif.words);
2077 : : uint32_t cmd_words = RTE_DIM(idev->dev_cmd->data);
2078 : : uint32_t i, nwords;
2079 : : int err;
2080 : :
2081 : 0 : ionic_dev_cmd_lif_identify(idev, IONIC_LIF_TYPE_CLASSIC,
2082 : : IONIC_IDENTITY_VERSION_1);
2083 : 0 : err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
2084 [ # # ]: 0 : if (err)
2085 : : return (err);
2086 : :
2087 : : nwords = RTE_MIN(lif_words, cmd_words);
2088 [ # # ]: 0 : for (i = 0; i < nwords; i++)
2089 : 0 : ident->lif.words[i] = ioread32(&idev->dev_cmd->data[i]);
2090 : :
2091 : 0 : IONIC_PRINT(INFO, "capabilities 0x%" PRIx64 " ",
2092 : : rte_le_to_cpu_64(ident->lif.capabilities));
2093 : :
2094 : 0 : IONIC_PRINT(INFO, "eth.max_ucast_filters 0x%" PRIx32 " ",
2095 : : rte_le_to_cpu_32(ident->lif.eth.max_ucast_filters));
2096 : 0 : IONIC_PRINT(INFO, "eth.max_mcast_filters 0x%" PRIx32 " ",
2097 : : rte_le_to_cpu_32(ident->lif.eth.max_mcast_filters));
2098 : :
2099 : 0 : IONIC_PRINT(INFO, "eth.features 0x%" PRIx64 " ",
2100 : : rte_le_to_cpu_64(cfg->features));
2101 : 0 : IONIC_PRINT(INFO, "eth.queue_count[IONIC_QTYPE_ADMINQ] 0x%" PRIx32 " ",
2102 : : rte_le_to_cpu_32(cfg->queue_count[IONIC_QTYPE_ADMINQ]));
2103 : 0 : IONIC_PRINT(INFO, "eth.queue_count[IONIC_QTYPE_NOTIFYQ] 0x%" PRIx32 " ",
2104 : : rte_le_to_cpu_32(cfg->queue_count[IONIC_QTYPE_NOTIFYQ]));
2105 : 0 : IONIC_PRINT(INFO, "eth.queue_count[IONIC_QTYPE_RXQ] 0x%" PRIx32 " ",
2106 : : rte_le_to_cpu_32(cfg->queue_count[IONIC_QTYPE_RXQ]));
2107 : 0 : IONIC_PRINT(INFO, "eth.queue_count[IONIC_QTYPE_TXQ] 0x%" PRIx32 " ",
2108 : : rte_le_to_cpu_32(cfg->queue_count[IONIC_QTYPE_TXQ]));
2109 : :
2110 : 0 : return 0;
2111 : : }
2112 : :
2113 : : int
2114 : 0 : ionic_lifs_size(struct ionic_adapter *adapter)
2115 : : {
2116 : : struct ionic_identity *ident = &adapter->ident;
2117 : : union ionic_lif_config *cfg = &ident->lif.eth.config;
2118 : 0 : uint32_t nintrs, dev_nintrs = rte_le_to_cpu_32(ident->dev.nintrs);
2119 : :
2120 : 0 : adapter->max_ntxqs_per_lif =
2121 : 0 : rte_le_to_cpu_32(cfg->queue_count[IONIC_QTYPE_TXQ]);
2122 : 0 : adapter->max_nrxqs_per_lif =
2123 : 0 : rte_le_to_cpu_32(cfg->queue_count[IONIC_QTYPE_RXQ]);
2124 : :
2125 : : nintrs = 1 /* notifyq */;
2126 : :
2127 [ # # ]: 0 : if (nintrs > dev_nintrs) {
2128 : 0 : IONIC_PRINT(ERR,
2129 : : "At most %d intr supported, minimum req'd is %u",
2130 : : dev_nintrs, nintrs);
2131 : 0 : return -ENOSPC;
2132 : : }
2133 : :
2134 : 0 : adapter->nintrs = nintrs;
2135 : :
2136 : 0 : return 0;
2137 : : }
|