2 // Copyright (c) 2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
20 * Reads the packet from the interface and sets the
21 * masks for a burst of packets based on ethertype and
22 * calls the relevant function registered for that ethertype
34 #include <sys/types.h>
35 #include <sys/queue.h>
36 #include <netinet/in.h>
45 #include <rte_common.h>
47 #include <rte_malloc.h>
48 #include <rte_memory.h>
49 #include <rte_memcpy.h>
50 #include <rte_memzone.h>
52 #include <rte_per_lcore.h>
53 #include <rte_launch.h>
54 #include <rte_atomic.h>
55 #include <rte_cycles.h>
56 #include <rte_prefetch.h>
57 #include <rte_lcore.h>
58 #include <rte_per_lcore.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_interrupts.h>
62 #include <rte_random.h>
63 #include <rte_debug.h>
64 #include <rte_ether.h>
65 #include <rte_ethdev.h>
68 #include <rte_mempool.h>
70 #include <rte_eth_ctrl.h>
71 #include <interface.h>
73 /* Array indexes of proto_packet_type structure */
74 #define IPv4_VAL 0 /**< Array index for IPv4 */
75 #define ARP_VAL 1 /**< Array index for ARP */
76 #define IPv6_VAL 2 /**< Array index for IPv6 */
78 /* Enable to print L2_Proto debugs */
79 #define L2_PROTO_DBG 1 /**< Enable to print L2 Proto debugs */
82 * A structure used to call the function handlers for a certain ethertype
84 struct proto_packet_type {
85 uint16_t type; /**< Ethertype */
86 void (*func) (struct rte_mbuf **m, uint16_t nb_pkts, uint64_t pkt_mask, l2_phy_interface_t *port); /**< Function pointer to the registered callback function */
87 } __rte_cache_aligned;/**< RTE Cache alignment */
90 * Function called from other modules to add the certain rx functions for particular ethertypes
95 * Function pointer to the function being registered by different modules
98 list_add_type(uint16_t type,
99 void (*func) (struct rte_mbuf **, uint16_t, uint64_t,
100 l2_phy_interface_t *));
103 * Function to check whether the destination mac address of the packet is the mac address of the received port.
104 * Drop the packet if it is not destined to the host.
105 * If it is destined to this host, then set the packet masks for IPv4, IPv6 and ARP packet types for a burst of packets.
111 * Portid from which the packet was received
114 * Index of the packet in the burst
117 * Packet mask where bits are set at positions for the packets in the burst which were destined to the host
119 * @param arp_pkts_mask
120 * Packet mask for ARP where bits are set for valid ARP packets
122 * @param ipv4_pkts_mask
123 * Packet mask for IPv4 where bits are set for valid IPv4 packets
125 * @param ipv6_pkts_mask
126 * Packet mask for IPv6 where bits are set for valid IPv6 packets
130 l2_check_mac(struct rte_mbuf *m[IFM_BURST_SIZE], l2_phy_interface_t *port,
131 uint8_t pos, uint64_t *pkts_mask, uint64_t *arp_pkts_mask,
132 uint64_t *ipv4_pkts_mask, uint64_t *ipv6_pkts_mask);
135 * Entry function to L2 Protocol Handler where appropriate functions are called for particular ethertypes
141 * Number of packets read
144 * Port-id of the port in which packet was received
147 protocol_handler_recv(struct rte_mbuf *m[IFM_BURST_SIZE], uint16_t nb_rx,
148 l2_phy_interface_t *port);