Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2014-2018 Chelsio Communications.
3 : : * All rights reserved.
4 : : */
5 : :
6 : : #include <sys/queue.h>
7 : : #include <stdio.h>
8 : : #include <errno.h>
9 : : #include <stdint.h>
10 : : #include <string.h>
11 : : #include <unistd.h>
12 : : #include <stdarg.h>
13 : : #include <inttypes.h>
14 : : #include <netinet/in.h>
15 : :
16 : : #include <rte_byteorder.h>
17 : : #include <rte_common.h>
18 : : #include <rte_cycles.h>
19 : : #include <rte_interrupts.h>
20 : : #include <rte_log.h>
21 : : #include <rte_debug.h>
22 : : #include <rte_pci.h>
23 : : #include <bus_pci_driver.h>
24 : : #include <rte_branch_prediction.h>
25 : : #include <rte_memory.h>
26 : : #include <rte_tailq.h>
27 : : #include <rte_eal.h>
28 : : #include <rte_alarm.h>
29 : : #include <rte_ether.h>
30 : : #include <ethdev_driver.h>
31 : : #include <ethdev_pci.h>
32 : : #include <rte_malloc.h>
33 : : #include <rte_random.h>
34 : : #include <dev_driver.h>
35 : :
36 : : #include "cxgbe.h"
37 : : #include "cxgbe_pfvf.h"
38 : : #include "cxgbe_flow.h"
39 : :
40 : : /*
41 : : * Macros needed to support the PCI Device ID Table ...
42 : : */
43 : : #define CH_PCI_DEVICE_ID_TABLE_DEFINE_BEGIN \
44 : : static const struct rte_pci_id cxgb4_pci_tbl[] = {
45 : : #define CH_PCI_DEVICE_ID_FUNCTION 0x4
46 : :
47 : : #define PCI_VENDOR_ID_CHELSIO 0x1425
48 : :
49 : : #define CH_PCI_ID_TABLE_ENTRY(devid) \
50 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_CHELSIO, (devid)) }
51 : :
52 : : #define CH_PCI_DEVICE_ID_TABLE_DEFINE_END \
53 : : { .vendor_id = 0, } \
54 : : }
55 : :
56 : : /*
57 : : *... and the PCI ID Table itself ...
58 : : */
59 : : #include "base/t4_pci_id_tbl.h"
60 : :
61 : 0 : uint16_t cxgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
62 : : uint16_t nb_pkts)
63 : : {
64 : : struct sge_eth_txq *txq = (struct sge_eth_txq *)tx_queue;
65 : : uint16_t pkts_sent, pkts_remain;
66 : : uint16_t total_sent = 0;
67 : : uint16_t idx = 0;
68 : : int ret = 0;
69 : :
70 : 0 : t4_os_lock(&txq->txq_lock);
71 : : /* free up desc from already completed tx */
72 : 0 : reclaim_completed_tx(&txq->q);
73 [ # # ]: 0 : if (unlikely(!nb_pkts))
74 : 0 : goto out_unlock;
75 : :
76 : 0 : rte_prefetch0(rte_pktmbuf_mtod(tx_pkts[0], volatile void *));
77 [ # # ]: 0 : while (total_sent < nb_pkts) {
78 : 0 : pkts_remain = nb_pkts - total_sent;
79 : :
80 [ # # ]: 0 : for (pkts_sent = 0; pkts_sent < pkts_remain; pkts_sent++) {
81 : 0 : idx = total_sent + pkts_sent;
82 [ # # ]: 0 : if ((idx + 1) < nb_pkts)
83 : 0 : rte_prefetch0(rte_pktmbuf_mtod(tx_pkts[idx + 1],
84 : : volatile void *));
85 : 0 : ret = t4_eth_xmit(txq, tx_pkts[idx], nb_pkts);
86 [ # # ]: 0 : if (ret < 0)
87 : : break;
88 : : }
89 [ # # ]: 0 : if (!pkts_sent)
90 : : break;
91 : 0 : total_sent += pkts_sent;
92 : : /* reclaim as much as possible */
93 : 0 : reclaim_completed_tx(&txq->q);
94 : : }
95 : :
96 : 0 : out_unlock:
97 : : t4_os_unlock(&txq->txq_lock);
98 : 0 : return total_sent;
99 : : }
100 : :
101 : 0 : uint16_t cxgbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
102 : : uint16_t nb_pkts)
103 : : {
104 : : struct sge_eth_rxq *rxq = (struct sge_eth_rxq *)rx_queue;
105 : : unsigned int work_done;
106 : :
107 [ # # ]: 0 : if (cxgbe_poll(&rxq->rspq, rx_pkts, (unsigned int)nb_pkts, &work_done))
108 : 0 : dev_err(adapter, "error in cxgbe poll\n");
109 : :
110 : 0 : return work_done;
111 : : }
112 : :
113 : 0 : int cxgbe_dev_info_get(struct rte_eth_dev *eth_dev,
114 : : struct rte_eth_dev_info *device_info)
115 : : {
116 : 0 : struct port_info *pi = eth_dev->data->dev_private;
117 : 0 : struct adapter *adapter = pi->adapter;
118 : :
119 : : static const struct rte_eth_desc_lim cxgbe_desc_lim = {
120 : : .nb_max = CXGBE_MAX_RING_DESC_SIZE,
121 : : .nb_min = CXGBE_MIN_RING_DESC_SIZE,
122 : : .nb_align = 1,
123 : : };
124 : :
125 : 0 : device_info->min_rx_bufsize = CXGBE_MIN_RX_BUFSIZE;
126 : 0 : device_info->max_rx_pktlen = CXGBE_MAX_RX_PKTLEN;
127 : 0 : device_info->max_rx_queues = adapter->sge.max_ethqsets;
128 : 0 : device_info->max_tx_queues = adapter->sge.max_ethqsets;
129 : 0 : device_info->max_mac_addrs = 1;
130 : : /* XXX: For now we support one MAC/port */
131 : 0 : device_info->max_vfs = adapter->params.arch.vfcount;
132 : 0 : device_info->max_vmdq_pools = 0; /* XXX: For now no support for VMDQ */
133 : :
134 : 0 : device_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
135 : :
136 : 0 : device_info->rx_queue_offload_capa = 0UL;
137 : 0 : device_info->rx_offload_capa = CXGBE_RX_OFFLOADS;
138 : :
139 : 0 : device_info->tx_queue_offload_capa = 0UL;
140 : 0 : device_info->tx_offload_capa = CXGBE_TX_OFFLOADS;
141 : :
142 : 0 : device_info->reta_size = pi->rss_size;
143 : 0 : device_info->hash_key_size = CXGBE_DEFAULT_RSS_KEY_LEN;
144 : 0 : device_info->flow_type_rss_offloads = CXGBE_RSS_HF_ALL;
145 : :
146 : 0 : device_info->rx_desc_lim = cxgbe_desc_lim;
147 : 0 : device_info->tx_desc_lim = cxgbe_desc_lim;
148 : 0 : cxgbe_get_speed_caps(pi, &device_info->speed_capa);
149 : :
150 : 0 : return 0;
151 : : }
152 : :
153 : 0 : int cxgbe_dev_promiscuous_enable(struct rte_eth_dev *eth_dev)
154 : : {
155 : 0 : struct port_info *pi = eth_dev->data->dev_private;
156 : 0 : struct adapter *adapter = pi->adapter;
157 : : int ret;
158 : :
159 [ # # ]: 0 : if (adapter->params.rawf_size != 0) {
160 : 0 : ret = cxgbe_mpstcam_rawf_enable(pi);
161 [ # # ]: 0 : if (ret < 0)
162 : : return ret;
163 : : }
164 : :
165 : 0 : return t4_set_rxmode(adapter, adapter->mbox, pi->viid, -1,
166 : : 1, -1, 1, -1, false);
167 : : }
168 : :
169 : 0 : int cxgbe_dev_promiscuous_disable(struct rte_eth_dev *eth_dev)
170 : : {
171 : 0 : struct port_info *pi = eth_dev->data->dev_private;
172 : 0 : struct adapter *adapter = pi->adapter;
173 : : int ret;
174 : :
175 [ # # ]: 0 : if (adapter->params.rawf_size != 0) {
176 : 0 : ret = cxgbe_mpstcam_rawf_disable(pi);
177 [ # # ]: 0 : if (ret < 0)
178 : : return ret;
179 : : }
180 : :
181 : 0 : return t4_set_rxmode(adapter, adapter->mbox, pi->viid, -1,
182 : : 0, -1, 1, -1, false);
183 : : }
184 : :
185 : 0 : int cxgbe_dev_allmulticast_enable(struct rte_eth_dev *eth_dev)
186 : : {
187 : 0 : struct port_info *pi = eth_dev->data->dev_private;
188 : 0 : struct adapter *adapter = pi->adapter;
189 : :
190 : : /* TODO: address filters ?? */
191 : :
192 : 0 : return t4_set_rxmode(adapter, adapter->mbox, pi->viid, -1,
193 : : -1, 1, 1, -1, false);
194 : : }
195 : :
196 : 0 : int cxgbe_dev_allmulticast_disable(struct rte_eth_dev *eth_dev)
197 : : {
198 : 0 : struct port_info *pi = eth_dev->data->dev_private;
199 : 0 : struct adapter *adapter = pi->adapter;
200 : :
201 : : /* TODO: address filters ?? */
202 : :
203 : 0 : return t4_set_rxmode(adapter, adapter->mbox, pi->viid, -1,
204 : : -1, 0, 1, -1, false);
205 : : }
206 : :
207 : 0 : int cxgbe_dev_link_update(struct rte_eth_dev *eth_dev,
208 : : int wait_to_complete)
209 : : {
210 : 0 : struct port_info *pi = eth_dev->data->dev_private;
211 : : unsigned int i, work_done, budget = 32;
212 : : struct link_config *lc = &pi->link_cfg;
213 : 0 : struct adapter *adapter = pi->adapter;
214 : 0 : u8 old_link = pi->link_cfg.link_ok;
215 : : struct sge *s = &adapter->sge;
216 : : struct rte_eth_link new_link;
217 : :
218 [ # # ]: 0 : for (i = 0; i < CXGBE_LINK_STATUS_POLL_CNT; i++) {
219 [ # # ]: 0 : if (!s->fw_evtq.desc)
220 : : break;
221 : :
222 : 0 : cxgbe_poll(&s->fw_evtq, NULL, budget, &work_done);
223 : :
224 : : /* Exit if link status changed or always forced up */
225 [ # # # # ]: 0 : if (pi->link_cfg.link_ok != old_link ||
226 : 0 : cxgbe_force_linkup(adapter))
227 : : break;
228 : :
229 [ # # ]: 0 : if (!wait_to_complete)
230 : : break;
231 : :
232 : : rte_delay_ms(CXGBE_LINK_STATUS_POLL_MS);
233 : : }
234 : :
235 : : memset(&new_link, 0, sizeof(new_link));
236 : 0 : new_link.link_status = cxgbe_force_linkup(adapter) ?
237 [ # # ]: 0 : RTE_ETH_LINK_UP : pi->link_cfg.link_ok;
238 : 0 : new_link.link_autoneg = (lc->link_caps & FW_PORT_CAP32_ANEG) ? 1 : 0;
239 : 0 : new_link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
240 [ # # ]: 0 : new_link.link_speed = t4_fwcap_to_speed(lc->link_caps);
241 : :
242 : 0 : return rte_eth_linkstatus_set(eth_dev, &new_link);
243 : : }
244 : :
245 : : /**
246 : : * Set device link up.
247 : : */
248 : 0 : int cxgbe_dev_set_link_up(struct rte_eth_dev *dev)
249 : : {
250 : 0 : struct port_info *pi = dev->data->dev_private;
251 : 0 : struct adapter *adapter = pi->adapter;
252 : : unsigned int work_done, budget = 32;
253 : : struct sge *s = &adapter->sge;
254 : : int ret;
255 : :
256 [ # # ]: 0 : if (!s->fw_evtq.desc)
257 : : return -ENOMEM;
258 : :
259 : : /* Flush all link events */
260 : 0 : cxgbe_poll(&s->fw_evtq, NULL, budget, &work_done);
261 : :
262 : : /* If link already up, nothing to do */
263 [ # # ]: 0 : if (pi->link_cfg.link_ok)
264 : : return 0;
265 : :
266 : 0 : ret = cxgbe_set_link_status(pi, true);
267 [ # # ]: 0 : if (ret)
268 : : return ret;
269 : :
270 : 0 : cxgbe_dev_link_update(dev, 1);
271 : 0 : return 0;
272 : : }
273 : :
274 : : /**
275 : : * Set device link down.
276 : : */
277 : 0 : int cxgbe_dev_set_link_down(struct rte_eth_dev *dev)
278 : : {
279 : 0 : struct port_info *pi = dev->data->dev_private;
280 : 0 : struct adapter *adapter = pi->adapter;
281 : : unsigned int work_done, budget = 32;
282 : : struct sge *s = &adapter->sge;
283 : : int ret;
284 : :
285 [ # # ]: 0 : if (!s->fw_evtq.desc)
286 : : return -ENOMEM;
287 : :
288 : : /* Flush all link events */
289 : 0 : cxgbe_poll(&s->fw_evtq, NULL, budget, &work_done);
290 : :
291 : : /* If link already down, nothing to do */
292 [ # # ]: 0 : if (!pi->link_cfg.link_ok)
293 : : return 0;
294 : :
295 : 0 : ret = cxgbe_set_link_status(pi, false);
296 [ # # ]: 0 : if (ret)
297 : : return ret;
298 : :
299 : 0 : cxgbe_dev_link_update(dev, 0);
300 : 0 : return 0;
301 : : }
302 : :
303 : 0 : int cxgbe_dev_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
304 : : {
305 : 0 : struct port_info *pi = eth_dev->data->dev_private;
306 : 0 : struct adapter *adapter = pi->adapter;
307 : 0 : uint16_t new_mtu = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
308 : :
309 : 0 : return t4_set_rxmode(adapter, adapter->mbox, pi->viid, new_mtu, -1, -1,
310 : : -1, -1, true);
311 : : }
312 : :
313 : : /*
314 : : * Stop device.
315 : : */
316 : 0 : int cxgbe_dev_close(struct rte_eth_dev *eth_dev)
317 : : {
318 : 0 : struct port_info *temp_pi, *pi = eth_dev->data->dev_private;
319 : 0 : struct adapter *adapter = pi->adapter;
320 : : u8 i;
321 : :
322 : 0 : CXGBE_FUNC_TRACE();
323 : :
324 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
325 : : return 0;
326 : :
327 [ # # ]: 0 : if (!(adapter->flags & FULL_INIT_DONE))
328 : : return 0;
329 : :
330 [ # # ]: 0 : if (!pi->viid)
331 : : return 0;
332 : :
333 : 0 : cxgbe_down(pi);
334 : 0 : t4_sge_eth_release_queues(pi);
335 : 0 : t4_free_vi(adapter, adapter->mbox, adapter->pf, 0, pi->viid);
336 : 0 : pi->viid = 0;
337 : :
338 : : /* Free up the adapter-wide resources only after all the ports
339 : : * under this PF have been closed.
340 : : */
341 [ # # ]: 0 : for_each_port(adapter, i) {
342 [ # # ]: 0 : temp_pi = adap2pinfo(adapter, i);
343 [ # # ]: 0 : if (temp_pi->viid)
344 : : return 0;
345 : : }
346 : :
347 : 0 : cxgbe_close(adapter);
348 : 0 : rte_free(adapter);
349 : :
350 : 0 : return 0;
351 : : }
352 : :
353 : : /* Start the device.
354 : : * It returns 0 on success.
355 : : */
356 : 0 : int cxgbe_dev_start(struct rte_eth_dev *eth_dev)
357 : : {
358 : 0 : struct port_info *pi = eth_dev->data->dev_private;
359 : : struct rte_eth_rxmode *rx_conf = ð_dev->data->dev_conf.rxmode;
360 : 0 : struct adapter *adapter = pi->adapter;
361 : : int err = 0, i;
362 : :
363 : 0 : CXGBE_FUNC_TRACE();
364 : :
365 : : /*
366 : : * If we don't have a connection to the firmware there's nothing we
367 : : * can do.
368 : : */
369 [ # # ]: 0 : if (!(adapter->flags & FW_OK)) {
370 : : err = -ENXIO;
371 : 0 : goto out;
372 : : }
373 : :
374 [ # # ]: 0 : if (!(adapter->flags & FULL_INIT_DONE)) {
375 : 0 : err = cxgbe_up(adapter);
376 [ # # ]: 0 : if (err < 0)
377 : 0 : goto out;
378 : : }
379 : :
380 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_SCATTER)
381 : 0 : eth_dev->data->scattered_rx = 1;
382 : : else
383 : 0 : eth_dev->data->scattered_rx = 0;
384 : :
385 : 0 : cxgbe_enable_rx_queues(pi);
386 : :
387 : 0 : err = cxgbe_setup_rss(pi);
388 [ # # ]: 0 : if (err)
389 : 0 : goto out;
390 : :
391 [ # # ]: 0 : for (i = 0; i < pi->n_tx_qsets; i++) {
392 : 0 : err = cxgbe_dev_tx_queue_start(eth_dev, i);
393 [ # # ]: 0 : if (err)
394 : 0 : goto out;
395 : : }
396 : :
397 [ # # ]: 0 : for (i = 0; i < pi->n_rx_qsets; i++) {
398 : 0 : err = cxgbe_dev_rx_queue_start(eth_dev, i);
399 [ # # ]: 0 : if (err)
400 : 0 : goto out;
401 : : }
402 : :
403 : 0 : err = cxgbe_link_start(pi);
404 [ # # ]: 0 : if (err)
405 : 0 : goto out;
406 : :
407 : 0 : out:
408 : 0 : return err;
409 : : }
410 : :
411 : : /*
412 : : * Stop device: disable rx and tx functions to allow for reconfiguring.
413 : : */
414 : 0 : int cxgbe_dev_stop(struct rte_eth_dev *eth_dev)
415 : : {
416 : 0 : struct port_info *pi = eth_dev->data->dev_private;
417 : 0 : struct adapter *adapter = pi->adapter;
418 : : uint16_t i;
419 : :
420 : 0 : CXGBE_FUNC_TRACE();
421 : :
422 [ # # ]: 0 : if (!(adapter->flags & FULL_INIT_DONE))
423 : : return 0;
424 : :
425 : 0 : cxgbe_down(pi);
426 : :
427 : : /*
428 : : * We clear queues only if both tx and rx path of the port
429 : : * have been disabled
430 : : */
431 : 0 : t4_sge_eth_clear_queues(pi);
432 : 0 : eth_dev->data->scattered_rx = 0;
433 : :
434 [ # # ]: 0 : for (i = 0; i < eth_dev->data->nb_rx_queues; i++)
435 : 0 : eth_dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
436 [ # # ]: 0 : for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
437 : 0 : eth_dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
438 : :
439 : : return 0;
440 : : }
441 : :
442 : 0 : int cxgbe_dev_configure(struct rte_eth_dev *eth_dev)
443 : : {
444 : 0 : struct port_info *pi = eth_dev->data->dev_private;
445 : 0 : struct adapter *adapter = pi->adapter;
446 : : int err;
447 : :
448 : 0 : CXGBE_FUNC_TRACE();
449 : :
450 [ # # ]: 0 : if (eth_dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
451 : 0 : eth_dev->data->dev_conf.rxmode.offloads |=
452 : : RTE_ETH_RX_OFFLOAD_RSS_HASH;
453 : :
454 [ # # ]: 0 : if (!(adapter->flags & FW_QUEUE_BOUND)) {
455 : 0 : err = cxgbe_setup_sge_fwevtq(adapter);
456 [ # # ]: 0 : if (err)
457 : : return err;
458 [ # # ]: 0 : adapter->flags |= FW_QUEUE_BOUND;
459 [ # # ]: 0 : if (is_pf4(adapter)) {
460 : 0 : err = cxgbe_setup_sge_ctrl_txq(adapter);
461 [ # # ]: 0 : if (err)
462 : : return err;
463 : : }
464 : : }
465 : :
466 : 0 : err = cxgbe_cfg_queue_count(eth_dev);
467 [ # # ]: 0 : if (err)
468 : 0 : return err;
469 : :
470 : : return 0;
471 : : }
472 : :
473 : 0 : int cxgbe_dev_tx_queue_start(struct rte_eth_dev *eth_dev, uint16_t tx_queue_id)
474 : : {
475 : : int ret;
476 : 0 : struct sge_eth_txq *txq = (struct sge_eth_txq *)
477 : 0 : (eth_dev->data->tx_queues[tx_queue_id]);
478 : :
479 : 0 : dev_debug(NULL, "%s: tx_queue_id = %d\n", __func__, tx_queue_id);
480 : :
481 : 0 : ret = t4_sge_eth_txq_start(txq);
482 [ # # ]: 0 : if (ret == 0)
483 : 0 : eth_dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
484 : :
485 : 0 : return ret;
486 : : }
487 : :
488 : 0 : int cxgbe_dev_tx_queue_stop(struct rte_eth_dev *eth_dev, uint16_t tx_queue_id)
489 : : {
490 : : int ret;
491 : 0 : struct sge_eth_txq *txq = (struct sge_eth_txq *)
492 : 0 : (eth_dev->data->tx_queues[tx_queue_id]);
493 : :
494 : 0 : dev_debug(NULL, "%s: tx_queue_id = %d\n", __func__, tx_queue_id);
495 : :
496 : 0 : ret = t4_sge_eth_txq_stop(txq);
497 [ # # ]: 0 : if (ret == 0)
498 : 0 : eth_dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
499 : :
500 : 0 : return ret;
501 : : }
502 : :
503 : 0 : int cxgbe_dev_tx_queue_setup(struct rte_eth_dev *eth_dev,
504 : : uint16_t queue_idx, uint16_t nb_desc,
505 : : unsigned int socket_id,
506 : : const struct rte_eth_txconf *tx_conf __rte_unused)
507 : : {
508 : 0 : struct port_info *pi = eth_dev->data->dev_private;
509 : 0 : struct adapter *adapter = pi->adapter;
510 : : struct sge *s = &adapter->sge;
511 : : unsigned int temp_nb_desc;
512 : : struct sge_eth_txq *txq;
513 : : int err = 0;
514 : :
515 : 0 : txq = &s->ethtxq[pi->first_txqset + queue_idx];
516 : 0 : dev_debug(adapter, "%s: eth_dev->data->nb_tx_queues = %d; queue_idx = %d; nb_desc = %d; socket_id = %d; pi->first_qset = %u\n",
517 : : __func__, eth_dev->data->nb_tx_queues, queue_idx, nb_desc,
518 : : socket_id, pi->first_txqset);
519 : :
520 : : /* Free up the existing queue */
521 [ # # ]: 0 : if (eth_dev->data->tx_queues[queue_idx]) {
522 : 0 : cxgbe_dev_tx_queue_release(eth_dev, queue_idx);
523 : 0 : eth_dev->data->tx_queues[queue_idx] = NULL;
524 : : }
525 : :
526 : 0 : eth_dev->data->tx_queues[queue_idx] = (void *)txq;
527 : :
528 : : /* Sanity Checking
529 : : *
530 : : * nb_desc should be > 1023 and <= CXGBE_MAX_RING_DESC_SIZE
531 : : */
532 : 0 : temp_nb_desc = nb_desc;
533 [ # # ]: 0 : if (nb_desc < CXGBE_MIN_RING_DESC_SIZE) {
534 : 0 : dev_warn(adapter, "%s: number of descriptors must be >= %d. Using default [%d]\n",
535 : : __func__, CXGBE_MIN_RING_DESC_SIZE,
536 : : CXGBE_DEFAULT_TX_DESC_SIZE);
537 : : temp_nb_desc = CXGBE_DEFAULT_TX_DESC_SIZE;
538 [ # # ]: 0 : } else if (nb_desc > CXGBE_MAX_RING_DESC_SIZE) {
539 : 0 : dev_err(adapter, "%s: number of descriptors must be between %d and %d inclusive. Default [%d]\n",
540 : : __func__, CXGBE_MIN_RING_DESC_SIZE,
541 : : CXGBE_MAX_RING_DESC_SIZE, CXGBE_DEFAULT_TX_DESC_SIZE);
542 : 0 : return -(EINVAL);
543 : : }
544 : :
545 : 0 : txq->q.size = temp_nb_desc;
546 : :
547 : 0 : err = t4_sge_alloc_eth_txq(adapter, txq, eth_dev, queue_idx,
548 : 0 : s->fw_evtq.cntxt_id, socket_id);
549 : :
550 : 0 : dev_debug(adapter, "%s: txq->q.cntxt_id= %u txq->q.abs_id= %u err = %d\n",
551 : : __func__, txq->q.cntxt_id, txq->q.abs_id, err);
552 : 0 : return err;
553 : : }
554 : :
555 : 0 : void cxgbe_dev_tx_queue_release(struct rte_eth_dev *eth_dev, uint16_t qid)
556 : : {
557 : 0 : struct sge_eth_txq *txq = eth_dev->data->tx_queues[qid];
558 : :
559 [ # # ]: 0 : if (txq) {
560 : 0 : struct port_info *pi = (struct port_info *)
561 : 0 : (txq->eth_dev->data->dev_private);
562 : 0 : struct adapter *adap = pi->adapter;
563 : :
564 : 0 : dev_debug(adapter, "%s: pi->port_id = %d; tx_queue_id = %d\n",
565 : : __func__, pi->port_id, txq->q.cntxt_id);
566 : :
567 : 0 : t4_sge_eth_txq_release(adap, txq);
568 : : }
569 : 0 : }
570 : :
571 : 0 : int cxgbe_dev_rx_queue_start(struct rte_eth_dev *eth_dev, uint16_t rx_queue_id)
572 : : {
573 : 0 : struct port_info *pi = eth_dev->data->dev_private;
574 : 0 : struct adapter *adap = pi->adapter;
575 : : struct sge_eth_rxq *rxq;
576 : : int ret;
577 : :
578 : 0 : dev_debug(adapter, "%s: pi->port_id = %d; rx_queue_id = %d\n",
579 : : __func__, pi->port_id, rx_queue_id);
580 : :
581 : 0 : rxq = eth_dev->data->rx_queues[rx_queue_id];
582 : 0 : ret = t4_sge_eth_rxq_start(adap, rxq);
583 [ # # ]: 0 : if (ret == 0)
584 : 0 : eth_dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
585 : :
586 : 0 : return ret;
587 : : }
588 : :
589 : 0 : int cxgbe_dev_rx_queue_stop(struct rte_eth_dev *eth_dev, uint16_t rx_queue_id)
590 : : {
591 : 0 : struct port_info *pi = eth_dev->data->dev_private;
592 : 0 : struct adapter *adap = pi->adapter;
593 : : struct sge_eth_rxq *rxq;
594 : : int ret;
595 : :
596 : 0 : dev_debug(adapter, "%s: pi->port_id = %d; rx_queue_id = %d\n",
597 : : __func__, pi->port_id, rx_queue_id);
598 : :
599 : 0 : rxq = eth_dev->data->rx_queues[rx_queue_id];
600 : 0 : ret = t4_sge_eth_rxq_stop(adap, rxq);
601 [ # # ]: 0 : if (ret == 0)
602 : 0 : eth_dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
603 : :
604 : 0 : return ret;
605 : : }
606 : :
607 : 0 : int cxgbe_dev_rx_queue_setup(struct rte_eth_dev *eth_dev,
608 : : uint16_t queue_idx, uint16_t nb_desc,
609 : : unsigned int socket_id,
610 : : const struct rte_eth_rxconf *rx_conf __rte_unused,
611 : : struct rte_mempool *mp)
612 : : {
613 : 0 : unsigned int pkt_len = eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
614 : : RTE_ETHER_CRC_LEN;
615 : 0 : struct port_info *pi = eth_dev->data->dev_private;
616 : 0 : struct adapter *adapter = pi->adapter;
617 : : struct rte_eth_dev_info dev_info;
618 : : struct sge *s = &adapter->sge;
619 : : unsigned int temp_nb_desc;
620 : : int err = 0, msi_idx = 0;
621 : : struct sge_eth_rxq *rxq;
622 : :
623 : 0 : rxq = &s->ethrxq[pi->first_rxqset + queue_idx];
624 : 0 : dev_debug(adapter, "%s: eth_dev->data->nb_rx_queues = %d; queue_idx = %d; nb_desc = %d; socket_id = %d; mp = %p\n",
625 : : __func__, eth_dev->data->nb_rx_queues, queue_idx, nb_desc,
626 : : socket_id, mp);
627 : :
628 : 0 : err = cxgbe_dev_info_get(eth_dev, &dev_info);
629 [ # # ]: 0 : if (err != 0) {
630 : 0 : dev_err(adap, "%s: error during getting ethernet device info",
631 : : __func__);
632 : 0 : return err;
633 : : }
634 : :
635 : : /* Must accommodate at least RTE_ETHER_MIN_MTU */
636 [ # # ]: 0 : if ((pkt_len < dev_info.min_rx_bufsize) ||
637 [ # # ]: 0 : (pkt_len > dev_info.max_rx_pktlen)) {
638 : 0 : dev_err(adap, "%s: max pkt len must be > %d and <= %d\n",
639 : : __func__, dev_info.min_rx_bufsize,
640 : : dev_info.max_rx_pktlen);
641 : 0 : return -EINVAL;
642 : : }
643 : :
644 : : /* Free up the existing queue */
645 [ # # ]: 0 : if (eth_dev->data->rx_queues[queue_idx]) {
646 : 0 : cxgbe_dev_rx_queue_release(eth_dev, queue_idx);
647 : 0 : eth_dev->data->rx_queues[queue_idx] = NULL;
648 : : }
649 : :
650 : 0 : eth_dev->data->rx_queues[queue_idx] = (void *)rxq;
651 : :
652 : : /* Sanity Checking
653 : : *
654 : : * nb_desc should be > 0 and <= CXGBE_MAX_RING_DESC_SIZE
655 : : */
656 : 0 : temp_nb_desc = nb_desc;
657 [ # # ]: 0 : if (nb_desc < CXGBE_MIN_RING_DESC_SIZE) {
658 : 0 : dev_warn(adapter, "%s: number of descriptors must be >= %d. Using default [%d]\n",
659 : : __func__, CXGBE_MIN_RING_DESC_SIZE,
660 : : CXGBE_DEFAULT_RX_DESC_SIZE);
661 : : temp_nb_desc = CXGBE_DEFAULT_RX_DESC_SIZE;
662 [ # # ]: 0 : } else if (nb_desc > CXGBE_MAX_RING_DESC_SIZE) {
663 : 0 : dev_err(adapter, "%s: number of descriptors must be between %d and %d inclusive. Default [%d]\n",
664 : : __func__, CXGBE_MIN_RING_DESC_SIZE,
665 : : CXGBE_MAX_RING_DESC_SIZE, CXGBE_DEFAULT_RX_DESC_SIZE);
666 : 0 : return -(EINVAL);
667 : : }
668 : :
669 : 0 : rxq->rspq.size = temp_nb_desc;
670 : 0 : rxq->fl.size = temp_nb_desc;
671 : :
672 [ # # ]: 0 : err = t4_sge_alloc_rxq(adapter, &rxq->rspq, false, eth_dev, msi_idx,
673 : : &rxq->fl, NULL,
674 : : is_pf4(adapter) ?
675 : 0 : t4_get_tp_ch_map(adapter, pi->tx_chan) : 0, mp,
676 : : queue_idx, socket_id);
677 : :
678 : 0 : dev_debug(adapter, "%s: err = %d; port_id = %d; cntxt_id = %u; abs_id = %u\n",
679 : : __func__, err, pi->port_id, rxq->rspq.cntxt_id,
680 : : rxq->rspq.abs_id);
681 : 0 : return err;
682 : : }
683 : :
684 : 0 : void cxgbe_dev_rx_queue_release(struct rte_eth_dev *eth_dev, uint16_t qid)
685 : : {
686 : 0 : struct sge_eth_rxq *rxq = eth_dev->data->rx_queues[qid];
687 : :
688 [ # # ]: 0 : if (rxq) {
689 : 0 : struct port_info *pi = (struct port_info *)
690 : 0 : (rxq->rspq.eth_dev->data->dev_private);
691 : 0 : struct adapter *adap = pi->adapter;
692 : :
693 : 0 : dev_debug(adapter, "%s: pi->port_id = %d; rx_queue_id = %d\n",
694 : : __func__, pi->port_id, rxq->rspq.cntxt_id);
695 : :
696 : 0 : t4_sge_eth_rxq_release(adap, rxq);
697 : : }
698 : 0 : }
699 : :
700 : : /*
701 : : * Get port statistics.
702 : : */
703 : 0 : static int cxgbe_dev_stats_get(struct rte_eth_dev *eth_dev,
704 : : struct rte_eth_stats *eth_stats)
705 : : {
706 : 0 : struct port_info *pi = eth_dev->data->dev_private;
707 : 0 : struct adapter *adapter = pi->adapter;
708 : : struct sge *s = &adapter->sge;
709 : : struct port_stats ps;
710 : : unsigned int i;
711 : :
712 : 0 : cxgbe_stats_get(pi, &ps);
713 : :
714 : : /* RX Stats */
715 : 0 : eth_stats->imissed = ps.rx_ovflow0 + ps.rx_ovflow1 +
716 : 0 : ps.rx_ovflow2 + ps.rx_ovflow3 +
717 : 0 : ps.rx_trunc0 + ps.rx_trunc1 +
718 : 0 : ps.rx_trunc2 + ps.rx_trunc3;
719 [ # # ]: 0 : for (i = 0; i < NCHAN; i++)
720 : 0 : eth_stats->imissed += ps.rx_tp_tnl_cong_drops[i];
721 : :
722 : 0 : eth_stats->ierrors = ps.rx_symbol_err + ps.rx_fcs_err +
723 : 0 : ps.rx_jabber + ps.rx_too_long + ps.rx_runt +
724 : 0 : ps.rx_len_err;
725 : :
726 : : /* TX Stats */
727 : 0 : eth_stats->opackets = ps.tx_frames;
728 : 0 : eth_stats->obytes = ps.tx_octets;
729 : 0 : eth_stats->oerrors = ps.tx_error_frames;
730 : :
731 [ # # ]: 0 : for (i = 0; i < pi->n_rx_qsets; i++) {
732 : 0 : struct sge_eth_rxq *rxq = &s->ethrxq[pi->first_rxqset + i];
733 : :
734 : 0 : eth_stats->ipackets += rxq->stats.pkts;
735 : 0 : eth_stats->ibytes += rxq->stats.rx_bytes;
736 : : }
737 : :
738 : 0 : return 0;
739 : : }
740 : :
741 : : /*
742 : : * Reset port statistics.
743 : : */
744 : 0 : static int cxgbe_dev_stats_reset(struct rte_eth_dev *eth_dev)
745 : : {
746 : 0 : struct port_info *pi = eth_dev->data->dev_private;
747 : 0 : struct adapter *adapter = pi->adapter;
748 : : struct sge *s = &adapter->sge;
749 : : unsigned int i;
750 : :
751 : 0 : cxgbe_stats_reset(pi);
752 [ # # ]: 0 : for (i = 0; i < pi->n_rx_qsets; i++) {
753 : 0 : struct sge_eth_rxq *rxq = &s->ethrxq[pi->first_rxqset + i];
754 : :
755 : 0 : memset(&rxq->stats, 0, sizeof(rxq->stats));
756 : : }
757 [ # # ]: 0 : for (i = 0; i < pi->n_tx_qsets; i++) {
758 : 0 : struct sge_eth_txq *txq = &s->ethtxq[pi->first_txqset + i];
759 : :
760 : 0 : memset(&txq->stats, 0, sizeof(txq->stats));
761 : : }
762 : :
763 : 0 : return 0;
764 : : }
765 : :
766 : : /* Store extended statistics names and its offset in stats structure */
767 : : struct cxgbe_dev_xstats_name_off {
768 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
769 : : unsigned int offset;
770 : : };
771 : :
772 : : static const struct cxgbe_dev_xstats_name_off cxgbe_dev_rxq_stats_strings[] = {
773 : : {"packets", offsetof(struct sge_eth_rx_stats, pkts)},
774 : : {"bytes", offsetof(struct sge_eth_rx_stats, rx_bytes)},
775 : : {"checksum_offloads", offsetof(struct sge_eth_rx_stats, rx_cso)},
776 : : {"vlan_extractions", offsetof(struct sge_eth_rx_stats, vlan_ex)},
777 : : {"dropped_packets", offsetof(struct sge_eth_rx_stats, rx_drops)},
778 : : };
779 : :
780 : : static const struct cxgbe_dev_xstats_name_off cxgbe_dev_txq_stats_strings[] = {
781 : : {"packets", offsetof(struct sge_eth_tx_stats, pkts)},
782 : : {"bytes", offsetof(struct sge_eth_tx_stats, tx_bytes)},
783 : : {"tso_requests", offsetof(struct sge_eth_tx_stats, tso)},
784 : : {"checksum_offloads", offsetof(struct sge_eth_tx_stats, tx_cso)},
785 : : {"vlan_insertions", offsetof(struct sge_eth_tx_stats, vlan_ins)},
786 : : {"packet_mapping_errors",
787 : : offsetof(struct sge_eth_tx_stats, mapping_err)},
788 : : {"coalesced_wrs", offsetof(struct sge_eth_tx_stats, coal_wr)},
789 : : {"coalesced_packets", offsetof(struct sge_eth_tx_stats, coal_pkts)},
790 : : };
791 : :
792 : : static const struct cxgbe_dev_xstats_name_off cxgbe_dev_port_stats_strings[] = {
793 : : {"tx_bytes", offsetof(struct port_stats, tx_octets)},
794 : : {"tx_packets", offsetof(struct port_stats, tx_frames)},
795 : : {"tx_broadcast_packets", offsetof(struct port_stats, tx_bcast_frames)},
796 : : {"tx_multicast_packets", offsetof(struct port_stats, tx_mcast_frames)},
797 : : {"tx_unicast_packets", offsetof(struct port_stats, tx_ucast_frames)},
798 : : {"tx_error_packets", offsetof(struct port_stats, tx_error_frames)},
799 : : {"tx_size_64_packets", offsetof(struct port_stats, tx_frames_64)},
800 : : {"tx_size_65_to_127_packets",
801 : : offsetof(struct port_stats, tx_frames_65_127)},
802 : : {"tx_size_128_to_255_packets",
803 : : offsetof(struct port_stats, tx_frames_128_255)},
804 : : {"tx_size_256_to_511_packets",
805 : : offsetof(struct port_stats, tx_frames_256_511)},
806 : : {"tx_size_512_to_1023_packets",
807 : : offsetof(struct port_stats, tx_frames_512_1023)},
808 : : {"tx_size_1024_to_1518_packets",
809 : : offsetof(struct port_stats, tx_frames_1024_1518)},
810 : : {"tx_size_1519_to_max_packets",
811 : : offsetof(struct port_stats, tx_frames_1519_max)},
812 : : {"tx_drop_packets", offsetof(struct port_stats, tx_drop)},
813 : : {"tx_pause_frames", offsetof(struct port_stats, tx_pause)},
814 : : {"tx_ppp_pri0_packets", offsetof(struct port_stats, tx_ppp0)},
815 : : {"tx_ppp_pri1_packets", offsetof(struct port_stats, tx_ppp1)},
816 : : {"tx_ppp_pri2_packets", offsetof(struct port_stats, tx_ppp2)},
817 : : {"tx_ppp_pri3_packets", offsetof(struct port_stats, tx_ppp3)},
818 : : {"tx_ppp_pri4_packets", offsetof(struct port_stats, tx_ppp4)},
819 : : {"tx_ppp_pri5_packets", offsetof(struct port_stats, tx_ppp5)},
820 : : {"tx_ppp_pri6_packets", offsetof(struct port_stats, tx_ppp6)},
821 : : {"tx_ppp_pri7_packets", offsetof(struct port_stats, tx_ppp7)},
822 : : {"rx_bytes", offsetof(struct port_stats, rx_octets)},
823 : : {"rx_packets", offsetof(struct port_stats, rx_frames)},
824 : : {"rx_broadcast_packets", offsetof(struct port_stats, rx_bcast_frames)},
825 : : {"rx_multicast_packets", offsetof(struct port_stats, rx_mcast_frames)},
826 : : {"rx_unicast_packets", offsetof(struct port_stats, rx_ucast_frames)},
827 : : {"rx_too_long_packets", offsetof(struct port_stats, rx_too_long)},
828 : : {"rx_jabber_packets", offsetof(struct port_stats, rx_jabber)},
829 : : {"rx_fcs_error_packets", offsetof(struct port_stats, rx_fcs_err)},
830 : : {"rx_length_error_packets", offsetof(struct port_stats, rx_len_err)},
831 : : {"rx_symbol_error_packets",
832 : : offsetof(struct port_stats, rx_symbol_err)},
833 : : {"rx_short_packets", offsetof(struct port_stats, rx_runt)},
834 : : {"rx_size_64_packets", offsetof(struct port_stats, rx_frames_64)},
835 : : {"rx_size_65_to_127_packets",
836 : : offsetof(struct port_stats, rx_frames_65_127)},
837 : : {"rx_size_128_to_255_packets",
838 : : offsetof(struct port_stats, rx_frames_128_255)},
839 : : {"rx_size_256_to_511_packets",
840 : : offsetof(struct port_stats, rx_frames_256_511)},
841 : : {"rx_size_512_to_1023_packets",
842 : : offsetof(struct port_stats, rx_frames_512_1023)},
843 : : {"rx_size_1024_to_1518_packets",
844 : : offsetof(struct port_stats, rx_frames_1024_1518)},
845 : : {"rx_size_1519_to_max_packets",
846 : : offsetof(struct port_stats, rx_frames_1519_max)},
847 : : {"rx_pause_packets", offsetof(struct port_stats, rx_pause)},
848 : : {"rx_ppp_pri0_packets", offsetof(struct port_stats, rx_ppp0)},
849 : : {"rx_ppp_pri1_packets", offsetof(struct port_stats, rx_ppp1)},
850 : : {"rx_ppp_pri2_packets", offsetof(struct port_stats, rx_ppp2)},
851 : : {"rx_ppp_pri3_packets", offsetof(struct port_stats, rx_ppp3)},
852 : : {"rx_ppp_pri4_packets", offsetof(struct port_stats, rx_ppp4)},
853 : : {"rx_ppp_pri5_packets", offsetof(struct port_stats, rx_ppp5)},
854 : : {"rx_ppp_pri6_packets", offsetof(struct port_stats, rx_ppp6)},
855 : : {"rx_ppp_pri7_packets", offsetof(struct port_stats, rx_ppp7)},
856 : : {"rx_bg0_dropped_packets", offsetof(struct port_stats, rx_ovflow0)},
857 : : {"rx_bg1_dropped_packets", offsetof(struct port_stats, rx_ovflow1)},
858 : : {"rx_bg2_dropped_packets", offsetof(struct port_stats, rx_ovflow2)},
859 : : {"rx_bg3_dropped_packets", offsetof(struct port_stats, rx_ovflow3)},
860 : : {"rx_bg0_truncated_packets", offsetof(struct port_stats, rx_trunc0)},
861 : : {"rx_bg1_truncated_packets", offsetof(struct port_stats, rx_trunc1)},
862 : : {"rx_bg2_truncated_packets", offsetof(struct port_stats, rx_trunc2)},
863 : : {"rx_bg3_truncated_packets", offsetof(struct port_stats, rx_trunc3)},
864 : : {"rx_tp_tnl_cong_drops0",
865 : : offsetof(struct port_stats, rx_tp_tnl_cong_drops[0])},
866 : : {"rx_tp_tnl_cong_drops1",
867 : : offsetof(struct port_stats, rx_tp_tnl_cong_drops[1])},
868 : : {"rx_tp_tnl_cong_drops2",
869 : : offsetof(struct port_stats, rx_tp_tnl_cong_drops[2])},
870 : : {"rx_tp_tnl_cong_drops3",
871 : : offsetof(struct port_stats, rx_tp_tnl_cong_drops[3])},
872 : : };
873 : :
874 : : static const struct cxgbe_dev_xstats_name_off
875 : : cxgbevf_dev_port_stats_strings[] = {
876 : : {"tx_bytes", offsetof(struct port_stats, tx_octets)},
877 : : {"tx_broadcast_packets", offsetof(struct port_stats, tx_bcast_frames)},
878 : : {"tx_multicast_packets", offsetof(struct port_stats, tx_mcast_frames)},
879 : : {"tx_unicast_packets", offsetof(struct port_stats, tx_ucast_frames)},
880 : : {"tx_drop_packets", offsetof(struct port_stats, tx_drop)},
881 : : {"rx_broadcast_packets", offsetof(struct port_stats, rx_bcast_frames)},
882 : : {"rx_multicast_packets", offsetof(struct port_stats, rx_mcast_frames)},
883 : : {"rx_unicast_packets", offsetof(struct port_stats, rx_ucast_frames)},
884 : : {"rx_length_error_packets", offsetof(struct port_stats, rx_len_err)},
885 : : };
886 : :
887 : : #define CXGBE_NB_RXQ_STATS RTE_DIM(cxgbe_dev_rxq_stats_strings)
888 : : #define CXGBE_NB_TXQ_STATS RTE_DIM(cxgbe_dev_txq_stats_strings)
889 : : #define CXGBE_NB_PORT_STATS RTE_DIM(cxgbe_dev_port_stats_strings)
890 : : #define CXGBEVF_NB_PORT_STATS RTE_DIM(cxgbevf_dev_port_stats_strings)
891 : :
892 : : static u16 cxgbe_dev_xstats_count(struct port_info *pi)
893 : : {
894 : : u16 count;
895 : :
896 : 0 : count = (pi->n_tx_qsets * CXGBE_NB_TXQ_STATS) +
897 : 0 : (pi->n_rx_qsets * CXGBE_NB_RXQ_STATS);
898 : :
899 [ # # ]: 0 : if (is_pf4(pi->adapter) != 0)
900 : 0 : count += CXGBE_NB_PORT_STATS;
901 : : else
902 : 0 : count += CXGBEVF_NB_PORT_STATS;
903 : :
904 : : return count;
905 : : }
906 : :
907 : 0 : static int cxgbe_dev_xstats(struct rte_eth_dev *dev,
908 : : struct rte_eth_xstat_name *xstats_names,
909 : : struct rte_eth_xstat *xstats, unsigned int size)
910 : : {
911 : : const struct cxgbe_dev_xstats_name_off *xstats_str;
912 : 0 : struct port_info *pi = dev->data->dev_private;
913 [ # # ]: 0 : struct adapter *adap = pi->adapter;
914 : : struct sge *s = &adap->sge;
915 : : u16 count, i, qid, nstats;
916 : : struct port_stats ps;
917 : : u64 *stats_ptr;
918 : :
919 : : count = cxgbe_dev_xstats_count(pi);
920 [ # # ]: 0 : if (size < count)
921 : 0 : return count;
922 : :
923 [ # # ]: 0 : if (is_pf4(adap) != 0) {
924 : : /* port stats for PF*/
925 : 0 : cxgbe_stats_get(pi, &ps);
926 : : xstats_str = cxgbe_dev_port_stats_strings;
927 : : nstats = CXGBE_NB_PORT_STATS;
928 : : } else {
929 : : /* port stats for VF*/
930 : 0 : cxgbevf_stats_get(pi, &ps);
931 : : xstats_str = cxgbevf_dev_port_stats_strings;
932 : : nstats = CXGBEVF_NB_PORT_STATS;
933 : : }
934 : :
935 : : count = 0;
936 [ # # ]: 0 : for (i = 0; i < nstats; i++, count++) {
937 [ # # ]: 0 : if (xstats_names != NULL)
938 : 0 : snprintf(xstats_names[count].name,
939 : : sizeof(xstats_names[count].name),
940 : 0 : "%s", xstats_str[i].name);
941 [ # # ]: 0 : if (xstats != NULL) {
942 : 0 : stats_ptr = RTE_PTR_ADD(&ps,
943 : : xstats_str[i].offset);
944 : 0 : xstats[count].value = *stats_ptr;
945 : 0 : xstats[count].id = count;
946 : : }
947 : : }
948 : :
949 : : /* per-txq stats */
950 : : xstats_str = cxgbe_dev_txq_stats_strings;
951 [ # # ]: 0 : for (qid = 0; qid < pi->n_tx_qsets; qid++) {
952 : 0 : struct sge_eth_txq *txq = &s->ethtxq[pi->first_txqset + qid];
953 : :
954 [ # # ]: 0 : for (i = 0; i < CXGBE_NB_TXQ_STATS; i++, count++) {
955 [ # # ]: 0 : if (xstats_names != NULL)
956 : 0 : snprintf(xstats_names[count].name,
957 : : sizeof(xstats_names[count].name),
958 : : "tx_q%u_%s",
959 : 0 : qid, xstats_str[i].name);
960 [ # # ]: 0 : if (xstats != NULL) {
961 : 0 : stats_ptr = RTE_PTR_ADD(&txq->stats,
962 : : xstats_str[i].offset);
963 : 0 : xstats[count].value = *stats_ptr;
964 : 0 : xstats[count].id = count;
965 : : }
966 : : }
967 : : }
968 : :
969 : : /* per-rxq stats */
970 : : xstats_str = cxgbe_dev_rxq_stats_strings;
971 [ # # ]: 0 : for (qid = 0; qid < pi->n_rx_qsets; qid++) {
972 : 0 : struct sge_eth_rxq *rxq = &s->ethrxq[pi->first_rxqset + qid];
973 : :
974 [ # # ]: 0 : for (i = 0; i < CXGBE_NB_RXQ_STATS; i++, count++) {
975 [ # # ]: 0 : if (xstats_names != NULL)
976 : 0 : snprintf(xstats_names[count].name,
977 : : sizeof(xstats_names[count].name),
978 : : "rx_q%u_%s",
979 : 0 : qid, xstats_str[i].name);
980 [ # # ]: 0 : if (xstats != NULL) {
981 : 0 : stats_ptr = RTE_PTR_ADD(&rxq->stats,
982 : : xstats_str[i].offset);
983 : 0 : xstats[count].value = *stats_ptr;
984 : 0 : xstats[count].id = count;
985 : : }
986 : : }
987 : : }
988 : :
989 : 0 : return count;
990 : : }
991 : :
992 : : /* Get port extended statistics by ID. */
993 : 0 : int cxgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev,
994 : : const uint64_t *ids, uint64_t *values,
995 : : unsigned int n)
996 : : {
997 [ # # ]: 0 : struct port_info *pi = dev->data->dev_private;
998 : : struct rte_eth_xstat *xstats_copy;
999 : : u16 count, i;
1000 : : int ret = 0;
1001 : :
1002 : : count = cxgbe_dev_xstats_count(pi);
1003 [ # # ]: 0 : if (ids == NULL || values == NULL)
1004 : 0 : return count;
1005 : :
1006 : 0 : xstats_copy = rte_calloc(NULL, count, sizeof(*xstats_copy), 0);
1007 [ # # ]: 0 : if (xstats_copy == NULL)
1008 : : return -ENOMEM;
1009 : :
1010 : 0 : cxgbe_dev_xstats(dev, NULL, xstats_copy, count);
1011 : :
1012 [ # # ]: 0 : for (i = 0; i < n; i++) {
1013 [ # # ]: 0 : if (ids[i] >= count) {
1014 : : ret = -EINVAL;
1015 : 0 : goto out_err;
1016 : : }
1017 : 0 : values[i] = xstats_copy[ids[i]].value;
1018 : : }
1019 : :
1020 : 0 : ret = n;
1021 : :
1022 : 0 : out_err:
1023 : 0 : rte_free(xstats_copy);
1024 : 0 : return ret;
1025 : : }
1026 : :
1027 : : /* Get names of port extended statistics by ID. */
1028 : 0 : int cxgbe_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,
1029 : : const uint64_t *ids,
1030 : : struct rte_eth_xstat_name *xnames,
1031 : : unsigned int n)
1032 : : {
1033 [ # # ]: 0 : struct port_info *pi = dev->data->dev_private;
1034 : : struct rte_eth_xstat_name *xnames_copy;
1035 : : u16 count, i;
1036 : : int ret = 0;
1037 : :
1038 : : count = cxgbe_dev_xstats_count(pi);
1039 [ # # ]: 0 : if (ids == NULL || xnames == NULL)
1040 : 0 : return count;
1041 : :
1042 : 0 : xnames_copy = rte_calloc(NULL, count, sizeof(*xnames_copy), 0);
1043 [ # # ]: 0 : if (xnames_copy == NULL)
1044 : : return -ENOMEM;
1045 : :
1046 : 0 : cxgbe_dev_xstats(dev, xnames_copy, NULL, count);
1047 : :
1048 [ # # ]: 0 : for (i = 0; i < n; i++) {
1049 [ # # ]: 0 : if (ids[i] >= count) {
1050 : : ret = -EINVAL;
1051 : 0 : goto out_err;
1052 : : }
1053 : 0 : rte_strlcpy(xnames[i].name, xnames_copy[ids[i]].name,
1054 : : sizeof(xnames[i].name));
1055 : : }
1056 : :
1057 : 0 : ret = n;
1058 : :
1059 : 0 : out_err:
1060 : 0 : rte_free(xnames_copy);
1061 : 0 : return ret;
1062 : : }
1063 : :
1064 : : /* Get port extended statistics. */
1065 : 0 : int cxgbe_dev_xstats_get(struct rte_eth_dev *dev,
1066 : : struct rte_eth_xstat *xstats, unsigned int n)
1067 : : {
1068 : 0 : return cxgbe_dev_xstats(dev, NULL, xstats, n);
1069 : : }
1070 : :
1071 : : /* Get names of port extended statistics. */
1072 : 0 : int cxgbe_dev_xstats_get_names(struct rte_eth_dev *dev,
1073 : : struct rte_eth_xstat_name *xstats_names,
1074 : : unsigned int n)
1075 : : {
1076 : 0 : return cxgbe_dev_xstats(dev, xstats_names, NULL, n);
1077 : : }
1078 : :
1079 : : /* Reset port extended statistics. */
1080 : 0 : static int cxgbe_dev_xstats_reset(struct rte_eth_dev *dev)
1081 : : {
1082 : 0 : return cxgbe_dev_stats_reset(dev);
1083 : : }
1084 : :
1085 : 0 : static int cxgbe_flow_ctrl_get(struct rte_eth_dev *eth_dev,
1086 : : struct rte_eth_fc_conf *fc_conf)
1087 : : {
1088 : 0 : struct port_info *pi = eth_dev->data->dev_private;
1089 : : struct link_config *lc = &pi->link_cfg;
1090 : : u8 rx_pause = 0, tx_pause = 0;
1091 : 0 : u32 caps = lc->link_caps;
1092 : :
1093 [ # # ]: 0 : if (caps & FW_PORT_CAP32_ANEG)
1094 : 0 : fc_conf->autoneg = 1;
1095 : :
1096 [ # # ]: 0 : if (caps & FW_PORT_CAP32_FC_TX)
1097 : : tx_pause = 1;
1098 : :
1099 [ # # ]: 0 : if (caps & FW_PORT_CAP32_FC_RX)
1100 : : rx_pause = 1;
1101 : :
1102 [ # # ]: 0 : if (rx_pause && tx_pause)
1103 : 0 : fc_conf->mode = RTE_ETH_FC_FULL;
1104 [ # # ]: 0 : else if (rx_pause)
1105 : 0 : fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
1106 [ # # ]: 0 : else if (tx_pause)
1107 : 0 : fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
1108 : : else
1109 : 0 : fc_conf->mode = RTE_ETH_FC_NONE;
1110 : 0 : return 0;
1111 : : }
1112 : :
1113 : 0 : static int cxgbe_flow_ctrl_set(struct rte_eth_dev *eth_dev,
1114 : : struct rte_eth_fc_conf *fc_conf)
1115 : : {
1116 : 0 : struct port_info *pi = eth_dev->data->dev_private;
1117 : : struct link_config *lc = &pi->link_cfg;
1118 : 0 : u32 new_caps = lc->admin_caps;
1119 : : u8 tx_pause = 0, rx_pause = 0;
1120 : : int ret;
1121 : :
1122 [ # # ]: 0 : if (fc_conf->mode == RTE_ETH_FC_FULL) {
1123 : : tx_pause = 1;
1124 : : rx_pause = 1;
1125 [ # # ]: 0 : } else if (fc_conf->mode == RTE_ETH_FC_TX_PAUSE) {
1126 : : tx_pause = 1;
1127 [ # # ]: 0 : } else if (fc_conf->mode == RTE_ETH_FC_RX_PAUSE) {
1128 : : rx_pause = 1;
1129 : : }
1130 : :
1131 : 0 : ret = t4_set_link_pause(pi, fc_conf->autoneg, tx_pause,
1132 : : rx_pause, &new_caps);
1133 [ # # ]: 0 : if (ret != 0)
1134 : : return ret;
1135 : :
1136 [ # # ]: 0 : if (!fc_conf->autoneg) {
1137 [ # # ]: 0 : if (lc->pcaps & FW_PORT_CAP32_FORCE_PAUSE)
1138 : 0 : new_caps |= FW_PORT_CAP32_FORCE_PAUSE;
1139 : : } else {
1140 : 0 : new_caps &= ~FW_PORT_CAP32_FORCE_PAUSE;
1141 : : }
1142 : :
1143 [ # # ]: 0 : if (new_caps != lc->admin_caps) {
1144 : : ret = t4_link_l1cfg(pi, new_caps);
1145 [ # # ]: 0 : if (ret == 0)
1146 : 0 : lc->admin_caps = new_caps;
1147 : : }
1148 : :
1149 : : return ret;
1150 : : }
1151 : :
1152 : : const uint32_t *
1153 : 0 : cxgbe_dev_supported_ptypes_get(struct rte_eth_dev *eth_dev,
1154 : : size_t *no_of_elements)
1155 : : {
1156 : : static const uint32_t ptypes[] = {
1157 : : RTE_PTYPE_L3_IPV4,
1158 : : RTE_PTYPE_L3_IPV6,
1159 : : };
1160 : :
1161 [ # # ]: 0 : if (eth_dev->rx_pkt_burst == cxgbe_recv_pkts) {
1162 : 0 : *no_of_elements = RTE_DIM(ptypes);
1163 : 0 : return ptypes;
1164 : : }
1165 : : return NULL;
1166 : : }
1167 : :
1168 : : /* Update RSS hash configuration
1169 : : */
1170 : 0 : static int cxgbe_dev_rss_hash_update(struct rte_eth_dev *dev,
1171 : : struct rte_eth_rss_conf *rss_conf)
1172 : : {
1173 : 0 : struct port_info *pi = dev->data->dev_private;
1174 : 0 : struct adapter *adapter = pi->adapter;
1175 : : int err;
1176 : :
1177 : 0 : err = cxgbe_write_rss_conf(pi, rss_conf->rss_hf);
1178 [ # # ]: 0 : if (err)
1179 : : return err;
1180 : :
1181 : 0 : pi->rss_hf = rss_conf->rss_hf;
1182 : :
1183 [ # # ]: 0 : if (rss_conf->rss_key) {
1184 : : u32 key[10], mod_key[10];
1185 : : int i, j;
1186 : :
1187 : : memcpy(key, rss_conf->rss_key, CXGBE_DEFAULT_RSS_KEY_LEN);
1188 : :
1189 [ # # ]: 0 : for (i = 9, j = 0; i >= 0; i--, j++)
1190 [ # # ]: 0 : mod_key[j] = cpu_to_be32(key[i]);
1191 : :
1192 : 0 : t4_write_rss_key(adapter, mod_key, -1);
1193 : : }
1194 : :
1195 : : return 0;
1196 : : }
1197 : :
1198 : : /* Get RSS hash configuration
1199 : : */
1200 : 0 : static int cxgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1201 : : struct rte_eth_rss_conf *rss_conf)
1202 : : {
1203 : 0 : struct port_info *pi = dev->data->dev_private;
1204 : 0 : struct adapter *adapter = pi->adapter;
1205 : : u64 rss_hf = 0;
1206 : 0 : u64 flags = 0;
1207 : : int err;
1208 : :
1209 : 0 : err = t4_read_config_vi_rss(adapter, adapter->mbox, pi->viid,
1210 : : &flags, NULL);
1211 : :
1212 [ # # ]: 0 : if (err)
1213 : : return err;
1214 : :
1215 [ # # ]: 0 : if (flags & F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN) {
1216 : : rss_hf |= CXGBE_RSS_HF_TCP_IPV6_MASK;
1217 [ # # ]: 0 : if (flags & F_FW_RSS_VI_CONFIG_CMD_UDPEN)
1218 : : rss_hf |= CXGBE_RSS_HF_UDP_IPV6_MASK;
1219 : : }
1220 : :
1221 [ # # ]: 0 : if (flags & F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN)
1222 : 0 : rss_hf |= CXGBE_RSS_HF_IPV6_MASK;
1223 : :
1224 [ # # ]: 0 : if (flags & F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN) {
1225 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_TCP;
1226 [ # # ]: 0 : if (flags & F_FW_RSS_VI_CONFIG_CMD_UDPEN)
1227 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_UDP;
1228 : : }
1229 : :
1230 [ # # ]: 0 : if (flags & F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN)
1231 : 0 : rss_hf |= CXGBE_RSS_HF_IPV4_MASK;
1232 : :
1233 : 0 : rss_conf->rss_hf = rss_hf;
1234 : :
1235 [ # # ]: 0 : if (rss_conf->rss_key) {
1236 : : u32 key[10], mod_key[10];
1237 : : int i, j;
1238 : :
1239 : 0 : t4_read_rss_key(adapter, key);
1240 : :
1241 [ # # ]: 0 : for (i = 9, j = 0; i >= 0; i--, j++)
1242 [ # # ]: 0 : mod_key[j] = be32_to_cpu(key[i]);
1243 : :
1244 : 0 : memcpy(rss_conf->rss_key, mod_key, CXGBE_DEFAULT_RSS_KEY_LEN);
1245 : : }
1246 : :
1247 : : return 0;
1248 : : }
1249 : :
1250 : 0 : static int cxgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
1251 : : struct rte_eth_rss_reta_entry64 *reta_conf,
1252 : : uint16_t reta_size)
1253 : : {
1254 : 0 : struct port_info *pi = dev->data->dev_private;
1255 : 0 : struct adapter *adapter = pi->adapter;
1256 : : u16 i, idx, shift, *rss;
1257 : : int ret;
1258 : :
1259 [ # # ]: 0 : if (!(adapter->flags & FULL_INIT_DONE))
1260 : : return -ENOMEM;
1261 : :
1262 [ # # # # ]: 0 : if (!reta_size || reta_size > pi->rss_size)
1263 : : return -EINVAL;
1264 : :
1265 : 0 : rss = rte_calloc(NULL, pi->rss_size, sizeof(u16), 0);
1266 [ # # ]: 0 : if (!rss)
1267 : : return -ENOMEM;
1268 : :
1269 [ # # ]: 0 : rte_memcpy(rss, pi->rss, pi->rss_size * sizeof(u16));
1270 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
1271 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
1272 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
1273 [ # # ]: 0 : if (!(reta_conf[idx].mask & (1ULL << shift)))
1274 : 0 : continue;
1275 : :
1276 : 0 : rss[i] = reta_conf[idx].reta[shift];
1277 : : }
1278 : :
1279 : 0 : ret = cxgbe_write_rss(pi, rss);
1280 [ # # ]: 0 : if (!ret)
1281 [ # # ]: 0 : rte_memcpy(pi->rss, rss, pi->rss_size * sizeof(u16));
1282 : :
1283 : 0 : rte_free(rss);
1284 : 0 : return ret;
1285 : : }
1286 : :
1287 : 0 : static int cxgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
1288 : : struct rte_eth_rss_reta_entry64 *reta_conf,
1289 : : uint16_t reta_size)
1290 : : {
1291 : 0 : struct port_info *pi = dev->data->dev_private;
1292 : 0 : struct adapter *adapter = pi->adapter;
1293 : : u16 i, idx, shift;
1294 : :
1295 [ # # ]: 0 : if (!(adapter->flags & FULL_INIT_DONE))
1296 : : return -ENOMEM;
1297 : :
1298 [ # # # # ]: 0 : if (!reta_size || reta_size > pi->rss_size)
1299 : : return -EINVAL;
1300 : :
1301 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
1302 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
1303 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
1304 [ # # ]: 0 : if (!(reta_conf[idx].mask & (1ULL << shift)))
1305 : 0 : continue;
1306 : :
1307 : 0 : reta_conf[idx].reta[shift] = pi->rss[i];
1308 : : }
1309 : :
1310 : : return 0;
1311 : : }
1312 : :
1313 : 0 : static int cxgbe_get_eeprom_length(struct rte_eth_dev *dev)
1314 : : {
1315 : : RTE_SET_USED(dev);
1316 : 0 : return EEPROMSIZE;
1317 : : }
1318 : :
1319 : : /**
1320 : : * eeprom_ptov - translate a physical EEPROM address to virtual
1321 : : * @phys_addr: the physical EEPROM address
1322 : : * @fn: the PCI function number
1323 : : * @sz: size of function-specific area
1324 : : *
1325 : : * Translate a physical EEPROM address to virtual. The first 1K is
1326 : : * accessed through virtual addresses starting at 31K, the rest is
1327 : : * accessed through virtual addresses starting at 0.
1328 : : *
1329 : : * The mapping is as follows:
1330 : : * [0..1K) -> [31K..32K)
1331 : : * [1K..1K+A) -> [31K-A..31K)
1332 : : * [1K+A..ES) -> [0..ES-A-1K)
1333 : : *
1334 : : * where A = @fn * @sz, and ES = EEPROM size.
1335 : : */
1336 : : static int eeprom_ptov(unsigned int phys_addr, unsigned int fn, unsigned int sz)
1337 : : {
1338 : 0 : fn *= sz;
1339 : 0 : if (phys_addr < 1024)
1340 : 0 : return phys_addr + (31 << 10);
1341 [ # # # # ]: 0 : if (phys_addr < 1024 + fn)
1342 : 0 : return fn + phys_addr - 1024;
1343 [ # # # # ]: 0 : if (phys_addr < EEPROMSIZE)
1344 : 0 : return phys_addr - 1024 - fn;
1345 [ # # # # ]: 0 : if (phys_addr < EEPROMVSIZE)
1346 : 0 : return phys_addr - 1024;
1347 : : return -EINVAL;
1348 : : }
1349 : :
1350 : : /* The next two routines implement eeprom read/write from physical addresses.
1351 : : */
1352 : 0 : static int eeprom_rd_phys(struct adapter *adap, unsigned int phys_addr, u32 *v)
1353 : : {
1354 [ # # ]: 0 : int vaddr = eeprom_ptov(phys_addr, adap->pf, EEPROMPFSIZE);
1355 : :
1356 [ # # ]: 0 : if (vaddr >= 0)
1357 : 0 : vaddr = t4_seeprom_read(adap, vaddr, v);
1358 : 0 : return vaddr < 0 ? vaddr : 0;
1359 : : }
1360 : :
1361 : 0 : static int eeprom_wr_phys(struct adapter *adap, unsigned int phys_addr, u32 v)
1362 : : {
1363 [ # # ]: 0 : int vaddr = eeprom_ptov(phys_addr, adap->pf, EEPROMPFSIZE);
1364 : :
1365 [ # # ]: 0 : if (vaddr >= 0)
1366 : 0 : vaddr = t4_seeprom_write(adap, vaddr, v);
1367 : 0 : return vaddr < 0 ? vaddr : 0;
1368 : : }
1369 : :
1370 : : #define EEPROM_MAGIC 0x38E2F10C
1371 : :
1372 : 0 : static int cxgbe_get_eeprom(struct rte_eth_dev *dev,
1373 : : struct rte_dev_eeprom_info *e)
1374 : : {
1375 : 0 : struct port_info *pi = dev->data->dev_private;
1376 : 0 : struct adapter *adapter = pi->adapter;
1377 : : u32 i, err = 0;
1378 : 0 : u8 *buf = rte_zmalloc(NULL, EEPROMSIZE, 0);
1379 : :
1380 [ # # ]: 0 : if (!buf)
1381 : : return -ENOMEM;
1382 : :
1383 : 0 : e->magic = EEPROM_MAGIC;
1384 [ # # # # ]: 0 : for (i = e->offset & ~3; !err && i < e->offset + e->length; i += 4)
1385 : 0 : err = eeprom_rd_phys(adapter, i, (u32 *)&buf[i]);
1386 : :
1387 [ # # ]: 0 : if (!err)
1388 [ # # ]: 0 : rte_memcpy(e->data, buf + e->offset, e->length);
1389 : 0 : rte_free(buf);
1390 : 0 : return err;
1391 : : }
1392 : :
1393 : 0 : static int cxgbe_set_eeprom(struct rte_eth_dev *dev,
1394 : : struct rte_dev_eeprom_info *eeprom)
1395 : : {
1396 : 0 : struct port_info *pi = dev->data->dev_private;
1397 : 0 : struct adapter *adapter = pi->adapter;
1398 : : u8 *buf;
1399 : : int err = 0;
1400 : : u32 aligned_offset, aligned_len, *p;
1401 : :
1402 [ # # ]: 0 : if (eeprom->magic != EEPROM_MAGIC)
1403 : : return -EINVAL;
1404 : :
1405 : 0 : aligned_offset = eeprom->offset & ~3;
1406 : 0 : aligned_len = (eeprom->length + (eeprom->offset & 3) + 3) & ~3;
1407 : :
1408 [ # # ]: 0 : if (adapter->pf > 0) {
1409 : 0 : u32 start = 1024 + adapter->pf * EEPROMPFSIZE;
1410 : :
1411 [ # # ]: 0 : if (aligned_offset < start ||
1412 [ # # ]: 0 : aligned_offset + aligned_len > start + EEPROMPFSIZE)
1413 : : return -EPERM;
1414 : : }
1415 : :
1416 [ # # # # ]: 0 : if (aligned_offset != eeprom->offset || aligned_len != eeprom->length) {
1417 : : /* RMW possibly needed for first or last words.
1418 : : */
1419 : 0 : buf = rte_zmalloc(NULL, aligned_len, 0);
1420 [ # # ]: 0 : if (!buf)
1421 : : return -ENOMEM;
1422 : 0 : err = eeprom_rd_phys(adapter, aligned_offset, (u32 *)buf);
1423 [ # # ]: 0 : if (!err && aligned_len > 4)
1424 : 0 : err = eeprom_rd_phys(adapter,
1425 : 0 : aligned_offset + aligned_len - 4,
1426 : 0 : (u32 *)&buf[aligned_len - 4]);
1427 [ # # ]: 0 : if (err)
1428 : 0 : goto out;
1429 : 0 : rte_memcpy(buf + (eeprom->offset & 3), eeprom->data,
1430 [ # # ]: 0 : eeprom->length);
1431 : : } else {
1432 : 0 : buf = eeprom->data;
1433 : : }
1434 : :
1435 : 0 : err = t4_seeprom_wp(adapter, false);
1436 [ # # ]: 0 : if (err)
1437 : 0 : goto out;
1438 : :
1439 [ # # ]: 0 : for (p = (u32 *)buf; !err && aligned_len; aligned_len -= 4, p++) {
1440 : 0 : err = eeprom_wr_phys(adapter, aligned_offset, *p);
1441 : 0 : aligned_offset += 4;
1442 : : }
1443 : :
1444 [ # # ]: 0 : if (!err)
1445 : 0 : err = t4_seeprom_wp(adapter, true);
1446 : 0 : out:
1447 [ # # ]: 0 : if (buf != eeprom->data)
1448 : 0 : rte_free(buf);
1449 : : return err;
1450 : : }
1451 : :
1452 : : static int cxgbe_get_regs_len(struct rte_eth_dev *eth_dev)
1453 : : {
1454 : : struct port_info *pi = eth_dev->data->dev_private;
1455 : : struct adapter *adapter = pi->adapter;
1456 : :
1457 : 0 : return t4_get_regs_len(adapter) / sizeof(uint32_t);
1458 : : }
1459 : :
1460 : 0 : static int cxgbe_get_regs(struct rte_eth_dev *eth_dev,
1461 : : struct rte_dev_reg_info *regs)
1462 : : {
1463 : 0 : struct port_info *pi = eth_dev->data->dev_private;
1464 : 0 : struct adapter *adapter = pi->adapter;
1465 : :
1466 : 0 : regs->version = CHELSIO_CHIP_VERSION(adapter->params.chip) |
1467 : 0 : (CHELSIO_CHIP_RELEASE(adapter->params.chip) << 10) |
1468 : : (1 << 16);
1469 : :
1470 [ # # ]: 0 : if (regs->data == NULL) {
1471 : 0 : regs->length = cxgbe_get_regs_len(eth_dev);
1472 : 0 : regs->width = sizeof(uint32_t);
1473 : :
1474 : 0 : return 0;
1475 : : }
1476 : :
1477 : 0 : t4_get_regs(adapter, regs->data, (regs->length * sizeof(uint32_t)));
1478 : :
1479 : 0 : return 0;
1480 : : }
1481 : :
1482 : 0 : int cxgbe_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *addr)
1483 : : {
1484 : 0 : struct port_info *pi = dev->data->dev_private;
1485 : : int ret;
1486 : :
1487 : 0 : ret = cxgbe_mpstcam_modify(pi, (int)pi->xact_addr_filt, (u8 *)addr);
1488 [ # # ]: 0 : if (ret < 0) {
1489 : 0 : dev_err(adapter, "failed to set mac addr; err = %d\n",
1490 : : ret);
1491 : 0 : return ret;
1492 : : }
1493 : 0 : pi->xact_addr_filt = ret;
1494 : 0 : return 0;
1495 : : }
1496 : :
1497 : 0 : static int cxgbe_fec_get_capa_speed_to_fec(struct link_config *lc,
1498 : : struct rte_eth_fec_capa *capa_arr)
1499 : : {
1500 : : int num = 0;
1501 : :
1502 [ # # # # ]: 0 : if (lc->pcaps & FW_PORT_CAP32_SPEED_100G) {
1503 [ # # ]: 0 : if (capa_arr) {
1504 : 0 : capa_arr[num].speed = RTE_ETH_SPEED_NUM_100G;
1505 : 0 : capa_arr[num].capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) |
1506 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS);
1507 : : }
1508 : : num++;
1509 : : }
1510 : :
1511 [ # # # # ]: 0 : if (lc->pcaps & FW_PORT_CAP32_SPEED_50G) {
1512 [ # # ]: 0 : if (capa_arr) {
1513 : 0 : capa_arr[num].speed = RTE_ETH_SPEED_NUM_50G;
1514 : 0 : capa_arr[num].capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) |
1515 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
1516 : : }
1517 : 0 : num++;
1518 : : }
1519 : :
1520 [ # # # # ]: 0 : if (lc->pcaps & FW_PORT_CAP32_SPEED_25G) {
1521 [ # # ]: 0 : if (capa_arr) {
1522 : 0 : capa_arr[num].speed = RTE_ETH_SPEED_NUM_25G;
1523 : 0 : capa_arr[num].capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) |
1524 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER) |
1525 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS);
1526 : : }
1527 : 0 : num++;
1528 : : }
1529 : :
1530 : 0 : return num;
1531 : : }
1532 : :
1533 : 0 : static int cxgbe_fec_get_capability(struct rte_eth_dev *dev,
1534 : : struct rte_eth_fec_capa *speed_fec_capa,
1535 : : unsigned int num)
1536 : : {
1537 : 0 : struct port_info *pi = dev->data->dev_private;
1538 : 0 : struct link_config *lc = &pi->link_cfg;
1539 : : u8 num_entries;
1540 : :
1541 [ # # ]: 0 : if (!(lc->pcaps & V_FW_PORT_CAP32_FEC(M_FW_PORT_CAP32_FEC)))
1542 : : return -EOPNOTSUPP;
1543 : :
1544 : : num_entries = cxgbe_fec_get_capa_speed_to_fec(lc, NULL);
1545 [ # # # # ]: 0 : if (!speed_fec_capa || num < num_entries)
1546 : : return num_entries;
1547 : :
1548 : 0 : return cxgbe_fec_get_capa_speed_to_fec(lc, speed_fec_capa);
1549 : : }
1550 : :
1551 : 0 : static int cxgbe_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa)
1552 : : {
1553 : 0 : struct port_info *pi = dev->data->dev_private;
1554 : : struct link_config *lc = &pi->link_cfg;
1555 : 0 : u32 fec_caps = 0, caps = lc->link_caps;
1556 : :
1557 [ # # ]: 0 : if (!(lc->pcaps & V_FW_PORT_CAP32_FEC(M_FW_PORT_CAP32_FEC)))
1558 : : return -EOPNOTSUPP;
1559 : :
1560 [ # # ]: 0 : if (caps & FW_PORT_CAP32_FEC_RS)
1561 : : fec_caps = RTE_ETH_FEC_MODE_CAPA_MASK(RS);
1562 [ # # ]: 0 : else if (caps & FW_PORT_CAP32_FEC_BASER_RS)
1563 : : fec_caps = RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
1564 : : else
1565 : : fec_caps = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
1566 : :
1567 : 0 : *fec_capa = fec_caps;
1568 : 0 : return 0;
1569 : : }
1570 : :
1571 : 0 : static int cxgbe_fec_set(struct rte_eth_dev *dev, uint32_t fec_capa)
1572 : : {
1573 : 0 : struct port_info *pi = dev->data->dev_private;
1574 : : u8 fec_rs = 0, fec_baser = 0, fec_none = 0;
1575 : : struct link_config *lc = &pi->link_cfg;
1576 : 0 : u32 new_caps = lc->admin_caps;
1577 : : int ret;
1578 : :
1579 [ # # ]: 0 : if (!(lc->pcaps & V_FW_PORT_CAP32_FEC(M_FW_PORT_CAP32_FEC)))
1580 : : return -EOPNOTSUPP;
1581 : :
1582 [ # # ]: 0 : if (!fec_capa)
1583 : : return -EINVAL;
1584 : :
1585 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(AUTO))
1586 : 0 : goto set_fec;
1587 : :
1588 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC))
1589 : : fec_none = 1;
1590 : :
1591 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(BASER))
1592 : : fec_baser = 1;
1593 : :
1594 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(RS))
1595 : : fec_rs = 1;
1596 : :
1597 : 0 : set_fec:
1598 : 0 : ret = t4_set_link_fec(pi, fec_rs, fec_baser, fec_none, &new_caps);
1599 [ # # ]: 0 : if (ret != 0)
1600 : : return ret;
1601 : :
1602 [ # # ]: 0 : if (lc->pcaps & FW_PORT_CAP32_FORCE_FEC)
1603 : 0 : new_caps |= FW_PORT_CAP32_FORCE_FEC;
1604 : : else
1605 : 0 : new_caps &= ~FW_PORT_CAP32_FORCE_FEC;
1606 : :
1607 [ # # ]: 0 : if (new_caps != lc->admin_caps) {
1608 : : ret = t4_link_l1cfg(pi, new_caps);
1609 [ # # ]: 0 : if (ret == 0)
1610 : 0 : lc->admin_caps = new_caps;
1611 : : }
1612 : :
1613 : : return ret;
1614 : : }
1615 : :
1616 : 0 : int cxgbe_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
1617 : : size_t fw_size)
1618 : : {
1619 : 0 : struct port_info *pi = dev->data->dev_private;
1620 : 0 : struct adapter *adapter = pi->adapter;
1621 : : int ret;
1622 : :
1623 [ # # ]: 0 : if (adapter->params.fw_vers == 0)
1624 : : return -EIO;
1625 : :
1626 : 0 : ret = snprintf(fw_version, fw_size, "%u.%u.%u.%u",
1627 : : G_FW_HDR_FW_VER_MAJOR(adapter->params.fw_vers),
1628 : 0 : G_FW_HDR_FW_VER_MINOR(adapter->params.fw_vers),
1629 [ # # ]: 0 : G_FW_HDR_FW_VER_MICRO(adapter->params.fw_vers),
1630 : : G_FW_HDR_FW_VER_BUILD(adapter->params.fw_vers));
1631 [ # # ]: 0 : if (ret < 0)
1632 : : return -EINVAL;
1633 : :
1634 : 0 : ret += 1;
1635 [ # # ]: 0 : if (fw_size < (size_t)ret)
1636 : 0 : return ret;
1637 : :
1638 : : return 0;
1639 : : }
1640 : :
1641 : : static const struct eth_dev_ops cxgbe_eth_dev_ops = {
1642 : : .dev_start = cxgbe_dev_start,
1643 : : .dev_stop = cxgbe_dev_stop,
1644 : : .dev_close = cxgbe_dev_close,
1645 : : .promiscuous_enable = cxgbe_dev_promiscuous_enable,
1646 : : .promiscuous_disable = cxgbe_dev_promiscuous_disable,
1647 : : .allmulticast_enable = cxgbe_dev_allmulticast_enable,
1648 : : .allmulticast_disable = cxgbe_dev_allmulticast_disable,
1649 : : .dev_configure = cxgbe_dev_configure,
1650 : : .dev_infos_get = cxgbe_dev_info_get,
1651 : : .dev_supported_ptypes_get = cxgbe_dev_supported_ptypes_get,
1652 : : .link_update = cxgbe_dev_link_update,
1653 : : .dev_set_link_up = cxgbe_dev_set_link_up,
1654 : : .dev_set_link_down = cxgbe_dev_set_link_down,
1655 : : .mtu_set = cxgbe_dev_mtu_set,
1656 : : .tx_queue_setup = cxgbe_dev_tx_queue_setup,
1657 : : .tx_queue_start = cxgbe_dev_tx_queue_start,
1658 : : .tx_queue_stop = cxgbe_dev_tx_queue_stop,
1659 : : .tx_queue_release = cxgbe_dev_tx_queue_release,
1660 : : .rx_queue_setup = cxgbe_dev_rx_queue_setup,
1661 : : .rx_queue_start = cxgbe_dev_rx_queue_start,
1662 : : .rx_queue_stop = cxgbe_dev_rx_queue_stop,
1663 : : .rx_queue_release = cxgbe_dev_rx_queue_release,
1664 : : .flow_ops_get = cxgbe_dev_flow_ops_get,
1665 : : .stats_get = cxgbe_dev_stats_get,
1666 : : .stats_reset = cxgbe_dev_stats_reset,
1667 : : .xstats_get = cxgbe_dev_xstats_get,
1668 : : .xstats_get_by_id = cxgbe_dev_xstats_get_by_id,
1669 : : .xstats_get_names = cxgbe_dev_xstats_get_names,
1670 : : .xstats_get_names_by_id = cxgbe_dev_xstats_get_names_by_id,
1671 : : .xstats_reset = cxgbe_dev_xstats_reset,
1672 : : .flow_ctrl_get = cxgbe_flow_ctrl_get,
1673 : : .flow_ctrl_set = cxgbe_flow_ctrl_set,
1674 : : .get_eeprom_length = cxgbe_get_eeprom_length,
1675 : : .get_eeprom = cxgbe_get_eeprom,
1676 : : .set_eeprom = cxgbe_set_eeprom,
1677 : : .get_reg = cxgbe_get_regs,
1678 : : .rss_hash_update = cxgbe_dev_rss_hash_update,
1679 : : .rss_hash_conf_get = cxgbe_dev_rss_hash_conf_get,
1680 : : .mac_addr_set = cxgbe_mac_addr_set,
1681 : : .reta_update = cxgbe_dev_rss_reta_update,
1682 : : .reta_query = cxgbe_dev_rss_reta_query,
1683 : : .fec_get_capability = cxgbe_fec_get_capability,
1684 : : .fec_get = cxgbe_fec_get,
1685 : : .fec_set = cxgbe_fec_set,
1686 : : .fw_version_get = cxgbe_fw_version_get,
1687 : : };
1688 : :
1689 : : /*
1690 : : * Initialize driver
1691 : : * It returns 0 on success.
1692 : : */
1693 : 0 : static int eth_cxgbe_dev_init(struct rte_eth_dev *eth_dev)
1694 : : {
1695 : : struct rte_pci_device *pci_dev;
1696 : 0 : struct port_info *pi = eth_dev->data->dev_private;
1697 : : struct adapter *adapter = NULL;
1698 : : char name[RTE_ETH_NAME_MAX_LEN];
1699 : : int err = 0;
1700 : :
1701 : 0 : CXGBE_FUNC_TRACE();
1702 : :
1703 : 0 : eth_dev->dev_ops = &cxgbe_eth_dev_ops;
1704 : 0 : eth_dev->rx_pkt_burst = &cxgbe_recv_pkts;
1705 : 0 : eth_dev->tx_pkt_burst = &cxgbe_xmit_pkts;
1706 : 0 : pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1707 : :
1708 : : /* for secondary processes, we attach to ethdevs allocated by primary
1709 : : * and do minimal initialization.
1710 : : */
1711 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1712 : : int i;
1713 : :
1714 [ # # ]: 0 : for (i = 1; i < MAX_NPORTS; i++) {
1715 : : struct rte_eth_dev *rest_eth_dev;
1716 : : char namei[RTE_ETH_NAME_MAX_LEN];
1717 : :
1718 : 0 : snprintf(namei, sizeof(namei), "%s_%d",
1719 : : pci_dev->device.name, i);
1720 : 0 : rest_eth_dev = rte_eth_dev_attach_secondary(namei);
1721 [ # # ]: 0 : if (rest_eth_dev) {
1722 : 0 : rest_eth_dev->device = &pci_dev->device;
1723 : 0 : rest_eth_dev->dev_ops =
1724 : 0 : eth_dev->dev_ops;
1725 : 0 : rest_eth_dev->rx_pkt_burst =
1726 : 0 : eth_dev->rx_pkt_burst;
1727 : 0 : rest_eth_dev->tx_pkt_burst =
1728 : 0 : eth_dev->tx_pkt_burst;
1729 : 0 : rte_eth_dev_probing_finish(rest_eth_dev);
1730 : : }
1731 : : }
1732 : : return 0;
1733 : : }
1734 : :
1735 : 0 : snprintf(name, sizeof(name), "cxgbeadapter%d", eth_dev->data->port_id);
1736 : 0 : adapter = rte_zmalloc(name, sizeof(*adapter), 0);
1737 [ # # ]: 0 : if (!adapter)
1738 : : return -1;
1739 : :
1740 : 0 : adapter->use_unpacked_mode = 1;
1741 : 0 : adapter->regs = (void *)pci_dev->mem_resource[0].addr;
1742 [ # # ]: 0 : if (!adapter->regs) {
1743 : 0 : dev_err(adapter, "%s: cannot map device registers\n", __func__);
1744 : : err = -ENOMEM;
1745 : 0 : goto out_free_adapter;
1746 : : }
1747 : 0 : adapter->pdev = pci_dev;
1748 : 0 : adapter->eth_dev = eth_dev;
1749 : 0 : pi->adapter = adapter;
1750 : :
1751 : 0 : cxgbe_process_devargs(adapter);
1752 : :
1753 : 0 : err = cxgbe_probe(adapter);
1754 [ # # ]: 0 : if (err) {
1755 : 0 : dev_err(adapter, "%s: cxgbe probe failed with err %d\n",
1756 : : __func__, err);
1757 : 0 : goto out_free_adapter;
1758 : : }
1759 : :
1760 : : return 0;
1761 : :
1762 : 0 : out_free_adapter:
1763 : 0 : rte_free(adapter);
1764 : 0 : return err;
1765 : : }
1766 : :
1767 : 0 : static int eth_cxgbe_dev_uninit(struct rte_eth_dev *eth_dev)
1768 : : {
1769 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1770 : : uint16_t port_id;
1771 : : int err = 0;
1772 : :
1773 : : /* Free up other ports and all resources */
1774 [ # # ]: 0 : RTE_ETH_FOREACH_DEV_OF(port_id, &pci_dev->device)
1775 : 0 : err |= rte_eth_dev_close(port_id);
1776 : :
1777 [ # # ]: 0 : return err == 0 ? 0 : -EIO;
1778 : : }
1779 : :
1780 : 0 : static int eth_cxgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1781 : : struct rte_pci_device *pci_dev)
1782 : : {
1783 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev,
1784 : : sizeof(struct port_info), eth_cxgbe_dev_init);
1785 : : }
1786 : :
1787 : 0 : static int eth_cxgbe_pci_remove(struct rte_pci_device *pci_dev)
1788 : : {
1789 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, eth_cxgbe_dev_uninit);
1790 : : }
1791 : :
1792 : : static struct rte_pci_driver rte_cxgbe_pmd = {
1793 : : .id_table = cxgb4_pci_tbl,
1794 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1795 : : .probe = eth_cxgbe_pci_probe,
1796 : : .remove = eth_cxgbe_pci_remove,
1797 : : };
1798 : :
1799 : 251 : RTE_PMD_REGISTER_PCI(net_cxgbe, rte_cxgbe_pmd);
1800 : : RTE_PMD_REGISTER_PCI_TABLE(net_cxgbe, cxgb4_pci_tbl);
1801 : : RTE_PMD_REGISTER_KMOD_DEP(net_cxgbe, "* igb_uio | uio_pci_generic | vfio-pci");
1802 : : RTE_PMD_REGISTER_PARAM_STRING(net_cxgbe,
1803 : : CXGBE_DEVARG_CMN_KEEP_OVLAN "=<0|1> "
1804 : : CXGBE_DEVARG_CMN_TX_MODE_LATENCY "=<0|1> "
1805 : : CXGBE_DEVARG_PF_FILTER_MODE "=<uint32> "
1806 : : CXGBE_DEVARG_PF_FILTER_MASK "=<uint32> ");
1807 [ - + ]: 251 : RTE_LOG_REGISTER_DEFAULT(cxgbe_logtype, NOTICE);
1808 [ - + ]: 251 : RTE_LOG_REGISTER_SUFFIX(cxgbe_mbox_logtype, mbox, NOTICE);
|