2011-05-21 20:25:31 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/net/e1000.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Yu Qiang. All rights reserved.
|
|
|
|
* Author: Yu Qiang <yuq825@gmail.com>
|
|
|
|
*
|
|
|
|
* This file is a part of NuttX:
|
|
|
|
*
|
2014-08-21 19:16:55 +02:00
|
|
|
* Copyright (C) 2011, 2014 Gregory Nutt. All rights reserved.
|
2011-05-21 20:25:31 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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
|
|
|
|
* COPYRIGHT OWNER 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2014-07-05 03:13:08 +02:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
2011-05-21 20:25:31 +02:00
|
|
|
#include <nuttx/arch.h>
|
2014-08-21 19:16:55 +02:00
|
|
|
#include <nuttx/irq.h>
|
|
|
|
#include <nuttx/wdog.h>
|
2013-03-09 22:12:20 +01:00
|
|
|
#include <nuttx/kmalloc.h>
|
2014-05-30 20:13:06 +02:00
|
|
|
#include <nuttx/net/arp.h>
|
2014-06-24 17:28:44 +02:00
|
|
|
#include <nuttx/net/netdev.h>
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2015-01-20 22:14:29 +01:00
|
|
|
#ifdef CONFIG_NET_PKT
|
|
|
|
# include <nuttx/net/pkt.h>
|
|
|
|
#endif
|
|
|
|
|
2011-05-21 20:25:31 +02:00
|
|
|
#include <rgmp/pmap.h>
|
|
|
|
#include <rgmp/string.h>
|
|
|
|
#include <rgmp/stdio.h>
|
2012-11-04 16:12:55 +01:00
|
|
|
#include <rgmp/utils.h>
|
2011-08-04 14:29:19 +02:00
|
|
|
#include <rgmp/arch/pci.h>
|
|
|
|
#include <rgmp/memio.h>
|
2014-07-05 03:13:08 +02:00
|
|
|
|
2011-05-21 20:25:31 +02:00
|
|
|
#include "e1000.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* TX poll deley = 1 seconds. CLK_TCK is the number of clock ticks per second */
|
|
|
|
|
|
|
|
#define E1000_WDDELAY (1*CLK_TCK)
|
|
|
|
|
|
|
|
/* TX timeout = 1 minute */
|
|
|
|
|
|
|
|
#define E1000_TXTIMEOUT (60*CLK_TCK)
|
|
|
|
|
|
|
|
/* This is a helper pointer for accessing the contents of the Ethernet header */
|
|
|
|
|
2014-06-29 21:03:19 +02:00
|
|
|
#define BUF ((struct eth_hdr_s *)e1000->netdev.d_buf)
|
2011-05-21 20:25:31 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
struct tx_ring
|
|
|
|
{
|
|
|
|
struct tx_desc *desc;
|
|
|
|
char *buf;
|
|
|
|
int tail; /* where to write desc */
|
2011-05-21 20:25:31 +02:00
|
|
|
};
|
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
struct rx_ring
|
|
|
|
{
|
|
|
|
struct rx_desc *desc;
|
|
|
|
char *buf;
|
|
|
|
int head; /* where to read */
|
|
|
|
int tail; /* where to release free desc */
|
|
|
|
int free; /* number of freed desc */
|
2011-05-21 20:25:31 +02:00
|
|
|
};
|
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
struct e1000_dev
|
|
|
|
{
|
|
|
|
uint32_t phy_mem_base;
|
|
|
|
uint32_t io_mem_base;
|
|
|
|
uint32_t mem_size;
|
|
|
|
int pci_dev_id;
|
|
|
|
uint16_t pci_addr;
|
|
|
|
unsigned char src_mac[6];
|
|
|
|
unsigned char dst_mac[6];
|
|
|
|
struct irq_action int_desc;
|
|
|
|
struct tx_ring tx_ring;
|
|
|
|
struct rx_ring rx_ring;
|
|
|
|
struct e1000_dev *next;
|
|
|
|
|
|
|
|
/* NuttX net data */
|
|
|
|
|
2014-06-29 21:03:19 +02:00
|
|
|
bool bifup; /* true:ifup false:ifdown */
|
|
|
|
WDOG_ID txpoll; /* TX poll timer */
|
|
|
|
WDOG_ID txtimeout; /* TX timeout timer */
|
2014-02-11 01:08:49 +01:00
|
|
|
|
|
|
|
/* This holds the information visible to uIP/NuttX */
|
|
|
|
|
2014-06-29 21:03:19 +02:00
|
|
|
struct net_driver_s netdev; /* Interface understood by networking layer */
|
2011-05-21 20:25:31 +02:00
|
|
|
};
|
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
struct e1000_dev_head
|
|
|
|
{
|
|
|
|
struct e1000_dev *next;
|
2011-05-21 20:25:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
static struct e1000_dev_head e1000_list =
|
|
|
|
{
|
|
|
|
0
|
|
|
|
};
|
2011-05-21 20:25:31 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Common TX logic */
|
|
|
|
|
|
|
|
static int e1000_transmit(struct e1000_dev *e1000);
|
2014-07-02 02:41:08 +02:00
|
|
|
static int e1000_txpoll(struct net_driver_s *dev);
|
2011-05-21 20:25:31 +02:00
|
|
|
|
|
|
|
/* Interrupt handling */
|
|
|
|
|
|
|
|
static void e1000_receive(struct e1000_dev *e1000);
|
|
|
|
|
|
|
|
/* Watchdog timer expirations */
|
|
|
|
|
|
|
|
static void e1000_polltimer(int argc, uint32_t arg, ...);
|
|
|
|
static void e1000_txtimeout(int argc, uint32_t arg, ...);
|
|
|
|
|
|
|
|
/* NuttX callback functions */
|
|
|
|
|
2014-06-28 00:48:12 +02:00
|
|
|
static int e1000_ifup(struct net_driver_s *dev);
|
|
|
|
static int e1000_ifdown(struct net_driver_s *dev);
|
|
|
|
static int e1000_txavail(struct net_driver_s *dev);
|
2011-05-21 20:25:31 +02:00
|
|
|
#ifdef CONFIG_NET_IGMP
|
2014-06-28 00:48:12 +02:00
|
|
|
static int e1000_addmac(struct net_driver_s *dev, const uint8_t *mac);
|
|
|
|
static int e1000_rmmac(struct net_driver_s *dev, const uint8_t *mac);
|
2011-05-21 20:25:31 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
2014-02-11 01:08:49 +01:00
|
|
|
|
2011-05-21 20:25:31 +02:00
|
|
|
static inline void e1000_outl(struct e1000_dev *dev, int reg, uint32_t val)
|
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
writel(dev->io_mem_base+reg, val);
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t e1000_inl(struct e1000_dev *dev, int reg)
|
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
return readl(dev->io_mem_base+reg);
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************** e1000 driver ********************************/
|
|
|
|
|
2011-06-09 16:11:33 +02:00
|
|
|
void e1000_reset(struct e1000_dev *dev)
|
2011-05-21 20:25:31 +02:00
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
uint32_t dev_control;
|
|
|
|
|
|
|
|
/* Reset the network controller hardware */
|
|
|
|
|
|
|
|
dev_control = 0;
|
2015-10-10 18:41:00 +02:00
|
|
|
dev_control |= (1 << 0); /* FD-bit (Full Duplex) */
|
|
|
|
dev_control |= (0 << 2); /* GIOMD-bit (GIO Master Disable) */
|
|
|
|
dev_control |= (1 << 3); /* LRST-bit (Link Reset) */
|
|
|
|
dev_control |= (1 << 6); /* SLU-bit (Set Link Up) */
|
|
|
|
dev_control |= (2 << 8); /* SPEED=2 (1000Mbps) */
|
|
|
|
dev_control |= (0 << 11); /* FRCSPD-bit (Force Speed) */
|
|
|
|
dev_control |= (0 << 12); /* FRCDPLX-bit (Force Duplex) */
|
|
|
|
dev_control |= (0 << 20); /* ADVD3WUC-bit (Advertise D3 Wake Up Cap) */
|
|
|
|
dev_control |= (1 << 26); /* RST-bit (Device Reset) */
|
|
|
|
dev_control |= (1 << 27); /* RFCE-bit (Receive Flow Control Enable) */
|
|
|
|
dev_control |= (1 << 28); /* TFCE-bit (Transmit Flow Control Enable) */
|
|
|
|
dev_control |= (0 << 30); /* VME-bit (VLAN Mode Enable) */
|
|
|
|
dev_control |= (0 << 31); /* PHY_RST-bit (PHY Reset) */
|
2014-02-11 01:08:49 +01:00
|
|
|
|
|
|
|
e1000_outl(dev, E1000_IMC, 0xFFFFFFFF);
|
|
|
|
e1000_outl(dev, E1000_STATUS, 0x00000000);
|
|
|
|
e1000_outl(dev, E1000_CTRL, dev_control);
|
2015-10-10 18:41:00 +02:00
|
|
|
dev_control &= ~(1 << 26); /* clear RST-bit (Device Reset) */
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000_outl(dev, E1000_CTRL, dev_control);
|
|
|
|
up_mdelay(10);
|
|
|
|
e1000_outl(dev, E1000_CTRL_EXT, 0x001401C0);
|
|
|
|
e1000_outl(dev, E1000_IMC, 0xFFFFFFFF);
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
2011-06-09 16:11:33 +02:00
|
|
|
void e1000_turn_on(struct e1000_dev *dev)
|
2011-05-21 20:25:31 +02:00
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
int tx_control;
|
|
|
|
int rx_control;
|
|
|
|
uint32_t ims = 0;
|
|
|
|
|
|
|
|
/* turn on the controller's receive engine */
|
|
|
|
|
|
|
|
rx_control = e1000_inl(dev, E1000_RCTL);
|
2015-10-10 18:41:00 +02:00
|
|
|
rx_control |= (1 << 1);
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000_outl(dev, E1000_RCTL, rx_control);
|
|
|
|
|
|
|
|
/* turn on the controller's transmit engine */
|
|
|
|
|
|
|
|
tx_control = e1000_inl(dev, E1000_TCTL);
|
2015-10-10 18:41:00 +02:00
|
|
|
tx_control |= (1 << 1);
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000_outl(dev, E1000_TCTL, tx_control);
|
|
|
|
|
|
|
|
/* enable the controller's interrupts */
|
|
|
|
|
|
|
|
e1000_outl(dev, E1000_ICR, 0xFFFFFFFF);
|
|
|
|
e1000_outl(dev, E1000_IMC, 0xFFFFFFFF);
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
ims |= 1 << 0; /* TXDW */
|
|
|
|
ims |= 1 << 1; /* TXQE */
|
|
|
|
ims |= 1 << 2; /* LSC */
|
|
|
|
ims |= 1 << 4; /* RXDMT0 */
|
|
|
|
ims |= 1 << 7; /* RXT0 */
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000_outl(dev, E1000_IMS, ims);
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
2011-06-09 16:11:33 +02:00
|
|
|
void e1000_turn_off(struct e1000_dev *dev)
|
2011-05-21 20:25:31 +02:00
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
int tx_control;
|
|
|
|
int rx_control;
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* turn off the controller's receive engine */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
rx_control = e1000_inl(dev, E1000_RCTL);
|
2015-10-10 18:41:00 +02:00
|
|
|
rx_control &= ~(1 << 1);
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000_outl(dev, E1000_RCTL, rx_control);
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* turn off the controller's transmit engine */
|
|
|
|
|
|
|
|
tx_control = e1000_inl(dev, E1000_TCTL);
|
2015-10-10 18:41:00 +02:00
|
|
|
tx_control &= ~(1 << 1);
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000_outl(dev, E1000_TCTL, tx_control);
|
|
|
|
|
|
|
|
/* turn off the controller's interrupts */
|
|
|
|
|
|
|
|
e1000_outl(dev, E1000_IMC, 0xFFFFFFFF);
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
2011-06-09 16:11:33 +02:00
|
|
|
void e1000_init(struct e1000_dev *dev)
|
2011-05-21 20:25:31 +02:00
|
|
|
{
|
2014-11-25 20:15:09 +01:00
|
|
|
uint32_t rxd_phys;
|
2014-02-11 01:08:49 +01:00
|
|
|
uint32_t txd_phys;
|
|
|
|
uint32_t kmem_phys;
|
|
|
|
uint32_t rx_control;
|
|
|
|
uint32_t tx_control;
|
|
|
|
uint32_t pba;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
e1000_reset(dev);
|
|
|
|
|
|
|
|
/* configure the controller's 'receive' engine */
|
|
|
|
|
|
|
|
rx_control = 0;
|
2015-10-10 18:41:00 +02:00
|
|
|
rx_control |= (0 << 1); /* EN-bit (Enable) */
|
|
|
|
rx_control |= (0 << 2); /* SPB-bit (Store Bad Packets) */
|
|
|
|
rx_control |= (0 << 3); /* UPE-bit (Unicast Promiscuous Mode) */
|
|
|
|
rx_control |= (1 << 4); /* MPE-bit (Multicast Promiscuous Mode) */
|
|
|
|
rx_control |= (0 << 5); /* LPE-bit (Long Packet Enable) */
|
|
|
|
rx_control |= (0 << 6); /* LBM=0 (Loop-Back Mode) */
|
|
|
|
rx_control |= (0 << 8); /* RDMTS=0 (Rx Descriptor Min Threshold Size) */
|
|
|
|
rx_control |= (0 << 10); /* DTYPE=0 (Descriptor Type) */
|
|
|
|
rx_control |= (0 << 12); /* MO=0 (Multicast Offset) */
|
|
|
|
rx_control |= (1 << 15); /* BAM-bit (Broadcast Address Mode) */
|
|
|
|
rx_control |= (0 << 16); /* BSIZE=0 (Buffer Size = 2048) */
|
|
|
|
rx_control |= (0 << 18); /* VLE-bit (VLAN filter Enable) */
|
|
|
|
rx_control |= (0 << 19); /* CFIEN-bit (Canonical Form Indicator Enable) */
|
|
|
|
rx_control |= (0 << 20); /* CFI-bit (Canonical Form Indicator) */
|
|
|
|
rx_control |= (1 << 22); /* DPF-bit (Discard Pause Frames) */
|
|
|
|
rx_control |= (0 << 23); /* PMCF-bit (Pass MAC Control Frames) */
|
|
|
|
rx_control |= (0 << 25); /* BSEX=0 (Buffer Size EXtension) */
|
|
|
|
rx_control |= (1 << 26); /* SECRC-bit (Strip Ethernet CRC) */
|
|
|
|
rx_control |= (0 << 27); /* FLEXBUF=0 (Flexible Buffer size) */
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000_outl(dev, E1000_RCTL, rx_control);
|
|
|
|
|
|
|
|
/* configure the controller's 'transmit' engine */
|
|
|
|
|
|
|
|
tx_control = 0;
|
2015-10-10 18:41:00 +02:00
|
|
|
tx_control |= (0 << 1); /* EN-bit (Enable) */
|
|
|
|
tx_control |= (1 << 3); /* PSP-bit (Pad Short Packets) */
|
|
|
|
tx_control |= (15 << 4); /* CT=15 (Collision Threshold) */
|
|
|
|
tx_control |= (63 << 12); /* COLD=63 (Collision Distance) */
|
|
|
|
tx_control |= (0 << 22); /* SWXOFF-bit (Software XOFF) */
|
|
|
|
tx_control |= (1 << 24); /* RTLC-bit (Re-Transmit on Late Collision) */
|
|
|
|
tx_control |= (0 << 25); /* UNORTX-bit (Underrun No Re-Transmit) */
|
|
|
|
tx_control |= (0 << 26); /* TXCSCMT=0 (TxDesc Mininum Threshold) */
|
|
|
|
tx_control |= (0 << 28); /* MULR-bit (Multiple Request Support) */
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000_outl(dev, E1000_TCTL, tx_control);
|
|
|
|
|
|
|
|
/* hardware flow control */
|
|
|
|
|
|
|
|
pba = e1000_inl(dev, E1000_PBA);
|
|
|
|
|
|
|
|
/* get receive FIFO size */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
pba = (pba & 0x000000ff) << 10;
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000_outl(dev, E1000_FCAL, 0x00C28001);
|
|
|
|
e1000_outl(dev, E1000_FCAH, 0x00000100);
|
|
|
|
e1000_outl(dev, E1000_FCT, 0x00008808);
|
|
|
|
e1000_outl(dev, E1000_FCTTV, 0x00000680);
|
2015-10-10 18:41:00 +02:00
|
|
|
e1000_outl(dev, E1000_FCRTL, (pba * 8 / 10) | 0x80000000);
|
|
|
|
e1000_outl(dev, E1000_FCRTH, pba * 9 / 10);
|
2014-02-11 01:08:49 +01:00
|
|
|
|
|
|
|
/* setup tx rings */
|
|
|
|
|
|
|
|
txd_phys = PADDR((uintptr_t)dev->tx_ring.desc);
|
|
|
|
kmem_phys = PADDR((uintptr_t)dev->tx_ring.buf);
|
2015-10-10 18:41:00 +02:00
|
|
|
for (i = 0; i < CONFIG_E1000_N_TX_DESC; i++, kmem_phys += CONFIG_E1000_BUFF_SIZE)
|
2014-02-11 01:08:49 +01:00
|
|
|
{
|
2015-10-10 18:41:00 +02:00
|
|
|
dev->tx_ring.desc[i].base_address = kmem_phys;
|
2014-02-11 01:08:49 +01:00
|
|
|
dev->tx_ring.desc[i].packet_length = 0;
|
2015-10-10 18:41:00 +02:00
|
|
|
dev->tx_ring.desc[i].cksum_offset = 0;
|
|
|
|
dev->tx_ring.desc[i].cksum_origin = 0;
|
|
|
|
dev->tx_ring.desc[i].desc_status = 1;
|
|
|
|
dev->tx_ring.desc[i].desc_command = (1 << 0) | (1 << 1) | (1 << 3);
|
|
|
|
dev->tx_ring.desc[i].special_info = 0;
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
2014-02-11 01:08:49 +01:00
|
|
|
|
|
|
|
dev->tx_ring.tail = 0;
|
|
|
|
e1000_outl(dev, E1000_TDT, 0);
|
|
|
|
e1000_outl(dev, E1000_TDH, 0);
|
|
|
|
|
|
|
|
/* tell controller the location, size, and fetch-policy for Tx queue */
|
|
|
|
|
|
|
|
e1000_outl(dev, E1000_TDBAL, txd_phys);
|
|
|
|
e1000_outl(dev, E1000_TDBAH, 0x00000000);
|
2015-10-10 18:41:00 +02:00
|
|
|
e1000_outl(dev, E1000_TDLEN, CONFIG_E1000_N_TX_DESC * 16);
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000_outl(dev, E1000_TXDCTL, 0x01010000);
|
|
|
|
|
|
|
|
/* setup rx rings */
|
|
|
|
|
|
|
|
rxd_phys = PADDR((uintptr_t)dev->rx_ring.desc);
|
|
|
|
kmem_phys = PADDR((uintptr_t)dev->rx_ring.buf);
|
2015-10-10 18:41:00 +02:00
|
|
|
for (i = 0; i < CONFIG_E1000_N_RX_DESC; i++, kmem_phys += CONFIG_E1000_BUFF_SIZE)
|
2014-02-11 01:08:49 +01:00
|
|
|
{
|
|
|
|
dev->rx_ring.desc[i].base_address = kmem_phys;
|
|
|
|
dev->rx_ring.desc[i].packet_length = 0;
|
|
|
|
dev->rx_ring.desc[i].packet_cksum = 0;
|
|
|
|
dev->rx_ring.desc[i].desc_status = 0;
|
|
|
|
dev->rx_ring.desc[i].desc_errors = 0;
|
|
|
|
dev->rx_ring.desc[i].vlan_tag = 0;
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
2014-02-11 01:08:49 +01:00
|
|
|
|
|
|
|
dev->rx_ring.head = 0;
|
|
|
|
dev->rx_ring.tail = CONFIG_E1000_N_RX_DESC-1;
|
|
|
|
dev->rx_ring.free = 0;
|
|
|
|
|
|
|
|
/* give the controller ownership of all receive descriptors */
|
|
|
|
|
|
|
|
e1000_outl(dev, E1000_RDH, 0);
|
|
|
|
e1000_outl(dev, E1000_RDT, CONFIG_E1000_N_RX_DESC-1);
|
|
|
|
|
|
|
|
/* tell controller the location, size, and fetch-policy for RX queue */
|
|
|
|
|
|
|
|
e1000_outl(dev, E1000_RDBAL, rxd_phys);
|
|
|
|
e1000_outl(dev, E1000_RDBAH, 0x00000000);
|
|
|
|
e1000_outl(dev, E1000_RDLEN, CONFIG_E1000_N_RX_DESC*16);
|
|
|
|
e1000_outl(dev, E1000_RXDCTL, 0x01010000);
|
|
|
|
|
|
|
|
e1000_turn_on(dev);
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Function: e1000_transmit
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Start hardware transmission. Called either from the txdone interrupt
|
|
|
|
* handling or from watchdog based polling.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* e1000 - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success; a negated errno on failure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* May or may not be called from an interrupt handler. In either case,
|
|
|
|
* global interrupts are disabled, either explicitly or indirectly through
|
|
|
|
* interrupt handling logic.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int e1000_transmit(struct e1000_dev *e1000)
|
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
int tail = e1000->tx_ring.tail;
|
|
|
|
unsigned char *cp = (unsigned char *)
|
|
|
|
(e1000->tx_ring.buf + tail * CONFIG_E1000_BUFF_SIZE);
|
2014-06-29 21:03:19 +02:00
|
|
|
int count = e1000->netdev.d_len;
|
2014-02-11 01:08:49 +01:00
|
|
|
|
|
|
|
/* Verify that the hardware is ready to send another packet. If we get
|
|
|
|
* here, then we are committed to sending a packet; Higher level logic
|
|
|
|
* must have assured that there is not transmission in progress.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!e1000->tx_ring.desc[tail].desc_status)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send the packet: address=skel->sk_dev.d_buf, length=skel->sk_dev.d_len */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-06-29 21:03:19 +02:00
|
|
|
memcpy(cp, e1000->netdev.d_buf, e1000->netdev.d_len);
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* prepare the transmit-descriptor */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
e1000->tx_ring.desc[tail].packet_length = count < 60 ? 60 : count;
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000->tx_ring.desc[tail].desc_status = 0;
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* give ownership of this descriptor to the network controller */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
tail = (tail + 1) % CONFIG_E1000_N_TX_DESC;
|
|
|
|
e1000->tx_ring.tail = tail;
|
|
|
|
e1000_outl(e1000, E1000_TDT, tail);
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* Enable Tx interrupts */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* Setup the TX timeout watchdog (perhaps restarting the timer) */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
wd_start(e1000->txtimeout, E1000_TXTIMEOUT, e1000_txtimeout, 1, (uint32_t)e1000);
|
|
|
|
return OK;
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-07-02 02:41:08 +02:00
|
|
|
* Function: e1000_txpoll
|
2011-05-21 20:25:31 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The transmitter is available, check if uIP has any outgoing packets ready
|
2014-07-01 02:40:41 +02:00
|
|
|
* to send. This is a callback from devif_poll(). devif_poll() may be called:
|
2011-05-21 20:25:31 +02:00
|
|
|
*
|
|
|
|
* 1. When the preceding TX packet send is complete,
|
|
|
|
* 2. When the preceding TX packet send timesout and the interface is reset
|
|
|
|
* 3. During normal TX polling
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success; a negated errno on failure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* May or may not be called from an interrupt handler. In either case,
|
|
|
|
* global interrupts are disabled, either explicitly or indirectly through
|
|
|
|
* interrupt handling logic.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-07-02 02:41:08 +02:00
|
|
|
static int e1000_txpoll(struct net_driver_s *dev)
|
2011-05-21 20:25:31 +02:00
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
struct e1000_dev *e1000 = (struct e1000_dev *)dev->d_private;
|
|
|
|
int tail = e1000->tx_ring.tail;
|
|
|
|
|
|
|
|
/* If the polling resulted in data that should be sent out on the network,
|
|
|
|
* the field d_len is set to a value > 0.
|
|
|
|
*/
|
|
|
|
|
2014-06-29 21:03:19 +02:00
|
|
|
if (e1000->netdev.d_len > 0)
|
2014-02-11 01:08:49 +01:00
|
|
|
{
|
2015-01-21 18:36:33 +01:00
|
|
|
/* Look up the destination MAC address and add it to the Ethernet
|
|
|
|
* header.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
if (IFF_IS_IPv4(e1000->netdev.d_flags))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
arp_out(&e1000->netdev);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_IPv4 */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
neighbor_out(&e1000->netdev);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_IPv6 */
|
|
|
|
|
|
|
|
/* Send the packet */
|
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000_transmit(e1000);
|
|
|
|
|
|
|
|
/* Check if there is room in the device to hold another packet. If not,
|
|
|
|
* return a non-zero value to terminate the poll.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!e1000->tx_ring.desc[tail].desc_status)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* If zero is returned, the polling will continue until all connections have
|
|
|
|
* been examined.
|
|
|
|
*/
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
return 0;
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Function: e1000_receive
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* An interrupt was received indicating the availability of a new RX packet
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* e1000 - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Global interrupts are disabled by interrupt handling logic.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void e1000_receive(struct e1000_dev *e1000)
|
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
int head = e1000->rx_ring.head;
|
|
|
|
unsigned char *cp = (unsigned char *)
|
|
|
|
(e1000->rx_ring.buf + head * CONFIG_E1000_BUFF_SIZE);
|
|
|
|
int cnt;
|
|
|
|
|
|
|
|
while (e1000->rx_ring.desc[head].desc_status)
|
|
|
|
{
|
|
|
|
/* Here we do not handle packets that exceed packet-buffer size */
|
|
|
|
|
|
|
|
if ((e1000->rx_ring.desc[head].desc_status & 3) == 1)
|
|
|
|
{
|
|
|
|
cprintf("NIC READ: Oversized packet\n");
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the packet is a valid size for the uIP buffer configuration */
|
|
|
|
|
|
|
|
/* get the number of actual data-bytes in this packet */
|
|
|
|
|
|
|
|
cnt = e1000->rx_ring.desc[head].packet_length;
|
|
|
|
|
2014-11-16 15:53:20 +01:00
|
|
|
if (cnt > CONFIG_NET_ETH_MTU || cnt < 14)
|
2014-02-11 01:08:49 +01:00
|
|
|
{
|
|
|
|
cprintf("NIC READ: invalid package size\n");
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
2014-06-29 21:03:19 +02:00
|
|
|
/* Copy the data data from the hardware to e1000->netdev.d_buf. Set
|
|
|
|
* amount of data in e1000->netdev.d_len
|
2014-02-11 01:08:49 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* now we try to copy these data-bytes to the UIP buffer */
|
|
|
|
|
2014-06-29 21:03:19 +02:00
|
|
|
memcpy(e1000->netdev.d_buf, cp, cnt);
|
|
|
|
e1000->netdev.d_len = cnt;
|
2014-02-11 01:08:49 +01:00
|
|
|
|
2015-01-20 22:14:29 +01:00
|
|
|
#ifdef CONFIG_NET_PKT
|
|
|
|
/* When packet sockets are enabled, feed the frame into the packet tap */
|
|
|
|
|
|
|
|
pkt_input(&e1000->netdev);
|
|
|
|
#endif
|
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* We only accept IP packets of the configured type and ARP packets */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2015-01-15 17:25:53 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2014-11-25 20:15:09 +01:00
|
|
|
if (BUF->type == HTONS(ETHTYPE_IP))
|
|
|
|
{
|
2015-01-15 17:25:53 +01:00
|
|
|
nllvdbg("IPv4 frame\n");
|
|
|
|
|
|
|
|
/* Handle ARP on input then give the IPv4 packet to the network
|
|
|
|
* layer
|
|
|
|
*/
|
|
|
|
|
2014-11-25 20:15:09 +01:00
|
|
|
arp_ipin(&e1000->netdev);
|
2015-01-15 15:03:56 +01:00
|
|
|
ipv4_input(&e1000->netdev);
|
2014-11-25 20:15:09 +01:00
|
|
|
|
|
|
|
/* If the above function invocation resulted in data that should be
|
|
|
|
* sent out on the network, the field d_len will set to a value > 0.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (e1000->netdev.d_len > 0)
|
2014-02-11 01:08:49 +01:00
|
|
|
{
|
2015-01-15 17:25:53 +01:00
|
|
|
/* Update the Ethernet header with the correct MAC address */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2015-01-20 22:14:29 +01:00
|
|
|
if (IFF_IS_IPv4(e1000->netdev.d_flags))
|
2015-01-15 17:25:53 +01:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
arp_out(&e1000->netdev);
|
|
|
|
}
|
2015-01-20 22:52:25 +01:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
else
|
|
|
|
{
|
|
|
|
neighbor_out(&e1000->netdev);
|
|
|
|
}
|
|
|
|
#endif
|
2015-01-15 17:25:53 +01:00
|
|
|
|
|
|
|
/* And send the packet */
|
|
|
|
|
2014-11-25 20:15:09 +01:00
|
|
|
e1000_transmit(e1000);
|
2014-02-11 01:08:49 +01:00
|
|
|
}
|
2014-11-25 20:15:09 +01:00
|
|
|
}
|
2015-01-15 17:25:53 +01:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
if (BUF->type == HTONS(ETHTYPE_IP6))
|
|
|
|
{
|
|
|
|
nllvdbg("Iv6 frame\n");
|
|
|
|
|
|
|
|
/* Give the IPv6 packet to the network layer */
|
|
|
|
|
|
|
|
ipv6_input(&e1000->netdev);
|
|
|
|
|
|
|
|
/* If the above function invocation resulted in data that should be
|
|
|
|
* sent out on the network, the field d_len will set to a value > 0.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (e1000->netdev.d_len > 0)
|
|
|
|
{
|
|
|
|
/* Update the Ethernet header with the correct MAC address */
|
|
|
|
|
2015-01-20 22:52:25 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2015-01-20 22:14:29 +01:00
|
|
|
if (IFF_IS_IPv4(e1000->netdev.d_flags))
|
2015-01-15 17:25:53 +01:00
|
|
|
{
|
|
|
|
arp_out(&e1000->netdev);
|
|
|
|
}
|
2015-01-20 22:52:25 +01:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
{
|
|
|
|
neighbor_out(&e1000->netdev);
|
|
|
|
}
|
2015-01-15 17:25:53 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* And send the packet */
|
|
|
|
|
|
|
|
e1000_transmit(e1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_ARP
|
|
|
|
if (BUF->type == htons(ETHTYPE_ARP))
|
2014-11-25 20:15:09 +01:00
|
|
|
{
|
|
|
|
arp_arpin(&e1000->netdev);
|
2014-02-11 01:08:49 +01:00
|
|
|
|
2014-11-25 20:15:09 +01:00
|
|
|
/* If the above function invocation resulted in data that should be
|
|
|
|
* sent out on the network, the field d_len will set to a value > 0.
|
|
|
|
*/
|
2014-02-11 01:08:49 +01:00
|
|
|
|
2014-11-25 20:15:09 +01:00
|
|
|
if (e1000->netdev.d_len > 0)
|
|
|
|
{
|
|
|
|
e1000_transmit(e1000);
|
2014-02-11 01:08:49 +01:00
|
|
|
}
|
2015-01-15 17:25:53 +01:00
|
|
|
#endif
|
2014-02-11 01:08:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
next:
|
|
|
|
e1000->rx_ring.desc[head].desc_status = 0;
|
|
|
|
e1000->rx_ring.head = (head + 1) % CONFIG_E1000_N_RX_DESC;
|
|
|
|
e1000->rx_ring.free++;
|
|
|
|
head = e1000->rx_ring.head;
|
|
|
|
cp = (unsigned char *)(e1000->rx_ring.buf + head * CONFIG_E1000_BUFF_SIZE);
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Function: e1000_txtimeout
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Our TX watchdog timed out. Called from the timer interrupt handler.
|
|
|
|
* The last TX never completed. Reset the hardware and start again.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* argc - The number of available arguments
|
|
|
|
* arg - The first argument
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Global interrupts are disabled by the watchdog logic.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void e1000_txtimeout(int argc, uint32_t arg, ...)
|
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
struct e1000_dev *e1000 = (struct e1000_dev *)arg;
|
|
|
|
|
|
|
|
/* Then reset the hardware */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000_init(e1000);
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* Then poll uIP for new XMIT data */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-07-02 02:41:08 +02:00
|
|
|
(void)devif_poll(&e1000->netdev, e1000_txpoll);
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Function: e1000_polltimer
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Periodic timer handler. Called from the timer interrupt handler.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* argc - The number of available arguments
|
|
|
|
* arg - The first argument
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Global interrupts are disabled by the watchdog logic.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void e1000_polltimer(int argc, uint32_t arg, ...)
|
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
struct e1000_dev *e1000 = (struct e1000_dev *)arg;
|
|
|
|
int tail = e1000->tx_ring.tail;
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* Check if there is room in the send another TX packet. We cannot perform
|
|
|
|
* the TX poll if he are unable to accept another packet for transmission.
|
|
|
|
*/
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
if (!e1000->tx_ring.desc[tail].desc_status)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If so, update TCP timing states and poll uIP for new XMIT data. Hmmm..
|
|
|
|
* might be bug here. Does this mean if there is a transmit in progress,
|
|
|
|
* we will missing TCP time state updates?
|
|
|
|
*/
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2016-02-03 19:12:41 +01:00
|
|
|
(void)devif_timer(&e1000->netdev, e1000_txpoll);
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* Setup the watchdog poll timer again */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
(void)wd_start(e1000->txpoll, E1000_WDDELAY, e1000_polltimer, 1, arg);
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Function: e1000_ifup
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Bring up the Ethernet interface when an IP address is
|
2014-02-11 01:08:49 +01:00
|
|
|
* provided
|
2011-05-21 20:25:31 +02:00
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-28 00:48:12 +02:00
|
|
|
static int e1000_ifup(struct net_driver_s *dev)
|
2011-05-21 20:25:31 +02:00
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
struct e1000_dev *e1000 = (struct e1000_dev *)dev->d_private;
|
|
|
|
|
|
|
|
ndbg("Bringing up: %d.%d.%d.%d\n",
|
|
|
|
dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff,
|
2015-10-10 18:41:00 +02:00
|
|
|
(dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24);
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* Initialize PHYs, the Ethernet interface, and setup up Ethernet interrupts */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000_init(e1000);
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* Set and activate a timer process */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
(void)wd_start(e1000->txpoll, E1000_WDDELAY, e1000_polltimer, 1, (uint32_t)e1000);
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
if (e1000_inl(e1000, E1000_STATUS) & 2)
|
|
|
|
{
|
|
|
|
e1000->bifup = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e1000->bifup = false;
|
|
|
|
}
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
return OK;
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Function: e1000_ifdown
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Stop the interface.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-28 00:48:12 +02:00
|
|
|
static int e1000_ifdown(struct net_driver_s *dev)
|
2011-05-21 20:25:31 +02:00
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
struct e1000_dev *e1000 = (struct e1000_dev *)dev->d_private;
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
/* Disable the Ethernet interrupt */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
flags = irqsave();
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000_turn_off(e1000);
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* Cancel the TX poll timer and TX timeout timers */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
wd_cancel(e1000->txpoll);
|
|
|
|
wd_cancel(e1000->txtimeout);
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* Put the EMAC is its reset, non-operational state. This should be
|
|
|
|
* a known configuration that will guarantee the skel_ifup() always
|
|
|
|
* successfully brings the interface back up.
|
|
|
|
*/
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
//e1000_reset(e1000);
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* Mark the device "down" */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000->bifup = false;
|
|
|
|
irqrestore(flags);
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
return OK;
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Function: e1000_txavail
|
|
|
|
*
|
|
|
|
* Description:
|
2014-02-11 01:08:49 +01:00
|
|
|
* Driver callback invoked when new TX data is available. This is a
|
2011-05-21 20:25:31 +02:00
|
|
|
* stimulus perform an out-of-cycle poll and, thereby, reduce the TX
|
|
|
|
* latency.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called in normal user mode
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-28 00:48:12 +02:00
|
|
|
static int e1000_txavail(struct net_driver_s *dev)
|
2011-05-21 20:25:31 +02:00
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
struct e1000_dev *e1000 = (struct e1000_dev *)dev->d_private;
|
|
|
|
int tail = e1000->tx_ring.tail;
|
|
|
|
irqstate_t flags;
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* Disable interrupts because this function may be called from interrupt
|
|
|
|
* level processing.
|
|
|
|
*/
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
flags = irqsave();
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* Ignore the notification if the interface is not yet up */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
if (e1000->bifup)
|
|
|
|
{
|
|
|
|
/* Check if there is room in the hardware to hold another outgoing packet. */
|
|
|
|
|
|
|
|
if (e1000->tx_ring.desc[tail].desc_status)
|
|
|
|
{
|
2014-07-02 02:41:08 +02:00
|
|
|
(void)devif_poll(&e1000->netdev, e1000_txpoll);
|
2014-02-11 01:08:49 +01:00
|
|
|
}
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
irqrestore(flags);
|
|
|
|
return OK;
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Function: e1000_addmac
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Add the specified MAC address to the hardware multicast
|
|
|
|
* address filtering
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* dev - Reference to the NuttX driver state structure
|
2014-02-11 01:08:49 +01:00
|
|
|
* mac - The MAC address to be added
|
2011-05-21 20:25:31 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IGMP
|
2014-06-28 00:48:12 +02:00
|
|
|
static int e1000_addmac(struct net_driver_s *dev, const uint8_t *mac)
|
2011-05-21 20:25:31 +02:00
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
/* Add the MAC address to the hardware multicast routing table */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
return OK;
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Function: e1000_rmmac
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Remove the specified MAC address from the hardware multicast
|
|
|
|
* address filtering
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* dev - Reference to the NuttX driver state structure
|
2014-02-11 01:08:49 +01:00
|
|
|
* mac - The MAC address to be removed
|
2011-05-21 20:25:31 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IGMP
|
2014-06-28 00:48:12 +02:00
|
|
|
static int e1000_rmmac(struct net_driver_s *dev, const uint8_t *mac)
|
2011-05-21 20:25:31 +02:00
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
/* Add the MAC address to the hardware multicast routing table */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
return OK;
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-04 16:12:55 +01:00
|
|
|
static irqreturn_t e1000_interrupt_handler(int irq, void *dev_id)
|
2011-05-21 20:25:31 +02:00
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
struct e1000_dev *e1000 = (struct e1000_dev *)dev_id;
|
|
|
|
|
|
|
|
/* Get and clear interrupt status bits */
|
|
|
|
|
|
|
|
int intr_cause = e1000_inl(e1000, E1000_ICR);
|
|
|
|
e1000_outl(e1000, E1000_ICR, intr_cause);
|
|
|
|
|
|
|
|
/* not for me */
|
|
|
|
|
|
|
|
if (intr_cause == 0)
|
|
|
|
{
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle interrupts according to status bit settings */
|
|
|
|
|
|
|
|
/* Link status change */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
if (intr_cause & (1 << 2))
|
2014-02-11 01:08:49 +01:00
|
|
|
{
|
|
|
|
if (e1000_inl(e1000, E1000_STATUS) & 2)
|
|
|
|
{
|
|
|
|
e1000->bifup = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e1000->bifup = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we received an incoming packet, if so, call skel_receive() */
|
|
|
|
|
|
|
|
/* Rx-descriptor Timer expired */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
if (intr_cause & (1 << 7))
|
2014-02-11 01:08:49 +01:00
|
|
|
{
|
|
|
|
e1000_receive(e1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Tx queue empty */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
if (intr_cause & (1 << 1))
|
2014-02-11 01:08:49 +01:00
|
|
|
{
|
|
|
|
wd_cancel(e1000->txtimeout);
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
2014-02-11 01:08:49 +01:00
|
|
|
|
|
|
|
/* Tx-descriptor Written back */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
if (intr_cause & (1 << 0))
|
2014-02-11 01:08:49 +01:00
|
|
|
{
|
2014-07-02 02:41:08 +02:00
|
|
|
devif_poll(&e1000->netdev, e1000_txpoll);
|
2014-02-11 01:08:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Rx-Descriptors Low */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
if (intr_cause & (1 << 4))
|
2014-02-11 01:08:49 +01:00
|
|
|
{
|
|
|
|
int tail;
|
|
|
|
|
|
|
|
tail = e1000->rx_ring.tail + e1000->rx_ring.free;
|
|
|
|
tail %= CONFIG_E1000_N_RX_DESC;
|
|
|
|
e1000->rx_ring.tail = tail;
|
|
|
|
e1000->rx_ring.free = 0;
|
|
|
|
e1000_outl(e1000, E1000_RDT, tail);
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
return IRQ_HANDLED;
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************* PCI driver *********************************/
|
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
static pci_id_t e1000_id_table[] =
|
|
|
|
{
|
2015-10-10 18:41:00 +02:00
|
|
|
{
|
|
|
|
.sep =
|
|
|
|
{
|
|
|
|
INTEL_VENDERID, E1000_82573L
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.sep =
|
|
|
|
{
|
|
|
|
INTEL_VENDERID, E1000_82540EM
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.sep =
|
|
|
|
{
|
|
|
|
INTEL_VENDERID, E1000_82574L
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.sep =
|
|
|
|
{
|
|
|
|
INTEL_VENDERID, E1000_82567LM
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.sep =
|
|
|
|
{
|
|
|
|
INTEL_VENDERID, E1000_82541PI
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.sep =
|
|
|
|
{
|
|
|
|
0, 0
|
|
|
|
}
|
|
|
|
}
|
2011-05-21 20:25:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static int e1000_probe(uint16_t addr, pci_id_t id)
|
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
uint32_t mmio_base, mmio_size;
|
|
|
|
uint32_t size;
|
|
|
|
int err;
|
|
|
|
void *kmem;
|
|
|
|
void *omem;
|
|
|
|
struct e1000_dev *dev;
|
|
|
|
|
|
|
|
/* alloc e1000_dev memory */
|
|
|
|
|
2014-09-01 01:34:44 +02:00
|
|
|
if ((dev = kmm_zalloc(sizeof(struct e1000_dev))) == NULL)
|
2014-02-11 01:08:49 +01:00
|
|
|
{
|
|
|
|
return -1;
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* save pci addr */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
dev->pci_addr = addr;
|
|
|
|
|
|
|
|
/* enable device */
|
|
|
|
|
|
|
|
if ((err = pci_enable_device(addr, PCI_BUS_MASTER)) < 0)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* get e1000 device type */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
dev->pci_dev_id = id.join;
|
|
|
|
|
|
|
|
/* remap the controller's i/o-memory into kernel's address-space */
|
|
|
|
|
|
|
|
mmio_base = pci_resource_start(addr, 0);
|
|
|
|
mmio_size = pci_resource_len(addr, 0);
|
|
|
|
err = rgmp_memmap_nocache(mmio_base, mmio_size, mmio_base);
|
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->phy_mem_base = mmio_base;
|
|
|
|
dev->io_mem_base = mmio_base;
|
|
|
|
dev->mem_size = mmio_size;
|
|
|
|
|
|
|
|
/* MAC address */
|
|
|
|
|
|
|
|
memset(dev->dst_mac, 0xFF, 6);
|
|
|
|
memcpy(dev->src_mac, (void *)(dev->io_mem_base+E1000_RA), 6);
|
|
|
|
|
|
|
|
/* IRQ setup */
|
|
|
|
|
|
|
|
dev->int_desc.handler = e1000_interrupt_handler;
|
|
|
|
dev->int_desc.dev_id = dev;
|
|
|
|
if ((err = pci_request_irq(addr, &dev->int_desc, 0)) < 0)
|
|
|
|
{
|
|
|
|
goto err0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Here we alloc a big block of memory once and make it
|
|
|
|
* aligned to page boundary and multiple of page size. This
|
|
|
|
* is because the memory can be modified by E1000 DMA and
|
|
|
|
* should be mapped no-cache which will hugely reduce memory
|
|
|
|
* access performance. The page size alloc will restrict
|
|
|
|
* this bad effect only within the memory we alloc here.
|
|
|
|
*
|
2015-08-16 19:00:30 +02:00
|
|
|
* NEED FIX: the memalign may alloc memory continuous in
|
|
|
|
* virtual address but dis-continuous in physical address
|
2014-02-11 01:08:49 +01:00
|
|
|
* due to RGMP memory setup.
|
|
|
|
*/
|
|
|
|
|
|
|
|
size = CONFIG_E1000_N_TX_DESC * sizeof(struct tx_desc) +
|
|
|
|
CONFIG_E1000_N_TX_DESC * CONFIG_E1000_BUFF_SIZE +
|
|
|
|
CONFIG_E1000_N_RX_DESC * sizeof(struct rx_desc) +
|
|
|
|
CONFIG_E1000_N_RX_DESC * CONFIG_E1000_BUFF_SIZE;
|
|
|
|
size = ROUNDUP(size, PGSIZE);
|
|
|
|
omem = kmem = memalign(PGSIZE, size);
|
|
|
|
if (kmem == NULL)
|
|
|
|
{
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rgmp_memremap_nocache((uintptr_t)kmem, size);
|
|
|
|
|
|
|
|
/* alloc memory for tx ring */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
dev->tx_ring.desc = (FAR struct tx_desc *)kmem;
|
2014-02-11 01:08:49 +01:00
|
|
|
kmem += CONFIG_E1000_N_TX_DESC * sizeof(struct tx_desc);
|
|
|
|
dev->tx_ring.buf = kmem;
|
|
|
|
kmem += CONFIG_E1000_N_TX_DESC * CONFIG_E1000_BUFF_SIZE;
|
|
|
|
|
|
|
|
/* alloc memory for rx rings */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
dev->rx_ring.desc = (FAR struct rx_desc *)kmem;
|
2014-02-11 01:08:49 +01:00
|
|
|
kmem += CONFIG_E1000_N_RX_DESC * sizeof(struct rx_desc);
|
|
|
|
dev->rx_ring.buf = kmem;
|
|
|
|
|
|
|
|
/* Initialize the driver structure */
|
|
|
|
|
2014-06-29 21:03:19 +02:00
|
|
|
dev->netdev.d_ifup = e1000_ifup; /* I/F up (new IP address) callback */
|
|
|
|
dev->netdev.d_ifdown = e1000_ifdown; /* I/F down callback */
|
|
|
|
dev->netdev.d_txavail = e1000_txavail; /* New TX data callback */
|
2011-05-21 20:25:31 +02:00
|
|
|
#ifdef CONFIG_NET_IGMP
|
2014-06-29 21:03:19 +02:00
|
|
|
dev->netdev.d_addmac = e1000_addmac; /* Add multicast MAC address */
|
|
|
|
dev->netdev.d_rmmac = e1000_rmmac; /* Remove multicast MAC address */
|
2011-05-21 20:25:31 +02:00
|
|
|
#endif
|
2014-06-29 21:03:19 +02:00
|
|
|
dev->netdev.d_private = dev; /* Used to recover private state from dev */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* Create a watchdog for timing polling for and timing of transmisstions */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-06-29 21:03:19 +02:00
|
|
|
dev->txpoll = wd_create(); /* Create periodic poll timer */
|
|
|
|
dev->txtimeout = wd_create(); /* Create TX timeout timer */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* Put the interface in the down state.
|
|
|
|
* e1000 reset
|
|
|
|
*/
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000_reset(dev);
|
|
|
|
|
|
|
|
/* Read the MAC address from the hardware */
|
|
|
|
|
2014-06-29 21:03:19 +02:00
|
|
|
memcpy(dev->netdev.d_mac.ether_addr_octet, (void *)(dev->io_mem_base+E1000_RA), 6);
|
2014-02-11 01:08:49 +01:00
|
|
|
|
|
|
|
/* Register the device with the OS so that socket IOCTLs can be performed */
|
|
|
|
|
2014-11-15 15:22:51 +01:00
|
|
|
err = netdev_register(&dev->netdev, NET_LL_ETHERNET);
|
2014-02-11 01:08:49 +01:00
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
goto err2;
|
|
|
|
}
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
/* insert into e1000_list */
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
dev->next = e1000_list.next;
|
|
|
|
e1000_list.next = dev;
|
|
|
|
cprintf("bring up e1000 device: %04x %08x\n", addr, id.join);
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
return 0;
|
2011-05-21 20:25:31 +02:00
|
|
|
|
2012-11-04 16:12:55 +01:00
|
|
|
err2:
|
2014-02-11 01:08:49 +01:00
|
|
|
rgmp_memremap((uintptr_t)omem, size);
|
|
|
|
free(omem);
|
2012-11-04 16:12:55 +01:00
|
|
|
err1:
|
2014-02-11 01:08:49 +01:00
|
|
|
pci_free_irq(addr);
|
2012-11-04 16:12:55 +01:00
|
|
|
err0:
|
2014-02-11 01:08:49 +01:00
|
|
|
rgmp_memunmap(mmio_base, mmio_size);
|
2012-11-04 16:12:55 +01:00
|
|
|
error:
|
2014-09-01 01:04:02 +02:00
|
|
|
kmm_free(dev);
|
2014-02-11 01:08:49 +01:00
|
|
|
cprintf("e1000 device probe fail: %d\n", err);
|
|
|
|
return err;
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void e1000_mod_init(void)
|
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
pci_probe_device(e1000_id_table, e1000_probe);
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void e1000_mod_exit(void)
|
|
|
|
{
|
2014-02-11 01:08:49 +01:00
|
|
|
uint32_t size;
|
|
|
|
struct e1000_dev *dev;
|
|
|
|
|
|
|
|
size = CONFIG_E1000_N_TX_DESC * sizeof(struct tx_desc) +
|
|
|
|
CONFIG_E1000_N_TX_DESC * CONFIG_E1000_BUFF_SIZE +
|
|
|
|
CONFIG_E1000_N_RX_DESC * sizeof(struct rx_desc) +
|
|
|
|
CONFIG_E1000_N_RX_DESC * CONFIG_E1000_BUFF_SIZE;
|
|
|
|
size = ROUNDUP(size, PGSIZE);
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
for (dev = e1000_list.next; dev != NULL; dev = dev->next)
|
2014-02-11 01:08:49 +01:00
|
|
|
{
|
2014-06-29 21:03:19 +02:00
|
|
|
netdev_unregister(&dev->netdev);
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000_reset(dev);
|
|
|
|
wd_delete(dev->txpoll);
|
|
|
|
wd_delete(dev->txtimeout);
|
|
|
|
rgmp_memremap((uintptr_t)dev->tx_ring.desc, size);
|
|
|
|
free(dev->tx_ring.desc);
|
|
|
|
pci_free_irq(dev->pci_addr);
|
|
|
|
rgmp_memunmap((uintptr_t)dev->io_mem_base, dev->mem_size);
|
2014-09-01 01:04:02 +02:00
|
|
|
kmm_free(dev);
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
e1000_list.next = NULL;
|
2011-05-21 20:25:31 +02:00
|
|
|
}
|