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