major PCI rework to make possible NIC autoconf. now bootloader

can have multiple network interface device drivers and choose one
by PCI_ID_REG matching.
This commit is contained in:
nisimura 2007-10-30 00:30:13 +00:00
parent c9ebd528c1
commit d1fea0c157
15 changed files with 300 additions and 201 deletions

View File

@ -1,17 +1,17 @@
# $NetBSD: Makefile,v 1.2 2007/10/17 19:57:00 garbled Exp $
# $NetBSD: Makefile,v 1.3 2007/10/30 00:30:13 nisimura Exp $
S= ${.CURDIR}/../../../..
PROG= netboot
SRCS= entry.S main.c pci.c devopen.c dev_net.c nif_fxp.c fxp.c \
printf.c vers.c
SRCS= entry.S main.c pci.c devopen.c dev_net.c nif.c \
fxp.c tlp.c pcn.c sip.c nvt.c rge.c vge.c printf.c vers.c
CLEANFILES+= vers.c ${PROG} ${PROG}.bin
CFLAGS+= -Wall -Wno-main -ffreestanding -msoft-float -mmultiple
CPPFLAGS+= -D_STANDALONE -DSUPPORT_DHCP
CPPFLAGS+= -DCONSNAME=\"com\" -DCONSPORT=0x3f8 -DCONSSPEED=115200
#CPPFLAGS+= -DCONSNAME=\"eumb\" -DCONSPORT=0x4600 -DCONSSPEED=115200
#CPPFLAGS+= -DDEBUG
CPPFLAGS+= -nostdinc -I. -I${S}
CPPFLAGS+= -Wall -nostdinc -I. -I${S}
DBG= -Os
# XXX SHOULD NOT NEED TO DEFINE THESE!

View File

@ -1,4 +1,4 @@
/* $NetBSD: dev_net.c,v 1.3 2007/10/26 13:32:57 nisimura Exp $ */
/* $NetBSD: dev_net.c,v 1.4 2007/10/30 00:30:13 nisimura Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -37,8 +37,7 @@
*/
#include <sys/param.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>

View File

