1 /* $OpenBSD: if_lmcvar.h,v 1.6 2002/06/02 22:50:00 deraadt Exp $ */ 2 /* $NetBSD: if_lmcvar.h,v 1.1 1999/03/25 03:32:43 explorer Exp $ */ 3 4 /*- 5 * Copyright (c) 1997-1999 LAN Media Corporation (LMC) 6 * All rights reserved. www.lanmedia.com 7 * 8 * This code is written by Michael Graff <graff@vix.com> for LMC. 9 * The code is derived from permitted modifications to software created 10 * by Matt Thomas (matt@3am-software.com). 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above 18 * copyright notice, this list of conditions and the following disclaimer 19 * in the documentation and/or other materials provided with the 20 * distribution. 21 * 3. All marketing or advertising materials mentioning features or 22 * use of this software must display the following acknowledgement: 23 * This product includes software developed by LAN Media Corporation 24 * and its contributors. 25 * 4. Neither the name of LAN Media Corporation nor the names of its 26 * contributors may be used to endorse or promote products derived 27 * from this software without specific prior written permission. 28 * 29 * THIS SOFTWARE IS PROVIDED BY LAN MEDIA CORPORATION AND CONTRIBUTORS 30 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 31 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 32 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 33 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 36 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 37 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 39 * THE POSSIBILITY OF SUCH DAMAGE. 40 */ 41 42 /*- 43 * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com) 44 * All rights reserved. 45 * 46 * Redistribution and use in source and binary forms, with or without 47 * modification, are permitted provided that the following conditions 48 * are met: 49 * 1. Redistributions of source code must retain the above copyright 50 * notice, this list of conditions and the following disclaimer. 51 * 2. The name of the author may not be used to endorse or promote products 52 * derived from this software without specific prior written permission 53 * 54 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 55 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 56 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 57 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 58 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 59 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 60 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 61 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 62 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 63 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 64 */ 65 66 #define LMC_MTU 1500 67 #define PPP_HEADER_LEN 4 68 #define BIG_PACKET 69 70 /* 71 * This turns on all sort of debugging stuff and make the 72 * driver much larger. 73 */ 74 #if 0 75 #define LMC_DEBUG 76 #define DP(x) printf x 77 #else 78 #define DP(x) 79 #endif 80 81 /* 82 * the dec chip has its own idea of what a receive error is, but we don't 83 * want to use it, as it will get the crc error wrong when 16-bit 84 * crcs are used. So, we only care about certain conditions. 85 */ 86 #ifndef TULIP_DSTS_RxMIIERR 87 #define TULIP_DSTS_RxMIIERR 0x00000008 88 #endif 89 #define LMC_DSTS_ERRSUM (TULIP_DSTS_RxMIIERR) 90 91 /* 92 * This is the PCI configuration support. 93 */ 94 #define PCI_CFID 0x00 /* Configuration ID */ 95 #define PCI_CFCS 0x04 /* Configurtion Command/Status */ 96 #define PCI_CFRV 0x08 /* Configuration Revision */ 97 #define PCI_CFLT 0x0c /* Configuration Latency Timer */ 98 #define PCI_CBIO 0x10 /* Configuration Base IO Address */ 99 #define PCI_CBMA 0x14 /* Configuration Base Memory Address */ 100 #define PCI_SSID 0x2c /* subsystem config register */ 101 #define PCI_CFIT 0x3c /* Configuration Interrupt */ 102 #define PCI_CFDA 0x40 /* Configuration Driver Area */ 103 104 #define LMC_HZ 10 105 106 #ifndef TULIP_GP_PINSET 107 #define TULIP_GP_PINSET 0x00000100L 108 #endif 109 #ifndef TULIP_BUSMODE_READMULTIPLE 110 #define TULIP_BUSMODE_READMULTIPLE 0x00200000L 111 #endif 112 113 #if defined(__NetBSD__) 114 115 #include "rnd.h" 116 #if NRND > 0 117 #include <sys/rnd.h> 118 #endif 119 120 #endif /* NetBSD */ 121 122 #if defined(__NetBSD__) || defined(__OpenBSD__) 123 #define LMC_CSR_READ(sc, csr) \ 124 bus_space_read_4((sc)->lmc_bustag, (sc)->lmc_bushandle, (sc)->lmc_csrs.csr) 125 #define LMC_CSR_WRITE(sc, csr, val) \ 126 bus_space_write_4((sc)->lmc_bustag, (sc)->lmc_bushandle, (sc)->lmc_csrs.csr, (val)) 127 128 #define LMC_CSR_READBYTE(sc, csr) \ 129 bus_space_read_1((sc)->lmc_bustag, (sc)->lmc_bushandle, (sc)->lmc_csrs.csr) 130 #define LMC_CSR_WRITEBYTE(sc, csr, val) \ 131 bus_space_write_1((sc)->lmc_bustag, (sc)->lmc_bushandle, (sc)->lmc_csrs.csr, (val)) 132 #endif /* __NetBSD__ */ 133 134 #if !defined(__NetBSD__) && !defined(__OpenBSD__) 135 #define LMC_CSR_READ(sc, csr) (inl((sc)->lmc_csrs.csr)) 136 #define LMC_CSR_WRITE(sc, csr, val) outl((sc)->lmc_csrs.csr, val) 137 138 #define LMC_CSR_READBYTE(sc, csr) (inb((sc)->lmc_csrs.csr)) 139 #define LMC_CSR_WRITEBYTE(sc, csr, val) outb((sc)->lmc_csrs.csr, val) 140 #endif /* __NetBSD__ */ 141 142 #define LMC_PCI_CSRSIZE 8 143 #define LMC_PCI_CSROFFSET 0 144 145 #if !defined(__NetBSD__) && !defined(__OpenBSD__) 146 /* 147 * macros to read and write CSRs. Note that the "0 +" in 148 * READ_CSR is to prevent the macro from being an lvalue 149 * and WRITE_CSR shouldn't be assigned from. 150 */ 151 #define LMC_CSR_READ(sc, csr) (0 + *(sc)->lmc_csrs.csr) 152 #define LMC_CSR_WRITE(sc, csr, val) ((void)(*(sc)->lmc_csrs.csr = (val))) 153 #endif /* __NetBSD__ */ 154 155 /* 156 * This structure contains "pointers" for the registers on 157 * the various 21x4x chips. 158 */ 159 typedef struct { 160 lmc_csrptr_t csr_busmode; /* CSR0 */ 161 lmc_csrptr_t csr_txpoll; /* CSR1 */ 162 lmc_csrptr_t csr_rxpoll; /* CSR2 */ 163 lmc_csrptr_t csr_rxlist; /* CSR3 */ 164 lmc_csrptr_t csr_txlist; /* CSR4 */ 165 lmc_csrptr_t csr_status; /* CSR5 */ 166 lmc_csrptr_t csr_command; /* CSR6 */ 167 lmc_csrptr_t csr_intr; /* CSR7 */ 168 lmc_csrptr_t csr_missed_frames; /* CSR8 */ 169 lmc_csrptr_t csr_9; /* CSR9 */ 170 lmc_csrptr_t csr_10; /* CSR10 */ 171 lmc_csrptr_t csr_11; /* CSR11 */ 172 lmc_csrptr_t csr_12; /* CSR12 */ 173 lmc_csrptr_t csr_13; /* CSR13 */ 174 lmc_csrptr_t csr_14; /* CSR14 */ 175 lmc_csrptr_t csr_15; /* CSR15 */ 176 } lmc_regfile_t; 177 178 #define csr_enetrom csr_9 /* 21040 */ 179 #define csr_reserved csr_10 /* 21040 */ 180 #define csr_full_duplex csr_11 /* 21040 */ 181 #define csr_bootrom csr_10 /* 21041/21140A/?? */ 182 #define csr_gp csr_12 /* 21140* */ 183 #define csr_watchdog csr_15 /* 21140* */ 184 #define csr_gp_timer csr_11 /* 21041/21140* */ 185 #define csr_srom_mii csr_9 /* 21041/21140* */ 186 #define csr_sia_status csr_12 /* 2104x */ 187 #define csr_sia_connectivity csr_13 /* 2104x */ 188 #define csr_sia_tx_rx csr_14 /* 2104x */ 189 #define csr_sia_general csr_15 /* 2104x */ 190 191 /* 192 * While 21x4x allows chaining of its descriptors, this driver 193 * doesn't take advantage of it. We keep the descriptors in a 194 * traditional FIFO ring. 195 */ 196 struct lmc_ringinfo { 197 tulip_desc_t *ri_first; /* first entry in ring */ 198 tulip_desc_t *ri_last; /* one after last entry */ 199 tulip_desc_t *ri_nextin; /* next to processed by host */ 200 tulip_desc_t *ri_nextout; /* next to processed by adapter */ 201 int ri_max; 202 int ri_free; 203 }; 204 205 /* 206 * The 21040 has a stupid restriction in that the receive 207 * buffers must be longword aligned. But since Ethernet 208 * headers are not a multiple of longwords in size this forces 209 * the data to non-longword aligned. Since IP requires the 210 * data to be longword aligned, we need to copy it after it has 211 * been DMA'ed in our memory. 212 * 213 * Since we have to copy it anyways, we might as well as allocate 214 * dedicated receive space for the input. This allows to use a 215 * small receive buffer size and more ring entries to be able to 216 * better keep with a flood of tiny Ethernet packets. 217 * 218 * The receive space MUST ALWAYS be a multiple of the page size. 219 * And the number of receive descriptors multiplied by the size 220 * of the receive buffers must equal the recevive space. This 221 * is so that we can manipulate the page tables so that even if a 222 * packet wraps around the end of the receive space, we can 223 * treat it as virtually contiguous. 224 * 225 * The above used to be true (the stupid restriction is still true) 226 * but we gone to directly DMA'ing into MBUFs (unless it's on an 227 * architecture which can't handle unaligned accesses) because with 228 * 100Mb/s cards the copying is just too much of a hit. 229 */ 230 231 #define LMC_RXDESCS 48 232 #define LMC_TXDESCS 128 233 #define LMC_RXQ_TARGET 32 234 #if LMC_RXQ_TARGET >= LMC_RXDESCS 235 #error LMC_RXQ_TARGET must be less than LMC_RXDESCS 236 #endif 237 238 #define LMC_RX_BUFLEN ((MCLBYTES < 2048 ? MCLBYTES : 2048) - 16) 239 240 #define LMC_LINK_UP 1 241 #define LMC_LINK_DOWN 0 242 243 typedef enum { 244 LMC_21140, LMC_21140A, 245 LMC_CHIPID_UNKNOWN 246 } lmc_chipid_t; 247 248 #define LMC_BIT(b) (1L << ((int)(b))) 249 250 typedef struct { 251 /* 252 * Transmit Statistics 253 */ 254 u_int32_t dot3StatsSingleCollisionFrames; 255 u_int32_t dot3StatsMultipleCollisionFrames; 256 u_int32_t dot3StatsSQETestErrors; 257 u_int32_t dot3StatsDeferredTransmissions; 258 u_int32_t dot3StatsLateCollisions; 259 u_int32_t dot3StatsExcessiveCollisions; 260 u_int32_t dot3StatsCarrierSenseErrors; 261 u_int32_t dot3StatsInternalMacTransmitErrors; 262 u_int32_t dot3StatsInternalTransmitUnderflows; /* not in rfc1650! */ 263 u_int32_t dot3StatsInternalTransmitBabbles; /* not in rfc1650! */ 264 /* 265 * Receive Statistics 266 */ 267 u_int32_t dot3StatsMissedFrames; /* not in rfc1650! */ 268 u_int32_t dot3StatsAlignmentErrors; 269 u_int32_t dot3StatsFCSErrors; 270 u_int32_t dot3StatsFrameTooLongs; 271 u_int32_t dot3StatsInternalMacReceiveErrors; 272 } lmc_dot3_stats_t; 273 274 /* 275 * Now to important stuff. This is softc structure (where does softc 276 * come from??? No idea) for the tulip device. 277 * 278 */ 279 struct lmc___softc { 280 #if defined(__bsdi__) 281 struct device lmc_dev; /* base device */ 282 struct isadev lmc_id; /* ISA device */ 283 struct intrhand lmc_ih; /* intrrupt vectoring */ 284 struct atshutdown lmc_ats; /* shutdown hook */ 285 struct p2pcom lmc_p2pcom; /* point-to-point common stuff */ 286 287 #define lmc_if lmc_p2pcom.p2p_if /* network-visible interface */ 288 #endif /* __bsdi__ */ 289 290 #if defined(__NetBSD__) || defined(__OpenBSD__) 291 struct device lmc_dev; /* base device */ 292 void *lmc_ih; /* intrrupt vectoring */ 293 void *lmc_ats; /* shutdown hook */ 294 bus_space_tag_t lmc_bustag; 295 bus_space_handle_t lmc_bushandle; /* CSR region handle */ 296 pci_chipset_tag_t lmc_pc; 297 #endif 298 299 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) 300 struct sppp lmc_sppp; 301 #define lmc_if lmc_sppp.pp_if 302 #endif 303 304 u_int8_t lmc_enaddr[6]; /* yes, a small hack... */ 305 lmc_regfile_t lmc_csrs; 306 volatile u_int32_t lmc_txtick; 307 volatile u_int32_t lmc_rxtick; 308 u_int32_t lmc_flags; 309 310 u_int32_t lmc_features; /* static bits indicating features of chip */ 311 u_int32_t lmc_intrmask; /* our copy of csr_intr */ 312 u_int32_t lmc_cmdmode; /* our copy of csr_cmdmode */ 313 u_int32_t lmc_last_system_error : 3; /* last system error (only value is LMC_SYSTEMERROR is also set) */ 314 u_int32_t lmc_system_errors; /* number of system errors encountered */ 315 u_int32_t lmc_statusbits; /* status bits from CSR5 that may need to be printed */ 316 317 u_int8_t lmc_revinfo; /* revision of chip */ 318 u_int8_t lmc_cardtype; /* LMC_CARDTYPE_HSSI or ..._DS3 */ 319 u_int32_t lmc_gpio_io; /* state of in/out settings */ 320 u_int32_t lmc_gpio; /* state of outputs */ 321 u_int8_t lmc_gp; 322 323 lmc_chipid_t lmc_chipid; /* type of chip we are using */ 324 u_int32_t lmc_miireg16; 325 struct ifqueue lmc_txq; 326 struct ifqueue lmc_rxq; 327 lmc_dot3_stats_t lmc_dot3stats; 328 lmc_ringinfo_t lmc_rxinfo; 329 lmc_ringinfo_t lmc_txinfo; 330 u_int8_t lmc_rombuf[128]; 331 lmc_media_t *lmc_media; 332 lmc_ctl_t ictl; 333 334 #if defined(__NetBSD__) || defined(__OpenBSD__) 335 struct device *lmc_pci_busno; /* needed for multiport boards */ 336 #else 337 u_int8_t lmc_pci_busno; /* needed for multiport boards */ 338 #endif 339 u_int8_t lmc_pci_devno; /* needed for multiport boards */ 340 #if defined(__FreeBSD__) 341 tulip_desc_t *lmc_rxdescs; 342 tulip_desc_t *lmc_txdescs; 343 #else 344 tulip_desc_t lmc_rxdescs[LMC_RXDESCS]; 345 tulip_desc_t lmc_txdescs[LMC_TXDESCS]; 346 #endif 347 #if defined(__NetBSD__) && NRND > 0 348 rndsource_element_t lmc_rndsource; 349 #endif 350 351 u_int32_t lmc_crcSize; 352 u_int32_t tx_clockState; 353 char lmc_yel, lmc_blue, lmc_red; /* for T1 and DS3 */ 354 char lmc_timing; /* for HSSI and SSI */ 355 u_int16_t t1_alarm1_status; 356 u_int16_t t1_alarm2_status; 357 }; 358 359 /* 360 * lmc_flags 361 */ 362 #define LMC_IFUP 0x00000001 363 #define LMC_00000002 0x00000002 364 #define LMC_00000004 0x00000004 365 #define LMC_00000008 0x00000008 366 #define LMC_00000010 0x00000010 367 #define LMC_MODEMOK 0x00000020 368 #define LMC_00000040 0x00000040 369 #define LMC_00000080 0x00000080 370 #define LMC_RXACT 0x00000100 371 #define LMC_INRESET 0x00000200 372 #define LMC_NEEDRESET 0x00000400 373 #define LMC_00000800 0x00000800 374 #define LMC_00001000 0x00001000 375 #define LMC_00002000 0x00002000 376 #define LMC_WANTTXSTART 0x00004000 377 #define LMC_NEWTXTHRESH 0x00008000 378 #define LMC_NOAUTOSENSE 0x00010000 379 #define LMC_PRINTLINKUP 0x00020000 380 #define LMC_LINKUP 0x00040000 381 #define LMC_RXBUFSLOW 0x00080000 382 #define LMC_NOMESSAGES 0x00100000 383 #define LMC_SYSTEMERROR 0x00200000 384 #define LMC_TIMEOUTPENDING 0x00400000 385 #define LMC_00800000 0x00800000 386 #define LMC_01000000 0x01000000 387 #define LMC_02000000 0x02000000 388 #define LMC_RXIGNORE 0x04000000 389 #define LMC_08000000 0x08000000 390 #define LMC_10000000 0x10000000 391 #define LMC_20000000 0x20000000 392 #define LMC_40000000 0x40000000 393 #define LMC_80000000 0x80000000 394 395 /* 396 * lmc_features 397 */ 398 #define LMC_HAVE_GPR 0x00000001 /* have gp register (140[A]) */ 399 #define LMC_HAVE_RXBADOVRFLW 0x00000002 /* RX corrupts on overflow */ 400 #define LMC_HAVE_POWERMGMT 0x00000004 /* Snooze/sleep modes */ 401 #define LMC_HAVE_MII 0x00000008 /* Some medium on MII */ 402 #define LMC_HAVE_SIANWAY 0x00000010 /* SIA does NWAY */ 403 #define LMC_HAVE_DUALSENSE 0x00000020 /* SIA senses both AUI & TP */ 404 #define LMC_HAVE_SIAGP 0x00000040 /* SIA has a GP port */ 405 #define LMC_HAVE_BROKEN_HASH 0x00000080 /* Broken Multicast Hash */ 406 #define LMC_HAVE_ISVSROM 0x00000100 /* uses ISV SROM Format */ 407 #define LMC_HAVE_BASEROM 0x00000200 /* Board ROM can be cloned */ 408 #define LMC_HAVE_SLAVEDROM 0x00000400 /* Board ROM cloned */ 409 #define LMC_HAVE_SLAVEDINTR 0x00000800 /* Board slaved interrupt */ 410 #define LMC_HAVE_SHAREDINTR 0x00001000 /* Board shares interrupts */ 411 #define LMC_HAVE_OKROM 0x00002000 /* ROM was recognized */ 412 #define LMC_HAVE_NOMEDIA 0x00004000 /* did not detect any media */ 413 #define LMC_HAVE_STOREFWD 0x00008000 /* have CMD_STOREFWD */ 414 #define LMC_HAVE_SIA100 0x00010000 /* has LS100 in SIA status */ 415 416 static const char * const lmc_system_errors[] = { 417 "parity error", 418 "master abort", 419 "target abort", 420 "reserved #3", 421 "reserved #4", 422 "reserved #5", 423 "reserved #6", 424 "reserved #7", 425 }; 426 427 static const char * const lmc_status_bits[] = { 428 NULL, 429 "transmit process stopped", 430 NULL, 431 "transmit jabber timeout", 432 433 NULL, 434 "transmit underflow", 435 NULL, 436 "receive underflow", 437 438 "receive process stopped", 439 "receive watchdog timeout", 440 NULL, 441 NULL, 442 443 "link failure", 444 NULL, 445 NULL, 446 }; 447 448 /* 449 * This driver supports a maximum of 32 devices. 450 */ 451 #define LMC_MAX_DEVICES 32 452 453 #if defined(__FreeBSD__) 454 typedef void ifnet_ret_t; 455 typedef int ioctl_cmd_t; 456 static lmc_softc_t *tulips[LMC_MAX_DEVICES]; 457 #if BSD >= 199506 458 #define LMC_IFP_TO_SOFTC(ifp) ((lmc_softc_t *)((ifp)->if_softc)) 459 #if NBPFILTER > 0 460 #define LMC_BPF_MTAP(sc, m) bpf_mtap(&(sc)->lmc_sppp.pp_if, m) 461 #define LMC_BPF_TAP(sc, p, l) bpf_tap(&(sc)->lmc_sppp.pp_if, p, l) 462 #define LMC_BPF_ATTACH(sc) bpfattach(&(sc)->lmc_sppp.pp_if, DLT_PPP, PPP_HEADER_LEN) 463 #endif 464 #define LMC_VOID_INTRFUNC 465 #define IFF_NOTRAILERS 0 466 #define LMC_EADDR_FMT "%6D" 467 #define LMC_EADDR_ARGS(addr) addr, ":" 468 #else 469 extern int bootverbose; 470 #define LMC_IFP_TO_SOFTC(ifp) (LMC_UNIT_TO_SOFTC((ifp)->if_unit)) 471 #include <sys/devconf.h> 472 #define LMC_DEVCONF 473 #endif 474 #define LMC_UNIT_TO_SOFTC(unit) (tulips[unit]) 475 #define LMC_BURSTSIZE(unit) pci_max_burst_len 476 #define loudprintf if (bootverbose) printf 477 #endif 478 479 #if defined(__bsdi__) 480 typedef int ifnet_ret_t; 481 typedef u_long ioctl_cmd_t; 482 extern struct cfdriver lmccd; 483 #define LMC_UNIT_TO_SOFTC(unit) ((lmc_softc_t *)lmccd.cd_devs[unit]) 484 #define LMC_IFP_TO_SOFTC(ifp) (LMC_UNIT_TO_SOFTC((ifp)->if_unit)) 485 #define loudprintf aprint_verbose 486 #define MCNT(x) (sizeof(x) / sizeof(struct ifmedia_entry)) 487 #define lmc_unit lmc_dev.dv_unit 488 #define lmc_name lmc_p2pcom.p2p_if.if_name 489 #define LMC_BPF_MTAP(sc, m) 490 #define LMC_BPF_TAP(sc, p, l) 491 #define LMC_BPF_ATTACH(sc) 492 #endif /* __bsdi__ */ 493 494 #if defined(__NetBSD__) || defined(__OpenBSD__) 495 typedef void ifnet_ret_t; 496 typedef u_long ioctl_cmd_t; 497 extern struct cfattach lmc_ca; 498 extern struct cfdriver lmc_cd; 499 #define LMC_UNIT_TO_SOFTC(unit) ((lmc_softc_t *) lmc_cd.cd_devs[unit]) 500 #define LMC_IFP_TO_SOFTC(ifp) ((lmc_softc_t *)((ifp)->if_softc)) 501 #define lmc_unit lmc_dev.dv_unit 502 #define lmc_xname lmc_if.if_xname 503 #define LMC_RAISESPL() splnet() 504 #define LMC_RAISESOFTSPL() splsoftnet() 505 #define LMC_RESTORESPL(s) splx(s) 506 /* #define lmc_enaddr lmc_enaddr */ 507 #define loudprintf printf 508 #define LMC_PRINTF_FMT "%s" 509 #define LMC_PRINTF_ARGS sc->lmc_xname 510 #if defined(__alpha__) 511 /* XXX XXX NEED REAL DMA MAPPING SUPPORT XXX XXX */ 512 #define LMC_KVATOPHYS(sc, va) alpha_XXX_dmamap((vm_offset_t)(va)) 513 #endif 514 #endif /* __NetBSD__ */ 515 516 #ifndef LMC_PRINTF_FMT 517 #define LMC_PRINTF_FMT "%s%d" 518 #endif 519 #ifndef LMC_PRINTF_ARGS 520 #define LMC_PRINTF_ARGS sc->lmc_name, sc->lmc_unit 521 #endif 522 523 #ifndef LMC_BURSTSIZE 524 #define LMC_BURSTSIZE(unit) 3 525 #endif 526 527 #ifndef lmc_unit 528 #define lmc_unit lmc_sppp.pp_if.if_unit 529 #endif 530 531 #ifndef lmc_name 532 #define lmc_name lmc_sppp.pp_if.if_name 533 #endif 534 535 #if !defined(lmc_bpf) 536 #if defined(__NetBSD__) || defined(__FreeBSD__) | defined(__OpenBSD__) 537 #define lmc_bpf lmc_sppp.pp_if.if_bpf 538 #endif 539 #if defined(__bsdi__) 540 #define lmc_bpf lmc_if.if_bpf 541 #endif 542 #endif 543 544 #if !defined(LMC_KVATOPHYS) 545 #define LMC_KVATOPHYS(sc, va) vtophys(va) 546 #endif 547 548 #ifndef LMC_RAISESPL 549 #define LMC_RAISESPL() splimp() 550 #endif 551 #ifndef LMC_RAISESOFTSPL 552 #define LMC_RAISESOFTSPL() splnet() 553 #endif 554 #ifndef TULUP_RESTORESPL 555 #define LMC_RESTORESPL(s) splx(s) 556 #endif 557 558 /* 559 * While I think FreeBSD's 2.2 change to the bpf is a nice simplification, 560 * it does add yet more conditional code to this driver. Sigh. 561 */ 562 #if !defined(LMC_BPF_MTAP) && NBPFILTER > 0 563 #define LMC_BPF_MTAP(sc, m) bpf_mtap((sc)->lmc_bpf, m) 564 #define LMC_BPF_TAP(sc, p, l) bpf_tap((sc)->lmc_bpf, p, l) 565 #define LMC_BPF_ATTACH(sc) bpfattach(&(sc)->lmc_bpf, &(sc)->lmc_sppp.pp_if, DLT_PPP, PPP_HEADER_LEN) 566 #endif 567 568 /* 569 * However, this change to FreeBSD I am much less enamored with. 570 */ 571 #if !defined(LMC_EADDR_FMT) 572 #define LMC_EADDR_FMT "%s" 573 #define LMC_EADDR_ARGS(addr) ether_sprintf(addr) 574 #endif 575 576 #define LMC_CRC32_POLY 0xEDB88320UL /* CRC-32 Poly -- Little Endian */ 577 #define LMC_MAX_TXSEG 30 578 579 #define LMC_ADDREQUAL(a1, a2) \ 580 (((u_int16_t *)a1)[0] == ((u_int16_t *)a2)[0] \ 581 && ((u_int16_t *)a1)[1] == ((u_int16_t *)a2)[1] \ 582 && ((u_int16_t *)a1)[2] == ((u_int16_t *)a2)[2]) 583 #define LMC_ADDRBRDCST(a1) \ 584 (((u_int16_t *)a1)[0] == 0xFFFFU \ 585 && ((u_int16_t *)a1)[1] == 0xFFFFU \ 586 && ((u_int16_t *)a1)[2] == 0xFFFFU) 587 588 typedef int lmc_spl_t; 589