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 static struct rte_ether_addr eth_addr = {
106 .addr_bytes = { 0x00, 0x11, 0x17, 0x00, 0x00, 0x00 }
110 eth_szedata2_rx(void *queue,
111 struct rte_mbuf **bufs,
115 struct rte_mbuf *mbuf;
116 struct szedata2_rx_queue *sze_q = queue;
117 struct rte_pktmbuf_pool_private *mbp_priv;
122 uint16_t packet_size;
123 uint64_t num_bytes = 0;
124 struct szedata *sze = sze_q->sze;
125 uint8_t *header_ptr = NULL; /* header of packet */
126 uint8_t *packet_ptr1 = NULL;
127 uint8_t *packet_ptr2 = NULL;
128 uint16_t packet_len1 = 0;
129 uint16_t packet_len2 = 0;
130 uint16_t hw_data_align;
132 if (unlikely(sze_q->sze == NULL || nb_pkts == 0))
136 * Reads the given number of packets from szedata2 channel given
137 * by queue and copies the packet data into a newly allocated mbuf
140 for (i = 0; i < nb_pkts; i++) {
141 mbuf = rte_pktmbuf_alloc(sze_q->mb_pool);
143 if (unlikely(mbuf == NULL)) {
144 sze_q->priv->dev->data->rx_mbuf_alloc_failed++;
148 /* get the next sze packet */
149 if (sze->ct_rx_lck != NULL && !sze->ct_rx_rem_bytes &&
150 sze->ct_rx_lck->next == NULL) {
151 /* unlock old data */
152 szedata_rx_unlock_data(sze_q->sze, sze->ct_rx_lck_orig);
153 sze->ct_rx_lck_orig = NULL;
154 sze->ct_rx_lck = NULL;
157 if (!sze->ct_rx_rem_bytes && sze->ct_rx_lck_orig == NULL) {
158 /* nothing to read, lock new data */
159 sze->ct_rx_lck = szedata_rx_lock_data(sze_q->sze, ~0U);
160 sze->ct_rx_lck_orig = sze->ct_rx_lck;
162 if (sze->ct_rx_lck == NULL) {
163 /* nothing to lock */
164 rte_pktmbuf_free(mbuf);
168 sze->ct_rx_cur_ptr = sze->ct_rx_lck->start;
169 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len;
171 if (!sze->ct_rx_rem_bytes) {
172 rte_pktmbuf_free(mbuf);
177 if (sze->ct_rx_rem_bytes < RTE_SZE2_PACKET_HEADER_SIZE) {
180 * copy parts of header to merge buffer
182 if (sze->ct_rx_lck->next == NULL) {
183 rte_pktmbuf_free(mbuf);
187 /* copy first part of header */
188 rte_memcpy(sze->ct_rx_buffer, sze->ct_rx_cur_ptr,
189 sze->ct_rx_rem_bytes);
191 /* copy second part of header */
192 sze->ct_rx_lck = sze->ct_rx_lck->next;
193 sze->ct_rx_cur_ptr = sze->ct_rx_lck->start;
194 rte_memcpy(sze->ct_rx_buffer + sze->ct_rx_rem_bytes,
196 RTE_SZE2_PACKET_HEADER_SIZE -
197 sze->ct_rx_rem_bytes);
199 sze->ct_rx_cur_ptr += RTE_SZE2_PACKET_HEADER_SIZE -
200 sze->ct_rx_rem_bytes;
201 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len -
202 RTE_SZE2_PACKET_HEADER_SIZE +
203 sze->ct_rx_rem_bytes;
205 header_ptr = (uint8_t *)sze->ct_rx_buffer;
208 header_ptr = (uint8_t *)sze->ct_rx_cur_ptr;
209 sze->ct_rx_cur_ptr += RTE_SZE2_PACKET_HEADER_SIZE;
210 sze->ct_rx_rem_bytes -= RTE_SZE2_PACKET_HEADER_SIZE;
213 sg_size = le16toh(*((uint16_t *)header_ptr));
214 hw_size = le16toh(*(((uint16_t *)header_ptr) + 1));
215 packet_size = sg_size -
216 RTE_SZE2_ALIGN8(RTE_SZE2_PACKET_HEADER_SIZE + hw_size);
219 /* checks if packet all right */
221 errx(5, "Zero segsize");
223 /* check sg_size and hwsize */
224 if (hw_size > sg_size - RTE_SZE2_PACKET_HEADER_SIZE) {
225 errx(10, "Hwsize bigger than expected. Segsize: %d, "
226 "hwsize: %d", sg_size, hw_size);
230 RTE_SZE2_ALIGN8(RTE_SZE2_PACKET_HEADER_SIZE + hw_size) -
231 RTE_SZE2_PACKET_HEADER_SIZE;
233 if (sze->ct_rx_rem_bytes >=
235 RTE_SZE2_PACKET_HEADER_SIZE)) {
237 /* one packet ready - go to another */
238 packet_ptr1 = sze->ct_rx_cur_ptr + hw_data_align;
239 packet_len1 = packet_size;
243 sze->ct_rx_cur_ptr += RTE_SZE2_ALIGN8(sg_size) -
244 RTE_SZE2_PACKET_HEADER_SIZE;
245 sze->ct_rx_rem_bytes -= RTE_SZE2_ALIGN8(sg_size) -
246 RTE_SZE2_PACKET_HEADER_SIZE;
249 if (sze->ct_rx_lck->next == NULL) {
250 errx(6, "Need \"next\" lock, "
251 "but it is missing: %u",
252 sze->ct_rx_rem_bytes);
256 if (sze->ct_rx_rem_bytes <= hw_data_align) {
257 uint16_t rem_size = hw_data_align -
258 sze->ct_rx_rem_bytes;
260 /* MOVE to next lock */
261 sze->ct_rx_lck = sze->ct_rx_lck->next;
263 (void *)(((uint8_t *)
264 (sze->ct_rx_lck->start)) + rem_size);
266 packet_ptr1 = sze->ct_rx_cur_ptr;
267 packet_len1 = packet_size;
271 sze->ct_rx_cur_ptr +=
272 RTE_SZE2_ALIGN8(packet_size);
273 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len -
274 rem_size - RTE_SZE2_ALIGN8(packet_size);
276 /* get pointer and length from first part */
277 packet_ptr1 = sze->ct_rx_cur_ptr +
279 packet_len1 = sze->ct_rx_rem_bytes -
282 /* MOVE to next lock */
283 sze->ct_rx_lck = sze->ct_rx_lck->next;
284 sze->ct_rx_cur_ptr = sze->ct_rx_lck->start;
286 /* get pointer and length from second part */
287 packet_ptr2 = sze->ct_rx_cur_ptr;
288 packet_len2 = packet_size - packet_len1;
290 sze->ct_rx_cur_ptr +=
291 RTE_SZE2_ALIGN8(packet_size) -
293 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len -
294 (RTE_SZE2_ALIGN8(packet_size) -
299 if (unlikely(packet_ptr1 == NULL)) {
300 rte_pktmbuf_free(mbuf);
304 /* get the space available for data in the mbuf */
305 mbp_priv = rte_mempool_get_priv(sze_q->mb_pool);
306 buf_size = (uint16_t)(mbp_priv->mbuf_data_room_size -
307 RTE_PKTMBUF_HEADROOM);
309 if (packet_size <= buf_size) {
310 /* sze packet will fit in one mbuf, go ahead and copy */
311 rte_memcpy(rte_pktmbuf_mtod(mbuf, void *),
312 packet_ptr1, packet_len1);
313 if (packet_ptr2 != NULL) {
314 rte_memcpy((void *)(rte_pktmbuf_mtod(mbuf,
315 uint8_t *) + packet_len1),
316 packet_ptr2, packet_len2);
318 mbuf->data_len = (uint16_t)packet_size;
320 mbuf->pkt_len = packet_size;
321 mbuf->port = sze_q->in_port;
324 num_bytes += packet_size;
327 * sze packet will not fit in one mbuf,
328 * scattered mode is not enabled, drop packet
331 "SZE segment %d bytes will not fit in one mbuf "
332 "(%d bytes), scattered mode is not enabled, "
334 packet_size, buf_size);
335 rte_pktmbuf_free(mbuf);
339 sze_q->rx_pkts += num_rx;
340 sze_q->rx_bytes += num_bytes;
345 eth_szedata2_rx_scattered(void *queue,
346 struct rte_mbuf **bufs,
350 struct rte_mbuf *mbuf;
351 struct szedata2_rx_queue *sze_q = queue;
352 struct rte_pktmbuf_pool_private *mbp_priv;
357 uint16_t packet_size;
358 uint64_t num_bytes = 0;
359 struct szedata *sze = sze_q->sze;
360 uint8_t *header_ptr = NULL; /* header of packet */
361 uint8_t *packet_ptr1 = NULL;
362 uint8_t *packet_ptr2 = NULL;
363 uint16_t packet_len1 = 0;
364 uint16_t packet_len2 = 0;
365 uint16_t hw_data_align;
366 uint64_t *mbuf_failed_ptr =
367 &sze_q->priv->dev->data->rx_mbuf_alloc_failed;
369 if (unlikely(sze_q->sze == NULL || nb_pkts == 0))
373 * Reads the given number of packets from szedata2 channel given
374 * by queue and copies the packet data into a newly allocated mbuf
377 for (i = 0; i < nb_pkts; i++) {
378 const struct szedata_lock *ct_rx_lck_backup;
379 unsigned int ct_rx_rem_bytes_backup;
380 unsigned char *ct_rx_cur_ptr_backup;
382 /* get the next sze packet */
383 if (sze->ct_rx_lck != NULL && !sze->ct_rx_rem_bytes &&
384 sze->ct_rx_lck->next == NULL) {
385 /* unlock old data */
386 szedata_rx_unlock_data(sze_q->sze, sze->ct_rx_lck_orig);
387 sze->ct_rx_lck_orig = NULL;
388 sze->ct_rx_lck = NULL;
392 * Store items from sze structure which can be changed
393 * before mbuf allocating. Use these items in case of mbuf
394 * allocating failure.
396 ct_rx_lck_backup = sze->ct_rx_lck;
397 ct_rx_rem_bytes_backup = sze->ct_rx_rem_bytes;
398 ct_rx_cur_ptr_backup = sze->ct_rx_cur_ptr;
400 if (!sze->ct_rx_rem_bytes && sze->ct_rx_lck_orig == NULL) {
401 /* nothing to read, lock new data */
402 sze->ct_rx_lck = szedata_rx_lock_data(sze_q->sze, ~0U);
403 sze->ct_rx_lck_orig = sze->ct_rx_lck;
406 * Backup items from sze structure must be updated
407 * after locking to contain pointers to new locks.
409 ct_rx_lck_backup = sze->ct_rx_lck;
410 ct_rx_rem_bytes_backup = sze->ct_rx_rem_bytes;
411 ct_rx_cur_ptr_backup = sze->ct_rx_cur_ptr;
413 if (sze->ct_rx_lck == NULL)
414 /* nothing to lock */
417 sze->ct_rx_cur_ptr = sze->ct_rx_lck->start;
418 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len;
420 if (!sze->ct_rx_rem_bytes)
424 if (sze->ct_rx_rem_bytes < RTE_SZE2_PACKET_HEADER_SIZE) {
426 * cut in header - copy parts of header to merge buffer
428 if (sze->ct_rx_lck->next == NULL)
431 /* copy first part of header */
432 rte_memcpy(sze->ct_rx_buffer, sze->ct_rx_cur_ptr,
433 sze->ct_rx_rem_bytes);
435 /* copy second part of header */
436 sze->ct_rx_lck = sze->ct_rx_lck->next;
437 sze->ct_rx_cur_ptr = sze->ct_rx_lck->start;
438 rte_memcpy(sze->ct_rx_buffer + sze->ct_rx_rem_bytes,
440 RTE_SZE2_PACKET_HEADER_SIZE -
441 sze->ct_rx_rem_bytes);
443 sze->ct_rx_cur_ptr += RTE_SZE2_PACKET_HEADER_SIZE -
444 sze->ct_rx_rem_bytes;
445 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len -
446 RTE_SZE2_PACKET_HEADER_SIZE +
447 sze->ct_rx_rem_bytes;
449 header_ptr = (uint8_t *)sze->ct_rx_buffer;
452 header_ptr = (uint8_t *)sze->ct_rx_cur_ptr;
453 sze->ct_rx_cur_ptr += RTE_SZE2_PACKET_HEADER_SIZE;
454 sze->ct_rx_rem_bytes -= RTE_SZE2_PACKET_HEADER_SIZE;
457 sg_size = le16toh(*((uint16_t *)header_ptr));
458 hw_size = le16toh(*(((uint16_t *)header_ptr) + 1));
459 packet_size = sg_size -
460 RTE_SZE2_ALIGN8(RTE_SZE2_PACKET_HEADER_SIZE + hw_size);
463 /* checks if packet all right */
465 errx(5, "Zero segsize");
467 /* check sg_size and hwsize */
468 if (hw_size > sg_size - RTE_SZE2_PACKET_HEADER_SIZE) {
469 errx(10, "Hwsize bigger than expected. Segsize: %d, "
470 "hwsize: %d", sg_size, hw_size);
474 RTE_SZE2_ALIGN8((RTE_SZE2_PACKET_HEADER_SIZE +
475 hw_size)) - RTE_SZE2_PACKET_HEADER_SIZE;
477 if (sze->ct_rx_rem_bytes >=
479 RTE_SZE2_PACKET_HEADER_SIZE)) {
481 /* one packet ready - go to another */
482 packet_ptr1 = sze->ct_rx_cur_ptr + hw_data_align;
483 packet_len1 = packet_size;
487 sze->ct_rx_cur_ptr += RTE_SZE2_ALIGN8(sg_size) -
488 RTE_SZE2_PACKET_HEADER_SIZE;
489 sze->ct_rx_rem_bytes -= RTE_SZE2_ALIGN8(sg_size) -
490 RTE_SZE2_PACKET_HEADER_SIZE;
493 if (sze->ct_rx_lck->next == NULL) {
494 errx(6, "Need \"next\" lock, but it is "
495 "missing: %u", sze->ct_rx_rem_bytes);
499 if (sze->ct_rx_rem_bytes <= hw_data_align) {
500 uint16_t rem_size = hw_data_align -
501 sze->ct_rx_rem_bytes;
503 /* MOVE to next lock */
504 sze->ct_rx_lck = sze->ct_rx_lck->next;
506 (void *)(((uint8_t *)
507 (sze->ct_rx_lck->start)) + rem_size);
509 packet_ptr1 = sze->ct_rx_cur_ptr;
510 packet_len1 = packet_size;
514 sze->ct_rx_cur_ptr +=
515 RTE_SZE2_ALIGN8(packet_size);
516 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len -
517 rem_size - RTE_SZE2_ALIGN8(packet_size);
519 /* get pointer and length from first part */
520 packet_ptr1 = sze->ct_rx_cur_ptr +
522 packet_len1 = sze->ct_rx_rem_bytes -
525 /* MOVE to next lock */
526 sze->ct_rx_lck = sze->ct_rx_lck->next;
527 sze->ct_rx_cur_ptr = sze->ct_rx_lck->start;
529 /* get pointer and length from second part */
530 packet_ptr2 = sze->ct_rx_cur_ptr;
531 packet_len2 = packet_size - packet_len1;
533 sze->ct_rx_cur_ptr +=
534 RTE_SZE2_ALIGN8(packet_size) -
536 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len -
537 (RTE_SZE2_ALIGN8(packet_size) -
542 if (unlikely(packet_ptr1 == NULL))
545 mbuf = rte_pktmbuf_alloc(sze_q->mb_pool);
547 if (unlikely(mbuf == NULL)) {
549 * Restore items from sze structure to state after
550 * unlocking (eventually locking).
552 sze->ct_rx_lck = ct_rx_lck_backup;
553 sze->ct_rx_rem_bytes = ct_rx_rem_bytes_backup;
554 sze->ct_rx_cur_ptr = ct_rx_cur_ptr_backup;
555 sze_q->priv->dev->data->rx_mbuf_alloc_failed++;
559 /* get the space available for data in the mbuf */
560 mbp_priv = rte_mempool_get_priv(sze_q->mb_pool);
561 buf_size = (uint16_t)(mbp_priv->mbuf_data_room_size -
562 RTE_PKTMBUF_HEADROOM);
564 if (packet_size <= buf_size) {
565 /* sze packet will fit in one mbuf, go ahead and copy */
566 rte_memcpy(rte_pktmbuf_mtod(mbuf, void *),
567 packet_ptr1, packet_len1);
568 if (packet_ptr2 != NULL) {
570 (rte_pktmbuf_mtod(mbuf, uint8_t *) +
571 packet_len1), packet_ptr2, packet_len2);
573 mbuf->data_len = (uint16_t)packet_size;
576 * sze packet will not fit in one mbuf,
577 * scatter packet into more mbufs
579 struct rte_mbuf *m = mbuf;
580 uint16_t len = rte_pktmbuf_tailroom(mbuf);
582 /* copy first part of packet */
583 /* fill first mbuf */
584 rte_memcpy(rte_pktmbuf_append(mbuf, len), packet_ptr1,
587 packet_ptr1 = ((uint8_t *)packet_ptr1) + len;
589 while (packet_len1 > 0) {
591 m->next = rte_pktmbuf_alloc(sze_q->mb_pool);
593 if (unlikely(m->next == NULL)) {
594 rte_pktmbuf_free(mbuf);
596 * Restore items from sze structure
597 * to state after unlocking (eventually
600 sze->ct_rx_lck = ct_rx_lck_backup;
601 sze->ct_rx_rem_bytes =
602 ct_rx_rem_bytes_backup;
604 ct_rx_cur_ptr_backup;
605 (*mbuf_failed_ptr)++;
611 len = RTE_MIN(rte_pktmbuf_tailroom(m),
613 rte_memcpy(rte_pktmbuf_append(mbuf, len),
618 packet_ptr1 = ((uint8_t *)packet_ptr1) + len;
621 if (packet_ptr2 != NULL) {
622 /* copy second part of packet, if exists */
623 /* fill the rest of currently last mbuf */
624 len = rte_pktmbuf_tailroom(m);
625 rte_memcpy(rte_pktmbuf_append(mbuf, len),
628 packet_ptr2 = ((uint8_t *)packet_ptr2) + len;
630 while (packet_len2 > 0) {
632 m->next = rte_pktmbuf_alloc(
635 if (unlikely(m->next == NULL)) {
636 rte_pktmbuf_free(mbuf);
638 * Restore items from sze
639 * structure to state after
640 * unlocking (eventually
645 sze->ct_rx_rem_bytes =
646 ct_rx_rem_bytes_backup;
648 ct_rx_cur_ptr_backup;
649 (*mbuf_failed_ptr)++;
655 len = RTE_MIN(rte_pktmbuf_tailroom(m),
658 rte_pktmbuf_append(mbuf, len),
663 packet_ptr2 = ((uint8_t *)packet_ptr2) +
668 mbuf->pkt_len = packet_size;
669 mbuf->port = sze_q->in_port;
672 num_bytes += packet_size;
676 sze_q->rx_pkts += num_rx;
677 sze_q->rx_bytes += num_bytes;
682 eth_szedata2_tx(void *queue,
683 struct rte_mbuf **bufs,
686 struct rte_mbuf *mbuf;
687 struct szedata2_tx_queue *sze_q = queue;
689 uint64_t num_bytes = 0;
691 const struct szedata_lock *lck;
697 uint32_t unlock_size;
700 uint16_t pkt_left = nb_pkts;
702 if (sze_q->sze == NULL || nb_pkts == 0)
705 while (pkt_left > 0) {
707 lck = szedata_tx_lock_data(sze_q->sze,
708 RTE_ETH_SZEDATA2_TX_LOCK_SIZE,
714 lock_size = lck->len;
715 lock_size2 = lck->next ? lck->next->len : 0;
718 mbuf = bufs[nb_pkts - pkt_left];
720 pkt_len = mbuf->pkt_len;
721 mbuf_segs = mbuf->nb_segs;
723 hwpkt_len = RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED +
724 RTE_SZE2_ALIGN8(pkt_len);
726 if (lock_size + lock_size2 < hwpkt_len) {
727 szedata_tx_unlock_data(sze_q->sze, lck, unlock_size);
731 num_bytes += pkt_len;
733 if (lock_size > hwpkt_len) {
738 /* write packet length at first 2 bytes in 8B header */
739 *((uint16_t *)dst) = htole16(
740 RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED +
742 *(((uint16_t *)dst) + 1) = htole16(0);
744 /* copy packet from mbuf */
745 tmp_dst = ((uint8_t *)(dst)) +
746 RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED;
747 if (mbuf_segs == 1) {
749 * non-scattered packet,
750 * transmit from one mbuf
753 rte_pktmbuf_mtod(mbuf, const void *),
756 /* scattered packet, transmit from more mbufs */
757 struct rte_mbuf *m = mbuf;
763 tmp_dst = ((uint8_t *)(tmp_dst)) +
770 dst = ((uint8_t *)dst) + hwpkt_len;
771 unlock_size += hwpkt_len;
772 lock_size -= hwpkt_len;
774 rte_pktmbuf_free(mbuf);
778 szedata_tx_unlock_data(sze_q->sze, lck,
783 } else if (lock_size + lock_size2 >= hwpkt_len) {
787 /* write packet length at first 2 bytes in 8B header */
789 htole16(RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED +
791 *(((uint16_t *)dst) + 1) = htole16(0);
794 * If the raw packet (pkt_len) is smaller than lock_size
795 * get the correct length for memcpy
798 pkt_len < lock_size -
799 RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED ?
801 lock_size - RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED;
803 rem_len = hwpkt_len - lock_size;
805 tmp_dst = ((uint8_t *)(dst)) +
806 RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED;
807 if (mbuf_segs == 1) {
809 * non-scattered packet,
810 * transmit from one mbuf
812 /* copy part of packet to first area */
814 rte_pktmbuf_mtod(mbuf, const void *),
818 dst = lck->next->start;
820 /* copy part of packet to second area */
822 (const void *)(rte_pktmbuf_mtod(mbuf,
824 write_len), pkt_len - write_len);
826 /* scattered packet, transmit from more mbufs */
827 struct rte_mbuf *m = mbuf;
828 uint16_t written = 0;
829 uint16_t to_write = 0;
830 bool new_mbuf = true;
831 uint16_t write_off = 0;
833 /* copy part of packet to first area */
834 while (m && written < write_len) {
835 to_write = RTE_MIN(m->data_len,
836 write_len - written);
842 tmp_dst = ((uint8_t *)(tmp_dst)) +
844 if (m->data_len <= write_len -
855 dst = lck->next->start;
859 write_off = new_mbuf ? 0 : to_write;
861 /* copy part of packet to second area */
862 while (m && written < pkt_len - write_len) {
863 rte_memcpy(tmp_dst, (const void *)
865 uint8_t *) + write_off),
866 m->data_len - write_off);
868 tmp_dst = ((uint8_t *)(tmp_dst)) +
869 (m->data_len - write_off);
870 written += m->data_len - write_off;
876 dst = ((uint8_t *)dst) + rem_len;
877 unlock_size += hwpkt_len;
878 lock_size = lock_size2 - rem_len;
881 rte_pktmbuf_free(mbuf);
885 szedata_tx_unlock_data(sze_q->sze, lck, unlock_size);
889 sze_q->tx_pkts += num_tx;
890 sze_q->err_pkts += nb_pkts - num_tx;
891 sze_q->tx_bytes += num_bytes;
896 eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rxq_id)
898 struct szedata2_rx_queue *rxq = dev->data->rx_queues[rxq_id];
900 struct pmd_internals *internals = (struct pmd_internals *)
901 dev->data->dev_private;
903 if (rxq->sze == NULL) {
904 uint32_t rx = 1 << rxq->rx_channel;
906 rxq->sze = szedata_open(internals->sze_dev_path);
907 if (rxq->sze == NULL)
909 ret = szedata_subscribe3(rxq->sze, &rx, &tx);
910 if (ret != 0 || rx == 0)
914 ret = szedata_start(rxq->sze);
917 dev->data->rx_queue_state[rxq_id] = RTE_ETH_QUEUE_STATE_STARTED;
921 szedata_close(rxq->sze);
927 eth_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rxq_id)
929 struct szedata2_rx_queue *rxq = dev->data->rx_queues[rxq_id];
931 if (rxq->sze != NULL) {
932 szedata_close(rxq->sze);
936 dev->data->rx_queue_state[rxq_id] = RTE_ETH_QUEUE_STATE_STOPPED;
941 eth_tx_queue_start(struct rte_eth_dev *dev, uint16_t txq_id)
943 struct szedata2_tx_queue *txq = dev->data->tx_queues[txq_id];
945 struct pmd_internals *internals = (struct pmd_internals *)
946 dev->data->dev_private;
948 if (txq->sze == NULL) {
950 uint32_t tx = 1 << txq->tx_channel;
951 txq->sze = szedata_open(internals->sze_dev_path);
952 if (txq->sze == NULL)
954 ret = szedata_subscribe3(txq->sze, &rx, &tx);
955 if (ret != 0 || tx == 0)
959 ret = szedata_start(txq->sze);
962 dev->data->tx_queue_state[txq_id] = RTE_ETH_QUEUE_STATE_STARTED;
966 szedata_close(txq->sze);
972 eth_tx_queue_stop(struct rte_eth_dev *dev, uint16_t txq_id)
974 struct szedata2_tx_queue *txq = dev->data->tx_queues[txq_id];
976 if (txq->sze != NULL) {
977 szedata_close(txq->sze);
981 dev->data->tx_queue_state[txq_id] = RTE_ETH_QUEUE_STATE_STOPPED;
986 eth_dev_start(struct rte_eth_dev *dev)
990 uint16_t nb_rx = dev->data->nb_rx_queues;
991 uint16_t nb_tx = dev->data->nb_tx_queues;
993 for (i = 0; i < nb_rx; i++) {
994 ret = eth_rx_queue_start(dev, i);
999 for (i = 0; i < nb_tx; i++) {
1000 ret = eth_tx_queue_start(dev, i);
1008 for (i = 0; i < nb_tx; i++)
1009 eth_tx_queue_stop(dev, i);
1011 for (i = 0; i < nb_rx; i++)
1012 eth_rx_queue_stop(dev, i);
1017 eth_dev_stop(struct rte_eth_dev *dev)
1020 uint16_t nb_rx = dev->data->nb_rx_queues;
1021 uint16_t nb_tx = dev->data->nb_tx_queues;
1023 for (i = 0; i < nb_tx; i++)
1024 eth_tx_queue_stop(dev, i);
1026 for (i = 0; i < nb_rx; i++)
1027 eth_rx_queue_stop(dev, i);
1031 eth_dev_configure(struct rte_eth_dev *dev)
1033 struct rte_eth_dev_data *data = dev->data;
1034 if (data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_SCATTER) {
1035 dev->rx_pkt_burst = eth_szedata2_rx_scattered;
1036 data->scattered_rx = 1;
1038 dev->rx_pkt_burst = eth_szedata2_rx;
1039 data->scattered_rx = 0;
1045 eth_dev_info(struct rte_eth_dev *dev,
1046 struct rte_eth_dev_info *dev_info)
1048 struct pmd_internals *internals = dev->data->dev_private;
1050 dev_info->if_index = 0;
1051 dev_info->max_mac_addrs = 1;
1052 dev_info->max_rx_pktlen = (uint32_t)-1;
1053 dev_info->max_rx_queues = internals->max_rx_queues;
1054 dev_info->max_tx_queues = internals->max_tx_queues;
1055 dev_info->min_rx_bufsize = 0;
1056 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_SCATTER;
1057 dev_info->tx_offload_capa = 0;
1058 dev_info->rx_queue_offload_capa = 0;
1059 dev_info->tx_queue_offload_capa = 0;
1060 dev_info->speed_capa = ETH_LINK_SPEED_100G;
1066 eth_stats_get(struct rte_eth_dev *dev,
1067 struct rte_eth_stats *stats)
1070 uint16_t nb_rx = dev->data->nb_rx_queues;
1071 uint16_t nb_tx = dev->data->nb_tx_queues;
1072 uint64_t rx_total = 0;
1073 uint64_t tx_total = 0;
1074 uint64_t tx_err_total = 0;
1075 uint64_t rx_total_bytes = 0;
1076 uint64_t tx_total_bytes = 0;
1078 for (i = 0; i < nb_rx; i++) {
1079 struct szedata2_rx_queue *rxq = dev->data->rx_queues[i];
1081 if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1082 stats->q_ipackets[i] = rxq->rx_pkts;
1083 stats->q_ibytes[i] = rxq->rx_bytes;
1085 rx_total += rxq->rx_pkts;
1086 rx_total_bytes += rxq->rx_bytes;
1089 for (i = 0; i < nb_tx; i++) {
1090 struct szedata2_tx_queue *txq = dev->data->tx_queues[i];
1092 if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1093 stats->q_opackets[i] = txq->tx_pkts;
1094 stats->q_obytes[i] = txq->tx_bytes;
1096 tx_total += txq->tx_pkts;
1097 tx_total_bytes += txq->tx_bytes;
1098 tx_err_total += txq->err_pkts;
1101 stats->ipackets = rx_total;
1102 stats->opackets = tx_total;
1103 stats->ibytes = rx_total_bytes;
1104 stats->obytes = tx_total_bytes;
1105 stats->oerrors = tx_err_total;
1106 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1112 eth_stats_reset(struct rte_eth_dev *dev)
1115 uint16_t nb_rx = dev->data->nb_rx_queues;
1116 uint16_t nb_tx = dev->data->nb_tx_queues;
1118 for (i = 0; i < nb_rx; i++) {
1119 struct szedata2_rx_queue *rxq = dev->data->rx_queues[i];
1124 for (i = 0; i < nb_tx; i++) {
1125 struct szedata2_tx_queue *txq = dev->data->tx_queues[i];
1135 eth_rx_queue_release(void *q)
1137 struct szedata2_rx_queue *rxq = (struct szedata2_rx_queue *)q;
1140 if (rxq->sze != NULL)
1141 szedata_close(rxq->sze);
1147 eth_tx_queue_release(void *q)
1149 struct szedata2_tx_queue *txq = (struct szedata2_tx_queue *)q;
1152 if (txq->sze != NULL)
1153 szedata_close(txq->sze);
1159 eth_dev_close(struct rte_eth_dev *dev)
1161 struct pmd_internals *internals = dev->data->dev_private;
1163 uint16_t nb_rx = dev->data->nb_rx_queues;
1164 uint16_t nb_tx = dev->data->nb_tx_queues;
1168 free(internals->sze_dev_path);
1170 for (i = 0; i < nb_rx; i++) {
1171 eth_rx_queue_release(dev->data->rx_queues[i]);
1172 dev->data->rx_queues[i] = NULL;
1174 dev->data->nb_rx_queues = 0;
1175 for (i = 0; i < nb_tx; i++) {
1176 eth_tx_queue_release(dev->data->tx_queues[i]);
1177 dev->data->tx_queues[i] = NULL;
1179 dev->data->nb_tx_queues = 0;
1181 rte_free(dev->data->mac_addrs);
1182 dev->data->mac_addrs = NULL;
1186 eth_link_update(struct rte_eth_dev *dev,
1187 int wait_to_complete __rte_unused)
1189 struct rte_eth_link link;
1191 memset(&link, 0, sizeof(link));
1193 link.link_speed = ETH_SPEED_NUM_100G;
1194 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1195 link.link_status = ETH_LINK_UP;
1196 link.link_autoneg = ETH_LINK_FIXED;
1198 rte_eth_linkstatus_set(dev, &link);
1203 eth_dev_set_link_up(struct rte_eth_dev *dev __rte_unused)
1205 PMD_DRV_LOG(WARNING, "Setting link up is not supported.");
1210 eth_dev_set_link_down(struct rte_eth_dev *dev __rte_unused)
1212 PMD_DRV_LOG(WARNING, "Setting link down is not supported.");
1217 eth_rx_queue_setup(struct rte_eth_dev *dev,
1218 uint16_t rx_queue_id,
1219 uint16_t nb_rx_desc __rte_unused,
1220 unsigned int socket_id,
1221 const struct rte_eth_rxconf *rx_conf __rte_unused,
1222 struct rte_mempool *mb_pool)
1224 struct szedata2_rx_queue *rxq;
1226 struct pmd_internals *internals = dev->data->dev_private;
1227 uint8_t rx_channel = internals->rxq_base_id + rx_queue_id;
1228 uint32_t rx = 1 << rx_channel;
1231 PMD_INIT_FUNC_TRACE();
1233 if (dev->data->rx_queues[rx_queue_id] != NULL) {
1234 eth_rx_queue_release(dev->data->rx_queues[rx_queue_id]);
1235 dev->data->rx_queues[rx_queue_id] = NULL;
1238 rxq = rte_zmalloc_socket("szedata2 rx queue",
1239 sizeof(struct szedata2_rx_queue),
1240 RTE_CACHE_LINE_SIZE, socket_id);
1242 PMD_INIT_LOG(ERR, "rte_zmalloc_socket() failed for rx queue id "
1243 "%" PRIu16 "!", rx_queue_id);
1247 rxq->priv = internals;
1248 rxq->sze = szedata_open(internals->sze_dev_path);
1249 if (rxq->sze == NULL) {
1250 PMD_INIT_LOG(ERR, "szedata_open() failed for rx queue id "
1251 "%" PRIu16 "!", rx_queue_id);
1252 eth_rx_queue_release(rxq);
1255 ret = szedata_subscribe3(rxq->sze, &rx, &tx);
1256 if (ret != 0 || rx == 0) {
1257 PMD_INIT_LOG(ERR, "szedata_subscribe3() failed for rx queue id "
1258 "%" PRIu16 "!", rx_queue_id);
1259 eth_rx_queue_release(rxq);
1262 rxq->rx_channel = rx_channel;
1263 rxq->qid = rx_queue_id;
1264 rxq->in_port = dev->data->port_id;
1265 rxq->mb_pool = mb_pool;
1270 dev->data->rx_queues[rx_queue_id] = rxq;
1272 PMD_INIT_LOG(DEBUG, "Configured rx queue id %" PRIu16 " on socket "
1273 "%u (channel id %u).", rxq->qid, socket_id,
1280 eth_tx_queue_setup(struct rte_eth_dev *dev,
1281 uint16_t tx_queue_id,
1282 uint16_t nb_tx_desc __rte_unused,
1283 unsigned int socket_id,
1284 const struct rte_eth_txconf *tx_conf __rte_unused)
1286 struct szedata2_tx_queue *txq;
1288 struct pmd_internals *internals = dev->data->dev_private;
1289 uint8_t tx_channel = internals->txq_base_id + tx_queue_id;
1291 uint32_t tx = 1 << tx_channel;
1293 PMD_INIT_FUNC_TRACE();
1295 if (dev->data->tx_queues[tx_queue_id] != NULL) {
1296 eth_tx_queue_release(dev->data->tx_queues[tx_queue_id]);
1297 dev->data->tx_queues[tx_queue_id] = NULL;
1300 txq = rte_zmalloc_socket("szedata2 tx queue",
1301 sizeof(struct szedata2_tx_queue),
1302 RTE_CACHE_LINE_SIZE, socket_id);
1304 PMD_INIT_LOG(ERR, "rte_zmalloc_socket() failed for tx queue id "
1305 "%" PRIu16 "!", tx_queue_id);
1309 txq->priv = internals;
1310 txq->sze = szedata_open(internals->sze_dev_path);
1311 if (txq->sze == NULL) {
1312 PMD_INIT_LOG(ERR, "szedata_open() failed for tx queue id "
1313 "%" PRIu16 "!", tx_queue_id);
1314 eth_tx_queue_release(txq);
1317 ret = szedata_subscribe3(txq->sze, &rx, &tx);
1318 if (ret != 0 || tx == 0) {
1319 PMD_INIT_LOG(ERR, "szedata_subscribe3() failed for tx queue id "
1320 "%" PRIu16 "!", tx_queue_id);
1321 eth_tx_queue_release(txq);
1324 txq->tx_channel = tx_channel;
1325 txq->qid = tx_queue_id;
1330 dev->data->tx_queues[tx_queue_id] = txq;
1332 PMD_INIT_LOG(DEBUG, "Configured tx queue id %" PRIu16 " on socket "
1333 "%u (channel id %u).", txq->qid, socket_id,
1340 eth_mac_addr_set(struct rte_eth_dev *dev __rte_unused,
1341 struct rte_ether_addr *mac_addr __rte_unused)
1347 eth_promiscuous_enable(struct rte_eth_dev *dev __rte_unused)
1349 PMD_DRV_LOG(WARNING, "Enabling promiscuous mode is not supported. "
1350 "The card is always in promiscuous mode.");
1355 eth_promiscuous_disable(struct rte_eth_dev *dev __rte_unused)
1357 PMD_DRV_LOG(WARNING, "Disabling promiscuous mode is not supported. "
1358 "The card is always in promiscuous mode.");
1363 eth_allmulticast_enable(struct rte_eth_dev *dev __rte_unused)
1365 PMD_DRV_LOG(WARNING, "Enabling allmulticast mode is not supported.");
1370 eth_allmulticast_disable(struct rte_eth_dev *dev __rte_unused)
1372 PMD_DRV_LOG(WARNING, "Disabling allmulticast mode is not supported.");
1376 static const struct eth_dev_ops ops = {
1377 .dev_start = eth_dev_start,
1378 .dev_stop = eth_dev_stop,
1379 .dev_set_link_up = eth_dev_set_link_up,
1380 .dev_set_link_down = eth_dev_set_link_down,
1381 .dev_close = eth_dev_close,
1382 .dev_configure = eth_dev_configure,
1383 .dev_infos_get = eth_dev_info,
1384 .promiscuous_enable = eth_promiscuous_enable,
1385 .promiscuous_disable = eth_promiscuous_disable,
1386 .allmulticast_enable = eth_allmulticast_enable,
1387 .allmulticast_disable = eth_allmulticast_disable,
1388 .rx_queue_start = eth_rx_queue_start,
1389 .rx_queue_stop = eth_rx_queue_stop,
1390 .tx_queue_start = eth_tx_queue_start,
1391 .tx_queue_stop = eth_tx_queue_stop,
1392 .rx_queue_setup = eth_rx_queue_setup,
1393 .tx_queue_setup = eth_tx_queue_setup,
1394 .rx_queue_release = eth_rx_queue_release,
1395 .tx_queue_release = eth_tx_queue_release,
1396 .link_update = eth_link_update,
1397 .stats_get = eth_stats_get,
1398 .stats_reset = eth_stats_reset,
1399 .mac_addr_set = eth_mac_addr_set,
1403 * This function goes through sysfs and looks for an index of szedata2
1404 * device file (/dev/szedataIIX, where X is the index).
1411 get_szedata2_index(const struct rte_pci_addr *pcislot_addr, uint32_t *index)
1414 struct dirent *entry;
1418 char pcislot_path[PATH_MAX];
1424 dir = opendir("/sys/class/combo");
1429 * Iterate through all combosixX directories.
1430 * When the value in /sys/class/combo/combosixX/device/pcislot
1431 * file is the location of the ethernet device dev, "X" is the
1432 * index of the device.
1434 while ((entry = readdir(dir)) != NULL) {
1435 ret = sscanf(entry->d_name, "combosix%u", &tmp_index);
1439 snprintf(pcislot_path, PATH_MAX,
1440 "/sys/class/combo/combosix%u/device/pcislot",
1443 fd = fopen(pcislot_path, "r");
1447 ret = fscanf(fd, "%8" SCNx32 ":%2" SCNx8 ":%2" SCNx8 ".%" SCNx8,
1448 &domain, &bus, &devid, &function);
1453 if (pcislot_addr->domain == domain &&
1454 pcislot_addr->bus == bus &&
1455 pcislot_addr->devid == devid &&
1456 pcislot_addr->function == function) {
1468 * @brief Initializes rte_eth_dev device.
1469 * @param dev Device to initialize.
1470 * @param pi Structure with info about DMA queues.
1471 * @return 0 on success, negative error code on error.
1474 rte_szedata2_eth_dev_init(struct rte_eth_dev *dev, struct port_info *pi)
1477 uint32_t szedata2_index;
1478 char name[PATH_MAX];
1479 struct rte_eth_dev_data *data = dev->data;
1480 struct pmd_internals *internals = (struct pmd_internals *)
1482 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1484 PMD_INIT_FUNC_TRACE();
1486 PMD_INIT_LOG(INFO, "Initializing eth_dev %s (driver %s)", data->name,
1487 RTE_STR(RTE_SZEDATA2_DRIVER_NAME));
1489 /* Let rte_eth_dev_close() release the port resources */
1490 dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
1492 /* Fill internal private structure. */
1493 internals->dev = dev;
1494 /* Get index of szedata2 device file and create path to device file */
1495 ret = get_szedata2_index(&pci_dev->addr, &szedata2_index);
1497 PMD_INIT_LOG(ERR, "Failed to get szedata2 device index!");
1500 snprintf(name, PATH_MAX, SZEDATA2_DEV_PATH_FMT, szedata2_index);
1501 internals->sze_dev_path = strdup(name);
1502 if (internals->sze_dev_path == NULL) {
1503 PMD_INIT_LOG(ERR, "strdup() failed!");
1506 PMD_INIT_LOG(INFO, "SZEDATA2 path: %s", internals->sze_dev_path);
1507 internals->max_rx_queues = pi->rx_count;
1508 internals->max_tx_queues = pi->tx_count;
1509 internals->rxq_base_id = pi->rx_base_id;
1510 internals->txq_base_id = pi->tx_base_id;
1511 PMD_INIT_LOG(INFO, "%u RX DMA channels from id %u",
1512 internals->max_rx_queues, internals->rxq_base_id);
1513 PMD_INIT_LOG(INFO, "%u TX DMA channels from id %u",
1514 internals->max_tx_queues, internals->txq_base_id);
1516 /* Set rx, tx burst functions */
1517 if (data->scattered_rx == 1)
1518 dev->rx_pkt_burst = eth_szedata2_rx_scattered;
1520 dev->rx_pkt_burst = eth_szedata2_rx;
1521 dev->tx_pkt_burst = eth_szedata2_tx;
1523 /* Set function callbacks for Ethernet API */
1524 dev->dev_ops = &ops;
1526 /* Get link state */
1527 eth_link_update(dev, 0);
1529 /* Allocate space for one mac address */
1530 data->mac_addrs = rte_zmalloc(data->name, sizeof(struct rte_ether_addr),
1531 RTE_CACHE_LINE_SIZE);
1532 if (data->mac_addrs == NULL) {
1533 PMD_INIT_LOG(ERR, "Could not alloc space for MAC address!");
1534 free(internals->sze_dev_path);
1538 rte_ether_addr_copy(ð_addr, data->mac_addrs);
1540 PMD_INIT_LOG(INFO, "%s device %s successfully initialized",
1541 RTE_STR(RTE_SZEDATA2_DRIVER_NAME), data->name);
1547 * @brief Unitializes rte_eth_dev device.
1548 * @param dev Device to uninitialize.
1549 * @return 0 on success, negative error code on error.
1552 rte_szedata2_eth_dev_uninit(struct rte_eth_dev *dev)
1554 PMD_INIT_FUNC_TRACE();
1558 PMD_DRV_LOG(INFO, "%s device %s successfully uninitialized",
1559 RTE_STR(RTE_SZEDATA2_DRIVER_NAME), dev->data->name);
1564 static const struct rte_pci_id rte_szedata2_pci_id_table[] = {
1566 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE,
1567 PCI_DEVICE_ID_NETCOPE_COMBO80G)
1570 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE,
1571 PCI_DEVICE_ID_NETCOPE_COMBO100G)
1574 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE,
1575 PCI_DEVICE_ID_NETCOPE_COMBO100G2)
1578 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE,
1579 PCI_DEVICE_ID_NETCOPE_NFB200G2QL)
1582 RTE_PCI_DEVICE(PCI_VENDOR_ID_SILICOM,
1583 PCI_DEVICE_ID_FB2CGG3)
1586 RTE_PCI_DEVICE(PCI_VENDOR_ID_SILICOM,
1587 PCI_DEVICE_ID_FB2CGG3D)
1595 * @brief Gets info about DMA queues for ports.
1596 * @param pci_dev PCI device structure.
1597 * @param port_count Pointer to variable set with number of ports.
1598 * @param pi Pointer to array of structures with info about DMA queues
1600 * @param max_ports Maximum number of ports.
1601 * @return 0 on success, negative error code on error.
1604 get_port_info(struct rte_pci_device *pci_dev, unsigned int *port_count,
1605 struct port_info *pi, unsigned int max_ports)
1607 struct szedata *szedata_temp;
1608 char sze_dev_path[PATH_MAX];
1609 uint32_t szedata2_index;
1611 uint16_t max_rx_queues;
1612 uint16_t max_tx_queues;
1617 memset(pi, 0, max_ports * sizeof(struct port_info));
1620 /* Get index of szedata2 device file and create path to device file */
1621 ret = get_szedata2_index(&pci_dev->addr, &szedata2_index);
1623 PMD_INIT_LOG(ERR, "Failed to get szedata2 device index!");
1626 snprintf(sze_dev_path, PATH_MAX, SZEDATA2_DEV_PATH_FMT, szedata2_index);
1629 * Get number of available DMA RX and TX channels, which is maximum
1630 * number of queues that can be created.
1632 szedata_temp = szedata_open(sze_dev_path);
1633 if (szedata_temp == NULL) {
1634 PMD_INIT_LOG(ERR, "szedata_open(%s) failed", sze_dev_path);
1637 max_rx_queues = szedata_ifaces_available(szedata_temp, SZE2_DIR_RX);
1638 max_tx_queues = szedata_ifaces_available(szedata_temp, SZE2_DIR_TX);
1639 PMD_INIT_LOG(INFO, "Available DMA channels RX: %u TX: %u",
1640 max_rx_queues, max_tx_queues);
1641 if (max_rx_queues > RTE_ETH_SZEDATA2_MAX_RX_QUEUES) {
1642 PMD_INIT_LOG(ERR, "%u RX queues exceeds supported number %u",
1643 max_rx_queues, RTE_ETH_SZEDATA2_MAX_RX_QUEUES);
1644 szedata_close(szedata_temp);
1647 if (max_tx_queues > RTE_ETH_SZEDATA2_MAX_TX_QUEUES) {
1648 PMD_INIT_LOG(ERR, "%u TX queues exceeds supported number %u",
1649 max_tx_queues, RTE_ETH_SZEDATA2_MAX_TX_QUEUES);
1650 szedata_close(szedata_temp);
1654 if (pci_dev->id.device_id == PCI_DEVICE_ID_NETCOPE_NFB200G2QL) {
1656 unsigned int rx_queues = max_rx_queues / max_ports;
1657 unsigned int tx_queues = max_tx_queues / max_ports;
1660 * Number of queues reported by szedata_ifaces_available()
1661 * is the number of all queues from all DMA controllers which
1662 * may reside at different numa locations.
1663 * All queues from the same DMA controller have the same numa
1665 * Numa node from the first queue of each DMA controller is
1667 * If the numa node differs from the numa node of the queues
1668 * from the previous DMA controller the queues are assigned
1672 for (i = 0; i < max_ports; i++) {
1673 int numa_rx = szedata_get_area_numa_node(szedata_temp,
1674 SZE2_DIR_RX, rx_queues * i);
1675 int numa_tx = szedata_get_area_numa_node(szedata_temp,
1676 SZE2_DIR_TX, tx_queues * i);
1677 unsigned int port_rx_queues = numa_rx != -1 ?
1679 unsigned int port_tx_queues = numa_tx != -1 ?
1681 PMD_INIT_LOG(DEBUG, "%u rx queues from id %u, numa %d",
1682 rx_queues, rx_queues * i, numa_rx);
1683 PMD_INIT_LOG(DEBUG, "%u tx queues from id %u, numa %d",
1684 tx_queues, tx_queues * i, numa_tx);
1686 if (port_rx_queues != 0 && port_tx_queues != 0 &&
1687 numa_rx != numa_tx) {
1688 PMD_INIT_LOG(ERR, "RX queue %u numa %d differs "
1689 "from TX queue %u numa %d "
1691 rx_queues * i, numa_rx,
1692 tx_queues * i, numa_tx);
1693 szedata_close(szedata_temp);
1695 } else if (port_rx_queues == 0 && port_tx_queues == 0) {
1699 unsigned int current = *port_count;
1700 int port_numa = port_rx_queues != 0 ?
1703 for (j = 0; j < *port_count; j++) {
1704 if (pi[j].numa_node ==
1710 if (pi[current].rx_count == 0 &&
1711 pi[current].tx_count == 0) {
1712 pi[current].rx_base_id = rx_queues * i;
1713 pi[current].tx_base_id = tx_queues * i;
1715 } else if ((rx_queues * i !=
1716 pi[current].rx_base_id +
1717 pi[current].rx_count) ||
1719 pi[current].tx_base_id +
1720 pi[current].tx_count)) {
1721 PMD_INIT_LOG(ERR, "Queue ids does not "
1722 "fulfill constraints");
1723 szedata_close(szedata_temp);
1726 pi[current].rx_count += port_rx_queues;
1727 pi[current].tx_count += port_tx_queues;
1728 pi[current].numa_node = port_numa;
1732 pi[0].rx_count = max_rx_queues;
1733 pi[0].tx_count = max_tx_queues;
1734 pi[0].numa_node = pci_dev->device.numa_node;
1738 szedata_close(szedata_temp);
1743 * @brief Allocates rte_eth_dev device.
1744 * @param pci_dev Corresponding PCI device.
1745 * @param numa_node NUMA node on which device is allocated.
1746 * @param port_no Id of rte_eth_device created on PCI device pci_dev.
1747 * @return Pointer to allocated device or NULL on error.
1749 static struct rte_eth_dev *
1750 szedata2_eth_dev_allocate(struct rte_pci_device *pci_dev, int numa_node,
1751 unsigned int port_no)
1753 struct rte_eth_dev *eth_dev;
1754 char name[RTE_ETH_NAME_MAX_LEN];
1756 PMD_INIT_FUNC_TRACE();
1758 snprintf(name, RTE_ETH_NAME_MAX_LEN, "%s"
1759 SZEDATA2_ETH_DEV_NAME_SUFFIX_FMT,
1760 pci_dev->device.name, port_no);
1761 PMD_INIT_LOG(DEBUG, "Allocating eth_dev %s", name);
1763 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1764 eth_dev = rte_eth_dev_allocate(name);
1768 eth_dev->data->dev_private = rte_zmalloc_socket(name,
1769 sizeof(struct pmd_internals), RTE_CACHE_LINE_SIZE,
1771 if (!eth_dev->data->dev_private) {
1772 rte_eth_dev_release_port(eth_dev);
1776 eth_dev = rte_eth_dev_attach_secondary(name);
1781 eth_dev->device = &pci_dev->device;
1782 rte_eth_copy_pci_info(eth_dev, pci_dev);
1783 eth_dev->data->numa_node = numa_node;
1788 * @brief Releases interval of rte_eth_dev devices from array.
1789 * @param eth_devs Array of pointers to rte_eth_dev devices.
1790 * @param from Index in array eth_devs to start with.
1791 * @param to Index in array right after the last element to release.
1793 * Used for releasing at failed initialization.
1796 szedata2_eth_dev_release_interval(struct rte_eth_dev **eth_devs,
1797 unsigned int from, unsigned int to)
1801 PMD_INIT_FUNC_TRACE();
1803 for (i = from; i < to; i++) {
1804 rte_szedata2_eth_dev_uninit(eth_devs[i]);
1805 rte_eth_dev_pci_release(eth_devs[i]);
1810 * @brief Callback .probe for struct rte_pci_driver.
1812 static int szedata2_eth_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1813 struct rte_pci_device *pci_dev)
1815 struct port_info port_info[SZEDATA2_MAX_PORTS];
1816 unsigned int port_count;
1819 struct pci_dev_list_entry *list_entry;
1820 struct rte_eth_dev *eth_devs[SZEDATA2_MAX_PORTS] = {NULL,};
1822 PMD_INIT_FUNC_TRACE();
1824 ret = get_port_info(pci_dev, &port_count, port_info,
1825 SZEDATA2_MAX_PORTS);
1829 if (port_count == 0) {
1830 PMD_INIT_LOG(ERR, "No available ports!");
1834 list_entry = rte_zmalloc(NULL, sizeof(struct pci_dev_list_entry),
1835 RTE_CACHE_LINE_SIZE);
1836 if (list_entry == NULL) {
1837 PMD_INIT_LOG(ERR, "rte_zmalloc() failed!");
1841 for (i = 0; i < port_count; i++) {
1842 eth_devs[i] = szedata2_eth_dev_allocate(pci_dev,
1843 port_info[i].numa_node, i);
1844 if (eth_devs[i] == NULL) {
1845 PMD_INIT_LOG(ERR, "Failed to alloc eth_dev for port %u",
1847 szedata2_eth_dev_release_interval(eth_devs, 0, i);
1848 rte_free(list_entry);
1852 ret = rte_szedata2_eth_dev_init(eth_devs[i], &port_info[i]);
1854 PMD_INIT_LOG(ERR, "Failed to init eth_dev for port %u",
1856 rte_eth_dev_pci_release(eth_devs[i]);
1857 szedata2_eth_dev_release_interval(eth_devs, 0, i);
1858 rte_free(list_entry);
1862 rte_eth_dev_probing_finish(eth_devs[i]);
1866 * Add pci_dev to list of PCI devices for this driver
1867 * which is used at remove callback to release all created eth_devs.
1869 list_entry->pci_dev = pci_dev;
1870 list_entry->port_count = port_count;
1871 LIST_INSERT_HEAD(&szedata2_pci_dev_list, list_entry, next);
1876 * @brief Callback .remove for struct rte_pci_driver.
1878 static int szedata2_eth_pci_remove(struct rte_pci_device *pci_dev)
1881 unsigned int port_count;
1882 char name[RTE_ETH_NAME_MAX_LEN];
1883 struct rte_eth_dev *eth_dev;
1887 struct pci_dev_list_entry *list_entry = NULL;
1889 PMD_INIT_FUNC_TRACE();
1891 LIST_FOREACH(list_entry, &szedata2_pci_dev_list, next) {
1892 if (list_entry->pci_dev == pci_dev) {
1893 port_count = list_entry->port_count;
1898 LIST_REMOVE(list_entry, next);
1899 rte_free(list_entry);
1902 PMD_DRV_LOG(ERR, "PCI device " PCI_PRI_FMT " not found",
1903 pci_dev->addr.domain, pci_dev->addr.bus,
1904 pci_dev->addr.devid, pci_dev->addr.function);
1908 for (i = 0; i < port_count; i++) {
1909 snprintf(name, RTE_ETH_NAME_MAX_LEN, "%s"
1910 SZEDATA2_ETH_DEV_NAME_SUFFIX_FMT,
1911 pci_dev->device.name, i);
1912 PMD_DRV_LOG(DEBUG, "Removing eth_dev %s", name);
1913 eth_dev = rte_eth_dev_allocated(name);
1915 PMD_DRV_LOG(ERR, "eth_dev %s not found", name);
1916 retval = retval ? retval : -ENODEV;
1919 ret = rte_szedata2_eth_dev_uninit(eth_dev);
1921 PMD_DRV_LOG(ERR, "eth_dev %s uninit failed", name);
1922 retval = retval ? retval : ret;
1925 rte_eth_dev_pci_release(eth_dev);
1931 static struct rte_pci_driver szedata2_eth_driver = {
1932 .id_table = rte_szedata2_pci_id_table,
1933 .probe = szedata2_eth_pci_probe,
1934 .remove = szedata2_eth_pci_remove,
1937 RTE_PMD_REGISTER_PCI(RTE_SZEDATA2_DRIVER_NAME, szedata2_eth_driver);
1938 RTE_PMD_REGISTER_PCI_TABLE(RTE_SZEDATA2_DRIVER_NAME, rte_szedata2_pci_id_table);
1939 RTE_PMD_REGISTER_KMOD_DEP(RTE_SZEDATA2_DRIVER_NAME,
1940 "* combo6core & combov3 & szedata2 & ( szedata2_cv3 | szedata2_cv3_fdt )");
1941 RTE_LOG_REGISTER(szedata2_logtype_init, pmd.net.szedata2.init, NOTICE);
1942 RTE_LOG_REGISTER(szedata2_logtype_driver, pmd.net.szedata2.driver, NOTICE);