Home | History | Annotate | Line # | Download | only in pci
if_bnx.c revision 1.20.4.2
      1  1.20.4.2  sborrill /*	$NetBSD: if_bnx.c,v 1.20.4.2 2010/01/27 22:03:18 sborrill Exp $	*/
      2  1.20.4.2  sborrill /*      $OpenBSD: if_bnx.c,v 1.85 2009/11/09 14:32:41 dlg Exp $ */
      3       1.1    bouyer 
      4       1.1    bouyer /*-
      5       1.1    bouyer  * Copyright (c) 2006 Broadcom Corporation
      6       1.1    bouyer  *	David Christensen <davidch (at) broadcom.com>.  All rights reserved.
      7       1.1    bouyer  *
      8       1.1    bouyer  * Redistribution and use in source and binary forms, with or without
      9       1.1    bouyer  * modification, are permitted provided that the following conditions
     10       1.1    bouyer  * are met:
     11       1.1    bouyer  *
     12       1.1    bouyer  * 1. Redistributions of source code must retain the above copyright
     13       1.1    bouyer  *    notice, this list of conditions and the following disclaimer.
     14       1.1    bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     15       1.1    bouyer  *    notice, this list of conditions and the following disclaimer in the
     16       1.1    bouyer  *    documentation and/or other materials provided with the distribution.
     17       1.1    bouyer  * 3. Neither the name of Broadcom Corporation nor the name of its contributors
     18       1.1    bouyer  *    may be used to endorse or promote products derived from this software
     19       1.1    bouyer  *    without specific prior written consent.
     20       1.1    bouyer  *
     21       1.1    bouyer  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
     22       1.1    bouyer  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23       1.1    bouyer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24       1.1    bouyer  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
     25       1.1    bouyer  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26       1.1    bouyer  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27       1.1    bouyer  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28       1.1    bouyer  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29       1.1    bouyer  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30       1.1    bouyer  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     31       1.1    bouyer  * THE POSSIBILITY OF SUCH DAMAGE.
     32       1.1    bouyer  */
     33       1.1    bouyer 
     34       1.1    bouyer #include <sys/cdefs.h>
     35       1.1    bouyer #if 0
     36       1.1    bouyer __FBSDID("$FreeBSD: src/sys/dev/bce/if_bce.c,v 1.3 2006/04/13 14:12:26 ru Exp $");
     37       1.1    bouyer #endif
     38  1.20.4.2  sborrill __KERNEL_RCSID(0, "$NetBSD: if_bnx.c,v 1.20.4.2 2010/01/27 22:03:18 sborrill Exp $");
     39       1.1    bouyer 
     40       1.1    bouyer /*
     41       1.1    bouyer  * The following controllers are supported by this driver:
     42       1.1    bouyer  *   BCM5706C A2, A3
     43  1.20.4.2  sborrill  *   BCM5706S A2, A3
     44      1.20    mhitch  *   BCM5708C B1, B2
     45  1.20.4.2  sborrill  *   BCM5708S B1, B2
     46  1.20.4.2  sborrill  *   BCM5709C A1, C0
     47  1.20.4.2  sborrill  *   BCM5716  C0
     48       1.1    bouyer  *
     49       1.1    bouyer  * The following controllers are not supported by this driver:
     50       1.1    bouyer  *
     51       1.1    bouyer  *   BCM5706C A0, A1
     52  1.20.4.2  sborrill  *   BCM5706S A0, A1
     53       1.1    bouyer  *   BCM5708C A0, B0
     54  1.20.4.2  sborrill  *   BCM5708S A0, B0
     55  1.20.4.2  sborrill  *   BCM5709C A0  B0, B1, B2 (pre-production)
     56  1.20.4.2  sborrill  *   BCM5709S A0, A1, B0, B1, B2, C0 (pre-production)
     57       1.1    bouyer  */
     58       1.1    bouyer 
     59       1.1    bouyer #include <sys/callout.h>
     60  1.20.4.2  sborrill #include <sys/mutex.h>
     61       1.1    bouyer 
     62       1.1    bouyer #include <dev/pci/if_bnxreg.h>
     63       1.1    bouyer #include <dev/microcode/bnx/bnxfw.h>
     64       1.1    bouyer 
     65       1.1    bouyer /****************************************************************************/
     66       1.1    bouyer /* BNX Driver Version                                                       */
     67       1.1    bouyer /****************************************************************************/
     68  1.20.4.2  sborrill #define BNX_DRIVER_VERSION	"v0.9.6"
     69       1.1    bouyer 
     70       1.1    bouyer /****************************************************************************/
     71       1.1    bouyer /* BNX Debug Options                                                        */
     72       1.1    bouyer /****************************************************************************/
     73       1.1    bouyer #ifdef BNX_DEBUG
     74       1.1    bouyer 	u_int32_t bnx_debug = /*BNX_WARN*/ BNX_VERBOSE_SEND;
     75       1.1    bouyer 
     76       1.1    bouyer 	/*          0 = Never              */
     77       1.1    bouyer 	/*          1 = 1 in 2,147,483,648 */
     78       1.1    bouyer 	/*        256 = 1 in     8,388,608 */
     79       1.1    bouyer 	/*       2048 = 1 in     1,048,576 */
     80       1.1    bouyer 	/*      65536 = 1 in        32,768 */
     81       1.1    bouyer 	/*    1048576 = 1 in         2,048 */
     82       1.1    bouyer 	/*  268435456 =	1 in             8 */
     83       1.1    bouyer 	/*  536870912 = 1 in             4 */
     84       1.1    bouyer 	/* 1073741824 = 1 in             2 */
     85       1.1    bouyer 
     86       1.1    bouyer 	/* Controls how often the l2_fhdr frame error check will fail. */
     87       1.1    bouyer 	int bnx_debug_l2fhdr_status_check = 0;
     88       1.1    bouyer 
     89       1.1    bouyer 	/* Controls how often the unexpected attention check will fail. */
     90       1.1    bouyer 	int bnx_debug_unexpected_attention = 0;
     91       1.1    bouyer 
     92       1.1    bouyer 	/* Controls how often to simulate an mbuf allocation failure. */
     93       1.1    bouyer 	int bnx_debug_mbuf_allocation_failure = 0;
     94       1.1    bouyer 
     95       1.1    bouyer 	/* Controls how often to simulate a DMA mapping failure. */
     96       1.1    bouyer 	int bnx_debug_dma_map_addr_failure = 0;
     97       1.1    bouyer 
     98       1.1    bouyer 	/* Controls how often to simulate a bootcode failure. */
     99       1.1    bouyer 	int bnx_debug_bootcode_running_failure = 0;
    100       1.1    bouyer #endif
    101       1.1    bouyer 
    102       1.1    bouyer /****************************************************************************/
    103       1.1    bouyer /* PCI Device ID Table                                                      */
    104       1.1    bouyer /*                                                                          */
    105       1.1    bouyer /* Used by bnx_probe() to identify the devices supported by this driver.    */
    106       1.1    bouyer /****************************************************************************/
    107       1.1    bouyer static const struct bnx_product {
    108       1.1    bouyer 	pci_vendor_id_t		bp_vendor;
    109       1.1    bouyer 	pci_product_id_t	bp_product;
    110       1.1    bouyer 	pci_vendor_id_t		bp_subvendor;
    111       1.1    bouyer 	pci_product_id_t	bp_subproduct;
    112       1.1    bouyer 	const char		*bp_name;
    113       1.1    bouyer } bnx_devices[] = {
    114       1.1    bouyer #ifdef PCI_SUBPRODUCT_HP_NC370T
    115       1.1    bouyer 	{
    116       1.1    bouyer 	  PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5706,
    117       1.1    bouyer 	  PCI_VENDOR_HP, PCI_SUBPRODUCT_HP_NC370T,
    118       1.1    bouyer 	  "HP NC370T Multifunction Gigabit Server Adapter"
    119       1.1    bouyer 	},
    120       1.1    bouyer #endif
    121       1.1    bouyer #ifdef PCI_SUBPRODUCT_HP_NC370i
    122       1.1    bouyer 	{
    123       1.1    bouyer 	  PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5706,
    124       1.1    bouyer 	  PCI_VENDOR_HP, PCI_SUBPRODUCT_HP_NC370i,
    125       1.1    bouyer 	  "HP NC370i Multifunction Gigabit Server Adapter"
    126       1.1    bouyer 	},
    127       1.1    bouyer #endif
    128       1.1    bouyer 	{
    129       1.1    bouyer 	  PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5706,
    130       1.1    bouyer 	  0, 0,
    131       1.1    bouyer 	  "Broadcom NetXtreme II BCM5706 1000Base-T"
    132       1.1    bouyer 	},
    133       1.1    bouyer #ifdef PCI_SUBPRODUCT_HP_NC370F
    134       1.1    bouyer 	{
    135       1.1    bouyer 	  PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5706S,
    136       1.1    bouyer 	  PCI_VENDOR_HP, PCI_SUBPRODUCT_HP_NC370F,
    137       1.1    bouyer 	  "HP NC370F Multifunction Gigabit Server Adapter"
    138       1.1    bouyer 	},
    139       1.1    bouyer #endif
    140       1.1    bouyer 	{
    141       1.1    bouyer 	  PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5706S,
    142       1.1    bouyer 	  0, 0,
    143       1.1    bouyer 	  "Broadcom NetXtreme II BCM5706 1000Base-SX"
    144       1.1    bouyer 	},
    145       1.1    bouyer 	{
    146       1.1    bouyer 	  PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5708,
    147       1.1    bouyer 	  0, 0,
    148       1.1    bouyer 	  "Broadcom NetXtreme II BCM5708 1000Base-T"
    149       1.1    bouyer 	},
    150       1.1    bouyer 	{
    151       1.1    bouyer 	  PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5708S,
    152       1.1    bouyer 	  0, 0,
    153       1.1    bouyer 	  "Broadcom NetXtreme II BCM5708 1000Base-SX"
    154       1.1    bouyer 	},
    155  1.20.4.2  sborrill 	{
    156  1.20.4.2  sborrill 	  PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5709,
    157  1.20.4.2  sborrill 	  0, 0,
    158  1.20.4.2  sborrill 	  "Broadcom NetXtreme II BCM5709 1000Base-T"
    159  1.20.4.2  sborrill 	},
    160  1.20.4.2  sborrill 	{
    161  1.20.4.2  sborrill 	  PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5709S,
    162  1.20.4.2  sborrill 	  0, 0,
    163  1.20.4.2  sborrill 	  "Broadcom NetXtreme II BCM5709 1000Base-SX"
    164  1.20.4.2  sborrill 	},
    165  1.20.4.2  sborrill 	{
    166  1.20.4.2  sborrill 	  PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5716,
    167  1.20.4.2  sborrill 	  0, 0,
    168  1.20.4.2  sborrill 	  "Broadcom NetXtreme II BCM5716 1000Base-T"
    169  1.20.4.2  sborrill 	},
    170  1.20.4.2  sborrill 	{
    171  1.20.4.2  sborrill 	  PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5716S,
    172  1.20.4.2  sborrill 	  0, 0,
    173  1.20.4.2  sborrill 	  "Broadcom NetXtreme II BCM5716 1000Base-SX"
    174  1.20.4.2  sborrill 	},
    175       1.1    bouyer };
    176       1.1    bouyer 
    177       1.1    bouyer /****************************************************************************/
    178       1.1    bouyer /* Supported Flash NVRAM device data.                                       */
    179       1.1    bouyer /****************************************************************************/
    180       1.1    bouyer static struct flash_spec flash_table[] =
    181       1.1    bouyer {
    182  1.20.4.2  sborrill #define BUFFERED_FLAGS		(BNX_NV_BUFFERED | BNX_NV_TRANSLATE)
    183  1.20.4.2  sborrill #define NONBUFFERED_FLAGS	(BNX_NV_WREN)
    184       1.1    bouyer 	/* Slow EEPROM */
    185       1.1    bouyer 	{0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
    186  1.20.4.2  sborrill 	 BUFFERED_FLAGS, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
    187       1.1    bouyer 	 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
    188       1.1    bouyer 	 "EEPROM - slow"},
    189       1.1    bouyer 	/* Expansion entry 0001 */
    190       1.1    bouyer 	{0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
    191  1.20.4.2  sborrill 	 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
    192       1.1    bouyer 	 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
    193       1.1    bouyer 	 "Entry 0001"},
    194       1.1    bouyer 	/* Saifun SA25F010 (non-buffered flash) */
    195       1.1    bouyer 	/* strap, cfg1, & write1 need updates */
    196       1.1    bouyer 	{0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
    197  1.20.4.2  sborrill 	 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
    198       1.1    bouyer 	 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
    199       1.1    bouyer 	 "Non-buffered flash (128kB)"},
    200       1.1    bouyer 	/* Saifun SA25F020 (non-buffered flash) */
    201       1.1    bouyer 	/* strap, cfg1, & write1 need updates */
    202       1.1    bouyer 	{0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
    203  1.20.4.2  sborrill 	 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
    204       1.1    bouyer 	 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
    205       1.1    bouyer 	 "Non-buffered flash (256kB)"},
    206       1.1    bouyer 	/* Expansion entry 0100 */
    207       1.1    bouyer 	{0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
    208  1.20.4.2  sborrill 	 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
    209       1.1    bouyer 	 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
    210       1.1    bouyer 	 "Entry 0100"},
    211       1.1    bouyer 	/* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
    212       1.1    bouyer 	{0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
    213  1.20.4.2  sborrill 	 NONBUFFERED_FLAGS, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
    214       1.1    bouyer 	 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*2,
    215       1.1    bouyer 	 "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
    216       1.1    bouyer 	/* Entry 0110: ST M45PE20 (non-buffered flash)*/
    217       1.1    bouyer 	{0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
    218  1.20.4.2  sborrill 	 NONBUFFERED_FLAGS, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
    219       1.1    bouyer 	 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*4,
    220       1.1    bouyer 	 "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
    221       1.1    bouyer 	/* Saifun SA25F005 (non-buffered flash) */
    222       1.1    bouyer 	/* strap, cfg1, & write1 need updates */
    223       1.1    bouyer 	{0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
    224  1.20.4.2  sborrill 	 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
    225       1.1    bouyer 	 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
    226       1.1    bouyer 	 "Non-buffered flash (64kB)"},
    227       1.1    bouyer 	/* Fast EEPROM */
    228       1.1    bouyer 	{0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
    229  1.20.4.2  sborrill 	 BUFFERED_FLAGS, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
    230       1.1    bouyer 	 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
    231       1.1    bouyer 	 "EEPROM - fast"},
    232       1.1    bouyer 	/* Expansion entry 1001 */
    233       1.1    bouyer 	{0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
    234  1.20.4.2  sborrill 	 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
    235       1.1    bouyer 	 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
    236       1.1    bouyer 	 "Entry 1001"},
    237       1.1    bouyer 	/* Expansion entry 1010 */
    238       1.1    bouyer 	{0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
    239  1.20.4.2  sborrill 	 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
    240       1.1    bouyer 	 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
    241       1.1    bouyer 	 "Entry 1010"},
    242       1.1    bouyer 	/* ATMEL AT45DB011B (buffered flash) */
    243       1.1    bouyer 	{0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
    244  1.20.4.2  sborrill 	 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
    245       1.1    bouyer 	 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
    246       1.1    bouyer 	 "Buffered flash (128kB)"},
    247       1.1    bouyer 	/* Expansion entry 1100 */
    248       1.1    bouyer 	{0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
    249  1.20.4.2  sborrill 	 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
    250       1.1    bouyer 	 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
    251       1.1    bouyer 	 "Entry 1100"},
    252       1.1    bouyer 	/* Expansion entry 1101 */
    253       1.1    bouyer 	{0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
    254  1.20.4.2  sborrill 	 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
    255       1.1    bouyer 	 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
    256       1.1    bouyer 	 "Entry 1101"},
    257       1.1    bouyer 	/* Ateml Expansion entry 1110 */
    258       1.1    bouyer 	{0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
    259  1.20.4.2  sborrill 	 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
    260       1.1    bouyer 	 BUFFERED_FLASH_BYTE_ADDR_MASK, 0,
    261       1.1    bouyer 	 "Entry 1110 (Atmel)"},
    262       1.1    bouyer 	/* ATMEL AT45DB021B (buffered flash) */
    263       1.1    bouyer 	{0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
    264  1.20.4.2  sborrill 	 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
    265       1.1    bouyer 	 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE*2,
    266       1.1    bouyer 	 "Buffered flash (256kB)"},
    267       1.1    bouyer };
    268       1.1    bouyer 
    269  1.20.4.2  sborrill /*
    270  1.20.4.2  sborrill  * The BCM5709 controllers transparently handle the
    271  1.20.4.2  sborrill  * differences between Atmel 264 byte pages and all
    272  1.20.4.2  sborrill  * flash devices which use 256 byte pages, so no
    273  1.20.4.2  sborrill  * logical-to-physical mapping is required in the
    274  1.20.4.2  sborrill  * driver.
    275  1.20.4.2  sborrill  */
    276  1.20.4.2  sborrill static struct flash_spec flash_5709 = {
    277  1.20.4.2  sborrill 	.flags		= BNX_NV_BUFFERED,
    278  1.20.4.2  sborrill 	.page_bits	= BCM5709_FLASH_PAGE_BITS,
    279  1.20.4.2  sborrill 	.page_size	= BCM5709_FLASH_PAGE_SIZE,
    280  1.20.4.2  sborrill 	.addr_mask	= BCM5709_FLASH_BYTE_ADDR_MASK,
    281  1.20.4.2  sborrill 	.total_size	= BUFFERED_FLASH_TOTAL_SIZE * 2,
    282  1.20.4.2  sborrill 	.name		= "5709 buffered flash (256kB)",
    283  1.20.4.2  sborrill };
    284  1.20.4.2  sborrill 
    285       1.1    bouyer /****************************************************************************/
    286       1.1    bouyer /* OpenBSD device entry points.                                             */
    287       1.1    bouyer /****************************************************************************/
    288       1.1    bouyer static int	bnx_probe(device_t, cfdata_t, void *);
    289      1.13    dyoung void	bnx_attach(device_t, device_t, void *);
    290      1.13    dyoung int	bnx_detach(device_t, int);
    291       1.1    bouyer 
    292       1.1    bouyer /****************************************************************************/
    293       1.1    bouyer /* BNX Debug Data Structure Dump Routines                                   */
    294       1.1    bouyer /****************************************************************************/
    295       1.1    bouyer #ifdef BNX_DEBUG
    296       1.1    bouyer void	bnx_dump_mbuf(struct bnx_softc *, struct mbuf *);
    297       1.1    bouyer void	bnx_dump_tx_mbuf_chain(struct bnx_softc *, int, int);
    298       1.1    bouyer void	bnx_dump_rx_mbuf_chain(struct bnx_softc *, int, int);
    299       1.1    bouyer void	bnx_dump_txbd(struct bnx_softc *, int, struct tx_bd *);
    300       1.1    bouyer void	bnx_dump_rxbd(struct bnx_softc *, int, struct rx_bd *);
    301       1.1    bouyer void	bnx_dump_l2fhdr(struct bnx_softc *, int, struct l2_fhdr *);
    302       1.1    bouyer void	bnx_dump_tx_chain(struct bnx_softc *, int, int);
    303       1.1    bouyer void	bnx_dump_rx_chain(struct bnx_softc *, int, int);
    304       1.1    bouyer void	bnx_dump_status_block(struct bnx_softc *);
    305       1.1    bouyer void	bnx_dump_stats_block(struct bnx_softc *);
    306       1.1    bouyer void	bnx_dump_driver_state(struct bnx_softc *);
    307       1.1    bouyer void	bnx_dump_hw_state(struct bnx_softc *);
    308       1.1    bouyer void	bnx_breakpoint(struct bnx_softc *);
    309       1.1    bouyer #endif
    310       1.1    bouyer 
    311       1.1    bouyer /****************************************************************************/
    312       1.1    bouyer /* BNX Register/Memory Access Routines                                      */
    313       1.1    bouyer /****************************************************************************/
    314       1.1    bouyer u_int32_t	bnx_reg_rd_ind(struct bnx_softc *, u_int32_t);
    315       1.1    bouyer void	bnx_reg_wr_ind(struct bnx_softc *, u_int32_t, u_int32_t);
    316       1.1    bouyer void	bnx_ctx_wr(struct bnx_softc *, u_int32_t, u_int32_t, u_int32_t);
    317      1.13    dyoung int	bnx_miibus_read_reg(device_t, int, int);
    318      1.13    dyoung void	bnx_miibus_write_reg(device_t, int, int, int);
    319      1.13    dyoung void	bnx_miibus_statchg(device_t);
    320       1.1    bouyer 
    321       1.1    bouyer /****************************************************************************/
    322       1.1    bouyer /* BNX NVRAM Access Routines                                                */
    323       1.1    bouyer /****************************************************************************/
    324       1.1    bouyer int	bnx_acquire_nvram_lock(struct bnx_softc *);
    325       1.1    bouyer int	bnx_release_nvram_lock(struct bnx_softc *);
    326       1.1    bouyer void	bnx_enable_nvram_access(struct bnx_softc *);
    327       1.1    bouyer void	bnx_disable_nvram_access(struct bnx_softc *);
    328       1.1    bouyer int	bnx_nvram_read_dword(struct bnx_softc *, u_int32_t, u_int8_t *,
    329       1.1    bouyer 	    u_int32_t);
    330       1.1    bouyer int	bnx_init_nvram(struct bnx_softc *);
    331       1.1    bouyer int	bnx_nvram_read(struct bnx_softc *, u_int32_t, u_int8_t *, int);
    332       1.1    bouyer int	bnx_nvram_test(struct bnx_softc *);
    333       1.1    bouyer #ifdef BNX_NVRAM_WRITE_SUPPORT
    334       1.1    bouyer int	bnx_enable_nvram_write(struct bnx_softc *);
    335       1.1    bouyer void	bnx_disable_nvram_write(struct bnx_softc *);
    336       1.1    bouyer int	bnx_nvram_erase_page(struct bnx_softc *, u_int32_t);
    337       1.1    bouyer int	bnx_nvram_write_dword(struct bnx_softc *, u_int32_t, u_int8_t *,
    338       1.1    bouyer 	    u_int32_t);
    339       1.1    bouyer int	bnx_nvram_write(struct bnx_softc *, u_int32_t, u_int8_t *, int);
    340       1.1    bouyer #endif
    341       1.1    bouyer 
    342       1.1    bouyer /****************************************************************************/
    343       1.1    bouyer /*                                                                          */
    344       1.1    bouyer /****************************************************************************/
    345  1.20.4.2  sborrill void	bnx_get_media(struct bnx_softc *);
    346       1.1    bouyer int	bnx_dma_alloc(struct bnx_softc *);
    347       1.1    bouyer void	bnx_dma_free(struct bnx_softc *);
    348       1.1    bouyer void	bnx_release_resources(struct bnx_softc *);
    349       1.1    bouyer 
    350       1.1    bouyer /****************************************************************************/
    351       1.1    bouyer /* BNX Firmware Synchronization and Load                                    */
    352       1.1    bouyer /****************************************************************************/
    353       1.1    bouyer int	bnx_fw_sync(struct bnx_softc *, u_int32_t);
    354       1.1    bouyer void	bnx_load_rv2p_fw(struct bnx_softc *, u_int32_t *, u_int32_t,
    355       1.1    bouyer 	    u_int32_t);
    356       1.1    bouyer void	bnx_load_cpu_fw(struct bnx_softc *, struct cpu_reg *,
    357       1.1    bouyer 	    struct fw_info *);
    358       1.1    bouyer void	bnx_init_cpus(struct bnx_softc *);
    359       1.1    bouyer 
    360      1.14    dyoung void	bnx_stop(struct ifnet *, int);
    361       1.1    bouyer int	bnx_reset(struct bnx_softc *, u_int32_t);
    362       1.1    bouyer int	bnx_chipinit(struct bnx_softc *);
    363       1.1    bouyer int	bnx_blockinit(struct bnx_softc *);
    364  1.20.4.1    bouyer static int	bnx_add_buf(struct bnx_softc *, struct mbuf *, u_int16_t *,
    365       1.1    bouyer 	    u_int16_t *, u_int32_t *);
    366  1.20.4.1    bouyer int	bnx_get_buf(struct bnx_softc *, u_int16_t *, u_int16_t *, u_int32_t *);
    367       1.1    bouyer 
    368       1.1    bouyer int	bnx_init_tx_chain(struct bnx_softc *);
    369  1.20.4.2  sborrill void	bnx_init_tx_context(struct bnx_softc *);
    370       1.1    bouyer int	bnx_init_rx_chain(struct bnx_softc *);
    371  1.20.4.2  sborrill void	bnx_init_rx_context(struct bnx_softc *);
    372       1.1    bouyer void	bnx_free_rx_chain(struct bnx_softc *);
    373       1.1    bouyer void	bnx_free_tx_chain(struct bnx_softc *);
    374       1.1    bouyer 
    375  1.20.4.2  sborrill int	bnx_tx_encap(struct bnx_softc *, struct mbuf *);
    376       1.1    bouyer void	bnx_start(struct ifnet *);
    377       1.3  christos int	bnx_ioctl(struct ifnet *, u_long, void *);
    378       1.1    bouyer void	bnx_watchdog(struct ifnet *);
    379       1.1    bouyer int	bnx_init(struct ifnet *);
    380       1.1    bouyer 
    381       1.1    bouyer void	bnx_init_context(struct bnx_softc *);
    382       1.1    bouyer void	bnx_get_mac_addr(struct bnx_softc *);
    383       1.1    bouyer void	bnx_set_mac_addr(struct bnx_softc *);
    384       1.1    bouyer void	bnx_phy_intr(struct bnx_softc *);
    385       1.1    bouyer void	bnx_rx_intr(struct bnx_softc *);
    386       1.1    bouyer void	bnx_tx_intr(struct bnx_softc *);
    387       1.1    bouyer void	bnx_disable_intr(struct bnx_softc *);
    388       1.1    bouyer void	bnx_enable_intr(struct bnx_softc *);
    389       1.1    bouyer 
    390       1.1    bouyer int	bnx_intr(void *);
    391  1.20.4.2  sborrill void	bnx_iff(struct bnx_softc *);
    392       1.1    bouyer void	bnx_stats_update(struct bnx_softc *);
    393       1.1    bouyer void	bnx_tick(void *);
    394       1.1    bouyer 
    395  1.20.4.2  sborrill struct pool *bnx_tx_pool = NULL;
    396  1.20.4.2  sborrill int	bnx_alloc_pkts(struct bnx_softc *);
    397  1.20.4.2  sborrill 
    398       1.1    bouyer /****************************************************************************/
    399       1.1    bouyer /* OpenBSD device dispatch table.                                           */
    400       1.1    bouyer /****************************************************************************/
    401      1.13    dyoung CFATTACH_DECL_NEW(bnx, sizeof(struct bnx_softc),
    402      1.13    dyoung     bnx_probe, bnx_attach, bnx_detach, NULL);
    403       1.1    bouyer 
    404       1.1    bouyer /****************************************************************************/
    405       1.1    bouyer /* Device probe function.                                                   */
    406       1.1    bouyer /*                                                                          */
    407       1.1    bouyer /* Compares the device to the driver's list of supported devices and        */
    408       1.1    bouyer /* reports back to the OS whether this is the right driver for the device.  */
    409       1.1    bouyer /*                                                                          */
    410       1.1    bouyer /* Returns:                                                                 */
    411       1.1    bouyer /*   BUS_PROBE_DEFAULT on success, positive value on failure.               */
    412       1.1    bouyer /****************************************************************************/
    413       1.1    bouyer static const struct bnx_product *
    414       1.1    bouyer bnx_lookup(const struct pci_attach_args *pa)
    415       1.1    bouyer {
    416       1.1    bouyer 	int i;
    417       1.1    bouyer 	pcireg_t subid;
    418       1.1    bouyer 
    419      1.13    dyoung 	for (i = 0; i < __arraycount(bnx_devices); i++) {
    420       1.1    bouyer 		if (PCI_VENDOR(pa->pa_id) != bnx_devices[i].bp_vendor ||
    421       1.1    bouyer 		    PCI_PRODUCT(pa->pa_id) != bnx_devices[i].bp_product)
    422       1.1    bouyer 			continue;
    423       1.1    bouyer 		if (!bnx_devices[i].bp_subvendor)
    424       1.1    bouyer 			return &bnx_devices[i];
    425       1.1    bouyer 		subid = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
    426       1.1    bouyer 		if (PCI_VENDOR(subid) == bnx_devices[i].bp_subvendor &&
    427       1.1    bouyer 		    PCI_PRODUCT(subid) == bnx_devices[i].bp_subproduct)
    428       1.1    bouyer 			return &bnx_devices[i];
    429       1.1    bouyer 	}
    430       1.1    bouyer 
    431       1.1    bouyer 	return NULL;
    432       1.1    bouyer }
    433       1.1    bouyer static int
    434       1.1    bouyer bnx_probe(device_t parent, cfdata_t match, void *aux)
    435       1.1    bouyer {
    436       1.1    bouyer 	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
    437       1.1    bouyer 
    438       1.1    bouyer 	if (bnx_lookup(pa) != NULL)
    439       1.1    bouyer 		return (1);
    440       1.1    bouyer 
    441       1.1    bouyer 	return (0);
    442       1.1    bouyer }
    443       1.1    bouyer 
    444       1.1    bouyer /****************************************************************************/
    445       1.1    bouyer /* Device attach function.                                                  */
    446       1.1    bouyer /*                                                                          */
    447       1.1    bouyer /* Allocates device resources, performs secondary chip identification,      */
    448       1.1    bouyer /* resets and initializes the hardware, and initializes driver instance     */
    449       1.1    bouyer /* variables.                                                               */
    450       1.1    bouyer /*                                                                          */
    451       1.1    bouyer /* Returns:                                                                 */
    452       1.1    bouyer /*   0 on success, positive value on failure.                               */
    453       1.1    bouyer /****************************************************************************/
    454       1.1    bouyer void
    455      1.13    dyoung bnx_attach(device_t parent, device_t self, void *aux)
    456       1.1    bouyer {
    457       1.1    bouyer 	const struct bnx_product *bp;
    458      1.13    dyoung 	struct bnx_softc	*sc = device_private(self);
    459       1.1    bouyer 	struct pci_attach_args	*pa = aux;
    460       1.1    bouyer 	pci_chipset_tag_t	pc = pa->pa_pc;
    461       1.1    bouyer 	pci_intr_handle_t	ih;
    462       1.1    bouyer 	const char 		*intrstr = NULL;
    463       1.1    bouyer 	u_int32_t		command;
    464       1.1    bouyer 	struct ifnet		*ifp;
    465       1.1    bouyer 	u_int32_t		val;
    466      1.20    mhitch 	int			mii_flags = MIIF_FORCEANEG;
    467       1.1    bouyer 	pcireg_t		memtype;
    468       1.1    bouyer 
    469  1.20.4.2  sborrill 	if (bnx_tx_pool == NULL) {
    470  1.20.4.2  sborrill 		bnx_tx_pool = malloc(sizeof(*bnx_tx_pool), M_DEVBUF, M_NOWAIT);
    471  1.20.4.2  sborrill 		if (bnx_tx_pool != NULL) {
    472  1.20.4.2  sborrill 			pool_init(bnx_tx_pool, sizeof(struct bnx_pkt),
    473  1.20.4.2  sborrill 			    0, 0, 0, "bnxpkts", NULL, IPL_NET);
    474  1.20.4.2  sborrill 		} else {
    475  1.20.4.2  sborrill 			aprint_error(": can't alloc bnx_tx_pool\n");
    476  1.20.4.2  sborrill 			return;
    477  1.20.4.2  sborrill 		}
    478  1.20.4.2  sborrill 	}
    479  1.20.4.2  sborrill 
    480       1.1    bouyer 	bp = bnx_lookup(pa);
    481       1.1    bouyer 	if (bp == NULL)
    482       1.1    bouyer 		panic("unknown device");
    483       1.1    bouyer 
    484      1.13    dyoung 	sc->bnx_dev = self;
    485      1.13    dyoung 
    486       1.1    bouyer 	aprint_naive("\n");
    487      1.10    martti 	aprint_normal(": %s\n", bp->bp_name);
    488       1.1    bouyer 
    489       1.1    bouyer 	sc->bnx_pa = *pa;
    490       1.1    bouyer 
    491       1.1    bouyer 	/*
    492       1.1    bouyer 	 * Map control/status registers.
    493       1.1    bouyer 	*/
    494       1.1    bouyer 	command = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    495       1.1    bouyer 	command |= PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE;
    496       1.1    bouyer 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command);
    497       1.1    bouyer 	command = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    498       1.1    bouyer 
    499       1.1    bouyer 	if (!(command & PCI_COMMAND_MEM_ENABLE)) {
    500      1.13    dyoung 		aprint_error_dev(sc->bnx_dev,
    501      1.13    dyoung 		    "failed to enable memory mapping!\n");
    502       1.1    bouyer 		return;
    503       1.1    bouyer 	}
    504       1.1    bouyer 
    505       1.1    bouyer 	memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, BNX_PCI_BAR0);
    506  1.20.4.2  sborrill 	if (pci_mapreg_map(pa, BNX_PCI_BAR0, memtype, 0, &sc->bnx_btag,
    507  1.20.4.2  sborrill 	    &sc->bnx_bhandle, NULL, &sc->bnx_size)) {
    508      1.13    dyoung 		aprint_error_dev(sc->bnx_dev, "can't find mem space\n");
    509       1.1    bouyer 		return;
    510       1.1    bouyer 	}
    511       1.1    bouyer 
    512       1.1    bouyer 	if (pci_intr_map(pa, &ih)) {
    513      1.13    dyoung 		aprint_error_dev(sc->bnx_dev, "couldn't map interrupt\n");
    514       1.1    bouyer 		goto bnx_attach_fail;
    515       1.1    bouyer 	}
    516       1.1    bouyer 
    517       1.1    bouyer 	intrstr = pci_intr_string(pc, ih);
    518       1.1    bouyer 
    519       1.1    bouyer 	/*
    520       1.1    bouyer 	 * Configure byte swap and enable indirect register access.
    521       1.1    bouyer 	 * Rely on CPU to do target byte swapping on big endian systems.
    522       1.1    bouyer 	 * Access to registers outside of PCI configurtion space are not
    523       1.1    bouyer 	 * valid until this is done.
    524       1.1    bouyer 	 */
    525       1.1    bouyer 	pci_conf_write(pa->pa_pc, pa->pa_tag, BNX_PCICFG_MISC_CONFIG,
    526       1.1    bouyer 	    BNX_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
    527       1.1    bouyer 	    BNX_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP);
    528       1.1    bouyer 
    529       1.1    bouyer 	/* Save ASIC revsion info. */
    530       1.1    bouyer 	sc->bnx_chipid =  REG_RD(sc, BNX_MISC_ID);
    531       1.1    bouyer 
    532       1.1    bouyer 	/*
    533       1.1    bouyer 	 * Find the base address for shared memory access.
    534       1.1    bouyer 	 * Newer versions of bootcode use a signature and offset
    535       1.1    bouyer 	 * while older versions use a fixed address.
    536       1.1    bouyer 	 */
    537       1.1    bouyer 	val = REG_RD_IND(sc, BNX_SHM_HDR_SIGNATURE);
    538       1.1    bouyer 	if ((val & BNX_SHM_HDR_SIGNATURE_SIG_MASK) == BNX_SHM_HDR_SIGNATURE_SIG)
    539  1.20.4.2  sborrill 		sc->bnx_shmem_base = REG_RD_IND(sc, BNX_SHM_HDR_ADDR_0 +
    540  1.20.4.2  sborrill 		    (sc->bnx_pa.pa_function << 2));
    541       1.1    bouyer 	else
    542       1.1    bouyer 		sc->bnx_shmem_base = HOST_VIEW_SHMEM_BASE;
    543       1.1    bouyer 
    544       1.1    bouyer 	DBPRINT(sc, BNX_INFO, "bnx_shmem_base = 0x%08X\n", sc->bnx_shmem_base);
    545       1.1    bouyer 
    546       1.1    bouyer 	/* Set initial device and PHY flags */
    547       1.1    bouyer 	sc->bnx_flags = 0;
    548       1.1    bouyer 	sc->bnx_phy_flags = 0;
    549       1.1    bouyer 
    550       1.1    bouyer 	/* Get PCI bus information (speed and type). */
    551       1.1    bouyer 	val = REG_RD(sc, BNX_PCICFG_MISC_STATUS);
    552       1.1    bouyer 	if (val & BNX_PCICFG_MISC_STATUS_PCIX_DET) {
    553       1.1    bouyer 		u_int32_t clkreg;
    554       1.1    bouyer 
    555       1.1    bouyer 		sc->bnx_flags |= BNX_PCIX_FLAG;
    556       1.1    bouyer 
    557       1.1    bouyer 		clkreg = REG_RD(sc, BNX_PCICFG_PCI_CLOCK_CONTROL_BITS);
    558       1.1    bouyer 
    559       1.1    bouyer 		clkreg &= BNX_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
    560       1.1    bouyer 		switch (clkreg) {
    561       1.1    bouyer 		case BNX_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
    562       1.1    bouyer 			sc->bus_speed_mhz = 133;
    563       1.1    bouyer 			break;
    564       1.1    bouyer 
    565       1.1    bouyer 		case BNX_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
    566       1.1    bouyer 			sc->bus_speed_mhz = 100;
    567       1.1    bouyer 			break;
    568       1.1    bouyer 
    569       1.1    bouyer 		case BNX_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
    570       1.1    bouyer 		case BNX_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
    571       1.1    bouyer 			sc->bus_speed_mhz = 66;
    572       1.1    bouyer 			break;
    573       1.1    bouyer 
    574       1.1    bouyer 		case BNX_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
    575       1.1    bouyer 		case BNX_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
    576       1.1    bouyer 			sc->bus_speed_mhz = 50;
    577       1.1    bouyer 			break;
    578       1.1    bouyer 
    579       1.1    bouyer 		case BNX_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
    580       1.1    bouyer 		case BNX_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
    581       1.1    bouyer 		case BNX_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
    582       1.1    bouyer 			sc->bus_speed_mhz = 33;
    583       1.1    bouyer 			break;
    584       1.1    bouyer 		}
    585       1.1    bouyer 	} else if (val & BNX_PCICFG_MISC_STATUS_M66EN)
    586       1.1    bouyer 			sc->bus_speed_mhz = 66;
    587       1.1    bouyer 		else
    588       1.1    bouyer 			sc->bus_speed_mhz = 33;
    589       1.1    bouyer 
    590       1.1    bouyer 	if (val & BNX_PCICFG_MISC_STATUS_32BIT_DET)
    591       1.1    bouyer 		sc->bnx_flags |= BNX_PCI_32BIT_FLAG;
    592       1.1    bouyer 
    593       1.1    bouyer 	/* Reset the controller. */
    594       1.1    bouyer 	if (bnx_reset(sc, BNX_DRV_MSG_CODE_RESET))
    595       1.1    bouyer 		goto bnx_attach_fail;
    596       1.1    bouyer 
    597       1.1    bouyer 	/* Initialize the controller. */
    598       1.1    bouyer 	if (bnx_chipinit(sc)) {
    599      1.13    dyoung 		aprint_error_dev(sc->bnx_dev,
    600      1.13    dyoung 		    "Controller initialization failed!\n");
    601       1.1    bouyer 		goto bnx_attach_fail;
    602       1.1    bouyer 	}
    603       1.1    bouyer 
    604       1.1    bouyer 	/* Perform NVRAM test. */
    605       1.1    bouyer 	if (bnx_nvram_test(sc)) {
    606      1.13    dyoung 		aprint_error_dev(sc->bnx_dev, "NVRAM test failed!\n");
    607       1.1    bouyer 		goto bnx_attach_fail;
    608       1.1    bouyer 	}
    609       1.1    bouyer 
    610       1.1    bouyer 	/* Fetch the permanent Ethernet MAC address. */
    611       1.1    bouyer 	bnx_get_mac_addr(sc);
    612      1.13    dyoung 	aprint_normal_dev(sc->bnx_dev, "Ethernet address %s\n",
    613       1.1    bouyer 	    ether_sprintf(sc->eaddr));
    614       1.1    bouyer 
    615       1.1    bouyer 	/*
    616       1.1    bouyer 	 * Trip points control how many BDs
    617       1.1    bouyer 	 * should be ready before generating an
    618       1.1    bouyer 	 * interrupt while ticks control how long
    619       1.1    bouyer 	 * a BD can sit in the chain before
    620       1.1    bouyer 	 * generating an interrupt.  Set the default
    621       1.1    bouyer 	 * values for the RX and TX rings.
    622       1.1    bouyer 	 */
    623       1.1    bouyer 
    624       1.1    bouyer #ifdef BNX_DEBUG
    625       1.1    bouyer 	/* Force more frequent interrupts. */
    626       1.1    bouyer 	sc->bnx_tx_quick_cons_trip_int = 1;
    627       1.1    bouyer 	sc->bnx_tx_quick_cons_trip     = 1;
    628       1.1    bouyer 	sc->bnx_tx_ticks_int           = 0;
    629       1.1    bouyer 	sc->bnx_tx_ticks               = 0;
    630       1.1    bouyer 
    631       1.1    bouyer 	sc->bnx_rx_quick_cons_trip_int = 1;
    632       1.1    bouyer 	sc->bnx_rx_quick_cons_trip     = 1;
    633       1.1    bouyer 	sc->bnx_rx_ticks_int           = 0;
    634       1.1    bouyer 	sc->bnx_rx_ticks               = 0;
    635       1.1    bouyer #else
    636       1.1    bouyer 	sc->bnx_tx_quick_cons_trip_int = 20;
    637       1.1    bouyer 	sc->bnx_tx_quick_cons_trip     = 20;
    638       1.1    bouyer 	sc->bnx_tx_ticks_int           = 80;
    639       1.1    bouyer 	sc->bnx_tx_ticks               = 80;
    640       1.1    bouyer 
    641       1.1    bouyer 	sc->bnx_rx_quick_cons_trip_int = 6;
    642       1.1    bouyer 	sc->bnx_rx_quick_cons_trip     = 6;
    643       1.1    bouyer 	sc->bnx_rx_ticks_int           = 18;
    644       1.1    bouyer 	sc->bnx_rx_ticks               = 18;
    645       1.1    bouyer #endif
    646       1.1    bouyer 
    647       1.1    bouyer 	/* Update statistics once every second. */
    648       1.1    bouyer 	sc->bnx_stats_ticks = 1000000 & 0xffff00;
    649       1.1    bouyer 
    650  1.20.4.2  sborrill 	/* Find the media type for the adapter. */
    651  1.20.4.2  sborrill 	bnx_get_media(sc);
    652  1.20.4.2  sborrill 
    653       1.1    bouyer 	/*
    654  1.20.4.2  sborrill 	 * Store config data needed by the PHY driver for
    655  1.20.4.2  sborrill 	 * backplane applications
    656       1.1    bouyer 	 */
    657  1.20.4.2  sborrill 	sc->bnx_shared_hw_cfg = REG_RD_IND(sc, sc->bnx_shmem_base +
    658  1.20.4.2  sborrill 	    BNX_SHARED_HW_CFG_CONFIG);
    659  1.20.4.2  sborrill 	sc->bnx_port_hw_cfg = REG_RD_IND(sc, sc->bnx_shmem_base +
    660  1.20.4.2  sborrill 	    BNX_PORT_HW_CFG_CONFIG);
    661       1.1    bouyer 
    662       1.1    bouyer 	/* Allocate DMA memory resources. */
    663       1.1    bouyer 	sc->bnx_dmatag = pa->pa_dmat;
    664       1.1    bouyer 	if (bnx_dma_alloc(sc)) {
    665      1.13    dyoung 		aprint_error_dev(sc->bnx_dev,
    666      1.13    dyoung 		    "DMA resource allocation failed!\n");
    667       1.1    bouyer 		goto bnx_attach_fail;
    668       1.1    bouyer 	}
    669       1.1    bouyer 
    670       1.1    bouyer 	/* Initialize the ifnet interface. */
    671      1.15    dyoung 	ifp = &sc->bnx_ec.ec_if;
    672       1.1    bouyer 	ifp->if_softc = sc;
    673       1.1    bouyer 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
    674       1.1    bouyer 	ifp->if_ioctl = bnx_ioctl;
    675      1.14    dyoung 	ifp->if_stop = bnx_stop;
    676       1.1    bouyer 	ifp->if_start = bnx_start;
    677       1.1    bouyer 	ifp->if_init = bnx_init;
    678       1.1    bouyer 	ifp->if_timer = 0;
    679       1.1    bouyer 	ifp->if_watchdog = bnx_watchdog;
    680       1.4    bouyer 	IFQ_SET_MAXLEN(&ifp->if_snd, USABLE_TX_BD - 1);
    681       1.1    bouyer 	IFQ_SET_READY(&ifp->if_snd);
    682      1.13    dyoung 	memcpy(ifp->if_xname, device_xname(self), IFNAMSIZ);
    683       1.1    bouyer 
    684      1.15    dyoung 	sc->bnx_ec.ec_capabilities |= ETHERCAP_JUMBO_MTU |
    685       1.1    bouyer 	    ETHERCAP_VLAN_MTU | ETHERCAP_VLAN_HWTAGGING;
    686       1.1    bouyer 
    687       1.1    bouyer 	ifp->if_capabilities |=
    688       1.1    bouyer 	    IFCAP_CSUM_IPv4_Tx | IFCAP_CSUM_IPv4_Rx |
    689       1.1    bouyer 	    IFCAP_CSUM_TCPv4_Tx | IFCAP_CSUM_TCPv4_Rx |
    690       1.1    bouyer 	    IFCAP_CSUM_UDPv4_Tx | IFCAP_CSUM_UDPv4_Rx;
    691       1.1    bouyer 
    692       1.1    bouyer 	/* Hookup IRQ last. */
    693       1.1    bouyer 	sc->bnx_intrhand = pci_intr_establish(pc, ih, IPL_NET, bnx_intr, sc);
    694       1.1    bouyer 	if (sc->bnx_intrhand == NULL) {
    695      1.13    dyoung 		aprint_error_dev(self, "couldn't establish interrupt");
    696       1.1    bouyer 		if (intrstr != NULL)
    697       1.1    bouyer 			aprint_error(" at %s", intrstr);
    698       1.1    bouyer 		aprint_error("\n");
    699       1.1    bouyer 		goto bnx_attach_fail;
    700       1.1    bouyer 	}
    701  1.20.4.2  sborrill 	aprint_normal_dev(sc->bnx_dev, "interrupting at %s\n", intrstr);
    702       1.1    bouyer 
    703       1.1    bouyer 	sc->bnx_mii.mii_ifp = ifp;
    704       1.1    bouyer 	sc->bnx_mii.mii_readreg = bnx_miibus_read_reg;
    705       1.1    bouyer 	sc->bnx_mii.mii_writereg = bnx_miibus_write_reg;
    706       1.1    bouyer 	sc->bnx_mii.mii_statchg = bnx_miibus_statchg;
    707       1.1    bouyer 
    708      1.16    dyoung 	sc->bnx_ec.ec_mii = &sc->bnx_mii;
    709      1.16    dyoung 	ifmedia_init(&sc->bnx_mii.mii_media, 0, ether_mediachange,
    710      1.16    dyoung 	    ether_mediastatus);
    711      1.20    mhitch 	if (sc->bnx_phy_flags & BNX_PHY_SERDES_FLAG)
    712      1.20    mhitch 		mii_flags |= MIIF_HAVEFIBER;
    713      1.13    dyoung 	mii_attach(self, &sc->bnx_mii, 0xffffffff,
    714      1.20    mhitch 	    MII_PHY_ANY, MII_OFFSET_ANY, mii_flags);
    715       1.1    bouyer 
    716      1.14    dyoung 	if (LIST_EMPTY(&sc->bnx_mii.mii_phys)) {
    717      1.13    dyoung 		aprint_error_dev(self, "no PHY found!\n");
    718       1.1    bouyer 		ifmedia_add(&sc->bnx_mii.mii_media,
    719       1.1    bouyer 		    IFM_ETHER|IFM_MANUAL, 0, NULL);
    720       1.1    bouyer 		ifmedia_set(&sc->bnx_mii.mii_media,
    721       1.1    bouyer 		    IFM_ETHER|IFM_MANUAL);
    722       1.1    bouyer 	} else {
    723       1.1    bouyer 		ifmedia_set(&sc->bnx_mii.mii_media,
    724       1.1    bouyer 		    IFM_ETHER|IFM_AUTO);
    725       1.1    bouyer 	}
    726       1.1    bouyer 
    727       1.1    bouyer 	/* Attach to the Ethernet interface list. */
    728       1.1    bouyer 	if_attach(ifp);
    729       1.1    bouyer 	ether_ifattach(ifp,sc->eaddr);
    730       1.1    bouyer 
    731       1.7        ad 	callout_init(&sc->bnx_timeout, 0);
    732       1.1    bouyer 
    733      1.14    dyoung 	if (!pmf_device_register(self, NULL, NULL))
    734      1.13    dyoung 		aprint_error_dev(self, "couldn't establish power handler\n");
    735      1.13    dyoung 	else
    736      1.13    dyoung 		pmf_class_network_register(self, ifp);
    737      1.13    dyoung 
    738       1.1    bouyer 	/* Print some important debugging info. */
    739       1.1    bouyer 	DBRUN(BNX_INFO, bnx_dump_driver_state(sc));
    740       1.1    bouyer 
    741       1.1    bouyer 	goto bnx_attach_exit;
    742       1.1    bouyer 
    743       1.1    bouyer bnx_attach_fail:
    744       1.1    bouyer 	bnx_release_resources(sc);
    745       1.1    bouyer 
    746       1.1    bouyer bnx_attach_exit:
    747      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Exiting %s()\n", __func__);
    748       1.1    bouyer }
    749       1.1    bouyer 
    750       1.1    bouyer /****************************************************************************/
    751       1.1    bouyer /* Device detach function.                                                  */
    752       1.1    bouyer /*                                                                          */
    753       1.1    bouyer /* Stops the controller, resets the controller, and releases resources.     */
    754       1.1    bouyer /*                                                                          */
    755       1.1    bouyer /* Returns:                                                                 */
    756       1.1    bouyer /*   0 on success, positive value on failure.                               */
    757       1.1    bouyer /****************************************************************************/
    758      1.13    dyoung int
    759      1.13    dyoung bnx_detach(device_t dev, int flags)
    760       1.1    bouyer {
    761      1.14    dyoung 	int s;
    762       1.1    bouyer 	struct bnx_softc *sc;
    763      1.13    dyoung 	struct ifnet *ifp;
    764       1.1    bouyer 
    765      1.13    dyoung 	sc = device_private(dev);
    766      1.15    dyoung 	ifp = &sc->bnx_ec.ec_if;
    767       1.1    bouyer 
    768      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Entering %s()\n", __func__);
    769       1.1    bouyer 
    770       1.1    bouyer 	/* Stop and reset the controller. */
    771      1.14    dyoung 	s = splnet();
    772      1.14    dyoung 	if (ifp->if_flags & IFF_RUNNING)
    773      1.14    dyoung 		bnx_stop(ifp, 1);
    774  1.20.4.2  sborrill 	else {
    775  1.20.4.2  sborrill 		/* Disable the transmit/receive blocks. */
    776  1.20.4.2  sborrill 		REG_WR(sc, BNX_MISC_ENABLE_CLR_BITS, 0x5ffffff);
    777  1.20.4.2  sborrill 		REG_RD(sc, BNX_MISC_ENABLE_CLR_BITS);
    778  1.20.4.2  sborrill 		DELAY(20);
    779  1.20.4.2  sborrill 		bnx_disable_intr(sc);
    780  1.20.4.2  sborrill 		bnx_reset(sc, BNX_DRV_MSG_CODE_RESET);
    781  1.20.4.2  sborrill 	}
    782  1.20.4.2  sborrill 
    783      1.14    dyoung 	splx(s);
    784       1.1    bouyer 
    785      1.13    dyoung 	pmf_device_deregister(dev);
    786       1.1    bouyer 	ether_ifdetach(ifp);
    787      1.13    dyoung 	if_detach(ifp);
    788      1.13    dyoung 	mii_detach(&sc->bnx_mii, MII_PHY_ANY, MII_OFFSET_ANY);
    789       1.1    bouyer 
    790       1.1    bouyer 	/* Release all remaining resources. */
    791       1.1    bouyer 	bnx_release_resources(sc);
    792       1.1    bouyer 
    793      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Exiting %s()\n", __func__);
    794       1.1    bouyer 
    795       1.1    bouyer 	return(0);
    796       1.1    bouyer }
    797       1.1    bouyer 
    798       1.1    bouyer /****************************************************************************/
    799       1.1    bouyer /* Indirect register read.                                                  */
    800       1.1    bouyer /*                                                                          */
    801       1.1    bouyer /* Reads NetXtreme II registers using an index/data register pair in PCI    */
    802       1.1    bouyer /* configuration space.  Using this mechanism avoids issues with posted     */
    803       1.1    bouyer /* reads but is much slower than memory-mapped I/O.                         */
    804       1.1    bouyer /*                                                                          */
    805       1.1    bouyer /* Returns:                                                                 */
    806       1.1    bouyer /*   The value of the register.                                             */
    807       1.1    bouyer /****************************************************************************/
    808       1.1    bouyer u_int32_t
    809       1.1    bouyer bnx_reg_rd_ind(struct bnx_softc *sc, u_int32_t offset)
    810       1.1    bouyer {
    811       1.1    bouyer 	struct pci_attach_args	*pa = &(sc->bnx_pa);
    812       1.1    bouyer 
    813       1.1    bouyer 	pci_conf_write(pa->pa_pc, pa->pa_tag, BNX_PCICFG_REG_WINDOW_ADDRESS,
    814       1.1    bouyer 	    offset);
    815       1.1    bouyer #ifdef BNX_DEBUG
    816       1.1    bouyer 	{
    817       1.1    bouyer 		u_int32_t val;
    818       1.1    bouyer 		val = pci_conf_read(pa->pa_pc, pa->pa_tag,
    819       1.1    bouyer 		    BNX_PCICFG_REG_WINDOW);
    820       1.1    bouyer 		DBPRINT(sc, BNX_EXCESSIVE, "%s(); offset = 0x%08X, "
    821      1.12     perry 		    "val = 0x%08X\n", __func__, offset, val);
    822       1.1    bouyer 		return (val);
    823       1.1    bouyer 	}
    824       1.1    bouyer #else
    825       1.1    bouyer 	return pci_conf_read(pa->pa_pc, pa->pa_tag, BNX_PCICFG_REG_WINDOW);
    826       1.1    bouyer #endif
    827       1.1    bouyer }
    828       1.1    bouyer 
    829       1.1    bouyer /****************************************************************************/
    830       1.1    bouyer /* Indirect register write.                                                 */
    831       1.1    bouyer /*                                                                          */
    832       1.1    bouyer /* Writes NetXtreme II registers using an index/data register pair in PCI   */
    833       1.1    bouyer /* configuration space.  Using this mechanism avoids issues with posted     */
    834       1.1    bouyer /* writes but is muchh slower than memory-mapped I/O.                       */
    835       1.1    bouyer /*                                                                          */
    836       1.1    bouyer /* Returns:                                                                 */
    837       1.1    bouyer /*   Nothing.                                                               */
    838       1.1    bouyer /****************************************************************************/
    839       1.1    bouyer void
    840       1.1    bouyer bnx_reg_wr_ind(struct bnx_softc *sc, u_int32_t offset, u_int32_t val)
    841       1.1    bouyer {
    842       1.1    bouyer 	struct pci_attach_args  *pa = &(sc->bnx_pa);
    843       1.1    bouyer 
    844       1.1    bouyer 	DBPRINT(sc, BNX_EXCESSIVE, "%s(); offset = 0x%08X, val = 0x%08X\n",
    845      1.12     perry 		__func__, offset, val);
    846       1.1    bouyer 
    847       1.1    bouyer 	pci_conf_write(pa->pa_pc, pa->pa_tag, BNX_PCICFG_REG_WINDOW_ADDRESS,
    848       1.1    bouyer 	    offset);
    849       1.1    bouyer 	pci_conf_write(pa->pa_pc, pa->pa_tag, BNX_PCICFG_REG_WINDOW, val);
    850       1.1    bouyer }
    851       1.1    bouyer 
    852       1.1    bouyer /****************************************************************************/
    853       1.1    bouyer /* Context memory write.                                                    */
    854       1.1    bouyer /*                                                                          */
    855       1.1    bouyer /* The NetXtreme II controller uses context memory to track connection      */
    856       1.1    bouyer /* information for L2 and higher network protocols.                         */
    857       1.1    bouyer /*                                                                          */
    858       1.1    bouyer /* Returns:                                                                 */
    859       1.1    bouyer /*   Nothing.                                                               */
    860       1.1    bouyer /****************************************************************************/
    861       1.1    bouyer void
    862  1.20.4.2  sborrill bnx_ctx_wr(struct bnx_softc *sc, u_int32_t cid_addr, u_int32_t ctx_offset,
    863  1.20.4.2  sborrill     u_int32_t ctx_val)
    864       1.1    bouyer {
    865  1.20.4.2  sborrill 	u_int32_t idx, offset = ctx_offset + cid_addr;
    866  1.20.4.2  sborrill 	u_int32_t val, retry_cnt = 5;
    867  1.20.4.2  sborrill 
    868  1.20.4.2  sborrill 	if (BNX_CHIP_NUM(sc) == BNX_CHIP_NUM_5709) {
    869  1.20.4.2  sborrill 		REG_WR(sc, BNX_CTX_CTX_DATA, ctx_val);
    870  1.20.4.2  sborrill 		REG_WR(sc, BNX_CTX_CTX_CTRL,
    871  1.20.4.2  sborrill 		    (offset | BNX_CTX_CTX_CTRL_WRITE_REQ));
    872  1.20.4.2  sborrill 
    873  1.20.4.2  sborrill 		for (idx = 0; idx < retry_cnt; idx++) {
    874  1.20.4.2  sborrill 			val = REG_RD(sc, BNX_CTX_CTX_CTRL);
    875  1.20.4.2  sborrill 			if ((val & BNX_CTX_CTX_CTRL_WRITE_REQ) == 0)
    876  1.20.4.2  sborrill 				break;
    877  1.20.4.2  sborrill 			DELAY(5);
    878  1.20.4.2  sborrill 		}
    879       1.1    bouyer 
    880  1.20.4.2  sborrill #if 0
    881  1.20.4.2  sborrill 		if (val & BNX_CTX_CTX_CTRL_WRITE_REQ)
    882  1.20.4.2  sborrill 			BNX_PRINTF("%s(%d); Unable to write CTX memory: "
    883  1.20.4.2  sborrill 				"cid_addr = 0x%08X, offset = 0x%08X!\n",
    884  1.20.4.2  sborrill 				__FILE__, __LINE__, cid_addr, ctx_offset);
    885  1.20.4.2  sborrill #endif
    886       1.1    bouyer 
    887  1.20.4.2  sborrill 	} else {
    888  1.20.4.2  sborrill 		REG_WR(sc, BNX_CTX_DATA_ADR, offset);
    889  1.20.4.2  sborrill 		REG_WR(sc, BNX_CTX_DATA, ctx_val);
    890  1.20.4.2  sborrill 	}
    891       1.1    bouyer }
    892       1.1    bouyer 
    893       1.1    bouyer /****************************************************************************/
    894       1.1    bouyer /* PHY register read.                                                       */
    895       1.1    bouyer /*                                                                          */
    896       1.1    bouyer /* Implements register reads on the MII bus.                                */
    897       1.1    bouyer /*                                                                          */
    898       1.1    bouyer /* Returns:                                                                 */
    899       1.1    bouyer /*   The value of the register.                                             */
    900       1.1    bouyer /****************************************************************************/
    901       1.1    bouyer int
    902      1.13    dyoung bnx_miibus_read_reg(device_t dev, int phy, int reg)
    903       1.1    bouyer {
    904      1.13    dyoung 	struct bnx_softc	*sc = device_private(dev);
    905       1.1    bouyer 	u_int32_t		val;
    906       1.1    bouyer 	int			i;
    907       1.1    bouyer 
    908       1.1    bouyer 	/* Make sure we are accessing the correct PHY address. */
    909       1.1    bouyer 	if (phy != sc->bnx_phy_addr) {
    910       1.1    bouyer 		DBPRINT(sc, BNX_VERBOSE,
    911       1.1    bouyer 		    "Invalid PHY address %d for PHY read!\n", phy);
    912       1.1    bouyer 		return(0);
    913       1.1    bouyer 	}
    914       1.1    bouyer 
    915       1.1    bouyer 	if (sc->bnx_phy_flags & BNX_PHY_INT_MODE_AUTO_POLLING_FLAG) {
    916       1.1    bouyer 		val = REG_RD(sc, BNX_EMAC_MDIO_MODE);
    917       1.1    bouyer 		val &= ~BNX_EMAC_MDIO_MODE_AUTO_POLL;
    918       1.1    bouyer 
    919       1.1    bouyer 		REG_WR(sc, BNX_EMAC_MDIO_MODE, val);
    920       1.1    bouyer 		REG_RD(sc, BNX_EMAC_MDIO_MODE);
    921       1.1    bouyer 
    922       1.1    bouyer 		DELAY(40);
    923       1.1    bouyer 	}
    924       1.1    bouyer 
    925       1.1    bouyer 	val = BNX_MIPHY(phy) | BNX_MIREG(reg) |
    926       1.1    bouyer 	    BNX_EMAC_MDIO_COMM_COMMAND_READ | BNX_EMAC_MDIO_COMM_DISEXT |
    927       1.1    bouyer 	    BNX_EMAC_MDIO_COMM_START_BUSY;
    928       1.1    bouyer 	REG_WR(sc, BNX_EMAC_MDIO_COMM, val);
    929       1.1    bouyer 
    930       1.1    bouyer 	for (i = 0; i < BNX_PHY_TIMEOUT; i++) {
    931       1.1    bouyer 		DELAY(10);
    932       1.1    bouyer 
    933       1.1    bouyer 		val = REG_RD(sc, BNX_EMAC_MDIO_COMM);
    934       1.1    bouyer 		if (!(val & BNX_EMAC_MDIO_COMM_START_BUSY)) {
    935       1.1    bouyer 			DELAY(5);
    936       1.1    bouyer 
    937       1.1    bouyer 			val = REG_RD(sc, BNX_EMAC_MDIO_COMM);
    938       1.1    bouyer 			val &= BNX_EMAC_MDIO_COMM_DATA;
    939       1.1    bouyer 
    940       1.1    bouyer 			break;
    941       1.1    bouyer 		}
    942       1.1    bouyer 	}
    943       1.1    bouyer 
    944       1.1    bouyer 	if (val & BNX_EMAC_MDIO_COMM_START_BUSY) {
    945       1.1    bouyer 		BNX_PRINTF(sc, "%s(%d): Error: PHY read timeout! phy = %d, "
    946       1.1    bouyer 		    "reg = 0x%04X\n", __FILE__, __LINE__, phy, reg);
    947       1.1    bouyer 		val = 0x0;
    948       1.1    bouyer 	} else
    949       1.1    bouyer 		val = REG_RD(sc, BNX_EMAC_MDIO_COMM);
    950       1.1    bouyer 
    951       1.1    bouyer 	DBPRINT(sc, BNX_EXCESSIVE,
    952      1.12     perry 	    "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n", __func__, phy,
    953       1.1    bouyer 	    (u_int16_t) reg & 0xffff, (u_int16_t) val & 0xffff);
    954       1.1    bouyer 
    955       1.1    bouyer 	if (sc->bnx_phy_flags & BNX_PHY_INT_MODE_AUTO_POLLING_FLAG) {
    956       1.1    bouyer 		val = REG_RD(sc, BNX_EMAC_MDIO_MODE);
    957       1.1    bouyer 		val |= BNX_EMAC_MDIO_MODE_AUTO_POLL;
    958       1.1    bouyer 
    959       1.1    bouyer 		REG_WR(sc, BNX_EMAC_MDIO_MODE, val);
    960       1.1    bouyer 		REG_RD(sc, BNX_EMAC_MDIO_MODE);
    961       1.1    bouyer 
    962       1.1    bouyer 		DELAY(40);
    963       1.1    bouyer 	}
    964       1.1    bouyer 
    965       1.1    bouyer 	return (val & 0xffff);
    966       1.1    bouyer }
    967       1.1    bouyer 
    968       1.1    bouyer /****************************************************************************/
    969       1.1    bouyer /* PHY register write.                                                      */
    970       1.1    bouyer /*                                                                          */
    971       1.1    bouyer /* Implements register writes on the MII bus.                               */
    972       1.1    bouyer /*                                                                          */
    973       1.1    bouyer /* Returns:                                                                 */
    974       1.1    bouyer /*   The value of the register.                                             */
    975       1.1    bouyer /****************************************************************************/
    976       1.1    bouyer void
    977      1.13    dyoung bnx_miibus_write_reg(device_t dev, int phy, int reg, int val)
    978       1.1    bouyer {
    979      1.13    dyoung 	struct bnx_softc	*sc = device_private(dev);
    980       1.1    bouyer 	u_int32_t		val1;
    981       1.1    bouyer 	int			i;
    982       1.1    bouyer 
    983       1.1    bouyer 	/* Make sure we are accessing the correct PHY address. */
    984       1.1    bouyer 	if (phy != sc->bnx_phy_addr) {
    985       1.1    bouyer 		DBPRINT(sc, BNX_WARN, "Invalid PHY address %d for PHY write!\n",
    986       1.1    bouyer 		    phy);
    987       1.1    bouyer 		return;
    988       1.1    bouyer 	}
    989       1.1    bouyer 
    990       1.1    bouyer 	DBPRINT(sc, BNX_EXCESSIVE, "%s(): phy = %d, reg = 0x%04X, "
    991      1.12     perry 	    "val = 0x%04X\n", __func__,
    992       1.1    bouyer 	    phy, (u_int16_t) reg & 0xffff, (u_int16_t) val & 0xffff);
    993       1.1    bouyer 
    994       1.1    bouyer 	if (sc->bnx_phy_flags & BNX_PHY_INT_MODE_AUTO_POLLING_FLAG) {
    995       1.1    bouyer 		val1 = REG_RD(sc, BNX_EMAC_MDIO_MODE);
    996       1.1    bouyer 		val1 &= ~BNX_EMAC_MDIO_MODE_AUTO_POLL;
    997       1.1    bouyer 
    998       1.1    bouyer 		REG_WR(sc, BNX_EMAC_MDIO_MODE, val1);
    999       1.1    bouyer 		REG_RD(sc, BNX_EMAC_MDIO_MODE);
   1000       1.1    bouyer 
   1001       1.1    bouyer 		DELAY(40);
   1002       1.1    bouyer 	}
   1003       1.1    bouyer 
   1004       1.1    bouyer 	val1 = BNX_MIPHY(phy) | BNX_MIREG(reg) | val |
   1005       1.1    bouyer 	    BNX_EMAC_MDIO_COMM_COMMAND_WRITE |
   1006       1.1    bouyer 	    BNX_EMAC_MDIO_COMM_START_BUSY | BNX_EMAC_MDIO_COMM_DISEXT;
   1007       1.1    bouyer 	REG_WR(sc, BNX_EMAC_MDIO_COMM, val1);
   1008       1.1    bouyer 
   1009       1.1    bouyer 	for (i = 0; i < BNX_PHY_TIMEOUT; i++) {
   1010       1.1    bouyer 		DELAY(10);
   1011       1.1    bouyer 
   1012       1.1    bouyer 		val1 = REG_RD(sc, BNX_EMAC_MDIO_COMM);
   1013       1.1    bouyer 		if (!(val1 & BNX_EMAC_MDIO_COMM_START_BUSY)) {
   1014       1.1    bouyer 			DELAY(5);
   1015       1.1    bouyer 			break;
   1016       1.1    bouyer 		}
   1017       1.1    bouyer 	}
   1018       1.1    bouyer 
   1019       1.1    bouyer 	if (val1 & BNX_EMAC_MDIO_COMM_START_BUSY) {
   1020       1.1    bouyer 		BNX_PRINTF(sc, "%s(%d): PHY write timeout!\n", __FILE__,
   1021       1.1    bouyer 		    __LINE__);
   1022       1.1    bouyer 	}
   1023       1.1    bouyer 
   1024       1.1    bouyer 	if (sc->bnx_phy_flags & BNX_PHY_INT_MODE_AUTO_POLLING_FLAG) {
   1025       1.1    bouyer 		val1 = REG_RD(sc, BNX_EMAC_MDIO_MODE);
   1026       1.1    bouyer 		val1 |= BNX_EMAC_MDIO_MODE_AUTO_POLL;
   1027       1.1    bouyer 
   1028       1.1    bouyer 		REG_WR(sc, BNX_EMAC_MDIO_MODE, val1);
   1029       1.1    bouyer 		REG_RD(sc, BNX_EMAC_MDIO_MODE);
   1030       1.1    bouyer 
   1031       1.1    bouyer 		DELAY(40);
   1032       1.1    bouyer 	}
   1033       1.1    bouyer }
   1034       1.1    bouyer 
   1035       1.1    bouyer /****************************************************************************/
   1036       1.1    bouyer /* MII bus status change.                                                   */
   1037       1.1    bouyer /*                                                                          */
   1038       1.1    bouyer /* Called by the MII bus driver when the PHY establishes link to set the    */
   1039       1.1    bouyer /* MAC interface registers.                                                 */
   1040       1.1    bouyer /*                                                                          */
   1041       1.1    bouyer /* Returns:                                                                 */
   1042       1.1    bouyer /*   Nothing.                                                               */
   1043       1.1    bouyer /****************************************************************************/
   1044       1.1    bouyer void
   1045      1.13    dyoung bnx_miibus_statchg(device_t dev)
   1046       1.1    bouyer {
   1047      1.13    dyoung 	struct bnx_softc	*sc = device_private(dev);
   1048       1.1    bouyer 	struct mii_data		*mii = &sc->bnx_mii;
   1049      1.20    mhitch 	int			val;
   1050       1.1    bouyer 
   1051      1.20    mhitch 	val = REG_RD(sc, BNX_EMAC_MODE);
   1052      1.20    mhitch 	val &= ~(BNX_EMAC_MODE_PORT | BNX_EMAC_MODE_HALF_DUPLEX |
   1053      1.20    mhitch 	    BNX_EMAC_MODE_MAC_LOOP | BNX_EMAC_MODE_FORCE_LINK |
   1054      1.20    mhitch 	    BNX_EMAC_MODE_25G);
   1055       1.1    bouyer 
   1056      1.20    mhitch 	/* Set MII or GMII interface based on the speed
   1057      1.20    mhitch 	 * negotiated by the PHY.
   1058      1.20    mhitch 	 */
   1059      1.20    mhitch 	switch (IFM_SUBTYPE(mii->mii_media_active)) {
   1060      1.20    mhitch 	case IFM_10_T:
   1061      1.20    mhitch 		if (BNX_CHIP_NUM(sc) != BNX_CHIP_NUM_5706) {
   1062      1.20    mhitch 			DBPRINT(sc, BNX_INFO, "Enabling 10Mb interface.\n");
   1063      1.20    mhitch 			val |= BNX_EMAC_MODE_PORT_MII_10;
   1064      1.20    mhitch 			break;
   1065      1.20    mhitch 		}
   1066      1.20    mhitch 		/* FALLTHROUGH */
   1067      1.20    mhitch 	case IFM_100_TX:
   1068      1.20    mhitch 		DBPRINT(sc, BNX_INFO, "Enabling MII interface.\n");
   1069      1.20    mhitch 		val |= BNX_EMAC_MODE_PORT_MII;
   1070      1.20    mhitch 		break;
   1071      1.20    mhitch 	case IFM_2500_SX:
   1072      1.20    mhitch 		DBPRINT(sc, BNX_INFO, "Enabling 2.5G MAC mode.\n");
   1073      1.20    mhitch 		val |= BNX_EMAC_MODE_25G;
   1074      1.20    mhitch 		/* FALLTHROUGH */
   1075      1.20    mhitch 	case IFM_1000_T:
   1076      1.20    mhitch 	case IFM_1000_SX:
   1077      1.20    mhitch 		DBPRINT(sc, BNX_INFO, "Enabling GMII interface.\n");
   1078      1.20    mhitch 		val |= BNX_EMAC_MODE_PORT_GMII;
   1079      1.20    mhitch 		break;
   1080      1.20    mhitch 	default:
   1081      1.20    mhitch 		val |= BNX_EMAC_MODE_PORT_GMII;
   1082      1.20    mhitch 		break;
   1083       1.1    bouyer 	}
   1084       1.1    bouyer 
   1085       1.1    bouyer 	/* Set half or full duplex based on the duplicity
   1086       1.1    bouyer 	 * negotiated by the PHY.
   1087       1.1    bouyer 	 */
   1088      1.20    mhitch 	if ((mii->mii_media_active & IFM_GMASK) == IFM_HDX) {
   1089      1.20    mhitch 		DBPRINT(sc, BNX_INFO, "Setting Half-Duplex interface.\n");
   1090      1.20    mhitch 		val |= BNX_EMAC_MODE_HALF_DUPLEX;
   1091      1.20    mhitch 	} else {
   1092       1.1    bouyer 		DBPRINT(sc, BNX_INFO, "Setting Full-Duplex interface.\n");
   1093       1.1    bouyer 	}
   1094      1.20    mhitch 
   1095      1.20    mhitch 	REG_WR(sc, BNX_EMAC_MODE, val);
   1096       1.1    bouyer }
   1097       1.1    bouyer 
   1098       1.1    bouyer /****************************************************************************/
   1099       1.1    bouyer /* Acquire NVRAM lock.                                                      */
   1100       1.1    bouyer /*                                                                          */
   1101       1.1    bouyer /* Before the NVRAM can be accessed the caller must acquire an NVRAM lock.  */
   1102       1.1    bouyer /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is     */
   1103       1.1    bouyer /* for use by the driver.                                                   */
   1104       1.1    bouyer /*                                                                          */
   1105       1.1    bouyer /* Returns:                                                                 */
   1106       1.1    bouyer /*   0 on success, positive value on failure.                               */
   1107       1.1    bouyer /****************************************************************************/
   1108       1.1    bouyer int
   1109       1.1    bouyer bnx_acquire_nvram_lock(struct bnx_softc *sc)
   1110       1.1    bouyer {
   1111       1.1    bouyer 	u_int32_t		val;
   1112       1.1    bouyer 	int			j;
   1113       1.1    bouyer 
   1114       1.1    bouyer 	DBPRINT(sc, BNX_VERBOSE, "Acquiring NVRAM lock.\n");
   1115       1.1    bouyer 
   1116       1.1    bouyer 	/* Request access to the flash interface. */
   1117       1.1    bouyer 	REG_WR(sc, BNX_NVM_SW_ARB, BNX_NVM_SW_ARB_ARB_REQ_SET2);
   1118       1.1    bouyer 	for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
   1119       1.1    bouyer 		val = REG_RD(sc, BNX_NVM_SW_ARB);
   1120       1.1    bouyer 		if (val & BNX_NVM_SW_ARB_ARB_ARB2)
   1121       1.1    bouyer 			break;
   1122       1.1    bouyer 
   1123       1.1    bouyer 		DELAY(5);
   1124       1.1    bouyer 	}
   1125       1.1    bouyer 
   1126       1.1    bouyer 	if (j >= NVRAM_TIMEOUT_COUNT) {
   1127       1.1    bouyer 		DBPRINT(sc, BNX_WARN, "Timeout acquiring NVRAM lock!\n");
   1128       1.1    bouyer 		return (EBUSY);
   1129       1.1    bouyer 	}
   1130       1.1    bouyer 
   1131       1.1    bouyer 	return (0);
   1132       1.1    bouyer }
   1133       1.1    bouyer 
   1134       1.1    bouyer /****************************************************************************/
   1135       1.1    bouyer /* Release NVRAM lock.                                                      */
   1136       1.1    bouyer /*                                                                          */
   1137       1.1    bouyer /* When the caller is finished accessing NVRAM the lock must be released.   */
   1138       1.1    bouyer /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is     */
   1139       1.1    bouyer /* for use by the driver.                                                   */
   1140       1.1    bouyer /*                                                                          */
   1141       1.1    bouyer /* Returns:                                                                 */
   1142       1.1    bouyer /*   0 on success, positive value on failure.                               */
   1143       1.1    bouyer /****************************************************************************/
   1144       1.1    bouyer int
   1145       1.1    bouyer bnx_release_nvram_lock(struct bnx_softc *sc)
   1146       1.1    bouyer {
   1147       1.1    bouyer 	int			j;
   1148       1.1    bouyer 	u_int32_t		val;
   1149       1.1    bouyer 
   1150       1.1    bouyer 	DBPRINT(sc, BNX_VERBOSE, "Releasing NVRAM lock.\n");
   1151       1.1    bouyer 
   1152       1.1    bouyer 	/* Relinquish nvram interface. */
   1153       1.1    bouyer 	REG_WR(sc, BNX_NVM_SW_ARB, BNX_NVM_SW_ARB_ARB_REQ_CLR2);
   1154       1.1    bouyer 
   1155       1.1    bouyer 	for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
   1156       1.1    bouyer 		val = REG_RD(sc, BNX_NVM_SW_ARB);
   1157       1.1    bouyer 		if (!(val & BNX_NVM_SW_ARB_ARB_ARB2))
   1158       1.1    bouyer 			break;
   1159       1.1    bouyer 
   1160       1.1    bouyer 		DELAY(5);
   1161       1.1    bouyer 	}
   1162       1.1    bouyer 
   1163       1.1    bouyer 	if (j >= NVRAM_TIMEOUT_COUNT) {
   1164       1.1    bouyer 		DBPRINT(sc, BNX_WARN, "Timeout reeasing NVRAM lock!\n");
   1165       1.1    bouyer 		return (EBUSY);
   1166       1.1    bouyer 	}
   1167       1.1    bouyer 
   1168       1.1    bouyer 	return (0);
   1169       1.1    bouyer }
   1170       1.1    bouyer 
   1171       1.1    bouyer #ifdef BNX_NVRAM_WRITE_SUPPORT
   1172       1.1    bouyer /****************************************************************************/
   1173       1.1    bouyer /* Enable NVRAM write access.                                               */
   1174       1.1    bouyer /*                                                                          */
   1175       1.1    bouyer /* Before writing to NVRAM the caller must enable NVRAM writes.             */
   1176       1.1    bouyer /*                                                                          */
   1177       1.1    bouyer /* Returns:                                                                 */
   1178       1.1    bouyer /*   0 on success, positive value on failure.                               */
   1179       1.1    bouyer /****************************************************************************/
   1180       1.1    bouyer int
   1181       1.1    bouyer bnx_enable_nvram_write(struct bnx_softc *sc)
   1182       1.1    bouyer {
   1183       1.1    bouyer 	u_int32_t		val;
   1184       1.1    bouyer 
   1185       1.1    bouyer 	DBPRINT(sc, BNX_VERBOSE, "Enabling NVRAM write.\n");
   1186       1.1    bouyer 
   1187       1.1    bouyer 	val = REG_RD(sc, BNX_MISC_CFG);
   1188       1.1    bouyer 	REG_WR(sc, BNX_MISC_CFG, val | BNX_MISC_CFG_NVM_WR_EN_PCI);
   1189       1.1    bouyer 
   1190  1.20.4.2  sborrill 	if (!ISSET(sc->bnx_flash_info->flags, BNX_NV_BUFFERED)) {
   1191       1.1    bouyer 		int j;
   1192       1.1    bouyer 
   1193       1.1    bouyer 		REG_WR(sc, BNX_NVM_COMMAND, BNX_NVM_COMMAND_DONE);
   1194       1.1    bouyer 		REG_WR(sc, BNX_NVM_COMMAND,
   1195       1.1    bouyer 		    BNX_NVM_COMMAND_WREN | BNX_NVM_COMMAND_DOIT);
   1196       1.1    bouyer 
   1197       1.1    bouyer 		for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
   1198       1.1    bouyer 			DELAY(5);
   1199       1.1    bouyer 
   1200       1.1    bouyer 			val = REG_RD(sc, BNX_NVM_COMMAND);
   1201       1.1    bouyer 			if (val & BNX_NVM_COMMAND_DONE)
   1202       1.1    bouyer 				break;
   1203       1.1    bouyer 		}
   1204       1.1    bouyer 
   1205       1.1    bouyer 		if (j >= NVRAM_TIMEOUT_COUNT) {
   1206       1.1    bouyer 			DBPRINT(sc, BNX_WARN, "Timeout writing NVRAM!\n");
   1207       1.1    bouyer 			return (EBUSY);
   1208       1.1    bouyer 		}
   1209       1.1    bouyer 	}
   1210       1.1    bouyer 
   1211       1.1    bouyer 	return (0);
   1212       1.1    bouyer }
   1213       1.1    bouyer 
   1214       1.1    bouyer /****************************************************************************/
   1215       1.1    bouyer /* Disable NVRAM write access.                                              */
   1216       1.1    bouyer /*                                                                          */
   1217       1.1    bouyer /* When the caller is finished writing to NVRAM write access must be        */
   1218       1.1    bouyer /* disabled.                                                                */
   1219       1.1    bouyer /*                                                                          */
   1220       1.1    bouyer /* Returns:                                                                 */
   1221       1.1    bouyer /*   Nothing.                                                               */
   1222       1.1    bouyer /****************************************************************************/
   1223       1.1    bouyer void
   1224       1.1    bouyer bnx_disable_nvram_write(struct bnx_softc *sc)
   1225       1.1    bouyer {
   1226       1.1    bouyer 	u_int32_t		val;
   1227       1.1    bouyer 
   1228       1.1    bouyer 	DBPRINT(sc, BNX_VERBOSE,  "Disabling NVRAM write.\n");
   1229       1.1    bouyer 
   1230       1.1    bouyer 	val = REG_RD(sc, BNX_MISC_CFG);
   1231       1.1    bouyer 	REG_WR(sc, BNX_MISC_CFG, val & ~BNX_MISC_CFG_NVM_WR_EN);
   1232       1.1    bouyer }
   1233       1.1    bouyer #endif
   1234       1.1    bouyer 
   1235       1.1    bouyer /****************************************************************************/
   1236       1.1    bouyer /* Enable NVRAM access.                                                     */
   1237       1.1    bouyer /*                                                                          */
   1238       1.1    bouyer /* Before accessing NVRAM for read or write operations the caller must      */
   1239       1.1    bouyer /* enabled NVRAM access.                                                    */
   1240       1.1    bouyer /*                                                                          */
   1241       1.1    bouyer /* Returns:                                                                 */
   1242       1.1    bouyer /*   Nothing.                                                               */
   1243       1.1    bouyer /****************************************************************************/
   1244       1.1    bouyer void
   1245       1.1    bouyer bnx_enable_nvram_access(struct bnx_softc *sc)
   1246       1.1    bouyer {
   1247       1.1    bouyer 	u_int32_t		val;
   1248       1.1    bouyer 
   1249       1.1    bouyer 	DBPRINT(sc, BNX_VERBOSE, "Enabling NVRAM access.\n");
   1250       1.1    bouyer 
   1251       1.1    bouyer 	val = REG_RD(sc, BNX_NVM_ACCESS_ENABLE);
   1252       1.1    bouyer 	/* Enable both bits, even on read. */
   1253       1.1    bouyer 	REG_WR(sc, BNX_NVM_ACCESS_ENABLE,
   1254       1.1    bouyer 	    val | BNX_NVM_ACCESS_ENABLE_EN | BNX_NVM_ACCESS_ENABLE_WR_EN);
   1255       1.1    bouyer }
   1256       1.1    bouyer 
   1257       1.1    bouyer /****************************************************************************/
   1258       1.1    bouyer /* Disable NVRAM access.                                                    */
   1259       1.1    bouyer /*                                                                          */
   1260       1.1    bouyer /* When the caller is finished accessing NVRAM access must be disabled.     */
   1261       1.1    bouyer /*                                                                          */
   1262       1.1    bouyer /* Returns:                                                                 */
   1263       1.1    bouyer /*   Nothing.                                                               */
   1264       1.1    bouyer /****************************************************************************/
   1265       1.1    bouyer void
   1266       1.1    bouyer bnx_disable_nvram_access(struct bnx_softc *sc)
   1267       1.1    bouyer {
   1268       1.1    bouyer 	u_int32_t		val;
   1269       1.1    bouyer 
   1270       1.1    bouyer 	DBPRINT(sc, BNX_VERBOSE, "Disabling NVRAM access.\n");
   1271       1.1    bouyer 
   1272       1.1    bouyer 	val = REG_RD(sc, BNX_NVM_ACCESS_ENABLE);
   1273       1.1    bouyer 
   1274       1.1    bouyer 	/* Disable both bits, even after read. */
   1275       1.1    bouyer 	REG_WR(sc, BNX_NVM_ACCESS_ENABLE,
   1276       1.1    bouyer 	    val & ~(BNX_NVM_ACCESS_ENABLE_EN | BNX_NVM_ACCESS_ENABLE_WR_EN));
   1277       1.1    bouyer }
   1278       1.1    bouyer 
   1279       1.1    bouyer #ifdef BNX_NVRAM_WRITE_SUPPORT
   1280       1.1    bouyer /****************************************************************************/
   1281       1.1    bouyer /* Erase NVRAM page before writing.                                         */
   1282       1.1    bouyer /*                                                                          */
   1283       1.1    bouyer /* Non-buffered flash parts require that a page be erased before it is      */
   1284       1.1    bouyer /* written.                                                                 */
   1285       1.1    bouyer /*                                                                          */
   1286       1.1    bouyer /* Returns:                                                                 */
   1287       1.1    bouyer /*   0 on success, positive value on failure.                               */
   1288       1.1    bouyer /****************************************************************************/
   1289       1.1    bouyer int
   1290       1.1    bouyer bnx_nvram_erase_page(struct bnx_softc *sc, u_int32_t offset)
   1291       1.1    bouyer {
   1292       1.1    bouyer 	u_int32_t		cmd;
   1293       1.1    bouyer 	int			j;
   1294       1.1    bouyer 
   1295       1.1    bouyer 	/* Buffered flash doesn't require an erase. */
   1296  1.20.4.2  sborrill 	if (ISSET(sc->bnx_flash_info->flags, BNX_NV_BUFFERED))
   1297       1.1    bouyer 		return (0);
   1298       1.1    bouyer 
   1299       1.1    bouyer 	DBPRINT(sc, BNX_VERBOSE, "Erasing NVRAM page.\n");
   1300       1.1    bouyer 
   1301       1.1    bouyer 	/* Build an erase command. */
   1302       1.1    bouyer 	cmd = BNX_NVM_COMMAND_ERASE | BNX_NVM_COMMAND_WR |
   1303       1.1    bouyer 	    BNX_NVM_COMMAND_DOIT;
   1304       1.1    bouyer 
   1305       1.1    bouyer 	/*
   1306       1.1    bouyer 	 * Clear the DONE bit separately, set the NVRAM adress to erase,
   1307       1.1    bouyer 	 * and issue the erase command.
   1308       1.1    bouyer 	 */
   1309       1.1    bouyer 	REG_WR(sc, BNX_NVM_COMMAND, BNX_NVM_COMMAND_DONE);
   1310       1.1    bouyer 	REG_WR(sc, BNX_NVM_ADDR, offset & BNX_NVM_ADDR_NVM_ADDR_VALUE);
   1311       1.1    bouyer 	REG_WR(sc, BNX_NVM_COMMAND, cmd);
   1312       1.1    bouyer 
   1313       1.1    bouyer 	/* Wait for completion. */
   1314       1.1    bouyer 	for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
   1315       1.1    bouyer 		u_int32_t val;
   1316       1.1    bouyer 
   1317       1.1    bouyer 		DELAY(5);
   1318       1.1    bouyer 
   1319       1.1    bouyer 		val = REG_RD(sc, BNX_NVM_COMMAND);
   1320       1.1    bouyer 		if (val & BNX_NVM_COMMAND_DONE)
   1321       1.1    bouyer 			break;
   1322       1.1    bouyer 	}
   1323       1.1    bouyer 
   1324       1.1    bouyer 	if (j >= NVRAM_TIMEOUT_COUNT) {
   1325       1.1    bouyer 		DBPRINT(sc, BNX_WARN, "Timeout erasing NVRAM.\n");
   1326       1.1    bouyer 		return (EBUSY);
   1327       1.1    bouyer 	}
   1328       1.1    bouyer 
   1329       1.1    bouyer 	return (0);
   1330       1.1    bouyer }
   1331       1.1    bouyer #endif /* BNX_NVRAM_WRITE_SUPPORT */
   1332       1.1    bouyer 
   1333       1.1    bouyer /****************************************************************************/
   1334       1.1    bouyer /* Read a dword (32 bits) from NVRAM.                                       */
   1335       1.1    bouyer /*                                                                          */
   1336       1.1    bouyer /* Read a 32 bit word from NVRAM.  The caller is assumed to have already    */
   1337       1.1    bouyer /* obtained the NVRAM lock and enabled the controller for NVRAM access.     */
   1338       1.1    bouyer /*                                                                          */
   1339       1.1    bouyer /* Returns:                                                                 */
   1340       1.1    bouyer /*   0 on success and the 32 bit value read, positive value on failure.     */
   1341       1.1    bouyer /****************************************************************************/
   1342       1.1    bouyer int
   1343       1.1    bouyer bnx_nvram_read_dword(struct bnx_softc *sc, u_int32_t offset,
   1344       1.1    bouyer     u_int8_t *ret_val, u_int32_t cmd_flags)
   1345       1.1    bouyer {
   1346       1.1    bouyer 	u_int32_t		cmd;
   1347       1.1    bouyer 	int			i, rc = 0;
   1348       1.1    bouyer 
   1349       1.1    bouyer 	/* Build the command word. */
   1350       1.1    bouyer 	cmd = BNX_NVM_COMMAND_DOIT | cmd_flags;
   1351       1.1    bouyer 
   1352  1.20.4.2  sborrill 	/* Calculate the offset for buffered flash if translation is used. */
   1353  1.20.4.2  sborrill 	if (ISSET(sc->bnx_flash_info->flags, BNX_NV_TRANSLATE)) {
   1354       1.1    bouyer 		offset = ((offset / sc->bnx_flash_info->page_size) <<
   1355       1.1    bouyer 		    sc->bnx_flash_info->page_bits) +
   1356       1.1    bouyer 		    (offset % sc->bnx_flash_info->page_size);
   1357  1.20.4.2  sborrill 	}
   1358       1.1    bouyer 
   1359       1.1    bouyer 	/*
   1360       1.1    bouyer 	 * Clear the DONE bit separately, set the address to read,
   1361       1.1    bouyer 	 * and issue the read.
   1362       1.1    bouyer 	 */
   1363       1.1    bouyer 	REG_WR(sc, BNX_NVM_COMMAND, BNX_NVM_COMMAND_DONE);
   1364       1.1    bouyer 	REG_WR(sc, BNX_NVM_ADDR, offset & BNX_NVM_ADDR_NVM_ADDR_VALUE);
   1365       1.1    bouyer 	REG_WR(sc, BNX_NVM_COMMAND, cmd);
   1366       1.1    bouyer 
   1367       1.1    bouyer 	/* Wait for completion. */
   1368       1.1    bouyer 	for (i = 0; i < NVRAM_TIMEOUT_COUNT; i++) {
   1369       1.1    bouyer 		u_int32_t val;
   1370       1.1    bouyer 
   1371       1.1    bouyer 		DELAY(5);
   1372       1.1    bouyer 
   1373       1.1    bouyer 		val = REG_RD(sc, BNX_NVM_COMMAND);
   1374       1.1    bouyer 		if (val & BNX_NVM_COMMAND_DONE) {
   1375       1.1    bouyer 			val = REG_RD(sc, BNX_NVM_READ);
   1376       1.1    bouyer 
   1377       1.1    bouyer 			val = bnx_be32toh(val);
   1378       1.1    bouyer 			memcpy(ret_val, &val, 4);
   1379       1.1    bouyer 			break;
   1380       1.1    bouyer 		}
   1381       1.1    bouyer 	}
   1382       1.1    bouyer 
   1383       1.1    bouyer 	/* Check for errors. */
   1384       1.1    bouyer 	if (i >= NVRAM_TIMEOUT_COUNT) {
   1385       1.1    bouyer 		BNX_PRINTF(sc, "%s(%d): Timeout error reading NVRAM at "
   1386       1.1    bouyer 		    "offset 0x%08X!\n", __FILE__, __LINE__, offset);
   1387       1.1    bouyer 		rc = EBUSY;
   1388       1.1    bouyer 	}
   1389       1.1    bouyer 
   1390       1.1    bouyer 	return(rc);
   1391       1.1    bouyer }
   1392       1.1    bouyer 
   1393       1.1    bouyer #ifdef BNX_NVRAM_WRITE_SUPPORT
   1394       1.1    bouyer /****************************************************************************/
   1395       1.1    bouyer /* Write a dword (32 bits) to NVRAM.                                        */
   1396       1.1    bouyer /*                                                                          */
   1397       1.1    bouyer /* Write a 32 bit word to NVRAM.  The caller is assumed to have already     */
   1398       1.1    bouyer /* obtained the NVRAM lock, enabled the controller for NVRAM access, and    */
   1399       1.1    bouyer /* enabled NVRAM write access.                                              */
   1400       1.1    bouyer /*                                                                          */
   1401       1.1    bouyer /* Returns:                                                                 */
   1402       1.1    bouyer /*   0 on success, positive value on failure.                               */
   1403       1.1    bouyer /****************************************************************************/
   1404       1.1    bouyer int
   1405       1.1    bouyer bnx_nvram_write_dword(struct bnx_softc *sc, u_int32_t offset, u_int8_t *val,
   1406       1.1    bouyer     u_int32_t cmd_flags)
   1407       1.1    bouyer {
   1408       1.1    bouyer 	u_int32_t		cmd, val32;
   1409       1.1    bouyer 	int			j;
   1410       1.1    bouyer 
   1411       1.1    bouyer 	/* Build the command word. */
   1412       1.1    bouyer 	cmd = BNX_NVM_COMMAND_DOIT | BNX_NVM_COMMAND_WR | cmd_flags;
   1413       1.1    bouyer 
   1414  1.20.4.2  sborrill 	/* Calculate the offset for buffered flash if translation is used. */
   1415  1.20.4.2  sborrill 	if (ISSET(sc->bnx_flash_info->flags, BNX_NV_TRANSLATE)) {
   1416       1.1    bouyer 		offset = ((offset / sc->bnx_flash_info->page_size) <<
   1417       1.1    bouyer 		    sc->bnx_flash_info->page_bits) +
   1418       1.1    bouyer 		    (offset % sc->bnx_flash_info->page_size);
   1419  1.20.4.2  sborrill 	}
   1420       1.1    bouyer 
   1421       1.1    bouyer 	/*
   1422       1.1    bouyer 	 * Clear the DONE bit separately, convert NVRAM data to big-endian,
   1423       1.1    bouyer 	 * set the NVRAM address to write, and issue the write command
   1424       1.1    bouyer 	 */
   1425       1.1    bouyer 	REG_WR(sc, BNX_NVM_COMMAND, BNX_NVM_COMMAND_DONE);
   1426       1.1    bouyer 	memcpy(&val32, val, 4);
   1427       1.1    bouyer 	val32 = htobe32(val32);
   1428       1.1    bouyer 	REG_WR(sc, BNX_NVM_WRITE, val32);
   1429       1.1    bouyer 	REG_WR(sc, BNX_NVM_ADDR, offset & BNX_NVM_ADDR_NVM_ADDR_VALUE);
   1430       1.1    bouyer 	REG_WR(sc, BNX_NVM_COMMAND, cmd);
   1431       1.1    bouyer 
   1432       1.1    bouyer 	/* Wait for completion. */
   1433       1.1    bouyer 	for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
   1434       1.1    bouyer 		DELAY(5);
   1435       1.1    bouyer 
   1436       1.1    bouyer 		if (REG_RD(sc, BNX_NVM_COMMAND) & BNX_NVM_COMMAND_DONE)
   1437       1.1    bouyer 			break;
   1438       1.1    bouyer 	}
   1439       1.1    bouyer 	if (j >= NVRAM_TIMEOUT_COUNT) {
   1440       1.1    bouyer 		BNX_PRINTF(sc, "%s(%d): Timeout error writing NVRAM at "
   1441       1.1    bouyer 		    "offset 0x%08X\n", __FILE__, __LINE__, offset);
   1442       1.1    bouyer 		return (EBUSY);
   1443       1.1    bouyer 	}
   1444       1.1    bouyer 
   1445       1.1    bouyer 	return (0);
   1446       1.1    bouyer }
   1447       1.1    bouyer #endif /* BNX_NVRAM_WRITE_SUPPORT */
   1448       1.1    bouyer 
   1449       1.1    bouyer /****************************************************************************/
   1450       1.1    bouyer /* Initialize NVRAM access.                                                 */
   1451       1.1    bouyer /*                                                                          */
   1452       1.1    bouyer /* Identify the NVRAM device in use and prepare the NVRAM interface to      */
   1453       1.1    bouyer /* access that device.                                                      */
   1454       1.1    bouyer /*                                                                          */
   1455       1.1    bouyer /* Returns:                                                                 */
   1456       1.1    bouyer /*   0 on success, positive value on failure.                               */
   1457       1.1    bouyer /****************************************************************************/
   1458       1.1    bouyer int
   1459       1.1    bouyer bnx_init_nvram(struct bnx_softc *sc)
   1460       1.1    bouyer {
   1461       1.1    bouyer 	u_int32_t		val;
   1462  1.20.4.2  sborrill 	int			j, entry_count, rc = 0;
   1463       1.1    bouyer 	struct flash_spec	*flash;
   1464       1.1    bouyer 
   1465      1.12     perry 	DBPRINT(sc,BNX_VERBOSE_RESET, "Entering %s()\n", __func__);
   1466       1.1    bouyer 
   1467  1.20.4.2  sborrill 	if (BNX_CHIP_NUM(sc) == BNX_CHIP_NUM_5709) {
   1468  1.20.4.2  sborrill 		sc->bnx_flash_info = &flash_5709;
   1469  1.20.4.2  sborrill 		goto bnx_init_nvram_get_flash_size;
   1470  1.20.4.2  sborrill 	}
   1471  1.20.4.2  sborrill 
   1472       1.1    bouyer 	/* Determine the selected interface. */
   1473       1.1    bouyer 	val = REG_RD(sc, BNX_NVM_CFG1);
   1474       1.1    bouyer 
   1475       1.1    bouyer 	entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
   1476       1.1    bouyer 
   1477       1.1    bouyer 	/*
   1478       1.1    bouyer 	 * Flash reconfiguration is required to support additional
   1479       1.1    bouyer 	 * NVRAM devices not directly supported in hardware.
   1480       1.1    bouyer 	 * Check if the flash interface was reconfigured
   1481       1.1    bouyer 	 * by the bootcode.
   1482       1.1    bouyer 	 */
   1483       1.1    bouyer 
   1484       1.1    bouyer 	if (val & 0x40000000) {
   1485       1.1    bouyer 		/* Flash interface reconfigured by bootcode. */
   1486       1.1    bouyer 
   1487       1.1    bouyer 		DBPRINT(sc,BNX_INFO_LOAD,
   1488       1.1    bouyer 			"bnx_init_nvram(): Flash WAS reconfigured.\n");
   1489       1.1    bouyer 
   1490       1.1    bouyer 		for (j = 0, flash = &flash_table[0]; j < entry_count;
   1491       1.1    bouyer 		     j++, flash++) {
   1492       1.1    bouyer 			if ((val & FLASH_BACKUP_STRAP_MASK) ==
   1493       1.1    bouyer 			    (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
   1494       1.1    bouyer 				sc->bnx_flash_info = flash;
   1495       1.1    bouyer 				break;
   1496       1.1    bouyer 			}
   1497       1.1    bouyer 		}
   1498       1.1    bouyer 	} else {
   1499       1.1    bouyer 		/* Flash interface not yet reconfigured. */
   1500       1.1    bouyer 		u_int32_t mask;
   1501       1.1    bouyer 
   1502       1.1    bouyer 		DBPRINT(sc,BNX_INFO_LOAD,
   1503       1.1    bouyer 			"bnx_init_nvram(): Flash was NOT reconfigured.\n");
   1504       1.1    bouyer 
   1505       1.1    bouyer 		if (val & (1 << 23))
   1506       1.1    bouyer 			mask = FLASH_BACKUP_STRAP_MASK;
   1507       1.1    bouyer 		else
   1508       1.1    bouyer 			mask = FLASH_STRAP_MASK;
   1509       1.1    bouyer 
   1510       1.1    bouyer 		/* Look for the matching NVRAM device configuration data. */
   1511       1.1    bouyer 		for (j = 0, flash = &flash_table[0]; j < entry_count;
   1512       1.1    bouyer 		    j++, flash++) {
   1513       1.1    bouyer 			/* Check if the dev matches any of the known devices. */
   1514       1.1    bouyer 			if ((val & mask) == (flash->strapping & mask)) {
   1515       1.1    bouyer 				/* Found a device match. */
   1516       1.1    bouyer 				sc->bnx_flash_info = flash;
   1517       1.1    bouyer 
   1518       1.1    bouyer 				/* Request access to the flash interface. */
   1519       1.1    bouyer 				if ((rc = bnx_acquire_nvram_lock(sc)) != 0)
   1520       1.1    bouyer 					return (rc);
   1521       1.1    bouyer 
   1522       1.1    bouyer 				/* Reconfigure the flash interface. */
   1523       1.1    bouyer 				bnx_enable_nvram_access(sc);
   1524       1.1    bouyer 				REG_WR(sc, BNX_NVM_CFG1, flash->config1);
   1525       1.1    bouyer 				REG_WR(sc, BNX_NVM_CFG2, flash->config2);
   1526       1.1    bouyer 				REG_WR(sc, BNX_NVM_CFG3, flash->config3);
   1527       1.1    bouyer 				REG_WR(sc, BNX_NVM_WRITE1, flash->write1);
   1528       1.1    bouyer 				bnx_disable_nvram_access(sc);
   1529       1.1    bouyer 				bnx_release_nvram_lock(sc);
   1530       1.1    bouyer 
   1531       1.1    bouyer 				break;
   1532       1.1    bouyer 			}
   1533       1.1    bouyer 		}
   1534       1.1    bouyer 	}
   1535       1.1    bouyer 
   1536       1.1    bouyer 	/* Check if a matching device was found. */
   1537       1.1    bouyer 	if (j == entry_count) {
   1538       1.1    bouyer 		sc->bnx_flash_info = NULL;
   1539       1.1    bouyer 		BNX_PRINTF(sc, "%s(%d): Unknown Flash NVRAM found!\n",
   1540       1.1    bouyer 			__FILE__, __LINE__);
   1541       1.1    bouyer 		rc = ENODEV;
   1542       1.1    bouyer 	}
   1543       1.1    bouyer 
   1544  1.20.4.2  sborrill bnx_init_nvram_get_flash_size:
   1545       1.1    bouyer 	/* Write the flash config data to the shared memory interface. */
   1546       1.1    bouyer 	val = REG_RD_IND(sc, sc->bnx_shmem_base + BNX_SHARED_HW_CFG_CONFIG2);
   1547       1.1    bouyer 	val &= BNX_SHARED_HW_CFG2_NVM_SIZE_MASK;
   1548       1.1    bouyer 	if (val)
   1549       1.1    bouyer 		sc->bnx_flash_size = val;
   1550       1.1    bouyer 	else
   1551       1.1    bouyer 		sc->bnx_flash_size = sc->bnx_flash_info->total_size;
   1552       1.1    bouyer 
   1553       1.1    bouyer 	DBPRINT(sc, BNX_INFO_LOAD, "bnx_init_nvram() flash->total_size = "
   1554       1.1    bouyer 	    "0x%08X\n", sc->bnx_flash_info->total_size);
   1555       1.1    bouyer 
   1556      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Exiting %s()\n", __func__);
   1557       1.1    bouyer 
   1558       1.1    bouyer 	return (rc);
   1559       1.1    bouyer }
   1560       1.1    bouyer 
   1561       1.1    bouyer /****************************************************************************/
   1562       1.1    bouyer /* Read an arbitrary range of data from NVRAM.                              */
   1563       1.1    bouyer /*                                                                          */
   1564       1.1    bouyer /* Prepares the NVRAM interface for access and reads the requested data     */
   1565       1.1    bouyer /* into the supplied buffer.                                                */
   1566       1.1    bouyer /*                                                                          */
   1567       1.1    bouyer /* Returns:                                                                 */
   1568       1.1    bouyer /*   0 on success and the data read, positive value on failure.             */
   1569       1.1    bouyer /****************************************************************************/
   1570       1.1    bouyer int
   1571       1.1    bouyer bnx_nvram_read(struct bnx_softc *sc, u_int32_t offset, u_int8_t *ret_buf,
   1572       1.1    bouyer     int buf_size)
   1573       1.1    bouyer {
   1574       1.1    bouyer 	int			rc = 0;
   1575       1.1    bouyer 	u_int32_t		cmd_flags, offset32, len32, extra;
   1576       1.1    bouyer 
   1577       1.1    bouyer 	if (buf_size == 0)
   1578       1.1    bouyer 		return (0);
   1579       1.1    bouyer 
   1580       1.1    bouyer 	/* Request access to the flash interface. */
   1581       1.1    bouyer 	if ((rc = bnx_acquire_nvram_lock(sc)) != 0)
   1582       1.1    bouyer 		return (rc);
   1583       1.1    bouyer 
   1584       1.1    bouyer 	/* Enable access to flash interface */
   1585       1.1    bouyer 	bnx_enable_nvram_access(sc);
   1586       1.1    bouyer 
   1587       1.1    bouyer 	len32 = buf_size;
   1588       1.1    bouyer 	offset32 = offset;
   1589       1.1    bouyer 	extra = 0;
   1590       1.1    bouyer 
   1591       1.1    bouyer 	cmd_flags = 0;
   1592       1.1    bouyer 
   1593       1.1    bouyer 	if (offset32 & 3) {
   1594       1.1    bouyer 		u_int8_t buf[4];
   1595       1.1    bouyer 		u_int32_t pre_len;
   1596       1.1    bouyer 
   1597       1.1    bouyer 		offset32 &= ~3;
   1598       1.1    bouyer 		pre_len = 4 - (offset & 3);
   1599       1.1    bouyer 
   1600       1.1    bouyer 		if (pre_len >= len32) {
   1601       1.1    bouyer 			pre_len = len32;
   1602       1.1    bouyer 			cmd_flags =
   1603       1.1    bouyer 			    BNX_NVM_COMMAND_FIRST | BNX_NVM_COMMAND_LAST;
   1604       1.1    bouyer 		} else
   1605       1.1    bouyer 			cmd_flags = BNX_NVM_COMMAND_FIRST;
   1606       1.1    bouyer 
   1607       1.1    bouyer 		rc = bnx_nvram_read_dword(sc, offset32, buf, cmd_flags);
   1608       1.1    bouyer 
   1609       1.1    bouyer 		if (rc)
   1610       1.1    bouyer 			return (rc);
   1611       1.1    bouyer 
   1612       1.1    bouyer 		memcpy(ret_buf, buf + (offset & 3), pre_len);
   1613       1.1    bouyer 
   1614       1.1    bouyer 		offset32 += 4;
   1615       1.1    bouyer 		ret_buf += pre_len;
   1616       1.1    bouyer 		len32 -= pre_len;
   1617       1.1    bouyer 	}
   1618       1.1    bouyer 
   1619       1.1    bouyer 	if (len32 & 3) {
   1620       1.1    bouyer 		extra = 4 - (len32 & 3);
   1621       1.1    bouyer 		len32 = (len32 + 4) & ~3;
   1622       1.1    bouyer 	}
   1623       1.1    bouyer 
   1624       1.1    bouyer 	if (len32 == 4) {
   1625       1.1    bouyer 		u_int8_t buf[4];
   1626       1.1    bouyer 
   1627       1.1    bouyer 		if (cmd_flags)
   1628       1.1    bouyer 			cmd_flags = BNX_NVM_COMMAND_LAST;
   1629       1.1    bouyer 		else
   1630       1.1    bouyer 			cmd_flags =
   1631       1.1    bouyer 			    BNX_NVM_COMMAND_FIRST | BNX_NVM_COMMAND_LAST;
   1632       1.1    bouyer 
   1633       1.1    bouyer 		rc = bnx_nvram_read_dword(sc, offset32, buf, cmd_flags);
   1634       1.1    bouyer 
   1635       1.1    bouyer 		memcpy(ret_buf, buf, 4 - extra);
   1636       1.1    bouyer 	} else if (len32 > 0) {
   1637       1.1    bouyer 		u_int8_t buf[4];
   1638       1.1    bouyer 
   1639       1.1    bouyer 		/* Read the first word. */
   1640       1.1    bouyer 		if (cmd_flags)
   1641       1.1    bouyer 			cmd_flags = 0;
   1642       1.1    bouyer 		else
   1643       1.1    bouyer 			cmd_flags = BNX_NVM_COMMAND_FIRST;
   1644       1.1    bouyer 
   1645       1.1    bouyer 		rc = bnx_nvram_read_dword(sc, offset32, ret_buf, cmd_flags);
   1646       1.1    bouyer 
   1647       1.1    bouyer 		/* Advance to the next dword. */
   1648       1.1    bouyer 		offset32 += 4;
   1649       1.1    bouyer 		ret_buf += 4;
   1650       1.1    bouyer 		len32 -= 4;
   1651       1.1    bouyer 
   1652       1.1    bouyer 		while (len32 > 4 && rc == 0) {
   1653       1.1    bouyer 			rc = bnx_nvram_read_dword(sc, offset32, ret_buf, 0);
   1654       1.1    bouyer 
   1655       1.1    bouyer 			/* Advance to the next dword. */
   1656       1.1    bouyer 			offset32 += 4;
   1657       1.1    bouyer 			ret_buf += 4;
   1658       1.1    bouyer 			len32 -= 4;
   1659       1.1    bouyer 		}
   1660       1.1    bouyer 
   1661       1.1    bouyer 		if (rc)
   1662       1.1    bouyer 			return (rc);
   1663       1.1    bouyer 
   1664       1.1    bouyer 		cmd_flags = BNX_NVM_COMMAND_LAST;
   1665       1.1    bouyer 		rc = bnx_nvram_read_dword(sc, offset32, buf, cmd_flags);
   1666       1.1    bouyer 
   1667       1.1    bouyer 		memcpy(ret_buf, buf, 4 - extra);
   1668       1.1    bouyer 	}
   1669       1.1    bouyer 
   1670       1.1    bouyer 	/* Disable access to flash interface and release the lock. */
   1671       1.1    bouyer 	bnx_disable_nvram_access(sc);
   1672       1.1    bouyer 	bnx_release_nvram_lock(sc);
   1673       1.1    bouyer 
   1674       1.1    bouyer 	return (rc);
   1675       1.1    bouyer }
   1676       1.1    bouyer 
   1677       1.1    bouyer #ifdef BNX_NVRAM_WRITE_SUPPORT
   1678       1.1    bouyer /****************************************************************************/
   1679       1.1    bouyer /* Write an arbitrary range of data from NVRAM.                             */
   1680       1.1    bouyer /*                                                                          */
   1681       1.1    bouyer /* Prepares the NVRAM interface for write access and writes the requested   */
   1682       1.1    bouyer /* data from the supplied buffer.  The caller is responsible for            */
   1683       1.1    bouyer /* calculating any appropriate CRCs.                                        */
   1684       1.1    bouyer /*                                                                          */
   1685       1.1    bouyer /* Returns:                                                                 */
   1686       1.1    bouyer /*   0 on success, positive value on failure.                               */
   1687       1.1    bouyer /****************************************************************************/
   1688       1.1    bouyer int
   1689       1.1    bouyer bnx_nvram_write(struct bnx_softc *sc, u_int32_t offset, u_int8_t *data_buf,
   1690       1.1    bouyer     int buf_size)
   1691       1.1    bouyer {
   1692       1.1    bouyer 	u_int32_t		written, offset32, len32;
   1693       1.1    bouyer 	u_int8_t		*buf, start[4], end[4];
   1694       1.1    bouyer 	int			rc = 0;
   1695       1.1    bouyer 	int			align_start, align_end;
   1696       1.1    bouyer 
   1697       1.1    bouyer 	buf = data_buf;
   1698       1.1    bouyer 	offset32 = offset;
   1699       1.1    bouyer 	len32 = buf_size;
   1700       1.1    bouyer 	align_start = align_end = 0;
   1701       1.1    bouyer 
   1702       1.1    bouyer 	if ((align_start = (offset32 & 3))) {
   1703       1.1    bouyer 		offset32 &= ~3;
   1704       1.1    bouyer 		len32 += align_start;
   1705       1.1    bouyer 		if ((rc = bnx_nvram_read(sc, offset32, start, 4)))
   1706       1.1    bouyer 			return (rc);
   1707       1.1    bouyer 	}
   1708       1.1    bouyer 
   1709       1.1    bouyer 	if (len32 & 3) {
   1710       1.1    bouyer 	       	if ((len32 > 4) || !align_start) {
   1711       1.1    bouyer 			align_end = 4 - (len32 & 3);
   1712       1.1    bouyer 			len32 += align_end;
   1713       1.1    bouyer 			if ((rc = bnx_nvram_read(sc, offset32 + len32 - 4,
   1714       1.1    bouyer 			    end, 4))) {
   1715       1.1    bouyer 				return (rc);
   1716       1.1    bouyer 			}
   1717       1.1    bouyer 		}
   1718       1.1    bouyer 	}
   1719       1.1    bouyer 
   1720       1.1    bouyer 	if (align_start || align_end) {
   1721       1.1    bouyer 		buf = malloc(len32, M_DEVBUF, M_NOWAIT);
   1722       1.1    bouyer 		if (buf == 0)
   1723       1.1    bouyer 			return (ENOMEM);
   1724       1.1    bouyer 
   1725       1.1    bouyer 		if (align_start)
   1726       1.1    bouyer 			memcpy(buf, start, 4);
   1727       1.1    bouyer 
   1728       1.1    bouyer 		if (align_end)
   1729       1.1    bouyer 			memcpy(buf + len32 - 4, end, 4);
   1730       1.1    bouyer 
   1731       1.1    bouyer 		memcpy(buf + align_start, data_buf, buf_size);
   1732       1.1    bouyer 	}
   1733       1.1    bouyer 
   1734       1.1    bouyer 	written = 0;
   1735       1.1    bouyer 	while ((written < len32) && (rc == 0)) {
   1736       1.1    bouyer 		u_int32_t page_start, page_end, data_start, data_end;
   1737       1.1    bouyer 		u_int32_t addr, cmd_flags;
   1738       1.1    bouyer 		int i;
   1739       1.1    bouyer 		u_int8_t flash_buffer[264];
   1740       1.1    bouyer 
   1741       1.1    bouyer 	    /* Find the page_start addr */
   1742       1.1    bouyer 		page_start = offset32 + written;
   1743       1.1    bouyer 		page_start -= (page_start % sc->bnx_flash_info->page_size);
   1744       1.1    bouyer 		/* Find the page_end addr */
   1745       1.1    bouyer 		page_end = page_start + sc->bnx_flash_info->page_size;
   1746       1.1    bouyer 		/* Find the data_start addr */
   1747       1.1    bouyer 		data_start = (written == 0) ? offset32 : page_start;
   1748       1.1    bouyer 		/* Find the data_end addr */
   1749       1.1    bouyer 		data_end = (page_end > offset32 + len32) ?
   1750       1.1    bouyer 		    (offset32 + len32) : page_end;
   1751       1.1    bouyer 
   1752       1.1    bouyer 		/* Request access to the flash interface. */
   1753       1.1    bouyer 		if ((rc = bnx_acquire_nvram_lock(sc)) != 0)
   1754       1.1    bouyer 			goto nvram_write_end;
   1755       1.1    bouyer 
   1756       1.1    bouyer 		/* Enable access to flash interface */
   1757       1.1    bouyer 		bnx_enable_nvram_access(sc);
   1758       1.1    bouyer 
   1759       1.1    bouyer 		cmd_flags = BNX_NVM_COMMAND_FIRST;
   1760  1.20.4.2  sborrill 		if (!ISSET(sc->bnx_flash_info->flags, BNX_NV_BUFFERED)) {
   1761       1.1    bouyer 			int j;
   1762       1.1    bouyer 
   1763       1.1    bouyer 			/* Read the whole page into the buffer
   1764       1.1    bouyer 			 * (non-buffer flash only) */
   1765       1.1    bouyer 			for (j = 0; j < sc->bnx_flash_info->page_size; j += 4) {
   1766       1.1    bouyer 				if (j == (sc->bnx_flash_info->page_size - 4))
   1767       1.1    bouyer 					cmd_flags |= BNX_NVM_COMMAND_LAST;
   1768       1.1    bouyer 
   1769       1.1    bouyer 				rc = bnx_nvram_read_dword(sc,
   1770       1.1    bouyer 					page_start + j,
   1771       1.1    bouyer 					&flash_buffer[j],
   1772       1.1    bouyer 					cmd_flags);
   1773       1.1    bouyer 
   1774       1.1    bouyer 				if (rc)
   1775       1.1    bouyer 					goto nvram_write_end;
   1776       1.1    bouyer 
   1777       1.1    bouyer 				cmd_flags = 0;
   1778       1.1    bouyer 			}
   1779       1.1    bouyer 		}
   1780       1.1    bouyer 
   1781       1.1    bouyer 		/* Enable writes to flash interface (unlock write-protect) */
   1782       1.1    bouyer 		if ((rc = bnx_enable_nvram_write(sc)) != 0)
   1783       1.1    bouyer 			goto nvram_write_end;
   1784       1.1    bouyer 
   1785       1.1    bouyer 		/* Erase the page */
   1786       1.1    bouyer 		if ((rc = bnx_nvram_erase_page(sc, page_start)) != 0)
   1787       1.1    bouyer 			goto nvram_write_end;
   1788       1.1    bouyer 
   1789       1.1    bouyer 		/* Re-enable the write again for the actual write */
   1790       1.1    bouyer 		bnx_enable_nvram_write(sc);
   1791       1.1    bouyer 
   1792       1.1    bouyer 		/* Loop to write back the buffer data from page_start to
   1793       1.1    bouyer 		 * data_start */
   1794       1.1    bouyer 		i = 0;
   1795  1.20.4.2  sborrill 		if (!ISSET(sc->bnx_flash_info->flags, BNX_NV_BUFFERED)) {
   1796       1.1    bouyer 			for (addr = page_start; addr < data_start;
   1797       1.1    bouyer 				addr += 4, i += 4) {
   1798       1.1    bouyer 
   1799       1.1    bouyer 				rc = bnx_nvram_write_dword(sc, addr,
   1800       1.1    bouyer 				    &flash_buffer[i], cmd_flags);
   1801       1.1    bouyer 
   1802       1.1    bouyer 				if (rc != 0)
   1803       1.1    bouyer 					goto nvram_write_end;
   1804       1.1    bouyer 
   1805       1.1    bouyer 				cmd_flags = 0;
   1806       1.1    bouyer 			}
   1807       1.1    bouyer 		}
   1808       1.1    bouyer 
   1809       1.1    bouyer 		/* Loop to write the new data from data_start to data_end */
   1810       1.1    bouyer 		for (addr = data_start; addr < data_end; addr += 4, i++) {
   1811       1.1    bouyer 			if ((addr == page_end - 4) ||
   1812  1.20.4.2  sborrill 			    (ISSET(sc->bnx_flash_info->flags, BNX_NV_BUFFERED)
   1813  1.20.4.2  sborrill 			    && (addr == data_end - 4))) {
   1814       1.1    bouyer 
   1815       1.1    bouyer 				cmd_flags |= BNX_NVM_COMMAND_LAST;
   1816       1.1    bouyer 			}
   1817       1.1    bouyer 
   1818       1.1    bouyer 			rc = bnx_nvram_write_dword(sc, addr, buf, cmd_flags);
   1819       1.1    bouyer 
   1820       1.1    bouyer 			if (rc != 0)
   1821       1.1    bouyer 				goto nvram_write_end;
   1822       1.1    bouyer 
   1823       1.1    bouyer 			cmd_flags = 0;
   1824       1.1    bouyer 			buf += 4;
   1825       1.1    bouyer 		}
   1826       1.1    bouyer 
   1827       1.1    bouyer 		/* Loop to write back the buffer data from data_end
   1828       1.1    bouyer 		 * to page_end */
   1829  1.20.4.2  sborrill 		if (!ISSET(sc->bnx_flash_info->flags, BNX_NV_BUFFERED)) {
   1830       1.1    bouyer 			for (addr = data_end; addr < page_end;
   1831       1.1    bouyer 			    addr += 4, i += 4) {
   1832       1.1    bouyer 
   1833       1.1    bouyer 				if (addr == page_end-4)
   1834       1.1    bouyer 					cmd_flags = BNX_NVM_COMMAND_LAST;
   1835       1.1    bouyer 
   1836       1.1    bouyer 				rc = bnx_nvram_write_dword(sc, addr,
   1837       1.1    bouyer 				    &flash_buffer[i], cmd_flags);
   1838       1.1    bouyer 
   1839       1.1    bouyer 				if (rc != 0)
   1840       1.1    bouyer 					goto nvram_write_end;
   1841       1.1    bouyer 
   1842       1.1    bouyer 				cmd_flags = 0;
   1843       1.1    bouyer 			}
   1844       1.1    bouyer 		}
   1845       1.1    bouyer 
   1846       1.1    bouyer 		/* Disable writes to flash interface (lock write-protect) */
   1847       1.1    bouyer 		bnx_disable_nvram_write(sc);
   1848       1.1    bouyer 
   1849       1.1    bouyer 		/* Disable access to flash interface */
   1850       1.1    bouyer 		bnx_disable_nvram_access(sc);
   1851       1.1    bouyer 		bnx_release_nvram_lock(sc);
   1852       1.1    bouyer 
   1853       1.1    bouyer 		/* Increment written */
   1854       1.1    bouyer 		written += data_end - data_start;
   1855       1.1    bouyer 	}
   1856       1.1    bouyer 
   1857       1.1    bouyer nvram_write_end:
   1858       1.1    bouyer 	if (align_start || align_end)
   1859       1.1    bouyer 		free(buf, M_DEVBUF);
   1860       1.1    bouyer 
   1861       1.1    bouyer 	return (rc);
   1862       1.1    bouyer }
   1863       1.1    bouyer #endif /* BNX_NVRAM_WRITE_SUPPORT */
   1864       1.1    bouyer 
   1865       1.1    bouyer /****************************************************************************/
   1866       1.1    bouyer /* Verifies that NVRAM is accessible and contains valid data.               */
   1867       1.1    bouyer /*                                                                          */
   1868       1.1    bouyer /* Reads the configuration data from NVRAM and verifies that the CRC is     */
   1869       1.1    bouyer /* correct.                                                                 */
   1870       1.1    bouyer /*                                                                          */
   1871       1.1    bouyer /* Returns:                                                                 */
   1872       1.1    bouyer /*   0 on success, positive value on failure.                               */
   1873       1.1    bouyer /****************************************************************************/
   1874       1.1    bouyer int
   1875       1.1    bouyer bnx_nvram_test(struct bnx_softc *sc)
   1876       1.1    bouyer {
   1877       1.1    bouyer 	u_int32_t		buf[BNX_NVRAM_SIZE / 4];
   1878       1.1    bouyer 	u_int8_t		*data = (u_int8_t *) buf;
   1879       1.1    bouyer 	int			rc = 0;
   1880       1.1    bouyer 	u_int32_t		magic, csum;
   1881       1.1    bouyer 
   1882       1.1    bouyer 	/*
   1883       1.1    bouyer 	 * Check that the device NVRAM is valid by reading
   1884       1.1    bouyer 	 * the magic value at offset 0.
   1885       1.1    bouyer 	 */
   1886       1.1    bouyer 	if ((rc = bnx_nvram_read(sc, 0, data, 4)) != 0)
   1887       1.1    bouyer 		goto bnx_nvram_test_done;
   1888       1.1    bouyer 
   1889       1.1    bouyer 	magic = bnx_be32toh(buf[0]);
   1890       1.1    bouyer 	if (magic != BNX_NVRAM_MAGIC) {
   1891       1.1    bouyer 		rc = ENODEV;
   1892       1.1    bouyer 		BNX_PRINTF(sc, "%s(%d): Invalid NVRAM magic value! "
   1893       1.1    bouyer 		    "Expected: 0x%08X, Found: 0x%08X\n",
   1894       1.1    bouyer 		    __FILE__, __LINE__, BNX_NVRAM_MAGIC, magic);
   1895       1.1    bouyer 		goto bnx_nvram_test_done;
   1896       1.1    bouyer 	}
   1897       1.1    bouyer 
   1898       1.1    bouyer 	/*
   1899       1.1    bouyer 	 * Verify that the device NVRAM includes valid
   1900       1.1    bouyer 	 * configuration data.
   1901       1.1    bouyer 	 */
   1902       1.1    bouyer 	if ((rc = bnx_nvram_read(sc, 0x100, data, BNX_NVRAM_SIZE)) != 0)
   1903       1.1    bouyer 		goto bnx_nvram_test_done;
   1904       1.1    bouyer 
   1905       1.1    bouyer 	csum = ether_crc32_le(data, 0x100);
   1906       1.1    bouyer 	if (csum != BNX_CRC32_RESIDUAL) {
   1907       1.1    bouyer 		rc = ENODEV;
   1908       1.1    bouyer 		BNX_PRINTF(sc, "%s(%d): Invalid Manufacturing Information "
   1909       1.1    bouyer 		    "NVRAM CRC! Expected: 0x%08X, Found: 0x%08X\n",
   1910       1.1    bouyer 		    __FILE__, __LINE__, BNX_CRC32_RESIDUAL, csum);
   1911       1.1    bouyer 		goto bnx_nvram_test_done;
   1912       1.1    bouyer 	}
   1913       1.1    bouyer 
   1914       1.1    bouyer 	csum = ether_crc32_le(data + 0x100, 0x100);
   1915       1.1    bouyer 	if (csum != BNX_CRC32_RESIDUAL) {
   1916       1.1    bouyer 		BNX_PRINTF(sc, "%s(%d): Invalid Feature Configuration "
   1917       1.1    bouyer 		    "Information NVRAM CRC! Expected: 0x%08X, Found: 08%08X\n",
   1918       1.1    bouyer 		    __FILE__, __LINE__, BNX_CRC32_RESIDUAL, csum);
   1919       1.1    bouyer 		rc = ENODEV;
   1920       1.1    bouyer 	}
   1921       1.1    bouyer 
   1922       1.1    bouyer bnx_nvram_test_done:
   1923       1.1    bouyer 	return (rc);
   1924       1.1    bouyer }
   1925       1.1    bouyer 
   1926       1.1    bouyer /****************************************************************************/
   1927  1.20.4.2  sborrill /* Identifies the current media type of the controller and sets the PHY     */
   1928  1.20.4.2  sborrill /* address.                                                                 */
   1929  1.20.4.2  sborrill /*                                                                          */
   1930  1.20.4.2  sborrill /* Returns:                                                                 */
   1931  1.20.4.2  sborrill /*   Nothing.                                                               */
   1932  1.20.4.2  sborrill /****************************************************************************/
   1933  1.20.4.2  sborrill void
   1934  1.20.4.2  sborrill bnx_get_media(struct bnx_softc *sc)
   1935  1.20.4.2  sborrill {
   1936  1.20.4.2  sborrill 	sc->bnx_phy_addr = 1;
   1937  1.20.4.2  sborrill 
   1938  1.20.4.2  sborrill 	if (BNX_CHIP_NUM(sc) == BNX_CHIP_NUM_5709) {
   1939  1.20.4.2  sborrill 		u_int32_t val = REG_RD(sc, BNX_MISC_DUAL_MEDIA_CTRL);
   1940  1.20.4.2  sborrill 		u_int32_t bond_id = val & BNX_MISC_DUAL_MEDIA_CTRL_BOND_ID;
   1941  1.20.4.2  sborrill 		u_int32_t strap;
   1942  1.20.4.2  sborrill 
   1943  1.20.4.2  sborrill 		/*
   1944  1.20.4.2  sborrill 		 * The BCM5709S is software configurable
   1945  1.20.4.2  sborrill 		 * for Copper or SerDes operation.
   1946  1.20.4.2  sborrill 		 */
   1947  1.20.4.2  sborrill 		if (bond_id == BNX_MISC_DUAL_MEDIA_CTRL_BOND_ID_C) {
   1948  1.20.4.2  sborrill 			DBPRINT(sc, BNX_INFO_LOAD,
   1949  1.20.4.2  sborrill 			    "5709 bonded for copper.\n");
   1950  1.20.4.2  sborrill 			goto bnx_get_media_exit;
   1951  1.20.4.2  sborrill 		} else if (bond_id == BNX_MISC_DUAL_MEDIA_CTRL_BOND_ID_S) {
   1952  1.20.4.2  sborrill 			DBPRINT(sc, BNX_INFO_LOAD,
   1953  1.20.4.2  sborrill 			    "5709 bonded for dual media.\n");
   1954  1.20.4.2  sborrill 			sc->bnx_phy_flags |= BNX_PHY_SERDES_FLAG;
   1955  1.20.4.2  sborrill 			goto bnx_get_media_exit;
   1956  1.20.4.2  sborrill 		}
   1957  1.20.4.2  sborrill 
   1958  1.20.4.2  sborrill 		if (val & BNX_MISC_DUAL_MEDIA_CTRL_STRAP_OVERRIDE)
   1959  1.20.4.2  sborrill 			strap = (val & BNX_MISC_DUAL_MEDIA_CTRL_PHY_CTRL) >> 21;
   1960  1.20.4.2  sborrill 		else {
   1961  1.20.4.2  sborrill 			strap = (val & BNX_MISC_DUAL_MEDIA_CTRL_PHY_CTRL_STRAP)
   1962  1.20.4.2  sborrill 			    >> 8;
   1963  1.20.4.2  sborrill 		}
   1964  1.20.4.2  sborrill 
   1965  1.20.4.2  sborrill 		if (sc->bnx_pa.pa_function == 0) {
   1966  1.20.4.2  sborrill 			switch (strap) {
   1967  1.20.4.2  sborrill 			case 0x4:
   1968  1.20.4.2  sborrill 			case 0x5:
   1969  1.20.4.2  sborrill 			case 0x6:
   1970  1.20.4.2  sborrill 				DBPRINT(sc, BNX_INFO_LOAD,
   1971  1.20.4.2  sborrill 					"BCM5709 s/w configured for SerDes.\n");
   1972  1.20.4.2  sborrill 				sc->bnx_phy_flags |= BNX_PHY_SERDES_FLAG;
   1973  1.20.4.2  sborrill 			default:
   1974  1.20.4.2  sborrill 				DBPRINT(sc, BNX_INFO_LOAD,
   1975  1.20.4.2  sborrill 					"BCM5709 s/w configured for Copper.\n");
   1976  1.20.4.2  sborrill 			}
   1977  1.20.4.2  sborrill 		} else {
   1978  1.20.4.2  sborrill 			switch (strap) {
   1979  1.20.4.2  sborrill 			case 0x1:
   1980  1.20.4.2  sborrill 			case 0x2:
   1981  1.20.4.2  sborrill 			case 0x4:
   1982  1.20.4.2  sborrill 				DBPRINT(sc, BNX_INFO_LOAD,
   1983  1.20.4.2  sborrill 					"BCM5709 s/w configured for SerDes.\n");
   1984  1.20.4.2  sborrill 				sc->bnx_phy_flags |= BNX_PHY_SERDES_FLAG;
   1985  1.20.4.2  sborrill 			default:
   1986  1.20.4.2  sborrill 				DBPRINT(sc, BNX_INFO_LOAD,
   1987  1.20.4.2  sborrill 					"BCM5709 s/w configured for Copper.\n");
   1988  1.20.4.2  sborrill 			}
   1989  1.20.4.2  sborrill 		}
   1990  1.20.4.2  sborrill 
   1991  1.20.4.2  sborrill 	} else if (BNX_CHIP_BOND_ID(sc) & BNX_CHIP_BOND_ID_SERDES_BIT)
   1992  1.20.4.2  sborrill 		sc->bnx_phy_flags |= BNX_PHY_SERDES_FLAG;
   1993  1.20.4.2  sborrill 
   1994  1.20.4.2  sborrill 	if (sc->bnx_phy_flags && BNX_PHY_SERDES_FLAG) {
   1995  1.20.4.2  sborrill 		u_int32_t val;
   1996  1.20.4.2  sborrill 
   1997  1.20.4.2  sborrill 		sc->bnx_flags |= BNX_NO_WOL_FLAG;
   1998  1.20.4.2  sborrill 		if (BNX_CHIP_NUM(sc) != BNX_CHIP_NUM_5706) {
   1999  1.20.4.2  sborrill 			sc->bnx_phy_addr = 2;
   2000  1.20.4.2  sborrill 			val = REG_RD_IND(sc, sc->bnx_shmem_base +
   2001  1.20.4.2  sborrill 				 BNX_SHARED_HW_CFG_CONFIG);
   2002  1.20.4.2  sborrill 			if (val & BNX_SHARED_HW_CFG_PHY_2_5G) {
   2003  1.20.4.2  sborrill 				sc->bnx_phy_flags |= BNX_PHY_2_5G_CAPABLE_FLAG;
   2004  1.20.4.2  sborrill 				DBPRINT(sc, BNX_INFO_LOAD,
   2005  1.20.4.2  sborrill 				    "Found 2.5Gb capable adapter\n");
   2006  1.20.4.2  sborrill 			}
   2007  1.20.4.2  sborrill 		}
   2008  1.20.4.2  sborrill 	} else if ((BNX_CHIP_NUM(sc) == BNX_CHIP_NUM_5706) ||
   2009  1.20.4.2  sborrill 		   (BNX_CHIP_NUM(sc) == BNX_CHIP_NUM_5708))
   2010  1.20.4.2  sborrill 		sc->bnx_phy_flags |= BNX_PHY_CRC_FIX_FLAG;
   2011  1.20.4.2  sborrill 
   2012  1.20.4.2  sborrill bnx_get_media_exit:
   2013  1.20.4.2  sborrill 	DBPRINT(sc, (BNX_INFO_LOAD),
   2014  1.20.4.2  sborrill 		"Using PHY address %d.\n", sc->bnx_phy_addr);
   2015  1.20.4.2  sborrill }
   2016  1.20.4.2  sborrill 
   2017  1.20.4.2  sborrill /****************************************************************************/
   2018       1.1    bouyer /* Free any DMA memory owned by the driver.                                 */
   2019       1.1    bouyer /*                                                                          */
   2020       1.1    bouyer /* Scans through each data structre that requires DMA memory and frees      */
   2021       1.1    bouyer /* the memory if allocated.                                                 */
   2022       1.1    bouyer /*                                                                          */
   2023       1.1    bouyer /* Returns:                                                                 */
   2024       1.1    bouyer /*   Nothing.                                                               */
   2025       1.1    bouyer /****************************************************************************/
   2026       1.1    bouyer void
   2027       1.1    bouyer bnx_dma_free(struct bnx_softc *sc)
   2028       1.1    bouyer {
   2029       1.1    bouyer 	int			i;
   2030       1.1    bouyer 
   2031      1.12     perry 	DBPRINT(sc,BNX_VERBOSE_RESET, "Entering %s()\n", __func__);
   2032       1.1    bouyer 
   2033       1.1    bouyer 	/* Destroy the status block. */
   2034       1.1    bouyer 	if (sc->status_block != NULL && sc->status_map != NULL) {
   2035       1.1    bouyer 		bus_dmamap_unload(sc->bnx_dmatag, sc->status_map);
   2036       1.3  christos 		bus_dmamem_unmap(sc->bnx_dmatag, (void *)sc->status_block,
   2037       1.1    bouyer 		    BNX_STATUS_BLK_SZ);
   2038       1.1    bouyer 		bus_dmamem_free(sc->bnx_dmatag, &sc->status_seg,
   2039       1.1    bouyer 		    sc->status_rseg);
   2040       1.1    bouyer 		bus_dmamap_destroy(sc->bnx_dmatag, sc->status_map);
   2041       1.1    bouyer 		sc->status_block = NULL;
   2042       1.1    bouyer 		sc->status_map = NULL;
   2043       1.1    bouyer 	}
   2044       1.1    bouyer 
   2045       1.1    bouyer 	/* Destroy the statistics block. */
   2046       1.1    bouyer 	if (sc->stats_block != NULL && sc->stats_map != NULL) {
   2047       1.1    bouyer 		bus_dmamap_unload(sc->bnx_dmatag, sc->stats_map);
   2048       1.3  christos 		bus_dmamem_unmap(sc->bnx_dmatag, (void *)sc->stats_block,
   2049       1.1    bouyer 		    BNX_STATS_BLK_SZ);
   2050       1.1    bouyer 		bus_dmamem_free(sc->bnx_dmatag, &sc->stats_seg,
   2051       1.1    bouyer 		    sc->stats_rseg);
   2052       1.1    bouyer 		bus_dmamap_destroy(sc->bnx_dmatag, sc->stats_map);
   2053       1.1    bouyer 		sc->stats_block = NULL;
   2054       1.1    bouyer 		sc->stats_map = NULL;
   2055       1.1    bouyer 	}
   2056       1.1    bouyer 
   2057  1.20.4.2  sborrill 	/* Free, unmap and destroy all context memory pages. */
   2058  1.20.4.2  sborrill 	if (BNX_CHIP_NUM(sc) == BNX_CHIP_NUM_5709) {
   2059  1.20.4.2  sborrill 		for (i = 0; i < sc->ctx_pages; i++) {
   2060  1.20.4.2  sborrill 			if (sc->ctx_block[i] != NULL) {
   2061  1.20.4.2  sborrill 				bus_dmamap_unload(sc->bnx_dmatag,
   2062  1.20.4.2  sborrill 				    sc->ctx_map[i]);
   2063  1.20.4.2  sborrill 				bus_dmamem_unmap(sc->bnx_dmatag,
   2064  1.20.4.2  sborrill 				    (void *)sc->ctx_block[i],
   2065  1.20.4.2  sborrill 				    BCM_PAGE_SIZE);
   2066  1.20.4.2  sborrill 				bus_dmamem_free(sc->bnx_dmatag,
   2067  1.20.4.2  sborrill 				    &sc->ctx_segs[i], sc->ctx_rsegs[i]);
   2068  1.20.4.2  sborrill 				bus_dmamap_destroy(sc->bnx_dmatag,
   2069  1.20.4.2  sborrill 				    sc->ctx_map[i]);
   2070  1.20.4.2  sborrill 				sc->ctx_block[i] = NULL;
   2071  1.20.4.2  sborrill 			}
   2072  1.20.4.2  sborrill 		}
   2073  1.20.4.2  sborrill 	}
   2074  1.20.4.2  sborrill 
   2075       1.1    bouyer 	/* Free, unmap and destroy all TX buffer descriptor chain pages. */
   2076       1.1    bouyer 	for (i = 0; i < TX_PAGES; i++ ) {
   2077       1.1    bouyer 		if (sc->tx_bd_chain[i] != NULL &&
   2078       1.1    bouyer 		    sc->tx_bd_chain_map[i] != NULL) {
   2079       1.1    bouyer 			bus_dmamap_unload(sc->bnx_dmatag,
   2080       1.1    bouyer 			    sc->tx_bd_chain_map[i]);
   2081       1.1    bouyer 			bus_dmamem_unmap(sc->bnx_dmatag,
   2082       1.3  christos 			    (void *)sc->tx_bd_chain[i], BNX_TX_CHAIN_PAGE_SZ);
   2083       1.1    bouyer 			bus_dmamem_free(sc->bnx_dmatag, &sc->tx_bd_chain_seg[i],
   2084       1.1    bouyer 			    sc->tx_bd_chain_rseg[i]);
   2085       1.1    bouyer 			bus_dmamap_destroy(sc->bnx_dmatag,
   2086       1.1    bouyer 			    sc->tx_bd_chain_map[i]);
   2087       1.1    bouyer 			sc->tx_bd_chain[i] = NULL;
   2088       1.1    bouyer 			sc->tx_bd_chain_map[i] = NULL;
   2089       1.1    bouyer 		}
   2090       1.1    bouyer 	}
   2091       1.1    bouyer 
   2092  1.20.4.2  sborrill 	/* Destroy the TX dmamaps. */
   2093  1.20.4.2  sborrill 	/* This isn't necessary since we dont allocate them up front */
   2094       1.1    bouyer 
   2095       1.1    bouyer 	/* Free, unmap and destroy all RX buffer descriptor chain pages. */
   2096       1.1    bouyer 	for (i = 0; i < RX_PAGES; i++ ) {
   2097       1.1    bouyer 		if (sc->rx_bd_chain[i] != NULL &&
   2098       1.1    bouyer 		    sc->rx_bd_chain_map[i] != NULL) {
   2099       1.1    bouyer 			bus_dmamap_unload(sc->bnx_dmatag,
   2100       1.1    bouyer 			    sc->rx_bd_chain_map[i]);
   2101       1.1    bouyer 			bus_dmamem_unmap(sc->bnx_dmatag,
   2102       1.3  christos 			    (void *)sc->rx_bd_chain[i], BNX_RX_CHAIN_PAGE_SZ);
   2103       1.1    bouyer 			bus_dmamem_free(sc->bnx_dmatag, &sc->rx_bd_chain_seg[i],
   2104       1.1    bouyer 			    sc->rx_bd_chain_rseg[i]);
   2105       1.1    bouyer 
   2106       1.1    bouyer 			bus_dmamap_destroy(sc->bnx_dmatag,
   2107       1.1    bouyer 			    sc->rx_bd_chain_map[i]);
   2108       1.1    bouyer 			sc->rx_bd_chain[i] = NULL;
   2109       1.1    bouyer 			sc->rx_bd_chain_map[i] = NULL;
   2110       1.1    bouyer 		}
   2111       1.1    bouyer 	}
   2112       1.1    bouyer 
   2113       1.1    bouyer 	/* Unload and destroy the RX mbuf maps. */
   2114       1.1    bouyer 	for (i = 0; i < TOTAL_RX_BD; i++) {
   2115       1.1    bouyer 		if (sc->rx_mbuf_map[i] != NULL) {
   2116       1.1    bouyer 			bus_dmamap_unload(sc->bnx_dmatag, sc->rx_mbuf_map[i]);
   2117       1.1    bouyer 			bus_dmamap_destroy(sc->bnx_dmatag, sc->rx_mbuf_map[i]);
   2118       1.1    bouyer 		}
   2119       1.1    bouyer 	}
   2120       1.1    bouyer 
   2121      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Exiting %s()\n", __func__);
   2122       1.1    bouyer }
   2123       1.1    bouyer 
   2124       1.1    bouyer /****************************************************************************/
   2125       1.1    bouyer /* Allocate any DMA memory needed by the driver.                            */
   2126       1.1    bouyer /*                                                                          */
   2127       1.1    bouyer /* Allocates DMA memory needed for the various global structures needed by  */
   2128       1.1    bouyer /* hardware.                                                                */
   2129       1.1    bouyer /*                                                                          */
   2130       1.1    bouyer /* Returns:                                                                 */
   2131       1.1    bouyer /*   0 for success, positive value for failure.                             */
   2132       1.1    bouyer /****************************************************************************/
   2133       1.1    bouyer int
   2134       1.1    bouyer bnx_dma_alloc(struct bnx_softc *sc)
   2135       1.1    bouyer {
   2136       1.1    bouyer 	int			i, rc = 0;
   2137       1.1    bouyer 
   2138      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Entering %s()\n", __func__);
   2139       1.1    bouyer 
   2140       1.1    bouyer 	/*
   2141       1.1    bouyer 	 * Allocate DMA memory for the status block, map the memory into DMA
   2142       1.1    bouyer 	 * space, and fetch the physical address of the block.
   2143       1.1    bouyer 	 */
   2144       1.1    bouyer 	if (bus_dmamap_create(sc->bnx_dmatag, BNX_STATUS_BLK_SZ, 1,
   2145       1.1    bouyer 	    BNX_STATUS_BLK_SZ, 0, BUS_DMA_NOWAIT, &sc->status_map)) {
   2146      1.13    dyoung 		aprint_error_dev(sc->bnx_dev,
   2147      1.13    dyoung 		    "Could not create status block DMA map!\n");
   2148       1.1    bouyer 		rc = ENOMEM;
   2149       1.1    bouyer 		goto bnx_dma_alloc_exit;
   2150       1.1    bouyer 	}
   2151       1.1    bouyer 
   2152       1.1    bouyer 	if (bus_dmamem_alloc(sc->bnx_dmatag, BNX_STATUS_BLK_SZ,
   2153       1.1    bouyer 	    BNX_DMA_ALIGN, BNX_DMA_BOUNDARY, &sc->status_seg, 1,
   2154       1.1    bouyer 	    &sc->status_rseg, BUS_DMA_NOWAIT)) {
   2155      1.13    dyoung 		aprint_error_dev(sc->bnx_dev,
   2156      1.13    dyoung 		    "Could not allocate status block DMA memory!\n");
   2157       1.1    bouyer 		rc = ENOMEM;
   2158       1.1    bouyer 		goto bnx_dma_alloc_exit;
   2159       1.1    bouyer 	}
   2160       1.1    bouyer 
   2161       1.1    bouyer 	if (bus_dmamem_map(sc->bnx_dmatag, &sc->status_seg, sc->status_rseg,
   2162       1.3  christos 	    BNX_STATUS_BLK_SZ, (void **)&sc->status_block, BUS_DMA_NOWAIT)) {
   2163      1.13    dyoung 		aprint_error_dev(sc->bnx_dev,
   2164      1.13    dyoung 		    "Could not map status block DMA memory!\n");
   2165       1.1    bouyer 		rc = ENOMEM;
   2166       1.1    bouyer 		goto bnx_dma_alloc_exit;
   2167       1.1    bouyer 	}
   2168       1.1    bouyer 
   2169       1.1    bouyer 	if (bus_dmamap_load(sc->bnx_dmatag, sc->status_map,
   2170       1.1    bouyer 	    sc->status_block, BNX_STATUS_BLK_SZ, NULL, BUS_DMA_NOWAIT)) {
   2171      1.13    dyoung 		aprint_error_dev(sc->bnx_dev,
   2172      1.13    dyoung 		    "Could not load status block DMA memory!\n");
   2173       1.1    bouyer 		rc = ENOMEM;
   2174       1.1    bouyer 		goto bnx_dma_alloc_exit;
   2175       1.1    bouyer 	}
   2176       1.1    bouyer 
   2177       1.1    bouyer 	sc->status_block_paddr = sc->status_map->dm_segs[0].ds_addr;
   2178       1.1    bouyer 	bzero(sc->status_block, BNX_STATUS_BLK_SZ);
   2179       1.1    bouyer 
   2180       1.1    bouyer 	/* DRC - Fix for 64 bit addresses. */
   2181       1.1    bouyer 	DBPRINT(sc, BNX_INFO, "status_block_paddr = 0x%08X\n",
   2182       1.1    bouyer 		(u_int32_t) sc->status_block_paddr);
   2183       1.1    bouyer 
   2184  1.20.4.2  sborrill 	/* BCM5709 uses host memory as cache for context memory. */
   2185  1.20.4.2  sborrill 	if (BNX_CHIP_NUM(sc) == BNX_CHIP_NUM_5709) {
   2186  1.20.4.2  sborrill 		sc->ctx_pages = 0x2000 / BCM_PAGE_SIZE;
   2187  1.20.4.2  sborrill 		if (sc->ctx_pages == 0)
   2188  1.20.4.2  sborrill 			sc->ctx_pages = 1;
   2189  1.20.4.2  sborrill 		if (sc->ctx_pages > 4) /* XXX */
   2190  1.20.4.2  sborrill 			sc->ctx_pages = 4;
   2191  1.20.4.2  sborrill 
   2192  1.20.4.2  sborrill 		DBRUNIF((sc->ctx_pages > 512),
   2193  1.20.4.2  sborrill 			BNX_PRINTF(sc, "%s(%d): Too many CTX pages! %d > 512\n",
   2194  1.20.4.2  sborrill 				__FILE__, __LINE__, sc->ctx_pages));
   2195  1.20.4.2  sborrill 
   2196  1.20.4.2  sborrill 
   2197  1.20.4.2  sborrill 		for (i = 0; i < sc->ctx_pages; i++) {
   2198  1.20.4.2  sborrill 			if (bus_dmamap_create(sc->bnx_dmatag, BCM_PAGE_SIZE,
   2199  1.20.4.2  sborrill 			    1, BCM_PAGE_SIZE, BNX_DMA_BOUNDARY,
   2200  1.20.4.2  sborrill 			    BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
   2201  1.20.4.2  sborrill 			    &sc->ctx_map[i]) != 0) {
   2202  1.20.4.2  sborrill 				rc = ENOMEM;
   2203  1.20.4.2  sborrill 				goto bnx_dma_alloc_exit;
   2204  1.20.4.2  sborrill 			}
   2205  1.20.4.2  sborrill 
   2206  1.20.4.2  sborrill 			if (bus_dmamem_alloc(sc->bnx_dmatag, BCM_PAGE_SIZE,
   2207  1.20.4.2  sborrill 			    BCM_PAGE_SIZE, BNX_DMA_BOUNDARY, &sc->ctx_segs[i],
   2208  1.20.4.2  sborrill 			    1, &sc->ctx_rsegs[i], BUS_DMA_NOWAIT) != 0) {
   2209  1.20.4.2  sborrill 				rc = ENOMEM;
   2210  1.20.4.2  sborrill 				goto bnx_dma_alloc_exit;
   2211  1.20.4.2  sborrill 			}
   2212  1.20.4.2  sborrill 
   2213  1.20.4.2  sborrill 			if (bus_dmamem_map(sc->bnx_dmatag, &sc->ctx_segs[i],
   2214  1.20.4.2  sborrill 			    sc->ctx_rsegs[i], BCM_PAGE_SIZE,
   2215  1.20.4.2  sborrill 			    &sc->ctx_block[i], BUS_DMA_NOWAIT) != 0) {
   2216  1.20.4.2  sborrill 				rc = ENOMEM;
   2217  1.20.4.2  sborrill 				goto bnx_dma_alloc_exit;
   2218  1.20.4.2  sborrill 			}
   2219  1.20.4.2  sborrill 
   2220  1.20.4.2  sborrill 			if (bus_dmamap_load(sc->bnx_dmatag, sc->ctx_map[i],
   2221  1.20.4.2  sborrill 			    sc->ctx_block[i], BCM_PAGE_SIZE, NULL,
   2222  1.20.4.2  sborrill 			    BUS_DMA_NOWAIT) != 0) {
   2223  1.20.4.2  sborrill 				rc = ENOMEM;
   2224  1.20.4.2  sborrill 				goto bnx_dma_alloc_exit;
   2225  1.20.4.2  sborrill 			}
   2226  1.20.4.2  sborrill 
   2227  1.20.4.2  sborrill 			bzero(sc->ctx_block[i], BCM_PAGE_SIZE);
   2228  1.20.4.2  sborrill 		}
   2229  1.20.4.2  sborrill 	}
   2230  1.20.4.2  sborrill 
   2231       1.1    bouyer 	/*
   2232       1.1    bouyer 	 * Allocate DMA memory for the statistics block, map the memory into
   2233       1.1    bouyer 	 * DMA space, and fetch the physical address of the block.
   2234       1.1    bouyer 	 */
   2235       1.1    bouyer 	if (bus_dmamap_create(sc->bnx_dmatag, BNX_STATS_BLK_SZ, 1,
   2236       1.1    bouyer 	    BNX_STATS_BLK_SZ, 0, BUS_DMA_NOWAIT, &sc->stats_map)) {
   2237      1.13    dyoung 		aprint_error_dev(sc->bnx_dev,
   2238      1.13    dyoung 		    "Could not create stats block DMA map!\n");
   2239       1.1    bouyer 		rc = ENOMEM;
   2240       1.1    bouyer 		goto bnx_dma_alloc_exit;
   2241       1.1    bouyer 	}
   2242       1.1    bouyer 
   2243       1.1    bouyer 	if (bus_dmamem_alloc(sc->bnx_dmatag, BNX_STATS_BLK_SZ,
   2244       1.1    bouyer 	    BNX_DMA_ALIGN, BNX_DMA_BOUNDARY, &sc->stats_seg, 1,
   2245       1.1    bouyer 	    &sc->stats_rseg, BUS_DMA_NOWAIT)) {
   2246      1.13    dyoung 		aprint_error_dev(sc->bnx_dev,
   2247      1.13    dyoung 		    "Could not allocate stats block DMA memory!\n");
   2248       1.1    bouyer 		rc = ENOMEM;
   2249       1.1    bouyer 		goto bnx_dma_alloc_exit;
   2250       1.1    bouyer 	}
   2251       1.1    bouyer 
   2252       1.1    bouyer 	if (bus_dmamem_map(sc->bnx_dmatag, &sc->stats_seg, sc->stats_rseg,
   2253       1.3  christos 	    BNX_STATS_BLK_SZ, (void **)&sc->stats_block, BUS_DMA_NOWAIT)) {
   2254      1.13    dyoung 		aprint_error_dev(sc->bnx_dev,
   2255      1.13    dyoung 		    "Could not map stats block DMA memory!\n");
   2256       1.1    bouyer 		rc = ENOMEM;
   2257       1.1    bouyer 		goto bnx_dma_alloc_exit;
   2258       1.1    bouyer 	}
   2259       1.1    bouyer 
   2260       1.1    bouyer 	if (bus_dmamap_load(sc->bnx_dmatag, sc->stats_map,
   2261       1.1    bouyer 	    sc->stats_block, BNX_STATS_BLK_SZ, NULL, BUS_DMA_NOWAIT)) {
   2262      1.13    dyoung 		aprint_error_dev(sc->bnx_dev,
   2263      1.13    dyoung 		    "Could not load status block DMA memory!\n");
   2264       1.1    bouyer 		rc = ENOMEM;
   2265       1.1    bouyer 		goto bnx_dma_alloc_exit;
   2266       1.1    bouyer 	}
   2267       1.1    bouyer 
   2268       1.1    bouyer 	sc->stats_block_paddr = sc->stats_map->dm_segs[0].ds_addr;
   2269       1.1    bouyer 	bzero(sc->stats_block, BNX_STATS_BLK_SZ);
   2270       1.1    bouyer 
   2271       1.1    bouyer 	/* DRC - Fix for 64 bit address. */
   2272       1.1    bouyer 	DBPRINT(sc,BNX_INFO, "stats_block_paddr = 0x%08X\n",
   2273       1.1    bouyer 	    (u_int32_t) sc->stats_block_paddr);
   2274       1.1    bouyer 
   2275       1.1    bouyer 	/*
   2276       1.1    bouyer 	 * Allocate DMA memory for the TX buffer descriptor chain,
   2277       1.1    bouyer 	 * and fetch the physical address of the block.
   2278       1.1    bouyer 	 */
   2279       1.1    bouyer 	for (i = 0; i < TX_PAGES; i++) {
   2280       1.1    bouyer 		if (bus_dmamap_create(sc->bnx_dmatag, BNX_TX_CHAIN_PAGE_SZ, 1,
   2281       1.1    bouyer 		    BNX_TX_CHAIN_PAGE_SZ, 0, BUS_DMA_NOWAIT,
   2282       1.1    bouyer 		    &sc->tx_bd_chain_map[i])) {
   2283      1.13    dyoung 			aprint_error_dev(sc->bnx_dev,
   2284      1.13    dyoung 			    "Could not create Tx desc %d DMA map!\n", i);
   2285       1.1    bouyer 			rc = ENOMEM;
   2286       1.1    bouyer 			goto bnx_dma_alloc_exit;
   2287       1.1    bouyer 		}
   2288       1.1    bouyer 
   2289       1.1    bouyer 		if (bus_dmamem_alloc(sc->bnx_dmatag, BNX_TX_CHAIN_PAGE_SZ,
   2290       1.1    bouyer 		    BCM_PAGE_SIZE, BNX_DMA_BOUNDARY, &sc->tx_bd_chain_seg[i], 1,
   2291       1.1    bouyer 		    &sc->tx_bd_chain_rseg[i], BUS_DMA_NOWAIT)) {
   2292      1.13    dyoung 			aprint_error_dev(sc->bnx_dev,
   2293      1.13    dyoung 			    "Could not allocate TX desc %d DMA memory!\n",
   2294      1.13    dyoung 			    i);
   2295       1.1    bouyer 			rc = ENOMEM;
   2296       1.1    bouyer 			goto bnx_dma_alloc_exit;
   2297       1.1    bouyer 		}
   2298       1.1    bouyer 
   2299       1.1    bouyer 		if (bus_dmamem_map(sc->bnx_dmatag, &sc->tx_bd_chain_seg[i],
   2300       1.1    bouyer 		    sc->tx_bd_chain_rseg[i], BNX_TX_CHAIN_PAGE_SZ,
   2301       1.3  christos 		    (void **)&sc->tx_bd_chain[i], BUS_DMA_NOWAIT)) {
   2302      1.13    dyoung 			aprint_error_dev(sc->bnx_dev,
   2303      1.13    dyoung 			    "Could not map TX desc %d DMA memory!\n", i);
   2304       1.1    bouyer 			rc = ENOMEM;
   2305       1.1    bouyer 			goto bnx_dma_alloc_exit;
   2306       1.1    bouyer 		}
   2307       1.1    bouyer 
   2308       1.1    bouyer 		if (bus_dmamap_load(sc->bnx_dmatag, sc->tx_bd_chain_map[i],
   2309       1.3  christos 		    (void *)sc->tx_bd_chain[i], BNX_TX_CHAIN_PAGE_SZ, NULL,
   2310       1.1    bouyer 		    BUS_DMA_NOWAIT)) {
   2311      1.13    dyoung 			aprint_error_dev(sc->bnx_dev,
   2312      1.13    dyoung 			    "Could not load TX desc %d DMA memory!\n", i);
   2313       1.1    bouyer 			rc = ENOMEM;
   2314       1.1    bouyer 			goto bnx_dma_alloc_exit;
   2315       1.1    bouyer 		}
   2316       1.1    bouyer 
   2317       1.1    bouyer 		sc->tx_bd_chain_paddr[i] =
   2318       1.1    bouyer 		    sc->tx_bd_chain_map[i]->dm_segs[0].ds_addr;
   2319       1.1    bouyer 
   2320       1.1    bouyer 		/* DRC - Fix for 64 bit systems. */
   2321       1.1    bouyer 		DBPRINT(sc, BNX_INFO, "tx_bd_chain_paddr[%d] = 0x%08X\n",
   2322       1.1    bouyer 		    i, (u_int32_t) sc->tx_bd_chain_paddr[i]);
   2323       1.1    bouyer 	}
   2324       1.1    bouyer 
   2325       1.1    bouyer 	/*
   2326  1.20.4.2  sborrill 	 * Create lists to hold TX mbufs.
   2327       1.1    bouyer 	 */
   2328  1.20.4.2  sborrill 	TAILQ_INIT(&sc->tx_free_pkts);
   2329  1.20.4.2  sborrill 	TAILQ_INIT(&sc->tx_used_pkts);
   2330  1.20.4.2  sborrill 	sc->tx_pkt_count = 0;
   2331  1.20.4.2  sborrill 	mutex_init(&sc->tx_pkt_mtx, MUTEX_DEFAULT, IPL_NET);
   2332       1.1    bouyer 
   2333       1.1    bouyer 	/*
   2334       1.1    bouyer 	 * Allocate DMA memory for the Rx buffer descriptor chain,
   2335       1.1    bouyer 	 * and fetch the physical address of the block.
   2336       1.1    bouyer 	 */
   2337       1.1    bouyer 	for (i = 0; i < RX_PAGES; i++) {
   2338       1.1    bouyer 		if (bus_dmamap_create(sc->bnx_dmatag, BNX_RX_CHAIN_PAGE_SZ, 1,
   2339       1.1    bouyer 		    BNX_RX_CHAIN_PAGE_SZ, 0, BUS_DMA_NOWAIT,
   2340       1.1    bouyer 		    &sc->rx_bd_chain_map[i])) {
   2341      1.13    dyoung 			aprint_error_dev(sc->bnx_dev,
   2342      1.13    dyoung 			    "Could not create Rx desc %d DMA map!\n", i);
   2343       1.1    bouyer 			rc = ENOMEM;
   2344       1.1    bouyer 			goto bnx_dma_alloc_exit;
   2345       1.1    bouyer 		}
   2346       1.1    bouyer 
   2347       1.1    bouyer 		if (bus_dmamem_alloc(sc->bnx_dmatag, BNX_RX_CHAIN_PAGE_SZ,
   2348       1.1    bouyer 		    BCM_PAGE_SIZE, BNX_DMA_BOUNDARY, &sc->rx_bd_chain_seg[i], 1,
   2349       1.1    bouyer 		    &sc->rx_bd_chain_rseg[i], BUS_DMA_NOWAIT)) {
   2350      1.13    dyoung 			aprint_error_dev(sc->bnx_dev,
   2351      1.13    dyoung 			    "Could not allocate Rx desc %d DMA memory!\n", i);
   2352       1.1    bouyer 			rc = ENOMEM;
   2353       1.1    bouyer 			goto bnx_dma_alloc_exit;
   2354       1.1    bouyer 		}
   2355       1.1    bouyer 
   2356       1.1    bouyer 		if (bus_dmamem_map(sc->bnx_dmatag, &sc->rx_bd_chain_seg[i],
   2357       1.1    bouyer 		    sc->rx_bd_chain_rseg[i], BNX_RX_CHAIN_PAGE_SZ,
   2358       1.3  christos 		    (void **)&sc->rx_bd_chain[i], BUS_DMA_NOWAIT)) {
   2359      1.13    dyoung 			aprint_error_dev(sc->bnx_dev,
   2360      1.13    dyoung 			    "Could not map Rx desc %d DMA memory!\n", i);
   2361       1.1    bouyer 			rc = ENOMEM;
   2362       1.1    bouyer 			goto bnx_dma_alloc_exit;
   2363       1.1    bouyer 		}
   2364       1.1    bouyer 
   2365       1.1    bouyer 		if (bus_dmamap_load(sc->bnx_dmatag, sc->rx_bd_chain_map[i],
   2366       1.3  christos 		    (void *)sc->rx_bd_chain[i], BNX_RX_CHAIN_PAGE_SZ, NULL,
   2367       1.1    bouyer 		    BUS_DMA_NOWAIT)) {
   2368      1.13    dyoung 			aprint_error_dev(sc->bnx_dev,
   2369      1.13    dyoung 			    "Could not load Rx desc %d DMA memory!\n", i);
   2370       1.1    bouyer 			rc = ENOMEM;
   2371       1.1    bouyer 			goto bnx_dma_alloc_exit;
   2372       1.1    bouyer 		}
   2373       1.1    bouyer 
   2374       1.1    bouyer 		bzero(sc->rx_bd_chain[i], BNX_RX_CHAIN_PAGE_SZ);
   2375       1.1    bouyer 		sc->rx_bd_chain_paddr[i] =
   2376       1.1    bouyer 		    sc->rx_bd_chain_map[i]->dm_segs[0].ds_addr;
   2377       1.1    bouyer 
   2378       1.1    bouyer 		/* DRC - Fix for 64 bit systems. */
   2379       1.1    bouyer 		DBPRINT(sc, BNX_INFO, "rx_bd_chain_paddr[%d] = 0x%08X\n",
   2380       1.1    bouyer 		    i, (u_int32_t) sc->rx_bd_chain_paddr[i]);
   2381       1.1    bouyer 		bus_dmamap_sync(sc->bnx_dmatag, sc->rx_bd_chain_map[i],
   2382       1.1    bouyer 		    0, BNX_RX_CHAIN_PAGE_SZ,
   2383       1.1    bouyer 		    BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
   2384       1.1    bouyer 	}
   2385       1.1    bouyer 
   2386       1.1    bouyer 	/*
   2387       1.1    bouyer 	 * Create DMA maps for the Rx buffer mbufs.
   2388       1.1    bouyer 	 */
   2389       1.1    bouyer 	for (i = 0; i < TOTAL_RX_BD; i++) {
   2390       1.1    bouyer 		if (bus_dmamap_create(sc->bnx_dmatag, BNX_MAX_MRU,
   2391       1.1    bouyer 		    BNX_MAX_SEGMENTS, BNX_MAX_MRU, 0, BUS_DMA_NOWAIT,
   2392       1.1    bouyer 		    &sc->rx_mbuf_map[i])) {
   2393      1.13    dyoung 			aprint_error_dev(sc->bnx_dev,
   2394      1.13    dyoung 			    "Could not create Rx mbuf %d DMA map!\n", i);
   2395       1.1    bouyer 			rc = ENOMEM;
   2396       1.1    bouyer 			goto bnx_dma_alloc_exit;
   2397       1.1    bouyer 		}
   2398       1.1    bouyer 	}
   2399       1.1    bouyer 
   2400       1.1    bouyer  bnx_dma_alloc_exit:
   2401      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Exiting %s()\n", __func__);
   2402       1.1    bouyer 
   2403       1.1    bouyer 	return(rc);
   2404       1.1    bouyer }
   2405       1.1    bouyer 
   2406       1.1    bouyer /****************************************************************************/
   2407       1.1    bouyer /* Release all resources used by the driver.                                */
   2408       1.1    bouyer /*                                                                          */
   2409       1.1    bouyer /* Releases all resources acquired by the driver including interrupts,      */
   2410       1.1    bouyer /* interrupt handler, interfaces, mutexes, and DMA memory.                  */
   2411       1.1    bouyer /*                                                                          */
   2412       1.1    bouyer /* Returns:                                                                 */
   2413       1.1    bouyer /*   Nothing.                                                               */
   2414       1.1    bouyer /****************************************************************************/
   2415       1.1    bouyer void
   2416       1.1    bouyer bnx_release_resources(struct bnx_softc *sc)
   2417       1.1    bouyer {
   2418      1.13    dyoung 	int i;
   2419       1.1    bouyer 	struct pci_attach_args	*pa = &(sc->bnx_pa);
   2420       1.1    bouyer 
   2421      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Entering %s()\n", __func__);
   2422       1.1    bouyer 
   2423       1.1    bouyer 	bnx_dma_free(sc);
   2424       1.1    bouyer 
   2425       1.1    bouyer 	if (sc->bnx_intrhand != NULL)
   2426       1.1    bouyer 		pci_intr_disestablish(pa->pa_pc, sc->bnx_intrhand);
   2427       1.1    bouyer 
   2428       1.1    bouyer 	if (sc->bnx_size)
   2429       1.1    bouyer 		bus_space_unmap(sc->bnx_btag, sc->bnx_bhandle, sc->bnx_size);
   2430       1.1    bouyer 
   2431      1.13    dyoung 	for (i = 0; i < TOTAL_RX_BD; i++)
   2432      1.19    mhitch 		if (sc->rx_mbuf_map[i])
   2433      1.19    mhitch 			bus_dmamap_destroy(sc->bnx_dmatag, sc->rx_mbuf_map[i]);
   2434      1.13    dyoung 
   2435      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Exiting %s()\n", __func__);
   2436       1.1    bouyer }
   2437       1.1    bouyer 
   2438       1.1    bouyer /****************************************************************************/
   2439       1.1    bouyer /* Firmware synchronization.                                                */
   2440       1.1    bouyer /*                                                                          */
   2441       1.1    bouyer /* Before performing certain events such as a chip reset, synchronize with  */
   2442       1.1    bouyer /* the firmware first.                                                      */
   2443       1.1    bouyer /*                                                                          */
   2444       1.1    bouyer /* Returns:                                                                 */
   2445       1.1    bouyer /*   0 for success, positive value for failure.                             */
   2446       1.1    bouyer /****************************************************************************/
   2447       1.1    bouyer int
   2448       1.1    bouyer bnx_fw_sync(struct bnx_softc *sc, u_int32_t msg_data)
   2449       1.1    bouyer {
   2450       1.1    bouyer 	int			i, rc = 0;
   2451       1.1    bouyer 	u_int32_t		val;
   2452       1.1    bouyer 
   2453       1.1    bouyer 	/* Don't waste any time if we've timed out before. */
   2454       1.1    bouyer 	if (sc->bnx_fw_timed_out) {
   2455       1.1    bouyer 		rc = EBUSY;
   2456       1.1    bouyer 		goto bnx_fw_sync_exit;
   2457       1.1    bouyer 	}
   2458       1.1    bouyer 
   2459       1.1    bouyer 	/* Increment the message sequence number. */
   2460       1.1    bouyer 	sc->bnx_fw_wr_seq++;
   2461       1.1    bouyer 	msg_data |= sc->bnx_fw_wr_seq;
   2462       1.1    bouyer 
   2463       1.1    bouyer  	DBPRINT(sc, BNX_VERBOSE, "bnx_fw_sync(): msg_data = 0x%08X\n",
   2464       1.1    bouyer 	    msg_data);
   2465       1.1    bouyer 
   2466       1.1    bouyer 	/* Send the message to the bootcode driver mailbox. */
   2467       1.1    bouyer 	REG_WR_IND(sc, sc->bnx_shmem_base + BNX_DRV_MB, msg_data);
   2468       1.1    bouyer 
   2469       1.1    bouyer 	/* Wait for the bootcode to acknowledge the message. */
   2470       1.1    bouyer 	for (i = 0; i < FW_ACK_TIME_OUT_MS; i++) {
   2471       1.1    bouyer 		/* Check for a response in the bootcode firmware mailbox. */
   2472       1.1    bouyer 		val = REG_RD_IND(sc, sc->bnx_shmem_base + BNX_FW_MB);
   2473       1.1    bouyer 		if ((val & BNX_FW_MSG_ACK) == (msg_data & BNX_DRV_MSG_SEQ))
   2474       1.1    bouyer 			break;
   2475       1.1    bouyer 		DELAY(1000);
   2476       1.1    bouyer 	}
   2477       1.1    bouyer 
   2478       1.1    bouyer 	/* If we've timed out, tell the bootcode that we've stopped waiting. */
   2479       1.1    bouyer 	if (((val & BNX_FW_MSG_ACK) != (msg_data & BNX_DRV_MSG_SEQ)) &&
   2480       1.1    bouyer 		((msg_data & BNX_DRV_MSG_DATA) != BNX_DRV_MSG_DATA_WAIT0)) {
   2481       1.1    bouyer 		BNX_PRINTF(sc, "%s(%d): Firmware synchronization timeout! "
   2482       1.1    bouyer 		    "msg_data = 0x%08X\n", __FILE__, __LINE__, msg_data);
   2483       1.1    bouyer 
   2484       1.1    bouyer 		msg_data &= ~BNX_DRV_MSG_CODE;
   2485       1.1    bouyer 		msg_data |= BNX_DRV_MSG_CODE_FW_TIMEOUT;
   2486       1.1    bouyer 
   2487       1.1    bouyer 		REG_WR_IND(sc, sc->bnx_shmem_base + BNX_DRV_MB, msg_data);
   2488       1.1    bouyer 
   2489       1.1    bouyer 		sc->bnx_fw_timed_out = 1;
   2490       1.1    bouyer 		rc = EBUSY;
   2491       1.1    bouyer 	}
   2492       1.1    bouyer 
   2493       1.1    bouyer bnx_fw_sync_exit:
   2494       1.1    bouyer 	return (rc);
   2495       1.1    bouyer }
   2496       1.1    bouyer 
   2497       1.1    bouyer /****************************************************************************/
   2498       1.1    bouyer /* Load Receive Virtual 2 Physical (RV2P) processor firmware.               */
   2499       1.1    bouyer /*                                                                          */
   2500       1.1    bouyer /* Returns:                                                                 */
   2501       1.1    bouyer /*   Nothing.                                                               */
   2502       1.1    bouyer /****************************************************************************/
   2503       1.1    bouyer void
   2504       1.1    bouyer bnx_load_rv2p_fw(struct bnx_softc *sc, u_int32_t *rv2p_code,
   2505       1.1    bouyer     u_int32_t rv2p_code_len, u_int32_t rv2p_proc)
   2506       1.1    bouyer {
   2507       1.1    bouyer 	int			i;
   2508       1.1    bouyer 	u_int32_t		val;
   2509       1.1    bouyer 
   2510  1.20.4.2  sborrill 	/* Set the page size used by RV2P. */
   2511  1.20.4.2  sborrill 	if (rv2p_proc == RV2P_PROC2) {
   2512  1.20.4.2  sborrill 		BNX_RV2P_PROC2_CHG_MAX_BD_PAGE(rv2p_code,
   2513  1.20.4.2  sborrill 		    USABLE_RX_BD_PER_PAGE);
   2514  1.20.4.2  sborrill 	}
   2515  1.20.4.2  sborrill 
   2516       1.1    bouyer 	for (i = 0; i < rv2p_code_len; i += 8) {
   2517       1.1    bouyer 		REG_WR(sc, BNX_RV2P_INSTR_HIGH, *rv2p_code);
   2518       1.1    bouyer 		rv2p_code++;
   2519       1.1    bouyer 		REG_WR(sc, BNX_RV2P_INSTR_LOW, *rv2p_code);
   2520       1.1    bouyer 		rv2p_code++;
   2521       1.1    bouyer 
   2522       1.1    bouyer 		if (rv2p_proc == RV2P_PROC1) {
   2523       1.1    bouyer 			val = (i / 8) | BNX_RV2P_PROC1_ADDR_CMD_RDWR;
   2524       1.1    bouyer 			REG_WR(sc, BNX_RV2P_PROC1_ADDR_CMD, val);
   2525  1.20.4.2  sborrill 		} else {
   2526       1.1    bouyer 			val = (i / 8) | BNX_RV2P_PROC2_ADDR_CMD_RDWR;
   2527       1.1    bouyer 			REG_WR(sc, BNX_RV2P_PROC2_ADDR_CMD, val);
   2528       1.1    bouyer 		}
   2529       1.1    bouyer 	}
   2530       1.1    bouyer 
   2531       1.1    bouyer 	/* Reset the processor, un-stall is done later. */
   2532       1.1    bouyer 	if (rv2p_proc == RV2P_PROC1)
   2533       1.1    bouyer 		REG_WR(sc, BNX_RV2P_COMMAND, BNX_RV2P_COMMAND_PROC1_RESET);
   2534       1.1    bouyer 	else
   2535       1.1    bouyer 		REG_WR(sc, BNX_RV2P_COMMAND, BNX_RV2P_COMMAND_PROC2_RESET);
   2536       1.1    bouyer }
   2537       1.1    bouyer 
   2538       1.1    bouyer /****************************************************************************/
   2539       1.1    bouyer /* Load RISC processor firmware.                                            */
   2540       1.1    bouyer /*                                                                          */
   2541       1.1    bouyer /* Loads firmware from the file if_bnxfw.h into the scratchpad memory       */
   2542       1.1    bouyer /* associated with a particular processor.                                  */
   2543       1.1    bouyer /*                                                                          */
   2544       1.1    bouyer /* Returns:                                                                 */
   2545       1.1    bouyer /*   Nothing.                                                               */
   2546       1.1    bouyer /****************************************************************************/
   2547       1.1    bouyer void
   2548       1.1    bouyer bnx_load_cpu_fw(struct bnx_softc *sc, struct cpu_reg *cpu_reg,
   2549       1.1    bouyer     struct fw_info *fw)
   2550       1.1    bouyer {
   2551       1.1    bouyer 	u_int32_t		offset;
   2552       1.1    bouyer 	u_int32_t		val;
   2553       1.1    bouyer 
   2554       1.1    bouyer 	/* Halt the CPU. */
   2555       1.1    bouyer 	val = REG_RD_IND(sc, cpu_reg->mode);
   2556       1.1    bouyer 	val |= cpu_reg->mode_value_halt;
   2557       1.1    bouyer 	REG_WR_IND(sc, cpu_reg->mode, val);
   2558       1.1    bouyer 	REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
   2559       1.1    bouyer 
   2560       1.1    bouyer 	/* Load the Text area. */
   2561       1.1    bouyer 	offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
   2562       1.1    bouyer 	if (fw->text) {
   2563       1.1    bouyer 		int j;
   2564       1.1    bouyer 
   2565       1.1    bouyer 		for (j = 0; j < (fw->text_len / 4); j++, offset += 4)
   2566       1.1    bouyer 			REG_WR_IND(sc, offset, fw->text[j]);
   2567       1.1    bouyer 	}
   2568       1.1    bouyer 
   2569       1.1    bouyer 	/* Load the Data area. */
   2570       1.1    bouyer 	offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
   2571       1.1    bouyer 	if (fw->data) {
   2572       1.1    bouyer 		int j;
   2573       1.1    bouyer 
   2574       1.1    bouyer 		for (j = 0; j < (fw->data_len / 4); j++, offset += 4)
   2575       1.1    bouyer 			REG_WR_IND(sc, offset, fw->data[j]);
   2576       1.1    bouyer 	}
   2577       1.1    bouyer 
   2578       1.1    bouyer 	/* Load the SBSS area. */
   2579       1.1    bouyer 	offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
   2580       1.1    bouyer 	if (fw->sbss) {
   2581       1.1    bouyer 		int j;
   2582       1.1    bouyer 
   2583       1.1    bouyer 		for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4)
   2584       1.1    bouyer 			REG_WR_IND(sc, offset, fw->sbss[j]);
   2585       1.1    bouyer 	}
   2586       1.1    bouyer 
   2587       1.1    bouyer 	/* Load the BSS area. */
   2588       1.1    bouyer 	offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
   2589       1.1    bouyer 	if (fw->bss) {
   2590       1.1    bouyer 		int j;
   2591       1.1    bouyer 
   2592       1.1    bouyer 		for (j = 0; j < (fw->bss_len/4); j++, offset += 4)
   2593       1.1    bouyer 			REG_WR_IND(sc, offset, fw->bss[j]);
   2594       1.1    bouyer 	}
   2595       1.1    bouyer 
   2596       1.1    bouyer 	/* Load the Read-Only area. */
   2597       1.1    bouyer 	offset = cpu_reg->spad_base +
   2598       1.1    bouyer 	    (fw->rodata_addr - cpu_reg->mips_view_base);
   2599       1.1    bouyer 	if (fw->rodata) {
   2600       1.1    bouyer 		int j;
   2601       1.1    bouyer 
   2602       1.1    bouyer 		for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4)
   2603       1.1    bouyer 			REG_WR_IND(sc, offset, fw->rodata[j]);
   2604       1.1    bouyer 	}
   2605       1.1    bouyer 
   2606       1.1    bouyer 	/* Clear the pre-fetch instruction. */
   2607       1.1    bouyer 	REG_WR_IND(sc, cpu_reg->inst, 0);
   2608       1.1    bouyer 	REG_WR_IND(sc, cpu_reg->pc, fw->start_addr);
   2609       1.1    bouyer 
   2610       1.1    bouyer 	/* Start the CPU. */
   2611       1.1    bouyer 	val = REG_RD_IND(sc, cpu_reg->mode);
   2612       1.1    bouyer 	val &= ~cpu_reg->mode_value_halt;
   2613       1.1    bouyer 	REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
   2614       1.1    bouyer 	REG_WR_IND(sc, cpu_reg->mode, val);
   2615       1.1    bouyer }
   2616       1.1    bouyer 
   2617       1.1    bouyer /****************************************************************************/
   2618       1.1    bouyer /* Initialize the RV2P, RX, TX, TPAT, and COM CPUs.                         */
   2619       1.1    bouyer /*                                                                          */
   2620       1.1    bouyer /* Loads the firmware for each CPU and starts the CPU.                      */
   2621       1.1    bouyer /*                                                                          */
   2622       1.1    bouyer /* Returns:                                                                 */
   2623       1.1    bouyer /*   Nothing.                                                               */
   2624       1.1    bouyer /****************************************************************************/
   2625       1.1    bouyer void
   2626       1.1    bouyer bnx_init_cpus(struct bnx_softc *sc)
   2627       1.1    bouyer {
   2628       1.1    bouyer 	struct cpu_reg cpu_reg;
   2629       1.1    bouyer 	struct fw_info fw;
   2630       1.1    bouyer 
   2631  1.20.4.2  sborrill 	switch(BNX_CHIP_NUM(sc)) {
   2632  1.20.4.2  sborrill 	case BNX_CHIP_NUM_5709:
   2633  1.20.4.2  sborrill 		/* Initialize the RV2P processor. */
   2634  1.20.4.2  sborrill 		if (BNX_CHIP_REV(sc) == BNX_CHIP_REV_Ax) {
   2635  1.20.4.2  sborrill 			bnx_load_rv2p_fw(sc, bnx_xi90_rv2p_proc1,
   2636  1.20.4.2  sborrill 			    sizeof(bnx_xi90_rv2p_proc1), RV2P_PROC1);
   2637  1.20.4.2  sborrill 			bnx_load_rv2p_fw(sc, bnx_xi90_rv2p_proc2,
   2638  1.20.4.2  sborrill 			    sizeof(bnx_xi90_rv2p_proc2), RV2P_PROC2);
   2639  1.20.4.2  sborrill 		} else {
   2640  1.20.4.2  sborrill 			bnx_load_rv2p_fw(sc, bnx_xi_rv2p_proc1,
   2641  1.20.4.2  sborrill 			    sizeof(bnx_xi_rv2p_proc1), RV2P_PROC1);
   2642  1.20.4.2  sborrill 			bnx_load_rv2p_fw(sc, bnx_xi_rv2p_proc2,
   2643  1.20.4.2  sborrill 			    sizeof(bnx_xi_rv2p_proc2), RV2P_PROC2);
   2644  1.20.4.2  sborrill 		}
   2645  1.20.4.2  sborrill 
   2646  1.20.4.2  sborrill 		/* Initialize the RX Processor. */
   2647  1.20.4.2  sborrill 		cpu_reg.mode = BNX_RXP_CPU_MODE;
   2648  1.20.4.2  sborrill 		cpu_reg.mode_value_halt = BNX_RXP_CPU_MODE_SOFT_HALT;
   2649  1.20.4.2  sborrill 		cpu_reg.mode_value_sstep = BNX_RXP_CPU_MODE_STEP_ENA;
   2650  1.20.4.2  sborrill 		cpu_reg.state = BNX_RXP_CPU_STATE;
   2651  1.20.4.2  sborrill 		cpu_reg.state_value_clear = 0xffffff;
   2652  1.20.4.2  sborrill 		cpu_reg.gpr0 = BNX_RXP_CPU_REG_FILE;
   2653  1.20.4.2  sborrill 		cpu_reg.evmask = BNX_RXP_CPU_EVENT_MASK;
   2654  1.20.4.2  sborrill 		cpu_reg.pc = BNX_RXP_CPU_PROGRAM_COUNTER;
   2655  1.20.4.2  sborrill 		cpu_reg.inst = BNX_RXP_CPU_INSTRUCTION;
   2656  1.20.4.2  sborrill 		cpu_reg.bp = BNX_RXP_CPU_HW_BREAKPOINT;
   2657  1.20.4.2  sborrill 		cpu_reg.spad_base = BNX_RXP_SCRATCH;
   2658  1.20.4.2  sborrill 		cpu_reg.mips_view_base = 0x8000000;
   2659  1.20.4.2  sborrill 
   2660  1.20.4.2  sborrill 		fw.ver_major = bnx_RXP_b09FwReleaseMajor;
   2661  1.20.4.2  sborrill 		fw.ver_minor = bnx_RXP_b09FwReleaseMinor;
   2662  1.20.4.2  sborrill 		fw.ver_fix = bnx_RXP_b09FwReleaseFix;
   2663  1.20.4.2  sborrill 		fw.start_addr = bnx_RXP_b09FwStartAddr;
   2664  1.20.4.2  sborrill 
   2665  1.20.4.2  sborrill 		fw.text_addr = bnx_RXP_b09FwTextAddr;
   2666  1.20.4.2  sborrill 		fw.text_len = bnx_RXP_b09FwTextLen;
   2667  1.20.4.2  sborrill 		fw.text_index = 0;
   2668  1.20.4.2  sborrill 		fw.text = bnx_RXP_b09FwText;
   2669  1.20.4.2  sborrill 
   2670  1.20.4.2  sborrill 		fw.data_addr = bnx_RXP_b09FwDataAddr;
   2671  1.20.4.2  sborrill 		fw.data_len = bnx_RXP_b09FwDataLen;
   2672  1.20.4.2  sborrill 		fw.data_index = 0;
   2673  1.20.4.2  sborrill 		fw.data = bnx_RXP_b09FwData;
   2674  1.20.4.2  sborrill 
   2675  1.20.4.2  sborrill 		fw.sbss_addr = bnx_RXP_b09FwSbssAddr;
   2676  1.20.4.2  sborrill 		fw.sbss_len = bnx_RXP_b09FwSbssLen;
   2677  1.20.4.2  sborrill 		fw.sbss_index = 0;
   2678  1.20.4.2  sborrill 		fw.sbss = bnx_RXP_b09FwSbss;
   2679  1.20.4.2  sborrill 
   2680  1.20.4.2  sborrill 		fw.bss_addr = bnx_RXP_b09FwBssAddr;
   2681  1.20.4.2  sborrill 		fw.bss_len = bnx_RXP_b09FwBssLen;
   2682  1.20.4.2  sborrill 		fw.bss_index = 0;
   2683  1.20.4.2  sborrill 		fw.bss = bnx_RXP_b09FwBss;
   2684  1.20.4.2  sborrill 
   2685  1.20.4.2  sborrill 		fw.rodata_addr = bnx_RXP_b09FwRodataAddr;
   2686  1.20.4.2  sborrill 		fw.rodata_len = bnx_RXP_b09FwRodataLen;
   2687  1.20.4.2  sborrill 		fw.rodata_index = 0;
   2688  1.20.4.2  sborrill 		fw.rodata = bnx_RXP_b09FwRodata;
   2689  1.20.4.2  sborrill 
   2690  1.20.4.2  sborrill 		DBPRINT(sc, BNX_INFO_RESET, "Loading RX firmware.\n");
   2691  1.20.4.2  sborrill 		bnx_load_cpu_fw(sc, &cpu_reg, &fw);
   2692  1.20.4.2  sborrill 
   2693  1.20.4.2  sborrill 		/* Initialize the TX Processor. */
   2694  1.20.4.2  sborrill 		cpu_reg.mode = BNX_TXP_CPU_MODE;
   2695  1.20.4.2  sborrill 		cpu_reg.mode_value_halt = BNX_TXP_CPU_MODE_SOFT_HALT;
   2696  1.20.4.2  sborrill 		cpu_reg.mode_value_sstep = BNX_TXP_CPU_MODE_STEP_ENA;
   2697  1.20.4.2  sborrill 		cpu_reg.state = BNX_TXP_CPU_STATE;
   2698  1.20.4.2  sborrill 		cpu_reg.state_value_clear = 0xffffff;
   2699  1.20.4.2  sborrill 		cpu_reg.gpr0 = BNX_TXP_CPU_REG_FILE;
   2700  1.20.4.2  sborrill 		cpu_reg.evmask = BNX_TXP_CPU_EVENT_MASK;
   2701  1.20.4.2  sborrill 		cpu_reg.pc = BNX_TXP_CPU_PROGRAM_COUNTER;
   2702  1.20.4.2  sborrill 		cpu_reg.inst = BNX_TXP_CPU_INSTRUCTION;
   2703  1.20.4.2  sborrill 		cpu_reg.bp = BNX_TXP_CPU_HW_BREAKPOINT;
   2704  1.20.4.2  sborrill 		cpu_reg.spad_base = BNX_TXP_SCRATCH;
   2705  1.20.4.2  sborrill 		cpu_reg.mips_view_base = 0x8000000;
   2706  1.20.4.2  sborrill 
   2707  1.20.4.2  sborrill 		fw.ver_major = bnx_TXP_b09FwReleaseMajor;
   2708  1.20.4.2  sborrill 		fw.ver_minor = bnx_TXP_b09FwReleaseMinor;
   2709  1.20.4.2  sborrill 		fw.ver_fix = bnx_TXP_b09FwReleaseFix;
   2710  1.20.4.2  sborrill 		fw.start_addr = bnx_TXP_b09FwStartAddr;
   2711  1.20.4.2  sborrill 
   2712  1.20.4.2  sborrill 		fw.text_addr = bnx_TXP_b09FwTextAddr;
   2713  1.20.4.2  sborrill 		fw.text_len = bnx_TXP_b09FwTextLen;
   2714  1.20.4.2  sborrill 		fw.text_index = 0;
   2715  1.20.4.2  sborrill 		fw.text = bnx_TXP_b09FwText;
   2716  1.20.4.2  sborrill 
   2717  1.20.4.2  sborrill 		fw.data_addr = bnx_TXP_b09FwDataAddr;
   2718  1.20.4.2  sborrill 		fw.data_len = bnx_TXP_b09FwDataLen;
   2719  1.20.4.2  sborrill 		fw.data_index = 0;
   2720  1.20.4.2  sborrill 		fw.data = bnx_TXP_b09FwData;
   2721  1.20.4.2  sborrill 
   2722  1.20.4.2  sborrill 		fw.sbss_addr = bnx_TXP_b09FwSbssAddr;
   2723  1.20.4.2  sborrill 		fw.sbss_len = bnx_TXP_b09FwSbssLen;
   2724  1.20.4.2  sborrill 		fw.sbss_index = 0;
   2725  1.20.4.2  sborrill 		fw.sbss = bnx_TXP_b09FwSbss;
   2726  1.20.4.2  sborrill 
   2727  1.20.4.2  sborrill 		fw.bss_addr = bnx_TXP_b09FwBssAddr;
   2728  1.20.4.2  sborrill 		fw.bss_len = bnx_TXP_b09FwBssLen;
   2729  1.20.4.2  sborrill 		fw.bss_index = 0;
   2730  1.20.4.2  sborrill 		fw.bss = bnx_TXP_b09FwBss;
   2731  1.20.4.2  sborrill 
   2732  1.20.4.2  sborrill 		fw.rodata_addr = bnx_TXP_b09FwRodataAddr;
   2733  1.20.4.2  sborrill 		fw.rodata_len = bnx_TXP_b09FwRodataLen;
   2734  1.20.4.2  sborrill 		fw.rodata_index = 0;
   2735  1.20.4.2  sborrill 		fw.rodata = bnx_TXP_b09FwRodata;
   2736  1.20.4.2  sborrill 
   2737  1.20.4.2  sborrill 		DBPRINT(sc, BNX_INFO_RESET, "Loading TX firmware.\n");
   2738  1.20.4.2  sborrill 		bnx_load_cpu_fw(sc, &cpu_reg, &fw);
   2739  1.20.4.2  sborrill 
   2740  1.20.4.2  sborrill 		/* Initialize the TX Patch-up Processor. */
   2741  1.20.4.2  sborrill 		cpu_reg.mode = BNX_TPAT_CPU_MODE;
   2742  1.20.4.2  sborrill 		cpu_reg.mode_value_halt = BNX_TPAT_CPU_MODE_SOFT_HALT;
   2743  1.20.4.2  sborrill 		cpu_reg.mode_value_sstep = BNX_TPAT_CPU_MODE_STEP_ENA;
   2744  1.20.4.2  sborrill 		cpu_reg.state = BNX_TPAT_CPU_STATE;
   2745  1.20.4.2  sborrill 		cpu_reg.state_value_clear = 0xffffff;
   2746  1.20.4.2  sborrill 		cpu_reg.gpr0 = BNX_TPAT_CPU_REG_FILE;
   2747  1.20.4.2  sborrill 		cpu_reg.evmask = BNX_TPAT_CPU_EVENT_MASK;
   2748  1.20.4.2  sborrill 		cpu_reg.pc = BNX_TPAT_CPU_PROGRAM_COUNTER;
   2749  1.20.4.2  sborrill 		cpu_reg.inst = BNX_TPAT_CPU_INSTRUCTION;
   2750  1.20.4.2  sborrill 		cpu_reg.bp = BNX_TPAT_CPU_HW_BREAKPOINT;
   2751  1.20.4.2  sborrill 		cpu_reg.spad_base = BNX_TPAT_SCRATCH;
   2752  1.20.4.2  sborrill 		cpu_reg.mips_view_base = 0x8000000;
   2753  1.20.4.2  sborrill 
   2754  1.20.4.2  sborrill 		fw.ver_major = bnx_TPAT_b09FwReleaseMajor;
   2755  1.20.4.2  sborrill 		fw.ver_minor = bnx_TPAT_b09FwReleaseMinor;
   2756  1.20.4.2  sborrill 		fw.ver_fix = bnx_TPAT_b09FwReleaseFix;
   2757  1.20.4.2  sborrill 		fw.start_addr = bnx_TPAT_b09FwStartAddr;
   2758  1.20.4.2  sborrill 
   2759  1.20.4.2  sborrill 		fw.text_addr = bnx_TPAT_b09FwTextAddr;
   2760  1.20.4.2  sborrill 		fw.text_len = bnx_TPAT_b09FwTextLen;
   2761  1.20.4.2  sborrill 		fw.text_index = 0;
   2762  1.20.4.2  sborrill 		fw.text = bnx_TPAT_b09FwText;
   2763  1.20.4.2  sborrill 
   2764  1.20.4.2  sborrill 		fw.data_addr = bnx_TPAT_b09FwDataAddr;
   2765  1.20.4.2  sborrill 		fw.data_len = bnx_TPAT_b09FwDataLen;
   2766  1.20.4.2  sborrill 		fw.data_index = 0;
   2767  1.20.4.2  sborrill 		fw.data = bnx_TPAT_b09FwData;
   2768  1.20.4.2  sborrill 
   2769  1.20.4.2  sborrill 		fw.sbss_addr = bnx_TPAT_b09FwSbssAddr;
   2770  1.20.4.2  sborrill 		fw.sbss_len = bnx_TPAT_b09FwSbssLen;
   2771  1.20.4.2  sborrill 		fw.sbss_index = 0;
   2772  1.20.4.2  sborrill 		fw.sbss = bnx_TPAT_b09FwSbss;
   2773  1.20.4.2  sborrill 
   2774  1.20.4.2  sborrill 		fw.bss_addr = bnx_TPAT_b09FwBssAddr;
   2775  1.20.4.2  sborrill 		fw.bss_len = bnx_TPAT_b09FwBssLen;
   2776  1.20.4.2  sborrill 		fw.bss_index = 0;
   2777  1.20.4.2  sborrill 		fw.bss = bnx_TPAT_b09FwBss;
   2778  1.20.4.2  sborrill 
   2779  1.20.4.2  sborrill 		fw.rodata_addr = bnx_TPAT_b09FwRodataAddr;
   2780  1.20.4.2  sborrill 		fw.rodata_len = bnx_TPAT_b09FwRodataLen;
   2781  1.20.4.2  sborrill 		fw.rodata_index = 0;
   2782  1.20.4.2  sborrill 		fw.rodata = bnx_TPAT_b09FwRodata;
   2783  1.20.4.2  sborrill 
   2784  1.20.4.2  sborrill 		DBPRINT(sc, BNX_INFO_RESET, "Loading TPAT firmware.\n");
   2785  1.20.4.2  sborrill 		bnx_load_cpu_fw(sc, &cpu_reg, &fw);
   2786  1.20.4.2  sborrill 
   2787  1.20.4.2  sborrill 		/* Initialize the Completion Processor. */
   2788  1.20.4.2  sborrill 		cpu_reg.mode = BNX_COM_CPU_MODE;
   2789  1.20.4.2  sborrill 		cpu_reg.mode_value_halt = BNX_COM_CPU_MODE_SOFT_HALT;
   2790  1.20.4.2  sborrill 		cpu_reg.mode_value_sstep = BNX_COM_CPU_MODE_STEP_ENA;
   2791  1.20.4.2  sborrill 		cpu_reg.state = BNX_COM_CPU_STATE;
   2792  1.20.4.2  sborrill 		cpu_reg.state_value_clear = 0xffffff;
   2793  1.20.4.2  sborrill 		cpu_reg.gpr0 = BNX_COM_CPU_REG_FILE;
   2794  1.20.4.2  sborrill 		cpu_reg.evmask = BNX_COM_CPU_EVENT_MASK;
   2795  1.20.4.2  sborrill 		cpu_reg.pc = BNX_COM_CPU_PROGRAM_COUNTER;
   2796  1.20.4.2  sborrill 		cpu_reg.inst = BNX_COM_CPU_INSTRUCTION;
   2797  1.20.4.2  sborrill 		cpu_reg.bp = BNX_COM_CPU_HW_BREAKPOINT;
   2798  1.20.4.2  sborrill 		cpu_reg.spad_base = BNX_COM_SCRATCH;
   2799  1.20.4.2  sborrill 		cpu_reg.mips_view_base = 0x8000000;
   2800  1.20.4.2  sborrill 
   2801  1.20.4.2  sborrill 		fw.ver_major = bnx_COM_b09FwReleaseMajor;
   2802  1.20.4.2  sborrill 		fw.ver_minor = bnx_COM_b09FwReleaseMinor;
   2803  1.20.4.2  sborrill 		fw.ver_fix = bnx_COM_b09FwReleaseFix;
   2804  1.20.4.2  sborrill 		fw.start_addr = bnx_COM_b09FwStartAddr;
   2805  1.20.4.2  sborrill 
   2806  1.20.4.2  sborrill 		fw.text_addr = bnx_COM_b09FwTextAddr;
   2807  1.20.4.2  sborrill 		fw.text_len = bnx_COM_b09FwTextLen;
   2808  1.20.4.2  sborrill 		fw.text_index = 0;
   2809  1.20.4.2  sborrill 		fw.text = bnx_COM_b09FwText;
   2810  1.20.4.2  sborrill 
   2811  1.20.4.2  sborrill 		fw.data_addr = bnx_COM_b09FwDataAddr;
   2812  1.20.4.2  sborrill 		fw.data_len = bnx_COM_b09FwDataLen;
   2813  1.20.4.2  sborrill 		fw.data_index = 0;
   2814  1.20.4.2  sborrill 		fw.data = bnx_COM_b09FwData;
   2815  1.20.4.2  sborrill 
   2816  1.20.4.2  sborrill 		fw.sbss_addr = bnx_COM_b09FwSbssAddr;
   2817  1.20.4.2  sborrill 		fw.sbss_len = bnx_COM_b09FwSbssLen;
   2818  1.20.4.2  sborrill 		fw.sbss_index = 0;
   2819  1.20.4.2  sborrill 		fw.sbss = bnx_COM_b09FwSbss;
   2820  1.20.4.2  sborrill 
   2821  1.20.4.2  sborrill 		fw.bss_addr = bnx_COM_b09FwBssAddr;
   2822  1.20.4.2  sborrill 		fw.bss_len = bnx_COM_b09FwBssLen;
   2823  1.20.4.2  sborrill 		fw.bss_index = 0;
   2824  1.20.4.2  sborrill 		fw.bss = bnx_COM_b09FwBss;
   2825  1.20.4.2  sborrill 
   2826  1.20.4.2  sborrill 		fw.rodata_addr = bnx_COM_b09FwRodataAddr;
   2827  1.20.4.2  sborrill 		fw.rodata_len = bnx_COM_b09FwRodataLen;
   2828  1.20.4.2  sborrill 		fw.rodata_index = 0;
   2829  1.20.4.2  sborrill 		fw.rodata = bnx_COM_b09FwRodata;
   2830  1.20.4.2  sborrill 		DBPRINT(sc, BNX_INFO_RESET, "Loading COM firmware.\n");
   2831  1.20.4.2  sborrill 		bnx_load_cpu_fw(sc, &cpu_reg, &fw);
   2832  1.20.4.2  sborrill 		break;
   2833  1.20.4.2  sborrill 	default:
   2834  1.20.4.2  sborrill 		/* Initialize the RV2P processor. */
   2835  1.20.4.2  sborrill 		bnx_load_rv2p_fw(sc, bnx_rv2p_proc1, sizeof(bnx_rv2p_proc1),
   2836  1.20.4.2  sborrill 		    RV2P_PROC1);
   2837  1.20.4.2  sborrill 		bnx_load_rv2p_fw(sc, bnx_rv2p_proc2, sizeof(bnx_rv2p_proc2),
   2838  1.20.4.2  sborrill 		    RV2P_PROC2);
   2839  1.20.4.2  sborrill 
   2840  1.20.4.2  sborrill 		/* Initialize the RX Processor. */
   2841  1.20.4.2  sborrill 		cpu_reg.mode = BNX_RXP_CPU_MODE;
   2842  1.20.4.2  sborrill 		cpu_reg.mode_value_halt = BNX_RXP_CPU_MODE_SOFT_HALT;
   2843  1.20.4.2  sborrill 		cpu_reg.mode_value_sstep = BNX_RXP_CPU_MODE_STEP_ENA;
   2844  1.20.4.2  sborrill 		cpu_reg.state = BNX_RXP_CPU_STATE;
   2845  1.20.4.2  sborrill 		cpu_reg.state_value_clear = 0xffffff;
   2846  1.20.4.2  sborrill 		cpu_reg.gpr0 = BNX_RXP_CPU_REG_FILE;
   2847  1.20.4.2  sborrill 		cpu_reg.evmask = BNX_RXP_CPU_EVENT_MASK;
   2848  1.20.4.2  sborrill 		cpu_reg.pc = BNX_RXP_CPU_PROGRAM_COUNTER;
   2849  1.20.4.2  sborrill 		cpu_reg.inst = BNX_RXP_CPU_INSTRUCTION;
   2850  1.20.4.2  sborrill 		cpu_reg.bp = BNX_RXP_CPU_HW_BREAKPOINT;
   2851  1.20.4.2  sborrill 		cpu_reg.spad_base = BNX_RXP_SCRATCH;
   2852  1.20.4.2  sborrill 		cpu_reg.mips_view_base = 0x8000000;
   2853  1.20.4.2  sborrill 
   2854  1.20.4.2  sborrill 		fw.ver_major = bnx_RXP_b06FwReleaseMajor;
   2855  1.20.4.2  sborrill 		fw.ver_minor = bnx_RXP_b06FwReleaseMinor;
   2856  1.20.4.2  sborrill 		fw.ver_fix = bnx_RXP_b06FwReleaseFix;
   2857  1.20.4.2  sborrill 		fw.start_addr = bnx_RXP_b06FwStartAddr;
   2858  1.20.4.2  sborrill 
   2859  1.20.4.2  sborrill 		fw.text_addr = bnx_RXP_b06FwTextAddr;
   2860  1.20.4.2  sborrill 		fw.text_len = bnx_RXP_b06FwTextLen;
   2861  1.20.4.2  sborrill 		fw.text_index = 0;
   2862  1.20.4.2  sborrill 		fw.text = bnx_RXP_b06FwText;
   2863  1.20.4.2  sborrill 
   2864  1.20.4.2  sborrill 		fw.data_addr = bnx_RXP_b06FwDataAddr;
   2865  1.20.4.2  sborrill 		fw.data_len = bnx_RXP_b06FwDataLen;
   2866  1.20.4.2  sborrill 		fw.data_index = 0;
   2867  1.20.4.2  sborrill 		fw.data = bnx_RXP_b06FwData;
   2868  1.20.4.2  sborrill 
   2869  1.20.4.2  sborrill 		fw.sbss_addr = bnx_RXP_b06FwSbssAddr;
   2870  1.20.4.2  sborrill 		fw.sbss_len = bnx_RXP_b06FwSbssLen;
   2871  1.20.4.2  sborrill 		fw.sbss_index = 0;
   2872  1.20.4.2  sborrill 		fw.sbss = bnx_RXP_b06FwSbss;
   2873  1.20.4.2  sborrill 
   2874  1.20.4.2  sborrill 		fw.bss_addr = bnx_RXP_b06FwBssAddr;
   2875  1.20.4.2  sborrill 		fw.bss_len = bnx_RXP_b06FwBssLen;
   2876  1.20.4.2  sborrill 		fw.bss_index = 0;
   2877  1.20.4.2  sborrill 		fw.bss = bnx_RXP_b06FwBss;
   2878  1.20.4.2  sborrill 
   2879  1.20.4.2  sborrill 		fw.rodata_addr = bnx_RXP_b06FwRodataAddr;
   2880  1.20.4.2  sborrill 		fw.rodata_len = bnx_RXP_b06FwRodataLen;
   2881  1.20.4.2  sborrill 		fw.rodata_index = 0;
   2882  1.20.4.2  sborrill 		fw.rodata = bnx_RXP_b06FwRodata;
   2883  1.20.4.2  sborrill 
   2884  1.20.4.2  sborrill 		DBPRINT(sc, BNX_INFO_RESET, "Loading RX firmware.\n");
   2885  1.20.4.2  sborrill 		bnx_load_cpu_fw(sc, &cpu_reg, &fw);
   2886  1.20.4.2  sborrill 
   2887  1.20.4.2  sborrill 		/* Initialize the TX Processor. */
   2888  1.20.4.2  sborrill 		cpu_reg.mode = BNX_TXP_CPU_MODE;
   2889  1.20.4.2  sborrill 		cpu_reg.mode_value_halt = BNX_TXP_CPU_MODE_SOFT_HALT;
   2890  1.20.4.2  sborrill 		cpu_reg.mode_value_sstep = BNX_TXP_CPU_MODE_STEP_ENA;
   2891  1.20.4.2  sborrill 		cpu_reg.state = BNX_TXP_CPU_STATE;
   2892  1.20.4.2  sborrill 		cpu_reg.state_value_clear = 0xffffff;
   2893  1.20.4.2  sborrill 		cpu_reg.gpr0 = BNX_TXP_CPU_REG_FILE;
   2894  1.20.4.2  sborrill 		cpu_reg.evmask = BNX_TXP_CPU_EVENT_MASK;
   2895  1.20.4.2  sborrill 		cpu_reg.pc = BNX_TXP_CPU_PROGRAM_COUNTER;
   2896  1.20.4.2  sborrill 		cpu_reg.inst = BNX_TXP_CPU_INSTRUCTION;
   2897  1.20.4.2  sborrill 		cpu_reg.bp = BNX_TXP_CPU_HW_BREAKPOINT;
   2898  1.20.4.2  sborrill 		cpu_reg.spad_base = BNX_TXP_SCRATCH;
   2899  1.20.4.2  sborrill 		cpu_reg.mips_view_base = 0x8000000;
   2900  1.20.4.2  sborrill 
   2901  1.20.4.2  sborrill 		fw.ver_major = bnx_TXP_b06FwReleaseMajor;
   2902  1.20.4.2  sborrill 		fw.ver_minor = bnx_TXP_b06FwReleaseMinor;
   2903  1.20.4.2  sborrill 		fw.ver_fix = bnx_TXP_b06FwReleaseFix;
   2904  1.20.4.2  sborrill 		fw.start_addr = bnx_TXP_b06FwStartAddr;
   2905  1.20.4.2  sborrill 
   2906  1.20.4.2  sborrill 		fw.text_addr = bnx_TXP_b06FwTextAddr;
   2907  1.20.4.2  sborrill 		fw.text_len = bnx_TXP_b06FwTextLen;
   2908  1.20.4.2  sborrill 		fw.text_index = 0;
   2909  1.20.4.2  sborrill 		fw.text = bnx_TXP_b06FwText;
   2910  1.20.4.2  sborrill 
   2911  1.20.4.2  sborrill 		fw.data_addr = bnx_TXP_b06FwDataAddr;
   2912  1.20.4.2  sborrill 		fw.data_len = bnx_TXP_b06FwDataLen;
   2913  1.20.4.2  sborrill 		fw.data_index = 0;
   2914  1.20.4.2  sborrill 		fw.data = bnx_TXP_b06FwData;
   2915  1.20.4.2  sborrill 
   2916  1.20.4.2  sborrill 		fw.sbss_addr = bnx_TXP_b06FwSbssAddr;
   2917  1.20.4.2  sborrill 		fw.sbss_len = bnx_TXP_b06FwSbssLen;
   2918  1.20.4.2  sborrill 		fw.sbss_index = 0;
   2919  1.20.4.2  sborrill 		fw.sbss = bnx_TXP_b06FwSbss;
   2920  1.20.4.2  sborrill 
   2921  1.20.4.2  sborrill 		fw.bss_addr = bnx_TXP_b06FwBssAddr;
   2922  1.20.4.2  sborrill 		fw.bss_len = bnx_TXP_b06FwBssLen;
   2923  1.20.4.2  sborrill 		fw.bss_index = 0;
   2924  1.20.4.2  sborrill 		fw.bss = bnx_TXP_b06FwBss;
   2925  1.20.4.2  sborrill 
   2926  1.20.4.2  sborrill 		fw.rodata_addr = bnx_TXP_b06FwRodataAddr;
   2927  1.20.4.2  sborrill 		fw.rodata_len = bnx_TXP_b06FwRodataLen;
   2928  1.20.4.2  sborrill 		fw.rodata_index = 0;
   2929  1.20.4.2  sborrill 		fw.rodata = bnx_TXP_b06FwRodata;
   2930  1.20.4.2  sborrill 
   2931  1.20.4.2  sborrill 		DBPRINT(sc, BNX_INFO_RESET, "Loading TX firmware.\n");
   2932  1.20.4.2  sborrill 		bnx_load_cpu_fw(sc, &cpu_reg, &fw);
   2933  1.20.4.2  sborrill 
   2934  1.20.4.2  sborrill 		/* Initialize the TX Patch-up Processor. */
   2935  1.20.4.2  sborrill 		cpu_reg.mode = BNX_TPAT_CPU_MODE;
   2936  1.20.4.2  sborrill 		cpu_reg.mode_value_halt = BNX_TPAT_CPU_MODE_SOFT_HALT;
   2937  1.20.4.2  sborrill 		cpu_reg.mode_value_sstep = BNX_TPAT_CPU_MODE_STEP_ENA;
   2938  1.20.4.2  sborrill 		cpu_reg.state = BNX_TPAT_CPU_STATE;
   2939  1.20.4.2  sborrill 		cpu_reg.state_value_clear = 0xffffff;
   2940  1.20.4.2  sborrill 		cpu_reg.gpr0 = BNX_TPAT_CPU_REG_FILE;
   2941  1.20.4.2  sborrill 		cpu_reg.evmask = BNX_TPAT_CPU_EVENT_MASK;
   2942  1.20.4.2  sborrill 		cpu_reg.pc = BNX_TPAT_CPU_PROGRAM_COUNTER;
   2943  1.20.4.2  sborrill 		cpu_reg.inst = BNX_TPAT_CPU_INSTRUCTION;
   2944  1.20.4.2  sborrill 		cpu_reg.bp = BNX_TPAT_CPU_HW_BREAKPOINT;
   2945  1.20.4.2  sborrill 		cpu_reg.spad_base = BNX_TPAT_SCRATCH;
   2946  1.20.4.2  sborrill 		cpu_reg.mips_view_base = 0x8000000;
   2947  1.20.4.2  sborrill 
   2948  1.20.4.2  sborrill 		fw.ver_major = bnx_TPAT_b06FwReleaseMajor;
   2949  1.20.4.2  sborrill 		fw.ver_minor = bnx_TPAT_b06FwReleaseMinor;
   2950  1.20.4.2  sborrill 		fw.ver_fix = bnx_TPAT_b06FwReleaseFix;
   2951  1.20.4.2  sborrill 		fw.start_addr = bnx_TPAT_b06FwStartAddr;
   2952  1.20.4.2  sborrill 
   2953  1.20.4.2  sborrill 		fw.text_addr = bnx_TPAT_b06FwTextAddr;
   2954  1.20.4.2  sborrill 		fw.text_len = bnx_TPAT_b06FwTextLen;
   2955  1.20.4.2  sborrill 		fw.text_index = 0;
   2956  1.20.4.2  sborrill 		fw.text = bnx_TPAT_b06FwText;
   2957  1.20.4.2  sborrill 
   2958  1.20.4.2  sborrill 		fw.data_addr = bnx_TPAT_b06FwDataAddr;
   2959  1.20.4.2  sborrill 		fw.data_len = bnx_TPAT_b06FwDataLen;
   2960  1.20.4.2  sborrill 		fw.data_index = 0;
   2961  1.20.4.2  sborrill 		fw.data = bnx_TPAT_b06FwData;
   2962  1.20.4.2  sborrill 
   2963  1.20.4.2  sborrill 		fw.sbss_addr = bnx_TPAT_b06FwSbssAddr;
   2964  1.20.4.2  sborrill 		fw.sbss_len = bnx_TPAT_b06FwSbssLen;
   2965  1.20.4.2  sborrill 		fw.sbss_index = 0;
   2966  1.20.4.2  sborrill 		fw.sbss = bnx_TPAT_b06FwSbss;
   2967  1.20.4.2  sborrill 
   2968  1.20.4.2  sborrill 		fw.bss_addr = bnx_TPAT_b06FwBssAddr;
   2969  1.20.4.2  sborrill 		fw.bss_len = bnx_TPAT_b06FwBssLen;
   2970  1.20.4.2  sborrill 		fw.bss_index = 0;
   2971  1.20.4.2  sborrill 		fw.bss = bnx_TPAT_b06FwBss;
   2972  1.20.4.2  sborrill 
   2973  1.20.4.2  sborrill 		fw.rodata_addr = bnx_TPAT_b06FwRodataAddr;
   2974  1.20.4.2  sborrill 		fw.rodata_len = bnx_TPAT_b06FwRodataLen;
   2975  1.20.4.2  sborrill 		fw.rodata_index = 0;
   2976  1.20.4.2  sborrill 		fw.rodata = bnx_TPAT_b06FwRodata;
   2977  1.20.4.2  sborrill 
   2978  1.20.4.2  sborrill 		DBPRINT(sc, BNX_INFO_RESET, "Loading TPAT firmware.\n");
   2979  1.20.4.2  sborrill 		bnx_load_cpu_fw(sc, &cpu_reg, &fw);
   2980  1.20.4.2  sborrill 
   2981  1.20.4.2  sborrill 		/* Initialize the Completion Processor. */
   2982  1.20.4.2  sborrill 		cpu_reg.mode = BNX_COM_CPU_MODE;
   2983  1.20.4.2  sborrill 		cpu_reg.mode_value_halt = BNX_COM_CPU_MODE_SOFT_HALT;
   2984  1.20.4.2  sborrill 		cpu_reg.mode_value_sstep = BNX_COM_CPU_MODE_STEP_ENA;
   2985  1.20.4.2  sborrill 		cpu_reg.state = BNX_COM_CPU_STATE;
   2986  1.20.4.2  sborrill 		cpu_reg.state_value_clear = 0xffffff;
   2987  1.20.4.2  sborrill 		cpu_reg.gpr0 = BNX_COM_CPU_REG_FILE;
   2988  1.20.4.2  sborrill 		cpu_reg.evmask = BNX_COM_CPU_EVENT_MASK;
   2989  1.20.4.2  sborrill 		cpu_reg.pc = BNX_COM_CPU_PROGRAM_COUNTER;
   2990  1.20.4.2  sborrill 		cpu_reg.inst = BNX_COM_CPU_INSTRUCTION;
   2991  1.20.4.2  sborrill 		cpu_reg.bp = BNX_COM_CPU_HW_BREAKPOINT;
   2992  1.20.4.2  sborrill 		cpu_reg.spad_base = BNX_COM_SCRATCH;
   2993  1.20.4.2  sborrill 		cpu_reg.mips_view_base = 0x8000000;
   2994  1.20.4.2  sborrill 
   2995  1.20.4.2  sborrill 		fw.ver_major = bnx_COM_b06FwReleaseMajor;
   2996  1.20.4.2  sborrill 		fw.ver_minor = bnx_COM_b06FwReleaseMinor;
   2997  1.20.4.2  sborrill 		fw.ver_fix = bnx_COM_b06FwReleaseFix;
   2998  1.20.4.2  sborrill 		fw.start_addr = bnx_COM_b06FwStartAddr;
   2999  1.20.4.2  sborrill 
   3000  1.20.4.2  sborrill 		fw.text_addr = bnx_COM_b06FwTextAddr;
   3001  1.20.4.2  sborrill 		fw.text_len = bnx_COM_b06FwTextLen;
   3002  1.20.4.2  sborrill 		fw.text_index = 0;
   3003  1.20.4.2  sborrill 		fw.text = bnx_COM_b06FwText;
   3004  1.20.4.2  sborrill 
   3005  1.20.4.2  sborrill 		fw.data_addr = bnx_COM_b06FwDataAddr;
   3006  1.20.4.2  sborrill 		fw.data_len = bnx_COM_b06FwDataLen;
   3007  1.20.4.2  sborrill 		fw.data_index = 0;
   3008  1.20.4.2  sborrill 		fw.data = bnx_COM_b06FwData;
   3009  1.20.4.2  sborrill 
   3010  1.20.4.2  sborrill 		fw.sbss_addr = bnx_COM_b06FwSbssAddr;
   3011  1.20.4.2  sborrill 		fw.sbss_len = bnx_COM_b06FwSbssLen;
   3012  1.20.4.2  sborrill 		fw.sbss_index = 0;
   3013  1.20.4.2  sborrill 		fw.sbss = bnx_COM_b06FwSbss;
   3014  1.20.4.2  sborrill 
   3015  1.20.4.2  sborrill 		fw.bss_addr = bnx_COM_b06FwBssAddr;
   3016  1.20.4.2  sborrill 		fw.bss_len = bnx_COM_b06FwBssLen;
   3017  1.20.4.2  sborrill 		fw.bss_index = 0;
   3018  1.20.4.2  sborrill 		fw.bss = bnx_COM_b06FwBss;
   3019  1.20.4.2  sborrill 
   3020  1.20.4.2  sborrill 		fw.rodata_addr = bnx_COM_b06FwRodataAddr;
   3021  1.20.4.2  sborrill 		fw.rodata_len = bnx_COM_b06FwRodataLen;
   3022  1.20.4.2  sborrill 		fw.rodata_index = 0;
   3023  1.20.4.2  sborrill 		fw.rodata = bnx_COM_b06FwRodata;
   3024  1.20.4.2  sborrill 		DBPRINT(sc, BNX_INFO_RESET, "Loading COM firmware.\n");
   3025  1.20.4.2  sborrill 		bnx_load_cpu_fw(sc, &cpu_reg, &fw);
   3026  1.20.4.2  sborrill 		break;
   3027  1.20.4.2  sborrill 	}
   3028       1.1    bouyer }
   3029       1.1    bouyer 
   3030       1.1    bouyer /****************************************************************************/
   3031       1.1    bouyer /* Initialize context memory.                                               */
   3032       1.1    bouyer /*                                                                          */
   3033       1.1    bouyer /* Clears the memory associated with each Context ID (CID).                 */
   3034       1.1    bouyer /*                                                                          */
   3035       1.1    bouyer /* Returns:                                                                 */
   3036       1.1    bouyer /*   Nothing.                                                               */
   3037       1.1    bouyer /****************************************************************************/
   3038       1.1    bouyer void
   3039       1.1    bouyer bnx_init_context(struct bnx_softc *sc)
   3040       1.1    bouyer {
   3041  1.20.4.2  sborrill 	if (BNX_CHIP_NUM(sc) == BNX_CHIP_NUM_5709) {
   3042  1.20.4.2  sborrill 		/* DRC: Replace this constant value with a #define. */
   3043  1.20.4.2  sborrill 		int i, retry_cnt = 10;
   3044  1.20.4.2  sborrill 		u_int32_t val;
   3045  1.20.4.2  sborrill 
   3046  1.20.4.2  sborrill 		/*
   3047  1.20.4.2  sborrill 		 * BCM5709 context memory may be cached
   3048  1.20.4.2  sborrill 		 * in host memory so prepare the host memory
   3049  1.20.4.2  sborrill 		 * for access.
   3050  1.20.4.2  sborrill 		 */
   3051  1.20.4.2  sborrill 		val = BNX_CTX_COMMAND_ENABLED | BNX_CTX_COMMAND_MEM_INIT
   3052  1.20.4.2  sborrill 		    | (1 << 12);
   3053  1.20.4.2  sborrill 		val |= (BCM_PAGE_BITS - 8) << 16;
   3054  1.20.4.2  sborrill 		REG_WR(sc, BNX_CTX_COMMAND, val);
   3055  1.20.4.2  sborrill 
   3056  1.20.4.2  sborrill 		/* Wait for mem init command to complete. */
   3057  1.20.4.2  sborrill 		for (i = 0; i < retry_cnt; i++) {
   3058  1.20.4.2  sborrill 			val = REG_RD(sc, BNX_CTX_COMMAND);
   3059  1.20.4.2  sborrill 			if (!(val & BNX_CTX_COMMAND_MEM_INIT))
   3060  1.20.4.2  sborrill 				break;
   3061  1.20.4.2  sborrill 			DELAY(2);
   3062  1.20.4.2  sborrill 		}
   3063  1.20.4.2  sborrill 
   3064  1.20.4.2  sborrill 
   3065  1.20.4.2  sborrill 		/* ToDo: Consider returning an error here. */
   3066  1.20.4.2  sborrill 
   3067  1.20.4.2  sborrill 		for (i = 0; i < sc->ctx_pages; i++) {
   3068  1.20.4.2  sborrill 			int j;
   3069       1.1    bouyer 
   3070       1.1    bouyer 
   3071  1.20.4.2  sborrill 			/* Set the physaddr of the context memory cache. */
   3072  1.20.4.2  sborrill 			val = (u_int32_t)(sc->ctx_segs[i].ds_addr);
   3073  1.20.4.2  sborrill 			REG_WR(sc, BNX_CTX_HOST_PAGE_TBL_DATA0, val |
   3074  1.20.4.2  sborrill 				BNX_CTX_HOST_PAGE_TBL_DATA0_VALID);
   3075  1.20.4.2  sborrill 			val = (u_int32_t)
   3076  1.20.4.2  sborrill 			    ((u_int64_t)sc->ctx_segs[i].ds_addr >> 32);
   3077  1.20.4.2  sborrill 			REG_WR(sc, BNX_CTX_HOST_PAGE_TBL_DATA1, val);
   3078  1.20.4.2  sborrill 			REG_WR(sc, BNX_CTX_HOST_PAGE_TBL_CTRL, i |
   3079  1.20.4.2  sborrill 				BNX_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ);
   3080  1.20.4.2  sborrill 
   3081  1.20.4.2  sborrill 
   3082  1.20.4.2  sborrill 			/* Verify that the context memory write was successful. */
   3083  1.20.4.2  sborrill 			for (j = 0; j < retry_cnt; j++) {
   3084  1.20.4.2  sborrill 				val = REG_RD(sc, BNX_CTX_HOST_PAGE_TBL_CTRL);
   3085  1.20.4.2  sborrill 				if ((val & BNX_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) == 0)
   3086  1.20.4.2  sborrill 					break;
   3087  1.20.4.2  sborrill 				DELAY(5);
   3088  1.20.4.2  sborrill 			}
   3089       1.1    bouyer 
   3090  1.20.4.2  sborrill 			/* ToDo: Consider returning an error here. */
   3091  1.20.4.2  sborrill 		}
   3092  1.20.4.2  sborrill 	} else {
   3093  1.20.4.2  sborrill 		u_int32_t vcid_addr, offset;
   3094       1.1    bouyer 
   3095  1.20.4.2  sborrill 		/*
   3096  1.20.4.2  sborrill 		 * For the 5706/5708, context memory is local to
   3097  1.20.4.2  sborrill 		 * the controller, so initialize the controller
   3098  1.20.4.2  sborrill 		 * context memory.
   3099  1.20.4.2  sborrill 		 */
   3100       1.1    bouyer 
   3101  1.20.4.2  sborrill 		vcid_addr = GET_CID_ADDR(96);
   3102  1.20.4.2  sborrill 		while (vcid_addr) {
   3103       1.1    bouyer 
   3104  1.20.4.2  sborrill 			vcid_addr -= PHY_CTX_SIZE;
   3105  1.20.4.2  sborrill 
   3106  1.20.4.2  sborrill 			REG_WR(sc, BNX_CTX_VIRT_ADDR, 0);
   3107  1.20.4.2  sborrill 			REG_WR(sc, BNX_CTX_PAGE_TBL, vcid_addr);
   3108  1.20.4.2  sborrill 
   3109  1.20.4.2  sborrill 			for(offset = 0; offset < PHY_CTX_SIZE; offset += 4) {
   3110  1.20.4.2  sborrill 				CTX_WR(sc, 0x00, offset, 0);
   3111  1.20.4.2  sborrill 			}
   3112  1.20.4.2  sborrill 
   3113  1.20.4.2  sborrill 			REG_WR(sc, BNX_CTX_VIRT_ADDR, vcid_addr);
   3114  1.20.4.2  sborrill 			REG_WR(sc, BNX_CTX_PAGE_TBL, vcid_addr);
   3115  1.20.4.2  sborrill 		}
   3116       1.1    bouyer 	}
   3117       1.1    bouyer }
   3118       1.1    bouyer 
   3119       1.1    bouyer /****************************************************************************/
   3120       1.1    bouyer /* Fetch the permanent MAC address of the controller.                       */
   3121       1.1    bouyer /*                                                                          */
   3122       1.1    bouyer /* Returns:                                                                 */
   3123       1.1    bouyer /*   Nothing.                                                               */
   3124       1.1    bouyer /****************************************************************************/
   3125       1.1    bouyer void
   3126       1.1    bouyer bnx_get_mac_addr(struct bnx_softc *sc)
   3127       1.1    bouyer {
   3128       1.1    bouyer 	u_int32_t		mac_lo = 0, mac_hi = 0;
   3129       1.1    bouyer 
   3130       1.1    bouyer 	/*
   3131       1.1    bouyer 	 * The NetXtreme II bootcode populates various NIC
   3132       1.1    bouyer 	 * power-on and runtime configuration items in a
   3133       1.1    bouyer 	 * shared memory area.  The factory configured MAC
   3134       1.1    bouyer 	 * address is available from both NVRAM and the
   3135       1.1    bouyer 	 * shared memory area so we'll read the value from
   3136       1.1    bouyer 	 * shared memory for speed.
   3137       1.1    bouyer 	 */
   3138       1.1    bouyer 
   3139       1.1    bouyer 	mac_hi = REG_RD_IND(sc, sc->bnx_shmem_base + BNX_PORT_HW_CFG_MAC_UPPER);
   3140       1.1    bouyer 	mac_lo = REG_RD_IND(sc, sc->bnx_shmem_base + BNX_PORT_HW_CFG_MAC_LOWER);
   3141       1.1    bouyer 
   3142       1.1    bouyer 	if ((mac_lo == 0) && (mac_hi == 0)) {
   3143       1.1    bouyer 		BNX_PRINTF(sc, "%s(%d): Invalid Ethernet address!\n",
   3144       1.1    bouyer 		    __FILE__, __LINE__);
   3145       1.1    bouyer 	} else {
   3146       1.1    bouyer 		sc->eaddr[0] = (u_char)(mac_hi >> 8);
   3147       1.1    bouyer 		sc->eaddr[1] = (u_char)(mac_hi >> 0);
   3148       1.1    bouyer 		sc->eaddr[2] = (u_char)(mac_lo >> 24);
   3149       1.1    bouyer 		sc->eaddr[3] = (u_char)(mac_lo >> 16);
   3150       1.1    bouyer 		sc->eaddr[4] = (u_char)(mac_lo >> 8);
   3151       1.1    bouyer 		sc->eaddr[5] = (u_char)(mac_lo >> 0);
   3152       1.1    bouyer 	}
   3153       1.1    bouyer 
   3154       1.1    bouyer 	DBPRINT(sc, BNX_INFO, "Permanent Ethernet address = "
   3155       1.1    bouyer 	    "%s\n", ether_sprintf(sc->eaddr));
   3156       1.1    bouyer }
   3157       1.1    bouyer 
   3158       1.1    bouyer /****************************************************************************/
   3159       1.1    bouyer /* Program the MAC address.                                                 */
   3160       1.1    bouyer /*                                                                          */
   3161       1.1    bouyer /* Returns:                                                                 */
   3162       1.1    bouyer /*   Nothing.                                                               */
   3163       1.1    bouyer /****************************************************************************/
   3164       1.1    bouyer void
   3165       1.1    bouyer bnx_set_mac_addr(struct bnx_softc *sc)
   3166       1.1    bouyer {
   3167       1.1    bouyer 	u_int32_t		val;
   3168      1.15    dyoung 	const u_int8_t		*mac_addr = CLLADDR(sc->bnx_ec.ec_if.if_sadl);
   3169       1.1    bouyer 
   3170       1.1    bouyer 	DBPRINT(sc, BNX_INFO, "Setting Ethernet address = "
   3171       1.1    bouyer 	    "%s\n", ether_sprintf(sc->eaddr));
   3172       1.1    bouyer 
   3173       1.1    bouyer 	val = (mac_addr[0] << 8) | mac_addr[1];
   3174       1.1    bouyer 
   3175       1.1    bouyer 	REG_WR(sc, BNX_EMAC_MAC_MATCH0, val);
   3176       1.1    bouyer 
   3177       1.1    bouyer 	val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
   3178       1.1    bouyer 		(mac_addr[4] << 8) | mac_addr[5];
   3179       1.1    bouyer 
   3180       1.1    bouyer 	REG_WR(sc, BNX_EMAC_MAC_MATCH1, val);
   3181       1.1    bouyer }
   3182       1.1    bouyer 
   3183       1.1    bouyer /****************************************************************************/
   3184       1.1    bouyer /* Stop the controller.                                                     */
   3185       1.1    bouyer /*                                                                          */
   3186       1.1    bouyer /* Returns:                                                                 */
   3187       1.1    bouyer /*   Nothing.                                                               */
   3188       1.1    bouyer /****************************************************************************/
   3189       1.1    bouyer void
   3190      1.14    dyoung bnx_stop(struct ifnet *ifp, int disable)
   3191       1.1    bouyer {
   3192      1.14    dyoung 	struct bnx_softc *sc = ifp->if_softc;
   3193       1.1    bouyer 
   3194      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Entering %s()\n", __func__);
   3195       1.1    bouyer 
   3196      1.14    dyoung 	if ((ifp->if_flags & IFF_RUNNING) == 0)
   3197      1.14    dyoung 		return;
   3198       1.1    bouyer 
   3199       1.1    bouyer 	callout_stop(&sc->bnx_timeout);
   3200       1.1    bouyer 
   3201      1.14    dyoung 	mii_down(&sc->bnx_mii);
   3202      1.14    dyoung 
   3203       1.1    bouyer 	ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
   3204       1.1    bouyer 
   3205       1.1    bouyer 	/* Disable the transmit/receive blocks. */
   3206       1.1    bouyer 	REG_WR(sc, BNX_MISC_ENABLE_CLR_BITS, 0x5ffffff);
   3207       1.1    bouyer 	REG_RD(sc, BNX_MISC_ENABLE_CLR_BITS);
   3208       1.1    bouyer 	DELAY(20);
   3209       1.1    bouyer 
   3210       1.1    bouyer 	bnx_disable_intr(sc);
   3211       1.1    bouyer 
   3212       1.1    bouyer 	/* Tell firmware that the driver is going away. */
   3213      1.14    dyoung 	if (disable)
   3214      1.14    dyoung 		bnx_reset(sc, BNX_DRV_MSG_CODE_RESET);
   3215      1.14    dyoung 	else
   3216      1.14    dyoung 		bnx_reset(sc, BNX_DRV_MSG_CODE_SUSPEND_NO_WOL);
   3217       1.1    bouyer 
   3218  1.20.4.2  sborrill 	/* Free RX buffers. */
   3219       1.1    bouyer 	bnx_free_rx_chain(sc);
   3220       1.1    bouyer 
   3221       1.1    bouyer 	/* Free TX buffers. */
   3222       1.1    bouyer 	bnx_free_tx_chain(sc);
   3223       1.1    bouyer 
   3224       1.1    bouyer 	ifp->if_timer = 0;
   3225       1.1    bouyer 
   3226      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Exiting %s()\n", __func__);
   3227       1.1    bouyer 
   3228       1.1    bouyer }
   3229       1.1    bouyer 
   3230       1.1    bouyer int
   3231       1.1    bouyer bnx_reset(struct bnx_softc *sc, u_int32_t reset_code)
   3232       1.1    bouyer {
   3233  1.20.4.2  sborrill 	struct pci_attach_args	*pa = &(sc->bnx_pa);
   3234       1.1    bouyer 	u_int32_t		val;
   3235       1.1    bouyer 	int			i, rc = 0;
   3236       1.1    bouyer 
   3237      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Entering %s()\n", __func__);
   3238       1.1    bouyer 
   3239       1.1    bouyer 	/* Wait for pending PCI transactions to complete. */
   3240       1.1    bouyer 	REG_WR(sc, BNX_MISC_ENABLE_CLR_BITS,
   3241       1.1    bouyer 	    BNX_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
   3242       1.1    bouyer 	    BNX_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
   3243       1.1    bouyer 	    BNX_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
   3244       1.1    bouyer 	    BNX_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
   3245       1.1    bouyer 	val = REG_RD(sc, BNX_MISC_ENABLE_CLR_BITS);
   3246       1.1    bouyer 	DELAY(5);
   3247       1.1    bouyer 
   3248  1.20.4.2  sborrill 	/* Disable DMA */
   3249  1.20.4.2  sborrill 	if (BNX_CHIP_NUM(sc) == BNX_CHIP_NUM_5709) {
   3250  1.20.4.2  sborrill 		val = REG_RD(sc, BNX_MISC_NEW_CORE_CTL);
   3251  1.20.4.2  sborrill 		val &= ~BNX_MISC_NEW_CORE_CTL_DMA_ENABLE;
   3252  1.20.4.2  sborrill 		REG_WR(sc, BNX_MISC_NEW_CORE_CTL, val);
   3253  1.20.4.2  sborrill 	}
   3254  1.20.4.2  sborrill 
   3255       1.1    bouyer 	/* Assume bootcode is running. */
   3256       1.1    bouyer 	sc->bnx_fw_timed_out = 0;
   3257       1.1    bouyer 
   3258       1.1    bouyer 	/* Give the firmware a chance to prepare for the reset. */
   3259       1.1    bouyer 	rc = bnx_fw_sync(sc, BNX_DRV_MSG_DATA_WAIT0 | reset_code);
   3260       1.1    bouyer 	if (rc)
   3261       1.1    bouyer 		goto bnx_reset_exit;
   3262       1.1    bouyer 
   3263       1.1    bouyer 	/* Set a firmware reminder that this is a soft reset. */
   3264       1.1    bouyer 	REG_WR_IND(sc, sc->bnx_shmem_base + BNX_DRV_RESET_SIGNATURE,
   3265       1.1    bouyer 	    BNX_DRV_RESET_SIGNATURE_MAGIC);
   3266       1.1    bouyer 
   3267       1.1    bouyer 	/* Dummy read to force the chip to complete all current transactions. */
   3268       1.1    bouyer 	val = REG_RD(sc, BNX_MISC_ID);
   3269       1.1    bouyer 
   3270       1.1    bouyer 	/* Chip reset. */
   3271  1.20.4.2  sborrill 	if (BNX_CHIP_NUM(sc) == BNX_CHIP_NUM_5709) {
   3272  1.20.4.2  sborrill 		REG_WR(sc, BNX_MISC_COMMAND, BNX_MISC_COMMAND_SW_RESET);
   3273  1.20.4.2  sborrill 		REG_RD(sc, BNX_MISC_COMMAND);
   3274  1.20.4.2  sborrill 		DELAY(5);
   3275       1.1    bouyer 
   3276  1.20.4.2  sborrill 		val = BNX_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
   3277  1.20.4.2  sborrill 		      BNX_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
   3278       1.1    bouyer 
   3279  1.20.4.2  sborrill 		pci_conf_write(pa->pa_pc, pa->pa_tag, BNX_PCICFG_MISC_CONFIG,
   3280  1.20.4.2  sborrill 		    val);
   3281  1.20.4.2  sborrill 	} else {
   3282  1.20.4.2  sborrill 		val = BNX_PCICFG_MISC_CONFIG_CORE_RST_REQ |
   3283  1.20.4.2  sborrill 			BNX_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
   3284  1.20.4.2  sborrill 			BNX_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
   3285  1.20.4.2  sborrill 		REG_WR(sc, BNX_PCICFG_MISC_CONFIG, val);
   3286  1.20.4.2  sborrill 
   3287  1.20.4.2  sborrill 		/* Allow up to 30us for reset to complete. */
   3288  1.20.4.2  sborrill 		for (i = 0; i < 10; i++) {
   3289  1.20.4.2  sborrill 			val = REG_RD(sc, BNX_PCICFG_MISC_CONFIG);
   3290  1.20.4.2  sborrill 			if ((val & (BNX_PCICFG_MISC_CONFIG_CORE_RST_REQ |
   3291  1.20.4.2  sborrill 				BNX_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0) {
   3292  1.20.4.2  sborrill 				break;
   3293  1.20.4.2  sborrill 			}
   3294  1.20.4.2  sborrill 			DELAY(10);
   3295  1.20.4.2  sborrill 		}
   3296       1.1    bouyer 
   3297  1.20.4.2  sborrill 		/* Check that reset completed successfully. */
   3298  1.20.4.2  sborrill 		if (val & (BNX_PCICFG_MISC_CONFIG_CORE_RST_REQ |
   3299  1.20.4.2  sborrill 		    BNX_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
   3300  1.20.4.2  sborrill 			BNX_PRINTF(sc, "%s(%d): Reset failed!\n",
   3301  1.20.4.2  sborrill 			    __FILE__, __LINE__);
   3302  1.20.4.2  sborrill 			rc = EBUSY;
   3303  1.20.4.2  sborrill 			goto bnx_reset_exit;
   3304  1.20.4.2  sborrill 		}
   3305       1.1    bouyer 	}
   3306       1.1    bouyer 
   3307       1.1    bouyer 	/* Make sure byte swapping is properly configured. */
   3308       1.1    bouyer 	val = REG_RD(sc, BNX_PCI_SWAP_DIAG0);
   3309       1.1    bouyer 	if (val != 0x01020304) {
   3310       1.1    bouyer 		BNX_PRINTF(sc, "%s(%d): Byte swap is incorrect!\n",
   3311       1.1    bouyer 		    __FILE__, __LINE__);
   3312       1.1    bouyer 		rc = ENODEV;
   3313       1.1    bouyer 		goto bnx_reset_exit;
   3314       1.1    bouyer 	}
   3315       1.1    bouyer 
   3316       1.1    bouyer 	/* Just completed a reset, assume that firmware is running again. */
   3317       1.1    bouyer 	sc->bnx_fw_timed_out = 0;
   3318       1.1    bouyer 
   3319       1.1    bouyer 	/* Wait for the firmware to finish its initialization. */
   3320       1.1    bouyer 	rc = bnx_fw_sync(sc, BNX_DRV_MSG_DATA_WAIT1 | reset_code);
   3321       1.1    bouyer 	if (rc)
   3322       1.1    bouyer 		BNX_PRINTF(sc, "%s(%d): Firmware did not complete "
   3323       1.1    bouyer 		    "initialization!\n", __FILE__, __LINE__);
   3324       1.1    bouyer 
   3325       1.1    bouyer bnx_reset_exit:
   3326      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Exiting %s()\n", __func__);
   3327       1.1    bouyer 
   3328       1.1    bouyer 	return (rc);
   3329       1.1    bouyer }
   3330       1.1    bouyer 
   3331       1.1    bouyer int
   3332       1.1    bouyer bnx_chipinit(struct bnx_softc *sc)
   3333       1.1    bouyer {
   3334       1.1    bouyer 	struct pci_attach_args	*pa = &(sc->bnx_pa);
   3335       1.1    bouyer 	u_int32_t		val;
   3336       1.1    bouyer 	int			rc = 0;
   3337       1.1    bouyer 
   3338      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Entering %s()\n", __func__);
   3339       1.1    bouyer 
   3340       1.1    bouyer 	/* Make sure the interrupt is not active. */
   3341       1.1    bouyer 	REG_WR(sc, BNX_PCICFG_INT_ACK_CMD, BNX_PCICFG_INT_ACK_CMD_MASK_INT);
   3342       1.1    bouyer 
   3343       1.1    bouyer 	/* Initialize DMA byte/word swapping, configure the number of DMA  */
   3344       1.1    bouyer 	/* channels and PCI clock compensation delay.                      */
   3345       1.1    bouyer 	val = BNX_DMA_CONFIG_DATA_BYTE_SWAP |
   3346       1.1    bouyer 	    BNX_DMA_CONFIG_DATA_WORD_SWAP |
   3347       1.1    bouyer #if BYTE_ORDER == BIG_ENDIAN
   3348       1.1    bouyer 	    BNX_DMA_CONFIG_CNTL_BYTE_SWAP |
   3349       1.1    bouyer #endif
   3350       1.1    bouyer 	    BNX_DMA_CONFIG_CNTL_WORD_SWAP |
   3351       1.1    bouyer 	    DMA_READ_CHANS << 12 |
   3352       1.1    bouyer 	    DMA_WRITE_CHANS << 16;
   3353       1.1    bouyer 
   3354       1.1    bouyer 	val |= (0x2 << 20) | BNX_DMA_CONFIG_CNTL_PCI_COMP_DLY;
   3355       1.1    bouyer 
   3356       1.1    bouyer 	if ((sc->bnx_flags & BNX_PCIX_FLAG) && (sc->bus_speed_mhz == 133))
   3357       1.1    bouyer 		val |= BNX_DMA_CONFIG_PCI_FAST_CLK_CMP;
   3358       1.1    bouyer 
   3359       1.1    bouyer 	/*
   3360       1.1    bouyer 	 * This setting resolves a problem observed on certain Intel PCI
   3361       1.1    bouyer 	 * chipsets that cannot handle multiple outstanding DMA operations.
   3362       1.1    bouyer 	 * See errata E9_5706A1_65.
   3363       1.1    bouyer 	 */
   3364       1.1    bouyer 	if ((BNX_CHIP_NUM(sc) == BNX_CHIP_NUM_5706) &&
   3365       1.1    bouyer 	    (BNX_CHIP_ID(sc) != BNX_CHIP_ID_5706_A0) &&
   3366       1.1    bouyer 	    !(sc->bnx_flags & BNX_PCIX_FLAG))
   3367       1.1    bouyer 		val |= BNX_DMA_CONFIG_CNTL_PING_PONG_DMA;
   3368       1.1    bouyer 
   3369       1.1    bouyer 	REG_WR(sc, BNX_DMA_CONFIG, val);
   3370       1.1    bouyer 
   3371       1.1    bouyer 	/* Clear the PCI-X relaxed ordering bit. See errata E3_5708CA0_570. */
   3372       1.1    bouyer 	if (sc->bnx_flags & BNX_PCIX_FLAG) {
   3373  1.20.4.2  sborrill 		val = pci_conf_read(pa->pa_pc, pa->pa_tag, BNX_PCI_PCIX_CMD);
   3374       1.1    bouyer 		pci_conf_write(pa->pa_pc, pa->pa_tag, BNX_PCI_PCIX_CMD,
   3375  1.20.4.2  sborrill 		    val & ~0x20000);
   3376       1.1    bouyer 	}
   3377       1.1    bouyer 
   3378       1.1    bouyer 	/* Enable the RX_V2P and Context state machines before access. */
   3379       1.1    bouyer 	REG_WR(sc, BNX_MISC_ENABLE_SET_BITS,
   3380       1.1    bouyer 	    BNX_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
   3381       1.1    bouyer 	    BNX_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
   3382       1.1    bouyer 	    BNX_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
   3383       1.1    bouyer 
   3384       1.1    bouyer 	/* Initialize context mapping and zero out the quick contexts. */
   3385       1.1    bouyer 	bnx_init_context(sc);
   3386       1.1    bouyer 
   3387       1.1    bouyer 	/* Initialize the on-boards CPUs */
   3388       1.1    bouyer 	bnx_init_cpus(sc);
   3389       1.1    bouyer 
   3390       1.1    bouyer 	/* Prepare NVRAM for access. */
   3391       1.1    bouyer 	if (bnx_init_nvram(sc)) {
   3392       1.1    bouyer 		rc = ENODEV;
   3393       1.1    bouyer 		goto bnx_chipinit_exit;
   3394       1.1    bouyer 	}
   3395       1.1    bouyer 
   3396       1.1    bouyer 	/* Set the kernel bypass block size */
   3397       1.1    bouyer 	val = REG_RD(sc, BNX_MQ_CONFIG);
   3398       1.1    bouyer 	val &= ~BNX_MQ_CONFIG_KNL_BYP_BLK_SIZE;
   3399       1.1    bouyer 	val |= BNX_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
   3400  1.20.4.2  sborrill 
   3401  1.20.4.2  sborrill 	/* Enable bins used on the 5709. */
   3402  1.20.4.2  sborrill 	if (BNX_CHIP_NUM(sc) == BNX_CHIP_NUM_5709) {
   3403  1.20.4.2  sborrill 		val |= BNX_MQ_CONFIG_BIN_MQ_MODE;
   3404  1.20.4.2  sborrill 		if (BNX_CHIP_ID(sc) == BNX_CHIP_ID_5709_A1)
   3405  1.20.4.2  sborrill 			val |= BNX_MQ_CONFIG_HALT_DIS;
   3406  1.20.4.2  sborrill 	}
   3407  1.20.4.2  sborrill 
   3408       1.1    bouyer 	REG_WR(sc, BNX_MQ_CONFIG, val);
   3409       1.1    bouyer 
   3410       1.1    bouyer 	val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
   3411       1.1    bouyer 	REG_WR(sc, BNX_MQ_KNL_BYP_WIND_START, val);
   3412       1.1    bouyer 	REG_WR(sc, BNX_MQ_KNL_WIND_END, val);
   3413       1.1    bouyer 
   3414       1.1    bouyer 	val = (BCM_PAGE_BITS - 8) << 24;
   3415       1.1    bouyer 	REG_WR(sc, BNX_RV2P_CONFIG, val);
   3416       1.1    bouyer 
   3417       1.1    bouyer 	/* Configure page size. */
   3418       1.1    bouyer 	val = REG_RD(sc, BNX_TBDR_CONFIG);
   3419       1.1    bouyer 	val &= ~BNX_TBDR_CONFIG_PAGE_SIZE;
   3420       1.1    bouyer 	val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
   3421       1.1    bouyer 	REG_WR(sc, BNX_TBDR_CONFIG, val);
   3422       1.1    bouyer 
   3423  1.20.4.2  sborrill #if 0
   3424  1.20.4.2  sborrill 	/* Set the perfect match control register to default. */
   3425  1.20.4.2  sborrill 	REG_WR_IND(sc, BNX_RXP_PM_CTRL, 0);
   3426  1.20.4.2  sborrill #endif
   3427  1.20.4.2  sborrill 
   3428       1.1    bouyer bnx_chipinit_exit:
   3429      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Exiting %s()\n", __func__);
   3430       1.1    bouyer 
   3431       1.1    bouyer 	return(rc);
   3432       1.1    bouyer }
   3433       1.1    bouyer 
   3434       1.1    bouyer /****************************************************************************/
   3435       1.1    bouyer /* Initialize the controller in preparation to send/receive traffic.        */
   3436       1.1    bouyer /*                                                                          */
   3437       1.1    bouyer /* Returns:                                                                 */
   3438       1.1    bouyer /*   0 for success, positive value for failure.                             */
   3439       1.1    bouyer /****************************************************************************/
   3440       1.1    bouyer int
   3441       1.1    bouyer bnx_blockinit(struct bnx_softc *sc)
   3442       1.1    bouyer {
   3443       1.1    bouyer 	u_int32_t		reg, val;
   3444       1.1    bouyer 	int 			rc = 0;
   3445       1.1    bouyer 
   3446      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Entering %s()\n", __func__);
   3447       1.1    bouyer 
   3448       1.1    bouyer 	/* Load the hardware default MAC address. */
   3449       1.1    bouyer 	bnx_set_mac_addr(sc);
   3450       1.1    bouyer 
   3451       1.1    bouyer 	/* Set the Ethernet backoff seed value */
   3452       1.1    bouyer 	val = sc->eaddr[0] + (sc->eaddr[1] << 8) + (sc->eaddr[2] << 16) +
   3453       1.1    bouyer 	    (sc->eaddr[3]) + (sc->eaddr[4] << 8) + (sc->eaddr[5] << 16);
   3454       1.1    bouyer 	REG_WR(sc, BNX_EMAC_BACKOFF_SEED, val);
   3455       1.1    bouyer 
   3456       1.1    bouyer 	sc->last_status_idx = 0;
   3457       1.1    bouyer 	sc->rx_mode = BNX_EMAC_RX_MODE_SORT_MODE;
   3458       1.1    bouyer 
   3459       1.1    bouyer 	/* Set up link change interrupt generation. */
   3460       1.1    bouyer 	REG_WR(sc, BNX_EMAC_ATTENTION_ENA, BNX_EMAC_ATTENTION_ENA_LINK);
   3461  1.20.4.2  sborrill 	REG_WR(sc, BNX_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
   3462       1.1    bouyer 
   3463       1.1    bouyer 	/* Program the physical address of the status block. */
   3464       1.1    bouyer 	REG_WR(sc, BNX_HC_STATUS_ADDR_L, (u_int32_t)(sc->status_block_paddr));
   3465       1.1    bouyer 	REG_WR(sc, BNX_HC_STATUS_ADDR_H,
   3466       1.1    bouyer 	    (u_int32_t)((u_int64_t)sc->status_block_paddr >> 32));
   3467       1.1    bouyer 
   3468       1.1    bouyer 	/* Program the physical address of the statistics block. */
   3469       1.1    bouyer 	REG_WR(sc, BNX_HC_STATISTICS_ADDR_L,
   3470       1.1    bouyer 	    (u_int32_t)(sc->stats_block_paddr));
   3471       1.1    bouyer 	REG_WR(sc, BNX_HC_STATISTICS_ADDR_H,
   3472       1.1    bouyer 	    (u_int32_t)((u_int64_t)sc->stats_block_paddr >> 32));
   3473       1.1    bouyer 
   3474       1.1    bouyer 	/* Program various host coalescing parameters. */
   3475       1.1    bouyer 	REG_WR(sc, BNX_HC_TX_QUICK_CONS_TRIP, (sc->bnx_tx_quick_cons_trip_int
   3476       1.1    bouyer 	    << 16) | sc->bnx_tx_quick_cons_trip);
   3477       1.1    bouyer 	REG_WR(sc, BNX_HC_RX_QUICK_CONS_TRIP, (sc->bnx_rx_quick_cons_trip_int
   3478       1.1    bouyer 	    << 16) | sc->bnx_rx_quick_cons_trip);
   3479       1.1    bouyer 	REG_WR(sc, BNX_HC_COMP_PROD_TRIP, (sc->bnx_comp_prod_trip_int << 16) |
   3480       1.1    bouyer 	    sc->bnx_comp_prod_trip);
   3481       1.1    bouyer 	REG_WR(sc, BNX_HC_TX_TICKS, (sc->bnx_tx_ticks_int << 16) |
   3482       1.1    bouyer 	    sc->bnx_tx_ticks);
   3483       1.1    bouyer 	REG_WR(sc, BNX_HC_RX_TICKS, (sc->bnx_rx_ticks_int << 16) |
   3484       1.1    bouyer 	    sc->bnx_rx_ticks);
   3485       1.1    bouyer 	REG_WR(sc, BNX_HC_COM_TICKS, (sc->bnx_com_ticks_int << 16) |
   3486       1.1    bouyer 	    sc->bnx_com_ticks);
   3487       1.1    bouyer 	REG_WR(sc, BNX_HC_CMD_TICKS, (sc->bnx_cmd_ticks_int << 16) |
   3488       1.1    bouyer 	    sc->bnx_cmd_ticks);
   3489       1.1    bouyer 	REG_WR(sc, BNX_HC_STATS_TICKS, (sc->bnx_stats_ticks & 0xffff00));
   3490       1.1    bouyer 	REG_WR(sc, BNX_HC_STAT_COLLECT_TICKS, 0xbb8);  /* 3ms */
   3491       1.1    bouyer 	REG_WR(sc, BNX_HC_CONFIG,
   3492       1.1    bouyer 	    (BNX_HC_CONFIG_RX_TMR_MODE | BNX_HC_CONFIG_TX_TMR_MODE |
   3493       1.1    bouyer 	    BNX_HC_CONFIG_COLLECT_STATS));
   3494       1.1    bouyer 
   3495       1.1    bouyer 	/* Clear the internal statistics counters. */
   3496       1.1    bouyer 	REG_WR(sc, BNX_HC_COMMAND, BNX_HC_COMMAND_CLR_STAT_NOW);
   3497       1.1    bouyer 
   3498       1.1    bouyer 	/* Verify that bootcode is running. */
   3499       1.1    bouyer 	reg = REG_RD_IND(sc, sc->bnx_shmem_base + BNX_DEV_INFO_SIGNATURE);
   3500       1.1    bouyer 
   3501       1.1    bouyer 	DBRUNIF(DB_RANDOMTRUE(bnx_debug_bootcode_running_failure),
   3502       1.1    bouyer 	    BNX_PRINTF(sc, "%s(%d): Simulating bootcode failure.\n",
   3503       1.1    bouyer 	    __FILE__, __LINE__); reg = 0);
   3504       1.1    bouyer 
   3505       1.1    bouyer 	if ((reg & BNX_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
   3506       1.1    bouyer 	    BNX_DEV_INFO_SIGNATURE_MAGIC) {
   3507       1.1    bouyer 		BNX_PRINTF(sc, "%s(%d): Bootcode not running! Found: 0x%08X, "
   3508       1.1    bouyer 		    "Expected: 08%08X\n", __FILE__, __LINE__,
   3509       1.1    bouyer 		    (reg & BNX_DEV_INFO_SIGNATURE_MAGIC_MASK),
   3510       1.1    bouyer 		    BNX_DEV_INFO_SIGNATURE_MAGIC);
   3511       1.1    bouyer 		rc = ENODEV;
   3512       1.1    bouyer 		goto bnx_blockinit_exit;
   3513       1.1    bouyer 	}
   3514       1.1    bouyer 
   3515       1.1    bouyer 	/* Check if any management firmware is running. */
   3516       1.1    bouyer 	reg = REG_RD_IND(sc, sc->bnx_shmem_base + BNX_PORT_FEATURE);
   3517       1.1    bouyer 	if (reg & (BNX_PORT_FEATURE_ASF_ENABLED |
   3518       1.1    bouyer 	    BNX_PORT_FEATURE_IMD_ENABLED)) {
   3519       1.1    bouyer 		DBPRINT(sc, BNX_INFO, "Management F/W Enabled.\n");
   3520       1.1    bouyer 		sc->bnx_flags |= BNX_MFW_ENABLE_FLAG;
   3521       1.1    bouyer 	}
   3522       1.1    bouyer 
   3523       1.1    bouyer 	sc->bnx_fw_ver = REG_RD_IND(sc, sc->bnx_shmem_base +
   3524       1.1    bouyer 	    BNX_DEV_INFO_BC_REV);
   3525       1.1    bouyer 
   3526       1.1    bouyer 	DBPRINT(sc, BNX_INFO, "bootcode rev = 0x%08X\n", sc->bnx_fw_ver);
   3527       1.1    bouyer 
   3528  1.20.4.2  sborrill 	/* Enable DMA */
   3529  1.20.4.2  sborrill 	if (BNX_CHIP_NUM(sc) == BNX_CHIP_NUM_5709) {
   3530  1.20.4.2  sborrill 		val = REG_RD(sc, BNX_MISC_NEW_CORE_CTL);
   3531  1.20.4.2  sborrill 		val |= BNX_MISC_NEW_CORE_CTL_DMA_ENABLE;
   3532  1.20.4.2  sborrill 		REG_WR(sc, BNX_MISC_NEW_CORE_CTL, val);
   3533  1.20.4.2  sborrill 	}
   3534  1.20.4.2  sborrill 
   3535       1.1    bouyer 	/* Allow bootcode to apply any additional fixes before enabling MAC. */
   3536       1.1    bouyer 	rc = bnx_fw_sync(sc, BNX_DRV_MSG_DATA_WAIT2 | BNX_DRV_MSG_CODE_RESET);
   3537       1.1    bouyer 
   3538       1.1    bouyer 	/* Enable link state change interrupt generation. */
   3539  1.20.4.2  sborrill 	if (BNX_CHIP_NUM(sc) == BNX_CHIP_NUM_5709) {
   3540  1.20.4.2  sborrill 		REG_WR(sc, BNX_MISC_ENABLE_SET_BITS,
   3541  1.20.4.2  sborrill 		    BNX_MISC_ENABLE_DEFAULT_XI);
   3542  1.20.4.2  sborrill 	} else
   3543  1.20.4.2  sborrill 		REG_WR(sc, BNX_MISC_ENABLE_SET_BITS, BNX_MISC_ENABLE_DEFAULT);
   3544       1.1    bouyer 
   3545       1.1    bouyer 	/* Enable all remaining blocks in the MAC. */
   3546       1.1    bouyer 	REG_WR(sc, BNX_MISC_ENABLE_SET_BITS, 0x5ffffff);
   3547       1.1    bouyer 	REG_RD(sc, BNX_MISC_ENABLE_SET_BITS);
   3548       1.1    bouyer 	DELAY(20);
   3549       1.1    bouyer 
   3550       1.1    bouyer bnx_blockinit_exit:
   3551      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Exiting %s()\n", __func__);
   3552       1.1    bouyer 
   3553       1.1    bouyer 	return (rc);
   3554       1.1    bouyer }
   3555       1.1    bouyer 
   3556  1.20.4.1    bouyer static int
   3557  1.20.4.1    bouyer bnx_add_buf(struct bnx_softc *sc, struct mbuf *m_new, u_int16_t *prod,
   3558  1.20.4.1    bouyer     u_int16_t *chain_prod, u_int32_t *prod_bseq)
   3559  1.20.4.1    bouyer {
   3560  1.20.4.1    bouyer 	bus_dmamap_t		map;
   3561  1.20.4.1    bouyer 	struct rx_bd		*rxbd;
   3562  1.20.4.1    bouyer 	u_int32_t		addr;
   3563  1.20.4.1    bouyer 	int i;
   3564  1.20.4.1    bouyer #ifdef BNX_DEBUG
   3565  1.20.4.1    bouyer 	u_int16_t debug_chain_prod =	*chain_prod;
   3566  1.20.4.1    bouyer #endif
   3567  1.20.4.1    bouyer 	u_int16_t first_chain_prod;
   3568  1.20.4.1    bouyer 
   3569  1.20.4.1    bouyer 	m_new->m_len = m_new->m_pkthdr.len = sc->mbuf_alloc_size;
   3570  1.20.4.1    bouyer 
   3571  1.20.4.1    bouyer 	/* Map the mbuf cluster into device memory. */
   3572  1.20.4.1    bouyer 	map = sc->rx_mbuf_map[*chain_prod];
   3573  1.20.4.1    bouyer 	first_chain_prod = *chain_prod;
   3574  1.20.4.1    bouyer 	if (bus_dmamap_load_mbuf(sc->bnx_dmatag, map, m_new, BUS_DMA_NOWAIT)) {
   3575  1.20.4.1    bouyer 		BNX_PRINTF(sc, "%s(%d): Error mapping mbuf into RX chain!\n",
   3576  1.20.4.1    bouyer 		    __FILE__, __LINE__);
   3577  1.20.4.1    bouyer 
   3578  1.20.4.1    bouyer 		m_freem(m_new);
   3579  1.20.4.1    bouyer 
   3580  1.20.4.1    bouyer 		DBRUNIF(1, sc->rx_mbuf_alloc--);
   3581  1.20.4.1    bouyer 
   3582  1.20.4.1    bouyer 		return ENOBUFS;
   3583  1.20.4.1    bouyer 	}
   3584  1.20.4.2  sborrill 	/* Make sure there is room in the receive chain. */
   3585  1.20.4.2  sborrill 	if (map->dm_nsegs > sc->free_rx_bd) {
   3586  1.20.4.2  sborrill 		bus_dmamap_unload(sc->bnx_dmatag, map);
   3587  1.20.4.2  sborrill 		m_freem(m_new);
   3588  1.20.4.2  sborrill 		return EFBIG;
   3589  1.20.4.2  sborrill 	}
   3590  1.20.4.2  sborrill #ifdef BNX_DEBUG
   3591  1.20.4.2  sborrill 	/* Track the distribution of buffer segments. */
   3592  1.20.4.2  sborrill 	sc->rx_mbuf_segs[map->dm_nsegs]++;
   3593  1.20.4.2  sborrill #endif
   3594  1.20.4.2  sborrill 
   3595  1.20.4.1    bouyer 	bus_dmamap_sync(sc->bnx_dmatag, map, 0, map->dm_mapsize,
   3596  1.20.4.1    bouyer 	    BUS_DMASYNC_PREREAD);
   3597  1.20.4.1    bouyer 
   3598  1.20.4.2  sborrill 	/* Update some debug statistics counters */
   3599  1.20.4.1    bouyer 	DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
   3600  1.20.4.1    bouyer 	    sc->rx_low_watermark = sc->free_rx_bd);
   3601  1.20.4.2  sborrill 	DBRUNIF((sc->free_rx_bd == sc->max_rx_bd), sc->rx_empty_count++);
   3602  1.20.4.1    bouyer 
   3603  1.20.4.1    bouyer 	/*
   3604  1.20.4.1    bouyer 	 * Setup the rx_bd for the first segment
   3605  1.20.4.1    bouyer 	 */
   3606  1.20.4.1    bouyer 	rxbd = &sc->rx_bd_chain[RX_PAGE(*chain_prod)][RX_IDX(*chain_prod)];
   3607  1.20.4.1    bouyer 
   3608  1.20.4.1    bouyer 	addr = (u_int32_t)(map->dm_segs[0].ds_addr);
   3609  1.20.4.1    bouyer 	rxbd->rx_bd_haddr_lo = htole32(addr);
   3610  1.20.4.1    bouyer 	addr = (u_int32_t)((u_int64_t)map->dm_segs[0].ds_addr >> 32);
   3611  1.20.4.1    bouyer 	rxbd->rx_bd_haddr_hi = htole32(addr);
   3612  1.20.4.1    bouyer 	rxbd->rx_bd_len = htole32(map->dm_segs[0].ds_len);
   3613  1.20.4.1    bouyer 	rxbd->rx_bd_flags = htole32(RX_BD_FLAGS_START);
   3614  1.20.4.1    bouyer 	*prod_bseq += map->dm_segs[0].ds_len;
   3615  1.20.4.1    bouyer 	bus_dmamap_sync(sc->bnx_dmatag,
   3616  1.20.4.1    bouyer 	    sc->rx_bd_chain_map[RX_PAGE(*chain_prod)],
   3617  1.20.4.1    bouyer 	    sizeof(struct rx_bd) * RX_IDX(*chain_prod), sizeof(struct rx_bd),
   3618  1.20.4.1    bouyer 	    BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
   3619  1.20.4.1    bouyer 
   3620  1.20.4.1    bouyer 	for (i = 1; i < map->dm_nsegs; i++) {
   3621  1.20.4.1    bouyer 		*prod = NEXT_RX_BD(*prod);
   3622  1.20.4.1    bouyer 		*chain_prod = RX_CHAIN_IDX(*prod);
   3623  1.20.4.1    bouyer 
   3624  1.20.4.1    bouyer 		rxbd =
   3625  1.20.4.1    bouyer 		    &sc->rx_bd_chain[RX_PAGE(*chain_prod)][RX_IDX(*chain_prod)];
   3626  1.20.4.1    bouyer 
   3627  1.20.4.1    bouyer 		addr = (u_int32_t)(map->dm_segs[i].ds_addr);
   3628  1.20.4.1    bouyer 		rxbd->rx_bd_haddr_lo = htole32(addr);
   3629  1.20.4.1    bouyer 		addr = (u_int32_t)((u_int64_t)map->dm_segs[i].ds_addr >> 32);
   3630  1.20.4.1    bouyer 		rxbd->rx_bd_haddr_hi = htole32(addr);
   3631  1.20.4.1    bouyer 		rxbd->rx_bd_len = htole32(map->dm_segs[i].ds_len);
   3632  1.20.4.1    bouyer 		rxbd->rx_bd_flags = 0;
   3633  1.20.4.1    bouyer 		*prod_bseq += map->dm_segs[i].ds_len;
   3634  1.20.4.1    bouyer 		bus_dmamap_sync(sc->bnx_dmatag,
   3635  1.20.4.1    bouyer 		    sc->rx_bd_chain_map[RX_PAGE(*chain_prod)],
   3636  1.20.4.1    bouyer 		    sizeof(struct rx_bd) * RX_IDX(*chain_prod),
   3637  1.20.4.1    bouyer 		    sizeof(struct rx_bd), BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
   3638  1.20.4.1    bouyer 	}
   3639  1.20.4.1    bouyer 
   3640  1.20.4.1    bouyer 	rxbd->rx_bd_flags |= htole32(RX_BD_FLAGS_END);
   3641  1.20.4.1    bouyer 	bus_dmamap_sync(sc->bnx_dmatag,
   3642  1.20.4.1    bouyer 	    sc->rx_bd_chain_map[RX_PAGE(*chain_prod)],
   3643  1.20.4.1    bouyer 	    sizeof(struct rx_bd) * RX_IDX(*chain_prod),
   3644  1.20.4.1    bouyer 	    sizeof(struct rx_bd), BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
   3645  1.20.4.1    bouyer 
   3646  1.20.4.1    bouyer 	/*
   3647  1.20.4.1    bouyer 	 * Save the mbuf, ajust the map pointer (swap map for first and
   3648  1.20.4.1    bouyer 	 * last rx_bd entry to that rx_mbuf_ptr and rx_mbuf_map matches)
   3649  1.20.4.1    bouyer 	 * and update counter.
   3650  1.20.4.1    bouyer 	 */
   3651  1.20.4.1    bouyer 	sc->rx_mbuf_ptr[*chain_prod] = m_new;
   3652  1.20.4.1    bouyer 	sc->rx_mbuf_map[first_chain_prod] = sc->rx_mbuf_map[*chain_prod];
   3653  1.20.4.1    bouyer 	sc->rx_mbuf_map[*chain_prod] = map;
   3654  1.20.4.1    bouyer 	sc->free_rx_bd -= map->dm_nsegs;
   3655  1.20.4.1    bouyer 
   3656  1.20.4.1    bouyer 	DBRUN(BNX_VERBOSE_RECV, bnx_dump_rx_mbuf_chain(sc, debug_chain_prod,
   3657  1.20.4.1    bouyer 	    map->dm_nsegs));
   3658  1.20.4.1    bouyer 	*prod = NEXT_RX_BD(*prod);
   3659  1.20.4.1    bouyer 	*chain_prod = RX_CHAIN_IDX(*prod);
   3660  1.20.4.1    bouyer 
   3661  1.20.4.1    bouyer 	return 0;
   3662  1.20.4.1    bouyer }
   3663  1.20.4.1    bouyer 
   3664       1.1    bouyer /****************************************************************************/
   3665       1.1    bouyer /* Encapsulate an mbuf cluster into the rx_bd chain.                        */
   3666       1.1    bouyer /*                                                                          */
   3667       1.1    bouyer /* The NetXtreme II can support Jumbo frames by using multiple rx_bd's.     */
   3668       1.1    bouyer /* This routine will map an mbuf cluster into 1 or more rx_bd's as          */
   3669       1.1    bouyer /* necessary.                                                               */
   3670       1.1    bouyer /*                                                                          */
   3671       1.1    bouyer /* Returns:                                                                 */
   3672       1.1    bouyer /*   0 for success, positive value for failure.                             */
   3673       1.1    bouyer /****************************************************************************/
   3674       1.1    bouyer int
   3675  1.20.4.1    bouyer bnx_get_buf(struct bnx_softc *sc, u_int16_t *prod,
   3676       1.1    bouyer     u_int16_t *chain_prod, u_int32_t *prod_bseq)
   3677       1.1    bouyer {
   3678       1.1    bouyer 	struct mbuf 		*m_new = NULL;
   3679  1.20.4.1    bouyer 	int			rc = 0;
   3680       1.5    bouyer 	u_int16_t min_free_bd;
   3681       1.1    bouyer 
   3682       1.1    bouyer 	DBPRINT(sc, (BNX_VERBOSE_RESET | BNX_VERBOSE_RECV), "Entering %s()\n",
   3683      1.12     perry 	    __func__);
   3684       1.1    bouyer 
   3685       1.1    bouyer 	/* Make sure the inputs are valid. */
   3686       1.1    bouyer 	DBRUNIF((*chain_prod > MAX_RX_BD),
   3687      1.13    dyoung 	    aprint_error_dev(sc->bnx_dev,
   3688      1.13    dyoung 	        "RX producer out of range: 0x%04X > 0x%04X\n",
   3689      1.13    dyoung 		*chain_prod, (u_int16_t)MAX_RX_BD));
   3690       1.1    bouyer 
   3691       1.1    bouyer 	DBPRINT(sc, BNX_VERBOSE_RECV, "%s(enter): prod = 0x%04X, chain_prod = "
   3692      1.12     perry 	    "0x%04X, prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod,
   3693       1.1    bouyer 	    *prod_bseq);
   3694       1.1    bouyer 
   3695       1.5    bouyer 	/* try to get in as many mbufs as possible */
   3696       1.5    bouyer 	if (sc->mbuf_alloc_size == MCLBYTES)
   3697       1.5    bouyer 		min_free_bd = (MCLBYTES + PAGE_SIZE - 1) / PAGE_SIZE;
   3698       1.5    bouyer 	else
   3699       1.5    bouyer 		min_free_bd = (BNX_MAX_MRU + PAGE_SIZE - 1) / PAGE_SIZE;
   3700       1.5    bouyer 	while (sc->free_rx_bd >= min_free_bd) {
   3701  1.20.4.2  sborrill 		/* Simulate an mbuf allocation failure. */
   3702  1.20.4.1    bouyer 		DBRUNIF(DB_RANDOMTRUE(bnx_debug_mbuf_allocation_failure),
   3703  1.20.4.2  sborrill 		    aprint_error_dev(sc->bnx_dev,
   3704  1.20.4.2  sborrill 		    "Simulating mbuf allocation failure.\n");
   3705  1.20.4.2  sborrill 			sc->mbuf_sim_alloc_failed++;
   3706  1.20.4.1    bouyer 			rc = ENOBUFS;
   3707  1.20.4.1    bouyer 			goto bnx_get_buf_exit);
   3708       1.1    bouyer 
   3709  1.20.4.1    bouyer 		/* This is a new mbuf allocation. */
   3710  1.20.4.1    bouyer 		MGETHDR(m_new, M_DONTWAIT, MT_DATA);
   3711  1.20.4.1    bouyer 		if (m_new == NULL) {
   3712  1.20.4.1    bouyer 			DBPRINT(sc, BNX_WARN,
   3713  1.20.4.1    bouyer 			    "%s(%d): RX mbuf header allocation failed!\n",
   3714  1.20.4.1    bouyer 			    __FILE__, __LINE__);
   3715       1.1    bouyer 
   3716  1.20.4.2  sborrill 			sc->mbuf_alloc_failed++;
   3717       1.1    bouyer 
   3718  1.20.4.1    bouyer 			rc = ENOBUFS;
   3719  1.20.4.1    bouyer 			goto bnx_get_buf_exit;
   3720  1.20.4.1    bouyer 		}
   3721       1.1    bouyer 
   3722  1.20.4.1    bouyer 		DBRUNIF(1, sc->rx_mbuf_alloc++);
   3723  1.20.4.2  sborrill 
   3724  1.20.4.2  sborrill 		/* Simulate an mbuf cluster allocation failure. */
   3725  1.20.4.2  sborrill 		DBRUNIF(DB_RANDOMTRUE(bnx_debug_mbuf_allocation_failure),
   3726  1.20.4.2  sborrill 			m_freem(m_new);
   3727  1.20.4.2  sborrill 			sc->rx_mbuf_alloc--;
   3728  1.20.4.2  sborrill 			sc->mbuf_alloc_failed++;
   3729  1.20.4.2  sborrill 			sc->mbuf_sim_alloc_failed++;
   3730  1.20.4.2  sborrill 			rc = ENOBUFS;
   3731  1.20.4.2  sborrill 			goto bnx_get_buf_exit);
   3732  1.20.4.2  sborrill 
   3733  1.20.4.1    bouyer 		if (sc->mbuf_alloc_size == MCLBYTES)
   3734  1.20.4.1    bouyer 			MCLGET(m_new, M_DONTWAIT);
   3735  1.20.4.1    bouyer 		else
   3736  1.20.4.1    bouyer 			MEXTMALLOC(m_new, sc->mbuf_alloc_size,
   3737  1.20.4.1    bouyer 			    M_DONTWAIT);
   3738  1.20.4.1    bouyer 		if (!(m_new->m_flags & M_EXT)) {
   3739  1.20.4.1    bouyer 			DBPRINT(sc, BNX_WARN,
   3740  1.20.4.1    bouyer 			    "%s(%d): RX mbuf chain allocation failed!\n",
   3741       1.1    bouyer 			    __FILE__, __LINE__);
   3742  1.20.4.1    bouyer 
   3743       1.1    bouyer 			m_freem(m_new);
   3744       1.1    bouyer 
   3745       1.1    bouyer 			DBRUNIF(1, sc->rx_mbuf_alloc--);
   3746  1.20.4.2  sborrill 			sc->mbuf_alloc_failed++;
   3747       1.1    bouyer 
   3748       1.1    bouyer 			rc = ENOBUFS;
   3749       1.1    bouyer 			goto bnx_get_buf_exit;
   3750       1.1    bouyer 		}
   3751  1.20.4.1    bouyer 
   3752  1.20.4.1    bouyer 		rc = bnx_add_buf(sc, m_new, prod, chain_prod, prod_bseq);
   3753  1.20.4.1    bouyer 		if (rc != 0)
   3754  1.20.4.1    bouyer 			goto bnx_get_buf_exit;
   3755       1.5    bouyer 	}
   3756       1.1    bouyer 
   3757       1.5    bouyer bnx_get_buf_exit:
   3758       1.1    bouyer 	DBPRINT(sc, BNX_VERBOSE_RECV, "%s(exit): prod = 0x%04X, chain_prod "
   3759      1.12     perry 	    "= 0x%04X, prod_bseq = 0x%08X\n", __func__, *prod,
   3760       1.1    bouyer 	    *chain_prod, *prod_bseq);
   3761       1.1    bouyer 
   3762       1.1    bouyer 	DBPRINT(sc, (BNX_VERBOSE_RESET | BNX_VERBOSE_RECV), "Exiting %s()\n",
   3763      1.12     perry 	    __func__);
   3764       1.1    bouyer 
   3765       1.1    bouyer 	return(rc);
   3766       1.1    bouyer }
   3767       1.1    bouyer 
   3768  1.20.4.2  sborrill int
   3769  1.20.4.2  sborrill bnx_alloc_pkts(struct bnx_softc *sc)
   3770  1.20.4.2  sborrill {
   3771  1.20.4.2  sborrill 	struct ifnet *ifp = &sc->bnx_ec.ec_if;
   3772  1.20.4.2  sborrill 	struct bnx_pkt *pkt;
   3773  1.20.4.2  sborrill 	int i;
   3774  1.20.4.2  sborrill 
   3775  1.20.4.2  sborrill 	for (i = 0; i < 4; i++) { /* magic! */
   3776  1.20.4.2  sborrill 		pkt = pool_get(bnx_tx_pool, PR_NOWAIT);
   3777  1.20.4.2  sborrill 		if (pkt == NULL)
   3778  1.20.4.2  sborrill 			break;
   3779  1.20.4.2  sborrill 
   3780  1.20.4.2  sborrill 		if (bus_dmamap_create(sc->bnx_dmatag,
   3781  1.20.4.2  sborrill 		    MCLBYTES * BNX_MAX_SEGMENTS, USABLE_TX_BD,
   3782  1.20.4.2  sborrill 		    MCLBYTES, 0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
   3783  1.20.4.2  sborrill 		    &pkt->pkt_dmamap) != 0)
   3784  1.20.4.2  sborrill 			goto put;
   3785  1.20.4.2  sborrill 
   3786  1.20.4.2  sborrill 		if (!ISSET(ifp->if_flags, IFF_UP))
   3787  1.20.4.2  sborrill 			goto stopping;
   3788  1.20.4.2  sborrill 
   3789  1.20.4.2  sborrill 		mutex_enter(&sc->tx_pkt_mtx);
   3790  1.20.4.2  sborrill 		TAILQ_INSERT_TAIL(&sc->tx_free_pkts, pkt, pkt_entry);
   3791  1.20.4.2  sborrill 		sc->tx_pkt_count++;
   3792  1.20.4.2  sborrill 		mutex_exit(&sc->tx_pkt_mtx);
   3793  1.20.4.2  sborrill 	}
   3794  1.20.4.2  sborrill 
   3795  1.20.4.2  sborrill 	return (i == 0) ? ENOMEM : 0;
   3796  1.20.4.2  sborrill 
   3797  1.20.4.2  sborrill stopping:
   3798  1.20.4.2  sborrill 	bus_dmamap_destroy(sc->bnx_dmatag, pkt->pkt_dmamap);
   3799  1.20.4.2  sborrill put:
   3800  1.20.4.2  sborrill 	pool_put(bnx_tx_pool, pkt);
   3801  1.20.4.2  sborrill 	return (i == 0) ? ENOMEM : 0;
   3802  1.20.4.2  sborrill }
   3803  1.20.4.2  sborrill 
   3804  1.20.4.2  sborrill /****************************************************************************/
   3805  1.20.4.2  sborrill /* Initialize the TX context memory.                                        */
   3806  1.20.4.2  sborrill /*                                                                          */
   3807  1.20.4.2  sborrill /* Returns:                                                                 */
   3808  1.20.4.2  sborrill /*   Nothing                                                                */
   3809  1.20.4.2  sborrill /****************************************************************************/
   3810  1.20.4.2  sborrill void
   3811  1.20.4.2  sborrill bnx_init_tx_context(struct bnx_softc *sc)
   3812  1.20.4.2  sborrill {
   3813  1.20.4.2  sborrill 	u_int32_t val;
   3814  1.20.4.2  sborrill 
   3815  1.20.4.2  sborrill 	/* Initialize the context ID for an L2 TX chain. */
   3816  1.20.4.2  sborrill 	if (BNX_CHIP_NUM(sc) == BNX_CHIP_NUM_5709) {
   3817  1.20.4.2  sborrill 		/* Set the CID type to support an L2 connection. */
   3818  1.20.4.2  sborrill 		val = BNX_L2CTX_TYPE_TYPE_L2 | BNX_L2CTX_TYPE_SIZE_L2;
   3819  1.20.4.2  sborrill 		CTX_WR(sc, GET_CID_ADDR(TX_CID), BNX_L2CTX_TYPE_XI, val);
   3820  1.20.4.2  sborrill 		val = BNX_L2CTX_CMD_TYPE_TYPE_L2 | (8 << 16);
   3821  1.20.4.2  sborrill 		CTX_WR(sc, GET_CID_ADDR(TX_CID), BNX_L2CTX_CMD_TYPE_XI, val);
   3822  1.20.4.2  sborrill 
   3823  1.20.4.2  sborrill 		/* Point the hardware to the first page in the chain. */
   3824  1.20.4.2  sborrill 		val = (u_int32_t)((u_int64_t)sc->tx_bd_chain_paddr[0] >> 32);
   3825  1.20.4.2  sborrill 		CTX_WR(sc, GET_CID_ADDR(TX_CID),
   3826  1.20.4.2  sborrill 		    BNX_L2CTX_TBDR_BHADDR_HI_XI, val);
   3827  1.20.4.2  sborrill 		val = (u_int32_t)(sc->tx_bd_chain_paddr[0]);
   3828  1.20.4.2  sborrill 		CTX_WR(sc, GET_CID_ADDR(TX_CID),
   3829  1.20.4.2  sborrill 		    BNX_L2CTX_TBDR_BHADDR_LO_XI, val);
   3830  1.20.4.2  sborrill 	} else {
   3831  1.20.4.2  sborrill 		/* Set the CID type to support an L2 connection. */
   3832  1.20.4.2  sborrill 		val = BNX_L2CTX_TYPE_TYPE_L2 | BNX_L2CTX_TYPE_SIZE_L2;
   3833  1.20.4.2  sborrill 		CTX_WR(sc, GET_CID_ADDR(TX_CID), BNX_L2CTX_TYPE, val);
   3834  1.20.4.2  sborrill 		val = BNX_L2CTX_CMD_TYPE_TYPE_L2 | (8 << 16);
   3835  1.20.4.2  sborrill 		CTX_WR(sc, GET_CID_ADDR(TX_CID), BNX_L2CTX_CMD_TYPE, val);
   3836  1.20.4.2  sborrill 
   3837  1.20.4.2  sborrill 		/* Point the hardware to the first page in the chain. */
   3838  1.20.4.2  sborrill 		val = (u_int32_t)((u_int64_t)sc->tx_bd_chain_paddr[0] >> 32);
   3839  1.20.4.2  sborrill 		CTX_WR(sc, GET_CID_ADDR(TX_CID), BNX_L2CTX_TBDR_BHADDR_HI, val);
   3840  1.20.4.2  sborrill 		val = (u_int32_t)(sc->tx_bd_chain_paddr[0]);
   3841  1.20.4.2  sborrill 		CTX_WR(sc, GET_CID_ADDR(TX_CID), BNX_L2CTX_TBDR_BHADDR_LO, val);
   3842  1.20.4.2  sborrill 	}
   3843  1.20.4.2  sborrill }
   3844  1.20.4.2  sborrill 
   3845  1.20.4.2  sborrill 
   3846       1.1    bouyer /****************************************************************************/
   3847       1.1    bouyer /* Allocate memory and initialize the TX data structures.                   */
   3848       1.1    bouyer /*                                                                          */
   3849       1.1    bouyer /* Returns:                                                                 */
   3850       1.1    bouyer /*   0 for success, positive value for failure.                             */
   3851       1.1    bouyer /****************************************************************************/
   3852       1.1    bouyer int
   3853       1.1    bouyer bnx_init_tx_chain(struct bnx_softc *sc)
   3854       1.1    bouyer {
   3855       1.1    bouyer 	struct tx_bd		*txbd;
   3856  1.20.4.2  sborrill 	u_int32_t		addr;
   3857       1.1    bouyer 	int			i, rc = 0;
   3858       1.1    bouyer 
   3859      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Entering %s()\n", __func__);
   3860       1.1    bouyer 
   3861  1.20.4.2  sborrill 	/* Force an allocation of some dmamaps for tx up front */
   3862  1.20.4.2  sborrill 	bnx_alloc_pkts(sc);
   3863  1.20.4.2  sborrill 
   3864       1.1    bouyer 	/* Set the initial TX producer/consumer indices. */
   3865       1.1    bouyer 	sc->tx_prod = 0;
   3866       1.1    bouyer 	sc->tx_cons = 0;
   3867       1.1    bouyer 	sc->tx_prod_bseq = 0;
   3868       1.1    bouyer 	sc->used_tx_bd = 0;
   3869  1.20.4.2  sborrill 	sc->max_tx_bd = USABLE_TX_BD;
   3870       1.1    bouyer 	DBRUNIF(1, sc->tx_hi_watermark = USABLE_TX_BD);
   3871  1.20.4.2  sborrill 	DBRUNIF(1, sc->tx_full_count = 0);
   3872       1.1    bouyer 
   3873       1.1    bouyer 	/*
   3874       1.1    bouyer 	 * The NetXtreme II supports a linked-list structure called
   3875       1.1    bouyer 	 * a Buffer Descriptor Chain (or BD chain).  A BD chain
   3876       1.1    bouyer 	 * consists of a series of 1 or more chain pages, each of which
   3877       1.1    bouyer 	 * consists of a fixed number of BD entries.
   3878       1.1    bouyer 	 * The last BD entry on each page is a pointer to the next page
   3879       1.1    bouyer 	 * in the chain, and the last pointer in the BD chain
   3880       1.1    bouyer 	 * points back to the beginning of the chain.
   3881       1.1    bouyer 	 */
   3882       1.1    bouyer 
   3883       1.1    bouyer 	/* Set the TX next pointer chain entries. */
   3884       1.1    bouyer 	for (i = 0; i < TX_PAGES; i++) {
   3885       1.1    bouyer 		int j;
   3886       1.1    bouyer 
   3887       1.1    bouyer 		txbd = &sc->tx_bd_chain[i][USABLE_TX_BD_PER_PAGE];
   3888       1.1    bouyer 
   3889       1.1    bouyer 		/* Check if we've reached the last page. */
   3890       1.1    bouyer 		if (i == (TX_PAGES - 1))
   3891       1.1    bouyer 			j = 0;
   3892       1.1    bouyer 		else
   3893       1.1    bouyer 			j = i + 1;
   3894       1.1    bouyer 
   3895       1.1    bouyer 		addr = (u_int32_t)(sc->tx_bd_chain_paddr[j]);
   3896       1.1    bouyer 		txbd->tx_bd_haddr_lo = htole32(addr);
   3897       1.1    bouyer 		addr = (u_int32_t)((u_int64_t)sc->tx_bd_chain_paddr[j] >> 32);
   3898       1.1    bouyer 		txbd->tx_bd_haddr_hi = htole32(addr);
   3899       1.1    bouyer 		bus_dmamap_sync(sc->bnx_dmatag, sc->tx_bd_chain_map[i], 0,
   3900       1.1    bouyer 		    BNX_TX_CHAIN_PAGE_SZ, BUS_DMASYNC_PREWRITE);
   3901       1.1    bouyer 	}
   3902       1.1    bouyer 
   3903       1.1    bouyer 	/*
   3904       1.1    bouyer 	 * Initialize the context ID for an L2 TX chain.
   3905       1.1    bouyer 	 */
   3906  1.20.4.2  sborrill 	bnx_init_tx_context(sc);
   3907       1.1    bouyer 
   3908      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Exiting %s()\n", __func__);
   3909       1.1    bouyer 
   3910       1.1    bouyer 	return(rc);
   3911       1.1    bouyer }
   3912       1.1    bouyer 
   3913       1.1    bouyer /****************************************************************************/
   3914       1.1    bouyer /* Free memory and clear the TX data structures.                            */
   3915       1.1    bouyer /*                                                                          */
   3916       1.1    bouyer /* Returns:                                                                 */
   3917       1.1    bouyer /*   Nothing.                                                               */
   3918       1.1    bouyer /****************************************************************************/
   3919       1.1    bouyer void
   3920       1.1    bouyer bnx_free_tx_chain(struct bnx_softc *sc)
   3921       1.1    bouyer {
   3922  1.20.4.2  sborrill 	struct bnx_pkt		*pkt;
   3923       1.1    bouyer 	int			i;
   3924       1.1    bouyer 
   3925      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Entering %s()\n", __func__);
   3926       1.1    bouyer 
   3927       1.1    bouyer 	/* Unmap, unload, and free any mbufs still in the TX mbuf chain. */
   3928  1.20.4.2  sborrill 	mutex_enter(&sc->tx_pkt_mtx);
   3929  1.20.4.2  sborrill 	while ((pkt = TAILQ_FIRST(&sc->tx_used_pkts)) != NULL) {
   3930  1.20.4.2  sborrill 		TAILQ_REMOVE(&sc->tx_used_pkts, pkt, pkt_entry);
   3931  1.20.4.2  sborrill 		mutex_exit(&sc->tx_pkt_mtx);
   3932  1.20.4.2  sborrill 
   3933  1.20.4.2  sborrill 		bus_dmamap_sync(sc->bnx_dmatag, pkt->pkt_dmamap, 0,
   3934  1.20.4.2  sborrill 		    pkt->pkt_dmamap->dm_mapsize, BUS_DMASYNC_POSTWRITE);
   3935  1.20.4.2  sborrill 		bus_dmamap_unload(sc->bnx_dmatag, pkt->pkt_dmamap);
   3936  1.20.4.2  sborrill 
   3937  1.20.4.2  sborrill 		m_freem(pkt->pkt_mbuf);
   3938  1.20.4.2  sborrill 		DBRUNIF(1, sc->tx_mbuf_alloc--);
   3939  1.20.4.2  sborrill 
   3940  1.20.4.2  sborrill 		mutex_enter(&sc->tx_pkt_mtx);
   3941  1.20.4.2  sborrill 		TAILQ_INSERT_TAIL(&sc->tx_free_pkts, pkt, pkt_entry);
   3942  1.20.4.2  sborrill         }
   3943  1.20.4.2  sborrill 
   3944  1.20.4.2  sborrill 	/* Destroy all the dmamaps we allocated for TX */
   3945  1.20.4.2  sborrill 	while ((pkt = TAILQ_FIRST(&sc->tx_free_pkts)) != NULL) {
   3946  1.20.4.2  sborrill 		TAILQ_REMOVE(&sc->tx_free_pkts, pkt, pkt_entry);
   3947  1.20.4.2  sborrill 		sc->tx_pkt_count--;
   3948  1.20.4.2  sborrill 		mutex_exit(&sc->tx_pkt_mtx);
   3949  1.20.4.2  sborrill 
   3950  1.20.4.2  sborrill 		bus_dmamap_destroy(sc->bnx_dmatag, pkt->pkt_dmamap);
   3951  1.20.4.2  sborrill 		pool_put(bnx_tx_pool, pkt);
   3952  1.20.4.2  sborrill 
   3953  1.20.4.2  sborrill 		mutex_enter(&sc->tx_pkt_mtx);
   3954       1.1    bouyer 	}
   3955  1.20.4.2  sborrill 	mutex_exit(&sc->tx_pkt_mtx);
   3956  1.20.4.2  sborrill 
   3957  1.20.4.2  sborrill 
   3958       1.1    bouyer 
   3959       1.1    bouyer 	/* Clear each TX chain page. */
   3960       1.1    bouyer 	for (i = 0; i < TX_PAGES; i++) {
   3961       1.1    bouyer 		bzero((char *)sc->tx_bd_chain[i], BNX_TX_CHAIN_PAGE_SZ);
   3962       1.1    bouyer 		bus_dmamap_sync(sc->bnx_dmatag, sc->tx_bd_chain_map[i], 0,
   3963       1.1    bouyer 		    BNX_TX_CHAIN_PAGE_SZ, BUS_DMASYNC_PREWRITE);
   3964       1.1    bouyer 	}
   3965       1.1    bouyer 
   3966  1.20.4.2  sborrill 	sc->used_tx_bd = 0;
   3967  1.20.4.2  sborrill 
   3968       1.1    bouyer 	/* Check if we lost any mbufs in the process. */
   3969       1.1    bouyer 	DBRUNIF((sc->tx_mbuf_alloc),
   3970      1.13    dyoung 	    aprint_error_dev(sc->bnx_dev,
   3971      1.13    dyoung 	        "Memory leak! Lost %d mbufs from tx chain!\n",
   3972      1.13    dyoung 		sc->tx_mbuf_alloc));
   3973       1.1    bouyer 
   3974      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Exiting %s()\n", __func__);
   3975       1.1    bouyer }
   3976       1.1    bouyer 
   3977       1.1    bouyer /****************************************************************************/
   3978  1.20.4.2  sborrill /* Initialize the RX context memory.                                        */
   3979  1.20.4.2  sborrill /*                                                                          */
   3980  1.20.4.2  sborrill /* Returns:                                                                 */
   3981  1.20.4.2  sborrill /*   Nothing                                                                */
   3982  1.20.4.2  sborrill /****************************************************************************/
   3983  1.20.4.2  sborrill void
   3984  1.20.4.2  sborrill bnx_init_rx_context(struct bnx_softc *sc)
   3985  1.20.4.2  sborrill {
   3986  1.20.4.2  sborrill 	u_int32_t val;
   3987  1.20.4.2  sborrill 
   3988  1.20.4.2  sborrill 	/* Initialize the context ID for an L2 RX chain. */
   3989  1.20.4.2  sborrill 	val = BNX_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE |
   3990  1.20.4.2  sborrill 		BNX_L2CTX_CTX_TYPE_SIZE_L2 | (0x02 << 8);
   3991  1.20.4.2  sborrill 
   3992  1.20.4.2  sborrill 	if (BNX_CHIP_NUM(sc) == BNX_CHIP_NUM_5709) {
   3993  1.20.4.2  sborrill 		u_int32_t lo_water, hi_water;
   3994  1.20.4.2  sborrill 
   3995  1.20.4.2  sborrill 		lo_water = BNX_L2CTX_RX_LO_WATER_MARK_DEFAULT;
   3996  1.20.4.2  sborrill 		hi_water = USABLE_RX_BD / 4;
   3997  1.20.4.2  sborrill 
   3998  1.20.4.2  sborrill 		lo_water /= BNX_L2CTX_RX_LO_WATER_MARK_SCALE;
   3999  1.20.4.2  sborrill 		hi_water /= BNX_L2CTX_RX_HI_WATER_MARK_SCALE;
   4000  1.20.4.2  sborrill 
   4001  1.20.4.2  sborrill 		if (hi_water > 0xf)
   4002  1.20.4.2  sborrill 			hi_water = 0xf;
   4003  1.20.4.2  sborrill 		else if (hi_water == 0)
   4004  1.20.4.2  sborrill 			lo_water = 0;
   4005  1.20.4.2  sborrill 		val |= lo_water |
   4006  1.20.4.2  sborrill 		    (hi_water << BNX_L2CTX_RX_HI_WATER_MARK_SHIFT);
   4007  1.20.4.2  sborrill 	}
   4008  1.20.4.2  sborrill 
   4009  1.20.4.2  sborrill  	CTX_WR(sc, GET_CID_ADDR(RX_CID), BNX_L2CTX_CTX_TYPE, val);
   4010  1.20.4.2  sborrill 
   4011  1.20.4.2  sborrill 	/* Setup the MQ BIN mapping for l2_ctx_host_bseq. */
   4012  1.20.4.2  sborrill 	if (BNX_CHIP_NUM(sc) == BNX_CHIP_NUM_5709) {
   4013  1.20.4.2  sborrill 		val = REG_RD(sc, BNX_MQ_MAP_L2_5);
   4014  1.20.4.2  sborrill 		REG_WR(sc, BNX_MQ_MAP_L2_5, val | BNX_MQ_MAP_L2_5_ARM);
   4015  1.20.4.2  sborrill 	}
   4016  1.20.4.2  sborrill 
   4017  1.20.4.2  sborrill 	/* Point the hardware to the first page in the chain. */
   4018  1.20.4.2  sborrill 	val = (u_int32_t)((u_int64_t)sc->rx_bd_chain_paddr[0] >> 32);
   4019  1.20.4.2  sborrill 	CTX_WR(sc, GET_CID_ADDR(RX_CID), BNX_L2CTX_NX_BDHADDR_HI, val);
   4020  1.20.4.2  sborrill 	val = (u_int32_t)(sc->rx_bd_chain_paddr[0]);
   4021  1.20.4.2  sborrill 	CTX_WR(sc, GET_CID_ADDR(RX_CID), BNX_L2CTX_NX_BDHADDR_LO, val);
   4022  1.20.4.2  sborrill }
   4023  1.20.4.2  sborrill 
   4024  1.20.4.2  sborrill /****************************************************************************/
   4025       1.1    bouyer /* Allocate memory and initialize the RX data structures.                   */
   4026       1.1    bouyer /*                                                                          */
   4027       1.1    bouyer /* Returns:                                                                 */
   4028       1.1    bouyer /*   0 for success, positive value for failure.                             */
   4029       1.1    bouyer /****************************************************************************/
   4030       1.1    bouyer int
   4031       1.1    bouyer bnx_init_rx_chain(struct bnx_softc *sc)
   4032       1.1    bouyer {
   4033       1.1    bouyer 	struct rx_bd		*rxbd;
   4034       1.1    bouyer 	int			i, rc = 0;
   4035       1.1    bouyer 	u_int16_t		prod, chain_prod;
   4036  1.20.4.2  sborrill 	u_int32_t		prod_bseq, addr;
   4037       1.1    bouyer 
   4038      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Entering %s()\n", __func__);
   4039       1.1    bouyer 
   4040       1.1    bouyer 	/* Initialize the RX producer and consumer indices. */
   4041       1.1    bouyer 	sc->rx_prod = 0;
   4042       1.1    bouyer 	sc->rx_cons = 0;
   4043       1.1    bouyer 	sc->rx_prod_bseq = 0;
   4044  1.20.4.2  sborrill 	sc->free_rx_bd = USABLE_RX_BD;
   4045  1.20.4.2  sborrill 	sc->max_rx_bd = USABLE_RX_BD;
   4046       1.1    bouyer 	DBRUNIF(1, sc->rx_low_watermark = USABLE_RX_BD);
   4047  1.20.4.2  sborrill 	DBRUNIF(1, sc->rx_empty_count = 0);
   4048       1.1    bouyer 
   4049       1.1    bouyer 	/* Initialize the RX next pointer chain entries. */
   4050       1.1    bouyer 	for (i = 0; i < RX_PAGES; i++) {
   4051       1.1    bouyer 		int j;
   4052       1.1    bouyer 
   4053       1.1    bouyer 		rxbd = &sc->rx_bd_chain[i][USABLE_RX_BD_PER_PAGE];
   4054       1.1    bouyer 
   4055       1.1    bouyer 		/* Check if we've reached the last page. */
   4056       1.1    bouyer 		if (i == (RX_PAGES - 1))
   4057       1.1    bouyer 			j = 0;
   4058       1.1    bouyer 		else
   4059       1.1    bouyer 			j = i + 1;
   4060       1.1    bouyer 
   4061       1.1    bouyer 		/* Setup the chain page pointers. */
   4062       1.1    bouyer 		addr = (u_int32_t)((u_int64_t)sc->rx_bd_chain_paddr[j] >> 32);
   4063       1.1    bouyer 		rxbd->rx_bd_haddr_hi = htole32(addr);
   4064       1.1    bouyer 		addr = (u_int32_t)(sc->rx_bd_chain_paddr[j]);
   4065       1.1    bouyer 		rxbd->rx_bd_haddr_lo = htole32(addr);
   4066       1.1    bouyer 		bus_dmamap_sync(sc->bnx_dmatag, sc->rx_bd_chain_map[i],
   4067       1.1    bouyer 		    0, BNX_RX_CHAIN_PAGE_SZ,
   4068       1.1    bouyer 		    BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
   4069       1.1    bouyer 	}
   4070       1.1    bouyer 
   4071       1.1    bouyer 	/* Allocate mbuf clusters for the rx_bd chain. */
   4072       1.1    bouyer 	prod = prod_bseq = 0;
   4073       1.5    bouyer 	chain_prod = RX_CHAIN_IDX(prod);
   4074  1.20.4.1    bouyer 	if (bnx_get_buf(sc, &prod, &chain_prod, &prod_bseq)) {
   4075       1.5    bouyer 		BNX_PRINTF(sc,
   4076       1.5    bouyer 		    "Error filling RX chain: rx_bd[0x%04X]!\n", chain_prod);
   4077       1.1    bouyer 	}
   4078       1.1    bouyer 
   4079       1.1    bouyer 	/* Save the RX chain producer index. */
   4080       1.1    bouyer 	sc->rx_prod = prod;
   4081       1.1    bouyer 	sc->rx_prod_bseq = prod_bseq;
   4082       1.1    bouyer 
   4083       1.1    bouyer 	for (i = 0; i < RX_PAGES; i++)
   4084       1.1    bouyer 		bus_dmamap_sync(sc->bnx_dmatag, sc->rx_bd_chain_map[i], 0,
   4085       1.1    bouyer 		    sc->rx_bd_chain_map[i]->dm_mapsize,
   4086       1.1    bouyer 		    BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
   4087       1.1    bouyer 
   4088       1.1    bouyer 	/* Tell the chip about the waiting rx_bd's. */
   4089       1.1    bouyer 	REG_WR16(sc, MB_RX_CID_ADDR + BNX_L2CTX_HOST_BDIDX, sc->rx_prod);
   4090       1.1    bouyer 	REG_WR(sc, MB_RX_CID_ADDR + BNX_L2CTX_HOST_BSEQ, sc->rx_prod_bseq);
   4091       1.1    bouyer 
   4092  1.20.4.2  sborrill 	bnx_init_rx_context(sc);
   4093  1.20.4.2  sborrill 
   4094       1.1    bouyer 	DBRUN(BNX_VERBOSE_RECV, bnx_dump_rx_chain(sc, 0, TOTAL_RX_BD));
   4095       1.1    bouyer 
   4096      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Exiting %s()\n", __func__);
   4097       1.1    bouyer 
   4098       1.1    bouyer 	return(rc);
   4099       1.1    bouyer }
   4100       1.1    bouyer 
   4101       1.1    bouyer /****************************************************************************/
   4102       1.1    bouyer /* Free memory and clear the RX data structures.                            */
   4103       1.1    bouyer /*                                                                          */
   4104       1.1    bouyer /* Returns:                                                                 */
   4105       1.1    bouyer /*   Nothing.                                                               */
   4106       1.1    bouyer /****************************************************************************/
   4107       1.1    bouyer void
   4108       1.1    bouyer bnx_free_rx_chain(struct bnx_softc *sc)
   4109       1.1    bouyer {
   4110       1.1    bouyer 	int			i;
   4111       1.1    bouyer 
   4112      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Entering %s()\n", __func__);
   4113       1.1    bouyer 
   4114       1.1    bouyer 	/* Free any mbufs still in the RX mbuf chain. */
   4115       1.1    bouyer 	for (i = 0; i < TOTAL_RX_BD; i++) {
   4116       1.1    bouyer 		if (sc->rx_mbuf_ptr[i] != NULL) {
   4117  1.20.4.2  sborrill 			if (sc->rx_mbuf_map[i] != NULL) {
   4118       1.1    bouyer 				bus_dmamap_sync(sc->bnx_dmatag,
   4119       1.1    bouyer 				    sc->rx_mbuf_map[i],	0,
   4120       1.1    bouyer 				    sc->rx_mbuf_map[i]->dm_mapsize,
   4121       1.1    bouyer 				    BUS_DMASYNC_POSTREAD);
   4122  1.20.4.2  sborrill 				bus_dmamap_unload(sc->bnx_dmatag,
   4123  1.20.4.2  sborrill 				    sc->rx_mbuf_map[i]);
   4124  1.20.4.2  sborrill 			}
   4125       1.1    bouyer 			m_freem(sc->rx_mbuf_ptr[i]);
   4126       1.1    bouyer 			sc->rx_mbuf_ptr[i] = NULL;
   4127       1.1    bouyer 			DBRUNIF(1, sc->rx_mbuf_alloc--);
   4128       1.1    bouyer 		}
   4129       1.1    bouyer 	}
   4130       1.1    bouyer 
   4131       1.1    bouyer 	/* Clear each RX chain page. */
   4132       1.1    bouyer 	for (i = 0; i < RX_PAGES; i++)
   4133       1.1    bouyer 		bzero((char *)sc->rx_bd_chain[i], BNX_RX_CHAIN_PAGE_SZ);
   4134       1.1    bouyer 
   4135  1.20.4.2  sborrill 	sc->free_rx_bd = sc->max_rx_bd;
   4136  1.20.4.2  sborrill 
   4137       1.1    bouyer 	/* Check if we lost any mbufs in the process. */
   4138       1.1    bouyer 	DBRUNIF((sc->rx_mbuf_alloc),
   4139      1.13    dyoung 	    aprint_error_dev(sc->bnx_dev,
   4140      1.13    dyoung 	        "Memory leak! Lost %d mbufs from rx chain!\n",
   4141      1.13    dyoung 		sc->rx_mbuf_alloc));
   4142       1.1    bouyer 
   4143      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Exiting %s()\n", __func__);
   4144       1.1    bouyer }
   4145       1.1    bouyer 
   4146       1.1    bouyer /****************************************************************************/
   4147       1.1    bouyer /* Handles PHY generated interrupt events.                                  */
   4148       1.1    bouyer /*                                                                          */
   4149       1.1    bouyer /* Returns:                                                                 */
   4150       1.1    bouyer /*   Nothing.                                                               */
   4151       1.1    bouyer /****************************************************************************/
   4152       1.1    bouyer void
   4153       1.1    bouyer bnx_phy_intr(struct bnx_softc *sc)
   4154       1.1    bouyer {
   4155       1.1    bouyer 	u_int32_t		new_link_state, old_link_state;
   4156       1.1    bouyer 
   4157       1.1    bouyer 	bus_dmamap_sync(sc->bnx_dmatag, sc->status_map, 0, BNX_STATUS_BLK_SZ,
   4158       1.1    bouyer 	    BUS_DMASYNC_POSTREAD);
   4159       1.1    bouyer 	new_link_state = sc->status_block->status_attn_bits &
   4160       1.1    bouyer 	    STATUS_ATTN_BITS_LINK_STATE;
   4161       1.1    bouyer 	old_link_state = sc->status_block->status_attn_bits_ack &
   4162       1.1    bouyer 	    STATUS_ATTN_BITS_LINK_STATE;
   4163       1.1    bouyer 
   4164       1.1    bouyer 	/* Handle any changes if the link state has changed. */
   4165       1.1    bouyer 	if (new_link_state != old_link_state) {
   4166       1.1    bouyer 		DBRUN(BNX_VERBOSE_INTR, bnx_dump_status_block(sc));
   4167       1.1    bouyer 
   4168       1.1    bouyer 		callout_stop(&sc->bnx_timeout);
   4169       1.1    bouyer 		bnx_tick(sc);
   4170       1.1    bouyer 
   4171       1.1    bouyer 		/* Update the status_attn_bits_ack field in the status block. */
   4172       1.1    bouyer 		if (new_link_state) {
   4173       1.1    bouyer 			REG_WR(sc, BNX_PCICFG_STATUS_BIT_SET_CMD,
   4174       1.1    bouyer 			    STATUS_ATTN_BITS_LINK_STATE);
   4175       1.1    bouyer 			DBPRINT(sc, BNX_INFO, "Link is now UP.\n");
   4176       1.1    bouyer 		} else {
   4177       1.1    bouyer 			REG_WR(sc, BNX_PCICFG_STATUS_BIT_CLEAR_CMD,
   4178       1.1    bouyer 			    STATUS_ATTN_BITS_LINK_STATE);
   4179       1.1    bouyer 			DBPRINT(sc, BNX_INFO, "Link is now DOWN.\n");
   4180       1.1    bouyer 		}
   4181       1.1    bouyer 	}
   4182       1.1    bouyer 
   4183       1.1    bouyer 	/* Acknowledge the link change interrupt. */
   4184       1.1    bouyer 	REG_WR(sc, BNX_EMAC_STATUS, BNX_EMAC_STATUS_LINK_CHANGE);
   4185       1.1    bouyer }
   4186       1.1    bouyer 
   4187       1.1    bouyer /****************************************************************************/
   4188       1.1    bouyer /* Handles received frame interrupt events.                                 */
   4189       1.1    bouyer /*                                                                          */
   4190       1.1    bouyer /* Returns:                                                                 */
   4191       1.1    bouyer /*   Nothing.                                                               */
   4192       1.1    bouyer /****************************************************************************/
   4193       1.1    bouyer void
   4194       1.1    bouyer bnx_rx_intr(struct bnx_softc *sc)
   4195       1.1    bouyer {
   4196       1.1    bouyer 	struct status_block	*sblk = sc->status_block;
   4197      1.15    dyoung 	struct ifnet		*ifp = &sc->bnx_ec.ec_if;
   4198       1.1    bouyer 	u_int16_t		hw_cons, sw_cons, sw_chain_cons;
   4199       1.1    bouyer 	u_int16_t		sw_prod, sw_chain_prod;
   4200       1.1    bouyer 	u_int32_t		sw_prod_bseq;
   4201       1.1    bouyer 	struct l2_fhdr		*l2fhdr;
   4202       1.1    bouyer 	int			i;
   4203       1.1    bouyer 
   4204       1.1    bouyer 	DBRUNIF(1, sc->rx_interrupts++);
   4205       1.1    bouyer 	bus_dmamap_sync(sc->bnx_dmatag, sc->status_map, 0, BNX_STATUS_BLK_SZ,
   4206       1.1    bouyer 	    BUS_DMASYNC_POSTREAD);
   4207       1.1    bouyer 
   4208       1.1    bouyer 	/* Prepare the RX chain pages to be accessed by the host CPU. */
   4209       1.1    bouyer 	for (i = 0; i < RX_PAGES; i++)
   4210       1.1    bouyer 		bus_dmamap_sync(sc->bnx_dmatag,
   4211       1.1    bouyer 		    sc->rx_bd_chain_map[i], 0,
   4212       1.1    bouyer 		    sc->rx_bd_chain_map[i]->dm_mapsize,
   4213       1.1    bouyer 		    BUS_DMASYNC_POSTWRITE);
   4214       1.1    bouyer 
   4215       1.1    bouyer 	/* Get the hardware's view of the RX consumer index. */
   4216       1.1    bouyer 	hw_cons = sc->hw_rx_cons = sblk->status_rx_quick_consumer_index0;
   4217       1.1    bouyer 	if ((hw_cons & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
   4218       1.1    bouyer 		hw_cons++;
   4219       1.1    bouyer 
   4220       1.1    bouyer 	/* Get working copies of the driver's view of the RX indices. */
   4221       1.1    bouyer 	sw_cons = sc->rx_cons;
   4222       1.1    bouyer 	sw_prod = sc->rx_prod;
   4223       1.1    bouyer 	sw_prod_bseq = sc->rx_prod_bseq;
   4224       1.1    bouyer 
   4225       1.1    bouyer 	DBPRINT(sc, BNX_INFO_RECV, "%s(enter): sw_prod = 0x%04X, "
   4226       1.1    bouyer 	    "sw_cons = 0x%04X, sw_prod_bseq = 0x%08X\n",
   4227      1.12     perry 	    __func__, sw_prod, sw_cons, sw_prod_bseq);
   4228       1.1    bouyer 
   4229       1.1    bouyer 	/* Prevent speculative reads from getting ahead of the status block. */
   4230       1.1    bouyer 	bus_space_barrier(sc->bnx_btag, sc->bnx_bhandle, 0, 0,
   4231       1.1    bouyer 	    BUS_SPACE_BARRIER_READ);
   4232       1.1    bouyer 
   4233  1.20.4.2  sborrill 	/* Update some debug statistics counters */
   4234       1.1    bouyer 	DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
   4235       1.1    bouyer 	    sc->rx_low_watermark = sc->free_rx_bd);
   4236  1.20.4.2  sborrill 	DBRUNIF((sc->free_rx_bd == USABLE_RX_BD), sc->rx_empty_count++);
   4237       1.1    bouyer 
   4238       1.1    bouyer 	/*
   4239       1.1    bouyer 	 * Scan through the receive chain as long
   4240       1.1    bouyer 	 * as there is work to do.
   4241       1.1    bouyer 	 */
   4242       1.1    bouyer 	while (sw_cons != hw_cons) {
   4243       1.1    bouyer 		struct mbuf *m;
   4244       1.1    bouyer 		struct rx_bd *rxbd;
   4245       1.1    bouyer 		unsigned int len;
   4246       1.1    bouyer 		u_int32_t status;
   4247       1.1    bouyer 
   4248       1.1    bouyer 		/* Convert the producer/consumer indices to an actual
   4249       1.1    bouyer 		 * rx_bd index.
   4250       1.1    bouyer 		 */
   4251       1.1    bouyer 		sw_chain_cons = RX_CHAIN_IDX(sw_cons);
   4252       1.1    bouyer 		sw_chain_prod = RX_CHAIN_IDX(sw_prod);
   4253       1.1    bouyer 
   4254       1.1    bouyer 		/* Get the used rx_bd. */
   4255       1.1    bouyer 		rxbd = &sc->rx_bd_chain[RX_PAGE(sw_chain_cons)][RX_IDX(sw_chain_cons)];
   4256       1.1    bouyer 		sc->free_rx_bd++;
   4257       1.1    bouyer 
   4258      1.12     perry 		DBRUN(BNX_VERBOSE_RECV, aprint_error("%s(): ", __func__);
   4259       1.1    bouyer 		bnx_dump_rxbd(sc, sw_chain_cons, rxbd));
   4260       1.1    bouyer 
   4261       1.1    bouyer 		/* The mbuf is stored with the last rx_bd entry of a packet. */
   4262       1.1    bouyer 		if (sc->rx_mbuf_ptr[sw_chain_cons] != NULL) {
   4263       1.5    bouyer #ifdef DIAGNOSTIC
   4264       1.1    bouyer 			/* Validate that this is the last rx_bd. */
   4265       1.5    bouyer 			if ((rxbd->rx_bd_flags & RX_BD_FLAGS_END) == 0) {
   4266       1.5    bouyer 			    printf("%s: Unexpected mbuf found in "
   4267      1.13    dyoung 			        "rx_bd[0x%04X]!\n", device_xname(sc->bnx_dev),
   4268       1.1    bouyer 			        sw_chain_cons);
   4269       1.5    bouyer 			}
   4270       1.5    bouyer #endif
   4271       1.1    bouyer 
   4272       1.1    bouyer 			/* DRC - ToDo: If the received packet is small, say less
   4273       1.1    bouyer 			 *             than 128 bytes, allocate a new mbuf here,
   4274       1.1    bouyer 			 *             copy the data to that mbuf, and recycle
   4275       1.1    bouyer 			 *             the mapped jumbo frame.
   4276       1.1    bouyer 			 */
   4277       1.1    bouyer 
   4278       1.1    bouyer 			/* Unmap the mbuf from DMA space. */
   4279       1.5    bouyer #ifdef DIAGNOSTIC
   4280       1.5    bouyer 			if (sc->rx_mbuf_map[sw_chain_cons]->dm_mapsize == 0) {
   4281       1.5    bouyer 				printf("invalid map sw_cons 0x%x "
   4282       1.5    bouyer 				"sw_prod 0x%x "
   4283       1.5    bouyer 				"sw_chain_cons 0x%x "
   4284       1.5    bouyer 				"sw_chain_prod 0x%x "
   4285       1.5    bouyer 				"hw_cons 0x%x "
   4286       1.6    bouyer 				"TOTAL_RX_BD_PER_PAGE 0x%x "
   4287       1.6    bouyer 				"TOTAL_RX_BD 0x%x\n",
   4288       1.5    bouyer 				sw_cons, sw_prod, sw_chain_cons, sw_chain_prod,
   4289       1.6    bouyer 				hw_cons,
   4290       1.6    bouyer 				(int)TOTAL_RX_BD_PER_PAGE, (int)TOTAL_RX_BD);
   4291       1.5    bouyer 			}
   4292       1.5    bouyer #endif
   4293       1.1    bouyer 			bus_dmamap_sync(sc->bnx_dmatag,
   4294       1.1    bouyer 			    sc->rx_mbuf_map[sw_chain_cons], 0,
   4295       1.1    bouyer 			    sc->rx_mbuf_map[sw_chain_cons]->dm_mapsize,
   4296       1.1    bouyer 			    BUS_DMASYNC_POSTREAD);
   4297       1.1    bouyer 			bus_dmamap_unload(sc->bnx_dmatag,
   4298       1.1    bouyer 			    sc->rx_mbuf_map[sw_chain_cons]);
   4299       1.1    bouyer 
   4300       1.1    bouyer 			/* Remove the mbuf from the driver's chain. */
   4301       1.1    bouyer 			m = sc->rx_mbuf_ptr[sw_chain_cons];
   4302       1.1    bouyer 			sc->rx_mbuf_ptr[sw_chain_cons] = NULL;
   4303       1.1    bouyer 
   4304       1.1    bouyer 			/*
   4305       1.1    bouyer 			 * Frames received on the NetXteme II are prepended
   4306       1.1    bouyer 			 * with the l2_fhdr structure which provides status
   4307       1.1    bouyer 			 * information about the received frame (including
   4308       1.1    bouyer 			 * VLAN tags and checksum info) and are also
   4309       1.1    bouyer 			 * automatically adjusted to align the IP header
   4310       1.1    bouyer 			 * (i.e. two null bytes are inserted before the
   4311       1.1    bouyer 			 * Ethernet header).
   4312       1.1    bouyer 			 */
   4313       1.1    bouyer 			l2fhdr = mtod(m, struct l2_fhdr *);
   4314       1.1    bouyer 
   4315       1.1    bouyer 			len    = l2fhdr->l2_fhdr_pkt_len;
   4316       1.1    bouyer 			status = l2fhdr->l2_fhdr_status;
   4317       1.1    bouyer 
   4318       1.1    bouyer 			DBRUNIF(DB_RANDOMTRUE(bnx_debug_l2fhdr_status_check),
   4319       1.1    bouyer 			    aprint_error("Simulating l2_fhdr status error.\n");
   4320       1.1    bouyer 			    status = status | L2_FHDR_ERRORS_PHY_DECODE);
   4321       1.1    bouyer 
   4322       1.1    bouyer 			/* Watch for unusual sized frames. */
   4323       1.1    bouyer 			DBRUNIF(((len < BNX_MIN_MTU) ||
   4324       1.1    bouyer 			    (len > BNX_MAX_JUMBO_ETHER_MTU_VLAN)),
   4325      1.13    dyoung 			    aprint_error_dev(sc->bnx_dev,
   4326      1.13    dyoung 			        "Unusual frame size found. "
   4327      1.13    dyoung 				"Min(%d), Actual(%d), Max(%d)\n",
   4328      1.13    dyoung 				(int)BNX_MIN_MTU, len,
   4329      1.13    dyoung 				(int)BNX_MAX_JUMBO_ETHER_MTU_VLAN);
   4330       1.1    bouyer 
   4331       1.1    bouyer 			bnx_dump_mbuf(sc, m);
   4332       1.1    bouyer 			bnx_breakpoint(sc));
   4333       1.1    bouyer 
   4334       1.1    bouyer 			len -= ETHER_CRC_LEN;
   4335       1.1    bouyer 
   4336       1.1    bouyer 			/* Check the received frame for errors. */
   4337       1.1    bouyer 			if ((status &  (L2_FHDR_ERRORS_BAD_CRC |
   4338       1.1    bouyer 			    L2_FHDR_ERRORS_PHY_DECODE |
   4339       1.1    bouyer 			    L2_FHDR_ERRORS_ALIGNMENT |
   4340       1.1    bouyer 			    L2_FHDR_ERRORS_TOO_SHORT |
   4341       1.1    bouyer 			    L2_FHDR_ERRORS_GIANT_FRAME)) ||
   4342       1.1    bouyer 			    len < (BNX_MIN_MTU - ETHER_CRC_LEN) ||
   4343       1.1    bouyer 			    len >
   4344       1.1    bouyer 			    (BNX_MAX_JUMBO_ETHER_MTU_VLAN - ETHER_CRC_LEN)) {
   4345       1.1    bouyer 				ifp->if_ierrors++;
   4346       1.1    bouyer 				DBRUNIF(1, sc->l2fhdr_status_errors++);
   4347       1.1    bouyer 
   4348       1.1    bouyer 				/* Reuse the mbuf for a new frame. */
   4349  1.20.4.1    bouyer 				if (bnx_add_buf(sc, m, &sw_prod,
   4350       1.1    bouyer 				    &sw_chain_prod, &sw_prod_bseq)) {
   4351       1.1    bouyer 					DBRUNIF(1, bnx_breakpoint(sc));
   4352       1.1    bouyer 					panic("%s: Can't reuse RX mbuf!\n",
   4353      1.13    dyoung 					    device_xname(sc->bnx_dev));
   4354       1.1    bouyer 				}
   4355       1.5    bouyer 				continue;
   4356       1.1    bouyer 			}
   4357       1.1    bouyer 
   4358       1.1    bouyer 			/*
   4359       1.1    bouyer 			 * Get a new mbuf for the rx_bd.   If no new
   4360       1.1    bouyer 			 * mbufs are available then reuse the current mbuf,
   4361       1.1    bouyer 			 * log an ierror on the interface, and generate
   4362       1.1    bouyer 			 * an error in the system log.
   4363       1.1    bouyer 			 */
   4364  1.20.4.1    bouyer 			if (bnx_get_buf(sc, &sw_prod, &sw_chain_prod,
   4365       1.1    bouyer 			    &sw_prod_bseq)) {
   4366  1.20.4.2  sborrill 				DBRUN(BNX_WARN, aprint_debug_dev(sc->bnx_dev,
   4367  1.20.4.2  sborrill 				    "Failed to allocate "
   4368  1.20.4.2  sborrill 				    "new mbuf, incoming frame dropped!\n"));
   4369       1.1    bouyer 
   4370       1.1    bouyer 				ifp->if_ierrors++;
   4371       1.1    bouyer 
   4372       1.1    bouyer 				/* Try and reuse the exisitng mbuf. */
   4373  1.20.4.1    bouyer 				if (bnx_add_buf(sc, m, &sw_prod,
   4374       1.1    bouyer 				    &sw_chain_prod, &sw_prod_bseq)) {
   4375       1.1    bouyer 					DBRUNIF(1, bnx_breakpoint(sc));
   4376       1.1    bouyer 					panic("%s: Double mbuf allocation "
   4377      1.13    dyoung 					    "failure!",
   4378      1.13    dyoung 					    device_xname(sc->bnx_dev));
   4379       1.1    bouyer 				}
   4380       1.5    bouyer 				continue;
   4381       1.1    bouyer 			}
   4382       1.1    bouyer 
   4383       1.1    bouyer 			/* Skip over the l2_fhdr when passing the data up
   4384       1.1    bouyer 			 * the stack.
   4385       1.1    bouyer 			 */
   4386       1.1    bouyer 			m_adj(m, sizeof(struct l2_fhdr) + ETHER_ALIGN);
   4387       1.1    bouyer 
   4388       1.1    bouyer 			/* Adjust the pckt length to match the received data. */
   4389       1.1    bouyer 			m->m_pkthdr.len = m->m_len = len;
   4390       1.1    bouyer 
   4391       1.1    bouyer 			/* Send the packet to the appropriate interface. */
   4392       1.1    bouyer 			m->m_pkthdr.rcvif = ifp;
   4393       1.1    bouyer 
   4394       1.1    bouyer 			DBRUN(BNX_VERBOSE_RECV,
   4395       1.1    bouyer 			    struct ether_header *eh;
   4396       1.1    bouyer 			    eh = mtod(m, struct ether_header *);
   4397       1.1    bouyer 			    aprint_error("%s: to: %s, from: %s, type: 0x%04X\n",
   4398      1.12     perry 			    __func__, ether_sprintf(eh->ether_dhost),
   4399       1.1    bouyer 			    ether_sprintf(eh->ether_shost),
   4400       1.1    bouyer 			    htons(eh->ether_type)));
   4401       1.1    bouyer 
   4402       1.1    bouyer 			/* Validate the checksum. */
   4403       1.1    bouyer 
   4404       1.1    bouyer 			/* Check for an IP datagram. */
   4405       1.1    bouyer 			if (status & L2_FHDR_STATUS_IP_DATAGRAM) {
   4406       1.1    bouyer 				/* Check if the IP checksum is valid. */
   4407       1.1    bouyer 				if ((l2fhdr->l2_fhdr_ip_xsum ^ 0xffff)
   4408       1.1    bouyer 				    == 0)
   4409       1.1    bouyer 					m->m_pkthdr.csum_flags |=
   4410       1.1    bouyer 					    M_CSUM_IPv4;
   4411       1.1    bouyer #ifdef BNX_DEBUG
   4412       1.1    bouyer 				else
   4413       1.1    bouyer 					DBPRINT(sc, BNX_WARN_SEND,
   4414       1.1    bouyer 					    "%s(): Invalid IP checksum "
   4415       1.1    bouyer 					        "= 0x%04X!\n",
   4416      1.12     perry 						__func__,
   4417       1.1    bouyer 						l2fhdr->l2_fhdr_ip_xsum
   4418       1.1    bouyer 						);
   4419       1.1    bouyer #endif
   4420       1.1    bouyer 			}
   4421       1.1    bouyer 
   4422       1.1    bouyer 			/* Check for a valid TCP/UDP frame. */
   4423       1.1    bouyer 			if (status & (L2_FHDR_STATUS_TCP_SEGMENT |
   4424       1.1    bouyer 			    L2_FHDR_STATUS_UDP_DATAGRAM)) {
   4425       1.1    bouyer 				/* Check for a good TCP/UDP checksum. */
   4426       1.1    bouyer 				if ((status &
   4427       1.1    bouyer 				    (L2_FHDR_ERRORS_TCP_XSUM |
   4428       1.1    bouyer 				    L2_FHDR_ERRORS_UDP_XSUM)) == 0) {
   4429       1.1    bouyer 					m->m_pkthdr.csum_flags |=
   4430       1.1    bouyer 					    M_CSUM_TCPv4 |
   4431       1.1    bouyer 					    M_CSUM_UDPv4;
   4432       1.1    bouyer 				} else {
   4433       1.1    bouyer 					DBPRINT(sc, BNX_WARN_SEND,
   4434       1.1    bouyer 					    "%s(): Invalid TCP/UDP "
   4435       1.1    bouyer 					    "checksum = 0x%04X!\n",
   4436      1.12     perry 					    __func__,
   4437       1.1    bouyer 					    l2fhdr->l2_fhdr_tcp_udp_xsum);
   4438       1.1    bouyer 				}
   4439       1.1    bouyer 			}
   4440       1.1    bouyer 
   4441       1.1    bouyer 			/*
   4442       1.1    bouyer 			 * If we received a packet with a vlan tag,
   4443       1.1    bouyer 			 * attach that information to the packet.
   4444       1.1    bouyer 			 */
   4445  1.20.4.2  sborrill 			if ((status & L2_FHDR_STATUS_L2_VLAN_TAG) &&
   4446  1.20.4.2  sborrill 			    !(sc->rx_mode & BNX_EMAC_RX_MODE_KEEP_VLAN_TAG)) {
   4447       1.1    bouyer 				VLAN_INPUT_TAG(ifp, m,
   4448       1.8    bouyer 				    l2fhdr->l2_fhdr_vlan_tag,
   4449       1.5    bouyer 				    continue);
   4450       1.1    bouyer 			}
   4451       1.1    bouyer 
   4452       1.1    bouyer #if NBPFILTER > 0
   4453       1.1    bouyer 			/*
   4454       1.1    bouyer 			 * Handle BPF listeners. Let the BPF
   4455       1.1    bouyer 			 * user see the packet.
   4456       1.1    bouyer 			 */
   4457       1.1    bouyer 			if (ifp->if_bpf)
   4458       1.1    bouyer 				bpf_mtap(ifp->if_bpf, m);
   4459       1.1    bouyer #endif
   4460       1.1    bouyer 
   4461       1.1    bouyer 			/* Pass the mbuf off to the upper layers. */
   4462       1.1    bouyer 			ifp->if_ipackets++;
   4463       1.1    bouyer 			DBPRINT(sc, BNX_VERBOSE_RECV,
   4464      1.12     perry 			    "%s(): Passing received frame up.\n", __func__);
   4465       1.1    bouyer 			(*ifp->if_input)(ifp, m);
   4466       1.1    bouyer 			DBRUNIF(1, sc->rx_mbuf_alloc--);
   4467       1.1    bouyer 
   4468       1.1    bouyer 		}
   4469       1.1    bouyer 
   4470       1.1    bouyer 		sw_cons = NEXT_RX_BD(sw_cons);
   4471       1.1    bouyer 
   4472       1.1    bouyer 		/* Refresh hw_cons to see if there's new work */
   4473       1.1    bouyer 		if (sw_cons == hw_cons) {
   4474       1.1    bouyer 			hw_cons = sc->hw_rx_cons =
   4475       1.1    bouyer 			    sblk->status_rx_quick_consumer_index0;
   4476       1.1    bouyer 			if ((hw_cons & USABLE_RX_BD_PER_PAGE) ==
   4477       1.1    bouyer 			    USABLE_RX_BD_PER_PAGE)
   4478       1.1    bouyer 				hw_cons++;
   4479       1.1    bouyer 		}
   4480       1.1    bouyer 
   4481       1.1    bouyer 		/* Prevent speculative reads from getting ahead of
   4482       1.1    bouyer 		 * the status block.
   4483       1.1    bouyer 		 */
   4484       1.1    bouyer 		bus_space_barrier(sc->bnx_btag, sc->bnx_bhandle, 0, 0,
   4485       1.1    bouyer 		    BUS_SPACE_BARRIER_READ);
   4486       1.1    bouyer 	}
   4487       1.1    bouyer 
   4488       1.1    bouyer 	for (i = 0; i < RX_PAGES; i++)
   4489       1.1    bouyer 		bus_dmamap_sync(sc->bnx_dmatag,
   4490       1.1    bouyer 		    sc->rx_bd_chain_map[i], 0,
   4491       1.1    bouyer 		    sc->rx_bd_chain_map[i]->dm_mapsize,
   4492       1.1    bouyer 		    BUS_DMASYNC_PREWRITE);
   4493       1.1    bouyer 
   4494       1.1    bouyer 	sc->rx_cons = sw_cons;
   4495       1.1    bouyer 	sc->rx_prod = sw_prod;
   4496       1.1    bouyer 	sc->rx_prod_bseq = sw_prod_bseq;
   4497       1.1    bouyer 
   4498       1.1    bouyer 	REG_WR16(sc, MB_RX_CID_ADDR + BNX_L2CTX_HOST_BDIDX, sc->rx_prod);
   4499       1.1    bouyer 	REG_WR(sc, MB_RX_CID_ADDR + BNX_L2CTX_HOST_BSEQ, sc->rx_prod_bseq);
   4500       1.1    bouyer 
   4501       1.1    bouyer 	DBPRINT(sc, BNX_INFO_RECV, "%s(exit): rx_prod = 0x%04X, "
   4502       1.1    bouyer 	    "rx_cons = 0x%04X, rx_prod_bseq = 0x%08X\n",
   4503      1.12     perry 	    __func__, sc->rx_prod, sc->rx_cons, sc->rx_prod_bseq);
   4504       1.1    bouyer }
   4505       1.1    bouyer 
   4506       1.1    bouyer /****************************************************************************/
   4507       1.1    bouyer /* Handles transmit completion interrupt events.                            */
   4508       1.1    bouyer /*                                                                          */
   4509       1.1    bouyer /* Returns:                                                                 */
   4510       1.1    bouyer /*   Nothing.                                                               */
   4511       1.1    bouyer /****************************************************************************/
   4512       1.1    bouyer void
   4513       1.1    bouyer bnx_tx_intr(struct bnx_softc *sc)
   4514       1.1    bouyer {
   4515       1.1    bouyer 	struct status_block	*sblk = sc->status_block;
   4516      1.15    dyoung 	struct ifnet		*ifp = &sc->bnx_ec.ec_if;
   4517  1.20.4.2  sborrill 	struct bnx_pkt		*pkt;
   4518  1.20.4.2  sborrill 	bus_dmamap_t		map;
   4519       1.1    bouyer 	u_int16_t		hw_tx_cons, sw_tx_cons, sw_tx_chain_cons;
   4520       1.1    bouyer 
   4521       1.1    bouyer 	DBRUNIF(1, sc->tx_interrupts++);
   4522       1.1    bouyer 	bus_dmamap_sync(sc->bnx_dmatag, sc->status_map, 0, BNX_STATUS_BLK_SZ,
   4523       1.1    bouyer 	    BUS_DMASYNC_POSTREAD);
   4524       1.1    bouyer 
   4525       1.1    bouyer 	/* Get the hardware's view of the TX consumer index. */
   4526       1.1    bouyer 	hw_tx_cons = sc->hw_tx_cons = sblk->status_tx_quick_consumer_index0;
   4527       1.1    bouyer 
   4528       1.1    bouyer 	/* Skip to the next entry if this is a chain page pointer. */
   4529       1.1    bouyer 	if ((hw_tx_cons & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
   4530       1.1    bouyer 		hw_tx_cons++;
   4531       1.1    bouyer 
   4532       1.1    bouyer 	sw_tx_cons = sc->tx_cons;
   4533       1.1    bouyer 
   4534       1.1    bouyer 	/* Prevent speculative reads from getting ahead of the status block. */
   4535       1.1    bouyer 	bus_space_barrier(sc->bnx_btag, sc->bnx_bhandle, 0, 0,
   4536       1.1    bouyer 	    BUS_SPACE_BARRIER_READ);
   4537       1.1    bouyer 
   4538       1.1    bouyer 	/* Cycle through any completed TX chain page entries. */
   4539       1.1    bouyer 	while (sw_tx_cons != hw_tx_cons) {
   4540       1.1    bouyer #ifdef BNX_DEBUG
   4541       1.1    bouyer 		struct tx_bd *txbd = NULL;
   4542       1.1    bouyer #endif
   4543       1.1    bouyer 		sw_tx_chain_cons = TX_CHAIN_IDX(sw_tx_cons);
   4544       1.1    bouyer 
   4545       1.1    bouyer 		DBPRINT(sc, BNX_INFO_SEND, "%s(): hw_tx_cons = 0x%04X, "
   4546       1.1    bouyer 		    "sw_tx_cons = 0x%04X, sw_tx_chain_cons = 0x%04X\n",
   4547      1.12     perry 		    __func__, hw_tx_cons, sw_tx_cons, sw_tx_chain_cons);
   4548       1.1    bouyer 
   4549       1.1    bouyer 		DBRUNIF((sw_tx_chain_cons > MAX_TX_BD),
   4550      1.13    dyoung 		    aprint_error_dev(sc->bnx_dev,
   4551      1.13    dyoung 		        "TX chain consumer out of range! 0x%04X > 0x%04X\n",
   4552      1.13    dyoung 			sw_tx_chain_cons, (int)MAX_TX_BD); bnx_breakpoint(sc));
   4553       1.1    bouyer 
   4554       1.1    bouyer 		DBRUNIF(1, txbd = &sc->tx_bd_chain
   4555       1.1    bouyer 		    [TX_PAGE(sw_tx_chain_cons)][TX_IDX(sw_tx_chain_cons)]);
   4556       1.1    bouyer 
   4557       1.1    bouyer 		DBRUNIF((txbd == NULL),
   4558      1.13    dyoung 		    aprint_error_dev(sc->bnx_dev,
   4559      1.13    dyoung 		        "Unexpected NULL tx_bd[0x%04X]!\n", sw_tx_chain_cons);
   4560       1.1    bouyer 		    bnx_breakpoint(sc));
   4561       1.1    bouyer 
   4562      1.12     perry 		DBRUN(BNX_INFO_SEND, aprint_debug("%s: ", __func__);
   4563       1.1    bouyer 		    bnx_dump_txbd(sc, sw_tx_chain_cons, txbd));
   4564       1.1    bouyer 
   4565       1.1    bouyer 
   4566  1.20.4.2  sborrill 		mutex_enter(&sc->tx_pkt_mtx);
   4567  1.20.4.2  sborrill 		pkt = TAILQ_FIRST(&sc->tx_used_pkts);
   4568  1.20.4.2  sborrill 		if (pkt != NULL && pkt->pkt_end_desc == sw_tx_chain_cons) {
   4569  1.20.4.2  sborrill 			TAILQ_REMOVE(&sc->tx_used_pkts, pkt, pkt_entry);
   4570  1.20.4.2  sborrill 			mutex_exit(&sc->tx_pkt_mtx);
   4571  1.20.4.2  sborrill 			/*
   4572  1.20.4.2  sborrill 			 * Free the associated mbuf. Remember
   4573  1.20.4.2  sborrill 			 * that only the last tx_bd of a packet
   4574  1.20.4.2  sborrill 			 * has an mbuf pointer and DMA map.
   4575  1.20.4.2  sborrill 			 */
   4576  1.20.4.2  sborrill 			map = pkt->pkt_dmamap;
   4577  1.20.4.2  sborrill 			bus_dmamap_sync(sc->bnx_dmatag, map, 0,
   4578  1.20.4.2  sborrill 			    map->dm_mapsize, BUS_DMASYNC_POSTWRITE);
   4579  1.20.4.2  sborrill 			bus_dmamap_unload(sc->bnx_dmatag, map);
   4580       1.1    bouyer 
   4581  1.20.4.2  sborrill 			m_freem(pkt->pkt_mbuf);
   4582       1.1    bouyer 			DBRUNIF(1, sc->tx_mbuf_alloc--);
   4583       1.1    bouyer 
   4584       1.1    bouyer 			ifp->if_opackets++;
   4585  1.20.4.2  sborrill 
   4586  1.20.4.2  sborrill 			mutex_enter(&sc->tx_pkt_mtx);
   4587  1.20.4.2  sborrill 			TAILQ_INSERT_TAIL(&sc->tx_free_pkts, pkt, pkt_entry);
   4588       1.1    bouyer 		}
   4589  1.20.4.2  sborrill 		mutex_exit(&sc->tx_pkt_mtx);
   4590       1.1    bouyer 
   4591       1.1    bouyer 		sc->used_tx_bd--;
   4592  1.20.4.2  sborrill 		DBPRINT(sc, BNX_INFO_SEND, "%s(%d) used_tx_bd %d\n",
   4593  1.20.4.2  sborrill 			__FILE__, __LINE__, sc->used_tx_bd);
   4594  1.20.4.2  sborrill 
   4595       1.1    bouyer 		sw_tx_cons = NEXT_TX_BD(sw_tx_cons);
   4596       1.1    bouyer 
   4597       1.1    bouyer 		/* Refresh hw_cons to see if there's new work. */
   4598       1.1    bouyer 		hw_tx_cons = sc->hw_tx_cons =
   4599       1.1    bouyer 		    sblk->status_tx_quick_consumer_index0;
   4600       1.1    bouyer 		if ((hw_tx_cons & USABLE_TX_BD_PER_PAGE) ==
   4601       1.1    bouyer 		    USABLE_TX_BD_PER_PAGE)
   4602       1.1    bouyer 			hw_tx_cons++;
   4603       1.1    bouyer 
   4604       1.1    bouyer 		/* Prevent speculative reads from getting ahead of
   4605       1.1    bouyer 		 * the status block.
   4606       1.1    bouyer 		 */
   4607       1.1    bouyer 		bus_space_barrier(sc->bnx_btag, sc->bnx_bhandle, 0, 0,
   4608       1.1    bouyer 		    BUS_SPACE_BARRIER_READ);
   4609       1.1    bouyer 	}
   4610       1.1    bouyer 
   4611       1.1    bouyer 	/* Clear the TX timeout timer. */
   4612       1.1    bouyer 	ifp->if_timer = 0;
   4613       1.1    bouyer 
   4614       1.1    bouyer 	/* Clear the tx hardware queue full flag. */
   4615  1.20.4.2  sborrill 	if (sc->used_tx_bd < sc->max_tx_bd) {
   4616       1.1    bouyer 		DBRUNIF((ifp->if_flags & IFF_OACTIVE),
   4617      1.13    dyoung 		    aprint_debug_dev(sc->bnx_dev,
   4618  1.20.4.2  sborrill 		        "Open TX chain! %d/%d (used/total)\n",
   4619  1.20.4.2  sborrill 			sc->used_tx_bd, sc->max_tx_bd));
   4620       1.1    bouyer 		ifp->if_flags &= ~IFF_OACTIVE;
   4621       1.1    bouyer 	}
   4622       1.1    bouyer 
   4623       1.1    bouyer 	sc->tx_cons = sw_tx_cons;
   4624       1.1    bouyer }
   4625       1.1    bouyer 
   4626       1.1    bouyer /****************************************************************************/
   4627       1.1    bouyer /* Disables interrupt generation.                                           */
   4628       1.1    bouyer /*                                                                          */
   4629       1.1    bouyer /* Returns:                                                                 */
   4630       1.1    bouyer /*   Nothing.                                                               */
   4631       1.1    bouyer /****************************************************************************/
   4632       1.1    bouyer void
   4633       1.1    bouyer bnx_disable_intr(struct bnx_softc *sc)
   4634       1.1    bouyer {
   4635       1.1    bouyer 	REG_WR(sc, BNX_PCICFG_INT_ACK_CMD, BNX_PCICFG_INT_ACK_CMD_MASK_INT);
   4636       1.1    bouyer 	REG_RD(sc, BNX_PCICFG_INT_ACK_CMD);
   4637       1.1    bouyer }
   4638       1.1    bouyer 
   4639       1.1    bouyer /****************************************************************************/
   4640       1.1    bouyer /* Enables interrupt generation.                                            */
   4641       1.1    bouyer /*                                                                          */
   4642       1.1    bouyer /* Returns:                                                                 */
   4643       1.1    bouyer /*   Nothing.                                                               */
   4644       1.1    bouyer /****************************************************************************/
   4645       1.1    bouyer void
   4646       1.1    bouyer bnx_enable_intr(struct bnx_softc *sc)
   4647       1.1    bouyer {
   4648       1.1    bouyer 	u_int32_t		val;
   4649       1.1    bouyer 
   4650       1.1    bouyer 	REG_WR(sc, BNX_PCICFG_INT_ACK_CMD, BNX_PCICFG_INT_ACK_CMD_INDEX_VALID |
   4651       1.1    bouyer 	    BNX_PCICFG_INT_ACK_CMD_MASK_INT | sc->last_status_idx);
   4652       1.1    bouyer 
   4653       1.1    bouyer 	REG_WR(sc, BNX_PCICFG_INT_ACK_CMD, BNX_PCICFG_INT_ACK_CMD_INDEX_VALID |
   4654       1.1    bouyer 	    sc->last_status_idx);
   4655       1.1    bouyer 
   4656       1.1    bouyer 	val = REG_RD(sc, BNX_HC_COMMAND);
   4657       1.1    bouyer 	REG_WR(sc, BNX_HC_COMMAND, val | BNX_HC_COMMAND_COAL_NOW);
   4658       1.1    bouyer }
   4659       1.1    bouyer 
   4660       1.1    bouyer /****************************************************************************/
   4661       1.1    bouyer /* Handles controller initialization.                                       */
   4662       1.1    bouyer /*                                                                          */
   4663       1.1    bouyer /****************************************************************************/
   4664       1.1    bouyer int
   4665       1.1    bouyer bnx_init(struct ifnet *ifp)
   4666       1.1    bouyer {
   4667       1.1    bouyer 	struct bnx_softc	*sc = ifp->if_softc;
   4668       1.1    bouyer 	u_int32_t		ether_mtu;
   4669       1.1    bouyer 	int			s, error = 0;
   4670       1.1    bouyer 
   4671      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Entering %s()\n", __func__);
   4672       1.1    bouyer 
   4673       1.1    bouyer 	s = splnet();
   4674       1.1    bouyer 
   4675      1.14    dyoung 	bnx_stop(ifp, 0);
   4676       1.1    bouyer 
   4677       1.1    bouyer 	if ((error = bnx_reset(sc, BNX_DRV_MSG_CODE_RESET)) != 0) {
   4678  1.20.4.2  sborrill 		aprint_error_dev(sc->bnx_dev,
   4679  1.20.4.2  sborrill 		    "Controller reset failed!\n");
   4680       1.4    bouyer 		goto bnx_init_exit;
   4681       1.1    bouyer 	}
   4682       1.1    bouyer 
   4683       1.1    bouyer 	if ((error = bnx_chipinit(sc)) != 0) {
   4684  1.20.4.2  sborrill 		aprint_error_dev(sc->bnx_dev,
   4685  1.20.4.2  sborrill 		    "Controller initialization failed!\n");
   4686       1.4    bouyer 		goto bnx_init_exit;
   4687       1.1    bouyer 	}
   4688       1.1    bouyer 
   4689       1.1    bouyer 	if ((error = bnx_blockinit(sc)) != 0) {
   4690  1.20.4.2  sborrill 		aprint_error_dev(sc->bnx_dev,
   4691  1.20.4.2  sborrill 		    "Block initialization failed!\n");
   4692       1.4    bouyer 		goto bnx_init_exit;
   4693       1.1    bouyer 	}
   4694       1.1    bouyer 
   4695       1.1    bouyer 	/* Calculate and program the Ethernet MRU size. */
   4696       1.5    bouyer 	if (ifp->if_mtu <= ETHERMTU) {
   4697       1.5    bouyer 		ether_mtu = BNX_MAX_STD_ETHER_MTU_VLAN;
   4698       1.5    bouyer 		sc->mbuf_alloc_size = MCLBYTES;
   4699       1.5    bouyer 	} else {
   4700       1.5    bouyer 		ether_mtu = BNX_MAX_JUMBO_ETHER_MTU_VLAN;
   4701       1.5    bouyer 		sc->mbuf_alloc_size = BNX_MAX_MRU;
   4702       1.5    bouyer 	}
   4703       1.5    bouyer 
   4704       1.1    bouyer 
   4705       1.1    bouyer 	DBPRINT(sc, BNX_INFO, "%s(): setting MRU = %d\n",
   4706      1.12     perry 	    __func__, ether_mtu);
   4707       1.1    bouyer 
   4708       1.1    bouyer 	/*
   4709       1.1    bouyer 	 * Program the MRU and enable Jumbo frame
   4710       1.1    bouyer 	 * support.
   4711       1.1    bouyer 	 */
   4712       1.1    bouyer 	REG_WR(sc, BNX_EMAC_RX_MTU_SIZE, ether_mtu |
   4713       1.1    bouyer 		BNX_EMAC_RX_MTU_SIZE_JUMBO_ENA);
   4714       1.1    bouyer 
   4715       1.1    bouyer 	/* Calculate the RX Ethernet frame size for rx_bd's. */
   4716       1.1    bouyer 	sc->max_frame_size = sizeof(struct l2_fhdr) + 2 + ether_mtu + 8;
   4717       1.1    bouyer 
   4718       1.1    bouyer 	DBPRINT(sc, BNX_INFO, "%s(): mclbytes = %d, mbuf_alloc_size = %d, "
   4719      1.12     perry 	    "max_frame_size = %d\n", __func__, (int)MCLBYTES,
   4720       1.1    bouyer 	    sc->mbuf_alloc_size, sc->max_frame_size);
   4721       1.1    bouyer 
   4722       1.1    bouyer 	/* Program appropriate promiscuous/multicast filtering. */
   4723  1.20.4.2  sborrill 	bnx_iff(sc);
   4724       1.1    bouyer 
   4725       1.1    bouyer 	/* Init RX buffer descriptor chain. */
   4726       1.1    bouyer 	bnx_init_rx_chain(sc);
   4727       1.1    bouyer 
   4728       1.1    bouyer 	/* Init TX buffer descriptor chain. */
   4729       1.1    bouyer 	bnx_init_tx_chain(sc);
   4730       1.1    bouyer 
   4731       1.1    bouyer 	/* Enable host interrupts. */
   4732       1.1    bouyer 	bnx_enable_intr(sc);
   4733       1.1    bouyer 
   4734      1.16    dyoung 	if ((error = ether_mediachange(ifp)) != 0)
   4735      1.14    dyoung 		goto bnx_init_exit;
   4736       1.1    bouyer 
   4737       1.1    bouyer 	ifp->if_flags |= IFF_RUNNING;
   4738       1.1    bouyer 	ifp->if_flags &= ~IFF_OACTIVE;
   4739       1.1    bouyer 
   4740       1.1    bouyer 	callout_reset(&sc->bnx_timeout, hz, bnx_tick, sc);
   4741       1.1    bouyer 
   4742       1.4    bouyer bnx_init_exit:
   4743      1.12     perry 	DBPRINT(sc, BNX_VERBOSE_RESET, "Exiting %s()\n", __func__);
   4744       1.1    bouyer 
   4745       1.1    bouyer 	splx(s);
   4746       1.1    bouyer 
   4747       1.1    bouyer 	return(error);
   4748       1.1    bouyer }
   4749       1.1    bouyer 
   4750       1.1    bouyer /****************************************************************************/
   4751       1.1    bouyer /* Encapsultes an mbuf cluster into the tx_bd chain structure and makes the */
   4752       1.1    bouyer /* memory visible to the controller.                                        */
   4753       1.1    bouyer /*                                                                          */
   4754       1.1    bouyer /* Returns:                                                                 */
   4755       1.1    bouyer /*   0 for success, positive value for failure.                             */
   4756       1.1    bouyer /****************************************************************************/
   4757       1.1    bouyer int
   4758  1.20.4.2  sborrill bnx_tx_encap(struct bnx_softc *sc, struct mbuf *m)
   4759       1.1    bouyer {
   4760  1.20.4.2  sborrill 	struct bnx_pkt		*pkt;
   4761       1.1    bouyer 	bus_dmamap_t		map;
   4762       1.4    bouyer 	struct tx_bd		*txbd = NULL;
   4763       1.4    bouyer 	u_int16_t		vlan_tag = 0, flags = 0;
   4764       1.4    bouyer 	u_int16_t		chain_prod, prod;
   4765       1.4    bouyer #ifdef BNX_DEBUG
   4766       1.4    bouyer 	u_int16_t		debug_prod;
   4767       1.4    bouyer #endif
   4768       1.4    bouyer 	u_int32_t		addr, prod_bseq;
   4769  1.20.4.2  sborrill 	int			i, error;
   4770       1.1    bouyer 	struct m_tag		*mtag;
   4771       1.1    bouyer 
   4772  1.20.4.2  sborrill again:
   4773  1.20.4.2  sborrill 	mutex_enter(&sc->tx_pkt_mtx);
   4774  1.20.4.2  sborrill 	pkt = TAILQ_FIRST(&sc->tx_free_pkts);
   4775  1.20.4.2  sborrill 	if (pkt == NULL) {
   4776  1.20.4.2  sborrill 		if (!ISSET(sc->bnx_ec.ec_if.if_flags, IFF_UP)) {
   4777  1.20.4.2  sborrill 			mutex_exit(&sc->tx_pkt_mtx);
   4778  1.20.4.2  sborrill 			return ENETDOWN;
   4779  1.20.4.2  sborrill 		}
   4780  1.20.4.2  sborrill 		if (sc->tx_pkt_count <= TOTAL_TX_BD) {
   4781  1.20.4.2  sborrill 			mutex_exit(&sc->tx_pkt_mtx);
   4782  1.20.4.2  sborrill 			if (bnx_alloc_pkts(sc) == 0)
   4783  1.20.4.2  sborrill 				goto again;
   4784  1.20.4.2  sborrill 		} else {
   4785  1.20.4.2  sborrill 			mutex_exit(&sc->tx_pkt_mtx);
   4786  1.20.4.2  sborrill 		}
   4787  1.20.4.2  sborrill 		return (ENOMEM);
   4788  1.20.4.2  sborrill 	}
   4789  1.20.4.2  sborrill 	TAILQ_REMOVE(&sc->tx_free_pkts, pkt, pkt_entry);
   4790  1.20.4.2  sborrill 	mutex_exit(&sc->tx_pkt_mtx);
   4791       1.4    bouyer 
   4792       1.1    bouyer 	/* Transfer any checksum offload flags to the bd. */
   4793  1.20.4.2  sborrill 	if (m->m_pkthdr.csum_flags) {
   4794  1.20.4.2  sborrill 		if (m->m_pkthdr.csum_flags & M_CSUM_IPv4)
   4795       1.4    bouyer 			flags |= TX_BD_FLAGS_IP_CKSUM;
   4796  1.20.4.2  sborrill 		if (m->m_pkthdr.csum_flags &
   4797       1.1    bouyer 		    (M_CSUM_TCPv4 | M_CSUM_UDPv4))
   4798       1.4    bouyer 			flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
   4799       1.1    bouyer 	}
   4800       1.1    bouyer 
   4801       1.1    bouyer 	/* Transfer any VLAN tags to the bd. */
   4802  1.20.4.2  sborrill 	mtag = VLAN_OUTPUT_TAG(&sc->bnx_ec, m);
   4803       1.4    bouyer 	if (mtag != NULL) {
   4804       1.4    bouyer 		flags |= TX_BD_FLAGS_VLAN_TAG;
   4805       1.4    bouyer 		vlan_tag = VLAN_TAG_VALUE(mtag);
   4806       1.4    bouyer 	}
   4807       1.1    bouyer 
   4808       1.1    bouyer 	/* Map the mbuf into DMAable memory. */
   4809       1.4    bouyer 	prod = sc->tx_prod;
   4810       1.4    bouyer 	chain_prod = TX_CHAIN_IDX(prod);
   4811  1.20.4.2  sborrill 	map = pkt->pkt_dmamap;
   4812       1.4    bouyer 
   4813       1.1    bouyer 	/* Map the mbuf into our DMA address space. */
   4814  1.20.4.2  sborrill 	error = bus_dmamap_load_mbuf(sc->bnx_dmatag, map, m, BUS_DMA_NOWAIT);
   4815       1.4    bouyer 	if (error != 0) {
   4816      1.13    dyoung 		aprint_error_dev(sc->bnx_dev,
   4817      1.13    dyoung 		    "Error mapping mbuf into TX chain!\n");
   4818  1.20.4.2  sborrill 		sc->tx_dma_map_failures++;
   4819  1.20.4.2  sborrill 		goto maperr;
   4820       1.1    bouyer 	}
   4821       1.1    bouyer 	bus_dmamap_sync(sc->bnx_dmatag, map, 0, map->dm_mapsize,
   4822       1.1    bouyer 	    BUS_DMASYNC_PREWRITE);
   4823  1.20.4.2  sborrill         /* Make sure there's room in the chain */
   4824  1.20.4.2  sborrill 	if (map->dm_nsegs > (sc->max_tx_bd - sc->used_tx_bd))
   4825  1.20.4.2  sborrill                 goto nospace;
   4826       1.4    bouyer 
   4827       1.4    bouyer 	/* prod points to an empty tx_bd at this point. */
   4828       1.4    bouyer 	prod_bseq = sc->tx_prod_bseq;
   4829       1.4    bouyer #ifdef BNX_DEBUG
   4830       1.4    bouyer 	debug_prod = chain_prod;
   4831       1.4    bouyer #endif
   4832       1.4    bouyer 	DBPRINT(sc, BNX_INFO_SEND,
   4833       1.4    bouyer 		"%s(): Start: prod = 0x%04X, chain_prod = %04X, "
   4834       1.4    bouyer 		"prod_bseq = 0x%08X\n",
   4835  1.20.4.2  sborrill 		__func__, prod, chain_prod, prod_bseq);
   4836       1.1    bouyer 
   4837       1.1    bouyer 	/*
   4838       1.4    bouyer 	 * Cycle through each mbuf segment that makes up
   4839       1.4    bouyer 	 * the outgoing frame, gathering the mapping info
   4840       1.4    bouyer 	 * for that segment and creating a tx_bd for the
   4841       1.4    bouyer 	 * mbuf.
   4842       1.4    bouyer 	 */
   4843       1.4    bouyer 	for (i = 0; i < map->dm_nsegs ; i++) {
   4844       1.4    bouyer 		chain_prod = TX_CHAIN_IDX(prod);
   4845       1.4    bouyer 		txbd = &sc->tx_bd_chain[TX_PAGE(chain_prod)][TX_IDX(chain_prod)];
   4846       1.4    bouyer 
   4847       1.4    bouyer 		addr = (u_int32_t)(map->dm_segs[i].ds_addr);
   4848       1.4    bouyer 		txbd->tx_bd_haddr_lo = htole32(addr);
   4849       1.4    bouyer 		addr = (u_int32_t)((u_int64_t)map->dm_segs[i].ds_addr >> 32);
   4850       1.4    bouyer 		txbd->tx_bd_haddr_hi = htole32(addr);
   4851       1.4    bouyer 		txbd->tx_bd_mss_nbytes = htole16(map->dm_segs[i].ds_len);
   4852       1.4    bouyer 		txbd->tx_bd_vlan_tag = htole16(vlan_tag);
   4853       1.4    bouyer 		txbd->tx_bd_flags = htole16(flags);
   4854       1.4    bouyer 		prod_bseq += map->dm_segs[i].ds_len;
   4855       1.4    bouyer 		if (i == 0)
   4856       1.4    bouyer 			txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_START);
   4857       1.4    bouyer 		prod = NEXT_TX_BD(prod);
   4858       1.4    bouyer 	}
   4859       1.4    bouyer 	/* Set the END flag on the last TX buffer descriptor. */
   4860       1.4    bouyer 	txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_END);
   4861       1.4    bouyer 
   4862  1.20.4.2  sborrill 	DBRUN(BNX_INFO_SEND, bnx_dump_tx_chain(sc, debug_prod, map->dm_nsegs));
   4863       1.4    bouyer 
   4864       1.4    bouyer 	DBPRINT(sc, BNX_INFO_SEND,
   4865       1.4    bouyer 		"%s(): End: prod = 0x%04X, chain_prod = %04X, "
   4866       1.4    bouyer 		"prod_bseq = 0x%08X\n",
   4867      1.12     perry 		__func__, prod, chain_prod, prod_bseq);
   4868       1.4    bouyer 
   4869  1.20.4.2  sborrill 	pkt->pkt_mbuf = m;
   4870  1.20.4.2  sborrill 	pkt->pkt_end_desc = chain_prod;
   4871  1.20.4.2  sborrill 
   4872  1.20.4.2  sborrill 	mutex_enter(&sc->tx_pkt_mtx);
   4873  1.20.4.2  sborrill 	TAILQ_INSERT_TAIL(&sc->tx_used_pkts, pkt, pkt_entry);
   4874  1.20.4.2  sborrill 	mutex_exit(&sc->tx_pkt_mtx);
   4875  1.20.4.2  sborrill 
   4876       1.4    bouyer 	sc->used_tx_bd += map->dm_nsegs;
   4877  1.20.4.2  sborrill 	DBPRINT(sc, BNX_INFO_SEND, "%s(%d) used_tx_bd %d\n",
   4878  1.20.4.2  sborrill 		__FILE__, __LINE__, sc->used_tx_bd);
   4879       1.1    bouyer 
   4880  1.20.4.2  sborrill 	/* Update some debug statistics counters */
   4881       1.1    bouyer 	DBRUNIF((sc->used_tx_bd > sc->tx_hi_watermark),
   4882       1.1    bouyer 	    sc->tx_hi_watermark = sc->used_tx_bd);
   4883  1.20.4.2  sborrill 	DBRUNIF(sc->used_tx_bd == sc->max_tx_bd, sc->tx_full_count++);
   4884       1.1    bouyer 	DBRUNIF(1, sc->tx_mbuf_alloc++);
   4885       1.1    bouyer 
   4886       1.4    bouyer 	DBRUN(BNX_VERBOSE_SEND, bnx_dump_tx_mbuf_chain(sc, chain_prod,
   4887  1.20.4.2  sborrill 	    map->dm_nsegs));
   4888       1.1    bouyer 
   4889       1.4    bouyer 	/* prod points to the next free tx_bd at this point. */
   4890       1.4    bouyer 	sc->tx_prod = prod;
   4891       1.4    bouyer 	sc->tx_prod_bseq = prod_bseq;
   4892       1.1    bouyer 
   4893  1.20.4.2  sborrill 	return (0);
   4894  1.20.4.2  sborrill 
   4895  1.20.4.2  sborrill 
   4896  1.20.4.2  sborrill nospace:
   4897  1.20.4.2  sborrill 	bus_dmamap_unload(sc->bnx_dmatag, map);
   4898  1.20.4.2  sborrill maperr:
   4899  1.20.4.2  sborrill 	mutex_enter(&sc->tx_pkt_mtx);
   4900  1.20.4.2  sborrill 	TAILQ_INSERT_TAIL(&sc->tx_free_pkts, pkt, pkt_entry);
   4901  1.20.4.2  sborrill 	mutex_exit(&sc->tx_pkt_mtx);
   4902  1.20.4.2  sborrill 
   4903  1.20.4.2  sborrill 	return (ENOMEM);
   4904       1.1    bouyer }
   4905       1.1    bouyer 
   4906       1.1    bouyer /****************************************************************************/
   4907       1.1    bouyer /* Main transmit routine.                                                   */
   4908       1.1    bouyer /*                                                                          */
   4909       1.1    bouyer /* Returns:                                                                 */
   4910       1.1    bouyer /*   Nothing.                                                               */
   4911       1.1    bouyer /****************************************************************************/
   4912       1.1    bouyer void
   4913       1.1    bouyer bnx_start(struct ifnet *ifp)
   4914       1.1    bouyer {
   4915       1.1    bouyer 	struct bnx_softc	*sc = ifp->if_softc;
   4916       1.1    bouyer 	struct mbuf		*m_head = NULL;
   4917       1.1    bouyer 	int			count = 0;
   4918       1.1    bouyer 	u_int16_t		tx_prod, tx_chain_prod;
   4919       1.1    bouyer 
   4920       1.1    bouyer 	/* If there's no link or the transmit queue is empty then just exit. */
   4921      1.16    dyoung 	if ((ifp->if_flags & (IFF_OACTIVE|IFF_RUNNING)) != IFF_RUNNING) {
   4922       1.1    bouyer 		DBPRINT(sc, BNX_INFO_SEND,
   4923      1.16    dyoung 		    "%s(): output active or device not running.\n", __func__);
   4924       1.4    bouyer 		goto bnx_start_exit;
   4925       1.1    bouyer 	}
   4926       1.1    bouyer 
   4927       1.1    bouyer 	/* prod points to the next free tx_bd. */
   4928       1.1    bouyer 	tx_prod = sc->tx_prod;
   4929       1.1    bouyer 	tx_chain_prod = TX_CHAIN_IDX(tx_prod);
   4930       1.1    bouyer 
   4931       1.1    bouyer 	DBPRINT(sc, BNX_INFO_SEND, "%s(): Start: tx_prod = 0x%04X, "
   4932  1.20.4.2  sborrill 	    "tx_chain_prod = %04X, tx_prod_bseq = 0x%08X, "
   4933  1.20.4.2  sborrill 	    "used_tx %d max_tx %d\n",
   4934  1.20.4.2  sborrill 	    __func__, tx_prod, tx_chain_prod, sc->tx_prod_bseq,
   4935  1.20.4.2  sborrill 	    sc->used_tx_bd, sc->max_tx_bd);
   4936       1.1    bouyer 
   4937       1.4    bouyer 	/*
   4938  1.20.4.2  sborrill 	 * Keep adding entries while there is space in the ring.
   4939       1.4    bouyer 	 */
   4940  1.20.4.2  sborrill 	while (sc->used_tx_bd < sc->max_tx_bd) {
   4941       1.1    bouyer 		/* Check for any frames to send. */
   4942       1.1    bouyer 		IFQ_POLL(&ifp->if_snd, m_head);
   4943       1.1    bouyer 		if (m_head == NULL)
   4944       1.1    bouyer 			break;
   4945       1.1    bouyer 
   4946       1.1    bouyer 		/*
   4947       1.1    bouyer 		 * Pack the data into the transmit ring. If we
   4948       1.4    bouyer 		 * don't have room, set the OACTIVE flag to wait
   4949       1.4    bouyer 		 * for the NIC to drain the chain.
   4950       1.1    bouyer 		 */
   4951  1.20.4.2  sborrill 		if (bnx_tx_encap(sc, m_head)) {
   4952       1.1    bouyer 			ifp->if_flags |= IFF_OACTIVE;
   4953       1.1    bouyer 			DBPRINT(sc, BNX_INFO_SEND, "TX chain is closed for "
   4954       1.1    bouyer 			    "business! Total tx_bd used = %d\n",
   4955       1.1    bouyer 			    sc->used_tx_bd);
   4956       1.1    bouyer 			break;
   4957       1.1    bouyer 		}
   4958       1.1    bouyer 
   4959       1.1    bouyer 		IFQ_DEQUEUE(&ifp->if_snd, m_head);
   4960       1.1    bouyer 		count++;
   4961       1.1    bouyer 
   4962       1.1    bouyer #if NBPFILTER > 0
   4963       1.1    bouyer 		/* Send a copy of the frame to any BPF listeners. */
   4964       1.1    bouyer 		if (ifp->if_bpf)
   4965       1.1    bouyer 			bpf_mtap(ifp->if_bpf, m_head);
   4966       1.1    bouyer #endif
   4967       1.1    bouyer 	}
   4968       1.1    bouyer 
   4969       1.1    bouyer 	if (count == 0) {
   4970       1.1    bouyer 		/* no packets were dequeued */
   4971       1.1    bouyer 		DBPRINT(sc, BNX_VERBOSE_SEND,
   4972      1.12     perry 		    "%s(): No packets were dequeued\n", __func__);
   4973       1.4    bouyer 		goto bnx_start_exit;
   4974       1.1    bouyer 	}
   4975       1.1    bouyer 
   4976       1.1    bouyer 	/* Update the driver's counters. */
   4977       1.4    bouyer 	tx_chain_prod = TX_CHAIN_IDX(sc->tx_prod);
   4978       1.1    bouyer 
   4979       1.1    bouyer 	DBPRINT(sc, BNX_INFO_SEND, "%s(): End: tx_prod = 0x%04X, tx_chain_prod "
   4980      1.12     perry 	    "= 0x%04X, tx_prod_bseq = 0x%08X\n", __func__, tx_prod,
   4981       1.4    bouyer 	    tx_chain_prod, sc->tx_prod_bseq);
   4982       1.1    bouyer 
   4983       1.1    bouyer 	/* Start the transmit. */
   4984       1.1    bouyer 	REG_WR16(sc, MB_TX_CID_ADDR + BNX_L2CTX_TX_HOST_BIDX, sc->tx_prod);
   4985       1.1    bouyer 	REG_WR(sc, MB_TX_CID_ADDR + BNX_L2CTX_TX_HOST_BSEQ, sc->tx_prod_bseq);
   4986       1.1    bouyer 
   4987       1.1    bouyer 	/* Set the tx timeout. */
   4988       1.1    bouyer 	ifp->if_timer = BNX_TX_TIMEOUT;
   4989       1.1    bouyer 
   4990       1.4    bouyer bnx_start_exit:
   4991       1.1    bouyer 	return;
   4992       1.1    bouyer }
   4993       1.1    bouyer 
   4994       1.1    bouyer /****************************************************************************/
   4995       1.1    bouyer /* Handles any IOCTL calls from the operating system.                       */
   4996       1.1    bouyer /*                                                                          */
   4997       1.1    bouyer /* Returns:                                                                 */
   4998       1.1    bouyer /*   0 for success, positive value for failure.                             */
   4999       1.1    bouyer /****************************************************************************/
   5000       1.1    bouyer int
   5001       1.3  christos bnx_ioctl(struct ifnet *ifp, u_long command, void *data)
   5002       1.1    bouyer {
   5003       1.1    bouyer 	struct bnx_softc	*sc = ifp->if_softc;
   5004       1.1    bouyer 	struct ifreq		*ifr = (struct ifreq *) data;
   5005      1.20    mhitch 	struct mii_data		*mii = &sc->bnx_mii;
   5006       1.1    bouyer 	int			s, error = 0;
   5007       1.1    bouyer 
   5008       1.1    bouyer 	s = splnet();
   5009       1.1    bouyer 
   5010       1.1    bouyer 	switch (command) {
   5011       1.1    bouyer 	case SIOCSIFFLAGS:
   5012       1.1    bouyer 		if (ifp->if_flags & IFF_UP) {
   5013  1.20.4.2  sborrill 			if (ifp->if_flags & IFF_RUNNING)
   5014  1.20.4.2  sborrill 				error = ENETRESET;
   5015  1.20.4.2  sborrill 			else
   5016  1.20.4.2  sborrill 			    bnx_init(ifp);
   5017       1.4    bouyer 		} else if (ifp->if_flags & IFF_RUNNING)
   5018      1.14    dyoung 			bnx_stop(ifp, 1);
   5019       1.1    bouyer 		break;
   5020       1.1    bouyer 
   5021       1.1    bouyer 	case SIOCSIFMEDIA:
   5022       1.1    bouyer 	case SIOCGIFMEDIA:
   5023       1.1    bouyer 		DBPRINT(sc, BNX_VERBOSE, "bnx_phy_flags = 0x%08X\n",
   5024       1.1    bouyer 		    sc->bnx_phy_flags);
   5025       1.1    bouyer 
   5026      1.20    mhitch 		error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
   5027       1.1    bouyer 		break;
   5028       1.1    bouyer 
   5029       1.1    bouyer 	default:
   5030  1.20.4.2  sborrill 		error = ether_ioctl(ifp, command, data);
   5031  1.20.4.2  sborrill 	}
   5032      1.18    dyoung 
   5033  1.20.4.2  sborrill 	if (error == ENETRESET) {
   5034  1.20.4.2  sborrill 		if (ifp->if_flags & IFF_RUNNING)
   5035  1.20.4.2  sborrill 			bnx_iff(sc);
   5036  1.20.4.2  sborrill 		error = 0;
   5037       1.1    bouyer 	}
   5038       1.1    bouyer 
   5039       1.1    bouyer 	splx(s);
   5040       1.1    bouyer 	return (error);
   5041       1.1    bouyer }
   5042       1.1    bouyer 
   5043       1.1    bouyer /****************************************************************************/
   5044       1.1    bouyer /* Transmit timeout handler.                                                */
   5045       1.1    bouyer /*                                                                          */
   5046       1.1    bouyer /* Returns:                                                                 */
   5047       1.1    bouyer /*   Nothing.                                                               */
   5048       1.1    bouyer /****************************************************************************/
   5049       1.1    bouyer void
   5050       1.1    bouyer bnx_watchdog(struct ifnet *ifp)
   5051       1.1    bouyer {
   5052       1.1    bouyer 	struct bnx_softc	*sc = ifp->if_softc;
   5053       1.1    bouyer 
   5054       1.1    bouyer 	DBRUN(BNX_WARN_SEND, bnx_dump_driver_state(sc);
   5055       1.1    bouyer 	    bnx_dump_status_block(sc));
   5056  1.20.4.2  sborrill 	/*
   5057  1.20.4.2  sborrill 	 * If we are in this routine because of pause frames, then
   5058  1.20.4.2  sborrill 	 * don't reset the hardware.
   5059  1.20.4.2  sborrill 	 */
   5060  1.20.4.2  sborrill 	if (REG_RD(sc, BNX_EMAC_TX_STATUS) & BNX_EMAC_TX_STATUS_XOFFED)
   5061  1.20.4.2  sborrill 		return;
   5062       1.1    bouyer 
   5063      1.13    dyoung 	aprint_error_dev(sc->bnx_dev, "Watchdog timeout -- resetting!\n");
   5064       1.1    bouyer 
   5065       1.1    bouyer 	/* DBRUN(BNX_FATAL, bnx_breakpoint(sc)); */
   5066       1.1    bouyer 
   5067       1.1    bouyer 	bnx_init(ifp);
   5068       1.1    bouyer 
   5069       1.1    bouyer 	ifp->if_oerrors++;
   5070       1.1    bouyer }
   5071       1.1    bouyer 
   5072       1.1    bouyer /*
   5073       1.1    bouyer  * Interrupt handler.
   5074       1.1    bouyer  */
   5075       1.1    bouyer /****************************************************************************/
   5076       1.1    bouyer /* Main interrupt entry point.  Verifies that the controller generated the  */
   5077       1.1    bouyer /* interrupt and then calls a separate routine for handle the various       */
   5078       1.1    bouyer /* interrupt causes (PHY, TX, RX).                                          */
   5079       1.1    bouyer /*                                                                          */
   5080       1.1    bouyer /* Returns:                                                                 */
   5081       1.1    bouyer /*   0 for success, positive value for failure.                             */
   5082       1.1    bouyer /****************************************************************************/
   5083       1.1    bouyer int
   5084       1.1    bouyer bnx_intr(void *xsc)
   5085       1.1    bouyer {
   5086       1.1    bouyer 	struct bnx_softc	*sc;
   5087       1.1    bouyer 	struct ifnet		*ifp;
   5088       1.1    bouyer 	u_int32_t		status_attn_bits;
   5089      1.14    dyoung 	const struct status_block *sblk;
   5090       1.1    bouyer 
   5091       1.1    bouyer 	sc = xsc;
   5092      1.13    dyoung 	if (!device_is_active(sc->bnx_dev))
   5093      1.13    dyoung 		return 0;
   5094      1.13    dyoung 
   5095      1.15    dyoung 	ifp = &sc->bnx_ec.ec_if;
   5096       1.1    bouyer 
   5097       1.1    bouyer 	DBRUNIF(1, sc->interrupts_generated++);
   5098       1.1    bouyer 
   5099       1.1    bouyer 	bus_dmamap_sync(sc->bnx_dmatag, sc->status_map, 0,
   5100       1.1    bouyer 	    sc->status_map->dm_mapsize, BUS_DMASYNC_POSTWRITE);
   5101       1.1    bouyer 
   5102       1.1    bouyer 	/*
   5103       1.1    bouyer 	 * If the hardware status block index
   5104       1.1    bouyer 	 * matches the last value read by the
   5105       1.1    bouyer 	 * driver and we haven't asserted our
   5106       1.1    bouyer 	 * interrupt then there's nothing to do.
   5107       1.1    bouyer 	 */
   5108       1.1    bouyer 	if ((sc->status_block->status_idx == sc->last_status_idx) &&
   5109       1.1    bouyer 	    (REG_RD(sc, BNX_PCICFG_MISC_STATUS) &
   5110       1.1    bouyer 	    BNX_PCICFG_MISC_STATUS_INTA_VALUE))
   5111       1.1    bouyer 		return (0);
   5112       1.1    bouyer 
   5113       1.1    bouyer 	/* Ack the interrupt and stop others from occuring. */
   5114       1.1    bouyer 	REG_WR(sc, BNX_PCICFG_INT_ACK_CMD,
   5115       1.1    bouyer 	    BNX_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
   5116       1.1    bouyer 	    BNX_PCICFG_INT_ACK_CMD_MASK_INT);
   5117       1.1    bouyer 
   5118       1.1    bouyer 	/* Keep processing data as long as there is work to do. */
   5119       1.1    bouyer 	for (;;) {
   5120      1.14    dyoung 		sblk = sc->status_block;
   5121      1.14    dyoung 		status_attn_bits = sblk->status_attn_bits;
   5122       1.1    bouyer 
   5123       1.1    bouyer 		DBRUNIF(DB_RANDOMTRUE(bnx_debug_unexpected_attention),
   5124       1.1    bouyer 		    aprint_debug("Simulating unexpected status attention bit set.");
   5125       1.1    bouyer 		    status_attn_bits = status_attn_bits |
   5126       1.1    bouyer 		    STATUS_ATTN_BITS_PARITY_ERROR);
   5127       1.1    bouyer 
   5128       1.1    bouyer 		/* Was it a link change interrupt? */
   5129       1.1    bouyer 		if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
   5130      1.14    dyoung 		    (sblk->status_attn_bits_ack &
   5131       1.1    bouyer 		    STATUS_ATTN_BITS_LINK_STATE))
   5132       1.1    bouyer 			bnx_phy_intr(sc);
   5133       1.1    bouyer 
   5134       1.1    bouyer 		/* If any other attention is asserted then the chip is toast. */
   5135       1.1    bouyer 		if (((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
   5136      1.14    dyoung 		    (sblk->status_attn_bits_ack &
   5137       1.1    bouyer 		    ~STATUS_ATTN_BITS_LINK_STATE))) {
   5138       1.1    bouyer 			DBRUN(1, sc->unexpected_attentions++);
   5139       1.1    bouyer 
   5140  1.20.4.2  sborrill 			BNX_PRINTF(sc,
   5141      1.13    dyoung 			    "Fatal attention detected: 0x%08X\n",
   5142      1.14    dyoung 			    sblk->status_attn_bits);
   5143       1.1    bouyer 
   5144       1.1    bouyer 			DBRUN(BNX_FATAL,
   5145       1.1    bouyer 			    if (bnx_debug_unexpected_attention == 0)
   5146       1.1    bouyer 			    bnx_breakpoint(sc));
   5147       1.1    bouyer 
   5148       1.1    bouyer 			bnx_init(ifp);
   5149       1.1    bouyer 			return (1);
   5150       1.1    bouyer 		}
   5151       1.1    bouyer 
   5152       1.1    bouyer 		/* Check for any completed RX frames. */
   5153      1.14    dyoung 		if (sblk->status_rx_quick_consumer_index0 !=
   5154       1.1    bouyer 		    sc->hw_rx_cons)
   5155       1.1    bouyer 			bnx_rx_intr(sc);
   5156       1.1    bouyer 
   5157       1.1    bouyer 		/* Check for any completed TX frames. */
   5158      1.14    dyoung 		if (sblk->status_tx_quick_consumer_index0 !=
   5159       1.1    bouyer 		    sc->hw_tx_cons)
   5160       1.1    bouyer 			bnx_tx_intr(sc);
   5161       1.1    bouyer 
   5162       1.1    bouyer 		/* Save the status block index value for use during the
   5163       1.1    bouyer 		 * next interrupt.
   5164       1.1    bouyer 		 */
   5165      1.14    dyoung 		sc->last_status_idx = sblk->status_idx;
   5166       1.1    bouyer 
   5167       1.1    bouyer 		/* Prevent speculative reads from getting ahead of the
   5168       1.1    bouyer 		 * status block.
   5169       1.1    bouyer 		 */
   5170       1.1    bouyer 		bus_space_barrier(sc->bnx_btag, sc->bnx_bhandle, 0, 0,
   5171       1.1    bouyer 		    BUS_SPACE_BARRIER_READ);
   5172       1.1    bouyer 
   5173       1.1    bouyer 		/* If there's no work left then exit the isr. */
   5174      1.14    dyoung 		if ((sblk->status_rx_quick_consumer_index0 ==
   5175       1.1    bouyer 		    sc->hw_rx_cons) &&
   5176      1.14    dyoung 		    (sblk->status_tx_quick_consumer_index0 ==
   5177       1.1    bouyer 		    sc->hw_tx_cons))
   5178       1.1    bouyer 			break;
   5179       1.1    bouyer 	}
   5180       1.1    bouyer 
   5181       1.1    bouyer 	bus_dmamap_sync(sc->bnx_dmatag, sc->status_map, 0,
   5182       1.1    bouyer 	    sc->status_map->dm_mapsize, BUS_DMASYNC_PREWRITE);
   5183       1.1    bouyer 
   5184       1.1    bouyer 	/* Re-enable interrupts. */
   5185       1.1    bouyer 	REG_WR(sc, BNX_PCICFG_INT_ACK_CMD,
   5186       1.1    bouyer 	    BNX_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx |
   5187       1.4    bouyer 	    BNX_PCICFG_INT_ACK_CMD_MASK_INT);
   5188       1.1    bouyer 	REG_WR(sc, BNX_PCICFG_INT_ACK_CMD,
   5189       1.1    bouyer 	    BNX_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
   5190       1.1    bouyer 
   5191       1.1    bouyer 	/* Handle any frames that arrived while handling the interrupt. */
   5192      1.16    dyoung 	if (!IFQ_IS_EMPTY(&ifp->if_snd))
   5193       1.1    bouyer 		bnx_start(ifp);
   5194       1.1    bouyer 
   5195       1.1    bouyer 	return (1);
   5196       1.1    bouyer }
   5197       1.1    bouyer 
   5198       1.1    bouyer /****************************************************************************/
   5199       1.1    bouyer /* Programs the various packet receive modes (broadcast and multicast).     */
   5200       1.1    bouyer /*                                                                          */
   5201       1.1    bouyer /* Returns:                                                                 */
   5202       1.1    bouyer /*   Nothing.                                                               */
   5203       1.1    bouyer /****************************************************************************/
   5204       1.1    bouyer void
   5205  1.20.4.2  sborrill bnx_iff(struct bnx_softc *sc)
   5206       1.1    bouyer {
   5207      1.15    dyoung 	struct ethercom		*ec = &sc->bnx_ec;
   5208       1.1    bouyer 	struct ifnet		*ifp = &ec->ec_if;
   5209       1.1    bouyer 	struct ether_multi	*enm;
   5210       1.1    bouyer 	struct ether_multistep	step;
   5211       1.4    bouyer 	u_int32_t		hashes[NUM_MC_HASH_REGISTERS] = { 0, 0, 0, 0, 0, 0, 0, 0 };
   5212       1.1    bouyer 	u_int32_t		rx_mode, sort_mode;
   5213       1.1    bouyer 	int			h, i;
   5214       1.1    bouyer 
   5215       1.1    bouyer 	/* Initialize receive mode default settings. */
   5216       1.1    bouyer 	rx_mode = sc->rx_mode & ~(BNX_EMAC_RX_MODE_PROMISCUOUS |
   5217       1.1    bouyer 	    BNX_EMAC_RX_MODE_KEEP_VLAN_TAG);
   5218       1.1    bouyer 	sort_mode = 1 | BNX_RPM_SORT_USER0_BC_EN;
   5219  1.20.4.2  sborrill 	ifp->if_flags &= ~IFF_ALLMULTI;
   5220       1.1    bouyer 
   5221       1.1    bouyer 	/*
   5222       1.1    bouyer 	 * ASF/IPMI/UMP firmware requires that VLAN tag stripping
   5223       1.1    bouyer 	 * be enbled.
   5224       1.1    bouyer 	 */
   5225       1.1    bouyer 	if (!(sc->bnx_flags & BNX_MFW_ENABLE_FLAG))
   5226       1.1    bouyer 		rx_mode |= BNX_EMAC_RX_MODE_KEEP_VLAN_TAG;
   5227       1.1    bouyer 
   5228       1.1    bouyer 	/*
   5229       1.1    bouyer 	 * Check for promiscuous, all multicast, or selected
   5230       1.1    bouyer 	 * multicast address filtering.
   5231       1.1    bouyer 	 */
   5232       1.1    bouyer 	if (ifp->if_flags & IFF_PROMISC) {
   5233       1.1    bouyer 		DBPRINT(sc, BNX_INFO, "Enabling promiscuous mode.\n");
   5234       1.1    bouyer 
   5235  1.20.4.2  sborrill 		ifp->if_flags |= IFF_ALLMULTI;
   5236       1.1    bouyer 		/* Enable promiscuous mode. */
   5237       1.1    bouyer 		rx_mode |= BNX_EMAC_RX_MODE_PROMISCUOUS;
   5238       1.1    bouyer 		sort_mode |= BNX_RPM_SORT_USER0_PROM_EN;
   5239       1.1    bouyer 	} else if (ifp->if_flags & IFF_ALLMULTI) {
   5240       1.1    bouyer allmulti:
   5241       1.1    bouyer 		DBPRINT(sc, BNX_INFO, "Enabling all multicast mode.\n");
   5242       1.1    bouyer 
   5243  1.20.4.2  sborrill 		ifp->if_flags |= IFF_ALLMULTI;
   5244       1.1    bouyer 		/* Enable all multicast addresses. */
   5245       1.1    bouyer 		for (i = 0; i < NUM_MC_HASH_REGISTERS; i++)
   5246       1.1    bouyer 			REG_WR(sc, BNX_EMAC_MULTICAST_HASH0 + (i * 4),
   5247       1.1    bouyer 			    0xffffffff);
   5248       1.1    bouyer 		sort_mode |= BNX_RPM_SORT_USER0_MC_EN;
   5249       1.1    bouyer 	} else {
   5250       1.1    bouyer 		/* Accept one or more multicast(s). */
   5251       1.1    bouyer 		DBPRINT(sc, BNX_INFO, "Enabling selective multicast mode.\n");
   5252       1.1    bouyer 
   5253       1.1    bouyer 		ETHER_FIRST_MULTI(step, ec, enm);
   5254       1.1    bouyer 		while (enm != NULL) {
   5255  1.20.4.2  sborrill 			if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
   5256       1.1    bouyer 			    ETHER_ADDR_LEN)) {
   5257       1.1    bouyer 				goto allmulti;
   5258       1.1    bouyer 			}
   5259       1.1    bouyer 			h = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN) &
   5260       1.4    bouyer 			    0xFF;
   5261       1.4    bouyer 			hashes[(h & 0xE0) >> 5] |= 1 << (h & 0x1F);
   5262       1.1    bouyer 			ETHER_NEXT_MULTI(step, enm);
   5263       1.1    bouyer 		}
   5264       1.1    bouyer 
   5265       1.4    bouyer 		for (i = 0; i < NUM_MC_HASH_REGISTERS; i++)
   5266       1.1    bouyer 			REG_WR(sc, BNX_EMAC_MULTICAST_HASH0 + (i * 4),
   5267       1.1    bouyer 			    hashes[i]);
   5268       1.1    bouyer 
   5269       1.1    bouyer 		sort_mode |= BNX_RPM_SORT_USER0_MC_HSH_EN;
   5270       1.1    bouyer 	}
   5271       1.1    bouyer 
   5272       1.1    bouyer 	/* Only make changes if the recive mode has actually changed. */
   5273       1.1    bouyer 	if (rx_mode != sc->rx_mode) {
   5274       1.1    bouyer 		DBPRINT(sc, BNX_VERBOSE, "Enabling new receive mode: 0x%08X\n",
   5275       1.1    bouyer 		    rx_mode);
   5276       1.1    bouyer 
   5277       1.1    bouyer 		sc->rx_mode = rx_mode;
   5278       1.1    bouyer 		REG_WR(sc, BNX_EMAC_RX_MODE, rx_mode);
   5279       1.1    bouyer 	}
   5280       1.1    bouyer 
   5281       1.1    bouyer 	/* Disable and clear the exisitng sort before enabling a new sort. */
   5282       1.1    bouyer 	REG_WR(sc, BNX_RPM_SORT_USER0, 0x0);
   5283       1.1    bouyer 	REG_WR(sc, BNX_RPM_SORT_USER0, sort_mode);
   5284       1.1    bouyer 	REG_WR(sc, BNX_RPM_SORT_USER0, sort_mode | BNX_RPM_SORT_USER0_ENA);
   5285       1.1    bouyer }
   5286       1.1    bouyer 
   5287       1.1    bouyer /****************************************************************************/
   5288       1.1    bouyer /* Called periodically to updates statistics from the controllers           */
   5289       1.1    bouyer /* statistics block.                                                        */
   5290       1.1    bouyer /*                                                                          */
   5291       1.1    bouyer /* Returns:                                                                 */
   5292       1.1    bouyer /*   Nothing.                                                               */
   5293       1.1    bouyer /****************************************************************************/
   5294       1.1    bouyer void
   5295       1.1    bouyer bnx_stats_update(struct bnx_softc *sc)
   5296       1.1    bouyer {
   5297      1.15    dyoung 	struct ifnet		*ifp = &sc->bnx_ec.ec_if;
   5298       1.1    bouyer 	struct statistics_block	*stats;
   5299       1.1    bouyer 
   5300      1.12     perry 	DBPRINT(sc, BNX_EXCESSIVE, "Entering %s()\n", __func__);
   5301       1.1    bouyer 	bus_dmamap_sync(sc->bnx_dmatag, sc->status_map, 0, BNX_STATUS_BLK_SZ,
   5302       1.1    bouyer 	    BUS_DMASYNC_POSTREAD);
   5303       1.1    bouyer 
   5304       1.1    bouyer 	stats = (struct statistics_block *)sc->stats_block;
   5305       1.1    bouyer 
   5306       1.1    bouyer 	/*
   5307       1.1    bouyer 	 * Update the interface statistics from the
   5308       1.1    bouyer 	 * hardware statistics.
   5309       1.1    bouyer 	 */
   5310       1.1    bouyer 	ifp->if_collisions = (u_long)stats->stat_EtherStatsCollisions;
   5311       1.1    bouyer 
   5312       1.1    bouyer 	ifp->if_ierrors = (u_long)stats->stat_EtherStatsUndersizePkts +
   5313       1.1    bouyer 	    (u_long)stats->stat_EtherStatsOverrsizePkts +
   5314       1.1    bouyer 	    (u_long)stats->stat_IfInMBUFDiscards +
   5315       1.1    bouyer 	    (u_long)stats->stat_Dot3StatsAlignmentErrors +
   5316       1.1    bouyer 	    (u_long)stats->stat_Dot3StatsFCSErrors;
   5317       1.1    bouyer 
   5318       1.1    bouyer 	ifp->if_oerrors = (u_long)
   5319       1.1    bouyer 	    stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors +
   5320       1.1    bouyer 	    (u_long)stats->stat_Dot3StatsExcessiveCollisions +
   5321       1.1    bouyer 	    (u_long)stats->stat_Dot3StatsLateCollisions;
   5322       1.1    bouyer 
   5323       1.1    bouyer 	/*
   5324       1.1    bouyer 	 * Certain controllers don't report
   5325       1.1    bouyer 	 * carrier sense errors correctly.
   5326       1.1    bouyer 	 * See errata E11_5708CA0_1165.
   5327       1.1    bouyer 	 */
   5328       1.1    bouyer 	if (!(BNX_CHIP_NUM(sc) == BNX_CHIP_NUM_5706) &&
   5329       1.1    bouyer 	    !(BNX_CHIP_ID(sc) == BNX_CHIP_ID_5708_A0))
   5330       1.1    bouyer 		ifp->if_oerrors += (u_long) stats->stat_Dot3StatsCarrierSenseErrors;
   5331       1.1    bouyer 
   5332       1.1    bouyer 	/*
   5333       1.1    bouyer 	 * Update the sysctl statistics from the
   5334       1.1    bouyer 	 * hardware statistics.
   5335       1.1    bouyer 	 */
   5336       1.1    bouyer 	sc->stat_IfHCInOctets = ((u_int64_t)stats->stat_IfHCInOctets_hi << 32) +
   5337       1.1    bouyer 	    (u_int64_t) stats->stat_IfHCInOctets_lo;
   5338       1.1    bouyer 
   5339       1.1    bouyer 	sc->stat_IfHCInBadOctets =
   5340       1.1    bouyer 	    ((u_int64_t) stats->stat_IfHCInBadOctets_hi << 32) +
   5341       1.1    bouyer 	    (u_int64_t) stats->stat_IfHCInBadOctets_lo;
   5342       1.1    bouyer 
   5343       1.1    bouyer 	sc->stat_IfHCOutOctets =
   5344       1.1    bouyer 	    ((u_int64_t) stats->stat_IfHCOutOctets_hi << 32) +
   5345       1.1    bouyer 	    (u_int64_t) stats->stat_IfHCOutOctets_lo;
   5346       1.1    bouyer 
   5347       1.1    bouyer 	sc->stat_IfHCOutBadOctets =
   5348       1.1    bouyer 	    ((u_int64_t) stats->stat_IfHCOutBadOctets_hi << 32) +
   5349       1.1    bouyer 	    (u_int64_t) stats->stat_IfHCOutBadOctets_lo;
   5350       1.1    bouyer 
   5351       1.1    bouyer 	sc->stat_IfHCInUcastPkts =
   5352       1.1    bouyer 	    ((u_int64_t) stats->stat_IfHCInUcastPkts_hi << 32) +
   5353       1.1    bouyer 	    (u_int64_t) stats->stat_IfHCInUcastPkts_lo;
   5354       1.1    bouyer 
   5355       1.1    bouyer 	sc->stat_IfHCInMulticastPkts =
   5356       1.1    bouyer 	    ((u_int64_t) stats->stat_IfHCInMulticastPkts_hi << 32) +
   5357       1.1    bouyer 	    (u_int64_t) stats->stat_IfHCInMulticastPkts_lo;
   5358       1.1    bouyer 
   5359       1.1    bouyer 	sc->stat_IfHCInBroadcastPkts =
   5360       1.1    bouyer 	    ((u_int64_t) stats->stat_IfHCInBroadcastPkts_hi << 32) +
   5361       1.1    bouyer 	    (u_int64_t) stats->stat_IfHCInBroadcastPkts_lo;
   5362       1.1    bouyer 
   5363       1.1    bouyer 	sc->stat_IfHCOutUcastPkts =
   5364       1.1    bouyer 	   ((u_int64_t) stats->stat_IfHCOutUcastPkts_hi << 32) +
   5365       1.1    bouyer 	    (u_int64_t) stats->stat_IfHCOutUcastPkts_lo;
   5366       1.1    bouyer 
   5367       1.1    bouyer 	sc->stat_IfHCOutMulticastPkts =
   5368       1.1    bouyer 	    ((u_int64_t) stats->stat_IfHCOutMulticastPkts_hi << 32) +
   5369       1.1    bouyer 	    (u_int64_t) stats->stat_IfHCOutMulticastPkts_lo;
   5370       1.1    bouyer 
   5371       1.1    bouyer 	sc->stat_IfHCOutBroadcastPkts =
   5372       1.1    bouyer 	    ((u_int64_t) stats->stat_IfHCOutBroadcastPkts_hi << 32) +
   5373       1.1    bouyer 	    (u_int64_t) stats->stat_IfHCOutBroadcastPkts_lo;
   5374       1.1    bouyer 
   5375       1.1    bouyer 	sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors =
   5376       1.1    bouyer 	    stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors;
   5377       1.1    bouyer 
   5378       1.1    bouyer 	sc->stat_Dot3StatsCarrierSenseErrors =
   5379       1.1    bouyer 	    stats->stat_Dot3StatsCarrierSenseErrors;
   5380       1.1    bouyer 
   5381       1.1    bouyer 	sc->stat_Dot3StatsFCSErrors = stats->stat_Dot3StatsFCSErrors;
   5382       1.1    bouyer 
   5383       1.1    bouyer 	sc->stat_Dot3StatsAlignmentErrors =
   5384       1.1    bouyer 	    stats->stat_Dot3StatsAlignmentErrors;
   5385       1.1    bouyer 
   5386       1.1    bouyer 	sc->stat_Dot3StatsSingleCollisionFrames =
   5387       1.1    bouyer 	    stats->stat_Dot3StatsSingleCollisionFrames;
   5388       1.1    bouyer 
   5389       1.1    bouyer 	sc->stat_Dot3StatsMultipleCollisionFrames =
   5390       1.1    bouyer 	    stats->stat_Dot3StatsMultipleCollisionFrames;
   5391       1.1    bouyer 
   5392       1.1    bouyer 	sc->stat_Dot3StatsDeferredTransmissions =
   5393       1.1    bouyer 	    stats->stat_Dot3StatsDeferredTransmissions;
   5394       1.1    bouyer 
   5395       1.1    bouyer 	sc->stat_Dot3StatsExcessiveCollisions =
   5396       1.1    bouyer 	    stats->stat_Dot3StatsExcessiveCollisions;
   5397       1.1    bouyer 
   5398       1.1    bouyer 	sc->stat_Dot3StatsLateCollisions = stats->stat_Dot3StatsLateCollisions;
   5399       1.1    bouyer 
   5400       1.1    bouyer 	sc->stat_EtherStatsCollisions = stats->stat_EtherStatsCollisions;
   5401       1.1    bouyer 
   5402       1.1    bouyer 	sc->stat_EtherStatsFragments = stats->stat_EtherStatsFragments;
   5403       1.1    bouyer 
   5404       1.1    bouyer 	sc->stat_EtherStatsJabbers = stats->stat_EtherStatsJabbers;
   5405       1.1    bouyer 
   5406       1.1    bouyer 	sc->stat_EtherStatsUndersizePkts = stats->stat_EtherStatsUndersizePkts;
   5407       1.1    bouyer 
   5408       1.1    bouyer 	sc->stat_EtherStatsOverrsizePkts = stats->stat_EtherStatsOverrsizePkts;
   5409       1.1    bouyer 
   5410       1.1    bouyer 	sc->stat_EtherStatsPktsRx64Octets =
   5411       1.1    bouyer 	    stats->stat_EtherStatsPktsRx64Octets;
   5412       1.1    bouyer 
   5413       1.1    bouyer 	sc->stat_EtherStatsPktsRx65Octetsto127Octets =
   5414       1.1    bouyer 	    stats->stat_EtherStatsPktsRx65Octetsto127Octets;
   5415       1.1    bouyer 
   5416       1.1    bouyer 	sc->stat_EtherStatsPktsRx128Octetsto255Octets =
   5417       1.1    bouyer 	    stats->stat_EtherStatsPktsRx128Octetsto255Octets;
   5418       1.1    bouyer 
   5419       1.1    bouyer 	sc->stat_EtherStatsPktsRx256Octetsto511Octets =
   5420       1.1    bouyer 	    stats->stat_EtherStatsPktsRx256Octetsto511Octets;
   5421       1.1    bouyer 
   5422       1.1    bouyer 	sc->stat_EtherStatsPktsRx512Octetsto1023Octets =
   5423       1.1    bouyer 	    stats->stat_EtherStatsPktsRx512Octetsto1023Octets;
   5424       1.1    bouyer 
   5425       1.1    bouyer 	sc->stat_EtherStatsPktsRx1024Octetsto1522Octets =
   5426       1.1    bouyer 	    stats->stat_EtherStatsPktsRx1024Octetsto1522Octets;
   5427       1.1    bouyer 
   5428       1.1    bouyer 	sc->stat_EtherStatsPktsRx1523Octetsto9022Octets =
   5429       1.1    bouyer 	    stats->stat_EtherStatsPktsRx1523Octetsto9022Octets;
   5430       1.1    bouyer 
   5431       1.1    bouyer 	sc->stat_EtherStatsPktsTx64Octets =
   5432       1.1    bouyer 	    stats->stat_EtherStatsPktsTx64Octets;
   5433       1.1    bouyer 
   5434       1.1    bouyer 	sc->stat_EtherStatsPktsTx65Octetsto127Octets =
   5435       1.1    bouyer 	    stats->stat_EtherStatsPktsTx65Octetsto127Octets;
   5436       1.1    bouyer 
   5437       1.1    bouyer 	sc->stat_EtherStatsPktsTx128Octetsto255Octets =
   5438       1.1    bouyer 	    stats->stat_EtherStatsPktsTx128Octetsto255Octets;
   5439       1.1    bouyer 
   5440       1.1    bouyer 	sc->stat_EtherStatsPktsTx256Octetsto511Octets =
   5441       1.1    bouyer 	    stats->stat_EtherStatsPktsTx256Octetsto511Octets;
   5442       1.1    bouyer 
   5443       1.1    bouyer 	sc->stat_EtherStatsPktsTx512Octetsto1023Octets =
   5444       1.1    bouyer 	    stats->stat_EtherStatsPktsTx512Octetsto1023Octets;
   5445       1.1    bouyer 
   5446       1.1    bouyer 	sc->stat_EtherStatsPktsTx1024Octetsto1522Octets =
   5447       1.1    bouyer 	    stats->stat_EtherStatsPktsTx1024Octetsto1522Octets;
   5448       1.1    bouyer 
   5449       1.1    bouyer 	sc->stat_EtherStatsPktsTx1523Octetsto9022Octets =
   5450       1.1    bouyer 	    stats->stat_EtherStatsPktsTx1523Octetsto9022Octets;
   5451       1.1    bouyer 
   5452       1.1    bouyer 	sc->stat_XonPauseFramesReceived = stats->stat_XonPauseFramesReceived;
   5453       1.1    bouyer 
   5454       1.1    bouyer 	sc->stat_XoffPauseFramesReceived = stats->stat_XoffPauseFramesReceived;
   5455       1.1    bouyer 
   5456       1.1    bouyer 	sc->stat_OutXonSent = stats->stat_OutXonSent;
   5457       1.1    bouyer 
   5458       1.1    bouyer 	sc->stat_OutXoffSent = stats->stat_OutXoffSent;
   5459       1.1    bouyer 
   5460       1.1    bouyer 	sc->stat_FlowControlDone = stats->stat_FlowControlDone;
   5461       1.1    bouyer 
   5462       1.1    bouyer 	sc->stat_MacControlFramesReceived =
   5463       1.1    bouyer 	    stats->stat_MacControlFramesReceived;
   5464       1.1    bouyer 
   5465       1.1    bouyer 	sc->stat_XoffStateEntered = stats->stat_XoffStateEntered;
   5466       1.1    bouyer 
   5467       1.1    bouyer 	sc->stat_IfInFramesL2FilterDiscards =
   5468       1.1    bouyer 	    stats->stat_IfInFramesL2FilterDiscards;
   5469       1.1    bouyer 
   5470       1.1    bouyer 	sc->stat_IfInRuleCheckerDiscards = stats->stat_IfInRuleCheckerDiscards;
   5471       1.1    bouyer 
   5472       1.1    bouyer 	sc->stat_IfInFTQDiscards = stats->stat_IfInFTQDiscards;
   5473       1.1    bouyer 
   5474       1.1    bouyer 	sc->stat_IfInMBUFDiscards = stats->stat_IfInMBUFDiscards;
   5475       1.1    bouyer 
   5476       1.1    bouyer 	sc->stat_IfInRuleCheckerP4Hit = stats->stat_IfInRuleCheckerP4Hit;
   5477       1.1    bouyer 
   5478       1.1    bouyer 	sc->stat_CatchupInRuleCheckerDiscards =
   5479       1.1    bouyer 	    stats->stat_CatchupInRuleCheckerDiscards;
   5480       1.1    bouyer 
   5481       1.1    bouyer 	sc->stat_CatchupInFTQDiscards = stats->stat_CatchupInFTQDiscards;
   5482       1.1    bouyer 
   5483       1.1    bouyer 	sc->stat_CatchupInMBUFDiscards = stats->stat_CatchupInMBUFDiscards;
   5484       1.1    bouyer 
   5485       1.1    bouyer 	sc->stat_CatchupInRuleCheckerP4Hit =
   5486       1.1    bouyer 	    stats->stat_CatchupInRuleCheckerP4Hit;
   5487       1.1    bouyer 
   5488      1.12     perry 	DBPRINT(sc, BNX_EXCESSIVE, "Exiting %s()\n", __func__);
   5489       1.1    bouyer }
   5490       1.1    bouyer 
   5491       1.1    bouyer void
   5492       1.1    bouyer bnx_tick(void *xsc)
   5493       1.1    bouyer {
   5494       1.1    bouyer 	struct bnx_softc	*sc = xsc;
   5495      1.14    dyoung 	struct mii_data		*mii;
   5496       1.1    bouyer 	u_int32_t		msg;
   5497       1.5    bouyer 	u_int16_t		prod, chain_prod;
   5498       1.5    bouyer 	u_int32_t		prod_bseq;
   5499       1.4    bouyer 	int s = splnet();
   5500       1.1    bouyer 
   5501       1.1    bouyer 	/* Tell the firmware that the driver is still running. */
   5502       1.1    bouyer #ifdef BNX_DEBUG
   5503       1.1    bouyer 	msg = (u_int32_t)BNX_DRV_MSG_DATA_PULSE_CODE_ALWAYS_ALIVE;
   5504       1.1    bouyer #else
   5505       1.1    bouyer 	msg = (u_int32_t)++sc->bnx_fw_drv_pulse_wr_seq;
   5506       1.1    bouyer #endif
   5507       1.1    bouyer 	REG_WR_IND(sc, sc->bnx_shmem_base + BNX_DRV_PULSE_MB, msg);
   5508       1.1    bouyer 
   5509       1.1    bouyer 	/* Update the statistics from the hardware statistics block. */
   5510       1.1    bouyer 	bnx_stats_update(sc);
   5511       1.1    bouyer 
   5512       1.1    bouyer 	/* Schedule the next tick. */
   5513       1.1    bouyer 	callout_reset(&sc->bnx_timeout, hz, bnx_tick, sc);
   5514       1.1    bouyer 
   5515       1.1    bouyer 	mii = &sc->bnx_mii;
   5516       1.1    bouyer 	mii_tick(mii);
   5517       1.1    bouyer 
   5518       1.5    bouyer 	/* try to get more RX buffers, just in case */
   5519       1.5    bouyer 	prod = sc->rx_prod;
   5520       1.5    bouyer 	prod_bseq = sc->rx_prod_bseq;
   5521       1.5    bouyer 	chain_prod = RX_CHAIN_IDX(prod);
   5522  1.20.4.1    bouyer 	bnx_get_buf(sc, &prod, &chain_prod, &prod_bseq);
   5523       1.5    bouyer 	sc->rx_prod = prod;
   5524       1.5    bouyer 	sc->rx_prod_bseq = prod_bseq;
   5525       1.4    bouyer 	splx(s);
   5526       1.1    bouyer 	return;
   5527       1.1    bouyer }
   5528       1.1    bouyer 
   5529       1.1    bouyer /****************************************************************************/
   5530       1.1    bouyer /* BNX Debug Routines                                                       */
   5531       1.1    bouyer /****************************************************************************/
   5532       1.1    bouyer #ifdef BNX_DEBUG
   5533       1.1    bouyer 
   5534       1.1    bouyer /****************************************************************************/
   5535       1.1    bouyer /* Prints out information about an mbuf.                                    */
   5536       1.1    bouyer /*                                                                          */
   5537       1.1    bouyer /* Returns:                                                                 */
   5538       1.1    bouyer /*   Nothing.                                                               */
   5539       1.1    bouyer /****************************************************************************/
   5540       1.1    bouyer void
   5541       1.1    bouyer bnx_dump_mbuf(struct bnx_softc *sc, struct mbuf *m)
   5542       1.1    bouyer {
   5543       1.1    bouyer 	struct mbuf		*mp = m;
   5544       1.1    bouyer 
   5545       1.1    bouyer 	if (m == NULL) {
   5546       1.1    bouyer 		/* Index out of range. */
   5547       1.1    bouyer 		aprint_error("mbuf ptr is null!\n");
   5548       1.1    bouyer 		return;
   5549       1.1    bouyer 	}
   5550       1.1    bouyer 
   5551       1.1    bouyer 	while (mp) {
   5552       1.1    bouyer 		aprint_debug("mbuf: vaddr = %p, m_len = %d, m_flags = ",
   5553       1.1    bouyer 		    mp, mp->m_len);
   5554       1.1    bouyer 
   5555       1.1    bouyer 		if (mp->m_flags & M_EXT)
   5556       1.1    bouyer 			aprint_debug("M_EXT ");
   5557       1.1    bouyer 		if (mp->m_flags & M_PKTHDR)
   5558       1.1    bouyer 			aprint_debug("M_PKTHDR ");
   5559       1.1    bouyer 		aprint_debug("\n");
   5560       1.1    bouyer 
   5561       1.1    bouyer 		if (mp->m_flags & M_EXT)
   5562       1.1    bouyer 			aprint_debug("- m_ext: vaddr = %p, ext_size = 0x%04zX\n",
   5563       1.1    bouyer 			    mp, mp->m_ext.ext_size);
   5564       1.1    bouyer 
   5565       1.1    bouyer 		mp = mp->m_next;
   5566       1.1    bouyer 	}
   5567       1.1    bouyer }
   5568       1.1    bouyer 
   5569       1.1    bouyer /****************************************************************************/
   5570       1.1    bouyer /* Prints out the mbufs in the TX mbuf chain.                               */
   5571       1.1    bouyer /*                                                                          */
   5572       1.1    bouyer /* Returns:                                                                 */
   5573       1.1    bouyer /*   Nothing.                                                               */
   5574       1.1    bouyer /****************************************************************************/
   5575       1.1    bouyer void
   5576       1.1    bouyer bnx_dump_tx_mbuf_chain(struct bnx_softc *sc, int chain_prod, int count)
   5577       1.1    bouyer {
   5578  1.20.4.2  sborrill #if 0
   5579       1.1    bouyer 	struct mbuf		*m;
   5580       1.1    bouyer 	int			i;
   5581       1.1    bouyer 
   5582  1.20.4.2  sborrill 	aprint_debug_dev(sc->bnx_dev,
   5583       1.1    bouyer 	    "----------------------------"
   5584       1.1    bouyer 	    "  tx mbuf data  "
   5585       1.1    bouyer 	    "----------------------------\n");
   5586       1.1    bouyer 
   5587       1.1    bouyer 	for (i = 0; i < count; i++) {
   5588       1.1    bouyer 	 	m = sc->tx_mbuf_ptr[chain_prod];
   5589       1.1    bouyer 		BNX_PRINTF(sc, "txmbuf[%d]\n", chain_prod);
   5590       1.1    bouyer 		bnx_dump_mbuf(sc, m);
   5591       1.1    bouyer 		chain_prod = TX_CHAIN_IDX(NEXT_TX_BD(chain_prod));
   5592       1.1    bouyer 	}
   5593       1.1    bouyer 
   5594  1.20.4.2  sborrill 	aprint_debug_dev(sc->bnx_dev,
   5595       1.1    bouyer 	    "--------------------------------------------"
   5596       1.1    bouyer 	    "----------------------------\n");
   5597  1.20.4.2  sborrill #endif
   5598       1.1    bouyer }
   5599       1.1    bouyer 
   5600       1.1    bouyer /*
   5601       1.1    bouyer  * This routine prints the RX mbuf chain.
   5602       1.1    bouyer  */
   5603       1.1    bouyer void
   5604       1.1    bouyer bnx_dump_rx_mbuf_chain(struct bnx_softc *sc, int chain_prod, int count)
   5605       1.1    bouyer {
   5606       1.1    bouyer 	struct mbuf		*m;
   5607       1.1    bouyer 	int			i;
   5608       1.1    bouyer 
   5609  1.20.4.2  sborrill 	aprint_debug_dev(sc->bnx_dev,
   5610       1.1    bouyer 	    "----------------------------"
   5611       1.1    bouyer 	    "  rx mbuf data  "
   5612       1.1    bouyer 	    "----------------------------\n");
   5613       1.1    bouyer 
   5614       1.1    bouyer 	for (i = 0; i < count; i++) {
   5615       1.1    bouyer 	 	m = sc->rx_mbuf_ptr[chain_prod];
   5616       1.1    bouyer 		BNX_PRINTF(sc, "rxmbuf[0x%04X]\n", chain_prod);
   5617       1.1    bouyer 		bnx_dump_mbuf(sc, m);
   5618       1.1    bouyer 		chain_prod = RX_CHAIN_IDX(NEXT_RX_BD(chain_prod));
   5619       1.1    bouyer 	}
   5620       1.1    bouyer 
   5621       1.1    bouyer 
   5622  1.20.4.2  sborrill 	aprint_debug_dev(sc->bnx_dev,
   5623       1.1    bouyer 	    "--------------------------------------------"
   5624       1.1    bouyer 	    "----------------------------\n");
   5625       1.1    bouyer }
   5626       1.1    bouyer 
   5627       1.1    bouyer void
   5628       1.1    bouyer bnx_dump_txbd(struct bnx_softc *sc, int idx, struct tx_bd *txbd)
   5629       1.1    bouyer {
   5630       1.1    bouyer 	if (idx > MAX_TX_BD)
   5631       1.1    bouyer 		/* Index out of range. */
   5632       1.1    bouyer 		BNX_PRINTF(sc, "tx_bd[0x%04X]: Invalid tx_bd index!\n", idx);
   5633       1.1    bouyer 	else if ((idx & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
   5634       1.1    bouyer 		/* TX Chain page pointer. */
   5635       1.1    bouyer 		BNX_PRINTF(sc, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, chain "
   5636       1.1    bouyer 		    "page pointer\n", idx, txbd->tx_bd_haddr_hi,
   5637       1.1    bouyer 		    txbd->tx_bd_haddr_lo);
   5638       1.1    bouyer 	else
   5639       1.1    bouyer 		/* Normal tx_bd entry. */
   5640       1.1    bouyer 		BNX_PRINTF(sc, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, nbytes = "
   5641       1.4    bouyer 		    "0x%08X, vlan tag = 0x%4X, flags = 0x%08X\n", idx,
   5642       1.1    bouyer 		    txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo,
   5643       1.4    bouyer 		    txbd->tx_bd_mss_nbytes, txbd->tx_bd_vlan_tag,
   5644       1.4    bouyer 		    txbd->tx_bd_flags);
   5645       1.1    bouyer }
   5646       1.1    bouyer 
   5647       1.1    bouyer void
   5648       1.1    bouyer bnx_dump_rxbd(struct bnx_softc *sc, int idx, struct rx_bd *rxbd)
   5649       1.1    bouyer {
   5650       1.1    bouyer 	if (idx > MAX_RX_BD)
   5651       1.1    bouyer 		/* Index out of range. */
   5652       1.1    bouyer 		BNX_PRINTF(sc, "rx_bd[0x%04X]: Invalid rx_bd index!\n", idx);
   5653       1.1    bouyer 	else if ((idx & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
   5654       1.1    bouyer 		/* TX Chain page pointer. */
   5655       1.1    bouyer 		BNX_PRINTF(sc, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, chain page "
   5656       1.1    bouyer 		    "pointer\n", idx, rxbd->rx_bd_haddr_hi,
   5657       1.1    bouyer 		    rxbd->rx_bd_haddr_lo);
   5658       1.1    bouyer 	else
   5659       1.1    bouyer 		/* Normal tx_bd entry. */
   5660       1.1    bouyer 		BNX_PRINTF(sc, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, nbytes = "
   5661       1.1    bouyer 		    "0x%08X, flags = 0x%08X\n", idx,
   5662       1.1    bouyer 			rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo,
   5663       1.1    bouyer 			rxbd->rx_bd_len, rxbd->rx_bd_flags);
   5664       1.1    bouyer }
   5665       1.1    bouyer 
   5666       1.1    bouyer void
   5667       1.1    bouyer bnx_dump_l2fhdr(struct bnx_softc *sc, int idx, struct l2_fhdr *l2fhdr)
   5668       1.1    bouyer {
   5669       1.1    bouyer 	BNX_PRINTF(sc, "l2_fhdr[0x%04X]: status = 0x%08X, "
   5670       1.1    bouyer 	    "pkt_len = 0x%04X, vlan = 0x%04x, ip_xsum = 0x%04X, "
   5671       1.1    bouyer 	    "tcp_udp_xsum = 0x%04X\n", idx,
   5672       1.1    bouyer 	    l2fhdr->l2_fhdr_status, l2fhdr->l2_fhdr_pkt_len,
   5673       1.1    bouyer 	    l2fhdr->l2_fhdr_vlan_tag, l2fhdr->l2_fhdr_ip_xsum,
   5674       1.1    bouyer 	    l2fhdr->l2_fhdr_tcp_udp_xsum);
   5675       1.1    bouyer }
   5676       1.1    bouyer 
   5677       1.1    bouyer /*
   5678       1.1    bouyer  * This routine prints the TX chain.
   5679       1.1    bouyer  */
   5680       1.1    bouyer void
   5681       1.1    bouyer bnx_dump_tx_chain(struct bnx_softc *sc, int tx_prod, int count)
   5682       1.1    bouyer {
   5683       1.1    bouyer 	struct tx_bd		*txbd;
   5684       1.1    bouyer 	int			i;
   5685       1.1    bouyer 
   5686       1.1    bouyer 	/* First some info about the tx_bd chain structure. */
   5687  1.20.4.2  sborrill 	aprint_debug_dev(sc->bnx_dev,
   5688       1.1    bouyer 	    "----------------------------"
   5689       1.1    bouyer 	    "  tx_bd  chain  "
   5690       1.1    bouyer 	    "----------------------------\n");
   5691       1.1    bouyer 
   5692       1.1    bouyer 	BNX_PRINTF(sc,
   5693       1.1    bouyer 	    "page size      = 0x%08X, tx chain pages        = 0x%08X\n",
   5694       1.1    bouyer 	    (u_int32_t)BCM_PAGE_SIZE, (u_int32_t) TX_PAGES);
   5695       1.1    bouyer 
   5696       1.1    bouyer 	BNX_PRINTF(sc,
   5697       1.1    bouyer 	    "tx_bd per page = 0x%08X, usable tx_bd per page = 0x%08X\n",
   5698       1.1    bouyer 	    (u_int32_t)TOTAL_TX_BD_PER_PAGE, (u_int32_t)USABLE_TX_BD_PER_PAGE);
   5699       1.1    bouyer 
   5700  1.20.4.2  sborrill 	BNX_PRINTF(sc, "total tx_bd    = 0x%08X\n", TOTAL_TX_BD);
   5701       1.1    bouyer 
   5702  1.20.4.2  sborrill 	aprint_error_dev(sc->bnx_dev, ""
   5703       1.1    bouyer 	    "-----------------------------"
   5704       1.1    bouyer 	    "   tx_bd data   "
   5705       1.1    bouyer 	    "-----------------------------\n");
   5706       1.1    bouyer 
   5707       1.1    bouyer 	/* Now print out the tx_bd's themselves. */
   5708       1.1    bouyer 	for (i = 0; i < count; i++) {
   5709       1.1    bouyer 	 	txbd = &sc->tx_bd_chain[TX_PAGE(tx_prod)][TX_IDX(tx_prod)];
   5710       1.1    bouyer 		bnx_dump_txbd(sc, tx_prod, txbd);
   5711       1.1    bouyer 		tx_prod = TX_CHAIN_IDX(NEXT_TX_BD(tx_prod));
   5712       1.1    bouyer 	}
   5713       1.1    bouyer 
   5714  1.20.4.2  sborrill 	aprint_debug_dev(sc->bnx_dev,
   5715       1.1    bouyer 	    "-----------------------------"
   5716       1.1    bouyer 	    "--------------"
   5717       1.1    bouyer 	    "-----------------------------\n");
   5718       1.1    bouyer }
   5719       1.1    bouyer 
   5720       1.1    bouyer /*
   5721       1.1    bouyer  * This routine prints the RX chain.
   5722       1.1    bouyer  */
   5723       1.1    bouyer void
   5724       1.1    bouyer bnx_dump_rx_chain(struct bnx_softc *sc, int rx_prod, int count)
   5725       1.1    bouyer {
   5726       1.1    bouyer 	struct rx_bd		*rxbd;
   5727       1.1    bouyer 	int			i;
   5728       1.1    bouyer 
   5729       1.1    bouyer 	/* First some info about the tx_bd chain structure. */
   5730  1.20.4.2  sborrill 	aprint_debug_dev(sc->bnx_dev,
   5731       1.1    bouyer 	    "----------------------------"
   5732       1.1    bouyer 	    "  rx_bd  chain  "
   5733       1.1    bouyer 	    "----------------------------\n");
   5734       1.1    bouyer 
   5735  1.20.4.2  sborrill 	aprint_debug_dev(sc->bnx_dev, "----- RX_BD Chain -----\n");
   5736       1.1    bouyer 
   5737       1.1    bouyer 	BNX_PRINTF(sc,
   5738       1.1    bouyer 	    "page size      = 0x%08X, rx chain pages        = 0x%08X\n",
   5739       1.1    bouyer 	    (u_int32_t)BCM_PAGE_SIZE, (u_int32_t)RX_PAGES);
   5740       1.1    bouyer 
   5741       1.1    bouyer 	BNX_PRINTF(sc,
   5742       1.1    bouyer 	    "rx_bd per page = 0x%08X, usable rx_bd per page = 0x%08X\n",
   5743       1.1    bouyer 	    (u_int32_t)TOTAL_RX_BD_PER_PAGE, (u_int32_t)USABLE_RX_BD_PER_PAGE);
   5744       1.1    bouyer 
   5745  1.20.4.2  sborrill 	BNX_PRINTF(sc, "total rx_bd    = 0x%08X\n", TOTAL_RX_BD);
   5746       1.1    bouyer 
   5747  1.20.4.2  sborrill 	aprint_error_dev(sc->bnx_dev,
   5748       1.1    bouyer 	    "----------------------------"
   5749       1.1    bouyer 	    "   rx_bd data   "
   5750       1.1    bouyer 	    "----------------------------\n");
   5751       1.1    bouyer 
   5752       1.1    bouyer 	/* Now print out the rx_bd's themselves. */
   5753       1.1    bouyer 	for (i = 0; i < count; i++) {
   5754       1.1    bouyer 		rxbd = &sc->rx_bd_chain[RX_PAGE(rx_prod)][RX_IDX(rx_prod)];
   5755       1.1    bouyer 		bnx_dump_rxbd(sc, rx_prod, rxbd);
   5756       1.1    bouyer 		rx_prod = RX_CHAIN_IDX(NEXT_RX_BD(rx_prod));
   5757       1.1    bouyer 	}
   5758       1.1    bouyer 
   5759  1.20.4.2  sborrill 	aprint_debug_dev(sc->bnx_dev,
   5760       1.1    bouyer 	    "----------------------------"
   5761       1.1    bouyer 	    "--------------"
   5762       1.1    bouyer 	    "----------------------------\n");
   5763       1.1    bouyer }
   5764       1.1    bouyer 
   5765       1.1    bouyer /*
   5766       1.1    bouyer  * This routine prints the status block.
   5767       1.1    bouyer  */
   5768       1.1    bouyer void
   5769       1.1    bouyer bnx_dump_status_block(struct bnx_softc *sc)
   5770       1.1    bouyer {
   5771       1.1    bouyer 	struct status_block	*sblk;
   5772       1.1    bouyer 	bus_dmamap_sync(sc->bnx_dmatag, sc->status_map, 0, BNX_STATUS_BLK_SZ,
   5773       1.1    bouyer 	    BUS_DMASYNC_POSTREAD);
   5774       1.1    bouyer 
   5775       1.1    bouyer 	sblk = sc->status_block;
   5776       1.1    bouyer 
   5777  1.20.4.2  sborrill    	aprint_debug_dev(sc->bnx_dev, "----------------------------- Status Block "
   5778       1.1    bouyer 	    "-----------------------------\n");
   5779       1.1    bouyer 
   5780       1.1    bouyer 	BNX_PRINTF(sc,
   5781       1.1    bouyer 	    "attn_bits  = 0x%08X, attn_bits_ack = 0x%08X, index = 0x%04X\n",
   5782       1.1    bouyer 	    sblk->status_attn_bits, sblk->status_attn_bits_ack,
   5783       1.1    bouyer 	    sblk->status_idx);
   5784       1.1    bouyer 
   5785       1.1    bouyer 	BNX_PRINTF(sc, "rx_cons0   = 0x%08X, tx_cons0      = 0x%08X\n",
   5786       1.1    bouyer 	    sblk->status_rx_quick_consumer_index0,
   5787       1.1    bouyer 	    sblk->status_tx_quick_consumer_index0);
   5788       1.1    bouyer 
   5789       1.1    bouyer 	BNX_PRINTF(sc, "status_idx = 0x%04X\n", sblk->status_idx);
   5790       1.1    bouyer 
   5791       1.1    bouyer 	/* Theses indices are not used for normal L2 drivers. */
   5792       1.1    bouyer 	if (sblk->status_rx_quick_consumer_index1 ||
   5793       1.1    bouyer 		sblk->status_tx_quick_consumer_index1)
   5794       1.1    bouyer 		BNX_PRINTF(sc, "rx_cons1  = 0x%08X, tx_cons1      = 0x%08X\n",
   5795       1.1    bouyer 		    sblk->status_rx_quick_consumer_index1,
   5796       1.1    bouyer 		    sblk->status_tx_quick_consumer_index1);
   5797       1.1    bouyer 
   5798       1.1    bouyer 	if (sblk->status_rx_quick_consumer_index2 ||
   5799       1.1    bouyer 		sblk->status_tx_quick_consumer_index2)
   5800       1.1    bouyer 		BNX_PRINTF(sc, "rx_cons2  = 0x%08X, tx_cons2      = 0x%08X\n",
   5801       1.1    bouyer 		    sblk->status_rx_quick_consumer_index2,
   5802       1.1    bouyer 		    sblk->status_tx_quick_consumer_index2);
   5803       1.1    bouyer 
   5804       1.1    bouyer 	if (sblk->status_rx_quick_consumer_index3 ||
   5805       1.1    bouyer 		sblk->status_tx_quick_consumer_index3)
   5806       1.1    bouyer 		BNX_PRINTF(sc, "rx_cons3  = 0x%08X, tx_cons3      = 0x%08X\n",
   5807       1.1    bouyer 		    sblk->status_rx_quick_consumer_index3,
   5808       1.1    bouyer 		    sblk->status_tx_quick_consumer_index3);
   5809       1.1    bouyer 
   5810       1.1    bouyer 	if (sblk->status_rx_quick_consumer_index4 ||
   5811       1.1    bouyer 		sblk->status_rx_quick_consumer_index5)
   5812       1.1    bouyer 		BNX_PRINTF(sc, "rx_cons4  = 0x%08X, rx_cons5      = 0x%08X\n",
   5813       1.1    bouyer 		    sblk->status_rx_quick_consumer_index4,
   5814       1.1    bouyer 		    sblk->status_rx_quick_consumer_index5);
   5815       1.1    bouyer 
   5816       1.1    bouyer 	if (sblk->status_rx_quick_consumer_index6 ||
   5817       1.1    bouyer 		sblk->status_rx_quick_consumer_index7)
   5818       1.1    bouyer 		BNX_PRINTF(sc, "rx_cons6  = 0x%08X, rx_cons7      = 0x%08X\n",
   5819       1.1    bouyer 		    sblk->status_rx_quick_consumer_index6,
   5820       1.1    bouyer 		    sblk->status_rx_quick_consumer_index7);
   5821       1.1    bouyer 
   5822       1.1    bouyer 	if (sblk->status_rx_quick_consumer_index8 ||
   5823       1.1    bouyer 		sblk->status_rx_quick_consumer_index9)
   5824       1.1    bouyer 		BNX_PRINTF(sc, "rx_cons8  = 0x%08X, rx_cons9      = 0x%08X\n",
   5825       1.1    bouyer 		    sblk->status_rx_quick_consumer_index8,
   5826       1.1    bouyer 		    sblk->status_rx_quick_consumer_index9);
   5827       1.1    bouyer 
   5828       1.1    bouyer 	if (sblk->status_rx_quick_consumer_index10 ||
   5829       1.1    bouyer 		sblk->status_rx_quick_consumer_index11)
   5830       1.1    bouyer 		BNX_PRINTF(sc, "rx_cons10 = 0x%08X, rx_cons11     = 0x%08X\n",
   5831       1.1    bouyer 		    sblk->status_rx_quick_consumer_index10,
   5832       1.1    bouyer 		    sblk->status_rx_quick_consumer_index11);
   5833       1.1    bouyer 
   5834       1.1    bouyer 	if (sblk->status_rx_quick_consumer_index12 ||
   5835       1.1    bouyer 		sblk->status_rx_quick_consumer_index13)
   5836       1.1    bouyer 		BNX_PRINTF(sc, "rx_cons12 = 0x%08X, rx_cons13     = 0x%08X\n",
   5837       1.1    bouyer 		    sblk->status_rx_quick_consumer_index12,
   5838       1.1    bouyer 		    sblk->status_rx_quick_consumer_index13);
   5839       1.1    bouyer 
   5840       1.1    bouyer 	if (sblk->status_rx_quick_consumer_index14 ||
   5841       1.1    bouyer 		sblk->status_rx_quick_consumer_index15)
   5842       1.1    bouyer 		BNX_PRINTF(sc, "rx_cons14 = 0x%08X, rx_cons15     = 0x%08X\n",
   5843       1.1    bouyer 		    sblk->status_rx_quick_consumer_index14,
   5844       1.1    bouyer 		    sblk->status_rx_quick_consumer_index15);
   5845       1.1    bouyer 
   5846       1.1    bouyer 	if (sblk->status_completion_producer_index ||
   5847       1.1    bouyer 		sblk->status_cmd_consumer_index)
   5848       1.1    bouyer 		BNX_PRINTF(sc, "com_prod  = 0x%08X, cmd_cons      = 0x%08X\n",
   5849       1.1    bouyer 		    sblk->status_completion_producer_index,
   5850       1.1    bouyer 		    sblk->status_cmd_consumer_index);
   5851       1.1    bouyer 
   5852  1.20.4.2  sborrill 	aprint_debug_dev(sc->bnx_dev, "-------------------------------------------"
   5853       1.1    bouyer 	    "-----------------------------\n");
   5854       1.1    bouyer }
   5855       1.1    bouyer 
   5856       1.1    bouyer /*
   5857       1.1    bouyer  * This routine prints the statistics block.
   5858       1.1    bouyer  */
   5859       1.1    bouyer void
   5860       1.1    bouyer bnx_dump_stats_block(struct bnx_softc *sc)
   5861       1.1    bouyer {
   5862       1.1    bouyer 	struct statistics_block	*sblk;
   5863       1.1    bouyer 	bus_dmamap_sync(sc->bnx_dmatag, sc->status_map, 0, BNX_STATUS_BLK_SZ,
   5864       1.1    bouyer 	    BUS_DMASYNC_POSTREAD);
   5865       1.1    bouyer 
   5866       1.1    bouyer 	sblk = sc->stats_block;
   5867       1.1    bouyer 
   5868  1.20.4.2  sborrill 	aprint_debug_dev(sc->bnx_dev, ""
   5869       1.1    bouyer 	    "-----------------------------"
   5870       1.1    bouyer 	    " Stats  Block "
   5871       1.1    bouyer 	    "-----------------------------\n");
   5872       1.1    bouyer 
   5873       1.1    bouyer 	BNX_PRINTF(sc, "IfHcInOctets         = 0x%08X:%08X, "
   5874       1.1    bouyer 	    "IfHcInBadOctets      = 0x%08X:%08X\n",
   5875       1.1    bouyer 	    sblk->stat_IfHCInOctets_hi, sblk->stat_IfHCInOctets_lo,
   5876       1.1    bouyer 	    sblk->stat_IfHCInBadOctets_hi, sblk->stat_IfHCInBadOctets_lo);
   5877       1.1    bouyer 
   5878       1.1    bouyer 	BNX_PRINTF(sc, "IfHcOutOctets        = 0x%08X:%08X, "
   5879       1.1    bouyer 	    "IfHcOutBadOctets     = 0x%08X:%08X\n",
   5880       1.1    bouyer 	    sblk->stat_IfHCOutOctets_hi, sblk->stat_IfHCOutOctets_lo,
   5881       1.1    bouyer 	    sblk->stat_IfHCOutBadOctets_hi, sblk->stat_IfHCOutBadOctets_lo);
   5882       1.1    bouyer 
   5883       1.1    bouyer 	BNX_PRINTF(sc, "IfHcInUcastPkts      = 0x%08X:%08X, "
   5884       1.1    bouyer 	    "IfHcInMulticastPkts  = 0x%08X:%08X\n",
   5885       1.1    bouyer 	    sblk->stat_IfHCInUcastPkts_hi, sblk->stat_IfHCInUcastPkts_lo,
   5886       1.1    bouyer 	    sblk->stat_IfHCInMulticastPkts_hi,
   5887       1.1    bouyer 	    sblk->stat_IfHCInMulticastPkts_lo);
   5888       1.1    bouyer 
   5889       1.1    bouyer 	BNX_PRINTF(sc, "IfHcInBroadcastPkts  = 0x%08X:%08X, "
   5890       1.1    bouyer 	    "IfHcOutUcastPkts     = 0x%08X:%08X\n",
   5891       1.1    bouyer 	    sblk->stat_IfHCInBroadcastPkts_hi,
   5892       1.1    bouyer 	    sblk->stat_IfHCInBroadcastPkts_lo,
   5893       1.1    bouyer 	    sblk->stat_IfHCOutUcastPkts_hi,
   5894       1.1    bouyer 	    sblk->stat_IfHCOutUcastPkts_lo);
   5895       1.1    bouyer 
   5896       1.1    bouyer 	BNX_PRINTF(sc, "IfHcOutMulticastPkts = 0x%08X:%08X, "
   5897       1.1    bouyer 	    "IfHcOutBroadcastPkts = 0x%08X:%08X\n",
   5898       1.1    bouyer 	    sblk->stat_IfHCOutMulticastPkts_hi,
   5899       1.1    bouyer 	    sblk->stat_IfHCOutMulticastPkts_lo,
   5900       1.1    bouyer 	    sblk->stat_IfHCOutBroadcastPkts_hi,
   5901       1.1    bouyer 	    sblk->stat_IfHCOutBroadcastPkts_lo);
   5902       1.1    bouyer 
   5903       1.1    bouyer 	if (sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors)
   5904       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : "
   5905       1.1    bouyer 		    "emac_tx_stat_dot3statsinternalmactransmiterrors\n",
   5906       1.1    bouyer 		    sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors);
   5907       1.1    bouyer 
   5908       1.1    bouyer 	if (sblk->stat_Dot3StatsCarrierSenseErrors)
   5909       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : Dot3StatsCarrierSenseErrors\n",
   5910       1.1    bouyer 		    sblk->stat_Dot3StatsCarrierSenseErrors);
   5911       1.1    bouyer 
   5912       1.1    bouyer 	if (sblk->stat_Dot3StatsFCSErrors)
   5913       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : Dot3StatsFCSErrors\n",
   5914       1.1    bouyer 		    sblk->stat_Dot3StatsFCSErrors);
   5915       1.1    bouyer 
   5916       1.1    bouyer 	if (sblk->stat_Dot3StatsAlignmentErrors)
   5917       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : Dot3StatsAlignmentErrors\n",
   5918       1.1    bouyer 		    sblk->stat_Dot3StatsAlignmentErrors);
   5919       1.1    bouyer 
   5920       1.1    bouyer 	if (sblk->stat_Dot3StatsSingleCollisionFrames)
   5921       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : Dot3StatsSingleCollisionFrames\n",
   5922       1.1    bouyer 		    sblk->stat_Dot3StatsSingleCollisionFrames);
   5923       1.1    bouyer 
   5924       1.1    bouyer 	if (sblk->stat_Dot3StatsMultipleCollisionFrames)
   5925       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : Dot3StatsMultipleCollisionFrames\n",
   5926       1.1    bouyer 		    sblk->stat_Dot3StatsMultipleCollisionFrames);
   5927       1.1    bouyer 
   5928       1.1    bouyer 	if (sblk->stat_Dot3StatsDeferredTransmissions)
   5929       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : Dot3StatsDeferredTransmissions\n",
   5930       1.1    bouyer 		    sblk->stat_Dot3StatsDeferredTransmissions);
   5931       1.1    bouyer 
   5932       1.1    bouyer 	if (sblk->stat_Dot3StatsExcessiveCollisions)
   5933       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : Dot3StatsExcessiveCollisions\n",
   5934       1.1    bouyer 		    sblk->stat_Dot3StatsExcessiveCollisions);
   5935       1.1    bouyer 
   5936       1.1    bouyer 	if (sblk->stat_Dot3StatsLateCollisions)
   5937       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : Dot3StatsLateCollisions\n",
   5938       1.1    bouyer 		    sblk->stat_Dot3StatsLateCollisions);
   5939       1.1    bouyer 
   5940       1.1    bouyer 	if (sblk->stat_EtherStatsCollisions)
   5941       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : EtherStatsCollisions\n",
   5942       1.1    bouyer 		    sblk->stat_EtherStatsCollisions);
   5943       1.1    bouyer 
   5944       1.1    bouyer 	if (sblk->stat_EtherStatsFragments)
   5945       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : EtherStatsFragments\n",
   5946       1.1    bouyer 		    sblk->stat_EtherStatsFragments);
   5947       1.1    bouyer 
   5948       1.1    bouyer 	if (sblk->stat_EtherStatsJabbers)
   5949       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : EtherStatsJabbers\n",
   5950       1.1    bouyer 		    sblk->stat_EtherStatsJabbers);
   5951       1.1    bouyer 
   5952       1.1    bouyer 	if (sblk->stat_EtherStatsUndersizePkts)
   5953       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : EtherStatsUndersizePkts\n",
   5954       1.1    bouyer 		    sblk->stat_EtherStatsUndersizePkts);
   5955       1.1    bouyer 
   5956       1.1    bouyer 	if (sblk->stat_EtherStatsOverrsizePkts)
   5957       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : EtherStatsOverrsizePkts\n",
   5958       1.1    bouyer 		    sblk->stat_EtherStatsOverrsizePkts);
   5959       1.1    bouyer 
   5960       1.1    bouyer 	if (sblk->stat_EtherStatsPktsRx64Octets)
   5961       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : EtherStatsPktsRx64Octets\n",
   5962       1.1    bouyer 		    sblk->stat_EtherStatsPktsRx64Octets);
   5963       1.1    bouyer 
   5964       1.1    bouyer 	if (sblk->stat_EtherStatsPktsRx65Octetsto127Octets)
   5965       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : EtherStatsPktsRx65Octetsto127Octets\n",
   5966       1.1    bouyer 		    sblk->stat_EtherStatsPktsRx65Octetsto127Octets);
   5967       1.1    bouyer 
   5968       1.1    bouyer 	if (sblk->stat_EtherStatsPktsRx128Octetsto255Octets)
   5969       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : "
   5970       1.1    bouyer 		    "EtherStatsPktsRx128Octetsto255Octets\n",
   5971       1.1    bouyer 		    sblk->stat_EtherStatsPktsRx128Octetsto255Octets);
   5972       1.1    bouyer 
   5973       1.1    bouyer 	if (sblk->stat_EtherStatsPktsRx256Octetsto511Octets)
   5974       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : "
   5975       1.1    bouyer 		    "EtherStatsPktsRx256Octetsto511Octets\n",
   5976       1.1    bouyer 		    sblk->stat_EtherStatsPktsRx256Octetsto511Octets);
   5977       1.1    bouyer 
   5978       1.1    bouyer 	if (sblk->stat_EtherStatsPktsRx512Octetsto1023Octets)
   5979       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : "
   5980       1.1    bouyer 		    "EtherStatsPktsRx512Octetsto1023Octets\n",
   5981       1.1    bouyer 		    sblk->stat_EtherStatsPktsRx512Octetsto1023Octets);
   5982       1.1    bouyer 
   5983       1.1    bouyer 	if (sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets)
   5984       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : "
   5985       1.1    bouyer 		    "EtherStatsPktsRx1024Octetsto1522Octets\n",
   5986       1.1    bouyer 		sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets);
   5987       1.1    bouyer 
   5988       1.1    bouyer 	if (sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets)
   5989       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : "
   5990       1.1    bouyer 		    "EtherStatsPktsRx1523Octetsto9022Octets\n",
   5991       1.1    bouyer 		    sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets);
   5992       1.1    bouyer 
   5993       1.1    bouyer 	if (sblk->stat_EtherStatsPktsTx64Octets)
   5994       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : EtherStatsPktsTx64Octets\n",
   5995       1.1    bouyer 		    sblk->stat_EtherStatsPktsTx64Octets);
   5996       1.1    bouyer 
   5997       1.1    bouyer 	if (sblk->stat_EtherStatsPktsTx65Octetsto127Octets)
   5998       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : EtherStatsPktsTx65Octetsto127Octets\n",
   5999       1.1    bouyer 		    sblk->stat_EtherStatsPktsTx65Octetsto127Octets);
   6000       1.1    bouyer 
   6001       1.1    bouyer 	if (sblk->stat_EtherStatsPktsTx128Octetsto255Octets)
   6002       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : "
   6003       1.1    bouyer 		    "EtherStatsPktsTx128Octetsto255Octets\n",
   6004       1.1    bouyer 		    sblk->stat_EtherStatsPktsTx128Octetsto255Octets);
   6005       1.1    bouyer 
   6006       1.1    bouyer 	if (sblk->stat_EtherStatsPktsTx256Octetsto511Octets)
   6007       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : "
   6008       1.1    bouyer 		    "EtherStatsPktsTx256Octetsto511Octets\n",
   6009       1.1    bouyer 		    sblk->stat_EtherStatsPktsTx256Octetsto511Octets);
   6010       1.1    bouyer 
   6011       1.1    bouyer 	if (sblk->stat_EtherStatsPktsTx512Octetsto1023Octets)
   6012       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : "
   6013       1.1    bouyer 		    "EtherStatsPktsTx512Octetsto1023Octets\n",
   6014       1.1    bouyer 		    sblk->stat_EtherStatsPktsTx512Octetsto1023Octets);
   6015       1.1    bouyer 
   6016       1.1    bouyer 	if (sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets)
   6017       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : "
   6018       1.1    bouyer 		    "EtherStatsPktsTx1024Octetsto1522Octets\n",
   6019       1.1    bouyer 		    sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets);
   6020       1.1    bouyer 
   6021       1.1    bouyer 	if (sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets)
   6022       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : "
   6023       1.1    bouyer 		    "EtherStatsPktsTx1523Octetsto9022Octets\n",
   6024       1.1    bouyer 		    sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets);
   6025       1.1    bouyer 
   6026       1.1    bouyer 	if (sblk->stat_XonPauseFramesReceived)
   6027       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : XonPauseFramesReceived\n",
   6028       1.1    bouyer 		    sblk->stat_XonPauseFramesReceived);
   6029       1.1    bouyer 
   6030       1.1    bouyer 	if (sblk->stat_XoffPauseFramesReceived)
   6031       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : XoffPauseFramesReceived\n",
   6032       1.1    bouyer 		    sblk->stat_XoffPauseFramesReceived);
   6033       1.1    bouyer 
   6034       1.1    bouyer 	if (sblk->stat_OutXonSent)
   6035       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : OutXonSent\n",
   6036       1.1    bouyer 		    sblk->stat_OutXonSent);
   6037       1.1    bouyer 
   6038       1.1    bouyer 	if (sblk->stat_OutXoffSent)
   6039       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : OutXoffSent\n",
   6040       1.1    bouyer 		    sblk->stat_OutXoffSent);
   6041       1.1    bouyer 
   6042       1.1    bouyer 	if (sblk->stat_FlowControlDone)
   6043       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : FlowControlDone\n",
   6044       1.1    bouyer 		    sblk->stat_FlowControlDone);
   6045       1.1    bouyer 
   6046       1.1    bouyer 	if (sblk->stat_MacControlFramesReceived)
   6047       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : MacControlFramesReceived\n",
   6048       1.1    bouyer 		    sblk->stat_MacControlFramesReceived);
   6049       1.1    bouyer 
   6050       1.1    bouyer 	if (sblk->stat_XoffStateEntered)
   6051       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : XoffStateEntered\n",
   6052       1.1    bouyer 		    sblk->stat_XoffStateEntered);
   6053       1.1    bouyer 
   6054       1.1    bouyer 	if (sblk->stat_IfInFramesL2FilterDiscards)
   6055       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : IfInFramesL2FilterDiscards\n",
   6056       1.1    bouyer 		    sblk->stat_IfInFramesL2FilterDiscards);
   6057       1.1    bouyer 
   6058       1.1    bouyer 	if (sblk->stat_IfInRuleCheckerDiscards)
   6059       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : IfInRuleCheckerDiscards\n",
   6060       1.1    bouyer 		    sblk->stat_IfInRuleCheckerDiscards);
   6061       1.1    bouyer 
   6062       1.1    bouyer 	if (sblk->stat_IfInFTQDiscards)
   6063       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : IfInFTQDiscards\n",
   6064       1.1    bouyer 		    sblk->stat_IfInFTQDiscards);
   6065       1.1    bouyer 
   6066       1.1    bouyer 	if (sblk->stat_IfInMBUFDiscards)
   6067       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : IfInMBUFDiscards\n",
   6068       1.1    bouyer 		    sblk->stat_IfInMBUFDiscards);
   6069       1.1    bouyer 
   6070       1.1    bouyer 	if (sblk->stat_IfInRuleCheckerP4Hit)
   6071       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : IfInRuleCheckerP4Hit\n",
   6072       1.1    bouyer 		    sblk->stat_IfInRuleCheckerP4Hit);
   6073       1.1    bouyer 
   6074       1.1    bouyer 	if (sblk->stat_CatchupInRuleCheckerDiscards)
   6075       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : CatchupInRuleCheckerDiscards\n",
   6076       1.1    bouyer 		    sblk->stat_CatchupInRuleCheckerDiscards);
   6077       1.1    bouyer 
   6078       1.1    bouyer 	if (sblk->stat_CatchupInFTQDiscards)
   6079       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : CatchupInFTQDiscards\n",
   6080       1.1    bouyer 		    sblk->stat_CatchupInFTQDiscards);
   6081       1.1    bouyer 
   6082       1.1    bouyer 	if (sblk->stat_CatchupInMBUFDiscards)
   6083       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : CatchupInMBUFDiscards\n",
   6084       1.1    bouyer 		    sblk->stat_CatchupInMBUFDiscards);
   6085       1.1    bouyer 
   6086       1.1    bouyer 	if (sblk->stat_CatchupInRuleCheckerP4Hit)
   6087       1.1    bouyer 		BNX_PRINTF(sc, "0x%08X : CatchupInRuleCheckerP4Hit\n",
   6088       1.1    bouyer 		    sblk->stat_CatchupInRuleCheckerP4Hit);
   6089       1.1    bouyer 
   6090  1.20.4.2  sborrill 	aprint_debug_dev(sc->bnx_dev,
   6091       1.1    bouyer 	    "-----------------------------"
   6092       1.1    bouyer 	    "--------------"
   6093       1.1    bouyer 	    "-----------------------------\n");
   6094       1.1    bouyer }
   6095       1.1    bouyer 
   6096       1.1    bouyer void
   6097       1.1    bouyer bnx_dump_driver_state(struct bnx_softc *sc)
   6098       1.1    bouyer {
   6099  1.20.4.2  sborrill 	aprint_debug_dev(sc->bnx_dev,
   6100       1.1    bouyer 	    "-----------------------------"
   6101       1.1    bouyer 	    " Driver State "
   6102       1.1    bouyer 	    "-----------------------------\n");
   6103       1.1    bouyer 
   6104       1.1    bouyer 	BNX_PRINTF(sc, "%p - (sc) driver softc structure virtual "
   6105       1.1    bouyer 	    "address\n", sc);
   6106       1.1    bouyer 
   6107       1.1    bouyer 	BNX_PRINTF(sc, "%p - (sc->status_block) status block virtual address\n",
   6108       1.1    bouyer 	    sc->status_block);
   6109       1.1    bouyer 
   6110       1.1    bouyer 	BNX_PRINTF(sc, "%p - (sc->stats_block) statistics block virtual "
   6111       1.1    bouyer 	    "address\n", sc->stats_block);
   6112       1.1    bouyer 
   6113       1.1    bouyer 	BNX_PRINTF(sc, "%p - (sc->tx_bd_chain) tx_bd chain virtual "
   6114       1.1    bouyer 	    "adddress\n", sc->tx_bd_chain);
   6115       1.1    bouyer 
   6116  1.20.4.2  sborrill #if 0
   6117       1.1    bouyer 	BNX_PRINTF(sc, "%p - (sc->rx_bd_chain) rx_bd chain virtual address\n",
   6118       1.1    bouyer 	    sc->rx_bd_chain);
   6119       1.1    bouyer 
   6120       1.1    bouyer 	BNX_PRINTF(sc, "%p - (sc->tx_mbuf_ptr) tx mbuf chain virtual address\n",
   6121       1.1    bouyer 	    sc->tx_mbuf_ptr);
   6122  1.20.4.2  sborrill #endif
   6123       1.1    bouyer 
   6124       1.1    bouyer 	BNX_PRINTF(sc, "%p - (sc->rx_mbuf_ptr) rx mbuf chain virtual address\n",
   6125       1.1    bouyer 	    sc->rx_mbuf_ptr);
   6126       1.1    bouyer 
   6127       1.1    bouyer 	BNX_PRINTF(sc,
   6128       1.1    bouyer 	    "         0x%08X - (sc->interrupts_generated) h/w intrs\n",
   6129       1.1    bouyer 	    sc->interrupts_generated);
   6130       1.1    bouyer 
   6131       1.1    bouyer 	BNX_PRINTF(sc,
   6132       1.1    bouyer 	    "         0x%08X - (sc->rx_interrupts) rx interrupts handled\n",
   6133       1.1    bouyer 	    sc->rx_interrupts);
   6134       1.1    bouyer 
   6135       1.1    bouyer 	BNX_PRINTF(sc,
   6136       1.1    bouyer 	    "         0x%08X - (sc->tx_interrupts) tx interrupts handled\n",
   6137       1.1    bouyer 	    sc->tx_interrupts);
   6138       1.1    bouyer 
   6139       1.1    bouyer 	BNX_PRINTF(sc,
   6140       1.1    bouyer 	    "         0x%08X - (sc->last_status_idx) status block index\n",
   6141       1.1    bouyer 	    sc->last_status_idx);
   6142       1.1    bouyer 
   6143       1.1    bouyer 	BNX_PRINTF(sc, "         0x%08X - (sc->tx_prod) tx producer index\n",
   6144       1.1    bouyer 	    sc->tx_prod);
   6145       1.1    bouyer 
   6146       1.1    bouyer 	BNX_PRINTF(sc, "         0x%08X - (sc->tx_cons) tx consumer index\n",
   6147       1.1    bouyer 	    sc->tx_cons);
   6148       1.1    bouyer 
   6149       1.1    bouyer 	BNX_PRINTF(sc,
   6150       1.1    bouyer 	    "         0x%08X - (sc->tx_prod_bseq) tx producer bseq index\n",
   6151       1.1    bouyer 	    sc->tx_prod_bseq);
   6152  1.20.4.2  sborrill 	BNX_PRINTF(sc,
   6153  1.20.4.2  sborrill 	    "	 0x%08X - (sc->tx_mbuf_alloc) tx mbufs allocated\n",
   6154  1.20.4.2  sborrill 	    sc->tx_mbuf_alloc);
   6155  1.20.4.2  sborrill 
   6156  1.20.4.2  sborrill 	BNX_PRINTF(sc,
   6157  1.20.4.2  sborrill 	    "	 0x%08X - (sc->used_tx_bd) used tx_bd's\n",
   6158  1.20.4.2  sborrill 	    sc->used_tx_bd);
   6159  1.20.4.2  sborrill 
   6160  1.20.4.2  sborrill 	BNX_PRINTF(sc,
   6161  1.20.4.2  sborrill 	    "	 0x%08X/%08X - (sc->tx_hi_watermark) tx hi watermark\n",
   6162  1.20.4.2  sborrill 	    sc->tx_hi_watermark, sc->max_tx_bd);
   6163  1.20.4.2  sborrill 
   6164       1.1    bouyer 
   6165       1.1    bouyer 	BNX_PRINTF(sc, "         0x%08X - (sc->rx_prod) rx producer index\n",
   6166       1.1    bouyer 	    sc->rx_prod);
   6167       1.1    bouyer 
   6168       1.1    bouyer 	BNX_PRINTF(sc, "         0x%08X - (sc->rx_cons) rx consumer index\n",
   6169       1.1    bouyer 	    sc->rx_cons);
   6170       1.1    bouyer 
   6171       1.1    bouyer 	BNX_PRINTF(sc,
   6172       1.1    bouyer 	    "         0x%08X - (sc->rx_prod_bseq) rx producer bseq index\n",
   6173       1.1    bouyer 	    sc->rx_prod_bseq);
   6174       1.1    bouyer 
   6175       1.1    bouyer 	BNX_PRINTF(sc,
   6176       1.1    bouyer 	    "         0x%08X - (sc->rx_mbuf_alloc) rx mbufs allocated\n",
   6177       1.1    bouyer 	    sc->rx_mbuf_alloc);
   6178       1.1    bouyer 
   6179       1.1    bouyer 	BNX_PRINTF(sc, "         0x%08X - (sc->free_rx_bd) free rx_bd's\n",
   6180       1.1    bouyer 	    sc->free_rx_bd);
   6181       1.1    bouyer 
   6182       1.1    bouyer 	BNX_PRINTF(sc,
   6183       1.1    bouyer 	    "0x%08X/%08X - (sc->rx_low_watermark) rx low watermark\n",
   6184  1.20.4.2  sborrill 	    sc->rx_low_watermark, sc->max_rx_bd);
   6185       1.1    bouyer 
   6186       1.1    bouyer 	BNX_PRINTF(sc,
   6187  1.20.4.2  sborrill 	    "         0x%08X - (sc->mbuf_alloc_failed) "
   6188  1.20.4.2  sborrill 	    "mbuf alloc failures\n",
   6189  1.20.4.2  sborrill 	    sc->mbuf_alloc_failed);
   6190       1.1    bouyer 
   6191       1.1    bouyer 	BNX_PRINTF(sc,
   6192  1.20.4.2  sborrill 	    "         0x%0X - (sc->mbuf_sim_allocated_failed) "
   6193  1.20.4.2  sborrill 	    "simulated mbuf alloc failures\n",
   6194  1.20.4.2  sborrill 	    sc->mbuf_sim_alloc_failed);
   6195       1.1    bouyer 
   6196  1.20.4.2  sborrill 	aprint_debug_dev(sc->bnx_dev, "-------------------------------------------"
   6197       1.1    bouyer 	    "-----------------------------\n");
   6198       1.1    bouyer }
   6199       1.1    bouyer 
   6200       1.1    bouyer void
   6201       1.1    bouyer bnx_dump_hw_state(struct bnx_softc *sc)
   6202       1.1    bouyer {
   6203       1.1    bouyer 	u_int32_t		val1;
   6204       1.1    bouyer 	int			i;
   6205       1.1    bouyer 
   6206  1.20.4.2  sborrill 	aprint_debug_dev(sc->bnx_dev,
   6207       1.1    bouyer 	    "----------------------------"
   6208       1.1    bouyer 	    " Hardware State "
   6209       1.1    bouyer 	    "----------------------------\n");
   6210       1.1    bouyer 
   6211       1.1    bouyer 	BNX_PRINTF(sc, "0x%08X : bootcode version\n", sc->bnx_fw_ver);
   6212       1.1    bouyer 
   6213       1.1    bouyer 	val1 = REG_RD(sc, BNX_MISC_ENABLE_STATUS_BITS);
   6214       1.1    bouyer 	BNX_PRINTF(sc, "0x%08X : (0x%04X) misc_enable_status_bits\n",
   6215       1.1    bouyer 	    val1, BNX_MISC_ENABLE_STATUS_BITS);
   6216       1.1    bouyer 
   6217       1.1    bouyer 	val1 = REG_RD(sc, BNX_DMA_STATUS);
   6218       1.1    bouyer 	BNX_PRINTF(sc, "0x%08X : (0x%04X) dma_status\n", val1, BNX_DMA_STATUS);
   6219       1.1    bouyer 
   6220       1.1    bouyer 	val1 = REG_RD(sc, BNX_CTX_STATUS);
   6221       1.1    bouyer 	BNX_PRINTF(sc, "0x%08X : (0x%04X) ctx_status\n", val1, BNX_CTX_STATUS);
   6222       1.1    bouyer 
   6223       1.1    bouyer 	val1 = REG_RD(sc, BNX_EMAC_STATUS);
   6224       1.1    bouyer 	BNX_PRINTF(sc, "0x%08X : (0x%04X) emac_status\n", val1,
   6225       1.1    bouyer 	    BNX_EMAC_STATUS);
   6226       1.1    bouyer 
   6227       1.1    bouyer 	val1 = REG_RD(sc, BNX_RPM_STATUS);
   6228       1.1    bouyer 	BNX_PRINTF(sc, "0x%08X : (0x%04X) rpm_status\n", val1, BNX_RPM_STATUS);
   6229       1.1    bouyer 
   6230       1.1    bouyer 	val1 = REG_RD(sc, BNX_TBDR_STATUS);
   6231       1.1    bouyer 	BNX_PRINTF(sc, "0x%08X : (0x%04X) tbdr_status\n", val1,
   6232       1.1    bouyer 	    BNX_TBDR_STATUS);
   6233       1.1    bouyer 
   6234       1.1    bouyer 	val1 = REG_RD(sc, BNX_TDMA_STATUS);
   6235       1.1    bouyer 	BNX_PRINTF(sc, "0x%08X : (0x%04X) tdma_status\n", val1,
   6236       1.1    bouyer 	    BNX_TDMA_STATUS);
   6237       1.1    bouyer 
   6238       1.1    bouyer 	val1 = REG_RD(sc, BNX_HC_STATUS);
   6239       1.1    bouyer 	BNX_PRINTF(sc, "0x%08X : (0x%04X) hc_status\n", val1, BNX_HC_STATUS);
   6240       1.1    bouyer 
   6241  1.20.4.2  sborrill 	aprint_debug_dev(sc->bnx_dev,
   6242       1.1    bouyer 	    "----------------------------"
   6243       1.1    bouyer 	    "----------------"
   6244       1.1    bouyer 	    "----------------------------\n");
   6245       1.1    bouyer 
   6246  1.20.4.2  sborrill 	aprint_debug_dev(sc->bnx_dev,
   6247       1.1    bouyer 	    "----------------------------"
   6248       1.1    bouyer 	    " Register  Dump "
   6249       1.1    bouyer 	    "----------------------------\n");
   6250       1.1    bouyer 
   6251       1.1    bouyer 	for (i = 0x400; i < 0x8000; i += 0x10)
   6252       1.1    bouyer 		BNX_PRINTF(sc, "0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n",
   6253       1.1    bouyer 		    i, REG_RD(sc, i), REG_RD(sc, i + 0x4),
   6254       1.1    bouyer 		    REG_RD(sc, i + 0x8), REG_RD(sc, i + 0xC));
   6255       1.1    bouyer 
   6256  1.20.4.2  sborrill 	aprint_debug_dev(sc->bnx_dev,
   6257       1.1    bouyer 	    "----------------------------"
   6258       1.1    bouyer 	    "----------------"
   6259       1.1    bouyer 	    "----------------------------\n");
   6260       1.1    bouyer }
   6261       1.1    bouyer 
   6262       1.1    bouyer void
   6263       1.1    bouyer bnx_breakpoint(struct bnx_softc *sc)
   6264       1.1    bouyer {
   6265       1.1    bouyer 	/* Unreachable code to shut the compiler up about unused functions. */
   6266       1.1    bouyer 	if (0) {
   6267       1.1    bouyer    		bnx_dump_txbd(sc, 0, NULL);
   6268       1.1    bouyer 		bnx_dump_rxbd(sc, 0, NULL);
   6269       1.1    bouyer 		bnx_dump_tx_mbuf_chain(sc, 0, USABLE_TX_BD);
   6270  1.20.4.2  sborrill 		bnx_dump_rx_mbuf_chain(sc, 0, sc->max_rx_bd);
   6271       1.1    bouyer 		bnx_dump_l2fhdr(sc, 0, NULL);
   6272       1.1    bouyer 		bnx_dump_tx_chain(sc, 0, USABLE_TX_BD);
   6273  1.20.4.2  sborrill 		bnx_dump_rx_chain(sc, 0, sc->max_rx_bd);
   6274       1.1    bouyer 		bnx_dump_status_block(sc);
   6275       1.1    bouyer 		bnx_dump_stats_block(sc);
   6276       1.1    bouyer 		bnx_dump_driver_state(sc);
   6277       1.1    bouyer 		bnx_dump_hw_state(sc);
   6278       1.1    bouyer 	}
   6279       1.1    bouyer 
   6280       1.1    bouyer 	bnx_dump_driver_state(sc);
   6281       1.1    bouyer 	/* Print the important status block fields. */
   6282       1.1    bouyer 	bnx_dump_status_block(sc);
   6283       1.1    bouyer 
   6284       1.1    bouyer #if 0
   6285       1.1    bouyer 	/* Call the debugger. */
   6286       1.1    bouyer 	breakpoint();
   6287       1.1    bouyer #endif
   6288       1.1    bouyer 
   6289       1.1    bouyer 	return;
   6290       1.1    bouyer }
   6291       1.1    bouyer #endif
   6292