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