Added EtherExpress, tulip, and Broadcom Nics.

BCM570x, E1000, and Legacy Nics are commented out until pieces are
added to get them to link.
This commit is contained in:
Jennifer Averett 2012-05-09 12:28:53 -05:00
parent 5ab1e1daa7
commit 2dbdc7c926
5 changed files with 498 additions and 0 deletions

View File

@ -376,6 +376,8 @@ C_FILES += freebsd/kern/kern_ntptime.c
C_FILES += freebsd/kern/kern_environment.c C_FILES += freebsd/kern/kern_environment.c
C_FILES += freebsd/kern/kern_intr.c C_FILES += freebsd/kern/kern_intr.c
C_FILES += freebsd/kern/kern_resource.c C_FILES += freebsd/kern/kern_resource.c
C_FILES += freebsd/kern/subr_bufring.c
C_FILES += freebsd/dev/led/led.c
C_FILES += freebsd/dev/re/if_re.c C_FILES += freebsd/dev/re/if_re.c
C_FILES += freebsd/dev/fxp/if_fxp.c C_FILES += freebsd/dev/fxp/if_fxp.c
C_FILES += freebsd/dev/e1000/e1000_80003es2lan.c C_FILES += freebsd/dev/e1000/e1000_80003es2lan.c

View File

@ -1193,6 +1193,7 @@ devNic.addHeaderFiles(
'dev/random/randomdev_soft.h', 'dev/random/randomdev_soft.h',
'sys/eventvar.h', 'sys/eventvar.h',
'sys/kenv.h', 'sys/kenv.h',
'dev/pci/pci_private.h',
] ]
) )
devNic.addSourceFiles( devNic.addSourceFiles(
@ -1216,6 +1217,8 @@ devNic.addSourceFiles(
'kern/kern_environment.c', 'kern/kern_environment.c',
'kern/kern_intr.c', 'kern/kern_intr.c',
'kern/kern_resource.c', 'kern/kern_resource.c',
'kern/subr_bufring.c',
'dev/led/led.c',
] ]
) )

310
freebsd/dev/led/led.c Normal file
View File

