2001-12-02 07:37:17 +00:00
|
|
|
/**************************************************************************
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
Copyright (c) 2001-2002 Intel Corporation
|
2001-12-02 07:37:17 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms of the Software, with or
|
|
|
|
without modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
1. Redistributions of source code of the Software may retain the above
|
|
|
|
copyright notice, this list of conditions and the following disclaimer.
|
|
|
|
|
|
|
|
2. Redistributions in binary form of the Software may 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 of the Intel Corporation nor the names of its
|
|
|
|
contributors shall 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 INTEL OR ITS 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.
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
2002-02-13 18:19:27 +00:00
|
|
|
/*$FreeBSD$*/
|
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
#include <dev/em/if_em.h>
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Set this to one to display debug statistics
|
|
|
|
*********************************************************************/
|
|
|
|
int em_display_debug_stats = 0;
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Linked list of board private structures for all NICs found
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
struct adapter *em_adapter_list = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Driver version
|
|
|
|
*********************************************************************/
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
char em_driver_version[] = "1.2.7";
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* PCI Device ID Table
|
|
|
|
*
|
|
|
|
* Used by probe to select devices to load on
|
|
|
|
* Last field stores an index into em_strings
|
|
|
|
* Last entry must be all 0s
|
|
|
|
*
|
|
|
|
* { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index }
|
|
|
|
*********************************************************************/
|
|
|
|
static em_vendor_info_t em_vendor_info_array[] =
|
|
|
|
{
|
|
|
|
/* Intel(R) PRO/1000 Network Connection */
|
|
|
|
{ 0x8086, 0x1000, PCI_ANY_ID, PCI_ANY_ID, 0 },
|
|
|
|
{ 0x8086, 0x1001, PCI_ANY_ID, PCI_ANY_ID, 0 },
|
|
|
|
{ 0x8086, 0x1004, PCI_ANY_ID, PCI_ANY_ID, 0 },
|
|
|
|
{ 0x8086, 0x1008, PCI_ANY_ID, PCI_ANY_ID, 0 },
|
|
|
|
{ 0x8086, 0x1009, PCI_ANY_ID, PCI_ANY_ID, 0 },
|
|
|
|
{ 0x8086, 0x100C, PCI_ANY_ID, PCI_ANY_ID, 0 },
|
|
|
|
{ 0x8086, 0x100D, PCI_ANY_ID, PCI_ANY_ID, 0 },
|
2002-04-06 00:36:53 +00:00
|
|
|
{ 0x8086, 0x100E, PCI_ANY_ID, PCI_ANY_ID, 0 },
|
2001-12-02 07:37:17 +00:00
|
|
|
/* required last entry */
|
|
|
|
{ 0, 0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Table of branding strings for all supported NICs.
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
static char *em_strings[] = {
|
|
|
|
"Intel(R) PRO/1000 Network Connection"
|
|
|
|
};
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Function prototypes
|
|
|
|
*********************************************************************/
|
2002-04-06 00:36:53 +00:00
|
|
|
static int em_probe(device_t);
|
|
|
|
static int em_attach(device_t);
|
|
|
|
static int em_detach(device_t);
|
|
|
|
static int em_shutdown(device_t);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_intr(void *);
|
|
|
|
static void em_start(struct ifnet *);
|
2002-04-06 00:36:53 +00:00
|
|
|
static int em_ioctl(struct ifnet *, IOCTL_CMD_TYPE, caddr_t);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_watchdog(struct ifnet *);
|
|
|
|
static void em_init(void *);
|
|
|
|
static void em_stop(void *);
|
|
|
|
static void em_media_status(struct ifnet *, struct ifmediareq *);
|
2002-04-06 00:36:53 +00:00
|
|
|
static int em_media_change(struct ifnet *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_identify_hardware(struct adapter *);
|
2002-04-06 00:36:53 +00:00
|
|
|
static int em_allocate_pci_resources(struct adapter *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_free_pci_resources(struct adapter *);
|
|
|
|
static void em_local_timer(void *);
|
2002-04-06 00:36:53 +00:00
|
|
|
static int em_hardware_init(struct adapter *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_read_mac_address(struct adapter *, u_int8_t *);
|
|
|
|
static void em_setup_interface(device_t, struct adapter *);
|
2002-04-06 00:36:53 +00:00
|
|
|
static int em_setup_transmit_structures(struct adapter *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_initialize_transmit_unit(struct adapter *);
|
2002-04-06 00:36:53 +00:00
|
|
|
static int em_setup_receive_structures(struct adapter *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_initialize_receive_unit(struct adapter *);
|
2002-04-06 00:36:53 +00:00
|
|
|
static void em_enable_intr(struct adapter *);
|
|
|
|
static void em_disable_intr(struct adapter *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_free_transmit_structures(struct adapter *);
|
|
|
|
static void em_free_receive_structures(struct adapter *);
|
|
|
|
static void em_update_stats_counters(struct adapter *);
|
|
|
|
static void em_clean_transmit_interrupts(struct adapter *);
|
2002-04-06 00:36:53 +00:00
|
|
|
static int em_allocate_receive_structures(struct adapter *);
|
|
|
|
static int em_allocate_transmit_structures(struct adapter *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_process_receive_interrupts(struct adapter *);
|
|
|
|
static void em_receive_checksum(struct adapter *,
|
2002-04-06 00:36:53 +00:00
|
|
|
struct em_rx_desc * rx_desc,
|
|
|
|
struct mbuf *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_transmit_checksum_setup(struct adapter *,
|
2002-04-06 00:36:53 +00:00
|
|
|
struct mbuf *,
|
|
|
|
struct em_tx_buffer *,
|
|
|
|
u_int32_t *,
|
|
|
|
u_int32_t *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_set_promisc(struct adapter *);
|
|
|
|
static void em_disable_promisc(struct adapter *);
|
|
|
|
static void em_set_multi(struct adapter *);
|
|
|
|
static void em_print_hw_stats(struct adapter *);
|
|
|
|
static void em_print_link_status(struct adapter *);
|
2002-04-06 00:36:53 +00:00
|
|
|
static int em_get_buf(struct em_rx_buffer *, struct adapter *,
|
|
|
|
struct mbuf *);
|
2001-12-02 07:37:17 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* FreeBSD Device Interface Entry Points
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
static device_method_t em_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, em_probe),
|
|
|
|
DEVMETHOD(device_attach, em_attach),
|
|
|
|
DEVMETHOD(device_detach, em_detach),
|
|
|
|
DEVMETHOD(device_shutdown, em_shutdown),
|
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t em_driver = {
|
|
|
|
"em", em_methods, sizeof(struct adapter ),
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t em_devclass;
|
|
|
|
DRIVER_MODULE(if_em, pci, em_driver, em_devclass, 0, 0);
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Device identification routine
|
|
|
|
*
|
|
|
|
* em_probe determines if the driver should be loaded on
|
|
|
|
* adapter based on PCI vendor/device id of the adapter.
|
|
|
|
*
|
|
|
|
* return 0 on success, positive on failure
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
static int
|
|
|
|
em_probe(device_t dev)
|
|
|
|
{
|
|
|
|
em_vendor_info_t *ent;
|
|
|
|
|
|
|
|
u_int16_t pci_vendor_id = 0;
|
|
|
|
u_int16_t pci_device_id = 0;
|
|
|
|
u_int16_t pci_subvendor_id = 0;
|
|
|
|
u_int16_t pci_subdevice_id = 0;
|
|
|
|
char adapter_name[60];
|
|
|
|
|
|
|
|
INIT_DEBUGOUT("em_probe: begin");
|
|
|
|
|
|
|
|
pci_vendor_id = pci_get_vendor(dev);
|
|
|
|
if (pci_vendor_id != EM_VENDOR_ID)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
pci_device_id = pci_get_device(dev);
|
|
|
|
pci_subvendor_id = pci_get_subvendor(dev);
|
|
|
|
pci_subdevice_id = pci_get_subdevice(dev);
|
|
|
|
|
|
|
|
ent = em_vendor_info_array;
|
|
|
|
while(ent->vendor_id != 0) {
|
|
|
|
if ((pci_vendor_id == ent->vendor_id) &&
|
|
|
|
(pci_device_id == ent->device_id) &&
|
|
|
|
|
|
|
|
((pci_subvendor_id == ent->subvendor_id) ||
|
|
|
|
(ent->subvendor_id == PCI_ANY_ID)) &&
|
|
|
|
|
|
|
|
((pci_subdevice_id == ent->subdevice_id) ||
|
|
|
|
(ent->subdevice_id == PCI_ANY_ID))) {
|
|
|
|
INIT_DEBUGOUT1("em_probe: Found PRO/1000 (pci_device_id=0x%x)",
|
|
|
|
pci_device_id);
|
|
|
|
sprintf(adapter_name, "%s, Version - %s", em_strings[ent->index],
|
|
|
|
em_driver_version);
|
|
|
|
device_set_desc_copy(dev, adapter_name);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
ent++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Device initialization routine
|
|
|
|
*
|
|
|
|
* The attach entry point is called when the driver is being loaded.
|
|
|
|
* This routine identifies the type of hardware, allocates all resources
|
|
|
|
* and initializes the hardware.
|
|
|
|
*
|
|
|
|
* return 0 on success, positive on failure
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
static int
|
|
|
|
em_attach(device_t dev)
|
|
|
|
{
|
2002-04-06 00:36:53 +00:00
|
|
|
struct adapter * adapter;
|
2001-12-02 07:37:17 +00:00
|
|
|
int s;
|
|
|
|
int tsize, rsize;
|
|
|
|
|
|
|
|
INIT_DEBUGOUT("em_attach: begin");
|
|
|
|
s = splimp();
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
/* Allocate, clear, and link in our adapter structure */
|
|
|
|
if (!(adapter = device_get_softc(dev))) {
|
|
|
|
printf("em: adapter structure allocation failed\n");
|
2001-12-02 07:37:17 +00:00
|
|
|
splx(s);
|
|
|
|
return(ENOMEM);
|
|
|
|
}
|
2002-04-06 00:36:53 +00:00
|
|
|
bzero(adapter, sizeof(struct adapter ));
|
|
|
|
adapter->dev = dev;
|
|
|
|
adapter->osdep.dev = dev;
|
|
|
|
adapter->unit = device_get_unit(dev);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
if (em_adapter_list != NULL)
|
2002-04-06 00:36:53 +00:00
|
|
|
em_adapter_list->prev = adapter;
|
|
|
|
adapter->next = em_adapter_list;
|
|
|
|
em_adapter_list = adapter;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
callout_handle_init(&adapter->timer_handle);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Determine hardware revision */
|
2002-04-06 00:36:53 +00:00
|
|
|
em_identify_hardware(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Parameters (to be read from user) */
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->num_tx_desc = MAX_TXD;
|
|
|
|
adapter->num_rx_desc = MAX_RXD;
|
|
|
|
adapter->tx_int_delay = TIDV;
|
|
|
|
adapter->rx_int_delay = RIDV;
|
|
|
|
adapter->shared.autoneg = DO_AUTO_NEG;
|
|
|
|
adapter->shared.wait_autoneg_complete = WAIT_FOR_AUTO_NEG_DEFAULT;
|
|
|
|
adapter->shared.autoneg_advertised = AUTONEG_ADV_DEFAULT;
|
|
|
|
adapter->shared.tbi_compatibility_en = TRUE;
|
|
|
|
adapter->rx_buffer_len = EM_RXBUFFER_2048;
|
|
|
|
adapter->rx_checksum = EM_ENABLE_RXCSUM_OFFLOAD;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->shared.fc_high_water = FC_DEFAULT_HI_THRESH;
|
|
|
|
adapter->shared.fc_low_water = FC_DEFAULT_LO_THRESH;
|
|
|
|
adapter->shared.fc_pause_time = FC_DEFAULT_TX_TIMER;
|
|
|
|
adapter->shared.fc_send_xon = TRUE;
|
|
|
|
adapter->shared.fc = em_fc_full;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Set the max frame size assuming standard ethernet sized frames */
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->shared.max_frame_size = ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN;
|
|
|
|
adapter->shared.min_frame_size = MINIMUM_ETHERNET_PACKET_SIZE + ETHER_CRC_LEN;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* This controls when hardware reports transmit completion status. */
|
|
|
|
if ((EM_REPORT_TX_EARLY == 0) || (EM_REPORT_TX_EARLY == 1)) {
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->shared.report_tx_early = EM_REPORT_TX_EARLY;
|
2001-12-02 07:37:17 +00:00
|
|
|
} else {
|
2002-04-06 00:36:53 +00:00
|
|
|
if(adapter->shared.mac_type < em_82543) {
|
|
|
|
adapter->shared.report_tx_early = 0;
|
2001-12-02 07:37:17 +00:00
|
|
|
} else {
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->shared.report_tx_early = 1;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (em_allocate_pci_resources(adapter)) {
|
|
|
|
printf("em%d: Allocation of PCI resources failed\n", adapter->unit);
|
|
|
|
em_free_pci_resources(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
splx(s);
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
tsize = EM_ROUNDUP(adapter->num_tx_desc *
|
2002-02-13 18:19:27 +00:00
|
|
|
sizeof(struct em_tx_desc), 4096);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Allocate Transmit Descriptor ring */
|
2002-04-06 00:36:53 +00:00
|
|
|
if (!(adapter->tx_desc_base = (struct em_tx_desc *)
|
2001-12-02 07:37:17 +00:00
|
|
|
contigmalloc(tsize, M_DEVBUF, M_NOWAIT, 0, ~0, PAGE_SIZE, 0))) {
|
2002-04-06 00:36:53 +00:00
|
|
|
printf("em%d: Unable to allocate TxDescriptor memory\n", adapter->unit);
|
|
|
|
em_free_pci_resources(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
splx(s);
|
|
|
|
return(ENOMEM);
|
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
rsize = EM_ROUNDUP(adapter->num_rx_desc *
|
2002-02-13 18:19:27 +00:00
|
|
|
sizeof(struct em_rx_desc), 4096);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Allocate Receive Descriptor ring */
|
2002-04-06 00:36:53 +00:00
|
|
|
if (!(adapter->rx_desc_base = (struct em_rx_desc *)
|
2001-12-02 07:37:17 +00:00
|
|
|
contigmalloc(rsize, M_DEVBUF, M_NOWAIT, 0, ~0, PAGE_SIZE, 0))) {
|
2002-04-06 00:36:53 +00:00
|
|
|
printf("em%d: Unable to allocate rx_desc memory\n", adapter->unit);
|
|
|
|
em_free_pci_resources(adapter);
|
|
|
|
contigfree(adapter->tx_desc_base, tsize, M_DEVBUF);
|
2001-12-02 07:37:17 +00:00
|
|
|
splx(s);
|
|
|
|
return(ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the hardware */
|
2002-04-06 00:36:53 +00:00
|
|
|
if (em_hardware_init(adapter)) {
|
|
|
|
printf("em%d: Unable to initialize the hardware\n",adapter->unit);
|
|
|
|
em_free_pci_resources(adapter);
|
|
|
|
contigfree(adapter->tx_desc_base, tsize, M_DEVBUF);
|
|
|
|
contigfree(adapter->rx_desc_base, rsize, M_DEVBUF);
|
2001-12-02 07:37:17 +00:00
|
|
|
splx(s);
|
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup OS specific network interface */
|
2002-04-06 00:36:53 +00:00
|
|
|
em_setup_interface(dev, adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Initialize statistics */
|
2002-04-06 00:36:53 +00:00
|
|
|
em_clear_hw_cntrs(&adapter->shared);
|
|
|
|
em_update_stats_counters(adapter);
|
|
|
|
adapter->shared.get_link_status = 1;
|
|
|
|
em_check_for_link(&adapter->shared);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Print the link status */
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->link_active == 1) {
|
|
|
|
em_get_speed_and_duplex(&adapter->shared, &adapter->link_speed, &adapter->link_duplex);
|
2001-12-02 07:37:17 +00:00
|
|
|
printf("em%d: Speed:%d Mbps Duplex:%s\n",
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->unit,
|
|
|
|
adapter->link_speed,
|
|
|
|
adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half");
|
2002-02-13 18:19:27 +00:00
|
|
|
}
|
2001-12-02 07:37:17 +00:00
|
|
|
else
|
2002-04-06 00:36:53 +00:00
|
|
|
printf("em%d: Speed:N/A Duplex:N/A\n", adapter->unit);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
INIT_DEBUGOUT("em_attach: end");
|
|
|
|
splx(s);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Device removal routine
|
|
|
|
*
|
|
|
|
* The detach entry point is called when the driver is being removed.
|
|
|
|
* This routine stops the adapter and deallocates all the resources
|
|
|
|
* that were allocated for driver operation.
|
|
|
|
*
|
|
|
|
* return 0 on success, positive on failure
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
static int
|
|
|
|
em_detach(device_t dev)
|
|
|
|
{
|
2002-04-06 00:36:53 +00:00
|
|
|
struct adapter * adapter = device_get_softc(dev);
|
|
|
|
struct ifnet *ifp = &adapter->interface_data.ac_if;
|
2001-12-02 07:37:17 +00:00
|
|
|
int s;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
INIT_DEBUGOUT("em_detach: begin");
|
|
|
|
s = splimp();
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
em_stop(adapter);
|
|
|
|
em_phy_hw_reset(&adapter->shared);
|
|
|
|
ether_ifdetach(&adapter->interface_data.ac_if, ETHER_BPF_SUPPORTED);
|
|
|
|
em_free_pci_resources(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
size = EM_ROUNDUP(adapter->num_tx_desc *
|
2002-02-13 18:19:27 +00:00
|
|
|
sizeof(struct em_tx_desc), 4096);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Free Transmit Descriptor ring */
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->tx_desc_base) {
|
|
|
|
contigfree(adapter->tx_desc_base, size, M_DEVBUF);
|
|
|
|
adapter->tx_desc_base = NULL;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
size = EM_ROUNDUP(adapter->num_rx_desc *
|
2002-02-13 18:19:27 +00:00
|
|
|
sizeof(struct em_rx_desc), 4096);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Free Receive Descriptor ring */
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->rx_desc_base) {
|
|
|
|
contigfree(adapter->rx_desc_base, size, M_DEVBUF);
|
|
|
|
adapter->rx_desc_base = NULL;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove from the adapter list */
|
2002-04-06 00:36:53 +00:00
|
|
|
if(em_adapter_list == adapter)
|
|
|
|
em_adapter_list = adapter->next;
|
|
|
|
if(adapter->next != NULL)
|
|
|
|
adapter->next->prev = adapter->prev;
|
|
|
|
if(adapter->prev != NULL)
|
|
|
|
adapter->prev->next = adapter->next;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
em_shutdown(device_t dev)
|
|
|
|
{
|
2002-04-06 00:36:53 +00:00
|
|
|
struct adapter * adapter = device_get_softc(dev);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Issue a global reset */
|
2002-04-06 00:36:53 +00:00
|
|
|
em_adapter_stop(&adapter->shared);
|
2001-12-02 07:37:17 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Transmit entry point
|
|
|
|
*
|
|
|
|
* em_start is called by the stack to initiate a transmit.
|
|
|
|
* The driver will remain in this routine as long as there are
|
|
|
|
* packets to transmit and transmit resources are available.
|
|
|
|
* In case resources are not available stack is notified and
|
|
|
|
* the packet is requeued.
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
static void
|
|
|
|
em_start(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
int s;
|
2002-04-06 00:36:53 +00:00
|
|
|
struct mbuf *m_head, *mp;
|
|
|
|
vm_offset_t virtual_addr;
|
2001-12-02 07:37:17 +00:00
|
|
|
u_int32_t txd_upper;
|
|
|
|
u_int32_t txd_lower;
|
2002-04-06 00:36:53 +00:00
|
|
|
struct em_tx_buffer *tx_buffer;
|
|
|
|
struct em_tx_desc *current_tx_desc = NULL;
|
|
|
|
struct adapter * adapter = ifp->if_softc;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (!adapter->link_active)
|
2001-12-02 07:37:17 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
s = splimp();
|
|
|
|
while (ifp->if_snd.ifq_head != NULL) {
|
|
|
|
|
|
|
|
IF_DEQUEUE(&ifp->if_snd, m_head);
|
|
|
|
|
|
|
|
if(m_head == NULL) break;
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->num_tx_desc_avail <= TX_CLEANUP_THRESHOLD)
|
|
|
|
em_clean_transmit_interrupts(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->num_tx_desc_avail <= TX_CLEANUP_THRESHOLD) {
|
2001-12-02 07:37:17 +00:00
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
IF_PREPEND(&ifp->if_snd, m_head);
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->no_tx_desc_avail++;
|
2001-12-02 07:37:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
tx_buffer = STAILQ_FIRST(&adapter->free_tx_buffer_list);
|
2001-12-02 07:37:17 +00:00
|
|
|
if (!tx_buffer) {
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->no_tx_buffer_avail1++;
|
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
/*
|
|
|
|
* OK so we should not get here but I've seen it so lets try to
|
|
|
|
* clean up and then try to get a SwPacket again and only break
|
|
|
|
* if we still don't get one
|
|
|
|
*/
|
2002-04-06 00:36:53 +00:00
|
|
|
em_clean_transmit_interrupts(adapter);
|
|
|
|
tx_buffer = STAILQ_FIRST(&adapter->free_tx_buffer_list);
|
2001-12-02 07:37:17 +00:00
|
|
|
if (!tx_buffer) {
|
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
IF_PREPEND(&ifp->if_snd, m_head);
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->no_tx_buffer_avail2++;
|
2001-12-02 07:37:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-04-06 00:36:53 +00:00
|
|
|
STAILQ_REMOVE_HEAD(&adapter->free_tx_buffer_list, em_tx_entry);
|
|
|
|
|
|
|
|
tx_buffer->num_tx_desc_used = 0;
|
|
|
|
tx_buffer->m_head = m_head;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
if (ifp->if_hwassist > 0) {
|
2002-04-06 00:36:53 +00:00
|
|
|
em_transmit_checksum_setup(adapter, m_head, tx_buffer, &txd_upper, &txd_lower);
|
2001-12-02 07:37:17 +00:00
|
|
|
} else {
|
|
|
|
txd_upper = 0;
|
|
|
|
txd_lower = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (mp = m_head; mp != NULL; mp = mp->m_next) {
|
|
|
|
if (mp->m_len == 0)
|
|
|
|
continue;
|
2002-04-06 00:36:53 +00:00
|
|
|
current_tx_desc = adapter->next_avail_tx_desc;
|
|
|
|
virtual_addr = mtod(mp, vm_offset_t);
|
|
|
|
current_tx_desc->buffer_addr = vtophys(virtual_addr);
|
|
|
|
|
|
|
|
current_tx_desc->lower.data = (txd_lower | mp->m_len);
|
|
|
|
current_tx_desc->upper.data = (txd_upper);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (current_tx_desc == adapter->last_tx_desc)
|
|
|
|
adapter->next_avail_tx_desc =
|
|
|
|
adapter->first_tx_desc;
|
2001-12-02 07:37:17 +00:00
|
|
|
else
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->next_avail_tx_desc++;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->num_tx_desc_avail--;
|
|
|
|
tx_buffer->num_tx_desc_used++;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
2002-04-06 00:36:53 +00:00
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
/* Put this tx_buffer at the end in the "in use" list */
|
2002-04-06 00:36:53 +00:00
|
|
|
STAILQ_INSERT_TAIL(&adapter->used_tx_buffer_list, tx_buffer, em_tx_entry);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Last Descriptor of Packet needs End Of Packet (EOP), Report Status
|
|
|
|
* (RS) and append Ethernet CRC (IFCS) bits set.
|
|
|
|
*/
|
2002-04-06 00:36:53 +00:00
|
|
|
current_tx_desc->lower.data |= (adapter->txd_cmd | E1000_TXD_CMD_EOP);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Send a copy of the frame to the BPF listener */
|
|
|
|
if (ifp->if_bpf)
|
|
|
|
bpf_mtap(ifp, m_head);
|
|
|
|
/*
|
|
|
|
* Advance the Transmit Descriptor Tail (Tdt), this tells the E1000
|
|
|
|
* that this frame is available to transmit.
|
|
|
|
*/
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, TDT, (((u_int32_t) adapter->next_avail_tx_desc -
|
|
|
|
(u_int32_t) adapter->first_tx_desc) >> 4));
|
2001-12-02 07:37:17 +00:00
|
|
|
} /* end of while loop */
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
/* Set timeout in case chip has problems transmitting */
|
|
|
|
ifp->if_timer = EM_TX_TIMEOUT;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Ioctl entry point
|
|
|
|
*
|
|
|
|
* em_ioctl is called when the user wants to configure the
|
|
|
|
* interface.
|
|
|
|
*
|
|
|
|
* return 0 on success, positive on failure
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
static int
|
|
|
|
em_ioctl(struct ifnet *ifp, IOCTL_CMD_TYPE command, caddr_t data)
|
|
|
|
{
|
2002-04-06 00:36:53 +00:00
|
|
|
int s, mask, error = 0;
|
2001-12-02 07:37:17 +00:00
|
|
|
struct ifreq *ifr = (struct ifreq *) data;
|
2002-04-06 00:36:53 +00:00
|
|
|
struct adapter * adapter = ifp->if_softc;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
s = splimp();
|
|
|
|
switch (command) {
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
case SIOCGIFADDR:
|
|
|
|
IOCTL_DEBUGOUT("ioctl rcv'd: SIOCxIFADDR (Get/Set Interface Addr)");
|
|
|
|
ether_ioctl(ifp, command, data);
|
|
|
|
break;
|
|
|
|
case SIOCSIFMTU:
|
|
|
|
IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFMTU (Set Interface MTU)");
|
|
|
|
if (ifr->ifr_mtu > MAX_JUMBO_FRAME_SIZE - ETHER_HDR_LEN) {
|
|
|
|
error = EINVAL;
|
|
|
|
} else {
|
|
|
|
ifp->if_mtu = ifr->ifr_mtu;
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->shared.max_frame_size = ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
|
|
|
|
em_init(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFFLAGS (Set Interface Flags)");
|
|
|
|
if (ifp->if_flags & IFF_UP) {
|
|
|
|
if (ifp->if_flags & IFF_RUNNING &&
|
|
|
|
ifp->if_flags & IFF_PROMISC) {
|
2002-04-06 00:36:53 +00:00
|
|
|
em_set_promisc(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
} else if (ifp->if_flags & IFF_RUNNING &&
|
|
|
|
!(ifp->if_flags & IFF_PROMISC)) {
|
2002-04-06 00:36:53 +00:00
|
|
|
em_disable_promisc(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
} else
|
2002-04-06 00:36:53 +00:00
|
|
|
em_init(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
} else {
|
|
|
|
if (ifp->if_flags & IFF_RUNNING) {
|
2002-04-06 00:36:53 +00:00
|
|
|
em_stop(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
IOCTL_DEBUGOUT("ioctl rcv'd: SIOC(ADD|DEL)MULTI");
|
|
|
|
if (ifp->if_flags & IFF_RUNNING) {
|
2002-04-06 00:36:53 +00:00
|
|
|
em_disable_intr(adapter);
|
|
|
|
em_set_multi(adapter);
|
|
|
|
if(adapter->shared.mac_type == em_82542_rev2_0)
|
|
|
|
em_initialize_receive_unit(adapter);
|
|
|
|
em_enable_intr(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
IOCTL_DEBUGOUT("ioctl rcv'd: SIOCxIFMEDIA (Get/Set Interface Media)");
|
2002-04-06 00:36:53 +00:00
|
|
|
error = ifmedia_ioctl(ifp, ifr, &adapter->media, command);
|
|
|
|
break;
|
|
|
|
case SIOCSIFCAP:
|
|
|
|
IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFCAP (Set Capabilities)");
|
|
|
|
mask = ifr->ifr_reqcap ^ ifp->if_capenable;
|
|
|
|
if (mask & IFCAP_HWCSUM) {
|
|
|
|
if (IFCAP_HWCSUM & ifp->if_capenable)
|
|
|
|
ifp->if_capenable &= ~IFCAP_HWCSUM;
|
|
|
|
else
|
|
|
|
ifp->if_capenable |= IFCAP_HWCSUM;
|
|
|
|
if (ifp->if_flags & IFF_RUNNING)
|
|
|
|
em_init(adapter);
|
|
|
|
}
|
2001-12-02 07:37:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
IOCTL_DEBUGOUT1("ioctl received: UNKNOWN (0x%d)\n", (int)command);
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_set_promisc(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
u_int32_t reg_rctl;
|
2002-04-06 00:36:53 +00:00
|
|
|
struct ifnet *ifp = &adapter->interface_data.ac_if;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
reg_rctl = E1000_READ_REG(&adapter->shared, RCTL);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
if(ifp->if_flags & IFF_PROMISC) {
|
|
|
|
reg_rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, RCTL, reg_rctl);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
else if (ifp->if_flags & IFF_ALLMULTI) {
|
|
|
|
reg_rctl |= E1000_RCTL_MPE;
|
|
|
|
reg_rctl &= ~E1000_RCTL_UPE;
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, RCTL, reg_rctl);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_disable_promisc(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
|
|
|
u_int32_t reg_rctl;
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
reg_rctl = E1000_READ_REG(&adapter->shared, RCTL);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
reg_rctl &= (~E1000_RCTL_UPE);
|
|
|
|
reg_rctl &= (~E1000_RCTL_MPE);
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, RCTL, reg_rctl);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Multicast Update
|
|
|
|
*
|
|
|
|
* This routine is called whenever multicast address list is updated.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_set_multi(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
|
|
|
u_int32_t reg_rctl = 0;
|
|
|
|
u_int8_t mta[MAX_NUM_MULTICAST_ADDRESSES * ETH_LENGTH_OF_ADDRESS];
|
2002-04-06 00:36:53 +00:00
|
|
|
u_int16_t pci_cmd_word;
|
2002-02-13 18:19:27 +00:00
|
|
|
struct ifmultiaddr *ifma;
|
|
|
|
int mcnt = 0;
|
2002-04-06 00:36:53 +00:00
|
|
|
struct ifnet *ifp = &adapter->interface_data.ac_if;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-02-13 18:19:27 +00:00
|
|
|
IOCTL_DEBUGOUT("em_set_multi: begin");
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if(adapter->shared.mac_type == em_82542_rev2_0) {
|
|
|
|
reg_rctl = E1000_READ_REG(&adapter->shared, RCTL);
|
|
|
|
if(adapter->shared.pci_cmd_word & CMD_MEM_WRT_INVALIDATE) {
|
|
|
|
pci_cmd_word = adapter->shared.pci_cmd_word & ~CMD_MEM_WRT_INVALIDATE;
|
|
|
|
pci_write_config(adapter->dev, PCIR_COMMAND, pci_cmd_word, 2);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
reg_rctl |= E1000_RCTL_RST;
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, RCTL, reg_rctl);
|
2002-02-13 18:19:27 +00:00
|
|
|
msec_delay(5);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
2002-02-13 18:19:27 +00:00
|
|
|
#if __FreeBSD_version < 500000
|
|
|
|
LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
|
|
|
|
#else
|
|
|
|
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
|
|
|
|
#endif
|
|
|
|
if (ifma->ifma_addr->sa_family != AF_LINK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
|
|
|
|
&mta[mcnt*ETH_LENGTH_OF_ADDRESS], ETH_LENGTH_OF_ADDRESS);
|
|
|
|
mcnt++;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
2002-02-13 18:19:27 +00:00
|
|
|
if (mcnt > MAX_NUM_MULTICAST_ADDRESSES) {
|
2002-04-06 00:36:53 +00:00
|
|
|
reg_rctl = E1000_READ_REG(&adapter->shared, RCTL);
|
2001-12-02 07:37:17 +00:00
|
|
|
reg_rctl |= E1000_RCTL_MPE;
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, RCTL, reg_rctl);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
else
|
2002-04-06 00:36:53 +00:00
|
|
|
em_mc_addr_list_update(&adapter->shared, mta, mcnt, 0);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if(adapter->shared.mac_type == em_82542_rev2_0) {
|
|
|
|
reg_rctl = E1000_READ_REG(&adapter->shared, RCTL);
|
2001-12-02 07:37:17 +00:00
|
|
|
reg_rctl &= ~E1000_RCTL_RST;
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, RCTL, reg_rctl);
|
2002-02-13 18:19:27 +00:00
|
|
|
msec_delay(5);
|
2002-04-06 00:36:53 +00:00
|
|
|
if(adapter->shared.pci_cmd_word & CMD_MEM_WRT_INVALIDATE) {
|
|
|
|
pci_write_config(adapter->dev, PCIR_COMMAND, adapter->shared.pci_cmd_word, 2);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-13 18:19:27 +00:00
|
|
|
return;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Watchdog entry point
|
|
|
|
*
|
|
|
|
* This routine is called whenever hardware quits transmitting.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
static void
|
|
|
|
em_watchdog(struct ifnet *ifp)
|
|
|
|
{
|
2002-04-06 00:36:53 +00:00
|
|
|
struct adapter * adapter;
|
|
|
|
adapter = ifp->if_softc;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* If we are in this routine because of pause frames, then
|
|
|
|
* don't reset the hardware.
|
|
|
|
*/
|
2002-04-06 00:36:53 +00:00
|
|
|
if(E1000_READ_REG(&adapter->shared, STATUS) & E1000_STATUS_TXOFF) {
|
2001-12-02 07:37:17 +00:00
|
|
|
ifp->if_timer = EM_TX_TIMEOUT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
printf("em%d: watchdog timeout -- resetting\n", adapter->unit);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
em_stop(adapter);
|
|
|
|
em_init(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Timer routine
|
|
|
|
*
|
|
|
|
* This routine checks for link status and updates statistics.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
static void
|
|
|
|
em_local_timer(void *arg)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
struct ifnet *ifp;
|
2002-04-06 00:36:53 +00:00
|
|
|
struct adapter * adapter = arg;
|
|
|
|
ifp = &adapter->interface_data.ac_if;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
s = splimp();
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
em_check_for_link(&adapter->shared);
|
|
|
|
em_print_link_status(adapter);
|
|
|
|
em_update_stats_counters(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
if(em_display_debug_stats && ifp->if_flags & IFF_RUNNING) {
|
2002-04-06 00:36:53 +00:00
|
|
|
em_print_hw_stats(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->timer_handle = timeout(em_local_timer, adapter, 2*hz);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_print_link_status(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-04-06 00:36:53 +00:00
|
|
|
if(E1000_READ_REG(&adapter->shared, STATUS) & E1000_STATUS_LU) {
|
|
|
|
if(adapter->link_active == 0) {
|
|
|
|
em_get_speed_and_duplex(&adapter->shared, &adapter->link_speed, &adapter->link_duplex);
|
2001-12-02 07:37:17 +00:00
|
|
|
printf("em%d: Link is up %d Mbps %s\n",
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->unit,
|
|
|
|
adapter->link_speed,
|
|
|
|
((adapter->link_duplex == FULL_DUPLEX) ?
|
2001-12-02 07:37:17 +00:00
|
|
|
"Full Duplex" : "Half Duplex"));
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->link_active = 1;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-04-06 00:36:53 +00:00
|
|
|
if(adapter->link_active == 1) {
|
|
|
|
adapter->link_speed = 0;
|
|
|
|
adapter->link_duplex = 0;
|
|
|
|
printf("em%d: Link is Down\n", adapter->unit);
|
|
|
|
adapter->link_active = 0;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Init entry point
|
|
|
|
*
|
|
|
|
* This routine is used in two ways. It is used by the stack as
|
|
|
|
* init entry point in network interface structure. It is also used
|
|
|
|
* by the driver as a hw/sw initialization routine to get to a
|
|
|
|
* consistent state.
|
|
|
|
*
|
|
|
|
* return 0 on success, positive on failure
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
static void
|
|
|
|
em_init(void *arg)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
struct ifnet *ifp;
|
2002-04-06 00:36:53 +00:00
|
|
|
struct adapter * adapter = arg;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
INIT_DEBUGOUT("em_init: begin");
|
|
|
|
|
|
|
|
s = splimp();
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
em_stop(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Initialize the hardware */
|
2002-04-06 00:36:53 +00:00
|
|
|
if (em_hardware_init(adapter)) {
|
|
|
|
printf("em%d: Unable to initialize the hardware\n", adapter->unit);
|
2001-12-02 07:37:17 +00:00
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->shared.adapter_stopped = FALSE;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Prepare transmit descriptors and buffers */
|
2002-04-06 00:36:53 +00:00
|
|
|
if (em_setup_transmit_structures(adapter)) {
|
|
|
|
printf("em%d: Could not setup transmit structures\n", adapter->unit);
|
|
|
|
em_stop(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
2002-04-06 00:36:53 +00:00
|
|
|
em_initialize_transmit_unit(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Setup Multicast table */
|
2002-04-06 00:36:53 +00:00
|
|
|
em_set_multi(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Prepare receive descriptors and buffers */
|
2002-04-06 00:36:53 +00:00
|
|
|
if (em_setup_receive_structures(adapter)) {
|
|
|
|
printf("em%d: Could not setup receive structures\n", adapter->unit);
|
|
|
|
em_stop(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
2002-04-06 00:36:53 +00:00
|
|
|
em_initialize_receive_unit(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
ifp = &adapter->interface_data.ac_if;
|
2001-12-02 07:37:17 +00:00
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if(adapter->shared.mac_type >= em_82543) {
|
|
|
|
if (ifp->if_capenable & IFCAP_TXCSUM)
|
|
|
|
ifp->if_hwassist = EM_CHECKSUM_FEATURES;
|
|
|
|
}
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->timer_handle = timeout(em_local_timer, adapter, 2*hz);
|
|
|
|
em_clear_hw_cntrs(&adapter->shared);
|
|
|
|
em_enable_intr(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* This routine disables all traffic on the adapter by issuing a
|
|
|
|
* global reset on the MAC and deallocates TX/RX buffers.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
static void
|
|
|
|
em_stop(void *arg)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
2002-04-06 00:36:53 +00:00
|
|
|
struct adapter * adapter = arg;
|
|
|
|
ifp = &adapter->interface_data.ac_if;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
INIT_DEBUGOUT("em_stop: begin\n");
|
2002-04-06 00:36:53 +00:00
|
|
|
em_disable_intr(adapter);
|
|
|
|
em_adapter_stop(&adapter->shared);
|
|
|
|
untimeout(em_local_timer, adapter, adapter->timer_handle);
|
|
|
|
em_free_transmit_structures(adapter);
|
|
|
|
em_free_receive_structures(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Tell the stack that the interface is no longer active */
|
|
|
|
ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Interrupt Service routine
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
static void
|
|
|
|
em_intr(void *arg)
|
|
|
|
{
|
2002-04-06 00:36:53 +00:00
|
|
|
u_int32_t loop_cnt = EM_MAX_INTR;
|
|
|
|
u_int32_t reg_icr;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct adapter *adapter = arg;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
ifp = &adapter->interface_data.ac_if;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
em_disable_intr(adapter);
|
|
|
|
while(loop_cnt > 0 && (reg_icr = E1000_READ_REG(&adapter->shared, ICR)) != 0) {
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Link status change */
|
2002-04-06 00:36:53 +00:00
|
|
|
if(reg_icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
|
|
|
|
untimeout(em_local_timer, adapter, adapter->timer_handle);
|
|
|
|
adapter->shared.get_link_status = 1;
|
|
|
|
em_check_for_link(&adapter->shared);
|
|
|
|
em_print_link_status(adapter);
|
|
|
|
adapter->timer_handle = timeout(em_local_timer, adapter, 2*hz);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_RUNNING) {
|
2002-04-06 00:36:53 +00:00
|
|
|
em_process_receive_interrupts(adapter);
|
|
|
|
em_clean_transmit_interrupts(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
2002-04-06 00:36:53 +00:00
|
|
|
loop_cnt--;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
em_enable_intr(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
if(ifp->if_flags & IFF_RUNNING && ifp->if_snd.ifq_head != NULL)
|
|
|
|
em_start(ifp);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Media Ioctl callback
|
|
|
|
*
|
|
|
|
* This routine is called whenever the user queries the status of
|
|
|
|
* the interface using ifconfig.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
|
|
|
em_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
|
|
|
|
{
|
2002-04-06 00:36:53 +00:00
|
|
|
struct adapter * adapter = ifp->if_softc;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
INIT_DEBUGOUT("em_media_status: begin");
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
em_check_for_link(&adapter->shared);
|
|
|
|
if(E1000_READ_REG(&adapter->shared, STATUS) & E1000_STATUS_LU) {
|
|
|
|
if(adapter->link_active == 0) {
|
|
|
|
em_get_speed_and_duplex(&adapter->shared, &adapter->link_speed, &adapter->link_duplex);
|
|
|
|
adapter->link_active = 1;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2002-04-06 00:36:53 +00:00
|
|
|
if(adapter->link_active == 1) {
|
|
|
|
adapter->link_speed = 0;
|
|
|
|
adapter->link_duplex = 0;
|
|
|
|
adapter->link_active = 0;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ifmr->ifm_status = IFM_AVALID;
|
|
|
|
ifmr->ifm_active = IFM_ETHER;
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (!adapter->link_active)
|
2001-12-02 07:37:17 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
ifmr->ifm_status |= IFM_ACTIVE;
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->shared.media_type == em_media_type_fiber) {
|
2001-12-02 07:37:17 +00:00
|
|
|
ifmr->ifm_active |= IFM_1000_SX | IFM_FDX;
|
|
|
|
} else {
|
2002-04-06 00:36:53 +00:00
|
|
|
switch (adapter->link_speed) {
|
2001-12-02 07:37:17 +00:00
|
|
|
case 10:
|
|
|
|
ifmr->ifm_active |= IFM_10_T;
|
|
|
|
break;
|
|
|
|
case 100:
|
|
|
|
ifmr->ifm_active |= IFM_100_TX;
|
|
|
|
break;
|
|
|
|
case 1000:
|
|
|
|
ifmr->ifm_active |= IFM_1000_TX;
|
|
|
|
break;
|
|
|
|
}
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->link_duplex == FULL_DUPLEX)
|
2001-12-02 07:37:17 +00:00
|
|
|
ifmr->ifm_active |= IFM_FDX;
|
|
|
|
else
|
|
|
|
ifmr->ifm_active |= IFM_HDX;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Media Ioctl callback
|
|
|
|
*
|
|
|
|
* This routine is called when the user changes speed/duplex using
|
|
|
|
* media/mediopt option with ifconfig.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static int
|
|
|
|
em_media_change(struct ifnet *ifp)
|
|
|
|
{
|
2002-04-06 00:36:53 +00:00
|
|
|
struct adapter * adapter = ifp->if_softc;
|
|
|
|
struct ifmedia *ifm = &adapter->media;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
INIT_DEBUGOUT("em_media_change: begin");
|
|
|
|
|
|
|
|
if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
|
|
|
|
return(EINVAL);
|
|
|
|
|
|
|
|
switch(IFM_SUBTYPE(ifm->ifm_media)) {
|
|
|
|
case IFM_AUTO:
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->shared.autoneg)
|
2001-12-02 07:37:17 +00:00
|
|
|
return 0;
|
|
|
|
else {
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->shared.autoneg = DO_AUTO_NEG;
|
|
|
|
adapter->shared.autoneg_advertised = AUTONEG_ADV_DEFAULT;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IFM_1000_SX:
|
|
|
|
case IFM_1000_TX:
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->shared.autoneg = DO_AUTO_NEG;
|
|
|
|
adapter->shared.autoneg_advertised = ADVERTISE_1000_FULL;
|
2001-12-02 07:37:17 +00:00
|
|
|
break;
|
|
|
|
case IFM_100_TX:
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->shared.autoneg = FALSE;
|
|
|
|
adapter->shared.autoneg_advertised = 0;
|
2001-12-02 07:37:17 +00:00
|
|
|
if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX)
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->shared.forced_speed_duplex = em_100_full;
|
2001-12-02 07:37:17 +00:00
|
|
|
else
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->shared.forced_speed_duplex = em_100_half;
|
2001-12-02 07:37:17 +00:00
|
|
|
break;
|
|
|
|
case IFM_10_T:
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->shared.autoneg = FALSE;
|
|
|
|
adapter->shared.autoneg_advertised = 0;
|
2001-12-02 07:37:17 +00:00
|
|
|
if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX)
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->shared.forced_speed_duplex = em_10_full;
|
2001-12-02 07:37:17 +00:00
|
|
|
else
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->shared.forced_speed_duplex = em_10_half;
|
2001-12-02 07:37:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
2002-04-06 00:36:53 +00:00
|
|
|
printf("em%d: Unsupported media type\n", adapter->unit);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
em_init(adapter);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
/* Section end: Other registered entry points */
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Determine hardware revision.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_identify_hardware(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-04-06 00:36:53 +00:00
|
|
|
device_t dev = adapter->dev;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Make sure our PCI config space has the necessary stuff set */
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->shared.pci_cmd_word = pci_read_config(dev, PCIR_COMMAND, 2);
|
|
|
|
if (!((adapter->shared.pci_cmd_word & PCIM_CMD_BUSMASTEREN) &&
|
|
|
|
(adapter->shared.pci_cmd_word & PCIM_CMD_MEMEN))) {
|
2002-02-13 18:19:27 +00:00
|
|
|
printf("em%d: Memory Access and/or Bus Master bits were not set!\n",
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->unit);
|
|
|
|
adapter->shared.pci_cmd_word |= (PCIM_CMD_BUSMASTEREN | PCIM_CMD_MEMEN);
|
|
|
|
pci_write_config(dev, PCIR_COMMAND, adapter->shared.pci_cmd_word, 2);
|
2002-02-13 18:19:27 +00:00
|
|
|
}
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Save off the information about this board */
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->shared.vendor_id = pci_get_vendor(dev);
|
|
|
|
adapter->shared.device_id = pci_get_device(dev);
|
|
|
|
adapter->shared.revision_id = pci_read_config(dev, PCIR_REVID, 1);
|
|
|
|
adapter->shared.subsystem_vendor_id = pci_read_config(dev, PCIR_SUBVEND_0, 2);
|
|
|
|
adapter->shared.subsystem_id = pci_read_config(dev, PCIR_SUBDEV_0, 2);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Set MacType, etc. based on this PCI info */
|
2002-04-06 00:36:53 +00:00
|
|
|
switch (adapter->shared.device_id) {
|
|
|
|
case E1000_DEV_ID_82542:
|
|
|
|
adapter->shared.mac_type = (adapter->shared.revision_id == 3) ?
|
2002-02-13 18:19:27 +00:00
|
|
|
em_82542_rev2_1 : em_82542_rev2_0;
|
2001-12-02 07:37:17 +00:00
|
|
|
break;
|
2002-04-06 00:36:53 +00:00
|
|
|
case E1000_DEV_ID_82543GC_FIBER:
|
|
|
|
case E1000_DEV_ID_82543GC_COPPER:
|
|
|
|
adapter->shared.mac_type = em_82543;
|
2001-12-02 07:37:17 +00:00
|
|
|
break;
|
2002-04-06 00:36:53 +00:00
|
|
|
case E1000_DEV_ID_82544EI_FIBER:
|
|
|
|
case E1000_DEV_ID_82544EI_COPPER:
|
|
|
|
case E1000_DEV_ID_82544GC_COPPER:
|
|
|
|
case E1000_DEV_ID_82544GC_LOM:
|
|
|
|
adapter->shared.mac_type = em_82544;
|
2001-12-02 07:37:17 +00:00
|
|
|
break;
|
2002-04-06 00:36:53 +00:00
|
|
|
case E1000_DEV_ID_82540EM:
|
|
|
|
adapter->shared.mac_type = em_82540;
|
2001-12-02 07:37:17 +00:00
|
|
|
default:
|
2002-04-06 00:36:53 +00:00
|
|
|
INIT_DEBUGOUT1("Unknown device id 0x%x", adapter->shared.device_id);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-04-06 00:36:53 +00:00
|
|
|
em_allocate_pci_resources(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
|
|
|
int resource_id = EM_MMBA;
|
2002-04-06 00:36:53 +00:00
|
|
|
device_t dev = adapter->dev;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->res_memory = bus_alloc_resource(dev, SYS_RES_MEMORY,
|
2001-12-02 07:37:17 +00:00
|
|
|
&resource_id, 0, ~0, 1,
|
|
|
|
RF_ACTIVE);
|
2002-04-06 00:36:53 +00:00
|
|
|
if (!(adapter->res_memory)) {
|
|
|
|
printf("em%d: Unable to allocate bus resource: memory\n", adapter->unit);
|
2001-12-02 07:37:17 +00:00
|
|
|
return(ENXIO);
|
|
|
|
}
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->osdep.bus_space_tag = rman_get_bustag(adapter->res_memory);
|
|
|
|
adapter->osdep.bus_space_handle = rman_get_bushandle(adapter->res_memory);
|
|
|
|
adapter->shared.hw_addr = (uint8_t *)adapter->osdep.bus_space_handle;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
resource_id = 0x0;
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->res_interrupt = bus_alloc_resource(dev, SYS_RES_IRQ,
|
2001-12-02 07:37:17 +00:00
|
|
|
&resource_id, 0, ~0, 1,
|
|
|
|
RF_SHAREABLE | RF_ACTIVE);
|
2002-04-06 00:36:53 +00:00
|
|
|
if (!(adapter->res_interrupt)) {
|
|
|
|
printf("em%d: Unable to allocate bus resource: interrupt\n", adapter->unit);
|
2001-12-02 07:37:17 +00:00
|
|
|
return(ENXIO);
|
|
|
|
}
|
2002-04-06 00:36:53 +00:00
|
|
|
if (bus_setup_intr(dev, adapter->res_interrupt, INTR_TYPE_NET,
|
|
|
|
(void (*)(void *)) em_intr, adapter,
|
|
|
|
&adapter->int_handler_tag)) {
|
|
|
|
printf("em%d: Error registering interrupt handler!\n", adapter->unit);
|
2001-12-02 07:37:17 +00:00
|
|
|
return(ENXIO);
|
|
|
|
}
|
2002-02-13 18:19:27 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->shared.back = &adapter->osdep;
|
2002-02-13 18:19:27 +00:00
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_free_pci_resources(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-04-06 00:36:53 +00:00
|
|
|
device_t dev = adapter->dev;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if(adapter->res_interrupt != NULL) {
|
|
|
|
bus_teardown_intr(dev, adapter->res_interrupt, adapter->int_handler_tag);
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, 0, adapter->res_interrupt);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->res_memory != NULL) {
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, EM_MMBA, adapter->res_memory);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Initialize the hardware to a configuration as specified by the
|
2002-04-06 00:36:53 +00:00
|
|
|
* adapter structure. The controller is reset, the EEPROM is
|
2001-12-02 07:37:17 +00:00
|
|
|
* verified, the MAC address is set, then the shared initialization
|
|
|
|
* routines are called.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static int
|
2002-04-06 00:36:53 +00:00
|
|
|
em_hardware_init(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
|
|
|
/* Issue a global reset */
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->shared.adapter_stopped = FALSE;
|
|
|
|
em_adapter_stop(&adapter->shared);
|
|
|
|
adapter->shared.adapter_stopped = FALSE;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Make sure we have a good EEPROM before we read from it */
|
2002-04-06 00:36:53 +00:00
|
|
|
if (!em_validate_eeprom_checksum(&adapter->shared)) {
|
|
|
|
printf("em%d: The EEPROM Checksum Is Not Valid\n", adapter->unit);
|
2001-12-02 07:37:17 +00:00
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
/* Copy the permanent MAC address and part number out of the EEPROM */
|
2002-04-06 00:36:53 +00:00
|
|
|
em_read_mac_address(adapter, adapter->interface_data.ac_enaddr);
|
|
|
|
memcpy(adapter->shared.mac_addr, adapter->interface_data.ac_enaddr,
|
2001-12-02 07:37:17 +00:00
|
|
|
ETH_LENGTH_OF_ADDRESS);
|
2002-04-06 00:36:53 +00:00
|
|
|
em_read_part_num(&adapter->shared, &(adapter->part_num));
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (!em_init_hw(&adapter->shared)) {
|
|
|
|
printf("em%d: Hardware Initialization Failed", adapter->unit);
|
2001-12-02 07:37:17 +00:00
|
|
|
return EIO;
|
|
|
|
}
|
2002-02-13 18:19:27 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
em_check_for_link(&adapter->shared);
|
|
|
|
if (E1000_READ_REG(&adapter->shared, STATUS) & E1000_STATUS_LU)
|
|
|
|
adapter->link_active = 1;
|
2001-12-02 07:37:17 +00:00
|
|
|
else
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->link_active = 0;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->link_active) {
|
|
|
|
em_get_speed_and_duplex(&adapter->shared, &adapter->link_speed, &adapter->link_duplex);
|
2001-12-02 07:37:17 +00:00
|
|
|
} else {
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->link_speed = 0;
|
|
|
|
adapter->link_duplex = 0;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_read_mac_address(struct adapter * adapter, u_int8_t * NodeAddress)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
|
|
|
u_int16_t EepromWordValue;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
|
|
|
|
EepromWordValue =
|
2002-04-06 00:36:53 +00:00
|
|
|
em_read_eeprom(&adapter->shared, EEPROM_NODE_ADDRESS_BYTE_0 + (i / 2));
|
2001-12-02 07:37:17 +00:00
|
|
|
NodeAddress[i] = (uint8_t) (EepromWordValue & 0x00FF);
|
|
|
|
NodeAddress[i + 1] = (uint8_t) (EepromWordValue >> 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Setup networking device structure and register an interface.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_setup_interface(device_t dev, struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
|
|
|
INIT_DEBUGOUT("em_setup_interface: begin");
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
ifp = &adapter->interface_data.ac_if;
|
|
|
|
ifp->if_unit = adapter->unit;
|
2001-12-02 07:37:17 +00:00
|
|
|
ifp->if_name = "em";
|
|
|
|
ifp->if_mtu = ETHERMTU;
|
|
|
|
ifp->if_output = ether_output;
|
|
|
|
ifp->if_baudrate = 1000000000;
|
|
|
|
ifp->if_init = em_init;
|
2002-04-06 00:36:53 +00:00
|
|
|
ifp->if_softc = adapter;
|
2001-12-02 07:37:17 +00:00
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
|
|
|
ifp->if_ioctl = em_ioctl;
|
|
|
|
ifp->if_start = em_start;
|
|
|
|
ifp->if_watchdog = em_watchdog;
|
2002-04-06 00:36:53 +00:00
|
|
|
ifp->if_snd.ifq_maxlen = adapter->num_tx_desc - 1;
|
2001-12-02 07:37:17 +00:00
|
|
|
ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->shared.mac_type >= em_82543) {
|
|
|
|
ifp->if_capabilities = IFCAP_HWCSUM;
|
|
|
|
ifp->if_capenable = ifp->if_capabilities;
|
|
|
|
}
|
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
/*
|
|
|
|
* Specify the media types supported by this adapter and register
|
|
|
|
* callbacks to update media and link information
|
|
|
|
*/
|
2002-04-06 00:36:53 +00:00
|
|
|
ifmedia_init(&adapter->media, IFM_IMASK, em_media_change,
|
2001-12-02 07:37:17 +00:00
|
|
|
em_media_status);
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->shared.media_type == em_media_type_fiber) {
|
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_SX | IFM_FDX, 0,
|
2001-12-02 07:37:17 +00:00
|
|
|
NULL);
|
2002-04-06 00:36:53 +00:00
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_SX , 0, NULL);
|
2001-12-02 07:37:17 +00:00
|
|
|
} else {
|
2002-04-06 00:36:53 +00:00
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_10_T, 0, NULL);
|
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_10_T | IFM_FDX, 0,
|
2001-12-02 07:37:17 +00:00
|
|
|
NULL);
|
2002-04-06 00:36:53 +00:00
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_100_TX, 0, NULL);
|
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_100_TX | IFM_FDX, 0,
|
2001-12-02 07:37:17 +00:00
|
|
|
NULL);
|
2002-04-06 00:36:53 +00:00
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_TX | IFM_FDX, 0,
|
2001-12-02 07:37:17 +00:00
|
|
|
NULL);
|
2002-04-06 00:36:53 +00:00
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_TX, 0, NULL);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
2002-04-06 00:36:53 +00:00
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL);
|
|
|
|
ifmedia_set(&adapter->media, IFM_ETHER | IFM_AUTO);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Allocate memory for tx_buffer structures. The tx_buffer stores all
|
|
|
|
* the information needed to transmit a packet on the wire.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static int
|
2002-04-06 00:36:53 +00:00
|
|
|
em_allocate_transmit_structures(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-04-06 00:36:53 +00:00
|
|
|
if (!(adapter->tx_buffer_area =
|
2001-12-02 07:37:17 +00:00
|
|
|
(struct em_tx_buffer *) malloc(sizeof(struct em_tx_buffer) *
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->num_tx_desc, M_DEVBUF,
|
2001-12-02 07:37:17 +00:00
|
|
|
M_NOWAIT))) {
|
2002-04-06 00:36:53 +00:00
|
|
|
printf("em%d: Unable to allocate tx_buffer memory\n", adapter->unit);
|
2001-12-02 07:37:17 +00:00
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
bzero(adapter->tx_buffer_area,
|
|
|
|
sizeof(struct em_tx_buffer) * adapter->num_tx_desc);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Allocate and initialize transmit structures.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static int
|
2002-04-06 00:36:53 +00:00
|
|
|
em_setup_transmit_structures(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
|
|
|
struct em_tx_buffer *tx_buffer;
|
|
|
|
int i;
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (em_allocate_transmit_structures(adapter))
|
2001-12-02 07:37:17 +00:00
|
|
|
return ENOMEM;
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->first_tx_desc = adapter->tx_desc_base;
|
|
|
|
adapter->last_tx_desc =
|
|
|
|
adapter->first_tx_desc + (adapter->num_tx_desc - 1);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
STAILQ_INIT(&adapter->free_tx_buffer_list);
|
|
|
|
STAILQ_INIT(&adapter->used_tx_buffer_list);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
tx_buffer = adapter->tx_buffer_area;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Setup the linked list of the tx_buffer's */
|
2002-04-06 00:36:53 +00:00
|
|
|
for (i = 0; i < adapter->num_tx_desc; i++, tx_buffer++) {
|
2001-12-02 07:37:17 +00:00
|
|
|
bzero((void *) tx_buffer, sizeof(struct em_tx_buffer));
|
2002-04-06 00:36:53 +00:00
|
|
|
STAILQ_INSERT_TAIL(&adapter->free_tx_buffer_list, tx_buffer, em_tx_entry);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
bzero((void *) adapter->first_tx_desc,
|
|
|
|
(sizeof(struct em_tx_desc)) * adapter->num_tx_desc);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Setup TX descriptor pointers */
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->next_avail_tx_desc = adapter->first_tx_desc;
|
|
|
|
adapter->oldest_used_tx_desc = adapter->first_tx_desc;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Set number of descriptors available */
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->num_tx_desc_avail = adapter->num_tx_desc;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Set checksum context */
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->active_checksum_context = OFFLOAD_NONE;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Enable transmit unit.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_initialize_transmit_unit(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
|
|
|
u_int32_t reg_tctl;
|
|
|
|
u_int32_t reg_tipg = 0;
|
|
|
|
|
|
|
|
/* Setup the Base and Length of the Tx Descriptor Ring */
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, TDBAL, vtophys((vm_offset_t) adapter->tx_desc_base));
|
|
|
|
E1000_WRITE_REG(&adapter->shared, TDBAH, 0);
|
|
|
|
E1000_WRITE_REG(&adapter->shared, TDLEN, adapter->num_tx_desc *
|
2002-02-13 18:19:27 +00:00
|
|
|
sizeof(struct em_tx_desc));
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Setup the HW Tx Head and Tail descriptor pointers */
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, TDH, 0);
|
|
|
|
E1000_WRITE_REG(&adapter->shared, TDT, 0);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
HW_DEBUGOUT2("Base = %x, Length = %x\n", E1000_READ_REG(&adapter->shared, TDBAL),
|
|
|
|
E1000_READ_REG(&adapter->shared, TDLEN));
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Set the default values for the Tx Inter Packet Gap timer */
|
2002-04-06 00:36:53 +00:00
|
|
|
switch (adapter->shared.mac_type) {
|
2002-02-13 18:19:27 +00:00
|
|
|
case em_82543:
|
|
|
|
case em_82544:
|
2002-04-06 00:36:53 +00:00
|
|
|
case em_82540:
|
|
|
|
if (adapter->shared.media_type == em_media_type_fiber)
|
2002-02-13 18:19:27 +00:00
|
|
|
reg_tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
|
2001-12-02 07:37:17 +00:00
|
|
|
else
|
2002-02-13 18:19:27 +00:00
|
|
|
reg_tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
|
|
|
|
reg_tipg |= DEFAULT_82543_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
|
|
|
|
reg_tipg |= DEFAULT_82543_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
|
2001-12-02 07:37:17 +00:00
|
|
|
break;
|
2002-02-13 18:19:27 +00:00
|
|
|
case em_82542_rev2_0:
|
|
|
|
case em_82542_rev2_1:
|
|
|
|
reg_tipg = DEFAULT_82542_TIPG_IPGT;
|
|
|
|
reg_tipg |= DEFAULT_82542_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
|
|
|
|
reg_tipg |= DEFAULT_82542_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
|
2001-12-02 07:37:17 +00:00
|
|
|
break;
|
2002-02-13 18:19:27 +00:00
|
|
|
default:
|
2002-04-06 00:36:53 +00:00
|
|
|
printf("em%d: Invalid mac type detected\n", adapter->unit);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, TIPG, reg_tipg);
|
|
|
|
E1000_WRITE_REG(&adapter->shared, TIDV, adapter->tx_int_delay);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Program the Transmit Control Register */
|
|
|
|
reg_tctl = E1000_TCTL_PSP | E1000_TCTL_EN |
|
|
|
|
(E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->link_duplex == 1) {
|
2001-12-02 07:37:17 +00:00
|
|
|
reg_tctl |= E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT;
|
|
|
|
} else {
|
|
|
|
reg_tctl |= E1000_HDX_COLLISION_DISTANCE << E1000_COLD_SHIFT;
|
|
|
|
}
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, TCTL, reg_tctl);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Setup Transmit Descriptor Settings for this adapter */
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->txd_cmd = E1000_TXD_CMD_IFCS;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if(adapter->tx_int_delay > 0)
|
|
|
|
adapter->txd_cmd |= E1000_TXD_CMD_IDE;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if(adapter->shared.report_tx_early == 1)
|
|
|
|
adapter->txd_cmd |= E1000_TXD_CMD_RS;
|
2001-12-02 07:37:17 +00:00
|
|
|
else
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->txd_cmd |= E1000_TXD_CMD_RPS;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Free all transmit related data structures.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_free_transmit_structures(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
|
|
|
struct em_tx_buffer *tx_buffer;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
INIT_DEBUGOUT("free_transmit_structures: begin");
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->tx_buffer_area != NULL) {
|
|
|
|
tx_buffer = adapter->tx_buffer_area;
|
|
|
|
for (i = 0; i < adapter->num_tx_desc; i++, tx_buffer++) {
|
|
|
|
if (tx_buffer->m_head != NULL)
|
|
|
|
m_freem(tx_buffer->m_head);
|
|
|
|
tx_buffer->m_head = NULL;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->tx_buffer_area != NULL) {
|
|
|
|
free(adapter->tx_buffer_area, M_DEVBUF);
|
|
|
|
adapter->tx_buffer_area = NULL;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* The offload context needs to be set when we transfer the first
|
|
|
|
* packet of a particular protocol (TCP/UDP). We change the
|
|
|
|
* context only if the protocol type changes.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_transmit_checksum_setup(struct adapter * adapter,
|
2001-12-02 07:37:17 +00:00
|
|
|
struct mbuf *mp,
|
|
|
|
struct em_tx_buffer *tx_buffer,
|
|
|
|
u_int32_t *txd_upper,
|
|
|
|
u_int32_t *txd_lower)
|
|
|
|
{
|
2002-02-13 18:19:27 +00:00
|
|
|
struct em_context_desc *TXD;
|
2002-04-06 00:36:53 +00:00
|
|
|
struct em_tx_desc * current_tx_desc;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
if (mp->m_pkthdr.csum_flags) {
|
|
|
|
|
|
|
|
if(mp->m_pkthdr.csum_flags & CSUM_TCP) {
|
|
|
|
*txd_upper = E1000_TXD_POPTS_TXSM << 8;
|
|
|
|
*txd_lower = E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
|
2002-04-06 00:36:53 +00:00
|
|
|
if(adapter->active_checksum_context == OFFLOAD_TCP_IP)
|
2001-12-02 07:37:17 +00:00
|
|
|
return;
|
|
|
|
else
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->active_checksum_context = OFFLOAD_TCP_IP;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
} else if(mp->m_pkthdr.csum_flags & CSUM_UDP) {
|
|
|
|
*txd_upper = E1000_TXD_POPTS_TXSM << 8;
|
|
|
|
*txd_lower = E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
|
2002-04-06 00:36:53 +00:00
|
|
|
if(adapter->active_checksum_context == OFFLOAD_UDP_IP)
|
2001-12-02 07:37:17 +00:00
|
|
|
return;
|
|
|
|
else
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->active_checksum_context = OFFLOAD_UDP_IP;
|
2001-12-02 07:37:17 +00:00
|
|
|
} else {
|
|
|
|
*txd_upper = 0;
|
|
|
|
*txd_lower = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*txd_upper = 0;
|
|
|
|
*txd_lower = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we reach this point, the checksum offload context
|
|
|
|
* needs to be reset.
|
|
|
|
*/
|
2002-04-06 00:36:53 +00:00
|
|
|
current_tx_desc = adapter->next_avail_tx_desc;
|
|
|
|
TXD = (struct em_context_desc *)current_tx_desc;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-02-13 18:19:27 +00:00
|
|
|
TXD->lower_setup.ip_fields.ipcss = ETHER_HDR_LEN;
|
|
|
|
TXD->lower_setup.ip_fields.ipcso = ETHER_HDR_LEN + offsetof(struct ip, ip_sum);
|
|
|
|
TXD->lower_setup.ip_fields.ipcse = ETHER_HDR_LEN + sizeof(struct ip) - 1;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-02-13 18:19:27 +00:00
|
|
|
TXD->upper_setup.tcp_fields.tucss = ETHER_HDR_LEN + sizeof(struct ip);
|
|
|
|
TXD->upper_setup.tcp_fields.tucse = 0;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if(adapter->active_checksum_context == OFFLOAD_TCP_IP) {
|
2002-02-13 18:19:27 +00:00
|
|
|
TXD->upper_setup.tcp_fields.tucso = ETHER_HDR_LEN + sizeof(struct ip) +
|
2001-12-02 07:37:17 +00:00
|
|
|
offsetof(struct tcphdr, th_sum);
|
2002-04-06 00:36:53 +00:00
|
|
|
} else if (adapter->active_checksum_context == OFFLOAD_UDP_IP) {
|
2002-02-13 18:19:27 +00:00
|
|
|
TXD->upper_setup.tcp_fields.tucso = ETHER_HDR_LEN + sizeof(struct ip) +
|
2001-12-02 07:37:17 +00:00
|
|
|
offsetof(struct udphdr, uh_sum);
|
|
|
|
}
|
|
|
|
|
2002-02-13 18:19:27 +00:00
|
|
|
TXD->tcp_seg_setup.data = 0;
|
|
|
|
TXD->cmd_and_length = E1000_TXD_CMD_DEXT;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (current_tx_desc == adapter->last_tx_desc)
|
|
|
|
adapter->next_avail_tx_desc = adapter->first_tx_desc;
|
2001-12-02 07:37:17 +00:00
|
|
|
else
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->next_avail_tx_desc++;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->num_tx_desc_avail--;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
tx_buffer->num_tx_desc_used++;
|
2001-12-02 07:37:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Get a buffer from system mbuf buffer pool.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static int
|
2002-04-06 00:36:53 +00:00
|
|
|
em_get_buf(struct em_rx_buffer *rx_buffer, struct adapter *adapter,
|
2002-02-13 18:19:27 +00:00
|
|
|
struct mbuf *mp)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
|
|
|
struct mbuf *nmp;
|
2002-02-13 18:19:27 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
ifp = &adapter->interface_data.ac_if;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
if (mp == NULL) {
|
|
|
|
MGETHDR(nmp, M_DONTWAIT, MT_DATA);
|
|
|
|
if (nmp == NULL) {
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->mbuf_alloc_failed++;
|
2001-12-02 07:37:17 +00:00
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
MCLGET(nmp, M_DONTWAIT);
|
|
|
|
if ((nmp->m_flags & M_EXT) == 0) {
|
|
|
|
m_freem(nmp);
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->mbuf_cluster_failed++;
|
2001-12-02 07:37:17 +00:00
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
nmp->m_len = nmp->m_pkthdr.len = MCLBYTES;
|
|
|
|
} else {
|
|
|
|
nmp = mp;
|
|
|
|
nmp->m_len = nmp->m_pkthdr.len = MCLBYTES;
|
|
|
|
nmp->m_data = nmp->m_ext.ext_buf;
|
2002-02-13 18:19:27 +00:00
|
|
|
nmp->m_next = NULL;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
2002-02-13 18:19:27 +00:00
|
|
|
if (ifp->if_mtu <= ETHERMTU) {
|
|
|
|
m_adj(nmp, ETHER_ALIGN);
|
|
|
|
}
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
rx_buffer->m_head = nmp;
|
|
|
|
rx_buffer->buffer_addr = vtophys(mtod(nmp, vm_offset_t));
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Allocate memory for rx_buffer structures. Since we use one
|
|
|
|
* rx_buffer per received packet, the maximum number of rx_buffer's
|
|
|
|
* that we'll need is equal to the number of receive descriptors
|
|
|
|
* that we've allocated.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static int
|
2002-04-06 00:36:53 +00:00
|
|
|
em_allocate_receive_structures(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct em_rx_buffer *rx_buffer;
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (!(adapter->rx_buffer_area =
|
2001-12-02 07:37:17 +00:00
|
|
|
(struct em_rx_buffer *) malloc(sizeof(struct em_rx_buffer) *
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->num_rx_desc, M_DEVBUF,
|
2001-12-02 07:37:17 +00:00
|
|
|
M_NOWAIT))) {
|
2002-04-06 00:36:53 +00:00
|
|
|
printf("em%d: Unable to allocate rx_buffer memory\n", adapter->unit);
|
2001-12-02 07:37:17 +00:00
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
bzero(adapter->rx_buffer_area,
|
|
|
|
sizeof(struct em_rx_buffer) * adapter->num_rx_desc);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
for (i = 0, rx_buffer = adapter->rx_buffer_area;
|
|
|
|
i < adapter->num_rx_desc; i++, rx_buffer++) {
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (em_get_buf(rx_buffer, adapter, NULL) == ENOBUFS) {
|
|
|
|
rx_buffer->m_head = NULL;
|
2001-12-02 07:37:17 +00:00
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Allocate and initialize receive structures.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static int
|
2002-04-06 00:36:53 +00:00
|
|
|
em_setup_receive_structures(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
|
|
|
struct em_rx_buffer *rx_buffer;
|
2002-04-06 00:36:53 +00:00
|
|
|
struct em_rx_desc *rx_desc;
|
2001-12-02 07:37:17 +00:00
|
|
|
int i;
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if(em_allocate_receive_structures(adapter))
|
2001-12-02 07:37:17 +00:00
|
|
|
return ENOMEM;
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
STAILQ_INIT(&adapter->rx_buffer_list);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->first_rx_desc =
|
|
|
|
(struct em_rx_desc *) adapter->rx_desc_base;
|
|
|
|
adapter->last_rx_desc =
|
|
|
|
adapter->first_rx_desc + (adapter->num_rx_desc - 1);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
rx_buffer = (struct em_rx_buffer *) adapter->rx_buffer_area;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
bzero((void *) adapter->first_rx_desc,
|
|
|
|
(sizeof(struct em_rx_desc)) * adapter->num_rx_desc);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Build a linked list of rx_buffer's */
|
2002-04-06 00:36:53 +00:00
|
|
|
for (i = 0, rx_desc = adapter->first_rx_desc;
|
|
|
|
i < adapter->num_rx_desc;
|
|
|
|
i++, rx_buffer++, rx_desc++) {
|
|
|
|
if (rx_buffer->m_head == NULL)
|
|
|
|
printf("em%d: Receive buffer memory not allocated", adapter->unit);
|
2001-12-02 07:37:17 +00:00
|
|
|
else {
|
2002-04-06 00:36:53 +00:00
|
|
|
rx_desc->buffer_addr = rx_buffer->buffer_addr;
|
|
|
|
STAILQ_INSERT_TAIL(&adapter->rx_buffer_list, rx_buffer, em_rx_entry);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup our descriptor pointers */
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->next_rx_desc_to_check = adapter->first_rx_desc;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Enable receive unit.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_initialize_receive_unit(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
|
|
|
u_int32_t reg_rctl;
|
|
|
|
u_int32_t reg_rxcsum;
|
2002-04-06 00:36:53 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
ifp = &adapter->interface_data.ac_if;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Make sure receives are disabled while setting up the descriptor ring */
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, RCTL, 0);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Set the Receive Delay Timer Register */
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, RDTR, adapter->rx_int_delay | E1000_RDT_FPDB);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Setup the Base and Length of the Rx Descriptor Ring */
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, RDBAL, vtophys((vm_offset_t) adapter->rx_desc_base));
|
|
|
|
E1000_WRITE_REG(&adapter->shared, RDBAH, 0);
|
|
|
|
E1000_WRITE_REG(&adapter->shared, RDLEN, adapter->num_rx_desc *
|
2002-02-13 18:19:27 +00:00
|
|
|
sizeof(struct em_rx_desc));
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Setup the HW Rx Head and Tail Descriptor Pointers */
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, RDH, 0);
|
|
|
|
E1000_WRITE_REG(&adapter->shared, RDT,
|
|
|
|
(((u_int32_t) adapter->last_rx_desc -
|
|
|
|
(u_int32_t) adapter->first_rx_desc) >> 4));
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Setup the Receive Control Register */
|
|
|
|
reg_rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO |
|
2002-02-13 18:19:27 +00:00
|
|
|
E1000_RCTL_RDMTS_HALF |
|
2002-04-06 00:36:53 +00:00
|
|
|
(adapter->shared.mc_filter_type << E1000_RCTL_MO_SHIFT);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->shared.tbi_compatibility_on == TRUE)
|
2001-12-02 07:37:17 +00:00
|
|
|
reg_rctl |= E1000_RCTL_SBP;
|
|
|
|
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
switch (adapter->rx_buffer_len) {
|
2001-12-02 07:37:17 +00:00
|
|
|
case EM_RXBUFFER_2048:
|
|
|
|
reg_rctl |= E1000_RCTL_SZ_2048 | E1000_RCTL_LPE;
|
|
|
|
break;
|
|
|
|
case EM_RXBUFFER_4096:
|
|
|
|
reg_rctl |= E1000_RCTL_SZ_4096 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
|
|
|
|
break;
|
|
|
|
case EM_RXBUFFER_8192:
|
|
|
|
reg_rctl |= E1000_RCTL_SZ_8192 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
|
|
|
|
break;
|
|
|
|
case EM_RXBUFFER_16384:
|
|
|
|
reg_rctl |= E1000_RCTL_SZ_16384 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
reg_rctl |= E1000_RCTL_SZ_2048;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable 82543 Receive Checksum Offload for TCP and UDP */
|
2002-04-06 00:36:53 +00:00
|
|
|
if((adapter->shared.mac_type >= em_82543) && (ifp->if_capenable & IFCAP_RXCSUM)) {
|
|
|
|
reg_rxcsum = E1000_READ_REG(&adapter->shared, RXCSUM);
|
2001-12-02 07:37:17 +00:00
|
|
|
reg_rxcsum |= (E1000_RXCSUM_IPOFL | E1000_RXCSUM_TUOFL);
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, RXCSUM, reg_rxcsum);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable Receives */
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, RCTL, reg_rctl);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Free receive related data structures.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_free_receive_structures(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
|
|
|
struct em_rx_buffer *rx_buffer;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
INIT_DEBUGOUT("free_receive_structures: begin");
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->rx_buffer_area != NULL) {
|
|
|
|
rx_buffer = adapter->rx_buffer_area;
|
|
|
|
for (i = 0; i < adapter->num_rx_desc; i++, rx_buffer++) {
|
|
|
|
if (rx_buffer->m_head != NULL)
|
|
|
|
m_freem(rx_buffer->m_head);
|
|
|
|
rx_buffer->m_head = NULL;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->rx_buffer_area != NULL) {
|
|
|
|
free(adapter->rx_buffer_area, M_DEVBUF);
|
|
|
|
adapter->rx_buffer_area = NULL;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* This routine executes in interrupt context. It replenishes
|
|
|
|
* the mbufs in the descriptor and sends data which has been
|
|
|
|
* dma'ed into host memory to upper layer.
|
|
|
|
*
|
|
|
|
*********************************************************************/
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_process_receive_interrupts(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-02-13 18:19:27 +00:00
|
|
|
struct mbuf *mp;
|
2001-12-02 07:37:17 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ether_header *eh;
|
2002-04-06 00:36:53 +00:00
|
|
|
u_int16_t len;
|
|
|
|
u_int8_t last_byte;
|
|
|
|
u_int8_t accept_frame = 0;
|
|
|
|
u_int8_t eop = 0;
|
|
|
|
u_int32_t pkt_len = 0;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Pointer to the receive descriptor being examined. */
|
2002-04-06 00:36:53 +00:00
|
|
|
struct em_rx_desc *current_desc;
|
|
|
|
struct em_rx_desc *last_desc_processed;
|
|
|
|
struct em_rx_buffer *rx_buffer;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
ifp = &adapter->interface_data.ac_if;
|
|
|
|
current_desc = adapter->next_rx_desc_to_check;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (!((current_desc->status) & E1000_RXD_STAT_DD)) {
|
2001-12-02 07:37:17 +00:00
|
|
|
#ifdef DBG_STATS
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->no_pkts_avail++;
|
2001-12-02 07:37:17 +00:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
while (current_desc->status & E1000_RXD_STAT_DD) {
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Get a pointer to the actual receive buffer */
|
2002-04-06 00:36:53 +00:00
|
|
|
rx_buffer = STAILQ_FIRST(&adapter->rx_buffer_list);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
if(rx_buffer == NULL) {
|
2002-04-06 00:36:53 +00:00
|
|
|
printf("em%d: Found null rx_buffer\n", adapter->unit);
|
2001-12-02 07:37:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
mp = rx_buffer->m_head;
|
|
|
|
accept_frame = 1;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (current_desc->status & E1000_RXD_STAT_EOP) {
|
|
|
|
eop = 1;
|
|
|
|
len = current_desc->length - ETHER_CRC_LEN;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-04-06 00:36:53 +00:00
|
|
|
eop = 0;
|
|
|
|
len = current_desc->length;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if(current_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
|
2002-02-13 18:19:27 +00:00
|
|
|
|
|
|
|
/* Compute packet length for tbi_accept macro */
|
2002-04-06 00:36:53 +00:00
|
|
|
pkt_len = current_desc->length;
|
|
|
|
if (adapter->fmp != NULL) {
|
|
|
|
pkt_len += adapter->fmp->m_pkthdr.len;
|
2002-02-13 18:19:27 +00:00
|
|
|
}
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
last_byte = *(mtod(rx_buffer->m_head,caddr_t) + current_desc->length - 1);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (TBI_ACCEPT(&adapter->shared, current_desc->status,
|
|
|
|
current_desc->errors,
|
|
|
|
pkt_len, last_byte)) {
|
|
|
|
pkt_len = em_tbi_adjust_stats(&adapter->shared, &adapter->stats,
|
|
|
|
pkt_len, adapter->shared.mac_addr);
|
|
|
|
len--;
|
2001-12-02 07:37:17 +00:00
|
|
|
} else {
|
2002-04-06 00:36:53 +00:00
|
|
|
accept_frame = 0;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (accept_frame) {
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (em_get_buf(rx_buffer, adapter, NULL) == ENOBUFS) {
|
|
|
|
adapter->dropped_pkts++;
|
|
|
|
em_get_buf(rx_buffer, adapter, mp);
|
|
|
|
if(adapter->fmp != NULL) m_freem(adapter->fmp);
|
|
|
|
adapter->fmp = NULL;
|
|
|
|
adapter->lmp = NULL;
|
2002-02-13 18:19:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Assign correct length to the current fragment */
|
2002-04-06 00:36:53 +00:00
|
|
|
mp->m_len = len;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if(adapter->fmp == NULL) {
|
|
|
|
mp->m_pkthdr.len = len;
|
|
|
|
adapter->fmp = mp; /* Store the first mbuf */
|
|
|
|
adapter->lmp = mp;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Chain mbuf's together */
|
|
|
|
mp->m_flags &= ~M_PKTHDR;
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->lmp->m_next = mp;
|
|
|
|
adapter->lmp = adapter->lmp->m_next;
|
|
|
|
adapter->fmp->m_pkthdr.len += len;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (eop) {
|
|
|
|
adapter->fmp->m_pkthdr.rcvif = ifp;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
eh = mtod(adapter->fmp, struct ether_header *);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Remove ethernet header from mbuf */
|
2002-04-06 00:36:53 +00:00
|
|
|
m_adj(adapter->fmp, sizeof(struct ether_header));
|
|
|
|
em_receive_checksum(adapter, current_desc, adapter->fmp);
|
|
|
|
ether_input(ifp, eh, adapter->fmp);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->fmp = NULL;
|
|
|
|
adapter->lmp = NULL;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->dropped_pkts++;
|
|
|
|
em_get_buf(rx_buffer, adapter, mp);
|
|
|
|
if(adapter->fmp != NULL) m_freem(adapter->fmp);
|
|
|
|
adapter->fmp = NULL;
|
|
|
|
adapter->lmp = NULL;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Zero out the receive descriptors status */
|
2002-04-06 00:36:53 +00:00
|
|
|
current_desc->status = 0;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (rx_buffer->m_head != NULL) {
|
|
|
|
current_desc->buffer_addr = rx_buffer->buffer_addr;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Advance our pointers to the next descriptor (checking for wrap). */
|
2002-04-06 00:36:53 +00:00
|
|
|
if (current_desc == adapter->last_rx_desc)
|
|
|
|
adapter->next_rx_desc_to_check = adapter->first_rx_desc;
|
2001-12-02 07:37:17 +00:00
|
|
|
else
|
2002-04-06 00:36:53 +00:00
|
|
|
((adapter)->next_rx_desc_to_check)++;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
last_desc_processed = current_desc;
|
|
|
|
current_desc = adapter->next_rx_desc_to_check;
|
2001-12-02 07:37:17 +00:00
|
|
|
/*
|
|
|
|
* Put the buffer that we just indicated back at the end of our list
|
|
|
|
*/
|
2002-04-06 00:36:53 +00:00
|
|
|
STAILQ_REMOVE_HEAD(&adapter->rx_buffer_list, em_rx_entry);
|
|
|
|
STAILQ_INSERT_TAIL(&adapter->rx_buffer_list, rx_buffer, em_rx_entry);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Advance the E1000's Receive Queue #0 "Tail Pointer". */
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, RDT, (((u_int32_t) last_desc_processed -
|
|
|
|
(u_int32_t) adapter->first_rx_desc) >> 4));
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Verify that the hardware indicated that the checksum is valid.
|
|
|
|
* Inform the stack about the status of checksum so that stack
|
|
|
|
* doesn't spend time verifying the checksum.
|
|
|
|
*
|
|
|
|
*********************************************************************/
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_receive_checksum(struct adapter *adapter,
|
|
|
|
struct em_rx_desc *rx_desc,
|
|
|
|
struct mbuf *mp)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
|
|
|
/* 82543 or newer only */
|
2002-04-06 00:36:53 +00:00
|
|
|
if((adapter->shared.mac_type < em_82543) ||
|
2001-12-02 07:37:17 +00:00
|
|
|
/* Ignore Checksum bit is set */
|
2002-04-06 00:36:53 +00:00
|
|
|
(rx_desc->status & E1000_RXD_STAT_IXSM)) {
|
2001-12-02 07:37:17 +00:00
|
|
|
mp->m_pkthdr.csum_flags = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (rx_desc->status & E1000_RXD_STAT_IPCS) {
|
2001-12-02 07:37:17 +00:00
|
|
|
/* Did it pass? */
|
2002-04-06 00:36:53 +00:00
|
|
|
if (!(rx_desc->errors & E1000_RXD_ERR_IPE)) {
|
2001-12-02 07:37:17 +00:00
|
|
|
/* IP Checksum Good */
|
|
|
|
mp->m_pkthdr.csum_flags = CSUM_IP_CHECKED;
|
|
|
|
mp->m_pkthdr.csum_flags |= CSUM_IP_VALID;
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mp->m_pkthdr.csum_flags = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (rx_desc->status & E1000_RXD_STAT_TCPCS) {
|
2001-12-02 07:37:17 +00:00
|
|
|
/* Did it pass? */
|
2002-04-06 00:36:53 +00:00
|
|
|
if (!(rx_desc->errors & E1000_RXD_ERR_TCPE)) {
|
2001-12-02 07:37:17 +00:00
|
|
|
mp->m_pkthdr.csum_flags |= (CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
|
|
|
|
mp->m_pkthdr.csum_data = htons(0xffff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_enable_intr(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, IMS, (IMS_ENABLE_MASK));
|
2001-12-02 07:37:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_disable_intr(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-04-06 00:36:53 +00:00
|
|
|
E1000_WRITE_REG(&adapter->shared, IMC, (0xffffffff & ~E1000_IMC_RXSEQ));
|
2001-12-02 07:37:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
void em_write_pci_cfg(struct em_shared_adapter *adapter,
|
2002-02-13 18:19:27 +00:00
|
|
|
uint32_t reg,
|
|
|
|
uint16_t * value)
|
|
|
|
{
|
2002-04-06 00:36:53 +00:00
|
|
|
pci_write_config(((struct em_osdep *)adapter->back)->dev, reg, *value, 2);
|
2002-02-13 18:19:27 +00:00
|
|
|
}
|
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
*
|
|
|
|
* Update the board statistics counters.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_update_stats_counters(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->stats.crcerrs += E1000_READ_REG(&adapter->shared, CRCERRS);
|
|
|
|
adapter->stats.symerrs += E1000_READ_REG(&adapter->shared, SYMERRS);
|
|
|
|
adapter->stats.mpc += E1000_READ_REG(&adapter->shared, MPC);
|
|
|
|
adapter->stats.scc += E1000_READ_REG(&adapter->shared, SCC);
|
|
|
|
adapter->stats.ecol += E1000_READ_REG(&adapter->shared, ECOL);
|
|
|
|
adapter->stats.mcc += E1000_READ_REG(&adapter->shared, MCC);
|
|
|
|
adapter->stats.latecol += E1000_READ_REG(&adapter->shared, LATECOL);
|
|
|
|
adapter->stats.colc += E1000_READ_REG(&adapter->shared, COLC);
|
|
|
|
adapter->stats.dc += E1000_READ_REG(&adapter->shared, DC);
|
|
|
|
adapter->stats.sec += E1000_READ_REG(&adapter->shared, SEC);
|
|
|
|
adapter->stats.rlec += E1000_READ_REG(&adapter->shared, RLEC);
|
|
|
|
adapter->stats.xonrxc += E1000_READ_REG(&adapter->shared, XONRXC);
|
|
|
|
adapter->stats.xontxc += E1000_READ_REG(&adapter->shared, XONTXC);
|
|
|
|
adapter->stats.xoffrxc += E1000_READ_REG(&adapter->shared, XOFFRXC);
|
|
|
|
adapter->stats.xofftxc += E1000_READ_REG(&adapter->shared, XOFFTXC);
|
|
|
|
adapter->stats.fcruc += E1000_READ_REG(&adapter->shared, FCRUC);
|
|
|
|
adapter->stats.prc64 += E1000_READ_REG(&adapter->shared, PRC64);
|
|
|
|
adapter->stats.prc127 += E1000_READ_REG(&adapter->shared, PRC127);
|
|
|
|
adapter->stats.prc255 += E1000_READ_REG(&adapter->shared, PRC255);
|
|
|
|
adapter->stats.prc511 += E1000_READ_REG(&adapter->shared, PRC511);
|
|
|
|
adapter->stats.prc1023 += E1000_READ_REG(&adapter->shared, PRC1023);
|
|
|
|
adapter->stats.prc1522 += E1000_READ_REG(&adapter->shared, PRC1522);
|
|
|
|
adapter->stats.gprc += E1000_READ_REG(&adapter->shared, GPRC);
|
|
|
|
adapter->stats.bprc += E1000_READ_REG(&adapter->shared, BPRC);
|
|
|
|
adapter->stats.mprc += E1000_READ_REG(&adapter->shared, MPRC);
|
|
|
|
adapter->stats.gptc += E1000_READ_REG(&adapter->shared, GPTC);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* For the 64-bit byte counters the low dword must be read first. */
|
|
|
|
/* Both registers clear on the read of the high dword */
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->stats.gorcl += E1000_READ_REG(&adapter->shared, GORCL);
|
|
|
|
adapter->stats.gorch += E1000_READ_REG(&adapter->shared, GORCH);
|
|
|
|
adapter->stats.gotcl += E1000_READ_REG(&adapter->shared, GOTCL);
|
|
|
|
adapter->stats.gotch += E1000_READ_REG(&adapter->shared, GOTCH);
|
|
|
|
|
|
|
|
adapter->stats.rnbc += E1000_READ_REG(&adapter->shared, RNBC);
|
|
|
|
adapter->stats.ruc += E1000_READ_REG(&adapter->shared, RUC);
|
|
|
|
adapter->stats.rfc += E1000_READ_REG(&adapter->shared, RFC);
|
|
|
|
adapter->stats.roc += E1000_READ_REG(&adapter->shared, ROC);
|
|
|
|
adapter->stats.rjc += E1000_READ_REG(&adapter->shared, RJC);
|
|
|
|
|
|
|
|
adapter->stats.torl += E1000_READ_REG(&adapter->shared, TORL);
|
|
|
|
adapter->stats.torh += E1000_READ_REG(&adapter->shared, TORH);
|
|
|
|
adapter->stats.totl += E1000_READ_REG(&adapter->shared, TOTL);
|
|
|
|
adapter->stats.toth += E1000_READ_REG(&adapter->shared, TOTH);
|
|
|
|
|
|
|
|
adapter->stats.tpr += E1000_READ_REG(&adapter->shared, TPR);
|
|
|
|
adapter->stats.tpt += E1000_READ_REG(&adapter->shared, TPT);
|
|
|
|
adapter->stats.ptc64 += E1000_READ_REG(&adapter->shared, PTC64);
|
|
|
|
adapter->stats.ptc127 += E1000_READ_REG(&adapter->shared, PTC127);
|
|
|
|
adapter->stats.ptc255 += E1000_READ_REG(&adapter->shared, PTC255);
|
|
|
|
adapter->stats.ptc511 += E1000_READ_REG(&adapter->shared, PTC511);
|
|
|
|
adapter->stats.ptc1023 += E1000_READ_REG(&adapter->shared, PTC1023);
|
|
|
|
adapter->stats.ptc1522 += E1000_READ_REG(&adapter->shared, PTC1522);
|
|
|
|
adapter->stats.mptc += E1000_READ_REG(&adapter->shared, MPTC);
|
|
|
|
adapter->stats.bptc += E1000_READ_REG(&adapter->shared, BPTC);
|
|
|
|
|
|
|
|
if (adapter->shared.mac_type >= em_82543) {
|
|
|
|
adapter->stats.algnerrc += E1000_READ_REG(&adapter->shared, ALGNERRC);
|
|
|
|
adapter->stats.rxerrc += E1000_READ_REG(&adapter->shared, RXERRC);
|
|
|
|
adapter->stats.tncrs += E1000_READ_REG(&adapter->shared, TNCRS);
|
|
|
|
adapter->stats.cexterr += E1000_READ_REG(&adapter->shared, CEXTERR);
|
|
|
|
adapter->stats.tsctc += E1000_READ_REG(&adapter->shared, TSCTC);
|
|
|
|
adapter->stats.tsctfc += E1000_READ_REG(&adapter->shared, TSCTFC);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
2002-04-06 00:36:53 +00:00
|
|
|
ifp = &adapter->interface_data.ac_if;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Fill out the OS statistics structure */
|
2002-04-06 00:36:53 +00:00
|
|
|
ifp->if_ipackets = adapter->stats.gprc;
|
|
|
|
ifp->if_opackets = adapter->stats.gptc;
|
|
|
|
ifp->if_ibytes = adapter->stats.gorcl;
|
|
|
|
ifp->if_obytes = adapter->stats.gotcl;
|
|
|
|
ifp->if_imcasts = adapter->stats.mprc;
|
|
|
|
ifp->if_collisions = adapter->stats.colc;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Rx Errors */
|
|
|
|
ifp->if_ierrors =
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->dropped_pkts +
|
|
|
|
adapter->stats.rxerrc +
|
|
|
|
adapter->stats.crcerrs +
|
|
|
|
adapter->stats.algnerrc +
|
|
|
|
adapter->stats.rlec + adapter->stats.rnbc +
|
|
|
|
adapter->stats.mpc + adapter->stats.cexterr;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Tx Errors */
|
2002-04-06 00:36:53 +00:00
|
|
|
ifp->if_oerrors = adapter->stats.ecol + adapter->stats.latecol;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
*
|
|
|
|
* This routine is called only when em_display_debug_stats is enabled.
|
|
|
|
* This routine provides a way to take a look at important statistics
|
|
|
|
* maintained by the driver and hardware.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_print_hw_stats(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-04-06 00:36:53 +00:00
|
|
|
int unit = adapter->unit;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
#ifdef DBG_STATS
|
2002-04-06 00:36:53 +00:00
|
|
|
printf("em%d: Packets not Avail = %ld\n", unit, adapter->no_pkts_avail);
|
|
|
|
printf("em%d: clean_tx_interrupts = %ld\n", unit, adapter->clean_tx_interrupts);
|
2001-12-02 07:37:17 +00:00
|
|
|
#endif
|
2002-04-06 00:36:53 +00:00
|
|
|
|
|
|
|
printf("em%d: Tx Descriptors not Avail = %ld\n", unit, adapter->no_tx_desc_avail);
|
|
|
|
printf("em%d: Tx Buffer not avail1 = %ld\n", unit, adapter->no_tx_buffer_avail1);
|
|
|
|
printf("em%d: Tx Buffer not avail2 = %ld\n", unit, adapter->no_tx_buffer_avail2);
|
|
|
|
printf("em%d: Std Mbuf Failed = %ld\n",unit, adapter->mbuf_alloc_failed);
|
|
|
|
printf("em%d: Std Cluster Failed = %ld\n",unit, adapter->mbuf_cluster_failed);
|
|
|
|
printf("em%d: Xmit Pullup = %ld\n",unit, adapter->xmit_pullup);
|
|
|
|
|
|
|
|
printf("em%d: Symbol errors = %lld\n", unit, adapter->stats.symerrs);
|
|
|
|
printf("em%d: Sequence errors = %lld\n", unit, adapter->stats.sec);
|
|
|
|
printf("em%d: Defer count = %lld\n", unit, adapter->stats.dc);
|
|
|
|
|
|
|
|
printf("em%d: Missed Packets = %lld\n", unit, adapter->stats.mpc);
|
|
|
|
printf("em%d: Receive No Buffers = %lld\n", unit, adapter->stats.rnbc);
|
|
|
|
printf("em%d: Receive length errors = %lld\n", unit, adapter->stats.rlec);
|
|
|
|
printf("em%d: Receive errors = %lld\n", unit, adapter->stats.rxerrc);
|
|
|
|
printf("em%d: Crc errors = %lld\n", unit, adapter->stats.crcerrs);
|
|
|
|
printf("em%d: Alignment errors = %lld\n", unit, adapter->stats.algnerrc);
|
|
|
|
printf("em%d: Carrier extension errors = %lld\n", unit, adapter->stats.cexterr);
|
|
|
|
printf("em%d: Driver dropped packets = %ld\n", unit, adapter->dropped_pkts);
|
|
|
|
|
|
|
|
printf("em%d: XON Rcvd = %lld\n", unit, adapter->stats.xonrxc);
|
|
|
|
printf("em%d: XON Xmtd = %lld\n", unit, adapter->stats.xontxc);
|
|
|
|
printf("em%d: XOFF Rcvd = %lld\n", unit, adapter->stats.xoffrxc);
|
|
|
|
printf("em%d: XOFF Xmtd = %lld\n", unit, adapter->stats.xofftxc);
|
|
|
|
|
|
|
|
printf("em%d: Good Packets Rcvd = %lld\n", unit, adapter->stats.gprc);
|
|
|
|
printf("em%d: Good Packets Xmtd = %lld\n", unit, adapter->stats.gptc);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
*
|
|
|
|
* Examine each tx_buffer in the used queue. If the hardware is done
|
|
|
|
* processing the packet then free associated resources. The
|
|
|
|
* tx_buffer is put back on the free queue.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_clean_transmit_interrupts(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
|
|
|
struct em_tx_buffer *tx_buffer;
|
2002-04-06 00:36:53 +00:00
|
|
|
struct em_tx_desc *tx_desc;
|
2001-12-02 07:37:17 +00:00
|
|
|
int s;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
s = splimp();
|
|
|
|
#ifdef DBG_STATS
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->clean_tx_interrupts++;
|
2001-12-02 07:37:17 +00:00
|
|
|
#endif
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
for (tx_buffer = STAILQ_FIRST(&adapter->used_tx_buffer_list);
|
2001-12-02 07:37:17 +00:00
|
|
|
tx_buffer;
|
2002-04-06 00:36:53 +00:00
|
|
|
tx_buffer = STAILQ_FIRST(&adapter->used_tx_buffer_list)) {
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get hold of the next descriptor that the em will report status
|
|
|
|
* back to (this will be the last descriptor of a given tx_buffer). We
|
|
|
|
* only want to free the tx_buffer (and it resources) if the driver is
|
|
|
|
* done with ALL of the descriptors. If the driver is done with the
|
|
|
|
* last one then it is done with all of them.
|
|
|
|
*/
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
tx_desc = adapter->oldest_used_tx_desc +
|
|
|
|
(tx_buffer->num_tx_desc_used - 1);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Check for wrap case */
|
2002-04-06 00:36:53 +00:00
|
|
|
if (tx_desc > adapter->last_tx_desc)
|
|
|
|
tx_desc -= adapter->num_tx_desc;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the descriptor done bit is set free tx_buffer and associated
|
|
|
|
* resources
|
|
|
|
*/
|
2002-04-06 00:36:53 +00:00
|
|
|
if (tx_desc->upper.fields.status &
|
2001-12-02 07:37:17 +00:00
|
|
|
E1000_TXD_STAT_DD) {
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
STAILQ_REMOVE_HEAD(&adapter->used_tx_buffer_list, em_tx_entry);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if ((tx_desc == adapter->last_tx_desc))
|
|
|
|
adapter->oldest_used_tx_desc =
|
|
|
|
adapter->first_tx_desc;
|
2001-12-02 07:37:17 +00:00
|
|
|
else
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->oldest_used_tx_desc = (tx_desc + 1);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Make available the descriptors that were previously used */
|
2002-04-06 00:36:53 +00:00
|
|
|
adapter->num_tx_desc_avail +=
|
|
|
|
tx_buffer->num_tx_desc_used;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
tx_buffer->num_tx_desc_used = 0;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
if (tx_buffer->m_head) {
|
|
|
|
m_freem(tx_buffer->m_head);
|
|
|
|
tx_buffer->m_head = NULL;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
/* Return this "Software packet" back to the "free" list */
|
2002-04-06 00:36:53 +00:00
|
|
|
STAILQ_INSERT_TAIL(&adapter->free_tx_buffer_list, tx_buffer, em_tx_entry);
|
2001-12-02 07:37:17 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Found a tx_buffer that the em is not done with then there is
|
|
|
|
* no reason to check the rest of the queue.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} /* end for each tx_buffer */
|
|
|
|
|
2002-04-06 00:36:53 +00:00
|
|
|
ifp = &adapter->interface_data.ac_if;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/* Tell the stack that it is OK to send packets */
|
2002-04-06 00:36:53 +00:00
|
|
|
if (adapter->num_tx_desc_avail > TX_CLEANUP_THRESHOLD) {
|
2001-12-02 07:37:17 +00:00
|
|
|
ifp->if_timer = 0;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|