Home | History | Annotate | Line # | Download | only in dev
if_ie_vme.c revision 1.21.44.2
      1  1.21.44.2      yamt /*	$NetBSD: if_ie_vme.c,v 1.21.44.2 2009/05/04 08:12:00 yamt Exp $	*/
      2        1.1       gwr 
      3        1.5       gwr /*-
      4        1.5       gwr  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5        1.1       gwr  * All rights reserved.
      6        1.1       gwr  *
      7        1.5       gwr  * This code is derived from software contributed to The NetBSD Foundation
      8        1.5       gwr  * by Gordon W. Ross.
      9        1.5       gwr  *
     10        1.1       gwr  * Redistribution and use in source and binary forms, with or without
     11        1.1       gwr  * modification, are permitted provided that the following conditions
     12        1.1       gwr  * are met:
     13        1.1       gwr  * 1. Redistributions of source code must retain the above copyright
     14        1.1       gwr  *    notice, this list of conditions and the following disclaimer.
     15        1.1       gwr  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1       gwr  *    notice, this list of conditions and the following disclaimer in the
     17        1.1       gwr  *    documentation and/or other materials provided with the distribution.
     18        1.1       gwr  *
     19        1.5       gwr  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.5       gwr  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.5       gwr  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.7       gwr  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.7       gwr  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.5       gwr  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.5       gwr  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.5       gwr  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.5       gwr  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.5       gwr  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.5       gwr  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1       gwr  */
     31        1.1       gwr 
     32        1.1       gwr /*
     33        1.1       gwr  * Machine-dependent glue for the Intel Ethernet (ie) driver.
     34        1.1       gwr  */
     35       1.17     lukem 
     36       1.17     lukem #include <sys/cdefs.h>
     37  1.21.44.2      yamt __KERNEL_RCSID(0, "$NetBSD: if_ie_vme.c,v 1.21.44.2 2009/05/04 08:12:00 yamt Exp $");
     38       1.12  jonathan 
     39       1.12  jonathan #include "opt_inet.h"
     40        1.1       gwr 
     41        1.1       gwr #include <sys/param.h>
     42        1.1       gwr #include <sys/systm.h>
     43        1.1       gwr #include <sys/device.h>
     44        1.1       gwr #include <sys/protosw.h>
     45        1.1       gwr #include <sys/socket.h>
     46        1.1       gwr #include <net/if.h>
     47        1.8        is #include <net/if_ether.h>
     48        1.1       gwr 
     49        1.1       gwr #ifdef INET
     50        1.1       gwr #include <netinet/in.h>
     51        1.1       gwr #include <netinet/in_systm.h>
     52        1.1       gwr #include <netinet/in_var.h>
     53        1.1       gwr #include <netinet/ip.h>
     54        1.8        is #include <netinet/if_inarp.h>
     55        1.1       gwr #endif
     56        1.1       gwr 
     57        1.1       gwr #include <machine/autoconf.h>
     58        1.1       gwr #include <machine/cpu.h>
     59        1.1       gwr #include <machine/dvma.h>
     60        1.1       gwr #include <machine/idprom.h>
     61        1.1       gwr #include <machine/vmparam.h>
     62        1.1       gwr 
     63        1.1       gwr #include "i82586.h"
     64        1.2       gwr #include "if_iereg.h"
     65        1.2       gwr #include "if_ievar.h"
     66        1.1       gwr 
     67       1.18       chs static void ie_vmereset(struct ie_softc *);
     68       1.18       chs static void ie_vmeattend(struct ie_softc *);
     69       1.18       chs static void ie_vmerun(struct ie_softc *);
     70        1.1       gwr 
     71        1.1       gwr /*
     72        1.1       gwr  * zero/copy functions: OBIO can use the normal functions, but VME
     73        1.1       gwr  *    must do only byte or half-word (16 bit) accesses...
     74        1.1       gwr  */
     75       1.18       chs static void *wmemcpy(void *, const void *, size_t);
     76       1.18       chs static void *wmemset(void *, int, size_t);
     77        1.6       gwr 
     78        1.1       gwr 
     79        1.1       gwr /*
     80        1.1       gwr  * New-style autoconfig attachment
     81        1.1       gwr  */
     82        1.1       gwr 
     83  1.21.44.2      yamt static int  ie_vme_match(device_t, cfdata_t, void *);
     84  1.21.44.2      yamt static void ie_vme_attach(device_t, device_t, void *);
     85        1.1       gwr 
     86  1.21.44.2      yamt CFATTACH_DECL_NEW(ie_vme, sizeof(struct ie_softc),
     87       1.16   thorpej     ie_vme_match, ie_vme_attach, NULL, NULL);
     88        1.1       gwr 
     89       1.18       chs static int
     90  1.21.44.2      yamt ie_vme_match(device_t parent, cfdata_t cf, void *args)
     91        1.1       gwr {
     92        1.1       gwr 	struct confargs *ca = args;
     93        1.1       gwr 
     94        1.1       gwr 	/* No default VME address. */
     95        1.1       gwr 	if (ca->ca_paddr == -1)
     96  1.21.44.2      yamt 		return 0;
     97        1.1       gwr 
     98        1.9       gwr 	/* Make sure something is there... */
     99        1.9       gwr 	if (bus_peek(ca->ca_bustype, ca->ca_paddr, 2) == -1)
    100  1.21.44.2      yamt 		return 0;
    101        1.9       gwr 
    102        1.9       gwr 	/* Default interrupt priority. */
    103        1.1       gwr 	if (ca->ca_intpri == -1)
    104        1.1       gwr 		ca->ca_intpri = 3;
    105        1.1       gwr 
    106  1.21.44.2      yamt 	return 1;
    107        1.1       gwr }
    108        1.1       gwr 
    109        1.1       gwr /*
    110        1.1       gwr  * *note*: we don't detect the difference between a VME3E and
    111        1.1       gwr  * a multibus/vme card.   if you want to use a 3E you'll have
    112        1.1       gwr  * to fix this.
    113        1.1       gwr  */
    114       1.18       chs void
    115  1.21.44.2      yamt ie_vme_attach(device_t parent, device_t self, void *args)
    116        1.1       gwr {
    117  1.21.44.2      yamt 	struct ie_softc *sc = device_private(self);
    118        1.1       gwr 	struct confargs *ca = args;
    119        1.1       gwr 	volatile struct ievme *iev;
    120        1.1       gwr 	u_long  rampaddr;
    121        1.1       gwr 	int     lcv, off;
    122        1.1       gwr 
    123  1.21.44.2      yamt 	sc->sc_dev = self;
    124        1.1       gwr 	sc->hard_type = IE_VME;
    125        1.1       gwr 	sc->reset_586 = ie_vmereset;
    126        1.1       gwr 	sc->chan_attn = ie_vmeattend;
    127        1.1       gwr 	sc->run_586 = ie_vmerun;
    128       1.13   thorpej 	sc->sc_memcpy = wmemcpy;
    129       1.13   thorpej 	sc->sc_memset = wmemset;
    130        1.1       gwr 
    131        1.1       gwr 	/*
    132        1.1       gwr 	 * There is 64K of memory on the VME board.
    133        1.1       gwr 	 * (determined by hardware - NOT configurable!)
    134        1.1       gwr 	 */
    135        1.1       gwr 	sc->sc_msize = 0x10000; /* MEMSIZE 64K */
    136        1.1       gwr 
    137        1.1       gwr 	/* Map in the board control regs. */
    138        1.1       gwr 	sc->sc_reg = bus_mapin(ca->ca_bustype, ca->ca_paddr,
    139        1.1       gwr 						   sizeof(struct ievme));
    140        1.1       gwr 	iev = (volatile struct ievme *) sc->sc_reg;
    141        1.1       gwr 
    142        1.1       gwr 	/*
    143        1.1       gwr 	 * Find and map in the board memory.
    144        1.1       gwr 	 */
    145        1.1       gwr 	/* top 12 bits */
    146        1.1       gwr 	rampaddr = ca->ca_paddr & 0xfff00000;
    147        1.1       gwr 	/* 4 more */
    148        1.1       gwr 	rampaddr |= ((iev->status & IEVME_HADDR) << 16);
    149        1.1       gwr 	sc->sc_maddr = bus_mapin(ca->ca_bustype, rampaddr, sc->sc_msize);
    150        1.1       gwr 
    151        1.1       gwr 	/*
    152        1.1       gwr 	 * On this hardware, the i82586 address is just
    153        1.1       gwr 	 * masked to 16 bits, so sc_iobase == sc_maddr
    154        1.1       gwr 	 */
    155        1.1       gwr 	sc->sc_iobase = sc->sc_maddr;
    156        1.1       gwr 
    157        1.1       gwr 	/*
    158        1.1       gwr 	 * Set up on-board mapping registers for linear map.
    159        1.1       gwr 	 */
    160        1.1       gwr 	iev->pectrl |= IEVME_PARACK; /* clear to start */
    161        1.1       gwr 	for (lcv = 0; lcv < IEVME_MAPSZ; lcv++)
    162        1.1       gwr 		iev->pgmap[lcv] = IEVME_SBORDR | IEVME_OBMEM | lcv;
    163       1.13   thorpej 	(sc->sc_memset)(sc->sc_maddr, 0, sc->sc_msize);
    164        1.1       gwr 
    165        1.1       gwr 	/*
    166        1.1       gwr 	 * Set the System Configuration Pointer (SCP).
    167        1.1       gwr 	 * Its location is system-dependent because the
    168        1.1       gwr 	 * i82586 reads it from a fixed physical address.
    169        1.1       gwr 	 * On this hardware, the i82586 address is just
    170        1.1       gwr 	 * masked down to 16 bits, so the SCP is found
    171        1.1       gwr 	 * at the end of the RAM on the VME board.
    172        1.1       gwr 	 */
    173        1.1       gwr 	off = IE_SCP_ADDR & 0xFFFF;
    174       1.21   tsutsui 	sc->scp = (volatile void *)((char *)sc->sc_maddr + off);
    175        1.1       gwr 
    176        1.1       gwr 	/*
    177        1.1       gwr 	 * The rest of ram is used for buffers, etc.
    178        1.1       gwr 	 */
    179        1.1       gwr 	sc->buf_area = sc->sc_maddr;
    180        1.1       gwr 	sc->buf_area_sz = off;
    181        1.1       gwr 
    182        1.1       gwr 	/* Set the ethernet address. */
    183        1.1       gwr 	idprom_etheraddr(sc->sc_addr);
    184        1.1       gwr 
    185        1.1       gwr 	/* Do machine-independent parts of attach. */
    186        1.1       gwr 	ie_attach(sc);
    187        1.1       gwr 
    188        1.1       gwr 	/* Install interrupt handler. */
    189  1.21.44.2      yamt 	isr_add_vectored(ie_intr, sc, ca->ca_intpri, ca->ca_intvec);
    190        1.1       gwr }
    191        1.1       gwr 
    192        1.1       gwr 
    193        1.1       gwr /*
    194        1.1       gwr  * MULTIBUS/VME support
    195        1.1       gwr  */
    196       1.10       gwr 
    197       1.18       chs void
    198       1.18       chs ie_vmeattend(struct ie_softc *sc)
    199        1.1       gwr {
    200  1.21.44.2      yamt 	volatile struct ievme *iev = (struct ievme *)sc->sc_reg;
    201       1.10       gwr 
    202       1.10       gwr 	iev->status |= IEVME_ATTEN;	/* flag! */
    203       1.10       gwr 	iev->status &= ~IEVME_ATTEN;	/* down. */
    204        1.1       gwr }
    205        1.1       gwr 
    206       1.18       chs void
    207       1.18       chs ie_vmereset(struct ie_softc *sc)
    208        1.1       gwr {
    209  1.21.44.2      yamt 	volatile struct ievme *iev = (struct ievme *)sc->sc_reg;
    210        1.1       gwr 
    211       1.10       gwr 	iev->status = IEVME_RESET;
    212       1.10       gwr 	delay(20);
    213       1.10       gwr 	iev->status = (IEVME_ONAIR | IEVME_IENAB | IEVME_PEINT);
    214        1.1       gwr }
    215        1.1       gwr 
    216       1.18       chs void
    217       1.18       chs ie_vmerun(struct ie_softc *sc)
    218        1.1       gwr {
    219  1.21.44.2      yamt 
    220       1.10       gwr 	/* do it all in reset */
    221        1.1       gwr }
    222        1.1       gwr 
    223        1.1       gwr /*
    224       1.13   thorpej  * wmemcpy/wmemset - like memcpy/memset but largest access is 16-bits,
    225        1.1       gwr  * and also does byte swaps...
    226        1.1       gwr  * XXX - Would be nice to have asm versions in some library...
    227        1.1       gwr  */
    228        1.1       gwr 
    229       1.13   thorpej static void *
    230       1.18       chs wmemset(void *vb, int val, size_t l)
    231        1.1       gwr {
    232  1.21.44.2      yamt 	uint8_t *b = vb;
    233  1.21.44.2      yamt 	uint8_t *be = b + l;
    234  1.21.44.2      yamt 	uint16_t *sp;
    235        1.1       gwr 
    236        1.1       gwr 	if (l == 0)
    237  1.21.44.2      yamt 		return vb;
    238        1.1       gwr 
    239        1.1       gwr 	/* front, */
    240  1.21.44.2      yamt 	if ((uint32_t)b & 1)
    241       1.13   thorpej 		*b++ = val;
    242        1.1       gwr 
    243        1.1       gwr 	/* back, */
    244  1.21.44.2      yamt 	if (b != be && ((uint32_t)be & 1) != 0) {
    245        1.1       gwr 		be--;
    246       1.13   thorpej 		*be = val;
    247        1.1       gwr 	}
    248        1.1       gwr 
    249        1.1       gwr 	/* and middle. */
    250  1.21.44.2      yamt 	sp = (uint16_t *)b;
    251  1.21.44.2      yamt 	while (sp != (uint16_t *)be)
    252       1.13   thorpej 		*sp++ = val;
    253       1.13   thorpej 
    254  1.21.44.2      yamt 	return vb;
    255        1.1       gwr }
    256        1.1       gwr 
    257       1.13   thorpej static void *
    258       1.18       chs wmemcpy(void *dst, const void *src, size_t l)
    259        1.1       gwr {
    260  1.21.44.2      yamt 	const uint8_t *b1e, *b1 = src;
    261  1.21.44.2      yamt 	uint8_t *b2 = dst;
    262  1.21.44.2      yamt 	const uint16_t *sp;
    263        1.1       gwr 	int bstore = 0;
    264        1.1       gwr 
    265        1.1       gwr 	if (l == 0)
    266  1.21.44.2      yamt 		return dst;
    267        1.1       gwr 
    268        1.1       gwr 	/* front, */
    269  1.21.44.2      yamt 	if ((uint32_t)b1 & 1) {
    270        1.1       gwr 		*b2++ = *b1++;
    271        1.1       gwr 		l--;
    272        1.1       gwr 	}
    273        1.1       gwr 
    274        1.1       gwr 	/* middle, */
    275  1.21.44.2      yamt 	sp = (const uint16_t *)b1;
    276        1.1       gwr 	b1e = b1 + l;
    277        1.1       gwr 	if (l & 1)
    278        1.1       gwr 		b1e--;
    279  1.21.44.2      yamt 	bstore = (uint32_t)b2 & 1;
    280        1.1       gwr 
    281  1.21.44.2      yamt 	while (sp < (const uint16_t *)b1e) {
    282        1.1       gwr 		if (bstore) {
    283        1.1       gwr 			b2[1] = *sp & 0xff;
    284        1.1       gwr 			b2[0] = *sp >> 8;
    285        1.1       gwr 		} else
    286  1.21.44.2      yamt 			*((uint16_t *)b2) = *sp;
    287        1.1       gwr 		sp++;
    288        1.1       gwr 		b2 += 2;
    289        1.1       gwr 	}
    290        1.1       gwr 
    291        1.1       gwr 	/* and back. */
    292        1.1       gwr 	if (l & 1)
    293        1.1       gwr 		*b2 = *b1e;
    294       1.13   thorpej 
    295  1.21.44.2      yamt 	return dst;
    296        1.1       gwr }
    297