Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Add driver for MCA Tiara LANCard / Fujitsu mb86950 Ether...



details:   https://anonhg.NetBSD.org/src/rev/c6d28cd37ac1
branches:  trunk
changeset: 579964:c6d28cd37ac1
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Sun Apr 03 11:21:44 2005 +0000

description:
Add driver for MCA Tiara LANCard / Fujitsu mb86950 EtherStar. Driver provided
in PR kern/26899 by Dave Barnes.

diffstat:

 sys/conf/files           |     7 +-
 sys/dev/ic/mb86950.c     |  1072 ++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/ic/mb86950reg.h  |   145 ++++++
 sys/dev/ic/mb86950var.h  |    90 +++
 sys/dev/mca/files.mca    |     7 +-
 sys/dev/mca/if_tra_mca.c |   253 ++++++++++
 6 files changed, 1572 insertions(+), 2 deletions(-)

diffs (truncated from 1615 to 300 lines):

diff -r 8ad5df6b2207 -r c6d28cd37ac1 sys/conf/files
--- a/sys/conf/files    Sun Apr 03 11:19:30 2005 +0000
+++ b/sys/conf/files    Sun Apr 03 11:21:44 2005 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files,v 1.714 2005/03/25 23:06:19 cube Exp $
+#      $NetBSD: files,v 1.715 2005/04/03 11:21:44 jdolecek Exp $
 
 #      @(#)files.newconf       7.5 (Berkeley) 5/10/93
 
@@ -669,6 +669,11 @@
 define sgec
 file   dev/ic/sgec.c                   sgec
 
+# MB86950 Ethernet Controller
+#
+define mb86950
+file   dev/ic/mb86950.c                mb86950
+
 # MB8696x Ethernet Controller
 #
 define mb86960
