Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2018-2019 NXP
3 : : */
4 : :
5 : : #include <sys/ioctl.h>
6 : : #include <sys/epoll.h>
7 : : #include <rte_kvargs.h>
8 : : #include <ethdev_vdev.h>
9 : : #include <bus_vdev_driver.h>
10 : : #include <rte_ether.h>
11 : : #include <dpaa_of.h>
12 : :
13 : : #include "pfe_logs.h"
14 : : #include "pfe_mod.h"
15 : :
16 : : #define PFE_MAX_MACS 1 /* we can support up to 4 MACs per IF */
17 : : #define PFE_VDEV_GEM_ID_ARG "intf"
18 : :
19 : : struct pfe_vdev_init_params {
20 : : int8_t gem_id;
21 : : };
22 : : static struct pfe *g_pfe;
23 : : /* Supported Rx offloads */
24 : : static uint64_t dev_rx_offloads_sup =
25 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
26 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
27 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM;
28 : :
29 : : /* Supported Tx offloads */
30 : : static uint64_t dev_tx_offloads_sup =
31 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
32 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
33 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM;
34 : :
35 : : /* TODO: make pfe_svr a runtime option.
36 : : * Driver should be able to get the SVR
37 : : * information from HW.
38 : : */
39 : : unsigned int pfe_svr = SVR_LS1012A_REV1;
40 : : static void *cbus_emac_base[3];
41 : : static void *cbus_gpi_base[3];
42 : :
43 : : /* pfe_gemac_init
44 : : */
45 : : static int
46 : 0 : pfe_gemac_init(struct pfe_eth_priv_s *priv)
47 : : {
48 : : struct gemac_cfg cfg;
49 : :
50 : 0 : cfg.speed = SPEED_1000M;
51 : 0 : cfg.duplex = DUPLEX_FULL;
52 : :
53 : 0 : gemac_set_config(priv->EMAC_baseaddr, &cfg);
54 : 0 : gemac_allow_broadcast(priv->EMAC_baseaddr);
55 : 0 : gemac_enable_1536_rx(priv->EMAC_baseaddr);
56 : 0 : gemac_enable_stacked_vlan(priv->EMAC_baseaddr);
57 : 0 : gemac_enable_pause_rx(priv->EMAC_baseaddr);
58 : 0 : gemac_set_bus_width(priv->EMAC_baseaddr, 64);
59 : 0 : gemac_enable_rx_checksum_offload(priv->EMAC_baseaddr);
60 : :
61 : 0 : return 0;
62 : : }
63 : :
64 : : static void
65 : 0 : pfe_soc_version_get(void)
66 : : {
67 : : FILE *svr_file = NULL;
68 : 0 : unsigned int svr_ver = 0;
69 : :
70 : 0 : PMD_INIT_FUNC_TRACE();
71 : :
72 : 0 : svr_file = fopen(PFE_SOC_ID_FILE, "r");
73 [ # # ]: 0 : if (!svr_file) {
74 : 0 : PFE_PMD_ERR("Unable to open SoC device");
75 : 0 : return; /* Not supported on this infra */
76 : : }
77 : :
78 [ # # ]: 0 : if (fscanf(svr_file, "svr:%x", &svr_ver) > 0)
79 : 0 : pfe_svr = svr_ver;
80 : : else
81 : 0 : PFE_PMD_ERR("Unable to read SoC device");
82 : :
83 : 0 : fclose(svr_file);
84 : : }
85 : :
86 : : static int pfe_eth_start(struct pfe_eth_priv_s *priv)
87 : : {
88 : 0 : gpi_enable(priv->GPI_baseaddr);
89 : 0 : gemac_enable(priv->EMAC_baseaddr);
90 : :
91 : : return 0;
92 : : }
93 : :
94 : : static void
95 : 0 : pfe_eth_flush_txQ(struct pfe_eth_priv_s *priv, int tx_q_num, int
96 : : __rte_unused from_tx, __rte_unused int n_desc)
97 : : {
98 : : struct rte_mbuf *mbuf;
99 : : unsigned int flags;
100 : :
101 : : /* Clean HIF and client queue */
102 [ # # ]: 0 : while ((mbuf = hif_lib_tx_get_next_complete(&priv->client,
103 : : tx_q_num, &flags,
104 : : HIF_TX_DESC_NT))) {
105 : : if (mbuf) {
106 : 0 : mbuf->next = NULL;
107 : 0 : mbuf->nb_segs = 1;
108 : 0 : rte_pktmbuf_free(mbuf);
109 : : }
110 : : }
111 : 0 : }
112 : :
113 : :
114 : : static void
115 : : pfe_eth_flush_tx(struct pfe_eth_priv_s *priv)
116 : : {
117 : : unsigned int ii;
118 : :
119 [ # # ]: 0 : for (ii = 0; ii < emac_txq_cnt; ii++)
120 : 0 : pfe_eth_flush_txQ(priv, ii, 0, 0);
121 : : }
122 : :
123 : : static int
124 : 0 : pfe_eth_event_handler(void *data, int event, __rte_unused int qno)
125 : : {
126 : : struct pfe_eth_priv_s *priv = data;
127 : :
128 [ # # ]: 0 : switch (event) {
129 : : case EVENT_TXDONE_IND:
130 : : pfe_eth_flush_tx(priv);
131 : 0 : hif_lib_event_handler_start(&priv->client, EVENT_TXDONE_IND, 0);
132 : 0 : break;
133 : : case EVENT_HIGH_RX_WM:
134 : : default:
135 : : break;
136 : : }
137 : :
138 : 0 : return 0;
139 : : }
140 : :
141 : : static uint16_t
142 : 0 : pfe_recv_pkts_on_intr(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
143 : : {
144 : : struct hif_client_rx_queue *queue = rxq;
145 : 0 : struct pfe_eth_priv_s *priv = queue->priv;
146 : : struct epoll_event epoll_ev;
147 : : uint64_t ticks = 1; /* 1 msec */
148 : : int ret;
149 : : int have_something, work_done;
150 : :
151 : : #define RESET_STATUS (HIF_INT | HIF_RXPKT_INT)
152 : :
153 : : /*TODO can we remove this cleanup from here?*/
154 : 0 : pfe_tx_do_cleanup(priv->pfe);
155 : 0 : have_something = pfe_hif_rx_process(priv->pfe, nb_pkts);
156 : 0 : work_done = hif_lib_receive_pkt(rxq, priv->pfe->hif.shm->pool,
157 : : rx_pkts, nb_pkts);
158 : :
159 [ # # ]: 0 : if (!have_something || !work_done) {
160 : 0 : writel(RESET_STATUS, HIF_INT_SRC);
161 : 0 : writel(readl(HIF_INT_ENABLE) | HIF_RXPKT_INT, HIF_INT_ENABLE);
162 : 0 : ret = epoll_wait(priv->pfe->hif.epoll_fd, &epoll_ev, 1, ticks);
163 [ # # # # ]: 0 : if (ret < 0 && errno != EINTR)
164 : 0 : PFE_PMD_ERR("epoll_wait fails with %d", errno);
165 : : }
166 : :
167 : 0 : return work_done;
168 : : }
169 : :
170 : : static uint16_t
171 : 0 : pfe_recv_pkts(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
172 : : {
173 : : struct hif_client_rx_queue *queue = rxq;
174 : 0 : struct pfe_eth_priv_s *priv = queue->priv;
175 : : struct rte_mempool *pool;
176 : :
177 : : /*TODO can we remove this cleanup from here?*/
178 : 0 : pfe_tx_do_cleanup(priv->pfe);
179 : 0 : pfe_hif_rx_process(priv->pfe, nb_pkts);
180 : 0 : pool = priv->pfe->hif.shm->pool;
181 : :
182 : 0 : return hif_lib_receive_pkt(rxq, pool, rx_pkts, nb_pkts);
183 : : }
184 : :
185 : : static uint16_t
186 : 0 : pfe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
187 : : {
188 : : struct hif_client_tx_queue *queue = tx_queue;
189 : 0 : struct pfe_eth_priv_s *priv = queue->priv;
190 : : struct rte_eth_stats *stats = &priv->stats;
191 : : int i;
192 : :
193 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
194 [ # # ]: 0 : if (tx_pkts[i]->nb_segs > 1) {
195 : : struct rte_mbuf *mbuf;
196 : : int j;
197 : :
198 : 0 : hif_lib_xmit_pkt(&priv->client, queue->queue_id,
199 : 0 : (void *)(size_t)rte_pktmbuf_iova(tx_pkts[i]),
200 : 0 : tx_pkts[i]->buf_addr + tx_pkts[i]->data_off,
201 : 0 : tx_pkts[i]->data_len, 0x0, HIF_FIRST_BUFFER,
202 : : tx_pkts[i]);
203 : :
204 : 0 : mbuf = tx_pkts[i]->next;
205 [ # # ]: 0 : for (j = 0; j < (tx_pkts[i]->nb_segs - 2); j++) {
206 : 0 : hif_lib_xmit_pkt(&priv->client, queue->queue_id,
207 : 0 : (void *)(size_t)rte_pktmbuf_iova(mbuf),
208 : 0 : mbuf->buf_addr + mbuf->data_off,
209 : 0 : mbuf->data_len,
210 : : 0x0, 0x0, mbuf);
211 : 0 : mbuf = mbuf->next;
212 : : }
213 : :
214 : 0 : hif_lib_xmit_pkt(&priv->client, queue->queue_id,
215 : 0 : (void *)(size_t)rte_pktmbuf_iova(mbuf),
216 : 0 : mbuf->buf_addr + mbuf->data_off,
217 : 0 : mbuf->data_len,
218 : : 0x0, HIF_LAST_BUFFER | HIF_DATA_VALID,
219 : : mbuf);
220 : : } else {
221 : 0 : hif_lib_xmit_pkt(&priv->client, queue->queue_id,
222 : 0 : (void *)(size_t)rte_pktmbuf_iova(tx_pkts[i]),
223 : 0 : tx_pkts[i]->buf_addr + tx_pkts[i]->data_off,
224 : : tx_pkts[i]->pkt_len, 0 /*ctrl*/,
225 : : HIF_FIRST_BUFFER | HIF_LAST_BUFFER |
226 : : HIF_DATA_VALID,
227 : : tx_pkts[i]);
228 : : }
229 : 0 : stats->obytes += tx_pkts[i]->pkt_len;
230 : : hif_tx_dma_start();
231 : : }
232 : 0 : stats->opackets += nb_pkts;
233 : 0 : pfe_tx_do_cleanup(priv->pfe);
234 : :
235 : 0 : return nb_pkts;
236 : : }
237 : :
238 : : static int
239 : 0 : pfe_eth_open(struct rte_eth_dev *dev)
240 : : {
241 : 0 : struct pfe_eth_priv_s *priv = dev->data->dev_private;
242 : : struct hif_client_s *client;
243 : : struct hif_shm *hif_shm;
244 : : uint16_t i;
245 : : int rc;
246 : :
247 : : /* Register client driver with HIF */
248 : 0 : client = &priv->client;
249 : :
250 [ # # ]: 0 : if (client->pfe) {
251 : 0 : hif_shm = client->pfe->hif.shm;
252 : : /* TODO please remove the below code of if block, once we add
253 : : * the proper cleanup in eth_close
254 : : */
255 : 0 : if (!test_bit(PFE_CL_GEM0 + priv->id,
256 [ # # ]: 0 : &hif_shm->g_client_status[0])) {
257 : : /* Register client driver with HIF */
258 : : memset(client, 0, sizeof(*client));
259 : 0 : client->id = PFE_CL_GEM0 + priv->id;
260 : 0 : client->tx_qn = emac_txq_cnt;
261 : 0 : client->rx_qn = EMAC_RXQ_CNT;
262 : 0 : client->priv = priv;
263 : 0 : client->pfe = priv->pfe;
264 : 0 : client->port_id = dev->data->port_id;
265 : 0 : client->event_handler = pfe_eth_event_handler;
266 : :
267 : 0 : client->tx_qsize = EMAC_TXQ_DEPTH;
268 : 0 : client->rx_qsize = EMAC_RXQ_DEPTH;
269 : :
270 : 0 : rc = hif_lib_client_register(client);
271 [ # # ]: 0 : if (rc) {
272 : 0 : PFE_PMD_ERR("hif_lib_client_register(%d)"
273 : : " failed", client->id);
274 : 0 : goto err0;
275 : : }
276 : : } else {
277 : : /* Freeing the packets if already exists */
278 : : int ret = 0;
279 : : struct rte_mbuf *rx_pkts[32];
280 : : /* TODO multiqueue support */
281 : 0 : ret = hif_lib_receive_pkt(&client->rx_q[0],
282 : : hif_shm->pool, rx_pkts, 32);
283 [ # # ]: 0 : while (ret) {
284 : : int i;
285 [ # # ]: 0 : for (i = 0; i < ret; i++)
286 : 0 : rte_pktmbuf_free(rx_pkts[i]);
287 : 0 : ret = hif_lib_receive_pkt(&client->rx_q[0],
288 : : hif_shm->pool,
289 : : rx_pkts, 32);
290 : : }
291 : : }
292 : : } else {
293 : : /* Register client driver with HIF */
294 : : memset(client, 0, sizeof(*client));
295 : 0 : client->id = PFE_CL_GEM0 + priv->id;
296 : 0 : client->tx_qn = emac_txq_cnt;
297 : 0 : client->rx_qn = EMAC_RXQ_CNT;
298 : 0 : client->priv = priv;
299 : 0 : client->pfe = priv->pfe;
300 : 0 : client->port_id = dev->data->port_id;
301 : 0 : client->event_handler = pfe_eth_event_handler;
302 : :
303 : 0 : client->tx_qsize = EMAC_TXQ_DEPTH;
304 : 0 : client->rx_qsize = EMAC_RXQ_DEPTH;
305 : :
306 : 0 : rc = hif_lib_client_register(client);
307 [ # # ]: 0 : if (rc) {
308 : 0 : PFE_PMD_ERR("hif_lib_client_register(%d) failed",
309 : : client->id);
310 : 0 : goto err0;
311 : : }
312 : : }
313 : : rc = pfe_eth_start(priv);
314 : 0 : dev->rx_pkt_burst = &pfe_recv_pkts;
315 : 0 : dev->tx_pkt_burst = &pfe_xmit_pkts;
316 : : /* If no prefetch is configured. */
317 [ # # ]: 0 : if (getenv("PFE_INTR_SUPPORT")) {
318 : 0 : dev->rx_pkt_burst = &pfe_recv_pkts_on_intr;
319 : 0 : PFE_PMD_INFO("PFE INTERRUPT Mode enabled");
320 : : }
321 : :
322 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
323 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
324 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
325 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
326 : :
327 : 0 : err0:
328 : 0 : return rc;
329 : : }
330 : :
331 : : static int
332 : 0 : pfe_eth_open_cdev(struct pfe_eth_priv_s *priv)
333 : : {
334 : : int pfe_cdev_fd;
335 : :
336 [ # # ]: 0 : if (priv == NULL)
337 : : return -1;
338 : :
339 : : pfe_cdev_fd = open(PFE_CDEV_PATH, O_RDONLY);
340 [ # # ]: 0 : if (pfe_cdev_fd < 0) {
341 : 0 : PFE_PMD_WARN("Unable to open PFE device file (%s).",
342 : : PFE_CDEV_PATH);
343 : 0 : PFE_PMD_WARN("Link status update will not be available.");
344 : 0 : priv->link_fd = PFE_CDEV_INVALID_FD;
345 : 0 : return -1;
346 : : }
347 : :
348 : 0 : priv->link_fd = pfe_cdev_fd;
349 : :
350 : 0 : return 0;
351 : : }
352 : :
353 : : static void
354 : : pfe_eth_close_cdev(struct pfe_eth_priv_s *priv)
355 : : {
356 : 0 : if (priv == NULL)
357 : : return;
358 : :
359 [ # # ]: 0 : if (priv->link_fd != PFE_CDEV_INVALID_FD) {
360 : 0 : close(priv->link_fd);
361 : 0 : priv->link_fd = PFE_CDEV_INVALID_FD;
362 : : }
363 : : }
364 : :
365 : : static int
366 : 0 : pfe_eth_stop(struct rte_eth_dev *dev/*, int wake*/)
367 : : {
368 : 0 : struct pfe_eth_priv_s *priv = dev->data->dev_private;
369 : : uint16_t i;
370 : :
371 : 0 : dev->data->dev_started = 0;
372 : :
373 : 0 : gemac_disable(priv->EMAC_baseaddr);
374 : 0 : gpi_disable(priv->GPI_baseaddr);
375 : :
376 : 0 : dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
377 : 0 : dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
378 : :
379 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
380 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
381 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
382 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
383 : :
384 : 0 : return 0;
385 : : }
386 : :
387 : : static int
388 : 0 : pfe_eth_close(struct rte_eth_dev *dev)
389 : : {
390 : : int ret;
391 : 0 : PMD_INIT_FUNC_TRACE();
392 : :
393 [ # # ]: 0 : if (!dev)
394 : : return -1;
395 : :
396 [ # # ]: 0 : if (!g_pfe)
397 : : return -1;
398 : :
399 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
400 : : return 0;
401 : :
402 : 0 : ret = pfe_eth_stop(dev);
403 : : /* Close the device file for link status */
404 [ # # ]: 0 : pfe_eth_close_cdev(dev->data->dev_private);
405 : :
406 : 0 : munmap(g_pfe->cbus_baseaddr, g_pfe->cbus_size);
407 : 0 : g_pfe->nb_devs--;
408 : :
409 [ # # ]: 0 : if (g_pfe->nb_devs == 0) {
410 : 0 : pfe_hif_exit(g_pfe);
411 : 0 : pfe_hif_lib_exit(g_pfe);
412 : 0 : rte_free(g_pfe);
413 : 0 : g_pfe = NULL;
414 : : }
415 : :
416 : : return ret;
417 : : }
418 : :
419 : : static int
420 : 0 : pfe_eth_configure(struct rte_eth_dev *dev __rte_unused)
421 : : {
422 : 0 : return 0;
423 : : }
424 : :
425 : : static int
426 : 0 : pfe_eth_info(struct rte_eth_dev *dev,
427 : : struct rte_eth_dev_info *dev_info)
428 : : {
429 : 0 : dev_info->max_mac_addrs = PFE_MAX_MACS;
430 : 0 : dev_info->max_rx_queues = dev->data->nb_rx_queues;
431 : 0 : dev_info->max_tx_queues = dev->data->nb_tx_queues;
432 : 0 : dev_info->min_rx_bufsize = HIF_RX_PKT_MIN_SIZE;
433 : 0 : dev_info->min_mtu = RTE_ETHER_MIN_MTU;
434 : 0 : dev_info->rx_offload_capa = dev_rx_offloads_sup;
435 : 0 : dev_info->tx_offload_capa = dev_tx_offloads_sup;
436 [ # # ]: 0 : if (pfe_svr == SVR_LS1012A_REV1) {
437 : 0 : dev_info->max_rx_pktlen = MAX_MTU_ON_REV1 + PFE_ETH_OVERHEAD;
438 : 0 : dev_info->max_mtu = MAX_MTU_ON_REV1;
439 : : } else {
440 : 0 : dev_info->max_rx_pktlen = JUMBO_FRAME_SIZE;
441 : 0 : dev_info->max_mtu = JUMBO_FRAME_SIZE - PFE_ETH_OVERHEAD;
442 : : }
443 : :
444 : 0 : return 0;
445 : : }
446 : :
447 : : /* Only first mb_pool given on first call of this API will be used
448 : : * in whole system, also nb_rx_desc and rx_conf are unused params
449 : : */
450 : : static int
451 : 0 : pfe_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
452 : : __rte_unused uint16_t nb_rx_desc,
453 : : __rte_unused unsigned int socket_id,
454 : : __rte_unused const struct rte_eth_rxconf *rx_conf,
455 : : struct rte_mempool *mb_pool)
456 : : {
457 : : int rc = 0;
458 : : struct pfe *pfe;
459 : 0 : struct pfe_eth_priv_s *priv = dev->data->dev_private;
460 : :
461 : 0 : pfe = priv->pfe;
462 : :
463 [ # # ]: 0 : if (queue_idx >= EMAC_RXQ_CNT) {
464 : 0 : PFE_PMD_ERR("Invalid queue idx = %d, Max queues = %d",
465 : : queue_idx, EMAC_RXQ_CNT);
466 : 0 : return -1;
467 : : }
468 : :
469 [ # # ]: 0 : if (!pfe->hif.setuped) {
470 : 0 : rc = pfe_hif_shm_init(pfe->hif.shm, mb_pool);
471 [ # # ]: 0 : if (rc) {
472 : 0 : PFE_PMD_ERR("Could not allocate buffer descriptors");
473 : 0 : return -1;
474 : : }
475 : :
476 : 0 : pfe->hif.shm->pool = mb_pool;
477 [ # # ]: 0 : if (pfe_hif_init_buffers(&pfe->hif)) {
478 : 0 : PFE_PMD_ERR("Could not initialize buffer descriptors");
479 : 0 : return -1;
480 : : }
481 : 0 : hif_init();
482 : 0 : hif_rx_enable();
483 : 0 : hif_tx_enable();
484 : 0 : pfe->hif.setuped = 1;
485 : : }
486 : 0 : dev->data->rx_queues[queue_idx] = &priv->client.rx_q[queue_idx];
487 : 0 : priv->client.rx_q[queue_idx].queue_id = queue_idx;
488 : :
489 : 0 : return 0;
490 : : }
491 : :
492 : : static int
493 : 0 : pfe_tx_queue_setup(struct rte_eth_dev *dev,
494 : : uint16_t queue_idx,
495 : : __rte_unused uint16_t nb_desc,
496 : : __rte_unused unsigned int socket_id,
497 : : __rte_unused const struct rte_eth_txconf *tx_conf)
498 : : {
499 : 0 : struct pfe_eth_priv_s *priv = dev->data->dev_private;
500 : :
501 [ # # ]: 0 : if (queue_idx >= emac_txq_cnt) {
502 : 0 : PFE_PMD_ERR("Invalid queue idx = %d, Max queues = %d",
503 : : queue_idx, emac_txq_cnt);
504 : 0 : return -1;
505 : : }
506 : 0 : dev->data->tx_queues[queue_idx] = &priv->client.tx_q[queue_idx];
507 : 0 : priv->client.tx_q[queue_idx].queue_id = queue_idx;
508 : 0 : return 0;
509 : : }
510 : :
511 : : static const uint32_t *
512 : 0 : pfe_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
513 : : {
514 : : static const uint32_t ptypes[] = {
515 : : /*todo -= add more types */
516 : : RTE_PTYPE_L2_ETHER,
517 : : RTE_PTYPE_L3_IPV4,
518 : : RTE_PTYPE_L3_IPV4_EXT,
519 : : RTE_PTYPE_L3_IPV6,
520 : : RTE_PTYPE_L3_IPV6_EXT,
521 : : RTE_PTYPE_L4_TCP,
522 : : RTE_PTYPE_L4_UDP,
523 : : RTE_PTYPE_L4_SCTP,
524 : : };
525 : :
526 [ # # # # ]: 0 : if (dev->rx_pkt_burst == pfe_recv_pkts ||
527 : : dev->rx_pkt_burst == pfe_recv_pkts_on_intr) {
528 : 0 : *no_of_elements = RTE_DIM(ptypes);
529 : 0 : return ptypes;
530 : : }
531 : : return NULL;
532 : : }
533 : :
534 : : static inline int
535 : : pfe_eth_atomic_read_link_status(struct rte_eth_dev *dev,
536 : : struct rte_eth_link *link)
537 : : {
538 : : struct rte_eth_link *dst = link;
539 : : struct rte_eth_link *src = &dev->data->dev_link;
540 : :
541 : 0 : if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
542 : : *(uint64_t *)src) == 0)
543 : : return -1;
544 : :
545 : : return 0;
546 : : }
547 : :
548 : : static inline int
549 : : pfe_eth_atomic_write_link_status(struct rte_eth_dev *dev,
550 : : struct rte_eth_link *link)
551 : : {
552 : 0 : struct rte_eth_link *dst = &dev->data->dev_link;
553 : : struct rte_eth_link *src = link;
554 : :
555 : 0 : if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
556 : : *(uint64_t *)src) == 0)
557 : : return -1;
558 : :
559 : : return 0;
560 : : }
561 : :
562 : : static int
563 : 0 : pfe_eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)
564 : : {
565 : : int ret, ioctl_cmd = 0;
566 : 0 : struct pfe_eth_priv_s *priv = dev->data->dev_private;
567 : : struct rte_eth_link link, old;
568 : 0 : unsigned int lstatus = 1;
569 : :
570 : : memset(&old, 0, sizeof(old));
571 : : memset(&link, 0, sizeof(struct rte_eth_link));
572 : :
573 : : pfe_eth_atomic_read_link_status(dev, &old);
574 : :
575 : : /* Read from PFE CDEV, status of link, if file was successfully
576 : : * opened.
577 : : */
578 [ # # ]: 0 : if (priv->link_fd != PFE_CDEV_INVALID_FD) {
579 [ # # ]: 0 : if (priv->id == 0)
580 : : ioctl_cmd = PFE_CDEV_ETH0_STATE_GET;
581 [ # # ]: 0 : if (priv->id == 1)
582 : : ioctl_cmd = PFE_CDEV_ETH1_STATE_GET;
583 : :
584 : 0 : ret = ioctl(priv->link_fd, ioctl_cmd, &lstatus);
585 [ # # ]: 0 : if (ret != 0) {
586 : 0 : PFE_PMD_ERR("Unable to fetch link status (ioctl)");
587 : 0 : return -1;
588 : : }
589 : 0 : PFE_PMD_DEBUG("Fetched link state (%d) for dev %d.",
590 : : lstatus, priv->id);
591 : : }
592 : :
593 [ # # ]: 0 : if (old.link_status == lstatus) {
594 : : /* no change in status */
595 : 0 : PFE_PMD_DEBUG("No change in link status; Not updating.");
596 : 0 : return -1;
597 : : }
598 : :
599 : 0 : link.link_status = lstatus;
600 : 0 : link.link_speed = RTE_ETH_LINK_SPEED_1G;
601 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
602 : 0 : link.link_autoneg = RTE_ETH_LINK_AUTONEG;
603 : :
604 : : pfe_eth_atomic_write_link_status(dev, &link);
605 : :
606 [ # # ]: 0 : PFE_PMD_INFO("Port (%d) link is %s", dev->data->port_id,
607 : : link.link_status ? "up" : "down");
608 : :
609 : 0 : return 0;
610 : : }
611 : :
612 : : static int
613 : 0 : pfe_promiscuous_enable(struct rte_eth_dev *dev)
614 : : {
615 : 0 : struct pfe_eth_priv_s *priv = dev->data->dev_private;
616 : :
617 : 0 : priv->promisc = 1;
618 : 0 : dev->data->promiscuous = 1;
619 : 0 : gemac_enable_copy_all(priv->EMAC_baseaddr);
620 : :
621 : 0 : return 0;
622 : : }
623 : :
624 : : static int
625 : 0 : pfe_promiscuous_disable(struct rte_eth_dev *dev)
626 : : {
627 : 0 : struct pfe_eth_priv_s *priv = dev->data->dev_private;
628 : :
629 : 0 : priv->promisc = 0;
630 : 0 : dev->data->promiscuous = 0;
631 : 0 : gemac_disable_copy_all(priv->EMAC_baseaddr);
632 : :
633 : 0 : return 0;
634 : : }
635 : :
636 : : static int
637 : 0 : pfe_allmulticast_enable(struct rte_eth_dev *dev)
638 : : {
639 : 0 : struct pfe_eth_priv_s *priv = dev->data->dev_private;
640 : : struct pfe_mac_addr hash_addr; /* hash register structure */
641 : :
642 : : /* Set the hash to rx all multicast frames */
643 : 0 : hash_addr.bottom = 0xFFFFFFFF;
644 : 0 : hash_addr.top = 0xFFFFFFFF;
645 : 0 : gemac_set_hash(priv->EMAC_baseaddr, &hash_addr);
646 : 0 : dev->data->all_multicast = 1;
647 : :
648 : 0 : return 0;
649 : : }
650 : :
651 : : static int
652 : 0 : pfe_link_down(struct rte_eth_dev *dev)
653 : : {
654 : 0 : return pfe_eth_stop(dev);
655 : : }
656 : :
657 : : static int
658 : 0 : pfe_link_up(struct rte_eth_dev *dev)
659 : : {
660 : 0 : struct pfe_eth_priv_s *priv = dev->data->dev_private;
661 : :
662 : : pfe_eth_start(priv);
663 : 0 : return 0;
664 : : }
665 : :
666 : : static int
667 : 0 : pfe_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
668 : : {
669 : 0 : struct pfe_eth_priv_s *priv = dev->data->dev_private;
670 : 0 : uint16_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
671 : :
672 : : /*TODO Support VLAN*/
673 : 0 : return gemac_set_rx(priv->EMAC_baseaddr, frame_size);
674 : : }
675 : :
676 : : /* pfe_eth_enet_addr_byte_mac
677 : : */
678 : : static int
679 : : pfe_eth_enet_addr_byte_mac(u8 *enet_byte_addr,
680 : : struct pfe_mac_addr *enet_addr)
681 : : {
682 : 0 : if (!enet_byte_addr || !enet_addr) {
683 : : return -1;
684 : :
685 : : } else {
686 : 0 : enet_addr->bottom = enet_byte_addr[0] |
687 : 0 : (enet_byte_addr[1] << 8) |
688 : 0 : (enet_byte_addr[2] << 16) |
689 : 0 : (enet_byte_addr[3] << 24);
690 : 0 : enet_addr->top = enet_byte_addr[4] |
691 : 0 : (enet_byte_addr[5] << 8);
692 : : return 0;
693 : : }
694 : : }
695 : :
696 : : static int
697 : 0 : pfe_dev_set_mac_addr(struct rte_eth_dev *dev,
698 : : struct rte_ether_addr *addr)
699 : : {
700 : 0 : struct pfe_eth_priv_s *priv = dev->data->dev_private;
701 : : struct pfe_mac_addr spec_addr;
702 : : int ret;
703 : :
704 [ # # ]: 0 : ret = pfe_eth_enet_addr_byte_mac(addr->addr_bytes, &spec_addr);
705 : : if (ret)
706 : : return ret;
707 : :
708 : 0 : gemac_set_laddrN(priv->EMAC_baseaddr,
709 : : (struct pfe_mac_addr *)&spec_addr, 1);
710 : 0 : rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);
711 : 0 : return 0;
712 : : }
713 : :
714 : : static int
715 : 0 : pfe_stats_get(struct rte_eth_dev *dev,
716 : : struct rte_eth_stats *stats,
717 : : struct eth_queue_stats *qstats __rte_unused)
718 : : {
719 : 0 : struct pfe_eth_priv_s *priv = dev->data->dev_private;
720 : : struct rte_eth_stats *eth_stats = &priv->stats;
721 : :
722 [ # # ]: 0 : if (stats == NULL)
723 : : return -1;
724 : :
725 : : memset(stats, 0, sizeof(struct rte_eth_stats));
726 : :
727 : 0 : stats->ipackets = eth_stats->ipackets;
728 : 0 : stats->ibytes = eth_stats->ibytes;
729 : 0 : stats->opackets = eth_stats->opackets;
730 : 0 : stats->obytes = eth_stats->obytes;
731 : :
732 : 0 : return 0;
733 : : }
734 : :
735 : : static const struct eth_dev_ops ops = {
736 : : .dev_start = pfe_eth_open,
737 : : .dev_stop = pfe_eth_stop,
738 : : .dev_close = pfe_eth_close,
739 : : .dev_configure = pfe_eth_configure,
740 : : .dev_infos_get = pfe_eth_info,
741 : : .rx_queue_setup = pfe_rx_queue_setup,
742 : : .tx_queue_setup = pfe_tx_queue_setup,
743 : : .dev_supported_ptypes_get = pfe_supported_ptypes_get,
744 : : .link_update = pfe_eth_link_update,
745 : : .promiscuous_enable = pfe_promiscuous_enable,
746 : : .promiscuous_disable = pfe_promiscuous_disable,
747 : : .allmulticast_enable = pfe_allmulticast_enable,
748 : : .dev_set_link_down = pfe_link_down,
749 : : .dev_set_link_up = pfe_link_up,
750 : : .mtu_set = pfe_mtu_set,
751 : : .mac_addr_set = pfe_dev_set_mac_addr,
752 : : .stats_get = pfe_stats_get,
753 : : };
754 : :
755 : : static int
756 : 0 : pfe_eth_init(struct rte_vdev_device *vdev, struct pfe *pfe, int id)
757 : : {
758 : : struct rte_eth_dev *eth_dev = NULL;
759 : : struct pfe_eth_priv_s *priv = NULL;
760 : : struct ls1012a_eth_platform_data *einfo;
761 : : struct ls1012a_pfe_platform_data *pfe_info;
762 : : struct rte_ether_addr addr;
763 : : int err;
764 : :
765 : 0 : eth_dev = rte_eth_vdev_allocate(vdev, sizeof(*priv));
766 [ # # ]: 0 : if (eth_dev == NULL)
767 : : return -ENOMEM;
768 : :
769 : : /* Extract platform data */
770 : : pfe_info = (struct ls1012a_pfe_platform_data *)&pfe->platform_data;
771 : : if (!pfe_info) {
772 : : PFE_PMD_ERR("pfe missing additional platform data");
773 : : err = -ENODEV;
774 : : goto err0;
775 : : }
776 : :
777 : 0 : einfo = (struct ls1012a_eth_platform_data *)pfe_info->ls1012a_eth_pdata;
778 : :
779 : : /* einfo never be NULL, but no harm in having this check */
780 : : if (!einfo) {
781 : : PFE_PMD_ERR("pfe missing additional gemacs platform data");
782 : : err = -ENODEV;
783 : : goto err0;
784 : : }
785 : :
786 : 0 : priv = eth_dev->data->dev_private;
787 : 0 : priv->ndev = eth_dev;
788 : 0 : priv->id = einfo[id].gem_id;
789 : 0 : priv->pfe = pfe;
790 : :
791 : 0 : pfe->eth.eth_priv[id] = priv;
792 : :
793 : : /* Set the info in the priv to the current info */
794 : 0 : priv->einfo = &einfo[id];
795 : 0 : priv->EMAC_baseaddr = cbus_emac_base[id];
796 : 0 : priv->PHY_baseaddr = cbus_emac_base[id];
797 : 0 : priv->GPI_baseaddr = cbus_gpi_base[id];
798 : :
799 : : #define HIF_GEMAC_TMUQ_BASE 6
800 : 0 : priv->low_tmu_q = HIF_GEMAC_TMUQ_BASE + (id * 2);
801 : 0 : priv->high_tmu_q = priv->low_tmu_q + 1;
802 : :
803 : : rte_spinlock_init(&priv->lock);
804 : :
805 : : /* Copy the station address into the dev structure, */
806 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("mac_addr",
807 : : ETHER_ADDR_LEN * PFE_MAX_MACS, 0);
808 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
809 : 0 : PFE_PMD_ERR("Failed to allocate mem %d to store MAC addresses",
810 : : ETHER_ADDR_LEN * PFE_MAX_MACS);
811 : : err = -ENOMEM;
812 : 0 : goto err0;
813 : : }
814 : :
815 : 0 : memcpy(addr.addr_bytes, priv->einfo->mac_addr,
816 : : ETH_ALEN);
817 : :
818 : 0 : pfe_dev_set_mac_addr(eth_dev, &addr);
819 : 0 : rte_ether_addr_copy(&addr, ð_dev->data->mac_addrs[0]);
820 : :
821 : 0 : eth_dev->data->mtu = 1500;
822 : 0 : eth_dev->dev_ops = &ops;
823 : 0 : err = pfe_eth_stop(eth_dev);
824 [ # # ]: 0 : if (err != 0)
825 : 0 : goto err0;
826 : 0 : pfe_gemac_init(priv);
827 : :
828 : 0 : eth_dev->data->nb_rx_queues = 1;
829 : 0 : eth_dev->data->nb_tx_queues = 1;
830 : :
831 : : /* For link status, open the PFE CDEV; Error from this function
832 : : * is silently ignored; In case of error, the link status will not
833 : : * be available.
834 : : */
835 : 0 : pfe_eth_open_cdev(priv);
836 : 0 : rte_eth_dev_probing_finish(eth_dev);
837 : :
838 : 0 : return 0;
839 : 0 : err0:
840 : 0 : rte_eth_dev_release_port(eth_dev);
841 : 0 : return err;
842 : : }
843 : :
844 : : static int
845 : 0 : pfe_get_gemac_if_proprties(struct pfe *pfe,
846 : : __rte_unused const struct device_node *parent,
847 : : unsigned int port, unsigned int if_cnt,
848 : : struct ls1012a_pfe_platform_data *pdata)
849 : : {
850 : : const struct device_node *gem = NULL;
851 : : size_t size;
852 : : unsigned int ii = 0, phy_id = 0;
853 : : const u32 *addr;
854 : : const void *mac_addr;
855 : :
856 [ # # ]: 0 : for (ii = 0; ii < if_cnt; ii++) {
857 : 0 : gem = of_get_next_child(parent, gem);
858 [ # # ]: 0 : if (!gem)
859 : 0 : goto err;
860 : 0 : addr = of_get_property(gem, "reg", &size);
861 [ # # # # : 0 : if (addr && (rte_be_to_cpu_32((unsigned int)*addr) == port))
# # ]
862 : : break;
863 : : }
864 : :
865 [ # # ]: 0 : if (ii >= if_cnt) {
866 : 0 : PFE_PMD_ERR("Failed to find interface = %d", if_cnt);
867 : 0 : goto err;
868 : : }
869 : :
870 : 0 : pdata->ls1012a_eth_pdata[port].gem_id = port;
871 : :
872 : 0 : mac_addr = of_get_mac_address(gem);
873 : :
874 [ # # ]: 0 : if (mac_addr) {
875 : 0 : memcpy(pdata->ls1012a_eth_pdata[port].mac_addr, mac_addr,
876 : : ETH_ALEN);
877 : : }
878 : :
879 : 0 : addr = of_get_property(gem, "fsl,mdio-mux-val", &size);
880 [ # # ]: 0 : if (!addr) {
881 : 0 : PFE_PMD_ERR("Invalid mdio-mux-val....");
882 : : } else {
883 [ # # ]: 0 : phy_id = rte_be_to_cpu_32((unsigned int)*addr);
884 : 0 : pdata->ls1012a_eth_pdata[port].mdio_muxval = phy_id;
885 : : }
886 [ # # ]: 0 : if (pdata->ls1012a_eth_pdata[port].phy_id < 32)
887 : 0 : pfe->mdio_muxval[pdata->ls1012a_eth_pdata[port].phy_id] =
888 : 0 : pdata->ls1012a_eth_pdata[port].mdio_muxval;
889 : :
890 : : return 0;
891 : :
892 : : err:
893 : : return -1;
894 : : }
895 : :
896 : : /* Parse integer from integer argument */
897 : : static int
898 : 0 : parse_integer_arg(const char *key __rte_unused,
899 : : const char *value, void *extra_args)
900 : : {
901 : : int i;
902 : : char *end;
903 : 0 : errno = 0;
904 : :
905 : 0 : i = strtol(value, &end, 10);
906 [ # # # # : 0 : if (*end != 0 || errno != 0 || i < 0 || i > 1) {
# # ]
907 : 0 : PFE_PMD_ERR("Supported Port IDS are 0 and 1");
908 : 0 : return -EINVAL;
909 : : }
910 : :
911 : 0 : *((uint32_t *)extra_args) = i;
912 : :
913 : 0 : return 0;
914 : : }
915 : :
916 : : static int
917 [ # # ]: 0 : pfe_parse_vdev_init_params(struct pfe_vdev_init_params *params,
918 : : struct rte_vdev_device *dev)
919 : : {
920 : : struct rte_kvargs *kvlist = NULL;
921 : : int ret = 0;
922 : :
923 : : static const char * const pfe_vdev_valid_params[] = {
924 : : PFE_VDEV_GEM_ID_ARG,
925 : : NULL
926 : : };
927 : :
928 : : const char *input_args = rte_vdev_device_args(dev);
929 : :
930 [ # # ]: 0 : if (!input_args)
931 : : return -1;
932 : :
933 : 0 : kvlist = rte_kvargs_parse(input_args, pfe_vdev_valid_params);
934 [ # # ]: 0 : if (kvlist == NULL)
935 : : return -1;
936 : :
937 : 0 : ret = rte_kvargs_process(kvlist,
938 : : PFE_VDEV_GEM_ID_ARG,
939 : : &parse_integer_arg,
940 : 0 : ¶ms->gem_id);
941 : 0 : rte_kvargs_free(kvlist);
942 : 0 : return ret;
943 : : }
944 : :
945 : : static int
946 : 0 : pmd_pfe_probe(struct rte_vdev_device *vdev)
947 : : {
948 : : const u32 *prop;
949 : : const struct device_node *np;
950 : : const char *name;
951 : : const uint32_t *addr;
952 : : uint64_t cbus_addr, ddr_size, cbus_size;
953 : : int rc = -1, fd = -1, gem_id;
954 : : unsigned int ii, interface_count = 0;
955 : 0 : size_t size = 0;
956 [ # # ]: 0 : struct pfe_vdev_init_params init_params = {
957 : : .gem_id = -1
958 : : };
959 : :
960 : : name = rte_vdev_device_name(vdev);
961 : 0 : rc = pfe_parse_vdev_init_params(&init_params, vdev);
962 [ # # ]: 0 : if (rc < 0)
963 : : return -EINVAL;
964 : :
965 : 0 : PFE_PMD_LOG(INFO, "Initializing pmd_pfe for %s Given gem-id %d",
966 : : name, init_params.gem_id);
967 : :
968 [ # # ]: 0 : if (g_pfe) {
969 [ # # ]: 0 : if (g_pfe->nb_devs >= g_pfe->max_intf) {
970 : 0 : PFE_PMD_ERR("PFE %d dev already created Max is %d",
971 : : g_pfe->nb_devs, g_pfe->max_intf);
972 : 0 : return -EINVAL;
973 : : }
974 : 0 : goto eth_init;
975 : : }
976 : :
977 : 0 : g_pfe = rte_zmalloc(NULL, sizeof(*g_pfe), RTE_CACHE_LINE_SIZE);
978 [ # # ]: 0 : if (g_pfe == NULL)
979 : : return -EINVAL;
980 : :
981 : : /* Load the device-tree driver */
982 : : rc = of_init();
983 [ # # ]: 0 : if (rc) {
984 : 0 : PFE_PMD_ERR("of_init failed with ret: %d", rc);
985 : 0 : goto err;
986 : : }
987 : :
988 : 0 : np = of_find_compatible_node(NULL, NULL, "fsl,pfe");
989 [ # # ]: 0 : if (!np) {
990 : 0 : PFE_PMD_ERR("Invalid device node");
991 : : rc = -EINVAL;
992 : 0 : goto err;
993 : : }
994 : :
995 : 0 : addr = of_get_address(np, 0, &cbus_size, NULL);
996 [ # # ]: 0 : if (!addr) {
997 : 0 : PFE_PMD_ERR("of_get_address cannot return qman address");
998 : 0 : goto err;
999 : : }
1000 : 0 : cbus_addr = of_translate_address(np, addr);
1001 [ # # ]: 0 : if (!cbus_addr) {
1002 : 0 : PFE_PMD_ERR("of_translate_address failed");
1003 : 0 : goto err;
1004 : : }
1005 : :
1006 : 0 : addr = of_get_address(np, 1, &ddr_size, NULL);
1007 [ # # ]: 0 : if (!addr) {
1008 : 0 : PFE_PMD_ERR("of_get_address cannot return qman address");
1009 : 0 : goto err;
1010 : : }
1011 : :
1012 : 0 : g_pfe->ddr_phys_baseaddr = of_translate_address(np, addr);
1013 [ # # ]: 0 : if (!g_pfe->ddr_phys_baseaddr) {
1014 : 0 : PFE_PMD_ERR("of_translate_address failed");
1015 : 0 : goto err;
1016 : : }
1017 : :
1018 : 0 : g_pfe->ddr_baseaddr = pfe_mem_ptov(g_pfe->ddr_phys_baseaddr);
1019 : 0 : g_pfe->ddr_size = ddr_size;
1020 : 0 : g_pfe->cbus_size = cbus_size;
1021 : :
1022 : : fd = open("/dev/mem", O_RDWR);
1023 : 0 : g_pfe->cbus_baseaddr = mmap(NULL, cbus_size, PROT_READ | PROT_WRITE,
1024 : : MAP_SHARED, fd, cbus_addr);
1025 : 0 : close(fd);
1026 [ # # ]: 0 : if (g_pfe->cbus_baseaddr == MAP_FAILED) {
1027 : 0 : PFE_PMD_ERR("Can not map cbus base");
1028 : : rc = -EINVAL;
1029 : 0 : goto err;
1030 : : }
1031 : :
1032 : : /* Read interface count */
1033 : 0 : prop = of_get_property(np, "fsl,pfe-num-interfaces", &size);
1034 [ # # ]: 0 : if (!prop) {
1035 : 0 : PFE_PMD_ERR("Failed to read number of interfaces");
1036 : : rc = -ENXIO;
1037 : 0 : goto err_prop;
1038 : : }
1039 : :
1040 [ # # ]: 0 : interface_count = rte_be_to_cpu_32((unsigned int)*prop);
1041 [ # # ]: 0 : if (interface_count <= 0) {
1042 : 0 : PFE_PMD_ERR("No ethernet interface count : %d",
1043 : : interface_count);
1044 : : rc = -ENXIO;
1045 : 0 : goto err_prop;
1046 : : }
1047 : 0 : PFE_PMD_INFO("num interfaces = %d ", interface_count);
1048 : :
1049 : 0 : g_pfe->max_intf = interface_count;
1050 : 0 : g_pfe->platform_data.ls1012a_mdio_pdata[0].phy_mask = 0xffffffff;
1051 : :
1052 [ # # ]: 0 : for (ii = 0; ii < interface_count; ii++) {
1053 : 0 : pfe_get_gemac_if_proprties(g_pfe, np, ii, interface_count,
1054 : 0 : &g_pfe->platform_data);
1055 : : }
1056 : :
1057 : 0 : pfe_lib_init(g_pfe->cbus_baseaddr, g_pfe->ddr_baseaddr,
1058 : 0 : g_pfe->ddr_phys_baseaddr, g_pfe->ddr_size);
1059 : :
1060 : 0 : PFE_PMD_INFO("CLASS version: %x", readl(CLASS_VERSION));
1061 : 0 : PFE_PMD_INFO("TMU version: %x", readl(TMU_VERSION));
1062 : :
1063 : 0 : PFE_PMD_INFO("BMU1 version: %x", readl(BMU1_BASE_ADDR + BMU_VERSION));
1064 : 0 : PFE_PMD_INFO("BMU2 version: %x", readl(BMU2_BASE_ADDR + BMU_VERSION));
1065 : :
1066 : 0 : PFE_PMD_INFO("EGPI1 version: %x", readl(EGPI1_BASE_ADDR + GPI_VERSION));
1067 : 0 : PFE_PMD_INFO("EGPI2 version: %x", readl(EGPI2_BASE_ADDR + GPI_VERSION));
1068 : 0 : PFE_PMD_INFO("HGPI version: %x", readl(HGPI_BASE_ADDR + GPI_VERSION));
1069 : :
1070 : 0 : PFE_PMD_INFO("HIF version: %x", readl(HIF_VERSION));
1071 : 0 : PFE_PMD_INFO("HIF NOPCY version: %x", readl(HIF_NOCPY_VERSION));
1072 : :
1073 : 0 : cbus_emac_base[0] = EMAC1_BASE_ADDR;
1074 : 0 : cbus_emac_base[1] = EMAC2_BASE_ADDR;
1075 : :
1076 : 0 : cbus_gpi_base[0] = EGPI1_BASE_ADDR;
1077 : 0 : cbus_gpi_base[1] = EGPI2_BASE_ADDR;
1078 : :
1079 : 0 : rc = pfe_hif_lib_init(g_pfe);
1080 [ # # ]: 0 : if (rc < 0)
1081 : 0 : goto err_hif_lib;
1082 : :
1083 : 0 : rc = pfe_hif_init(g_pfe);
1084 [ # # ]: 0 : if (rc < 0)
1085 : 0 : goto err_hif;
1086 : 0 : pfe_soc_version_get();
1087 : 0 : eth_init:
1088 [ # # ]: 0 : if (init_params.gem_id < 0)
1089 : 0 : gem_id = g_pfe->nb_devs;
1090 : : else
1091 : 0 : gem_id = init_params.gem_id;
1092 : :
1093 : 0 : PFE_PMD_LOG(INFO, "Init pmd_pfe for %s gem-id %d(given =%d)",
1094 : : name, gem_id, init_params.gem_id);
1095 : :
1096 : 0 : rc = pfe_eth_init(vdev, g_pfe, gem_id);
1097 [ # # ]: 0 : if (rc < 0)
1098 : 0 : goto err_eth;
1099 : : else
1100 : 0 : g_pfe->nb_devs++;
1101 : :
1102 : 0 : return 0;
1103 : :
1104 : : err_eth:
1105 : 0 : pfe_hif_exit(g_pfe);
1106 : :
1107 : 0 : err_hif:
1108 : 0 : pfe_hif_lib_exit(g_pfe);
1109 : :
1110 : 0 : err_hif_lib:
1111 : 0 : err_prop:
1112 : 0 : munmap(g_pfe->cbus_baseaddr, cbus_size);
1113 : 0 : err:
1114 : 0 : rte_free(g_pfe);
1115 : 0 : return rc;
1116 : : }
1117 : :
1118 : : static int
1119 [ # # ]: 0 : pmd_pfe_remove(struct rte_vdev_device *vdev)
1120 : : {
1121 : : const char *name;
1122 : : struct rte_eth_dev *eth_dev = NULL;
1123 : : int ret = 0;
1124 : :
1125 : : name = rte_vdev_device_name(vdev);
1126 : : if (name == NULL)
1127 : : return -EINVAL;
1128 : :
1129 : 0 : PFE_PMD_INFO("Closing eventdev sw device %s", name);
1130 : :
1131 [ # # ]: 0 : if (!g_pfe)
1132 : : return 0;
1133 : :
1134 : 0 : eth_dev = rte_eth_dev_allocated(name);
1135 [ # # ]: 0 : if (eth_dev) {
1136 : 0 : pfe_eth_close(eth_dev);
1137 : 0 : ret = rte_eth_dev_release_port(eth_dev);
1138 : : }
1139 : :
1140 : : return ret;
1141 : : }
1142 : :
1143 : : static
1144 : : struct rte_vdev_driver pmd_pfe_drv = {
1145 : : .probe = pmd_pfe_probe,
1146 : : .remove = pmd_pfe_remove,
1147 : : };
1148 : :
1149 : 253 : RTE_PMD_REGISTER_VDEV(PFE_NAME_PMD, pmd_pfe_drv);
1150 : : RTE_PMD_REGISTER_PARAM_STRING(PFE_NAME_PMD, PFE_VDEV_GEM_ID_ARG "=<int> ");
1151 [ - + ]: 253 : RTE_LOG_REGISTER_DEFAULT(pfe_logtype_pmd, NOTICE);
|