2006-06-13 13:53:52 +00:00
|
|
|
/******************************************************************************
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2009-02-17 22:15:58 +00:00
|
|
|
Copyright (c) 2006-2009, Myricom Inc.
|
2006-02-19 22:39:19 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
this list of conditions and the following disclaimer.
|
|
|
|
|
2007-07-12 16:04:55 +00:00
|
|
|
2. Neither the name of the Myricom Inc, nor the names of its
|
2006-02-19 22:39:19 +00:00
|
|
|
contributors may be used to endorse or promote products derived from
|
|
|
|
this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2009-04-27 15:45:54 +00:00
|
|
|
#define IFNET_BUF_RING
|
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/linker.h>
|
|
|
|
#include <sys/firmware.h>
|
|
|
|
#include <sys/endian.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kdb.h>
|
|
|
|
#include <sys/kernel.h>
|
2007-03-31 23:23:42 +00:00
|
|
|
#include <sys/lock.h>
|
2006-02-19 22:39:19 +00:00
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/sx.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/if_vlan_var.h>
|
|
|
|
#include <net/zlib.h>
|
|
|
|
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/ip.h>
|
2006-09-15 15:41:28 +00:00
|
|
|
#include <netinet/tcp.h>
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
#include <machine/bus.h>
|
2007-05-21 18:32:27 +00:00
|
|
|
#include <machine/in_cksum.h>
|
2006-02-19 22:39:19 +00:00
|
|
|
#include <machine/resource.h>
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
#include <sys/buf_ring.h>
|
|
|
|
#endif
|
2006-02-19 22:39:19 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/rman.h>
|
2008-01-15 20:34:49 +00:00
|
|
|
#include <sys/smp.h>
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
2008-07-17 15:46:35 +00:00
|
|
|
#include <dev/pci/pci_private.h> /* XXX for pci_cfg_restore */
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
#include <vm/vm.h> /* for pmap_mapdev() */
|
|
|
|
#include <vm/pmap.h>
|
|
|
|
|
2007-06-05 15:02:14 +00:00
|
|
|
#if defined(__i386) || defined(__amd64)
|
|
|
|
#include <machine/specialreg.h>
|
|
|
|
#endif
|
|
|
|
|
2006-06-13 13:53:52 +00:00
|
|
|
#include <dev/mxge/mxge_mcp.h>
|
|
|
|
#include <dev/mxge/mcp_gen_header.h>
|
2008-01-15 20:34:49 +00:00
|
|
|
/*#define MXGE_FAKE_IFP*/
|
2006-06-13 13:53:52 +00:00
|
|
|
#include <dev/mxge/if_mxge_var.h>
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
/* tunable params */
|
2006-06-13 13:53:52 +00:00
|
|
|
static int mxge_nvidia_ecrc_enable = 1;
|
2006-11-22 16:33:40 +00:00
|
|
|
static int mxge_force_firmware = 0;
|
2006-06-13 13:53:52 +00:00
|
|
|
static int mxge_intr_coal_delay = 30;
|
2006-06-14 16:23:17 +00:00
|
|
|
static int mxge_deassert_wait = 1;
|
2006-06-13 13:53:52 +00:00
|
|
|
static int mxge_flow_control = 1;
|
2006-06-14 16:23:17 +00:00
|
|
|
static int mxge_verbose = 0;
|
2007-06-12 19:15:16 +00:00
|
|
|
static int mxge_lro_cnt = 8;
|
2007-01-31 19:53:36 +00:00
|
|
|
static int mxge_ticks;
|
2008-01-15 20:34:49 +00:00
|
|
|
static int mxge_max_slices = 1;
|
|
|
|
static int mxge_rss_hash_type = MXGEFW_RSS_HASH_TYPE_SRC_PORT;
|
|
|
|
static int mxge_always_promisc = 0;
|
2006-06-13 13:53:52 +00:00
|
|
|
static char *mxge_fw_unaligned = "mxge_ethp_z8e";
|
|
|
|
static char *mxge_fw_aligned = "mxge_eth_z8e";
|
2008-01-15 20:34:49 +00:00
|
|
|
static char *mxge_fw_rss_aligned = "mxge_rss_eth_z8e";
|
|
|
|
static char *mxge_fw_rss_unaligned = "mxge_rss_ethp_z8e";
|
2006-06-13 13:53:52 +00:00
|
|
|
|
|
|
|
static int mxge_probe(device_t dev);
|
|
|
|
static int mxge_attach(device_t dev);
|
|
|
|
static int mxge_detach(device_t dev);
|
|
|
|
static int mxge_shutdown(device_t dev);
|
|
|
|
static void mxge_intr(void *arg);
|
|
|
|
|
|
|
|
static device_method_t mxge_methods[] =
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
|
|
|
/* Device interface */
|
2006-06-13 13:53:52 +00:00
|
|
|
DEVMETHOD(device_probe, mxge_probe),
|
|
|
|
DEVMETHOD(device_attach, mxge_attach),
|
|
|
|
DEVMETHOD(device_detach, mxge_detach),
|
|
|
|
DEVMETHOD(device_shutdown, mxge_shutdown),
|
2006-02-19 22:39:19 +00:00
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
2006-06-13 13:53:52 +00:00
|
|
|
static driver_t mxge_driver =
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2006-06-13 13:53:52 +00:00
|
|
|
"mxge",
|
|
|
|
mxge_methods,
|
|
|
|
sizeof(mxge_softc_t),
|
2006-02-19 22:39:19 +00:00
|
|
|
};
|
|
|
|
|
2006-06-13 13:53:52 +00:00
|
|
|
static devclass_t mxge_devclass;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
/* Declare ourselves to be a child of the PCI bus.*/
|
2006-06-13 13:53:52 +00:00
|
|
|
DRIVER_MODULE(mxge, pci, mxge_driver, mxge_devclass, 0, 0);
|
|
|
|
MODULE_DEPEND(mxge, firmware, 1, 1, 1);
|
2007-07-19 16:16:00 +00:00
|
|
|
MODULE_DEPEND(mxge, zlib, 1, 1, 1);
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
static int mxge_load_firmware(mxge_softc_t *sc, int adopt);
|
2007-05-08 14:19:43 +00:00
|
|
|
static int mxge_send_cmd(mxge_softc_t *sc, uint32_t cmd, mxge_cmd_t *data);
|
2007-06-11 14:01:10 +00:00
|
|
|
static int mxge_close(mxge_softc_t *sc);
|
|
|
|
static int mxge_open(mxge_softc_t *sc);
|
|
|
|
static void mxge_tick(void *arg);
|
2007-05-08 14:19:43 +00:00
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
static int
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_probe(device_t dev)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2009-02-17 22:15:58 +00:00
|
|
|
int rev;
|
|
|
|
|
|
|
|
|
|
|
|
if ((pci_get_vendor(dev) == MXGE_PCI_VENDOR_MYRICOM) &&
|
|
|
|
((pci_get_device(dev) == MXGE_PCI_DEVICE_Z8E) ||
|
|
|
|
(pci_get_device(dev) == MXGE_PCI_DEVICE_Z8E_9))) {
|
|
|
|
rev = pci_get_revid(dev);
|
|
|
|
switch (rev) {
|
|
|
|
case MXGE_PCI_REV_Z8E:
|
|
|
|
device_set_desc(dev, "Myri10G-PCIE-8A");
|
|
|
|
break;
|
|
|
|
case MXGE_PCI_REV_Z8ES:
|
|
|
|
device_set_desc(dev, "Myri10G-PCIE-8B");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
device_set_desc(dev, "Myri10G-PCIE-8??");
|
|
|
|
device_printf(dev, "Unrecognized rev %d NIC\n",
|
|
|
|
rev);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ENXIO;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_enable_wc(mxge_softc_t *sc)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2007-07-19 16:16:00 +00:00
|
|
|
#if defined(__i386) || defined(__amd64)
|
2006-02-19 22:39:19 +00:00
|
|
|
vm_offset_t len;
|
2008-03-12 15:36:00 +00:00
|
|
|
int err;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2007-06-17 00:09:51 +00:00
|
|
|
sc->wc = 1;
|
2006-02-19 22:39:19 +00:00
|
|
|
len = rman_get_size(sc->mem_res);
|
2007-06-05 15:02:14 +00:00
|
|
|
err = pmap_change_attr((vm_offset_t) sc->sram,
|
|
|
|
len, PAT_WRITE_COMBINING);
|
2008-03-12 15:36:00 +00:00
|
|
|
if (err != 0) {
|
2007-06-05 15:02:14 +00:00
|
|
|
device_printf(sc->dev, "pmap_change_attr failed, %d\n",
|
|
|
|
err);
|
2007-06-17 00:09:51 +00:00
|
|
|
sc->wc = 0;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2007-07-19 16:16:00 +00:00
|
|
|
#endif
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* callback to get our DMA address */
|
|
|
|
static void
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs,
|
2006-02-19 22:39:19 +00:00
|
|
|
int error)
|
|
|
|
{
|
|
|
|
if (error == 0) {
|
|
|
|
*(bus_addr_t *) arg = segs->ds_addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_dma_alloc(mxge_softc_t *sc, mxge_dma_t *dma, size_t bytes,
|
2006-02-19 22:39:19 +00:00
|
|
|
bus_size_t alignment)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
device_t dev = sc->dev;
|
2008-01-15 20:34:49 +00:00
|
|
|
bus_size_t boundary, maxsegsize;
|
|
|
|
|
|
|
|
if (bytes > 4096 && alignment == 4096) {
|
|
|
|
boundary = 0;
|
|
|
|
maxsegsize = bytes;
|
|
|
|
} else {
|
|
|
|
boundary = 4096;
|
|
|
|
maxsegsize = 4096;
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
/* allocate DMAable memory tags */
|
|
|
|
err = bus_dma_tag_create(sc->parent_dmat, /* parent */
|
|
|
|
alignment, /* alignment */
|
2008-01-15 20:34:49 +00:00
|
|
|
boundary, /* boundary */
|
2006-02-19 22:39:19 +00:00
|
|
|
BUS_SPACE_MAXADDR, /* low */
|
|
|
|
BUS_SPACE_MAXADDR, /* high */
|
|
|
|
NULL, NULL, /* filter */
|
|
|
|
bytes, /* maxsize */
|
|
|
|
1, /* num segs */
|
2008-01-15 20:34:49 +00:00
|
|
|
maxsegsize, /* maxsegsize */
|
2006-02-19 22:39:19 +00:00
|
|
|
BUS_DMA_COHERENT, /* flags */
|
|
|
|
NULL, NULL, /* lock */
|
|
|
|
&dma->dmat); /* tag */
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(dev, "couldn't alloc tag (err = %d)\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate DMAable memory & map */
|
|
|
|
err = bus_dmamem_alloc(dma->dmat, &dma->addr,
|
|
|
|
(BUS_DMA_WAITOK | BUS_DMA_COHERENT
|
|
|
|
| BUS_DMA_ZERO), &dma->map);
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(dev, "couldn't alloc mem (err = %d)\n", err);
|
|
|
|
goto abort_with_dmat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load the memory */
|
|
|
|
err = bus_dmamap_load(dma->dmat, dma->map, dma->addr, bytes,
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_dmamap_callback,
|
2006-02-19 22:39:19 +00:00
|
|
|
(void *)&dma->bus_addr, 0);
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(dev, "couldn't load map (err = %d)\n", err);
|
|
|
|
goto abort_with_mem;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
abort_with_mem:
|
|
|
|
bus_dmamem_free(dma->dmat, dma->addr, dma->map);
|
|
|
|
abort_with_dmat:
|
|
|
|
(void)bus_dma_tag_destroy(dma->dmat);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_dma_free(mxge_dma_t *dma)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
|
|
|
bus_dmamap_unload(dma->dmat, dma->map);
|
|
|
|
bus_dmamem_free(dma->dmat, dma->addr, dma->map);
|
|
|
|
(void)bus_dma_tag_destroy(dma->dmat);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The eeprom strings on the lanaiX have the format
|
|
|
|
* SN=x\0
|
|
|
|
* MAC=x:x:x:x:x:x\0
|
|
|
|
* PC=text\0
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_parse_strings(mxge_softc_t *sc)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2006-06-13 13:53:52 +00:00
|
|
|
#define MXGE_NEXT_STRING(p) while(ptr < limit && *ptr++)
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
char *ptr, *limit;
|
|
|
|
int i, found_mac;
|
|
|
|
|
|
|
|
ptr = sc->eeprom_strings;
|
2006-06-13 13:53:52 +00:00
|
|
|
limit = sc->eeprom_strings + MXGE_EEPROM_STRINGS_SIZE;
|
2006-02-19 22:39:19 +00:00
|
|
|
found_mac = 0;
|
|
|
|
while (ptr < limit && *ptr != '\0') {
|
|
|
|
if (memcmp(ptr, "MAC=", 4) == 0) {
|
2006-06-14 16:23:17 +00:00
|
|
|
ptr += 1;
|
2006-02-19 22:39:19 +00:00
|
|
|
sc->mac_addr_string = ptr;
|
|
|
|
for (i = 0; i < 6; i++) {
|
2006-06-14 16:23:17 +00:00
|
|
|
ptr += 3;
|
2006-02-19 22:39:19 +00:00
|
|
|
if ((ptr + 2) > limit)
|
|
|
|
goto abort;
|
|
|
|
sc->mac_addr[i] = strtoul(ptr, NULL, 16);
|
|
|
|
found_mac = 1;
|
|
|
|
}
|
2006-06-14 16:23:17 +00:00
|
|
|
} else if (memcmp(ptr, "PC=", 3) == 0) {
|
|
|
|
ptr += 3;
|
|
|
|
strncpy(sc->product_code_string, ptr,
|
|
|
|
sizeof (sc->product_code_string) - 1);
|
|
|
|
} else if (memcmp(ptr, "SN=", 3) == 0) {
|
|
|
|
ptr += 3;
|
|
|
|
strncpy(sc->serial_number_string, ptr,
|
|
|
|
sizeof (sc->serial_number_string) - 1);
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2006-06-13 13:53:52 +00:00
|
|
|
MXGE_NEXT_STRING(ptr);
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (found_mac)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
abort:
|
|
|
|
device_printf(sc->dev, "failed to parse eeprom_strings\n");
|
|
|
|
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
2009-02-12 18:33:56 +00:00
|
|
|
#if defined __i386 || defined i386 || defined __i386__ || defined __x86_64__
|
2007-05-08 14:19:43 +00:00
|
|
|
static void
|
|
|
|
mxge_enable_nvidia_ecrc(mxge_softc_t *sc)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
|
|
|
uint32_t val;
|
2007-05-08 14:19:43 +00:00
|
|
|
unsigned long base, off;
|
2006-02-19 22:39:19 +00:00
|
|
|
char *va, *cfgptr;
|
2007-05-08 14:19:43 +00:00
|
|
|
device_t pdev, mcp55;
|
|
|
|
uint16_t vendor_id, device_id, word;
|
2006-02-19 22:39:19 +00:00
|
|
|
uintptr_t bus, slot, func, ivend, idev;
|
|
|
|
uint32_t *ptr32;
|
|
|
|
|
2007-05-08 14:19:43 +00:00
|
|
|
|
|
|
|
if (!mxge_nvidia_ecrc_enable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pdev = device_get_parent(device_get_parent(sc->dev));
|
|
|
|
if (pdev == NULL) {
|
|
|
|
device_printf(sc->dev, "could not find parent?\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
vendor_id = pci_read_config(pdev, PCIR_VENDOR, 2);
|
|
|
|
device_id = pci_read_config(pdev, PCIR_DEVICE, 2);
|
|
|
|
|
|
|
|
if (vendor_id != 0x10de)
|
|
|
|
return;
|
|
|
|
|
|
|
|
base = 0;
|
|
|
|
|
|
|
|
if (device_id == 0x005d) {
|
|
|
|
/* ck804, base address is magic */
|
|
|
|
base = 0xe0000000UL;
|
|
|
|
} else if (device_id >= 0x0374 && device_id <= 0x378) {
|
|
|
|
/* mcp55, base address stored in chipset */
|
|
|
|
mcp55 = pci_find_bsf(0, 0, 0);
|
|
|
|
if (mcp55 &&
|
|
|
|
0x10de == pci_read_config(mcp55, PCIR_VENDOR, 2) &&
|
|
|
|
0x0369 == pci_read_config(mcp55, PCIR_DEVICE, 2)) {
|
|
|
|
word = pci_read_config(mcp55, 0x90, 2);
|
|
|
|
base = ((unsigned long)word & 0x7ffeU) << 25;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!base)
|
|
|
|
return;
|
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
/* XXXX
|
|
|
|
Test below is commented because it is believed that doing
|
|
|
|
config read/write beyond 0xff will access the config space
|
|
|
|
for the next larger function. Uncomment this and remove
|
|
|
|
the hacky pmap_mapdev() way of accessing config space when
|
|
|
|
FreeBSD grows support for extended pcie config space access
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
/* See if we can, by some miracle, access the extended
|
|
|
|
config space */
|
|
|
|
val = pci_read_config(pdev, 0x178, 4);
|
|
|
|
if (val != 0xffffffff) {
|
|
|
|
val |= 0x40;
|
|
|
|
pci_write_config(pdev, 0x178, val, 4);
|
2007-05-08 14:19:43 +00:00
|
|
|
return;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* Rather than using normal pci config space writes, we must
|
|
|
|
* map the Nvidia config space ourselves. This is because on
|
|
|
|
* opteron/nvidia class machine the 0xe000000 mapping is
|
|
|
|
* handled by the nvidia chipset, that means the internal PCI
|
|
|
|
* device (the on-chip northbridge), or the amd-8131 bridge
|
|
|
|
* and things behind them are not visible by this method.
|
|
|
|
*/
|
|
|
|
|
|
|
|
BUS_READ_IVAR(device_get_parent(pdev), pdev,
|
|
|
|
PCI_IVAR_BUS, &bus);
|
|
|
|
BUS_READ_IVAR(device_get_parent(pdev), pdev,
|
|
|
|
PCI_IVAR_SLOT, &slot);
|
|
|
|
BUS_READ_IVAR(device_get_parent(pdev), pdev,
|
|
|
|
PCI_IVAR_FUNCTION, &func);
|
|
|
|
BUS_READ_IVAR(device_get_parent(pdev), pdev,
|
|
|
|
PCI_IVAR_VENDOR, &ivend);
|
|
|
|
BUS_READ_IVAR(device_get_parent(pdev), pdev,
|
|
|
|
PCI_IVAR_DEVICE, &idev);
|
|
|
|
|
2007-05-08 14:19:43 +00:00
|
|
|
off = base
|
2006-02-19 22:39:19 +00:00
|
|
|
+ 0x00100000UL * (unsigned long)bus
|
|
|
|
+ 0x00001000UL * (unsigned long)(func
|
|
|
|
+ 8 * slot);
|
|
|
|
|
|
|
|
/* map it into the kernel */
|
|
|
|
va = pmap_mapdev(trunc_page((vm_paddr_t)off), PAGE_SIZE);
|
|
|
|
|
|
|
|
|
|
|
|
if (va == NULL) {
|
|
|
|
device_printf(sc->dev, "pmap_kenter_temporary didn't\n");
|
2007-05-08 14:19:43 +00:00
|
|
|
return;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
/* get a pointer to the config space mapped into the kernel */
|
|
|
|
cfgptr = va + (off & PAGE_MASK);
|
|
|
|
|
|
|
|
/* make sure that we can really access it */
|
|
|
|
vendor_id = *(uint16_t *)(cfgptr + PCIR_VENDOR);
|
|
|
|
device_id = *(uint16_t *)(cfgptr + PCIR_DEVICE);
|
|
|
|
if (! (vendor_id == ivend && device_id == idev)) {
|
|
|
|
device_printf(sc->dev, "mapping failed: 0x%x:0x%x\n",
|
|
|
|
vendor_id, device_id);
|
|
|
|
pmap_unmapdev((vm_offset_t)va, PAGE_SIZE);
|
2007-05-08 14:19:43 +00:00
|
|
|
return;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ptr32 = (uint32_t*)(cfgptr + 0x178);
|
|
|
|
val = *ptr32;
|
|
|
|
|
|
|
|
if (val == 0xffffffff) {
|
|
|
|
device_printf(sc->dev, "extended mapping failed\n");
|
|
|
|
pmap_unmapdev((vm_offset_t)va, PAGE_SIZE);
|
2007-05-08 14:19:43 +00:00
|
|
|
return;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
*ptr32 = val | 0x40;
|
|
|
|
pmap_unmapdev((vm_offset_t)va, PAGE_SIZE);
|
2006-06-14 16:23:17 +00:00
|
|
|
if (mxge_verbose)
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"Enabled ECRC on upstream Nvidia bridge "
|
|
|
|
"at %d:%d:%d\n",
|
|
|
|
(int)bus, (int)slot, (int)func);
|
2007-05-08 14:19:43 +00:00
|
|
|
return;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
#else
|
2007-05-08 14:19:43 +00:00
|
|
|
static void
|
2007-07-19 16:16:00 +00:00
|
|
|
mxge_enable_nvidia_ecrc(mxge_softc_t *sc)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"Nforce 4 chipset on non-x86/amd64!?!?!\n");
|
2007-05-08 14:19:43 +00:00
|
|
|
return;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
2007-05-08 14:19:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
mxge_dma_test(mxge_softc_t *sc, int test_type)
|
|
|
|
{
|
|
|
|
mxge_cmd_t cmd;
|
|
|
|
bus_addr_t dmatest_bus = sc->dmabench_dma.bus_addr;
|
|
|
|
int status;
|
|
|
|
uint32_t len;
|
|
|
|
char *test = " ";
|
|
|
|
|
|
|
|
|
|
|
|
/* Run a small DMA test.
|
|
|
|
* The magic multipliers to the length tell the firmware
|
|
|
|
* to do DMA read, write, or read+write tests. The
|
|
|
|
* results are returned in cmd.data0. The upper 16
|
|
|
|
* bits of the return is the number of transfers completed.
|
|
|
|
* The lower 16 bits is the time in 0.5us ticks that the
|
|
|
|
* transfers took to complete.
|
|
|
|
*/
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
len = sc->tx_boundary;
|
2007-05-08 14:19:43 +00:00
|
|
|
|
|
|
|
cmd.data0 = MXGE_LOWPART_TO_U32(dmatest_bus);
|
|
|
|
cmd.data1 = MXGE_HIGHPART_TO_U32(dmatest_bus);
|
|
|
|
cmd.data2 = len * 0x10000;
|
|
|
|
status = mxge_send_cmd(sc, test_type, &cmd);
|
|
|
|
if (status != 0) {
|
|
|
|
test = "read";
|
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
sc->read_dma = ((cmd.data0>>16) * len * 2) /
|
|
|
|
(cmd.data0 & 0xffff);
|
|
|
|
cmd.data0 = MXGE_LOWPART_TO_U32(dmatest_bus);
|
|
|
|
cmd.data1 = MXGE_HIGHPART_TO_U32(dmatest_bus);
|
|
|
|
cmd.data2 = len * 0x1;
|
|
|
|
status = mxge_send_cmd(sc, test_type, &cmd);
|
|
|
|
if (status != 0) {
|
|
|
|
test = "write";
|
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
sc->write_dma = ((cmd.data0>>16) * len * 2) /
|
|
|
|
(cmd.data0 & 0xffff);
|
|
|
|
|
|
|
|
cmd.data0 = MXGE_LOWPART_TO_U32(dmatest_bus);
|
|
|
|
cmd.data1 = MXGE_HIGHPART_TO_U32(dmatest_bus);
|
|
|
|
cmd.data2 = len * 0x10001;
|
|
|
|
status = mxge_send_cmd(sc, test_type, &cmd);
|
|
|
|
if (status != 0) {
|
|
|
|
test = "read/write";
|
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
sc->read_write_dma = ((cmd.data0>>16) * len * 2 * 2) /
|
|
|
|
(cmd.data0 & 0xffff);
|
|
|
|
|
|
|
|
abort:
|
|
|
|
if (status != 0 && test_type != MXGEFW_CMD_UNALIGNED_TEST)
|
|
|
|
device_printf(sc->dev, "DMA %s benchmark failed: %d\n",
|
|
|
|
test, status);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
/*
|
|
|
|
* The Lanai Z8E PCI-E interface achieves higher Read-DMA throughput
|
|
|
|
* when the PCI-E Completion packets are aligned on an 8-byte
|
|
|
|
* boundary. Some PCI-E chip sets always align Completion packets; on
|
|
|
|
* the ones that do not, the alignment can be enforced by enabling
|
|
|
|
* ECRC generation (if supported).
|
|
|
|
*
|
|
|
|
* When PCI-E Completion packets are not aligned, it is actually more
|
|
|
|
* efficient to limit Read-DMA transactions to 2KB, rather than 4KB.
|
|
|
|
*
|
|
|
|
* If the driver can neither enable ECRC nor verify that it has
|
|
|
|
* already been enabled, then it must use a firmware image which works
|
|
|
|
* around unaligned completion packets (ethp_z8e.dat), and it should
|
|
|
|
* also ensure that it never gives the device a Read-DMA which is
|
2008-01-15 20:34:49 +00:00
|
|
|
* larger than 2KB by setting the tx_boundary to 2KB. If ECRC is
|
2006-02-19 22:39:19 +00:00
|
|
|
* enabled, then the driver should use the aligned (eth_z8e.dat)
|
2008-01-15 20:34:49 +00:00
|
|
|
* firmware image, and set tx_boundary to 4KB.
|
2006-02-19 22:39:19 +00:00
|
|
|
*/
|
|
|
|
|
2007-05-08 14:19:43 +00:00
|
|
|
static int
|
|
|
|
mxge_firmware_probe(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
device_t dev = sc->dev;
|
|
|
|
int reg, status;
|
|
|
|
uint16_t pectl;
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
sc->tx_boundary = 4096;
|
2007-05-08 14:19:43 +00:00
|
|
|
/*
|
|
|
|
* Verify the max read request size was set to 4KB
|
|
|
|
* before trying the test with 4KB.
|
|
|
|
*/
|
|
|
|
if (pci_find_extcap(dev, PCIY_EXPRESS, ®) == 0) {
|
|
|
|
pectl = pci_read_config(dev, reg + 0x8, 2);
|
|
|
|
if ((pectl & (5 << 12)) != (5 << 12)) {
|
|
|
|
device_printf(dev, "Max Read Req. size != 4k (0x%x\n",
|
|
|
|
pectl);
|
2008-01-15 20:34:49 +00:00
|
|
|
sc->tx_boundary = 2048;
|
2007-05-08 14:19:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* load the optimized firmware (which assumes aligned PCIe
|
|
|
|
* completions) in order to see if it works on this host.
|
|
|
|
*/
|
|
|
|
sc->fw_name = mxge_fw_aligned;
|
2008-01-15 20:34:49 +00:00
|
|
|
status = mxge_load_firmware(sc, 1);
|
2007-05-08 14:19:43 +00:00
|
|
|
if (status != 0) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable ECRC if possible
|
|
|
|
*/
|
|
|
|
mxge_enable_nvidia_ecrc(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run a DMA test which watches for unaligned completions and
|
|
|
|
* aborts on the first one seen.
|
|
|
|
*/
|
|
|
|
|
|
|
|
status = mxge_dma_test(sc, MXGEFW_CMD_UNALIGNED_TEST);
|
|
|
|
if (status == 0)
|
|
|
|
return 0; /* keep the aligned firmware */
|
|
|
|
|
|
|
|
if (status != E2BIG)
|
|
|
|
device_printf(dev, "DMA test failed: %d\n", status);
|
|
|
|
if (status == ENOSYS)
|
|
|
|
device_printf(dev, "Falling back to ethp! "
|
|
|
|
"Please install up to date fw\n");
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_select_firmware(mxge_softc_t *sc)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2007-05-08 14:19:43 +00:00
|
|
|
int aligned = 0;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2006-11-22 16:33:40 +00:00
|
|
|
|
|
|
|
if (mxge_force_firmware != 0) {
|
|
|
|
if (mxge_force_firmware == 1)
|
|
|
|
aligned = 1;
|
|
|
|
else
|
|
|
|
aligned = 0;
|
|
|
|
if (mxge_verbose)
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"Assuming %s completions (forced)\n",
|
|
|
|
aligned ? "aligned" : "unaligned");
|
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if the PCIe link width is 4 or less, we can use the aligned
|
|
|
|
firmware and skip any checks */
|
|
|
|
if (sc->link_width != 0 && sc->link_width <= 4) {
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"PCIe x%d Link, expect reduced performance\n",
|
|
|
|
sc->link_width);
|
|
|
|
aligned = 1;
|
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
|
2007-05-08 14:19:43 +00:00
|
|
|
if (0 == mxge_firmware_probe(sc))
|
|
|
|
return 0;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
abort:
|
|
|
|
if (aligned) {
|
2006-06-13 13:53:52 +00:00
|
|
|
sc->fw_name = mxge_fw_aligned;
|
2008-01-15 20:34:49 +00:00
|
|
|
sc->tx_boundary = 4096;
|
2006-02-19 22:39:19 +00:00
|
|
|
} else {
|
2006-06-13 13:53:52 +00:00
|
|
|
sc->fw_name = mxge_fw_unaligned;
|
2008-01-15 20:34:49 +00:00
|
|
|
sc->tx_boundary = 2048;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
return (mxge_load_firmware(sc, 0));
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
union qualhack
|
|
|
|
{
|
|
|
|
const char *ro_char;
|
|
|
|
char *rw_char;
|
|
|
|
};
|
|
|
|
|
2006-07-17 22:17:05 +00:00
|
|
|
static int
|
|
|
|
mxge_validate_firmware(mxge_softc_t *sc, const mcp_gen_header_t *hdr)
|
|
|
|
{
|
2007-02-21 17:34:05 +00:00
|
|
|
|
2006-07-17 22:17:05 +00:00
|
|
|
|
|
|
|
if (be32toh(hdr->mcp_type) != MCP_TYPE_ETH) {
|
|
|
|
device_printf(sc->dev, "Bad firmware type: 0x%x\n",
|
|
|
|
be32toh(hdr->mcp_type));
|
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save firmware version for sysctl */
|
|
|
|
strncpy(sc->fw_version, hdr->version, sizeof (sc->fw_version));
|
|
|
|
if (mxge_verbose)
|
|
|
|
device_printf(sc->dev, "firmware id: %s\n", hdr->version);
|
|
|
|
|
2007-02-21 17:34:05 +00:00
|
|
|
sscanf(sc->fw_version, "%d.%d.%d", &sc->fw_ver_major,
|
|
|
|
&sc->fw_ver_minor, &sc->fw_ver_tiny);
|
2006-07-17 22:17:05 +00:00
|
|
|
|
2007-02-21 17:34:05 +00:00
|
|
|
if (!(sc->fw_ver_major == MXGEFW_VERSION_MAJOR
|
|
|
|
&& sc->fw_ver_minor == MXGEFW_VERSION_MINOR)) {
|
2006-07-17 22:17:05 +00:00
|
|
|
device_printf(sc->dev, "Found firmware version %s\n",
|
|
|
|
sc->fw_version);
|
|
|
|
device_printf(sc->dev, "Driver needs %d.%d\n",
|
|
|
|
MXGEFW_VERSION_MAJOR, MXGEFW_VERSION_MINOR);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2007-07-19 16:16:00 +00:00
|
|
|
static void *
|
|
|
|
z_alloc(void *nil, u_int items, u_int size)
|
|
|
|
{
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
ptr = malloc(items * size, M_TEMP, M_NOWAIT);
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
z_free(void *nil, void *ptr)
|
|
|
|
{
|
|
|
|
free(ptr, M_TEMP);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
static int
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_load_firmware_helper(mxge_softc_t *sc, uint32_t *limit)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2007-07-19 16:16:00 +00:00
|
|
|
z_stream zs;
|
|
|
|
char *inflate_buffer;
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
const struct firmware *fw;
|
2006-02-19 22:39:19 +00:00
|
|
|
const mcp_gen_header_t *hdr;
|
|
|
|
unsigned hdr_offset;
|
|
|
|
int status;
|
2006-07-17 22:17:05 +00:00
|
|
|
unsigned int i;
|
|
|
|
char dummy;
|
2007-07-19 16:16:00 +00:00
|
|
|
size_t fw_len;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
fw = firmware_get(sc->fw_name);
|
|
|
|
if (fw == NULL) {
|
|
|
|
device_printf(sc->dev, "Could not find firmware image %s\n",
|
|
|
|
sc->fw_name);
|
|
|
|
return ENOENT;
|
|
|
|
}
|
2007-07-19 16:16:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* setup zlib and decompress f/w */
|
|
|
|
bzero(&zs, sizeof (zs));
|
|
|
|
zs.zalloc = z_alloc;
|
|
|
|
zs.zfree = z_free;
|
|
|
|
status = inflateInit(&zs);
|
|
|
|
if (status != Z_OK) {
|
|
|
|
status = EIO;
|
2006-02-19 22:39:19 +00:00
|
|
|
goto abort_with_fw;
|
|
|
|
}
|
2007-07-19 16:16:00 +00:00
|
|
|
|
|
|
|
/* the uncompressed size is stored as the firmware version,
|
|
|
|
which would otherwise go unused */
|
|
|
|
fw_len = (size_t) fw->version;
|
|
|
|
inflate_buffer = malloc(fw_len, M_TEMP, M_NOWAIT);
|
|
|
|
if (inflate_buffer == NULL)
|
|
|
|
goto abort_with_zs;
|
|
|
|
zs.avail_in = fw->datasize;
|
|
|
|
zs.next_in = __DECONST(char *, fw->data);
|
|
|
|
zs.avail_out = fw_len;
|
|
|
|
zs.next_out = inflate_buffer;
|
|
|
|
status = inflate(&zs, Z_FINISH);
|
|
|
|
if (status != Z_STREAM_END) {
|
|
|
|
device_printf(sc->dev, "zlib %d\n", status);
|
|
|
|
status = EIO;
|
|
|
|
goto abort_with_buffer;
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
/* check id */
|
|
|
|
hdr_offset = htobe32(*(const uint32_t *)
|
2007-07-19 16:16:00 +00:00
|
|
|
(inflate_buffer + MCP_HEADER_PTR_OFFSET));
|
|
|
|
if ((hdr_offset & 3) || hdr_offset + sizeof(*hdr) > fw_len) {
|
2006-02-19 22:39:19 +00:00
|
|
|
device_printf(sc->dev, "Bad firmware file");
|
|
|
|
status = EIO;
|
2007-07-19 16:16:00 +00:00
|
|
|
goto abort_with_buffer;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2007-07-19 16:16:00 +00:00
|
|
|
hdr = (const void*)(inflate_buffer + hdr_offset);
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2006-07-17 22:17:05 +00:00
|
|
|
status = mxge_validate_firmware(sc, hdr);
|
|
|
|
if (status != 0)
|
2007-07-19 16:16:00 +00:00
|
|
|
goto abort_with_buffer;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
/* Copy the inflated firmware to NIC SRAM. */
|
2007-07-19 16:16:00 +00:00
|
|
|
for (i = 0; i < fw_len; i += 256) {
|
2006-07-17 22:17:05 +00:00
|
|
|
mxge_pio_copy(sc->sram + MXGE_FW_OFFSET + i,
|
2007-07-19 16:16:00 +00:00
|
|
|
inflate_buffer + i,
|
|
|
|
min(256U, (unsigned)(fw_len - i)));
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2006-07-17 22:17:05 +00:00
|
|
|
dummy = *sc->sram;
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2006-07-17 22:17:05 +00:00
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2007-07-19 16:16:00 +00:00
|
|
|
*limit = fw_len;
|
2006-02-19 22:39:19 +00:00
|
|
|
status = 0;
|
2007-07-19 16:16:00 +00:00
|
|
|
abort_with_buffer:
|
|
|
|
free(inflate_buffer, M_TEMP);
|
|
|
|
abort_with_zs:
|
|
|
|
inflateEnd(&zs);
|
2006-02-19 22:39:19 +00:00
|
|
|
abort_with_fw:
|
|
|
|
firmware_put(fw, FIRMWARE_UNLOAD);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable or disable periodic RDMAs from the host to make certain
|
|
|
|
* chipsets resend dropped PCIe messages
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_dummy_rdma(mxge_softc_t *sc, int enable)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
|
|
|
char buf_bytes[72];
|
|
|
|
volatile uint32_t *confirm;
|
|
|
|
volatile char *submit;
|
|
|
|
uint32_t *buf, dma_low, dma_high;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
buf = (uint32_t *)((unsigned long)(buf_bytes + 7) & ~7UL);
|
|
|
|
|
|
|
|
/* clear confirmation addr */
|
|
|
|
confirm = (volatile uint32_t *)sc->cmd;
|
|
|
|
*confirm = 0;
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
/* send an rdma command to the PCIe engine, and wait for the
|
|
|
|
response in the confirmation address. The firmware should
|
|
|
|
write a -1 there to indicate it is alive and well
|
|
|
|
*/
|
|
|
|
|
2006-06-13 13:53:52 +00:00
|
|
|
dma_low = MXGE_LOWPART_TO_U32(sc->cmd_dma.bus_addr);
|
|
|
|
dma_high = MXGE_HIGHPART_TO_U32(sc->cmd_dma.bus_addr);
|
2006-02-19 22:39:19 +00:00
|
|
|
buf[0] = htobe32(dma_high); /* confirm addr MSW */
|
|
|
|
buf[1] = htobe32(dma_low); /* confirm addr LSW */
|
|
|
|
buf[2] = htobe32(0xffffffff); /* confirm data */
|
2006-06-13 13:53:52 +00:00
|
|
|
dma_low = MXGE_LOWPART_TO_U32(sc->zeropad_dma.bus_addr);
|
|
|
|
dma_high = MXGE_HIGHPART_TO_U32(sc->zeropad_dma.bus_addr);
|
2006-02-19 22:39:19 +00:00
|
|
|
buf[3] = htobe32(dma_high); /* dummy addr MSW */
|
|
|
|
buf[4] = htobe32(dma_low); /* dummy addr LSW */
|
|
|
|
buf[5] = htobe32(enable); /* enable? */
|
|
|
|
|
|
|
|
|
2006-09-15 19:24:45 +00:00
|
|
|
submit = (volatile char *)(sc->sram + MXGEFW_BOOT_DUMMY_RDMA);
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_pio_copy(submit, buf, 64);
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2006-02-19 22:39:19 +00:00
|
|
|
DELAY(1000);
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2006-02-19 22:39:19 +00:00
|
|
|
i = 0;
|
|
|
|
while (*confirm != 0xffffffff && i < 20) {
|
|
|
|
DELAY(1000);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (*confirm != 0xffffffff) {
|
|
|
|
device_printf(sc->dev, "dummy rdma %s failed (%p = 0x%x)",
|
|
|
|
(enable ? "enable" : "disable"), confirm,
|
|
|
|
*confirm);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_send_cmd(mxge_softc_t *sc, uint32_t cmd, mxge_cmd_t *data)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
|
|
|
mcp_cmd_t *buf;
|
|
|
|
char buf_bytes[sizeof(*buf) + 8];
|
|
|
|
volatile mcp_cmd_response_t *response = sc->cmd;
|
2006-09-15 19:24:45 +00:00
|
|
|
volatile char *cmd_addr = sc->sram + MXGEFW_ETH_CMD;
|
2006-02-19 22:39:19 +00:00
|
|
|
uint32_t dma_low, dma_high;
|
2007-05-08 18:45:43 +00:00
|
|
|
int err, sleep_total = 0;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
/* ensure buf is aligned to 8 bytes */
|
|
|
|
buf = (mcp_cmd_t *)((unsigned long)(buf_bytes + 7) & ~7UL);
|
|
|
|
|
|
|
|
buf->data0 = htobe32(data->data0);
|
|
|
|
buf->data1 = htobe32(data->data1);
|
|
|
|
buf->data2 = htobe32(data->data2);
|
|
|
|
buf->cmd = htobe32(cmd);
|
2006-06-13 13:53:52 +00:00
|
|
|
dma_low = MXGE_LOWPART_TO_U32(sc->cmd_dma.bus_addr);
|
|
|
|
dma_high = MXGE_HIGHPART_TO_U32(sc->cmd_dma.bus_addr);
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
buf->response_addr.low = htobe32(dma_low);
|
|
|
|
buf->response_addr.high = htobe32(dma_high);
|
2007-01-31 15:29:31 +00:00
|
|
|
mtx_lock(&sc->cmd_mtx);
|
2006-02-19 22:39:19 +00:00
|
|
|
response->result = 0xffffffff;
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_pio_copy((volatile void *)cmd_addr, buf, sizeof (*buf));
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2006-06-14 16:23:17 +00:00
|
|
|
/* wait up to 20ms */
|
2007-05-08 18:45:43 +00:00
|
|
|
err = EAGAIN;
|
2006-06-14 16:23:17 +00:00
|
|
|
for (sleep_total = 0; sleep_total < 20; sleep_total++) {
|
2006-02-19 22:39:19 +00:00
|
|
|
bus_dmamap_sync(sc->cmd_dma.dmat,
|
|
|
|
sc->cmd_dma.map, BUS_DMASYNC_POSTREAD);
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2007-05-08 18:45:43 +00:00
|
|
|
switch (be32toh(response->result)) {
|
|
|
|
case 0:
|
|
|
|
data->data0 = be32toh(response->data);
|
|
|
|
err = 0;
|
|
|
|
break;
|
|
|
|
case 0xffffffff:
|
|
|
|
DELAY(1000);
|
|
|
|
break;
|
|
|
|
case MXGEFW_CMD_UNKNOWN:
|
|
|
|
err = ENOSYS;
|
|
|
|
break;
|
|
|
|
case MXGEFW_CMD_ERROR_UNALIGNED:
|
|
|
|
err = E2BIG;
|
|
|
|
break;
|
2007-08-22 13:22:12 +00:00
|
|
|
case MXGEFW_CMD_ERROR_BUSY:
|
|
|
|
err = EBUSY;
|
|
|
|
break;
|
2007-05-08 18:45:43 +00:00
|
|
|
default:
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"mxge: command %d "
|
|
|
|
"failed, result = %d\n",
|
|
|
|
cmd, be32toh(response->result));
|
|
|
|
err = ENXIO;
|
|
|
|
break;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2007-05-08 18:45:43 +00:00
|
|
|
if (err != EAGAIN)
|
|
|
|
break;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2007-05-08 18:45:43 +00:00
|
|
|
if (err == EAGAIN)
|
|
|
|
device_printf(sc->dev, "mxge: command %d timed out"
|
|
|
|
"result = %d\n",
|
|
|
|
cmd, be32toh(response->result));
|
2007-01-31 15:29:31 +00:00
|
|
|
mtx_unlock(&sc->cmd_mtx);
|
2007-05-08 18:45:43 +00:00
|
|
|
return err;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
2006-07-17 22:17:05 +00:00
|
|
|
static int
|
|
|
|
mxge_adopt_running_firmware(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
struct mcp_gen_header *hdr;
|
|
|
|
const size_t bytes = sizeof (struct mcp_gen_header);
|
|
|
|
size_t hdr_offset;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
/* find running firmware header */
|
|
|
|
hdr_offset = htobe32(*(volatile uint32_t *)
|
|
|
|
(sc->sram + MCP_HEADER_PTR_OFFSET));
|
|
|
|
|
|
|
|
if ((hdr_offset & 3) || hdr_offset + sizeof(*hdr) > sc->sram_size) {
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"Running firmware has bad header offset (%d)\n",
|
|
|
|
(int)hdr_offset);
|
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy header of running firmware from SRAM to host memory to
|
|
|
|
* validate firmware */
|
|
|
|
hdr = malloc(bytes, M_DEVBUF, M_NOWAIT);
|
|
|
|
if (hdr == NULL) {
|
|
|
|
device_printf(sc->dev, "could not malloc firmware hdr\n");
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
bus_space_read_region_1(rman_get_bustag(sc->mem_res),
|
|
|
|
rman_get_bushandle(sc->mem_res),
|
|
|
|
hdr_offset, (char *)hdr, bytes);
|
|
|
|
status = mxge_validate_firmware(sc, hdr);
|
|
|
|
free(hdr, M_DEVBUF);
|
2007-02-21 17:34:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* check to see if adopted firmware has bug where adopting
|
|
|
|
* it will cause broadcasts to be filtered unless the NIC
|
|
|
|
* is kept in ALLMULTI mode
|
|
|
|
*/
|
|
|
|
if (sc->fw_ver_major == 1 && sc->fw_ver_minor == 4 &&
|
|
|
|
sc->fw_ver_tiny >= 4 && sc->fw_ver_tiny <= 11) {
|
|
|
|
sc->adopted_rx_filter_bug = 1;
|
|
|
|
device_printf(sc->dev, "Adopting fw %d.%d.%d: "
|
|
|
|
"working around rx filter bug\n",
|
|
|
|
sc->fw_ver_major, sc->fw_ver_minor,
|
|
|
|
sc->fw_ver_tiny);
|
|
|
|
}
|
|
|
|
|
2006-07-17 22:17:05 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
static int
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_load_firmware(mxge_softc_t *sc, int adopt)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
|
|
|
volatile uint32_t *confirm;
|
|
|
|
volatile char *submit;
|
|
|
|
char buf_bytes[72];
|
|
|
|
uint32_t *buf, size, dma_low, dma_high;
|
|
|
|
int status, i;
|
|
|
|
|
|
|
|
buf = (uint32_t *)((unsigned long)(buf_bytes + 7) & ~7UL);
|
|
|
|
|
|
|
|
size = sc->sram_size;
|
2006-06-13 13:53:52 +00:00
|
|
|
status = mxge_load_firmware_helper(sc, &size);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (status) {
|
2008-01-15 20:34:49 +00:00
|
|
|
if (!adopt)
|
|
|
|
return status;
|
2006-07-17 22:17:05 +00:00
|
|
|
/* Try to use the currently running firmware, if
|
|
|
|
it is new enough */
|
|
|
|
status = mxge_adopt_running_firmware(sc);
|
|
|
|
if (status) {
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"failed to adopt running firmware\n");
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"Successfully adopted running firmware\n");
|
2008-01-15 20:34:49 +00:00
|
|
|
if (sc->tx_boundary == 4096) {
|
2006-07-17 22:17:05 +00:00
|
|
|
device_printf(sc->dev,
|
|
|
|
"Using firmware currently running on NIC"
|
|
|
|
". For optimal\n");
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"performance consider loading optimized "
|
|
|
|
"firmware\n");
|
|
|
|
}
|
2006-11-22 16:33:40 +00:00
|
|
|
sc->fw_name = mxge_fw_unaligned;
|
2008-01-15 20:34:49 +00:00
|
|
|
sc->tx_boundary = 2048;
|
2006-11-22 16:33:40 +00:00
|
|
|
return 0;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
/* clear confirmation addr */
|
|
|
|
confirm = (volatile uint32_t *)sc->cmd;
|
|
|
|
*confirm = 0;
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2006-02-19 22:39:19 +00:00
|
|
|
/* send a reload command to the bootstrap MCP, and wait for the
|
|
|
|
response in the confirmation address. The firmware should
|
|
|
|
write a -1 there to indicate it is alive and well
|
|
|
|
*/
|
|
|
|
|
2006-06-13 13:53:52 +00:00
|
|
|
dma_low = MXGE_LOWPART_TO_U32(sc->cmd_dma.bus_addr);
|
|
|
|
dma_high = MXGE_HIGHPART_TO_U32(sc->cmd_dma.bus_addr);
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
buf[0] = htobe32(dma_high); /* confirm addr MSW */
|
|
|
|
buf[1] = htobe32(dma_low); /* confirm addr LSW */
|
|
|
|
buf[2] = htobe32(0xffffffff); /* confirm data */
|
|
|
|
|
|
|
|
/* FIX: All newest firmware should un-protect the bottom of
|
|
|
|
the sram before handoff. However, the very first interfaces
|
|
|
|
do not. Therefore the handoff copy must skip the first 8 bytes
|
|
|
|
*/
|
|
|
|
/* where the code starts*/
|
2006-06-13 13:53:52 +00:00
|
|
|
buf[3] = htobe32(MXGE_FW_OFFSET + 8);
|
2006-02-19 22:39:19 +00:00
|
|
|
buf[4] = htobe32(size - 8); /* length of code */
|
|
|
|
buf[5] = htobe32(8); /* where to copy to */
|
|
|
|
buf[6] = htobe32(0); /* where to jump to */
|
|
|
|
|
2006-09-15 19:24:45 +00:00
|
|
|
submit = (volatile char *)(sc->sram + MXGEFW_BOOT_HANDOFF);
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_pio_copy(submit, buf, 64);
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2006-02-19 22:39:19 +00:00
|
|
|
DELAY(1000);
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2006-02-19 22:39:19 +00:00
|
|
|
i = 0;
|
|
|
|
while (*confirm != 0xffffffff && i < 20) {
|
|
|
|
DELAY(1000*10);
|
|
|
|
i++;
|
|
|
|
bus_dmamap_sync(sc->cmd_dma.dmat,
|
|
|
|
sc->cmd_dma.map, BUS_DMASYNC_POSTREAD);
|
|
|
|
}
|
|
|
|
if (*confirm != 0xffffffff) {
|
|
|
|
device_printf(sc->dev,"handoff failed (%p = 0x%x)",
|
|
|
|
confirm, *confirm);
|
|
|
|
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_update_mac_address(mxge_softc_t *sc)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_cmd_t cmd;
|
2006-02-19 22:39:19 +00:00
|
|
|
uint8_t *addr = sc->mac_addr;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
|
|
|
|
cmd.data0 = ((addr[0] << 24) | (addr[1] << 16)
|
|
|
|
| (addr[2] << 8) | addr[3]);
|
|
|
|
|
|
|
|
cmd.data1 = ((addr[4] << 8) | (addr[5]));
|
|
|
|
|
2006-06-14 16:23:17 +00:00
|
|
|
status = mxge_send_cmd(sc, MXGEFW_SET_MAC_ADDRESS, &cmd);
|
2006-02-19 22:39:19 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_change_pause(mxge_softc_t *sc, int pause)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_cmd_t cmd;
|
2006-02-19 22:39:19 +00:00
|
|
|
int status;
|
|
|
|
|
|
|
|
if (pause)
|
2006-06-14 16:23:17 +00:00
|
|
|
status = mxge_send_cmd(sc, MXGEFW_ENABLE_FLOW_CONTROL,
|
2006-06-13 13:53:52 +00:00
|
|
|
&cmd);
|
2006-02-19 22:39:19 +00:00
|
|
|
else
|
2006-06-14 16:23:17 +00:00
|
|
|
status = mxge_send_cmd(sc, MXGEFW_DISABLE_FLOW_CONTROL,
|
2006-06-13 13:53:52 +00:00
|
|
|
&cmd);
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
if (status) {
|
|
|
|
device_printf(sc->dev, "Failed to set flow control mode\n");
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
sc->pause = pause;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_change_promisc(mxge_softc_t *sc, int promisc)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_cmd_t cmd;
|
2006-02-19 22:39:19 +00:00
|
|
|
int status;
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
if (mxge_always_promisc)
|
|
|
|
promisc = 1;
|
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
if (promisc)
|
2006-06-14 16:23:17 +00:00
|
|
|
status = mxge_send_cmd(sc, MXGEFW_ENABLE_PROMISC,
|
2006-06-13 13:53:52 +00:00
|
|
|
&cmd);
|
2006-02-19 22:39:19 +00:00
|
|
|
else
|
2006-06-14 16:23:17 +00:00
|
|
|
status = mxge_send_cmd(sc, MXGEFW_DISABLE_PROMISC,
|
2006-06-13 13:53:52 +00:00
|
|
|
&cmd);
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
if (status) {
|
|
|
|
device_printf(sc->dev, "Failed to set promisc mode\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-15 19:24:45 +00:00
|
|
|
static void
|
|
|
|
mxge_set_multicast_list(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
mxge_cmd_t cmd;
|
|
|
|
struct ifmultiaddr *ifma;
|
|
|
|
struct ifnet *ifp = sc->ifp;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* This firmware is known to not support multicast */
|
|
|
|
if (!sc->fw_multicast_support)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Disable multicast filtering while we play with the lists*/
|
|
|
|
err = mxge_send_cmd(sc, MXGEFW_ENABLE_ALLMULTI, &cmd);
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "Failed MXGEFW_ENABLE_ALLMULTI,"
|
|
|
|
" error status: %d\n", err);
|
|
|
|
return;
|
|
|
|
}
|
2007-02-21 17:34:05 +00:00
|
|
|
|
|
|
|
if (sc->adopted_rx_filter_bug)
|
|
|
|
return;
|
2006-09-15 19:24:45 +00:00
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_ALLMULTI)
|
|
|
|
/* request to disable multicast filtering, so quit here */
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Flush all the filters */
|
|
|
|
|
|
|
|
err = mxge_send_cmd(sc, MXGEFW_LEAVE_ALL_MULTICAST_GROUPS, &cmd);
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"Failed MXGEFW_LEAVE_ALL_MULTICAST_GROUPS"
|
|
|
|
", error status: %d\n", err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Walk the multicast list, and add each address */
|
|
|
|
|
|
|
|
IF_ADDR_LOCK(ifp);
|
|
|
|
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
|
|
|
|
if (ifma->ifma_addr->sa_family != AF_LINK)
|
|
|
|
continue;
|
|
|
|
bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
|
|
|
|
&cmd.data0, 4);
|
|
|
|
bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr) + 4,
|
|
|
|
&cmd.data1, 2);
|
|
|
|
cmd.data0 = htonl(cmd.data0);
|
|
|
|
cmd.data1 = htonl(cmd.data1);
|
|
|
|
err = mxge_send_cmd(sc, MXGEFW_JOIN_MULTICAST_GROUP, &cmd);
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "Failed "
|
|
|
|
"MXGEFW_JOIN_MULTICAST_GROUP, error status:"
|
|
|
|
"%d\t", err);
|
|
|
|
/* abort, leaving multicast filtering off */
|
|
|
|
IF_ADDR_UNLOCK(ifp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IF_ADDR_UNLOCK(ifp);
|
|
|
|
/* Enable multicast filtering */
|
|
|
|
err = mxge_send_cmd(sc, MXGEFW_DISABLE_ALLMULTI, &cmd);
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "Failed MXGEFW_DISABLE_ALLMULTI"
|
|
|
|
", error status: %d\n", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-21 18:32:27 +00:00
|
|
|
static int
|
|
|
|
mxge_max_mtu(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
mxge_cmd_t cmd;
|
|
|
|
int status;
|
|
|
|
|
2007-05-23 16:25:40 +00:00
|
|
|
if (MJUMPAGESIZE - MXGEFW_PAD > MXGEFW_MAX_MTU)
|
|
|
|
return MXGEFW_MAX_MTU - MXGEFW_PAD;
|
2007-05-21 18:32:27 +00:00
|
|
|
|
|
|
|
/* try to set nbufs to see if it we can
|
|
|
|
use virtually contiguous jumbos */
|
|
|
|
cmd.data0 = 0;
|
|
|
|
status = mxge_send_cmd(sc, MXGEFW_CMD_ALWAYS_USE_N_BIG_BUFFERS,
|
|
|
|
&cmd);
|
|
|
|
if (status == 0)
|
2007-05-23 16:25:40 +00:00
|
|
|
return MXGEFW_MAX_MTU - MXGEFW_PAD;
|
2007-05-21 18:32:27 +00:00
|
|
|
|
|
|
|
/* otherwise, we're limited to MJUMPAGESIZE */
|
|
|
|
return MJUMPAGESIZE - MXGEFW_PAD;
|
|
|
|
}
|
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
static int
|
2007-05-22 15:57:49 +00:00
|
|
|
mxge_reset(mxge_softc_t *sc, int interrupts_setup)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2008-01-15 20:34:49 +00:00
|
|
|
struct mxge_slice_state *ss;
|
|
|
|
mxge_rx_done_t *rx_done;
|
|
|
|
volatile uint32_t *irq_claim;
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_cmd_t cmd;
|
2008-01-15 20:34:49 +00:00
|
|
|
int slice, status;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
/* try to send a reset command to the card to see if it
|
|
|
|
is alive */
|
|
|
|
memset(&cmd, 0, sizeof (cmd));
|
2006-06-14 16:23:17 +00:00
|
|
|
status = mxge_send_cmd(sc, MXGEFW_CMD_RESET, &cmd);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (status != 0) {
|
|
|
|
device_printf(sc->dev, "failed reset\n");
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
2006-08-01 14:02:54 +00:00
|
|
|
mxge_dummy_rdma(sc, 1);
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
|
|
|
|
/* set the intrq size */
|
|
|
|
cmd.data0 = sc->rx_ring_size;
|
|
|
|
status = mxge_send_cmd(sc, MXGEFW_CMD_SET_INTRQ_SIZE, &cmd);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Even though we already know how many slices are supported
|
|
|
|
* via mxge_slice_probe(), MXGEFW_CMD_GET_MAX_RSS_QUEUES
|
|
|
|
* has magic side effects, and must be called after a reset.
|
|
|
|
* It must be called prior to calling any RSS related cmds,
|
|
|
|
* including assigning an interrupt queue for anything but
|
|
|
|
* slice 0. It must also be called *after*
|
|
|
|
* MXGEFW_CMD_SET_INTRQ_SIZE, since the intrq size is used by
|
|
|
|
* the firmware to compute offsets.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (sc->num_slices > 1) {
|
|
|
|
/* ask the maximum number of slices it supports */
|
|
|
|
status = mxge_send_cmd(sc, MXGEFW_CMD_GET_MAX_RSS_QUEUES,
|
|
|
|
&cmd);
|
|
|
|
if (status != 0) {
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"failed to get number of slices\n");
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* MXGEFW_CMD_ENABLE_RSS_QUEUES must be called prior
|
|
|
|
* to setting up the interrupt queue DMA
|
|
|
|
*/
|
|
|
|
cmd.data0 = sc->num_slices;
|
|
|
|
cmd.data1 = MXGEFW_SLICE_INTR_MODE_ONE_PER_SLICE;
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
cmd.data1 |= MXGEFW_SLICE_ENABLE_MULTIPLE_TX_QUEUES;
|
|
|
|
#endif
|
2008-01-15 20:34:49 +00:00
|
|
|
status = mxge_send_cmd(sc, MXGEFW_CMD_ENABLE_RSS_QUEUES,
|
|
|
|
&cmd);
|
|
|
|
if (status != 0) {
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"failed to set number of slices\n");
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-22 15:57:49 +00:00
|
|
|
if (interrupts_setup) {
|
|
|
|
/* Now exchange information about interrupts */
|
2008-01-15 20:34:49 +00:00
|
|
|
for (slice = 0; slice < sc->num_slices; slice++) {
|
|
|
|
rx_done = &sc->ss[slice].rx_done;
|
|
|
|
memset(rx_done->entry, 0, sc->rx_ring_size);
|
|
|
|
cmd.data0 = MXGE_LOWPART_TO_U32(rx_done->dma.bus_addr);
|
|
|
|
cmd.data1 = MXGE_HIGHPART_TO_U32(rx_done->dma.bus_addr);
|
|
|
|
cmd.data2 = slice;
|
|
|
|
status |= mxge_send_cmd(sc,
|
|
|
|
MXGEFW_CMD_SET_INTRQ_DMA,
|
|
|
|
&cmd);
|
|
|
|
}
|
2007-05-22 15:57:49 +00:00
|
|
|
}
|
2006-06-14 16:23:17 +00:00
|
|
|
|
|
|
|
status |= mxge_send_cmd(sc,
|
|
|
|
MXGEFW_CMD_GET_INTR_COAL_DELAY_OFFSET, &cmd);
|
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2006-06-14 16:23:17 +00:00
|
|
|
sc->intr_coal_delay_ptr = (volatile uint32_t *)(sc->sram + cmd.data0);
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2006-06-14 16:23:17 +00:00
|
|
|
status |= mxge_send_cmd(sc, MXGEFW_CMD_GET_IRQ_ACK_OFFSET, &cmd);
|
2008-01-15 20:34:49 +00:00
|
|
|
irq_claim = (volatile uint32_t *)(sc->sram + cmd.data0);
|
2006-06-14 16:23:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
status |= mxge_send_cmd(sc, MXGEFW_CMD_GET_IRQ_DEASSERT_OFFSET,
|
|
|
|
&cmd);
|
|
|
|
sc->irq_deassert = (volatile uint32_t *)(sc->sram + cmd.data0);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (status != 0) {
|
|
|
|
device_printf(sc->dev, "failed set interrupt parameters\n");
|
|
|
|
return status;
|
|
|
|
}
|
2006-06-14 16:23:17 +00:00
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2006-06-14 16:23:17 +00:00
|
|
|
*sc->intr_coal_delay_ptr = htobe32(sc->intr_coal_delay);
|
|
|
|
|
|
|
|
|
|
|
|
/* run a DMA benchmark */
|
2007-05-08 14:19:43 +00:00
|
|
|
(void) mxge_dma_test(sc, MXGEFW_DMA_TEST);
|
2006-06-14 16:23:17 +00:00
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
for (slice = 0; slice < sc->num_slices; slice++) {
|
|
|
|
ss = &sc->ss[slice];
|
|
|
|
|
|
|
|
ss->irq_claim = irq_claim + (2 * slice);
|
|
|
|
/* reset mcp/driver shared state back to 0 */
|
|
|
|
ss->rx_done.idx = 0;
|
|
|
|
ss->rx_done.cnt = 0;
|
|
|
|
ss->tx.req = 0;
|
|
|
|
ss->tx.done = 0;
|
|
|
|
ss->tx.pkt_done = 0;
|
2009-04-27 15:45:54 +00:00
|
|
|
ss->tx.queue_active = 0;
|
|
|
|
ss->tx.activate = 0;
|
|
|
|
ss->tx.deactivate = 0;
|
2008-01-15 20:34:49 +00:00
|
|
|
ss->tx.wake = 0;
|
|
|
|
ss->tx.defrag = 0;
|
|
|
|
ss->tx.stall = 0;
|
|
|
|
ss->rx_big.cnt = 0;
|
|
|
|
ss->rx_small.cnt = 0;
|
|
|
|
ss->lro_bad_csum = 0;
|
|
|
|
ss->lro_queued = 0;
|
|
|
|
ss->lro_flushed = 0;
|
|
|
|
if (ss->fw_stats != NULL) {
|
|
|
|
ss->fw_stats->valid = 0;
|
|
|
|
ss->fw_stats->send_done_count = 0;
|
|
|
|
}
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
sc->rdma_tags_available = 15;
|
2006-06-13 13:53:52 +00:00
|
|
|
status = mxge_update_mac_address(sc);
|
|
|
|
mxge_change_promisc(sc, 0);
|
|
|
|
mxge_change_pause(sc, sc->pause);
|
2006-09-15 19:24:45 +00:00
|
|
|
mxge_set_multicast_list(sc);
|
2006-02-19 22:39:19 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_change_intr_coal(SYSCTL_HANDLER_ARGS)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_softc_t *sc;
|
2006-02-19 22:39:19 +00:00
|
|
|
unsigned int intr_coal_delay;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
sc = arg1;
|
|
|
|
intr_coal_delay = sc->intr_coal_delay;
|
|
|
|
err = sysctl_handle_int(oidp, &intr_coal_delay, arg2, req);
|
|
|
|
if (err != 0) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if (intr_coal_delay == sc->intr_coal_delay)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (intr_coal_delay == 0 || intr_coal_delay > 1000*1000)
|
|
|
|
return EINVAL;
|
|
|
|
|
2007-01-31 15:29:31 +00:00
|
|
|
mtx_lock(&sc->driver_mtx);
|
2006-06-14 16:23:17 +00:00
|
|
|
*sc->intr_coal_delay_ptr = htobe32(intr_coal_delay);
|
|
|
|
sc->intr_coal_delay = intr_coal_delay;
|
|
|
|
|
2007-01-31 15:29:31 +00:00
|
|
|
mtx_unlock(&sc->driver_mtx);
|
2006-02-19 22:39:19 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_change_flow_control(SYSCTL_HANDLER_ARGS)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_softc_t *sc;
|
2006-02-19 22:39:19 +00:00
|
|
|
unsigned int enabled;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
sc = arg1;
|
|
|
|
enabled = sc->pause;
|
|
|
|
err = sysctl_handle_int(oidp, &enabled, arg2, req);
|
|
|
|
if (err != 0) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if (enabled == sc->pause)
|
|
|
|
return 0;
|
|
|
|
|
2007-01-31 15:29:31 +00:00
|
|
|
mtx_lock(&sc->driver_mtx);
|
2006-06-13 13:53:52 +00:00
|
|
|
err = mxge_change_pause(sc, enabled);
|
2007-01-31 15:29:31 +00:00
|
|
|
mtx_unlock(&sc->driver_mtx);
|
2006-02-19 22:39:19 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2007-06-12 19:15:16 +00:00
|
|
|
static int
|
|
|
|
mxge_change_lro_locked(mxge_softc_t *sc, int lro_cnt)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
2007-08-22 13:22:12 +00:00
|
|
|
int err = 0;
|
2007-06-12 19:15:16 +00:00
|
|
|
|
|
|
|
ifp = sc->ifp;
|
|
|
|
if (lro_cnt == 0)
|
|
|
|
ifp->if_capenable &= ~IFCAP_LRO;
|
|
|
|
else
|
|
|
|
ifp->if_capenable |= IFCAP_LRO;
|
|
|
|
sc->lro_cnt = lro_cnt;
|
2007-08-22 13:22:12 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
|
|
|
|
mxge_close(sc);
|
|
|
|
err = mxge_open(sc);
|
|
|
|
}
|
2007-06-12 19:15:16 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2007-06-11 14:01:10 +00:00
|
|
|
static int
|
|
|
|
mxge_change_lro(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
mxge_softc_t *sc;
|
|
|
|
unsigned int lro_cnt;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
sc = arg1;
|
|
|
|
lro_cnt = sc->lro_cnt;
|
|
|
|
err = sysctl_handle_int(oidp, &lro_cnt, arg2, req);
|
|
|
|
if (err != 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (lro_cnt == sc->lro_cnt)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (lro_cnt > 128)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
mtx_lock(&sc->driver_mtx);
|
2007-06-12 19:15:16 +00:00
|
|
|
err = mxge_change_lro_locked(sc, lro_cnt);
|
2007-06-11 14:01:10 +00:00
|
|
|
mtx_unlock(&sc->driver_mtx);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
static int
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_handle_be32(SYSCTL_HANDLER_ARGS)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (arg1 == NULL)
|
|
|
|
return EFAULT;
|
|
|
|
arg2 = be32toh(*(int *)arg1);
|
|
|
|
arg1 = NULL;
|
|
|
|
err = sysctl_handle_int(oidp, arg1, arg2, req);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
static void
|
|
|
|
mxge_rem_sysctls(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
struct mxge_slice_state *ss;
|
|
|
|
int slice;
|
|
|
|
|
|
|
|
if (sc->slice_sysctl_tree == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (slice = 0; slice < sc->num_slices; slice++) {
|
|
|
|
ss = &sc->ss[slice];
|
|
|
|
if (ss == NULL || ss->sysctl_tree == NULL)
|
|
|
|
continue;
|
|
|
|
sysctl_ctx_free(&ss->sysctl_ctx);
|
|
|
|
ss->sysctl_tree = NULL;
|
|
|
|
}
|
|
|
|
sysctl_ctx_free(&sc->slice_sysctl_ctx);
|
|
|
|
sc->slice_sysctl_tree = NULL;
|
|
|
|
}
|
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
static void
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_add_sysctls(mxge_softc_t *sc)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
|
|
|
struct sysctl_ctx_list *ctx;
|
|
|
|
struct sysctl_oid_list *children;
|
2006-06-14 16:23:17 +00:00
|
|
|
mcp_irq_data_t *fw;
|
2008-01-15 20:34:49 +00:00
|
|
|
struct mxge_slice_state *ss;
|
|
|
|
int slice;
|
|
|
|
char slice_num[8];
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
ctx = device_get_sysctl_ctx(sc->dev);
|
|
|
|
children = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev));
|
2008-01-15 20:34:49 +00:00
|
|
|
fw = sc->ss[0].fw_stats;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2006-06-14 16:23:17 +00:00
|
|
|
/* random information */
|
|
|
|
SYSCTL_ADD_STRING(ctx, children, OID_AUTO,
|
|
|
|
"firmware_version",
|
|
|
|
CTLFLAG_RD, &sc->fw_version,
|
|
|
|
0, "firmware version");
|
|
|
|
SYSCTL_ADD_STRING(ctx, children, OID_AUTO,
|
|
|
|
"serial_number",
|
|
|
|
CTLFLAG_RD, &sc->serial_number_string,
|
|
|
|
0, "serial number");
|
|
|
|
SYSCTL_ADD_STRING(ctx, children, OID_AUTO,
|
|
|
|
"product_code",
|
|
|
|
CTLFLAG_RD, &sc->product_code_string,
|
|
|
|
0, "product_code");
|
2006-11-22 16:33:40 +00:00
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"pcie_link_width",
|
|
|
|
CTLFLAG_RD, &sc->link_width,
|
|
|
|
0, "tx_boundary");
|
2006-06-14 16:23:17 +00:00
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"tx_boundary",
|
2008-01-15 20:34:49 +00:00
|
|
|
CTLFLAG_RD, &sc->tx_boundary,
|
2006-06-14 16:23:17 +00:00
|
|
|
0, "tx_boundary");
|
2006-08-01 14:02:54 +00:00
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"write_combine",
|
|
|
|
CTLFLAG_RD, &sc->wc,
|
|
|
|
0, "write combining PIO?");
|
2006-06-14 16:23:17 +00:00
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"read_dma_MBs",
|
|
|
|
CTLFLAG_RD, &sc->read_dma,
|
|
|
|
0, "DMA Read speed in MB/s");
|
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"write_dma_MBs",
|
|
|
|
CTLFLAG_RD, &sc->write_dma,
|
|
|
|
0, "DMA Write speed in MB/s");
|
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"read_write_dma_MBs",
|
|
|
|
CTLFLAG_RD, &sc->read_write_dma,
|
|
|
|
0, "DMA concurrent Read/Write speed in MB/s");
|
|
|
|
|
|
|
|
|
|
|
|
/* performance related tunables */
|
2006-02-19 22:39:19 +00:00
|
|
|
SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
|
|
|
|
"intr_coal_delay",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RW, sc,
|
2006-06-13 13:53:52 +00:00
|
|
|
0, mxge_change_intr_coal,
|
2006-02-19 22:39:19 +00:00
|
|
|
"I", "interrupt coalescing delay in usecs");
|
|
|
|
|
|
|
|
SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
|
|
|
|
"flow_control_enabled",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RW, sc,
|
2006-06-13 13:53:52 +00:00
|
|
|
0, mxge_change_flow_control,
|
2006-02-19 22:39:19 +00:00
|
|
|
"I", "interrupt coalescing delay in usecs");
|
|
|
|
|
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
2006-06-14 16:23:17 +00:00
|
|
|
"deassert_wait",
|
|
|
|
CTLFLAG_RW, &mxge_deassert_wait,
|
|
|
|
0, "Wait for IRQ line to go low in ihandler");
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
/* stats block from firmware is in network byte order.
|
|
|
|
Need to swap it */
|
|
|
|
SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
|
|
|
|
"link_up",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RD, &fw->link_up,
|
2006-06-13 13:53:52 +00:00
|
|
|
0, mxge_handle_be32,
|
2006-02-19 22:39:19 +00:00
|
|
|
"I", "link up");
|
|
|
|
SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
|
|
|
|
"rdma_tags_available",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RD, &fw->rdma_tags_available,
|
2006-06-13 13:53:52 +00:00
|
|
|
0, mxge_handle_be32,
|
2006-02-19 22:39:19 +00:00
|
|
|
"I", "rdma_tags_available");
|
|
|
|
SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
|
2007-05-22 15:57:49 +00:00
|
|
|
"dropped_bad_crc32",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RD,
|
|
|
|
&fw->dropped_bad_crc32,
|
2006-06-13 13:53:52 +00:00
|
|
|
0, mxge_handle_be32,
|
2007-05-22 15:57:49 +00:00
|
|
|
"I", "dropped_bad_crc32");
|
|
|
|
SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
|
|
|
|
"dropped_bad_phy",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RD,
|
|
|
|
&fw->dropped_bad_phy,
|
|
|
|
0, mxge_handle_be32,
|
|
|
|
"I", "dropped_bad_phy");
|
2006-02-19 22:39:19 +00:00
|
|
|
SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
|
|
|
|
"dropped_link_error_or_filtered",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RD,
|
|
|
|
&fw->dropped_link_error_or_filtered,
|
2006-06-13 13:53:52 +00:00
|
|
|
0, mxge_handle_be32,
|
2006-02-19 22:39:19 +00:00
|
|
|
"I", "dropped_link_error_or_filtered");
|
2007-05-22 15:57:49 +00:00
|
|
|
SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
|
|
|
|
"dropped_link_overflow",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RD, &fw->dropped_link_overflow,
|
|
|
|
0, mxge_handle_be32,
|
|
|
|
"I", "dropped_link_overflow");
|
2006-09-15 19:24:45 +00:00
|
|
|
SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
|
|
|
|
"dropped_multicast_filtered",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RD,
|
|
|
|
&fw->dropped_multicast_filtered,
|
|
|
|
0, mxge_handle_be32,
|
|
|
|
"I", "dropped_multicast_filtered");
|
2006-02-19 22:39:19 +00:00
|
|
|
SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
|
2007-05-22 15:57:49 +00:00
|
|
|
"dropped_no_big_buffer",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RD, &fw->dropped_no_big_buffer,
|
2006-06-13 13:53:52 +00:00
|
|
|
0, mxge_handle_be32,
|
2007-05-22 15:57:49 +00:00
|
|
|
"I", "dropped_no_big_buffer");
|
|
|
|
SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
|
|
|
|
"dropped_no_small_buffer",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RD,
|
|
|
|
&fw->dropped_no_small_buffer,
|
|
|
|
0, mxge_handle_be32,
|
|
|
|
"I", "dropped_no_small_buffer");
|
2006-02-19 22:39:19 +00:00
|
|
|
SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
|
|
|
|
"dropped_overrun",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RD, &fw->dropped_overrun,
|
2006-06-13 13:53:52 +00:00
|
|
|
0, mxge_handle_be32,
|
2006-02-19 22:39:19 +00:00
|
|
|
"I", "dropped_overrun");
|
|
|
|
SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
|
2007-05-22 15:57:49 +00:00
|
|
|
"dropped_pause",
|
2006-02-19 22:39:19 +00:00
|
|
|
CTLTYPE_INT|CTLFLAG_RD,
|
2007-05-22 15:57:49 +00:00
|
|
|
&fw->dropped_pause,
|
2006-06-13 13:53:52 +00:00
|
|
|
0, mxge_handle_be32,
|
2007-05-22 15:57:49 +00:00
|
|
|
"I", "dropped_pause");
|
2006-02-19 22:39:19 +00:00
|
|
|
SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
|
2007-05-22 15:57:49 +00:00
|
|
|
"dropped_runt",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RD, &fw->dropped_runt,
|
2006-06-13 13:53:52 +00:00
|
|
|
0, mxge_handle_be32,
|
2007-05-22 15:57:49 +00:00
|
|
|
"I", "dropped_runt");
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2007-05-25 19:38:32 +00:00
|
|
|
SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
|
|
|
|
"dropped_unicast_filtered",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RD, &fw->dropped_unicast_filtered,
|
|
|
|
0, mxge_handle_be32,
|
|
|
|
"I", "dropped_unicast_filtered");
|
|
|
|
|
2006-06-14 16:23:17 +00:00
|
|
|
/* verbose printing? */
|
2006-02-19 22:39:19 +00:00
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
2006-06-14 16:23:17 +00:00
|
|
|
"verbose",
|
|
|
|
CTLFLAG_RW, &mxge_verbose,
|
|
|
|
0, "verbose printing");
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2007-05-21 18:32:27 +00:00
|
|
|
/* lro */
|
2007-06-11 14:01:10 +00:00
|
|
|
SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
|
|
|
|
"lro_cnt",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RW, sc,
|
|
|
|
0, mxge_change_lro,
|
|
|
|
"I", "number of lro merge queues");
|
2007-05-21 18:32:27 +00:00
|
|
|
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
/* add counters exported for debugging from all slices */
|
|
|
|
sysctl_ctx_init(&sc->slice_sysctl_ctx);
|
|
|
|
sc->slice_sysctl_tree =
|
|
|
|
SYSCTL_ADD_NODE(&sc->slice_sysctl_ctx, children, OID_AUTO,
|
|
|
|
"slice", CTLFLAG_RD, 0, "");
|
|
|
|
|
|
|
|
for (slice = 0; slice < sc->num_slices; slice++) {
|
|
|
|
ss = &sc->ss[slice];
|
|
|
|
sysctl_ctx_init(&ss->sysctl_ctx);
|
|
|
|
ctx = &ss->sysctl_ctx;
|
|
|
|
children = SYSCTL_CHILDREN(sc->slice_sysctl_tree);
|
|
|
|
sprintf(slice_num, "%d", slice);
|
|
|
|
ss->sysctl_tree =
|
|
|
|
SYSCTL_ADD_NODE(ctx, children, OID_AUTO, slice_num,
|
|
|
|
CTLFLAG_RD, 0, "");
|
|
|
|
children = SYSCTL_CHILDREN(ss->sysctl_tree);
|
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"rx_small_cnt",
|
|
|
|
CTLFLAG_RD, &ss->rx_small.cnt,
|
|
|
|
0, "rx_small_cnt");
|
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"rx_big_cnt",
|
|
|
|
CTLFLAG_RD, &ss->rx_big.cnt,
|
|
|
|
0, "rx_small_cnt");
|
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"lro_flushed", CTLFLAG_RD, &ss->lro_flushed,
|
|
|
|
0, "number of lro merge queues flushed");
|
|
|
|
|
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"lro_queued", CTLFLAG_RD, &ss->lro_queued,
|
|
|
|
0, "number of frames appended to lro merge"
|
|
|
|
"queues");
|
|
|
|
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifndef IFNET_BUF_RING
|
2008-01-15 20:34:49 +00:00
|
|
|
/* only transmit from slice 0 for now */
|
|
|
|
if (slice > 0)
|
|
|
|
continue;
|
2009-04-27 15:45:54 +00:00
|
|
|
#endif
|
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"tx_req",
|
|
|
|
CTLFLAG_RD, &ss->tx.req,
|
|
|
|
0, "tx_req");
|
2007-05-21 18:32:27 +00:00
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"tx_done",
|
|
|
|
CTLFLAG_RD, &ss->tx.done,
|
|
|
|
0, "tx_done");
|
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"tx_pkt_done",
|
|
|
|
CTLFLAG_RD, &ss->tx.pkt_done,
|
|
|
|
0, "tx_done");
|
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"tx_stall",
|
|
|
|
CTLFLAG_RD, &ss->tx.stall,
|
|
|
|
0, "tx_stall");
|
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"tx_wake",
|
|
|
|
CTLFLAG_RD, &ss->tx.wake,
|
|
|
|
0, "tx_wake");
|
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"tx_defrag",
|
|
|
|
CTLFLAG_RD, &ss->tx.defrag,
|
|
|
|
0, "tx_defrag");
|
2009-04-27 15:45:54 +00:00
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"tx_queue_active",
|
|
|
|
CTLFLAG_RD, &ss->tx.queue_active,
|
|
|
|
0, "tx_queue_active");
|
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"tx_activate",
|
|
|
|
CTLFLAG_RD, &ss->tx.activate,
|
|
|
|
0, "tx_activate");
|
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO,
|
|
|
|
"tx_deactivate",
|
|
|
|
CTLFLAG_RD, &ss->tx.deactivate,
|
|
|
|
0, "tx_deactivate");
|
2008-01-15 20:34:49 +00:00
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* copy an array of mcp_kreq_ether_send_t's to the mcp. Copy
|
|
|
|
backwards one at a time and handle ring wraps */
|
|
|
|
|
|
|
|
static inline void
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_submit_req_backwards(mxge_tx_ring_t *tx,
|
2006-02-19 22:39:19 +00:00
|
|
|
mcp_kreq_ether_send_t *src, int cnt)
|
|
|
|
{
|
|
|
|
int idx, starting_slot;
|
|
|
|
starting_slot = tx->req;
|
|
|
|
while (cnt > 1) {
|
|
|
|
cnt--;
|
|
|
|
idx = (starting_slot + cnt) & tx->mask;
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_pio_copy(&tx->lanai[idx],
|
|
|
|
&src[cnt], sizeof(*src));
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* copy an array of mcp_kreq_ether_send_t's to the mcp. Copy
|
|
|
|
* at most 32 bytes at a time, so as to avoid involving the software
|
|
|
|
* pio handler in the nic. We re-write the first segment's flags
|
|
|
|
* to mark them valid only after writing the entire chain
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline void
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_submit_req(mxge_tx_ring_t *tx, mcp_kreq_ether_send_t *src,
|
2006-02-19 22:39:19 +00:00
|
|
|
int cnt)
|
|
|
|
{
|
|
|
|
int idx, i;
|
|
|
|
uint32_t *src_ints;
|
|
|
|
volatile uint32_t *dst_ints;
|
|
|
|
mcp_kreq_ether_send_t *srcp;
|
|
|
|
volatile mcp_kreq_ether_send_t *dstp, *dst;
|
2006-06-14 16:23:17 +00:00
|
|
|
uint8_t last_flags;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
idx = tx->req & tx->mask;
|
|
|
|
|
2006-06-14 16:23:17 +00:00
|
|
|
last_flags = src->flags;
|
|
|
|
src->flags = 0;
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2006-02-19 22:39:19 +00:00
|
|
|
dst = dstp = &tx->lanai[idx];
|
|
|
|
srcp = src;
|
|
|
|
|
|
|
|
if ((idx + cnt) < tx->mask) {
|
|
|
|
for (i = 0; i < (cnt - 1); i += 2) {
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_pio_copy(dstp, srcp, 2 * sizeof(*src));
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb(); /* force write every 32 bytes */
|
2006-02-19 22:39:19 +00:00
|
|
|
srcp += 2;
|
|
|
|
dstp += 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* submit all but the first request, and ensure
|
|
|
|
that it is submitted below */
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_submit_req_backwards(tx, src, cnt);
|
2006-02-19 22:39:19 +00:00
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
if (i < cnt) {
|
|
|
|
/* submit the first request */
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_pio_copy(dstp, srcp, sizeof(*src));
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb(); /* barrier before setting valid flag */
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* re-write the last 32-bits with the valid flags */
|
2006-06-14 16:23:17 +00:00
|
|
|
src->flags = last_flags;
|
2006-02-19 22:39:19 +00:00
|
|
|
src_ints = (uint32_t *)src;
|
|
|
|
src_ints+=3;
|
|
|
|
dst_ints = (volatile uint32_t *)dst;
|
|
|
|
dst_ints+=3;
|
|
|
|
*dst_ints = *src_ints;
|
|
|
|
tx->req += cnt;
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
2008-02-14 00:09:59 +00:00
|
|
|
#if IFCAP_TSO4
|
|
|
|
|
2006-09-15 15:41:28 +00:00
|
|
|
static void
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_encap_tso(struct mxge_slice_state *ss, struct mbuf *m,
|
|
|
|
int busdma_seg_cnt, int ip_off)
|
2006-09-15 15:41:28 +00:00
|
|
|
{
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_tx_ring_t *tx;
|
2006-09-15 15:41:28 +00:00
|
|
|
mcp_kreq_ether_send_t *req;
|
|
|
|
bus_dma_segment_t *seg;
|
|
|
|
struct ip *ip;
|
|
|
|
struct tcphdr *tcp;
|
|
|
|
uint32_t low, high_swapped;
|
|
|
|
int len, seglen, cum_len, cum_len_next;
|
|
|
|
int next_is_first, chop, cnt, rdma_count, small;
|
|
|
|
uint16_t pseudo_hdr_offset, cksum_offset, mss;
|
|
|
|
uint8_t flags, flags_next;
|
|
|
|
static int once;
|
2008-01-15 20:34:49 +00:00
|
|
|
|
2006-09-15 15:41:28 +00:00
|
|
|
mss = m->m_pkthdr.tso_segsz;
|
|
|
|
|
|
|
|
/* negative cum_len signifies to the
|
|
|
|
* send loop that we are still in the
|
|
|
|
* header portion of the TSO packet.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ensure we have the ethernet, IP and TCP
|
|
|
|
header together in the first mbuf, copy
|
|
|
|
it to a scratch buffer if not */
|
2007-05-23 16:25:40 +00:00
|
|
|
if (__predict_false(m->m_len < ip_off + sizeof (*ip))) {
|
|
|
|
m_copydata(m, 0, ip_off + sizeof (*ip),
|
2008-01-15 20:34:49 +00:00
|
|
|
ss->scratch);
|
|
|
|
ip = (struct ip *)(ss->scratch + ip_off);
|
2006-09-15 15:41:28 +00:00
|
|
|
} else {
|
2007-05-23 16:25:40 +00:00
|
|
|
ip = (struct ip *)(mtod(m, char *) + ip_off);
|
2006-09-15 15:41:28 +00:00
|
|
|
}
|
2007-05-23 16:25:40 +00:00
|
|
|
if (__predict_false(m->m_len < ip_off + (ip->ip_hl << 2)
|
2006-09-15 15:41:28 +00:00
|
|
|
+ sizeof (*tcp))) {
|
2007-05-23 16:25:40 +00:00
|
|
|
m_copydata(m, 0, ip_off + (ip->ip_hl << 2)
|
2008-01-15 20:34:49 +00:00
|
|
|
+ sizeof (*tcp), ss->scratch);
|
2007-05-23 16:25:40 +00:00
|
|
|
ip = (struct ip *)(mtod(m, char *) + ip_off);
|
2006-09-15 15:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tcp = (struct tcphdr *)((char *)ip + (ip->ip_hl << 2));
|
2007-05-23 16:25:40 +00:00
|
|
|
cum_len = -(ip_off + ((ip->ip_hl + tcp->th_off) << 2));
|
2006-09-15 15:41:28 +00:00
|
|
|
|
|
|
|
/* TSO implies checksum offload on this hardware */
|
2007-05-23 16:25:40 +00:00
|
|
|
cksum_offset = ip_off + (ip->ip_hl << 2);
|
2006-09-15 15:41:28 +00:00
|
|
|
flags = MXGEFW_FLAGS_TSO_HDR | MXGEFW_FLAGS_FIRST;
|
|
|
|
|
|
|
|
|
|
|
|
/* for TSO, pseudo_hdr_offset holds mss.
|
|
|
|
* The firmware figures out where to put
|
|
|
|
* the checksum by parsing the header. */
|
|
|
|
pseudo_hdr_offset = htobe16(mss);
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
tx = &ss->tx;
|
2006-09-15 15:41:28 +00:00
|
|
|
req = tx->req_list;
|
|
|
|
seg = tx->seg_list;
|
|
|
|
cnt = 0;
|
|
|
|
rdma_count = 0;
|
|
|
|
/* "rdma_count" is the number of RDMAs belonging to the
|
|
|
|
* current packet BEFORE the current send request. For
|
|
|
|
* non-TSO packets, this is equal to "count".
|
|
|
|
* For TSO packets, rdma_count needs to be reset
|
|
|
|
* to 0 after a segment cut.
|
|
|
|
*
|
|
|
|
* The rdma_count field of the send request is
|
|
|
|
* the number of RDMAs of the packet starting at
|
|
|
|
* that request. For TSO send requests with one ore more cuts
|
|
|
|
* in the middle, this is the number of RDMAs starting
|
|
|
|
* after the last cut in the request. All previous
|
|
|
|
* segments before the last cut implicitly have 1 RDMA.
|
|
|
|
*
|
|
|
|
* Since the number of RDMAs is not known beforehand,
|
|
|
|
* it must be filled-in retroactively - after each
|
|
|
|
* segmentation cut or at the end of the entire packet.
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (busdma_seg_cnt) {
|
|
|
|
/* Break the busdma segment up into pieces*/
|
|
|
|
low = MXGE_LOWPART_TO_U32(seg->ds_addr);
|
|
|
|
high_swapped = htobe32(MXGE_HIGHPART_TO_U32(seg->ds_addr));
|
2007-04-03 10:41:33 +00:00
|
|
|
len = seg->ds_len;
|
2006-09-15 15:41:28 +00:00
|
|
|
|
|
|
|
while (len) {
|
|
|
|
flags_next = flags & ~MXGEFW_FLAGS_FIRST;
|
2007-04-03 10:41:33 +00:00
|
|
|
seglen = len;
|
2006-09-15 15:41:28 +00:00
|
|
|
cum_len_next = cum_len + seglen;
|
|
|
|
(req-rdma_count)->rdma_count = rdma_count + 1;
|
|
|
|
if (__predict_true(cum_len >= 0)) {
|
|
|
|
/* payload */
|
|
|
|
chop = (cum_len_next > mss);
|
|
|
|
cum_len_next = cum_len_next % mss;
|
|
|
|
next_is_first = (cum_len_next == 0);
|
|
|
|
flags |= chop * MXGEFW_FLAGS_TSO_CHOP;
|
|
|
|
flags_next |= next_is_first *
|
|
|
|
MXGEFW_FLAGS_FIRST;
|
|
|
|
rdma_count |= -(chop | next_is_first);
|
|
|
|
rdma_count += chop & !next_is_first;
|
|
|
|
} else if (cum_len_next >= 0) {
|
|
|
|
/* header ends */
|
|
|
|
rdma_count = -1;
|
|
|
|
cum_len_next = 0;
|
|
|
|
seglen = -cum_len;
|
|
|
|
small = (mss <= MXGEFW_SEND_SMALL_SIZE);
|
|
|
|
flags_next = MXGEFW_FLAGS_TSO_PLD |
|
|
|
|
MXGEFW_FLAGS_FIRST |
|
|
|
|
(small * MXGEFW_FLAGS_SMALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
req->addr_high = high_swapped;
|
|
|
|
req->addr_low = htobe32(low);
|
|
|
|
req->pseudo_hdr_offset = pseudo_hdr_offset;
|
|
|
|
req->pad = 0;
|
|
|
|
req->rdma_count = 1;
|
|
|
|
req->length = htobe16(seglen);
|
|
|
|
req->cksum_offset = cksum_offset;
|
|
|
|
req->flags = flags | ((cum_len & 1) *
|
|
|
|
MXGEFW_FLAGS_ALIGN_ODD);
|
|
|
|
low += seglen;
|
|
|
|
len -= seglen;
|
|
|
|
cum_len = cum_len_next;
|
|
|
|
flags = flags_next;
|
|
|
|
req++;
|
|
|
|
cnt++;
|
|
|
|
rdma_count++;
|
|
|
|
if (__predict_false(cksum_offset > seglen))
|
|
|
|
cksum_offset -= seglen;
|
|
|
|
else
|
|
|
|
cksum_offset = 0;
|
2007-05-22 15:57:49 +00:00
|
|
|
if (__predict_false(cnt > tx->max_desc))
|
2006-09-15 15:41:28 +00:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
busdma_seg_cnt--;
|
|
|
|
seg++;
|
|
|
|
}
|
|
|
|
(req-rdma_count)->rdma_count = rdma_count;
|
|
|
|
|
|
|
|
do {
|
|
|
|
req--;
|
|
|
|
req->flags |= MXGEFW_FLAGS_TSO_LAST;
|
|
|
|
} while (!(req->flags & (MXGEFW_FLAGS_TSO_CHOP | MXGEFW_FLAGS_FIRST)));
|
|
|
|
|
|
|
|
tx->info[((cnt - 1) + tx->req) & tx->mask].flag = 1;
|
2007-05-22 15:57:49 +00:00
|
|
|
mxge_submit_req(tx, tx->req_list, cnt);
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
if ((ss->sc->num_slices > 1) && tx->queue_active == 0) {
|
|
|
|
/* tell the NIC to start polling this slice */
|
|
|
|
*tx->send_go = 1;
|
|
|
|
tx->queue_active = 1;
|
|
|
|
tx->activate++;
|
|
|
|
wmb();
|
|
|
|
}
|
|
|
|
#endif
|
2006-09-15 15:41:28 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
drop:
|
2007-04-03 10:41:33 +00:00
|
|
|
bus_dmamap_unload(tx->dmat, tx->info[tx->req & tx->mask].map);
|
2006-09-15 15:41:28 +00:00
|
|
|
m_freem(m);
|
2009-04-27 15:45:54 +00:00
|
|
|
ss->oerrors++;
|
2006-09-15 15:41:28 +00:00
|
|
|
if (!once) {
|
2007-05-22 15:57:49 +00:00
|
|
|
printf("tx->max_desc exceeded via TSO!\n");
|
|
|
|
printf("mss = %d, %ld, %d!\n", mss,
|
|
|
|
(long)seg - (long)tx->seg_list, tx->max_desc);
|
2006-09-15 15:41:28 +00:00
|
|
|
once = 1;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-02-14 00:09:59 +00:00
|
|
|
#endif /* IFCAP_TSO4 */
|
|
|
|
|
|
|
|
#ifdef MXGE_NEW_VLAN_API
|
2007-05-23 16:25:40 +00:00
|
|
|
/*
|
|
|
|
* We reproduce the software vlan tag insertion from
|
|
|
|
* net/if_vlan.c:vlan_start() here so that we can advertise "hardware"
|
|
|
|
* vlan tag insertion. We need to advertise this in order to have the
|
|
|
|
* vlan interface respect our csum offload flags.
|
|
|
|
*/
|
|
|
|
static struct mbuf *
|
|
|
|
mxge_vlan_tag_insert(struct mbuf *m)
|
|
|
|
{
|
|
|
|
struct ether_vlan_header *evl;
|
|
|
|
|
|
|
|
M_PREPEND(m, ETHER_VLAN_ENCAP_LEN, M_DONTWAIT);
|
|
|
|
if (__predict_false(m == NULL))
|
|
|
|
return NULL;
|
|
|
|
if (m->m_len < sizeof(*evl)) {
|
|
|
|
m = m_pullup(m, sizeof(*evl));
|
|
|
|
if (__predict_false(m == NULL))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Transform the Ethernet header into an Ethernet header
|
|
|
|
* with 802.1Q encapsulation.
|
|
|
|
*/
|
|
|
|
evl = mtod(m, struct ether_vlan_header *);
|
|
|
|
bcopy((char *)evl + ETHER_VLAN_ENCAP_LEN,
|
|
|
|
(char *)evl, ETHER_HDR_LEN - ETHER_TYPE_LEN);
|
|
|
|
evl->evl_encap_proto = htons(ETHERTYPE_VLAN);
|
|
|
|
evl->evl_tag = htons(m->m_pkthdr.ether_vtag);
|
|
|
|
m->m_flags &= ~M_VLANTAG;
|
|
|
|
return m;
|
|
|
|
}
|
2008-02-14 00:09:59 +00:00
|
|
|
#endif /* MXGE_NEW_VLAN_API */
|
2007-05-23 16:25:40 +00:00
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
static void
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_encap(struct mxge_slice_state *ss, struct mbuf *m)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_softc_t *sc;
|
2006-02-19 22:39:19 +00:00
|
|
|
mcp_kreq_ether_send_t *req;
|
|
|
|
bus_dma_segment_t *seg;
|
|
|
|
struct mbuf *m_tmp;
|
|
|
|
struct ifnet *ifp;
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_tx_ring_t *tx;
|
2006-02-19 22:39:19 +00:00
|
|
|
struct ip *ip;
|
2007-05-23 16:25:40 +00:00
|
|
|
int cnt, cum_len, err, i, idx, odd_flag, ip_off;
|
2006-09-15 15:41:28 +00:00
|
|
|
uint16_t pseudo_hdr_offset;
|
|
|
|
uint8_t flags, cksum_offset;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
sc = ss->sc;
|
2006-02-19 22:39:19 +00:00
|
|
|
ifp = sc->ifp;
|
2008-01-15 20:34:49 +00:00
|
|
|
tx = &ss->tx;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2007-05-23 16:25:40 +00:00
|
|
|
ip_off = sizeof (struct ether_header);
|
2008-02-14 00:09:59 +00:00
|
|
|
#ifdef MXGE_NEW_VLAN_API
|
2007-05-23 16:25:40 +00:00
|
|
|
if (m->m_flags & M_VLANTAG) {
|
|
|
|
m = mxge_vlan_tag_insert(m);
|
|
|
|
if (__predict_false(m == NULL))
|
|
|
|
goto drop;
|
|
|
|
ip_off += ETHER_VLAN_ENCAP_LEN;
|
|
|
|
}
|
2008-02-14 00:09:59 +00:00
|
|
|
#endif
|
2006-02-19 22:39:19 +00:00
|
|
|
/* (try to) map the frame for DMA */
|
|
|
|
idx = tx->req & tx->mask;
|
|
|
|
err = bus_dmamap_load_mbuf_sg(tx->dmat, tx->info[idx].map,
|
2006-09-15 15:41:28 +00:00
|
|
|
m, tx->seg_list, &cnt,
|
2006-02-19 22:39:19 +00:00
|
|
|
BUS_DMA_NOWAIT);
|
2007-05-22 15:57:49 +00:00
|
|
|
if (__predict_false(err == EFBIG)) {
|
2006-02-19 22:39:19 +00:00
|
|
|
/* Too many segments in the chain. Try
|
|
|
|
to defrag */
|
|
|
|
m_tmp = m_defrag(m, M_NOWAIT);
|
|
|
|
if (m_tmp == NULL) {
|
|
|
|
goto drop;
|
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
ss->tx.defrag++;
|
2006-02-19 22:39:19 +00:00
|
|
|
m = m_tmp;
|
|
|
|
err = bus_dmamap_load_mbuf_sg(tx->dmat,
|
|
|
|
tx->info[idx].map,
|
2006-09-15 15:41:28 +00:00
|
|
|
m, tx->seg_list, &cnt,
|
2006-02-19 22:39:19 +00:00
|
|
|
BUS_DMA_NOWAIT);
|
|
|
|
}
|
2007-05-22 15:57:49 +00:00
|
|
|
if (__predict_false(err != 0)) {
|
2006-09-15 15:41:28 +00:00
|
|
|
device_printf(sc->dev, "bus_dmamap_load_mbuf_sg returned %d"
|
|
|
|
" packet len = %d\n", err, m->m_pkthdr.len);
|
2006-02-19 22:39:19 +00:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
bus_dmamap_sync(tx->dmat, tx->info[idx].map,
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
2006-06-14 16:23:17 +00:00
|
|
|
tx->info[idx].m = m;
|
|
|
|
|
2008-02-14 00:09:59 +00:00
|
|
|
#if IFCAP_TSO4
|
2006-09-15 15:41:28 +00:00
|
|
|
/* TSO is different enough, we handle it in another routine */
|
|
|
|
if (m->m_pkthdr.csum_flags & (CSUM_TSO)) {
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_encap_tso(ss, m, cnt, ip_off);
|
2006-09-15 15:41:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-02-14 00:09:59 +00:00
|
|
|
#endif
|
2006-09-15 15:41:28 +00:00
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
req = tx->req_list;
|
|
|
|
cksum_offset = 0;
|
2006-06-14 16:23:17 +00:00
|
|
|
pseudo_hdr_offset = 0;
|
|
|
|
flags = MXGEFW_FLAGS_NO_TSO;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
/* checksum offloading? */
|
|
|
|
if (m->m_pkthdr.csum_flags & (CSUM_DELAY_DATA)) {
|
2006-09-15 15:41:28 +00:00
|
|
|
/* ensure ip header is in first mbuf, copy
|
|
|
|
it to a scratch buffer if not */
|
2007-05-23 16:25:40 +00:00
|
|
|
if (__predict_false(m->m_len < ip_off + sizeof (*ip))) {
|
|
|
|
m_copydata(m, 0, ip_off + sizeof (*ip),
|
2008-01-15 20:34:49 +00:00
|
|
|
ss->scratch);
|
|
|
|
ip = (struct ip *)(ss->scratch + ip_off);
|
2006-09-15 15:41:28 +00:00
|
|
|
} else {
|
2007-05-23 16:25:40 +00:00
|
|
|
ip = (struct ip *)(mtod(m, char *) + ip_off);
|
2006-09-15 15:41:28 +00:00
|
|
|
}
|
2007-05-23 16:25:40 +00:00
|
|
|
cksum_offset = ip_off + (ip->ip_hl << 2);
|
2006-02-19 22:39:19 +00:00
|
|
|
pseudo_hdr_offset = cksum_offset + m->m_pkthdr.csum_data;
|
2006-06-14 16:23:17 +00:00
|
|
|
pseudo_hdr_offset = htobe16(pseudo_hdr_offset);
|
2006-02-19 22:39:19 +00:00
|
|
|
req->cksum_offset = cksum_offset;
|
2006-06-14 16:23:17 +00:00
|
|
|
flags |= MXGEFW_FLAGS_CKSUM;
|
2006-09-15 15:41:28 +00:00
|
|
|
odd_flag = MXGEFW_FLAGS_ALIGN_ODD;
|
|
|
|
} else {
|
|
|
|
odd_flag = 0;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2006-06-14 16:23:17 +00:00
|
|
|
if (m->m_pkthdr.len < MXGEFW_SEND_SMALL_SIZE)
|
|
|
|
flags |= MXGEFW_FLAGS_SMALL;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
/* convert segments into a request list */
|
|
|
|
cum_len = 0;
|
2006-09-15 15:41:28 +00:00
|
|
|
seg = tx->seg_list;
|
2006-06-14 16:23:17 +00:00
|
|
|
req->flags = MXGEFW_FLAGS_FIRST;
|
2006-02-19 22:39:19 +00:00
|
|
|
for (i = 0; i < cnt; i++) {
|
|
|
|
req->addr_low =
|
2006-06-13 13:53:52 +00:00
|
|
|
htobe32(MXGE_LOWPART_TO_U32(seg->ds_addr));
|
2006-02-19 22:39:19 +00:00
|
|
|
req->addr_high =
|
2006-06-13 13:53:52 +00:00
|
|
|
htobe32(MXGE_HIGHPART_TO_U32(seg->ds_addr));
|
2006-02-19 22:39:19 +00:00
|
|
|
req->length = htobe16(seg->ds_len);
|
|
|
|
req->cksum_offset = cksum_offset;
|
|
|
|
if (cksum_offset > seg->ds_len)
|
|
|
|
cksum_offset -= seg->ds_len;
|
|
|
|
else
|
|
|
|
cksum_offset = 0;
|
2006-06-14 16:23:17 +00:00
|
|
|
req->pseudo_hdr_offset = pseudo_hdr_offset;
|
|
|
|
req->pad = 0; /* complete solid 16-byte block */
|
|
|
|
req->rdma_count = 1;
|
2006-09-15 15:41:28 +00:00
|
|
|
req->flags |= flags | ((cum_len & 1) * odd_flag);
|
2006-02-19 22:39:19 +00:00
|
|
|
cum_len += seg->ds_len;
|
|
|
|
seg++;
|
|
|
|
req++;
|
|
|
|
req->flags = 0;
|
|
|
|
}
|
|
|
|
req--;
|
|
|
|
/* pad runts to 60 bytes */
|
|
|
|
if (cum_len < 60) {
|
|
|
|
req++;
|
|
|
|
req->addr_low =
|
2006-06-13 13:53:52 +00:00
|
|
|
htobe32(MXGE_LOWPART_TO_U32(sc->zeropad_dma.bus_addr));
|
2006-02-19 22:39:19 +00:00
|
|
|
req->addr_high =
|
2006-06-13 13:53:52 +00:00
|
|
|
htobe32(MXGE_HIGHPART_TO_U32(sc->zeropad_dma.bus_addr));
|
2006-02-19 22:39:19 +00:00
|
|
|
req->length = htobe16(60 - cum_len);
|
2006-06-14 16:23:17 +00:00
|
|
|
req->cksum_offset = 0;
|
|
|
|
req->pseudo_hdr_offset = pseudo_hdr_offset;
|
|
|
|
req->pad = 0; /* complete solid 16-byte block */
|
|
|
|
req->rdma_count = 1;
|
2006-09-15 15:41:28 +00:00
|
|
|
req->flags |= flags | ((cum_len & 1) * odd_flag);
|
2006-02-19 22:39:19 +00:00
|
|
|
cnt++;
|
|
|
|
}
|
2006-06-14 16:23:17 +00:00
|
|
|
|
|
|
|
tx->req_list[0].rdma_count = cnt;
|
|
|
|
#if 0
|
|
|
|
/* print what the firmware will see */
|
|
|
|
for (i = 0; i < cnt; i++) {
|
|
|
|
printf("%d: addr: 0x%x 0x%x len:%d pso%d,"
|
|
|
|
"cso:%d, flags:0x%x, rdma:%d\n",
|
|
|
|
i, (int)ntohl(tx->req_list[i].addr_high),
|
|
|
|
(int)ntohl(tx->req_list[i].addr_low),
|
|
|
|
(int)ntohs(tx->req_list[i].length),
|
|
|
|
(int)ntohs(tx->req_list[i].pseudo_hdr_offset),
|
|
|
|
tx->req_list[i].cksum_offset, tx->req_list[i].flags,
|
|
|
|
tx->req_list[i].rdma_count);
|
|
|
|
}
|
|
|
|
printf("--------------\n");
|
|
|
|
#endif
|
|
|
|
tx->info[((cnt - 1) + tx->req) & tx->mask].flag = 1;
|
2007-05-22 15:57:49 +00:00
|
|
|
mxge_submit_req(tx, tx->req_list, cnt);
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
if ((ss->sc->num_slices > 1) && tx->queue_active == 0) {
|
|
|
|
/* tell the NIC to start polling this slice */
|
|
|
|
*tx->send_go = 1;
|
|
|
|
tx->queue_active = 1;
|
|
|
|
tx->activate++;
|
|
|
|
wmb();
|
|
|
|
}
|
|
|
|
#endif
|
2006-02-19 22:39:19 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
drop:
|
|
|
|
m_freem(m);
|
2009-04-27 15:45:54 +00:00
|
|
|
ss->oerrors++;
|
2006-02-19 22:39:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
static void
|
|
|
|
mxge_qflush(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
mxge_softc_t *sc = ifp->if_softc;
|
|
|
|
mxge_tx_ring_t *tx;
|
|
|
|
struct mbuf *m;
|
|
|
|
int slice;
|
|
|
|
|
|
|
|
for (slice = 0; slice < sc->num_slices; slice++) {
|
|
|
|
tx = &sc->ss[slice].tx;
|
|
|
|
mtx_lock(&tx->mtx);
|
|
|
|
while ((m = buf_ring_dequeue_sc(tx->br)) != NULL)
|
|
|
|
m_freem(m);
|
|
|
|
mtx_unlock(&tx->mtx);
|
|
|
|
}
|
|
|
|
if_qflush(ifp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
mxge_start_locked(struct mxge_slice_state *ss)
|
|
|
|
{
|
|
|
|
mxge_softc_t *sc;
|
|
|
|
struct mbuf *m;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
mxge_tx_ring_t *tx;
|
|
|
|
|
|
|
|
sc = ss->sc;
|
|
|
|
ifp = sc->ifp;
|
|
|
|
tx = &ss->tx;
|
|
|
|
|
|
|
|
while ((tx->mask - (tx->req - tx->done)) > tx->max_desc) {
|
|
|
|
m = drbr_dequeue(ifp, tx->br);
|
|
|
|
if (m == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* let BPF see it */
|
|
|
|
BPF_MTAP(ifp, m);
|
|
|
|
|
|
|
|
/* give it to the nic */
|
|
|
|
mxge_encap(ss, m);
|
|
|
|
}
|
|
|
|
/* ran out of transmit slots */
|
|
|
|
if (((ss->if_drv_flags & IFF_DRV_OACTIVE) == 0)
|
|
|
|
&& (!drbr_empty(ifp, tx->br))) {
|
|
|
|
ss->if_drv_flags |= IFF_DRV_OACTIVE;
|
|
|
|
tx->stall++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mxge_transmit_locked(struct mxge_slice_state *ss, struct mbuf *m)
|
|
|
|
{
|
|
|
|
mxge_softc_t *sc;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
mxge_tx_ring_t *tx;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
sc = ss->sc;
|
|
|
|
ifp = sc->ifp;
|
|
|
|
tx = &ss->tx;
|
|
|
|
|
|
|
|
if ((ss->if_drv_flags & (IFF_DRV_RUNNING|IFF_DRV_OACTIVE)) !=
|
|
|
|
IFF_DRV_RUNNING) {
|
|
|
|
err = drbr_enqueue(ifp, tx->br, m);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drbr_empty(ifp, tx->br) &&
|
|
|
|
((tx->mask - (tx->req - tx->done)) > tx->max_desc)) {
|
|
|
|
/* let BPF see it */
|
|
|
|
BPF_MTAP(ifp, m);
|
|
|
|
/* give it to the nic */
|
|
|
|
mxge_encap(ss, m);
|
|
|
|
} else if ((err = drbr_enqueue(ifp, tx->br, m)) != 0) {
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
if (!drbr_empty(ifp, tx->br))
|
|
|
|
mxge_start_locked(ss);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mxge_transmit(struct ifnet *ifp, struct mbuf *m)
|
|
|
|
{
|
|
|
|
mxge_softc_t *sc = ifp->if_softc;
|
|
|
|
struct mxge_slice_state *ss;
|
|
|
|
mxge_tx_ring_t *tx;
|
|
|
|
int err = 0;
|
|
|
|
int slice;
|
|
|
|
|
|
|
|
slice = m->m_pkthdr.flowid;
|
|
|
|
slice &= (sc->num_slices - 1); /* num_slices always power of 2 */
|
|
|
|
|
|
|
|
ss = &sc->ss[slice];
|
|
|
|
tx = &ss->tx;
|
|
|
|
|
|
|
|
if (mtx_trylock(&tx->mtx)) {
|
|
|
|
err = mxge_transmit_locked(ss, m);
|
|
|
|
mtx_unlock(&tx->mtx);
|
|
|
|
} else {
|
|
|
|
err = drbr_enqueue(ifp, tx->br, m);
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2009-04-27 15:45:54 +00:00
|
|
|
return (err);
|
|
|
|
}
|
2006-06-14 19:32:00 +00:00
|
|
|
|
2009-04-27 15:45:54 +00:00
|
|
|
#else
|
2006-06-14 19:32:00 +00:00
|
|
|
|
|
|
|
static inline void
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_start_locked(struct mxge_slice_state *ss)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_softc_t *sc;
|
2006-02-19 22:39:19 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
struct ifnet *ifp;
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_tx_ring_t *tx;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
sc = ss->sc;
|
2006-02-19 22:39:19 +00:00
|
|
|
ifp = sc->ifp;
|
2008-01-15 20:34:49 +00:00
|
|
|
tx = &ss->tx;
|
2007-05-22 15:57:49 +00:00
|
|
|
while ((tx->mask - (tx->req - tx->done)) > tx->max_desc) {
|
2006-02-19 22:39:19 +00:00
|
|
|
IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
|
2006-06-14 19:32:00 +00:00
|
|
|
if (m == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
/* let BPF see it */
|
|
|
|
BPF_MTAP(ifp, m);
|
|
|
|
|
|
|
|
/* give it to the nic */
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_encap(ss, m);
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2006-06-14 19:32:00 +00:00
|
|
|
/* ran out of transmit slots */
|
2007-01-30 08:39:44 +00:00
|
|
|
if ((sc->ifp->if_drv_flags & IFF_DRV_OACTIVE) == 0) {
|
|
|
|
sc->ifp->if_drv_flags |= IFF_DRV_OACTIVE;
|
2007-05-22 15:57:49 +00:00
|
|
|
tx->stall++;
|
2007-01-30 08:39:44 +00:00
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2009-04-27 15:45:54 +00:00
|
|
|
#endif
|
2006-02-19 22:39:19 +00:00
|
|
|
static void
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_start(struct ifnet *ifp)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_softc_t *sc = ifp->if_softc;
|
2008-01-15 20:34:49 +00:00
|
|
|
struct mxge_slice_state *ss;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
/* only use the first slice for now */
|
|
|
|
ss = &sc->ss[0];
|
|
|
|
mtx_lock(&ss->tx.mtx);
|
|
|
|
mxge_start_locked(ss);
|
|
|
|
mtx_unlock(&ss->tx.mtx);
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
2006-06-14 16:23:17 +00:00
|
|
|
/*
|
|
|
|
* copy an array of mcp_kreq_ether_recv_t's to the mcp. Copy
|
|
|
|
* at most 32 bytes at a time, so as to avoid involving the software
|
|
|
|
* pio handler in the nic. We re-write the first segment's low
|
|
|
|
* DMA address to mark it valid only after we write the entire chunk
|
|
|
|
* in a burst
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
mxge_submit_8rx(volatile mcp_kreq_ether_recv_t *dst,
|
|
|
|
mcp_kreq_ether_recv_t *src)
|
|
|
|
{
|
|
|
|
uint32_t low;
|
|
|
|
|
|
|
|
low = src->addr_low;
|
|
|
|
src->addr_low = 0xffffffff;
|
2006-11-29 15:30:39 +00:00
|
|
|
mxge_pio_copy(dst, src, 4 * sizeof (*src));
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2006-11-29 15:30:39 +00:00
|
|
|
mxge_pio_copy(dst + 4, src + 4, 4 * sizeof (*src));
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2007-03-27 15:55:32 +00:00
|
|
|
src->addr_low = low;
|
2006-06-14 16:23:17 +00:00
|
|
|
dst->addr_low = low;
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2006-06-14 16:23:17 +00:00
|
|
|
}
|
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
static int
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_get_buf_small(struct mxge_slice_state *ss, bus_dmamap_t map, int idx)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
|
|
|
bus_dma_segment_t seg;
|
|
|
|
struct mbuf *m;
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_rx_ring_t *rx = &ss->rx_small;
|
2006-02-19 22:39:19 +00:00
|
|
|
int cnt, err;
|
|
|
|
|
|
|
|
m = m_gethdr(M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == NULL) {
|
|
|
|
rx->alloc_fail++;
|
|
|
|
err = ENOBUFS;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
m->m_len = MHLEN;
|
|
|
|
err = bus_dmamap_load_mbuf_sg(rx->dmat, map, m,
|
|
|
|
&seg, &cnt, BUS_DMA_NOWAIT);
|
|
|
|
if (err != 0) {
|
|
|
|
m_free(m);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
rx->info[idx].m = m;
|
|
|
|
rx->shadow[idx].addr_low =
|
2006-06-13 13:53:52 +00:00
|
|
|
htobe32(MXGE_LOWPART_TO_U32(seg.ds_addr));
|
2006-02-19 22:39:19 +00:00
|
|
|
rx->shadow[idx].addr_high =
|
2006-06-13 13:53:52 +00:00
|
|
|
htobe32(MXGE_HIGHPART_TO_U32(seg.ds_addr));
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
done:
|
2007-05-22 15:57:49 +00:00
|
|
|
if ((idx & 7) == 7)
|
|
|
|
mxge_submit_8rx(&rx->lanai[idx - 7], &rx->shadow[idx - 7]);
|
2006-02-19 22:39:19 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_get_buf_big(struct mxge_slice_state *ss, bus_dmamap_t map, int idx)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2007-05-21 18:32:27 +00:00
|
|
|
bus_dma_segment_t seg[3];
|
2006-02-19 22:39:19 +00:00
|
|
|
struct mbuf *m;
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_rx_ring_t *rx = &ss->rx_big;
|
2007-05-21 18:32:27 +00:00
|
|
|
int cnt, err, i;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2007-05-25 19:38:32 +00:00
|
|
|
if (rx->cl_size == MCLBYTES)
|
|
|
|
m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
|
|
|
|
else
|
|
|
|
m = m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR, rx->cl_size);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (m == NULL) {
|
|
|
|
rx->alloc_fail++;
|
|
|
|
err = ENOBUFS;
|
|
|
|
goto done;
|
|
|
|
}
|
2007-05-21 18:32:27 +00:00
|
|
|
m->m_len = rx->cl_size;
|
2006-02-19 22:39:19 +00:00
|
|
|
err = bus_dmamap_load_mbuf_sg(rx->dmat, map, m,
|
2007-05-21 18:32:27 +00:00
|
|
|
seg, &cnt, BUS_DMA_NOWAIT);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (err != 0) {
|
|
|
|
m_free(m);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
rx->info[idx].m = m;
|
2008-01-22 22:04:31 +00:00
|
|
|
rx->shadow[idx].addr_low =
|
|
|
|
htobe32(MXGE_LOWPART_TO_U32(seg->ds_addr));
|
|
|
|
rx->shadow[idx].addr_high =
|
|
|
|
htobe32(MXGE_HIGHPART_TO_U32(seg->ds_addr));
|
2007-05-21 18:32:27 +00:00
|
|
|
|
2008-01-22 22:04:31 +00:00
|
|
|
#if MXGE_VIRT_JUMBOS
|
|
|
|
for (i = 1; i < cnt; i++) {
|
2007-05-21 18:32:27 +00:00
|
|
|
rx->shadow[idx + i].addr_low =
|
|
|
|
htobe32(MXGE_LOWPART_TO_U32(seg[i].ds_addr));
|
|
|
|
rx->shadow[idx + i].addr_high =
|
|
|
|
htobe32(MXGE_HIGHPART_TO_U32(seg[i].ds_addr));
|
|
|
|
}
|
2008-01-22 22:04:31 +00:00
|
|
|
#endif
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
done:
|
2007-05-21 18:32:27 +00:00
|
|
|
for (i = 0; i < rx->nbufs; i++) {
|
|
|
|
if ((idx & 7) == 7) {
|
2007-05-22 15:57:49 +00:00
|
|
|
mxge_submit_8rx(&rx->lanai[idx - 7],
|
|
|
|
&rx->shadow[idx - 7]);
|
2006-06-14 16:23:17 +00:00
|
|
|
}
|
2007-05-21 18:32:27 +00:00
|
|
|
idx++;
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2007-05-21 18:32:27 +00:00
|
|
|
/*
|
|
|
|
* Myri10GE hardware checksums are not valid if the sender
|
|
|
|
* padded the frame with non-zero padding. This is because
|
|
|
|
* the firmware just does a simple 16-bit 1s complement
|
|
|
|
* checksum across the entire frame, excluding the first 14
|
|
|
|
* bytes. It is best to simply to check the checksum and
|
|
|
|
* tell the stack about it only if the checksum is good
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline uint16_t
|
2006-06-14 16:23:17 +00:00
|
|
|
mxge_rx_csum(struct mbuf *m, int csum)
|
|
|
|
{
|
|
|
|
struct ether_header *eh;
|
|
|
|
struct ip *ip;
|
2007-05-21 18:32:27 +00:00
|
|
|
uint16_t c;
|
2006-06-14 16:23:17 +00:00
|
|
|
|
|
|
|
eh = mtod(m, struct ether_header *);
|
2007-04-27 13:11:50 +00:00
|
|
|
|
|
|
|
/* only deal with IPv4 TCP & UDP for now */
|
|
|
|
if (__predict_false(eh->ether_type != htons(ETHERTYPE_IP)))
|
2007-05-21 18:32:27 +00:00
|
|
|
return 1;
|
2007-04-27 13:11:50 +00:00
|
|
|
ip = (struct ip *)(eh + 1);
|
|
|
|
if (__predict_false(ip->ip_p != IPPROTO_TCP &&
|
|
|
|
ip->ip_p != IPPROTO_UDP))
|
2007-05-21 18:32:27 +00:00
|
|
|
return 1;
|
2007-04-27 13:11:50 +00:00
|
|
|
|
2007-05-21 18:32:27 +00:00
|
|
|
c = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr,
|
|
|
|
htonl(ntohs(csum) + ntohs(ip->ip_len) +
|
|
|
|
- (ip->ip_hl << 2) + ip->ip_p));
|
|
|
|
c ^= 0xffff;
|
|
|
|
return (c);
|
2006-06-14 16:23:17 +00:00
|
|
|
}
|
|
|
|
|
2007-05-23 16:25:40 +00:00
|
|
|
static void
|
|
|
|
mxge_vlan_tag_remove(struct mbuf *m, uint32_t *csum)
|
|
|
|
{
|
|
|
|
struct ether_vlan_header *evl;
|
|
|
|
struct ether_header *eh;
|
|
|
|
uint32_t partial;
|
|
|
|
|
|
|
|
evl = mtod(m, struct ether_vlan_header *);
|
|
|
|
eh = mtod(m, struct ether_header *);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fix checksum by subtracting ETHER_VLAN_ENCAP_LEN bytes
|
|
|
|
* after what the firmware thought was the end of the ethernet
|
|
|
|
* header.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* put checksum into host byte order */
|
|
|
|
*csum = ntohs(*csum);
|
|
|
|
partial = ntohl(*(uint32_t *)(mtod(m, char *) + ETHER_HDR_LEN));
|
|
|
|
(*csum) += ~partial;
|
|
|
|
(*csum) += ((*csum) < ~partial);
|
|
|
|
(*csum) = ((*csum) >> 16) + ((*csum) & 0xFFFF);
|
|
|
|
(*csum) = ((*csum) >> 16) + ((*csum) & 0xFFFF);
|
|
|
|
|
|
|
|
/* restore checksum to network byte order;
|
|
|
|
later consumers expect this */
|
|
|
|
*csum = htons(*csum);
|
|
|
|
|
|
|
|
/* save the tag */
|
2008-02-14 00:09:59 +00:00
|
|
|
#ifdef MXGE_NEW_VLAN_API
|
2007-05-23 16:25:40 +00:00
|
|
|
m->m_pkthdr.ether_vtag = ntohs(evl->evl_tag);
|
2008-02-14 00:09:59 +00:00
|
|
|
#else
|
|
|
|
{
|
|
|
|
struct m_tag *mtag;
|
|
|
|
mtag = m_tag_alloc(MTAG_VLAN, MTAG_VLAN_TAG, sizeof(u_int),
|
|
|
|
M_NOWAIT);
|
|
|
|
if (mtag == NULL)
|
|
|
|
return;
|
|
|
|
VLAN_TAG_VALUE(mtag) = ntohs(evl->evl_tag);
|
|
|
|
m_tag_prepend(m, mtag);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
m->m_flags |= M_VLANTAG;
|
2007-05-23 16:25:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove the 802.1q header by copying the Ethernet
|
|
|
|
* addresses over it and adjusting the beginning of
|
|
|
|
* the data in the mbuf. The encapsulated Ethernet
|
|
|
|
* type field is already in place.
|
|
|
|
*/
|
|
|
|
bcopy((char *)evl, (char *)evl + ETHER_VLAN_ENCAP_LEN,
|
|
|
|
ETHER_HDR_LEN - ETHER_TYPE_LEN);
|
|
|
|
m_adj(m, ETHER_VLAN_ENCAP_LEN);
|
|
|
|
}
|
|
|
|
|
2007-05-21 18:32:27 +00:00
|
|
|
|
|
|
|
static inline void
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_rx_done_big(struct mxge_slice_state *ss, uint32_t len, uint32_t csum)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_softc_t *sc;
|
2006-02-19 22:39:19 +00:00
|
|
|
struct ifnet *ifp;
|
2007-05-21 18:32:27 +00:00
|
|
|
struct mbuf *m;
|
2007-05-23 16:25:40 +00:00
|
|
|
struct ether_header *eh;
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_rx_ring_t *rx;
|
2007-05-21 18:32:27 +00:00
|
|
|
bus_dmamap_t old_map;
|
2006-02-19 22:39:19 +00:00
|
|
|
int idx;
|
2007-05-21 18:32:27 +00:00
|
|
|
uint16_t tcpudp_csum;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
sc = ss->sc;
|
2006-02-19 22:39:19 +00:00
|
|
|
ifp = sc->ifp;
|
2008-01-15 20:34:49 +00:00
|
|
|
rx = &ss->rx_big;
|
2007-05-21 18:32:27 +00:00
|
|
|
idx = rx->cnt & rx->mask;
|
|
|
|
rx->cnt += rx->nbufs;
|
|
|
|
/* save a pointer to the received mbuf */
|
|
|
|
m = rx->info[idx].m;
|
|
|
|
/* try to replace the received mbuf */
|
2008-01-15 20:34:49 +00:00
|
|
|
if (mxge_get_buf_big(ss, rx->extra_map, idx)) {
|
2007-05-21 18:32:27 +00:00
|
|
|
/* drop the frame -- the old mbuf is re-cycled */
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
2007-05-21 18:32:27 +00:00
|
|
|
/* unmap the received buffer */
|
|
|
|
old_map = rx->info[idx].map;
|
|
|
|
bus_dmamap_sync(rx->dmat, old_map, BUS_DMASYNC_POSTREAD);
|
|
|
|
bus_dmamap_unload(rx->dmat, old_map);
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2007-05-21 18:32:27 +00:00
|
|
|
/* swap the bus_dmamap_t's */
|
|
|
|
rx->info[idx].map = rx->extra_map;
|
|
|
|
rx->extra_map = old_map;
|
|
|
|
|
|
|
|
/* mcp implicitly skips 1st 2 bytes so that packet is properly
|
|
|
|
* aligned */
|
|
|
|
m->m_data += MXGEFW_PAD;
|
|
|
|
|
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
m->m_len = m->m_pkthdr.len = len;
|
2008-01-15 20:34:49 +00:00
|
|
|
ss->ipackets++;
|
2007-05-23 16:25:40 +00:00
|
|
|
eh = mtod(m, struct ether_header *);
|
|
|
|
if (eh->ether_type == htons(ETHERTYPE_VLAN)) {
|
|
|
|
mxge_vlan_tag_remove(m, &csum);
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
/* if the checksum is valid, mark it in the mbuf header */
|
2007-05-21 18:32:27 +00:00
|
|
|
if (sc->csum_flag && (0 == (tcpudp_csum = mxge_rx_csum(m, csum)))) {
|
2008-01-15 20:34:49 +00:00
|
|
|
if (sc->lro_cnt && (0 == mxge_lro_rx(ss, m, csum)))
|
2007-05-21 18:32:27 +00:00
|
|
|
return;
|
|
|
|
/* otherwise, it was a UDP frame, or a TCP frame which
|
|
|
|
we could not do LRO on. Tell the stack that the
|
|
|
|
checksum is good */
|
|
|
|
m->m_pkthdr.csum_data = 0xffff;
|
|
|
|
m->m_pkthdr.csum_flags = CSUM_PSEUDO_HDR | CSUM_DATA_VALID;
|
|
|
|
}
|
2009-04-27 15:45:54 +00:00
|
|
|
/* flowid only valid if RSS hashing is enabled */
|
|
|
|
if (sc->num_slices > 1) {
|
|
|
|
m->m_pkthdr.flowid = (ss - sc->ss);
|
|
|
|
m->m_flags |= M_FLOWID;
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
/* pass the frame up the stack */
|
2007-05-21 18:32:27 +00:00
|
|
|
(*ifp->if_input)(ifp, m);
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_rx_done_small(struct mxge_slice_state *ss, uint32_t len, uint32_t csum)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_softc_t *sc;
|
2006-02-19 22:39:19 +00:00
|
|
|
struct ifnet *ifp;
|
2007-05-23 16:25:40 +00:00
|
|
|
struct ether_header *eh;
|
2006-02-19 22:39:19 +00:00
|
|
|
struct mbuf *m;
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_rx_ring_t *rx;
|
2006-02-19 22:39:19 +00:00
|
|
|
bus_dmamap_t old_map;
|
|
|
|
int idx;
|
2007-05-21 18:32:27 +00:00
|
|
|
uint16_t tcpudp_csum;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
sc = ss->sc;
|
2006-02-19 22:39:19 +00:00
|
|
|
ifp = sc->ifp;
|
2008-01-15 20:34:49 +00:00
|
|
|
rx = &ss->rx_small;
|
2006-02-19 22:39:19 +00:00
|
|
|
idx = rx->cnt & rx->mask;
|
|
|
|
rx->cnt++;
|
|
|
|
/* save a pointer to the received mbuf */
|
|
|
|
m = rx->info[idx].m;
|
|
|
|
/* try to replace the received mbuf */
|
2008-01-15 20:34:49 +00:00
|
|
|
if (mxge_get_buf_small(ss, rx->extra_map, idx)) {
|
2006-02-19 22:39:19 +00:00
|
|
|
/* drop the frame -- the old mbuf is re-cycled */
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* unmap the received buffer */
|
|
|
|
old_map = rx->info[idx].map;
|
|
|
|
bus_dmamap_sync(rx->dmat, old_map, BUS_DMASYNC_POSTREAD);
|
|
|
|
bus_dmamap_unload(rx->dmat, old_map);
|
|
|
|
|
|
|
|
/* swap the bus_dmamap_t's */
|
|
|
|
rx->info[idx].map = rx->extra_map;
|
|
|
|
rx->extra_map = old_map;
|
|
|
|
|
|
|
|
/* mcp implicitly skips 1st 2 bytes so that packet is properly
|
|
|
|
* aligned */
|
2006-06-14 16:23:17 +00:00
|
|
|
m->m_data += MXGEFW_PAD;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2007-04-27 13:11:50 +00:00
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
m->m_len = m->m_pkthdr.len = len;
|
2008-01-15 20:34:49 +00:00
|
|
|
ss->ipackets++;
|
2007-05-23 16:25:40 +00:00
|
|
|
eh = mtod(m, struct ether_header *);
|
|
|
|
if (eh->ether_type == htons(ETHERTYPE_VLAN)) {
|
|
|
|
mxge_vlan_tag_remove(m, &csum);
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
/* if the checksum is valid, mark it in the mbuf header */
|
2007-05-21 18:32:27 +00:00
|
|
|
if (sc->csum_flag && (0 == (tcpudp_csum = mxge_rx_csum(m, csum)))) {
|
2008-01-15 20:34:49 +00:00
|
|
|
if (sc->lro_cnt && (0 == mxge_lro_rx(ss, m, csum)))
|
2007-05-21 18:32:27 +00:00
|
|
|
return;
|
|
|
|
/* otherwise, it was a UDP frame, or a TCP frame which
|
|
|
|
we could not do LRO on. Tell the stack that the
|
|
|
|
checksum is good */
|
|
|
|
m->m_pkthdr.csum_data = 0xffff;
|
|
|
|
m->m_pkthdr.csum_flags = CSUM_PSEUDO_HDR | CSUM_DATA_VALID;
|
|
|
|
}
|
2009-04-27 15:45:54 +00:00
|
|
|
/* flowid only valid if RSS hashing is enabled */
|
|
|
|
if (sc->num_slices > 1) {
|
|
|
|
m->m_pkthdr.flowid = (ss - sc->ss);
|
|
|
|
m->m_flags |= M_FLOWID;
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
/* pass the frame up the stack */
|
|
|
|
(*ifp->if_input)(ifp, m);
|
|
|
|
}
|
|
|
|
|
2006-06-14 16:23:17 +00:00
|
|
|
static inline void
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_clean_rx_done(struct mxge_slice_state *ss)
|
2006-06-14 16:23:17 +00:00
|
|
|
{
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_rx_done_t *rx_done = &ss->rx_done;
|
2007-05-21 18:32:27 +00:00
|
|
|
struct lro_entry *lro;
|
2006-06-14 16:23:17 +00:00
|
|
|
int limit = 0;
|
|
|
|
uint16_t length;
|
|
|
|
uint16_t checksum;
|
|
|
|
|
|
|
|
|
|
|
|
while (rx_done->entry[rx_done->idx].length != 0) {
|
|
|
|
length = ntohs(rx_done->entry[rx_done->idx].length);
|
|
|
|
rx_done->entry[rx_done->idx].length = 0;
|
2007-05-21 18:32:27 +00:00
|
|
|
checksum = rx_done->entry[rx_done->idx].checksum;
|
2006-10-17 14:39:19 +00:00
|
|
|
if (length <= (MHLEN - MXGEFW_PAD))
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_rx_done_small(ss, length, checksum);
|
2006-06-14 16:23:17 +00:00
|
|
|
else
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_rx_done_big(ss, length, checksum);
|
2006-06-14 16:23:17 +00:00
|
|
|
rx_done->cnt++;
|
2007-05-22 15:57:49 +00:00
|
|
|
rx_done->idx = rx_done->cnt & rx_done->mask;
|
2006-06-14 16:23:17 +00:00
|
|
|
|
|
|
|
/* limit potential for livelock */
|
2007-06-14 19:35:03 +00:00
|
|
|
if (__predict_false(++limit > rx_done->mask / 2))
|
2006-06-14 16:23:17 +00:00
|
|
|
break;
|
2007-05-21 18:32:27 +00:00
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
while (!SLIST_EMPTY(&ss->lro_active)) {
|
|
|
|
lro = SLIST_FIRST(&ss->lro_active);
|
|
|
|
SLIST_REMOVE_HEAD(&ss->lro_active, next);
|
|
|
|
mxge_lro_flush(ss, lro);
|
2006-06-14 16:23:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
static inline void
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_tx_done(struct mxge_slice_state *ss, uint32_t mcp_idx)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_tx_ring_t *tx;
|
2006-02-19 22:39:19 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
bus_dmamap_t map;
|
2007-06-14 19:35:03 +00:00
|
|
|
int idx;
|
2009-04-27 15:45:54 +00:00
|
|
|
int *flags;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
tx = &ss->tx;
|
|
|
|
ifp = ss->sc->ifp;
|
2006-06-14 16:23:17 +00:00
|
|
|
while (tx->pkt_done != mcp_idx) {
|
2006-02-19 22:39:19 +00:00
|
|
|
idx = tx->done & tx->mask;
|
|
|
|
tx->done++;
|
|
|
|
m = tx->info[idx].m;
|
|
|
|
/* mbuf and DMA map only attached to the first
|
|
|
|
segment per-mbuf */
|
|
|
|
if (m != NULL) {
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
ss->obytes += m->m_pkthdr.len;
|
|
|
|
if (m->m_flags & M_MCAST)
|
|
|
|
ss->omcasts++;
|
|
|
|
#endif
|
|
|
|
ss->opackets++;
|
2006-02-19 22:39:19 +00:00
|
|
|
tx->info[idx].m = NULL;
|
|
|
|
map = tx->info[idx].map;
|
|
|
|
bus_dmamap_unload(tx->dmat, map);
|
|
|
|
m_freem(m);
|
|
|
|
}
|
2006-06-14 16:23:17 +00:00
|
|
|
if (tx->info[idx].flag) {
|
|
|
|
tx->info[idx].flag = 0;
|
|
|
|
tx->pkt_done++;
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we have space, clear IFF_OACTIVE to tell the stack that
|
|
|
|
its OK to send packets */
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
flags = &ss->if_drv_flags;
|
|
|
|
#else
|
|
|
|
flags = &ifp->if_drv_flags;
|
|
|
|
#endif
|
|
|
|
mtx_lock(&ss->tx.mtx);
|
|
|
|
if ((*flags) & IFF_DRV_OACTIVE &&
|
2006-02-19 22:39:19 +00:00
|
|
|
tx->req - tx->done < (tx->mask + 1)/4) {
|
2009-04-27 15:45:54 +00:00
|
|
|
*(flags) &= ~IFF_DRV_OACTIVE;
|
2008-01-15 20:34:49 +00:00
|
|
|
ss->tx.wake++;
|
|
|
|
mxge_start_locked(ss);
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
if ((ss->sc->num_slices > 1) && (tx->req == tx->done)) {
|
|
|
|
/* let the NIC stop polling this queue, since there
|
|
|
|
* are no more transmits pending */
|
|
|
|
if (tx->req == tx->done) {
|
|
|
|
*tx->send_stop = 1;
|
|
|
|
tx->queue_active = 0;
|
|
|
|
tx->deactivate++;
|
|
|
|
wmb();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
mtx_unlock(&ss->tx.mtx);
|
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
2009-02-17 22:15:58 +00:00
|
|
|
static struct mxge_media_type mxge_xfp_media_types[] =
|
2007-08-22 13:22:12 +00:00
|
|
|
{
|
|
|
|
{IFM_10G_CX4, 0x7f, "10GBASE-CX4 (module)"},
|
|
|
|
{IFM_10G_SR, (1 << 7), "10GBASE-SR"},
|
|
|
|
{IFM_10G_LR, (1 << 6), "10GBASE-LR"},
|
|
|
|
{0, (1 << 5), "10GBASE-ER"},
|
2009-02-17 22:15:58 +00:00
|
|
|
{IFM_10G_LRM, (1 << 4), "10GBASE-LRM"},
|
2007-08-22 13:22:12 +00:00
|
|
|
{0, (1 << 3), "10GBASE-SW"},
|
|
|
|
{0, (1 << 2), "10GBASE-LW"},
|
|
|
|
{0, (1 << 1), "10GBASE-EW"},
|
|
|
|
{0, (1 << 0), "Reserved"}
|
|
|
|
};
|
2009-02-17 22:15:58 +00:00
|
|
|
static struct mxge_media_type mxge_sfp_media_types[] =
|
|
|
|
{
|
2009-02-17 22:25:19 +00:00
|
|
|
{0, (1 << 7), "Reserved"},
|
2009-02-17 22:15:58 +00:00
|
|
|
{IFM_10G_LRM, (1 << 6), "10GBASE-LRM"},
|
|
|
|
{IFM_10G_LR, (1 << 5), "10GBASE-LR"},
|
|
|
|
{IFM_10G_SR, (1 << 4), "10GBASE-SR"}
|
|
|
|
};
|
2007-08-22 13:22:12 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
mxge_set_media(mxge_softc_t *sc, int type)
|
|
|
|
{
|
|
|
|
sc->media_flags |= type;
|
|
|
|
ifmedia_add(&sc->media, sc->media_flags, 0, NULL);
|
|
|
|
ifmedia_set(&sc->media, sc->media_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine the media type for a NIC. Some XFPs will identify
|
|
|
|
* themselves only when their link is up, so this is initiated via a
|
|
|
|
* link up interrupt. However, this can potentially take up to
|
|
|
|
* several milliseconds, so it is run via the watchdog routine, rather
|
|
|
|
* than in the interrupt handler itself. This need only be done
|
|
|
|
* once, not each time the link is up.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
mxge_media_probe(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
mxge_cmd_t cmd;
|
2009-02-17 22:15:58 +00:00
|
|
|
char *cage_type;
|
2007-08-22 13:22:12 +00:00
|
|
|
char *ptr;
|
2009-02-17 22:15:58 +00:00
|
|
|
struct mxge_media_type *mxge_media_types = NULL;
|
|
|
|
int i, err, ms, mxge_media_type_entries;
|
|
|
|
uint32_t byte;
|
2007-08-22 13:22:12 +00:00
|
|
|
|
|
|
|
sc->need_media_probe = 0;
|
|
|
|
|
|
|
|
/* if we've already set a media type, we're done */
|
|
|
|
if (sc->media_flags != (IFM_ETHER | IFM_AUTO))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* parse the product code to deterimine the interface type
|
|
|
|
* (CX4, XFP, Quad Ribbon Fiber) by looking at the character
|
|
|
|
* after the 3rd dash in the driver's cached copy of the
|
|
|
|
* EEPROM's product code string.
|
|
|
|
*/
|
|
|
|
ptr = sc->product_code_string;
|
|
|
|
if (ptr == NULL) {
|
|
|
|
device_printf(sc->dev, "Missing product code\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++, ptr++) {
|
2008-02-14 00:09:59 +00:00
|
|
|
ptr = index(ptr, '-');
|
2007-08-22 13:22:12 +00:00
|
|
|
if (ptr == NULL) {
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"only %d dashes in PC?!?\n", i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*ptr == 'C') {
|
2009-02-17 22:15:58 +00:00
|
|
|
/* -C is CX4 */
|
2007-08-22 13:22:12 +00:00
|
|
|
mxge_set_media(sc, IFM_10G_CX4);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (*ptr == 'Q') {
|
2009-02-17 22:15:58 +00:00
|
|
|
/* -Q is Quad Ribbon Fiber */
|
2007-08-22 13:22:12 +00:00
|
|
|
device_printf(sc->dev, "Quad Ribbon Fiber Media\n");
|
|
|
|
/* FreeBSD has no media type for Quad ribbon fiber */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-17 22:15:58 +00:00
|
|
|
if (*ptr == 'R') {
|
|
|
|
/* -R is XFP */
|
|
|
|
mxge_media_types = mxge_xfp_media_types;
|
|
|
|
mxge_media_type_entries =
|
|
|
|
sizeof (mxge_xfp_media_types) /
|
|
|
|
sizeof (mxge_xfp_media_types[0]);
|
|
|
|
byte = MXGE_XFP_COMPLIANCE_BYTE;
|
|
|
|
cage_type = "XFP";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*ptr == 'S' || *(ptr +1) == 'S') {
|
|
|
|
/* -S or -2S is SFP+ */
|
|
|
|
mxge_media_types = mxge_sfp_media_types;
|
|
|
|
mxge_media_type_entries =
|
|
|
|
sizeof (mxge_sfp_media_types) /
|
|
|
|
sizeof (mxge_sfp_media_types[0]);
|
|
|
|
cage_type = "SFP+";
|
|
|
|
byte = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mxge_media_types == NULL) {
|
2007-08-22 13:22:12 +00:00
|
|
|
device_printf(sc->dev, "Unknown media type: %c\n", *ptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point we know the NIC has an XFP cage, so now we
|
|
|
|
* try to determine what is in the cage by using the
|
|
|
|
* firmware's XFP I2C commands to read the XFP 10GbE compilance
|
|
|
|
* register. We read just one byte, which may take over
|
|
|
|
* a millisecond
|
|
|
|
*/
|
|
|
|
|
|
|
|
cmd.data0 = 0; /* just fetch 1 byte, not all 256 */
|
2009-02-17 22:15:58 +00:00
|
|
|
cmd.data1 = byte;
|
|
|
|
err = mxge_send_cmd(sc, MXGEFW_CMD_I2C_READ, &cmd);
|
|
|
|
if (err == MXGEFW_CMD_ERROR_I2C_FAILURE) {
|
2007-08-22 13:22:12 +00:00
|
|
|
device_printf(sc->dev, "failed to read XFP\n");
|
|
|
|
}
|
2009-02-17 22:15:58 +00:00
|
|
|
if (err == MXGEFW_CMD_ERROR_I2C_ABSENT) {
|
|
|
|
device_printf(sc->dev, "Type R/S with no XFP!?!?\n");
|
2007-08-22 13:22:12 +00:00
|
|
|
}
|
|
|
|
if (err != MXGEFW_CMD_OK) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now we wait for the data to be cached */
|
2009-02-17 22:15:58 +00:00
|
|
|
cmd.data0 = byte;
|
|
|
|
err = mxge_send_cmd(sc, MXGEFW_CMD_I2C_BYTE, &cmd);
|
2007-08-22 13:22:12 +00:00
|
|
|
for (ms = 0; (err == EBUSY) && (ms < 50); ms++) {
|
|
|
|
DELAY(1000);
|
2009-02-17 22:15:58 +00:00
|
|
|
cmd.data0 = byte;
|
|
|
|
err = mxge_send_cmd(sc, MXGEFW_CMD_I2C_BYTE, &cmd);
|
2007-08-22 13:22:12 +00:00
|
|
|
}
|
|
|
|
if (err != MXGEFW_CMD_OK) {
|
2009-02-17 22:15:58 +00:00
|
|
|
device_printf(sc->dev, "failed to read %s (%d, %dms)\n",
|
|
|
|
cage_type, err, ms);
|
2007-08-22 13:22:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmd.data0 == mxge_media_types[0].bitmask) {
|
|
|
|
if (mxge_verbose)
|
2009-02-17 22:15:58 +00:00
|
|
|
device_printf(sc->dev, "%s:%s\n", cage_type,
|
2007-08-22 13:22:12 +00:00
|
|
|
mxge_media_types[0].name);
|
|
|
|
mxge_set_media(sc, IFM_10G_CX4);
|
|
|
|
return;
|
|
|
|
}
|
2009-02-17 22:15:58 +00:00
|
|
|
for (i = 1; i < mxge_media_type_entries; i++) {
|
2007-08-22 13:22:12 +00:00
|
|
|
if (cmd.data0 & mxge_media_types[i].bitmask) {
|
|
|
|
if (mxge_verbose)
|
2009-02-17 22:15:58 +00:00
|
|
|
device_printf(sc->dev, "%s:%s\n",
|
|
|
|
cage_type,
|
2007-08-22 13:22:12 +00:00
|
|
|
mxge_media_types[i].name);
|
|
|
|
|
|
|
|
mxge_set_media(sc, mxge_media_types[i].flag);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2009-02-17 22:15:58 +00:00
|
|
|
device_printf(sc->dev, "%s media 0x%x unknown\n", cage_type,
|
|
|
|
cmd.data0);
|
2007-08-22 13:22:12 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
static void
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_intr(void *arg)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2008-01-15 20:34:49 +00:00
|
|
|
struct mxge_slice_state *ss = arg;
|
|
|
|
mxge_softc_t *sc = ss->sc;
|
|
|
|
mcp_irq_data_t *stats = ss->fw_stats;
|
|
|
|
mxge_tx_ring_t *tx = &ss->tx;
|
|
|
|
mxge_rx_done_t *rx_done = &ss->rx_done;
|
2006-06-14 16:23:17 +00:00
|
|
|
uint32_t send_done_count;
|
|
|
|
uint8_t valid;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifndef IFNET_BUF_RING
|
2008-01-15 20:34:49 +00:00
|
|
|
/* an interrupt on a non-zero slice is implicitly valid
|
|
|
|
since MSI-X irqs are not shared */
|
|
|
|
if (ss != sc->ss) {
|
|
|
|
mxge_clean_rx_done(ss);
|
|
|
|
*ss->irq_claim = be32toh(3);
|
|
|
|
return;
|
|
|
|
}
|
2009-04-27 15:45:54 +00:00
|
|
|
#endif
|
2008-01-15 20:34:49 +00:00
|
|
|
|
2006-06-14 16:23:17 +00:00
|
|
|
/* make sure the DMA has finished */
|
|
|
|
if (!stats->valid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
valid = stats->valid;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2008-02-14 16:24:14 +00:00
|
|
|
if (sc->legacy_irq) {
|
2006-11-21 15:55:01 +00:00
|
|
|
/* lower legacy IRQ */
|
|
|
|
*sc->irq_deassert = 0;
|
|
|
|
if (!mxge_deassert_wait)
|
|
|
|
/* don't wait for conf. that irq is low */
|
|
|
|
stats->valid = 0;
|
|
|
|
} else {
|
2006-06-14 16:23:17 +00:00
|
|
|
stats->valid = 0;
|
2006-11-21 15:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* loop while waiting for legacy irq deassertion */
|
2006-06-14 16:23:17 +00:00
|
|
|
do {
|
|
|
|
/* check for transmit completes and receives */
|
|
|
|
send_done_count = be32toh(stats->send_done_count);
|
|
|
|
while ((send_done_count != tx->pkt_done) ||
|
|
|
|
(rx_done->entry[rx_done->idx].length != 0)) {
|
2009-04-27 15:45:54 +00:00
|
|
|
if (send_done_count != tx->pkt_done)
|
|
|
|
mxge_tx_done(ss, (int)send_done_count);
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_clean_rx_done(ss);
|
2006-06-14 16:23:17 +00:00
|
|
|
send_done_count = be32toh(stats->send_done_count);
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2008-02-14 16:24:14 +00:00
|
|
|
if (sc->legacy_irq && mxge_deassert_wait)
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2006-06-14 16:23:17 +00:00
|
|
|
} while (*((volatile uint8_t *) &stats->valid));
|
|
|
|
|
2009-04-27 15:45:54 +00:00
|
|
|
/* fw link & error stats meaningful only on the first slice */
|
|
|
|
if (__predict_false((ss == sc->ss) && stats->stats_updated)) {
|
2006-06-14 16:23:17 +00:00
|
|
|
if (sc->link_state != stats->link_up) {
|
|
|
|
sc->link_state = stats->link_up;
|
|
|
|
if (sc->link_state) {
|
|
|
|
if_link_state_change(sc->ifp, LINK_STATE_UP);
|
|
|
|
if (mxge_verbose)
|
|
|
|
device_printf(sc->dev, "link up\n");
|
|
|
|
} else {
|
|
|
|
if_link_state_change(sc->ifp, LINK_STATE_DOWN);
|
|
|
|
if (mxge_verbose)
|
|
|
|
device_printf(sc->dev, "link down\n");
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2007-08-22 13:22:12 +00:00
|
|
|
sc->need_media_probe = 1;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2006-06-14 16:23:17 +00:00
|
|
|
if (sc->rdma_tags_available !=
|
2008-01-15 20:34:49 +00:00
|
|
|
be32toh(stats->rdma_tags_available)) {
|
2006-06-14 16:23:17 +00:00
|
|
|
sc->rdma_tags_available =
|
2008-01-15 20:34:49 +00:00
|
|
|
be32toh(stats->rdma_tags_available);
|
2006-06-14 16:23:17 +00:00
|
|
|
device_printf(sc->dev, "RDMA timed out! %d tags "
|
|
|
|
"left\n", sc->rdma_tags_available);
|
|
|
|
}
|
2007-08-22 13:22:12 +00:00
|
|
|
|
|
|
|
if (stats->link_down) {
|
|
|
|
sc->down_cnt += stats->link_down;
|
|
|
|
sc->link_state = 0;
|
|
|
|
if_link_state_change(sc->ifp, LINK_STATE_DOWN);
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
2006-06-14 16:23:17 +00:00
|
|
|
/* check to see if we have rx token to pass back */
|
|
|
|
if (valid & 0x1)
|
2008-01-15 20:34:49 +00:00
|
|
|
*ss->irq_claim = be32toh(3);
|
|
|
|
*(ss->irq_claim + 1) = be32toh(3);
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_init(void *arg)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_free_slice_mbufs(struct mxge_slice_state *ss)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2008-01-15 20:34:49 +00:00
|
|
|
struct lro_entry *lro_entry;
|
2006-02-19 22:39:19 +00:00
|
|
|
int i;
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
while (!SLIST_EMPTY(&ss->lro_free)) {
|
|
|
|
lro_entry = SLIST_FIRST(&ss->lro_free);
|
|
|
|
SLIST_REMOVE_HEAD(&ss->lro_free, next);
|
|
|
|
free(lro_entry, M_DEVBUF);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i <= ss->rx_big.mask; i++) {
|
|
|
|
if (ss->rx_big.info[i].m == NULL)
|
2006-02-19 22:39:19 +00:00
|
|
|
continue;
|
2008-01-15 20:34:49 +00:00
|
|
|
bus_dmamap_unload(ss->rx_big.dmat,
|
|
|
|
ss->rx_big.info[i].map);
|
|
|
|
m_freem(ss->rx_big.info[i].m);
|
|
|
|
ss->rx_big.info[i].m = NULL;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
for (i = 0; i <= ss->rx_small.mask; i++) {
|
|
|
|
if (ss->rx_small.info[i].m == NULL)
|
2006-02-19 22:39:19 +00:00
|
|
|
continue;
|
2008-01-15 20:34:49 +00:00
|
|
|
bus_dmamap_unload(ss->rx_small.dmat,
|
|
|
|
ss->rx_small.info[i].map);
|
|
|
|
m_freem(ss->rx_small.info[i].m);
|
|
|
|
ss->rx_small.info[i].m = NULL;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
/* transmit ring used only on the first slice */
|
|
|
|
if (ss->tx.info == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i <= ss->tx.mask; i++) {
|
|
|
|
ss->tx.info[i].flag = 0;
|
|
|
|
if (ss->tx.info[i].m == NULL)
|
2006-02-19 22:39:19 +00:00
|
|
|
continue;
|
2008-01-15 20:34:49 +00:00
|
|
|
bus_dmamap_unload(ss->tx.dmat,
|
|
|
|
ss->tx.info[i].map);
|
|
|
|
m_freem(ss->tx.info[i].m);
|
|
|
|
ss->tx.info[i].m = NULL;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_free_mbufs(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
int slice;
|
|
|
|
|
|
|
|
for (slice = 0; slice < sc->num_slices; slice++)
|
|
|
|
mxge_free_slice_mbufs(&sc->ss[slice]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mxge_free_slice_rings(struct mxge_slice_state *ss)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
|
|
|
|
if (ss->rx_done.entry != NULL)
|
|
|
|
mxge_dma_free(&ss->rx_done.dma);
|
|
|
|
ss->rx_done.entry = NULL;
|
|
|
|
|
|
|
|
if (ss->tx.req_bytes != NULL)
|
|
|
|
free(ss->tx.req_bytes, M_DEVBUF);
|
|
|
|
ss->tx.req_bytes = NULL;
|
|
|
|
|
|
|
|
if (ss->tx.seg_list != NULL)
|
|
|
|
free(ss->tx.seg_list, M_DEVBUF);
|
|
|
|
ss->tx.seg_list = NULL;
|
|
|
|
|
|
|
|
if (ss->rx_small.shadow != NULL)
|
|
|
|
free(ss->rx_small.shadow, M_DEVBUF);
|
|
|
|
ss->rx_small.shadow = NULL;
|
|
|
|
|
|
|
|
if (ss->rx_big.shadow != NULL)
|
|
|
|
free(ss->rx_big.shadow, M_DEVBUF);
|
|
|
|
ss->rx_big.shadow = NULL;
|
|
|
|
|
|
|
|
if (ss->tx.info != NULL) {
|
|
|
|
if (ss->tx.dmat != NULL) {
|
|
|
|
for (i = 0; i <= ss->tx.mask; i++) {
|
|
|
|
bus_dmamap_destroy(ss->tx.dmat,
|
|
|
|
ss->tx.info[i].map);
|
2007-01-31 15:47:44 +00:00
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
bus_dma_tag_destroy(ss->tx.dmat);
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
free(ss->tx.info, M_DEVBUF);
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
ss->tx.info = NULL;
|
|
|
|
|
|
|
|
if (ss->rx_small.info != NULL) {
|
|
|
|
if (ss->rx_small.dmat != NULL) {
|
|
|
|
for (i = 0; i <= ss->rx_small.mask; i++) {
|
|
|
|
bus_dmamap_destroy(ss->rx_small.dmat,
|
|
|
|
ss->rx_small.info[i].map);
|
2007-01-31 15:47:44 +00:00
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
bus_dmamap_destroy(ss->rx_small.dmat,
|
|
|
|
ss->rx_small.extra_map);
|
|
|
|
bus_dma_tag_destroy(ss->rx_small.dmat);
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
free(ss->rx_small.info, M_DEVBUF);
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
ss->rx_small.info = NULL;
|
|
|
|
|
|
|
|
if (ss->rx_big.info != NULL) {
|
|
|
|
if (ss->rx_big.dmat != NULL) {
|
|
|
|
for (i = 0; i <= ss->rx_big.mask; i++) {
|
|
|
|
bus_dmamap_destroy(ss->rx_big.dmat,
|
|
|
|
ss->rx_big.info[i].map);
|
2007-01-31 15:47:44 +00:00
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
bus_dmamap_destroy(ss->rx_big.dmat,
|
|
|
|
ss->rx_big.extra_map);
|
|
|
|
bus_dma_tag_destroy(ss->rx_big.dmat);
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
free(ss->rx_big.info, M_DEVBUF);
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
ss->rx_big.info = NULL;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
static void
|
|
|
|
mxge_free_rings(mxge_softc_t *sc)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2008-01-15 20:34:49 +00:00
|
|
|
int slice;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
for (slice = 0; slice < sc->num_slices; slice++)
|
|
|
|
mxge_free_slice_rings(&sc->ss[slice]);
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
static int
|
|
|
|
mxge_alloc_slice_rings(struct mxge_slice_state *ss, int rx_ring_entries,
|
|
|
|
int tx_ring_entries)
|
|
|
|
{
|
|
|
|
mxge_softc_t *sc = ss->sc;
|
|
|
|
size_t bytes;
|
|
|
|
int err, i;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
err = ENOMEM;
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
/* allocate per-slice receive resources */
|
2007-05-22 15:57:49 +00:00
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
ss->rx_small.mask = ss->rx_big.mask = rx_ring_entries - 1;
|
|
|
|
ss->rx_done.mask = (2 * rx_ring_entries) - 1;
|
2006-09-15 15:41:28 +00:00
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
/* allocate the rx shadow rings */
|
2008-01-15 20:34:49 +00:00
|
|
|
bytes = rx_ring_entries * sizeof (*ss->rx_small.shadow);
|
|
|
|
ss->rx_small.shadow = malloc(bytes, M_DEVBUF, M_ZERO|M_WAITOK);
|
|
|
|
if (ss->rx_small.shadow == NULL)
|
|
|
|
return err;;
|
|
|
|
|
|
|
|
bytes = rx_ring_entries * sizeof (*ss->rx_big.shadow);
|
|
|
|
ss->rx_big.shadow = malloc(bytes, M_DEVBUF, M_ZERO|M_WAITOK);
|
|
|
|
if (ss->rx_big.shadow == NULL)
|
|
|
|
return err;;
|
|
|
|
|
|
|
|
/* allocate the rx host info rings */
|
|
|
|
bytes = rx_ring_entries * sizeof (*ss->rx_small.info);
|
|
|
|
ss->rx_small.info = malloc(bytes, M_DEVBUF, M_ZERO|M_WAITOK);
|
|
|
|
if (ss->rx_small.info == NULL)
|
|
|
|
return err;;
|
|
|
|
|
|
|
|
bytes = rx_ring_entries * sizeof (*ss->rx_big.info);
|
|
|
|
ss->rx_big.info = malloc(bytes, M_DEVBUF, M_ZERO|M_WAITOK);
|
|
|
|
if (ss->rx_big.info == NULL)
|
|
|
|
return err;;
|
|
|
|
|
|
|
|
/* allocate the rx busdma resources */
|
2006-02-19 22:39:19 +00:00
|
|
|
err = bus_dma_tag_create(sc->parent_dmat, /* parent */
|
|
|
|
1, /* alignment */
|
|
|
|
4096, /* boundary */
|
|
|
|
BUS_SPACE_MAXADDR, /* low */
|
|
|
|
BUS_SPACE_MAXADDR, /* high */
|
|
|
|
NULL, NULL, /* filter */
|
|
|
|
MHLEN, /* maxsize */
|
|
|
|
1, /* num segs */
|
|
|
|
MHLEN, /* maxsegsize */
|
|
|
|
BUS_DMA_ALLOCNOW, /* flags */
|
|
|
|
NULL, NULL, /* lock */
|
2008-01-15 20:34:49 +00:00
|
|
|
&ss->rx_small.dmat); /* tag */
|
2006-02-19 22:39:19 +00:00
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "Err %d allocating rx_small dmat\n",
|
|
|
|
err);
|
2008-01-15 20:34:49 +00:00
|
|
|
return err;;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = bus_dma_tag_create(sc->parent_dmat, /* parent */
|
|
|
|
1, /* alignment */
|
2008-01-22 22:04:31 +00:00
|
|
|
#if MXGE_VIRT_JUMBOS
|
2006-02-19 22:39:19 +00:00
|
|
|
4096, /* boundary */
|
2008-01-22 22:04:31 +00:00
|
|
|
#else
|
|
|
|
0, /* boundary */
|
|
|
|
#endif
|
2006-02-19 22:39:19 +00:00
|
|
|
BUS_SPACE_MAXADDR, /* low */
|
|
|
|
BUS_SPACE_MAXADDR, /* high */
|
|
|
|
NULL, NULL, /* filter */
|
2007-05-21 18:32:27 +00:00
|
|
|
3*4096, /* maxsize */
|
2008-01-22 22:04:31 +00:00
|
|
|
#if MXGE_VIRT_JUMBOS
|
2007-05-21 18:32:27 +00:00
|
|
|
3, /* num segs */
|
2008-01-22 22:04:31 +00:00
|
|
|
4096, /* maxsegsize*/
|
|
|
|
#else
|
|
|
|
1, /* num segs */
|
|
|
|
MJUM9BYTES, /* maxsegsize*/
|
|
|
|
#endif
|
2006-02-19 22:39:19 +00:00
|
|
|
BUS_DMA_ALLOCNOW, /* flags */
|
|
|
|
NULL, NULL, /* lock */
|
2008-01-15 20:34:49 +00:00
|
|
|
&ss->rx_big.dmat); /* tag */
|
2006-02-19 22:39:19 +00:00
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "Err %d allocating rx_big dmat\n",
|
|
|
|
err);
|
2008-01-15 20:34:49 +00:00
|
|
|
return err;;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
for (i = 0; i <= ss->rx_small.mask; i++) {
|
|
|
|
err = bus_dmamap_create(ss->rx_small.dmat, 0,
|
|
|
|
&ss->rx_small.info[i].map);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "Err %d rx_small dmamap\n",
|
2006-06-13 13:53:52 +00:00
|
|
|
err);
|
2008-01-15 20:34:49 +00:00
|
|
|
return err;;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
err = bus_dmamap_create(ss->rx_small.dmat, 0,
|
|
|
|
&ss->rx_small.extra_map);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "Err %d extra rx_small dmamap\n",
|
|
|
|
err);
|
2008-01-15 20:34:49 +00:00
|
|
|
return err;;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
for (i = 0; i <= ss->rx_big.mask; i++) {
|
|
|
|
err = bus_dmamap_create(ss->rx_big.dmat, 0,
|
|
|
|
&ss->rx_big.info[i].map);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "Err %d rx_big dmamap\n",
|
2008-01-15 20:34:49 +00:00
|
|
|
err);
|
|
|
|
return err;;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
err = bus_dmamap_create(ss->rx_big.dmat, 0,
|
|
|
|
&ss->rx_big.extra_map);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "Err %d extra rx_big dmamap\n",
|
|
|
|
err);
|
2008-01-15 20:34:49 +00:00
|
|
|
return err;;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now allocate TX resouces */
|
|
|
|
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifndef IFNET_BUF_RING
|
2008-01-15 20:34:49 +00:00
|
|
|
/* only use a single TX ring for now */
|
|
|
|
if (ss != ss->sc->ss)
|
|
|
|
return 0;
|
2009-04-27 15:45:54 +00:00
|
|
|
#endif
|
2008-01-15 20:34:49 +00:00
|
|
|
|
|
|
|
ss->tx.mask = tx_ring_entries - 1;
|
|
|
|
ss->tx.max_desc = MIN(MXGE_MAX_SEND_DESC, tx_ring_entries / 4);
|
|
|
|
|
|
|
|
|
|
|
|
/* allocate the tx request copy block */
|
|
|
|
bytes = 8 +
|
|
|
|
sizeof (*ss->tx.req_list) * (ss->tx.max_desc + 4);
|
|
|
|
ss->tx.req_bytes = malloc(bytes, M_DEVBUF, M_WAITOK);
|
|
|
|
if (ss->tx.req_bytes == NULL)
|
|
|
|
return err;;
|
|
|
|
/* ensure req_list entries are aligned to 8 bytes */
|
|
|
|
ss->tx.req_list = (mcp_kreq_ether_send_t *)
|
|
|
|
((unsigned long)(ss->tx.req_bytes + 7) & ~7UL);
|
|
|
|
|
|
|
|
/* allocate the tx busdma segment list */
|
|
|
|
bytes = sizeof (*ss->tx.seg_list) * ss->tx.max_desc;
|
|
|
|
ss->tx.seg_list = (bus_dma_segment_t *)
|
|
|
|
malloc(bytes, M_DEVBUF, M_WAITOK);
|
|
|
|
if (ss->tx.seg_list == NULL)
|
|
|
|
return err;;
|
|
|
|
|
|
|
|
/* allocate the tx host info ring */
|
|
|
|
bytes = tx_ring_entries * sizeof (*ss->tx.info);
|
|
|
|
ss->tx.info = malloc(bytes, M_DEVBUF, M_ZERO|M_WAITOK);
|
|
|
|
if (ss->tx.info == NULL)
|
|
|
|
return err;;
|
|
|
|
|
|
|
|
/* allocate the tx busdma resources */
|
|
|
|
err = bus_dma_tag_create(sc->parent_dmat, /* parent */
|
|
|
|
1, /* alignment */
|
|
|
|
sc->tx_boundary, /* boundary */
|
|
|
|
BUS_SPACE_MAXADDR, /* low */
|
|
|
|
BUS_SPACE_MAXADDR, /* high */
|
|
|
|
NULL, NULL, /* filter */
|
|
|
|
65536 + 256, /* maxsize */
|
|
|
|
ss->tx.max_desc - 2, /* num segs */
|
|
|
|
sc->tx_boundary, /* maxsegsz */
|
|
|
|
BUS_DMA_ALLOCNOW, /* flags */
|
|
|
|
NULL, NULL, /* lock */
|
|
|
|
&ss->tx.dmat); /* tag */
|
|
|
|
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "Err %d allocating tx dmat\n",
|
|
|
|
err);
|
|
|
|
return err;;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now use these tags to setup dmamaps for each slot
|
|
|
|
in the ring */
|
|
|
|
for (i = 0; i <= ss->tx.mask; i++) {
|
|
|
|
err = bus_dmamap_create(ss->tx.dmat, 0,
|
|
|
|
&ss->tx.info[i].map);
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "Err %d tx dmamap\n",
|
|
|
|
err);
|
|
|
|
return err;;
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
static int
|
|
|
|
mxge_alloc_rings(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
mxge_cmd_t cmd;
|
|
|
|
int tx_ring_size;
|
|
|
|
int tx_ring_entries, rx_ring_entries;
|
|
|
|
int err, slice;
|
|
|
|
|
|
|
|
/* get ring sizes */
|
|
|
|
err = mxge_send_cmd(sc, MXGEFW_CMD_GET_SEND_RING_SIZE, &cmd);
|
|
|
|
tx_ring_size = cmd.data0;
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "Cannot determine tx ring sizes\n");
|
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
|
|
|
|
tx_ring_entries = tx_ring_size / sizeof (mcp_kreq_ether_send_t);
|
|
|
|
rx_ring_entries = sc->rx_ring_size / sizeof (mcp_dma_addr_t);
|
|
|
|
IFQ_SET_MAXLEN(&sc->ifp->if_snd, tx_ring_entries - 1);
|
|
|
|
sc->ifp->if_snd.ifq_drv_maxlen = sc->ifp->if_snd.ifq_maxlen;
|
|
|
|
IFQ_SET_READY(&sc->ifp->if_snd);
|
|
|
|
|
|
|
|
for (slice = 0; slice < sc->num_slices; slice++) {
|
|
|
|
err = mxge_alloc_slice_rings(&sc->ss[slice],
|
|
|
|
rx_ring_entries,
|
|
|
|
tx_ring_entries);
|
|
|
|
if (err != 0)
|
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
abort:
|
|
|
|
mxge_free_rings(sc);
|
2006-02-19 22:39:19 +00:00
|
|
|
return err;
|
2008-01-15 20:34:49 +00:00
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
|
2007-05-21 18:32:27 +00:00
|
|
|
static void
|
|
|
|
mxge_choose_params(int mtu, int *big_buf_size, int *cl_size, int *nbufs)
|
|
|
|
{
|
2007-05-23 16:25:40 +00:00
|
|
|
int bufsize = mtu + ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN + MXGEFW_PAD;
|
2007-05-21 18:32:27 +00:00
|
|
|
|
|
|
|
if (bufsize < MCLBYTES) {
|
|
|
|
/* easy, everything fits in a single buffer */
|
|
|
|
*big_buf_size = MCLBYTES;
|
|
|
|
*cl_size = MCLBYTES;
|
|
|
|
*nbufs = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bufsize < MJUMPAGESIZE) {
|
|
|
|
/* still easy, everything still fits in a single buffer */
|
|
|
|
*big_buf_size = MJUMPAGESIZE;
|
|
|
|
*cl_size = MJUMPAGESIZE;
|
|
|
|
*nbufs = 1;
|
|
|
|
return;
|
|
|
|
}
|
2008-01-22 22:04:31 +00:00
|
|
|
#if MXGE_VIRT_JUMBOS
|
2007-05-21 18:32:27 +00:00
|
|
|
/* now we need to use virtually contiguous buffers */
|
|
|
|
*cl_size = MJUM9BYTES;
|
|
|
|
*big_buf_size = 4096;
|
|
|
|
*nbufs = mtu / 4096 + 1;
|
|
|
|
/* needs to be a power of two, so round up */
|
|
|
|
if (*nbufs == 3)
|
|
|
|
*nbufs = 4;
|
2008-01-22 22:04:31 +00:00
|
|
|
#else
|
|
|
|
*cl_size = MJUM9BYTES;
|
|
|
|
*big_buf_size = MJUM9BYTES;
|
|
|
|
*nbufs = 1;
|
|
|
|
#endif
|
2007-05-21 18:32:27 +00:00
|
|
|
}
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
static int
|
|
|
|
mxge_slice_open(struct mxge_slice_state *ss, int nbufs, int cl_size)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_softc_t *sc;
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_cmd_t cmd;
|
2006-02-19 22:39:19 +00:00
|
|
|
bus_dmamap_t map;
|
2007-05-21 18:32:27 +00:00
|
|
|
struct lro_entry *lro_entry;
|
2008-01-15 20:34:49 +00:00
|
|
|
int err, i, slice;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
|
|
|
|
sc = ss->sc;
|
|
|
|
slice = ss - sc->ss;
|
|
|
|
|
|
|
|
SLIST_INIT(&ss->lro_free);
|
|
|
|
SLIST_INIT(&ss->lro_active);
|
2007-05-21 18:32:27 +00:00
|
|
|
|
|
|
|
for (i = 0; i < sc->lro_cnt; i++) {
|
|
|
|
lro_entry = (struct lro_entry *)
|
2008-01-15 20:34:49 +00:00
|
|
|
malloc(sizeof (*lro_entry), M_DEVBUF,
|
|
|
|
M_NOWAIT | M_ZERO);
|
2007-05-21 18:32:27 +00:00
|
|
|
if (lro_entry == NULL) {
|
|
|
|
sc->lro_cnt = i;
|
|
|
|
break;
|
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
SLIST_INSERT_HEAD(&ss->lro_free, lro_entry, next);
|
2007-05-21 18:32:27 +00:00
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
/* get the lanai pointers to the send and receive rings */
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
err = 0;
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifndef IFNET_BUF_RING
|
2008-01-15 20:34:49 +00:00
|
|
|
/* We currently only send from the first slice */
|
|
|
|
if (slice == 0) {
|
2009-04-27 15:45:54 +00:00
|
|
|
#endif
|
2008-01-15 20:34:49 +00:00
|
|
|
cmd.data0 = slice;
|
|
|
|
err = mxge_send_cmd(sc, MXGEFW_CMD_GET_SEND_OFFSET, &cmd);
|
|
|
|
ss->tx.lanai =
|
|
|
|
(volatile mcp_kreq_ether_send_t *)(sc->sram + cmd.data0);
|
2009-04-27 15:45:54 +00:00
|
|
|
ss->tx.send_go = (volatile uint32_t *)
|
|
|
|
(sc->sram + MXGEFW_ETH_SEND_GO + 64 * slice);
|
|
|
|
ss->tx.send_stop = (volatile uint32_t *)
|
|
|
|
(sc->sram + MXGEFW_ETH_SEND_STOP + 64 * slice);
|
|
|
|
#ifndef IFNET_BUF_RING
|
2008-01-15 20:34:49 +00:00
|
|
|
}
|
2009-04-27 15:45:54 +00:00
|
|
|
#endif
|
2008-01-15 20:34:49 +00:00
|
|
|
cmd.data0 = slice;
|
2006-06-13 13:53:52 +00:00
|
|
|
err |= mxge_send_cmd(sc,
|
2008-01-15 20:34:49 +00:00
|
|
|
MXGEFW_CMD_GET_SMALL_RX_OFFSET, &cmd);
|
|
|
|
ss->rx_small.lanai =
|
2006-02-19 22:39:19 +00:00
|
|
|
(volatile mcp_kreq_ether_recv_t *)(sc->sram + cmd.data0);
|
2008-01-15 20:34:49 +00:00
|
|
|
cmd.data0 = slice;
|
2006-06-14 16:23:17 +00:00
|
|
|
err |= mxge_send_cmd(sc, MXGEFW_CMD_GET_BIG_RX_OFFSET, &cmd);
|
2008-01-15 20:34:49 +00:00
|
|
|
ss->rx_big.lanai =
|
2006-02-19 22:39:19 +00:00
|
|
|
(volatile mcp_kreq_ether_recv_t *)(sc->sram + cmd.data0);
|
|
|
|
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"failed to get ring sizes or locations\n");
|
2007-01-31 15:29:31 +00:00
|
|
|
return EIO;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* stock receive rings */
|
2008-01-15 20:34:49 +00:00
|
|
|
for (i = 0; i <= ss->rx_small.mask; i++) {
|
|
|
|
map = ss->rx_small.info[i].map;
|
|
|
|
err = mxge_get_buf_small(ss, map, i);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (err) {
|
|
|
|
device_printf(sc->dev, "alloced %d/%d smalls\n",
|
2008-01-15 20:34:49 +00:00
|
|
|
i, ss->rx_small.mask + 1);
|
|
|
|
return ENOMEM;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
for (i = 0; i <= ss->rx_big.mask; i++) {
|
|
|
|
ss->rx_big.shadow[i].addr_low = 0xffffffff;
|
|
|
|
ss->rx_big.shadow[i].addr_high = 0xffffffff;
|
2007-05-21 18:32:27 +00:00
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
ss->rx_big.nbufs = nbufs;
|
|
|
|
ss->rx_big.cl_size = cl_size;
|
|
|
|
for (i = 0; i <= ss->rx_big.mask; i += ss->rx_big.nbufs) {
|
|
|
|
map = ss->rx_big.info[i].map;
|
|
|
|
err = mxge_get_buf_big(ss, map, i);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (err) {
|
|
|
|
device_printf(sc->dev, "alloced %d/%d bigs\n",
|
2008-01-15 20:34:49 +00:00
|
|
|
i, ss->rx_big.mask + 1);
|
|
|
|
return ENOMEM;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mxge_open(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
mxge_cmd_t cmd;
|
|
|
|
int err, big_bytes, nbufs, slice, cl_size, i;
|
|
|
|
bus_addr_t bus;
|
|
|
|
volatile uint8_t *itable;
|
2009-04-27 15:45:54 +00:00
|
|
|
struct mxge_slice_state *ss;
|
2008-01-15 20:34:49 +00:00
|
|
|
|
|
|
|
/* Copy the MAC address in case it was overridden */
|
|
|
|
bcopy(IF_LLADDR(sc->ifp), sc->mac_addr, ETHER_ADDR_LEN);
|
|
|
|
|
|
|
|
err = mxge_reset(sc, 1);
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "failed to reset\n");
|
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->num_slices > 1) {
|
|
|
|
/* setup the indirection table */
|
|
|
|
cmd.data0 = sc->num_slices;
|
|
|
|
err = mxge_send_cmd(sc, MXGEFW_CMD_SET_RSS_TABLE_SIZE,
|
|
|
|
&cmd);
|
|
|
|
|
|
|
|
err |= mxge_send_cmd(sc, MXGEFW_CMD_GET_RSS_TABLE_OFFSET,
|
|
|
|
&cmd);
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"failed to setup rss tables\n");
|
|
|
|
return err;
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
/* just enable an identity mapping */
|
|
|
|
itable = sc->sram + cmd.data0;
|
|
|
|
for (i = 0; i < sc->num_slices; i++)
|
|
|
|
itable[i] = (uint8_t)i;
|
|
|
|
|
|
|
|
cmd.data0 = 1;
|
|
|
|
cmd.data1 = mxge_rss_hash_type;
|
|
|
|
err = mxge_send_cmd(sc, MXGEFW_CMD_SET_RSS_ENABLE, &cmd);
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "failed to enable slices\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mxge_choose_params(sc->ifp->if_mtu, &big_bytes, &cl_size, &nbufs);
|
|
|
|
|
|
|
|
cmd.data0 = nbufs;
|
|
|
|
err = mxge_send_cmd(sc, MXGEFW_CMD_ALWAYS_USE_N_BIG_BUFFERS,
|
|
|
|
&cmd);
|
|
|
|
/* error is only meaningful if we're trying to set
|
|
|
|
MXGEFW_CMD_ALWAYS_USE_N_BIG_BUFFERS > 1 */
|
|
|
|
if (err && nbufs > 1) {
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"Failed to set alway-use-n to %d\n",
|
|
|
|
nbufs);
|
|
|
|
return EIO;
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
/* Give the firmware the mtu and the big and small buffer
|
|
|
|
sizes. The firmware wants the big buf size to be a power
|
|
|
|
of two. Luckily, FreeBSD's clusters are powers of two */
|
2007-05-23 16:25:40 +00:00
|
|
|
cmd.data0 = sc->ifp->if_mtu + ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
|
2006-06-14 16:23:17 +00:00
|
|
|
err = mxge_send_cmd(sc, MXGEFW_CMD_SET_MTU, &cmd);
|
2006-10-17 14:39:19 +00:00
|
|
|
cmd.data0 = MHLEN - MXGEFW_PAD;
|
2006-06-14 16:23:17 +00:00
|
|
|
err |= mxge_send_cmd(sc, MXGEFW_CMD_SET_SMALL_BUFFER_SIZE,
|
2006-06-13 13:53:52 +00:00
|
|
|
&cmd);
|
2007-05-21 18:32:27 +00:00
|
|
|
cmd.data0 = big_bytes;
|
2006-06-14 16:23:17 +00:00
|
|
|
err |= mxge_send_cmd(sc, MXGEFW_CMD_SET_BIG_BUFFER_SIZE, &cmd);
|
2006-09-15 19:24:45 +00:00
|
|
|
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "failed to setup params\n");
|
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
/* Now give him the pointer to the stats block */
|
2009-04-27 15:45:54 +00:00
|
|
|
for (slice = 0;
|
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
slice < sc->num_slices;
|
|
|
|
#else
|
|
|
|
slice < 1;
|
|
|
|
#endif
|
|
|
|
slice++) {
|
|
|
|
ss = &sc->ss[slice];
|
|
|
|
cmd.data0 =
|
|
|
|
MXGE_LOWPART_TO_U32(ss->fw_stats_dma.bus_addr);
|
|
|
|
cmd.data1 =
|
|
|
|
MXGE_HIGHPART_TO_U32(ss->fw_stats_dma.bus_addr);
|
|
|
|
cmd.data2 = sizeof(struct mcp_irq_data);
|
|
|
|
cmd.data2 |= (slice << 16);
|
|
|
|
err |= mxge_send_cmd(sc, MXGEFW_CMD_SET_STATS_DMA_V2, &cmd);
|
|
|
|
}
|
2006-09-15 19:24:45 +00:00
|
|
|
|
|
|
|
if (err != 0) {
|
2008-01-15 20:34:49 +00:00
|
|
|
bus = sc->ss->fw_stats_dma.bus_addr;
|
2006-09-15 19:24:45 +00:00
|
|
|
bus += offsetof(struct mcp_irq_data, send_done_count);
|
|
|
|
cmd.data0 = MXGE_LOWPART_TO_U32(bus);
|
|
|
|
cmd.data1 = MXGE_HIGHPART_TO_U32(bus);
|
|
|
|
err = mxge_send_cmd(sc,
|
|
|
|
MXGEFW_CMD_SET_STATS_DMA_OBSOLETE,
|
|
|
|
&cmd);
|
|
|
|
/* Firmware cannot support multicast without STATS_DMA_V2 */
|
|
|
|
sc->fw_multicast_support = 0;
|
|
|
|
} else {
|
|
|
|
sc->fw_multicast_support = 1;
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "failed to setup params\n");
|
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
for (slice = 0; slice < sc->num_slices; slice++) {
|
|
|
|
err = mxge_slice_open(&sc->ss[slice], nbufs, cl_size);
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "couldn't open slice %d\n",
|
|
|
|
slice);
|
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
/* Finally, start the firmware running */
|
2006-06-14 16:23:17 +00:00
|
|
|
err = mxge_send_cmd(sc, MXGEFW_CMD_ETHERNET_UP, &cmd);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (err) {
|
|
|
|
device_printf(sc->dev, "Couldn't bring up link\n");
|
|
|
|
goto abort;
|
|
|
|
}
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
for (slice = 0; slice < sc->num_slices; slice++) {
|
|
|
|
ss = &sc->ss[slice];
|
|
|
|
ss->if_drv_flags |= IFF_DRV_RUNNING;
|
|
|
|
ss->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
|
|
|
}
|
|
|
|
#endif
|
2006-02-19 22:39:19 +00:00
|
|
|
sc->ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
|
|
|
sc->ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
2008-07-17 15:46:35 +00:00
|
|
|
callout_reset(&sc->co_hdl, mxge_ticks, mxge_tick, sc);
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
abort:
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_free_mbufs(sc);
|
2007-01-31 15:29:31 +00:00
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_close(mxge_softc_t *sc)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_cmd_t cmd;
|
2006-02-19 22:39:19 +00:00
|
|
|
int err, old_down_cnt;
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
struct mxge_slice_state *ss;
|
|
|
|
int slice;
|
|
|
|
#endif
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2008-07-17 15:46:35 +00:00
|
|
|
callout_stop(&sc->co_hdl);
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
for (slice = 0; slice < sc->num_slices; slice++) {
|
|
|
|
ss = &sc->ss[slice];
|
|
|
|
ss->if_drv_flags &= ~IFF_DRV_RUNNING;
|
|
|
|
}
|
|
|
|
#endif
|
2006-02-19 22:39:19 +00:00
|
|
|
sc->ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
|
|
|
old_down_cnt = sc->down_cnt;
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2006-06-14 16:23:17 +00:00
|
|
|
err = mxge_send_cmd(sc, MXGEFW_CMD_ETHERNET_DOWN, &cmd);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (err) {
|
|
|
|
device_printf(sc->dev, "Couldn't bring down link\n");
|
|
|
|
}
|
|
|
|
if (old_down_cnt == sc->down_cnt) {
|
|
|
|
/* wait for down irq */
|
2007-01-31 19:53:36 +00:00
|
|
|
DELAY(10 * sc->intr_coal_delay);
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2008-11-24 19:00:57 +00:00
|
|
|
wmb();
|
2006-02-19 22:39:19 +00:00
|
|
|
if (old_down_cnt == sc->down_cnt) {
|
|
|
|
device_printf(sc->dev, "never got down irq\n");
|
|
|
|
}
|
2007-01-31 15:29:31 +00:00
|
|
|
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_free_mbufs(sc);
|
2007-01-31 15:29:31 +00:00
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-31 19:53:36 +00:00
|
|
|
static void
|
|
|
|
mxge_setup_cfg_space(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
device_t dev = sc->dev;
|
|
|
|
int reg;
|
|
|
|
uint16_t cmd, lnk, pectl;
|
|
|
|
|
|
|
|
/* find the PCIe link width and set max read request to 4KB*/
|
|
|
|
if (pci_find_extcap(dev, PCIY_EXPRESS, ®) == 0) {
|
|
|
|
lnk = pci_read_config(dev, reg + 0x12, 2);
|
|
|
|
sc->link_width = (lnk >> 4) & 0x3f;
|
|
|
|
|
|
|
|
pectl = pci_read_config(dev, reg + 0x8, 2);
|
|
|
|
pectl = (pectl & ~0x7000) | (5 << 12);
|
|
|
|
pci_write_config(dev, reg + 0x8, pectl, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable DMA and Memory space access */
|
|
|
|
pci_enable_busmaster(dev);
|
|
|
|
cmd = pci_read_config(dev, PCIR_COMMAND, 2);
|
|
|
|
cmd |= PCIM_CMD_MEMEN;
|
|
|
|
pci_write_config(dev, PCIR_COMMAND, cmd, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
mxge_read_reboot(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
device_t dev = sc->dev;
|
|
|
|
uint32_t vs;
|
|
|
|
|
|
|
|
/* find the vendor specific offset */
|
|
|
|
if (pci_find_extcap(dev, PCIY_VENDOR, &vs) != 0) {
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"could not find vendor specific offset\n");
|
|
|
|
return (uint32_t)-1;
|
|
|
|
}
|
|
|
|
/* enable read32 mode */
|
|
|
|
pci_write_config(dev, vs + 0x10, 0x3, 1);
|
|
|
|
/* tell NIC which register to read */
|
|
|
|
pci_write_config(dev, vs + 0x18, 0xfffffff0, 4);
|
|
|
|
return (pci_read_config(dev, vs + 0x14, 4));
|
|
|
|
}
|
|
|
|
|
2008-07-17 15:46:35 +00:00
|
|
|
static int
|
2009-04-27 15:45:54 +00:00
|
|
|
mxge_watchdog_reset(mxge_softc_t *sc, int slice)
|
2007-01-31 19:53:36 +00:00
|
|
|
{
|
2008-07-17 15:46:35 +00:00
|
|
|
struct pci_devinfo *dinfo;
|
2009-04-27 15:45:54 +00:00
|
|
|
mxge_tx_ring_t *tx;
|
2007-01-31 19:53:36 +00:00
|
|
|
int err;
|
|
|
|
uint32_t reboot;
|
|
|
|
uint16_t cmd;
|
|
|
|
|
|
|
|
err = ENXIO;
|
|
|
|
|
|
|
|
device_printf(sc->dev, "Watchdog reset!\n");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check to see if the NIC rebooted. If it did, then all of
|
|
|
|
* PCI config space has been reset, and things like the
|
|
|
|
* busmaster bit will be zero. If this is the case, then we
|
|
|
|
* must restore PCI config space before the NIC can be used
|
|
|
|
* again
|
|
|
|
*/
|
|
|
|
cmd = pci_read_config(sc->dev, PCIR_COMMAND, 2);
|
|
|
|
if (cmd == 0xffff) {
|
|
|
|
/*
|
|
|
|
* maybe the watchdog caught the NIC rebooting; wait
|
|
|
|
* up to 100ms for it to finish. If it does not come
|
|
|
|
* back, then give up
|
|
|
|
*/
|
|
|
|
DELAY(1000*100);
|
|
|
|
cmd = pci_read_config(sc->dev, PCIR_COMMAND, 2);
|
|
|
|
if (cmd == 0xffff) {
|
|
|
|
device_printf(sc->dev, "NIC disappeared!\n");
|
2008-07-17 15:46:35 +00:00
|
|
|
return (err);
|
2007-01-31 19:53:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((cmd & PCIM_CMD_BUSMASTEREN) == 0) {
|
|
|
|
/* print the reboot status */
|
|
|
|
reboot = mxge_read_reboot(sc);
|
|
|
|
device_printf(sc->dev, "NIC rebooted, status = 0x%x\n",
|
|
|
|
reboot);
|
|
|
|
/* restore PCI configuration space */
|
2008-07-17 15:46:35 +00:00
|
|
|
dinfo = device_get_ivars(sc->dev);
|
|
|
|
pci_cfg_restore(sc->dev, dinfo);
|
2007-01-31 19:53:36 +00:00
|
|
|
|
|
|
|
/* and redo any changes we made to our config space */
|
|
|
|
mxge_setup_cfg_space(sc);
|
2008-01-28 13:20:51 +00:00
|
|
|
|
|
|
|
if (sc->ifp->if_drv_flags & IFF_DRV_RUNNING) {
|
|
|
|
mxge_close(sc);
|
|
|
|
err = mxge_open(sc);
|
|
|
|
}
|
2007-01-31 19:53:36 +00:00
|
|
|
} else {
|
2009-04-27 15:45:54 +00:00
|
|
|
tx = &sc->ss[slice].tx;
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"NIC did not reboot, slice %d ring state:\n",
|
|
|
|
slice);
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"tx.req=%d tx.done=%d, tx.queue_active=%d\n",
|
|
|
|
tx->req, tx->done, tx->queue_active);
|
|
|
|
device_printf(sc->dev, "tx.activate=%d tx.deactivate=%d\n",
|
|
|
|
tx->activate, tx->deactivate);
|
2007-01-31 19:53:36 +00:00
|
|
|
device_printf(sc->dev, "pkt_done=%d fw=%d\n",
|
2009-04-27 15:45:54 +00:00
|
|
|
tx->pkt_done,
|
2008-01-15 20:34:49 +00:00
|
|
|
be32toh(sc->ss->fw_stats->send_done_count));
|
2008-01-28 13:20:51 +00:00
|
|
|
device_printf(sc->dev, "not resetting\n");
|
2007-01-31 19:53:36 +00:00
|
|
|
}
|
2008-07-17 15:46:35 +00:00
|
|
|
return (err);
|
2007-01-31 19:53:36 +00:00
|
|
|
}
|
|
|
|
|
2008-07-17 15:46:35 +00:00
|
|
|
static int
|
2007-01-31 19:53:36 +00:00
|
|
|
mxge_watchdog(mxge_softc_t *sc)
|
|
|
|
{
|
2009-04-27 15:45:54 +00:00
|
|
|
mxge_tx_ring_t *tx;
|
2008-01-15 20:34:49 +00:00
|
|
|
uint32_t rx_pause = be32toh(sc->ss->fw_stats->dropped_pause);
|
2009-04-27 15:45:54 +00:00
|
|
|
int i, err = 0;
|
2007-01-31 19:53:36 +00:00
|
|
|
|
|
|
|
/* see if we have outstanding transmits, which
|
|
|
|
have been pending for more than mxge_ticks */
|
2009-04-27 15:45:54 +00:00
|
|
|
for (i = 0;
|
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
(i < sc->num_slices) && (err == 0);
|
|
|
|
#else
|
|
|
|
(i < 1) && (err == 0);
|
|
|
|
#endif
|
|
|
|
i++) {
|
|
|
|
tx = &sc->ss[i].tx;
|
|
|
|
if (tx->req != tx->done &&
|
|
|
|
tx->watchdog_req != tx->watchdog_done &&
|
|
|
|
tx->done == tx->watchdog_done) {
|
|
|
|
/* check for pause blocking before resetting */
|
|
|
|
if (tx->watchdog_rx_pause == rx_pause)
|
|
|
|
err = mxge_watchdog_reset(sc, i);
|
|
|
|
else
|
|
|
|
device_printf(sc->dev, "Flow control blocking "
|
|
|
|
"xmits, check link partner\n");
|
|
|
|
}
|
2007-01-31 19:53:36 +00:00
|
|
|
|
2009-04-27 15:45:54 +00:00
|
|
|
tx->watchdog_req = tx->req;
|
|
|
|
tx->watchdog_done = tx->done;
|
|
|
|
tx->watchdog_rx_pause = rx_pause;
|
|
|
|
}
|
2007-08-22 13:22:12 +00:00
|
|
|
|
|
|
|
if (sc->need_media_probe)
|
|
|
|
mxge_media_probe(sc);
|
2008-07-17 15:46:35 +00:00
|
|
|
return (err);
|
2007-01-31 19:53:36 +00:00
|
|
|
}
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
static void
|
|
|
|
mxge_update_stats(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
struct mxge_slice_state *ss;
|
|
|
|
u_long ipackets = 0;
|
2009-04-27 15:45:54 +00:00
|
|
|
u_long opackets = 0;
|
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
u_long obytes = 0;
|
|
|
|
u_long omcasts = 0;
|
|
|
|
u_long odrops = 0;
|
|
|
|
#endif
|
|
|
|
u_long oerrors = 0;
|
2008-01-15 20:34:49 +00:00
|
|
|
int slice;
|
|
|
|
|
2009-04-27 15:45:54 +00:00
|
|
|
for (slice = 0; slice < sc->num_slices; slice++) {
|
2008-01-15 20:34:49 +00:00
|
|
|
ss = &sc->ss[slice];
|
|
|
|
ipackets += ss->ipackets;
|
2009-04-27 15:45:54 +00:00
|
|
|
opackets += ss->opackets;
|
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
obytes += ss->obytes;
|
|
|
|
omcasts += ss->omcasts;
|
|
|
|
odrops += ss->tx.br->br_drops;
|
|
|
|
#endif
|
|
|
|
oerrors += ss->oerrors;
|
2008-01-15 20:34:49 +00:00
|
|
|
}
|
|
|
|
sc->ifp->if_ipackets = ipackets;
|
2009-04-27 15:45:54 +00:00
|
|
|
sc->ifp->if_opackets = opackets;
|
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
sc->ifp->if_obytes = obytes;
|
|
|
|
sc->ifp->if_omcasts = omcasts;
|
|
|
|
sc->ifp->if_snd.ifq_drops = odrops;
|
|
|
|
#endif
|
|
|
|
sc->ifp->if_oerrors = oerrors;
|
2008-01-15 20:34:49 +00:00
|
|
|
}
|
2009-04-27 15:45:54 +00:00
|
|
|
|
2007-01-31 19:53:36 +00:00
|
|
|
static void
|
|
|
|
mxge_tick(void *arg)
|
|
|
|
{
|
|
|
|
mxge_softc_t *sc = arg;
|
2008-07-17 15:46:35 +00:00
|
|
|
int err = 0;
|
2007-01-31 19:53:36 +00:00
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
/* aggregate stats from different slices */
|
|
|
|
mxge_update_stats(sc);
|
|
|
|
if (!sc->watchdog_countdown) {
|
2008-07-17 15:46:35 +00:00
|
|
|
err = mxge_watchdog(sc);
|
2008-01-15 20:34:49 +00:00
|
|
|
sc->watchdog_countdown = 4;
|
|
|
|
}
|
|
|
|
sc->watchdog_countdown--;
|
2008-07-17 15:46:35 +00:00
|
|
|
if (err == 0)
|
|
|
|
callout_reset(&sc->co_hdl, mxge_ticks, mxge_tick, sc);
|
|
|
|
|
2007-01-31 19:53:36 +00:00
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
static int
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_media_change(struct ifnet *ifp)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_change_mtu(mxge_softc_t *sc, int mtu)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = sc->ifp;
|
|
|
|
int real_mtu, old_mtu;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
|
2007-05-23 16:25:40 +00:00
|
|
|
real_mtu = mtu + ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
|
2007-05-21 18:32:27 +00:00
|
|
|
if ((real_mtu > sc->max_mtu) || real_mtu < 60)
|
2006-02-19 22:39:19 +00:00
|
|
|
return EINVAL;
|
2007-01-31 15:29:31 +00:00
|
|
|
mtx_lock(&sc->driver_mtx);
|
2006-02-19 22:39:19 +00:00
|
|
|
old_mtu = ifp->if_mtu;
|
|
|
|
ifp->if_mtu = mtu;
|
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_close(sc);
|
|
|
|
err = mxge_open(sc);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (err != 0) {
|
|
|
|
ifp->if_mtu = old_mtu;
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_close(sc);
|
|
|
|
(void) mxge_open(sc);
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
2007-01-31 15:29:31 +00:00
|
|
|
mtx_unlock(&sc->driver_mtx);
|
2006-02-19 22:39:19 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_softc_t *sc = ifp->if_softc;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (sc == NULL)
|
|
|
|
return;
|
|
|
|
ifmr->ifm_status = IFM_AVALID;
|
2007-08-22 13:22:12 +00:00
|
|
|
ifmr->ifm_status |= sc->link_state ? IFM_ACTIVE : 0;
|
2006-02-19 22:39:19 +00:00
|
|
|
ifmr->ifm_active = IFM_AUTO | IFM_ETHER;
|
2007-08-22 13:22:12 +00:00
|
|
|
ifmr->ifm_active |= sc->link_state ? IFM_FDX : 0;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_softc_t *sc = ifp->if_softc;
|
2006-02-19 22:39:19 +00:00
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
|
|
|
int err, mask;
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
switch (command) {
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
case SIOCGIFADDR:
|
|
|
|
err = ether_ioctl(ifp, command, data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFMTU:
|
2006-06-13 13:53:52 +00:00
|
|
|
err = mxge_change_mtu(sc, ifr->ifr_mtu);
|
2006-02-19 22:39:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFFLAGS:
|
2007-01-31 15:29:31 +00:00
|
|
|
mtx_lock(&sc->driver_mtx);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (ifp->if_flags & IFF_UP) {
|
2007-01-31 19:53:36 +00:00
|
|
|
if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
|
2006-06-13 13:53:52 +00:00
|
|
|
err = mxge_open(sc);
|
2007-01-31 19:53:36 +00:00
|
|
|
} else {
|
2006-09-15 19:24:45 +00:00
|
|
|
/* take care of promis can allmulti
|
|
|
|
flag chages */
|
|
|
|
mxge_change_promisc(sc,
|
|
|
|
ifp->if_flags & IFF_PROMISC);
|
|
|
|
mxge_set_multicast_list(sc);
|
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
} else {
|
2007-01-31 19:53:36 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_close(sc);
|
2007-01-31 19:53:36 +00:00
|
|
|
}
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
2007-01-31 15:29:31 +00:00
|
|
|
mtx_unlock(&sc->driver_mtx);
|
2006-02-19 22:39:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
2007-01-31 15:29:31 +00:00
|
|
|
mtx_lock(&sc->driver_mtx);
|
2006-09-15 19:24:45 +00:00
|
|
|
mxge_set_multicast_list(sc);
|
2007-01-31 15:29:31 +00:00
|
|
|
mtx_unlock(&sc->driver_mtx);
|
2006-02-19 22:39:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFCAP:
|
2007-01-31 15:29:31 +00:00
|
|
|
mtx_lock(&sc->driver_mtx);
|
2006-02-19 22:39:19 +00:00
|
|
|
mask = ifr->ifr_reqcap ^ ifp->if_capenable;
|
|
|
|
if (mask & IFCAP_TXCSUM) {
|
|
|
|
if (IFCAP_TXCSUM & ifp->if_capenable) {
|
2006-09-15 15:41:28 +00:00
|
|
|
ifp->if_capenable &= ~(IFCAP_TXCSUM|IFCAP_TSO4);
|
|
|
|
ifp->if_hwassist &= ~(CSUM_TCP | CSUM_UDP
|
|
|
|
| CSUM_TSO);
|
2006-02-19 22:39:19 +00:00
|
|
|
} else {
|
|
|
|
ifp->if_capenable |= IFCAP_TXCSUM;
|
|
|
|
ifp->if_hwassist |= (CSUM_TCP | CSUM_UDP);
|
|
|
|
}
|
|
|
|
} else if (mask & IFCAP_RXCSUM) {
|
|
|
|
if (IFCAP_RXCSUM & ifp->if_capenable) {
|
|
|
|
ifp->if_capenable &= ~IFCAP_RXCSUM;
|
2006-06-14 16:23:17 +00:00
|
|
|
sc->csum_flag = 0;
|
2006-02-19 22:39:19 +00:00
|
|
|
} else {
|
|
|
|
ifp->if_capenable |= IFCAP_RXCSUM;
|
2006-06-14 16:23:17 +00:00
|
|
|
sc->csum_flag = 1;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-15 15:41:28 +00:00
|
|
|
if (mask & IFCAP_TSO4) {
|
|
|
|
if (IFCAP_TSO4 & ifp->if_capenable) {
|
|
|
|
ifp->if_capenable &= ~IFCAP_TSO4;
|
|
|
|
ifp->if_hwassist &= ~CSUM_TSO;
|
|
|
|
} else if (IFCAP_TXCSUM & ifp->if_capenable) {
|
|
|
|
ifp->if_capenable |= IFCAP_TSO4;
|
|
|
|
ifp->if_hwassist |= CSUM_TSO;
|
|
|
|
} else {
|
|
|
|
printf("mxge requires tx checksum offload"
|
|
|
|
" be enabled to use TSO\n");
|
|
|
|
err = EINVAL;
|
|
|
|
}
|
|
|
|
}
|
2007-06-12 19:15:16 +00:00
|
|
|
if (mask & IFCAP_LRO) {
|
|
|
|
if (IFCAP_LRO & ifp->if_capenable)
|
|
|
|
err = mxge_change_lro_locked(sc, 0);
|
|
|
|
else
|
|
|
|
err = mxge_change_lro_locked(sc, mxge_lro_cnt);
|
|
|
|
}
|
2007-05-23 16:25:40 +00:00
|
|
|
if (mask & IFCAP_VLAN_HWTAGGING)
|
|
|
|
ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
|
2007-01-31 15:29:31 +00:00
|
|
|
mtx_unlock(&sc->driver_mtx);
|
2007-05-23 16:25:40 +00:00
|
|
|
VLAN_CAPABILITIES(ifp);
|
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
err = ifmedia_ioctl(ifp, (struct ifreq *)data,
|
|
|
|
&sc->media, command);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
err = ENOTTY;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_fetch_tunables(mxge_softc_t *sc)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2008-01-15 20:34:49 +00:00
|
|
|
|
|
|
|
TUNABLE_INT_FETCH("hw.mxge.max_slices", &mxge_max_slices);
|
2006-06-13 13:53:52 +00:00
|
|
|
TUNABLE_INT_FETCH("hw.mxge.flow_control_enabled",
|
|
|
|
&mxge_flow_control);
|
|
|
|
TUNABLE_INT_FETCH("hw.mxge.intr_coal_delay",
|
|
|
|
&mxge_intr_coal_delay);
|
|
|
|
TUNABLE_INT_FETCH("hw.mxge.nvidia_ecrc_enable",
|
|
|
|
&mxge_nvidia_ecrc_enable);
|
2006-11-22 16:33:40 +00:00
|
|
|
TUNABLE_INT_FETCH("hw.mxge.force_firmware",
|
|
|
|
&mxge_force_firmware);
|
2006-06-14 16:23:17 +00:00
|
|
|
TUNABLE_INT_FETCH("hw.mxge.deassert_wait",
|
|
|
|
&mxge_deassert_wait);
|
|
|
|
TUNABLE_INT_FETCH("hw.mxge.verbose",
|
|
|
|
&mxge_verbose);
|
2007-01-31 19:53:36 +00:00
|
|
|
TUNABLE_INT_FETCH("hw.mxge.ticks", &mxge_ticks);
|
2007-05-21 18:32:27 +00:00
|
|
|
TUNABLE_INT_FETCH("hw.mxge.lro_cnt", &sc->lro_cnt);
|
2008-01-15 20:34:49 +00:00
|
|
|
TUNABLE_INT_FETCH("hw.mxge.always_promisc", &mxge_always_promisc);
|
|
|
|
TUNABLE_INT_FETCH("hw.mxge.rss_hash_type", &mxge_rss_hash_type);
|
2007-06-12 19:15:16 +00:00
|
|
|
if (sc->lro_cnt != 0)
|
|
|
|
mxge_lro_cnt = sc->lro_cnt;
|
2006-06-13 13:53:52 +00:00
|
|
|
|
2006-06-14 16:23:17 +00:00
|
|
|
if (bootverbose)
|
|
|
|
mxge_verbose = 1;
|
2006-06-13 13:53:52 +00:00
|
|
|
if (mxge_intr_coal_delay < 0 || mxge_intr_coal_delay > 10*1000)
|
|
|
|
mxge_intr_coal_delay = 30;
|
2007-01-31 19:53:36 +00:00
|
|
|
if (mxge_ticks == 0)
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_ticks = hz / 2;
|
2006-06-13 13:53:52 +00:00
|
|
|
sc->pause = mxge_flow_control;
|
2008-01-15 20:34:49 +00:00
|
|
|
if (mxge_rss_hash_type < MXGEFW_RSS_HASH_TYPE_IPV4
|
|
|
|
|| mxge_rss_hash_type > MXGEFW_RSS_HASH_TYPE_SRC_PORT) {
|
|
|
|
mxge_rss_hash_type = MXGEFW_RSS_HASH_TYPE_SRC_PORT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
mxge_free_slices(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
struct mxge_slice_state *ss;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
|
|
if (sc->ss == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < sc->num_slices; i++) {
|
|
|
|
ss = &sc->ss[i];
|
|
|
|
if (ss->fw_stats != NULL) {
|
|
|
|
mxge_dma_free(&ss->fw_stats_dma);
|
|
|
|
ss->fw_stats = NULL;
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
if (ss->tx.br != NULL) {
|
|
|
|
drbr_free(ss->tx.br, M_DEVBUF);
|
|
|
|
ss->tx.br = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2008-01-15 20:34:49 +00:00
|
|
|
mtx_destroy(&ss->tx.mtx);
|
|
|
|
}
|
|
|
|
if (ss->rx_done.entry != NULL) {
|
|
|
|
mxge_dma_free(&ss->rx_done.dma);
|
|
|
|
ss->rx_done.entry = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(sc->ss, M_DEVBUF);
|
|
|
|
sc->ss = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mxge_alloc_slices(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
mxge_cmd_t cmd;
|
|
|
|
struct mxge_slice_state *ss;
|
|
|
|
size_t bytes;
|
|
|
|
int err, i, max_intr_slots;
|
|
|
|
|
|
|
|
err = mxge_send_cmd(sc, MXGEFW_CMD_GET_RX_RING_SIZE, &cmd);
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "Cannot determine rx ring size\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
sc->rx_ring_size = cmd.data0;
|
|
|
|
max_intr_slots = 2 * (sc->rx_ring_size / sizeof (mcp_dma_addr_t));
|
|
|
|
|
|
|
|
bytes = sizeof (*sc->ss) * sc->num_slices;
|
|
|
|
sc->ss = malloc(bytes, M_DEVBUF, M_NOWAIT | M_ZERO);
|
|
|
|
if (sc->ss == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
for (i = 0; i < sc->num_slices; i++) {
|
|
|
|
ss = &sc->ss[i];
|
|
|
|
|
|
|
|
ss->sc = sc;
|
|
|
|
|
|
|
|
/* allocate per-slice rx interrupt queues */
|
|
|
|
|
|
|
|
bytes = max_intr_slots * sizeof (*ss->rx_done.entry);
|
|
|
|
err = mxge_dma_alloc(sc, &ss->rx_done.dma, bytes, 4096);
|
|
|
|
if (err != 0)
|
|
|
|
goto abort;
|
|
|
|
ss->rx_done.entry = ss->rx_done.dma.addr;
|
|
|
|
bzero(ss->rx_done.entry, bytes);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* allocate the per-slice firmware stats; stats
|
|
|
|
* (including tx) are used used only on the first
|
|
|
|
* slice for now
|
|
|
|
*/
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifndef IFNET_BUF_RING
|
2008-01-15 20:34:49 +00:00
|
|
|
if (i > 0)
|
|
|
|
continue;
|
2009-04-27 15:45:54 +00:00
|
|
|
#endif
|
2008-01-15 20:34:49 +00:00
|
|
|
|
|
|
|
bytes = sizeof (*ss->fw_stats);
|
|
|
|
err = mxge_dma_alloc(sc, &ss->fw_stats_dma,
|
|
|
|
sizeof (*ss->fw_stats), 64);
|
|
|
|
if (err != 0)
|
|
|
|
goto abort;
|
|
|
|
ss->fw_stats = (mcp_irq_data_t *)ss->fw_stats_dma.addr;
|
|
|
|
snprintf(ss->tx.mtx_name, sizeof(ss->tx.mtx_name),
|
|
|
|
"%s:tx(%d)", device_get_nameunit(sc->dev), i);
|
|
|
|
mtx_init(&ss->tx.mtx, ss->tx.mtx_name, NULL, MTX_DEF);
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
ss->tx.br = buf_ring_alloc(2048, M_DEVBUF, M_WAITOK,
|
|
|
|
&ss->tx.mtx);
|
|
|
|
#endif
|
2008-01-15 20:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
abort:
|
|
|
|
mxge_free_slices(sc);
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mxge_slice_probe(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
mxge_cmd_t cmd;
|
|
|
|
char *old_fw;
|
|
|
|
int msix_cnt, status, max_intr_slots;
|
|
|
|
|
|
|
|
sc->num_slices = 1;
|
|
|
|
/*
|
|
|
|
* don't enable multiple slices if they are not enabled,
|
|
|
|
* or if this is not an SMP system
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (mxge_max_slices == 0 || mxge_max_slices == 1 || mp_ncpus < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* see how many MSI-X interrupts are available */
|
|
|
|
msix_cnt = pci_msix_count(sc->dev);
|
|
|
|
if (msix_cnt < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* now load the slice aware firmware see what it supports */
|
|
|
|
old_fw = sc->fw_name;
|
|
|
|
if (old_fw == mxge_fw_aligned)
|
|
|
|
sc->fw_name = mxge_fw_rss_aligned;
|
|
|
|
else
|
|
|
|
sc->fw_name = mxge_fw_rss_unaligned;
|
|
|
|
status = mxge_load_firmware(sc, 0);
|
|
|
|
if (status != 0) {
|
|
|
|
device_printf(sc->dev, "Falling back to a single slice\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to send a reset command to the card to see if it
|
|
|
|
is alive */
|
|
|
|
memset(&cmd, 0, sizeof (cmd));
|
|
|
|
status = mxge_send_cmd(sc, MXGEFW_CMD_RESET, &cmd);
|
|
|
|
if (status != 0) {
|
|
|
|
device_printf(sc->dev, "failed reset\n");
|
|
|
|
goto abort_with_fw;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get rx ring size */
|
|
|
|
status = mxge_send_cmd(sc, MXGEFW_CMD_GET_RX_RING_SIZE, &cmd);
|
|
|
|
if (status != 0) {
|
|
|
|
device_printf(sc->dev, "Cannot determine rx ring size\n");
|
|
|
|
goto abort_with_fw;
|
|
|
|
}
|
|
|
|
max_intr_slots = 2 * (cmd.data0 / sizeof (mcp_dma_addr_t));
|
|
|
|
|
|
|
|
/* tell it the size of the interrupt queues */
|
|
|
|
cmd.data0 = max_intr_slots * sizeof (struct mcp_slot);
|
|
|
|
status = mxge_send_cmd(sc, MXGEFW_CMD_SET_INTRQ_SIZE, &cmd);
|
|
|
|
if (status != 0) {
|
|
|
|
device_printf(sc->dev, "failed MXGEFW_CMD_SET_INTRQ_SIZE\n");
|
|
|
|
goto abort_with_fw;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ask the maximum number of slices it supports */
|
|
|
|
status = mxge_send_cmd(sc, MXGEFW_CMD_GET_MAX_RSS_QUEUES, &cmd);
|
|
|
|
if (status != 0) {
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"failed MXGEFW_CMD_GET_MAX_RSS_QUEUES\n");
|
|
|
|
goto abort_with_fw;
|
|
|
|
}
|
|
|
|
sc->num_slices = cmd.data0;
|
|
|
|
if (sc->num_slices > msix_cnt)
|
|
|
|
sc->num_slices = msix_cnt;
|
|
|
|
|
|
|
|
if (mxge_max_slices == -1) {
|
|
|
|
/* cap to number of CPUs in system */
|
|
|
|
if (sc->num_slices > mp_ncpus)
|
|
|
|
sc->num_slices = mp_ncpus;
|
|
|
|
} else {
|
|
|
|
if (sc->num_slices > mxge_max_slices)
|
|
|
|
sc->num_slices = mxge_max_slices;
|
|
|
|
}
|
|
|
|
/* make sure it is a power of two */
|
|
|
|
while (sc->num_slices & (sc->num_slices - 1))
|
|
|
|
sc->num_slices--;
|
|
|
|
|
|
|
|
if (mxge_verbose)
|
|
|
|
device_printf(sc->dev, "using %d slices\n",
|
|
|
|
sc->num_slices);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
abort_with_fw:
|
|
|
|
sc->fw_name = old_fw;
|
|
|
|
(void) mxge_load_firmware(sc, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mxge_add_msix_irqs(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
size_t bytes;
|
|
|
|
int count, err, i, rid;
|
|
|
|
|
|
|
|
rid = PCIR_BAR(2);
|
|
|
|
sc->msix_table_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
|
|
|
|
&rid, RF_ACTIVE);
|
|
|
|
|
|
|
|
if (sc->msix_table_res == NULL) {
|
|
|
|
device_printf(sc->dev, "couldn't alloc MSIX table res\n");
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
count = sc->num_slices;
|
|
|
|
err = pci_alloc_msix(sc->dev, &count);
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "pci_alloc_msix: failed, wanted %d"
|
|
|
|
"err = %d \n", sc->num_slices, err);
|
|
|
|
goto abort_with_msix_table;
|
|
|
|
}
|
|
|
|
if (count < sc->num_slices) {
|
|
|
|
device_printf(sc->dev, "pci_alloc_msix: need %d, got %d\n",
|
|
|
|
count, sc->num_slices);
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"Try setting hw.mxge.max_slices to %d\n",
|
|
|
|
count);
|
|
|
|
err = ENOSPC;
|
|
|
|
goto abort_with_msix;
|
|
|
|
}
|
|
|
|
bytes = sizeof (*sc->msix_irq_res) * sc->num_slices;
|
|
|
|
sc->msix_irq_res = malloc(bytes, M_DEVBUF, M_NOWAIT|M_ZERO);
|
|
|
|
if (sc->msix_irq_res == NULL) {
|
|
|
|
err = ENOMEM;
|
|
|
|
goto abort_with_msix;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < sc->num_slices; i++) {
|
|
|
|
rid = i + 1;
|
|
|
|
sc->msix_irq_res[i] = bus_alloc_resource_any(sc->dev,
|
|
|
|
SYS_RES_IRQ,
|
|
|
|
&rid, RF_ACTIVE);
|
|
|
|
if (sc->msix_irq_res[i] == NULL) {
|
|
|
|
device_printf(sc->dev, "couldn't allocate IRQ res"
|
|
|
|
" for message %d\n", i);
|
|
|
|
err = ENXIO;
|
|
|
|
goto abort_with_res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bytes = sizeof (*sc->msix_ih) * sc->num_slices;
|
|
|
|
sc->msix_ih = malloc(bytes, M_DEVBUF, M_NOWAIT|M_ZERO);
|
|
|
|
|
|
|
|
for (i = 0; i < sc->num_slices; i++) {
|
|
|
|
err = bus_setup_intr(sc->dev, sc->msix_irq_res[i],
|
|
|
|
INTR_TYPE_NET | INTR_MPSAFE,
|
2008-02-14 00:09:59 +00:00
|
|
|
#if __FreeBSD_version > 700030
|
|
|
|
NULL,
|
|
|
|
#endif
|
|
|
|
mxge_intr, &sc->ss[i], &sc->msix_ih[i]);
|
2008-01-15 20:34:49 +00:00
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "couldn't setup intr for "
|
|
|
|
"message %d\n", i);
|
|
|
|
goto abort_with_intr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mxge_verbose) {
|
|
|
|
device_printf(sc->dev, "using %d msix IRQs:",
|
|
|
|
sc->num_slices);
|
|
|
|
for (i = 0; i < sc->num_slices; i++)
|
|
|
|
printf(" %ld", rman_get_start(sc->msix_irq_res[i]));
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
abort_with_intr:
|
|
|
|
for (i = 0; i < sc->num_slices; i++) {
|
|
|
|
if (sc->msix_ih[i] != NULL) {
|
|
|
|
bus_teardown_intr(sc->dev, sc->msix_irq_res[i],
|
|
|
|
sc->msix_ih[i]);
|
|
|
|
sc->msix_ih[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(sc->msix_ih, M_DEVBUF);
|
|
|
|
|
|
|
|
|
|
|
|
abort_with_res:
|
|
|
|
for (i = 0; i < sc->num_slices; i++) {
|
|
|
|
rid = i + 1;
|
|
|
|
if (sc->msix_irq_res[i] != NULL)
|
|
|
|
bus_release_resource(sc->dev, SYS_RES_IRQ, rid,
|
|
|
|
sc->msix_irq_res[i]);
|
|
|
|
sc->msix_irq_res[i] = NULL;
|
|
|
|
}
|
|
|
|
free(sc->msix_irq_res, M_DEVBUF);
|
|
|
|
|
|
|
|
|
|
|
|
abort_with_msix:
|
|
|
|
pci_release_msi(sc->dev);
|
|
|
|
|
|
|
|
abort_with_msix_table:
|
|
|
|
bus_release_resource(sc->dev, SYS_RES_MEMORY, PCIR_BAR(2),
|
|
|
|
sc->msix_table_res);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mxge_add_single_irq(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
int count, err, rid;
|
|
|
|
|
|
|
|
count = pci_msi_count(sc->dev);
|
|
|
|
if (count == 1 && pci_alloc_msi(sc->dev, &count) == 0) {
|
|
|
|
rid = 1;
|
|
|
|
} else {
|
|
|
|
rid = 0;
|
2008-02-14 16:24:14 +00:00
|
|
|
sc->legacy_irq = 1;
|
2008-01-15 20:34:49 +00:00
|
|
|
}
|
|
|
|
sc->irq_res = bus_alloc_resource(sc->dev, SYS_RES_IRQ, &rid, 0, ~0,
|
|
|
|
1, RF_SHAREABLE | RF_ACTIVE);
|
|
|
|
if (sc->irq_res == NULL) {
|
|
|
|
device_printf(sc->dev, "could not alloc interrupt\n");
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
if (mxge_verbose)
|
|
|
|
device_printf(sc->dev, "using %s irq %ld\n",
|
2008-02-14 16:24:14 +00:00
|
|
|
sc->legacy_irq ? "INTx" : "MSI",
|
2008-01-15 20:34:49 +00:00
|
|
|
rman_get_start(sc->irq_res));
|
|
|
|
err = bus_setup_intr(sc->dev, sc->irq_res,
|
|
|
|
INTR_TYPE_NET | INTR_MPSAFE,
|
2008-02-14 00:09:59 +00:00
|
|
|
#if __FreeBSD_version > 700030
|
|
|
|
NULL,
|
|
|
|
#endif
|
|
|
|
mxge_intr, &sc->ss[0], &sc->ih);
|
2008-01-15 20:34:49 +00:00
|
|
|
if (err != 0) {
|
|
|
|
bus_release_resource(sc->dev, SYS_RES_IRQ,
|
2008-02-14 16:24:14 +00:00
|
|
|
sc->legacy_irq ? 0 : 1, sc->irq_res);
|
|
|
|
if (!sc->legacy_irq)
|
2008-01-15 20:34:49 +00:00
|
|
|
pci_release_msi(sc->dev);
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mxge_rem_msix_irqs(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
int i, rid;
|
|
|
|
|
|
|
|
for (i = 0; i < sc->num_slices; i++) {
|
|
|
|
if (sc->msix_ih[i] != NULL) {
|
|
|
|
bus_teardown_intr(sc->dev, sc->msix_irq_res[i],
|
|
|
|
sc->msix_ih[i]);
|
|
|
|
sc->msix_ih[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(sc->msix_ih, M_DEVBUF);
|
|
|
|
|
|
|
|
for (i = 0; i < sc->num_slices; i++) {
|
|
|
|
rid = i + 1;
|
|
|
|
if (sc->msix_irq_res[i] != NULL)
|
|
|
|
bus_release_resource(sc->dev, SYS_RES_IRQ, rid,
|
|
|
|
sc->msix_irq_res[i]);
|
|
|
|
sc->msix_irq_res[i] = NULL;
|
|
|
|
}
|
|
|
|
free(sc->msix_irq_res, M_DEVBUF);
|
|
|
|
|
|
|
|
bus_release_resource(sc->dev, SYS_RES_MEMORY, PCIR_BAR(2),
|
|
|
|
sc->msix_table_res);
|
2007-05-21 18:32:27 +00:00
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
pci_release_msi(sc->dev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mxge_rem_single_irq(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
bus_teardown_intr(sc->dev, sc->irq_res, sc->ih);
|
|
|
|
bus_release_resource(sc->dev, SYS_RES_IRQ,
|
2008-02-14 16:24:14 +00:00
|
|
|
sc->legacy_irq ? 0 : 1, sc->irq_res);
|
|
|
|
if (!sc->legacy_irq)
|
2008-01-15 20:34:49 +00:00
|
|
|
pci_release_msi(sc->dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mxge_rem_irq(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
if (sc->num_slices > 1)
|
|
|
|
mxge_rem_msix_irqs(sc);
|
|
|
|
else
|
|
|
|
mxge_rem_single_irq(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mxge_add_irq(mxge_softc_t *sc)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (sc->num_slices > 1)
|
|
|
|
err = mxge_add_msix_irqs(sc);
|
|
|
|
else
|
|
|
|
err = mxge_add_single_irq(sc);
|
|
|
|
|
|
|
|
if (0 && err == 0 && sc->num_slices > 1) {
|
|
|
|
mxge_rem_msix_irqs(sc);
|
|
|
|
err = mxge_add_msix_irqs(sc);
|
|
|
|
}
|
|
|
|
return err;
|
2006-02-19 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
static int
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_attach(device_t dev)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_softc_t *sc = device_get_softc(dev);
|
2006-02-19 22:39:19 +00:00
|
|
|
struct ifnet *ifp;
|
2008-01-15 20:34:49 +00:00
|
|
|
int err, rid;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
sc->dev = dev;
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_fetch_tunables(sc);
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
err = bus_dma_tag_create(NULL, /* parent */
|
|
|
|
1, /* alignment */
|
2008-01-15 20:34:49 +00:00
|
|
|
0, /* boundary */
|
2006-02-19 22:39:19 +00:00
|
|
|
BUS_SPACE_MAXADDR, /* low */
|
|
|
|
BUS_SPACE_MAXADDR, /* high */
|
|
|
|
NULL, NULL, /* filter */
|
2006-09-15 15:41:28 +00:00
|
|
|
65536 + 256, /* maxsize */
|
2006-06-14 16:23:17 +00:00
|
|
|
MXGE_MAX_SEND_DESC, /* num segs */
|
2008-01-15 20:34:49 +00:00
|
|
|
65536, /* maxsegsize */
|
2006-02-19 22:39:19 +00:00
|
|
|
0, /* flags */
|
|
|
|
NULL, NULL, /* lock */
|
|
|
|
&sc->parent_dmat); /* tag */
|
|
|
|
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "Err %d allocating parent dmat\n",
|
|
|
|
err);
|
|
|
|
goto abort_with_nothing;
|
|
|
|
}
|
|
|
|
|
|
|
|
ifp = sc->ifp = if_alloc(IFT_ETHER);
|
|
|
|
if (ifp == NULL) {
|
|
|
|
device_printf(dev, "can not if_alloc()\n");
|
|
|
|
err = ENOSPC;
|
|
|
|
goto abort_with_parent_dmat;
|
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
if_initname(ifp, device_get_name(dev), device_get_unit(dev));
|
|
|
|
|
2007-01-31 15:29:31 +00:00
|
|
|
snprintf(sc->cmd_mtx_name, sizeof(sc->cmd_mtx_name), "%s:cmd",
|
|
|
|
device_get_nameunit(dev));
|
|
|
|
mtx_init(&sc->cmd_mtx, sc->cmd_mtx_name, NULL, MTX_DEF);
|
|
|
|
snprintf(sc->driver_mtx_name, sizeof(sc->driver_mtx_name),
|
|
|
|
"%s:drv", device_get_nameunit(dev));
|
|
|
|
mtx_init(&sc->driver_mtx, sc->driver_mtx_name,
|
2006-02-19 22:39:19 +00:00
|
|
|
MTX_NETWORK_LOCK, MTX_DEF);
|
|
|
|
|
2007-01-31 19:53:36 +00:00
|
|
|
callout_init_mtx(&sc->co_hdl, &sc->driver_mtx, 0);
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2007-01-31 19:53:36 +00:00
|
|
|
mxge_setup_cfg_space(sc);
|
|
|
|
|
2006-02-19 22:39:19 +00:00
|
|
|
/* Map the board into the kernel */
|
|
|
|
rid = PCIR_BARS;
|
|
|
|
sc->mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0,
|
|
|
|
~0, 1, RF_ACTIVE);
|
|
|
|
if (sc->mem_res == NULL) {
|
|
|
|
device_printf(dev, "could not map memory\n");
|
|
|
|
err = ENXIO;
|
|
|
|
goto abort_with_lock;
|
|
|
|
}
|
|
|
|
sc->sram = rman_get_virtual(sc->mem_res);
|
|
|
|
sc->sram_size = 2*1024*1024 - (2*(48*1024)+(32*1024)) - 0x100;
|
|
|
|
if (sc->sram_size > rman_get_size(sc->mem_res)) {
|
|
|
|
device_printf(dev, "impossible memory region size %ld\n",
|
|
|
|
rman_get_size(sc->mem_res));
|
|
|
|
err = ENXIO;
|
|
|
|
goto abort_with_mem_res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make NULL terminated copy of the EEPROM strings section of
|
|
|
|
lanai SRAM */
|
2006-06-13 13:53:52 +00:00
|
|
|
bzero(sc->eeprom_strings, MXGE_EEPROM_STRINGS_SIZE);
|
2006-02-19 22:39:19 +00:00
|
|
|
bus_space_read_region_1(rman_get_bustag(sc->mem_res),
|
|
|
|
rman_get_bushandle(sc->mem_res),
|
2006-06-13 13:53:52 +00:00
|
|
|
sc->sram_size - MXGE_EEPROM_STRINGS_SIZE,
|
2006-02-19 22:39:19 +00:00
|
|
|
sc->eeprom_strings,
|
2006-06-13 13:53:52 +00:00
|
|
|
MXGE_EEPROM_STRINGS_SIZE - 2);
|
|
|
|
err = mxge_parse_strings(sc);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (err != 0)
|
|
|
|
goto abort_with_mem_res;
|
|
|
|
|
|
|
|
/* Enable write combining for efficient use of PCIe bus */
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_enable_wc(sc);
|
2006-02-19 22:39:19 +00:00
|
|
|
|
|
|
|
/* Allocate the out of band dma memory */
|
2006-06-13 13:53:52 +00:00
|
|
|
err = mxge_dma_alloc(sc, &sc->cmd_dma,
|
|
|
|
sizeof (mxge_cmd_t), 64);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (err != 0)
|
|
|
|
goto abort_with_mem_res;
|
|
|
|
sc->cmd = (mcp_cmd_response_t *) sc->cmd_dma.addr;
|
2006-06-13 13:53:52 +00:00
|
|
|
err = mxge_dma_alloc(sc, &sc->zeropad_dma, 64, 64);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (err != 0)
|
|
|
|
goto abort_with_cmd_dma;
|
|
|
|
|
2007-01-31 15:29:31 +00:00
|
|
|
err = mxge_dma_alloc(sc, &sc->dmabench_dma, 4096, 4096);
|
|
|
|
if (err != 0)
|
2008-01-15 20:34:49 +00:00
|
|
|
goto abort_with_zeropad_dma;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2007-05-08 14:19:43 +00:00
|
|
|
/* select & load the firmware */
|
|
|
|
err = mxge_select_firmware(sc);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (err != 0)
|
2008-01-15 20:34:49 +00:00
|
|
|
goto abort_with_dmabench;
|
2006-06-14 16:23:17 +00:00
|
|
|
sc->intr_coal_delay = mxge_intr_coal_delay;
|
2008-01-15 20:34:49 +00:00
|
|
|
|
|
|
|
mxge_slice_probe(sc);
|
|
|
|
err = mxge_alloc_slices(sc);
|
|
|
|
if (err != 0)
|
|
|
|
goto abort_with_dmabench;
|
|
|
|
|
2007-05-22 15:57:49 +00:00
|
|
|
err = mxge_reset(sc, 0);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (err != 0)
|
2008-01-15 20:34:49 +00:00
|
|
|
goto abort_with_slices;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2007-01-31 15:29:31 +00:00
|
|
|
err = mxge_alloc_rings(sc);
|
|
|
|
if (err != 0) {
|
|
|
|
device_printf(sc->dev, "failed to allocate rings\n");
|
2008-01-15 20:34:49 +00:00
|
|
|
goto abort_with_dmabench;
|
2007-01-31 15:29:31 +00:00
|
|
|
}
|
|
|
|
|
2008-01-15 20:34:49 +00:00
|
|
|
err = mxge_add_irq(sc);
|
2007-01-31 15:29:31 +00:00
|
|
|
if (err != 0) {
|
2008-01-15 20:34:49 +00:00
|
|
|
device_printf(sc->dev, "failed to add irq\n");
|
2007-01-31 15:29:31 +00:00
|
|
|
goto abort_with_rings;
|
|
|
|
}
|
2008-01-15 20:34:49 +00:00
|
|
|
|
2008-04-02 13:59:43 +00:00
|
|
|
ifp->if_baudrate = IF_Gbps(10UL);
|
2007-05-23 16:25:40 +00:00
|
|
|
ifp->if_capabilities = IFCAP_RXCSUM | IFCAP_TXCSUM | IFCAP_TSO4 |
|
2008-02-14 00:09:59 +00:00
|
|
|
IFCAP_VLAN_MTU | IFCAP_LRO;
|
|
|
|
|
|
|
|
#ifdef MXGE_NEW_VLAN_API
|
|
|
|
ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_HWCSUM;
|
|
|
|
#endif
|
2007-05-23 16:25:40 +00:00
|
|
|
|
2007-05-21 18:32:27 +00:00
|
|
|
sc->max_mtu = mxge_max_mtu(sc);
|
|
|
|
if (sc->max_mtu >= 9000)
|
|
|
|
ifp->if_capabilities |= IFCAP_JUMBO_MTU;
|
|
|
|
else
|
|
|
|
device_printf(dev, "MTU limited to %d. Install "
|
2007-05-22 15:57:49 +00:00
|
|
|
"latest firmware for 9000 byte jumbo support\n",
|
2007-05-21 18:32:27 +00:00
|
|
|
sc->max_mtu - ETHER_HDR_LEN);
|
2006-09-15 15:41:28 +00:00
|
|
|
ifp->if_hwassist = CSUM_TCP | CSUM_UDP | CSUM_TSO;
|
2006-02-19 22:39:19 +00:00
|
|
|
ifp->if_capenable = ifp->if_capabilities;
|
2007-06-12 19:15:16 +00:00
|
|
|
if (sc->lro_cnt == 0)
|
|
|
|
ifp->if_capenable &= ~IFCAP_LRO;
|
2006-06-14 16:23:17 +00:00
|
|
|
sc->csum_flag = 1;
|
2006-06-13 13:53:52 +00:00
|
|
|
ifp->if_init = mxge_init;
|
2006-02-19 22:39:19 +00:00
|
|
|
ifp->if_softc = sc;
|
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
2006-06-13 13:53:52 +00:00
|
|
|
ifp->if_ioctl = mxge_ioctl;
|
|
|
|
ifp->if_start = mxge_start;
|
2007-08-22 13:22:12 +00:00
|
|
|
/* Initialise the ifmedia structure */
|
|
|
|
ifmedia_init(&sc->media, 0, mxge_media_change,
|
|
|
|
mxge_media_status);
|
|
|
|
mxge_set_media(sc, IFM_ETHER | IFM_AUTO);
|
|
|
|
mxge_media_probe(sc);
|
2006-02-19 22:39:19 +00:00
|
|
|
ether_ifattach(ifp, sc->mac_addr);
|
|
|
|
/* ether_ifattach sets mtu to 1500 */
|
2007-05-21 18:32:27 +00:00
|
|
|
if (ifp->if_capabilities & IFCAP_JUMBO_MTU)
|
2007-05-23 16:25:40 +00:00
|
|
|
ifp->if_mtu = 9000;
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_add_sysctls(sc);
|
2009-04-27 15:45:54 +00:00
|
|
|
#ifdef IFNET_BUF_RING
|
|
|
|
ifp->if_transmit = mxge_transmit;
|
|
|
|
ifp->if_qflush = mxge_qflush;
|
|
|
|
#endif
|
2006-02-19 22:39:19 +00:00
|
|
|
return 0;
|
|
|
|
|
2007-01-31 15:29:31 +00:00
|
|
|
abort_with_rings:
|
|
|
|
mxge_free_rings(sc);
|
2008-01-15 20:34:49 +00:00
|
|
|
abort_with_slices:
|
|
|
|
mxge_free_slices(sc);
|
2007-01-31 15:29:31 +00:00
|
|
|
abort_with_dmabench:
|
|
|
|
mxge_dma_free(&sc->dmabench_dma);
|
2006-02-19 22:39:19 +00:00
|
|
|
abort_with_zeropad_dma:
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_dma_free(&sc->zeropad_dma);
|
2006-02-19 22:39:19 +00:00
|
|
|
abort_with_cmd_dma:
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_dma_free(&sc->cmd_dma);
|
2006-02-19 22:39:19 +00:00
|
|
|
abort_with_mem_res:
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BARS, sc->mem_res);
|
|
|
|
abort_with_lock:
|
|
|
|
pci_disable_busmaster(dev);
|
2007-01-31 15:29:31 +00:00
|
|
|
mtx_destroy(&sc->cmd_mtx);
|
|
|
|
mtx_destroy(&sc->driver_mtx);
|
2006-02-19 22:39:19 +00:00
|
|
|
if_free(ifp);
|
|
|
|
abort_with_parent_dmat:
|
|
|
|
bus_dma_tag_destroy(sc->parent_dmat);
|
|
|
|
|
|
|
|
abort_with_nothing:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_detach(device_t dev)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_softc_t *sc = device_get_softc(dev);
|
2006-02-19 22:39:19 +00:00
|
|
|
|
2008-02-14 00:09:59 +00:00
|
|
|
if (mxge_vlans_active(sc)) {
|
2007-05-23 16:25:40 +00:00
|
|
|
device_printf(sc->dev,
|
|
|
|
"Detach vlans before removing module\n");
|
|
|
|
return EBUSY;
|
|
|
|
}
|
2007-01-31 15:29:31 +00:00
|
|
|
mtx_lock(&sc->driver_mtx);
|
2006-02-19 22:39:19 +00:00
|
|
|
if (sc->ifp->if_drv_flags & IFF_DRV_RUNNING)
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_close(sc);
|
2007-01-31 15:29:31 +00:00
|
|
|
mtx_unlock(&sc->driver_mtx);
|
2006-02-19 22:39:19 +00:00
|
|
|
ether_ifdetach(sc->ifp);
|
2008-07-17 15:46:35 +00:00
|
|
|
callout_drain(&sc->co_hdl);
|
2007-01-31 19:53:36 +00:00
|
|
|
ifmedia_removeall(&sc->media);
|
2006-08-01 14:02:54 +00:00
|
|
|
mxge_dummy_rdma(sc, 0);
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_rem_sysctls(sc);
|
|
|
|
mxge_rem_irq(sc);
|
2007-01-31 15:29:31 +00:00
|
|
|
mxge_free_rings(sc);
|
2008-01-15 20:34:49 +00:00
|
|
|
mxge_free_slices(sc);
|
2007-01-31 15:29:31 +00:00
|
|
|
mxge_dma_free(&sc->dmabench_dma);
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_dma_free(&sc->zeropad_dma);
|
|
|
|
mxge_dma_free(&sc->cmd_dma);
|
2006-02-19 22:39:19 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BARS, sc->mem_res);
|
|
|
|
pci_disable_busmaster(dev);
|
2007-01-31 15:29:31 +00:00
|
|
|
mtx_destroy(&sc->cmd_mtx);
|
|
|
|
mtx_destroy(&sc->driver_mtx);
|
2006-02-19 22:39:19 +00:00
|
|
|
if_free(sc->ifp);
|
|
|
|
bus_dma_tag_destroy(sc->parent_dmat);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-06-13 13:53:52 +00:00
|
|
|
mxge_shutdown(device_t dev)
|
2006-02-19 22:39:19 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
This file uses Myri10GE driver indentation.
|
|
|
|
|
|
|
|
Local Variables:
|
|
|
|
c-file-style:"linux"
|
|
|
|
tab-width:8
|
|
|
|
End:
|
|
|
|
*/
|