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_driver.h>
48 #include <rte_ethdev_pci.h>
49 #include <rte_malloc.h>
50 #include <rte_memcpy.h>
51 #include <rte_kvargs.h>
54 #include "rte_eth_szedata2.h"
55 #include "szedata2_iobuf.h"
57 #define RTE_ETH_SZEDATA2_MAX_RX_QUEUES 32
58 #define RTE_ETH_SZEDATA2_MAX_TX_QUEUES 32
59 #define RTE_ETH_SZEDATA2_TX_LOCK_SIZE (32 * 1024 * 1024)
62 * size of szedata2_packet header with alignment
64 #define RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED 8
66 #define RTE_SZEDATA2_DRIVER_NAME net_szedata2
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.offloads & DEV_RX_OFFLOAD_SCATTER) {
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;
1035 dev_info->pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1036 dev_info->if_index = 0;
1037 dev_info->max_mac_addrs = 1;
1038 dev_info->max_rx_pktlen = (uint32_t)-1;
1039 dev_info->max_rx_queues = internals->max_rx_queues;
1040 dev_info->max_tx_queues = internals->max_tx_queues;
1041 dev_info->min_rx_bufsize = 0;
1042 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_SCATTER;
1043 dev_info->tx_offload_capa = 0;
1044 dev_info->rx_queue_offload_capa = 0;
1045 dev_info->tx_queue_offload_capa = 0;
1046 dev_info->speed_capa = ETH_LINK_SPEED_100G;
1050 eth_stats_get(struct rte_eth_dev *dev,
1051 struct rte_eth_stats *stats)
1054 uint16_t nb_rx = dev->data->nb_rx_queues;
1055 uint16_t nb_tx = dev->data->nb_tx_queues;
1056 uint64_t rx_total = 0;
1057 uint64_t tx_total = 0;
1058 uint64_t tx_err_total = 0;
1059 uint64_t rx_total_bytes = 0;
1060 uint64_t tx_total_bytes = 0;
1061 const struct pmd_internals *internals = dev->data->dev_private;
1063 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && i < nb_rx; i++) {
1064 stats->q_ipackets[i] = internals->rx_queue[i].rx_pkts;
1065 stats->q_ibytes[i] = internals->rx_queue[i].rx_bytes;
1066 rx_total += stats->q_ipackets[i];
1067 rx_total_bytes += stats->q_ibytes[i];
1070 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && i < nb_tx; i++) {
1071 stats->q_opackets[i] = internals->tx_queue[i].tx_pkts;
1072 stats->q_obytes[i] = internals->tx_queue[i].tx_bytes;
1073 stats->q_errors[i] = internals->tx_queue[i].err_pkts;
1074 tx_total += stats->q_opackets[i];
1075 tx_total_bytes += stats->q_obytes[i];
1076 tx_err_total += stats->q_errors[i];
1079 stats->ipackets = rx_total;
1080 stats->opackets = tx_total;
1081 stats->ibytes = rx_total_bytes;
1082 stats->obytes = tx_total_bytes;
1083 stats->oerrors = tx_err_total;
1089 eth_stats_reset(struct rte_eth_dev *dev)
1092 uint16_t nb_rx = dev->data->nb_rx_queues;
1093 uint16_t nb_tx = dev->data->nb_tx_queues;
1094 struct pmd_internals *internals = dev->data->dev_private;
1096 for (i = 0; i < nb_rx; i++) {
1097 internals->rx_queue[i].rx_pkts = 0;
1098 internals->rx_queue[i].rx_bytes = 0;
1099 internals->rx_queue[i].err_pkts = 0;
1101 for (i = 0; i < nb_tx; i++) {
1102 internals->tx_queue[i].tx_pkts = 0;
1103 internals->tx_queue[i].tx_bytes = 0;
1104 internals->tx_queue[i].err_pkts = 0;
1109 eth_rx_queue_release(void *q)
1111 struct szedata2_rx_queue *rxq = (struct szedata2_rx_queue *)q;
1112 if (rxq->sze != NULL) {
1113 szedata_close(rxq->sze);
1119 eth_tx_queue_release(void *q)
1121 struct szedata2_tx_queue *txq = (struct szedata2_tx_queue *)q;
1122 if (txq->sze != NULL) {
1123 szedata_close(txq->sze);
1129 eth_dev_close(struct rte_eth_dev *dev)
1132 uint16_t nb_rx = dev->data->nb_rx_queues;
1133 uint16_t nb_tx = dev->data->nb_tx_queues;
1137 for (i = 0; i < nb_rx; i++) {
1138 eth_rx_queue_release(dev->data->rx_queues[i]);
1139 dev->data->rx_queues[i] = NULL;
1141 dev->data->nb_rx_queues = 0;
1142 for (i = 0; i < nb_tx; i++) {
1143 eth_tx_queue_release(dev->data->tx_queues[i]);
1144 dev->data->tx_queues[i] = NULL;
1146 dev->data->nb_tx_queues = 0;
1150 * Function takes value from first IBUF status register.
1151 * Values in IBUF and OBUF should be same.
1154 * Pointer to device private structure.
1156 * Link speed constant.
1158 static inline enum szedata2_link_speed
1159 get_link_speed(const struct pmd_internals *internals)
1161 const volatile struct szedata2_ibuf *ibuf =
1162 ibuf_ptr_by_index(internals->pci_rsc, 0);
1163 uint32_t speed = (szedata2_read32(&ibuf->ibuf_st) & 0x70) >> 4;
1166 return SZEDATA2_LINK_SPEED_10G;
1168 return SZEDATA2_LINK_SPEED_40G;
1170 return SZEDATA2_LINK_SPEED_100G;
1172 return SZEDATA2_LINK_SPEED_DEFAULT;
1177 eth_link_update(struct rte_eth_dev *dev,
1178 int wait_to_complete __rte_unused)
1180 struct rte_eth_link link;
1181 struct pmd_internals *internals = (struct pmd_internals *)
1182 dev->data->dev_private;
1183 const volatile struct szedata2_ibuf *ibuf;
1185 bool link_is_up = false;
1187 memset(&link, 0, sizeof(link));
1189 switch (get_link_speed(internals)) {
1190 case SZEDATA2_LINK_SPEED_10G:
1191 link.link_speed = ETH_SPEED_NUM_10G;
1193 case SZEDATA2_LINK_SPEED_40G:
1194 link.link_speed = ETH_SPEED_NUM_40G;
1196 case SZEDATA2_LINK_SPEED_100G:
1197 link.link_speed = ETH_SPEED_NUM_100G;
1200 link.link_speed = ETH_SPEED_NUM_10G;
1204 /* szedata2 uses only full duplex */
1205 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1207 for (i = 0; i < szedata2_ibuf_count; i++) {
1208 ibuf = ibuf_ptr_by_index(internals->pci_rsc, i);
1210 * Link is considered up if at least one ibuf is enabled
1213 if (ibuf_is_enabled(ibuf) && ibuf_is_link_up(ibuf)) {
1219 link.link_status = link_is_up ? ETH_LINK_UP : ETH_LINK_DOWN;
1221 link.link_autoneg = ETH_LINK_FIXED;
1223 rte_eth_linkstatus_set(dev, &link);
1228 eth_dev_set_link_up(struct rte_eth_dev *dev)
1230 struct pmd_internals *internals = (struct pmd_internals *)
1231 dev->data->dev_private;
1234 for (i = 0; i < szedata2_ibuf_count; i++)
1235 ibuf_enable(ibuf_ptr_by_index(internals->pci_rsc, i));
1236 for (i = 0; i < szedata2_obuf_count; i++)
1237 obuf_enable(obuf_ptr_by_index(internals->pci_rsc, i));
1242 eth_dev_set_link_down(struct rte_eth_dev *dev)
1244 struct pmd_internals *internals = (struct pmd_internals *)
1245 dev->data->dev_private;
1248 for (i = 0; i < szedata2_ibuf_count; i++)
1249 ibuf_disable(ibuf_ptr_by_index(internals->pci_rsc, i));
1250 for (i = 0; i < szedata2_obuf_count; i++)
1251 obuf_disable(obuf_ptr_by_index(internals->pci_rsc, i));
1256 eth_rx_queue_setup(struct rte_eth_dev *dev,
1257 uint16_t rx_queue_id,
1258 uint16_t nb_rx_desc __rte_unused,
1259 unsigned int socket_id __rte_unused,
1260 const struct rte_eth_rxconf *rx_conf __rte_unused,
1261 struct rte_mempool *mb_pool)
1263 struct pmd_internals *internals = dev->data->dev_private;
1264 struct szedata2_rx_queue *rxq = &internals->rx_queue[rx_queue_id];
1266 uint32_t rx = 1 << rx_queue_id;
1269 rxq->sze = szedata_open(internals->sze_dev);
1270 if (rxq->sze == NULL)
1272 ret = szedata_subscribe3(rxq->sze, &rx, &tx);
1273 if (ret != 0 || rx == 0) {
1274 szedata_close(rxq->sze);
1278 rxq->rx_channel = rx_queue_id;
1279 rxq->in_port = dev->data->port_id;
1280 rxq->mb_pool = mb_pool;
1285 dev->data->rx_queues[rx_queue_id] = rxq;
1290 eth_tx_queue_setup(struct rte_eth_dev *dev,
1291 uint16_t tx_queue_id,
1292 uint16_t nb_tx_desc __rte_unused,
1293 unsigned int socket_id __rte_unused,
1294 const struct rte_eth_txconf *tx_conf __rte_unused)
1296 struct pmd_internals *internals = dev->data->dev_private;
1297 struct szedata2_tx_queue *txq = &internals->tx_queue[tx_queue_id];
1300 uint32_t tx = 1 << tx_queue_id;
1302 txq->sze = szedata_open(internals->sze_dev);
1303 if (txq->sze == NULL)
1305 ret = szedata_subscribe3(txq->sze, &rx, &tx);
1306 if (ret != 0 || tx == 0) {
1307 szedata_close(txq->sze);
1311 txq->tx_channel = tx_queue_id;
1316 dev->data->tx_queues[tx_queue_id] = txq;
1321 eth_mac_addr_set(struct rte_eth_dev *dev __rte_unused,
1322 struct ether_addr *mac_addr __rte_unused)
1327 eth_promiscuous_enable(struct rte_eth_dev *dev)
1329 struct pmd_internals *internals = (struct pmd_internals *)
1330 dev->data->dev_private;
1333 for (i = 0; i < szedata2_ibuf_count; i++) {
1334 ibuf_mac_mode_write(ibuf_ptr_by_index(internals->pci_rsc, i),
1335 SZEDATA2_MAC_CHMODE_PROMISC);
1340 eth_promiscuous_disable(struct rte_eth_dev *dev)
1342 struct pmd_internals *internals = (struct pmd_internals *)
1343 dev->data->dev_private;
1346 for (i = 0; i < szedata2_ibuf_count; i++) {
1347 ibuf_mac_mode_write(ibuf_ptr_by_index(internals->pci_rsc, i),
1348 SZEDATA2_MAC_CHMODE_ONLY_VALID);
1353 eth_allmulticast_enable(struct rte_eth_dev *dev)
1355 struct pmd_internals *internals = (struct pmd_internals *)
1356 dev->data->dev_private;
1359 for (i = 0; i < szedata2_ibuf_count; i++) {
1360 ibuf_mac_mode_write(ibuf_ptr_by_index(internals->pci_rsc, i),
1361 SZEDATA2_MAC_CHMODE_ALL_MULTICAST);
1366 eth_allmulticast_disable(struct rte_eth_dev *dev)
1368 struct pmd_internals *internals = (struct pmd_internals *)
1369 dev->data->dev_private;
1372 for (i = 0; i < szedata2_ibuf_count; i++) {
1373 ibuf_mac_mode_write(ibuf_ptr_by_index(internals->pci_rsc, i),
1374 SZEDATA2_MAC_CHMODE_ONLY_VALID);
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, "%4" PRIx16 ":%2" PRIx8 ":%2" PRIx8 ".%" PRIx8,
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 rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
1472 struct rte_eth_dev_data *data = dev->data;
1473 struct pmd_internals *internals = (struct pmd_internals *)
1475 struct szedata *szedata_temp;
1477 uint32_t szedata2_index;
1478 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1479 struct rte_pci_addr *pci_addr = &pci_dev->addr;
1480 struct rte_mem_resource *pci_rsc =
1481 &pci_dev->mem_resource[PCI_RESOURCE_NUMBER];
1482 char rsc_filename[PATH_MAX];
1483 void *pci_resource_ptr = NULL;
1486 RTE_LOG(INFO, PMD, "Initializing szedata2 device (" PCI_PRI_FMT ")\n",
1487 pci_addr->domain, pci_addr->bus, pci_addr->devid,
1488 pci_addr->function);
1490 /* Get index of szedata2 device file and create path to device file */
1491 ret = get_szedata2_index(pci_addr, &szedata2_index);
1493 RTE_LOG(ERR, PMD, "Failed to get szedata2 device index!\n");
1496 snprintf(internals->sze_dev, PATH_MAX, SZEDATA2_DEV_PATH_FMT,
1499 RTE_LOG(INFO, PMD, "SZEDATA2 path: %s\n", internals->sze_dev);
1502 * Get number of available DMA RX and TX channels, which is maximum
1503 * number of queues that can be created and store it in private device
1506 szedata_temp = szedata_open(internals->sze_dev);
1507 if (szedata_temp == NULL) {
1508 RTE_LOG(ERR, PMD, "szedata_open(): failed to open %s",
1509 internals->sze_dev);
1512 internals->max_rx_queues = szedata_ifaces_available(szedata_temp,
1514 internals->max_tx_queues = szedata_ifaces_available(szedata_temp,
1516 szedata_close(szedata_temp);
1518 RTE_LOG(INFO, PMD, "Available DMA channels RX: %u TX: %u\n",
1519 internals->max_rx_queues, internals->max_tx_queues);
1521 /* Set rx, tx burst functions */
1522 if (data->scattered_rx == 1)
1523 dev->rx_pkt_burst = eth_szedata2_rx_scattered;
1525 dev->rx_pkt_burst = eth_szedata2_rx;
1526 dev->tx_pkt_burst = eth_szedata2_tx;
1528 /* Set function callbacks for Ethernet API */
1529 dev->dev_ops = &ops;
1531 rte_eth_copy_pci_info(dev, pci_dev);
1533 /* mmap pci resource0 file to rte_mem_resource structure */
1534 if (pci_dev->mem_resource[PCI_RESOURCE_NUMBER].phys_addr ==
1536 RTE_LOG(ERR, PMD, "Missing resource%u file\n",
1537 PCI_RESOURCE_NUMBER);
1540 snprintf(rsc_filename, PATH_MAX,
1541 "%s/" PCI_PRI_FMT "/resource%u", rte_pci_get_sysfs_path(),
1542 pci_addr->domain, pci_addr->bus,
1543 pci_addr->devid, pci_addr->function, PCI_RESOURCE_NUMBER);
1544 fd = open(rsc_filename, O_RDWR);
1546 RTE_LOG(ERR, PMD, "Could not open file %s\n", rsc_filename);
1550 pci_resource_ptr = mmap(0,
1551 pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len,
1552 PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
1554 if (pci_resource_ptr == MAP_FAILED) {
1555 RTE_LOG(ERR, PMD, "Could not mmap file %s (fd = %d)\n",
1559 pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr = pci_resource_ptr;
1560 internals->pci_rsc = pci_rsc;
1562 RTE_LOG(DEBUG, PMD, "resource%u phys_addr = 0x%llx len = %llu "
1563 "virt addr = %llx\n", PCI_RESOURCE_NUMBER,
1564 (unsigned long long)pci_rsc->phys_addr,
1565 (unsigned long long)pci_rsc->len,
1566 (unsigned long long)pci_rsc->addr);
1568 /* Get link state */
1569 eth_link_update(dev, 0);
1571 /* Allocate space for one mac address */
1572 data->mac_addrs = rte_zmalloc(data->name, sizeof(struct ether_addr),
1573 RTE_CACHE_LINE_SIZE);
1574 if (data->mac_addrs == NULL) {
1575 RTE_LOG(ERR, PMD, "Could not alloc space for MAC address!\n");
1576 munmap(pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr,
1577 pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len);
1581 ether_addr_copy(ð_addr, data->mac_addrs);
1583 /* At initial state COMBO card is in promiscuous mode so disable it */
1584 eth_promiscuous_disable(dev);
1586 RTE_LOG(INFO, PMD, "szedata2 device ("
1587 PCI_PRI_FMT ") successfully initialized\n",
1588 pci_addr->domain, pci_addr->bus, pci_addr->devid,
1589 pci_addr->function);
1595 rte_szedata2_eth_dev_uninit(struct rte_eth_dev *dev)
1597 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1598 struct rte_pci_addr *pci_addr = &pci_dev->addr;
1600 rte_free(dev->data->mac_addrs);
1601 dev->data->mac_addrs = NULL;
1602 munmap(pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr,
1603 pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len);
1605 RTE_LOG(INFO, PMD, "szedata2 device ("
1606 PCI_PRI_FMT ") successfully uninitialized\n",
1607 pci_addr->domain, pci_addr->bus, pci_addr->devid,
1608 pci_addr->function);
1613 static const struct rte_pci_id rte_szedata2_pci_id_table[] = {
1615 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE,
1616 PCI_DEVICE_ID_NETCOPE_COMBO80G)
1619 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE,
1620 PCI_DEVICE_ID_NETCOPE_COMBO100G)
1623 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETCOPE,
1624 PCI_DEVICE_ID_NETCOPE_COMBO100G2)
1631 static int szedata2_eth_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1632 struct rte_pci_device *pci_dev)
1634 return rte_eth_dev_pci_generic_probe(pci_dev,
1635 sizeof(struct pmd_internals), rte_szedata2_eth_dev_init);
1638 static int szedata2_eth_pci_remove(struct rte_pci_device *pci_dev)
1640 return rte_eth_dev_pci_generic_remove(pci_dev,
1641 rte_szedata2_eth_dev_uninit);
1644 static struct rte_pci_driver szedata2_eth_driver = {
1645 .id_table = rte_szedata2_pci_id_table,
1646 .probe = szedata2_eth_pci_probe,
1647 .remove = szedata2_eth_pci_remove,
1650 RTE_PMD_REGISTER_PCI(RTE_SZEDATA2_DRIVER_NAME, szedata2_eth_driver);
1651 RTE_PMD_REGISTER_PCI_TABLE(RTE_SZEDATA2_DRIVER_NAME, rte_szedata2_pci_id_table);
1652 RTE_PMD_REGISTER_KMOD_DEP(RTE_SZEDATA2_DRIVER_NAME,
1653 "* combo6core & combov3 & szedata2 & szedata2_cv3");