Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sandpoint/stand/netboot Add support for Qnap TS101 ...



details:   https://anonhg.NetBSD.org/src/rev/91c904d9a01e
branches:  trunk
changeset: 754505:91c904d9a01e
user:      phx <phx%NetBSD.org@localhost>
date:      Sun May 02 13:31:14 2010 +0000

description:
Add support for Qnap TS101 (untested) and Synology-DS boards.
Detect Synology SATAlink device (although still unused).
New skg driver for Marvell SKnet Yukon-lite based GbE, used on most DS boards.
As there is no documentation available, it was based on if_sk.c, with lots
of testing. Known problem: The MAC address on my DS-101g+ is always read
as 00:11:22:33:44:54, but sk(4) unfortunately has the same problem.
New allocaligned() function to replace non-working ALLOC() macros.

diffstat:

 sys/arch/sandpoint/stand/netboot/Makefile   |    4 +-
 sys/arch/sandpoint/stand/netboot/brdsetup.c |   32 +-
 sys/arch/sandpoint/stand/netboot/globals.h  |    9 +-
 sys/arch/sandpoint/stand/netboot/main.c     |   20 +-
 sys/arch/sandpoint/stand/netboot/nif.c      |    7 +-
 sys/arch/sandpoint/stand/netboot/skg.c      |  504 ++++++++++++++++++++++++++++
 6 files changed, 556 insertions(+), 20 deletions(-)

diffs (truncated from 694 to 300 lines):

diff -r 6caa8ae34b5d -r 91c904d9a01e sys/arch/sandpoint/stand/netboot/Makefile
--- a/sys/arch/sandpoint/stand/netboot/Makefile Sun May 02 12:43:05 2010 +0000
+++ b/sys/arch/sandpoint/stand/netboot/Makefile Sun May 02 13:31:14 2010 +0000
@@ -1,10 +1,10 @@
-#      $NetBSD: Makefile,v 1.15 2009/07/20 11:43:08 nisimura Exp $
+#      $NetBSD: Makefile,v 1.16 2010/05/02 13:31:14 phx Exp $
 
 S=             ${.CURDIR}/../../../..
 
 PROG=          netboot
 SRCS=          entry.S main.c brdsetup.c pci.c devopen.c dev_net.c nif.c \
-               fxp.c tlp.c rge.c printf.c
+               fxp.c tlp.c rge.c skg.c printf.c
 CLEANFILES+=   vers.c vers.o ${PROG} ${PROG}.bin
 CFLAGS+=       -Wall -Wno-main -ffreestanding -msoft-float -mmultiple
 CFLAGS+=       -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith
diff -r 6caa8ae34b5d -r 91c904d9a01e sys/arch/sandpoint/stand/netboot/brdsetup.c
--- a/sys/arch/sandpoint/stand/netboot/brdsetup.c       Sun May 02 12:43:05 2010 +0000
+++ b/sys/arch/sandpoint/stand/netboot/brdsetup.c       Sun May 02 13:31:14 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: brdsetup.c,v 1.8 2009/07/03 10:31:19 nisimura Exp $ */
+/* $NetBSD: brdsetup.c,v 1.9 2010/05/02 13:31:14 phx Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -104,23 +104,29 @@
                UART_WRITE(IER, 0x00);          /* make sure INT disabled */
                printf("AAAAFFFFJJJJ>>>>VVVV>>>>ZZZZVVVVKKKK");
        }
