2001-12-02 07:37:17 +00:00
|
|
|
/**************************************************************************
|
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
Copyright (c) 2001-2003, 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$*/
|
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
#include <dev/em/if_em.h>
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Set this to one to display debug statistics
|
|
|
|
*********************************************************************/
|
|
|
|
int em_display_debug_stats = 0;
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Linked list of board private structures for all NICs found
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
struct adapter *em_adapter_list = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Driver version
|
|
|
|
*********************************************************************/
|
|
|
|
|
2004-09-01 23:22:41 +00:00
|
|
|
char em_driver_version[] = "1.7.35";
|
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[] =
|
|
|
|
{
|
2002-12-23 19:11:23 +00:00
|
|
|
/* Intel(R) PRO/1000 Network Connection */
|
|
|
|
{ 0x8086, 0x1000, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x1001, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x1004, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x1008, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x1009, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x100C, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x100D, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x100E, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x100F, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x1010, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x1011, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x1012, PCI_ANY_ID, PCI_ANY_ID, 0},
|
2003-03-21 21:47:31 +00:00
|
|
|
{ 0x8086, 0x1013, PCI_ANY_ID, PCI_ANY_ID, 0},
|
2002-12-23 19:11:23 +00:00
|
|
|
{ 0x8086, 0x1015, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x1016, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x1017, PCI_ANY_ID, PCI_ANY_ID, 0},
|
2003-03-21 21:47:31 +00:00
|
|
|
{ 0x8086, 0x1018, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x1019, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x101A, PCI_ANY_ID, PCI_ANY_ID, 0},
|
2003-06-05 17:51:38 +00:00
|
|
|
{ 0x8086, 0x101D, PCI_ANY_ID, PCI_ANY_ID, 0},
|
2003-03-21 21:47:31 +00:00
|
|
|
{ 0x8086, 0x101E, PCI_ANY_ID, PCI_ANY_ID, 0},
|
2003-08-27 21:52:37 +00:00
|
|
|
{ 0x8086, 0x1026, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x1027, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x1028, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x1075, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x1076, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x1077, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x1078, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x1079, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x107A, PCI_ANY_ID, PCI_ANY_ID, 0},
|
|
|
|
{ 0x8086, 0x107B, PCI_ANY_ID, PCI_ANY_ID, 0},
|
2004-09-01 23:22:41 +00:00
|
|
|
{ 0x8086, 0x107C, PCI_ANY_ID, PCI_ANY_ID, 0},
|
2002-12-23 19:11:23 +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
|
|
|
};
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Function prototypes
|
|
|
|
*********************************************************************/
|
2002-04-06 00:36:53 +00:00
|
|
|
static int em_probe(device_t);
|
|
|
|
static int em_attach(device_t);
|
|
|
|
static int em_detach(device_t);
|
|
|
|
static int em_shutdown(device_t);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_intr(void *);
|
|
|
|
static void em_start(struct ifnet *);
|
2003-03-21 21:47:31 +00:00
|
|
|
static int em_ioctl(struct ifnet *, u_long, caddr_t);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_watchdog(struct ifnet *);
|
|
|
|
static void em_init(void *);
|
2003-09-23 00:18:25 +00:00
|
|
|
static void em_init_locked(struct adapter *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_stop(void *);
|
|
|
|
static void em_media_status(struct ifnet *, struct ifmediareq *);
|
2002-04-06 00:36:53 +00:00
|
|
|
static int em_media_change(struct ifnet *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_identify_hardware(struct adapter *);
|
2002-04-06 00:36:53 +00:00
|
|
|
static int em_allocate_pci_resources(struct adapter *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_free_pci_resources(struct adapter *);
|
|
|
|
static void em_local_timer(void *);
|
2002-04-06 00:36:53 +00:00
|
|
|
static int em_hardware_init(struct adapter *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_setup_interface(device_t, struct adapter *);
|
2002-04-06 00:36:53 +00:00
|
|
|
static int em_setup_transmit_structures(struct adapter *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_initialize_transmit_unit(struct adapter *);
|
2002-04-06 00:36:53 +00:00
|
|
|
static int em_setup_receive_structures(struct adapter *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_initialize_receive_unit(struct adapter *);
|
2002-04-06 00:36:53 +00:00
|
|
|
static void em_enable_intr(struct adapter *);
|
|
|
|
static void em_disable_intr(struct adapter *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_free_transmit_structures(struct adapter *);
|
|
|
|
static void em_free_receive_structures(struct adapter *);
|
|
|
|
static void em_update_stats_counters(struct adapter *);
|
|
|
|
static void em_clean_transmit_interrupts(struct adapter *);
|
2002-04-06 00:36:53 +00:00
|
|
|
static int em_allocate_receive_structures(struct adapter *);
|
|
|
|
static int em_allocate_transmit_structures(struct adapter *);
|
2002-11-25 19:56:16 +00:00
|
|
|
static void em_process_receive_interrupts(struct adapter *, int);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_receive_checksum(struct adapter *,
|
2003-03-21 21:47:31 +00:00
|
|
|
struct em_rx_desc *,
|
2002-12-23 19:11:23 +00:00
|
|
|
struct mbuf *);
|
2002-08-26 18:59:16 +00:00
|
|
|
static void em_transmit_checksum_setup(struct adapter *,
|
2002-12-23 19:11:23 +00:00
|
|
|
struct mbuf *,
|
|
|
|
u_int32_t *,
|
|
|
|
u_int32_t *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void em_set_promisc(struct adapter *);
|
|
|
|
static void em_disable_promisc(struct adapter *);
|
|
|
|
static void em_set_multi(struct adapter *);
|
|
|
|
static void em_print_hw_stats(struct adapter *);
|
|
|
|
static void em_print_link_status(struct adapter *);
|
2002-12-23 19:11:23 +00:00
|
|
|
static int em_get_buf(int i, struct adapter *,
|
2002-11-08 18:14:17 +00:00
|
|
|
struct mbuf *);
|
2003-03-21 21:47:31 +00:00
|
|
|
static void em_enable_vlans(struct adapter *);
|
|
|
|
static int em_encap(struct adapter *, struct mbuf *);
|
|
|
|
static void em_smartspeed(struct adapter *);
|
|
|
|
static int em_82547_fifo_workaround(struct adapter *, int);
|
|
|
|
static void em_82547_update_fifo_head(struct adapter *, int);
|
|
|
|
static int em_82547_tx_fifo_reset(struct adapter *);
|
|
|
|
static void em_82547_move_tail(void *arg);
|
2003-10-15 05:34:41 +00:00
|
|
|
static void em_82547_move_tail_locked(struct adapter *);
|
2003-05-02 21:17:08 +00:00
|
|
|
static int em_dma_malloc(struct adapter *, bus_size_t,
|
|
|
|
struct em_dma_alloc *, int);
|
|
|
|
static void em_dma_free(struct adapter *, struct em_dma_alloc *);
|
2003-06-05 17:51:38 +00:00
|
|
|
static void em_print_debug_info(struct adapter *);
|
|
|
|
static int em_is_valid_ether_addr(u_int8_t *);
|
|
|
|
static int em_sysctl_stats(SYSCTL_HANDLER_ARGS);
|
|
|
|
static int em_sysctl_debug_info(SYSCTL_HANDLER_ARGS);
|
2003-08-27 21:52:37 +00:00
|
|
|
static u_int32_t em_fill_descriptors (u_int64_t address,
|
|
|
|
u_int32_t length,
|
|
|
|
PDESC_ARRAY desc_array);
|
2003-08-01 17:33:59 +00:00
|
|
|
static int em_sysctl_int_delay(SYSCTL_HANDLER_ARGS);
|
|
|
|
static void em_add_int_delay_sysctl(struct adapter *, const char *,
|
|
|
|
const char *, struct em_int_delay_info *,
|
|
|
|
int, int);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* FreeBSD Device Interface Entry Points
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
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),
|
|
|
|
{0, 0}
|
2001-12-02 07:37:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t em_driver = {
|
2002-06-03 22:30:51 +00:00
|
|
|
"em", em_methods, sizeof(struct adapter ),
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* return 0 on success, positive on failure
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
static int
|
|
|
|
em_probe(device_t dev)
|
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
em_vendor_info_t *ent;
|
|
|
|
|
|
|
|
u_int16_t pci_vendor_id = 0;
|
|
|
|
u_int16_t pci_device_id = 0;
|
|
|
|
u_int16_t pci_subvendor_id = 0;
|
|
|
|
u_int16_t pci_subdevice_id = 0;
|
|
|
|
char adapter_name[60];
|
|
|
|
|
|
|
|
INIT_DEBUGOUT("em_probe: begin");
|
|
|
|
|
|
|
|
pci_vendor_id = pci_get_vendor(dev);
|
|
|
|
if (pci_vendor_id != EM_VENDOR_ID)
|
|
|
|
return(ENXIO);
|
|
|
|
|
|
|
|
pci_device_id = pci_get_device(dev);
|
|
|
|
pci_subvendor_id = pci_get_subvendor(dev);
|
|
|
|
pci_subdevice_id = pci_get_subdevice(dev);
|
|
|
|
|
|
|
|
ent = em_vendor_info_array;
|
|
|
|
while (ent->vendor_id != 0) {
|
|
|
|
if ((pci_vendor_id == ent->vendor_id) &&
|
|
|
|
(pci_device_id == ent->device_id) &&
|
|
|
|
|
|
|
|
((pci_subvendor_id == ent->subvendor_id) ||
|
|
|
|
(ent->subvendor_id == PCI_ANY_ID)) &&
|
|
|
|
|
|
|
|
((pci_subdevice_id == ent->subdevice_id) ||
|
|
|
|
(ent->subdevice_id == PCI_ANY_ID))) {
|
|
|
|
sprintf(adapter_name, "%s, Version - %s",
|
|
|
|
em_strings[ent->index],
|
|
|
|
em_driver_version);
|
|
|
|
device_set_desc_copy(dev, adapter_name);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
ent++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(ENXIO);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Device initialization routine
|
|
|
|
*
|
|
|
|
* The attach entry point is called when the driver is being loaded.
|
|
|
|
* This routine identifies the type of hardware, allocates all resources
|
|
|
|
* and initializes the hardware.
|
|
|
|
*
|
|
|
|
* return 0 on success, positive on failure
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
static int
|
|
|
|
em_attach(device_t dev)
|
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
struct adapter * adapter;
|
|
|
|
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");
|
|
|
|
|
|
|
|
/* Allocate, clear, and link in our adapter structure */
|
|
|
|
if (!(adapter = device_get_softc(dev))) {
|
|
|
|
printf("em: adapter structure allocation failed\n");
|
|
|
|
return(ENOMEM);
|
|
|
|
}
|
|
|
|
bzero(adapter, sizeof(struct adapter ));
|
|
|
|
adapter->dev = dev;
|
|
|
|
adapter->osdep.dev = dev;
|
|
|
|
adapter->unit = device_get_unit(dev);
|
2003-10-10 23:14:21 +00:00
|
|
|
EM_LOCK_INIT(adapter, device_get_nameunit(dev));
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
if (em_adapter_list != NULL)
|
|
|
|
em_adapter_list->prev = adapter;
|
|
|
|
adapter->next = em_adapter_list;
|
|
|
|
em_adapter_list = adapter;
|
|
|
|
|
2003-06-05 17:51:38 +00:00
|
|
|
/* SYSCTL stuff */
|
|
|
|
sysctl_ctx_init(&adapter->sysctl_ctx);
|
|
|
|
adapter->sysctl_tree = SYSCTL_ADD_NODE(&adapter->sysctl_ctx,
|
|
|
|
SYSCTL_STATIC_CHILDREN(_hw),
|
|
|
|
OID_AUTO,
|
|
|
|
device_get_nameunit(dev),
|
|
|
|
CTLFLAG_RD,
|
|
|
|
0, "");
|
|
|
|
if (adapter->sysctl_tree == NULL) {
|
|
|
|
error = EIO;
|
|
|
|
goto err_sysctl;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCTL_ADD_PROC(&adapter->sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(adapter->sysctl_tree),
|
|
|
|
OID_AUTO, "debug_info", CTLTYPE_INT|CTLFLAG_RW,
|
|
|
|
(void *)adapter, 0,
|
|
|
|
em_sysctl_debug_info, "I", "Debug Information");
|
|
|
|
|
|
|
|
SYSCTL_ADD_PROC(&adapter->sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(adapter->sysctl_tree),
|
|
|
|
OID_AUTO, "stats", CTLTYPE_INT|CTLFLAG_RW,
|
|
|
|
(void *)adapter, 0,
|
|
|
|
em_sysctl_stats, "I", "Statistics");
|
|
|
|
|
2003-09-23 00:18:25 +00:00
|
|
|
callout_init(&adapter->timer, CALLOUT_MPSAFE);
|
|
|
|
callout_init(&adapter->tx_fifo_timer, CALLOUT_MPSAFE);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Determine hardware revision */
|
|
|
|
em_identify_hardware(adapter);
|
2003-08-01 17:33:59 +00:00
|
|
|
|
|
|
|
/* Set up some sysctls for the tunable interrupt delays */
|
|
|
|
em_add_int_delay_sysctl(adapter, "rx_int_delay",
|
|
|
|
"receive interrupt delay in usecs", &adapter->rx_int_delay,
|
|
|
|
E1000_REG_OFFSET(&adapter->hw, RDTR), em_rx_int_delay_dflt);
|
|
|
|
em_add_int_delay_sysctl(adapter, "tx_int_delay",
|
|
|
|
"transmit interrupt delay in usecs", &adapter->tx_int_delay,
|
|
|
|
E1000_REG_OFFSET(&adapter->hw, TIDV), em_tx_int_delay_dflt);
|
|
|
|
if (adapter->hw.mac_type >= em_82540) {
|
|
|
|
em_add_int_delay_sysctl(adapter, "rx_abs_int_delay",
|
|
|
|
"receive interrupt delay limit in usecs",
|
|
|
|
&adapter->rx_abs_int_delay,
|
|
|
|
E1000_REG_OFFSET(&adapter->hw, RADV),
|
|
|
|
em_rx_abs_int_delay_dflt);
|
|
|
|
em_add_int_delay_sysctl(adapter, "tx_abs_int_delay",
|
|
|
|
"transmit interrupt delay limit in usecs",
|
|
|
|
&adapter->tx_abs_int_delay,
|
|
|
|
E1000_REG_OFFSET(&adapter->hw, TADV),
|
|
|
|
em_tx_abs_int_delay_dflt);
|
|
|
|
}
|
2002-12-23 19:11:23 +00:00
|
|
|
|
|
|
|
/* Parameters (to be read from user) */
|
|
|
|
adapter->num_tx_desc = EM_MAX_TXD;
|
|
|
|
adapter->num_rx_desc = EM_MAX_RXD;
|
|
|
|
adapter->hw.autoneg = DO_AUTO_NEG;
|
|
|
|
adapter->hw.wait_autoneg_complete = WAIT_FOR_AUTO_NEG_DEFAULT;
|
|
|
|
adapter->hw.autoneg_advertised = AUTONEG_ADV_DEFAULT;
|
|
|
|
adapter->hw.tbi_compatibility_en = TRUE;
|
|
|
|
adapter->rx_buffer_len = EM_RXBUFFER_2048;
|
|
|
|
|
2003-06-05 17:51:38 +00:00
|
|
|
/*
|
|
|
|
* These parameters control the automatic generation(Tx) and
|
|
|
|
* response(Rx) to Ethernet PAUSE frames.
|
|
|
|
*/
|
2002-12-23 19:11:23 +00:00
|
|
|
adapter->hw.fc_high_water = FC_DEFAULT_HI_THRESH;
|
|
|
|
adapter->hw.fc_low_water = FC_DEFAULT_LO_THRESH;
|
|
|
|
adapter->hw.fc_pause_time = FC_DEFAULT_TX_TIMER;
|
|
|
|
adapter->hw.fc_send_xon = TRUE;
|
|
|
|
adapter->hw.fc = em_fc_full;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
adapter->hw.phy_init_script = 1;
|
2003-08-27 21:52:37 +00:00
|
|
|
adapter->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
|
|
|
|
adapter->hw.master_slave = em_ms_hw_default;
|
|
|
|
#else
|
|
|
|
adapter->hw.master_slave = EM_MASTER_SLAVE;
|
|
|
|
#endif
|
2003-03-21 21:47:31 +00:00
|
|
|
/*
|
|
|
|
* Set the max frame size assuming standard ethernet
|
|
|
|
* sized frames
|
|
|
|
*/
|
2002-06-03 22:30:51 +00:00
|
|
|
adapter->hw.max_frame_size =
|
2002-12-23 19:11:23 +00:00
|
|
|
ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
adapter->hw.min_frame_size =
|
2002-12-23 19:11:23 +00:00
|
|
|
MINIMUM_ETHERNET_PACKET_SIZE + ETHER_CRC_LEN;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
/*
|
|
|
|
* This controls when hardware reports transmit completion
|
|
|
|
* status.
|
|
|
|
*/
|
|
|
|
adapter->hw.report_tx_early = 1;
|
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
if (em_allocate_pci_resources(adapter)) {
|
|
|
|
printf("em%d: Allocation of PCI resources failed\n",
|
|
|
|
adapter->unit);
|
2003-06-05 17:51:38 +00:00
|
|
|
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 */
|
|
|
|
em_init_eeprom_params(&adapter->hw);
|
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
tsize = EM_ROUNDUP(adapter->num_tx_desc *
|
|
|
|
sizeof(struct em_tx_desc), 4096);
|
|
|
|
|
|
|
|
/* Allocate Transmit Descriptor ring */
|
2003-05-02 21:17:08 +00:00
|
|
|
if (em_dma_malloc(adapter, tsize, &adapter->txdma, BUS_DMA_NOWAIT)) {
|
|
|
|
printf("em%d: Unable to allocate tx_desc memory\n",
|
|
|
|
adapter->unit);
|
2003-06-05 17:51:38 +00:00
|
|
|
error = ENOMEM;
|
|
|
|
goto err_tx_desc;
|
2003-05-02 21:17:08 +00:00
|
|
|
}
|
|
|
|
adapter->tx_desc_base = (struct em_tx_desc *) adapter->txdma.dma_vaddr;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
rsize = EM_ROUNDUP(adapter->num_rx_desc *
|
|
|
|
sizeof(struct em_rx_desc), 4096);
|
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
/* Allocate Receive Descriptor ring */
|
|
|
|
if (em_dma_malloc(adapter, rsize, &adapter->rxdma, BUS_DMA_NOWAIT)) {
|
|
|
|
printf("em%d: Unable to allocate rx_desc memory\n",
|
|
|
|
adapter->unit);
|
2003-06-05 17:51:38 +00:00
|
|
|
error = ENOMEM;
|
|
|
|
goto err_rx_desc;
|
2003-05-02 21:17:08 +00:00
|
|
|
}
|
|
|
|
adapter->rx_desc_base = (struct em_rx_desc *) adapter->rxdma.dma_vaddr;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Initialize the hardware */
|
|
|
|
if (em_hardware_init(adapter)) {
|
|
|
|
printf("em%d: Unable to initialize the hardware\n",
|
|
|
|
adapter->unit);
|
2003-06-05 17:51:38 +00:00
|
|
|
error = EIO;
|
|
|
|
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 */
|
|
|
|
if (em_read_mac_addr(&adapter->hw) < 0) {
|
|
|
|
printf("em%d: EEPROM read error while reading mac address\n",
|
|
|
|
adapter->unit);
|
2003-06-05 17:51:38 +00:00
|
|
|
error = EIO;
|
|
|
|
goto err_mac_addr;
|
2002-07-16 16:55:03 +00:00
|
|
|
}
|
|
|
|
|
2003-06-05 17:51:38 +00:00
|
|
|
if (!em_is_valid_ether_addr(adapter->hw.mac_addr)) {
|
|
|
|
printf("em%d: Invalid mac address\n", adapter->unit);
|
|
|
|
error = EIO;
|
|
|
|
goto err_mac_addr;
|
|
|
|
}
|
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
bcopy(adapter->hw.mac_addr, adapter->interface_data.ac_enaddr,
|
|
|
|
ETHER_ADDR_LEN);
|
2002-07-16 16:55:03 +00:00
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
/* Setup OS specific network interface */
|
|
|
|
em_setup_interface(dev, adapter);
|
|
|
|
|
|
|
|
/* Initialize statistics */
|
|
|
|
em_clear_hw_cntrs(&adapter->hw);
|
|
|
|
em_update_stats_counters(adapter);
|
|
|
|
adapter->hw.get_link_status = 1;
|
|
|
|
em_check_for_link(&adapter->hw);
|
|
|
|
|
|
|
|
/* Print the link status */
|
|
|
|
if (adapter->link_active == 1) {
|
|
|
|
em_get_speed_and_duplex(&adapter->hw, &adapter->link_speed,
|
|
|
|
&adapter->link_duplex);
|
|
|
|
printf("em%d: Speed:%d Mbps Duplex:%s\n",
|
|
|
|
adapter->unit,
|
|
|
|
adapter->link_speed,
|
|
|
|
adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half");
|
|
|
|
} else
|
|
|
|
printf("em%d: Speed:N/A Duplex:N/A\n", adapter->unit);
|
|
|
|
|
2003-08-27 21:52:37 +00:00
|
|
|
/* Identify 82544 on PCIX */
|
|
|
|
em_get_bus_info(&adapter->hw);
|
|
|
|
if(adapter->hw.bus_type == em_bus_type_pcix &&
|
|
|
|
adapter->hw.mac_type == em_82544) {
|
|
|
|
adapter->pcix_82544 = TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
adapter->pcix_82544 = FALSE;
|
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
INIT_DEBUGOUT("em_attach: end");
|
|
|
|
return(0);
|
2003-06-05 17:51:38 +00:00
|
|
|
|
|
|
|
err_mac_addr:
|
|
|
|
err_hw_init:
|
|
|
|
em_dma_free(adapter, &adapter->rxdma);
|
|
|
|
err_rx_desc:
|
|
|
|
em_dma_free(adapter, &adapter->txdma);
|
|
|
|
err_tx_desc:
|
|
|
|
err_pci:
|
|
|
|
em_free_pci_resources(adapter);
|
|
|
|
sysctl_ctx_free(&adapter->sysctl_ctx);
|
|
|
|
err_sysctl:
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* return 0 on success, positive on failure
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
static int
|
|
|
|
em_detach(device_t dev)
|
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
struct adapter * adapter = device_get_softc(dev);
|
|
|
|
struct ifnet *ifp = &adapter->interface_data.ac_if;
|
|
|
|
|
|
|
|
INIT_DEBUGOUT("em_detach: begin");
|
|
|
|
|
2003-09-23 00:18:25 +00:00
|
|
|
EM_LOCK(adapter);
|
2003-11-14 18:02:25 +00:00
|
|
|
adapter->in_detach = 1;
|
2002-06-03 22:30:51 +00:00
|
|
|
em_stop(adapter);
|
|
|
|
em_phy_hw_reset(&adapter->hw);
|
2003-09-23 00:18:25 +00:00
|
|
|
EM_UNLOCK(adapter);
|
2002-12-23 19:11:23 +00:00
|
|
|
#if __FreeBSD_version < 500000
|
2003-03-21 21:47:31 +00:00
|
|
|
ether_ifdetach(&adapter->interface_data.ac_if, ETHER_BPF_SUPPORTED);
|
2002-12-23 19:11:23 +00:00
|
|
|
#else
|
2003-03-21 21:47:31 +00:00
|
|
|
ether_ifdetach(&adapter->interface_data.ac_if);
|
2002-12-23 19:11:23 +00:00
|
|
|
#endif
|
2002-06-03 22:30:51 +00:00
|
|
|
em_free_pci_resources(adapter);
|
2004-02-10 21:31:09 +00:00
|
|
|
bus_generic_detach(dev);
|
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
/* Free Transmit Descriptor ring */
|
2003-05-02 21:17:08 +00:00
|
|
|
if (adapter->tx_desc_base) {
|
|
|
|
em_dma_free(adapter, &adapter->txdma);
|
|
|
|
adapter->tx_desc_base = NULL;
|
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
/* Free Receive Descriptor ring */
|
|
|
|
if (adapter->rx_desc_base) {
|
|
|
|
em_dma_free(adapter, &adapter->rxdma);
|
|
|
|
adapter->rx_desc_base = NULL;
|
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-08-27 21:52:37 +00:00
|
|
|
/* Free the sysctl tree */
|
|
|
|
sysctl_ctx_free(&adapter->sysctl_ctx);
|
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
/* Remove from the adapter list */
|
|
|
|
if (em_adapter_list == adapter)
|
|
|
|
em_adapter_list = adapter->next;
|
|
|
|
if (adapter->next != NULL)
|
|
|
|
adapter->next->prev = adapter->prev;
|
|
|
|
if (adapter->prev != NULL)
|
|
|
|
adapter->prev->next = adapter->next;
|
|
|
|
|
2003-10-10 23:14:21 +00:00
|
|
|
EM_LOCK_DESTROY(adapter);
|
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
|
|
|
|
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
|
|
|
*
|
|
|
|
**********************************************************************/
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
static int
|
|
|
|
em_shutdown(device_t dev)
|
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
struct adapter *adapter = device_get_softc(dev);
|
2003-09-23 00:18:25 +00:00
|
|
|
EM_LOCK(adapter);
|
2002-06-03 22:30:51 +00:00
|
|
|
em_stop(adapter);
|
2003-09-23 00:18:25 +00:00
|
|
|
EM_UNLOCK(adapter);
|
2002-06-03 22:30:51 +00:00
|
|
|
return(0);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2002-12-23 19:11:23 +00:00
|
|
|
struct mbuf *m_head;
|
|
|
|
struct adapter *adapter = ifp->if_softc;
|
2003-03-21 21:47:31 +00:00
|
|
|
|
2003-09-23 00:18:25 +00:00
|
|
|
mtx_assert(&adapter->mtx, MA_OWNED);
|
|
|
|
|
2002-12-23 19:11:23 +00:00
|
|
|
if (!adapter->link_active)
|
|
|
|
return;
|
|
|
|
|
2004-07-02 12:16:02 +00:00
|
|
|
while (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) {
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2004-07-02 12:16:02 +00:00
|
|
|
IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head);
|
2002-12-23 19:11:23 +00:00
|
|
|
|
|
|
|
if (m_head == NULL) break;
|
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
if (em_encap(adapter, m_head)) {
|
|
|
|
ifp->if_flags |= IFF_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;
|
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-12-23 19:11:23 +00:00
|
|
|
#if __FreeBSD_version < 500000
|
|
|
|
if (ifp->if_bpf)
|
|
|
|
bpf_mtap(ifp, m_head);
|
|
|
|
#else
|
2002-11-14 23:54:55 +00:00
|
|
|
BPF_MTAP(ifp, m_head);
|
2002-12-23 19:11:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Set timeout in case hardware has problems transmitting */
|
|
|
|
ifp->if_timer = EM_TX_TIMEOUT;
|
|
|
|
|
|
|
|
}
|
|
|
|
return;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
2003-09-23 00:18:25 +00:00
|
|
|
static void
|
|
|
|
em_start(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct adapter *adapter = ifp->if_softc;
|
|
|
|
|
|
|
|
EM_LOCK(adapter);
|
|
|
|
em_start_locked(ifp);
|
|
|
|
EM_UNLOCK(adapter);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2004-06-04 16:57:18 +00:00
|
|
|
int mask, reinit, error = 0;
|
2002-06-03 22:30:51 +00:00
|
|
|
struct ifreq *ifr = (struct ifreq *) data;
|
|
|
|
struct adapter * adapter = ifp->if_softc;
|
|
|
|
|
2003-11-14 18:02:25 +00:00
|
|
|
if (adapter->in_detach) return(error);
|
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
switch (command) {
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
case SIOCGIFADDR:
|
|
|
|
IOCTL_DEBUGOUT("ioctl rcv'd: SIOCxIFADDR (Get/Set Interface Addr)");
|
|
|
|
ether_ioctl(ifp, command, data);
|
|
|
|
break;
|
|
|
|
case SIOCSIFMTU:
|
|
|
|
IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFMTU (Set Interface MTU)");
|
|
|
|
if (ifr->ifr_mtu > MAX_JUMBO_FRAME_SIZE - ETHER_HDR_LEN) {
|
|
|
|
error = EINVAL;
|
|
|
|
} else {
|
2003-09-23 00:18:25 +00:00
|
|
|
EM_LOCK(adapter);
|
2002-06-03 22:30:51 +00:00
|
|
|
ifp->if_mtu = ifr->ifr_mtu;
|
|
|
|
adapter->hw.max_frame_size =
|
|
|
|
ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
|
2003-09-23 00:18:25 +00:00
|
|
|
em_init_locked(adapter);
|
|
|
|
EM_UNLOCK(adapter);
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
break;
|
2003-03-21 21:47:31 +00:00
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFFLAGS (Set Interface Flags)");
|
2003-09-23 00:18:25 +00:00
|
|
|
EM_LOCK(adapter);
|
2003-03-21 21:47:31 +00:00
|
|
|
if (ifp->if_flags & IFF_UP) {
|
2003-08-27 21:52:37 +00:00
|
|
|
if (!(ifp->if_flags & IFF_RUNNING)) {
|
2003-09-23 00:18:25 +00:00
|
|
|
em_init_locked(adapter);
|
2003-08-27 21:52:37 +00:00
|
|
|
}
|
2003-03-21 21:47:31 +00:00
|
|
|
|
|
|
|
em_disable_promisc(adapter);
|
|
|
|
em_set_promisc(adapter);
|
|
|
|
} else {
|
|
|
|
if (ifp->if_flags & IFF_RUNNING) {
|
|
|
|
em_stop(adapter);
|
|
|
|
}
|
|
|
|
}
|
2003-09-23 00:18:25 +00:00
|
|
|
EM_UNLOCK(adapter);
|
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");
|
|
|
|
if (ifp->if_flags & IFF_RUNNING) {
|
2003-09-23 00:18:25 +00:00
|
|
|
EM_LOCK(adapter);
|
2002-06-03 22:30:51 +00:00
|
|
|
em_disable_intr(adapter);
|
|
|
|
em_set_multi(adapter);
|
2003-06-05 17:51:38 +00:00
|
|
|
if (adapter->hw.mac_type == em_82542_rev2_0) {
|
2002-06-03 22:30:51 +00:00
|
|
|
em_initialize_receive_unit(adapter);
|
2003-06-05 17:51:38 +00:00
|
|
|
}
|
|
|
|
#ifdef DEVICE_POLLING
|
2003-12-02 22:13:08 +00:00
|
|
|
if (!(ifp->if_flags & IFF_POLLING))
|
2003-06-05 17:51:38 +00:00
|
|
|
#endif
|
|
|
|
em_enable_intr(adapter);
|
2003-09-23 00:18:25 +00:00
|
|
|
EM_UNLOCK(adapter);
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
IOCTL_DEBUGOUT("ioctl rcv'd: SIOCxIFMEDIA (Get/Set Interface Media)");
|
|
|
|
error = ifmedia_ioctl(ifp, ifr, &adapter->media, command);
|
|
|
|
break;
|
|
|
|
case SIOCSIFCAP:
|
|
|
|
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;
|
2004-04-11 21:01:12 +00:00
|
|
|
if (mask & IFCAP_POLLING)
|
|
|
|
ifp->if_capenable ^= IFCAP_POLLING;
|
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;
|
|
|
|
}
|
|
|
|
if (reinit && (ifp->if_flags & IFF_RUNNING))
|
|
|
|
em_init(adapter);
|
2002-06-03 22:30:51 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-09-01 23:22:41 +00:00
|
|
|
IOCTL_DEBUGOUT1("ioctl received: UNKNOWN (0x%x)", (int)command);
|
2002-06-03 22:30:51 +00:00
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
struct adapter * adapter;
|
|
|
|
adapter = ifp->if_softc;
|
|
|
|
|
|
|
|
/* If we are in this routine because of pause frames, then
|
|
|
|
* don't reset the hardware.
|
|
|
|
*/
|
|
|
|
if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_TXOFF) {
|
|
|
|
ifp->if_timer = EM_TX_TIMEOUT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-10 21:31:09 +00:00
|
|
|
if (em_check_for_link(&adapter->hw))
|
|
|
|
printf("em%d: watchdog timeout -- resetting\n", adapter->unit);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
|
|
|
|
|
|
|
em_init(adapter);
|
|
|
|
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
return;
|
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
|
|
|
|
* by the driver as a hw/sw initialization routine to get to a
|
|
|
|
* consistent state.
|
|
|
|
*
|
|
|
|
* return 0 on success, positive on failure
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
static void
|
2003-09-23 00:18:25 +00:00
|
|
|
em_init_locked(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
|
2004-09-01 23:22:41 +00:00
|
|
|
uint32_t pba;
|
2004-06-04 16:57:18 +00:00
|
|
|
ifp = &adapter->interface_data.ac_if;
|
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
INIT_DEBUGOUT("em_init: begin");
|
|
|
|
|
2003-09-23 00:18:25 +00:00
|
|
|
mtx_assert(&adapter->mtx, MA_OWNED);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
em_stop(adapter);
|
|
|
|
|
2004-09-01 23:22:41 +00:00
|
|
|
/* Packet Buffer Allocation (PBA)
|
|
|
|
* Writing PBA sets the receive portion of the buffer
|
|
|
|
* the remainder is used for the transmit buffer.
|
|
|
|
*
|
|
|
|
* Devices before the 82547 had a Packet Buffer of 64K.
|
|
|
|
* Default allocation: PBA=48K for Rx, leaving 16K for Tx.
|
|
|
|
* After the 82547 the buffer was reduced to 40K.
|
|
|
|
* Default allocation: PBA=30K for Rx, leaving 10K for Tx.
|
|
|
|
* Note: default does not leave enough room for Jumbo Frame >10k.
|
|
|
|
*/
|
|
|
|
if(adapter->hw.mac_type < em_82547) {
|
|
|
|
/* Total FIFO is 64K */
|
|
|
|
if(adapter->rx_buffer_len > EM_RXBUFFER_8192)
|
|
|
|
pba = E1000_PBA_40K; /* 40K for Rx, 24K for Tx */
|
|
|
|
else
|
|
|
|
pba = E1000_PBA_48K; /* 48K for Rx, 16K for Tx */
|
|
|
|
} else {
|
|
|
|
/* Total FIFO is 40K */
|
|
|
|
if(adapter->hw.max_frame_size > EM_RXBUFFER_8192) {
|
|
|
|
pba = E1000_PBA_22K; /* 22K for Rx, 18K for Tx */
|
|
|
|
} else {
|
|
|
|
pba = E1000_PBA_30K; /* 30K for Rx, 10K for Tx */
|
|
|
|
}
|
|
|
|
adapter->tx_fifo_head = 0;
|
|
|
|
adapter->tx_head_addr = pba << EM_TX_HEAD_ADDR_SHIFT;
|
|
|
|
adapter->tx_fifo_size = (E1000_PBA_40K - pba) << EM_PBA_BYTES_SHIFT;
|
|
|
|
}
|
|
|
|
INIT_DEBUGOUT1("em_init: pba=%dK",pba);
|
|
|
|
E1000_WRITE_REG(&adapter->hw, PBA, pba);
|
|
|
|
|
2003-11-14 18:02:25 +00:00
|
|
|
/* Get the latest mac address, User can use a LAA */
|
|
|
|
bcopy(adapter->interface_data.ac_enaddr, adapter->hw.mac_addr,
|
|
|
|
ETHER_ADDR_LEN);
|
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
/* Initialize the hardware */
|
|
|
|
if (em_hardware_init(adapter)) {
|
|
|
|
printf("em%d: Unable to initialize the hardware\n",
|
|
|
|
adapter->unit);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-06-04 16:57:18 +00:00
|
|
|
if (ifp->if_capenable & IFCAP_VLAN_HWTAGGING)
|
|
|
|
em_enable_vlans(adapter);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Prepare transmit descriptors and buffers */
|
|
|
|
if (em_setup_transmit_structures(adapter)) {
|
|
|
|
printf("em%d: Could not setup transmit structures\n",
|
|
|
|
adapter->unit);
|
|
|
|
em_stop(adapter);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
em_initialize_transmit_unit(adapter);
|
|
|
|
|
|
|
|
/* Setup Multicast table */
|
|
|
|
em_set_multi(adapter);
|
|
|
|
|
|
|
|
/* Prepare receive descriptors and buffers */
|
|
|
|
if (em_setup_receive_structures(adapter)) {
|
|
|
|
printf("em%d: Could not setup receive structures\n",
|
|
|
|
adapter->unit);
|
|
|
|
em_stop(adapter);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
em_initialize_receive_unit(adapter);
|
2003-11-14 18:02:25 +00:00
|
|
|
|
|
|
|
/* Don't loose promiscuous settings */
|
|
|
|
em_set_promisc(adapter);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
|
|
|
if (adapter->hw.mac_type >= em_82543) {
|
|
|
|
if (ifp->if_capenable & IFCAP_TXCSUM)
|
|
|
|
ifp->if_hwassist = EM_CHECKSUM_FEATURES;
|
|
|
|
else
|
|
|
|
ifp->if_hwassist = 0;
|
|
|
|
}
|
|
|
|
|
2003-09-23 00:18:25 +00:00
|
|
|
callout_reset(&adapter->timer, 2*hz, em_local_timer, adapter);
|
2002-06-03 22:30:51 +00:00
|
|
|
em_clear_hw_cntrs(&adapter->hw);
|
2002-11-25 19:56:16 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
2002-12-23 19:11:23 +00:00
|
|
|
/*
|
|
|
|
* Only enable interrupts if we are not polling, make sure
|
|
|
|
* they are off otherwise.
|
|
|
|
*/
|
2003-12-02 22:13:08 +00:00
|
|
|
if (ifp->if_flags & IFF_POLLING)
|
2002-12-23 19:11:23 +00:00
|
|
|
em_disable_intr(adapter);
|
|
|
|
else
|
2002-11-25 19:56:16 +00:00
|
|
|
#endif /* DEVICE_POLLING */
|
2003-03-21 21:47:31 +00:00
|
|
|
em_enable_intr(adapter);
|
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 */
|
|
|
|
adapter->hw.phy_reset_disable = TRUE;
|
|
|
|
|
2003-09-23 00:18:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
em_init(void *arg)
|
|
|
|
{
|
|
|
|
struct adapter * adapter = arg;
|
|
|
|
|
|
|
|
EM_LOCK(adapter);
|
|
|
|
em_init_locked(adapter);
|
|
|
|
EM_UNLOCK(adapter);
|
2002-06-03 22:30:51 +00:00
|
|
|
return;
|
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
|
|
|
|
static poll_handler_t em_poll;
|
2003-03-21 21:47:31 +00:00
|
|
|
|
|
|
|
static void
|
2003-09-23 00:18:25 +00:00
|
|
|
em_poll_locked(struct ifnet *ifp, enum poll_cmd cmd, int count)
|
2002-11-25 19:56:16 +00:00
|
|
|
{
|
2002-12-23 19:11:23 +00:00
|
|
|
struct adapter *adapter = ifp->if_softc;
|
|
|
|
u_int32_t reg_icr;
|
|
|
|
|
2003-09-23 00:18:25 +00:00
|
|
|
mtx_assert(&adapter->mtx, MA_OWNED);
|
|
|
|
|
2004-04-11 21:01:12 +00:00
|
|
|
if (!(ifp->if_capenable & IFCAP_POLLING)) {
|
|
|
|
ether_poll_deregister(ifp);
|
|
|
|
cmd = POLL_DEREGISTER;
|
|
|
|
}
|
2002-12-23 19:11:23 +00:00
|
|
|
if (cmd == POLL_DEREGISTER) { /* final call, enable interrupts */
|
|
|
|
em_enable_intr(adapter);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (cmd == POLL_AND_CHECK_STATUS) {
|
|
|
|
reg_icr = E1000_READ_REG(&adapter->hw, ICR);
|
|
|
|
if (reg_icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
|
2003-09-23 00:18:25 +00:00
|
|
|
callout_stop(&adapter->timer);
|
2002-12-23 19:11:23 +00:00
|
|
|
adapter->hw.get_link_status = 1;
|
|
|
|
em_check_for_link(&adapter->hw);
|
|
|
|
em_print_link_status(adapter);
|
2003-09-23 00:18:25 +00:00
|
|
|
callout_reset(&adapter->timer, 2*hz, em_local_timer, adapter);
|
2002-12-23 19:11:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ifp->if_flags & IFF_RUNNING) {
|
|
|
|
em_process_receive_interrupts(adapter, count);
|
|
|
|
em_clean_transmit_interrupts(adapter);
|
|
|
|
}
|
2003-03-21 21:47:31 +00:00
|
|
|
|
2004-07-02 12:16:02 +00:00
|
|
|
if (ifp->if_flags & IFF_RUNNING && !IFQ_DRV_IS_EMPTY(&ifp->if_snd))
|
2003-09-23 00:18:25 +00:00
|
|
|
em_start_locked(ifp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
em_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
|
|
|
|
{
|
|
|
|
struct adapter *adapter = ifp->if_softc;
|
|
|
|
|
|
|
|
EM_LOCK(adapter);
|
|
|
|
em_poll_locked(ifp, cmd, count);
|
|
|
|
EM_UNLOCK(adapter);
|
2002-11-25 19:56:16 +00:00
|
|
|
}
|
|
|
|
#endif /* DEVICE_POLLING */
|
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
/*********************************************************************
|
|
|
|
*
|
2003-03-21 21:47:31 +00:00
|
|
|
* Interrupt Service routine
|
2001-12-02 07:37:17 +00:00
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
|
|
|
em_intr(void *arg)
|
|
|
|
{
|
2003-03-21 21:47:31 +00:00
|
|
|
u_int32_t loop_cnt = EM_MAX_INTR;
|
|
|
|
u_int32_t reg_icr;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct adapter *adapter = arg;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-09-23 00:18:25 +00:00
|
|
|
EM_LOCK(adapter);
|
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
ifp = &adapter->interface_data.ac_if;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2002-11-25 19:56:16 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
2003-12-02 22:13:08 +00:00
|
|
|
if (ifp->if_flags & IFF_POLLING) {
|
2003-09-23 00:18:25 +00:00
|
|
|
EM_UNLOCK(adapter);
|
2002-12-23 19:11:23 +00:00
|
|
|
return;
|
2003-09-23 00:18:25 +00:00
|
|
|
}
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2004-04-11 21:01:12 +00:00
|
|
|
if ((ifp->if_capenable & IFCAP_POLLING) &&
|
|
|
|
ether_poll_register(em_poll, ifp)) {
|
2002-12-23 19:11:23 +00:00
|
|
|
em_disable_intr(adapter);
|
2003-10-10 23:14:21 +00:00
|
|
|
em_poll_locked(ifp, 0, 1);
|
2003-09-23 00:18:25 +00:00
|
|
|
EM_UNLOCK(adapter);
|
2002-12-23 19:11:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-11-25 19:56:16 +00:00
|
|
|
#endif /* DEVICE_POLLING */
|
|
|
|
|
2003-06-05 17:51:38 +00:00
|
|
|
reg_icr = E1000_READ_REG(&adapter->hw, ICR);
|
|
|
|
if (!reg_icr) {
|
2003-09-23 00:18:25 +00:00
|
|
|
EM_UNLOCK(adapter);
|
2003-06-05 17:51:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2003-06-05 17:51:38 +00:00
|
|
|
/* Link status change */
|
|
|
|
if (reg_icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
|
2003-09-23 00:18:25 +00:00
|
|
|
callout_stop(&adapter->timer);
|
2003-06-05 17:51:38 +00:00
|
|
|
adapter->hw.get_link_status = 1;
|
|
|
|
em_check_for_link(&adapter->hw);
|
|
|
|
em_print_link_status(adapter);
|
2003-09-23 00:18:25 +00:00
|
|
|
callout_reset(&adapter->timer, 2*hz, em_local_timer, adapter);
|
2003-06-05 17:51:38 +00:00
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-06-05 17:51:38 +00:00
|
|
|
while (loop_cnt > 0) {
|
2003-03-21 21:47:31 +00:00
|
|
|
if (ifp->if_flags & IFF_RUNNING) {
|
|
|
|
em_process_receive_interrupts(adapter, -1);
|
|
|
|
em_clean_transmit_interrupts(adapter);
|
|
|
|
}
|
|
|
|
loop_cnt--;
|
|
|
|
}
|
2003-06-05 17:51:38 +00:00
|
|
|
|
2004-07-02 12:16:02 +00:00
|
|
|
if (ifp->if_flags & IFF_RUNNING && IFQ_DRV_IS_EMPTY(&ifp->if_snd))
|
2003-09-23 00:18:25 +00:00
|
|
|
em_start_locked(ifp);
|
2003-03-21 21:47:31 +00:00
|
|
|
|
2003-09-23 00:18:25 +00:00
|
|
|
EM_UNLOCK(adapter);
|
2003-03-21 21:47:31 +00:00
|
|
|
return;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
struct adapter * adapter = ifp->if_softc;
|
|
|
|
|
|
|
|
INIT_DEBUGOUT("em_media_status: begin");
|
|
|
|
|
|
|
|
em_check_for_link(&adapter->hw);
|
|
|
|
if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU) {
|
|
|
|
if (adapter->link_active == 0) {
|
|
|
|
em_get_speed_and_duplex(&adapter->hw,
|
|
|
|
&adapter->link_speed,
|
|
|
|
&adapter->link_duplex);
|
|
|
|
adapter->link_active = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (adapter->link_active == 1) {
|
|
|
|
adapter->link_speed = 0;
|
|
|
|
adapter->link_duplex = 0;
|
|
|
|
adapter->link_active = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
ifmr->ifm_status = IFM_AVALID;
|
|
|
|
ifmr->ifm_active = IFM_ETHER;
|
|
|
|
|
|
|
|
if (!adapter->link_active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ifmr->ifm_status |= IFM_ACTIVE;
|
|
|
|
|
|
|
|
if (adapter->hw.media_type == em_media_type_fiber) {
|
|
|
|
ifmr->ifm_active |= IFM_1000_SX | IFM_FDX;
|
|
|
|
} else {
|
|
|
|
switch (adapter->link_speed) {
|
|
|
|
case 10:
|
|
|
|
ifmr->ifm_active |= IFM_10_T;
|
|
|
|
break;
|
|
|
|
case 100:
|
|
|
|
ifmr->ifm_active |= IFM_100_TX;
|
|
|
|
break;
|
|
|
|
case 1000:
|
|
|
|
#if __FreeBSD_version < 500000
|
|
|
|
ifmr->ifm_active |= IFM_1000_TX;
|
|
|
|
#else
|
|
|
|
ifmr->ifm_active |= IFM_1000_T;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (adapter->link_duplex == FULL_DUPLEX)
|
|
|
|
ifmr->ifm_active |= IFM_FDX;
|
|
|
|
else
|
|
|
|
ifmr->ifm_active |= IFM_HDX;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Media Ioctl callback
|
|
|
|
*
|
|
|
|
* This routine is called when the user changes speed/duplex using
|
|
|
|
* media/mediopt option with ifconfig.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static int
|
|
|
|
em_media_change(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct adapter * adapter = ifp->if_softc;
|
|
|
|
struct ifmedia *ifm = &adapter->media;
|
|
|
|
|
|
|
|
INIT_DEBUGOUT("em_media_change: begin");
|
|
|
|
|
|
|
|
if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
|
|
|
|
return(EINVAL);
|
|
|
|
|
|
|
|
switch (IFM_SUBTYPE(ifm->ifm_media)) {
|
|
|
|
case IFM_AUTO:
|
|
|
|
adapter->hw.autoneg = DO_AUTO_NEG;
|
|
|
|
adapter->hw.autoneg_advertised = AUTONEG_ADV_DEFAULT;
|
|
|
|
break;
|
|
|
|
case IFM_1000_SX:
|
|
|
|
#if __FreeBSD_version < 500000
|
|
|
|
case IFM_1000_TX:
|
|
|
|
#else
|
|
|
|
case IFM_1000_T:
|
|
|
|
#endif
|
|
|
|
adapter->hw.autoneg = DO_AUTO_NEG;
|
|
|
|
adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
|
|
|
|
break;
|
|
|
|
case IFM_100_TX:
|
|
|
|
adapter->hw.autoneg = FALSE;
|
|
|
|
adapter->hw.autoneg_advertised = 0;
|
|
|
|
if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX)
|
|
|
|
adapter->hw.forced_speed_duplex = em_100_full;
|
|
|
|
else
|
|
|
|
adapter->hw.forced_speed_duplex = em_100_half;
|
|
|
|
break;
|
|
|
|
case IFM_10_T:
|
|
|
|
adapter->hw.autoneg = FALSE;
|
|
|
|
adapter->hw.autoneg_advertised = 0;
|
|
|
|
if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX)
|
|
|
|
adapter->hw.forced_speed_duplex = em_10_full;
|
|
|
|
else
|
|
|
|
adapter->hw.forced_speed_duplex = em_10_half;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("em%d: Unsupported media type\n", adapter->unit);
|
|
|
|
}
|
|
|
|
|
2004-02-10 21:31:09 +00:00
|
|
|
/* As the speed/duplex settings my have changed we need to
|
|
|
|
* reset the PHY.
|
|
|
|
*/
|
|
|
|
adapter->hw.phy_reset_disable = FALSE;
|
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
em_init(adapter);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
static void
|
|
|
|
em_tx_cb(void *arg, bus_dma_segment_t *seg, int nsegs, bus_size_t mapsize, int error)
|
|
|
|
{
|
|
|
|
struct em_q *q = arg;
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
return;
|
|
|
|
KASSERT(nsegs <= EM_MAX_SCATTER,
|
|
|
|
("Too many DMA segments returned when mapping tx packet"));
|
|
|
|
q->nsegs = nsegs;
|
|
|
|
bcopy(seg, q->segs, nsegs * sizeof(seg[0]));
|
|
|
|
}
|
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* This routine maps the mbufs to tx descriptors.
|
|
|
|
*
|
|
|
|
* return 0 on success, positive on failure
|
|
|
|
**********************************************************************/
|
2003-05-02 21:17:08 +00:00
|
|
|
static int
|
2002-11-08 18:14:17 +00:00
|
|
|
em_encap(struct adapter *adapter, struct mbuf *m_head)
|
2003-05-02 21:17:08 +00:00
|
|
|
{
|
2002-12-23 19:11:23 +00:00
|
|
|
u_int32_t txd_upper;
|
2003-08-27 21:52:37 +00:00
|
|
|
u_int32_t txd_lower, txd_used = 0, txd_saved = 0;
|
2003-05-02 21:17:08 +00:00
|
|
|
int i, j, error;
|
2003-08-27 21:52:37 +00:00
|
|
|
u_int64_t address;
|
|
|
|
|
|
|
|
/* For 82544 Workaround */
|
|
|
|
DESC_ARRAY desc_array;
|
|
|
|
u_int32_t array_elements;
|
|
|
|
u_int32_t counter;
|
|
|
|
|
2002-12-23 19:11:23 +00:00
|
|
|
#if __FreeBSD_version < 500000
|
|
|
|
struct ifvlan *ifv = NULL;
|
|
|
|
#else
|
2003-03-21 21:47:31 +00:00
|
|
|
struct m_tag *mtag;
|
2003-05-02 21:17:08 +00:00
|
|
|
#endif
|
|
|
|
struct em_q q;
|
2002-12-23 19:11:23 +00:00
|
|
|
struct em_buffer *tx_buffer = NULL;
|
|
|
|
struct em_tx_desc *current_tx_desc = NULL;
|
|
|
|
struct ifnet *ifp = &adapter->interface_data.ac_if;
|
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
/*
|
|
|
|
* Force a cleanup if number of TX descriptors
|
|
|
|
* available hits the threshold
|
|
|
|
*/
|
|
|
|
if (adapter->num_tx_desc_avail <= EM_TX_CLEANUP_THRESHOLD) {
|
|
|
|
em_clean_transmit_interrupts(adapter);
|
|
|
|
if (adapter->num_tx_desc_avail <= EM_TX_CLEANUP_THRESHOLD) {
|
|
|
|
adapter->no_tx_desc_avail1++;
|
|
|
|
return(ENOBUFS);
|
|
|
|
}
|
|
|
|
}
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
/*
|
|
|
|
* Map the packet for DMA.
|
|
|
|
*/
|
|
|
|
if (bus_dmamap_create(adapter->txtag, BUS_DMA_NOWAIT, &q.map)) {
|
|
|
|
adapter->no_tx_map_avail++;
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
error = bus_dmamap_load_mbuf(adapter->txtag, q.map,
|
|
|
|
m_head, em_tx_cb, &q, BUS_DMA_NOWAIT);
|
|
|
|
if (error != 0) {
|
|
|
|
adapter->no_tx_dma_setup++;
|
|
|
|
bus_dmamap_destroy(adapter->txtag, q.map);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
KASSERT(q.nsegs != 0, ("em_encap: empty packet"));
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
if (q.nsegs > adapter->num_tx_desc_avail) {
|
|
|
|
adapter->no_tx_desc_avail2++;
|
|
|
|
bus_dmamap_destroy(adapter->txtag, q.map);
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ifp->if_hwassist > 0) {
|
|
|
|
em_transmit_checksum_setup(adapter, m_head,
|
|
|
|
&txd_upper, &txd_lower);
|
|
|
|
} else
|
|
|
|
txd_upper = txd_lower = 0;
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
|
|
|
|
/* Find out if we are in vlan mode */
|
2002-12-23 19:11:23 +00:00
|
|
|
#if __FreeBSD_version < 500000
|
2003-03-21 21:47:31 +00:00
|
|
|
if ((m_head->m_flags & (M_PROTO1|M_PKTHDR)) == (M_PROTO1|M_PKTHDR) &&
|
|
|
|
m_head->m_pkthdr.rcvif != NULL &&
|
|
|
|
m_head->m_pkthdr.rcvif->if_type == IFT_L2VLAN)
|
|
|
|
ifv = m_head->m_pkthdr.rcvif->if_softc;
|
2002-12-23 19:11:23 +00:00
|
|
|
#else
|
2003-05-02 21:17:08 +00:00
|
|
|
mtag = VLAN_OUTPUT_TAG(ifp, m_head);
|
2002-12-23 19:11:23 +00:00
|
|
|
#endif
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
i = adapter->next_avail_tx_desc;
|
2003-08-27 21:52:37 +00:00
|
|
|
if (adapter->pcix_82544) {
|
|
|
|
txd_saved = i;
|
|
|
|
txd_used = 0;
|
|
|
|
}
|
2003-05-02 21:17:08 +00:00
|
|
|
for (j = 0; j < q.nsegs; j++) {
|
2003-08-27 21:52:37 +00:00
|
|
|
/* If adapter is 82544 and on PCIX bus */
|
|
|
|
if(adapter->pcix_82544) {
|
|
|
|
array_elements = 0;
|
|
|
|
address = htole64(q.segs[j].ds_addr);
|
|
|
|
/*
|
|
|
|
* Check the Address and Length combination and
|
|
|
|
* split the data accordingly
|
|
|
|
*/
|
|
|
|
array_elements = em_fill_descriptors(address,
|
|
|
|
htole32(q.segs[j].ds_len),
|
|
|
|
&desc_array);
|
|
|
|
for (counter = 0; counter < array_elements; counter++) {
|
|
|
|
if (txd_used == adapter->num_tx_desc_avail) {
|
|
|
|
adapter->next_avail_tx_desc = txd_saved;
|
|
|
|
adapter->no_tx_desc_avail2++;
|
|
|
|
bus_dmamap_destroy(adapter->txtag, q.map);
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
tx_buffer = &adapter->tx_buffer_area[i];
|
|
|
|
current_tx_desc = &adapter->tx_desc_base[i];
|
|
|
|
current_tx_desc->buffer_addr = htole64(
|
|
|
|
desc_array.descriptor[counter].address);
|
|
|
|
current_tx_desc->lower.data = htole32(
|
|
|
|
(adapter->txd_cmd | txd_lower |
|
|
|
|
(u_int16_t)desc_array.descriptor[counter].length));
|
|
|
|
current_tx_desc->upper.data = htole32((txd_upper));
|
|
|
|
if (++i == adapter->num_tx_desc)
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
tx_buffer->m_head = NULL;
|
|
|
|
txd_used++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tx_buffer = &adapter->tx_buffer_area[i];
|
|
|
|
current_tx_desc = &adapter->tx_desc_base[i];
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2003-08-27 21:52:37 +00:00
|
|
|
current_tx_desc->buffer_addr = htole64(q.segs[j].ds_addr);
|
|
|
|
current_tx_desc->lower.data = htole32(
|
|
|
|
adapter->txd_cmd | txd_lower | q.segs[j].ds_len);
|
|
|
|
current_tx_desc->upper.data = htole32(txd_upper);
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2003-08-27 21:52:37 +00:00
|
|
|
if (++i == adapter->num_tx_desc)
|
|
|
|
i = 0;
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2003-08-27 21:52:37 +00:00
|
|
|
tx_buffer->m_head = NULL;
|
|
|
|
}
|
2003-05-02 21:17:08 +00:00
|
|
|
}
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2003-08-27 21:52:37 +00:00
|
|
|
adapter->next_avail_tx_desc = i;
|
|
|
|
if (adapter->pcix_82544) {
|
|
|
|
adapter->num_tx_desc_avail -= txd_used;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
adapter->num_tx_desc_avail -= q.nsegs;
|
|
|
|
}
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2002-12-23 19:11:23 +00:00
|
|
|
#if __FreeBSD_version < 500000
|
2003-03-21 21:47:31 +00:00
|
|
|
if (ifv != NULL) {
|
|
|
|
/* Set the vlan id */
|
2003-05-02 21:17:08 +00:00
|
|
|
current_tx_desc->upper.fields.special = htole16(ifv->ifv_tag);
|
2002-12-23 19:11:23 +00:00
|
|
|
#else
|
2003-03-21 21:47:31 +00:00
|
|
|
if (mtag != NULL) {
|
|
|
|
/* Set the vlan id */
|
2003-05-02 21:17:08 +00:00
|
|
|
current_tx_desc->upper.fields.special = htole16(VLAN_TAG_VALUE(mtag));
|
2002-12-23 19:11:23 +00:00
|
|
|
#endif
|
2003-05-02 21:17:08 +00:00
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
/* Tell hardware to add tag */
|
2003-05-02 21:17:08 +00:00
|
|
|
current_tx_desc->lower.data |= htole32(E1000_TXD_CMD_VLE);
|
2003-03-21 21:47:31 +00:00
|
|
|
}
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
tx_buffer->m_head = m_head;
|
|
|
|
tx_buffer->map = q.map;
|
|
|
|
bus_dmamap_sync(adapter->txtag, q.map, BUS_DMASYNC_PREWRITE);
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2003-05-02 21:17:08 +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
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
/*
|
|
|
|
* Advance the Transmit Descriptor Tail (Tdt), this tells the E1000
|
|
|
|
* that this frame is available to transmit.
|
|
|
|
*/
|
|
|
|
if (adapter->hw.mac_type == em_82547 &&
|
|
|
|
adapter->link_duplex == HALF_DUPLEX) {
|
2003-10-15 05:34:41 +00:00
|
|
|
em_82547_move_tail_locked(adapter);
|
2003-05-02 21:17:08 +00:00
|
|
|
} else {
|
|
|
|
E1000_WRITE_REG(&adapter->hw, TDT, i);
|
|
|
|
if (adapter->hw.mac_type == em_82547) {
|
|
|
|
em_82547_update_fifo_head(adapter, m_head->m_pkthdr.len);
|
|
|
|
}
|
|
|
|
}
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
return(0);
|
|
|
|
}
|
2003-03-21 21:47:31 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* 82547 workaround to avoid controller hang in half-duplex environment.
|
|
|
|
* The workaround is to avoid queuing a large packet that would span
|
|
|
|
* 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
|
2003-10-15 05:34:41 +00:00
|
|
|
em_82547_move_tail_locked(struct adapter *adapter)
|
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;
|
|
|
|
|
2003-10-10 23:14:21 +00:00
|
|
|
EM_LOCK_ASSERT(adapter);
|
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
hw_tdt = E1000_READ_REG(&adapter->hw, TDT);
|
|
|
|
sw_tdt = adapter->next_avail_tx_desc;
|
|
|
|
|
|
|
|
while (hw_tdt != sw_tdt) {
|
|
|
|
tx_desc = &adapter->tx_desc_base[hw_tdt];
|
|
|
|
length += tx_desc->lower.flags.length;
|
|
|
|
eop = tx_desc->lower.data & E1000_TXD_CMD_EOP;
|
|
|
|
if(++hw_tdt == adapter->num_tx_desc)
|
|
|
|
hw_tdt = 0;
|
|
|
|
|
|
|
|
if(eop) {
|
|
|
|
if (em_82547_fifo_workaround(adapter, length)) {
|
2004-09-01 23:22:41 +00:00
|
|
|
adapter->tx_fifo_wrk_cnt++;
|
2003-09-23 00:18:25 +00:00
|
|
|
callout_reset(&adapter->tx_fifo_timer, 1,
|
|
|
|
em_82547_move_tail, adapter);
|
|
|
|
break;
|
2003-03-21 21:47:31 +00:00
|
|
|
}
|
2003-09-23 00:18:25 +00:00
|
|
|
E1000_WRITE_REG(&adapter->hw, TDT, hw_tdt);
|
|
|
|
em_82547_update_fifo_head(adapter, length);
|
|
|
|
length = 0;
|
2003-03-21 21:47:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-10-15 05:34:41 +00:00
|
|
|
static void
|
|
|
|
em_82547_move_tail(void *arg)
|
|
|
|
{
|
|
|
|
struct adapter *adapter = arg;
|
|
|
|
|
|
|
|
EM_LOCK(adapter);
|
|
|
|
em_82547_move_tail_locked(adapter);
|
|
|
|
EM_UNLOCK(adapter);
|
|
|
|
}
|
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
static int
|
|
|
|
em_82547_fifo_workaround(struct adapter *adapter, int len)
|
|
|
|
{
|
|
|
|
int fifo_space, fifo_pkt_len;
|
|
|
|
|
|
|
|
fifo_pkt_len = EM_ROUNDUP(len + EM_FIFO_HDR, EM_FIFO_HDR);
|
|
|
|
|
|
|
|
if (adapter->link_duplex == HALF_DUPLEX) {
|
2004-09-01 23:22:41 +00:00
|
|
|
fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
|
2003-03-21 21:47:31 +00:00
|
|
|
|
|
|
|
if (fifo_pkt_len >= (EM_82547_PKT_THRESH + fifo_space)) {
|
|
|
|
if (em_82547_tx_fifo_reset(adapter)) {
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
em_82547_update_fifo_head(struct adapter *adapter, int len)
|
|
|
|
{
|
|
|
|
int fifo_pkt_len = EM_ROUNDUP(len + EM_FIFO_HDR, EM_FIFO_HDR);
|
|
|
|
|
|
|
|
/* tx_fifo_head is always 16 byte aligned */
|
|
|
|
adapter->tx_fifo_head += fifo_pkt_len;
|
2004-09-01 23:22:41 +00:00
|
|
|
if (adapter->tx_fifo_head >= adapter->tx_fifo_size) {
|
|
|
|
adapter->tx_fifo_head -= adapter->tx_fifo_size;
|
2003-03-21 21:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
em_82547_tx_fifo_reset(struct adapter *adapter)
|
|
|
|
{
|
|
|
|
uint32_t tctl;
|
|
|
|
|
|
|
|
if ( (E1000_READ_REG(&adapter->hw, TDT) ==
|
|
|
|
E1000_READ_REG(&adapter->hw, TDH)) &&
|
|
|
|
(E1000_READ_REG(&adapter->hw, TDFT) ==
|
|
|
|
E1000_READ_REG(&adapter->hw, TDFH)) &&
|
|
|
|
(E1000_READ_REG(&adapter->hw, TDFTS) ==
|
|
|
|
E1000_READ_REG(&adapter->hw, TDFHS)) &&
|
|
|
|
(E1000_READ_REG(&adapter->hw, TDFPC) == 0)) {
|
|
|
|
|
|
|
|
/* Disable TX unit */
|
|
|
|
tctl = E1000_READ_REG(&adapter->hw, TCTL);
|
|
|
|
E1000_WRITE_REG(&adapter->hw, TCTL, tctl & ~E1000_TCTL_EN);
|
|
|
|
|
|
|
|
/* Reset FIFO pointers */
|
2004-09-01 23:22:41 +00:00
|
|
|
E1000_WRITE_REG(&adapter->hw, TDFT, adapter->tx_head_addr);
|
|
|
|
E1000_WRITE_REG(&adapter->hw, TDFH, adapter->tx_head_addr);
|
|
|
|
E1000_WRITE_REG(&adapter->hw, TDFTS, adapter->tx_head_addr);
|
|
|
|
E1000_WRITE_REG(&adapter->hw, TDFHS, adapter->tx_head_addr);
|
2003-03-21 21:47:31 +00:00
|
|
|
|
|
|
|
/* Re-enable TX unit */
|
|
|
|
E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
|
|
|
|
E1000_WRITE_FLUSH(&adapter->hw);
|
|
|
|
|
|
|
|
adapter->tx_fifo_head = 0;
|
2004-09-01 23:22:41 +00:00
|
|
|
adapter->tx_fifo_reset_cnt++;
|
2003-03-21 21:47:31 +00:00
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
static void
|
|
|
|
em_set_promisc(struct adapter * adapter)
|
|
|
|
{
|
|
|
|
|
|
|
|
u_int32_t reg_rctl;
|
2004-09-01 23:22:41 +00:00
|
|
|
u_int32_t ctrl;
|
2002-11-08 18:14:17 +00:00
|
|
|
struct ifnet *ifp = &adapter->interface_data.ac_if;
|
|
|
|
|
|
|
|
reg_rctl = E1000_READ_REG(&adapter->hw, RCTL);
|
2004-09-01 23:22:41 +00:00
|
|
|
ctrl = E1000_READ_REG(&adapter->hw, CTRL);
|
2002-11-08 18:14:17 +00:00
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_PROMISC) {
|
|
|
|
reg_rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
|
|
|
|
E1000_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
|
2004-09-01 23:22:41 +00:00
|
|
|
|
|
|
|
/* Disable VLAN stripping in promiscous mode
|
|
|
|
* This enables bridging of vlan tagged frames to occur
|
|
|
|
* and also allows vlan tags to be seen in tcpdump
|
|
|
|
*/
|
|
|
|
ctrl &= ~E1000_CTRL_VME;
|
|
|
|
E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
|
|
|
|
|
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;
|
|
|
|
E1000_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
em_disable_promisc(struct adapter * adapter)
|
|
|
|
{
|
|
|
|
u_int32_t reg_rctl;
|
|
|
|
|
|
|
|
reg_rctl = E1000_READ_REG(&adapter->hw, RCTL);
|
|
|
|
|
|
|
|
reg_rctl &= (~E1000_RCTL_UPE);
|
|
|
|
reg_rctl &= (~E1000_RCTL_MPE);
|
|
|
|
E1000_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
|
|
|
|
|
2004-09-01 23:22:41 +00:00
|
|
|
em_enable_vlans(adapter);
|
2002-11-08 18:14:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Multicast Update
|
|
|
|
*
|
|
|
|
* This routine is called whenever multicast address list is updated.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
static void
|
|
|
|
em_set_multi(struct adapter * adapter)
|
|
|
|
{
|
2002-12-23 19:11:23 +00:00
|
|
|
u_int32_t reg_rctl = 0;
|
|
|
|
u_int8_t mta[MAX_NUM_MULTICAST_ADDRESSES * ETH_LENGTH_OF_ADDRESS];
|
|
|
|
struct ifmultiaddr *ifma;
|
|
|
|
int mcnt = 0;
|
|
|
|
struct ifnet *ifp = &adapter->interface_data.ac_if;
|
|
|
|
|
|
|
|
IOCTL_DEBUGOUT("em_set_multi: begin");
|
|
|
|
|
|
|
|
if (adapter->hw.mac_type == em_82542_rev2_0) {
|
|
|
|
reg_rctl = E1000_READ_REG(&adapter->hw, RCTL);
|
|
|
|
if (adapter->hw.pci_cmd_word & CMD_MEM_WRT_INVALIDATE) {
|
|
|
|
em_pci_clear_mwi(&adapter->hw);
|
|
|
|
}
|
|
|
|
reg_rctl |= E1000_RCTL_RST;
|
|
|
|
E1000_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
|
|
|
|
msec_delay(5);
|
|
|
|
}
|
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
#if __FreeBSD_version < 500000
|
2002-12-23 19:11:23 +00:00
|
|
|
LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
|
2002-11-08 18:14:17 +00:00
|
|
|
#else
|
2002-12-23 19:11:23 +00:00
|
|
|
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
|
|
|
|
#endif
|
|
|
|
if (ifma->ifma_addr->sa_family != AF_LINK)
|
|
|
|
continue;
|
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
if (mcnt == MAX_NUM_MULTICAST_ADDRESSES) break;
|
|
|
|
|
2002-12-23 19:11:23 +00:00
|
|
|
bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
|
|
|
|
&mta[mcnt*ETH_LENGTH_OF_ADDRESS], ETH_LENGTH_OF_ADDRESS);
|
|
|
|
mcnt++;
|
|
|
|
}
|
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
if (mcnt >= MAX_NUM_MULTICAST_ADDRESSES) {
|
2002-12-23 19:11:23 +00:00
|
|
|
reg_rctl = E1000_READ_REG(&adapter->hw, RCTL);
|
|
|
|
reg_rctl |= E1000_RCTL_MPE;
|
|
|
|
E1000_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
|
|
|
|
} else
|
2004-02-10 21:31:09 +00:00
|
|
|
em_mc_addr_list_update(&adapter->hw, mta, mcnt, 0, 1);
|
2002-12-23 19:11:23 +00:00
|
|
|
|
|
|
|
if (adapter->hw.mac_type == em_82542_rev2_0) {
|
|
|
|
reg_rctl = E1000_READ_REG(&adapter->hw, RCTL);
|
|
|
|
reg_rctl &= ~E1000_RCTL_RST;
|
|
|
|
E1000_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
|
|
|
|
msec_delay(5);
|
|
|
|
if (adapter->hw.pci_cmd_word & CMD_MEM_WRT_INVALIDATE) {
|
|
|
|
em_pci_set_mwi(&adapter->hw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
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)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct adapter * adapter = arg;
|
|
|
|
ifp = &adapter->interface_data.ac_if;
|
|
|
|
|
2003-09-23 00:18:25 +00:00
|
|
|
EM_LOCK(adapter);
|
2002-11-08 18:14:17 +00:00
|
|
|
|
|
|
|
em_check_for_link(&adapter->hw);
|
|
|
|
em_print_link_status(adapter);
|
|
|
|
em_update_stats_counters(adapter);
|
|
|
|
if (em_display_debug_stats && ifp->if_flags & IFF_RUNNING) {
|
|
|
|
em_print_hw_stats(adapter);
|
|
|
|
}
|
2003-03-21 21:47:31 +00:00
|
|
|
em_smartspeed(adapter);
|
|
|
|
|
2003-09-23 00:18:25 +00:00
|
|
|
callout_reset(&adapter->timer, 2*hz, em_local_timer, adapter);
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2003-09-23 00:18:25 +00:00
|
|
|
EM_UNLOCK(adapter);
|
2002-11-08 18:14:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
em_print_link_status(struct adapter * adapter)
|
|
|
|
{
|
|
|
|
if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU) {
|
|
|
|
if (adapter->link_active == 0) {
|
|
|
|
em_get_speed_and_duplex(&adapter->hw,
|
|
|
|
&adapter->link_speed,
|
|
|
|
&adapter->link_duplex);
|
|
|
|
printf("em%d: Link is up %d Mbps %s\n",
|
|
|
|
adapter->unit,
|
|
|
|
adapter->link_speed,
|
|
|
|
((adapter->link_duplex == FULL_DUPLEX) ?
|
|
|
|
"Full Duplex" : "Half Duplex"));
|
|
|
|
adapter->link_active = 1;
|
2003-03-21 21:47:31 +00:00
|
|
|
adapter->smartspeed = 0;
|
2002-11-08 18:14:17 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (adapter->link_active == 1) {
|
|
|
|
adapter->link_speed = 0;
|
|
|
|
adapter->link_duplex = 0;
|
|
|
|
printf("em%d: Link is Down\n", adapter->unit);
|
|
|
|
adapter->link_active = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
return;
|
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
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct adapter * adapter = arg;
|
|
|
|
ifp = &adapter->interface_data.ac_if;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-09-23 00:18:25 +00:00
|
|
|
mtx_assert(&adapter->mtx, MA_OWNED);
|
|
|
|
|
2003-08-27 21:52:37 +00:00
|
|
|
INIT_DEBUGOUT("em_stop: begin");
|
2002-11-08 18:14:17 +00:00
|
|
|
em_disable_intr(adapter);
|
|
|
|
em_reset_hw(&adapter->hw);
|
2003-09-23 00:18:25 +00:00
|
|
|
callout_stop(&adapter->timer);
|
|
|
|
callout_stop(&adapter->tx_fifo_timer);
|
2002-11-08 18:14:17 +00:00
|
|
|
em_free_transmit_structures(adapter);
|
|
|
|
em_free_receive_structures(adapter);
|
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 */
|
|
|
|
ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
return;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Determine hardware revision.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_identify_hardware(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
device_t dev = adapter->dev;
|
|
|
|
|
|
|
|
/* Make sure our PCI config space has the necessary stuff set */
|
|
|
|
adapter->hw.pci_cmd_word = pci_read_config(dev, PCIR_COMMAND, 2);
|
|
|
|
if (!((adapter->hw.pci_cmd_word & PCIM_CMD_BUSMASTEREN) &&
|
|
|
|
(adapter->hw.pci_cmd_word & PCIM_CMD_MEMEN))) {
|
2002-12-23 19:11:23 +00:00
|
|
|
printf("em%d: Memory Access and/or Bus Master bits were not set!\n",
|
2002-06-03 22:30:51 +00:00
|
|
|
adapter->unit);
|
2002-12-23 19:11:23 +00:00
|
|
|
adapter->hw.pci_cmd_word |=
|
2002-06-03 22:30:51 +00:00
|
|
|
(PCIM_CMD_BUSMASTEREN | PCIM_CMD_MEMEN);
|
|
|
|
pci_write_config(dev, PCIR_COMMAND, adapter->hw.pci_cmd_word, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save off the information about this board */
|
|
|
|
adapter->hw.vendor_id = pci_get_vendor(dev);
|
|
|
|
adapter->hw.device_id = pci_get_device(dev);
|
|
|
|
adapter->hw.revision_id = pci_read_config(dev, PCIR_REVID, 1);
|
|
|
|
adapter->hw.subsystem_vendor_id = pci_read_config(dev, PCIR_SUBVEND_0, 2);
|
|
|
|
adapter->hw.subsystem_id = pci_read_config(dev, PCIR_SUBDEV_0, 2);
|
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
/* Identify the MAC */
|
2002-12-23 19:11:23 +00:00
|
|
|
if (em_set_mac_type(&adapter->hw))
|
|
|
|
printf("em%d: Unknown MAC Type\n", adapter->unit);
|
2003-08-27 21:52:37 +00:00
|
|
|
|
|
|
|
if(adapter->hw.mac_type == em_82541 ||
|
|
|
|
adapter->hw.mac_type == em_82541_rev_2 ||
|
|
|
|
adapter->hw.mac_type == em_82547 ||
|
|
|
|
adapter->hw.mac_type == em_82547_rev_2)
|
|
|
|
adapter->hw.phy_init_script = TRUE;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2002-12-23 19:11:23 +00:00
|
|
|
return;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-04-06 00:36:53 +00:00
|
|
|
em_allocate_pci_resources(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-07-16 16:55:03 +00:00
|
|
|
int i, val, rid;
|
2002-06-03 22:30:51 +00:00
|
|
|
device_t dev = adapter->dev;
|
|
|
|
|
2002-07-16 16:55:03 +00:00
|
|
|
rid = EM_MMBA;
|
2004-03-17 17:50:55 +00:00
|
|
|
adapter->res_memory = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
|
|
|
|
&rid, RF_ACTIVE);
|
2002-06-03 22:30:51 +00:00
|
|
|
if (!(adapter->res_memory)) {
|
|
|
|
printf("em%d: Unable to allocate bus resource: memory\n",
|
|
|
|
adapter->unit);
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
2002-07-16 16:55:03 +00:00
|
|
|
adapter->osdep.mem_bus_space_tag =
|
2002-06-03 22:30:51 +00:00
|
|
|
rman_get_bustag(adapter->res_memory);
|
2002-07-16 16:55:03 +00:00
|
|
|
adapter->osdep.mem_bus_space_handle =
|
2002-06-03 22:30:51 +00:00
|
|
|
rman_get_bushandle(adapter->res_memory);
|
2002-07-16 16:55:03 +00:00
|
|
|
adapter->hw.hw_addr = (uint8_t *)&adapter->osdep.mem_bus_space_handle;
|
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2002-07-16 16:55:03 +00:00
|
|
|
if (adapter->hw.mac_type > em_82543) {
|
|
|
|
/* Figure our where our IO BAR is ? */
|
|
|
|
rid = EM_MMBA;
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
val = pci_read_config(dev, rid, 4);
|
|
|
|
if (val & 0x00000001) {
|
|
|
|
adapter->io_rid = rid;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rid += 4;
|
|
|
|
}
|
|
|
|
|
2004-03-17 17:50:55 +00:00
|
|
|
adapter->res_ioport = bus_alloc_resource_any(dev,
|
|
|
|
SYS_RES_IOPORT,
|
|
|
|
&adapter->io_rid,
|
|
|
|
RF_ACTIVE);
|
2002-07-16 16:55:03 +00:00
|
|
|
if (!(adapter->res_ioport)) {
|
|
|
|
printf("em%d: Unable to allocate bus resource: ioport\n",
|
|
|
|
adapter->unit);
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
adapter->hw.io_base =
|
|
|
|
rman_get_start(adapter->res_ioport);
|
|
|
|
}
|
|
|
|
|
|
|
|
rid = 0x0;
|
2004-03-17 17:50:55 +00:00
|
|
|
adapter->res_interrupt = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
|
|
|
|
RF_SHAREABLE |
|
|
|
|
RF_ACTIVE);
|
2002-06-03 22:30:51 +00:00
|
|
|
if (!(adapter->res_interrupt)) {
|
|
|
|
printf("em%d: Unable to allocate bus resource: interrupt\n",
|
|
|
|
adapter->unit);
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
2003-09-23 00:18:25 +00:00
|
|
|
if (bus_setup_intr(dev, adapter->res_interrupt,
|
2003-10-10 23:14:21 +00:00
|
|
|
INTR_TYPE_NET | INTR_MPSAFE,
|
2002-06-03 22:30:51 +00:00
|
|
|
(void (*)(void *)) em_intr, adapter,
|
|
|
|
&adapter->int_handler_tag)) {
|
|
|
|
printf("em%d: Error registering interrupt handler!\n",
|
|
|
|
adapter->unit);
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
adapter->hw.back = &adapter->osdep;
|
|
|
|
|
|
|
|
return(0);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_free_pci_resources(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
device_t dev = adapter->dev;
|
|
|
|
|
|
|
|
if (adapter->res_interrupt != NULL) {
|
|
|
|
bus_teardown_intr(dev, adapter->res_interrupt,
|
|
|
|
adapter->int_handler_tag);
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, 0,
|
|
|
|
adapter->res_interrupt);
|
|
|
|
}
|
|
|
|
if (adapter->res_memory != NULL) {
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, EM_MMBA,
|
|
|
|
adapter->res_memory);
|
|
|
|
}
|
2002-07-16 16:55:03 +00:00
|
|
|
|
|
|
|
if (adapter->res_ioport != NULL) {
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, adapter->io_rid,
|
|
|
|
adapter->res_ioport);
|
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
return;
|
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
|
2002-04-06 00:36:53 +00:00
|
|
|
em_hardware_init(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2003-08-27 21:52:37 +00:00
|
|
|
INIT_DEBUGOUT("em_hardware_init: begin");
|
2002-06-03 22:30:51 +00:00
|
|
|
/* Issue a global reset */
|
|
|
|
em_reset_hw(&adapter->hw);
|
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
/* When hardware is reset, fifo_head is also reset */
|
|
|
|
adapter->tx_fifo_head = 0;
|
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
/* Make sure we have a good EEPROM before we read from it */
|
|
|
|
if (em_validate_eeprom_checksum(&adapter->hw) < 0) {
|
|
|
|
printf("em%d: The EEPROM Checksum Is Not Valid\n",
|
|
|
|
adapter->unit);
|
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (em_read_part_num(&adapter->hw, &(adapter->part_num)) < 0) {
|
|
|
|
printf("em%d: EEPROM read error while reading part number\n",
|
|
|
|
adapter->unit);
|
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (em_init_hw(&adapter->hw) < 0) {
|
|
|
|
printf("em%d: Hardware Initialization Failed",
|
|
|
|
adapter->unit);
|
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
em_check_for_link(&adapter->hw);
|
|
|
|
if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU)
|
|
|
|
adapter->link_active = 1;
|
|
|
|
else
|
|
|
|
adapter->link_active = 0;
|
|
|
|
|
|
|
|
if (adapter->link_active) {
|
|
|
|
em_get_speed_and_duplex(&adapter->hw,
|
|
|
|
&adapter->link_speed,
|
|
|
|
&adapter->link_duplex);
|
|
|
|
} else {
|
|
|
|
adapter->link_speed = 0;
|
|
|
|
adapter->link_duplex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Setup networking device structure and register an interface.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_setup_interface(device_t dev, struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
INIT_DEBUGOUT("em_setup_interface: begin");
|
|
|
|
|
|
|
|
ifp = &adapter->interface_data.ac_if;
|
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_baudrate = 1000000000;
|
|
|
|
ifp->if_init = em_init;
|
|
|
|
ifp->if_softc = adapter;
|
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
|
|
|
ifp->if_ioctl = em_ioctl;
|
|
|
|
ifp->if_start = em_start;
|
|
|
|
ifp->if_watchdog = em_watchdog;
|
2004-07-02 12:16:02 +00:00
|
|
|
IFQ_SET_MAXLEN(&ifp->if_snd, adapter->num_tx_desc - 1);
|
|
|
|
ifp->if_snd.ifq_drv_maxlen = adapter->num_tx_desc - 1;
|
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
#if __FreeBSD_version < 500000
|
|
|
|
ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
|
2002-12-23 19:11:23 +00:00
|
|
|
#else
|
2003-03-21 21:47:31 +00:00
|
|
|
ether_ifattach(ifp, adapter->interface_data.ac_enaddr);
|
2002-12-23 19:11:23 +00:00
|
|
|
#endif
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2004-05-20 11:04:09 +00:00
|
|
|
ifp->if_capabilities = ifp->if_capenable = 0;
|
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
if (adapter->hw.mac_type >= em_82543) {
|
2004-05-20 11:04:09 +00:00
|
|
|
ifp->if_capabilities |= IFCAP_HWCSUM;
|
|
|
|
ifp->if_capenable |= IFCAP_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);
|
2003-03-21 21:47:31 +00:00
|
|
|
#if __FreeBSD_version >= 500000
|
2004-05-20 11:04:09 +00:00
|
|
|
ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU;
|
2004-05-20 10:57:33 +00:00
|
|
|
ifp->if_capenable |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU;
|
2002-12-23 19:11:23 +00:00
|
|
|
#endif
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2004-04-11 21:01:12 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
|
|
|
ifp->if_capabilities |= IFCAP_POLLING;
|
|
|
|
ifp->if_capenable |= IFCAP_POLLING;
|
|
|
|
#endif
|
2003-03-21 21:47:31 +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
|
|
|
|
*/
|
|
|
|
ifmedia_init(&adapter->media, IFM_IMASK, em_media_change,
|
|
|
|
em_media_status);
|
|
|
|
if (adapter->hw.media_type == em_media_type_fiber) {
|
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_SX | IFM_FDX,
|
|
|
|
0, NULL);
|
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_SX,
|
|
|
|
0, NULL);
|
|
|
|
} else {
|
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_10_T, 0, NULL);
|
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_10_T | IFM_FDX,
|
|
|
|
0, NULL);
|
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_100_TX,
|
|
|
|
0, NULL);
|
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_100_TX | IFM_FDX,
|
|
|
|
0, NULL);
|
2002-07-16 16:55:03 +00:00
|
|
|
#if __FreeBSD_version < 500000
|
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_TX | IFM_FDX,
|
|
|
|
0, NULL);
|
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_TX, 0, NULL);
|
|
|
|
#else
|
2002-06-03 22:30:51 +00:00
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_T | IFM_FDX,
|
|
|
|
0, NULL);
|
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_T, 0, NULL);
|
2002-07-16 16:55:03 +00:00
|
|
|
#endif
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
|
|
|
ifmedia_add(&adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL);
|
|
|
|
ifmedia_set(&adapter->media, IFM_ETHER | IFM_AUTO);
|
|
|
|
|
|
|
|
return;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Workaround for SmartSpeed on 82541 and 82547 controllers
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
|
|
|
em_smartspeed(struct adapter *adapter)
|
|
|
|
{
|
|
|
|
uint16_t phy_tmp;
|
|
|
|
|
|
|
|
if(adapter->link_active || (adapter->hw.phy_type != em_phy_igp) ||
|
|
|
|
!adapter->hw.autoneg || !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(adapter->smartspeed == 0) {
|
|
|
|
/* If Master/Slave config fault is asserted twice,
|
|
|
|
* we assume back-to-back */
|
|
|
|
em_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_tmp);
|
|
|
|
if(!(phy_tmp & SR_1000T_MS_CONFIG_FAULT)) return;
|
|
|
|
em_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_tmp);
|
|
|
|
if(phy_tmp & SR_1000T_MS_CONFIG_FAULT) {
|
|
|
|
em_read_phy_reg(&adapter->hw, PHY_1000T_CTRL,
|
|
|
|
&phy_tmp);
|
|
|
|
if(phy_tmp & CR_1000T_MS_ENABLE) {
|
|
|
|
phy_tmp &= ~CR_1000T_MS_ENABLE;
|
|
|
|
em_write_phy_reg(&adapter->hw,
|
|
|
|
PHY_1000T_CTRL, phy_tmp);
|
|
|
|
adapter->smartspeed++;
|
|
|
|
if(adapter->hw.autoneg &&
|
|
|
|
!em_phy_setup_autoneg(&adapter->hw) &&
|
|
|
|
!em_read_phy_reg(&adapter->hw, PHY_CTRL,
|
|
|
|
&phy_tmp)) {
|
|
|
|
phy_tmp |= (MII_CR_AUTO_NEG_EN |
|
|
|
|
MII_CR_RESTART_AUTO_NEG);
|
|
|
|
em_write_phy_reg(&adapter->hw,
|
|
|
|
PHY_CTRL, phy_tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else if(adapter->smartspeed == EM_SMARTSPEED_DOWNSHIFT) {
|
|
|
|
/* If still no link, perhaps using 2/3 pair cable */
|
|
|
|
em_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_tmp);
|
|
|
|
phy_tmp |= CR_1000T_MS_ENABLE;
|
|
|
|
em_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_tmp);
|
|
|
|
if(adapter->hw.autoneg &&
|
|
|
|
!em_phy_setup_autoneg(&adapter->hw) &&
|
|
|
|
!em_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_tmp)) {
|
|
|
|
phy_tmp |= (MII_CR_AUTO_NEG_EN |
|
|
|
|
MII_CR_RESTART_AUTO_NEG);
|
|
|
|
em_write_phy_reg(&adapter->hw, PHY_CTRL, phy_tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Restart process after EM_SMARTSPEED_MAX iterations */
|
|
|
|
if(adapter->smartspeed++ == EM_SMARTSPEED_MAX)
|
|
|
|
adapter->smartspeed = 0;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (error)
|
|
|
|
return;
|
|
|
|
*(bus_addr_t*) arg = segs->ds_addr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
em_dma_malloc(struct adapter *adapter, bus_size_t size,
|
|
|
|
struct em_dma_alloc *dma, int mapflags)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = bus_dma_tag_create(NULL, /* parent */
|
|
|
|
PAGE_SIZE, 0, /* alignment, bounds */
|
|
|
|
BUS_SPACE_MAXADDR, /* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
|
|
|
size, /* maxsize */
|
|
|
|
1, /* nsegments */
|
|
|
|
size, /* maxsegsize */
|
|
|
|
BUS_DMA_ALLOCNOW, /* flags */
|
2003-07-01 15:52:06 +00:00
|
|
|
NULL, /* lockfunc */
|
|
|
|
NULL, /* lockarg */
|
2003-05-02 21:17:08 +00:00
|
|
|
&dma->dma_tag);
|
|
|
|
if (r != 0) {
|
|
|
|
printf("em%d: em_dma_malloc: bus_dma_tag_create failed; "
|
|
|
|
"error %u\n", adapter->unit, r);
|
|
|
|
goto fail_0;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = bus_dmamap_create(dma->dma_tag, BUS_DMA_NOWAIT, &dma->dma_map);
|
|
|
|
if (r != 0) {
|
|
|
|
printf("em%d: em_dma_malloc: bus_dmamap_create failed; "
|
|
|
|
"error %u\n", adapter->unit, r);
|
|
|
|
goto fail_1;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = bus_dmamem_alloc(dma->dma_tag, (void**) &dma->dma_vaddr,
|
|
|
|
BUS_DMA_NOWAIT, &dma->dma_map);
|
|
|
|
if (r != 0) {
|
|
|
|
printf("em%d: em_dma_malloc: bus_dmammem_alloc failed; "
|
2003-05-06 03:55:12 +00:00
|
|
|
"size %ju, error %d\n", adapter->unit,
|
|
|
|
(uintmax_t)size, r);
|
2003-05-02 21:17:08 +00:00
|
|
|
goto fail_2;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
|
|
|
|
size,
|
|
|
|
em_dmamap_cb,
|
|
|
|
&dma->dma_paddr,
|
|
|
|
mapflags | BUS_DMA_NOWAIT);
|
|
|
|
if (r != 0) {
|
|
|
|
printf("em%d: em_dma_malloc: bus_dmamap_load failed; "
|
|
|
|
"error %u\n", adapter->unit, r);
|
|
|
|
goto fail_3;
|
|
|
|
}
|
|
|
|
|
|
|
|
dma->dma_size = size;
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
fail_3:
|
|
|
|
bus_dmamap_unload(dma->dma_tag, dma->dma_map);
|
|
|
|
fail_2:
|
|
|
|
bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
|
|
|
|
fail_1:
|
|
|
|
bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
|
|
|
|
bus_dma_tag_destroy(dma->dma_tag);
|
|
|
|
fail_0:
|
|
|
|
dma->dma_map = NULL;
|
|
|
|
dma->dma_tag = NULL;
|
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
em_dma_free(struct adapter *adapter, struct em_dma_alloc *dma)
|
|
|
|
{
|
|
|
|
bus_dmamap_unload(dma->dma_tag, dma->dma_map);
|
|
|
|
bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
|
|
|
|
bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
|
|
|
|
bus_dma_tag_destroy(dma->dma_tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Allocate memory for tx_buffer structures. The tx_buffer stores all
|
|
|
|
* the information needed to transmit a packet on the wire.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static int
|
2002-04-06 00:36:53 +00:00
|
|
|
em_allocate_transmit_structures(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
if (!(adapter->tx_buffer_area =
|
2002-12-23 19:11:23 +00:00
|
|
|
(struct em_buffer *) malloc(sizeof(struct em_buffer) *
|
2002-06-03 22:30:51 +00:00
|
|
|
adapter->num_tx_desc, M_DEVBUF,
|
|
|
|
M_NOWAIT))) {
|
|
|
|
printf("em%d: Unable to allocate tx_buffer memory\n",
|
|
|
|
adapter->unit);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero(adapter->tx_buffer_area,
|
2002-12-23 19:11:23 +00:00
|
|
|
sizeof(struct em_buffer) * adapter->num_tx_desc);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
return 0;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Allocate and initialize transmit structures.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static int
|
2002-04-06 00:36:53 +00:00
|
|
|
em_setup_transmit_structures(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2003-05-02 21:17:08 +00:00
|
|
|
/*
|
|
|
|
* Setup DMA descriptor areas.
|
|
|
|
*/
|
|
|
|
if (bus_dma_tag_create(NULL, /* parent */
|
|
|
|
PAGE_SIZE, 0, /* alignment, bounds */
|
|
|
|
BUS_SPACE_MAXADDR, /* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
|
|
|
MCLBYTES * 8, /* maxsize */
|
|
|
|
EM_MAX_SCATTER, /* nsegments */
|
|
|
|
MCLBYTES * 8, /* maxsegsize */
|
|
|
|
BUS_DMA_ALLOCNOW, /* flags */
|
2003-07-01 15:52:06 +00:00
|
|
|
NULL, /* lockfunc */
|
|
|
|
NULL, /* lockarg */
|
2003-05-02 21:17:08 +00:00
|
|
|
&adapter->txtag)) {
|
|
|
|
printf("em%d: Unable to allocate TX DMA tag\n", adapter->unit);
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (em_allocate_transmit_structures(adapter))
|
|
|
|
return (ENOMEM);
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2002-12-23 19:11:23 +00:00
|
|
|
bzero((void *) adapter->tx_desc_base,
|
|
|
|
(sizeof(struct em_tx_desc)) * adapter->num_tx_desc);
|
2003-05-02 21:17:08 +00:00
|
|
|
|
2002-12-23 19:11:23 +00:00
|
|
|
adapter->next_avail_tx_desc = 0;
|
2003-05-02 21:17:08 +00:00
|
|
|
adapter->oldest_used_tx_desc = 0;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
/* Set number of descriptors available */
|
|
|
|
adapter->num_tx_desc_avail = adapter->num_tx_desc;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
/* Set checksum context */
|
|
|
|
adapter->active_checksum_context = OFFLOAD_NONE;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
return (0);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Enable transmit unit.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_initialize_transmit_unit(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
u_int32_t reg_tctl;
|
|
|
|
u_int32_t reg_tipg = 0;
|
2003-05-03 07:35:47 +00:00
|
|
|
u_int64_t bus_addr;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-08-27 21:52:37 +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 */
|
2003-05-03 07:35:47 +00:00
|
|
|
bus_addr = adapter->txdma.dma_paddr;
|
|
|
|
E1000_WRITE_REG(&adapter->hw, TDBAL, (u_int32_t)bus_addr);
|
|
|
|
E1000_WRITE_REG(&adapter->hw, TDBAH, (u_int32_t)(bus_addr >> 32));
|
2002-06-03 22:30:51 +00:00
|
|
|
E1000_WRITE_REG(&adapter->hw, TDLEN,
|
|
|
|
adapter->num_tx_desc *
|
|
|
|
sizeof(struct em_tx_desc));
|
|
|
|
|
|
|
|
/* Setup the HW Tx Head and Tail descriptor pointers */
|
|
|
|
E1000_WRITE_REG(&adapter->hw, TDH, 0);
|
|
|
|
E1000_WRITE_REG(&adapter->hw, TDT, 0);
|
|
|
|
|
|
|
|
|
|
|
|
HW_DEBUGOUT2("Base = %x, Length = %x\n",
|
|
|
|
E1000_READ_REG(&adapter->hw, TDBAL),
|
|
|
|
E1000_READ_REG(&adapter->hw, TDLEN));
|
|
|
|
|
|
|
|
/* Set the default values for the Tx Inter Packet Gap timer */
|
|
|
|
switch (adapter->hw.mac_type) {
|
|
|
|
case em_82542_rev2_0:
|
2003-06-05 17:51:38 +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;
|
|
|
|
default:
|
|
|
|
if (adapter->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;
|
|
|
|
}
|
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
E1000_WRITE_REG(&adapter->hw, TIPG, reg_tipg);
|
2003-08-01 17:33:59 +00:00
|
|
|
E1000_WRITE_REG(&adapter->hw, TIDV, adapter->tx_int_delay.value);
|
2002-12-23 19:11:23 +00:00
|
|
|
if(adapter->hw.mac_type >= em_82540)
|
2003-08-01 17:33:59 +00:00
|
|
|
E1000_WRITE_REG(&adapter->hw, TADV,
|
|
|
|
adapter->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);
|
|
|
|
if (adapter->link_duplex == 1) {
|
|
|
|
reg_tctl |= E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT;
|
|
|
|
} else {
|
|
|
|
reg_tctl |= E1000_HDX_COLLISION_DISTANCE << E1000_COLD_SHIFT;
|
|
|
|
}
|
|
|
|
E1000_WRITE_REG(&adapter->hw, TCTL, reg_tctl);
|
|
|
|
|
|
|
|
/* Setup Transmit Descriptor Settings for this adapter */
|
2003-03-21 21:47:31 +00:00
|
|
|
adapter->txd_cmd = E1000_TXD_CMD_IFCS | E1000_TXD_CMD_RS;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-08-01 17:33:59 +00:00
|
|
|
if (adapter->tx_int_delay.value > 0)
|
2002-06-03 22:30:51 +00:00
|
|
|
adapter->txd_cmd |= E1000_TXD_CMD_IDE;
|
|
|
|
|
|
|
|
return;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Free all transmit related data structures.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_free_transmit_structures(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2003-05-02 21:17:08 +00:00
|
|
|
struct em_buffer *tx_buffer;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
INIT_DEBUGOUT("free_transmit_structures: begin");
|
|
|
|
|
|
|
|
if (adapter->tx_buffer_area != NULL) {
|
|
|
|
tx_buffer = adapter->tx_buffer_area;
|
|
|
|
for (i = 0; i < adapter->num_tx_desc; i++, tx_buffer++) {
|
|
|
|
if (tx_buffer->m_head != NULL) {
|
|
|
|
bus_dmamap_unload(adapter->txtag, tx_buffer->map);
|
|
|
|
bus_dmamap_destroy(adapter->txtag, tx_buffer->map);
|
|
|
|
m_freem(tx_buffer->m_head);
|
|
|
|
}
|
|
|
|
tx_buffer->m_head = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (adapter->tx_buffer_area != NULL) {
|
|
|
|
free(adapter->tx_buffer_area, M_DEVBUF);
|
|
|
|
adapter->tx_buffer_area = NULL;
|
|
|
|
}
|
|
|
|
if (adapter->txtag != NULL) {
|
|
|
|
bus_dma_tag_destroy(adapter->txtag);
|
|
|
|
adapter->txtag = NULL;
|
|
|
|
}
|
|
|
|
return;
|
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
|
2002-12-23 19:11:23 +00:00
|
|
|
em_transmit_checksum_setup(struct adapter * adapter,
|
2002-06-03 22:30:51 +00:00
|
|
|
struct mbuf *mp,
|
|
|
|
u_int32_t *txd_upper,
|
|
|
|
u_int32_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;
|
|
|
|
if (adapter->active_checksum_context == OFFLOAD_TCP_IP)
|
2002-08-26 18:59:16 +00:00
|
|
|
return;
|
2002-06-03 22:30:51 +00:00
|
|
|
else
|
|
|
|
adapter->active_checksum_context = OFFLOAD_TCP_IP;
|
|
|
|
|
|
|
|
} 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;
|
|
|
|
if (adapter->active_checksum_context == OFFLOAD_UDP_IP)
|
2002-08-26 18:59:16 +00:00
|
|
|
return;
|
2002-06-03 22:30:51 +00:00
|
|
|
else
|
|
|
|
adapter->active_checksum_context = OFFLOAD_UDP_IP;
|
|
|
|
} 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.
|
|
|
|
*/
|
2002-12-23 19:11:23 +00:00
|
|
|
curr_txd = adapter->next_avail_tx_desc;
|
|
|
|
tx_buffer = &adapter->tx_buffer_area[curr_txd];
|
|
|
|
TXD = (struct em_context_desc *) &adapter->tx_desc_base[curr_txd];
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
TXD->lower_setup.ip_fields.ipcss = ETHER_HDR_LEN;
|
|
|
|
TXD->lower_setup.ip_fields.ipcso =
|
2002-12-23 19:11:23 +00:00
|
|
|
ETHER_HDR_LEN + offsetof(struct ip, ip_sum);
|
2002-06-03 22:30:51 +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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
if (adapter->active_checksum_context == OFFLOAD_TCP_IP) {
|
|
|
|
TXD->upper_setup.tcp_fields.tucso =
|
2002-12-23 19:11:23 +00:00
|
|
|
ETHER_HDR_LEN + sizeof(struct ip) +
|
|
|
|
offsetof(struct tcphdr, th_sum);
|
2002-06-03 22:30:51 +00:00
|
|
|
} else if (adapter->active_checksum_context == OFFLOAD_UDP_IP) {
|
|
|
|
TXD->upper_setup.tcp_fields.tucso =
|
2002-12-23 19:11:23 +00:00
|
|
|
ETHER_HDR_LEN + sizeof(struct ip) +
|
|
|
|
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);
|
|
|
|
TXD->cmd_and_length = htole32(adapter->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;
|
|
|
|
|
|
|
|
if (++curr_txd == adapter->num_tx_desc)
|
|
|
|
curr_txd = 0;
|
2002-08-26 18:59:16 +00:00
|
|
|
|
|
|
|
adapter->num_tx_desc_avail--;
|
2002-12-23 19:11:23 +00:00
|
|
|
adapter->next_avail_tx_desc = curr_txd;
|
2002-08-26 18:59:16 +00:00
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
em_clean_transmit_interrupts(struct adapter * adapter)
|
|
|
|
{
|
2002-12-23 19:11:23 +00:00
|
|
|
int i, num_avail;
|
2003-05-02 21:17:08 +00:00
|
|
|
struct em_buffer *tx_buffer;
|
|
|
|
struct em_tx_desc *tx_desc;
|
2003-06-05 17:51:38 +00:00
|
|
|
struct ifnet *ifp = &adapter->interface_data.ac_if;
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2003-09-23 00:18:25 +00:00
|
|
|
mtx_assert(&adapter->mtx, MA_OWNED);
|
|
|
|
|
2002-12-23 19:11:23 +00:00
|
|
|
if (adapter->num_tx_desc_avail == adapter->num_tx_desc)
|
|
|
|
return;
|
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
#ifdef DBG_STATS
|
2002-12-23 19:11:23 +00:00
|
|
|
adapter->clean_tx_interrupts++;
|
2002-11-08 18:14:17 +00:00
|
|
|
#endif
|
2003-05-02 21:17:08 +00:00
|
|
|
num_avail = adapter->num_tx_desc_avail;
|
|
|
|
i = adapter->oldest_used_tx_desc;
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
tx_buffer = &adapter->tx_buffer_area[i];
|
|
|
|
tx_desc = &adapter->tx_desc_base[i];
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
while (tx_desc->upper.fields.status & E1000_TXD_STAT_DD) {
|
|
|
|
|
|
|
|
tx_desc->upper.data = 0;
|
|
|
|
num_avail++;
|
|
|
|
|
|
|
|
if (tx_buffer->m_head) {
|
2003-06-05 17:51:38 +00:00
|
|
|
ifp->if_opackets++;
|
2003-05-02 21:17:08 +00:00
|
|
|
bus_dmamap_sync(adapter->txtag, tx_buffer->map,
|
|
|
|
BUS_DMASYNC_POSTWRITE);
|
|
|
|
bus_dmamap_unload(adapter->txtag, tx_buffer->map);
|
|
|
|
bus_dmamap_destroy(adapter->txtag, tx_buffer->map);
|
|
|
|
|
|
|
|
m_freem(tx_buffer->m_head);
|
|
|
|
tx_buffer->m_head = NULL;
|
|
|
|
}
|
2002-11-08 18:14:17 +00:00
|
|
|
|
2002-12-23 19:11:23 +00:00
|
|
|
if (++i == adapter->num_tx_desc)
|
|
|
|
i = 0;
|
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
tx_buffer = &adapter->tx_buffer_area[i];
|
|
|
|
tx_desc = &adapter->tx_desc_base[i];
|
2002-12-23 19:11:23 +00:00
|
|
|
}
|
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
adapter->oldest_used_tx_desc = i;
|
2002-12-23 19:11:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have enough room, clear IFF_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.
|
|
|
|
*/
|
2003-06-05 17:51:38 +00:00
|
|
|
if (num_avail > EM_TX_CLEANUP_THRESHOLD) {
|
2002-12-23 19:11:23 +00:00
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
if (num_avail == adapter->num_tx_desc)
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
else if (num_avail == adapter->num_tx_desc_avail)
|
|
|
|
ifp->if_timer = EM_TX_TIMEOUT;
|
|
|
|
}
|
|
|
|
adapter->num_tx_desc_avail = num_avail;
|
|
|
|
return;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Get a buffer from system mbuf buffer pool.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static int
|
2002-12-23 19:11:23 +00:00
|
|
|
em_get_buf(int i, struct adapter *adapter,
|
2003-05-02 21:17:08 +00:00
|
|
|
struct mbuf *nmp)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2003-05-02 21:17:08 +00:00
|
|
|
register struct mbuf *mp = nmp;
|
|
|
|
struct em_buffer *rx_buffer;
|
|
|
|
struct ifnet *ifp;
|
2003-05-03 07:35:47 +00:00
|
|
|
bus_addr_t paddr;
|
2003-05-02 21:17:08 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
ifp = &adapter->interface_data.ac_if;
|
|
|
|
|
|
|
|
if (mp == NULL) {
|
|
|
|
mp = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
|
|
|
|
if (mp == NULL) {
|
|
|
|
adapter->mbuf_cluster_failed++;
|
|
|
|
return(ENOBUFS);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
if (ifp->if_mtu <= ETHERMTU) {
|
|
|
|
m_adj(mp, ETHER_ALIGN);
|
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
rx_buffer = &adapter->rx_buffer_area[i];
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
/*
|
|
|
|
* Using memory from the mbuf cluster pool, invoke the
|
|
|
|
* bus_dma machinery to arrange the memory mapping.
|
|
|
|
*/
|
|
|
|
error = bus_dmamap_load(adapter->rxtag, rx_buffer->map,
|
|
|
|
mtod(mp, void *), mp->m_len,
|
|
|
|
em_dmamap_cb, &paddr, 0);
|
|
|
|
if (error) {
|
|
|
|
m_free(mp);
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
rx_buffer->m_head = mp;
|
|
|
|
adapter->rx_desc_base[i].buffer_addr = htole64(paddr);
|
|
|
|
bus_dmamap_sync(adapter->rxtag, rx_buffer->map, BUS_DMASYNC_PREREAD);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
return(0);
|
2001-12-02 07:37:17 +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
|
|
|
|
* that we've allocated.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static int
|
2002-04-06 00:36:53 +00:00
|
|
|
em_allocate_receive_structures(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2003-05-02 21:17:08 +00:00
|
|
|
int i, error;
|
|
|
|
struct em_buffer *rx_buffer;
|
|
|
|
|
|
|
|
if (!(adapter->rx_buffer_area =
|
|
|
|
(struct em_buffer *) malloc(sizeof(struct em_buffer) *
|
|
|
|
adapter->num_rx_desc, M_DEVBUF,
|
|
|
|
M_NOWAIT))) {
|
|
|
|
printf("em%d: Unable to allocate rx_buffer memory\n",
|
|
|
|
adapter->unit);
|
|
|
|
return(ENOMEM);
|
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
bzero(adapter->rx_buffer_area,
|
|
|
|
sizeof(struct em_buffer) * adapter->num_rx_desc);
|
|
|
|
|
|
|
|
error = bus_dma_tag_create(NULL, /* parent */
|
|
|
|
PAGE_SIZE, 0, /* alignment, bounds */
|
|
|
|
BUS_SPACE_MAXADDR, /* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
|
|
|
MCLBYTES, /* maxsize */
|
|
|
|
1, /* nsegments */
|
|
|
|
MCLBYTES, /* maxsegsize */
|
|
|
|
BUS_DMA_ALLOCNOW, /* flags */
|
2003-07-01 15:52:06 +00:00
|
|
|
NULL, /* lockfunc */
|
|
|
|
NULL, /* lockarg */
|
2003-05-02 21:17:08 +00:00
|
|
|
&adapter->rxtag);
|
|
|
|
if (error != 0) {
|
|
|
|
printf("em%d: em_allocate_receive_structures: "
|
|
|
|
"bus_dma_tag_create failed; error %u\n",
|
|
|
|
adapter->unit, error);
|
|
|
|
goto fail_0;
|
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
rx_buffer = adapter->rx_buffer_area;
|
|
|
|
for (i = 0; i < adapter->num_rx_desc; i++, rx_buffer++) {
|
|
|
|
error = bus_dmamap_create(adapter->rxtag, BUS_DMA_NOWAIT,
|
|
|
|
&rx_buffer->map);
|
|
|
|
if (error != 0) {
|
|
|
|
printf("em%d: em_allocate_receive_structures: "
|
|
|
|
"bus_dmamap_create failed; error %u\n",
|
|
|
|
adapter->unit, error);
|
|
|
|
goto fail_1;
|
|
|
|
}
|
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
for (i = 0; i < adapter->num_rx_desc; i++) {
|
|
|
|
error = em_get_buf(i, adapter, NULL);
|
|
|
|
if (error != 0) {
|
|
|
|
adapter->rx_buffer_area[i].m_head = NULL;
|
|
|
|
adapter->rx_desc_base[i].buffer_addr = 0;
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
return(0);
|
|
|
|
|
|
|
|
fail_1:
|
|
|
|
bus_dma_tag_destroy(adapter->rxtag);
|
|
|
|
fail_0:
|
|
|
|
adapter->rxtag = NULL;
|
|
|
|
free(adapter->rx_buffer_area, M_DEVBUF);
|
|
|
|
adapter->rx_buffer_area = NULL;
|
|
|
|
return (error);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Allocate and initialize receive structures.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static int
|
2002-04-06 00:36:53 +00:00
|
|
|
em_setup_receive_structures(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-12-23 19:11:23 +00:00
|
|
|
bzero((void *) adapter->rx_desc_base,
|
|
|
|
(sizeof(struct em_rx_desc)) * adapter->num_rx_desc);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
if (em_allocate_receive_structures(adapter))
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
/* Setup our descriptor pointers */
|
2002-12-23 19:11:23 +00:00
|
|
|
adapter->next_rx_desc_to_check = 0;
|
2002-06-03 22:30:51 +00:00
|
|
|
return(0);
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Enable receive unit.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_initialize_receive_unit(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
u_int32_t reg_rctl;
|
|
|
|
u_int32_t reg_rxcsum;
|
|
|
|
struct ifnet *ifp;
|
2003-05-03 07:35:47 +00:00
|
|
|
u_int64_t bus_addr;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-08-27 21:52:37 +00:00
|
|
|
INIT_DEBUGOUT("em_initialize_receive_unit: begin");
|
2002-06-03 22:30:51 +00:00
|
|
|
ifp = &adapter->interface_data.ac_if;
|
|
|
|
|
|
|
|
/* Make sure receives are disabled while setting up the descriptor ring */
|
|
|
|
E1000_WRITE_REG(&adapter->hw, RCTL, 0);
|
|
|
|
|
|
|
|
/* Set the Receive Delay Timer Register */
|
|
|
|
E1000_WRITE_REG(&adapter->hw, RDTR,
|
2003-08-01 17:33:59 +00:00
|
|
|
adapter->rx_int_delay.value | E1000_RDT_FPDB);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2002-12-23 19:11:23 +00:00
|
|
|
if(adapter->hw.mac_type >= em_82540) {
|
2003-08-01 17:33:59 +00:00
|
|
|
E1000_WRITE_REG(&adapter->hw, RADV,
|
|
|
|
adapter->rx_abs_int_delay.value);
|
2002-12-23 19:11:23 +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(&adapter->hw, ITR, DEFAULT_ITR);
|
|
|
|
}
|
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
/* Setup the Base and Length of the Rx Descriptor Ring */
|
2003-05-03 07:35:47 +00:00
|
|
|
bus_addr = adapter->rxdma.dma_paddr;
|
|
|
|
E1000_WRITE_REG(&adapter->hw, RDBAL, (u_int32_t)bus_addr);
|
|
|
|
E1000_WRITE_REG(&adapter->hw, RDBAH, (u_int32_t)(bus_addr >> 32));
|
2002-06-03 22:30:51 +00:00
|
|
|
E1000_WRITE_REG(&adapter->hw, RDLEN, adapter->num_rx_desc *
|
|
|
|
sizeof(struct em_rx_desc));
|
|
|
|
|
|
|
|
/* Setup the HW Rx Head and Tail Descriptor Pointers */
|
|
|
|
E1000_WRITE_REG(&adapter->hw, RDH, 0);
|
2002-12-23 19:11:23 +00:00
|
|
|
E1000_WRITE_REG(&adapter->hw, RDT, adapter->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 |
|
|
|
|
(adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
|
|
|
|
|
|
|
|
if (adapter->hw.tbi_compatibility_on == TRUE)
|
|
|
|
reg_rctl |= E1000_RCTL_SBP;
|
|
|
|
|
|
|
|
|
|
|
|
switch (adapter->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;
|
|
|
|
break;
|
|
|
|
case EM_RXBUFFER_8192:
|
|
|
|
reg_rctl |= E1000_RCTL_SZ_8192 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
|
|
|
|
break;
|
|
|
|
case EM_RXBUFFER_16384:
|
|
|
|
reg_rctl |= E1000_RCTL_SZ_16384 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
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 */
|
|
|
|
if ((adapter->hw.mac_type >= em_82543) &&
|
|
|
|
(ifp->if_capenable & IFCAP_RXCSUM)) {
|
|
|
|
reg_rxcsum = E1000_READ_REG(&adapter->hw, RXCSUM);
|
|
|
|
reg_rxcsum |= (E1000_RXCSUM_IPOFL | E1000_RXCSUM_TUOFL);
|
|
|
|
E1000_WRITE_REG(&adapter->hw, RXCSUM, reg_rxcsum);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable Receives */
|
|
|
|
E1000_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
|
|
|
|
|
|
|
|
return;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Free receive related data structures.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2002-12-23 19:11:23 +00:00
|
|
|
em_free_receive_structures(struct adapter *adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2003-05-02 21:17:08 +00:00
|
|
|
struct em_buffer *rx_buffer;
|
|
|
|
int i;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
INIT_DEBUGOUT("free_receive_structures: begin");
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
if (adapter->rx_buffer_area != NULL) {
|
|
|
|
rx_buffer = adapter->rx_buffer_area;
|
|
|
|
for (i = 0; i < adapter->num_rx_desc; i++, rx_buffer++) {
|
|
|
|
if (rx_buffer->map != NULL) {
|
|
|
|
bus_dmamap_unload(adapter->rxtag, rx_buffer->map);
|
|
|
|
bus_dmamap_destroy(adapter->rxtag, rx_buffer->map);
|
|
|
|
}
|
|
|
|
if (rx_buffer->m_head != NULL)
|
|
|
|
m_freem(rx_buffer->m_head);
|
|
|
|
rx_buffer->m_head = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (adapter->rx_buffer_area != NULL) {
|
|
|
|
free(adapter->rx_buffer_area, M_DEVBUF);
|
|
|
|
adapter->rx_buffer_area = NULL;
|
|
|
|
}
|
|
|
|
if (adapter->rxtag != NULL) {
|
|
|
|
bus_dma_tag_destroy(adapter->rxtag);
|
|
|
|
adapter->rxtag = NULL;
|
|
|
|
}
|
|
|
|
return;
|
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
|
|
|
*********************************************************************/
|
|
|
|
static void
|
2002-11-25 19:56:16 +00:00
|
|
|
em_process_receive_interrupts(struct adapter * adapter, int count)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
struct ifnet *ifp;
|
2002-12-23 19:11:23 +00:00
|
|
|
struct mbuf *mp;
|
2003-03-21 21:47:31 +00:00
|
|
|
#if __FreeBSD_version < 500000
|
|
|
|
struct ether_header *eh;
|
2002-12-23 19:11:23 +00:00
|
|
|
#endif
|
2002-06-03 22:30:51 +00:00
|
|
|
u_int8_t accept_frame = 0;
|
2003-03-21 21:47:31 +00:00
|
|
|
u_int8_t eop = 0;
|
2003-11-14 18:02:25 +00:00
|
|
|
u_int16_t len, desc_len, prev_len_adj;
|
2002-12-23 19:11:23 +00:00
|
|
|
int i;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
/* Pointer to the receive descriptor being examined. */
|
|
|
|
struct em_rx_desc *current_desc;
|
|
|
|
|
2003-09-23 00:18:25 +00:00
|
|
|
mtx_assert(&adapter->mtx, MA_OWNED);
|
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
ifp = &adapter->interface_data.ac_if;
|
2002-12-23 19:11:23 +00:00
|
|
|
i = adapter->next_rx_desc_to_check;
|
|
|
|
current_desc = &adapter->rx_desc_base[i];
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
if (!((current_desc->status) & E1000_RXD_STAT_DD)) {
|
2001-12-02 07:37:17 +00:00
|
|
|
#ifdef DBG_STATS
|
2002-06-03 22:30:51 +00:00
|
|
|
adapter->no_pkts_avail++;
|
2001-12-02 07:37:17 +00:00
|
|
|
#endif
|
2002-06-03 22:30:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-11-25 19:56:16 +00:00
|
|
|
while ((current_desc->status & E1000_RXD_STAT_DD) && (count != 0)) {
|
2003-03-21 21:47:31 +00:00
|
|
|
|
2002-12-23 19:11:23 +00:00
|
|
|
mp = adapter->rx_buffer_area[i].m_head;
|
2003-05-02 21:17:08 +00:00
|
|
|
bus_dmamap_sync(adapter->rxtag, adapter->rx_buffer_area[i].map,
|
|
|
|
BUS_DMASYNC_POSTREAD);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
accept_frame = 1;
|
2003-11-14 18:02:25 +00:00
|
|
|
prev_len_adj = 0;
|
2003-05-02 21:17:08 +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) {
|
|
|
|
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) {
|
2002-12-23 19:11:23 +00:00
|
|
|
u_int8_t last_byte;
|
2003-05-02 21:17:08 +00:00
|
|
|
u_int32_t pkt_len = desc_len;
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2002-12-23 19:11:23 +00:00
|
|
|
if (adapter->fmp != NULL)
|
2002-06-03 22:30:51 +00:00
|
|
|
pkt_len += adapter->fmp->m_pkthdr.len;
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2003-05-02 21:17:08 +00:00
|
|
|
last_byte = *(mtod(mp, caddr_t) + desc_len - 1);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
if (TBI_ACCEPT(&adapter->hw, current_desc->status,
|
|
|
|
current_desc->errors,
|
|
|
|
pkt_len, last_byte)) {
|
|
|
|
em_tbi_adjust_stats(&adapter->hw,
|
|
|
|
&adapter->stats,
|
|
|
|
pkt_len,
|
|
|
|
adapter->hw.mac_addr);
|
2003-11-14 18:02:25 +00:00
|
|
|
if (len > 0) len--;
|
2002-12-23 19:11:23 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-06-03 22:30:51 +00:00
|
|
|
accept_frame = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (accept_frame) {
|
|
|
|
|
2002-12-23 19:11:23 +00:00
|
|
|
if (em_get_buf(i, adapter, NULL) == ENOBUFS) {
|
2002-06-03 22:30:51 +00:00
|
|
|
adapter->dropped_pkts++;
|
2002-12-23 19:11:23 +00:00
|
|
|
em_get_buf(i, adapter, mp);
|
|
|
|
if (adapter->fmp != NULL)
|
|
|
|
m_freem(adapter->fmp);
|
2002-06-03 22:30:51 +00:00
|
|
|
adapter->fmp = NULL;
|
|
|
|
adapter->lmp = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Assign correct length to the current fragment */
|
|
|
|
mp->m_len = len;
|
|
|
|
|
|
|
|
if (adapter->fmp == NULL) {
|
|
|
|
mp->m_pkthdr.len = len;
|
|
|
|
adapter->fmp = mp; /* Store the first mbuf */
|
|
|
|
adapter->lmp = mp;
|
|
|
|
} else {
|
|
|
|
/* Chain mbuf's together */
|
|
|
|
mp->m_flags &= ~M_PKTHDR;
|
2003-11-14 18:02:25 +00:00
|
|
|
/*
|
|
|
|
* Adjust length of previous mbuf in chain if we
|
|
|
|
* received less than 4 bytes in the last descriptor.
|
|
|
|
*/
|
|
|
|
if (prev_len_adj > 0) {
|
|
|
|
adapter->lmp->m_len -= prev_len_adj;
|
|
|
|
adapter->fmp->m_pkthdr.len -= prev_len_adj;
|
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
adapter->lmp->m_next = mp;
|
|
|
|
adapter->lmp = adapter->lmp->m_next;
|
|
|
|
adapter->fmp->m_pkthdr.len += len;
|
|
|
|
}
|
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
if (eop) {
|
|
|
|
adapter->fmp->m_pkthdr.rcvif = ifp;
|
2003-06-05 17:51:38 +00:00
|
|
|
ifp->if_ipackets++;
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
#if __FreeBSD_version < 500000
|
|
|
|
eh = mtod(adapter->fmp, struct ether_header *);
|
|
|
|
/* Remove ethernet header from mbuf */
|
|
|
|
m_adj(adapter->fmp, sizeof(struct ether_header));
|
|
|
|
em_receive_checksum(adapter, current_desc,
|
|
|
|
adapter->fmp);
|
|
|
|
if (current_desc->status & E1000_RXD_STAT_VP)
|
|
|
|
VLAN_INPUT_TAG(eh, adapter->fmp,
|
|
|
|
(current_desc->special &
|
2002-12-23 19:11:23 +00:00
|
|
|
E1000_RXD_SPC_VLAN_MASK));
|
2003-03-21 21:47:31 +00:00
|
|
|
else
|
|
|
|
ether_input(ifp, eh, adapter->fmp);
|
2002-12-23 19:11:23 +00:00
|
|
|
#else
|
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
em_receive_checksum(adapter, current_desc,
|
|
|
|
adapter->fmp);
|
|
|
|
if (current_desc->status & E1000_RXD_STAT_VP)
|
|
|
|
VLAN_INPUT_TAG(ifp, adapter->fmp,
|
|
|
|
(current_desc->special &
|
|
|
|
E1000_RXD_SPC_VLAN_MASK),
|
2002-12-23 19:11:23 +00:00
|
|
|
adapter->fmp = NULL);
|
2003-03-21 21:47:31 +00:00
|
|
|
|
2003-09-23 00:18:25 +00:00
|
|
|
if (adapter->fmp != NULL) {
|
|
|
|
EM_UNLOCK(adapter);
|
2003-03-21 21:47:31 +00:00
|
|
|
(*ifp->if_input)(ifp, adapter->fmp);
|
2003-09-23 00:18:25 +00:00
|
|
|
EM_LOCK(adapter);
|
|
|
|
}
|
2002-12-23 19:11:23 +00:00
|
|
|
#endif
|
2003-03-21 21:47:31 +00:00
|
|
|
adapter->fmp = NULL;
|
|
|
|
adapter->lmp = NULL;
|
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
} else {
|
|
|
|
adapter->dropped_pkts++;
|
2002-12-23 19:11:23 +00:00
|
|
|
em_get_buf(i, adapter, mp);
|
|
|
|
if (adapter->fmp != NULL)
|
|
|
|
m_freem(adapter->fmp);
|
2002-06-03 22:30:51 +00:00
|
|
|
adapter->fmp = NULL;
|
|
|
|
adapter->lmp = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Zero out the receive descriptors status */
|
|
|
|
current_desc->status = 0;
|
2002-12-23 19:11:23 +00:00
|
|
|
|
2002-08-26 18:59:16 +00:00
|
|
|
/* Advance the E1000's Receive Queue #0 "Tail Pointer". */
|
2002-12-23 19:11:23 +00:00
|
|
|
E1000_WRITE_REG(&adapter->hw, RDT, i);
|
|
|
|
|
|
|
|
/* Advance our pointers to the next descriptor */
|
|
|
|
if (++i == adapter->num_rx_desc) {
|
|
|
|
i = 0;
|
|
|
|
current_desc = adapter->rx_desc_base;
|
|
|
|
} else
|
|
|
|
current_desc++;
|
2002-06-03 22:30:51 +00:00
|
|
|
}
|
2002-12-23 19:11:23 +00:00
|
|
|
adapter->next_rx_desc_to_check = i;
|
2002-06-03 22:30:51 +00:00
|
|
|
return;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Verify that the hardware indicated that the checksum is valid.
|
|
|
|
* Inform the stack about the status of checksum so that stack
|
|
|
|
* doesn't spend time verifying the checksum.
|
|
|
|
*
|
|
|
|
*********************************************************************/
|
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_receive_checksum(struct adapter *adapter,
|
2002-06-03 22:30:51 +00:00
|
|
|
struct em_rx_desc *rx_desc,
|
|
|
|
struct mbuf *mp)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
/* 82543 or newer only */
|
|
|
|
if ((adapter->hw.mac_type < em_82543) ||
|
|
|
|
/* 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) {
|
|
|
|
/* Did it pass? */
|
|
|
|
if (!(rx_desc->errors & E1000_RXD_ERR_TCPE)) {
|
|
|
|
mp->m_pkthdr.csum_flags |=
|
|
|
|
(CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
|
|
|
|
mp->m_pkthdr.csum_data = htons(0xffff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-23 19:11:23 +00:00
|
|
|
static void
|
|
|
|
em_enable_vlans(struct adapter *adapter)
|
2002-06-03 22:30:51 +00:00
|
|
|
{
|
|
|
|
uint32_t ctrl;
|
|
|
|
|
2003-03-21 21:47:31 +00:00
|
|
|
E1000_WRITE_REG(&adapter->hw, VET, ETHERTYPE_VLAN);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
|
|
|
ctrl = E1000_READ_REG(&adapter->hw, CTRL);
|
|
|
|
ctrl |= E1000_CTRL_VME;
|
|
|
|
E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
static void
|
2002-04-06 00:36:53 +00:00
|
|
|
em_enable_intr(struct adapter * adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
E1000_WRITE_REG(&adapter->hw, IMS, (IMS_ENABLE_MASK));
|
|
|
|
return;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-06-03 22:30:51 +00:00
|
|
|
em_disable_intr(struct adapter *adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
E1000_WRITE_REG(&adapter->hw, IMC,
|
|
|
|
(0xffffffff & ~E1000_IMC_RXSEQ));
|
|
|
|
return;
|
2001-12-02 07:37:17 +00:00
|
|
|
}
|
|
|
|
|
2003-06-05 17:51:38 +00:00
|
|
|
static int
|
|
|
|
em_is_valid_ether_addr(u_int8_t *addr)
|
|
|
|
{
|
|
|
|
char zero_addr[6] = { 0, 0, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
if ((addr[0] & 1) || (!bcmp(addr, zero_addr, ETHER_ADDR_LEN))) {
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
void
|
|
|
|
em_write_pci_cfg(struct em_hw *hw,
|
2002-12-23 19:11:23 +00:00
|
|
|
uint32_t reg,
|
|
|
|
uint16_t *value)
|
2002-02-13 18:19:27 +00:00
|
|
|
{
|
2002-07-16 16:55:03 +00:00
|
|
|
pci_write_config(((struct em_osdep *)hw->back)->dev, reg,
|
2002-06-03 22:30:51 +00:00
|
|
|
*value, 2);
|
2002-02-13 18:19:27 +00:00
|
|
|
}
|
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
void
|
|
|
|
em_read_pci_cfg(struct em_hw *hw, uint32_t reg,
|
2002-12-23 19:11:23 +00:00
|
|
|
uint16_t *value)
|
2002-07-16 16:55:03 +00:00
|
|
|
{
|
|
|
|
*value = pci_read_config(((struct em_osdep *)hw->back)->dev,
|
|
|
|
reg, 2);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
void
|
|
|
|
em_pci_set_mwi(struct em_hw *hw)
|
|
|
|
{
|
2002-12-23 19:11:23 +00:00
|
|
|
pci_write_config(((struct em_osdep *)hw->back)->dev,
|
|
|
|
PCIR_COMMAND,
|
|
|
|
(hw->pci_cmd_word | CMD_MEM_WRT_INVALIDATE), 2);
|
|
|
|
return;
|
2002-11-08 18:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
em_pci_clear_mwi(struct em_hw *hw)
|
|
|
|
{
|
2002-12-23 19:11:23 +00:00
|
|
|
pci_write_config(((struct em_osdep *)hw->back)->dev,
|
|
|
|
PCIR_COMMAND,
|
|
|
|
(hw->pci_cmd_word & ~CMD_MEM_WRT_INVALIDATE), 2);
|
|
|
|
return;
|
2002-11-08 18:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2004-02-10 21:31:09 +00:00
|
|
|
em_io_read(struct em_hw *hw, unsigned long port)
|
2002-07-16 16:55:03 +00:00
|
|
|
{
|
|
|
|
return(inl(port));
|
|
|
|
}
|
|
|
|
|
2002-11-08 18:14:17 +00:00
|
|
|
void
|
2004-02-10 21:31:09 +00:00
|
|
|
em_io_write(struct em_hw *hw, unsigned long port, uint32_t value)
|
2002-07-16 16:55:03 +00:00
|
|
|
{
|
|
|
|
outl(port, value);
|
|
|
|
return;
|
2003-03-21 21:47:31 +00:00
|
|
|
}
|
2001-12-02 07:37: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...
|
|
|
|
* SIZE[3:0] + ADDR[2:0] = SUM[3:0].
|
|
|
|
* If SUM[3:0] is in between 1 to 4, we will have this issue.
|
|
|
|
*
|
|
|
|
* 2. DAC issue.
|
|
|
|
* To detect this issue, following equation can be used...
|
|
|
|
* SIZE[3:0] + ADDR[2:0] = SUM[3:0].
|
|
|
|
* If SUM[3:0] is in between 9 to c, we will have this issue.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* WORKAROUND:
|
|
|
|
* Make sure we do not have ending address as 1,2,3,4(Hang) or 9,a,b,c (DAC)
|
|
|
|
*
|
|
|
|
*** *********************************************************************/
|
|
|
|
static u_int32_t
|
|
|
|
em_fill_descriptors (u_int64_t address,
|
|
|
|
u_int32_t length,
|
|
|
|
PDESC_ARRAY desc_array)
|
|
|
|
{
|
|
|
|
/* Since issue is sensitive to length and address.*/
|
|
|
|
/* Let us first check the address...*/
|
|
|
|
u_int32_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 = (u_int32_t)((((u_int32_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;
|
|
|
|
}
|
|
|
|
|
2001-12-02 07:37:17 +00:00
|
|
|
/**********************************************************************
|
|
|
|
*
|
|
|
|
* Update the board statistics counters.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2002-06-03 22:30:51 +00:00
|
|
|
em_update_stats_counters(struct adapter *adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2002-06-03 22:30:51 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
|
2003-08-27 21:52:37 +00:00
|
|
|
if(adapter->hw.media_type == em_media_type_copper ||
|
|
|
|
(E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU)) {
|
|
|
|
adapter->stats.symerrs += E1000_READ_REG(&adapter->hw, SYMERRS);
|
|
|
|
adapter->stats.sec += E1000_READ_REG(&adapter->hw, SEC);
|
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
adapter->stats.crcerrs += E1000_READ_REG(&adapter->hw, CRCERRS);
|
|
|
|
adapter->stats.mpc += E1000_READ_REG(&adapter->hw, MPC);
|
|
|
|
adapter->stats.scc += E1000_READ_REG(&adapter->hw, SCC);
|
|
|
|
adapter->stats.ecol += E1000_READ_REG(&adapter->hw, ECOL);
|
2003-03-21 21:47:31 +00:00
|
|
|
|
2002-06-03 22:30:51 +00:00
|
|
|
adapter->stats.mcc += E1000_READ_REG(&adapter->hw, MCC);
|
|
|
|
adapter->stats.latecol += E1000_READ_REG(&adapter->hw, LATECOL);
|
|
|
|
adapter->stats.colc += E1000_READ_REG(&adapter->hw, COLC);
|
|
|
|
adapter->stats.dc += E1000_READ_REG(&adapter->hw, DC);
|
|
|
|
adapter->stats.rlec += E1000_READ_REG(&adapter->hw, RLEC);
|
|
|
|
adapter->stats.xonrxc += E1000_READ_REG(&adapter->hw, XONRXC);
|
|
|
|
adapter->stats.xontxc += E1000_READ_REG(&adapter->hw, XONTXC);
|
|
|
|
adapter->stats.xoffrxc += E1000_READ_REG(&adapter->hw, XOFFRXC);
|
|
|
|
adapter->stats.xofftxc += E1000_READ_REG(&adapter->hw, XOFFTXC);
|
|
|
|
adapter->stats.fcruc += E1000_READ_REG(&adapter->hw, FCRUC);
|
|
|
|
adapter->stats.prc64 += E1000_READ_REG(&adapter->hw, PRC64);
|
|
|
|
adapter->stats.prc127 += E1000_READ_REG(&adapter->hw, PRC127);
|
|
|
|
adapter->stats.prc255 += E1000_READ_REG(&adapter->hw, PRC255);
|
|
|
|
adapter->stats.prc511 += E1000_READ_REG(&adapter->hw, PRC511);
|
|
|
|
adapter->stats.prc1023 += E1000_READ_REG(&adapter->hw, PRC1023);
|
|
|
|
adapter->stats.prc1522 += E1000_READ_REG(&adapter->hw, PRC1522);
|
|
|
|
adapter->stats.gprc += E1000_READ_REG(&adapter->hw, GPRC);
|
|
|
|
adapter->stats.bprc += E1000_READ_REG(&adapter->hw, BPRC);
|
|
|
|
adapter->stats.mprc += E1000_READ_REG(&adapter->hw, MPRC);
|
|
|
|
adapter->stats.gptc += E1000_READ_REG(&adapter->hw, GPTC);
|
|
|
|
|
|
|
|
/* For the 64-bit byte counters the low dword must be read first. */
|
|
|
|
/* Both registers clear on the read of the high dword */
|
|
|
|
|
|
|
|
adapter->stats.gorcl += E1000_READ_REG(&adapter->hw, GORCL);
|
|
|
|
adapter->stats.gorch += E1000_READ_REG(&adapter->hw, GORCH);
|
|
|
|
adapter->stats.gotcl += E1000_READ_REG(&adapter->hw, GOTCL);
|
|
|
|
adapter->stats.gotch += E1000_READ_REG(&adapter->hw, GOTCH);
|
|
|
|
|
|
|
|
adapter->stats.rnbc += E1000_READ_REG(&adapter->hw, RNBC);
|
|
|
|
adapter->stats.ruc += E1000_READ_REG(&adapter->hw, RUC);
|
|
|
|
adapter->stats.rfc += E1000_READ_REG(&adapter->hw, RFC);
|
|
|
|
adapter->stats.roc += E1000_READ_REG(&adapter->hw, ROC);
|
|
|
|
adapter->stats.rjc += E1000_READ_REG(&adapter->hw, RJC);
|
|
|
|
|
|
|
|
adapter->stats.torl += E1000_READ_REG(&adapter->hw, TORL);
|
|
|
|
adapter->stats.torh += E1000_READ_REG(&adapter->hw, TORH);
|
|
|
|
adapter->stats.totl += E1000_READ_REG(&adapter->hw, TOTL);
|
|
|
|
adapter->stats.toth += E1000_READ_REG(&adapter->hw, TOTH);
|
|
|
|
|
|
|
|
adapter->stats.tpr += E1000_READ_REG(&adapter->hw, TPR);
|
|
|
|
adapter->stats.tpt += E1000_READ_REG(&adapter->hw, TPT);
|
|
|
|
adapter->stats.ptc64 += E1000_READ_REG(&adapter->hw, PTC64);
|
|
|
|
adapter->stats.ptc127 += E1000_READ_REG(&adapter->hw, PTC127);
|
|
|
|
adapter->stats.ptc255 += E1000_READ_REG(&adapter->hw, PTC255);
|
|
|
|
adapter->stats.ptc511 += E1000_READ_REG(&adapter->hw, PTC511);
|
|
|
|
adapter->stats.ptc1023 += E1000_READ_REG(&adapter->hw, PTC1023);
|
|
|
|
adapter->stats.ptc1522 += E1000_READ_REG(&adapter->hw, PTC1522);
|
|
|
|
adapter->stats.mptc += E1000_READ_REG(&adapter->hw, MPTC);
|
|
|
|
adapter->stats.bptc += E1000_READ_REG(&adapter->hw, BPTC);
|
|
|
|
|
|
|
|
if (adapter->hw.mac_type >= em_82543) {
|
|
|
|
adapter->stats.algnerrc +=
|
|
|
|
E1000_READ_REG(&adapter->hw, ALGNERRC);
|
|
|
|
adapter->stats.rxerrc +=
|
|
|
|
E1000_READ_REG(&adapter->hw, RXERRC);
|
|
|
|
adapter->stats.tncrs +=
|
|
|
|
E1000_READ_REG(&adapter->hw, TNCRS);
|
|
|
|
adapter->stats.cexterr +=
|
|
|
|
E1000_READ_REG(&adapter->hw, CEXTERR);
|
|
|
|
adapter->stats.tsctc +=
|
|
|
|
E1000_READ_REG(&adapter->hw, TSCTC);
|
|
|
|
adapter->stats.tsctfc +=
|
|
|
|
E1000_READ_REG(&adapter->hw, TSCTFC);
|
|
|
|
}
|
|
|
|
ifp = &adapter->interface_data.ac_if;
|
|
|
|
|
|
|
|
/* Fill out the OS statistics structure */
|
|
|
|
ifp->if_ibytes = adapter->stats.gorcl;
|
|
|
|
ifp->if_obytes = adapter->stats.gotcl;
|
|
|
|
ifp->if_imcasts = adapter->stats.mprc;
|
|
|
|
ifp->if_collisions = adapter->stats.colc;
|
|
|
|
|
|
|
|
/* Rx Errors */
|
|
|
|
ifp->if_ierrors =
|
|
|
|
adapter->dropped_pkts +
|
|
|
|
adapter->stats.rxerrc +
|
|
|
|
adapter->stats.crcerrs +
|
|
|
|
adapter->stats.algnerrc +
|
|
|
|
adapter->stats.rlec + adapter->stats.rnbc +
|
|
|
|
adapter->stats.mpc + adapter->stats.cexterr;
|
|
|
|
|
|
|
|
/* Tx Errors */
|
|
|
|
ifp->if_oerrors = adapter->stats.ecol + adapter->stats.latecol;
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
*
|
|
|
|
* This routine is called only when em_display_debug_stats is enabled.
|
|
|
|
* This routine provides a way to take a look at important statistics
|
|
|
|
* maintained by the driver and hardware.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
static void
|
2003-06-05 17:51:38 +00:00
|
|
|
em_print_debug_info(struct adapter *adapter)
|
2001-12-02 07:37:17 +00:00
|
|
|
{
|
2003-06-05 17:51:38 +00:00
|
|
|
int unit = adapter->unit;
|
2004-02-10 21:31:09 +00:00
|
|
|
uint8_t *hw_addr = adapter->hw.hw_addr;
|
|
|
|
|
|
|
|
printf("em%d: Adapter hardware address = %p \n", unit, hw_addr);
|
2004-09-01 23:22:41 +00:00
|
|
|
printf("em%d:CTRL = 0x%x\n", unit,
|
|
|
|
E1000_READ_REG(&adapter->hw, CTRL));
|
|
|
|
printf("em%d:RCTL = 0x%x PS=(0x8402)\n", unit,
|
|
|
|
E1000_READ_REG(&adapter->hw, RCTL));
|
2004-02-10 21:31:09 +00:00
|
|
|
printf("em%d:tx_int_delay = %d, tx_abs_int_delay = %d\n", unit,
|
|
|
|
E1000_READ_REG(&adapter->hw, TIDV),
|
|
|
|
E1000_READ_REG(&adapter->hw, TADV));
|
|
|
|
printf("em%d:rx_int_delay = %d, rx_abs_int_delay = %d\n", unit,
|
|
|
|
E1000_READ_REG(&adapter->hw, RDTR),
|
|
|
|
E1000_READ_REG(&adapter->hw, RADV));
|
2001-12-02 07:37:17 +00:00
|
|
|
|
|
|
|
#ifdef DBG_STATS
|
2003-06-05 17:51:38 +00:00
|
|
|
printf("em%d: Packets not Avail = %ld\n", unit,
|
|
|
|
adapter->no_pkts_avail);
|
|
|
|
printf("em%d: CleanTxInterrupts = %ld\n", unit,
|
|
|
|
adapter->clean_tx_interrupts);
|
2001-12-02 07:37:17 +00:00
|
|
|
#endif
|
2003-06-05 17:51:38 +00:00
|
|
|
printf("em%d: fifo workaround = %lld, fifo_reset = %lld\n", unit,
|
2004-09-01 23:22:41 +00:00
|
|
|
(long long)adapter->tx_fifo_wrk_cnt,
|
|
|
|
(long long)adapter->tx_fifo_reset_cnt);
|
2003-06-05 17:51:38 +00:00
|
|
|
printf("em%d: hw tdh = %d, hw tdt = %d\n", unit,
|
|
|
|
E1000_READ_REG(&adapter->hw, TDH),
|
|
|
|
E1000_READ_REG(&adapter->hw, TDT));
|
|
|
|
printf("em%d: Num Tx descriptors avail = %d\n", unit,
|
|
|
|
adapter->num_tx_desc_avail);
|
|
|
|
printf("em%d: Tx Descriptors not avail1 = %ld\n", unit,
|
|
|
|
adapter->no_tx_desc_avail1);
|
|
|
|
printf("em%d: Tx Descriptors not avail2 = %ld\n", unit,
|
|
|
|
adapter->no_tx_desc_avail2);
|
|
|
|
printf("em%d: Std mbuf failed = %ld\n", unit,
|
|
|
|
adapter->mbuf_alloc_failed);
|
|
|
|
printf("em%d: Std mbuf cluster failed = %ld\n", unit,
|
|
|
|
adapter->mbuf_cluster_failed);
|
|
|
|
printf("em%d: Driver dropped packets = %ld\n", unit,
|
|
|
|
adapter->dropped_pkts);
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-06-05 17:51:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-06-03 22:30:51 +00:00
|
|
|
|
2003-06-05 17:51:38 +00:00
|
|
|
static void
|
|
|
|
em_print_hw_stats(struct adapter *adapter)
|
|
|
|
{
|
|
|
|
int unit = adapter->unit;
|
|
|
|
|
|
|
|
printf("em%d: Excessive collisions = %lld\n", unit,
|
|
|
|
(long long)adapter->stats.ecol);
|
|
|
|
printf("em%d: Symbol errors = %lld\n", unit,
|
|
|
|
(long long)adapter->stats.symerrs);
|
|
|
|
printf("em%d: Sequence errors = %lld\n", unit,
|
|
|
|
(long long)adapter->stats.sec);
|
|
|
|
printf("em%d: Defer count = %lld\n", unit,
|
|
|
|
(long long)adapter->stats.dc);
|
|
|
|
|
|
|
|
printf("em%d: Missed Packets = %lld\n", unit,
|
|
|
|
(long long)adapter->stats.mpc);
|
|
|
|
printf("em%d: Receive No Buffers = %lld\n", unit,
|
|
|
|
(long long)adapter->stats.rnbc);
|
|
|
|
printf("em%d: Receive length errors = %lld\n", unit,
|
|
|
|
(long long)adapter->stats.rlec);
|
|
|
|
printf("em%d: Receive errors = %lld\n", unit,
|
|
|
|
(long long)adapter->stats.rxerrc);
|
|
|
|
printf("em%d: Crc errors = %lld\n", unit,
|
|
|
|
(long long)adapter->stats.crcerrs);
|
|
|
|
printf("em%d: Alignment errors = %lld\n", unit,
|
|
|
|
(long long)adapter->stats.algnerrc);
|
|
|
|
printf("em%d: Carrier extension errors = %lld\n", unit,
|
|
|
|
(long long)adapter->stats.cexterr);
|
|
|
|
|
|
|
|
printf("em%d: XON Rcvd = %lld\n", unit,
|
|
|
|
(long long)adapter->stats.xonrxc);
|
|
|
|
printf("em%d: XON Xmtd = %lld\n", unit,
|
|
|
|
(long long)adapter->stats.xontxc);
|
|
|
|
printf("em%d: XOFF Rcvd = %lld\n", unit,
|
|
|
|
(long long)adapter->stats.xoffrxc);
|
|
|
|
printf("em%d: XOFF Xmtd = %lld\n", unit,
|
|
|
|
(long long)adapter->stats.xofftxc);
|
|
|
|
|
|
|
|
printf("em%d: Good Packets Rcvd = %lld\n", unit,
|
|
|
|
(long long)adapter->stats.gprc);
|
|
|
|
printf("em%d: Good Packets Xmtd = %lld\n", unit,
|
|
|
|
(long long)adapter->stats.gptc);
|
|
|
|
|
|
|
|
return;
|
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)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
int result;
|
|
|
|
struct adapter *adapter;
|
|
|
|
|
|
|
|
result = -1;
|
|
|
|
error = sysctl_handle_int(oidp, &result, 0, req);
|
|
|
|
|
|
|
|
if (error || !req->newptr)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if (result == 1) {
|
|
|
|
adapter = (struct adapter *)arg1;
|
|
|
|
em_print_debug_info(adapter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
em_sysctl_stats(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
int result;
|
|
|
|
struct adapter *adapter;
|
|
|
|
|
|
|
|
result = -1;
|
|
|
|
error = sysctl_handle_int(oidp, &result, 0, req);
|
|
|
|
|
|
|
|
if (error || !req->newptr)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if (result == 1) {
|
|
|
|
adapter = (struct adapter *)arg1;
|
|
|
|
em_print_hw_stats(adapter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
2003-08-01 17:33:59 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
em_sysctl_int_delay(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct em_int_delay_info *info;
|
|
|
|
struct adapter *adapter;
|
|
|
|
u_int32_t regval;
|
|
|
|
int error;
|
|
|
|
int usecs;
|
|
|
|
int ticks;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
info = (struct em_int_delay_info *)arg1;
|
|
|
|
adapter = info->adapter;
|
|
|
|
usecs = info->value;
|
|
|
|
error = sysctl_handle_int(oidp, &usecs, 0, req);
|
|
|
|
if (error != 0 || req->newptr == NULL)
|
|
|
|
return error;
|
|
|
|
if (usecs < 0 || usecs > E1000_TICKS_TO_USECS(65535))
|
|
|
|
return EINVAL;
|
|
|
|
info->value = usecs;
|
|
|
|
ticks = E1000_USECS_TO_TICKS(usecs);
|
|
|
|
|
|
|
|
s = splimp();
|
|
|
|
regval = E1000_READ_OFFSET(&adapter->hw, info->offset);
|
|
|
|
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) {
|
|
|
|
adapter->txd_cmd &= ~E1000_TXD_CMD_IDE;
|
|
|
|
/* Don't write 0 into the TIDV register. */
|
|
|
|
regval++;
|
|
|
|
} else
|
|
|
|
adapter->txd_cmd |= E1000_TXD_CMD_IDE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
E1000_WRITE_OFFSET(&adapter->hw, info->offset, regval);
|
|
|
|
splx(s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
em_add_int_delay_sysctl(struct adapter *adapter, const char *name,
|
|
|
|
const char *description, struct em_int_delay_info *info,
|
|
|
|
int offset, int value)
|
|
|
|
{
|
|
|
|
info->adapter = adapter;
|
|
|
|
info->offset = offset;
|
|
|
|
info->value = value;
|
|
|
|
SYSCTL_ADD_PROC(&adapter->sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(adapter->sysctl_tree),
|
|
|
|
OID_AUTO, name, CTLTYPE_INT|CTLFLAG_RW,
|
|
|
|
info, 0, em_sysctl_int_delay, "I", description);
|
|
|
|
}
|