2001-12-02 07:37:17 +00:00
|
|
|
/**************************************************************************
|
|
|
|
|
2005-05-26 23:32:02 +00:00
|
|
|
Copyright (c) 2001-2005, Intel Corporation
|
2001-12-02 07:37:17 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
2002-09-24 16:27:59 +00:00
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-09-24 16:27:59 +00:00
|
|
|
1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
this list of conditions and the following disclaimer.
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-09-24 16:27:59 +00:00
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
3. Neither the name of the Intel Corporation nor the names of its
|
2002-09-24 16:27:59 +00:00
|
|
|
contributors may be used to endorse or promote products derived from
|
|
|
|
this software without specific prior written permission.
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
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
|
2002-09-24 16:27:59 +00:00
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
2002-02-13 18:19:27 +00:00
|
|
|
/*$FreeBSD$*/
|
|
|
|
|
2005-10-05 10:09:17 +00:00
|
|
|
#ifdef HAVE_KERNEL_OPTION_HEADERS
|
|
|
|
#include "opt_device_polling.h"
|
|
|
|
#endif
|
|
|
|
|
2006-02-14 13:11:36 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/endian.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/kthread.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/taskqueue.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/if_vlan_var.h>
|
|
|
|
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in.h>
|
2006-07-20 04:18:45 +00:00
|
|
|
#include <netinet/if_ether.h>
|
2006-02-14 13:11:36 +00:00
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#include <netinet/udp.h>
|
|
|
|
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/em/if_em_hw.h>
|
2001-12-02 07:37:17 +00:00
|
|
|
#include <dev/em/if_em.h>
|
|
|
|
|
|
|
|
/*********************************************************************
|
2006-01-20 11:38:25 +00:00
|
|
|
* Set this to one to display debug statistics
|
2001-12-02 07:37:17 +00:00
|
|
|
*********************************************************************/
|
2006-02-15 08:39:50 +00:00
|
|
|
int em_display_debug_stats = 0;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Driver version
|
|
|
|
*********************************************************************/
|
|
|
|
|
2006-04-06 17:09:03 +00:00
|
|
|
char em_driver_version[] = "Version - 5.1.5";
|
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 }
|
|
|
|
*********************************************************************/
|
2003-03-21 21:47:31 +00:00
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
static em_vendor_info_t em_vendor_info_array[] =
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
/* Intel(R) PRO/1000 Network Connection */
|
|
|
|
{ 0x8086, E1000_DEV_ID_82540EM, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82540EM_LOM, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82540EP, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82540EP_LOM, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82540EP_LP, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
|
|
|
|
{ 0x8086, E1000_DEV_ID_82541EI, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82541ER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82541ER_LOM, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82541EI_MOBILE, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82541GI, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82541GI_LF, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82541GI_MOBILE, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
|
|
|
|
{ 0x8086, E1000_DEV_ID_82542, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
|
|
|
|
{ 0x8086, E1000_DEV_ID_82543GC_FIBER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82543GC_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
|
|
|
|
{ 0x8086, E1000_DEV_ID_82544EI_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82544EI_FIBER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82544GC_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82544GC_LOM, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
|
|
|
|
{ 0x8086, E1000_DEV_ID_82545EM_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82545EM_FIBER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82545GM_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82545GM_FIBER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82545GM_SERDES, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
|
|
|
|
{ 0x8086, E1000_DEV_ID_82546EB_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82546EB_FIBER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82546EB_QUAD_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82546GB_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82546GB_FIBER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82546GB_SERDES, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82546GB_PCIE, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82546GB_QUAD_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
2006-04-06 17:09:03 +00:00
|
|
|
{ 0x8086, E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3,
|
|
|
|
PCI_ANY_ID, PCI_ANY_ID, 0},
|
2006-02-15 08:39:50 +00:00
|
|
|
|
|
|
|
{ 0x8086, E1000_DEV_ID_82547EI, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82547EI_MOBILE, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82547GI, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
|
|
|
|
{ 0x8086, E1000_DEV_ID_82571EB_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82571EB_FIBER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82571EB_SERDES, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
|
|
|
|
{ 0x8086, E1000_DEV_ID_82572EI_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82572EI_FIBER, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82572EI_SERDES, PCI_ANY_ID, PCI_ANY_ID, 0},
|
2006-04-06 17:09:03 +00:00
|
|
|
{ 0x8086, E1000_DEV_ID_82572EI, PCI_ANY_ID, PCI_ANY_ID, 0},
|
2006-02-15 08:39:50 +00:00
|
|
|
|
|
|
|
{ 0x8086, E1000_DEV_ID_82573E, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82573E_IAMT, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_82573L, PCI_ANY_ID, PCI_ANY_ID, 0},
|
2006-04-06 17:09:03 +00:00
|
|
|
{ 0x8086, E1000_DEV_ID_80003ES2LAN_COPPER_DPT,
|
|
|
|
PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, E1000_DEV_ID_80003ES2LAN_SERDES_DPT,
|
|
|
|
PCI_ANY_ID, PCI_ANY_ID, 0},
|
2006-02-15 08:39:50 +00:00
|
|
|
|
|
|
|
/* required last entry */
|
|
|
|
{ 0, 0, 0, 0, 0}
|
2001-12-02 07:37:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Table of branding strings for all supported NICs.
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
static char *em_strings[] = {
|
2002-06-03 22:30:51 +00:00
|
|
|
"Intel(R) PRO/1000 Network Connection"
|
2001-12-02 07:37:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*********************************************************************
|
2006-01-20 11:38:25 +00:00
|
|
|
* Function prototypes
|
2001-12-02 07:37:17 +00:00
|
|
|
*********************************************************************/
|
2006-02-15 08:39:50 +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);
|
|
|
|
static int em_suspend(device_t);
|
|
|
|
static int em_resume(device_t);
|
|
|
|
static void em_start(struct ifnet *);
|
|
|
|
static void em_start_locked(struct ifnet *ifp);
|
|
|
|
static int em_ioctl(struct ifnet *, u_long, caddr_t);
|
|
|
|
static void em_watchdog(struct ifnet *);
|
|
|
|
static void em_init(void *);
|
|
|
|
static void em_init_locked(struct em_softc *);
|
|
|
|
static void em_stop(void *);
|
|
|
|
static void em_media_status(struct ifnet *, struct ifmediareq *);
|
|
|
|
static int em_media_change(struct ifnet *);
|
|
|
|
static void em_identify_hardware(struct em_softc *);
|
|
|
|
static int em_allocate_pci_resources(struct em_softc *);
|
|
|
|
static int em_allocate_intr(struct em_softc *);
|
|
|
|
static void em_free_intr(struct em_softc *);
|
|
|
|
static void em_free_pci_resources(struct em_softc *);
|
|
|
|
static void em_local_timer(void *);
|
|
|
|
static int em_hardware_init(struct em_softc *);
|
|
|
|
static void em_setup_interface(device_t, struct em_softc *);
|
|
|
|
static int em_setup_transmit_structures(struct em_softc *);
|
|
|
|
static void em_initialize_transmit_unit(struct em_softc *);
|
|
|
|
static int em_setup_receive_structures(struct em_softc *);
|
|
|
|
static void em_initialize_receive_unit(struct em_softc *);
|
|
|
|
static void em_enable_intr(struct em_softc *);
|
|
|
|
static void em_disable_intr(struct em_softc *);
|
|
|
|
static void em_free_transmit_structures(struct em_softc *);
|
|
|
|
static void em_free_receive_structures(struct em_softc *);
|
|
|
|
static void em_update_stats_counters(struct em_softc *);
|
|
|
|
static void em_txeof(struct em_softc *);
|
|
|
|
static int em_allocate_receive_structures(struct em_softc *);
|
|
|
|
static int em_allocate_transmit_structures(struct em_softc *);
|
|
|
|
static int em_rxeof(struct em_softc *, int);
|
2005-12-16 08:29:43 +00:00
|
|
|
#ifndef __NO_STRICT_ALIGNMENT
|
2006-02-15 08:39:50 +00:00
|
|
|
static int em_fixup_rx(struct em_softc *);
|
2005-12-16 08:29:43 +00:00
|
|
|
#endif
|
2006-02-15 08:39:50 +00:00
|
|
|
static void em_receive_checksum(struct em_softc *, struct em_rx_desc *,
|
|
|
|
struct mbuf *);
|
|
|
|
static void em_transmit_checksum_setup(struct em_softc *, struct mbuf *,
|
|
|
|
uint32_t *, uint32_t *);
|
|
|
|
static void em_set_promisc(struct em_softc *);
|
|
|
|
static void em_disable_promisc(struct em_softc *);
|
|
|
|
static void em_set_multi(struct em_softc *);
|
|
|
|
static void em_print_hw_stats(struct em_softc *);
|
2006-02-15 10:51:11 +00:00
|
|
|
static void em_update_link_status(struct em_softc *);
|
2006-02-15 08:39:50 +00:00
|
|
|
static int em_get_buf(int i, struct em_softc *, struct mbuf *);
|
|
|
|
static void em_enable_vlans(struct em_softc *);
|
|
|
|
static void em_disable_vlans(struct em_softc *);
|
|
|
|
static int em_encap(struct em_softc *, struct mbuf **);
|
|
|
|
static void em_smartspeed(struct em_softc *);
|
|
|
|
static int em_82547_fifo_workaround(struct em_softc *, int);
|
|
|
|
static void em_82547_update_fifo_head(struct em_softc *, int);
|
|
|
|
static int em_82547_tx_fifo_reset(struct em_softc *);
|
|
|
|
static void em_82547_move_tail(void *arg);
|
|
|
|
static void em_82547_move_tail_locked(struct em_softc *);
|
|
|
|
static int em_dma_malloc(struct em_softc *, bus_size_t,
|
|
|
|
struct em_dma_alloc *, int);
|
|
|
|
static void em_dma_free(struct em_softc *, struct em_dma_alloc *);
|
|
|
|
static void em_print_debug_info(struct em_softc *);
|
|
|
|
static int em_is_valid_ether_addr(uint8_t *);
|
|
|
|
static int em_sysctl_stats(SYSCTL_HANDLER_ARGS);
|
|
|
|
static int em_sysctl_debug_info(SYSCTL_HANDLER_ARGS);
|
|
|
|
static uint32_t em_fill_descriptors (bus_addr_t address, uint32_t length,
|
|
|
|
PDESC_ARRAY desc_array);
|
|
|
|
static int em_sysctl_int_delay(SYSCTL_HANDLER_ARGS);
|
|
|
|
static void em_add_int_delay_sysctl(struct em_softc *, const char *,
|
|
|
|
const char *, struct em_int_delay_info *, int, int);
|
2006-06-06 08:03:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fast interrupt handler and legacy ithread/polling modes are
|
|
|
|
* mutually exclusive.
|
|
|
|
*/
|
|
|
|
#ifdef DEVICE_POLLING
|
|
|
|
static poll_handler_t em_poll;
|
|
|
|
static void em_intr(void *);
|
|
|
|
#else
|
|
|
|
static void em_intr_fast(void *);
|
2006-02-15 08:39:50 +00:00
|
|
|
static void em_add_int_process_limit(struct em_softc *, const char *,
|
|
|
|
const char *, int *, int);
|
|
|
|
static void em_handle_rxtx(void *context, int pending);
|
|
|
|
static void em_handle_link(void *context, int pending);
|
2006-01-11 00:30:25 +00:00
|
|
|
#endif
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
/*********************************************************************
|
2006-01-20 11:38:25 +00:00
|
|
|
* FreeBSD Device Interface Entry Points
|
2001-12-02 07:37:17 +00:00
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
static device_method_t em_methods[] = {
|
2002-06-03 22:30:51 +00:00
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, em_probe),
|
|
|
|
DEVMETHOD(device_attach, em_attach),
|
|
|
|
DEVMETHOD(device_detach, em_detach),
|
|
|
|
DEVMETHOD(device_shutdown, em_shutdown),
|
2005-12-26 10:39:21 +00:00
|
|
|
DEVMETHOD(device_suspend, em_suspend),
|
|
|
|
DEVMETHOD(device_resume, em_resume),
|
2002-06-03 22:30:51 +00:00
|
|
|
{0, 0}
|
2001-12-02 07:37:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t em_driver = {
|
2006-02-15 08:39:50 +00:00
|
|
|
"em", em_methods, sizeof(struct em_softc),
|
2001-12-02 07:37:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t em_devclass;
|
2003-04-15 06:37:30 +00:00
|
|
|
DRIVER_MODULE(em, pci, em_driver, em_devclass, 0, 0);
|
|
|
|
MODULE_DEPEND(em, pci, 1, 1, 1);
|
|
|
|
MODULE_DEPEND(em, ether, 1, 1, 1);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2003-08-01 17:33:59 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* Tunable default values.
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
#define E1000_TICKS_TO_USECS(ticks) ((1024 * (ticks) + 500) / 1000)
|
|
|
|
#define E1000_USECS_TO_TICKS(usecs) ((1000 * (usecs) + 512) / 1024)
|
|
|
|
|
|
|
|
static int em_tx_int_delay_dflt = E1000_TICKS_TO_USECS(EM_TIDV);
|
|
|
|
static int em_rx_int_delay_dflt = E1000_TICKS_TO_USECS(EM_RDTR);
|
|
|
|
static int em_tx_abs_int_delay_dflt = E1000_TICKS_TO_USECS(EM_TADV);
|
|
|
|
static int em_rx_abs_int_delay_dflt = E1000_TICKS_TO_USECS(EM_RADV);
|
2005-11-17 10:13:18 +00:00
|
|
|
static int em_rxd = EM_DEFAULT_RXD;
|
|
|
|
static int em_txd = EM_DEFAULT_TXD;
|
2003-08-01 17:33:59 +00:00
|
|
|
|
|
|
|
TUNABLE_INT("hw.em.tx_int_delay", &em_tx_int_delay_dflt);
|
|
|
|
TUNABLE_INT("hw.em.rx_int_delay", &em_rx_int_delay_dflt);
|
|
|
|
TUNABLE_INT("hw.em.tx_abs_int_delay", &em_tx_abs_int_delay_dflt);
|
|
|
|
TUNABLE_INT("hw.em.rx_abs_int_delay", &em_rx_abs_int_delay_dflt);
|
2005-11-17 10:13:18 +00:00
|
|
|
TUNABLE_INT("hw.em.rxd", &em_rxd);
|
|
|
|
TUNABLE_INT("hw.em.txd", &em_txd);
|
2006-06-06 08:03:49 +00:00
|
|
|
#ifndef DEVICE_POLLING
|
2006-01-11 00:30:25 +00:00
|
|
|
static int em_rx_process_limit = 100;
|
|
|
|
TUNABLE_INT("hw.em.rx_process_limit", &em_rx_process_limit);
|
|
|
|
#endif
|
2003-08-01 17:33:59 +00:00
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* Device identification routine
|
|
|
|
*
|
|
|
|
* em_probe determines if the driver should be loaded on
|
|
|
|
* adapter based on PCI vendor/device id of the adapter.
|
|
|
|
*
|
2005-03-05 18:30:12 +00:00
|
|
|
* return BUS_PROBE_DEFAULT on success, positive on failure
|
2001-12-02 07:37:17 +00:00
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
static int
|
|
|
|
em_probe(device_t dev)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
char adapter_name[60];
|
|
|
|
uint16_t pci_vendor_id = 0;
|
|
|
|
uint16_t pci_device_id = 0;
|
|
|
|
uint16_t pci_subvendor_id = 0;
|
|
|
|
uint16_t pci_subdevice_id = 0;
|
2002-06-03 22:30:51 +00:00
|
|
|
em_vendor_info_t *ent;
|
|
|
|
|
|
|
|
INIT_DEBUGOUT("em_probe: begin");
|
|
|
|
|
|
|
|
pci_vendor_id = pci_get_vendor(dev);
|
|
|
|
if (pci_vendor_id != EM_VENDOR_ID)
|
2006-02-15 08:39:50 +00:00
|
|
|
return (ENXIO);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
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) ||
|
2006-02-15 08:39:50 +00:00
|
|
|
(ent->subvendor_id == PCI_ANY_ID)) &&
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
((pci_subdevice_id == ent->subdevice_id) ||
|
2006-02-15 08:39:50 +00:00
|
|
|
(ent->subdevice_id == PCI_ANY_ID))) {
|
2006-01-20 11:38:25 +00:00
|
|
|
sprintf(adapter_name, "%s %s",
|
|
|
|
em_strings[ent->index],
|
2002-06-03 22:30:51 +00:00
|
|
|
em_driver_version);
|
|
|
|
device_set_desc_copy(dev, adapter_name);
|
2006-02-15 08:39:50 +00:00
|
|
|
return (BUS_PROBE_DEFAULT);
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
ent++;
|
|
|
|
}
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
return (ENXIO);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Device initialization routine
|
|
|
|
*
|
|
|
|
* The attach entry point is called when the driver is being loaded.
|
2006-01-20 11:38:25 +00:00
|
|
|
* This routine identifies the type of hardware, allocates all resources
|
|
|
|
* and initializes the hardware.
|
|
|
|
*
|
2001-12-02 07:37:17 +00:00
|
|
|
* return 0 on success, positive on failure
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
static int
|
|
|
|
em_attach(device_t dev)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc;
|
|
|
|
int tsize, rsize;
|
2003-06-05 17:51:38 +00:00
|
|
|
int error = 0;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
INIT_DEBUGOUT("em_attach: begin");
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
sc = device_get_softc(dev);
|
|
|
|
sc->dev = sc->osdep.dev = dev;
|
|
|
|
EM_LOCK_INIT(sc, device_get_nameunit(dev));
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-06-05 17:51:38 +00:00
|
|
|
/* SYSCTL stuff */
|
2006-02-15 08:39:50 +00:00
|
|
|
SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
|
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
|
|
|
|
OID_AUTO, "debug_info", CTLTYPE_INT|CTLFLAG_RW, sc, 0,
|
|
|
|
em_sysctl_debug_info, "I", "Debug Information");
|
2006-01-20 11:38:25 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
|
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
|
|
|
|
OID_AUTO, "stats", CTLTYPE_INT|CTLFLAG_RW, sc, 0,
|
|
|
|
em_sysctl_stats, "I", "Statistics");
|
2003-06-05 17:51:38 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
callout_init(&sc->timer, CALLOUT_MPSAFE);
|
|
|
|
callout_init(&sc->tx_fifo_timer, CALLOUT_MPSAFE);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Determine hardware revision */
|
2006-02-15 08:39:50 +00:00
|
|
|
em_identify_hardware(sc);
|
2003-08-01 17:33:59 +00:00
|
|
|
|
|
|
|
/* Set up some sysctls for the tunable interrupt delays */
|
2006-02-15 08:39:50 +00:00
|
|
|
em_add_int_delay_sysctl(sc, "rx_int_delay",
|
|
|
|
"receive interrupt delay in usecs", &sc->rx_int_delay,
|
|
|
|
E1000_REG_OFFSET(&sc->hw, RDTR), em_rx_int_delay_dflt);
|
|
|
|
em_add_int_delay_sysctl(sc, "tx_int_delay",
|
|
|
|
"transmit interrupt delay in usecs", &sc->tx_int_delay,
|
|
|
|
E1000_REG_OFFSET(&sc->hw, TIDV), em_tx_int_delay_dflt);
|
|
|
|
if (sc->hw.mac_type >= em_82540) {
|
|
|
|
em_add_int_delay_sysctl(sc, "rx_abs_int_delay",
|
2003-08-01 17:33:59 +00:00
|
|
|
"receive interrupt delay limit in usecs",
|
2006-02-15 08:39:50 +00:00
|
|
|
&sc->rx_abs_int_delay,
|
|
|
|
E1000_REG_OFFSET(&sc->hw, RADV),
|
2003-08-01 17:33:59 +00:00
|
|
|
em_rx_abs_int_delay_dflt);
|
2006-02-15 08:39:50 +00:00
|
|
|
em_add_int_delay_sysctl(sc, "tx_abs_int_delay",
|
2003-08-01 17:33:59 +00:00
|
|
|
"transmit interrupt delay limit in usecs",
|
2006-02-15 08:39:50 +00:00
|
|
|
&sc->tx_abs_int_delay,
|
|
|
|
E1000_REG_OFFSET(&sc->hw, TADV),
|
2003-08-01 17:33:59 +00:00
|
|
|
em_tx_abs_int_delay_dflt);
|
|
|
|
}
|
2005-11-17 10:13:18 +00:00
|
|
|
|
2006-06-06 08:03:49 +00:00
|
|
|
#ifndef DEVICE_POLLING
|
2006-01-11 00:30:25 +00:00
|
|
|
/* Sysctls for limiting the amount of work done in the taskqueue */
|
2006-02-15 08:39:50 +00:00
|
|
|
em_add_int_process_limit(sc, "rx_processing_limit",
|
|
|
|
"max number of rx packets to process", &sc->rx_process_limit,
|
2006-01-11 00:30:25 +00:00
|
|
|
em_rx_process_limit);
|
|
|
|
#endif
|
|
|
|
|
2005-11-17 10:13:18 +00:00
|
|
|
/*
|
|
|
|
* Validate number of transmit and receive descriptors. It
|
|
|
|
* must not exceed hardware maximum, and must be multiple
|
|
|
|
* of E1000_DBA_ALIGN.
|
|
|
|
*/
|
|
|
|
if (((em_txd * sizeof(struct em_tx_desc)) % E1000_DBA_ALIGN) != 0 ||
|
2006-02-15 08:39:50 +00:00
|
|
|
(sc->hw.mac_type >= em_82544 && em_txd > EM_MAX_TXD) ||
|
|
|
|
(sc->hw.mac_type < em_82544 && em_txd > EM_MAX_TXD_82543) ||
|
2005-11-17 10:13:18 +00:00
|
|
|
(em_txd < EM_MIN_TXD)) {
|
2006-02-15 08:39:50 +00:00
|
|
|
device_printf(dev, "Using %d TX descriptors instead of %d!\n",
|
|
|
|
EM_DEFAULT_TXD, em_txd);
|
|
|
|
sc->num_tx_desc = EM_DEFAULT_TXD;
|
2005-11-17 10:13:18 +00:00
|
|
|
} else
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->num_tx_desc = em_txd;
|
2005-11-17 10:13:18 +00:00
|
|
|
if (((em_rxd * sizeof(struct em_rx_desc)) % E1000_DBA_ALIGN) != 0 ||
|
2006-02-15 08:39:50 +00:00
|
|
|
(sc->hw.mac_type >= em_82544 && em_rxd > EM_MAX_RXD) ||
|
|
|
|
(sc->hw.mac_type < em_82544 && em_rxd > EM_MAX_RXD_82543) ||
|
2005-11-17 10:13:18 +00:00
|
|
|
(em_rxd < EM_MIN_RXD)) {
|
2006-02-15 08:39:50 +00:00
|
|
|
device_printf(dev, "Using %d RX descriptors instead of %d!\n",
|
|
|
|
EM_DEFAULT_RXD, em_rxd);
|
|
|
|
sc->num_rx_desc = EM_DEFAULT_RXD;
|
2005-11-17 10:13:18 +00:00
|
|
|
} else
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->num_rx_desc = em_rxd;
|
2005-11-17 10:13:18 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.autoneg = DO_AUTO_NEG;
|
|
|
|
sc->hw.wait_autoneg_complete = WAIT_FOR_AUTO_NEG_DEFAULT;
|
|
|
|
sc->hw.autoneg_advertised = AUTONEG_ADV_DEFAULT;
|
|
|
|
sc->hw.tbi_compatibility_en = TRUE;
|
|
|
|
sc->rx_buffer_len = EM_RXBUFFER_2048;
|
2006-01-20 11:38:25 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.phy_init_script = 1;
|
|
|
|
sc->hw.phy_reset_disable = FALSE;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-08-27 21:52:37 +00:00
|
|
|
#ifndef EM_MASTER_SLAVE
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.master_slave = em_ms_hw_default;
|
2003-08-27 21:52:37 +00:00
|
|
|
#else
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.master_slave = EM_MASTER_SLAVE;
|
2003-08-27 21:52:37 +00:00
|
|
|
#endif
|
2006-01-20 11:38:25 +00:00
|
|
|
/*
|
|
|
|
* Set the max frame size assuming standard ethernet
|
|
|
|
* sized frames.
|
|
|
|
*/
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.max_frame_size = ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.min_frame_size = MINIMUM_ETHERNET_PACKET_SIZE + ETHER_CRC_LEN;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
/*
|
|
|
|
* This controls when hardware reports transmit completion
|
|
|
|
* status.
|
2003-03-21 21:47:31 +00:00
|
|
|
*/
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.report_tx_early = 1;
|
|
|
|
if (em_allocate_pci_resources(sc)) {
|
|
|
|
device_printf(dev, "Allocation of PCI resources failed\n");
|
|
|
|
error = ENXIO;
|
|
|
|
goto err_pci;
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
/* Initialize eeprom parameters */
|
2006-02-15 08:39:50 +00:00
|
|
|
em_init_eeprom_params(&sc->hw);
|
2003-03-21 21:47:31 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
tsize = roundup2(sc->num_tx_desc * sizeof(struct em_tx_desc),
|
2005-11-21 04:17:43 +00:00
|
|
|
E1000_DBA_ALIGN);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Allocate Transmit Descriptor ring */
|
2006-02-15 08:39:50 +00:00
|
|
|
if (em_dma_malloc(sc, tsize, &sc->txdma, BUS_DMA_NOWAIT)) {
|
|
|
|
device_printf(dev, "Unable to allocate tx_desc memory\n");
|
2003-06-05 17:51:38 +00:00
|
|
|
error = ENOMEM;
|
2006-02-15 08:39:50 +00:00
|
|
|
goto err_tx_desc;
|
|
|
|
}
|
|
|
|
sc->tx_desc_base = (struct em_tx_desc *)sc->txdma.dma_vaddr;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
rsize = roundup2(sc->num_rx_desc * sizeof(struct em_rx_desc),
|
2005-11-21 04:17:43 +00:00
|
|
|
E1000_DBA_ALIGN);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
/* Allocate Receive Descriptor ring */
|
2006-02-15 08:39:50 +00:00
|
|
|
if (em_dma_malloc(sc, rsize, &sc->rxdma, BUS_DMA_NOWAIT)) {
|
|
|
|
device_printf(dev, "Unable to allocate rx_desc memory\n");
|
2003-06-05 17:51:38 +00:00
|
|
|
error = ENOMEM;
|
2006-02-15 08:39:50 +00:00
|
|
|
goto err_rx_desc;
|
|
|
|
}
|
|
|
|
sc->rx_desc_base = (struct em_rx_desc *)sc->rxdma.dma_vaddr;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Initialize the hardware */
|
2006-02-15 08:39:50 +00:00
|
|
|
if (em_hardware_init(sc)) {
|
|
|
|
device_printf(dev, "Unable to initialize the hardware\n");
|
2003-06-05 17:51:38 +00:00
|
|
|
error = EIO;
|
2006-02-15 08:39:50 +00:00
|
|
|
goto err_hw_init;
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
|
2002-07-16 16:55:03 +00:00
|
|
|
/* Copy the permanent MAC address out of the EEPROM */
|
2006-02-15 08:39:50 +00:00
|
|
|
if (em_read_mac_addr(&sc->hw) < 0) {
|
|
|
|
device_printf(dev, "EEPROM read error while reading MAC"
|
|
|
|
" address\n");
|
2003-06-05 17:51:38 +00:00
|
|
|
error = EIO;
|
2006-02-15 08:39:50 +00:00
|
|
|
goto err_hw_init;
|
2002-07-16 16:55:03 +00:00
|
|
|
}
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (!em_is_valid_ether_addr(sc->hw.mac_addr)) {
|
|
|
|
device_printf(dev, "Invalid MAC address\n");
|
|
|
|
error = EIO;
|
|
|
|
goto err_hw_init;
|
|
|
|
}
|
2003-06-05 17:51:38 +00:00
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
/* Setup OS specific network interface */
|
2006-02-15 08:39:50 +00:00
|
|
|
em_setup_interface(dev, sc);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
em_allocate_intr(sc);
|
2006-01-13 08:18:04 +00:00
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
/* Initialize statistics */
|
2006-02-15 08:39:50 +00:00
|
|
|
em_clear_hw_cntrs(&sc->hw);
|
|
|
|
em_update_stats_counters(sc);
|
|
|
|
sc->hw.get_link_status = 1;
|
2006-02-15 10:51:11 +00:00
|
|
|
em_update_link_status(sc);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-04-06 17:09:03 +00:00
|
|
|
/* Indicate SOL/IDER usage */
|
|
|
|
if (em_check_phy_reset_block(&sc->hw))
|
|
|
|
device_printf(dev,
|
|
|
|
"PHY reset is blocked due to SOL/IDER session.\n");
|
|
|
|
|
2003-08-27 21:52:37 +00:00
|
|
|
/* Identify 82544 on PCIX */
|
2006-02-15 08:39:50 +00:00
|
|
|
em_get_bus_info(&sc->hw);
|
|
|
|
if(sc->hw.bus_type == em_bus_type_pcix && sc->hw.mac_type == em_82544)
|
|
|
|
sc->pcix_82544 = TRUE;
|
|
|
|
else
|
|
|
|
sc->pcix_82544 = FALSE;
|
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
INIT_DEBUGOUT("em_attach: end");
|
2003-06-05 17:51:38 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
return (0);
|
|
|
|
|
2003-06-05 17:51:38 +00:00
|
|
|
err_hw_init:
|
2006-02-15 08:39:50 +00:00
|
|
|
em_dma_free(sc, &sc->rxdma);
|
2003-06-05 17:51:38 +00:00
|
|
|
err_rx_desc:
|
2006-02-15 08:39:50 +00:00
|
|
|
em_dma_free(sc, &sc->txdma);
|
2003-06-05 17:51:38 +00:00
|
|
|
err_tx_desc:
|
|
|
|
err_pci:
|
2006-02-15 08:39:50 +00:00
|
|
|
em_free_intr(sc);
|
|
|
|
em_free_pci_resources(sc);
|
|
|
|
EM_LOCK_DESTROY(sc);
|
2003-06-05 17:51:38 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
return (error);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* 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.
|
2006-01-20 11:38:25 +00:00
|
|
|
*
|
2001-12-02 07:37:17 +00:00
|
|
|
* return 0 on success, positive on failure
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
static int
|
|
|
|
em_detach(device_t dev)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc = device_get_softc(dev);
|
|
|
|
struct ifnet *ifp = sc->ifp;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
INIT_DEBUGOUT("em_detach: begin");
|
|
|
|
|
Big polling(4) cleanup.
o Axe poll in trap.
o Axe IFF_POLLING flag from if_flags.
o Rework revision 1.21 (Giant removal), in such a way that
poll_mtx is not dropped during call to polling handler.
This fixes problem with idle polling.
o Make registration and deregistration from polling in a
functional way, insted of next tick/interrupt.
o Obsolete kern.polling.enable. Polling is turned on/off
with ifconfig.
Detailed kern_poll.c changes:
- Remove polling handler flags, introduced in 1.21. The are not
needed now.
- Forget and do not check if_flags, if_capenable and if_drv_flags.
- Call all registered polling handlers unconditionally.
- Do not drop poll_mtx, when entering polling handlers.
- In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx.
- In netisr_poll() axe the block, where polling code asks drivers
to unregister.
- In netisr_poll() and ether_poll() do polling always, if any
handlers are present.
- In ether_poll_[de]register() remove a lot of error hiding code. Assert
that arguments are correct, instead.
- In ether_poll_[de]register() use standard return values in case of
error or success.
- Introduce poll_switch() that is a sysctl handler for kern.polling.enable.
poll_switch() goes through interface list and enabled/disables polling.
A message that kern.polling.enable is deprecated is printed.
Detailed driver changes:
- On attach driver announces IFCAP_POLLING in if_capabilities, but
not in if_capenable.
- On detach driver calls ether_poll_deregister() if polling is enabled.
- In polling handler driver obtains its lock and checks IFF_DRV_RUNNING
flag. If there is no, then unlocks and returns.
- In ioctl handler driver checks for IFCAP_POLLING flag requested to
be set or cleared. Driver first calls ether_poll_[de]register(), then
obtains driver lock and [dis/en]ables interrupts.
- In interrupt handler driver checks IFCAP_POLLING flag in if_capenable.
If present, then returns.This is important to protect from spurious
interrupts.
Reviewed by: ru, sam, jhb
2005-10-01 18:56:19 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
|
|
|
if (ifp->if_capenable & IFCAP_POLLING)
|
|
|
|
ether_poll_deregister(ifp);
|
|
|
|
#endif
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
em_free_intr(sc);
|
|
|
|
EM_LOCK(sc);
|
|
|
|
sc->in_detach = 1;
|
|
|
|
em_stop(sc);
|
|
|
|
em_phy_hw_reset(&sc->hw);
|
|
|
|
EM_UNLOCK(sc);
|
|
|
|
ether_ifdetach(sc->ifp);
|
2005-10-14 10:34:46 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
em_free_pci_resources(sc);
|
2004-02-10 21:31:09 +00:00
|
|
|
bus_generic_detach(dev);
|
2005-09-19 03:10:21 +00:00
|
|
|
if_free(ifp);
|
2004-02-10 21:31:09 +00:00
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
/* Free Transmit Descriptor ring */
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->tx_desc_base) {
|
|
|
|
em_dma_free(sc, &sc->txdma);
|
|
|
|
sc->tx_desc_base = NULL;
|
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
/* Free Receive Descriptor ring */
|
|
|
|
if (sc->rx_desc_base) {
|
|
|
|
em_dma_free(sc, &sc->rxdma);
|
|
|
|
sc->rx_desc_base = NULL;
|
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK_DESTROY(sc);
|
2003-10-10 23:14:21 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
return (0);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Shutdown entry point
|
2002-12-23 19:11:23 +00:00
|
|
|
*
|
2006-01-20 11:38:25 +00:00
|
|
|
**********************************************************************/
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
static int
|
|
|
|
em_shutdown(device_t dev)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc = device_get_softc(dev);
|
|
|
|
EM_LOCK(sc);
|
|
|
|
em_stop(sc);
|
|
|
|
EM_UNLOCK(sc);
|
|
|
|
return (0);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
2005-12-26 10:39:21 +00:00
|
|
|
/*
|
|
|
|
* Suspend/resume device methods.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
em_suspend(device_t dev)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc = device_get_softc(dev);
|
2005-12-26 10:39:21 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK(sc);
|
|
|
|
em_stop(sc);
|
|
|
|
EM_UNLOCK(sc);
|
2005-12-26 10:39:21 +00:00
|
|
|
|
|
|
|
return bus_generic_suspend(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
em_resume(device_t dev)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc = device_get_softc(dev);
|
|
|
|
struct ifnet *ifp = sc->ifp;
|
2005-12-26 10:39:21 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK(sc);
|
|
|
|
em_init_locked(sc);
|
2005-12-28 08:58:28 +00:00
|
|
|
if ((ifp->if_flags & IFF_UP) &&
|
|
|
|
(ifp->if_drv_flags & IFF_DRV_RUNNING))
|
2005-12-28 09:37:04 +00:00
|
|
|
em_start_locked(ifp);
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_UNLOCK(sc);
|
2005-12-26 10:39:21 +00:00
|
|
|
|
|
|
|
return bus_generic_resume(dev);
|
|
|
|
}
|
|
|
|
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* 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
|
2003-09-23 00:18:25 +00:00
|
|
|
em_start_locked(struct ifnet *ifp)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc = ifp->if_softc;
|
2006-01-20 11:38:25 +00:00
|
|
|
struct mbuf *m_head;
|
2003-03-21 21:47:31 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK_ASSERT(sc);
|
2003-09-23 00:18:25 +00:00
|
|
|
|
2006-07-20 03:57:58 +00:00
|
|
|
if ((ifp->if_drv_flags & (IFF_DRV_RUNNING|IFF_DRV_OACTIVE)) !=
|
|
|
|
IFF_DRV_RUNNING)
|
|
|
|
return;
|
2006-02-15 08:39:50 +00:00
|
|
|
if (!sc->link_active)
|
2006-01-20 11:38:25 +00:00
|
|
|
return;
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
while (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) {
|
2004-11-14 20:20:28 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head);
|
|
|
|
if (m_head == NULL)
|
|
|
|
break;
|
2004-11-14 20:20:28 +00:00
|
|
|
/*
|
|
|
|
* em_encap() can modify our pointer, and or make it NULL on
|
|
|
|
* failure. In that event, we can't requeue.
|
|
|
|
*/
|
2006-02-15 08:39:50 +00:00
|
|
|
if (em_encap(sc, &m_head)) {
|
2004-11-14 20:20:28 +00:00
|
|
|
if (m_head == NULL)
|
|
|
|
break;
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_OACTIVE;
|
2004-07-02 12:16:02 +00:00
|
|
|
IFQ_DRV_PREPEND(&ifp->if_snd, m_head);
|
2003-03-21 21:47:31 +00:00
|
|
|
break;
|
2006-01-20 11:38:25 +00:00
|
|
|
}
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
/* Send a copy of the frame to the BPF listener */
|
2002-11-14 23:54:55 +00:00
|
|
|
BPF_MTAP(ifp, m_head);
|
2006-01-20 11:38:25 +00:00
|
|
|
|
|
|
|
/* Set timeout in case hardware has problems transmitting. */
|
|
|
|
ifp->if_timer = EM_TX_TIMEOUT;
|
|
|
|
}
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
2003-09-23 00:18:25 +00:00
|
|
|
static void
|
|
|
|
em_start(struct ifnet *ifp)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc = ifp->if_softc;
|
2003-09-23 00:18:25 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK(sc);
|
2005-09-20 14:52:57 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING)
|
2005-09-20 13:37:17 +00:00
|
|
|
em_start_locked(ifp);
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_UNLOCK(sc);
|
2003-09-23 00:18:25 +00:00
|
|
|
}
|
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* Ioctl entry point
|
|
|
|
*
|
|
|
|
* em_ioctl is called when the user wants to configure the
|
|
|
|
* interface.
|
|
|
|
*
|
|
|
|
* return 0 on success, positive on failure
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
static int
|
2003-03-21 21:47:31 +00:00
|
|
|
em_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc = ifp->if_softc;
|
2006-04-06 17:09:03 +00:00
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
2006-07-20 04:18:45 +00:00
|
|
|
struct ifaddr *ifa = (struct ifaddr *)data;
|
2005-11-24 01:44:49 +00:00
|
|
|
int error = 0;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->in_detach)
|
|
|
|
return (error);
|
2003-11-14 18:02:25 +00:00
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
switch (command) {
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
case SIOCGIFADDR:
|
2006-07-20 04:18:45 +00:00
|
|
|
if (ifa->ifa_addr->sa_family == AF_INET) {
|
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
* Since resetting hardware takes a very long time
|
|
|
|
* and results in link renegotiation we only
|
|
|
|
* initialize the hardware only when it is absolutely
|
|
|
|
* required.
|
|
|
|
*/
|
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
|
|
|
|
EM_LOCK(sc);
|
|
|
|
em_init_locked(sc);
|
|
|
|
EM_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
arp_ifinit(ifp, ifa);
|
|
|
|
} else
|
|
|
|
error = ether_ioctl(ifp, command, data);
|
2002-06-03 22:30:51 +00:00
|
|
|
break;
|
|
|
|
case SIOCSIFMTU:
|
2005-11-24 01:44:49 +00:00
|
|
|
{
|
|
|
|
int max_frame_size;
|
2006-04-06 17:09:03 +00:00
|
|
|
uint16_t eeprom_data = 0;
|
2005-11-24 01:44:49 +00:00
|
|
|
|
|
|
|
IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFMTU (Set Interface MTU)");
|
|
|
|
|
2006-07-20 04:01:54 +00:00
|
|
|
EM_LOCK(sc);
|
2006-02-15 08:39:50 +00:00
|
|
|
switch (sc->hw.mac_type) {
|
2006-04-06 17:09:03 +00:00
|
|
|
case em_82573:
|
|
|
|
/*
|
|
|
|
* 82573 only supports jumbo frames
|
|
|
|
* if ASPM is disabled.
|
|
|
|
*/
|
|
|
|
em_read_eeprom(&sc->hw, EEPROM_INIT_3GIO_3, 1,
|
|
|
|
&eeprom_data);
|
|
|
|
if (eeprom_data & EEPROM_WORD1A_ASPM_MASK) {
|
|
|
|
max_frame_size = ETHER_MAX_LEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Allow Jumbo frames - fall thru */
|
2005-11-24 01:44:49 +00:00
|
|
|
case em_82571:
|
|
|
|
case em_82572:
|
2006-04-06 17:09:03 +00:00
|
|
|
case em_80003es2lan: /* Limit Jumbo Frame size */
|
|
|
|
max_frame_size = 9234;
|
2005-11-24 01:44:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
max_frame_size = MAX_JUMBO_FRAME_SIZE;
|
|
|
|
}
|
|
|
|
if (ifr->ifr_mtu > max_frame_size - ETHER_HDR_LEN -
|
|
|
|
ETHER_CRC_LEN) {
|
2006-07-20 04:01:54 +00:00
|
|
|
EM_UNLOCK(sc);
|
2002-06-03 22:30:51 +00:00
|
|
|
error = EINVAL;
|
2005-11-24 01:44:49 +00:00
|
|
|
break;
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
2005-11-24 01:44:49 +00:00
|
|
|
|
|
|
|
ifp->if_mtu = ifr->ifr_mtu;
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.max_frame_size =
|
2005-11-24 01:44:49 +00:00
|
|
|
ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
|
2006-02-15 08:39:50 +00:00
|
|
|
em_init_locked(sc);
|
|
|
|
EM_UNLOCK(sc);
|
2002-06-03 22:30:51 +00:00
|
|
|
break;
|
2005-11-24 01:44:49 +00:00
|
|
|
}
|
2003-03-21 21:47:31 +00:00
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFFLAGS (Set Interface Flags)");
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK(sc);
|
2003-03-21 21:47:31 +00:00
|
|
|
if (ifp->if_flags & IFF_UP) {
|
2006-07-20 04:18:45 +00:00
|
|
|
if ((ifp->if_drv_flags & IFF_DRV_RUNNING)) {
|
|
|
|
if ((ifp->if_flags ^ sc->if_flags) &
|
|
|
|
IFF_PROMISC) {
|
|
|
|
em_disable_promisc(sc);
|
|
|
|
em_set_promisc(sc);
|
|
|
|
}
|
|
|
|
} else
|
2006-02-15 08:39:50 +00:00
|
|
|
em_init_locked(sc);
|
2003-03-21 21:47:31 +00:00
|
|
|
} else {
|
2005-08-09 10:20:02 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
|
2006-02-15 08:39:50 +00:00
|
|
|
em_stop(sc);
|
2003-03-21 21:47:31 +00:00
|
|
|
}
|
|
|
|
}
|
2006-07-20 04:18:45 +00:00
|
|
|
sc->if_flags = ifp->if_flags;
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_UNLOCK(sc);
|
2003-03-21 21:47:31 +00:00
|
|
|
break;
|
2002-06-03 22:30:51 +00:00
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
IOCTL_DEBUGOUT("ioctl rcv'd: SIOC(ADD|DEL)MULTI");
|
2005-08-09 10:20:02 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK(sc);
|
|
|
|
em_disable_intr(sc);
|
|
|
|
em_set_multi(sc);
|
|
|
|
if (sc->hw.mac_type == em_82542_rev2_0) {
|
|
|
|
em_initialize_receive_unit(sc);
|
2003-06-05 17:51:38 +00:00
|
|
|
}
|
|
|
|
#ifdef DEVICE_POLLING
|
2006-02-15 08:39:50 +00:00
|
|
|
if (!(ifp->if_capenable & IFCAP_POLLING))
|
2003-06-05 17:51:38 +00:00
|
|
|
#endif
|
2006-02-15 08:39:50 +00:00
|
|
|
em_enable_intr(sc);
|
|
|
|
EM_UNLOCK(sc);
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
IOCTL_DEBUGOUT("ioctl rcv'd: SIOCxIFMEDIA (Get/Set Interface Media)");
|
2006-02-15 08:39:50 +00:00
|
|
|
error = ifmedia_ioctl(ifp, ifr, &sc->media, command);
|
2002-06-03 22:30:51 +00:00
|
|
|
break;
|
|
|
|
case SIOCSIFCAP:
|
2005-11-24 01:44:49 +00:00
|
|
|
{
|
|
|
|
int mask, reinit;
|
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFCAP (Set Capabilities)");
|
2004-06-04 16:57:18 +00:00
|
|
|
reinit = 0;
|
2002-06-03 22:30:51 +00:00
|
|
|
mask = ifr->ifr_reqcap ^ ifp->if_capenable;
|
Big polling(4) cleanup.
o Axe poll in trap.
o Axe IFF_POLLING flag from if_flags.
o Rework revision 1.21 (Giant removal), in such a way that
poll_mtx is not dropped during call to polling handler.
This fixes problem with idle polling.
o Make registration and deregistration from polling in a
functional way, insted of next tick/interrupt.
o Obsolete kern.polling.enable. Polling is turned on/off
with ifconfig.
Detailed kern_poll.c changes:
- Remove polling handler flags, introduced in 1.21. The are not
needed now.
- Forget and do not check if_flags, if_capenable and if_drv_flags.
- Call all registered polling handlers unconditionally.
- Do not drop poll_mtx, when entering polling handlers.
- In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx.
- In netisr_poll() axe the block, where polling code asks drivers
to unregister.
- In netisr_poll() and ether_poll() do polling always, if any
handlers are present.
- In ether_poll_[de]register() remove a lot of error hiding code. Assert
that arguments are correct, instead.
- In ether_poll_[de]register() use standard return values in case of
error or success.
- Introduce poll_switch() that is a sysctl handler for kern.polling.enable.
poll_switch() goes through interface list and enabled/disables polling.
A message that kern.polling.enable is deprecated is printed.
Detailed driver changes:
- On attach driver announces IFCAP_POLLING in if_capabilities, but
not in if_capenable.
- On detach driver calls ether_poll_deregister() if polling is enabled.
- In polling handler driver obtains its lock and checks IFF_DRV_RUNNING
flag. If there is no, then unlocks and returns.
- In ioctl handler driver checks for IFCAP_POLLING flag requested to
be set or cleared. Driver first calls ether_poll_[de]register(), then
obtains driver lock and [dis/en]ables interrupts.
- In interrupt handler driver checks IFCAP_POLLING flag in if_capenable.
If present, then returns.This is important to protect from spurious
interrupts.
Reviewed by: ru, sam, jhb
2005-10-01 18:56:19 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
|
|
|
if (mask & IFCAP_POLLING) {
|
|
|
|
if (ifr->ifr_reqcap & IFCAP_POLLING) {
|
|
|
|
error = ether_poll_register(em_poll, ifp);
|
|
|
|
if (error)
|
2006-02-15 08:39:50 +00:00
|
|
|
return (error);
|
|
|
|
EM_LOCK(sc);
|
|
|
|
em_disable_intr(sc);
|
Big polling(4) cleanup.
o Axe poll in trap.
o Axe IFF_POLLING flag from if_flags.
o Rework revision 1.21 (Giant removal), in such a way that
poll_mtx is not dropped during call to polling handler.
This fixes problem with idle polling.
o Make registration and deregistration from polling in a
functional way, insted of next tick/interrupt.
o Obsolete kern.polling.enable. Polling is turned on/off
with ifconfig.
Detailed kern_poll.c changes:
- Remove polling handler flags, introduced in 1.21. The are not
needed now.
- Forget and do not check if_flags, if_capenable and if_drv_flags.
- Call all registered polling handlers unconditionally.
- Do not drop poll_mtx, when entering polling handlers.
- In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx.
- In netisr_poll() axe the block, where polling code asks drivers
to unregister.
- In netisr_poll() and ether_poll() do polling always, if any
handlers are present.
- In ether_poll_[de]register() remove a lot of error hiding code. Assert
that arguments are correct, instead.
- In ether_poll_[de]register() use standard return values in case of
error or success.
- Introduce poll_switch() that is a sysctl handler for kern.polling.enable.
poll_switch() goes through interface list and enabled/disables polling.
A message that kern.polling.enable is deprecated is printed.
Detailed driver changes:
- On attach driver announces IFCAP_POLLING in if_capabilities, but
not in if_capenable.
- On detach driver calls ether_poll_deregister() if polling is enabled.
- In polling handler driver obtains its lock and checks IFF_DRV_RUNNING
flag. If there is no, then unlocks and returns.
- In ioctl handler driver checks for IFCAP_POLLING flag requested to
be set or cleared. Driver first calls ether_poll_[de]register(), then
obtains driver lock and [dis/en]ables interrupts.
- In interrupt handler driver checks IFCAP_POLLING flag in if_capenable.
If present, then returns.This is important to protect from spurious
interrupts.
Reviewed by: ru, sam, jhb
2005-10-01 18:56:19 +00:00
|
|
|
ifp->if_capenable |= IFCAP_POLLING;
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_UNLOCK(sc);
|
Big polling(4) cleanup.
o Axe poll in trap.
o Axe IFF_POLLING flag from if_flags.
o Rework revision 1.21 (Giant removal), in such a way that
poll_mtx is not dropped during call to polling handler.
This fixes problem with idle polling.
o Make registration and deregistration from polling in a
functional way, insted of next tick/interrupt.
o Obsolete kern.polling.enable. Polling is turned on/off
with ifconfig.
Detailed kern_poll.c changes:
- Remove polling handler flags, introduced in 1.21. The are not
needed now.
- Forget and do not check if_flags, if_capenable and if_drv_flags.
- Call all registered polling handlers unconditionally.
- Do not drop poll_mtx, when entering polling handlers.
- In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx.
- In netisr_poll() axe the block, where polling code asks drivers
to unregister.
- In netisr_poll() and ether_poll() do polling always, if any
handlers are present.
- In ether_poll_[de]register() remove a lot of error hiding code. Assert
that arguments are correct, instead.
- In ether_poll_[de]register() use standard return values in case of
error or success.
- Introduce poll_switch() that is a sysctl handler for kern.polling.enable.
poll_switch() goes through interface list and enabled/disables polling.
A message that kern.polling.enable is deprecated is printed.
Detailed driver changes:
- On attach driver announces IFCAP_POLLING in if_capabilities, but
not in if_capenable.
- On detach driver calls ether_poll_deregister() if polling is enabled.
- In polling handler driver obtains its lock and checks IFF_DRV_RUNNING
flag. If there is no, then unlocks and returns.
- In ioctl handler driver checks for IFCAP_POLLING flag requested to
be set or cleared. Driver first calls ether_poll_[de]register(), then
obtains driver lock and [dis/en]ables interrupts.
- In interrupt handler driver checks IFCAP_POLLING flag in if_capenable.
If present, then returns.This is important to protect from spurious
interrupts.
Reviewed by: ru, sam, jhb
2005-10-01 18:56:19 +00:00
|
|
|
} else {
|
|
|
|
error = ether_poll_deregister(ifp);
|
|
|
|
/* Enable interrupt even in error case */
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK(sc);
|
|
|
|
em_enable_intr(sc);
|
Big polling(4) cleanup.
o Axe poll in trap.
o Axe IFF_POLLING flag from if_flags.
o Rework revision 1.21 (Giant removal), in such a way that
poll_mtx is not dropped during call to polling handler.
This fixes problem with idle polling.
o Make registration and deregistration from polling in a
functional way, insted of next tick/interrupt.
o Obsolete kern.polling.enable. Polling is turned on/off
with ifconfig.
Detailed kern_poll.c changes:
- Remove polling handler flags, introduced in 1.21. The are not
needed now.
- Forget and do not check if_flags, if_capenable and if_drv_flags.
- Call all registered polling handlers unconditionally.
- Do not drop poll_mtx, when entering polling handlers.
- In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx.
- In netisr_poll() axe the block, where polling code asks drivers
to unregister.
- In netisr_poll() and ether_poll() do polling always, if any
handlers are present.
- In ether_poll_[de]register() remove a lot of error hiding code. Assert
that arguments are correct, instead.
- In ether_poll_[de]register() use standard return values in case of
error or success.
- Introduce poll_switch() that is a sysctl handler for kern.polling.enable.
poll_switch() goes through interface list and enabled/disables polling.
A message that kern.polling.enable is deprecated is printed.
Detailed driver changes:
- On attach driver announces IFCAP_POLLING in if_capabilities, but
not in if_capenable.
- On detach driver calls ether_poll_deregister() if polling is enabled.
- In polling handler driver obtains its lock and checks IFF_DRV_RUNNING
flag. If there is no, then unlocks and returns.
- In ioctl handler driver checks for IFCAP_POLLING flag requested to
be set or cleared. Driver first calls ether_poll_[de]register(), then
obtains driver lock and [dis/en]ables interrupts.
- In interrupt handler driver checks IFCAP_POLLING flag in if_capenable.
If present, then returns.This is important to protect from spurious
interrupts.
Reviewed by: ru, sam, jhb
2005-10-01 18:56:19 +00:00
|
|
|
ifp->if_capenable &= ~IFCAP_POLLING;
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_UNLOCK(sc);
|
Big polling(4) cleanup.
o Axe poll in trap.
o Axe IFF_POLLING flag from if_flags.
o Rework revision 1.21 (Giant removal), in such a way that
poll_mtx is not dropped during call to polling handler.
This fixes problem with idle polling.
o Make registration and deregistration from polling in a
functional way, insted of next tick/interrupt.
o Obsolete kern.polling.enable. Polling is turned on/off
with ifconfig.
Detailed kern_poll.c changes:
- Remove polling handler flags, introduced in 1.21. The are not
needed now.
- Forget and do not check if_flags, if_capenable and if_drv_flags.
- Call all registered polling handlers unconditionally.
- Do not drop poll_mtx, when entering polling handlers.
- In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx.
- In netisr_poll() axe the block, where polling code asks drivers
to unregister.
- In netisr_poll() and ether_poll() do polling always, if any
handlers are present.
- In ether_poll_[de]register() remove a lot of error hiding code. Assert
that arguments are correct, instead.
- In ether_poll_[de]register() use standard return values in case of
error or success.
- Introduce poll_switch() that is a sysctl handler for kern.polling.enable.
poll_switch() goes through interface list and enabled/disables polling.
A message that kern.polling.enable is deprecated is printed.
Detailed driver changes:
- On attach driver announces IFCAP_POLLING in if_capabilities, but
not in if_capenable.
- On detach driver calls ether_poll_deregister() if polling is enabled.
- In polling handler driver obtains its lock and checks IFF_DRV_RUNNING
flag. If there is no, then unlocks and returns.
- In ioctl handler driver checks for IFCAP_POLLING flag requested to
be set or cleared. Driver first calls ether_poll_[de]register(), then
obtains driver lock and [dis/en]ables interrupts.
- In interrupt handler driver checks IFCAP_POLLING flag in if_capenable.
If present, then returns.This is important to protect from spurious
interrupts.
Reviewed by: ru, sam, jhb
2005-10-01 18:56:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2002-06-03 22:30:51 +00:00
|
|
|
if (mask & IFCAP_HWCSUM) {
|
2004-04-11 21:01:12 +00:00
|
|
|
ifp->if_capenable ^= IFCAP_HWCSUM;
|
2004-06-04 16:57:18 +00:00
|
|
|
reinit = 1;
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
2004-06-04 16:57:18 +00:00
|
|
|
if (mask & IFCAP_VLAN_HWTAGGING) {
|
|
|
|
ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
|
|
|
|
reinit = 1;
|
|
|
|
}
|
2005-08-09 10:20:02 +00:00
|
|
|
if (reinit && (ifp->if_drv_flags & IFF_DRV_RUNNING))
|
2006-02-15 08:39:50 +00:00
|
|
|
em_init(sc);
|
2006-01-30 13:45:55 +00:00
|
|
|
VLAN_CAPABILITIES(ifp);
|
2002-06-03 22:30:51 +00:00
|
|
|
break;
|
2005-11-24 01:44:49 +00:00
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
default:
|
2006-07-20 04:18:45 +00:00
|
|
|
error = ether_ioctl(ifp, command, data);
|
|
|
|
break;
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
return (error);
|
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)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc = ifp->if_softc;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK(sc);
|
2002-06-03 22:30:51 +00:00
|
|
|
/* If we are in this routine because of pause frames, then
|
|
|
|
* don't reset the hardware.
|
|
|
|
*/
|
2006-02-15 08:39:50 +00:00
|
|
|
if (E1000_READ_REG(&sc->hw, STATUS) & E1000_STATUS_TXOFF) {
|
2002-06-03 22:30:51 +00:00
|
|
|
ifp->if_timer = EM_TX_TIMEOUT;
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_UNLOCK(sc);
|
2002-06-03 22:30:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (em_check_for_link(&sc->hw) == 0)
|
|
|
|
device_printf(sc->dev, "watchdog timeout -- resetting\n");
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->watchdog_events++;
|
2005-10-20 09:55:49 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
em_init_locked(sc);
|
|
|
|
EM_UNLOCK(sc);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* 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
|
2006-01-20 11:38:25 +00:00
|
|
|
* by the driver as a hw/sw initialization routine to get to a
|
2001-12-02 07:37:17 +00:00
|
|
|
* consistent state.
|
|
|
|
*
|
|
|
|
* return 0 on success, positive on failure
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_init_locked(struct em_softc *sc)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct ifnet *ifp = sc->ifp;
|
|
|
|
device_t dev = sc->dev;
|
2004-09-01 23:22:41 +00:00
|
|
|
uint32_t pba;
|
2004-06-04 16:57:18 +00:00
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
INIT_DEBUGOUT("em_init: begin");
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK_ASSERT(sc);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
em_stop(sc);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2005-11-24 01:44:49 +00:00
|
|
|
/*
|
|
|
|
* Packet Buffer Allocation (PBA)
|
2004-09-01 23:22:41 +00:00
|
|
|
* Writing PBA sets the receive portion of the buffer
|
|
|
|
* the remainder is used for the transmit buffer.
|
|
|
|
*/
|
2006-02-15 08:39:50 +00:00
|
|
|
switch (sc->hw.mac_type) {
|
2005-11-24 01:44:49 +00:00
|
|
|
case em_82547:
|
|
|
|
case em_82547_rev_2: /* 82547: Total Packet Buffer is 40K */
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->hw.max_frame_size > EM_RXBUFFER_8192)
|
2004-09-01 23:22:41 +00:00
|
|
|
pba = E1000_PBA_22K; /* 22K for Rx, 18K for Tx */
|
2005-11-24 01:44:49 +00:00
|
|
|
else
|
|
|
|
pba = E1000_PBA_30K; /* 30K for Rx, 10K for Tx */
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->tx_fifo_head = 0;
|
|
|
|
sc->tx_head_addr = pba << EM_TX_HEAD_ADDR_SHIFT;
|
|
|
|
sc->tx_fifo_size = (E1000_PBA_40K - pba) << EM_PBA_BYTES_SHIFT;
|
2005-11-24 01:44:49 +00:00
|
|
|
break;
|
2006-04-06 17:09:03 +00:00
|
|
|
case em_80003es2lan: /* 80003es2lan: Total Packet Buffer is 48K */
|
2005-11-24 01:44:49 +00:00
|
|
|
case em_82571: /* 82571: Total Packet Buffer is 48K */
|
|
|
|
case em_82572: /* 82572: Total Packet Buffer is 48K */
|
|
|
|
pba = E1000_PBA_32K; /* 32K for Rx, 16K for Tx */
|
|
|
|
break;
|
|
|
|
case em_82573: /* 82573: Total Packet Buffer is 32K */
|
|
|
|
/* Jumbo frames not supported */
|
|
|
|
pba = E1000_PBA_12K; /* 12K for Rx, 20K for Tx */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Devices before 82547 had a Packet Buffer of 64K. */
|
2006-02-15 08:39:50 +00:00
|
|
|
if(sc->hw.max_frame_size > EM_RXBUFFER_8192)
|
2005-11-24 01:44:49 +00:00
|
|
|
pba = E1000_PBA_40K; /* 40K for Rx, 24K for Tx */
|
|
|
|
else
|
|
|
|
pba = E1000_PBA_48K; /* 48K for Rx, 16K for Tx */
|
2004-09-01 23:22:41 +00:00
|
|
|
}
|
2005-11-24 01:44:49 +00:00
|
|
|
|
2004-09-01 23:22:41 +00:00
|
|
|
INIT_DEBUGOUT1("em_init: pba=%dK",pba);
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, PBA, pba);
|
2004-09-01 23:22:41 +00:00
|
|
|
|
2003-11-14 18:02:25 +00:00
|
|
|
/* Get the latest mac address, User can use a LAA */
|
2006-02-15 08:39:50 +00:00
|
|
|
bcopy(IF_LLADDR(sc->ifp), sc->hw.mac_addr, ETHER_ADDR_LEN);
|
2006-02-22 14:11:16 +00:00
|
|
|
|
|
|
|
/* Initialize the hardware */
|
|
|
|
if (em_hardware_init(sc)) {
|
|
|
|
device_printf(dev, "Unable to initialize the hardware\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
em_update_link_status(sc);
|
2003-11-14 18:02:25 +00:00
|
|
|
|
2004-06-04 16:57:18 +00:00
|
|
|
if (ifp->if_capenable & IFCAP_VLAN_HWTAGGING)
|
2006-02-15 08:39:50 +00:00
|
|
|
em_enable_vlans(sc);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Prepare transmit descriptors and buffers */
|
2006-02-15 08:39:50 +00:00
|
|
|
if (em_setup_transmit_structures(sc)) {
|
|
|
|
device_printf(dev, "Could not setup transmit structures\n");
|
|
|
|
em_stop(sc);
|
2002-06-03 22:30:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-02-15 08:39:50 +00:00
|
|
|
em_initialize_transmit_unit(sc);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Setup Multicast table */
|
2006-02-15 08:39:50 +00:00
|
|
|
em_set_multi(sc);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Prepare receive descriptors and buffers */
|
2006-02-15 08:39:50 +00:00
|
|
|
if (em_setup_receive_structures(sc)) {
|
|
|
|
device_printf(dev, "Could not setup receive structures\n");
|
|
|
|
em_stop(sc);
|
2002-06-03 22:30:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-02-15 08:39:50 +00:00
|
|
|
em_initialize_receive_unit(sc);
|
2006-01-20 11:38:25 +00:00
|
|
|
|
2003-11-14 18:02:25 +00:00
|
|
|
/* Don't loose promiscuous settings */
|
2006-02-15 08:39:50 +00:00
|
|
|
em_set_promisc(sc);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->hw.mac_type >= em_82543) {
|
2002-06-03 22:30:51 +00:00
|
|
|
if (ifp->if_capenable & IFCAP_TXCSUM)
|
|
|
|
ifp->if_hwassist = EM_CHECKSUM_FEATURES;
|
|
|
|
else
|
|
|
|
ifp->if_hwassist = 0;
|
|
|
|
}
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
callout_reset(&sc->timer, hz, em_local_timer, sc);
|
|
|
|
em_clear_hw_cntrs(&sc->hw);
|
2002-11-25 19:56:16 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
2006-02-15 08:39:50 +00:00
|
|
|
/*
|
|
|
|
* Only enable interrupts if we are not polling, make sure
|
|
|
|
* they are off otherwise.
|
|
|
|
*/
|
|
|
|
if (ifp->if_capenable & IFCAP_POLLING)
|
|
|
|
em_disable_intr(sc);
|
|
|
|
else
|
2002-11-25 19:56:16 +00:00
|
|
|
#endif /* DEVICE_POLLING */
|
2006-02-15 08:39:50 +00:00
|
|
|
em_enable_intr(sc);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2004-02-10 21:31:09 +00:00
|
|
|
/* Don't reset the phy next time init gets called */
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.phy_reset_disable = TRUE;
|
2003-09-23 00:18:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
em_init(void *arg)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc = arg;
|
2003-09-23 00:18:25 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK(sc);
|
|
|
|
em_init_locked(sc);
|
|
|
|
EM_UNLOCK(sc);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
|
2002-11-25 19:56:16 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
2006-06-06 08:03:49 +00:00
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Legacy polling routine
|
|
|
|
*
|
|
|
|
*********************************************************************/
|
2006-01-20 11:38:25 +00:00
|
|
|
static void
|
2006-06-06 08:03:49 +00:00
|
|
|
em_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
|
2002-11-25 19:56:16 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc = ifp->if_softc;
|
2006-01-20 11:38:25 +00:00
|
|
|
uint32_t reg_icr;
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2006-06-06 08:03:49 +00:00
|
|
|
EM_LOCK(sc);
|
|
|
|
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
|
|
|
|
EM_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
2003-09-23 00:18:25 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
if (cmd == POLL_AND_CHECK_STATUS) {
|
2006-02-15 08:39:50 +00:00
|
|
|
reg_icr = E1000_READ_REG(&sc->hw, ICR);
|
2006-01-20 11:38:25 +00:00
|
|
|
if (reg_icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
|
2006-02-15 08:39:50 +00:00
|
|
|
callout_stop(&sc->timer);
|
|
|
|
sc->hw.get_link_status = 1;
|
|
|
|
em_check_for_link(&sc->hw);
|
2006-02-15 10:51:11 +00:00
|
|
|
em_update_link_status(sc);
|
2006-02-15 08:39:50 +00:00
|
|
|
callout_reset(&sc->timer, hz, em_local_timer, sc);
|
2006-01-20 11:38:25 +00:00
|
|
|
}
|
2006-02-15 08:39:50 +00:00
|
|
|
}
|
|
|
|
em_rxeof(sc, count);
|
|
|
|
em_txeof(sc);
|
2006-01-20 11:38:25 +00:00
|
|
|
|
|
|
|
if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
|
|
|
|
em_start_locked(ifp);
|
2006-06-06 08:03:49 +00:00
|
|
|
EM_UNLOCK(sc);
|
2003-09-23 00:18:25 +00:00
|
|
|
}
|
2006-01-20 11:38:25 +00:00
|
|
|
|
2006-06-06 08:03:49 +00:00
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Legacy Interrupt Service routine
|
|
|
|
*
|
|
|
|
*********************************************************************/
|
2006-01-20 11:38:25 +00:00
|
|
|
static void
|
2006-06-06 08:03:49 +00:00
|
|
|
em_intr(void *arg)
|
2003-09-23 00:18:25 +00:00
|
|
|
{
|
2006-06-06 08:03:49 +00:00
|
|
|
struct em_softc *sc = arg;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
uint32_t reg_icr;
|
2003-09-23 00:18:25 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK(sc);
|
2006-06-06 08:03:49 +00:00
|
|
|
|
|
|
|
ifp = sc->ifp;
|
|
|
|
|
|
|
|
if (ifp->if_capenable & IFCAP_POLLING) {
|
|
|
|
EM_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
reg_icr = E1000_READ_REG(&sc->hw, ICR);
|
|
|
|
if (sc->hw.mac_type >= em_82571 &&
|
|
|
|
(reg_icr & E1000_ICR_INT_ASSERTED) == 0)
|
|
|
|
break;
|
|
|
|
else if (reg_icr == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: some laptops trigger several spurious interrupts
|
|
|
|
* on em(4) when in the resume cycle. The ICR register
|
|
|
|
* reports all-ones value in this case. Processing such
|
|
|
|
* interrupts would lead to a freeze. I don't know why.
|
|
|
|
*/
|
|
|
|
if (reg_icr == 0xffffffff)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
|
|
|
|
em_rxeof(sc, -1);
|
|
|
|
em_txeof(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Link status change */
|
|
|
|
if (reg_icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
|
|
|
|
callout_stop(&sc->timer);
|
|
|
|
sc->hw.get_link_status = 1;
|
|
|
|
em_check_for_link(&sc->hw);
|
|
|
|
em_update_link_status(sc);
|
|
|
|
callout_reset(&sc->timer, hz, em_local_timer, sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reg_icr & E1000_ICR_RXO)
|
|
|
|
sc->rx_overruns++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
|
|
|
|
!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
|
|
|
|
em_start_locked(ifp);
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_UNLOCK(sc);
|
2002-11-25 19:56:16 +00:00
|
|
|
}
|
|
|
|
|
2006-06-06 08:03:49 +00:00
|
|
|
#else /* if not DEVICE_POLLING, then fast interrupt routines only */
|
|
|
|
|
2006-01-11 00:30:25 +00:00
|
|
|
static void
|
|
|
|
em_handle_link(void *context, int pending)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc = context;
|
2006-01-11 00:30:25 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
ifp = sc->ifp;
|
2006-01-11 00:30:25 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK(sc);
|
2006-01-11 00:30:25 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
callout_stop(&sc->timer);
|
|
|
|
sc->hw.get_link_status = 1;
|
|
|
|
em_check_for_link(&sc->hw);
|
2006-02-15 10:51:11 +00:00
|
|
|
em_update_link_status(sc);
|
2006-02-15 08:39:50 +00:00
|
|
|
callout_reset(&sc->timer, hz, em_local_timer, sc);
|
|
|
|
EM_UNLOCK(sc);
|
2006-01-11 00:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
em_handle_rxtx(void *context, int pending)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc = context;
|
2006-01-11 00:30:25 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
|
2006-02-07 13:11:13 +00:00
|
|
|
NET_LOCK_GIANT();
|
2006-02-15 08:39:50 +00:00
|
|
|
ifp = sc->ifp;
|
2006-01-11 00:30:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO:
|
|
|
|
* It should be possible to run the tx clean loop without the lock.
|
|
|
|
*/
|
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
|
2006-02-15 08:39:50 +00:00
|
|
|
if (em_rxeof(sc, sc->rx_process_limit) != 0)
|
|
|
|
taskqueue_enqueue(sc->tq, &sc->rxtx_task);
|
|
|
|
EM_LOCK(sc);
|
|
|
|
em_txeof(sc);
|
2006-01-11 00:30:25 +00:00
|
|
|
|
|
|
|
if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
|
|
|
|
em_start_locked(ifp);
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_UNLOCK(sc);
|
2006-01-11 00:30:25 +00:00
|
|
|
}
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
em_enable_intr(sc);
|
2006-02-07 13:11:13 +00:00
|
|
|
NET_UNLOCK_GIANT();
|
2006-01-11 00:30:25 +00:00
|
|
|
}
|
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
/*********************************************************************
|
|
|
|
*
|
2006-06-06 08:03:49 +00:00
|
|
|
* Fast Interrupt Service routine
|
2001-12-02 07:37:17 +00:00
|
|
|
*
|
2006-06-06 08:03:49 +00:00
|
|
|
*********************************************************************/
|
2006-01-11 00:30:25 +00:00
|
|
|
static void
|
|
|
|
em_intr_fast(void *arg)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc = arg;
|
2006-01-11 00:30:25 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
uint32_t reg_icr;
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
ifp = sc->ifp;
|
2006-01-11 00:30:25 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
reg_icr = E1000_READ_REG(&sc->hw, ICR);
|
2006-01-11 00:30:25 +00:00
|
|
|
|
|
|
|
/* Hot eject? */
|
|
|
|
if (reg_icr == 0xffffffff)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Definitely not our interrupt. */
|
|
|
|
if (reg_icr == 0x0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Starting with the 82571 chip, bit 31 should be used to
|
|
|
|
* determine whether the interrupt belongs to us.
|
|
|
|
*/
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->hw.mac_type >= em_82571 &&
|
2006-01-11 00:30:25 +00:00
|
|
|
(reg_icr & E1000_ICR_INT_ASSERTED) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mask interrupts until the taskqueue is finished running. This is
|
|
|
|
* cheap, just assume that it is needed. This also works around the
|
|
|
|
* MSI message reordering errata on certain systems.
|
|
|
|
*/
|
2006-02-15 08:39:50 +00:00
|
|
|
em_disable_intr(sc);
|
|
|
|
taskqueue_enqueue(sc->tq, &sc->rxtx_task);
|
2006-01-11 00:30:25 +00:00
|
|
|
|
|
|
|
/* Link status change */
|
|
|
|
if (reg_icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))
|
2006-02-15 08:39:50 +00:00
|
|
|
taskqueue_enqueue(taskqueue_fast, &sc->link_task);
|
2006-01-11 00:30:25 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (reg_icr & E1000_ICR_RXO)
|
|
|
|
sc->rx_overruns++;
|
2006-01-11 00:30:25 +00:00
|
|
|
}
|
2006-06-06 08:03:49 +00:00
|
|
|
#endif /* ! DEVICE_POLLING */
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc = ifp->if_softc;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
INIT_DEBUGOUT("em_media_status: begin");
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
em_check_for_link(&sc->hw);
|
2006-02-15 10:51:11 +00:00
|
|
|
em_update_link_status(sc);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
ifmr->ifm_status = IFM_AVALID;
|
|
|
|
ifmr->ifm_active = IFM_ETHER;
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (!sc->link_active)
|
2002-11-08 18:14:17 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
ifmr->ifm_status |= IFM_ACTIVE;
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->hw.media_type == em_media_type_fiber) {
|
2002-11-08 18:14:17 +00:00
|
|
|
ifmr->ifm_active |= IFM_1000_SX | IFM_FDX;
|
|
|
|
} else {
|
2006-02-15 08:39:50 +00:00
|
|
|
switch (sc->link_speed) {
|
2002-11-08 18:14: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_T;
|
|
|
|
break;
|
|
|
|
}
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->link_duplex == FULL_DUPLEX)
|
2002-11-08 18:14:17 +00:00
|
|
|
ifmr->ifm_active |= IFM_FDX;
|
|
|
|
else
|
|
|
|
ifmr->ifm_active |= IFM_HDX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc = ifp->if_softc;
|
|
|
|
struct ifmedia *ifm = &sc->media;
|
2002-11-08 18:14:17 +00:00
|
|
|
|
|
|
|
INIT_DEBUGOUT("em_media_change: begin");
|
|
|
|
|
|
|
|
if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
|
2006-02-15 08:39:50 +00:00
|
|
|
return (EINVAL);
|
2002-11-08 18:14:17 +00:00
|
|
|
|
|
|
|
switch (IFM_SUBTYPE(ifm->ifm_media)) {
|
|
|
|
case IFM_AUTO:
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.autoneg = DO_AUTO_NEG;
|
|
|
|
sc->hw.autoneg_advertised = AUTONEG_ADV_DEFAULT;
|
2002-11-08 18:14:17 +00:00
|
|
|
break;
|
|
|
|
case IFM_1000_SX:
|
|
|
|
case IFM_1000_T:
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.autoneg = DO_AUTO_NEG;
|
|
|
|
sc->hw.autoneg_advertised = ADVERTISE_1000_FULL;
|
2002-11-08 18:14:17 +00:00
|
|
|
break;
|
|
|
|
case IFM_100_TX:
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.autoneg = FALSE;
|
|
|
|
sc->hw.autoneg_advertised = 0;
|
2002-11-08 18:14:17 +00:00
|
|
|
if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX)
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.forced_speed_duplex = em_100_full;
|
2002-11-08 18:14:17 +00:00
|
|
|
else
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.forced_speed_duplex = em_100_half;
|
2002-11-08 18:14:17 +00:00
|
|
|
break;
|
|
|
|
case IFM_10_T:
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.autoneg = FALSE;
|
|
|
|
sc->hw.autoneg_advertised = 0;
|
2002-11-08 18:14:17 +00:00
|
|
|
if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX)
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.forced_speed_duplex = em_10_full;
|
2002-11-08 18:14:17 +00:00
|
|
|
else
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.forced_speed_duplex = em_10_half;
|
2002-11-08 18:14:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
2006-02-15 08:39:50 +00:00
|
|
|
device_printf(sc->dev, "Unsupported media type\n");
|
2002-11-08 18:14:17 +00:00
|
|
|
}
|
|
|
|
|
2004-02-10 21:31:09 +00:00
|
|
|
/* As the speed/duplex settings my have changed we need to
|
|
|
|
* reset the PHY.
|
|
|
|
*/
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.phy_reset_disable = FALSE;
|
2004-02-10 21:31:09 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
em_init(sc);
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
return (0);
|
2002-11-08 18:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* This routine maps the mbufs to tx descriptors.
|
|
|
|
*
|
|
|
|
* return 0 on success, positive on failure
|
|
|
|
**********************************************************************/
|
2006-01-20 11:38:25 +00:00
|
|
|
static int
|
2006-02-15 08:39:50 +00:00
|
|
|
em_encap(struct em_softc *sc, struct mbuf **m_headp)
|
2003-05-02 21:17:08 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct ifnet *ifp = sc->ifp;
|
2005-01-15 20:52:15 +00:00
|
|
|
bus_dma_segment_t segs[EM_MAX_SCATTER];
|
2006-01-20 11:38:25 +00:00
|
|
|
bus_dmamap_t map;
|
2006-07-27 00:26:20 +00:00
|
|
|
struct em_buffer *tx_buffer, *tx_buffer_last;
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_tx_desc *current_tx_desc;
|
2006-01-20 11:38:25 +00:00
|
|
|
struct mbuf *m_head;
|
2006-02-15 08:39:50 +00:00
|
|
|
struct m_tag *mtag;
|
2006-01-20 11:38:25 +00:00
|
|
|
uint32_t txd_upper, txd_lower, txd_used, txd_saved;
|
|
|
|
int nsegs, i, j;
|
2006-07-27 00:26:20 +00:00
|
|
|
int error;
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2004-11-12 11:03:07 +00:00
|
|
|
m_head = *m_headp;
|
2006-01-20 11:38:25 +00:00
|
|
|
current_tx_desc = NULL;
|
|
|
|
txd_used = txd_saved = 0;
|
2004-11-12 11:03:07 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
/*
|
|
|
|
* Force a cleanup if number of TX descriptors
|
|
|
|
* available hits the threshold.
|
|
|
|
*/
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->num_tx_desc_avail <= EM_TX_CLEANUP_THRESHOLD) {
|
|
|
|
em_txeof(sc);
|
|
|
|
if (sc->num_tx_desc_avail <= EM_TX_CLEANUP_THRESHOLD) {
|
|
|
|
sc->no_tx_desc_avail1++;
|
|
|
|
return (ENOBUFS);
|
2006-01-20 11:38:25 +00:00
|
|
|
}
|
|
|
|
}
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
/* Find out if we are in vlan mode. */
|
|
|
|
mtag = VLAN_OUTPUT_TAG(ifp, m_head);
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2004-11-12 11:03:07 +00:00
|
|
|
/*
|
|
|
|
* When operating in promiscuous mode, hardware encapsulation for
|
|
|
|
* packets is disabled. This means we have to add the vlan
|
|
|
|
* encapsulation in the driver, since it will have come down from the
|
|
|
|
* VLAN layer with a tag instead of a VLAN header.
|
|
|
|
*/
|
2006-02-15 08:39:50 +00:00
|
|
|
if (mtag != NULL && sc->em_insert_vlan_header) {
|
2004-11-12 11:03:07 +00:00
|
|
|
struct ether_vlan_header *evl;
|
|
|
|
struct ether_header eh;
|
|
|
|
|
|
|
|
m_head = m_pullup(m_head, sizeof(eh));
|
2004-11-14 20:20:28 +00:00
|
|
|
if (m_head == NULL) {
|
|
|
|
*m_headp = NULL;
|
2006-07-27 00:43:34 +00:00
|
|
|
return (ENOBUFS);
|
2004-11-14 20:20:28 +00:00
|
|
|
}
|
2004-11-12 11:03:07 +00:00
|
|
|
eh = *mtod(m_head, struct ether_header *);
|
|
|
|
M_PREPEND(m_head, sizeof(*evl), M_DONTWAIT);
|
2004-11-14 20:20:28 +00:00
|
|
|
if (m_head == NULL) {
|
|
|
|
*m_headp = NULL;
|
2006-07-27 00:43:34 +00:00
|
|
|
return (ENOBUFS);
|
2004-11-14 20:20:28 +00:00
|
|
|
}
|
2004-11-12 11:03:07 +00:00
|
|
|
m_head = m_pullup(m_head, sizeof(*evl));
|
2004-11-14 20:20:28 +00:00
|
|
|
if (m_head == NULL) {
|
|
|
|
*m_headp = NULL;
|
2006-07-27 00:43:34 +00:00
|
|
|
return (ENOBUFS);
|
2004-11-14 20:20:28 +00:00
|
|
|
}
|
2004-11-12 11:03:07 +00:00
|
|
|
evl = mtod(m_head, struct ether_vlan_header *);
|
|
|
|
bcopy(&eh, evl, sizeof(*evl));
|
|
|
|
evl->evl_proto = evl->evl_encap_proto;
|
|
|
|
evl->evl_encap_proto = htons(ETHERTYPE_VLAN);
|
|
|
|
evl->evl_tag = htons(VLAN_TAG_VALUE(mtag));
|
|
|
|
m_tag_delete(m_head, mtag);
|
|
|
|
mtag = NULL;
|
|
|
|
*m_headp = m_head;
|
|
|
|
}
|
|
|
|
|
2006-07-27 00:43:34 +00:00
|
|
|
/*
|
|
|
|
* Map the packet for DMA.
|
|
|
|
*/
|
|
|
|
tx_buffer = &sc->tx_buffer_area[sc->next_avail_tx_desc];
|
|
|
|
tx_buffer_last = tx_buffer;
|
|
|
|
map = tx_buffer->map;
|
|
|
|
error = bus_dmamap_load_mbuf_sg(sc->txtag, map, m_head, segs, &nsegs,
|
|
|
|
BUS_DMA_NOWAIT);
|
|
|
|
if (error != 0) {
|
|
|
|
sc->no_tx_dma_setup++;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
KASSERT(nsegs != 0, ("em_encap: empty packet"));
|
|
|
|
|
|
|
|
if (nsegs > sc->num_tx_desc_avail) {
|
|
|
|
sc->no_tx_desc_avail2++;
|
|
|
|
error = ENOBUFS;
|
|
|
|
goto encap_fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ifp->if_hwassist > 0)
|
|
|
|
em_transmit_checksum_setup(sc, m_head, &txd_upper, &txd_lower);
|
|
|
|
else
|
|
|
|
txd_upper = txd_lower = 0;
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
i = sc->next_avail_tx_desc;
|
|
|
|
if (sc->pcix_82544) {
|
2003-08-27 21:52:37 +00:00
|
|
|
txd_saved = i;
|
|
|
|
txd_used = 0;
|
|
|
|
}
|
2006-01-20 11:38:25 +00:00
|
|
|
for (j = 0; j < nsegs; j++) {
|
|
|
|
/* If adapter is 82544 and on PCIX bus. */
|
2006-02-15 08:39:50 +00:00
|
|
|
if(sc->pcix_82544) {
|
2006-01-20 11:38:25 +00:00
|
|
|
DESC_ARRAY desc_array;
|
|
|
|
uint32_t array_elements, counter;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the Address and Length combination and
|
|
|
|
* split the data accordingly
|
2003-08-27 21:52:37 +00:00
|
|
|
*/
|
2006-01-20 11:38:25 +00:00
|
|
|
array_elements = em_fill_descriptors(segs[j].ds_addr,
|
2005-11-09 08:43:18 +00:00
|
|
|
segs[j].ds_len, &desc_array);
|
2003-08-27 21:52:37 +00:00
|
|
|
for (counter = 0; counter < array_elements; counter++) {
|
2006-02-15 08:39:50 +00:00
|
|
|
if (txd_used == sc->num_tx_desc_avail) {
|
|
|
|
sc->next_avail_tx_desc = txd_saved;
|
|
|
|
sc->no_tx_desc_avail2++;
|
2005-11-21 04:17:43 +00:00
|
|
|
error = ENOBUFS;
|
|
|
|
goto encap_fail;
|
2006-01-20 11:38:25 +00:00
|
|
|
}
|
2006-02-15 08:39:50 +00:00
|
|
|
tx_buffer = &sc->tx_buffer_area[i];
|
|
|
|
current_tx_desc = &sc->tx_desc_base[i];
|
2006-01-20 11:38:25 +00:00
|
|
|
current_tx_desc->buffer_addr = htole64(
|
2003-08-27 21:52:37 +00:00
|
|
|
desc_array.descriptor[counter].address);
|
2006-01-20 11:38:25 +00:00
|
|
|
current_tx_desc->lower.data = htole32(
|
2006-02-15 08:39:50 +00:00
|
|
|
(sc->txd_cmd | txd_lower |
|
2006-01-20 11:38:25 +00:00
|
|
|
(uint16_t)desc_array.descriptor[counter].length));
|
|
|
|
current_tx_desc->upper.data = htole32((txd_upper));
|
2006-02-15 08:39:50 +00:00
|
|
|
if (++i == sc->num_tx_desc)
|
2006-01-20 11:38:25 +00:00
|
|
|
i = 0;
|
|
|
|
|
|
|
|
tx_buffer->m_head = NULL;
|
|
|
|
txd_used++;
|
|
|
|
}
|
2003-08-27 21:52:37 +00:00
|
|
|
} else {
|
2006-02-15 08:39:50 +00:00
|
|
|
tx_buffer = &sc->tx_buffer_area[i];
|
|
|
|
current_tx_desc = &sc->tx_desc_base[i];
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2005-01-15 20:52:15 +00:00
|
|
|
current_tx_desc->buffer_addr = htole64(segs[j].ds_addr);
|
2003-08-27 21:52:37 +00:00
|
|
|
current_tx_desc->lower.data = htole32(
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->txd_cmd | txd_lower | segs[j].ds_len);
|
2003-08-27 21:52:37 +00:00
|
|
|
current_tx_desc->upper.data = htole32(txd_upper);
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (++i == sc->num_tx_desc)
|
2003-08-27 21:52:37 +00:00
|
|
|
i = 0;
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2003-08-27 21:52:37 +00:00
|
|
|
tx_buffer->m_head = NULL;
|
|
|
|
}
|
2006-01-20 11:38:25 +00:00
|
|
|
}
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->next_avail_tx_desc = i;
|
|
|
|
if (sc->pcix_82544)
|
|
|
|
sc->num_tx_desc_avail -= txd_used;
|
2006-01-20 11:38:25 +00:00
|
|
|
else
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->num_tx_desc_avail -= nsegs;
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
if (mtag != NULL) {
|
|
|
|
/* Set the vlan id. */
|
|
|
|
current_tx_desc->upper.fields.special =
|
|
|
|
htole16(VLAN_TAG_VALUE(mtag));
|
2003-05-02 21:17:08 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
/* Tell hardware to add tag. */
|
|
|
|
current_tx_desc->lower.data |= htole32(E1000_TXD_CMD_VLE);
|
|
|
|
}
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
tx_buffer->m_head = m_head;
|
2006-07-27 00:26:20 +00:00
|
|
|
tx_buffer_last->map = tx_buffer->map;
|
|
|
|
tx_buffer->map = map;
|
2006-02-15 08:39:50 +00:00
|
|
|
bus_dmamap_sync(sc->txtag, map, BUS_DMASYNC_PREWRITE);
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
/*
|
|
|
|
* Last Descriptor of Packet needs End Of Packet (EOP).
|
|
|
|
*/
|
|
|
|
current_tx_desc->lower.data |= htole32(E1000_TXD_CMD_EOP);
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
/*
|
|
|
|
* Advance the Transmit Descriptor Tail (Tdt), this tells the E1000
|
|
|
|
* that this frame is available to transmit.
|
|
|
|
*/
|
2006-02-15 08:39:50 +00:00
|
|
|
bus_dmamap_sync(sc->txdma.dma_tag, sc->txdma.dma_map,
|
|
|
|
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
|
|
|
if (sc->hw.mac_type == em_82547 && sc->link_duplex == HALF_DUPLEX)
|
|
|
|
em_82547_move_tail_locked(sc);
|
|
|
|
else {
|
|
|
|
E1000_WRITE_REG(&sc->hw, TDT, i);
|
|
|
|
if (sc->hw.mac_type == em_82547)
|
|
|
|
em_82547_update_fifo_head(sc, m_head->m_pkthdr.len);
|
2006-01-20 11:38:25 +00:00
|
|
|
}
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
return (0);
|
2005-11-21 04:17:43 +00:00
|
|
|
|
|
|
|
encap_fail:
|
2006-07-27 00:26:20 +00:00
|
|
|
bus_dmamap_unload(sc->txtag, map);
|
2005-11-21 04:17:43 +00:00
|
|
|
return (error);
|
2003-05-02 21:17:08 +00:00
|
|
|
}
|
2003-03-21 21:47:31 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* 82547 workaround to avoid controller hang in half-duplex environment.
|
2006-01-20 11:38:25 +00:00
|
|
|
* The workaround is to avoid queuing a large packet that would span
|
2003-03-21 21:47:31 +00:00
|
|
|
* the internal Tx FIFO ring boundary. We need to reset the FIFO pointers
|
2003-10-10 23:14:21 +00:00
|
|
|
* in this case. We do that only when FIFO is quiescent.
|
2003-03-21 21:47:31 +00:00
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_82547_move_tail_locked(struct em_softc *sc)
|
2003-03-21 21:47:31 +00:00
|
|
|
{
|
|
|
|
uint16_t hw_tdt;
|
|
|
|
uint16_t sw_tdt;
|
|
|
|
struct em_tx_desc *tx_desc;
|
|
|
|
uint16_t length = 0;
|
|
|
|
boolean_t eop = 0;
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK_ASSERT(sc);
|
2003-10-10 23:14:21 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
hw_tdt = E1000_READ_REG(&sc->hw, TDT);
|
|
|
|
sw_tdt = sc->next_avail_tx_desc;
|
2003-03-21 21:47:31 +00:00
|
|
|
|
|
|
|
while (hw_tdt != sw_tdt) {
|
2006-02-15 08:39:50 +00:00
|
|
|
tx_desc = &sc->tx_desc_base[hw_tdt];
|
2003-03-21 21:47:31 +00:00
|
|
|
length += tx_desc->lower.flags.length;
|
|
|
|
eop = tx_desc->lower.data & E1000_TXD_CMD_EOP;
|
2006-02-15 08:39:50 +00:00
|
|
|
if(++hw_tdt == sc->num_tx_desc)
|
2003-03-21 21:47:31 +00:00
|
|
|
hw_tdt = 0;
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (eop) {
|
|
|
|
if (em_82547_fifo_workaround(sc, length)) {
|
|
|
|
sc->tx_fifo_wrk_cnt++;
|
|
|
|
callout_reset(&sc->tx_fifo_timer, 1,
|
|
|
|
em_82547_move_tail, sc);
|
2003-09-23 00:18:25 +00:00
|
|
|
break;
|
2003-03-21 21:47:31 +00:00
|
|
|
}
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, TDT, hw_tdt);
|
|
|
|
em_82547_update_fifo_head(sc, length);
|
2003-09-23 00:18:25 +00:00
|
|
|
length = 0;
|
2003-03-21 21:47:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-15 05:34:41 +00:00
|
|
|
static void
|
|
|
|
em_82547_move_tail(void *arg)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc = arg;
|
2003-10-15 05:34:41 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK(sc);
|
|
|
|
em_82547_move_tail_locked(sc);
|
|
|
|
EM_UNLOCK(sc);
|
2003-10-15 05:34:41 +00:00
|
|
|
}
|
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
static int
|
2006-02-15 08:39:50 +00:00
|
|
|
em_82547_fifo_workaround(struct em_softc *sc, int len)
|
2003-03-21 21:47:31 +00:00
|
|
|
{
|
|
|
|
int fifo_space, fifo_pkt_len;
|
|
|
|
|
2005-11-21 04:17:43 +00:00
|
|
|
fifo_pkt_len = roundup2(len + EM_FIFO_HDR, EM_FIFO_HDR);
|
2003-03-21 21:47:31 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->link_duplex == HALF_DUPLEX) {
|
|
|
|
fifo_space = sc->tx_fifo_size - sc->tx_fifo_head;
|
2003-03-21 21:47:31 +00:00
|
|
|
|
|
|
|
if (fifo_pkt_len >= (EM_82547_PKT_THRESH + fifo_space)) {
|
2006-02-15 08:39:50 +00:00
|
|
|
if (em_82547_tx_fifo_reset(sc))
|
|
|
|
return (0);
|
2006-01-20 11:38:25 +00:00
|
|
|
else
|
2006-02-15 08:39:50 +00:00
|
|
|
return (1);
|
2003-03-21 21:47:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
return (0);
|
2003-03-21 21:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_82547_update_fifo_head(struct em_softc *sc, int len)
|
2003-03-21 21:47:31 +00:00
|
|
|
{
|
2005-11-21 04:17:43 +00:00
|
|
|
int fifo_pkt_len = roundup2(len + EM_FIFO_HDR, EM_FIFO_HDR);
|
2003-03-21 21:47:31 +00:00
|
|
|
|
|
|
|
/* tx_fifo_head is always 16 byte aligned */
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->tx_fifo_head += fifo_pkt_len;
|
|
|
|
if (sc->tx_fifo_head >= sc->tx_fifo_size) {
|
|
|
|
sc->tx_fifo_head -= sc->tx_fifo_size;
|
2003-03-21 21:47:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2006-02-15 08:39:50 +00:00
|
|
|
em_82547_tx_fifo_reset(struct em_softc *sc)
|
2003-03-21 21:47:31 +00:00
|
|
|
{
|
|
|
|
uint32_t tctl;
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if ((E1000_READ_REG(&sc->hw, TDT) == E1000_READ_REG(&sc->hw, TDH)) &&
|
|
|
|
(E1000_READ_REG(&sc->hw, TDFT) == E1000_READ_REG(&sc->hw, TDFH)) &&
|
|
|
|
(E1000_READ_REG(&sc->hw, TDFTS) == E1000_READ_REG(&sc->hw, TDFHS))&&
|
|
|
|
(E1000_READ_REG(&sc->hw, TDFPC) == 0)) {
|
2003-03-21 21:47:31 +00:00
|
|
|
|
|
|
|
/* Disable TX unit */
|
2006-02-15 08:39:50 +00:00
|
|
|
tctl = E1000_READ_REG(&sc->hw, TCTL);
|
|
|
|
E1000_WRITE_REG(&sc->hw, TCTL, tctl & ~E1000_TCTL_EN);
|
2003-03-21 21:47:31 +00:00
|
|
|
|
|
|
|
/* Reset FIFO pointers */
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, TDFT, sc->tx_head_addr);
|
|
|
|
E1000_WRITE_REG(&sc->hw, TDFH, sc->tx_head_addr);
|
|
|
|
E1000_WRITE_REG(&sc->hw, TDFTS, sc->tx_head_addr);
|
|
|
|
E1000_WRITE_REG(&sc->hw, TDFHS, sc->tx_head_addr);
|
2003-03-21 21:47:31 +00:00
|
|
|
|
|
|
|
/* Re-enable TX unit */
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, TCTL, tctl);
|
|
|
|
E1000_WRITE_FLUSH(&sc->hw);
|
2003-03-21 21:47:31 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->tx_fifo_head = 0;
|
|
|
|
sc->tx_fifo_reset_cnt++;
|
2003-03-21 21:47:31 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
return (TRUE);
|
2003-03-21 21:47:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-02-15 08:39:50 +00:00
|
|
|
return (FALSE);
|
2003-03-21 21:47:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_set_promisc(struct em_softc *sc)
|
2002-11-08 18:14:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct ifnet *ifp = sc->ifp;
|
2006-01-20 11:38:25 +00:00
|
|
|
uint32_t reg_rctl;
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
reg_rctl = E1000_READ_REG(&sc->hw, RCTL);
|
2002-11-08 18:14:17 +00:00
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_PROMISC) {
|
|
|
|
reg_rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, RCTL, reg_rctl);
|
2006-01-20 11:38:25 +00:00
|
|
|
/* Disable VLAN stripping in promiscous mode
|
|
|
|
* This enables bridging of vlan tagged frames to occur
|
2004-09-01 23:22:41 +00:00
|
|
|
* and also allows vlan tags to be seen in tcpdump
|
|
|
|
*/
|
2005-01-26 13:44:47 +00:00
|
|
|
if (ifp->if_capenable & IFCAP_VLAN_HWTAGGING)
|
2006-02-15 08:39:50 +00:00
|
|
|
em_disable_vlans(sc);
|
|
|
|
sc->em_insert_vlan_header = 1;
|
2002-11-08 18:14:17 +00:00
|
|
|
} else if (ifp->if_flags & IFF_ALLMULTI) {
|
|
|
|
reg_rctl |= E1000_RCTL_MPE;
|
|
|
|
reg_rctl &= ~E1000_RCTL_UPE;
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, RCTL, reg_rctl);
|
|
|
|
sc->em_insert_vlan_header = 0;
|
2004-11-12 11:03:07 +00:00
|
|
|
} else
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->em_insert_vlan_header = 0;
|
2002-11-08 18:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_disable_promisc(struct em_softc *sc)
|
2002-11-08 18:14:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct ifnet *ifp = sc->ifp;
|
2006-01-20 11:38:25 +00:00
|
|
|
uint32_t reg_rctl;
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
reg_rctl = E1000_READ_REG(&sc->hw, RCTL);
|
2002-11-08 18:14:17 +00:00
|
|
|
|
|
|
|
reg_rctl &= (~E1000_RCTL_UPE);
|
|
|
|
reg_rctl &= (~E1000_RCTL_MPE);
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, RCTL, reg_rctl);
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2005-01-26 13:44:47 +00:00
|
|
|
if (ifp->if_capenable & IFCAP_VLAN_HWTAGGING)
|
2006-02-15 08:39:50 +00:00
|
|
|
em_enable_vlans(sc);
|
|
|
|
sc->em_insert_vlan_header = 0;
|
2002-11-08 18:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Multicast Update
|
|
|
|
*
|
|
|
|
* This routine is called whenever multicast address list is updated.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_set_multi(struct em_softc *sc)
|
2002-11-08 18:14:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct ifnet *ifp = sc->ifp;
|
|
|
|
struct ifmultiaddr *ifma;
|
|
|
|
uint32_t reg_rctl = 0;
|
|
|
|
uint8_t mta[MAX_NUM_MULTICAST_ADDRESSES * ETH_LENGTH_OF_ADDRESS];
|
|
|
|
int mcnt = 0;
|
2006-01-20 11:38:25 +00:00
|
|
|
|
|
|
|
IOCTL_DEBUGOUT("em_set_multi: begin");
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->hw.mac_type == em_82542_rev2_0) {
|
|
|
|
reg_rctl = E1000_READ_REG(&sc->hw, RCTL);
|
|
|
|
if (sc->hw.pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
|
|
|
|
em_pci_clear_mwi(&sc->hw);
|
2006-01-20 11:38:25 +00:00
|
|
|
reg_rctl |= E1000_RCTL_RST;
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, RCTL, reg_rctl);
|
2006-01-20 11:38:25 +00:00
|
|
|
msec_delay(5);
|
|
|
|
}
|
2005-08-03 00:18:35 +00:00
|
|
|
|
|
|
|
IF_ADDR_LOCK(ifp);
|
2006-02-15 08:39:50 +00:00
|
|
|
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
|
2006-01-20 11:38:25 +00:00
|
|
|
if (ifma->ifma_addr->sa_family != AF_LINK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (mcnt == MAX_NUM_MULTICAST_ADDRESSES)
|
|
|
|
break;
|
|
|
|
|
|
|
|
bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
|
|
|
|
&mta[mcnt*ETH_LENGTH_OF_ADDRESS], ETH_LENGTH_OF_ADDRESS);
|
|
|
|
mcnt++;
|
|
|
|
}
|
2005-08-03 00:18:35 +00:00
|
|
|
IF_ADDR_UNLOCK(ifp);
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
if (mcnt >= MAX_NUM_MULTICAST_ADDRESSES) {
|
2006-02-15 08:39:50 +00:00
|
|
|
reg_rctl = E1000_READ_REG(&sc->hw, RCTL);
|
2006-01-20 11:38:25 +00:00
|
|
|
reg_rctl |= E1000_RCTL_MPE;
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, RCTL, reg_rctl);
|
2006-01-20 11:38:25 +00:00
|
|
|
} else
|
2006-02-15 08:39:50 +00:00
|
|
|
em_mc_addr_list_update(&sc->hw, mta, mcnt, 0, 1);
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->hw.mac_type == em_82542_rev2_0) {
|
|
|
|
reg_rctl = E1000_READ_REG(&sc->hw, RCTL);
|
2006-01-20 11:38:25 +00:00
|
|
|
reg_rctl &= ~E1000_RCTL_RST;
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, RCTL, reg_rctl);
|
2006-01-20 11:38:25 +00:00
|
|
|
msec_delay(5);
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->hw.pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
|
|
|
|
em_pci_set_mwi(&sc->hw);
|
2006-01-20 11:38:25 +00:00
|
|
|
}
|
2002-11-08 18:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Timer routine
|
|
|
|
*
|
|
|
|
* This routine checks for link status and updates statistics.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
static void
|
|
|
|
em_local_timer(void *arg)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc = arg;
|
|
|
|
struct ifnet *ifp = sc->ifp;
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK(sc);
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
em_check_for_link(&sc->hw);
|
2006-02-15 10:51:11 +00:00
|
|
|
em_update_link_status(sc);
|
2006-02-15 08:39:50 +00:00
|
|
|
em_update_stats_counters(sc);
|
2006-01-20 11:38:25 +00:00
|
|
|
if (em_display_debug_stats && ifp->if_drv_flags & IFF_DRV_RUNNING)
|
2006-02-15 08:39:50 +00:00
|
|
|
em_print_hw_stats(sc);
|
|
|
|
em_smartspeed(sc);
|
2003-03-21 21:47:31 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
callout_reset(&sc->timer, hz, em_local_timer, sc);
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_UNLOCK(sc);
|
2002-11-08 18:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-02-15 10:51:11 +00:00
|
|
|
em_update_link_status(struct em_softc *sc)
|
2002-11-08 18:14:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct ifnet *ifp = sc->ifp;
|
|
|
|
device_t dev = sc->dev;
|
2005-02-04 18:36:04 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (E1000_READ_REG(&sc->hw, STATUS) & E1000_STATUS_LU) {
|
|
|
|
if (sc->link_active == 0) {
|
|
|
|
em_get_speed_and_duplex(&sc->hw, &sc->link_speed,
|
|
|
|
&sc->link_duplex);
|
2004-11-03 14:11:18 +00:00
|
|
|
if (bootverbose)
|
2006-02-15 08:39:50 +00:00
|
|
|
device_printf(dev, "Link is up %d Mbps %s\n",
|
|
|
|
sc->link_speed,
|
|
|
|
((sc->link_duplex == FULL_DUPLEX) ?
|
2006-01-20 11:38:25 +00:00
|
|
|
"Full Duplex" : "Half Duplex"));
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->link_active = 1;
|
|
|
|
sc->smartspeed = 0;
|
2006-02-15 11:38:33 +00:00
|
|
|
ifp->if_baudrate = sc->link_speed * 1000000;
|
2005-02-04 18:36:04 +00:00
|
|
|
if_link_state_change(ifp, LINK_STATE_UP);
|
2002-11-08 18:14:17 +00:00
|
|
|
}
|
|
|
|
} else {
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->link_active == 1) {
|
2006-02-15 11:38:33 +00:00
|
|
|
ifp->if_baudrate = sc->link_speed = 0;
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->link_duplex = 0;
|
2004-11-03 14:11:18 +00:00
|
|
|
if (bootverbose)
|
2006-02-15 08:39:50 +00:00
|
|
|
device_printf(dev, "Link is Down\n");
|
|
|
|
sc->link_active = 0;
|
2005-02-04 18:36:04 +00:00
|
|
|
if_link_state_change(ifp, LINK_STATE_DOWN);
|
2002-11-08 18:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
2002-11-08 18:14:17 +00:00
|
|
|
* This routine disables all traffic on the adapter by issuing a
|
2006-01-20 11:38:25 +00:00
|
|
|
* global reset on the MAC and deallocates TX/RX buffers.
|
2001-12-02 07:37:17 +00:00
|
|
|
*
|
|
|
|
**********************************************************************/
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
static void
|
|
|
|
em_stop(void *arg)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc = arg;
|
|
|
|
struct ifnet *ifp = sc->ifp;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK_ASSERT(sc);
|
2003-09-23 00:18:25 +00:00
|
|
|
|
2003-08-27 21:52:37 +00:00
|
|
|
INIT_DEBUGOUT("em_stop: begin");
|
Big polling(4) cleanup.
o Axe poll in trap.
o Axe IFF_POLLING flag from if_flags.
o Rework revision 1.21 (Giant removal), in such a way that
poll_mtx is not dropped during call to polling handler.
This fixes problem with idle polling.
o Make registration and deregistration from polling in a
functional way, insted of next tick/interrupt.
o Obsolete kern.polling.enable. Polling is turned on/off
with ifconfig.
Detailed kern_poll.c changes:
- Remove polling handler flags, introduced in 1.21. The are not
needed now.
- Forget and do not check if_flags, if_capenable and if_drv_flags.
- Call all registered polling handlers unconditionally.
- Do not drop poll_mtx, when entering polling handlers.
- In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx.
- In netisr_poll() axe the block, where polling code asks drivers
to unregister.
- In netisr_poll() and ether_poll() do polling always, if any
handlers are present.
- In ether_poll_[de]register() remove a lot of error hiding code. Assert
that arguments are correct, instead.
- In ether_poll_[de]register() use standard return values in case of
error or success.
- Introduce poll_switch() that is a sysctl handler for kern.polling.enable.
poll_switch() goes through interface list and enabled/disables polling.
A message that kern.polling.enable is deprecated is printed.
Detailed driver changes:
- On attach driver announces IFCAP_POLLING in if_capabilities, but
not in if_capenable.
- On detach driver calls ether_poll_deregister() if polling is enabled.
- In polling handler driver obtains its lock and checks IFF_DRV_RUNNING
flag. If there is no, then unlocks and returns.
- In ioctl handler driver checks for IFCAP_POLLING flag requested to
be set or cleared. Driver first calls ether_poll_[de]register(), then
obtains driver lock and [dis/en]ables interrupts.
- In interrupt handler driver checks IFCAP_POLLING flag in if_capenable.
If present, then returns.This is important to protect from spurious
interrupts.
Reviewed by: ru, sam, jhb
2005-10-01 18:56:19 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
em_disable_intr(sc);
|
|
|
|
em_reset_hw(&sc->hw);
|
|
|
|
callout_stop(&sc->timer);
|
|
|
|
callout_stop(&sc->tx_fifo_timer);
|
|
|
|
em_free_transmit_structures(sc);
|
|
|
|
em_free_receive_structures(sc);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
/* Tell the stack that the interface is no longer active */
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Determine hardware revision.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_identify_hardware(struct em_softc *sc)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
device_t dev = sc->dev;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Make sure our PCI config space has the necessary stuff set */
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.pci_cmd_word = pci_read_config(dev, PCIR_COMMAND, 2);
|
|
|
|
if ((sc->hw.pci_cmd_word & PCIM_CMD_BUSMASTEREN) == 0 &&
|
|
|
|
(sc->hw.pci_cmd_word & PCIM_CMD_MEMEN)) {
|
|
|
|
device_printf(dev, "Memory Access and/or Bus Master bits "
|
|
|
|
"were not set!\n");
|
|
|
|
sc->hw.pci_cmd_word |=
|
2002-06-03 22:30:51 +00:00
|
|
|
(PCIM_CMD_BUSMASTEREN | PCIM_CMD_MEMEN);
|
2006-02-15 08:39:50 +00:00
|
|
|
pci_write_config(dev, PCIR_COMMAND, sc->hw.pci_cmd_word, 2);
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Save off the information about this board */
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.vendor_id = pci_get_vendor(dev);
|
|
|
|
sc->hw.device_id = pci_get_device(dev);
|
|
|
|
sc->hw.revision_id = pci_read_config(dev, PCIR_REVID, 1);
|
|
|
|
sc->hw.subsystem_vendor_id = pci_read_config(dev, PCIR_SUBVEND_0, 2);
|
|
|
|
sc->hw.subsystem_id = pci_read_config(dev, PCIR_SUBDEV_0, 2);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
/* Identify the MAC */
|
2006-02-15 08:39:50 +00:00
|
|
|
if (em_set_mac_type(&sc->hw))
|
|
|
|
device_printf(dev, "Unknown MAC Type\n");
|
2003-08-27 21:52:37 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if(sc->hw.mac_type == em_82541 || sc->hw.mac_type == em_82541_rev_2 ||
|
|
|
|
sc->hw.mac_type == em_82547 || sc->hw.mac_type == em_82547_rev_2)
|
|
|
|
sc->hw.phy_init_script = TRUE;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-02-15 08:39:50 +00:00
|
|
|
em_allocate_pci_resources(struct em_softc *sc)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
device_t dev = sc->dev;
|
|
|
|
int val, rid;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2005-11-09 08:43:18 +00:00
|
|
|
rid = PCIR_BAR(0);
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->res_memory = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
|
|
|
|
&rid, RF_ACTIVE);
|
|
|
|
if (sc->res_memory == NULL) {
|
|
|
|
device_printf(dev, "Unable to allocate bus resource: memory\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
sc->osdep.mem_bus_space_tag =
|
|
|
|
rman_get_bustag(sc->res_memory);
|
|
|
|
sc->osdep.mem_bus_space_handle = rman_get_bushandle(sc->res_memory);
|
|
|
|
sc->hw.hw_addr = (uint8_t *)&sc->osdep.mem_bus_space_handle;
|
|
|
|
|
|
|
|
if (sc->hw.mac_type > em_82543) {
|
2002-07-16 16:55:03 +00:00
|
|
|
/* Figure our where our IO BAR is ? */
|
2005-11-09 08:43:18 +00:00
|
|
|
for (rid = PCIR_BAR(0); rid < PCIR_CIS;) {
|
2002-07-16 16:55:03 +00:00
|
|
|
val = pci_read_config(dev, rid, 4);
|
2005-11-09 08:43:18 +00:00
|
|
|
if (E1000_BAR_TYPE(val) == E1000_BAR_TYPE_IO) {
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->io_rid = rid;
|
2002-07-16 16:55:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
rid += 4;
|
2005-11-09 08:43:18 +00:00
|
|
|
/* check for 64bit BAR */
|
|
|
|
if (E1000_BAR_MEM_TYPE(val) == E1000_BAR_MEM_TYPE_64BIT)
|
|
|
|
rid += 4;
|
|
|
|
}
|
|
|
|
if (rid >= PCIR_CIS) {
|
2006-02-15 08:39:50 +00:00
|
|
|
device_printf(dev, "Unable to locate IO BAR\n");
|
2005-11-09 08:43:18 +00:00
|
|
|
return (ENXIO);
|
2002-07-16 16:55:03 +00:00
|
|
|
}
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->res_ioport = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
|
|
|
|
&sc->io_rid, RF_ACTIVE);
|
|
|
|
if (sc->res_ioport == NULL) {
|
|
|
|
device_printf(dev, "Unable to allocate bus resource: "
|
|
|
|
"ioport\n");
|
|
|
|
return (ENXIO);
|
2002-07-16 16:55:03 +00:00
|
|
|
}
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.io_base = 0;
|
|
|
|
sc->osdep.io_bus_space_tag = rman_get_bustag(sc->res_ioport);
|
|
|
|
sc->osdep.io_bus_space_handle =
|
|
|
|
rman_get_bushandle(sc->res_ioport);
|
2002-07-16 16:55:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rid = 0x0;
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->res_interrupt = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
|
|
|
|
RF_SHAREABLE | RF_ACTIVE);
|
|
|
|
if (sc->res_interrupt == NULL) {
|
|
|
|
device_printf(dev, "Unable to allocate bus resource: "
|
|
|
|
"interrupt\n");
|
|
|
|
return (ENXIO);
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
2006-01-11 00:30:25 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.back = &sc->osdep;
|
2006-01-13 08:18:04 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
return (0);
|
2006-01-13 08:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-02-15 08:39:50 +00:00
|
|
|
em_allocate_intr(struct em_softc *sc)
|
2006-01-13 08:18:04 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
device_t dev = sc->dev;
|
|
|
|
int error;
|
2006-01-13 08:18:04 +00:00
|
|
|
|
|
|
|
/* Manually turn off all interrupts */
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, IMC, 0xffffffff);
|
2006-01-13 05:04:27 +00:00
|
|
|
|
2006-06-06 08:03:49 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
|
|
|
if (sc->int_handler_tag == NULL && (error = bus_setup_intr(dev,
|
|
|
|
sc->res_interrupt, INTR_TYPE_NET | INTR_MPSAFE, em_intr, sc,
|
|
|
|
&sc->int_handler_tag)) != 0) {
|
|
|
|
device_printf(dev, "Failed to register interrupt handler");
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
#else
|
2006-01-11 00:30:25 +00:00
|
|
|
/*
|
|
|
|
* Try allocating a fast interrupt and the associated deferred
|
2006-06-06 08:03:49 +00:00
|
|
|
* processing contexts.
|
2006-01-11 00:30:25 +00:00
|
|
|
*/
|
2006-02-15 08:39:50 +00:00
|
|
|
TASK_INIT(&sc->rxtx_task, 0, em_handle_rxtx, sc);
|
|
|
|
TASK_INIT(&sc->link_task, 0, em_handle_link, sc);
|
|
|
|
sc->tq = taskqueue_create_fast("em_taskq", M_NOWAIT,
|
|
|
|
taskqueue_thread_enqueue, &sc->tq);
|
|
|
|
taskqueue_start_threads(&sc->tq, 1, PI_NET, "%s taskq",
|
|
|
|
device_get_nameunit(sc->dev));
|
|
|
|
if ((error = bus_setup_intr(dev, sc->res_interrupt,
|
|
|
|
INTR_TYPE_NET | INTR_FAST, em_intr_fast, sc,
|
|
|
|
&sc->int_handler_tag)) != 0) {
|
|
|
|
device_printf(dev, "Failed to register fast interrupt "
|
|
|
|
"handler: %d\n", error);
|
|
|
|
taskqueue_free(sc->tq);
|
|
|
|
sc->tq = NULL;
|
|
|
|
return (error);
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
2006-06-06 08:03:49 +00:00
|
|
|
#endif
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
em_enable_intr(sc);
|
2006-01-13 08:18:04 +00:00
|
|
|
return (0);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_free_intr(struct em_softc *sc)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
device_t dev = sc->dev;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->res_interrupt != NULL) {
|
|
|
|
bus_teardown_intr(dev, sc->res_interrupt, sc->int_handler_tag);
|
|
|
|
sc->int_handler_tag = NULL;
|
2006-01-13 08:18:04 +00:00
|
|
|
}
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->tq != NULL) {
|
|
|
|
taskqueue_drain(sc->tq, &sc->rxtx_task);
|
|
|
|
taskqueue_drain(taskqueue_fast, &sc->link_task);
|
|
|
|
taskqueue_free(sc->tq);
|
|
|
|
sc->tq = NULL;
|
2006-01-11 00:30:25 +00:00
|
|
|
}
|
2006-01-13 08:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_free_pci_resources(struct em_softc *sc)
|
2006-01-13 08:18:04 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
device_t dev = sc->dev;
|
2006-01-13 08:18:04 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->res_interrupt != NULL)
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->res_interrupt);
|
|
|
|
|
|
|
|
if (sc->res_memory != NULL)
|
2006-01-20 11:38:25 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0),
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->res_memory);
|
2002-07-16 16:55:03 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->res_ioport != NULL)
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, sc->io_rid,
|
|
|
|
sc->res_ioport);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* 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
|
2006-02-15 08:39:50 +00:00
|
|
|
em_hardware_init(struct em_softc *sc)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
device_t dev = sc->dev;
|
2005-11-24 01:44:49 +00:00
|
|
|
uint16_t rx_buffer_size;
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
INIT_DEBUGOUT("em_hardware_init: begin");
|
2002-06-03 22:30:51 +00:00
|
|
|
/* Issue a global reset */
|
2006-02-15 08:39:50 +00:00
|
|
|
em_reset_hw(&sc->hw);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
/* When hardware is reset, fifo_head is also reset */
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->tx_fifo_head = 0;
|
2003-03-21 21:47:31 +00:00
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
/* Make sure we have a good EEPROM before we read from it */
|
2006-02-15 08:39:50 +00:00
|
|
|
if (em_validate_eeprom_checksum(&sc->hw) < 0) {
|
|
|
|
device_printf(dev, "The EEPROM Checksum Is Not Valid\n");
|
|
|
|
return (EIO);
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (em_read_part_num(&sc->hw, &(sc->part_num)) < 0) {
|
|
|
|
device_printf(dev, "EEPROM read error while reading part "
|
|
|
|
"number\n");
|
|
|
|
return (EIO);
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 01:44:49 +00:00
|
|
|
/*
|
2006-01-20 11:38:25 +00:00
|
|
|
* These parameters control the automatic generation (Tx) and
|
2005-11-24 01:44:49 +00:00
|
|
|
* response (Rx) to Ethernet PAUSE frames.
|
|
|
|
* - High water mark should allow for at least two frames to be
|
|
|
|
* received after sending an XOFF.
|
|
|
|
* - Low water mark works best when it is very near the high water mark.
|
2006-02-15 08:39:50 +00:00
|
|
|
* This allows the receiver to restart by sending XON when it has
|
|
|
|
* drained a bit. Here we use an arbitary value of 1500 which will
|
|
|
|
* restart after one full frame is pulled from the buffer. There
|
|
|
|
* could be several smaller frames in the buffer and if so they will
|
|
|
|
* not trigger the XON until their total number reduces the buffer
|
|
|
|
* by 1500.
|
2005-11-24 01:44:49 +00:00
|
|
|
* - The pause time is fairly large at 1000 x 512ns = 512 usec.
|
|
|
|
*/
|
2006-02-15 08:39:50 +00:00
|
|
|
rx_buffer_size = ((E1000_READ_REG(&sc->hw, PBA) & 0xffff) << 10 );
|
2005-11-24 01:44:49 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.fc_high_water = rx_buffer_size -
|
|
|
|
roundup2(sc->hw.max_frame_size, 1024);
|
|
|
|
sc->hw.fc_low_water = sc->hw.fc_high_water - 1500;
|
2006-04-06 17:09:03 +00:00
|
|
|
if (sc->hw.mac_type == em_80003es2lan)
|
|
|
|
sc->hw.fc_pause_time = 0xFFFF;
|
|
|
|
else
|
|
|
|
sc->hw.fc_pause_time = 0x1000;
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->hw.fc_send_xon = TRUE;
|
|
|
|
sc->hw.fc = em_fc_full;
|
2005-11-24 01:44:49 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (em_init_hw(&sc->hw) < 0) {
|
|
|
|
device_printf(dev, "Hardware Initialization Failed");
|
|
|
|
return (EIO);
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
em_check_for_link(&sc->hw);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
return (0);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Setup networking device structure and register an interface.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_setup_interface(device_t dev, struct em_softc *sc)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
INIT_DEBUGOUT("em_setup_interface: begin");
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
ifp = sc->ifp = if_alloc(IFT_ETHER);
|
2005-06-10 16:49:24 +00:00
|
|
|
if (ifp == NULL)
|
|
|
|
panic("%s: can not if_alloc()", device_get_nameunit(dev));
|
2003-10-31 18:32:15 +00:00
|
|
|
if_initname(ifp, device_get_name(dev), device_get_unit(dev));
|
2002-06-03 22:30:51 +00:00
|
|
|
ifp->if_mtu = ETHERMTU;
|
|
|
|
ifp->if_init = em_init;
|
2006-02-15 08:39:50 +00:00
|
|
|
ifp->if_softc = sc;
|
2002-06-03 22:30:51 +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;
|
2006-02-15 08:39:50 +00:00
|
|
|
IFQ_SET_MAXLEN(&ifp->if_snd, sc->num_tx_desc - 1);
|
|
|
|
ifp->if_snd.ifq_drv_maxlen = sc->num_tx_desc - 1;
|
2004-07-02 12:16:02 +00:00
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
ether_ifattach(ifp, sc->hw.mac_addr);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2004-05-20 11:04:09 +00:00
|
|
|
ifp->if_capabilities = ifp->if_capenable = 0;
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->hw.mac_type >= em_82543) {
|
2006-01-30 13:45:55 +00:00
|
|
|
ifp->if_capabilities |= IFCAP_HWCSUM | IFCAP_VLAN_HWCSUM;
|
|
|
|
ifp->if_capenable |= IFCAP_HWCSUM | IFCAP_VLAN_HWCSUM;
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2003-04-18 17:36:13 +00:00
|
|
|
/*
|
|
|
|
* Tell the upper layer(s) we support long frames.
|
|
|
|
*/
|
|
|
|
ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
|
2004-05-20 11:04:09 +00:00
|
|
|
ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU;
|
2005-01-26 11:40:58 +00:00
|
|
|
ifp->if_capenable |= IFCAP_VLAN_MTU;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2004-04-11 21:01:12 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
|
|
|
ifp->if_capabilities |= IFCAP_POLLING;
|
|
|
|
#endif
|
2003-03-21 21:47:31 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
/*
|
2002-06-03 22:30:51 +00:00
|
|
|
* Specify the media types supported by this adapter and register
|
|
|
|
* callbacks to update media and link information
|
|
|
|
*/
|
2006-02-15 08:39:50 +00:00
|
|
|
ifmedia_init(&sc->media, IFM_IMASK, em_media_change, em_media_status);
|
|
|
|
if (sc->hw.media_type == em_media_type_fiber) {
|
|
|
|
ifmedia_add(&sc->media, IFM_ETHER | IFM_1000_SX | IFM_FDX,
|
2002-06-03 22:30:51 +00:00
|
|
|
0, NULL);
|
2006-02-15 08:39:50 +00:00
|
|
|
ifmedia_add(&sc->media, IFM_ETHER | IFM_1000_SX,
|
2002-06-03 22:30:51 +00:00
|
|
|
0, NULL);
|
|
|
|
} else {
|
2006-02-15 08:39:50 +00:00
|
|
|
ifmedia_add(&sc->media, IFM_ETHER | IFM_10_T, 0, NULL);
|
|
|
|
ifmedia_add(&sc->media, IFM_ETHER | IFM_10_T | IFM_FDX,
|
2002-06-03 22:30:51 +00:00
|
|
|
0, NULL);
|
2006-02-15 08:39:50 +00:00
|
|
|
ifmedia_add(&sc->media, IFM_ETHER | IFM_100_TX,
|
2002-06-03 22:30:51 +00:00
|
|
|
0, NULL);
|
2006-02-15 08:39:50 +00:00
|
|
|
ifmedia_add(&sc->media, IFM_ETHER | IFM_100_TX | IFM_FDX,
|
2002-06-03 22:30:51 +00:00
|
|
|
0, NULL);
|
2006-02-15 08:39:50 +00:00
|
|
|
ifmedia_add(&sc->media, IFM_ETHER | IFM_1000_T | IFM_FDX,
|
2002-06-03 22:30:51 +00:00
|
|
|
0, NULL);
|
2006-02-15 08:39:50 +00:00
|
|
|
ifmedia_add(&sc->media, IFM_ETHER | IFM_1000_T, 0, NULL);
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
2006-02-15 08:39:50 +00:00
|
|
|
ifmedia_add(&sc->media, IFM_ETHER | IFM_AUTO, 0, NULL);
|
|
|
|
ifmedia_set(&sc->media, IFM_ETHER | IFM_AUTO);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Workaround for SmartSpeed on 82541 and 82547 controllers
|
|
|
|
*
|
2006-01-20 11:38:25 +00:00
|
|
|
**********************************************************************/
|
2003-03-21 21:47:31 +00:00
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_smartspeed(struct em_softc *sc)
|
2003-03-21 21:47:31 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
uint16_t phy_tmp;
|
2006-01-20 11:38:25 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->link_active || (sc->hw.phy_type != em_phy_igp) ||
|
|
|
|
sc->hw.autoneg == 0 ||
|
|
|
|
(sc->hw.autoneg_advertised & ADVERTISE_1000_FULL) == 0)
|
2003-03-21 21:47:31 +00:00
|
|
|
return;
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->smartspeed == 0) {
|
|
|
|
/* If Master/Slave config fault is asserted twice,
|
|
|
|
* we assume back-to-back */
|
|
|
|
em_read_phy_reg(&sc->hw, PHY_1000T_STATUS, &phy_tmp);
|
|
|
|
if (!(phy_tmp & SR_1000T_MS_CONFIG_FAULT))
|
|
|
|
return;
|
|
|
|
em_read_phy_reg(&sc->hw, PHY_1000T_STATUS, &phy_tmp);
|
|
|
|
if (phy_tmp & SR_1000T_MS_CONFIG_FAULT) {
|
|
|
|
em_read_phy_reg(&sc->hw, PHY_1000T_CTRL, &phy_tmp);
|
|
|
|
if(phy_tmp & CR_1000T_MS_ENABLE) {
|
|
|
|
phy_tmp &= ~CR_1000T_MS_ENABLE;
|
|
|
|
em_write_phy_reg(&sc->hw, PHY_1000T_CTRL,
|
|
|
|
phy_tmp);
|
|
|
|
sc->smartspeed++;
|
|
|
|
if(sc->hw.autoneg &&
|
|
|
|
!em_phy_setup_autoneg(&sc->hw) &&
|
|
|
|
!em_read_phy_reg(&sc->hw, PHY_CTRL,
|
|
|
|
&phy_tmp)) {
|
|
|
|
phy_tmp |= (MII_CR_AUTO_NEG_EN |
|
|
|
|
MII_CR_RESTART_AUTO_NEG);
|
|
|
|
em_write_phy_reg(&sc->hw, PHY_CTRL,
|
|
|
|
phy_tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else if(sc->smartspeed == EM_SMARTSPEED_DOWNSHIFT) {
|
|
|
|
/* If still no link, perhaps using 2/3 pair cable */
|
|
|
|
em_read_phy_reg(&sc->hw, PHY_1000T_CTRL, &phy_tmp);
|
|
|
|
phy_tmp |= CR_1000T_MS_ENABLE;
|
|
|
|
em_write_phy_reg(&sc->hw, PHY_1000T_CTRL, phy_tmp);
|
|
|
|
if(sc->hw.autoneg &&
|
|
|
|
!em_phy_setup_autoneg(&sc->hw) &&
|
|
|
|
!em_read_phy_reg(&sc->hw, PHY_CTRL, &phy_tmp)) {
|
|
|
|
phy_tmp |= (MII_CR_AUTO_NEG_EN |
|
|
|
|
MII_CR_RESTART_AUTO_NEG);
|
|
|
|
em_write_phy_reg(&sc->hw, PHY_CTRL, phy_tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Restart process after EM_SMARTSPEED_MAX iterations */
|
|
|
|
if(sc->smartspeed++ == EM_SMARTSPEED_MAX)
|
|
|
|
sc->smartspeed = 0;
|
2003-03-21 21:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
/*
|
|
|
|
* Manage DMA'able memory.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
em_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
|
2006-01-20 11:38:25 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
if (error)
|
|
|
|
return;
|
|
|
|
*(bus_addr_t *) arg = segs[0].ds_addr;
|
2003-05-02 21:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-02-15 08:39:50 +00:00
|
|
|
em_dma_malloc(struct em_softc *sc, bus_size_t size, struct em_dma_alloc *dma,
|
|
|
|
int mapflags)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = bus_dma_tag_create(NULL, /* parent */
|
|
|
|
E1000_DBA_ALIGN, 0, /* alignment, bounds */
|
|
|
|
BUS_SPACE_MAXADDR, /* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
|
|
|
size, /* maxsize */
|
|
|
|
1, /* nsegments */
|
|
|
|
size, /* maxsegsize */
|
|
|
|
0, /* flags */
|
|
|
|
NULL, /* lockfunc */
|
|
|
|
NULL, /* lockarg */
|
|
|
|
&dma->dma_tag);
|
|
|
|
if (error) {
|
|
|
|
device_printf(sc->dev, "%s: bus_dma_tag_create failed: %d\n",
|
|
|
|
__func__, error);
|
|
|
|
goto fail_0;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = bus_dmamem_alloc(dma->dma_tag, (void**) &dma->dma_vaddr,
|
|
|
|
BUS_DMA_NOWAIT, &dma->dma_map);
|
|
|
|
if (error) {
|
|
|
|
device_printf(sc->dev, "%s: bus_dmamem_alloc(%ju) failed: %d\n",
|
|
|
|
__func__, (uintmax_t)size, error);
|
|
|
|
goto fail_2;
|
|
|
|
}
|
2003-05-02 21:17:08 +00:00
|
|
|
|
2005-11-09 08:43:18 +00:00
|
|
|
dma->dma_paddr = 0;
|
2006-02-15 08:39:50 +00:00
|
|
|
error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
|
|
|
|
size, em_dmamap_cb, &dma->dma_paddr, mapflags | BUS_DMA_NOWAIT);
|
|
|
|
if (error || dma->dma_paddr == 0) {
|
|
|
|
device_printf(sc->dev, "%s: bus_dmamap_load failed: %d\n",
|
|
|
|
__func__, error);
|
|
|
|
goto fail_3;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
2003-05-02 21:17:08 +00:00
|
|
|
|
|
|
|
fail_3:
|
2006-02-15 08:39:50 +00:00
|
|
|
bus_dmamap_unload(dma->dma_tag, dma->dma_map);
|
2003-05-02 21:17:08 +00:00
|
|
|
fail_2:
|
2006-02-15 08:39:50 +00:00
|
|
|
bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
|
|
|
|
bus_dma_tag_destroy(dma->dma_tag);
|
2003-05-02 21:17:08 +00:00
|
|
|
fail_0:
|
2006-02-15 08:39:50 +00:00
|
|
|
dma->dma_map = NULL;
|
|
|
|
dma->dma_tag = NULL;
|
|
|
|
|
|
|
|
return (error);
|
2003-05-02 21:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_dma_free(struct em_softc *sc, struct em_dma_alloc *dma)
|
2003-05-02 21:17:08 +00:00
|
|
|
{
|
2005-11-21 04:17:43 +00:00
|
|
|
if (dma->dma_tag == NULL)
|
|
|
|
return;
|
|
|
|
if (dma->dma_map != NULL) {
|
|
|
|
bus_dmamap_sync(dma->dma_tag, dma->dma_map,
|
|
|
|
BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
|
|
|
|
bus_dmamap_unload(dma->dma_tag, dma->dma_map);
|
|
|
|
bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
|
|
|
|
dma->dma_map = NULL;
|
|
|
|
}
|
2006-02-15 08:39:50 +00:00
|
|
|
bus_dma_tag_destroy(dma->dma_tag);
|
2005-11-21 04:17:43 +00:00
|
|
|
dma->dma_tag = NULL;
|
2003-05-02 21:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
/*********************************************************************
|
|
|
|
*
|
2006-01-20 11:38:25 +00:00
|
|
|
* Allocate memory for tx_buffer structures. The tx_buffer stores all
|
|
|
|
* the information needed to transmit a packet on the wire.
|
2001-12-02 07:37:17 +00:00
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static int
|
2006-02-15 08:39:50 +00:00
|
|
|
em_allocate_transmit_structures(struct em_softc *sc)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->tx_buffer_area = malloc(sizeof(struct em_buffer) *
|
|
|
|
sc->num_tx_desc, M_DEVBUF, M_NOWAIT);
|
|
|
|
if (sc->tx_buffer_area == NULL) {
|
|
|
|
device_printf(sc->dev, "Unable to allocate tx_buffer memory\n");
|
|
|
|
return (ENOMEM);
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
bzero(sc->tx_buffer_area, sizeof(struct em_buffer) * sc->num_tx_desc);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
return (0);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
2006-01-20 11:38:25 +00:00
|
|
|
* Allocate and initialize transmit structures.
|
2001-12-02 07:37:17 +00:00
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static int
|
2006-02-15 08:39:50 +00:00
|
|
|
em_setup_transmit_structures(struct em_softc *sc)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
device_t dev = sc->dev;
|
2005-11-21 04:17:43 +00:00
|
|
|
struct em_buffer *tx_buffer;
|
|
|
|
bus_size_t size;
|
|
|
|
int error, i;
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
/*
|
|
|
|
* Setup DMA descriptor areas.
|
|
|
|
*/
|
|
|
|
size = roundup2(sc->hw.max_frame_size, MCLBYTES);
|
|
|
|
if ((error = bus_dma_tag_create(NULL, /* parent */
|
|
|
|
1, 0, /* alignment, bounds */
|
|
|
|
BUS_SPACE_MAXADDR, /* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
|
|
|
size, /* maxsize */
|
|
|
|
EM_MAX_SCATTER, /* nsegments */
|
|
|
|
size, /* maxsegsize */
|
|
|
|
0, /* flags */
|
|
|
|
NULL, /* lockfunc */
|
|
|
|
NULL, /* lockarg */
|
|
|
|
&sc->txtag)) != 0) {
|
|
|
|
device_printf(dev, "Unable to allocate TX DMA tag\n");
|
2005-11-21 04:17:43 +00:00
|
|
|
goto fail;
|
2006-02-15 08:39:50 +00:00
|
|
|
}
|
2003-05-02 21:17:08 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if ((error = em_allocate_transmit_structures(sc)) != 0)
|
2005-11-21 04:17:43 +00:00
|
|
|
goto fail;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
bzero(sc->tx_desc_base, (sizeof(struct em_tx_desc)) * sc->num_tx_desc);
|
|
|
|
tx_buffer = sc->tx_buffer_area;
|
|
|
|
for (i = 0; i < sc->num_tx_desc; i++) {
|
|
|
|
error = bus_dmamap_create(sc->txtag, 0, &tx_buffer->map);
|
2005-11-21 04:17:43 +00:00
|
|
|
if (error != 0) {
|
2006-02-15 08:39:50 +00:00
|
|
|
device_printf(dev, "Unable to create TX DMA map\n");
|
2005-11-21 04:17:43 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
tx_buffer++;
|
|
|
|
}
|
2003-05-02 21:17:08 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->next_avail_tx_desc = 0;
|
|
|
|
sc->oldest_used_tx_desc = 0;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
/* Set number of descriptors available */
|
|
|
|
sc->num_tx_desc_avail = sc->num_tx_desc;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
/* Set checksum context */
|
|
|
|
sc->active_checksum_context = OFFLOAD_NONE;
|
|
|
|
bus_dmamap_sync(sc->txdma.dma_tag, sc->txdma.dma_map,
|
2005-11-21 04:17:43 +00:00
|
|
|
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
return (0);
|
2005-11-21 04:17:43 +00:00
|
|
|
|
|
|
|
fail:
|
2006-02-15 08:39:50 +00:00
|
|
|
em_free_transmit_structures(sc);
|
2005-11-21 04:17:43 +00:00
|
|
|
return (error);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Enable transmit unit.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_initialize_transmit_unit(struct em_softc *sc)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2006-04-06 17:09:03 +00:00
|
|
|
uint32_t reg_tctl, tarc;
|
2006-02-15 08:39:50 +00:00
|
|
|
uint32_t reg_tipg = 0;
|
|
|
|
uint64_t bus_addr;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
INIT_DEBUGOUT("em_initialize_transmit_unit: begin");
|
2002-06-03 22:30:51 +00:00
|
|
|
/* Setup the Base and Length of the Tx Descriptor Ring */
|
2006-02-15 08:39:50 +00:00
|
|
|
bus_addr = sc->txdma.dma_paddr;
|
|
|
|
E1000_WRITE_REG(&sc->hw, TDBAL, (uint32_t)bus_addr);
|
|
|
|
E1000_WRITE_REG(&sc->hw, TDBAH, (uint32_t)(bus_addr >> 32));
|
|
|
|
E1000_WRITE_REG(&sc->hw, TDLEN,
|
|
|
|
sc->num_tx_desc * sizeof(struct em_tx_desc));
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Setup the HW Tx Head and Tail descriptor pointers */
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, TDH, 0);
|
|
|
|
E1000_WRITE_REG(&sc->hw, TDT, 0);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
HW_DEBUGOUT2("Base = %x, Length = %x\n", E1000_READ_REG(&sc->hw, TDBAL),
|
|
|
|
E1000_READ_REG(&sc->hw, TDLEN));
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Set the default values for the Tx Inter Packet Gap timer */
|
2006-02-15 08:39:50 +00:00
|
|
|
switch (sc->hw.mac_type) {
|
2002-06-03 22:30:51 +00:00
|
|
|
case em_82542_rev2_0:
|
2006-02-15 08:39:50 +00:00
|
|
|
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;
|
|
|
|
break;
|
2006-04-06 17:09:03 +00:00
|
|
|
case em_80003es2lan:
|
|
|
|
reg_tipg = DEFAULT_82543_TIPG_IPGR1;
|
|
|
|
reg_tipg |= DEFAULT_80003ES2LAN_TIPG_IPGR2 <<
|
|
|
|
E1000_TIPG_IPGR2_SHIFT;
|
|
|
|
break;
|
2006-02-15 08:39:50 +00:00
|
|
|
default:
|
|
|
|
if (sc->hw.media_type == em_media_type_fiber)
|
|
|
|
reg_tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
|
|
|
|
else
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
E1000_WRITE_REG(&sc->hw, TIPG, reg_tipg);
|
|
|
|
E1000_WRITE_REG(&sc->hw, TIDV, sc->tx_int_delay.value);
|
|
|
|
if(sc->hw.mac_type >= em_82540)
|
|
|
|
E1000_WRITE_REG(&sc->hw, TADV, sc->tx_abs_int_delay.value);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Program the Transmit Control Register */
|
|
|
|
reg_tctl = E1000_TCTL_PSP | E1000_TCTL_EN |
|
|
|
|
(E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->hw.mac_type >= em_82571)
|
2005-05-26 23:32:02 +00:00
|
|
|
reg_tctl |= E1000_TCTL_MULR;
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->link_duplex == 1) {
|
2002-06-03 22:30:51 +00:00
|
|
|
reg_tctl |= E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT;
|
|
|
|
} else {
|
|
|
|
reg_tctl |= E1000_HDX_COLLISION_DISTANCE << E1000_COLD_SHIFT;
|
|
|
|
}
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, TCTL, reg_tctl);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-04-06 17:09:03 +00:00
|
|
|
if (sc->hw.mac_type == em_82571 || sc->hw.mac_type == em_82572) {
|
|
|
|
tarc = E1000_READ_REG(&sc->hw, TARC0);
|
|
|
|
tarc |= ((1 << 25) | (1 << 21));
|
|
|
|
E1000_WRITE_REG(&sc->hw, TARC0, tarc);
|
|
|
|
tarc = E1000_READ_REG(&sc->hw, TARC1);
|
|
|
|
tarc |= (1 << 25);
|
|
|
|
if (reg_tctl & E1000_TCTL_MULR)
|
|
|
|
tarc &= ~(1 << 28);
|
|
|
|
else
|
|
|
|
tarc |= (1 << 28);
|
|
|
|
E1000_WRITE_REG(&sc->hw, TARC1, tarc);
|
|
|
|
} else if (sc->hw.mac_type == em_80003es2lan) {
|
|
|
|
tarc = E1000_READ_REG(&sc->hw, TARC0);
|
|
|
|
tarc |= 1;
|
|
|
|
if (sc->hw.media_type == em_media_type_internal_serdes)
|
|
|
|
tarc |= (1 << 20);
|
|
|
|
E1000_WRITE_REG(&sc->hw, TARC0, tarc);
|
|
|
|
tarc = E1000_READ_REG(&sc->hw, TARC1);
|
|
|
|
tarc |= 1;
|
|
|
|
E1000_WRITE_REG(&sc->hw, TARC1, tarc);
|
|
|
|
}
|
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
/* Setup Transmit Descriptor Settings for this adapter */
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->txd_cmd = E1000_TXD_CMD_IFCS | E1000_TXD_CMD_RS;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->tx_int_delay.value > 0)
|
|
|
|
sc->txd_cmd |= E1000_TXD_CMD_IDE;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Free all transmit related data structures.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_free_transmit_structures(struct em_softc *sc)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_buffer *tx_buffer;
|
|
|
|
int i;
|
2003-05-02 21:17:08 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
INIT_DEBUGOUT("free_transmit_structures: begin");
|
2003-05-02 21:17:08 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->tx_buffer_area != NULL) {
|
|
|
|
tx_buffer = sc->tx_buffer_area;
|
|
|
|
for (i = 0; i < sc->num_tx_desc; i++, tx_buffer++) {
|
|
|
|
if (tx_buffer->m_head != NULL) {
|
|
|
|
bus_dmamap_sync(sc->txtag, tx_buffer->map,
|
2005-11-21 04:17:43 +00:00
|
|
|
BUS_DMASYNC_POSTWRITE);
|
2006-02-15 08:39:50 +00:00
|
|
|
bus_dmamap_unload(sc->txtag,
|
2005-11-21 04:17:43 +00:00
|
|
|
tx_buffer->map);
|
2006-02-15 08:39:50 +00:00
|
|
|
m_freem(tx_buffer->m_head);
|
2005-11-21 04:17:43 +00:00
|
|
|
tx_buffer->m_head = NULL;
|
2006-02-15 08:39:50 +00:00
|
|
|
} else if (tx_buffer->map != NULL)
|
|
|
|
bus_dmamap_unload(sc->txtag,
|
2005-11-21 04:17:43 +00:00
|
|
|
tx_buffer->map);
|
|
|
|
if (tx_buffer->map != NULL) {
|
2006-02-15 08:39:50 +00:00
|
|
|
bus_dmamap_destroy(sc->txtag,
|
2005-11-21 04:17:43 +00:00
|
|
|
tx_buffer->map);
|
|
|
|
tx_buffer->map = NULL;
|
|
|
|
}
|
2006-02-15 08:39:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sc->tx_buffer_area != NULL) {
|
|
|
|
free(sc->tx_buffer_area, M_DEVBUF);
|
|
|
|
sc->tx_buffer_area = NULL;
|
|
|
|
}
|
|
|
|
if (sc->txtag != NULL) {
|
|
|
|
bus_dma_tag_destroy(sc->txtag);
|
|
|
|
sc->txtag = NULL;
|
|
|
|
}
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
2002-08-26 18:59:16 +00:00
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_transmit_checksum_setup(struct em_softc *sc, struct mbuf *mp,
|
|
|
|
uint32_t *txd_upper, uint32_t *txd_lower)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
struct em_context_desc *TXD;
|
2002-12-23 19:11:23 +00:00
|
|
|
struct em_buffer *tx_buffer;
|
|
|
|
int curr_txd;
|
2002-06-03 22:30:51 +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;
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->active_checksum_context == OFFLOAD_TCP_IP)
|
2002-08-26 18:59:16 +00:00
|
|
|
return;
|
2002-06-03 22:30:51 +00:00
|
|
|
else
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->active_checksum_context = OFFLOAD_TCP_IP;
|
2002-06-03 22:30:51 +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;
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->active_checksum_context == OFFLOAD_UDP_IP)
|
2002-08-26 18:59:16 +00:00
|
|
|
return;
|
2002-06-03 22:30:51 +00:00
|
|
|
else
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->active_checksum_context = OFFLOAD_UDP_IP;
|
2002-06-03 22:30:51 +00:00
|
|
|
} else {
|
|
|
|
*txd_upper = 0;
|
|
|
|
*txd_lower = 0;
|
2002-08-26 18:59:16 +00:00
|
|
|
return;
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*txd_upper = 0;
|
|
|
|
*txd_lower = 0;
|
2002-08-26 18:59:16 +00:00
|
|
|
return;
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we reach this point, the checksum offload context
|
|
|
|
* needs to be reset.
|
|
|
|
*/
|
2006-02-15 08:39:50 +00:00
|
|
|
curr_txd = sc->next_avail_tx_desc;
|
|
|
|
tx_buffer = &sc->tx_buffer_area[curr_txd];
|
|
|
|
TXD = (struct em_context_desc *) &sc->tx_desc_base[curr_txd];
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
TXD->lower_setup.ip_fields.ipcss = ETHER_HDR_LEN;
|
2006-01-20 11:38:25 +00:00
|
|
|
TXD->lower_setup.ip_fields.ipcso =
|
2002-12-23 19:11:23 +00:00
|
|
|
ETHER_HDR_LEN + offsetof(struct ip, ip_sum);
|
2006-01-20 11:38:25 +00:00
|
|
|
TXD->lower_setup.ip_fields.ipcse =
|
2003-05-02 21:17:08 +00:00
|
|
|
htole16(ETHER_HDR_LEN + sizeof(struct ip) - 1);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
TXD->upper_setup.tcp_fields.tucss =
|
2002-12-23 19:11:23 +00:00
|
|
|
ETHER_HDR_LEN + sizeof(struct ip);
|
2003-05-02 21:17:08 +00:00
|
|
|
TXD->upper_setup.tcp_fields.tucse = htole16(0);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->active_checksum_context == OFFLOAD_TCP_IP) {
|
2006-01-20 11:38:25 +00:00
|
|
|
TXD->upper_setup.tcp_fields.tucso =
|
|
|
|
ETHER_HDR_LEN + sizeof(struct ip) +
|
2002-12-23 19:11:23 +00:00
|
|
|
offsetof(struct tcphdr, th_sum);
|
2006-02-15 08:39:50 +00:00
|
|
|
} else if (sc->active_checksum_context == OFFLOAD_UDP_IP) {
|
2006-01-20 11:38:25 +00:00
|
|
|
TXD->upper_setup.tcp_fields.tucso =
|
|
|
|
ETHER_HDR_LEN + sizeof(struct ip) +
|
2002-12-23 19:11:23 +00:00
|
|
|
offsetof(struct udphdr, uh_sum);
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
TXD->tcp_seg_setup.data = htole32(0);
|
2006-02-15 08:39:50 +00:00
|
|
|
TXD->cmd_and_length = htole32(sc->txd_cmd | E1000_TXD_CMD_DEXT);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2002-12-23 19:11:23 +00:00
|
|
|
tx_buffer->m_head = NULL;
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (++curr_txd == sc->num_tx_desc)
|
2002-12-23 19:11:23 +00:00
|
|
|
curr_txd = 0;
|
2002-08-26 18:59:16 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->num_tx_desc_avail--;
|
|
|
|
sc->next_avail_tx_desc = curr_txd;
|
2002-11-08 18:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
*
|
|
|
|
* Examine each tx_buffer in the used queue. If the hardware is done
|
|
|
|
* processing the packet then free associated resources. The
|
2002-12-23 19:11:23 +00:00
|
|
|
* tx_buffer is put back on the free queue.
|
2002-11-08 18:14:17 +00:00
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_txeof(struct em_softc *sc)
|
2002-11-08 18:14:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
int i, num_avail;
|
|
|
|
struct em_buffer *tx_buffer;
|
|
|
|
struct em_tx_desc *tx_desc;
|
|
|
|
struct ifnet *ifp = sc->ifp;
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK_ASSERT(sc);
|
2003-09-23 00:18:25 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->num_tx_desc_avail == sc->num_tx_desc)
|
|
|
|
return;
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
num_avail = sc->num_tx_desc_avail;
|
|
|
|
i = sc->oldest_used_tx_desc;
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
tx_buffer = &sc->tx_buffer_area[i];
|
|
|
|
tx_desc = &sc->tx_desc_base[i];
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
bus_dmamap_sync(sc->txdma.dma_tag, sc->txdma.dma_map,
|
|
|
|
BUS_DMASYNC_POSTREAD);
|
|
|
|
while (tx_desc->upper.fields.status & E1000_TXD_STAT_DD) {
|
2003-05-02 21:17:08 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
tx_desc->upper.data = 0;
|
|
|
|
num_avail++;
|
2003-05-02 21:17:08 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (tx_buffer->m_head) {
|
2003-06-05 17:51:38 +00:00
|
|
|
ifp->if_opackets++;
|
2006-02-15 08:39:50 +00:00
|
|
|
bus_dmamap_sync(sc->txtag, tx_buffer->map,
|
2005-11-21 04:17:43 +00:00
|
|
|
BUS_DMASYNC_POSTWRITE);
|
2006-02-15 08:39:50 +00:00
|
|
|
bus_dmamap_unload(sc->txtag, tx_buffer->map);
|
|
|
|
|
|
|
|
m_freem(tx_buffer->m_head);
|
|
|
|
tx_buffer->m_head = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (++i == sc->num_tx_desc)
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
tx_buffer = &sc->tx_buffer_area[i];
|
|
|
|
tx_desc = &sc->tx_desc_base[i];
|
|
|
|
}
|
|
|
|
bus_dmamap_sync(sc->txdma.dma_tag, sc->txdma.dma_map,
|
|
|
|
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
|
|
|
|
|
|
|
sc->oldest_used_tx_desc = i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have enough room, clear IFF_DRV_OACTIVE to tell the stack
|
|
|
|
* that it is OK to send packets.
|
|
|
|
* If there are no pending descriptors, clear the timeout. Otherwise,
|
|
|
|
* if some descriptors have been freed, restart the timeout.
|
|
|
|
*/
|
|
|
|
if (num_avail > EM_TX_CLEANUP_THRESHOLD) {
|
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
|
|
|
if (num_avail == sc->num_tx_desc)
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
else if (num_avail != sc->num_tx_desc_avail)
|
|
|
|
ifp->if_timer = EM_TX_TIMEOUT;
|
|
|
|
}
|
|
|
|
sc->num_tx_desc_avail = num_avail;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Get a buffer from system mbuf buffer pool.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static int
|
2006-02-15 08:39:50 +00:00
|
|
|
em_get_buf(int i, struct em_softc *sc, struct mbuf *mp)
|
2006-01-20 11:38:25 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct ifnet *ifp = sc->ifp;
|
2006-01-20 11:38:25 +00:00
|
|
|
bus_dma_segment_t segs[1];
|
|
|
|
struct em_buffer *rx_buffer;
|
|
|
|
int error, nsegs;
|
|
|
|
|
|
|
|
if (mp == NULL) {
|
|
|
|
mp = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
|
|
|
|
if (mp == NULL) {
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->mbuf_cluster_failed++;
|
|
|
|
return (ENOBUFS);
|
2006-01-20 11:38:25 +00:00
|
|
|
}
|
|
|
|
mp->m_len = mp->m_pkthdr.len = MCLBYTES;
|
|
|
|
} else {
|
|
|
|
mp->m_len = mp->m_pkthdr.len = MCLBYTES;
|
|
|
|
mp->m_data = mp->m_ext.ext_buf;
|
|
|
|
mp->m_next = NULL;
|
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
if (ifp->if_mtu <= ETHERMTU)
|
2006-02-15 08:39:50 +00:00
|
|
|
m_adj(mp, ETHER_ALIGN);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
rx_buffer = &sc->rx_buffer_area[i];
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
/*
|
|
|
|
* Using memory from the mbuf cluster pool, invoke the
|
|
|
|
* bus_dma machinery to arrange the memory mapping.
|
|
|
|
*/
|
2006-02-15 08:39:50 +00:00
|
|
|
error = bus_dmamap_load_mbuf_sg(sc->rxtag, rx_buffer->map,
|
2005-11-21 04:17:43 +00:00
|
|
|
mp, segs, &nsegs, 0);
|
2006-01-20 11:38:25 +00:00
|
|
|
if (error != 0) {
|
|
|
|
m_free(mp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
/* If nsegs is wrong then the stack is corrupt. */
|
2005-11-21 04:17:43 +00:00
|
|
|
KASSERT(nsegs == 1, ("Too many segments returned!"));
|
2006-01-20 11:38:25 +00:00
|
|
|
rx_buffer->m_head = mp;
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->rx_desc_base[i].buffer_addr = htole64(segs[0].ds_addr);
|
|
|
|
bus_dmamap_sync(sc->rxtag, rx_buffer->map, BUS_DMASYNC_PREREAD);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
return (0);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
2006-01-20 11:38:25 +00:00
|
|
|
* 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
|
2001-12-02 07:37:17 +00:00
|
|
|
* that we've allocated.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static int
|
2006-02-15 08:39:50 +00:00
|
|
|
em_allocate_receive_structures(struct em_softc *sc)
|
|
|
|
{
|
|
|
|
device_t dev = sc->dev;
|
|
|
|
struct em_buffer *rx_buffer;
|
|
|
|
int i, error;
|
|
|
|
|
|
|
|
sc->rx_buffer_area = malloc(sizeof(struct em_buffer) * sc->num_rx_desc,
|
|
|
|
M_DEVBUF, M_NOWAIT);
|
|
|
|
if (sc->rx_buffer_area == NULL) {
|
|
|
|
device_printf(dev, "Unable to allocate rx_buffer memory\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero(sc->rx_buffer_area, sizeof(struct em_buffer) * sc->num_rx_desc);
|
|
|
|
|
|
|
|
error = bus_dma_tag_create(NULL, /* parent */
|
|
|
|
1, 0, /* alignment, bounds */
|
|
|
|
BUS_SPACE_MAXADDR, /* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
|
|
|
MCLBYTES, /* maxsize */
|
|
|
|
1, /* nsegments */
|
|
|
|
MCLBYTES, /* maxsegsize */
|
2006-07-27 00:29:44 +00:00
|
|
|
0, /* flags */
|
2006-02-15 08:39:50 +00:00
|
|
|
NULL, /* lockfunc */
|
|
|
|
NULL, /* lockarg */
|
|
|
|
&sc->rxtag);
|
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "%s: bus_dma_tag_create failed %d\n",
|
|
|
|
__func__, error);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
rx_buffer = sc->rx_buffer_area;
|
|
|
|
for (i = 0; i < sc->num_rx_desc; i++, rx_buffer++) {
|
|
|
|
error = bus_dmamap_create(sc->rxtag, BUS_DMA_NOWAIT,
|
|
|
|
&rx_buffer->map);
|
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "%s: bus_dmamap_create failed: %d\n",
|
|
|
|
__func__, error);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < sc->num_rx_desc; i++) {
|
|
|
|
error = em_get_buf(i, sc, NULL);
|
|
|
|
if (error)
|
2005-11-21 04:17:43 +00:00
|
|
|
goto fail;
|
2006-02-15 08:39:50 +00:00
|
|
|
}
|
|
|
|
bus_dmamap_sync(sc->rxdma.dma_tag, sc->rxdma.dma_map,
|
|
|
|
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
return (0);
|
2003-05-02 21:17:08 +00:00
|
|
|
|
2005-11-21 04:17:43 +00:00
|
|
|
fail:
|
2006-02-15 08:39:50 +00:00
|
|
|
em_free_receive_structures(sc);
|
|
|
|
return (error);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Allocate and initialize receive structures.
|
2006-01-20 11:38:25 +00:00
|
|
|
*
|
2001-12-02 07:37:17 +00:00
|
|
|
**********************************************************************/
|
|
|
|
static int
|
2006-02-15 08:39:50 +00:00
|
|
|
em_setup_receive_structures(struct em_softc *sc)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
int error;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
bzero(sc->rx_desc_base, (sizeof(struct em_rx_desc)) * sc->num_rx_desc);
|
|
|
|
|
|
|
|
if ((error = em_allocate_receive_structures(sc)) != 0)
|
|
|
|
return (error);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Setup our descriptor pointers */
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->next_rx_desc_to_check = 0;
|
|
|
|
|
|
|
|
return (0);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Enable receive unit.
|
2006-01-20 11:38:25 +00:00
|
|
|
*
|
2001-12-02 07:37:17 +00:00
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_initialize_receive_unit(struct em_softc *sc)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct ifnet *ifp = sc->ifp;
|
|
|
|
uint64_t bus_addr;
|
|
|
|
uint32_t reg_rctl;
|
|
|
|
uint32_t reg_rxcsum;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
INIT_DEBUGOUT("em_initialize_receive_unit: begin");
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
/*
|
|
|
|
* Make sure receives are disabled while setting
|
|
|
|
* up the descriptor ring
|
|
|
|
*/
|
|
|
|
E1000_WRITE_REG(&sc->hw, RCTL, 0);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Set the Receive Delay Timer Register */
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, RDTR, sc->rx_int_delay.value | E1000_RDT_FPDB);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if(sc->hw.mac_type >= em_82540) {
|
|
|
|
E1000_WRITE_REG(&sc->hw, RADV, sc->rx_abs_int_delay.value);
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
/*
|
|
|
|
* Set the interrupt throttling rate. Value is calculated
|
|
|
|
* as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns)
|
|
|
|
*/
|
|
|
|
#define MAX_INTS_PER_SEC 8000
|
|
|
|
#define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
|
|
|
|
E1000_WRITE_REG(&sc->hw, ITR, DEFAULT_ITR);
|
|
|
|
}
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
/* Setup the Base and Length of the Rx Descriptor Ring */
|
2006-02-15 08:39:50 +00:00
|
|
|
bus_addr = sc->rxdma.dma_paddr;
|
|
|
|
E1000_WRITE_REG(&sc->hw, RDBAL, (uint32_t)bus_addr);
|
|
|
|
E1000_WRITE_REG(&sc->hw, RDBAH, (uint32_t)(bus_addr >> 32));
|
|
|
|
E1000_WRITE_REG(&sc->hw, RDLEN, sc->num_rx_desc *
|
2002-06-03 22:30:51 +00:00
|
|
|
sizeof(struct em_rx_desc));
|
|
|
|
|
|
|
|
/* Setup the HW Rx Head and Tail Descriptor Pointers */
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, RDH, 0);
|
|
|
|
E1000_WRITE_REG(&sc->hw, RDT, sc->num_rx_desc - 1);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Setup the Receive Control Register */
|
|
|
|
reg_rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO |
|
|
|
|
E1000_RCTL_RDMTS_HALF |
|
2006-02-15 08:39:50 +00:00
|
|
|
(sc->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->hw.tbi_compatibility_on == TRUE)
|
2002-06-03 22:30:51 +00:00
|
|
|
reg_rctl |= E1000_RCTL_SBP;
|
|
|
|
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
switch (sc->rx_buffer_len) {
|
2002-07-16 16:55:03 +00:00
|
|
|
default:
|
2002-06-03 22:30:51 +00:00
|
|
|
case EM_RXBUFFER_2048:
|
2002-07-16 16:55:03 +00:00
|
|
|
reg_rctl |= E1000_RCTL_SZ_2048;
|
2002-06-03 22:30:51 +00:00
|
|
|
break;
|
|
|
|
case EM_RXBUFFER_4096:
|
|
|
|
reg_rctl |= E1000_RCTL_SZ_4096 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
|
2006-01-20 11:38:25 +00:00
|
|
|
break;
|
2002-06-03 22:30:51 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-07-16 16:55:03 +00:00
|
|
|
if (ifp->if_mtu > ETHERMTU)
|
|
|
|
reg_rctl |= E1000_RCTL_LPE;
|
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
/* Enable 82543 Receive Checksum Offload for TCP and UDP */
|
2006-02-15 08:39:50 +00:00
|
|
|
if ((sc->hw.mac_type >= em_82543) &&
|
2002-06-03 22:30:51 +00:00
|
|
|
(ifp->if_capenable & IFCAP_RXCSUM)) {
|
2006-02-15 08:39:50 +00:00
|
|
|
reg_rxcsum = E1000_READ_REG(&sc->hw, RXCSUM);
|
2002-06-03 22:30:51 +00:00
|
|
|
reg_rxcsum |= (E1000_RXCSUM_IPOFL | E1000_RXCSUM_TUOFL);
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, RXCSUM, reg_rxcsum);
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable Receives */
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, RCTL, reg_rctl);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Free receive related data structures.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_free_receive_structures(struct em_softc *sc)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_buffer *rx_buffer;
|
|
|
|
int i;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
INIT_DEBUGOUT("free_receive_structures: begin");
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->rx_buffer_area != NULL) {
|
|
|
|
rx_buffer = sc->rx_buffer_area;
|
|
|
|
for (i = 0; i < sc->num_rx_desc; i++, rx_buffer++) {
|
2005-11-21 04:17:43 +00:00
|
|
|
if (rx_buffer->m_head != NULL) {
|
2006-02-15 08:39:50 +00:00
|
|
|
bus_dmamap_sync(sc->rxtag, rx_buffer->map,
|
2005-11-21 04:17:43 +00:00
|
|
|
BUS_DMASYNC_POSTREAD);
|
2006-02-15 08:39:50 +00:00
|
|
|
bus_dmamap_unload(sc->rxtag,
|
2005-11-21 04:17:43 +00:00
|
|
|
rx_buffer->map);
|
|
|
|
m_freem(rx_buffer->m_head);
|
|
|
|
rx_buffer->m_head = NULL;
|
|
|
|
} else if (rx_buffer->map != NULL)
|
2006-02-15 08:39:50 +00:00
|
|
|
bus_dmamap_unload(sc->rxtag,
|
2005-11-21 04:17:43 +00:00
|
|
|
rx_buffer->map);
|
2006-02-15 08:39:50 +00:00
|
|
|
if (rx_buffer->map != NULL) {
|
|
|
|
bus_dmamap_destroy(sc->rxtag,
|
2005-11-21 04:17:43 +00:00
|
|
|
rx_buffer->map);
|
|
|
|
rx_buffer->map = NULL;
|
|
|
|
}
|
2006-02-15 08:39:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sc->rx_buffer_area != NULL) {
|
|
|
|
free(sc->rx_buffer_area, M_DEVBUF);
|
|
|
|
sc->rx_buffer_area = NULL;
|
|
|
|
}
|
|
|
|
if (sc->rxtag != NULL) {
|
|
|
|
bus_dma_tag_destroy(sc->rxtag);
|
|
|
|
sc->rxtag = NULL;
|
|
|
|
}
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2002-12-23 19:11:23 +00:00
|
|
|
* We loop at most count times if count is > 0, or until done if
|
|
|
|
* count < 0.
|
|
|
|
*
|
2001-12-02 07:37:17 +00:00
|
|
|
*********************************************************************/
|
2006-01-11 00:30:25 +00:00
|
|
|
static int
|
2006-02-15 08:39:50 +00:00
|
|
|
em_rxeof(struct em_softc *sc, int count)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2006-01-20 11:38:25 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct mbuf *mp;
|
|
|
|
uint8_t accept_frame = 0;
|
|
|
|
uint8_t eop = 0;
|
|
|
|
uint16_t len, desc_len, prev_len_adj;
|
|
|
|
int i;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Pointer to the receive descriptor being examined. */
|
|
|
|
struct em_rx_desc *current_desc;
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
ifp = sc->ifp;
|
|
|
|
i = sc->next_rx_desc_to_check;
|
|
|
|
current_desc = &sc->rx_desc_base[i];
|
|
|
|
bus_dmamap_sync(sc->rxdma.dma_tag, sc->rxdma.dma_map,
|
2004-10-19 23:31:44 +00:00
|
|
|
BUS_DMASYNC_POSTREAD);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
if (!((current_desc->status) & E1000_RXD_STAT_DD))
|
2006-01-11 00:30:25 +00:00
|
|
|
return (0);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2005-10-19 13:34:48 +00:00
|
|
|
while ((current_desc->status & E1000_RXD_STAT_DD) &&
|
2006-01-20 11:38:25 +00:00
|
|
|
(count != 0) &&
|
|
|
|
(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
|
2005-10-14 11:00:15 +00:00
|
|
|
struct mbuf *m = NULL;
|
2005-11-09 08:43:18 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
mp = sc->rx_buffer_area[i].m_head;
|
|
|
|
bus_dmamap_sync(sc->rxtag, sc->rx_buffer_area[i].map,
|
2005-11-21 04:17:43 +00:00
|
|
|
BUS_DMASYNC_POSTREAD);
|
2006-02-15 08:39:50 +00:00
|
|
|
bus_dmamap_unload(sc->rxtag,
|
|
|
|
sc->rx_buffer_area[i].map);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
accept_frame = 1;
|
2003-11-14 18:02:25 +00:00
|
|
|
prev_len_adj = 0;
|
2006-01-20 11:38:25 +00:00
|
|
|
desc_len = le16toh(current_desc->length);
|
2002-06-03 22:30:51 +00:00
|
|
|
if (current_desc->status & E1000_RXD_STAT_EOP) {
|
2002-11-25 19:56:16 +00:00
|
|
|
count--;
|
2002-06-03 22:30:51 +00:00
|
|
|
eop = 1;
|
2003-11-14 18:02:25 +00:00
|
|
|
if (desc_len < ETHER_CRC_LEN) {
|
2006-01-20 11:38:25 +00:00
|
|
|
len = 0;
|
|
|
|
prev_len_adj = ETHER_CRC_LEN - desc_len;
|
|
|
|
} else
|
|
|
|
len = desc_len - ETHER_CRC_LEN;
|
2002-06-03 22:30:51 +00:00
|
|
|
} else {
|
|
|
|
eop = 0;
|
2003-05-02 21:17:08 +00:00
|
|
|
len = desc_len;
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
|
2006-01-20 11:38:25 +00:00
|
|
|
uint8_t last_byte;
|
|
|
|
uint32_t pkt_len = desc_len;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->fmp != NULL)
|
|
|
|
pkt_len += sc->fmp->m_pkthdr.len;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
last_byte = *(mtod(mp, caddr_t) + desc_len - 1);
|
2006-02-15 08:39:50 +00:00
|
|
|
if (TBI_ACCEPT(&sc->hw, current_desc->status,
|
2006-01-20 11:38:25 +00:00
|
|
|
current_desc->errors,
|
|
|
|
pkt_len, last_byte)) {
|
2006-02-15 08:39:50 +00:00
|
|
|
em_tbi_adjust_stats(&sc->hw,
|
|
|
|
&sc->stats, pkt_len,
|
|
|
|
sc->hw.mac_addr);
|
2006-01-20 11:38:25 +00:00
|
|
|
if (len > 0)
|
|
|
|
len--;
|
|
|
|
} else
|
2002-06-03 22:30:51 +00:00
|
|
|
accept_frame = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (accept_frame) {
|
2006-02-15 08:39:50 +00:00
|
|
|
if (em_get_buf(i, sc, NULL) == ENOBUFS) {
|
|
|
|
sc->dropped_pkts++;
|
|
|
|
em_get_buf(i, sc, mp);
|
|
|
|
if (sc->fmp != NULL)
|
|
|
|
m_freem(sc->fmp);
|
|
|
|
sc->fmp = NULL;
|
|
|
|
sc->lmp = NULL;
|
2002-06-03 22:30:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Assign correct length to the current fragment */
|
|
|
|
mp->m_len = len;
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->fmp == NULL) {
|
2002-06-03 22:30:51 +00:00
|
|
|
mp->m_pkthdr.len = len;
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->fmp = mp; /* Store the first mbuf */
|
|
|
|
sc->lmp = mp;
|
2002-06-03 22:30:51 +00:00
|
|
|
} else {
|
|
|
|
/* Chain mbuf's together */
|
|
|
|
mp->m_flags &= ~M_PKTHDR;
|
2006-01-20 11:38:25 +00:00
|
|
|
/*
|
|
|
|
* Adjust length of previous mbuf in chain if
|
|
|
|
* we received less than 4 bytes in the last
|
|
|
|
* descriptor.
|
|
|
|
*/
|
2003-11-14 18:02:25 +00:00
|
|
|
if (prev_len_adj > 0) {
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->lmp->m_len -= prev_len_adj;
|
|
|
|
sc->fmp->m_pkthdr.len -=
|
2006-01-20 11:38:25 +00:00
|
|
|
prev_len_adj;
|
2003-11-14 18:02:25 +00:00
|
|
|
}
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->lmp->m_next = mp;
|
|
|
|
sc->lmp = sc->lmp->m_next;
|
|
|
|
sc->fmp->m_pkthdr.len += len;
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
if (eop) {
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->fmp->m_pkthdr.rcvif = ifp;
|
2005-10-14 10:34:46 +00:00
|
|
|
ifp->if_ipackets++;
|
2006-02-15 08:39:50 +00:00
|
|
|
em_receive_checksum(sc, current_desc,
|
|
|
|
sc->fmp);
|
2005-12-16 08:29:43 +00:00
|
|
|
#ifndef __NO_STRICT_ALIGNMENT
|
|
|
|
if (ifp->if_mtu > ETHERMTU &&
|
2006-02-15 08:39:50 +00:00
|
|
|
em_fixup_rx(sc) != 0)
|
2005-12-16 08:29:43 +00:00
|
|
|
goto skip;
|
|
|
|
#endif
|
2006-01-20 11:38:25 +00:00
|
|
|
if (current_desc->status & E1000_RXD_STAT_VP)
|
2006-02-15 08:39:50 +00:00
|
|
|
VLAN_INPUT_TAG(ifp, sc->fmp,
|
2005-11-09 08:43:18 +00:00
|
|
|
(le16toh(current_desc->special) &
|
2005-12-18 18:24:27 +00:00
|
|
|
E1000_RXD_SPC_VLAN_MASK));
|
2005-12-16 08:29:43 +00:00
|
|
|
#ifndef __NO_STRICT_ALIGNMENT
|
|
|
|
skip:
|
|
|
|
#endif
|
2006-02-15 08:39:50 +00:00
|
|
|
m = sc->fmp;
|
|
|
|
sc->fmp = NULL;
|
|
|
|
sc->lmp = NULL;
|
2006-01-20 11:38:25 +00:00
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
} else {
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->dropped_pkts++;
|
|
|
|
em_get_buf(i, sc, mp);
|
|
|
|
if (sc->fmp != NULL)
|
|
|
|
m_freem(sc->fmp);
|
|
|
|
sc->fmp = NULL;
|
|
|
|
sc->lmp = NULL;
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
/* Zero out the receive descriptors status. */
|
2002-06-03 22:30:51 +00:00
|
|
|
current_desc->status = 0;
|
2006-02-15 08:39:50 +00:00
|
|
|
bus_dmamap_sync(sc->rxdma.dma_tag, sc->rxdma.dma_map,
|
2005-10-18 00:42:10 +00:00
|
|
|
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
2006-01-20 11:38:25 +00:00
|
|
|
|
|
|
|
/* Advance our pointers to the next descriptor. */
|
2006-02-15 08:39:50 +00:00
|
|
|
if (++i == sc->num_rx_desc)
|
2005-10-14 11:00:15 +00:00
|
|
|
i = 0;
|
|
|
|
if (m != NULL) {
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->next_rx_desc_to_check = i;
|
2006-06-06 08:03:49 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
|
|
|
EM_UNLOCK(sc);
|
2005-10-14 11:00:15 +00:00
|
|
|
(*ifp->if_input)(ifp, m);
|
2006-06-06 08:03:49 +00:00
|
|
|
EM_LOCK(sc);
|
|
|
|
#else
|
|
|
|
(*ifp->if_input)(ifp, m);
|
|
|
|
#endif
|
2006-02-15 08:39:50 +00:00
|
|
|
i = sc->next_rx_desc_to_check;
|
2005-10-14 11:00:15 +00:00
|
|
|
}
|
2006-02-15 08:39:50 +00:00
|
|
|
current_desc = &sc->rx_desc_base[i];
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->next_rx_desc_to_check = i;
|
2006-01-11 00:30:25 +00:00
|
|
|
|
|
|
|
/* Advance the E1000's Receive Queue #0 "Tail Pointer". */
|
2006-01-20 11:38:25 +00:00
|
|
|
if (--i < 0)
|
2006-02-15 08:39:50 +00:00
|
|
|
i = sc->num_rx_desc - 1;
|
|
|
|
E1000_WRITE_REG(&sc->hw, RDT, i);
|
2006-01-20 11:38:25 +00:00
|
|
|
if (!((current_desc->status) & E1000_RXD_STAT_DD))
|
2006-01-11 00:30:25 +00:00
|
|
|
return (0);
|
2006-01-20 11:38:25 +00:00
|
|
|
|
2006-01-11 00:30:25 +00:00
|
|
|
return (1);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
2005-12-16 08:29:43 +00:00
|
|
|
#ifndef __NO_STRICT_ALIGNMENT
|
|
|
|
/*
|
|
|
|
* When jumbo frames are enabled we should realign entire payload on
|
|
|
|
* architecures with strict alignment. This is serious design mistake of 8254x
|
|
|
|
* as it nullifies DMA operations. 8254x just allows RX buffer size to be
|
|
|
|
* 2048/4096/8192/16384. What we really want is 2048 - ETHER_ALIGN to align its
|
|
|
|
* payload. On architecures without strict alignment restrictions 8254x still
|
2006-01-20 11:38:25 +00:00
|
|
|
* performs unaligned memory access which would reduce the performance too.
|
2005-12-16 08:29:43 +00:00
|
|
|
* To avoid copying over an entire frame to align, we allocate a new mbuf and
|
|
|
|
* copy ethernet header to the new mbuf. The new mbuf is prepended into the
|
|
|
|
* existing mbuf chain.
|
|
|
|
*
|
|
|
|
* Be aware, best performance of the 8254x is achived only when jumbo frame is
|
|
|
|
* not used at all on architectures with strict alignment.
|
|
|
|
*/
|
|
|
|
static int
|
2006-02-15 08:39:50 +00:00
|
|
|
em_fixup_rx(struct em_softc *sc)
|
2005-12-16 08:29:43 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m, *n;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = 0;
|
2006-02-15 08:39:50 +00:00
|
|
|
m = sc->fmp;
|
2005-12-16 08:29:43 +00:00
|
|
|
if (m->m_len <= (MCLBYTES - ETHER_HDR_LEN)) {
|
|
|
|
bcopy(m->m_data, m->m_data + ETHER_HDR_LEN, m->m_len);
|
|
|
|
m->m_data += ETHER_HDR_LEN;
|
|
|
|
} else {
|
|
|
|
MGETHDR(n, M_DONTWAIT, MT_DATA);
|
|
|
|
if (n != NULL) {
|
|
|
|
bcopy(m->m_data, n->m_data, ETHER_HDR_LEN);
|
|
|
|
m->m_data += ETHER_HDR_LEN;
|
|
|
|
m->m_len -= ETHER_HDR_LEN;
|
|
|
|
n->m_len = ETHER_HDR_LEN;
|
|
|
|
M_MOVE_PKTHDR(n, m);
|
|
|
|
n->m_next = m;
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->fmp = n;
|
2005-12-16 08:29:43 +00:00
|
|
|
} else {
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->dropped_pkts++;
|
|
|
|
m_freem(sc->fmp);
|
|
|
|
sc->fmp = NULL;
|
2005-12-16 08:29:43 +00:00
|
|
|
error = ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
/*********************************************************************
|
|
|
|
*
|
2006-01-20 11:38:25 +00:00
|
|
|
* Verify that the hardware indicated that the checksum is valid.
|
2001-12-02 07:37:17 +00:00
|
|
|
* Inform the stack about the status of checksum so that stack
|
|
|
|
* doesn't spend time verifying the checksum.
|
|
|
|
*
|
|
|
|
*********************************************************************/
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_receive_checksum(struct em_softc *sc, struct em_rx_desc *rx_desc,
|
2002-06-03 22:30:51 +00:00
|
|
|
struct mbuf *mp)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
/* 82543 or newer only */
|
2006-02-15 08:39:50 +00:00
|
|
|
if ((sc->hw.mac_type < em_82543) ||
|
2002-06-03 22:30:51 +00:00
|
|
|
/* Ignore Checksum bit is set */
|
|
|
|
(rx_desc->status & E1000_RXD_STAT_IXSM)) {
|
|
|
|
mp->m_pkthdr.csum_flags = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rx_desc->status & E1000_RXD_STAT_IPCS) {
|
|
|
|
/* Did it pass? */
|
|
|
|
if (!(rx_desc->errors & E1000_RXD_ERR_IPE)) {
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rx_desc->status & E1000_RXD_STAT_TCPCS) {
|
2006-01-20 11:38:25 +00:00
|
|
|
/* Did it pass? */
|
2002-06-03 22:30:51 +00:00
|
|
|
if (!(rx_desc->errors & E1000_RXD_ERR_TCPE)) {
|
2006-01-20 11:38:25 +00:00
|
|
|
mp->m_pkthdr.csum_flags |=
|
2002-06-03 22:30:51 +00:00
|
|
|
(CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
|
|
|
|
mp->m_pkthdr.csum_data = htons(0xffff);
|
|
|
|
}
|
|
|
|
}
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_enable_vlans(struct em_softc *sc)
|
2002-06-03 22:30:51 +00:00
|
|
|
{
|
|
|
|
uint32_t ctrl;
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, VET, ETHERTYPE_VLAN);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
ctrl = E1000_READ_REG(&sc->hw, CTRL);
|
2006-01-20 11:38:25 +00:00
|
|
|
ctrl |= E1000_CTRL_VME;
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, CTRL, ctrl);
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
|
2005-01-26 13:44:47 +00:00
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_disable_vlans(struct em_softc *sc)
|
2005-01-26 13:44:47 +00:00
|
|
|
{
|
|
|
|
uint32_t ctrl;
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
ctrl = E1000_READ_REG(&sc->hw, CTRL);
|
2005-01-26 13:44:47 +00:00
|
|
|
ctrl &= ~E1000_CTRL_VME;
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, CTRL, ctrl);
|
2005-01-26 13:44:47 +00:00
|
|
|
}
|
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_enable_intr(struct em_softc *sc)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, IMS, (IMS_ENABLE_MASK));
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_disable_intr(struct em_softc *sc)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2005-01-01 19:57:23 +00:00
|
|
|
/*
|
2006-01-20 11:38:25 +00:00
|
|
|
* The first version of 82542 had an errata where when link was forced
|
|
|
|
* it would stay up even up even if the cable was disconnected.
|
|
|
|
* Sequence errors were used to detect the disconnect and then the
|
|
|
|
* driver would unforce the link. This code in the in the ISR. For this
|
|
|
|
* to work correctly the Sequence error interrupt had to be enabled
|
|
|
|
* all the time.
|
2005-01-01 19:57:23 +00:00
|
|
|
*/
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (sc->hw.mac_type == em_82542_rev2_0)
|
|
|
|
E1000_WRITE_REG(&sc->hw, IMC,
|
|
|
|
(0xffffffff & ~E1000_IMC_RXSEQ));
|
2005-01-01 19:57:23 +00:00
|
|
|
else
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_REG(&sc->hw, IMC,
|
|
|
|
0xffffffff);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
2003-06-05 17:51:38 +00:00
|
|
|
static int
|
2006-02-15 08:39:50 +00:00
|
|
|
em_is_valid_ether_addr(uint8_t *addr)
|
2003-06-05 17:51:38 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
char zero_addr[6] = { 0, 0, 0, 0, 0, 0 };
|
2006-01-20 11:38:25 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if ((addr[0] & 1) || (!bcmp(addr, zero_addr, ETHER_ADDR_LEN))) {
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2003-06-05 17:51:38 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
return (TRUE);
|
2003-06-05 17:51:38 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_write_pci_cfg(struct em_hw *hw, uint32_t reg, uint16_t *value)
|
2002-02-13 18:19:27 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
pci_write_config(((struct em_osdep *)hw->back)->dev, reg, *value, 2);
|
2002-02-13 18:19:27 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 11:38:25 +00:00
|
|
|
void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_read_pci_cfg(struct em_hw *hw, uint32_t reg, uint16_t *value)
|
2002-07-16 16:55:03 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
*value = pci_read_config(((struct em_osdep *)hw->back)->dev, reg, 2);
|
2002-07-16 16:55:03 +00:00
|
|
|
}
|
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
void
|
|
|
|
em_pci_set_mwi(struct em_hw *hw)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
pci_write_config(((struct em_osdep *)hw->back)->dev, PCIR_COMMAND,
|
|
|
|
(hw->pci_cmd_word | CMD_MEM_WRT_INVALIDATE), 2);
|
2002-11-08 18:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
em_pci_clear_mwi(struct em_hw *hw)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
pci_write_config(((struct em_osdep *)hw->back)->dev, PCIR_COMMAND,
|
|
|
|
(hw->pci_cmd_word & ~CMD_MEM_WRT_INVALIDATE), 2);
|
2002-11-08 18:14:17 +00:00
|
|
|
}
|
|
|
|
|
2003-08-27 21:52:37 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* 82544 Coexistence issue workaround.
|
|
|
|
* There are 2 issues.
|
|
|
|
* 1. Transmit Hang issue.
|
|
|
|
* To detect this issue, following equation can be used...
|
2006-02-15 08:39:50 +00:00
|
|
|
* SIZE[3:0] + ADDR[2:0] = SUM[3:0].
|
|
|
|
* If SUM[3:0] is in between 1 to 4, we will have this issue.
|
2003-08-27 21:52:37 +00:00
|
|
|
*
|
|
|
|
* 2. DAC issue.
|
|
|
|
* To detect this issue, following equation can be used...
|
2006-02-15 08:39:50 +00:00
|
|
|
* SIZE[3:0] + ADDR[2:0] = SUM[3:0].
|
|
|
|
* If SUM[3:0] is in between 9 to c, we will have this issue.
|
2003-08-27 21:52:37 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* WORKAROUND:
|
2006-02-15 08:39:50 +00:00
|
|
|
* Make sure we do not have ending address as 1,2,3,4(Hang) or 9,a,b,c (DAC)
|
2003-08-27 21:52:37 +00:00
|
|
|
*
|
|
|
|
*** *********************************************************************/
|
2006-02-15 08:39:50 +00:00
|
|
|
static uint32_t
|
|
|
|
em_fill_descriptors (bus_addr_t address, uint32_t length,
|
|
|
|
PDESC_ARRAY desc_array)
|
|
|
|
{
|
|
|
|
/* Since issue is sensitive to length and address.*/
|
|
|
|
/* Let us first check the address...*/
|
|
|
|
uint32_t safe_terminator;
|
|
|
|
if (length <= 4) {
|
|
|
|
desc_array->descriptor[0].address = address;
|
|
|
|
desc_array->descriptor[0].length = length;
|
|
|
|
desc_array->elements = 1;
|
|
|
|
return (desc_array->elements);
|
|
|
|
}
|
|
|
|
safe_terminator = (uint32_t)((((uint32_t)address & 0x7) + (length & 0xF)) & 0xF);
|
|
|
|
/* if it does not fall between 0x1 to 0x4 and 0x9 to 0xC then return */
|
|
|
|
if (safe_terminator == 0 ||
|
|
|
|
(safe_terminator > 4 &&
|
|
|
|
safe_terminator < 9) ||
|
|
|
|
(safe_terminator > 0xC &&
|
|
|
|
safe_terminator <= 0xF)) {
|
|
|
|
desc_array->descriptor[0].address = address;
|
|
|
|
desc_array->descriptor[0].length = length;
|
|
|
|
desc_array->elements = 1;
|
|
|
|
return (desc_array->elements);
|
|
|
|
}
|
|
|
|
|
|
|
|
desc_array->descriptor[0].address = address;
|
|
|
|
desc_array->descriptor[0].length = length - 4;
|
|
|
|
desc_array->descriptor[1].address = address + (length - 4);
|
|
|
|
desc_array->descriptor[1].length = 4;
|
|
|
|
desc_array->elements = 2;
|
|
|
|
return (desc_array->elements);
|
2003-08-27 21:52:37 +00:00
|
|
|
}
|
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
/**********************************************************************
|
|
|
|
*
|
2006-01-20 11:38:25 +00:00
|
|
|
* Update the board statistics counters.
|
2001-12-02 07:37:17 +00:00
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_update_stats_counters(struct em_softc *sc)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if(sc->hw.media_type == em_media_type_copper ||
|
|
|
|
(E1000_READ_REG(&sc->hw, STATUS) & E1000_STATUS_LU)) {
|
|
|
|
sc->stats.symerrs += E1000_READ_REG(&sc->hw, SYMERRS);
|
|
|
|
sc->stats.sec += E1000_READ_REG(&sc->hw, SEC);
|
|
|
|
}
|
|
|
|
sc->stats.crcerrs += E1000_READ_REG(&sc->hw, CRCERRS);
|
|
|
|
sc->stats.mpc += E1000_READ_REG(&sc->hw, MPC);
|
|
|
|
sc->stats.scc += E1000_READ_REG(&sc->hw, SCC);
|
|
|
|
sc->stats.ecol += E1000_READ_REG(&sc->hw, ECOL);
|
|
|
|
|
|
|
|
sc->stats.mcc += E1000_READ_REG(&sc->hw, MCC);
|
|
|
|
sc->stats.latecol += E1000_READ_REG(&sc->hw, LATECOL);
|
|
|
|
sc->stats.colc += E1000_READ_REG(&sc->hw, COLC);
|
|
|
|
sc->stats.dc += E1000_READ_REG(&sc->hw, DC);
|
|
|
|
sc->stats.rlec += E1000_READ_REG(&sc->hw, RLEC);
|
|
|
|
sc->stats.xonrxc += E1000_READ_REG(&sc->hw, XONRXC);
|
|
|
|
sc->stats.xontxc += E1000_READ_REG(&sc->hw, XONTXC);
|
|
|
|
sc->stats.xoffrxc += E1000_READ_REG(&sc->hw, XOFFRXC);
|
|
|
|
sc->stats.xofftxc += E1000_READ_REG(&sc->hw, XOFFTXC);
|
|
|
|
sc->stats.fcruc += E1000_READ_REG(&sc->hw, FCRUC);
|
|
|
|
sc->stats.prc64 += E1000_READ_REG(&sc->hw, PRC64);
|
|
|
|
sc->stats.prc127 += E1000_READ_REG(&sc->hw, PRC127);
|
|
|
|
sc->stats.prc255 += E1000_READ_REG(&sc->hw, PRC255);
|
|
|
|
sc->stats.prc511 += E1000_READ_REG(&sc->hw, PRC511);
|
|
|
|
sc->stats.prc1023 += E1000_READ_REG(&sc->hw, PRC1023);
|
|
|
|
sc->stats.prc1522 += E1000_READ_REG(&sc->hw, PRC1522);
|
|
|
|
sc->stats.gprc += E1000_READ_REG(&sc->hw, GPRC);
|
|
|
|
sc->stats.bprc += E1000_READ_REG(&sc->hw, BPRC);
|
|
|
|
sc->stats.mprc += E1000_READ_REG(&sc->hw, MPRC);
|
|
|
|
sc->stats.gptc += E1000_READ_REG(&sc->hw, GPTC);
|
2002-06-03 22:30:51 +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 */
|
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->stats.gorcl += E1000_READ_REG(&sc->hw, GORCL);
|
|
|
|
sc->stats.gorch += E1000_READ_REG(&sc->hw, GORCH);
|
|
|
|
sc->stats.gotcl += E1000_READ_REG(&sc->hw, GOTCL);
|
|
|
|
sc->stats.gotch += E1000_READ_REG(&sc->hw, GOTCH);
|
|
|
|
|
|
|
|
sc->stats.rnbc += E1000_READ_REG(&sc->hw, RNBC);
|
|
|
|
sc->stats.ruc += E1000_READ_REG(&sc->hw, RUC);
|
|
|
|
sc->stats.rfc += E1000_READ_REG(&sc->hw, RFC);
|
|
|
|
sc->stats.roc += E1000_READ_REG(&sc->hw, ROC);
|
|
|
|
sc->stats.rjc += E1000_READ_REG(&sc->hw, RJC);
|
|
|
|
|
|
|
|
sc->stats.torl += E1000_READ_REG(&sc->hw, TORL);
|
|
|
|
sc->stats.torh += E1000_READ_REG(&sc->hw, TORH);
|
|
|
|
sc->stats.totl += E1000_READ_REG(&sc->hw, TOTL);
|
|
|
|
sc->stats.toth += E1000_READ_REG(&sc->hw, TOTH);
|
|
|
|
|
|
|
|
sc->stats.tpr += E1000_READ_REG(&sc->hw, TPR);
|
|
|
|
sc->stats.tpt += E1000_READ_REG(&sc->hw, TPT);
|
|
|
|
sc->stats.ptc64 += E1000_READ_REG(&sc->hw, PTC64);
|
|
|
|
sc->stats.ptc127 += E1000_READ_REG(&sc->hw, PTC127);
|
|
|
|
sc->stats.ptc255 += E1000_READ_REG(&sc->hw, PTC255);
|
|
|
|
sc->stats.ptc511 += E1000_READ_REG(&sc->hw, PTC511);
|
|
|
|
sc->stats.ptc1023 += E1000_READ_REG(&sc->hw, PTC1023);
|
|
|
|
sc->stats.ptc1522 += E1000_READ_REG(&sc->hw, PTC1522);
|
|
|
|
sc->stats.mptc += E1000_READ_REG(&sc->hw, MPTC);
|
|
|
|
sc->stats.bptc += E1000_READ_REG(&sc->hw, BPTC);
|
|
|
|
|
|
|
|
if (sc->hw.mac_type >= em_82543) {
|
|
|
|
sc->stats.algnerrc += E1000_READ_REG(&sc->hw, ALGNERRC);
|
|
|
|
sc->stats.rxerrc += E1000_READ_REG(&sc->hw, RXERRC);
|
|
|
|
sc->stats.tncrs += E1000_READ_REG(&sc->hw, TNCRS);
|
|
|
|
sc->stats.cexterr += E1000_READ_REG(&sc->hw, CEXTERR);
|
|
|
|
sc->stats.tsctc += E1000_READ_REG(&sc->hw, TSCTC);
|
|
|
|
sc->stats.tsctfc += E1000_READ_REG(&sc->hw, TSCTFC);
|
|
|
|
}
|
|
|
|
ifp = sc->ifp;
|
|
|
|
|
|
|
|
ifp->if_collisions = sc->stats.colc;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Rx Errors */
|
2006-02-15 08:39:50 +00:00
|
|
|
ifp->if_ierrors = sc->dropped_pkts + sc->stats.rxerrc +
|
|
|
|
sc->stats.crcerrs + sc->stats.algnerrc + sc->stats.rlec +
|
|
|
|
sc->stats.mpc + sc->stats.cexterr;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Tx Errors */
|
2006-02-15 08:39:50 +00:00
|
|
|
ifp->if_oerrors = sc->stats.ecol + sc->stats.latecol +
|
|
|
|
sc->watchdog_events;
|
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
|
2006-02-15 08:39:50 +00:00
|
|
|
em_print_debug_info(struct em_softc *sc)
|
|
|
|
{
|
|
|
|
device_t dev = sc->dev;
|
|
|
|
uint8_t *hw_addr = sc->hw.hw_addr;
|
|
|
|
|
|
|
|
device_printf(dev, "Adapter hardware address = %p \n", hw_addr);
|
|
|
|
device_printf(dev, "CTRL = 0x%x RCTL = 0x%x \n",
|
|
|
|
E1000_READ_REG(&sc->hw, CTRL),
|
|
|
|
E1000_READ_REG(&sc->hw, RCTL));
|
|
|
|
device_printf(dev, "Packet buffer = Tx=%dk Rx=%dk \n",
|
|
|
|
((E1000_READ_REG(&sc->hw, PBA) & 0xffff0000) >> 16),\
|
|
|
|
(E1000_READ_REG(&sc->hw, PBA) & 0xffff) );
|
|
|
|
device_printf(dev, "Flow control watermarks high = %d low = %d\n",
|
|
|
|
sc->hw.fc_high_water,
|
|
|
|
sc->hw.fc_low_water);
|
|
|
|
device_printf(dev, "tx_int_delay = %d, tx_abs_int_delay = %d\n",
|
|
|
|
E1000_READ_REG(&sc->hw, TIDV),
|
|
|
|
E1000_READ_REG(&sc->hw, TADV));
|
|
|
|
device_printf(dev, "rx_int_delay = %d, rx_abs_int_delay = %d\n",
|
|
|
|
E1000_READ_REG(&sc->hw, RDTR),
|
|
|
|
E1000_READ_REG(&sc->hw, RADV));
|
|
|
|
device_printf(dev, "fifo workaround = %lld, fifo_reset_count = %lld\n",
|
|
|
|
(long long)sc->tx_fifo_wrk_cnt,
|
|
|
|
(long long)sc->tx_fifo_reset_cnt);
|
|
|
|
device_printf(dev, "hw tdh = %d, hw tdt = %d\n",
|
|
|
|
E1000_READ_REG(&sc->hw, TDH),
|
|
|
|
E1000_READ_REG(&sc->hw, TDT));
|
|
|
|
device_printf(dev, "Num Tx descriptors avail = %d\n",
|
|
|
|
sc->num_tx_desc_avail);
|
|
|
|
device_printf(dev, "Tx Descriptors not avail1 = %ld\n",
|
|
|
|
sc->no_tx_desc_avail1);
|
|
|
|
device_printf(dev, "Tx Descriptors not avail2 = %ld\n",
|
|
|
|
sc->no_tx_desc_avail2);
|
|
|
|
device_printf(dev, "Std mbuf failed = %ld\n",
|
|
|
|
sc->mbuf_alloc_failed);
|
|
|
|
device_printf(dev, "Std mbuf cluster failed = %ld\n",
|
|
|
|
sc->mbuf_cluster_failed);
|
|
|
|
device_printf(dev, "Driver dropped packets = %ld\n",
|
|
|
|
sc->dropped_pkts);
|
2003-06-05 17:51:38 +00:00
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-06-05 17:51:38 +00:00
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_print_hw_stats(struct em_softc *sc)
|
|
|
|
{
|
|
|
|
device_t dev = sc->dev;
|
|
|
|
|
|
|
|
device_printf(dev, "Excessive collisions = %lld\n",
|
|
|
|
(long long)sc->stats.ecol);
|
|
|
|
device_printf(dev, "Symbol errors = %lld\n",
|
|
|
|
(long long)sc->stats.symerrs);
|
|
|
|
device_printf(dev, "Sequence errors = %lld\n",
|
|
|
|
(long long)sc->stats.sec);
|
|
|
|
device_printf(dev, "Defer count = %lld\n", (long long)sc->stats.dc);
|
|
|
|
|
|
|
|
device_printf(dev, "Missed Packets = %lld\n", (long long)sc->stats.mpc);
|
|
|
|
device_printf(dev, "Receive No Buffers = %lld\n",
|
|
|
|
(long long)sc->stats.rnbc);
|
|
|
|
device_printf(dev, "Receive length errors = %lld\n",
|
|
|
|
(long long)sc->stats.rlec);
|
|
|
|
device_printf(dev, "Receive errors = %lld\n",
|
|
|
|
(long long)sc->stats.rxerrc);
|
|
|
|
device_printf(dev, "Crc errors = %lld\n", (long long)sc->stats.crcerrs);
|
|
|
|
device_printf(dev, "Alignment errors = %lld\n",
|
|
|
|
(long long)sc->stats.algnerrc);
|
|
|
|
device_printf(dev, "Carrier extension errors = %lld\n",
|
|
|
|
(long long)sc->stats.cexterr);
|
|
|
|
device_printf(dev, "RX overruns = %ld\n", sc->rx_overruns);
|
|
|
|
device_printf(dev, "watchdog timeouts = %ld\n", sc->watchdog_events);
|
|
|
|
|
|
|
|
device_printf(dev, "XON Rcvd = %lld\n", (long long)sc->stats.xonrxc);
|
|
|
|
device_printf(dev, "XON Xmtd = %lld\n", (long long)sc->stats.xontxc);
|
|
|
|
device_printf(dev, "XOFF Rcvd = %lld\n", (long long)sc->stats.xoffrxc);
|
|
|
|
device_printf(dev, "XOFF Xmtd = %lld\n", (long long)sc->stats.xofftxc);
|
|
|
|
|
|
|
|
device_printf(dev, "Good Packets Rcvd = %lld\n",
|
|
|
|
(long long)sc->stats.gprc);
|
|
|
|
device_printf(dev, "Good Packets Xmtd = %lld\n",
|
|
|
|
(long long)sc->stats.gptc);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
2003-06-05 17:51:38 +00:00
|
|
|
static int
|
|
|
|
em_sysctl_debug_info(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc;
|
|
|
|
int error;
|
|
|
|
int result;
|
2003-06-05 17:51:38 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
result = -1;
|
|
|
|
error = sysctl_handle_int(oidp, &result, 0, req);
|
2003-06-05 17:51:38 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (error || !req->newptr)
|
|
|
|
return (error);
|
2003-06-05 17:51:38 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (result == 1) {
|
|
|
|
sc = (struct em_softc *)arg1;
|
|
|
|
em_print_debug_info(sc);
|
|
|
|
}
|
2003-06-05 17:51:38 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
return (error);
|
2003-06-05 17:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
em_sysctl_stats(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc;
|
|
|
|
int error;
|
|
|
|
int result;
|
2003-06-05 17:51:38 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
result = -1;
|
|
|
|
error = sysctl_handle_int(oidp, &result, 0, req);
|
2003-06-05 17:51:38 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (error || !req->newptr)
|
|
|
|
return (error);
|
2003-06-05 17:51:38 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
if (result == 1) {
|
|
|
|
sc = (struct em_softc *)arg1;
|
|
|
|
em_print_hw_stats(sc);
|
|
|
|
}
|
2003-06-05 17:51:38 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
return (error);
|
2003-06-05 17:51:38 +00:00
|
|
|
}
|
2003-08-01 17:33:59 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
em_sysctl_int_delay(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct em_int_delay_info *info;
|
2006-02-15 08:39:50 +00:00
|
|
|
struct em_softc *sc;
|
|
|
|
uint32_t regval;
|
2003-08-01 17:33:59 +00:00
|
|
|
int error;
|
|
|
|
int usecs;
|
|
|
|
int ticks;
|
|
|
|
|
|
|
|
info = (struct em_int_delay_info *)arg1;
|
|
|
|
usecs = info->value;
|
|
|
|
error = sysctl_handle_int(oidp, &usecs, 0, req);
|
|
|
|
if (error != 0 || req->newptr == NULL)
|
2006-02-15 08:39:50 +00:00
|
|
|
return (error);
|
2003-08-01 17:33:59 +00:00
|
|
|
if (usecs < 0 || usecs > E1000_TICKS_TO_USECS(65535))
|
2006-02-15 08:39:50 +00:00
|
|
|
return (EINVAL);
|
2003-08-01 17:33:59 +00:00
|
|
|
info->value = usecs;
|
|
|
|
ticks = E1000_USECS_TO_TICKS(usecs);
|
2005-10-20 09:55:49 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
sc = info->sc;
|
2003-08-01 17:33:59 +00:00
|
|
|
|
2006-02-15 08:39:50 +00:00
|
|
|
EM_LOCK(sc);
|
|
|
|
regval = E1000_READ_OFFSET(&sc->hw, info->offset);
|
2003-08-01 17:33:59 +00:00
|
|
|
regval = (regval & ~0xffff) | (ticks & 0xffff);
|
|
|
|
/* Handle a few special cases. */
|
|
|
|
switch (info->offset) {
|
|
|
|
case E1000_RDTR:
|
|
|
|
case E1000_82542_RDTR:
|
|
|
|
regval |= E1000_RDT_FPDB;
|
|
|
|
break;
|
|
|
|
case E1000_TIDV:
|
|
|
|
case E1000_82542_TIDV:
|
|
|
|
if (ticks == 0) {
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->txd_cmd &= ~E1000_TXD_CMD_IDE;
|
2003-08-01 17:33:59 +00:00
|
|
|
/* Don't write 0 into the TIDV register. */
|
|
|
|
regval++;
|
|
|
|
} else
|
2006-02-15 08:39:50 +00:00
|
|
|
sc->txd_cmd |= E1000_TXD_CMD_IDE;
|
2003-08-01 17:33:59 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-02-15 08:39:50 +00:00
|
|
|
E1000_WRITE_OFFSET(&sc->hw, info->offset, regval);
|
|
|
|
EM_UNLOCK(sc);
|
|
|
|
return (0);
|
2003-08-01 17:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_add_int_delay_sysctl(struct em_softc *sc, const char *name,
|
|
|
|
const char *description, struct em_int_delay_info *info,
|
|
|
|
int offset, int value)
|
2003-08-01 17:33:59 +00:00
|
|
|
{
|
2006-02-15 08:39:50 +00:00
|
|
|
info->sc = sc;
|
2003-08-01 17:33:59 +00:00
|
|
|
info->offset = offset;
|
|
|
|
info->value = value;
|
2006-02-15 08:39:50 +00:00
|
|
|
SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->dev),
|
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)),
|
2003-08-01 17:33:59 +00:00
|
|
|
OID_AUTO, name, CTLTYPE_INT|CTLFLAG_RW,
|
|
|
|
info, 0, em_sysctl_int_delay, "I", description);
|
|
|
|
}
|
2006-01-11 00:30:25 +00:00
|
|
|
|
2006-06-06 08:03:49 +00:00
|
|
|
#ifndef DEVICE_POLLING
|
2006-01-11 00:30:25 +00:00
|
|
|
static void
|
2006-02-15 08:39:50 +00:00
|
|
|
em_add_int_process_limit(struct em_softc *sc, const char *name,
|
|
|
|
const char *description, int *limit, int value)
|
2006-01-11 00:30:25 +00:00
|
|
|
{
|
|
|
|
*limit = value;
|
2006-02-15 08:39:50 +00:00
|
|
|
SYSCTL_ADD_INT(device_get_sysctl_ctx(sc->dev),
|
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)),
|
2006-01-11 00:30:25 +00:00
|
|
|
OID_AUTO, name, CTLTYPE_INT|CTLFLAG_RW, limit, value, description);
|
|
|
|
}
|
|
|
|
#endif
|