if_hatmvar.h revision 118598
1116491Sharti/* 2116491Sharti * Copyright (c) 2001-2003 3116491Sharti * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4116491Sharti * All rights reserved. 5116491Sharti * 6116491Sharti * Redistribution and use in source and binary forms, with or without 7116491Sharti * modification, are permitted provided that the following conditions 8116491Sharti * are met: 9116491Sharti * 1. Redistributions of source code must retain the above copyright 10116491Sharti * notice, this list of conditions and the following disclaimer. 11116491Sharti * 2. Redistributions in binary form must reproduce the above copyright 12116491Sharti * notice, this list of conditions and the following disclaimer in the 13116491Sharti * documentation and/or other materials provided with the distribution. 14116491Sharti * 15116491Sharti * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16116491Sharti * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17116491Sharti * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18116491Sharti * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19116491Sharti * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20116491Sharti * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21116491Sharti * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22116491Sharti * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23116491Sharti * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24116491Sharti * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25116491Sharti * SUCH DAMAGE. 26116491Sharti * 27116491Sharti * Author: Hartmut Brandt <harti@freebsd.org> 28116491Sharti * 29116491Sharti * $FreeBSD: head/sys/dev/hatm/if_hatmvar.h 118598 2003-08-07 13:42:31Z harti $ 30116491Sharti * 31116491Sharti * Fore HE driver for NATM 32116491Sharti */ 33116491Sharti 34116491Sharti/* 35116491Sharti * Debug statistics of the HE driver 36116491Sharti */ 37116491Shartistruct istats { 38116491Sharti uint32_t tdprq_full; 39116491Sharti uint32_t hbuf_error; 40116491Sharti uint32_t crc_error; 41116491Sharti uint32_t len_error; 42116491Sharti uint32_t flow_closed; 43116491Sharti uint32_t flow_drop; 44116491Sharti uint32_t tpd_no_mem; 45116491Sharti uint32_t rx_seg; 46116491Sharti uint32_t empty_hbuf; 47116491Sharti uint32_t short_aal5; 48116491Sharti uint32_t badlen_aal5; 49116491Sharti uint32_t bug_bad_isw; 50116491Sharti uint32_t bug_no_irq_upd; 51116491Sharti uint32_t itype_tbrq; 52116491Sharti uint32_t itype_tpd; 53116491Sharti uint32_t itype_rbps; 54116491Sharti uint32_t itype_rbpl; 55116491Sharti uint32_t itype_rbrq; 56116491Sharti uint32_t itype_rbrqt; 57116491Sharti uint32_t itype_unknown; 58116491Sharti uint32_t itype_phys; 59116491Sharti uint32_t itype_err; 60116491Sharti uint32_t defrag; 61118169Sharti uint32_t mcc; 62118169Sharti uint32_t oec; 63118169Sharti uint32_t dcc; 64118169Sharti uint32_t cec; 65116491Sharti}; 66116491Sharti 67116491Sharti/* Card memory layout parameters */ 68116491Sharti#define HE_CONFIG_MEM_LAYOUT { \ 69116491Sharti { /* 155 */ \ 70116491Sharti 20, /* cells_per_row */ \ 71116491Sharti 1024, /* bytes_per_row */ \ 72116491Sharti 512, /* r0_numrows */ \ 73116491Sharti 1018, /* tx_numrows */ \ 74116491Sharti 512, /* r1_numrows */ \ 75116491Sharti 6, /* r0_startrow */ \ 76116491Sharti 2 /* cells_per_lbuf */ \ 77116491Sharti }, { /* 622 */ \ 78116491Sharti 40, /* cells_per_row */ \ 79116491Sharti 2048, /* bytes_per_row */ \ 80116491Sharti 256, /* r0_numrows */ \ 81116491Sharti 512, /* tx_numrows */ \ 82116491Sharti 256, /* r1_numrows */ \ 83116491Sharti 0, /* r0_startrow */ \ 84116491Sharti 4 /* cells_per_lbuf */ \ 85116491Sharti } \ 86116491Sharti} 87116491Sharti 88116491Sharti/*********************************************************************/ 89116491Shartistruct hatm_softc; 90116491Sharti 91116491Sharti/* 92116491Sharti * A chunk of DMA-able memory 93116491Sharti */ 94116491Shartistruct dmamem { 95116491Sharti u_int size; /* in bytes */ 96116491Sharti u_int align; /* alignement */ 97116491Sharti bus_dma_tag_t tag; /* DMA tag */ 98116491Sharti void *base; /* the memory */ 99116491Sharti bus_addr_t paddr; /* physical address */ 100116491Sharti bus_dmamap_t map; /* the MAP */ 101116491Sharti}; 102116491Sharti 103116491Sharti/* 104116491Sharti * RBP (Receive Buffer Pool) queue entry and queue. 105116491Sharti */ 106116491Shartistruct herbp { 107116491Sharti u_int size; /* RBP number of entries (power of two) */ 108116491Sharti u_int thresh; /* interrupt treshold */ 109116491Sharti uint32_t bsize; /* buffer size in bytes */ 110116491Sharti u_int offset; /* free space at start for small bufs */ 111116491Sharti uint32_t mask; /* mask for index */ 112116491Sharti struct dmamem mem; /* the queue area */ 113116491Sharti struct he_rbpen *rbp; 114116491Sharti uint32_t head, tail; /* head and tail */ 115116491Sharti}; 116116491Sharti 117116491Sharti/* 118116491Sharti * RBRQ (Receive Buffer Return Queue) entry and queue. 119116491Sharti */ 120116491Shartistruct herbrq { 121116491Sharti u_int size; /* number of entries */ 122116491Sharti u_int thresh; /* interrupt threshold */ 123116491Sharti u_int tout; /* timeout value */ 124116491Sharti u_int pcnt; /* packet count threshold */ 125116491Sharti struct dmamem mem; /* memory */ 126116491Sharti struct he_rbrqen *rbrq; 127116491Sharti uint32_t head; /* driver end */ 128116491Sharti}; 129116491Sharti 130116491Sharti/* 131116491Sharti * TPDRQ (Transmit Packet Descriptor Ready Queue) entry and queue 132116491Sharti */ 133116491Shartistruct hetpdrq { 134116491Sharti u_int size; /* number of entries */ 135116491Sharti struct dmamem mem; /* memory */ 136116491Sharti struct he_tpdrqen *tpdrq; 137116491Sharti u_int head; /* head (copy of adapter) */ 138116491Sharti u_int tail; /* written back to adapter */ 139116491Sharti}; 140116491Sharti 141116491Sharti/* 142116491Sharti * TBRQ (Transmit Buffer Return Queue) entry and queue 143116491Sharti */ 144116491Shartistruct hetbrq { 145116491Sharti u_int size; /* number of entries */ 146116491Sharti u_int thresh; /* interrupt threshold */ 147116491Sharti struct dmamem mem; /* memory */ 148116491Sharti struct he_tbrqen *tbrq; 149116491Sharti u_int head; /* adapter end */ 150116491Sharti}; 151116491Sharti 152116491Sharti/*==================================================================*/ 153116491Sharti 154116491Sharti/* 155116491Sharti * TPDs are 32 byte and must be aligned on 64 byte boundaries. That means, 156116491Sharti * that half of the space is free. We use this space to plug in a link for 157116491Sharti * the list of free TPDs. Note, that the m_act member of the mbufs contain 158116491Sharti * a pointer to the dmamap. 159116491Sharti * 160116491Sharti * The maximum number of TDPs is the size of the common transmit packet 161116491Sharti * descriptor ready queue plus the sizes of the transmit buffer return queues 162116491Sharti * (currently only queue 0). We allocate and map these TPD when initializing 163116491Sharti * the card. We also allocate on DMA map for each TPD. Only the map in the 164116491Sharti * last TPD of a packets is used when a packet is transmitted. 165116491Sharti * This is signalled by having the mbuf member of this TPD non-zero and 166116491Sharti * pointing to the mbuf. 167116491Sharti */ 168116491Sharti#define HE_TPD_SIZE 64 169116491Shartistruct tpd { 170116491Sharti struct he_tpd tpd; /* at beginning */ 171116491Sharti SLIST_ENTRY(tpd) link; /* free cid list link */ 172116491Sharti struct mbuf *mbuf; /* the buf chain */ 173116491Sharti bus_dmamap_t map; /* map */ 174116491Sharti uint32_t cid; /* CID */ 175116491Sharti uint16_t no; /* number of this tpd */ 176116491Sharti}; 177116491ShartiSLIST_HEAD(tpd_list, tpd); 178116491Sharti 179116491Sharti#define TPD_SET_USED(SC, I) do { \ 180116491Sharti (SC)->tpd_used[(I) / 8] |= (1 << ((I) % 8)); \ 181116491Sharti } while (0) 182116491Sharti 183116491Sharti#define TPD_CLR_USED(SC, I) do { \ 184116491Sharti (SC)->tpd_used[(I) / 8] &= ~(1 << ((I) % 8)); \ 185116491Sharti } while (0) 186116491Sharti 187116491Sharti#define TPD_TST_USED(SC, I) ((SC)->tpd_used[(I) / 8] & (1 << ((I) % 8))) 188116491Sharti 189116491Sharti#define TPD_ADDR(SC, I) ((struct tpd *)((char *)sc->tpds.base + \ 190116491Sharti (I) * HE_TPD_SIZE)) 191116491Sharti 192116491Sharti/*==================================================================*/ 193116491Sharti 194116491Sharti/* 195116491Sharti * External MBUFs. The card needs a lot of mbufs in the pools for high 196116491Sharti * performance. The problem with using mbufs directly is that we would need 197116491Sharti * a dmamap for each of the mbufs. This can exhaust iommu space on the sparc 198116491Sharti * and it eats also a lot of processing time. So we use external mbufs 199116491Sharti * for the small buffers and clusters for the large buffers. 200116491Sharti * For receive group 0 we use 5 ATM cells, for group 1 one (52 byte) ATM 201116491Sharti * cell. The mbuf storage is allocated pagewise and one dmamap is used per 202116491Sharti * page. 203116491Sharti * 204116491Sharti * The handle we give to the card for the small buffers is a word combined 205116491Sharti * of the page number and the number of the chunk in the page. This restricts 206116491Sharti * the number of chunks per page to 256 (8 bit) and the number of pages to 207116491Sharti * 65536 (16 bits). 208116491Sharti * 209116491Sharti * A chunk may be in one of three states: free, on the card and floating around 210116491Sharti * in the system. If it is free, it is on one of the two free lists and 211116491Sharti * start with a struct mbufx_free. Each page has a bitmap that tracks where 212116491Sharti * its chunks are. 213116491Sharti * 214116491Sharti * For large buffers we use mbuf clusters. Here we have two problems: we need 215116491Sharti * to track the buffers on the card (in the case we want to stop it) and 216116491Sharti * we need to map the 64bit mbuf address to a 26bit handle for 64-bit machines. 217116491Sharti * The card uses the buffers in the order we give it to the card. Therefor 218116491Sharti * we can use a private array holding pointers to the mbufs as a circular 219116491Sharti * queue for both tasks. This is done with the lbufs member of softc. The 220116491Sharti * handle for these buffer is the lbufs index ored with a flag. 221116491Sharti */ 222116491Sharti#define MBUF0_SIZE (5 * 48) /* 240 */ 223116491Sharti#define MBUF1_SIZE (52) 224116491Sharti 225116491Sharti#define MBUF0_CHUNK 256 /* 16 free bytes */ 226116491Sharti#define MBUF1_CHUNK 96 /* 44 free bytes */ 227116491Sharti#ifdef XXX 228116491Sharti#define MBUF0_OFFSET (MBUF0_CHUNK - sizeof(struct mbuf_chunk_hdr) \ 229116491Sharti - MBUF0_SIZE) 230116491Sharti#else 231116491Sharti#define MBUF0_OFFSET 0 232116491Sharti#endif 233116491Sharti#define MBUF1_OFFSET (MBUF1_CHUNK - sizeof(struct mbuf_chunk_hdr) \ 234116491Sharti - MBUF1_SIZE) 235116491Sharti#define MBUFL_OFFSET 16 /* two pointers for HARP */ 236116491Sharti 237116491Sharti#define MBUF_ALLOC_SIZE (PAGE_SIZE) 238116491Sharti 239116491Sharti/* each allocated page has one of these structures at its very end. */ 240116491Shartistruct mbuf_page_hdr { 241116491Sharti uint8_t card[32]; /* bitmap for on-card */ 242116491Sharti uint8_t used[32]; /* bitmap for used but not on-card */ 243116491Sharti uint16_t nchunks; /* chunks on this page */ 244116491Sharti bus_dmamap_t map; /* the DMA MAP */ 245116491Sharti uint32_t phys; /* physical base address */ 246116491Sharti uint32_t hdroff; /* chunk header offset */ 247116491Sharti uint32_t chunksize; /* chunk size */ 248116491Sharti}; 249116491Shartistruct mbuf_page { 250116491Sharti char storage[MBUF_ALLOC_SIZE - sizeof(struct mbuf_page_hdr)]; 251116491Sharti struct mbuf_page_hdr hdr; 252116491Sharti}; 253116491Sharti 254116491Sharti/* numbers per page */ 255116491Sharti#define MBUF0_PER_PAGE ((MBUF_ALLOC_SIZE - sizeof(struct mbuf_page_hdr)) / \ 256116491Sharti MBUF0_CHUNK) 257116491Sharti#define MBUF1_PER_PAGE ((MBUF_ALLOC_SIZE - sizeof(struct mbuf_page_hdr)) / \ 258116491Sharti MBUF1_CHUNK) 259116491Sharti 260116491Sharti#define MBUF_CLR_BIT(ARRAY, BIT) ((ARRAY)[(BIT) / 8] &= ~(1 << ((BIT) % 8))) 261116491Sharti#define MBUF_SET_BIT(ARRAY, BIT) ((ARRAY)[(BIT) / 8] |= (1 << ((BIT) % 8))) 262116491Sharti#define MBUF_TST_BIT(ARRAY, BIT) ((ARRAY)[(BIT) / 8] & (1 << ((BIT) % 8))) 263116491Sharti 264116491Sharti#define MBUF_MAKE_HANDLE(PAGENO, CHUNKNO) \ 265116491Sharti (((PAGENO) << 10) | (CHUNKNO)) 266116491Sharti 267116491Sharti#define MBUF_PARSE_HANDLE(HANDLE, PAGENO, CHUNKNO) do { \ 268116491Sharti (CHUNKNO) = (HANDLE) & 0x3ff; \ 269116491Sharti (PAGENO) = ((HANDLE) >> 10) & 0x3ff; \ 270116491Sharti } while (0) 271116491Sharti 272116491Sharti#define MBUF_LARGE_FLAG (1 << 20) 273116491Sharti 274116491Sharti/* chunks have the following structure at the end */ 275116491Shartistruct mbuf_chunk_hdr { 276116491Sharti struct mbuf *mbuf; 277116491Sharti uint16_t pageno; 278116491Sharti uint16_t chunkno; 279116491Sharti}; 280116491Sharti 281116491Sharti#define MBUFX_STORAGE_SIZE(X) (MBUF##X##_CHUNK \ 282116491Sharti - sizeof(struct mbuf_chunk_hdr)) 283116491Sharti 284116491Shartistruct mbuf0_chunk { 285116491Sharti char storage[MBUFX_STORAGE_SIZE(0)]; 286116491Sharti struct mbuf_chunk_hdr hdr; 287116491Sharti}; 288116491Sharti 289116491Shartistruct mbuf1_chunk { 290116491Sharti char storage[MBUFX_STORAGE_SIZE(1)]; 291116491Sharti struct mbuf_chunk_hdr hdr; 292116491Sharti}; 293116491Sharti 294116491Shartistruct mbufx_free { 295116491Sharti SLIST_ENTRY(mbufx_free) link; 296116491Sharti}; 297116491ShartiSLIST_HEAD(mbufx_free_list, mbufx_free); 298116491Sharti 299116491Sharti/*==================================================================*/ 300116491Sharti 301116491Sharti/* 302116491Sharti * Interrupt queue 303116491Sharti */ 304116491Shartistruct heirq { 305116491Sharti u_int size; /* number of entries */ 306116491Sharti u_int thresh; /* re-interrupt threshold */ 307116491Sharti u_int line; /* interrupt line to use */ 308116491Sharti struct dmamem mem; /* interrupt queues */ 309116491Sharti uint32_t * irq; /* interrupt queue */ 310116491Sharti uint32_t head; /* head index */ 311116491Sharti uint32_t * tailp; /* pointer to tail */ 312116491Sharti struct hatm_softc *sc; /* back pointer */ 313116491Sharti u_int group; /* interrupt group */ 314116491Sharti}; 315116491Sharti 316116491Sharti/* 317116491Sharti * This structure describes all information for a VCC open on the card. 318116491Sharti * The array of these structures is indexed by the compressed connection ID 319118205Sharti * (CID). This structure must begin with the atmio_vcc. 320116491Sharti */ 321116491Shartistruct hevcc { 322118205Sharti struct atmio_vcc param; /* traffic parameters */ 323118205Sharti void * rxhand; /* NATM protocol block */ 324116491Sharti u_int vflags; /* private flags */ 325118205Sharti uint32_t ipackets; 326118205Sharti uint32_t opackets; 327118205Sharti uint32_t ibytes; 328118205Sharti uint32_t obytes; 329118205Sharti 330116491Sharti u_int rc; /* rate control group for CBR */ 331116491Sharti struct mbuf * chain; /* partial received PDU */ 332116491Sharti struct mbuf * last; /* last mbuf in chain */ 333116491Sharti u_int ntpds; /* number of active TPDs */ 334116491Sharti}; 335116491Sharti#define HE_VCC_OPEN 0x000f0000 336116491Sharti#define HE_VCC_RX_OPEN 0x00010000 337116491Sharti#define HE_VCC_RX_CLOSING 0x00020000 338116491Sharti#define HE_VCC_TX_OPEN 0x00040000 339116491Sharti#define HE_VCC_TX_CLOSING 0x00080000 340116491Sharti#define HE_VCC_FLOW_CTRL 0x00100000 341116491Sharti 342116491Sharti/* 343116491Sharti * CBR rate groups 344116491Sharti */ 345116491Shartistruct herg { 346116491Sharti u_int refcnt; /* how many connections reference this group */ 347116491Sharti u_int rate; /* the value */ 348116491Sharti}; 349116491Sharti 350116491Sharti/* 351116491Sharti * Softc 352116491Sharti */ 353116491Shartistruct hatm_softc { 354116491Sharti struct ifatm ifatm; /* common ATM stuff */ 355116491Sharti struct mtx mtx; /* lock */ 356116491Sharti struct ifmedia media; /* media */ 357116491Sharti device_t dev; /* device */ 358116491Sharti int memid; /* resoure id for memory */ 359116491Sharti struct resource * memres; /* memory resource */ 360116491Sharti bus_space_handle_t memh; /* handle */ 361116491Sharti bus_space_tag_t memt; /* ... and tag */ 362116491Sharti bus_dma_tag_t parent_tag; /* global restriction */ 363116491Sharti struct cv vcc_cv; /* condition variable */ 364116491Sharti int irqid; /* resource id */ 365116491Sharti struct resource * irqres; /* resource */ 366116491Sharti void * ih; /* interrupt handle */ 367116491Sharti struct utopia utopia; /* utopia state */ 368116491Sharti 369116491Sharti /* rest has to be reset by stop */ 370116491Sharti int he622; /* this is a HE622 */ 371116491Sharti int pci64; /* 64bit bus */ 372116491Sharti char prod_id[HE_EEPROM_PROD_ID_LEN + 1]; 373116491Sharti char rev[HE_EEPROM_REV_LEN + 1]; 374116491Sharti struct heirq irq_0; /* interrupt queues 0 */ 375116491Sharti 376116491Sharti /* generic network controller state */ 377116491Sharti u_int cells_per_row; 378116491Sharti u_int bytes_per_row; 379116491Sharti u_int r0_numrows; 380116491Sharti u_int tx_numrows; 381116491Sharti u_int r1_numrows; 382116491Sharti u_int r0_startrow; 383116491Sharti u_int tx_startrow; 384116491Sharti u_int r1_startrow; 385116491Sharti u_int cells_per_lbuf; 386116491Sharti u_int r0_numbuffs; 387116491Sharti u_int r1_numbuffs; 388116491Sharti u_int tx_numbuffs; 389116491Sharti 390116491Sharti /* HSP */ 391116491Sharti struct he_hsp *hsp; 392116491Sharti struct dmamem hsp_mem; 393116491Sharti 394116491Sharti /*** TX ***/ 395116491Sharti struct hetbrq tbrq; /* TBRQ 0 */ 396116491Sharti struct hetpdrq tpdrq; /* TPDRQ */ 397116491Sharti struct tpd_list tpd_free; /* Free TPDs */ 398116491Sharti u_int tpd_nfree; /* number of free TPDs */ 399116491Sharti u_int tpd_total; /* total TPDs */ 400116491Sharti uint8_t *tpd_used; /* bitmap of used TPDs */ 401116491Sharti struct dmamem tpds; /* TPD memory */ 402116491Sharti bus_dma_tag_t tx_tag; /* DMA tag for all tx mbufs */ 403116491Sharti 404116491Sharti /*** RX ***/ 405116491Sharti /* receive/transmit groups */ 406116491Sharti struct herbp rbp_s0; /* RBPS0 */ 407116491Sharti struct herbp rbp_l0; /* RBPL0 */ 408116491Sharti struct herbp rbp_s1; /* RBPS1 */ 409116491Sharti struct herbrq rbrq_0; /* RBRQ0 */ 410116491Sharti struct herbrq rbrq_1; /* RBRQ1 */ 411116491Sharti 412116491Sharti /* list of external mbuf storage */ 413116491Sharti bus_dma_tag_t mbuf_tag; 414116491Sharti struct mbuf_page **mbuf_pages; 415116491Sharti u_int mbuf_npages; 416116491Sharti struct mtx mbuf0_mtx; 417116491Sharti struct mbufx_free_list mbuf0_list; 418116491Sharti struct mtx mbuf1_mtx; 419116491Sharti struct mbufx_free_list mbuf1_list; 420116491Sharti 421116491Sharti /* mbuf cluster tracking and mapping for group 0 */ 422116491Sharti struct mbuf **lbufs; /* mbufs */ 423116491Sharti bus_dmamap_t *rmaps; /* DMA maps */ 424116491Sharti u_int lbufs_size; 425116491Sharti u_int lbufs_next; 426116491Sharti 427116491Sharti /* VCCs */ 428116491Sharti struct hevcc *vccs[HE_MAX_VCCS]; 429116491Sharti u_int cbr_bw; /* BW allocated to CBR */ 430116491Sharti u_int max_tpd; /* per VCC */ 431116491Sharti u_int open_vccs; 432116491Sharti uma_zone_t vcc_zone; 433116491Sharti 434116491Sharti /* rate groups */ 435116491Sharti struct herg rate_ctrl[HE_REGN_CS_STPER]; 436116491Sharti 437116491Sharti /* memory offsets */ 438116491Sharti u_int tsrb, tsrc, tsrd; 439116491Sharti u_int rsrb; 440116491Sharti 441116491Sharti struct cv cv_rcclose; /* condition variable */ 442116491Sharti uint32_t rate_grid[16][16]; /* our copy */ 443116491Sharti 444116491Sharti /* sysctl support */ 445116491Sharti struct sysctl_ctx_list sysctl_ctx; 446116491Sharti struct sysctl_oid *sysctl_tree; 447116491Sharti 448116491Sharti /* internal statistics */ 449116491Sharti struct istats istats; 450116491Sharti 451116491Sharti#ifdef HATM_DEBUG 452116491Sharti /* debugging */ 453116491Sharti u_int debug; 454116491Sharti#endif 455116491Sharti}; 456116491Sharti 457116491Sharti#define READ4(SC,OFF) bus_space_read_4(SC->memt, SC->memh, (OFF)) 458116491Sharti#define READ2(SC,OFF) bus_space_read_2(SC->memt, SC->memh, (OFF)) 459116491Sharti#define READ1(SC,OFF) bus_space_read_1(SC->memt, SC->memh, (OFF)) 460116491Sharti 461116491Sharti#define WRITE4(SC,OFF,VAL) bus_space_write_4(SC->memt, SC->memh, (OFF), (VAL)) 462116491Sharti#define WRITE2(SC,OFF,VAL) bus_space_write_2(SC->memt, SC->memh, (OFF), (VAL)) 463116491Sharti#define WRITE1(SC,OFF,VAL) bus_space_write_1(SC->memt, SC->memh, (OFF), (VAL)) 464116491Sharti 465116491Sharti#define BARRIER_R(SC) bus_space_barrier(SC->memt, SC->memh, 0, HE_REGO_END, \ 466116491Sharti BUS_SPACE_BARRIER_READ) 467116491Sharti#define BARRIER_W(SC) bus_space_barrier(SC->memt, SC->memh, 0, HE_REGO_END, \ 468116491Sharti BUS_SPACE_BARRIER_WRITE) 469116491Sharti#define BARRIER_RW(SC) bus_space_barrier(SC->memt, SC->memh, 0, HE_REGO_END, \ 470116491Sharti BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE) 471116491Sharti 472116491Sharti#define READ_SUNI(SC,OFF) READ4(SC, HE_REGO_SUNI + 4 * (OFF)) 473116491Sharti#define WRITE_SUNI(SC,OFF,VAL) WRITE4(SC, HE_REGO_SUNI + 4 * (OFF), (VAL)) 474116491Sharti 475116491Sharti#define READ_LB4(SC,OFF) \ 476116491Sharti ({ \ 477116491Sharti WRITE4(SC, HE_REGO_LB_MEM_ADDR, (OFF)); \ 478116491Sharti WRITE4(SC, HE_REGO_LB_MEM_ACCESS, \ 479116491Sharti (HE_REGM_LB_MEM_HNDSHK | HE_REGM_LB_MEM_READ)); \ 480116491Sharti while((READ4(SC, HE_REGO_LB_MEM_ACCESS) & HE_REGM_LB_MEM_HNDSHK))\ 481116491Sharti ; \ 482116491Sharti READ4(SC, HE_REGO_LB_MEM_DATA); \ 483116491Sharti }) 484116491Sharti#define WRITE_LB4(SC,OFF,VAL) \ 485116491Sharti do { \ 486116491Sharti WRITE4(SC, HE_REGO_LB_MEM_ADDR, (OFF)); \ 487116491Sharti WRITE4(SC, HE_REGO_LB_MEM_DATA, (VAL)); \ 488116491Sharti WRITE4(SC, HE_REGO_LB_MEM_ACCESS, \ 489116491Sharti (HE_REGM_LB_MEM_HNDSHK | HE_REGM_LB_MEM_WRITE)); \ 490116491Sharti while((READ4(SC, HE_REGO_LB_MEM_ACCESS) & HE_REGM_LB_MEM_HNDSHK))\ 491116491Sharti ; \ 492116491Sharti } while(0) 493116491Sharti 494116491Sharti#define WRITE_MEM4(SC,OFF,VAL,SPACE) \ 495116491Sharti do { \ 496116491Sharti WRITE4(SC, HE_REGO_CON_DAT, (VAL)); \ 497116491Sharti WRITE4(SC, HE_REGO_CON_CTL, \ 498116491Sharti (SPACE | HE_REGM_CON_WE | HE_REGM_CON_STATUS | (OFF))); \ 499116491Sharti while((READ4(SC, HE_REGO_CON_CTL) & HE_REGM_CON_STATUS) != 0) \ 500116491Sharti ; \ 501116491Sharti } while(0) 502116491Sharti 503116491Sharti#define READ_MEM4(SC,OFF,SPACE) \ 504116491Sharti ({ \ 505116491Sharti WRITE4(SC, HE_REGO_CON_CTL, \ 506116491Sharti (SPACE | HE_REGM_CON_STATUS | (OFF))); \ 507116491Sharti while((READ4(SC, HE_REGO_CON_CTL) & HE_REGM_CON_STATUS) != 0) \ 508116491Sharti ; \ 509116491Sharti READ4(SC, HE_REGO_CON_DAT); \ 510116491Sharti }) 511116491Sharti 512116491Sharti#define WRITE_TCM4(SC,OFF,VAL) WRITE_MEM4(SC,(OFF),(VAL),HE_REGM_CON_TCM) 513116491Sharti#define WRITE_RCM4(SC,OFF,VAL) WRITE_MEM4(SC,(OFF),(VAL),HE_REGM_CON_RCM) 514116491Sharti#define WRITE_MBOX4(SC,OFF,VAL) WRITE_MEM4(SC,(OFF),(VAL),HE_REGM_CON_MBOX) 515116491Sharti 516116491Sharti#define READ_TCM4(SC,OFF) READ_MEM4(SC,(OFF),HE_REGM_CON_TCM) 517116491Sharti#define READ_RCM4(SC,OFF) READ_MEM4(SC,(OFF),HE_REGM_CON_RCM) 518116491Sharti#define READ_MBOX4(SC,OFF) READ_MEM4(SC,(OFF),HE_REGM_CON_MBOX) 519116491Sharti 520116491Sharti#define WRITE_TCM(SC,OFF,BYTES,VAL) \ 521116491Sharti WRITE_MEM4(SC,(OFF) | ((~(BYTES) & 0xf) << HE_REGS_CON_DIS), \ 522116491Sharti (VAL), HE_REGM_CON_TCM) 523116491Sharti#define WRITE_RCM(SC,OFF,BYTES,VAL) \ 524116491Sharti WRITE_MEM4(SC,(OFF) | ((~(BYTES) & 0xf) << HE_REGS_CON_DIS), \ 525116491Sharti (VAL), HE_REGM_CON_RCM) 526116491Sharti 527116491Sharti#define READ_TSR(SC,CID,NR) \ 528116491Sharti ({ \ 529116491Sharti uint32_t _v; \ 530116491Sharti if((NR) <= 7) { \ 531116491Sharti _v = READ_TCM4(SC, HE_REGO_TSRA(0,CID,NR)); \ 532116491Sharti } else if((NR) <= 11) { \ 533116491Sharti _v = READ_TCM4(SC, HE_REGO_TSRB((SC)->tsrb,CID,(NR-8)));\ 534116491Sharti } else if((NR) <= 13) { \ 535116491Sharti _v = READ_TCM4(SC, HE_REGO_TSRC((SC)->tsrc,CID,(NR-12)));\ 536116491Sharti } else { \ 537116491Sharti _v = READ_TCM4(SC, HE_REGO_TSRD((SC)->tsrd,CID)); \ 538116491Sharti } \ 539116491Sharti _v; \ 540116491Sharti }) 541116491Sharti 542116491Sharti#define WRITE_TSR(SC,CID,NR,BEN,VAL) \ 543116491Sharti do { \ 544116491Sharti if((NR) <= 7) { \ 545116491Sharti WRITE_TCM(SC, HE_REGO_TSRA(0,CID,NR),BEN,VAL); \ 546116491Sharti } else if((NR) <= 11) { \ 547116491Sharti WRITE_TCM(SC, HE_REGO_TSRB((SC)->tsrb,CID,(NR-8)),BEN,VAL);\ 548116491Sharti } else if((NR) <= 13) { \ 549116491Sharti WRITE_TCM(SC, HE_REGO_TSRC((SC)->tsrc,CID,(NR-12)),BEN,VAL);\ 550116491Sharti } else { \ 551116491Sharti WRITE_TCM(SC, HE_REGO_TSRD((SC)->tsrd,CID),BEN,VAL); \ 552116491Sharti } \ 553116491Sharti } while(0) 554116491Sharti 555116491Sharti#define READ_RSR(SC,CID,NR) \ 556116491Sharti ({ \ 557116491Sharti uint32_t _v; \ 558116491Sharti if((NR) <= 7) { \ 559116491Sharti _v = READ_RCM4(SC, HE_REGO_RSRA(0,CID,NR)); \ 560116491Sharti } else { \ 561116491Sharti _v = READ_RCM4(SC, HE_REGO_RSRB((SC)->rsrb,CID,(NR-8)));\ 562116491Sharti } \ 563116491Sharti _v; \ 564116491Sharti }) 565116491Sharti 566116491Sharti#define WRITE_RSR(SC,CID,NR,BEN,VAL) \ 567116491Sharti do { \ 568116491Sharti if((NR) <= 7) { \ 569116491Sharti WRITE_RCM(SC, HE_REGO_RSRA(0,CID,NR),BEN,VAL); \ 570116491Sharti } else { \ 571116491Sharti WRITE_RCM(SC, HE_REGO_RSRB((SC)->rsrb,CID,(NR-8)),BEN,VAL);\ 572116491Sharti } \ 573116491Sharti } while(0) 574116491Sharti 575116491Sharti#ifdef HATM_DEBUG 576116491Sharti#define DBG(SC, FL, PRINT) do { \ 577116491Sharti if((SC)->debug & DBG_##FL) { \ 578116491Sharti if_printf(&(SC)->ifatm.ifnet, "%s: ", __func__); \ 579116491Sharti printf PRINT; \ 580116491Sharti printf("\n"); \ 581116491Sharti } \ 582116491Sharti } while (0) 583116491Sharti 584116491Shartienum { 585116491Sharti DBG_RX = 0x0001, 586116491Sharti DBG_TX = 0x0002, 587116491Sharti DBG_VCC = 0x0004, 588116491Sharti DBG_IOCTL = 0x0008, 589116491Sharti DBG_ATTACH = 0x0010, 590116491Sharti DBG_INTR = 0x0020, 591116491Sharti DBG_DMA = 0x0040, 592116491Sharti DBG_DMAH = 0x0080, 593116491Sharti 594116491Sharti DBG_ALL = 0x00ff 595116491Sharti}; 596116491Sharti 597116491Sharti#else 598116491Sharti#define DBG(SC, FL, PRINT) 599116491Sharti#endif 600116491Sharti 601116491Shartiu_int hatm_cps2atmf(uint32_t); 602116491Shartiu_int hatm_atmf2cps(uint32_t); 603116491Sharti 604116491Shartivoid hatm_intr(void *); 605116491Shartiint hatm_ioctl(struct ifnet *, u_long, caddr_t); 606116491Shartivoid hatm_initialize(struct hatm_softc *); 607116491Shartivoid hatm_stop(struct hatm_softc *sc); 608116491Shartivoid hatm_start(struct ifnet *); 609116491Sharti 610116491Shartivoid hatm_rx(struct hatm_softc *sc, u_int cid, u_int flags, struct mbuf *m, 611116491Sharti u_int len); 612116491Shartivoid hatm_tx_complete(struct hatm_softc *sc, struct tpd *tpd, uint32_t); 613116491Sharti 614116491Shartiint hatm_tx_vcc_can_open(struct hatm_softc *sc, u_int cid, struct hevcc *); 615116491Shartivoid hatm_tx_vcc_open(struct hatm_softc *sc, u_int cid); 616116491Shartivoid hatm_rx_vcc_open(struct hatm_softc *sc, u_int cid); 617116491Shartivoid hatm_tx_vcc_close(struct hatm_softc *sc, u_int cid); 618116491Shartivoid hatm_rx_vcc_close(struct hatm_softc *sc, u_int cid); 619116491Shartivoid hatm_tx_vcc_closed(struct hatm_softc *sc, u_int cid); 620116491Shartivoid hatm_vcc_closed(struct hatm_softc *sc, u_int cid); 621118598Shartivoid hatm_load_vc(struct hatm_softc *sc, u_int cid, int reopen); 622