1/* 2 * HND RTE packet buffer definitions. 3 * 4 * Copyright (C) 2014, Broadcom Corporation 5 * All Rights Reserved. 6 * 7 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation; 8 * the contents of this file may not be disclosed to third parties, copied 9 * or duplicated in any form, in whole or in part, without the prior 10 * written permission of Broadcom Corporation. 11 * 12 * $Id: bcm_lbuf.h,v 1.3 2010-02-23 17:43:13 $ 13 */ 14 15#ifndef _bcm_lbuf_h 16#define _bcm_lbuf_h 17 18#if defined(OSL_EXT) 19 20#include "typedefs.h" 21#include "bcmdefs.h" 22#include "osl.h" 23#include "pkt_lbuf.h" 24#include "lbuf.h" 25 26/* This should be a multiple of 4 to avoid mis-aligned memory accesses. */ 27#define TXOFF 172 28 29#else 30 31#include <bcmdefs.h> 32 33#define OSL_PKTTAG_SZ 32 34 35 36 37struct lbuf { 38 struct lbuf *next; /* next lbuf in a chain of lbufs forming one packet */ 39 struct lbuf *link; /* first lbuf of next packet in a list of packets */ 40 uchar *head; /* fixed start of buffer */ 41 uchar *end; /* fixed end of buffer */ 42 uchar *data; /* variable start of data */ 43 uint16 len; /* nbytes of data */ 44 uint16 flags; /* private flags; don't touch */ 45 uint16 dmapad; /* padding to be added for tx dma */ 46 uint32 pkttag[(OSL_PKTTAG_SZ + 3) / 4]; /* 4-byte-aligned packet tag area */ 47}; 48 49#define LBUFSZ sizeof(struct lbuf) 50 51/* Total maximum packet buffer size including lbuf header */ 52#define MAXPKTBUFSZ 1920 /* enough to fit a 1500 MTU plus overhead */ 53 54/* private flags - don't reference directly */ 55#define LBF_PRI 0x0007 /* priority (low 3 bits of flags) */ 56#define LBF_SUM_NEEDED 0x0008 57#define LBF_SUM_GOOD 0x0010 58 59#define LBF_MSGTRACE 0x0020 60#define LBP(lb) ((struct lbuf *)(lb)) 61 62/* prototypes */ 63extern void lb_init(void); 64#if defined(BCMDBG_MEMFAIL) 65extern struct lbuf *lb_alloc(uint size, char *file, int line); 66#else 67extern struct lbuf *lb_alloc(uint size); 68#endif 69 70extern struct lbuf *lb_dup(struct lbuf *lb); 71extern void lb_free(struct lbuf *lb); 72extern bool lb_sane(struct lbuf *lb); 73 74static INLINE uchar * 75lb_push(struct lbuf *lb, uint len) 76{ 77 ASSERT(lb_sane(lb)); 78 ASSERT((lb->data - len) >= lb->head); 79 lb->data -= len; 80 lb->len += len; 81 return (lb->data); 82} 83 84static INLINE uchar * 85lb_pull(struct lbuf *lb, uint len) 86{ 87 ASSERT(lb_sane(lb)); 88 ASSERT(len <= lb->len); 89 lb->data += len; 90 lb->len -= len; 91 return (lb->data); 92} 93 94static INLINE void 95lb_setlen(struct lbuf *lb, uint len) 96{ 97 ASSERT(lb_sane(lb)); 98 ASSERT(lb->data + len <= lb->end); 99 lb->len = len; 100} 101 102static INLINE uint 103lb_pri(struct lbuf *lb) 104{ 105 ASSERT(lb_sane(lb)); 106 return (lb->flags & LBF_PRI); 107} 108 109static INLINE void 110lb_setpri(struct lbuf *lb, uint pri) 111{ 112 ASSERT(lb_sane(lb)); 113 ASSERT((pri & LBF_PRI) == pri); 114 lb->flags = (lb->flags & ~LBF_PRI) | (pri & LBF_PRI); 115} 116 117static INLINE bool 118lb_sumneeded(struct lbuf *lb) 119{ 120 ASSERT(lb_sane(lb)); 121 return ((lb->flags & LBF_SUM_NEEDED) != 0); 122} 123 124static INLINE void 125lb_setsumneeded(struct lbuf *lb, bool summed) 126{ 127 ASSERT(lb_sane(lb)); 128 if (summed) 129 lb->flags |= LBF_SUM_NEEDED; 130 else 131 lb->flags &= ~LBF_SUM_NEEDED; 132} 133 134static INLINE bool 135lb_sumgood(struct lbuf *lb) 136{ 137 ASSERT(lb_sane(lb)); 138 return ((lb->flags & LBF_SUM_GOOD) != 0); 139} 140 141static INLINE void 142lb_setsumgood(struct lbuf *lb, bool summed) 143{ 144 ASSERT(lb_sane(lb)); 145 if (summed) 146 lb->flags |= LBF_SUM_GOOD; 147 else 148 lb->flags &= ~LBF_SUM_GOOD; 149} 150 151static INLINE bool 152lb_msgtrace(struct lbuf *lb) 153{ 154 ASSERT(lb_sane(lb)); 155 return ((lb->flags & LBF_MSGTRACE) != 0); 156} 157 158static INLINE void 159lb_setmsgtrace(struct lbuf *lb, bool set) 160{ 161 ASSERT(lb_sane(lb)); 162 if (set) 163 lb->flags |= LBF_MSGTRACE; 164 else 165 lb->flags &= ~LBF_MSGTRACE; 166} 167 168 169/* Common to all ports */ 170/* dummy decl */ 171struct osl_info { 172 uint pad; 173}; 174typedef struct osl_info osl_t; 175 176 177 178/* Absolutely minimalist pktbuffer utilities */ 179#define TXOFF 170 180 181#if !defined(BCM_OSL) 182/* packet primitives */ 183#define PKTGET(osh, len, send) (void *)osl_pktget((osh),(len)) 184#define PKTFREE(osh, lb, send) osl_pktfree((osh), (lb), (send)) 185#define PKTDATA(osh, lb) LBP(lb)->data 186#define PKTLEN(osh, lb) LBP(lb)->len 187#define PKTSETLEN(osh, lb, len) lb_setlen(LBP(lb), (len)) 188#define PKTPUSH(osh, lb, bytes) lb_push(LBP(lb), (bytes)) 189#define PKTPULL(osh, lb, bytes) lb_pull(LBP(lb), (bytes)) 190#define PKTTAG(lb) ((void *)((LBP(lb))->pkttag)) 191#endif /* !BCM_OSL */ 192 193 194extern void *osl_pktget(osl_t *osh, uint size); 195extern void osl_pktfree(osl_t *osh, void *lb, bool send); 196extern int osl_init(void); 197 198#endif /* defined(OSL_EXT) */ 199#endif /* _bcm_lbuf_h */ 200