Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2020-2021,2023-2024 NXP
3 : : */
4 : :
5 : : #include <inttypes.h>
6 : :
7 : : #include <ethdev_vdev.h>
8 : : #include <ethdev_driver.h>
9 : : #include <rte_bitops.h>
10 : : #include <rte_io.h>
11 : :
12 : : #include "enet_pmd_logs.h"
13 : : #include "enet_ethdev.h"
14 : : #include "enet_regs.h"
15 : : #include "enet_uio.h"
16 : :
17 : : /* Supported Rx offloads */
18 : : static uint64_t dev_rx_offloads_sup =
19 : : RTE_ETH_RX_OFFLOAD_CHECKSUM |
20 : : RTE_ETH_RX_OFFLOAD_VLAN;
21 : :
22 : : /*
23 : : * This function is called to start or restart the ENETFEC during a link
24 : : * change, transmit timeout, or to reconfigure the ENETFEC. The network
25 : : * packet processing for this device must be stopped before this call.
26 : : */
27 : : static void
28 : 0 : enetfec_restart(struct rte_eth_dev *dev)
29 : : {
30 : 0 : struct enetfec_private *fep = dev->data->dev_private;
31 : : uint32_t rcntl = OPT_FRAME_SIZE | 0x04;
32 : : uint32_t ecntl = ENETFEC_ETHEREN;
33 : : uint32_t val;
34 : : int i;
35 : :
36 : : /* Clear any outstanding interrupt. */
37 : 0 : writel(0xffffffff, (uint8_t *)fep->hw_baseaddr_v + ENETFEC_EIR);
38 : :
39 : : /* Enable MII mode */
40 [ # # ]: 0 : if (fep->full_duplex == FULL_DUPLEX) {
41 : : /* FD enable */
42 : : rte_write32(rte_cpu_to_le_32(0x04),
43 : : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_TCR);
44 : : } else {
45 : : /* No Rcv on Xmit */
46 : : rcntl |= 0x02;
47 : : rte_write32(0, (uint8_t *)fep->hw_baseaddr_v + ENETFEC_TCR);
48 : : }
49 : :
50 [ # # ]: 0 : if (fep->quirks & QUIRK_RACC) {
51 : 0 : val = rte_read32((uint8_t *)fep->hw_baseaddr_v + ENETFEC_RACC);
52 : : /* align IP header */
53 : : val |= ENETFEC_RACC_SHIFT16;
54 [ # # ]: 0 : if (fep->flag_csum & RX_FLAG_CSUM_EN)
55 : : /* set RX checksum */
56 : 0 : val |= ENETFEC_RACC_OPTIONS;
57 : : else
58 : 0 : val &= ~ENETFEC_RACC_OPTIONS;
59 : : rte_write32(rte_cpu_to_le_32(val),
60 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_RACC);
61 : : rte_write32(rte_cpu_to_le_32(PKT_MAX_BUF_SIZE),
62 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_FRAME_TRL);
63 : : }
64 : :
65 : : /*
66 : : * The phy interface and speed need to get configured
67 : : * differently on enet-mac.
68 : : */
69 [ # # ]: 0 : if (fep->quirks & QUIRK_HAS_ENETFEC_MAC) {
70 : : /* Enable flow control and length check */
71 : : rcntl |= 0x40000000 | 0x00000020;
72 : :
73 : : /* RGMII, RMII or MII */
74 : 0 : rcntl |= RTE_BIT32(6);
75 : : ecntl |= RTE_BIT32(5);
76 : : }
77 : :
78 : : /* enable pause frame*/
79 [ # # ]: 0 : if ((fep->flag_pause & ENETFEC_PAUSE_FLAG_ENABLE) ||
80 : : ((fep->flag_pause & ENETFEC_PAUSE_FLAG_AUTONEG)
81 : : /*&& ndev->phydev && ndev->phydev->pause*/)) {
82 : 0 : rcntl |= ENETFEC_FCE;
83 : :
84 : : /* set FIFO threshold parameter to reduce overrun */
85 : : rte_write32(rte_cpu_to_le_32(ENETFEC_RSEM_V),
86 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_R_FIFO_SEM);
87 : : rte_write32(rte_cpu_to_le_32(ENETFEC_RSFL_V),
88 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_R_FIFO_SFL);
89 : : rte_write32(rte_cpu_to_le_32(ENETFEC_RAEM_V),
90 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_R_FIFO_AEM);
91 : : rte_write32(rte_cpu_to_le_32(ENETFEC_RAFL_V),
92 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_R_FIFO_AFL);
93 : :
94 : : /* OPD */
95 : : rte_write32(rte_cpu_to_le_32(ENETFEC_OPD_V),
96 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_OPD);
97 : : } else {
98 : 0 : rcntl &= ~ENETFEC_FCE;
99 : : }
100 : :
101 : : rte_write32(rte_cpu_to_le_32(rcntl),
102 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_RCR);
103 : :
104 : 0 : rte_write32(0, (uint8_t *)fep->hw_baseaddr_v + ENETFEC_IAUR);
105 : 0 : rte_write32(0, (uint8_t *)fep->hw_baseaddr_v + ENETFEC_IALR);
106 : :
107 [ # # ]: 0 : if (fep->quirks & QUIRK_HAS_ENETFEC_MAC) {
108 : : /* enable ENETFEC endian swap */
109 : 0 : ecntl |= (1 << 8);
110 : : /* enable ENETFEC store and forward mode */
111 : : rte_write32(rte_cpu_to_le_32(1 << 8),
112 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_TFWR);
113 : : }
114 [ # # ]: 0 : if (fep->bufdesc_ex)
115 : 0 : ecntl |= (1 << 4);
116 [ # # ]: 0 : if (fep->quirks & QUIRK_SUPPORT_DELAYED_CLKS &&
117 [ # # ]: 0 : fep->rgmii_txc_delay)
118 : 0 : ecntl |= ENETFEC_TXC_DLY;
119 [ # # ]: 0 : if (fep->quirks & QUIRK_SUPPORT_DELAYED_CLKS &&
120 [ # # ]: 0 : fep->rgmii_rxc_delay)
121 : 0 : ecntl |= ENETFEC_RXC_DLY;
122 : : /* Enable the MIB statistic event counters */
123 : 0 : rte_write32(0, (uint8_t *)fep->hw_baseaddr_v + ENETFEC_MIBC);
124 : :
125 : 0 : ecntl |= 0x70000000;
126 : 0 : fep->enetfec_e_cntl = ecntl;
127 : : /* And last, enable the transmit and receive processing */
128 : : rte_write32(rte_cpu_to_le_32(ecntl),
129 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_ECR);
130 : :
131 [ # # ]: 0 : for (i = 0; i < fep->max_rx_queues; i++)
132 : 0 : rte_write32(0, fep->rx_queues[i]->bd.active_reg_desc);
133 : 0 : rte_delay_us(10);
134 : 0 : }
135 : :
136 : : static void
137 : 0 : enet_free_buffers(struct rte_eth_dev *dev)
138 : : {
139 : 0 : struct enetfec_private *fep = dev->data->dev_private;
140 : : unsigned int i, q;
141 : : struct rte_mbuf *mbuf;
142 : : struct bufdesc *bdp;
143 : : struct enetfec_priv_rx_q *rxq;
144 : : struct enetfec_priv_tx_q *txq;
145 : :
146 [ # # ]: 0 : for (q = 0; q < dev->data->nb_rx_queues; q++) {
147 : 0 : rxq = fep->rx_queues[q];
148 : : bdp = rxq->bd.base;
149 [ # # ]: 0 : for (i = 0; i < rxq->bd.ring_size; i++) {
150 : 0 : mbuf = rxq->rx_mbuf[i];
151 [ # # ]: 0 : if (mbuf) {
152 : 0 : rxq->rx_mbuf[i] = NULL;
153 : 0 : rte_pktmbuf_free(mbuf);
154 : : }
155 : : bdp = enet_get_nextdesc(bdp, &rxq->bd);
156 : : }
157 : : }
158 : :
159 [ # # ]: 0 : for (q = 0; q < dev->data->nb_tx_queues; q++) {
160 : 0 : txq = fep->tx_queues[q];
161 : : bdp = txq->bd.base;
162 [ # # ]: 0 : for (i = 0; i < txq->bd.ring_size; i++) {
163 : 0 : mbuf = txq->tx_mbuf[i];
164 : 0 : txq->tx_mbuf[i] = NULL;
165 : 0 : rte_pktmbuf_free(mbuf);
166 : : }
167 : : }
168 : 0 : }
169 : :
170 : : static int
171 : 0 : enetfec_eth_configure(struct rte_eth_dev *dev)
172 : : {
173 : 0 : struct enetfec_private *fep = dev->data->dev_private;
174 : :
175 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM)
176 : 0 : fep->flag_csum |= RX_FLAG_CSUM_EN;
177 : :
178 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
179 : 0 : ENETFEC_PMD_ERR("PMD does not support KEEP_CRC offload");
180 : :
181 : 0 : return 0;
182 : : }
183 : :
184 : : static int
185 : 0 : enetfec_eth_start(struct rte_eth_dev *dev)
186 : : {
187 : 0 : enetfec_restart(dev);
188 : 0 : dev->rx_pkt_burst = &enetfec_recv_pkts;
189 : 0 : dev->tx_pkt_burst = &enetfec_xmit_pkts;
190 : :
191 : 0 : return 0;
192 : : }
193 : :
194 : : /* ENETFEC disable function.
195 : : * @param[in] base ENETFEC base address
196 : : */
197 : : static void
198 : : enetfec_disable(struct enetfec_private *fep)
199 : : {
200 : 0 : rte_write32(rte_read32((uint8_t *)fep->hw_baseaddr_v + ENETFEC_ECR)
201 : 0 : & ~(fep->enetfec_e_cntl),
202 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_ECR);
203 : : }
204 : :
205 : : static int
206 : 0 : enetfec_eth_stop(struct rte_eth_dev *dev)
207 : : {
208 : 0 : struct enetfec_private *fep = dev->data->dev_private;
209 : :
210 : 0 : dev->data->dev_started = 0;
211 : : enetfec_disable(fep);
212 : :
213 : 0 : return 0;
214 : : }
215 : :
216 : : static int
217 : 0 : enetfec_eth_close(struct rte_eth_dev *dev)
218 : : {
219 : 0 : enet_free_buffers(dev);
220 : 0 : return 0;
221 : : }
222 : :
223 : : static int
224 : 0 : enetfec_eth_link_update(struct rte_eth_dev *dev,
225 : : int wait_to_complete __rte_unused)
226 : : {
227 : : struct rte_eth_link link;
228 : : unsigned int lstatus = 1;
229 : :
230 : : memset(&link, 0, sizeof(struct rte_eth_link));
231 : :
232 : 0 : link.link_status = lstatus;
233 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_1G;
234 : :
235 : 0 : ENETFEC_PMD_INFO("Port (%d) link is %s", dev->data->port_id,
236 : : "Up");
237 : :
238 : 0 : return rte_eth_linkstatus_set(dev, &link);
239 : : }
240 : :
241 : : static int
242 : 0 : enetfec_promiscuous_enable(struct rte_eth_dev *dev)
243 : : {
244 : 0 : struct enetfec_private *fep = dev->data->dev_private;
245 : : uint32_t tmp;
246 : :
247 : 0 : tmp = rte_read32((uint8_t *)fep->hw_baseaddr_v + ENETFEC_RCR);
248 : : tmp |= 0x8;
249 : 0 : tmp &= ~0x2;
250 : : rte_write32(rte_cpu_to_le_32(tmp),
251 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_RCR);
252 : :
253 : 0 : return 0;
254 : : }
255 : :
256 : : static int
257 : 0 : enetfec_multicast_enable(struct rte_eth_dev *dev)
258 : : {
259 : 0 : struct enetfec_private *fep = dev->data->dev_private;
260 : :
261 : : rte_write32(rte_cpu_to_le_32(0xffffffff),
262 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_GAUR);
263 : : rte_write32(rte_cpu_to_le_32(0xffffffff),
264 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_GALR);
265 : 0 : dev->data->all_multicast = 1;
266 : :
267 : : rte_write32(rte_cpu_to_le_32(0x04400002),
268 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_GAUR);
269 : : rte_write32(rte_cpu_to_le_32(0x10800049),
270 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_GALR);
271 : :
272 : 0 : return 0;
273 : : }
274 : :
275 : : /* Set a MAC change in hardware. */
276 : : static int
277 : 0 : enetfec_set_mac_address(struct rte_eth_dev *dev, struct rte_ether_addr *addr)
278 : : {
279 : 0 : struct enetfec_private *fep = dev->data->dev_private;
280 : :
281 : 0 : writel(addr->addr_bytes[3] | (addr->addr_bytes[2] << 8) |
282 : : (addr->addr_bytes[1] << 16) | (addr->addr_bytes[0] << 24),
283 : : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_PALR);
284 : 0 : writel((addr->addr_bytes[5] << 16) | (addr->addr_bytes[4] << 24),
285 : : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_PAUR);
286 : :
287 : 0 : rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);
288 : :
289 : 0 : return 0;
290 : : }
291 : :
292 : : static int
293 : 0 : enetfec_stats_get(struct rte_eth_dev *dev,
294 : : struct rte_eth_stats *stats,
295 : : struct eth_queue_stats *qstats __rte_unused)
296 : : {
297 : 0 : struct enetfec_private *fep = dev->data->dev_private;
298 : : struct rte_eth_stats *eth_stats = &fep->stats;
299 : :
300 : 0 : stats->ipackets = eth_stats->ipackets;
301 : 0 : stats->ibytes = eth_stats->ibytes;
302 : 0 : stats->ierrors = eth_stats->ierrors;
303 : 0 : stats->opackets = eth_stats->opackets;
304 : 0 : stats->obytes = eth_stats->obytes;
305 : 0 : stats->oerrors = eth_stats->oerrors;
306 : 0 : stats->rx_nombuf = eth_stats->rx_nombuf;
307 : :
308 : 0 : return 0;
309 : : }
310 : :
311 : : static int
312 : 0 : enetfec_eth_info(__rte_unused struct rte_eth_dev *dev,
313 : : struct rte_eth_dev_info *dev_info)
314 : : {
315 : 0 : dev_info->max_rx_pktlen = ENETFEC_MAX_RX_PKT_LEN;
316 : 0 : dev_info->max_rx_queues = ENETFEC_MAX_Q;
317 : 0 : dev_info->max_tx_queues = ENETFEC_MAX_Q;
318 : 0 : dev_info->rx_offload_capa = dev_rx_offloads_sup;
319 : 0 : return 0;
320 : : }
321 : :
322 : : static void
323 : 0 : enet_free_queue(struct rte_eth_dev *dev)
324 : : {
325 : 0 : struct enetfec_private *fep = dev->data->dev_private;
326 : : unsigned int i;
327 : :
328 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
329 : 0 : rte_free(fep->rx_queues[i]);
330 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
331 : 0 : rte_free(fep->tx_queues[i]);
332 : 0 : }
333 : :
334 : : static const unsigned short offset_des_active_rxq[] = {
335 : : ENETFEC_RDAR_0, ENETFEC_RDAR_1, ENETFEC_RDAR_2
336 : : };
337 : :
338 : : static const unsigned short offset_des_active_txq[] = {
339 : : ENETFEC_TDAR_0, ENETFEC_TDAR_1, ENETFEC_TDAR_2
340 : : };
341 : :
342 : : static int
343 : 0 : enetfec_tx_queue_setup(struct rte_eth_dev *dev,
344 : : uint16_t queue_idx,
345 : : uint16_t nb_desc,
346 : : unsigned int socket_id __rte_unused,
347 : : const struct rte_eth_txconf *tx_conf __rte_unused)
348 : : {
349 : 0 : struct enetfec_private *fep = dev->data->dev_private;
350 : : unsigned int i;
351 : : struct bufdesc *bdp, *bd_base;
352 : : struct enetfec_priv_tx_q *txq;
353 : : unsigned int size;
354 [ # # ]: 0 : unsigned int dsize = fep->bufdesc_ex ? sizeof(struct bufdesc_ex) :
355 : : sizeof(struct bufdesc);
356 [ # # ]: 0 : unsigned int dsize_log2 = rte_fls_u64(dsize) - 1;
357 : :
358 [ # # ]: 0 : if (queue_idx > 0) {
359 : 0 : ENETFEC_PMD_ERR("Multi queue not supported");
360 : 0 : return -EINVAL;
361 : : }
362 : :
363 : : /* Tx deferred start is not supported */
364 [ # # ]: 0 : if (tx_conf->tx_deferred_start) {
365 : 0 : ENETFEC_PMD_ERR("Tx deferred start not supported");
366 : 0 : return -EINVAL;
367 : : }
368 : :
369 : : /* allocate transmit queue */
370 : 0 : txq = rte_zmalloc(NULL, sizeof(*txq), RTE_CACHE_LINE_SIZE);
371 [ # # ]: 0 : if (txq == NULL) {
372 : 0 : ENETFEC_PMD_ERR("transmit queue allocation failed");
373 : 0 : return -ENOMEM;
374 : : }
375 : :
376 [ # # ]: 0 : if (nb_desc != MAX_TX_BD_RING_SIZE) {
377 : : nb_desc = MAX_TX_BD_RING_SIZE;
378 : 0 : ENETFEC_PMD_WARN("modified the nb_desc to MAX_TX_BD_RING_SIZE");
379 : : }
380 : 0 : txq->bd.ring_size = nb_desc;
381 : 0 : fep->total_tx_ring_size += txq->bd.ring_size;
382 : 0 : fep->tx_queues[queue_idx] = txq;
383 : :
384 : 0 : rte_write32(rte_cpu_to_le_32(fep->bd_addr_p_t[queue_idx]),
385 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_TD_START(queue_idx));
386 : :
387 : : /* Set transmit descriptor base. */
388 : 0 : txq = fep->tx_queues[queue_idx];
389 : 0 : txq->fep = fep;
390 : 0 : size = dsize * txq->bd.ring_size;
391 : 0 : bd_base = (struct bufdesc *)fep->dma_baseaddr_t[queue_idx];
392 : 0 : txq->bd.queue_id = queue_idx;
393 : 0 : txq->bd.base = bd_base;
394 : 0 : txq->bd.cur = bd_base;
395 : 0 : txq->bd.d_size = dsize;
396 : 0 : txq->bd.d_size_log2 = dsize_log2;
397 : 0 : txq->bd.active_reg_desc = (uint8_t *)fep->hw_baseaddr_v +
398 : 0 : offset_des_active_txq[queue_idx];
399 : 0 : bd_base = (struct bufdesc *)(((uintptr_t)bd_base) + size);
400 : 0 : txq->bd.last = (struct bufdesc *)(((uintptr_t)bd_base) - dsize);
401 : : bdp = txq->bd.cur;
402 : :
403 [ # # ]: 0 : for (i = 0; i < txq->bd.ring_size; i++) {
404 : : /* Initialize the BD for every fragment in the page. */
405 : : rte_write16(rte_cpu_to_le_16(0), &bdp->bd_sc);
406 [ # # ]: 0 : if (txq->tx_mbuf[i] != NULL) {
407 : 0 : rte_pktmbuf_free(txq->tx_mbuf[i]);
408 : 0 : txq->tx_mbuf[i] = NULL;
409 : : }
410 : : rte_write32(0, &bdp->bd_bufaddr);
411 : : bdp = enet_get_nextdesc(bdp, &txq->bd);
412 : : }
413 : :
414 : : /* Set the last buffer to wrap */
415 : : bdp = enet_get_prevdesc(bdp, &txq->bd);
416 : 0 : rte_write16((rte_cpu_to_le_16(TX_BD_WRAP) |
417 : : rte_read16(&bdp->bd_sc)), &bdp->bd_sc);
418 : 0 : txq->dirty_tx = bdp;
419 : 0 : dev->data->tx_queues[queue_idx] = fep->tx_queues[queue_idx];
420 : 0 : return 0;
421 : : }
422 : :
423 : : static int
424 : 0 : enetfec_rx_queue_setup(struct rte_eth_dev *dev,
425 : : uint16_t queue_idx,
426 : : uint16_t nb_rx_desc,
427 : : unsigned int socket_id __rte_unused,
428 : : const struct rte_eth_rxconf *rx_conf __rte_unused,
429 : : struct rte_mempool *mb_pool)
430 : : {
431 : 0 : struct enetfec_private *fep = dev->data->dev_private;
432 : : unsigned int i;
433 : : struct bufdesc *bd_base;
434 : : struct bufdesc *bdp;
435 : : struct enetfec_priv_rx_q *rxq;
436 : : unsigned int size;
437 [ # # ]: 0 : unsigned int dsize = fep->bufdesc_ex ? sizeof(struct bufdesc_ex) :
438 : : sizeof(struct bufdesc);
439 [ # # ]: 0 : unsigned int dsize_log2 = rte_fls_u64(dsize) - 1;
440 : :
441 [ # # ]: 0 : if (queue_idx >= ENETFEC_MAX_Q) {
442 : 0 : ENETFEC_PMD_ERR("Invalid queue id %" PRIu16 ", max %d",
443 : : queue_idx, ENETFEC_MAX_Q);
444 : 0 : return -EINVAL;
445 : : }
446 : :
447 : : /* allocate receive queue */
448 : 0 : rxq = rte_zmalloc(NULL, sizeof(*rxq), RTE_CACHE_LINE_SIZE);
449 [ # # ]: 0 : if (rxq == NULL) {
450 : 0 : ENETFEC_PMD_ERR("receive queue allocation failed");
451 : 0 : return -ENOMEM;
452 : : }
453 : :
454 [ # # ]: 0 : if (nb_rx_desc != MAX_RX_BD_RING_SIZE) {
455 : : nb_rx_desc = MAX_RX_BD_RING_SIZE;
456 : 0 : ENETFEC_PMD_WARN("modified the nb_desc to MAX_RX_BD_RING_SIZE");
457 : : }
458 : :
459 : 0 : rxq->bd.ring_size = nb_rx_desc;
460 : 0 : fep->total_rx_ring_size += rxq->bd.ring_size;
461 : 0 : fep->rx_queues[queue_idx] = rxq;
462 : :
463 : 0 : rte_write32(rte_cpu_to_le_32(fep->bd_addr_p_r[queue_idx]),
464 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_RD_START(queue_idx));
465 : 0 : rte_write32(rte_cpu_to_le_32(PKT_MAX_BUF_SIZE),
466 : 0 : (uint8_t *)fep->hw_baseaddr_v + ENETFEC_MRB_SIZE(queue_idx));
467 : :
468 : : /* Set receive descriptor base. */
469 : 0 : rxq = fep->rx_queues[queue_idx];
470 : 0 : rxq->pool = mb_pool;
471 : 0 : size = dsize * rxq->bd.ring_size;
472 : 0 : bd_base = (struct bufdesc *)fep->dma_baseaddr_r[queue_idx];
473 : 0 : rxq->bd.queue_id = queue_idx;
474 : 0 : rxq->bd.base = bd_base;
475 : 0 : rxq->bd.cur = bd_base;
476 : 0 : rxq->bd.d_size = dsize;
477 : 0 : rxq->bd.d_size_log2 = dsize_log2;
478 : 0 : rxq->bd.active_reg_desc = (uint8_t *)fep->hw_baseaddr_v +
479 : 0 : offset_des_active_rxq[queue_idx];
480 : 0 : bd_base = (struct bufdesc *)(((uintptr_t)bd_base) + size);
481 : 0 : rxq->bd.last = (struct bufdesc *)(((uintptr_t)bd_base) - dsize);
482 : :
483 : 0 : rxq->fep = fep;
484 : : bdp = rxq->bd.base;
485 : : rxq->bd.cur = bdp;
486 : :
487 [ # # ]: 0 : for (i = 0; i < nb_rx_desc; i++) {
488 : : /* Initialize Rx buffers from pktmbuf pool */
489 : 0 : struct rte_mbuf *mbuf = rte_pktmbuf_alloc(mb_pool);
490 [ # # ]: 0 : if (mbuf == NULL) {
491 : 0 : ENETFEC_PMD_ERR("mbuf failed");
492 : 0 : goto err_alloc;
493 : : }
494 : :
495 : : /* Get the virtual address & physical address */
496 : 0 : rte_write32(rte_cpu_to_le_32(rte_pktmbuf_iova(mbuf)),
497 : : &bdp->bd_bufaddr);
498 : :
499 : 0 : rxq->rx_mbuf[i] = mbuf;
500 : : rte_write16(rte_cpu_to_le_16(RX_BD_EMPTY), &bdp->bd_sc);
501 : :
502 : : bdp = enet_get_nextdesc(bdp, &rxq->bd);
503 : : }
504 : :
505 : : /* Initialize the receive buffer descriptors. */
506 : 0 : bdp = rxq->bd.cur;
507 [ # # ]: 0 : for (i = 0; i < rxq->bd.ring_size; i++) {
508 : : /* Initialize the BD for every fragment in the page. */
509 [ # # ]: 0 : if (rte_read32(&bdp->bd_bufaddr) > 0)
510 : : rte_write16(rte_cpu_to_le_16(RX_BD_EMPTY),
511 : : &bdp->bd_sc);
512 : : else
513 : : rte_write16(rte_cpu_to_le_16(0), &bdp->bd_sc);
514 : :
515 : : bdp = enet_get_nextdesc(bdp, &rxq->bd);
516 : : }
517 : :
518 : : /* Set the last buffer to wrap */
519 : : bdp = enet_get_prevdesc(bdp, &rxq->bd);
520 : 0 : rte_write16((rte_cpu_to_le_16(RX_BD_WRAP) |
521 : : rte_read16(&bdp->bd_sc)), &bdp->bd_sc);
522 : 0 : dev->data->rx_queues[queue_idx] = fep->rx_queues[queue_idx];
523 : 0 : rte_write32(0, fep->rx_queues[queue_idx]->bd.active_reg_desc);
524 : 0 : return 0;
525 : :
526 : : err_alloc:
527 [ # # ]: 0 : for (i = 0; i < nb_rx_desc; i++) {
528 [ # # ]: 0 : if (rxq->rx_mbuf[i] != NULL) {
529 : 0 : rte_pktmbuf_free(rxq->rx_mbuf[i]);
530 : 0 : rxq->rx_mbuf[i] = NULL;
531 : : }
532 : : }
533 : 0 : rte_free(rxq);
534 : 0 : return -ENOMEM;
535 : : }
536 : :
537 : : static const struct eth_dev_ops enetfec_ops = {
538 : : .dev_configure = enetfec_eth_configure,
539 : : .dev_start = enetfec_eth_start,
540 : : .dev_stop = enetfec_eth_stop,
541 : : .dev_close = enetfec_eth_close,
542 : : .link_update = enetfec_eth_link_update,
543 : : .promiscuous_enable = enetfec_promiscuous_enable,
544 : : .allmulticast_enable = enetfec_multicast_enable,
545 : : .mac_addr_set = enetfec_set_mac_address,
546 : : .stats_get = enetfec_stats_get,
547 : : .dev_infos_get = enetfec_eth_info,
548 : : .rx_queue_setup = enetfec_rx_queue_setup,
549 : : .tx_queue_setup = enetfec_tx_queue_setup
550 : : };
551 : :
552 : : static int
553 : : enetfec_eth_init(struct rte_eth_dev *dev)
554 : : {
555 : 0 : struct enetfec_private *fep = dev->data->dev_private;
556 : :
557 : 0 : fep->full_duplex = FULL_DUPLEX;
558 : 0 : dev->dev_ops = &enetfec_ops;
559 : 0 : rte_eth_dev_probing_finish(dev);
560 : :
561 : : return 0;
562 : : }
563 : :
564 : : static int
565 [ # # ]: 0 : pmd_enetfec_probe(struct rte_vdev_device *vdev)
566 : : {
567 : : char eth_name[ENETFEC_ETH_NAMESIZE];
568 : : struct rte_eth_dev *dev = NULL;
569 : : struct enetfec_private *fep;
570 : : uint16_t *mac, high_mac = 0;
571 : : struct rte_ether_addr addr;
572 : : uint32_t tmac, low_mac = 0;
573 : : unsigned int bdsize;
574 : : const char *name;
575 : : int rc, i;
576 : :
577 : : name = rte_vdev_device_name(vdev);
578 : 0 : ENETFEC_PMD_LOG(INFO, "Initializing pmd_fec for %s", name);
579 : :
580 : 0 : dev = rte_eth_vdev_allocate(vdev, sizeof(*fep));
581 [ # # ]: 0 : if (dev == NULL)
582 : : return -ENOMEM;
583 : :
584 : : /* setup board info structure */
585 : 0 : fep = dev->data->dev_private;
586 : 0 : fep->dev = dev;
587 : :
588 : 0 : fep->max_rx_queues = ENETFEC_MAX_Q;
589 : 0 : fep->max_tx_queues = ENETFEC_MAX_Q;
590 : 0 : fep->quirks = QUIRK_HAS_ENETFEC_MAC | QUIRK_GBIT
591 : : | QUIRK_RACC;
592 : :
593 : 0 : rc = enetfec_configure();
594 [ # # ]: 0 : if (rc != 0)
595 : : return -ENOMEM;
596 : 0 : rc = config_enetfec_uio(fep);
597 [ # # ]: 0 : if (rc != 0)
598 : : return -ENOMEM;
599 : :
600 : : /* Get the BD size for distributing among six queues */
601 : 0 : bdsize = (fep->bd_size) / NUM_OF_BD_QUEUES;
602 : :
603 [ # # ]: 0 : for (i = 0; i < fep->max_tx_queues; i++) {
604 : 0 : fep->dma_baseaddr_t[i] = fep->bd_addr_v;
605 : 0 : fep->bd_addr_p_t[i] = fep->bd_addr_p;
606 : 0 : fep->bd_addr_v = (uint8_t *)fep->bd_addr_v + bdsize;
607 : 0 : fep->bd_addr_p = fep->bd_addr_p + bdsize;
608 : : }
609 [ # # ]: 0 : for (i = 0; i < fep->max_rx_queues; i++) {
610 : 0 : fep->dma_baseaddr_r[i] = fep->bd_addr_v;
611 : 0 : fep->bd_addr_p_r[i] = fep->bd_addr_p;
612 : 0 : fep->bd_addr_v = (uint8_t *)fep->bd_addr_v + bdsize;
613 : 0 : fep->bd_addr_p = fep->bd_addr_p + bdsize;
614 : : }
615 : :
616 : : /* Allocate memory for storing MAC addresses */
617 : 0 : snprintf(eth_name, sizeof(eth_name), "enetfec_eth_mac_%d",
618 : 0 : dev->data->port_id);
619 : :
620 : : /* Copy the station address into the dev structure, */
621 : 0 : dev->data->mac_addrs = rte_zmalloc(eth_name, RTE_ETHER_ADDR_LEN, 0);
622 [ # # ]: 0 : if (dev->data->mac_addrs == NULL) {
623 : 0 : ENETFEC_PMD_ERR("Failed to allocate mem %d to store MAC addresses",
624 : : RTE_ETHER_ADDR_LEN);
625 : : rc = -ENOMEM;
626 : 0 : goto err;
627 : : }
628 : :
629 : : /* Set mac address */
630 : : mac = (uint16_t *)addr.addr_bytes;
631 : 0 : low_mac = (uint32_t)rte_read32((uint8_t *)fep->hw_baseaddr_v + ENETFEC_PALR);
632 : 0 : *mac = (uint16_t)low_mac;
633 : : mac++;
634 : 0 : *mac = (uint16_t)(low_mac >> ENETFEC_MAC_SHIFT);
635 : : mac++;
636 : 0 : tmac = (uint32_t)rte_read32((uint8_t *)fep->hw_baseaddr_v + ENETFEC_PAUR);
637 : 0 : *mac = (uint16_t)(tmac >> ENETFEC_MAC_SHIFT);
638 : : high_mac = (uint16_t)(*mac);
639 : :
640 [ # # ]: 0 : if ((high_mac | low_mac) == 0 || (high_mac | low_mac) == ENETFEC_MAC_RESET) {
641 : : uint8_t *first_byte;
642 : :
643 : : mac = (uint16_t *)addr.addr_bytes;
644 : 0 : tmac = (uint32_t)rte_rand();
645 : : first_byte = (uint8_t *)&tmac;
646 : 0 : *first_byte &= (uint8_t)~RTE_ETHER_GROUP_ADDR; /* clear multicast bit */
647 : 0 : *first_byte |= RTE_ETHER_LOCAL_ADMIN_ADDR; /* set local assignment bit (IEEE802) */
648 : 0 : *mac = (uint16_t)tmac;
649 : : mac++;
650 : 0 : *mac = (uint16_t)(tmac >> ENETFEC_MAC_SHIFT);
651 : : mac++;
652 : 0 : *mac = (uint16_t)rte_rand();
653 : : }
654 : :
655 : 0 : enetfec_set_mac_address(dev, &addr);
656 : :
657 : 0 : fep->bufdesc_ex = ENETFEC_EXTENDED_BD;
658 : : rc = enetfec_eth_init(dev);
659 : : if (rc)
660 : : goto failed_init;
661 : :
662 : 0 : return 0;
663 : :
664 : : failed_init:
665 : : ENETFEC_PMD_ERR("Failed to init");
666 : : err:
667 : 0 : rte_eth_dev_release_port(dev);
668 : 0 : return rc;
669 : : }
670 : :
671 : : static int
672 [ # # ]: 0 : pmd_enetfec_remove(struct rte_vdev_device *vdev)
673 : : {
674 : : struct rte_eth_dev *eth_dev = NULL;
675 : : struct enetfec_private *fep;
676 : : struct enetfec_priv_rx_q *rxq;
677 : : int ret;
678 : :
679 : : /* find the ethdev entry */
680 : 0 : eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(vdev));
681 [ # # ]: 0 : if (eth_dev == NULL)
682 : : return -ENODEV;
683 : :
684 : 0 : fep = eth_dev->data->dev_private;
685 : : /* Free descriptor base of first RX queue as it was configured
686 : : * first in enetfec_eth_init().
687 : : */
688 : 0 : rxq = fep->rx_queues[0];
689 : 0 : rte_free(rxq->bd.base);
690 : 0 : enet_free_queue(eth_dev);
691 : : enetfec_eth_stop(eth_dev);
692 : :
693 : 0 : ret = rte_eth_dev_release_port(eth_dev);
694 [ # # ]: 0 : if (ret != 0)
695 : : return -EINVAL;
696 : :
697 : 0 : ENETFEC_PMD_INFO("Release enetfec sw device");
698 : 0 : enetfec_cleanup(fep);
699 : :
700 : 0 : return 0;
701 : : }
702 : :
703 : : static struct rte_vdev_driver pmd_enetfec_drv = {
704 : : .probe = pmd_enetfec_probe,
705 : : .remove = pmd_enetfec_remove,
706 : : };
707 : :
708 : 253 : RTE_PMD_REGISTER_VDEV(ENETFEC_NAME_PMD, pmd_enetfec_drv);
709 [ - + ]: 253 : RTE_LOG_REGISTER_DEFAULT(enetfec_logtype_pmd, NOTICE);
|