@ -0,0 +1,310 @@
#include <freebsd/machine/rtems-bsd-config.h>
/*-
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
*/
#include <freebsd/sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <freebsd/sys/param.h>
#include <freebsd/sys/conf.h>
#include <freebsd/sys/kernel.h>
#include <freebsd/sys/systm.h>
#include <freebsd/sys/limits.h>
#include <freebsd/sys/malloc.h>
#include <freebsd/sys/ctype.h>
#include <freebsd/sys/sbuf.h>
#include <freebsd/sys/queue.h>
#include <freebsd/dev/led/led.h>
#include <freebsd/sys/uio.h>
#include <freebsd/sys/sx.h>
struct ledsc {
LIST_ENTRY(ledsc) list;
void *private;
int unit;
led_t *func;
struct cdev *dev;
struct sbuf *spec;
char *str;
char *ptr;
int count;
time_t last_second;
};
static struct unrhdr *led_unit;
static struct mtx led_mtx;
static struct sx led_sx;
static LIST_HEAD(, ledsc) led_list = LIST_HEAD_INITIALIZER(led_list);
static struct callout led_ch;
static MALLOC_DEFINE(M_LED, "LED", "LED driver");
static void
led_timeout(void *p)
{
struct ledsc *sc;
mtx_lock(&led_mtx);
LIST_FOREACH(sc, &led_list, list) {
if (sc->ptr == NULL)
continue;
if (sc->count > 0) {
sc->count--;
continue;
}
if (*sc->ptr == '.') {
sc->ptr = NULL;
continue;
} else if (*sc->ptr == 'U' || *sc->ptr == 'u') {
if (sc->last_second == time_second)
continue;
sc->last_second = time_second;
sc->func(sc->private, *sc->ptr == 'U');
} else if (*sc->ptr >= 'a' && *sc->ptr <= 'j') {
sc->func(sc->private, 0);
sc->count = (*sc->ptr & 0xf) - 1;
} else if (*sc->ptr >= 'A' && *sc->ptr <= 'J') {
sc->func(sc->private, 1);
sc->count = (*sc->ptr & 0xf) - 1;
}
sc->ptr++;
if (*sc->ptr == '\0')
sc->ptr = sc->str;
}
mtx_unlock(&led_mtx);
callout_reset(&led_ch, hz / 10, led_timeout, p);
return;
}
static int
led_state(struct cdev *dev, struct sbuf *sb, int state)
{
struct sbuf *sb2 = NULL;
struct ledsc *sc;
mtx_lock(&led_mtx);
sc = dev->si_drv1;
if (sc != NULL) {
sb2 = sc->spec;
sc->spec = sb;
if (sb != NULL) {
sc->str = sbuf_data(sb);
sc->ptr = sc->str;
} else {
sc->str = NULL;
sc->ptr = NULL;
sc->func(sc->private, state);
}
sc->count = 0;
}
mtx_unlock(&led_mtx);
if (sb2 != NULL)
sbuf_delete(sb2);
if (sc == NULL)
return (ENXIO);
return(0);
}
static int
led_write(struct cdev *dev, struct uio *uio, int ioflag)
{
int error;
char *s, *s2;
struct sbuf *sb = NULL;
int i;
if (dev->si_drv1 == NULL)
return (ENXIO);
if (uio->uio_resid > 512)
return (EINVAL);
s2 = s = malloc(uio->uio_resid + 1, M_DEVBUF, M_WAITOK);
s[uio->uio_resid] = '\0';
error = uiomove(s, uio->uio_resid, uio);
if (error) {
free(s2, M_DEVBUF);
return (error);
}
/*
* Handle "on" and "off" immediately so people can flash really
* fast from userland if they want to
*/
if (*s == '0' || *s == '1') {
error = led_state(dev, NULL, *s & 1);
free(s2, M_DEVBUF);
return(error);
}
sb = sbuf_new_auto();
if (sb == NULL) {
free(s2, M_DEVBUF);
return (ENOMEM);
}
switch(s[0]) {
/*
* Flash, default is 100msec/100msec.
* 'f2' sets 200msec/200msec etc.
*/
case 'f':
if (s[1] >= '1' && s[1] <= '9')
i = s[1] - '1';
else
i = 0;
sbuf_printf(sb, "%c%c", 'A' + i, 'a' + i);
break;
/*
* Digits, flashes out numbers.
* 'd12' becomes -__________-_-______________________________
*/
case 'd':
for(s++; *s; s++) {
if (!isdigit(*s))
continue;
i = *s - '0';
if (i == 0)
i = 10;
for (; i > 1; i--)
sbuf_cat(sb, "Aa");
sbuf_cat(sb, "Aj");
}
sbuf_cat(sb, "jj");
break;
/*
* String, roll your own.
* 'a-j' gives "off" for n/10 sec.
* 'A-J' gives "on" for n/10 sec.
* no delay before repeat
* 'sAaAbBa' becomes _-_--__-
*/
case 's':
for(s++; *s; s++) {
if ((*s >= 'a' && *s <= 'j') ||
(*s >= 'A' && *s <= 'J') ||
*s == 'U' || *s <= 'u' ||
*s == '.')
sbuf_bcat(sb, s, 1);
}
break;
/*
* Morse.
* '.' becomes _-
* '-' becomes _---
* ' ' becomes __
* '\n' becomes ____
* 1sec pause between repeats
* '... --- ...' -> _-_-_-___---_---_---___-_-_-__________
*/
case 'm':
for(s++; *s; s++) {
if (*s == '.')
sbuf_cat(sb, "aA");
else if (*s == '-')
sbuf_cat(sb, "aC");
else if (*s == ' ')
sbuf_cat(sb, "b");
else if (*s == '\n')
sbuf_cat(sb, "d");
}
sbuf_cat(sb, "j");
break;
default:
sbuf_delete(sb);
free(s2, M_DEVBUF);
return (EINVAL);
}
sbuf_finish(sb);
free(s2, M_DEVBUF);
if (sbuf_overflowed(sb)) {
sbuf_delete(sb);
return (ENOMEM);
}
if (sbuf_len(sb) == 0) {
sbuf_delete(sb);
return (0);
}
return (led_state(dev, sb, 0));
}
static struct cdevsw led_cdevsw = {
.d_version = D_VERSION,
.d_write = led_write,
.d_name = "LED",
};
struct cdev *
led_create(led_t *func, void *priv, char const *name)
{
return (led_create_state(func, priv, name, 0));
}
struct cdev *
led_create_state(led_t *func, void *priv, char const *name, int state)
{
struct ledsc *sc;
sc = malloc(sizeof *sc, M_LED, M_WAITOK | M_ZERO);
sx_xlock(&led_sx);
sc->unit = alloc_unr(led_unit);
sc->private = priv;
sc->func = func;
sc->dev = make_dev(&led_cdevsw, sc->unit,
UID_ROOT, GID_WHEEL, 0600, "led/%s", name);
sx_xunlock(&led_sx);
mtx_lock(&led_mtx);
sc->dev->si_drv1 = sc;
if (LIST_EMPTY(&led_list))
callout_reset(&led_ch, hz / 10, led_timeout, NULL);
LIST_INSERT_HEAD(&led_list, sc, list);
sc->func(sc->private, state != 0);
mtx_unlock(&led_mtx);
return (sc->dev);
}
void
led_destroy(struct cdev *dev)
{
struct ledsc *sc;
mtx_lock(&led_mtx);
sc = dev->si_drv1;
dev->si_drv1 = NULL;
LIST_REMOVE(sc, list);
if (LIST_EMPTY(&led_list))
callout_stop(&led_ch);
mtx_unlock(&led_mtx);
sx_xlock(&led_sx);
free_unr(led_unit, sc->unit);
destroy_dev(dev);
if (sc->spec != NULL)
sbuf_delete(sc->spec);
free(sc, M_LED);
sx_xunlock(&led_sx);
}
static void
led_drvinit(void *unused)
{
led_unit = new_unrhdr(0, INT_MAX, NULL);
mtx_init(&led_mtx, "LED mtx", NULL, MTX_DEF);
sx_init(&led_sx, "LED sx");
callout_init(&led_ch, CALLOUT_MPSAFE);
}
SYSINIT(leddev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, led_drvinit, NULL);

