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