@ -1,4 +1,4 @@
/* $NetBSD: devopen.c,v 1.3 2007/10/26 13:32:57 nisimura Exp $ */
/* $NetBSD: devopen.c,v 1.4 2007/10/30 00:30:13 nisimura Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -50,7 +50,7 @@ int net_close(struct open_file *);
int net_strategy(void *, int, daddr_t, size_t, void *, size_t *);
struct devsw devsw[] = {
{ "fxp", net_strategy, net_open, net_close, noioctl },
{ "net", net_strategy, net_open, net_close, noioctl },
};
int ndevs = sizeof(devsw) / sizeof(devsw[0]);
@ -88,5 +88,6 @@ noioctl(f, cmd, data)
u_long cmd;
void *data;
{
return EINVAL;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: fxp.c,v 1.2 2007/10/17 19:57:01 garbled Exp $ */
/* $NetBSD: fxp.c,v 1.3 2007/10/30 00:30:13 nisimura Exp $ */
/*
* most of the following code was imported from dev/ic/i82557.c; the
@ -73,7 +73,6 @@
*/
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
@ -137,7 +136,7 @@ struct local {
unsigned eeprom_addr;
};
void *fxp_init(void *);
void *fxp_init(unsigned, void *);
int fxp_send(void *, char *, unsigned);
int fxp_recv(void *, char *, unsigned, unsigned);
static void autosize_eeprom(struct local *);
@ -181,20 +180,19 @@ static struct fxp_cb_config store_cbc;
static struct fxp_cb_ias store_cbi;
void *
fxp_init(void *cookie)
fxp_init(unsigned tag, void *data)
{
struct local *sc;
uint8_t *en = cookie;
uint8_t *en = data;
struct fxp_cb_config *cbp = &store_cbc;
struct fxp_cb_ias *cb_ias = &store_cbi;
struct rxdesc *rfa;
unsigned tag, v, i;
unsigned v, i;
if (pcifinddev(0x8086, 0x1209, &tag) != 0
&& pcifinddev(0x8086, 0x1229, &tag) != 0) {
printf("fxp NIC not found\n");
v = pcicfgread(tag, PCI_ID_REG);
if (PCI_VENDOR(v) != 0x8086 ||
(PCI_PRODUCT(v) != 0x1209 && PCI_PRODUCT(v) != 0x1229))
return NULL;
}
sc = alloc(sizeof(struct local));
memset(sc, 0, sizeof(struct local));

View File

@ -1,4 +1,4 @@
/* $NetBSD: globals.h,v 1.2 2007/10/17 19:57:01 garbled Exp $ */
/* $NetBSD: globals.h,v 1.3 2007/10/30 00:30:13 nisimura Exp $ */
/* clock feed */
#define TICKS_PER_SEC (100000000 / 4) /* 100MHz front bus */
@ -25,8 +25,22 @@ void pcisetup(void);
unsigned pcimaketag(int, int, int);
void pcidecomposetag(unsigned, int *, int *, int *);
int pcifinddev(unsigned, unsigned, unsigned *);
unsigned pcicfgread(unsigned, unsigned);
void pcicfgwrite(unsigned, unsigned, unsigned);
int pcilookup(unsigned, unsigned [][2], int);
unsigned pcicfgread(unsigned, int);
void pcicfgwrite(unsigned, int, unsigned);
#define PCI_ID_REG 0x00
#define PCI_COMMAND_STATUS_REG 0x04
#define PCI_VENDOR(id) ((id) & 0xffff)
#define PCI_PRODUCT(id) (((id) >> 16) & 0xffff)
#define PCI_VENDOR_INVALID 0xffff
#define PCI_CLASS_REG 0x08
#define PCI_CLASS_PPB 0x0604
#define PCI_CLASS_ETH 0x0200
#define PCI_CLASS_IDE 0x0101
#define PCI_BHLC_REG 0x0c
#define PCI_HDRTYPE_TYPE(r) (((r) >> 16) & 0x7f)
#define PCI_HDRTYPE_MULTIFN(r) ((r) & (0x80 << 16))
/* cache ops */
void _wb(uint32_t, uint32_t);
@ -34,4 +48,4 @@ void _wbinv(uint32_t, uint32_t);
void _inv(uint32_t, uint32_t);
/* NIF */
void netif_init(void);
int netif_init(unsigned);

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.3 2007/10/26 13:32:57 nisimura Exp $ */
/* $NetBSD: main.c,v 1.4 2007/10/30 00:30:13 nisimura Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -82,7 +82,7 @@ int brdtype;
void
main()
{
int howto;
int n, b, d, f, howto;
unsigned memsize, tag;
unsigned long marks[MARK_MAX];
struct btinfo_memory bi_mem;
@ -90,6 +90,7 @@ main()
struct btinfo_clock bi_clk;
struct btinfo_bootpath bi_path;
struct btinfo_rootdevice bi_rdev;
unsigned lnif[1][2];
/* determine SDRAM size */
memsize = mpc107memsize();
@ -103,19 +104,23 @@ main()
case BRD_ENCOREPP1:
printf("Encore PP1"); break;
}
printf(", %dMB SDRAM", memsize >> 20);
if (pcifinddev(0x8086, 0x1209, &tag) == 0
|| pcifinddev(0x8086, 0x1229, &tag) == 0) {
int b, d, f;
pcidecomposetag(tag, &b, &d, &f);
printf(", Intel i82559 NIC %02d:%02d:%02d", b, d, f);
printf(", %dMB SDRAM\n", memsize >> 20);
n = pcilookup(PCI_CLASS_ETH, lnif, sizeof(lnif)/sizeof(lnif[0]));
if (n == 0) {
tag = ~0;
printf("no NIC found\n");
}
else {
tag = lnif[0][1];
pcidecomposetag(tag, &b, &d, &f);
printf("%08x NIC %02d:%02d:%02d", lnif[0][0], b, d, f);
}
printf("\n");
pcisetup();
pcifixup();
netif_init();
if (netif_init(tag) == 0)
printf("no device driver is found\n");
printf("Try NFS load /netbsd\n");
marks[MARK_START] = 0;
@ -361,8 +366,6 @@ _inv(adr, siz)
asm volatile ("sync");
}
#include <dev/ic/mpc106reg.h>
unsigned
mpc107memsize()
{
@ -373,6 +376,11 @@ mpc107memsize()
if (brdtype == BRD_ENCOREPP1) {
/* the brd's PPCBOOT looks to have erroneous values */
unsigned tbl[] = {
#define MPC106_MEMSTARTADDR1 0x80
#define MPC106_EXTMEMSTARTADDR1 0x88
#define MPC106_MEMENDADDR1 0x90
#define MPC106_EXTMEMENDADDR1 0x98
#define MPC106_MEMEN 0xa0
#define BK0_S 0x00000000
#define BK0_E (128 << 20) - 1
#define BK1_S 0x3ff00000

View File

@ -1,4 +1,4 @@
/* $NetBSD: nif_fxp.c,v 1.3 2007/10/26 13:32:58 nisimura Exp $ */
/* $NetBSD: nif.c,v 1.1 2007/10/30 00:30:13 nisimura Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -37,7 +37,6 @@
*/
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
@ -45,45 +44,80 @@
#include <lib/libsa/stand.h>
#include <lib/libsa/net.h>
struct iodesc sockets[2]; /* SOPEN_MAX */
struct nifdv {
unsigned (*init)(unsigned, void *);
int (*send)(void *, char *, unsigned);
int (*recv)(void *, char *, unsigned, unsigned);
void *priv;
int unit;
};
struct iodesc *socktodesc(int);
void netif_init(void);
int netif_init(unsigned);
int netif_open(void *);
int netif_close(int);
ssize_t netif_put(struct iodesc *, void *, size_t);
ssize_t netif_get(struct iodesc *, void *, size_t, time_t);
struct iodesc *socktodesc(int);
void *fxp_init(void *);
int fxp_send(void *, char *, unsigned);
int fxp_recv(void *, char *, unsigned, unsigned);
static struct iodesc netdesc;
struct iodesc *
socktodesc(sock)
int sock;
{
if (sock < 0 || sock >= 2)
return NULL;
return &sockets[sock];
}
#define NIF_DECL(xxx) \
unsigned xxx ## _init(unsigned, void *); \
int xxx ## _send(void *, char *, unsigned); \
int xxx ## _recv(void *, char *, unsigned, unsigned);
void
netif_init()
NIF_DECL(fxp);
NIF_DECL(tlp);
NIF_DECL(nvt);
NIF_DECL(sip);
NIF_DECL(vge);
NIF_DECL(rge);
static struct nifdv vnifdv[] = {
{ fxp_init, fxp_send, fxp_recv },
{ tlp_init, tlp_send, tlp_recv },
{ nvt_init, nvt_send, nvt_recv },
{ sip_init, sip_send, sip_recv },
{ vge_init, vge_send, vge_recv },
{ rge_init, rge_send, rge_recv }
};
static int nnifdv = sizeof(vnifdv)/sizeof(vnifdv[0]);
int nmatchednif = 0;
int
netif_init(tag)
unsigned tag;
{
struct iodesc *s;
struct nifdv *dv;
int n;
void *l;
uint8_t enaddr[6];
extern uint8_t en[];
s = &sockets[0];
s->io_netif = fxp_init(s->myea); /* determine MAC address */
memcpy(en, s->myea, sizeof(s->myea));
for (n = 0; n < nnifdv; n++) {
l = (void *)(*vnifdv[n].init)(tag, enaddr);
if (l != NULL)
goto found;
}
return 0;
found:
memcpy(en, enaddr, sizeof(enaddr));
dv = alloc(sizeof(struct nifdv));
*dv = vnifdv[n];
dv->priv = l;
dv->unit = nmatchednif++;
s = &netdesc;
s->io_netif = dv;
memcpy(s->myea, enaddr, sizeof(enaddr));
return 1;
}
int
netif_open(cookie)
void *cookie;
{
/* single action */
return 0;
}
@ -91,7 +125,6 @@ int
netif_close(sock)
int sock;
{
/* nothing to do for the HW */
return 0;
}
@ -106,16 +139,9 @@ netif_put(desc, pkt, len)
void *pkt;
size_t len;
{
ssize_t rv;
size_t sendlen;
struct nifdv *dv = desc->io_netif;
sendlen = len;
if (sendlen < 60)
sendlen = 60;
rv = fxp_send(desc->io_netif, pkt, sendlen);
return rv;
return (*dv->send)(dv->priv, pkt, len);
}
/*
@ -129,15 +155,19 @@ netif_get(desc, pkt, maxlen, timo)
size_t maxlen;
time_t timo;
{
struct nifdv *dv = desc->io_netif;
int len;
len = fxp_recv(desc->io_netif, pkt, maxlen, timo);
if (len == -1) {
len = (*dv->recv)(dv->priv, pkt, maxlen, timo);
if (len == -1)
printf("timeout\n");
/* XXX errno = ... */
}
if (len < 12)
return -1;
return len;
}
struct iodesc *
socktodesc(num)
int num;
{
return (num == 0) ? &netdesc : NULL;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: nvt.c,v 1.5 2007/10/28 03:15:04 nisimura Exp $ */
/* $NetBSD: nvt.c,v 1.6 2007/10/30 00:30:14 nisimura Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -37,7 +37,6 @@
*/
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
@ -64,7 +63,7 @@
#define DELAY(n) delay(n)
#define ALLOC(T,A) (T *)((unsigned)alloc(sizeof(T) + (A)) &~ ((A) - 1))
void *nvt_init(void *);
void *nvt_init(unsigned, void *);
int nvt_send(void *, char *, unsigned);
int nvt_recv(void *, char *, unsigned, unsigned);
@ -171,18 +170,16 @@ static void nvt_mii_write(struct local *, int, int, int);
static void mii_initphy(struct local *);
void *
nvt_init(void *cookie)
nvt_init(unsigned tag, void *data)
{
unsigned tag, val;
unsigned val;
struct local *l;
struct desc *TxD, *RxD;
uint8_t *en;
if (pcifinddev(0x1106, 0x3106, &tag) != 0
|| pcifinddev(0x1106, 0x3053, &tag) != 0) {
printf("nvt NIC not found\n");
val = pcicfgread(tag, PCI_ID_REG);
if (PCI_VENDOR(val) != 0x1106 && PCI_PRODUCT(val) != 0x3053)
return NULL;
}
l = ALLOC(struct local, sizeof(struct desc));
memset(l, 0, sizeof(struct local));
@ -197,7 +194,7 @@ nvt_init(void *cookie)
l->phy = CSR_READ_1(l, VR_MIICFG) & 0x1f;
mii_initphy(l);
en = cookie;
en = data;
en[0] = CSR_READ_1(l, VR_PAR0);
en[1] = CSR_READ_1(l, VR_PAR1);
en[2] = CSR_READ_1(l, VR_PAR2);

View File

@ -1,4 +1,4 @@
/* $NetBSD: pci.c,v 1.3 2007/10/26 13:32:58 nisimura Exp $ */
/* $NetBSD: pci.c,v 1.4 2007/10/30 00:30:14 nisimura Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -37,13 +37,9 @@
*/
#include <sys/param.h>
#include <lib/libsa/stand.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcidevs.h>
#include "globals.h"
/*
* "Map B" layout
*
@ -51,20 +47,23 @@
* (0xfec0'0000) and CONFIG_DATA (0xfee0'0000).
*/
#define PCI_MEMBASE 0x80000000
#define PCI_MEMLIMIT 0xfbffffff /* EUMB is next to this */
#define PCI_MEMLIMIT 0xfbffffff /* EUMB is next to this */
#define PCI_IOBASE 0x00001000 /* reserves room for via 686B */
#define PCI_IOLIMIT 0x000fffff
#define CONFIG_ADDR 0xfec00000
#define CONFIG_DATA 0xfee00000
#define PCI_IOLIMIT 0x000fffff
#define CONFIG_ADDR 0xfec00000
#define CONFIG_DATA 0xfee00000
#define MAXNDEVS 32
static unsigned cfgread(unsigned, unsigned, unsigned, unsigned);
static void cfgwrite(unsigned, unsigned, unsigned, unsigned, unsigned);
static int _pcifinddev(unsigned, unsigned, unsigned, unsigned *);
static void busprobe(unsigned);
static void devicemap(unsigned, unsigned, unsigned);
static void deviceinit(unsigned, unsigned, unsigned);
#include "globals.h"
static unsigned cfgread(int, int, int, int);
static void cfgwrite(int, int, int, int, unsigned);
static void busprobe(int);
static void deviceinit(int, int, int);
static void devicemap(int, int, int);
static int _pcifinddev(unsigned, unsigned, int, unsigned *);
static int _pcilookup(unsigned, unsigned [][2], int, int, int);
unsigned memstart, memlimit;
unsigned iostart, iolimit;
@ -87,6 +86,7 @@ unsigned
pcimaketag(b, d, f)
int b, d, f;
{
return (1U << 31) | (b << 16) | (d << 11) | (f << 8);
}
@ -95,6 +95,7 @@ pcidecomposetag(tag, b, d, f)
unsigned tag;
int *b, *d, *f;
{
if (b != NULL)
*b = (tag >> 16) & 0xff;
if (d != NULL)
@ -109,37 +110,52 @@ pcifinddev(vend, prod, tag)
unsigned vend, prod;
unsigned *tag;
{
return _pcifinddev(vend, prod, 0, tag);
}
int
pcilookup(type, list, max)
unsigned type;
unsigned list[][2];
int max;
{
return _pcilookup(type, list, 0, 0, max);
}
unsigned
pcicfgread(tag, off)
unsigned tag, off;
unsigned tag;
int off;
{
unsigned cfg;
cfg = tag | (off &~ 3);
cfg = tag | (off &~ 03);
iohtole32(CONFIG_ADDR, cfg);
return iole32toh(CONFIG_DATA);
}
void
pcicfgwrite(tag, off, val)
unsigned tag, off, val;
unsigned tag;
int off;
unsigned val;
{
unsigned cfg;
cfg = tag | (off &~ 3);
cfg = tag | (off &~ 03);
iohtole32(CONFIG_ADDR, cfg);
iohtole32(CONFIG_DATA, val);
}
static unsigned
cfgread(b, d, f, off)
unsigned b, d, f, off;
int b, d, f, off;
{
unsigned cfg;
off &= ~03;
cfg = (1U << 31) | (b << 16) | (d << 11) | (f << 8) | off | 0;
iohtole32(CONFIG_ADDR, cfg);
return iole32toh(CONFIG_DATA);
@ -147,62 +163,22 @@ cfgread(b, d, f, off)
static void
cfgwrite(b, d, f, off, val)
unsigned b, d, f, off, val;
int b, d, f, off;
unsigned val;
{
unsigned cfg;
off &= ~03;
cfg = (1U << 31) | (b << 16) | (d << 11) | (f << 8) | off | 0;
iohtole32(CONFIG_ADDR, cfg);
iohtole32(CONFIG_DATA, val);
}
static int _maxbus;
static int
_pcifinddev(vend, prod, bus, tag)
unsigned vend, prod, bus;
unsigned *tag;
{
unsigned device, function, nfunctions;
unsigned pciid, bhlcr;
for (device = 0; device < MAXNDEVS; device++) {
pciid = cfgread(bus, device, 0, PCI_ID_REG);
if (PCI_VENDOR(pciid) == PCI_VENDOR_INVALID)
continue;
if (PCI_VENDOR(pciid) == 0)
continue;
if ((cfgread(bus, device, 0, 0x08) >> 16) == 0x0604) {
/* exploring bus beyond PCI-PCI bridge */
_maxbus = (bus += 1);
if (_pcifinddev(vend, prod, bus, tag) == 0)
return 0;
continue;
}
bhlcr = cfgread(bus, device, 0, PCI_BHLC_REG);
nfunctions = (PCI_HDRTYPE_MULTIFN(bhlcr)) ? 8 : 1;
for (function = 0; function < nfunctions; function++) {
pciid = cfgread(bus, device, function, PCI_ID_REG);
if (PCI_VENDOR(pciid) == PCI_VENDOR_INVALID)
continue;
if (PCI_VENDOR(pciid) == 0)
continue;
if (PCI_VENDOR(pciid) == vend
&& PCI_PRODUCT(pciid) == prod) {
*tag = pcimaketag(bus, device, function);
return 0;
}
}
}
*tag = ~0;
return -1;
}
static void
busprobe(bus)
unsigned bus;
int bus;
{
unsigned device, function, nfunctions;
int device, function, nfunctions;
unsigned pciid, bhlcr;
for (device = 0; device < MAXNDEVS; device++) {
@ -227,7 +203,7 @@ busprobe(bus)
static void
deviceinit(bus, dev, func)
unsigned bus, dev, func;
int bus, dev, func;
{
unsigned val;
@ -255,7 +231,7 @@ deviceinit(bus, dev, func)
devicemap(bus, dev, func);
/* descending toward PCI-PCI bridge */
if ((cfgread(bus, dev, func, 0x08) >> 16) == 0x0604) {
if ((cfgread(bus, dev, func, 0x08) >> 16) == PCI_CLASS_PPB) {
unsigned new;
/* 0x18 */
@ -293,7 +269,7 @@ deviceinit(bus, dev, func)
static void
devicemap(bus, dev, func)
unsigned bus, dev, func;
int bus, dev, func;
{
unsigned val, maxbar, mapr, req, mapbase, size;
@ -351,3 +327,88 @@ devicemap(bus, dev, func)
printf("%s base %x size %x\n", (val & 01) ? "i/o" : "mem", mapbase, size);
}
}
static int
_pcifinddev(vend, prod, bus, tag)
unsigned vend, prod;
int bus;
unsigned *tag;
{
unsigned device, function, nfunctions;
unsigned pciid, bhlcr, class;
for (device = 0; device < MAXNDEVS; device++) {
pciid = cfgread(bus, device, 0, PCI_ID_REG);
if (PCI_VENDOR(pciid) == PCI_VENDOR_INVALID)
continue;
if (PCI_VENDOR(pciid) == 0)
continue;
class = cfgread(bus, device, 0, PCI_CLASS_REG);
if ((class >> 16) == PCI_CLASS_PPB) {
/* exploring bus beyond PCI-PCI bridge */
if (_pcifinddev(vend, prod, bus + 1, tag) == 0)
return 0;
continue;
}
bhlcr = cfgread(bus, device, 0, PCI_BHLC_REG);
nfunctions = (PCI_HDRTYPE_MULTIFN(bhlcr)) ? 8 : 1;
for (function = 0; function < nfunctions; function++) {
pciid = cfgread(bus, device, function, PCI_ID_REG);
if (PCI_VENDOR(pciid) == PCI_VENDOR_INVALID)
continue;
if (PCI_VENDOR(pciid) == 0)
continue;
if (PCI_VENDOR(pciid) == vend
&& PCI_PRODUCT(pciid) == prod) {
*tag = pcimaketag(bus, device, function);
return 0;
}
}
}
*tag = ~0;
return -1;
}
static int
_pcilookup(type, list, bus, index, limit)
unsigned type;
unsigned list[][2];
int bus, index, limit;
{
int device, function, nfunctions;
unsigned pciid, bhlcr, class;
for (device = 0; device < MAXNDEVS; device++) {
pciid = cfgread(bus, device, 0, PCI_ID_REG);
if (PCI_VENDOR(pciid) == PCI_VENDOR_INVALID)
continue;
if (PCI_VENDOR(pciid) == 0)
continue;
class = cfgread(bus, device, 0, PCI_CLASS_REG);
if ((class >> 16) == PCI_CLASS_PPB) {
/* exploring bus beyond PCI-PCI bridge */
index += _pcilookup(type, list, bus + 1, index, limit);
continue;
}
bhlcr = cfgread(bus, device, 0, PCI_BHLC_REG);
nfunctions = (PCI_HDRTYPE_MULTIFN(bhlcr)) ? 8 : 1;
for (function = 0; function < nfunctions; function++) {
pciid = cfgread(bus, device, function, PCI_ID_REG);
if (PCI_VENDOR(pciid) == PCI_VENDOR_INVALID)
continue;
if (PCI_VENDOR(pciid) == 0)
continue;
class = cfgread(bus, device, function, PCI_CLASS_REG);
if ((class >> 16) == type) {
list[index][0] = pciid;
list[index][1] =
pcimaketag(bus, device, function);
index += 1;
if (index >= limit)
goto out;
}
}
}
out:
return index;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcn.c,v 1.4 2007/10/27 06:34:20 nisimura Exp $ */
/* $NetBSD: pcn.c,v 1.5 2007/10/30 00:30:14 nisimura Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -37,7 +37,6 @@
*/
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
@ -66,7 +65,7 @@
#define DELAY(n) delay(n)
#define ALLOC(T,A) (T *)((unsigned)alloc(sizeof(T) + (A)) &~ ((A) - 1))
void *pcn_init(void *);
void *pcn_init(unsigned, void *);
int pcn_send(void *, char *, unsigned);
int pcn_recv(void *, char *, unsigned, unsigned);
@ -94,18 +93,17 @@ static void pcn_bcr_write(struct local *, int, int);
static void mii_initphy(struct local *l);
void *
pcn_init(void *cookie)
pcn_init(unsigned tag, void *data)
{
unsigned tag, val, loop;
unsigned val, loop;
struct local *l;
struct desc *TxD, *RxD;
uint8_t *en;
struct leinit initblock, *ib;
if (pcifinddev(0x1022, 0x2000, &tag) != 0) {
printf("pcn NIC not found\n");
val = pcicfgread(tag, PCI_ID_REG);
if (PCI_VENDOR(val) != 0x1022 && PCI_PRODUCT(val) != 0x2000)
return NULL;
}
l = ALLOC(struct local, sizeof(struct desc));
memset(l, 0, sizeof(struct local));
@ -117,7 +115,7 @@ pcn_init(void *cookie)
CSR_WRITE_4(l, PCN32_RDP, 0);
mii_initphy(l);
en = cookie;
en = data;
val = pcn_csr_read(l, LE_CSR12); en[0] = val; en[1] = (val >> 8);
val = pcn_csr_read(l, LE_CSR13); en[2] = val; en[3] = (val >> 8);
val = pcn_csr_read(l, LE_CSR14); en[4] = val; en[5] = (val >> 8);

View File

@ -1,4 +1,4 @@
/* $NetBSD: rge.c,v 1.4 2007/10/28 03:15:04 nisimura Exp $ */
/* $NetBSD: rge.c,v 1.5 2007/10/30 00:30:14 nisimura Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -37,7 +37,6 @@
*/
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
@ -64,7 +63,7 @@
#define DELAY(n) delay(n)
#define ALLOC(T,A) (T *)((unsigned)alloc(sizeof(T) + (A)) &~ ((A) - 1))
void *rge_init(void *);
void *rge_init(unsigned, void *);
int rge_send(void *, char *, unsigned);
int rge_recv(void *, char *, unsigned, unsigned);
@ -167,17 +166,16 @@ static void rge_mii_write(struct local *, int, int, int);
static void mii_initphy(struct local *);
void *
rge_init(void *cookie)
rge_init(unsigned tag, void *data)
{
unsigned tag, val;
unsigned val;
struct local *l;
struct desc *TxD, *RxD;
uint8_t *en = cookie;
uint8_t *en = data;
if (pcifinddev(0x10ec, 0x8169, &tag) != 0) {
printf("rge NIC not found\n");
val = pcicfgread(tag, PCI_ID_REG);
if (PCI_VENDOR(val) != 0x10ec && PCI_PRODUCT(val) != 0x8169)
return NULL;
}
l = ALLOC(struct local, 256); /* desc alignment */
memset(l, 0, sizeof(struct local));
@ -190,7 +188,7 @@ rge_init(void *cookie)
mii_initphy(l);
en = cookie;
en = data;
en[0] = CSR_READ_1(l, RGE_IDR0);
en[1] = CSR_READ_1(l, RGE_IDR1);
en[2] = CSR_READ_1(l, RGE_IDR2);

View File

@ -1,4 +1,4 @@
/* $NetBSD: sip.c,v 1.4 2007/10/26 14:30:03 nisimura Exp $ */
/* $NetBSD: sip.c,v 1.5 2007/10/30 00:30:14 nisimura Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -37,7 +37,6 @@
*/
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
@ -61,7 +60,7 @@
#define inv(adr, siz) _inv(VTOPHYS(adr), (uint32_t)(siz))
#define DELAY(n) delay(n)
void *sip_init(void *);
void *sip_init(unsigned, void *);
int sip_send(void *, char *, unsigned);
int sip_recv(void *, char *, unsigned, unsigned);
@ -89,18 +88,17 @@ static const uint8_t bbr4[] = {0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15};
#define bbr(v) ((bbr4[(v)&0xf] << 4) | bbr4[((v)>>4) & 0xf])
void *
sip_init(void *cookie)
sip_init(unsigned tag, void *data)
{
unsigned tag, val, i, txcfg, rxcfg;
unsigned val, i, txcfg, rxcfg;
struct local *l;
struct desc *TxD, *RxD;
uint16_t eedata[4], *ee;
uint8_t *en;
if (pcifinddev(0x100b, 0x0020, &tag) != 0) {
printf("sip NIC not found\n");
val = pcicfgread(tag, PCI_ID_REG);
if (PCI_VENDOR(val) != 0x100b && PCI_PRODUCT(val) != 0x0020)
return NULL;
}
l = alloc(sizeof(struct local));
memset(l, 0, sizeof(struct local));
@ -116,7 +114,7 @@ sip_init(void *cookie)
mii_initphy(l);
ee = eedata; en = cookie;
ee = eedata; en = data;
ee[0] = read_eeprom(l, 6);
ee[1] = read_eeprom(l, 7);
ee[2] = read_eeprom(l, 8);

View File

@ -1,4 +1,4 @@
/* $NetBSD: tlp.c,v 1.8 2007/10/28 03:15:04 nisimura Exp $ */
/* $NetBSD: tlp.c,v 1.9 2007/10/30 00:30:14 nisimura Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -37,7 +37,6 @@
*/
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
@ -60,7 +59,7 @@
#define DELAY(n) delay(n)
#define ALLOC(T,A) (T *)((unsigned)alloc(sizeof(T) + (A)) &~ ((A) - 1))
void *tlp_init(void *);
void *tlp_init(unsigned, void *);
int tlp_send(void *, char *, unsigned);
int tlp_recv(void *, char *, unsigned, unsigned);
@ -127,19 +126,18 @@ static void mii_initphy(struct local *);
#endif
void *
tlp_init(void *cookie)
tlp_init(unsigned tag, void *data)
{
unsigned tag, val, i;
unsigned val, i;
struct local *l;
struct desc *TxD, *RxD;
uint8_t *en;
uint32_t *p;
if (pcifinddev(0x1011, 0x0009, &tag) != 0) {
/* genuine DE500 */
printf("tlp NIC not found\n");
val = pcicfgread(tag, PCI_ID_REG);
/* genuine DE500 */
if (PCI_VENDOR(val) != 0x1011 && PCI_PRODUCT(val) != 0x0009)
return NULL;
}
l = ALLOC(struct local, sizeof(struct desc));
memset(l, 0, sizeof(struct local));
@ -158,7 +156,7 @@ tlp_init(void *cookie)
CSR_WRITE(l, TLP_IEN, 0);
size_srom(l);
en = cookie;
en = data;
val = read_srom(l, 20/2+0); en[0] = val; en[1] = val >> 8;
val = read_srom(l, 20/2+1); en[2] = val; en[3] = val >> 8;
val = read_srom(l, 20/2+2); en[4] = val; en[5] = val >> 8;

View File

@ -1 +1,2 @@
1.0 initial version
1.1 PCI autoconf for multiple NIC device drivers

View File

@ -1,4 +1,4 @@
/* $NetBSD: vge.c,v 1.6 2007/10/28 03:15:04 nisimura Exp $ */
/* $NetBSD: vge.c,v 1.7 2007/10/30 00:30:14 nisimura Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -37,7 +37,6 @@
*/
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
@ -64,7 +63,7 @@
#define DELAY(n) delay(n)
#define ALLOC(T,A) (T *)((unsigned)alloc(sizeof(T) + (A)) &~ ((A) - 1))
void *vge_init(void *);
void *vge_init(unsigned, void *);
int vge_send(void *, char *, unsigned);
int vge_recv(void *, char *, unsigned, unsigned);
@ -205,18 +204,17 @@ static void vge_mii_write(struct local *, int, int, int);
static void mii_initphy(struct local *);
void *
vge_init(void *cookie)
vge_init(unsigned tag, void *data)
{
unsigned tag, val, i, loop, chipgcr;
unsigned val, i, loop, chipgcr;
struct local *l;
struct tdesc *TxD;
struct rdesc *RxD;
uint8_t *en;
if (pcifinddev(0x1106, 0x3119, &tag) != 0) {
printf("vge NIC not found\n");
val = pcicfgread(tag, PCI_ID_REG);
if (PCI_VENDOR(val) != 0x1106 && PCI_PRODUCT(val) != 0x3119)
return NULL;
}
l = ALLOC(struct local, 256); /* tdesc alignment */
memset(l, 0, sizeof(struct local));
@ -231,7 +229,7 @@ vge_init(void *cookie)
l->phy = CSR_READ_1(l, VGE_MIICFG) & 0x1f;
mii_initphy(l);
en = cookie;
en = data;
en[0] = CSR_READ_1(l, VGE_PAR0);
en[1] = CSR_READ_1(l, VGE_PAR1);
en[2] = CSR_READ_1(l, VGE_PAR2);