diff -r 8ad5df6b2207 -r c6d28cd37ac1 sys/dev/ic/mb86950.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/ic/mb86950.c      Sun Apr 03 11:21:44 2005 +0000
@@ -0,0 +1,1072 @@
+/*     $NetBSD: mb86950.c,v 1.1 2005/04/03 11:21:44 jdolecek Exp $     */
+
+/*
+ * All Rights Reserved, Copyright (C) Fujitsu Limited 1995
+ *
+ * This software may be used, modified, copied, distributed, and sold, in
+ * both source and binary form provided that the above copyright, these
+ * terms and the following disclaimer are retained.  The name of the author
+ * and/or the contributor may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND THE CONTRIBUTOR ``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 AUTHOR OR THE CONTRIBUTOR 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.
+ */
+
+/*
+ * Portions copyright (C) 1993, David Greenman.  This software may be used,
+ * modified, copied, distributed, and sold, in both source and binary form
+ * provided that the above copyright and these terms are retained.  Under no
+ * circumstances is the author responsible for the proper functioning of this
+ * software, nor does the author assume any responsibility for damages
+ * incurred with its use.
+ */
+
+ /*
+  * Portions copyright (c) 1995 Mika Kortelainen
+  * 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.
+  * 3. All advertising materials mentioning features or use of this software
+  *    must display the following acknowledgement:
+  *      This product includes software developed by  Mika Kortelainen
+  * 4. The name of the author may not be used to endorse or promote products
+  *    derived from this software without specific prior written permission
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+  */
+
+ /*
+  * Device driver for Fujitsu MB86960A/MB86965A based Ethernet cards.
+  * Contributed by M.S. <seki%sysrap.cs.fujitsu.co.jp@localhost>
+  */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: mb86950.c,v 1.1 2005/04/03 11:21:44 jdolecek Exp $");
+
+/*
+ * Device driver for Fujitsu mb86950 based Ethernet cards.
+ * Adapted by Dave J. Barnes from various Internet sources including
+ * mb86960.c (NetBSD), if_qn.c (NetBSD/Amiga), DOS Packet Driver (Brian Fisher,
+ * Queens University), EtherBoot Driver (Ken Yap).
+ */
+
+/* XXX There are still rough edges......
+
+ * (1) There is no watchdog timer for the transmitter. It's doubtful that
+ * transmit from the chip could be restarted without a hardware reset though.
+Fixed - not fully tested
+
+ * (2) The media interface callback goo is broke.  No big deal since to change
+ * from aui to bnc on the old Tiara LANCard requires moving 8 board jumpers.
+ * Other cards (SMC ?) using the EtherStar chip may support media change via software.
+Fixed - tested
+
+ * (3) The maximum outstanding transmit packets is set to 4.  What is a good limit
+ * of outstanding transmit packets for the EtherStar?  Is there a way to tell how
+ * many bytes are remaining to be transmitted? [no]
+---
+       When the EtherStar was designed, CPU power was a fraction of what it is now.  The
+       single EtherStar transmit buffer was fine.  It was unlikely that the CPU could
+       outrun the EtherStar. However, things in 2004 are quite different.  sc->txb_size
+       is used to keep the CPU from overrunning the EtherStar.  At most allow one packet
+       transmitting and one going into the fifo.
+---
+    No, that isn't right either :(
+
+ * (4) Multicast isn't supported.  Feel free to add multicast code if you know how
+ * to make the EtherStar do multicast.  Otherwise you'd have to use promiscuous mode
+ * and do multicast in software. OUCH!
+
+ * (5) There are no bus_space_barrier calls used. Are they needed? Maybe not.
+
+ * (6) Access to the fifo assumes word (16 bit) mode.  Cards configured for byte
+ * wide fifo access will require driver code changes.
+
+ * Only the minimum code necessary to make the Tiara LANCard work has been tested.
+ * Other cards may require more work, especially byte mode fifo and if DMA is used.
+
+ * djb / 2004
+
+ */
+
+#include "opt_inet.h"
+#include "opt_ns.h"
+#include "bpfilter.h"
+#include "rnd.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/errno.h>
+#include <sys/ioctl.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/syslog.h>
+#include <sys/device.h>
+#if NRND > 0
+#include <sys/rnd.h>
+#endif
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_types.h>
+#include <net/if_media.h>
+#include <net/if_ether.h>
+
+#ifdef INET
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/in_var.h>
+#include <netinet/ip.h>
+#include <netinet/if_inarp.h>
+#endif
+
+#ifdef NS
+#include <netns/ns.h>
+#include <netns/ns_if.h>
+#endif
+
+#if NBPFILTER > 0
+#include <net/bpf.h>
+#include <net/bpfdesc.h>
+#endif
+
+#include <machine/bus.h>
+
+#include <dev/ic/mb86950reg.h>
+#include <dev/ic/mb86950var.h>
+
+#ifndef __BUS_SPACE_HAS_STREAM_METHODS
+#define bus_space_write_stream_2       bus_space_write_2
+#define bus_space_write_multi_stream_2 bus_space_write_multi_2
+#define bus_space_read_multi_stream_2  bus_space_read_multi_2
+#endif /* __BUS_SPACE_HAS_STREAM_METHODS */
+
+/* Standard driver entry points.  These can be static. */
+int            mb86950_ioctl   __P((struct ifnet *, u_long, caddr_t));
+void   mb86950_init    __P((struct mb86950_softc *));
+void   mb86950_start   __P((struct ifnet *));
+void   mb86950_watchdog __P((struct ifnet *));
+void   mb86950_reset   __P((struct mb86950_softc *));
+
+/* Local functions. */
+void   mb86950_stop __P((struct mb86950_softc *));
+void   mb86950_tint __P((struct mb86950_softc *, u_int8_t));
+void   mb86950_rint __P((struct mb86950_softc *, u_int8_t));
+int            mb86950_get_fifo __P((struct mb86950_softc *, u_int));
+ushort mb86950_put_fifo __P((struct mb86950_softc *, struct mbuf *));
+void   mb86950_drain_fifo __P((struct mb86950_softc *));
+
+int            mb86950_mediachange __P((struct ifnet *));
+void   mb86950_mediastatus __P((struct ifnet *, struct ifmediareq *));
+
+
+#if ESTAR_DEBUG >= 1
+void   mb86950_dump __P((int, struct mb86950_softc *));
+#endif
+
+/********************************************************************/
+
+void
+mb86950_attach(sc, myea)
+       struct mb86950_softc *sc;
+       u_int8_t *myea;
+{
+
+#ifdef DIAGNOSTIC
+       if (myea == NULL) {
+               printf("%s: ethernet address shouldn't be NULL\n",
+                   sc->sc_dev.dv_xname);
+               panic("NULL ethernet address");
+       }
+#endif
+
+       /* Initialize 86950. */
+       mb86950_stop(sc);
+
+       memcpy(sc->sc_enaddr, myea, sizeof(sc->sc_enaddr));
+
+       sc->sc_stat |= ESTAR_STAT_ENABLED;
+}
+
+/*
+ * Stop everything on the interface.
+ *
+ * All buffered packets, both transmitting and receiving,
+ * if any, will be lost by stopping the interface.
+ */
+void
+mb86950_stop(sc)
+       struct mb86950_softc *sc;
+{
+       bus_space_tag_t bst = sc->sc_bst;
+       bus_space_handle_t bsh = sc->sc_bsh;
+
+       /* Stop interface hardware. */
+       bus_space_write_1(bst, bsh, DLCR_CONFIG, DISABLE_DLC);
+       delay(200);
+
+       /* Disable interrupts. */
+       bus_space_write_1(bst, bsh, DLCR_TX_INT_EN, 0);
+       bus_space_write_1(bst, bsh, DLCR_RX_INT_EN, 0);
+
+       /* Ack / Clear all interrupt status. */
+       bus_space_write_1(bst, bsh, DLCR_TX_STAT, 0xff);
+       bus_space_write_1(bst, bsh, DLCR_RX_STAT, 0xff);
+
+       /* Clear DMA Bit */
+    bus_space_write_2(bst, bsh, BMPR_DMA, 0);
+
+    /* accept no packets */
+       bus_space_write_1(bst, bsh, DLCR_TX_MODE, 0);
+       bus_space_write_1(bst, bsh, DLCR_RX_MODE, 0);
+
+    mb86950_drain_fifo(sc);
+
+}
+
+void
+mb86950_drain_fifo(sc)
+       struct mb86950_softc *sc;
+{
+       bus_space_tag_t bst = sc->sc_bst;
+       bus_space_handle_t bsh = sc->sc_bsh;
+
+/* XXX There ought to be a better way, eats CPU and bothers the chip ....... */
+       /* Read data until bus read error (i.e. buffer empty). */
+       while (!(bus_space_read_1(bst, bsh, DLCR_RX_STAT) & RX_BUS_RD_ERR))
+               bus_space_read_2(bst, bsh, BMPR_FIFO);
+/* XXX                                        */
+
+       /* Clear Bus Rd Error */
+       bus_space_write_1(bst, bsh, DLCR_RX_STAT, RX_BUS_RD_ERR);
+}
+
+/*
+ * Install interface into kernel networking data structures
+ */
+void
+mb86950_config(sc, media, nmedia, defmedia)
+       struct mb86950_softc *sc;



Home | Main Index | Thread Index | Old Index