BE NIC driver - beclib (h/w access lib) header files
Subsystems (2)
PATCH 4/12 BE NIC driver - beclib (h/w access lib) header files
Signed-off-by Subbu Seetharaman <[email protected]>
--- drivers/message/beclib/beclib_common.h | 667 ++++++++++++++++ drivers/message/beclib/beclib_ll_bmap_nic.h | 1111 +++++++++++++++++++++++++++ drivers/message/beclib/beclib_ll_enum_nic.h | 48 ++ 3 files changed, 1826 insertions(+), 0 deletions(-) create mode 100644 drivers/message/beclib/beclib_common.h create mode 100644 drivers/message/beclib/beclib_ll_bmap_nic.h create mode 100644 drivers/message/beclib/beclib_ll_enum_nic.h
drivers/message/beclib/beclib_common.h new file +667 -0
@@ -0,0 +1,667 @@ +/* +* Copyright (C) 2005 - 2008 ServerEngines +* All rights reserved. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License version 2 +* as published by the Free Software Foundation. The full GNU General +* Public License is included in this distribution in the file called COPYING. +* +* Contact Information: +* [email protected] +* +* ServerEngines +* 209 N. Fair Oaks Ave +* Sunnyvale, CA 94085 +*/ +#ifndef __beclib_common_h__ +#define __beclib_common_h__ + +#include <linux/io.h> +#include <linux/list.h> +#include <linux/spinlock.h> + +/*----- Platform specific defines for Linux -------*/ + +#define TRUE (1) +#define FALSE (0) + +#if !defined(SG_PACK ) +#define SG_PACK __attribute__ ((packed)) +#endif +/* +*--------- Assert related -------- +* a way to force compilation error +*/ + +#define SA_C_ASSERT (_expression_) { \ + struct __COMPILE_TIME_ASSERT__ { \ + u8 __COMPILE_TIME_ASSERT__[(_expression_)?1: -1]; \ + }; \ +} + +#define SA_COMPILETIME_NAMED_TYPEDEF_ASSERT (_name_, _expression_) \ + struct _name_##_COMPILE_TIME_ASSERT_ { \ + u8 _name##_COMPILE_TIME_ASSERT_[(_expression_)?1: -1]; \ + }; + + +#define SA_GLOBAL_C_ASSERT SA_COMPILETIME_NAMED_TYPEDEF_ASSERT + +#define SA_ASSERT ASSERT +#ifdef SA_DEBUG + +#define ASSERT (c) if (!(c)) \ + BUG(); + +#define SA_DBG_CSTR (_str_) (_str_) + +#else + +#define ASSERT (c) +#define SA_DBG_CSTR (_str_) "" + +#endif + +/*--------- Trace log related --------*/ + +/* debug levels */ +enum SA_DEBUG_LEVELS { +DL_ALWAYS =0 ,/* cannot be masked */ + +DL_ERR =0x1 ,/* errors that should never happen */ +DL_WARN =0x2 ,/* something is questionable. +recoverable errors */ +DL_NOTE =0x4 ,/* infrequent, important debug info */ +DL_INFO =0x8 ,/* debug information */ + +DL_VERBOSE =0x10 ,/* detailed information, such as +buffer traces */ +DL_ENTRY =0x20 ,/* function entry */ +DL_EXIT =0x40 ,/* function exit */ +DL_RSVD1 =0x80 , + +SA_DL_MIN_VALUE =0x1 ,/* this is the min value used */ +SA_DL_MAX_VALUE =0x80 /* this is the higheset value used */ +} ; + +/* Bit mask describing events of interest to be traced */ +extern unsigned int trace_level; + +#define SA_TRACE(lm, fmt, args...) { \ + if (trace_level & lm) { \ + printk(KERN_NOTICE "BE: %s:%d \n" fmt, \ + __FILE__ , __LINE__ , ## args); \ + } \ + } + +#define TRACE SA_TRACE + +static inline unsigned int sa_trace_set_level (unsigned int l) +{ +unsigned int old_level = trace_level; + trace_level = l; +return (old_level); +} + +#define sa_trace_get_level () trace_level +#define sa_trace_set_debug_level_string (lm, s)/* nothing */ + +/*----- power of 2 functions -----*/ +static inline u32 sa_required_bits (u32 x) +{ +u32 hi =31 , lo =0 ; +u32 guess =16 ; + +if (x ==0 ) +return 0 ; +if (x &0x80000000 ) +return 32 ; + +/* Binary search */ +while (hi > lo) { +if ((x >> guess) >0 ) { +/* x is more than i bits in length */ + lo = guess; + guess = (hi + guess +1 ) >>1 ; + }else { + hi = guess -1 ; + guess = (lo + guess) >>1 ; + } + } + +return hi +1 ; +} + +/* +* Returns the log base 2 for a number, always rounding down. +* sa_log2 example input->output +* 0->4294967295, 1->0, 2->1, 3->1, 4->2, 5->2, 6->2, 7->2, 8->3, 9->3 +*/ +static inline u32 sa_log2 (u32 x) +{ +return sa_required_bits (x) -1 ; +} + +/* +* "greater than power of 2" +* Returns the next higher power of 2 -- even if input is a power of 2. +* input->output +* 0->1, 1->2, 2->4, 3->4, 4->8, 5->8, 6->8, 7->8, 8->16, 9->16 +*/ +static inline u32 sa_gt_power2 (u32 x) +{ + x =sa_required_bits (x); + +if (x >=32 ) +/* error -- cannot represent this number in 32 bits */ +return (u32 )0xFFFFFFFF ; + +return (1 << x); +} + +/* +* Status code datatype +*/ +typedef int SA_STATUS , *PSA_STATUS ; + +/* Error codes */ +#define SA_SUCCESS (0x00000000L) + +/*-------- Basic defines -------*/ + +/* +* Returns number of pages spanned by the size of data +* starting at the given address. +*/ +#define SA_PAGES_SPANNED (_address, _size) \ + ((u32)(((SA_PTR_TO_INT(_address) & (PAGE_SIZE - 1)) + \ + (_size) + (PAGE_SIZE - 1)) >> PAGE_SHIFT)) +/* +* Appropriate casts to avoid compiler warnings about casting between +* integers and pointers. +*/ +#define SA_PTR_TO_INT (_p_) ((size_t)(_p_)) +#define SA_PTR_TO_U32 (_p_) ((u32)SA_PTR_TO_INT(_p_)) +#define SA_PTR_TO_U64 (_p_) ((u64)SA_PTR_TO_INT(_p_)) + +#define SA_PTR_TO_INT (_p_) ((size_t)(_p_)) +#define SA_U64_TO_PTR (_u_) ((void *)(size_t)(_u_)) +#define SA_U32_TO_PTR (_u_) ((void *)(size_t)(_u_)) +#define SA_PAGE_OFFSET (_addr_) (SA_PTR_TO_INT(_addr_) & (PAGE_SIZE-1)) + +/* Conversion from 64 bit values to hi and lo 32-bit values. */ +static inline u32 sa_hi (u64 quad) +{ +return (u32) (quad >>32 ); +} +static inline u32 sa_lo (u64 quad) +{ +return (u32) (quad); +} + +static inline u64 sa_make_u64 (u32 hi,u32 lo) +{ +return (((u64 ) hi) <<32 ) | lo; +} + +static inline u32 sa_pvoid_hi (void *p) +{ +return sa_hi (SA_PTR_TO_U64 (p)); +} + +static inline u32 sa_pvoid_lo (void *p) +{ +return sa_lo (SA_PTR_TO_U64 (p)); +} + +static inline void *sa_make_pvoid (u32 hi,u32 lo) +{ +return SA_U64_TO_PTR (sa_make_u64 (hi, lo)); +} + +/* Returns byte offset of field within given struct type. */ +#define SA_FIELD_OFFSET (_type_, _field_) \ + (SA_PTR_TO_U32((u8 *)&(((struct _type_ *)0)->_field_))) + +/* Returns byte size of given field with a structure. */ +#define SA_SIZEOF_FIELD (_type_, _field_) \ + sizeof(((struct _type_ *)0)->_field_) + +/* Returns the number of items in the field array. */ +#define SA_NUMBER_OF_FIELD (_type_, _field_) \ + (SA_SIZEOF_FIELD(_type_, _field_) / \ + sizeof((((struct _type_ *)0)->_field_[0]))) + +/* Returns x/y plus 1 if there is a remainder. */ +static inline u32 sa_ceiling (u32 x,u32 y) +{ +ASSERT (y >0 ); +return (x + y -1 ) / y; +} + +/* +* circular subtract. +* Returns a - b assuming a circular number system, where a and b are +* in range (0, maxValue-1). If a==b, zero is returned so the +* highest value possible with this subtraction is maxValue-1. +*/ +static inline u32 sa_subc (u32 a,u32 b,u32 max) +{ +ASSERT (a <= max && b <= max); +ASSERT (max >0 ); +return (a >= b ? (a - b) : (max - b + a)); +} + +static inline u32 sa_addc (u32 a,u32 b,u32 max) +{ +ASSERT (a < max); +ASSERT (max >0 ); +return ((max - a > b) ? (a + b) : (b + a - max)); +} + +/*------- SGL related ------*/ + +/* descriptor for a physically contiguous memory region */ +struct sa_sgl { +u32 length; +void *va; +u64 pa; +} ; + +static inline u32 sa_sgl_get_byte_count (struct sa_sgl *sgl) +{ +return sgl->length; +} + +static inline u32 sa_sgl_get_page_count (struct sa_sgl *sgl) +{ +return SA_PAGES_SPANNED (sgl->va, sgl->length); +} + +static inline void *sa_sgl_get_base_va (struct sa_sgl *sgl) +{ +return sgl->va; +} + +static inline u32 sa_sgl_get_offset (struct sa_sgl *sgl) +{ +return SA_PAGE_OFFSET (sgl->va); +} + +/* +* Creates a SGL for a physically contiguous chunk of memory. +* The sgl struct must be previously allocated. +*/ +static inline SA_STATUS +sa_sgl_create_contiguous (void *va,u64 pa,u32 length,struct sa_sgl *sgl) +{ + + sgl->va = va; + sgl->pa = pa; + sgl->length = length; +return (SA_SUCCESS ); +} + +/* +*------- ring manipulation related ------ +* This structure stores information about a ring shared between hardware +* and software. Each ring is allocated by the driver in the uncached +* extension and mapped into BladeEngine's unified table. BEKLIB manages +* creation and destruction of the rings in hardware. It returns the +* corresponding HANDLE to the ring. +*/ +struct sa_ring { +u32 pages;/* queue size in pages */ +u32 id;/* queue id assigned by beklib */ +u32 num;/* number of elements in queue */ +u32 cidx;/* consumer index */ +u32 pidx;/* producer index -- not used by most rings */ +u32 itemSize;/* size in bytes of one object */ + +void *va;/* The virtual address of the ring. +This should be last to allow 32 & 64 +bit debugger extensions to work. */ + +} ; + +static +inline void sa_ring_create (struct sa_ring *ring, +u32 num,u32 itemSize,void *va) +{ +ASSERT (ring); +memset (ring,0 ,sizeof (struct sa_ring )); + ring->num = num; + ring->pages =sa_ceiling (num * itemSize,PAGE_SIZE ); + ring->itemSize = itemSize; + ring->va = va; +} + +static inline void sa_ring_set_id (struct sa_ring *ring,u32 id) +{ +ASSERT (ring); + ring->id = id; +} + +static inline u32 sa_ring_num (struct sa_ring *ring) +{ +ASSERT (ring); +return ring->num; +} + +static inline void *sa_ring_va (struct sa_ring *ring) +{ +ASSERT (ring); +return ring->va; +} + +static inline void sa_ring_clear (struct sa_ring *ring) +{ +ASSERT (ring); + ring->pidx = ring->cidx =0 ; +} + +/* +* ----------------------------------------------------------------------- +* Interface for 2 index rings. i.e. consumer/producer rings +* -------------------------------------------------------------------------- +*/ + +/* Returns TRUE if ring is empty */ +static inline bool sa_ring_is_empty (struct sa_ring *ring) +{ +ASSERT (ring); +return (ring->pidx == ring->cidx); +} + +/* Define the power2 version equivalent */ +#define sa_ring_power2_is_empty sa_ring_is_empty + +/* Returns number items pending on ring. */ +static inline u32 sa_ring_num_pending (struct sa_ring *ring) +{ +ASSERT (ring); +if (ring->num ==0 ) +return 0 ; +return sa_subc (ring->pidx, ring->cidx, ring->num); +} + +/* Returns number items free on ring. */ +static inline u32 sa_ring_num_empty (struct sa_ring *ring) +{ +ASSERT (ring); +return ring->num -1 -sa_ring_num_pending (ring); +} + +/* Returns TRUE if ring is full */ +static inline bool sa_ring_is_full (struct sa_ring *ring) +{ +ASSERT (ring); +return sa_ring_num_pending (ring) == (ring->num -1 ); +} + +/* Consume 1 item */ +static inline void sa_ring_consume (struct sa_ring *ring) +{ +ASSERT (ring); +ASSERT (!sa_ring_is_empty (ring)); + ring->cidx =sa_addc (ring->cidx,1 , ring->num); +} + +/* Produce 1 item */ +static inline void sa_ring_produce (struct sa_ring *ring) +{ +ASSERT (ring); +ASSERT (!sa_ring_is_full (ring)); + ring->pidx =sa_addc (ring->pidx,1 , ring->num); +} + +/* Consume count items */ +static inline void sa_ring_consume_multiple (struct sa_ring *ring,u32 count) +{ +ASSERT (ring); +ASSERT (sa_ring_num_pending (ring) >= count); + ring->cidx =sa_addc (ring->cidx, count, ring->num); +} + +static inline void *sa_ring_item (struct sa_ring *ring,u32 index) +{ +ASSERT (ring); +ASSERT (index < ring->num); +ASSERT (ring->itemSize >0 ); +return (u8 *) ring->va + index * ring->itemSize; +} + +#define sa_ring_power2_item sa_ring_item + +/* Ptr to produce item */ +static inline void *sa_ring_producer_ptr (struct sa_ring *ring) +{ +ASSERT (ring); +ASSERT (!sa_ring_is_full (ring)); +return sa_ring_item (ring, ring->pidx); +} + +#define sa_ring_power2_producer_ptr sa_ring_producer_ptr + +/* +* Returns a pointer to the current location in the ring. +* This is used for rings with 1 index. +*/ +static inline void *sa_ring_current (struct sa_ring *ring) +{ +ASSERT (ring); +ASSERT (ring->pidx ==0 );/* not used */ + +return sa_ring_item (ring, ring->cidx); +} + +/* Ptr to consume item */ +static inline void *sa_ring_consumer_ptr (struct sa_ring *ring) +{ +ASSERT (ring); +ASSERT (!sa_ring_is_empty (ring)); +return sa_ring_item (ring, ring->cidx); +} + +#define sa_ring_power2_current sa_ring_current + +/* +* Increment index for rings with only 1 index. +* This is used for rings with 1 index. +*/ +static inline void *sa_ring_next (struct sa_ring *ring) +{ +ASSERT (ring); +ASSERT (ring->num >0 ); +ASSERT (ring->pidx ==0 );/* not used */ + + ring->cidx =sa_addc (ring->cidx,1 , ring->num); +return sa_ring_current (ring); +} + +/*----------- amap bit filed get / set macros and functions -----*/ +/* +* Structures defined in the map header files (under fw/amap/) with names +* in the format BE_<name>_AMAP are pseudo structures with members +* of type BE_BIT. These structures are templates that are used in +* conjuntion with the structures with names in the format +* <name>_AMAP to calculate the bit masks and bit offsets to get or set +* bit fields in structures. The structures <name>_AMAP are arrays +* of 32 bits words and have the correct size. The following macros +* provide convenient ways to get and set the various members +* in the structures without using strucctures with bit fields. +* Always use the macros AMAP_GET_BITS_PTR and AMAP_SET_BITS_PTR +* macros to extract and set various members. +*/ +/* Each bit is 1 byte in array maps. */ +typedef u8 AMAP_BIT ,BE_BIT ; + +/* +* Returns the a bit mask for the register that is NOT shifted into location. +* That means return values always look like: 0x1, 0xFF, 0x7FF, etc... +*/ +static inline u32 amap_mask (u32 bit_size) +{ +return (bit_size ==32 ?0xFFFFFFFF : (1 << bit_size) -1 ); +} + +#define AMAP_BIT_MASK_UNION (_struct_, _register_) \ + amap_mask(AMAP_BIT_SIZE_UNION(_struct_, _register_)) \ + +#define AMAP_BIT_MASK (_struct_, _register_) \ + amap_mask(AMAP_BIT_SIZE(_struct_, _register_)) \ + +/* +* non-optimized set bits function. First clears the bits and then assigns them. +* This does not require knowledge of the particular DWORD you are setting. +* e.g. AMAP_SET_BITS_PTR (struct, field1, &contextMemory, 123); +*/ +static inline void +amap_set (void *ptr,u32 dw_offset,u32 mask,u32 offset,u32 value) +{ +u32 *dw = (u32 *)ptr; + *(dw + dw_offset) &= ~(mask << offset); + *(dw + dw_offset) |= (mask & value) << offset; +} + +#define AMAP_SET_BITS_PTR_UNION (_struct_, _register_, _structPtr_, _value_) \ + amap_set(_structPtr_, AMAP_WORD_OFFSET_UNION(_struct_, _register_), \ + AMAP_BIT_MASK_UNION(_struct_, _register_), \ + AMAP_BIT_OFFSET_UNION(_struct_, _register_), _value_) \ + +#define AMAP_SET_BITS_PTR (_struct_, _register_, _structPtr_, _value_) \ + amap_set(_structPtr_, AMAP_WORD_OFFSET(_struct_, _register_), \ + AMAP_BIT_MASK(_struct_, _register_), \ + AMAP_BIT_OFFSET(_struct_, _register_), _value_) \ + +/* +* Non-optimized routine that gets the bits without knowing the correct DWORD. +* e.g. fieldValue = AMAP_GET_BITS_PTR (struct, field1, &contextMemory); +*/ +static inline u32 +amap_get (void *ptr,u32 dw_offset,u32 mask,u32 offset) +{ +u32 *dw = (u32 *)ptr; +return mask & (*(dw + dw_offset) >> offset); +} +#define AMAP_GET_BITS_PTR (_struct_, _register_, _structPtr_) \ + amap_get(_structPtr_, AMAP_WORD_OFFSET(_struct_, _register_), \ + AMAP_BIT_MASK(_struct_, _register_), \ + AMAP_BIT_OFFSET(_struct_, _register_)) \ + +/* Returns 0-31 representing bit offset within a DWORD of a bitfield */ +#define AMAP_BIT_OFFSET_UNION (_struct_, _register_) \ + (((size_t)&(((union BE_ ## _struct_ ## _AMAP*)0)->_register_))%32) + +/* Returns 0-31 representing bit offset within a DWORD of a bitfield. */ +#define AMAP_BIT_OFFSET (_struct_, _register_) \ + (((size_t)&(((struct BE_ ## _struct_ ## _AMAP*)0)->_register_))%32) + +/* Returns 0-n representing byte offset of bitfield with the structure */ +#define AMAP_BYTE_OFFSET_UNION (_struct_, _register_) \ + (((size_t)&(((union BE_ ## _struct_ ## _AMAP *)0)->_register_))/8) + +/* Returns 0-n representing byte offset of bitfield with the structure. */ +#define AMAP_BYTE_OFFSET (_struct_, _register_) \ + (((size_t)&(((struct BE_ ## _struct_ ## _AMAP *)0)->_register_))/8) + +/* Returns 0-n representing DWORD offset of bitfield within the structure. */ +#define AMAP_WORD_OFFSET_UNION (_struct_, _register_) \ + (AMAP_BYTE_OFFSET_UNION(_struct_, _register_)/4) + +/* Returns 0-n representing DWORD offset of bitfield within the structure. */ +#define AMAP_WORD_OFFSET (_struct_, _register_) \ + (AMAP_BYTE_OFFSET(_struct_, _register_)/4) + +/* +* Gets a pointer to a field within a structure +* The field must be byte aligned. +*/ +#define AMAP_GET_PTR (_struct_, _register_, _structPtr_) \ + (void *) ((u8 *)(_structPtr_) + AMAP_BYTE_OFFSET(_struct_, _register_)) + +/* Returns size of bitfield in bits. */ +#define AMAP_BIT_SIZE_UNION (_struct_, _register_) \ + sizeof(((union BE_ ## _struct_ ## _AMAP*)0)->_register_) + +/* Returns size of bitfield in bits. */ +#define AMAP_BIT_SIZE (_struct_, _register_) \ + sizeof(((struct BE_ ## _struct_ ## _AMAP*)0)->_register_) + +/* Returns size of bitfield in bytes. */ +#define AMAP_BYTE_SIZE (_struct_) (sizeof(struct BE_ ## _struct_ ## _AMAP)/8) + +/* Returns size of bitfield in DWORDS. */ +#define AMAP_WORD_SIZE (_struct_) (AMAP_BYTE_SIZE(_struct_)/4) + +static +inline u64 sa_bit_range64 (u64 value,u32 bit_offset,u32 num_bits) +{ +ASSERT (bit_offset <=sizeof (value) *8 ); +ASSERT (num_bits <=sizeof (value) *8 ); +return (value >> bit_offset) & ((1ULL << num_bits) -1 ); +} + +static inline u64 sa_upper_bits64 (u64 value,u32 num_bits) +{ +ASSERT (num_bits <=sizeof (value) *8 ); +return sa_bit_range64 (value,sizeof (value) *8 - num_bits, num_bits); +} + + +#if !defined(BE_CONFIG ) +#define BE_CONFIG 0 +#define CONFIG0 +#endif + +/*Id ranges and RID conversions based on config */ +#include "be_gen_id_ranges.h" + +/* Srcgen includes */ + +#include "regmap.h" /* srcgen array map output */ +#include "be_common_bmap.h" /* srcgen array map output */ +#include "fwcmd_top.h" /* srcgen array map output */ + +#include "fwcmd_top_bmap.h" /* srcgen bitmap output */ + +#include "bestatus.h" + +/* Debug trace categories. */ +enum BE_DEBUG_LEVELS { +DL_HW =0x00000100 , +DL_FWCMD =0x00000200 , + +BE_DL_MIN_VALUE =0x100 ,/* this is the min value used */ +BE_DL_MAX_VALUE =0x800 /* this is the higheset value used */ +} ; + +SA_GLOBAL_C_ASSERT (beclib_debug_level_range, + ((u32 )BE_DL_MIN_VALUE > (u32 )SA_DL_MAX_VALUE )); + +#include "beregister.h" /* Macros for register access using srcgen structs */ +#include "beclib_stats.h" + +/* BECLIB status data type maps to the SA_STATUS */ +typedef SA_STATUS BESTATUS ; + +/* Forward declarations. */ +struct be_function_object ; +struct be_eq_object ; +struct be_cq_object ; + +/* Callback types. Deprecate most of these. */ +typedef void (*MCC_WRB_CQE_CALLBACK ) (void *context, +BESTATUS status, +struct MCC_WRB_AMAP *optional_wrb); +typedef void (*MCC_ASYNC_EVENT_CALLBACK ) (void *context, +u32 event_code, +void *event); + +typedef BESTATUS (*EQ_CALLBACK ) (struct be_function_object *, +struct be_eq_object *,void *context); +typedef BESTATUS (*CQ_CALLBACK ) (struct be_function_object *, +struct be_cq_object *,void *context); + +#endif /* __beclib_common_h__ */
drivers/message/beclib/beclib_ll_bmap_nic.h new file +1111 -0
1,111 lines not on this page · raw message
drivers/message/beclib/beclib_ll_enum_nic.h new file +48 -0
48 lines not on this page · raw message
Signature · 8 lines
1.5.5 ___________________________________________________________________________________ This message, together with any attachment(s), contains confidential and proprietary information of ServerEngines Corporation and is intended only for the designated recipient(s) named above. Any unauthorized review, printing, retention, copying, disclosure or distribution is strictly prohibited. If you are not the intended recipient of this message, please immediately advise the sender by reply email message and delete all copies of this message and any attachment(s). Thank you.