Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/x68k/stand First cut at x68k network bootloader via...



details:   https://anonhg.NetBSD.org/src/rev/dbb2832349ef
branches:  trunk
changeset: 782005:dbb2832349ef
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Fri Oct 12 20:15:52 2012 +0000

description:
First cut at x68k network bootloader via NE2000 on Neptune-X and Nereid.
Written by isaki@ back in 2003 based on x86's NE2000 netboot, and
misc debug and improvements by tsutsui@ and Y.Sugahara.

Tested on XM6i (emulating Nereid Ethernet) and X68030 + Neptune-X by me,
also on X68030 + Nereid and X68000 PRO-II + Xellent30 + Nereid by isaki@.

Note:
- X680x0 IPLROM doesn't support bootstrap from Neptune-X or Nereid,
  so this network bootloader needs to be loaded from floppy or harddisk.
- Currently netboot support is not merged into the secondary Multi-boot
  (/usr/mdec/boot) due to size restriction.
- Primary loaders assumes that the secondary bootloader name is /boot,
  so /usr/mdec/netboot needs to be installed as /boot into the target
  bootstrap device.

diffstat:

 sys/arch/x68k/stand/Makefile           |    4 +-
 sys/arch/x68k/stand/boot/conf.c        |   10 +-
 sys/arch/x68k/stand/boot/dp8390.c      |  300 +++++++++++++++++++++++++++++++++
 sys/arch/x68k/stand/boot/dp8390.h      |   36 +++
 sys/arch/x68k/stand/boot/if_ne.c       |  156 +++++++++++++++++
 sys/arch/x68k/stand/boot/ne.c          |  272 +++++++++++++++++++++++++++++
 sys/arch/x68k/stand/boot/ne.h          |   38 ++++
 sys/arch/x68k/stand/libsa/Makefile     |    3 +-
 sys/arch/x68k/stand/libsa/Makefile.inc |    6 +-
 sys/arch/x68k/stand/libsa/clock.c      |  112 ++++++++++++
 sys/arch/x68k/stand/libsa/devopen.c    |   23 +-
 sys/arch/x68k/stand/libsa/libx68k.h    |    7 +-
 sys/arch/x68k/stand/netboot/Makefile   |   72 +++++++
 sys/arch/x68k/stand/netboot/boot.c     |  249 +++++++++++++++++++++++++++
 sys/arch/x68k/stand/netboot/conf.c     |   64 +++++++
 sys/arch/x68k/stand/netboot/version    |    7 +
 16 files changed, 1339 insertions(+), 20 deletions(-)

diffs (truncated from 1484 to 300 lines):

diff -r c34501a549f6 -r dbb2832349ef sys/arch/x68k/stand/Makefile
--- a/sys/arch/x68k/stand/Makefile      Fri Oct 12 19:45:47 2012 +0000
+++ b/sys/arch/x68k/stand/Makefile      Fri Oct 12 20:15:52 2012 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.12 2012/10/12 17:06:48 tsutsui Exp $
+#      $NetBSD: Makefile,v 1.13 2012/10/12 20:15:52 tsutsui Exp $
 
 # host tools
 SUBDIR= newdisk installboot
@@ -9,7 +9,7 @@
 # standalone bootloaders
 SUBDIR+= mboot
 SUBDIR+= boot_ufs boot_ustar xxboot
-SUBDIR+= boot
+SUBDIR+= boot netboot
 
 # Human68k utility
 SUBDIR+= aout2hux .WAIT loadbsd