+       else if (PCI_VENDOR(pcicfgread(pcimaketag(0, 15, 0), PCI_ID_REG)) ==
+           0x8086) {                           /* PCI_VENDOR_INTEL */
+               brdtype = BRD_QNAPTS101;
+               consname = "eumb";
+               consport = 0x4600;
+               consspeed = 57600;              /* XXX unverified */
+               ticks_per_sec = 133000000 / 4;  /* TS-101 is 266MHz */
+       }
+       else if (PCI_VENDOR(pcicfgread(pcimaketag(0, 15, 0), PCI_ID_REG)) ==
+           0x11ab) {                           /* PCI_VENDOR_MARVELL */
+               brdtype = BRD_SYNOLOGY;
+               consname = "eumb";
+               consport = 0x4500;
+               consspeed = 115200;
+               /* XXX assume 133MHz bus clock, valid for 266MHz models */
+               ticks_per_sec = 133000000 / 4;
+       }
 
        /* now prepare serial console */
        if (strcmp(consname, "eumb") != 0)
                uartbase = 0xfe000000 + consport; /* 0x3f8, 0x2f8 */
-       else {
+       else
                uartbase = 0xfc000000 + consport; /* 0x4500, 0x4600 */
-               div = (ticks_per_sec * 4) / consspeed / 16;
-               UART_WRITE(DCR, 0x01);  /* 2 independent UART */
-               UART_WRITE(LCR, 0x80);  /* turn on DLAB bit */
-               UART_WRITE(FCR, 0x00);
-               UART_WRITE(DMB, div >> 8);
-               UART_WRITE(DLB, div & 0xff); /* 0x36 when 115200bps@100MHz */
-               UART_WRITE(LCR, 0x03);  /* 8 N 1 */
-               UART_WRITE(MCR, 0x03);  /* RTS DTR */
-               UART_WRITE(FCR, 0x07);  /* FIFO_EN | RXSR | TXSR */
-               UART_WRITE(IER, 0x00);  /* make sure INT disabled */
-       }
 }
 
 void
diff -r 6caa8ae34b5d -r 91c904d9a01e sys/arch/sandpoint/stand/netboot/globals.h
--- a/sys/arch/sandpoint/stand/netboot/globals.h        Sun May 02 12:43:05 2010 +0000
+++ b/sys/arch/sandpoint/stand/netboot/globals.h        Sun May 02 13:31:14 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: globals.h,v 1.11 2009/07/20 11:43:09 nisimura Exp $ */
+/* $NetBSD: globals.h,v 1.12 2010/05/02 13:31:14 phx Exp $ */
 
 /* clock feed */
 #ifndef TICKS_PER_SEC
@@ -12,6 +12,8 @@
 #define BRD_SANDPOINTX3                3
 #define BRD_ENCOREPP1          10
 #define BRD_KUROBOX            100
+#define BRD_QNAPTS101          101
+#define BRD_SYNOLOGY           102
 #define BRD_UNKNOWN            -1
 
 extern char *consname;
@@ -62,6 +64,7 @@
 #define  PCI_CLASS_IDE                 0x0101
 #define  PCI_CLASS_RAID                        0x0104
 #define  PCI_CLASS_SATA                        0x0106
+#define  PCI_CLASS_MISCSTORAGE         0x0180
 #define PCI_BHLC_REG                   0x0c
 #define  PCI_HDRTYPE_TYPE(r)           (((r) >> 16) & 0x7f)
 #define  PCI_HDRTYPE_MULTIFN(r)                ((r) & (0x80 << 16))
@@ -71,6 +74,9 @@
 void _wbinv(uint32_t, uint32_t);
 void _inv(uint32_t, uint32_t);
 
+/* heap */
+void *allocaligned(size_t, size_t);
+
 /* NIF */
 int net_open(struct open_file *, ...);
 int net_close(struct open_file *);
@@ -89,3 +95,4 @@
 NIF_DECL(fxp);
 NIF_DECL(tlp);
 NIF_DECL(rge);
