2 * Copyright (c) 2007-2014 QLogic Corporation. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #define BXE_DRIVER_VERSION "1.78.81"
34 #include "ecore_init.h"
35 #include "ecore_init_ops.h"
37 #include "57710_int_offsets.h"
38 #include "57711_int_offsets.h"
39 #include "57712_int_offsets.h"
42 * CTLTYPE_U64 and sysctl_handle_64 were added in r217616. Define these
43 * explicitly here for older kernels that don't include this changeset.
46 #define CTLTYPE_U64 CTLTYPE_QUAD
47 #define sysctl_handle_64 sysctl_handle_quad
51 * CSUM_TCP_IPV6 and CSUM_UDP_IPV6 were added in r236170. Define these
52 * here as zero(0) for older kernels that don't include this changeset
53 * thereby masking the functionality.
56 #define CSUM_TCP_IPV6 0
57 #define CSUM_UDP_IPV6 0
61 * pci_find_cap was added in r219865. Re-define this at pci_find_extcap
62 * for older kernels that don't include this changeset.
64 #if __FreeBSD_version < 900035
65 #define pci_find_cap pci_find_extcap
68 #define BXE_DEF_SB_ATT_IDX 0x0001
69 #define BXE_DEF_SB_IDX 0x0002
72 * FLR Support - bxe_pf_flr_clnup() is called during nic_load in the per
73 * function HW initialization.
75 #define FLR_WAIT_USEC 10000 /* 10 msecs */
76 #define FLR_WAIT_INTERVAL 50 /* usecs */
77 #define FLR_POLL_CNT (FLR_WAIT_USEC / FLR_WAIT_INTERVAL) /* 200 */
79 struct pbf_pN_buf_regs {
86 struct pbf_pN_cmd_regs {
93 * PCI Device ID Table used by bxe_probe().
95 #define BXE_DEVDESC_MAX 64
96 static struct bxe_device_type bxe_devs[] = {
100 PCI_ANY_ID, PCI_ANY_ID,
101 "QLogic NetXtreme II BCM57710 10GbE"
106 PCI_ANY_ID, PCI_ANY_ID,
107 "QLogic NetXtreme II BCM57711 10GbE"
112 PCI_ANY_ID, PCI_ANY_ID,
113 "QLogic NetXtreme II BCM57711E 10GbE"
118 PCI_ANY_ID, PCI_ANY_ID,
119 "QLogic NetXtreme II BCM57712 10GbE"
124 PCI_ANY_ID, PCI_ANY_ID,
125 "QLogic NetXtreme II BCM57712 MF 10GbE"
130 PCI_ANY_ID, PCI_ANY_ID,
131 "QLogic NetXtreme II BCM57800 10GbE"
136 PCI_ANY_ID, PCI_ANY_ID,
137 "QLogic NetXtreme II BCM57800 MF 10GbE"
142 PCI_ANY_ID, PCI_ANY_ID,
143 "QLogic NetXtreme II BCM57810 10GbE"
148 PCI_ANY_ID, PCI_ANY_ID,
149 "QLogic NetXtreme II BCM57810 MF 10GbE"
154 PCI_ANY_ID, PCI_ANY_ID,
155 "QLogic NetXtreme II BCM57811 10GbE"
160 PCI_ANY_ID, PCI_ANY_ID,
161 "QLogic NetXtreme II BCM57811 MF 10GbE"
166 PCI_ANY_ID, PCI_ANY_ID,
167 "QLogic NetXtreme II BCM57840 4x10GbE"
172 PCI_ANY_ID, PCI_ANY_ID,
173 "QLogic NetXtreme II BCM57840 MF 10GbE"
180 MALLOC_DECLARE(M_BXE_ILT);
181 MALLOC_DEFINE(M_BXE_ILT, "bxe_ilt", "bxe ILT pointer");
184 * FreeBSD device entry points.
186 static int bxe_probe(device_t);
187 static int bxe_attach(device_t);
188 static int bxe_detach(device_t);
189 static int bxe_shutdown(device_t);
192 * FreeBSD KLD module/device interface event handler method.
194 static device_method_t bxe_methods[] = {
195 /* Device interface (device_if.h) */
196 DEVMETHOD(device_probe, bxe_probe),
197 DEVMETHOD(device_attach, bxe_attach),
198 DEVMETHOD(device_detach, bxe_detach),
199 DEVMETHOD(device_shutdown, bxe_shutdown),
200 /* Bus interface (bus_if.h) */
201 DEVMETHOD(bus_print_child, bus_generic_print_child),
202 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
207 * FreeBSD KLD Module data declaration
209 static driver_t bxe_driver = {
210 "bxe", /* module name */
211 bxe_methods, /* event handler */
212 sizeof(struct bxe_softc) /* extra data */
216 * FreeBSD dev class is needed to manage dev instances and
217 * to associate with a bus type
219 static devclass_t bxe_devclass;
221 MODULE_DEPEND(bxe, pci, 1, 1, 1);
222 MODULE_DEPEND(bxe, ether, 1, 1, 1);
223 DRIVER_MODULE(bxe, pci, bxe_driver, bxe_devclass, 0, 0);
225 /* resources needed for unloading a previously loaded device */
227 #define BXE_PREV_WAIT_NEEDED 1
228 struct mtx bxe_prev_mtx;
229 MTX_SYSINIT(bxe_prev_mtx, &bxe_prev_mtx, "bxe_prev_lock", MTX_DEF);
230 struct bxe_prev_list_node {
231 LIST_ENTRY(bxe_prev_list_node) node;
235 uint8_t aer; /* XXX automatic error recovery */
238 static LIST_HEAD(, bxe_prev_list_node) bxe_prev_list = LIST_HEAD_INITIALIZER(bxe_prev_list);
240 static int load_count[2][3] = { {0} }; /* per-path: 0-common, 1-port0, 2-port1 */
242 /* Tunable device values... */
244 SYSCTL_NODE(_hw, OID_AUTO, bxe, CTLFLAG_RD, 0, "bxe driver parameters");
247 unsigned long bxe_debug = 0;
248 TUNABLE_ULONG("hw.bxe.debug", &bxe_debug);
249 SYSCTL_ULONG(_hw_bxe, OID_AUTO, debug, (CTLFLAG_RDTUN),
250 &bxe_debug, 0, "Debug logging mode");
252 /* Interrupt Mode: 0 (IRQ), 1 (MSI/IRQ), and 2 (MSI-X/MSI/IRQ) */
253 static int bxe_interrupt_mode = INTR_MODE_MSIX;
254 TUNABLE_INT("hw.bxe.interrupt_mode", &bxe_interrupt_mode);
255 SYSCTL_INT(_hw_bxe, OID_AUTO, interrupt_mode, CTLFLAG_RDTUN,
256 &bxe_interrupt_mode, 0, "Interrupt (MSI-X/MSI/INTx) mode");
258 /* Number of Queues: 0 (Auto) or 1 to 16 (fixed queue number) */
259 static int bxe_queue_count = 4;
260 TUNABLE_INT("hw.bxe.queue_count", &bxe_queue_count);
261 SYSCTL_INT(_hw_bxe, OID_AUTO, queue_count, CTLFLAG_RDTUN,
262 &bxe_queue_count, 0, "Multi-Queue queue count");
264 /* max number of buffers per queue (default RX_BD_USABLE) */
265 static int bxe_max_rx_bufs = 0;
266 TUNABLE_INT("hw.bxe.max_rx_bufs", &bxe_max_rx_bufs);
267 SYSCTL_INT(_hw_bxe, OID_AUTO, max_rx_bufs, CTLFLAG_RDTUN,
268 &bxe_max_rx_bufs, 0, "Maximum Number of Rx Buffers Per Queue");
270 /* Host interrupt coalescing RX tick timer (usecs) */
271 static int bxe_hc_rx_ticks = 25;
272 TUNABLE_INT("hw.bxe.hc_rx_ticks", &bxe_hc_rx_ticks);
273 SYSCTL_INT(_hw_bxe, OID_AUTO, hc_rx_ticks, CTLFLAG_RDTUN,
274 &bxe_hc_rx_ticks, 0, "Host Coalescing Rx ticks");
276 /* Host interrupt coalescing TX tick timer (usecs) */
277 static int bxe_hc_tx_ticks = 50;
278 TUNABLE_INT("hw.bxe.hc_tx_ticks", &bxe_hc_tx_ticks);
279 SYSCTL_INT(_hw_bxe, OID_AUTO, hc_tx_ticks, CTLFLAG_RDTUN,
280 &bxe_hc_tx_ticks, 0, "Host Coalescing Tx ticks");
282 /* Maximum number of Rx packets to process at a time */
283 static int bxe_rx_budget = 0xffffffff;
284 TUNABLE_INT("hw.bxe.rx_budget", &bxe_rx_budget);
285 SYSCTL_INT(_hw_bxe, OID_AUTO, rx_budget, CTLFLAG_TUN,
286 &bxe_rx_budget, 0, "Rx processing budget");
288 /* Maximum LRO aggregation size */
289 static int bxe_max_aggregation_size = 0;
290 TUNABLE_INT("hw.bxe.max_aggregation_size", &bxe_max_aggregation_size);
291 SYSCTL_INT(_hw_bxe, OID_AUTO, max_aggregation_size, CTLFLAG_TUN,
292 &bxe_max_aggregation_size, 0, "max aggregation size");
294 /* PCI MRRS: -1 (Auto), 0 (128B), 1 (256B), 2 (512B), 3 (1KB) */
295 static int bxe_mrrs = -1;
296 TUNABLE_INT("hw.bxe.mrrs", &bxe_mrrs);
297 SYSCTL_INT(_hw_bxe, OID_AUTO, mrrs, CTLFLAG_RDTUN,
298 &bxe_mrrs, 0, "PCIe maximum read request size");
300 /* AutoGrEEEn: 0 (hardware default), 1 (force on), 2 (force off) */
301 static int bxe_autogreeen = 0;
302 TUNABLE_INT("hw.bxe.autogreeen", &bxe_autogreeen);
303 SYSCTL_INT(_hw_bxe, OID_AUTO, autogreeen, CTLFLAG_RDTUN,
304 &bxe_autogreeen, 0, "AutoGrEEEn support");
306 /* 4-tuple RSS support for UDP: 0 (disabled), 1 (enabled) */
307 static int bxe_udp_rss = 0;
308 TUNABLE_INT("hw.bxe.udp_rss", &bxe_udp_rss);
309 SYSCTL_INT(_hw_bxe, OID_AUTO, udp_rss, CTLFLAG_RDTUN,
310 &bxe_udp_rss, 0, "UDP RSS support");
313 #define STAT_NAME_LEN 32 /* no stat names below can be longer than this */
315 #define STATS_OFFSET32(stat_name) \
316 (offsetof(struct bxe_eth_stats, stat_name) / 4)
318 #define Q_STATS_OFFSET32(stat_name) \
319 (offsetof(struct bxe_eth_q_stats, stat_name) / 4)
321 static const struct {
325 #define STATS_FLAGS_PORT 1
326 #define STATS_FLAGS_FUNC 2 /* MF only cares about function stats */
327 #define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
328 char string[STAT_NAME_LEN];
329 } bxe_eth_stats_arr[] = {
330 { STATS_OFFSET32(total_bytes_received_hi),
331 8, STATS_FLAGS_BOTH, "rx_bytes" },
332 { STATS_OFFSET32(error_bytes_received_hi),
333 8, STATS_FLAGS_BOTH, "rx_error_bytes" },
334 { STATS_OFFSET32(total_unicast_packets_received_hi),
335 8, STATS_FLAGS_BOTH, "rx_ucast_packets" },
336 { STATS_OFFSET32(total_multicast_packets_received_hi),
337 8, STATS_FLAGS_BOTH, "rx_mcast_packets" },
338 { STATS_OFFSET32(total_broadcast_packets_received_hi),
339 8, STATS_FLAGS_BOTH, "rx_bcast_packets" },
340 { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
341 8, STATS_FLAGS_PORT, "rx_crc_errors" },
342 { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
343 8, STATS_FLAGS_PORT, "rx_align_errors" },
344 { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
345 8, STATS_FLAGS_PORT, "rx_undersize_packets" },
346 { STATS_OFFSET32(etherstatsoverrsizepkts_hi),
347 8, STATS_FLAGS_PORT, "rx_oversize_packets" },
348 { STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
349 8, STATS_FLAGS_PORT, "rx_fragments" },
350 { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
351 8, STATS_FLAGS_PORT, "rx_jabbers" },
352 { STATS_OFFSET32(no_buff_discard_hi),
353 8, STATS_FLAGS_BOTH, "rx_discards" },
354 { STATS_OFFSET32(mac_filter_discard),
355 4, STATS_FLAGS_PORT, "rx_filtered_packets" },
356 { STATS_OFFSET32(mf_tag_discard),
357 4, STATS_FLAGS_PORT, "rx_mf_tag_discard" },
358 { STATS_OFFSET32(pfc_frames_received_hi),
359 8, STATS_FLAGS_PORT, "pfc_frames_received" },
360 { STATS_OFFSET32(pfc_frames_sent_hi),
361 8, STATS_FLAGS_PORT, "pfc_frames_sent" },
362 { STATS_OFFSET32(brb_drop_hi),
363 8, STATS_FLAGS_PORT, "rx_brb_discard" },
364 { STATS_OFFSET32(brb_truncate_hi),
365 8, STATS_FLAGS_PORT, "rx_brb_truncate" },
366 { STATS_OFFSET32(pause_frames_received_hi),
367 8, STATS_FLAGS_PORT, "rx_pause_frames" },
368 { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
369 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" },
370 { STATS_OFFSET32(nig_timer_max),
371 4, STATS_FLAGS_PORT, "rx_constant_pause_events" },
372 { STATS_OFFSET32(total_bytes_transmitted_hi),
373 8, STATS_FLAGS_BOTH, "tx_bytes" },
374 { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
375 8, STATS_FLAGS_PORT, "tx_error_bytes" },
376 { STATS_OFFSET32(total_unicast_packets_transmitted_hi),
377 8, STATS_FLAGS_BOTH, "tx_ucast_packets" },
378 { STATS_OFFSET32(total_multicast_packets_transmitted_hi),
379 8, STATS_FLAGS_BOTH, "tx_mcast_packets" },
380 { STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
381 8, STATS_FLAGS_BOTH, "tx_bcast_packets" },
382 { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
383 8, STATS_FLAGS_PORT, "tx_mac_errors" },
384 { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
385 8, STATS_FLAGS_PORT, "tx_carrier_errors" },
386 { STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
387 8, STATS_FLAGS_PORT, "tx_single_collisions" },
388 { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
389 8, STATS_FLAGS_PORT, "tx_multi_collisions" },
390 { STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
391 8, STATS_FLAGS_PORT, "tx_deferred" },
392 { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
393 8, STATS_FLAGS_PORT, "tx_excess_collisions" },
394 { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
395 8, STATS_FLAGS_PORT, "tx_late_collisions" },
396 { STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
397 8, STATS_FLAGS_PORT, "tx_total_collisions" },
398 { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
399 8, STATS_FLAGS_PORT, "tx_64_byte_packets" },
400 { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
401 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" },
402 { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
403 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" },
404 { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
405 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" },
406 { STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
407 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" },
408 { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
409 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" },
410 { STATS_OFFSET32(etherstatspktsover1522octets_hi),
411 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" },
412 { STATS_OFFSET32(pause_frames_sent_hi),
413 8, STATS_FLAGS_PORT, "tx_pause_frames" },
414 { STATS_OFFSET32(total_tpa_aggregations_hi),
415 8, STATS_FLAGS_FUNC, "tpa_aggregations" },
416 { STATS_OFFSET32(total_tpa_aggregated_frames_hi),
417 8, STATS_FLAGS_FUNC, "tpa_aggregated_frames"},
418 { STATS_OFFSET32(total_tpa_bytes_hi),
419 8, STATS_FLAGS_FUNC, "tpa_bytes"},
420 { STATS_OFFSET32(eee_tx_lpi),
421 4, STATS_FLAGS_PORT, "eee_tx_lpi"},
422 { STATS_OFFSET32(rx_calls),
423 4, STATS_FLAGS_FUNC, "rx_calls"},
424 { STATS_OFFSET32(rx_pkts),
425 4, STATS_FLAGS_FUNC, "rx_pkts"},
426 { STATS_OFFSET32(rx_tpa_pkts),
427 4, STATS_FLAGS_FUNC, "rx_tpa_pkts"},
428 { STATS_OFFSET32(rx_erroneous_jumbo_sge_pkts),
429 4, STATS_FLAGS_FUNC, "rx_erroneous_jumbo_sge_pkts"},
430 { STATS_OFFSET32(rx_bxe_service_rxsgl),
431 4, STATS_FLAGS_FUNC, "rx_bxe_service_rxsgl"},
432 { STATS_OFFSET32(rx_jumbo_sge_pkts),
433 4, STATS_FLAGS_FUNC, "rx_jumbo_sge_pkts"},
434 { STATS_OFFSET32(rx_soft_errors),
435 4, STATS_FLAGS_FUNC, "rx_soft_errors"},
436 { STATS_OFFSET32(rx_hw_csum_errors),
437 4, STATS_FLAGS_FUNC, "rx_hw_csum_errors"},
438 { STATS_OFFSET32(rx_ofld_frames_csum_ip),
439 4, STATS_FLAGS_FUNC, "rx_ofld_frames_csum_ip"},
440 { STATS_OFFSET32(rx_ofld_frames_csum_tcp_udp),
441 4, STATS_FLAGS_FUNC, "rx_ofld_frames_csum_tcp_udp"},
442 { STATS_OFFSET32(rx_budget_reached),
443 4, STATS_FLAGS_FUNC, "rx_budget_reached"},
444 { STATS_OFFSET32(tx_pkts),
445 4, STATS_FLAGS_FUNC, "tx_pkts"},
446 { STATS_OFFSET32(tx_soft_errors),
447 4, STATS_FLAGS_FUNC, "tx_soft_errors"},
448 { STATS_OFFSET32(tx_ofld_frames_csum_ip),
449 4, STATS_FLAGS_FUNC, "tx_ofld_frames_csum_ip"},
450 { STATS_OFFSET32(tx_ofld_frames_csum_tcp),
451 4, STATS_FLAGS_FUNC, "tx_ofld_frames_csum_tcp"},
452 { STATS_OFFSET32(tx_ofld_frames_csum_udp),
453 4, STATS_FLAGS_FUNC, "tx_ofld_frames_csum_udp"},
454 { STATS_OFFSET32(tx_ofld_frames_lso),
455 4, STATS_FLAGS_FUNC, "tx_ofld_frames_lso"},
456 { STATS_OFFSET32(tx_ofld_frames_lso_hdr_splits),
457 4, STATS_FLAGS_FUNC, "tx_ofld_frames_lso_hdr_splits"},
458 { STATS_OFFSET32(tx_encap_failures),
459 4, STATS_FLAGS_FUNC, "tx_encap_failures"},
460 { STATS_OFFSET32(tx_hw_queue_full),
461 4, STATS_FLAGS_FUNC, "tx_hw_queue_full"},
462 { STATS_OFFSET32(tx_hw_max_queue_depth),
463 4, STATS_FLAGS_FUNC, "tx_hw_max_queue_depth"},
464 { STATS_OFFSET32(tx_dma_mapping_failure),
465 4, STATS_FLAGS_FUNC, "tx_dma_mapping_failure"},
466 { STATS_OFFSET32(tx_max_drbr_queue_depth),
467 4, STATS_FLAGS_FUNC, "tx_max_drbr_queue_depth"},
468 { STATS_OFFSET32(tx_window_violation_std),
469 4, STATS_FLAGS_FUNC, "tx_window_violation_std"},
470 { STATS_OFFSET32(tx_window_violation_tso),
471 4, STATS_FLAGS_FUNC, "tx_window_violation_tso"},
472 { STATS_OFFSET32(tx_chain_lost_mbuf),
473 4, STATS_FLAGS_FUNC, "tx_chain_lost_mbuf"},
474 { STATS_OFFSET32(tx_frames_deferred),
475 4, STATS_FLAGS_FUNC, "tx_frames_deferred"},
476 { STATS_OFFSET32(tx_queue_xoff),
477 4, STATS_FLAGS_FUNC, "tx_queue_xoff"},
478 { STATS_OFFSET32(mbuf_defrag_attempts),
479 4, STATS_FLAGS_FUNC, "mbuf_defrag_attempts"},
480 { STATS_OFFSET32(mbuf_defrag_failures),
481 4, STATS_FLAGS_FUNC, "mbuf_defrag_failures"},
482 { STATS_OFFSET32(mbuf_rx_bd_alloc_failed),
483 4, STATS_FLAGS_FUNC, "mbuf_rx_bd_alloc_failed"},
484 { STATS_OFFSET32(mbuf_rx_bd_mapping_failed),
485 4, STATS_FLAGS_FUNC, "mbuf_rx_bd_mapping_failed"},
486 { STATS_OFFSET32(mbuf_rx_tpa_alloc_failed),
487 4, STATS_FLAGS_FUNC, "mbuf_rx_tpa_alloc_failed"},
488 { STATS_OFFSET32(mbuf_rx_tpa_mapping_failed),
489 4, STATS_FLAGS_FUNC, "mbuf_rx_tpa_mapping_failed"},
490 { STATS_OFFSET32(mbuf_rx_sge_alloc_failed),
491 4, STATS_FLAGS_FUNC, "mbuf_rx_sge_alloc_failed"},
492 { STATS_OFFSET32(mbuf_rx_sge_mapping_failed),
493 4, STATS_FLAGS_FUNC, "mbuf_rx_sge_mapping_failed"},
494 { STATS_OFFSET32(mbuf_alloc_tx),
495 4, STATS_FLAGS_FUNC, "mbuf_alloc_tx"},
496 { STATS_OFFSET32(mbuf_alloc_rx),
497 4, STATS_FLAGS_FUNC, "mbuf_alloc_rx"},
498 { STATS_OFFSET32(mbuf_alloc_sge),
499 4, STATS_FLAGS_FUNC, "mbuf_alloc_sge"},
500 { STATS_OFFSET32(mbuf_alloc_tpa),
501 4, STATS_FLAGS_FUNC, "mbuf_alloc_tpa"}
504 static const struct {
507 char string[STAT_NAME_LEN];
508 } bxe_eth_q_stats_arr[] = {
509 { Q_STATS_OFFSET32(total_bytes_received_hi),
511 { Q_STATS_OFFSET32(total_unicast_packets_received_hi),
512 8, "rx_ucast_packets" },
513 { Q_STATS_OFFSET32(total_multicast_packets_received_hi),
514 8, "rx_mcast_packets" },
515 { Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
516 8, "rx_bcast_packets" },
517 { Q_STATS_OFFSET32(no_buff_discard_hi),
519 { Q_STATS_OFFSET32(total_bytes_transmitted_hi),
521 { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
522 8, "tx_ucast_packets" },
523 { Q_STATS_OFFSET32(total_multicast_packets_transmitted_hi),
524 8, "tx_mcast_packets" },
525 { Q_STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
526 8, "tx_bcast_packets" },
527 { Q_STATS_OFFSET32(total_tpa_aggregations_hi),
528 8, "tpa_aggregations" },
529 { Q_STATS_OFFSET32(total_tpa_aggregated_frames_hi),
530 8, "tpa_aggregated_frames"},
531 { Q_STATS_OFFSET32(total_tpa_bytes_hi),
533 { Q_STATS_OFFSET32(rx_calls),
535 { Q_STATS_OFFSET32(rx_pkts),
537 { Q_STATS_OFFSET32(rx_tpa_pkts),
539 { Q_STATS_OFFSET32(rx_erroneous_jumbo_sge_pkts),
540 4, "rx_erroneous_jumbo_sge_pkts"},
541 { Q_STATS_OFFSET32(rx_bxe_service_rxsgl),
542 4, "rx_bxe_service_rxsgl"},
543 { Q_STATS_OFFSET32(rx_jumbo_sge_pkts),
544 4, "rx_jumbo_sge_pkts"},
545 { Q_STATS_OFFSET32(rx_soft_errors),
546 4, "rx_soft_errors"},
547 { Q_STATS_OFFSET32(rx_hw_csum_errors),
548 4, "rx_hw_csum_errors"},
549 { Q_STATS_OFFSET32(rx_ofld_frames_csum_ip),
550 4, "rx_ofld_frames_csum_ip"},
551 { Q_STATS_OFFSET32(rx_ofld_frames_csum_tcp_udp),
552 4, "rx_ofld_frames_csum_tcp_udp"},
553 { Q_STATS_OFFSET32(rx_budget_reached),
554 4, "rx_budget_reached"},
555 { Q_STATS_OFFSET32(tx_pkts),
557 { Q_STATS_OFFSET32(tx_soft_errors),
558 4, "tx_soft_errors"},
559 { Q_STATS_OFFSET32(tx_ofld_frames_csum_ip),
560 4, "tx_ofld_frames_csum_ip"},
561 { Q_STATS_OFFSET32(tx_ofld_frames_csum_tcp),
562 4, "tx_ofld_frames_csum_tcp"},
563 { Q_STATS_OFFSET32(tx_ofld_frames_csum_udp),
564 4, "tx_ofld_frames_csum_udp"},
565 { Q_STATS_OFFSET32(tx_ofld_frames_lso),
566 4, "tx_ofld_frames_lso"},
567 { Q_STATS_OFFSET32(tx_ofld_frames_lso_hdr_splits),
568 4, "tx_ofld_frames_lso_hdr_splits"},
569 { Q_STATS_OFFSET32(tx_encap_failures),
570 4, "tx_encap_failures"},
571 { Q_STATS_OFFSET32(tx_hw_queue_full),
572 4, "tx_hw_queue_full"},
573 { Q_STATS_OFFSET32(tx_hw_max_queue_depth),
574 4, "tx_hw_max_queue_depth"},
575 { Q_STATS_OFFSET32(tx_dma_mapping_failure),
576 4, "tx_dma_mapping_failure"},
577 { Q_STATS_OFFSET32(tx_max_drbr_queue_depth),
578 4, "tx_max_drbr_queue_depth"},
579 { Q_STATS_OFFSET32(tx_window_violation_std),
580 4, "tx_window_violation_std"},
581 { Q_STATS_OFFSET32(tx_window_violation_tso),
582 4, "tx_window_violation_tso"},
583 { Q_STATS_OFFSET32(tx_chain_lost_mbuf),
584 4, "tx_chain_lost_mbuf"},
585 { Q_STATS_OFFSET32(tx_frames_deferred),
586 4, "tx_frames_deferred"},
587 { Q_STATS_OFFSET32(tx_queue_xoff),
589 { Q_STATS_OFFSET32(mbuf_defrag_attempts),
590 4, "mbuf_defrag_attempts"},
591 { Q_STATS_OFFSET32(mbuf_defrag_failures),
592 4, "mbuf_defrag_failures"},
593 { Q_STATS_OFFSET32(mbuf_rx_bd_alloc_failed),
594 4, "mbuf_rx_bd_alloc_failed"},
595 { Q_STATS_OFFSET32(mbuf_rx_bd_mapping_failed),
596 4, "mbuf_rx_bd_mapping_failed"},
597 { Q_STATS_OFFSET32(mbuf_rx_tpa_alloc_failed),
598 4, "mbuf_rx_tpa_alloc_failed"},
599 { Q_STATS_OFFSET32(mbuf_rx_tpa_mapping_failed),
600 4, "mbuf_rx_tpa_mapping_failed"},
601 { Q_STATS_OFFSET32(mbuf_rx_sge_alloc_failed),
602 4, "mbuf_rx_sge_alloc_failed"},
603 { Q_STATS_OFFSET32(mbuf_rx_sge_mapping_failed),
604 4, "mbuf_rx_sge_mapping_failed"},
605 { Q_STATS_OFFSET32(mbuf_alloc_tx),
607 { Q_STATS_OFFSET32(mbuf_alloc_rx),
609 { Q_STATS_OFFSET32(mbuf_alloc_sge),
610 4, "mbuf_alloc_sge"},
611 { Q_STATS_OFFSET32(mbuf_alloc_tpa),
615 #define BXE_NUM_ETH_STATS ARRAY_SIZE(bxe_eth_stats_arr)
616 #define BXE_NUM_ETH_Q_STATS ARRAY_SIZE(bxe_eth_q_stats_arr)
619 static void bxe_cmng_fns_init(struct bxe_softc *sc,
622 static int bxe_get_cmng_fns_mode(struct bxe_softc *sc);
623 static void storm_memset_cmng(struct bxe_softc *sc,
624 struct cmng_init *cmng,
626 static void bxe_set_reset_global(struct bxe_softc *sc);
627 static void bxe_set_reset_in_progress(struct bxe_softc *sc);
628 static uint8_t bxe_reset_is_done(struct bxe_softc *sc,
630 static uint8_t bxe_clear_pf_load(struct bxe_softc *sc);
631 static uint8_t bxe_chk_parity_attn(struct bxe_softc *sc,
634 static void bxe_int_disable(struct bxe_softc *sc);
635 static int bxe_release_leader_lock(struct bxe_softc *sc);
636 static void bxe_pf_disable(struct bxe_softc *sc);
637 static void bxe_free_fp_buffers(struct bxe_softc *sc);
638 static inline void bxe_update_rx_prod(struct bxe_softc *sc,
639 struct bxe_fastpath *fp,
642 uint16_t rx_sge_prod);
643 static void bxe_link_report_locked(struct bxe_softc *sc);
644 static void bxe_link_report(struct bxe_softc *sc);
645 static void bxe_link_status_update(struct bxe_softc *sc);
646 static void bxe_periodic_callout_func(void *xsc);
647 static void bxe_periodic_start(struct bxe_softc *sc);
648 static void bxe_periodic_stop(struct bxe_softc *sc);
649 static int bxe_alloc_rx_bd_mbuf(struct bxe_fastpath *fp,
652 static int bxe_alloc_rx_tpa_mbuf(struct bxe_fastpath *fp,
654 static int bxe_alloc_rx_sge_mbuf(struct bxe_fastpath *fp,
656 static uint8_t bxe_txeof(struct bxe_softc *sc,
657 struct bxe_fastpath *fp);
658 static void bxe_task_fp(struct bxe_fastpath *fp);
659 static __noinline void bxe_dump_mbuf(struct bxe_softc *sc,
662 static int bxe_alloc_mem(struct bxe_softc *sc);
663 static void bxe_free_mem(struct bxe_softc *sc);
664 static int bxe_alloc_fw_stats_mem(struct bxe_softc *sc);
665 static void bxe_free_fw_stats_mem(struct bxe_softc *sc);
666 static int bxe_interrupt_attach(struct bxe_softc *sc);
667 static void bxe_interrupt_detach(struct bxe_softc *sc);
668 static void bxe_set_rx_mode(struct bxe_softc *sc);
669 static int bxe_init_locked(struct bxe_softc *sc);
670 static int bxe_stop_locked(struct bxe_softc *sc);
671 static __noinline int bxe_nic_load(struct bxe_softc *sc,
673 static __noinline int bxe_nic_unload(struct bxe_softc *sc,
674 uint32_t unload_mode,
677 static void bxe_handle_sp_tq(void *context, int pending);
678 static void bxe_handle_fp_tq(void *context, int pending);
680 static int bxe_add_cdev(struct bxe_softc *sc);
681 static void bxe_del_cdev(struct bxe_softc *sc);
682 static int bxe_grc_dump(struct bxe_softc *sc);
683 static int bxe_alloc_buf_rings(struct bxe_softc *sc);
684 static void bxe_free_buf_rings(struct bxe_softc *sc);
686 /* calculate crc32 on a buffer (NOTE: crc32_length MUST be aligned to 8) */
688 calc_crc32(uint8_t *crc32_packet,
689 uint32_t crc32_length,
698 uint8_t current_byte = 0;
699 uint32_t crc32_result = crc32_seed;
700 const uint32_t CRC32_POLY = 0x1edc6f41;
702 if ((crc32_packet == NULL) ||
703 (crc32_length == 0) ||
704 ((crc32_length % 8) != 0))
706 return (crc32_result);
709 for (byte = 0; byte < crc32_length; byte = byte + 1)
711 current_byte = crc32_packet[byte];
712 for (bit = 0; bit < 8; bit = bit + 1)
714 /* msb = crc32_result[31]; */
715 msb = (uint8_t)(crc32_result >> 31);
717 crc32_result = crc32_result << 1;
719 /* it (msb != current_byte[bit]) */
720 if (msb != (0x1 & (current_byte >> bit)))
722 crc32_result = crc32_result ^ CRC32_POLY;
723 /* crc32_result[0] = 1 */
730 * 1. "mirror" every bit
731 * 2. swap the 4 bytes
732 * 3. complement each bit
737 shft = sizeof(crc32_result) * 8 - 1;
739 for (crc32_result >>= 1; crc32_result; crc32_result >>= 1)
742 temp |= crc32_result & 1;
746 /* temp[31-bit] = crc32_result[bit] */
750 /* crc32_result = {temp[7:0], temp[15:8], temp[23:16], temp[31:24]} */
752 uint32_t t0, t1, t2, t3;
753 t0 = (0x000000ff & (temp >> 24));
754 t1 = (0x0000ff00 & (temp >> 8));
755 t2 = (0x00ff0000 & (temp << 8));
756 t3 = (0xff000000 & (temp << 24));
757 crc32_result = t0 | t1 | t2 | t3;
763 crc32_result = ~crc32_result;
766 return (crc32_result);
771 volatile unsigned long *addr)
773 return ((atomic_load_acq_long(addr) & (1 << nr)) != 0);
777 bxe_set_bit(unsigned int nr,
778 volatile unsigned long *addr)
780 atomic_set_acq_long(addr, (1 << nr));
784 bxe_clear_bit(int nr,
785 volatile unsigned long *addr)
787 atomic_clear_acq_long(addr, (1 << nr));
791 bxe_test_and_set_bit(int nr,
792 volatile unsigned long *addr)
798 } while (atomic_cmpset_acq_long(addr, x, x | nr) == 0);
799 // if (x & nr) bit_was_set; else bit_was_not_set;
804 bxe_test_and_clear_bit(int nr,
805 volatile unsigned long *addr)
811 } while (atomic_cmpset_acq_long(addr, x, x & ~nr) == 0);
812 // if (x & nr) bit_was_set; else bit_was_not_set;
817 bxe_cmpxchg(volatile int *addr,
824 } while (atomic_cmpset_acq_int(addr, old, new) == 0);
829 * Get DMA memory from the OS.
831 * Validates that the OS has provided DMA buffers in response to a
832 * bus_dmamap_load call and saves the physical address of those buffers.
833 * When the callback is used the OS will return 0 for the mapping function
834 * (bus_dmamap_load) so we use the value of map_arg->maxsegs to pass any
835 * failures back to the caller.
841 bxe_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
843 struct bxe_dma *dma = arg;
848 BLOGE(dma->sc, "Failed DMA alloc '%s' (%d)!\n", dma->msg, error);
850 dma->paddr = segs->ds_addr;
856 * Allocate a block of memory and map it for DMA. No partial completions
857 * allowed and release any resources acquired if we can't acquire all
861 * 0 = Success, !0 = Failure
864 bxe_dma_alloc(struct bxe_softc *sc,
872 BLOGE(sc, "dma block '%s' already has size %lu\n", msg,
873 (unsigned long)dma->size);
877 memset(dma, 0, sizeof(*dma)); /* sanity */
880 snprintf(dma->msg, sizeof(dma->msg), "%s", msg);
882 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */
883 BCM_PAGE_SIZE, /* alignment */
884 0, /* boundary limit */
885 BUS_SPACE_MAXADDR, /* restricted low */
886 BUS_SPACE_MAXADDR, /* restricted hi */
887 NULL, /* addr filter() */
888 NULL, /* addr filter() arg */
889 size, /* max map size */
890 1, /* num discontinuous */
891 size, /* max seg size */
892 BUS_DMA_ALLOCNOW, /* flags */
894 NULL, /* lock() arg */
895 &dma->tag); /* returned dma tag */
897 BLOGE(sc, "Failed to create dma tag for '%s' (%d)\n", msg, rc);
898 memset(dma, 0, sizeof(*dma));
902 rc = bus_dmamem_alloc(dma->tag,
903 (void **)&dma->vaddr,
904 (BUS_DMA_NOWAIT | BUS_DMA_ZERO),
907 BLOGE(sc, "Failed to alloc dma mem for '%s' (%d)\n", msg, rc);
908 bus_dma_tag_destroy(dma->tag);
909 memset(dma, 0, sizeof(*dma));
913 rc = bus_dmamap_load(dma->tag,
917 bxe_dma_map_addr, /* BLOGD in here */
921 BLOGE(sc, "Failed to load dma map for '%s' (%d)\n", msg, rc);
922 bus_dmamem_free(dma->tag, dma->vaddr, dma->map);
923 bus_dma_tag_destroy(dma->tag);
924 memset(dma, 0, sizeof(*dma));
932 bxe_dma_free(struct bxe_softc *sc,
936 DBASSERT(sc, (dma->tag != NULL), ("dma tag is NULL"));
938 bus_dmamap_sync(dma->tag, dma->map,
939 (BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE));
940 bus_dmamap_unload(dma->tag, dma->map);
941 bus_dmamem_free(dma->tag, dma->vaddr, dma->map);
942 bus_dma_tag_destroy(dma->tag);
945 memset(dma, 0, sizeof(*dma));
949 * These indirect read and write routines are only during init.
950 * The locking is handled by the MCP.
954 bxe_reg_wr_ind(struct bxe_softc *sc,
958 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, addr, 4);
959 pci_write_config(sc->dev, PCICFG_GRC_DATA, val, 4);
960 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, 0, 4);
964 bxe_reg_rd_ind(struct bxe_softc *sc,
969 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, addr, 4);
970 val = pci_read_config(sc->dev, PCICFG_GRC_DATA, 4);
971 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, 0, 4);
977 bxe_acquire_hw_lock(struct bxe_softc *sc,
980 uint32_t lock_status;
981 uint32_t resource_bit = (1 << resource);
982 int func = SC_FUNC(sc);
983 uint32_t hw_lock_control_reg;
986 /* validate the resource is within range */
987 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
988 BLOGE(sc, "(resource 0x%x > HW_LOCK_MAX_RESOURCE_VALUE)"
989 " resource_bit 0x%x\n", resource, resource_bit);
994 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + (func * 8));
996 hw_lock_control_reg =
997 (MISC_REG_DRIVER_CONTROL_7 + ((func - 6) * 8));
1000 /* validate the resource is not already taken */
1001 lock_status = REG_RD(sc, hw_lock_control_reg);
1002 if (lock_status & resource_bit) {
1003 BLOGE(sc, "resource (0x%x) in use (status 0x%x bit 0x%x)\n",
1004 resource, lock_status, resource_bit);
1008 /* try every 5ms for 5 seconds */
1009 for (cnt = 0; cnt < 1000; cnt++) {
1010 REG_WR(sc, (hw_lock_control_reg + 4), resource_bit);
1011 lock_status = REG_RD(sc, hw_lock_control_reg);
1012 if (lock_status & resource_bit) {
1018 BLOGE(sc, "Resource 0x%x resource_bit 0x%x lock timeout!\n",
1019 resource, resource_bit);
1024 bxe_release_hw_lock(struct bxe_softc *sc,
1027 uint32_t lock_status;
1028 uint32_t resource_bit = (1 << resource);
1029 int func = SC_FUNC(sc);
1030 uint32_t hw_lock_control_reg;
1032 /* validate the resource is within range */
1033 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1034 BLOGE(sc, "(resource 0x%x > HW_LOCK_MAX_RESOURCE_VALUE)"
1035 " resource_bit 0x%x\n", resource, resource_bit);
1040 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + (func * 8));
1042 hw_lock_control_reg =
1043 (MISC_REG_DRIVER_CONTROL_7 + ((func - 6) * 8));
1046 /* validate the resource is currently taken */
1047 lock_status = REG_RD(sc, hw_lock_control_reg);
1048 if (!(lock_status & resource_bit)) {
1049 BLOGE(sc, "resource (0x%x) not in use (status 0x%x bit 0x%x)\n",
1050 resource, lock_status, resource_bit);
1054 REG_WR(sc, hw_lock_control_reg, resource_bit);
1057 static void bxe_acquire_phy_lock(struct bxe_softc *sc)
1060 bxe_acquire_hw_lock(sc,HW_LOCK_RESOURCE_MDIO);
1063 static void bxe_release_phy_lock(struct bxe_softc *sc)
1065 bxe_release_hw_lock(sc,HW_LOCK_RESOURCE_MDIO);
1069 * Per pf misc lock must be acquired before the per port mcp lock. Otherwise,
1070 * had we done things the other way around, if two pfs from the same port
1071 * would attempt to access nvram at the same time, we could run into a
1073 * pf A takes the port lock.
1074 * pf B succeeds in taking the same lock since they are from the same port.
1075 * pf A takes the per pf misc lock. Performs eeprom access.
1076 * pf A finishes. Unlocks the per pf misc lock.
1077 * Pf B takes the lock and proceeds to perform it's own access.
1078 * pf A unlocks the per port lock, while pf B is still working (!).
1079 * mcp takes the per port lock and corrupts pf B's access (and/or has it's own
1080 * access corrupted by pf B).*
1083 bxe_acquire_nvram_lock(struct bxe_softc *sc)
1085 int port = SC_PORT(sc);
1089 /* acquire HW lock: protect against other PFs in PF Direct Assignment */
1090 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_NVRAM);
1092 /* adjust timeout for emulation/FPGA */
1093 count = NVRAM_TIMEOUT_COUNT;
1094 if (CHIP_REV_IS_SLOW(sc)) {
1098 /* request access to nvram interface */
1099 REG_WR(sc, MCP_REG_MCPR_NVM_SW_ARB,
1100 (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port));
1102 for (i = 0; i < count*10; i++) {
1103 val = REG_RD(sc, MCP_REG_MCPR_NVM_SW_ARB);
1104 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
1111 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
1112 BLOGE(sc, "Cannot get access to nvram interface "
1113 "port %d val 0x%x (MCPR_NVM_SW_ARB_ARB_ARB1 << port)\n",
1122 bxe_release_nvram_lock(struct bxe_softc *sc)
1124 int port = SC_PORT(sc);
1128 /* adjust timeout for emulation/FPGA */
1129 count = NVRAM_TIMEOUT_COUNT;
1130 if (CHIP_REV_IS_SLOW(sc)) {
1134 /* relinquish nvram interface */
1135 REG_WR(sc, MCP_REG_MCPR_NVM_SW_ARB,
1136 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port));
1138 for (i = 0; i < count*10; i++) {
1139 val = REG_RD(sc, MCP_REG_MCPR_NVM_SW_ARB);
1140 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
1147 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
1148 BLOGE(sc, "Cannot free access to nvram interface "
1149 "port %d val 0x%x (MCPR_NVM_SW_ARB_ARB_ARB1 << port)\n",
1154 /* release HW lock: protect against other PFs in PF Direct Assignment */
1155 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_NVRAM);
1161 bxe_enable_nvram_access(struct bxe_softc *sc)
1165 val = REG_RD(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
1167 /* enable both bits, even on read */
1168 REG_WR(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
1169 (val | MCPR_NVM_ACCESS_ENABLE_EN | MCPR_NVM_ACCESS_ENABLE_WR_EN));
1173 bxe_disable_nvram_access(struct bxe_softc *sc)
1177 val = REG_RD(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
1179 /* disable both bits, even after read */
1180 REG_WR(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
1181 (val & ~(MCPR_NVM_ACCESS_ENABLE_EN |
1182 MCPR_NVM_ACCESS_ENABLE_WR_EN)));
1186 bxe_nvram_read_dword(struct bxe_softc *sc,
1194 /* build the command word */
1195 cmd_flags |= MCPR_NVM_COMMAND_DOIT;
1197 /* need to clear DONE bit separately */
1198 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
1200 /* address of the NVRAM to read from */
1201 REG_WR(sc, MCP_REG_MCPR_NVM_ADDR,
1202 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
1204 /* issue a read command */
1205 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
1207 /* adjust timeout for emulation/FPGA */
1208 count = NVRAM_TIMEOUT_COUNT;
1209 if (CHIP_REV_IS_SLOW(sc)) {
1213 /* wait for completion */
1216 for (i = 0; i < count; i++) {
1218 val = REG_RD(sc, MCP_REG_MCPR_NVM_COMMAND);
1220 if (val & MCPR_NVM_COMMAND_DONE) {
1221 val = REG_RD(sc, MCP_REG_MCPR_NVM_READ);
1222 /* we read nvram data in cpu order
1223 * but ethtool sees it as an array of bytes
1224 * converting to big-endian will do the work
1226 *ret_val = htobe32(val);
1233 BLOGE(sc, "nvram read timeout expired "
1234 "(offset 0x%x cmd_flags 0x%x val 0x%x)\n",
1235 offset, cmd_flags, val);
1242 bxe_nvram_read(struct bxe_softc *sc,
1251 if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
1252 BLOGE(sc, "Invalid parameter, offset 0x%x buf_size 0x%x\n",
1257 if ((offset + buf_size) > sc->devinfo.flash_size) {
1258 BLOGE(sc, "Invalid parameter, "
1259 "offset 0x%x + buf_size 0x%x > flash_size 0x%x\n",
1260 offset, buf_size, sc->devinfo.flash_size);
1264 /* request access to nvram interface */
1265 rc = bxe_acquire_nvram_lock(sc);
1270 /* enable access to nvram interface */
1271 bxe_enable_nvram_access(sc);
1273 /* read the first word(s) */
1274 cmd_flags = MCPR_NVM_COMMAND_FIRST;
1275 while ((buf_size > sizeof(uint32_t)) && (rc == 0)) {
1276 rc = bxe_nvram_read_dword(sc, offset, &val, cmd_flags);
1277 memcpy(ret_buf, &val, 4);
1279 /* advance to the next dword */
1280 offset += sizeof(uint32_t);
1281 ret_buf += sizeof(uint32_t);
1282 buf_size -= sizeof(uint32_t);
1287 cmd_flags |= MCPR_NVM_COMMAND_LAST;
1288 rc = bxe_nvram_read_dword(sc, offset, &val, cmd_flags);
1289 memcpy(ret_buf, &val, 4);
1292 /* disable access to nvram interface */
1293 bxe_disable_nvram_access(sc);
1294 bxe_release_nvram_lock(sc);
1300 bxe_nvram_write_dword(struct bxe_softc *sc,
1307 /* build the command word */
1308 cmd_flags |= (MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR);
1310 /* need to clear DONE bit separately */
1311 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
1313 /* write the data */
1314 REG_WR(sc, MCP_REG_MCPR_NVM_WRITE, val);
1316 /* address of the NVRAM to write to */
1317 REG_WR(sc, MCP_REG_MCPR_NVM_ADDR,
1318 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
1320 /* issue the write command */
1321 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
1323 /* adjust timeout for emulation/FPGA */
1324 count = NVRAM_TIMEOUT_COUNT;
1325 if (CHIP_REV_IS_SLOW(sc)) {
1329 /* wait for completion */
1331 for (i = 0; i < count; i++) {
1333 val = REG_RD(sc, MCP_REG_MCPR_NVM_COMMAND);
1334 if (val & MCPR_NVM_COMMAND_DONE) {
1341 BLOGE(sc, "nvram write timeout expired "
1342 "(offset 0x%x cmd_flags 0x%x val 0x%x)\n",
1343 offset, cmd_flags, val);
1349 #define BYTE_OFFSET(offset) (8 * (offset & 0x03))
1352 bxe_nvram_write1(struct bxe_softc *sc,
1358 uint32_t align_offset;
1362 if ((offset + buf_size) > sc->devinfo.flash_size) {
1363 BLOGE(sc, "Invalid parameter, "
1364 "offset 0x%x + buf_size 0x%x > flash_size 0x%x\n",
1365 offset, buf_size, sc->devinfo.flash_size);
1369 /* request access to nvram interface */
1370 rc = bxe_acquire_nvram_lock(sc);
1375 /* enable access to nvram interface */
1376 bxe_enable_nvram_access(sc);
1378 cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST);
1379 align_offset = (offset & ~0x03);
1380 rc = bxe_nvram_read_dword(sc, align_offset, &val, cmd_flags);
1383 val &= ~(0xff << BYTE_OFFSET(offset));
1384 val |= (*data_buf << BYTE_OFFSET(offset));
1386 /* nvram data is returned as an array of bytes
1387 * convert it back to cpu order
1391 rc = bxe_nvram_write_dword(sc, align_offset, val, cmd_flags);
1394 /* disable access to nvram interface */
1395 bxe_disable_nvram_access(sc);
1396 bxe_release_nvram_lock(sc);
1402 bxe_nvram_write(struct bxe_softc *sc,
1409 uint32_t written_so_far;
1412 if (buf_size == 1) {
1413 return (bxe_nvram_write1(sc, offset, data_buf, buf_size));
1416 if ((offset & 0x03) || (buf_size & 0x03) /* || (buf_size == 0) */) {
1417 BLOGE(sc, "Invalid parameter, offset 0x%x buf_size 0x%x\n",
1422 if (buf_size == 0) {
1423 return (0); /* nothing to do */
1426 if ((offset + buf_size) > sc->devinfo.flash_size) {
1427 BLOGE(sc, "Invalid parameter, "
1428 "offset 0x%x + buf_size 0x%x > flash_size 0x%x\n",
1429 offset, buf_size, sc->devinfo.flash_size);
1433 /* request access to nvram interface */
1434 rc = bxe_acquire_nvram_lock(sc);
1439 /* enable access to nvram interface */
1440 bxe_enable_nvram_access(sc);
1443 cmd_flags = MCPR_NVM_COMMAND_FIRST;
1444 while ((written_so_far < buf_size) && (rc == 0)) {
1445 if (written_so_far == (buf_size - sizeof(uint32_t))) {
1446 cmd_flags |= MCPR_NVM_COMMAND_LAST;
1447 } else if (((offset + 4) % NVRAM_PAGE_SIZE) == 0) {
1448 cmd_flags |= MCPR_NVM_COMMAND_LAST;
1449 } else if ((offset % NVRAM_PAGE_SIZE) == 0) {
1450 cmd_flags |= MCPR_NVM_COMMAND_FIRST;
1453 memcpy(&val, data_buf, 4);
1455 rc = bxe_nvram_write_dword(sc, offset, val, cmd_flags);
1457 /* advance to the next dword */
1458 offset += sizeof(uint32_t);
1459 data_buf += sizeof(uint32_t);
1460 written_so_far += sizeof(uint32_t);
1464 /* disable access to nvram interface */
1465 bxe_disable_nvram_access(sc);
1466 bxe_release_nvram_lock(sc);
1471 /* copy command into DMAE command memory and set DMAE command Go */
1473 bxe_post_dmae(struct bxe_softc *sc,
1474 struct dmae_cmd *dmae,
1477 uint32_t cmd_offset;
1480 cmd_offset = (DMAE_REG_CMD_MEM + (sizeof(struct dmae_cmd) * idx));
1481 for (i = 0; i < ((sizeof(struct dmae_cmd) / 4)); i++) {
1482 REG_WR(sc, (cmd_offset + (i * 4)), *(((uint32_t *)dmae) + i));
1485 REG_WR(sc, dmae_reg_go_c[idx], 1);
1489 bxe_dmae_opcode_add_comp(uint32_t opcode,
1492 return (opcode | ((comp_type << DMAE_CMD_C_DST_SHIFT) |
1493 DMAE_CMD_C_TYPE_ENABLE));
1497 bxe_dmae_opcode_clr_src_reset(uint32_t opcode)
1499 return (opcode & ~DMAE_CMD_SRC_RESET);
1503 bxe_dmae_opcode(struct bxe_softc *sc,
1509 uint32_t opcode = 0;
1511 opcode |= ((src_type << DMAE_CMD_SRC_SHIFT) |
1512 (dst_type << DMAE_CMD_DST_SHIFT));
1514 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
1516 opcode |= (SC_PORT(sc) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
1518 opcode |= ((SC_VN(sc) << DMAE_CMD_E1HVN_SHIFT) |
1519 (SC_VN(sc) << DMAE_CMD_DST_VN_SHIFT));
1521 opcode |= (DMAE_COM_SET_ERR << DMAE_CMD_ERR_POLICY_SHIFT);
1524 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
1526 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
1530 opcode = bxe_dmae_opcode_add_comp(opcode, comp_type);
1537 bxe_prep_dmae_with_comp(struct bxe_softc *sc,
1538 struct dmae_cmd *dmae,
1542 memset(dmae, 0, sizeof(struct dmae_cmd));
1544 /* set the opcode */
1545 dmae->opcode = bxe_dmae_opcode(sc, src_type, dst_type,
1546 TRUE, DMAE_COMP_PCI);
1548 /* fill in the completion parameters */
1549 dmae->comp_addr_lo = U64_LO(BXE_SP_MAPPING(sc, wb_comp));
1550 dmae->comp_addr_hi = U64_HI(BXE_SP_MAPPING(sc, wb_comp));
1551 dmae->comp_val = DMAE_COMP_VAL;
1554 /* issue a DMAE command over the init channel and wait for completion */
1556 bxe_issue_dmae_with_comp(struct bxe_softc *sc,
1557 struct dmae_cmd *dmae)
1559 uint32_t *wb_comp = BXE_SP(sc, wb_comp);
1560 int timeout = CHIP_REV_IS_SLOW(sc) ? 400000 : 4000;
1564 /* reset completion */
1567 /* post the command on the channel used for initializations */
1568 bxe_post_dmae(sc, dmae, INIT_DMAE_C(sc));
1570 /* wait for completion */
1573 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
1575 (sc->recovery_state != BXE_RECOVERY_DONE &&
1576 sc->recovery_state != BXE_RECOVERY_NIC_LOADING)) {
1577 BLOGE(sc, "DMAE timeout! *wb_comp 0x%x recovery_state 0x%x\n",
1578 *wb_comp, sc->recovery_state);
1579 BXE_DMAE_UNLOCK(sc);
1580 return (DMAE_TIMEOUT);
1587 if (*wb_comp & DMAE_PCI_ERR_FLAG) {
1588 BLOGE(sc, "DMAE PCI error! *wb_comp 0x%x recovery_state 0x%x\n",
1589 *wb_comp, sc->recovery_state);
1590 BXE_DMAE_UNLOCK(sc);
1591 return (DMAE_PCI_ERROR);
1594 BXE_DMAE_UNLOCK(sc);
1599 bxe_read_dmae(struct bxe_softc *sc,
1603 struct dmae_cmd dmae;
1607 DBASSERT(sc, (len32 <= 4), ("DMAE read length is %d", len32));
1609 if (!sc->dmae_ready) {
1610 data = BXE_SP(sc, wb_data[0]);
1612 for (i = 0; i < len32; i++) {
1613 data[i] = (CHIP_IS_E1(sc)) ?
1614 bxe_reg_rd_ind(sc, (src_addr + (i * 4))) :
1615 REG_RD(sc, (src_addr + (i * 4)));
1621 /* set opcode and fixed command fields */
1622 bxe_prep_dmae_with_comp(sc, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
1624 /* fill in addresses and len */
1625 dmae.src_addr_lo = (src_addr >> 2); /* GRC addr has dword resolution */
1626 dmae.src_addr_hi = 0;
1627 dmae.dst_addr_lo = U64_LO(BXE_SP_MAPPING(sc, wb_data));
1628 dmae.dst_addr_hi = U64_HI(BXE_SP_MAPPING(sc, wb_data));
1631 /* issue the command and wait for completion */
1632 if ((rc = bxe_issue_dmae_with_comp(sc, &dmae)) != 0) {
1633 bxe_panic(sc, ("DMAE failed (%d)\n", rc));
1638 bxe_write_dmae(struct bxe_softc *sc,
1639 bus_addr_t dma_addr,
1643 struct dmae_cmd dmae;
1646 if (!sc->dmae_ready) {
1647 DBASSERT(sc, (len32 <= 4), ("DMAE not ready and length is %d", len32));
1649 if (CHIP_IS_E1(sc)) {
1650 ecore_init_ind_wr(sc, dst_addr, BXE_SP(sc, wb_data[0]), len32);
1652 ecore_init_str_wr(sc, dst_addr, BXE_SP(sc, wb_data[0]), len32);
1658 /* set opcode and fixed command fields */
1659 bxe_prep_dmae_with_comp(sc, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
1661 /* fill in addresses and len */
1662 dmae.src_addr_lo = U64_LO(dma_addr);
1663 dmae.src_addr_hi = U64_HI(dma_addr);
1664 dmae.dst_addr_lo = (dst_addr >> 2); /* GRC addr has dword resolution */
1665 dmae.dst_addr_hi = 0;
1668 /* issue the command and wait for completion */
1669 if ((rc = bxe_issue_dmae_with_comp(sc, &dmae)) != 0) {
1670 bxe_panic(sc, ("DMAE failed (%d)\n", rc));
1675 bxe_write_dmae_phys_len(struct bxe_softc *sc,
1676 bus_addr_t phys_addr,
1680 int dmae_wr_max = DMAE_LEN32_WR_MAX(sc);
1683 while (len > dmae_wr_max) {
1685 (phys_addr + offset), /* src DMA address */
1686 (addr + offset), /* dst GRC address */
1688 offset += (dmae_wr_max * 4);
1693 (phys_addr + offset), /* src DMA address */
1694 (addr + offset), /* dst GRC address */
1699 bxe_set_ctx_validation(struct bxe_softc *sc,
1700 struct eth_context *cxt,
1703 /* ustorm cxt validation */
1704 cxt->ustorm_ag_context.cdu_usage =
1705 CDU_RSRVD_VALUE_TYPE_A(HW_CID(sc, cid),
1706 CDU_REGION_NUMBER_UCM_AG, ETH_CONNECTION_TYPE);
1707 /* xcontext validation */
1708 cxt->xstorm_ag_context.cdu_reserved =
1709 CDU_RSRVD_VALUE_TYPE_A(HW_CID(sc, cid),
1710 CDU_REGION_NUMBER_XCM_AG, ETH_CONNECTION_TYPE);
1714 bxe_storm_memset_hc_timeout(struct bxe_softc *sc,
1721 (BAR_CSTRORM_INTMEM +
1722 CSTORM_STATUS_BLOCK_DATA_TIMEOUT_OFFSET(fw_sb_id, sb_index));
1724 REG_WR8(sc, addr, ticks);
1727 "port %d fw_sb_id %d sb_index %d ticks %d\n",
1728 port, fw_sb_id, sb_index, ticks);
1732 bxe_storm_memset_hc_disable(struct bxe_softc *sc,
1738 uint32_t enable_flag =
1739 (disable) ? 0 : (1 << HC_INDEX_DATA_HC_ENABLED_SHIFT);
1741 (BAR_CSTRORM_INTMEM +
1742 CSTORM_STATUS_BLOCK_DATA_FLAGS_OFFSET(fw_sb_id, sb_index));
1746 flags = REG_RD8(sc, addr);
1747 flags &= ~HC_INDEX_DATA_HC_ENABLED;
1748 flags |= enable_flag;
1749 REG_WR8(sc, addr, flags);
1752 "port %d fw_sb_id %d sb_index %d disable %d\n",
1753 port, fw_sb_id, sb_index, disable);
1757 bxe_update_coalesce_sb_index(struct bxe_softc *sc,
1763 int port = SC_PORT(sc);
1764 uint8_t ticks = (usec / 4); /* XXX ??? */
1766 bxe_storm_memset_hc_timeout(sc, port, fw_sb_id, sb_index, ticks);
1768 disable = (disable) ? 1 : ((usec) ? 0 : 1);
1769 bxe_storm_memset_hc_disable(sc, port, fw_sb_id, sb_index, disable);
1773 elink_cb_udelay(struct bxe_softc *sc,
1780 elink_cb_reg_read(struct bxe_softc *sc,
1783 return (REG_RD(sc, reg_addr));
1787 elink_cb_reg_write(struct bxe_softc *sc,
1791 REG_WR(sc, reg_addr, val);
1795 elink_cb_reg_wb_write(struct bxe_softc *sc,
1800 REG_WR_DMAE(sc, offset, wb_write, len);
1804 elink_cb_reg_wb_read(struct bxe_softc *sc,
1809 REG_RD_DMAE(sc, offset, wb_write, len);
1813 elink_cb_path_id(struct bxe_softc *sc)
1815 return (SC_PATH(sc));
1819 elink_cb_event_log(struct bxe_softc *sc,
1820 const elink_log_id_t elink_log_id,
1824 BLOGI(sc, "ELINK EVENT LOG (%d)\n", elink_log_id);
1828 bxe_set_spio(struct bxe_softc *sc,
1834 /* Only 2 SPIOs are configurable */
1835 if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
1836 BLOGE(sc, "Invalid SPIO 0x%x mode 0x%x\n", spio, mode);
1840 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_SPIO);
1842 /* read SPIO and mask except the float bits */
1843 spio_reg = (REG_RD(sc, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
1846 case MISC_SPIO_OUTPUT_LOW:
1847 BLOGD(sc, DBG_LOAD, "Set SPIO 0x%x -> output low\n", spio);
1848 /* clear FLOAT and set CLR */
1849 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
1850 spio_reg |= (spio << MISC_SPIO_CLR_POS);
1853 case MISC_SPIO_OUTPUT_HIGH:
1854 BLOGD(sc, DBG_LOAD, "Set SPIO 0x%x -> output high\n", spio);
1855 /* clear FLOAT and set SET */
1856 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
1857 spio_reg |= (spio << MISC_SPIO_SET_POS);
1860 case MISC_SPIO_INPUT_HI_Z:
1861 BLOGD(sc, DBG_LOAD, "Set SPIO 0x%x -> input\n", spio);
1863 spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
1870 REG_WR(sc, MISC_REG_SPIO, spio_reg);
1871 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_SPIO);
1877 bxe_gpio_read(struct bxe_softc *sc,
1881 /* The GPIO should be swapped if swap register is set and active */
1882 int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) &&
1883 REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port);
1884 int gpio_shift = (gpio_num +
1885 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0));
1886 uint32_t gpio_mask = (1 << gpio_shift);
1889 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1890 BLOGE(sc, "Invalid GPIO %d port 0x%x gpio_port %d gpio_shift %d"
1891 " gpio_mask 0x%x\n", gpio_num, port, gpio_port, gpio_shift,
1896 /* read GPIO value */
1897 gpio_reg = REG_RD(sc, MISC_REG_GPIO);
1899 /* get the requested pin value */
1900 return ((gpio_reg & gpio_mask) == gpio_mask) ? 1 : 0;
1904 bxe_gpio_write(struct bxe_softc *sc,
1909 /* The GPIO should be swapped if swap register is set and active */
1910 int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) &&
1911 REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port);
1912 int gpio_shift = (gpio_num +
1913 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0));
1914 uint32_t gpio_mask = (1 << gpio_shift);
1917 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1918 BLOGE(sc, "Invalid GPIO %d mode 0x%x port 0x%x gpio_port %d"
1919 " gpio_shift %d gpio_mask 0x%x\n",
1920 gpio_num, mode, port, gpio_port, gpio_shift, gpio_mask);
1924 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
1926 /* read GPIO and mask except the float bits */
1927 gpio_reg = (REG_RD(sc, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
1930 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1932 "Set GPIO %d (shift %d) -> output low\n",
1933 gpio_num, gpio_shift);
1934 /* clear FLOAT and set CLR */
1935 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1936 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
1939 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1941 "Set GPIO %d (shift %d) -> output high\n",
1942 gpio_num, gpio_shift);
1943 /* clear FLOAT and set SET */
1944 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1945 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
1948 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
1950 "Set GPIO %d (shift %d) -> input\n",
1951 gpio_num, gpio_shift);
1953 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1960 REG_WR(sc, MISC_REG_GPIO, gpio_reg);
1961 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
1967 bxe_gpio_mult_write(struct bxe_softc *sc,
1973 /* any port swapping should be handled by caller */
1975 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
1977 /* read GPIO and mask except the float bits */
1978 gpio_reg = REG_RD(sc, MISC_REG_GPIO);
1979 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
1980 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
1981 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
1984 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1985 BLOGD(sc, DBG_PHY, "Set GPIO 0x%x -> output low\n", pins);
1987 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
1990 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1991 BLOGD(sc, DBG_PHY, "Set GPIO 0x%x -> output high\n", pins);
1993 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
1996 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
1997 BLOGD(sc, DBG_PHY, "Set GPIO 0x%x -> input\n", pins);
1999 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2003 BLOGE(sc, "Invalid GPIO mode assignment pins 0x%x mode 0x%x"
2004 " gpio_reg 0x%x\n", pins, mode, gpio_reg);
2005 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2009 REG_WR(sc, MISC_REG_GPIO, gpio_reg);
2010 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2016 bxe_gpio_int_write(struct bxe_softc *sc,
2021 /* The GPIO should be swapped if swap register is set and active */
2022 int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) &&
2023 REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port);
2024 int gpio_shift = (gpio_num +
2025 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0));
2026 uint32_t gpio_mask = (1 << gpio_shift);
2029 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2030 BLOGE(sc, "Invalid GPIO %d mode 0x%x port 0x%x gpio_port %d"
2031 " gpio_shift %d gpio_mask 0x%x\n",
2032 gpio_num, mode, port, gpio_port, gpio_shift, gpio_mask);
2036 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2039 gpio_reg = REG_RD(sc, MISC_REG_GPIO_INT);
2042 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
2044 "Clear GPIO INT %d (shift %d) -> output low\n",
2045 gpio_num, gpio_shift);
2046 /* clear SET and set CLR */
2047 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2048 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2051 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
2053 "Set GPIO INT %d (shift %d) -> output high\n",
2054 gpio_num, gpio_shift);
2055 /* clear CLR and set SET */
2056 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2057 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2064 REG_WR(sc, MISC_REG_GPIO_INT, gpio_reg);
2065 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2071 elink_cb_gpio_read(struct bxe_softc *sc,
2075 return (bxe_gpio_read(sc, gpio_num, port));
2079 elink_cb_gpio_write(struct bxe_softc *sc,
2081 uint8_t mode, /* 0=low 1=high */
2084 return (bxe_gpio_write(sc, gpio_num, mode, port));
2088 elink_cb_gpio_mult_write(struct bxe_softc *sc,
2090 uint8_t mode) /* 0=low 1=high */
2092 return (bxe_gpio_mult_write(sc, pins, mode));
2096 elink_cb_gpio_int_write(struct bxe_softc *sc,
2098 uint8_t mode, /* 0=low 1=high */
2101 return (bxe_gpio_int_write(sc, gpio_num, mode, port));
2105 elink_cb_notify_link_changed(struct bxe_softc *sc)
2107 REG_WR(sc, (MISC_REG_AEU_GENERAL_ATTN_12 +
2108 (SC_FUNC(sc) * sizeof(uint32_t))), 1);
2111 /* send the MCP a request, block until there is a reply */
2113 elink_cb_fw_command(struct bxe_softc *sc,
2117 int mb_idx = SC_FW_MB_IDX(sc);
2121 uint8_t delay = CHIP_REV_IS_SLOW(sc) ? 100 : 10;
2126 SHMEM_WR(sc, func_mb[mb_idx].drv_mb_param, param);
2127 SHMEM_WR(sc, func_mb[mb_idx].drv_mb_header, (command | seq));
2130 "wrote command 0x%08x to FW MB param 0x%08x\n",
2131 (command | seq), param);
2133 /* Let the FW do it's magic. GIve it up to 5 seconds... */
2135 DELAY(delay * 1000);
2136 rc = SHMEM_RD(sc, func_mb[mb_idx].fw_mb_header);
2137 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
2140 "[after %d ms] read 0x%x seq 0x%x from FW MB\n",
2141 cnt*delay, rc, seq);
2143 /* is this a reply to our command? */
2144 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK)) {
2145 rc &= FW_MSG_CODE_MASK;
2148 BLOGE(sc, "FW failed to respond!\n");
2149 // XXX bxe_fw_dump(sc);
2153 BXE_FWMB_UNLOCK(sc);
2158 bxe_fw_command(struct bxe_softc *sc,
2162 return (elink_cb_fw_command(sc, command, param));
2166 __storm_memset_dma_mapping(struct bxe_softc *sc,
2170 REG_WR(sc, addr, U64_LO(mapping));
2171 REG_WR(sc, (addr + 4), U64_HI(mapping));
2175 storm_memset_spq_addr(struct bxe_softc *sc,
2179 uint32_t addr = (XSEM_REG_FAST_MEMORY +
2180 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid));
2181 __storm_memset_dma_mapping(sc, addr, mapping);
2185 storm_memset_vf_to_pf(struct bxe_softc *sc,
2189 REG_WR8(sc, (BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id);
2190 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id);
2191 REG_WR8(sc, (BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id);
2192 REG_WR8(sc, (BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id);
2196 storm_memset_func_en(struct bxe_softc *sc,
2200 REG_WR8(sc, (BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid)), enable);
2201 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid)), enable);
2202 REG_WR8(sc, (BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid)), enable);
2203 REG_WR8(sc, (BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid)), enable);
2207 storm_memset_eq_data(struct bxe_softc *sc,
2208 struct event_ring_data *eq_data,
2214 addr = (BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid));
2215 size = sizeof(struct event_ring_data);
2216 ecore_storm_memset_struct(sc, addr, size, (uint32_t *)eq_data);
2220 storm_memset_eq_prod(struct bxe_softc *sc,
2224 uint32_t addr = (BAR_CSTRORM_INTMEM +
2225 CSTORM_EVENT_RING_PROD_OFFSET(pfid));
2226 REG_WR16(sc, addr, eq_prod);
2230 * Post a slowpath command.
2232 * A slowpath command is used to propogate a configuration change through
2233 * the controller in a controlled manner, allowing each STORM processor and
2234 * other H/W blocks to phase in the change. The commands sent on the
2235 * slowpath are referred to as ramrods. Depending on the ramrod used the
2236 * completion of the ramrod will occur in different ways. Here's a
2237 * breakdown of ramrods and how they complete:
2239 * RAMROD_CMD_ID_ETH_PORT_SETUP
2240 * Used to setup the leading connection on a port. Completes on the
2241 * Receive Completion Queue (RCQ) of that port (typically fp[0]).
2243 * RAMROD_CMD_ID_ETH_CLIENT_SETUP
2244 * Used to setup an additional connection on a port. Completes on the
2245 * RCQ of the multi-queue/RSS connection being initialized.
2247 * RAMROD_CMD_ID_ETH_STAT_QUERY
2248 * Used to force the storm processors to update the statistics database
2249 * in host memory. This ramrod is send on the leading connection CID and
2250 * completes as an index increment of the CSTORM on the default status
2253 * RAMROD_CMD_ID_ETH_UPDATE
2254 * Used to update the state of the leading connection, usually to udpate
2255 * the RSS indirection table. Completes on the RCQ of the leading
2256 * connection. (Not currently used under FreeBSD until OS support becomes
2259 * RAMROD_CMD_ID_ETH_HALT
2260 * Used when tearing down a connection prior to driver unload. Completes
2261 * on the RCQ of the multi-queue/RSS connection being torn down. Don't
2262 * use this on the leading connection.
2264 * RAMROD_CMD_ID_ETH_SET_MAC
2265 * Sets the Unicast/Broadcast/Multicast used by the port. Completes on
2266 * the RCQ of the leading connection.
2268 * RAMROD_CMD_ID_ETH_CFC_DEL
2269 * Used when tearing down a conneciton prior to driver unload. Completes
2270 * on the RCQ of the leading connection (since the current connection
2271 * has been completely removed from controller memory).
2273 * RAMROD_CMD_ID_ETH_PORT_DEL
2274 * Used to tear down the leading connection prior to driver unload,
2275 * typically fp[0]. Completes as an index increment of the CSTORM on the
2276 * default status block.
2278 * RAMROD_CMD_ID_ETH_FORWARD_SETUP
2279 * Used for connection offload. Completes on the RCQ of the multi-queue
2280 * RSS connection that is being offloaded. (Not currently used under
2283 * There can only be one command pending per function.
2286 * 0 = Success, !0 = Failure.
2289 /* must be called under the spq lock */
2291 struct eth_spe *bxe_sp_get_next(struct bxe_softc *sc)
2293 struct eth_spe *next_spe = sc->spq_prod_bd;
2295 if (sc->spq_prod_bd == sc->spq_last_bd) {
2296 /* wrap back to the first eth_spq */
2297 sc->spq_prod_bd = sc->spq;
2298 sc->spq_prod_idx = 0;
2307 /* must be called under the spq lock */
2309 void bxe_sp_prod_update(struct bxe_softc *sc)
2311 int func = SC_FUNC(sc);
2314 * Make sure that BD data is updated before writing the producer.
2315 * BD data is written to the memory, the producer is read from the
2316 * memory, thus we need a full memory barrier to ensure the ordering.
2320 REG_WR16(sc, (BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func)),
2323 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle, 0, 0,
2324 BUS_SPACE_BARRIER_WRITE);
2328 * bxe_is_contextless_ramrod - check if the current command ends on EQ
2330 * @cmd: command to check
2331 * @cmd_type: command type
2334 int bxe_is_contextless_ramrod(int cmd,
2337 if ((cmd_type == NONE_CONNECTION_TYPE) ||
2338 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
2339 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
2340 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
2341 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
2342 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
2343 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE)) {
2351 * bxe_sp_post - place a single command on an SP ring
2353 * @sc: driver handle
2354 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
2355 * @cid: SW CID the command is related to
2356 * @data_hi: command private data address (high 32 bits)
2357 * @data_lo: command private data address (low 32 bits)
2358 * @cmd_type: command type (e.g. NONE, ETH)
2360 * SP data is handled as if it's always an address pair, thus data fields are
2361 * not swapped to little endian in upper functions. Instead this function swaps
2362 * data as if it's two uint32 fields.
2365 bxe_sp_post(struct bxe_softc *sc,
2372 struct eth_spe *spe;
2376 common = bxe_is_contextless_ramrod(command, cmd_type);
2381 if (!atomic_load_acq_long(&sc->eq_spq_left)) {
2382 BLOGE(sc, "EQ ring is full!\n");
2387 if (!atomic_load_acq_long(&sc->cq_spq_left)) {
2388 BLOGE(sc, "SPQ ring is full!\n");
2394 spe = bxe_sp_get_next(sc);
2396 /* CID needs port number to be encoded int it */
2397 spe->hdr.conn_and_cmd_data =
2398 htole32((command << SPE_HDR_T_CMD_ID_SHIFT) | HW_CID(sc, cid));
2400 type = (cmd_type << SPE_HDR_T_CONN_TYPE_SHIFT) & SPE_HDR_T_CONN_TYPE;
2402 /* TBD: Check if it works for VFs */
2403 type |= ((SC_FUNC(sc) << SPE_HDR_T_FUNCTION_ID_SHIFT) &
2404 SPE_HDR_T_FUNCTION_ID);
2406 spe->hdr.type = htole16(type);
2408 spe->data.update_data_addr.hi = htole32(data_hi);
2409 spe->data.update_data_addr.lo = htole32(data_lo);
2412 * It's ok if the actual decrement is issued towards the memory
2413 * somewhere between the lock and unlock. Thus no more explict
2414 * memory barrier is needed.
2417 atomic_subtract_acq_long(&sc->eq_spq_left, 1);
2419 atomic_subtract_acq_long(&sc->cq_spq_left, 1);
2422 BLOGD(sc, DBG_SP, "SPQE -> %#jx\n", (uintmax_t)sc->spq_dma.paddr);
2423 BLOGD(sc, DBG_SP, "FUNC_RDATA -> %p / %#jx\n",
2424 BXE_SP(sc, func_rdata), (uintmax_t)BXE_SP_MAPPING(sc, func_rdata));
2426 "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%lx,%lx)\n",
2428 (uint32_t)U64_HI(sc->spq_dma.paddr),
2429 (uint32_t)(U64_LO(sc->spq_dma.paddr) + (uint8_t *)sc->spq_prod_bd - (uint8_t *)sc->spq),
2436 atomic_load_acq_long(&sc->cq_spq_left),
2437 atomic_load_acq_long(&sc->eq_spq_left));
2439 bxe_sp_prod_update(sc);
2446 * bxe_debug_print_ind_table - prints the indirection table configuration.
2448 * @sc: driver hanlde
2449 * @p: pointer to rss configuration
2453 * FreeBSD Device probe function.
2455 * Compares the device found to the driver's list of supported devices and
2456 * reports back to the bsd loader whether this is the right driver for the device.
2457 * This is the driver entry function called from the "kldload" command.
2460 * BUS_PROBE_DEFAULT on success, positive value on failure.
2463 bxe_probe(device_t dev)
2465 struct bxe_softc *sc;
2466 struct bxe_device_type *t;
2468 uint16_t did, sdid, svid, vid;
2470 /* Find our device structure */
2471 sc = device_get_softc(dev);
2475 /* Get the data for the device to be probed. */
2476 vid = pci_get_vendor(dev);
2477 did = pci_get_device(dev);
2478 svid = pci_get_subvendor(dev);
2479 sdid = pci_get_subdevice(dev);
2482 "%s(); VID = 0x%04X, DID = 0x%04X, SVID = 0x%04X, "
2483 "SDID = 0x%04X\n", __FUNCTION__, vid, did, svid, sdid);
2485 /* Look through the list of known devices for a match. */
2486 while (t->bxe_name != NULL) {
2487 if ((vid == t->bxe_vid) && (did == t->bxe_did) &&
2488 ((svid == t->bxe_svid) || (t->bxe_svid == PCI_ANY_ID)) &&
2489 ((sdid == t->bxe_sdid) || (t->bxe_sdid == PCI_ANY_ID))) {
2490 descbuf = malloc(BXE_DEVDESC_MAX, M_TEMP, M_NOWAIT);
2491 if (descbuf == NULL)
2494 /* Print out the device identity. */
2495 snprintf(descbuf, BXE_DEVDESC_MAX,
2496 "%s (%c%d) BXE v:%s\n", t->bxe_name,
2497 (((pci_read_config(dev, PCIR_REVID, 4) &
2499 (pci_read_config(dev, PCIR_REVID, 4) & 0xf),
2500 BXE_DRIVER_VERSION);
2502 device_set_desc_copy(dev, descbuf);
2503 free(descbuf, M_TEMP);
2504 return (BUS_PROBE_DEFAULT);
2513 bxe_init_mutexes(struct bxe_softc *sc)
2515 #ifdef BXE_CORE_LOCK_SX
2516 snprintf(sc->core_sx_name, sizeof(sc->core_sx_name),
2517 "bxe%d_core_lock", sc->unit);
2518 sx_init(&sc->core_sx, sc->core_sx_name);
2520 snprintf(sc->core_mtx_name, sizeof(sc->core_mtx_name),
2521 "bxe%d_core_lock", sc->unit);
2522 mtx_init(&sc->core_mtx, sc->core_mtx_name, NULL, MTX_DEF);
2525 snprintf(sc->sp_mtx_name, sizeof(sc->sp_mtx_name),
2526 "bxe%d_sp_lock", sc->unit);
2527 mtx_init(&sc->sp_mtx, sc->sp_mtx_name, NULL, MTX_DEF);
2529 snprintf(sc->dmae_mtx_name, sizeof(sc->dmae_mtx_name),
2530 "bxe%d_dmae_lock", sc->unit);
2531 mtx_init(&sc->dmae_mtx, sc->dmae_mtx_name, NULL, MTX_DEF);
2533 snprintf(sc->port.phy_mtx_name, sizeof(sc->port.phy_mtx_name),
2534 "bxe%d_phy_lock", sc->unit);
2535 mtx_init(&sc->port.phy_mtx, sc->port.phy_mtx_name, NULL, MTX_DEF);
2537 snprintf(sc->fwmb_mtx_name, sizeof(sc->fwmb_mtx_name),
2538 "bxe%d_fwmb_lock", sc->unit);
2539 mtx_init(&sc->fwmb_mtx, sc->fwmb_mtx_name, NULL, MTX_DEF);
2541 snprintf(sc->print_mtx_name, sizeof(sc->print_mtx_name),
2542 "bxe%d_print_lock", sc->unit);
2543 mtx_init(&(sc->print_mtx), sc->print_mtx_name, NULL, MTX_DEF);
2545 snprintf(sc->stats_mtx_name, sizeof(sc->stats_mtx_name),
2546 "bxe%d_stats_lock", sc->unit);
2547 mtx_init(&(sc->stats_mtx), sc->stats_mtx_name, NULL, MTX_DEF);
2549 snprintf(sc->mcast_mtx_name, sizeof(sc->mcast_mtx_name),
2550 "bxe%d_mcast_lock", sc->unit);
2551 mtx_init(&(sc->mcast_mtx), sc->mcast_mtx_name, NULL, MTX_DEF);
2555 bxe_release_mutexes(struct bxe_softc *sc)
2557 #ifdef BXE_CORE_LOCK_SX
2558 sx_destroy(&sc->core_sx);
2560 if (mtx_initialized(&sc->core_mtx)) {
2561 mtx_destroy(&sc->core_mtx);
2565 if (mtx_initialized(&sc->sp_mtx)) {
2566 mtx_destroy(&sc->sp_mtx);
2569 if (mtx_initialized(&sc->dmae_mtx)) {
2570 mtx_destroy(&sc->dmae_mtx);
2573 if (mtx_initialized(&sc->port.phy_mtx)) {
2574 mtx_destroy(&sc->port.phy_mtx);
2577 if (mtx_initialized(&sc->fwmb_mtx)) {
2578 mtx_destroy(&sc->fwmb_mtx);
2581 if (mtx_initialized(&sc->print_mtx)) {
2582 mtx_destroy(&sc->print_mtx);
2585 if (mtx_initialized(&sc->stats_mtx)) {
2586 mtx_destroy(&sc->stats_mtx);
2589 if (mtx_initialized(&sc->mcast_mtx)) {
2590 mtx_destroy(&sc->mcast_mtx);
2595 bxe_tx_disable(struct bxe_softc* sc)
2597 struct ifnet *ifp = sc->ifnet;
2599 /* tell the stack the driver is stopped and TX queue is full */
2601 ifp->if_drv_flags = 0;
2606 bxe_drv_pulse(struct bxe_softc *sc)
2608 SHMEM_WR(sc, func_mb[SC_FW_MB_IDX(sc)].drv_pulse_mb,
2609 sc->fw_drv_pulse_wr_seq);
2612 static inline uint16_t
2613 bxe_tx_avail(struct bxe_softc *sc,
2614 struct bxe_fastpath *fp)
2620 prod = fp->tx_bd_prod;
2621 cons = fp->tx_bd_cons;
2623 used = SUB_S16(prod, cons);
2625 return (int16_t)(sc->tx_ring_size) - used;
2629 bxe_tx_queue_has_work(struct bxe_fastpath *fp)
2633 mb(); /* status block fields can change */
2634 hw_cons = le16toh(*fp->tx_cons_sb);
2635 return (hw_cons != fp->tx_pkt_cons);
2638 static inline uint8_t
2639 bxe_has_tx_work(struct bxe_fastpath *fp)
2641 /* expand this for multi-cos if ever supported */
2642 return (bxe_tx_queue_has_work(fp)) ? TRUE : FALSE;
2646 bxe_has_rx_work(struct bxe_fastpath *fp)
2648 uint16_t rx_cq_cons_sb;
2650 mb(); /* status block fields can change */
2651 rx_cq_cons_sb = le16toh(*fp->rx_cq_cons_sb);
2652 if ((rx_cq_cons_sb & RCQ_MAX) == RCQ_MAX)
2654 return (fp->rx_cq_cons != rx_cq_cons_sb);
2658 bxe_sp_event(struct bxe_softc *sc,
2659 struct bxe_fastpath *fp,
2660 union eth_rx_cqe *rr_cqe)
2662 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
2663 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
2664 enum ecore_queue_cmd drv_cmd = ECORE_Q_CMD_MAX;
2665 struct ecore_queue_sp_obj *q_obj = &BXE_SP_OBJ(sc, fp).q_obj;
2667 BLOGD(sc, DBG_SP, "fp=%d cid=%d got ramrod #%d state is %x type is %d\n",
2668 fp->index, cid, command, sc->state, rr_cqe->ramrod_cqe.ramrod_type);
2671 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
2672 BLOGD(sc, DBG_SP, "got UPDATE ramrod. CID %d\n", cid);
2673 drv_cmd = ECORE_Q_CMD_UPDATE;
2676 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
2677 BLOGD(sc, DBG_SP, "got MULTI[%d] setup ramrod\n", cid);
2678 drv_cmd = ECORE_Q_CMD_SETUP;
2681 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
2682 BLOGD(sc, DBG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
2683 drv_cmd = ECORE_Q_CMD_SETUP_TX_ONLY;
2686 case (RAMROD_CMD_ID_ETH_HALT):
2687 BLOGD(sc, DBG_SP, "got MULTI[%d] halt ramrod\n", cid);
2688 drv_cmd = ECORE_Q_CMD_HALT;
2691 case (RAMROD_CMD_ID_ETH_TERMINATE):
2692 BLOGD(sc, DBG_SP, "got MULTI[%d] teminate ramrod\n", cid);
2693 drv_cmd = ECORE_Q_CMD_TERMINATE;
2696 case (RAMROD_CMD_ID_ETH_EMPTY):
2697 BLOGD(sc, DBG_SP, "got MULTI[%d] empty ramrod\n", cid);
2698 drv_cmd = ECORE_Q_CMD_EMPTY;
2702 BLOGD(sc, DBG_SP, "ERROR: unexpected MC reply (%d) on fp[%d]\n",
2703 command, fp->index);
2707 if ((drv_cmd != ECORE_Q_CMD_MAX) &&
2708 q_obj->complete_cmd(sc, q_obj, drv_cmd)) {
2710 * q_obj->complete_cmd() failure means that this was
2711 * an unexpected completion.
2713 * In this case we don't want to increase the sc->spq_left
2714 * because apparently we haven't sent this command the first
2717 // bxe_panic(sc, ("Unexpected SP completion\n"));
2721 atomic_add_acq_long(&sc->cq_spq_left, 1);
2723 BLOGD(sc, DBG_SP, "sc->cq_spq_left 0x%lx\n",
2724 atomic_load_acq_long(&sc->cq_spq_left));
2728 * The current mbuf is part of an aggregation. Move the mbuf into the TPA
2729 * aggregation queue, put an empty mbuf back onto the receive chain, and mark
2730 * the current aggregation queue as in-progress.
2733 bxe_tpa_start(struct bxe_softc *sc,
2734 struct bxe_fastpath *fp,
2738 struct eth_fast_path_rx_cqe *cqe)
2740 struct bxe_sw_rx_bd tmp_bd;
2741 struct bxe_sw_rx_bd *rx_buf;
2742 struct eth_rx_bd *rx_bd;
2744 struct bxe_sw_tpa_info *tpa_info = &fp->rx_tpa_info[queue];
2747 BLOGD(sc, DBG_LRO, "fp[%02d].tpa[%02d] TPA START "
2748 "cons=%d prod=%d\n",
2749 fp->index, queue, cons, prod);
2751 max_agg_queues = MAX_AGG_QS(sc);
2753 KASSERT((queue < max_agg_queues),
2754 ("fp[%02d] invalid aggr queue (%d >= %d)!",
2755 fp->index, queue, max_agg_queues));
2757 KASSERT((tpa_info->state == BXE_TPA_STATE_STOP),
2758 ("fp[%02d].tpa[%02d] starting aggr on queue not stopped!",
2761 /* copy the existing mbuf and mapping from the TPA pool */
2762 tmp_bd = tpa_info->bd;
2764 if (tmp_bd.m == NULL) {
2767 tmp = (uint32_t *)cqe;
2769 BLOGE(sc, "fp[%02d].tpa[%02d] cons[%d] prod[%d]mbuf not allocated!\n",
2770 fp->index, queue, cons, prod);
2771 BLOGE(sc, "cqe [0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x]\n",
2772 *tmp, *(tmp+1), *(tmp+2), *(tmp+3), *(tmp+4), *(tmp+5), *(tmp+6), *(tmp+7));
2774 /* XXX Error handling? */
2778 /* change the TPA queue to the start state */
2779 tpa_info->state = BXE_TPA_STATE_START;
2780 tpa_info->placement_offset = cqe->placement_offset;
2781 tpa_info->parsing_flags = le16toh(cqe->pars_flags.flags);
2782 tpa_info->vlan_tag = le16toh(cqe->vlan_tag);
2783 tpa_info->len_on_bd = le16toh(cqe->len_on_bd);
2785 fp->rx_tpa_queue_used |= (1 << queue);
2788 * If all the buffer descriptors are filled with mbufs then fill in
2789 * the current consumer index with a new BD. Else if a maximum Rx
2790 * buffer limit is imposed then fill in the next producer index.
2792 index = (sc->max_rx_bufs != RX_BD_USABLE) ?
2795 /* move the received mbuf and mapping to TPA pool */
2796 tpa_info->bd = fp->rx_mbuf_chain[cons];
2798 /* release any existing RX BD mbuf mappings */
2799 if (cons != index) {
2800 rx_buf = &fp->rx_mbuf_chain[cons];
2802 if (rx_buf->m_map != NULL) {
2803 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map,
2804 BUS_DMASYNC_POSTREAD);
2805 bus_dmamap_unload(fp->rx_mbuf_tag, rx_buf->m_map);
2809 * We get here when the maximum number of rx buffers is less than
2810 * RX_BD_USABLE. The mbuf is already saved above so it's OK to NULL
2811 * it out here without concern of a memory leak.
2813 fp->rx_mbuf_chain[cons].m = NULL;
2816 /* update the Rx SW BD with the mbuf info from the TPA pool */
2817 fp->rx_mbuf_chain[index] = tmp_bd;
2819 /* update the Rx BD with the empty mbuf phys address from the TPA pool */
2820 rx_bd = &fp->rx_chain[index];
2821 rx_bd->addr_hi = htole32(U64_HI(tpa_info->seg.ds_addr));
2822 rx_bd->addr_lo = htole32(U64_LO(tpa_info->seg.ds_addr));
2826 * When a TPA aggregation is completed, loop through the individual mbufs
2827 * of the aggregation, combining them into a single mbuf which will be sent
2828 * up the stack. Refill all freed SGEs with mbufs as we go along.
2831 bxe_fill_frag_mbuf(struct bxe_softc *sc,
2832 struct bxe_fastpath *fp,
2833 struct bxe_sw_tpa_info *tpa_info,
2837 struct eth_end_agg_rx_cqe *cqe,
2840 struct mbuf *m_frag;
2841 uint32_t frag_len, frag_size, i;
2846 frag_size = le16toh(cqe->pkt_len) - tpa_info->len_on_bd;
2849 "fp[%02d].tpa[%02d] TPA fill len_on_bd=%d frag_size=%d pages=%d\n",
2850 fp->index, queue, tpa_info->len_on_bd, frag_size, pages);
2852 /* make sure the aggregated frame is not too big to handle */
2853 if (pages > 8 * PAGES_PER_SGE) {
2855 uint32_t *tmp = (uint32_t *)cqe;
2857 BLOGE(sc, "fp[%02d].sge[0x%04x] has too many pages (%d)! "
2858 "pkt_len=%d len_on_bd=%d frag_size=%d\n",
2859 fp->index, cqe_idx, pages, le16toh(cqe->pkt_len),
2860 tpa_info->len_on_bd, frag_size);
2862 BLOGE(sc, "cqe [0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x]\n",
2863 *tmp, *(tmp+1), *(tmp+2), *(tmp+3), *(tmp+4), *(tmp+5), *(tmp+6), *(tmp+7));
2865 bxe_panic(sc, ("sge page count error\n"));
2870 * Scan through the scatter gather list pulling individual mbufs into a
2871 * single mbuf for the host stack.
2873 for (i = 0, j = 0; i < pages; i += PAGES_PER_SGE, j++) {
2874 sge_idx = RX_SGE(le16toh(cqe->sgl_or_raw_data.sgl[j]));
2877 * Firmware gives the indices of the SGE as if the ring is an array
2878 * (meaning that the "next" element will consume 2 indices).
2880 frag_len = min(frag_size, (uint32_t)(SGE_PAGES));
2882 BLOGD(sc, DBG_LRO, "fp[%02d].tpa[%02d] TPA fill i=%d j=%d "
2883 "sge_idx=%d frag_size=%d frag_len=%d\n",
2884 fp->index, queue, i, j, sge_idx, frag_size, frag_len);
2886 m_frag = fp->rx_sge_mbuf_chain[sge_idx].m;
2888 /* allocate a new mbuf for the SGE */
2889 rc = bxe_alloc_rx_sge_mbuf(fp, sge_idx);
2891 /* Leave all remaining SGEs in the ring! */
2895 /* update the fragment length */
2896 m_frag->m_len = frag_len;
2898 /* concatenate the fragment to the head mbuf */
2900 fp->eth_q_stats.mbuf_alloc_sge--;
2902 /* update the TPA mbuf size and remaining fragment size */
2903 m->m_pkthdr.len += frag_len;
2904 frag_size -= frag_len;
2908 "fp[%02d].tpa[%02d] TPA fill done frag_size=%d\n",
2909 fp->index, queue, frag_size);
2915 bxe_clear_sge_mask_next_elems(struct bxe_fastpath *fp)
2919 for (i = 1; i <= RX_SGE_NUM_PAGES; i++) {
2920 int idx = RX_SGE_TOTAL_PER_PAGE * i - 1;
2922 for (j = 0; j < 2; j++) {
2923 BIT_VEC64_CLEAR_BIT(fp->sge_mask, idx);
2930 bxe_init_sge_ring_bit_mask(struct bxe_fastpath *fp)
2932 /* set the mask to all 1's, it's faster to compare to 0 than to 0xf's */
2933 memset(fp->sge_mask, 0xff, sizeof(fp->sge_mask));
2936 * Clear the two last indices in the page to 1. These are the indices that
2937 * correspond to the "next" element, hence will never be indicated and
2938 * should be removed from the calculations.
2940 bxe_clear_sge_mask_next_elems(fp);
2944 bxe_update_last_max_sge(struct bxe_fastpath *fp,
2947 uint16_t last_max = fp->last_max_sge;
2949 if (SUB_S16(idx, last_max) > 0) {
2950 fp->last_max_sge = idx;
2955 bxe_update_sge_prod(struct bxe_softc *sc,
2956 struct bxe_fastpath *fp,
2958 union eth_sgl_or_raw_data *cqe)
2960 uint16_t last_max, last_elem, first_elem;
2968 /* first mark all used pages */
2969 for (i = 0; i < sge_len; i++) {
2970 BIT_VEC64_CLEAR_BIT(fp->sge_mask,
2971 RX_SGE(le16toh(cqe->sgl[i])));
2975 "fp[%02d] fp_cqe->sgl[%d] = %d\n",
2976 fp->index, sge_len - 1,
2977 le16toh(cqe->sgl[sge_len - 1]));
2979 /* assume that the last SGE index is the biggest */
2980 bxe_update_last_max_sge(fp,
2981 le16toh(cqe->sgl[sge_len - 1]));
2983 last_max = RX_SGE(fp->last_max_sge);
2984 last_elem = last_max >> BIT_VEC64_ELEM_SHIFT;
2985 first_elem = RX_SGE(fp->rx_sge_prod) >> BIT_VEC64_ELEM_SHIFT;
2987 /* if ring is not full */
2988 if (last_elem + 1 != first_elem) {
2992 /* now update the prod */
2993 for (i = first_elem; i != last_elem; i = RX_SGE_NEXT_MASK_ELEM(i)) {
2994 if (__predict_true(fp->sge_mask[i])) {
2998 fp->sge_mask[i] = BIT_VEC64_ELEM_ONE_MASK;
2999 delta += BIT_VEC64_ELEM_SZ;
3003 fp->rx_sge_prod += delta;
3004 /* clear page-end entries */
3005 bxe_clear_sge_mask_next_elems(fp);
3009 "fp[%02d] fp->last_max_sge=%d fp->rx_sge_prod=%d\n",
3010 fp->index, fp->last_max_sge, fp->rx_sge_prod);
3014 * The aggregation on the current TPA queue has completed. Pull the individual
3015 * mbuf fragments together into a single mbuf, perform all necessary checksum
3016 * calculations, and send the resuting mbuf to the stack.
3019 bxe_tpa_stop(struct bxe_softc *sc,
3020 struct bxe_fastpath *fp,
3021 struct bxe_sw_tpa_info *tpa_info,
3024 struct eth_end_agg_rx_cqe *cqe,
3027 struct ifnet *ifp = sc->ifnet;
3032 "fp[%02d].tpa[%02d] pad=%d pkt_len=%d pages=%d vlan=%d\n",
3033 fp->index, queue, tpa_info->placement_offset,
3034 le16toh(cqe->pkt_len), pages, tpa_info->vlan_tag);
3038 /* allocate a replacement before modifying existing mbuf */
3039 rc = bxe_alloc_rx_tpa_mbuf(fp, queue);
3041 /* drop the frame and log an error */
3042 fp->eth_q_stats.rx_soft_errors++;
3043 goto bxe_tpa_stop_exit;
3046 /* we have a replacement, fixup the current mbuf */
3047 m_adj(m, tpa_info->placement_offset);
3048 m->m_pkthdr.len = m->m_len = tpa_info->len_on_bd;
3050 /* mark the checksums valid (taken care of by the firmware) */
3051 fp->eth_q_stats.rx_ofld_frames_csum_ip++;
3052 fp->eth_q_stats.rx_ofld_frames_csum_tcp_udp++;
3053 m->m_pkthdr.csum_data = 0xffff;
3054 m->m_pkthdr.csum_flags |= (CSUM_IP_CHECKED |
3059 /* aggregate all of the SGEs into a single mbuf */
3060 rc = bxe_fill_frag_mbuf(sc, fp, tpa_info, queue, pages, m, cqe, cqe_idx);
3062 /* drop the packet and log an error */
3063 fp->eth_q_stats.rx_soft_errors++;
3066 if (tpa_info->parsing_flags & PARSING_FLAGS_INNER_VLAN_EXIST) {
3067 m->m_pkthdr.ether_vtag = tpa_info->vlan_tag;
3068 m->m_flags |= M_VLANTAG;
3071 /* assign packet to this interface interface */
3072 m->m_pkthdr.rcvif = ifp;
3074 #if __FreeBSD_version >= 800000
3075 /* specify what RSS queue was used for this flow */
3076 m->m_pkthdr.flowid = fp->index;
3077 m->m_flags |= M_FLOWID;
3081 fp->eth_q_stats.rx_tpa_pkts++;
3083 /* pass the frame to the stack */
3084 (*ifp->if_input)(ifp, m);
3087 /* we passed an mbuf up the stack or dropped the frame */
3088 fp->eth_q_stats.mbuf_alloc_tpa--;
3092 fp->rx_tpa_info[queue].state = BXE_TPA_STATE_STOP;
3093 fp->rx_tpa_queue_used &= ~(1 << queue);
3098 struct bxe_fastpath *fp,
3102 struct eth_fast_path_rx_cqe *cqe_fp)
3104 struct mbuf *m_frag;
3105 uint16_t frags, frag_len;
3106 uint16_t sge_idx = 0;
3111 /* adjust the mbuf */
3114 frag_size = len - lenonbd;
3115 frags = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT;
3117 for (i = 0, j = 0; i < frags; i += PAGES_PER_SGE, j++) {
3118 sge_idx = RX_SGE(le16toh(cqe_fp->sgl_or_raw_data.sgl[j]));
3120 m_frag = fp->rx_sge_mbuf_chain[sge_idx].m;
3121 frag_len = min(frag_size, (uint32_t)(SGE_PAGE_SIZE));
3122 m_frag->m_len = frag_len;
3124 /* allocate a new mbuf for the SGE */
3125 rc = bxe_alloc_rx_sge_mbuf(fp, sge_idx);
3127 /* Leave all remaining SGEs in the ring! */
3130 fp->eth_q_stats.mbuf_alloc_sge--;
3132 /* concatenate the fragment to the head mbuf */
3135 frag_size -= frag_len;
3138 bxe_update_sge_prod(fp->sc, fp, frags, &cqe_fp->sgl_or_raw_data);
3144 bxe_rxeof(struct bxe_softc *sc,
3145 struct bxe_fastpath *fp)
3147 struct ifnet *ifp = sc->ifnet;
3148 uint16_t bd_cons, bd_prod, bd_prod_fw, comp_ring_cons;
3149 uint16_t hw_cq_cons, sw_cq_cons, sw_cq_prod;
3155 /* CQ "next element" is of the size of the regular element */
3156 hw_cq_cons = le16toh(*fp->rx_cq_cons_sb);
3157 if ((hw_cq_cons & RCQ_USABLE_PER_PAGE) == RCQ_USABLE_PER_PAGE) {
3161 bd_cons = fp->rx_bd_cons;
3162 bd_prod = fp->rx_bd_prod;
3163 bd_prod_fw = bd_prod;
3164 sw_cq_cons = fp->rx_cq_cons;
3165 sw_cq_prod = fp->rx_cq_prod;
3168 * Memory barrier necessary as speculative reads of the rx
3169 * buffer can be ahead of the index in the status block
3174 "fp[%02d] Rx START hw_cq_cons=%u sw_cq_cons=%u\n",
3175 fp->index, hw_cq_cons, sw_cq_cons);
3177 while (sw_cq_cons != hw_cq_cons) {
3178 struct bxe_sw_rx_bd *rx_buf = NULL;
3179 union eth_rx_cqe *cqe;
3180 struct eth_fast_path_rx_cqe *cqe_fp;
3181 uint8_t cqe_fp_flags;
3182 enum eth_rx_cqe_type cqe_fp_type;
3183 uint16_t len, lenonbd, pad;
3184 struct mbuf *m = NULL;
3186 comp_ring_cons = RCQ(sw_cq_cons);
3187 bd_prod = RX_BD(bd_prod);
3188 bd_cons = RX_BD(bd_cons);
3190 cqe = &fp->rcq_chain[comp_ring_cons];
3191 cqe_fp = &cqe->fast_path_cqe;
3192 cqe_fp_flags = cqe_fp->type_error_flags;
3193 cqe_fp_type = cqe_fp_flags & ETH_FAST_PATH_RX_CQE_TYPE;
3196 "fp[%02d] Rx hw_cq_cons=%d hw_sw_cons=%d "
3197 "BD prod=%d cons=%d CQE type=0x%x err=0x%x "
3198 "status=0x%x rss_hash=0x%x vlan=0x%x len=%u lenonbd=%u\n",
3204 CQE_TYPE(cqe_fp_flags),
3206 cqe_fp->status_flags,
3207 le32toh(cqe_fp->rss_hash_result),
3208 le16toh(cqe_fp->vlan_tag),
3209 le16toh(cqe_fp->pkt_len_or_gro_seg_len),
3210 le16toh(cqe_fp->len_on_bd));
3212 /* is this a slowpath msg? */
3213 if (__predict_false(CQE_TYPE_SLOW(cqe_fp_type))) {
3214 bxe_sp_event(sc, fp, cqe);
3218 rx_buf = &fp->rx_mbuf_chain[bd_cons];
3220 if (!CQE_TYPE_FAST(cqe_fp_type)) {
3221 struct bxe_sw_tpa_info *tpa_info;
3222 uint16_t frag_size, pages;
3225 if (CQE_TYPE_START(cqe_fp_type)) {
3226 bxe_tpa_start(sc, fp, cqe_fp->queue_index,
3227 bd_cons, bd_prod, cqe_fp);
3228 m = NULL; /* packet not ready yet */
3232 KASSERT(CQE_TYPE_STOP(cqe_fp_type),
3233 ("CQE type is not STOP! (0x%x)\n", cqe_fp_type));
3235 queue = cqe->end_agg_cqe.queue_index;
3236 tpa_info = &fp->rx_tpa_info[queue];
3238 BLOGD(sc, DBG_LRO, "fp[%02d].tpa[%02d] TPA STOP\n",
3241 frag_size = (le16toh(cqe->end_agg_cqe.pkt_len) -
3242 tpa_info->len_on_bd);
3243 pages = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT;
3245 bxe_tpa_stop(sc, fp, tpa_info, queue, pages,
3246 &cqe->end_agg_cqe, comp_ring_cons);
3248 bxe_update_sge_prod(sc, fp, pages, &cqe->end_agg_cqe.sgl_or_raw_data);
3255 /* is this an error packet? */
3256 if (__predict_false(cqe_fp_flags &
3257 ETH_FAST_PATH_RX_CQE_PHY_DECODE_ERR_FLG)) {
3258 BLOGE(sc, "flags 0x%x rx packet %u\n", cqe_fp_flags, sw_cq_cons);
3259 fp->eth_q_stats.rx_soft_errors++;
3263 len = le16toh(cqe_fp->pkt_len_or_gro_seg_len);
3264 lenonbd = le16toh(cqe_fp->len_on_bd);
3265 pad = cqe_fp->placement_offset;
3269 if (__predict_false(m == NULL)) {
3270 BLOGE(sc, "No mbuf in rx chain descriptor %d for fp[%02d]\n",
3271 bd_cons, fp->index);
3275 /* XXX double copy if packet length under a threshold */
3278 * If all the buffer descriptors are filled with mbufs then fill in
3279 * the current consumer index with a new BD. Else if a maximum Rx
3280 * buffer limit is imposed then fill in the next producer index.
3282 rc = bxe_alloc_rx_bd_mbuf(fp, bd_cons,
3283 (sc->max_rx_bufs != RX_BD_USABLE) ?
3287 /* we simply reuse the received mbuf and don't post it to the stack */
3290 BLOGE(sc, "mbuf alloc fail for fp[%02d] rx chain (%d)\n",
3292 fp->eth_q_stats.rx_soft_errors++;
3294 if (sc->max_rx_bufs != RX_BD_USABLE) {
3295 /* copy this consumer index to the producer index */
3296 memcpy(&fp->rx_mbuf_chain[bd_prod], rx_buf,
3297 sizeof(struct bxe_sw_rx_bd));
3298 memset(rx_buf, 0, sizeof(struct bxe_sw_rx_bd));
3304 /* current mbuf was detached from the bd */
3305 fp->eth_q_stats.mbuf_alloc_rx--;
3307 /* we allocated a replacement mbuf, fixup the current one */
3309 m->m_pkthdr.len = m->m_len = len;
3311 if ((len > 60) && (len > lenonbd)) {
3312 fp->eth_q_stats.rx_bxe_service_rxsgl++;
3313 rc = bxe_service_rxsgl(fp, len, lenonbd, m, cqe_fp);
3316 fp->eth_q_stats.rx_jumbo_sge_pkts++;
3317 } else if (lenonbd < len) {
3318 fp->eth_q_stats.rx_erroneous_jumbo_sge_pkts++;
3321 /* assign packet to this interface interface */
3322 m->m_pkthdr.rcvif = ifp;
3324 /* assume no hardware checksum has complated */
3325 m->m_pkthdr.csum_flags = 0;
3327 /* validate checksum if offload enabled */
3328 if (ifp->if_capenable & IFCAP_RXCSUM) {
3329 /* check for a valid IP frame */
3330 if (!(cqe->fast_path_cqe.status_flags &
3331 ETH_FAST_PATH_RX_CQE_IP_XSUM_NO_VALIDATION_FLG)) {
3332 m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED;
3333 if (__predict_false(cqe_fp_flags &
3334 ETH_FAST_PATH_RX_CQE_IP_BAD_XSUM_FLG)) {
3335 fp->eth_q_stats.rx_hw_csum_errors++;
3337 fp->eth_q_stats.rx_ofld_frames_csum_ip++;
3338 m->m_pkthdr.csum_flags |= CSUM_IP_VALID;
3342 /* check for a valid TCP/UDP frame */
3343 if (!(cqe->fast_path_cqe.status_flags &
3344 ETH_FAST_PATH_RX_CQE_L4_XSUM_NO_VALIDATION_FLG)) {
3345 if (__predict_false(cqe_fp_flags &
3346 ETH_FAST_PATH_RX_CQE_L4_BAD_XSUM_FLG)) {
3347 fp->eth_q_stats.rx_hw_csum_errors++;
3349 fp->eth_q_stats.rx_ofld_frames_csum_tcp_udp++;
3350 m->m_pkthdr.csum_data = 0xFFFF;
3351 m->m_pkthdr.csum_flags |= (CSUM_DATA_VALID |
3357 /* if there is a VLAN tag then flag that info */
3358 if (cqe->fast_path_cqe.pars_flags.flags & PARSING_FLAGS_INNER_VLAN_EXIST) {
3359 m->m_pkthdr.ether_vtag = cqe->fast_path_cqe.vlan_tag;
3360 m->m_flags |= M_VLANTAG;
3363 #if __FreeBSD_version >= 800000
3364 /* specify what RSS queue was used for this flow */
3365 m->m_pkthdr.flowid = fp->index;
3366 m->m_flags |= M_FLOWID;
3371 bd_cons = RX_BD_NEXT(bd_cons);
3372 bd_prod = RX_BD_NEXT(bd_prod);
3373 bd_prod_fw = RX_BD_NEXT(bd_prod_fw);
3375 /* pass the frame to the stack */
3376 if (__predict_true(m != NULL)) {
3379 (*ifp->if_input)(ifp, m);
3384 sw_cq_prod = RCQ_NEXT(sw_cq_prod);
3385 sw_cq_cons = RCQ_NEXT(sw_cq_cons);
3387 /* limit spinning on the queue */
3391 if (rx_pkts == sc->rx_budget) {
3392 fp->eth_q_stats.rx_budget_reached++;
3395 } /* while work to do */
3397 fp->rx_bd_cons = bd_cons;
3398 fp->rx_bd_prod = bd_prod_fw;
3399 fp->rx_cq_cons = sw_cq_cons;
3400 fp->rx_cq_prod = sw_cq_prod;
3402 /* Update producers */
3403 bxe_update_rx_prod(sc, fp, bd_prod_fw, sw_cq_prod, fp->rx_sge_prod);
3405 fp->eth_q_stats.rx_pkts += rx_pkts;
3406 fp->eth_q_stats.rx_calls++;
3408 BXE_FP_RX_UNLOCK(fp);
3410 return (sw_cq_cons != hw_cq_cons);
3414 bxe_free_tx_pkt(struct bxe_softc *sc,
3415 struct bxe_fastpath *fp,
3418 struct bxe_sw_tx_bd *tx_buf = &fp->tx_mbuf_chain[idx];
3419 struct eth_tx_start_bd *tx_start_bd;
3420 uint16_t bd_idx = TX_BD(tx_buf->first_bd);
3424 /* unmap the mbuf from non-paged memory */
3425 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
3427 tx_start_bd = &fp->tx_chain[bd_idx].start_bd;
3428 nbd = le16toh(tx_start_bd->nbd) - 1;
3430 new_cons = (tx_buf->first_bd + nbd);
3433 if (__predict_true(tx_buf->m != NULL)) {
3435 fp->eth_q_stats.mbuf_alloc_tx--;
3437 fp->eth_q_stats.tx_chain_lost_mbuf++;
3441 tx_buf->first_bd = 0;
3446 /* transmit timeout watchdog */
3448 bxe_watchdog(struct bxe_softc *sc,
3449 struct bxe_fastpath *fp)
3453 if ((fp->watchdog_timer == 0) || (--fp->watchdog_timer)) {
3454 BXE_FP_TX_UNLOCK(fp);
3458 BLOGE(sc, "TX watchdog timeout on fp[%02d], resetting!\n", fp->index);
3460 BXE_FP_TX_UNLOCK(fp);
3462 atomic_store_rel_long(&sc->chip_tq_flags, CHIP_TQ_REINIT);
3463 taskqueue_enqueue(sc->chip_tq, &sc->chip_tq_task);
3468 /* processes transmit completions */
3470 bxe_txeof(struct bxe_softc *sc,
3471 struct bxe_fastpath *fp)
3473 struct ifnet *ifp = sc->ifnet;
3474 uint16_t bd_cons, hw_cons, sw_cons, pkt_cons;
3475 uint16_t tx_bd_avail;
3477 BXE_FP_TX_LOCK_ASSERT(fp);
3479 bd_cons = fp->tx_bd_cons;
3480 hw_cons = le16toh(*fp->tx_cons_sb);
3481 sw_cons = fp->tx_pkt_cons;
3483 while (sw_cons != hw_cons) {
3484 pkt_cons = TX_BD(sw_cons);
3487 "TX: fp[%d]: hw_cons=%u sw_cons=%u pkt_cons=%u\n",
3488 fp->index, hw_cons, sw_cons, pkt_cons);
3490 bd_cons = bxe_free_tx_pkt(sc, fp, pkt_cons);
3495 fp->tx_pkt_cons = sw_cons;
3496 fp->tx_bd_cons = bd_cons;
3499 "TX done: fp[%d]: hw_cons=%u sw_cons=%u sw_prod=%u\n",
3500 fp->index, hw_cons, fp->tx_pkt_cons, fp->tx_pkt_prod);
3504 tx_bd_avail = bxe_tx_avail(sc, fp);
3506 if (tx_bd_avail < BXE_TX_CLEANUP_THRESHOLD) {
3507 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
3509 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
3512 if (fp->tx_pkt_prod != fp->tx_pkt_cons) {
3513 /* reset the watchdog timer if there are pending transmits */
3514 fp->watchdog_timer = BXE_TX_TIMEOUT;
3517 /* clear watchdog when there are no pending transmits */
3518 fp->watchdog_timer = 0;
3524 bxe_drain_tx_queues(struct bxe_softc *sc)
3526 struct bxe_fastpath *fp;
3529 /* wait until all TX fastpath tasks have completed */
3530 for (i = 0; i < sc->num_queues; i++) {
3535 while (bxe_has_tx_work(fp)) {
3539 BXE_FP_TX_UNLOCK(fp);
3542 BLOGE(sc, "Timeout waiting for fp[%d] "
3543 "transmits to complete!\n", i);
3544 bxe_panic(sc, ("tx drain failure\n"));
3558 bxe_del_all_macs(struct bxe_softc *sc,
3559 struct ecore_vlan_mac_obj *mac_obj,
3561 uint8_t wait_for_comp)
3563 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
3566 /* wait for completion of requested */
3567 if (wait_for_comp) {
3568 bxe_set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
3571 /* Set the mac type of addresses we want to clear */
3572 bxe_set_bit(mac_type, &vlan_mac_flags);
3574 rc = mac_obj->delete_all(sc, mac_obj, &vlan_mac_flags, &ramrod_flags);
3576 BLOGE(sc, "Failed to delete MACs (%d) mac_type %d wait_for_comp 0x%x\n",
3577 rc, mac_type, wait_for_comp);
3584 bxe_fill_accept_flags(struct bxe_softc *sc,
3586 unsigned long *rx_accept_flags,
3587 unsigned long *tx_accept_flags)
3589 /* Clear the flags first */
3590 *rx_accept_flags = 0;
3591 *tx_accept_flags = 0;
3594 case BXE_RX_MODE_NONE:
3596 * 'drop all' supersedes any accept flags that may have been
3597 * passed to the function.
3601 case BXE_RX_MODE_NORMAL:
3602 bxe_set_bit(ECORE_ACCEPT_UNICAST, rx_accept_flags);
3603 bxe_set_bit(ECORE_ACCEPT_MULTICAST, rx_accept_flags);
3604 bxe_set_bit(ECORE_ACCEPT_BROADCAST, rx_accept_flags);
3606 /* internal switching mode */
3607 bxe_set_bit(ECORE_ACCEPT_UNICAST, tx_accept_flags);
3608 bxe_set_bit(ECORE_ACCEPT_MULTICAST, tx_accept_flags);
3609 bxe_set_bit(ECORE_ACCEPT_BROADCAST, tx_accept_flags);
3613 case BXE_RX_MODE_ALLMULTI:
3614 bxe_set_bit(ECORE_ACCEPT_UNICAST, rx_accept_flags);
3615 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, rx_accept_flags);
3616 bxe_set_bit(ECORE_ACCEPT_BROADCAST, rx_accept_flags);
3618 /* internal switching mode */
3619 bxe_set_bit(ECORE_ACCEPT_UNICAST, tx_accept_flags);
3620 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, tx_accept_flags);
3621 bxe_set_bit(ECORE_ACCEPT_BROADCAST, tx_accept_flags);
3625 case BXE_RX_MODE_PROMISC:
3627 * According to deffinition of SI mode, iface in promisc mode
3628 * should receive matched and unmatched (in resolution of port)
3631 bxe_set_bit(ECORE_ACCEPT_UNMATCHED, rx_accept_flags);
3632 bxe_set_bit(ECORE_ACCEPT_UNICAST, rx_accept_flags);
3633 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, rx_accept_flags);
3634 bxe_set_bit(ECORE_ACCEPT_BROADCAST, rx_accept_flags);
3636 /* internal switching mode */
3637 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, tx_accept_flags);
3638 bxe_set_bit(ECORE_ACCEPT_BROADCAST, tx_accept_flags);
3641 bxe_set_bit(ECORE_ACCEPT_ALL_UNICAST, tx_accept_flags);
3643 bxe_set_bit(ECORE_ACCEPT_UNICAST, tx_accept_flags);
3649 BLOGE(sc, "Unknown rx_mode (0x%x)\n", rx_mode);
3653 /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
3654 if (rx_mode != BXE_RX_MODE_NONE) {
3655 bxe_set_bit(ECORE_ACCEPT_ANY_VLAN, rx_accept_flags);
3656 bxe_set_bit(ECORE_ACCEPT_ANY_VLAN, tx_accept_flags);
3663 bxe_set_q_rx_mode(struct bxe_softc *sc,
3665 unsigned long rx_mode_flags,
3666 unsigned long rx_accept_flags,
3667 unsigned long tx_accept_flags,
3668 unsigned long ramrod_flags)
3670 struct ecore_rx_mode_ramrod_params ramrod_param;
3673 memset(&ramrod_param, 0, sizeof(ramrod_param));
3675 /* Prepare ramrod parameters */
3676 ramrod_param.cid = 0;
3677 ramrod_param.cl_id = cl_id;
3678 ramrod_param.rx_mode_obj = &sc->rx_mode_obj;
3679 ramrod_param.func_id = SC_FUNC(sc);
3681 ramrod_param.pstate = &sc->sp_state;
3682 ramrod_param.state = ECORE_FILTER_RX_MODE_PENDING;
3684 ramrod_param.rdata = BXE_SP(sc, rx_mode_rdata);
3685 ramrod_param.rdata_mapping = BXE_SP_MAPPING(sc, rx_mode_rdata);
3687 bxe_set_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state);
3689 ramrod_param.ramrod_flags = ramrod_flags;
3690 ramrod_param.rx_mode_flags = rx_mode_flags;
3692 ramrod_param.rx_accept_flags = rx_accept_flags;
3693 ramrod_param.tx_accept_flags = tx_accept_flags;
3695 rc = ecore_config_rx_mode(sc, &ramrod_param);
3697 BLOGE(sc, "Set rx_mode %d cli_id 0x%x rx_mode_flags 0x%x "
3698 "rx_accept_flags 0x%x tx_accept_flags 0x%x "
3699 "ramrod_flags 0x%x rc %d failed\n", sc->rx_mode, cl_id,
3700 (uint32_t)rx_mode_flags, (uint32_t)rx_accept_flags,
3701 (uint32_t)tx_accept_flags, (uint32_t)ramrod_flags, rc);
3709 bxe_set_storm_rx_mode(struct bxe_softc *sc)
3711 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
3712 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
3715 rc = bxe_fill_accept_flags(sc, sc->rx_mode, &rx_accept_flags,
3721 bxe_set_bit(RAMROD_RX, &ramrod_flags);
3722 bxe_set_bit(RAMROD_TX, &ramrod_flags);
3724 /* XXX ensure all fastpath have same cl_id and/or move it to bxe_softc */
3725 return (bxe_set_q_rx_mode(sc, sc->fp[0].cl_id, rx_mode_flags,
3726 rx_accept_flags, tx_accept_flags,
3730 /* returns the "mcp load_code" according to global load_count array */
3732 bxe_nic_load_no_mcp(struct bxe_softc *sc)
3734 int path = SC_PATH(sc);
3735 int port = SC_PORT(sc);
3737 BLOGI(sc, "NO MCP - load counts[%d] %d, %d, %d\n",
3738 path, load_count[path][0], load_count[path][1],
3739 load_count[path][2]);
3740 load_count[path][0]++;
3741 load_count[path][1 + port]++;
3742 BLOGI(sc, "NO MCP - new load counts[%d] %d, %d, %d\n",
3743 path, load_count[path][0], load_count[path][1],
3744 load_count[path][2]);
3745 if (load_count[path][0] == 1) {
3746 return (FW_MSG_CODE_DRV_LOAD_COMMON);
3747 } else if (load_count[path][1 + port] == 1) {
3748 return (FW_MSG_CODE_DRV_LOAD_PORT);
3750 return (FW_MSG_CODE_DRV_LOAD_FUNCTION);
3754 /* returns the "mcp load_code" according to global load_count array */
3756 bxe_nic_unload_no_mcp(struct bxe_softc *sc)
3758 int port = SC_PORT(sc);
3759 int path = SC_PATH(sc);
3761 BLOGI(sc, "NO MCP - load counts[%d] %d, %d, %d\n",
3762 path, load_count[path][0], load_count[path][1],
3763 load_count[path][2]);
3764 load_count[path][0]--;
3765 load_count[path][1 + port]--;
3766 BLOGI(sc, "NO MCP - new load counts[%d] %d, %d, %d\n",
3767 path, load_count[path][0], load_count[path][1],
3768 load_count[path][2]);
3769 if (load_count[path][0] == 0) {
3770 return (FW_MSG_CODE_DRV_UNLOAD_COMMON);
3771 } else if (load_count[path][1 + port] == 0) {
3772 return (FW_MSG_CODE_DRV_UNLOAD_PORT);
3774 return (FW_MSG_CODE_DRV_UNLOAD_FUNCTION);
3778 /* request unload mode from the MCP: COMMON, PORT or FUNCTION */
3780 bxe_send_unload_req(struct bxe_softc *sc,
3783 uint32_t reset_code = 0;
3785 /* Select the UNLOAD request mode */
3786 if (unload_mode == UNLOAD_NORMAL) {
3787 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
3789 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
3792 /* Send the request to the MCP */
3793 if (!BXE_NOMCP(sc)) {
3794 reset_code = bxe_fw_command(sc, reset_code, 0);
3796 reset_code = bxe_nic_unload_no_mcp(sc);
3799 return (reset_code);
3802 /* send UNLOAD_DONE command to the MCP */
3804 bxe_send_unload_done(struct bxe_softc *sc,
3807 uint32_t reset_param =
3808 keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
3810 /* Report UNLOAD_DONE to MCP */
3811 if (!BXE_NOMCP(sc)) {
3812 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
3817 bxe_func_wait_started(struct bxe_softc *sc)
3821 if (!sc->port.pmf) {
3826 * (assumption: No Attention from MCP at this stage)
3827 * PMF probably in the middle of TX disable/enable transaction
3828 * 1. Sync IRS for default SB
3829 * 2. Sync SP queue - this guarantees us that attention handling started
3830 * 3. Wait, that TX disable/enable transaction completes
3832 * 1+2 guarantee that if DCBX attention was scheduled it already changed
3833 * pending bit of transaction from STARTED-->TX_STOPPED, if we already
3834 * received completion for the transaction the state is TX_STOPPED.
3835 * State will return to STARTED after completion of TX_STOPPED-->STARTED
3839 /* XXX make sure default SB ISR is done */
3840 /* need a way to synchronize an irq (intr_mtx?) */
3842 /* XXX flush any work queues */
3844 while (ecore_func_get_state(sc, &sc->func_obj) !=
3845 ECORE_F_STATE_STARTED && tout--) {
3849 if (ecore_func_get_state(sc, &sc->func_obj) != ECORE_F_STATE_STARTED) {
3851 * Failed to complete the transaction in a "good way"
3852 * Force both transactions with CLR bit.
3854 struct ecore_func_state_params func_params = { NULL };
3856 BLOGE(sc, "Unexpected function state! "
3857 "Forcing STARTED-->TX_STOPPED-->STARTED\n");
3859 func_params.f_obj = &sc->func_obj;
3860 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
3862 /* STARTED-->TX_STOPPED */
3863 func_params.cmd = ECORE_F_CMD_TX_STOP;
3864 ecore_func_state_change(sc, &func_params);
3866 /* TX_STOPPED-->STARTED */
3867 func_params.cmd = ECORE_F_CMD_TX_START;
3868 return (ecore_func_state_change(sc, &func_params));
3875 bxe_stop_queue(struct bxe_softc *sc,
3878 struct bxe_fastpath *fp = &sc->fp[index];
3879 struct ecore_queue_state_params q_params = { NULL };
3882 BLOGD(sc, DBG_LOAD, "stopping queue %d cid %d\n", index, fp->index);
3884 q_params.q_obj = &sc->sp_objs[fp->index].q_obj;
3885 /* We want to wait for completion in this context */
3886 bxe_set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
3888 /* Stop the primary connection: */
3890 /* ...halt the connection */
3891 q_params.cmd = ECORE_Q_CMD_HALT;
3892 rc = ecore_queue_state_change(sc, &q_params);
3897 /* ...terminate the connection */
3898 q_params.cmd = ECORE_Q_CMD_TERMINATE;
3899 memset(&q_params.params.terminate, 0, sizeof(q_params.params.terminate));
3900 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
3901 rc = ecore_queue_state_change(sc, &q_params);
3906 /* ...delete cfc entry */
3907 q_params.cmd = ECORE_Q_CMD_CFC_DEL;
3908 memset(&q_params.params.cfc_del, 0, sizeof(q_params.params.cfc_del));
3909 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
3910 return (ecore_queue_state_change(sc, &q_params));
3913 /* wait for the outstanding SP commands */
3914 static inline uint8_t
3915 bxe_wait_sp_comp(struct bxe_softc *sc,
3919 int tout = 5000; /* wait for 5 secs tops */
3923 if (!(atomic_load_acq_long(&sc->sp_state) & mask)) {
3932 tmp = atomic_load_acq_long(&sc->sp_state);
3934 BLOGE(sc, "Filtering completion timed out: "
3935 "sp_state 0x%lx, mask 0x%lx\n",
3944 bxe_func_stop(struct bxe_softc *sc)
3946 struct ecore_func_state_params func_params = { NULL };
3949 /* prepare parameters for function state transitions */
3950 bxe_set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
3951 func_params.f_obj = &sc->func_obj;
3952 func_params.cmd = ECORE_F_CMD_STOP;
3955 * Try to stop the function the 'good way'. If it fails (in case
3956 * of a parity error during bxe_chip_cleanup()) and we are
3957 * not in a debug mode, perform a state transaction in order to
3958 * enable further HW_RESET transaction.
3960 rc = ecore_func_state_change(sc, &func_params);
3962 BLOGE(sc, "FUNC_STOP ramrod failed. "
3963 "Running a dry transaction (%d)\n", rc);
3964 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
3965 return (ecore_func_state_change(sc, &func_params));
3972 bxe_reset_hw(struct bxe_softc *sc,
3975 struct ecore_func_state_params func_params = { NULL };
3977 /* Prepare parameters for function state transitions */
3978 bxe_set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
3980 func_params.f_obj = &sc->func_obj;
3981 func_params.cmd = ECORE_F_CMD_HW_RESET;
3983 func_params.params.hw_init.load_phase = load_code;
3985 return (ecore_func_state_change(sc, &func_params));
3989 bxe_int_disable_sync(struct bxe_softc *sc,
3993 /* prevent the HW from sending interrupts */
3994 bxe_int_disable(sc);
3997 /* XXX need a way to synchronize ALL irqs (intr_mtx?) */
3998 /* make sure all ISRs are done */
4000 /* XXX make sure sp_task is not running */
4001 /* cancel and flush work queues */
4005 bxe_chip_cleanup(struct bxe_softc *sc,
4006 uint32_t unload_mode,
4009 int port = SC_PORT(sc);
4010 struct ecore_mcast_ramrod_params rparam = { NULL };
4011 uint32_t reset_code;
4014 bxe_drain_tx_queues(sc);
4016 /* give HW time to discard old tx messages */
4019 /* Clean all ETH MACs */
4020 rc = bxe_del_all_macs(sc, &sc->sp_objs[0].mac_obj, ECORE_ETH_MAC, FALSE);
4022 BLOGE(sc, "Failed to delete all ETH MACs (%d)\n", rc);
4025 /* Clean up UC list */
4026 rc = bxe_del_all_macs(sc, &sc->sp_objs[0].mac_obj, ECORE_UC_LIST_MAC, TRUE);
4028 BLOGE(sc, "Failed to delete UC MACs list (%d)\n", rc);
4032 if (!CHIP_IS_E1(sc)) {
4033 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 0);
4036 /* Set "drop all" to stop Rx */
4039 * We need to take the BXE_MCAST_LOCK() here in order to prevent
4040 * a race between the completion code and this code.
4044 if (bxe_test_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state)) {
4045 bxe_set_bit(ECORE_FILTER_RX_MODE_SCHED, &sc->sp_state);
4047 bxe_set_storm_rx_mode(sc);
4050 /* Clean up multicast configuration */
4051 rparam.mcast_obj = &sc->mcast_obj;
4052 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL);
4054 BLOGE(sc, "Failed to send DEL MCAST command (%d)\n", rc);
4057 BXE_MCAST_UNLOCK(sc);
4059 // XXX bxe_iov_chip_cleanup(sc);
4062 * Send the UNLOAD_REQUEST to the MCP. This will return if
4063 * this function should perform FUNCTION, PORT, or COMMON HW
4066 reset_code = bxe_send_unload_req(sc, unload_mode);
4069 * (assumption: No Attention from MCP at this stage)
4070 * PMF probably in the middle of TX disable/enable transaction
4072 rc = bxe_func_wait_started(sc);
4074 BLOGE(sc, "bxe_func_wait_started failed (%d)\n", rc);
4078 * Close multi and leading connections
4079 * Completions for ramrods are collected in a synchronous way
4081 for (i = 0; i < sc->num_queues; i++) {
4082 if (bxe_stop_queue(sc, i)) {
4088 * If SP settings didn't get completed so far - something
4089 * very wrong has happen.
4091 if (!bxe_wait_sp_comp(sc, ~0x0UL)) {
4092 BLOGE(sc, "Common slow path ramrods got stuck!(%d)\n", rc);
4097 rc = bxe_func_stop(sc);
4099 BLOGE(sc, "Function stop failed!(%d)\n", rc);
4102 /* disable HW interrupts */
4103 bxe_int_disable_sync(sc, TRUE);
4105 /* detach interrupts */
4106 bxe_interrupt_detach(sc);
4108 /* Reset the chip */
4109 rc = bxe_reset_hw(sc, reset_code);
4111 BLOGE(sc, "Hardware reset failed(%d)\n", rc);
4114 /* Report UNLOAD_DONE to MCP */
4115 bxe_send_unload_done(sc, keep_link);
4119 bxe_disable_close_the_gate(struct bxe_softc *sc)
4122 int port = SC_PORT(sc);
4125 "Disabling 'close the gates'\n");
4127 if (CHIP_IS_E1(sc)) {
4128 uint32_t addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4129 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4130 val = REG_RD(sc, addr);
4132 REG_WR(sc, addr, val);
4134 val = REG_RD(sc, MISC_REG_AEU_GENERAL_MASK);
4135 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
4136 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
4137 REG_WR(sc, MISC_REG_AEU_GENERAL_MASK, val);
4142 * Cleans the object that have internal lists without sending
4143 * ramrods. Should be run when interrutps are disabled.
4146 bxe_squeeze_objects(struct bxe_softc *sc)
4148 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
4149 struct ecore_mcast_ramrod_params rparam = { NULL };
4150 struct ecore_vlan_mac_obj *mac_obj = &sc->sp_objs->mac_obj;
4153 /* Cleanup MACs' object first... */
4155 /* Wait for completion of requested */
4156 bxe_set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
4157 /* Perform a dry cleanup */
4158 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &ramrod_flags);
4160 /* Clean ETH primary MAC */
4161 bxe_set_bit(ECORE_ETH_MAC, &vlan_mac_flags);
4162 rc = mac_obj->delete_all(sc, &sc->sp_objs->mac_obj, &vlan_mac_flags,
4165 BLOGE(sc, "Failed to clean ETH MACs (%d)\n", rc);
4168 /* Cleanup UC list */
4170 bxe_set_bit(ECORE_UC_LIST_MAC, &vlan_mac_flags);
4171 rc = mac_obj->delete_all(sc, mac_obj, &vlan_mac_flags,
4174 BLOGE(sc, "Failed to clean UC list MACs (%d)\n", rc);
4177 /* Now clean mcast object... */
4179 rparam.mcast_obj = &sc->mcast_obj;
4180 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &rparam.ramrod_flags);
4182 /* Add a DEL command... */
4183 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL);
4185 BLOGE(sc, "Failed to send DEL MCAST command (%d)\n", rc);
4188 /* now wait until all pending commands are cleared */
4190 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT);
4193 BLOGE(sc, "Failed to clean MCAST object (%d)\n", rc);
4197 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT);
4201 /* stop the controller */
4202 static __noinline int
4203 bxe_nic_unload(struct bxe_softc *sc,
4204 uint32_t unload_mode,
4207 uint8_t global = FALSE;
4211 BXE_CORE_LOCK_ASSERT(sc);
4213 sc->ifnet->if_drv_flags &= ~IFF_DRV_RUNNING;
4215 for (i = 0; i < sc->num_queues; i++) {
4216 struct bxe_fastpath *fp;
4220 BXE_FP_TX_UNLOCK(fp);
4223 BLOGD(sc, DBG_LOAD, "Starting NIC unload...\n");
4225 /* mark driver as unloaded in shmem2 */
4226 if (IS_PF(sc) && SHMEM2_HAS(sc, drv_capabilities_flag)) {
4227 val = SHMEM2_RD(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)]);
4228 SHMEM2_WR(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)],
4229 val & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
4232 if (IS_PF(sc) && sc->recovery_state != BXE_RECOVERY_DONE &&
4233 (sc->state == BXE_STATE_CLOSED || sc->state == BXE_STATE_ERROR)) {
4235 * We can get here if the driver has been unloaded
4236 * during parity error recovery and is either waiting for a
4237 * leader to complete or for other functions to unload and
4238 * then ifconfig down has been issued. In this case we want to
4239 * unload and let other functions to complete a recovery
4242 sc->recovery_state = BXE_RECOVERY_DONE;
4244 bxe_release_leader_lock(sc);
4247 BLOGD(sc, DBG_LOAD, "Releasing a leadership...\n");
4248 BLOGE(sc, "Can't unload in closed or error state recover_state 0x%x"
4249 " state = 0x%x\n", sc->recovery_state, sc->state);
4254 * Nothing to do during unload if previous bxe_nic_load()
4255 * did not completed succesfully - all resourses are released.
4257 if ((sc->state == BXE_STATE_CLOSED) ||
4258 (sc->state == BXE_STATE_ERROR)) {
4262 sc->state = BXE_STATE_CLOSING_WAITING_HALT;
4268 sc->rx_mode = BXE_RX_MODE_NONE;
4269 /* XXX set rx mode ??? */
4271 if (IS_PF(sc) && !sc->grcdump_done) {
4272 /* set ALWAYS_ALIVE bit in shmem */
4273 sc->fw_drv_pulse_wr_seq |= DRV_PULSE_ALWAYS_ALIVE;
4277 bxe_stats_handle(sc, STATS_EVENT_STOP);
4278 bxe_save_statistics(sc);
4281 /* wait till consumers catch up with producers in all queues */
4282 bxe_drain_tx_queues(sc);
4284 /* if VF indicate to PF this function is going down (PF will delete sp
4285 * elements and clear initializations
4288 ; /* bxe_vfpf_close_vf(sc); */
4289 } else if (unload_mode != UNLOAD_RECOVERY) {
4290 /* if this is a normal/close unload need to clean up chip */
4291 if (!sc->grcdump_done)
4292 bxe_chip_cleanup(sc, unload_mode, keep_link);
4294 /* Send the UNLOAD_REQUEST to the MCP */
4295 bxe_send_unload_req(sc, unload_mode);
4298 * Prevent transactions to host from the functions on the
4299 * engine that doesn't reset global blocks in case of global
4300 * attention once gloabl blocks are reset and gates are opened
4301 * (the engine which leader will perform the recovery
4304 if (!CHIP_IS_E1x(sc)) {
4308 /* disable HW interrupts */
4309 bxe_int_disable_sync(sc, TRUE);
4311 /* detach interrupts */
4312 bxe_interrupt_detach(sc);
4314 /* Report UNLOAD_DONE to MCP */
4315 bxe_send_unload_done(sc, FALSE);
4319 * At this stage no more interrupts will arrive so we may safely clean
4320 * the queue'able objects here in case they failed to get cleaned so far.
4323 bxe_squeeze_objects(sc);
4326 /* There should be no more pending SP commands at this stage */
4331 bxe_free_fp_buffers(sc);
4337 bxe_free_fw_stats_mem(sc);
4339 sc->state = BXE_STATE_CLOSED;
4342 * Check if there are pending parity attentions. If there are - set
4343 * RECOVERY_IN_PROGRESS.
4345 if (IS_PF(sc) && bxe_chk_parity_attn(sc, &global, FALSE)) {
4346 bxe_set_reset_in_progress(sc);
4348 /* Set RESET_IS_GLOBAL if needed */
4350 bxe_set_reset_global(sc);
4355 * The last driver must disable a "close the gate" if there is no
4356 * parity attention or "process kill" pending.
4358 if (IS_PF(sc) && !bxe_clear_pf_load(sc) &&
4359 bxe_reset_is_done(sc, SC_PATH(sc))) {
4360 bxe_disable_close_the_gate(sc);
4363 BLOGD(sc, DBG_LOAD, "Ended NIC unload\n");
4369 * Called by the OS to set various media options (i.e. link, speed, etc.) when
4370 * the user runs "ifconfig bxe media ..." or "ifconfig bxe mediaopt ...".
4373 bxe_ifmedia_update(struct ifnet *ifp)
4375 struct bxe_softc *sc = (struct bxe_softc *)ifp->if_softc;
4376 struct ifmedia *ifm;
4380 /* We only support Ethernet media type. */
4381 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) {
4385 switch (IFM_SUBTYPE(ifm->ifm_media)) {
4391 case IFM_10G_TWINAX:
4393 /* We don't support changing the media type. */
4394 BLOGD(sc, DBG_LOAD, "Invalid media type (%d)\n",
4395 IFM_SUBTYPE(ifm->ifm_media));
4403 * Called by the OS to get the current media status (i.e. link, speed, etc.).
4406 bxe_ifmedia_status(struct ifnet *ifp, struct ifmediareq *ifmr)
4408 struct bxe_softc *sc = ifp->if_softc;
4410 /* Report link down if the driver isn't running. */
4411 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
4412 ifmr->ifm_active |= IFM_NONE;
4416 /* Setup the default interface info. */
4417 ifmr->ifm_status = IFM_AVALID;
4418 ifmr->ifm_active = IFM_ETHER;
4420 if (sc->link_vars.link_up) {
4421 ifmr->ifm_status |= IFM_ACTIVE;
4423 ifmr->ifm_active |= IFM_NONE;
4427 ifmr->ifm_active |= sc->media;
4429 if (sc->link_vars.duplex == DUPLEX_FULL) {
4430 ifmr->ifm_active |= IFM_FDX;
4432 ifmr->ifm_active |= IFM_HDX;
4437 bxe_ioctl_nvram(struct bxe_softc *sc,
4441 struct bxe_nvram_data nvdata_base;
4442 struct bxe_nvram_data *nvdata;
4446 copyin(ifr->ifr_data, &nvdata_base, sizeof(nvdata_base));
4448 len = (sizeof(struct bxe_nvram_data) +
4452 if (len > sizeof(struct bxe_nvram_data)) {
4453 if ((nvdata = (struct bxe_nvram_data *)
4454 malloc(len, M_DEVBUF,
4455 (M_NOWAIT | M_ZERO))) == NULL) {
4456 BLOGE(sc, "BXE_IOC_RD_NVRAM malloc failed priv_op 0x%x "
4457 " len = 0x%x\n", priv_op, len);
4460 memcpy(nvdata, &nvdata_base, sizeof(struct bxe_nvram_data));
4462 nvdata = &nvdata_base;
4465 if (priv_op == BXE_IOC_RD_NVRAM) {
4466 BLOGD(sc, DBG_IOCTL, "IOC_RD_NVRAM 0x%x %d\n",
4467 nvdata->offset, nvdata->len);
4468 error = bxe_nvram_read(sc,
4470 (uint8_t *)nvdata->value,
4472 copyout(nvdata, ifr->ifr_data, len);
4473 } else { /* BXE_IOC_WR_NVRAM */
4474 BLOGD(sc, DBG_IOCTL, "IOC_WR_NVRAM 0x%x %d\n",
4475 nvdata->offset, nvdata->len);
4476 copyin(ifr->ifr_data, nvdata, len);
4477 error = bxe_nvram_write(sc,
4479 (uint8_t *)nvdata->value,
4483 if (len > sizeof(struct bxe_nvram_data)) {
4484 free(nvdata, M_DEVBUF);
4491 bxe_ioctl_stats_show(struct bxe_softc *sc,
4495 const size_t str_size = (BXE_NUM_ETH_STATS * STAT_NAME_LEN);
4496 const size_t stats_size = (BXE_NUM_ETH_STATS * sizeof(uint64_t));
4503 case BXE_IOC_STATS_SHOW_NUM:
4504 memset(ifr->ifr_data, 0, sizeof(union bxe_stats_show_data));
4505 ((union bxe_stats_show_data *)ifr->ifr_data)->desc.num =
4507 ((union bxe_stats_show_data *)ifr->ifr_data)->desc.len =
4511 case BXE_IOC_STATS_SHOW_STR:
4512 memset(ifr->ifr_data, 0, str_size);
4513 p_tmp = ifr->ifr_data;
4514 for (i = 0; i < BXE_NUM_ETH_STATS; i++) {
4515 strcpy(p_tmp, bxe_eth_stats_arr[i].string);
4516 p_tmp += STAT_NAME_LEN;
4520 case BXE_IOC_STATS_SHOW_CNT:
4521 memset(ifr->ifr_data, 0, stats_size);
4522 p_tmp = ifr->ifr_data;
4523 for (i = 0; i < BXE_NUM_ETH_STATS; i++) {
4524 offset = ((uint32_t *)&sc->eth_stats +
4525 bxe_eth_stats_arr[i].offset);
4526 switch (bxe_eth_stats_arr[i].size) {
4528 *((uint64_t *)p_tmp) = (uint64_t)*offset;
4531 *((uint64_t *)p_tmp) = HILO_U64(*offset, *(offset + 1));
4534 *((uint64_t *)p_tmp) = 0;
4536 p_tmp += sizeof(uint64_t);
4546 bxe_handle_chip_tq(void *context,
4549 struct bxe_softc *sc = (struct bxe_softc *)context;
4550 long work = atomic_load_acq_long(&sc->chip_tq_flags);
4554 case CHIP_TQ_REINIT:
4555 if (sc->ifnet->if_drv_flags & IFF_DRV_RUNNING) {
4556 /* restart the interface */
4557 BLOGD(sc, DBG_LOAD, "Restarting the interface...\n");
4558 bxe_periodic_stop(sc);
4560 bxe_stop_locked(sc);
4561 bxe_init_locked(sc);
4562 BXE_CORE_UNLOCK(sc);
4572 * Handles any IOCTL calls from the operating system.
4575 * 0 = Success, >0 Failure
4578 bxe_ioctl(struct ifnet *ifp,
4582 struct bxe_softc *sc = ifp->if_softc;
4583 struct ifreq *ifr = (struct ifreq *)data;
4584 struct bxe_nvram_data *nvdata;
4590 int mtu_min = (ETH_MIN_PACKET_SIZE - ETH_HLEN);
4591 int mtu_max = (MJUM9BYTES - ETH_OVERHEAD - IP_HEADER_ALIGNMENT_PADDING);
4596 BLOGD(sc, DBG_IOCTL, "Received SIOCSIFMTU ioctl (mtu=%d)\n",
4599 if (sc->mtu == ifr->ifr_mtu) {
4600 /* nothing to change */
4604 if ((ifr->ifr_mtu < mtu_min) || (ifr->ifr_mtu > mtu_max)) {
4605 BLOGE(sc, "Unsupported MTU size %d (range is %d-%d)\n",
4606 ifr->ifr_mtu, mtu_min, mtu_max);
4611 atomic_store_rel_int((volatile unsigned int *)&sc->mtu,
4612 (unsigned long)ifr->ifr_mtu);
4613 atomic_store_rel_long((volatile unsigned long *)&ifp->if_mtu,
4614 (unsigned long)ifr->ifr_mtu);
4620 /* toggle the interface state up or down */
4621 BLOGD(sc, DBG_IOCTL, "Received SIOCSIFFLAGS ioctl\n");
4624 /* check if the interface is up */
4625 if (ifp->if_flags & IFF_UP) {
4626 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
4627 /* set the receive mode flags */
4628 bxe_set_rx_mode(sc);
4630 bxe_init_locked(sc);
4633 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
4634 bxe_periodic_stop(sc);
4635 bxe_stop_locked(sc);
4638 BXE_CORE_UNLOCK(sc);
4644 /* add/delete multicast addresses */
4645 BLOGD(sc, DBG_IOCTL, "Received SIOCADDMULTI/SIOCDELMULTI ioctl\n");
4647 /* check if the interface is up */
4648 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
4649 /* set the receive mode flags */
4651 bxe_set_rx_mode(sc);
4652 BXE_CORE_UNLOCK(sc);
4658 /* find out which capabilities have changed */
4659 mask = (ifr->ifr_reqcap ^ ifp->if_capenable);
4661 BLOGD(sc, DBG_IOCTL, "Received SIOCSIFCAP ioctl (mask=0x%08x)\n",
4664 /* toggle the LRO capabilites enable flag */
4665 if (mask & IFCAP_LRO) {
4666 ifp->if_capenable ^= IFCAP_LRO;
4667 BLOGD(sc, DBG_IOCTL, "Turning LRO %s\n",
4668 (ifp->if_capenable & IFCAP_LRO) ? "ON" : "OFF");
4672 /* toggle the TXCSUM checksum capabilites enable flag */
4673 if (mask & IFCAP_TXCSUM) {
4674 ifp->if_capenable ^= IFCAP_TXCSUM;
4675 BLOGD(sc, DBG_IOCTL, "Turning TXCSUM %s\n",
4676 (ifp->if_capenable & IFCAP_TXCSUM) ? "ON" : "OFF");
4677 if (ifp->if_capenable & IFCAP_TXCSUM) {
4678 ifp->if_hwassist = (CSUM_IP |
4685 ifp->if_hwassist = 0;
4689 /* toggle the RXCSUM checksum capabilities enable flag */
4690 if (mask & IFCAP_RXCSUM) {
4691 ifp->if_capenable ^= IFCAP_RXCSUM;
4692 BLOGD(sc, DBG_IOCTL, "Turning RXCSUM %s\n",
4693 (ifp->if_capenable & IFCAP_RXCSUM) ? "ON" : "OFF");
4694 if (ifp->if_capenable & IFCAP_RXCSUM) {
4695 ifp->if_hwassist = (CSUM_IP |
4702 ifp->if_hwassist = 0;
4706 /* toggle TSO4 capabilities enabled flag */
4707 if (mask & IFCAP_TSO4) {
4708 ifp->if_capenable ^= IFCAP_TSO4;
4709 BLOGD(sc, DBG_IOCTL, "Turning TSO4 %s\n",
4710 (ifp->if_capenable & IFCAP_TSO4) ? "ON" : "OFF");
4713 /* toggle TSO6 capabilities enabled flag */
4714 if (mask & IFCAP_TSO6) {
4715 ifp->if_capenable ^= IFCAP_TSO6;
4716 BLOGD(sc, DBG_IOCTL, "Turning TSO6 %s\n",
4717 (ifp->if_capenable & IFCAP_TSO6) ? "ON" : "OFF");
4720 /* toggle VLAN_HWTSO capabilities enabled flag */
4721 if (mask & IFCAP_VLAN_HWTSO) {
4722 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
4723 BLOGD(sc, DBG_IOCTL, "Turning VLAN_HWTSO %s\n",
4724 (ifp->if_capenable & IFCAP_VLAN_HWTSO) ? "ON" : "OFF");
4727 /* toggle VLAN_HWCSUM capabilities enabled flag */
4728 if (mask & IFCAP_VLAN_HWCSUM) {
4729 /* XXX investigate this... */
4730 BLOGE(sc, "Changing VLAN_HWCSUM is not supported!\n");
4734 /* toggle VLAN_MTU capabilities enable flag */
4735 if (mask & IFCAP_VLAN_MTU) {
4736 /* XXX investigate this... */
4737 BLOGE(sc, "Changing VLAN_MTU is not supported!\n");
4741 /* toggle VLAN_HWTAGGING capabilities enabled flag */
4742 if (mask & IFCAP_VLAN_HWTAGGING) {
4743 /* XXX investigate this... */
4744 BLOGE(sc, "Changing VLAN_HWTAGGING is not supported!\n");
4748 /* toggle VLAN_HWFILTER capabilities enabled flag */
4749 if (mask & IFCAP_VLAN_HWFILTER) {
4750 /* XXX investigate this... */
4751 BLOGE(sc, "Changing VLAN_HWFILTER is not supported!\n");
4763 /* set/get interface media */
4764 BLOGD(sc, DBG_IOCTL,
4765 "Received SIOCSIFMEDIA/SIOCGIFMEDIA ioctl (cmd=%lu)\n",
4767 error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, command);
4770 case SIOCGPRIVATE_0:
4771 copyin(ifr->ifr_data, &priv_op, sizeof(priv_op));
4775 case BXE_IOC_RD_NVRAM:
4776 case BXE_IOC_WR_NVRAM:
4777 nvdata = (struct bxe_nvram_data *)ifr->ifr_data;
4778 BLOGD(sc, DBG_IOCTL,
4779 "Received Private NVRAM ioctl addr=0x%x size=%u\n",
4780 nvdata->offset, nvdata->len);
4781 error = bxe_ioctl_nvram(sc, priv_op, ifr);
4784 case BXE_IOC_STATS_SHOW_NUM:
4785 case BXE_IOC_STATS_SHOW_STR:
4786 case BXE_IOC_STATS_SHOW_CNT:
4787 BLOGD(sc, DBG_IOCTL, "Received Private Stats ioctl (%d)\n",
4789 error = bxe_ioctl_stats_show(sc, priv_op, ifr);
4793 BLOGW(sc, "Received Private Unknown ioctl (%d)\n", priv_op);
4801 BLOGD(sc, DBG_IOCTL, "Received Unknown Ioctl (cmd=%lu)\n",
4803 error = ether_ioctl(ifp, command, data);
4807 if (reinit && (sc->ifnet->if_drv_flags & IFF_DRV_RUNNING)) {
4808 BLOGD(sc, DBG_LOAD | DBG_IOCTL,
4809 "Re-initializing hardware from IOCTL change\n");
4810 bxe_periodic_stop(sc);
4812 bxe_stop_locked(sc);
4813 bxe_init_locked(sc);
4814 BXE_CORE_UNLOCK(sc);
4820 static __noinline void
4821 bxe_dump_mbuf(struct bxe_softc *sc,
4828 if (!(sc->debug & DBG_MBUF)) {
4833 BLOGD(sc, DBG_MBUF, "mbuf: null pointer\n");
4839 "%02d: mbuf=%p m_len=%d m_flags=0x%b m_data=%p\n",
4840 i, m, m->m_len, m->m_flags,
4841 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY", m->m_data);
4843 if (m->m_flags & M_PKTHDR) {
4845 "%02d: - m_pkthdr: tot_len=%d flags=0x%b csum_flags=%b\n",
4846 i, m->m_pkthdr.len, m->m_flags,
4847 "\20\12M_BCAST\13M_MCAST\14M_FRAG"
4848 "\15M_FIRSTFRAG\16M_LASTFRAG\21M_VLANTAG"
4849 "\22M_PROMISC\23M_NOFREE",
4850 (int)m->m_pkthdr.csum_flags,
4851 "\20\1CSUM_IP\2CSUM_TCP\3CSUM_UDP\4CSUM_IP_FRAGS"
4852 "\5CSUM_FRAGMENT\6CSUM_TSO\11CSUM_IP_CHECKED"
4853 "\12CSUM_IP_VALID\13CSUM_DATA_VALID"
4854 "\14CSUM_PSEUDO_HDR");
4857 if (m->m_flags & M_EXT) {
4858 switch (m->m_ext.ext_type) {
4859 case EXT_CLUSTER: type = "EXT_CLUSTER"; break;
4860 case EXT_SFBUF: type = "EXT_SFBUF"; break;
4861 case EXT_JUMBOP: type = "EXT_JUMBOP"; break;
4862 case EXT_JUMBO9: type = "EXT_JUMBO9"; break;
4863 case EXT_JUMBO16: type = "EXT_JUMBO16"; break;
4864 case EXT_PACKET: type = "EXT_PACKET"; break;
4865 case EXT_MBUF: type = "EXT_MBUF"; break;
4866 case EXT_NET_DRV: type = "EXT_NET_DRV"; break;
4867 case EXT_MOD_TYPE: type = "EXT_MOD_TYPE"; break;
4868 case EXT_DISPOSABLE: type = "EXT_DISPOSABLE"; break;
4869 case EXT_EXTREF: type = "EXT_EXTREF"; break;
4870 default: type = "UNKNOWN"; break;
4874 "%02d: - m_ext: %p ext_size=%d type=%s\n",
4875 i, m->m_ext.ext_buf, m->m_ext.ext_size, type);
4879 bxe_dump_mbuf_data(sc, "mbuf data", m, TRUE);
4888 * Checks to ensure the 13 bd sliding window is >= MSS for TSO.
4889 * Check that (13 total bds - 3 bds) = 10 bd window >= MSS.
4890 * The window: 3 bds are = 1 for headers BD + 2 for parse BD and last BD
4891 * The headers comes in a seperate bd in FreeBSD so 13-3=10.
4892 * Returns: 0 if OK to send, 1 if packet needs further defragmentation
4895 bxe_chktso_window(struct bxe_softc *sc,
4897 bus_dma_segment_t *segs,
4900 uint32_t num_wnds, wnd_size, wnd_sum;
4901 int32_t frag_idx, wnd_idx;
4902 unsigned short lso_mss;
4908 num_wnds = nsegs - wnd_size;
4909 lso_mss = htole16(m->m_pkthdr.tso_segsz);
4912 * Total header lengths Eth+IP+TCP in first FreeBSD mbuf so calculate the
4913 * first window sum of data while skipping the first assuming it is the
4914 * header in FreeBSD.
4916 for (frag_idx = 1; (frag_idx <= wnd_size); frag_idx++) {
4917 wnd_sum += htole16(segs[frag_idx].ds_len);
4920 /* check the first 10 bd window size */
4921 if (wnd_sum < lso_mss) {
4925 /* run through the windows */
4926 for (wnd_idx = 0; wnd_idx < num_wnds; wnd_idx++, frag_idx++) {
4927 /* subtract the first mbuf->m_len of the last wndw(-header) */
4928 wnd_sum -= htole16(segs[wnd_idx+1].ds_len);
4929 /* add the next mbuf len to the len of our new window */
4930 wnd_sum += htole16(segs[frag_idx].ds_len);
4931 if (wnd_sum < lso_mss) {
4940 bxe_set_pbd_csum_e2(struct bxe_fastpath *fp,
4942 uint32_t *parsing_data)
4944 struct ether_vlan_header *eh = NULL;
4945 struct ip *ip4 = NULL;
4946 struct ip6_hdr *ip6 = NULL;
4948 struct tcphdr *th = NULL;
4949 int e_hlen, ip_hlen, l4_off;
4952 if (m->m_pkthdr.csum_flags == CSUM_IP) {
4953 /* no L4 checksum offload needed */
4957 /* get the Ethernet header */
4958 eh = mtod(m, struct ether_vlan_header *);
4960 /* handle VLAN encapsulation if present */
4961 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
4962 e_hlen = (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN);
4963 proto = ntohs(eh->evl_proto);
4965 e_hlen = ETHER_HDR_LEN;
4966 proto = ntohs(eh->evl_encap_proto);
4971 /* get the IP header, if mbuf len < 20 then header in next mbuf */
4972 ip4 = (m->m_len < sizeof(struct ip)) ?
4973 (struct ip *)m->m_next->m_data :
4974 (struct ip *)(m->m_data + e_hlen);
4975 /* ip_hl is number of 32-bit words */
4976 ip_hlen = (ip4->ip_hl << 2);
4979 case ETHERTYPE_IPV6:
4980 /* get the IPv6 header, if mbuf len < 40 then header in next mbuf */
4981 ip6 = (m->m_len < sizeof(struct ip6_hdr)) ?
4982 (struct ip6_hdr *)m->m_next->m_data :
4983 (struct ip6_hdr *)(m->m_data + e_hlen);
4984 /* XXX cannot support offload with IPv6 extensions */
4985 ip_hlen = sizeof(struct ip6_hdr);
4989 /* We can't offload in this case... */
4990 /* XXX error stat ??? */
4994 /* XXX assuming L4 header is contiguous to IPv4/IPv6 in the same mbuf */
4995 l4_off = (e_hlen + ip_hlen);
4998 (((l4_off >> 1) << ETH_TX_PARSE_BD_E2_L4_HDR_START_OFFSET_W_SHIFT) &
4999 ETH_TX_PARSE_BD_E2_L4_HDR_START_OFFSET_W);
5001 if (m->m_pkthdr.csum_flags & (CSUM_TCP |
5004 fp->eth_q_stats.tx_ofld_frames_csum_tcp++;
5005 th = (struct tcphdr *)(ip + ip_hlen);
5006 /* th_off is number of 32-bit words */
5007 *parsing_data |= ((th->th_off <<
5008 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW_SHIFT) &
5009 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW);
5010 return (l4_off + (th->th_off << 2)); /* entire header length */
5011 } else if (m->m_pkthdr.csum_flags & (CSUM_UDP |
5013 fp->eth_q_stats.tx_ofld_frames_csum_udp++;
5014 return (l4_off + sizeof(struct udphdr)); /* entire header length */
5016 /* XXX error stat ??? */
5022 bxe_set_pbd_csum(struct bxe_fastpath *fp,
5024 struct eth_tx_parse_bd_e1x *pbd)
5026 struct ether_vlan_header *eh = NULL;
5027 struct ip *ip4 = NULL;
5028 struct ip6_hdr *ip6 = NULL;
5030 struct tcphdr *th = NULL;
5031 struct udphdr *uh = NULL;
5032 int e_hlen, ip_hlen;
5038 /* get the Ethernet header */
5039 eh = mtod(m, struct ether_vlan_header *);
5041 /* handle VLAN encapsulation if present */
5042 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
5043 e_hlen = (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN);
5044 proto = ntohs(eh->evl_proto);
5046 e_hlen = ETHER_HDR_LEN;
5047 proto = ntohs(eh->evl_encap_proto);
5052 /* get the IP header, if mbuf len < 20 then header in next mbuf */
5053 ip4 = (m->m_len < sizeof(struct ip)) ?
5054 (struct ip *)m->m_next->m_data :
5055 (struct ip *)(m->m_data + e_hlen);
5056 /* ip_hl is number of 32-bit words */
5057 ip_hlen = (ip4->ip_hl << 1);
5060 case ETHERTYPE_IPV6:
5061 /* get the IPv6 header, if mbuf len < 40 then header in next mbuf */
5062 ip6 = (m->m_len < sizeof(struct ip6_hdr)) ?
5063 (struct ip6_hdr *)m->m_next->m_data :
5064 (struct ip6_hdr *)(m->m_data + e_hlen);
5065 /* XXX cannot support offload with IPv6 extensions */
5066 ip_hlen = (sizeof(struct ip6_hdr) >> 1);
5070 /* We can't offload in this case... */
5071 /* XXX error stat ??? */
5075 hlen = (e_hlen >> 1);
5077 /* note that rest of global_data is indirectly zeroed here */
5078 if (m->m_flags & M_VLANTAG) {
5080 htole16(hlen | (1 << ETH_TX_PARSE_BD_E1X_LLC_SNAP_EN_SHIFT));
5082 pbd->global_data = htole16(hlen);
5085 pbd->ip_hlen_w = ip_hlen;
5087 hlen += pbd->ip_hlen_w;
5089 /* XXX assuming L4 header is contiguous to IPv4/IPv6 in the same mbuf */
5091 if (m->m_pkthdr.csum_flags & (CSUM_TCP |
5094 th = (struct tcphdr *)(ip + (ip_hlen << 1));
5095 /* th_off is number of 32-bit words */
5096 hlen += (uint16_t)(th->th_off << 1);
5097 } else if (m->m_pkthdr.csum_flags & (CSUM_UDP |
5099 uh = (struct udphdr *)(ip + (ip_hlen << 1));
5100 hlen += (sizeof(struct udphdr) / 2);
5102 /* valid case as only CSUM_IP was set */
5106 pbd->total_hlen_w = htole16(hlen);
5108 if (m->m_pkthdr.csum_flags & (CSUM_TCP |
5111 fp->eth_q_stats.tx_ofld_frames_csum_tcp++;
5112 pbd->tcp_pseudo_csum = ntohs(th->th_sum);
5113 } else if (m->m_pkthdr.csum_flags & (CSUM_UDP |
5115 fp->eth_q_stats.tx_ofld_frames_csum_udp++;
5118 * Everest1 (i.e. 57710, 57711, 57711E) does not natively support UDP
5119 * checksums and does not know anything about the UDP header and where
5120 * the checksum field is located. It only knows about TCP. Therefore
5121 * we "lie" to the hardware for outgoing UDP packets w/ checksum
5122 * offload. Since the checksum field offset for TCP is 16 bytes and
5123 * for UDP it is 6 bytes we pass a pointer to the hardware that is 10
5124 * bytes less than the start of the UDP header. This allows the
5125 * hardware to write the checksum in the correct spot. But the
5126 * hardware will compute a checksum which includes the last 10 bytes
5127 * of the IP header. To correct this we tweak the stack computed
5128 * pseudo checksum by folding in the calculation of the inverse
5129 * checksum for those final 10 bytes of the IP header. This allows
5130 * the correct checksum to be computed by the hardware.
5133 /* set pointer 10 bytes before UDP header */
5134 tmp_uh = (uint32_t *)((uint8_t *)uh - 10);
5136 /* calculate a pseudo header checksum over the first 10 bytes */
5137 tmp_csum = in_pseudo(*tmp_uh,
5139 *(uint16_t *)(tmp_uh + 2));
5141 pbd->tcp_pseudo_csum = ntohs(in_addword(uh->uh_sum, ~tmp_csum));
5144 return (hlen * 2); /* entire header length, number of bytes */
5148 bxe_set_pbd_lso_e2(struct mbuf *m,
5149 uint32_t *parsing_data)
5151 *parsing_data |= ((m->m_pkthdr.tso_segsz <<
5152 ETH_TX_PARSE_BD_E2_LSO_MSS_SHIFT) &
5153 ETH_TX_PARSE_BD_E2_LSO_MSS);
5155 /* XXX test for IPv6 with extension header... */
5159 bxe_set_pbd_lso(struct mbuf *m,
5160 struct eth_tx_parse_bd_e1x *pbd)
5162 struct ether_vlan_header *eh = NULL;
5163 struct ip *ip = NULL;
5164 struct tcphdr *th = NULL;
5167 /* get the Ethernet header */
5168 eh = mtod(m, struct ether_vlan_header *);
5170 /* handle VLAN encapsulation if present */
5171 e_hlen = (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) ?
5172 (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN) : ETHER_HDR_LEN;
5174 /* get the IP and TCP header, with LSO entire header in first mbuf */
5175 /* XXX assuming IPv4 */
5176 ip = (struct ip *)(m->m_data + e_hlen);
5177 th = (struct tcphdr *)((caddr_t)ip + (ip->ip_hl << 2));
5179 pbd->lso_mss = htole16(m->m_pkthdr.tso_segsz);
5180 pbd->tcp_send_seq = ntohl(th->th_seq);
5181 pbd->tcp_flags = ((ntohl(((uint32_t *)th)[3]) >> 16) & 0xff);
5185 pbd->ip_id = ntohs(ip->ip_id);
5186 pbd->tcp_pseudo_csum =
5187 ntohs(in_pseudo(ip->ip_src.s_addr,
5189 htons(IPPROTO_TCP)));
5192 pbd->tcp_pseudo_csum =
5193 ntohs(in_pseudo(&ip6->ip6_src,
5195 htons(IPPROTO_TCP)));
5199 htole16(ETH_TX_PARSE_BD_E1X_PSEUDO_CS_WITHOUT_LEN);
5203 * Encapsulte an mbuf cluster into the tx bd chain and makes the memory
5204 * visible to the controller.
5206 * If an mbuf is submitted to this routine and cannot be given to the
5207 * controller (e.g. it has too many fragments) then the function may free
5208 * the mbuf and return to the caller.
5211 * 0 = Success, !0 = Failure
5212 * Note the side effect that an mbuf may be freed if it causes a problem.
5215 bxe_tx_encap(struct bxe_fastpath *fp, struct mbuf **m_head)
5217 bus_dma_segment_t segs[32];
5219 struct bxe_sw_tx_bd *tx_buf;
5220 struct eth_tx_parse_bd_e1x *pbd_e1x = NULL;
5221 struct eth_tx_parse_bd_e2 *pbd_e2 = NULL;
5222 /* struct eth_tx_parse_2nd_bd *pbd2 = NULL; */
5223 struct eth_tx_bd *tx_data_bd;
5224 struct eth_tx_bd *tx_total_pkt_size_bd;
5225 struct eth_tx_start_bd *tx_start_bd;
5226 uint16_t bd_prod, pkt_prod, total_pkt_size;
5228 int defragged, error, nsegs, rc, nbds, vlan_off, ovlan;
5229 struct bxe_softc *sc;
5230 uint16_t tx_bd_avail;
5231 struct ether_vlan_header *eh;
5232 uint32_t pbd_e2_parsing_data = 0;
5239 M_ASSERTPKTHDR(*m_head);
5242 rc = defragged = nbds = ovlan = vlan_off = total_pkt_size = 0;
5245 tx_total_pkt_size_bd = NULL;
5247 /* get the H/W pointer for packets and BDs */
5248 pkt_prod = fp->tx_pkt_prod;
5249 bd_prod = fp->tx_bd_prod;
5251 mac_type = UNICAST_ADDRESS;
5253 /* map the mbuf into the next open DMAable memory */
5254 tx_buf = &fp->tx_mbuf_chain[TX_BD(pkt_prod)];
5255 error = bus_dmamap_load_mbuf_sg(fp->tx_mbuf_tag,
5257 segs, &nsegs, BUS_DMA_NOWAIT);
5259 /* mapping errors */
5260 if(__predict_false(error != 0)) {
5261 fp->eth_q_stats.tx_dma_mapping_failure++;
5262 if (error == ENOMEM) {
5263 /* resource issue, try again later */
5265 } else if (error == EFBIG) {
5266 /* possibly recoverable with defragmentation */
5267 fp->eth_q_stats.mbuf_defrag_attempts++;
5268 m0 = m_defrag(*m_head, M_DONTWAIT);
5270 fp->eth_q_stats.mbuf_defrag_failures++;
5273 /* defrag successful, try mapping again */
5275 error = bus_dmamap_load_mbuf_sg(fp->tx_mbuf_tag,
5277 segs, &nsegs, BUS_DMA_NOWAIT);
5279 fp->eth_q_stats.tx_dma_mapping_failure++;
5284 /* unknown, unrecoverable mapping error */
5285 BLOGE(sc, "Unknown TX mapping error rc=%d\n", error);
5286 bxe_dump_mbuf(sc, m0, FALSE);
5290 goto bxe_tx_encap_continue;
5293 tx_bd_avail = bxe_tx_avail(sc, fp);
5295 /* make sure there is enough room in the send queue */
5296 if (__predict_false(tx_bd_avail < (nsegs + 2))) {
5297 /* Recoverable, try again later. */
5298 fp->eth_q_stats.tx_hw_queue_full++;
5299 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
5301 goto bxe_tx_encap_continue;
5304 /* capture the current H/W TX chain high watermark */
5305 if (__predict_false(fp->eth_q_stats.tx_hw_max_queue_depth <
5306 (TX_BD_USABLE - tx_bd_avail))) {
5307 fp->eth_q_stats.tx_hw_max_queue_depth = (TX_BD_USABLE - tx_bd_avail);
5310 /* make sure it fits in the packet window */
5311 if (__predict_false(nsegs > BXE_MAX_SEGMENTS)) {
5313 * The mbuf may be to big for the controller to handle. If the frame
5314 * is a TSO frame we'll need to do an additional check.
5316 if (m0->m_pkthdr.csum_flags & CSUM_TSO) {
5317 if (bxe_chktso_window(sc, nsegs, segs, m0) == 0) {
5318 goto bxe_tx_encap_continue; /* OK to send */
5320 fp->eth_q_stats.tx_window_violation_tso++;
5323 fp->eth_q_stats.tx_window_violation_std++;
5326 /* lets try to defragment this mbuf and remap it */
5327 fp->eth_q_stats.mbuf_defrag_attempts++;
5328 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
5330 m0 = m_defrag(*m_head, M_DONTWAIT);
5332 fp->eth_q_stats.mbuf_defrag_failures++;
5333 /* Ugh, just drop the frame... :( */
5336 /* defrag successful, try mapping again */
5338 error = bus_dmamap_load_mbuf_sg(fp->tx_mbuf_tag,
5340 segs, &nsegs, BUS_DMA_NOWAIT);
5342 fp->eth_q_stats.tx_dma_mapping_failure++;
5343 /* No sense in trying to defrag/copy chain, drop it. :( */
5347 /* if the chain is still too long then drop it */
5348 if (__predict_false(nsegs > BXE_MAX_SEGMENTS)) {
5349 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
5356 bxe_tx_encap_continue:
5358 /* Check for errors */
5361 /* recoverable try again later */
5363 fp->eth_q_stats.tx_soft_errors++;
5364 fp->eth_q_stats.mbuf_alloc_tx--;
5372 /* set flag according to packet type (UNICAST_ADDRESS is default) */
5373 if (m0->m_flags & M_BCAST) {
5374 mac_type = BROADCAST_ADDRESS;
5375 } else if (m0->m_flags & M_MCAST) {
5376 mac_type = MULTICAST_ADDRESS;
5379 /* store the mbuf into the mbuf ring */
5381 tx_buf->first_bd = fp->tx_bd_prod;
5384 /* prepare the first transmit (start) BD for the mbuf */
5385 tx_start_bd = &fp->tx_chain[TX_BD(bd_prod)].start_bd;
5388 "sending pkt_prod=%u tx_buf=%p next_idx=%u bd=%u tx_start_bd=%p\n",
5389 pkt_prod, tx_buf, fp->tx_pkt_prod, bd_prod, tx_start_bd);
5391 tx_start_bd->addr_lo = htole32(U64_LO(segs[0].ds_addr));
5392 tx_start_bd->addr_hi = htole32(U64_HI(segs[0].ds_addr));
5393 tx_start_bd->nbytes = htole16(segs[0].ds_len);
5394 total_pkt_size += tx_start_bd->nbytes;
5395 tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
5397 tx_start_bd->general_data = (1 << ETH_TX_START_BD_HDR_NBDS_SHIFT);
5399 /* all frames have at least Start BD + Parsing BD */
5401 tx_start_bd->nbd = htole16(nbds);
5403 if (m0->m_flags & M_VLANTAG) {
5404 tx_start_bd->vlan_or_ethertype = htole16(m0->m_pkthdr.ether_vtag);
5405 tx_start_bd->bd_flags.as_bitfield |=
5406 (X_ETH_OUTBAND_VLAN << ETH_TX_BD_FLAGS_VLAN_MODE_SHIFT);
5408 /* vf tx, start bd must hold the ethertype for fw to enforce it */
5410 /* map ethernet header to find type and header length */
5411 eh = mtod(m0, struct ether_vlan_header *);
5412 tx_start_bd->vlan_or_ethertype = eh->evl_encap_proto;
5414 /* used by FW for packet accounting */
5415 tx_start_bd->vlan_or_ethertype = htole16(fp->tx_pkt_prod);
5420 * add a parsing BD from the chain. The parsing BD is always added
5421 * though it is only used for TSO and chksum
5423 bd_prod = TX_BD_NEXT(bd_prod);
5425 if (m0->m_pkthdr.csum_flags) {
5426 if (m0->m_pkthdr.csum_flags & CSUM_IP) {
5427 fp->eth_q_stats.tx_ofld_frames_csum_ip++;
5428 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_IP_CSUM;
5431 if (m0->m_pkthdr.csum_flags & CSUM_TCP_IPV6) {
5432 tx_start_bd->bd_flags.as_bitfield |= (ETH_TX_BD_FLAGS_IPV6 |
5433 ETH_TX_BD_FLAGS_L4_CSUM);
5434 } else if (m0->m_pkthdr.csum_flags & CSUM_UDP_IPV6) {
5435 tx_start_bd->bd_flags.as_bitfield |= (ETH_TX_BD_FLAGS_IPV6 |
5436 ETH_TX_BD_FLAGS_IS_UDP |
5437 ETH_TX_BD_FLAGS_L4_CSUM);
5438 } else if ((m0->m_pkthdr.csum_flags & CSUM_TCP) ||
5439 (m0->m_pkthdr.csum_flags & CSUM_TSO)) {
5440 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_L4_CSUM;
5441 } else if (m0->m_pkthdr.csum_flags & CSUM_UDP) {
5442 tx_start_bd->bd_flags.as_bitfield |= (ETH_TX_BD_FLAGS_L4_CSUM |
5443 ETH_TX_BD_FLAGS_IS_UDP);
5447 if (!CHIP_IS_E1x(sc)) {
5448 pbd_e2 = &fp->tx_chain[TX_BD(bd_prod)].parse_bd_e2;
5449 memset(pbd_e2, 0, sizeof(struct eth_tx_parse_bd_e2));
5451 if (m0->m_pkthdr.csum_flags) {
5452 hlen = bxe_set_pbd_csum_e2(fp, m0, &pbd_e2_parsing_data);
5455 SET_FLAG(pbd_e2_parsing_data, ETH_TX_PARSE_BD_E2_ETH_ADDR_TYPE,
5458 uint16_t global_data = 0;
5460 pbd_e1x = &fp->tx_chain[TX_BD(bd_prod)].parse_bd_e1x;
5461 memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x));
5463 if (m0->m_pkthdr.csum_flags) {
5464 hlen = bxe_set_pbd_csum(fp, m0, pbd_e1x);
5467 SET_FLAG(global_data,
5468 ETH_TX_PARSE_BD_E1X_ETH_ADDR_TYPE, mac_type);
5469 pbd_e1x->global_data |= htole16(global_data);
5472 /* setup the parsing BD with TSO specific info */
5473 if (m0->m_pkthdr.csum_flags & CSUM_TSO) {
5474 fp->eth_q_stats.tx_ofld_frames_lso++;
5475 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_SW_LSO;
5477 if (__predict_false(tx_start_bd->nbytes > hlen)) {
5478 fp->eth_q_stats.tx_ofld_frames_lso_hdr_splits++;
5480 /* split the first BD into header/data making the fw job easy */
5482 tx_start_bd->nbd = htole16(nbds);
5483 tx_start_bd->nbytes = htole16(hlen);
5485 bd_prod = TX_BD_NEXT(bd_prod);
5487 /* new transmit BD after the tx_parse_bd */
5488 tx_data_bd = &fp->tx_chain[TX_BD(bd_prod)].reg_bd;
5489 tx_data_bd->addr_hi = htole32(U64_HI(segs[0].ds_addr + hlen));
5490 tx_data_bd->addr_lo = htole32(U64_LO(segs[0].ds_addr + hlen));
5491 tx_data_bd->nbytes = htole16(segs[0].ds_len - hlen);
5492 if (tx_total_pkt_size_bd == NULL) {
5493 tx_total_pkt_size_bd = tx_data_bd;
5497 "TSO split header size is %d (%x:%x) nbds %d\n",
5498 le16toh(tx_start_bd->nbytes),
5499 le32toh(tx_start_bd->addr_hi),
5500 le32toh(tx_start_bd->addr_lo),
5504 if (!CHIP_IS_E1x(sc)) {
5505 bxe_set_pbd_lso_e2(m0, &pbd_e2_parsing_data);
5507 bxe_set_pbd_lso(m0, pbd_e1x);
5511 if (pbd_e2_parsing_data) {
5512 pbd_e2->parsing_data = htole32(pbd_e2_parsing_data);
5515 /* prepare remaining BDs, start tx bd contains first seg/frag */
5516 for (i = 1; i < nsegs ; i++) {
5517 bd_prod = TX_BD_NEXT(bd_prod);
5518 tx_data_bd = &fp->tx_chain[TX_BD(bd_prod)].reg_bd;
5519 tx_data_bd->addr_lo = htole32(U64_LO(segs[i].ds_addr));
5520 tx_data_bd->addr_hi = htole32(U64_HI(segs[i].ds_addr));
5521 tx_data_bd->nbytes = htole16(segs[i].ds_len);
5522 if (tx_total_pkt_size_bd == NULL) {
5523 tx_total_pkt_size_bd = tx_data_bd;
5525 total_pkt_size += tx_data_bd->nbytes;
5528 BLOGD(sc, DBG_TX, "last bd %p\n", tx_data_bd);
5530 if (tx_total_pkt_size_bd != NULL) {
5531 tx_total_pkt_size_bd->total_pkt_bytes = total_pkt_size;
5534 if (__predict_false(sc->debug & DBG_TX)) {
5535 tmp_bd = tx_buf->first_bd;
5536 for (i = 0; i < nbds; i++)
5540 "TX Strt: %p bd=%d nbd=%d vlan=0x%x "
5541 "bd_flags=0x%x hdr_nbds=%d\n",
5544 le16toh(tx_start_bd->nbd),
5545 le16toh(tx_start_bd->vlan_or_ethertype),
5546 tx_start_bd->bd_flags.as_bitfield,
5547 (tx_start_bd->general_data & ETH_TX_START_BD_HDR_NBDS));
5548 } else if (i == 1) {
5551 "-> Prse: %p bd=%d global=0x%x ip_hlen_w=%u "
5552 "ip_id=%u lso_mss=%u tcp_flags=0x%x csum=0x%x "
5553 "tcp_seq=%u total_hlen_w=%u\n",
5556 pbd_e1x->global_data,
5561 pbd_e1x->tcp_pseudo_csum,
5562 pbd_e1x->tcp_send_seq,
5563 le16toh(pbd_e1x->total_hlen_w));
5564 } else { /* if (pbd_e2) */
5566 "-> Parse: %p bd=%d dst=%02x:%02x:%02x "
5567 "src=%02x:%02x:%02x parsing_data=0x%x\n",
5570 pbd_e2->data.mac_addr.dst_hi,
5571 pbd_e2->data.mac_addr.dst_mid,
5572 pbd_e2->data.mac_addr.dst_lo,
5573 pbd_e2->data.mac_addr.src_hi,
5574 pbd_e2->data.mac_addr.src_mid,
5575 pbd_e2->data.mac_addr.src_lo,
5576 pbd_e2->parsing_data);
5580 if (i != 1) { /* skip parse db as it doesn't hold data */
5581 tx_data_bd = &fp->tx_chain[TX_BD(tmp_bd)].reg_bd;
5583 "-> Frag: %p bd=%d nbytes=%d hi=0x%x lo: 0x%x\n",
5586 le16toh(tx_data_bd->nbytes),
5587 le32toh(tx_data_bd->addr_hi),
5588 le32toh(tx_data_bd->addr_lo));
5591 tmp_bd = TX_BD_NEXT(tmp_bd);
5595 BLOGD(sc, DBG_TX, "doorbell: nbds=%d bd=%u\n", nbds, bd_prod);
5597 /* update TX BD producer index value for next TX */
5598 bd_prod = TX_BD_NEXT(bd_prod);
5601 * If the chain of tx_bd's describing this frame is adjacent to or spans
5602 * an eth_tx_next_bd element then we need to increment the nbds value.
5604 if (TX_BD_IDX(bd_prod) < nbds) {
5608 /* don't allow reordering of writes for nbd and packets */
5611 fp->tx_db.data.prod += nbds;
5613 /* producer points to the next free tx_bd at this point */
5615 fp->tx_bd_prod = bd_prod;
5617 DOORBELL(sc, fp->index, fp->tx_db.raw);
5619 fp->eth_q_stats.tx_pkts++;
5621 /* Prevent speculative reads from getting ahead of the status block. */
5622 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle,
5623 0, 0, BUS_SPACE_BARRIER_READ);
5625 /* Prevent speculative reads from getting ahead of the doorbell. */
5626 bus_space_barrier(sc->bar[BAR2].tag, sc->bar[BAR2].handle,
5627 0, 0, BUS_SPACE_BARRIER_READ);
5633 bxe_tx_start_locked(struct bxe_softc *sc,
5635 struct bxe_fastpath *fp)
5637 struct mbuf *m = NULL;
5639 uint16_t tx_bd_avail;
5641 BXE_FP_TX_LOCK_ASSERT(fp);
5643 /* keep adding entries while there are frames to send */
5644 while (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) {
5647 * check for any frames to send
5648 * dequeue can still be NULL even if queue is not empty
5650 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
5651 if (__predict_false(m == NULL)) {
5655 /* the mbuf now belongs to us */
5656 fp->eth_q_stats.mbuf_alloc_tx++;
5659 * Put the frame into the transmit ring. If we don't have room,
5660 * place the mbuf back at the head of the TX queue, set the
5661 * OACTIVE flag, and wait for the NIC to drain the chain.
5663 if (__predict_false(bxe_tx_encap(fp, &m))) {
5664 fp->eth_q_stats.tx_encap_failures++;
5666 /* mark the TX queue as full and return the frame */
5667 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
5668 IFQ_DRV_PREPEND(&ifp->if_snd, m);
5669 fp->eth_q_stats.mbuf_alloc_tx--;
5670 fp->eth_q_stats.tx_queue_xoff++;
5673 /* stop looking for more work */
5677 /* the frame was enqueued successfully */
5680 /* send a copy of the frame to any BPF listeners. */
5683 tx_bd_avail = bxe_tx_avail(sc, fp);
5685 /* handle any completions if we're running low */
5686 if (tx_bd_avail < BXE_TX_CLEANUP_THRESHOLD) {
5687 /* bxe_txeof will set IFF_DRV_OACTIVE appropriately */
5689 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
5695 /* all TX packets were dequeued and/or the tx ring is full */
5697 /* reset the TX watchdog timeout timer */
5698 fp->watchdog_timer = BXE_TX_TIMEOUT;
5702 /* Legacy (non-RSS) dispatch routine */
5704 bxe_tx_start(struct ifnet *ifp)
5706 struct bxe_softc *sc;
5707 struct bxe_fastpath *fp;
5711 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
5712 BLOGW(sc, "Interface not running, ignoring transmit request\n");
5716 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
5717 BLOGW(sc, "Interface TX queue is full, ignoring transmit request\n");
5721 if (!sc->link_vars.link_up) {
5722 BLOGW(sc, "Interface link is down, ignoring transmit request\n");
5729 bxe_tx_start_locked(sc, ifp, fp);
5730 BXE_FP_TX_UNLOCK(fp);
5733 #if __FreeBSD_version >= 800000
5736 bxe_tx_mq_start_locked(struct bxe_softc *sc,
5738 struct bxe_fastpath *fp,
5741 struct buf_ring *tx_br = fp->tx_br;
5743 int depth, rc, tx_count;
5744 uint16_t tx_bd_avail;
5748 BXE_FP_TX_LOCK_ASSERT(fp);
5751 BLOGE(sc, "Multiqueue TX and no buf_ring!\n");
5755 if (!sc->link_vars.link_up ||
5756 (ifp->if_drv_flags &
5757 (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != IFF_DRV_RUNNING) {
5758 rc = drbr_enqueue(ifp, tx_br, m);
5759 goto bxe_tx_mq_start_locked_exit;
5762 /* fetch the depth of the driver queue */
5763 depth = drbr_inuse(ifp, tx_br);
5764 if (depth > fp->eth_q_stats.tx_max_drbr_queue_depth) {
5765 fp->eth_q_stats.tx_max_drbr_queue_depth = depth;
5769 /* no new work, check for pending frames */
5770 next = drbr_dequeue(ifp, tx_br);
5771 } else if (drbr_needs_enqueue(ifp, tx_br)) {
5772 /* have both new and pending work, maintain packet order */
5773 rc = drbr_enqueue(ifp, tx_br, m);
5775 fp->eth_q_stats.tx_soft_errors++;
5776 goto bxe_tx_mq_start_locked_exit;
5778 next = drbr_dequeue(ifp, tx_br);
5780 /* new work only and nothing pending */
5784 /* keep adding entries while there are frames to send */
5785 while (next != NULL) {
5787 /* the mbuf now belongs to us */
5788 fp->eth_q_stats.mbuf_alloc_tx++;
5791 * Put the frame into the transmit ring. If we don't have room,
5792 * place the mbuf back at the head of the TX queue, set the
5793 * OACTIVE flag, and wait for the NIC to drain the chain.
5795 rc = bxe_tx_encap(fp, &next);
5796 if (__predict_false(rc != 0)) {
5797 fp->eth_q_stats.tx_encap_failures++;
5799 /* mark the TX queue as full and save the frame */
5800 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
5801 /* XXX this may reorder the frame */
5802 rc = drbr_enqueue(ifp, tx_br, next);
5803 fp->eth_q_stats.mbuf_alloc_tx--;
5804 fp->eth_q_stats.tx_frames_deferred++;
5807 /* stop looking for more work */
5811 /* the transmit frame was enqueued successfully */
5814 /* send a copy of the frame to any BPF listeners */
5815 BPF_MTAP(ifp, next);
5817 tx_bd_avail = bxe_tx_avail(sc, fp);
5819 /* handle any completions if we're running low */
5820 if (tx_bd_avail < BXE_TX_CLEANUP_THRESHOLD) {
5821 /* bxe_txeof will set IFF_DRV_OACTIVE appropriately */
5823 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
5828 next = drbr_dequeue(ifp, tx_br);
5831 /* all TX packets were dequeued and/or the tx ring is full */
5833 /* reset the TX watchdog timeout timer */
5834 fp->watchdog_timer = BXE_TX_TIMEOUT;
5837 bxe_tx_mq_start_locked_exit:
5842 /* Multiqueue (TSS) dispatch routine. */
5844 bxe_tx_mq_start(struct ifnet *ifp,
5847 struct bxe_softc *sc = ifp->if_softc;
5848 struct bxe_fastpath *fp;
5851 fp_index = 0; /* default is the first queue */
5853 /* change the queue if using flow ID */
5854 if ((m->m_flags & M_FLOWID) != 0) {
5855 fp_index = (m->m_pkthdr.flowid % sc->num_queues);
5858 fp = &sc->fp[fp_index];
5860 if (BXE_FP_TX_TRYLOCK(fp)) {
5861 rc = bxe_tx_mq_start_locked(sc, ifp, fp, m);
5862 BXE_FP_TX_UNLOCK(fp);
5864 rc = drbr_enqueue(ifp, fp->tx_br, m);
5870 bxe_mq_flush(struct ifnet *ifp)
5872 struct bxe_softc *sc = ifp->if_softc;
5873 struct bxe_fastpath *fp;
5877 for (i = 0; i < sc->num_queues; i++) {
5880 if (fp->state != BXE_FP_STATE_OPEN) {
5881 BLOGD(sc, DBG_LOAD, "Not clearing fp[%02d] buf_ring (state=%d)\n",
5882 fp->index, fp->state);
5886 if (fp->tx_br != NULL) {
5887 BLOGD(sc, DBG_LOAD, "Clearing fp[%02d] buf_ring\n", fp->index);
5889 while ((m = buf_ring_dequeue_sc(fp->tx_br)) != NULL) {
5892 BXE_FP_TX_UNLOCK(fp);
5899 #endif /* FreeBSD_version >= 800000 */
5902 bxe_cid_ilt_lines(struct bxe_softc *sc)
5905 return ((BXE_FIRST_VF_CID + BXE_VF_CIDS) / ILT_PAGE_CIDS);
5907 return (L2_ILT_LINES(sc));
5911 bxe_ilt_set_info(struct bxe_softc *sc)
5913 struct ilt_client_info *ilt_client;
5914 struct ecore_ilt *ilt = sc->ilt;
5917 ilt->start_line = FUNC_ILT_BASE(SC_FUNC(sc));
5918 BLOGD(sc, DBG_LOAD, "ilt starts at line %d\n", ilt->start_line);
5921 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
5922 ilt_client->client_num = ILT_CLIENT_CDU;
5923 ilt_client->page_size = CDU_ILT_PAGE_SZ;
5924 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
5925 ilt_client->start = line;
5926 line += bxe_cid_ilt_lines(sc);
5928 if (CNIC_SUPPORT(sc)) {
5929 line += CNIC_ILT_LINES;
5932 ilt_client->end = (line - 1);
5935 "ilt client[CDU]: start %d, end %d, "
5936 "psz 0x%x, flags 0x%x, hw psz %d\n",
5937 ilt_client->start, ilt_client->end,
5938 ilt_client->page_size,
5940 ilog2(ilt_client->page_size >> 12));
5943 if (QM_INIT(sc->qm_cid_count)) {
5944 ilt_client = &ilt->clients[ILT_CLIENT_QM];
5945 ilt_client->client_num = ILT_CLIENT_QM;
5946 ilt_client->page_size = QM_ILT_PAGE_SZ;
5947 ilt_client->flags = 0;
5948 ilt_client->start = line;
5950 /* 4 bytes for each cid */
5951 line += DIV_ROUND_UP(sc->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
5954 ilt_client->end = (line - 1);
5957 "ilt client[QM]: start %d, end %d, "
5958 "psz 0x%x, flags 0x%x, hw psz %d\n",
5959 ilt_client->start, ilt_client->end,
5960 ilt_client->page_size, ilt_client->flags,
5961 ilog2(ilt_client->page_size >> 12));
5964 if (CNIC_SUPPORT(sc)) {
5966 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
5967 ilt_client->client_num = ILT_CLIENT_SRC;
5968 ilt_client->page_size = SRC_ILT_PAGE_SZ;
5969 ilt_client->flags = 0;
5970 ilt_client->start = line;
5971 line += SRC_ILT_LINES;
5972 ilt_client->end = (line - 1);
5975 "ilt client[SRC]: start %d, end %d, "
5976 "psz 0x%x, flags 0x%x, hw psz %d\n",
5977 ilt_client->start, ilt_client->end,
5978 ilt_client->page_size, ilt_client->flags,
5979 ilog2(ilt_client->page_size >> 12));
5982 ilt_client = &ilt->clients[ILT_CLIENT_TM];
5983 ilt_client->client_num = ILT_CLIENT_TM;
5984 ilt_client->page_size = TM_ILT_PAGE_SZ;
5985 ilt_client->flags = 0;
5986 ilt_client->start = line;
5987 line += TM_ILT_LINES;
5988 ilt_client->end = (line - 1);
5991 "ilt client[TM]: start %d, end %d, "
5992 "psz 0x%x, flags 0x%x, hw psz %d\n",
5993 ilt_client->start, ilt_client->end,
5994 ilt_client->page_size, ilt_client->flags,
5995 ilog2(ilt_client->page_size >> 12));
5998 KASSERT((line <= ILT_MAX_LINES), ("Invalid number of ILT lines!"));
6002 bxe_set_fp_rx_buf_size(struct bxe_softc *sc)
6005 uint32_t rx_buf_size;
6007 rx_buf_size = (IP_HEADER_ALIGNMENT_PADDING + ETH_OVERHEAD + sc->mtu);
6009 for (i = 0; i < sc->num_queues; i++) {
6010 if(rx_buf_size <= MCLBYTES){
6011 sc->fp[i].rx_buf_size = rx_buf_size;
6012 sc->fp[i].mbuf_alloc_size = MCLBYTES;
6013 }else if (rx_buf_size <= MJUMPAGESIZE){
6014 sc->fp[i].rx_buf_size = rx_buf_size;
6015 sc->fp[i].mbuf_alloc_size = MJUMPAGESIZE;
6016 }else if (rx_buf_size <= (MJUMPAGESIZE + MCLBYTES)){
6017 sc->fp[i].rx_buf_size = MCLBYTES;
6018 sc->fp[i].mbuf_alloc_size = MCLBYTES;
6019 }else if (rx_buf_size <= (2 * MJUMPAGESIZE)){
6020 sc->fp[i].rx_buf_size = MJUMPAGESIZE;
6021 sc->fp[i].mbuf_alloc_size = MJUMPAGESIZE;
6023 sc->fp[i].rx_buf_size = MCLBYTES;
6024 sc->fp[i].mbuf_alloc_size = MCLBYTES;
6030 bxe_alloc_ilt_mem(struct bxe_softc *sc)
6035 (struct ecore_ilt *)malloc(sizeof(struct ecore_ilt),
6037 (M_NOWAIT | M_ZERO))) == NULL) {
6045 bxe_alloc_ilt_lines_mem(struct bxe_softc *sc)
6049 if ((sc->ilt->lines =
6050 (struct ilt_line *)malloc((sizeof(struct ilt_line) * ILT_MAX_LINES),
6052 (M_NOWAIT | M_ZERO))) == NULL) {
6060 bxe_free_ilt_mem(struct bxe_softc *sc)
6062 if (sc->ilt != NULL) {
6063 free(sc->ilt, M_BXE_ILT);
6069 bxe_free_ilt_lines_mem(struct bxe_softc *sc)
6071 if (sc->ilt->lines != NULL) {
6072 free(sc->ilt->lines, M_BXE_ILT);
6073 sc->ilt->lines = NULL;
6078 bxe_free_mem(struct bxe_softc *sc)
6082 for (i = 0; i < L2_ILT_LINES(sc); i++) {
6083 bxe_dma_free(sc, &sc->context[i].vcxt_dma);
6084 sc->context[i].vcxt = NULL;
6085 sc->context[i].size = 0;
6088 ecore_ilt_mem_op(sc, ILT_MEMOP_FREE);
6090 bxe_free_ilt_lines_mem(sc);
6095 bxe_alloc_mem(struct bxe_softc *sc)
6102 * Allocate memory for CDU context:
6103 * This memory is allocated separately and not in the generic ILT
6104 * functions because CDU differs in few aspects:
6105 * 1. There can be multiple entities allocating memory for context -
6106 * regular L2, CNIC, and SRIOV drivers. Each separately controls
6107 * its own ILT lines.
6108 * 2. Since CDU page-size is not a single 4KB page (which is the case
6109 * for the other ILT clients), to be efficient we want to support
6110 * allocation of sub-page-size in the last entry.
6111 * 3. Context pointers are used by the driver to pass to FW / update
6112 * the context (for the other ILT clients the pointers are used just to
6113 * free the memory during unload).
6115 context_size = (sizeof(union cdu_context) * BXE_L2_CID_COUNT(sc));
6116 for (i = 0, allocated = 0; allocated < context_size; i++) {
6117 sc->context[i].size = min(CDU_ILT_PAGE_SZ,
6118 (context_size - allocated));
6120 if (bxe_dma_alloc(sc, sc->context[i].size,
6121 &sc->context[i].vcxt_dma,
6122 "cdu context") != 0) {
6127 sc->context[i].vcxt =
6128 (union cdu_context *)sc->context[i].vcxt_dma.vaddr;
6130 allocated += sc->context[i].size;
6133 bxe_alloc_ilt_lines_mem(sc);
6135 BLOGD(sc, DBG_LOAD, "ilt=%p start_line=%u lines=%p\n",
6136 sc->ilt, sc->ilt->start_line, sc->ilt->lines);
6138 for (i = 0; i < 4; i++) {
6140 "c%d page_size=%u start=%u end=%u num=%u flags=0x%x\n",
6142 sc->ilt->clients[i].page_size,
6143 sc->ilt->clients[i].start,
6144 sc->ilt->clients[i].end,
6145 sc->ilt->clients[i].client_num,
6146 sc->ilt->clients[i].flags);
6149 if (ecore_ilt_mem_op(sc, ILT_MEMOP_ALLOC)) {
6150 BLOGE(sc, "ecore_ilt_mem_op ILT_MEMOP_ALLOC failed\n");
6159 bxe_free_rx_bd_chain(struct bxe_fastpath *fp)
6161 struct bxe_softc *sc;
6166 if (fp->rx_mbuf_tag == NULL) {
6170 /* free all mbufs and unload all maps */
6171 for (i = 0; i < RX_BD_TOTAL; i++) {
6172 if (fp->rx_mbuf_chain[i].m_map != NULL) {
6173 bus_dmamap_sync(fp->rx_mbuf_tag,
6174 fp->rx_mbuf_chain[i].m_map,
6175 BUS_DMASYNC_POSTREAD);
6176 bus_dmamap_unload(fp->rx_mbuf_tag,
6177 fp->rx_mbuf_chain[i].m_map);
6180 if (fp->rx_mbuf_chain[i].m != NULL) {
6181 m_freem(fp->rx_mbuf_chain[i].m);
6182 fp->rx_mbuf_chain[i].m = NULL;
6183 fp->eth_q_stats.mbuf_alloc_rx--;
6189 bxe_free_tpa_pool(struct bxe_fastpath *fp)
6191 struct bxe_softc *sc;
6192 int i, max_agg_queues;
6196 if (fp->rx_mbuf_tag == NULL) {
6200 max_agg_queues = MAX_AGG_QS(sc);
6202 /* release all mbufs and unload all DMA maps in the TPA pool */
6203 for (i = 0; i < max_agg_queues; i++) {
6204 if (fp->rx_tpa_info[i].bd.m_map != NULL) {
6205 bus_dmamap_sync(fp->rx_mbuf_tag,
6206 fp->rx_tpa_info[i].bd.m_map,
6207 BUS_DMASYNC_POSTREAD);
6208 bus_dmamap_unload(fp->rx_mbuf_tag,
6209 fp->rx_tpa_info[i].bd.m_map);
6212 if (fp->rx_tpa_info[i].bd.m != NULL) {
6213 m_freem(fp->rx_tpa_info[i].bd.m);
6214 fp->rx_tpa_info[i].bd.m = NULL;
6215 fp->eth_q_stats.mbuf_alloc_tpa--;
6221 bxe_free_sge_chain(struct bxe_fastpath *fp)
6223 struct bxe_softc *sc;
6228 if (fp->rx_sge_mbuf_tag == NULL) {
6232 /* rree all mbufs and unload all maps */
6233 for (i = 0; i < RX_SGE_TOTAL; i++) {
6234 if (fp->rx_sge_mbuf_chain[i].m_map != NULL) {
6235 bus_dmamap_sync(fp->rx_sge_mbuf_tag,
6236 fp->rx_sge_mbuf_chain[i].m_map,
6237 BUS_DMASYNC_POSTREAD);
6238 bus_dmamap_unload(fp->rx_sge_mbuf_tag,
6239 fp->rx_sge_mbuf_chain[i].m_map);
6242 if (fp->rx_sge_mbuf_chain[i].m != NULL) {
6243 m_freem(fp->rx_sge_mbuf_chain[i].m);
6244 fp->rx_sge_mbuf_chain[i].m = NULL;
6245 fp->eth_q_stats.mbuf_alloc_sge--;
6251 bxe_free_fp_buffers(struct bxe_softc *sc)
6253 struct bxe_fastpath *fp;
6256 for (i = 0; i < sc->num_queues; i++) {
6259 #if __FreeBSD_version >= 800000
6260 if (fp->tx_br != NULL) {
6261 /* just in case bxe_mq_flush() wasn't called */
6262 if (mtx_initialized(&fp->tx_mtx)) {
6266 while ((m = buf_ring_dequeue_sc(fp->tx_br)) != NULL)
6268 BXE_FP_TX_UNLOCK(fp);
6273 /* free all RX buffers */
6274 bxe_free_rx_bd_chain(fp);
6275 bxe_free_tpa_pool(fp);
6276 bxe_free_sge_chain(fp);
6278 if (fp->eth_q_stats.mbuf_alloc_rx != 0) {
6279 BLOGE(sc, "failed to claim all rx mbufs (%d left)\n",
6280 fp->eth_q_stats.mbuf_alloc_rx);
6283 if (fp->eth_q_stats.mbuf_alloc_sge != 0) {
6284 BLOGE(sc, "failed to claim all sge mbufs (%d left)\n",
6285 fp->eth_q_stats.mbuf_alloc_sge);
6288 if (fp->eth_q_stats.mbuf_alloc_tpa != 0) {
6289 BLOGE(sc, "failed to claim all sge mbufs (%d left)\n",
6290 fp->eth_q_stats.mbuf_alloc_tpa);
6293 if (fp->eth_q_stats.mbuf_alloc_tx != 0) {
6294 BLOGE(sc, "failed to release tx mbufs (%d left)\n",
6295 fp->eth_q_stats.mbuf_alloc_tx);
6298 /* XXX verify all mbufs were reclaimed */
6303 bxe_alloc_rx_bd_mbuf(struct bxe_fastpath *fp,
6304 uint16_t prev_index,
6307 struct bxe_sw_rx_bd *rx_buf;
6308 struct eth_rx_bd *rx_bd;
6309 bus_dma_segment_t segs[1];
6316 /* allocate the new RX BD mbuf */
6317 m = m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR, fp->mbuf_alloc_size);
6318 if (__predict_false(m == NULL)) {
6319 fp->eth_q_stats.mbuf_rx_bd_alloc_failed++;
6323 fp->eth_q_stats.mbuf_alloc_rx++;
6325 /* initialize the mbuf buffer length */
6326 m->m_pkthdr.len = m->m_len = fp->rx_buf_size;
6328 /* map the mbuf into non-paged pool */
6329 rc = bus_dmamap_load_mbuf_sg(fp->rx_mbuf_tag,
6330 fp->rx_mbuf_spare_map,
6331 m, segs, &nsegs, BUS_DMA_NOWAIT);
6332 if (__predict_false(rc != 0)) {
6333 fp->eth_q_stats.mbuf_rx_bd_mapping_failed++;
6335 fp->eth_q_stats.mbuf_alloc_rx--;
6339 /* all mbufs must map to a single segment */
6340 KASSERT((nsegs == 1), ("Too many segments, %d returned!", nsegs));
6342 /* release any existing RX BD mbuf mappings */
6344 if (prev_index != index) {
6345 rx_buf = &fp->rx_mbuf_chain[prev_index];
6347 if (rx_buf->m_map != NULL) {
6348 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map,
6349 BUS_DMASYNC_POSTREAD);
6350 bus_dmamap_unload(fp->rx_mbuf_tag, rx_buf->m_map);
6354 * We only get here from bxe_rxeof() when the maximum number
6355 * of rx buffers is less than RX_BD_USABLE. bxe_rxeof() already
6356 * holds the mbuf in the prev_index so it's OK to NULL it out
6357 * here without concern of a memory leak.
6359 fp->rx_mbuf_chain[prev_index].m = NULL;
6362 rx_buf = &fp->rx_mbuf_chain[index];
6364 if (rx_buf->m_map != NULL) {
6365 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map,
6366 BUS_DMASYNC_POSTREAD);
6367 bus_dmamap_unload(fp->rx_mbuf_tag, rx_buf->m_map);
6370 /* save the mbuf and mapping info for a future packet */
6371 map = (prev_index != index) ?
6372 fp->rx_mbuf_chain[prev_index].m_map : rx_buf->m_map;
6373 rx_buf->m_map = fp->rx_mbuf_spare_map;
6374 fp->rx_mbuf_spare_map = map;
6375 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map,
6376 BUS_DMASYNC_PREREAD);
6379 rx_bd = &fp->rx_chain[index];
6380 rx_bd->addr_hi = htole32(U64_HI(segs[0].ds_addr));
6381 rx_bd->addr_lo = htole32(U64_LO(segs[0].ds_addr));
6387 bxe_alloc_rx_tpa_mbuf(struct bxe_fastpath *fp,
6390 struct bxe_sw_tpa_info *tpa_info = &fp->rx_tpa_info[queue];
6391 bus_dma_segment_t segs[1];
6397 /* allocate the new TPA mbuf */
6398 m = m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR, fp->mbuf_alloc_size);
6399 if (__predict_false(m == NULL)) {
6400 fp->eth_q_stats.mbuf_rx_tpa_alloc_failed++;
6404 fp->eth_q_stats.mbuf_alloc_tpa++;
6406 /* initialize the mbuf buffer length */
6407 m->m_pkthdr.len = m->m_len = fp->rx_buf_size;
6409 /* map the mbuf into non-paged pool */
6410 rc = bus_dmamap_load_mbuf_sg(fp->rx_mbuf_tag,
6411 fp->rx_tpa_info_mbuf_spare_map,
6412 m, segs, &nsegs, BUS_DMA_NOWAIT);
6413 if (__predict_false(rc != 0)) {
6414 fp->eth_q_stats.mbuf_rx_tpa_mapping_failed++;
6416 fp->eth_q_stats.mbuf_alloc_tpa--;
6420 /* all mbufs must map to a single segment */
6421 KASSERT((nsegs == 1), ("Too many segments, %d returned!", nsegs));
6423 /* release any existing TPA mbuf mapping */
6424 if (tpa_info->bd.m_map != NULL) {
6425 bus_dmamap_sync(fp->rx_mbuf_tag, tpa_info->bd.m_map,
6426 BUS_DMASYNC_POSTREAD);
6427 bus_dmamap_unload(fp->rx_mbuf_tag, tpa_info->bd.m_map);
6430 /* save the mbuf and mapping info for the TPA mbuf */
6431 map = tpa_info->bd.m_map;
6432 tpa_info->bd.m_map = fp->rx_tpa_info_mbuf_spare_map;
6433 fp->rx_tpa_info_mbuf_spare_map = map;
6434 bus_dmamap_sync(fp->rx_mbuf_tag, tpa_info->bd.m_map,
6435 BUS_DMASYNC_PREREAD);
6437 tpa_info->seg = segs[0];
6443 * Allocate an mbuf and assign it to the receive scatter gather chain. The
6444 * caller must take care to save a copy of the existing mbuf in the SG mbuf
6448 bxe_alloc_rx_sge_mbuf(struct bxe_fastpath *fp,
6451 struct bxe_sw_rx_bd *sge_buf;
6452 struct eth_rx_sge *sge;
6453 bus_dma_segment_t segs[1];
6459 /* allocate a new SGE mbuf */
6460 m = m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR, SGE_PAGE_SIZE);
6461 if (__predict_false(m == NULL)) {
6462 fp->eth_q_stats.mbuf_rx_sge_alloc_failed++;
6466 fp->eth_q_stats.mbuf_alloc_sge++;
6468 /* initialize the mbuf buffer length */
6469 m->m_pkthdr.len = m->m_len = SGE_PAGE_SIZE;
6471 /* map the SGE mbuf into non-paged pool */
6472 rc = bus_dmamap_load_mbuf_sg(fp->rx_sge_mbuf_tag,
6473 fp->rx_sge_mbuf_spare_map,
6474 m, segs, &nsegs, BUS_DMA_NOWAIT);
6475 if (__predict_false(rc != 0)) {
6476 fp->eth_q_stats.mbuf_rx_sge_mapping_failed++;
6478 fp->eth_q_stats.mbuf_alloc_sge--;
6482 /* all mbufs must map to a single segment */
6483 KASSERT((nsegs == 1), ("Too many segments, %d returned!", nsegs));
6485 sge_buf = &fp->rx_sge_mbuf_chain[index];
6487 /* release any existing SGE mbuf mapping */
6488 if (sge_buf->m_map != NULL) {
6489 bus_dmamap_sync(fp->rx_sge_mbuf_tag, sge_buf->m_map,
6490 BUS_DMASYNC_POSTREAD);
6491 bus_dmamap_unload(fp->rx_sge_mbuf_tag, sge_buf->m_map);
6494 /* save the mbuf and mapping info for a future packet */
6495 map = sge_buf->m_map;
6496 sge_buf->m_map = fp->rx_sge_mbuf_spare_map;
6497 fp->rx_sge_mbuf_spare_map = map;
6498 bus_dmamap_sync(fp->rx_sge_mbuf_tag, sge_buf->m_map,
6499 BUS_DMASYNC_PREREAD);
6502 sge = &fp->rx_sge_chain[index];
6503 sge->addr_hi = htole32(U64_HI(segs[0].ds_addr));
6504 sge->addr_lo = htole32(U64_LO(segs[0].ds_addr));
6509 static __noinline int
6510 bxe_alloc_fp_buffers(struct bxe_softc *sc)
6512 struct bxe_fastpath *fp;
6514 int ring_prod, cqe_ring_prod;
6517 for (i = 0; i < sc->num_queues; i++) {
6520 ring_prod = cqe_ring_prod = 0;
6524 /* allocate buffers for the RX BDs in RX BD chain */
6525 for (j = 0; j < sc->max_rx_bufs; j++) {
6526 rc = bxe_alloc_rx_bd_mbuf(fp, ring_prod, ring_prod);
6528 BLOGE(sc, "mbuf alloc fail for fp[%02d] rx chain (%d)\n",
6530 goto bxe_alloc_fp_buffers_error;
6533 ring_prod = RX_BD_NEXT(ring_prod);
6534 cqe_ring_prod = RCQ_NEXT(cqe_ring_prod);
6537 fp->rx_bd_prod = ring_prod;
6538 fp->rx_cq_prod = cqe_ring_prod;
6539 fp->eth_q_stats.rx_calls = fp->eth_q_stats.rx_pkts = 0;
6541 max_agg_queues = MAX_AGG_QS(sc);
6543 fp->tpa_enable = TRUE;
6545 /* fill the TPA pool */
6546 for (j = 0; j < max_agg_queues; j++) {
6547 rc = bxe_alloc_rx_tpa_mbuf(fp, j);
6549 BLOGE(sc, "mbuf alloc fail for fp[%02d] TPA queue %d\n",
6551 fp->tpa_enable = FALSE;
6552 goto bxe_alloc_fp_buffers_error;
6555 fp->rx_tpa_info[j].state = BXE_TPA_STATE_STOP;
6558 if (fp->tpa_enable) {
6559 /* fill the RX SGE chain */
6561 for (j = 0; j < RX_SGE_USABLE; j++) {
6562 rc = bxe_alloc_rx_sge_mbuf(fp, ring_prod);
6564 BLOGE(sc, "mbuf alloc fail for fp[%02d] SGE %d\n",
6566 fp->tpa_enable = FALSE;
6568 goto bxe_alloc_fp_buffers_error;
6571 ring_prod = RX_SGE_NEXT(ring_prod);
6574 fp->rx_sge_prod = ring_prod;
6580 bxe_alloc_fp_buffers_error:
6582 /* unwind what was already allocated */
6583 bxe_free_rx_bd_chain(fp);
6584 bxe_free_tpa_pool(fp);
6585 bxe_free_sge_chain(fp);
6591 bxe_free_fw_stats_mem(struct bxe_softc *sc)
6593 bxe_dma_free(sc, &sc->fw_stats_dma);
6595 sc->fw_stats_num = 0;
6597 sc->fw_stats_req_size = 0;
6598 sc->fw_stats_req = NULL;
6599 sc->fw_stats_req_mapping = 0;
6601 sc->fw_stats_data_size = 0;
6602 sc->fw_stats_data = NULL;
6603 sc->fw_stats_data_mapping = 0;
6607 bxe_alloc_fw_stats_mem(struct bxe_softc *sc)
6609 uint8_t num_queue_stats;
6612 /* number of queues for statistics is number of eth queues */
6613 num_queue_stats = BXE_NUM_ETH_QUEUES(sc);
6616 * Total number of FW statistics requests =
6617 * 1 for port stats + 1 for PF stats + num of queues
6619 sc->fw_stats_num = (2 + num_queue_stats);
6622 * Request is built from stats_query_header and an array of
6623 * stats_query_cmd_group each of which contains STATS_QUERY_CMD_COUNT
6624 * rules. The real number or requests is configured in the
6625 * stats_query_header.
6628 ((sc->fw_stats_num / STATS_QUERY_CMD_COUNT) +
6629 ((sc->fw_stats_num % STATS_QUERY_CMD_COUNT) ? 1 : 0));
6631 BLOGD(sc, DBG_LOAD, "stats fw_stats_num %d num_groups %d\n",
6632 sc->fw_stats_num, num_groups);
6634 sc->fw_stats_req_size =
6635 (sizeof(struct stats_query_header) +
6636 (num_groups * sizeof(struct stats_query_cmd_group)));
6639 * Data for statistics requests + stats_counter.
6640 * stats_counter holds per-STORM counters that are incremented when
6641 * STORM has finished with the current request. Memory for FCoE
6642 * offloaded statistics are counted anyway, even if they will not be sent.
6643 * VF stats are not accounted for here as the data of VF stats is stored
6644 * in memory allocated by the VF, not here.
6646 sc->fw_stats_data_size =
6647 (sizeof(struct stats_counter) +
6648 sizeof(struct per_port_stats) +
6649 sizeof(struct per_pf_stats) +
6650 /* sizeof(struct fcoe_statistics_params) + */
6651 (sizeof(struct per_queue_stats) * num_queue_stats));
6653 if (bxe_dma_alloc(sc, (sc->fw_stats_req_size + sc->fw_stats_data_size),
6654 &sc->fw_stats_dma, "fw stats") != 0) {
6655 bxe_free_fw_stats_mem(sc);
6659 /* set up the shortcuts */
6662 (struct bxe_fw_stats_req *)sc->fw_stats_dma.vaddr;
6663 sc->fw_stats_req_mapping = sc->fw_stats_dma.paddr;
6666 (struct bxe_fw_stats_data *)((uint8_t *)sc->fw_stats_dma.vaddr +
6667 sc->fw_stats_req_size);
6668 sc->fw_stats_data_mapping = (sc->fw_stats_dma.paddr +
6669 sc->fw_stats_req_size);
6671 BLOGD(sc, DBG_LOAD, "statistics request base address set to %#jx\n",
6672 (uintmax_t)sc->fw_stats_req_mapping);
6674 BLOGD(sc, DBG_LOAD, "statistics data base address set to %#jx\n",
6675 (uintmax_t)sc->fw_stats_data_mapping);
6682 * 0-7 - Engine0 load counter.
6683 * 8-15 - Engine1 load counter.
6684 * 16 - Engine0 RESET_IN_PROGRESS bit.
6685 * 17 - Engine1 RESET_IN_PROGRESS bit.
6686 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active
6687 * function on the engine
6688 * 19 - Engine1 ONE_IS_LOADED.
6689 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
6690 * leader to complete (check for both RESET_IN_PROGRESS bits and not
6691 * for just the one belonging to its engine).
6693 #define BXE_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
6694 #define BXE_PATH0_LOAD_CNT_MASK 0x000000ff
6695 #define BXE_PATH0_LOAD_CNT_SHIFT 0
6696 #define BXE_PATH1_LOAD_CNT_MASK 0x0000ff00
6697 #define BXE_PATH1_LOAD_CNT_SHIFT 8
6698 #define BXE_PATH0_RST_IN_PROG_BIT 0x00010000
6699 #define BXE_PATH1_RST_IN_PROG_BIT 0x00020000
6700 #define BXE_GLOBAL_RESET_BIT 0x00040000
6702 /* set the GLOBAL_RESET bit, should be run under rtnl lock */
6704 bxe_set_reset_global(struct bxe_softc *sc)
6707 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6708 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6709 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val | BXE_GLOBAL_RESET_BIT);
6710 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6713 /* clear the GLOBAL_RESET bit, should be run under rtnl lock */
6715 bxe_clear_reset_global(struct bxe_softc *sc)
6718 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6719 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6720 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val & (~BXE_GLOBAL_RESET_BIT));
6721 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6724 /* checks the GLOBAL_RESET bit, should be run under rtnl lock */
6726 bxe_reset_is_global(struct bxe_softc *sc)
6728 uint32_t val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6729 BLOGD(sc, DBG_LOAD, "GLOB_REG=0x%08x\n", val);
6730 return (val & BXE_GLOBAL_RESET_BIT) ? TRUE : FALSE;
6733 /* clear RESET_IN_PROGRESS bit for the engine, should be run under rtnl lock */
6735 bxe_set_reset_done(struct bxe_softc *sc)
6738 uint32_t bit = SC_PATH(sc) ? BXE_PATH1_RST_IN_PROG_BIT :
6739 BXE_PATH0_RST_IN_PROG_BIT;
6741 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6743 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6746 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val);
6748 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6751 /* set RESET_IN_PROGRESS for the engine, should be run under rtnl lock */
6753 bxe_set_reset_in_progress(struct bxe_softc *sc)
6756 uint32_t bit = SC_PATH(sc) ? BXE_PATH1_RST_IN_PROG_BIT :
6757 BXE_PATH0_RST_IN_PROG_BIT;
6759 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6761 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6764 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val);
6766 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6769 /* check RESET_IN_PROGRESS bit for an engine, should be run under rtnl lock */
6771 bxe_reset_is_done(struct bxe_softc *sc,
6774 uint32_t val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6775 uint32_t bit = engine ? BXE_PATH1_RST_IN_PROG_BIT :
6776 BXE_PATH0_RST_IN_PROG_BIT;
6778 /* return false if bit is set */
6779 return (val & bit) ? FALSE : TRUE;
6782 /* get the load status for an engine, should be run under rtnl lock */
6784 bxe_get_load_status(struct bxe_softc *sc,
6787 uint32_t mask = engine ? BXE_PATH1_LOAD_CNT_MASK :
6788 BXE_PATH0_LOAD_CNT_MASK;
6789 uint32_t shift = engine ? BXE_PATH1_LOAD_CNT_SHIFT :
6790 BXE_PATH0_LOAD_CNT_SHIFT;
6791 uint32_t val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6793 BLOGD(sc, DBG_LOAD, "Old value for GLOB_REG=0x%08x\n", val);
6795 val = ((val & mask) >> shift);
6797 BLOGD(sc, DBG_LOAD, "Load mask engine %d = 0x%08x\n", engine, val);
6802 /* set pf load mark */
6803 /* XXX needs to be under rtnl lock */
6805 bxe_set_pf_load(struct bxe_softc *sc)
6809 uint32_t mask = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_MASK :
6810 BXE_PATH0_LOAD_CNT_MASK;
6811 uint32_t shift = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_SHIFT :
6812 BXE_PATH0_LOAD_CNT_SHIFT;
6814 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6816 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6817 BLOGD(sc, DBG_LOAD, "Old value for GLOB_REG=0x%08x\n", val);
6819 /* get the current counter value */
6820 val1 = ((val & mask) >> shift);
6822 /* set bit of this PF */
6823 val1 |= (1 << SC_ABS_FUNC(sc));
6825 /* clear the old value */
6828 /* set the new one */
6829 val |= ((val1 << shift) & mask);
6831 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val);
6833 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6836 /* clear pf load mark */
6837 /* XXX needs to be under rtnl lock */
6839 bxe_clear_pf_load(struct bxe_softc *sc)
6842 uint32_t mask = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_MASK :
6843 BXE_PATH0_LOAD_CNT_MASK;
6844 uint32_t shift = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_SHIFT :
6845 BXE_PATH0_LOAD_CNT_SHIFT;
6847 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6848 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6849 BLOGD(sc, DBG_LOAD, "Old GEN_REG_VAL=0x%08x\n", val);
6851 /* get the current counter value */
6852 val1 = (val & mask) >> shift;
6854 /* clear bit of that PF */
6855 val1 &= ~(1 << SC_ABS_FUNC(sc));
6857 /* clear the old value */
6860 /* set the new one */
6861 val |= ((val1 << shift) & mask);
6863 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val);
6864 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6868 /* send load requrest to mcp and analyze response */
6870 bxe_nic_load_request(struct bxe_softc *sc,
6871 uint32_t *load_code)
6875 (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_mb_header) &
6876 DRV_MSG_SEQ_NUMBER_MASK);
6878 BLOGD(sc, DBG_LOAD, "initial fw_seq 0x%04x\n", sc->fw_seq);
6880 /* get the current FW pulse sequence */
6881 sc->fw_drv_pulse_wr_seq =
6882 (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_pulse_mb) &
6883 DRV_PULSE_SEQ_MASK);
6885 BLOGD(sc, DBG_LOAD, "initial drv_pulse 0x%04x\n",
6886 sc->fw_drv_pulse_wr_seq);
6889 (*load_code) = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_REQ,
6890 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
6892 /* if the MCP fails to respond we must abort */
6893 if (!(*load_code)) {
6894 BLOGE(sc, "MCP response failure!\n");
6898 /* if MCP refused then must abort */
6899 if ((*load_code) == FW_MSG_CODE_DRV_LOAD_REFUSED) {
6900 BLOGE(sc, "MCP refused load request\n");
6908 * Check whether another PF has already loaded FW to chip. In virtualized
6909 * environments a pf from anoth VM may have already initialized the device
6910 * including loading FW.
6913 bxe_nic_load_analyze_req(struct bxe_softc *sc,
6916 uint32_t my_fw, loaded_fw;
6918 /* is another pf loaded on this engine? */
6919 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
6920 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
6921 /* build my FW version dword */
6922 my_fw = (BCM_5710_FW_MAJOR_VERSION +
6923 (BCM_5710_FW_MINOR_VERSION << 8 ) +
6924 (BCM_5710_FW_REVISION_VERSION << 16) +
6925 (BCM_5710_FW_ENGINEERING_VERSION << 24));
6927 /* read loaded FW from chip */
6928 loaded_fw = REG_RD(sc, XSEM_REG_PRAM);
6929 BLOGD(sc, DBG_LOAD, "loaded FW 0x%08x / my FW 0x%08x\n",
6932 /* abort nic load if version mismatch */
6933 if (my_fw != loaded_fw) {
6934 BLOGE(sc, "FW 0x%08x already loaded (mine is 0x%08x)",
6943 /* mark PMF if applicable */
6945 bxe_nic_load_pmf(struct bxe_softc *sc,
6948 uint32_t ncsi_oem_data_addr;
6950 if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) ||
6951 (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) ||
6952 (load_code == FW_MSG_CODE_DRV_LOAD_PORT)) {
6954 * Barrier here for ordering between the writing to sc->port.pmf here
6955 * and reading it from the periodic task.
6963 BLOGD(sc, DBG_LOAD, "pmf %d\n", sc->port.pmf);
6966 if (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) {
6967 if (SHMEM2_HAS(sc, ncsi_oem_data_addr)) {
6968 ncsi_oem_data_addr = SHMEM2_RD(sc, ncsi_oem_data_addr);
6969 if (ncsi_oem_data_addr) {
6971 (ncsi_oem_data_addr +
6972 offsetof(struct glob_ncsi_oem_data, driver_version)),
6980 bxe_read_mf_cfg(struct bxe_softc *sc)
6982 int n = (CHIP_IS_MODE_4_PORT(sc) ? 2 : 1);
6986 if (BXE_NOMCP(sc)) {
6987 return; /* what should be the default bvalue in this case */
6991 * The formula for computing the absolute function number is...
6992 * For 2 port configuration (4 functions per port):
6993 * abs_func = 2 * vn + SC_PORT + SC_PATH
6994 * For 4 port configuration (2 functions per port):
6995 * abs_func = 4 * vn + 2 * SC_PORT + SC_PATH
6997 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
6998 abs_func = (n * (2 * vn + SC_PORT(sc)) + SC_PATH(sc));
6999 if (abs_func >= E1H_FUNC_MAX) {
7002 sc->devinfo.mf_info.mf_config[vn] =
7003 MFCFG_RD(sc, func_mf_config[abs_func].config);
7006 if (sc->devinfo.mf_info.mf_config[SC_VN(sc)] &
7007 FUNC_MF_CFG_FUNC_DISABLED) {
7008 BLOGD(sc, DBG_LOAD, "mf_cfg function disabled\n");
7009 sc->flags |= BXE_MF_FUNC_DIS;
7011 BLOGD(sc, DBG_LOAD, "mf_cfg function enabled\n");
7012 sc->flags &= ~BXE_MF_FUNC_DIS;
7016 /* acquire split MCP access lock register */
7017 static int bxe_acquire_alr(struct bxe_softc *sc)
7021 for (j = 0; j < 1000; j++) {
7023 REG_WR(sc, GRCBASE_MCP + 0x9c, val);
7024 val = REG_RD(sc, GRCBASE_MCP + 0x9c);
7025 if (val & (1L << 31))
7031 if (!(val & (1L << 31))) {
7032 BLOGE(sc, "Cannot acquire MCP access lock register\n");
7039 /* release split MCP access lock register */
7040 static void bxe_release_alr(struct bxe_softc *sc)
7042 REG_WR(sc, GRCBASE_MCP + 0x9c, 0);
7046 bxe_fan_failure(struct bxe_softc *sc)
7048 int port = SC_PORT(sc);
7049 uint32_t ext_phy_config;
7051 /* mark the failure */
7053 SHMEM_RD(sc, dev_info.port_hw_config[port].external_phy_config);
7055 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
7056 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
7057 SHMEM_WR(sc, dev_info.port_hw_config[port].external_phy_config,
7060 /* log the failure */
7061 BLOGW(sc, "Fan Failure has caused the driver to shutdown "
7062 "the card to prevent permanent damage. "
7063 "Please contact OEM Support for assistance\n");
7067 bxe_panic(sc, ("Schedule task to handle fan failure\n"));
7070 * Schedule device reset (unload)
7071 * This is due to some boards consuming sufficient power when driver is
7072 * up to overheat if fan fails.
7074 bxe_set_bit(BXE_SP_RTNL_FAN_FAILURE, &sc->sp_rtnl_state);
7075 schedule_delayed_work(&sc->sp_rtnl_task, 0);
7079 /* this function is called upon a link interrupt */
7081 bxe_link_attn(struct bxe_softc *sc)
7083 uint32_t pause_enabled = 0;
7084 struct host_port_stats *pstats;
7087 /* Make sure that we are synced with the current statistics */
7088 bxe_stats_handle(sc, STATS_EVENT_STOP);
7090 elink_link_update(&sc->link_params, &sc->link_vars);
7092 if (sc->link_vars.link_up) {
7094 /* dropless flow control */
7095 if (!CHIP_IS_E1(sc) && sc->dropless_fc) {
7098 if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_TX) {
7103 (BAR_USTRORM_INTMEM +
7104 USTORM_ETH_PAUSE_ENABLED_OFFSET(SC_PORT(sc))),
7108 if (sc->link_vars.mac_type != ELINK_MAC_TYPE_EMAC) {
7109 pstats = BXE_SP(sc, port_stats);
7110 /* reset old mac stats */
7111 memset(&(pstats->mac_stx[0]), 0, sizeof(struct mac_stx));
7114 if (sc->state == BXE_STATE_OPEN) {
7115 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
7119 if (sc->link_vars.link_up && sc->link_vars.line_speed) {
7120 cmng_fns = bxe_get_cmng_fns_mode(sc);
7122 if (cmng_fns != CMNG_FNS_NONE) {
7123 bxe_cmng_fns_init(sc, FALSE, cmng_fns);
7124 storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc));
7126 /* rate shaping and fairness are disabled */
7127 BLOGD(sc, DBG_LOAD, "single function mode without fairness\n");
7131 bxe_link_report_locked(sc);
7134 ; // XXX bxe_link_sync_notify(sc);
7139 bxe_attn_int_asserted(struct bxe_softc *sc,
7142 int port = SC_PORT(sc);
7143 uint32_t aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
7144 MISC_REG_AEU_MASK_ATTN_FUNC_0;
7145 uint32_t nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
7146 NIG_REG_MASK_INTERRUPT_PORT0;
7148 uint32_t nig_mask = 0;
7153 if (sc->attn_state & asserted) {
7154 BLOGE(sc, "IGU ERROR attn=0x%08x\n", asserted);
7157 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
7159 aeu_mask = REG_RD(sc, aeu_addr);
7161 BLOGD(sc, DBG_INTR, "aeu_mask 0x%08x newly asserted 0x%08x\n",
7162 aeu_mask, asserted);
7164 aeu_mask &= ~(asserted & 0x3ff);
7166 BLOGD(sc, DBG_INTR, "new mask 0x%08x\n", aeu_mask);
7168 REG_WR(sc, aeu_addr, aeu_mask);
7170 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
7172 BLOGD(sc, DBG_INTR, "attn_state 0x%08x\n", sc->attn_state);
7173 sc->attn_state |= asserted;
7174 BLOGD(sc, DBG_INTR, "new state 0x%08x\n", sc->attn_state);
7176 if (asserted & ATTN_HARD_WIRED_MASK) {
7177 if (asserted & ATTN_NIG_FOR_FUNC) {
7179 bxe_acquire_phy_lock(sc);
7180 /* save nig interrupt mask */
7181 nig_mask = REG_RD(sc, nig_int_mask_addr);
7183 /* If nig_mask is not set, no need to call the update function */
7185 REG_WR(sc, nig_int_mask_addr, 0);
7190 /* handle unicore attn? */
7193 if (asserted & ATTN_SW_TIMER_4_FUNC) {
7194 BLOGD(sc, DBG_INTR, "ATTN_SW_TIMER_4_FUNC!\n");
7197 if (asserted & GPIO_2_FUNC) {
7198 BLOGD(sc, DBG_INTR, "GPIO_2_FUNC!\n");
7201 if (asserted & GPIO_3_FUNC) {
7202 BLOGD(sc, DBG_INTR, "GPIO_3_FUNC!\n");
7205 if (asserted & GPIO_4_FUNC) {
7206 BLOGD(sc, DBG_INTR, "GPIO_4_FUNC!\n");
7210 if (asserted & ATTN_GENERAL_ATTN_1) {
7211 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_1!\n");
7212 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
7214 if (asserted & ATTN_GENERAL_ATTN_2) {
7215 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_2!\n");
7216 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
7218 if (asserted & ATTN_GENERAL_ATTN_3) {
7219 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_3!\n");
7220 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
7223 if (asserted & ATTN_GENERAL_ATTN_4) {
7224 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_4!\n");
7225 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
7227 if (asserted & ATTN_GENERAL_ATTN_5) {
7228 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_5!\n");
7229 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
7231 if (asserted & ATTN_GENERAL_ATTN_6) {
7232 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_6!\n");
7233 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
7238 if (sc->devinfo.int_block == INT_BLOCK_HC) {
7239 reg_addr = (HC_REG_COMMAND_REG + port*32 + COMMAND_REG_ATTN_BITS_SET);
7241 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
7244 BLOGD(sc, DBG_INTR, "about to mask 0x%08x at %s addr 0x%08x\n",
7246 (sc->devinfo.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
7247 REG_WR(sc, reg_addr, asserted);
7249 /* now set back the mask */
7250 if (asserted & ATTN_NIG_FOR_FUNC) {
7252 * Verify that IGU ack through BAR was written before restoring
7253 * NIG mask. This loop should exit after 2-3 iterations max.
7255 if (sc->devinfo.int_block != INT_BLOCK_HC) {
7259 igu_acked = REG_RD(sc, IGU_REG_ATTENTION_ACK_BITS);
7260 } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
7261 (++cnt < MAX_IGU_ATTN_ACK_TO));
7264 BLOGE(sc, "Failed to verify IGU ack on time\n");
7270 REG_WR(sc, nig_int_mask_addr, nig_mask);
7272 bxe_release_phy_lock(sc);
7277 bxe_print_next_block(struct bxe_softc *sc,
7281 BLOGI(sc, "%s%s", idx ? ", " : "", blk);
7285 bxe_check_blocks_with_parity0(struct bxe_softc *sc,
7290 uint32_t cur_bit = 0;
7293 for (i = 0; sig; i++) {
7294 cur_bit = ((uint32_t)0x1 << i);
7295 if (sig & cur_bit) {
7297 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
7299 bxe_print_next_block(sc, par_num++, "BRB");
7301 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
7303 bxe_print_next_block(sc, par_num++, "PARSER");
7305 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
7307 bxe_print_next_block(sc, par_num++, "TSDM");
7309 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
7311 bxe_print_next_block(sc, par_num++, "SEARCHER");
7313 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
7315 bxe_print_next_block(sc, par_num++, "TCM");
7317 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
7319 bxe_print_next_block(sc, par_num++, "TSEMI");
7321 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
7323 bxe_print_next_block(sc, par_num++, "XPB");
7336 bxe_check_blocks_with_parity1(struct bxe_softc *sc,
7343 uint32_t cur_bit = 0;
7344 for (i = 0; sig; i++) {
7345 cur_bit = ((uint32_t)0x1 << i);
7346 if (sig & cur_bit) {
7348 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
7350 bxe_print_next_block(sc, par_num++, "PBF");
7352 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
7354 bxe_print_next_block(sc, par_num++, "QM");
7356 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
7358 bxe_print_next_block(sc, par_num++, "TM");
7360 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
7362 bxe_print_next_block(sc, par_num++, "XSDM");
7364 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
7366 bxe_print_next_block(sc, par_num++, "XCM");
7368 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
7370 bxe_print_next_block(sc, par_num++, "XSEMI");
7372 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
7374 bxe_print_next_block(sc, par_num++, "DOORBELLQ");
7376 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
7378 bxe_print_next_block(sc, par_num++, "NIG");
7380 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
7382 bxe_print_next_block(sc, par_num++, "VAUX PCI CORE");
7385 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
7387 bxe_print_next_block(sc, par_num++, "DEBUG");
7389 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
7391 bxe_print_next_block(sc, par_num++, "USDM");
7393 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
7395 bxe_print_next_block(sc, par_num++, "UCM");
7397 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
7399 bxe_print_next_block(sc, par_num++, "USEMI");
7401 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
7403 bxe_print_next_block(sc, par_num++, "UPB");
7405 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
7407 bxe_print_next_block(sc, par_num++, "CSDM");
7409 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
7411 bxe_print_next_block(sc, par_num++, "CCM");
7424 bxe_check_blocks_with_parity2(struct bxe_softc *sc,
7429 uint32_t cur_bit = 0;
7432 for (i = 0; sig; i++) {
7433 cur_bit = ((uint32_t)0x1 << i);
7434 if (sig & cur_bit) {
7436 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
7438 bxe_print_next_block(sc, par_num++, "CSEMI");
7440 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
7442 bxe_print_next_block(sc, par_num++, "PXP");
7444 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
7446 bxe_print_next_block(sc, par_num++, "PXPPCICLOCKCLIENT");
7448 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
7450 bxe_print_next_block(sc, par_num++, "CFC");
7452 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
7454 bxe_print_next_block(sc, par_num++, "CDU");
7456 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
7458 bxe_print_next_block(sc, par_num++, "DMAE");
7460 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
7462 bxe_print_next_block(sc, par_num++, "IGU");
7464 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
7466 bxe_print_next_block(sc, par_num++, "MISC");
7479 bxe_check_blocks_with_parity3(struct bxe_softc *sc,
7485 uint32_t cur_bit = 0;
7488 for (i = 0; sig; i++) {
7489 cur_bit = ((uint32_t)0x1 << i);
7490 if (sig & cur_bit) {
7492 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
7494 bxe_print_next_block(sc, par_num++, "MCP ROM");
7497 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
7499 bxe_print_next_block(sc, par_num++,
7503 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
7505 bxe_print_next_block(sc, par_num++,
7509 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
7511 bxe_print_next_block(sc, par_num++,
7526 bxe_check_blocks_with_parity4(struct bxe_softc *sc,
7531 uint32_t cur_bit = 0;
7534 for (i = 0; sig; i++) {
7535 cur_bit = ((uint32_t)0x1 << i);
7536 if (sig & cur_bit) {
7538 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
7540 bxe_print_next_block(sc, par_num++, "PGLUE_B");
7542 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
7544 bxe_print_next_block(sc, par_num++, "ATC");
7557 bxe_parity_attn(struct bxe_softc *sc,
7564 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
7565 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
7566 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
7567 (sig[3] & HW_PRTY_ASSERT_SET_3) ||
7568 (sig[4] & HW_PRTY_ASSERT_SET_4)) {
7569 BLOGE(sc, "Parity error: HW block parity attention:\n"
7570 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
7571 (uint32_t)(sig[0] & HW_PRTY_ASSERT_SET_0),
7572 (uint32_t)(sig[1] & HW_PRTY_ASSERT_SET_1),
7573 (uint32_t)(sig[2] & HW_PRTY_ASSERT_SET_2),
7574 (uint32_t)(sig[3] & HW_PRTY_ASSERT_SET_3),
7575 (uint32_t)(sig[4] & HW_PRTY_ASSERT_SET_4));
7578 BLOGI(sc, "Parity errors detected in blocks: ");
7581 bxe_check_blocks_with_parity0(sc, sig[0] &
7582 HW_PRTY_ASSERT_SET_0,
7585 bxe_check_blocks_with_parity1(sc, sig[1] &
7586 HW_PRTY_ASSERT_SET_1,
7587 par_num, global, print);
7589 bxe_check_blocks_with_parity2(sc, sig[2] &
7590 HW_PRTY_ASSERT_SET_2,
7593 bxe_check_blocks_with_parity3(sc, sig[3] &
7594 HW_PRTY_ASSERT_SET_3,
7595 par_num, global, print);
7597 bxe_check_blocks_with_parity4(sc, sig[4] &
7598 HW_PRTY_ASSERT_SET_4,
7611 bxe_chk_parity_attn(struct bxe_softc *sc,
7615 struct attn_route attn = { {0} };
7616 int port = SC_PORT(sc);
7618 attn.sig[0] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
7619 attn.sig[1] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
7620 attn.sig[2] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
7621 attn.sig[3] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
7624 * Since MCP attentions can't be disabled inside the block, we need to
7625 * read AEU registers to see whether they're currently disabled
7627 attn.sig[3] &= ((REG_RD(sc, (!port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
7628 : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0)) &
7629 MISC_AEU_ENABLE_MCP_PRTY_BITS) |
7630 ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
7633 if (!CHIP_IS_E1x(sc))
7634 attn.sig[4] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
7636 return (bxe_parity_attn(sc, global, print, attn.sig));
7640 bxe_attn_int_deasserted4(struct bxe_softc *sc,
7645 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
7646 val = REG_RD(sc, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
7647 BLOGE(sc, "PGLUE hw attention 0x%08x\n", val);
7648 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
7649 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
7650 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
7651 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
7652 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
7653 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
7654 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
7655 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
7656 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
7657 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
7658 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
7659 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
7660 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
7661 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
7662 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
7663 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
7664 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
7665 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
7668 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
7669 val = REG_RD(sc, ATC_REG_ATC_INT_STS_CLR);
7670 BLOGE(sc, "ATC hw attention 0x%08x\n", val);
7671 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
7672 BLOGE(sc, "ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
7673 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
7674 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
7675 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
7676 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
7677 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
7678 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
7679 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
7680 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
7681 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
7682 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
7685 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
7686 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
7687 BLOGE(sc, "FATAL parity attention set4 0x%08x\n",
7688 (uint32_t)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
7689 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
7694 bxe_e1h_disable(struct bxe_softc *sc)
7696 int port = SC_PORT(sc);
7700 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 0);
7704 bxe_e1h_enable(struct bxe_softc *sc)
7706 int port = SC_PORT(sc);
7708 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 1);
7710 // XXX bxe_tx_enable(sc);
7714 * called due to MCP event (on pmf):
7715 * reread new bandwidth configuration
7717 * notify others function about the change
7720 bxe_config_mf_bw(struct bxe_softc *sc)
7722 if (sc->link_vars.link_up) {
7723 bxe_cmng_fns_init(sc, TRUE, CMNG_FNS_MINMAX);
7724 // XXX bxe_link_sync_notify(sc);
7727 storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc));
7731 bxe_set_mf_bw(struct bxe_softc *sc)
7733 bxe_config_mf_bw(sc);
7734 bxe_fw_command(sc, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
7738 bxe_handle_eee_event(struct bxe_softc *sc)
7740 BLOGD(sc, DBG_INTR, "EEE - LLDP event\n");
7741 bxe_fw_command(sc, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
7744 #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
7747 bxe_drv_info_ether_stat(struct bxe_softc *sc)
7749 struct eth_stats_info *ether_stat =
7750 &sc->sp->drv_info_to_mcp.ether_stat;
7752 strlcpy(ether_stat->version, BXE_DRIVER_VERSION,
7753 ETH_STAT_INFO_VERSION_LEN);
7755 /* XXX (+ MAC_PAD) taken from other driver... verify this is right */
7756 sc->sp_objs[0].mac_obj.get_n_elements(sc, &sc->sp_objs[0].mac_obj,
7757 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
7758 ether_stat->mac_local + MAC_PAD,
7761 ether_stat->mtu_size = sc->mtu;
7763 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
7764 if (sc->ifnet->if_capenable & (IFCAP_TSO4 | IFCAP_TSO6)) {
7765 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
7768 // XXX ether_stat->feature_flags |= ???;
7770 ether_stat->promiscuous_mode = 0; // (flags & PROMISC) ? 1 : 0;
7772 ether_stat->txq_size = sc->tx_ring_size;
7773 ether_stat->rxq_size = sc->rx_ring_size;
7777 bxe_handle_drv_info_req(struct bxe_softc *sc)
7779 enum drv_info_opcode op_code;
7780 uint32_t drv_info_ctl = SHMEM2_RD(sc, drv_info_control);
7782 /* if drv_info version supported by MFW doesn't match - send NACK */
7783 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
7784 bxe_fw_command(sc, DRV_MSG_CODE_DRV_INFO_NACK, 0);
7788 op_code = ((drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
7789 DRV_INFO_CONTROL_OP_CODE_SHIFT);
7791 memset(&sc->sp->drv_info_to_mcp, 0, sizeof(union drv_info_to_mcp));
7794 case ETH_STATS_OPCODE:
7795 bxe_drv_info_ether_stat(sc);
7797 case FCOE_STATS_OPCODE:
7798 case ISCSI_STATS_OPCODE:
7800 /* if op code isn't supported - send NACK */
7801 bxe_fw_command(sc, DRV_MSG_CODE_DRV_INFO_NACK, 0);
7806 * If we got drv_info attn from MFW then these fields are defined in
7809 SHMEM2_WR(sc, drv_info_host_addr_lo,
7810 U64_LO(BXE_SP_MAPPING(sc, drv_info_to_mcp)));
7811 SHMEM2_WR(sc, drv_info_host_addr_hi,
7812 U64_HI(BXE_SP_MAPPING(sc, drv_info_to_mcp)));
7814 bxe_fw_command(sc, DRV_MSG_CODE_DRV_INFO_ACK, 0);
7818 bxe_dcc_event(struct bxe_softc *sc,
7821 BLOGD(sc, DBG_INTR, "dcc_event 0x%08x\n", dcc_event);
7823 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
7825 * This is the only place besides the function initialization
7826 * where the sc->flags can change so it is done without any
7829 if (sc->devinfo.mf_info.mf_config[SC_VN(sc)] & FUNC_MF_CFG_FUNC_DISABLED) {
7830 BLOGD(sc, DBG_INTR, "mf_cfg function disabled\n");
7831 sc->flags |= BXE_MF_FUNC_DIS;
7832 bxe_e1h_disable(sc);
7834 BLOGD(sc, DBG_INTR, "mf_cfg function enabled\n");
7835 sc->flags &= ~BXE_MF_FUNC_DIS;
7838 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
7841 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
7842 bxe_config_mf_bw(sc);
7843 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
7846 /* Report results to MCP */
7848 bxe_fw_command(sc, DRV_MSG_CODE_DCC_FAILURE, 0);
7850 bxe_fw_command(sc, DRV_MSG_CODE_DCC_OK, 0);
7854 bxe_pmf_update(struct bxe_softc *sc)
7856 int port = SC_PORT(sc);
7860 BLOGD(sc, DBG_INTR, "pmf %d\n", sc->port.pmf);
7863 * We need the mb() to ensure the ordering between the writing to
7864 * sc->port.pmf here and reading it from the bxe_periodic_task().
7868 /* queue a periodic task */
7869 // XXX schedule task...
7871 // XXX bxe_dcbx_pmf_update(sc);
7873 /* enable nig attention */
7874 val = (0xff0f | (1 << (SC_VN(sc) + 4)));
7875 if (sc->devinfo.int_block == INT_BLOCK_HC) {
7876 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, val);
7877 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, val);
7878 } else if (!CHIP_IS_E1x(sc)) {
7879 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, val);
7880 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, val);
7883 bxe_stats_handle(sc, STATS_EVENT_PMF);
7887 bxe_mc_assert(struct bxe_softc *sc)
7891 uint32_t row0, row1, row2, row3;
7894 last_idx = REG_RD8(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_INDEX_OFFSET);
7896 BLOGE(sc, "XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
7898 /* print the asserts */
7899 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
7901 row0 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i));
7902 row1 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) + 4);
7903 row2 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) + 8);
7904 row3 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) + 12);
7906 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
7907 BLOGE(sc, "XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
7908 i, row3, row2, row1, row0);
7916 last_idx = REG_RD8(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_INDEX_OFFSET);
7918 BLOGE(sc, "TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
7921 /* print the asserts */
7922 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
7924 row0 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i));
7925 row1 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) + 4);
7926 row2 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) + 8);
7927 row3 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) + 12);
7929 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
7930 BLOGE(sc, "TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
7931 i, row3, row2, row1, row0);
7939 last_idx = REG_RD8(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_INDEX_OFFSET);
7941 BLOGE(sc, "CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
7944 /* print the asserts */
7945 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
7947 row0 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i));
7948 row1 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) + 4);
7949 row2 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) + 8);
7950 row3 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) + 12);
7952 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
7953 BLOGE(sc, "CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
7954 i, row3, row2, row1, row0);
7962 last_idx = REG_RD8(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_INDEX_OFFSET);
7964 BLOGE(sc, "USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
7967 /* print the asserts */
7968 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
7970 row0 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i));
7971 row1 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) + 4);
7972 row2 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) + 8);
7973 row3 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) + 12);
7975 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
7976 BLOGE(sc, "USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
7977 i, row3, row2, row1, row0);
7988 bxe_attn_int_deasserted3(struct bxe_softc *sc,
7991 int func = SC_FUNC(sc);
7994 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
7996 if (attn & BXE_PMF_LINK_ASSERT(sc)) {
7998 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7999 bxe_read_mf_cfg(sc);
8000 sc->devinfo.mf_info.mf_config[SC_VN(sc)] =
8001 MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config);
8002 val = SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_status);
8004 if (val & DRV_STATUS_DCC_EVENT_MASK)
8005 bxe_dcc_event(sc, (val & DRV_STATUS_DCC_EVENT_MASK));
8007 if (val & DRV_STATUS_SET_MF_BW)
8010 if (val & DRV_STATUS_DRV_INFO_REQ)
8011 bxe_handle_drv_info_req(sc);
8013 if ((sc->port.pmf == 0) && (val & DRV_STATUS_PMF))
8016 if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
8017 bxe_handle_eee_event(sc);
8019 if (sc->link_vars.periodic_flags &
8020 ELINK_PERIODIC_FLAGS_LINK_EVENT) {
8021 /* sync with link */
8022 bxe_acquire_phy_lock(sc);
8023 sc->link_vars.periodic_flags &=
8024 ~ELINK_PERIODIC_FLAGS_LINK_EVENT;
8025 bxe_release_phy_lock(sc);
8027 ; // XXX bxe_link_sync_notify(sc);
8028 bxe_link_report(sc);
8032 * Always call it here: bxe_link_report() will
8033 * prevent the link indication duplication.
8035 bxe_link_status_update(sc);
8037 } else if (attn & BXE_MC_ASSERT_BITS) {
8039 BLOGE(sc, "MC assert!\n");
8041 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_10, 0);
8042 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_9, 0);
8043 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_8, 0);
8044 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_7, 0);
8045 bxe_panic(sc, ("MC assert!\n"));
8047 } else if (attn & BXE_MCP_ASSERT) {
8049 BLOGE(sc, "MCP assert!\n");
8050 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_11, 0);
8051 // XXX bxe_fw_dump(sc);
8054 BLOGE(sc, "Unknown HW assert! (attn 0x%08x)\n", attn);
8058 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
8059 BLOGE(sc, "LATCHED attention 0x%08x (masked)\n", attn);
8060 if (attn & BXE_GRC_TIMEOUT) {
8061 val = CHIP_IS_E1(sc) ? 0 : REG_RD(sc, MISC_REG_GRC_TIMEOUT_ATTN);
8062 BLOGE(sc, "GRC time-out 0x%08x\n", val);
8064 if (attn & BXE_GRC_RSV) {
8065 val = CHIP_IS_E1(sc) ? 0 : REG_RD(sc, MISC_REG_GRC_RSV_ATTN);
8066 BLOGE(sc, "GRC reserved 0x%08x\n", val);
8068 REG_WR(sc, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
8073 bxe_attn_int_deasserted2(struct bxe_softc *sc,
8076 int port = SC_PORT(sc);
8078 uint32_t val0, mask0, val1, mask1;
8081 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
8082 val = REG_RD(sc, CFC_REG_CFC_INT_STS_CLR);
8083 BLOGE(sc, "CFC hw attention 0x%08x\n", val);
8084 /* CFC error attention */
8086 BLOGE(sc, "FATAL error from CFC\n");
8090 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
8091 val = REG_RD(sc, PXP_REG_PXP_INT_STS_CLR_0);
8092 BLOGE(sc, "PXP hw attention-0 0x%08x\n", val);
8093 /* RQ_USDMDP_FIFO_OVERFLOW */
8094 if (val & 0x18000) {
8095 BLOGE(sc, "FATAL error from PXP\n");
8098 if (!CHIP_IS_E1x(sc)) {
8099 val = REG_RD(sc, PXP_REG_PXP_INT_STS_CLR_1);
8100 BLOGE(sc, "PXP hw attention-1 0x%08x\n", val);
8104 #define PXP2_EOP_ERROR_BIT PXP2_PXP2_INT_STS_CLR_0_REG_WR_PGLUE_EOP_ERROR
8105 #define AEU_PXP2_HW_INT_BIT AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_HW_INTERRUPT
8107 if (attn & AEU_PXP2_HW_INT_BIT) {
8108 /* CQ47854 workaround do not panic on
8109 * PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR
8111 if (!CHIP_IS_E1x(sc)) {
8112 mask0 = REG_RD(sc, PXP2_REG_PXP2_INT_MASK_0);
8113 val1 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_1);
8114 mask1 = REG_RD(sc, PXP2_REG_PXP2_INT_MASK_1);
8115 val0 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_0);
8117 * If the olny PXP2_EOP_ERROR_BIT is set in
8118 * STS0 and STS1 - clear it
8120 * probably we lose additional attentions between
8121 * STS0 and STS_CLR0, in this case user will not
8122 * be notified about them
8124 if (val0 & mask0 & PXP2_EOP_ERROR_BIT &&
8126 val0 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_CLR_0);
8128 /* print the register, since no one can restore it */
8129 BLOGE(sc, "PXP2_REG_PXP2_INT_STS_CLR_0 0x%08x\n", val0);
8132 * if PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR
8135 if (val0 & PXP2_EOP_ERROR_BIT) {
8136 BLOGE(sc, "PXP2_WR_PGLUE_EOP_ERROR\n");
8139 * if only PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR is
8140 * set then clear attention from PXP2 block without panic
8142 if (((val0 & mask0) == PXP2_EOP_ERROR_BIT) &&
8143 ((val1 & mask1) == 0))
8144 attn &= ~AEU_PXP2_HW_INT_BIT;
8149 if (attn & HW_INTERRUT_ASSERT_SET_2) {
8150 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
8151 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
8153 val = REG_RD(sc, reg_offset);
8154 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
8155 REG_WR(sc, reg_offset, val);
8157 BLOGE(sc, "FATAL HW block attention set2 0x%x\n",
8158 (uint32_t)(attn & HW_INTERRUT_ASSERT_SET_2));
8159 bxe_panic(sc, ("HW block attention set2\n"));
8164 bxe_attn_int_deasserted1(struct bxe_softc *sc,
8167 int port = SC_PORT(sc);
8171 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
8172 val = REG_RD(sc, DORQ_REG_DORQ_INT_STS_CLR);
8173 BLOGE(sc, "DB hw attention 0x%08x\n", val);
8174 /* DORQ discard attention */
8176 BLOGE(sc, "FATAL error from DORQ\n");
8180 if (attn & HW_INTERRUT_ASSERT_SET_1) {
8181 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
8182 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
8184 val = REG_RD(sc, reg_offset);
8185 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
8186 REG_WR(sc, reg_offset, val);
8188 BLOGE(sc, "FATAL HW block attention set1 0x%08x\n",
8189 (uint32_t)(attn & HW_INTERRUT_ASSERT_SET_1));
8190 bxe_panic(sc, ("HW block attention set1\n"));
8195 bxe_attn_int_deasserted0(struct bxe_softc *sc,
8198 int port = SC_PORT(sc);
8202 reg_offset = (port) ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
8203 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
8205 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
8206 val = REG_RD(sc, reg_offset);
8207 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
8208 REG_WR(sc, reg_offset, val);
8210 BLOGW(sc, "SPIO5 hw attention\n");
8212 /* Fan failure attention */
8213 elink_hw_reset_phy(&sc->link_params);
8214 bxe_fan_failure(sc);
8217 if ((attn & sc->link_vars.aeu_int_mask) && sc->port.pmf) {
8218 bxe_acquire_phy_lock(sc);
8219 elink_handle_module_detect_int(&sc->link_params);
8220 bxe_release_phy_lock(sc);
8223 if (attn & HW_INTERRUT_ASSERT_SET_0) {
8224 val = REG_RD(sc, reg_offset);
8225 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
8226 REG_WR(sc, reg_offset, val);
8228 bxe_panic(sc, ("FATAL HW block attention set0 0x%lx\n",
8229 (attn & HW_INTERRUT_ASSERT_SET_0)));
8234 bxe_attn_int_deasserted(struct bxe_softc *sc,
8235 uint32_t deasserted)
8237 struct attn_route attn;
8238 struct attn_route *group_mask;
8239 int port = SC_PORT(sc);
8244 uint8_t global = FALSE;
8247 * Need to take HW lock because MCP or other port might also
8248 * try to handle this event.
8250 bxe_acquire_alr(sc);
8252 if (bxe_chk_parity_attn(sc, &global, TRUE)) {
8254 * In case of parity errors don't handle attentions so that
8255 * other function would "see" parity errors.
8257 sc->recovery_state = BXE_RECOVERY_INIT;
8258 // XXX schedule a recovery task...
8259 /* disable HW interrupts */
8260 bxe_int_disable(sc);
8261 bxe_release_alr(sc);
8265 attn.sig[0] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
8266 attn.sig[1] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
8267 attn.sig[2] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
8268 attn.sig[3] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
8269 if (!CHIP_IS_E1x(sc)) {
8270 attn.sig[4] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
8275 BLOGD(sc, DBG_INTR, "attn: 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
8276 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
8278 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
8279 if (deasserted & (1 << index)) {
8280 group_mask = &sc->attn_group[index];
8283 "group[%d]: 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n", index,
8284 group_mask->sig[0], group_mask->sig[1],
8285 group_mask->sig[2], group_mask->sig[3],
8286 group_mask->sig[4]);
8288 bxe_attn_int_deasserted4(sc, attn.sig[4] & group_mask->sig[4]);
8289 bxe_attn_int_deasserted3(sc, attn.sig[3] & group_mask->sig[3]);
8290 bxe_attn_int_deasserted1(sc, attn.sig[1] & group_mask->sig[1]);
8291 bxe_attn_int_deasserted2(sc, attn.sig[2] & group_mask->sig[2]);
8292 bxe_attn_int_deasserted0(sc, attn.sig[0] & group_mask->sig[0]);
8296 bxe_release_alr(sc);
8298 if (sc->devinfo.int_block == INT_BLOCK_HC) {
8299 reg_addr = (HC_REG_COMMAND_REG + port*32 +
8300 COMMAND_REG_ATTN_BITS_CLR);
8302 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
8307 "about to mask 0x%08x at %s addr 0x%08x\n", val,
8308 (sc->devinfo.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
8309 REG_WR(sc, reg_addr, val);
8311 if (~sc->attn_state & deasserted) {
8312 BLOGE(sc, "IGU error\n");
8315 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8316 MISC_REG_AEU_MASK_ATTN_FUNC_0;
8318 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
8320 aeu_mask = REG_RD(sc, reg_addr);
8322 BLOGD(sc, DBG_INTR, "aeu_mask 0x%08x newly deasserted 0x%08x\n",
8323 aeu_mask, deasserted);
8324 aeu_mask |= (deasserted & 0x3ff);
8325 BLOGD(sc, DBG_INTR, "new mask 0x%08x\n", aeu_mask);
8327 REG_WR(sc, reg_addr, aeu_mask);
8328 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
8330 BLOGD(sc, DBG_INTR, "attn_state 0x%08x\n", sc->attn_state);
8331 sc->attn_state &= ~deasserted;
8332 BLOGD(sc, DBG_INTR, "new state 0x%08x\n", sc->attn_state);
8336 bxe_attn_int(struct bxe_softc *sc)
8338 /* read local copy of bits */
8339 uint32_t attn_bits = le32toh(sc->def_sb->atten_status_block.attn_bits);
8340 uint32_t attn_ack = le32toh(sc->def_sb->atten_status_block.attn_bits_ack);
8341 uint32_t attn_state = sc->attn_state;
8343 /* look for changed bits */
8344 uint32_t asserted = attn_bits & ~attn_ack & ~attn_state;
8345 uint32_t deasserted = ~attn_bits & attn_ack & attn_state;
8348 "attn_bits 0x%08x attn_ack 0x%08x asserted 0x%08x deasserted 0x%08x\n",
8349 attn_bits, attn_ack, asserted, deasserted);
8351 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state)) {
8352 BLOGE(sc, "BAD attention state\n");
8355 /* handle bits that were raised */
8357 bxe_attn_int_asserted(sc, asserted);
8361 bxe_attn_int_deasserted(sc, deasserted);
8366 bxe_update_dsb_idx(struct bxe_softc *sc)
8368 struct host_sp_status_block *def_sb = sc->def_sb;
8371 mb(); /* status block is written to by the chip */
8373 if (sc->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
8374 sc->def_att_idx = def_sb->atten_status_block.attn_bits_index;
8375 rc |= BXE_DEF_SB_ATT_IDX;
8378 if (sc->def_idx != def_sb->sp_sb.running_index) {
8379 sc->def_idx = def_sb->sp_sb.running_index;
8380 rc |= BXE_DEF_SB_IDX;
8388 static inline struct ecore_queue_sp_obj *
8389 bxe_cid_to_q_obj(struct bxe_softc *sc,
8392 BLOGD(sc, DBG_SP, "retrieving fp from cid %d\n", cid);
8393 return (&sc->sp_objs[CID_TO_FP(cid, sc)].q_obj);
8397 bxe_handle_mcast_eqe(struct bxe_softc *sc)
8399 struct ecore_mcast_ramrod_params rparam;
8402 memset(&rparam, 0, sizeof(rparam));
8404 rparam.mcast_obj = &sc->mcast_obj;
8408 /* clear pending state for the last command */
8409 sc->mcast_obj.raw.clear_pending(&sc->mcast_obj.raw);
8411 /* if there are pending mcast commands - send them */
8412 if (sc->mcast_obj.check_pending(&sc->mcast_obj)) {
8413 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT);
8416 "ERROR: Failed to send pending mcast commands (%d)\n", rc);
8420 BXE_MCAST_UNLOCK(sc);
8424 bxe_handle_classification_eqe(struct bxe_softc *sc,
8425 union event_ring_elem *elem)
8427 unsigned long ramrod_flags = 0;
8429 uint32_t cid = elem->message.data.eth_event.echo & BXE_SWCID_MASK;
8430 struct ecore_vlan_mac_obj *vlan_mac_obj;
8432 /* always push next commands out, don't wait here */
8433 bit_set(&ramrod_flags, RAMROD_CONT);
8435 switch (le32toh(elem->message.data.eth_event.echo) >> BXE_SWCID_SHIFT) {
8436 case ECORE_FILTER_MAC_PENDING:
8437 BLOGD(sc, DBG_SP, "Got SETUP_MAC completions\n");
8438 vlan_mac_obj = &sc->sp_objs[cid].mac_obj;
8441 case ECORE_FILTER_MCAST_PENDING:
8442 BLOGD(sc, DBG_SP, "Got SETUP_MCAST completions\n");
8444 * This is only relevant for 57710 where multicast MACs are
8445 * configured as unicast MACs using the same ramrod.
8447 bxe_handle_mcast_eqe(sc);
8451 BLOGE(sc, "Unsupported classification command: %d\n",
8452 elem->message.data.eth_event.echo);
8456 rc = vlan_mac_obj->complete(sc, vlan_mac_obj, elem, &ramrod_flags);
8459 BLOGE(sc, "Failed to schedule new commands (%d)\n", rc);
8460 } else if (rc > 0) {
8461 BLOGD(sc, DBG_SP, "Scheduled next pending commands...\n");
8466 bxe_handle_rx_mode_eqe(struct bxe_softc *sc,
8467 union event_ring_elem *elem)
8469 bxe_clear_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state);
8471 /* send rx_mode command again if was requested */
8472 if (bxe_test_and_clear_bit(ECORE_FILTER_RX_MODE_SCHED,
8474 bxe_set_storm_rx_mode(sc);
8479 bxe_update_eq_prod(struct bxe_softc *sc,
8482 storm_memset_eq_prod(sc, prod, SC_FUNC(sc));
8483 wmb(); /* keep prod updates ordered */
8487 bxe_eq_int(struct bxe_softc *sc)
8489 uint16_t hw_cons, sw_cons, sw_prod;
8490 union event_ring_elem *elem;
8495 struct ecore_queue_sp_obj *q_obj;
8496 struct ecore_func_sp_obj *f_obj = &sc->func_obj;
8497 struct ecore_raw_obj *rss_raw = &sc->rss_conf_obj.raw;
8499 hw_cons = le16toh(*sc->eq_cons_sb);
8502 * The hw_cons range is 1-255, 257 - the sw_cons range is 0-254, 256.
8503 * when we get to the next-page we need to adjust so the loop
8504 * condition below will be met. The next element is the size of a
8505 * regular element and hence incrementing by 1
8507 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE) {
8512 * This function may never run in parallel with itself for a
8513 * specific sc and no need for a read memory barrier here.
8515 sw_cons = sc->eq_cons;
8516 sw_prod = sc->eq_prod;
8518 BLOGD(sc, DBG_SP,"EQ: hw_cons=%u sw_cons=%u eq_spq_left=0x%lx\n",
8519 hw_cons, sw_cons, atomic_load_acq_long(&sc->eq_spq_left));
8523 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
8525 elem = &sc->eq[EQ_DESC(sw_cons)];
8527 /* elem CID originates from FW, actually LE */
8528 cid = SW_CID(elem->message.data.cfc_del_event.cid);
8529 opcode = elem->message.opcode;
8531 /* handle eq element */
8534 case EVENT_RING_OPCODE_STAT_QUERY:
8535 BLOGD(sc, DBG_SP, "got statistics completion event %d\n",
8537 /* nothing to do with stats comp */
8540 case EVENT_RING_OPCODE_CFC_DEL:
8541 /* handle according to cid range */
8542 /* we may want to verify here that the sc state is HALTING */
8543 BLOGD(sc, DBG_SP, "got delete ramrod for MULTI[%d]\n", cid);
8544 q_obj = bxe_cid_to_q_obj(sc, cid);
8545 if (q_obj->complete_cmd(sc, q_obj, ECORE_Q_CMD_CFC_DEL)) {
8550 case EVENT_RING_OPCODE_STOP_TRAFFIC:
8551 BLOGD(sc, DBG_SP, "got STOP TRAFFIC\n");
8552 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_TX_STOP)) {
8555 // XXX bxe_dcbx_set_params(sc, BXE_DCBX_STATE_TX_PAUSED);
8558 case EVENT_RING_OPCODE_START_TRAFFIC:
8559 BLOGD(sc, DBG_SP, "got START TRAFFIC\n");
8560 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_TX_START)) {
8563 // XXX bxe_dcbx_set_params(sc, BXE_DCBX_STATE_TX_RELEASED);
8566 case EVENT_RING_OPCODE_FUNCTION_UPDATE:
8567 echo = elem->message.data.function_update_event.echo;
8568 if (echo == SWITCH_UPDATE) {
8569 BLOGD(sc, DBG_SP, "got FUNC_SWITCH_UPDATE ramrod\n");
8570 if (f_obj->complete_cmd(sc, f_obj,
8571 ECORE_F_CMD_SWITCH_UPDATE)) {
8577 "AFEX: ramrod completed FUNCTION_UPDATE\n");
8581 case EVENT_RING_OPCODE_FORWARD_SETUP:
8582 q_obj = &bxe_fwd_sp_obj(sc, q_obj);
8583 if (q_obj->complete_cmd(sc, q_obj,
8584 ECORE_Q_CMD_SETUP_TX_ONLY)) {
8589 case EVENT_RING_OPCODE_FUNCTION_START:
8590 BLOGD(sc, DBG_SP, "got FUNC_START ramrod\n");
8591 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_START)) {
8596 case EVENT_RING_OPCODE_FUNCTION_STOP:
8597 BLOGD(sc, DBG_SP, "got FUNC_STOP ramrod\n");
8598 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_STOP)) {
8604 switch (opcode | sc->state) {
8605 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | BXE_STATE_OPEN):
8606 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | BXE_STATE_OPENING_WAITING_PORT):
8607 cid = elem->message.data.eth_event.echo & BXE_SWCID_MASK;
8608 BLOGD(sc, DBG_SP, "got RSS_UPDATE ramrod. CID %d\n", cid);
8609 rss_raw->clear_pending(rss_raw);
8612 case (EVENT_RING_OPCODE_SET_MAC | BXE_STATE_OPEN):
8613 case (EVENT_RING_OPCODE_SET_MAC | BXE_STATE_DIAG):
8614 case (EVENT_RING_OPCODE_SET_MAC | BXE_STATE_CLOSING_WAITING_HALT):
8615 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BXE_STATE_OPEN):
8616 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BXE_STATE_DIAG):
8617 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BXE_STATE_CLOSING_WAITING_HALT):
8618 BLOGD(sc, DBG_SP, "got (un)set mac ramrod\n");
8619 bxe_handle_classification_eqe(sc, elem);
8622 case (EVENT_RING_OPCODE_MULTICAST_RULES | BXE_STATE_OPEN):
8623 case (EVENT_RING_OPCODE_MULTICAST_RULES | BXE_STATE_DIAG):
8624 case (EVENT_RING_OPCODE_MULTICAST_RULES | BXE_STATE_CLOSING_WAITING_HALT):
8625 BLOGD(sc, DBG_SP, "got mcast ramrod\n");
8626 bxe_handle_mcast_eqe(sc);
8629 case (EVENT_RING_OPCODE_FILTERS_RULES | BXE_STATE_OPEN):
8630 case (EVENT_RING_OPCODE_FILTERS_RULES | BXE_STATE_DIAG):
8631 case (EVENT_RING_OPCODE_FILTERS_RULES | BXE_STATE_CLOSING_WAITING_HALT):
8632 BLOGD(sc, DBG_SP, "got rx_mode ramrod\n");
8633 bxe_handle_rx_mode_eqe(sc, elem);
8637 /* unknown event log error and continue */
8638 BLOGE(sc, "Unknown EQ event %d, sc->state 0x%x\n",
8639 elem->message.opcode, sc->state);
8647 atomic_add_acq_long(&sc->eq_spq_left, spqe_cnt);
8649 sc->eq_cons = sw_cons;
8650 sc->eq_prod = sw_prod;
8652 /* make sure that above mem writes were issued towards the memory */
8655 /* update producer */
8656 bxe_update_eq_prod(sc, sc->eq_prod);
8660 bxe_handle_sp_tq(void *context,
8663 struct bxe_softc *sc = (struct bxe_softc *)context;
8666 BLOGD(sc, DBG_SP, "---> SP TASK <---\n");
8668 /* what work needs to be performed? */
8669 status = bxe_update_dsb_idx(sc);
8671 BLOGD(sc, DBG_SP, "dsb status 0x%04x\n", status);
8674 if (status & BXE_DEF_SB_ATT_IDX) {
8675 BLOGD(sc, DBG_SP, "---> ATTN INTR <---\n");
8677 status &= ~BXE_DEF_SB_ATT_IDX;
8680 /* SP events: STAT_QUERY and others */
8681 if (status & BXE_DEF_SB_IDX) {
8682 /* handle EQ completions */
8683 BLOGD(sc, DBG_SP, "---> EQ INTR <---\n");
8685 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID,
8686 le16toh(sc->def_idx), IGU_INT_NOP, 1);
8687 status &= ~BXE_DEF_SB_IDX;
8690 /* if status is non zero then something went wrong */
8691 if (__predict_false(status)) {
8692 BLOGE(sc, "Got an unknown SP interrupt! (0x%04x)\n", status);
8695 /* ack status block only if something was actually handled */
8696 bxe_ack_sb(sc, sc->igu_dsb_id, ATTENTION_ID,
8697 le16toh(sc->def_att_idx), IGU_INT_ENABLE, 1);
8700 * Must be called after the EQ processing (since eq leads to sriov
8701 * ramrod completion flows).
8702 * This flow may have been scheduled by the arrival of a ramrod
8703 * completion, or by the sriov code rescheduling itself.
8705 // XXX bxe_iov_sp_task(sc);
8710 bxe_handle_fp_tq(void *context,
8713 struct bxe_fastpath *fp = (struct bxe_fastpath *)context;
8714 struct bxe_softc *sc = fp->sc;
8715 uint8_t more_tx = FALSE;
8716 uint8_t more_rx = FALSE;
8718 BLOGD(sc, DBG_INTR, "---> FP TASK QUEUE (%d) <---\n", fp->index);
8721 * IFF_DRV_RUNNING state can't be checked here since we process
8722 * slowpath events on a client queue during setup. Instead
8723 * we need to add a "process/continue" flag here that the driver
8724 * can use to tell the task here not to do anything.
8727 if (!(sc->ifnet->if_drv_flags & IFF_DRV_RUNNING)) {
8732 /* update the fastpath index */
8733 bxe_update_fp_sb_idx(fp);
8735 /* XXX add loop here if ever support multiple tx CoS */
8736 /* fp->txdata[cos] */
8737 if (bxe_has_tx_work(fp)) {
8739 more_tx = bxe_txeof(sc, fp);
8740 BXE_FP_TX_UNLOCK(fp);
8743 if (bxe_has_rx_work(fp)) {
8744 more_rx = bxe_rxeof(sc, fp);
8747 if (more_rx /*|| more_tx*/) {
8748 /* still more work to do */
8749 taskqueue_enqueue_fast(fp->tq, &fp->tq_task);
8753 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID,
8754 le16toh(fp->fp_hc_idx), IGU_INT_ENABLE, 1);
8758 bxe_task_fp(struct bxe_fastpath *fp)
8760 struct bxe_softc *sc = fp->sc;
8761 uint8_t more_tx = FALSE;
8762 uint8_t more_rx = FALSE;
8764 BLOGD(sc, DBG_INTR, "---> FP TASK ISR (%d) <---\n", fp->index);
8766 /* update the fastpath index */
8767 bxe_update_fp_sb_idx(fp);
8769 /* XXX add loop here if ever support multiple tx CoS */
8770 /* fp->txdata[cos] */
8771 if (bxe_has_tx_work(fp)) {
8773 more_tx = bxe_txeof(sc, fp);
8774 BXE_FP_TX_UNLOCK(fp);
8777 if (bxe_has_rx_work(fp)) {
8778 more_rx = bxe_rxeof(sc, fp);
8781 if (more_rx /*|| more_tx*/) {
8782 /* still more work to do, bail out if this ISR and process later */
8783 taskqueue_enqueue_fast(fp->tq, &fp->tq_task);
8788 * Here we write the fastpath index taken before doing any tx or rx work.
8789 * It is very well possible other hw events occurred up to this point and
8790 * they were actually processed accordingly above. Since we're going to
8791 * write an older fastpath index, an interrupt is coming which we might
8792 * not do any work in.
8794 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID,
8795 le16toh(fp->fp_hc_idx), IGU_INT_ENABLE, 1);
8799 * Legacy interrupt entry point.
8801 * Verifies that the controller generated the interrupt and
8802 * then calls a separate routine to handle the various
8803 * interrupt causes: link, RX, and TX.
8806 bxe_intr_legacy(void *xsc)
8808 struct bxe_softc *sc = (struct bxe_softc *)xsc;
8809 struct bxe_fastpath *fp;
8810 uint16_t status, mask;
8813 BLOGD(sc, DBG_INTR, "---> BXE INTx <---\n");
8816 * 0 for ustorm, 1 for cstorm
8817 * the bits returned from ack_int() are 0-15
8818 * bit 0 = attention status block
8819 * bit 1 = fast path status block
8820 * a mask of 0x2 or more = tx/rx event
8821 * a mask of 1 = slow path event
8824 status = bxe_ack_int(sc);
8826 /* the interrupt is not for us */
8827 if (__predict_false(status == 0)) {
8828 BLOGD(sc, DBG_INTR, "Not our interrupt!\n");
8832 BLOGD(sc, DBG_INTR, "Interrupt status 0x%04x\n", status);
8834 FOR_EACH_ETH_QUEUE(sc, i) {
8836 mask = (0x2 << (fp->index + CNIC_SUPPORT(sc)));
8837 if (status & mask) {
8838 /* acknowledge and disable further fastpath interrupts */
8839 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
8845 if (__predict_false(status & 0x1)) {
8846 /* acknowledge and disable further slowpath interrupts */
8847 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
8849 /* schedule slowpath handler */
8850 taskqueue_enqueue_fast(sc->sp_tq, &sc->sp_tq_task);
8855 if (__predict_false(status)) {
8856 BLOGW(sc, "Unexpected fastpath status (0x%08x)!\n", status);
8860 /* slowpath interrupt entry point */
8862 bxe_intr_sp(void *xsc)
8864 struct bxe_softc *sc = (struct bxe_softc *)xsc;
8866 BLOGD(sc, (DBG_INTR | DBG_SP), "---> SP INTR <---\n");
8868 /* acknowledge and disable further slowpath interrupts */
8869 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
8871 /* schedule slowpath handler */
8872 taskqueue_enqueue_fast(sc->sp_tq, &sc->sp_tq_task);
8875 /* fastpath interrupt entry point */
8877 bxe_intr_fp(void *xfp)
8879 struct bxe_fastpath *fp = (struct bxe_fastpath *)xfp;
8880 struct bxe_softc *sc = fp->sc;
8882 BLOGD(sc, DBG_INTR, "---> FP INTR %d <---\n", fp->index);
8885 "(cpu=%d) MSI-X fp=%d fw_sb=%d igu_sb=%d\n",
8886 curcpu, fp->index, fp->fw_sb_id, fp->igu_sb_id);
8888 /* acknowledge and disable further fastpath interrupts */
8889 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
8894 /* Release all interrupts allocated by the driver. */
8896 bxe_interrupt_free(struct bxe_softc *sc)
8900 switch (sc->interrupt_mode) {
8901 case INTR_MODE_INTX:
8902 BLOGD(sc, DBG_LOAD, "Releasing legacy INTx vector\n");
8903 if (sc->intr[0].resource != NULL) {
8904 bus_release_resource(sc->dev,
8907 sc->intr[0].resource);
8911 for (i = 0; i < sc->intr_count; i++) {
8912 BLOGD(sc, DBG_LOAD, "Releasing MSI vector %d\n", i);
8913 if (sc->intr[i].resource && sc->intr[i].rid) {
8914 bus_release_resource(sc->dev,
8917 sc->intr[i].resource);
8920 pci_release_msi(sc->dev);
8922 case INTR_MODE_MSIX:
8923 for (i = 0; i < sc->intr_count; i++) {
8924 BLOGD(sc, DBG_LOAD, "Releasing MSI-X vector %d\n", i);
8925 if (sc->intr[i].resource && sc->intr[i].rid) {
8926 bus_release_resource(sc->dev,
8929 sc->intr[i].resource);
8932 pci_release_msi(sc->dev);
8935 /* nothing to do as initial allocation failed */
8941 * This function determines and allocates the appropriate
8942 * interrupt based on system capabilites and user request.
8944 * The user may force a particular interrupt mode, specify
8945 * the number of receive queues, specify the method for
8946 * distribuitng received frames to receive queues, or use
8947 * the default settings which will automatically select the
8948 * best supported combination. In addition, the OS may or
8949 * may not support certain combinations of these settings.
8950 * This routine attempts to reconcile the settings requested
8951 * by the user with the capabilites available from the system
8952 * to select the optimal combination of features.
8955 * 0 = Success, !0 = Failure.
8958 bxe_interrupt_alloc(struct bxe_softc *sc)
8962 int num_requested = 0;
8963 int num_allocated = 0;
8967 /* get the number of available MSI/MSI-X interrupts from the OS */
8968 if (sc->interrupt_mode > 0) {
8969 if (sc->devinfo.pcie_cap_flags & BXE_MSIX_CAPABLE_FLAG) {
8970 msix_count = pci_msix_count(sc->dev);
8973 if (sc->devinfo.pcie_cap_flags & BXE_MSI_CAPABLE_FLAG) {
8974 msi_count = pci_msi_count(sc->dev);
8977 BLOGD(sc, DBG_LOAD, "%d MSI and %d MSI-X vectors available\n",
8978 msi_count, msix_count);
8981 do { /* try allocating MSI-X interrupt resources (at least 2) */
8982 if (sc->interrupt_mode != INTR_MODE_MSIX) {
8986 if (((sc->devinfo.pcie_cap_flags & BXE_MSIX_CAPABLE_FLAG) == 0) ||
8988 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */
8992 /* ask for the necessary number of MSI-X vectors */
8993 num_requested = min((sc->num_queues + 1), msix_count);
8995 BLOGD(sc, DBG_LOAD, "Requesting %d MSI-X vectors\n", num_requested);
8997 num_allocated = num_requested;
8998 if ((rc = pci_alloc_msix(sc->dev, &num_allocated)) != 0) {
8999 BLOGE(sc, "MSI-X alloc failed! (%d)\n", rc);
9000 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */
9004 if (num_allocated < 2) { /* possible? */
9005 BLOGE(sc, "MSI-X allocation less than 2!\n");
9006 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */
9007 pci_release_msi(sc->dev);
9011 BLOGI(sc, "MSI-X vectors Requested %d and Allocated %d\n",
9012 num_requested, num_allocated);
9014 /* best effort so use the number of vectors allocated to us */
9015 sc->intr_count = num_allocated;
9016 sc->num_queues = num_allocated - 1;
9018 rid = 1; /* initial resource identifier */
9020 /* allocate the MSI-X vectors */
9021 for (i = 0; i < num_allocated; i++) {
9022 sc->intr[i].rid = (rid + i);
9024 if ((sc->intr[i].resource =
9025 bus_alloc_resource_any(sc->dev,
9028 RF_ACTIVE)) == NULL) {
9029 BLOGE(sc, "Failed to map MSI-X[%d] (rid=%d)!\n",
9032 for (j = (i - 1); j >= 0; j--) {
9033 bus_release_resource(sc->dev,
9036 sc->intr[j].resource);
9041 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */
9042 pci_release_msi(sc->dev);
9046 BLOGD(sc, DBG_LOAD, "Mapped MSI-X[%d] (rid=%d)\n", i, (rid + i));
9050 do { /* try allocating MSI vector resources (at least 2) */
9051 if (sc->interrupt_mode != INTR_MODE_MSI) {
9055 if (((sc->devinfo.pcie_cap_flags & BXE_MSI_CAPABLE_FLAG) == 0) ||
9057 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */
9061 /* ask for a single MSI vector */
9064 BLOGD(sc, DBG_LOAD, "Requesting %d MSI vectors\n", num_requested);
9066 num_allocated = num_requested;
9067 if ((rc = pci_alloc_msi(sc->dev, &num_allocated)) != 0) {
9068 BLOGE(sc, "MSI alloc failed (%d)!\n", rc);
9069 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */
9073 if (num_allocated != 1) { /* possible? */
9074 BLOGE(sc, "MSI allocation is not 1!\n");
9075 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */
9076 pci_release_msi(sc->dev);
9080 BLOGI(sc, "MSI vectors Requested %d and Allocated %d\n",
9081 num_requested, num_allocated);
9083 /* best effort so use the number of vectors allocated to us */
9084 sc->intr_count = num_allocated;
9085 sc->num_queues = num_allocated;
9087 rid = 1; /* initial resource identifier */
9089 sc->intr[0].rid = rid;
9091 if ((sc->intr[0].resource =
9092 bus_alloc_resource_any(sc->dev,
9095 RF_ACTIVE)) == NULL) {
9096 BLOGE(sc, "Failed to map MSI[0] (rid=%d)!\n", rid);
9099 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */
9100 pci_release_msi(sc->dev);
9104 BLOGD(sc, DBG_LOAD, "Mapped MSI[0] (rid=%d)\n", rid);
9107 do { /* try allocating INTx vector resources */
9108 if (sc->interrupt_mode != INTR_MODE_INTX) {
9112 BLOGD(sc, DBG_LOAD, "Requesting legacy INTx interrupt\n");
9114 /* only one vector for INTx */
9118 rid = 0; /* initial resource identifier */
9120 sc->intr[0].rid = rid;
9122 if ((sc->intr[0].resource =
9123 bus_alloc_resource_any(sc->dev,
9126 (RF_ACTIVE | RF_SHAREABLE))) == NULL) {
9127 BLOGE(sc, "Failed to map INTx (rid=%d)!\n", rid);
9130 sc->interrupt_mode = -1; /* Failed! */
9134 BLOGD(sc, DBG_LOAD, "Mapped INTx (rid=%d)\n", rid);
9137 if (sc->interrupt_mode == -1) {
9138 BLOGE(sc, "Interrupt Allocation: FAILED!!!\n");
9142 "Interrupt Allocation: interrupt_mode=%d, num_queues=%d\n",
9143 sc->interrupt_mode, sc->num_queues);
9151 bxe_interrupt_detach(struct bxe_softc *sc)
9153 struct bxe_fastpath *fp;
9156 /* release interrupt resources */
9157 for (i = 0; i < sc->intr_count; i++) {
9158 if (sc->intr[i].resource && sc->intr[i].tag) {
9159 BLOGD(sc, DBG_LOAD, "Disabling interrupt vector %d\n", i);
9160 bus_teardown_intr(sc->dev, sc->intr[i].resource, sc->intr[i].tag);
9164 for (i = 0; i < sc->num_queues; i++) {
9167 taskqueue_drain(fp->tq, &fp->tq_task);
9168 taskqueue_free(fp->tq);
9175 taskqueue_drain(sc->sp_tq, &sc->sp_tq_task);
9176 taskqueue_free(sc->sp_tq);
9182 * Enables interrupts and attach to the ISR.
9184 * When using multiple MSI/MSI-X vectors the first vector
9185 * is used for slowpath operations while all remaining
9186 * vectors are used for fastpath operations. If only a
9187 * single MSI/MSI-X vector is used (SINGLE_ISR) then the
9188 * ISR must look for both slowpath and fastpath completions.
9191 bxe_interrupt_attach(struct bxe_softc *sc)
9193 struct bxe_fastpath *fp;
9197 snprintf(sc->sp_tq_name, sizeof(sc->sp_tq_name),
9198 "bxe%d_sp_tq", sc->unit);
9199 TASK_INIT(&sc->sp_tq_task, 0, bxe_handle_sp_tq, sc);
9200 sc->sp_tq = taskqueue_create_fast(sc->sp_tq_name, M_NOWAIT,
9201 taskqueue_thread_enqueue,
9203 taskqueue_start_threads(&sc->sp_tq, 1, PWAIT, /* lower priority */
9204 "%s", sc->sp_tq_name);
9207 for (i = 0; i < sc->num_queues; i++) {
9209 snprintf(fp->tq_name, sizeof(fp->tq_name),
9210 "bxe%d_fp%d_tq", sc->unit, i);
9211 TASK_INIT(&fp->tq_task, 0, bxe_handle_fp_tq, fp);
9212 fp->tq = taskqueue_create_fast(fp->tq_name, M_NOWAIT,
9213 taskqueue_thread_enqueue,
9215 taskqueue_start_threads(&fp->tq, 1, PI_NET, /* higher priority */
9219 /* setup interrupt handlers */
9220 if (sc->interrupt_mode == INTR_MODE_MSIX) {
9221 BLOGD(sc, DBG_LOAD, "Enabling slowpath MSI-X[0] vector\n");
9224 * Setup the interrupt handler. Note that we pass the driver instance
9225 * to the interrupt handler for the slowpath.
9227 if ((rc = bus_setup_intr(sc->dev, sc->intr[0].resource,
9228 (INTR_TYPE_NET | INTR_MPSAFE),
9229 NULL, bxe_intr_sp, sc,
9230 &sc->intr[0].tag)) != 0) {
9231 BLOGE(sc, "Failed to allocate MSI-X[0] vector (%d)\n", rc);
9232 goto bxe_interrupt_attach_exit;
9235 bus_describe_intr(sc->dev, sc->intr[0].resource,
9236 sc->intr[0].tag, "sp");
9238 /* bus_bind_intr(sc->dev, sc->intr[0].resource, 0); */
9240 /* initialize the fastpath vectors (note the first was used for sp) */
9241 for (i = 0; i < sc->num_queues; i++) {
9243 BLOGD(sc, DBG_LOAD, "Enabling MSI-X[%d] vector\n", (i + 1));
9246 * Setup the interrupt handler. Note that we pass the
9247 * fastpath context to the interrupt handler in this
9250 if ((rc = bus_setup_intr(sc->dev, sc->intr[i + 1].resource,
9251 (INTR_TYPE_NET | INTR_MPSAFE),
9252 NULL, bxe_intr_fp, fp,
9253 &sc->intr[i + 1].tag)) != 0) {
9254 BLOGE(sc, "Failed to allocate MSI-X[%d] vector (%d)\n",
9256 goto bxe_interrupt_attach_exit;
9259 bus_describe_intr(sc->dev, sc->intr[i + 1].resource,
9260 sc->intr[i + 1].tag, "fp%02d", i);
9262 /* bind the fastpath instance to a cpu */
9263 if (sc->num_queues > 1) {
9264 bus_bind_intr(sc->dev, sc->intr[i + 1].resource, i);
9267 fp->state = BXE_FP_STATE_IRQ;
9269 } else if (sc->interrupt_mode == INTR_MODE_MSI) {
9270 BLOGD(sc, DBG_LOAD, "Enabling MSI[0] vector\n");
9273 * Setup the interrupt handler. Note that we pass the
9274 * driver instance to the interrupt handler which
9275 * will handle both the slowpath and fastpath.
9277 if ((rc = bus_setup_intr(sc->dev, sc->intr[0].resource,
9278 (INTR_TYPE_NET | INTR_MPSAFE),
9279 NULL, bxe_intr_legacy, sc,
9280 &sc->intr[0].tag)) != 0) {
9281 BLOGE(sc, "Failed to allocate MSI[0] vector (%d)\n", rc);
9282 goto bxe_interrupt_attach_exit;
9285 } else { /* (sc->interrupt_mode == INTR_MODE_INTX) */
9286 BLOGD(sc, DBG_LOAD, "Enabling INTx interrupts\n");
9289 * Setup the interrupt handler. Note that we pass the
9290 * driver instance to the interrupt handler which
9291 * will handle both the slowpath and fastpath.
9293 if ((rc = bus_setup_intr(sc->dev, sc->intr[0].resource,
9294 (INTR_TYPE_NET | INTR_MPSAFE),
9295 NULL, bxe_intr_legacy, sc,
9296 &sc->intr[0].tag)) != 0) {
9297 BLOGE(sc, "Failed to allocate INTx interrupt (%d)\n", rc);
9298 goto bxe_interrupt_attach_exit;
9302 bxe_interrupt_attach_exit:
9307 static int bxe_init_hw_common_chip(struct bxe_softc *sc);
9308 static int bxe_init_hw_common(struct bxe_softc *sc);
9309 static int bxe_init_hw_port(struct bxe_softc *sc);
9310 static int bxe_init_hw_func(struct bxe_softc *sc);
9311 static void bxe_reset_common(struct bxe_softc *sc);
9312 static void bxe_reset_port(struct bxe_softc *sc);
9313 static void bxe_reset_func(struct bxe_softc *sc);
9314 static int bxe_gunzip_init(struct bxe_softc *sc);
9315 static void bxe_gunzip_end(struct bxe_softc *sc);
9316 static int bxe_init_firmware(struct bxe_softc *sc);
9317 static void bxe_release_firmware(struct bxe_softc *sc);
9320 ecore_func_sp_drv_ops bxe_func_sp_drv = {
9321 .init_hw_cmn_chip = bxe_init_hw_common_chip,
9322 .init_hw_cmn = bxe_init_hw_common,
9323 .init_hw_port = bxe_init_hw_port,
9324 .init_hw_func = bxe_init_hw_func,
9326 .reset_hw_cmn = bxe_reset_common,
9327 .reset_hw_port = bxe_reset_port,
9328 .reset_hw_func = bxe_reset_func,
9330 .gunzip_init = bxe_gunzip_init,
9331 .gunzip_end = bxe_gunzip_end,
9333 .init_fw = bxe_init_firmware,
9334 .release_fw = bxe_release_firmware,
9338 bxe_init_func_obj(struct bxe_softc *sc)
9342 ecore_init_func_obj(sc,
9344 BXE_SP(sc, func_rdata),
9345 BXE_SP_MAPPING(sc, func_rdata),
9346 BXE_SP(sc, func_afex_rdata),
9347 BXE_SP_MAPPING(sc, func_afex_rdata),
9352 bxe_init_hw(struct bxe_softc *sc,
9355 struct ecore_func_state_params func_params = { NULL };
9358 /* prepare the parameters for function state transitions */
9359 bit_set(&func_params.ramrod_flags, RAMROD_COMP_WAIT);
9361 func_params.f_obj = &sc->func_obj;
9362 func_params.cmd = ECORE_F_CMD_HW_INIT;
9364 func_params.params.hw_init.load_phase = load_code;
9367 * Via a plethora of function pointers, we will eventually reach
9368 * bxe_init_hw_common(), bxe_init_hw_port(), or bxe_init_hw_func().
9370 rc = ecore_func_state_change(sc, &func_params);
9376 bxe_fill(struct bxe_softc *sc,
9383 if (!(len % 4) && !(addr % 4)) {
9384 for (i = 0; i < len; i += 4) {
9385 REG_WR(sc, (addr + i), fill);
9388 for (i = 0; i < len; i++) {
9389 REG_WR8(sc, (addr + i), fill);
9394 /* writes FP SP data to FW - data_size in dwords */
9396 bxe_wr_fp_sb_data(struct bxe_softc *sc,
9398 uint32_t *sb_data_p,
9403 for (index = 0; index < data_size; index++) {
9405 (BAR_CSTRORM_INTMEM +
9406 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
9407 (sizeof(uint32_t) * index)),
9408 *(sb_data_p + index));
9413 bxe_zero_fp_sb(struct bxe_softc *sc,
9416 struct hc_status_block_data_e2 sb_data_e2;
9417 struct hc_status_block_data_e1x sb_data_e1x;
9418 uint32_t *sb_data_p;
9419 uint32_t data_size = 0;
9421 if (!CHIP_IS_E1x(sc)) {
9422 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
9423 sb_data_e2.common.state = SB_DISABLED;
9424 sb_data_e2.common.p_func.vf_valid = FALSE;
9425 sb_data_p = (uint32_t *)&sb_data_e2;
9426 data_size = (sizeof(struct hc_status_block_data_e2) /
9429 memset(&sb_data_e1x, 0, sizeof(struct hc_status_block_data_e1x));
9430 sb_data_e1x.common.state = SB_DISABLED;
9431 sb_data_e1x.common.p_func.vf_valid = FALSE;
9432 sb_data_p = (uint32_t *)&sb_data_e1x;
9433 data_size = (sizeof(struct hc_status_block_data_e1x) /
9437 bxe_wr_fp_sb_data(sc, fw_sb_id, sb_data_p, data_size);
9439 bxe_fill(sc, (BAR_CSTRORM_INTMEM + CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id)),
9440 0, CSTORM_STATUS_BLOCK_SIZE);
9441 bxe_fill(sc, (BAR_CSTRORM_INTMEM + CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id)),
9442 0, CSTORM_SYNC_BLOCK_SIZE);
9446 bxe_wr_sp_sb_data(struct bxe_softc *sc,
9447 struct hc_sp_status_block_data *sp_sb_data)
9452 i < (sizeof(struct hc_sp_status_block_data) / sizeof(uint32_t));
9455 (BAR_CSTRORM_INTMEM +
9456 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(SC_FUNC(sc)) +
9457 (i * sizeof(uint32_t))),
9458 *((uint32_t *)sp_sb_data + i));
9463 bxe_zero_sp_sb(struct bxe_softc *sc)
9465 struct hc_sp_status_block_data sp_sb_data;
9467 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
9469 sp_sb_data.state = SB_DISABLED;
9470 sp_sb_data.p_func.vf_valid = FALSE;
9472 bxe_wr_sp_sb_data(sc, &sp_sb_data);
9475 (BAR_CSTRORM_INTMEM +
9476 CSTORM_SP_STATUS_BLOCK_OFFSET(SC_FUNC(sc))),
9477 0, CSTORM_SP_STATUS_BLOCK_SIZE);
9479 (BAR_CSTRORM_INTMEM +
9480 CSTORM_SP_SYNC_BLOCK_OFFSET(SC_FUNC(sc))),
9481 0, CSTORM_SP_SYNC_BLOCK_SIZE);
9485 bxe_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
9489 hc_sm->igu_sb_id = igu_sb_id;
9490 hc_sm->igu_seg_id = igu_seg_id;
9491 hc_sm->timer_value = 0xFF;
9492 hc_sm->time_to_expire = 0xFFFFFFFF;
9496 bxe_map_sb_state_machines(struct hc_index_data *index_data)
9498 /* zero out state machine indices */
9501 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
9504 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
9505 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
9506 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
9507 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
9512 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
9513 (SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9516 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
9517 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9518 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
9519 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9520 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
9521 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9522 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
9523 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9527 bxe_init_sb(struct bxe_softc *sc,
9534 struct hc_status_block_data_e2 sb_data_e2;
9535 struct hc_status_block_data_e1x sb_data_e1x;
9536 struct hc_status_block_sm *hc_sm_p;
9537 uint32_t *sb_data_p;
9541 if (CHIP_INT_MODE_IS_BC(sc)) {
9542 igu_seg_id = HC_SEG_ACCESS_NORM;
9544 igu_seg_id = IGU_SEG_ACCESS_NORM;
9547 bxe_zero_fp_sb(sc, fw_sb_id);
9549 if (!CHIP_IS_E1x(sc)) {
9550 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
9551 sb_data_e2.common.state = SB_ENABLED;
9552 sb_data_e2.common.p_func.pf_id = SC_FUNC(sc);
9553 sb_data_e2.common.p_func.vf_id = vfid;
9554 sb_data_e2.common.p_func.vf_valid = vf_valid;
9555 sb_data_e2.common.p_func.vnic_id = SC_VN(sc);
9556 sb_data_e2.common.same_igu_sb_1b = TRUE;
9557 sb_data_e2.common.host_sb_addr.hi = U64_HI(busaddr);
9558 sb_data_e2.common.host_sb_addr.lo = U64_LO(busaddr);
9559 hc_sm_p = sb_data_e2.common.state_machine;
9560 sb_data_p = (uint32_t *)&sb_data_e2;
9561 data_size = (sizeof(struct hc_status_block_data_e2) /
9563 bxe_map_sb_state_machines(sb_data_e2.index_data);
9565 memset(&sb_data_e1x, 0, sizeof(struct hc_status_block_data_e1x));
9566 sb_data_e1x.common.state = SB_ENABLED;
9567 sb_data_e1x.common.p_func.pf_id = SC_FUNC(sc);
9568 sb_data_e1x.common.p_func.vf_id = 0xff;
9569 sb_data_e1x.common.p_func.vf_valid = FALSE;
9570 sb_data_e1x.common.p_func.vnic_id = SC_VN(sc);
9571 sb_data_e1x.common.same_igu_sb_1b = TRUE;
9572 sb_data_e1x.common.host_sb_addr.hi = U64_HI(busaddr);
9573 sb_data_e1x.common.host_sb_addr.lo = U64_LO(busaddr);
9574 hc_sm_p = sb_data_e1x.common.state_machine;
9575 sb_data_p = (uint32_t *)&sb_data_e1x;
9576 data_size = (sizeof(struct hc_status_block_data_e1x) /
9578 bxe_map_sb_state_machines(sb_data_e1x.index_data);
9581 bxe_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID], igu_sb_id, igu_seg_id);
9582 bxe_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID], igu_sb_id, igu_seg_id);
9584 BLOGD(sc, DBG_LOAD, "Init FW SB %d\n", fw_sb_id);
9586 /* write indices to HW - PCI guarantees endianity of regpairs */
9587 bxe_wr_fp_sb_data(sc, fw_sb_id, sb_data_p, data_size);
9590 static inline uint8_t
9591 bxe_fp_qzone_id(struct bxe_fastpath *fp)
9593 if (CHIP_IS_E1x(fp->sc)) {
9594 return (fp->cl_id + SC_PORT(fp->sc) * ETH_MAX_RX_CLIENTS_E1H);
9600 static inline uint32_t
9601 bxe_rx_ustorm_prods_offset(struct bxe_softc *sc,
9602 struct bxe_fastpath *fp)
9604 uint32_t offset = BAR_USTRORM_INTMEM;
9606 if (!CHIP_IS_E1x(sc)) {
9607 offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
9609 offset += USTORM_RX_PRODS_E1X_OFFSET(SC_PORT(sc), fp->cl_id);
9616 bxe_init_eth_fp(struct bxe_softc *sc,
9619 struct bxe_fastpath *fp = &sc->fp[idx];
9620 uint32_t cids[ECORE_MULTI_TX_COS] = { 0 };
9621 unsigned long q_type = 0;
9627 fp->igu_sb_id = (sc->igu_base_sb + idx + CNIC_SUPPORT(sc));
9628 fp->fw_sb_id = (sc->base_fw_ndsb + idx + CNIC_SUPPORT(sc));
9630 fp->cl_id = (CHIP_IS_E1x(sc)) ?
9631 (SC_L_ID(sc) + idx) :
9632 /* want client ID same as IGU SB ID for non-E1 */
9634 fp->cl_qzone_id = bxe_fp_qzone_id(fp);
9636 /* setup sb indices */
9637 if (!CHIP_IS_E1x(sc)) {
9638 fp->sb_index_values = fp->status_block.e2_sb->sb.index_values;
9639 fp->sb_running_index = fp->status_block.e2_sb->sb.running_index;
9641 fp->sb_index_values = fp->status_block.e1x_sb->sb.index_values;
9642 fp->sb_running_index = fp->status_block.e1x_sb->sb.running_index;
9646 fp->ustorm_rx_prods_offset = bxe_rx_ustorm_prods_offset(sc, fp);
9648 fp->rx_cq_cons_sb = &fp->sb_index_values[HC_INDEX_ETH_RX_CQ_CONS];
9651 * XXX If multiple CoS is ever supported then each fastpath structure
9652 * will need to maintain tx producer/consumer/dma/etc values *per* CoS.
9654 for (cos = 0; cos < sc->max_cos; cos++) {
9657 fp->tx_cons_sb = &fp->sb_index_values[HC_INDEX_ETH_TX_CQ_CONS_COS0];
9659 /* nothing more for a VF to do */
9664 bxe_init_sb(sc, fp->sb_dma.paddr, BXE_VF_ID_INVALID, FALSE,
9665 fp->fw_sb_id, fp->igu_sb_id);
9667 bxe_update_fp_sb_idx(fp);
9669 /* Configure Queue State object */
9670 bit_set(&q_type, ECORE_Q_TYPE_HAS_RX);
9671 bit_set(&q_type, ECORE_Q_TYPE_HAS_TX);
9673 ecore_init_queue_obj(sc,
9674 &sc->sp_objs[idx].q_obj,
9679 BXE_SP(sc, q_rdata),
9680 BXE_SP_MAPPING(sc, q_rdata),
9683 /* configure classification DBs */
9684 ecore_init_mac_obj(sc,
9685 &sc->sp_objs[idx].mac_obj,
9689 BXE_SP(sc, mac_rdata),
9690 BXE_SP_MAPPING(sc, mac_rdata),
9691 ECORE_FILTER_MAC_PENDING,
9693 ECORE_OBJ_TYPE_RX_TX,
9696 BLOGD(sc, DBG_LOAD, "fp[%d]: sb=%p cl_id=%d fw_sb=%d igu_sb=%d\n",
9697 idx, fp->status_block.e2_sb, fp->cl_id, fp->fw_sb_id, fp->igu_sb_id);
9701 bxe_update_rx_prod(struct bxe_softc *sc,
9702 struct bxe_fastpath *fp,
9703 uint16_t rx_bd_prod,
9704 uint16_t rx_cq_prod,
9705 uint16_t rx_sge_prod)
9707 struct ustorm_eth_rx_producers rx_prods = { 0 };
9710 /* update producers */
9711 rx_prods.bd_prod = rx_bd_prod;
9712 rx_prods.cqe_prod = rx_cq_prod;
9713 rx_prods.sge_prod = rx_sge_prod;
9716 * Make sure that the BD and SGE data is updated before updating the
9717 * producers since FW might read the BD/SGE right after the producer
9719 * This is only applicable for weak-ordered memory model archs such
9720 * as IA-64. The following barrier is also mandatory since FW will
9721 * assumes BDs must have buffers.
9725 for (i = 0; i < (sizeof(rx_prods) / 4); i++) {
9727 (fp->ustorm_rx_prods_offset + (i * 4)),
9728 ((uint32_t *)&rx_prods)[i]);
9731 wmb(); /* keep prod updates ordered */
9734 "RX fp[%d]: wrote prods bd_prod=%u cqe_prod=%u sge_prod=%u\n",
9735 fp->index, rx_bd_prod, rx_cq_prod, rx_sge_prod);
9739 bxe_init_rx_rings(struct bxe_softc *sc)
9741 struct bxe_fastpath *fp;
9744 for (i = 0; i < sc->num_queues; i++) {
9750 * Activate the BD ring...
9751 * Warning, this will generate an interrupt (to the TSTORM)
9752 * so this can only be done after the chip is initialized
9754 bxe_update_rx_prod(sc, fp,
9763 if (CHIP_IS_E1(sc)) {
9765 (BAR_USTRORM_INTMEM +
9766 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(SC_FUNC(sc))),
9767 U64_LO(fp->rcq_dma.paddr));
9769 (BAR_USTRORM_INTMEM +
9770 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(SC_FUNC(sc)) + 4),
9771 U64_HI(fp->rcq_dma.paddr));
9777 bxe_init_tx_ring_one(struct bxe_fastpath *fp)
9779 SET_FLAG(fp->tx_db.data.header.data, DOORBELL_HDR_T_DB_TYPE, 1);
9780 fp->tx_db.data.zero_fill1 = 0;
9781 fp->tx_db.data.prod = 0;
9783 fp->tx_pkt_prod = 0;
9784 fp->tx_pkt_cons = 0;
9787 fp->eth_q_stats.tx_pkts = 0;
9791 bxe_init_tx_rings(struct bxe_softc *sc)
9795 for (i = 0; i < sc->num_queues; i++) {
9796 bxe_init_tx_ring_one(&sc->fp[i]);
9801 bxe_init_def_sb(struct bxe_softc *sc)
9803 struct host_sp_status_block *def_sb = sc->def_sb;
9804 bus_addr_t mapping = sc->def_sb_dma.paddr;
9805 int igu_sp_sb_index;
9807 int port = SC_PORT(sc);
9808 int func = SC_FUNC(sc);
9809 int reg_offset, reg_offset_en5;
9812 struct hc_sp_status_block_data sp_sb_data;
9814 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
9816 if (CHIP_INT_MODE_IS_BC(sc)) {
9817 igu_sp_sb_index = DEF_SB_IGU_ID;
9818 igu_seg_id = HC_SEG_ACCESS_DEF;
9820 igu_sp_sb_index = sc->igu_dsb_id;
9821 igu_seg_id = IGU_SEG_ACCESS_DEF;
9825 section = ((uint64_t)mapping +
9826 offsetof(struct host_sp_status_block, atten_status_block));
9827 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
9830 reg_offset = (port) ?
9831 MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
9832 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
9833 reg_offset_en5 = (port) ?
9834 MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
9835 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0;
9837 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
9838 /* take care of sig[0]..sig[4] */
9839 for (sindex = 0; sindex < 4; sindex++) {
9840 sc->attn_group[index].sig[sindex] =
9841 REG_RD(sc, (reg_offset + (sindex * 0x4) + (0x10 * index)));
9844 if (!CHIP_IS_E1x(sc)) {
9846 * enable5 is separate from the rest of the registers,
9847 * and the address skip is 4 and not 16 between the
9850 sc->attn_group[index].sig[4] =
9851 REG_RD(sc, (reg_offset_en5 + (0x4 * index)));
9853 sc->attn_group[index].sig[4] = 0;
9857 if (sc->devinfo.int_block == INT_BLOCK_HC) {
9858 reg_offset = (port) ?
9859 HC_REG_ATTN_MSG1_ADDR_L :
9860 HC_REG_ATTN_MSG0_ADDR_L;
9861 REG_WR(sc, reg_offset, U64_LO(section));
9862 REG_WR(sc, (reg_offset + 4), U64_HI(section));
9863 } else if (!CHIP_IS_E1x(sc)) {
9864 REG_WR(sc, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
9865 REG_WR(sc, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
9868 section = ((uint64_t)mapping +
9869 offsetof(struct host_sp_status_block, sp_sb));
9873 /* PCI guarantees endianity of regpair */
9874 sp_sb_data.state = SB_ENABLED;
9875 sp_sb_data.host_sb_addr.lo = U64_LO(section);
9876 sp_sb_data.host_sb_addr.hi = U64_HI(section);
9877 sp_sb_data.igu_sb_id = igu_sp_sb_index;
9878 sp_sb_data.igu_seg_id = igu_seg_id;
9879 sp_sb_data.p_func.pf_id = func;
9880 sp_sb_data.p_func.vnic_id = SC_VN(sc);
9881 sp_sb_data.p_func.vf_id = 0xff;
9883 bxe_wr_sp_sb_data(sc, &sp_sb_data);
9885 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
9889 bxe_init_sp_ring(struct bxe_softc *sc)
9891 atomic_store_rel_long(&sc->cq_spq_left, MAX_SPQ_PENDING);
9892 sc->spq_prod_idx = 0;
9893 sc->dsb_sp_prod = &sc->def_sb->sp_sb.index_values[HC_SP_INDEX_ETH_DEF_CONS];
9894 sc->spq_prod_bd = sc->spq;
9895 sc->spq_last_bd = (sc->spq_prod_bd + MAX_SP_DESC_CNT);
9899 bxe_init_eq_ring(struct bxe_softc *sc)
9901 union event_ring_elem *elem;
9904 for (i = 1; i <= NUM_EQ_PAGES; i++) {
9905 elem = &sc->eq[EQ_DESC_CNT_PAGE * i - 1];
9907 elem->next_page.addr.hi = htole32(U64_HI(sc->eq_dma.paddr +
9909 (i % NUM_EQ_PAGES)));
9910 elem->next_page.addr.lo = htole32(U64_LO(sc->eq_dma.paddr +
9912 (i % NUM_EQ_PAGES)));
9916 sc->eq_prod = NUM_EQ_DESC;
9917 sc->eq_cons_sb = &sc->def_sb->sp_sb.index_values[HC_SP_INDEX_EQ_CONS];
9919 atomic_store_rel_long(&sc->eq_spq_left,
9920 (min((MAX_SP_DESC_CNT - MAX_SPQ_PENDING),
9925 bxe_init_internal_common(struct bxe_softc *sc)
9931 * In switch independent mode, the TSTORM needs to accept
9932 * packets that failed classification, since approximate match
9933 * mac addresses aren't written to NIG LLH.
9936 (BAR_TSTRORM_INTMEM + TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET),
9938 } else if (!CHIP_IS_E1(sc)) { /* 57710 doesn't support MF */
9940 (BAR_TSTRORM_INTMEM + TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET),
9945 * Zero this manually as its initialization is currently missing
9948 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++) {
9950 (BAR_USTRORM_INTMEM + USTORM_AGG_DATA_OFFSET + (i * 4)),
9954 if (!CHIP_IS_E1x(sc)) {
9955 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET),
9956 CHIP_INT_MODE_IS_BC(sc) ? HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
9961 bxe_init_internal(struct bxe_softc *sc,
9964 switch (load_code) {
9965 case FW_MSG_CODE_DRV_LOAD_COMMON:
9966 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
9967 bxe_init_internal_common(sc);
9970 case FW_MSG_CODE_DRV_LOAD_PORT:
9974 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
9975 /* internal memory per function is initialized inside bxe_pf_init */
9979 BLOGE(sc, "Unknown load_code (0x%x) from MCP\n", load_code);
9985 storm_memset_func_cfg(struct bxe_softc *sc,
9986 struct tstorm_eth_function_common_config *tcfg,
9992 addr = (BAR_TSTRORM_INTMEM +
9993 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid));
9994 size = sizeof(struct tstorm_eth_function_common_config);
9995 ecore_storm_memset_struct(sc, addr, size, (uint32_t *)tcfg);
9999 bxe_func_init(struct bxe_softc *sc,
10000 struct bxe_func_init_params *p)
10002 struct tstorm_eth_function_common_config tcfg = { 0 };
10004 if (CHIP_IS_E1x(sc)) {
10005 storm_memset_func_cfg(sc, &tcfg, p->func_id);
10008 /* Enable the function in the FW */
10009 storm_memset_vf_to_pf(sc, p->func_id, p->pf_id);
10010 storm_memset_func_en(sc, p->func_id, 1);
10013 if (p->func_flgs & FUNC_FLG_SPQ) {
10014 storm_memset_spq_addr(sc, p->spq_map, p->func_id);
10016 (XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PROD_OFFSET(p->func_id)),
10022 * Calculates the sum of vn_min_rates.
10023 * It's needed for further normalizing of the min_rates.
10025 * sum of vn_min_rates.
10027 * 0 - if all the min_rates are 0.
10028 * In the later case fainess algorithm should be deactivated.
10029 * If all min rates are not zero then those that are zeroes will be set to 1.
10032 bxe_calc_vn_min(struct bxe_softc *sc,
10033 struct cmng_init_input *input)
10036 uint32_t vn_min_rate;
10040 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
10041 vn_cfg = sc->devinfo.mf_info.mf_config[vn];
10042 vn_min_rate = (((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
10043 FUNC_MF_CFG_MIN_BW_SHIFT) * 100);
10045 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
10046 /* skip hidden VNs */
10048 } else if (!vn_min_rate) {
10049 /* If min rate is zero - set it to 100 */
10050 vn_min_rate = DEF_MIN_RATE;
10055 input->vnic_min_rate[vn] = vn_min_rate;
10058 /* if ETS or all min rates are zeros - disable fairness */
10059 if (BXE_IS_ETS_ENABLED(sc)) {
10060 input->flags.cmng_enables &= ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
10061 BLOGD(sc, DBG_LOAD, "Fairness disabled (ETS)\n");
10062 } else if (all_zero) {
10063 input->flags.cmng_enables &= ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
10064 BLOGD(sc, DBG_LOAD,
10065 "Fariness disabled (all MIN values are zeroes)\n");
10067 input->flags.cmng_enables |= CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
10071 static inline uint16_t
10072 bxe_extract_max_cfg(struct bxe_softc *sc,
10075 uint16_t max_cfg = ((mf_cfg & FUNC_MF_CFG_MAX_BW_MASK) >>
10076 FUNC_MF_CFG_MAX_BW_SHIFT);
10079 BLOGD(sc, DBG_LOAD, "Max BW configured to 0 - using 100 instead\n");
10087 bxe_calc_vn_max(struct bxe_softc *sc,
10089 struct cmng_init_input *input)
10091 uint16_t vn_max_rate;
10092 uint32_t vn_cfg = sc->devinfo.mf_info.mf_config[vn];
10095 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
10098 max_cfg = bxe_extract_max_cfg(sc, vn_cfg);
10100 if (IS_MF_SI(sc)) {
10101 /* max_cfg in percents of linkspeed */
10102 vn_max_rate = ((sc->link_vars.line_speed * max_cfg) / 100);
10103 } else { /* SD modes */
10104 /* max_cfg is absolute in 100Mb units */
10105 vn_max_rate = (max_cfg * 100);
10109 BLOGD(sc, DBG_LOAD, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
10111 input->vnic_max_rate[vn] = vn_max_rate;
10115 bxe_cmng_fns_init(struct bxe_softc *sc,
10119 struct cmng_init_input input;
10122 memset(&input, 0, sizeof(struct cmng_init_input));
10124 input.port_rate = sc->link_vars.line_speed;
10126 if (cmng_type == CMNG_FNS_MINMAX) {
10127 /* read mf conf from shmem */
10129 bxe_read_mf_cfg(sc);
10132 /* get VN min rate and enable fairness if not 0 */
10133 bxe_calc_vn_min(sc, &input);
10135 /* get VN max rate */
10136 if (sc->port.pmf) {
10137 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
10138 bxe_calc_vn_max(sc, vn, &input);
10142 /* always enable rate shaping and fairness */
10143 input.flags.cmng_enables |= CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
10145 ecore_init_cmng(&input, &sc->cmng);
10149 /* rate shaping and fairness are disabled */
10150 BLOGD(sc, DBG_LOAD, "rate shaping and fairness have been disabled\n");
10154 bxe_get_cmng_fns_mode(struct bxe_softc *sc)
10156 if (CHIP_REV_IS_SLOW(sc)) {
10157 return (CMNG_FNS_NONE);
10161 return (CMNG_FNS_MINMAX);
10164 return (CMNG_FNS_NONE);
10168 storm_memset_cmng(struct bxe_softc *sc,
10169 struct cmng_init *cmng,
10177 addr = (BAR_XSTRORM_INTMEM +
10178 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port));
10179 size = sizeof(struct cmng_struct_per_port);
10180 ecore_storm_memset_struct(sc, addr, size, (uint32_t *)&cmng->port);
10182 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
10183 func = func_by_vn(sc, vn);
10185 addr = (BAR_XSTRORM_INTMEM +
10186 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func));
10187 size = sizeof(struct rate_shaping_vars_per_vn);
10188 ecore_storm_memset_struct(sc, addr, size,
10189 (uint32_t *)&cmng->vnic.vnic_max_rate[vn]);
10191 addr = (BAR_XSTRORM_INTMEM +
10192 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func));
10193 size = sizeof(struct fairness_vars_per_vn);
10194 ecore_storm_memset_struct(sc, addr, size,
10195 (uint32_t *)&cmng->vnic.vnic_min_rate[vn]);
10200 bxe_pf_init(struct bxe_softc *sc)
10202 struct bxe_func_init_params func_init = { 0 };
10203 struct event_ring_data eq_data = { { 0 } };
10206 if (!CHIP_IS_E1x(sc)) {
10207 /* reset IGU PF statistics: MSIX + ATTN */
10210 (IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
10211 (BXE_IGU_STAS_MSG_VF_CNT * 4) +
10212 ((CHIP_IS_MODE_4_PORT(sc) ? SC_FUNC(sc) : SC_VN(sc)) * 4)),
10216 (IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
10217 (BXE_IGU_STAS_MSG_VF_CNT * 4) +
10218 (BXE_IGU_STAS_MSG_PF_CNT * 4) +
10219 ((CHIP_IS_MODE_4_PORT(sc) ? SC_FUNC(sc) : SC_VN(sc)) * 4)),
10223 /* function setup flags */
10224 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
10227 * This flag is relevant for E1x only.
10228 * E2 doesn't have a TPA configuration in a function level.
10230 flags |= (sc->ifnet->if_capenable & IFCAP_LRO) ? FUNC_FLG_TPA : 0;
10232 func_init.func_flgs = flags;
10233 func_init.pf_id = SC_FUNC(sc);
10234 func_init.func_id = SC_FUNC(sc);
10235 func_init.spq_map = sc->spq_dma.paddr;
10236 func_init.spq_prod = sc->spq_prod_idx;
10238 bxe_func_init(sc, &func_init);
10240 memset(&sc->cmng, 0, sizeof(struct cmng_struct_per_port));
10243 * Congestion management values depend on the link rate.
10244 * There is no active link so initial link rate is set to 10Gbps.
10245 * When the link comes up the congestion management values are
10246 * re-calculated according to the actual link rate.
10248 sc->link_vars.line_speed = SPEED_10000;
10249 bxe_cmng_fns_init(sc, TRUE, bxe_get_cmng_fns_mode(sc));
10251 /* Only the PMF sets the HW */
10252 if (sc->port.pmf) {
10253 storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc));
10256 /* init Event Queue - PCI bus guarantees correct endainity */
10257 eq_data.base_addr.hi = U64_HI(sc->eq_dma.paddr);
10258 eq_data.base_addr.lo = U64_LO(sc->eq_dma.paddr);
10259 eq_data.producer = sc->eq_prod;
10260 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
10261 eq_data.sb_id = DEF_SB_ID;
10262 storm_memset_eq_data(sc, &eq_data, SC_FUNC(sc));
10266 bxe_hc_int_enable(struct bxe_softc *sc)
10268 int port = SC_PORT(sc);
10269 uint32_t addr = (port) ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
10270 uint32_t val = REG_RD(sc, addr);
10271 uint8_t msix = (sc->interrupt_mode == INTR_MODE_MSIX) ? TRUE : FALSE;
10272 uint8_t single_msix = ((sc->interrupt_mode == INTR_MODE_MSIX) &&
10273 (sc->intr_count == 1)) ? TRUE : FALSE;
10274 uint8_t msi = (sc->interrupt_mode == INTR_MODE_MSI) ? TRUE : FALSE;
10277 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10278 HC_CONFIG_0_REG_INT_LINE_EN_0);
10279 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
10280 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10282 val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
10285 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
10286 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10287 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
10288 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10290 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10291 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
10292 HC_CONFIG_0_REG_INT_LINE_EN_0 |
10293 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10295 if (!CHIP_IS_E1(sc)) {
10296 BLOGD(sc, DBG_INTR, "write %x to HC %d (addr 0x%x)\n",
10299 REG_WR(sc, addr, val);
10301 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
10305 if (CHIP_IS_E1(sc)) {
10306 REG_WR(sc, (HC_REG_INT_MASK + port*4), 0x1FFFF);
10309 BLOGD(sc, DBG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n",
10310 val, port, addr, ((msix) ? "MSI-X" : ((msi) ? "MSI" : "INTx")));
10312 REG_WR(sc, addr, val);
10314 /* ensure that HC_CONFIG is written before leading/trailing edge config */
10317 if (!CHIP_IS_E1(sc)) {
10318 /* init leading/trailing edge */
10320 val = (0xee0f | (1 << (SC_VN(sc) + 4)));
10321 if (sc->port.pmf) {
10322 /* enable nig and gpio3 attention */
10329 REG_WR(sc, (HC_REG_TRAILING_EDGE_0 + port*8), val);
10330 REG_WR(sc, (HC_REG_LEADING_EDGE_0 + port*8), val);
10333 /* make sure that interrupts are indeed enabled from here on */
10338 bxe_igu_int_enable(struct bxe_softc *sc)
10341 uint8_t msix = (sc->interrupt_mode == INTR_MODE_MSIX) ? TRUE : FALSE;
10342 uint8_t single_msix = ((sc->interrupt_mode == INTR_MODE_MSIX) &&
10343 (sc->intr_count == 1)) ? TRUE : FALSE;
10344 uint8_t msi = (sc->interrupt_mode == INTR_MODE_MSI) ? TRUE : FALSE;
10346 val = REG_RD(sc, IGU_REG_PF_CONFIGURATION);
10349 val &= ~(IGU_PF_CONF_INT_LINE_EN |
10350 IGU_PF_CONF_SINGLE_ISR_EN);
10351 val |= (IGU_PF_CONF_MSI_MSIX_EN |
10352 IGU_PF_CONF_ATTN_BIT_EN);
10354 val |= IGU_PF_CONF_SINGLE_ISR_EN;
10357 val &= ~IGU_PF_CONF_INT_LINE_EN;
10358 val |= (IGU_PF_CONF_MSI_MSIX_EN |
10359 IGU_PF_CONF_ATTN_BIT_EN |
10360 IGU_PF_CONF_SINGLE_ISR_EN);
10362 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
10363 val |= (IGU_PF_CONF_INT_LINE_EN |
10364 IGU_PF_CONF_ATTN_BIT_EN |
10365 IGU_PF_CONF_SINGLE_ISR_EN);
10368 /* clean previous status - need to configure igu prior to ack*/
10369 if ((!msix) || single_msix) {
10370 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
10374 val |= IGU_PF_CONF_FUNC_EN;
10376 BLOGD(sc, DBG_INTR, "write 0x%x to IGU mode %s\n",
10377 val, ((msix) ? "MSI-X" : ((msi) ? "MSI" : "INTx")));
10379 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
10383 /* init leading/trailing edge */
10385 val = (0xee0f | (1 << (SC_VN(sc) + 4)));
10386 if (sc->port.pmf) {
10387 /* enable nig and gpio3 attention */
10394 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, val);
10395 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, val);
10397 /* make sure that interrupts are indeed enabled from here on */
10402 bxe_int_enable(struct bxe_softc *sc)
10404 if (sc->devinfo.int_block == INT_BLOCK_HC) {
10405 bxe_hc_int_enable(sc);
10407 bxe_igu_int_enable(sc);
10412 bxe_hc_int_disable(struct bxe_softc *sc)
10414 int port = SC_PORT(sc);
10415 uint32_t addr = (port) ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
10416 uint32_t val = REG_RD(sc, addr);
10419 * In E1 we must use only PCI configuration space to disable MSI/MSIX
10420 * capablility. It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC
10423 if (CHIP_IS_E1(sc)) {
10425 * Since IGU_PF_CONF_MSI_MSIX_EN still always on use mask register
10426 * to prevent from HC sending interrupts after we exit the function
10428 REG_WR(sc, (HC_REG_INT_MASK + port*4), 0);
10430 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10431 HC_CONFIG_0_REG_INT_LINE_EN_0 |
10432 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10434 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10435 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
10436 HC_CONFIG_0_REG_INT_LINE_EN_0 |
10437 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10440 BLOGD(sc, DBG_INTR, "write %x to HC %d (addr 0x%x)\n", val, port, addr);
10442 /* flush all outstanding writes */
10445 REG_WR(sc, addr, val);
10446 if (REG_RD(sc, addr) != val) {
10447 BLOGE(sc, "proper val not read from HC IGU!\n");
10452 bxe_igu_int_disable(struct bxe_softc *sc)
10454 uint32_t val = REG_RD(sc, IGU_REG_PF_CONFIGURATION);
10456 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
10457 IGU_PF_CONF_INT_LINE_EN |
10458 IGU_PF_CONF_ATTN_BIT_EN);
10460 BLOGD(sc, DBG_INTR, "write %x to IGU\n", val);
10462 /* flush all outstanding writes */
10465 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
10466 if (REG_RD(sc, IGU_REG_PF_CONFIGURATION) != val) {
10467 BLOGE(sc, "proper val not read from IGU!\n");
10472 bxe_int_disable(struct bxe_softc *sc)
10474 if (sc->devinfo.int_block == INT_BLOCK_HC) {
10475 bxe_hc_int_disable(sc);
10477 bxe_igu_int_disable(sc);
10482 bxe_nic_init(struct bxe_softc *sc,
10487 for (i = 0; i < sc->num_queues; i++) {
10488 bxe_init_eth_fp(sc, i);
10491 rmb(); /* ensure status block indices were read */
10493 bxe_init_rx_rings(sc);
10494 bxe_init_tx_rings(sc);
10500 /* initialize MOD_ABS interrupts */
10501 elink_init_mod_abs_int(sc, &sc->link_vars,
10502 sc->devinfo.chip_id,
10503 sc->devinfo.shmem_base,
10504 sc->devinfo.shmem2_base,
10507 bxe_init_def_sb(sc);
10508 bxe_update_dsb_idx(sc);
10509 bxe_init_sp_ring(sc);
10510 bxe_init_eq_ring(sc);
10511 bxe_init_internal(sc, load_code);
10513 bxe_stats_init(sc);
10515 /* flush all before enabling interrupts */
10518 bxe_int_enable(sc);
10520 /* check for SPIO5 */
10521 bxe_attn_int_deasserted0(sc,
10523 (MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
10525 AEU_INPUTS_ATTN_BITS_SPIO5);
10529 bxe_init_objs(struct bxe_softc *sc)
10531 /* mcast rules must be added to tx if tx switching is enabled */
10532 ecore_obj_type o_type =
10533 (sc->flags & BXE_TX_SWITCHING) ? ECORE_OBJ_TYPE_RX_TX :
10536 /* RX_MODE controlling object */
10537 ecore_init_rx_mode_obj(sc, &sc->rx_mode_obj);
10539 /* multicast configuration controlling object */
10540 ecore_init_mcast_obj(sc,
10546 BXE_SP(sc, mcast_rdata),
10547 BXE_SP_MAPPING(sc, mcast_rdata),
10548 ECORE_FILTER_MCAST_PENDING,
10552 /* Setup CAM credit pools */
10553 ecore_init_mac_credit_pool(sc,
10556 CHIP_IS_E1x(sc) ? VNICS_PER_PORT(sc) :
10557 VNICS_PER_PATH(sc));
10559 ecore_init_vlan_credit_pool(sc,
10561 SC_ABS_FUNC(sc) >> 1,
10562 CHIP_IS_E1x(sc) ? VNICS_PER_PORT(sc) :
10563 VNICS_PER_PATH(sc));
10565 /* RSS configuration object */
10566 ecore_init_rss_config_obj(sc,
10572 BXE_SP(sc, rss_rdata),
10573 BXE_SP_MAPPING(sc, rss_rdata),
10574 ECORE_FILTER_RSS_CONF_PENDING,
10575 &sc->sp_state, ECORE_OBJ_TYPE_RX);
10579 * Initialize the function. This must be called before sending CLIENT_SETUP
10580 * for the first client.
10583 bxe_func_start(struct bxe_softc *sc)
10585 struct ecore_func_state_params func_params = { NULL };
10586 struct ecore_func_start_params *start_params = &func_params.params.start;
10588 /* Prepare parameters for function state transitions */
10589 bit_set(&func_params.ramrod_flags, RAMROD_COMP_WAIT);
10591 func_params.f_obj = &sc->func_obj;
10592 func_params.cmd = ECORE_F_CMD_START;
10594 /* Function parameters */
10595 start_params->mf_mode = sc->devinfo.mf_info.mf_mode;
10596 start_params->sd_vlan_tag = OVLAN(sc);
10598 if (CHIP_IS_E2(sc) || CHIP_IS_E3(sc)) {
10599 start_params->network_cos_mode = STATIC_COS;
10600 } else { /* CHIP_IS_E1X */
10601 start_params->network_cos_mode = FW_WRR;
10604 //start_params->gre_tunnel_mode = 0;
10605 //start_params->gre_tunnel_rss = 0;
10607 return (ecore_func_state_change(sc, &func_params));
10611 bxe_set_power_state(struct bxe_softc *sc,
10616 /* If there is no power capability, silently succeed */
10617 if (!(sc->devinfo.pcie_cap_flags & BXE_PM_CAPABLE_FLAG)) {
10618 BLOGW(sc, "No power capability\n");
10622 pmcsr = pci_read_config(sc->dev,
10623 (sc->devinfo.pcie_pm_cap_reg + PCIR_POWER_STATUS),
10628 pci_write_config(sc->dev,
10629 (sc->devinfo.pcie_pm_cap_reg + PCIR_POWER_STATUS),
10630 ((pmcsr & ~PCIM_PSTAT_DMASK) | PCIM_PSTAT_PME), 2);
10632 if (pmcsr & PCIM_PSTAT_DMASK) {
10633 /* delay required during transition out of D3hot */
10640 /* XXX if there are other clients above don't shut down the power */
10642 /* don't shut down the power for emulation and FPGA */
10643 if (CHIP_REV_IS_SLOW(sc)) {
10647 pmcsr &= ~PCIM_PSTAT_DMASK;
10648 pmcsr |= PCIM_PSTAT_D3;
10651 pmcsr |= PCIM_PSTAT_PMEENABLE;
10654 pci_write_config(sc->dev,
10655 (sc->devinfo.pcie_pm_cap_reg + PCIR_POWER_STATUS),
10659 * No more memory access after this point until device is brought back
10665 BLOGE(sc, "Can't support PCI power state = 0x%x pmcsr 0x%x\n",
10674 /* return true if succeeded to acquire the lock */
10676 bxe_trylock_hw_lock(struct bxe_softc *sc,
10679 uint32_t lock_status;
10680 uint32_t resource_bit = (1 << resource);
10681 int func = SC_FUNC(sc);
10682 uint32_t hw_lock_control_reg;
10684 BLOGD(sc, DBG_LOAD, "Trying to take a resource lock 0x%x\n", resource);
10686 /* Validating that the resource is within range */
10687 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
10688 BLOGD(sc, DBG_LOAD,
10689 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
10690 resource, HW_LOCK_MAX_RESOURCE_VALUE);
10695 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
10697 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
10700 /* try to acquire the lock */
10701 REG_WR(sc, hw_lock_control_reg + 4, resource_bit);
10702 lock_status = REG_RD(sc, hw_lock_control_reg);
10703 if (lock_status & resource_bit) {
10707 BLOGE(sc, "Failed to get a resource lock 0x%x func %d "
10708 "lock_status 0x%x resource_bit 0x%x\n", resource, func,
10709 lock_status, resource_bit);
10715 * Get the recovery leader resource id according to the engine this function
10716 * belongs to. Currently only only 2 engines is supported.
10719 bxe_get_leader_lock_resource(struct bxe_softc *sc)
10722 return (HW_LOCK_RESOURCE_RECOVERY_LEADER_1);
10724 return (HW_LOCK_RESOURCE_RECOVERY_LEADER_0);
10728 /* try to acquire a leader lock for current engine */
10730 bxe_trylock_leader_lock(struct bxe_softc *sc)
10732 return (bxe_trylock_hw_lock(sc, bxe_get_leader_lock_resource(sc)));
10736 bxe_release_leader_lock(struct bxe_softc *sc)
10738 return (bxe_release_hw_lock(sc, bxe_get_leader_lock_resource(sc)));
10741 /* close gates #2, #3 and #4 */
10743 bxe_set_234_gates(struct bxe_softc *sc,
10748 /* gates #2 and #4a are closed/opened for "not E1" only */
10749 if (!CHIP_IS_E1(sc)) {
10751 REG_WR(sc, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
10753 REG_WR(sc, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
10757 if (CHIP_IS_E1x(sc)) {
10758 /* prevent interrupts from HC on both ports */
10759 val = REG_RD(sc, HC_REG_CONFIG_1);
10760 REG_WR(sc, HC_REG_CONFIG_1,
10761 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
10762 (val & ~(uint32_t)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
10764 val = REG_RD(sc, HC_REG_CONFIG_0);
10765 REG_WR(sc, HC_REG_CONFIG_0,
10766 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
10767 (val & ~(uint32_t)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
10769 /* Prevent incomming interrupts in IGU */
10770 val = REG_RD(sc, IGU_REG_BLOCK_CONFIGURATION);
10772 REG_WR(sc, IGU_REG_BLOCK_CONFIGURATION,
10774 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
10775 (val & ~(uint32_t)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
10778 BLOGD(sc, DBG_LOAD, "%s gates #2, #3 and #4\n",
10779 close ? "closing" : "opening");
10784 /* poll for pending writes bit, it should get cleared in no more than 1s */
10786 bxe_er_poll_igu_vq(struct bxe_softc *sc)
10788 uint32_t cnt = 1000;
10789 uint32_t pend_bits = 0;
10792 pend_bits = REG_RD(sc, IGU_REG_PENDING_BITS_STATUS);
10794 if (pend_bits == 0) {
10799 } while (--cnt > 0);
10802 BLOGE(sc, "Still pending IGU requests bits=0x%08x!\n", pend_bits);
10809 #define SHARED_MF_CLP_MAGIC 0x80000000 /* 'magic' bit */
10812 bxe_clp_reset_prep(struct bxe_softc *sc,
10813 uint32_t *magic_val)
10815 /* Do some magic... */
10816 uint32_t val = MFCFG_RD(sc, shared_mf_config.clp_mb);
10817 *magic_val = val & SHARED_MF_CLP_MAGIC;
10818 MFCFG_WR(sc, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
10821 /* restore the value of the 'magic' bit */
10823 bxe_clp_reset_done(struct bxe_softc *sc,
10824 uint32_t magic_val)
10826 /* Restore the 'magic' bit value... */
10827 uint32_t val = MFCFG_RD(sc, shared_mf_config.clp_mb);
10828 MFCFG_WR(sc, shared_mf_config.clp_mb,
10829 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
10832 /* prepare for MCP reset, takes care of CLP configurations */
10834 bxe_reset_mcp_prep(struct bxe_softc *sc,
10835 uint32_t *magic_val)
10838 uint32_t validity_offset;
10840 /* set `magic' bit in order to save MF config */
10841 if (!CHIP_IS_E1(sc)) {
10842 bxe_clp_reset_prep(sc, magic_val);
10845 /* get shmem offset */
10846 shmem = REG_RD(sc, MISC_REG_SHARED_MEM_ADDR);
10848 offsetof(struct shmem_region, validity_map[SC_PORT(sc)]);
10850 /* Clear validity map flags */
10852 REG_WR(sc, shmem + validity_offset, 0);
10856 #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
10857 #define MCP_ONE_TIMEOUT 100 /* 100 ms */
10860 bxe_mcp_wait_one(struct bxe_softc *sc)
10862 /* special handling for emulation and FPGA (10 times longer) */
10863 if (CHIP_REV_IS_SLOW(sc)) {
10864 DELAY((MCP_ONE_TIMEOUT*10) * 1000);
10866 DELAY((MCP_ONE_TIMEOUT) * 1000);
10870 /* initialize shmem_base and waits for validity signature to appear */
10872 bxe_init_shmem(struct bxe_softc *sc)
10878 sc->devinfo.shmem_base =
10879 sc->link_params.shmem_base =
10880 REG_RD(sc, MISC_REG_SHARED_MEM_ADDR);
10882 if (sc->devinfo.shmem_base) {
10883 val = SHMEM_RD(sc, validity_map[SC_PORT(sc)]);
10884 if (val & SHR_MEM_VALIDITY_MB)
10888 bxe_mcp_wait_one(sc);
10890 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
10892 BLOGE(sc, "BAD MCP validity signature\n");
10898 bxe_reset_mcp_comp(struct bxe_softc *sc,
10899 uint32_t magic_val)
10901 int rc = bxe_init_shmem(sc);
10903 /* Restore the `magic' bit value */
10904 if (!CHIP_IS_E1(sc)) {
10905 bxe_clp_reset_done(sc, magic_val);
10912 bxe_pxp_prep(struct bxe_softc *sc)
10914 if (!CHIP_IS_E1(sc)) {
10915 REG_WR(sc, PXP2_REG_RD_START_INIT, 0);
10916 REG_WR(sc, PXP2_REG_RQ_RBC_DONE, 0);
10922 * Reset the whole chip except for:
10924 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by one reset bit)
10926 * - MISC (including AEU)
10931 bxe_process_kill_chip_reset(struct bxe_softc *sc,
10934 uint32_t not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
10935 uint32_t global_bits2, stay_reset2;
10938 * Bits that have to be set in reset_mask2 if we want to reset 'global'
10939 * (per chip) blocks.
10942 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
10943 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
10946 * Don't reset the following blocks.
10947 * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
10948 * reset, as in 4 port device they might still be owned
10949 * by the MCP (there is only one leader per path).
10952 MISC_REGISTERS_RESET_REG_1_RST_HC |
10953 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
10954 MISC_REGISTERS_RESET_REG_1_RST_PXP;
10957 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
10958 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
10959 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
10960 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
10961 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
10962 MISC_REGISTERS_RESET_REG_2_RST_GRC |
10963 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
10964 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
10965 MISC_REGISTERS_RESET_REG_2_RST_ATC |
10966 MISC_REGISTERS_RESET_REG_2_PGLC |
10967 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
10968 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
10969 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
10970 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
10971 MISC_REGISTERS_RESET_REG_2_UMAC0 |
10972 MISC_REGISTERS_RESET_REG_2_UMAC1;
10975 * Keep the following blocks in reset:
10976 * - all xxMACs are handled by the elink code.
10979 MISC_REGISTERS_RESET_REG_2_XMAC |
10980 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
10982 /* Full reset masks according to the chip */
10983 reset_mask1 = 0xffffffff;
10985 if (CHIP_IS_E1(sc))
10986 reset_mask2 = 0xffff;
10987 else if (CHIP_IS_E1H(sc))
10988 reset_mask2 = 0x1ffff;
10989 else if (CHIP_IS_E2(sc))
10990 reset_mask2 = 0xfffff;
10991 else /* CHIP_IS_E3 */
10992 reset_mask2 = 0x3ffffff;
10994 /* Don't reset global blocks unless we need to */
10996 reset_mask2 &= ~global_bits2;
10999 * In case of attention in the QM, we need to reset PXP
11000 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
11001 * because otherwise QM reset would release 'close the gates' shortly
11002 * before resetting the PXP, then the PSWRQ would send a write
11003 * request to PGLUE. Then when PXP is reset, PGLUE would try to
11004 * read the payload data from PSWWR, but PSWWR would not
11005 * respond. The write queue in PGLUE would stuck, dmae commands
11006 * would not return. Therefore it's important to reset the second
11007 * reset register (containing the
11008 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
11009 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
11012 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
11013 reset_mask2 & (~not_reset_mask2));
11015 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
11016 reset_mask1 & (~not_reset_mask1));
11021 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
11022 reset_mask2 & (~stay_reset2));
11027 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
11032 bxe_process_kill(struct bxe_softc *sc,
11037 uint32_t sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
11038 uint32_t tags_63_32 = 0;
11040 /* Empty the Tetris buffer, wait for 1s */
11042 sr_cnt = REG_RD(sc, PXP2_REG_RD_SR_CNT);
11043 blk_cnt = REG_RD(sc, PXP2_REG_RD_BLK_CNT);
11044 port_is_idle_0 = REG_RD(sc, PXP2_REG_RD_PORT_IS_IDLE_0);
11045 port_is_idle_1 = REG_RD(sc, PXP2_REG_RD_PORT_IS_IDLE_1);
11046 pgl_exp_rom2 = REG_RD(sc, PXP2_REG_PGL_EXP_ROM2);
11047 if (CHIP_IS_E3(sc)) {
11048 tags_63_32 = REG_RD(sc, PGLUE_B_REG_TAGS_63_32);
11051 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
11052 ((port_is_idle_0 & 0x1) == 0x1) &&
11053 ((port_is_idle_1 & 0x1) == 0x1) &&
11054 (pgl_exp_rom2 == 0xffffffff) &&
11055 (!CHIP_IS_E3(sc) || (tags_63_32 == 0xffffffff)))
11058 } while (cnt-- > 0);
11061 BLOGE(sc, "ERROR: Tetris buffer didn't get empty or there "
11062 "are still outstanding read requests after 1s! "
11063 "sr_cnt=0x%08x, blk_cnt=0x%08x, port_is_idle_0=0x%08x, "
11064 "port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
11065 sr_cnt, blk_cnt, port_is_idle_0,
11066 port_is_idle_1, pgl_exp_rom2);
11072 /* Close gates #2, #3 and #4 */
11073 bxe_set_234_gates(sc, TRUE);
11075 /* Poll for IGU VQs for 57712 and newer chips */
11076 if (!CHIP_IS_E1x(sc) && bxe_er_poll_igu_vq(sc)) {
11080 /* XXX indicate that "process kill" is in progress to MCP */
11082 /* clear "unprepared" bit */
11083 REG_WR(sc, MISC_REG_UNPREPARED, 0);
11086 /* Make sure all is written to the chip before the reset */
11090 * Wait for 1ms to empty GLUE and PCI-E core queues,
11091 * PSWHST, GRC and PSWRD Tetris buffer.
11095 /* Prepare to chip reset: */
11098 bxe_reset_mcp_prep(sc, &val);
11105 /* reset the chip */
11106 bxe_process_kill_chip_reset(sc, global);
11109 /* clear errors in PGB */
11110 if (!CHIP_IS_E1(sc))
11111 REG_WR(sc, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
11113 /* Recover after reset: */
11115 if (global && bxe_reset_mcp_comp(sc, val)) {
11119 /* XXX add resetting the NO_MCP mode DB here */
11121 /* Open the gates #2, #3 and #4 */
11122 bxe_set_234_gates(sc, FALSE);
11125 * IGU/AEU preparation bring back the AEU/IGU to a reset state
11126 * re-enable attentions
11133 bxe_leader_reset(struct bxe_softc *sc)
11136 uint8_t global = bxe_reset_is_global(sc);
11137 uint32_t load_code;
11140 * If not going to reset MCP, load "fake" driver to reset HW while
11141 * driver is owner of the HW.
11143 if (!global && !BXE_NOMCP(sc)) {
11144 load_code = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_REQ,
11145 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
11147 BLOGE(sc, "MCP response failure, aborting\n");
11149 goto exit_leader_reset;
11152 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
11153 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
11154 BLOGE(sc, "MCP unexpected response, aborting\n");
11156 goto exit_leader_reset2;
11159 load_code = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
11161 BLOGE(sc, "MCP response failure, aborting\n");
11163 goto exit_leader_reset2;
11167 /* try to recover after the failure */
11168 if (bxe_process_kill(sc, global)) {
11169 BLOGE(sc, "Something bad occurred on engine %d!\n", SC_PATH(sc));
11171 goto exit_leader_reset2;
11175 * Clear the RESET_IN_PROGRESS and RESET_GLOBAL bits and update the driver
11178 bxe_set_reset_done(sc);
11180 bxe_clear_reset_global(sc);
11183 exit_leader_reset2:
11185 /* unload "fake driver" if it was loaded */
11186 if (!global && !BXE_NOMCP(sc)) {
11187 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
11188 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, 0);
11194 bxe_release_leader_lock(sc);
11201 * prepare INIT transition, parameters configured:
11202 * - HC configuration
11203 * - Queue's CDU context
11206 bxe_pf_q_prep_init(struct bxe_softc *sc,
11207 struct bxe_fastpath *fp,
11208 struct ecore_queue_init_params *init_params)
11211 int cxt_index, cxt_offset;
11213 bxe_set_bit(ECORE_Q_FLG_HC, &init_params->rx.flags);
11214 bxe_set_bit(ECORE_Q_FLG_HC, &init_params->tx.flags);
11216 bxe_set_bit(ECORE_Q_FLG_HC_EN, &init_params->rx.flags);
11217 bxe_set_bit(ECORE_Q_FLG_HC_EN, &init_params->tx.flags);
11220 init_params->rx.hc_rate =
11221 sc->hc_rx_ticks ? (1000000 / sc->hc_rx_ticks) : 0;
11222 init_params->tx.hc_rate =
11223 sc->hc_tx_ticks ? (1000000 / sc->hc_tx_ticks) : 0;
11226 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id = fp->fw_sb_id;
11228 /* CQ index among the SB indices */
11229 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
11230 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
11232 /* set maximum number of COSs supported by this queue */
11233 init_params->max_cos = sc->max_cos;
11235 BLOGD(sc, DBG_LOAD, "fp %d setting queue params max cos to %d\n",
11236 fp->index, init_params->max_cos);
11238 /* set the context pointers queue object */
11239 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
11240 /* XXX change index/cid here if ever support multiple tx CoS */
11241 /* fp->txdata[cos]->cid */
11242 cxt_index = fp->index / ILT_PAGE_CIDS;
11243 cxt_offset = fp->index - (cxt_index * ILT_PAGE_CIDS);
11244 init_params->cxts[cos] = &sc->context[cxt_index].vcxt[cxt_offset].eth;
11248 /* set flags that are common for the Tx-only and not normal connections */
11249 static unsigned long
11250 bxe_get_common_flags(struct bxe_softc *sc,
11251 struct bxe_fastpath *fp,
11252 uint8_t zero_stats)
11254 unsigned long flags = 0;
11256 /* PF driver will always initialize the Queue to an ACTIVE state */
11257 bxe_set_bit(ECORE_Q_FLG_ACTIVE, &flags);
11260 * tx only connections collect statistics (on the same index as the
11261 * parent connection). The statistics are zeroed when the parent
11262 * connection is initialized.
11265 bxe_set_bit(ECORE_Q_FLG_STATS, &flags);
11267 bxe_set_bit(ECORE_Q_FLG_ZERO_STATS, &flags);
11271 * tx only connections can support tx-switching, though their
11272 * CoS-ness doesn't survive the loopback
11274 if (sc->flags & BXE_TX_SWITCHING) {
11275 bxe_set_bit(ECORE_Q_FLG_TX_SWITCH, &flags);
11278 bxe_set_bit(ECORE_Q_FLG_PCSUM_ON_PKT, &flags);
11283 static unsigned long
11284 bxe_get_q_flags(struct bxe_softc *sc,
11285 struct bxe_fastpath *fp,
11288 unsigned long flags = 0;
11290 if (IS_MF_SD(sc)) {
11291 bxe_set_bit(ECORE_Q_FLG_OV, &flags);
11294 if (sc->ifnet->if_capenable & IFCAP_LRO) {
11295 bxe_set_bit(ECORE_Q_FLG_TPA, &flags);
11296 bxe_set_bit(ECORE_Q_FLG_TPA_IPV6, &flags);
11300 bxe_set_bit(ECORE_Q_FLG_LEADING_RSS, &flags);
11301 bxe_set_bit(ECORE_Q_FLG_MCAST, &flags);
11304 bxe_set_bit(ECORE_Q_FLG_VLAN, &flags);
11306 /* merge with common flags */
11307 return (flags | bxe_get_common_flags(sc, fp, TRUE));
11311 bxe_pf_q_prep_general(struct bxe_softc *sc,
11312 struct bxe_fastpath *fp,
11313 struct ecore_general_setup_params *gen_init,
11316 gen_init->stat_id = bxe_stats_id(fp);
11317 gen_init->spcl_id = fp->cl_id;
11318 gen_init->mtu = sc->mtu;
11319 gen_init->cos = cos;
11323 bxe_pf_rx_q_prep(struct bxe_softc *sc,
11324 struct bxe_fastpath *fp,
11325 struct rxq_pause_params *pause,
11326 struct ecore_rxq_setup_params *rxq_init)
11328 uint8_t max_sge = 0;
11329 uint16_t sge_sz = 0;
11330 uint16_t tpa_agg_size = 0;
11332 pause->sge_th_lo = SGE_TH_LO(sc);
11333 pause->sge_th_hi = SGE_TH_HI(sc);
11335 /* validate SGE ring has enough to cross high threshold */
11336 if (sc->dropless_fc &&
11337 (pause->sge_th_hi + FW_PREFETCH_CNT) >
11338 (RX_SGE_USABLE_PER_PAGE * RX_SGE_NUM_PAGES)) {
11339 BLOGW(sc, "sge ring threshold limit\n");
11342 /* minimum max_aggregation_size is 2*MTU (two full buffers) */
11343 tpa_agg_size = (2 * sc->mtu);
11344 if (tpa_agg_size < sc->max_aggregation_size) {
11345 tpa_agg_size = sc->max_aggregation_size;
11348 max_sge = SGE_PAGE_ALIGN(sc->mtu) >> SGE_PAGE_SHIFT;
11349 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
11350 (~(PAGES_PER_SGE - 1))) >> PAGES_PER_SGE_SHIFT;
11351 sge_sz = (uint16_t)min(SGE_PAGES, 0xffff);
11353 /* pause - not for e1 */
11354 if (!CHIP_IS_E1(sc)) {
11355 pause->bd_th_lo = BD_TH_LO(sc);
11356 pause->bd_th_hi = BD_TH_HI(sc);
11358 pause->rcq_th_lo = RCQ_TH_LO(sc);
11359 pause->rcq_th_hi = RCQ_TH_HI(sc);
11361 /* validate rings have enough entries to cross high thresholds */
11362 if (sc->dropless_fc &&
11363 pause->bd_th_hi + FW_PREFETCH_CNT >
11364 sc->rx_ring_size) {
11365 BLOGW(sc, "rx bd ring threshold limit\n");
11368 if (sc->dropless_fc &&
11369 pause->rcq_th_hi + FW_PREFETCH_CNT >
11370 RCQ_NUM_PAGES * RCQ_USABLE_PER_PAGE) {
11371 BLOGW(sc, "rcq ring threshold limit\n");
11374 pause->pri_map = 1;
11378 rxq_init->dscr_map = fp->rx_dma.paddr;
11379 rxq_init->sge_map = fp->rx_sge_dma.paddr;
11380 rxq_init->rcq_map = fp->rcq_dma.paddr;
11381 rxq_init->rcq_np_map = (fp->rcq_dma.paddr + BCM_PAGE_SIZE);
11384 * This should be a maximum number of data bytes that may be
11385 * placed on the BD (not including paddings).
11387 rxq_init->buf_sz = (fp->rx_buf_size -
11388 IP_HEADER_ALIGNMENT_PADDING);
11390 rxq_init->cl_qzone_id = fp->cl_qzone_id;
11391 rxq_init->tpa_agg_sz = tpa_agg_size;
11392 rxq_init->sge_buf_sz = sge_sz;
11393 rxq_init->max_sges_pkt = max_sge;
11394 rxq_init->rss_engine_id = SC_FUNC(sc);
11395 rxq_init->mcast_engine_id = SC_FUNC(sc);
11398 * Maximum number or simultaneous TPA aggregation for this Queue.
11399 * For PF Clients it should be the maximum available number.
11400 * VF driver(s) may want to define it to a smaller value.
11402 rxq_init->max_tpa_queues = MAX_AGG_QS(sc);
11404 rxq_init->cache_line_log = BXE_RX_ALIGN_SHIFT;
11405 rxq_init->fw_sb_id = fp->fw_sb_id;
11407 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
11410 * configure silent vlan removal
11411 * if multi function mode is afex, then mask default vlan
11413 if (IS_MF_AFEX(sc)) {
11414 rxq_init->silent_removal_value =
11415 sc->devinfo.mf_info.afex_def_vlan_tag;
11416 rxq_init->silent_removal_mask = EVL_VLID_MASK;
11421 bxe_pf_tx_q_prep(struct bxe_softc *sc,
11422 struct bxe_fastpath *fp,
11423 struct ecore_txq_setup_params *txq_init,
11427 * XXX If multiple CoS is ever supported then each fastpath structure
11428 * will need to maintain tx producer/consumer/dma/etc values *per* CoS.
11429 * fp->txdata[cos]->tx_dma.paddr;
11431 txq_init->dscr_map = fp->tx_dma.paddr;
11432 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
11433 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
11434 txq_init->fw_sb_id = fp->fw_sb_id;
11437 * set the TSS leading client id for TX classfication to the
11438 * leading RSS client id
11440 txq_init->tss_leading_cl_id = BXE_FP(sc, 0, cl_id);
11444 * This function performs 2 steps in a queue state machine:
11449 bxe_setup_queue(struct bxe_softc *sc,
11450 struct bxe_fastpath *fp,
11453 struct ecore_queue_state_params q_params = { NULL };
11454 struct ecore_queue_setup_params *setup_params =
11455 &q_params.params.setup;
11458 BLOGD(sc, DBG_LOAD, "setting up queue %d\n", fp->index);
11460 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
11462 q_params.q_obj = &BXE_SP_OBJ(sc, fp).q_obj;
11464 /* we want to wait for completion in this context */
11465 bxe_set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
11467 /* prepare the INIT parameters */
11468 bxe_pf_q_prep_init(sc, fp, &q_params.params.init);
11470 /* Set the command */
11471 q_params.cmd = ECORE_Q_CMD_INIT;
11473 /* Change the state to INIT */
11474 rc = ecore_queue_state_change(sc, &q_params);
11476 BLOGE(sc, "Queue(%d) INIT failed rc = %d\n", fp->index, rc);
11480 BLOGD(sc, DBG_LOAD, "init complete\n");
11482 /* now move the Queue to the SETUP state */
11483 memset(setup_params, 0, sizeof(*setup_params));
11485 /* set Queue flags */
11486 setup_params->flags = bxe_get_q_flags(sc, fp, leading);
11488 /* set general SETUP parameters */
11489 bxe_pf_q_prep_general(sc, fp, &setup_params->gen_params,
11490 FIRST_TX_COS_INDEX);
11492 bxe_pf_rx_q_prep(sc, fp,
11493 &setup_params->pause_params,
11494 &setup_params->rxq_params);
11496 bxe_pf_tx_q_prep(sc, fp,
11497 &setup_params->txq_params,
11498 FIRST_TX_COS_INDEX);
11500 /* Set the command */
11501 q_params.cmd = ECORE_Q_CMD_SETUP;
11503 /* change the state to SETUP */
11504 rc = ecore_queue_state_change(sc, &q_params);
11506 BLOGE(sc, "Queue(%d) SETUP failed (rc = %d)\n", fp->index, rc);
11514 bxe_setup_leading(struct bxe_softc *sc)
11516 return (bxe_setup_queue(sc, &sc->fp[0], TRUE));
11520 bxe_config_rss_pf(struct bxe_softc *sc,
11521 struct ecore_rss_config_obj *rss_obj,
11522 uint8_t config_hash)
11524 struct ecore_config_rss_params params = { NULL };
11528 * Although RSS is meaningless when there is a single HW queue we
11529 * still need it enabled in order to have HW Rx hash generated.
11532 params.rss_obj = rss_obj;
11534 bxe_set_bit(RAMROD_COMP_WAIT, ¶ms.ramrod_flags);
11536 bxe_set_bit(ECORE_RSS_MODE_REGULAR, ¶ms.rss_flags);
11538 /* RSS configuration */
11539 bxe_set_bit(ECORE_RSS_IPV4, ¶ms.rss_flags);
11540 bxe_set_bit(ECORE_RSS_IPV4_TCP, ¶ms.rss_flags);
11541 bxe_set_bit(ECORE_RSS_IPV6, ¶ms.rss_flags);
11542 bxe_set_bit(ECORE_RSS_IPV6_TCP, ¶ms.rss_flags);
11543 if (rss_obj->udp_rss_v4) {
11544 bxe_set_bit(ECORE_RSS_IPV4_UDP, ¶ms.rss_flags);
11546 if (rss_obj->udp_rss_v6) {
11547 bxe_set_bit(ECORE_RSS_IPV6_UDP, ¶ms.rss_flags);
11551 params.rss_result_mask = MULTI_MASK;
11553 memcpy(params.ind_table, rss_obj->ind_table, sizeof(params.ind_table));
11557 for (i = 0; i < sizeof(params.rss_key) / 4; i++) {
11558 params.rss_key[i] = arc4random();
11561 bxe_set_bit(ECORE_RSS_SET_SRCH, ¶ms.rss_flags);
11564 return (ecore_config_rss(sc, ¶ms));
11568 bxe_config_rss_eth(struct bxe_softc *sc,
11569 uint8_t config_hash)
11571 return (bxe_config_rss_pf(sc, &sc->rss_conf_obj, config_hash));
11575 bxe_init_rss_pf(struct bxe_softc *sc)
11577 uint8_t num_eth_queues = BXE_NUM_ETH_QUEUES(sc);
11581 * Prepare the initial contents of the indirection table if
11584 for (i = 0; i < sizeof(sc->rss_conf_obj.ind_table); i++) {
11585 sc->rss_conf_obj.ind_table[i] =
11586 (sc->fp->cl_id + (i % num_eth_queues));
11590 sc->rss_conf_obj.udp_rss_v4 = sc->rss_conf_obj.udp_rss_v6 = 1;
11594 * For 57710 and 57711 SEARCHER configuration (rss_keys) is
11595 * per-port, so if explicit configuration is needed, do it only
11598 * For 57712 and newer it's a per-function configuration.
11600 return (bxe_config_rss_eth(sc, sc->port.pmf || !CHIP_IS_E1x(sc)));
11604 bxe_set_mac_one(struct bxe_softc *sc,
11606 struct ecore_vlan_mac_obj *obj,
11609 unsigned long *ramrod_flags)
11611 struct ecore_vlan_mac_ramrod_params ramrod_param;
11614 memset(&ramrod_param, 0, sizeof(ramrod_param));
11616 /* fill in general parameters */
11617 ramrod_param.vlan_mac_obj = obj;
11618 ramrod_param.ramrod_flags = *ramrod_flags;
11620 /* fill a user request section if needed */
11621 if (!bxe_test_bit(RAMROD_CONT, ramrod_flags)) {
11622 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
11624 bxe_set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
11626 /* Set the command: ADD or DEL */
11627 ramrod_param.user_req.cmd = (set) ? ECORE_VLAN_MAC_ADD :
11628 ECORE_VLAN_MAC_DEL;
11631 rc = ecore_config_vlan_mac(sc, &ramrod_param);
11633 if (rc == ECORE_EXISTS) {
11634 BLOGD(sc, DBG_SP, "Failed to schedule ADD operations (EEXIST)\n");
11635 /* do not treat adding same MAC as error */
11637 } else if (rc < 0) {
11638 BLOGE(sc, "%s MAC failed (%d)\n", (set ? "Set" : "Delete"), rc);
11645 bxe_set_eth_mac(struct bxe_softc *sc,
11648 unsigned long ramrod_flags = 0;
11650 BLOGD(sc, DBG_LOAD, "Adding Ethernet MAC\n");
11652 bxe_set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
11654 /* Eth MAC is set on RSS leading client (fp[0]) */
11655 return (bxe_set_mac_one(sc, sc->link_params.mac_addr,
11656 &sc->sp_objs->mac_obj,
11657 set, ECORE_ETH_MAC, &ramrod_flags));
11661 bxe_get_cur_phy_idx(struct bxe_softc *sc)
11663 uint32_t sel_phy_idx = 0;
11665 if (sc->link_params.num_phys <= 1) {
11666 return (ELINK_INT_PHY);
11669 if (sc->link_vars.link_up) {
11670 sel_phy_idx = ELINK_EXT_PHY1;
11671 /* In case link is SERDES, check if the ELINK_EXT_PHY2 is the one */
11672 if ((sc->link_vars.link_status & LINK_STATUS_SERDES_LINK) &&
11673 (sc->link_params.phy[ELINK_EXT_PHY2].supported &
11674 ELINK_SUPPORTED_FIBRE))
11675 sel_phy_idx = ELINK_EXT_PHY2;
11677 switch (elink_phy_selection(&sc->link_params)) {
11678 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
11679 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
11680 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
11681 sel_phy_idx = ELINK_EXT_PHY1;
11683 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
11684 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
11685 sel_phy_idx = ELINK_EXT_PHY2;
11690 return (sel_phy_idx);
11694 bxe_get_link_cfg_idx(struct bxe_softc *sc)
11696 uint32_t sel_phy_idx = bxe_get_cur_phy_idx(sc);
11699 * The selected activated PHY is always after swapping (in case PHY
11700 * swapping is enabled). So when swapping is enabled, we need to reverse
11701 * the configuration
11704 if (sc->link_params.multi_phy_config & PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
11705 if (sel_phy_idx == ELINK_EXT_PHY1)
11706 sel_phy_idx = ELINK_EXT_PHY2;
11707 else if (sel_phy_idx == ELINK_EXT_PHY2)
11708 sel_phy_idx = ELINK_EXT_PHY1;
11711 return (ELINK_LINK_CONFIG_IDX(sel_phy_idx));
11715 bxe_set_requested_fc(struct bxe_softc *sc)
11718 * Initialize link parameters structure variables
11719 * It is recommended to turn off RX FC for jumbo frames
11720 * for better performance
11722 if (CHIP_IS_E1x(sc) && (sc->mtu > 5000)) {
11723 sc->link_params.req_fc_auto_adv = ELINK_FLOW_CTRL_TX;
11725 sc->link_params.req_fc_auto_adv = ELINK_FLOW_CTRL_BOTH;
11730 bxe_calc_fc_adv(struct bxe_softc *sc)
11732 uint8_t cfg_idx = bxe_get_link_cfg_idx(sc);
11733 switch (sc->link_vars.ieee_fc &
11734 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
11735 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
11737 sc->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
11741 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
11742 sc->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
11746 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
11747 sc->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
11753 bxe_get_mf_speed(struct bxe_softc *sc)
11755 uint16_t line_speed = sc->link_vars.line_speed;
11758 bxe_extract_max_cfg(sc, sc->devinfo.mf_info.mf_config[SC_VN(sc)]);
11760 /* calculate the current MAX line speed limit for the MF devices */
11761 if (IS_MF_SI(sc)) {
11762 line_speed = (line_speed * maxCfg) / 100;
11763 } else { /* SD mode */
11764 uint16_t vn_max_rate = maxCfg * 100;
11766 if (vn_max_rate < line_speed) {
11767 line_speed = vn_max_rate;
11772 return (line_speed);
11776 bxe_fill_report_data(struct bxe_softc *sc,
11777 struct bxe_link_report_data *data)
11779 uint16_t line_speed = bxe_get_mf_speed(sc);
11781 memset(data, 0, sizeof(*data));
11783 /* fill the report data with the effective line speed */
11784 data->line_speed = line_speed;
11787 if (!sc->link_vars.link_up || (sc->flags & BXE_MF_FUNC_DIS)) {
11788 bxe_set_bit(BXE_LINK_REPORT_LINK_DOWN, &data->link_report_flags);
11792 if (sc->link_vars.duplex == DUPLEX_FULL) {
11793 bxe_set_bit(BXE_LINK_REPORT_FULL_DUPLEX, &data->link_report_flags);
11796 /* Rx Flow Control is ON */
11797 if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_RX) {
11798 bxe_set_bit(BXE_LINK_REPORT_RX_FC_ON, &data->link_report_flags);
11801 /* Tx Flow Control is ON */
11802 if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_TX) {
11803 bxe_set_bit(BXE_LINK_REPORT_TX_FC_ON, &data->link_report_flags);
11807 /* report link status to OS, should be called under phy_lock */
11809 bxe_link_report_locked(struct bxe_softc *sc)
11811 struct bxe_link_report_data cur_data;
11813 /* reread mf_cfg */
11814 if (IS_PF(sc) && !CHIP_IS_E1(sc)) {
11815 bxe_read_mf_cfg(sc);
11818 /* Read the current link report info */
11819 bxe_fill_report_data(sc, &cur_data);
11821 /* Don't report link down or exactly the same link status twice */
11822 if (!memcmp(&cur_data, &sc->last_reported_link, sizeof(cur_data)) ||
11823 (bxe_test_bit(BXE_LINK_REPORT_LINK_DOWN,
11824 &sc->last_reported_link.link_report_flags) &&
11825 bxe_test_bit(BXE_LINK_REPORT_LINK_DOWN,
11826 &cur_data.link_report_flags))) {
11832 /* report new link params and remember the state for the next time */
11833 memcpy(&sc->last_reported_link, &cur_data, sizeof(cur_data));
11835 if (bxe_test_bit(BXE_LINK_REPORT_LINK_DOWN,
11836 &cur_data.link_report_flags)) {
11837 if_link_state_change(sc->ifnet, LINK_STATE_DOWN);
11838 BLOGI(sc, "NIC Link is Down\n");
11840 const char *duplex;
11843 if (bxe_test_and_clear_bit(BXE_LINK_REPORT_FULL_DUPLEX,
11844 &cur_data.link_report_flags)) {
11851 * Handle the FC at the end so that only these flags would be
11852 * possibly set. This way we may easily check if there is no FC
11855 if (cur_data.link_report_flags) {
11856 if (bxe_test_bit(BXE_LINK_REPORT_RX_FC_ON,
11857 &cur_data.link_report_flags) &&
11858 bxe_test_bit(BXE_LINK_REPORT_TX_FC_ON,
11859 &cur_data.link_report_flags)) {
11860 flow = "ON - receive & transmit";
11861 } else if (bxe_test_bit(BXE_LINK_REPORT_RX_FC_ON,
11862 &cur_data.link_report_flags) &&
11863 !bxe_test_bit(BXE_LINK_REPORT_TX_FC_ON,
11864 &cur_data.link_report_flags)) {
11865 flow = "ON - receive";
11866 } else if (!bxe_test_bit(BXE_LINK_REPORT_RX_FC_ON,
11867 &cur_data.link_report_flags) &&
11868 bxe_test_bit(BXE_LINK_REPORT_TX_FC_ON,
11869 &cur_data.link_report_flags)) {
11870 flow = "ON - transmit";
11872 flow = "none"; /* possible? */
11878 if_link_state_change(sc->ifnet, LINK_STATE_UP);
11879 BLOGI(sc, "NIC Link is Up, %d Mbps %s duplex, Flow control: %s\n",
11880 cur_data.line_speed, duplex, flow);
11885 bxe_link_report(struct bxe_softc *sc)
11887 bxe_acquire_phy_lock(sc);
11888 bxe_link_report_locked(sc);
11889 bxe_release_phy_lock(sc);
11893 bxe_link_status_update(struct bxe_softc *sc)
11895 if (sc->state != BXE_STATE_OPEN) {
11899 if (IS_PF(sc) && !CHIP_REV_IS_SLOW(sc)) {
11900 elink_link_status_update(&sc->link_params, &sc->link_vars);
11902 sc->port.supported[0] |= (ELINK_SUPPORTED_10baseT_Half |
11903 ELINK_SUPPORTED_10baseT_Full |
11904 ELINK_SUPPORTED_100baseT_Half |
11905 ELINK_SUPPORTED_100baseT_Full |
11906 ELINK_SUPPORTED_1000baseT_Full |
11907 ELINK_SUPPORTED_2500baseX_Full |
11908 ELINK_SUPPORTED_10000baseT_Full |
11909 ELINK_SUPPORTED_TP |
11910 ELINK_SUPPORTED_FIBRE |
11911 ELINK_SUPPORTED_Autoneg |
11912 ELINK_SUPPORTED_Pause |
11913 ELINK_SUPPORTED_Asym_Pause);
11914 sc->port.advertising[0] = sc->port.supported[0];
11916 sc->link_params.sc = sc;
11917 sc->link_params.port = SC_PORT(sc);
11918 sc->link_params.req_duplex[0] = DUPLEX_FULL;
11919 sc->link_params.req_flow_ctrl[0] = ELINK_FLOW_CTRL_NONE;
11920 sc->link_params.req_line_speed[0] = SPEED_10000;
11921 sc->link_params.speed_cap_mask[0] = 0x7f0000;
11922 sc->link_params.switch_cfg = ELINK_SWITCH_CFG_10G;
11924 if (CHIP_REV_IS_FPGA(sc)) {
11925 sc->link_vars.mac_type = ELINK_MAC_TYPE_EMAC;
11926 sc->link_vars.line_speed = ELINK_SPEED_1000;
11927 sc->link_vars.link_status = (LINK_STATUS_LINK_UP |
11928 LINK_STATUS_SPEED_AND_DUPLEX_1000TFD);
11930 sc->link_vars.mac_type = ELINK_MAC_TYPE_BMAC;
11931 sc->link_vars.line_speed = ELINK_SPEED_10000;
11932 sc->link_vars.link_status = (LINK_STATUS_LINK_UP |
11933 LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
11936 sc->link_vars.link_up = 1;
11938 sc->link_vars.duplex = DUPLEX_FULL;
11939 sc->link_vars.flow_ctrl = ELINK_FLOW_CTRL_NONE;
11942 REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + sc->link_params.port*4, 0);
11943 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
11944 bxe_link_report(sc);
11949 if (sc->link_vars.link_up) {
11950 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
11952 bxe_stats_handle(sc, STATS_EVENT_STOP);
11954 bxe_link_report(sc);
11956 bxe_link_report(sc);
11957 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
11962 bxe_initial_phy_init(struct bxe_softc *sc,
11965 int rc, cfg_idx = bxe_get_link_cfg_idx(sc);
11966 uint16_t req_line_speed = sc->link_params.req_line_speed[cfg_idx];
11967 struct elink_params *lp = &sc->link_params;
11969 bxe_set_requested_fc(sc);
11971 if (CHIP_REV_IS_SLOW(sc)) {
11972 uint32_t bond = CHIP_BOND_ID(sc);
11975 if (CHIP_IS_E2(sc) && CHIP_IS_MODE_4_PORT(sc)) {
11976 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_BMAC;
11977 } else if (bond & 0x4) {
11978 if (CHIP_IS_E3(sc)) {
11979 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_XMAC;
11981 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_BMAC;
11983 } else if (bond & 0x8) {
11984 if (CHIP_IS_E3(sc)) {
11985 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_UMAC;
11987 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_EMAC;
11991 /* disable EMAC for E3 and above */
11993 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_EMAC;
11996 sc->link_params.feature_config_flags |= feat;
11999 bxe_acquire_phy_lock(sc);
12001 if (load_mode == LOAD_DIAG) {
12002 lp->loopback_mode = ELINK_LOOPBACK_XGXS;
12003 /* Prefer doing PHY loopback at 10G speed, if possible */
12004 if (lp->req_line_speed[cfg_idx] < ELINK_SPEED_10000) {
12005 if (lp->speed_cap_mask[cfg_idx] &
12006 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) {
12007 lp->req_line_speed[cfg_idx] = ELINK_SPEED_10000;
12009 lp->req_line_speed[cfg_idx] = ELINK_SPEED_1000;
12014 if (load_mode == LOAD_LOOPBACK_EXT) {
12015 lp->loopback_mode = ELINK_LOOPBACK_EXT;
12018 rc = elink_phy_init(&sc->link_params, &sc->link_vars);
12020 bxe_release_phy_lock(sc);
12022 bxe_calc_fc_adv(sc);
12024 if (sc->link_vars.link_up) {
12025 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
12026 bxe_link_report(sc);
12029 if (!CHIP_REV_IS_SLOW(sc)) {
12030 bxe_periodic_start(sc);
12033 sc->link_params.req_line_speed[cfg_idx] = req_line_speed;
12037 /* must be called under IF_ADDR_LOCK */
12039 bxe_init_mcast_macs_list(struct bxe_softc *sc,
12040 struct ecore_mcast_ramrod_params *p)
12042 struct ifnet *ifp = sc->ifnet;
12044 struct ifmultiaddr *ifma;
12045 struct ecore_mcast_list_elem *mc_mac;
12047 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
12048 if (ifma->ifma_addr->sa_family != AF_LINK) {
12055 ECORE_LIST_INIT(&p->mcast_list);
12056 p->mcast_list_len = 0;
12062 mc_mac = malloc(sizeof(*mc_mac) * mc_count, M_DEVBUF,
12063 (M_NOWAIT | M_ZERO));
12065 BLOGE(sc, "Failed to allocate temp mcast list\n");
12068 bzero(mc_mac, (sizeof(*mc_mac) * mc_count));
12070 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
12071 if (ifma->ifma_addr->sa_family != AF_LINK) {
12075 mc_mac->mac = (uint8_t *)LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
12076 ECORE_LIST_PUSH_TAIL(&mc_mac->link, &p->mcast_list);
12078 BLOGD(sc, DBG_LOAD,
12079 "Setting MCAST %02X:%02X:%02X:%02X:%02X:%02X\n",
12080 mc_mac->mac[0], mc_mac->mac[1], mc_mac->mac[2],
12081 mc_mac->mac[3], mc_mac->mac[4], mc_mac->mac[5]);
12086 p->mcast_list_len = mc_count;
12092 bxe_free_mcast_macs_list(struct ecore_mcast_ramrod_params *p)
12094 struct ecore_mcast_list_elem *mc_mac =
12095 ECORE_LIST_FIRST_ENTRY(&p->mcast_list,
12096 struct ecore_mcast_list_elem,
12100 /* only a single free as all mc_macs are in the same heap array */
12101 free(mc_mac, M_DEVBUF);
12106 bxe_set_mc_list(struct bxe_softc *sc)
12108 struct ecore_mcast_ramrod_params rparam = { NULL };
12111 rparam.mcast_obj = &sc->mcast_obj;
12113 BXE_MCAST_LOCK(sc);
12115 /* first, clear all configured multicast MACs */
12116 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL);
12118 BLOGE(sc, "Failed to clear multicast configuration: %d\n", rc);
12119 BXE_MCAST_UNLOCK(sc);
12123 /* configure a new MACs list */
12124 rc = bxe_init_mcast_macs_list(sc, &rparam);
12126 BLOGE(sc, "Failed to create mcast MACs list (%d)\n", rc);
12127 BXE_MCAST_UNLOCK(sc);
12131 /* Now add the new MACs */
12132 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_ADD);
12134 BLOGE(sc, "Failed to set new mcast config (%d)\n", rc);
12137 bxe_free_mcast_macs_list(&rparam);
12139 BXE_MCAST_UNLOCK(sc);
12145 bxe_set_uc_list(struct bxe_softc *sc)
12147 struct ifnet *ifp = sc->ifnet;
12148 struct ecore_vlan_mac_obj *mac_obj = &sc->sp_objs->mac_obj;
12149 struct ifaddr *ifa;
12150 unsigned long ramrod_flags = 0;
12153 #if __FreeBSD_version < 800000
12156 if_addr_rlock(ifp);
12159 /* first schedule a cleanup up of old configuration */
12160 rc = bxe_del_all_macs(sc, mac_obj, ECORE_UC_LIST_MAC, FALSE);
12162 BLOGE(sc, "Failed to schedule delete of all ETH MACs (%d)\n", rc);
12163 #if __FreeBSD_version < 800000
12164 IF_ADDR_UNLOCK(ifp);
12166 if_addr_runlock(ifp);
12171 ifa = ifp->if_addr;
12173 if (ifa->ifa_addr->sa_family != AF_LINK) {
12174 ifa = TAILQ_NEXT(ifa, ifa_link);
12178 rc = bxe_set_mac_one(sc, (uint8_t *)LLADDR((struct sockaddr_dl *)ifa->ifa_addr),
12179 mac_obj, TRUE, ECORE_UC_LIST_MAC, &ramrod_flags);
12180 if (rc == -EEXIST) {
12181 BLOGD(sc, DBG_SP, "Failed to schedule ADD operations (EEXIST)\n");
12182 /* do not treat adding same MAC as an error */
12184 } else if (rc < 0) {
12185 BLOGE(sc, "Failed to schedule ADD operations (%d)\n", rc);
12186 #if __FreeBSD_version < 800000
12187 IF_ADDR_UNLOCK(ifp);
12189 if_addr_runlock(ifp);
12194 ifa = TAILQ_NEXT(ifa, ifa_link);
12197 #if __FreeBSD_version < 800000
12198 IF_ADDR_UNLOCK(ifp);
12200 if_addr_runlock(ifp);
12203 /* Execute the pending commands */
12204 bit_set(&ramrod_flags, RAMROD_CONT);
12205 return (bxe_set_mac_one(sc, NULL, mac_obj, FALSE /* don't care */,
12206 ECORE_UC_LIST_MAC, &ramrod_flags));
12210 bxe_set_rx_mode(struct bxe_softc *sc)
12212 struct ifnet *ifp = sc->ifnet;
12213 uint32_t rx_mode = BXE_RX_MODE_NORMAL;
12215 if (sc->state != BXE_STATE_OPEN) {
12216 BLOGD(sc, DBG_SP, "state is %x, returning\n", sc->state);
12220 BLOGD(sc, DBG_SP, "ifp->if_flags=0x%x\n", ifp->if_flags);
12222 if (ifp->if_flags & IFF_PROMISC) {
12223 rx_mode = BXE_RX_MODE_PROMISC;
12224 } else if ((ifp->if_flags & IFF_ALLMULTI) ||
12225 ((ifp->if_amcount > BXE_MAX_MULTICAST) &&
12227 rx_mode = BXE_RX_MODE_ALLMULTI;
12230 /* some multicasts */
12231 if (bxe_set_mc_list(sc) < 0) {
12232 rx_mode = BXE_RX_MODE_ALLMULTI;
12234 if (bxe_set_uc_list(sc) < 0) {
12235 rx_mode = BXE_RX_MODE_PROMISC;
12240 sc->rx_mode = rx_mode;
12242 /* schedule the rx_mode command */
12243 if (bxe_test_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state)) {
12244 BLOGD(sc, DBG_LOAD, "Scheduled setting rx_mode with ECORE...\n");
12245 bxe_set_bit(ECORE_FILTER_RX_MODE_SCHED, &sc->sp_state);
12250 bxe_set_storm_rx_mode(sc);
12255 /* update flags in shmem */
12257 bxe_update_drv_flags(struct bxe_softc *sc,
12261 uint32_t drv_flags;
12263 if (SHMEM2_HAS(sc, drv_flags)) {
12264 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_DRV_FLAGS);
12265 drv_flags = SHMEM2_RD(sc, drv_flags);
12268 SET_FLAGS(drv_flags, flags);
12270 RESET_FLAGS(drv_flags, flags);
12273 SHMEM2_WR(sc, drv_flags, drv_flags);
12274 BLOGD(sc, DBG_LOAD, "drv_flags 0x%08x\n", drv_flags);
12276 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_DRV_FLAGS);
12280 /* periodic timer callout routine, only runs when the interface is up */
12283 bxe_periodic_callout_func(void *xsc)
12285 struct bxe_softc *sc = (struct bxe_softc *)xsc;
12288 if (!BXE_CORE_TRYLOCK(sc)) {
12289 /* just bail and try again next time */
12291 if ((sc->state == BXE_STATE_OPEN) &&
12292 (atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_GO)) {
12293 /* schedule the next periodic callout */
12294 callout_reset(&sc->periodic_callout, hz,
12295 bxe_periodic_callout_func, sc);
12301 if ((sc->state != BXE_STATE_OPEN) ||
12302 (atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_STOP)) {
12303 BLOGW(sc, "periodic callout exit (state=0x%x)\n", sc->state);
12304 BXE_CORE_UNLOCK(sc);
12308 /* Check for TX timeouts on any fastpath. */
12309 FOR_EACH_QUEUE(sc, i) {
12310 if (bxe_watchdog(sc, &sc->fp[i]) != 0) {
12311 /* Ruh-Roh, chip was reset! */
12316 if (!CHIP_REV_IS_SLOW(sc)) {
12318 * This barrier is needed to ensure the ordering between the writing
12319 * to the sc->port.pmf in the bxe_nic_load() or bxe_pmf_update() and
12320 * the reading here.
12323 if (sc->port.pmf) {
12324 bxe_acquire_phy_lock(sc);
12325 elink_period_func(&sc->link_params, &sc->link_vars);
12326 bxe_release_phy_lock(sc);
12330 if (IS_PF(sc) && !(sc->flags & BXE_NO_PULSE)) {
12331 int mb_idx = SC_FW_MB_IDX(sc);
12332 uint32_t drv_pulse;
12333 uint32_t mcp_pulse;
12335 ++sc->fw_drv_pulse_wr_seq;
12336 sc->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
12338 drv_pulse = sc->fw_drv_pulse_wr_seq;
12341 mcp_pulse = (SHMEM_RD(sc, func_mb[mb_idx].mcp_pulse_mb) &
12342 MCP_PULSE_SEQ_MASK);
12345 * The delta between driver pulse and mcp response should
12346 * be 1 (before mcp response) or 0 (after mcp response).
12348 if ((drv_pulse != mcp_pulse) &&
12349 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
12350 /* someone lost a heartbeat... */
12351 BLOGE(sc, "drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
12352 drv_pulse, mcp_pulse);
12356 /* state is BXE_STATE_OPEN */
12357 bxe_stats_handle(sc, STATS_EVENT_UPDATE);
12359 BXE_CORE_UNLOCK(sc);
12361 if ((sc->state == BXE_STATE_OPEN) &&
12362 (atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_GO)) {
12363 /* schedule the next periodic callout */
12364 callout_reset(&sc->periodic_callout, hz,
12365 bxe_periodic_callout_func, sc);
12370 bxe_periodic_start(struct bxe_softc *sc)
12372 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_GO);
12373 callout_reset(&sc->periodic_callout, hz, bxe_periodic_callout_func, sc);
12377 bxe_periodic_stop(struct bxe_softc *sc)
12379 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_STOP);
12380 callout_drain(&sc->periodic_callout);
12383 /* start the controller */
12384 static __noinline int
12385 bxe_nic_load(struct bxe_softc *sc,
12392 BXE_CORE_LOCK_ASSERT(sc);
12394 BLOGD(sc, DBG_LOAD, "Starting NIC load...\n");
12396 sc->state = BXE_STATE_OPENING_WAITING_LOAD;
12399 /* must be called before memory allocation and HW init */
12400 bxe_ilt_set_info(sc);
12403 sc->last_reported_link_state = LINK_STATE_UNKNOWN;
12405 bxe_set_fp_rx_buf_size(sc);
12407 if (bxe_alloc_fp_buffers(sc) != 0) {
12408 BLOGE(sc, "Failed to allocate fastpath memory\n");
12409 sc->state = BXE_STATE_CLOSED;
12411 goto bxe_nic_load_error0;
12414 if (bxe_alloc_mem(sc) != 0) {
12415 sc->state = BXE_STATE_CLOSED;
12417 goto bxe_nic_load_error0;
12420 if (bxe_alloc_fw_stats_mem(sc) != 0) {
12421 sc->state = BXE_STATE_CLOSED;
12423 goto bxe_nic_load_error0;
12427 /* set pf load just before approaching the MCP */
12428 bxe_set_pf_load(sc);
12430 /* if MCP exists send load request and analyze response */
12431 if (!BXE_NOMCP(sc)) {
12432 /* attempt to load pf */
12433 if (bxe_nic_load_request(sc, &load_code) != 0) {
12434 sc->state = BXE_STATE_CLOSED;
12436 goto bxe_nic_load_error1;
12439 /* what did the MCP say? */
12440 if (bxe_nic_load_analyze_req(sc, load_code) != 0) {
12441 bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
12442 sc->state = BXE_STATE_CLOSED;
12444 goto bxe_nic_load_error2;
12447 BLOGI(sc, "Device has no MCP!\n");
12448 load_code = bxe_nic_load_no_mcp(sc);
12451 /* mark PMF if applicable */
12452 bxe_nic_load_pmf(sc, load_code);
12454 /* Init Function state controlling object */
12455 bxe_init_func_obj(sc);
12457 /* Initialize HW */
12458 if (bxe_init_hw(sc, load_code) != 0) {
12459 BLOGE(sc, "HW init failed\n");
12460 bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
12461 sc->state = BXE_STATE_CLOSED;
12463 goto bxe_nic_load_error2;
12467 /* set ALWAYS_ALIVE bit in shmem */
12468 sc->fw_drv_pulse_wr_seq |= DRV_PULSE_ALWAYS_ALIVE;
12470 sc->flags |= BXE_NO_PULSE;
12472 /* attach interrupts */
12473 if (bxe_interrupt_attach(sc) != 0) {
12474 sc->state = BXE_STATE_CLOSED;
12476 goto bxe_nic_load_error2;
12479 bxe_nic_init(sc, load_code);
12481 /* Init per-function objects */
12484 // XXX bxe_iov_nic_init(sc);
12486 /* set AFEX default VLAN tag to an invalid value */
12487 sc->devinfo.mf_info.afex_def_vlan_tag = -1;
12488 // XXX bxe_nic_load_afex_dcc(sc, load_code);
12490 sc->state = BXE_STATE_OPENING_WAITING_PORT;
12491 rc = bxe_func_start(sc);
12493 BLOGE(sc, "Function start failed! rc = %d\n", rc);
12494 bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
12495 sc->state = BXE_STATE_ERROR;
12496 goto bxe_nic_load_error3;
12499 /* send LOAD_DONE command to MCP */
12500 if (!BXE_NOMCP(sc)) {
12501 load_code = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
12503 BLOGE(sc, "MCP response failure, aborting\n");
12504 sc->state = BXE_STATE_ERROR;
12506 goto bxe_nic_load_error3;
12510 rc = bxe_setup_leading(sc);
12512 BLOGE(sc, "Setup leading failed! rc = %d\n", rc);
12513 sc->state = BXE_STATE_ERROR;
12514 goto bxe_nic_load_error3;
12517 FOR_EACH_NONDEFAULT_ETH_QUEUE(sc, i) {
12518 rc = bxe_setup_queue(sc, &sc->fp[i], FALSE);
12520 BLOGE(sc, "Queue(%d) setup failed rc = %d\n", i, rc);
12521 sc->state = BXE_STATE_ERROR;
12522 goto bxe_nic_load_error3;
12526 rc = bxe_init_rss_pf(sc);
12528 BLOGE(sc, "PF RSS init failed\n");
12529 sc->state = BXE_STATE_ERROR;
12530 goto bxe_nic_load_error3;
12535 /* now when Clients are configured we are ready to work */
12536 sc->state = BXE_STATE_OPEN;
12538 /* Configure a ucast MAC */
12540 rc = bxe_set_eth_mac(sc, TRUE);
12543 BLOGE(sc, "Setting Ethernet MAC failed rc = %d\n", rc);
12544 sc->state = BXE_STATE_ERROR;
12545 goto bxe_nic_load_error3;
12548 if (sc->port.pmf) {
12549 rc = bxe_initial_phy_init(sc, /* XXX load_mode */LOAD_OPEN);
12551 sc->state = BXE_STATE_ERROR;
12552 goto bxe_nic_load_error3;
12556 sc->link_params.feature_config_flags &=
12557 ~ELINK_FEATURE_CONFIG_BOOT_FROM_SAN;
12559 /* start fast path */
12561 /* Initialize Rx filter */
12562 bxe_set_rx_mode(sc);
12565 switch (/* XXX load_mode */LOAD_OPEN) {
12571 case LOAD_LOOPBACK_EXT:
12572 sc->state = BXE_STATE_DIAG;
12579 if (sc->port.pmf) {
12580 bxe_update_drv_flags(sc, 1 << DRV_FLAGS_PORT_MASK, 0);
12582 bxe_link_status_update(sc);
12585 /* start the periodic timer callout */
12586 bxe_periodic_start(sc);
12588 if (IS_PF(sc) && SHMEM2_HAS(sc, drv_capabilities_flag)) {
12589 /* mark driver is loaded in shmem2 */
12590 val = SHMEM2_RD(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)]);
12591 SHMEM2_WR(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)],
12593 DRV_FLAGS_CAPABILITIES_LOADED_SUPPORTED |
12594 DRV_FLAGS_CAPABILITIES_LOADED_L2));
12597 /* wait for all pending SP commands to complete */
12598 if (IS_PF(sc) && !bxe_wait_sp_comp(sc, ~0x0UL)) {
12599 BLOGE(sc, "Timeout waiting for all SPs to complete!\n");
12600 bxe_periodic_stop(sc);
12601 bxe_nic_unload(sc, UNLOAD_CLOSE, FALSE);
12605 /* Tell the stack the driver is running! */
12606 sc->ifnet->if_drv_flags = IFF_DRV_RUNNING;
12608 BLOGD(sc, DBG_LOAD, "NIC successfully loaded\n");
12612 bxe_nic_load_error3:
12615 bxe_int_disable_sync(sc, 1);
12617 /* clean out queued objects */
12618 bxe_squeeze_objects(sc);
12621 bxe_interrupt_detach(sc);
12623 bxe_nic_load_error2:
12625 if (IS_PF(sc) && !BXE_NOMCP(sc)) {
12626 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
12627 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, 0);
12632 bxe_nic_load_error1:
12634 /* clear pf_load status, as it was already set */
12636 bxe_clear_pf_load(sc);
12639 bxe_nic_load_error0:
12641 bxe_free_fw_stats_mem(sc);
12642 bxe_free_fp_buffers(sc);
12649 bxe_init_locked(struct bxe_softc *sc)
12651 int other_engine = SC_PATH(sc) ? 0 : 1;
12652 uint8_t other_load_status, load_status;
12653 uint8_t global = FALSE;
12656 BXE_CORE_LOCK_ASSERT(sc);
12658 /* check if the driver is already running */
12659 if (sc->ifnet->if_drv_flags & IFF_DRV_RUNNING) {
12660 BLOGD(sc, DBG_LOAD, "Init called while driver is running!\n");
12664 bxe_set_power_state(sc, PCI_PM_D0);
12667 * If parity occurred during the unload, then attentions and/or
12668 * RECOVERY_IN_PROGRES may still be set. If so we want the first function
12669 * loaded on the current engine to complete the recovery. Parity recovery
12670 * is only relevant for PF driver.
12673 other_load_status = bxe_get_load_status(sc, other_engine);
12674 load_status = bxe_get_load_status(sc, SC_PATH(sc));
12676 if (!bxe_reset_is_done(sc, SC_PATH(sc)) ||
12677 bxe_chk_parity_attn(sc, &global, TRUE)) {
12680 * If there are attentions and they are in global blocks, set
12681 * the GLOBAL_RESET bit regardless whether it will be this
12682 * function that will complete the recovery or not.
12685 bxe_set_reset_global(sc);
12689 * Only the first function on the current engine should try
12690 * to recover in open. In case of attentions in global blocks
12691 * only the first in the chip should try to recover.
12693 if ((!load_status && (!global || !other_load_status)) &&
12694 bxe_trylock_leader_lock(sc) && !bxe_leader_reset(sc)) {
12695 BLOGI(sc, "Recovered during init\n");
12699 /* recovery has failed... */
12700 bxe_set_power_state(sc, PCI_PM_D3hot);
12701 sc->recovery_state = BXE_RECOVERY_FAILED;
12703 BLOGE(sc, "Recovery flow hasn't properly "
12704 "completed yet, try again later. "
12705 "If you still see this message after a "
12706 "few retries then power cycle is required.\n");
12709 goto bxe_init_locked_done;
12714 sc->recovery_state = BXE_RECOVERY_DONE;
12716 rc = bxe_nic_load(sc, LOAD_OPEN);
12718 bxe_init_locked_done:
12721 /* Tell the stack the driver is NOT running! */
12722 BLOGE(sc, "Initialization failed, "
12723 "stack notified driver is NOT running!\n");
12724 sc->ifnet->if_drv_flags &= ~IFF_DRV_RUNNING;
12731 bxe_stop_locked(struct bxe_softc *sc)
12733 BXE_CORE_LOCK_ASSERT(sc);
12734 return (bxe_nic_unload(sc, UNLOAD_NORMAL, TRUE));
12738 * Handles controller initialization when called from an unlocked routine.
12739 * ifconfig calls this function.
12745 bxe_init(void *xsc)
12747 struct bxe_softc *sc = (struct bxe_softc *)xsc;
12750 bxe_init_locked(sc);
12751 BXE_CORE_UNLOCK(sc);
12755 bxe_init_ifnet(struct bxe_softc *sc)
12759 /* ifconfig entrypoint for media type/status reporting */
12760 ifmedia_init(&sc->ifmedia, IFM_IMASK,
12761 bxe_ifmedia_update,
12762 bxe_ifmedia_status);
12764 /* set the default interface values */
12765 ifmedia_add(&sc->ifmedia, (IFM_ETHER | IFM_FDX | sc->media), 0, NULL);
12766 ifmedia_add(&sc->ifmedia, (IFM_ETHER | IFM_AUTO), 0, NULL);
12767 ifmedia_set(&sc->ifmedia, (IFM_ETHER | IFM_AUTO));
12769 sc->ifmedia.ifm_media = sc->ifmedia.ifm_cur->ifm_media; /* XXX ? */
12771 /* allocate the ifnet structure */
12772 if ((ifp = if_alloc(IFT_ETHER)) == NULL) {
12773 BLOGE(sc, "Interface allocation failed!\n");
12777 ifp->if_softc = sc;
12778 if_initname(ifp, device_get_name(sc->dev), device_get_unit(sc->dev));
12779 ifp->if_flags = (IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
12780 ifp->if_ioctl = bxe_ioctl;
12781 ifp->if_start = bxe_tx_start;
12782 #if __FreeBSD_version >= 800000
12783 ifp->if_transmit = bxe_tx_mq_start;
12784 ifp->if_qflush = bxe_mq_flush;
12789 ifp->if_init = bxe_init;
12790 ifp->if_mtu = sc->mtu;
12791 ifp->if_hwassist = (CSUM_IP |
12797 ifp->if_capabilities =
12798 #if __FreeBSD_version < 700000
12800 IFCAP_VLAN_HWTAGGING |
12806 IFCAP_VLAN_HWTAGGING |
12808 IFCAP_VLAN_HWFILTER |
12809 IFCAP_VLAN_HWCSUM |
12817 ifp->if_capenable = ifp->if_capabilities;
12818 ifp->if_capenable &= ~IFCAP_WOL_MAGIC; /* XXX not yet... */
12819 #if __FreeBSD_version < 1000025
12820 ifp->if_baudrate = 1000000000;
12822 if_initbaudrate(ifp, IF_Gbps(10));
12824 ifp->if_snd.ifq_drv_maxlen = sc->tx_ring_size;
12826 IFQ_SET_MAXLEN(&ifp->if_snd, ifp->if_snd.ifq_drv_maxlen);
12827 IFQ_SET_READY(&ifp->if_snd);
12831 /* attach to the Ethernet interface list */
12832 ether_ifattach(ifp, sc->link_params.mac_addr);
12838 bxe_deallocate_bars(struct bxe_softc *sc)
12842 for (i = 0; i < MAX_BARS; i++) {
12843 if (sc->bar[i].resource != NULL) {
12844 bus_release_resource(sc->dev,
12847 sc->bar[i].resource);
12848 BLOGD(sc, DBG_LOAD, "Released PCI BAR%d [%02x] memory\n",
12855 bxe_allocate_bars(struct bxe_softc *sc)
12860 memset(sc->bar, 0, sizeof(sc->bar));
12862 for (i = 0; i < MAX_BARS; i++) {
12864 /* memory resources reside at BARs 0, 2, 4 */
12865 /* Run `pciconf -lb` to see mappings */
12866 if ((i != 0) && (i != 2) && (i != 4)) {
12870 sc->bar[i].rid = PCIR_BAR(i);
12874 flags |= RF_SHAREABLE;
12877 if ((sc->bar[i].resource =
12878 bus_alloc_resource_any(sc->dev,
12885 sc->bar[i].tag = rman_get_bustag(sc->bar[i].resource);
12886 sc->bar[i].handle = rman_get_bushandle(sc->bar[i].resource);
12887 sc->bar[i].kva = (vm_offset_t)rman_get_virtual(sc->bar[i].resource);
12889 BLOGI(sc, "PCI BAR%d [%02x] memory allocated: %p-%p (%ld) -> %p\n",
12891 (void *)rman_get_start(sc->bar[i].resource),
12892 (void *)rman_get_end(sc->bar[i].resource),
12893 rman_get_size(sc->bar[i].resource),
12894 (void *)sc->bar[i].kva);
12901 bxe_get_function_num(struct bxe_softc *sc)
12906 * Read the ME register to get the function number. The ME register
12907 * holds the relative-function number and absolute-function number. The
12908 * absolute-function number appears only in E2 and above. Before that
12909 * these bits always contained zero, therefore we cannot blindly use them.
12912 val = REG_RD(sc, BAR_ME_REGISTER);
12915 (uint8_t)((val & ME_REG_PF_NUM) >> ME_REG_PF_NUM_SHIFT);
12917 (uint8_t)((val & ME_REG_ABS_PF_NUM) >> ME_REG_ABS_PF_NUM_SHIFT) & 1;
12919 if (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) {
12920 sc->pfunc_abs = ((sc->pfunc_rel << 1) | sc->path_id);
12922 sc->pfunc_abs = (sc->pfunc_rel | sc->path_id);
12925 BLOGD(sc, DBG_LOAD,
12926 "Relative function %d, Absolute function %d, Path %d\n",
12927 sc->pfunc_rel, sc->pfunc_abs, sc->path_id);
12931 bxe_get_shmem_mf_cfg_base(struct bxe_softc *sc)
12933 uint32_t shmem2_size;
12935 uint32_t mf_cfg_offset_value;
12938 offset = (SHMEM_RD(sc, func_mb) +
12939 (MAX_FUNC_NUM * sizeof(struct drv_func_mb)));
12942 if (sc->devinfo.shmem2_base != 0) {
12943 shmem2_size = SHMEM2_RD(sc, size);
12944 if (shmem2_size > offsetof(struct shmem2_region, mf_cfg_addr)) {
12945 mf_cfg_offset_value = SHMEM2_RD(sc, mf_cfg_addr);
12946 if (SHMEM_MF_CFG_ADDR_NONE != mf_cfg_offset_value) {
12947 offset = mf_cfg_offset_value;
12956 bxe_pcie_capability_read(struct bxe_softc *sc,
12962 /* ensure PCIe capability is enabled */
12963 if (pci_find_cap(sc->dev, PCIY_EXPRESS, &pcie_reg) == 0) {
12964 if (pcie_reg != 0) {
12965 BLOGD(sc, DBG_LOAD, "PCIe capability at 0x%04x\n", pcie_reg);
12966 return (pci_read_config(sc->dev, (pcie_reg + reg), width));
12970 BLOGE(sc, "PCIe capability NOT FOUND!!!\n");
12976 bxe_is_pcie_pending(struct bxe_softc *sc)
12978 return (bxe_pcie_capability_read(sc, PCIR_EXPRESS_DEVICE_STA, 2) &
12979 PCIM_EXP_STA_TRANSACTION_PND);
12983 * Walk the PCI capabiites list for the device to find what features are
12984 * supported. These capabilites may be enabled/disabled by firmware so it's
12985 * best to walk the list rather than make assumptions.
12988 bxe_probe_pci_caps(struct bxe_softc *sc)
12990 uint16_t link_status;
12993 /* check if PCI Power Management is enabled */
12994 if (pci_find_cap(sc->dev, PCIY_PMG, ®) == 0) {
12996 BLOGD(sc, DBG_LOAD, "Found PM capability at 0x%04x\n", reg);
12998 sc->devinfo.pcie_cap_flags |= BXE_PM_CAPABLE_FLAG;
12999 sc->devinfo.pcie_pm_cap_reg = (uint16_t)reg;
13003 link_status = bxe_pcie_capability_read(sc, PCIR_EXPRESS_LINK_STA, 2);
13005 /* handle PCIe 2.0 workarounds for 57710 */
13006 if (CHIP_IS_E1(sc)) {
13007 /* workaround for 57710 errata E4_57710_27462 */
13008 sc->devinfo.pcie_link_speed =
13009 (REG_RD(sc, 0x3d04) & (1 << 24)) ? 2 : 1;
13011 /* workaround for 57710 errata E4_57710_27488 */
13012 sc->devinfo.pcie_link_width =
13013 ((link_status & PCIM_LINK_STA_WIDTH) >> 4);
13014 if (sc->devinfo.pcie_link_speed > 1) {
13015 sc->devinfo.pcie_link_width =
13016 ((link_status & PCIM_LINK_STA_WIDTH) >> 4) >> 1;
13019 sc->devinfo.pcie_link_speed =
13020 (link_status & PCIM_LINK_STA_SPEED);
13021 sc->devinfo.pcie_link_width =
13022 ((link_status & PCIM_LINK_STA_WIDTH) >> 4);
13025 BLOGD(sc, DBG_LOAD, "PCIe link speed=%d width=%d\n",
13026 sc->devinfo.pcie_link_speed, sc->devinfo.pcie_link_width);
13028 sc->devinfo.pcie_cap_flags |= BXE_PCIE_CAPABLE_FLAG;
13029 sc->devinfo.pcie_pcie_cap_reg = (uint16_t)reg;
13031 /* check if MSI capability is enabled */
13032 if (pci_find_cap(sc->dev, PCIY_MSI, ®) == 0) {
13034 BLOGD(sc, DBG_LOAD, "Found MSI capability at 0x%04x\n", reg);
13036 sc->devinfo.pcie_cap_flags |= BXE_MSI_CAPABLE_FLAG;
13037 sc->devinfo.pcie_msi_cap_reg = (uint16_t)reg;
13041 /* check if MSI-X capability is enabled */
13042 if (pci_find_cap(sc->dev, PCIY_MSIX, ®) == 0) {
13044 BLOGD(sc, DBG_LOAD, "Found MSI-X capability at 0x%04x\n", reg);
13046 sc->devinfo.pcie_cap_flags |= BXE_MSIX_CAPABLE_FLAG;
13047 sc->devinfo.pcie_msix_cap_reg = (uint16_t)reg;
13053 bxe_get_shmem_mf_cfg_info_sd(struct bxe_softc *sc)
13055 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13058 /* get the outer vlan if we're in switch-dependent mode */
13060 val = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag);
13061 mf_info->ext_id = (uint16_t)val;
13063 mf_info->multi_vnics_mode = 1;
13065 if (!VALID_OVLAN(mf_info->ext_id)) {
13066 BLOGE(sc, "Invalid VLAN (%d)\n", mf_info->ext_id);
13070 /* get the capabilities */
13071 if ((mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_PROTOCOL_MASK) ==
13072 FUNC_MF_CFG_PROTOCOL_ISCSI) {
13073 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_ISCSI;
13074 } else if ((mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_PROTOCOL_MASK) ==
13075 FUNC_MF_CFG_PROTOCOL_FCOE) {
13076 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_FCOE;
13078 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_ETHERNET;
13081 mf_info->vnics_per_port =
13082 (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4;
13088 bxe_get_shmem_ext_proto_support_flags(struct bxe_softc *sc)
13090 uint32_t retval = 0;
13093 val = MFCFG_RD(sc, func_ext_config[SC_ABS_FUNC(sc)].func_cfg);
13095 if (val & MACP_FUNC_CFG_FLAGS_ENABLED) {
13096 if (val & MACP_FUNC_CFG_FLAGS_ETHERNET) {
13097 retval |= MF_PROTO_SUPPORT_ETHERNET;
13099 if (val & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
13100 retval |= MF_PROTO_SUPPORT_ISCSI;
13102 if (val & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
13103 retval |= MF_PROTO_SUPPORT_FCOE;
13111 bxe_get_shmem_mf_cfg_info_si(struct bxe_softc *sc)
13113 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13117 * There is no outer vlan if we're in switch-independent mode.
13118 * If the mac is valid then assume multi-function.
13121 val = MFCFG_RD(sc, func_ext_config[SC_ABS_FUNC(sc)].func_cfg);
13123 mf_info->multi_vnics_mode = ((val & MACP_FUNC_CFG_FLAGS_MASK) != 0);
13125 mf_info->mf_protos_supported = bxe_get_shmem_ext_proto_support_flags(sc);
13127 mf_info->vnics_per_port =
13128 (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4;
13134 bxe_get_shmem_mf_cfg_info_niv(struct bxe_softc *sc)
13136 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13137 uint32_t e1hov_tag;
13138 uint32_t func_config;
13139 uint32_t niv_config;
13141 mf_info->multi_vnics_mode = 1;
13143 e1hov_tag = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag);
13144 func_config = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config);
13145 niv_config = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].afex_config);
13148 (uint16_t)((e1hov_tag & FUNC_MF_CFG_E1HOV_TAG_MASK) >>
13149 FUNC_MF_CFG_E1HOV_TAG_SHIFT);
13151 mf_info->default_vlan =
13152 (uint16_t)((e1hov_tag & FUNC_MF_CFG_AFEX_VLAN_MASK) >>
13153 FUNC_MF_CFG_AFEX_VLAN_SHIFT);
13155 mf_info->niv_allowed_priorities =
13156 (uint8_t)((niv_config & FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
13157 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT);
13159 mf_info->niv_default_cos =
13160 (uint8_t)((func_config & FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
13161 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT);
13163 mf_info->afex_vlan_mode =
13164 ((niv_config & FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
13165 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT);
13167 mf_info->niv_mba_enabled =
13168 ((niv_config & FUNC_MF_CFG_AFEX_MBA_ENABLED_MASK) >>
13169 FUNC_MF_CFG_AFEX_MBA_ENABLED_SHIFT);
13171 mf_info->mf_protos_supported = bxe_get_shmem_ext_proto_support_flags(sc);
13173 mf_info->vnics_per_port =
13174 (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4;
13180 bxe_check_valid_mf_cfg(struct bxe_softc *sc)
13182 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13189 BLOGD(sc, DBG_LOAD, "MF config parameters for function %d\n",
13191 BLOGD(sc, DBG_LOAD, "\tmf_config=0x%x\n",
13192 mf_info->mf_config[SC_VN(sc)]);
13193 BLOGD(sc, DBG_LOAD, "\tmulti_vnics_mode=%d\n",
13194 mf_info->multi_vnics_mode);
13195 BLOGD(sc, DBG_LOAD, "\tvnics_per_port=%d\n",
13196 mf_info->vnics_per_port);
13197 BLOGD(sc, DBG_LOAD, "\tovlan/vifid=%d\n",
13199 BLOGD(sc, DBG_LOAD, "\tmin_bw=%d/%d/%d/%d\n",
13200 mf_info->min_bw[0], mf_info->min_bw[1],
13201 mf_info->min_bw[2], mf_info->min_bw[3]);
13202 BLOGD(sc, DBG_LOAD, "\tmax_bw=%d/%d/%d/%d\n",
13203 mf_info->max_bw[0], mf_info->max_bw[1],
13204 mf_info->max_bw[2], mf_info->max_bw[3]);
13205 BLOGD(sc, DBG_LOAD, "\tmac_addr: %s\n",
13208 /* various MF mode sanity checks... */
13210 if (mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_FUNC_HIDE) {
13211 BLOGE(sc, "Enumerated function %d is marked as hidden\n",
13216 if ((mf_info->vnics_per_port > 1) && !mf_info->multi_vnics_mode) {
13217 BLOGE(sc, "vnics_per_port=%d multi_vnics_mode=%d\n",
13218 mf_info->vnics_per_port, mf_info->multi_vnics_mode);
13222 if (mf_info->mf_mode == MULTI_FUNCTION_SD) {
13223 /* vnic id > 0 must have valid ovlan in switch-dependent mode */
13224 if ((SC_VN(sc) > 0) && !VALID_OVLAN(OVLAN(sc))) {
13225 BLOGE(sc, "mf_mode=SD vnic_id=%d ovlan=%d\n",
13226 SC_VN(sc), OVLAN(sc));
13230 if (!VALID_OVLAN(OVLAN(sc)) && mf_info->multi_vnics_mode) {
13231 BLOGE(sc, "mf_mode=SD multi_vnics_mode=%d ovlan=%d\n",
13232 mf_info->multi_vnics_mode, OVLAN(sc));
13237 * Verify all functions are either MF or SF mode. If MF, make sure
13238 * sure that all non-hidden functions have a valid ovlan. If SF,
13239 * make sure that all non-hidden functions have an invalid ovlan.
13241 FOREACH_ABS_FUNC_IN_PORT(sc, i) {
13242 mf_cfg1 = MFCFG_RD(sc, func_mf_config[i].config);
13243 ovlan1 = MFCFG_RD(sc, func_mf_config[i].e1hov_tag);
13244 if (!(mf_cfg1 & FUNC_MF_CFG_FUNC_HIDE) &&
13245 (((mf_info->multi_vnics_mode) && !VALID_OVLAN(ovlan1)) ||
13246 ((!mf_info->multi_vnics_mode) && VALID_OVLAN(ovlan1)))) {
13247 BLOGE(sc, "mf_mode=SD function %d MF config "
13248 "mismatch, multi_vnics_mode=%d ovlan=%d\n",
13249 i, mf_info->multi_vnics_mode, ovlan1);
13254 /* Verify all funcs on the same port each have a different ovlan. */
13255 FOREACH_ABS_FUNC_IN_PORT(sc, i) {
13256 mf_cfg1 = MFCFG_RD(sc, func_mf_config[i].config);
13257 ovlan1 = MFCFG_RD(sc, func_mf_config[i].e1hov_tag);
13258 /* iterate from the next function on the port to the max func */
13259 for (j = i + 2; j < MAX_FUNC_NUM; j += 2) {
13260 mf_cfg2 = MFCFG_RD(sc, func_mf_config[j].config);
13261 ovlan2 = MFCFG_RD(sc, func_mf_config[j].e1hov_tag);
13262 if (!(mf_cfg1 & FUNC_MF_CFG_FUNC_HIDE) &&
13263 VALID_OVLAN(ovlan1) &&
13264 !(mf_cfg2 & FUNC_MF_CFG_FUNC_HIDE) &&
13265 VALID_OVLAN(ovlan2) &&
13266 (ovlan1 == ovlan2)) {
13267 BLOGE(sc, "mf_mode=SD functions %d and %d "
13268 "have the same ovlan (%d)\n",
13274 } /* MULTI_FUNCTION_SD */
13280 bxe_get_mf_cfg_info(struct bxe_softc *sc)
13282 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13283 uint32_t val, mac_upper;
13286 /* initialize mf_info defaults */
13287 mf_info->vnics_per_port = 1;
13288 mf_info->multi_vnics_mode = FALSE;
13289 mf_info->path_has_ovlan = FALSE;
13290 mf_info->mf_mode = SINGLE_FUNCTION;
13292 if (!CHIP_IS_MF_CAP(sc)) {
13296 if (sc->devinfo.mf_cfg_base == SHMEM_MF_CFG_ADDR_NONE) {
13297 BLOGE(sc, "Invalid mf_cfg_base!\n");
13301 /* get the MF mode (switch dependent / independent / single-function) */
13303 val = SHMEM_RD(sc, dev_info.shared_feature_config.config);
13305 switch (val & SHARED_FEAT_CFG_FORCE_SF_MODE_MASK)
13307 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
13309 mac_upper = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper);
13311 /* check for legal upper mac bytes */
13312 if (mac_upper != FUNC_MF_CFG_UPPERMAC_DEFAULT) {
13313 mf_info->mf_mode = MULTI_FUNCTION_SI;
13315 BLOGE(sc, "Invalid config for Switch Independent mode\n");
13320 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
13321 case SHARED_FEAT_CFG_FORCE_SF_MODE_SPIO4:
13323 /* get outer vlan configuration */
13324 val = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag);
13326 if ((val & FUNC_MF_CFG_E1HOV_TAG_MASK) !=
13327 FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
13328 mf_info->mf_mode = MULTI_FUNCTION_SD;
13330 BLOGE(sc, "Invalid config for Switch Dependent mode\n");
13335 case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
13337 /* not in MF mode, vnics_per_port=1 and multi_vnics_mode=FALSE */
13340 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
13343 * Mark MF mode as NIV if MCP version includes NPAR-SD support
13344 * and the MAC address is valid.
13346 mac_upper = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper);
13348 if ((SHMEM2_HAS(sc, afex_driver_support)) &&
13349 (mac_upper != FUNC_MF_CFG_UPPERMAC_DEFAULT)) {
13350 mf_info->mf_mode = MULTI_FUNCTION_AFEX;
13352 BLOGE(sc, "Invalid config for AFEX mode\n");
13359 BLOGE(sc, "Unknown MF mode (0x%08x)\n",
13360 (val & SHARED_FEAT_CFG_FORCE_SF_MODE_MASK));
13365 /* set path mf_mode (which could be different than function mf_mode) */
13366 if (mf_info->mf_mode == MULTI_FUNCTION_SD) {
13367 mf_info->path_has_ovlan = TRUE;
13368 } else if (mf_info->mf_mode == SINGLE_FUNCTION) {
13370 * Decide on path multi vnics mode. If we're not in MF mode and in
13371 * 4-port mode, this is good enough to check vnic-0 of the other port
13374 if (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) {
13375 uint8_t other_port = !(PORT_ID(sc) & 1);
13376 uint8_t abs_func_other_port = (SC_PATH(sc) + (2 * other_port));
13378 val = MFCFG_RD(sc, func_mf_config[abs_func_other_port].e1hov_tag);
13380 mf_info->path_has_ovlan = VALID_OVLAN((uint16_t)val) ? 1 : 0;
13384 if (mf_info->mf_mode == SINGLE_FUNCTION) {
13385 /* invalid MF config */
13386 if (SC_VN(sc) >= 1) {
13387 BLOGE(sc, "VNIC ID >= 1 in SF mode\n");
13394 /* get the MF configuration */
13395 mf_info->mf_config[SC_VN(sc)] =
13396 MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config);
13398 switch(mf_info->mf_mode)
13400 case MULTI_FUNCTION_SD:
13402 bxe_get_shmem_mf_cfg_info_sd(sc);
13405 case MULTI_FUNCTION_SI:
13407 bxe_get_shmem_mf_cfg_info_si(sc);
13410 case MULTI_FUNCTION_AFEX:
13412 bxe_get_shmem_mf_cfg_info_niv(sc);
13417 BLOGE(sc, "Get MF config failed (mf_mode=0x%08x)\n",
13422 /* get the congestion management parameters */
13425 FOREACH_ABS_FUNC_IN_PORT(sc, i) {
13426 /* get min/max bw */
13427 val = MFCFG_RD(sc, func_mf_config[i].config);
13428 mf_info->min_bw[vnic] =
13429 ((val & FUNC_MF_CFG_MIN_BW_MASK) >> FUNC_MF_CFG_MIN_BW_SHIFT);
13430 mf_info->max_bw[vnic] =
13431 ((val & FUNC_MF_CFG_MAX_BW_MASK) >> FUNC_MF_CFG_MAX_BW_SHIFT);
13435 return (bxe_check_valid_mf_cfg(sc));
13439 bxe_get_shmem_info(struct bxe_softc *sc)
13442 uint32_t mac_hi, mac_lo, val;
13444 port = SC_PORT(sc);
13445 mac_hi = mac_lo = 0;
13447 sc->link_params.sc = sc;
13448 sc->link_params.port = port;
13450 /* get the hardware config info */
13451 sc->devinfo.hw_config =
13452 SHMEM_RD(sc, dev_info.shared_hw_config.config);
13453 sc->devinfo.hw_config2 =
13454 SHMEM_RD(sc, dev_info.shared_hw_config.config2);
13456 sc->link_params.hw_led_mode =
13457 ((sc->devinfo.hw_config & SHARED_HW_CFG_LED_MODE_MASK) >>
13458 SHARED_HW_CFG_LED_MODE_SHIFT);
13460 /* get the port feature config */
13462 SHMEM_RD(sc, dev_info.port_feature_config[port].config),
13464 /* get the link params */
13465 sc->link_params.speed_cap_mask[0] =
13466 SHMEM_RD(sc, dev_info.port_hw_config[port].speed_capability_mask);
13467 sc->link_params.speed_cap_mask[1] =
13468 SHMEM_RD(sc, dev_info.port_hw_config[port].speed_capability_mask2);
13470 /* get the lane config */
13471 sc->link_params.lane_config =
13472 SHMEM_RD(sc, dev_info.port_hw_config[port].lane_config);
13474 /* get the link config */
13475 val = SHMEM_RD(sc, dev_info.port_feature_config[port].link_config);
13476 sc->port.link_config[ELINK_INT_PHY] = val;
13477 sc->link_params.switch_cfg = (val & PORT_FEATURE_CONNECTED_SWITCH_MASK);
13478 sc->port.link_config[ELINK_EXT_PHY1] =
13479 SHMEM_RD(sc, dev_info.port_feature_config[port].link_config2);
13481 /* get the override preemphasis flag and enable it or turn it off */
13482 val = SHMEM_RD(sc, dev_info.shared_feature_config.config);
13483 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED) {
13484 sc->link_params.feature_config_flags |=
13485 ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
13487 sc->link_params.feature_config_flags &=
13488 ~ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
13491 /* get the initial value of the link params */
13492 sc->link_params.multi_phy_config =
13493 SHMEM_RD(sc, dev_info.port_hw_config[port].multi_phy_config);
13495 /* get external phy info */
13496 sc->port.ext_phy_config =
13497 SHMEM_RD(sc, dev_info.port_hw_config[port].external_phy_config);
13499 /* get the multifunction configuration */
13500 bxe_get_mf_cfg_info(sc);
13502 /* get the mac address */
13504 mac_hi = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper);
13505 mac_lo = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_lower);
13507 mac_hi = SHMEM_RD(sc, dev_info.port_hw_config[port].mac_upper);
13508 mac_lo = SHMEM_RD(sc, dev_info.port_hw_config[port].mac_lower);
13511 if ((mac_lo == 0) && (mac_hi == 0)) {
13512 *sc->mac_addr_str = 0;
13513 BLOGE(sc, "No Ethernet address programmed!\n");
13515 sc->link_params.mac_addr[0] = (uint8_t)(mac_hi >> 8);
13516 sc->link_params.mac_addr[1] = (uint8_t)(mac_hi);
13517 sc->link_params.mac_addr[2] = (uint8_t)(mac_lo >> 24);
13518 sc->link_params.mac_addr[3] = (uint8_t)(mac_lo >> 16);
13519 sc->link_params.mac_addr[4] = (uint8_t)(mac_lo >> 8);
13520 sc->link_params.mac_addr[5] = (uint8_t)(mac_lo);
13521 snprintf(sc->mac_addr_str, sizeof(sc->mac_addr_str),
13522 "%02x:%02x:%02x:%02x:%02x:%02x",
13523 sc->link_params.mac_addr[0], sc->link_params.mac_addr[1],
13524 sc->link_params.mac_addr[2], sc->link_params.mac_addr[3],
13525 sc->link_params.mac_addr[4], sc->link_params.mac_addr[5]);
13526 BLOGD(sc, DBG_LOAD, "Ethernet address: %s\n", sc->mac_addr_str);
13533 bxe_get_tunable_params(struct bxe_softc *sc)
13535 /* sanity checks */
13537 if ((bxe_interrupt_mode != INTR_MODE_INTX) &&
13538 (bxe_interrupt_mode != INTR_MODE_MSI) &&
13539 (bxe_interrupt_mode != INTR_MODE_MSIX)) {
13540 BLOGW(sc, "invalid interrupt_mode value (%d)\n", bxe_interrupt_mode);
13541 bxe_interrupt_mode = INTR_MODE_MSIX;
13544 if ((bxe_queue_count < 0) || (bxe_queue_count > MAX_RSS_CHAINS)) {
13545 BLOGW(sc, "invalid queue_count value (%d)\n", bxe_queue_count);
13546 bxe_queue_count = 0;
13549 if ((bxe_max_rx_bufs < 1) || (bxe_max_rx_bufs > RX_BD_USABLE)) {
13550 if (bxe_max_rx_bufs == 0) {
13551 bxe_max_rx_bufs = RX_BD_USABLE;
13553 BLOGW(sc, "invalid max_rx_bufs (%d)\n", bxe_max_rx_bufs);
13554 bxe_max_rx_bufs = 2048;
13558 if ((bxe_hc_rx_ticks < 1) || (bxe_hc_rx_ticks > 100)) {
13559 BLOGW(sc, "invalid hc_rx_ticks (%d)\n", bxe_hc_rx_ticks);
13560 bxe_hc_rx_ticks = 25;
13563 if ((bxe_hc_tx_ticks < 1) || (bxe_hc_tx_ticks > 100)) {
13564 BLOGW(sc, "invalid hc_tx_ticks (%d)\n", bxe_hc_tx_ticks);
13565 bxe_hc_tx_ticks = 50;
13568 if (bxe_max_aggregation_size == 0) {
13569 bxe_max_aggregation_size = TPA_AGG_SIZE;
13572 if (bxe_max_aggregation_size > 0xffff) {
13573 BLOGW(sc, "invalid max_aggregation_size (%d)\n",
13574 bxe_max_aggregation_size);
13575 bxe_max_aggregation_size = TPA_AGG_SIZE;
13578 if ((bxe_mrrs < -1) || (bxe_mrrs > 3)) {
13579 BLOGW(sc, "invalid mrrs (%d)\n", bxe_mrrs);
13583 if ((bxe_autogreeen < 0) || (bxe_autogreeen > 2)) {
13584 BLOGW(sc, "invalid autogreeen (%d)\n", bxe_autogreeen);
13585 bxe_autogreeen = 0;
13588 if ((bxe_udp_rss < 0) || (bxe_udp_rss > 1)) {
13589 BLOGW(sc, "invalid udp_rss (%d)\n", bxe_udp_rss);
13593 /* pull in user settings */
13595 sc->interrupt_mode = bxe_interrupt_mode;
13596 sc->max_rx_bufs = bxe_max_rx_bufs;
13597 sc->hc_rx_ticks = bxe_hc_rx_ticks;
13598 sc->hc_tx_ticks = bxe_hc_tx_ticks;
13599 sc->max_aggregation_size = bxe_max_aggregation_size;
13600 sc->mrrs = bxe_mrrs;
13601 sc->autogreeen = bxe_autogreeen;
13602 sc->udp_rss = bxe_udp_rss;
13604 if (bxe_interrupt_mode == INTR_MODE_INTX) {
13605 sc->num_queues = 1;
13606 } else { /* INTR_MODE_MSI or INTR_MODE_MSIX */
13608 min((bxe_queue_count ? bxe_queue_count : mp_ncpus),
13610 if (sc->num_queues > mp_ncpus) {
13611 sc->num_queues = mp_ncpus;
13615 BLOGD(sc, DBG_LOAD,
13618 "interrupt_mode=%d "
13623 "max_aggregation_size=%d "
13628 sc->interrupt_mode,
13633 sc->max_aggregation_size,
13640 bxe_media_detect(struct bxe_softc *sc)
13642 uint32_t phy_idx = bxe_get_cur_phy_idx(sc);
13643 switch (sc->link_params.phy[phy_idx].media_type) {
13644 case ELINK_ETH_PHY_SFPP_10G_FIBER:
13645 case ELINK_ETH_PHY_XFP_FIBER:
13646 BLOGI(sc, "Found 10Gb Fiber media.\n");
13647 sc->media = IFM_10G_SR;
13649 case ELINK_ETH_PHY_SFP_1G_FIBER:
13650 BLOGI(sc, "Found 1Gb Fiber media.\n");
13651 sc->media = IFM_1000_SX;
13653 case ELINK_ETH_PHY_KR:
13654 case ELINK_ETH_PHY_CX4:
13655 BLOGI(sc, "Found 10GBase-CX4 media.\n");
13656 sc->media = IFM_10G_CX4;
13658 case ELINK_ETH_PHY_DA_TWINAX:
13659 BLOGI(sc, "Found 10Gb Twinax media.\n");
13660 sc->media = IFM_10G_TWINAX;
13662 case ELINK_ETH_PHY_BASE_T:
13663 if (sc->link_params.speed_cap_mask[0] &
13664 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) {
13665 BLOGI(sc, "Found 10GBase-T media.\n");
13666 sc->media = IFM_10G_T;
13668 BLOGI(sc, "Found 1000Base-T media.\n");
13669 sc->media = IFM_1000_T;
13672 case ELINK_ETH_PHY_NOT_PRESENT:
13673 BLOGI(sc, "Media not present.\n");
13676 case ELINK_ETH_PHY_UNSPECIFIED:
13678 BLOGI(sc, "Unknown media!\n");
13684 #define GET_FIELD(value, fname) \
13685 (((value) & (fname##_MASK)) >> (fname##_SHIFT))
13686 #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
13687 #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
13690 bxe_get_igu_cam_info(struct bxe_softc *sc)
13692 int pfid = SC_FUNC(sc);
13695 uint8_t fid, igu_sb_cnt = 0;
13697 sc->igu_base_sb = 0xff;
13699 if (CHIP_INT_MODE_IS_BC(sc)) {
13700 int vn = SC_VN(sc);
13701 igu_sb_cnt = sc->igu_sb_cnt;
13702 sc->igu_base_sb = ((CHIP_IS_MODE_4_PORT(sc) ? pfid : vn) *
13704 sc->igu_dsb_id = (E1HVN_MAX * FP_SB_MAX_E1x +
13705 (CHIP_IS_MODE_4_PORT(sc) ? pfid : vn));
13709 /* IGU in normal mode - read CAM */
13710 for (igu_sb_id = 0;
13711 igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
13713 val = REG_RD(sc, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
13714 if (!(val & IGU_REG_MAPPING_MEMORY_VALID)) {
13717 fid = IGU_FID(val);
13718 if ((fid & IGU_FID_ENCODE_IS_PF)) {
13719 if ((fid & IGU_FID_PF_NUM_MASK) != pfid) {
13722 if (IGU_VEC(val) == 0) {
13723 /* default status block */
13724 sc->igu_dsb_id = igu_sb_id;
13726 if (sc->igu_base_sb == 0xff) {
13727 sc->igu_base_sb = igu_sb_id;
13735 * Due to new PF resource allocation by MFW T7.4 and above, it's optional
13736 * that number of CAM entries will not be equal to the value advertised in
13737 * PCI. Driver should use the minimal value of both as the actual status
13740 sc->igu_sb_cnt = min(sc->igu_sb_cnt, igu_sb_cnt);
13742 if (igu_sb_cnt == 0) {
13743 BLOGE(sc, "CAM configuration error\n");
13751 * Gather various information from the device config space, the device itself,
13752 * shmem, and the user input.
13755 bxe_get_device_info(struct bxe_softc *sc)
13760 /* Get the data for the device */
13761 sc->devinfo.vendor_id = pci_get_vendor(sc->dev);
13762 sc->devinfo.device_id = pci_get_device(sc->dev);
13763 sc->devinfo.subvendor_id = pci_get_subvendor(sc->dev);
13764 sc->devinfo.subdevice_id = pci_get_subdevice(sc->dev);
13766 /* get the chip revision (chip metal comes from pci config space) */
13767 sc->devinfo.chip_id =
13768 sc->link_params.chip_id =
13769 (((REG_RD(sc, MISC_REG_CHIP_NUM) & 0xffff) << 16) |
13770 ((REG_RD(sc, MISC_REG_CHIP_REV) & 0xf) << 12) |
13771 (((REG_RD(sc, PCICFG_OFFSET + PCI_ID_VAL3) >> 24) & 0xf) << 4) |
13772 ((REG_RD(sc, MISC_REG_BOND_ID) & 0xf) << 0));
13774 /* force 57811 according to MISC register */
13775 if (REG_RD(sc, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
13776 if (CHIP_IS_57810(sc)) {
13777 sc->devinfo.chip_id = ((CHIP_NUM_57811 << 16) |
13778 (sc->devinfo.chip_id & 0x0000ffff));
13779 } else if (CHIP_IS_57810_MF(sc)) {
13780 sc->devinfo.chip_id = ((CHIP_NUM_57811_MF << 16) |
13781 (sc->devinfo.chip_id & 0x0000ffff));
13783 sc->devinfo.chip_id |= 0x1;
13786 BLOGD(sc, DBG_LOAD,
13787 "chip_id=0x%08x (num=0x%04x rev=0x%01x metal=0x%02x bond=0x%01x)\n",
13788 sc->devinfo.chip_id,
13789 ((sc->devinfo.chip_id >> 16) & 0xffff),
13790 ((sc->devinfo.chip_id >> 12) & 0xf),
13791 ((sc->devinfo.chip_id >> 4) & 0xff),
13792 ((sc->devinfo.chip_id >> 0) & 0xf));
13794 val = (REG_RD(sc, 0x2874) & 0x55);
13795 if ((sc->devinfo.chip_id & 0x1) ||
13796 (CHIP_IS_E1(sc) && val) ||
13797 (CHIP_IS_E1H(sc) && (val == 0x55))) {
13798 sc->flags |= BXE_ONE_PORT_FLAG;
13799 BLOGD(sc, DBG_LOAD, "single port device\n");
13802 /* set the doorbell size */
13803 sc->doorbell_size = (1 << BXE_DB_SHIFT);
13805 /* determine whether the device is in 2 port or 4 port mode */
13806 sc->devinfo.chip_port_mode = CHIP_PORT_MODE_NONE; /* E1 & E1h*/
13807 if (CHIP_IS_E2E3(sc)) {
13809 * Read port4mode_en_ovwr[0]:
13810 * If 1, four port mode is in port4mode_en_ovwr[1].
13811 * If 0, four port mode is in port4mode_en[0].
13813 val = REG_RD(sc, MISC_REG_PORT4MODE_EN_OVWR);
13815 val = ((val >> 1) & 1);
13817 val = REG_RD(sc, MISC_REG_PORT4MODE_EN);
13820 sc->devinfo.chip_port_mode =
13821 (val) ? CHIP_4_PORT_MODE : CHIP_2_PORT_MODE;
13823 BLOGD(sc, DBG_LOAD, "Port mode = %s\n", (val) ? "4" : "2");
13826 /* get the function and path info for the device */
13827 bxe_get_function_num(sc);
13829 /* get the shared memory base address */
13830 sc->devinfo.shmem_base =
13831 sc->link_params.shmem_base =
13832 REG_RD(sc, MISC_REG_SHARED_MEM_ADDR);
13833 sc->devinfo.shmem2_base =
13834 REG_RD(sc, (SC_PATH(sc) ? MISC_REG_GENERIC_CR_1 :
13835 MISC_REG_GENERIC_CR_0));
13837 BLOGD(sc, DBG_LOAD, "shmem_base=0x%08x, shmem2_base=0x%08x\n",
13838 sc->devinfo.shmem_base, sc->devinfo.shmem2_base);
13840 if (!sc->devinfo.shmem_base) {
13841 /* this should ONLY prevent upcoming shmem reads */
13842 BLOGI(sc, "MCP not active\n");
13843 sc->flags |= BXE_NO_MCP_FLAG;
13847 /* make sure the shared memory contents are valid */
13848 val = SHMEM_RD(sc, validity_map[SC_PORT(sc)]);
13849 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) !=
13850 (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) {
13851 BLOGE(sc, "Invalid SHMEM validity signature: 0x%08x\n", val);
13854 BLOGD(sc, DBG_LOAD, "Valid SHMEM validity signature: 0x%08x\n", val);
13856 /* get the bootcode version */
13857 sc->devinfo.bc_ver = SHMEM_RD(sc, dev_info.bc_rev);
13858 snprintf(sc->devinfo.bc_ver_str,
13859 sizeof(sc->devinfo.bc_ver_str),
13861 ((sc->devinfo.bc_ver >> 24) & 0xff),
13862 ((sc->devinfo.bc_ver >> 16) & 0xff),
13863 ((sc->devinfo.bc_ver >> 8) & 0xff));
13864 BLOGD(sc, DBG_LOAD, "Bootcode version: %s\n", sc->devinfo.bc_ver_str);
13866 /* get the bootcode shmem address */
13867 sc->devinfo.mf_cfg_base = bxe_get_shmem_mf_cfg_base(sc);
13868 BLOGD(sc, DBG_LOAD, "mf_cfg_base=0x08%x \n", sc->devinfo.mf_cfg_base);
13870 /* clean indirect addresses as they're not used */
13871 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, 0, 4);
13873 REG_WR(sc, PXP2_REG_PGL_ADDR_88_F0, 0);
13874 REG_WR(sc, PXP2_REG_PGL_ADDR_8C_F0, 0);
13875 REG_WR(sc, PXP2_REG_PGL_ADDR_90_F0, 0);
13876 REG_WR(sc, PXP2_REG_PGL_ADDR_94_F0, 0);
13877 if (CHIP_IS_E1x(sc)) {
13878 REG_WR(sc, PXP2_REG_PGL_ADDR_88_F1, 0);
13879 REG_WR(sc, PXP2_REG_PGL_ADDR_8C_F1, 0);
13880 REG_WR(sc, PXP2_REG_PGL_ADDR_90_F1, 0);
13881 REG_WR(sc, PXP2_REG_PGL_ADDR_94_F1, 0);
13885 * Enable internal target-read (in case we are probed after PF
13886 * FLR). Must be done prior to any BAR read access. Only for
13889 if (!CHIP_IS_E1x(sc)) {
13890 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
13894 /* get the nvram size */
13895 val = REG_RD(sc, MCP_REG_MCPR_NVM_CFG4);
13896 sc->devinfo.flash_size =
13897 (NVRAM_1MB_SIZE << (val & MCPR_NVM_CFG4_FLASH_SIZE));
13898 BLOGD(sc, DBG_LOAD, "nvram flash size: %d\n", sc->devinfo.flash_size);
13900 /* get PCI capabilites */
13901 bxe_probe_pci_caps(sc);
13903 bxe_set_power_state(sc, PCI_PM_D0);
13905 /* get various configuration parameters from shmem */
13906 bxe_get_shmem_info(sc);
13908 if (sc->devinfo.pcie_msix_cap_reg != 0) {
13909 val = pci_read_config(sc->dev,
13910 (sc->devinfo.pcie_msix_cap_reg +
13913 sc->igu_sb_cnt = (val & PCIM_MSIXCTRL_TABLE_SIZE);
13915 sc->igu_sb_cnt = 1;
13918 sc->igu_base_addr = BAR_IGU_INTMEM;
13920 /* initialize IGU parameters */
13921 if (CHIP_IS_E1x(sc)) {
13922 sc->devinfo.int_block = INT_BLOCK_HC;
13923 sc->igu_dsb_id = DEF_SB_IGU_ID;
13924 sc->igu_base_sb = 0;
13926 sc->devinfo.int_block = INT_BLOCK_IGU;
13928 /* do not allow device reset during IGU info preocessing */
13929 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
13931 val = REG_RD(sc, IGU_REG_BLOCK_CONFIGURATION);
13933 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
13936 BLOGD(sc, DBG_LOAD, "FORCING IGU Normal Mode\n");
13938 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
13939 REG_WR(sc, IGU_REG_BLOCK_CONFIGURATION, val);
13940 REG_WR(sc, IGU_REG_RESET_MEMORIES, 0x7f);
13942 while (tout && REG_RD(sc, IGU_REG_RESET_MEMORIES)) {
13947 if (REG_RD(sc, IGU_REG_RESET_MEMORIES)) {
13948 BLOGD(sc, DBG_LOAD, "FORCING IGU Normal Mode failed!!!\n");
13949 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
13954 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
13955 BLOGD(sc, DBG_LOAD, "IGU Backward Compatible Mode\n");
13956 sc->devinfo.int_block |= INT_BLOCK_MODE_BW_COMP;
13958 BLOGD(sc, DBG_LOAD, "IGU Normal Mode\n");
13961 rc = bxe_get_igu_cam_info(sc);
13963 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
13971 * Get base FW non-default (fast path) status block ID. This value is
13972 * used to initialize the fw_sb_id saved on the fp/queue structure to
13973 * determine the id used by the FW.
13975 if (CHIP_IS_E1x(sc)) {
13976 sc->base_fw_ndsb = ((SC_PORT(sc) * FP_SB_MAX_E1x) + SC_L_ID(sc));
13979 * 57712+ - We currently use one FW SB per IGU SB (Rx and Tx of
13980 * the same queue are indicated on the same IGU SB). So we prefer
13981 * FW and IGU SBs to be the same value.
13983 sc->base_fw_ndsb = sc->igu_base_sb;
13986 BLOGD(sc, DBG_LOAD,
13987 "igu_dsb_id=%d igu_base_sb=%d igu_sb_cnt=%d base_fw_ndsb=%d\n",
13988 sc->igu_dsb_id, sc->igu_base_sb,
13989 sc->igu_sb_cnt, sc->base_fw_ndsb);
13991 elink_phy_probe(&sc->link_params);
13997 bxe_link_settings_supported(struct bxe_softc *sc,
13998 uint32_t switch_cfg)
14000 uint32_t cfg_size = 0;
14002 uint8_t port = SC_PORT(sc);
14004 /* aggregation of supported attributes of all external phys */
14005 sc->port.supported[0] = 0;
14006 sc->port.supported[1] = 0;
14008 switch (sc->link_params.num_phys) {
14010 sc->port.supported[0] = sc->link_params.phy[ELINK_INT_PHY].supported;
14014 sc->port.supported[0] = sc->link_params.phy[ELINK_EXT_PHY1].supported;
14018 if (sc->link_params.multi_phy_config &
14019 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
14020 sc->port.supported[1] =
14021 sc->link_params.phy[ELINK_EXT_PHY1].supported;
14022 sc->port.supported[0] =
14023 sc->link_params.phy[ELINK_EXT_PHY2].supported;
14025 sc->port.supported[0] =
14026 sc->link_params.phy[ELINK_EXT_PHY1].supported;
14027 sc->port.supported[1] =
14028 sc->link_params.phy[ELINK_EXT_PHY2].supported;
14034 if (!(sc->port.supported[0] || sc->port.supported[1])) {
14035 BLOGE(sc, "Invalid phy config in NVRAM (PHY1=0x%08x PHY2=0x%08x)\n",
14037 dev_info.port_hw_config[port].external_phy_config),
14039 dev_info.port_hw_config[port].external_phy_config2));
14043 if (CHIP_IS_E3(sc))
14044 sc->port.phy_addr = REG_RD(sc, MISC_REG_WC0_CTRL_PHY_ADDR);
14046 switch (switch_cfg) {
14047 case ELINK_SWITCH_CFG_1G:
14048 sc->port.phy_addr =
14049 REG_RD(sc, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
14051 case ELINK_SWITCH_CFG_10G:
14052 sc->port.phy_addr =
14053 REG_RD(sc, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
14056 BLOGE(sc, "Invalid switch config in link_config=0x%08x\n",
14057 sc->port.link_config[0]);
14062 BLOGD(sc, DBG_LOAD, "PHY addr 0x%08x\n", sc->port.phy_addr);
14064 /* mask what we support according to speed_cap_mask per configuration */
14065 for (idx = 0; idx < cfg_size; idx++) {
14066 if (!(sc->link_params.speed_cap_mask[idx] &
14067 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) {
14068 sc->port.supported[idx] &= ~ELINK_SUPPORTED_10baseT_Half;
14071 if (!(sc->link_params.speed_cap_mask[idx] &
14072 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL)) {
14073 sc->port.supported[idx] &= ~ELINK_SUPPORTED_10baseT_Full;
14076 if (!(sc->link_params.speed_cap_mask[idx] &
14077 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)) {
14078 sc->port.supported[idx] &= ~ELINK_SUPPORTED_100baseT_Half;
14081 if (!(sc->link_params.speed_cap_mask[idx] &
14082 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL)) {
14083 sc->port.supported[idx] &= ~ELINK_SUPPORTED_100baseT_Full;
14086 if (!(sc->link_params.speed_cap_mask[idx] &
14087 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) {
14088 sc->port.supported[idx] &= ~ELINK_SUPPORTED_1000baseT_Full;
14091 if (!(sc->link_params.speed_cap_mask[idx] &
14092 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)) {
14093 sc->port.supported[idx] &= ~ELINK_SUPPORTED_2500baseX_Full;
14096 if (!(sc->link_params.speed_cap_mask[idx] &
14097 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
14098 sc->port.supported[idx] &= ~ELINK_SUPPORTED_10000baseT_Full;
14101 if (!(sc->link_params.speed_cap_mask[idx] &
14102 PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)) {
14103 sc->port.supported[idx] &= ~ELINK_SUPPORTED_20000baseKR2_Full;
14107 BLOGD(sc, DBG_LOAD, "PHY supported 0=0x%08x 1=0x%08x\n",
14108 sc->port.supported[0], sc->port.supported[1]);
14112 bxe_link_settings_requested(struct bxe_softc *sc)
14114 uint32_t link_config;
14116 uint32_t cfg_size = 0;
14118 sc->port.advertising[0] = 0;
14119 sc->port.advertising[1] = 0;
14121 switch (sc->link_params.num_phys) {
14131 for (idx = 0; idx < cfg_size; idx++) {
14132 sc->link_params.req_duplex[idx] = DUPLEX_FULL;
14133 link_config = sc->port.link_config[idx];
14135 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
14136 case PORT_FEATURE_LINK_SPEED_AUTO:
14137 if (sc->port.supported[idx] & ELINK_SUPPORTED_Autoneg) {
14138 sc->link_params.req_line_speed[idx] = ELINK_SPEED_AUTO_NEG;
14139 sc->port.advertising[idx] |= sc->port.supported[idx];
14140 if (sc->link_params.phy[ELINK_EXT_PHY1].type ==
14141 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
14142 sc->port.advertising[idx] |=
14143 (ELINK_SUPPORTED_100baseT_Half |
14144 ELINK_SUPPORTED_100baseT_Full);
14146 /* force 10G, no AN */
14147 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10000;
14148 sc->port.advertising[idx] |=
14149 (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
14154 case PORT_FEATURE_LINK_SPEED_10M_FULL:
14155 if (sc->port.supported[idx] & ELINK_SUPPORTED_10baseT_Full) {
14156 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10;
14157 sc->port.advertising[idx] |= (ADVERTISED_10baseT_Full |
14160 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14161 "speed_cap_mask=0x%08x\n",
14162 link_config, sc->link_params.speed_cap_mask[idx]);
14167 case PORT_FEATURE_LINK_SPEED_10M_HALF:
14168 if (sc->port.supported[idx] & ELINK_SUPPORTED_10baseT_Half) {
14169 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10;
14170 sc->link_params.req_duplex[idx] = DUPLEX_HALF;
14171 sc->port.advertising[idx] |= (ADVERTISED_10baseT_Half |
14174 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14175 "speed_cap_mask=0x%08x\n",
14176 link_config, sc->link_params.speed_cap_mask[idx]);
14181 case PORT_FEATURE_LINK_SPEED_100M_FULL:
14182 if (sc->port.supported[idx] & ELINK_SUPPORTED_100baseT_Full) {
14183 sc->link_params.req_line_speed[idx] = ELINK_SPEED_100;
14184 sc->port.advertising[idx] |= (ADVERTISED_100baseT_Full |
14187 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14188 "speed_cap_mask=0x%08x\n",
14189 link_config, sc->link_params.speed_cap_mask[idx]);
14194 case PORT_FEATURE_LINK_SPEED_100M_HALF:
14195 if (sc->port.supported[idx] & ELINK_SUPPORTED_100baseT_Half) {
14196 sc->link_params.req_line_speed[idx] = ELINK_SPEED_100;
14197 sc->link_params.req_duplex[idx] = DUPLEX_HALF;
14198 sc->port.advertising[idx] |= (ADVERTISED_100baseT_Half |
14201 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14202 "speed_cap_mask=0x%08x\n",
14203 link_config, sc->link_params.speed_cap_mask[idx]);
14208 case PORT_FEATURE_LINK_SPEED_1G:
14209 if (sc->port.supported[idx] & ELINK_SUPPORTED_1000baseT_Full) {
14210 sc->link_params.req_line_speed[idx] = ELINK_SPEED_1000;
14211 sc->port.advertising[idx] |= (ADVERTISED_1000baseT_Full |
14214 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14215 "speed_cap_mask=0x%08x\n",
14216 link_config, sc->link_params.speed_cap_mask[idx]);
14221 case PORT_FEATURE_LINK_SPEED_2_5G:
14222 if (sc->port.supported[idx] & ELINK_SUPPORTED_2500baseX_Full) {
14223 sc->link_params.req_line_speed[idx] = ELINK_SPEED_2500;
14224 sc->port.advertising[idx] |= (ADVERTISED_2500baseX_Full |
14227 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14228 "speed_cap_mask=0x%08x\n",
14229 link_config, sc->link_params.speed_cap_mask[idx]);
14234 case PORT_FEATURE_LINK_SPEED_10G_CX4:
14235 if (sc->port.supported[idx] & ELINK_SUPPORTED_10000baseT_Full) {
14236 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10000;
14237 sc->port.advertising[idx] |= (ADVERTISED_10000baseT_Full |
14240 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14241 "speed_cap_mask=0x%08x\n",
14242 link_config, sc->link_params.speed_cap_mask[idx]);
14247 case PORT_FEATURE_LINK_SPEED_20G:
14248 sc->link_params.req_line_speed[idx] = ELINK_SPEED_20000;
14252 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14253 "speed_cap_mask=0x%08x\n",
14254 link_config, sc->link_params.speed_cap_mask[idx]);
14255 sc->link_params.req_line_speed[idx] = ELINK_SPEED_AUTO_NEG;
14256 sc->port.advertising[idx] = sc->port.supported[idx];
14260 sc->link_params.req_flow_ctrl[idx] =
14261 (link_config & PORT_FEATURE_FLOW_CONTROL_MASK);
14263 if (sc->link_params.req_flow_ctrl[idx] == ELINK_FLOW_CTRL_AUTO) {
14264 if (!(sc->port.supported[idx] & ELINK_SUPPORTED_Autoneg)) {
14265 sc->link_params.req_flow_ctrl[idx] = ELINK_FLOW_CTRL_NONE;
14267 bxe_set_requested_fc(sc);
14271 BLOGD(sc, DBG_LOAD, "req_line_speed=%d req_duplex=%d "
14272 "req_flow_ctrl=0x%x advertising=0x%x\n",
14273 sc->link_params.req_line_speed[idx],
14274 sc->link_params.req_duplex[idx],
14275 sc->link_params.req_flow_ctrl[idx],
14276 sc->port.advertising[idx]);
14281 bxe_get_phy_info(struct bxe_softc *sc)
14283 uint8_t port = SC_PORT(sc);
14284 uint32_t config = sc->port.config;
14287 /* shmem data already read in bxe_get_shmem_info() */
14289 BLOGD(sc, DBG_LOAD, "lane_config=0x%08x speed_cap_mask0=0x%08x "
14290 "link_config0=0x%08x\n",
14291 sc->link_params.lane_config,
14292 sc->link_params.speed_cap_mask[0],
14293 sc->port.link_config[0]);
14295 bxe_link_settings_supported(sc, sc->link_params.switch_cfg);
14296 bxe_link_settings_requested(sc);
14298 if (sc->autogreeen == AUTO_GREEN_FORCE_ON) {
14299 sc->link_params.feature_config_flags |=
14300 ELINK_FEATURE_CONFIG_AUTOGREEEN_ENABLED;
14301 } else if (sc->autogreeen == AUTO_GREEN_FORCE_OFF) {
14302 sc->link_params.feature_config_flags &=
14303 ~ELINK_FEATURE_CONFIG_AUTOGREEEN_ENABLED;
14304 } else if (config & PORT_FEAT_CFG_AUTOGREEEN_ENABLED) {
14305 sc->link_params.feature_config_flags |=
14306 ELINK_FEATURE_CONFIG_AUTOGREEEN_ENABLED;
14309 /* configure link feature according to nvram value */
14311 (((SHMEM_RD(sc, dev_info.port_feature_config[port].eee_power_mode)) &
14312 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
14313 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
14314 if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
14315 sc->link_params.eee_mode = (ELINK_EEE_MODE_ADV_LPI |
14316 ELINK_EEE_MODE_ENABLE_LPI |
14317 ELINK_EEE_MODE_OUTPUT_TIME);
14319 sc->link_params.eee_mode = 0;
14322 /* get the media type */
14323 bxe_media_detect(sc);
14327 bxe_get_params(struct bxe_softc *sc)
14329 /* get user tunable params */
14330 bxe_get_tunable_params(sc);
14332 /* select the RX and TX ring sizes */
14333 sc->tx_ring_size = TX_BD_USABLE;
14334 sc->rx_ring_size = RX_BD_USABLE;
14336 /* XXX disable WoL */
14341 bxe_set_modes_bitmap(struct bxe_softc *sc)
14343 uint32_t flags = 0;
14345 if (CHIP_REV_IS_FPGA(sc)) {
14346 SET_FLAGS(flags, MODE_FPGA);
14347 } else if (CHIP_REV_IS_EMUL(sc)) {
14348 SET_FLAGS(flags, MODE_EMUL);
14350 SET_FLAGS(flags, MODE_ASIC);
14353 if (CHIP_IS_MODE_4_PORT(sc)) {
14354 SET_FLAGS(flags, MODE_PORT4);
14356 SET_FLAGS(flags, MODE_PORT2);
14359 if (CHIP_IS_E2(sc)) {
14360 SET_FLAGS(flags, MODE_E2);
14361 } else if (CHIP_IS_E3(sc)) {
14362 SET_FLAGS(flags, MODE_E3);
14363 if (CHIP_REV(sc) == CHIP_REV_Ax) {
14364 SET_FLAGS(flags, MODE_E3_A0);
14365 } else /*if (CHIP_REV(sc) == CHIP_REV_Bx)*/ {
14366 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
14371 SET_FLAGS(flags, MODE_MF);
14372 switch (sc->devinfo.mf_info.mf_mode) {
14373 case MULTI_FUNCTION_SD:
14374 SET_FLAGS(flags, MODE_MF_SD);
14376 case MULTI_FUNCTION_SI:
14377 SET_FLAGS(flags, MODE_MF_SI);
14379 case MULTI_FUNCTION_AFEX:
14380 SET_FLAGS(flags, MODE_MF_AFEX);
14384 SET_FLAGS(flags, MODE_SF);
14387 #if defined(__LITTLE_ENDIAN)
14388 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
14389 #else /* __BIG_ENDIAN */
14390 SET_FLAGS(flags, MODE_BIG_ENDIAN);
14393 INIT_MODE_FLAGS(sc) = flags;
14397 bxe_alloc_hsi_mem(struct bxe_softc *sc)
14399 struct bxe_fastpath *fp;
14400 bus_addr_t busaddr;
14401 int max_agg_queues;
14403 bus_size_t max_size;
14404 bus_size_t max_seg_size;
14409 /* XXX zero out all vars here and call bxe_alloc_hsi_mem on error */
14411 /* allocate the parent bus DMA tag */
14412 rc = bus_dma_tag_create(bus_get_dma_tag(sc->dev), /* parent tag */
14414 0, /* boundary limit */
14415 BUS_SPACE_MAXADDR, /* restricted low */
14416 BUS_SPACE_MAXADDR, /* restricted hi */
14417 NULL, /* addr filter() */
14418 NULL, /* addr filter() arg */
14419 BUS_SPACE_MAXSIZE_32BIT, /* max map size */
14420 BUS_SPACE_UNRESTRICTED, /* num discontinuous */
14421 BUS_SPACE_MAXSIZE_32BIT, /* max seg size */
14424 NULL, /* lock() arg */
14425 &sc->parent_dma_tag); /* returned dma tag */
14427 BLOGE(sc, "Failed to alloc parent DMA tag (%d)!\n", rc);
14431 /************************/
14432 /* DEFAULT STATUS BLOCK */
14433 /************************/
14435 if (bxe_dma_alloc(sc, sizeof(struct host_sp_status_block),
14436 &sc->def_sb_dma, "default status block") != 0) {
14438 bus_dma_tag_destroy(sc->parent_dma_tag);
14442 sc->def_sb = (struct host_sp_status_block *)sc->def_sb_dma.vaddr;
14448 if (bxe_dma_alloc(sc, BCM_PAGE_SIZE,
14449 &sc->eq_dma, "event queue") != 0) {
14451 bxe_dma_free(sc, &sc->def_sb_dma);
14453 bus_dma_tag_destroy(sc->parent_dma_tag);
14457 sc->eq = (union event_ring_elem * )sc->eq_dma.vaddr;
14463 if (bxe_dma_alloc(sc, sizeof(struct bxe_slowpath),
14464 &sc->sp_dma, "slow path") != 0) {
14466 bxe_dma_free(sc, &sc->eq_dma);
14468 bxe_dma_free(sc, &sc->def_sb_dma);
14470 bus_dma_tag_destroy(sc->parent_dma_tag);
14474 sc->sp = (struct bxe_slowpath *)sc->sp_dma.vaddr;
14476 /*******************/
14477 /* SLOW PATH QUEUE */
14478 /*******************/
14480 if (bxe_dma_alloc(sc, BCM_PAGE_SIZE,
14481 &sc->spq_dma, "slow path queue") != 0) {
14483 bxe_dma_free(sc, &sc->sp_dma);
14485 bxe_dma_free(sc, &sc->eq_dma);
14487 bxe_dma_free(sc, &sc->def_sb_dma);
14489 bus_dma_tag_destroy(sc->parent_dma_tag);
14493 sc->spq = (struct eth_spe *)sc->spq_dma.vaddr;
14495 /***************************/
14496 /* FW DECOMPRESSION BUFFER */
14497 /***************************/
14499 if (bxe_dma_alloc(sc, FW_BUF_SIZE, &sc->gz_buf_dma,
14500 "fw decompression buffer") != 0) {
14502 bxe_dma_free(sc, &sc->spq_dma);
14504 bxe_dma_free(sc, &sc->sp_dma);
14506 bxe_dma_free(sc, &sc->eq_dma);
14508 bxe_dma_free(sc, &sc->def_sb_dma);
14510 bus_dma_tag_destroy(sc->parent_dma_tag);
14514 sc->gz_buf = (void *)sc->gz_buf_dma.vaddr;
14517 malloc(sizeof(*sc->gz_strm), M_DEVBUF, M_NOWAIT)) == NULL) {
14519 bxe_dma_free(sc, &sc->gz_buf_dma);
14521 bxe_dma_free(sc, &sc->spq_dma);
14523 bxe_dma_free(sc, &sc->sp_dma);
14525 bxe_dma_free(sc, &sc->eq_dma);
14527 bxe_dma_free(sc, &sc->def_sb_dma);
14529 bus_dma_tag_destroy(sc->parent_dma_tag);
14537 /* allocate DMA memory for each fastpath structure */
14538 for (i = 0; i < sc->num_queues; i++) {
14543 /*******************/
14544 /* FP STATUS BLOCK */
14545 /*******************/
14547 snprintf(buf, sizeof(buf), "fp %d status block", i);
14548 if (bxe_dma_alloc(sc, sizeof(union bxe_host_hc_status_block),
14549 &fp->sb_dma, buf) != 0) {
14550 /* XXX unwind and free previous fastpath allocations */
14551 BLOGE(sc, "Failed to alloc %s\n", buf);
14554 if (CHIP_IS_E2E3(sc)) {
14555 fp->status_block.e2_sb =
14556 (struct host_hc_status_block_e2 *)fp->sb_dma.vaddr;
14558 fp->status_block.e1x_sb =
14559 (struct host_hc_status_block_e1x *)fp->sb_dma.vaddr;
14563 /******************/
14564 /* FP TX BD CHAIN */
14565 /******************/
14567 snprintf(buf, sizeof(buf), "fp %d tx bd chain", i);
14568 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * TX_BD_NUM_PAGES),
14569 &fp->tx_dma, buf) != 0) {
14570 /* XXX unwind and free previous fastpath allocations */
14571 BLOGE(sc, "Failed to alloc %s\n", buf);
14574 fp->tx_chain = (union eth_tx_bd_types *)fp->tx_dma.vaddr;
14577 /* link together the tx bd chain pages */
14578 for (j = 1; j <= TX_BD_NUM_PAGES; j++) {
14579 /* index into the tx bd chain array to last entry per page */
14580 struct eth_tx_next_bd *tx_next_bd =
14581 &fp->tx_chain[TX_BD_TOTAL_PER_PAGE * j - 1].next_bd;
14582 /* point to the next page and wrap from last page */
14583 busaddr = (fp->tx_dma.paddr +
14584 (BCM_PAGE_SIZE * (j % TX_BD_NUM_PAGES)));
14585 tx_next_bd->addr_hi = htole32(U64_HI(busaddr));
14586 tx_next_bd->addr_lo = htole32(U64_LO(busaddr));
14589 /******************/
14590 /* FP RX BD CHAIN */
14591 /******************/
14593 snprintf(buf, sizeof(buf), "fp %d rx bd chain", i);
14594 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * RX_BD_NUM_PAGES),
14595 &fp->rx_dma, buf) != 0) {
14596 /* XXX unwind and free previous fastpath allocations */
14597 BLOGE(sc, "Failed to alloc %s\n", buf);
14600 fp->rx_chain = (struct eth_rx_bd *)fp->rx_dma.vaddr;
14603 /* link together the rx bd chain pages */
14604 for (j = 1; j <= RX_BD_NUM_PAGES; j++) {
14605 /* index into the rx bd chain array to last entry per page */
14606 struct eth_rx_bd *rx_bd =
14607 &fp->rx_chain[RX_BD_TOTAL_PER_PAGE * j - 2];
14608 /* point to the next page and wrap from last page */
14609 busaddr = (fp->rx_dma.paddr +
14610 (BCM_PAGE_SIZE * (j % RX_BD_NUM_PAGES)));
14611 rx_bd->addr_hi = htole32(U64_HI(busaddr));
14612 rx_bd->addr_lo = htole32(U64_LO(busaddr));
14615 /*******************/
14616 /* FP RX RCQ CHAIN */
14617 /*******************/
14619 snprintf(buf, sizeof(buf), "fp %d rcq chain", i);
14620 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * RCQ_NUM_PAGES),
14621 &fp->rcq_dma, buf) != 0) {
14622 /* XXX unwind and free previous fastpath allocations */
14623 BLOGE(sc, "Failed to alloc %s\n", buf);
14626 fp->rcq_chain = (union eth_rx_cqe *)fp->rcq_dma.vaddr;
14629 /* link together the rcq chain pages */
14630 for (j = 1; j <= RCQ_NUM_PAGES; j++) {
14631 /* index into the rcq chain array to last entry per page */
14632 struct eth_rx_cqe_next_page *rx_cqe_next =
14633 (struct eth_rx_cqe_next_page *)
14634 &fp->rcq_chain[RCQ_TOTAL_PER_PAGE * j - 1];
14635 /* point to the next page and wrap from last page */
14636 busaddr = (fp->rcq_dma.paddr +
14637 (BCM_PAGE_SIZE * (j % RCQ_NUM_PAGES)));
14638 rx_cqe_next->addr_hi = htole32(U64_HI(busaddr));
14639 rx_cqe_next->addr_lo = htole32(U64_LO(busaddr));
14642 /*******************/
14643 /* FP RX SGE CHAIN */
14644 /*******************/
14646 snprintf(buf, sizeof(buf), "fp %d sge chain", i);
14647 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * RX_SGE_NUM_PAGES),
14648 &fp->rx_sge_dma, buf) != 0) {
14649 /* XXX unwind and free previous fastpath allocations */
14650 BLOGE(sc, "Failed to alloc %s\n", buf);
14653 fp->rx_sge_chain = (struct eth_rx_sge *)fp->rx_sge_dma.vaddr;
14656 /* link together the sge chain pages */
14657 for (j = 1; j <= RX_SGE_NUM_PAGES; j++) {
14658 /* index into the rcq chain array to last entry per page */
14659 struct eth_rx_sge *rx_sge =
14660 &fp->rx_sge_chain[RX_SGE_TOTAL_PER_PAGE * j - 2];
14661 /* point to the next page and wrap from last page */
14662 busaddr = (fp->rx_sge_dma.paddr +
14663 (BCM_PAGE_SIZE * (j % RX_SGE_NUM_PAGES)));
14664 rx_sge->addr_hi = htole32(U64_HI(busaddr));
14665 rx_sge->addr_lo = htole32(U64_LO(busaddr));
14668 /***********************/
14669 /* FP TX MBUF DMA MAPS */
14670 /***********************/
14672 /* set required sizes before mapping to conserve resources */
14673 if (sc->ifnet->if_capenable & (IFCAP_TSO4 | IFCAP_TSO6)) {
14674 max_size = BXE_TSO_MAX_SIZE;
14675 max_segments = BXE_TSO_MAX_SEGMENTS;
14676 max_seg_size = BXE_TSO_MAX_SEG_SIZE;
14678 max_size = (MCLBYTES * BXE_MAX_SEGMENTS);
14679 max_segments = BXE_MAX_SEGMENTS;
14680 max_seg_size = MCLBYTES;
14683 /* create a dma tag for the tx mbufs */
14684 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */
14686 0, /* boundary limit */
14687 BUS_SPACE_MAXADDR, /* restricted low */
14688 BUS_SPACE_MAXADDR, /* restricted hi */
14689 NULL, /* addr filter() */
14690 NULL, /* addr filter() arg */
14691 max_size, /* max map size */
14692 max_segments, /* num discontinuous */
14693 max_seg_size, /* max seg size */
14696 NULL, /* lock() arg */
14697 &fp->tx_mbuf_tag); /* returned dma tag */
14699 /* XXX unwind and free previous fastpath allocations */
14700 BLOGE(sc, "Failed to create dma tag for "
14701 "'fp %d tx mbufs' (%d)\n", i, rc);
14705 /* create dma maps for each of the tx mbuf clusters */
14706 for (j = 0; j < TX_BD_TOTAL; j++) {
14707 if (bus_dmamap_create(fp->tx_mbuf_tag,
14709 &fp->tx_mbuf_chain[j].m_map)) {
14710 /* XXX unwind and free previous fastpath allocations */
14711 BLOGE(sc, "Failed to create dma map for "
14712 "'fp %d tx mbuf %d' (%d)\n", i, j, rc);
14717 /***********************/
14718 /* FP RX MBUF DMA MAPS */
14719 /***********************/
14721 /* create a dma tag for the rx mbufs */
14722 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */
14724 0, /* boundary limit */
14725 BUS_SPACE_MAXADDR, /* restricted low */
14726 BUS_SPACE_MAXADDR, /* restricted hi */
14727 NULL, /* addr filter() */
14728 NULL, /* addr filter() arg */
14729 MJUM9BYTES, /* max map size */
14730 1, /* num discontinuous */
14731 MJUM9BYTES, /* max seg size */
14734 NULL, /* lock() arg */
14735 &fp->rx_mbuf_tag); /* returned dma tag */
14737 /* XXX unwind and free previous fastpath allocations */
14738 BLOGE(sc, "Failed to create dma tag for "
14739 "'fp %d rx mbufs' (%d)\n", i, rc);
14743 /* create dma maps for each of the rx mbuf clusters */
14744 for (j = 0; j < RX_BD_TOTAL; j++) {
14745 if (bus_dmamap_create(fp->rx_mbuf_tag,
14747 &fp->rx_mbuf_chain[j].m_map)) {
14748 /* XXX unwind and free previous fastpath allocations */
14749 BLOGE(sc, "Failed to create dma map for "
14750 "'fp %d rx mbuf %d' (%d)\n", i, j, rc);
14755 /* create dma map for the spare rx mbuf cluster */
14756 if (bus_dmamap_create(fp->rx_mbuf_tag,
14758 &fp->rx_mbuf_spare_map)) {
14759 /* XXX unwind and free previous fastpath allocations */
14760 BLOGE(sc, "Failed to create dma map for "
14761 "'fp %d spare rx mbuf' (%d)\n", i, rc);
14765 /***************************/
14766 /* FP RX SGE MBUF DMA MAPS */
14767 /***************************/
14769 /* create a dma tag for the rx sge mbufs */
14770 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */
14772 0, /* boundary limit */
14773 BUS_SPACE_MAXADDR, /* restricted low */
14774 BUS_SPACE_MAXADDR, /* restricted hi */
14775 NULL, /* addr filter() */
14776 NULL, /* addr filter() arg */
14777 BCM_PAGE_SIZE, /* max map size */
14778 1, /* num discontinuous */
14779 BCM_PAGE_SIZE, /* max seg size */
14782 NULL, /* lock() arg */
14783 &fp->rx_sge_mbuf_tag); /* returned dma tag */
14785 /* XXX unwind and free previous fastpath allocations */
14786 BLOGE(sc, "Failed to create dma tag for "
14787 "'fp %d rx sge mbufs' (%d)\n", i, rc);
14791 /* create dma maps for the rx sge mbuf clusters */
14792 for (j = 0; j < RX_SGE_TOTAL; j++) {
14793 if (bus_dmamap_create(fp->rx_sge_mbuf_tag,
14795 &fp->rx_sge_mbuf_chain[j].m_map)) {
14796 /* XXX unwind and free previous fastpath allocations */
14797 BLOGE(sc, "Failed to create dma map for "
14798 "'fp %d rx sge mbuf %d' (%d)\n", i, j, rc);
14803 /* create dma map for the spare rx sge mbuf cluster */
14804 if (bus_dmamap_create(fp->rx_sge_mbuf_tag,
14806 &fp->rx_sge_mbuf_spare_map)) {
14807 /* XXX unwind and free previous fastpath allocations */
14808 BLOGE(sc, "Failed to create dma map for "
14809 "'fp %d spare rx sge mbuf' (%d)\n", i, rc);
14813 /***************************/
14814 /* FP RX TPA MBUF DMA MAPS */
14815 /***************************/
14817 /* create dma maps for the rx tpa mbuf clusters */
14818 max_agg_queues = MAX_AGG_QS(sc);
14820 for (j = 0; j < max_agg_queues; j++) {
14821 if (bus_dmamap_create(fp->rx_mbuf_tag,
14823 &fp->rx_tpa_info[j].bd.m_map)) {
14824 /* XXX unwind and free previous fastpath allocations */
14825 BLOGE(sc, "Failed to create dma map for "
14826 "'fp %d rx tpa mbuf %d' (%d)\n", i, j, rc);
14831 /* create dma map for the spare rx tpa mbuf cluster */
14832 if (bus_dmamap_create(fp->rx_mbuf_tag,
14834 &fp->rx_tpa_info_mbuf_spare_map)) {
14835 /* XXX unwind and free previous fastpath allocations */
14836 BLOGE(sc, "Failed to create dma map for "
14837 "'fp %d spare rx tpa mbuf' (%d)\n", i, rc);
14841 bxe_init_sge_ring_bit_mask(fp);
14848 bxe_free_hsi_mem(struct bxe_softc *sc)
14850 struct bxe_fastpath *fp;
14851 int max_agg_queues;
14854 if (sc->parent_dma_tag == NULL) {
14855 return; /* assume nothing was allocated */
14858 for (i = 0; i < sc->num_queues; i++) {
14861 /*******************/
14862 /* FP STATUS BLOCK */
14863 /*******************/
14865 bxe_dma_free(sc, &fp->sb_dma);
14866 memset(&fp->status_block, 0, sizeof(fp->status_block));
14868 /******************/
14869 /* FP TX BD CHAIN */
14870 /******************/
14872 bxe_dma_free(sc, &fp->tx_dma);
14873 fp->tx_chain = NULL;
14875 /******************/
14876 /* FP RX BD CHAIN */
14877 /******************/
14879 bxe_dma_free(sc, &fp->rx_dma);
14880 fp->rx_chain = NULL;
14882 /*******************/
14883 /* FP RX RCQ CHAIN */
14884 /*******************/
14886 bxe_dma_free(sc, &fp->rcq_dma);
14887 fp->rcq_chain = NULL;
14889 /*******************/
14890 /* FP RX SGE CHAIN */
14891 /*******************/
14893 bxe_dma_free(sc, &fp->rx_sge_dma);
14894 fp->rx_sge_chain = NULL;
14896 /***********************/
14897 /* FP TX MBUF DMA MAPS */
14898 /***********************/
14900 if (fp->tx_mbuf_tag != NULL) {
14901 for (j = 0; j < TX_BD_TOTAL; j++) {
14902 if (fp->tx_mbuf_chain[j].m_map != NULL) {
14903 bus_dmamap_unload(fp->tx_mbuf_tag,
14904 fp->tx_mbuf_chain[j].m_map);
14905 bus_dmamap_destroy(fp->tx_mbuf_tag,
14906 fp->tx_mbuf_chain[j].m_map);
14910 bus_dma_tag_destroy(fp->tx_mbuf_tag);
14911 fp->tx_mbuf_tag = NULL;
14914 /***********************/
14915 /* FP RX MBUF DMA MAPS */
14916 /***********************/
14918 if (fp->rx_mbuf_tag != NULL) {
14919 for (j = 0; j < RX_BD_TOTAL; j++) {
14920 if (fp->rx_mbuf_chain[j].m_map != NULL) {
14921 bus_dmamap_unload(fp->rx_mbuf_tag,
14922 fp->rx_mbuf_chain[j].m_map);
14923 bus_dmamap_destroy(fp->rx_mbuf_tag,
14924 fp->rx_mbuf_chain[j].m_map);
14928 if (fp->rx_mbuf_spare_map != NULL) {
14929 bus_dmamap_unload(fp->rx_mbuf_tag, fp->rx_mbuf_spare_map);
14930 bus_dmamap_destroy(fp->rx_mbuf_tag, fp->rx_mbuf_spare_map);
14933 /***************************/
14934 /* FP RX TPA MBUF DMA MAPS */
14935 /***************************/
14937 max_agg_queues = MAX_AGG_QS(sc);
14939 for (j = 0; j < max_agg_queues; j++) {
14940 if (fp->rx_tpa_info[j].bd.m_map != NULL) {
14941 bus_dmamap_unload(fp->rx_mbuf_tag,
14942 fp->rx_tpa_info[j].bd.m_map);
14943 bus_dmamap_destroy(fp->rx_mbuf_tag,
14944 fp->rx_tpa_info[j].bd.m_map);
14948 if (fp->rx_tpa_info_mbuf_spare_map != NULL) {
14949 bus_dmamap_unload(fp->rx_mbuf_tag,
14950 fp->rx_tpa_info_mbuf_spare_map);
14951 bus_dmamap_destroy(fp->rx_mbuf_tag,
14952 fp->rx_tpa_info_mbuf_spare_map);
14955 bus_dma_tag_destroy(fp->rx_mbuf_tag);
14956 fp->rx_mbuf_tag = NULL;
14959 /***************************/
14960 /* FP RX SGE MBUF DMA MAPS */
14961 /***************************/
14963 if (fp->rx_sge_mbuf_tag != NULL) {
14964 for (j = 0; j < RX_SGE_TOTAL; j++) {
14965 if (fp->rx_sge_mbuf_chain[j].m_map != NULL) {
14966 bus_dmamap_unload(fp->rx_sge_mbuf_tag,
14967 fp->rx_sge_mbuf_chain[j].m_map);
14968 bus_dmamap_destroy(fp->rx_sge_mbuf_tag,
14969 fp->rx_sge_mbuf_chain[j].m_map);
14973 if (fp->rx_sge_mbuf_spare_map != NULL) {
14974 bus_dmamap_unload(fp->rx_sge_mbuf_tag,
14975 fp->rx_sge_mbuf_spare_map);
14976 bus_dmamap_destroy(fp->rx_sge_mbuf_tag,
14977 fp->rx_sge_mbuf_spare_map);
14980 bus_dma_tag_destroy(fp->rx_sge_mbuf_tag);
14981 fp->rx_sge_mbuf_tag = NULL;
14985 /***************************/
14986 /* FW DECOMPRESSION BUFFER */
14987 /***************************/
14989 bxe_dma_free(sc, &sc->gz_buf_dma);
14991 free(sc->gz_strm, M_DEVBUF);
14992 sc->gz_strm = NULL;
14994 /*******************/
14995 /* SLOW PATH QUEUE */
14996 /*******************/
14998 bxe_dma_free(sc, &sc->spq_dma);
15005 bxe_dma_free(sc, &sc->sp_dma);
15012 bxe_dma_free(sc, &sc->eq_dma);
15015 /************************/
15016 /* DEFAULT STATUS BLOCK */
15017 /************************/
15019 bxe_dma_free(sc, &sc->def_sb_dma);
15022 bus_dma_tag_destroy(sc->parent_dma_tag);
15023 sc->parent_dma_tag = NULL;
15027 * Previous driver DMAE transaction may have occurred when pre-boot stage
15028 * ended and boot began. This would invalidate the addresses of the
15029 * transaction, resulting in was-error bit set in the PCI causing all
15030 * hw-to-host PCIe transactions to timeout. If this happened we want to clear
15031 * the interrupt which detected this from the pglueb and the was-done bit
15034 bxe_prev_interrupted_dmae(struct bxe_softc *sc)
15038 if (!CHIP_IS_E1x(sc)) {
15039 val = REG_RD(sc, PGLUE_B_REG_PGLUE_B_INT_STS);
15040 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
15041 BLOGD(sc, DBG_LOAD,
15042 "Clearing 'was-error' bit that was set in pglueb");
15043 REG_WR(sc, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, 1 << SC_FUNC(sc));
15049 bxe_prev_mcp_done(struct bxe_softc *sc)
15051 uint32_t rc = bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE,
15052 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
15054 BLOGE(sc, "MCP response failure, aborting\n");
15061 static struct bxe_prev_list_node *
15062 bxe_prev_path_get_entry(struct bxe_softc *sc)
15064 struct bxe_prev_list_node *tmp;
15066 LIST_FOREACH(tmp, &bxe_prev_list, node) {
15067 if ((sc->pcie_bus == tmp->bus) &&
15068 (sc->pcie_device == tmp->slot) &&
15069 (SC_PATH(sc) == tmp->path)) {
15078 bxe_prev_is_path_marked(struct bxe_softc *sc)
15080 struct bxe_prev_list_node *tmp;
15083 mtx_lock(&bxe_prev_mtx);
15085 tmp = bxe_prev_path_get_entry(sc);
15088 BLOGD(sc, DBG_LOAD,
15089 "Path %d/%d/%d was marked by AER\n",
15090 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15093 BLOGD(sc, DBG_LOAD,
15094 "Path %d/%d/%d was already cleaned from previous drivers\n",
15095 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15099 mtx_unlock(&bxe_prev_mtx);
15105 bxe_prev_mark_path(struct bxe_softc *sc,
15106 uint8_t after_undi)
15108 struct bxe_prev_list_node *tmp;
15110 mtx_lock(&bxe_prev_mtx);
15112 /* Check whether the entry for this path already exists */
15113 tmp = bxe_prev_path_get_entry(sc);
15116 BLOGD(sc, DBG_LOAD,
15117 "Re-marking AER in path %d/%d/%d\n",
15118 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15120 BLOGD(sc, DBG_LOAD,
15121 "Removing AER indication from path %d/%d/%d\n",
15122 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15126 mtx_unlock(&bxe_prev_mtx);
15130 mtx_unlock(&bxe_prev_mtx);
15132 /* Create an entry for this path and add it */
15133 tmp = malloc(sizeof(struct bxe_prev_list_node), M_DEVBUF,
15134 (M_NOWAIT | M_ZERO));
15136 BLOGE(sc, "Failed to allocate 'bxe_prev_list_node'\n");
15140 tmp->bus = sc->pcie_bus;
15141 tmp->slot = sc->pcie_device;
15142 tmp->path = SC_PATH(sc);
15144 tmp->undi = after_undi ? (1 << SC_PORT(sc)) : 0;
15146 mtx_lock(&bxe_prev_mtx);
15148 BLOGD(sc, DBG_LOAD,
15149 "Marked path %d/%d/%d - finished previous unload\n",
15150 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15151 LIST_INSERT_HEAD(&bxe_prev_list, tmp, node);
15153 mtx_unlock(&bxe_prev_mtx);
15159 bxe_do_flr(struct bxe_softc *sc)
15163 /* only E2 and onwards support FLR */
15164 if (CHIP_IS_E1x(sc)) {
15165 BLOGD(sc, DBG_LOAD, "FLR not supported in E1/E1H\n");
15169 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
15170 if (sc->devinfo.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
15171 BLOGD(sc, DBG_LOAD, "FLR not supported by BC_VER: 0x%08x\n",
15172 sc->devinfo.bc_ver);
15176 /* Wait for Transaction Pending bit clean */
15177 for (i = 0; i < 4; i++) {
15179 DELAY(((1 << (i - 1)) * 100) * 1000);
15182 if (!bxe_is_pcie_pending(sc)) {
15187 BLOGE(sc, "PCIE transaction is not cleared, "
15188 "proceeding with reset anyway\n");
15192 BLOGD(sc, DBG_LOAD, "Initiating FLR\n");
15193 bxe_fw_command(sc, DRV_MSG_CODE_INITIATE_FLR, 0);
15198 struct bxe_mac_vals {
15199 uint32_t xmac_addr;
15201 uint32_t emac_addr;
15203 uint32_t umac_addr;
15205 uint32_t bmac_addr;
15206 uint32_t bmac_val[2];
15210 bxe_prev_unload_close_mac(struct bxe_softc *sc,
15211 struct bxe_mac_vals *vals)
15213 uint32_t val, base_addr, offset, mask, reset_reg;
15214 uint8_t mac_stopped = FALSE;
15215 uint8_t port = SC_PORT(sc);
15216 uint32_t wb_data[2];
15218 /* reset addresses as they also mark which values were changed */
15219 vals->bmac_addr = 0;
15220 vals->umac_addr = 0;
15221 vals->xmac_addr = 0;
15222 vals->emac_addr = 0;
15224 reset_reg = REG_RD(sc, MISC_REG_RESET_REG_2);
15226 if (!CHIP_IS_E3(sc)) {
15227 val = REG_RD(sc, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
15228 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
15229 if ((mask & reset_reg) && val) {
15230 BLOGD(sc, DBG_LOAD, "Disable BMAC Rx\n");
15231 base_addr = SC_PORT(sc) ? NIG_REG_INGRESS_BMAC1_MEM
15232 : NIG_REG_INGRESS_BMAC0_MEM;
15233 offset = CHIP_IS_E2(sc) ? BIGMAC2_REGISTER_BMAC_CONTROL
15234 : BIGMAC_REGISTER_BMAC_CONTROL;
15237 * use rd/wr since we cannot use dmae. This is safe
15238 * since MCP won't access the bus due to the request
15239 * to unload, and no function on the path can be
15240 * loaded at this time.
15242 wb_data[0] = REG_RD(sc, base_addr + offset);
15243 wb_data[1] = REG_RD(sc, base_addr + offset + 0x4);
15244 vals->bmac_addr = base_addr + offset;
15245 vals->bmac_val[0] = wb_data[0];
15246 vals->bmac_val[1] = wb_data[1];
15247 wb_data[0] &= ~ELINK_BMAC_CONTROL_RX_ENABLE;
15248 REG_WR(sc, vals->bmac_addr, wb_data[0]);
15249 REG_WR(sc, vals->bmac_addr + 0x4, wb_data[1]);
15252 BLOGD(sc, DBG_LOAD, "Disable EMAC Rx\n");
15253 vals->emac_addr = NIG_REG_NIG_EMAC0_EN + SC_PORT(sc)*4;
15254 vals->emac_val = REG_RD(sc, vals->emac_addr);
15255 REG_WR(sc, vals->emac_addr, 0);
15256 mac_stopped = TRUE;
15258 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
15259 BLOGD(sc, DBG_LOAD, "Disable XMAC Rx\n");
15260 base_addr = SC_PORT(sc) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
15261 val = REG_RD(sc, base_addr + XMAC_REG_PFC_CTRL_HI);
15262 REG_WR(sc, base_addr + XMAC_REG_PFC_CTRL_HI, val & ~(1 << 1));
15263 REG_WR(sc, base_addr + XMAC_REG_PFC_CTRL_HI, val | (1 << 1));
15264 vals->xmac_addr = base_addr + XMAC_REG_CTRL;
15265 vals->xmac_val = REG_RD(sc, vals->xmac_addr);
15266 REG_WR(sc, vals->xmac_addr, 0);
15267 mac_stopped = TRUE;
15270 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
15271 if (mask & reset_reg) {
15272 BLOGD(sc, DBG_LOAD, "Disable UMAC Rx\n");
15273 base_addr = SC_PORT(sc) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
15274 vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
15275 vals->umac_val = REG_RD(sc, vals->umac_addr);
15276 REG_WR(sc, vals->umac_addr, 0);
15277 mac_stopped = TRUE;
15286 #define BXE_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
15287 #define BXE_PREV_UNDI_RCQ(val) ((val) & 0xffff)
15288 #define BXE_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
15289 #define BXE_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
15292 bxe_prev_unload_undi_inc(struct bxe_softc *sc,
15297 uint32_t tmp_reg = REG_RD(sc, BXE_PREV_UNDI_PROD_ADDR(port));
15299 rcq = BXE_PREV_UNDI_RCQ(tmp_reg) + inc;
15300 bd = BXE_PREV_UNDI_BD(tmp_reg) + inc;
15302 tmp_reg = BXE_PREV_UNDI_PROD(rcq, bd);
15303 REG_WR(sc, BXE_PREV_UNDI_PROD_ADDR(port), tmp_reg);
15305 BLOGD(sc, DBG_LOAD,
15306 "UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
15311 bxe_prev_unload_common(struct bxe_softc *sc)
15313 uint32_t reset_reg, tmp_reg = 0, rc;
15314 uint8_t prev_undi = FALSE;
15315 struct bxe_mac_vals mac_vals;
15316 uint32_t timer_count = 1000;
15320 * It is possible a previous function received 'common' answer,
15321 * but hasn't loaded yet, therefore creating a scenario of
15322 * multiple functions receiving 'common' on the same path.
15324 BLOGD(sc, DBG_LOAD, "Common unload Flow\n");
15326 memset(&mac_vals, 0, sizeof(mac_vals));
15328 if (bxe_prev_is_path_marked(sc)) {
15329 return (bxe_prev_mcp_done(sc));
15332 reset_reg = REG_RD(sc, MISC_REG_RESET_REG_1);
15334 /* Reset should be performed after BRB is emptied */
15335 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
15336 /* Close the MAC Rx to prevent BRB from filling up */
15337 bxe_prev_unload_close_mac(sc, &mac_vals);
15339 /* close LLH filters towards the BRB */
15340 elink_set_rx_filter(&sc->link_params, 0);
15343 * Check if the UNDI driver was previously loaded.
15344 * UNDI driver initializes CID offset for normal bell to 0x7
15346 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
15347 tmp_reg = REG_RD(sc, DORQ_REG_NORM_CID_OFST);
15348 if (tmp_reg == 0x7) {
15349 BLOGD(sc, DBG_LOAD, "UNDI previously loaded\n");
15351 /* clear the UNDI indication */
15352 REG_WR(sc, DORQ_REG_NORM_CID_OFST, 0);
15353 /* clear possible idle check errors */
15354 REG_RD(sc, NIG_REG_NIG_INT_STS_CLR_0);
15358 /* wait until BRB is empty */
15359 tmp_reg = REG_RD(sc, BRB1_REG_NUM_OF_FULL_BLOCKS);
15360 while (timer_count) {
15361 prev_brb = tmp_reg;
15363 tmp_reg = REG_RD(sc, BRB1_REG_NUM_OF_FULL_BLOCKS);
15368 BLOGD(sc, DBG_LOAD, "BRB still has 0x%08x\n", tmp_reg);
15370 /* reset timer as long as BRB actually gets emptied */
15371 if (prev_brb > tmp_reg) {
15372 timer_count = 1000;
15377 /* If UNDI resides in memory, manually increment it */
15379 bxe_prev_unload_undi_inc(sc, SC_PORT(sc), 1);
15385 if (!timer_count) {
15386 BLOGE(sc, "Failed to empty BRB\n");
15390 /* No packets are in the pipeline, path is ready for reset */
15391 bxe_reset_common(sc);
15393 if (mac_vals.xmac_addr) {
15394 REG_WR(sc, mac_vals.xmac_addr, mac_vals.xmac_val);
15396 if (mac_vals.umac_addr) {
15397 REG_WR(sc, mac_vals.umac_addr, mac_vals.umac_val);
15399 if (mac_vals.emac_addr) {
15400 REG_WR(sc, mac_vals.emac_addr, mac_vals.emac_val);
15402 if (mac_vals.bmac_addr) {
15403 REG_WR(sc, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
15404 REG_WR(sc, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
15407 rc = bxe_prev_mark_path(sc, prev_undi);
15409 bxe_prev_mcp_done(sc);
15413 return (bxe_prev_mcp_done(sc));
15417 bxe_prev_unload_uncommon(struct bxe_softc *sc)
15421 BLOGD(sc, DBG_LOAD, "Uncommon unload Flow\n");
15423 /* Test if previous unload process was already finished for this path */
15424 if (bxe_prev_is_path_marked(sc)) {
15425 return (bxe_prev_mcp_done(sc));
15428 BLOGD(sc, DBG_LOAD, "Path is unmarked\n");
15431 * If function has FLR capabilities, and existing FW version matches
15432 * the one required, then FLR will be sufficient to clean any residue
15433 * left by previous driver
15435 rc = bxe_nic_load_analyze_req(sc, FW_MSG_CODE_DRV_LOAD_FUNCTION);
15437 /* fw version is good */
15438 BLOGD(sc, DBG_LOAD, "FW version matches our own, attempting FLR\n");
15439 rc = bxe_do_flr(sc);
15443 /* FLR was performed */
15444 BLOGD(sc, DBG_LOAD, "FLR successful\n");
15448 BLOGD(sc, DBG_LOAD, "Could not FLR\n");
15450 /* Close the MCP request, return failure*/
15451 rc = bxe_prev_mcp_done(sc);
15453 rc = BXE_PREV_WAIT_NEEDED;
15460 bxe_prev_unload(struct bxe_softc *sc)
15462 int time_counter = 10;
15463 uint32_t fw, hw_lock_reg, hw_lock_val;
15467 * Clear HW from errors which may have resulted from an interrupted
15468 * DMAE transaction.
15470 bxe_prev_interrupted_dmae(sc);
15472 /* Release previously held locks */
15474 (SC_FUNC(sc) <= 5) ?
15475 (MISC_REG_DRIVER_CONTROL_1 + SC_FUNC(sc) * 8) :
15476 (MISC_REG_DRIVER_CONTROL_7 + (SC_FUNC(sc) - 6) * 8);
15478 hw_lock_val = (REG_RD(sc, hw_lock_reg));
15480 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
15481 BLOGD(sc, DBG_LOAD, "Releasing previously held NVRAM lock\n");
15482 REG_WR(sc, MCP_REG_MCPR_NVM_SW_ARB,
15483 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << SC_PORT(sc)));
15485 BLOGD(sc, DBG_LOAD, "Releasing previously held HW lock\n");
15486 REG_WR(sc, hw_lock_reg, 0xffffffff);
15488 BLOGD(sc, DBG_LOAD, "No need to release HW/NVRAM locks\n");
15491 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(sc, MCP_REG_MCPR_ACCESS_LOCK)) {
15492 BLOGD(sc, DBG_LOAD, "Releasing previously held ALR\n");
15493 REG_WR(sc, MCP_REG_MCPR_ACCESS_LOCK, 0);
15497 /* Lock MCP using an unload request */
15498 fw = bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
15500 BLOGE(sc, "MCP response failure, aborting\n");
15505 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
15506 rc = bxe_prev_unload_common(sc);
15510 /* non-common reply from MCP night require looping */
15511 rc = bxe_prev_unload_uncommon(sc);
15512 if (rc != BXE_PREV_WAIT_NEEDED) {
15517 } while (--time_counter);
15519 if (!time_counter || rc) {
15520 BLOGE(sc, "Failed to unload previous driver!"
15521 " time_counter %d rc %d\n", time_counter, rc);
15529 bxe_dcbx_set_state(struct bxe_softc *sc,
15531 uint32_t dcbx_enabled)
15533 if (!CHIP_IS_E1x(sc)) {
15534 sc->dcb_state = dcb_on;
15535 sc->dcbx_enabled = dcbx_enabled;
15537 sc->dcb_state = FALSE;
15538 sc->dcbx_enabled = BXE_DCBX_ENABLED_INVALID;
15540 BLOGD(sc, DBG_LOAD,
15541 "DCB state [%s:%s]\n",
15542 dcb_on ? "ON" : "OFF",
15543 (dcbx_enabled == BXE_DCBX_ENABLED_OFF) ? "user-mode" :
15544 (dcbx_enabled == BXE_DCBX_ENABLED_ON_NEG_OFF) ? "on-chip static" :
15545 (dcbx_enabled == BXE_DCBX_ENABLED_ON_NEG_ON) ?
15546 "on-chip with negotiation" : "invalid");
15549 /* must be called after sriov-enable */
15551 bxe_set_qm_cid_count(struct bxe_softc *sc)
15553 int cid_count = BXE_L2_MAX_CID(sc);
15555 if (IS_SRIOV(sc)) {
15556 cid_count += BXE_VF_CIDS;
15559 if (CNIC_SUPPORT(sc)) {
15560 cid_count += CNIC_CID_MAX;
15563 return (roundup(cid_count, QM_CID_ROUND));
15567 bxe_init_multi_cos(struct bxe_softc *sc)
15571 uint32_t pri_map = 0; /* XXX change to user config */
15573 for (pri = 0; pri < BXE_MAX_PRIORITY; pri++) {
15574 cos = ((pri_map & (0xf << (pri * 4))) >> (pri * 4));
15575 if (cos < sc->max_cos) {
15576 sc->prio_to_cos[pri] = cos;
15578 BLOGW(sc, "Invalid COS %d for priority %d "
15579 "(max COS is %d), setting to 0\n",
15580 cos, pri, (sc->max_cos - 1));
15581 sc->prio_to_cos[pri] = 0;
15587 bxe_sysctl_state(SYSCTL_HANDLER_ARGS)
15589 struct bxe_softc *sc;
15593 error = sysctl_handle_int(oidp, &result, 0, req);
15595 if (error || !req->newptr) {
15601 sc = (struct bxe_softc *)arg1;
15603 BLOGI(sc, "... dumping driver state ...\n");
15604 temp = SHMEM2_RD(sc, temperature_in_half_celsius);
15605 BLOGI(sc, "\t Device Temperature = %d Celsius\n", (temp/2));
15612 bxe_sysctl_trigger_grcdump(SYSCTL_HANDLER_ARGS)
15614 struct bxe_softc *sc;
15618 error = sysctl_handle_int(oidp, &result, 0, req);
15620 if (error || !req->newptr) {
15625 sc = (struct bxe_softc *)arg1;
15627 BLOGI(sc, "... grcdump start ...\n");
15629 BLOGI(sc, "... grcdump done ...\n");
15636 bxe_sysctl_eth_stat(SYSCTL_HANDLER_ARGS)
15638 struct bxe_softc *sc = (struct bxe_softc *)arg1;
15639 uint32_t *eth_stats = (uint32_t *)&sc->eth_stats;
15641 uint64_t value = 0;
15642 int index = (int)arg2;
15644 if (index >= BXE_NUM_ETH_STATS) {
15645 BLOGE(sc, "bxe_eth_stats index out of range (%d)\n", index);
15649 offset = (eth_stats + bxe_eth_stats_arr[index].offset);
15651 switch (bxe_eth_stats_arr[index].size) {
15653 value = (uint64_t)*offset;
15656 value = HILO_U64(*offset, *(offset + 1));
15659 BLOGE(sc, "Invalid bxe_eth_stats size (index=%d size=%d)\n",
15660 index, bxe_eth_stats_arr[index].size);
15664 return (sysctl_handle_64(oidp, &value, 0, req));
15668 bxe_sysctl_eth_q_stat(SYSCTL_HANDLER_ARGS)
15670 struct bxe_softc *sc = (struct bxe_softc *)arg1;
15671 uint32_t *eth_stats;
15673 uint64_t value = 0;
15674 uint32_t q_stat = (uint32_t)arg2;
15675 uint32_t fp_index = ((q_stat >> 16) & 0xffff);
15676 uint32_t index = (q_stat & 0xffff);
15678 eth_stats = (uint32_t *)&sc->fp[fp_index].eth_q_stats;
15680 if (index >= BXE_NUM_ETH_Q_STATS) {
15681 BLOGE(sc, "bxe_eth_q_stats index out of range (%d)\n", index);
15685 offset = (eth_stats + bxe_eth_q_stats_arr[index].offset);
15687 switch (bxe_eth_q_stats_arr[index].size) {
15689 value = (uint64_t)*offset;
15692 value = HILO_U64(*offset, *(offset + 1));
15695 BLOGE(sc, "Invalid bxe_eth_q_stats size (index=%d size=%d)\n",
15696 index, bxe_eth_q_stats_arr[index].size);
15700 return (sysctl_handle_64(oidp, &value, 0, req));
15704 bxe_add_sysctls(struct bxe_softc *sc)
15706 struct sysctl_ctx_list *ctx;
15707 struct sysctl_oid_list *children;
15708 struct sysctl_oid *queue_top, *queue;
15709 struct sysctl_oid_list *queue_top_children, *queue_children;
15710 char queue_num_buf[32];
15714 ctx = device_get_sysctl_ctx(sc->dev);
15715 children = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev));
15717 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "version",
15718 CTLFLAG_RD, BXE_DRIVER_VERSION, 0,
15721 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "bc_version",
15722 CTLFLAG_RD, &sc->devinfo.bc_ver_str, 0,
15723 "bootcode version");
15725 snprintf(sc->fw_ver_str, sizeof(sc->fw_ver_str), "%d.%d.%d.%d",
15726 BCM_5710_FW_MAJOR_VERSION,
15727 BCM_5710_FW_MINOR_VERSION,
15728 BCM_5710_FW_REVISION_VERSION,
15729 BCM_5710_FW_ENGINEERING_VERSION);
15730 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "fw_version",
15731 CTLFLAG_RD, &sc->fw_ver_str, 0,
15732 "firmware version");
15734 snprintf(sc->mf_mode_str, sizeof(sc->mf_mode_str), "%s",
15735 ((sc->devinfo.mf_info.mf_mode == SINGLE_FUNCTION) ? "Single" :
15736 (sc->devinfo.mf_info.mf_mode == MULTI_FUNCTION_SD) ? "MF-SD" :
15737 (sc->devinfo.mf_info.mf_mode == MULTI_FUNCTION_SI) ? "MF-SI" :
15738 (sc->devinfo.mf_info.mf_mode == MULTI_FUNCTION_AFEX) ? "MF-AFEX" :
15740 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "mf_mode",
15741 CTLFLAG_RD, &sc->mf_mode_str, 0,
15742 "multifunction mode");
15744 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "mf_vnics",
15745 CTLFLAG_RD, &sc->devinfo.mf_info.vnics_per_port, 0,
15746 "multifunction vnics per port");
15748 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "mac_addr",
15749 CTLFLAG_RD, &sc->mac_addr_str, 0,
15752 snprintf(sc->pci_link_str, sizeof(sc->pci_link_str), "%s x%d",
15753 ((sc->devinfo.pcie_link_speed == 1) ? "2.5GT/s" :
15754 (sc->devinfo.pcie_link_speed == 2) ? "5.0GT/s" :
15755 (sc->devinfo.pcie_link_speed == 4) ? "8.0GT/s" :
15757 sc->devinfo.pcie_link_width);
15758 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "pci_link",
15759 CTLFLAG_RD, &sc->pci_link_str, 0,
15760 "pci link status");
15762 sc->debug = bxe_debug;
15763 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "debug",
15764 CTLFLAG_RW, &sc->debug, 0,
15765 "debug logging mode");
15767 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "trigger_grcdump",
15768 CTLTYPE_UINT | CTLFLAG_RW, sc, 0,
15769 bxe_sysctl_trigger_grcdump, "IU",
15770 "set by driver when a grcdump is needed");
15772 sc->grcdump_done = 0;
15773 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "grcdump_done",
15774 CTLFLAG_RW, &sc->grcdump_done, 0,
15775 "set by driver when grcdump is done");
15777 sc->rx_budget = bxe_rx_budget;
15778 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "rx_budget",
15779 CTLFLAG_RW, &sc->rx_budget, 0,
15780 "rx processing budget");
15782 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "state",
15783 CTLTYPE_UINT | CTLFLAG_RW, sc, 0,
15784 bxe_sysctl_state, "IU", "dump driver state");
15786 for (i = 0; i < BXE_NUM_ETH_STATS; i++) {
15787 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
15788 bxe_eth_stats_arr[i].string,
15789 CTLTYPE_U64 | CTLFLAG_RD, sc, i,
15790 bxe_sysctl_eth_stat, "LU",
15791 bxe_eth_stats_arr[i].string);
15794 /* add a new parent node for all queues "dev.bxe.#.queue" */
15795 queue_top = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "queue",
15796 CTLFLAG_RD, NULL, "queue");
15797 queue_top_children = SYSCTL_CHILDREN(queue_top);
15799 for (i = 0; i < sc->num_queues; i++) {
15800 /* add a new parent node for a single queue "dev.bxe.#.queue.#" */
15801 snprintf(queue_num_buf, sizeof(queue_num_buf), "%d", i);
15802 queue = SYSCTL_ADD_NODE(ctx, queue_top_children, OID_AUTO,
15803 queue_num_buf, CTLFLAG_RD, NULL,
15805 queue_children = SYSCTL_CHILDREN(queue);
15807 for (j = 0; j < BXE_NUM_ETH_Q_STATS; j++) {
15808 q_stat = ((i << 16) | j);
15809 SYSCTL_ADD_PROC(ctx, queue_children, OID_AUTO,
15810 bxe_eth_q_stats_arr[j].string,
15811 CTLTYPE_U64 | CTLFLAG_RD, sc, q_stat,
15812 bxe_sysctl_eth_q_stat, "LU",
15813 bxe_eth_q_stats_arr[j].string);
15819 bxe_alloc_buf_rings(struct bxe_softc *sc)
15821 #if __FreeBSD_version >= 800000
15824 struct bxe_fastpath *fp;
15826 for (i = 0; i < sc->num_queues; i++) {
15830 fp->tx_br = buf_ring_alloc(BXE_BR_SIZE, M_DEVBUF,
15831 M_NOWAIT, &fp->tx_mtx);
15832 if (fp->tx_br == NULL)
15840 bxe_free_buf_rings(struct bxe_softc *sc)
15842 #if __FreeBSD_version >= 800000
15845 struct bxe_fastpath *fp;
15847 for (i = 0; i < sc->num_queues; i++) {
15852 buf_ring_free(fp->tx_br, M_DEVBUF);
15861 bxe_init_fp_mutexs(struct bxe_softc *sc)
15864 struct bxe_fastpath *fp;
15866 for (i = 0; i < sc->num_queues; i++) {
15870 snprintf(fp->tx_mtx_name, sizeof(fp->tx_mtx_name),
15871 "bxe%d_fp%d_tx_lock", sc->unit, i);
15872 mtx_init(&fp->tx_mtx, fp->tx_mtx_name, NULL, MTX_DEF);
15874 snprintf(fp->rx_mtx_name, sizeof(fp->rx_mtx_name),
15875 "bxe%d_fp%d_rx_lock", sc->unit, i);
15876 mtx_init(&fp->rx_mtx, fp->rx_mtx_name, NULL, MTX_DEF);
15881 bxe_destroy_fp_mutexs(struct bxe_softc *sc)
15884 struct bxe_fastpath *fp;
15886 for (i = 0; i < sc->num_queues; i++) {
15890 if (mtx_initialized(&fp->tx_mtx)) {
15891 mtx_destroy(&fp->tx_mtx);
15894 if (mtx_initialized(&fp->rx_mtx)) {
15895 mtx_destroy(&fp->rx_mtx);
15902 * Device attach function.
15904 * Allocates device resources, performs secondary chip identification, and
15905 * initializes driver instance variables. This function is called from driver
15906 * load after a successful probe.
15909 * 0 = Success, >0 = Failure
15912 bxe_attach(device_t dev)
15914 struct bxe_softc *sc;
15916 sc = device_get_softc(dev);
15918 BLOGD(sc, DBG_LOAD, "Starting attach...\n");
15920 sc->state = BXE_STATE_CLOSED;
15923 sc->unit = device_get_unit(dev);
15925 BLOGD(sc, DBG_LOAD, "softc = %p\n", sc);
15927 sc->pcie_bus = pci_get_bus(dev);
15928 sc->pcie_device = pci_get_slot(dev);
15929 sc->pcie_func = pci_get_function(dev);
15931 /* enable bus master capability */
15932 pci_enable_busmaster(dev);
15935 if (bxe_allocate_bars(sc) != 0) {
15939 /* initialize the mutexes */
15940 bxe_init_mutexes(sc);
15942 /* prepare the periodic callout */
15943 callout_init(&sc->periodic_callout, 0);
15945 /* prepare the chip taskqueue */
15946 sc->chip_tq_flags = CHIP_TQ_NONE;
15947 snprintf(sc->chip_tq_name, sizeof(sc->chip_tq_name),
15948 "bxe%d_chip_tq", sc->unit);
15949 TASK_INIT(&sc->chip_tq_task, 0, bxe_handle_chip_tq, sc);
15950 sc->chip_tq = taskqueue_create(sc->chip_tq_name, M_NOWAIT,
15951 taskqueue_thread_enqueue,
15953 taskqueue_start_threads(&sc->chip_tq, 1, PWAIT, /* lower priority */
15954 "%s", sc->chip_tq_name);
15956 /* get device info and set params */
15957 if (bxe_get_device_info(sc) != 0) {
15958 BLOGE(sc, "getting device info\n");
15959 bxe_deallocate_bars(sc);
15960 pci_disable_busmaster(dev);
15964 /* get final misc params */
15965 bxe_get_params(sc);
15967 /* set the default MTU (changed via ifconfig) */
15968 sc->mtu = ETHERMTU;
15970 bxe_set_modes_bitmap(sc);
15973 * If in AFEX mode and the function is configured for FCoE
15974 * then bail... no L2 allowed.
15977 /* get phy settings from shmem and 'and' against admin settings */
15978 bxe_get_phy_info(sc);
15980 /* initialize the FreeBSD ifnet interface */
15981 if (bxe_init_ifnet(sc) != 0) {
15982 bxe_release_mutexes(sc);
15983 bxe_deallocate_bars(sc);
15984 pci_disable_busmaster(dev);
15988 if (bxe_add_cdev(sc) != 0) {
15989 if (sc->ifnet != NULL) {
15990 ether_ifdetach(sc->ifnet);
15992 ifmedia_removeall(&sc->ifmedia);
15993 bxe_release_mutexes(sc);
15994 bxe_deallocate_bars(sc);
15995 pci_disable_busmaster(dev);
15999 /* allocate device interrupts */
16000 if (bxe_interrupt_alloc(sc) != 0) {
16002 if (sc->ifnet != NULL) {
16003 ether_ifdetach(sc->ifnet);
16005 ifmedia_removeall(&sc->ifmedia);
16006 bxe_release_mutexes(sc);
16007 bxe_deallocate_bars(sc);
16008 pci_disable_busmaster(dev);
16012 bxe_init_fp_mutexs(sc);
16014 if (bxe_alloc_buf_rings(sc) != 0) {
16015 bxe_free_buf_rings(sc);
16016 bxe_interrupt_free(sc);
16018 if (sc->ifnet != NULL) {
16019 ether_ifdetach(sc->ifnet);
16021 ifmedia_removeall(&sc->ifmedia);
16022 bxe_release_mutexes(sc);
16023 bxe_deallocate_bars(sc);
16024 pci_disable_busmaster(dev);
16029 if (bxe_alloc_ilt_mem(sc) != 0) {
16030 bxe_free_buf_rings(sc);
16031 bxe_interrupt_free(sc);
16033 if (sc->ifnet != NULL) {
16034 ether_ifdetach(sc->ifnet);
16036 ifmedia_removeall(&sc->ifmedia);
16037 bxe_release_mutexes(sc);
16038 bxe_deallocate_bars(sc);
16039 pci_disable_busmaster(dev);
16043 /* allocate the host hardware/software hsi structures */
16044 if (bxe_alloc_hsi_mem(sc) != 0) {
16045 bxe_free_ilt_mem(sc);
16046 bxe_free_buf_rings(sc);
16047 bxe_interrupt_free(sc);
16049 if (sc->ifnet != NULL) {
16050 ether_ifdetach(sc->ifnet);
16052 ifmedia_removeall(&sc->ifmedia);
16053 bxe_release_mutexes(sc);
16054 bxe_deallocate_bars(sc);
16055 pci_disable_busmaster(dev);
16059 /* need to reset chip if UNDI was active */
16060 if (IS_PF(sc) && !BXE_NOMCP(sc)) {
16063 (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_mb_header) &
16064 DRV_MSG_SEQ_NUMBER_MASK);
16065 BLOGD(sc, DBG_LOAD, "prev unload fw_seq 0x%04x\n", sc->fw_seq);
16066 bxe_prev_unload(sc);
16071 bxe_dcbx_set_state(sc, FALSE, BXE_DCBX_ENABLED_OFF);
16073 if (SHMEM2_HAS(sc, dcbx_lldp_params_offset) &&
16074 SHMEM2_HAS(sc, dcbx_lldp_dcbx_stat_offset) &&
16075 SHMEM2_RD(sc, dcbx_lldp_params_offset) &&
16076 SHMEM2_RD(sc, dcbx_lldp_dcbx_stat_offset)) {
16077 bxe_dcbx_set_state(sc, TRUE, BXE_DCBX_ENABLED_ON_NEG_ON);
16078 bxe_dcbx_init_params(sc);
16080 bxe_dcbx_set_state(sc, FALSE, BXE_DCBX_ENABLED_OFF);
16084 /* calculate qm_cid_count */
16085 sc->qm_cid_count = bxe_set_qm_cid_count(sc);
16086 BLOGD(sc, DBG_LOAD, "qm_cid_count=%d\n", sc->qm_cid_count);
16089 bxe_init_multi_cos(sc);
16091 bxe_add_sysctls(sc);
16097 * Device detach function.
16099 * Stops the controller, resets the controller, and releases resources.
16102 * 0 = Success, >0 = Failure
16105 bxe_detach(device_t dev)
16107 struct bxe_softc *sc;
16110 sc = device_get_softc(dev);
16112 BLOGD(sc, DBG_LOAD, "Starting detach...\n");
16115 if (ifp != NULL && ifp->if_vlantrunk != NULL) {
16116 BLOGE(sc, "Cannot detach while VLANs are in use.\n");
16122 /* stop the periodic callout */
16123 bxe_periodic_stop(sc);
16125 /* stop the chip taskqueue */
16126 atomic_store_rel_long(&sc->chip_tq_flags, CHIP_TQ_NONE);
16128 taskqueue_drain(sc->chip_tq, &sc->chip_tq_task);
16129 taskqueue_free(sc->chip_tq);
16130 sc->chip_tq = NULL;
16133 /* stop and reset the controller if it was open */
16134 if (sc->state != BXE_STATE_CLOSED) {
16136 bxe_nic_unload(sc, UNLOAD_CLOSE, TRUE);
16137 BXE_CORE_UNLOCK(sc);
16140 /* release the network interface */
16142 ether_ifdetach(ifp);
16144 ifmedia_removeall(&sc->ifmedia);
16146 /* XXX do the following based on driver state... */
16148 /* free the host hardware/software hsi structures */
16149 bxe_free_hsi_mem(sc);
16152 bxe_free_ilt_mem(sc);
16154 bxe_free_buf_rings(sc);
16156 /* release the interrupts */
16157 bxe_interrupt_free(sc);
16159 /* Release the mutexes*/
16160 bxe_destroy_fp_mutexs(sc);
16161 bxe_release_mutexes(sc);
16164 /* Release the PCIe BAR mapped memory */
16165 bxe_deallocate_bars(sc);
16167 /* Release the FreeBSD interface. */
16168 if (sc->ifnet != NULL) {
16169 if_free(sc->ifnet);
16172 pci_disable_busmaster(dev);
16178 * Device shutdown function.
16180 * Stops and resets the controller.
16186 bxe_shutdown(device_t dev)
16188 struct bxe_softc *sc;
16190 sc = device_get_softc(dev);
16192 BLOGD(sc, DBG_LOAD, "Starting shutdown...\n");
16194 /* stop the periodic callout */
16195 bxe_periodic_stop(sc);
16198 bxe_nic_unload(sc, UNLOAD_NORMAL, FALSE);
16199 BXE_CORE_UNLOCK(sc);
16205 bxe_igu_ack_sb(struct bxe_softc *sc,
16212 uint32_t igu_addr = sc->igu_base_addr;
16213 igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
16214 bxe_igu_ack_sb_gen(sc, igu_sb_id, segment, index, op, update, igu_addr);
16218 bxe_igu_clear_sb_gen(struct bxe_softc *sc,
16223 uint32_t data, ctl, cnt = 100;
16224 uint32_t igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
16225 uint32_t igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
16226 uint32_t igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
16227 uint32_t sb_bit = 1 << (idu_sb_id%32);
16228 uint32_t func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
16229 uint32_t addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
16231 /* Not supported in BC mode */
16232 if (CHIP_INT_MODE_IS_BC(sc)) {
16236 data = ((IGU_USE_REGISTER_cstorm_type_0_sb_cleanup <<
16237 IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
16238 IGU_REGULAR_CLEANUP_SET |
16239 IGU_REGULAR_BCLEANUP);
16241 ctl = ((addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT) |
16242 (func_encode << IGU_CTRL_REG_FID_SHIFT) |
16243 (IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT));
16245 BLOGD(sc, DBG_LOAD, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
16246 data, igu_addr_data);
16247 REG_WR(sc, igu_addr_data, data);
16249 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle, 0, 0,
16250 BUS_SPACE_BARRIER_WRITE);
16253 BLOGD(sc, DBG_LOAD, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
16254 ctl, igu_addr_ctl);
16255 REG_WR(sc, igu_addr_ctl, ctl);
16257 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle, 0, 0,
16258 BUS_SPACE_BARRIER_WRITE);
16261 /* wait for clean up to finish */
16262 while (!(REG_RD(sc, igu_addr_ack) & sb_bit) && --cnt) {
16266 if (!(REG_RD(sc, igu_addr_ack) & sb_bit)) {
16267 BLOGD(sc, DBG_LOAD,
16268 "Unable to finish IGU cleanup: "
16269 "idu_sb_id %d offset %d bit %d (cnt %d)\n",
16270 idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
16275 bxe_igu_clear_sb(struct bxe_softc *sc,
16278 bxe_igu_clear_sb_gen(sc, SC_FUNC(sc), idu_sb_id, TRUE /*PF*/);
16287 /*******************/
16288 /* ECORE CALLBACKS */
16289 /*******************/
16292 bxe_reset_common(struct bxe_softc *sc)
16294 uint32_t val = 0x1400;
16297 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR), 0xd3ffff7f);
16299 if (CHIP_IS_E3(sc)) {
16300 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
16301 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
16304 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR), val);
16308 bxe_common_init_phy(struct bxe_softc *sc)
16310 uint32_t shmem_base[2];
16311 uint32_t shmem2_base[2];
16313 /* Avoid common init in case MFW supports LFA */
16314 if (SHMEM2_RD(sc, size) >
16315 (uint32_t)offsetof(struct shmem2_region,
16316 lfa_host_addr[SC_PORT(sc)])) {
16320 shmem_base[0] = sc->devinfo.shmem_base;
16321 shmem2_base[0] = sc->devinfo.shmem2_base;
16323 if (!CHIP_IS_E1x(sc)) {
16324 shmem_base[1] = SHMEM2_RD(sc, other_shmem_base_addr);
16325 shmem2_base[1] = SHMEM2_RD(sc, other_shmem2_base_addr);
16328 bxe_acquire_phy_lock(sc);
16329 elink_common_init_phy(sc, shmem_base, shmem2_base,
16330 sc->devinfo.chip_id, 0);
16331 bxe_release_phy_lock(sc);
16335 bxe_pf_disable(struct bxe_softc *sc)
16337 uint32_t val = REG_RD(sc, IGU_REG_PF_CONFIGURATION);
16339 val &= ~IGU_PF_CONF_FUNC_EN;
16341 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
16342 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
16343 REG_WR(sc, CFC_REG_WEAK_ENABLE_PF, 0);
16347 bxe_init_pxp(struct bxe_softc *sc)
16350 int r_order, w_order;
16352 devctl = bxe_pcie_capability_read(sc, PCIR_EXPRESS_DEVICE_CTL, 2);
16354 BLOGD(sc, DBG_LOAD, "read 0x%08x from devctl\n", devctl);
16356 w_order = ((devctl & PCIM_EXP_CTL_MAX_PAYLOAD) >> 5);
16358 if (sc->mrrs == -1) {
16359 r_order = ((devctl & PCIM_EXP_CTL_MAX_READ_REQUEST) >> 12);
16361 BLOGD(sc, DBG_LOAD, "forcing read order to %d\n", sc->mrrs);
16362 r_order = sc->mrrs;
16365 ecore_init_pxp_arb(sc, r_order, w_order);
16369 bxe_get_pretend_reg(struct bxe_softc *sc)
16371 uint32_t base = PXP2_REG_PGL_PRETEND_FUNC_F0;
16372 uint32_t stride = (PXP2_REG_PGL_PRETEND_FUNC_F1 - base);
16373 return (base + (SC_ABS_FUNC(sc)) * stride);
16377 * Called only on E1H or E2.
16378 * When pretending to be PF, the pretend value is the function number 0..7.
16379 * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
16383 bxe_pretend_func(struct bxe_softc *sc,
16384 uint16_t pretend_func_val)
16386 uint32_t pretend_reg;
16388 if (CHIP_IS_E1H(sc) && (pretend_func_val > E1H_FUNC_MAX)) {
16392 /* get my own pretend register */
16393 pretend_reg = bxe_get_pretend_reg(sc);
16394 REG_WR(sc, pretend_reg, pretend_func_val);
16395 REG_RD(sc, pretend_reg);
16400 bxe_iov_init_dmae(struct bxe_softc *sc)
16406 bxe_iov_init_dq(struct bxe_softc *sc)
16411 /* send a NIG loopback debug packet */
16413 bxe_lb_pckt(struct bxe_softc *sc)
16415 uint32_t wb_write[3];
16417 /* Ethernet source and destination addresses */
16418 wb_write[0] = 0x55555555;
16419 wb_write[1] = 0x55555555;
16420 wb_write[2] = 0x20; /* SOP */
16421 REG_WR_DMAE(sc, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
16423 /* NON-IP protocol */
16424 wb_write[0] = 0x09000000;
16425 wb_write[1] = 0x55555555;
16426 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
16427 REG_WR_DMAE(sc, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
16431 * Some of the internal memories are not directly readable from the driver.
16432 * To test them we send debug packets.
16435 bxe_int_mem_test(struct bxe_softc *sc)
16441 if (CHIP_REV_IS_FPGA(sc)) {
16443 } else if (CHIP_REV_IS_EMUL(sc)) {
16449 /* disable inputs of parser neighbor blocks */
16450 REG_WR(sc, TSDM_REG_ENABLE_IN1, 0x0);
16451 REG_WR(sc, TCM_REG_PRS_IFEN, 0x0);
16452 REG_WR(sc, CFC_REG_DEBUG0, 0x1);
16453 REG_WR(sc, NIG_REG_PRS_REQ_IN_EN, 0x0);
16455 /* write 0 to parser credits for CFC search request */
16456 REG_WR(sc, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
16458 /* send Ethernet packet */
16461 /* TODO do i reset NIG statistic? */
16462 /* Wait until NIG register shows 1 packet of size 0x10 */
16463 count = 1000 * factor;
16465 bxe_read_dmae(sc, NIG_REG_STAT2_BRB_OCTET, 2);
16466 val = *BXE_SP(sc, wb_data[0]);
16476 BLOGE(sc, "NIG timeout val=0x%x\n", val);
16480 /* wait until PRS register shows 1 packet */
16481 count = (1000 * factor);
16483 val = REG_RD(sc, PRS_REG_NUM_OF_PACKETS);
16493 BLOGE(sc, "PRS timeout val=0x%x\n", val);
16497 /* Reset and init BRB, PRS */
16498 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
16500 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
16502 ecore_init_block(sc, BLOCK_BRB1, PHASE_COMMON);
16503 ecore_init_block(sc, BLOCK_PRS, PHASE_COMMON);
16505 /* Disable inputs of parser neighbor blocks */
16506 REG_WR(sc, TSDM_REG_ENABLE_IN1, 0x0);
16507 REG_WR(sc, TCM_REG_PRS_IFEN, 0x0);
16508 REG_WR(sc, CFC_REG_DEBUG0, 0x1);
16509 REG_WR(sc, NIG_REG_PRS_REQ_IN_EN, 0x0);
16511 /* Write 0 to parser credits for CFC search request */
16512 REG_WR(sc, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
16514 /* send 10 Ethernet packets */
16515 for (i = 0; i < 10; i++) {
16519 /* Wait until NIG register shows 10+1 packets of size 11*0x10 = 0xb0 */
16520 count = (1000 * factor);
16522 bxe_read_dmae(sc, NIG_REG_STAT2_BRB_OCTET, 2);
16523 val = *BXE_SP(sc, wb_data[0]);
16533 BLOGE(sc, "NIG timeout val=0x%x\n", val);
16537 /* Wait until PRS register shows 2 packets */
16538 val = REG_RD(sc, PRS_REG_NUM_OF_PACKETS);
16540 BLOGE(sc, "PRS timeout val=0x%x\n", val);
16543 /* Write 1 to parser credits for CFC search request */
16544 REG_WR(sc, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
16546 /* Wait until PRS register shows 3 packets */
16547 DELAY(10000 * factor);
16549 /* Wait until NIG register shows 1 packet of size 0x10 */
16550 val = REG_RD(sc, PRS_REG_NUM_OF_PACKETS);
16552 BLOGE(sc, "PRS timeout val=0x%x\n", val);
16555 /* clear NIG EOP FIFO */
16556 for (i = 0; i < 11; i++) {
16557 REG_RD(sc, NIG_REG_INGRESS_EOP_LB_FIFO);
16560 val = REG_RD(sc, NIG_REG_INGRESS_EOP_LB_EMPTY);
16562 BLOGE(sc, "clear of NIG failed val=0x%x\n", val);
16566 /* Reset and init BRB, PRS, NIG */
16567 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
16569 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
16571 ecore_init_block(sc, BLOCK_BRB1, PHASE_COMMON);
16572 ecore_init_block(sc, BLOCK_PRS, PHASE_COMMON);
16573 if (!CNIC_SUPPORT(sc)) {
16575 REG_WR(sc, PRS_REG_NIC_MODE, 1);
16578 /* Enable inputs of parser neighbor blocks */
16579 REG_WR(sc, TSDM_REG_ENABLE_IN1, 0x7fffffff);
16580 REG_WR(sc, TCM_REG_PRS_IFEN, 0x1);
16581 REG_WR(sc, CFC_REG_DEBUG0, 0x0);
16582 REG_WR(sc, NIG_REG_PRS_REQ_IN_EN, 0x1);
16588 bxe_setup_fan_failure_detection(struct bxe_softc *sc)
16595 val = (SHMEM_RD(sc, dev_info.shared_hw_config.config2) &
16596 SHARED_HW_CFG_FAN_FAILURE_MASK);
16598 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED) {
16602 * The fan failure mechanism is usually related to the PHY type since
16603 * the power consumption of the board is affected by the PHY. Currently,
16604 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
16606 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE) {
16607 for (port = PORT_0; port < PORT_MAX; port++) {
16608 is_required |= elink_fan_failure_det_req(sc,
16609 sc->devinfo.shmem_base,
16610 sc->devinfo.shmem2_base,
16615 BLOGD(sc, DBG_LOAD, "fan detection setting: %d\n", is_required);
16617 if (is_required == 0) {
16621 /* Fan failure is indicated by SPIO 5 */
16622 bxe_set_spio(sc, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
16624 /* set to active low mode */
16625 val = REG_RD(sc, MISC_REG_SPIO_INT);
16626 val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
16627 REG_WR(sc, MISC_REG_SPIO_INT, val);
16629 /* enable interrupt to signal the IGU */
16630 val = REG_RD(sc, MISC_REG_SPIO_EVENT_EN);
16631 val |= MISC_SPIO_SPIO5;
16632 REG_WR(sc, MISC_REG_SPIO_EVENT_EN, val);
16636 bxe_enable_blocks_attention(struct bxe_softc *sc)
16640 REG_WR(sc, PXP_REG_PXP_INT_MASK_0, 0);
16641 if (!CHIP_IS_E1x(sc)) {
16642 REG_WR(sc, PXP_REG_PXP_INT_MASK_1, 0x40);
16644 REG_WR(sc, PXP_REG_PXP_INT_MASK_1, 0);
16646 REG_WR(sc, DORQ_REG_DORQ_INT_MASK, 0);
16647 REG_WR(sc, CFC_REG_CFC_INT_MASK, 0);
16649 * mask read length error interrupts in brb for parser
16650 * (parsing unit and 'checksum and crc' unit)
16651 * these errors are legal (PU reads fixed length and CAC can cause
16652 * read length error on truncated packets)
16654 REG_WR(sc, BRB1_REG_BRB1_INT_MASK, 0xFC00);
16655 REG_WR(sc, QM_REG_QM_INT_MASK, 0);
16656 REG_WR(sc, TM_REG_TM_INT_MASK, 0);
16657 REG_WR(sc, XSDM_REG_XSDM_INT_MASK_0, 0);
16658 REG_WR(sc, XSDM_REG_XSDM_INT_MASK_1, 0);
16659 REG_WR(sc, XCM_REG_XCM_INT_MASK, 0);
16660 /* REG_WR(sc, XSEM_REG_XSEM_INT_MASK_0, 0); */
16661 /* REG_WR(sc, XSEM_REG_XSEM_INT_MASK_1, 0); */
16662 REG_WR(sc, USDM_REG_USDM_INT_MASK_0, 0);
16663 REG_WR(sc, USDM_REG_USDM_INT_MASK_1, 0);
16664 REG_WR(sc, UCM_REG_UCM_INT_MASK, 0);
16665 /* REG_WR(sc, USEM_REG_USEM_INT_MASK_0, 0); */
16666 /* REG_WR(sc, USEM_REG_USEM_INT_MASK_1, 0); */
16667 REG_WR(sc, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
16668 REG_WR(sc, CSDM_REG_CSDM_INT_MASK_0, 0);
16669 REG_WR(sc, CSDM_REG_CSDM_INT_MASK_1, 0);
16670 REG_WR(sc, CCM_REG_CCM_INT_MASK, 0);
16671 /* REG_WR(sc, CSEM_REG_CSEM_INT_MASK_0, 0); */
16672 /* REG_WR(sc, CSEM_REG_CSEM_INT_MASK_1, 0); */
16674 val = (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
16675 PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
16676 PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN);
16677 if (!CHIP_IS_E1x(sc)) {
16678 val |= (PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
16679 PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED);
16681 REG_WR(sc, PXP2_REG_PXP2_INT_MASK_0, val);
16683 REG_WR(sc, TSDM_REG_TSDM_INT_MASK_0, 0);
16684 REG_WR(sc, TSDM_REG_TSDM_INT_MASK_1, 0);
16685 REG_WR(sc, TCM_REG_TCM_INT_MASK, 0);
16686 /* REG_WR(sc, TSEM_REG_TSEM_INT_MASK_0, 0); */
16688 if (!CHIP_IS_E1x(sc)) {
16689 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
16690 REG_WR(sc, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
16693 REG_WR(sc, CDU_REG_CDU_INT_MASK, 0);
16694 REG_WR(sc, DMAE_REG_DMAE_INT_MASK, 0);
16695 /* REG_WR(sc, MISC_REG_MISC_INT_MASK, 0); */
16696 REG_WR(sc, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
16700 * bxe_init_hw_common - initialize the HW at the COMMON phase.
16702 * @sc: driver handle
16705 bxe_init_hw_common(struct bxe_softc *sc)
16707 uint8_t abs_func_id;
16710 BLOGD(sc, DBG_LOAD, "starting common init for func %d\n",
16714 * take the RESET lock to protect undi_unload flow from accessing
16715 * registers while we are resetting the chip
16717 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
16719 bxe_reset_common(sc);
16721 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET), 0xffffffff);
16724 if (CHIP_IS_E3(sc)) {
16725 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
16726 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
16729 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET), val);
16731 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
16733 ecore_init_block(sc, BLOCK_MISC, PHASE_COMMON);
16734 BLOGD(sc, DBG_LOAD, "after misc block init\n");
16736 if (!CHIP_IS_E1x(sc)) {
16738 * 4-port mode or 2-port mode we need to turn off master-enable for
16739 * everyone. After that we turn it back on for self. So, we disregard
16740 * multi-function, and always disable all functions on the given path,
16741 * this means 0,2,4,6 for path 0 and 1,3,5,7 for path 1
16743 for (abs_func_id = SC_PATH(sc);
16744 abs_func_id < (E2_FUNC_MAX * 2);
16745 abs_func_id += 2) {
16746 if (abs_func_id == SC_ABS_FUNC(sc)) {
16747 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
16751 bxe_pretend_func(sc, abs_func_id);
16753 /* clear pf enable */
16754 bxe_pf_disable(sc);
16756 bxe_pretend_func(sc, SC_ABS_FUNC(sc));
16760 BLOGD(sc, DBG_LOAD, "after pf disable\n");
16762 ecore_init_block(sc, BLOCK_PXP, PHASE_COMMON);
16764 if (CHIP_IS_E1(sc)) {
16766 * enable HW interrupt from PXP on USDM overflow
16767 * bit 16 on INT_MASK_0
16769 REG_WR(sc, PXP_REG_PXP_INT_MASK_0, 0);
16772 ecore_init_block(sc, BLOCK_PXP2, PHASE_COMMON);
16775 #ifdef __BIG_ENDIAN
16776 REG_WR(sc, PXP2_REG_RQ_QM_ENDIAN_M, 1);
16777 REG_WR(sc, PXP2_REG_RQ_TM_ENDIAN_M, 1);
16778 REG_WR(sc, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
16779 REG_WR(sc, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
16780 REG_WR(sc, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
16781 /* make sure this value is 0 */
16782 REG_WR(sc, PXP2_REG_RQ_HC_ENDIAN_M, 0);
16784 //REG_WR(sc, PXP2_REG_RD_PBF_SWAP_MODE, 1);
16785 REG_WR(sc, PXP2_REG_RD_QM_SWAP_MODE, 1);
16786 REG_WR(sc, PXP2_REG_RD_TM_SWAP_MODE, 1);
16787 REG_WR(sc, PXP2_REG_RD_SRC_SWAP_MODE, 1);
16788 REG_WR(sc, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
16791 ecore_ilt_init_page_size(sc, INITOP_SET);
16793 if (CHIP_REV_IS_FPGA(sc) && CHIP_IS_E1H(sc)) {
16794 REG_WR(sc, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
16797 /* let the HW do it's magic... */
16800 /* finish PXP init */
16801 val = REG_RD(sc, PXP2_REG_RQ_CFG_DONE);
16803 BLOGE(sc, "PXP2 CFG failed PXP2_REG_RQ_CFG_DONE val = 0x%x\n",
16807 val = REG_RD(sc, PXP2_REG_RD_INIT_DONE);
16809 BLOGE(sc, "PXP2 RD_INIT failed val = 0x%x\n", val);
16813 BLOGD(sc, DBG_LOAD, "after pxp init\n");
16816 * Timer bug workaround for E2 only. We need to set the entire ILT to have
16817 * entries with value "0" and valid bit on. This needs to be done by the
16818 * first PF that is loaded in a path (i.e. common phase)
16820 if (!CHIP_IS_E1x(sc)) {
16822 * In E2 there is a bug in the timers block that can cause function 6 / 7
16823 * (i.e. vnic3) to start even if it is marked as "scan-off".
16824 * This occurs when a different function (func2,3) is being marked
16825 * as "scan-off". Real-life scenario for example: if a driver is being
16826 * load-unloaded while func6,7 are down. This will cause the timer to access
16827 * the ilt, translate to a logical address and send a request to read/write.
16828 * Since the ilt for the function that is down is not valid, this will cause
16829 * a translation error which is unrecoverable.
16830 * The Workaround is intended to make sure that when this happens nothing
16831 * fatal will occur. The workaround:
16832 * 1. First PF driver which loads on a path will:
16833 * a. After taking the chip out of reset, by using pretend,
16834 * it will write "0" to the following registers of
16836 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
16837 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
16838 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
16839 * And for itself it will write '1' to
16840 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
16841 * dmae-operations (writing to pram for example.)
16842 * note: can be done for only function 6,7 but cleaner this
16844 * b. Write zero+valid to the entire ILT.
16845 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
16846 * VNIC3 (of that port). The range allocated will be the
16847 * entire ILT. This is needed to prevent ILT range error.
16848 * 2. Any PF driver load flow:
16849 * a. ILT update with the physical addresses of the allocated
16851 * b. Wait 20msec. - note that this timeout is needed to make
16852 * sure there are no requests in one of the PXP internal
16853 * queues with "old" ILT addresses.
16854 * c. PF enable in the PGLC.
16855 * d. Clear the was_error of the PF in the PGLC. (could have
16856 * occurred while driver was down)
16857 * e. PF enable in the CFC (WEAK + STRONG)
16858 * f. Timers scan enable
16859 * 3. PF driver unload flow:
16860 * a. Clear the Timers scan_en.
16861 * b. Polling for scan_on=0 for that PF.
16862 * c. Clear the PF enable bit in the PXP.
16863 * d. Clear the PF enable in the CFC (WEAK + STRONG)
16864 * e. Write zero+valid to all ILT entries (The valid bit must
16866 * f. If this is VNIC 3 of a port then also init
16867 * first_timers_ilt_entry to zero and last_timers_ilt_entry
16868 * to the last enrty in the ILT.
16871 * Currently the PF error in the PGLC is non recoverable.
16872 * In the future the there will be a recovery routine for this error.
16873 * Currently attention is masked.
16874 * Having an MCP lock on the load/unload process does not guarantee that
16875 * there is no Timer disable during Func6/7 enable. This is because the
16876 * Timers scan is currently being cleared by the MCP on FLR.
16877 * Step 2.d can be done only for PF6/7 and the driver can also check if
16878 * there is error before clearing it. But the flow above is simpler and
16880 * All ILT entries are written by zero+valid and not just PF6/7
16881 * ILT entries since in the future the ILT entries allocation for
16882 * PF-s might be dynamic.
16884 struct ilt_client_info ilt_cli;
16885 struct ecore_ilt ilt;
16887 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
16888 memset(&ilt, 0, sizeof(struct ecore_ilt));
16890 /* initialize dummy TM client */
16892 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
16893 ilt_cli.client_num = ILT_CLIENT_TM;
16896 * Step 1: set zeroes to all ilt page entries with valid bit on
16897 * Step 2: set the timers first/last ilt entry to point
16898 * to the entire range to prevent ILT range error for 3rd/4th
16899 * vnic (this code assumes existence of the vnic)
16901 * both steps performed by call to ecore_ilt_client_init_op()
16902 * with dummy TM client
16904 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
16905 * and his brother are split registers
16908 bxe_pretend_func(sc, (SC_PATH(sc) + 6));
16909 ecore_ilt_client_init_op_ilt(sc, &ilt, &ilt_cli, INITOP_CLEAR);
16910 bxe_pretend_func(sc, SC_ABS_FUNC(sc));
16912 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN, BXE_PXP_DRAM_ALIGN);
16913 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN_RD, BXE_PXP_DRAM_ALIGN);
16914 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
16917 REG_WR(sc, PXP2_REG_RQ_DISABLE_INPUTS, 0);
16918 REG_WR(sc, PXP2_REG_RD_DISABLE_INPUTS, 0);
16920 if (!CHIP_IS_E1x(sc)) {
16921 int factor = CHIP_REV_IS_EMUL(sc) ? 1000 :
16922 (CHIP_REV_IS_FPGA(sc) ? 400 : 0);
16924 ecore_init_block(sc, BLOCK_PGLUE_B, PHASE_COMMON);
16925 ecore_init_block(sc, BLOCK_ATC, PHASE_COMMON);
16927 /* let the HW do it's magic... */
16930 val = REG_RD(sc, ATC_REG_ATC_INIT_DONE);
16931 } while (factor-- && (val != 1));
16934 BLOGE(sc, "ATC_INIT failed val = 0x%x\n", val);
16939 BLOGD(sc, DBG_LOAD, "after pglue and atc init\n");
16941 ecore_init_block(sc, BLOCK_DMAE, PHASE_COMMON);
16943 bxe_iov_init_dmae(sc);
16945 /* clean the DMAE memory */
16946 sc->dmae_ready = 1;
16947 ecore_init_fill(sc, TSEM_REG_PRAM, 0, 8, 1);
16949 ecore_init_block(sc, BLOCK_TCM, PHASE_COMMON);
16951 ecore_init_block(sc, BLOCK_UCM, PHASE_COMMON);
16953 ecore_init_block(sc, BLOCK_CCM, PHASE_COMMON);
16955 ecore_init_block(sc, BLOCK_XCM, PHASE_COMMON);
16957 bxe_read_dmae(sc, XSEM_REG_PASSIVE_BUFFER, 3);
16958 bxe_read_dmae(sc, CSEM_REG_PASSIVE_BUFFER, 3);
16959 bxe_read_dmae(sc, TSEM_REG_PASSIVE_BUFFER, 3);
16960 bxe_read_dmae(sc, USEM_REG_PASSIVE_BUFFER, 3);
16962 ecore_init_block(sc, BLOCK_QM, PHASE_COMMON);
16964 /* QM queues pointers table */
16965 ecore_qm_init_ptr_table(sc, sc->qm_cid_count, INITOP_SET);
16967 /* soft reset pulse */
16968 REG_WR(sc, QM_REG_SOFT_RESET, 1);
16969 REG_WR(sc, QM_REG_SOFT_RESET, 0);
16971 if (CNIC_SUPPORT(sc))
16972 ecore_init_block(sc, BLOCK_TM, PHASE_COMMON);
16974 ecore_init_block(sc, BLOCK_DORQ, PHASE_COMMON);
16975 REG_WR(sc, DORQ_REG_DPM_CID_OFST, BXE_DB_SHIFT);
16976 if (!CHIP_REV_IS_SLOW(sc)) {
16977 /* enable hw interrupt from doorbell Q */
16978 REG_WR(sc, DORQ_REG_DORQ_INT_MASK, 0);
16981 ecore_init_block(sc, BLOCK_BRB1, PHASE_COMMON);
16983 ecore_init_block(sc, BLOCK_PRS, PHASE_COMMON);
16984 REG_WR(sc, PRS_REG_A_PRSU_20, 0xf);
16986 if (!CHIP_IS_E1(sc)) {
16987 REG_WR(sc, PRS_REG_E1HOV_MODE, sc->devinfo.mf_info.path_has_ovlan);
16990 if (!CHIP_IS_E1x(sc) && !CHIP_IS_E3B0(sc)) {
16991 if (IS_MF_AFEX(sc)) {
16993 * configure that AFEX and VLAN headers must be
16994 * received in AFEX mode
16996 REG_WR(sc, PRS_REG_HDRS_AFTER_BASIC, 0xE);
16997 REG_WR(sc, PRS_REG_MUST_HAVE_HDRS, 0xA);
16998 REG_WR(sc, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
16999 REG_WR(sc, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
17000 REG_WR(sc, PRS_REG_TAG_LEN_0, 0x4);
17003 * Bit-map indicating which L2 hdrs may appear
17004 * after the basic Ethernet header
17006 REG_WR(sc, PRS_REG_HDRS_AFTER_BASIC,
17007 sc->devinfo.mf_info.path_has_ovlan ? 7 : 6);
17011 ecore_init_block(sc, BLOCK_TSDM, PHASE_COMMON);
17012 ecore_init_block(sc, BLOCK_CSDM, PHASE_COMMON);
17013 ecore_init_block(sc, BLOCK_USDM, PHASE_COMMON);
17014 ecore_init_block(sc, BLOCK_XSDM, PHASE_COMMON);
17016 if (!CHIP_IS_E1x(sc)) {
17017 /* reset VFC memories */
17018 REG_WR(sc, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
17019 VFC_MEMORIES_RST_REG_CAM_RST |
17020 VFC_MEMORIES_RST_REG_RAM_RST);
17021 REG_WR(sc, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
17022 VFC_MEMORIES_RST_REG_CAM_RST |
17023 VFC_MEMORIES_RST_REG_RAM_RST);
17028 ecore_init_block(sc, BLOCK_TSEM, PHASE_COMMON);
17029 ecore_init_block(sc, BLOCK_USEM, PHASE_COMMON);
17030 ecore_init_block(sc, BLOCK_CSEM, PHASE_COMMON);
17031 ecore_init_block(sc, BLOCK_XSEM, PHASE_COMMON);
17033 /* sync semi rtc */
17034 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
17036 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
17039 ecore_init_block(sc, BLOCK_UPB, PHASE_COMMON);
17040 ecore_init_block(sc, BLOCK_XPB, PHASE_COMMON);
17041 ecore_init_block(sc, BLOCK_PBF, PHASE_COMMON);
17043 if (!CHIP_IS_E1x(sc)) {
17044 if (IS_MF_AFEX(sc)) {
17046 * configure that AFEX and VLAN headers must be
17047 * sent in AFEX mode
17049 REG_WR(sc, PBF_REG_HDRS_AFTER_BASIC, 0xE);
17050 REG_WR(sc, PBF_REG_MUST_HAVE_HDRS, 0xA);
17051 REG_WR(sc, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
17052 REG_WR(sc, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
17053 REG_WR(sc, PBF_REG_TAG_LEN_0, 0x4);
17055 REG_WR(sc, PBF_REG_HDRS_AFTER_BASIC,
17056 sc->devinfo.mf_info.path_has_ovlan ? 7 : 6);
17060 REG_WR(sc, SRC_REG_SOFT_RST, 1);
17062 ecore_init_block(sc, BLOCK_SRC, PHASE_COMMON);
17064 if (CNIC_SUPPORT(sc)) {
17065 REG_WR(sc, SRC_REG_KEYSEARCH_0, 0x63285672);
17066 REG_WR(sc, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
17067 REG_WR(sc, SRC_REG_KEYSEARCH_2, 0x223aef9b);
17068 REG_WR(sc, SRC_REG_KEYSEARCH_3, 0x26001e3a);
17069 REG_WR(sc, SRC_REG_KEYSEARCH_4, 0x7ae91116);
17070 REG_WR(sc, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
17071 REG_WR(sc, SRC_REG_KEYSEARCH_6, 0x298d8adf);
17072 REG_WR(sc, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
17073 REG_WR(sc, SRC_REG_KEYSEARCH_8, 0x1830f82f);
17074 REG_WR(sc, SRC_REG_KEYSEARCH_9, 0x01e46be7);
17076 REG_WR(sc, SRC_REG_SOFT_RST, 0);
17078 if (sizeof(union cdu_context) != 1024) {
17079 /* we currently assume that a context is 1024 bytes */
17080 BLOGE(sc, "please adjust the size of cdu_context(%ld)\n",
17081 (long)sizeof(union cdu_context));
17084 ecore_init_block(sc, BLOCK_CDU, PHASE_COMMON);
17085 val = (4 << 24) + (0 << 12) + 1024;
17086 REG_WR(sc, CDU_REG_CDU_GLOBAL_PARAMS, val);
17088 ecore_init_block(sc, BLOCK_CFC, PHASE_COMMON);
17090 REG_WR(sc, CFC_REG_INIT_REG, 0x7FF);
17091 /* enable context validation interrupt from CFC */
17092 REG_WR(sc, CFC_REG_CFC_INT_MASK, 0);
17094 /* set the thresholds to prevent CFC/CDU race */
17095 REG_WR(sc, CFC_REG_DEBUG0, 0x20020000);
17096 ecore_init_block(sc, BLOCK_HC, PHASE_COMMON);
17098 if (!CHIP_IS_E1x(sc) && BXE_NOMCP(sc)) {
17099 REG_WR(sc, IGU_REG_RESET_MEMORIES, 0x36);
17102 ecore_init_block(sc, BLOCK_IGU, PHASE_COMMON);
17103 ecore_init_block(sc, BLOCK_MISC_AEU, PHASE_COMMON);
17105 /* Reset PCIE errors for debug */
17106 REG_WR(sc, 0x2814, 0xffffffff);
17107 REG_WR(sc, 0x3820, 0xffffffff);
17109 if (!CHIP_IS_E1x(sc)) {
17110 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
17111 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
17112 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
17113 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
17114 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
17115 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
17116 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
17117 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
17118 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
17119 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
17120 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
17123 ecore_init_block(sc, BLOCK_NIG, PHASE_COMMON);
17125 if (!CHIP_IS_E1(sc)) {
17126 /* in E3 this done in per-port section */
17127 if (!CHIP_IS_E3(sc))
17128 REG_WR(sc, NIG_REG_LLH_MF_MODE, IS_MF(sc));
17131 if (CHIP_IS_E1H(sc)) {
17132 /* not applicable for E2 (and above ...) */
17133 REG_WR(sc, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(sc));
17136 if (CHIP_REV_IS_SLOW(sc)) {
17140 /* finish CFC init */
17141 val = reg_poll(sc, CFC_REG_LL_INIT_DONE, 1, 100, 10);
17143 BLOGE(sc, "CFC LL_INIT failed val=0x%x\n", val);
17146 val = reg_poll(sc, CFC_REG_AC_INIT_DONE, 1, 100, 10);
17148 BLOGE(sc, "CFC AC_INIT failed val=0x%x\n", val);
17151 val = reg_poll(sc, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
17153 BLOGE(sc, "CFC CAM_INIT failed val=0x%x\n", val);
17156 REG_WR(sc, CFC_REG_DEBUG0, 0);
17158 if (CHIP_IS_E1(sc)) {
17159 /* read NIG statistic to see if this is our first up since powerup */
17160 bxe_read_dmae(sc, NIG_REG_STAT2_BRB_OCTET, 2);
17161 val = *BXE_SP(sc, wb_data[0]);
17163 /* do internal memory self test */
17164 if ((val == 0) && bxe_int_mem_test(sc)) {
17165 BLOGE(sc, "internal mem self test failed val=0x%x\n", val);
17170 bxe_setup_fan_failure_detection(sc);
17172 /* clear PXP2 attentions */
17173 REG_RD(sc, PXP2_REG_PXP2_INT_STS_CLR_0);
17175 bxe_enable_blocks_attention(sc);
17177 if (!CHIP_REV_IS_SLOW(sc)) {
17178 ecore_enable_blocks_parity(sc);
17181 if (!BXE_NOMCP(sc)) {
17182 if (CHIP_IS_E1x(sc)) {
17183 bxe_common_init_phy(sc);
17191 * bxe_init_hw_common_chip - init HW at the COMMON_CHIP phase.
17193 * @sc: driver handle
17196 bxe_init_hw_common_chip(struct bxe_softc *sc)
17198 int rc = bxe_init_hw_common(sc);
17201 BLOGE(sc, "bxe_init_hw_common failed rc=%d\n", rc);
17205 /* In E2 2-PORT mode, same ext phy is used for the two paths */
17206 if (!BXE_NOMCP(sc)) {
17207 bxe_common_init_phy(sc);
17214 bxe_init_hw_port(struct bxe_softc *sc)
17216 int port = SC_PORT(sc);
17217 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
17218 uint32_t low, high;
17221 BLOGD(sc, DBG_LOAD, "starting port init for port %d\n", port);
17223 REG_WR(sc, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
17225 ecore_init_block(sc, BLOCK_MISC, init_phase);
17226 ecore_init_block(sc, BLOCK_PXP, init_phase);
17227 ecore_init_block(sc, BLOCK_PXP2, init_phase);
17230 * Timers bug workaround: disables the pf_master bit in pglue at
17231 * common phase, we need to enable it here before any dmae access are
17232 * attempted. Therefore we manually added the enable-master to the
17233 * port phase (it also happens in the function phase)
17235 if (!CHIP_IS_E1x(sc)) {
17236 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
17239 ecore_init_block(sc, BLOCK_ATC, init_phase);
17240 ecore_init_block(sc, BLOCK_DMAE, init_phase);
17241 ecore_init_block(sc, BLOCK_PGLUE_B, init_phase);
17242 ecore_init_block(sc, BLOCK_QM, init_phase);
17244 ecore_init_block(sc, BLOCK_TCM, init_phase);
17245 ecore_init_block(sc, BLOCK_UCM, init_phase);
17246 ecore_init_block(sc, BLOCK_CCM, init_phase);
17247 ecore_init_block(sc, BLOCK_XCM, init_phase);
17249 /* QM cid (connection) count */
17250 ecore_qm_init_cid_count(sc, sc->qm_cid_count, INITOP_SET);
17252 if (CNIC_SUPPORT(sc)) {
17253 ecore_init_block(sc, BLOCK_TM, init_phase);
17254 REG_WR(sc, TM_REG_LIN0_SCAN_TIME + port*4, 20);
17255 REG_WR(sc, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
17258 ecore_init_block(sc, BLOCK_DORQ, init_phase);
17260 ecore_init_block(sc, BLOCK_BRB1, init_phase);
17262 if (CHIP_IS_E1(sc) || CHIP_IS_E1H(sc)) {
17264 low = (BXE_ONE_PORT(sc) ? 160 : 246);
17265 } else if (sc->mtu > 4096) {
17266 if (BXE_ONE_PORT(sc)) {
17270 /* (24*1024 + val*4)/256 */
17271 low = (96 + (val / 64) + ((val % 64) ? 1 : 0));
17274 low = (BXE_ONE_PORT(sc) ? 80 : 160);
17276 high = (low + 56); /* 14*1024/256 */
17277 REG_WR(sc, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
17278 REG_WR(sc, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
17281 if (CHIP_IS_MODE_4_PORT(sc)) {
17282 REG_WR(sc, SC_PORT(sc) ?
17283 BRB1_REG_MAC_GUARANTIED_1 :
17284 BRB1_REG_MAC_GUARANTIED_0, 40);
17287 ecore_init_block(sc, BLOCK_PRS, init_phase);
17288 if (CHIP_IS_E3B0(sc)) {
17289 if (IS_MF_AFEX(sc)) {
17290 /* configure headers for AFEX mode */
17291 REG_WR(sc, SC_PORT(sc) ?
17292 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
17293 PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
17294 REG_WR(sc, SC_PORT(sc) ?
17295 PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
17296 PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
17297 REG_WR(sc, SC_PORT(sc) ?
17298 PRS_REG_MUST_HAVE_HDRS_PORT_1 :
17299 PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
17301 /* Ovlan exists only if we are in multi-function +
17302 * switch-dependent mode, in switch-independent there
17303 * is no ovlan headers
17305 REG_WR(sc, SC_PORT(sc) ?
17306 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
17307 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
17308 (sc->devinfo.mf_info.path_has_ovlan ? 7 : 6));
17312 ecore_init_block(sc, BLOCK_TSDM, init_phase);
17313 ecore_init_block(sc, BLOCK_CSDM, init_phase);
17314 ecore_init_block(sc, BLOCK_USDM, init_phase);
17315 ecore_init_block(sc, BLOCK_XSDM, init_phase);
17317 ecore_init_block(sc, BLOCK_TSEM, init_phase);
17318 ecore_init_block(sc, BLOCK_USEM, init_phase);
17319 ecore_init_block(sc, BLOCK_CSEM, init_phase);
17320 ecore_init_block(sc, BLOCK_XSEM, init_phase);
17322 ecore_init_block(sc, BLOCK_UPB, init_phase);
17323 ecore_init_block(sc, BLOCK_XPB, init_phase);
17325 ecore_init_block(sc, BLOCK_PBF, init_phase);
17327 if (CHIP_IS_E1x(sc)) {
17328 /* configure PBF to work without PAUSE mtu 9000 */
17329 REG_WR(sc, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
17331 /* update threshold */
17332 REG_WR(sc, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
17333 /* update init credit */
17334 REG_WR(sc, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
17336 /* probe changes */
17337 REG_WR(sc, PBF_REG_INIT_P0 + port*4, 1);
17339 REG_WR(sc, PBF_REG_INIT_P0 + port*4, 0);
17342 if (CNIC_SUPPORT(sc)) {
17343 ecore_init_block(sc, BLOCK_SRC, init_phase);
17346 ecore_init_block(sc, BLOCK_CDU, init_phase);
17347 ecore_init_block(sc, BLOCK_CFC, init_phase);
17349 if (CHIP_IS_E1(sc)) {
17350 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, 0);
17351 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, 0);
17353 ecore_init_block(sc, BLOCK_HC, init_phase);
17355 ecore_init_block(sc, BLOCK_IGU, init_phase);
17357 ecore_init_block(sc, BLOCK_MISC_AEU, init_phase);
17358 /* init aeu_mask_attn_func_0/1:
17359 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
17360 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
17361 * bits 4-7 are used for "per vn group attention" */
17362 val = IS_MF(sc) ? 0xF7 : 0x7;
17363 /* Enable DCBX attention for all but E1 */
17364 val |= CHIP_IS_E1(sc) ? 0 : 0x10;
17365 REG_WR(sc, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
17367 ecore_init_block(sc, BLOCK_NIG, init_phase);
17369 if (!CHIP_IS_E1x(sc)) {
17370 /* Bit-map indicating which L2 hdrs may appear after the
17371 * basic Ethernet header
17373 if (IS_MF_AFEX(sc)) {
17374 REG_WR(sc, SC_PORT(sc) ?
17375 NIG_REG_P1_HDRS_AFTER_BASIC :
17376 NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
17378 REG_WR(sc, SC_PORT(sc) ?
17379 NIG_REG_P1_HDRS_AFTER_BASIC :
17380 NIG_REG_P0_HDRS_AFTER_BASIC,
17381 IS_MF_SD(sc) ? 7 : 6);
17384 if (CHIP_IS_E3(sc)) {
17385 REG_WR(sc, SC_PORT(sc) ?
17386 NIG_REG_LLH1_MF_MODE :
17387 NIG_REG_LLH_MF_MODE, IS_MF(sc));
17390 if (!CHIP_IS_E3(sc)) {
17391 REG_WR(sc, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
17394 if (!CHIP_IS_E1(sc)) {
17395 /* 0x2 disable mf_ov, 0x1 enable */
17396 REG_WR(sc, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
17397 (IS_MF_SD(sc) ? 0x1 : 0x2));
17399 if (!CHIP_IS_E1x(sc)) {
17401 switch (sc->devinfo.mf_info.mf_mode) {
17402 case MULTI_FUNCTION_SD:
17405 case MULTI_FUNCTION_SI:
17406 case MULTI_FUNCTION_AFEX:
17411 REG_WR(sc, (SC_PORT(sc) ? NIG_REG_LLH1_CLS_TYPE :
17412 NIG_REG_LLH0_CLS_TYPE), val);
17414 REG_WR(sc, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
17415 REG_WR(sc, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
17416 REG_WR(sc, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
17419 /* If SPIO5 is set to generate interrupts, enable it for this port */
17420 val = REG_RD(sc, MISC_REG_SPIO_EVENT_EN);
17421 if (val & MISC_SPIO_SPIO5) {
17422 uint32_t reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
17423 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
17424 val = REG_RD(sc, reg_addr);
17425 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
17426 REG_WR(sc, reg_addr, val);
17433 bxe_flr_clnup_reg_poll(struct bxe_softc *sc,
17436 uint32_t poll_count)
17438 uint32_t cur_cnt = poll_count;
17441 while ((val = REG_RD(sc, reg)) != expected && cur_cnt--) {
17442 DELAY(FLR_WAIT_INTERVAL);
17449 bxe_flr_clnup_poll_hw_counter(struct bxe_softc *sc,
17454 uint32_t val = bxe_flr_clnup_reg_poll(sc, reg, 0, poll_cnt);
17457 BLOGE(sc, "%s usage count=%d\n", msg, val);
17464 /* Common routines with VF FLR cleanup */
17466 bxe_flr_clnup_poll_count(struct bxe_softc *sc)
17468 /* adjust polling timeout */
17469 if (CHIP_REV_IS_EMUL(sc)) {
17470 return (FLR_POLL_CNT * 2000);
17473 if (CHIP_REV_IS_FPGA(sc)) {
17474 return (FLR_POLL_CNT * 120);
17477 return (FLR_POLL_CNT);
17481 bxe_poll_hw_usage_counters(struct bxe_softc *sc,
17484 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
17485 if (bxe_flr_clnup_poll_hw_counter(sc,
17486 CFC_REG_NUM_LCIDS_INSIDE_PF,
17487 "CFC PF usage counter timed out",
17492 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
17493 if (bxe_flr_clnup_poll_hw_counter(sc,
17494 DORQ_REG_PF_USAGE_CNT,
17495 "DQ PF usage counter timed out",
17500 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
17501 if (bxe_flr_clnup_poll_hw_counter(sc,
17502 QM_REG_PF_USG_CNT_0 + 4*SC_FUNC(sc),
17503 "QM PF usage counter timed out",
17508 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
17509 if (bxe_flr_clnup_poll_hw_counter(sc,
17510 TM_REG_LIN0_VNIC_UC + 4*SC_PORT(sc),
17511 "Timers VNIC usage counter timed out",
17516 if (bxe_flr_clnup_poll_hw_counter(sc,
17517 TM_REG_LIN0_NUM_SCANS + 4*SC_PORT(sc),
17518 "Timers NUM_SCANS usage counter timed out",
17523 /* Wait DMAE PF usage counter to zero */
17524 if (bxe_flr_clnup_poll_hw_counter(sc,
17525 dmae_reg_go_c[INIT_DMAE_C(sc)],
17526 "DMAE dommand register timed out",
17534 #define OP_GEN_PARAM(param) \
17535 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
17536 #define OP_GEN_TYPE(type) \
17537 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
17538 #define OP_GEN_AGG_VECT(index) \
17539 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
17542 bxe_send_final_clnup(struct bxe_softc *sc,
17543 uint8_t clnup_func,
17546 uint32_t op_gen_command = 0;
17547 uint32_t comp_addr = (BAR_CSTRORM_INTMEM +
17548 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func));
17551 if (REG_RD(sc, comp_addr)) {
17552 BLOGE(sc, "Cleanup complete was not 0 before sending\n");
17556 op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
17557 op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
17558 op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
17559 op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
17561 BLOGD(sc, DBG_LOAD, "sending FW Final cleanup\n");
17562 REG_WR(sc, XSDM_REG_OPERATION_GEN, op_gen_command);
17564 if (bxe_flr_clnup_reg_poll(sc, comp_addr, 1, poll_cnt) != 1) {
17565 BLOGE(sc, "FW final cleanup did not succeed\n");
17566 BLOGD(sc, DBG_LOAD, "At timeout completion address contained %x\n",
17567 (REG_RD(sc, comp_addr)));
17568 bxe_panic(sc, ("FLR cleanup failed\n"));
17572 /* Zero completion for nxt FLR */
17573 REG_WR(sc, comp_addr, 0);
17579 bxe_pbf_pN_buf_flushed(struct bxe_softc *sc,
17580 struct pbf_pN_buf_regs *regs,
17581 uint32_t poll_count)
17583 uint32_t init_crd, crd, crd_start, crd_freed, crd_freed_start;
17584 uint32_t cur_cnt = poll_count;
17586 crd_freed = crd_freed_start = REG_RD(sc, regs->crd_freed);
17587 crd = crd_start = REG_RD(sc, regs->crd);
17588 init_crd = REG_RD(sc, regs->init_crd);
17590 BLOGD(sc, DBG_LOAD, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
17591 BLOGD(sc, DBG_LOAD, "CREDIT[%d] : s:%x\n", regs->pN, crd);
17592 BLOGD(sc, DBG_LOAD, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
17594 while ((crd != init_crd) &&
17595 ((uint32_t)((int32_t)crd_freed - (int32_t)crd_freed_start) <
17596 (init_crd - crd_start))) {
17598 DELAY(FLR_WAIT_INTERVAL);
17599 crd = REG_RD(sc, regs->crd);
17600 crd_freed = REG_RD(sc, regs->crd_freed);
17602 BLOGD(sc, DBG_LOAD, "PBF tx buffer[%d] timed out\n", regs->pN);
17603 BLOGD(sc, DBG_LOAD, "CREDIT[%d] : c:%x\n", regs->pN, crd);
17604 BLOGD(sc, DBG_LOAD, "CREDIT_FREED[%d]: c:%x\n", regs->pN, crd_freed);
17609 BLOGD(sc, DBG_LOAD, "Waited %d*%d usec for PBF tx buffer[%d]\n",
17610 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
17614 bxe_pbf_pN_cmd_flushed(struct bxe_softc *sc,
17615 struct pbf_pN_cmd_regs *regs,
17616 uint32_t poll_count)
17618 uint32_t occup, to_free, freed, freed_start;
17619 uint32_t cur_cnt = poll_count;
17621 occup = to_free = REG_RD(sc, regs->lines_occup);
17622 freed = freed_start = REG_RD(sc, regs->lines_freed);
17624 BLOGD(sc, DBG_LOAD, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
17625 BLOGD(sc, DBG_LOAD, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
17628 ((uint32_t)((int32_t)freed - (int32_t)freed_start) < to_free)) {
17630 DELAY(FLR_WAIT_INTERVAL);
17631 occup = REG_RD(sc, regs->lines_occup);
17632 freed = REG_RD(sc, regs->lines_freed);
17634 BLOGD(sc, DBG_LOAD, "PBF cmd queue[%d] timed out\n", regs->pN);
17635 BLOGD(sc, DBG_LOAD, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
17636 BLOGD(sc, DBG_LOAD, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
17641 BLOGD(sc, DBG_LOAD, "Waited %d*%d usec for PBF cmd queue[%d]\n",
17642 poll_count - cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
17646 bxe_tx_hw_flushed(struct bxe_softc *sc, uint32_t poll_count)
17648 struct pbf_pN_cmd_regs cmd_regs[] = {
17649 {0, (CHIP_IS_E3B0(sc)) ?
17650 PBF_REG_TQ_OCCUPANCY_Q0 :
17651 PBF_REG_P0_TQ_OCCUPANCY,
17652 (CHIP_IS_E3B0(sc)) ?
17653 PBF_REG_TQ_LINES_FREED_CNT_Q0 :
17654 PBF_REG_P0_TQ_LINES_FREED_CNT},
17655 {1, (CHIP_IS_E3B0(sc)) ?
17656 PBF_REG_TQ_OCCUPANCY_Q1 :
17657 PBF_REG_P1_TQ_OCCUPANCY,
17658 (CHIP_IS_E3B0(sc)) ?
17659 PBF_REG_TQ_LINES_FREED_CNT_Q1 :
17660 PBF_REG_P1_TQ_LINES_FREED_CNT},
17661 {4, (CHIP_IS_E3B0(sc)) ?
17662 PBF_REG_TQ_OCCUPANCY_LB_Q :
17663 PBF_REG_P4_TQ_OCCUPANCY,
17664 (CHIP_IS_E3B0(sc)) ?
17665 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
17666 PBF_REG_P4_TQ_LINES_FREED_CNT}
17669 struct pbf_pN_buf_regs buf_regs[] = {
17670 {0, (CHIP_IS_E3B0(sc)) ?
17671 PBF_REG_INIT_CRD_Q0 :
17672 PBF_REG_P0_INIT_CRD ,
17673 (CHIP_IS_E3B0(sc)) ?
17674 PBF_REG_CREDIT_Q0 :
17676 (CHIP_IS_E3B0(sc)) ?
17677 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
17678 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
17679 {1, (CHIP_IS_E3B0(sc)) ?
17680 PBF_REG_INIT_CRD_Q1 :
17681 PBF_REG_P1_INIT_CRD,
17682 (CHIP_IS_E3B0(sc)) ?
17683 PBF_REG_CREDIT_Q1 :
17685 (CHIP_IS_E3B0(sc)) ?
17686 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
17687 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
17688 {4, (CHIP_IS_E3B0(sc)) ?
17689 PBF_REG_INIT_CRD_LB_Q :
17690 PBF_REG_P4_INIT_CRD,
17691 (CHIP_IS_E3B0(sc)) ?
17692 PBF_REG_CREDIT_LB_Q :
17694 (CHIP_IS_E3B0(sc)) ?
17695 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
17696 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
17701 /* Verify the command queues are flushed P0, P1, P4 */
17702 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++) {
17703 bxe_pbf_pN_cmd_flushed(sc, &cmd_regs[i], poll_count);
17706 /* Verify the transmission buffers are flushed P0, P1, P4 */
17707 for (i = 0; i < ARRAY_SIZE(buf_regs); i++) {
17708 bxe_pbf_pN_buf_flushed(sc, &buf_regs[i], poll_count);
17713 bxe_hw_enable_status(struct bxe_softc *sc)
17717 val = REG_RD(sc, CFC_REG_WEAK_ENABLE_PF);
17718 BLOGD(sc, DBG_LOAD, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
17720 val = REG_RD(sc, PBF_REG_DISABLE_PF);
17721 BLOGD(sc, DBG_LOAD, "PBF_REG_DISABLE_PF is 0x%x\n", val);
17723 val = REG_RD(sc, IGU_REG_PCI_PF_MSI_EN);
17724 BLOGD(sc, DBG_LOAD, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
17726 val = REG_RD(sc, IGU_REG_PCI_PF_MSIX_EN);
17727 BLOGD(sc, DBG_LOAD, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
17729 val = REG_RD(sc, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
17730 BLOGD(sc, DBG_LOAD, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
17732 val = REG_RD(sc, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
17733 BLOGD(sc, DBG_LOAD, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
17735 val = REG_RD(sc, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
17736 BLOGD(sc, DBG_LOAD, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
17738 val = REG_RD(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
17739 BLOGD(sc, DBG_LOAD, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n", val);
17743 bxe_pf_flr_clnup(struct bxe_softc *sc)
17745 uint32_t poll_cnt = bxe_flr_clnup_poll_count(sc);
17747 BLOGD(sc, DBG_LOAD, "Cleanup after FLR PF[%d]\n", SC_ABS_FUNC(sc));
17749 /* Re-enable PF target read access */
17750 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
17752 /* Poll HW usage counters */
17753 BLOGD(sc, DBG_LOAD, "Polling usage counters\n");
17754 if (bxe_poll_hw_usage_counters(sc, poll_cnt)) {
17758 /* Zero the igu 'trailing edge' and 'leading edge' */
17760 /* Send the FW cleanup command */
17761 if (bxe_send_final_clnup(sc, (uint8_t)SC_FUNC(sc), poll_cnt)) {
17767 /* Verify TX hw is flushed */
17768 bxe_tx_hw_flushed(sc, poll_cnt);
17770 /* Wait 100ms (not adjusted according to platform) */
17773 /* Verify no pending pci transactions */
17774 if (bxe_is_pcie_pending(sc)) {
17775 BLOGE(sc, "PCIE Transactions still pending\n");
17779 bxe_hw_enable_status(sc);
17782 * Master enable - Due to WB DMAE writes performed before this
17783 * register is re-initialized as part of the regular function init
17785 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
17791 bxe_init_hw_func(struct bxe_softc *sc)
17793 int port = SC_PORT(sc);
17794 int func = SC_FUNC(sc);
17795 int init_phase = PHASE_PF0 + func;
17796 struct ecore_ilt *ilt = sc->ilt;
17797 uint16_t cdu_ilt_start;
17798 uint32_t addr, val;
17799 uint32_t main_mem_base, main_mem_size, main_mem_prty_clr;
17800 int i, main_mem_width, rc;
17802 BLOGD(sc, DBG_LOAD, "starting func init for func %d\n", func);
17805 if (!CHIP_IS_E1x(sc)) {
17806 rc = bxe_pf_flr_clnup(sc);
17808 BLOGE(sc, "FLR cleanup failed!\n");
17809 // XXX bxe_fw_dump(sc);
17810 // XXX bxe_idle_chk(sc);
17815 /* set MSI reconfigure capability */
17816 if (sc->devinfo.int_block == INT_BLOCK_HC) {
17817 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
17818 val = REG_RD(sc, addr);
17819 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
17820 REG_WR(sc, addr, val);
17823 ecore_init_block(sc, BLOCK_PXP, init_phase);
17824 ecore_init_block(sc, BLOCK_PXP2, init_phase);
17827 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
17829 for (i = 0; i < L2_ILT_LINES(sc); i++) {
17830 ilt->lines[cdu_ilt_start + i].page = sc->context[i].vcxt;
17831 ilt->lines[cdu_ilt_start + i].page_mapping =
17832 sc->context[i].vcxt_dma.paddr;
17833 ilt->lines[cdu_ilt_start + i].size = sc->context[i].size;
17835 ecore_ilt_init_op(sc, INITOP_SET);
17838 REG_WR(sc, PRS_REG_NIC_MODE, 1);
17839 BLOGD(sc, DBG_LOAD, "NIC MODE configured\n");
17841 if (!CHIP_IS_E1x(sc)) {
17842 uint32_t pf_conf = IGU_PF_CONF_FUNC_EN;
17844 /* Turn on a single ISR mode in IGU if driver is going to use
17847 if (sc->interrupt_mode != INTR_MODE_MSIX) {
17848 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
17852 * Timers workaround bug: function init part.
17853 * Need to wait 20msec after initializing ILT,
17854 * needed to make sure there are no requests in
17855 * one of the PXP internal queues with "old" ILT addresses
17860 * Master enable - Due to WB DMAE writes performed before this
17861 * register is re-initialized as part of the regular function
17864 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
17865 /* Enable the function in IGU */
17866 REG_WR(sc, IGU_REG_PF_CONFIGURATION, pf_conf);
17869 sc->dmae_ready = 1;
17871 ecore_init_block(sc, BLOCK_PGLUE_B, init_phase);
17873 if (!CHIP_IS_E1x(sc))
17874 REG_WR(sc, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
17876 ecore_init_block(sc, BLOCK_ATC, init_phase);
17877 ecore_init_block(sc, BLOCK_DMAE, init_phase);
17878 ecore_init_block(sc, BLOCK_NIG, init_phase);
17879 ecore_init_block(sc, BLOCK_SRC, init_phase);
17880 ecore_init_block(sc, BLOCK_MISC, init_phase);
17881 ecore_init_block(sc, BLOCK_TCM, init_phase);
17882 ecore_init_block(sc, BLOCK_UCM, init_phase);
17883 ecore_init_block(sc, BLOCK_CCM, init_phase);
17884 ecore_init_block(sc, BLOCK_XCM, init_phase);
17885 ecore_init_block(sc, BLOCK_TSEM, init_phase);
17886 ecore_init_block(sc, BLOCK_USEM, init_phase);
17887 ecore_init_block(sc, BLOCK_CSEM, init_phase);
17888 ecore_init_block(sc, BLOCK_XSEM, init_phase);
17890 if (!CHIP_IS_E1x(sc))
17891 REG_WR(sc, QM_REG_PF_EN, 1);
17893 if (!CHIP_IS_E1x(sc)) {
17894 REG_WR(sc, TSEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func);
17895 REG_WR(sc, USEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func);
17896 REG_WR(sc, CSEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func);
17897 REG_WR(sc, XSEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func);
17899 ecore_init_block(sc, BLOCK_QM, init_phase);
17901 ecore_init_block(sc, BLOCK_TM, init_phase);
17902 ecore_init_block(sc, BLOCK_DORQ, init_phase);
17904 bxe_iov_init_dq(sc);
17906 ecore_init_block(sc, BLOCK_BRB1, init_phase);
17907 ecore_init_block(sc, BLOCK_PRS, init_phase);
17908 ecore_init_block(sc, BLOCK_TSDM, init_phase);
17909 ecore_init_block(sc, BLOCK_CSDM, init_phase);
17910 ecore_init_block(sc, BLOCK_USDM, init_phase);
17911 ecore_init_block(sc, BLOCK_XSDM, init_phase);
17912 ecore_init_block(sc, BLOCK_UPB, init_phase);
17913 ecore_init_block(sc, BLOCK_XPB, init_phase);
17914 ecore_init_block(sc, BLOCK_PBF, init_phase);
17915 if (!CHIP_IS_E1x(sc))
17916 REG_WR(sc, PBF_REG_DISABLE_PF, 0);
17918 ecore_init_block(sc, BLOCK_CDU, init_phase);
17920 ecore_init_block(sc, BLOCK_CFC, init_phase);
17922 if (!CHIP_IS_E1x(sc))
17923 REG_WR(sc, CFC_REG_WEAK_ENABLE_PF, 1);
17926 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 1);
17927 REG_WR(sc, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, OVLAN(sc));
17930 ecore_init_block(sc, BLOCK_MISC_AEU, init_phase);
17932 /* HC init per function */
17933 if (sc->devinfo.int_block == INT_BLOCK_HC) {
17934 if (CHIP_IS_E1H(sc)) {
17935 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
17937 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, 0);
17938 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, 0);
17940 ecore_init_block(sc, BLOCK_HC, init_phase);
17943 int num_segs, sb_idx, prod_offset;
17945 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
17947 if (!CHIP_IS_E1x(sc)) {
17948 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, 0);
17949 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, 0);
17952 ecore_init_block(sc, BLOCK_IGU, init_phase);
17954 if (!CHIP_IS_E1x(sc)) {
17958 * E2 mode: address 0-135 match to the mapping memory;
17959 * 136 - PF0 default prod; 137 - PF1 default prod;
17960 * 138 - PF2 default prod; 139 - PF3 default prod;
17961 * 140 - PF0 attn prod; 141 - PF1 attn prod;
17962 * 142 - PF2 attn prod; 143 - PF3 attn prod;
17963 * 144-147 reserved.
17965 * E1.5 mode - In backward compatible mode;
17966 * for non default SB; each even line in the memory
17967 * holds the U producer and each odd line hold
17968 * the C producer. The first 128 producers are for
17969 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
17970 * producers are for the DSB for each PF.
17971 * Each PF has five segments: (the order inside each
17972 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
17973 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
17974 * 144-147 attn prods;
17976 /* non-default-status-blocks */
17977 num_segs = CHIP_INT_MODE_IS_BC(sc) ?
17978 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
17979 for (sb_idx = 0; sb_idx < sc->igu_sb_cnt; sb_idx++) {
17980 prod_offset = (sc->igu_base_sb + sb_idx) *
17983 for (i = 0; i < num_segs; i++) {
17984 addr = IGU_REG_PROD_CONS_MEMORY +
17985 (prod_offset + i) * 4;
17986 REG_WR(sc, addr, 0);
17988 /* send consumer update with value 0 */
17989 bxe_ack_sb(sc, sc->igu_base_sb + sb_idx,
17990 USTORM_ID, 0, IGU_INT_NOP, 1);
17991 bxe_igu_clear_sb(sc, sc->igu_base_sb + sb_idx);
17994 /* default-status-blocks */
17995 num_segs = CHIP_INT_MODE_IS_BC(sc) ?
17996 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
17998 if (CHIP_IS_MODE_4_PORT(sc))
17999 dsb_idx = SC_FUNC(sc);
18001 dsb_idx = SC_VN(sc);
18003 prod_offset = (CHIP_INT_MODE_IS_BC(sc) ?
18004 IGU_BC_BASE_DSB_PROD + dsb_idx :
18005 IGU_NORM_BASE_DSB_PROD + dsb_idx);
18008 * igu prods come in chunks of E1HVN_MAX (4) -
18009 * does not matters what is the current chip mode
18011 for (i = 0; i < (num_segs * E1HVN_MAX);
18013 addr = IGU_REG_PROD_CONS_MEMORY +
18014 (prod_offset + i)*4;
18015 REG_WR(sc, addr, 0);
18017 /* send consumer update with 0 */
18018 if (CHIP_INT_MODE_IS_BC(sc)) {
18019 bxe_ack_sb(sc, sc->igu_dsb_id,
18020 USTORM_ID, 0, IGU_INT_NOP, 1);
18021 bxe_ack_sb(sc, sc->igu_dsb_id,
18022 CSTORM_ID, 0, IGU_INT_NOP, 1);
18023 bxe_ack_sb(sc, sc->igu_dsb_id,
18024 XSTORM_ID, 0, IGU_INT_NOP, 1);
18025 bxe_ack_sb(sc, sc->igu_dsb_id,
18026 TSTORM_ID, 0, IGU_INT_NOP, 1);
18027 bxe_ack_sb(sc, sc->igu_dsb_id,
18028 ATTENTION_ID, 0, IGU_INT_NOP, 1);
18030 bxe_ack_sb(sc, sc->igu_dsb_id,
18031 USTORM_ID, 0, IGU_INT_NOP, 1);
18032 bxe_ack_sb(sc, sc->igu_dsb_id,
18033 ATTENTION_ID, 0, IGU_INT_NOP, 1);
18035 bxe_igu_clear_sb(sc, sc->igu_dsb_id);
18037 /* !!! these should become driver const once
18038 rf-tool supports split-68 const */
18039 REG_WR(sc, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
18040 REG_WR(sc, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
18041 REG_WR(sc, IGU_REG_SB_MASK_LSB, 0);
18042 REG_WR(sc, IGU_REG_SB_MASK_MSB, 0);
18043 REG_WR(sc, IGU_REG_PBA_STATUS_LSB, 0);
18044 REG_WR(sc, IGU_REG_PBA_STATUS_MSB, 0);
18048 /* Reset PCIE errors for debug */
18049 REG_WR(sc, 0x2114, 0xffffffff);
18050 REG_WR(sc, 0x2120, 0xffffffff);
18052 if (CHIP_IS_E1x(sc)) {
18053 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
18054 main_mem_base = HC_REG_MAIN_MEMORY +
18055 SC_PORT(sc) * (main_mem_size * 4);
18056 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
18057 main_mem_width = 8;
18059 val = REG_RD(sc, main_mem_prty_clr);
18061 BLOGD(sc, DBG_LOAD,
18062 "Parity errors in HC block during function init (0x%x)!\n",
18066 /* Clear "false" parity errors in MSI-X table */
18067 for (i = main_mem_base;
18068 i < main_mem_base + main_mem_size * 4;
18069 i += main_mem_width) {
18070 bxe_read_dmae(sc, i, main_mem_width / 4);
18071 bxe_write_dmae(sc, BXE_SP_MAPPING(sc, wb_data),
18072 i, main_mem_width / 4);
18074 /* Clear HC parity attention */
18075 REG_RD(sc, main_mem_prty_clr);
18079 /* Enable STORMs SP logging */
18080 REG_WR8(sc, BAR_USTRORM_INTMEM +
18081 USTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
18082 REG_WR8(sc, BAR_TSTRORM_INTMEM +
18083 TSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
18084 REG_WR8(sc, BAR_CSTRORM_INTMEM +
18085 CSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
18086 REG_WR8(sc, BAR_XSTRORM_INTMEM +
18087 XSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
18090 elink_phy_probe(&sc->link_params);
18096 bxe_link_reset(struct bxe_softc *sc)
18098 if (!BXE_NOMCP(sc)) {
18099 bxe_acquire_phy_lock(sc);
18100 elink_lfa_reset(&sc->link_params, &sc->link_vars);
18101 bxe_release_phy_lock(sc);
18103 if (!CHIP_REV_IS_SLOW(sc)) {
18104 BLOGW(sc, "Bootcode is missing - cannot reset link\n");
18110 bxe_reset_port(struct bxe_softc *sc)
18112 int port = SC_PORT(sc);
18115 /* reset physical Link */
18116 bxe_link_reset(sc);
18118 REG_WR(sc, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
18120 /* Do not rcv packets to BRB */
18121 REG_WR(sc, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
18122 /* Do not direct rcv packets that are not for MCP to the BRB */
18123 REG_WR(sc, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
18124 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
18126 /* Configure AEU */
18127 REG_WR(sc, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
18131 /* Check for BRB port occupancy */
18132 val = REG_RD(sc, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
18134 BLOGD(sc, DBG_LOAD,
18135 "BRB1 is not empty, %d blocks are occupied\n", val);
18138 /* TODO: Close Doorbell port? */
18142 bxe_ilt_wr(struct bxe_softc *sc,
18147 uint32_t wb_write[2];
18149 if (CHIP_IS_E1(sc)) {
18150 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
18152 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
18155 wb_write[0] = ONCHIP_ADDR1(addr);
18156 wb_write[1] = ONCHIP_ADDR2(addr);
18157 REG_WR_DMAE(sc, reg, wb_write, 2);
18161 bxe_clear_func_ilt(struct bxe_softc *sc,
18164 uint32_t i, base = FUNC_ILT_BASE(func);
18165 for (i = base; i < base + ILT_PER_FUNC; i++) {
18166 bxe_ilt_wr(sc, i, 0);
18171 bxe_reset_func(struct bxe_softc *sc)
18173 struct bxe_fastpath *fp;
18174 int port = SC_PORT(sc);
18175 int func = SC_FUNC(sc);
18178 /* Disable the function in the FW */
18179 REG_WR8(sc, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
18180 REG_WR8(sc, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
18181 REG_WR8(sc, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
18182 REG_WR8(sc, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
18185 FOR_EACH_ETH_QUEUE(sc, i) {
18187 REG_WR8(sc, BAR_CSTRORM_INTMEM +
18188 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
18193 REG_WR8(sc, BAR_CSTRORM_INTMEM +
18194 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
18197 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++) {
18198 REG_WR(sc, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func), 0);
18201 /* Configure IGU */
18202 if (sc->devinfo.int_block == INT_BLOCK_HC) {
18203 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, 0);
18204 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, 0);
18206 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, 0);
18207 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, 0);
18210 if (CNIC_LOADED(sc)) {
18211 /* Disable Timer scan */
18212 REG_WR(sc, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
18214 * Wait for at least 10ms and up to 2 second for the timers
18217 for (i = 0; i < 200; i++) {
18219 if (!REG_RD(sc, TM_REG_LIN0_SCAN_ON + port*4))
18225 bxe_clear_func_ilt(sc, func);
18228 * Timers workaround bug for E2: if this is vnic-3,
18229 * we need to set the entire ilt range for this timers.
18231 if (!CHIP_IS_E1x(sc) && SC_VN(sc) == 3) {
18232 struct ilt_client_info ilt_cli;
18233 /* use dummy TM client */
18234 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
18236 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
18237 ilt_cli.client_num = ILT_CLIENT_TM;
18239 ecore_ilt_boundry_init_op(sc, &ilt_cli, 0, INITOP_CLEAR);
18242 /* this assumes that reset_port() called before reset_func()*/
18243 if (!CHIP_IS_E1x(sc)) {
18244 bxe_pf_disable(sc);
18247 sc->dmae_ready = 0;
18251 bxe_gunzip_init(struct bxe_softc *sc)
18257 bxe_gunzip_end(struct bxe_softc *sc)
18263 bxe_init_firmware(struct bxe_softc *sc)
18265 if (CHIP_IS_E1(sc)) {
18266 ecore_init_e1_firmware(sc);
18267 sc->iro_array = e1_iro_arr;
18268 } else if (CHIP_IS_E1H(sc)) {
18269 ecore_init_e1h_firmware(sc);
18270 sc->iro_array = e1h_iro_arr;
18271 } else if (!CHIP_IS_E1x(sc)) {
18272 ecore_init_e2_firmware(sc);
18273 sc->iro_array = e2_iro_arr;
18275 BLOGE(sc, "Unsupported chip revision\n");
18283 bxe_release_firmware(struct bxe_softc *sc)
18290 ecore_gunzip(struct bxe_softc *sc,
18291 const uint8_t *zbuf,
18294 /* XXX : Implement... */
18295 BLOGD(sc, DBG_LOAD, "ECORE_GUNZIP NOT IMPLEMENTED\n");
18300 ecore_reg_wr_ind(struct bxe_softc *sc,
18304 bxe_reg_wr_ind(sc, addr, val);
18308 ecore_write_dmae_phys_len(struct bxe_softc *sc,
18309 bus_addr_t phys_addr,
18313 bxe_write_dmae_phys_len(sc, phys_addr, addr, len);
18317 ecore_storm_memset_struct(struct bxe_softc *sc,
18323 for (i = 0; i < size/4; i++) {
18324 REG_WR(sc, addr + (i * 4), data[i]);
18330 * character device - ioctl interface definitions
18334 #include "bxe_dump.h"
18335 #include "bxe_ioctl.h"
18336 #include <sys/conf.h>
18338 static int bxe_eioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
18339 struct thread *td);
18341 static struct cdevsw bxe_cdevsw = {
18342 .d_version = D_VERSION,
18343 .d_ioctl = bxe_eioctl,
18344 .d_name = "bxecnic",
18347 #define BXE_PATH(sc) (CHIP_IS_E1x(sc) ? 0 : (sc->pcie_func & 1))
18350 #define DUMP_ALL_PRESETS 0x1FFF
18351 #define DUMP_MAX_PRESETS 13
18352 #define IS_E1_REG(chips) ((chips & DUMP_CHIP_E1) == DUMP_CHIP_E1)
18353 #define IS_E1H_REG(chips) ((chips & DUMP_CHIP_E1H) == DUMP_CHIP_E1H)
18354 #define IS_E2_REG(chips) ((chips & DUMP_CHIP_E2) == DUMP_CHIP_E2)
18355 #define IS_E3A0_REG(chips) ((chips & DUMP_CHIP_E3A0) == DUMP_CHIP_E3A0)
18356 #define IS_E3B0_REG(chips) ((chips & DUMP_CHIP_E3B0) == DUMP_CHIP_E3B0)
18358 #define IS_REG_IN_PRESET(presets, idx) \
18359 ((presets & (1 << (idx-1))) == (1 << (idx-1)))
18363 bxe_get_preset_regs_len(struct bxe_softc *sc, uint32_t preset)
18365 if (CHIP_IS_E1(sc))
18366 return dump_num_registers[0][preset-1];
18367 else if (CHIP_IS_E1H(sc))
18368 return dump_num_registers[1][preset-1];
18369 else if (CHIP_IS_E2(sc))
18370 return dump_num_registers[2][preset-1];
18371 else if (CHIP_IS_E3A0(sc))
18372 return dump_num_registers[3][preset-1];
18373 else if (CHIP_IS_E3B0(sc))
18374 return dump_num_registers[4][preset-1];
18380 bxe_get_total_regs_len32(struct bxe_softc *sc)
18382 uint32_t preset_idx;
18383 int regdump_len32 = 0;
18386 /* Calculate the total preset regs length */
18387 for (preset_idx = 1; preset_idx <= DUMP_MAX_PRESETS; preset_idx++) {
18388 regdump_len32 += bxe_get_preset_regs_len(sc, preset_idx);
18391 return regdump_len32;
18394 static const uint32_t *
18395 __bxe_get_page_addr_ar(struct bxe_softc *sc)
18397 if (CHIP_IS_E2(sc))
18398 return page_vals_e2;
18399 else if (CHIP_IS_E3(sc))
18400 return page_vals_e3;
18406 __bxe_get_page_reg_num(struct bxe_softc *sc)
18408 if (CHIP_IS_E2(sc))
18409 return PAGE_MODE_VALUES_E2;
18410 else if (CHIP_IS_E3(sc))
18411 return PAGE_MODE_VALUES_E3;
18416 static const uint32_t *
18417 __bxe_get_page_write_ar(struct bxe_softc *sc)
18419 if (CHIP_IS_E2(sc))
18420 return page_write_regs_e2;
18421 else if (CHIP_IS_E3(sc))
18422 return page_write_regs_e3;
18428 __bxe_get_page_write_num(struct bxe_softc *sc)
18430 if (CHIP_IS_E2(sc))
18431 return PAGE_WRITE_REGS_E2;
18432 else if (CHIP_IS_E3(sc))
18433 return PAGE_WRITE_REGS_E3;
18438 static const struct reg_addr *
18439 __bxe_get_page_read_ar(struct bxe_softc *sc)
18441 if (CHIP_IS_E2(sc))
18442 return page_read_regs_e2;
18443 else if (CHIP_IS_E3(sc))
18444 return page_read_regs_e3;
18450 __bxe_get_page_read_num(struct bxe_softc *sc)
18452 if (CHIP_IS_E2(sc))
18453 return PAGE_READ_REGS_E2;
18454 else if (CHIP_IS_E3(sc))
18455 return PAGE_READ_REGS_E3;
18461 bxe_is_reg_in_chip(struct bxe_softc *sc, const struct reg_addr *reg_info)
18463 if (CHIP_IS_E1(sc))
18464 return IS_E1_REG(reg_info->chips);
18465 else if (CHIP_IS_E1H(sc))
18466 return IS_E1H_REG(reg_info->chips);
18467 else if (CHIP_IS_E2(sc))
18468 return IS_E2_REG(reg_info->chips);
18469 else if (CHIP_IS_E3A0(sc))
18470 return IS_E3A0_REG(reg_info->chips);
18471 else if (CHIP_IS_E3B0(sc))
18472 return IS_E3B0_REG(reg_info->chips);
18478 bxe_is_wreg_in_chip(struct bxe_softc *sc, const struct wreg_addr *wreg_info)
18480 if (CHIP_IS_E1(sc))
18481 return IS_E1_REG(wreg_info->chips);
18482 else if (CHIP_IS_E1H(sc))
18483 return IS_E1H_REG(wreg_info->chips);
18484 else if (CHIP_IS_E2(sc))
18485 return IS_E2_REG(wreg_info->chips);
18486 else if (CHIP_IS_E3A0(sc))
18487 return IS_E3A0_REG(wreg_info->chips);
18488 else if (CHIP_IS_E3B0(sc))
18489 return IS_E3B0_REG(wreg_info->chips);
18495 * bxe_read_pages_regs - read "paged" registers
18497 * @bp device handle
18500 * Reads "paged" memories: memories that may only be read by first writing to a
18501 * specific address ("write address") and then reading from a specific address
18502 * ("read address"). There may be more than one write address per "page" and
18503 * more than one read address per write address.
18506 bxe_read_pages_regs(struct bxe_softc *sc, uint32_t *p, uint32_t preset)
18508 uint32_t i, j, k, n;
18510 /* addresses of the paged registers */
18511 const uint32_t *page_addr = __bxe_get_page_addr_ar(sc);
18512 /* number of paged registers */
18513 int num_pages = __bxe_get_page_reg_num(sc);
18514 /* write addresses */
18515 const uint32_t *write_addr = __bxe_get_page_write_ar(sc);
18516 /* number of write addresses */
18517 int write_num = __bxe_get_page_write_num(sc);
18518 /* read addresses info */
18519 const struct reg_addr *read_addr = __bxe_get_page_read_ar(sc);
18520 /* number of read addresses */
18521 int read_num = __bxe_get_page_read_num(sc);
18522 uint32_t addr, size;
18524 for (i = 0; i < num_pages; i++) {
18525 for (j = 0; j < write_num; j++) {
18526 REG_WR(sc, write_addr[j], page_addr[i]);
18528 for (k = 0; k < read_num; k++) {
18529 if (IS_REG_IN_PRESET(read_addr[k].presets, preset)) {
18530 size = read_addr[k].size;
18531 for (n = 0; n < size; n++) {
18532 addr = read_addr[k].addr + n*4;
18533 *p++ = REG_RD(sc, addr);
18544 bxe_get_preset_regs(struct bxe_softc *sc, uint32_t *p, uint32_t preset)
18546 uint32_t i, j, addr;
18547 const struct wreg_addr *wreg_addr_p = NULL;
18549 if (CHIP_IS_E1(sc))
18550 wreg_addr_p = &wreg_addr_e1;
18551 else if (CHIP_IS_E1H(sc))
18552 wreg_addr_p = &wreg_addr_e1h;
18553 else if (CHIP_IS_E2(sc))
18554 wreg_addr_p = &wreg_addr_e2;
18555 else if (CHIP_IS_E3A0(sc))
18556 wreg_addr_p = &wreg_addr_e3;
18557 else if (CHIP_IS_E3B0(sc))
18558 wreg_addr_p = &wreg_addr_e3b0;
18562 /* Read the idle_chk registers */
18563 for (i = 0; i < IDLE_REGS_COUNT; i++) {
18564 if (bxe_is_reg_in_chip(sc, &idle_reg_addrs[i]) &&
18565 IS_REG_IN_PRESET(idle_reg_addrs[i].presets, preset)) {
18566 for (j = 0; j < idle_reg_addrs[i].size; j++)
18567 *p++ = REG_RD(sc, idle_reg_addrs[i].addr + j*4);
18571 /* Read the regular registers */
18572 for (i = 0; i < REGS_COUNT; i++) {
18573 if (bxe_is_reg_in_chip(sc, ®_addrs[i]) &&
18574 IS_REG_IN_PRESET(reg_addrs[i].presets, preset)) {
18575 for (j = 0; j < reg_addrs[i].size; j++)
18576 *p++ = REG_RD(sc, reg_addrs[i].addr + j*4);
18580 /* Read the CAM registers */
18581 if (bxe_is_wreg_in_chip(sc, wreg_addr_p) &&
18582 IS_REG_IN_PRESET(wreg_addr_p->presets, preset)) {
18583 for (i = 0; i < wreg_addr_p->size; i++) {
18584 *p++ = REG_RD(sc, wreg_addr_p->addr + i*4);
18586 /* In case of wreg_addr register, read additional
18587 registers from read_regs array
18589 for (j = 0; j < wreg_addr_p->read_regs_count; j++) {
18590 addr = *(wreg_addr_p->read_regs);
18591 *p++ = REG_RD(sc, addr + j*4);
18596 /* Paged registers are supported in E2 & E3 only */
18597 if (CHIP_IS_E2(sc) || CHIP_IS_E3(sc)) {
18598 /* Read "paged" registers */
18599 bxe_read_pages_regs(sc, p, preset);
18606 bxe_grc_dump(struct bxe_softc *sc)
18609 uint32_t preset_idx;
18612 struct dump_header *d_hdr;
18614 if (sc->grcdump_done)
18617 ecore_disable_blocks_parity(sc);
18619 buf = sc->grc_dump;
18620 d_hdr = sc->grc_dump;
18622 d_hdr->header_size = (sizeof(struct dump_header) >> 2) - 1;
18623 d_hdr->version = BNX2X_DUMP_VERSION;
18624 d_hdr->preset = DUMP_ALL_PRESETS;
18626 if (CHIP_IS_E1(sc)) {
18627 d_hdr->dump_meta_data = DUMP_CHIP_E1;
18628 } else if (CHIP_IS_E1H(sc)) {
18629 d_hdr->dump_meta_data = DUMP_CHIP_E1H;
18630 } else if (CHIP_IS_E2(sc)) {
18631 d_hdr->dump_meta_data = DUMP_CHIP_E2 |
18632 (BXE_PATH(sc) ? DUMP_PATH_1 : DUMP_PATH_0);
18633 } else if (CHIP_IS_E3A0(sc)) {
18634 d_hdr->dump_meta_data = DUMP_CHIP_E3A0 |
18635 (BXE_PATH(sc) ? DUMP_PATH_1 : DUMP_PATH_0);
18636 } else if (CHIP_IS_E3B0(sc)) {
18637 d_hdr->dump_meta_data = DUMP_CHIP_E3B0 |
18638 (BXE_PATH(sc) ? DUMP_PATH_1 : DUMP_PATH_0);
18641 buf += sizeof(struct dump_header);
18643 for (preset_idx = 1; preset_idx <= DUMP_MAX_PRESETS; preset_idx++) {
18645 /* Skip presets with IOR */
18646 if ((preset_idx == 2) || (preset_idx == 5) || (preset_idx == 8) ||
18647 (preset_idx == 11))
18650 rval = bxe_get_preset_regs(sc, sc->grc_dump, preset_idx);
18655 size = bxe_get_preset_regs_len(sc, preset_idx) * (sizeof (uint32_t));
18660 ecore_clear_blocks_parity(sc);
18661 ecore_enable_blocks_parity(sc);
18663 sc->grcdump_done = 1;
18668 bxe_add_cdev(struct bxe_softc *sc)
18672 grc_dump_size = (bxe_get_total_regs_len32(sc) * sizeof(uint32_t)) +
18673 sizeof(struct dump_header);
18675 sc->grc_dump = malloc(grc_dump_size, M_DEVBUF, M_NOWAIT);
18677 if (sc->grc_dump == NULL)
18680 sc->ioctl_dev = make_dev(&bxe_cdevsw,
18681 sc->ifnet->if_dunit,
18686 if_name(sc->ifnet));
18688 if (sc->ioctl_dev == NULL) {
18690 free(sc->grc_dump, M_DEVBUF);
18695 sc->ioctl_dev->si_drv1 = sc;
18701 bxe_del_cdev(struct bxe_softc *sc)
18703 if (sc->ioctl_dev != NULL)
18704 destroy_dev(sc->ioctl_dev);
18706 if (sc->grc_dump == NULL)
18707 free(sc->grc_dump, M_DEVBUF);
18713 bxe_eioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
18716 struct bxe_softc *sc;
18719 bxe_grcdump_t *dump = NULL;
18722 if ((sc = (struct bxe_softc *)dev->si_drv1) == NULL)
18727 dump = (bxe_grcdump_t *)data;
18731 case BXE_GRC_DUMP_SIZE:
18732 dump->pci_func = sc->pcie_func;
18733 dump->grcdump_size = (bxe_get_total_regs_len32(sc) * sizeof(uint32_t)) +
18734 sizeof(struct dump_header);
18739 grc_dump_size = (bxe_get_total_regs_len32(sc) * sizeof(uint32_t)) +
18740 sizeof(struct dump_header);
18742 if ((sc->grc_dump == NULL) || (dump->grcdump == NULL) ||
18743 (dump->grcdump_size < grc_dump_size) || (!sc->grcdump_done)) {
18747 dump->grcdump_dwords = grc_dump_size >> 2;
18748 rval = copyout(sc->grc_dump, dump->grcdump, grc_dump_size);
18749 sc->grcdump_done = 0;