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;
1188 eth_link_update(struct rte_eth_dev *dev,
1189 int wait_to_complete __rte_unused)
1191 struct rte_eth_link link;
1193 memset(&link, 0, sizeof(link));
1195 link.link_speed = ETH_SPEED_NUM_100G;
1196 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1197 link.link_status = ETH_LINK_UP;
1198 link.link_autoneg = ETH_LINK_FIXED;
1200 rte_eth_linkstatus_set(dev, &link);
1205 eth_dev_set_link_up(struct rte_eth_dev *dev __rte_unused)
1207 PMD_DRV_LOG(WARNING, "Setting link up is not supported.");
1212 eth_dev_set_link_down(struct rte_eth_dev *dev __rte_unused)
1214 PMD_DRV_LOG(WARNING, "Setting link down is not supported.");
1219 eth_rx_queue_setup(struct rte_eth_dev *dev,
1220 uint16_t rx_queue_id,
1221 uint16_t nb_rx_desc __rte_unused,
1222 unsigned int socket_id,
1223 const struct rte_eth_rxconf *rx_conf __rte_unused,
1224 struct rte_mempool *mb_pool)
1226 struct szedata2_rx_queue *rxq;
1228 struct pmd_internals *internals = dev->data->dev_private;
1229 uint8_t rx_channel = internals->rxq_base_id + rx_queue_id;
1230 uint32_t rx = 1 << rx_channel;
1233 PMD_INIT_FUNC_TRACE();
1235 if (dev->data->rx_queues[rx_queue_id] != NULL) {
1236 eth_rx_queue_release(dev->data->rx_queues[rx_queue_id]);
1237 dev->data->rx_queues[rx_queue_id] = NULL;
1240 rxq = rte_zmalloc_socket("szedata2 rx queue",
1241 sizeof(struct szedata2_rx_queue),
1242 RTE_CACHE_LINE_SIZE, socket_id);
1244 PMD_INIT_LOG(ERR, "rte_zmalloc_socket() failed for rx queue id "
1245 "%" PRIu16 "!", rx_queue_id);
1249 rxq->priv = internals;
1250 rxq->sze = szedata_open(internals->sze_dev_path);
1251 if (rxq->sze == NULL) {
1252 PMD_INIT_LOG(ERR, "szedata_open() failed for rx queue id "
1253 "%" PRIu16 "!", rx_queue_id);
1254 eth_rx_queue_release(rxq);
1257 ret = szedata_subscribe3(rxq->sze, &rx, &tx);
1258 if (ret != 0 || rx == 0) {
1259 PMD_INIT_LOG(ERR, "szedata_subscribe3() failed for rx queue id "
1260 "%" PRIu16 "!", rx_queue_id);
1261 eth_rx_queue_release(rxq);
1264 rxq->rx_channel = rx_channel;
1265 rxq->qid = rx_queue_id;
1266 rxq->in_port = dev->data->port_id;
1267 rxq->mb_pool = mb_pool;
1272 dev->data->rx_queues[rx_queue_id] = rxq;
1274 PMD_INIT_LOG(DEBUG, "Configured rx queue id %" PRIu16 " on socket "
1275 "%u (channel id %u).", rxq->qid, socket_id,
1282 eth_tx_queue_setup(struct rte_eth_dev *dev,
1283 uint16_t tx_queue_id,
1284 uint16_t nb_tx_desc __rte_unused,
1285 unsigned int socket_id,
1286 const struct rte_eth_txconf *tx_conf __rte_unused)
1288 struct szedata2_tx_queue *txq;
1290 struct pmd_internals *internals = dev->data->dev_private;
1291 uint8_t tx_channel = internals->txq_base_id + tx_queue_id;
1293 uint32_t tx = 1 << tx_channel;
1295 PMD_INIT_FUNC_TRACE();
1297 if (dev->data->tx_queues[tx_queue_id] != NULL) {
1298 eth_tx_queue_release(dev->data->tx_queues[tx_queue_id]);
1299 dev->data->tx_queues[tx_queue_id] = NULL;
1302 txq = rte_zmalloc_socket("szedata2 tx queue",
1303 sizeof(struct szedata2_tx_queue),
1304 RTE_CACHE_LINE_SIZE, socket_id);
1306 PMD_INIT_LOG(ERR, "rte_zmalloc_socket() failed for tx queue id "
1307 "%" PRIu16 "!", tx_queue_id);
1311 txq->priv = internals;
1312 txq->sze = szedata_open(internals->sze_dev_path);
1313 if (txq->sze == NULL) {
1314 PMD_INIT_LOG(ERR, "szedata_open() failed for tx queue id "
1315 "%" PRIu16 "!", tx_queue_id);
1316 eth_tx_queue_release(txq);
1319 ret = szedata_subscribe3(txq->sze, &rx, &tx);
1320 if (ret != 0 || tx == 0) {
1321 PMD_INIT_LOG(ERR, "szedata_subscribe3() failed for tx queue id "
1322 "%" PRIu16 "!", tx_queue_id);
1323 eth_tx_queue_release(txq);
1326 txq->tx_channel = tx_channel;
1327 txq->qid = tx_queue_id;
1332 dev->data->tx_queues[tx_queue_id] = txq;
1334 PMD_INIT_LOG(DEBUG, "Configured tx queue id %" PRIu16 " on socket "
1335 "%u (channel id %u).", txq->qid, socket_id,
1342 eth_mac_addr_set(struct rte_eth_dev *dev __rte_unused,
1343 struct rte_ether_addr *mac_addr __rte_unused)
1349 eth_promiscuous_enable(struct rte_eth_dev *dev __rte_unused)
1351 PMD_DRV_LOG(WARNING, "Enabling promiscuous mode is not supported. "
1352 "The card is always in promiscuous mode.");
1357 eth_promiscuous_disable(struct rte_eth_dev *dev __rte_unused)
1359 PMD_DRV_LOG(WARNING, "Disabling promiscuous mode is not supported. "
1360 "The card is always in promiscuous mode.");
1365 eth_allmulticast_enable(struct rte_eth_dev *dev __rte_unused)
1367 PMD_DRV_LOG(WARNING, "Enabling allmulticast mode is not supported.");
1372 eth_allmulticast_disable(struct rte_eth_dev *dev __rte_unused)
1374 PMD_DRV_LOG(WARNING, "Disabling allmulticast mode is not supported.");
1378 static const struct eth_dev_ops ops = {
1379 .dev_start = eth_dev_start,
1380 .dev_stop = eth_dev_stop,
1381 .dev_set_link_up = eth_dev_set_link_up,
1382 .dev_set_link_down = eth_dev_set_link_down,
1383 .dev_close = eth_dev_close,
1384 .dev_configure = eth_dev_configure,
1385 .dev_infos_get = eth_dev_info,
1386 .promiscuous_enable = eth_promiscuous_enable,
1387 .promiscuous_disable = eth_promiscuous_disable,
1388 .allmulticast_enable = eth_allmulticast_enable,
1389 .allmulticast_disable = eth_allmulticast_disable,
1390 .rx_queue_start = eth_rx_queue_start,
1391 .rx_queue_stop = eth_rx_queue_stop,
1392 .tx_queue_start = eth_tx_queue_start,
1393 .tx_queue_stop = eth_tx_queue_stop,
1394 .rx_queue_setup = eth_rx_queue_setup,
1395 .tx_queue_setup = eth_tx_queue_setup,
1396 .rx_queue_release = eth_rx_queue_release,
1397 .tx_queue_release = eth_tx_queue_release,
1398 .link_update = eth_link_update,
1399 .stats_get = eth_stats_get,
1400 .stats_reset = eth_stats_reset,
1401 .mac_addr_set = eth_mac_addr_set,
1405 * This function goes through sysfs and looks for an index of szedata2
1406 * device file (/dev/szedataIIX, where X is the index).
1413 get_szedata2_index(const struct rte_pci_addr *pcislot_addr, uint32_t *index)
1416 struct dirent *entry;
1420 char pcislot_path[PATH_MAX];
1426 dir = opendir("/sys/class/combo");
1431 * Iterate through all combosixX directories.
1432 * When the value in /sys/class/combo/combosixX/device/pcislot
1433 * file is the location of the ethernet device dev, "X" is the
1434 * index of the device.
1436 while ((entry = readdir(dir)) != NULL) {
1437 ret = sscanf(entry->d_name, "combosix%u", &tmp_index);
1441 snprintf(pcislot_path, PATH_MAX,
1442 "/sys/class/combo/combosix%u/device/pcislot",
1445 fd = fopen(pcislot_path, "r");
1449 ret = fscanf(fd, "%8" SCNx32 ":%2" SCNx8 ":%2" SCNx8 ".%" SCNx8,
1450 &domain, &bus, &devid, &function);
1455 if (pcislot_addr->domain == domain &&
1456 pcislot_addr->bus == bus &&
1457 pcislot_addr->devid == devid &&
1458 pcislot_addr->function == function) {
1470 * @brief Initializes rte_eth_dev device.
1471 * @param dev Device to initialize.
1472 * @param pi Structure with info about DMA queues.
1473 * @return 0 on success, negative error code on error.
1476 rte_szedata2_eth_dev_init(struct rte_eth_dev *dev, struct port_info *pi)
1479 uint32_t szedata2_index;
1480 char name[PATH_MAX];
1481 struct rte_eth_dev_data *data = dev->data;
1482 struct pmd_internals *internals = (struct pmd_internals *)
1484 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1486 PMD_INIT_FUNC_TRACE();
1488 PMD_INIT_LOG(INFO, "Initializing eth_dev %s (driver %s)", data->name,
1489 RTE_STR(RTE_SZEDATA2_DRIVER_NAME));
1491 /* Fill internal private structure. */
1492 internals->dev = dev;
1493 /* Get index of szedata2 device file and create path to device file */
1494 ret = get_szedata2_index(&pci_dev->addr, &szedata2_index);
1496 PMD_INIT_LOG(ERR, "Failed to get szedata2 device index!");
1499 snprintf(name, PATH_MAX, SZEDATA2_DEV_PATH_FMT, szedata2_index);
1500 internals->sze_dev_path = strdup(name);
1501 if (internals->sze_dev_path == NULL) {
1502 PMD_INIT_LOG(ERR, "strdup() failed!");
1505 PMD_INIT_LOG(INFO, "SZEDATA2 path: %s", internals->sze_dev_path);
1506 internals->max_rx_queues = pi->rx_count;
1507 internals->max_tx_queues = pi->tx_count;
1508 internals->rxq_base_id = pi->rx_base_id;
1509 internals->txq_base_id = pi->tx_base_id;
1510 PMD_INIT_LOG(INFO, "%u RX DMA channels from id %u",
1511 internals->max_rx_queues, internals->rxq_base_id);
1512 PMD_INIT_LOG(INFO, "%u TX DMA channels from id %u",
1513 internals->max_tx_queues, internals->txq_base_id);
1515 /* Set rx, tx burst functions */
1516 if (data->scattered_rx == 1)
1517 dev->rx_pkt_burst = eth_szedata2_rx_scattered;
1519 dev->rx_pkt_burst = eth_szedata2_rx;
1520 dev->tx_pkt_burst = eth_szedata2_tx;
1522 /* Set function callbacks for Ethernet API */
1523 dev->dev_ops = &ops;
1525 /* Get link state */
1526 eth_link_update(dev, 0);
1528 /* Allocate space for one mac address */
1529 data->mac_addrs = rte_zmalloc(data->name, sizeof(struct rte_ether_addr),
1530 RTE_CACHE_LINE_SIZE);
1531 if (data->mac_addrs == NULL) {
1532 PMD_INIT_LOG(ERR, "Could not alloc space for MAC address!");
1533 free(internals->sze_dev_path);
1537 rte_ether_addr_copy(ð_addr, data->mac_addrs);
1539 PMD_INIT_LOG(INFO, "%s device %s successfully initialized",
1540 RTE_STR(RTE_SZEDATA2_DRIVER_NAME), data->name);
1546 * @brief Unitializes rte_eth_dev device.
1547 * @param dev Device to uninitialize.
1548 * @return 0 on success, negative error code on error.
1551 rte_szedata2_eth_dev_uninit(struct rte_eth_dev *dev)
1553 PMD_INIT_FUNC_TRACE();
1557 PMD_DRV_LOG(INFO, "%s device %s successfully uninitialized",
1558 RTE_STR(RTE_SZEDATA2_DRIVER_NAME), dev->data->name);
1563 static const struct rte_pci_id rte_szedata2_pci_id_table[] = {
1565 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE,
1566 PCI_DEVICE_ID_NETCOPE_COMBO80G)
1569 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE,
1570 PCI_DEVICE_ID_NETCOPE_COMBO100G)
1573 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE,
1574 PCI_DEVICE_ID_NETCOPE_COMBO100G2)
1577 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE,
1578 PCI_DEVICE_ID_NETCOPE_NFB200G2QL)
1581 RTE_PCI_DEVICE(PCI_VENDOR_ID_SILICOM,
1582 PCI_DEVICE_ID_FB2CGG3)
1585 RTE_PCI_DEVICE(PCI_VENDOR_ID_SILICOM,
1586 PCI_DEVICE_ID_FB2CGG3D)
1594 * @brief Gets info about DMA queues for ports.
1595 * @param pci_dev PCI device structure.
1596 * @param port_count Pointer to variable set with number of ports.
1597 * @param pi Pointer to array of structures with info about DMA queues
1599 * @param max_ports Maximum number of ports.
1600 * @return 0 on success, negative error code on error.
1603 get_port_info(struct rte_pci_device *pci_dev, unsigned int *port_count,
1604 struct port_info *pi, unsigned int max_ports)
1606 struct szedata *szedata_temp;
1607 char sze_dev_path[PATH_MAX];
1608 uint32_t szedata2_index;
1610 uint16_t max_rx_queues;
1611 uint16_t max_tx_queues;
1616 memset(pi, 0, max_ports * sizeof(struct port_info));
1619 /* Get index of szedata2 device file and create path to device file */
1620 ret = get_szedata2_index(&pci_dev->addr, &szedata2_index);
1622 PMD_INIT_LOG(ERR, "Failed to get szedata2 device index!");
1625 snprintf(sze_dev_path, PATH_MAX, SZEDATA2_DEV_PATH_FMT, szedata2_index);
1628 * Get number of available DMA RX and TX channels, which is maximum
1629 * number of queues that can be created.
1631 szedata_temp = szedata_open(sze_dev_path);
1632 if (szedata_temp == NULL) {
1633 PMD_INIT_LOG(ERR, "szedata_open(%s) failed", sze_dev_path);
1636 max_rx_queues = szedata_ifaces_available(szedata_temp, SZE2_DIR_RX);
1637 max_tx_queues = szedata_ifaces_available(szedata_temp, SZE2_DIR_TX);
1638 PMD_INIT_LOG(INFO, "Available DMA channels RX: %u TX: %u",
1639 max_rx_queues, max_tx_queues);
1640 if (max_rx_queues > RTE_ETH_SZEDATA2_MAX_RX_QUEUES) {
1641 PMD_INIT_LOG(ERR, "%u RX queues exceeds supported number %u",
1642 max_rx_queues, RTE_ETH_SZEDATA2_MAX_RX_QUEUES);
1643 szedata_close(szedata_temp);
1646 if (max_tx_queues > RTE_ETH_SZEDATA2_MAX_TX_QUEUES) {
1647 PMD_INIT_LOG(ERR, "%u TX queues exceeds supported number %u",
1648 max_tx_queues, RTE_ETH_SZEDATA2_MAX_TX_QUEUES);
1649 szedata_close(szedata_temp);
1653 if (pci_dev->id.device_id == PCI_DEVICE_ID_NETCOPE_NFB200G2QL) {
1655 unsigned int rx_queues = max_rx_queues / max_ports;
1656 unsigned int tx_queues = max_tx_queues / max_ports;
1659 * Number of queues reported by szedata_ifaces_available()
1660 * is the number of all queues from all DMA controllers which
1661 * may reside at different numa locations.
1662 * All queues from the same DMA controller have the same numa
1664 * Numa node from the first queue of each DMA controller is
1666 * If the numa node differs from the numa node of the queues
1667 * from the previous DMA controller the queues are assigned
1671 for (i = 0; i < max_ports; i++) {
1672 int numa_rx = szedata_get_area_numa_node(szedata_temp,
1673 SZE2_DIR_RX, rx_queues * i);
1674 int numa_tx = szedata_get_area_numa_node(szedata_temp,
1675 SZE2_DIR_TX, tx_queues * i);
1676 unsigned int port_rx_queues = numa_rx != -1 ?
1678 unsigned int port_tx_queues = numa_tx != -1 ?
1680 PMD_INIT_LOG(DEBUG, "%u rx queues from id %u, numa %d",
1681 rx_queues, rx_queues * i, numa_rx);
1682 PMD_INIT_LOG(DEBUG, "%u tx queues from id %u, numa %d",
1683 tx_queues, tx_queues * i, numa_tx);
1685 if (port_rx_queues != 0 && port_tx_queues != 0 &&
1686 numa_rx != numa_tx) {
1687 PMD_INIT_LOG(ERR, "RX queue %u numa %d differs "
1688 "from TX queue %u numa %d "
1690 rx_queues * i, numa_rx,
1691 tx_queues * i, numa_tx);
1692 szedata_close(szedata_temp);
1694 } else if (port_rx_queues == 0 && port_tx_queues == 0) {
1698 unsigned int current = *port_count;
1699 int port_numa = port_rx_queues != 0 ?
1702 for (j = 0; j < *port_count; j++) {
1703 if (pi[j].numa_node ==
1709 if (pi[current].rx_count == 0 &&
1710 pi[current].tx_count == 0) {
1711 pi[current].rx_base_id = rx_queues * i;
1712 pi[current].tx_base_id = tx_queues * i;
1714 } else if ((rx_queues * i !=
1715 pi[current].rx_base_id +
1716 pi[current].rx_count) ||
1718 pi[current].tx_base_id +
1719 pi[current].tx_count)) {
1720 PMD_INIT_LOG(ERR, "Queue ids does not "
1721 "fulfill constraints");
1722 szedata_close(szedata_temp);
1725 pi[current].rx_count += port_rx_queues;
1726 pi[current].tx_count += port_tx_queues;
1727 pi[current].numa_node = port_numa;
1731 pi[0].rx_count = max_rx_queues;
1732 pi[0].tx_count = max_tx_queues;
1733 pi[0].numa_node = pci_dev->device.numa_node;
1737 szedata_close(szedata_temp);
1742 * @brief Allocates rte_eth_dev device.
1743 * @param pci_dev Corresponding PCI device.
1744 * @param numa_node NUMA node on which device is allocated.
1745 * @param port_no Id of rte_eth_device created on PCI device pci_dev.
1746 * @return Pointer to allocated device or NULL on error.
1748 static struct rte_eth_dev *
1749 szedata2_eth_dev_allocate(struct rte_pci_device *pci_dev, int numa_node,
1750 unsigned int port_no)
1752 struct rte_eth_dev *eth_dev;
1753 char name[RTE_ETH_NAME_MAX_LEN];
1755 PMD_INIT_FUNC_TRACE();
1757 snprintf(name, RTE_ETH_NAME_MAX_LEN, "%s"
1758 SZEDATA2_ETH_DEV_NAME_SUFFIX_FMT,
1759 pci_dev->device.name, port_no);
1760 PMD_INIT_LOG(DEBUG, "Allocating eth_dev %s", name);
1762 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1763 eth_dev = rte_eth_dev_allocate(name);
1767 eth_dev->data->dev_private = rte_zmalloc_socket(name,
1768 sizeof(struct pmd_internals), RTE_CACHE_LINE_SIZE,
1770 if (!eth_dev->data->dev_private) {
1771 rte_eth_dev_release_port(eth_dev);
1775 eth_dev = rte_eth_dev_attach_secondary(name);
1780 eth_dev->device = &pci_dev->device;
1781 rte_eth_copy_pci_info(eth_dev, pci_dev);
1782 eth_dev->data->numa_node = numa_node;
1787 * @brief Releases interval of rte_eth_dev devices from array.
1788 * @param eth_devs Array of pointers to rte_eth_dev devices.
1789 * @param from Index in array eth_devs to start with.
1790 * @param to Index in array right after the last element to release.
1792 * Used for releasing at failed initialization.
1795 szedata2_eth_dev_release_interval(struct rte_eth_dev **eth_devs,
1796 unsigned int from, unsigned int to)
1800 PMD_INIT_FUNC_TRACE();
1802 for (i = from; i < to; i++) {
1803 rte_szedata2_eth_dev_uninit(eth_devs[i]);
1804 rte_eth_dev_release_port(eth_devs[i]);
1809 * @brief Callback .probe for struct rte_pci_driver.
1811 static int szedata2_eth_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1812 struct rte_pci_device *pci_dev)
1814 struct port_info port_info[SZEDATA2_MAX_PORTS];
1815 unsigned int port_count;
1818 struct pci_dev_list_entry *list_entry;
1819 struct rte_eth_dev *eth_devs[SZEDATA2_MAX_PORTS] = {NULL,};
1821 PMD_INIT_FUNC_TRACE();
1823 ret = get_port_info(pci_dev, &port_count, port_info,
1824 SZEDATA2_MAX_PORTS);
1828 if (port_count == 0) {
1829 PMD_INIT_LOG(ERR, "No available ports!");
1833 list_entry = rte_zmalloc(NULL, sizeof(struct pci_dev_list_entry),
1834 RTE_CACHE_LINE_SIZE);
1835 if (list_entry == NULL) {
1836 PMD_INIT_LOG(ERR, "rte_zmalloc() failed!");
1840 for (i = 0; i < port_count; i++) {
1841 eth_devs[i] = szedata2_eth_dev_allocate(pci_dev,
1842 port_info[i].numa_node, i);
1843 if (eth_devs[i] == NULL) {
1844 PMD_INIT_LOG(ERR, "Failed to alloc eth_dev for port %u",
1846 szedata2_eth_dev_release_interval(eth_devs, 0, i);
1847 rte_free(list_entry);
1851 ret = rte_szedata2_eth_dev_init(eth_devs[i], &port_info[i]);
1853 PMD_INIT_LOG(ERR, "Failed to init eth_dev for port %u",
1855 rte_eth_dev_release_port(eth_devs[i]);
1856 szedata2_eth_dev_release_interval(eth_devs, 0, i);
1857 rte_free(list_entry);
1861 rte_eth_dev_probing_finish(eth_devs[i]);
1865 * Add pci_dev to list of PCI devices for this driver
1866 * which is used at remove callback to release all created eth_devs.
1868 list_entry->pci_dev = pci_dev;
1869 list_entry->port_count = port_count;
1870 LIST_INSERT_HEAD(&szedata2_pci_dev_list, list_entry, next);
1875 * @brief Callback .remove for struct rte_pci_driver.
1877 static int szedata2_eth_pci_remove(struct rte_pci_device *pci_dev)
1880 unsigned int port_count;
1881 char name[RTE_ETH_NAME_MAX_LEN];
1882 struct rte_eth_dev *eth_dev;
1886 struct pci_dev_list_entry *list_entry = NULL;
1888 PMD_INIT_FUNC_TRACE();
1890 LIST_FOREACH(list_entry, &szedata2_pci_dev_list, next) {
1891 if (list_entry->pci_dev == pci_dev) {
1892 port_count = list_entry->port_count;
1897 LIST_REMOVE(list_entry, next);
1898 rte_free(list_entry);
1901 PMD_DRV_LOG(ERR, "PCI device " PCI_PRI_FMT " not found",
1902 pci_dev->addr.domain, pci_dev->addr.bus,
1903 pci_dev->addr.devid, pci_dev->addr.function);
1907 for (i = 0; i < port_count; i++) {
1908 snprintf(name, RTE_ETH_NAME_MAX_LEN, "%s"
1909 SZEDATA2_ETH_DEV_NAME_SUFFIX_FMT,
1910 pci_dev->device.name, i);
1911 PMD_DRV_LOG(DEBUG, "Removing eth_dev %s", name);
1912 eth_dev = rte_eth_dev_allocated(name);
1914 PMD_DRV_LOG(ERR, "eth_dev %s not found", name);
1915 retval = retval ? retval : -ENODEV;
1918 ret = rte_szedata2_eth_dev_uninit(eth_dev);
1920 PMD_DRV_LOG(ERR, "eth_dev %s uninit failed", name);
1921 retval = retval ? retval : ret;
1924 rte_eth_dev_release_port(eth_dev);
1930 static struct rte_pci_driver szedata2_eth_driver = {
1931 .id_table = rte_szedata2_pci_id_table,
1932 .probe = szedata2_eth_pci_probe,
1933 .remove = szedata2_eth_pci_remove,
1936 RTE_PMD_REGISTER_PCI(RTE_SZEDATA2_DRIVER_NAME, szedata2_eth_driver);
1937 RTE_PMD_REGISTER_PCI_TABLE(RTE_SZEDATA2_DRIVER_NAME, rte_szedata2_pci_id_table);
1938 RTE_PMD_REGISTER_KMOD_DEP(RTE_SZEDATA2_DRIVER_NAME,
1939 "* combo6core & combov3 & szedata2 & ( szedata2_cv3 | szedata2_cv3_fdt )");
1940 RTE_LOG_REGISTER(szedata2_logtype_init, pmd.net.szedata2.init, NOTICE);
1941 RTE_LOG_REGISTER(szedata2_logtype_driver, pmd.net.szedata2.driver, NOTICE);