Lines Matching refs:ring
66 struct ring { struct
71 void (*walk)(int sock, struct ring *ring); argument
220 static void walk_v1_v2_rx(int sock, struct ring *ring) in walk_v1_v2_rx() argument
227 bug_on(ring->type != PACKET_RX_RING); in walk_v1_v2_rx()
239 while (__v1_v2_rx_kernel_ready(ring->rd[frame_num].iov_base, in walk_v1_v2_rx()
240 ring->version)) { in walk_v1_v2_rx()
241 ppd.raw = ring->rd[frame_num].iov_base; in walk_v1_v2_rx()
243 switch (ring->version) { in walk_v1_v2_rx()
260 __v1_v2_rx_user_ready(ppd.raw, ring->version); in walk_v1_v2_rx()
262 frame_num = (frame_num + 1) % ring->rd_num; in walk_v1_v2_rx()
272 ring->version, total_packets, NUM_PACKETS); in walk_v1_v2_rx()
354 static inline void *get_next_frame(struct ring *ring, int n) in get_next_frame() argument
356 uint8_t *f0 = ring->rd[0].iov_base; in get_next_frame()
358 switch (ring->version) { in get_next_frame()
361 return ring->rd[n].iov_base; in get_next_frame()
363 return f0 + (n * ring->req3.tp_frame_size); in get_next_frame()
369 static void walk_tx(int sock, struct ring *ring) in walk_tx() argument
387 if (ring->version <= TPACKET_V2) in walk_tx()
388 nframes = ring->rd_num; in walk_tx()
390 nframes = ring->req3.tp_frame_nr; in walk_tx()
392 bug_on(ring->type != PACKET_TX_RING); in walk_tx()
419 void *next = get_next_frame(ring, frame_num); in walk_tx()
421 while (__tx_kernel_ready(next, ring->version) && in walk_tx()
425 switch (ring->version) { in walk_tx()
463 __tx_user_ready(next, ring->version); in walk_tx()
493 ring->version, total_packets, NUM_PACKETS); in walk_tx()
500 static void walk_v1_v2(int sock, struct ring *ring) in walk_v1_v2() argument
502 if (ring->type == PACKET_RX_RING) in walk_v1_v2()
503 walk_v1_v2_rx(sock, ring); in walk_v1_v2()
505 walk_tx(sock, ring); in walk_v1_v2()
581 static void walk_v3_rx(int sock, struct ring *ring) in walk_v3_rx() argument
588 bug_on(ring->type != PACKET_RX_RING); in walk_v3_rx()
600 pbd = (struct block_desc *) ring->rd[block_num].iov_base; in walk_v3_rx()
608 block_num = (block_num + 1) % ring->rd_num; in walk_v3_rx()
622 static void walk_v3(int sock, struct ring *ring) in walk_v3() argument
624 if (ring->type == PACKET_RX_RING) in walk_v3()
625 walk_v3_rx(sock, ring); in walk_v3()
627 walk_tx(sock, ring); in walk_v3()
630 static void __v1_v2_fill(struct ring *ring, unsigned int blocks) in __v1_v2_fill() argument
632 ring->req.tp_block_size = getpagesize() << 2; in __v1_v2_fill()
633 ring->req.tp_frame_size = TPACKET_ALIGNMENT << 7; in __v1_v2_fill()
634 ring->req.tp_block_nr = blocks; in __v1_v2_fill()
636 ring->req.tp_frame_nr = ring->req.tp_block_size / in __v1_v2_fill()
637 ring->req.tp_frame_size * in __v1_v2_fill()
638 ring->req.tp_block_nr; in __v1_v2_fill()
640 ring->mm_len = ring->req.tp_block_size * ring->req.tp_block_nr; in __v1_v2_fill()
641 ring->walk = walk_v1_v2; in __v1_v2_fill()
642 ring->rd_num = ring->req.tp_frame_nr; in __v1_v2_fill()
643 ring->flen = ring->req.tp_frame_size; in __v1_v2_fill()
646 static void __v3_fill(struct ring *ring, unsigned int blocks, int type) in __v3_fill() argument
649 ring->req3.tp_retire_blk_tov = 64; in __v3_fill()
650 ring->req3.tp_sizeof_priv = 0; in __v3_fill()
651 ring->req3.tp_feature_req_word = TP_FT_REQ_FILL_RXHASH; in __v3_fill()
653 ring->req3.tp_block_size = getpagesize() << 2; in __v3_fill()
654 ring->req3.tp_frame_size = TPACKET_ALIGNMENT << 7; in __v3_fill()
655 ring->req3.tp_block_nr = blocks; in __v3_fill()
657 ring->req3.tp_frame_nr = ring->req3.tp_block_size / in __v3_fill()
658 ring->req3.tp_frame_size * in __v3_fill()
659 ring->req3.tp_block_nr; in __v3_fill()
661 ring->mm_len = ring->req3.tp_block_size * ring->req3.tp_block_nr; in __v3_fill()
662 ring->walk = walk_v3; in __v3_fill()
663 ring->rd_num = ring->req3.tp_block_nr; in __v3_fill()
664 ring->flen = ring->req3.tp_block_size; in __v3_fill()
667 static void setup_ring(int sock, struct ring *ring, int version, int type) in setup_ring() argument
672 ring->type = type; in setup_ring()
673 ring->version = version; in setup_ring()
680 __v1_v2_fill(ring, blocks); in setup_ring()
681 ret = setsockopt(sock, SOL_PACKET, type, &ring->req, in setup_ring()
682 sizeof(ring->req)); in setup_ring()
686 __v3_fill(ring, blocks, type); in setup_ring()
687 ret = setsockopt(sock, SOL_PACKET, type, &ring->req3, in setup_ring()
688 sizeof(ring->req3)); in setup_ring()
697 ring->rd_len = ring->rd_num * sizeof(*ring->rd); in setup_ring()
698 ring->rd = malloc(ring->rd_len); in setup_ring()
699 if (ring->rd == NULL) { in setup_ring()
708 static void mmap_ring(int sock, struct ring *ring) in mmap_ring() argument
712 ring->mm_space = mmap(0, ring->mm_len, PROT_READ | PROT_WRITE, in mmap_ring()
714 if (ring->mm_space == MAP_FAILED) { in mmap_ring()
719 memset(ring->rd, 0, ring->rd_len); in mmap_ring()
720 for (i = 0; i < ring->rd_num; ++i) { in mmap_ring()
721 ring->rd[i].iov_base = ring->mm_space + (i * ring->flen); in mmap_ring()
722 ring->rd[i].iov_len = ring->flen; in mmap_ring()
726 static void bind_ring(int sock, struct ring *ring) in bind_ring() argument
732 ring->ll.sll_family = PF_PACKET; in bind_ring()
733 ring->ll.sll_protocol = htons(ETH_P_ALL); in bind_ring()
734 ring->ll.sll_ifindex = if_nametoindex("lo"); in bind_ring()
735 ring->ll.sll_hatype = 0; in bind_ring()
736 ring->ll.sll_pkttype = 0; in bind_ring()
737 ring->ll.sll_halen = 0; in bind_ring()
739 ret = bind(sock, (struct sockaddr *) &ring->ll, sizeof(ring->ll)); in bind_ring()
746 static void walk_ring(int sock, struct ring *ring) in walk_ring() argument
748 ring->walk(sock, ring); in walk_ring()
751 static void unmap_ring(int sock, struct ring *ring) in unmap_ring() argument
753 munmap(ring->mm_space, ring->mm_len); in unmap_ring()
754 free(ring->rd); in unmap_ring()
805 struct ring ring; in test_tpacket() local
820 memset(&ring, 0, sizeof(ring)); in test_tpacket()
821 setup_ring(sock, &ring, version, type); in test_tpacket()
822 mmap_ring(sock, &ring); in test_tpacket()
823 bind_ring(sock, &ring); in test_tpacket()
824 walk_ring(sock, &ring); in test_tpacket()
825 unmap_ring(sock, &ring); in test_tpacket()