1178173Simp/* $NetBSD: if_admswvar.h,v 1.1 2007/03/20 08:52:02 dyoung Exp $ */ 2178173Simp 3178173Simp/*- 4178173Simp * Copyright (c) 2007 Ruslan Ermilov and Vsevolod Lobko. 5178173Simp * All rights reserved. 6178173Simp * 7178173Simp * Redistribution and use in source and binary forms, with or 8178173Simp * without modification, are permitted provided that the following 9178173Simp * conditions are met: 10178173Simp * 1. Redistributions of source code must retain the above copyright 11178173Simp * notice, this list of conditions and the following disclaimer. 12178173Simp * 2. Redistributions in binary form must reproduce the above 13178173Simp * copyright notice, this list of conditions and the following 14178173Simp * disclaimer in the documentation and/or other materials provided 15178173Simp * with the distribution. 16178173Simp * 3. The names of the authors may not be used to endorse or promote 17178173Simp * products derived from this software without specific prior 18178173Simp * written permission. 19178173Simp * 20178173Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY 21178173Simp * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22178173Simp * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 23178173Simp * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS 24178173Simp * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 25178173Simp * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26178173Simp * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 27178173Simp * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28178173Simp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 29178173Simp * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 30178173Simp * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31178173Simp * OF SUCH DAMAGE. 32178173Simp */ 33178173Simp#ifndef _IF_ADMSWVAR_H_ 34178173Simp#define _IF_ADMSWVAR_H_ 35178173Simp 36178173Simp#include <sys/cdefs.h> 37178173Simp__FBSDID("$FreeBSD: releng/10.2/sys/mips/adm5120/if_admswvar.h 202175 2010-01-12 21:36:08Z imp $"); 38178173Simp 39178173Simp#include <sys/param.h> 40178173Simp#include <sys/systm.h> 41178173Simp#include <sys/bus.h> 42178173Simp#include <sys/kernel.h> 43178173Simp#include <sys/mbuf.h> 44178173Simp#include <sys/malloc.h> 45178173Simp#include <sys/module.h> 46178173Simp#include <sys/rman.h> 47178173Simp#include <sys/socket.h> 48178173Simp#include <sys/sockio.h> 49178173Simp#include <sys/sysctl.h> 50178173Simp#include <machine/bus.h> 51178173Simp 52178173Simp#include <net/ethernet.h> 53178173Simp#include <net/if.h> 54178173Simp#include <net/if_arp.h> 55178173Simp#include <net/if_dl.h> 56178173Simp#include <net/if_media.h> 57178173Simp#include <net/if_mib.h> 58178173Simp#include <net/if_types.h> 59178173Simp 60178173Simp#ifdef INET 61178173Simp#include <netinet/in.h> 62178173Simp#include <netinet/in_systm.h> 63178173Simp#include <netinet/in_var.h> 64178173Simp#include <netinet/ip.h> 65178173Simp#endif 66178173Simp 67178173Simp#include <net/bpf.h> 68178173Simp#include <net/bpfdesc.h> 69178173Simp 70178173Simp#include <dev/mii/mii.h> 71178173Simp#include <dev/mii/miivar.h> 72178173Simp 73182901Sgonzo#include <mips/adm5120/adm5120reg.h> 74182901Sgonzo#include <mips/adm5120/if_admswreg.h> 75178173Simp 76178173Simp#define MAC_BUFLEN 0x07ff 77178173Simp 78178173Simp#define ADMSW_NTXHDESC 4 79178173Simp#define ADMSW_NRXHDESC 32 80178173Simp#define ADMSW_NTXLDESC 32 81178173Simp#define ADMSW_NRXLDESC 32 82178173Simp 83178173Simp#define ADMSW_NTXHDESC_MASK (ADMSW_NTXHDESC - 1) 84178173Simp#define ADMSW_NRXHDESC_MASK (ADMSW_NRXHDESC - 1) 85178173Simp#define ADMSW_NTXLDESC_MASK (ADMSW_NTXLDESC - 1) 86178173Simp#define ADMSW_NRXLDESC_MASK (ADMSW_NRXLDESC - 1) 87178173Simp 88178173Simp#define ADMSW_NEXTTXH(x) (((x) + 1) & ADMSW_NTXHDESC_MASK) 89178173Simp#define ADMSW_NEXTRXH(x) (((x) + 1) & ADMSW_NRXHDESC_MASK) 90178173Simp#define ADMSW_NEXTTXL(x) (((x) + 1) & ADMSW_NTXLDESC_MASK) 91178173Simp#define ADMSW_NEXTRXL(x) (((x) + 1) & ADMSW_NRXLDESC_MASK) 92178173Simp 93178173Simp#define ADMSW_IRQ 9 94178173Simp 95178173Simpstruct admsw_control_data { 96178173Simp /* The transmit descriptors. */ 97178173Simp struct admsw_desc acd_txhdescs[ADMSW_NTXHDESC]; 98178173Simp 99178173Simp /* The receive descriptors. */ 100178173Simp struct admsw_desc acd_rxhdescs[ADMSW_NRXHDESC]; 101178173Simp 102178173Simp /* The transmit descriptors. */ 103178173Simp struct admsw_desc acd_txldescs[ADMSW_NTXLDESC]; 104178173Simp 105178173Simp /* The receive descriptors. */ 106178173Simp struct admsw_desc acd_rxldescs[ADMSW_NRXLDESC]; 107178173Simp}; 108178173Simp 109178173Simp#define ADMSW_CDOFF(x) offsetof(struct admsw_control_data, x) 110178173Simp#define ADMSW_CDTXHOFF(x) ADMSW_CDOFF(acd_txhdescs[(x)]) 111178173Simp#define ADMSW_CDTXLOFF(x) ADMSW_CDOFF(acd_txldescs[(x)]) 112178173Simp#define ADMSW_CDRXHOFF(x) ADMSW_CDOFF(acd_rxhdescs[(x)]) 113178173Simp#define ADMSW_CDRXLOFF(x) ADMSW_CDOFF(acd_rxldescs[(x)]) 114178173Simp 115178173Simpstruct admsw_descsoft { 116178173Simp struct mbuf *ds_mbuf; 117178173Simp bus_dmamap_t ds_dmamap; 118178173Simp /* Up to 2 segments */ 119178173Simp uint32_t ds_addr[2]; 120178173Simp uint32_t ds_len[2]; 121178173Simp uint32_t ds_nsegs; 122178173Simp}; 123178173Simp 124178173Simp/* 125178173Simp * Software state per device. 126178173Simp */ 127178173Simpstruct admsw_softc { 128178173Simp device_t sc_dev; /* generic device information */ 129178173Simp uint8_t sc_enaddr[ETHER_ADDR_LEN]; 130178173Simp bus_dma_tag_t sc_control_dmat; 131178173Simp /* bus DMA tag for control structs*/ 132178173Simp bus_dma_tag_t sc_bufs_dmat; /* bus DMA tag for buffers */ 133178173Simp struct ifmedia sc_ifmedia[SW_DEVS]; 134178173Simp int ndevs; /* number of IFF_RUNNING interfaces */ 135199762Sjhb struct ifnet *sc_ifnet[SW_DEVS]; 136199762Sjhb struct callout sc_watchdog; 137199762Sjhb int sc_timer; 138178173Simp /* Ethernet common data */ 139178173Simp void *sc_ih; /* interrupt cookie */ 140178173Simp struct resource *irq_res; 141178173Simp struct resource *mem_res; 142178173Simp bus_dmamap_t sc_cddmamap; /* control data DMA map */ 143178173Simp uint32_t sc_cddma; 144178173Simp struct admsw_control_data *sc_control_data; 145178173Simp 146178173Simp struct admsw_descsoft sc_txhsoft[ADMSW_NTXHDESC]; 147178173Simp struct admsw_descsoft sc_rxhsoft[ADMSW_NRXHDESC]; 148178173Simp struct admsw_descsoft sc_txlsoft[ADMSW_NTXLDESC]; 149178173Simp struct admsw_descsoft sc_rxlsoft[ADMSW_NRXLDESC]; 150178173Simp#define sc_txhdescs sc_control_data->acd_txhdescs 151178173Simp#define sc_rxhdescs sc_control_data->acd_rxhdescs 152178173Simp#define sc_txldescs sc_control_data->acd_txldescs 153178173Simp#define sc_rxldescs sc_control_data->acd_rxldescs 154178173Simp 155178173Simp int sc_txfree; /* number of free Tx descriptors */ 156178173Simp int sc_txnext; /* next Tx descriptor to use */ 157178173Simp int sc_txdirty; /* first dirty Tx descriptor */ 158178173Simp int sc_rxptr; /* next ready Rx descriptor */ 159178173Simp}; 160178173Simp 161178173Simp#define ADMSW_CDTXHADDR(sc, x) ((sc)->sc_cddma + ADMSW_CDTXHOFF((x))) 162178173Simp#define ADMSW_CDTXLADDR(sc, x) ((sc)->sc_cddma + ADMSW_CDTXLOFF((x))) 163178173Simp#define ADMSW_CDRXHADDR(sc, x) ((sc)->sc_cddma + ADMSW_CDRXHOFF((x))) 164178173Simp#define ADMSW_CDRXLADDR(sc, x) ((sc)->sc_cddma + ADMSW_CDRXLOFF((x))) 165178173Simp 166178173Simp#define ADMSW_CDTXHSYNC(sc, x, ops) \ 167178173Simp bus_dmamap_sync((sc)->sc_control_dmat, (sc)->sc_cddmamap, (ops)) 168178173Simp 169178173Simp#define ADMSW_CDTXLSYNC(sc, x, ops) \ 170178173Simp bus_dmamap_sync((sc)->sc_control_dmat, (sc)->sc_cddmamap, (ops)) 171178173Simp 172178173Simp#define ADMSW_CDRXHSYNC(sc, x, ops) \ 173178173Simp bus_dmamap_sync((sc)->sc_control_dmat, (sc)->sc_cddmamap, (ops)) 174178173Simp 175178173Simp#define ADMSW_CDRXLSYNC(sc, x, ops) \ 176178173Simp bus_dmamap_sync((sc)->sc_control_dmat, (sc)->sc_cddmamap, (ops)) 177178173Simp 178178173Simp#define ADMSW_INIT_RXHDESC(sc, x) \ 179178173Simpdo { \ 180178173Simp struct admsw_descsoft *__ds = &(sc)->sc_rxhsoft[(x)]; \ 181178173Simp struct admsw_desc *__desc = &(sc)->sc_rxhdescs[(x)]; \ 182178173Simp struct mbuf *__m = __ds->ds_mbuf; \ 183178173Simp \ 184178173Simp __m->m_data = __m->m_ext.ext_buf + 2; \ 185178173Simp __desc->data = __ds->ds_addr[0] + 2; \ 186178173Simp __desc->cntl = 0; \ 187178173Simp __desc->len = min(MCLBYTES - 2, MAC_BUFLEN - 2); \ 188178173Simp __desc->status = 0; \ 189178173Simp if ((x) == ADMSW_NRXHDESC - 1) \ 190178173Simp __desc->data |= ADM5120_DMA_RINGEND; \ 191178173Simp __desc->data |= ADM5120_DMA_OWN; \ 192178173Simp ADMSW_CDRXHSYNC((sc), (x), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); \ 193178173Simp} while (0) 194178173Simp 195178173Simp#define ADMSW_INIT_RXLDESC(sc, x) \ 196178173Simpdo { \ 197178173Simp struct admsw_descsoft *__ds = &(sc)->sc_rxlsoft[(x)]; \ 198178173Simp struct admsw_desc *__desc = &(sc)->sc_rxldescs[(x)]; \ 199178173Simp struct mbuf *__m = __ds->ds_mbuf; \ 200178173Simp \ 201178173Simp __m->m_data = __m->m_ext.ext_buf + 2; \ 202178173Simp __desc->data = __ds->ds_addr[0] + 2; \ 203178173Simp __desc->cntl = 0; \ 204178173Simp __desc->len = min(MCLBYTES - 2, MAC_BUFLEN - 2); \ 205178173Simp __desc->status = 0; \ 206178173Simp if ((x) == ADMSW_NRXLDESC - 1) \ 207178173Simp __desc->data |= ADM5120_DMA_RINGEND; \ 208178173Simp __desc->data |= ADM5120_DMA_OWN; \ 209178173Simp ADMSW_CDRXLSYNC((sc), (x), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); \ 210178173Simp} while (0) 211178173Simp 212178173Simpvoid admwdog_attach(struct admsw_softc *); 213178173Simp 214178173Simp#endif /* _IF_ADMSWVAR_H_ */ 215