Path: blob/master/arch/tile/include/hv/drv_xgbe_impl.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 drivers/xgbe/impl.h16* Implementation details for the NetIO library.17*/1819#ifndef __DRV_XGBE_IMPL_H__20#define __DRV_XGBE_IMPL_H__2122#include <hv/netio_errors.h>23#include <hv/netio_intf.h>24#include <hv/drv_xgbe_intf.h>252627/** How many groups we have (log2). */28#define LOG2_NUM_GROUPS (12)29/** How many groups we have. */30#define NUM_GROUPS (1 << LOG2_NUM_GROUPS)3132/** Number of output requests we'll buffer per tile. */33#define EPP_REQS_PER_TILE (32)3435/** Words used in an eDMA command without checksum acceleration. */36#define EDMA_WDS_NO_CSUM 837/** Words used in an eDMA command with checksum acceleration. */38#define EDMA_WDS_CSUM 1039/** Total available words in the eDMA command FIFO. */40#define EDMA_WDS_TOTAL 128414243/*44* FIXME: These definitions are internal and should have underscores!45* NOTE: The actual numeric values here are intentional and allow us to46* optimize the concept "if small ... else if large ... else ...", by47* checking for the low bit being set, and then for non-zero.48* These are used as array indices, so they must have the values (0, 1, 2)49* in some order.50*/51#define SIZE_SMALL (1) /**< Small packet queue. */52#define SIZE_LARGE (2) /**< Large packet queue. */53#define SIZE_JUMBO (0) /**< Jumbo packet queue. */5455/** The number of "SIZE_xxx" values. */56#define NETIO_NUM_SIZES 3575859/*60* Default numbers of packets for IPP drivers. These values are chosen61* such that CIPP1 will not overflow its L2 cache.62*/6364/** The default number of small packets. */65#define NETIO_DEFAULT_SMALL_PACKETS 275066/** The default number of large packets. */67#define NETIO_DEFAULT_LARGE_PACKETS 250068/** The default number of jumbo packets. */69#define NETIO_DEFAULT_JUMBO_PACKETS 250707172/** Log2 of the size of a memory arena. */73#define NETIO_ARENA_SHIFT 24 /* 16 MB */74/** Size of a memory arena. */75#define NETIO_ARENA_SIZE (1 << NETIO_ARENA_SHIFT)767778/** A queue of packets.79*80* This structure partially defines a queue of packets waiting to be81* processed. The queue as a whole is written to by an interrupt handler and82* read by non-interrupt code; this data structure is what's touched by the83* interrupt handler. The other part of the queue state, the read offset, is84* kept in user space, not in hypervisor space, so it is in a separate data85* structure.86*87* The read offset (__packet_receive_read in the user part of the queue88* structure) points to the next packet to be read. When the read offset is89* equal to the write offset, the queue is empty; therefore the queue must90* contain one more slot than the required maximum queue size.91*92* Here's an example of all 3 state variables and what they mean. All93* pointers move left to right.94*95* @code96* I I V V V V I I I I97* 0 1 2 3 4 5 6 7 8 9 1098* ^ ^ ^ ^99* | | |100* | | __last_packet_plus_one101* | __buffer_write102* __packet_receive_read103* @endcode104*105* This queue has 10 slots, and thus can hold 9 packets (_last_packet_plus_one106* = 10). The read pointer is at 2, and the write pointer is at 6; thus,107* there are valid, unread packets in slots 2, 3, 4, and 5. The remaining108* slots are invalid (do not contain a packet).109*/110typedef struct {111/** Byte offset of the next notify packet to be written: zero for the first112* packet on the queue, sizeof (netio_pkt_t) for the second packet on the113* queue, etc. */114volatile uint32_t __packet_write;115116/** Offset of the packet after the last valid packet (i.e., when any117* pointer is incremented to this value, it wraps back to zero). */118uint32_t __last_packet_plus_one;119}120__netio_packet_queue_t;121122123/** A queue of buffers.124*125* This structure partially defines a queue of empty buffers which have been126* obtained via requests to the IPP. (The elements of the queue are packet127* handles, which are transformed into a full netio_pkt_t when the buffer is128* retrieved.) The queue as a whole is written to by an interrupt handler and129* read by non-interrupt code; this data structure is what's touched by the130* interrupt handler. The other parts of the queue state, the read offset and131* requested write offset, are kept in user space, not in hypervisor space, so132* they are in a separate data structure.133*134* The read offset (__buffer_read in the user part of the queue structure)135* points to the next buffer to be read. When the read offset is equal to the136* write offset, the queue is empty; therefore the queue must contain one more137* slot than the required maximum queue size.138*139* The requested write offset (__buffer_requested_write in the user part of140* the queue structure) points to the slot which will hold the next buffer we141* request from the IPP, once we get around to sending such a request. When142* the requested write offset is equal to the write offset, no requests for143* new buffers are outstanding; when the requested write offset is one greater144* than the read offset, no more requests may be sent.145*146* Note that, unlike the packet_queue, the buffer_queue places incoming147* buffers at decreasing addresses. This makes the check for "is it time to148* wrap the buffer pointer" cheaper in the assembly code which receives new149* buffers, and means that the value which defines the queue size,150* __last_buffer, is different than in the packet queue. Also, the offset151* used in the packet_queue is already scaled by the size of a packet; here we152* use unscaled slot indices for the offsets. (These differences are153* historical, and in the future it's possible that the packet_queue will look154* more like this queue.)155*156* @code157* Here's an example of all 4 state variables and what they mean. Remember:158* all pointers move right to left.159*160* V V V I I R R V V V161* 0 1 2 3 4 5 6 7 8 9162* ^ ^ ^ ^163* | | | |164* | | | __last_buffer165* | | __buffer_write166* | __buffer_requested_write167* __buffer_read168* @endcode169*170* This queue has 10 slots, and thus can hold 9 buffers (_last_buffer = 9).171* The read pointer is at 2, and the write pointer is at 6; thus, there are172* valid, unread buffers in slots 2, 1, 0, 9, 8, and 7. The requested write173* pointer is at 4; thus, requests have been made to the IPP for buffers which174* will be placed in slots 6 and 5 when they arrive. Finally, the remaining175* slots are invalid (do not contain a buffer).176*/177typedef struct178{179/** Ordinal number of the next buffer to be written: 0 for the first slot in180* the queue, 1 for the second slot in the queue, etc. */181volatile uint32_t __buffer_write;182183/** Ordinal number of the last buffer (i.e., when any pointer is decremented184* below zero, it is reloaded with this value). */185uint32_t __last_buffer;186}187__netio_buffer_queue_t;188189190/**191* An object for providing Ethernet packets to a process.192*/193typedef struct __netio_queue_impl_t194{195/** The queue of packets waiting to be received. */196__netio_packet_queue_t __packet_receive_queue;197/** The intr bit mask that IDs this device. */198unsigned int __intr_id;199/** Offset to queues of empty buffers, one per size. */200uint32_t __buffer_queue[NETIO_NUM_SIZES];201/** The address of the first EPP tile, or -1 if no EPP. */202/* ISSUE: Actually this is always "0" or "~0". */203uint32_t __epp_location;204/** The queue ID that this queue represents. */205unsigned int __queue_id;206/** Number of acknowledgements received. */207volatile uint32_t __acks_received;208/** Last completion number received for packet_sendv. */209volatile uint32_t __last_completion_rcv;210/** Number of packets allowed to be outstanding. */211uint32_t __max_outstanding;212/** First VA available for packets. */213void* __va_0;214/** First VA in second range available for packets. */215void* __va_1;216/** Padding to align the "__packets" field to the size of a netio_pkt_t. */217uint32_t __padding[3];218/** The packets themselves. */219netio_pkt_t __packets[0];220}221netio_queue_impl_t;222223224/**225* An object for managing the user end of a NetIO queue.226*/227typedef struct __netio_queue_user_impl_t228{229/** The next incoming packet to be read. */230uint32_t __packet_receive_read;231/** The next empty buffers to be read, one index per size. */232uint8_t __buffer_read[NETIO_NUM_SIZES];233/** Where the empty buffer we next request from the IPP will go, one index234* per size. */235uint8_t __buffer_requested_write[NETIO_NUM_SIZES];236/** PCIe interface flag. */237uint8_t __pcie;238/** Number of packets left to be received before we send a credit update. */239uint32_t __receive_credit_remaining;240/** Value placed in __receive_credit_remaining when it reaches zero. */241uint32_t __receive_credit_interval;242/** First fast I/O routine index. */243uint32_t __fastio_index;244/** Number of acknowledgements expected. */245uint32_t __acks_outstanding;246/** Last completion number requested. */247uint32_t __last_completion_req;248/** File descriptor for driver. */249int __fd;250}251netio_queue_user_impl_t;252253254#define NETIO_GROUP_CHUNK_SIZE 64 /**< Max # groups in one IPP request */255#define NETIO_BUCKET_CHUNK_SIZE 64 /**< Max # buckets in one IPP request */256257258/** Internal structure used to convey packet send information to the259* hypervisor. FIXME: Actually, it's not used for that anymore, but260* netio_packet_send() still uses it internally.261*/262typedef struct263{264uint16_t flags; /**< Packet flags (__NETIO_SEND_FLG_xxx) */265uint16_t transfer_size; /**< Size of packet */266uint32_t va; /**< VA of start of packet */267__netio_pkt_handle_t handle; /**< Packet handle */268uint32_t csum0; /**< First checksum word */269uint32_t csum1; /**< Second checksum word */270}271__netio_send_cmd_t;272273274/** Flags used in two contexts:275* - As the "flags" member in the __netio_send_cmd_t, above; used only276* for netio_pkt_send_{prepare,commit}.277* - As part of the flags passed to the various send packet fast I/O calls.278*/279280/** Need acknowledgement on this packet. Note that some code in the281* normal send_pkt fast I/O handler assumes that this is equal to 1. */282#define __NETIO_SEND_FLG_ACK 0x1283284/** Do checksum on this packet. (Only used with the __netio_send_cmd_t;285* normal packet sends use a special fast I/O index to denote checksumming,286* and multi-segment sends test the checksum descriptor.) */287#define __NETIO_SEND_FLG_CSUM 0x2288289/** Get a completion on this packet. Only used with multi-segment sends. */290#define __NETIO_SEND_FLG_COMPLETION 0x4291292/** Position of the number-of-extra-segments value in the flags word.293Only used with multi-segment sends. */294#define __NETIO_SEND_FLG_XSEG_SHIFT 3295296/** Width of the number-of-extra-segments value in the flags word. */297#define __NETIO_SEND_FLG_XSEG_WIDTH 2298299#endif /* __DRV_XGBE_IMPL_H__ */300301302