David van Moolenbroek f7df02e747 libnetdriver: rewrite
This is a driver-breaking update to the netdriver library, which is
used by all network drivers.  The aim of this change is to make the
library more compatible with NetBSD, and in particular with various
features that are expected to be supported by the NetBSD userland.
The main changes made by this patch are the following:

- each network driver now has a NetBSD-style short device name;
- drivers are not expected to receive packets right after startup;
- extended support for receipt modes, including multicast lists;
- support for multiple parallel send, receive requests;
- embedding of I/O vectors in send and receive requests;
- support for capabilities, including checksum offloading;
- support for reporting link status updates to the TCP/IP stack;
- support for setting and retrieving media status;
- support for changing the hardware (MAC) address;
- support for NetBSD interface flags IFF_DEBUG, IFF_LINK[0-2];
- support for NetBSD error statistics;
- support for regular time-based ("tick") callbacks.

IMPORTANT: this patch applies a minimal update to the existing drivers
in order to make them work at all with the new netdriver library.  It
however does *not* change all drivers to make use of the new features.
In fact, strictly speaking, all drivers are now violating requirements
imposed by the new library in one way or another, most notably by
enabling packet receipt when starting the driver.  Changing all the
drivers to be compliant, and to support the newly added options, is
left to future patches.  The existing drivers should currently *not*
be taken as examples of how to implement a new network driver!

With that said, a few drivers have already been changed to make use of
some of the new features: fxp, e1000, rtl8139, and rtl8169 now report
link and media status, and the last three of those now support setting
the hardware MAC address on the fly.  In addition, dp8390 has been
changed to default to PCI autoconfiguration if no configuration is
specified through environment variables.

Change-Id: I4b3ea9c0b9bc25d5b0609c6ff256fb0db71cdc42
2017-04-30 13:15:28 +00:00

137 lines
3.1 KiB
C

/**
* @file e1000.h
*
* @brief Device driver implementation declarations for the
* Intel Pro/1000 Gigabit Ethernet card(s).
*
* Parts of this code is based on the DragonflyBSD (FreeBSD)
* implementation, and the fxp driver for Minix 3.
*
* @see http://svn.freebsd.org/viewvc/base/head/sys/dev/e1000/
* @see fxp.c
*
* @author Niek Linnenbank <nieklinnenbank@gmail.com>
* @date September 2009
*
*/
#ifndef __E1000_H
#define __E1000_H
#include "e1000_hw.h"
/**
* @name Constants.
* @{
*/
/** Number of receive descriptors per card. */
#define E1000_RXDESC_NR 256
/** Number of transmit descriptors per card. */
#define E1000_TXDESC_NR 256
/** Size of each I/O buffer per descriptor. */
#define E1000_IOBUF_SIZE 2048
/** Debug verbosity. */
#define E1000_VERBOSE 0
/** MAC address override variable. */
#define E1000_ENVVAR "E1000ETH"
/**
* @}
*/
/**
* @name Status Flags.
* @{
*/
/**
* @}
*/
/**
* @name Macros.
* @{
*/
/**
* @brief Print a debug message.
* @param level Debug verbosity level.
* @param args Arguments to printf().
*/
#define E1000_DEBUG(level, args) \
if ((level) <= E1000_VERBOSE) \
{ \
printf args; \
} \
/**
* Read a byte from flash memory.
* @param e e1000_t pointer.
* @param reg Register offset.
*/
#define E1000_READ_FLASH_REG(e,reg) \
*(u32_t *) (((e)->flash) + (reg))
/**
* Read a 16-bit word from flash memory.
* @param e e1000_t pointer.
* @param reg Register offset.
*/
#define E1000_READ_FLASH_REG16(e,reg) \
*(u16_t *) (((e)->flash) + (reg))
/**
* Write a 16-bit word to flash memory.
* @param e e1000_t pointer.
* @param reg Register offset.
* @param value New value.
*/
#define E1000_WRITE_FLASH_REG(e,reg,value) \
*((u32_t *) (((e)->flash) + (reg))) = (value)
/**
* Write a 16-bit word to flash memory.
* @param e e1000_t pointer.
* @param reg Register offset.
* @param value New value.
*/
#define E1000_WRITE_FLASH_REG16(e,reg,value) \
*((u16_t *) (((e)->flash) + (reg))) = (value)
/**
* @}
*/
/**
* @brief Describes the state of an Intel Pro/1000 card.
*/
typedef struct e1000
{
int irq; /**< Interrupt Request Vector. */
int irq_hook; /**< Interrupt Request Vector Hook. */
u8_t *regs; /**< Memory mapped hardware registers. */
u8_t *flash; /**< Optional flash memory. */
u32_t flash_base_addr; /**< Flash base address. */
u16_t (*eeprom_read)(struct e1000 *, int reg);
/**< Function to read the EEPROM. */
int eeprom_done_bit; /**< Offset of the EERD.DONE bit. */
int eeprom_addr_off; /**< Offset of the EERD.ADDR field. */
e1000_rx_desc_t *rx_desc; /**< Receive Descriptor table. */
int rx_desc_count; /**< Number of Receive Descriptors. */
char *rx_buffer; /**< Receive buffer returned by malloc(). */
int rx_buffer_size; /**< Size of the receive buffer. */
e1000_tx_desc_t *tx_desc; /**< Transmit Descriptor table. */
int tx_desc_count; /**< Number of Transmit Descriptors. */
char *tx_buffer; /**< Transmit buffer returned by malloc(). */
int tx_buffer_size; /**< Size of the transmit buffer. */
} e1000_t;
#endif /* __E1000_H */