diff -r c34501a549f6 -r dbb2832349ef sys/arch/x68k/stand/boot/conf.c
--- a/sys/arch/x68k/stand/boot/conf.c   Fri Oct 12 19:45:47 2012 +0000
+++ b/sys/arch/x68k/stand/boot/conf.c   Fri Oct 12 20:15:52 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: conf.c,v 1.9 2012/03/20 12:38:33 minoura Exp $ */
+/*     $NetBSD: conf.c,v 1.10 2012/10/12 20:15:52 tsutsui Exp $        */
 
 /*
  * Copyright (c) 2001 Minoura Makoto
@@ -45,10 +45,10 @@
 int ndevs = sizeof(devsw) / sizeof(devsw[0]);
 
 const struct devspec devspec[] = {
-       { "sd", 0, 7 },
-       { "cd", 1, 7 },
-       { "fd", 2, 3 },
-       { 0, 0, 0 }
+       { "sd", 0, 7, 0 },
+       { "cd", 1, 7, 0 },
+       { "fd", 2, 3, 0 },
+       { NULL, 0, 0, 0 }
 };
 
 struct fs_ops file_system[] = {
diff -r c34501a549f6 -r dbb2832349ef sys/arch/x68k/stand/boot/dp8390.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/x68k/stand/boot/dp8390.c Fri Oct 12 20:15:52 2012 +0000
@@ -0,0 +1,300 @@
+/*     $NetBSD: dp8390.c,v 1.1 2012/10/12 20:15:52 tsutsui Exp $       */
+/*     Id: dp8390.c,v 1.14 2011/10/05 13:16:20 isaki Exp       */
+
+/*
+ * This file is derived from sys/arch/i386/stand/lib/netif/dp8390.c
+ * NetBSD: dp8390.c,v 1.6 2008/12/14 18:46:33 christos Exp
+ */
+
+/*
+ * Polling driver for National Semiconductor DS8390/WD83C690 based
+ * ethernet adapters.
+ *
+ * Copyright (c) 1998 Matthias Drochner.  All rights reserved.
+ *
+ * Copyright (c) 1994, 1995 Charles M. Hannum.  All rights reserved.
+ *
+ * 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.
+ */
+
+
+#include <sys/types.h>
+
+#include <lib/libsa/stand.h>
+#include <libx68k.h>
+
+#include <dev/ic/dp8390reg.h>
+#include "dp8390.h"
+#include "ne.h"
+
+int dp8390_iobase, dp8390_membase, dp8390_memsize;
+#if defined(SUPPORT_WD80X3) && defined(SUPPORT_SMC_ULTRA)
+int dp8390_is790;
+#endif
+uint8_t dp8390_cr_proto;
+uint8_t dp8390_dcr_reg;
+
+#define WE_IOBASE dp8390_iobase
+
+static u_short rec_page_start;
+static u_short rec_page_stop;
+static u_short next_packet;
+
+extern u_char eth_myaddr[6];
+
+static void dp8390_read(int, char *, u_short);
+
+#define NIC_GET(reg) inb(WE_IOBASE + (reg) * 2)
+#define NIC_PUT(reg, val) outb(WE_IOBASE + (reg) * 2, val)
+
+static void
+dp8390_init(void)
+{
+       int i;
+
+       /*
+        * Initialize the NIC in the exact order outlined in the NS manual.
+        * This init procedure is "mandatory"...don't change what or when
+        * things happen.
+        */
+
+       /* Set interface for page 0, remote DMA complete, stopped. */
+       NIC_PUT(ED_P0_CR, dp8390_cr_proto | ED_CR_PAGE_0 | ED_CR_STP);
+
+       if ((dp8390_dcr_reg & ED_DCR_LS)) {
+               NIC_PUT(ED_P0_DCR, dp8390_dcr_reg);
+       } else {
+               /*
+                * Set FIFO threshold to 8, No auto-init Remote DMA, byte
+                * order=80x86, byte-wide DMA xfers,
+                */
+               NIC_PUT(ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS);
+       }
+
+       /* Clear remote byte count registers. */
+       NIC_PUT(ED_P0_RBCR0, 0);
+       NIC_PUT(ED_P0_RBCR1, 0);
+
+       /* Tell RCR to do nothing for now. */
+       NIC_PUT(ED_P0_RCR, ED_RCR_MON);
+
+       /* Place NIC in internal loopback mode. */
+       NIC_PUT(ED_P0_TCR, ED_TCR_LB0);
+
+       /* Set lower bits of byte addressable framing to 0. */
+       if (dp8390_is790)
+               NIC_PUT(0x09, 0);
+
+       /* Initialize receive buffer ring. */
+       NIC_PUT(ED_P0_BNRY, rec_page_start);
+       NIC_PUT(ED_P0_PSTART, rec_page_start);
+       NIC_PUT(ED_P0_PSTOP, rec_page_stop);
+
+       /*
+        * Clear all interrupts.  A '1' in each bit position clears the
+        * corresponding flag.
+        */
+       NIC_PUT(ED_P0_ISR, 0xff);
+
+       /*
+        * Disable all interrupts.
+        */
+       NIC_PUT(ED_P0_IMR, 0);
+
+       /* Program command register for page 1. */
+       NIC_PUT(ED_P0_CR, dp8390_cr_proto | ED_CR_PAGE_1 | ED_CR_STP);
+
+       /* Copy out our station address. */
+       for (i = 0; i < 6; i++)
+               NIC_PUT(ED_P1_PAR0 + i, eth_myaddr[i]);
+
+       /*
+        * Set current page pointer to one page after the boundary pointer, as
+        * recommended in the National manual.
+        */
+       next_packet = rec_page_start + 1;
+       NIC_PUT(ED_P1_CURR, next_packet);
+
+       /* Program command register for page 0. */
+       NIC_PUT(ED_P1_CR, dp8390_cr_proto | ED_CR_PAGE_0 | ED_CR_STP);
+
+       /* directed and broadcast */
+       NIC_PUT(ED_P0_RCR, ED_RCR_AB);
+
+       /* Take interface out of loopback. */
+       NIC_PUT(ED_P0_TCR, 0);
+
+       /* Fire up the interface. */
+       NIC_PUT(ED_P0_CR, dp8390_cr_proto | ED_CR_PAGE_0 | ED_CR_STA);
+}
+
+int
+dp8390_config(void)
+{
+
+       rec_page_start = TX_PAGE_START + ED_TXBUF_SIZE;
+       rec_page_stop = TX_PAGE_START + (dp8390_memsize >> ED_PAGE_SHIFT);
+
+       dp8390_init();
+
+       return 0;
+}
+
+void
+dp8390_stop(void)
+{
+       int n = 5000;
+
+       /* Stop everything on the interface, and select page 0 registers. */
+       NIC_PUT(ED_P0_CR, dp8390_cr_proto | ED_CR_PAGE_0 | ED_CR_STP);
+
+       /*
+        * Wait for interface to enter stopped state, but limit # of checks to
+        * 'n' (about 5ms).  It shouldn't even take 5us on modern DS8390's, but
+        * just in case it's an old one.
+        */
+       while (((NIC_GET(ED_P0_ISR) & ED_ISR_RST) == 0) && --n)
+               continue;
+}
+
+int
+EtherSend(char *pkt, int len)
+{
+       ne2000_writemem(pkt, dp8390_membase, len);
+
+       /* Set TX buffer start page. */
+       NIC_PUT(ED_P0_TPSR, TX_PAGE_START);
+
+       /* Set TX length. */
+       NIC_PUT(ED_P0_TBCR0, len < 60 ? 60 : len);
+       NIC_PUT(ED_P0_TBCR1, len >> 8);
+
+       /* Set page 0, remote DMA complete, transmit packet, and *start*. */
+       NIC_PUT(ED_P0_CR, dp8390_cr_proto | ED_CR_PAGE_0 | ED_CR_TXP | ED_CR_STA);
+
+       return len;
+}
+
+static void
+dp8390_read(int buf, char *dest, u_short len)
+{
+       u_short tmp_amount;
+
+       /* Does copy wrap to lower addr in ring buffer? */
+       if (buf + len > dp8390_membase + dp8390_memsize) {
+               tmp_amount = dp8390_membase + dp8390_memsize - buf;
+
+               /* Copy amount up to end of NIC memory. */
+               ne2000_readmem(buf, dest, tmp_amount);
+
+               len -= tmp_amount;
+               buf = RX_BUFBASE + (rec_page_start << ED_PAGE_SHIFT);
+               dest += tmp_amount;
+       }
+       ne2000_readmem(buf, dest, len);
+}
+
+int
+EtherReceive(char *pkt, int maxlen)
+{
+       struct dp8390_ring packet_hdr;
+       int packet_ptr;
+       u_short len;
+       u_char boundary, current;
+#ifdef DP8390_OLDCHIPS
+       u_char nlen;
+#endif
+
+       if (!(NIC_GET(ED_P0_RSR) & ED_RSR_PRX))
+               return 0; /* XXX error handling */
+
+       /* Set NIC to page 1 registers to get 'current' pointer. */
+       NIC_PUT(ED_P0_CR, dp8390_cr_proto | ED_CR_PAGE_1 | ED_CR_STA);
+
+       /*
+        * 'sc->next_packet' is the logical beginning of the ring-buffer - i.e.
+        * it points to where new data has been buffered.  The 'CURR' (current)
+        * register points to the logical end of the ring-buffer - i.e. it
+        * points to where additional new data will be added.  We loop here
+        * until the logical beginning equals the logical end (or in other
+        * words, until the ring-buffer is empty).
+        */
+       current = NIC_GET(ED_P1_CURR);
+
+       /* Set NIC to page 0 registers to update boundary register. */
+       NIC_PUT(ED_P1_CR, dp8390_cr_proto | ED_CR_PAGE_0 | ED_CR_STA);
+
+       if (next_packet == current)
+               return 0;
+
+       /* Get pointer to this buffer's header structure. */
+       packet_ptr = RX_BUFBASE + (next_packet << ED_PAGE_SHIFT);
+
+       /*
+        * The byte count includes a 4 byte header that was added by
+        * the NIC.
+        */
+       ne2000_readmem(packet_ptr, (void *)&packet_hdr, 4);
+
+       len = le16toh(packet_hdr.count);
+
+#ifdef DP8390_OLDCHIPS
+       /*
+        * Try do deal with old, buggy chips that sometimes duplicate
+        * the low byte of the length into the high byte.  We do this
+        * by simply ignoring the high byte of the length and always
+        * recalculating it.
+        *
+        * NOTE: sc->next_packet is pointing at the current packet.
+        */
+       if (packet_hdr.next_packet >= next_packet)



Home | Main Index | Thread Index | Old Index