2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
1997-09-05 10:23:58 +00:00
|
|
|
* Copyright (c) 1995, David Greenman
|
|
|
|
* All rights reserved.
|
2008-11-25 00:48:05 +00:00
|
|
|
*
|
1997-09-05 10:23:58 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
2008-11-25 00:48:05 +00:00
|
|
|
* are met:
|
1997-09-05 10:23:58 +00:00
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice unmodified, this list of conditions, and the following
|
2008-11-25 00:48:05 +00:00
|
|
|
* disclaimer.
|
1997-09-05 10:23:58 +00:00
|
|
|
* 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.
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1997-09-05 10:23:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Misc. defintions for the Intel EtherExpress Pro/100B PCI Fast
|
|
|
|
* Ethernet driver
|
|
|
|
*/
|
2001-03-12 21:30:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Number of transmit control blocks. This determines the number
|
|
|
|
* of transmit buffers that can be chained in the CB list.
|
|
|
|
* This must be a power of two.
|
|
|
|
*/
|
|
|
|
#define FXP_NTXCB 128
|
2008-11-25 04:16:16 +00:00
|
|
|
#define FXP_NTXCB_HIWAT ((FXP_NTXCB * 7) / 10)
|
2001-03-12 21:30:52 +00:00
|
|
|
|
2003-04-02 16:47:16 +00:00
|
|
|
/*
|
|
|
|
* Size of the TxCB list.
|
|
|
|
*/
|
|
|
|
#define FXP_TXCB_SZ (FXP_NTXCB * sizeof(struct fxp_cb_tx))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macro to obtain the DMA address of a virtual address in the
|
|
|
|
* TxCB list based on the base DMA address of the TxCB list.
|
|
|
|
*/
|
|
|
|
#define FXP_TXCB_DMA_ADDR(sc, addr) \
|
|
|
|
(sc->fxp_desc.cbl_addr + (uintptr_t)addr - \
|
|
|
|
(uintptr_t)sc->fxp_desc.cbl_list)
|
|
|
|
|
2001-03-12 21:30:52 +00:00
|
|
|
/*
|
|
|
|
* Number of completed TX commands at which point an interrupt
|
|
|
|
* will be generated to garbage collect the attached buffers.
|
|
|
|
* Must be at least one less than FXP_NTXCB, and should be
|
|
|
|
* enough less so that the transmitter doesn't becomes idle
|
|
|
|
* during the buffer rundown (which would reduce performance).
|
|
|
|
*/
|
|
|
|
#define FXP_CXINT_THRESH 120
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TxCB list index mask. This is used to do list wrap-around.
|
|
|
|
*/
|
|
|
|
#define FXP_TXCB_MASK (FXP_NTXCB - 1)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Number of receive frame area buffers. These are large so chose
|
|
|
|
* wisely.
|
|
|
|
*/
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
|
|
|
#define FXP_NRFABUFS 192
|
|
|
|
#else
|
2001-03-12 21:30:52 +00:00
|
|
|
#define FXP_NRFABUFS 64
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +00:00
|
|
|
#endif
|
2001-03-12 21:30:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Maximum number of seconds that the receiver can be idle before we
|
|
|
|
* assume it's dead and attempt to reset it by reprogramming the
|
|
|
|
* multicast filter. This is part of a work-around for a bug in the
|
|
|
|
* NIC. See fxp_stats_update().
|
|
|
|
*/
|
|
|
|
#define FXP_MAX_RX_IDLE 15
|
|
|
|
|
2001-10-25 05:27:25 +00:00
|
|
|
/*
|
|
|
|
* Default maximum time, in microseconds, that an interrupt may be delayed
|
2008-11-25 00:48:05 +00:00
|
|
|
* in an attempt to coalesce interrupts. This is only effective if the Intel
|
2001-10-25 05:27:25 +00:00
|
|
|
* microcode is loaded, and may be changed via either loader tunables or
|
|
|
|
* sysctl. See also the CPUSAVER_DWORD entry in rcvbundl.h.
|
|
|
|
*/
|
|
|
|
#define TUNABLE_INT_DELAY 1000
|
|
|
|
|
|
|
|
/*
|
2008-11-25 00:48:05 +00:00
|
|
|
* Default number of packets that will be bundled, before an interrupt is
|
2001-10-25 05:27:25 +00:00
|
|
|
* generated. This is only effective if the Intel microcode is loaded, and
|
2008-11-25 00:48:05 +00:00
|
|
|
* may be changed via either loader tunables or sysctl. This may not be
|
2001-10-25 05:27:25 +00:00
|
|
|
* present in all microcode revisions, see also the CPUSAVER_BUNDLE_MAX_DWORD
|
|
|
|
* entry in rcvbundl.h.
|
|
|
|
*/
|
|
|
|
#define TUNABLE_BUNDLE_MAX 6
|
|
|
|
|
2001-03-12 21:30:52 +00:00
|
|
|
#define FXP_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
|
|
|
|
#define FXP_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
|
2004-06-02 22:59:57 +00:00
|
|
|
#define FXP_LOCK_ASSERT(_sc, _what) mtx_assert(&(_sc)->sc_mtx, (_what))
|
2001-03-12 21:30:52 +00:00
|
|
|
|
2003-04-02 16:47:16 +00:00
|
|
|
/*
|
|
|
|
* Structures to handle TX and RX descriptors.
|
|
|
|
*/
|
|
|
|
struct fxp_rx {
|
|
|
|
struct fxp_rx *rx_next;
|
|
|
|
struct mbuf *rx_mbuf;
|
|
|
|
bus_dmamap_t rx_map;
|
2005-03-06 05:07:26 +00:00
|
|
|
uint32_t rx_addr;
|
2003-04-02 16:47:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct fxp_tx {
|
|
|
|
struct fxp_tx *tx_next;
|
|
|
|
struct fxp_cb_tx *tx_cb;
|
|
|
|
struct mbuf *tx_mbuf;
|
|
|
|
bus_dmamap_t tx_map;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct fxp_desc_list {
|
|
|
|
struct fxp_rx rx_list[FXP_NRFABUFS];
|
|
|
|
struct fxp_tx tx_list[FXP_NTXCB];
|
|
|
|
struct fxp_tx mcs_tx;
|
|
|
|
struct fxp_rx *rx_head;
|
|
|
|
struct fxp_rx *rx_tail;
|
|
|
|
struct fxp_tx *tx_first;
|
|
|
|
struct fxp_tx *tx_last;
|
|
|
|
struct fxp_rfa *rfa_list;
|
|
|
|
struct fxp_cb_tx *cbl_list;
|
2005-03-06 05:07:26 +00:00
|
|
|
uint32_t cbl_addr;
|
2003-04-02 16:47:16 +00:00
|
|
|
bus_dma_tag_t rx_tag;
|
|
|
|
};
|
2001-03-12 21:30:52 +00:00
|
|
|
|
1998-08-02 00:29:15 +00:00
|
|
|
/*
|
|
|
|
* NOTE: Elements are ordered for optimal cacheline behavior, and NOT
|
|
|
|
* for functional grouping.
|
|
|
|
*/
|
1997-09-05 10:23:58 +00:00
|
|
|
struct fxp_softc {
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp; /* per-interface network data */
|
2005-09-27 09:01:11 +00:00
|
|
|
struct resource *fxp_res[2]; /* I/O and IRQ resources */
|
|
|
|
struct resource_spec *fxp_spec; /* the resource spec we used */
|
1999-04-16 21:22:55 +00:00
|
|
|
void *ih; /* interrupt handler cookie */
|
2000-09-17 13:26:25 +00:00
|
|
|
struct mtx sc_mtx;
|
2003-04-02 16:47:16 +00:00
|
|
|
bus_dma_tag_t fxp_mtag; /* bus DMA tag for mbufs */
|
|
|
|
bus_dma_tag_t fxp_stag; /* bus DMA tag for stats */
|
|
|
|
bus_dmamap_t fxp_smap; /* bus DMA map for stats */
|
|
|
|
bus_dma_tag_t cbl_tag; /* DMA tag for the TxCB list */
|
|
|
|
bus_dmamap_t cbl_map; /* DMA map for the TxCB list */
|
|
|
|
bus_dma_tag_t mcs_tag; /* DMA tag for the multicast setup */
|
|
|
|
bus_dmamap_t mcs_map; /* DMA map for the multicast setup */
|
|
|
|
bus_dmamap_t spare_map; /* spare DMA map */
|
|
|
|
struct fxp_desc_list fxp_desc; /* descriptors management struct */
|
2005-03-07 13:20:49 +00:00
|
|
|
int maxtxseg; /* maximum # of TX segments */
|
1997-11-29 08:11:01 +00:00
|
|
|
int tx_queued; /* # of active TxCB's */
|
|
|
|
int need_mcsetup; /* multicast filter needs programming */
|
1997-09-05 10:23:58 +00:00
|
|
|
struct fxp_stats *fxp_stats; /* Pointer to interface stats */
|
2005-03-06 05:07:26 +00:00
|
|
|
uint32_t stats_addr; /* DMA address of the stats structure */
|
1997-11-29 08:11:01 +00:00
|
|
|
int rx_idle_secs; /* # of seconds RX has been idle */
|
2003-09-05 22:37:31 +00:00
|
|
|
struct callout stat_ch; /* stat callout */
|
2006-11-30 14:58:01 +00:00
|
|
|
int watchdog_timer; /* seconds until chip reset */
|
1997-11-29 08:11:01 +00:00
|
|
|
struct fxp_cb_mcs *mcsp; /* Pointer to mcast setup descriptor */
|
2005-03-06 05:07:26 +00:00
|
|
|
uint32_t mcs_addr; /* DMA address of the multicast cmd */
|
1998-08-02 00:29:15 +00:00
|
|
|
struct ifmedia sc_media; /* media information */
|
2001-03-12 21:30:52 +00:00
|
|
|
device_t miibus;
|
|
|
|
device_t dev;
|
2001-10-25 05:27:25 +00:00
|
|
|
int tunable_int_delay; /* interrupt delay value for ucode */
|
|
|
|
int tunable_bundle_max; /* max # frames per interrupt (ucode) */
|
2004-06-02 22:52:18 +00:00
|
|
|
int tunable_noflow; /* flow control disabled */
|
|
|
|
int rnr; /* RNR events */
|
2000-03-28 04:41:42 +00:00
|
|
|
int eeprom_size; /* size of serial EEPROM */
|
2003-04-30 01:54:38 +00:00
|
|
|
int suspended; /* 0 = normal 1 = suspended or dead */
|
2001-05-17 23:50:24 +00:00
|
|
|
int cu_resume_bug;
|
2001-10-25 05:27:25 +00:00
|
|
|
int revision;
|
2001-03-12 21:30:52 +00:00
|
|
|
int flags;
|
2005-03-06 05:07:26 +00:00
|
|
|
uint8_t rfa_size;
|
|
|
|
uint32_t tx_cmd;
|
1997-09-05 10:23:58 +00:00
|
|
|
};
|
|
|
|
|
2001-03-12 21:30:52 +00:00
|
|
|
#define FXP_FLAG_MWI_ENABLE 0x0001 /* MWI enable */
|
|
|
|
#define FXP_FLAG_READ_ALIGN 0x0002 /* align read access with cacheline */
|
|
|
|
#define FXP_FLAG_WRITE_ALIGN 0x0004 /* end write on cacheline */
|
|
|
|
#define FXP_FLAG_EXT_TXCB 0x0008 /* enable use of extended TXCB */
|
|
|
|
#define FXP_FLAG_SERIAL_MEDIA 0x0010 /* 10Mbps serial interface */
|
|
|
|
#define FXP_FLAG_LONG_PKT_EN 0x0020 /* enable long packet reception */
|
|
|
|
#define FXP_FLAG_ALL_MCAST 0x0040 /* accept all multicast frames */
|
2001-05-17 23:50:24 +00:00
|
|
|
#define FXP_FLAG_CU_RESUME_BUG 0x0080 /* requires workaround for CU_RESUME */
|
2001-10-25 05:27:25 +00:00
|
|
|
#define FXP_FLAG_UCODE 0x0100 /* ucode is loaded */
|
2002-11-07 16:04:07 +00:00
|
|
|
#define FXP_FLAG_DEFERRED_RNR 0x0200 /* DEVICE_POLLING deferred RNR */
|
2003-02-26 22:12:04 +00:00
|
|
|
#define FXP_FLAG_EXT_RFA 0x0400 /* extended RFDs for csum offload */
|
2004-05-25 14:49:46 +00:00
|
|
|
#define FXP_FLAG_SAVE_BAD 0x0800 /* save bad pkts: bad size, CRC, etc */
|
2001-03-12 21:30:52 +00:00
|
|
|
|
1997-09-05 10:23:58 +00:00
|
|
|
/* Macros to ease CSR access. */
|
2005-09-27 09:01:11 +00:00
|
|
|
#define CSR_READ_1(sc, reg) bus_read_1(sc->fxp_res[0], reg)
|
|
|
|
#define CSR_READ_2(sc, reg) bus_read_2(sc->fxp_res[0], reg)
|
|
|
|
#define CSR_READ_4(sc, reg) bus_read_4(sc->fxp_res[0], reg)
|
|
|
|
#define CSR_WRITE_1(sc, reg, val) bus_write_1(sc->fxp_res[0], reg, val)
|
|
|
|
#define CSR_WRITE_2(sc, reg, val) bus_write_2(sc->fxp_res[0], reg, val)
|
|
|
|
#define CSR_WRITE_4(sc, reg, val) bus_write_4(sc->fxp_res[0], reg, val)
|