+NIF_DECL(skg);
diff -r 6caa8ae34b5d -r 91c904d9a01e sys/arch/sandpoint/stand/netboot/main.c
--- a/sys/arch/sandpoint/stand/netboot/main.c   Sun May 02 12:43:05 2010 +0000
+++ b/sys/arch/sandpoint/stand/netboot/main.c   Sun May 02 13:31:14 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.23 2009/07/03 10:31:19 nisimura Exp $ */
+/* $NetBSD: main.c,v 1.24 2010/05/02 13:31:14 phx Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -84,11 +84,18 @@
                printf("Sandpoint X3"); break;
        case BRD_ENCOREPP1:
                printf("Encore PP1"); break;
+       case BRD_QNAPTS101:
+               printf("QNAP TS-101"); break;
+       case BRD_SYNOLOGY:
+               printf("Synology DS"); break;
        }
        printf(", %dMB SDRAM\n", memsize >> 20);
 
        n = pcilookup(PCI_CLASS_IDE, lata, sizeof(lata)/sizeof(lata[0]));
        if (n == 0)
+               n = pcilookup(PCI_CLASS_MISCSTORAGE, lata,
+                   sizeof(lata)/sizeof(lata[0]));
+       if (n == 0)
                printf("no IDE found\n");
        else {
                tag = lata[0][1];
@@ -237,3 +244,14 @@
        p->siz = 0;
 }
 #endif
+
+void *
+allocaligned(size_t size, size_t align)
+{
+       uint32_t p;
+
+       if (align-- < 2)
+               return alloc(size);
+       p = (uint32_t)alloc(size + align);
+       return (void *)((p + align) & ~align);
+}
diff -r 6caa8ae34b5d -r 91c904d9a01e sys/arch/sandpoint/stand/netboot/nif.c
--- a/sys/arch/sandpoint/stand/netboot/nif.c    Sun May 02 12:43:05 2010 +0000
+++ b/sys/arch/sandpoint/stand/netboot/nif.c    Sun May 02 13:31:14 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nif.c,v 1.11 2009/07/20 11:43:09 nisimura Exp $ */
+/* $NetBSD: nif.c,v 1.12 2010/05/02 13:31:14 phx Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -55,6 +55,7 @@
        { "fxp", fxp_match, fxp_init, fxp_send, fxp_recv },
        { "tlp", tlp_match, tlp_init, tlp_send, tlp_recv },
        { "re",  rge_match, rge_init, rge_send, rge_recv },
+       { "sk",  skg_match, skg_init, skg_send, skg_recv },
 };
 static int nnifdv = sizeof(vnifdv)/sizeof(vnifdv[0]);
 
@@ -107,7 +108,7 @@
 {
        struct nifdv *dv = desc->io_netif;
 
-       return (*dv->send)(dv->priv, pkt, len);
+       return dv ? (*dv->send)(dv->priv, pkt, len) : -1;
 }
 
 /*
@@ -120,7 +121,7 @@
        struct nifdv *dv = desc->io_netif;
        int len;
 
-       len = (*dv->recv)(dv->priv, pkt, maxlen, timo);
+       len = dv ? (*dv->recv)(dv->priv, pkt, maxlen, timo) : -1;
        if (len == -1)
                printf("timeout\n");
        return len;
diff -r 6caa8ae34b5d -r 91c904d9a01e sys/arch/sandpoint/stand/netboot/skg.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sandpoint/stand/netboot/skg.c    Sun May 02 13:31:14 2010 +0000
@@ -0,0 +1,504 @@
+/* $NetBSD: skg.c,v 1.1 2010/05/02 13:31:14 phx Exp $ */
+
+/*-
+ * Copyright (c) 2010 Frank Wille.
+ * All rights reserved.
+ *
+ * Written by Frank Wille for The NetBSD Project.
+ *
+ * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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.
+ */
+
+#include <sys/param.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+
+#include <lib/libsa/stand.h>
+#include <lib/libsa/net.h>
+
+#include "globals.h"
+
+/*
+ * - reverse endian access every CSR.
+ * - no vtophys() translation, vaddr_t == paddr_t.
+ * - PIPT writeback cache aware.
+ */
+#define CSR_WRITE_1(l, r, v)   *(volatile uint8_t *)((l)->csr+(r)) = (v)
+#define CSR_READ_1(l, r)       *(volatile uint8_t *)((l)->csr+(r))
+#define CSR_WRITE_2(l, r, v)   out16rb((l)->csr+(r), (v))
+#define CSR_READ_2(l, r)       in16rb((l)->csr+(r))
+#define CSR_WRITE_4(l, r, v)   out32rb((l)->csr+(r), (v))
+#define CSR_READ_4(l, r)       in32rb((l)->csr+(r))
+#define VTOPHYS(va)            (uint32_t)(va)
+#define DEVTOV(pa)             (uint32_t)(pa)
+#define wbinv(adr, siz)                _wbinv(VTOPHYS(adr), (uint32_t)(siz))
+#define inv(adr, siz)          _inv(VTOPHYS(adr), (uint32_t)(siz))
+#define DELAY(n)               delay(n)
+#define ALLOC(T,A)             (T *)allocaligned(sizeof(T),(A))
+
+struct desc {
+       uint32_t xd0, xd1, xd2, xd3, xd4;
+       uint32_t rsrvd[5];
+};
+#define CTL_LS                 0x20000000
+#define CTL_FS                 0x40000000
+#define CTL_OWN                        0x80000000
+#define CTL_DEFOPC             0x00550000
+#define FRAMEMASK              0x0000ffff
+#define RXSTAT_RXOK            0x00000100
+
+#define SK_CSR                 0x0004
+#define  CSR_SW_RESET          0x0001
+#define  CSR_SW_UNRESET                0x0002
+#define  CSR_MASTER_RESET      0x0004
+#define  CSR_MASTER_UNRESET    0x0008
+#define SK_IMR                 0x000c
+#define SK_BMU_RX_CSR0         0x0060
+#define SK_BMU_TXS_CSR0                0x0068
+#define SK_MAC0                        0x0100
+#define SK_MAC1                        0x0108
+#define SK_GPIO                        0x015c
+#define SK_RAMCTL              0x01a0
+#define SK_TXAR1_COUNTERCTL    0x0210
+#define  TXARCTL_ON            0x02
+#define  TXARCTL_FSYNC_ON       0x80
+#define SK_RXQ1_CURADDR_LO     0x0420
+#define SK_RXQ1_CURADDR_HI     0x0424
+#define SK_RXQ1_BMU_CSR                0x0434
+#define  RXBMU_CLR_IRQ_EOF             0x00000002
+#define  RXBMU_RX_START                        0x00000010
+#define  RXBMU_RX_STOP                 0x00000020
+#define  RXBMU_POLL_ON                 0x00000080
+#define  RXBMU_TRANSFER_SM_UNRESET     0x00000200
+#define  RXBMU_DESCWR_SM_UNRESET       0x00000800
+#define  RXBMU_DESCRD_SM_UNRESET       0x00002000
+#define  RXBMU_SUPERVISOR_SM_UNRESET   0x00008000
+#define  RXBMU_PFI_SM_UNRESET          0x00020000
+#define  RXBMU_FIFO_UNRESET            0x00080000
+#define  RXBMU_DESC_UNRESET            0x00200000
+#define SK_TXQS1_CURADDR_LO    0x0620
+#define SK_TXQS1_CURADDR_HI    0x0624
+#define SK_TXQS1_BMU_CSR       0x0634
+#define  TXBMU_CLR_IRQ_EOF             0x00000002
+#define  TXBMU_TX_START                        0x00000010
+#define  TXBMU_TX_STOP                 0x00000020
+#define  TXBMU_POLL_ON                 0x00000080
+#define  TXBMU_TRANSFER_SM_UNRESET     0x00000200
+#define  TXBMU_DESCWR_SM_UNRESET       0x00000800
+#define  TXBMU_DESCRD_SM_UNRESET       0x00002000
+#define  TXBMU_SUPERVISOR_SM_UNRESET   0x00008000
+#define  TXBMU_PFI_SM_UNRESET          0x00020000



Home | Main Index | Thread Index | Old Index