Home | History | Annotate | Line # | Download | only in dev
if_mc.c revision 1.13.20.1
      1  1.13.20.1      yamt /*	$NetBSD: if_mc.c,v 1.13.20.1 2009/05/04 08:11:28 yamt Exp $	*/
      2        1.1    tsubai 
      3        1.1    tsubai /*-
      4        1.1    tsubai  * Copyright (c) 1997 David Huang <khym (at) bga.com>
      5        1.1    tsubai  * All rights reserved.
      6        1.1    tsubai  *
      7        1.1    tsubai  * Portions of this code are based on code by Denton Gentry <denny1 (at) home.com>
      8        1.1    tsubai  * and Yanagisawa Takeshi <yanagisw (at) aa.ap.titech.ac.jp>.
      9        1.1    tsubai  *
     10        1.1    tsubai  * Redistribution and use in source and binary forms, with or without
     11        1.1    tsubai  * modification, are permitted provided that the following conditions
     12        1.1    tsubai  * are met:
     13        1.1    tsubai  * 1. Redistributions of source code must retain the above copyright
     14        1.1    tsubai  *    notice, this list of conditions and the following disclaimer.
     15        1.1    tsubai  * 2. The name of the author may not be used to endorse or promote products
     16        1.1    tsubai  *    derived from this software without specific prior written permission
     17        1.1    tsubai  *
     18        1.1    tsubai  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19        1.1    tsubai  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20        1.1    tsubai  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21        1.1    tsubai  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22        1.1    tsubai  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23        1.1    tsubai  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24        1.1    tsubai  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25        1.1    tsubai  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26        1.1    tsubai  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27        1.1    tsubai  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28        1.1    tsubai  *
     29        1.1    tsubai  */
     30        1.1    tsubai 
     31        1.1    tsubai /*
     32        1.1    tsubai  * Bus attachment and DMA routines for the mc driver (Centris/Quadra
     33        1.1    tsubai  * 660av and Quadra 840av onboard ethernet, based on the AMD Am79C940
     34        1.1    tsubai  * MACE ethernet chip). Also uses the PSC (Peripheral Subsystem
     35        1.1    tsubai  * Controller) for DMA to and from the MACE.
     36        1.1    tsubai  */
     37        1.9     lukem 
     38        1.9     lukem #include <sys/cdefs.h>
     39  1.13.20.1      yamt __KERNEL_RCSID(0, "$NetBSD: if_mc.c,v 1.13.20.1 2009/05/04 08:11:28 yamt Exp $");
     40        1.1    tsubai 
     41        1.1    tsubai #include <sys/param.h>
     42        1.1    tsubai #include <sys/device.h>
     43        1.1    tsubai #include <sys/malloc.h>
     44        1.1    tsubai #include <sys/socket.h>
     45        1.1    tsubai #include <sys/systm.h>
     46        1.1    tsubai 
     47        1.1    tsubai #include <net/if.h>
     48        1.1    tsubai #include <net/if_ether.h>
     49        1.1    tsubai #include <net/if_media.h>
     50        1.1    tsubai 
     51        1.3       mrg #include <uvm/uvm_extern.h>
     52        1.1    tsubai 
     53        1.1    tsubai #include <dev/ofw/openfirm.h>
     54        1.1    tsubai 
     55        1.1    tsubai #include <machine/bus.h>
     56        1.1    tsubai #include <machine/autoconf.h>
     57       1.13   garbled #include <machine/pio.h>
     58        1.1    tsubai 
     59        1.1    tsubai #include <macppc/dev/am79c950reg.h>
     60        1.1    tsubai #include <macppc/dev/if_mcvar.h>
     61        1.1    tsubai 
     62        1.1    tsubai #define MC_BUFSIZE 0x800
     63        1.1    tsubai 
     64  1.13.20.1      yamt hide int	mc_match(struct device *, struct cfdata *, void *);
     65  1.13.20.1      yamt hide void	mc_attach(struct device *, struct device *, void *);
     66  1.13.20.1      yamt hide void	mc_init(struct mc_softc *sc);
     67  1.13.20.1      yamt hide void	mc_putpacket(struct mc_softc *sc, u_int len);
     68  1.13.20.1      yamt hide int	mc_dmaintr(void *arg);
     69  1.13.20.1      yamt hide void	mc_reset_rxdma(struct mc_softc *sc);
     70  1.13.20.1      yamt hide void	mc_reset_txdma(struct mc_softc *sc);
     71  1.13.20.1      yamt hide void	mc_select_utp(struct mc_softc *sc);
     72  1.13.20.1      yamt hide void	mc_select_aui(struct mc_softc *sc);
     73  1.13.20.1      yamt hide int	mc_mediachange(struct mc_softc *sc);
     74  1.13.20.1      yamt hide void	mc_mediastatus(struct mc_softc *sc, struct ifmediareq *);
     75        1.1    tsubai 
     76        1.1    tsubai int mc_supmedia[] = {
     77        1.1    tsubai 	IFM_ETHER | IFM_10_T,
     78        1.1    tsubai 	IFM_ETHER | IFM_10_5,
     79        1.1    tsubai 	/*IFM_ETHER | IFM_AUTO,*/
     80        1.1    tsubai };
     81        1.1    tsubai 
     82        1.1    tsubai #define N_SUPMEDIA (sizeof(mc_supmedia) / sizeof(int));
     83        1.1    tsubai 
     84        1.7   thorpej CFATTACH_DECL(mc, sizeof(struct mc_softc),
     85        1.7   thorpej     mc_match, mc_attach, NULL, NULL);
     86        1.1    tsubai 
     87        1.1    tsubai hide int
     88  1.13.20.1      yamt mc_match(struct device *parent, struct cfdata *cf, void *aux)
     89        1.1    tsubai {
     90        1.1    tsubai 	struct confargs *ca = aux;
     91        1.1    tsubai 
     92        1.1    tsubai 	if (strcmp(ca->ca_name, "mace") != 0)
     93        1.1    tsubai 		return 0;
     94        1.1    tsubai 
     95        1.1    tsubai 	/* requires 6 regs */
     96        1.1    tsubai 	if (ca->ca_nreg / sizeof(int) != 6)
     97        1.1    tsubai 		return 0;
     98        1.1    tsubai 
     99        1.1    tsubai 	/* requires 3 intrs */
    100        1.1    tsubai 	if (ca->ca_nintr / sizeof(int) != 3)
    101        1.1    tsubai 		return 0;
    102        1.1    tsubai 
    103        1.1    tsubai 	return 1;
    104        1.1    tsubai }
    105        1.1    tsubai 
    106        1.1    tsubai hide void
    107  1.13.20.1      yamt mc_attach(struct device *parent, struct device *self, void *aux)
    108        1.1    tsubai {
    109        1.1    tsubai 	struct confargs *ca = aux;
    110        1.1    tsubai 	struct mc_softc *sc = (struct mc_softc *)self;
    111        1.1    tsubai 	u_int8_t myaddr[ETHER_ADDR_LEN];
    112        1.1    tsubai 	u_int *reg;
    113        1.1    tsubai 
    114        1.1    tsubai 	sc->sc_node = ca->ca_node;
    115  1.13.20.1      yamt 	sc->sc_regt = ca->ca_tag;
    116        1.1    tsubai 
    117        1.1    tsubai 	reg  = ca->ca_reg;
    118        1.1    tsubai 	reg[0] += ca->ca_baseaddr;
    119        1.1    tsubai 	reg[2] += ca->ca_baseaddr;
    120        1.1    tsubai 	reg[4] += ca->ca_baseaddr;
    121        1.1    tsubai 
    122        1.1    tsubai 	sc->sc_txdma = mapiodev(reg[2], reg[3]);
    123        1.1    tsubai 	sc->sc_rxdma = mapiodev(reg[4], reg[5]);
    124        1.1    tsubai 	bus_space_map(sc->sc_regt, reg[0], reg[1], 0, &sc->sc_regh);
    125  1.13.20.1      yamt 
    126        1.1    tsubai 	sc->sc_tail = 0;
    127        1.1    tsubai 	sc->sc_txdmacmd = dbdma_alloc(sizeof(dbdma_command_t) * 2);
    128        1.1    tsubai 	sc->sc_rxdmacmd = (void *)dbdma_alloc(sizeof(dbdma_command_t) * 8);
    129        1.5       wiz 	memset(sc->sc_txdmacmd, 0, sizeof(dbdma_command_t) * 2);
    130        1.5       wiz 	memset(sc->sc_rxdmacmd, 0, sizeof(dbdma_command_t) * 8);
    131        1.1    tsubai 
    132        1.1    tsubai 	printf(": irq %d,%d,%d",
    133        1.1    tsubai 		ca->ca_intr[0], ca->ca_intr[1], ca->ca_intr[2]);
    134        1.1    tsubai 
    135        1.1    tsubai 	if (OF_getprop(sc->sc_node, "local-mac-address", myaddr, 6) != 6) {
    136        1.1    tsubai 		printf(": failed to get MAC address.\n");
    137        1.1    tsubai 		return;
    138        1.1    tsubai 	}
    139        1.1    tsubai 
    140        1.1    tsubai 	/* allocate memory for transmit buffer and mark it non-cacheable */
    141        1.8   thorpej 	sc->sc_txbuf = malloc(PAGE_SIZE, M_DEVBUF, M_WAITOK);
    142        1.1    tsubai 	sc->sc_txbuf_phys = kvtop(sc->sc_txbuf);
    143        1.8   thorpej 	memset(sc->sc_txbuf, 0, PAGE_SIZE);
    144        1.1    tsubai 
    145        1.1    tsubai 	/*
    146        1.1    tsubai 	 * allocate memory for receive buffer and mark it non-cacheable
    147        1.1    tsubai 	 * XXX This should use the bus_dma interface, since the buffer
    148        1.1    tsubai 	 * needs to be physically contiguous. However, it seems that
    149        1.1    tsubai 	 * at least on my system, malloc() does allocate contiguous
    150        1.1    tsubai 	 * memory. If it's not, suggest reducing the number of buffers
    151        1.1    tsubai 	 * to 2, which will fit in one 4K page.
    152        1.1    tsubai 	 */
    153        1.8   thorpej 	sc->sc_rxbuf = malloc(MC_NPAGES * PAGE_SIZE, M_DEVBUF, M_WAITOK);
    154        1.1    tsubai 	sc->sc_rxbuf_phys = kvtop(sc->sc_rxbuf);
    155        1.8   thorpej 	memset(sc->sc_rxbuf, 0, MC_NPAGES * PAGE_SIZE);
    156        1.1    tsubai 
    157        1.1    tsubai 	if ((int)sc->sc_txbuf & PGOFSET)
    158        1.1    tsubai 		printf("txbuf is not page-aligned\n");
    159        1.1    tsubai 	if ((int)sc->sc_rxbuf & PGOFSET)
    160        1.1    tsubai 		printf("rxbuf is not page-aligned\n");
    161        1.1    tsubai 
    162        1.1    tsubai 	sc->sc_bus_init = mc_init;
    163        1.1    tsubai 	sc->sc_putpacket = mc_putpacket;
    164        1.1    tsubai 
    165        1.1    tsubai 
    166        1.1    tsubai 	/* disable receive DMA */
    167        1.1    tsubai 	dbdma_reset(sc->sc_rxdma);
    168        1.1    tsubai 
    169        1.1    tsubai 	/* disable transmit DMA */
    170        1.1    tsubai 	dbdma_reset(sc->sc_txdma);
    171        1.1    tsubai 
    172        1.1    tsubai 	/* install interrupt handlers */
    173       1.13   garbled 	/*intr_establish(ca->ca_intr[1], IST_EDGE, IPL_NET, mc_dmaintr, sc);*/
    174       1.13   garbled 	intr_establish(ca->ca_intr[2], IST_EDGE, IPL_NET, mc_dmaintr, sc);
    175       1.13   garbled 	intr_establish(ca->ca_intr[0], IST_EDGE, IPL_NET, mcintr, sc);
    176        1.1    tsubai 
    177        1.1    tsubai 	sc->sc_biucc = XMTSP_64;
    178        1.1    tsubai 	sc->sc_fifocc = XMTFW_16 | RCVFW_64 | XMTFWU | RCVFWU |
    179        1.1    tsubai 	    XMTBRST | RCVBRST;
    180        1.1    tsubai 	/*sc->sc_plscc = PORTSEL_10BT;*/
    181        1.1    tsubai 	sc->sc_plscc = PORTSEL_GPSI | ENPLSIO;
    182        1.1    tsubai 
    183        1.1    tsubai 	/* mcsetup returns 1 if something fails */
    184        1.1    tsubai 	if (mcsetup(sc, myaddr)) {
    185        1.1    tsubai 		printf("mcsetup returns non zero\n");
    186        1.1    tsubai 		return;
    187        1.1    tsubai 	}
    188        1.1    tsubai #ifdef NOTYET
    189        1.1    tsubai 	sc->sc_mediachange = mc_mediachange;
    190        1.1    tsubai 	sc->sc_mediastatus = mc_mediastatus;
    191        1.1    tsubai 	sc->sc_supmedia = mc_supmedia;
    192        1.1    tsubai 	sc->sc_nsupmedia = N_SUPMEDIA;
    193        1.1    tsubai 	sc->sc_defaultmedia = IFM_ETHER | IFM_10_T;
    194        1.1    tsubai #endif
    195        1.1    tsubai }
    196        1.1    tsubai 
    197        1.1    tsubai /* Bus-specific initialization */
    198        1.1    tsubai hide void
    199  1.13.20.1      yamt mc_init(struct mc_softc *sc)
    200        1.1    tsubai {
    201        1.1    tsubai 	mc_reset_rxdma(sc);
    202        1.1    tsubai 	mc_reset_txdma(sc);
    203        1.1    tsubai }
    204        1.1    tsubai 
    205        1.1    tsubai hide void
    206  1.13.20.1      yamt mc_putpacket(struct mc_softc *sc, u_int len)
    207        1.1    tsubai {
    208        1.1    tsubai 	dbdma_command_t *cmd = sc->sc_txdmacmd;
    209        1.1    tsubai 
    210        1.1    tsubai 	DBDMA_BUILD(cmd, DBDMA_CMD_OUT_LAST, 0, len, sc->sc_txbuf_phys,
    211        1.1    tsubai 		DBDMA_INT_NEVER, DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER);
    212        1.1    tsubai 
    213        1.1    tsubai 	dbdma_start(sc->sc_txdma, sc->sc_txdmacmd);
    214        1.1    tsubai }
    215        1.1    tsubai 
    216        1.1    tsubai /*
    217        1.1    tsubai  * Interrupt handler for the MACE DMA completion interrupts
    218        1.1    tsubai  */
    219        1.1    tsubai int
    220  1.13.20.1      yamt mc_dmaintr(void *arg)
    221        1.1    tsubai {
    222        1.1    tsubai 	struct mc_softc *sc = arg;
    223        1.1    tsubai 	int status, offset, statoff;
    224        1.1    tsubai 	int datalen, resid;
    225        1.1    tsubai 	int i, n;
    226        1.1    tsubai 	dbdma_command_t *cmd;
    227        1.1    tsubai 
    228        1.1    tsubai 	/* We've received some packets from the MACE */
    229        1.1    tsubai 
    230        1.1    tsubai 	/* Loop through, processing each of the packets */
    231        1.1    tsubai 	i = sc->sc_tail;
    232        1.1    tsubai 	for (n = 0; n < MC_RXDMABUFS; n++, i++) {
    233        1.1    tsubai 		if (i == MC_RXDMABUFS)
    234        1.1    tsubai 			i = 0;
    235        1.1    tsubai 
    236        1.1    tsubai 		cmd = &sc->sc_rxdmacmd[i];
    237        1.2    tsubai 		/* flushcache(cmd, sizeof(dbdma_command_t)); */
    238       1.13   garbled 		status = in16rb(&cmd->d_status);
    239       1.13   garbled 		resid = in16rb(&cmd->d_resid);
    240        1.1    tsubai 
    241        1.1    tsubai 		/*if ((status & D_ACTIVE) == 0)*/
    242        1.1    tsubai 		if ((status & 0x40) == 0)
    243        1.1    tsubai 			continue;
    244        1.1    tsubai 
    245        1.1    tsubai #if 1
    246       1.13   garbled 		if (in16rb(&cmd->d_count) != ETHERMTU + 22)
    247        1.1    tsubai 			printf("bad d_count\n");
    248        1.1    tsubai #endif
    249        1.1    tsubai 
    250       1.13   garbled 		datalen = in16rb(&cmd->d_count) - resid;
    251        1.1    tsubai 		datalen -= 4;	/* 4 == status bytes */
    252        1.1    tsubai 
    253        1.1    tsubai 		if (datalen < 4 + sizeof(struct ether_header)) {
    254        1.1    tsubai 			printf("short packet len=%d\n", datalen);
    255        1.1    tsubai 			/* continue; */
    256        1.1    tsubai 			goto next;
    257        1.1    tsubai 		}
    258        1.1    tsubai 
    259        1.1    tsubai 		offset = i * MC_BUFSIZE;
    260        1.1    tsubai 		statoff = offset + datalen;
    261        1.1    tsubai 
    262        1.1    tsubai 		DBDMA_BUILD_CMD(cmd, DBDMA_CMD_STOP, 0, 0, 0, 0);
    263       1.11     perry 		__asm volatile("eieio");
    264        1.1    tsubai 
    265        1.2    tsubai 		/* flushcache(sc->sc_rxbuf + offset, datalen + 4); */
    266        1.2    tsubai 
    267        1.1    tsubai 		sc->sc_rxframe.rx_rcvcnt = sc->sc_rxbuf[statoff + 0];
    268        1.1    tsubai 		sc->sc_rxframe.rx_rcvsts = sc->sc_rxbuf[statoff + 1];
    269        1.1    tsubai 		sc->sc_rxframe.rx_rntpc  = sc->sc_rxbuf[statoff + 2];
    270        1.1    tsubai 		sc->sc_rxframe.rx_rcvcc  = sc->sc_rxbuf[statoff + 3];
    271        1.1    tsubai 		sc->sc_rxframe.rx_frame  = sc->sc_rxbuf + offset;
    272        1.1    tsubai 
    273        1.1    tsubai 		mc_rint(sc);
    274        1.1    tsubai 
    275        1.1    tsubai next:
    276        1.1    tsubai 		DBDMA_BUILD_CMD(cmd, DBDMA_CMD_IN_LAST, 0, DBDMA_INT_ALWAYS,
    277        1.1    tsubai 			DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER);
    278       1.11     perry 		__asm volatile("eieio");
    279        1.1    tsubai 		cmd->d_status = 0;
    280        1.1    tsubai 		cmd->d_resid = 0;
    281        1.1    tsubai 		sc->sc_tail = i + 1;
    282        1.1    tsubai 	}
    283        1.1    tsubai 
    284        1.1    tsubai 	dbdma_continue(sc->sc_rxdma);
    285        1.1    tsubai 
    286        1.1    tsubai 	return 1;
    287        1.1    tsubai }
    288        1.1    tsubai 
    289        1.1    tsubai hide void
    290  1.13.20.1      yamt mc_reset_rxdma(struct mc_softc *sc)
    291        1.1    tsubai {
    292        1.1    tsubai 	dbdma_command_t *cmd = sc->sc_rxdmacmd;
    293        1.1    tsubai 	dbdma_regmap_t *dmareg = sc->sc_rxdma;
    294        1.1    tsubai 	int i;
    295        1.1    tsubai 	u_int8_t maccc;
    296        1.1    tsubai 
    297        1.1    tsubai 	/* Disable receiver, reset the DMA channels */
    298        1.1    tsubai 	maccc = NIC_GET(sc, MACE_MACCC);
    299        1.1    tsubai 	NIC_PUT(sc, MACE_MACCC, maccc & ~ENRCV);
    300        1.1    tsubai 
    301        1.1    tsubai 	dbdma_reset(dmareg);
    302        1.1    tsubai 
    303        1.1    tsubai 	for (i = 0; i < MC_RXDMABUFS; i++) {
    304        1.1    tsubai 		DBDMA_BUILD(cmd, DBDMA_CMD_IN_LAST, 0, ETHERMTU + 22,
    305        1.1    tsubai 			sc->sc_rxbuf_phys + MC_BUFSIZE * i, DBDMA_INT_ALWAYS,
    306        1.1    tsubai 			DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER);
    307        1.1    tsubai 		cmd++;
    308        1.1    tsubai 	}
    309        1.1    tsubai 
    310        1.1    tsubai 	DBDMA_BUILD(cmd, DBDMA_CMD_NOP, 0, 0, 0,
    311        1.1    tsubai 		DBDMA_INT_NEVER, DBDMA_WAIT_NEVER, DBDMA_BRANCH_ALWAYS);
    312       1.13   garbled 	out32rb(&cmd->d_cmddep, kvtop((void *)sc->sc_rxdmacmd));
    313        1.1    tsubai 	cmd++;
    314        1.1    tsubai 
    315        1.1    tsubai 	dbdma_start(dmareg, sc->sc_rxdmacmd);
    316        1.1    tsubai 
    317        1.1    tsubai 	sc->sc_tail = 0;
    318        1.1    tsubai 
    319        1.1    tsubai 	/* Reenable receiver, reenable DMA */
    320        1.1    tsubai 	NIC_PUT(sc, MACE_MACCC, maccc);
    321        1.1    tsubai }
    322        1.1    tsubai 
    323        1.1    tsubai hide void
    324  1.13.20.1      yamt mc_reset_txdma(struct mc_softc *sc)
    325        1.1    tsubai {
    326        1.1    tsubai 	dbdma_command_t *cmd = sc->sc_txdmacmd;
    327        1.1    tsubai 	dbdma_regmap_t *dmareg = sc->sc_txdma;
    328        1.1    tsubai 	u_int8_t maccc;
    329        1.1    tsubai 
    330        1.1    tsubai 	/* disable transmitter */
    331        1.1    tsubai 	maccc = NIC_GET(sc, MACE_MACCC);
    332        1.1    tsubai 	NIC_PUT(sc, MACE_MACCC, maccc & ~ENXMT);
    333        1.1    tsubai 
    334        1.1    tsubai 	dbdma_reset(dmareg);
    335        1.1    tsubai 
    336        1.1    tsubai 	DBDMA_BUILD(cmd, DBDMA_CMD_OUT_LAST, 0, 0, sc->sc_txbuf_phys,
    337        1.1    tsubai 		DBDMA_INT_NEVER, DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER);
    338        1.1    tsubai 	cmd++;
    339        1.1    tsubai 	DBDMA_BUILD(cmd, DBDMA_CMD_STOP, 0, 0, 0,
    340        1.1    tsubai 		DBDMA_INT_NEVER, DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER);
    341        1.1    tsubai 
    342        1.1    tsubai 	out32rb(&dmareg->d_cmdptrhi, 0);
    343       1.12  christos 	out32rb(&dmareg->d_cmdptrlo, kvtop((void *)sc->sc_txdmacmd));
    344        1.1    tsubai 
    345        1.1    tsubai 	/* restore old value */
    346        1.1    tsubai 	NIC_PUT(sc, MACE_MACCC, maccc);
    347        1.1    tsubai }
    348        1.1    tsubai 
    349        1.1    tsubai void
    350  1.13.20.1      yamt mc_select_utp(struct mc_softc *sc)
    351        1.1    tsubai {
    352        1.1    tsubai 	sc->sc_plscc = PORTSEL_GPSI | ENPLSIO;
    353        1.1    tsubai }
    354        1.1    tsubai 
    355        1.1    tsubai void
    356  1.13.20.1      yamt mc_select_aui(struct mc_softc *sc)
    357        1.1    tsubai {
    358        1.1    tsubai 	sc->sc_plscc = PORTSEL_AUI;
    359        1.1    tsubai }
    360        1.1    tsubai 
    361        1.1    tsubai int
    362  1.13.20.1      yamt mc_mediachange(struct mc_softc *sc)
    363        1.1    tsubai {
    364        1.1    tsubai 	struct ifmedia *ifm = &sc->sc_media;
    365        1.1    tsubai 
    366        1.1    tsubai 	if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
    367        1.1    tsubai 		return EINVAL;
    368        1.1    tsubai 
    369        1.1    tsubai 	switch (IFM_SUBTYPE(ifm->ifm_media)) {
    370        1.1    tsubai 
    371        1.1    tsubai 	case IFM_10_T:
    372        1.1    tsubai 		mc_select_utp(sc);
    373        1.1    tsubai 		break;
    374        1.1    tsubai 
    375        1.1    tsubai 	case IFM_10_5:
    376        1.1    tsubai 		mc_select_aui(sc);
    377        1.1    tsubai 		break;
    378        1.1    tsubai 
    379        1.1    tsubai 	default:
    380        1.1    tsubai 		return EINVAL;
    381        1.1    tsubai 	}
    382        1.1    tsubai 
    383        1.1    tsubai 	return 0;
    384        1.1    tsubai }
    385        1.1    tsubai 
    386        1.1    tsubai void
    387  1.13.20.1      yamt mc_mediastatus(struct mc_softc *sc, struct ifmediareq *ifmr)
    388        1.1    tsubai {
    389        1.1    tsubai 	if (sc->sc_plscc == PORTSEL_AUI)
    390        1.1    tsubai 		ifmr->ifm_active = IFM_ETHER | IFM_10_5;
    391        1.1    tsubai 	else
    392        1.1    tsubai 		ifmr->ifm_active = IFM_ETHER | IFM_10_T;
    393        1.1    tsubai }
    394