Path: blob/master/arch/tile/include/hv/netio_intf.h
10819 views
/*1* Copyright 2010 Tilera Corporation. All Rights Reserved.2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* as published by the Free Software Foundation, version 2.6*7* This program is distributed in the hope that it will be useful, but8* WITHOUT ANY WARRANTY; without even the implied warranty of9* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or10* NON INFRINGEMENT. See the GNU General Public License for11* more details.12*/1314/**15* NetIO interface structures and macros.16*/1718#ifndef __NETIO_INTF_H__19#define __NETIO_INTF_H__2021#include <hv/netio_errors.h>2223#ifdef __KERNEL__24#include <linux/types.h>25#else26#include <stdint.h>27#endif2829#if !defined(__HV__) && !defined(__BOGUX__) && !defined(__KERNEL__)30#include <assert.h>31#define netio_assert assert /**< Enable assertions from macros */32#else33#define netio_assert(...) ((void)(0)) /**< Disable assertions from macros */34#endif3536/*37* If none of these symbols are defined, we're building libnetio in an38* environment where we have pthreads, so we'll enable locking.39*/40#if !defined(__HV__) && !defined(__BOGUX__) && !defined(__KERNEL__) && \41!defined(__NEWLIB__)42#define _NETIO_PTHREAD /**< Include a mutex in netio_queue_t below */4344/*45* If NETIO_UNLOCKED is defined, we don't do use per-cpu locks on46* per-packet NetIO operations. We still do pthread locking on things47* like netio_input_register, though. This is used for building48* libnetio_unlocked.49*/50#ifndef NETIO_UNLOCKED5152/* Avoid PLT overhead by using our own inlined per-cpu lock. */53#include <sched.h>54typedef int _netio_percpu_mutex_t;5556static __inline int57_netio_percpu_mutex_init(_netio_percpu_mutex_t* lock)58{59*lock = 0;60return 0;61}6263static __inline int64_netio_percpu_mutex_lock(_netio_percpu_mutex_t* lock)65{66while (__builtin_expect(__insn_tns(lock), 0))67sched_yield();68return 0;69}7071static __inline int72_netio_percpu_mutex_unlock(_netio_percpu_mutex_t* lock)73{74*lock = 0;75return 0;76}7778#else /* NETIO_UNLOCKED */7980/* Don't do any locking for per-packet NetIO operations. */81typedef int _netio_percpu_mutex_t;82#define _netio_percpu_mutex_init(L)83#define _netio_percpu_mutex_lock(L)84#define _netio_percpu_mutex_unlock(L)8586#endif /* NETIO_UNLOCKED */87#endif /* !__HV__, !__BOGUX, !__KERNEL__, !__NEWLIB__ */8889/** How many tiles can register for a given queue.90* @ingroup setup */91#define NETIO_MAX_TILES_PER_QUEUE 64929394/** Largest permissible queue identifier.95* @ingroup setup */96#define NETIO_MAX_QUEUE_ID 255979899#ifndef __DOXYGEN__100101/* Metadata packet checksum/ethertype flags. */102103/** The L4 checksum has not been calculated. */104#define _NETIO_PKT_NO_L4_CSUM_SHIFT 0105#define _NETIO_PKT_NO_L4_CSUM_RMASK 1106#define _NETIO_PKT_NO_L4_CSUM_MASK \107(_NETIO_PKT_NO_L4_CSUM_RMASK << _NETIO_PKT_NO_L4_CSUM_SHIFT)108109/** The L3 checksum has not been calculated. */110#define _NETIO_PKT_NO_L3_CSUM_SHIFT 1111#define _NETIO_PKT_NO_L3_CSUM_RMASK 1112#define _NETIO_PKT_NO_L3_CSUM_MASK \113(_NETIO_PKT_NO_L3_CSUM_RMASK << _NETIO_PKT_NO_L3_CSUM_SHIFT)114115/** The L3 checksum is incorrect (or perhaps has not been calculated). */116#define _NETIO_PKT_BAD_L3_CSUM_SHIFT 2117#define _NETIO_PKT_BAD_L3_CSUM_RMASK 1118#define _NETIO_PKT_BAD_L3_CSUM_MASK \119(_NETIO_PKT_BAD_L3_CSUM_RMASK << _NETIO_PKT_BAD_L3_CSUM_SHIFT)120121/** The Ethernet packet type is unrecognized. */122#define _NETIO_PKT_TYPE_UNRECOGNIZED_SHIFT 3123#define _NETIO_PKT_TYPE_UNRECOGNIZED_RMASK 1124#define _NETIO_PKT_TYPE_UNRECOGNIZED_MASK \125(_NETIO_PKT_TYPE_UNRECOGNIZED_RMASK << \126_NETIO_PKT_TYPE_UNRECOGNIZED_SHIFT)127128/* Metadata packet type flags. */129130/** Where the packet type bits are; this field is the index into131* _netio_pkt_info. */132#define _NETIO_PKT_TYPE_SHIFT 4133#define _NETIO_PKT_TYPE_RMASK 0x3F134135/** How many VLAN tags the packet has, and, if we have two, which one we136* actually grouped on. A VLAN within a proprietary (Marvell or Broadcom)137* tag is counted here. */138#define _NETIO_PKT_VLAN_SHIFT 4139#define _NETIO_PKT_VLAN_RMASK 0x3140#define _NETIO_PKT_VLAN_MASK \141(_NETIO_PKT_VLAN_RMASK << _NETIO_PKT_VLAN_SHIFT)142#define _NETIO_PKT_VLAN_NONE 0 /* No VLAN tag. */143#define _NETIO_PKT_VLAN_ONE 1 /* One VLAN tag. */144#define _NETIO_PKT_VLAN_TWO_OUTER 2 /* Two VLAN tags, outer one used. */145#define _NETIO_PKT_VLAN_TWO_INNER 3 /* Two VLAN tags, inner one used. */146147/** Which proprietary tags the packet has. */148#define _NETIO_PKT_TAG_SHIFT 6149#define _NETIO_PKT_TAG_RMASK 0x3150#define _NETIO_PKT_TAG_MASK \151(_NETIO_PKT_TAG_RMASK << _NETIO_PKT_TAG_SHIFT)152#define _NETIO_PKT_TAG_NONE 0 /* No proprietary tags. */153#define _NETIO_PKT_TAG_MRVL 1 /* Marvell HyperG.Stack tags. */154#define _NETIO_PKT_TAG_MRVL_EXT 2 /* HyperG.Stack extended tags. */155#define _NETIO_PKT_TAG_BRCM 3 /* Broadcom HiGig tags. */156157/** Whether a packet has an LLC + SNAP header. */158#define _NETIO_PKT_SNAP_SHIFT 8159#define _NETIO_PKT_SNAP_RMASK 0x1160#define _NETIO_PKT_SNAP_MASK \161(_NETIO_PKT_SNAP_RMASK << _NETIO_PKT_SNAP_SHIFT)162163/* NOTE: Bits 9 and 10 are unused. */164165/** Length of any custom data before the L2 header, in words. */166#define _NETIO_PKT_CUSTOM_LEN_SHIFT 11167#define _NETIO_PKT_CUSTOM_LEN_RMASK 0x1F168#define _NETIO_PKT_CUSTOM_LEN_MASK \169(_NETIO_PKT_CUSTOM_LEN_RMASK << _NETIO_PKT_CUSTOM_LEN_SHIFT)170171/** The L4 checksum is incorrect (or perhaps has not been calculated). */172#define _NETIO_PKT_BAD_L4_CSUM_SHIFT 16173#define _NETIO_PKT_BAD_L4_CSUM_RMASK 0x1174#define _NETIO_PKT_BAD_L4_CSUM_MASK \175(_NETIO_PKT_BAD_L4_CSUM_RMASK << _NETIO_PKT_BAD_L4_CSUM_SHIFT)176177/** Length of the L2 header, in words. */178#define _NETIO_PKT_L2_LEN_SHIFT 17179#define _NETIO_PKT_L2_LEN_RMASK 0x1F180#define _NETIO_PKT_L2_LEN_MASK \181(_NETIO_PKT_L2_LEN_RMASK << _NETIO_PKT_L2_LEN_SHIFT)182183184/* Flags in minimal packet metadata. */185186/** We need an eDMA checksum on this packet. */187#define _NETIO_PKT_NEED_EDMA_CSUM_SHIFT 0188#define _NETIO_PKT_NEED_EDMA_CSUM_RMASK 1189#define _NETIO_PKT_NEED_EDMA_CSUM_MASK \190(_NETIO_PKT_NEED_EDMA_CSUM_RMASK << _NETIO_PKT_NEED_EDMA_CSUM_SHIFT)191192/* Data within the packet information table. */193194/* Note that, for efficiency, code which uses these fields assumes that none195* of the shift values below are zero. See uses below for an explanation. */196197/** Offset within the L2 header of the innermost ethertype (in halfwords). */198#define _NETIO_PKT_INFO_ETYPE_SHIFT 6199#define _NETIO_PKT_INFO_ETYPE_RMASK 0x1F200201/** Offset within the L2 header of the VLAN tag (in halfwords). */202#define _NETIO_PKT_INFO_VLAN_SHIFT 11203#define _NETIO_PKT_INFO_VLAN_RMASK 0x1F204205#endif206207208/** The size of a memory buffer representing a small packet.209* @ingroup egress */210#define SMALL_PACKET_SIZE 256211212/** The size of a memory buffer representing a large packet.213* @ingroup egress */214#define LARGE_PACKET_SIZE 2048215216/** The size of a memory buffer representing a jumbo packet.217* @ingroup egress */218#define JUMBO_PACKET_SIZE (12 * 1024)219220221/* Common ethertypes.222* @ingroup ingress */223/** @{ */224/** The ethertype of IPv4. */225#define ETHERTYPE_IPv4 (0x0800)226/** The ethertype of ARP. */227#define ETHERTYPE_ARP (0x0806)228/** The ethertype of VLANs. */229#define ETHERTYPE_VLAN (0x8100)230/** The ethertype of a Q-in-Q header. */231#define ETHERTYPE_Q_IN_Q (0x9100)232/** The ethertype of IPv6. */233#define ETHERTYPE_IPv6 (0x86DD)234/** The ethertype of MPLS. */235#define ETHERTYPE_MPLS (0x8847)236/** @} */237238239/** The possible return values of NETIO_PKT_STATUS.240* @ingroup ingress241*/242typedef enum243{244/** No problems were detected with this packet. */245NETIO_PKT_STATUS_OK,246/** The packet is undersized; this is expected behavior if the packet's247* ethertype is unrecognized, but otherwise the packet is likely corrupt. */248NETIO_PKT_STATUS_UNDERSIZE,249/** The packet is oversized and some trailing bytes have been discarded.250This is expected behavior for short packets, since it's impossible to251precisely determine the amount of padding which may have been added to252them to make them meet the minimum Ethernet packet size. */253NETIO_PKT_STATUS_OVERSIZE,254/** The packet was judged to be corrupt by hardware (for instance, it had255a bad CRC, or part of it was discarded due to lack of buffer space in256the I/O shim) and should be discarded. */257NETIO_PKT_STATUS_BAD258} netio_pkt_status_t;259260261/** Log2 of how many buckets we have. */262#define NETIO_LOG2_NUM_BUCKETS (10)263264/** How many buckets we have.265* @ingroup ingress */266#define NETIO_NUM_BUCKETS (1 << NETIO_LOG2_NUM_BUCKETS)267268269/**270* @brief A group-to-bucket identifier.271*272* @ingroup setup273*274* This tells us what to do with a given group.275*/276typedef union {277/** The header broken down into bits. */278struct {279/** Whether we should balance on L4, if available */280unsigned int __balance_on_l4:1;281/** Whether we should balance on L3, if available */282unsigned int __balance_on_l3:1;283/** Whether we should balance on L2, if available */284unsigned int __balance_on_l2:1;285/** Reserved for future use */286unsigned int __reserved:1;287/** The base bucket to use to send traffic */288unsigned int __bucket_base:NETIO_LOG2_NUM_BUCKETS;289/** The mask to apply to the balancing value. This must be one less290* than a power of two, e.g. 0x3 or 0xFF.291*/292unsigned int __bucket_mask:NETIO_LOG2_NUM_BUCKETS;293/** Pad to 32 bits */294unsigned int __padding:(32 - 4 - 2 * NETIO_LOG2_NUM_BUCKETS);295} bits;296/** To send out the IDN. */297unsigned int word;298}299netio_group_t;300301302/**303* @brief A VLAN-to-bucket identifier.304*305* @ingroup setup306*307* This tells us what to do with a given VLAN.308*/309typedef netio_group_t netio_vlan_t;310311312/**313* A bucket-to-queue mapping.314* @ingroup setup315*/316typedef unsigned char netio_bucket_t;317318319/**320* A packet size can always fit in a netio_size_t.321* @ingroup setup322*/323typedef unsigned int netio_size_t;324325326/**327* @brief Ethernet standard (ingress) packet metadata.328*329* @ingroup ingress330*331* This is additional data associated with each packet.332* This structure is opaque and accessed through the @ref ingress.333*334* Also, the buffer population operation currently assumes that standard335* metadata is at least as large as minimal metadata, and will need to be336* modified if that is no longer the case.337*/338typedef struct339{340#ifdef __DOXYGEN__341/** This structure is opaque. */342unsigned char opaque[24];343#else344/** The overall ordinal of the packet */345unsigned int __packet_ordinal;346/** The ordinal of the packet within the group */347unsigned int __group_ordinal;348/** The best flow hash IPP could compute. */349unsigned int __flow_hash;350/** Flags pertaining to checksum calculation, packet type, etc. */351unsigned int __flags;352/** The first word of "user data". */353unsigned int __user_data_0;354/** The second word of "user data". */355unsigned int __user_data_1;356#endif357}358netio_pkt_metadata_t;359360361/** To ensure that the L3 header is aligned mod 4, the L2 header should be362* aligned mod 4 plus 2, since every supported L2 header is 4n + 2 bytes363* long. The standard way to do this is to simply add 2 bytes of padding364* before the L2 header.365*/366#define NETIO_PACKET_PADDING 2367368369370/**371* @brief Ethernet minimal (egress) packet metadata.372*373* @ingroup egress374*375* This structure represents information about packets which have376* been processed by @ref netio_populate_buffer() or377* @ref netio_populate_prepend_buffer(). This structure is opaque378* and accessed through the @ref egress.379*380* @internal This structure is actually copied into the memory used by381* standard metadata, which is assumed to be large enough.382*/383typedef struct384{385#ifdef __DOXYGEN__386/** This structure is opaque. */387unsigned char opaque[14];388#else389/** The offset of the L2 header from the start of the packet data. */390unsigned short l2_offset;391/** The offset of the L3 header from the start of the packet data. */392unsigned short l3_offset;393/** Where to write the checksum. */394unsigned char csum_location;395/** Where to start checksumming from. */396unsigned char csum_start;397/** Flags pertaining to checksum calculation etc. */398unsigned short flags;399/** The L2 length of the packet. */400unsigned short l2_length;401/** The checksum with which to seed the checksum generator. */402unsigned short csum_seed;403/** How much to checksum. */404unsigned short csum_length;405#endif406}407netio_pkt_minimal_metadata_t;408409410#ifndef __DOXYGEN__411412/**413* @brief An I/O notification header.414*415* This is the first word of data received from an I/O shim in a notification416* packet. It contains framing and status information.417*/418typedef union419{420unsigned int word; /**< The whole word. */421/** The various fields. */422struct423{424unsigned int __channel:7; /**< Resource channel. */425unsigned int __type:4; /**< Type. */426unsigned int __ack:1; /**< Whether an acknowledgement is needed. */427unsigned int __reserved:1; /**< Reserved. */428unsigned int __protocol:1; /**< A protocol-specific word is added. */429unsigned int __status:2; /**< Status of the transfer. */430unsigned int __framing:2; /**< Framing of the transfer. */431unsigned int __transfer_size:14; /**< Transfer size in bytes (total). */432} bits;433}434__netio_pkt_notif_t;435436437/**438* Returns the base address of the packet.439*/440#define _NETIO_PKT_HANDLE_BASE(p) \441((unsigned char*)((p).word & 0xFFFFFFC0))442443/**444* Returns the base address of the packet.445*/446#define _NETIO_PKT_BASE(p) \447_NETIO_PKT_HANDLE_BASE(p->__packet)448449/**450* @brief An I/O notification packet (second word)451*452* This is the second word of data received from an I/O shim in a notification453* packet. This is the virtual address of the packet buffer, plus some flag454* bits. (The virtual address of the packet is always 256-byte aligned so we455* have room for 8 bits' worth of flags in the low 8 bits.)456*457* @internal458* NOTE: The low two bits must contain "__queue", so the "packet size"459* (SIZE_SMALL, SIZE_LARGE, or SIZE_JUMBO) can be determined quickly.460*461* If __addr or __offset are moved, _NETIO_PKT_BASE462* (defined right below this) must be changed.463*/464typedef union465{466unsigned int word; /**< The whole word. */467/** The various fields. */468struct469{470/** Which queue the packet will be returned to once it is sent back to471the IPP. This is one of the SIZE_xxx values. */472unsigned int __queue:2;473474/** The IPP handle of the sending IPP. */475unsigned int __ipp_handle:2;476477/** Reserved for future use. */478unsigned int __reserved:1;479480/** If 1, this packet has minimal (egress) metadata; otherwise, it481has standard (ingress) metadata. */482unsigned int __minimal:1;483484/** Offset of the metadata within the packet. This value is multiplied485* by 64 and added to the base packet address to get the metadata486* address. Note that this field is aligned within the word such that487* you can easily extract the metadata address with a 26-bit mask. */488unsigned int __offset:2;489490/** The top 24 bits of the packet's virtual address. */491unsigned int __addr:24;492} bits;493}494__netio_pkt_handle_t;495496#endif /* !__DOXYGEN__ */497498499/**500* @brief A handle for an I/O packet's storage.501* @ingroup ingress502*503* netio_pkt_handle_t encodes the concept of a ::netio_pkt_t with its504* packet metadata removed. It is a much smaller type that exists to505* facilitate applications where the full ::netio_pkt_t type is too506* large, such as those that cache enormous numbers of packets or wish507* to transmit packet descriptors over the UDN.508*509* Because there is no metadata, most ::netio_pkt_t operations cannot be510* performed on a netio_pkt_handle_t. It supports only511* netio_free_handle() (to free the buffer) and512* NETIO_PKT_CUSTOM_DATA_H() (to access a pointer to its contents).513* The application must acquire any additional metadata it wants from the514* original ::netio_pkt_t and record it separately.515*516* A netio_pkt_handle_t can be extracted from a ::netio_pkt_t by calling517* NETIO_PKT_HANDLE(). An invalid handle (analogous to NULL) can be518* created by assigning the value ::NETIO_PKT_HANDLE_NONE. A handle can519* be tested for validity with NETIO_PKT_HANDLE_IS_VALID().520*/521typedef struct522{523unsigned int word; /**< Opaque bits. */524} netio_pkt_handle_t;525526/**527* @brief A packet descriptor.528*529* @ingroup ingress530* @ingroup egress531*532* This data structure represents a packet. The structure is manipulated533* through the @ref ingress and the @ref egress.534*535* While the contents of a netio_pkt_t are opaque, the structure itself is536* portable. This means that it may be shared between all tiles which have537* done a netio_input_register() call for the interface on which the pkt_t538* was initially received (via netio_get_packet()) or retrieved (via539* netio_get_buffer()). The contents of a netio_pkt_t can be transmitted to540* another tile via shared memory, or via a UDN message, or by other means.541* The destination tile may then use the pkt_t as if it had originally been542* received locally; it may read or write the packet's data, read its543* metadata, free the packet, send the packet, transfer the netio_pkt_t to544* yet another tile, and so forth.545*546* Once a netio_pkt_t has been transferred to a second tile, the first tile547* should not reference the original copy; in particular, if more than one548* tile frees or sends the same netio_pkt_t, the IPP's packet free lists will549* become corrupted. Note also that each tile which reads or modifies550* packet data must obey the memory coherency rules outlined in @ref input.551*/552typedef struct553{554#ifdef __DOXYGEN__555/** This structure is opaque. */556unsigned char opaque[32];557#else558/** For an ingress packet (one with standard metadata), this is the559* notification header we got from the I/O shim. For an egress packet560* (one with minimal metadata), this word is zero if the packet has not561* been populated, and nonzero if it has. */562__netio_pkt_notif_t __notif_header;563564/** Virtual address of the packet buffer, plus state flags. */565__netio_pkt_handle_t __packet;566567/** Metadata associated with the packet. */568netio_pkt_metadata_t __metadata;569#endif570}571netio_pkt_t;572573574#ifndef __DOXYGEN__575576#define __NETIO_PKT_NOTIF_HEADER(pkt) ((pkt)->__notif_header)577#define __NETIO_PKT_IPP_HANDLE(pkt) ((pkt)->__packet.bits.__ipp_handle)578#define __NETIO_PKT_QUEUE(pkt) ((pkt)->__packet.bits.__queue)579#define __NETIO_PKT_NOTIF_HEADER_M(mda, pkt) ((pkt)->__notif_header)580#define __NETIO_PKT_IPP_HANDLE_M(mda, pkt) ((pkt)->__packet.bits.__ipp_handle)581#define __NETIO_PKT_MINIMAL(pkt) ((pkt)->__packet.bits.__minimal)582#define __NETIO_PKT_QUEUE_M(mda, pkt) ((pkt)->__packet.bits.__queue)583#define __NETIO_PKT_FLAGS_M(mda, pkt) ((mda)->__flags)584585/* Packet information table, used by the attribute access functions below. */586extern const uint16_t _netio_pkt_info[];587588#endif /* __DOXYGEN__ */589590591#ifndef __DOXYGEN__592/* These macros are deprecated and will disappear in a future MDE release. */593#define NETIO_PKT_GOOD_CHECKSUM(pkt) \594NETIO_PKT_L4_CSUM_CORRECT(pkt)595#define NETIO_PKT_GOOD_CHECKSUM_M(mda, pkt) \596NETIO_PKT_L4_CSUM_CORRECT_M(mda, pkt)597#endif /* __DOXYGEN__ */598599600/* Packet attribute access functions. */601602/** Return a pointer to the metadata for a packet.603* @ingroup ingress604*605* Calling this function once and passing the result to other retrieval606* functions with a "_M" suffix usually improves performance. This607* function must be called on an 'ingress' packet (i.e. one retrieved608* by @ref netio_get_packet(), on which @ref netio_populate_buffer() or609* @ref netio_populate_prepend_buffer have not been called). Use of this610* function on an 'egress' packet will cause an assertion failure.611*612* @param[in] pkt Packet on which to operate.613* @return A pointer to the packet's standard metadata.614*/615static __inline netio_pkt_metadata_t*616NETIO_PKT_METADATA(netio_pkt_t* pkt)617{618netio_assert(!pkt->__packet.bits.__minimal);619return &pkt->__metadata;620}621622623/** Return a pointer to the minimal metadata for a packet.624* @ingroup egress625*626* Calling this function once and passing the result to other retrieval627* functions with a "_MM" suffix usually improves performance. This628* function must be called on an 'egress' packet (i.e. one on which629* @ref netio_populate_buffer() or @ref netio_populate_prepend_buffer()630* have been called, or one retrieved by @ref netio_get_buffer()). Use of631* this function on an 'ingress' packet will cause an assertion failure.632*633* @param[in] pkt Packet on which to operate.634* @return A pointer to the packet's standard metadata.635*/636static __inline netio_pkt_minimal_metadata_t*637NETIO_PKT_MINIMAL_METADATA(netio_pkt_t* pkt)638{639netio_assert(pkt->__packet.bits.__minimal);640return (netio_pkt_minimal_metadata_t*) &pkt->__metadata;641}642643644/** Determine whether a packet has 'minimal' metadata.645* @ingroup pktfuncs646*647* This function will return nonzero if the packet is an 'egress'648* packet (i.e. one on which @ref netio_populate_buffer() or649* @ref netio_populate_prepend_buffer() have been called, or one650* retrieved by @ref netio_get_buffer()), and zero if the packet651* is an 'ingress' packet (i.e. one retrieved by @ref netio_get_packet(),652* which has not been converted into an 'egress' packet).653*654* @param[in] pkt Packet on which to operate.655* @return Nonzero if the packet has minimal metadata.656*/657static __inline unsigned int658NETIO_PKT_IS_MINIMAL(netio_pkt_t* pkt)659{660return pkt->__packet.bits.__minimal;661}662663664/** Return a handle for a packet's storage.665* @ingroup pktfuncs666*667* @param[in] pkt Packet on which to operate.668* @return A handle for the packet's storage.669*/670static __inline netio_pkt_handle_t671NETIO_PKT_HANDLE(netio_pkt_t* pkt)672{673netio_pkt_handle_t h;674h.word = pkt->__packet.word;675return h;676}677678679/** A special reserved value indicating the absence of a packet handle.680*681* @ingroup pktfuncs682*/683#define NETIO_PKT_HANDLE_NONE ((netio_pkt_handle_t) { 0 })684685686/** Test whether a packet handle is valid.687*688* Applications may wish to use the reserved value NETIO_PKT_HANDLE_NONE689* to indicate no packet at all. This function tests to see if a packet690* handle is a real handle, not this special reserved value.691*692* @ingroup pktfuncs693*694* @param[in] handle Handle on which to operate.695* @return One if the packet handle is valid, else zero.696*/697static __inline unsigned int698NETIO_PKT_HANDLE_IS_VALID(netio_pkt_handle_t handle)699{700return handle.word != 0;701}702703704705/** Return a pointer to the start of the packet's custom header.706* A custom header may or may not be present, depending upon the IPP; its707* contents and alignment are also IPP-dependent. Currently, none of the708* standard IPPs supplied by Tilera produce a custom header. If present,709* the custom header precedes the L2 header in the packet buffer.710* @ingroup ingress711*712* @param[in] handle Handle on which to operate.713* @return A pointer to start of the packet.714*/715static __inline unsigned char*716NETIO_PKT_CUSTOM_DATA_H(netio_pkt_handle_t handle)717{718return _NETIO_PKT_HANDLE_BASE(handle) + NETIO_PACKET_PADDING;719}720721722/** Return the length of the packet's custom header.723* A custom header may or may not be present, depending upon the IPP; its724* contents and alignment are also IPP-dependent. Currently, none of the725* standard IPPs supplied by Tilera produce a custom header. If present,726* the custom header precedes the L2 header in the packet buffer.727*728* @ingroup ingress729*730* @param[in] mda Pointer to packet's standard metadata.731* @param[in] pkt Packet on which to operate.732* @return The length of the packet's custom header, in bytes.733*/734static __inline netio_size_t735NETIO_PKT_CUSTOM_HEADER_LENGTH_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)736{737/*738* Note that we effectively need to extract a quantity from the flags word739* which is measured in words, and then turn it into bytes by shifting740* it left by 2. We do this all at once by just shifting right two less741* bits, and shifting the mask up two bits.742*/743return ((mda->__flags >> (_NETIO_PKT_CUSTOM_LEN_SHIFT - 2)) &744(_NETIO_PKT_CUSTOM_LEN_RMASK << 2));745}746747748/** Return the length of the packet, starting with the custom header.749* A custom header may or may not be present, depending upon the IPP; its750* contents and alignment are also IPP-dependent. Currently, none of the751* standard IPPs supplied by Tilera produce a custom header. If present,752* the custom header precedes the L2 header in the packet buffer.753* @ingroup ingress754*755* @param[in] mda Pointer to packet's standard metadata.756* @param[in] pkt Packet on which to operate.757* @return The length of the packet, in bytes.758*/759static __inline netio_size_t760NETIO_PKT_CUSTOM_LENGTH_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)761{762return (__NETIO_PKT_NOTIF_HEADER(pkt).bits.__transfer_size -763NETIO_PACKET_PADDING);764}765766767/** Return a pointer to the start of the packet's custom header.768* A custom header may or may not be present, depending upon the IPP; its769* contents and alignment are also IPP-dependent. Currently, none of the770* standard IPPs supplied by Tilera produce a custom header. If present,771* the custom header precedes the L2 header in the packet buffer.772* @ingroup ingress773*774* @param[in] mda Pointer to packet's standard metadata.775* @param[in] pkt Packet on which to operate.776* @return A pointer to start of the packet.777*/778static __inline unsigned char*779NETIO_PKT_CUSTOM_DATA_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)780{781return NETIO_PKT_CUSTOM_DATA_H(NETIO_PKT_HANDLE(pkt));782}783784785/** Return the length of the packet's L2 (Ethernet plus VLAN or SNAP) header.786* @ingroup ingress787*788* @param[in] mda Pointer to packet's standard metadata.789* @param[in] pkt Packet on which to operate.790* @return The length of the packet's L2 header, in bytes.791*/792static __inline netio_size_t793NETIO_PKT_L2_HEADER_LENGTH_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)794{795/*796* Note that we effectively need to extract a quantity from the flags word797* which is measured in words, and then turn it into bytes by shifting798* it left by 2. We do this all at once by just shifting right two less799* bits, and shifting the mask up two bits. We then add two bytes.800*/801return ((mda->__flags >> (_NETIO_PKT_L2_LEN_SHIFT - 2)) &802(_NETIO_PKT_L2_LEN_RMASK << 2)) + 2;803}804805806/** Return the length of the packet, starting with the L2 (Ethernet) header.807* @ingroup ingress808*809* @param[in] mda Pointer to packet's standard metadata.810* @param[in] pkt Packet on which to operate.811* @return The length of the packet, in bytes.812*/813static __inline netio_size_t814NETIO_PKT_L2_LENGTH_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)815{816return (NETIO_PKT_CUSTOM_LENGTH_M(mda, pkt) -817NETIO_PKT_CUSTOM_HEADER_LENGTH_M(mda,pkt));818}819820821/** Return a pointer to the start of the packet's L2 (Ethernet) header.822* @ingroup ingress823*824* @param[in] mda Pointer to packet's standard metadata.825* @param[in] pkt Packet on which to operate.826* @return A pointer to start of the packet.827*/828static __inline unsigned char*829NETIO_PKT_L2_DATA_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)830{831return (NETIO_PKT_CUSTOM_DATA_M(mda, pkt) +832NETIO_PKT_CUSTOM_HEADER_LENGTH_M(mda, pkt));833}834835836/** Retrieve the length of the packet, starting with the L3 (generally,837* the IP) header.838* @ingroup ingress839*840* @param[in] mda Pointer to packet's standard metadata.841* @param[in] pkt Packet on which to operate.842* @return Length of the packet's L3 header and data, in bytes.843*/844static __inline netio_size_t845NETIO_PKT_L3_LENGTH_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)846{847return (NETIO_PKT_L2_LENGTH_M(mda, pkt) -848NETIO_PKT_L2_HEADER_LENGTH_M(mda,pkt));849}850851852/** Return a pointer to the packet's L3 (generally, the IP) header.853* @ingroup ingress854*855* Note that we guarantee word alignment of the L3 header.856*857* @param[in] mda Pointer to packet's standard metadata.858* @param[in] pkt Packet on which to operate.859* @return A pointer to the packet's L3 header.860*/861static __inline unsigned char*862NETIO_PKT_L3_DATA_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)863{864return (NETIO_PKT_L2_DATA_M(mda, pkt) +865NETIO_PKT_L2_HEADER_LENGTH_M(mda, pkt));866}867868869/** Return the ordinal of the packet.870* @ingroup ingress871*872* Each packet is given an ordinal number when it is delivered by the IPP.873* In the medium term, the ordinal is unique and monotonically increasing,874* being incremented by 1 for each packet; the ordinal of the first packet875* delivered after the IPP starts is zero. (Since the ordinal is of finite876* size, given enough input packets, it will eventually wrap around to zero;877* in the long term, therefore, ordinals are not unique.) The ordinals878* handed out by different IPPs are not disjoint, so two packets from879* different IPPs may have identical ordinals. Packets dropped by the880* IPP or by the I/O shim are not assigned ordinals.881*882* @param[in] mda Pointer to packet's standard metadata.883* @param[in] pkt Packet on which to operate.884* @return The packet's per-IPP packet ordinal.885*/886static __inline unsigned int887NETIO_PKT_ORDINAL_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)888{889return mda->__packet_ordinal;890}891892893/** Return the per-group ordinal of the packet.894* @ingroup ingress895*896* Each packet is given a per-group ordinal number when it is897* delivered by the IPP. By default, the group is the packet's VLAN,898* although IPP can be recompiled to use different values. In899* the medium term, the ordinal is unique and monotonically900* increasing, being incremented by 1 for each packet; the ordinal of901* the first packet distributed to a particular group is zero.902* (Since the ordinal is of finite size, given enough input packets,903* it will eventually wrap around to zero; in the long term,904* therefore, ordinals are not unique.) The ordinals handed out by905* different IPPs are not disjoint, so two packets from different IPPs906* may have identical ordinals; similarly, packets distributed to907* different groups may have identical ordinals. Packets dropped by908* the IPP or by the I/O shim are not assigned ordinals.909*910* @param[in] mda Pointer to packet's standard metadata.911* @param[in] pkt Packet on which to operate.912* @return The packet's per-IPP, per-group ordinal.913*/914static __inline unsigned int915NETIO_PKT_GROUP_ORDINAL_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)916{917return mda->__group_ordinal;918}919920921/** Return the VLAN ID assigned to the packet.922* @ingroup ingress923*924* This value is usually contained within the packet header.925*926* This value will be zero if the packet does not have a VLAN tag, or if927* this value was not extracted from the packet.928*929* @param[in] mda Pointer to packet's standard metadata.930* @param[in] pkt Packet on which to operate.931* @return The packet's VLAN ID.932*/933static __inline unsigned short934NETIO_PKT_VLAN_ID_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)935{936int vl = (mda->__flags >> _NETIO_PKT_VLAN_SHIFT) & _NETIO_PKT_VLAN_RMASK;937unsigned short* pkt_p;938int index;939unsigned short val;940941if (vl == _NETIO_PKT_VLAN_NONE)942return 0;943944pkt_p = (unsigned short*) NETIO_PKT_L2_DATA_M(mda, pkt);945index = (mda->__flags >> _NETIO_PKT_TYPE_SHIFT) & _NETIO_PKT_TYPE_RMASK;946947val = pkt_p[(_netio_pkt_info[index] >> _NETIO_PKT_INFO_VLAN_SHIFT) &948_NETIO_PKT_INFO_VLAN_RMASK];949950#ifdef __TILECC__951return (__insn_bytex(val) >> 16) & 0xFFF;952#else953return (__builtin_bswap32(val) >> 16) & 0xFFF;954#endif955}956957958/** Return the ethertype of the packet.959* @ingroup ingress960*961* This value is usually contained within the packet header.962*963* This value is reliable if @ref NETIO_PKT_ETHERTYPE_RECOGNIZED_M()964* returns true, and otherwise, may not be well defined.965*966* @param[in] mda Pointer to packet's standard metadata.967* @param[in] pkt Packet on which to operate.968* @return The packet's ethertype.969*/970static __inline unsigned short971NETIO_PKT_ETHERTYPE_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)972{973unsigned short* pkt_p = (unsigned short*) NETIO_PKT_L2_DATA_M(mda, pkt);974int index = (mda->__flags >> _NETIO_PKT_TYPE_SHIFT) & _NETIO_PKT_TYPE_RMASK;975976unsigned short val =977pkt_p[(_netio_pkt_info[index] >> _NETIO_PKT_INFO_ETYPE_SHIFT) &978_NETIO_PKT_INFO_ETYPE_RMASK];979980return __builtin_bswap32(val) >> 16;981}982983984/** Return the flow hash computed on the packet.985* @ingroup ingress986*987* For TCP and UDP packets, this hash is calculated by hashing together988* the "5-tuple" values, specifically the source IP address, destination989* IP address, protocol type, source port and destination port.990* The hash value is intended to be helpful for millions of distinct991* flows.992*993* For IPv4 or IPv6 packets which are neither TCP nor UDP, the flow hash is994* derived by hashing together the source and destination IP addresses.995*996* For MPLS-encapsulated packets, the flow hash is derived by hashing997* the first MPLS label.998*999* For all other packets the flow hash is computed from the source1000* and destination Ethernet addresses.1001*1002* The hash is symmetric, meaning it produces the same value if the1003* source and destination are swapped. The only exceptions are1004* tunneling protocols 0x04 (IP in IP Encapsulation), 0x29 (Simple1005* Internet Protocol), 0x2F (General Routing Encapsulation) and 0x321006* (Encap Security Payload), which use only the destination address1007* since the source address is not meaningful.1008*1009* @param[in] mda Pointer to packet's standard metadata.1010* @param[in] pkt Packet on which to operate.1011* @return The packet's 32-bit flow hash.1012*/1013static __inline unsigned int1014NETIO_PKT_FLOW_HASH_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)1015{1016return mda->__flow_hash;1017}101810191020/** Return the first word of "user data" for the packet.1021*1022* The contents of the user data words depend on the IPP.1023*1024* When using the standard ipp1, ipp2, or ipp4 sub-drivers, the first1025* word of user data contains the least significant bits of the 64-bit1026* arrival cycle count (see @c get_cycle_count_low()).1027*1028* See the <em>System Programmer's Guide</em> for details.1029*1030* @ingroup ingress1031*1032* @param[in] mda Pointer to packet's standard metadata.1033* @param[in] pkt Packet on which to operate.1034* @return The packet's first word of "user data".1035*/1036static __inline unsigned int1037NETIO_PKT_USER_DATA_0_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)1038{1039return mda->__user_data_0;1040}104110421043/** Return the second word of "user data" for the packet.1044*1045* The contents of the user data words depend on the IPP.1046*1047* When using the standard ipp1, ipp2, or ipp4 sub-drivers, the second1048* word of user data contains the most significant bits of the 64-bit1049* arrival cycle count (see @c get_cycle_count_high()).1050*1051* See the <em>System Programmer's Guide</em> for details.1052*1053* @ingroup ingress1054*1055* @param[in] mda Pointer to packet's standard metadata.1056* @param[in] pkt Packet on which to operate.1057* @return The packet's second word of "user data".1058*/1059static __inline unsigned int1060NETIO_PKT_USER_DATA_1_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)1061{1062return mda->__user_data_1;1063}106410651066/** Determine whether the L4 (TCP/UDP) checksum was calculated.1067* @ingroup ingress1068*1069* @param[in] mda Pointer to packet's standard metadata.1070* @param[in] pkt Packet on which to operate.1071* @return Nonzero if the L4 checksum was calculated.1072*/1073static __inline unsigned int1074NETIO_PKT_L4_CSUM_CALCULATED_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)1075{1076return !(mda->__flags & _NETIO_PKT_NO_L4_CSUM_MASK);1077}107810791080/** Determine whether the L4 (TCP/UDP) checksum was calculated and found to1081* be correct.1082* @ingroup ingress1083*1084* @param[in] mda Pointer to packet's standard metadata.1085* @param[in] pkt Packet on which to operate.1086* @return Nonzero if the checksum was calculated and is correct.1087*/1088static __inline unsigned int1089NETIO_PKT_L4_CSUM_CORRECT_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)1090{1091return !(mda->__flags &1092(_NETIO_PKT_BAD_L4_CSUM_MASK | _NETIO_PKT_NO_L4_CSUM_MASK));1093}109410951096/** Determine whether the L3 (IP) checksum was calculated.1097* @ingroup ingress1098*1099* @param[in] mda Pointer to packet's standard metadata.1100* @param[in] pkt Packet on which to operate.1101* @return Nonzero if the L3 (IP) checksum was calculated.1102*/1103static __inline unsigned int1104NETIO_PKT_L3_CSUM_CALCULATED_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)1105{1106return !(mda->__flags & _NETIO_PKT_NO_L3_CSUM_MASK);1107}110811091110/** Determine whether the L3 (IP) checksum was calculated and found to be1111* correct.1112* @ingroup ingress1113*1114* @param[in] mda Pointer to packet's standard metadata.1115* @param[in] pkt Packet on which to operate.1116* @return Nonzero if the checksum was calculated and is correct.1117*/1118static __inline unsigned int1119NETIO_PKT_L3_CSUM_CORRECT_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)1120{1121return !(mda->__flags &1122(_NETIO_PKT_BAD_L3_CSUM_MASK | _NETIO_PKT_NO_L3_CSUM_MASK));1123}112411251126/** Determine whether the ethertype was recognized and L3 packet data was1127* processed.1128* @ingroup ingress1129*1130* @param[in] mda Pointer to packet's standard metadata.1131* @param[in] pkt Packet on which to operate.1132* @return Nonzero if the ethertype was recognized and L3 packet data was1133* processed.1134*/1135static __inline unsigned int1136NETIO_PKT_ETHERTYPE_RECOGNIZED_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)1137{1138return !(mda->__flags & _NETIO_PKT_TYPE_UNRECOGNIZED_MASK);1139}114011411142/** Retrieve the status of a packet and any errors that may have occurred1143* during ingress processing (length mismatches, CRC errors, etc.).1144* @ingroup ingress1145*1146* Note that packets for which @ref NETIO_PKT_ETHERTYPE_RECOGNIZED()1147* returns zero are always reported as underlength, as there is no a priori1148* means to determine their length. Normally, applications should use1149* @ref NETIO_PKT_BAD_M() instead of explicitly checking status with this1150* function.1151*1152* @param[in] mda Pointer to packet's standard metadata.1153* @param[in] pkt Packet on which to operate.1154* @return The packet's status.1155*/1156static __inline netio_pkt_status_t1157NETIO_PKT_STATUS_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)1158{1159return (netio_pkt_status_t) __NETIO_PKT_NOTIF_HEADER(pkt).bits.__status;1160}116111621163/** Report whether a packet is bad (i.e., was shorter than expected based on1164* its headers, or had a bad CRC).1165* @ingroup ingress1166*1167* Note that this function does not verify L3 or L4 checksums.1168*1169* @param[in] mda Pointer to packet's standard metadata.1170* @param[in] pkt Packet on which to operate.1171* @return Nonzero if the packet is bad and should be discarded.1172*/1173static __inline unsigned int1174NETIO_PKT_BAD_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)1175{1176return ((NETIO_PKT_STATUS_M(mda, pkt) & 1) &&1177(NETIO_PKT_ETHERTYPE_RECOGNIZED_M(mda, pkt) ||1178NETIO_PKT_STATUS_M(mda, pkt) == NETIO_PKT_STATUS_BAD));1179}118011811182/** Return the length of the packet, starting with the L2 (Ethernet) header.1183* @ingroup egress1184*1185* @param[in] mmd Pointer to packet's minimal metadata.1186* @param[in] pkt Packet on which to operate.1187* @return The length of the packet, in bytes.1188*/1189static __inline netio_size_t1190NETIO_PKT_L2_LENGTH_MM(netio_pkt_minimal_metadata_t* mmd, netio_pkt_t* pkt)1191{1192return mmd->l2_length;1193}119411951196/** Return the length of the L2 (Ethernet) header.1197* @ingroup egress1198*1199* @param[in] mmd Pointer to packet's minimal metadata.1200* @param[in] pkt Packet on which to operate.1201* @return The length of the packet's L2 header, in bytes.1202*/1203static __inline netio_size_t1204NETIO_PKT_L2_HEADER_LENGTH_MM(netio_pkt_minimal_metadata_t* mmd,1205netio_pkt_t* pkt)1206{1207return mmd->l3_offset - mmd->l2_offset;1208}120912101211/** Return the length of the packet, starting with the L3 (IP) header.1212* @ingroup egress1213*1214* @param[in] mmd Pointer to packet's minimal metadata.1215* @param[in] pkt Packet on which to operate.1216* @return Length of the packet's L3 header and data, in bytes.1217*/1218static __inline netio_size_t1219NETIO_PKT_L3_LENGTH_MM(netio_pkt_minimal_metadata_t* mmd, netio_pkt_t* pkt)1220{1221return (NETIO_PKT_L2_LENGTH_MM(mmd, pkt) -1222NETIO_PKT_L2_HEADER_LENGTH_MM(mmd, pkt));1223}122412251226/** Return a pointer to the packet's L3 (generally, the IP) header.1227* @ingroup egress1228*1229* Note that we guarantee word alignment of the L3 header.1230*1231* @param[in] mmd Pointer to packet's minimal metadata.1232* @param[in] pkt Packet on which to operate.1233* @return A pointer to the packet's L3 header.1234*/1235static __inline unsigned char*1236NETIO_PKT_L3_DATA_MM(netio_pkt_minimal_metadata_t* mmd, netio_pkt_t* pkt)1237{1238return _NETIO_PKT_BASE(pkt) + mmd->l3_offset;1239}124012411242/** Return a pointer to the packet's L2 (Ethernet) header.1243* @ingroup egress1244*1245* @param[in] mmd Pointer to packet's minimal metadata.1246* @param[in] pkt Packet on which to operate.1247* @return A pointer to start of the packet.1248*/1249static __inline unsigned char*1250NETIO_PKT_L2_DATA_MM(netio_pkt_minimal_metadata_t* mmd, netio_pkt_t* pkt)1251{1252return _NETIO_PKT_BASE(pkt) + mmd->l2_offset;1253}125412551256/** Retrieve the status of a packet and any errors that may have occurred1257* during ingress processing (length mismatches, CRC errors, etc.).1258* @ingroup ingress1259*1260* Note that packets for which @ref NETIO_PKT_ETHERTYPE_RECOGNIZED()1261* returns zero are always reported as underlength, as there is no a priori1262* means to determine their length. Normally, applications should use1263* @ref NETIO_PKT_BAD() instead of explicitly checking status with this1264* function.1265*1266* @param[in] pkt Packet on which to operate.1267* @return The packet's status.1268*/1269static __inline netio_pkt_status_t1270NETIO_PKT_STATUS(netio_pkt_t* pkt)1271{1272netio_assert(!pkt->__packet.bits.__minimal);12731274return (netio_pkt_status_t) __NETIO_PKT_NOTIF_HEADER(pkt).bits.__status;1275}127612771278/** Report whether a packet is bad (i.e., was shorter than expected based on1279* its headers, or had a bad CRC).1280* @ingroup ingress1281*1282* Note that this function does not verify L3 or L4 checksums.1283*1284* @param[in] pkt Packet on which to operate.1285* @return Nonzero if the packet is bad and should be discarded.1286*/1287static __inline unsigned int1288NETIO_PKT_BAD(netio_pkt_t* pkt)1289{1290netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);12911292return NETIO_PKT_BAD_M(mda, pkt);1293}129412951296/** Return the length of the packet's custom header.1297* A custom header may or may not be present, depending upon the IPP; its1298* contents and alignment are also IPP-dependent. Currently, none of the1299* standard IPPs supplied by Tilera produce a custom header. If present,1300* the custom header precedes the L2 header in the packet buffer.1301* @ingroup pktfuncs1302*1303* @param[in] pkt Packet on which to operate.1304* @return The length of the packet's custom header, in bytes.1305*/1306static __inline netio_size_t1307NETIO_PKT_CUSTOM_HEADER_LENGTH(netio_pkt_t* pkt)1308{1309netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);13101311return NETIO_PKT_CUSTOM_HEADER_LENGTH_M(mda, pkt);1312}131313141315/** Return the length of the packet, starting with the custom header.1316* A custom header may or may not be present, depending upon the IPP; its1317* contents and alignment are also IPP-dependent. Currently, none of the1318* standard IPPs supplied by Tilera produce a custom header. If present,1319* the custom header precedes the L2 header in the packet buffer.1320* @ingroup pktfuncs1321*1322* @param[in] pkt Packet on which to operate.1323* @return The length of the packet, in bytes.1324*/1325static __inline netio_size_t1326NETIO_PKT_CUSTOM_LENGTH(netio_pkt_t* pkt)1327{1328netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);13291330return NETIO_PKT_CUSTOM_LENGTH_M(mda, pkt);1331}133213331334/** Return a pointer to the packet's custom header.1335* A custom header may or may not be present, depending upon the IPP; its1336* contents and alignment are also IPP-dependent. Currently, none of the1337* standard IPPs supplied by Tilera produce a custom header. If present,1338* the custom header precedes the L2 header in the packet buffer.1339* @ingroup pktfuncs1340*1341* @param[in] pkt Packet on which to operate.1342* @return A pointer to start of the packet.1343*/1344static __inline unsigned char*1345NETIO_PKT_CUSTOM_DATA(netio_pkt_t* pkt)1346{1347netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);13481349return NETIO_PKT_CUSTOM_DATA_M(mda, pkt);1350}135113521353/** Return the length of the packet's L2 (Ethernet plus VLAN or SNAP) header.1354* @ingroup pktfuncs1355*1356* @param[in] pkt Packet on which to operate.1357* @return The length of the packet's L2 header, in bytes.1358*/1359static __inline netio_size_t1360NETIO_PKT_L2_HEADER_LENGTH(netio_pkt_t* pkt)1361{1362if (NETIO_PKT_IS_MINIMAL(pkt))1363{1364netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);13651366return NETIO_PKT_L2_HEADER_LENGTH_MM(mmd, pkt);1367}1368else1369{1370netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);13711372return NETIO_PKT_L2_HEADER_LENGTH_M(mda, pkt);1373}1374}137513761377/** Return the length of the packet, starting with the L2 (Ethernet) header.1378* @ingroup pktfuncs1379*1380* @param[in] pkt Packet on which to operate.1381* @return The length of the packet, in bytes.1382*/1383static __inline netio_size_t1384NETIO_PKT_L2_LENGTH(netio_pkt_t* pkt)1385{1386if (NETIO_PKT_IS_MINIMAL(pkt))1387{1388netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);13891390return NETIO_PKT_L2_LENGTH_MM(mmd, pkt);1391}1392else1393{1394netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);13951396return NETIO_PKT_L2_LENGTH_M(mda, pkt);1397}1398}139914001401/** Return a pointer to the packet's L2 (Ethernet) header.1402* @ingroup pktfuncs1403*1404* @param[in] pkt Packet on which to operate.1405* @return A pointer to start of the packet.1406*/1407static __inline unsigned char*1408NETIO_PKT_L2_DATA(netio_pkt_t* pkt)1409{1410if (NETIO_PKT_IS_MINIMAL(pkt))1411{1412netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);14131414return NETIO_PKT_L2_DATA_MM(mmd, pkt);1415}1416else1417{1418netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);14191420return NETIO_PKT_L2_DATA_M(mda, pkt);1421}1422}142314241425/** Retrieve the length of the packet, starting with the L3 (generally, the IP)1426* header.1427* @ingroup pktfuncs1428*1429* @param[in] pkt Packet on which to operate.1430* @return Length of the packet's L3 header and data, in bytes.1431*/1432static __inline netio_size_t1433NETIO_PKT_L3_LENGTH(netio_pkt_t* pkt)1434{1435if (NETIO_PKT_IS_MINIMAL(pkt))1436{1437netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);14381439return NETIO_PKT_L3_LENGTH_MM(mmd, pkt);1440}1441else1442{1443netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);14441445return NETIO_PKT_L3_LENGTH_M(mda, pkt);1446}1447}144814491450/** Return a pointer to the packet's L3 (generally, the IP) header.1451* @ingroup pktfuncs1452*1453* Note that we guarantee word alignment of the L3 header.1454*1455* @param[in] pkt Packet on which to operate.1456* @return A pointer to the packet's L3 header.1457*/1458static __inline unsigned char*1459NETIO_PKT_L3_DATA(netio_pkt_t* pkt)1460{1461if (NETIO_PKT_IS_MINIMAL(pkt))1462{1463netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);14641465return NETIO_PKT_L3_DATA_MM(mmd, pkt);1466}1467else1468{1469netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);14701471return NETIO_PKT_L3_DATA_M(mda, pkt);1472}1473}147414751476/** Return the ordinal of the packet.1477* @ingroup ingress1478*1479* Each packet is given an ordinal number when it is delivered by the IPP.1480* In the medium term, the ordinal is unique and monotonically increasing,1481* being incremented by 1 for each packet; the ordinal of the first packet1482* delivered after the IPP starts is zero. (Since the ordinal is of finite1483* size, given enough input packets, it will eventually wrap around to zero;1484* in the long term, therefore, ordinals are not unique.) The ordinals1485* handed out by different IPPs are not disjoint, so two packets from1486* different IPPs may have identical ordinals. Packets dropped by the1487* IPP or by the I/O shim are not assigned ordinals.1488*1489*1490* @param[in] pkt Packet on which to operate.1491* @return The packet's per-IPP packet ordinal.1492*/1493static __inline unsigned int1494NETIO_PKT_ORDINAL(netio_pkt_t* pkt)1495{1496netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);14971498return NETIO_PKT_ORDINAL_M(mda, pkt);1499}150015011502/** Return the per-group ordinal of the packet.1503* @ingroup ingress1504*1505* Each packet is given a per-group ordinal number when it is1506* delivered by the IPP. By default, the group is the packet's VLAN,1507* although IPP can be recompiled to use different values. In1508* the medium term, the ordinal is unique and monotonically1509* increasing, being incremented by 1 for each packet; the ordinal of1510* the first packet distributed to a particular group is zero.1511* (Since the ordinal is of finite size, given enough input packets,1512* it will eventually wrap around to zero; in the long term,1513* therefore, ordinals are not unique.) The ordinals handed out by1514* different IPPs are not disjoint, so two packets from different IPPs1515* may have identical ordinals; similarly, packets distributed to1516* different groups may have identical ordinals. Packets dropped by1517* the IPP or by the I/O shim are not assigned ordinals.1518*1519* @param[in] pkt Packet on which to operate.1520* @return The packet's per-IPP, per-group ordinal.1521*/1522static __inline unsigned int1523NETIO_PKT_GROUP_ORDINAL(netio_pkt_t* pkt)1524{1525netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);15261527return NETIO_PKT_GROUP_ORDINAL_M(mda, pkt);1528}152915301531/** Return the VLAN ID assigned to the packet.1532* @ingroup ingress1533*1534* This is usually also contained within the packet header. If the packet1535* does not have a VLAN tag, the VLAN ID returned by this function is zero.1536*1537* @param[in] pkt Packet on which to operate.1538* @return The packet's VLAN ID.1539*/1540static __inline unsigned short1541NETIO_PKT_VLAN_ID(netio_pkt_t* pkt)1542{1543netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);15441545return NETIO_PKT_VLAN_ID_M(mda, pkt);1546}154715481549/** Return the ethertype of the packet.1550* @ingroup ingress1551*1552* This value is reliable if @ref NETIO_PKT_ETHERTYPE_RECOGNIZED()1553* returns true, and otherwise, may not be well defined.1554*1555* @param[in] pkt Packet on which to operate.1556* @return The packet's ethertype.1557*/1558static __inline unsigned short1559NETIO_PKT_ETHERTYPE(netio_pkt_t* pkt)1560{1561netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);15621563return NETIO_PKT_ETHERTYPE_M(mda, pkt);1564}156515661567/** Return the flow hash computed on the packet.1568* @ingroup ingress1569*1570* For TCP and UDP packets, this hash is calculated by hashing together1571* the "5-tuple" values, specifically the source IP address, destination1572* IP address, protocol type, source port and destination port.1573* The hash value is intended to be helpful for millions of distinct1574* flows.1575*1576* For IPv4 or IPv6 packets which are neither TCP nor UDP, the flow hash is1577* derived by hashing together the source and destination IP addresses.1578*1579* For MPLS-encapsulated packets, the flow hash is derived by hashing1580* the first MPLS label.1581*1582* For all other packets the flow hash is computed from the source1583* and destination Ethernet addresses.1584*1585* The hash is symmetric, meaning it produces the same value if the1586* source and destination are swapped. The only exceptions are1587* tunneling protocols 0x04 (IP in IP Encapsulation), 0x29 (Simple1588* Internet Protocol), 0x2F (General Routing Encapsulation) and 0x321589* (Encap Security Payload), which use only the destination address1590* since the source address is not meaningful.1591*1592* @param[in] pkt Packet on which to operate.1593* @return The packet's 32-bit flow hash.1594*/1595static __inline unsigned int1596NETIO_PKT_FLOW_HASH(netio_pkt_t* pkt)1597{1598netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);15991600return NETIO_PKT_FLOW_HASH_M(mda, pkt);1601}160216031604/** Return the first word of "user data" for the packet.1605*1606* The contents of the user data words depend on the IPP.1607*1608* When using the standard ipp1, ipp2, or ipp4 sub-drivers, the first1609* word of user data contains the least significant bits of the 64-bit1610* arrival cycle count (see @c get_cycle_count_low()).1611*1612* See the <em>System Programmer's Guide</em> for details.1613*1614* @ingroup ingress1615*1616* @param[in] pkt Packet on which to operate.1617* @return The packet's first word of "user data".1618*/1619static __inline unsigned int1620NETIO_PKT_USER_DATA_0(netio_pkt_t* pkt)1621{1622netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);16231624return NETIO_PKT_USER_DATA_0_M(mda, pkt);1625}162616271628/** Return the second word of "user data" for the packet.1629*1630* The contents of the user data words depend on the IPP.1631*1632* When using the standard ipp1, ipp2, or ipp4 sub-drivers, the second1633* word of user data contains the most significant bits of the 64-bit1634* arrival cycle count (see @c get_cycle_count_high()).1635*1636* See the <em>System Programmer's Guide</em> for details.1637*1638* @ingroup ingress1639*1640* @param[in] pkt Packet on which to operate.1641* @return The packet's second word of "user data".1642*/1643static __inline unsigned int1644NETIO_PKT_USER_DATA_1(netio_pkt_t* pkt)1645{1646netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);16471648return NETIO_PKT_USER_DATA_1_M(mda, pkt);1649}165016511652/** Determine whether the L4 (TCP/UDP) checksum was calculated.1653* @ingroup ingress1654*1655* @param[in] pkt Packet on which to operate.1656* @return Nonzero if the L4 checksum was calculated.1657*/1658static __inline unsigned int1659NETIO_PKT_L4_CSUM_CALCULATED(netio_pkt_t* pkt)1660{1661netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);16621663return NETIO_PKT_L4_CSUM_CALCULATED_M(mda, pkt);1664}166516661667/** Determine whether the L4 (TCP/UDP) checksum was calculated and found to1668* be correct.1669* @ingroup ingress1670*1671* @param[in] pkt Packet on which to operate.1672* @return Nonzero if the checksum was calculated and is correct.1673*/1674static __inline unsigned int1675NETIO_PKT_L4_CSUM_CORRECT(netio_pkt_t* pkt)1676{1677netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);16781679return NETIO_PKT_L4_CSUM_CORRECT_M(mda, pkt);1680}168116821683/** Determine whether the L3 (IP) checksum was calculated.1684* @ingroup ingress1685*1686* @param[in] pkt Packet on which to operate.1687* @return Nonzero if the L3 (IP) checksum was calculated.1688*/1689static __inline unsigned int1690NETIO_PKT_L3_CSUM_CALCULATED(netio_pkt_t* pkt)1691{1692netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);16931694return NETIO_PKT_L3_CSUM_CALCULATED_M(mda, pkt);1695}169616971698/** Determine whether the L3 (IP) checksum was calculated and found to be1699* correct.1700* @ingroup ingress1701*1702* @param[in] pkt Packet on which to operate.1703* @return Nonzero if the checksum was calculated and is correct.1704*/1705static __inline unsigned int1706NETIO_PKT_L3_CSUM_CORRECT(netio_pkt_t* pkt)1707{1708netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);17091710return NETIO_PKT_L3_CSUM_CORRECT_M(mda, pkt);1711}171217131714/** Determine whether the Ethertype was recognized and L3 packet data was1715* processed.1716* @ingroup ingress1717*1718* @param[in] pkt Packet on which to operate.1719* @return Nonzero if the Ethertype was recognized and L3 packet data was1720* processed.1721*/1722static __inline unsigned int1723NETIO_PKT_ETHERTYPE_RECOGNIZED(netio_pkt_t* pkt)1724{1725netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);17261727return NETIO_PKT_ETHERTYPE_RECOGNIZED_M(mda, pkt);1728}172917301731/** Set an egress packet's L2 length, using a metadata pointer to speed the1732* computation.1733* @ingroup egress1734*1735* @param[in,out] mmd Pointer to packet's minimal metadata.1736* @param[in] pkt Packet on which to operate.1737* @param[in] len Packet L2 length, in bytes.1738*/1739static __inline void1740NETIO_PKT_SET_L2_LENGTH_MM(netio_pkt_minimal_metadata_t* mmd, netio_pkt_t* pkt,1741int len)1742{1743mmd->l2_length = len;1744}174517461747/** Set an egress packet's L2 length.1748* @ingroup egress1749*1750* @param[in,out] pkt Packet on which to operate.1751* @param[in] len Packet L2 length, in bytes.1752*/1753static __inline void1754NETIO_PKT_SET_L2_LENGTH(netio_pkt_t* pkt, int len)1755{1756netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);17571758NETIO_PKT_SET_L2_LENGTH_MM(mmd, pkt, len);1759}176017611762/** Set an egress packet's L2 header length, using a metadata pointer to1763* speed the computation.1764* @ingroup egress1765*1766* It is not normally necessary to call this routine; only the L2 length,1767* not the header length, is needed to transmit a packet. It may be useful if1768* the egress packet will later be processed by code which expects to use1769* functions like @ref NETIO_PKT_L3_DATA() to get a pointer to the L3 payload.1770*1771* @param[in,out] mmd Pointer to packet's minimal metadata.1772* @param[in] pkt Packet on which to operate.1773* @param[in] len Packet L2 header length, in bytes.1774*/1775static __inline void1776NETIO_PKT_SET_L2_HEADER_LENGTH_MM(netio_pkt_minimal_metadata_t* mmd,1777netio_pkt_t* pkt, int len)1778{1779mmd->l3_offset = mmd->l2_offset + len;1780}178117821783/** Set an egress packet's L2 header length.1784* @ingroup egress1785*1786* It is not normally necessary to call this routine; only the L2 length,1787* not the header length, is needed to transmit a packet. It may be useful if1788* the egress packet will later be processed by code which expects to use1789* functions like @ref NETIO_PKT_L3_DATA() to get a pointer to the L3 payload.1790*1791* @param[in,out] pkt Packet on which to operate.1792* @param[in] len Packet L2 header length, in bytes.1793*/1794static __inline void1795NETIO_PKT_SET_L2_HEADER_LENGTH(netio_pkt_t* pkt, int len)1796{1797netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);17981799NETIO_PKT_SET_L2_HEADER_LENGTH_MM(mmd, pkt, len);1800}180118021803/** Set up an egress packet for hardware checksum computation, using a1804* metadata pointer to speed the operation.1805* @ingroup egress1806*1807* NetIO provides the ability to automatically calculate a standard1808* 16-bit Internet checksum on transmitted packets. The application1809* may specify the point in the packet where the checksum starts, the1810* number of bytes to be checksummed, and the two bytes in the packet1811* which will be replaced with the completed checksum. (If the range1812* of bytes to be checksummed includes the bytes to be replaced, the1813* initial values of those bytes will be included in the checksum.)1814*1815* For some protocols, the packet checksum covers data which is not present1816* in the packet, or is at least not contiguous to the main data payload.1817* For instance, the TCP checksum includes a "pseudo-header" which includes1818* the source and destination IP addresses of the packet. To accommodate1819* this, the checksum engine may be "seeded" with an initial value, which1820* the application would need to compute based on the specific protocol's1821* requirements. Note that the seed is given in host byte order (little-1822* endian), not network byte order (big-endian); code written to compute a1823* pseudo-header checksum in network byte order will need to byte-swap it1824* before use as the seed.1825*1826* Note that the checksum is computed as part of the transmission process,1827* so it will not be present in the packet upon completion of this routine.1828*1829* @param[in,out] mmd Pointer to packet's minimal metadata.1830* @param[in] pkt Packet on which to operate.1831* @param[in] start Offset within L2 packet of the first byte to include in1832* the checksum.1833* @param[in] length Number of bytes to include in the checksum.1834* the checksum.1835* @param[in] location Offset within L2 packet of the first of the two bytes1836* to be replaced with the calculated checksum.1837* @param[in] seed Initial value of the running checksum before any of the1838* packet data is added.1839*/1840static __inline void1841NETIO_PKT_DO_EGRESS_CSUM_MM(netio_pkt_minimal_metadata_t* mmd,1842netio_pkt_t* pkt, int start, int length,1843int location, uint16_t seed)1844{1845mmd->csum_start = start;1846mmd->csum_length = length;1847mmd->csum_location = location;1848mmd->csum_seed = seed;1849mmd->flags |= _NETIO_PKT_NEED_EDMA_CSUM_MASK;1850}185118521853/** Set up an egress packet for hardware checksum computation.1854* @ingroup egress1855*1856* NetIO provides the ability to automatically calculate a standard1857* 16-bit Internet checksum on transmitted packets. The application1858* may specify the point in the packet where the checksum starts, the1859* number of bytes to be checksummed, and the two bytes in the packet1860* which will be replaced with the completed checksum. (If the range1861* of bytes to be checksummed includes the bytes to be replaced, the1862* initial values of those bytes will be included in the checksum.)1863*1864* For some protocols, the packet checksum covers data which is not present1865* in the packet, or is at least not contiguous to the main data payload.1866* For instance, the TCP checksum includes a "pseudo-header" which includes1867* the source and destination IP addresses of the packet. To accommodate1868* this, the checksum engine may be "seeded" with an initial value, which1869* the application would need to compute based on the specific protocol's1870* requirements. Note that the seed is given in host byte order (little-1871* endian), not network byte order (big-endian); code written to compute a1872* pseudo-header checksum in network byte order will need to byte-swap it1873* before use as the seed.1874*1875* Note that the checksum is computed as part of the transmission process,1876* so it will not be present in the packet upon completion of this routine.1877*1878* @param[in,out] pkt Packet on which to operate.1879* @param[in] start Offset within L2 packet of the first byte to include in1880* the checksum.1881* @param[in] length Number of bytes to include in the checksum.1882* the checksum.1883* @param[in] location Offset within L2 packet of the first of the two bytes1884* to be replaced with the calculated checksum.1885* @param[in] seed Initial value of the running checksum before any of the1886* packet data is added.1887*/1888static __inline void1889NETIO_PKT_DO_EGRESS_CSUM(netio_pkt_t* pkt, int start, int length,1890int location, uint16_t seed)1891{1892netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);18931894NETIO_PKT_DO_EGRESS_CSUM_MM(mmd, pkt, start, length, location, seed);1895}189618971898/** Return the number of bytes which could be prepended to a packet, using a1899* metadata pointer to speed the operation.1900* See @ref netio_populate_prepend_buffer() to get a full description of1901* prepending.1902*1903* @param[in,out] mda Pointer to packet's standard metadata.1904* @param[in] pkt Packet on which to operate.1905*/1906static __inline int1907NETIO_PKT_PREPEND_AVAIL_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)1908{1909return (pkt->__packet.bits.__offset << 6) +1910NETIO_PKT_CUSTOM_HEADER_LENGTH_M(mda, pkt);1911}191219131914/** Return the number of bytes which could be prepended to a packet, using a1915* metadata pointer to speed the operation.1916* See @ref netio_populate_prepend_buffer() to get a full description of1917* prepending.1918* @ingroup egress1919*1920* @param[in,out] mmd Pointer to packet's minimal metadata.1921* @param[in] pkt Packet on which to operate.1922*/1923static __inline int1924NETIO_PKT_PREPEND_AVAIL_MM(netio_pkt_minimal_metadata_t* mmd, netio_pkt_t* pkt)1925{1926return (pkt->__packet.bits.__offset << 6) + mmd->l2_offset;1927}192819291930/** Return the number of bytes which could be prepended to a packet.1931* See @ref netio_populate_prepend_buffer() to get a full description of1932* prepending.1933* @ingroup egress1934*1935* @param[in] pkt Packet on which to operate.1936*/1937static __inline int1938NETIO_PKT_PREPEND_AVAIL(netio_pkt_t* pkt)1939{1940if (NETIO_PKT_IS_MINIMAL(pkt))1941{1942netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);19431944return NETIO_PKT_PREPEND_AVAIL_MM(mmd, pkt);1945}1946else1947{1948netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);19491950return NETIO_PKT_PREPEND_AVAIL_M(mda, pkt);1951}1952}195319541955/** Flush a packet's minimal metadata from the cache, using a metadata pointer1956* to speed the operation.1957* @ingroup egress1958*1959* @param[in] mmd Pointer to packet's minimal metadata.1960* @param[in] pkt Packet on which to operate.1961*/1962static __inline void1963NETIO_PKT_FLUSH_MINIMAL_METADATA_MM(netio_pkt_minimal_metadata_t* mmd,1964netio_pkt_t* pkt)1965{1966}196719681969/** Invalidate a packet's minimal metadata from the cache, using a metadata1970* pointer to speed the operation.1971* @ingroup egress1972*1973* @param[in] mmd Pointer to packet's minimal metadata.1974* @param[in] pkt Packet on which to operate.1975*/1976static __inline void1977NETIO_PKT_INV_MINIMAL_METADATA_MM(netio_pkt_minimal_metadata_t* mmd,1978netio_pkt_t* pkt)1979{1980}198119821983/** Flush and then invalidate a packet's minimal metadata from the cache,1984* using a metadata pointer to speed the operation.1985* @ingroup egress1986*1987* @param[in] mmd Pointer to packet's minimal metadata.1988* @param[in] pkt Packet on which to operate.1989*/1990static __inline void1991NETIO_PKT_FLUSH_INV_MINIMAL_METADATA_MM(netio_pkt_minimal_metadata_t* mmd,1992netio_pkt_t* pkt)1993{1994}199519961997/** Flush a packet's metadata from the cache, using a metadata pointer1998* to speed the operation.1999* @ingroup ingress2000*2001* @param[in] mda Pointer to packet's minimal metadata.2002* @param[in] pkt Packet on which to operate.2003*/2004static __inline void2005NETIO_PKT_FLUSH_METADATA_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)2006{2007}200820092010/** Invalidate a packet's metadata from the cache, using a metadata2011* pointer to speed the operation.2012* @ingroup ingress2013*2014* @param[in] mda Pointer to packet's metadata.2015* @param[in] pkt Packet on which to operate.2016*/2017static __inline void2018NETIO_PKT_INV_METADATA_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)2019{2020}202120222023/** Flush and then invalidate a packet's metadata from the cache,2024* using a metadata pointer to speed the operation.2025* @ingroup ingress2026*2027* @param[in] mda Pointer to packet's metadata.2028* @param[in] pkt Packet on which to operate.2029*/2030static __inline void2031NETIO_PKT_FLUSH_INV_METADATA_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)2032{2033}203420352036/** Flush a packet's minimal metadata from the cache.2037* @ingroup egress2038*2039* @param[in] pkt Packet on which to operate.2040*/2041static __inline void2042NETIO_PKT_FLUSH_MINIMAL_METADATA(netio_pkt_t* pkt)2043{2044}204520462047/** Invalidate a packet's minimal metadata from the cache.2048* @ingroup egress2049*2050* @param[in] pkt Packet on which to operate.2051*/2052static __inline void2053NETIO_PKT_INV_MINIMAL_METADATA(netio_pkt_t* pkt)2054{2055}205620572058/** Flush and then invalidate a packet's minimal metadata from the cache.2059* @ingroup egress2060*2061* @param[in] pkt Packet on which to operate.2062*/2063static __inline void2064NETIO_PKT_FLUSH_INV_MINIMAL_METADATA(netio_pkt_t* pkt)2065{2066}206720682069/** Flush a packet's metadata from the cache.2070* @ingroup ingress2071*2072* @param[in] pkt Packet on which to operate.2073*/2074static __inline void2075NETIO_PKT_FLUSH_METADATA(netio_pkt_t* pkt)2076{2077}207820792080/** Invalidate a packet's metadata from the cache.2081* @ingroup ingress2082*2083* @param[in] pkt Packet on which to operate.2084*/2085static __inline void2086NETIO_PKT_INV_METADATA(netio_pkt_t* pkt)2087{2088}208920902091/** Flush and then invalidate a packet's metadata from the cache.2092* @ingroup ingress2093*2094* @param[in] pkt Packet on which to operate.2095*/2096static __inline void2097NETIO_PKT_FLUSH_INV_METADATA(netio_pkt_t* pkt)2098{2099}21002101/** Number of NUMA nodes we can distribute buffers to.2102* @ingroup setup */2103#define NETIO_NUM_NODE_WEIGHTS 1621042105/**2106* @brief An object for specifying the characteristics of NetIO communication2107* endpoint.2108*2109* @ingroup setup2110*2111* The @ref netio_input_register() function uses this structure to define2112* how an application tile will communicate with an IPP.2113*2114*2115* Future updates to NetIO may add new members to this structure,2116* which can affect the success of the registration operation. Thus,2117* if dynamically initializing the structure, applications are urged to2118* zero it out first, for example:2119*2120* @code2121* netio_input_config_t config;2122* memset(&config, 0, sizeof (config));2123* config.flags = NETIO_RECV | NETIO_XMIT_CSUM | NETIO_TAG_NONE;2124* config.num_receive_packets = NETIO_MAX_RECEIVE_PKTS;2125* config.queue_id = 0;2126* .2127* .2128* .2129* @endcode2130*2131* since that guarantees that any unused structure members, including2132* members which did not exist when the application was first developed,2133* will not have unexpected values.2134*2135* If statically initializing the structure, we strongly recommend use of2136* C99-style named initializers, for example:2137*2138* @code2139* netio_input_config_t config = {2140* .flags = NETIO_RECV | NETIO_XMIT_CSUM | NETIO_TAG_NONE,2141* .num_receive_packets = NETIO_MAX_RECEIVE_PKTS,2142* .queue_id = 0,2143* },2144* @endcode2145*2146* instead of the old-style structure initialization:2147*2148* @code2149* // Bad example! Currently equivalent to the above, but don't do this.2150* netio_input_config_t config = {2151* NETIO_RECV | NETIO_XMIT_CSUM | NETIO_TAG_NONE, NETIO_MAX_RECEIVE_PKTS, 02152* },2153* @endcode2154*2155* since the C99 style requires no changes to the code if elements of the2156* config structure are rearranged. (It also makes the initialization much2157* easier to understand.)2158*2159* Except for items which address a particular tile's transmit or receive2160* characteristics, such as the ::NETIO_RECV flag, applications are advised2161* to specify the same set of configuration data on all registrations.2162* This prevents differing results if multiple tiles happen to do their2163* registration operations in a different order on different invocations of2164* the application. This is particularly important for things like link2165* management flags, and buffer size and homing specifications.2166*2167* Unless the ::NETIO_FIXED_BUFFER_VA flag is specified in flags, the NetIO2168* buffer pool is automatically created and mapped into the application's2169* virtual address space at an address chosen by the operating system,2170* using the common memory (cmem) facility in the Tilera Multicore2171* Components library. The cmem facility allows multiple processes to gain2172* access to shared memory which is mapped into each process at an2173* identical virtual address. In order for this to work, the processes2174* must have a common ancestor, which must create the common memory using2175* tmc_cmem_init().2176*2177* In programs using the iLib process creation API, or in programs which use2178* only one process (which include programs using the pthreads library),2179* tmc_cmem_init() is called automatically. All other applications2180* must call it explicitly, before any child processes which might call2181* netio_input_register() are created.2182*/2183typedef struct2184{2185/** Registration characteristics.21862187This value determines several characteristics of the registration;2188flags for different types of behavior are ORed together to make the2189final flag value. Generally applications should specify exactly2190one flag from each of the following categories:21912192- Whether the application will be receiving packets on this queue2193(::NETIO_RECV or ::NETIO_NO_RECV).21942195- Whether the application will be transmitting packets on this queue,2196and if so, whether it will request egress checksum calculation2197(::NETIO_XMIT, ::NETIO_XMIT_CSUM, or ::NETIO_NO_XMIT). It is2198legal to call netio_get_buffer() without one of the XMIT flags,2199as long as ::NETIO_RECV is specified; in this case, the retrieved2200buffers must be passed to another tile for transmission.22012202- Whether the application expects any vendor-specific tags in2203its packets' L2 headers (::NETIO_TAG_NONE, ::NETIO_TAG_BRCM,2204or ::NETIO_TAG_MRVL). This must match the configuration of the2205target IPP.22062207To accommodate applications written to previous versions of the NetIO2208interface, none of the flags above are currently required; if omitted,2209NetIO behaves more or less as if ::NETIO_RECV | ::NETIO_XMIT_CSUM |2210::NETIO_TAG_NONE were used. However, explicit specification of2211the relevant flags allows NetIO to do a better job of resource2212allocation, allows earlier detection of certain configuration errors,2213and may enable advanced features or higher performance in the future,2214so their use is strongly recommended.22152216Note that specifying ::NETIO_NO_RECV along with ::NETIO_NO_XMIT2217is a special case, intended primarily for use by programs which2218retrieve network statistics or do link management operations.2219When these flags are both specified, the resulting queue may not2220be used with NetIO routines other than netio_get(), netio_set(),2221and netio_input_unregister(). See @ref link for more information2222on link management.22232224Other flags are optional; their use is described below.2225*/2226int flags;22272228/** Interface name. This is a string which identifies the specific2229Ethernet controller hardware to be used. The format of the string2230is a device type and a device index, separated by a slash; so,2231the first 10 Gigabit Ethernet controller is named "xgbe/0", while2232the second 10/100/1000 Megabit Ethernet controller is named "gbe/1".2233*/2234const char* interface;22352236/** Receive packet queue size. This specifies the maximum number2237of ingress packets that can be received on this queue without2238being retrieved by @ref netio_get_packet(). If the IPP's distribution2239algorithm calls for a packet to be sent to this queue, and this2240number of packets are already pending there, the new packet2241will either be discarded, or sent to another tile registered2242for the same queue_id (see @ref drops). This value must2243be at least ::NETIO_MIN_RECEIVE_PKTS, can always be at least2244::NETIO_MAX_RECEIVE_PKTS, and may be larger than that on certain2245interfaces.2246*/2247int num_receive_packets;22482249/** The queue ID being requested. Legal values for this range from 02250to ::NETIO_MAX_QUEUE_ID, inclusive. ::NETIO_MAX_QUEUE_ID is always2251greater than or equal to the number of tiles; this allows one queue2252for each tile, plus at least one additional queue. Some applications2253may wish to use the additional queue as a destination for unwanted2254packets, since packets delivered to queues for which no tiles have2255registered are discarded.2256*/2257unsigned int queue_id;22582259/** Maximum number of small send buffers to be held in the local empty2260buffer cache. This specifies the size of the area which holds2261empty small egress buffers requested from the IPP but not yet2262retrieved via @ref netio_get_buffer(). This value must be greater2263than zero if the application will ever use @ref netio_get_buffer()2264to allocate empty small egress buffers; it may be no larger than2265::NETIO_MAX_SEND_BUFFERS. See @ref epp for more details on empty2266buffer caching.2267*/2268int num_send_buffers_small_total;22692270/** Number of small send buffers to be preallocated at registration.2271If this value is nonzero, the specified number of empty small egress2272buffers will be requested from the IPP during the netio_input_register2273operation; this may speed the execution of @ref netio_get_buffer().2274This may be no larger than @ref num_send_buffers_small_total. See @ref2275epp for more details on empty buffer caching.2276*/2277int num_send_buffers_small_prealloc;22782279/** Maximum number of large send buffers to be held in the local empty2280buffer cache. This specifies the size of the area which holds empty2281large egress buffers requested from the IPP but not yet retrieved via2282@ref netio_get_buffer(). This value must be greater than zero if the2283application will ever use @ref netio_get_buffer() to allocate empty2284large egress buffers; it may be no larger than ::NETIO_MAX_SEND_BUFFERS.2285See @ref epp for more details on empty buffer caching.2286*/2287int num_send_buffers_large_total;22882289/** Number of large send buffers to be preallocated at registration.2290If this value is nonzero, the specified number of empty large egress2291buffers will be requested from the IPP during the netio_input_register2292operation; this may speed the execution of @ref netio_get_buffer().2293This may be no larger than @ref num_send_buffers_large_total. See @ref2294epp for more details on empty buffer caching.2295*/2296int num_send_buffers_large_prealloc;22972298/** Maximum number of jumbo send buffers to be held in the local empty2299buffer cache. This specifies the size of the area which holds empty2300jumbo egress buffers requested from the IPP but not yet retrieved via2301@ref netio_get_buffer(). This value must be greater than zero if the2302application will ever use @ref netio_get_buffer() to allocate empty2303jumbo egress buffers; it may be no larger than ::NETIO_MAX_SEND_BUFFERS.2304See @ref epp for more details on empty buffer caching.2305*/2306int num_send_buffers_jumbo_total;23072308/** Number of jumbo send buffers to be preallocated at registration.2309If this value is nonzero, the specified number of empty jumbo egress2310buffers will be requested from the IPP during the netio_input_register2311operation; this may speed the execution of @ref netio_get_buffer().2312This may be no larger than @ref num_send_buffers_jumbo_total. See @ref2313epp for more details on empty buffer caching.2314*/2315int num_send_buffers_jumbo_prealloc;23162317/** Total packet buffer size. This determines the total size, in bytes,2318of the NetIO buffer pool. Note that the maximum number of available2319buffers of each size is determined during hypervisor configuration2320(see the <em>System Programmer's Guide</em> for details); this just2321influences how much host memory is allocated for those buffers.23222323The buffer pool is allocated from common memory, which will be2324automatically initialized if needed. If your buffer pool is larger2325than 240 MB, you might need to explicitly call @c tmc_cmem_init(),2326as described in the Application Libraries Reference Manual (UG227).23272328Packet buffers are currently allocated in chunks of 16 MB; this2329value will be rounded up to the next larger multiple of 16 MB.2330If this value is zero, a default of 32 MB will be used; this was2331the value used by previous versions of NetIO. Note that taking this2332default also affects the placement of buffers on Linux NUMA nodes.2333See @ref buffer_node_weights for an explanation of buffer placement.23342335In order to successfully allocate packet buffers, Linux must have2336available huge pages on the relevant Linux NUMA nodes. See the2337<em>System Programmer's Guide</em> for information on configuring2338huge page support in Linux.2339*/2340uint64_t total_buffer_size;23412342/** Buffer placement weighting factors.23432344This array specifies the relative amount of buffering to place2345on each of the available Linux NUMA nodes. This array is2346indexed by the NUMA node, and the values in the array are2347proportional to the amount of buffer space to allocate on that2348node.23492350If memory striping is enabled in the Hypervisor, then there is2351only one logical NUMA node (node 0). In that case, NetIO will by2352default ignore the suggested buffer node weights, and buffers2353will be striped across the physical memory controllers. See2354UG209 System Programmer's Guide for a description of the2355hypervisor option that controls memory striping.23562357If memory striping is disabled, then there are up to four NUMA2358nodes, corresponding to the four DDRAM controllers in the TILE2359processor architecture. See UG100 Tile Processor Architecture2360Overview for a diagram showing the location of each of the DDRAM2361controllers relative to the tile array.23622363For instance, if memory striping is disabled, the following2364configuration strucure:23652366@code2367netio_input_config_t config = {2368.2369.2370.2371.total_buffer_size = 4 * 16 * 1024 * 1024;2372.buffer_node_weights = { 1, 0, 1, 0 },2373},2374@endcode23752376would result in 32 MB of buffers being placed on controller 0, and237732 MB on controller 2. (Since buffers are allocated in units of237816 MB, some sets of weights will not be able to be matched exactly.)23792380For the weights to be effective, @ref total_buffer_size must be2381nonzero. If @ref total_buffer_size is zero, causing the default238232 MB of buffer space to be used, then any specified weights will2383be ignored, and buffers will positioned as they were in previous2384versions of NetIO:23852386- For xgbe/0 and gbe/0, 16 MB of buffers will be placed on controller 1,2387and the other 16 MB will be placed on controller 2.23882389- For xgbe/1 and gbe/1, 16 MB of buffers will be placed on controller 2,2390and the other 16 MB will be placed on controller 3.23912392If @ref total_buffer_size is nonzero, but all weights are zero,2393then all buffer space will be allocated on Linux NUMA node zero.23942395By default, the specified buffer placement is treated as a hint;2396if sufficient free memory is not available on the specified2397controllers, the buffers will be allocated elsewhere. However,2398if the ::NETIO_STRICT_HOMING flag is specified in @ref flags, then a2399failure to allocate buffer space exactly as requested will cause the2400registration operation to fail with an error of ::NETIO_CANNOT_HOME.24012402Note that maximal network performance cannot be achieved with2403only one memory controller.2404*/2405uint8_t buffer_node_weights[NETIO_NUM_NODE_WEIGHTS];24062407/** Fixed virtual address for packet buffers. Only valid when2408::NETIO_FIXED_BUFFER_VA is specified in @ref flags; see the2409description of that flag for details.2410*/2411void* fixed_buffer_va;24122413/**2414Maximum number of outstanding send packet requests. This value is2415only relevant when an EPP is in use; it determines the number of2416slots in the EPP's outgoing packet queue which this tile is allowed2417to consume, and thus the number of packets which may be sent before2418the sending tile must wait for an acknowledgment from the EPP.2419Modifying this value is generally only helpful when using @ref2420netio_send_packet_vector(), where it can help improve performance by2421allowing a single vector send operation to process more packets.2422Typically it is not specified, and the default, which divides the2423outgoing packet slots evenly between all tiles on the chip, is used.24242425If a registration asks for more outgoing packet queue slots than are2426available, ::NETIO_TOOMANY_XMIT will be returned. The total number2427of packet queue slots which are available for all tiles for each EPP2428is subject to change, but is currently ::NETIO_TOTAL_SENDS_OUTSTANDING.242924302431This value is ignored if ::NETIO_XMIT is not specified in flags.2432If you want to specify a large value here for a specific tile, you are2433advised to specify NETIO_NO_XMIT on other, non-transmitting tiles so2434that they do not consume a default number of packet slots. Any tile2435transmitting is required to have at least ::NETIO_MIN_SENDS_OUTSTANDING2436slots allocated to it; values less than that will be silently2437increased by the NetIO library.2438*/2439int num_sends_outstanding;2440}2441netio_input_config_t;244224432444/** Registration flags; used in the @ref netio_input_config_t structure.2445* @addtogroup setup2446*/2447/** @{ */24482449/** Fail a registration request if we can't put packet buffers2450on the specified memory controllers. */2451#define NETIO_STRICT_HOMING 0x0000000224522453/** This application expects no tags on its L2 headers. */2454#define NETIO_TAG_NONE 0x0000000424552456/** This application expects Marvell extended tags on its L2 headers. */2457#define NETIO_TAG_MRVL 0x0000000824582459/** This application expects Broadcom tags on its L2 headers. */2460#define NETIO_TAG_BRCM 0x0000001024612462/** This registration may call routines which receive packets. */2463#define NETIO_RECV 0x0000002024642465/** This registration may not call routines which receive packets. */2466#define NETIO_NO_RECV 0x0000004024672468/** This registration may call routines which transmit packets. */2469#define NETIO_XMIT 0x0000008024702471/** This registration may call routines which transmit packets with2472checksum acceleration. */2473#define NETIO_XMIT_CSUM 0x0000010024742475/** This registration may not call routines which transmit packets. */2476#define NETIO_NO_XMIT 0x0000020024772478/** This registration wants NetIO buffers mapped at an application-specified2479virtual address.24802481NetIO buffers are by default created by the TMC common memory facility,2482which must be configured by a common ancestor of all processes sharing2483a network interface. When this flag is specified, NetIO buffers are2484instead mapped at an address chosen by the application (and specified2485in @ref netio_input_config_t::fixed_buffer_va). This allows multiple2486unrelated but cooperating processes to share a NetIO interface.2487All processes sharing the same interface must specify this flag,2488and all must specify the same fixed virtual address.24892490@ref netio_input_config_t::fixed_buffer_va must be a2491multiple of 16 MB, and the packet buffers will occupy @ref2492netio_input_config_t::total_buffer_size bytes of virtual address2493space, beginning at that address. If any of those virtual addresses2494are currently occupied by other memory objects, like application or2495shared library code or data, @ref netio_input_register() will return2496::NETIO_FAULT. While it is impossible to provide a fixed_buffer_va2497which will work for all applications, a good first guess might be to2498use 0xb0000000 minus @ref netio_input_config_t::total_buffer_size.2499If that fails, it might be helpful to consult the running application's2500virtual address description file (/proc/<em>pid</em>/maps) to see2501which regions of virtual address space are available.2502*/2503#define NETIO_FIXED_BUFFER_VA 0x0000040025042505/** This registration call will not complete unless the network link2506is up. The process will wait several seconds for this to happen (the2507precise interval is link-dependent), but if the link does not come up,2508::NETIO_LINK_DOWN will be returned. This flag is the default if2509::NETIO_NOREQUIRE_LINK_UP is not specified. Note that this flag by2510itself does not request that the link be brought up; that can be done2511with the ::NETIO_AUTO_LINK_UPDN or ::NETIO_AUTO_LINK_UP flags (the2512latter is the default if no NETIO_AUTO_LINK_xxx flags are specified),2513or by explicitly setting the link's desired state via netio_set().2514If the link is not brought up by one of those methods, and this flag2515is specified, the registration operation will return ::NETIO_LINK_DOWN.2516This flag is ignored if it is specified along with ::NETIO_NO_XMIT and2517::NETIO_NO_RECV. See @ref link for more information on link2518management.2519*/2520#define NETIO_REQUIRE_LINK_UP 0x0000080025212522/** This registration call will complete even if the network link is not up.2523Whenever the link is not up, packets will not be sent or received:2524netio_get_packet() will return ::NETIO_NOPKT once all queued packets2525have been drained, and netio_send_packet() and similar routines will2526return NETIO_QUEUE_FULL once the outgoing packet queue in the EPP2527or the I/O shim is full. See @ref link for more information on link2528management.2529*/2530#define NETIO_NOREQUIRE_LINK_UP 0x0000100025312532#ifndef __DOXYGEN__2533/*2534* These are part of the implementation of the NETIO_AUTO_LINK_xxx flags,2535* but should not be used directly by applications, and are thus not2536* documented.2537*/2538#define _NETIO_AUTO_UP 0x000020002539#define _NETIO_AUTO_DN 0x000040002540#define _NETIO_AUTO_PRESENT 0x000080002541#endif25422543/** Set the desired state of the link to up, allowing any speeds which are2544supported by the link hardware, as part of this registration operation.2545Do not take down the link automatically. This is the default if2546no other NETIO_AUTO_LINK_xxx flags are specified. This flag is ignored2547if it is specified along with ::NETIO_NO_XMIT and ::NETIO_NO_RECV.2548See @ref link for more information on link management.2549*/2550#define NETIO_AUTO_LINK_UP (_NETIO_AUTO_PRESENT | _NETIO_AUTO_UP)25512552/** Set the desired state of the link to up, allowing any speeds which are2553supported by the link hardware, as part of this registration operation.2554Set the desired state of the link to down the next time no tiles are2555registered for packet reception or transmission. This flag is ignored2556if it is specified along with ::NETIO_NO_XMIT and ::NETIO_NO_RECV.2557See @ref link for more information on link management.2558*/2559#define NETIO_AUTO_LINK_UPDN (_NETIO_AUTO_PRESENT | _NETIO_AUTO_UP | \2560_NETIO_AUTO_DN)25612562/** Set the desired state of the link to down the next time no tiles are2563registered for packet reception or transmission. This flag is ignored2564if it is specified along with ::NETIO_NO_XMIT and ::NETIO_NO_RECV.2565See @ref link for more information on link management.2566*/2567#define NETIO_AUTO_LINK_DN (_NETIO_AUTO_PRESENT | _NETIO_AUTO_DN)25682569/** Do not bring up the link automatically as part of this registration2570operation. Do not take down the link automatically. This flag2571is ignored if it is specified along with ::NETIO_NO_XMIT and2572::NETIO_NO_RECV. See @ref link for more information on link management.2573*/2574#define NETIO_AUTO_LINK_NONE _NETIO_AUTO_PRESENT257525762577/** Minimum number of receive packets. */2578#define NETIO_MIN_RECEIVE_PKTS 1625792580/** Lower bound on the maximum number of receive packets; may be higher2581than this on some interfaces. */2582#define NETIO_MAX_RECEIVE_PKTS 12825832584/** Maximum number of send buffers, per packet size. */2585#define NETIO_MAX_SEND_BUFFERS 1625862587/** Number of EPP queue slots, and thus outstanding sends, per EPP. */2588#define NETIO_TOTAL_SENDS_OUTSTANDING 201525892590/** Minimum number of EPP queue slots, and thus outstanding sends, per2591* transmitting tile. */2592#define NETIO_MIN_SENDS_OUTSTANDING 16259325942595/**@}*/25962597#ifndef __DOXYGEN__25982599/**2600* An object for providing Ethernet packets to a process.2601*/2602struct __netio_queue_impl_t;26032604/**2605* An object for managing the user end of a NetIO queue.2606*/2607struct __netio_queue_user_impl_t;26082609#endif /* !__DOXYGEN__ */261026112612/** A netio_queue_t describes a NetIO communications endpoint.2613* @ingroup setup2614*/2615typedef struct2616{2617#ifdef __DOXYGEN__2618uint8_t opaque[8]; /**< This is an opaque structure. */2619#else2620struct __netio_queue_impl_t* __system_part; /**< The system part. */2621struct __netio_queue_user_impl_t* __user_part; /**< The user part. */2622#ifdef _NETIO_PTHREAD2623_netio_percpu_mutex_t lock; /**< Queue lock. */2624#endif2625#endif2626}2627netio_queue_t;262826292630/**2631* @brief Packet send context.2632*2633* @ingroup egress2634*2635* Packet send context for use with netio_send_packet_prepare and _commit.2636*/2637typedef struct2638{2639#ifdef __DOXYGEN__2640uint8_t opaque[44]; /**< This is an opaque structure. */2641#else2642uint8_t flags; /**< Defined below */2643uint8_t datalen; /**< Number of valid words pointed to by data. */2644uint32_t request[9]; /**< Request to be sent to the EPP or shim. Note2645that this is smaller than the 11-word maximum2646request size, since some constant values are2647not saved in the context. */2648uint32_t *data; /**< Data to be sent to the EPP or shim via IDN. */2649#endif2650}2651netio_send_pkt_context_t;265226532654#ifndef __DOXYGEN__2655#define SEND_PKT_CTX_USE_EPP 1 /**< We're sending to an EPP. */2656#define SEND_PKT_CTX_SEND_CSUM 2 /**< Request includes a checksum. */2657#endif26582659/**2660* @brief Packet vector entry.2661*2662* @ingroup egress2663*2664* This data structure is used with netio_send_packet_vector() to send multiple2665* packets with one NetIO call. The structure should be initialized by2666* calling netio_pkt_vector_set(), rather than by setting the fields2667* directly.2668*2669* This structure is guaranteed to be a power of two in size, no2670* bigger than one L2 cache line, and to be aligned modulo its size.2671*/2672typedef struct2673#ifndef __DOXYGEN__2674__attribute__((aligned(8)))2675#endif2676{2677/** Reserved for use by the user application. When initialized with2678* the netio_set_pkt_vector_entry() function, this field is guaranteed2679* to be visible to readers only after all other fields are already2680* visible. This way it can be used as a valid flag or generation2681* counter. */2682uint8_t user_data;26832684/* Structure members below this point should not be accessed directly by2685* applications, as they may change in the future. */26862687/** Low 8 bits of the packet address to send. The high bits are2688* acquired from the 'handle' field. */2689uint8_t buffer_address_low;26902691/** Number of bytes to transmit. */2692uint16_t size;26932694/** The raw handle from a netio_pkt_t. If this is NETIO_PKT_HANDLE_NONE,2695* this vector entry will be skipped and no packet will be transmitted. */2696netio_pkt_handle_t handle;2697}2698netio_pkt_vector_entry_t;269927002701/**2702* @brief Initialize fields in a packet vector entry.2703*2704* @ingroup egress2705*2706* @param[out] v Pointer to the vector entry to be initialized.2707* @param[in] pkt Packet to be transmitted when the vector entry is passed to2708* netio_send_packet_vector(). Note that the packet's attributes2709* (e.g., its L2 offset and length) are captured at the time this2710* routine is called; subsequent changes in those attributes will not2711* be reflected in the packet which is actually transmitted.2712* Changes in the packet's contents, however, will be so reflected.2713* If this is NULL, no packet will be transmitted.2714* @param[in] user_data User data to be set in the vector entry.2715* This function guarantees that the "user_data" field will become2716* visible to a reader only after all other fields have become visible.2717* This allows a structure in a ring buffer to be written and read2718* by a polling reader without any locks or other synchronization.2719*/2720static __inline void2721netio_pkt_vector_set(volatile netio_pkt_vector_entry_t* v, netio_pkt_t* pkt,2722uint8_t user_data)2723{2724if (pkt)2725{2726if (NETIO_PKT_IS_MINIMAL(pkt))2727{2728netio_pkt_minimal_metadata_t* mmd =2729(netio_pkt_minimal_metadata_t*) &pkt->__metadata;2730v->buffer_address_low = (uintptr_t) NETIO_PKT_L2_DATA_MM(mmd, pkt) & 0xFF;2731v->size = NETIO_PKT_L2_LENGTH_MM(mmd, pkt);2732}2733else2734{2735netio_pkt_metadata_t* mda = &pkt->__metadata;2736v->buffer_address_low = (uintptr_t) NETIO_PKT_L2_DATA_M(mda, pkt) & 0xFF;2737v->size = NETIO_PKT_L2_LENGTH_M(mda, pkt);2738}2739v->handle.word = pkt->__packet.word;2740}2741else2742{2743v->handle.word = 0; /* Set handle to NETIO_PKT_HANDLE_NONE. */2744}27452746__asm__("" : : : "memory");27472748v->user_data = user_data;2749}275027512752/**2753* Flags and structures for @ref netio_get() and @ref netio_set().2754* @ingroup config2755*/27562757/** @{ */2758/** Parameter class; addr is a NETIO_PARAM_xxx value. */2759#define NETIO_PARAM 02760/** Interface MAC address. This address is only valid with @ref netio_get().2761* The value is a 6-byte MAC address. Depending upon the overall system2762* design, a MAC address may or may not be available for each interface. */2763#define NETIO_PARAM_MAC 027642765/** Determine whether to suspend output on the receipt of pause frames.2766* If the value is nonzero, the I/O shim will suspend output when a pause2767* frame is received. If the value is zero, pause frames will be ignored. */2768#define NETIO_PARAM_PAUSE_IN 127692770/** Determine whether to send pause frames if the I/O shim packet FIFOs are2771* nearly full. If the value is zero, pause frames are not sent. If2772* the value is nonzero, it is the delay value which will be sent in any2773* pause frames which are output, in units of 512 bit times. */2774#define NETIO_PARAM_PAUSE_OUT 227752776/** Jumbo frame support. The value is a 4-byte integer. If the value is2777* nonzero, the MAC will accept frames of up to 10240 bytes. If the value2778* is zero, the MAC will only accept frames of up to 1544 bytes. */2779#define NETIO_PARAM_JUMBO 327802781/** I/O shim's overflow statistics register. The value is two 16-bit integers.2782* The first 16-bit value (or the low 16 bits, if the value is treated as a2783* 32-bit number) is the count of packets which were completely dropped and2784* not delivered by the shim. The second 16-bit value (or the high 16 bits,2785* if the value is treated as a 32-bit number) is the count of packets2786* which were truncated and thus only partially delivered by the shim. This2787* register is automatically reset to zero after it has been read.2788*/2789#define NETIO_PARAM_OVERFLOW 427902791/** IPP statistics. This address is only valid with @ref netio_get(). The2792* value is a netio_stat_t structure. Unlike the I/O shim statistics, the2793* IPP statistics are not all reset to zero on read; see the description2794* of the netio_stat_t for details. */2795#define NETIO_PARAM_STAT 527962797/** Possible link state. The value is a combination of "NETIO_LINK_xxx"2798* flags. With @ref netio_get(), this will indicate which flags are2799* actually supported by the hardware.2800*2801* For historical reasons, specifying this value to netio_set() will have2802* the same behavior as using ::NETIO_PARAM_LINK_CONFIG, but this usage is2803* discouraged.2804*/2805#define NETIO_PARAM_LINK_POSSIBLE_STATE 628062807/** Link configuration. The value is a combination of "NETIO_LINK_xxx" flags.2808* With @ref netio_set(), this will attempt to immediately bring up the2809* link using whichever of the requested flags are supported by the2810* hardware, or take down the link if the flags are zero; if this is2811* not possible, an error will be returned. Many programs will want2812* to use ::NETIO_PARAM_LINK_DESIRED_STATE instead.2813*2814* For historical reasons, specifying this value to netio_get() will2815* have the same behavior as using ::NETIO_PARAM_LINK_POSSIBLE_STATE,2816* but this usage is discouraged.2817*/2818#define NETIO_PARAM_LINK_CONFIG NETIO_PARAM_LINK_POSSIBLE_STATE28192820/** Current link state. This address is only valid with @ref netio_get().2821* The value is zero or more of the "NETIO_LINK_xxx" flags, ORed together.2822* If the link is down, the value ANDed with NETIO_LINK_SPEED will be2823* zero; if the link is up, the value ANDed with NETIO_LINK_SPEED will2824* result in exactly one of the NETIO_LINK_xxx values, indicating the2825* current speed. */2826#define NETIO_PARAM_LINK_CURRENT_STATE 728272828/** Variant symbol for current state, retained for compatibility with2829* pre-MDE-2.1 programs. */2830#define NETIO_PARAM_LINK_STATUS NETIO_PARAM_LINK_CURRENT_STATE28312832/** Packet Coherence protocol. This address is only valid with @ref netio_get().2833* The value is nonzero if the interface is configured for cache-coherent DMA.2834*/2835#define NETIO_PARAM_COHERENT 828362837/** Desired link state. The value is a conbination of "NETIO_LINK_xxx"2838* flags, which specify the desired state for the link. With @ref2839* netio_set(), this will, in the background, attempt to bring up the link2840* using whichever of the requested flags are reasonable, or take down the2841* link if the flags are zero. The actual link up or down operation may2842* happen after this call completes. If the link state changes in the2843* future, the system will continue to try to get back to the desired link2844* state; for instance, if the link is brought up successfully, and then2845* the network cable is disconnected, the link will go down. However, the2846* desired state of the link is still up, so if the cable is reconnected,2847* the link will be brought up again.2848*2849* With @ref netio_get(), this will indicate the desired state for the2850* link, as set with a previous netio_set() call, or implicitly by a2851* netio_input_register() or netio_input_unregister() operation. This may2852* not reflect the current state of the link; to get that, use2853* ::NETIO_PARAM_LINK_CURRENT_STATE. */2854#define NETIO_PARAM_LINK_DESIRED_STATE 928552856/** NetIO statistics structure. Retrieved using the ::NETIO_PARAM_STAT2857* address passed to @ref netio_get(). */2858typedef struct2859{2860/** Number of packets which have been received by the IPP and forwarded2861* to a tile's receive queue for processing. This value wraps at its2862* maximum, and is not cleared upon read. */2863uint32_t packets_received;28642865/** Number of packets which have been dropped by the IPP, because they could2866* not be received, or could not be forwarded to a tile. The former happens2867* when the IPP does not have a free packet buffer of suitable size for an2868* incoming frame. The latter happens when all potential destination tiles2869* for a packet, as defined by the group, bucket, and queue configuration,2870* have full receive queues. This value wraps at its maximum, and is not2871* cleared upon read. */2872uint32_t packets_dropped;28732874/*2875* Note: the #defines after each of the following four one-byte values2876* denote their location within the third word of the netio_stat_t. They2877* are intended for use only by the IPP implementation and are thus omitted2878* from the Doxygen output.2879*/28802881/** Number of packets dropped because no worker was able to accept a new2882* packet. This value saturates at its maximum, and is cleared upon2883* read. */2884uint8_t drops_no_worker;2885#ifndef __DOXYGEN__2886#define NETIO_STAT_DROPS_NO_WORKER 02887#endif28882889/** Number of packets dropped because no small buffers were available.2890* This value saturates at its maximum, and is cleared upon read. */2891uint8_t drops_no_smallbuf;2892#ifndef __DOXYGEN__2893#define NETIO_STAT_DROPS_NO_SMALLBUF 12894#endif28952896/** Number of packets dropped because no large buffers were available.2897* This value saturates at its maximum, and is cleared upon read. */2898uint8_t drops_no_largebuf;2899#ifndef __DOXYGEN__2900#define NETIO_STAT_DROPS_NO_LARGEBUF 22901#endif29022903/** Number of packets dropped because no jumbo buffers were available.2904* This value saturates at its maximum, and is cleared upon read. */2905uint8_t drops_no_jumbobuf;2906#ifndef __DOXYGEN__2907#define NETIO_STAT_DROPS_NO_JUMBOBUF 32908#endif2909}2910netio_stat_t;291129122913/** Link can run, should run, or is running at 10 Mbps. */2914#define NETIO_LINK_10M 0x0129152916/** Link can run, should run, or is running at 100 Mbps. */2917#define NETIO_LINK_100M 0x0229182919/** Link can run, should run, or is running at 1 Gbps. */2920#define NETIO_LINK_1G 0x0429212922/** Link can run, should run, or is running at 10 Gbps. */2923#define NETIO_LINK_10G 0x0829242925/** Link should run at the highest speed supported by the link and by2926* the device connected to the link. Only usable as a value for2927* the link's desired state; never returned as a value for the current2928* or possible states. */2929#define NETIO_LINK_ANYSPEED 0x1029302931/** All legal link speeds. */2932#define NETIO_LINK_SPEED (NETIO_LINK_10M | \2933NETIO_LINK_100M | \2934NETIO_LINK_1G | \2935NETIO_LINK_10G | \2936NETIO_LINK_ANYSPEED)293729382939/** MAC register class. Addr is a register offset within the MAC.2940* Registers within the XGbE and GbE MACs are documented in the Tile2941* Processor I/O Device Guide (UG104). MAC registers start at address2942* 0x4000, and do not include the MAC_INTERFACE registers. */2943#define NETIO_MAC 129442945/** MDIO register class (IEEE 802.3 clause 22 format). Addr is the "addr"2946* member of a netio_mdio_addr_t structure. */2947#define NETIO_MDIO 229482949/** MDIO register class (IEEE 802.3 clause 45 format). Addr is the "addr"2950* member of a netio_mdio_addr_t structure. */2951#define NETIO_MDIO_CLAUSE45 329522953/** NetIO MDIO address type. Retrieved or provided using the ::NETIO_MDIO2954* address passed to @ref netio_get() or @ref netio_set(). */2955typedef union2956{2957struct2958{2959unsigned int reg:16; /**< MDIO register offset. For clause 22 access,2960must be less than 32. */2961unsigned int phy:5; /**< Which MDIO PHY to access. */2962unsigned int dev:5; /**< Which MDIO device to access within that PHY.2963Applicable for clause 45 access only; ignored2964for clause 22 access. */2965}2966bits; /**< Container for bitfields. */2967uint64_t addr; /**< Value to pass to @ref netio_get() or2968* @ref netio_set(). */2969}2970netio_mdio_addr_t;29712972/** @} */29732974#endif /* __NETIO_INTF_H__ */297529762977