1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015 - 2016 CESNET
18 #include <rte_ethdev_driver.h>
19 #include <rte_ethdev_pci.h>
20 #include <rte_malloc.h>
21 #include <rte_memcpy.h>
22 #include <rte_kvargs.h>
25 #include "rte_eth_szedata2.h"
26 #include "szedata2_logs.h"
28 #define RTE_ETH_SZEDATA2_MAX_RX_QUEUES 32
29 #define RTE_ETH_SZEDATA2_MAX_TX_QUEUES 32
30 #define RTE_ETH_SZEDATA2_TX_LOCK_SIZE (32 * 1024 * 1024)
33 * size of szedata2_packet header with alignment
35 #define RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED 8
37 #define RTE_SZEDATA2_DRIVER_NAME net_szedata2
39 #define SZEDATA2_DEV_PATH_FMT "/dev/szedataII%u"
42 * Format string for suffix used to differentiate between Ethernet ports
43 * on the same PCI device.
45 #define SZEDATA2_ETH_DEV_NAME_SUFFIX_FMT "-port%u"
48 * Maximum number of ports for one device.
50 #define SZEDATA2_MAX_PORTS 2
53 * Entry in list of PCI devices for this driver.
55 struct pci_dev_list_entry;
56 struct pci_dev_list_entry {
57 LIST_ENTRY(pci_dev_list_entry) next;
58 struct rte_pci_device *pci_dev;
59 unsigned int port_count;
62 /* List of PCI devices with number of ports for this driver. */
63 LIST_HEAD(pci_dev_list, pci_dev_list_entry) szedata2_pci_dev_list =
64 LIST_HEAD_INITIALIZER(szedata2_pci_dev_list);
67 unsigned int rx_base_id;
68 unsigned int tx_base_id;
69 unsigned int rx_count;
70 unsigned int tx_count;
74 struct pmd_internals {
75 struct rte_eth_dev *dev;
76 uint16_t max_rx_queues;
77 uint16_t max_tx_queues;
78 unsigned int rxq_base_id;
79 unsigned int txq_base_id;
83 struct szedata2_rx_queue {
84 struct pmd_internals *priv;
89 struct rte_mempool *mb_pool;
90 volatile uint64_t rx_pkts;
91 volatile uint64_t rx_bytes;
92 volatile uint64_t err_pkts;
95 struct szedata2_tx_queue {
96 struct pmd_internals *priv;
100 volatile uint64_t tx_pkts;
101 volatile uint64_t tx_bytes;
102 volatile uint64_t err_pkts;
105 int szedata2_logtype_init;
106 int szedata2_logtype_driver;
108 static struct rte_ether_addr eth_addr = {
109 .addr_bytes = { 0x00, 0x11, 0x17, 0x00, 0x00, 0x00 }
113 eth_szedata2_rx(void *queue,
114 struct rte_mbuf **bufs,
118 struct rte_mbuf *mbuf;
119 struct szedata2_rx_queue *sze_q = queue;
120 struct rte_pktmbuf_pool_private *mbp_priv;
125 uint16_t packet_size;
126 uint64_t num_bytes = 0;
127 struct szedata *sze = sze_q->sze;
128 uint8_t *header_ptr = NULL; /* header of packet */
129 uint8_t *packet_ptr1 = NULL;
130 uint8_t *packet_ptr2 = NULL;
131 uint16_t packet_len1 = 0;
132 uint16_t packet_len2 = 0;
133 uint16_t hw_data_align;
135 if (unlikely(sze_q->sze == NULL || nb_pkts == 0))
139 * Reads the given number of packets from szedata2 channel given
140 * by queue and copies the packet data into a newly allocated mbuf
143 for (i = 0; i < nb_pkts; i++) {
144 mbuf = rte_pktmbuf_alloc(sze_q->mb_pool);
146 if (unlikely(mbuf == NULL)) {
147 sze_q->priv->dev->data->rx_mbuf_alloc_failed++;
151 /* get the next sze packet */
152 if (sze->ct_rx_lck != NULL && !sze->ct_rx_rem_bytes &&
153 sze->ct_rx_lck->next == NULL) {
154 /* unlock old data */
155 szedata_rx_unlock_data(sze_q->sze, sze->ct_rx_lck_orig);
156 sze->ct_rx_lck_orig = NULL;
157 sze->ct_rx_lck = NULL;
160 if (!sze->ct_rx_rem_bytes && sze->ct_rx_lck_orig == NULL) {
161 /* nothing to read, lock new data */
162 sze->ct_rx_lck = szedata_rx_lock_data(sze_q->sze, ~0U);
163 sze->ct_rx_lck_orig = sze->ct_rx_lck;
165 if (sze->ct_rx_lck == NULL) {
166 /* nothing to lock */
167 rte_pktmbuf_free(mbuf);
171 sze->ct_rx_cur_ptr = sze->ct_rx_lck->start;
172 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len;
174 if (!sze->ct_rx_rem_bytes) {
175 rte_pktmbuf_free(mbuf);
180 if (sze->ct_rx_rem_bytes < RTE_SZE2_PACKET_HEADER_SIZE) {
183 * copy parts of header to merge buffer
185 if (sze->ct_rx_lck->next == NULL) {
186 rte_pktmbuf_free(mbuf);
190 /* copy first part of header */
191 rte_memcpy(sze->ct_rx_buffer, sze->ct_rx_cur_ptr,
192 sze->ct_rx_rem_bytes);
194 /* copy second part of header */
195 sze->ct_rx_lck = sze->ct_rx_lck->next;
196 sze->ct_rx_cur_ptr = sze->ct_rx_lck->start;
197 rte_memcpy(sze->ct_rx_buffer + sze->ct_rx_rem_bytes,
199 RTE_SZE2_PACKET_HEADER_SIZE -
200 sze->ct_rx_rem_bytes);
202 sze->ct_rx_cur_ptr += RTE_SZE2_PACKET_HEADER_SIZE -
203 sze->ct_rx_rem_bytes;
204 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len -
205 RTE_SZE2_PACKET_HEADER_SIZE +
206 sze->ct_rx_rem_bytes;
208 header_ptr = (uint8_t *)sze->ct_rx_buffer;
211 header_ptr = (uint8_t *)sze->ct_rx_cur_ptr;
212 sze->ct_rx_cur_ptr += RTE_SZE2_PACKET_HEADER_SIZE;
213 sze->ct_rx_rem_bytes -= RTE_SZE2_PACKET_HEADER_SIZE;
216 sg_size = le16toh(*((uint16_t *)header_ptr));
217 hw_size = le16toh(*(((uint16_t *)header_ptr) + 1));
218 packet_size = sg_size -
219 RTE_SZE2_ALIGN8(RTE_SZE2_PACKET_HEADER_SIZE + hw_size);
222 /* checks if packet all right */
224 errx(5, "Zero segsize");
226 /* check sg_size and hwsize */
227 if (hw_size > sg_size - RTE_SZE2_PACKET_HEADER_SIZE) {
228 errx(10, "Hwsize bigger than expected. Segsize: %d, "
229 "hwsize: %d", sg_size, hw_size);
233 RTE_SZE2_ALIGN8(RTE_SZE2_PACKET_HEADER_SIZE + hw_size) -
234 RTE_SZE2_PACKET_HEADER_SIZE;
236 if (sze->ct_rx_rem_bytes >=
238 RTE_SZE2_PACKET_HEADER_SIZE)) {
240 /* one packet ready - go to another */
241 packet_ptr1 = sze->ct_rx_cur_ptr + hw_data_align;
242 packet_len1 = packet_size;
246 sze->ct_rx_cur_ptr += RTE_SZE2_ALIGN8(sg_size) -
247 RTE_SZE2_PACKET_HEADER_SIZE;
248 sze->ct_rx_rem_bytes -= RTE_SZE2_ALIGN8(sg_size) -
249 RTE_SZE2_PACKET_HEADER_SIZE;
252 if (sze->ct_rx_lck->next == NULL) {
253 errx(6, "Need \"next\" lock, "
254 "but it is missing: %u",
255 sze->ct_rx_rem_bytes);
259 if (sze->ct_rx_rem_bytes <= hw_data_align) {
260 uint16_t rem_size = hw_data_align -
261 sze->ct_rx_rem_bytes;
263 /* MOVE to next lock */
264 sze->ct_rx_lck = sze->ct_rx_lck->next;
266 (void *)(((uint8_t *)
267 (sze->ct_rx_lck->start)) + rem_size);
269 packet_ptr1 = sze->ct_rx_cur_ptr;
270 packet_len1 = packet_size;
274 sze->ct_rx_cur_ptr +=
275 RTE_SZE2_ALIGN8(packet_size);
276 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len -
277 rem_size - RTE_SZE2_ALIGN8(packet_size);
279 /* get pointer and length from first part */
280 packet_ptr1 = sze->ct_rx_cur_ptr +
282 packet_len1 = sze->ct_rx_rem_bytes -
285 /* MOVE to next lock */
286 sze->ct_rx_lck = sze->ct_rx_lck->next;
287 sze->ct_rx_cur_ptr = sze->ct_rx_lck->start;
289 /* get pointer and length from second part */
290 packet_ptr2 = sze->ct_rx_cur_ptr;
291 packet_len2 = packet_size - packet_len1;
293 sze->ct_rx_cur_ptr +=
294 RTE_SZE2_ALIGN8(packet_size) -
296 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len -
297 (RTE_SZE2_ALIGN8(packet_size) -
302 if (unlikely(packet_ptr1 == NULL)) {
303 rte_pktmbuf_free(mbuf);
307 /* get the space available for data in the mbuf */
308 mbp_priv = rte_mempool_get_priv(sze_q->mb_pool);
309 buf_size = (uint16_t)(mbp_priv->mbuf_data_room_size -
310 RTE_PKTMBUF_HEADROOM);
312 if (packet_size <= buf_size) {
313 /* sze packet will fit in one mbuf, go ahead and copy */
314 rte_memcpy(rte_pktmbuf_mtod(mbuf, void *),
315 packet_ptr1, packet_len1);
316 if (packet_ptr2 != NULL) {
317 rte_memcpy((void *)(rte_pktmbuf_mtod(mbuf,
318 uint8_t *) + packet_len1),
319 packet_ptr2, packet_len2);
321 mbuf->data_len = (uint16_t)packet_size;
323 mbuf->pkt_len = packet_size;
324 mbuf->port = sze_q->in_port;
327 num_bytes += packet_size;
330 * sze packet will not fit in one mbuf,
331 * scattered mode is not enabled, drop packet
334 "SZE segment %d bytes will not fit in one mbuf "
335 "(%d bytes), scattered mode is not enabled, "
337 packet_size, buf_size);
338 rte_pktmbuf_free(mbuf);
342 sze_q->rx_pkts += num_rx;
343 sze_q->rx_bytes += num_bytes;
348 eth_szedata2_rx_scattered(void *queue,
349 struct rte_mbuf **bufs,
353 struct rte_mbuf *mbuf;
354 struct szedata2_rx_queue *sze_q = queue;
355 struct rte_pktmbuf_pool_private *mbp_priv;
360 uint16_t packet_size;
361 uint64_t num_bytes = 0;
362 struct szedata *sze = sze_q->sze;
363 uint8_t *header_ptr = NULL; /* header of packet */
364 uint8_t *packet_ptr1 = NULL;
365 uint8_t *packet_ptr2 = NULL;
366 uint16_t packet_len1 = 0;
367 uint16_t packet_len2 = 0;
368 uint16_t hw_data_align;
369 uint64_t *mbuf_failed_ptr =
370 &sze_q->priv->dev->data->rx_mbuf_alloc_failed;
372 if (unlikely(sze_q->sze == NULL || nb_pkts == 0))
376 * Reads the given number of packets from szedata2 channel given
377 * by queue and copies the packet data into a newly allocated mbuf
380 for (i = 0; i < nb_pkts; i++) {
381 const struct szedata_lock *ct_rx_lck_backup;
382 unsigned int ct_rx_rem_bytes_backup;
383 unsigned char *ct_rx_cur_ptr_backup;
385 /* get the next sze packet */
386 if (sze->ct_rx_lck != NULL && !sze->ct_rx_rem_bytes &&
387 sze->ct_rx_lck->next == NULL) {
388 /* unlock old data */
389 szedata_rx_unlock_data(sze_q->sze, sze->ct_rx_lck_orig);
390 sze->ct_rx_lck_orig = NULL;
391 sze->ct_rx_lck = NULL;
395 * Store items from sze structure which can be changed
396 * before mbuf allocating. Use these items in case of mbuf
397 * allocating failure.
399 ct_rx_lck_backup = sze->ct_rx_lck;
400 ct_rx_rem_bytes_backup = sze->ct_rx_rem_bytes;
401 ct_rx_cur_ptr_backup = sze->ct_rx_cur_ptr;
403 if (!sze->ct_rx_rem_bytes && sze->ct_rx_lck_orig == NULL) {
404 /* nothing to read, lock new data */
405 sze->ct_rx_lck = szedata_rx_lock_data(sze_q->sze, ~0U);
406 sze->ct_rx_lck_orig = sze->ct_rx_lck;
409 * Backup items from sze structure must be updated
410 * after locking to contain pointers to new locks.
412 ct_rx_lck_backup = sze->ct_rx_lck;
413 ct_rx_rem_bytes_backup = sze->ct_rx_rem_bytes;
414 ct_rx_cur_ptr_backup = sze->ct_rx_cur_ptr;
416 if (sze->ct_rx_lck == NULL)
417 /* nothing to lock */
420 sze->ct_rx_cur_ptr = sze->ct_rx_lck->start;
421 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len;
423 if (!sze->ct_rx_rem_bytes)
427 if (sze->ct_rx_rem_bytes < RTE_SZE2_PACKET_HEADER_SIZE) {
429 * cut in header - copy parts of header to merge buffer
431 if (sze->ct_rx_lck->next == NULL)
434 /* copy first part of header */
435 rte_memcpy(sze->ct_rx_buffer, sze->ct_rx_cur_ptr,
436 sze->ct_rx_rem_bytes);
438 /* copy second part of header */
439 sze->ct_rx_lck = sze->ct_rx_lck->next;
440 sze->ct_rx_cur_ptr = sze->ct_rx_lck->start;
441 rte_memcpy(sze->ct_rx_buffer + sze->ct_rx_rem_bytes,
443 RTE_SZE2_PACKET_HEADER_SIZE -
444 sze->ct_rx_rem_bytes);
446 sze->ct_rx_cur_ptr += RTE_SZE2_PACKET_HEADER_SIZE -
447 sze->ct_rx_rem_bytes;
448 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len -
449 RTE_SZE2_PACKET_HEADER_SIZE +
450 sze->ct_rx_rem_bytes;
452 header_ptr = (uint8_t *)sze->ct_rx_buffer;
455 header_ptr = (uint8_t *)sze->ct_rx_cur_ptr;
456 sze->ct_rx_cur_ptr += RTE_SZE2_PACKET_HEADER_SIZE;
457 sze->ct_rx_rem_bytes -= RTE_SZE2_PACKET_HEADER_SIZE;
460 sg_size = le16toh(*((uint16_t *)header_ptr));
461 hw_size = le16toh(*(((uint16_t *)header_ptr) + 1));
462 packet_size = sg_size -
463 RTE_SZE2_ALIGN8(RTE_SZE2_PACKET_HEADER_SIZE + hw_size);
466 /* checks if packet all right */
468 errx(5, "Zero segsize");
470 /* check sg_size and hwsize */
471 if (hw_size > sg_size - RTE_SZE2_PACKET_HEADER_SIZE) {
472 errx(10, "Hwsize bigger than expected. Segsize: %d, "
473 "hwsize: %d", sg_size, hw_size);
477 RTE_SZE2_ALIGN8((RTE_SZE2_PACKET_HEADER_SIZE +
478 hw_size)) - RTE_SZE2_PACKET_HEADER_SIZE;
480 if (sze->ct_rx_rem_bytes >=
482 RTE_SZE2_PACKET_HEADER_SIZE)) {
484 /* one packet ready - go to another */
485 packet_ptr1 = sze->ct_rx_cur_ptr + hw_data_align;
486 packet_len1 = packet_size;
490 sze->ct_rx_cur_ptr += RTE_SZE2_ALIGN8(sg_size) -
491 RTE_SZE2_PACKET_HEADER_SIZE;
492 sze->ct_rx_rem_bytes -= RTE_SZE2_ALIGN8(sg_size) -
493 RTE_SZE2_PACKET_HEADER_SIZE;
496 if (sze->ct_rx_lck->next == NULL) {
497 errx(6, "Need \"next\" lock, but it is "
498 "missing: %u", sze->ct_rx_rem_bytes);
502 if (sze->ct_rx_rem_bytes <= hw_data_align) {
503 uint16_t rem_size = hw_data_align -
504 sze->ct_rx_rem_bytes;
506 /* MOVE to next lock */
507 sze->ct_rx_lck = sze->ct_rx_lck->next;
509 (void *)(((uint8_t *)
510 (sze->ct_rx_lck->start)) + rem_size);
512 packet_ptr1 = sze->ct_rx_cur_ptr;
513 packet_len1 = packet_size;
517 sze->ct_rx_cur_ptr +=
518 RTE_SZE2_ALIGN8(packet_size);
519 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len -
520 rem_size - RTE_SZE2_ALIGN8(packet_size);
522 /* get pointer and length from first part */
523 packet_ptr1 = sze->ct_rx_cur_ptr +
525 packet_len1 = sze->ct_rx_rem_bytes -
528 /* MOVE to next lock */
529 sze->ct_rx_lck = sze->ct_rx_lck->next;
530 sze->ct_rx_cur_ptr = sze->ct_rx_lck->start;
532 /* get pointer and length from second part */
533 packet_ptr2 = sze->ct_rx_cur_ptr;
534 packet_len2 = packet_size - packet_len1;
536 sze->ct_rx_cur_ptr +=
537 RTE_SZE2_ALIGN8(packet_size) -
539 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len -
540 (RTE_SZE2_ALIGN8(packet_size) -
545 if (unlikely(packet_ptr1 == NULL))
548 mbuf = rte_pktmbuf_alloc(sze_q->mb_pool);
550 if (unlikely(mbuf == NULL)) {
552 * Restore items from sze structure to state after
553 * unlocking (eventually locking).
555 sze->ct_rx_lck = ct_rx_lck_backup;
556 sze->ct_rx_rem_bytes = ct_rx_rem_bytes_backup;
557 sze->ct_rx_cur_ptr = ct_rx_cur_ptr_backup;
558 sze_q->priv->dev->data->rx_mbuf_alloc_failed++;
562 /* get the space available for data in the mbuf */
563 mbp_priv = rte_mempool_get_priv(sze_q->mb_pool);
564 buf_size = (uint16_t)(mbp_priv->mbuf_data_room_size -
565 RTE_PKTMBUF_HEADROOM);
567 if (packet_size <= buf_size) {
568 /* sze packet will fit in one mbuf, go ahead and copy */
569 rte_memcpy(rte_pktmbuf_mtod(mbuf, void *),
570 packet_ptr1, packet_len1);
571 if (packet_ptr2 != NULL) {
573 (rte_pktmbuf_mtod(mbuf, uint8_t *) +
574 packet_len1), packet_ptr2, packet_len2);
576 mbuf->data_len = (uint16_t)packet_size;
579 * sze packet will not fit in one mbuf,
580 * scatter packet into more mbufs
582 struct rte_mbuf *m = mbuf;
583 uint16_t len = rte_pktmbuf_tailroom(mbuf);
585 /* copy first part of packet */
586 /* fill first mbuf */
587 rte_memcpy(rte_pktmbuf_append(mbuf, len), packet_ptr1,
590 packet_ptr1 = ((uint8_t *)packet_ptr1) + len;
592 while (packet_len1 > 0) {
594 m->next = rte_pktmbuf_alloc(sze_q->mb_pool);
596 if (unlikely(m->next == NULL)) {
597 rte_pktmbuf_free(mbuf);
599 * Restore items from sze structure
600 * to state after unlocking (eventually
603 sze->ct_rx_lck = ct_rx_lck_backup;
604 sze->ct_rx_rem_bytes =
605 ct_rx_rem_bytes_backup;
607 ct_rx_cur_ptr_backup;
608 (*mbuf_failed_ptr)++;
614 len = RTE_MIN(rte_pktmbuf_tailroom(m),
616 rte_memcpy(rte_pktmbuf_append(mbuf, len),
621 packet_ptr1 = ((uint8_t *)packet_ptr1) + len;
624 if (packet_ptr2 != NULL) {
625 /* copy second part of packet, if exists */
626 /* fill the rest of currently last mbuf */
627 len = rte_pktmbuf_tailroom(m);
628 rte_memcpy(rte_pktmbuf_append(mbuf, len),
631 packet_ptr2 = ((uint8_t *)packet_ptr2) + len;
633 while (packet_len2 > 0) {
635 m->next = rte_pktmbuf_alloc(
638 if (unlikely(m->next == NULL)) {
639 rte_pktmbuf_free(mbuf);
641 * Restore items from sze
642 * structure to state after
643 * unlocking (eventually
648 sze->ct_rx_rem_bytes =
649 ct_rx_rem_bytes_backup;
651 ct_rx_cur_ptr_backup;
652 (*mbuf_failed_ptr)++;
658 len = RTE_MIN(rte_pktmbuf_tailroom(m),
661 rte_pktmbuf_append(mbuf, len),
666 packet_ptr2 = ((uint8_t *)packet_ptr2) +
671 mbuf->pkt_len = packet_size;
672 mbuf->port = sze_q->in_port;
675 num_bytes += packet_size;
679 sze_q->rx_pkts += num_rx;
680 sze_q->rx_bytes += num_bytes;
685 eth_szedata2_tx(void *queue,
686 struct rte_mbuf **bufs,
689 struct rte_mbuf *mbuf;
690 struct szedata2_tx_queue *sze_q = queue;
692 uint64_t num_bytes = 0;
694 const struct szedata_lock *lck;
700 uint32_t unlock_size;
703 uint16_t pkt_left = nb_pkts;
705 if (sze_q->sze == NULL || nb_pkts == 0)
708 while (pkt_left > 0) {
710 lck = szedata_tx_lock_data(sze_q->sze,
711 RTE_ETH_SZEDATA2_TX_LOCK_SIZE,
717 lock_size = lck->len;
718 lock_size2 = lck->next ? lck->next->len : 0;
721 mbuf = bufs[nb_pkts - pkt_left];
723 pkt_len = mbuf->pkt_len;
724 mbuf_segs = mbuf->nb_segs;
726 hwpkt_len = RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED +
727 RTE_SZE2_ALIGN8(pkt_len);
729 if (lock_size + lock_size2 < hwpkt_len) {
730 szedata_tx_unlock_data(sze_q->sze, lck, unlock_size);
734 num_bytes += pkt_len;
736 if (lock_size > hwpkt_len) {
741 /* write packet length at first 2 bytes in 8B header */
742 *((uint16_t *)dst) = htole16(
743 RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED +
745 *(((uint16_t *)dst) + 1) = htole16(0);
747 /* copy packet from mbuf */
748 tmp_dst = ((uint8_t *)(dst)) +
749 RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED;
750 if (mbuf_segs == 1) {
752 * non-scattered packet,
753 * transmit from one mbuf
756 rte_pktmbuf_mtod(mbuf, const void *),
759 /* scattered packet, transmit from more mbufs */
760 struct rte_mbuf *m = mbuf;
766 tmp_dst = ((uint8_t *)(tmp_dst)) +
773 dst = ((uint8_t *)dst) + hwpkt_len;
774 unlock_size += hwpkt_len;
775 lock_size -= hwpkt_len;
777 rte_pktmbuf_free(mbuf);
781 szedata_tx_unlock_data(sze_q->sze, lck,
786 } else if (lock_size + lock_size2 >= hwpkt_len) {
790 /* write packet length at first 2 bytes in 8B header */
792 htole16(RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED +
794 *(((uint16_t *)dst) + 1) = htole16(0);
797 * If the raw packet (pkt_len) is smaller than lock_size
798 * get the correct length for memcpy
801 pkt_len < lock_size -
802 RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED ?
804 lock_size - RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED;
806 rem_len = hwpkt_len - lock_size;
808 tmp_dst = ((uint8_t *)(dst)) +
809 RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED;
810 if (mbuf_segs == 1) {
812 * non-scattered packet,
813 * transmit from one mbuf
815 /* copy part of packet to first area */
817 rte_pktmbuf_mtod(mbuf, const void *),
821 dst = lck->next->start;
823 /* copy part of packet to second area */
825 (const void *)(rte_pktmbuf_mtod(mbuf,
827 write_len), pkt_len - write_len);
829 /* scattered packet, transmit from more mbufs */
830 struct rte_mbuf *m = mbuf;
831 uint16_t written = 0;
832 uint16_t to_write = 0;
833 bool new_mbuf = true;
834 uint16_t write_off = 0;
836 /* copy part of packet to first area */
837 while (m && written < write_len) {
838 to_write = RTE_MIN(m->data_len,
839 write_len - written);
845 tmp_dst = ((uint8_t *)(tmp_dst)) +
847 if (m->data_len <= write_len -
858 dst = lck->next->start;
862 write_off = new_mbuf ? 0 : to_write;
864 /* copy part of packet to second area */
865 while (m && written < pkt_len - write_len) {
866 rte_memcpy(tmp_dst, (const void *)
868 uint8_t *) + write_off),
869 m->data_len - write_off);
871 tmp_dst = ((uint8_t *)(tmp_dst)) +
872 (m->data_len - write_off);
873 written += m->data_len - write_off;
879 dst = ((uint8_t *)dst) + rem_len;
880 unlock_size += hwpkt_len;
881 lock_size = lock_size2 - rem_len;
884 rte_pktmbuf_free(mbuf);
888 szedata_tx_unlock_data(sze_q->sze, lck, unlock_size);
892 sze_q->tx_pkts += num_tx;
893 sze_q->err_pkts += nb_pkts - num_tx;
894 sze_q->tx_bytes += num_bytes;
899 eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rxq_id)
901 struct szedata2_rx_queue *rxq = dev->data->rx_queues[rxq_id];
903 struct pmd_internals *internals = (struct pmd_internals *)
904 dev->data->dev_private;
906 if (rxq->sze == NULL) {
907 uint32_t rx = 1 << rxq->rx_channel;
909 rxq->sze = szedata_open(internals->sze_dev_path);
910 if (rxq->sze == NULL)
912 ret = szedata_subscribe3(rxq->sze, &rx, &tx);
913 if (ret != 0 || rx == 0)
917 ret = szedata_start(rxq->sze);
920 dev->data->rx_queue_state[rxq_id] = RTE_ETH_QUEUE_STATE_STARTED;
924 szedata_close(rxq->sze);
930 eth_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rxq_id)
932 struct szedata2_rx_queue *rxq = dev->data->rx_queues[rxq_id];
934 if (rxq->sze != NULL) {
935 szedata_close(rxq->sze);
939 dev->data->rx_queue_state[rxq_id] = RTE_ETH_QUEUE_STATE_STOPPED;
944 eth_tx_queue_start(struct rte_eth_dev *dev, uint16_t txq_id)
946 struct szedata2_tx_queue *txq = dev->data->tx_queues[txq_id];
948 struct pmd_internals *internals = (struct pmd_internals *)
949 dev->data->dev_private;
951 if (txq->sze == NULL) {
953 uint32_t tx = 1 << txq->tx_channel;
954 txq->sze = szedata_open(internals->sze_dev_path);
955 if (txq->sze == NULL)
957 ret = szedata_subscribe3(txq->sze, &rx, &tx);
958 if (ret != 0 || tx == 0)
962 ret = szedata_start(txq->sze);
965 dev->data->tx_queue_state[txq_id] = RTE_ETH_QUEUE_STATE_STARTED;
969 szedata_close(txq->sze);
975 eth_tx_queue_stop(struct rte_eth_dev *dev, uint16_t txq_id)
977 struct szedata2_tx_queue *txq = dev->data->tx_queues[txq_id];
979 if (txq->sze != NULL) {
980 szedata_close(txq->sze);
984 dev->data->tx_queue_state[txq_id] = RTE_ETH_QUEUE_STATE_STOPPED;
989 eth_dev_start(struct rte_eth_dev *dev)
993 uint16_t nb_rx = dev->data->nb_rx_queues;
994 uint16_t nb_tx = dev->data->nb_tx_queues;
996 for (i = 0; i < nb_rx; i++) {
997 ret = eth_rx_queue_start(dev, i);
1002 for (i = 0; i < nb_tx; i++) {
1003 ret = eth_tx_queue_start(dev, i);
1011 for (i = 0; i < nb_tx; i++)
1012 eth_tx_queue_stop(dev, i);
1014 for (i = 0; i < nb_rx; i++)
1015 eth_rx_queue_stop(dev, i);
1020 eth_dev_stop(struct rte_eth_dev *dev)
1023 uint16_t nb_rx = dev->data->nb_rx_queues;
1024 uint16_t nb_tx = dev->data->nb_tx_queues;
1026 for (i = 0; i < nb_tx; i++)
1027 eth_tx_queue_stop(dev, i);
1029 for (i = 0; i < nb_rx; i++)
1030 eth_rx_queue_stop(dev, i);
1034 eth_dev_configure(struct rte_eth_dev *dev)
1036 struct rte_eth_dev_data *data = dev->data;
1037 if (data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_SCATTER) {
1038 dev->rx_pkt_burst = eth_szedata2_rx_scattered;
1039 data->scattered_rx = 1;
1041 dev->rx_pkt_burst = eth_szedata2_rx;
1042 data->scattered_rx = 0;
1048 eth_dev_info(struct rte_eth_dev *dev,
1049 struct rte_eth_dev_info *dev_info)
1051 struct pmd_internals *internals = dev->data->dev_private;
1053 dev_info->if_index = 0;
1054 dev_info->max_mac_addrs = 1;
1055 dev_info->max_rx_pktlen = (uint32_t)-1;
1056 dev_info->max_rx_queues = internals->max_rx_queues;
1057 dev_info->max_tx_queues = internals->max_tx_queues;
1058 dev_info->min_rx_bufsize = 0;
1059 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_SCATTER;
1060 dev_info->tx_offload_capa = 0;
1061 dev_info->rx_queue_offload_capa = 0;
1062 dev_info->tx_queue_offload_capa = 0;
1063 dev_info->speed_capa = ETH_LINK_SPEED_100G;
1067 eth_stats_get(struct rte_eth_dev *dev,
1068 struct rte_eth_stats *stats)
1071 uint16_t nb_rx = dev->data->nb_rx_queues;
1072 uint16_t nb_tx = dev->data->nb_tx_queues;
1073 uint64_t rx_total = 0;
1074 uint64_t tx_total = 0;
1075 uint64_t tx_err_total = 0;
1076 uint64_t rx_total_bytes = 0;
1077 uint64_t tx_total_bytes = 0;
1079 for (i = 0; i < nb_rx; i++) {
1080 struct szedata2_rx_queue *rxq = dev->data->rx_queues[i];
1082 if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1083 stats->q_ipackets[i] = rxq->rx_pkts;
1084 stats->q_ibytes[i] = rxq->rx_bytes;
1086 rx_total += rxq->rx_pkts;
1087 rx_total_bytes += rxq->rx_bytes;
1090 for (i = 0; i < nb_tx; i++) {
1091 struct szedata2_tx_queue *txq = dev->data->tx_queues[i];
1093 if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1094 stats->q_opackets[i] = txq->tx_pkts;
1095 stats->q_obytes[i] = txq->tx_bytes;
1097 tx_total += txq->tx_pkts;
1098 tx_total_bytes += txq->tx_bytes;
1099 tx_err_total += txq->err_pkts;
1102 stats->ipackets = rx_total;
1103 stats->opackets = tx_total;
1104 stats->ibytes = rx_total_bytes;
1105 stats->obytes = tx_total_bytes;
1106 stats->oerrors = tx_err_total;
1107 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1113 eth_stats_reset(struct rte_eth_dev *dev)
1116 uint16_t nb_rx = dev->data->nb_rx_queues;
1117 uint16_t nb_tx = dev->data->nb_tx_queues;
1119 for (i = 0; i < nb_rx; i++) {
1120 struct szedata2_rx_queue *rxq = dev->data->rx_queues[i];
1125 for (i = 0; i < nb_tx; i++) {
1126 struct szedata2_tx_queue *txq = dev->data->tx_queues[i];
1134 eth_rx_queue_release(void *q)
1136 struct szedata2_rx_queue *rxq = (struct szedata2_rx_queue *)q;
1139 if (rxq->sze != NULL)
1140 szedata_close(rxq->sze);
1146 eth_tx_queue_release(void *q)
1148 struct szedata2_tx_queue *txq = (struct szedata2_tx_queue *)q;
1151 if (txq->sze != NULL)
1152 szedata_close(txq->sze);
1158 eth_dev_close(struct rte_eth_dev *dev)
1161 uint16_t nb_rx = dev->data->nb_rx_queues;
1162 uint16_t nb_tx = dev->data->nb_tx_queues;
1166 for (i = 0; i < nb_rx; i++) {
1167 eth_rx_queue_release(dev->data->rx_queues[i]);
1168 dev->data->rx_queues[i] = NULL;
1170 dev->data->nb_rx_queues = 0;
1171 for (i = 0; i < nb_tx; i++) {
1172 eth_tx_queue_release(dev->data->tx_queues[i]);
1173 dev->data->tx_queues[i] = NULL;
1175 dev->data->nb_tx_queues = 0;
1179 eth_link_update(struct rte_eth_dev *dev,
1180 int wait_to_complete __rte_unused)
1182 struct rte_eth_link link;
1184 memset(&link, 0, sizeof(link));
1186 link.link_speed = ETH_SPEED_NUM_100G;
1187 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1188 link.link_status = ETH_LINK_UP;
1189 link.link_autoneg = ETH_LINK_FIXED;
1191 rte_eth_linkstatus_set(dev, &link);
1196 eth_dev_set_link_up(struct rte_eth_dev *dev __rte_unused)
1198 PMD_DRV_LOG(WARNING, "Setting link up is not supported.");
1203 eth_dev_set_link_down(struct rte_eth_dev *dev __rte_unused)
1205 PMD_DRV_LOG(WARNING, "Setting link down is not supported.");
1210 eth_rx_queue_setup(struct rte_eth_dev *dev,
1211 uint16_t rx_queue_id,
1212 uint16_t nb_rx_desc __rte_unused,
1213 unsigned int socket_id,
1214 const struct rte_eth_rxconf *rx_conf __rte_unused,
1215 struct rte_mempool *mb_pool)
1217 struct szedata2_rx_queue *rxq;
1219 struct pmd_internals *internals = dev->data->dev_private;
1220 uint8_t rx_channel = internals->rxq_base_id + rx_queue_id;
1221 uint32_t rx = 1 << rx_channel;
1224 PMD_INIT_FUNC_TRACE();
1226 if (dev->data->rx_queues[rx_queue_id] != NULL) {
1227 eth_rx_queue_release(dev->data->rx_queues[rx_queue_id]);
1228 dev->data->rx_queues[rx_queue_id] = NULL;
1231 rxq = rte_zmalloc_socket("szedata2 rx queue",
1232 sizeof(struct szedata2_rx_queue),
1233 RTE_CACHE_LINE_SIZE, socket_id);
1235 PMD_INIT_LOG(ERR, "rte_zmalloc_socket() failed for rx queue id "
1236 "%" PRIu16 "!", rx_queue_id);
1240 rxq->priv = internals;
1241 rxq->sze = szedata_open(internals->sze_dev_path);
1242 if (rxq->sze == NULL) {
1243 PMD_INIT_LOG(ERR, "szedata_open() failed for rx queue id "
1244 "%" PRIu16 "!", rx_queue_id);
1245 eth_rx_queue_release(rxq);
1248 ret = szedata_subscribe3(rxq->sze, &rx, &tx);
1249 if (ret != 0 || rx == 0) {
1250 PMD_INIT_LOG(ERR, "szedata_subscribe3() failed for rx queue id "
1251 "%" PRIu16 "!", rx_queue_id);
1252 eth_rx_queue_release(rxq);
1255 rxq->rx_channel = rx_channel;
1256 rxq->qid = rx_queue_id;
1257 rxq->in_port = dev->data->port_id;
1258 rxq->mb_pool = mb_pool;
1263 dev->data->rx_queues[rx_queue_id] = rxq;
1265 PMD_INIT_LOG(DEBUG, "Configured rx queue id %" PRIu16 " on socket "
1266 "%u (channel id %u).", rxq->qid, socket_id,
1273 eth_tx_queue_setup(struct rte_eth_dev *dev,
1274 uint16_t tx_queue_id,
1275 uint16_t nb_tx_desc __rte_unused,
1276 unsigned int socket_id,
1277 const struct rte_eth_txconf *tx_conf __rte_unused)
1279 struct szedata2_tx_queue *txq;
1281 struct pmd_internals *internals = dev->data->dev_private;
1282 uint8_t tx_channel = internals->txq_base_id + tx_queue_id;
1284 uint32_t tx = 1 << tx_channel;
1286 PMD_INIT_FUNC_TRACE();
1288 if (dev->data->tx_queues[tx_queue_id] != NULL) {
1289 eth_tx_queue_release(dev->data->tx_queues[tx_queue_id]);
1290 dev->data->tx_queues[tx_queue_id] = NULL;
1293 txq = rte_zmalloc_socket("szedata2 tx queue",
1294 sizeof(struct szedata2_tx_queue),
1295 RTE_CACHE_LINE_SIZE, socket_id);
1297 PMD_INIT_LOG(ERR, "rte_zmalloc_socket() failed for tx queue id "
1298 "%" PRIu16 "!", tx_queue_id);
1302 txq->priv = internals;
1303 txq->sze = szedata_open(internals->sze_dev_path);
1304 if (txq->sze == NULL) {
1305 PMD_INIT_LOG(ERR, "szedata_open() failed for tx queue id "
1306 "%" PRIu16 "!", tx_queue_id);
1307 eth_tx_queue_release(txq);
1310 ret = szedata_subscribe3(txq->sze, &rx, &tx);
1311 if (ret != 0 || tx == 0) {
1312 PMD_INIT_LOG(ERR, "szedata_subscribe3() failed for tx queue id "
1313 "%" PRIu16 "!", tx_queue_id);
1314 eth_tx_queue_release(txq);
1317 txq->tx_channel = tx_channel;
1318 txq->qid = tx_queue_id;
1323 dev->data->tx_queues[tx_queue_id] = txq;
1325 PMD_INIT_LOG(DEBUG, "Configured tx queue id %" PRIu16 " on socket "
1326 "%u (channel id %u).", txq->qid, socket_id,
1333 eth_mac_addr_set(struct rte_eth_dev *dev __rte_unused,
1334 struct rte_ether_addr *mac_addr __rte_unused)
1340 eth_promiscuous_enable(struct rte_eth_dev *dev __rte_unused)
1342 PMD_DRV_LOG(WARNING, "Enabling promiscuous mode is not supported. "
1343 "The card is always in promiscuous mode.");
1347 eth_promiscuous_disable(struct rte_eth_dev *dev __rte_unused)
1349 PMD_DRV_LOG(WARNING, "Disabling promiscuous mode is not supported. "
1350 "The card is always in promiscuous mode.");
1354 eth_allmulticast_enable(struct rte_eth_dev *dev __rte_unused)
1356 PMD_DRV_LOG(WARNING, "Enabling allmulticast mode is not supported.");
1360 eth_allmulticast_disable(struct rte_eth_dev *dev __rte_unused)
1362 PMD_DRV_LOG(WARNING, "Disabling allmulticast mode is not supported.");
1365 static const struct eth_dev_ops ops = {
1366 .dev_start = eth_dev_start,
1367 .dev_stop = eth_dev_stop,
1368 .dev_set_link_up = eth_dev_set_link_up,
1369 .dev_set_link_down = eth_dev_set_link_down,
1370 .dev_close = eth_dev_close,
1371 .dev_configure = eth_dev_configure,
1372 .dev_infos_get = eth_dev_info,
1373 .promiscuous_enable = eth_promiscuous_enable,
1374 .promiscuous_disable = eth_promiscuous_disable,
1375 .allmulticast_enable = eth_allmulticast_enable,
1376 .allmulticast_disable = eth_allmulticast_disable,
1377 .rx_queue_start = eth_rx_queue_start,
1378 .rx_queue_stop = eth_rx_queue_stop,
1379 .tx_queue_start = eth_tx_queue_start,
1380 .tx_queue_stop = eth_tx_queue_stop,
1381 .rx_queue_setup = eth_rx_queue_setup,
1382 .tx_queue_setup = eth_tx_queue_setup,
1383 .rx_queue_release = eth_rx_queue_release,
1384 .tx_queue_release = eth_tx_queue_release,
1385 .link_update = eth_link_update,
1386 .stats_get = eth_stats_get,
1387 .stats_reset = eth_stats_reset,
1388 .mac_addr_set = eth_mac_addr_set,
1392 * This function goes through sysfs and looks for an index of szedata2
1393 * device file (/dev/szedataIIX, where X is the index).
1400 get_szedata2_index(const struct rte_pci_addr *pcislot_addr, uint32_t *index)
1403 struct dirent *entry;
1407 char pcislot_path[PATH_MAX];
1413 dir = opendir("/sys/class/combo");
1418 * Iterate through all combosixX directories.
1419 * When the value in /sys/class/combo/combosixX/device/pcislot
1420 * file is the location of the ethernet device dev, "X" is the
1421 * index of the device.
1423 while ((entry = readdir(dir)) != NULL) {
1424 ret = sscanf(entry->d_name, "combosix%u", &tmp_index);
1428 snprintf(pcislot_path, PATH_MAX,
1429 "/sys/class/combo/combosix%u/device/pcislot",
1432 fd = fopen(pcislot_path, "r");
1436 ret = fscanf(fd, "%8" SCNx32 ":%2" SCNx8 ":%2" SCNx8 ".%" SCNx8,
1437 &domain, &bus, &devid, &function);
1442 if (pcislot_addr->domain == domain &&
1443 pcislot_addr->bus == bus &&
1444 pcislot_addr->devid == devid &&
1445 pcislot_addr->function == function) {
1457 * @brief Initializes rte_eth_dev device.
1458 * @param dev Device to initialize.
1459 * @param pi Structure with info about DMA queues.
1460 * @return 0 on success, negative error code on error.
1463 rte_szedata2_eth_dev_init(struct rte_eth_dev *dev, struct port_info *pi)
1466 uint32_t szedata2_index;
1467 char name[PATH_MAX];
1468 struct rte_eth_dev_data *data = dev->data;
1469 struct pmd_internals *internals = (struct pmd_internals *)
1471 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1473 PMD_INIT_FUNC_TRACE();
1475 PMD_INIT_LOG(INFO, "Initializing eth_dev %s (driver %s)", data->name,
1476 RTE_STR(RTE_SZEDATA2_DRIVER_NAME));
1478 /* Fill internal private structure. */
1479 internals->dev = dev;
1480 /* Get index of szedata2 device file and create path to device file */
1481 ret = get_szedata2_index(&pci_dev->addr, &szedata2_index);
1483 PMD_INIT_LOG(ERR, "Failed to get szedata2 device index!");
1486 snprintf(name, PATH_MAX, SZEDATA2_DEV_PATH_FMT, szedata2_index);
1487 internals->sze_dev_path = strdup(name);
1488 if (internals->sze_dev_path == NULL) {
1489 PMD_INIT_LOG(ERR, "strdup() failed!");
1492 PMD_INIT_LOG(INFO, "SZEDATA2 path: %s", internals->sze_dev_path);
1493 internals->max_rx_queues = pi->rx_count;
1494 internals->max_tx_queues = pi->tx_count;
1495 internals->rxq_base_id = pi->rx_base_id;
1496 internals->txq_base_id = pi->tx_base_id;
1497 PMD_INIT_LOG(INFO, "%u RX DMA channels from id %u",
1498 internals->max_rx_queues, internals->rxq_base_id);
1499 PMD_INIT_LOG(INFO, "%u TX DMA channels from id %u",
1500 internals->max_tx_queues, internals->txq_base_id);
1502 /* Set rx, tx burst functions */
1503 if (data->scattered_rx == 1)
1504 dev->rx_pkt_burst = eth_szedata2_rx_scattered;
1506 dev->rx_pkt_burst = eth_szedata2_rx;
1507 dev->tx_pkt_burst = eth_szedata2_tx;
1509 /* Set function callbacks for Ethernet API */
1510 dev->dev_ops = &ops;
1512 /* Get link state */
1513 eth_link_update(dev, 0);
1515 /* Allocate space for one mac address */
1516 data->mac_addrs = rte_zmalloc(data->name, sizeof(struct rte_ether_addr),
1517 RTE_CACHE_LINE_SIZE);
1518 if (data->mac_addrs == NULL) {
1519 PMD_INIT_LOG(ERR, "Could not alloc space for MAC address!");
1520 free(internals->sze_dev_path);
1524 rte_ether_addr_copy(ð_addr, data->mac_addrs);
1526 PMD_INIT_LOG(INFO, "%s device %s successfully initialized",
1527 RTE_STR(RTE_SZEDATA2_DRIVER_NAME), data->name);
1533 * @brief Unitializes rte_eth_dev device.
1534 * @param dev Device to uninitialize.
1535 * @return 0 on success, negative error code on error.
1538 rte_szedata2_eth_dev_uninit(struct rte_eth_dev *dev)
1540 struct pmd_internals *internals = (struct pmd_internals *)
1541 dev->data->dev_private;
1543 PMD_INIT_FUNC_TRACE();
1545 free(internals->sze_dev_path);
1547 PMD_DRV_LOG(INFO, "%s device %s successfully uninitialized",
1548 RTE_STR(RTE_SZEDATA2_DRIVER_NAME), dev->data->name);
1553 static const struct rte_pci_id rte_szedata2_pci_id_table[] = {
1555 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE,
1556 PCI_DEVICE_ID_NETCOPE_COMBO80G)
1559 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE,
1560 PCI_DEVICE_ID_NETCOPE_COMBO100G)
1563 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE,
1564 PCI_DEVICE_ID_NETCOPE_COMBO100G2)
1567 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE,
1568 PCI_DEVICE_ID_NETCOPE_NFB200G2QL)
1571 RTE_PCI_DEVICE(PCI_VENDOR_ID_SILICOM,
1572 PCI_DEVICE_ID_FB2CGG3)
1575 RTE_PCI_DEVICE(PCI_VENDOR_ID_SILICOM,
1576 PCI_DEVICE_ID_FB2CGG3D)
1584 * @brief Gets info about DMA queues for ports.
1585 * @param pci_dev PCI device structure.
1586 * @param port_count Pointer to variable set with number of ports.
1587 * @param pi Pointer to array of structures with info about DMA queues
1589 * @param max_ports Maximum number of ports.
1590 * @return 0 on success, negative error code on error.
1593 get_port_info(struct rte_pci_device *pci_dev, unsigned int *port_count,
1594 struct port_info *pi, unsigned int max_ports)
1596 struct szedata *szedata_temp;
1597 char sze_dev_path[PATH_MAX];
1598 uint32_t szedata2_index;
1600 uint16_t max_rx_queues;
1601 uint16_t max_tx_queues;
1606 memset(pi, 0, max_ports * sizeof(struct port_info));
1609 /* Get index of szedata2 device file and create path to device file */
1610 ret = get_szedata2_index(&pci_dev->addr, &szedata2_index);
1612 PMD_INIT_LOG(ERR, "Failed to get szedata2 device index!");
1615 snprintf(sze_dev_path, PATH_MAX, SZEDATA2_DEV_PATH_FMT, szedata2_index);
1618 * Get number of available DMA RX and TX channels, which is maximum
1619 * number of queues that can be created.
1621 szedata_temp = szedata_open(sze_dev_path);
1622 if (szedata_temp == NULL) {
1623 PMD_INIT_LOG(ERR, "szedata_open(%s) failed", sze_dev_path);
1626 max_rx_queues = szedata_ifaces_available(szedata_temp, SZE2_DIR_RX);
1627 max_tx_queues = szedata_ifaces_available(szedata_temp, SZE2_DIR_TX);
1628 PMD_INIT_LOG(INFO, "Available DMA channels RX: %u TX: %u",
1629 max_rx_queues, max_tx_queues);
1630 if (max_rx_queues > RTE_ETH_SZEDATA2_MAX_RX_QUEUES) {
1631 PMD_INIT_LOG(ERR, "%u RX queues exceeds supported number %u",
1632 max_rx_queues, RTE_ETH_SZEDATA2_MAX_RX_QUEUES);
1633 szedata_close(szedata_temp);
1636 if (max_tx_queues > RTE_ETH_SZEDATA2_MAX_TX_QUEUES) {
1637 PMD_INIT_LOG(ERR, "%u TX queues exceeds supported number %u",
1638 max_tx_queues, RTE_ETH_SZEDATA2_MAX_TX_QUEUES);
1639 szedata_close(szedata_temp);
1643 if (pci_dev->id.device_id == PCI_DEVICE_ID_NETCOPE_NFB200G2QL) {
1645 unsigned int rx_queues = max_rx_queues / max_ports;
1646 unsigned int tx_queues = max_tx_queues / max_ports;
1649 * Number of queues reported by szedata_ifaces_available()
1650 * is the number of all queues from all DMA controllers which
1651 * may reside at different numa locations.
1652 * All queues from the same DMA controller have the same numa
1654 * Numa node from the first queue of each DMA controller is
1656 * If the numa node differs from the numa node of the queues
1657 * from the previous DMA controller the queues are assigned
1661 for (i = 0; i < max_ports; i++) {
1662 int numa_rx = szedata_get_area_numa_node(szedata_temp,
1663 SZE2_DIR_RX, rx_queues * i);
1664 int numa_tx = szedata_get_area_numa_node(szedata_temp,
1665 SZE2_DIR_TX, tx_queues * i);
1666 unsigned int port_rx_queues = numa_rx != -1 ?
1668 unsigned int port_tx_queues = numa_tx != -1 ?
1670 PMD_INIT_LOG(DEBUG, "%u rx queues from id %u, numa %d",
1671 rx_queues, rx_queues * i, numa_rx);
1672 PMD_INIT_LOG(DEBUG, "%u tx queues from id %u, numa %d",
1673 tx_queues, tx_queues * i, numa_tx);
1675 if (port_rx_queues != 0 && port_tx_queues != 0 &&
1676 numa_rx != numa_tx) {
1677 PMD_INIT_LOG(ERR, "RX queue %u numa %d differs "
1678 "from TX queue %u numa %d "
1680 rx_queues * i, numa_rx,
1681 tx_queues * i, numa_tx);
1682 szedata_close(szedata_temp);
1684 } else if (port_rx_queues == 0 && port_tx_queues == 0) {
1688 unsigned int current = *port_count;
1689 int port_numa = port_rx_queues != 0 ?
1692 for (j = 0; j < *port_count; j++) {
1693 if (pi[j].numa_node ==
1699 if (pi[current].rx_count == 0 &&
1700 pi[current].tx_count == 0) {
1701 pi[current].rx_base_id = rx_queues * i;
1702 pi[current].tx_base_id = tx_queues * i;
1704 } else if ((rx_queues * i !=
1705 pi[current].rx_base_id +
1706 pi[current].rx_count) ||
1708 pi[current].tx_base_id +
1709 pi[current].tx_count)) {
1710 PMD_INIT_LOG(ERR, "Queue ids does not "
1711 "fulfill constraints");
1712 szedata_close(szedata_temp);
1715 pi[current].rx_count += port_rx_queues;
1716 pi[current].tx_count += port_tx_queues;
1717 pi[current].numa_node = port_numa;
1721 pi[0].rx_count = max_rx_queues;
1722 pi[0].tx_count = max_tx_queues;
1723 pi[0].numa_node = pci_dev->device.numa_node;
1727 szedata_close(szedata_temp);
1732 * @brief Allocates rte_eth_dev device.
1733 * @param pci_dev Corresponding PCI device.
1734 * @param numa_node NUMA node on which device is allocated.
1735 * @param port_no Id of rte_eth_device created on PCI device pci_dev.
1736 * @return Pointer to allocated device or NULL on error.
1738 static struct rte_eth_dev *
1739 szedata2_eth_dev_allocate(struct rte_pci_device *pci_dev, int numa_node,
1740 unsigned int port_no)
1742 struct rte_eth_dev *eth_dev;
1743 char name[RTE_ETH_NAME_MAX_LEN];
1745 PMD_INIT_FUNC_TRACE();
1747 snprintf(name, RTE_ETH_NAME_MAX_LEN, "%s"
1748 SZEDATA2_ETH_DEV_NAME_SUFFIX_FMT,
1749 pci_dev->device.name, port_no);
1750 PMD_INIT_LOG(DEBUG, "Allocating eth_dev %s", name);
1752 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1753 eth_dev = rte_eth_dev_allocate(name);
1757 eth_dev->data->dev_private = rte_zmalloc_socket(name,
1758 sizeof(struct pmd_internals), RTE_CACHE_LINE_SIZE,
1760 if (!eth_dev->data->dev_private) {
1761 rte_eth_dev_release_port(eth_dev);
1765 eth_dev = rte_eth_dev_attach_secondary(name);
1770 eth_dev->device = &pci_dev->device;
1771 rte_eth_copy_pci_info(eth_dev, pci_dev);
1772 eth_dev->data->numa_node = numa_node;
1777 * @brief Releases interval of rte_eth_dev devices from array.
1778 * @param eth_devs Array of pointers to rte_eth_dev devices.
1779 * @param from Index in array eth_devs to start with.
1780 * @param to Index in array right after the last element to release.
1782 * Used for releasing at failed initialization.
1785 szedata2_eth_dev_release_interval(struct rte_eth_dev **eth_devs,
1786 unsigned int from, unsigned int to)
1790 PMD_INIT_FUNC_TRACE();
1792 for (i = from; i < to; i++) {
1793 rte_szedata2_eth_dev_uninit(eth_devs[i]);
1794 rte_eth_dev_pci_release(eth_devs[i]);
1799 * @brief Callback .probe for struct rte_pci_driver.
1801 static int szedata2_eth_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1802 struct rte_pci_device *pci_dev)
1804 struct port_info port_info[SZEDATA2_MAX_PORTS];
1805 unsigned int port_count;
1808 struct pci_dev_list_entry *list_entry;
1809 struct rte_eth_dev *eth_devs[SZEDATA2_MAX_PORTS] = {NULL,};
1811 PMD_INIT_FUNC_TRACE();
1813 ret = get_port_info(pci_dev, &port_count, port_info,
1814 SZEDATA2_MAX_PORTS);
1818 if (port_count == 0) {
1819 PMD_INIT_LOG(ERR, "No available ports!");
1823 list_entry = rte_zmalloc(NULL, sizeof(struct pci_dev_list_entry),
1824 RTE_CACHE_LINE_SIZE);
1825 if (list_entry == NULL) {
1826 PMD_INIT_LOG(ERR, "rte_zmalloc() failed!");
1830 for (i = 0; i < port_count; i++) {
1831 eth_devs[i] = szedata2_eth_dev_allocate(pci_dev,
1832 port_info[i].numa_node, i);
1833 if (eth_devs[i] == NULL) {
1834 PMD_INIT_LOG(ERR, "Failed to alloc eth_dev for port %u",
1836 szedata2_eth_dev_release_interval(eth_devs, 0, i);
1837 rte_free(list_entry);
1841 ret = rte_szedata2_eth_dev_init(eth_devs[i], &port_info[i]);
1843 PMD_INIT_LOG(ERR, "Failed to init eth_dev for port %u",
1845 rte_eth_dev_pci_release(eth_devs[i]);
1846 szedata2_eth_dev_release_interval(eth_devs, 0, i);
1847 rte_free(list_entry);
1851 rte_eth_dev_probing_finish(eth_devs[i]);
1855 * Add pci_dev to list of PCI devices for this driver
1856 * which is used at remove callback to release all created eth_devs.
1858 list_entry->pci_dev = pci_dev;
1859 list_entry->port_count = port_count;
1860 LIST_INSERT_HEAD(&szedata2_pci_dev_list, list_entry, next);
1865 * @brief Callback .remove for struct rte_pci_driver.
1867 static int szedata2_eth_pci_remove(struct rte_pci_device *pci_dev)
1870 unsigned int port_count;
1871 char name[RTE_ETH_NAME_MAX_LEN];
1872 struct rte_eth_dev *eth_dev;
1876 struct pci_dev_list_entry *list_entry = NULL;
1878 PMD_INIT_FUNC_TRACE();
1880 LIST_FOREACH(list_entry, &szedata2_pci_dev_list, next) {
1881 if (list_entry->pci_dev == pci_dev) {
1882 port_count = list_entry->port_count;
1887 LIST_REMOVE(list_entry, next);
1888 rte_free(list_entry);
1891 PMD_DRV_LOG(ERR, "PCI device " PCI_PRI_FMT " not found",
1892 pci_dev->addr.domain, pci_dev->addr.bus,
1893 pci_dev->addr.devid, pci_dev->addr.function);
1897 for (i = 0; i < port_count; i++) {
1898 snprintf(name, RTE_ETH_NAME_MAX_LEN, "%s"
1899 SZEDATA2_ETH_DEV_NAME_SUFFIX_FMT,
1900 pci_dev->device.name, i);
1901 PMD_DRV_LOG(DEBUG, "Removing eth_dev %s", name);
1902 eth_dev = rte_eth_dev_allocated(name);
1904 PMD_DRV_LOG(ERR, "eth_dev %s not found", name);
1905 retval = retval ? retval : -ENODEV;
1908 ret = rte_szedata2_eth_dev_uninit(eth_dev);
1910 PMD_DRV_LOG(ERR, "eth_dev %s uninit failed", name);
1911 retval = retval ? retval : ret;
1914 rte_eth_dev_pci_release(eth_dev);
1920 static struct rte_pci_driver szedata2_eth_driver = {
1921 .id_table = rte_szedata2_pci_id_table,
1922 .probe = szedata2_eth_pci_probe,
1923 .remove = szedata2_eth_pci_remove,
1926 RTE_PMD_REGISTER_PCI(RTE_SZEDATA2_DRIVER_NAME, szedata2_eth_driver);
1927 RTE_PMD_REGISTER_PCI_TABLE(RTE_SZEDATA2_DRIVER_NAME, rte_szedata2_pci_id_table);
1928 RTE_PMD_REGISTER_KMOD_DEP(RTE_SZEDATA2_DRIVER_NAME,
1929 "* combo6core & combov3 & szedata2 & ( szedata2_cv3 | szedata2_cv3_fdt )");
1931 RTE_INIT(szedata2_init_log)
1933 szedata2_logtype_init = rte_log_register("pmd.net.szedata2.init");
1934 if (szedata2_logtype_init >= 0)
1935 rte_log_set_level(szedata2_logtype_init, RTE_LOG_NOTICE);
1936 szedata2_logtype_driver = rte_log_register("pmd.net.szedata2.driver");
1937 if (szedata2_logtype_driver >= 0)
1938 rte_log_set_level(szedata2_logtype_driver, RTE_LOG_NOTICE);