View File

@ -0,0 +1,116 @@
/*-
* Copyright (c) 1997, Stefan Esser <se@freebsd.org>
* Copyright (c) 2000, Michael Smith <msmith@freebsd.org>
* Copyright (c) 2000, BSDi
* 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 unmodified, 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 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.
*
* $FreeBSD$
*
*/
#ifndef _PCI_PRIVATE_HH_
#define _PCI_PRIVATE_HH_
/*
* Export definitions of the pci bus so that we can more easily share
* it with "subclass" busses.
*/
DECLARE_CLASS(pci_driver);
void pci_add_children(device_t dev, int domain, int busno,
size_t dinfo_size);
void pci_add_child(device_t bus, struct pci_devinfo *dinfo);
void pci_add_resources(device_t bus, device_t dev, int force,
uint32_t prefetchmask);
void pci_driver_added(device_t dev, driver_t *driver);
int pci_print_child(device_t dev, device_t child);
void pci_probe_nomatch(device_t dev, device_t child);
int pci_read_ivar(device_t dev, device_t child, int which,
uintptr_t *result);
int pci_write_ivar(device_t dev, device_t child, int which,
uintptr_t value);
int pci_setup_intr(device_t dev, device_t child,
struct resource *irq, int flags, driver_filter_t *filter,
driver_intr_t *intr, void *arg, void **cookiep);
int pci_teardown_intr(device_t dev, device_t child,
struct resource *irq, void *cookie);
int pci_get_vpd_ident_method(device_t dev, device_t child,
const char **identptr);
int pci_get_vpd_readonly_method(device_t dev, device_t child,
const char *kw, const char **vptr);
int pci_set_powerstate_method(device_t dev, device_t child,
int state);
int pci_get_powerstate_method(device_t dev, device_t child);
uint32_t pci_read_config_method(device_t dev, device_t child,
int reg, int width);
void pci_write_config_method(device_t dev, device_t child,
int reg, uint32_t val, int width);
int pci_enable_busmaster_method(device_t dev, device_t child);
int pci_disable_busmaster_method(device_t dev, device_t child);
int pci_enable_io_method(device_t dev, device_t child, int space);
int pci_disable_io_method(device_t dev, device_t child, int space);
int pci_find_extcap_method(device_t dev, device_t child,
int capability, int *capreg);
int pci_alloc_msi_method(device_t dev, device_t child, int *count);
int pci_alloc_msix_method(device_t dev, device_t child, int *count);
int pci_remap_msix_method(device_t dev, device_t child,
int count, const u_int *vectors);
int pci_release_msi_method(device_t dev, device_t child);
int pci_msi_count_method(device_t dev, device_t child);
int pci_msix_count_method(device_t dev, device_t child);
struct resource *pci_alloc_resource(device_t dev, device_t child,
int type, int *rid, u_long start, u_long end, u_long count,
u_int flags);
int pci_release_resource(device_t dev, device_t child, int type,
int rid, struct resource *r);
int pci_activate_resource(device_t dev, device_t child, int type,
int rid, struct resource *r);
void pci_delete_resource(device_t dev, device_t child,
int type, int rid);
struct resource_list *pci_get_resource_list (device_t dev, device_t child);
struct pci_devinfo *pci_read_device(device_t pcib, int d, int b, int s, int f,
size_t size);
void pci_print_verbose(struct pci_devinfo *dinfo);
int pci_freecfg(struct pci_devinfo *dinfo);
int pci_child_location_str_method(device_t cbdev, device_t child,
char *buf, size_t buflen);
int pci_child_pnpinfo_str_method(device_t cbdev, device_t child,
char *buf, size_t buflen);
int pci_assign_interrupt_method(device_t dev, device_t child);
int pci_resume(device_t dev);
int pci_suspend(device_t dev);
/** Restore the config register state. The state must be previously
* saved with pci_cfg_save. However, the pci bus driver takes care of
* that. This function will also return the device to PCI_POWERSTATE_D0
* if it is currently in a lower power mode.
*/
void pci_cfg_restore(device_t, struct pci_devinfo *);
/** Save the config register state. Optionally set the power state to D3
* if the third argument is non-zero.
*/
void pci_cfg_save(device_t, struct pci_devinfo *, int);
#endif /* _PCI_PRIVATE_HH_ */

View File

@ -0,0 +1,67 @@
#include <freebsd/machine/rtems-bsd-config.h>
/*-
* Copyright (c) 2007, 2008 Kip Macy <kmacy@freebsd.org>
* 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 AUTHOR 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 AUTHOR 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 <freebsd/sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <freebsd/sys/param.h>
#include <freebsd/sys/systm.h>
#include <freebsd/sys/kernel.h>
#include <freebsd/sys/malloc.h>
#include <freebsd/sys/ktr.h>
#include <freebsd/sys/buf_ring.h>
struct buf_ring *
buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *lock)
{
struct buf_ring *br;
KASSERT(powerof2(count), ("buf ring must be size power of 2"));
br = malloc(sizeof(struct buf_ring) + count*sizeof(caddr_t),
type, flags|M_ZERO);
if (br == NULL)
return (NULL);
#ifdef DEBUG_BUFRING
br->br_lock = lock;
#endif
br->br_prod_size = br->br_cons_size = count;
br->br_prod_mask = br->br_cons_mask = count-1;
br->br_prod_head = br->br_cons_head = 0;
br->br_prod_tail = br->br_cons_tail = 0;
return (br);
}
void
buf_ring_free(struct buf_ring *br, struct malloc_type *type)
{
free(br, type);
}