1/*- 2 * Copyright (c) 1998, 1999 Scott Mitchell 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $Id: if_xe.c,v 1.20 1999/06/13 19:17:40 scott Exp $
| 1/*- 2 * Copyright (c) 1998, 1999 Scott Mitchell 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $Id: if_xe.c,v 1.20 1999/06/13 19:17:40 scott Exp $
|
27 * $FreeBSD: head/sys/dev/xe/if_xe.c 52632 1999-10-29 17:28:09Z imp $
| 27 * $FreeBSD: head/sys/dev/xe/if_xe.c 55723 2000-01-10 08:05:53Z imp $
|
28 */ 29 30/*
| 28 */ 29 30/*
|
| 31 * XXX TODO XXX 32 * 33 * I've pushed this fairly far, but there are some things that need to be 34 * done here. I'm documenting them here in case I get destracted. -- imp 35 * 36 * xe_memwrite -- maybe better handled pccard layer? 37 * xe_cem56fix -- need to figure out how to map the extra stuff. 38 * xe_activate -- need to write it, and add some stuff to it. Look at if_sn 39 * for guidance. resources/interrupts. 40 * xe_deactivate -- turn off resources/interrupts. 41 */ 42 43/*
|
31 * Portions of this software were derived from Werner Koch's xirc2ps driver 32 * for Linux under the terms of the following license (from v1.30 of the 33 * xirc2ps driver): 34 * 35 * Copyright (c) 1997 by Werner Koch (dd9jn) 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 40 * 1. Redistributions of source code must retain the above copyright 41 * notice, and the entire permission notice in its entirety, 42 * including the disclaimer of warranties. 43 * 2. Redistributions in binary form must reproduce the above copyright 44 * notice, this list of conditions and the following disclaimer in the 45 * documentation and/or other materials provided with the distribution. 46 * 3. The name of the author may not be used to endorse or promote 47 * products derived from this software without specific prior 48 * written permission. 49 * 50 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 51 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 52 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 53 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 54 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 55 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 56 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 58 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 59 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 60 * OF THE POSSIBILITY OF SUCH DAMAGE. 61 */ 62 63/* 64 * FreeBSD device driver for Xircom CreditCard PCMCIA Ethernet adapters. The 65 * following cards are currently known to work with the driver: 66 * Xircom CreditCard 10/100 (CE3) 67 * Xircom CreditCard Ethernet + Modem 28 (CEM28) 68 * Xircom CreditCard Ethernet 10/100 + Modem 56 (CEM56) 69 * Xircom RealPort Ethernet 10 70 * Xircom RealPort Ethernet 10/100 71 * Xircom RealPort Ethernet 10/100 + Modem 56 (REM56, REM56G) 72 * Intel EtherExpress Pro/100 PC Card Mobile Adapter 16 (Pro/100 M16A) 73 * Compaq Netelligent 10/100 PC Card (CPQ-10/100) 74 * 75 * Some other cards *should* work, but support for them is either broken or in 76 * an unknown state at the moment. I'm always interested in hearing from 77 * people who own any of these cards: 78 * Xircom CreditCard 10Base-T (PS-CE2-10) 79 * Xircom CreditCard Ethernet + ModemII (CEM2) 80 * Xircom CEM28 and CEM33 Ethernet/Modem cards (may be variants of CEM2?) 81 * 82 * Thanks to all who assisted with the development and testing of the driver, 83 * especially: Werner Koch, Duke Kamstra, Duncan Barclay, Jason George, Dru 84 * Nelson, Mike Kephart, Bill Rainey and Douglas Rand. Apologies if I've left 85 * out anyone who deserves a mention here. 86 * 87 * Special thanks to Ade Lovett for both hosting the mailing list and doing 88 * the CEM56/REM56 support code; and the FreeBSD UK Users' Group for hosting 89 * the web pages. 90 * 91 * Contact points: 92 * 93 * Driver web page: http://ukug.uk.freebsd.org/~scott/xe_drv/ 94 * 95 * Mailing list: http://www.lovett.com/lists/freebsd-xircom/ 96 * or send "subscribe freebsd-xircom" to <majordomo@lovett.com> 97 * 98 * Author email: <scott@uk.freebsd.org> 99 */ 100 101 102#ifndef XE_DEBUG 103#define XE_DEBUG 1 /* Increase for more voluminous output! */ 104#endif 105
| 44 * Portions of this software were derived from Werner Koch's xirc2ps driver 45 * for Linux under the terms of the following license (from v1.30 of the 46 * xirc2ps driver): 47 * 48 * Copyright (c) 1997 by Werner Koch (dd9jn) 49 * 50 * Redistribution and use in source and binary forms, with or without 51 * modification, are permitted provided that the following conditions 52 * are met: 53 * 1. Redistributions of source code must retain the above copyright 54 * notice, and the entire permission notice in its entirety, 55 * including the disclaimer of warranties. 56 * 2. Redistributions in binary form must reproduce the above copyright 57 * notice, this list of conditions and the following disclaimer in the 58 * documentation and/or other materials provided with the distribution. 59 * 3. The name of the author may not be used to endorse or promote 60 * products derived from this software without specific prior 61 * written permission. 62 * 63 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 64 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 65 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 66 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 67 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 68 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 69 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 70 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 71 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 72 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 73 * OF THE POSSIBILITY OF SUCH DAMAGE. 74 */ 75 76/* 77 * FreeBSD device driver for Xircom CreditCard PCMCIA Ethernet adapters. The 78 * following cards are currently known to work with the driver: 79 * Xircom CreditCard 10/100 (CE3) 80 * Xircom CreditCard Ethernet + Modem 28 (CEM28) 81 * Xircom CreditCard Ethernet 10/100 + Modem 56 (CEM56) 82 * Xircom RealPort Ethernet 10 83 * Xircom RealPort Ethernet 10/100 84 * Xircom RealPort Ethernet 10/100 + Modem 56 (REM56, REM56G) 85 * Intel EtherExpress Pro/100 PC Card Mobile Adapter 16 (Pro/100 M16A) 86 * Compaq Netelligent 10/100 PC Card (CPQ-10/100) 87 * 88 * Some other cards *should* work, but support for them is either broken or in 89 * an unknown state at the moment. I'm always interested in hearing from 90 * people who own any of these cards: 91 * Xircom CreditCard 10Base-T (PS-CE2-10) 92 * Xircom CreditCard Ethernet + ModemII (CEM2) 93 * Xircom CEM28 and CEM33 Ethernet/Modem cards (may be variants of CEM2?) 94 * 95 * Thanks to all who assisted with the development and testing of the driver, 96 * especially: Werner Koch, Duke Kamstra, Duncan Barclay, Jason George, Dru 97 * Nelson, Mike Kephart, Bill Rainey and Douglas Rand. Apologies if I've left 98 * out anyone who deserves a mention here. 99 * 100 * Special thanks to Ade Lovett for both hosting the mailing list and doing 101 * the CEM56/REM56 support code; and the FreeBSD UK Users' Group for hosting 102 * the web pages. 103 * 104 * Contact points: 105 * 106 * Driver web page: http://ukug.uk.freebsd.org/~scott/xe_drv/ 107 * 108 * Mailing list: http://www.lovett.com/lists/freebsd-xircom/ 109 * or send "subscribe freebsd-xircom" to <majordomo@lovett.com> 110 * 111 * Author email: <scott@uk.freebsd.org> 112 */ 113 114 115#ifndef XE_DEBUG 116#define XE_DEBUG 1 /* Increase for more voluminous output! */ 117#endif 118
|
106#include "xe.h" 107#include "card.h" 108#include "apm.h" 109 110#if NXE > 0 111 112#undef NCARD 113#define NCARD 0 114#if NCARD > 0 115
| |
116#include <sys/param.h> 117#include <sys/cdefs.h> 118#include <sys/errno.h> 119#include <sys/kernel.h> 120#include <sys/malloc.h> 121#include <sys/mbuf.h> 122#include <sys/select.h> 123#include <sys/socket.h> 124#include <sys/sockio.h> 125#include <sys/systm.h> 126#include <sys/uio.h> 127#include <sys/conf.h> 128
| 119#include <sys/param.h> 120#include <sys/cdefs.h> 121#include <sys/errno.h> 122#include <sys/kernel.h> 123#include <sys/malloc.h> 124#include <sys/mbuf.h> 125#include <sys/select.h> 126#include <sys/socket.h> 127#include <sys/sockio.h> 128#include <sys/systm.h> 129#include <sys/uio.h> 130#include <sys/conf.h> 131
|
| 132#include <sys/module.h> 133#include <sys/bus.h> 134 135#include <machine/bus.h> 136#include <machine/resource.h> 137#include <sys/rman.h> 138
|
129#include <net/ethernet.h> 130#include <net/if.h> 131#include <net/if_arp.h> 132#include <net/if_dl.h> 133#include <net/if_media.h> 134#include <net/if_mib.h> 135#include <net/bpf.h> 136
| 139#include <net/ethernet.h> 140#include <net/if.h> 141#include <net/if_arp.h> 142#include <net/if_dl.h> 143#include <net/if_media.h> 144#include <net/if_mib.h> 145#include <net/bpf.h> 146
|
137#include <i386/isa/isa.h> 138#include <i386/isa/isa_device.h> 139#include <dev/pccard/if_xereg.h>
| 147#include <dev/xe/if_xereg.h> 148#include <dev/xe/if_xevar.h> 149
|
140#include <machine/clock.h>
| 150#include <machine/clock.h>
|
141#if NAPM > 0 142#include <machine/apm_bios.h> 143#endif /* NAPM > 0 */
| |
144
| 151
|
145#include <pccard/cardinfo.h> 146#include <pccard/cis.h> 147#include <pccard/driver.h> 148#include <pccard/slot.h> 149 150 151
| |
152/*
| 152/*
|
153 * One of these structures per allocated device 154 */ 155struct xe_softc { 156 struct arpcom arpcom; 157 struct ifmedia ifmedia; 158 struct ifmib_iso_8802_3 mibdata; 159 struct callout_handle chand; 160 struct isa_device *dev; 161 struct pccard_devinfo *crd; 162 struct ifnet *ifp; 163 struct ifmedia *ifm; 164 char *card_type; /* Card model name */ 165 char *vendor; /* Card manufacturer */ 166 int unit; /* Unit number, from dev->id_unit */ 167 int srev; /* Silicon revision */ 168 int tx_queued; /* Packets currently waiting to transmit */ 169 int tx_tpr; /* Last value of TPR reg on card */ 170 int tx_collisions; /* Collisions since last successful send */ 171 int tx_timeouts; /* Count of transmit timeouts */ 172 int autoneg_status; /* Autonegotiation progress state */ 173 int media; /* Private media word */ 174 u_char version; /* Bonding Version register from card */ 175 u_char modem; /* 1 = Card has a modem */ 176 u_char ce2; /* 1 = Card has CE2 silicon */ 177 u_char mohawk; /* 1 = Card has Mohawk (CE3) silicon */ 178 u_char dingo; /* 1 = Card has Dingo (CEM56) silicon */ 179 u_char phy_ok; /* 1 = MII-compliant PHY found and initialised */ 180 u_char gone; /* 1 = Card bailed out */ 181#if NAPM > 0 182 struct apmhook suspend_hook; 183 struct apmhook resume_hook; 184#endif /* NAPM > 0 */ 185}; 186 187static struct xe_softc *sca[MAXSLOT]; 188 189 190/*
| |
191 * MII command structure 192 */ 193struct xe_mii_frame { 194 u_int8_t mii_stdelim; 195 u_int8_t mii_opcode; 196 u_int8_t mii_phyaddr; 197 u_int8_t mii_regaddr; 198 u_int8_t mii_turnaround; 199 u_int16_t mii_data; 200}; 201 202/*
| 153 * MII command structure 154 */ 155struct xe_mii_frame { 156 u_int8_t mii_stdelim; 157 u_int8_t mii_opcode; 158 u_int8_t mii_phyaddr; 159 u_int8_t mii_regaddr; 160 u_int8_t mii_turnaround; 161 u_int16_t mii_data; 162}; 163 164/*
|
203 * For accessing card registers 204 */ 205#define XE_INB(r) inb(scp->dev->id_iobase+(r)) 206#define XE_INW(r) inw(scp->dev->id_iobase+(r)) 207#define XE_OUTB(r, b) outb(scp->dev->id_iobase+(r), (b)) 208#define XE_OUTW(r, w) outw(scp->dev->id_iobase+(r), (w)) 209#define XE_SELECT_PAGE(p) XE_OUTB(XE_PR, (p)) 210 211/* 212 * Horrid stuff for accessing CIS tuples 213 */ 214#define CARD_MAJOR 50 215#define CISTPL_BUFSIZE 512 216#define CISTPL_TYPE(tpl) tpl[0] 217#define CISTPL_LEN(tpl) tpl[2] 218#define CISTPL_DATA(tpl,pos) tpl[4 + ((pos)<<1)] 219 220/*
| |
221 * Media autonegotiation progress constants 222 */ 223#define XE_AUTONEG_NONE 0 /* No autonegotiation in progress */ 224#define XE_AUTONEG_WAITING 1 /* Waiting for transmitter to go idle */ 225#define XE_AUTONEG_STARTED 2 /* Waiting for autonegotiation to complete */ 226#define XE_AUTONEG_100TX 3 /* Trying to force 100baseTX link */ 227#define XE_AUTONEG_FAIL 4 /* Autonegotiation failed */ 228 229 230/* 231 * Prototypes start here 232 */
| 165 * Media autonegotiation progress constants 166 */ 167#define XE_AUTONEG_NONE 0 /* No autonegotiation in progress */ 168#define XE_AUTONEG_WAITING 1 /* Waiting for transmitter to go idle */ 169#define XE_AUTONEG_STARTED 2 /* Waiting for autonegotiation to complete */ 170#define XE_AUTONEG_100TX 3 /* Trying to force 100baseTX link */ 171#define XE_AUTONEG_FAIL 4 /* Autonegotiation failed */ 172 173 174/* 175 * Prototypes start here 176 */
|
233static int xe_probe (struct isa_device *dev); 234static int xe_card_init (struct pccard_devinfo *devi); 235static int xe_attach (struct isa_device *dev);
| 177static int xe_probe (device_t dev); 178static int xe_attach (device_t dev); 179static int xe_detach (device_t dev); 180static int xe_activate (device_t dev); 181static void xe_deactivate (device_t dev);
|
236static void xe_init (void *xscp); 237static void xe_start (struct ifnet *ifp); 238static int xe_ioctl (struct ifnet *ifp, u_long command, caddr_t data);
| 182static void xe_init (void *xscp); 183static void xe_start (struct ifnet *ifp); 184static int xe_ioctl (struct ifnet *ifp, u_long command, caddr_t data);
|
239static int xe_card_intr (struct pccard_devinfo *devi);
| |
240static void xe_watchdog (struct ifnet *ifp); 241static int xe_media_change (struct ifnet *ifp); 242static void xe_media_status (struct ifnet *ifp, struct ifmediareq *mrp); 243static timeout_t xe_setmedia; 244static void xe_hard_reset (struct xe_softc *scp); 245static void xe_soft_reset (struct xe_softc *scp); 246static void xe_stop (struct xe_softc *scp); 247static void xe_enable_intr (struct xe_softc *scp); 248static void xe_disable_intr (struct xe_softc *scp); 249static void xe_setmulti (struct xe_softc *scp); 250static void xe_setaddrs (struct xe_softc *scp); 251static int xe_pio_write_packet (struct xe_softc *scp, struct mbuf *mbp);
| 185static void xe_watchdog (struct ifnet *ifp); 186static int xe_media_change (struct ifnet *ifp); 187static void xe_media_status (struct ifnet *ifp, struct ifmediareq *mrp); 188static timeout_t xe_setmedia; 189static void xe_hard_reset (struct xe_softc *scp); 190static void xe_soft_reset (struct xe_softc *scp); 191static void xe_stop (struct xe_softc *scp); 192static void xe_enable_intr (struct xe_softc *scp); 193static void xe_disable_intr (struct xe_softc *scp); 194static void xe_setmulti (struct xe_softc *scp); 195static void xe_setaddrs (struct xe_softc *scp); 196static int xe_pio_write_packet (struct xe_softc *scp, struct mbuf *mbp);
|
252static void xe_card_unload (struct pccard_devinfo *devi);
| |
253static u_int32_t xe_compute_crc (u_int8_t *data, int len); 254static int xe_compute_hashbit (u_int32_t crc); 255 256/* 257 * MII functions 258 */ 259static void xe_mii_sync (struct xe_softc *scp); 260static int xe_mii_init (struct xe_softc *scp); 261static void xe_mii_send (struct xe_softc *scp, u_int32_t bits, int cnt); 262static int xe_mii_readreg (struct xe_softc *scp, struct xe_mii_frame *frame); 263static int xe_mii_writereg (struct xe_softc *scp, struct xe_mii_frame *frame); 264static u_int16_t xe_phy_readreg (struct xe_softc *scp, u_int16_t reg); 265static void xe_phy_writereg (struct xe_softc *scp, u_int16_t reg, u_int16_t data); 266 267/* 268 * Debug functions 269 */ 270#ifdef XE_DEBUG 271#define XE_REG_DUMP(scp) xe_reg_dump((scp)) 272#define XE_MII_DUMP(scp) xe_mii_dump((scp)) 273static void xe_reg_dump (struct xe_softc *scp); 274static void xe_mii_dump (struct xe_softc *scp); 275#else 276#define XE_REG_DUMP(scp) 277#define XE_MII_DUMP(scp) 278#endif 279
| 197static u_int32_t xe_compute_crc (u_int8_t *data, int len); 198static int xe_compute_hashbit (u_int32_t crc); 199 200/* 201 * MII functions 202 */ 203static void xe_mii_sync (struct xe_softc *scp); 204static int xe_mii_init (struct xe_softc *scp); 205static void xe_mii_send (struct xe_softc *scp, u_int32_t bits, int cnt); 206static int xe_mii_readreg (struct xe_softc *scp, struct xe_mii_frame *frame); 207static int xe_mii_writereg (struct xe_softc *scp, struct xe_mii_frame *frame); 208static u_int16_t xe_phy_readreg (struct xe_softc *scp, u_int16_t reg); 209static void xe_phy_writereg (struct xe_softc *scp, u_int16_t reg, u_int16_t data); 210 211/* 212 * Debug functions 213 */ 214#ifdef XE_DEBUG 215#define XE_REG_DUMP(scp) xe_reg_dump((scp)) 216#define XE_MII_DUMP(scp) xe_mii_dump((scp)) 217static void xe_reg_dump (struct xe_softc *scp); 218static void xe_mii_dump (struct xe_softc *scp); 219#else 220#define XE_REG_DUMP(scp) 221#define XE_MII_DUMP(scp) 222#endif 223
|
280#if NAPM > 0
| |
281/*
| 224/*
|
282 * APM hook functions 283 */ 284static int xe_suspend (void *xunit); 285static int xe_resume (void *xunit); 286#endif /* NAPM > 0 */ 287 288 289/* 290 * PCMCIA driver hooks 291 */ 292#ifdef PCCARD_MODULE 293PCCARD_MODULE(xe, xe_card_init, xe_card_unload, xe_card_intr, 0, net_imask); 294#else 295static struct pccard_device xe_info = { /* For pre 3.1-STABLE code */ 296 "xe", 297 xe_card_init, 298 xe_card_unload, 299 xe_card_intr, 300 0, 301 &net_imask 302}; 303DATA_SET(pccarddrv_set, xe_info); 304#endif /* PCCARD_MODULE */ 305 306 307/* 308 * ISA driver hooks. I'd like to do without these but the kernel config stuff 309 * seems to require them. 310 */ 311struct isa_driver xedriver = { 312 xe_probe, 313 xe_attach, 314 "xe" 315}; 316 317 318 319/* 320 * ISA probe routine. 321 * All of the supported devices are PCMCIA cards. I have no idea if it's even 322 * possible to successfully probe/attach these at boot time (pccardd normally 323 * does a lot of setup work) so I don't even bother trying. 324 */ 325static int 326xe_probe (struct isa_device *dev) { 327#ifdef XE_DEBUG 328 printf("xe%d: probe\n", dev->id_unit); 329#endif 330 bzero(sca, MAXSLOT * sizeof(sca[0])); 331 return 0; 332} 333 334 335/*
| |
336 * Two routines to read from/write to the attribute memory 337 * the write portion is used only for fixing up the RealPort cards, 338 * the reader portion was needed for debugging info, and duplicated some 339 * code in xe_card_init(), so it appears here instead with suitable 340 * modifications to xe_card_init() 341 * -aDe Lovett 342 */ 343static int
| 225 * Two routines to read from/write to the attribute memory 226 * the write portion is used only for fixing up the RealPort cards, 227 * the reader portion was needed for debugging info, and duplicated some 228 * code in xe_card_init(), so it appears here instead with suitable 229 * modifications to xe_card_init() 230 * -aDe Lovett 231 */ 232static int
|
344xe_memwrite(struct pccard_devinfo *devi, off_t offset, u_char byte)
| 233xe_memwrite(device_t dev, off_t offset, u_char byte)
|
345{
| 234{
|
346 struct iovec iov; 347 struct uio uios; 348 349 iov.iov_base = &byte; 350 iov.iov_len = sizeof(byte); 351 352 uios.uio_iov = &iov; 353 uios.uio_iovcnt = 1; 354 uios.uio_offset = offset; 355 uios.uio_resid = sizeof(byte); 356 uios.uio_segflg = UIO_SYSSPACE; 357 uios.uio_rw = UIO_WRITE; 358 uios.uio_procp = 0; 359 360#if 0 /* THIS IS BOGUS */ 361 return cdevsw[CARD_MAJOR]->d_write(makedev(CARD_MAJOR, devi->slt->slotnum), &uios, 0); 362#else
| 235 /* XXX */
|
363 return (-1);
| 236 return (-1);
|
364#endif
| |
365} 366
| 237} 238
|
367 368static int 369xe_memread(struct pccard_devinfo *devi, off_t offset, u_char *buf, int size) 370{ 371 struct iovec iov; 372 struct uio uios; 373 374 iov.iov_base = buf; 375 iov.iov_len = size; 376 377 uios.uio_iov = &iov; 378 uios.uio_iovcnt = 1; 379 uios.uio_offset = offset; 380 uios.uio_resid = size; 381 uios.uio_segflg = UIO_SYSSPACE; 382 uios.uio_rw = UIO_READ; 383 uios.uio_procp = 0; 384 385#if 0 /* THIS IS BOGUS */ 386 return cdevsw[CARD_MAJOR]->d_read(makedev(CARD_MAJOR, devi->slt->slotnum), &uios, 0); 387#else 388 return (-1); 389#endif 390} 391 392
| |
393/* 394 * Hacking for RealPort cards 395 */ 396static int 397xe_cem56fix(struct xe_softc *scp) 398{
| 239/* 240 * Hacking for RealPort cards 241 */ 242static int 243xe_cem56fix(struct xe_softc *scp) 244{
|
399 struct pccard_devinfo *devi; 400 struct slot *slt; 401 struct slot_ctrl *ctrl;
| 245#if XXX /* Need to revisit */
|
402 int ioport, fail; 403
| 246 int ioport, fail; 247
|
404 /* initialise a few variables */ 405 devi = scp->crd; 406 slt = devi->slt; 407 ctrl = slt->ctrl; 408
| |
409 /* allocate a new I/O slot for the ethernet */ 410 /* XXX: ctrl->mapio() always appears to return 0 (success), so 411 * this may cause problems if another device is listening 412 * on 0x300 already. In this case, you should choose a 413 * known free I/O port address in the kernel config line 414 * for the driver. It will be picked up here and used 415 * instead of the autodetected value. 416 */ 417 slt->io[1].window = 1; 418 slt->io[1].flags = IODF_WS|IODF_16BIT|IODF_ZEROWS|IODF_ACTIVE; 419 slt->io[1].size = 0x10; 420 421#ifdef XE_IOBASE 422
| 248 /* allocate a new I/O slot for the ethernet */ 249 /* XXX: ctrl->mapio() always appears to return 0 (success), so 250 * this may cause problems if another device is listening 251 * on 0x300 already. In this case, you should choose a 252 * known free I/O port address in the kernel config line 253 * for the driver. It will be picked up here and used 254 * instead of the autodetected value. 255 */ 256 slt->io[1].window = 1; 257 slt->io[1].flags = IODF_WS|IODF_16BIT|IODF_ZEROWS|IODF_ACTIVE; 258 slt->io[1].size = 0x10; 259 260#ifdef XE_IOBASE 261
|
423 printf( "xe%d: user requested ioport 0x%x\n", scp->unit, XE_IOBASE );
| 262 device_printf(scp->dev, "user requested ioport 0x%x\n", XE_IOBASE );
|
424 ioport = XE_IOBASE; 425 slt->io[1].start = ioport; 426 fail = ctrl->mapio(slt, 1); 427 428#else 429 430 for (ioport = 0x300; ioport < 0x400; ioport += 0x10) { 431 slt->io[1].start = ioport; 432 if ((fail = ctrl->mapio( slt, 1 )) == 0) 433 break; 434 } 435 436#endif 437 438 /* did we find one? */ 439 if (fail) {
| 263 ioport = XE_IOBASE; 264 slt->io[1].start = ioport; 265 fail = ctrl->mapio(slt, 1); 266 267#else 268 269 for (ioport = 0x300; ioport < 0x400; ioport += 0x10) { 270 slt->io[1].start = ioport; 271 if ((fail = ctrl->mapio( slt, 1 )) == 0) 272 break; 273 } 274 275#endif 276 277 /* did we find one? */ 278 if (fail) {
|
440 printf( "xe%d: xe_cem56fix: no free address space\n", scp->unit );
| 279 device_printf(scp->dev, "xe_cem56fix: no free address space\n");
|
441 return -1; 442 } 443 444 445 /* munge the id_iobase entry for use by the rest of the driver */ 446#if XE_DEBUG > 1
| 280 return -1; 281 } 282 283 284 /* munge the id_iobase entry for use by the rest of the driver */ 285#if XE_DEBUG > 1
|
447 printf( "xe%d: using 0x%x for RealPort ethernet\n", scp->unit, ioport );
| 286 device_printf(scp->dev, "using 0x%x for RealPort ethernet\n", ioport);
|
448#endif
| 287#endif
|
| 288#if 0
|
449 scp->dev->id_iobase = ioport; 450 scp->dev->id_alive = 0x10;
| 289 scp->dev->id_iobase = ioport; 290 scp->dev->id_alive = 0x10;
|
| 291#endif
|
451 452 /* magic to set up the ethernet */
| 292 293 /* magic to set up the ethernet */
|
453 xe_memwrite( devi, DINGO_ECOR, DINGO_ECOR_IRQ_LEVEL|DINGO_ECOR_INT_ENABLE| 454 DINGO_ECOR_IOB_ENABLE|DINGO_ECOR_ETH_ENABLE ); 455 xe_memwrite( devi, DINGO_EBAR0, ioport & 0xff ); 456 xe_memwrite( devi, DINGO_EBAR1, (ioport >> 8) & 0xff );
| 294 xe_memwrite( scp->dev, DINGO_ECOR, DINGO_ECOR_IRQ_LEVEL| 295 DINGO_ECOR_INT_ENABLE|DINGO_ECOR_IOB_ENABLE| 296 DINGO_ECOR_ETH_ENABLE ); 297 xe_memwrite( scp->dev, DINGO_EBAR0, ioport & 0xff ); 298 xe_memwrite( scp->dev, DINGO_EBAR1, (ioport >> 8) & 0xff );
|
457
| 299
|
458 xe_memwrite( devi, DINGO_DCOR0, DINGO_DCOR0_SF_INT ); 459 xe_memwrite( devi, DINGO_DCOR1, DINGO_DCOR1_INT_LEVEL|DINGO_DCOR1_EEDIO ); 460 xe_memwrite( devi, DINGO_DCOR2, 0x00 ); 461 xe_memwrite( devi, DINGO_DCOR3, 0x00 ); 462 xe_memwrite( devi, DINGO_DCOR4, 0x00 );
| 300 xe_memwrite( scp->dev, DINGO_DCOR0, DINGO_DCOR0_SF_INT ); 301 xe_memwrite( scp->dev, DINGO_DCOR1, DINGO_DCOR1_INT_LEVEL|DINGO_DCOR1_EEDIO ); 302 xe_memwrite( scp->dev, DINGO_DCOR2, 0x00 ); 303 xe_memwrite( scp->dev, DINGO_DCOR3, 0x00 ); 304 xe_memwrite( scp->dev, DINGO_DCOR4, 0x00 );
|
463 464 /* success! */ 465 return 0;
| 305 306 /* success! */ 307 return 0;
|
| 308#else 309 return -1; 310#endif /* XXX */
|
466}
| 311}
|
467
| |
468 469/* 470 * PCMCIA probe routine. 471 * Probe and identify the device. Called by the slot manager when the card is 472 * inserted or the machine wakes up from suspend mode. Assmes that the slot 473 * structure has been initialised already. 474 */ 475static int
| 312 313/* 314 * PCMCIA probe routine. 315 * Probe and identify the device. Called by the slot manager when the card is 316 * inserted or the machine wakes up from suspend mode. Assmes that the slot 317 * structure has been initialised already. 318 */ 319static int
|
476xe_card_init(struct pccard_devinfo *devi)
| 320xe_probe(device_t dev)
|
477{
| 321{
|
478 struct xe_softc *scp; 479 struct isa_device *dev; 480 u_char buf[CISTPL_BUFSIZE];
| 322 struct xe_softc *scp = (struct xe_softc *) device_get_softc(dev); 323 u_char *buf;
|
481 u_char ver_str[CISTPL_BUFSIZE>>1]; 482 off_t offs;
| 324 u_char ver_str[CISTPL_BUFSIZE>>1]; 325 off_t offs;
|
483 int unit, success, rc, i;
| 326 int success, rc, i; 327 int rid; 328 struct resource *r;
|
484
| 329
|
485 unit = devi->isahd.id_unit; 486 scp = sca[unit]; 487 dev = &devi->isahd;
| |
488 success = 0; 489 490#ifdef XE_DEBUG
| 330 success = 0; 331 332#ifdef XE_DEBUG
|
491 printf("xe: Probing for unit %d\n", unit);
| 333 device_printf(dev, "xe: Probing\n");
|
492#endif 493
| 334#endif 335
|
494 /* Check that unit number is OK */ 495 if (unit > MAXSLOT) { 496 printf("xe%d: bad unit\n", unit); 497 return (ENODEV);
| 336 /* Map in the CIS */ 337 /* XXX This CANNOT work as it needs RF_PCCARD_ATTR support */ 338 r = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0, ~0, 4 << 10, RF_ACTIVE); 339 if (!r) { 340#ifdef XE_DEBUG 341 device_printf(dev, "Can't map in cis\n"); 342#endif 343 return ENOMEM;
|
498 }
| 344 }
|
| 345 buf = (u_char *) rman_get_start(r);
|
499
| 346
|
500 /* Don't attach an active device */ 501 if (scp && !scp->gone) { 502 printf("xe%d: already attached\n", unit); 503 return (EBUSY); 504 } 505 506 /* Allocate per-instance storage */ 507 if (!scp) { 508 if ((scp = malloc(sizeof(*scp), M_DEVBUF, M_NOWAIT)) == NULL) { 509 printf("xe%d: failed to allocage driver storage\n", unit); 510 return (ENOMEM); 511 } 512 bzero(scp, sizeof(*scp)); 513 } 514 515 /* Re-attach an existing device */ 516 if (scp->gone) { 517 scp->gone = 0; 518 return 0; 519 } 520
| |
521 /* Grep through CIS looking for relevant tuples */ 522 offs = 0; 523 do { 524 u_int16_t vendor; 525 u_int8_t rev, media, prod; 526
| 347 /* Grep through CIS looking for relevant tuples */ 348 offs = 0; 349 do { 350 u_int16_t vendor; 351 u_int8_t rev, media, prod; 352
|
527 /* 528 * Read tuples one at a time into buf. Sucks, but it only happens once. 529 * XXX - This assumes that attribute has been mapped by pccardd, which 530 * XXX - seems to be the default situation. If not, we're well and truly 531 * XXX - FUBAR. This is a general PCCARD problem, not our fault :) 532 */ 533 if ((rc = xe_memread( devi, offs, buf, CISTPL_BUFSIZE )) == 0) {
| 353 switch (CISTPL_TYPE(buf)) {
|
534
| 354
|
535 switch (CISTPL_TYPE(buf)) { 536 537 case 0x15: /* Grab version string (needed to ID some weird CE2's) */
| 355 case 0x15: /* Grab version string (needed to ID some weird CE2's) */
|
538#if XE_DEBUG > 1
| 356#if XE_DEBUG > 1
|
539 printf("xe%d: Got version string (0x15)\n", unit);
| 357 device_printf(dev, "Got version string (0x15)\n");
|
540#endif
| 358#endif
|
541 for (i = 0; i < CISTPL_LEN(buf); ver_str[i] = CISTPL_DATA(buf, i++)); 542 ver_str[i] = '\0'; 543 ver_str[(CISTPL_BUFSIZE>>1) - 1] = CISTPL_LEN(buf); 544 success++; 545 break;
| 359 for (i = 0; i < CISTPL_LEN(buf); ver_str[i] = CISTPL_DATA(buf, i++)); 360 ver_str[i] = '\0'; 361 ver_str[(CISTPL_BUFSIZE>>1) - 1] = CISTPL_LEN(buf); 362 success++; 363 break;
|
546
| 364
|
547 case 0x20: /* Figure out what type of card we have */
| 365 case 0x20: /* Figure out what type of card we have */
|
548#if XE_DEBUG > 1
| 366#if XE_DEBUG > 1
|
549 printf("xe%d: Got card ID (0x20)\n", unit);
| 367 device_printf(dev, "Got card ID (0x20)\n");
|
550#endif
| 368#endif
|
551 vendor = CISTPL_DATA(buf, 0) + (CISTPL_DATA(buf, 1) << 8); 552 rev = CISTPL_DATA(buf, 2); 553 media = CISTPL_DATA(buf, 3); 554 prod = CISTPL_DATA(buf, 4);
| 369 vendor = CISTPL_DATA(buf, 0) + (CISTPL_DATA(buf, 1) << 8); 370 rev = CISTPL_DATA(buf, 2); 371 media = CISTPL_DATA(buf, 3); 372 prod = CISTPL_DATA(buf, 4);
|
555
| 373
|
556 switch (vendor) { /* Get vendor ID */ 557 case 0x0105: 558 scp->vendor = "Xircom"; break; 559 case 0x0138: 560 case 0x0183: 561 scp->vendor = "Compaq"; break; 562 case 0x0089: 563 scp->vendor = "Intel"; break; 564 default: 565 scp->vendor = "Unknown"; 566 }
| 374 switch (vendor) { /* Get vendor ID */ 375 case 0x0105: 376 scp->vendor = "Xircom"; break; 377 case 0x0138: 378 case 0x0183: 379 scp->vendor = "Compaq"; break; 380 case 0x0089: 381 scp->vendor = "Intel"; break; 382 default: 383 scp->vendor = "Unknown"; 384 }
|
567
| 385
|
568 if (!((prod & 0x40) && (media & 0x01))) {
| 386 if (!((prod & 0x40) && (media & 0x01))) {
|
569#if XE_DEBUG > 1
| 387#if XE_DEBUG > 1
|
570 printf("xe%d: Not a PCMCIA Ethernet card!\n", unit);
| 388 device_printf(dev, "Not a PCMCIA Ethernet card!\n");
|
571#endif
| 389#endif
|
572 rc = ENODEV; /* Not a PCMCIA Ethernet device */ 573 } 574 else { 575 if (media & 0x10) { /* Ethernet/modem cards */
| 390 rc = ENODEV; /* Not a PCMCIA Ethernet device */ 391 } else { 392 if (media & 0x10) { /* Ethernet/modem cards */
|
576#if XE_DEBUG > 1
| 393#if XE_DEBUG > 1
|
577 printf("xe%d: Card is Ethernet/modem combo\n", unit);
| 394 device_printf(dev, "Card is Ethernet/modem combo\n");
|
578#endif
| 395#endif
|
579 scp->modem = 1; 580 switch (prod & 0x0f) { 581 case 1: 582 scp->card_type = "CEM"; break; 583 case 2: 584 scp->ce2 = 1; 585 scp->card_type = "CEM2"; break; 586 case 3: 587 scp->ce2 = 1; 588 scp->card_type = "CEM3"; break; 589 case 4: 590 scp->ce2 = 1; 591 scp->card_type = "CEM33"; break; 592 case 5: 593 scp->mohawk = 1; 594 scp->card_type = "CEM56M"; break; 595 case 6: 596 case 7: /* Some kind of RealPort card */ 597 scp->mohawk = 1; 598 scp->dingo = 1; 599 scp->card_type = "CEM56"; break; 600 default: 601 rc = ENODEV; 602 }
| 396 scp->modem = 1; 397 switch (prod & 0x0f) { 398 case 1: 399 scp->card_type = "CEM"; break; 400 case 2: 401 scp->ce2 = 1; 402 scp->card_type = "CEM2"; break; 403 case 3: 404 scp->ce2 = 1; 405 scp->card_type = "CEM3"; break; 406 case 4: 407 scp->ce2 = 1; 408 scp->card_type = "CEM33"; break; 409 case 5: 410 scp->mohawk = 1; 411 scp->card_type = "CEM56M"; break; 412 case 6: 413 case 7: /* Some kind of RealPort card */ 414 scp->mohawk = 1; 415 scp->dingo = 1; 416 scp->card_type = "CEM56"; break; 417 default: 418 rc = ENODEV;
|
603 }
| 419 }
|
604 else { /* Ethernet-only cards */
| 420 } else { /* Ethernet-only cards */
|
605#if XE_DEBUG > 1
| 421#if XE_DEBUG > 1
|
606 printf("xe%d: Card is Ethernet only\n", unit);
| 422 device_printf(dev, "Card is Ethernet only\n");
|
607#endif
| 423#endif
|
608 switch (prod & 0x0f) { 609 case 1: 610 scp->card_type = "CE"; break; 611 case 2: 612 scp->ce2 = 1; 613 scp->card_type = "CE2"; break; 614 case 3: 615 scp->mohawk = 1; 616 scp->card_type = "CE3"; break; 617 default: 618 rc = ENODEV; 619 }
| 424 switch (prod & 0x0f) { 425 case 1: 426 scp->card_type = "CE"; break; 427 case 2: 428 scp->ce2 = 1; 429 scp->card_type = "CE2"; break; 430 case 3: 431 scp->mohawk = 1; 432 scp->card_type = "CE3"; break; 433 default: 434 rc = ENODEV;
|
620 } 621 }
| 435 } 436 }
|
622 success++; 623 break;
| 437 } 438 success++; 439 break;
|
624
| 440
|
625 case 0x22: /* Get MAC address */ 626 if ((CISTPL_LEN(buf) == 8) && 627 (CISTPL_DATA(buf, 0) == 0x04) && 628 (CISTPL_DATA(buf, 1) == ETHER_ADDR_LEN)) {
| 441 case 0x22: /* Get MAC address */ 442 if ((CISTPL_LEN(buf) == 8) && 443 (CISTPL_DATA(buf, 0) == 0x04) && 444 (CISTPL_DATA(buf, 1) == ETHER_ADDR_LEN)) {
|
629#if XE_DEBUG > 1
| 445#if XE_DEBUG > 1
|
630 printf("xe%d: Got MAC address (0x22)\n", unit);
| 446 device_printf(dev, "Got MAC address (0x22)\n");
|
631#endif
| 447#endif
|
632 for (i = 0; i < ETHER_ADDR_LEN; scp->arpcom.ac_enaddr[i] = CISTPL_DATA(buf, i+2), i++); 633 } 634 success++; 635 break; 636 default:
| 448 for (i = 0; i < ETHER_ADDR_LEN; i++) 449 scp->arpcom.ac_enaddr[i] = CISTPL_DATA(buf, i+2);
|
637 }
| 450 }
|
| 451 success++; 452 break; 453 default: 454 break;
|
638 } 639
| 455 } 456
|
| 457 if (CISTPL_TYPE(buf) == 0xff) 458 break;
|
640 /* Skip to next tuple */
| 459 /* Skip to next tuple */
|
641 offs += ((CISTPL_LEN(buf) + 2) << 1);
| 460 buf += ((CISTPL_LEN(buf) + 2) << 1);
|
642
| 461
|
643 } while ((CISTPL_TYPE(buf) != 0xff) && (CISTPL_LEN(buf) != 0xff) && (rc == 0));
| 462 } while (1);
|
644
| 463
|
| 464 /* unmap the cis */ 465 bus_release_resource(dev, SYS_RES_MEMORY, rid, r);
|
645 646 /* Die now if something went wrong above */
| 466 467 /* Die now if something went wrong above */
|
647 if ((rc != 0) || (success < 3)) { 648 free(scp, M_DEVBUF); 649 return rc; 650 }
| 468 if (success < 3) 469 return ENXIO;
|
651 652 /* Check for certain strange CE2's that look like CE's */ 653 if (strcmp(scp->card_type, "CE") == 0) { 654 u_char *str = ver_str; 655#if XE_DEBUG > 1
| 470 471 /* Check for certain strange CE2's that look like CE's */ 472 if (strcmp(scp->card_type, "CE") == 0) { 473 u_char *str = ver_str; 474#if XE_DEBUG > 1
|
656 printf("xe%d: Checking for weird CE2 string\n", unit);
| 475 device_printf(dev, "Checking for weird CE2 string\n");
|
657#endif 658 str += strlen(str) + 1; /* Skip forward to 3rd version string */ 659 str += strlen(str) + 1; 660 str += strlen(str) + 1; 661 for (i = 0; i < strlen(str) - 2; i++) { 662 if (bcmp(&str[i], "CE2", 3) ==0) { /* Look for "CE2" string */ 663 scp->card_type = "CE2"; 664 } 665 } 666 } 667 668 /* Reject unsupported cards */ 669 if (strcmp(scp->card_type, "CE") == 0 || strcmp(scp->card_type, "CEM") == 0) {
| 476#endif 477 str += strlen(str) + 1; /* Skip forward to 3rd version string */ 478 str += strlen(str) + 1; 479 str += strlen(str) + 1; 480 for (i = 0; i < strlen(str) - 2; i++) { 481 if (bcmp(&str[i], "CE2", 3) ==0) { /* Look for "CE2" string */ 482 scp->card_type = "CE2"; 483 } 484 } 485 } 486 487 /* Reject unsupported cards */ 488 if (strcmp(scp->card_type, "CE") == 0 || strcmp(scp->card_type, "CEM") == 0) {
|
670 printf("xe%d: Sorry, your %s card is not supported :(\n", unit, scp->card_type); 671 free(scp, M_DEVBUF);
| 489 device_printf(dev, "Sorry, your %s card is not supported :(\n", 490 scp->card_type);
|
672 return ENODEV; 673 } 674
| 491 return ENODEV; 492 } 493
|
| 494 /* Success */ 495 return 0; 496} 497 498/* 499 * The device entry is being removed, probably because someone ejected the 500 * card. The interface should have been brought down manually before calling 501 * this function; if not you may well lose packets. In any case, I shut down 502 * the card and the interface, and hope for the best. 503 */ 504static int 505xe_detach(device_t dev) { 506 struct xe_softc *sc = device_get_softc(dev); 507 508 sc->arpcom.ac_if.if_flags &= ~IFF_RUNNING; 509 if_detach(&sc->arpcom.ac_if); 510 xe_deactivate(dev); 511 return 0; 512} 513 514/* 515 * Attach a device. 516 */ 517static int 518xe_attach (device_t dev) { 519 struct xe_softc *scp = device_get_softc(dev); 520 521#ifdef XE_DEBUG 522 device_printf(dev, "attach\n"); 523#endif 524 525 xe_activate(dev); 526
|
675 /* Fill in some private data */
| 527 /* Fill in some private data */
|
676 sca[unit] = scp; 677 scp->dev = &devi->isahd; 678 scp->crd = devi;
| |
679 scp->ifp = &scp->arpcom.ac_if; 680 scp->ifm = &scp->ifmedia;
| 528 scp->ifp = &scp->arpcom.ac_if; 529 scp->ifm = &scp->ifmedia;
|
681 scp->unit = unit;
| |
682 scp->autoneg_status = 0; 683 684 /* Hack RealPorts into submission */ 685 if (scp->dingo && xe_cem56fix(scp) < 0) {
| 530 scp->autoneg_status = 0; 531 532 /* Hack RealPorts into submission */ 533 if (scp->dingo && xe_cem56fix(scp) < 0) {
|
686 printf( "xe%d: Unable to fix your RealPort\n", unit ); 687 sca[unit] = 0; 688 free(scp, M_DEVBUF);
| 534 device_printf(dev, "Unable to fix your RealPort\n"); 535 xe_deactivate(dev);
|
689 return ENODEV; 690 } 691 692 /* Hopefully safe to read this here */ 693 XE_SELECT_PAGE(4); 694 scp->version = XE_INB(XE_BOV); 695
| 536 return ENODEV; 537 } 538 539 /* Hopefully safe to read this here */ 540 XE_SELECT_PAGE(4); 541 scp->version = XE_INB(XE_BOV); 542
|
696 /* Attempt to attach the device */ 697 if (!xe_attach(scp->dev)) { 698 sca[unit] = 0; 699 free(scp, M_DEVBUF); 700 return ENXIO; 701 } 702 703#if NAPM > 0 704 /* Establish APM hooks once device attached */ 705 scp->suspend_hook.ah_name = "xe_suspend"; 706 scp->suspend_hook.ah_fun = xe_suspend; 707 scp->suspend_hook.ah_arg = (void *)unit; 708 scp->suspend_hook.ah_order = APM_MIN_ORDER; 709 apm_hook_establish(APM_HOOK_SUSPEND, &scp->suspend_hook); 710 scp->resume_hook.ah_name = "xe_resume"; 711 scp->resume_hook.ah_fun = xe_resume; 712 scp->resume_hook.ah_arg = (void *)unit; 713 scp->resume_hook.ah_order = APM_MIN_ORDER; 714 apm_hook_establish(APM_HOOK_RESUME, &scp->resume_hook); 715#endif /* NAPM > 0 */ 716 717 /* Success */ 718 return 0; 719} 720 721 722/* 723 * Attach a device (called when xe_card_init succeeds). Assume that the probe 724 * routine has set up the softc structure correctly and that we can trust the 725 * unit number. 726 */ 727static int 728xe_attach (struct isa_device *dev) { 729 struct xe_softc *scp = sca[dev->id_unit]; 730 int i; 731 732#ifdef XE_DEBUG 733 printf("xe%d: attach\n", scp->unit); 734#endif 735
| 543 scp->dev = dev;
|
736 /* Initialise the ifnet structure */ 737 if (!scp->ifp->if_name) { 738 scp->ifp->if_softc = scp; 739 scp->ifp->if_name = "xe";
| 544 /* Initialise the ifnet structure */ 545 if (!scp->ifp->if_name) { 546 scp->ifp->if_softc = scp; 547 scp->ifp->if_name = "xe";
|
740 scp->ifp->if_unit = scp->unit;
| 548 scp->ifp->if_unit = device_get_unit(dev);
|
741 scp->ifp->if_timer = 0; 742 scp->ifp->if_flags = (IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST); 743 scp->ifp->if_linkmib = &scp->mibdata; 744 scp->ifp->if_linkmiblen = sizeof scp->mibdata; 745 scp->ifp->if_output = ether_output; 746 scp->ifp->if_start = xe_start; 747 scp->ifp->if_ioctl = xe_ioctl; 748 scp->ifp->if_watchdog = xe_watchdog; 749 scp->ifp->if_init = xe_init; 750 scp->ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; 751 } 752 753 /* Initialise the ifmedia structure */ 754 ifmedia_init(scp->ifm, 0, xe_media_change, xe_media_status); 755 callout_handle_init(&scp->chand); 756 757 /* 758 * Fill in supported media types. Some cards _do_ support full duplex 759 * operation, but this driver doesn't, yet. Therefore we leave those modes 760 * out of the list. We support some form of autoselection in all cases. 761 */ 762 if (scp->mohawk) { 763 ifmedia_add(scp->ifm, IFM_ETHER|IFM_100_TX, 0, NULL); 764 ifmedia_add(scp->ifm, IFM_ETHER|IFM_10_T, 0, NULL); 765 } 766 else { 767 ifmedia_add(scp->ifm, IFM_ETHER|IFM_10_T, 0, NULL); 768 ifmedia_add(scp->ifm, IFM_ETHER|IFM_10_2, 0, NULL); 769 } 770 ifmedia_add(scp->ifm, IFM_ETHER|IFM_AUTO, 0, NULL); 771 772 /* Default is to autoselect best supported media type */ 773 ifmedia_set(scp->ifm, IFM_ETHER|IFM_AUTO); 774 775 /* Print some useful information */
| 549 scp->ifp->if_timer = 0; 550 scp->ifp->if_flags = (IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST); 551 scp->ifp->if_linkmib = &scp->mibdata; 552 scp->ifp->if_linkmiblen = sizeof scp->mibdata; 553 scp->ifp->if_output = ether_output; 554 scp->ifp->if_start = xe_start; 555 scp->ifp->if_ioctl = xe_ioctl; 556 scp->ifp->if_watchdog = xe_watchdog; 557 scp->ifp->if_init = xe_init; 558 scp->ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; 559 } 560 561 /* Initialise the ifmedia structure */ 562 ifmedia_init(scp->ifm, 0, xe_media_change, xe_media_status); 563 callout_handle_init(&scp->chand); 564 565 /* 566 * Fill in supported media types. Some cards _do_ support full duplex 567 * operation, but this driver doesn't, yet. Therefore we leave those modes 568 * out of the list. We support some form of autoselection in all cases. 569 */ 570 if (scp->mohawk) { 571 ifmedia_add(scp->ifm, IFM_ETHER|IFM_100_TX, 0, NULL); 572 ifmedia_add(scp->ifm, IFM_ETHER|IFM_10_T, 0, NULL); 573 } 574 else { 575 ifmedia_add(scp->ifm, IFM_ETHER|IFM_10_T, 0, NULL); 576 ifmedia_add(scp->ifm, IFM_ETHER|IFM_10_2, 0, NULL); 577 } 578 ifmedia_add(scp->ifm, IFM_ETHER|IFM_AUTO, 0, NULL); 579 580 /* Default is to autoselect best supported media type */ 581 ifmedia_set(scp->ifm, IFM_ETHER|IFM_AUTO); 582 583 /* Print some useful information */
|
776 printf("\n"); 777 printf("xe%d: %s %s, bonding version %#x%s%s\n", 778 scp->unit,
| 584 device_printf(dev, "%s %s, bonding version %#x%s%s\n",
|
779 scp->vendor, 780 scp->card_type, 781 scp->version, 782 scp->mohawk ? ", 100Mbps capable" : "", 783 scp->modem ? ", with modem" : ""); 784 if (scp->mohawk) { 785 XE_SELECT_PAGE(0x10);
| 585 scp->vendor, 586 scp->card_type, 587 scp->version, 588 scp->mohawk ? ", 100Mbps capable" : "", 589 scp->modem ? ", with modem" : ""); 590 if (scp->mohawk) { 591 XE_SELECT_PAGE(0x10);
|
786 printf("xe%d: DingoID = %#x, RevisionID = %#x, VendorID = %#x\n", 787 scp->unit,
| 592 device_printf(dev, "DingoID = %#x, RevisionID = %#x, VendorID = %#x\n",
|
788 XE_INW(XE_DINGOID), 789 XE_INW(XE_RevID), 790 XE_INW(XE_VendorID)); 791 } 792 if (scp->ce2) { 793 XE_SELECT_PAGE(0x45);
| 593 XE_INW(XE_DINGOID), 594 XE_INW(XE_RevID), 595 XE_INW(XE_VendorID)); 596 } 597 if (scp->ce2) { 598 XE_SELECT_PAGE(0x45);
|
794 printf("xe%d: CE2 version = %#x\n", 795 scp->unit, 796 XE_INB(XE_REV));
| 599 device_printf(dev, "CE2 version = %#x\n", XE_INB(XE_REV));
|
797 } 798 799 /* Print MAC address */
| 600 } 601 602 /* Print MAC address */
|
800 printf("xe%d: Ethernet address %02x", scp->unit, scp->arpcom.ac_enaddr[0]); 801 for (i = 1; i < ETHER_ADDR_LEN; i++) { 802 printf(":%02x", scp->arpcom.ac_enaddr[i]); 803 } 804 printf("\n");
| 603 device_printf(dev, "Ethernet address %6D\n", scp->arpcom.ac_enaddr, ":");
|
805 806 /* Attach the interface */ 807 if_attach(scp->ifp); 808 ether_ifattach(scp->ifp); 809
| 604 605 /* Attach the interface */ 606 if_attach(scp->ifp); 607 ether_ifattach(scp->ifp); 608
|
810 /* If BPF is in the kernel, call the attach for it */
| 609 /* BPF is in the kernel, call the attach for it */
|
811#if XE_DEBUG > 1
| 610#if XE_DEBUG > 1
|
812 printf("xe%d: BPF listener attached\n", scp->unit);
| 611 device_printf(dev, "BPF listener attached\n");
|
813#endif 814 bpfattach(scp->ifp, DLT_EN10MB, sizeof(struct ether_header)); 815 816 /* Done */ 817 return 1; 818} 819 820 821/* 822 * Initialize device. Completes the reset procedure on the card and starts 823 * output. If there's an autonegotiation in progress we DON'T do anything; 824 * the media selection code will call us again when it's done. 825 */ 826static void 827xe_init(void *xscp) { 828 struct xe_softc *scp = xscp; 829 int s; 830 831#ifdef XE_DEBUG
| 612#endif 613 bpfattach(scp->ifp, DLT_EN10MB, sizeof(struct ether_header)); 614 615 /* Done */ 616 return 1; 617} 618 619 620/* 621 * Initialize device. Completes the reset procedure on the card and starts 622 * output. If there's an autonegotiation in progress we DON'T do anything; 623 * the media selection code will call us again when it's done. 624 */ 625static void 626xe_init(void *xscp) { 627 struct xe_softc *scp = xscp; 628 int s; 629 630#ifdef XE_DEBUG
|
832 printf("xe%d: init\n", scp->unit);
| 631 device_printf(scp->dev, "init\n");
|
833#endif 834
| 632#endif 633
|
835 if (scp->gone) return; 836
| |
837 if (TAILQ_EMPTY(&scp->ifp->if_addrhead)) return; 838 839 /* Reset transmitter flags */ 840 scp->tx_queued = 0; 841 scp->tx_tpr = 0; 842 scp->tx_collisions = 0; 843 scp->ifp->if_timer = 0; 844 845 s = splimp(); 846 847 XE_SELECT_PAGE(0x42); 848 XE_OUTB(XE_SWC0, 0x20); /* Disable source insertion (WTF is that?) */ 849 850 /* 851 * Set the 'local memory dividing line' -- splits the 32K card memory into 852 * 8K for transmit buffers and 24K for receive. This is done automatically 853 * on newer revision cards. 854 */ 855 if (scp->srev != 1) { 856 XE_SELECT_PAGE(2); 857 XE_OUTW(XE_RBS, 0x2000); 858 } 859 860 /* Set up multicast addresses */ 861 xe_setmulti(scp); 862 863 /* Fix the data offset register -- reset leaves it off-by-one */ 864 XE_SELECT_PAGE(0); 865 XE_OUTW(XE_DO, 0x2000); 866 867 /* 868 * Set MAC interrupt masks and clear status regs. The bit names are direct 869 * from the Linux code; I have no idea what most of them do. 870 */ 871 XE_SELECT_PAGE(0x40); /* Bit 7..0 */ 872 XE_OUTB(XE_RX0Msk, 0xff); /* ROK, RAB, rsv, RO, CRC, AE, PTL, MP */ 873 XE_OUTB(XE_TX0Msk, 0xff); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */ 874 XE_OUTB(XE_TX0Msk+1, 0xb0); /* rsv, rsv, PTD, EXT, rsv, rsv, rsv, rsv */ 875 XE_OUTB(XE_RST0, 0x00); /* ROK, RAB, REN, RO, CRC, AE, PTL, MP */ 876 XE_OUTB(XE_TXST0, 0x00); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */ 877 XE_OUTB(XE_TXST1, 0x00); /* TEN, rsv, PTD, EXT, retry_counter:4 */ 878 879 /* 880 * Check for an in-progress autonegotiation. If one is active, just set 881 * IFF_RUNNING and return. The media selection code will call us again when 882 * it's done. 883 */ 884 if (scp->autoneg_status) { 885 scp->ifp->if_flags |= IFF_RUNNING; 886 } 887 else { 888 /* Enable receiver, put MAC online */ 889 XE_SELECT_PAGE(0x40); 890 XE_OUTB(XE_CMD0, XE_CMD0_RX_ENABLE|XE_CMD0_ONLINE); 891 892 /* Set up IMR, enable interrupts */ 893 xe_enable_intr(scp); 894 895 /* Attempt to start output */ 896 scp->ifp->if_flags |= IFF_RUNNING; 897 scp->ifp->if_flags &= ~IFF_OACTIVE; 898 xe_start(scp->ifp); 899 } 900 901 (void)splx(s); 902} 903 904 905/* 906 * Start output on interface. We make two assumptions here: 907 * 1) that the current priority is set to splimp _before_ this code 908 * is called *and* is returned to the appropriate priority after 909 * return 910 * 2) that the IFF_OACTIVE flag is checked before this code is called 911 * (i.e. that the output part of the interface is idle) 912 */ 913static void 914xe_start(struct ifnet *ifp) { 915 struct xe_softc *scp = ifp->if_softc; 916 struct mbuf *mbp; 917
| 634 if (TAILQ_EMPTY(&scp->ifp->if_addrhead)) return; 635 636 /* Reset transmitter flags */ 637 scp->tx_queued = 0; 638 scp->tx_tpr = 0; 639 scp->tx_collisions = 0; 640 scp->ifp->if_timer = 0; 641 642 s = splimp(); 643 644 XE_SELECT_PAGE(0x42); 645 XE_OUTB(XE_SWC0, 0x20); /* Disable source insertion (WTF is that?) */ 646 647 /* 648 * Set the 'local memory dividing line' -- splits the 32K card memory into 649 * 8K for transmit buffers and 24K for receive. This is done automatically 650 * on newer revision cards. 651 */ 652 if (scp->srev != 1) { 653 XE_SELECT_PAGE(2); 654 XE_OUTW(XE_RBS, 0x2000); 655 } 656 657 /* Set up multicast addresses */ 658 xe_setmulti(scp); 659 660 /* Fix the data offset register -- reset leaves it off-by-one */ 661 XE_SELECT_PAGE(0); 662 XE_OUTW(XE_DO, 0x2000); 663 664 /* 665 * Set MAC interrupt masks and clear status regs. The bit names are direct 666 * from the Linux code; I have no idea what most of them do. 667 */ 668 XE_SELECT_PAGE(0x40); /* Bit 7..0 */ 669 XE_OUTB(XE_RX0Msk, 0xff); /* ROK, RAB, rsv, RO, CRC, AE, PTL, MP */ 670 XE_OUTB(XE_TX0Msk, 0xff); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */ 671 XE_OUTB(XE_TX0Msk+1, 0xb0); /* rsv, rsv, PTD, EXT, rsv, rsv, rsv, rsv */ 672 XE_OUTB(XE_RST0, 0x00); /* ROK, RAB, REN, RO, CRC, AE, PTL, MP */ 673 XE_OUTB(XE_TXST0, 0x00); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */ 674 XE_OUTB(XE_TXST1, 0x00); /* TEN, rsv, PTD, EXT, retry_counter:4 */ 675 676 /* 677 * Check for an in-progress autonegotiation. If one is active, just set 678 * IFF_RUNNING and return. The media selection code will call us again when 679 * it's done. 680 */ 681 if (scp->autoneg_status) { 682 scp->ifp->if_flags |= IFF_RUNNING; 683 } 684 else { 685 /* Enable receiver, put MAC online */ 686 XE_SELECT_PAGE(0x40); 687 XE_OUTB(XE_CMD0, XE_CMD0_RX_ENABLE|XE_CMD0_ONLINE); 688 689 /* Set up IMR, enable interrupts */ 690 xe_enable_intr(scp); 691 692 /* Attempt to start output */ 693 scp->ifp->if_flags |= IFF_RUNNING; 694 scp->ifp->if_flags &= ~IFF_OACTIVE; 695 xe_start(scp->ifp); 696 } 697 698 (void)splx(s); 699} 700 701 702/* 703 * Start output on interface. We make two assumptions here: 704 * 1) that the current priority is set to splimp _before_ this code 705 * is called *and* is returned to the appropriate priority after 706 * return 707 * 2) that the IFF_OACTIVE flag is checked before this code is called 708 * (i.e. that the output part of the interface is idle) 709 */ 710static void 711xe_start(struct ifnet *ifp) { 712 struct xe_softc *scp = ifp->if_softc; 713 struct mbuf *mbp; 714
|
918 if (scp->gone) return; 919
| |
920 /* 921 * Loop while there are packets to be sent, and space to send them. 922 */ 923 while (1) { 924 IF_DEQUEUE(&ifp->if_snd, mbp); /* Suck a packet off the send queue */ 925 926 if (mbp == NULL) { 927 /* 928 * We are using the !OACTIVE flag to indicate to the outside world that 929 * we can accept an additional packet rather than that the transmitter 930 * is _actually_ active. Indeed, the transmitter may be active, but if 931 * we haven't filled all the buffers with data then we still want to 932 * accept more. 933 */ 934 ifp->if_flags &= ~IFF_OACTIVE; 935 return; 936 } 937 938 if (xe_pio_write_packet(scp, mbp) != 0) { 939 IF_PREPEND(&ifp->if_snd, mbp); /* Push the packet back onto the queue */ 940 ifp->if_flags |= IFF_OACTIVE; 941 return; 942 } 943 944 /* Tap off here if there is a bpf listener */ 945 if (ifp->if_bpf) { 946#if XE_DEBUG > 1
| 715 /* 716 * Loop while there are packets to be sent, and space to send them. 717 */ 718 while (1) { 719 IF_DEQUEUE(&ifp->if_snd, mbp); /* Suck a packet off the send queue */ 720 721 if (mbp == NULL) { 722 /* 723 * We are using the !OACTIVE flag to indicate to the outside world that 724 * we can accept an additional packet rather than that the transmitter 725 * is _actually_ active. Indeed, the transmitter may be active, but if 726 * we haven't filled all the buffers with data then we still want to 727 * accept more. 728 */ 729 ifp->if_flags &= ~IFF_OACTIVE; 730 return; 731 } 732 733 if (xe_pio_write_packet(scp, mbp) != 0) { 734 IF_PREPEND(&ifp->if_snd, mbp); /* Push the packet back onto the queue */ 735 ifp->if_flags |= IFF_OACTIVE; 736 return; 737 } 738 739 /* Tap off here if there is a bpf listener */ 740 if (ifp->if_bpf) { 741#if XE_DEBUG > 1
|
947 printf("xe%d: sending output packet to BPF\n", scp->unit);
| 742 device_printf(scp->dev, "sending output packet to BPF\n");
|
948#endif 949 bpf_mtap(ifp, mbp); 950 } 951 952 ifp->if_timer = 5; /* In case we don't hear from the card again */ 953 scp->tx_queued++; 954 955 m_freem(mbp); 956 } 957} 958 959 960/* 961 * Process an ioctl request. Adapted from the ed driver. 962 */ 963static int 964xe_ioctl (register struct ifnet *ifp, u_long command, caddr_t data) { 965 struct xe_softc *scp; 966 int s, error; 967 968 scp = ifp->if_softc; 969 error = 0; 970
| 743#endif 744 bpf_mtap(ifp, mbp); 745 } 746 747 ifp->if_timer = 5; /* In case we don't hear from the card again */ 748 scp->tx_queued++; 749 750 m_freem(mbp); 751 } 752} 753 754 755/* 756 * Process an ioctl request. Adapted from the ed driver. 757 */ 758static int 759xe_ioctl (register struct ifnet *ifp, u_long command, caddr_t data) { 760 struct xe_softc *scp; 761 int s, error; 762 763 scp = ifp->if_softc; 764 error = 0; 765
|
971 if (scp->gone) { 972 return ENXIO; 973 } 974
| |
975 s = splimp(); 976 977 switch (command) { 978 979 case SIOCSIFADDR: 980 case SIOCGIFADDR: 981 case SIOCSIFMTU: 982 error = ether_ioctl(ifp, command, data); 983 break; 984 985 case SIOCSIFFLAGS: 986 /* 987 * If the interface is marked up and stopped, then start it. If it is 988 * marked down and running, then stop it. 989 */ 990 if (ifp->if_flags & IFF_UP) { 991 if (!(ifp->if_flags & IFF_RUNNING)) { 992 xe_hard_reset(scp); 993 xe_setmedia(scp); 994 xe_init(scp); 995 } 996 } 997 else { 998 if (ifp->if_flags & IFF_RUNNING) 999 xe_stop(scp); 1000 } 1001 1002 case SIOCADDMULTI: 1003 case SIOCDELMULTI: 1004 /* 1005 * Multicast list has (maybe) changed; set the hardware filter 1006 * accordingly. This also serves to deal with promiscuous mode if we have 1007 * a BPF listener active. 1008 */ 1009 xe_setmulti(scp); 1010 error = 0; 1011 break; 1012 1013 case SIOCSIFMEDIA: 1014 case SIOCGIFMEDIA: 1015 /* 1016 * Someone wants to get/set media options. 1017 */ 1018 error = ifmedia_ioctl(ifp, (struct ifreq *)data, &scp->ifmedia, command); 1019 break; 1020 1021 default: 1022 error = EINVAL; 1023 } 1024 1025 (void)splx(s); 1026 1027 return error; 1028} 1029 1030 1031/*
| 766 s = splimp(); 767 768 switch (command) { 769 770 case SIOCSIFADDR: 771 case SIOCGIFADDR: 772 case SIOCSIFMTU: 773 error = ether_ioctl(ifp, command, data); 774 break; 775 776 case SIOCSIFFLAGS: 777 /* 778 * If the interface is marked up and stopped, then start it. If it is 779 * marked down and running, then stop it. 780 */ 781 if (ifp->if_flags & IFF_UP) { 782 if (!(ifp->if_flags & IFF_RUNNING)) { 783 xe_hard_reset(scp); 784 xe_setmedia(scp); 785 xe_init(scp); 786 } 787 } 788 else { 789 if (ifp->if_flags & IFF_RUNNING) 790 xe_stop(scp); 791 } 792 793 case SIOCADDMULTI: 794 case SIOCDELMULTI: 795 /* 796 * Multicast list has (maybe) changed; set the hardware filter 797 * accordingly. This also serves to deal with promiscuous mode if we have 798 * a BPF listener active. 799 */ 800 xe_setmulti(scp); 801 error = 0; 802 break; 803 804 case SIOCSIFMEDIA: 805 case SIOCGIFMEDIA: 806 /* 807 * Someone wants to get/set media options. 808 */ 809 error = ifmedia_ioctl(ifp, (struct ifreq *)data, &scp->ifmedia, command); 810 break; 811 812 default: 813 error = EINVAL; 814 } 815 816 (void)splx(s); 817 818 return error; 819} 820 821 822/*
|
1032 * Card interrupt handler: should return true if the interrupt was for us, in 1033 * case we are sharing our IRQ line with other devices (this will probably be 1034 * the case for multifunction cards).
| 823 * Card interrupt handler.
|
1035 * 1036 * This function is probably more complicated than it needs to be, as it 1037 * attempts to deal with the case where multiple packets get sent between 1038 * interrupts. This is especially annoying when working out the collision 1039 * stats. Not sure whether this case ever really happens or not (maybe on a 1040 * slow/heavily loaded machine?) so it's probably best to leave this like it 1041 * is. 1042 * 1043 * Note that the crappy PIO used to get packets on and off the card means that 1044 * you will spend a lot of time in this routine -- I can get my P150 to spend 1045 * 90% of its time servicing interrupts if I really hammer the network. Could 1046 * fix this, but then you'd start dropping/losing packets. The moral of this 1047 * story? If you want good network performance _and_ some cycles left over to 1048 * get your work done, don't buy a Xircom card. Or convince them to tell me 1049 * how to do memory-mapped I/O :) 1050 */
| 824 * 825 * This function is probably more complicated than it needs to be, as it 826 * attempts to deal with the case where multiple packets get sent between 827 * interrupts. This is especially annoying when working out the collision 828 * stats. Not sure whether this case ever really happens or not (maybe on a 829 * slow/heavily loaded machine?) so it's probably best to leave this like it 830 * is. 831 * 832 * Note that the crappy PIO used to get packets on and off the card means that 833 * you will spend a lot of time in this routine -- I can get my P150 to spend 834 * 90% of its time servicing interrupts if I really hammer the network. Could 835 * fix this, but then you'd start dropping/losing packets. The moral of this 836 * story? If you want good network performance _and_ some cycles left over to 837 * get your work done, don't buy a Xircom card. Or convince them to tell me 838 * how to do memory-mapped I/O :) 839 */
|
1051static int 1052xe_card_intr(struct pccard_devinfo *devi) { 1053 struct xe_softc *scp;
| 840static void 841xe_intr(void *xscp) 842{ 843 struct xe_softc *scp = (struct xe_softc *) xscp;
|
1054 struct ifnet *ifp;
| 844 struct ifnet *ifp;
|
1055 int unit, result;
| 845 int result;
|
1056 u_int16_t rx_bytes, rxs, txs; 1057 u_int8_t psr, isr, esr, rsr; 1058
| 846 u_int16_t rx_bytes, rxs, txs; 847 u_int8_t psr, isr, esr, rsr; 848
|
1059 unit = devi->isahd.id_unit; 1060 scp = sca[unit];
| |
1061 ifp = &scp->arpcom.ac_if; 1062 rx_bytes = 0; /* Bytes received on this interrupt */ 1063 result = 0; /* Set true if the interrupt is for us */ 1064
| 849 ifp = &scp->arpcom.ac_if; 850 rx_bytes = 0; /* Bytes received on this interrupt */ 851 result = 0; /* Set true if the interrupt is for us */ 852
|
1065 if (scp->gone) 1066 return 0; 1067
| |
1068 if (scp->mohawk) { 1069 XE_OUTB(XE_CR, 0); /* Disable interrupts */ 1070 } 1071 1072 psr = XE_INB(XE_PR); /* Stash the current register page */ 1073 1074 /* 1075 * Read ISR to see what caused this interrupt. Note that this clears the 1076 * ISR on CE2 type cards. 1077 */ 1078 if ((isr = XE_INB(XE_ISR)) && isr != 0xff) { 1079 1080 result = 1; /* This device did generate an int */ 1081 esr = XE_INB(XE_ESR); /* Read the other status registers */ 1082 XE_SELECT_PAGE(0x40); 1083 rxs = XE_INB(XE_RST0); 1084 XE_OUTB(XE_RST0, ~rxs & 0xff); 1085 txs = XE_INB(XE_TXST0); 1086 txs |= XE_INB(XE_TXST1) << 8; 1087 XE_OUTB(XE_TXST0, 0); 1088 XE_OUTB(XE_TXST1, 0); 1089 XE_SELECT_PAGE(0); 1090 1091#if XE_DEBUG > 2 1092 printf("xe%d: ISR=%#2.2x ESR=%#2.2x RST=%#2.2x TXST=%#4.4x\n", unit, isr, esr, rxs, txs); 1093#endif 1094 1095 /* 1096 * Handle transmit interrupts 1097 */ 1098 if (isr & XE_ISR_TX_PACKET) { 1099 u_int8_t new_tpr, sent; 1100 1101 if ((new_tpr = XE_INB(XE_TPR)) < scp->tx_tpr) /* Update packet count */ 1102 sent = (0xff - scp->tx_tpr) + new_tpr; /* TPR rolled over */ 1103 else 1104 sent = new_tpr - scp->tx_tpr; 1105 1106 if (sent > 0) { /* Packets sent since last interrupt */ 1107 scp->tx_tpr = new_tpr; 1108 scp->tx_queued -= sent; 1109 ifp->if_opackets += sent; 1110 ifp->if_collisions += scp->tx_collisions; 1111 1112 /* 1113 * Collision stats are a PITA. If multiples frames have been sent, we 1114 * distribute any outstanding collision count equally amongst them. 1115 * However, if we're missing interrupts we're quite likely to also 1116 * miss some collisions; thus the total count will be off anyway. 1117 * Likewise, if we miss a frame dropped due to excessive collisions 1118 * any outstanding collisions count will be held against the next 1119 * frame to be successfully sent. Hopefully it averages out in the 1120 * end! 1121 * XXX - This will screw up if tx_collisions/sent > 14. FIX IT! 1122 */ 1123 switch (scp->tx_collisions) { 1124 case 0: 1125 break; 1126 case 1: 1127 scp->mibdata.dot3StatsSingleCollisionFrames++; 1128 scp->mibdata.dot3StatsCollFrequencies[0]++; 1129 break; 1130 default: 1131 if (sent == 1) { 1132 scp->mibdata.dot3StatsMultipleCollisionFrames++; 1133 scp->mibdata.dot3StatsCollFrequencies[scp->tx_collisions-1]++; 1134 } 1135 else { /* Distribute across multiple frames */ 1136 scp->mibdata.dot3StatsMultipleCollisionFrames += sent; 1137 scp->mibdata. 1138 dot3StatsCollFrequencies[scp->tx_collisions/sent] += sent - scp->tx_collisions%sent; 1139 scp->mibdata. 1140 dot3StatsCollFrequencies[scp->tx_collisions/sent + 1] += scp->tx_collisions%sent; 1141 } 1142 } 1143 scp->tx_collisions = 0; 1144 } 1145 ifp->if_timer = 0; 1146 ifp->if_flags &= ~IFF_OACTIVE; 1147 } 1148 if (txs & 0x0002) { /* Excessive collisions (packet dropped) */ 1149 ifp->if_collisions += 16; 1150 ifp->if_oerrors++; 1151 scp->tx_collisions = 0; 1152 scp->mibdata.dot3StatsExcessiveCollisions++; 1153 scp->mibdata.dot3StatsMultipleCollisionFrames++; 1154 scp->mibdata.dot3StatsCollFrequencies[15]++; 1155 XE_OUTB(XE_CR, XE_CR_RESTART_TX); 1156 } 1157 if (txs & 0x0040) /* Transmit aborted -- probably collisions */ 1158 scp->tx_collisions++; 1159 1160 1161 /* 1162 * Handle receive interrupts 1163 */ 1164 while ((esr = XE_INB(XE_ESR)) & XE_ESR_FULL_PACKET_RX) { 1165 1166 if ((rsr = XE_INB(XE_RSR)) & XE_RSR_RX_OK) { 1167 struct ether_header *ehp; 1168 struct mbuf *mbp; 1169 u_int16_t len; 1170 1171 len = XE_INW(XE_RBC); 1172 1173 if (len == 0) 1174 continue; 1175 1176#if 0 1177 /* 1178 * Limit the amount of time we spend in this loop, dropping packets if 1179 * necessary. The Linux code does this with considerably more 1180 * finesse, adjusting the threshold dynamically. 1181 */ 1182 if ((rx_bytes += len) > 22000) { 1183 ifp->if_iqdrops++; 1184 scp->mibData.dot3StatsMissedFrames++; 1185 XE_OUTW(XE_DO, 0x8000); 1186 continue; 1187 } 1188#endif 1189 1190 if (len & 0x01) 1191 len++; 1192 1193 MGETHDR(mbp, M_DONTWAIT, MT_DATA); /* Allocate a header mbuf */ 1194 if (mbp != NULL) { 1195 mbp->m_pkthdr.rcvif = ifp; 1196 mbp->m_pkthdr.len = mbp->m_len = len; 1197 1198 /* 1199 * If the mbuf header isn't big enough for the packet, attach an 1200 * mbuf cluster to hold it. The +2 is to allow for the nasty little 1201 * alignment hack below. 1202 */ 1203 if (len + 2 > MHLEN) { 1204 MCLGET(mbp, M_DONTWAIT); 1205 if ((mbp->m_flags & M_EXT) == 0) { 1206 m_freem(mbp); 1207 mbp = NULL; 1208 } 1209 } 1210 } 1211 1212 if (mbp != NULL) { 1213 /* 1214 * The Ethernet header is 14 bytes long; thus the actual packet data 1215 * won't be 32-bit aligned when it's dumped into the mbuf. We 1216 * offset everything by 2 bytes to fix this. Apparently the 1217 * alignment is important for NFS, damn its eyes. 1218 */ 1219 mbp->m_data += 2; 1220 ehp = mtod(mbp, struct ether_header *); 1221 1222 /* 1223 * Now get the packet, including the Ethernet header and trailer (?) 1224 * We use programmed I/O, because we don't know how to do shared 1225 * memory with these cards. So yes, it's real slow, and heavy on 1226 * the interrupts (CPU on my P150 maxed out at ~950KBps incoming). 1227 */ 1228 if (scp->srev == 0) { /* Workaround a bug in old cards */ 1229 u_short rhs; 1230 1231 XE_SELECT_PAGE(5); 1232 rhs = XE_INW(XE_RHSA); 1233 XE_SELECT_PAGE(0); 1234 1235 rhs += 3; /* Skip control info */ 1236 1237 if (rhs >= 0x8000) 1238 rhs = 0; 1239 1240 if (rhs + len > 0x8000) { 1241 int i; 1242 1243 /* 1244 * XXX - This i-- seems very wrong, but it's what the Linux guys 1245 * XXX - do. Need someone with an old CE2 to test this for me. 1246 * XXX - 99/3/28: Changed the first i-- to an i++, maybe that'll 1247 * XXX - fix it? It seems as though the previous version would 1248 * XXX - have caused an infinite loop (what, another one?). 1249 */ 1250 for (i = 0; i < len; i++, rhs++) { 1251 ((char *)ehp)[i] = XE_INB(XE_EDP); 1252 if (rhs == 0x8000) { 1253 rhs = 0; 1254 i--; 1255 } 1256 } 1257 } 1258 else
| 853 if (scp->mohawk) { 854 XE_OUTB(XE_CR, 0); /* Disable interrupts */ 855 } 856 857 psr = XE_INB(XE_PR); /* Stash the current register page */ 858 859 /* 860 * Read ISR to see what caused this interrupt. Note that this clears the 861 * ISR on CE2 type cards. 862 */ 863 if ((isr = XE_INB(XE_ISR)) && isr != 0xff) { 864 865 result = 1; /* This device did generate an int */ 866 esr = XE_INB(XE_ESR); /* Read the other status registers */ 867 XE_SELECT_PAGE(0x40); 868 rxs = XE_INB(XE_RST0); 869 XE_OUTB(XE_RST0, ~rxs & 0xff); 870 txs = XE_INB(XE_TXST0); 871 txs |= XE_INB(XE_TXST1) << 8; 872 XE_OUTB(XE_TXST0, 0); 873 XE_OUTB(XE_TXST1, 0); 874 XE_SELECT_PAGE(0); 875 876#if XE_DEBUG > 2 877 printf("xe%d: ISR=%#2.2x ESR=%#2.2x RST=%#2.2x TXST=%#4.4x\n", unit, isr, esr, rxs, txs); 878#endif 879 880 /* 881 * Handle transmit interrupts 882 */ 883 if (isr & XE_ISR_TX_PACKET) { 884 u_int8_t new_tpr, sent; 885 886 if ((new_tpr = XE_INB(XE_TPR)) < scp->tx_tpr) /* Update packet count */ 887 sent = (0xff - scp->tx_tpr) + new_tpr; /* TPR rolled over */ 888 else 889 sent = new_tpr - scp->tx_tpr; 890 891 if (sent > 0) { /* Packets sent since last interrupt */ 892 scp->tx_tpr = new_tpr; 893 scp->tx_queued -= sent; 894 ifp->if_opackets += sent; 895 ifp->if_collisions += scp->tx_collisions; 896 897 /* 898 * Collision stats are a PITA. If multiples frames have been sent, we 899 * distribute any outstanding collision count equally amongst them. 900 * However, if we're missing interrupts we're quite likely to also 901 * miss some collisions; thus the total count will be off anyway. 902 * Likewise, if we miss a frame dropped due to excessive collisions 903 * any outstanding collisions count will be held against the next 904 * frame to be successfully sent. Hopefully it averages out in the 905 * end! 906 * XXX - This will screw up if tx_collisions/sent > 14. FIX IT! 907 */ 908 switch (scp->tx_collisions) { 909 case 0: 910 break; 911 case 1: 912 scp->mibdata.dot3StatsSingleCollisionFrames++; 913 scp->mibdata.dot3StatsCollFrequencies[0]++; 914 break; 915 default: 916 if (sent == 1) { 917 scp->mibdata.dot3StatsMultipleCollisionFrames++; 918 scp->mibdata.dot3StatsCollFrequencies[scp->tx_collisions-1]++; 919 } 920 else { /* Distribute across multiple frames */ 921 scp->mibdata.dot3StatsMultipleCollisionFrames += sent; 922 scp->mibdata. 923 dot3StatsCollFrequencies[scp->tx_collisions/sent] += sent - scp->tx_collisions%sent; 924 scp->mibdata. 925 dot3StatsCollFrequencies[scp->tx_collisions/sent + 1] += scp->tx_collisions%sent; 926 } 927 } 928 scp->tx_collisions = 0; 929 } 930 ifp->if_timer = 0; 931 ifp->if_flags &= ~IFF_OACTIVE; 932 } 933 if (txs & 0x0002) { /* Excessive collisions (packet dropped) */ 934 ifp->if_collisions += 16; 935 ifp->if_oerrors++; 936 scp->tx_collisions = 0; 937 scp->mibdata.dot3StatsExcessiveCollisions++; 938 scp->mibdata.dot3StatsMultipleCollisionFrames++; 939 scp->mibdata.dot3StatsCollFrequencies[15]++; 940 XE_OUTB(XE_CR, XE_CR_RESTART_TX); 941 } 942 if (txs & 0x0040) /* Transmit aborted -- probably collisions */ 943 scp->tx_collisions++; 944 945 946 /* 947 * Handle receive interrupts 948 */ 949 while ((esr = XE_INB(XE_ESR)) & XE_ESR_FULL_PACKET_RX) { 950 951 if ((rsr = XE_INB(XE_RSR)) & XE_RSR_RX_OK) { 952 struct ether_header *ehp; 953 struct mbuf *mbp; 954 u_int16_t len; 955 956 len = XE_INW(XE_RBC); 957 958 if (len == 0) 959 continue; 960 961#if 0 962 /* 963 * Limit the amount of time we spend in this loop, dropping packets if 964 * necessary. The Linux code does this with considerably more 965 * finesse, adjusting the threshold dynamically. 966 */ 967 if ((rx_bytes += len) > 22000) { 968 ifp->if_iqdrops++; 969 scp->mibData.dot3StatsMissedFrames++; 970 XE_OUTW(XE_DO, 0x8000); 971 continue; 972 } 973#endif 974 975 if (len & 0x01) 976 len++; 977 978 MGETHDR(mbp, M_DONTWAIT, MT_DATA); /* Allocate a header mbuf */ 979 if (mbp != NULL) { 980 mbp->m_pkthdr.rcvif = ifp; 981 mbp->m_pkthdr.len = mbp->m_len = len; 982 983 /* 984 * If the mbuf header isn't big enough for the packet, attach an 985 * mbuf cluster to hold it. The +2 is to allow for the nasty little 986 * alignment hack below. 987 */ 988 if (len + 2 > MHLEN) { 989 MCLGET(mbp, M_DONTWAIT); 990 if ((mbp->m_flags & M_EXT) == 0) { 991 m_freem(mbp); 992 mbp = NULL; 993 } 994 } 995 } 996 997 if (mbp != NULL) { 998 /* 999 * The Ethernet header is 14 bytes long; thus the actual packet data 1000 * won't be 32-bit aligned when it's dumped into the mbuf. We 1001 * offset everything by 2 bytes to fix this. Apparently the 1002 * alignment is important for NFS, damn its eyes. 1003 */ 1004 mbp->m_data += 2; 1005 ehp = mtod(mbp, struct ether_header *); 1006 1007 /* 1008 * Now get the packet, including the Ethernet header and trailer (?) 1009 * We use programmed I/O, because we don't know how to do shared 1010 * memory with these cards. So yes, it's real slow, and heavy on 1011 * the interrupts (CPU on my P150 maxed out at ~950KBps incoming). 1012 */ 1013 if (scp->srev == 0) { /* Workaround a bug in old cards */ 1014 u_short rhs; 1015 1016 XE_SELECT_PAGE(5); 1017 rhs = XE_INW(XE_RHSA); 1018 XE_SELECT_PAGE(0); 1019 1020 rhs += 3; /* Skip control info */ 1021 1022 if (rhs >= 0x8000) 1023 rhs = 0; 1024 1025 if (rhs + len > 0x8000) { 1026 int i; 1027 1028 /* 1029 * XXX - This i-- seems very wrong, but it's what the Linux guys 1030 * XXX - do. Need someone with an old CE2 to test this for me. 1031 * XXX - 99/3/28: Changed the first i-- to an i++, maybe that'll 1032 * XXX - fix it? It seems as though the previous version would 1033 * XXX - have caused an infinite loop (what, another one?). 1034 */ 1035 for (i = 0; i < len; i++, rhs++) { 1036 ((char *)ehp)[i] = XE_INB(XE_EDP); 1037 if (rhs == 0x8000) { 1038 rhs = 0; 1039 i--; 1040 } 1041 } 1042 } 1043 else
|
1259 insw(scp->dev->id_iobase+XE_EDP, ehp, len >> 1);
| 1044 bus_space_read_multi_2(scp->bst, scp->bsh, XE_EDP, 1045 (u_int16_t *) ehp, len >> 1);
|
1260 } 1261 else
| 1046 } 1047 else
|
1262 insw(scp->dev->id_iobase+XE_EDP, ehp, len >> 1);
| 1048 bus_space_read_multi_2(scp->bst, scp->bsh, XE_EDP, 1049 (u_int16_t *) ehp, len >> 1);
|
1263 1264 /* 1265 * Check if there's a BPF listener on this interface. If so, hand 1266 * off the raw packet to bpf. 1267 */ 1268 if (ifp->if_bpf) { 1269#if XE_DEBUG > 1
| 1050 1051 /* 1052 * Check if there's a BPF listener on this interface. If so, hand 1053 * off the raw packet to bpf. 1054 */ 1055 if (ifp->if_bpf) { 1056#if XE_DEBUG > 1
|
1270 printf("xe%d: passing input packet to BPF\n", scp->unit);
| 1057 device_printf(scp->dev, "passing input packet to BPF\n");
|
1271#endif 1272 bpf_mtap(ifp, mbp); 1273 1274 /* 1275 * Note that the interface cannot be in promiscuous mode if there 1276 * are no BPF listeners. And if we are in promiscuous mode, we 1277 * have to check if this packet is really ours. 1278 */ 1279 if ((ifp->if_flags & IFF_PROMISC) && 1280 bcmp(ehp->ether_dhost, scp->arpcom.ac_enaddr, sizeof(ehp->ether_dhost)) != 0 && 1281 (rsr & XE_RSR_PHYS_PACKET)) { 1282 m_freem(mbp); 1283 mbp = NULL; 1284 } 1285 } 1286 1287 if (mbp != NULL) { 1288 mbp->m_pkthdr.len = mbp->m_len = len - ETHER_HDR_LEN; 1289 mbp->m_data += ETHER_HDR_LEN; /* Strip off Ethernet header */ 1290 ether_input(ifp, ehp, mbp); /* Send the packet on its way */ 1291 ifp->if_ipackets++; /* Success! */ 1292 } 1293 XE_OUTW(XE_DO, 0x8000); /* skip_rx_packet command */ 1294 } 1295 } 1296 else if (rsr & XE_RSR_LONG_PACKET) { /* Packet length >1518 bytes */ 1297 scp->mibdata.dot3StatsFrameTooLongs++; 1298 ifp->if_ierrors++; 1299 } 1300 else if (rsr & XE_RSR_CRC_ERROR) { /* Bad checksum on packet */ 1301 scp->mibdata.dot3StatsFCSErrors++; 1302 ifp->if_ierrors++; 1303 } 1304 else if (rsr & XE_RSR_ALIGN_ERROR) { /* Packet alignment error */ 1305 scp->mibdata.dot3StatsAlignmentErrors++; 1306 ifp->if_ierrors++; 1307 } 1308 } 1309 if (rxs & 0x10) { /* Receiver overrun */ 1310 scp->mibdata.dot3StatsInternalMacReceiveErrors++; 1311 ifp->if_ierrors++; 1312 XE_OUTB(XE_CR, XE_CR_CLEAR_OVERRUN); 1313 } 1314 } 1315 1316 XE_SELECT_PAGE(psr); /* Restore saved page */ 1317 XE_OUTB(XE_CR, XE_CR_ENABLE_INTR); /* Re-enable interrupts */ 1318 1319 /* Could force an int here, instead of dropping packets? */ 1320 /* XE_OUTB(XE_CR, XE_CR_ENABLE_INTR|XE_CE_FORCE_INTR); */ 1321
| 1058#endif 1059 bpf_mtap(ifp, mbp); 1060 1061 /* 1062 * Note that the interface cannot be in promiscuous mode if there 1063 * are no BPF listeners. And if we are in promiscuous mode, we 1064 * have to check if this packet is really ours. 1065 */ 1066 if ((ifp->if_flags & IFF_PROMISC) && 1067 bcmp(ehp->ether_dhost, scp->arpcom.ac_enaddr, sizeof(ehp->ether_dhost)) != 0 && 1068 (rsr & XE_RSR_PHYS_PACKET)) { 1069 m_freem(mbp); 1070 mbp = NULL; 1071 } 1072 } 1073 1074 if (mbp != NULL) { 1075 mbp->m_pkthdr.len = mbp->m_len = len - ETHER_HDR_LEN; 1076 mbp->m_data += ETHER_HDR_LEN; /* Strip off Ethernet header */ 1077 ether_input(ifp, ehp, mbp); /* Send the packet on its way */ 1078 ifp->if_ipackets++; /* Success! */ 1079 } 1080 XE_OUTW(XE_DO, 0x8000); /* skip_rx_packet command */ 1081 } 1082 } 1083 else if (rsr & XE_RSR_LONG_PACKET) { /* Packet length >1518 bytes */ 1084 scp->mibdata.dot3StatsFrameTooLongs++; 1085 ifp->if_ierrors++; 1086 } 1087 else if (rsr & XE_RSR_CRC_ERROR) { /* Bad checksum on packet */ 1088 scp->mibdata.dot3StatsFCSErrors++; 1089 ifp->if_ierrors++; 1090 } 1091 else if (rsr & XE_RSR_ALIGN_ERROR) { /* Packet alignment error */ 1092 scp->mibdata.dot3StatsAlignmentErrors++; 1093 ifp->if_ierrors++; 1094 } 1095 } 1096 if (rxs & 0x10) { /* Receiver overrun */ 1097 scp->mibdata.dot3StatsInternalMacReceiveErrors++; 1098 ifp->if_ierrors++; 1099 XE_OUTB(XE_CR, XE_CR_CLEAR_OVERRUN); 1100 } 1101 } 1102 1103 XE_SELECT_PAGE(psr); /* Restore saved page */ 1104 XE_OUTB(XE_CR, XE_CR_ENABLE_INTR); /* Re-enable interrupts */ 1105 1106 /* Could force an int here, instead of dropping packets? */ 1107 /* XE_OUTB(XE_CR, XE_CR_ENABLE_INTR|XE_CE_FORCE_INTR); */ 1108
|
1322 return result;
| 1109 return;
|
1323} 1324 1325 1326/* 1327 * Device timeout/watchdog routine. Called automatically if we queue a packet 1328 * for transmission but don't get an interrupt within a specified timeout 1329 * (usually 5 seconds). When this happens we assume the worst and reset the 1330 * card. 1331 */ 1332static void 1333xe_watchdog(struct ifnet *ifp) { 1334 struct xe_softc *scp = ifp->if_softc; 1335
| 1110} 1111 1112 1113/* 1114 * Device timeout/watchdog routine. Called automatically if we queue a packet 1115 * for transmission but don't get an interrupt within a specified timeout 1116 * (usually 5 seconds). When this happens we assume the worst and reset the 1117 * card. 1118 */ 1119static void 1120xe_watchdog(struct ifnet *ifp) { 1121 struct xe_softc *scp = ifp->if_softc; 1122
|
1336 if (scp->gone) return; 1337 1338 printf("xe%d: watchdog timeout; resetting card\n", scp->unit);
| 1123 device_printf(scp->dev, "watchdog timeout; resetting card\n");
|
1339 scp->tx_timeouts++; 1340 ifp->if_oerrors += scp->tx_queued; 1341 xe_stop(scp); 1342 xe_hard_reset(scp); 1343 xe_setmedia(scp); 1344 xe_init(scp); 1345} 1346 1347 1348/* 1349 * Change media selection. 1350 */ 1351static int 1352xe_media_change(struct ifnet *ifp) { 1353 struct xe_softc *scp = ifp->if_softc; 1354 1355#ifdef XE_DEBUG 1356 printf("xe%d: media_change\n", ifp->if_unit); 1357#endif 1358 1359 if (IFM_TYPE(scp->ifm->ifm_media) != IFM_ETHER) 1360 return(EINVAL); 1361 1362 /* 1363 * Some card/media combos aren't always possible -- filter those out here. 1364 */ 1365 if ((IFM_SUBTYPE(scp->ifm->ifm_media) == IFM_AUTO || 1366 IFM_SUBTYPE(scp->ifm->ifm_media) == IFM_100_TX) && !scp->phy_ok) 1367 return (EINVAL); 1368 1369 xe_setmedia(scp); 1370 1371 return 0; 1372} 1373 1374 1375/* 1376 * Return current media selection. 1377 */ 1378static void 1379xe_media_status(struct ifnet *ifp, struct ifmediareq *mrp) { 1380 1381#ifdef XE_DEBUG 1382 printf("xe%d: media_status\n", ifp->if_unit); 1383#endif 1384 1385 mrp->ifm_active = ((struct xe_softc *)ifp->if_softc)->media; 1386 1387 return; 1388} 1389 1390 1391/* 1392 * Select active media. 1393 */ 1394static void xe_setmedia(void *xscp) { 1395 struct xe_softc *scp = xscp; 1396 u_int16_t bmcr, bmsr, anar, lpar; 1397 1398#ifdef XE_DEBUG
| 1124 scp->tx_timeouts++; 1125 ifp->if_oerrors += scp->tx_queued; 1126 xe_stop(scp); 1127 xe_hard_reset(scp); 1128 xe_setmedia(scp); 1129 xe_init(scp); 1130} 1131 1132 1133/* 1134 * Change media selection. 1135 */ 1136static int 1137xe_media_change(struct ifnet *ifp) { 1138 struct xe_softc *scp = ifp->if_softc; 1139 1140#ifdef XE_DEBUG 1141 printf("xe%d: media_change\n", ifp->if_unit); 1142#endif 1143 1144 if (IFM_TYPE(scp->ifm->ifm_media) != IFM_ETHER) 1145 return(EINVAL); 1146 1147 /* 1148 * Some card/media combos aren't always possible -- filter those out here. 1149 */ 1150 if ((IFM_SUBTYPE(scp->ifm->ifm_media) == IFM_AUTO || 1151 IFM_SUBTYPE(scp->ifm->ifm_media) == IFM_100_TX) && !scp->phy_ok) 1152 return (EINVAL); 1153 1154 xe_setmedia(scp); 1155 1156 return 0; 1157} 1158 1159 1160/* 1161 * Return current media selection. 1162 */ 1163static void 1164xe_media_status(struct ifnet *ifp, struct ifmediareq *mrp) { 1165 1166#ifdef XE_DEBUG 1167 printf("xe%d: media_status\n", ifp->if_unit); 1168#endif 1169 1170 mrp->ifm_active = ((struct xe_softc *)ifp->if_softc)->media; 1171 1172 return; 1173} 1174 1175 1176/* 1177 * Select active media. 1178 */ 1179static void xe_setmedia(void *xscp) { 1180 struct xe_softc *scp = xscp; 1181 u_int16_t bmcr, bmsr, anar, lpar; 1182 1183#ifdef XE_DEBUG
|
1399 printf("xe%d: setmedia\n", scp->unit);
| 1184 device_printf(scp->dev, "setmedia\n");
|
1400#endif 1401 1402 /* Cancel any pending timeout */ 1403 untimeout(xe_setmedia, scp, scp->chand); 1404 xe_disable_intr(scp); 1405 1406 /* Select media */ 1407 scp->media = IFM_ETHER; 1408 switch (IFM_SUBTYPE(scp->ifm->ifm_media)) { 1409 1410 case IFM_AUTO: /* Autoselect media */ 1411 scp->media = IFM_ETHER|IFM_AUTO; 1412 1413 /* 1414 * Autoselection is really awful. It goes something like this: 1415 * 1416 * Wait until the transmitter goes idle (2sec timeout). 1417 * Reset card 1418 * IF a 100Mbit PHY exists 1419 * Start NWAY autonegotiation (3.5sec timeout) 1420 * IF that succeeds 1421 * Select 100baseTX or 10baseT, whichever was detected 1422 * ELSE 1423 * Reset card 1424 * IF a 100Mbit PHY exists 1425 * Try to force a 100baseTX link (3sec timeout) 1426 * IF that succeeds 1427 * Select 100baseTX 1428 * ELSE 1429 * Disable the PHY 1430 * ENDIF 1431 * ENDIF 1432 * ENDIF 1433 * ENDIF 1434 * IF nothing selected so far 1435 * IF a 100Mbit PHY exists 1436 * Select 10baseT 1437 * ELSE 1438 * Select 10baseT or 10base2, whichever is connected 1439 * ENDIF 1440 * ENDIF 1441 */ 1442 switch (scp->autoneg_status) { 1443 1444 case XE_AUTONEG_NONE: 1445#if XE_DEBUG > 1
| 1185#endif 1186 1187 /* Cancel any pending timeout */ 1188 untimeout(xe_setmedia, scp, scp->chand); 1189 xe_disable_intr(scp); 1190 1191 /* Select media */ 1192 scp->media = IFM_ETHER; 1193 switch (IFM_SUBTYPE(scp->ifm->ifm_media)) { 1194 1195 case IFM_AUTO: /* Autoselect media */ 1196 scp->media = IFM_ETHER|IFM_AUTO; 1197 1198 /* 1199 * Autoselection is really awful. It goes something like this: 1200 * 1201 * Wait until the transmitter goes idle (2sec timeout). 1202 * Reset card 1203 * IF a 100Mbit PHY exists 1204 * Start NWAY autonegotiation (3.5sec timeout) 1205 * IF that succeeds 1206 * Select 100baseTX or 10baseT, whichever was detected 1207 * ELSE 1208 * Reset card 1209 * IF a 100Mbit PHY exists 1210 * Try to force a 100baseTX link (3sec timeout) 1211 * IF that succeeds 1212 * Select 100baseTX 1213 * ELSE 1214 * Disable the PHY 1215 * ENDIF 1216 * ENDIF 1217 * ENDIF 1218 * ENDIF 1219 * IF nothing selected so far 1220 * IF a 100Mbit PHY exists 1221 * Select 10baseT 1222 * ELSE 1223 * Select 10baseT or 10base2, whichever is connected 1224 * ENDIF 1225 * ENDIF 1226 */ 1227 switch (scp->autoneg_status) { 1228 1229 case XE_AUTONEG_NONE: 1230#if XE_DEBUG > 1
|
1446 printf("xe%d: Waiting for idle transmitter\n", scp->unit);
| 1231 device_printf(scp->dev, "Waiting for idle transmitter\n");
|
1447#endif 1448 scp->arpcom.ac_if.if_flags |= IFF_OACTIVE; 1449 scp->autoneg_status = XE_AUTONEG_WAITING; 1450 scp->chand = timeout(xe_setmedia, scp, hz * 2); 1451 return; 1452 1453 case XE_AUTONEG_WAITING: 1454 xe_soft_reset(scp); 1455 if (scp->phy_ok) { 1456#if XE_DEBUG > 1
| 1232#endif 1233 scp->arpcom.ac_if.if_flags |= IFF_OACTIVE; 1234 scp->autoneg_status = XE_AUTONEG_WAITING; 1235 scp->chand = timeout(xe_setmedia, scp, hz * 2); 1236 return; 1237 1238 case XE_AUTONEG_WAITING: 1239 xe_soft_reset(scp); 1240 if (scp->phy_ok) { 1241#if XE_DEBUG > 1
|
1457 printf("xe%d: Starting autonegotiation\n", scp->unit);
| 1242 device_printf(scp->dev, "Starting autonegotiation\n");
|
1458#endif 1459 bmcr = xe_phy_readreg(scp, PHY_BMCR); 1460 bmcr &= ~(PHY_BMCR_AUTONEGENBL); 1461 xe_phy_writereg(scp, PHY_BMCR, bmcr); 1462 anar = xe_phy_readreg(scp, PHY_ANAR); 1463 anar &= ~(PHY_ANAR_100BT4|PHY_ANAR_100BTXFULL|PHY_ANAR_10BTFULL); 1464 anar |= PHY_ANAR_100BTXHALF|PHY_ANAR_10BTHALF; 1465 xe_phy_writereg(scp, PHY_ANAR, anar); 1466 bmcr |= PHY_BMCR_AUTONEGENBL|PHY_BMCR_AUTONEGRSTR; 1467 xe_phy_writereg(scp, PHY_BMCR, bmcr); 1468 scp->autoneg_status = XE_AUTONEG_STARTED; 1469 scp->chand = timeout(xe_setmedia, scp, hz * 7/2); 1470 return; 1471 } 1472 else { 1473 scp->autoneg_status = XE_AUTONEG_FAIL; 1474 } 1475 break; 1476 1477 case XE_AUTONEG_STARTED: 1478 bmsr = xe_phy_readreg(scp, PHY_BMSR); 1479 lpar = xe_phy_readreg(scp, PHY_LPAR); 1480 if (bmsr & (PHY_BMSR_AUTONEGCOMP|PHY_BMSR_LINKSTAT)) { 1481#if XE_DEBUG > 1
| 1243#endif 1244 bmcr = xe_phy_readreg(scp, PHY_BMCR); 1245 bmcr &= ~(PHY_BMCR_AUTONEGENBL); 1246 xe_phy_writereg(scp, PHY_BMCR, bmcr); 1247 anar = xe_phy_readreg(scp, PHY_ANAR); 1248 anar &= ~(PHY_ANAR_100BT4|PHY_ANAR_100BTXFULL|PHY_ANAR_10BTFULL); 1249 anar |= PHY_ANAR_100BTXHALF|PHY_ANAR_10BTHALF; 1250 xe_phy_writereg(scp, PHY_ANAR, anar); 1251 bmcr |= PHY_BMCR_AUTONEGENBL|PHY_BMCR_AUTONEGRSTR; 1252 xe_phy_writereg(scp, PHY_BMCR, bmcr); 1253 scp->autoneg_status = XE_AUTONEG_STARTED; 1254 scp->chand = timeout(xe_setmedia, scp, hz * 7/2); 1255 return; 1256 } 1257 else { 1258 scp->autoneg_status = XE_AUTONEG_FAIL; 1259 } 1260 break; 1261 1262 case XE_AUTONEG_STARTED: 1263 bmsr = xe_phy_readreg(scp, PHY_BMSR); 1264 lpar = xe_phy_readreg(scp, PHY_LPAR); 1265 if (bmsr & (PHY_BMSR_AUTONEGCOMP|PHY_BMSR_LINKSTAT)) { 1266#if XE_DEBUG > 1
|
1482 printf("xe%d: Autonegotiation complete!\n", scp->unit);
| 1267 device_printf(scp->dev, "Autonegotiation complete!\n");
|
1483#endif 1484 /* 1485 * XXX - Shouldn't have to do this, but (on my hub at least) the 1486 * XXX - transmitter won't work after a successful autoneg. So we see 1487 * XXX - what the negotiation result was and force that mode. I'm 1488 * XXX - sure there is an easy fix for this. 1489 */ 1490 if (lpar & PHY_LPAR_100BTXHALF) { 1491 xe_phy_writereg(scp, PHY_BMCR, PHY_BMCR_SPEEDSEL); 1492 XE_MII_DUMP(scp); 1493 XE_SELECT_PAGE(2); 1494 XE_OUTB(XE_MSR, XE_INB(XE_MSR) | 0x08); 1495 scp->media = IFM_ETHER|IFM_100_TX; 1496 scp->autoneg_status = XE_AUTONEG_NONE; 1497 } 1498 else { 1499 /* 1500 * XXX - Bit of a hack going on in here. 1501 * XXX - This is derived from Ken Hughes patch to the Linux driver 1502 * XXX - to make it work with 10Mbit _autonegotiated_ links on CE3B 1503 * XXX - cards. What's a CE3B and how's it differ from a plain CE3? 1504 * XXX - these are the things we need to find out. 1505 */ 1506 xe_phy_writereg(scp, PHY_BMCR, 0x0000); 1507 XE_SELECT_PAGE(2); 1508 /* BEGIN HACK */ 1509 XE_OUTB(XE_MSR, XE_INB(XE_MSR) | 0x08); 1510 XE_SELECT_PAGE(0x42); 1511 XE_OUTB(XE_SWC1, 0x80); 1512 scp->media = IFM_ETHER|IFM_10_T; 1513 scp->autoneg_status = XE_AUTONEG_NONE; 1514 /* END HACK */ 1515 /*XE_OUTB(XE_MSR, XE_INB(XE_MSR) & ~0x08);*/ /* Disable PHY? */ 1516 /*scp->autoneg_status = XE_AUTONEG_FAIL;*/ 1517 } 1518 } 1519 else { 1520#if XE_DEBUG > 1
| 1268#endif 1269 /* 1270 * XXX - Shouldn't have to do this, but (on my hub at least) the 1271 * XXX - transmitter won't work after a successful autoneg. So we see 1272 * XXX - what the negotiation result was and force that mode. I'm 1273 * XXX - sure there is an easy fix for this. 1274 */ 1275 if (lpar & PHY_LPAR_100BTXHALF) { 1276 xe_phy_writereg(scp, PHY_BMCR, PHY_BMCR_SPEEDSEL); 1277 XE_MII_DUMP(scp); 1278 XE_SELECT_PAGE(2); 1279 XE_OUTB(XE_MSR, XE_INB(XE_MSR) | 0x08); 1280 scp->media = IFM_ETHER|IFM_100_TX; 1281 scp->autoneg_status = XE_AUTONEG_NONE; 1282 } 1283 else { 1284 /* 1285 * XXX - Bit of a hack going on in here. 1286 * XXX - This is derived from Ken Hughes patch to the Linux driver 1287 * XXX - to make it work with 10Mbit _autonegotiated_ links on CE3B 1288 * XXX - cards. What's a CE3B and how's it differ from a plain CE3? 1289 * XXX - these are the things we need to find out. 1290 */ 1291 xe_phy_writereg(scp, PHY_BMCR, 0x0000); 1292 XE_SELECT_PAGE(2); 1293 /* BEGIN HACK */ 1294 XE_OUTB(XE_MSR, XE_INB(XE_MSR) | 0x08); 1295 XE_SELECT_PAGE(0x42); 1296 XE_OUTB(XE_SWC1, 0x80); 1297 scp->media = IFM_ETHER|IFM_10_T; 1298 scp->autoneg_status = XE_AUTONEG_NONE; 1299 /* END HACK */ 1300 /*XE_OUTB(XE_MSR, XE_INB(XE_MSR) & ~0x08);*/ /* Disable PHY? */ 1301 /*scp->autoneg_status = XE_AUTONEG_FAIL;*/ 1302 } 1303 } 1304 else { 1305#if XE_DEBUG > 1
|
1521 printf("xe%d: Autonegotiation failed; trying 100baseTX\n", scp->unit);
| 1306 device_printf(scp->dev, "Autonegotiation failed; trying 100baseTX\n");
|
1522#endif 1523 XE_MII_DUMP(scp); 1524 xe_soft_reset(scp); 1525 if (scp->phy_ok) { 1526 xe_phy_writereg(scp, PHY_BMCR, PHY_BMCR_SPEEDSEL); 1527 scp->autoneg_status = XE_AUTONEG_100TX; 1528 scp->chand = timeout(xe_setmedia, scp, hz * 3); 1529 return; 1530 } 1531 else { 1532 scp->autoneg_status = XE_AUTONEG_FAIL; 1533 } 1534 } 1535 break; 1536 1537 case XE_AUTONEG_100TX: 1538 (void)xe_phy_readreg(scp, PHY_BMSR); 1539 bmsr = xe_phy_readreg(scp, PHY_BMSR); 1540 if (bmsr & PHY_BMSR_LINKSTAT) { 1541#if XE_DEBUG > 1
| 1307#endif 1308 XE_MII_DUMP(scp); 1309 xe_soft_reset(scp); 1310 if (scp->phy_ok) { 1311 xe_phy_writereg(scp, PHY_BMCR, PHY_BMCR_SPEEDSEL); 1312 scp->autoneg_status = XE_AUTONEG_100TX; 1313 scp->chand = timeout(xe_setmedia, scp, hz * 3); 1314 return; 1315 } 1316 else { 1317 scp->autoneg_status = XE_AUTONEG_FAIL; 1318 } 1319 } 1320 break; 1321 1322 case XE_AUTONEG_100TX: 1323 (void)xe_phy_readreg(scp, PHY_BMSR); 1324 bmsr = xe_phy_readreg(scp, PHY_BMSR); 1325 if (bmsr & PHY_BMSR_LINKSTAT) { 1326#if XE_DEBUG > 1
|
1542 printf("xe%d: Got 100baseTX link!\n", scp->unit);
| 1327 device_printf(scp->dev, "Got 100baseTX link!\n");
|
1543#endif 1544 XE_MII_DUMP(scp); 1545 XE_SELECT_PAGE(2); 1546 XE_OUTB(XE_MSR, XE_INB(XE_MSR) | 0x08); 1547 scp->media = IFM_ETHER|IFM_100_TX; 1548 scp->autoneg_status = XE_AUTONEG_NONE; 1549 } 1550 else { 1551#if XE_DEBUG > 1
| 1328#endif 1329 XE_MII_DUMP(scp); 1330 XE_SELECT_PAGE(2); 1331 XE_OUTB(XE_MSR, XE_INB(XE_MSR) | 0x08); 1332 scp->media = IFM_ETHER|IFM_100_TX; 1333 scp->autoneg_status = XE_AUTONEG_NONE; 1334 } 1335 else { 1336#if XE_DEBUG > 1
|
1552 printf("xe%d: Autonegotiation failed; disabling PHY\n", scp->unit);
| 1337 device_printf(scp->dev, "Autonegotiation failed; disabling PHY\n");
|
1553#endif 1554 XE_MII_DUMP(scp); 1555 xe_phy_writereg(scp, PHY_BMCR, 0x0000); 1556 XE_SELECT_PAGE(2); 1557 XE_OUTB(XE_MSR, XE_INB(XE_MSR) & ~0x08); /* Disable PHY? */ 1558 scp->autoneg_status = XE_AUTONEG_FAIL; 1559 } 1560 break; 1561 } 1562 1563 /* 1564 * If we got down here _and_ autoneg_status is XE_AUTONEG_FAIL, then 1565 * either autonegotiation failed, or never got started to begin with. In 1566 * either case, select a suitable 10Mbit media and hope it works. We 1567 * don't need to reset the card again, since it will have been done 1568 * already by the big switch above. 1569 */ 1570 if (scp->autoneg_status == XE_AUTONEG_FAIL) { 1571#if XE_DEBUG > 1
| 1338#endif 1339 XE_MII_DUMP(scp); 1340 xe_phy_writereg(scp, PHY_BMCR, 0x0000); 1341 XE_SELECT_PAGE(2); 1342 XE_OUTB(XE_MSR, XE_INB(XE_MSR) & ~0x08); /* Disable PHY? */ 1343 scp->autoneg_status = XE_AUTONEG_FAIL; 1344 } 1345 break; 1346 } 1347 1348 /* 1349 * If we got down here _and_ autoneg_status is XE_AUTONEG_FAIL, then 1350 * either autonegotiation failed, or never got started to begin with. In 1351 * either case, select a suitable 10Mbit media and hope it works. We 1352 * don't need to reset the card again, since it will have been done 1353 * already by the big switch above. 1354 */ 1355 if (scp->autoneg_status == XE_AUTONEG_FAIL) { 1356#if XE_DEBUG > 1
|
1572 printf("xe%d: Selecting 10baseX\n", scp->unit);
| 1357 device_printf(scp->dev, "Selecting 10baseX\n");
|
1573#endif 1574 if (scp->mohawk) { 1575 XE_SELECT_PAGE(0x42); 1576 XE_OUTB(XE_SWC1, 0x80); 1577 scp->media = IFM_ETHER|IFM_10_T; 1578 scp->autoneg_status = XE_AUTONEG_NONE; 1579 } 1580 else { 1581 XE_SELECT_PAGE(4); 1582 XE_OUTB(XE_GPR0, 4); 1583 DELAY(50000); 1584 XE_SELECT_PAGE(0x42); 1585 XE_OUTB(XE_SWC1, (XE_INB(XE_ESR) & XE_ESR_MEDIA_SELECT) ? 0x80 : 0xc0); 1586 scp->media = IFM_ETHER|((XE_INB(XE_ESR) & XE_ESR_MEDIA_SELECT) ? IFM_10_T : IFM_10_2); 1587 scp->autoneg_status = XE_AUTONEG_NONE; 1588 } 1589 } 1590 break; 1591 1592 1593 /* 1594 * If a specific media has been requested, we just reset the card and 1595 * select it (one small exception -- if 100baseTX is requested by there is 1596 * no PHY, we fall back to 10baseT operation). 1597 */ 1598 case IFM_100_TX: /* Force 100baseTX */ 1599 xe_soft_reset(scp); 1600 if (scp->phy_ok) { 1601#if XE_DEBUG > 1
| 1358#endif 1359 if (scp->mohawk) { 1360 XE_SELECT_PAGE(0x42); 1361 XE_OUTB(XE_SWC1, 0x80); 1362 scp->media = IFM_ETHER|IFM_10_T; 1363 scp->autoneg_status = XE_AUTONEG_NONE; 1364 } 1365 else { 1366 XE_SELECT_PAGE(4); 1367 XE_OUTB(XE_GPR0, 4); 1368 DELAY(50000); 1369 XE_SELECT_PAGE(0x42); 1370 XE_OUTB(XE_SWC1, (XE_INB(XE_ESR) & XE_ESR_MEDIA_SELECT) ? 0x80 : 0xc0); 1371 scp->media = IFM_ETHER|((XE_INB(XE_ESR) & XE_ESR_MEDIA_SELECT) ? IFM_10_T : IFM_10_2); 1372 scp->autoneg_status = XE_AUTONEG_NONE; 1373 } 1374 } 1375 break; 1376 1377 1378 /* 1379 * If a specific media has been requested, we just reset the card and 1380 * select it (one small exception -- if 100baseTX is requested by there is 1381 * no PHY, we fall back to 10baseT operation). 1382 */ 1383 case IFM_100_TX: /* Force 100baseTX */ 1384 xe_soft_reset(scp); 1385 if (scp->phy_ok) { 1386#if XE_DEBUG > 1
|
1602 printf("xe%d: Selecting 100baseTX\n", scp->unit);
| 1387 device_printf(scp->dev, "Selecting 100baseTX\n");
|
1603#endif 1604 XE_SELECT_PAGE(0x42); 1605 XE_OUTB(XE_SWC1, 0); 1606 xe_phy_writereg(scp, PHY_BMCR, PHY_BMCR_SPEEDSEL); 1607 XE_SELECT_PAGE(2); 1608 XE_OUTB(XE_MSR, XE_INB(XE_MSR) | 0x08); 1609 scp->media |= IFM_100_TX; 1610 break; 1611 } 1612 /* FALLTHROUGH */ 1613 1614 case IFM_10_T: /* Force 10baseT */ 1615 xe_soft_reset(scp); 1616#if XE_DEBUG > 1
| 1388#endif 1389 XE_SELECT_PAGE(0x42); 1390 XE_OUTB(XE_SWC1, 0); 1391 xe_phy_writereg(scp, PHY_BMCR, PHY_BMCR_SPEEDSEL); 1392 XE_SELECT_PAGE(2); 1393 XE_OUTB(XE_MSR, XE_INB(XE_MSR) | 0x08); 1394 scp->media |= IFM_100_TX; 1395 break; 1396 } 1397 /* FALLTHROUGH */ 1398 1399 case IFM_10_T: /* Force 10baseT */ 1400 xe_soft_reset(scp); 1401#if XE_DEBUG > 1
|
1617 printf("xe%d: Selecting 10baseT\n", scp->unit);
| 1402 device_printf(csp->dev, "Selecting 10baseT\n");
|
1618#endif 1619 if (scp->phy_ok) { 1620 xe_phy_writereg(scp, PHY_BMCR, 0x0000); 1621 XE_SELECT_PAGE(2); 1622 XE_OUTB(XE_MSR, XE_INB(XE_MSR) & ~0x08); /* Disable PHY */ 1623 } 1624 XE_SELECT_PAGE(0x42); 1625 XE_OUTB(XE_SWC1, 0x80); 1626 scp->media |= IFM_10_T; 1627 break; 1628 1629 case IFM_10_2: 1630 xe_soft_reset(scp); 1631#if XE_DEBUG > 1
| 1403#endif 1404 if (scp->phy_ok) { 1405 xe_phy_writereg(scp, PHY_BMCR, 0x0000); 1406 XE_SELECT_PAGE(2); 1407 XE_OUTB(XE_MSR, XE_INB(XE_MSR) & ~0x08); /* Disable PHY */ 1408 } 1409 XE_SELECT_PAGE(0x42); 1410 XE_OUTB(XE_SWC1, 0x80); 1411 scp->media |= IFM_10_T; 1412 break; 1413 1414 case IFM_10_2: 1415 xe_soft_reset(scp); 1416#if XE_DEBUG > 1
|
1632 printf("xe%d: Selecting 10base2\n", scp->unit);
| 1417 device_printf(scp->dev, "Selecting 10base2\n");
|
1633#endif 1634 XE_SELECT_PAGE(0x42); 1635 XE_OUTB(XE_SWC1, 0xc0); 1636 scp->media |= IFM_10_2; 1637 break; 1638 } 1639 1640 1641 /* 1642 * Finally, the LEDs are set to match whatever media was chosen and the 1643 * transmitter is unblocked. 1644 */ 1645#if XE_DEBUG > 1
| 1418#endif 1419 XE_SELECT_PAGE(0x42); 1420 XE_OUTB(XE_SWC1, 0xc0); 1421 scp->media |= IFM_10_2; 1422 break; 1423 } 1424 1425 1426 /* 1427 * Finally, the LEDs are set to match whatever media was chosen and the 1428 * transmitter is unblocked. 1429 */ 1430#if XE_DEBUG > 1
|
1646 printf("xe%d: Setting LEDs\n", scp->unit);
| 1431 device_printf(scp->dev, "Setting LEDs\n");
|
1647#endif 1648 XE_SELECT_PAGE(2); 1649 switch (IFM_SUBTYPE(scp->media)) { 1650 case IFM_100_TX: 1651 case IFM_10_T: 1652 XE_OUTB(XE_LED, 0x3b); 1653 if (scp->dingo) 1654 XE_OUTB(0x0b, 0x04); /* 100Mbit LED */ 1655 break; 1656 1657 case IFM_10_2: 1658 XE_OUTB(XE_LED, 0x3a); 1659 break; 1660 } 1661 1662 /* Restart output? */ 1663 scp->ifp->if_flags &= ~IFF_OACTIVE; 1664 xe_init(scp); 1665} 1666 1667 1668/* 1669 * Hard reset (power cycle) the card. 1670 */ 1671static void 1672xe_hard_reset(struct xe_softc *scp) { 1673 int s; 1674 1675#ifdef XE_DEBUG
| 1432#endif 1433 XE_SELECT_PAGE(2); 1434 switch (IFM_SUBTYPE(scp->media)) { 1435 case IFM_100_TX: 1436 case IFM_10_T: 1437 XE_OUTB(XE_LED, 0x3b); 1438 if (scp->dingo) 1439 XE_OUTB(0x0b, 0x04); /* 100Mbit LED */ 1440 break; 1441 1442 case IFM_10_2: 1443 XE_OUTB(XE_LED, 0x3a); 1444 break; 1445 } 1446 1447 /* Restart output? */ 1448 scp->ifp->if_flags &= ~IFF_OACTIVE; 1449 xe_init(scp); 1450} 1451 1452 1453/* 1454 * Hard reset (power cycle) the card. 1455 */ 1456static void 1457xe_hard_reset(struct xe_softc *scp) { 1458 int s; 1459 1460#ifdef XE_DEBUG
|
1676 printf("xe%d: hard_reset\n", scp->unit);
| 1461 device_printf(scp->dev, "hard_reset\n");
|
1677#endif 1678
| 1462#endif 1463
|
1679 if (scp->gone) return; 1680
| |
1681 s = splimp(); 1682 1683 /* 1684 * Power cycle the card. 1685 */ 1686 XE_SELECT_PAGE(4); 1687 XE_OUTB(XE_GPR1, 0); /* Power off */ 1688 DELAY(40000); 1689 1690 if (scp->mohawk) 1691 XE_OUTB(XE_GPR1, 1); /* And back on again */ 1692 else 1693 XE_OUTB(XE_GPR1, 5); /* Also set AIC bit, whatever that is */ 1694 DELAY(40000); 1695 XE_SELECT_PAGE(0); 1696 1697 (void)splx(s); 1698} 1699 1700 1701/* 1702 * Soft reset the card. Also makes sure that the ML6692 and 10Mbit controller 1703 * are powered up, sets the silicon revision number in softc, disables 1704 * interrupts and checks for the prescence of a 100Mbit PHY. This should 1705 * leave us in a position where we can access the PHY and do media 1706 * selection. The function imposes a 0.5s delay while the hardware powers up. 1707 */ 1708static void 1709xe_soft_reset(struct xe_softc *scp) { 1710 int s; 1711 1712#ifdef XE_DEBUG
| 1464 s = splimp(); 1465 1466 /* 1467 * Power cycle the card. 1468 */ 1469 XE_SELECT_PAGE(4); 1470 XE_OUTB(XE_GPR1, 0); /* Power off */ 1471 DELAY(40000); 1472 1473 if (scp->mohawk) 1474 XE_OUTB(XE_GPR1, 1); /* And back on again */ 1475 else 1476 XE_OUTB(XE_GPR1, 5); /* Also set AIC bit, whatever that is */ 1477 DELAY(40000); 1478 XE_SELECT_PAGE(0); 1479 1480 (void)splx(s); 1481} 1482 1483 1484/* 1485 * Soft reset the card. Also makes sure that the ML6692 and 10Mbit controller 1486 * are powered up, sets the silicon revision number in softc, disables 1487 * interrupts and checks for the prescence of a 100Mbit PHY. This should 1488 * leave us in a position where we can access the PHY and do media 1489 * selection. The function imposes a 0.5s delay while the hardware powers up. 1490 */ 1491static void 1492xe_soft_reset(struct xe_softc *scp) { 1493 int s; 1494 1495#ifdef XE_DEBUG
|
1713 printf("xe%d: soft_reset\n", scp->unit);
| 1496 device_printf(scp->dev, "soft_reset\n");
|
1714#endif 1715
| 1497#endif 1498
|
1716 if (scp->gone) return; 1717
| |
1718 s = splimp(); 1719 1720 /* 1721 * Reset the card, (again). 1722 */ 1723 XE_SELECT_PAGE(0); 1724 XE_OUTB(XE_CR, XE_CR_SOFT_RESET); 1725 DELAY(40000); 1726 XE_OUTB(XE_CR, 0); 1727 DELAY(40000); 1728 1729 if (scp->mohawk) { 1730 /* 1731 * set GP1 and GP2 as outputs (bits 2 & 3) 1732 * set GP1 low to power on the ML6692 (bit 0) 1733 * set GP2 high to power on the 10Mhz chip (bit 1) 1734 */ 1735 XE_SELECT_PAGE(4); 1736 XE_OUTB(XE_GPR0, 0x0e); 1737 } 1738 1739 /* 1740 * Wait for everything to wake up. 1741 */ 1742 DELAY(500000); 1743 1744 /* 1745 * Get silicon revision number. 1746 */ 1747 XE_SELECT_PAGE(4); 1748 if (scp->mohawk) 1749 scp->srev = (XE_INB(XE_BOV) & 0x70) >> 4; 1750 else 1751 scp->srev = (XE_INB(XE_BOV) & 0x30) >> 4; 1752#ifdef XE_DEBUG
| 1499 s = splimp(); 1500 1501 /* 1502 * Reset the card, (again). 1503 */ 1504 XE_SELECT_PAGE(0); 1505 XE_OUTB(XE_CR, XE_CR_SOFT_RESET); 1506 DELAY(40000); 1507 XE_OUTB(XE_CR, 0); 1508 DELAY(40000); 1509 1510 if (scp->mohawk) { 1511 /* 1512 * set GP1 and GP2 as outputs (bits 2 & 3) 1513 * set GP1 low to power on the ML6692 (bit 0) 1514 * set GP2 high to power on the 10Mhz chip (bit 1) 1515 */ 1516 XE_SELECT_PAGE(4); 1517 XE_OUTB(XE_GPR0, 0x0e); 1518 } 1519 1520 /* 1521 * Wait for everything to wake up. 1522 */ 1523 DELAY(500000); 1524 1525 /* 1526 * Get silicon revision number. 1527 */ 1528 XE_SELECT_PAGE(4); 1529 if (scp->mohawk) 1530 scp->srev = (XE_INB(XE_BOV) & 0x70) >> 4; 1531 else 1532 scp->srev = (XE_INB(XE_BOV) & 0x30) >> 4; 1533#ifdef XE_DEBUG
|
1753 printf("xe%d: silicon revision = %d\n", scp->unit, scp->srev);
| 1534 device_printf(scp->dev, "silicon revision = %d\n", scp->srev);
|
1754#endif 1755 1756 /* 1757 * Shut off interrupts. 1758 */ 1759 xe_disable_intr(scp); 1760 1761 /* 1762 * Check for PHY. 1763 */ 1764 if (scp->mohawk) { 1765 scp->phy_ok = xe_mii_init(scp); 1766 } 1767 1768 XE_SELECT_PAGE(0); 1769 1770 (void)splx(s); 1771} 1772 1773 1774/* 1775 * Take interface offline. This is done by powering down the device, which I 1776 * assume means just shutting down the transceiver and Ethernet logic. This 1777 * requires a _hard_ reset to recover from, as we need to power up again. 1778 */ 1779static void 1780xe_stop(struct xe_softc *scp) { 1781 int s; 1782 1783#ifdef XE_DEBUG
| 1535#endif 1536 1537 /* 1538 * Shut off interrupts. 1539 */ 1540 xe_disable_intr(scp); 1541 1542 /* 1543 * Check for PHY. 1544 */ 1545 if (scp->mohawk) { 1546 scp->phy_ok = xe_mii_init(scp); 1547 } 1548 1549 XE_SELECT_PAGE(0); 1550 1551 (void)splx(s); 1552} 1553 1554 1555/* 1556 * Take interface offline. This is done by powering down the device, which I 1557 * assume means just shutting down the transceiver and Ethernet logic. This 1558 * requires a _hard_ reset to recover from, as we need to power up again. 1559 */ 1560static void 1561xe_stop(struct xe_softc *scp) { 1562 int s; 1563 1564#ifdef XE_DEBUG
|
1784 printf("xe%d: stop\n", scp->unit);
| 1565 device_printf(scp->dev, "stop\n");
|
1785#endif 1786
| 1566#endif 1567
|
1787 if (scp->gone) return; 1788
| |
1789 s = splimp(); 1790 1791 /* 1792 * Shut off interrupts. 1793 */ 1794 xe_disable_intr(scp); 1795 1796 /* 1797 * Power down. 1798 */ 1799 XE_SELECT_PAGE(4); 1800 XE_OUTB(XE_GPR1, 0); 1801 XE_SELECT_PAGE(0); 1802 1803 /* 1804 * ~IFF_RUNNING == interface down. 1805 */ 1806 scp->ifp->if_flags &= ~IFF_RUNNING; 1807 scp->ifp->if_flags &= ~IFF_OACTIVE; 1808 scp->ifp->if_timer = 0; 1809 1810 (void)splx(s); 1811} 1812 1813 1814/* 1815 * Enable Ethernet interrupts from the card. 1816 */ 1817static void 1818xe_enable_intr(struct xe_softc *scp) { 1819#ifdef XE_DEBUG
| 1568 s = splimp(); 1569 1570 /* 1571 * Shut off interrupts. 1572 */ 1573 xe_disable_intr(scp); 1574 1575 /* 1576 * Power down. 1577 */ 1578 XE_SELECT_PAGE(4); 1579 XE_OUTB(XE_GPR1, 0); 1580 XE_SELECT_PAGE(0); 1581 1582 /* 1583 * ~IFF_RUNNING == interface down. 1584 */ 1585 scp->ifp->if_flags &= ~IFF_RUNNING; 1586 scp->ifp->if_flags &= ~IFF_OACTIVE; 1587 scp->ifp->if_timer = 0; 1588 1589 (void)splx(s); 1590} 1591 1592 1593/* 1594 * Enable Ethernet interrupts from the card. 1595 */ 1596static void 1597xe_enable_intr(struct xe_softc *scp) { 1598#ifdef XE_DEBUG
|
1820 printf("xe%d: enable_intr\n", scp->unit);
| 1599 device_printf(scp->dev, "enable_intr\n");
|
1821#endif 1822 1823 XE_SELECT_PAGE(1); 1824 XE_OUTB(XE_IMR0, 0xff); /* Unmask everything */ 1825 XE_OUTB(XE_IMR1, 0x01); /* Unmask TX underrun detection */ 1826 DELAY(1); 1827 1828 XE_SELECT_PAGE(0); 1829 XE_OUTB(XE_CR, XE_CR_ENABLE_INTR); /* Enable interrupts */ 1830 if (scp->modem && !scp->dingo) { /* This bit is just magic */ 1831 if (!(XE_INB(0x10) & 0x01)) { 1832 XE_OUTB(0x10, 0x11); /* Unmask master int enable bit */ 1833 } 1834 } 1835} 1836 1837 1838/* 1839 * Disable all Ethernet interrupts from the card. 1840 */ 1841static void 1842xe_disable_intr(struct xe_softc *scp) { 1843#ifdef XE_DEBUG
| 1600#endif 1601 1602 XE_SELECT_PAGE(1); 1603 XE_OUTB(XE_IMR0, 0xff); /* Unmask everything */ 1604 XE_OUTB(XE_IMR1, 0x01); /* Unmask TX underrun detection */ 1605 DELAY(1); 1606 1607 XE_SELECT_PAGE(0); 1608 XE_OUTB(XE_CR, XE_CR_ENABLE_INTR); /* Enable interrupts */ 1609 if (scp->modem && !scp->dingo) { /* This bit is just magic */ 1610 if (!(XE_INB(0x10) & 0x01)) { 1611 XE_OUTB(0x10, 0x11); /* Unmask master int enable bit */ 1612 } 1613 } 1614} 1615 1616 1617/* 1618 * Disable all Ethernet interrupts from the card. 1619 */ 1620static void 1621xe_disable_intr(struct xe_softc *scp) { 1622#ifdef XE_DEBUG
|
1844 printf("xe%d: disable_intr\n", scp->unit);
| 1623 device_printf(scp->dev, "disable_intr\n");
|
1845#endif 1846 1847 XE_SELECT_PAGE(0); 1848 XE_OUTB(XE_CR, 0); /* Disable interrupts */ 1849 if (scp->modem && !scp->dingo) { /* More magic (does this work?) */ 1850 XE_OUTB(0x10, 0x10); /* Mask the master int enable bit */ 1851 } 1852 1853 XE_SELECT_PAGE(1); 1854 XE_OUTB(XE_IMR0, 0); /* Forbid all interrupts */ 1855 XE_OUTB(XE_IMR1, 0); 1856 XE_SELECT_PAGE(0); 1857} 1858 1859 1860/* 1861 * Set up multicast filter and promiscuous mode 1862 */ 1863static void 1864xe_setmulti(struct xe_softc *scp) { 1865 struct ifnet *ifp; 1866 struct ifmultiaddr *maddr; 1867 int count; 1868 1869 ifp = &scp->arpcom.ac_if; 1870 maddr = ifp->if_multiaddrs.lh_first; 1871 1872 /* Get length of multicast list */ 1873 for (count = 0; maddr != NULL; maddr = maddr->ifma_link.le_next, count++); 1874 1875 if ((ifp->if_flags & IFF_PROMISC) || (ifp->if_flags & IFF_ALLMULTI) || (count > 9)) { 1876 /* 1877 * Go into promiscuous mode if either of the PROMISC or ALLMULTI flags are 1878 * set, or if we have been asked to deal with more than 9 multicast 1879 * addresses. To do this: set MPE and PME in SWC1 1880 */ 1881 XE_SELECT_PAGE(0x42); 1882 XE_OUTB(XE_SWC1, 0x06); 1883 } 1884 else if ((ifp->if_flags & IFF_MULTICAST) && (count > 0)) { 1885 /* 1886 * Program the filters for up to 9 addresses 1887 */ 1888 XE_SELECT_PAGE(0x42); 1889 XE_OUTB(XE_SWC1, 0x01); 1890 XE_SELECT_PAGE(0x40); 1891 XE_OUTB(XE_CMD0, XE_CMD0_OFFLINE); 1892 /*xe_reg_dump(scp);*/ 1893 xe_setaddrs(scp); 1894 /*xe_reg_dump(scp);*/ 1895 XE_SELECT_PAGE(0x40); 1896 XE_OUTB(XE_CMD0, XE_CMD0_RX_ENABLE|XE_CMD0_ONLINE); 1897 } 1898 else { 1899 /* 1900 * No multicast operation (default) 1901 */ 1902 XE_SELECT_PAGE(0x42); 1903 XE_OUTB(XE_SWC1, 0); 1904 } 1905 XE_SELECT_PAGE(0); 1906} 1907 1908 1909/* 1910 * Set up all on-chip addresses (for multicast). AFAICS, there are 10 1911 * of these things; the first is our MAC address, the other 9 are mcast 1912 * addresses, padded with the MAC address if there aren't enough. 1913 * XXX - This doesn't work right, but I'm not sure why yet. We seem to be 1914 * XXX - doing much the same as the Linux code, which is weird enough that 1915 * XXX - it's probably right (despite my earlier comments to the contrary). 1916 */ 1917static void 1918xe_setaddrs(struct xe_softc *scp) { 1919 struct ifmultiaddr *maddr; 1920 u_int8_t *addr; 1921 u_int8_t page, slot, byte, i; 1922 1923 maddr = scp->arpcom.ac_if.if_multiaddrs.lh_first; 1924 1925 XE_SELECT_PAGE(page = 0x50); 1926 1927 for (slot = 0, byte = 8; slot < 10; slot++) { 1928 1929 if (slot == 0) 1930 addr = (u_int8_t *)(&scp->arpcom.ac_enaddr); 1931 else { 1932 while (maddr != NULL && maddr->ifma_addr->sa_family != AF_LINK) 1933 maddr = maddr->ifma_link.le_next; 1934 if (maddr != NULL) 1935 addr = LLADDR((struct sockaddr_dl *)maddr->ifma_addr); 1936 else 1937 addr = (u_int8_t *)(&scp->arpcom.ac_enaddr); 1938 } 1939 1940 for (i = 0; i < 6; i++, byte++) { 1941#if XE_DEBUG > 2 1942 if (i) 1943 printf(":%x", addr[i]); 1944 else
| 1624#endif 1625 1626 XE_SELECT_PAGE(0); 1627 XE_OUTB(XE_CR, 0); /* Disable interrupts */ 1628 if (scp->modem && !scp->dingo) { /* More magic (does this work?) */ 1629 XE_OUTB(0x10, 0x10); /* Mask the master int enable bit */ 1630 } 1631 1632 XE_SELECT_PAGE(1); 1633 XE_OUTB(XE_IMR0, 0); /* Forbid all interrupts */ 1634 XE_OUTB(XE_IMR1, 0); 1635 XE_SELECT_PAGE(0); 1636} 1637 1638 1639/* 1640 * Set up multicast filter and promiscuous mode 1641 */ 1642static void 1643xe_setmulti(struct xe_softc *scp) { 1644 struct ifnet *ifp; 1645 struct ifmultiaddr *maddr; 1646 int count; 1647 1648 ifp = &scp->arpcom.ac_if; 1649 maddr = ifp->if_multiaddrs.lh_first; 1650 1651 /* Get length of multicast list */ 1652 for (count = 0; maddr != NULL; maddr = maddr->ifma_link.le_next, count++); 1653 1654 if ((ifp->if_flags & IFF_PROMISC) || (ifp->if_flags & IFF_ALLMULTI) || (count > 9)) { 1655 /* 1656 * Go into promiscuous mode if either of the PROMISC or ALLMULTI flags are 1657 * set, or if we have been asked to deal with more than 9 multicast 1658 * addresses. To do this: set MPE and PME in SWC1 1659 */ 1660 XE_SELECT_PAGE(0x42); 1661 XE_OUTB(XE_SWC1, 0x06); 1662 } 1663 else if ((ifp->if_flags & IFF_MULTICAST) && (count > 0)) { 1664 /* 1665 * Program the filters for up to 9 addresses 1666 */ 1667 XE_SELECT_PAGE(0x42); 1668 XE_OUTB(XE_SWC1, 0x01); 1669 XE_SELECT_PAGE(0x40); 1670 XE_OUTB(XE_CMD0, XE_CMD0_OFFLINE); 1671 /*xe_reg_dump(scp);*/ 1672 xe_setaddrs(scp); 1673 /*xe_reg_dump(scp);*/ 1674 XE_SELECT_PAGE(0x40); 1675 XE_OUTB(XE_CMD0, XE_CMD0_RX_ENABLE|XE_CMD0_ONLINE); 1676 } 1677 else { 1678 /* 1679 * No multicast operation (default) 1680 */ 1681 XE_SELECT_PAGE(0x42); 1682 XE_OUTB(XE_SWC1, 0); 1683 } 1684 XE_SELECT_PAGE(0); 1685} 1686 1687 1688/* 1689 * Set up all on-chip addresses (for multicast). AFAICS, there are 10 1690 * of these things; the first is our MAC address, the other 9 are mcast 1691 * addresses, padded with the MAC address if there aren't enough. 1692 * XXX - This doesn't work right, but I'm not sure why yet. We seem to be 1693 * XXX - doing much the same as the Linux code, which is weird enough that 1694 * XXX - it's probably right (despite my earlier comments to the contrary). 1695 */ 1696static void 1697xe_setaddrs(struct xe_softc *scp) { 1698 struct ifmultiaddr *maddr; 1699 u_int8_t *addr; 1700 u_int8_t page, slot, byte, i; 1701 1702 maddr = scp->arpcom.ac_if.if_multiaddrs.lh_first; 1703 1704 XE_SELECT_PAGE(page = 0x50); 1705 1706 for (slot = 0, byte = 8; slot < 10; slot++) { 1707 1708 if (slot == 0) 1709 addr = (u_int8_t *)(&scp->arpcom.ac_enaddr); 1710 else { 1711 while (maddr != NULL && maddr->ifma_addr->sa_family != AF_LINK) 1712 maddr = maddr->ifma_link.le_next; 1713 if (maddr != NULL) 1714 addr = LLADDR((struct sockaddr_dl *)maddr->ifma_addr); 1715 else 1716 addr = (u_int8_t *)(&scp->arpcom.ac_enaddr); 1717 } 1718 1719 for (i = 0; i < 6; i++, byte++) { 1720#if XE_DEBUG > 2 1721 if (i) 1722 printf(":%x", addr[i]); 1723 else
|
1945 printf("xe%d: individual addresses %d: %x", scp->unit, slot, addr[0]);
| 1724 device_printf(scp->dev, "individual addresses %d: %x", slot, addr[0]);
|
1946#endif 1947 1948 if (byte > 15) { 1949 page++; 1950 byte = 8; 1951 XE_SELECT_PAGE(page); 1952 } 1953 1954 if (scp->mohawk) 1955 XE_OUTB(byte, addr[5 - i]); 1956 else 1957 XE_OUTB(byte, addr[i]); 1958 } 1959#if XE_DEBUG > 2 1960 printf("\n"); 1961#endif 1962 } 1963 1964 XE_SELECT_PAGE(0); 1965} 1966 1967 1968/* 1969 * Write an outgoing packet to the card using programmed I/O. 1970 */ 1971static int 1972xe_pio_write_packet(struct xe_softc *scp, struct mbuf *mbp) { 1973 struct mbuf *mbp2; 1974 u_int16_t len, pad, free, ok; 1975 u_int8_t *data; 1976 u_int8_t savebyte[2], wantbyte; 1977 1978 /* Get total packet length */ 1979 for (len = 0, mbp2 = mbp; mbp2 != NULL; len += mbp2->m_len, mbp2 = mbp2->m_next); 1980 1981 /* Packets < minimum length may need to be padded out */ 1982 pad = 0; 1983 if (len < ETHER_MIN_LEN - ETHER_CRC_LEN) { 1984 pad = (ETHER_MIN_LEN - ETHER_CRC_LEN - len + 1) >> 1; 1985 len = ETHER_MIN_LEN - ETHER_CRC_LEN; 1986 } 1987 1988 /* Check transmit buffer space */ 1989 XE_SELECT_PAGE(0); 1990 XE_OUTW(XE_TRS, len+2); 1991 free = XE_INW(XE_TSO); 1992 ok = free & 0x8000; 1993 free &= 0x7fff; 1994 if (free <= len + 2) 1995 return 1; 1996 1997 /* Send packet length to card */ 1998 XE_OUTW(XE_EDP, len); 1999 2000 /* 2001 * Write packet to card using PIO (code stolen from the ed driver) 2002 */ 2003 wantbyte = 0; 2004 while (mbp != NULL) { 2005 len = mbp->m_len; 2006 if (len > 0) { 2007 data = mtod(mbp, caddr_t); 2008 if (wantbyte) { /* Finish the last word */ 2009 savebyte[1] = *data; 2010 XE_OUTW(XE_EDP, *(u_short *)savebyte); 2011 data++; 2012 len--; 2013 wantbyte = 0; 2014 } 2015 if (len > 1) { /* Output contiguous words */
| 1725#endif 1726 1727 if (byte > 15) { 1728 page++; 1729 byte = 8; 1730 XE_SELECT_PAGE(page); 1731 } 1732 1733 if (scp->mohawk) 1734 XE_OUTB(byte, addr[5 - i]); 1735 else 1736 XE_OUTB(byte, addr[i]); 1737 } 1738#if XE_DEBUG > 2 1739 printf("\n"); 1740#endif 1741 } 1742 1743 XE_SELECT_PAGE(0); 1744} 1745 1746 1747/* 1748 * Write an outgoing packet to the card using programmed I/O. 1749 */ 1750static int 1751xe_pio_write_packet(struct xe_softc *scp, struct mbuf *mbp) { 1752 struct mbuf *mbp2; 1753 u_int16_t len, pad, free, ok; 1754 u_int8_t *data; 1755 u_int8_t savebyte[2], wantbyte; 1756 1757 /* Get total packet length */ 1758 for (len = 0, mbp2 = mbp; mbp2 != NULL; len += mbp2->m_len, mbp2 = mbp2->m_next); 1759 1760 /* Packets < minimum length may need to be padded out */ 1761 pad = 0; 1762 if (len < ETHER_MIN_LEN - ETHER_CRC_LEN) { 1763 pad = (ETHER_MIN_LEN - ETHER_CRC_LEN - len + 1) >> 1; 1764 len = ETHER_MIN_LEN - ETHER_CRC_LEN; 1765 } 1766 1767 /* Check transmit buffer space */ 1768 XE_SELECT_PAGE(0); 1769 XE_OUTW(XE_TRS, len+2); 1770 free = XE_INW(XE_TSO); 1771 ok = free & 0x8000; 1772 free &= 0x7fff; 1773 if (free <= len + 2) 1774 return 1; 1775 1776 /* Send packet length to card */ 1777 XE_OUTW(XE_EDP, len); 1778 1779 /* 1780 * Write packet to card using PIO (code stolen from the ed driver) 1781 */ 1782 wantbyte = 0; 1783 while (mbp != NULL) { 1784 len = mbp->m_len; 1785 if (len > 0) { 1786 data = mtod(mbp, caddr_t); 1787 if (wantbyte) { /* Finish the last word */ 1788 savebyte[1] = *data; 1789 XE_OUTW(XE_EDP, *(u_short *)savebyte); 1790 data++; 1791 len--; 1792 wantbyte = 0; 1793 } 1794 if (len > 1) { /* Output contiguous words */
|
2016 outsw(scp->dev->id_iobase+XE_EDP, data, len >> 1);
| 1795 bus_space_write_multi_2(scp->bst, scp->bsh, XE_EDP, (u_int16_t *) data, 1796 len >> 1);
|
2017 data += len & ~1; 2018 len &= 1; 2019 } 2020 if (len == 1) { /* Save last byte, if necessary */ 2021 savebyte[0] = *data; 2022 wantbyte = 1; 2023 } 2024 } 2025 mbp = mbp->m_next; 2026 } 2027 if (wantbyte) /* Last byte for odd-length packets */ 2028 XE_OUTW(XE_EDP, *(u_short *)savebyte); 2029 2030 /* 2031 * For CE3 cards, just tell 'em to send -- apparently the card will pad out 2032 * short packets with random cruft. Otherwise, write nonsense words to fill 2033 * out the packet. I guess it is then sent automatically (?) 2034 */ 2035 if (scp->mohawk) 2036 XE_OUTB(XE_CR, XE_CR_TX_PACKET|XE_CR_ENABLE_INTR); 2037 else 2038 while (pad > 0) { 2039 XE_OUTW(XE_EDP, 0xdead); 2040 pad--; 2041 } 2042 2043 return 0; 2044} 2045
| 1797 data += len & ~1; 1798 len &= 1; 1799 } 1800 if (len == 1) { /* Save last byte, if necessary */ 1801 savebyte[0] = *data; 1802 wantbyte = 1; 1803 } 1804 } 1805 mbp = mbp->m_next; 1806 } 1807 if (wantbyte) /* Last byte for odd-length packets */ 1808 XE_OUTW(XE_EDP, *(u_short *)savebyte); 1809 1810 /* 1811 * For CE3 cards, just tell 'em to send -- apparently the card will pad out 1812 * short packets with random cruft. Otherwise, write nonsense words to fill 1813 * out the packet. I guess it is then sent automatically (?) 1814 */ 1815 if (scp->mohawk) 1816 XE_OUTB(XE_CR, XE_CR_TX_PACKET|XE_CR_ENABLE_INTR); 1817 else 1818 while (pad > 0) { 1819 XE_OUTW(XE_EDP, 0xdead); 1820 pad--; 1821 } 1822 1823 return 0; 1824} 1825
|
2046
| |
2047/*
| 1826/*
|
2048 * The device entry is being removed, probably because someone ejected the 2049 * card. The interface should have been brought down manually before calling 2050 * this function; if not you may well lose packets. In any case, I shut down 2051 * the card and the interface, and hope for the best. The 'gone' flag is set, 2052 * so hopefully no-one else will try to access the missing card. 2053 */ 2054static void 2055xe_card_unload(struct pccard_devinfo *devi) { 2056 struct xe_softc *scp; 2057 struct ifnet *ifp; 2058 int unit; 2059 2060 unit = devi->isahd.id_unit; 2061 scp = sca[unit]; 2062 ifp = &scp->arpcom.ac_if; 2063 2064 if (scp->gone) { 2065 printf("xe%d: already unloaded\n", unit); 2066 return; 2067 } 2068 2069 if_down(ifp); 2070 ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE); 2071 xe_stop(scp); 2072 scp->gone = 1; 2073} 2074 2075 2076/*
| |
2077 * Compute the 32-bit Ethernet CRC for the given buffer. 2078 */ 2079static u_int32_t 2080xe_compute_crc(u_int8_t *data, int len) { 2081 u_int32_t crc = 0xffffffff; 2082 u_int32_t poly = 0x04c11db6; 2083 u_int8_t current, crc31, bit; 2084 int i, k; 2085 2086 for (i = 0; i < len; i++) { 2087 current = data[i]; 2088 for (k = 1; k <= 8; k++) { 2089 if (crc & 0x80000000) { 2090 crc31 = 0x01; 2091 } 2092 else { 2093 crc31 = 0; 2094 } 2095 bit = crc31 ^ (current & 0x01); 2096 crc <<= 1; 2097 current >>= 1; 2098 if (bit) { 2099 crc = (crc ^ poly)|1; 2100 } 2101 } 2102 } 2103 return crc; 2104} 2105 2106 2107/* 2108 * Convert a CRC into an index into the multicast hash table. What we do is 2109 * take the most-significant 6 bits of the CRC, reverse them, and use that as 2110 * the bit number in the hash table. Bits 5:3 of the result give the byte 2111 * within the table (0-7); bits 2:0 give the bit number within that byte (also 2112 * 0-7), ie. the number of shifts needed to get it into the lsb position. 2113 */ 2114static int 2115xe_compute_hashbit(u_int32_t crc) { 2116 u_int8_t hashbit = 0; 2117 int i; 2118 2119 for (i = 0; i < 6; i++) { 2120 hashbit >>= 1; 2121 if (crc & 0x80000000) { 2122 hashbit &= 0x80; 2123 } 2124 crc <<= 1; 2125 } 2126 return (hashbit >> 2); 2127} 2128 2129 2130 2131/************************************************************** 2132 * * 2133 * M I I F U N C T I O N S * 2134 * * 2135 **************************************************************/ 2136 2137/* 2138 * Alternative MII/PHY handling code adapted from the xl driver. It doesn't 2139 * seem to work any better than the xirc2_ps stuff, but it's cleaner code. 2140 * XXX - this stuff shouldn't be here. It should all be abstracted off to 2141 * XXX - some kind of common MII-handling code, shared by all drivers. But 2142 * XXX - that's a whole other mission. 2143 */ 2144#define XE_MII_SET(x) XE_OUTB(XE_GPR2, (XE_INB(XE_GPR2) | 0x04) | (x)) 2145#define XE_MII_CLR(x) XE_OUTB(XE_GPR2, (XE_INB(XE_GPR2) | 0x04) & ~(x)) 2146 2147 2148/* 2149 * Sync the PHYs by setting data bit and strobing the clock 32 times. 2150 */ 2151static void 2152xe_mii_sync(struct xe_softc *scp) { 2153 register int i; 2154 2155 XE_SELECT_PAGE(2); 2156 XE_MII_SET(XE_MII_DIR|XE_MII_WRD); 2157 2158 for (i = 0; i < 32; i++) { 2159 XE_MII_SET(XE_MII_CLK); 2160 DELAY(1); 2161 XE_MII_CLR(XE_MII_CLK); 2162 DELAY(1); 2163 } 2164} 2165 2166 2167/* 2168 * Look for a MII-compliant PHY. If we find one, reset it. 2169 */ 2170static int 2171xe_mii_init(struct xe_softc *scp) { 2172 u_int16_t status; 2173 2174 status = xe_phy_readreg(scp, PHY_BMSR); 2175 if ((status & 0xff00) != 0x7800) { 2176#if XE_DEBUG > 1
| 1827 * Compute the 32-bit Ethernet CRC for the given buffer. 1828 */ 1829static u_int32_t 1830xe_compute_crc(u_int8_t *data, int len) { 1831 u_int32_t crc = 0xffffffff; 1832 u_int32_t poly = 0x04c11db6; 1833 u_int8_t current, crc31, bit; 1834 int i, k; 1835 1836 for (i = 0; i < len; i++) { 1837 current = data[i]; 1838 for (k = 1; k <= 8; k++) { 1839 if (crc & 0x80000000) { 1840 crc31 = 0x01; 1841 } 1842 else { 1843 crc31 = 0; 1844 } 1845 bit = crc31 ^ (current & 0x01); 1846 crc <<= 1; 1847 current >>= 1; 1848 if (bit) { 1849 crc = (crc ^ poly)|1; 1850 } 1851 } 1852 } 1853 return crc; 1854} 1855 1856 1857/* 1858 * Convert a CRC into an index into the multicast hash table. What we do is 1859 * take the most-significant 6 bits of the CRC, reverse them, and use that as 1860 * the bit number in the hash table. Bits 5:3 of the result give the byte 1861 * within the table (0-7); bits 2:0 give the bit number within that byte (also 1862 * 0-7), ie. the number of shifts needed to get it into the lsb position. 1863 */ 1864static int 1865xe_compute_hashbit(u_int32_t crc) { 1866 u_int8_t hashbit = 0; 1867 int i; 1868 1869 for (i = 0; i < 6; i++) { 1870 hashbit >>= 1; 1871 if (crc & 0x80000000) { 1872 hashbit &= 0x80; 1873 } 1874 crc <<= 1; 1875 } 1876 return (hashbit >> 2); 1877} 1878 1879 1880 1881/************************************************************** 1882 * * 1883 * M I I F U N C T I O N S * 1884 * * 1885 **************************************************************/ 1886 1887/* 1888 * Alternative MII/PHY handling code adapted from the xl driver. It doesn't 1889 * seem to work any better than the xirc2_ps stuff, but it's cleaner code. 1890 * XXX - this stuff shouldn't be here. It should all be abstracted off to 1891 * XXX - some kind of common MII-handling code, shared by all drivers. But 1892 * XXX - that's a whole other mission. 1893 */ 1894#define XE_MII_SET(x) XE_OUTB(XE_GPR2, (XE_INB(XE_GPR2) | 0x04) | (x)) 1895#define XE_MII_CLR(x) XE_OUTB(XE_GPR2, (XE_INB(XE_GPR2) | 0x04) & ~(x)) 1896 1897 1898/* 1899 * Sync the PHYs by setting data bit and strobing the clock 32 times. 1900 */ 1901static void 1902xe_mii_sync(struct xe_softc *scp) { 1903 register int i; 1904 1905 XE_SELECT_PAGE(2); 1906 XE_MII_SET(XE_MII_DIR|XE_MII_WRD); 1907 1908 for (i = 0; i < 32; i++) { 1909 XE_MII_SET(XE_MII_CLK); 1910 DELAY(1); 1911 XE_MII_CLR(XE_MII_CLK); 1912 DELAY(1); 1913 } 1914} 1915 1916 1917/* 1918 * Look for a MII-compliant PHY. If we find one, reset it. 1919 */ 1920static int 1921xe_mii_init(struct xe_softc *scp) { 1922 u_int16_t status; 1923 1924 status = xe_phy_readreg(scp, PHY_BMSR); 1925 if ((status & 0xff00) != 0x7800) { 1926#if XE_DEBUG > 1
|
2177 printf("xe%d: no PHY found, %0x\n", scp->unit, status);
| 1927 device_printf(scp->dev, "no PHY found, %0x\n", status);
|
2178#endif 2179 return 0; 2180 } 2181 else { 2182#if XE_DEBUG > 1
| 1928#endif 1929 return 0; 1930 } 1931 else { 1932#if XE_DEBUG > 1
|
2183 printf("xe%d: PHY OK!\n", scp->unit);
| 1933 device_printf(scp->dev, "PHY OK!\n");
|
2184#endif 2185 2186 /* Reset the PHY */ 2187 xe_phy_writereg(scp, PHY_BMCR, PHY_BMCR_RESET); 2188 DELAY(500); 2189 while(xe_phy_readreg(scp, PHY_BMCR) & PHY_BMCR_RESET); 2190 XE_MII_DUMP(scp); 2191 return 1; 2192 } 2193} 2194 2195 2196/* 2197 * Clock a series of bits through the MII. 2198 */ 2199static void 2200xe_mii_send(struct xe_softc *scp, u_int32_t bits, int cnt) { 2201 int i; 2202 2203 XE_SELECT_PAGE(2); 2204 XE_MII_CLR(XE_MII_CLK); 2205 2206 for (i = (0x1 << (cnt - 1)); i; i >>= 1) { 2207 if (bits & i) { 2208 XE_MII_SET(XE_MII_WRD); 2209 } else { 2210 XE_MII_CLR(XE_MII_WRD); 2211 } 2212 DELAY(1); 2213 XE_MII_CLR(XE_MII_CLK); 2214 DELAY(1); 2215 XE_MII_SET(XE_MII_CLK); 2216 } 2217} 2218 2219 2220/* 2221 * Read an PHY register through the MII. 2222 */ 2223static int 2224xe_mii_readreg(struct xe_softc *scp, struct xe_mii_frame *frame) { 2225 int i, ack, s; 2226 2227 s = splimp(); 2228 2229 /* 2230 * Set up frame for RX. 2231 */ 2232 frame->mii_stdelim = XE_MII_STARTDELIM; 2233 frame->mii_opcode = XE_MII_READOP; 2234 frame->mii_turnaround = 0; 2235 frame->mii_data = 0; 2236 2237 XE_SELECT_PAGE(2); 2238 XE_OUTB(XE_GPR2, 0); 2239 2240 /* 2241 * Turn on data xmit. 2242 */ 2243 XE_MII_SET(XE_MII_DIR); 2244 2245 xe_mii_sync(scp); 2246 2247 /* 2248 * Send command/address info. 2249 */ 2250 xe_mii_send(scp, frame->mii_stdelim, 2); 2251 xe_mii_send(scp, frame->mii_opcode, 2); 2252 xe_mii_send(scp, frame->mii_phyaddr, 5); 2253 xe_mii_send(scp, frame->mii_regaddr, 5); 2254 2255 /* Idle bit */ 2256 XE_MII_CLR((XE_MII_CLK|XE_MII_WRD)); 2257 DELAY(1); 2258 XE_MII_SET(XE_MII_CLK); 2259 DELAY(1); 2260 2261 /* Turn off xmit. */ 2262 XE_MII_CLR(XE_MII_DIR); 2263 2264 /* Check for ack */ 2265 XE_MII_CLR(XE_MII_CLK); 2266 DELAY(1); 2267 XE_MII_SET(XE_MII_CLK); 2268 DELAY(1); 2269 ack = XE_INB(XE_GPR2) & XE_MII_RDD; 2270 2271 /* 2272 * Now try reading data bits. If the ack failed, we still 2273 * need to clock through 16 cycles to keep the PHY(s) in sync. 2274 */ 2275 if (ack) { 2276 for(i = 0; i < 16; i++) { 2277 XE_MII_CLR(XE_MII_CLK); 2278 DELAY(1); 2279 XE_MII_SET(XE_MII_CLK); 2280 DELAY(1); 2281 } 2282 goto fail; 2283 } 2284 2285 for (i = 0x8000; i; i >>= 1) { 2286 XE_MII_CLR(XE_MII_CLK); 2287 DELAY(1); 2288 if (!ack) { 2289 if (XE_INB(XE_GPR2) & XE_MII_RDD) 2290 frame->mii_data |= i; 2291 DELAY(1); 2292 } 2293 XE_MII_SET(XE_MII_CLK); 2294 DELAY(1); 2295 } 2296 2297fail: 2298 2299 XE_MII_CLR(XE_MII_CLK); 2300 DELAY(1); 2301 XE_MII_SET(XE_MII_CLK); 2302 DELAY(1); 2303 2304 splx(s); 2305 2306 if (ack) 2307 return(1); 2308 return(0); 2309} 2310 2311 2312/* 2313 * Write to a PHY register through the MII. 2314 */ 2315static int 2316xe_mii_writereg(struct xe_softc *scp, struct xe_mii_frame *frame) { 2317 int s; 2318 2319 s = splimp(); 2320 2321 /* 2322 * Set up frame for TX. 2323 */ 2324 frame->mii_stdelim = XE_MII_STARTDELIM; 2325 frame->mii_opcode = XE_MII_WRITEOP; 2326 frame->mii_turnaround = XE_MII_TURNAROUND; 2327 2328 XE_SELECT_PAGE(2); 2329 2330 /* 2331 * Turn on data output. 2332 */ 2333 XE_MII_SET(XE_MII_DIR); 2334 2335 xe_mii_sync(scp); 2336 2337 xe_mii_send(scp, frame->mii_stdelim, 2); 2338 xe_mii_send(scp, frame->mii_opcode, 2); 2339 xe_mii_send(scp, frame->mii_phyaddr, 5); 2340 xe_mii_send(scp, frame->mii_regaddr, 5); 2341 xe_mii_send(scp, frame->mii_turnaround, 2); 2342 xe_mii_send(scp, frame->mii_data, 16); 2343 2344 /* Idle bit. */ 2345 XE_MII_SET(XE_MII_CLK); 2346 DELAY(1); 2347 XE_MII_CLR(XE_MII_CLK); 2348 DELAY(1); 2349 2350 /* 2351 * Turn off xmit. 2352 */ 2353 XE_MII_CLR(XE_MII_DIR); 2354 2355 splx(s); 2356 2357 return(0); 2358} 2359 2360 2361/* 2362 * Read a register from the PHY. 2363 */ 2364static u_int16_t 2365xe_phy_readreg(struct xe_softc *scp, u_int16_t reg) { 2366 struct xe_mii_frame frame; 2367 2368 bzero((char *)&frame, sizeof(frame)); 2369 2370 frame.mii_phyaddr = 0; 2371 frame.mii_regaddr = reg; 2372 xe_mii_readreg(scp, &frame); 2373 2374 return(frame.mii_data); 2375} 2376 2377 2378/* 2379 * Write to a PHY register. 2380 */ 2381static void 2382xe_phy_writereg(struct xe_softc *scp, u_int16_t reg, u_int16_t data) { 2383 struct xe_mii_frame frame; 2384 2385 bzero((char *)&frame, sizeof(frame)); 2386 2387 frame.mii_phyaddr = 0; 2388 frame.mii_regaddr = reg; 2389 frame.mii_data = data; 2390 xe_mii_writereg(scp, &frame); 2391 2392 return; 2393} 2394 2395 2396#ifdef XE_DEBUG 2397/* 2398 * A bit of debugging code. 2399 */ 2400static void 2401xe_mii_dump(struct xe_softc *scp) { 2402 int i, s; 2403 2404 s = splimp(); 2405
| 1934#endif 1935 1936 /* Reset the PHY */ 1937 xe_phy_writereg(scp, PHY_BMCR, PHY_BMCR_RESET); 1938 DELAY(500); 1939 while(xe_phy_readreg(scp, PHY_BMCR) & PHY_BMCR_RESET); 1940 XE_MII_DUMP(scp); 1941 return 1; 1942 } 1943} 1944 1945 1946/* 1947 * Clock a series of bits through the MII. 1948 */ 1949static void 1950xe_mii_send(struct xe_softc *scp, u_int32_t bits, int cnt) { 1951 int i; 1952 1953 XE_SELECT_PAGE(2); 1954 XE_MII_CLR(XE_MII_CLK); 1955 1956 for (i = (0x1 << (cnt - 1)); i; i >>= 1) { 1957 if (bits & i) { 1958 XE_MII_SET(XE_MII_WRD); 1959 } else { 1960 XE_MII_CLR(XE_MII_WRD); 1961 } 1962 DELAY(1); 1963 XE_MII_CLR(XE_MII_CLK); 1964 DELAY(1); 1965 XE_MII_SET(XE_MII_CLK); 1966 } 1967} 1968 1969 1970/* 1971 * Read an PHY register through the MII. 1972 */ 1973static int 1974xe_mii_readreg(struct xe_softc *scp, struct xe_mii_frame *frame) { 1975 int i, ack, s; 1976 1977 s = splimp(); 1978 1979 /* 1980 * Set up frame for RX. 1981 */ 1982 frame->mii_stdelim = XE_MII_STARTDELIM; 1983 frame->mii_opcode = XE_MII_READOP; 1984 frame->mii_turnaround = 0; 1985 frame->mii_data = 0; 1986 1987 XE_SELECT_PAGE(2); 1988 XE_OUTB(XE_GPR2, 0); 1989 1990 /* 1991 * Turn on data xmit. 1992 */ 1993 XE_MII_SET(XE_MII_DIR); 1994 1995 xe_mii_sync(scp); 1996 1997 /* 1998 * Send command/address info. 1999 */ 2000 xe_mii_send(scp, frame->mii_stdelim, 2); 2001 xe_mii_send(scp, frame->mii_opcode, 2); 2002 xe_mii_send(scp, frame->mii_phyaddr, 5); 2003 xe_mii_send(scp, frame->mii_regaddr, 5); 2004 2005 /* Idle bit */ 2006 XE_MII_CLR((XE_MII_CLK|XE_MII_WRD)); 2007 DELAY(1); 2008 XE_MII_SET(XE_MII_CLK); 2009 DELAY(1); 2010 2011 /* Turn off xmit. */ 2012 XE_MII_CLR(XE_MII_DIR); 2013 2014 /* Check for ack */ 2015 XE_MII_CLR(XE_MII_CLK); 2016 DELAY(1); 2017 XE_MII_SET(XE_MII_CLK); 2018 DELAY(1); 2019 ack = XE_INB(XE_GPR2) & XE_MII_RDD; 2020 2021 /* 2022 * Now try reading data bits. If the ack failed, we still 2023 * need to clock through 16 cycles to keep the PHY(s) in sync. 2024 */ 2025 if (ack) { 2026 for(i = 0; i < 16; i++) { 2027 XE_MII_CLR(XE_MII_CLK); 2028 DELAY(1); 2029 XE_MII_SET(XE_MII_CLK); 2030 DELAY(1); 2031 } 2032 goto fail; 2033 } 2034 2035 for (i = 0x8000; i; i >>= 1) { 2036 XE_MII_CLR(XE_MII_CLK); 2037 DELAY(1); 2038 if (!ack) { 2039 if (XE_INB(XE_GPR2) & XE_MII_RDD) 2040 frame->mii_data |= i; 2041 DELAY(1); 2042 } 2043 XE_MII_SET(XE_MII_CLK); 2044 DELAY(1); 2045 } 2046 2047fail: 2048 2049 XE_MII_CLR(XE_MII_CLK); 2050 DELAY(1); 2051 XE_MII_SET(XE_MII_CLK); 2052 DELAY(1); 2053 2054 splx(s); 2055 2056 if (ack) 2057 return(1); 2058 return(0); 2059} 2060 2061 2062/* 2063 * Write to a PHY register through the MII. 2064 */ 2065static int 2066xe_mii_writereg(struct xe_softc *scp, struct xe_mii_frame *frame) { 2067 int s; 2068 2069 s = splimp(); 2070 2071 /* 2072 * Set up frame for TX. 2073 */ 2074 frame->mii_stdelim = XE_MII_STARTDELIM; 2075 frame->mii_opcode = XE_MII_WRITEOP; 2076 frame->mii_turnaround = XE_MII_TURNAROUND; 2077 2078 XE_SELECT_PAGE(2); 2079 2080 /* 2081 * Turn on data output. 2082 */ 2083 XE_MII_SET(XE_MII_DIR); 2084 2085 xe_mii_sync(scp); 2086 2087 xe_mii_send(scp, frame->mii_stdelim, 2); 2088 xe_mii_send(scp, frame->mii_opcode, 2); 2089 xe_mii_send(scp, frame->mii_phyaddr, 5); 2090 xe_mii_send(scp, frame->mii_regaddr, 5); 2091 xe_mii_send(scp, frame->mii_turnaround, 2); 2092 xe_mii_send(scp, frame->mii_data, 16); 2093 2094 /* Idle bit. */ 2095 XE_MII_SET(XE_MII_CLK); 2096 DELAY(1); 2097 XE_MII_CLR(XE_MII_CLK); 2098 DELAY(1); 2099 2100 /* 2101 * Turn off xmit. 2102 */ 2103 XE_MII_CLR(XE_MII_DIR); 2104 2105 splx(s); 2106 2107 return(0); 2108} 2109 2110 2111/* 2112 * Read a register from the PHY. 2113 */ 2114static u_int16_t 2115xe_phy_readreg(struct xe_softc *scp, u_int16_t reg) { 2116 struct xe_mii_frame frame; 2117 2118 bzero((char *)&frame, sizeof(frame)); 2119 2120 frame.mii_phyaddr = 0; 2121 frame.mii_regaddr = reg; 2122 xe_mii_readreg(scp, &frame); 2123 2124 return(frame.mii_data); 2125} 2126 2127 2128/* 2129 * Write to a PHY register. 2130 */ 2131static void 2132xe_phy_writereg(struct xe_softc *scp, u_int16_t reg, u_int16_t data) { 2133 struct xe_mii_frame frame; 2134 2135 bzero((char *)&frame, sizeof(frame)); 2136 2137 frame.mii_phyaddr = 0; 2138 frame.mii_regaddr = reg; 2139 frame.mii_data = data; 2140 xe_mii_writereg(scp, &frame); 2141 2142 return; 2143} 2144 2145 2146#ifdef XE_DEBUG 2147/* 2148 * A bit of debugging code. 2149 */ 2150static void 2151xe_mii_dump(struct xe_softc *scp) { 2152 int i, s; 2153 2154 s = splimp(); 2155
|
2406 printf("xe%d: MII registers: ", scp->unit);
| 2156 device_printf(scp->dev, "MII registers: ");
|
2407 for (i = 0; i < 2; i++) { 2408 printf(" %d:%04x", i, xe_phy_readreg(scp, i)); 2409 } 2410 for (i = 4; i < 7; i++) { 2411 printf(" %d:%04x", i, xe_phy_readreg(scp, i)); 2412 } 2413 printf("\n"); 2414 2415 (void)splx(s); 2416} 2417 2418static void 2419xe_reg_dump(struct xe_softc *scp) { 2420 int page, i, s; 2421 2422 s = splimp(); 2423
| 2157 for (i = 0; i < 2; i++) { 2158 printf(" %d:%04x", i, xe_phy_readreg(scp, i)); 2159 } 2160 for (i = 4; i < 7; i++) { 2161 printf(" %d:%04x", i, xe_phy_readreg(scp, i)); 2162 } 2163 printf("\n"); 2164 2165 (void)splx(s); 2166} 2167 2168static void 2169xe_reg_dump(struct xe_softc *scp) { 2170 int page, i, s; 2171 2172 s = splimp(); 2173
|
2424 printf("xe%d: Common registers: ", scp->unit);
| 2174 device_printf(scp->dev, "Common registers: ");
|
2425 for (i = 0; i < 8; i++) { 2426 printf(" %2.2x", XE_INB(i)); 2427 } 2428 printf("\n"); 2429 2430 for (page = 0; page <= 8; page++) {
| 2175 for (i = 0; i < 8; i++) { 2176 printf(" %2.2x", XE_INB(i)); 2177 } 2178 printf("\n"); 2179 2180 for (page = 0; page <= 8; page++) {
|
2431 printf("xe%d: Register page %2.2x: ", scp->unit, page);
| 2181 device_printf(scp->dev, "Register page %2.2x: ", page);
|
2432 XE_SELECT_PAGE(page); 2433 for (i = 8; i < 16; i++) { 2434 printf(" %2.2x", XE_INB(i)); 2435 } 2436 printf("\n"); 2437 } 2438 2439 for (page = 0x10; page < 0x5f; page++) { 2440 if ((page >= 0x11 && page <= 0x3f) || 2441 (page == 0x41) || 2442 (page >= 0x43 && page <= 0x4f) || 2443 (page >= 0x59)) 2444 continue;
| 2182 XE_SELECT_PAGE(page); 2183 for (i = 8; i < 16; i++) { 2184 printf(" %2.2x", XE_INB(i)); 2185 } 2186 printf("\n"); 2187 } 2188 2189 for (page = 0x10; page < 0x5f; page++) { 2190 if ((page >= 0x11 && page <= 0x3f) || 2191 (page == 0x41) || 2192 (page >= 0x43 && page <= 0x4f) || 2193 (page >= 0x59)) 2194 continue;
|
2445 printf("xe%d: Register page %2.2x: ", scp->unit, page);
| 2195 device_printf(scp->dev, "Register page %2.2x: ", page);
|
2446 XE_SELECT_PAGE(page); 2447 for (i = 8; i < 16; i++) { 2448 printf(" %2.2x", XE_INB(i)); 2449 } 2450 printf("\n"); 2451 } 2452 2453 (void)splx(s); 2454} 2455#endif 2456
| 2196 XE_SELECT_PAGE(page); 2197 for (i = 8; i < 16; i++) { 2198 printf(" %2.2x", XE_INB(i)); 2199 } 2200 printf("\n"); 2201 } 2202 2203 (void)splx(s); 2204} 2205#endif 2206
|
| 2207int 2208xe_activate(device_t dev) 2209{ 2210 struct xe_softc *sc = device_get_softc(dev); 2211 int err;
|
2457
| 2212
|
| 2213 sc->port_rid = 0; 2214 sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid, 2215 0, ~0, 16, RF_ACTIVE); 2216 if (!sc->port_res) { 2217#if XE_DEBUG > 0 2218 device_printf(dev, "Cannot allocate ioport\n"); 2219#endif 2220 return ENOMEM; 2221 }
|
2458
| 2222
|
2459#if NAPM > 0 2460/************************************************************** 2461 * * 2462 * A P M F U N C T I O N S * 2463 * * 2464 **************************************************************/ 2465 2466/* 2467 * This is called when we go into suspend/standby mode 2468 */ 2469static int 2470xe_suspend(void *xunit) { 2471 2472#ifdef XE_DEBUG 2473 struct xe_softc *scp = sca[(int)xunit]; 2474 2475 printf("xe%d: APM suspend\n", scp->unit);
| 2223 sc->irq_rid = 0; 2224 sc->irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irq_rid, 2225 0, ~0, 1, RF_ACTIVE); 2226 if (!sc->irq_res) { 2227#if XE_DEBUG > 0 2228 device_printf(dev, "Cannot allocate irq\n");
|
2476#endif
| 2229#endif
|
| 2230 xe_deactivate(dev); 2231 return ENOMEM; 2232 } 2233 if ((err = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET, xe_intr, sc, 2234 &sc->intrhand)) != 0) { 2235 xe_deactivate(dev); 2236 return err; 2237 } 2238 2239 sc->bst = rman_get_bustag(sc->port_res); 2240 sc->bsh = rman_get_bushandle(sc->port_res); 2241 return (0); 2242}
|
2477
| 2243
|
2478 return 0;
| 2244void 2245xe_deactivate(device_t dev) 2246{ 2247 struct xe_softc *sc = device_get_softc(dev); 2248 2249 if (sc->intrhand) 2250 bus_teardown_intr(dev, sc->irq_res, sc->intrhand); 2251 sc->intrhand = 0; 2252 if (sc->port_res) 2253 bus_release_resource(dev, SYS_RES_IOPORT, sc->port_rid, 2254 sc->port_res); 2255 sc->port_res = 0; 2256 if (sc->irq_res) 2257 bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, 2258 sc->irq_res); 2259 sc->irq_res = 0; 2260 return;
|
2479} 2480
| 2261} 2262
|
2481/* 2482 * This is called when we wake up again 2483 */ 2484static int 2485xe_resume(void *xunit) {
| 2263static device_method_t xe_pccard_methods[] = { 2264 /* Device interface */ 2265 DEVMETHOD(device_probe, xe_probe), 2266 DEVMETHOD(device_attach, xe_attach), 2267 DEVMETHOD(device_detach, xe_detach),
|
2486
| 2268
|
2487#ifdef XE_DEBUG 2488 struct xe_softc *scp = sca[(int)xunit];
| 2269 { 0, 0 } 2270};
|
2489
| 2271
|
2490 printf("xe%d: APM resume\n", scp->unit); 2491#endif
| 2272static driver_t xe_pccard_driver = { 2273 "xe", 2274 xe_pccard_methods, 2275 sizeof(struct xe_softc), 2276};
|
2492
| 2277
|
2493 return 0; 2494}
| 2278devclass_t xe_devclass;
|
2495
| 2279
|
2496#endif /* NAPM > 0 */ 2497 2498#endif /* NCARD > 0 */ 2499 2500#endif /* NXE > 0 */
| 2280DRIVER_MODULE(xe, pccard, xe_pccard_driver, xe_devclass, 0, 0);
|
| |