4 * Copyright (c) 2015 - 2016 CESNET
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of CESNET nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <sys/types.h>
47 #include <rte_ethdev.h>
48 #include <rte_malloc.h>
49 #include <rte_memcpy.h>
50 #include <rte_kvargs.h>
52 #include <rte_atomic.h>
54 #include "rte_eth_szedata2.h"
56 #define RTE_ETH_SZEDATA2_MAX_RX_QUEUES 32
57 #define RTE_ETH_SZEDATA2_MAX_TX_QUEUES 32
58 #define RTE_ETH_SZEDATA2_TX_LOCK_SIZE (32 * 1024 * 1024)
61 * size of szedata2_packet header with alignment
63 #define RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED 8
65 #define RTE_SZEDATA2_DRIVER_NAME net_szedata2
66 #define RTE_SZEDATA2_PCI_DRIVER_NAME "rte_szedata2_pmd"
68 #define SZEDATA2_DEV_PATH_FMT "/dev/szedataII%u"
70 struct szedata2_rx_queue {
74 struct rte_mempool *mb_pool;
75 volatile uint64_t rx_pkts;
76 volatile uint64_t rx_bytes;
77 volatile uint64_t err_pkts;
80 struct szedata2_tx_queue {
83 volatile uint64_t tx_pkts;
84 volatile uint64_t tx_bytes;
85 volatile uint64_t err_pkts;
88 struct pmd_internals {
89 struct szedata2_rx_queue rx_queue[RTE_ETH_SZEDATA2_MAX_RX_QUEUES];
90 struct szedata2_tx_queue tx_queue[RTE_ETH_SZEDATA2_MAX_TX_QUEUES];
91 uint16_t max_rx_queues;
92 uint16_t max_tx_queues;
93 char sze_dev[PATH_MAX];
94 struct rte_mem_resource *pci_rsc;
97 static struct ether_addr eth_addr = {
98 .addr_bytes = { 0x00, 0x11, 0x17, 0x00, 0x00, 0x00 }
102 eth_szedata2_rx(void *queue,
103 struct rte_mbuf **bufs,
107 struct rte_mbuf *mbuf;
108 struct szedata2_rx_queue *sze_q = queue;
109 struct rte_pktmbuf_pool_private *mbp_priv;
114 uint16_t packet_size;
115 uint64_t num_bytes = 0;
116 struct szedata *sze = sze_q->sze;
117 uint8_t *header_ptr = NULL; /* header of packet */
118 uint8_t *packet_ptr1 = NULL;
119 uint8_t *packet_ptr2 = NULL;
120 uint16_t packet_len1 = 0;
121 uint16_t packet_len2 = 0;
122 uint16_t hw_data_align;
124 if (unlikely(sze_q->sze == NULL || nb_pkts == 0))
128 * Reads the given number of packets from szedata2 channel given
129 * by queue and copies the packet data into a newly allocated mbuf
132 for (i = 0; i < nb_pkts; i++) {
133 mbuf = rte_pktmbuf_alloc(sze_q->mb_pool);
135 if (unlikely(mbuf == NULL))
138 /* get the next sze packet */
139 if (sze->ct_rx_lck != NULL && !sze->ct_rx_rem_bytes &&
140 sze->ct_rx_lck->next == NULL) {
141 /* unlock old data */
142 szedata_rx_unlock_data(sze_q->sze, sze->ct_rx_lck_orig);
143 sze->ct_rx_lck_orig = NULL;
144 sze->ct_rx_lck = NULL;
147 if (!sze->ct_rx_rem_bytes && sze->ct_rx_lck_orig == NULL) {
148 /* nothing to read, lock new data */
149 sze->ct_rx_lck = szedata_rx_lock_data(sze_q->sze, ~0U);
150 sze->ct_rx_lck_orig = sze->ct_rx_lck;
152 if (sze->ct_rx_lck == NULL) {
153 /* nothing to lock */
154 rte_pktmbuf_free(mbuf);
158 sze->ct_rx_cur_ptr = sze->ct_rx_lck->start;
159 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len;
161 if (!sze->ct_rx_rem_bytes) {
162 rte_pktmbuf_free(mbuf);
167 if (sze->ct_rx_rem_bytes < RTE_SZE2_PACKET_HEADER_SIZE) {
170 * copy parts of header to merge buffer
172 if (sze->ct_rx_lck->next == NULL) {
173 rte_pktmbuf_free(mbuf);
177 /* copy first part of header */
178 rte_memcpy(sze->ct_rx_buffer, sze->ct_rx_cur_ptr,
179 sze->ct_rx_rem_bytes);
181 /* copy second part of header */
182 sze->ct_rx_lck = sze->ct_rx_lck->next;
183 sze->ct_rx_cur_ptr = sze->ct_rx_lck->start;
184 rte_memcpy(sze->ct_rx_buffer + sze->ct_rx_rem_bytes,
186 RTE_SZE2_PACKET_HEADER_SIZE -
187 sze->ct_rx_rem_bytes);
189 sze->ct_rx_cur_ptr += RTE_SZE2_PACKET_HEADER_SIZE -
190 sze->ct_rx_rem_bytes;
191 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len -
192 RTE_SZE2_PACKET_HEADER_SIZE +
193 sze->ct_rx_rem_bytes;
195 header_ptr = (uint8_t *)sze->ct_rx_buffer;
198 header_ptr = (uint8_t *)sze->ct_rx_cur_ptr;
199 sze->ct_rx_cur_ptr += RTE_SZE2_PACKET_HEADER_SIZE;
200 sze->ct_rx_rem_bytes -= RTE_SZE2_PACKET_HEADER_SIZE;
203 sg_size = le16toh(*((uint16_t *)header_ptr));
204 hw_size = le16toh(*(((uint16_t *)header_ptr) + 1));
205 packet_size = sg_size -
206 RTE_SZE2_ALIGN8(RTE_SZE2_PACKET_HEADER_SIZE + hw_size);
209 /* checks if packet all right */
211 errx(5, "Zero segsize");
213 /* check sg_size and hwsize */
214 if (hw_size > sg_size - RTE_SZE2_PACKET_HEADER_SIZE) {
215 errx(10, "Hwsize bigger than expected. Segsize: %d, "
216 "hwsize: %d", sg_size, hw_size);
220 RTE_SZE2_ALIGN8(RTE_SZE2_PACKET_HEADER_SIZE + hw_size) -
221 RTE_SZE2_PACKET_HEADER_SIZE;
223 if (sze->ct_rx_rem_bytes >=
225 RTE_SZE2_PACKET_HEADER_SIZE)) {
227 /* one packet ready - go to another */
228 packet_ptr1 = sze->ct_rx_cur_ptr + hw_data_align;
229 packet_len1 = packet_size;
233 sze->ct_rx_cur_ptr += RTE_SZE2_ALIGN8(sg_size) -
234 RTE_SZE2_PACKET_HEADER_SIZE;
235 sze->ct_rx_rem_bytes -= RTE_SZE2_ALIGN8(sg_size) -
236 RTE_SZE2_PACKET_HEADER_SIZE;
239 if (sze->ct_rx_lck->next == NULL) {
240 errx(6, "Need \"next\" lock, "
241 "but it is missing: %u",
242 sze->ct_rx_rem_bytes);
246 if (sze->ct_rx_rem_bytes <= hw_data_align) {
247 uint16_t rem_size = hw_data_align -
248 sze->ct_rx_rem_bytes;
250 /* MOVE to next lock */
251 sze->ct_rx_lck = sze->ct_rx_lck->next;
253 (void *)(((uint8_t *)
254 (sze->ct_rx_lck->start)) + rem_size);
256 packet_ptr1 = sze->ct_rx_cur_ptr;
257 packet_len1 = packet_size;
261 sze->ct_rx_cur_ptr +=
262 RTE_SZE2_ALIGN8(packet_size);
263 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len -
264 rem_size - RTE_SZE2_ALIGN8(packet_size);
266 /* get pointer and length from first part */
267 packet_ptr1 = sze->ct_rx_cur_ptr +
269 packet_len1 = sze->ct_rx_rem_bytes -
272 /* MOVE to next lock */
273 sze->ct_rx_lck = sze->ct_rx_lck->next;
274 sze->ct_rx_cur_ptr = sze->ct_rx_lck->start;
276 /* get pointer and length from second part */
277 packet_ptr2 = sze->ct_rx_cur_ptr;
278 packet_len2 = packet_size - packet_len1;
280 sze->ct_rx_cur_ptr +=
281 RTE_SZE2_ALIGN8(packet_size) -
283 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len -
284 (RTE_SZE2_ALIGN8(packet_size) -
289 if (unlikely(packet_ptr1 == NULL)) {
290 rte_pktmbuf_free(mbuf);
294 /* get the space available for data in the mbuf */
295 mbp_priv = rte_mempool_get_priv(sze_q->mb_pool);
296 buf_size = (uint16_t)(mbp_priv->mbuf_data_room_size -
297 RTE_PKTMBUF_HEADROOM);
299 if (packet_size <= buf_size) {
300 /* sze packet will fit in one mbuf, go ahead and copy */
301 rte_memcpy(rte_pktmbuf_mtod(mbuf, void *),
302 packet_ptr1, packet_len1);
303 if (packet_ptr2 != NULL) {
304 rte_memcpy((void *)(rte_pktmbuf_mtod(mbuf,
305 uint8_t *) + packet_len1),
306 packet_ptr2, packet_len2);
308 mbuf->data_len = (uint16_t)packet_size;
310 mbuf->pkt_len = packet_size;
311 mbuf->port = sze_q->in_port;
314 num_bytes += packet_size;
317 * sze packet will not fit in one mbuf,
318 * scattered mode is not enabled, drop packet
321 "SZE segment %d bytes will not fit in one mbuf "
322 "(%d bytes), scattered mode is not enabled, "
324 packet_size, buf_size);
325 rte_pktmbuf_free(mbuf);
329 sze_q->rx_pkts += num_rx;
330 sze_q->rx_bytes += num_bytes;
335 eth_szedata2_rx_scattered(void *queue,
336 struct rte_mbuf **bufs,
340 struct rte_mbuf *mbuf;
341 struct szedata2_rx_queue *sze_q = queue;
342 struct rte_pktmbuf_pool_private *mbp_priv;
347 uint16_t packet_size;
348 uint64_t num_bytes = 0;
349 struct szedata *sze = sze_q->sze;
350 uint8_t *header_ptr = NULL; /* header of packet */
351 uint8_t *packet_ptr1 = NULL;
352 uint8_t *packet_ptr2 = NULL;
353 uint16_t packet_len1 = 0;
354 uint16_t packet_len2 = 0;
355 uint16_t hw_data_align;
357 if (unlikely(sze_q->sze == NULL || nb_pkts == 0))
361 * Reads the given number of packets from szedata2 channel given
362 * by queue and copies the packet data into a newly allocated mbuf
365 for (i = 0; i < nb_pkts; i++) {
366 const struct szedata_lock *ct_rx_lck_backup;
367 unsigned int ct_rx_rem_bytes_backup;
368 unsigned char *ct_rx_cur_ptr_backup;
370 /* get the next sze packet */
371 if (sze->ct_rx_lck != NULL && !sze->ct_rx_rem_bytes &&
372 sze->ct_rx_lck->next == NULL) {
373 /* unlock old data */
374 szedata_rx_unlock_data(sze_q->sze, sze->ct_rx_lck_orig);
375 sze->ct_rx_lck_orig = NULL;
376 sze->ct_rx_lck = NULL;
380 * Store items from sze structure which can be changed
381 * before mbuf allocating. Use these items in case of mbuf
382 * allocating failure.
384 ct_rx_lck_backup = sze->ct_rx_lck;
385 ct_rx_rem_bytes_backup = sze->ct_rx_rem_bytes;
386 ct_rx_cur_ptr_backup = sze->ct_rx_cur_ptr;
388 if (!sze->ct_rx_rem_bytes && sze->ct_rx_lck_orig == NULL) {
389 /* nothing to read, lock new data */
390 sze->ct_rx_lck = szedata_rx_lock_data(sze_q->sze, ~0U);
391 sze->ct_rx_lck_orig = sze->ct_rx_lck;
394 * Backup items from sze structure must be updated
395 * after locking to contain pointers to new locks.
397 ct_rx_lck_backup = sze->ct_rx_lck;
398 ct_rx_rem_bytes_backup = sze->ct_rx_rem_bytes;
399 ct_rx_cur_ptr_backup = sze->ct_rx_cur_ptr;
401 if (sze->ct_rx_lck == NULL)
402 /* nothing to lock */
405 sze->ct_rx_cur_ptr = sze->ct_rx_lck->start;
406 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len;
408 if (!sze->ct_rx_rem_bytes)
412 if (sze->ct_rx_rem_bytes < RTE_SZE2_PACKET_HEADER_SIZE) {
414 * cut in header - copy parts of header to merge buffer
416 if (sze->ct_rx_lck->next == NULL)
419 /* copy first part of header */
420 rte_memcpy(sze->ct_rx_buffer, sze->ct_rx_cur_ptr,
421 sze->ct_rx_rem_bytes);
423 /* copy second part of header */
424 sze->ct_rx_lck = sze->ct_rx_lck->next;
425 sze->ct_rx_cur_ptr = sze->ct_rx_lck->start;
426 rte_memcpy(sze->ct_rx_buffer + sze->ct_rx_rem_bytes,
428 RTE_SZE2_PACKET_HEADER_SIZE -
429 sze->ct_rx_rem_bytes);
431 sze->ct_rx_cur_ptr += RTE_SZE2_PACKET_HEADER_SIZE -
432 sze->ct_rx_rem_bytes;
433 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len -
434 RTE_SZE2_PACKET_HEADER_SIZE +
435 sze->ct_rx_rem_bytes;
437 header_ptr = (uint8_t *)sze->ct_rx_buffer;
440 header_ptr = (uint8_t *)sze->ct_rx_cur_ptr;
441 sze->ct_rx_cur_ptr += RTE_SZE2_PACKET_HEADER_SIZE;
442 sze->ct_rx_rem_bytes -= RTE_SZE2_PACKET_HEADER_SIZE;
445 sg_size = le16toh(*((uint16_t *)header_ptr));
446 hw_size = le16toh(*(((uint16_t *)header_ptr) + 1));
447 packet_size = sg_size -
448 RTE_SZE2_ALIGN8(RTE_SZE2_PACKET_HEADER_SIZE + hw_size);
451 /* checks if packet all right */
453 errx(5, "Zero segsize");
455 /* check sg_size and hwsize */
456 if (hw_size > sg_size - RTE_SZE2_PACKET_HEADER_SIZE) {
457 errx(10, "Hwsize bigger than expected. Segsize: %d, "
458 "hwsize: %d", sg_size, hw_size);
462 RTE_SZE2_ALIGN8((RTE_SZE2_PACKET_HEADER_SIZE +
463 hw_size)) - RTE_SZE2_PACKET_HEADER_SIZE;
465 if (sze->ct_rx_rem_bytes >=
467 RTE_SZE2_PACKET_HEADER_SIZE)) {
469 /* one packet ready - go to another */
470 packet_ptr1 = sze->ct_rx_cur_ptr + hw_data_align;
471 packet_len1 = packet_size;
475 sze->ct_rx_cur_ptr += RTE_SZE2_ALIGN8(sg_size) -
476 RTE_SZE2_PACKET_HEADER_SIZE;
477 sze->ct_rx_rem_bytes -= RTE_SZE2_ALIGN8(sg_size) -
478 RTE_SZE2_PACKET_HEADER_SIZE;
481 if (sze->ct_rx_lck->next == NULL) {
482 errx(6, "Need \"next\" lock, but it is "
483 "missing: %u", sze->ct_rx_rem_bytes);
487 if (sze->ct_rx_rem_bytes <= hw_data_align) {
488 uint16_t rem_size = hw_data_align -
489 sze->ct_rx_rem_bytes;
491 /* MOVE to next lock */
492 sze->ct_rx_lck = sze->ct_rx_lck->next;
494 (void *)(((uint8_t *)
495 (sze->ct_rx_lck->start)) + rem_size);
497 packet_ptr1 = sze->ct_rx_cur_ptr;
498 packet_len1 = packet_size;
502 sze->ct_rx_cur_ptr +=
503 RTE_SZE2_ALIGN8(packet_size);
504 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len -
505 rem_size - RTE_SZE2_ALIGN8(packet_size);
507 /* get pointer and length from first part */
508 packet_ptr1 = sze->ct_rx_cur_ptr +
510 packet_len1 = sze->ct_rx_rem_bytes -
513 /* MOVE to next lock */
514 sze->ct_rx_lck = sze->ct_rx_lck->next;
515 sze->ct_rx_cur_ptr = sze->ct_rx_lck->start;
517 /* get pointer and length from second part */
518 packet_ptr2 = sze->ct_rx_cur_ptr;
519 packet_len2 = packet_size - packet_len1;
521 sze->ct_rx_cur_ptr +=
522 RTE_SZE2_ALIGN8(packet_size) -
524 sze->ct_rx_rem_bytes = sze->ct_rx_lck->len -
525 (RTE_SZE2_ALIGN8(packet_size) -
530 if (unlikely(packet_ptr1 == NULL))
533 mbuf = rte_pktmbuf_alloc(sze_q->mb_pool);
535 if (unlikely(mbuf == NULL)) {
537 * Restore items from sze structure to state after
538 * unlocking (eventually locking).
540 sze->ct_rx_lck = ct_rx_lck_backup;
541 sze->ct_rx_rem_bytes = ct_rx_rem_bytes_backup;
542 sze->ct_rx_cur_ptr = ct_rx_cur_ptr_backup;
546 /* get the space available for data in the mbuf */
547 mbp_priv = rte_mempool_get_priv(sze_q->mb_pool);
548 buf_size = (uint16_t)(mbp_priv->mbuf_data_room_size -
549 RTE_PKTMBUF_HEADROOM);
551 if (packet_size <= buf_size) {
552 /* sze packet will fit in one mbuf, go ahead and copy */
553 rte_memcpy(rte_pktmbuf_mtod(mbuf, void *),
554 packet_ptr1, packet_len1);
555 if (packet_ptr2 != NULL) {
557 (rte_pktmbuf_mtod(mbuf, uint8_t *) +
558 packet_len1), packet_ptr2, packet_len2);
560 mbuf->data_len = (uint16_t)packet_size;
563 * sze packet will not fit in one mbuf,
564 * scatter packet into more mbufs
566 struct rte_mbuf *m = mbuf;
567 uint16_t len = rte_pktmbuf_tailroom(mbuf);
569 /* copy first part of packet */
570 /* fill first mbuf */
571 rte_memcpy(rte_pktmbuf_append(mbuf, len), packet_ptr1,
574 packet_ptr1 = ((uint8_t *)packet_ptr1) + len;
576 while (packet_len1 > 0) {
578 m->next = rte_pktmbuf_alloc(sze_q->mb_pool);
580 if (unlikely(m->next == NULL)) {
581 rte_pktmbuf_free(mbuf);
583 * Restore items from sze structure
584 * to state after unlocking (eventually
587 sze->ct_rx_lck = ct_rx_lck_backup;
588 sze->ct_rx_rem_bytes =
589 ct_rx_rem_bytes_backup;
591 ct_rx_cur_ptr_backup;
597 len = RTE_MIN(rte_pktmbuf_tailroom(m),
599 rte_memcpy(rte_pktmbuf_append(mbuf, len),
604 packet_ptr1 = ((uint8_t *)packet_ptr1) + len;
607 if (packet_ptr2 != NULL) {
608 /* copy second part of packet, if exists */
609 /* fill the rest of currently last mbuf */
610 len = rte_pktmbuf_tailroom(m);
611 rte_memcpy(rte_pktmbuf_append(mbuf, len),
614 packet_ptr2 = ((uint8_t *)packet_ptr2) + len;
616 while (packet_len2 > 0) {
618 m->next = rte_pktmbuf_alloc(
621 if (unlikely(m->next == NULL)) {
622 rte_pktmbuf_free(mbuf);
624 * Restore items from sze
625 * structure to state after
626 * unlocking (eventually
631 sze->ct_rx_rem_bytes =
632 ct_rx_rem_bytes_backup;
634 ct_rx_cur_ptr_backup;
640 len = RTE_MIN(rte_pktmbuf_tailroom(m),
643 rte_pktmbuf_append(mbuf, len),
648 packet_ptr2 = ((uint8_t *)packet_ptr2) +
653 mbuf->pkt_len = packet_size;
654 mbuf->port = sze_q->in_port;
657 num_bytes += packet_size;
661 sze_q->rx_pkts += num_rx;
662 sze_q->rx_bytes += num_bytes;
667 eth_szedata2_tx(void *queue,
668 struct rte_mbuf **bufs,
671 struct rte_mbuf *mbuf;
672 struct szedata2_tx_queue *sze_q = queue;
674 uint64_t num_bytes = 0;
676 const struct szedata_lock *lck;
682 uint32_t unlock_size;
685 uint16_t pkt_left = nb_pkts;
687 if (sze_q->sze == NULL || nb_pkts == 0)
690 while (pkt_left > 0) {
692 lck = szedata_tx_lock_data(sze_q->sze,
693 RTE_ETH_SZEDATA2_TX_LOCK_SIZE,
699 lock_size = lck->len;
700 lock_size2 = lck->next ? lck->next->len : 0;
703 mbuf = bufs[nb_pkts - pkt_left];
705 pkt_len = mbuf->pkt_len;
706 mbuf_segs = mbuf->nb_segs;
708 hwpkt_len = RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED +
709 RTE_SZE2_ALIGN8(pkt_len);
711 if (lock_size + lock_size2 < hwpkt_len) {
712 szedata_tx_unlock_data(sze_q->sze, lck, unlock_size);
716 num_bytes += pkt_len;
718 if (lock_size > hwpkt_len) {
723 /* write packet length at first 2 bytes in 8B header */
724 *((uint16_t *)dst) = htole16(
725 RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED +
727 *(((uint16_t *)dst) + 1) = htole16(0);
729 /* copy packet from mbuf */
730 tmp_dst = ((uint8_t *)(dst)) +
731 RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED;
732 if (mbuf_segs == 1) {
734 * non-scattered packet,
735 * transmit from one mbuf
738 rte_pktmbuf_mtod(mbuf, const void *),
741 /* scattered packet, transmit from more mbufs */
742 struct rte_mbuf *m = mbuf;
748 tmp_dst = ((uint8_t *)(tmp_dst)) +
755 dst = ((uint8_t *)dst) + hwpkt_len;
756 unlock_size += hwpkt_len;
757 lock_size -= hwpkt_len;
759 rte_pktmbuf_free(mbuf);
763 szedata_tx_unlock_data(sze_q->sze, lck,
768 } else if (lock_size + lock_size2 >= hwpkt_len) {
772 /* write packet length at first 2 bytes in 8B header */
774 htole16(RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED +
776 *(((uint16_t *)dst) + 1) = htole16(0);
779 * If the raw packet (pkt_len) is smaller than lock_size
780 * get the correct length for memcpy
783 pkt_len < lock_size -
784 RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED ?
786 lock_size - RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED;
788 rem_len = hwpkt_len - lock_size;
790 tmp_dst = ((uint8_t *)(dst)) +
791 RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED;
792 if (mbuf_segs == 1) {
794 * non-scattered packet,
795 * transmit from one mbuf
797 /* copy part of packet to first area */
799 rte_pktmbuf_mtod(mbuf, const void *),
803 dst = lck->next->start;
805 /* copy part of packet to second area */
807 (const void *)(rte_pktmbuf_mtod(mbuf,
809 write_len), pkt_len - write_len);
811 /* scattered packet, transmit from more mbufs */
812 struct rte_mbuf *m = mbuf;
813 uint16_t written = 0;
814 uint16_t to_write = 0;
815 bool new_mbuf = true;
816 uint16_t write_off = 0;
818 /* copy part of packet to first area */
819 while (m && written < write_len) {
820 to_write = RTE_MIN(m->data_len,
821 write_len - written);
827 tmp_dst = ((uint8_t *)(tmp_dst)) +
829 if (m->data_len <= write_len -
840 dst = lck->next->start;
844 write_off = new_mbuf ? 0 : to_write;
846 /* copy part of packet to second area */
847 while (m && written < pkt_len - write_len) {
848 rte_memcpy(tmp_dst, (const void *)
850 uint8_t *) + write_off),
851 m->data_len - write_off);
853 tmp_dst = ((uint8_t *)(tmp_dst)) +
854 (m->data_len - write_off);
855 written += m->data_len - write_off;
861 dst = ((uint8_t *)dst) + rem_len;
862 unlock_size += hwpkt_len;
863 lock_size = lock_size2 - rem_len;
866 rte_pktmbuf_free(mbuf);
870 szedata_tx_unlock_data(sze_q->sze, lck, unlock_size);
874 sze_q->tx_pkts += num_tx;
875 sze_q->err_pkts += nb_pkts - num_tx;
876 sze_q->tx_bytes += num_bytes;
881 eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rxq_id)
883 struct szedata2_rx_queue *rxq = dev->data->rx_queues[rxq_id];
885 struct pmd_internals *internals = (struct pmd_internals *)
886 dev->data->dev_private;
888 if (rxq->sze == NULL) {
889 uint32_t rx = 1 << rxq->rx_channel;
891 rxq->sze = szedata_open(internals->sze_dev);
892 if (rxq->sze == NULL)
894 ret = szedata_subscribe3(rxq->sze, &rx, &tx);
895 if (ret != 0 || rx == 0)
899 ret = szedata_start(rxq->sze);
902 dev->data->rx_queue_state[rxq_id] = RTE_ETH_QUEUE_STATE_STARTED;
906 szedata_close(rxq->sze);
912 eth_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rxq_id)
914 struct szedata2_rx_queue *rxq = dev->data->rx_queues[rxq_id];
916 if (rxq->sze != NULL) {
917 szedata_close(rxq->sze);
921 dev->data->rx_queue_state[rxq_id] = RTE_ETH_QUEUE_STATE_STOPPED;
926 eth_tx_queue_start(struct rte_eth_dev *dev, uint16_t txq_id)
928 struct szedata2_tx_queue *txq = dev->data->tx_queues[txq_id];
930 struct pmd_internals *internals = (struct pmd_internals *)
931 dev->data->dev_private;
933 if (txq->sze == NULL) {
935 uint32_t tx = 1 << txq->tx_channel;
936 txq->sze = szedata_open(internals->sze_dev);
937 if (txq->sze == NULL)
939 ret = szedata_subscribe3(txq->sze, &rx, &tx);
940 if (ret != 0 || tx == 0)
944 ret = szedata_start(txq->sze);
947 dev->data->tx_queue_state[txq_id] = RTE_ETH_QUEUE_STATE_STARTED;
951 szedata_close(txq->sze);
957 eth_tx_queue_stop(struct rte_eth_dev *dev, uint16_t txq_id)
959 struct szedata2_tx_queue *txq = dev->data->tx_queues[txq_id];
961 if (txq->sze != NULL) {
962 szedata_close(txq->sze);
966 dev->data->tx_queue_state[txq_id] = RTE_ETH_QUEUE_STATE_STOPPED;
971 eth_dev_start(struct rte_eth_dev *dev)
975 uint16_t nb_rx = dev->data->nb_rx_queues;
976 uint16_t nb_tx = dev->data->nb_tx_queues;
978 for (i = 0; i < nb_rx; i++) {
979 ret = eth_rx_queue_start(dev, i);
984 for (i = 0; i < nb_tx; i++) {
985 ret = eth_tx_queue_start(dev, i);
993 for (i = 0; i < nb_tx; i++)
994 eth_tx_queue_stop(dev, i);
996 for (i = 0; i < nb_rx; i++)
997 eth_rx_queue_stop(dev, i);
1002 eth_dev_stop(struct rte_eth_dev *dev)
1005 uint16_t nb_rx = dev->data->nb_rx_queues;
1006 uint16_t nb_tx = dev->data->nb_tx_queues;
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);
1016 eth_dev_configure(struct rte_eth_dev *dev)
1018 struct rte_eth_dev_data *data = dev->data;
1019 if (data->dev_conf.rxmode.enable_scatter == 1) {
1020 dev->rx_pkt_burst = eth_szedata2_rx_scattered;
1021 data->scattered_rx = 1;
1023 dev->rx_pkt_burst = eth_szedata2_rx;
1024 data->scattered_rx = 0;
1030 eth_dev_info(struct rte_eth_dev *dev,
1031 struct rte_eth_dev_info *dev_info)
1033 struct pmd_internals *internals = dev->data->dev_private;
1034 dev_info->pci_dev = RTE_DEV_TO_PCI(dev->device);
1035 dev_info->if_index = 0;
1036 dev_info->max_mac_addrs = 1;
1037 dev_info->max_rx_pktlen = (uint32_t)-1;
1038 dev_info->max_rx_queues = internals->max_rx_queues;
1039 dev_info->max_tx_queues = internals->max_tx_queues;
1040 dev_info->min_rx_bufsize = 0;
1041 dev_info->speed_capa = ETH_LINK_SPEED_100G;
1045 eth_stats_get(struct rte_eth_dev *dev,
1046 struct rte_eth_stats *stats)
1049 uint16_t nb_rx = dev->data->nb_rx_queues;
1050 uint16_t nb_tx = dev->data->nb_tx_queues;
1051 uint64_t rx_total = 0;
1052 uint64_t tx_total = 0;
1053 uint64_t tx_err_total = 0;
1054 uint64_t rx_total_bytes = 0;
1055 uint64_t tx_total_bytes = 0;
1056 const struct pmd_internals *internals = dev->data->dev_private;
1058 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && i < nb_rx; i++) {
1059 stats->q_ipackets[i] = internals->rx_queue[i].rx_pkts;
1060 stats->q_ibytes[i] = internals->rx_queue[i].rx_bytes;
1061 rx_total += stats->q_ipackets[i];
1062 rx_total_bytes += stats->q_ibytes[i];
1065 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && i < nb_tx; i++) {
1066 stats->q_opackets[i] = internals->tx_queue[i].tx_pkts;
1067 stats->q_obytes[i] = internals->tx_queue[i].tx_bytes;
1068 stats->q_errors[i] = internals->tx_queue[i].err_pkts;
1069 tx_total += stats->q_opackets[i];
1070 tx_total_bytes += stats->q_obytes[i];
1071 tx_err_total += stats->q_errors[i];
1074 stats->ipackets = rx_total;
1075 stats->opackets = tx_total;
1076 stats->ibytes = rx_total_bytes;
1077 stats->obytes = tx_total_bytes;
1078 stats->oerrors = tx_err_total;
1082 eth_stats_reset(struct rte_eth_dev *dev)
1085 uint16_t nb_rx = dev->data->nb_rx_queues;
1086 uint16_t nb_tx = dev->data->nb_tx_queues;
1087 struct pmd_internals *internals = dev->data->dev_private;
1089 for (i = 0; i < nb_rx; i++) {
1090 internals->rx_queue[i].rx_pkts = 0;
1091 internals->rx_queue[i].rx_bytes = 0;
1092 internals->rx_queue[i].err_pkts = 0;
1094 for (i = 0; i < nb_tx; i++) {
1095 internals->tx_queue[i].tx_pkts = 0;
1096 internals->tx_queue[i].tx_bytes = 0;
1097 internals->tx_queue[i].err_pkts = 0;
1102 eth_rx_queue_release(void *q)
1104 struct szedata2_rx_queue *rxq = (struct szedata2_rx_queue *)q;
1105 if (rxq->sze != NULL) {
1106 szedata_close(rxq->sze);
1112 eth_tx_queue_release(void *q)
1114 struct szedata2_tx_queue *txq = (struct szedata2_tx_queue *)q;
1115 if (txq->sze != NULL) {
1116 szedata_close(txq->sze);
1122 eth_dev_close(struct rte_eth_dev *dev)
1125 uint16_t nb_rx = dev->data->nb_rx_queues;
1126 uint16_t nb_tx = dev->data->nb_tx_queues;
1130 for (i = 0; i < nb_rx; i++) {
1131 eth_rx_queue_release(dev->data->rx_queues[i]);
1132 dev->data->rx_queues[i] = NULL;
1134 dev->data->nb_rx_queues = 0;
1135 for (i = 0; i < nb_tx; i++) {
1136 eth_tx_queue_release(dev->data->tx_queues[i]);
1137 dev->data->tx_queues[i] = NULL;
1139 dev->data->nb_tx_queues = 0;
1143 eth_link_update(struct rte_eth_dev *dev,
1144 int wait_to_complete __rte_unused)
1146 struct rte_eth_link link;
1147 struct rte_eth_link *link_ptr = &link;
1148 struct rte_eth_link *dev_link = &dev->data->dev_link;
1149 struct pmd_internals *internals = (struct pmd_internals *)
1150 dev->data->dev_private;
1151 volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
1152 internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
1153 volatile struct szedata2_cgmii_ibuf *);
1155 switch (cgmii_link_speed(ibuf)) {
1156 case SZEDATA2_LINK_SPEED_10G:
1157 link.link_speed = ETH_SPEED_NUM_10G;
1159 case SZEDATA2_LINK_SPEED_40G:
1160 link.link_speed = ETH_SPEED_NUM_40G;
1162 case SZEDATA2_LINK_SPEED_100G:
1163 link.link_speed = ETH_SPEED_NUM_100G;
1166 link.link_speed = ETH_SPEED_NUM_10G;
1170 /* szedata2 uses only full duplex */
1171 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1173 link.link_status = (cgmii_ibuf_is_enabled(ibuf) &&
1174 cgmii_ibuf_is_link_up(ibuf)) ? ETH_LINK_UP : ETH_LINK_DOWN;
1176 link.link_autoneg = ETH_LINK_SPEED_FIXED;
1178 rte_atomic64_cmpset((uint64_t *)dev_link, *(uint64_t *)dev_link,
1179 *(uint64_t *)link_ptr);
1185 eth_dev_set_link_up(struct rte_eth_dev *dev)
1187 struct pmd_internals *internals = (struct pmd_internals *)
1188 dev->data->dev_private;
1189 volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
1190 internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
1191 volatile struct szedata2_cgmii_ibuf *);
1192 volatile struct szedata2_cgmii_obuf *obuf = SZEDATA2_PCI_RESOURCE_PTR(
1193 internals->pci_rsc, SZEDATA2_CGMII_OBUF_BASE_OFF,
1194 volatile struct szedata2_cgmii_obuf *);
1196 cgmii_ibuf_enable(ibuf);
1197 cgmii_obuf_enable(obuf);
1202 eth_dev_set_link_down(struct rte_eth_dev *dev)
1204 struct pmd_internals *internals = (struct pmd_internals *)
1205 dev->data->dev_private;
1206 volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
1207 internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
1208 volatile struct szedata2_cgmii_ibuf *);
1209 volatile struct szedata2_cgmii_obuf *obuf = SZEDATA2_PCI_RESOURCE_PTR(
1210 internals->pci_rsc, SZEDATA2_CGMII_OBUF_BASE_OFF,
1211 volatile struct szedata2_cgmii_obuf *);
1213 cgmii_ibuf_disable(ibuf);
1214 cgmii_obuf_disable(obuf);
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 __rte_unused,
1223 const struct rte_eth_rxconf *rx_conf __rte_unused,
1224 struct rte_mempool *mb_pool)
1226 struct pmd_internals *internals = dev->data->dev_private;
1227 struct szedata2_rx_queue *rxq = &internals->rx_queue[rx_queue_id];
1229 uint32_t rx = 1 << rx_queue_id;
1232 rxq->sze = szedata_open(internals->sze_dev);
1233 if (rxq->sze == NULL)
1235 ret = szedata_subscribe3(rxq->sze, &rx, &tx);
1236 if (ret != 0 || rx == 0) {
1237 szedata_close(rxq->sze);
1241 rxq->rx_channel = rx_queue_id;
1242 rxq->in_port = dev->data->port_id;
1243 rxq->mb_pool = mb_pool;
1248 dev->data->rx_queues[rx_queue_id] = rxq;
1253 eth_tx_queue_setup(struct rte_eth_dev *dev,
1254 uint16_t tx_queue_id,
1255 uint16_t nb_tx_desc __rte_unused,
1256 unsigned int socket_id __rte_unused,
1257 const struct rte_eth_txconf *tx_conf __rte_unused)
1259 struct pmd_internals *internals = dev->data->dev_private;
1260 struct szedata2_tx_queue *txq = &internals->tx_queue[tx_queue_id];
1263 uint32_t tx = 1 << tx_queue_id;
1265 txq->sze = szedata_open(internals->sze_dev);
1266 if (txq->sze == NULL)
1268 ret = szedata_subscribe3(txq->sze, &rx, &tx);
1269 if (ret != 0 || tx == 0) {
1270 szedata_close(txq->sze);
1274 txq->tx_channel = tx_queue_id;
1279 dev->data->tx_queues[tx_queue_id] = txq;
1284 eth_mac_addr_set(struct rte_eth_dev *dev __rte_unused,
1285 struct ether_addr *mac_addr __rte_unused)
1290 eth_promiscuous_enable(struct rte_eth_dev *dev)
1292 struct pmd_internals *internals = (struct pmd_internals *)
1293 dev->data->dev_private;
1294 volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
1295 internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
1296 volatile struct szedata2_cgmii_ibuf *);
1297 cgmii_ibuf_mac_mode_write(ibuf, SZEDATA2_MAC_CHMODE_PROMISC);
1301 eth_promiscuous_disable(struct rte_eth_dev *dev)
1303 struct pmd_internals *internals = (struct pmd_internals *)
1304 dev->data->dev_private;
1305 volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
1306 internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
1307 volatile struct szedata2_cgmii_ibuf *);
1308 cgmii_ibuf_mac_mode_write(ibuf, SZEDATA2_MAC_CHMODE_ONLY_VALID);
1312 eth_allmulticast_enable(struct rte_eth_dev *dev)
1314 struct pmd_internals *internals = (struct pmd_internals *)
1315 dev->data->dev_private;
1316 volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
1317 internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
1318 volatile struct szedata2_cgmii_ibuf *);
1319 cgmii_ibuf_mac_mode_write(ibuf, SZEDATA2_MAC_CHMODE_ALL_MULTICAST);
1323 eth_allmulticast_disable(struct rte_eth_dev *dev)
1325 struct pmd_internals *internals = (struct pmd_internals *)
1326 dev->data->dev_private;
1327 volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
1328 internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
1329 volatile struct szedata2_cgmii_ibuf *);
1330 cgmii_ibuf_mac_mode_write(ibuf, SZEDATA2_MAC_CHMODE_ONLY_VALID);
1333 static const struct eth_dev_ops ops = {
1334 .dev_start = eth_dev_start,
1335 .dev_stop = eth_dev_stop,
1336 .dev_set_link_up = eth_dev_set_link_up,
1337 .dev_set_link_down = eth_dev_set_link_down,
1338 .dev_close = eth_dev_close,
1339 .dev_configure = eth_dev_configure,
1340 .dev_infos_get = eth_dev_info,
1341 .promiscuous_enable = eth_promiscuous_enable,
1342 .promiscuous_disable = eth_promiscuous_disable,
1343 .allmulticast_enable = eth_allmulticast_enable,
1344 .allmulticast_disable = eth_allmulticast_disable,
1345 .rx_queue_start = eth_rx_queue_start,
1346 .rx_queue_stop = eth_rx_queue_stop,
1347 .tx_queue_start = eth_tx_queue_start,
1348 .tx_queue_stop = eth_tx_queue_stop,
1349 .rx_queue_setup = eth_rx_queue_setup,
1350 .tx_queue_setup = eth_tx_queue_setup,
1351 .rx_queue_release = eth_rx_queue_release,
1352 .tx_queue_release = eth_tx_queue_release,
1353 .link_update = eth_link_update,
1354 .stats_get = eth_stats_get,
1355 .stats_reset = eth_stats_reset,
1356 .mac_addr_set = eth_mac_addr_set,
1360 * This function goes through sysfs and looks for an index of szedata2
1361 * device file (/dev/szedataIIX, where X is the index).
1368 get_szedata2_index(const struct rte_pci_addr *pcislot_addr, uint32_t *index)
1371 struct dirent *entry;
1375 char pcislot_path[PATH_MAX];
1381 dir = opendir("/sys/class/combo");
1386 * Iterate through all combosixX directories.
1387 * When the value in /sys/class/combo/combosixX/device/pcislot
1388 * file is the location of the ethernet device dev, "X" is the
1389 * index of the device.
1391 while ((entry = readdir(dir)) != NULL) {
1392 ret = sscanf(entry->d_name, "combosix%u", &tmp_index);
1396 snprintf(pcislot_path, PATH_MAX,
1397 "/sys/class/combo/combosix%u/device/pcislot",
1400 fd = fopen(pcislot_path, "r");
1404 ret = fscanf(fd, "%4" PRIx16 ":%2" PRIx8 ":%2" PRIx8 ".%" PRIx8,
1405 &domain, &bus, &devid, &function);
1410 if (pcislot_addr->domain == domain &&
1411 pcislot_addr->bus == bus &&
1412 pcislot_addr->devid == devid &&
1413 pcislot_addr->function == function) {
1425 rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
1427 struct rte_eth_dev_data *data = dev->data;
1428 struct pmd_internals *internals = (struct pmd_internals *)
1430 struct szedata *szedata_temp;
1432 uint32_t szedata2_index;
1433 struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
1434 struct rte_pci_addr *pci_addr = &pci_dev->addr;
1435 struct rte_mem_resource *pci_rsc =
1436 &pci_dev->mem_resource[PCI_RESOURCE_NUMBER];
1437 char rsc_filename[PATH_MAX];
1438 void *pci_resource_ptr = NULL;
1441 RTE_LOG(INFO, PMD, "Initializing szedata2 device (" PCI_PRI_FMT ")\n",
1442 pci_addr->domain, pci_addr->bus, pci_addr->devid,
1443 pci_addr->function);
1445 /* Get index of szedata2 device file and create path to device file */
1446 ret = get_szedata2_index(pci_addr, &szedata2_index);
1448 RTE_LOG(ERR, PMD, "Failed to get szedata2 device index!\n");
1451 snprintf(internals->sze_dev, PATH_MAX, SZEDATA2_DEV_PATH_FMT,
1454 RTE_LOG(INFO, PMD, "SZEDATA2 path: %s\n", internals->sze_dev);
1457 * Get number of available DMA RX and TX channels, which is maximum
1458 * number of queues that can be created and store it in private device
1461 szedata_temp = szedata_open(internals->sze_dev);
1462 if (szedata_temp == NULL) {
1463 RTE_LOG(ERR, PMD, "szedata_open(): failed to open %s",
1464 internals->sze_dev);
1467 internals->max_rx_queues = szedata_ifaces_available(szedata_temp,
1469 internals->max_tx_queues = szedata_ifaces_available(szedata_temp,
1471 szedata_close(szedata_temp);
1473 RTE_LOG(INFO, PMD, "Available DMA channels RX: %u TX: %u\n",
1474 internals->max_rx_queues, internals->max_tx_queues);
1476 /* Set rx, tx burst functions */
1477 if (data->dev_conf.rxmode.enable_scatter == 1 ||
1478 data->scattered_rx == 1) {
1479 dev->rx_pkt_burst = eth_szedata2_rx_scattered;
1480 data->scattered_rx = 1;
1482 dev->rx_pkt_burst = eth_szedata2_rx;
1483 data->scattered_rx = 0;
1485 dev->tx_pkt_burst = eth_szedata2_tx;
1487 /* Set function callbacks for Ethernet API */
1488 dev->dev_ops = &ops;
1490 rte_eth_copy_pci_info(dev, pci_dev);
1492 /* mmap pci resource0 file to rte_mem_resource structure */
1493 if (pci_dev->mem_resource[PCI_RESOURCE_NUMBER].phys_addr ==
1495 RTE_LOG(ERR, PMD, "Missing resource%u file\n",
1496 PCI_RESOURCE_NUMBER);
1499 snprintf(rsc_filename, PATH_MAX,
1500 "%s/" PCI_PRI_FMT "/resource%u", pci_get_sysfs_path(),
1501 pci_addr->domain, pci_addr->bus,
1502 pci_addr->devid, pci_addr->function, PCI_RESOURCE_NUMBER);
1503 fd = open(rsc_filename, O_RDWR);
1505 RTE_LOG(ERR, PMD, "Could not open file %s\n", rsc_filename);
1509 pci_resource_ptr = mmap(0,
1510 pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len,
1511 PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
1513 if (pci_resource_ptr == NULL) {
1514 RTE_LOG(ERR, PMD, "Could not mmap file %s (fd = %d)\n",
1518 pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr = pci_resource_ptr;
1519 internals->pci_rsc = pci_rsc;
1521 RTE_LOG(DEBUG, PMD, "resource%u phys_addr = 0x%llx len = %llu "
1522 "virt addr = %llx\n", PCI_RESOURCE_NUMBER,
1523 (unsigned long long)pci_rsc->phys_addr,
1524 (unsigned long long)pci_rsc->len,
1525 (unsigned long long)pci_rsc->addr);
1527 /* Get link state */
1528 eth_link_update(dev, 0);
1530 /* Allocate space for one mac address */
1531 data->mac_addrs = rte_zmalloc(data->name, sizeof(struct ether_addr),
1532 RTE_CACHE_LINE_SIZE);
1533 if (data->mac_addrs == NULL) {
1534 RTE_LOG(ERR, PMD, "Could not alloc space for MAC address!\n");
1535 munmap(pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr,
1536 pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len);
1540 ether_addr_copy(ð_addr, data->mac_addrs);
1542 /* At initial state COMBO card is in promiscuous mode so disable it */
1543 eth_promiscuous_disable(dev);
1545 RTE_LOG(INFO, PMD, "szedata2 device ("
1546 PCI_PRI_FMT ") successfully initialized\n",
1547 pci_addr->domain, pci_addr->bus, pci_addr->devid,
1548 pci_addr->function);
1554 rte_szedata2_eth_dev_uninit(struct rte_eth_dev *dev)
1556 struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
1557 struct rte_pci_addr *pci_addr = &pci_dev->addr;
1559 rte_free(dev->data->mac_addrs);
1560 dev->data->mac_addrs = NULL;
1561 munmap(pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr,
1562 pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len);
1564 RTE_LOG(INFO, PMD, "szedata2 device ("
1565 PCI_PRI_FMT ") successfully uninitialized\n",
1566 pci_addr->domain, pci_addr->bus, pci_addr->devid,
1567 pci_addr->function);
1572 static const struct rte_pci_id rte_szedata2_pci_id_table[] = {
1574 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE,
1575 PCI_DEVICE_ID_NETCOPE_COMBO80G)
1578 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE,
1579 PCI_DEVICE_ID_NETCOPE_COMBO100G)
1582 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE,
1583 PCI_DEVICE_ID_NETCOPE_COMBO100G2)
1590 static struct eth_driver szedata2_eth_driver = {
1592 .id_table = rte_szedata2_pci_id_table,
1593 .probe = rte_eth_dev_pci_probe,
1594 .remove = rte_eth_dev_pci_remove,
1596 .eth_dev_init = rte_szedata2_eth_dev_init,
1597 .eth_dev_uninit = rte_szedata2_eth_dev_uninit,
1598 .dev_private_size = sizeof(struct pmd_internals),
1601 RTE_PMD_REGISTER_PCI(RTE_SZEDATA2_DRIVER_NAME, szedata2_eth_driver.pci_drv);
1602 RTE_PMD_REGISTER_PCI_TABLE(RTE_SZEDATA2_DRIVER_NAME, rte_szedata2_pci_id_table);
1603 RTE_PMD_REGISTER_KMOD_DEP(RTE_SZEDATA2_DRIVER_NAME,
1604 "* combo6core & combov3 & szedata2 & szedata2_cv3");