if_ie_gsc.c revision 1.4       1  1.4   msaitoh /*	$NetBSD: if_ie_gsc.c,v 1.4 2019/04/25 10:08:45 msaitoh Exp $	*/
      2  1.1     skrll 
      3  1.1     skrll /*	$OpenBSD: if_ie_gsc.c,v 1.6 2001/01/12 22:57:04 mickey Exp $	*/
      4  1.1     skrll 
      5  1.1     skrll /*
      6  1.1     skrll  * Copyright (c) 1998-2004 Michael Shalayeff
      7  1.1     skrll  * All rights reserved.
      8  1.1     skrll  *
      9  1.1     skrll  * Redistribution and use in source and binary forms, with or without
     10  1.1     skrll  * modification, are permitted provided that the following conditions
     11  1.1     skrll  * are met:
     12  1.1     skrll  * 1. Redistributions of source code must retain the above copyright
     13  1.1     skrll  *    notice, this list of conditions and the following disclaimer.
     14  1.1     skrll  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1     skrll  *    notice, this list of conditions and the following disclaimer in the
     16  1.1     skrll  *    documentation and/or other materials provided with the distribution.
     17  1.1     skrll  *
     18  1.1     skrll  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.1     skrll  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.1     skrll  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.1     skrll  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
     22  1.1     skrll  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     23  1.1     skrll  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     24  1.1     skrll  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25  1.1     skrll  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     26  1.1     skrll  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     27  1.1     skrll  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     28  1.1     skrll  * THE POSSIBILITY OF SUCH DAMAGE.
     29  1.1     skrll  */
     30  1.1     skrll 
     31  1.1     skrll /*
     32  1.1     skrll  * Referencies:
     33  1.2  dholland  * 1. 82596DX and 82596SX High-Performance 32-bit Local Area Network Coprocessor
     34  1.1     skrll  *    Intel Corporation, November 1996, Order Number: 290219-006
     35  1.1     skrll  *
     36  1.1     skrll  * 2. 712 I/O Subsystem ERS Rev 1.0
     37  1.1     skrll  *    Hewlett-Packard, June 17 1992, Dwg No. A-A2263-66510-31
     38  1.1     skrll  */
     39  1.1     skrll 
     40  1.1     skrll #include <sys/cdefs.h>
     41  1.4   msaitoh __KERNEL_RCSID(0, "$NetBSD: if_ie_gsc.c,v 1.4 2019/04/25 10:08:45 msaitoh Exp $");
     42  1.1     skrll 
     43  1.1     skrll #include <sys/param.h>
     44  1.1     skrll #include <sys/systm.h>
     45  1.1     skrll #include <sys/device.h>
     46  1.1     skrll #include <sys/socket.h>
     47  1.1     skrll #include <sys/sockio.h>
     48  1.1     skrll 
     49  1.1     skrll #include <uvm/uvm_extern.h>
     50  1.1     skrll 
     51  1.1     skrll #include <net/if.h>
     52  1.1     skrll #include <net/if_dl.h>
     53  1.1     skrll #include <net/if_ether.h>
     54  1.1     skrll #include <net/if_types.h>
     55  1.1     skrll #include <net/if_media.h>
     56  1.1     skrll 
     57  1.1     skrll #include <netinet/in.h>
     58  1.1     skrll 
     59  1.1     skrll #include <sys/bus.h>
     60  1.1     skrll #include <machine/intr.h>
     61  1.1     skrll #include <machine/iomod.h>
     62  1.1     skrll #include <machine/autoconf.h>
     63  1.1     skrll 
     64  1.1     skrll #include <hppa/dev/cpudevs.h>
     65  1.1     skrll #include <hppa/gsc/gscbusvar.h>
     66  1.1     skrll #include <hppa/hppa/machdep.h>
     67  1.1     skrll 
     68  1.1     skrll #include <dev/ic/i82586reg.h>
     69  1.1     skrll #include <dev/ic/i82586var.h>
     70  1.1     skrll 
     71  1.1     skrll #define	I82596_DEBUG	I82586_DEBUG
     72  1.1     skrll 
     73  1.1     skrll #ifdef __for_reference_only
     74  1.1     skrll struct ie_gsc_regs {
     75  1.1     skrll 	uint32_t	ie_reset;
     76  1.1     skrll 	uint32_t	ie_port;
     77  1.1     skrll 	uint32_t	ie_attn;
     78  1.1     skrll };
     79  1.1     skrll #endif
     80  1.1     skrll 
     81  1.1     skrll #define	IE_GSC_BANK_SZ		(12)
     82  1.1     skrll #define	IE_GSC_REG_RESET	(0)
     83  1.1     skrll #define	IE_GSC_REG_PORT		(4)
     84  1.1     skrll #define	IE_GSC_REG_ATTN		(8)
     85  1.1     skrll 
     86  1.1     skrll #define	IE_GSC_ALIGN(v)	((((u_int) (v)) + 0xf) & ~0xf)
     87  1.1     skrll 
     88  1.1     skrll #define	IE_GSC_SYSBUS	(IE_SYSBUS_596_RSVD_SET	| \
     89  1.1     skrll 			 IE_SYSBUS_596_82586	| \
     90  1.1     skrll 			 IE_SYSBUS_596_INTLOW	| \
     91  1.1     skrll 			 IE_SYSBUS_596_TRGEXT	| \
     92  1.1     skrll 			 IE_SYSBUS_596_BE)
     93  1.1     skrll 
     94  1.1     skrll #define	IE_SIZE	0x8000
     95  1.1     skrll 
     96  1.1     skrll struct ie_gsc_softc {
     97  1.1     skrll 	struct ie_softc ie;
     98  1.3     skrll 
     99  1.1     skrll 	/* tag and handle to hppa-specific adapter registers. */
    100  1.1     skrll 	bus_space_tag_t iot;
    101  1.1     skrll 	bus_space_handle_t ioh;
    102  1.1     skrll 
    103  1.1     skrll 	/* bus_dma_tag_t for the memory used by the adapter. */
    104  1.1     skrll 	bus_dma_tag_t iemt;
    105  1.1     skrll 
    106  1.1     skrll 	/* interrupt handle. */
    107  1.1     skrll 	void *sc_ih;
    108  1.1     skrll 
    109  1.1     skrll 	/* miscellaneous flags. */
    110  1.1     skrll 	int flags;
    111  1.1     skrll #define	IEGSC_GECKO	(1 << 0)
    112  1.1     skrll };
    113  1.1     skrll 
    114  1.1     skrll int	ie_gsc_probe(device_t, cfdata_t, void *);
    115  1.1     skrll void	ie_gsc_attach(device_t, device_t, void *);
    116  1.1     skrll 
    117  1.1     skrll CFATTACH_DECL_NEW(ie_gsc, sizeof(struct ie_gsc_softc),
    118  1.1     skrll     ie_gsc_probe, ie_gsc_attach, NULL, NULL);
    119  1.1     skrll 
    120  1.1     skrll static int ie_gsc_media[] = {
    121  1.1     skrll 	IFM_ETHER | IFM_10_2,
    122  1.1     skrll };
    123  1.4   msaitoh #define	IE_NMEDIA	__arraycount(ie_gsc_media)
    124  1.1     skrll 
    125  1.1     skrll void ie_gsc_reset(struct ie_softc *, int);
    126  1.1     skrll void ie_gsc_attend(struct ie_softc *, int);
    127  1.1     skrll void ie_gsc_run(struct ie_softc *);
    128  1.1     skrll void ie_gsc_port(struct ie_softc *, u_int);
    129  1.1     skrll uint16_t ie_gsc_read16(struct ie_softc *, int);
    130  1.1     skrll void ie_gsc_write16(struct ie_softc *, int, uint16_t);
    131  1.1     skrll void ie_gsc_write24(struct ie_softc *, int, int);
    132  1.1     skrll void ie_gsc_memcopyin(struct ie_softc *, void *, int, size_t);
    133  1.1     skrll void ie_gsc_memcopyout(struct ie_softc *, const void *, int, size_t);
    134  1.1     skrll 
    135  1.1     skrll 
    136  1.1     skrll /* Reset the adapter. */
    137  1.1     skrll void
    138  1.1     skrll ie_gsc_reset(struct ie_softc *sc, int what)
    139  1.1     skrll {
    140  1.4   msaitoh 	struct ie_gsc_softc *gsc = (struct ie_gsc_softc *)sc;
    141  1.1     skrll 	int i;
    142  1.3     skrll 
    143  1.1     skrll 	switch (what) {
    144  1.1     skrll 	case CHIP_PROBE:
    145  1.1     skrll 		bus_space_write_4(gsc->iot, gsc->ioh, IE_GSC_REG_RESET, 0);
    146  1.1     skrll 		break;
    147  1.1     skrll 
    148  1.1     skrll 	case CARD_RESET:
    149  1.1     skrll 		bus_space_write_4(gsc->iot, gsc->ioh, IE_GSC_REG_RESET, 0);
    150  1.1     skrll 
    151  1.1     skrll 		/*
    152  1.4   msaitoh 		 * Per [2] 4.6.2.1
    153  1.1     skrll 		 * delay for 10 system clocks + 5 transmit clocks,
    154  1.1     skrll 		 * NB: works for system clocks over 10MHz
    155  1.1     skrll 		 */
    156  1.1     skrll 		DELAY(1000);
    157  1.1     skrll 
    158  1.1     skrll 		/*
    159  1.4   msaitoh 		 * After the hardware reset:
    160  1.1     skrll 		 * inform i825[89]6 about new SCP address,
    161  1.1     skrll 		 * which must be at least 16-byte aligned
    162  1.1     skrll 		 */
    163  1.1     skrll 		ie_gsc_port(sc, IE_PORT_ALT_SCP);
    164  1.1     skrll 		ie_gsc_attend(sc, what);
    165  1.1     skrll 
    166  1.1     skrll 		for (i = 9000; i-- && ie_gsc_read16(sc, IE_ISCP_BUSY(sc->iscp));
    167  1.1     skrll 		     DELAY(100))
    168  1.4   msaitoh 			pdcache(0, (vaddr_t)sc->sc_maddr + sc->iscp,
    169  1.4   msaitoh 			    IE_ISCP_SZ);
    170  1.1     skrll 
    171  1.1     skrll #if I82596_DEBUG
    172  1.1     skrll 		if (i < 0) {
    173  1.1     skrll 			printf("timeout for PORT command (%x)%s\n",
    174  1.1     skrll 			       ie_gsc_read16(sc, IE_ISCP_BUSY(sc->iscp)),
    175  1.1     skrll 			       (gsc->flags & IEGSC_GECKO)? " on gecko":"");
    176  1.1     skrll 			return;
    177  1.1     skrll 		}
    178  1.1     skrll #endif
    179  1.1     skrll 		break;
    180  1.1     skrll 	}
    181  1.1     skrll }
    182  1.1     skrll 
    183  1.1     skrll /* Do a channel attention on the adapter. */
    184  1.1     skrll void
    185  1.1     skrll ie_gsc_attend(struct ie_softc *sc, int why)
    186  1.1     skrll {
    187  1.4   msaitoh 	struct ie_gsc_softc *gsc = (struct ie_gsc_softc *)sc;
    188  1.1     skrll 
    189  1.1     skrll 	bus_space_write_4(gsc->iot, gsc->ioh, IE_GSC_REG_ATTN, 0);
    190  1.1     skrll }
    191  1.1     skrll 
    192  1.1     skrll /* Enable the adapter. */
    193  1.1     skrll void
    194  1.1     skrll ie_gsc_run(struct ie_softc *sc)
    195  1.1     skrll {
    196  1.1     skrll }
    197  1.1     skrll 
    198  1.1     skrll /* Run an i82596 PORT command on the adapter. */
    199  1.1     skrll void
    200  1.1     skrll ie_gsc_port(struct ie_softc *sc, u_int cmd)
    201  1.1     skrll {
    202  1.4   msaitoh 	struct ie_gsc_softc *gsc = (struct ie_gsc_softc *)sc;
    203  1.1     skrll 
    204  1.1     skrll 	switch (cmd) {
    205  1.1     skrll 	case IE_PORT_RESET:
    206  1.1     skrll 	case IE_PORT_DUMP:
    207  1.1     skrll 		break;
    208  1.1     skrll 	case IE_PORT_SELF_TEST:
    209  1.1     skrll 		cmd |= (sc->sc_dmamap->dm_segs[0].ds_addr + 0);
    210  1.1     skrll 		break;
    211  1.1     skrll 	case IE_PORT_ALT_SCP:
    212  1.1     skrll 		cmd |= (sc->sc_dmamap->dm_segs[0].ds_addr + sc->scp);
    213  1.1     skrll 		break;
    214  1.1     skrll 	}
    215  1.1     skrll 
    216  1.1     skrll 	if (gsc->flags & IEGSC_GECKO) {
    217  1.1     skrll 		bus_space_write_4(gsc->iot, gsc->ioh,
    218  1.1     skrll 				  IE_GSC_REG_PORT, (cmd & 0xffff));
    219  1.1     skrll 		DELAY(1000);
    220  1.1     skrll 		bus_space_write_4(gsc->iot, gsc->ioh,
    221  1.1     skrll 				  IE_GSC_REG_PORT, (cmd >> 16));
    222  1.1     skrll 		DELAY(1000);
    223  1.1     skrll 	} else {
    224  1.1     skrll 		bus_space_write_4(gsc->iot, gsc->ioh,
    225  1.1     skrll 				  IE_GSC_REG_PORT, (cmd >> 16));
    226  1.1     skrll 		DELAY(1000);
    227  1.1     skrll 		bus_space_write_4(gsc->iot, gsc->ioh,
    228  1.1     skrll 				  IE_GSC_REG_PORT, (cmd & 0xffff));
    229  1.1     skrll 		DELAY(1000);
    230  1.1     skrll 	}
    231  1.1     skrll }
    232  1.1     skrll 
    233  1.1     skrll uint16_t
    234  1.1     skrll ie_gsc_read16(struct ie_softc *sc, int offset)
    235  1.1     skrll {
    236  1.1     skrll 	uint16_t val;
    237  1.1     skrll 
    238  1.1     skrll 	__asm volatile(
    239  1.1     skrll 	"	ldh	0(%1), %0	\n"
    240  1.1     skrll 	"	fdc	%%r0(%1)	\n"
    241  1.1     skrll 	: "=&r" (val)
    242  1.1     skrll 	: "r" ((char *)sc->sc_maddr + offset));
    243  1.4   msaitoh 	return val;
    244  1.1     skrll }
    245  1.1     skrll 
    246  1.1     skrll void
    247  1.1     skrll ie_gsc_write16(struct ie_softc *sc, int offset, uint16_t v)
    248  1.1     skrll {
    249  1.1     skrll 
    250  1.1     skrll 	__asm volatile(
    251  1.1     skrll 	"	sth	%0, 0(%1)	\n"
    252  1.1     skrll 	"	fdc	%%r0(%1)	\n"
    253  1.1     skrll 	: /* no outputs */
    254  1.1     skrll 	: "r" (v), "r" ((char *)sc->sc_maddr + offset));
    255  1.1     skrll }
    256  1.1     skrll 
    257  1.1     skrll void
    258  1.1     skrll ie_gsc_write24(struct ie_softc *sc, int offset, int addr)
    259  1.1     skrll {
    260  1.1     skrll 
    261  1.1     skrll 	/*
    262  1.1     skrll 	 * i82586.c assumes that the chip address space starts at
    263  1.1     skrll 	 * zero, so we have to add in the appropriate offset here.
    264  1.1     skrll 	 */
    265  1.1     skrll 	addr += sc->sc_dmamap->dm_segs[0].ds_addr;
    266  1.1     skrll 	__asm volatile(
    267  1.1     skrll 	"	ldi	2, %%r21		\n"
    268  1.1     skrll 	"	extru	%0, 15, 16, %%r22	\n"
    269  1.1     skrll 	"	sth	%0, 0(%1)		\n"
    270  1.1     skrll 	"	sth	%%r22, 2(%1)		\n"
    271  1.1     skrll 	"	fdc	%%r0(%1)		\n"
    272  1.1     skrll 	"	fdc	%%r21(%1)		\n"
    273  1.1     skrll 	: /* No outputs */
    274  1.1     skrll 	: "r" (addr), "r" ((char *)sc->sc_maddr + offset)
    275  1.1     skrll 	: "r21", "r22");
    276  1.1     skrll }
    277  1.1     skrll 
    278  1.1     skrll void
    279  1.1     skrll ie_gsc_memcopyin(struct ie_softc *sc, void *p, int offset, size_t size)
    280  1.1     skrll {
    281  1.4   msaitoh 	struct ie_gsc_softc *gsc = (struct ie_gsc_softc *)sc;
    282  1.1     skrll 
    283  1.1     skrll 	if (size == 0)
    284  1.1     skrll 		return;
    285  1.1     skrll 
    286  1.1     skrll 	memcpy(p, (char *)sc->sc_maddr + offset, size);
    287  1.1     skrll 	bus_dmamap_sync(gsc->iemt, sc->sc_dmamap, offset, size,
    288  1.1     skrll 			BUS_DMASYNC_PREREAD);
    289  1.1     skrll 	hppa_led_blink(HPPA_LED_NETRCV);
    290  1.1     skrll }
    291  1.1     skrll 
    292  1.1     skrll void
    293  1.1     skrll ie_gsc_memcopyout(struct ie_softc *sc, const void *p, int offset, size_t size)
    294  1.1     skrll {
    295  1.4   msaitoh 	struct ie_gsc_softc *gsc = (struct ie_gsc_softc *)sc;
    296  1.1     skrll 
    297  1.1     skrll 	if (size == 0)
    298  1.1     skrll 		return;
    299  1.1     skrll 
    300  1.1     skrll 	memcpy((char *)sc->sc_maddr + offset, p, size);
    301  1.1     skrll 	bus_dmamap_sync(gsc->iemt, sc->sc_dmamap, offset, size,
    302  1.1     skrll 			BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
    303  1.1     skrll 	hppa_led_blink(HPPA_LED_NETSND);
    304  1.1     skrll }
    305  1.1     skrll 
    306  1.1     skrll /*
    307  1.1     skrll  * i82596 probe routine
    308  1.1     skrll  */
    309  1.1     skrll int i82596_probe(struct ie_softc *);
    310  1.1     skrll int
    311  1.1     skrll i82596_probe(struct ie_softc *sc)
    312  1.1     skrll {
    313  1.4   msaitoh 	struct ie_gsc_softc *gsc = (struct ie_gsc_softc *)sc;
    314  1.1     skrll 	int i;
    315  1.1     skrll 
    316  1.1     skrll 	/* Set up the SCP. */
    317  1.1     skrll 	sc->ie_bus_write16(sc, IE_SCP_BUS_USE(sc->scp), IE_GSC_SYSBUS);
    318  1.1     skrll 	sc->ie_bus_write24(sc, IE_SCP_ISCP(sc->scp), sc->iscp);
    319  1.1     skrll 
    320  1.1     skrll 	/* Set up the ISCP. */
    321  1.1     skrll 	sc->ie_bus_write16(sc, IE_ISCP_SCB(sc->iscp), sc->scb);
    322  1.1     skrll 	sc->ie_bus_write24(sc, IE_ISCP_BASE(sc->iscp), 0);
    323  1.1     skrll 
    324  1.1     skrll 	/* Set BUSY in the ISCP. */
    325  1.1     skrll 	sc->ie_bus_write16(sc, IE_ISCP_BUSY(sc->iscp), 1);
    326  1.1     skrll 
    327  1.1     skrll 	/* Reset the adapter. */
    328  1.1     skrll 	bus_dmamap_sync(gsc->iemt, sc->sc_dmamap, 0, sc->sc_msize,
    329  1.1     skrll 			BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
    330  1.1     skrll 	sc->hwreset(sc, CARD_RESET);
    331  1.1     skrll 
    332  1.1     skrll 	/* Make sure that BUSY got cleared. */
    333  1.1     skrll 	if (sc->ie_bus_read16(sc, IE_ISCP_BUSY(sc->iscp))) {
    334  1.1     skrll #if I82596_DEBUG
    335  1.1     skrll 		printf ("%s: ISCP set failed\n", device_xname(sc->sc_dev));
    336  1.1     skrll #endif
    337  1.1     skrll 		return 0;
    338  1.1     skrll 	}
    339  1.1     skrll 
    340  1.1     skrll 	/* Run the chip self-test. */
    341  1.1     skrll 	sc->ie_bus_write24(sc, 0, -sc->sc_dmamap->dm_segs[0].ds_addr);
    342  1.1     skrll 	sc->ie_bus_write24(sc, 4, -(sc->sc_dmamap->dm_segs[0].ds_addr + 1));
    343  1.1     skrll 	bus_dmamap_sync(gsc->iemt, sc->sc_dmamap, 0, sc->sc_msize,
    344  1.1     skrll 			BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
    345  1.1     skrll 	ie_gsc_port(sc, IE_PORT_SELF_TEST);
    346  1.4   msaitoh 	for (i = 9000; i-- && sc->ie_bus_read16(sc, 4); DELAY(100))
    347  1.1     skrll 		pdcache(0, (vaddr_t)sc->sc_maddr, sc->sc_msize);
    348  1.1     skrll 
    349  1.1     skrll #if I82596_DEBUG
    350  1.1     skrll 	printf (": test %x:%x\n%s",
    351  1.1     skrll 		*((volatile int32_t *)((char *)sc->sc_maddr + 0)),
    352  1.1     skrll 		*((volatile int32_t *)((char *)sc->sc_maddr + 4)),
    353  1.1     skrll 		device_xname(sc->sc_dev));
    354  1.1     skrll #endif
    355  1.1     skrll 	return 1;
    356  1.1     skrll }
    357  1.1     skrll 
    358  1.1     skrll int
    359  1.1     skrll ie_gsc_probe(device_t parent, cfdata_t match, void *aux)
    360  1.1     skrll {
    361  1.1     skrll 	struct gsc_attach_args *ga = aux;
    362  1.1     skrll 
    363  1.1     skrll 	if (ga->ga_type.iodc_type != HPPA_TYPE_FIO ||
    364  1.1     skrll 	    (ga->ga_type.iodc_sv_model != HPPA_FIO_LAN &&
    365  1.1     skrll 	     ga->ga_type.iodc_sv_model != HPPA_FIO_GLAN))
    366  1.1     skrll 		return 0;
    367  1.1     skrll 
    368  1.1     skrll 	return 1;
    369  1.1     skrll }
    370  1.1     skrll 
    371  1.1     skrll void
    372  1.1     skrll ie_gsc_attach(device_t parent, device_t self, void *aux)
    373  1.1     skrll {
    374  1.1     skrll 	struct ie_gsc_softc *gsc = device_private(self);
    375  1.1     skrll 	struct ie_softc *sc = &gsc->ie;
    376  1.1     skrll 	struct gsc_attach_args *ga = aux;
    377  1.1     skrll 	bus_dma_segment_t seg;
    378  1.1     skrll 	int rseg;
    379  1.1     skrll 	int rv;
    380  1.1     skrll 	uint8_t myaddr[ETHER_ADDR_LEN];
    381  1.1     skrll #ifdef PMAPDEBUG
    382  1.1     skrll 	extern int pmapdebug;
    383  1.1     skrll 	int opmapdebug = pmapdebug;
    384  1.1     skrll 	pmapdebug = 0;
    385  1.1     skrll #endif
    386  1.1     skrll 
    387  1.1     skrll 	if (ga->ga_type.iodc_sv_model == HPPA_FIO_GLAN)
    388  1.1     skrll 		gsc->flags |= IEGSC_GECKO;
    389  1.1     skrll 
    390  1.4   msaitoh 	/* Map the GSC registers. */
    391  1.1     skrll 	if (bus_space_map(ga->ga_iot, ga->ga_hpa,
    392  1.1     skrll 			  IE_GSC_BANK_SZ, 0, &gsc->ioh)) {
    393  1.1     skrll 		printf(": can't map i/o space\n");
    394  1.1     skrll 		return;
    395  1.1     skrll 	}
    396  1.1     skrll 
    397  1.1     skrll 	/* Set up some initial glue. */
    398  1.1     skrll 	sc->sc_dev = self;
    399  1.1     skrll 	gsc->iot = ga->ga_iot;
    400  1.1     skrll 	gsc->iemt = ga->ga_dmatag;
    401  1.1     skrll 	sc->bt = ga->ga_iot;
    402  1.1     skrll 	sc->sc_msize = IE_SIZE;
    403  1.1     skrll 
    404  1.1     skrll 	/*
    405  1.1     skrll 	 * Allocate one contiguous segment of physical memory
    406  1.1     skrll 	 * to be used with the i82596.  Since we're running the
    407  1.1     skrll 	 * chip in i82586 mode, we're restricted to 24-bit
    408  1.1     skrll 	 * physical addresses.
    409  1.1     skrll 	 */
    410  1.1     skrll 	if (bus_dmamem_alloc(gsc->iemt, sc->sc_msize, PAGE_SIZE, 0,
    411  1.1     skrll 	    &seg, 1, &rseg, BUS_DMA_NOWAIT | BUS_DMA_24BIT)) {
    412  1.1     skrll 		printf (": can't allocate %d bytes of DMA memory\n",
    413  1.1     skrll 			sc->sc_msize);
    414  1.1     skrll 		return;
    415  1.1     skrll 	}
    416  1.1     skrll 
    417  1.4   msaitoh 	/* Map that physical memory into kernel virtual space. */
    418  1.1     skrll 	if (bus_dmamem_map(gsc->iemt, &seg, rseg, sc->sc_msize,
    419  1.1     skrll 			   (void **)&sc->sc_maddr, BUS_DMA_NOWAIT)) {
    420  1.1     skrll 		printf (": can't map DMA memory\n");
    421  1.1     skrll 		bus_dmamem_free(gsc->iemt, &seg, rseg);
    422  1.1     skrll 		return;
    423  1.1     skrll 	}
    424  1.1     skrll 
    425  1.4   msaitoh 	/* Create a DMA map for the memory. */
    426  1.1     skrll 	if (bus_dmamap_create(gsc->iemt, sc->sc_msize, rseg, sc->sc_msize,
    427  1.1     skrll 			      0, BUS_DMA_NOWAIT, &sc->sc_dmamap)) {
    428  1.1     skrll 		printf(": can't create DMA map\n");
    429  1.1     skrll 		bus_dmamem_unmap(gsc->iemt,
    430  1.1     skrll 				 (void *)sc->sc_maddr, sc->sc_msize);
    431  1.1     skrll 		bus_dmamem_free(gsc->iemt, &seg, rseg);
    432  1.1     skrll 		return;
    433  1.1     skrll 	}
    434  1.1     skrll 
    435  1.4   msaitoh 	/* Load the mapped DMA memory into the DMA map. */
    436  1.4   msaitoh 	if (bus_dmamap_load(gsc->iemt, sc->sc_dmamap, sc->sc_maddr,
    437  1.4   msaitoh 	    sc->sc_msize, NULL, BUS_DMA_NOWAIT)) {
    438  1.1     skrll 		printf(": can't load DMA map\n");
    439  1.1     skrll 		bus_dmamap_destroy(gsc->iemt, sc->sc_dmamap);
    440  1.1     skrll 		bus_dmamem_unmap(gsc->iemt,
    441  1.1     skrll 				 (void *)sc->sc_maddr, sc->sc_msize);
    442  1.1     skrll 		bus_dmamem_free(gsc->iemt, &seg, rseg);
    443  1.1     skrll 		return;
    444  1.1     skrll 	}
    445  1.1     skrll 
    446  1.1     skrll #if 1
    447  1.1     skrll 	/* XXX - this should go away. */
    448  1.4   msaitoh 	sc->bh = (bus_space_handle_t)sc->sc_maddr;
    449  1.1     skrll #endif
    450  1.1     skrll 
    451  1.1     skrll #if I82596_DEBUG
    452  1.1     skrll 	printf(" mem %x[%p]/%x\n%s",
    453  1.1     skrll 		(u_int)sc->sc_dmamap->dm_segs[0].ds_addr,
    454  1.1     skrll 		sc->sc_maddr,
    455  1.1     skrll 		sc->sc_msize,
    456  1.1     skrll 		device_xname(self));
    457  1.1     skrll 	sc->sc_debug = IED_ALL;
    458  1.1     skrll #endif
    459  1.1     skrll 
    460  1.1     skrll 	/* Initialize our bus glue. */
    461  1.1     skrll 	sc->hwreset = ie_gsc_reset;
    462  1.1     skrll 	sc->chan_attn = ie_gsc_attend;
    463  1.1     skrll 	sc->hwinit = ie_gsc_run;
    464  1.1     skrll 	sc->memcopyout = ie_gsc_memcopyout;
    465  1.1     skrll 	sc->memcopyin = ie_gsc_memcopyin;
    466  1.1     skrll 	sc->ie_bus_read16 = ie_gsc_read16;
    467  1.1     skrll 	sc->ie_bus_write16 = ie_gsc_write16;
    468  1.1     skrll 	sc->ie_bus_write24 = ie_gsc_write24;
    469  1.1     skrll 	sc->intrhook = NULL;
    470  1.1     skrll 
    471  1.1     skrll 	/* Clear all RAM. */
    472  1.1     skrll 	memset(sc->sc_maddr, 0, sc->sc_msize);
    473  1.1     skrll 	bus_dmamap_sync(gsc->iemt, sc->sc_dmamap, 0, sc->sc_msize,
    474  1.1     skrll 			BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
    475  1.1     skrll 
    476  1.1     skrll 	/*
    477  1.1     skrll 	 * We use low memory to set up SCP, ICSP and SCB data
    478  1.1     skrll 	 * structures. The remaining pages become the buffer area
    479  1.1     skrll 	 * (managed in i82586.c).
    480  1.1     skrll 	 */
    481  1.1     skrll 
    482  1.1     skrll 	/*
    483  1.1     skrll 	 * Since we have an i82596, we can control where where
    484  1.1     skrll 	 * the chip looks for SCP.  We plan to use the first
    485  1.1     skrll 	 * two 32-bit words of memory for the self-test, so the
    486  1.1     skrll 	 * SCP can go after that.
    487  1.1     skrll 	 */
    488  1.1     skrll 	sc->scp = IE_GSC_ALIGN(8);
    489  1.3     skrll 
    490  1.1     skrll 	/* ISCP follows SCP */
    491  1.1     skrll 	sc->iscp = IE_GSC_ALIGN(sc->scp + IE_SCP_SZ);
    492  1.1     skrll 
    493  1.1     skrll 	/* SCB follows ISCP */
    494  1.1     skrll 	sc->scb = IE_GSC_ALIGN(sc->iscp + IE_ISCP_SZ);
    495  1.1     skrll 
    496  1.1     skrll 	/* The remainder of the memory is for buffers. */
    497  1.1     skrll 	sc->buf_area = IE_GSC_ALIGN(sc->scb + IE_SCB_SZ);
    498  1.1     skrll 	sc->buf_area_sz = sc->sc_msize - sc->buf_area;
    499  1.1     skrll 
    500  1.1     skrll 	/* Finally, we can probe the chip. */
    501  1.1     skrll 	rv = i82596_probe(sc);
    502  1.1     skrll 	if (!rv) {
    503  1.1     skrll 		bus_dmamap_destroy(gsc->iemt, sc->sc_dmamap);
    504  1.1     skrll 		bus_dmamem_unmap(gsc->iemt,
    505  1.1     skrll 				 (void *)sc->sc_maddr, sc->sc_msize);
    506  1.1     skrll 		bus_dmamem_free(gsc->iemt, &seg, rseg);
    507  1.1     skrll 		return;
    508  1.1     skrll 	}
    509  1.1     skrll #ifdef PMAPDEBUG
    510  1.1     skrll 	pmapdebug = opmapdebug;
    511  1.1     skrll #endif
    512  1.1     skrll 	if (!rv)
    513  1.1     skrll 		return;
    514  1.1     skrll 
    515  1.1     skrll 	/* Get our Ethernet address. */
    516  1.1     skrll 	memcpy(myaddr, ga->ga_ether_address, ETHER_ADDR_LEN);
    517  1.1     skrll 
    518  1.1     skrll 	/* Set up the SCP. */
    519  1.1     skrll 	sc->ie_bus_write16(sc, IE_SCP_BUS_USE(sc->scp), IE_GSC_SYSBUS);
    520  1.1     skrll 	sc->ie_bus_write24(sc, IE_SCP_ISCP(sc->scp), sc->iscp);
    521  1.1     skrll 
    522  1.1     skrll 	/* Set up the ISCP. */
    523  1.1     skrll 	sc->ie_bus_write16(sc, IE_ISCP_SCB(sc->iscp), sc->scb);
    524  1.1     skrll 	sc->ie_bus_write24(sc, IE_ISCP_BASE(sc->iscp), 0);
    525  1.1     skrll 
    526  1.1     skrll 	/* Set BUSY in the ISCP. */
    527  1.1     skrll 	sc->ie_bus_write16(sc, IE_ISCP_BUSY(sc->iscp), 1);
    528  1.1     skrll 
    529  1.1     skrll 	/* Reset the adapter. */
    530  1.1     skrll 	bus_dmamap_sync(gsc->iemt, sc->sc_dmamap, 0, sc->sc_msize,
    531  1.1     skrll 			BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
    532  1.1     skrll 	sc->hwreset(sc, CARD_RESET);
    533  1.1     skrll 	bus_dmamap_sync(gsc->iemt, sc->sc_dmamap, 0, sc->sc_msize,
    534  1.1     skrll 			BUS_DMASYNC_PREREAD);
    535  1.1     skrll 
    536  1.1     skrll 	/* Now call the MI attachment. */
    537  1.1     skrll 	printf(": v%d.%d", ga->ga_type.iodc_model, ga->ga_type.iodc_sv_rev);
    538  1.1     skrll 	i82586_attach(sc,
    539  1.1     skrll 		      (gsc->flags & IEGSC_GECKO) ?
    540  1.1     skrll 		      "LASI/i82596CA" :
    541  1.1     skrll 		      "i82596DX",
    542  1.1     skrll 		      myaddr, ie_gsc_media, IE_NMEDIA, ie_gsc_media[0]);
    543  1.1     skrll 	gsc->sc_ih = hppa_intr_establish(IPL_NET, i82586_intr, sc,
    544  1.1     skrll 	    ga->ga_ir, ga->ga_irq);
    545  1.1     skrll }
    546