Home | History | Annotate | Line # | Download | only in dev
if_mc.c revision 1.15
      1  1.15       dsl /*	$NetBSD: if_mc.c,v 1.15 2009/03/14 14:46:01 dsl 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.15       dsl __KERNEL_RCSID(0, "$NetBSD: if_mc.c,v 1.15 2009/03/14 14:46:01 dsl 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.15       dsl hide int	mc_match(struct device *, struct cfdata *, void *);
     65  1.15       dsl hide void	mc_attach(struct device *, struct device *, void *);
     66  1.15       dsl hide void	mc_init(struct mc_softc *sc);
     67  1.15       dsl hide void	mc_putpacket(struct mc_softc *sc, u_int len);
     68  1.15       dsl hide int	mc_dmaintr(void *arg);
     69  1.15       dsl hide void	mc_reset_rxdma(struct mc_softc *sc);
     70  1.15       dsl hide void	mc_reset_txdma(struct mc_softc *sc);
     71  1.15       dsl hide void	mc_select_utp(struct mc_softc *sc);
     72  1.15       dsl hide void	mc_select_aui(struct mc_softc *sc);
     73  1.15       dsl hide int	mc_mediachange(struct mc_softc *sc);
     74  1.15       dsl 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.1    tsubai mc_match(parent, cf, aux)
     89   1.1    tsubai 	struct device *parent;
     90   1.1    tsubai 	struct cfdata *cf;
     91   1.1    tsubai 	void *aux;
     92   1.1    tsubai {
     93   1.1    tsubai 	struct confargs *ca = aux;
     94   1.1    tsubai 
     95   1.1    tsubai 	if (strcmp(ca->ca_name, "mace") != 0)
     96   1.1    tsubai 		return 0;
     97   1.1    tsubai 
     98   1.1    tsubai 	/* requires 6 regs */
     99   1.1    tsubai 	if (ca->ca_nreg / sizeof(int) != 6)
    100   1.1    tsubai 		return 0;
    101   1.1    tsubai 
    102   1.1    tsubai 	/* requires 3 intrs */
    103   1.1    tsubai 	if (ca->ca_nintr / sizeof(int) != 3)
    104   1.1    tsubai 		return 0;
    105   1.1    tsubai 
    106   1.1    tsubai 	return 1;
    107   1.1    tsubai }
    108   1.1    tsubai 
    109   1.1    tsubai hide void
    110   1.1    tsubai mc_attach(parent, self, aux)
    111   1.1    tsubai 	struct device *parent, *self;
    112   1.1    tsubai 	void *aux;
    113   1.1    tsubai {
    114   1.1    tsubai 	struct confargs *ca = aux;
    115   1.1    tsubai 	struct mc_softc *sc = (struct mc_softc *)self;
    116   1.1    tsubai 	u_int8_t myaddr[ETHER_ADDR_LEN];
    117   1.1    tsubai 	u_int *reg;
    118   1.1    tsubai 
    119   1.1    tsubai 	sc->sc_node = ca->ca_node;
    120  1.14  macallan 	sc->sc_regt = ca->ca_tag;
    121   1.1    tsubai 
    122   1.1    tsubai 	reg  = ca->ca_reg;
    123   1.1    tsubai 	reg[0] += ca->ca_baseaddr;
    124   1.1    tsubai 	reg[2] += ca->ca_baseaddr;
    125   1.1    tsubai 	reg[4] += ca->ca_baseaddr;
    126   1.1    tsubai 
    127   1.1    tsubai 	sc->sc_txdma = mapiodev(reg[2], reg[3]);
    128   1.1    tsubai 	sc->sc_rxdma = mapiodev(reg[4], reg[5]);
    129   1.1    tsubai 	bus_space_map(sc->sc_regt, reg[0], reg[1], 0, &sc->sc_regh);
    130  1.14  macallan 
    131   1.1    tsubai 	sc->sc_tail = 0;
    132   1.1    tsubai 	sc->sc_txdmacmd = dbdma_alloc(sizeof(dbdma_command_t) * 2);
    133   1.1    tsubai 	sc->sc_rxdmacmd = (void *)dbdma_alloc(sizeof(dbdma_command_t) * 8);
    134   1.5       wiz 	memset(sc->sc_txdmacmd, 0, sizeof(dbdma_command_t) * 2);
    135   1.5       wiz 	memset(sc->sc_rxdmacmd, 0, sizeof(dbdma_command_t) * 8);
    136   1.1    tsubai 
    137   1.1    tsubai 	printf(": irq %d,%d,%d",
    138   1.1    tsubai 		ca->ca_intr[0], ca->ca_intr[1], ca->ca_intr[2]);
    139   1.1    tsubai 
    140   1.1    tsubai 	if (OF_getprop(sc->sc_node, "local-mac-address", myaddr, 6) != 6) {
    141   1.1    tsubai 		printf(": failed to get MAC address.\n");
    142   1.1    tsubai 		return;
    143   1.1    tsubai 	}
    144   1.1    tsubai 
    145   1.1    tsubai 	/* allocate memory for transmit buffer and mark it non-cacheable */
    146   1.8   thorpej 	sc->sc_txbuf = malloc(PAGE_SIZE, M_DEVBUF, M_WAITOK);
    147   1.1    tsubai 	sc->sc_txbuf_phys = kvtop(sc->sc_txbuf);
    148   1.8   thorpej 	memset(sc->sc_txbuf, 0, PAGE_SIZE);
    149   1.1    tsubai 
    150   1.1    tsubai 	/*
    151   1.1    tsubai 	 * allocate memory for receive buffer and mark it non-cacheable
    152   1.1    tsubai 	 * XXX This should use the bus_dma interface, since the buffer
    153   1.1    tsubai 	 * needs to be physically contiguous. However, it seems that
    154   1.1    tsubai 	 * at least on my system, malloc() does allocate contiguous
    155   1.1    tsubai 	 * memory. If it's not, suggest reducing the number of buffers
    156   1.1    tsubai 	 * to 2, which will fit in one 4K page.
    157   1.1    tsubai 	 */
    158   1.8   thorpej 	sc->sc_rxbuf = malloc(MC_NPAGES * PAGE_SIZE, M_DEVBUF, M_WAITOK);
    159   1.1    tsubai 	sc->sc_rxbuf_phys = kvtop(sc->sc_rxbuf);
    160   1.8   thorpej 	memset(sc->sc_rxbuf, 0, MC_NPAGES * PAGE_SIZE);
    161   1.1    tsubai 
    162   1.1    tsubai 	if ((int)sc->sc_txbuf & PGOFSET)
    163   1.1    tsubai 		printf("txbuf is not page-aligned\n");
    164   1.1    tsubai 	if ((int)sc->sc_rxbuf & PGOFSET)
    165   1.1    tsubai 		printf("rxbuf is not page-aligned\n");
    166   1.1    tsubai 
    167   1.1    tsubai 	sc->sc_bus_init = mc_init;
    168   1.1    tsubai 	sc->sc_putpacket = mc_putpacket;
    169   1.1    tsubai 
    170   1.1    tsubai 
    171   1.1    tsubai 	/* disable receive DMA */
    172   1.1    tsubai 	dbdma_reset(sc->sc_rxdma);
    173   1.1    tsubai 
    174   1.1    tsubai 	/* disable transmit DMA */
    175   1.1    tsubai 	dbdma_reset(sc->sc_txdma);
    176   1.1    tsubai 
    177   1.1    tsubai 	/* install interrupt handlers */
    178  1.13   garbled 	/*intr_establish(ca->ca_intr[1], IST_EDGE, IPL_NET, mc_dmaintr, sc);*/
    179  1.13   garbled 	intr_establish(ca->ca_intr[2], IST_EDGE, IPL_NET, mc_dmaintr, sc);
    180  1.13   garbled 	intr_establish(ca->ca_intr[0], IST_EDGE, IPL_NET, mcintr, sc);
    181   1.1    tsubai 
    182   1.1    tsubai 	sc->sc_biucc = XMTSP_64;
    183   1.1    tsubai 	sc->sc_fifocc = XMTFW_16 | RCVFW_64 | XMTFWU | RCVFWU |
    184   1.1    tsubai 	    XMTBRST | RCVBRST;
    185   1.1    tsubai 	/*sc->sc_plscc = PORTSEL_10BT;*/
    186   1.1    tsubai 	sc->sc_plscc = PORTSEL_GPSI | ENPLSIO;
    187   1.1    tsubai 
    188   1.1    tsubai 	/* mcsetup returns 1 if something fails */
    189   1.1    tsubai 	if (mcsetup(sc, myaddr)) {
    190   1.1    tsubai 		printf("mcsetup returns non zero\n");
    191   1.1    tsubai 		return;
    192   1.1    tsubai 	}
    193   1.1    tsubai #ifdef NOTYET
    194   1.1    tsubai 	sc->sc_mediachange = mc_mediachange;
    195   1.1    tsubai 	sc->sc_mediastatus = mc_mediastatus;
    196   1.1    tsubai 	sc->sc_supmedia = mc_supmedia;
    197   1.1    tsubai 	sc->sc_nsupmedia = N_SUPMEDIA;
    198   1.1    tsubai 	sc->sc_defaultmedia = IFM_ETHER | IFM_10_T;
    199   1.1    tsubai #endif
    200   1.1    tsubai }
    201   1.1    tsubai 
    202   1.1    tsubai /* Bus-specific initialization */
    203   1.1    tsubai hide void
    204   1.1    tsubai mc_init(sc)
    205   1.1    tsubai 	struct mc_softc *sc;
    206   1.1    tsubai {
    207   1.1    tsubai 	mc_reset_rxdma(sc);
    208   1.1    tsubai 	mc_reset_txdma(sc);
    209   1.1    tsubai }
    210   1.1    tsubai 
    211   1.1    tsubai hide void
    212   1.1    tsubai mc_putpacket(sc, len)
    213   1.1    tsubai 	struct mc_softc *sc;
    214   1.1    tsubai 	u_int len;
    215   1.1    tsubai {
    216   1.1    tsubai 	dbdma_command_t *cmd = sc->sc_txdmacmd;
    217   1.1    tsubai 
    218   1.1    tsubai 	DBDMA_BUILD(cmd, DBDMA_CMD_OUT_LAST, 0, len, sc->sc_txbuf_phys,
    219   1.1    tsubai 		DBDMA_INT_NEVER, DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER);
    220   1.1    tsubai 
    221   1.1    tsubai 	dbdma_start(sc->sc_txdma, sc->sc_txdmacmd);
    222   1.1    tsubai }
    223   1.1    tsubai 
    224   1.1    tsubai /*
    225   1.1    tsubai  * Interrupt handler for the MACE DMA completion interrupts
    226   1.1    tsubai  */
    227   1.1    tsubai int
    228   1.1    tsubai mc_dmaintr(arg)
    229   1.1    tsubai 	void *arg;
    230   1.1    tsubai {
    231   1.1    tsubai 	struct mc_softc *sc = arg;
    232   1.1    tsubai 	int status, offset, statoff;
    233   1.1    tsubai 	int datalen, resid;
    234   1.1    tsubai 	int i, n;
    235   1.1    tsubai 	dbdma_command_t *cmd;
    236   1.1    tsubai 
    237   1.1    tsubai 	/* We've received some packets from the MACE */
    238   1.1    tsubai 
    239   1.1    tsubai 	/* Loop through, processing each of the packets */
    240   1.1    tsubai 	i = sc->sc_tail;
    241   1.1    tsubai 	for (n = 0; n < MC_RXDMABUFS; n++, i++) {
    242   1.1    tsubai 		if (i == MC_RXDMABUFS)
    243   1.1    tsubai 			i = 0;
    244   1.1    tsubai 
    245   1.1    tsubai 		cmd = &sc->sc_rxdmacmd[i];
    246   1.2    tsubai 		/* flushcache(cmd, sizeof(dbdma_command_t)); */
    247  1.13   garbled 		status = in16rb(&cmd->d_status);
    248  1.13   garbled 		resid = in16rb(&cmd->d_resid);
    249   1.1    tsubai 
    250   1.1    tsubai 		/*if ((status & D_ACTIVE) == 0)*/
    251   1.1    tsubai 		if ((status & 0x40) == 0)
    252   1.1    tsubai 			continue;
    253   1.1    tsubai 
    254   1.1    tsubai #if 1
    255  1.13   garbled 		if (in16rb(&cmd->d_count) != ETHERMTU + 22)
    256   1.1    tsubai 			printf("bad d_count\n");
    257   1.1    tsubai #endif
    258   1.1    tsubai 
    259  1.13   garbled 		datalen = in16rb(&cmd->d_count) - resid;
    260   1.1    tsubai 		datalen -= 4;	/* 4 == status bytes */
    261   1.1    tsubai 
    262   1.1    tsubai 		if (datalen < 4 + sizeof(struct ether_header)) {
    263   1.1    tsubai 			printf("short packet len=%d\n", datalen);
    264   1.1    tsubai 			/* continue; */
    265   1.1    tsubai 			goto next;
    266   1.1    tsubai 		}
    267   1.1    tsubai 
    268   1.1    tsubai 		offset = i * MC_BUFSIZE;
    269   1.1    tsubai 		statoff = offset + datalen;
    270   1.1    tsubai 
    271   1.1    tsubai 		DBDMA_BUILD_CMD(cmd, DBDMA_CMD_STOP, 0, 0, 0, 0);
    272  1.11     perry 		__asm volatile("eieio");
    273   1.1    tsubai 
    274   1.2    tsubai 		/* flushcache(sc->sc_rxbuf + offset, datalen + 4); */
    275   1.2    tsubai 
    276   1.1    tsubai 		sc->sc_rxframe.rx_rcvcnt = sc->sc_rxbuf[statoff + 0];
    277   1.1    tsubai 		sc->sc_rxframe.rx_rcvsts = sc->sc_rxbuf[statoff + 1];
    278   1.1    tsubai 		sc->sc_rxframe.rx_rntpc  = sc->sc_rxbuf[statoff + 2];
    279   1.1    tsubai 		sc->sc_rxframe.rx_rcvcc  = sc->sc_rxbuf[statoff + 3];
    280   1.1    tsubai 		sc->sc_rxframe.rx_frame  = sc->sc_rxbuf + offset;
    281   1.1    tsubai 
    282   1.1    tsubai 		mc_rint(sc);
    283   1.1    tsubai 
    284   1.1    tsubai next:
    285   1.1    tsubai 		DBDMA_BUILD_CMD(cmd, DBDMA_CMD_IN_LAST, 0, DBDMA_INT_ALWAYS,
    286   1.1    tsubai 			DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER);
    287  1.11     perry 		__asm volatile("eieio");
    288   1.1    tsubai 		cmd->d_status = 0;
    289   1.1    tsubai 		cmd->d_resid = 0;
    290   1.1    tsubai 		sc->sc_tail = i + 1;
    291   1.1    tsubai 	}
    292   1.1    tsubai 
    293   1.1    tsubai 	dbdma_continue(sc->sc_rxdma);
    294   1.1    tsubai 
    295   1.1    tsubai 	return 1;
    296   1.1    tsubai }
    297   1.1    tsubai 
    298   1.1    tsubai hide void
    299   1.1    tsubai mc_reset_rxdma(sc)
    300   1.1    tsubai 	struct mc_softc *sc;
    301   1.1    tsubai {
    302   1.1    tsubai 	dbdma_command_t *cmd = sc->sc_rxdmacmd;
    303   1.1    tsubai 	dbdma_regmap_t *dmareg = sc->sc_rxdma;
    304   1.1    tsubai 	int i;
    305   1.1    tsubai 	u_int8_t maccc;
    306   1.1    tsubai 
    307   1.1    tsubai 	/* Disable receiver, reset the DMA channels */
    308   1.1    tsubai 	maccc = NIC_GET(sc, MACE_MACCC);
    309   1.1    tsubai 	NIC_PUT(sc, MACE_MACCC, maccc & ~ENRCV);
    310   1.1    tsubai 
    311   1.1    tsubai 	dbdma_reset(dmareg);
    312   1.1    tsubai 
    313   1.1    tsubai 	for (i = 0; i < MC_RXDMABUFS; i++) {
    314   1.1    tsubai 		DBDMA_BUILD(cmd, DBDMA_CMD_IN_LAST, 0, ETHERMTU + 22,
    315   1.1    tsubai 			sc->sc_rxbuf_phys + MC_BUFSIZE * i, DBDMA_INT_ALWAYS,
    316   1.1    tsubai 			DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER);
    317   1.1    tsubai 		cmd++;
    318   1.1    tsubai 	}
    319   1.1    tsubai 
    320   1.1    tsubai 	DBDMA_BUILD(cmd, DBDMA_CMD_NOP, 0, 0, 0,
    321   1.1    tsubai 		DBDMA_INT_NEVER, DBDMA_WAIT_NEVER, DBDMA_BRANCH_ALWAYS);
    322  1.13   garbled 	out32rb(&cmd->d_cmddep, kvtop((void *)sc->sc_rxdmacmd));
    323   1.1    tsubai 	cmd++;
    324   1.1    tsubai 
    325   1.1    tsubai 	dbdma_start(dmareg, sc->sc_rxdmacmd);
    326   1.1    tsubai 
    327   1.1    tsubai 	sc->sc_tail = 0;
    328   1.1    tsubai 
    329   1.1    tsubai 	/* Reenable receiver, reenable DMA */
    330   1.1    tsubai 	NIC_PUT(sc, MACE_MACCC, maccc);
    331   1.1    tsubai }
    332   1.1    tsubai 
    333   1.1    tsubai hide void
    334   1.1    tsubai mc_reset_txdma(sc)
    335   1.1    tsubai 	struct mc_softc *sc;
    336   1.1    tsubai {
    337   1.1    tsubai 	dbdma_command_t *cmd = sc->sc_txdmacmd;
    338   1.1    tsubai 	dbdma_regmap_t *dmareg = sc->sc_txdma;
    339   1.1    tsubai 	u_int8_t maccc;
    340   1.1    tsubai 
    341   1.1    tsubai 	/* disable transmitter */
    342   1.1    tsubai 	maccc = NIC_GET(sc, MACE_MACCC);
    343   1.1    tsubai 	NIC_PUT(sc, MACE_MACCC, maccc & ~ENXMT);
    344   1.1    tsubai 
    345   1.1    tsubai 	dbdma_reset(dmareg);
    346   1.1    tsubai 
    347   1.1    tsubai 	DBDMA_BUILD(cmd, DBDMA_CMD_OUT_LAST, 0, 0, sc->sc_txbuf_phys,
    348   1.1    tsubai 		DBDMA_INT_NEVER, DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER);
    349   1.1    tsubai 	cmd++;
    350   1.1    tsubai 	DBDMA_BUILD(cmd, DBDMA_CMD_STOP, 0, 0, 0,
    351   1.1    tsubai 		DBDMA_INT_NEVER, DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER);
    352   1.1    tsubai 
    353   1.1    tsubai 	out32rb(&dmareg->d_cmdptrhi, 0);
    354  1.12  christos 	out32rb(&dmareg->d_cmdptrlo, kvtop((void *)sc->sc_txdmacmd));
    355   1.1    tsubai 
    356   1.1    tsubai 	/* restore old value */
    357   1.1    tsubai 	NIC_PUT(sc, MACE_MACCC, maccc);
    358   1.1    tsubai }
    359   1.1    tsubai 
    360   1.1    tsubai void
    361   1.1    tsubai mc_select_utp(sc)
    362   1.1    tsubai 	struct mc_softc *sc;
    363   1.1    tsubai {
    364   1.1    tsubai 	sc->sc_plscc = PORTSEL_GPSI | ENPLSIO;
    365   1.1    tsubai }
    366   1.1    tsubai 
    367   1.1    tsubai void
    368   1.1    tsubai mc_select_aui(sc)
    369   1.1    tsubai 	struct mc_softc *sc;
    370   1.1    tsubai {
    371   1.1    tsubai 	sc->sc_plscc = PORTSEL_AUI;
    372   1.1    tsubai }
    373   1.1    tsubai 
    374   1.1    tsubai int
    375   1.1    tsubai mc_mediachange(sc)
    376   1.1    tsubai 	struct mc_softc *sc;
    377   1.1    tsubai {
    378   1.1    tsubai 	struct ifmedia *ifm = &sc->sc_media;
    379   1.1    tsubai 
    380   1.1    tsubai 	if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
    381   1.1    tsubai 		return EINVAL;
    382   1.1    tsubai 
    383   1.1    tsubai 	switch (IFM_SUBTYPE(ifm->ifm_media)) {
    384   1.1    tsubai 
    385   1.1    tsubai 	case IFM_10_T:
    386   1.1    tsubai 		mc_select_utp(sc);
    387   1.1    tsubai 		break;
    388   1.1    tsubai 
    389   1.1    tsubai 	case IFM_10_5:
    390   1.1    tsubai 		mc_select_aui(sc);
    391   1.1    tsubai 		break;
    392   1.1    tsubai 
    393   1.1    tsubai 	default:
    394   1.1    tsubai 		return EINVAL;
    395   1.1    tsubai 	}
    396   1.1    tsubai 
    397   1.1    tsubai 	return 0;
    398   1.1    tsubai }
    399   1.1    tsubai 
    400   1.1    tsubai void
    401   1.1    tsubai mc_mediastatus(sc, ifmr)
    402   1.1    tsubai 	struct mc_softc *sc;
    403   1.1    tsubai 	struct ifmediareq *ifmr;
    404   1.1    tsubai {
    405   1.1    tsubai 	if (sc->sc_plscc == PORTSEL_AUI)
    406   1.1    tsubai 		ifmr->ifm_active = IFM_ETHER | IFM_10_5;
    407   1.1    tsubai 	else
    408   1.1    tsubai 		ifmr->ifm_active = IFM_ETHER | IFM_10_T;
    409   1.1    tsubai }
    410