lancevar.h revision 164933
10SN/A/* $NetBSD: lancevar.h,v 1.10 2005/12/11 12:21:27 christos Exp $ */ 29330SN/A 30SN/A/*- 40SN/A * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. 50SN/A * All rights reserved. 60SN/A * 70SN/A * This code is derived from software contributed to The NetBSD Foundation 80SN/A * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace 90SN/A * Simulation Facility, NASA Ames Research Center. 100SN/A * 110SN/A * Redistribution and use in source and binary forms, with or without 120SN/A * modification, are permitted provided that the following conditions 130SN/A * are met: 140SN/A * 1. Redistributions of source code must retain the above copyright 152362SN/A * notice, this list of conditions and the following disclaimer. 160SN/A * 2. Redistributions in binary form must reproduce the above copyright 170SN/A * notice, this list of conditions and the following disclaimer in the 180SN/A * documentation and/or other materials provided with the distribution. 190SN/A * 3. All advertising materials mentioning features or use of this software 200SN/A * must display the following acknowledgement: 210SN/A * This product includes software developed by the NetBSD 220SN/A * Foundation, Inc. and its contributors. 230SN/A * 4. Neither the name of The NetBSD Foundation nor the names of its 240SN/A * contributors may be used to endorse or promote products derived 250SN/A * from this software without specific prior written permission. 260SN/A * 270SN/A * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 280SN/A * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 290SN/A * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 300SN/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 310SN/A * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 324457SN/A * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 334457SN/A * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 344457SN/A * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 354457SN/A * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 364457SN/A * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 374457SN/A * POSSIBILITY OF SUCH DAMAGE. 384457SN/A */ 394457SN/A 404457SN/A/* $FreeBSD: head/sys/dev/le/lancevar.h 164933 2006-12-06 02:14:31Z marius $ */ 410SN/A 420SN/A#ifndef _DEV_LE_LANCEVAR_H_ 430SN/A#define _DEV_LE_LANCEVAR_H_ 440SN/A 450SN/Aextern devclass_t le_devclass; 460SN/A 470SN/Astruct lance_softc { 480SN/A struct ifnet *sc_ifp; 490SN/A struct ifmedia sc_media; 500SN/A struct mtx sc_mtx; 510SN/A struct callout sc_wdog_ch; 520SN/A int sc_wdog_timer; 530SN/A 540SN/A /* 550SN/A * Memory functions: 560SN/A * 570SN/A * copy to/from descriptor 580SN/A * copy to/from buffer 590SN/A * zero bytes in buffer 600SN/A */ 610SN/A void (*sc_copytodesc)(struct lance_softc *, void *, int, int); 620SN/A void (*sc_copyfromdesc)(struct lance_softc *, void *, int, int); 630SN/A void (*sc_copytobuf)(struct lance_softc *, void *, int, int); 640SN/A void (*sc_copyfrombuf)(struct lance_softc *, void *, int, int); 650SN/A void (*sc_zerobuf)(struct lance_softc *, int, int); 660SN/A 670SN/A /* 680SN/A * Machine-dependent functions: 690SN/A * 700SN/A * read/write CSR 710SN/A * hardware reset hook - may be NULL 720SN/A * hardware init hook - may be NULL 730SN/A * no carrier hook - may be NULL 740SN/A * media change hook - may be NULL 750SN/A */ 760SN/A uint16_t (*sc_rdcsr)(struct lance_softc *, uint16_t); 770SN/A void (*sc_wrcsr)(struct lance_softc *, uint16_t, uint16_t); 780SN/A void (*sc_hwreset)(struct lance_softc *); 790SN/A void (*sc_hwinit)(struct lance_softc *); 800SN/A int (*sc_hwintr)(struct lance_softc *); 810SN/A void (*sc_nocarrier)(struct lance_softc *); 820SN/A int (*sc_mediachange)(struct lance_softc *); 830SN/A void (*sc_mediastatus)(struct lance_softc *, struct ifmediareq *); 840SN/A 850SN/A /* 860SN/A * Media-supported by this interface. If this is NULL, 870SN/A * the only supported media is assumed to be "manual". 880SN/A */ 890SN/A const int *sc_supmedia; 900SN/A int sc_nsupmedia; 910SN/A int sc_defaultmedia; 920SN/A 930SN/A uint16_t sc_conf3; /* CSR3 value */ 940SN/A 950SN/A void *sc_mem; /* base address of RAM - CPU's view */ 960SN/A bus_addr_t sc_addr; /* base address of RAM - LANCE's view */ 970SN/A 980SN/A bus_size_t sc_memsize; /* size of RAM */ 990SN/A 1000SN/A int sc_nrbuf; /* number of receive buffers */ 1010SN/A int sc_ntbuf; /* number of transmit buffers */ 1020SN/A int sc_last_rd; 1030SN/A int sc_first_td; 1040SN/A int sc_last_td; 1050SN/A int sc_no_td; 1060SN/A 1070SN/A int sc_initaddr; 1080SN/A int sc_rmdaddr; 1090SN/A int sc_tmdaddr; 1100SN/A int sc_rbufaddr; 1110SN/A int sc_tbufaddr; 1120SN/A 1130SN/A uint8_t sc_enaddr[ETHER_ADDR_LEN]; 1140SN/A 1150SN/A void (*sc_meminit)(struct lance_softc *); 1160SN/A void (*sc_start_locked)(struct lance_softc *); 1170SN/A 1180SN/A int sc_flags; 1190SN/A#define LE_ALLMULTI (1 << 0) 1200SN/A#define LE_BSWAP (1 << 1) 1210SN/A#define LE_CARRIER (1 << 2) 1220SN/A#define LE_DEBUG (1 << 3) 1230SN/A#define LE_PROMISC (1 << 4) 1240SN/A}; 1250SN/A 1260SN/A#define LE_LOCK_INIT(_sc, _name) \ 1270SN/A mtx_init(&(_sc)->sc_mtx, _name, MTX_NETWORK_LOCK, MTX_DEF) 1280SN/A#define LE_LOCK_INITIALIZED(_sc) mtx_initialized(&(_sc)->sc_mtx) 1290SN/A#define LE_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) 1300SN/A#define LE_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) 1310SN/A#define LE_LOCK_ASSERT(_sc, _what) mtx_assert(&(_sc)->sc_mtx, (_what)) 1320SN/A#define LE_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_mtx) 1330SN/A 1340SN/A/* 1350SN/A * Unfortunately, manual byte swapping is only necessary for the PCnet-PCI 1360SN/A * variants but not for the original LANCE or ILACC so we cannot do this 1370SN/A * with #ifdefs resolved at compile time. 1380SN/A */ 1390SN/A#define LE_HTOLE16(v) (((sc)->sc_flags & LE_BSWAP) ? htole16(v) : (v)) 1400SN/A#define LE_HTOLE32(v) (((sc)->sc_flags & LE_BSWAP) ? htole32(v) : (v)) 1410SN/A#define LE_LE16TOH(v) (((sc)->sc_flags & LE_BSWAP) ? le16toh(v) : (v)) 1420SN/A#define LE_LE32TOH(v) (((sc)->sc_flags & LE_BSWAP) ? le32toh(v) : (v)) 1430SN/A 1440SN/Aint lance_config(struct lance_softc *, const char*, int); 1450SN/Avoid lance_attach(struct lance_softc *); 1460SN/Avoid lance_detach(struct lance_softc *); 1470SN/Avoid lance_suspend(struct lance_softc *); 1480SN/Avoid lance_resume(struct lance_softc *); 1490SN/Avoid lance_init_locked(struct lance_softc *); 1500SN/Aint lance_put(struct lance_softc *, int, struct mbuf *); 1510SN/Astruct mbuf *lance_get(struct lance_softc *, int, int); 1520SN/Avoid lance_setladrf(struct lance_softc *, u_int16_t *); 1530SN/A 1540SN/A/* 1550SN/A * The following functions are only useful on certain CPU/bus 1560SN/A * combinations. They should be written in assembly language for 1570SN/A * maximum efficiency, but machine-independent versions are provided 1580SN/A * for drivers that have not yet been optimized. 1590SN/A */ 1600SN/Avoid lance_copytobuf_contig(struct lance_softc *, void *, int, int); 1610SN/Avoid lance_copyfrombuf_contig(struct lance_softc *, void *, int, int); 1620SN/Avoid lance_zerobuf_contig(struct lance_softc *, int, int); 1630SN/A 16412843Sprr#if 0 /* Example only - see lance.c */ 1650SN/Avoid lance_copytobuf_gap2(struct lance_softc *, void *, int, int); 1660SN/Avoid lance_copyfrombuf_gap2(struct lance_softc *, void *, int, int); 1670SN/Avoid lance_zerobuf_gap2(struct lance_softc *, int, int); 1680SN/A 1690SN/Avoid lance_copytobuf_gap16(struct lance_softc *, void *, int, int); 1700SN/Avoid lance_copyfrombuf_gap16(struct lance_softc *, void *, int, int); 1710SN/Avoid lance_zerobuf_gap16(struct lance_softc *, int, int); 1720SN/A#endif /* Example only */ 1730SN/A 1740SN/A/* 1750SN/A * Compare two Ether/802 addresses for equality, inlined and 1760SN/A * unrolled for speed. Use this like memcmp(). 1770SN/A * 1780SN/A * XXX: Add <machine/inlines.h> for stuff like this? 1790SN/A * XXX: or maybe add it to libkern.h instead? 1800SN/A * 1810SN/A * "I'd love to have an inline assembler version of this." 1820SN/A * XXX: Who wanted that? mycroft? I wrote one, but this 1830SN/A * version in C is as good as hand-coded assembly. -gwr 1840SN/A * 1850SN/A * Please do NOT tweak this without looking at the actual 1860SN/A * assembly code generated before and after your tweaks! 1870SN/A */ 1880SN/Astatic inline uint16_t 1890SN/Aether_cmp(void *one, void *two) 1900SN/A{ 1910SN/A uint16_t *a = (u_short *)one; 1920SN/A uint16_t *b = (u_short *)two; 1930SN/A uint16_t diff; 1940SN/A 1950SN/A#ifdef m68k 1960SN/A /* 1970SN/A * The post-increment-pointer form produces the best 1980SN/A * machine code for m68k. This was carefully tuned 1990SN/A * so it compiles to just 8 short (2-byte) op-codes! 2000SN/A */ 2010SN/A diff = *a++ - *b++; 2020SN/A diff |= *a++ - *b++; 2030SN/A diff |= *a++ - *b++; 2040SN/A#else 2050SN/A /* 2060SN/A * Most modern CPUs do better with a single expresion. 2070SN/A * Note that short-cut evaluation is NOT helpful here, 2080SN/A * because it just makes the code longer, not faster! 2090SN/A */ 2100SN/A diff = (a[0] - b[0]) | (a[1] - b[1]) | (a[2] - b[2]); 2110SN/A#endif 2120SN/A 2130SN/A return (diff); 2140SN/A} 2150SN/A 2160SN/A#endif /* _DEV_LE_LANCEVAR_H_ */ 2170SN/A