Path: blob/master/arch/tile/include/hv/drv_xgbe_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* @file drv_xgbe_intf.h16* Interface to the hypervisor XGBE driver.17*/1819#ifndef __DRV_XGBE_INTF_H__20#define __DRV_XGBE_INTF_H__2122/**23* An object for forwarding VAs and PAs to the hypervisor.24* @ingroup types25*26* This allows the supervisor to specify a number of areas of memory to27* store packet buffers.28*/29typedef struct30{31/** The physical address of the memory. */32HV_PhysAddr pa;33/** Page table entry for the memory. This is only used to derive the34* memory's caching mode; the PA bits are ignored. */35HV_PTE pte;36/** The virtual address of the memory. */37HV_VirtAddr va;38/** Size (in bytes) of the memory area. */39int size;4041}42netio_ipp_address_t;4344/** The various pread/pwrite offsets into the hypervisor-level driver.45* @ingroup types46*/47typedef enum48{49/** Inform the Linux driver of the address of the NetIO arena memory.50* This offset is actually only used to convey information from netio51* to the Linux driver; it never makes it from there to the hypervisor.52* Write-only; takes a uint32_t specifying the VA address. */53NETIO_FIXED_ADDR = 0x5000000000000000ULL,5455/** Inform the Linux driver of the size of the NetIO arena memory.56* This offset is actually only used to convey information from netio57* to the Linux driver; it never makes it from there to the hypervisor.58* Write-only; takes a uint32_t specifying the VA size. */59NETIO_FIXED_SIZE = 0x5100000000000000ULL,6061/** Register current tile with IPP. Write then read: write, takes a62* netio_input_config_t, read returns a pointer to a netio_queue_impl_t. */63NETIO_IPP_INPUT_REGISTER_OFF = 0x6000000000000000ULL,6465/** Unregister current tile from IPP. Write-only, takes a dummy argument. */66NETIO_IPP_INPUT_UNREGISTER_OFF = 0x6100000000000000ULL,6768/** Start packets flowing. Write-only, takes a dummy argument. */69NETIO_IPP_INPUT_INIT_OFF = 0x6200000000000000ULL,7071/** Stop packets flowing. Write-only, takes a dummy argument. */72NETIO_IPP_INPUT_UNINIT_OFF = 0x6300000000000000ULL,7374/** Configure group (typically we group on VLAN). Write-only: takes an75* array of netio_group_t's, low 24 bits of the offset is the base group76* number times the size of a netio_group_t. */77NETIO_IPP_INPUT_GROUP_CFG_OFF = 0x6400000000000000ULL,7879/** Configure bucket. Write-only: takes an array of netio_bucket_t's, low80* 24 bits of the offset is the base bucket number times the size of a81* netio_bucket_t. */82NETIO_IPP_INPUT_BUCKET_CFG_OFF = 0x6500000000000000ULL,8384/** Get/set a parameter. Read or write: read or write data is the parameter85* value, low 32 bits of the offset is a __netio_getset_offset_t. */86NETIO_IPP_PARAM_OFF = 0x6600000000000000ULL,8788/** Get fast I/O index. Read-only; returns a 4-byte base index value. */89NETIO_IPP_GET_FASTIO_OFF = 0x6700000000000000ULL,9091/** Configure hijack IP address. Packets with this IPv4 dest address92* go to bucket NETIO_NUM_BUCKETS - 1. Write-only: takes an IP address93* in some standard form. FIXME: Define the form! */94NETIO_IPP_INPUT_HIJACK_CFG_OFF = 0x6800000000000000ULL,9596/**97* Offsets beyond this point are reserved for the supervisor (although that98* enforcement must be done by the supervisor driver itself).99*/100NETIO_IPP_USER_MAX_OFF = 0x6FFFFFFFFFFFFFFFULL,101102/** Register I/O memory. Write-only, takes a netio_ipp_address_t. */103NETIO_IPP_IOMEM_REGISTER_OFF = 0x7000000000000000ULL,104105/** Unregister I/O memory. Write-only, takes a netio_ipp_address_t. */106NETIO_IPP_IOMEM_UNREGISTER_OFF = 0x7100000000000000ULL,107108/* Offsets greater than 0x7FFFFFFF can't be used directly from Linux109* userspace code due to limitations in the pread/pwrite syscalls. */110111/** Drain LIPP buffers. */112NETIO_IPP_DRAIN_OFF = 0xFA00000000000000ULL,113114/** Supply a netio_ipp_address_t to be used as shared memory for the115* LEPP command queue. */116NETIO_EPP_SHM_OFF = 0xFB00000000000000ULL,117118/* 0xFC... is currently unused. */119120/** Stop IPP/EPP tiles. Write-only, takes a dummy argument. */121NETIO_IPP_STOP_SHIM_OFF = 0xFD00000000000000ULL,122123/** Start IPP/EPP tiles. Write-only, takes a dummy argument. */124NETIO_IPP_START_SHIM_OFF = 0xFE00000000000000ULL,125126/** Supply packet arena. Write-only, takes an array of127* netio_ipp_address_t values. */128NETIO_IPP_ADDRESS_OFF = 0xFF00000000000000ULL,129} netio_hv_offset_t;130131/** Extract the base offset from an offset */132#define NETIO_BASE_OFFSET(off) ((off) & 0xFF00000000000000ULL)133/** Extract the local offset from an offset */134#define NETIO_LOCAL_OFFSET(off) ((off) & 0x00FFFFFFFFFFFFFFULL)135136137/**138* Get/set offset.139*/140typedef union141{142struct143{144uint64_t addr:48; /**< Class-specific address */145unsigned int class:8; /**< Class (e.g., NETIO_PARAM) */146unsigned int opcode:8; /**< High 8 bits of NETIO_IPP_PARAM_OFF */147}148bits; /**< Bitfields */149uint64_t word; /**< Aggregated value to use as the offset */150}151__netio_getset_offset_t;152153/**154* Fast I/O index offsets (must be contiguous).155*/156typedef enum157{158NETIO_FASTIO_ALLOCATE = 0, /**< Get empty packet buffer */159NETIO_FASTIO_FREE_BUFFER = 1, /**< Give buffer back to IPP */160NETIO_FASTIO_RETURN_CREDITS = 2, /**< Give credits to IPP */161NETIO_FASTIO_SEND_PKT_NOCK = 3, /**< Send a packet, no checksum */162NETIO_FASTIO_SEND_PKT_CK = 4, /**< Send a packet, with checksum */163NETIO_FASTIO_SEND_PKT_VEC = 5, /**< Send a vector of packets */164NETIO_FASTIO_SENDV_PKT = 6, /**< Sendv one packet */165NETIO_FASTIO_NUM_INDEX = 7, /**< Total number of fast I/O indices */166} netio_fastio_index_t;167168/** 3-word return type for Fast I/O call. */169typedef struct170{171int err; /**< Error code. */172uint32_t val0; /**< Value. Meaning depends upon the specific call. */173uint32_t val1; /**< Value. Meaning depends upon the specific call. */174} netio_fastio_rv3_t;175176/** 0-argument fast I/O call */177int __netio_fastio0(uint32_t fastio_index);178/** 1-argument fast I/O call */179int __netio_fastio1(uint32_t fastio_index, uint32_t arg0);180/** 3-argument fast I/O call, 2-word return value */181netio_fastio_rv3_t __netio_fastio3_rv3(uint32_t fastio_index, uint32_t arg0,182uint32_t arg1, uint32_t arg2);183/** 4-argument fast I/O call */184int __netio_fastio4(uint32_t fastio_index, uint32_t arg0, uint32_t arg1,185uint32_t arg2, uint32_t arg3);186/** 6-argument fast I/O call */187int __netio_fastio6(uint32_t fastio_index, uint32_t arg0, uint32_t arg1,188uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5);189/** 9-argument fast I/O call */190int __netio_fastio9(uint32_t fastio_index, uint32_t arg0, uint32_t arg1,191uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5,192uint32_t arg6, uint32_t arg7, uint32_t arg8);193194/** Allocate an empty packet.195* @param fastio_index Fast I/O index.196* @param size Size of the packet to allocate.197*/198#define __netio_fastio_allocate(fastio_index, size) \199__netio_fastio1((fastio_index) + NETIO_FASTIO_ALLOCATE, size)200201/** Free a buffer.202* @param fastio_index Fast I/O index.203* @param handle Handle for the packet to free.204*/205#define __netio_fastio_free_buffer(fastio_index, handle) \206__netio_fastio1((fastio_index) + NETIO_FASTIO_FREE_BUFFER, handle)207208/** Increment our receive credits.209* @param fastio_index Fast I/O index.210* @param credits Number of credits to add.211*/212#define __netio_fastio_return_credits(fastio_index, credits) \213__netio_fastio1((fastio_index) + NETIO_FASTIO_RETURN_CREDITS, credits)214215/** Send packet, no checksum.216* @param fastio_index Fast I/O index.217* @param ackflag Nonzero if we want an ack.218* @param size Size of the packet.219* @param va Virtual address of start of packet.220* @param handle Packet handle.221*/222#define __netio_fastio_send_pkt_nock(fastio_index, ackflag, size, va, handle) \223__netio_fastio4((fastio_index) + NETIO_FASTIO_SEND_PKT_NOCK, ackflag, \224size, va, handle)225226/** Send packet, calculate checksum.227* @param fastio_index Fast I/O index.228* @param ackflag Nonzero if we want an ack.229* @param size Size of the packet.230* @param va Virtual address of start of packet.231* @param handle Packet handle.232* @param csum0 Shim checksum header.233* @param csum1 Checksum seed.234*/235#define __netio_fastio_send_pkt_ck(fastio_index, ackflag, size, va, handle, \236csum0, csum1) \237__netio_fastio6((fastio_index) + NETIO_FASTIO_SEND_PKT_CK, ackflag, \238size, va, handle, csum0, csum1)239240241/** Format for the "csum0" argument to the __netio_fastio_send routines242* and LEPP. Note that this is currently exactly identical to the243* ShimProtocolOffloadHeader.244*/245typedef union246{247struct248{249unsigned int start_byte:7; /**< The first byte to be checksummed */250unsigned int count:14; /**< Number of bytes to be checksummed. */251unsigned int destination_byte:7; /**< The byte to write the checksum to. */252unsigned int reserved:4; /**< Reserved. */253} bits; /**< Decomposed method of access. */254unsigned int word; /**< To send out the IDN. */255} __netio_checksum_header_t;256257258/** Sendv packet with 1 or 2 segments.259* @param fastio_index Fast I/O index.260* @param flags Ack/csum/notify flags in low 3 bits; number of segments minus261* 1 in next 2 bits; expected checksum in high 16 bits.262* @param confno Confirmation number to request, if notify flag set.263* @param csum0 Checksum descriptor; if zero, no checksum.264* @param va_F Virtual address of first segment.265* @param va_L Virtual address of last segment, if 2 segments.266* @param len_F_L Length of first segment in low 16 bits; length of last267* segment, if 2 segments, in high 16 bits.268*/269#define __netio_fastio_sendv_pkt_1_2(fastio_index, flags, confno, csum0, \270va_F, va_L, len_F_L) \271__netio_fastio6((fastio_index) + NETIO_FASTIO_SENDV_PKT, flags, confno, \272csum0, va_F, va_L, len_F_L)273274/** Send packet on PCIe interface.275* @param fastio_index Fast I/O index.276* @param flags Ack/csum/notify flags in low 3 bits.277* @param confno Confirmation number to request, if notify flag set.278* @param csum0 Checksum descriptor; Hard wired 0, not needed for PCIe.279* @param va_F Virtual address of the packet buffer.280* @param va_L Virtual address of last segment, if 2 segments. Hard wired 0.281* @param len_F_L Length of the packet buffer in low 16 bits.282*/283#define __netio_fastio_send_pcie_pkt(fastio_index, flags, confno, csum0, \284va_F, va_L, len_F_L) \285__netio_fastio6((fastio_index) + PCIE_FASTIO_SENDV_PKT, flags, confno, \286csum0, va_F, va_L, len_F_L)287288/** Sendv packet with 3 or 4 segments.289* @param fastio_index Fast I/O index.290* @param flags Ack/csum/notify flags in low 3 bits; number of segments minus291* 1 in next 2 bits; expected checksum in high 16 bits.292* @param confno Confirmation number to request, if notify flag set.293* @param csum0 Checksum descriptor; if zero, no checksum.294* @param va_F Virtual address of first segment.295* @param va_L Virtual address of last segment (third segment if 3 segments,296* fourth segment if 4 segments).297* @param len_F_L Length of first segment in low 16 bits; length of last298* segment in high 16 bits.299* @param va_M0 Virtual address of "middle 0" segment; this segment is sent300* second when there are three segments, and third if there are four.301* @param va_M1 Virtual address of "middle 1" segment; this segment is sent302* second when there are four segments.303* @param len_M0_M1 Length of middle 0 segment in low 16 bits; length of middle304* 1 segment, if 4 segments, in high 16 bits.305*/306#define __netio_fastio_sendv_pkt_3_4(fastio_index, flags, confno, csum0, va_F, \307va_L, len_F_L, va_M0, va_M1, len_M0_M1) \308__netio_fastio9((fastio_index) + NETIO_FASTIO_SENDV_PKT, flags, confno, \309csum0, va_F, va_L, len_F_L, va_M0, va_M1, len_M0_M1)310311/** Send vector of packets.312* @param fastio_index Fast I/O index.313* @param seqno Number of packets transmitted so far on this interface;314* used to decide which packets should be acknowledged.315* @param nentries Number of entries in vector.316* @param va Virtual address of start of vector entry array.317* @return 3-word netio_fastio_rv3_t structure. The structure's err member318* is an error code, or zero if no error. The val0 member is the319* updated value of seqno; it has been incremented by 1 for each320* packet sent. That increment may be less than nentries if an321* error occurred, or if some of the entries in the vector contain322* handles equal to NETIO_PKT_HANDLE_NONE. The val1 member is the323* updated value of nentries; it has been decremented by 1 for each324* vector entry processed. Again, that decrement may be less than325* nentries (leaving the returned value positive) if an error326* occurred.327*/328#define __netio_fastio_send_pkt_vec(fastio_index, seqno, nentries, va) \329__netio_fastio3_rv3((fastio_index) + NETIO_FASTIO_SEND_PKT_VEC, seqno, \330nentries, va)331332333/** An egress DMA command for LEPP. */334typedef struct335{336/** Is this a TSO transfer?337*338* NOTE: This field is always 0, to distinguish it from339* lepp_tso_cmd_t. It must come first!340*/341uint8_t tso : 1;342343/** Unused padding bits. */344uint8_t _unused : 3;345346/** Should this packet be sent directly from caches instead of DRAM,347* using hash-for-home to locate the packet data?348*/349uint8_t hash_for_home : 1;350351/** Should we compute a checksum? */352uint8_t compute_checksum : 1;353354/** Is this the final buffer for this packet?355*356* A single packet can be split over several input buffers (a "gather"357* operation). This flag indicates that this is the last buffer358* in a packet.359*/360uint8_t end_of_packet : 1;361362/** Should LEPP advance 'comp_busy' when this DMA is fully finished? */363uint8_t send_completion : 1;364365/** High bits of Client Physical Address of the start of the buffer366* to be egressed.367*368* NOTE: Only 6 bits are actually needed here, as CPAs are369* currently 38 bits. So two bits could be scavenged from this.370*/371uint8_t cpa_hi;372373/** The number of bytes to be egressed. */374uint16_t length;375376/** Low 32 bits of Client Physical Address of the start of the buffer377* to be egressed.378*/379uint32_t cpa_lo;380381/** Checksum information (only used if 'compute_checksum'). */382__netio_checksum_header_t checksum_data;383384} lepp_cmd_t;385386387/** A chunk of physical memory for a TSO egress. */388typedef struct389{390/** The low bits of the CPA. */391uint32_t cpa_lo;392/** The high bits of the CPA. */393uint16_t cpa_hi : 15;394/** Should this packet be sent directly from caches instead of DRAM,395* using hash-for-home to locate the packet data?396*/397uint16_t hash_for_home : 1;398/** The length in bytes. */399uint16_t length;400} lepp_frag_t;401402403/** An LEPP command that handles TSO. */404typedef struct405{406/** Is this a TSO transfer?407*408* NOTE: This field is always 1, to distinguish it from409* lepp_cmd_t. It must come first!410*/411uint8_t tso : 1;412413/** Unused padding bits. */414uint8_t _unused : 7;415416/** Size of the header[] array in bytes. It must be in the range417* [40, 127], which are the smallest header for a TCP packet over418* Ethernet and the maximum possible prepend size supported by419* hardware, respectively. Note that the array storage must be420* padded out to a multiple of four bytes so that the following421* LEPP command is aligned properly.422*/423uint8_t header_size;424425/** Byte offset of the IP header in header[]. */426uint8_t ip_offset;427428/** Byte offset of the TCP header in header[]. */429uint8_t tcp_offset;430431/** The number of bytes to use for the payload of each packet,432* except of course the last one, which may not have enough bytes.433* This means that each Ethernet packet except the last will have a434* size of header_size + payload_size.435*/436uint16_t payload_size;437438/** The length of the 'frags' array that follows this struct. */439uint16_t num_frags;440441/** The actual frags. */442lepp_frag_t frags[0 /* Variable-sized; num_frags entries. */];443444/*445* The packet header template logically follows frags[],446* but you can't declare that in C.447*448* uint32_t header[header_size_in_words_rounded_up];449*/450451} lepp_tso_cmd_t;452453454/** An LEPP completion ring entry. */455typedef void* lepp_comp_t;456457458/** Maximum number of frags for one TSO command. This is adapted from459* linux's "MAX_SKB_FRAGS", and presumably over-estimates by one, for460* our page size of exactly 65536. We add one for a "body" fragment.461*/462#define LEPP_MAX_FRAGS (65536 / HV_PAGE_SIZE_SMALL + 2 + 1)463464/** Total number of bytes needed for an lepp_tso_cmd_t. */465#define LEPP_TSO_CMD_SIZE(num_frags, header_size) \466(sizeof(lepp_tso_cmd_t) + \467(num_frags) * sizeof(lepp_frag_t) + \468(((header_size) + 3) & -4))469470/** The size of the lepp "cmd" queue. */471#define LEPP_CMD_QUEUE_BYTES \472(((CHIP_L2_CACHE_SIZE() - 2 * CHIP_L2_LINE_SIZE()) / \473(sizeof(lepp_cmd_t) + sizeof(lepp_comp_t))) * sizeof(lepp_cmd_t))474475/** The largest possible command that can go in lepp_queue_t::cmds[]. */476#define LEPP_MAX_CMD_SIZE LEPP_TSO_CMD_SIZE(LEPP_MAX_FRAGS, 128)477478/** The largest possible value of lepp_queue_t::cmd_{head, tail} (inclusive).479*/480#define LEPP_CMD_LIMIT \481(LEPP_CMD_QUEUE_BYTES - LEPP_MAX_CMD_SIZE)482483/** The maximum number of completions in an LEPP queue. */484#define LEPP_COMP_QUEUE_SIZE \485((LEPP_CMD_LIMIT + sizeof(lepp_cmd_t) - 1) / sizeof(lepp_cmd_t))486487/** Increment an index modulo the queue size. */488#define LEPP_QINC(var) \489(var = __insn_mnz(var - (LEPP_COMP_QUEUE_SIZE - 1), var + 1))490491/** A queue used to convey egress commands from the client to LEPP. */492typedef struct493{494/** Index of first completion not yet processed by user code.495* If this is equal to comp_busy, there are no such completions.496*497* NOTE: This is only read/written by the user.498*/499unsigned int comp_head;500501/** Index of first completion record not yet completed.502* If this is equal to comp_tail, there are no such completions.503* This index gets advanced (modulo LEPP_QUEUE_SIZE) whenever504* a command with the 'completion' bit set is finished.505*506* NOTE: This is only written by LEPP, only read by the user.507*/508volatile unsigned int comp_busy;509510/** Index of the first empty slot in the completion ring.511* Entries from this up to but not including comp_head (in ring order)512* can be filled in with completion data.513*514* NOTE: This is only read/written by the user.515*/516unsigned int comp_tail;517518/** Byte index of first command enqueued for LEPP but not yet processed.519*520* This is always divisible by sizeof(void*) and always <= LEPP_CMD_LIMIT.521*522* NOTE: LEPP advances this counter as soon as it no longer needs523* the cmds[] storage for this entry, but the transfer is not actually524* complete (i.e. the buffer pointed to by the command is no longer525* needed) until comp_busy advances.526*527* If this is equal to cmd_tail, the ring is empty.528*529* NOTE: This is only written by LEPP, only read by the user.530*/531volatile unsigned int cmd_head;532533/** Byte index of first empty slot in the command ring. This field can534* be incremented up to but not equal to cmd_head (because that would535* mean the ring is empty).536*537* This is always divisible by sizeof(void*) and always <= LEPP_CMD_LIMIT.538*539* NOTE: This is read/written by the user, only read by LEPP.540*/541volatile unsigned int cmd_tail;542543/** A ring of variable-sized egress DMA commands.544*545* NOTE: Only written by the user, only read by LEPP.546*/547char cmds[LEPP_CMD_QUEUE_BYTES]548__attribute__((aligned(CHIP_L2_LINE_SIZE())));549550/** A ring of user completion data.551* NOTE: Only read/written by the user.552*/553lepp_comp_t comps[LEPP_COMP_QUEUE_SIZE]554__attribute__((aligned(CHIP_L2_LINE_SIZE())));555} lepp_queue_t;556557558/** An internal helper function for determining the number of entries559* available in a ring buffer, given that there is one sentinel.560*/561static inline unsigned int562_lepp_num_free_slots(unsigned int head, unsigned int tail)563{564/*565* One entry is reserved for use as a sentinel, to distinguish566* "empty" from "full". So we compute567* (head - tail - 1) % LEPP_QUEUE_SIZE, but without using a slow % operation.568*/569return (head - tail - 1) + ((head <= tail) ? LEPP_COMP_QUEUE_SIZE : 0);570}571572573/** Returns how many new comp entries can be enqueued. */574static inline unsigned int575lepp_num_free_comp_slots(const lepp_queue_t* q)576{577return _lepp_num_free_slots(q->comp_head, q->comp_tail);578}579580static inline int581lepp_qsub(int v1, int v2)582{583int delta = v1 - v2;584return delta + ((delta >> 31) & LEPP_COMP_QUEUE_SIZE);585}586587588/** FIXME: Check this from linux, via a new "pwrite()" call. */589#define LIPP_VERSION 1590591592/** We use exactly two bytes of alignment padding. */593#define LIPP_PACKET_PADDING 2594595/** The minimum size of a "small" buffer (including the padding). */596#define LIPP_SMALL_PACKET_SIZE 128597598/*599* NOTE: The following two values should total to less than around600* 13582, to keep the total size used for "lipp_state_t" below 64K.601*/602603/** The maximum number of "small" buffers.604* This is enough for 53 network cpus with 128 credits. Note that605* if these are exhausted, we will fall back to using large buffers.606*/607#define LIPP_SMALL_BUFFERS 6785608609/** The maximum number of "large" buffers.610* This is enough for 53 network cpus with 128 credits.611*/612#define LIPP_LARGE_BUFFERS 6785613614#endif /* __DRV_XGBE_INTF_H__ */615616617