This is my first cut on a driver for the RealTek RTL 8002 pocket

ethernet driver.

The BUGS section is still impressive, but the driver seems to work for
me now.  Disclaimer: i haven't been able to test this under -current
so far (but it compiles, and the notebook it's intended for can now be
updated to -current more easy than before).  Don't be afraid of the
many #ifdefs on __FreeBSD_version in the imported file; i want them in
the repository on the vendor-branch so other people can also manually
integrate it into older systems.  I'll clean it up on the -current
branch in a followup commit.  The vendor-banch version right now
supports systems back to 2.2R.

This driver should be layered upon ppc(4), but i currently have no
idea how to do this.

Eventually i'll further develop the driver to also support the more
modern RTL 8012 success, which seems to be present in a number of
cheap pocket ethernet adapters these days.  Right now, i doubt it will
run with the 8012 without any changes.

Finally a big Thanks! to RealTek for promptly providing me with
documentation and with the source code for the 8012 pocket driver upon
request.  I wish all vendors were that cooperative!.
This commit is contained in:
Joerg Wunsch 1998-12-21 18:01:15 +00:00
parent 19676bfc7d
commit 8194a57215
3 changed files with 1861 additions and 0 deletions

View File

@ -0,0 +1,181 @@
.\"
.\"
.\" Copyright (c) 1997 Joerg Wunsch
.\"
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $Id: rdp.4,v 1.1.1.1 1998/12/21 12:43:35 j Exp $
.\"
.\"
.\" " (emacs disconfusion)
.Dd December 21, 1998
.Dt RDP 4 i386
.Os
.Sh NAME
.Nm rdp
.Nd Ethernet driver for RealTek RTL 8002 pocket ethernet
.Sh SYNOPSIS
.Cd "device rdp0 at isa? port 0x378 net irq 7"
.Cd "device rdp0 at isa? port 0x378 net irq 7 flags 0x2"
.Sh DESCRIPTION
The
.Nm
device driver supports RealTek RTL 8002-based pocket ethernet adapters,
connected to a standard parallel port.
.Pp
These adapters seem to belong to the cheaper choices among pocket
ethernet adapters. The RTL 8002 is the central part, containing an
interface to BNC and UTP (10 Mbit/s) media, as well as a host
interface that is designed to talk to standard parallel printer
adapters. For the full ethernet adapter to work, it is completed by
an external RAM used as the Tx and Rx packet buffer (16 K x 4 for the
RTL 8002), and an EEPROM to hold the assigned ethernet hardware
address. For the RTL 8002, the EEPROM can be either a standard 93C46
serial EEPROM (which seems to be a common choice), or a 74S288
parallel one. The latter variant needs the device configuration flag
0x1 in order to work.
.Pp
Since standard printer adapters seem to vary wildly among their timing
requirements, there are currently two possible choices for the way
data are being exchanged between the pocket ethernet adapter and the
printer interface. The default is the fastest mode the RTL 8002
supports. If the printer adapter to use is particularly slow (which
can be noticed by watching the ethernet wire for crippled packets, or
by not seeing correclty received packets), the configuration flag 0x2
can be set in order to throttle down the
.Nm
driver. Note that in fast mode, the data rate is assymetric, sending
is a little faster (up to two times) than receiving. Rates like 150
KB/s for sending and 80 KB/s for receiving are common. For slow mode,
both rates are about the same, and in the range of 50 KB/s through 70
KB/s. As always, your mileage may vary.
.Pp
In case the adapter isn't recognized at boot-time, setting the
.Em bootverbose
flag
.Pq Ql Fl v
might help in diagnosing the reason. Since the RTL 8002 requires
the availability of a working interrupt for the printer adapter (unlike
the
.Xr lpt 4
driver), the
.Nm
driver fails to attach if the ethernet adapter cannot assert an
interrupt at probe time.
.Pp
The RTL 8002 doesn't support (hardware) multicast.
.Pp
The
.Nm
driver internally sets a flag so it gets probed very early. This way,
it is possible to configure both, an
.Nm
driver as well as an
.Xr lpt 4
driver into the same kernel. If no RTL 8002 hardware is present, probing
will eventually detect the printer driver.
.Sh DIAGNOSTICS
.Pp
.Dl "rdp0: configured IRQ (7) cannot be asserted by device"
.Pp
The probe routine was unable to get the RTL 8002 asserting an interrupt
request through the printer adapter.
.Pp
.Dl "rdp0: failed to find a valid hardware address in EEPROM"
.Pp
Since there doesn't seem to be a standard place for storing the hardware
ethernet address within the EEPROM, the
.Nm
driver walks the entire (serial) EEPROM contents until it finds something
that looks like a valid ethernet hardware address, based on the IEEE's
OUI assignments. This diagnostic tells the driver was unable to find
one. Note: it might as well be the current adapter is one of the rare
examples with a 74S288 EEPROM, so
.Ql flags 0x1
should be tried.
.Pp
.Dl "rdp0: Device timeout"
.Pp
After initiating a packet transmission, the ethernet adapter didn't
return a notification of the (successful or failed) transmission. The
hardware is likely to be wedged, and is being reset.
.Pp
.Sh SEE ALSO
.Xr lpt 4 ,
.Xr ifconfig 8
.Sh AUTHORS
This driver was written by
.ie t J\(:org Wunsch,
.el Joerg Wunsch,
based on RealTek's packet driver for the RTL 8002, as well as on some
description of the successor chip, RTL 8012, RealTek was gratefully
providing.
.Sh BUGS
There are certainly many of them.
.Pp
Since the
.Nm
driver wants to probe its hardware at boot-time, the adapter needs
to be present then in order to be detected.
.Pp
Only two out of the eight different speed modes RealTek's packet
driver could handle are implemented. Thus there might be hardware
where even the current slow mode is too fast.
.Pp
There should be a DMA transfer test in the probe routine that figures
out the usable mode automatically.
.Pp
Abusing a standard printer interface for data exchange is error-prone.
Occasional stuck hardware shouldn't surprise too much, hopefully the
timeout routine will catch these cases. Flood-pinging is a good
example of triggering this problem. Likewise, albeit BPF is of course
supported, it's certainly a bad idea attempting to watch a crowded
ethernet wire using promiscuous mode.
.Pp
Since the RTL 8002 has only 4 KB of Rx buffer space (2 x 2 KB are used
as Tx buffers), the usual NFS deadlock with large packets arriving too
quickly could happen if a machine using the
.Nm
driver NFS-mounts some fast server with the standard NFS blocksize of
8 KB. (Since NFS can only retransmit entire NFS packets, the same
packet will be retransmitted over and over again.)
.Pp
The heuristic to find out the ethernet hardware address from the
EEPROM sucks, but seems to be the only sensible generic way that
doesn't depend on the actual location in EEPROM. RealTek's sample
driver placed it directly at address 0, other vendors picked something
like 15, with other junk in front of it that must not be confused with
a valid ethernet address.
.Pp
The driver should support the successor chip RTL 8012, which seems to
be available and used these days. (The RTL 8002 is already somewhat
aged, around 1992/93.) The RTL 8012 offers support for advanced
printer adapter hardware, like bidirectional SPP, or EPP, which could
speed up the transfers substantially. The RTL 8012 also supports
hardware multicast, and has the ability to address 64 K x 4 packet
buffer RAM.
.Pp
The driver should be layered upon the ppc driver, instead of working
standalone, and should be available as a loadable module, so the
device probing can be deferred until the pocket ethernet adapter has
actually been attached.

1493
sys/i386/isa/if_rdp.c Normal file

File diff suppressed because it is too large Load Diff

187
sys/i386/isa/if_rdpreg.h Normal file
View File

@ -0,0 +1,187 @@
#ifndef IF_RDPREG_H
#define IF_RDPREG_H 1
/*
* Copyright (c) 1998 Joerg Wunsch
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: if_rdpreg.h,v 1.1.1.1 1998/12/21 12:43:35 j Exp $
*/
/*
* Part of the definitions here has been copied over from the REDP
* packet driver's REDPPD.INC file. This provides us with the same
* set of acronyms as the packet driver is using.
*
* The packet driver had no copyright, and is believed to be in the
* public domain. The author seems to be someone who calls himself
* "Chiu", so that's the only acknowledgment i can give here.
* Supposedly the author was someone from RealTek.
*/
/*
* We're hanging upon an LPT port, thus suck in the lpt defs as well.
*/
#include <i386/isa/lptreg.h>
struct rdphdr {
/* RTL8002 header that is prepended to the actual packet */
u_char unused2[2];
u_short pktlen;
u_char status; /* copy of RSR for this packet */
u_char unused3[3];
};
/*
*
* 8 Data Modes are provided:
*
* +--------+---------------+-------------+
* | Mode | Read | Write |
* +--------+---------------+-------------+
* | 0 | LptCtrl | LptData |
* +--------+---------------+-------------+
* | 1 | LptCtrl | LptCtrl |
* +--------+---------------+-------------+
* | 2 | LptCtrl*2 | LptData |
* +--------+---------------+-------------+
* | 3 | LptCtrl*2 | LptCtrl |
* +--------+---------------+-------------+
* | 4 | LptData | LptData |
* +--------+---------------+-------------+
* | 5 | LptData | LptCtrl |
* +--------+---------------+-------------+
* | 6 | LptData*2 | LptData |
* +--------+---------------+-------------+
* | 7 | LptData*2 | LptCtrl |
* +--------+---------------+-------------+
*
* Right now, this driver only implements mode 0 (which ought to work
* on any standard parallel interface).
*
*/
/*
* Page 0 of EPLC registers
*/
#define IDR0 0x00 /* Ethernet ID register (R/W) */
#define IDR1 0x01
#define IDR2 0x02
#define IDR3 0x03
#define IDR4 0x04
#define IDR5 0x05
#define TBCR0 0x06 /* transmit byte count (W), 11 bits valid */
#define TBCR1 0x07
#define TSR 0x08 /* transmit status (R), cleared upon next tx */
# define TSR_TOK 1 /* transmit OK */
# define TSR_TABT 2 /* transmit aborted (excessive collisions) */
# define TSR_COL 4 /* collision detected */
# define TSR_CDH 8 /* CD heartbeat detected */
#define RSR 0x09 /*
* receiver status (R), cleared upon next
* received packet (but stored in rx buffer
* header anyway)
*/
# define RSR_ROK 1 /* receive OK */
# define RSR_CRC 2 /* CRC error */
# define RSR_FA 4 /* frame alignment error (not multiple of 8) */
# define RSR_BUFO 0x10 /* rx buffer overflow, packet discarded */
# define RSR_PUN 0x20 /* packet count underflow (jump command issued
* but rx buffer was empty) */
# define RSR_POV 0x40 /* packet count overflow (more than 254 (?)
* packets still in buffer) */
#define ISR 0x0A /* interrupt status register (R), writing
* clears the written bits */
# define ISR_TOK 1 /* transmission OK (~ TSR_TOK) */
# define ISR_TER 2 /* transmitter error (~ TSR_TABT) */
# define ISR_ROK 4 /* receive OK (~ RSR_ROK) */
# define ISR_RER 8 /* receiver error (~ RSR_CRC|RSR_FA) */
# define ISR_RBER 0x10 /* rx buffer overflow (POV|PUN|BUFO) */
#define IMR 0x0B /* interrupt mask register (R/W), bit as ISR */
#define CMR1 0x0C /* command register 1 (R/W) */
# define CMR1_BUFE 1 /* (R) rx buffer empty */
# define CMR1_IRQ 2 /* (R) interrupt request */
# define CMR1_TRA 4 /* (R) transmission in progress */
/* (W) transmit start */
# define CMR1_TE 0x10 /* (R/W) transmitter enable */
# define CMR1_RE 0x20 /* (R/W) receiver enable */
# define CMR1_RST 0x40 /* (R/W) reset; sticks until reset completed */
# define CMR1_RDPAC 1 /* (W) `rx jump packet', prepare for reading
* next packet from ring buffer */
# define CMR1_WRPAC 2 /* (W) `tx jump packet', packet in tx buffer
* is complete and can be sent */
# define CMR1_RETX 8 /* (W) retransmit (must be accomp'ed by TRA) */
# define CMR1_MUX 0x80 /* (W) RTL8012: tell the printer MUX to
* connect the output pins to the host */
#define CMR2 0x0D /* command register 2 (R/W) */
# define CMR2_IRQOUT 1 /* interrupt signal output enabled */
# define CMR2_RAMTST 2 /* enable RAM test */
# define CMR2_PAGE 4 /* select register page #1 */
# define CMR2_IRQINV 8 /* make active IRQ `low' */
# define CMR2_AMbits 0x30 /* address mode bits: */
# define CMR2_AM_NONE 0x00 /* 0: accept nothing */
# define CMR2_AM_PHYS 0x10 /* 1: only physical addr */
# define CMR2_AM_PB 0x20 /* 2: phys + broadcast */
# define CMR2_AM_ALL 0x30 /* 3: promiscuous */
# define CMR2_LBK 0x40 /* enable loopback */
# define CMR2_SER 0x80 /* save error packet */
#define MAR 0x0E /* memory access register (?), used for
* remote DMA to the 8002's buffer */
#define PNR TBCR0 /* received packet number (R) */
#define COLR TBCR1 /* collision count (R) (4 bit valid) */
/*
* Page 1 of EPLC registers -- EEPROM control
*/
#define PCMR TBCR0 /* port command register */
/* bits for 93C46 control -- add HNib */
#define PCMR_SK 0x04 /* serial clock for EEPROM */
#define PCMR_CS 0x02 /* chip select for EEPROM */
#define PCMR_DO 0x01 /* DI to EEPROM */
/* EEPROM data, nibbles for 74S288, bits for 93C46 */
#define PDR TBCR1 /* DO from EEPROM, only bit 0 valid for
* serial EEPROM */
/*
* The following definitionss define remote DMA command through LptCtrl
*/
#define ATFD 3 /* ATFD bit in Lpt's Control register */
/* -> ATFD bit is added for Xircom's MUX */
#define Ctrl_LNibRead (0x08+ATFD) /* specify low nibble */
#define Ctrl_HNibRead (0+ATFD) /* specify high nibble */
#define Ctrl_SelData (0x04+ATFD) /* not through LptCtrl but through */
/* LptData */
#define Ctrl_IRQEN 0x10 /* set IRQEN of lpt control register */
/* Here define constants to construct the required read/write commands */
#define WrAddr 0x40 /* set address of EPLC write register */
#define RdAddr 0x0C0 /* set address of EPLC read register */
#define EOR 0x20 /* ORed to make 'end of read',set CSB=1 */
#define EOW 0x0E0 /* end of write, R/WB=A/DB=CSB=1 */
#define EOC 0x0E0 /* End Of r/w Command, R/WB=A/DB=CSB=1 */
#define HNib 0x10
#define MkHi(value) (((value) >> 4) | HNib)
#endif /* IF_RDPREG_H */