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.91"
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);
193 * FreeBSD KLD module/device interface event handler method.
195 static device_method_t bxe_methods[] = {
196 /* Device interface (device_if.h) */
197 DEVMETHOD(device_probe, bxe_probe),
198 DEVMETHOD(device_attach, bxe_attach),
199 DEVMETHOD(device_detach, bxe_detach),
200 DEVMETHOD(device_shutdown, bxe_shutdown),
201 /* Bus interface (bus_if.h) */
202 DEVMETHOD(bus_print_child, bus_generic_print_child),
203 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
208 * FreeBSD KLD Module data declaration
210 static driver_t bxe_driver = {
211 "bxe", /* module name */
212 bxe_methods, /* event handler */
213 sizeof(struct bxe_softc) /* extra data */
217 * FreeBSD dev class is needed to manage dev instances and
218 * to associate with a bus type
220 static devclass_t bxe_devclass;
222 MODULE_DEPEND(bxe, pci, 1, 1, 1);
223 MODULE_DEPEND(bxe, ether, 1, 1, 1);
224 DRIVER_MODULE(bxe, pci, bxe_driver, bxe_devclass, 0, 0);
226 /* resources needed for unloading a previously loaded device */
228 #define BXE_PREV_WAIT_NEEDED 1
229 struct mtx bxe_prev_mtx;
230 MTX_SYSINIT(bxe_prev_mtx, &bxe_prev_mtx, "bxe_prev_lock", MTX_DEF);
231 struct bxe_prev_list_node {
232 LIST_ENTRY(bxe_prev_list_node) node;
236 uint8_t aer; /* XXX automatic error recovery */
239 static LIST_HEAD(, bxe_prev_list_node) bxe_prev_list = LIST_HEAD_INITIALIZER(bxe_prev_list);
241 static int load_count[2][3] = { {0} }; /* per-path: 0-common, 1-port0, 2-port1 */
243 /* Tunable device values... */
245 SYSCTL_NODE(_hw, OID_AUTO, bxe, CTLFLAG_RD, 0, "bxe driver parameters");
248 unsigned long bxe_debug = 0;
249 TUNABLE_ULONG("hw.bxe.debug", &bxe_debug);
250 SYSCTL_ULONG(_hw_bxe, OID_AUTO, debug, (CTLFLAG_RDTUN),
251 &bxe_debug, 0, "Debug logging mode");
253 /* Interrupt Mode: 0 (IRQ), 1 (MSI/IRQ), and 2 (MSI-X/MSI/IRQ) */
254 static int bxe_interrupt_mode = INTR_MODE_MSIX;
255 TUNABLE_INT("hw.bxe.interrupt_mode", &bxe_interrupt_mode);
256 SYSCTL_INT(_hw_bxe, OID_AUTO, interrupt_mode, CTLFLAG_RDTUN,
257 &bxe_interrupt_mode, 0, "Interrupt (MSI-X/MSI/INTx) mode");
259 /* Number of Queues: 0 (Auto) or 1 to 16 (fixed queue number) */
260 static int bxe_queue_count = 4;
261 TUNABLE_INT("hw.bxe.queue_count", &bxe_queue_count);
262 SYSCTL_INT(_hw_bxe, OID_AUTO, queue_count, CTLFLAG_RDTUN,
263 &bxe_queue_count, 0, "Multi-Queue queue count");
265 /* max number of buffers per queue (default RX_BD_USABLE) */
266 static int bxe_max_rx_bufs = 0;
267 TUNABLE_INT("hw.bxe.max_rx_bufs", &bxe_max_rx_bufs);
268 SYSCTL_INT(_hw_bxe, OID_AUTO, max_rx_bufs, CTLFLAG_RDTUN,
269 &bxe_max_rx_bufs, 0, "Maximum Number of Rx Buffers Per Queue");
271 /* Host interrupt coalescing RX tick timer (usecs) */
272 static int bxe_hc_rx_ticks = 25;
273 TUNABLE_INT("hw.bxe.hc_rx_ticks", &bxe_hc_rx_ticks);
274 SYSCTL_INT(_hw_bxe, OID_AUTO, hc_rx_ticks, CTLFLAG_RDTUN,
275 &bxe_hc_rx_ticks, 0, "Host Coalescing Rx ticks");
277 /* Host interrupt coalescing TX tick timer (usecs) */
278 static int bxe_hc_tx_ticks = 50;
279 TUNABLE_INT("hw.bxe.hc_tx_ticks", &bxe_hc_tx_ticks);
280 SYSCTL_INT(_hw_bxe, OID_AUTO, hc_tx_ticks, CTLFLAG_RDTUN,
281 &bxe_hc_tx_ticks, 0, "Host Coalescing Tx ticks");
283 /* Maximum number of Rx packets to process at a time */
284 static int bxe_rx_budget = 0xffffffff;
285 TUNABLE_INT("hw.bxe.rx_budget", &bxe_rx_budget);
286 SYSCTL_INT(_hw_bxe, OID_AUTO, rx_budget, CTLFLAG_TUN,
287 &bxe_rx_budget, 0, "Rx processing budget");
289 /* Maximum LRO aggregation size */
290 static int bxe_max_aggregation_size = 0;
291 TUNABLE_INT("hw.bxe.max_aggregation_size", &bxe_max_aggregation_size);
292 SYSCTL_INT(_hw_bxe, OID_AUTO, max_aggregation_size, CTLFLAG_TUN,
293 &bxe_max_aggregation_size, 0, "max aggregation size");
295 /* PCI MRRS: -1 (Auto), 0 (128B), 1 (256B), 2 (512B), 3 (1KB) */
296 static int bxe_mrrs = -1;
297 TUNABLE_INT("hw.bxe.mrrs", &bxe_mrrs);
298 SYSCTL_INT(_hw_bxe, OID_AUTO, mrrs, CTLFLAG_RDTUN,
299 &bxe_mrrs, 0, "PCIe maximum read request size");
301 /* AutoGrEEEn: 0 (hardware default), 1 (force on), 2 (force off) */
302 static int bxe_autogreeen = 0;
303 TUNABLE_INT("hw.bxe.autogreeen", &bxe_autogreeen);
304 SYSCTL_INT(_hw_bxe, OID_AUTO, autogreeen, CTLFLAG_RDTUN,
305 &bxe_autogreeen, 0, "AutoGrEEEn support");
307 /* 4-tuple RSS support for UDP: 0 (disabled), 1 (enabled) */
308 static int bxe_udp_rss = 0;
309 TUNABLE_INT("hw.bxe.udp_rss", &bxe_udp_rss);
310 SYSCTL_INT(_hw_bxe, OID_AUTO, udp_rss, CTLFLAG_RDTUN,
311 &bxe_udp_rss, 0, "UDP RSS support");
314 #define STAT_NAME_LEN 32 /* no stat names below can be longer than this */
316 #define STATS_OFFSET32(stat_name) \
317 (offsetof(struct bxe_eth_stats, stat_name) / 4)
319 #define Q_STATS_OFFSET32(stat_name) \
320 (offsetof(struct bxe_eth_q_stats, stat_name) / 4)
322 static const struct {
326 #define STATS_FLAGS_PORT 1
327 #define STATS_FLAGS_FUNC 2 /* MF only cares about function stats */
328 #define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
329 char string[STAT_NAME_LEN];
330 } bxe_eth_stats_arr[] = {
331 { STATS_OFFSET32(total_bytes_received_hi),
332 8, STATS_FLAGS_BOTH, "rx_bytes" },
333 { STATS_OFFSET32(error_bytes_received_hi),
334 8, STATS_FLAGS_BOTH, "rx_error_bytes" },
335 { STATS_OFFSET32(total_unicast_packets_received_hi),
336 8, STATS_FLAGS_BOTH, "rx_ucast_packets" },
337 { STATS_OFFSET32(total_multicast_packets_received_hi),
338 8, STATS_FLAGS_BOTH, "rx_mcast_packets" },
339 { STATS_OFFSET32(total_broadcast_packets_received_hi),
340 8, STATS_FLAGS_BOTH, "rx_bcast_packets" },
341 { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
342 8, STATS_FLAGS_PORT, "rx_crc_errors" },
343 { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
344 8, STATS_FLAGS_PORT, "rx_align_errors" },
345 { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
346 8, STATS_FLAGS_PORT, "rx_undersize_packets" },
347 { STATS_OFFSET32(etherstatsoverrsizepkts_hi),
348 8, STATS_FLAGS_PORT, "rx_oversize_packets" },
349 { STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
350 8, STATS_FLAGS_PORT, "rx_fragments" },
351 { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
352 8, STATS_FLAGS_PORT, "rx_jabbers" },
353 { STATS_OFFSET32(no_buff_discard_hi),
354 8, STATS_FLAGS_BOTH, "rx_discards" },
355 { STATS_OFFSET32(mac_filter_discard),
356 4, STATS_FLAGS_PORT, "rx_filtered_packets" },
357 { STATS_OFFSET32(mf_tag_discard),
358 4, STATS_FLAGS_PORT, "rx_mf_tag_discard" },
359 { STATS_OFFSET32(pfc_frames_received_hi),
360 8, STATS_FLAGS_PORT, "pfc_frames_received" },
361 { STATS_OFFSET32(pfc_frames_sent_hi),
362 8, STATS_FLAGS_PORT, "pfc_frames_sent" },
363 { STATS_OFFSET32(brb_drop_hi),
364 8, STATS_FLAGS_PORT, "rx_brb_discard" },
365 { STATS_OFFSET32(brb_truncate_hi),
366 8, STATS_FLAGS_PORT, "rx_brb_truncate" },
367 { STATS_OFFSET32(pause_frames_received_hi),
368 8, STATS_FLAGS_PORT, "rx_pause_frames" },
369 { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
370 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" },
371 { STATS_OFFSET32(nig_timer_max),
372 4, STATS_FLAGS_PORT, "rx_constant_pause_events" },
373 { STATS_OFFSET32(total_bytes_transmitted_hi),
374 8, STATS_FLAGS_BOTH, "tx_bytes" },
375 { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
376 8, STATS_FLAGS_PORT, "tx_error_bytes" },
377 { STATS_OFFSET32(total_unicast_packets_transmitted_hi),
378 8, STATS_FLAGS_BOTH, "tx_ucast_packets" },
379 { STATS_OFFSET32(total_multicast_packets_transmitted_hi),
380 8, STATS_FLAGS_BOTH, "tx_mcast_packets" },
381 { STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
382 8, STATS_FLAGS_BOTH, "tx_bcast_packets" },
383 { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
384 8, STATS_FLAGS_PORT, "tx_mac_errors" },
385 { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
386 8, STATS_FLAGS_PORT, "tx_carrier_errors" },
387 { STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
388 8, STATS_FLAGS_PORT, "tx_single_collisions" },
389 { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
390 8, STATS_FLAGS_PORT, "tx_multi_collisions" },
391 { STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
392 8, STATS_FLAGS_PORT, "tx_deferred" },
393 { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
394 8, STATS_FLAGS_PORT, "tx_excess_collisions" },
395 { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
396 8, STATS_FLAGS_PORT, "tx_late_collisions" },
397 { STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
398 8, STATS_FLAGS_PORT, "tx_total_collisions" },
399 { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
400 8, STATS_FLAGS_PORT, "tx_64_byte_packets" },
401 { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
402 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" },
403 { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
404 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" },
405 { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
406 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" },
407 { STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
408 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" },
409 { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
410 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" },
411 { STATS_OFFSET32(etherstatspktsover1522octets_hi),
412 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" },
413 { STATS_OFFSET32(pause_frames_sent_hi),
414 8, STATS_FLAGS_PORT, "tx_pause_frames" },
415 { STATS_OFFSET32(total_tpa_aggregations_hi),
416 8, STATS_FLAGS_FUNC, "tpa_aggregations" },
417 { STATS_OFFSET32(total_tpa_aggregated_frames_hi),
418 8, STATS_FLAGS_FUNC, "tpa_aggregated_frames"},
419 { STATS_OFFSET32(total_tpa_bytes_hi),
420 8, STATS_FLAGS_FUNC, "tpa_bytes"},
421 { STATS_OFFSET32(eee_tx_lpi),
422 4, STATS_FLAGS_PORT, "eee_tx_lpi"},
423 { STATS_OFFSET32(rx_calls),
424 4, STATS_FLAGS_FUNC, "rx_calls"},
425 { STATS_OFFSET32(rx_pkts),
426 4, STATS_FLAGS_FUNC, "rx_pkts"},
427 { STATS_OFFSET32(rx_tpa_pkts),
428 4, STATS_FLAGS_FUNC, "rx_tpa_pkts"},
429 { STATS_OFFSET32(rx_erroneous_jumbo_sge_pkts),
430 4, STATS_FLAGS_FUNC, "rx_erroneous_jumbo_sge_pkts"},
431 { STATS_OFFSET32(rx_bxe_service_rxsgl),
432 4, STATS_FLAGS_FUNC, "rx_bxe_service_rxsgl"},
433 { STATS_OFFSET32(rx_jumbo_sge_pkts),
434 4, STATS_FLAGS_FUNC, "rx_jumbo_sge_pkts"},
435 { STATS_OFFSET32(rx_soft_errors),
436 4, STATS_FLAGS_FUNC, "rx_soft_errors"},
437 { STATS_OFFSET32(rx_hw_csum_errors),
438 4, STATS_FLAGS_FUNC, "rx_hw_csum_errors"},
439 { STATS_OFFSET32(rx_ofld_frames_csum_ip),
440 4, STATS_FLAGS_FUNC, "rx_ofld_frames_csum_ip"},
441 { STATS_OFFSET32(rx_ofld_frames_csum_tcp_udp),
442 4, STATS_FLAGS_FUNC, "rx_ofld_frames_csum_tcp_udp"},
443 { STATS_OFFSET32(rx_budget_reached),
444 4, STATS_FLAGS_FUNC, "rx_budget_reached"},
445 { STATS_OFFSET32(tx_pkts),
446 4, STATS_FLAGS_FUNC, "tx_pkts"},
447 { STATS_OFFSET32(tx_soft_errors),
448 4, STATS_FLAGS_FUNC, "tx_soft_errors"},
449 { STATS_OFFSET32(tx_ofld_frames_csum_ip),
450 4, STATS_FLAGS_FUNC, "tx_ofld_frames_csum_ip"},
451 { STATS_OFFSET32(tx_ofld_frames_csum_tcp),
452 4, STATS_FLAGS_FUNC, "tx_ofld_frames_csum_tcp"},
453 { STATS_OFFSET32(tx_ofld_frames_csum_udp),
454 4, STATS_FLAGS_FUNC, "tx_ofld_frames_csum_udp"},
455 { STATS_OFFSET32(tx_ofld_frames_lso),
456 4, STATS_FLAGS_FUNC, "tx_ofld_frames_lso"},
457 { STATS_OFFSET32(tx_ofld_frames_lso_hdr_splits),
458 4, STATS_FLAGS_FUNC, "tx_ofld_frames_lso_hdr_splits"},
459 { STATS_OFFSET32(tx_encap_failures),
460 4, STATS_FLAGS_FUNC, "tx_encap_failures"},
461 { STATS_OFFSET32(tx_hw_queue_full),
462 4, STATS_FLAGS_FUNC, "tx_hw_queue_full"},
463 { STATS_OFFSET32(tx_hw_max_queue_depth),
464 4, STATS_FLAGS_FUNC, "tx_hw_max_queue_depth"},
465 { STATS_OFFSET32(tx_dma_mapping_failure),
466 4, STATS_FLAGS_FUNC, "tx_dma_mapping_failure"},
467 { STATS_OFFSET32(tx_max_drbr_queue_depth),
468 4, STATS_FLAGS_FUNC, "tx_max_drbr_queue_depth"},
469 { STATS_OFFSET32(tx_window_violation_std),
470 4, STATS_FLAGS_FUNC, "tx_window_violation_std"},
471 { STATS_OFFSET32(tx_window_violation_tso),
472 4, STATS_FLAGS_FUNC, "tx_window_violation_tso"},
473 { STATS_OFFSET32(tx_chain_lost_mbuf),
474 4, STATS_FLAGS_FUNC, "tx_chain_lost_mbuf"},
475 { STATS_OFFSET32(tx_frames_deferred),
476 4, STATS_FLAGS_FUNC, "tx_frames_deferred"},
477 { STATS_OFFSET32(tx_queue_xoff),
478 4, STATS_FLAGS_FUNC, "tx_queue_xoff"},
479 { STATS_OFFSET32(mbuf_defrag_attempts),
480 4, STATS_FLAGS_FUNC, "mbuf_defrag_attempts"},
481 { STATS_OFFSET32(mbuf_defrag_failures),
482 4, STATS_FLAGS_FUNC, "mbuf_defrag_failures"},
483 { STATS_OFFSET32(mbuf_rx_bd_alloc_failed),
484 4, STATS_FLAGS_FUNC, "mbuf_rx_bd_alloc_failed"},
485 { STATS_OFFSET32(mbuf_rx_bd_mapping_failed),
486 4, STATS_FLAGS_FUNC, "mbuf_rx_bd_mapping_failed"},
487 { STATS_OFFSET32(mbuf_rx_tpa_alloc_failed),
488 4, STATS_FLAGS_FUNC, "mbuf_rx_tpa_alloc_failed"},
489 { STATS_OFFSET32(mbuf_rx_tpa_mapping_failed),
490 4, STATS_FLAGS_FUNC, "mbuf_rx_tpa_mapping_failed"},
491 { STATS_OFFSET32(mbuf_rx_sge_alloc_failed),
492 4, STATS_FLAGS_FUNC, "mbuf_rx_sge_alloc_failed"},
493 { STATS_OFFSET32(mbuf_rx_sge_mapping_failed),
494 4, STATS_FLAGS_FUNC, "mbuf_rx_sge_mapping_failed"},
495 { STATS_OFFSET32(mbuf_alloc_tx),
496 4, STATS_FLAGS_FUNC, "mbuf_alloc_tx"},
497 { STATS_OFFSET32(mbuf_alloc_rx),
498 4, STATS_FLAGS_FUNC, "mbuf_alloc_rx"},
499 { STATS_OFFSET32(mbuf_alloc_sge),
500 4, STATS_FLAGS_FUNC, "mbuf_alloc_sge"},
501 { STATS_OFFSET32(mbuf_alloc_tpa),
502 4, STATS_FLAGS_FUNC, "mbuf_alloc_tpa"},
503 { STATS_OFFSET32(tx_queue_full_return),
504 4, STATS_FLAGS_FUNC, "tx_queue_full_return"},
505 { STATS_OFFSET32(bxe_tx_mq_sc_state_failures),
506 4, STATS_FLAGS_FUNC, "bxe_tx_mq_sc_state_failures"},
507 { STATS_OFFSET32(tx_request_link_down_failures),
508 4, STATS_FLAGS_FUNC, "tx_request_link_down_failures"},
509 { STATS_OFFSET32(bd_avail_too_less_failures),
510 4, STATS_FLAGS_FUNC, "bd_avail_too_less_failures"},
511 { STATS_OFFSET32(tx_mq_not_empty),
512 4, STATS_FLAGS_FUNC, "tx_mq_not_empty"},
513 { STATS_OFFSET32(nsegs_path1_errors),
514 4, STATS_FLAGS_FUNC, "nsegs_path1_errors"},
515 { STATS_OFFSET32(nsegs_path2_errors),
516 4, STATS_FLAGS_FUNC, "nsegs_path2_errors"}
521 static const struct {
524 char string[STAT_NAME_LEN];
525 } bxe_eth_q_stats_arr[] = {
526 { Q_STATS_OFFSET32(total_bytes_received_hi),
528 { Q_STATS_OFFSET32(total_unicast_packets_received_hi),
529 8, "rx_ucast_packets" },
530 { Q_STATS_OFFSET32(total_multicast_packets_received_hi),
531 8, "rx_mcast_packets" },
532 { Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
533 8, "rx_bcast_packets" },
534 { Q_STATS_OFFSET32(no_buff_discard_hi),
536 { Q_STATS_OFFSET32(total_bytes_transmitted_hi),
538 { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
539 8, "tx_ucast_packets" },
540 { Q_STATS_OFFSET32(total_multicast_packets_transmitted_hi),
541 8, "tx_mcast_packets" },
542 { Q_STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
543 8, "tx_bcast_packets" },
544 { Q_STATS_OFFSET32(total_tpa_aggregations_hi),
545 8, "tpa_aggregations" },
546 { Q_STATS_OFFSET32(total_tpa_aggregated_frames_hi),
547 8, "tpa_aggregated_frames"},
548 { Q_STATS_OFFSET32(total_tpa_bytes_hi),
550 { Q_STATS_OFFSET32(rx_calls),
552 { Q_STATS_OFFSET32(rx_pkts),
554 { Q_STATS_OFFSET32(rx_tpa_pkts),
556 { Q_STATS_OFFSET32(rx_erroneous_jumbo_sge_pkts),
557 4, "rx_erroneous_jumbo_sge_pkts"},
558 { Q_STATS_OFFSET32(rx_bxe_service_rxsgl),
559 4, "rx_bxe_service_rxsgl"},
560 { Q_STATS_OFFSET32(rx_jumbo_sge_pkts),
561 4, "rx_jumbo_sge_pkts"},
562 { Q_STATS_OFFSET32(rx_soft_errors),
563 4, "rx_soft_errors"},
564 { Q_STATS_OFFSET32(rx_hw_csum_errors),
565 4, "rx_hw_csum_errors"},
566 { Q_STATS_OFFSET32(rx_ofld_frames_csum_ip),
567 4, "rx_ofld_frames_csum_ip"},
568 { Q_STATS_OFFSET32(rx_ofld_frames_csum_tcp_udp),
569 4, "rx_ofld_frames_csum_tcp_udp"},
570 { Q_STATS_OFFSET32(rx_budget_reached),
571 4, "rx_budget_reached"},
572 { Q_STATS_OFFSET32(tx_pkts),
574 { Q_STATS_OFFSET32(tx_soft_errors),
575 4, "tx_soft_errors"},
576 { Q_STATS_OFFSET32(tx_ofld_frames_csum_ip),
577 4, "tx_ofld_frames_csum_ip"},
578 { Q_STATS_OFFSET32(tx_ofld_frames_csum_tcp),
579 4, "tx_ofld_frames_csum_tcp"},
580 { Q_STATS_OFFSET32(tx_ofld_frames_csum_udp),
581 4, "tx_ofld_frames_csum_udp"},
582 { Q_STATS_OFFSET32(tx_ofld_frames_lso),
583 4, "tx_ofld_frames_lso"},
584 { Q_STATS_OFFSET32(tx_ofld_frames_lso_hdr_splits),
585 4, "tx_ofld_frames_lso_hdr_splits"},
586 { Q_STATS_OFFSET32(tx_encap_failures),
587 4, "tx_encap_failures"},
588 { Q_STATS_OFFSET32(tx_hw_queue_full),
589 4, "tx_hw_queue_full"},
590 { Q_STATS_OFFSET32(tx_hw_max_queue_depth),
591 4, "tx_hw_max_queue_depth"},
592 { Q_STATS_OFFSET32(tx_dma_mapping_failure),
593 4, "tx_dma_mapping_failure"},
594 { Q_STATS_OFFSET32(tx_max_drbr_queue_depth),
595 4, "tx_max_drbr_queue_depth"},
596 { Q_STATS_OFFSET32(tx_window_violation_std),
597 4, "tx_window_violation_std"},
598 { Q_STATS_OFFSET32(tx_window_violation_tso),
599 4, "tx_window_violation_tso"},
600 { Q_STATS_OFFSET32(tx_chain_lost_mbuf),
601 4, "tx_chain_lost_mbuf"},
602 { Q_STATS_OFFSET32(tx_frames_deferred),
603 4, "tx_frames_deferred"},
604 { Q_STATS_OFFSET32(tx_queue_xoff),
606 { Q_STATS_OFFSET32(mbuf_defrag_attempts),
607 4, "mbuf_defrag_attempts"},
608 { Q_STATS_OFFSET32(mbuf_defrag_failures),
609 4, "mbuf_defrag_failures"},
610 { Q_STATS_OFFSET32(mbuf_rx_bd_alloc_failed),
611 4, "mbuf_rx_bd_alloc_failed"},
612 { Q_STATS_OFFSET32(mbuf_rx_bd_mapping_failed),
613 4, "mbuf_rx_bd_mapping_failed"},
614 { Q_STATS_OFFSET32(mbuf_rx_tpa_alloc_failed),
615 4, "mbuf_rx_tpa_alloc_failed"},
616 { Q_STATS_OFFSET32(mbuf_rx_tpa_mapping_failed),
617 4, "mbuf_rx_tpa_mapping_failed"},
618 { Q_STATS_OFFSET32(mbuf_rx_sge_alloc_failed),
619 4, "mbuf_rx_sge_alloc_failed"},
620 { Q_STATS_OFFSET32(mbuf_rx_sge_mapping_failed),
621 4, "mbuf_rx_sge_mapping_failed"},
622 { Q_STATS_OFFSET32(mbuf_alloc_tx),
624 { Q_STATS_OFFSET32(mbuf_alloc_rx),
626 { Q_STATS_OFFSET32(mbuf_alloc_sge),
627 4, "mbuf_alloc_sge"},
628 { Q_STATS_OFFSET32(mbuf_alloc_tpa),
629 4, "mbuf_alloc_tpa"},
630 { Q_STATS_OFFSET32(tx_queue_full_return),
631 4, "tx_queue_full_return"},
632 { Q_STATS_OFFSET32(bxe_tx_mq_sc_state_failures),
633 4, "bxe_tx_mq_sc_state_failures"},
634 { Q_STATS_OFFSET32(tx_request_link_down_failures),
635 4, "tx_request_link_down_failures"},
636 { Q_STATS_OFFSET32(bd_avail_too_less_failures),
637 4, "bd_avail_too_less_failures"},
638 { Q_STATS_OFFSET32(tx_mq_not_empty),
639 4, "tx_mq_not_empty"},
640 { Q_STATS_OFFSET32(nsegs_path1_errors),
641 4, "nsegs_path1_errors"},
642 { Q_STATS_OFFSET32(nsegs_path2_errors),
643 4, "nsegs_path2_errors"}
648 #define BXE_NUM_ETH_STATS ARRAY_SIZE(bxe_eth_stats_arr)
649 #define BXE_NUM_ETH_Q_STATS ARRAY_SIZE(bxe_eth_q_stats_arr)
652 static void bxe_cmng_fns_init(struct bxe_softc *sc,
655 static int bxe_get_cmng_fns_mode(struct bxe_softc *sc);
656 static void storm_memset_cmng(struct bxe_softc *sc,
657 struct cmng_init *cmng,
659 static void bxe_set_reset_global(struct bxe_softc *sc);
660 static void bxe_set_reset_in_progress(struct bxe_softc *sc);
661 static uint8_t bxe_reset_is_done(struct bxe_softc *sc,
663 static uint8_t bxe_clear_pf_load(struct bxe_softc *sc);
664 static uint8_t bxe_chk_parity_attn(struct bxe_softc *sc,
667 static void bxe_int_disable(struct bxe_softc *sc);
668 static int bxe_release_leader_lock(struct bxe_softc *sc);
669 static void bxe_pf_disable(struct bxe_softc *sc);
670 static void bxe_free_fp_buffers(struct bxe_softc *sc);
671 static inline void bxe_update_rx_prod(struct bxe_softc *sc,
672 struct bxe_fastpath *fp,
675 uint16_t rx_sge_prod);
676 static void bxe_link_report_locked(struct bxe_softc *sc);
677 static void bxe_link_report(struct bxe_softc *sc);
678 static void bxe_link_status_update(struct bxe_softc *sc);
679 static void bxe_periodic_callout_func(void *xsc);
680 static void bxe_periodic_start(struct bxe_softc *sc);
681 static void bxe_periodic_stop(struct bxe_softc *sc);
682 static int bxe_alloc_rx_bd_mbuf(struct bxe_fastpath *fp,
685 static int bxe_alloc_rx_tpa_mbuf(struct bxe_fastpath *fp,
687 static int bxe_alloc_rx_sge_mbuf(struct bxe_fastpath *fp,
689 static uint8_t bxe_txeof(struct bxe_softc *sc,
690 struct bxe_fastpath *fp);
691 static void bxe_task_fp(struct bxe_fastpath *fp);
692 static __noinline void bxe_dump_mbuf(struct bxe_softc *sc,
695 static int bxe_alloc_mem(struct bxe_softc *sc);
696 static void bxe_free_mem(struct bxe_softc *sc);
697 static int bxe_alloc_fw_stats_mem(struct bxe_softc *sc);
698 static void bxe_free_fw_stats_mem(struct bxe_softc *sc);
699 static int bxe_interrupt_attach(struct bxe_softc *sc);
700 static void bxe_interrupt_detach(struct bxe_softc *sc);
701 static void bxe_set_rx_mode(struct bxe_softc *sc);
702 static int bxe_init_locked(struct bxe_softc *sc);
703 static int bxe_stop_locked(struct bxe_softc *sc);
704 static void bxe_sp_err_timeout_task(void *arg, int pending);
705 void bxe_parity_recover(struct bxe_softc *sc);
706 void bxe_handle_error(struct bxe_softc *sc);
707 static __noinline int bxe_nic_load(struct bxe_softc *sc,
709 static __noinline int bxe_nic_unload(struct bxe_softc *sc,
710 uint32_t unload_mode,
713 static void bxe_handle_sp_tq(void *context, int pending);
714 static void bxe_handle_fp_tq(void *context, int pending);
716 static int bxe_add_cdev(struct bxe_softc *sc);
717 static void bxe_del_cdev(struct bxe_softc *sc);
718 int bxe_grc_dump(struct bxe_softc *sc);
719 static int bxe_alloc_buf_rings(struct bxe_softc *sc);
720 static void bxe_free_buf_rings(struct bxe_softc *sc);
722 /* calculate crc32 on a buffer (NOTE: crc32_length MUST be aligned to 8) */
724 calc_crc32(uint8_t *crc32_packet,
725 uint32_t crc32_length,
734 uint8_t current_byte = 0;
735 uint32_t crc32_result = crc32_seed;
736 const uint32_t CRC32_POLY = 0x1edc6f41;
738 if ((crc32_packet == NULL) ||
739 (crc32_length == 0) ||
740 ((crc32_length % 8) != 0))
742 return (crc32_result);
745 for (byte = 0; byte < crc32_length; byte = byte + 1)
747 current_byte = crc32_packet[byte];
748 for (bit = 0; bit < 8; bit = bit + 1)
750 /* msb = crc32_result[31]; */
751 msb = (uint8_t)(crc32_result >> 31);
753 crc32_result = crc32_result << 1;
755 /* it (msb != current_byte[bit]) */
756 if (msb != (0x1 & (current_byte >> bit)))
758 crc32_result = crc32_result ^ CRC32_POLY;
759 /* crc32_result[0] = 1 */
766 * 1. "mirror" every bit
767 * 2. swap the 4 bytes
768 * 3. complement each bit
773 shft = sizeof(crc32_result) * 8 - 1;
775 for (crc32_result >>= 1; crc32_result; crc32_result >>= 1)
778 temp |= crc32_result & 1;
782 /* temp[31-bit] = crc32_result[bit] */
786 /* crc32_result = {temp[7:0], temp[15:8], temp[23:16], temp[31:24]} */
788 uint32_t t0, t1, t2, t3;
789 t0 = (0x000000ff & (temp >> 24));
790 t1 = (0x0000ff00 & (temp >> 8));
791 t2 = (0x00ff0000 & (temp << 8));
792 t3 = (0xff000000 & (temp << 24));
793 crc32_result = t0 | t1 | t2 | t3;
799 crc32_result = ~crc32_result;
802 return (crc32_result);
807 volatile unsigned long *addr)
809 return ((atomic_load_acq_long(addr) & (1 << nr)) != 0);
813 bxe_set_bit(unsigned int nr,
814 volatile unsigned long *addr)
816 atomic_set_acq_long(addr, (1 << nr));
820 bxe_clear_bit(int nr,
821 volatile unsigned long *addr)
823 atomic_clear_acq_long(addr, (1 << nr));
827 bxe_test_and_set_bit(int nr,
828 volatile unsigned long *addr)
834 } while (atomic_cmpset_acq_long(addr, x, x | nr) == 0);
835 // if (x & nr) bit_was_set; else bit_was_not_set;
840 bxe_test_and_clear_bit(int nr,
841 volatile unsigned long *addr)
847 } while (atomic_cmpset_acq_long(addr, x, x & ~nr) == 0);
848 // if (x & nr) bit_was_set; else bit_was_not_set;
853 bxe_cmpxchg(volatile int *addr,
860 } while (atomic_cmpset_acq_int(addr, old, new) == 0);
865 * Get DMA memory from the OS.
867 * Validates that the OS has provided DMA buffers in response to a
868 * bus_dmamap_load call and saves the physical address of those buffers.
869 * When the callback is used the OS will return 0 for the mapping function
870 * (bus_dmamap_load) so we use the value of map_arg->maxsegs to pass any
871 * failures back to the caller.
877 bxe_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
879 struct bxe_dma *dma = arg;
884 BLOGE(dma->sc, "Failed DMA alloc '%s' (%d)!\n", dma->msg, error);
886 dma->paddr = segs->ds_addr;
892 * Allocate a block of memory and map it for DMA. No partial completions
893 * allowed and release any resources acquired if we can't acquire all
897 * 0 = Success, !0 = Failure
900 bxe_dma_alloc(struct bxe_softc *sc,
908 BLOGE(sc, "dma block '%s' already has size %lu\n", msg,
909 (unsigned long)dma->size);
913 memset(dma, 0, sizeof(*dma)); /* sanity */
916 snprintf(dma->msg, sizeof(dma->msg), "%s", msg);
918 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */
919 BCM_PAGE_SIZE, /* alignment */
920 0, /* boundary limit */
921 BUS_SPACE_MAXADDR, /* restricted low */
922 BUS_SPACE_MAXADDR, /* restricted hi */
923 NULL, /* addr filter() */
924 NULL, /* addr filter() arg */
925 size, /* max map size */
926 1, /* num discontinuous */
927 size, /* max seg size */
928 BUS_DMA_ALLOCNOW, /* flags */
930 NULL, /* lock() arg */
931 &dma->tag); /* returned dma tag */
933 BLOGE(sc, "Failed to create dma tag for '%s' (%d)\n", msg, rc);
934 memset(dma, 0, sizeof(*dma));
938 rc = bus_dmamem_alloc(dma->tag,
939 (void **)&dma->vaddr,
940 (BUS_DMA_NOWAIT | BUS_DMA_ZERO),
943 BLOGE(sc, "Failed to alloc dma mem for '%s' (%d)\n", msg, rc);
944 bus_dma_tag_destroy(dma->tag);
945 memset(dma, 0, sizeof(*dma));
949 rc = bus_dmamap_load(dma->tag,
953 bxe_dma_map_addr, /* BLOGD in here */
957 BLOGE(sc, "Failed to load dma map for '%s' (%d)\n", msg, rc);
958 bus_dmamem_free(dma->tag, dma->vaddr, dma->map);
959 bus_dma_tag_destroy(dma->tag);
960 memset(dma, 0, sizeof(*dma));
968 bxe_dma_free(struct bxe_softc *sc,
972 DBASSERT(sc, (dma->tag != NULL), ("dma tag is NULL"));
974 bus_dmamap_sync(dma->tag, dma->map,
975 (BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE));
976 bus_dmamap_unload(dma->tag, dma->map);
977 bus_dmamem_free(dma->tag, dma->vaddr, dma->map);
978 bus_dma_tag_destroy(dma->tag);
981 memset(dma, 0, sizeof(*dma));
985 * These indirect read and write routines are only during init.
986 * The locking is handled by the MCP.
990 bxe_reg_wr_ind(struct bxe_softc *sc,
994 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, addr, 4);
995 pci_write_config(sc->dev, PCICFG_GRC_DATA, val, 4);
996 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, 0, 4);
1000 bxe_reg_rd_ind(struct bxe_softc *sc,
1005 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, addr, 4);
1006 val = pci_read_config(sc->dev, PCICFG_GRC_DATA, 4);
1007 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, 0, 4);
1013 bxe_acquire_hw_lock(struct bxe_softc *sc,
1016 uint32_t lock_status;
1017 uint32_t resource_bit = (1 << resource);
1018 int func = SC_FUNC(sc);
1019 uint32_t hw_lock_control_reg;
1022 /* validate the resource is within range */
1023 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1024 BLOGE(sc, "(resource 0x%x > HW_LOCK_MAX_RESOURCE_VALUE)"
1025 " resource_bit 0x%x\n", resource, resource_bit);
1030 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + (func * 8));
1032 hw_lock_control_reg =
1033 (MISC_REG_DRIVER_CONTROL_7 + ((func - 6) * 8));
1036 /* validate the resource is not already taken */
1037 lock_status = REG_RD(sc, hw_lock_control_reg);
1038 if (lock_status & resource_bit) {
1039 BLOGE(sc, "resource (0x%x) in use (status 0x%x bit 0x%x)\n",
1040 resource, lock_status, resource_bit);
1044 /* try every 5ms for 5 seconds */
1045 for (cnt = 0; cnt < 1000; cnt++) {
1046 REG_WR(sc, (hw_lock_control_reg + 4), resource_bit);
1047 lock_status = REG_RD(sc, hw_lock_control_reg);
1048 if (lock_status & resource_bit) {
1054 BLOGE(sc, "Resource 0x%x resource_bit 0x%x lock timeout!\n",
1055 resource, resource_bit);
1060 bxe_release_hw_lock(struct bxe_softc *sc,
1063 uint32_t lock_status;
1064 uint32_t resource_bit = (1 << resource);
1065 int func = SC_FUNC(sc);
1066 uint32_t hw_lock_control_reg;
1068 /* validate the resource is within range */
1069 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1070 BLOGE(sc, "(resource 0x%x > HW_LOCK_MAX_RESOURCE_VALUE)"
1071 " resource_bit 0x%x\n", resource, resource_bit);
1076 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + (func * 8));
1078 hw_lock_control_reg =
1079 (MISC_REG_DRIVER_CONTROL_7 + ((func - 6) * 8));
1082 /* validate the resource is currently taken */
1083 lock_status = REG_RD(sc, hw_lock_control_reg);
1084 if (!(lock_status & resource_bit)) {
1085 BLOGE(sc, "resource (0x%x) not in use (status 0x%x bit 0x%x)\n",
1086 resource, lock_status, resource_bit);
1090 REG_WR(sc, hw_lock_control_reg, resource_bit);
1093 static void bxe_acquire_phy_lock(struct bxe_softc *sc)
1096 bxe_acquire_hw_lock(sc,HW_LOCK_RESOURCE_MDIO);
1099 static void bxe_release_phy_lock(struct bxe_softc *sc)
1101 bxe_release_hw_lock(sc,HW_LOCK_RESOURCE_MDIO);
1105 * Per pf misc lock must be acquired before the per port mcp lock. Otherwise,
1106 * had we done things the other way around, if two pfs from the same port
1107 * would attempt to access nvram at the same time, we could run into a
1109 * pf A takes the port lock.
1110 * pf B succeeds in taking the same lock since they are from the same port.
1111 * pf A takes the per pf misc lock. Performs eeprom access.
1112 * pf A finishes. Unlocks the per pf misc lock.
1113 * Pf B takes the lock and proceeds to perform it's own access.
1114 * pf A unlocks the per port lock, while pf B is still working (!).
1115 * mcp takes the per port lock and corrupts pf B's access (and/or has it's own
1116 * access corrupted by pf B).*
1119 bxe_acquire_nvram_lock(struct bxe_softc *sc)
1121 int port = SC_PORT(sc);
1125 /* acquire HW lock: protect against other PFs in PF Direct Assignment */
1126 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_NVRAM);
1128 /* adjust timeout for emulation/FPGA */
1129 count = NVRAM_TIMEOUT_COUNT;
1130 if (CHIP_REV_IS_SLOW(sc)) {
1134 /* request access to nvram interface */
1135 REG_WR(sc, MCP_REG_MCPR_NVM_SW_ARB,
1136 (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << 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 get access to nvram interface "
1149 "port %d val 0x%x (MCPR_NVM_SW_ARB_ARB_ARB1 << port)\n",
1158 bxe_release_nvram_lock(struct bxe_softc *sc)
1160 int port = SC_PORT(sc);
1164 /* adjust timeout for emulation/FPGA */
1165 count = NVRAM_TIMEOUT_COUNT;
1166 if (CHIP_REV_IS_SLOW(sc)) {
1170 /* relinquish nvram interface */
1171 REG_WR(sc, MCP_REG_MCPR_NVM_SW_ARB,
1172 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port));
1174 for (i = 0; i < count*10; i++) {
1175 val = REG_RD(sc, MCP_REG_MCPR_NVM_SW_ARB);
1176 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
1183 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
1184 BLOGE(sc, "Cannot free access to nvram interface "
1185 "port %d val 0x%x (MCPR_NVM_SW_ARB_ARB_ARB1 << port)\n",
1190 /* release HW lock: protect against other PFs in PF Direct Assignment */
1191 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_NVRAM);
1197 bxe_enable_nvram_access(struct bxe_softc *sc)
1201 val = REG_RD(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
1203 /* enable both bits, even on read */
1204 REG_WR(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
1205 (val | MCPR_NVM_ACCESS_ENABLE_EN | MCPR_NVM_ACCESS_ENABLE_WR_EN));
1209 bxe_disable_nvram_access(struct bxe_softc *sc)
1213 val = REG_RD(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
1215 /* disable both bits, even after read */
1216 REG_WR(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
1217 (val & ~(MCPR_NVM_ACCESS_ENABLE_EN |
1218 MCPR_NVM_ACCESS_ENABLE_WR_EN)));
1222 bxe_nvram_read_dword(struct bxe_softc *sc,
1230 /* build the command word */
1231 cmd_flags |= MCPR_NVM_COMMAND_DOIT;
1233 /* need to clear DONE bit separately */
1234 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
1236 /* address of the NVRAM to read from */
1237 REG_WR(sc, MCP_REG_MCPR_NVM_ADDR,
1238 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
1240 /* issue a read command */
1241 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
1243 /* adjust timeout for emulation/FPGA */
1244 count = NVRAM_TIMEOUT_COUNT;
1245 if (CHIP_REV_IS_SLOW(sc)) {
1249 /* wait for completion */
1252 for (i = 0; i < count; i++) {
1254 val = REG_RD(sc, MCP_REG_MCPR_NVM_COMMAND);
1256 if (val & MCPR_NVM_COMMAND_DONE) {
1257 val = REG_RD(sc, MCP_REG_MCPR_NVM_READ);
1258 /* we read nvram data in cpu order
1259 * but ethtool sees it as an array of bytes
1260 * converting to big-endian will do the work
1262 *ret_val = htobe32(val);
1269 BLOGE(sc, "nvram read timeout expired "
1270 "(offset 0x%x cmd_flags 0x%x val 0x%x)\n",
1271 offset, cmd_flags, val);
1278 bxe_nvram_read(struct bxe_softc *sc,
1287 if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
1288 BLOGE(sc, "Invalid parameter, offset 0x%x buf_size 0x%x\n",
1293 if ((offset + buf_size) > sc->devinfo.flash_size) {
1294 BLOGE(sc, "Invalid parameter, "
1295 "offset 0x%x + buf_size 0x%x > flash_size 0x%x\n",
1296 offset, buf_size, sc->devinfo.flash_size);
1300 /* request access to nvram interface */
1301 rc = bxe_acquire_nvram_lock(sc);
1306 /* enable access to nvram interface */
1307 bxe_enable_nvram_access(sc);
1309 /* read the first word(s) */
1310 cmd_flags = MCPR_NVM_COMMAND_FIRST;
1311 while ((buf_size > sizeof(uint32_t)) && (rc == 0)) {
1312 rc = bxe_nvram_read_dword(sc, offset, &val, cmd_flags);
1313 memcpy(ret_buf, &val, 4);
1315 /* advance to the next dword */
1316 offset += sizeof(uint32_t);
1317 ret_buf += sizeof(uint32_t);
1318 buf_size -= sizeof(uint32_t);
1323 cmd_flags |= MCPR_NVM_COMMAND_LAST;
1324 rc = bxe_nvram_read_dword(sc, offset, &val, cmd_flags);
1325 memcpy(ret_buf, &val, 4);
1328 /* disable access to nvram interface */
1329 bxe_disable_nvram_access(sc);
1330 bxe_release_nvram_lock(sc);
1336 bxe_nvram_write_dword(struct bxe_softc *sc,
1343 /* build the command word */
1344 cmd_flags |= (MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR);
1346 /* need to clear DONE bit separately */
1347 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
1349 /* write the data */
1350 REG_WR(sc, MCP_REG_MCPR_NVM_WRITE, val);
1352 /* address of the NVRAM to write to */
1353 REG_WR(sc, MCP_REG_MCPR_NVM_ADDR,
1354 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
1356 /* issue the write command */
1357 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
1359 /* adjust timeout for emulation/FPGA */
1360 count = NVRAM_TIMEOUT_COUNT;
1361 if (CHIP_REV_IS_SLOW(sc)) {
1365 /* wait for completion */
1367 for (i = 0; i < count; i++) {
1369 val = REG_RD(sc, MCP_REG_MCPR_NVM_COMMAND);
1370 if (val & MCPR_NVM_COMMAND_DONE) {
1377 BLOGE(sc, "nvram write timeout expired "
1378 "(offset 0x%x cmd_flags 0x%x val 0x%x)\n",
1379 offset, cmd_flags, val);
1385 #define BYTE_OFFSET(offset) (8 * (offset & 0x03))
1388 bxe_nvram_write1(struct bxe_softc *sc,
1394 uint32_t align_offset;
1398 if ((offset + buf_size) > sc->devinfo.flash_size) {
1399 BLOGE(sc, "Invalid parameter, "
1400 "offset 0x%x + buf_size 0x%x > flash_size 0x%x\n",
1401 offset, buf_size, sc->devinfo.flash_size);
1405 /* request access to nvram interface */
1406 rc = bxe_acquire_nvram_lock(sc);
1411 /* enable access to nvram interface */
1412 bxe_enable_nvram_access(sc);
1414 cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST);
1415 align_offset = (offset & ~0x03);
1416 rc = bxe_nvram_read_dword(sc, align_offset, &val, cmd_flags);
1419 val &= ~(0xff << BYTE_OFFSET(offset));
1420 val |= (*data_buf << BYTE_OFFSET(offset));
1422 /* nvram data is returned as an array of bytes
1423 * convert it back to cpu order
1427 rc = bxe_nvram_write_dword(sc, align_offset, val, cmd_flags);
1430 /* disable access to nvram interface */
1431 bxe_disable_nvram_access(sc);
1432 bxe_release_nvram_lock(sc);
1438 bxe_nvram_write(struct bxe_softc *sc,
1445 uint32_t written_so_far;
1448 if (buf_size == 1) {
1449 return (bxe_nvram_write1(sc, offset, data_buf, buf_size));
1452 if ((offset & 0x03) || (buf_size & 0x03) /* || (buf_size == 0) */) {
1453 BLOGE(sc, "Invalid parameter, offset 0x%x buf_size 0x%x\n",
1458 if (buf_size == 0) {
1459 return (0); /* nothing to do */
1462 if ((offset + buf_size) > sc->devinfo.flash_size) {
1463 BLOGE(sc, "Invalid parameter, "
1464 "offset 0x%x + buf_size 0x%x > flash_size 0x%x\n",
1465 offset, buf_size, sc->devinfo.flash_size);
1469 /* request access to nvram interface */
1470 rc = bxe_acquire_nvram_lock(sc);
1475 /* enable access to nvram interface */
1476 bxe_enable_nvram_access(sc);
1479 cmd_flags = MCPR_NVM_COMMAND_FIRST;
1480 while ((written_so_far < buf_size) && (rc == 0)) {
1481 if (written_so_far == (buf_size - sizeof(uint32_t))) {
1482 cmd_flags |= MCPR_NVM_COMMAND_LAST;
1483 } else if (((offset + 4) % NVRAM_PAGE_SIZE) == 0) {
1484 cmd_flags |= MCPR_NVM_COMMAND_LAST;
1485 } else if ((offset % NVRAM_PAGE_SIZE) == 0) {
1486 cmd_flags |= MCPR_NVM_COMMAND_FIRST;
1489 memcpy(&val, data_buf, 4);
1491 rc = bxe_nvram_write_dword(sc, offset, val, cmd_flags);
1493 /* advance to the next dword */
1494 offset += sizeof(uint32_t);
1495 data_buf += sizeof(uint32_t);
1496 written_so_far += sizeof(uint32_t);
1500 /* disable access to nvram interface */
1501 bxe_disable_nvram_access(sc);
1502 bxe_release_nvram_lock(sc);
1507 /* copy command into DMAE command memory and set DMAE command Go */
1509 bxe_post_dmae(struct bxe_softc *sc,
1510 struct dmae_cmd *dmae,
1513 uint32_t cmd_offset;
1516 cmd_offset = (DMAE_REG_CMD_MEM + (sizeof(struct dmae_cmd) * idx));
1517 for (i = 0; i < ((sizeof(struct dmae_cmd) / 4)); i++) {
1518 REG_WR(sc, (cmd_offset + (i * 4)), *(((uint32_t *)dmae) + i));
1521 REG_WR(sc, dmae_reg_go_c[idx], 1);
1525 bxe_dmae_opcode_add_comp(uint32_t opcode,
1528 return (opcode | ((comp_type << DMAE_CMD_C_DST_SHIFT) |
1529 DMAE_CMD_C_TYPE_ENABLE));
1533 bxe_dmae_opcode_clr_src_reset(uint32_t opcode)
1535 return (opcode & ~DMAE_CMD_SRC_RESET);
1539 bxe_dmae_opcode(struct bxe_softc *sc,
1545 uint32_t opcode = 0;
1547 opcode |= ((src_type << DMAE_CMD_SRC_SHIFT) |
1548 (dst_type << DMAE_CMD_DST_SHIFT));
1550 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
1552 opcode |= (SC_PORT(sc) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
1554 opcode |= ((SC_VN(sc) << DMAE_CMD_E1HVN_SHIFT) |
1555 (SC_VN(sc) << DMAE_CMD_DST_VN_SHIFT));
1557 opcode |= (DMAE_COM_SET_ERR << DMAE_CMD_ERR_POLICY_SHIFT);
1560 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
1562 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
1566 opcode = bxe_dmae_opcode_add_comp(opcode, comp_type);
1573 bxe_prep_dmae_with_comp(struct bxe_softc *sc,
1574 struct dmae_cmd *dmae,
1578 memset(dmae, 0, sizeof(struct dmae_cmd));
1580 /* set the opcode */
1581 dmae->opcode = bxe_dmae_opcode(sc, src_type, dst_type,
1582 TRUE, DMAE_COMP_PCI);
1584 /* fill in the completion parameters */
1585 dmae->comp_addr_lo = U64_LO(BXE_SP_MAPPING(sc, wb_comp));
1586 dmae->comp_addr_hi = U64_HI(BXE_SP_MAPPING(sc, wb_comp));
1587 dmae->comp_val = DMAE_COMP_VAL;
1590 /* issue a DMAE command over the init channel and wait for completion */
1592 bxe_issue_dmae_with_comp(struct bxe_softc *sc,
1593 struct dmae_cmd *dmae)
1595 uint32_t *wb_comp = BXE_SP(sc, wb_comp);
1596 int timeout = CHIP_REV_IS_SLOW(sc) ? 400000 : 4000;
1600 /* reset completion */
1603 /* post the command on the channel used for initializations */
1604 bxe_post_dmae(sc, dmae, INIT_DMAE_C(sc));
1606 /* wait for completion */
1609 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
1611 (sc->recovery_state != BXE_RECOVERY_DONE &&
1612 sc->recovery_state != BXE_RECOVERY_NIC_LOADING)) {
1613 BLOGE(sc, "DMAE timeout! *wb_comp 0x%x recovery_state 0x%x\n",
1614 *wb_comp, sc->recovery_state);
1615 BXE_DMAE_UNLOCK(sc);
1616 return (DMAE_TIMEOUT);
1623 if (*wb_comp & DMAE_PCI_ERR_FLAG) {
1624 BLOGE(sc, "DMAE PCI error! *wb_comp 0x%x recovery_state 0x%x\n",
1625 *wb_comp, sc->recovery_state);
1626 BXE_DMAE_UNLOCK(sc);
1627 return (DMAE_PCI_ERROR);
1630 BXE_DMAE_UNLOCK(sc);
1635 bxe_read_dmae(struct bxe_softc *sc,
1639 struct dmae_cmd dmae;
1643 DBASSERT(sc, (len32 <= 4), ("DMAE read length is %d", len32));
1645 if (!sc->dmae_ready) {
1646 data = BXE_SP(sc, wb_data[0]);
1648 for (i = 0; i < len32; i++) {
1649 data[i] = (CHIP_IS_E1(sc)) ?
1650 bxe_reg_rd_ind(sc, (src_addr + (i * 4))) :
1651 REG_RD(sc, (src_addr + (i * 4)));
1657 /* set opcode and fixed command fields */
1658 bxe_prep_dmae_with_comp(sc, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
1660 /* fill in addresses and len */
1661 dmae.src_addr_lo = (src_addr >> 2); /* GRC addr has dword resolution */
1662 dmae.src_addr_hi = 0;
1663 dmae.dst_addr_lo = U64_LO(BXE_SP_MAPPING(sc, wb_data));
1664 dmae.dst_addr_hi = U64_HI(BXE_SP_MAPPING(sc, wb_data));
1667 /* issue the command and wait for completion */
1668 if ((rc = bxe_issue_dmae_with_comp(sc, &dmae)) != 0) {
1669 bxe_panic(sc, ("DMAE failed (%d)\n", rc));
1674 bxe_write_dmae(struct bxe_softc *sc,
1675 bus_addr_t dma_addr,
1679 struct dmae_cmd dmae;
1682 if (!sc->dmae_ready) {
1683 DBASSERT(sc, (len32 <= 4), ("DMAE not ready and length is %d", len32));
1685 if (CHIP_IS_E1(sc)) {
1686 ecore_init_ind_wr(sc, dst_addr, BXE_SP(sc, wb_data[0]), len32);
1688 ecore_init_str_wr(sc, dst_addr, BXE_SP(sc, wb_data[0]), len32);
1694 /* set opcode and fixed command fields */
1695 bxe_prep_dmae_with_comp(sc, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
1697 /* fill in addresses and len */
1698 dmae.src_addr_lo = U64_LO(dma_addr);
1699 dmae.src_addr_hi = U64_HI(dma_addr);
1700 dmae.dst_addr_lo = (dst_addr >> 2); /* GRC addr has dword resolution */
1701 dmae.dst_addr_hi = 0;
1704 /* issue the command and wait for completion */
1705 if ((rc = bxe_issue_dmae_with_comp(sc, &dmae)) != 0) {
1706 bxe_panic(sc, ("DMAE failed (%d)\n", rc));
1711 bxe_write_dmae_phys_len(struct bxe_softc *sc,
1712 bus_addr_t phys_addr,
1716 int dmae_wr_max = DMAE_LEN32_WR_MAX(sc);
1719 while (len > dmae_wr_max) {
1721 (phys_addr + offset), /* src DMA address */
1722 (addr + offset), /* dst GRC address */
1724 offset += (dmae_wr_max * 4);
1729 (phys_addr + offset), /* src DMA address */
1730 (addr + offset), /* dst GRC address */
1735 bxe_set_ctx_validation(struct bxe_softc *sc,
1736 struct eth_context *cxt,
1739 /* ustorm cxt validation */
1740 cxt->ustorm_ag_context.cdu_usage =
1741 CDU_RSRVD_VALUE_TYPE_A(HW_CID(sc, cid),
1742 CDU_REGION_NUMBER_UCM_AG, ETH_CONNECTION_TYPE);
1743 /* xcontext validation */
1744 cxt->xstorm_ag_context.cdu_reserved =
1745 CDU_RSRVD_VALUE_TYPE_A(HW_CID(sc, cid),
1746 CDU_REGION_NUMBER_XCM_AG, ETH_CONNECTION_TYPE);
1750 bxe_storm_memset_hc_timeout(struct bxe_softc *sc,
1757 (BAR_CSTRORM_INTMEM +
1758 CSTORM_STATUS_BLOCK_DATA_TIMEOUT_OFFSET(fw_sb_id, sb_index));
1760 REG_WR8(sc, addr, ticks);
1763 "port %d fw_sb_id %d sb_index %d ticks %d\n",
1764 port, fw_sb_id, sb_index, ticks);
1768 bxe_storm_memset_hc_disable(struct bxe_softc *sc,
1774 uint32_t enable_flag =
1775 (disable) ? 0 : (1 << HC_INDEX_DATA_HC_ENABLED_SHIFT);
1777 (BAR_CSTRORM_INTMEM +
1778 CSTORM_STATUS_BLOCK_DATA_FLAGS_OFFSET(fw_sb_id, sb_index));
1782 flags = REG_RD8(sc, addr);
1783 flags &= ~HC_INDEX_DATA_HC_ENABLED;
1784 flags |= enable_flag;
1785 REG_WR8(sc, addr, flags);
1788 "port %d fw_sb_id %d sb_index %d disable %d\n",
1789 port, fw_sb_id, sb_index, disable);
1793 bxe_update_coalesce_sb_index(struct bxe_softc *sc,
1799 int port = SC_PORT(sc);
1800 uint8_t ticks = (usec / 4); /* XXX ??? */
1802 bxe_storm_memset_hc_timeout(sc, port, fw_sb_id, sb_index, ticks);
1804 disable = (disable) ? 1 : ((usec) ? 0 : 1);
1805 bxe_storm_memset_hc_disable(sc, port, fw_sb_id, sb_index, disable);
1809 elink_cb_udelay(struct bxe_softc *sc,
1816 elink_cb_reg_read(struct bxe_softc *sc,
1819 return (REG_RD(sc, reg_addr));
1823 elink_cb_reg_write(struct bxe_softc *sc,
1827 REG_WR(sc, reg_addr, val);
1831 elink_cb_reg_wb_write(struct bxe_softc *sc,
1836 REG_WR_DMAE(sc, offset, wb_write, len);
1840 elink_cb_reg_wb_read(struct bxe_softc *sc,
1845 REG_RD_DMAE(sc, offset, wb_write, len);
1849 elink_cb_path_id(struct bxe_softc *sc)
1851 return (SC_PATH(sc));
1855 elink_cb_event_log(struct bxe_softc *sc,
1856 const elink_log_id_t elink_log_id,
1860 BLOGI(sc, "ELINK EVENT LOG (%d)\n", elink_log_id);
1864 bxe_set_spio(struct bxe_softc *sc,
1870 /* Only 2 SPIOs are configurable */
1871 if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
1872 BLOGE(sc, "Invalid SPIO 0x%x mode 0x%x\n", spio, mode);
1876 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_SPIO);
1878 /* read SPIO and mask except the float bits */
1879 spio_reg = (REG_RD(sc, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
1882 case MISC_SPIO_OUTPUT_LOW:
1883 BLOGD(sc, DBG_LOAD, "Set SPIO 0x%x -> output low\n", spio);
1884 /* clear FLOAT and set CLR */
1885 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
1886 spio_reg |= (spio << MISC_SPIO_CLR_POS);
1889 case MISC_SPIO_OUTPUT_HIGH:
1890 BLOGD(sc, DBG_LOAD, "Set SPIO 0x%x -> output high\n", spio);
1891 /* clear FLOAT and set SET */
1892 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
1893 spio_reg |= (spio << MISC_SPIO_SET_POS);
1896 case MISC_SPIO_INPUT_HI_Z:
1897 BLOGD(sc, DBG_LOAD, "Set SPIO 0x%x -> input\n", spio);
1899 spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
1906 REG_WR(sc, MISC_REG_SPIO, spio_reg);
1907 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_SPIO);
1913 bxe_gpio_read(struct bxe_softc *sc,
1917 /* The GPIO should be swapped if swap register is set and active */
1918 int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) &&
1919 REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port);
1920 int gpio_shift = (gpio_num +
1921 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0));
1922 uint32_t gpio_mask = (1 << gpio_shift);
1925 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1926 BLOGE(sc, "Invalid GPIO %d port 0x%x gpio_port %d gpio_shift %d"
1927 " gpio_mask 0x%x\n", gpio_num, port, gpio_port, gpio_shift,
1932 /* read GPIO value */
1933 gpio_reg = REG_RD(sc, MISC_REG_GPIO);
1935 /* get the requested pin value */
1936 return ((gpio_reg & gpio_mask) == gpio_mask) ? 1 : 0;
1940 bxe_gpio_write(struct bxe_softc *sc,
1945 /* The GPIO should be swapped if swap register is set and active */
1946 int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) &&
1947 REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port);
1948 int gpio_shift = (gpio_num +
1949 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0));
1950 uint32_t gpio_mask = (1 << gpio_shift);
1953 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1954 BLOGE(sc, "Invalid GPIO %d mode 0x%x port 0x%x gpio_port %d"
1955 " gpio_shift %d gpio_mask 0x%x\n",
1956 gpio_num, mode, port, gpio_port, gpio_shift, gpio_mask);
1960 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
1962 /* read GPIO and mask except the float bits */
1963 gpio_reg = (REG_RD(sc, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
1966 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1968 "Set GPIO %d (shift %d) -> output low\n",
1969 gpio_num, gpio_shift);
1970 /* clear FLOAT and set CLR */
1971 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1972 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
1975 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1977 "Set GPIO %d (shift %d) -> output high\n",
1978 gpio_num, gpio_shift);
1979 /* clear FLOAT and set SET */
1980 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1981 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
1984 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
1986 "Set GPIO %d (shift %d) -> input\n",
1987 gpio_num, gpio_shift);
1989 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1996 REG_WR(sc, MISC_REG_GPIO, gpio_reg);
1997 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2003 bxe_gpio_mult_write(struct bxe_softc *sc,
2009 /* any port swapping should be handled by caller */
2011 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2013 /* read GPIO and mask except the float bits */
2014 gpio_reg = REG_RD(sc, MISC_REG_GPIO);
2015 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2016 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
2017 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
2020 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
2021 BLOGD(sc, DBG_PHY, "Set GPIO 0x%x -> output low\n", pins);
2023 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
2026 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
2027 BLOGD(sc, DBG_PHY, "Set GPIO 0x%x -> output high\n", pins);
2029 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
2032 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
2033 BLOGD(sc, DBG_PHY, "Set GPIO 0x%x -> input\n", pins);
2035 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2039 BLOGE(sc, "Invalid GPIO mode assignment pins 0x%x mode 0x%x"
2040 " gpio_reg 0x%x\n", pins, mode, gpio_reg);
2041 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2045 REG_WR(sc, MISC_REG_GPIO, gpio_reg);
2046 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2052 bxe_gpio_int_write(struct bxe_softc *sc,
2057 /* The GPIO should be swapped if swap register is set and active */
2058 int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) &&
2059 REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port);
2060 int gpio_shift = (gpio_num +
2061 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0));
2062 uint32_t gpio_mask = (1 << gpio_shift);
2065 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2066 BLOGE(sc, "Invalid GPIO %d mode 0x%x port 0x%x gpio_port %d"
2067 " gpio_shift %d gpio_mask 0x%x\n",
2068 gpio_num, mode, port, gpio_port, gpio_shift, gpio_mask);
2072 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2075 gpio_reg = REG_RD(sc, MISC_REG_GPIO_INT);
2078 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
2080 "Clear GPIO INT %d (shift %d) -> output low\n",
2081 gpio_num, gpio_shift);
2082 /* clear SET and set CLR */
2083 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2084 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2087 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
2089 "Set GPIO INT %d (shift %d) -> output high\n",
2090 gpio_num, gpio_shift);
2091 /* clear CLR and set SET */
2092 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2093 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2100 REG_WR(sc, MISC_REG_GPIO_INT, gpio_reg);
2101 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2107 elink_cb_gpio_read(struct bxe_softc *sc,
2111 return (bxe_gpio_read(sc, gpio_num, port));
2115 elink_cb_gpio_write(struct bxe_softc *sc,
2117 uint8_t mode, /* 0=low 1=high */
2120 return (bxe_gpio_write(sc, gpio_num, mode, port));
2124 elink_cb_gpio_mult_write(struct bxe_softc *sc,
2126 uint8_t mode) /* 0=low 1=high */
2128 return (bxe_gpio_mult_write(sc, pins, mode));
2132 elink_cb_gpio_int_write(struct bxe_softc *sc,
2134 uint8_t mode, /* 0=low 1=high */
2137 return (bxe_gpio_int_write(sc, gpio_num, mode, port));
2141 elink_cb_notify_link_changed(struct bxe_softc *sc)
2143 REG_WR(sc, (MISC_REG_AEU_GENERAL_ATTN_12 +
2144 (SC_FUNC(sc) * sizeof(uint32_t))), 1);
2147 /* send the MCP a request, block until there is a reply */
2149 elink_cb_fw_command(struct bxe_softc *sc,
2153 int mb_idx = SC_FW_MB_IDX(sc);
2157 uint8_t delay = CHIP_REV_IS_SLOW(sc) ? 100 : 10;
2162 SHMEM_WR(sc, func_mb[mb_idx].drv_mb_param, param);
2163 SHMEM_WR(sc, func_mb[mb_idx].drv_mb_header, (command | seq));
2166 "wrote command 0x%08x to FW MB param 0x%08x\n",
2167 (command | seq), param);
2169 /* Let the FW do it's magic. GIve it up to 5 seconds... */
2171 DELAY(delay * 1000);
2172 rc = SHMEM_RD(sc, func_mb[mb_idx].fw_mb_header);
2173 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
2176 "[after %d ms] read 0x%x seq 0x%x from FW MB\n",
2177 cnt*delay, rc, seq);
2179 /* is this a reply to our command? */
2180 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK)) {
2181 rc &= FW_MSG_CODE_MASK;
2184 BLOGE(sc, "FW failed to respond!\n");
2185 // XXX bxe_fw_dump(sc);
2189 BXE_FWMB_UNLOCK(sc);
2194 bxe_fw_command(struct bxe_softc *sc,
2198 return (elink_cb_fw_command(sc, command, param));
2202 __storm_memset_dma_mapping(struct bxe_softc *sc,
2206 REG_WR(sc, addr, U64_LO(mapping));
2207 REG_WR(sc, (addr + 4), U64_HI(mapping));
2211 storm_memset_spq_addr(struct bxe_softc *sc,
2215 uint32_t addr = (XSEM_REG_FAST_MEMORY +
2216 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid));
2217 __storm_memset_dma_mapping(sc, addr, mapping);
2221 storm_memset_vf_to_pf(struct bxe_softc *sc,
2225 REG_WR8(sc, (BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id);
2226 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id);
2227 REG_WR8(sc, (BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id);
2228 REG_WR8(sc, (BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id);
2232 storm_memset_func_en(struct bxe_softc *sc,
2236 REG_WR8(sc, (BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid)), enable);
2237 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid)), enable);
2238 REG_WR8(sc, (BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid)), enable);
2239 REG_WR8(sc, (BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid)), enable);
2243 storm_memset_eq_data(struct bxe_softc *sc,
2244 struct event_ring_data *eq_data,
2250 addr = (BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid));
2251 size = sizeof(struct event_ring_data);
2252 ecore_storm_memset_struct(sc, addr, size, (uint32_t *)eq_data);
2256 storm_memset_eq_prod(struct bxe_softc *sc,
2260 uint32_t addr = (BAR_CSTRORM_INTMEM +
2261 CSTORM_EVENT_RING_PROD_OFFSET(pfid));
2262 REG_WR16(sc, addr, eq_prod);
2266 * Post a slowpath command.
2268 * A slowpath command is used to propogate a configuration change through
2269 * the controller in a controlled manner, allowing each STORM processor and
2270 * other H/W blocks to phase in the change. The commands sent on the
2271 * slowpath are referred to as ramrods. Depending on the ramrod used the
2272 * completion of the ramrod will occur in different ways. Here's a
2273 * breakdown of ramrods and how they complete:
2275 * RAMROD_CMD_ID_ETH_PORT_SETUP
2276 * Used to setup the leading connection on a port. Completes on the
2277 * Receive Completion Queue (RCQ) of that port (typically fp[0]).
2279 * RAMROD_CMD_ID_ETH_CLIENT_SETUP
2280 * Used to setup an additional connection on a port. Completes on the
2281 * RCQ of the multi-queue/RSS connection being initialized.
2283 * RAMROD_CMD_ID_ETH_STAT_QUERY
2284 * Used to force the storm processors to update the statistics database
2285 * in host memory. This ramrod is send on the leading connection CID and
2286 * completes as an index increment of the CSTORM on the default status
2289 * RAMROD_CMD_ID_ETH_UPDATE
2290 * Used to update the state of the leading connection, usually to udpate
2291 * the RSS indirection table. Completes on the RCQ of the leading
2292 * connection. (Not currently used under FreeBSD until OS support becomes
2295 * RAMROD_CMD_ID_ETH_HALT
2296 * Used when tearing down a connection prior to driver unload. Completes
2297 * on the RCQ of the multi-queue/RSS connection being torn down. Don't
2298 * use this on the leading connection.
2300 * RAMROD_CMD_ID_ETH_SET_MAC
2301 * Sets the Unicast/Broadcast/Multicast used by the port. Completes on
2302 * the RCQ of the leading connection.
2304 * RAMROD_CMD_ID_ETH_CFC_DEL
2305 * Used when tearing down a conneciton prior to driver unload. Completes
2306 * on the RCQ of the leading connection (since the current connection
2307 * has been completely removed from controller memory).
2309 * RAMROD_CMD_ID_ETH_PORT_DEL
2310 * Used to tear down the leading connection prior to driver unload,
2311 * typically fp[0]. Completes as an index increment of the CSTORM on the
2312 * default status block.
2314 * RAMROD_CMD_ID_ETH_FORWARD_SETUP
2315 * Used for connection offload. Completes on the RCQ of the multi-queue
2316 * RSS connection that is being offloaded. (Not currently used under
2319 * There can only be one command pending per function.
2322 * 0 = Success, !0 = Failure.
2325 /* must be called under the spq lock */
2327 struct eth_spe *bxe_sp_get_next(struct bxe_softc *sc)
2329 struct eth_spe *next_spe = sc->spq_prod_bd;
2331 if (sc->spq_prod_bd == sc->spq_last_bd) {
2332 /* wrap back to the first eth_spq */
2333 sc->spq_prod_bd = sc->spq;
2334 sc->spq_prod_idx = 0;
2343 /* must be called under the spq lock */
2345 void bxe_sp_prod_update(struct bxe_softc *sc)
2347 int func = SC_FUNC(sc);
2350 * Make sure that BD data is updated before writing the producer.
2351 * BD data is written to the memory, the producer is read from the
2352 * memory, thus we need a full memory barrier to ensure the ordering.
2356 REG_WR16(sc, (BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func)),
2359 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle, 0, 0,
2360 BUS_SPACE_BARRIER_WRITE);
2364 * bxe_is_contextless_ramrod - check if the current command ends on EQ
2366 * @cmd: command to check
2367 * @cmd_type: command type
2370 int bxe_is_contextless_ramrod(int cmd,
2373 if ((cmd_type == NONE_CONNECTION_TYPE) ||
2374 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
2375 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
2376 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
2377 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
2378 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
2379 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE)) {
2387 * bxe_sp_post - place a single command on an SP ring
2389 * @sc: driver handle
2390 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
2391 * @cid: SW CID the command is related to
2392 * @data_hi: command private data address (high 32 bits)
2393 * @data_lo: command private data address (low 32 bits)
2394 * @cmd_type: command type (e.g. NONE, ETH)
2396 * SP data is handled as if it's always an address pair, thus data fields are
2397 * not swapped to little endian in upper functions. Instead this function swaps
2398 * data as if it's two uint32 fields.
2401 bxe_sp_post(struct bxe_softc *sc,
2408 struct eth_spe *spe;
2412 common = bxe_is_contextless_ramrod(command, cmd_type);
2417 if (!atomic_load_acq_long(&sc->eq_spq_left)) {
2418 BLOGE(sc, "EQ ring is full!\n");
2423 if (!atomic_load_acq_long(&sc->cq_spq_left)) {
2424 BLOGE(sc, "SPQ ring is full!\n");
2430 spe = bxe_sp_get_next(sc);
2432 /* CID needs port number to be encoded int it */
2433 spe->hdr.conn_and_cmd_data =
2434 htole32((command << SPE_HDR_T_CMD_ID_SHIFT) | HW_CID(sc, cid));
2436 type = (cmd_type << SPE_HDR_T_CONN_TYPE_SHIFT) & SPE_HDR_T_CONN_TYPE;
2438 /* TBD: Check if it works for VFs */
2439 type |= ((SC_FUNC(sc) << SPE_HDR_T_FUNCTION_ID_SHIFT) &
2440 SPE_HDR_T_FUNCTION_ID);
2442 spe->hdr.type = htole16(type);
2444 spe->data.update_data_addr.hi = htole32(data_hi);
2445 spe->data.update_data_addr.lo = htole32(data_lo);
2448 * It's ok if the actual decrement is issued towards the memory
2449 * somewhere between the lock and unlock. Thus no more explict
2450 * memory barrier is needed.
2453 atomic_subtract_acq_long(&sc->eq_spq_left, 1);
2455 atomic_subtract_acq_long(&sc->cq_spq_left, 1);
2458 BLOGD(sc, DBG_SP, "SPQE -> %#jx\n", (uintmax_t)sc->spq_dma.paddr);
2459 BLOGD(sc, DBG_SP, "FUNC_RDATA -> %p / %#jx\n",
2460 BXE_SP(sc, func_rdata), (uintmax_t)BXE_SP_MAPPING(sc, func_rdata));
2462 "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%lx,%lx)\n",
2464 (uint32_t)U64_HI(sc->spq_dma.paddr),
2465 (uint32_t)(U64_LO(sc->spq_dma.paddr) + (uint8_t *)sc->spq_prod_bd - (uint8_t *)sc->spq),
2472 atomic_load_acq_long(&sc->cq_spq_left),
2473 atomic_load_acq_long(&sc->eq_spq_left));
2475 bxe_sp_prod_update(sc);
2482 * bxe_debug_print_ind_table - prints the indirection table configuration.
2484 * @sc: driver hanlde
2485 * @p: pointer to rss configuration
2489 * FreeBSD Device probe function.
2491 * Compares the device found to the driver's list of supported devices and
2492 * reports back to the bsd loader whether this is the right driver for the device.
2493 * This is the driver entry function called from the "kldload" command.
2496 * BUS_PROBE_DEFAULT on success, positive value on failure.
2499 bxe_probe(device_t dev)
2501 struct bxe_softc *sc;
2502 struct bxe_device_type *t;
2504 uint16_t did, sdid, svid, vid;
2506 /* Find our device structure */
2507 sc = device_get_softc(dev);
2511 /* Get the data for the device to be probed. */
2512 vid = pci_get_vendor(dev);
2513 did = pci_get_device(dev);
2514 svid = pci_get_subvendor(dev);
2515 sdid = pci_get_subdevice(dev);
2518 "%s(); VID = 0x%04X, DID = 0x%04X, SVID = 0x%04X, "
2519 "SDID = 0x%04X\n", __FUNCTION__, vid, did, svid, sdid);
2521 /* Look through the list of known devices for a match. */
2522 while (t->bxe_name != NULL) {
2523 if ((vid == t->bxe_vid) && (did == t->bxe_did) &&
2524 ((svid == t->bxe_svid) || (t->bxe_svid == PCI_ANY_ID)) &&
2525 ((sdid == t->bxe_sdid) || (t->bxe_sdid == PCI_ANY_ID))) {
2526 descbuf = malloc(BXE_DEVDESC_MAX, M_TEMP, M_NOWAIT);
2527 if (descbuf == NULL)
2530 /* Print out the device identity. */
2531 snprintf(descbuf, BXE_DEVDESC_MAX,
2532 "%s (%c%d) BXE v:%s\n", t->bxe_name,
2533 (((pci_read_config(dev, PCIR_REVID, 4) &
2535 (pci_read_config(dev, PCIR_REVID, 4) & 0xf),
2536 BXE_DRIVER_VERSION);
2538 device_set_desc_copy(dev, descbuf);
2539 free(descbuf, M_TEMP);
2540 return (BUS_PROBE_DEFAULT);
2549 bxe_init_mutexes(struct bxe_softc *sc)
2551 #ifdef BXE_CORE_LOCK_SX
2552 snprintf(sc->core_sx_name, sizeof(sc->core_sx_name),
2553 "bxe%d_core_lock", sc->unit);
2554 sx_init(&sc->core_sx, sc->core_sx_name);
2556 snprintf(sc->core_mtx_name, sizeof(sc->core_mtx_name),
2557 "bxe%d_core_lock", sc->unit);
2558 mtx_init(&sc->core_mtx, sc->core_mtx_name, NULL, MTX_DEF);
2561 snprintf(sc->sp_mtx_name, sizeof(sc->sp_mtx_name),
2562 "bxe%d_sp_lock", sc->unit);
2563 mtx_init(&sc->sp_mtx, sc->sp_mtx_name, NULL, MTX_DEF);
2565 snprintf(sc->dmae_mtx_name, sizeof(sc->dmae_mtx_name),
2566 "bxe%d_dmae_lock", sc->unit);
2567 mtx_init(&sc->dmae_mtx, sc->dmae_mtx_name, NULL, MTX_DEF);
2569 snprintf(sc->port.phy_mtx_name, sizeof(sc->port.phy_mtx_name),
2570 "bxe%d_phy_lock", sc->unit);
2571 mtx_init(&sc->port.phy_mtx, sc->port.phy_mtx_name, NULL, MTX_DEF);
2573 snprintf(sc->fwmb_mtx_name, sizeof(sc->fwmb_mtx_name),
2574 "bxe%d_fwmb_lock", sc->unit);
2575 mtx_init(&sc->fwmb_mtx, sc->fwmb_mtx_name, NULL, MTX_DEF);
2577 snprintf(sc->print_mtx_name, sizeof(sc->print_mtx_name),
2578 "bxe%d_print_lock", sc->unit);
2579 mtx_init(&(sc->print_mtx), sc->print_mtx_name, NULL, MTX_DEF);
2581 snprintf(sc->stats_mtx_name, sizeof(sc->stats_mtx_name),
2582 "bxe%d_stats_lock", sc->unit);
2583 mtx_init(&(sc->stats_mtx), sc->stats_mtx_name, NULL, MTX_DEF);
2585 snprintf(sc->mcast_mtx_name, sizeof(sc->mcast_mtx_name),
2586 "bxe%d_mcast_lock", sc->unit);
2587 mtx_init(&(sc->mcast_mtx), sc->mcast_mtx_name, NULL, MTX_DEF);
2591 bxe_release_mutexes(struct bxe_softc *sc)
2593 #ifdef BXE_CORE_LOCK_SX
2594 sx_destroy(&sc->core_sx);
2596 if (mtx_initialized(&sc->core_mtx)) {
2597 mtx_destroy(&sc->core_mtx);
2601 if (mtx_initialized(&sc->sp_mtx)) {
2602 mtx_destroy(&sc->sp_mtx);
2605 if (mtx_initialized(&sc->dmae_mtx)) {
2606 mtx_destroy(&sc->dmae_mtx);
2609 if (mtx_initialized(&sc->port.phy_mtx)) {
2610 mtx_destroy(&sc->port.phy_mtx);
2613 if (mtx_initialized(&sc->fwmb_mtx)) {
2614 mtx_destroy(&sc->fwmb_mtx);
2617 if (mtx_initialized(&sc->print_mtx)) {
2618 mtx_destroy(&sc->print_mtx);
2621 if (mtx_initialized(&sc->stats_mtx)) {
2622 mtx_destroy(&sc->stats_mtx);
2625 if (mtx_initialized(&sc->mcast_mtx)) {
2626 mtx_destroy(&sc->mcast_mtx);
2631 bxe_tx_disable(struct bxe_softc* sc)
2633 struct ifnet *ifp = sc->ifnet;
2635 /* tell the stack the driver is stopped and TX queue is full */
2637 ifp->if_drv_flags = 0;
2642 bxe_drv_pulse(struct bxe_softc *sc)
2644 SHMEM_WR(sc, func_mb[SC_FW_MB_IDX(sc)].drv_pulse_mb,
2645 sc->fw_drv_pulse_wr_seq);
2648 static inline uint16_t
2649 bxe_tx_avail(struct bxe_softc *sc,
2650 struct bxe_fastpath *fp)
2656 prod = fp->tx_bd_prod;
2657 cons = fp->tx_bd_cons;
2659 used = SUB_S16(prod, cons);
2661 return (int16_t)(sc->tx_ring_size) - used;
2665 bxe_tx_queue_has_work(struct bxe_fastpath *fp)
2669 mb(); /* status block fields can change */
2670 hw_cons = le16toh(*fp->tx_cons_sb);
2671 return (hw_cons != fp->tx_pkt_cons);
2674 static inline uint8_t
2675 bxe_has_tx_work(struct bxe_fastpath *fp)
2677 /* expand this for multi-cos if ever supported */
2678 return (bxe_tx_queue_has_work(fp)) ? TRUE : FALSE;
2682 bxe_has_rx_work(struct bxe_fastpath *fp)
2684 uint16_t rx_cq_cons_sb;
2686 mb(); /* status block fields can change */
2687 rx_cq_cons_sb = le16toh(*fp->rx_cq_cons_sb);
2688 if ((rx_cq_cons_sb & RCQ_MAX) == RCQ_MAX)
2690 return (fp->rx_cq_cons != rx_cq_cons_sb);
2694 bxe_sp_event(struct bxe_softc *sc,
2695 struct bxe_fastpath *fp,
2696 union eth_rx_cqe *rr_cqe)
2698 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
2699 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
2700 enum ecore_queue_cmd drv_cmd = ECORE_Q_CMD_MAX;
2701 struct ecore_queue_sp_obj *q_obj = &BXE_SP_OBJ(sc, fp).q_obj;
2703 BLOGD(sc, DBG_SP, "fp=%d cid=%d got ramrod #%d state is %x type is %d\n",
2704 fp->index, cid, command, sc->state, rr_cqe->ramrod_cqe.ramrod_type);
2707 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
2708 BLOGD(sc, DBG_SP, "got UPDATE ramrod. CID %d\n", cid);
2709 drv_cmd = ECORE_Q_CMD_UPDATE;
2712 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
2713 BLOGD(sc, DBG_SP, "got MULTI[%d] setup ramrod\n", cid);
2714 drv_cmd = ECORE_Q_CMD_SETUP;
2717 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
2718 BLOGD(sc, DBG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
2719 drv_cmd = ECORE_Q_CMD_SETUP_TX_ONLY;
2722 case (RAMROD_CMD_ID_ETH_HALT):
2723 BLOGD(sc, DBG_SP, "got MULTI[%d] halt ramrod\n", cid);
2724 drv_cmd = ECORE_Q_CMD_HALT;
2727 case (RAMROD_CMD_ID_ETH_TERMINATE):
2728 BLOGD(sc, DBG_SP, "got MULTI[%d] teminate ramrod\n", cid);
2729 drv_cmd = ECORE_Q_CMD_TERMINATE;
2732 case (RAMROD_CMD_ID_ETH_EMPTY):
2733 BLOGD(sc, DBG_SP, "got MULTI[%d] empty ramrod\n", cid);
2734 drv_cmd = ECORE_Q_CMD_EMPTY;
2738 BLOGD(sc, DBG_SP, "ERROR: unexpected MC reply (%d) on fp[%d]\n",
2739 command, fp->index);
2743 if ((drv_cmd != ECORE_Q_CMD_MAX) &&
2744 q_obj->complete_cmd(sc, q_obj, drv_cmd)) {
2746 * q_obj->complete_cmd() failure means that this was
2747 * an unexpected completion.
2749 * In this case we don't want to increase the sc->spq_left
2750 * because apparently we haven't sent this command the first
2753 // bxe_panic(sc, ("Unexpected SP completion\n"));
2757 atomic_add_acq_long(&sc->cq_spq_left, 1);
2759 BLOGD(sc, DBG_SP, "sc->cq_spq_left 0x%lx\n",
2760 atomic_load_acq_long(&sc->cq_spq_left));
2764 * The current mbuf is part of an aggregation. Move the mbuf into the TPA
2765 * aggregation queue, put an empty mbuf back onto the receive chain, and mark
2766 * the current aggregation queue as in-progress.
2769 bxe_tpa_start(struct bxe_softc *sc,
2770 struct bxe_fastpath *fp,
2774 struct eth_fast_path_rx_cqe *cqe)
2776 struct bxe_sw_rx_bd tmp_bd;
2777 struct bxe_sw_rx_bd *rx_buf;
2778 struct eth_rx_bd *rx_bd;
2780 struct bxe_sw_tpa_info *tpa_info = &fp->rx_tpa_info[queue];
2783 BLOGD(sc, DBG_LRO, "fp[%02d].tpa[%02d] TPA START "
2784 "cons=%d prod=%d\n",
2785 fp->index, queue, cons, prod);
2787 max_agg_queues = MAX_AGG_QS(sc);
2789 KASSERT((queue < max_agg_queues),
2790 ("fp[%02d] invalid aggr queue (%d >= %d)!",
2791 fp->index, queue, max_agg_queues));
2793 KASSERT((tpa_info->state == BXE_TPA_STATE_STOP),
2794 ("fp[%02d].tpa[%02d] starting aggr on queue not stopped!",
2797 /* copy the existing mbuf and mapping from the TPA pool */
2798 tmp_bd = tpa_info->bd;
2800 if (tmp_bd.m == NULL) {
2803 tmp = (uint32_t *)cqe;
2805 BLOGE(sc, "fp[%02d].tpa[%02d] cons[%d] prod[%d]mbuf not allocated!\n",
2806 fp->index, queue, cons, prod);
2807 BLOGE(sc, "cqe [0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x]\n",
2808 *tmp, *(tmp+1), *(tmp+2), *(tmp+3), *(tmp+4), *(tmp+5), *(tmp+6), *(tmp+7));
2810 /* XXX Error handling? */
2814 /* change the TPA queue to the start state */
2815 tpa_info->state = BXE_TPA_STATE_START;
2816 tpa_info->placement_offset = cqe->placement_offset;
2817 tpa_info->parsing_flags = le16toh(cqe->pars_flags.flags);
2818 tpa_info->vlan_tag = le16toh(cqe->vlan_tag);
2819 tpa_info->len_on_bd = le16toh(cqe->len_on_bd);
2821 fp->rx_tpa_queue_used |= (1 << queue);
2824 * If all the buffer descriptors are filled with mbufs then fill in
2825 * the current consumer index with a new BD. Else if a maximum Rx
2826 * buffer limit is imposed then fill in the next producer index.
2828 index = (sc->max_rx_bufs != RX_BD_USABLE) ?
2831 /* move the received mbuf and mapping to TPA pool */
2832 tpa_info->bd = fp->rx_mbuf_chain[cons];
2834 /* release any existing RX BD mbuf mappings */
2835 if (cons != index) {
2836 rx_buf = &fp->rx_mbuf_chain[cons];
2838 if (rx_buf->m_map != NULL) {
2839 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map,
2840 BUS_DMASYNC_POSTREAD);
2841 bus_dmamap_unload(fp->rx_mbuf_tag, rx_buf->m_map);
2845 * We get here when the maximum number of rx buffers is less than
2846 * RX_BD_USABLE. The mbuf is already saved above so it's OK to NULL
2847 * it out here without concern of a memory leak.
2849 fp->rx_mbuf_chain[cons].m = NULL;
2852 /* update the Rx SW BD with the mbuf info from the TPA pool */
2853 fp->rx_mbuf_chain[index] = tmp_bd;
2855 /* update the Rx BD with the empty mbuf phys address from the TPA pool */
2856 rx_bd = &fp->rx_chain[index];
2857 rx_bd->addr_hi = htole32(U64_HI(tpa_info->seg.ds_addr));
2858 rx_bd->addr_lo = htole32(U64_LO(tpa_info->seg.ds_addr));
2862 * When a TPA aggregation is completed, loop through the individual mbufs
2863 * of the aggregation, combining them into a single mbuf which will be sent
2864 * up the stack. Refill all freed SGEs with mbufs as we go along.
2867 bxe_fill_frag_mbuf(struct bxe_softc *sc,
2868 struct bxe_fastpath *fp,
2869 struct bxe_sw_tpa_info *tpa_info,
2873 struct eth_end_agg_rx_cqe *cqe,
2876 struct mbuf *m_frag;
2877 uint32_t frag_len, frag_size, i;
2882 frag_size = le16toh(cqe->pkt_len) - tpa_info->len_on_bd;
2885 "fp[%02d].tpa[%02d] TPA fill len_on_bd=%d frag_size=%d pages=%d\n",
2886 fp->index, queue, tpa_info->len_on_bd, frag_size, pages);
2888 /* make sure the aggregated frame is not too big to handle */
2889 if (pages > 8 * PAGES_PER_SGE) {
2891 uint32_t *tmp = (uint32_t *)cqe;
2893 BLOGE(sc, "fp[%02d].sge[0x%04x] has too many pages (%d)! "
2894 "pkt_len=%d len_on_bd=%d frag_size=%d\n",
2895 fp->index, cqe_idx, pages, le16toh(cqe->pkt_len),
2896 tpa_info->len_on_bd, frag_size);
2898 BLOGE(sc, "cqe [0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x]\n",
2899 *tmp, *(tmp+1), *(tmp+2), *(tmp+3), *(tmp+4), *(tmp+5), *(tmp+6), *(tmp+7));
2901 bxe_panic(sc, ("sge page count error\n"));
2906 * Scan through the scatter gather list pulling individual mbufs into a
2907 * single mbuf for the host stack.
2909 for (i = 0, j = 0; i < pages; i += PAGES_PER_SGE, j++) {
2910 sge_idx = RX_SGE(le16toh(cqe->sgl_or_raw_data.sgl[j]));
2913 * Firmware gives the indices of the SGE as if the ring is an array
2914 * (meaning that the "next" element will consume 2 indices).
2916 frag_len = min(frag_size, (uint32_t)(SGE_PAGES));
2918 BLOGD(sc, DBG_LRO, "fp[%02d].tpa[%02d] TPA fill i=%d j=%d "
2919 "sge_idx=%d frag_size=%d frag_len=%d\n",
2920 fp->index, queue, i, j, sge_idx, frag_size, frag_len);
2922 m_frag = fp->rx_sge_mbuf_chain[sge_idx].m;
2924 /* allocate a new mbuf for the SGE */
2925 rc = bxe_alloc_rx_sge_mbuf(fp, sge_idx);
2927 /* Leave all remaining SGEs in the ring! */
2931 /* update the fragment length */
2932 m_frag->m_len = frag_len;
2934 /* concatenate the fragment to the head mbuf */
2936 fp->eth_q_stats.mbuf_alloc_sge--;
2938 /* update the TPA mbuf size and remaining fragment size */
2939 m->m_pkthdr.len += frag_len;
2940 frag_size -= frag_len;
2944 "fp[%02d].tpa[%02d] TPA fill done frag_size=%d\n",
2945 fp->index, queue, frag_size);
2951 bxe_clear_sge_mask_next_elems(struct bxe_fastpath *fp)
2955 for (i = 1; i <= RX_SGE_NUM_PAGES; i++) {
2956 int idx = RX_SGE_TOTAL_PER_PAGE * i - 1;
2958 for (j = 0; j < 2; j++) {
2959 BIT_VEC64_CLEAR_BIT(fp->sge_mask, idx);
2966 bxe_init_sge_ring_bit_mask(struct bxe_fastpath *fp)
2968 /* set the mask to all 1's, it's faster to compare to 0 than to 0xf's */
2969 memset(fp->sge_mask, 0xff, sizeof(fp->sge_mask));
2972 * Clear the two last indices in the page to 1. These are the indices that
2973 * correspond to the "next" element, hence will never be indicated and
2974 * should be removed from the calculations.
2976 bxe_clear_sge_mask_next_elems(fp);
2980 bxe_update_last_max_sge(struct bxe_fastpath *fp,
2983 uint16_t last_max = fp->last_max_sge;
2985 if (SUB_S16(idx, last_max) > 0) {
2986 fp->last_max_sge = idx;
2991 bxe_update_sge_prod(struct bxe_softc *sc,
2992 struct bxe_fastpath *fp,
2994 union eth_sgl_or_raw_data *cqe)
2996 uint16_t last_max, last_elem, first_elem;
3004 /* first mark all used pages */
3005 for (i = 0; i < sge_len; i++) {
3006 BIT_VEC64_CLEAR_BIT(fp->sge_mask,
3007 RX_SGE(le16toh(cqe->sgl[i])));
3011 "fp[%02d] fp_cqe->sgl[%d] = %d\n",
3012 fp->index, sge_len - 1,
3013 le16toh(cqe->sgl[sge_len - 1]));
3015 /* assume that the last SGE index is the biggest */
3016 bxe_update_last_max_sge(fp,
3017 le16toh(cqe->sgl[sge_len - 1]));
3019 last_max = RX_SGE(fp->last_max_sge);
3020 last_elem = last_max >> BIT_VEC64_ELEM_SHIFT;
3021 first_elem = RX_SGE(fp->rx_sge_prod) >> BIT_VEC64_ELEM_SHIFT;
3023 /* if ring is not full */
3024 if (last_elem + 1 != first_elem) {
3028 /* now update the prod */
3029 for (i = first_elem; i != last_elem; i = RX_SGE_NEXT_MASK_ELEM(i)) {
3030 if (__predict_true(fp->sge_mask[i])) {
3034 fp->sge_mask[i] = BIT_VEC64_ELEM_ONE_MASK;
3035 delta += BIT_VEC64_ELEM_SZ;
3039 fp->rx_sge_prod += delta;
3040 /* clear page-end entries */
3041 bxe_clear_sge_mask_next_elems(fp);
3045 "fp[%02d] fp->last_max_sge=%d fp->rx_sge_prod=%d\n",
3046 fp->index, fp->last_max_sge, fp->rx_sge_prod);
3050 * The aggregation on the current TPA queue has completed. Pull the individual
3051 * mbuf fragments together into a single mbuf, perform all necessary checksum
3052 * calculations, and send the resuting mbuf to the stack.
3055 bxe_tpa_stop(struct bxe_softc *sc,
3056 struct bxe_fastpath *fp,
3057 struct bxe_sw_tpa_info *tpa_info,
3060 struct eth_end_agg_rx_cqe *cqe,
3063 struct ifnet *ifp = sc->ifnet;
3068 "fp[%02d].tpa[%02d] pad=%d pkt_len=%d pages=%d vlan=%d\n",
3069 fp->index, queue, tpa_info->placement_offset,
3070 le16toh(cqe->pkt_len), pages, tpa_info->vlan_tag);
3074 /* allocate a replacement before modifying existing mbuf */
3075 rc = bxe_alloc_rx_tpa_mbuf(fp, queue);
3077 /* drop the frame and log an error */
3078 fp->eth_q_stats.rx_soft_errors++;
3079 goto bxe_tpa_stop_exit;
3082 /* we have a replacement, fixup the current mbuf */
3083 m_adj(m, tpa_info->placement_offset);
3084 m->m_pkthdr.len = m->m_len = tpa_info->len_on_bd;
3086 /* mark the checksums valid (taken care of by the firmware) */
3087 fp->eth_q_stats.rx_ofld_frames_csum_ip++;
3088 fp->eth_q_stats.rx_ofld_frames_csum_tcp_udp++;
3089 m->m_pkthdr.csum_data = 0xffff;
3090 m->m_pkthdr.csum_flags |= (CSUM_IP_CHECKED |
3095 /* aggregate all of the SGEs into a single mbuf */
3096 rc = bxe_fill_frag_mbuf(sc, fp, tpa_info, queue, pages, m, cqe, cqe_idx);
3098 /* drop the packet and log an error */
3099 fp->eth_q_stats.rx_soft_errors++;
3102 if (tpa_info->parsing_flags & PARSING_FLAGS_INNER_VLAN_EXIST) {
3103 m->m_pkthdr.ether_vtag = tpa_info->vlan_tag;
3104 m->m_flags |= M_VLANTAG;
3107 /* assign packet to this interface interface */
3108 m->m_pkthdr.rcvif = ifp;
3110 #if __FreeBSD_version >= 800000
3111 /* specify what RSS queue was used for this flow */
3112 m->m_pkthdr.flowid = fp->index;
3117 fp->eth_q_stats.rx_tpa_pkts++;
3119 /* pass the frame to the stack */
3120 (*ifp->if_input)(ifp, m);
3123 /* we passed an mbuf up the stack or dropped the frame */
3124 fp->eth_q_stats.mbuf_alloc_tpa--;
3128 fp->rx_tpa_info[queue].state = BXE_TPA_STATE_STOP;
3129 fp->rx_tpa_queue_used &= ~(1 << queue);
3134 struct bxe_fastpath *fp,
3138 struct eth_fast_path_rx_cqe *cqe_fp)
3140 struct mbuf *m_frag;
3141 uint16_t frags, frag_len;
3142 uint16_t sge_idx = 0;
3147 /* adjust the mbuf */
3150 frag_size = len - lenonbd;
3151 frags = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT;
3153 for (i = 0, j = 0; i < frags; i += PAGES_PER_SGE, j++) {
3154 sge_idx = RX_SGE(le16toh(cqe_fp->sgl_or_raw_data.sgl[j]));
3156 m_frag = fp->rx_sge_mbuf_chain[sge_idx].m;
3157 frag_len = min(frag_size, (uint32_t)(SGE_PAGE_SIZE));
3158 m_frag->m_len = frag_len;
3160 /* allocate a new mbuf for the SGE */
3161 rc = bxe_alloc_rx_sge_mbuf(fp, sge_idx);
3163 /* Leave all remaining SGEs in the ring! */
3166 fp->eth_q_stats.mbuf_alloc_sge--;
3168 /* concatenate the fragment to the head mbuf */
3171 frag_size -= frag_len;
3174 bxe_update_sge_prod(fp->sc, fp, frags, &cqe_fp->sgl_or_raw_data);
3180 bxe_rxeof(struct bxe_softc *sc,
3181 struct bxe_fastpath *fp)
3183 struct ifnet *ifp = sc->ifnet;
3184 uint16_t bd_cons, bd_prod, bd_prod_fw, comp_ring_cons;
3185 uint16_t hw_cq_cons, sw_cq_cons, sw_cq_prod;
3191 /* CQ "next element" is of the size of the regular element */
3192 hw_cq_cons = le16toh(*fp->rx_cq_cons_sb);
3193 if ((hw_cq_cons & RCQ_USABLE_PER_PAGE) == RCQ_USABLE_PER_PAGE) {
3197 bd_cons = fp->rx_bd_cons;
3198 bd_prod = fp->rx_bd_prod;
3199 bd_prod_fw = bd_prod;
3200 sw_cq_cons = fp->rx_cq_cons;
3201 sw_cq_prod = fp->rx_cq_prod;
3204 * Memory barrier necessary as speculative reads of the rx
3205 * buffer can be ahead of the index in the status block
3210 "fp[%02d] Rx START hw_cq_cons=%u sw_cq_cons=%u\n",
3211 fp->index, hw_cq_cons, sw_cq_cons);
3213 while (sw_cq_cons != hw_cq_cons) {
3214 struct bxe_sw_rx_bd *rx_buf = NULL;
3215 union eth_rx_cqe *cqe;
3216 struct eth_fast_path_rx_cqe *cqe_fp;
3217 uint8_t cqe_fp_flags;
3218 enum eth_rx_cqe_type cqe_fp_type;
3219 uint16_t len, lenonbd, pad;
3220 struct mbuf *m = NULL;
3222 comp_ring_cons = RCQ(sw_cq_cons);
3223 bd_prod = RX_BD(bd_prod);
3224 bd_cons = RX_BD(bd_cons);
3226 cqe = &fp->rcq_chain[comp_ring_cons];
3227 cqe_fp = &cqe->fast_path_cqe;
3228 cqe_fp_flags = cqe_fp->type_error_flags;
3229 cqe_fp_type = cqe_fp_flags & ETH_FAST_PATH_RX_CQE_TYPE;
3232 "fp[%02d] Rx hw_cq_cons=%d hw_sw_cons=%d "
3233 "BD prod=%d cons=%d CQE type=0x%x err=0x%x "
3234 "status=0x%x rss_hash=0x%x vlan=0x%x len=%u lenonbd=%u\n",
3240 CQE_TYPE(cqe_fp_flags),
3242 cqe_fp->status_flags,
3243 le32toh(cqe_fp->rss_hash_result),
3244 le16toh(cqe_fp->vlan_tag),
3245 le16toh(cqe_fp->pkt_len_or_gro_seg_len),
3246 le16toh(cqe_fp->len_on_bd));
3248 /* is this a slowpath msg? */
3249 if (__predict_false(CQE_TYPE_SLOW(cqe_fp_type))) {
3250 bxe_sp_event(sc, fp, cqe);
3254 rx_buf = &fp->rx_mbuf_chain[bd_cons];
3256 if (!CQE_TYPE_FAST(cqe_fp_type)) {
3257 struct bxe_sw_tpa_info *tpa_info;
3258 uint16_t frag_size, pages;
3261 if (CQE_TYPE_START(cqe_fp_type)) {
3262 bxe_tpa_start(sc, fp, cqe_fp->queue_index,
3263 bd_cons, bd_prod, cqe_fp);
3264 m = NULL; /* packet not ready yet */
3268 KASSERT(CQE_TYPE_STOP(cqe_fp_type),
3269 ("CQE type is not STOP! (0x%x)\n", cqe_fp_type));
3271 queue = cqe->end_agg_cqe.queue_index;
3272 tpa_info = &fp->rx_tpa_info[queue];
3274 BLOGD(sc, DBG_LRO, "fp[%02d].tpa[%02d] TPA STOP\n",
3277 frag_size = (le16toh(cqe->end_agg_cqe.pkt_len) -
3278 tpa_info->len_on_bd);
3279 pages = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT;
3281 bxe_tpa_stop(sc, fp, tpa_info, queue, pages,
3282 &cqe->end_agg_cqe, comp_ring_cons);
3284 bxe_update_sge_prod(sc, fp, pages, &cqe->end_agg_cqe.sgl_or_raw_data);
3291 /* is this an error packet? */
3292 if (__predict_false(cqe_fp_flags &
3293 ETH_FAST_PATH_RX_CQE_PHY_DECODE_ERR_FLG)) {
3294 BLOGE(sc, "flags 0x%x rx packet %u\n", cqe_fp_flags, sw_cq_cons);
3295 fp->eth_q_stats.rx_soft_errors++;
3299 len = le16toh(cqe_fp->pkt_len_or_gro_seg_len);
3300 lenonbd = le16toh(cqe_fp->len_on_bd);
3301 pad = cqe_fp->placement_offset;
3305 if (__predict_false(m == NULL)) {
3306 BLOGE(sc, "No mbuf in rx chain descriptor %d for fp[%02d]\n",
3307 bd_cons, fp->index);
3311 /* XXX double copy if packet length under a threshold */
3314 * If all the buffer descriptors are filled with mbufs then fill in
3315 * the current consumer index with a new BD. Else if a maximum Rx
3316 * buffer limit is imposed then fill in the next producer index.
3318 rc = bxe_alloc_rx_bd_mbuf(fp, bd_cons,
3319 (sc->max_rx_bufs != RX_BD_USABLE) ?
3323 /* we simply reuse the received mbuf and don't post it to the stack */
3326 BLOGE(sc, "mbuf alloc fail for fp[%02d] rx chain (%d)\n",
3328 fp->eth_q_stats.rx_soft_errors++;
3330 if (sc->max_rx_bufs != RX_BD_USABLE) {
3331 /* copy this consumer index to the producer index */
3332 memcpy(&fp->rx_mbuf_chain[bd_prod], rx_buf,
3333 sizeof(struct bxe_sw_rx_bd));
3334 memset(rx_buf, 0, sizeof(struct bxe_sw_rx_bd));
3340 /* current mbuf was detached from the bd */
3341 fp->eth_q_stats.mbuf_alloc_rx--;
3343 /* we allocated a replacement mbuf, fixup the current one */
3345 m->m_pkthdr.len = m->m_len = len;
3347 if ((len > 60) && (len > lenonbd)) {
3348 fp->eth_q_stats.rx_bxe_service_rxsgl++;
3349 rc = bxe_service_rxsgl(fp, len, lenonbd, m, cqe_fp);
3352 fp->eth_q_stats.rx_jumbo_sge_pkts++;
3353 } else if (lenonbd < len) {
3354 fp->eth_q_stats.rx_erroneous_jumbo_sge_pkts++;
3357 /* assign packet to this interface interface */
3358 m->m_pkthdr.rcvif = ifp;
3360 /* assume no hardware checksum has complated */
3361 m->m_pkthdr.csum_flags = 0;
3363 /* validate checksum if offload enabled */
3364 if (ifp->if_capenable & IFCAP_RXCSUM) {
3365 /* check for a valid IP frame */
3366 if (!(cqe->fast_path_cqe.status_flags &
3367 ETH_FAST_PATH_RX_CQE_IP_XSUM_NO_VALIDATION_FLG)) {
3368 m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED;
3369 if (__predict_false(cqe_fp_flags &
3370 ETH_FAST_PATH_RX_CQE_IP_BAD_XSUM_FLG)) {
3371 fp->eth_q_stats.rx_hw_csum_errors++;
3373 fp->eth_q_stats.rx_ofld_frames_csum_ip++;
3374 m->m_pkthdr.csum_flags |= CSUM_IP_VALID;
3378 /* check for a valid TCP/UDP frame */
3379 if (!(cqe->fast_path_cqe.status_flags &
3380 ETH_FAST_PATH_RX_CQE_L4_XSUM_NO_VALIDATION_FLG)) {
3381 if (__predict_false(cqe_fp_flags &
3382 ETH_FAST_PATH_RX_CQE_L4_BAD_XSUM_FLG)) {
3383 fp->eth_q_stats.rx_hw_csum_errors++;
3385 fp->eth_q_stats.rx_ofld_frames_csum_tcp_udp++;
3386 m->m_pkthdr.csum_data = 0xFFFF;
3387 m->m_pkthdr.csum_flags |= (CSUM_DATA_VALID |
3393 /* if there is a VLAN tag then flag that info */
3394 if (cqe->fast_path_cqe.pars_flags.flags & PARSING_FLAGS_INNER_VLAN_EXIST) {
3395 m->m_pkthdr.ether_vtag = cqe->fast_path_cqe.vlan_tag;
3396 m->m_flags |= M_VLANTAG;
3399 #if __FreeBSD_version >= 800000
3400 /* specify what RSS queue was used for this flow */
3401 m->m_pkthdr.flowid = fp->index;
3407 bd_cons = RX_BD_NEXT(bd_cons);
3408 bd_prod = RX_BD_NEXT(bd_prod);
3409 bd_prod_fw = RX_BD_NEXT(bd_prod_fw);
3411 /* pass the frame to the stack */
3412 if (__predict_true(m != NULL)) {
3415 (*ifp->if_input)(ifp, m);
3420 sw_cq_prod = RCQ_NEXT(sw_cq_prod);
3421 sw_cq_cons = RCQ_NEXT(sw_cq_cons);
3423 /* limit spinning on the queue */
3427 if (rx_pkts == sc->rx_budget) {
3428 fp->eth_q_stats.rx_budget_reached++;
3431 } /* while work to do */
3433 fp->rx_bd_cons = bd_cons;
3434 fp->rx_bd_prod = bd_prod_fw;
3435 fp->rx_cq_cons = sw_cq_cons;
3436 fp->rx_cq_prod = sw_cq_prod;
3438 /* Update producers */
3439 bxe_update_rx_prod(sc, fp, bd_prod_fw, sw_cq_prod, fp->rx_sge_prod);
3441 fp->eth_q_stats.rx_pkts += rx_pkts;
3442 fp->eth_q_stats.rx_calls++;
3444 BXE_FP_RX_UNLOCK(fp);
3446 return (sw_cq_cons != hw_cq_cons);
3450 bxe_free_tx_pkt(struct bxe_softc *sc,
3451 struct bxe_fastpath *fp,
3454 struct bxe_sw_tx_bd *tx_buf = &fp->tx_mbuf_chain[idx];
3455 struct eth_tx_start_bd *tx_start_bd;
3456 uint16_t bd_idx = TX_BD(tx_buf->first_bd);
3460 /* unmap the mbuf from non-paged memory */
3461 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
3463 tx_start_bd = &fp->tx_chain[bd_idx].start_bd;
3464 nbd = le16toh(tx_start_bd->nbd) - 1;
3466 new_cons = (tx_buf->first_bd + nbd);
3469 if (__predict_true(tx_buf->m != NULL)) {
3471 fp->eth_q_stats.mbuf_alloc_tx--;
3473 fp->eth_q_stats.tx_chain_lost_mbuf++;
3477 tx_buf->first_bd = 0;
3482 /* transmit timeout watchdog */
3484 bxe_watchdog(struct bxe_softc *sc,
3485 struct bxe_fastpath *fp)
3489 if ((fp->watchdog_timer == 0) || (--fp->watchdog_timer)) {
3490 BXE_FP_TX_UNLOCK(fp);
3494 BLOGE(sc, "TX watchdog timeout on fp[%02d], resetting!\n", fp->index);
3496 BXE_FP_TX_UNLOCK(fp);
3497 BXE_SET_ERROR_BIT(sc, BXE_ERR_TXQ_STUCK);
3498 taskqueue_enqueue_timeout(taskqueue_thread,
3499 &sc->sp_err_timeout_task, hz/10);
3504 /* processes transmit completions */
3506 bxe_txeof(struct bxe_softc *sc,
3507 struct bxe_fastpath *fp)
3509 struct ifnet *ifp = sc->ifnet;
3510 uint16_t bd_cons, hw_cons, sw_cons, pkt_cons;
3511 uint16_t tx_bd_avail;
3513 BXE_FP_TX_LOCK_ASSERT(fp);
3515 bd_cons = fp->tx_bd_cons;
3516 hw_cons = le16toh(*fp->tx_cons_sb);
3517 sw_cons = fp->tx_pkt_cons;
3519 while (sw_cons != hw_cons) {
3520 pkt_cons = TX_BD(sw_cons);
3523 "TX: fp[%d]: hw_cons=%u sw_cons=%u pkt_cons=%u\n",
3524 fp->index, hw_cons, sw_cons, pkt_cons);
3526 bd_cons = bxe_free_tx_pkt(sc, fp, pkt_cons);
3531 fp->tx_pkt_cons = sw_cons;
3532 fp->tx_bd_cons = bd_cons;
3535 "TX done: fp[%d]: hw_cons=%u sw_cons=%u sw_prod=%u\n",
3536 fp->index, hw_cons, fp->tx_pkt_cons, fp->tx_pkt_prod);
3540 tx_bd_avail = bxe_tx_avail(sc, fp);
3542 if (tx_bd_avail < BXE_TX_CLEANUP_THRESHOLD) {
3543 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
3545 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
3548 if (fp->tx_pkt_prod != fp->tx_pkt_cons) {
3549 /* reset the watchdog timer if there are pending transmits */
3550 fp->watchdog_timer = BXE_TX_TIMEOUT;
3553 /* clear watchdog when there are no pending transmits */
3554 fp->watchdog_timer = 0;
3560 bxe_drain_tx_queues(struct bxe_softc *sc)
3562 struct bxe_fastpath *fp;
3565 /* wait until all TX fastpath tasks have completed */
3566 for (i = 0; i < sc->num_queues; i++) {
3571 while (bxe_has_tx_work(fp)) {
3575 BXE_FP_TX_UNLOCK(fp);
3578 BLOGE(sc, "Timeout waiting for fp[%d] "
3579 "transmits to complete!\n", i);
3580 bxe_panic(sc, ("tx drain failure\n"));
3594 bxe_del_all_macs(struct bxe_softc *sc,
3595 struct ecore_vlan_mac_obj *mac_obj,
3597 uint8_t wait_for_comp)
3599 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
3602 /* wait for completion of requested */
3603 if (wait_for_comp) {
3604 bxe_set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
3607 /* Set the mac type of addresses we want to clear */
3608 bxe_set_bit(mac_type, &vlan_mac_flags);
3610 rc = mac_obj->delete_all(sc, mac_obj, &vlan_mac_flags, &ramrod_flags);
3612 BLOGE(sc, "Failed to delete MACs (%d) mac_type %d wait_for_comp 0x%x\n",
3613 rc, mac_type, wait_for_comp);
3620 bxe_fill_accept_flags(struct bxe_softc *sc,
3622 unsigned long *rx_accept_flags,
3623 unsigned long *tx_accept_flags)
3625 /* Clear the flags first */
3626 *rx_accept_flags = 0;
3627 *tx_accept_flags = 0;
3630 case BXE_RX_MODE_NONE:
3632 * 'drop all' supersedes any accept flags that may have been
3633 * passed to the function.
3637 case BXE_RX_MODE_NORMAL:
3638 bxe_set_bit(ECORE_ACCEPT_UNICAST, rx_accept_flags);
3639 bxe_set_bit(ECORE_ACCEPT_MULTICAST, rx_accept_flags);
3640 bxe_set_bit(ECORE_ACCEPT_BROADCAST, rx_accept_flags);
3642 /* internal switching mode */
3643 bxe_set_bit(ECORE_ACCEPT_UNICAST, tx_accept_flags);
3644 bxe_set_bit(ECORE_ACCEPT_MULTICAST, tx_accept_flags);
3645 bxe_set_bit(ECORE_ACCEPT_BROADCAST, tx_accept_flags);
3649 case BXE_RX_MODE_ALLMULTI:
3650 bxe_set_bit(ECORE_ACCEPT_UNICAST, rx_accept_flags);
3651 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, rx_accept_flags);
3652 bxe_set_bit(ECORE_ACCEPT_BROADCAST, rx_accept_flags);
3654 /* internal switching mode */
3655 bxe_set_bit(ECORE_ACCEPT_UNICAST, tx_accept_flags);
3656 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, tx_accept_flags);
3657 bxe_set_bit(ECORE_ACCEPT_BROADCAST, tx_accept_flags);
3661 case BXE_RX_MODE_PROMISC:
3663 * According to deffinition of SI mode, iface in promisc mode
3664 * should receive matched and unmatched (in resolution of port)
3667 bxe_set_bit(ECORE_ACCEPT_UNMATCHED, rx_accept_flags);
3668 bxe_set_bit(ECORE_ACCEPT_UNICAST, rx_accept_flags);
3669 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, rx_accept_flags);
3670 bxe_set_bit(ECORE_ACCEPT_BROADCAST, rx_accept_flags);
3672 /* internal switching mode */
3673 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, tx_accept_flags);
3674 bxe_set_bit(ECORE_ACCEPT_BROADCAST, tx_accept_flags);
3677 bxe_set_bit(ECORE_ACCEPT_ALL_UNICAST, tx_accept_flags);
3679 bxe_set_bit(ECORE_ACCEPT_UNICAST, tx_accept_flags);
3685 BLOGE(sc, "Unknown rx_mode (0x%x)\n", rx_mode);
3689 /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
3690 if (rx_mode != BXE_RX_MODE_NONE) {
3691 bxe_set_bit(ECORE_ACCEPT_ANY_VLAN, rx_accept_flags);
3692 bxe_set_bit(ECORE_ACCEPT_ANY_VLAN, tx_accept_flags);
3699 bxe_set_q_rx_mode(struct bxe_softc *sc,
3701 unsigned long rx_mode_flags,
3702 unsigned long rx_accept_flags,
3703 unsigned long tx_accept_flags,
3704 unsigned long ramrod_flags)
3706 struct ecore_rx_mode_ramrod_params ramrod_param;
3709 memset(&ramrod_param, 0, sizeof(ramrod_param));
3711 /* Prepare ramrod parameters */
3712 ramrod_param.cid = 0;
3713 ramrod_param.cl_id = cl_id;
3714 ramrod_param.rx_mode_obj = &sc->rx_mode_obj;
3715 ramrod_param.func_id = SC_FUNC(sc);
3717 ramrod_param.pstate = &sc->sp_state;
3718 ramrod_param.state = ECORE_FILTER_RX_MODE_PENDING;
3720 ramrod_param.rdata = BXE_SP(sc, rx_mode_rdata);
3721 ramrod_param.rdata_mapping = BXE_SP_MAPPING(sc, rx_mode_rdata);
3723 bxe_set_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state);
3725 ramrod_param.ramrod_flags = ramrod_flags;
3726 ramrod_param.rx_mode_flags = rx_mode_flags;
3728 ramrod_param.rx_accept_flags = rx_accept_flags;
3729 ramrod_param.tx_accept_flags = tx_accept_flags;
3731 rc = ecore_config_rx_mode(sc, &ramrod_param);
3733 BLOGE(sc, "Set rx_mode %d cli_id 0x%x rx_mode_flags 0x%x "
3734 "rx_accept_flags 0x%x tx_accept_flags 0x%x "
3735 "ramrod_flags 0x%x rc %d failed\n", sc->rx_mode, cl_id,
3736 (uint32_t)rx_mode_flags, (uint32_t)rx_accept_flags,
3737 (uint32_t)tx_accept_flags, (uint32_t)ramrod_flags, rc);
3745 bxe_set_storm_rx_mode(struct bxe_softc *sc)
3747 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
3748 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
3751 rc = bxe_fill_accept_flags(sc, sc->rx_mode, &rx_accept_flags,
3757 bxe_set_bit(RAMROD_RX, &ramrod_flags);
3758 bxe_set_bit(RAMROD_TX, &ramrod_flags);
3760 /* XXX ensure all fastpath have same cl_id and/or move it to bxe_softc */
3761 return (bxe_set_q_rx_mode(sc, sc->fp[0].cl_id, rx_mode_flags,
3762 rx_accept_flags, tx_accept_flags,
3766 /* returns the "mcp load_code" according to global load_count array */
3768 bxe_nic_load_no_mcp(struct bxe_softc *sc)
3770 int path = SC_PATH(sc);
3771 int port = SC_PORT(sc);
3773 BLOGI(sc, "NO MCP - load counts[%d] %d, %d, %d\n",
3774 path, load_count[path][0], load_count[path][1],
3775 load_count[path][2]);
3776 load_count[path][0]++;
3777 load_count[path][1 + port]++;
3778 BLOGI(sc, "NO MCP - new load counts[%d] %d, %d, %d\n",
3779 path, load_count[path][0], load_count[path][1],
3780 load_count[path][2]);
3781 if (load_count[path][0] == 1) {
3782 return (FW_MSG_CODE_DRV_LOAD_COMMON);
3783 } else if (load_count[path][1 + port] == 1) {
3784 return (FW_MSG_CODE_DRV_LOAD_PORT);
3786 return (FW_MSG_CODE_DRV_LOAD_FUNCTION);
3790 /* returns the "mcp load_code" according to global load_count array */
3792 bxe_nic_unload_no_mcp(struct bxe_softc *sc)
3794 int port = SC_PORT(sc);
3795 int path = SC_PATH(sc);
3797 BLOGI(sc, "NO MCP - load counts[%d] %d, %d, %d\n",
3798 path, load_count[path][0], load_count[path][1],
3799 load_count[path][2]);
3800 load_count[path][0]--;
3801 load_count[path][1 + port]--;
3802 BLOGI(sc, "NO MCP - new load counts[%d] %d, %d, %d\n",
3803 path, load_count[path][0], load_count[path][1],
3804 load_count[path][2]);
3805 if (load_count[path][0] == 0) {
3806 return (FW_MSG_CODE_DRV_UNLOAD_COMMON);
3807 } else if (load_count[path][1 + port] == 0) {
3808 return (FW_MSG_CODE_DRV_UNLOAD_PORT);
3810 return (FW_MSG_CODE_DRV_UNLOAD_FUNCTION);
3814 /* request unload mode from the MCP: COMMON, PORT or FUNCTION */
3816 bxe_send_unload_req(struct bxe_softc *sc,
3819 uint32_t reset_code = 0;
3821 /* Select the UNLOAD request mode */
3822 if (unload_mode == UNLOAD_NORMAL) {
3823 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
3825 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
3828 /* Send the request to the MCP */
3829 if (!BXE_NOMCP(sc)) {
3830 reset_code = bxe_fw_command(sc, reset_code, 0);
3832 reset_code = bxe_nic_unload_no_mcp(sc);
3835 return (reset_code);
3838 /* send UNLOAD_DONE command to the MCP */
3840 bxe_send_unload_done(struct bxe_softc *sc,
3843 uint32_t reset_param =
3844 keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
3846 /* Report UNLOAD_DONE to MCP */
3847 if (!BXE_NOMCP(sc)) {
3848 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
3853 bxe_func_wait_started(struct bxe_softc *sc)
3857 if (!sc->port.pmf) {
3862 * (assumption: No Attention from MCP at this stage)
3863 * PMF probably in the middle of TX disable/enable transaction
3864 * 1. Sync IRS for default SB
3865 * 2. Sync SP queue - this guarantees us that attention handling started
3866 * 3. Wait, that TX disable/enable transaction completes
3868 * 1+2 guarantee that if DCBX attention was scheduled it already changed
3869 * pending bit of transaction from STARTED-->TX_STOPPED, if we already
3870 * received completion for the transaction the state is TX_STOPPED.
3871 * State will return to STARTED after completion of TX_STOPPED-->STARTED
3875 /* XXX make sure default SB ISR is done */
3876 /* need a way to synchronize an irq (intr_mtx?) */
3878 /* XXX flush any work queues */
3880 while (ecore_func_get_state(sc, &sc->func_obj) !=
3881 ECORE_F_STATE_STARTED && tout--) {
3885 if (ecore_func_get_state(sc, &sc->func_obj) != ECORE_F_STATE_STARTED) {
3887 * Failed to complete the transaction in a "good way"
3888 * Force both transactions with CLR bit.
3890 struct ecore_func_state_params func_params = { NULL };
3892 BLOGE(sc, "Unexpected function state! "
3893 "Forcing STARTED-->TX_STOPPED-->STARTED\n");
3895 func_params.f_obj = &sc->func_obj;
3896 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
3898 /* STARTED-->TX_STOPPED */
3899 func_params.cmd = ECORE_F_CMD_TX_STOP;
3900 ecore_func_state_change(sc, &func_params);
3902 /* TX_STOPPED-->STARTED */
3903 func_params.cmd = ECORE_F_CMD_TX_START;
3904 return (ecore_func_state_change(sc, &func_params));
3911 bxe_stop_queue(struct bxe_softc *sc,
3914 struct bxe_fastpath *fp = &sc->fp[index];
3915 struct ecore_queue_state_params q_params = { NULL };
3918 BLOGD(sc, DBG_LOAD, "stopping queue %d cid %d\n", index, fp->index);
3920 q_params.q_obj = &sc->sp_objs[fp->index].q_obj;
3921 /* We want to wait for completion in this context */
3922 bxe_set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
3924 /* Stop the primary connection: */
3926 /* ...halt the connection */
3927 q_params.cmd = ECORE_Q_CMD_HALT;
3928 rc = ecore_queue_state_change(sc, &q_params);
3933 /* ...terminate the connection */
3934 q_params.cmd = ECORE_Q_CMD_TERMINATE;
3935 memset(&q_params.params.terminate, 0, sizeof(q_params.params.terminate));
3936 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
3937 rc = ecore_queue_state_change(sc, &q_params);
3942 /* ...delete cfc entry */
3943 q_params.cmd = ECORE_Q_CMD_CFC_DEL;
3944 memset(&q_params.params.cfc_del, 0, sizeof(q_params.params.cfc_del));
3945 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
3946 return (ecore_queue_state_change(sc, &q_params));
3949 /* wait for the outstanding SP commands */
3950 static inline uint8_t
3951 bxe_wait_sp_comp(struct bxe_softc *sc,
3955 int tout = 5000; /* wait for 5 secs tops */
3959 if (!(atomic_load_acq_long(&sc->sp_state) & mask)) {
3968 tmp = atomic_load_acq_long(&sc->sp_state);
3970 BLOGE(sc, "Filtering completion timed out: "
3971 "sp_state 0x%lx, mask 0x%lx\n",
3980 bxe_func_stop(struct bxe_softc *sc)
3982 struct ecore_func_state_params func_params = { NULL };
3985 /* prepare parameters for function state transitions */
3986 bxe_set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
3987 func_params.f_obj = &sc->func_obj;
3988 func_params.cmd = ECORE_F_CMD_STOP;
3991 * Try to stop the function the 'good way'. If it fails (in case
3992 * of a parity error during bxe_chip_cleanup()) and we are
3993 * not in a debug mode, perform a state transaction in order to
3994 * enable further HW_RESET transaction.
3996 rc = ecore_func_state_change(sc, &func_params);
3998 BLOGE(sc, "FUNC_STOP ramrod failed. "
3999 "Running a dry transaction (%d)\n", rc);
4000 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
4001 return (ecore_func_state_change(sc, &func_params));
4008 bxe_reset_hw(struct bxe_softc *sc,
4011 struct ecore_func_state_params func_params = { NULL };
4013 /* Prepare parameters for function state transitions */
4014 bxe_set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
4016 func_params.f_obj = &sc->func_obj;
4017 func_params.cmd = ECORE_F_CMD_HW_RESET;
4019 func_params.params.hw_init.load_phase = load_code;
4021 return (ecore_func_state_change(sc, &func_params));
4025 bxe_int_disable_sync(struct bxe_softc *sc,
4029 /* prevent the HW from sending interrupts */
4030 bxe_int_disable(sc);
4033 /* XXX need a way to synchronize ALL irqs (intr_mtx?) */
4034 /* make sure all ISRs are done */
4036 /* XXX make sure sp_task is not running */
4037 /* cancel and flush work queues */
4041 bxe_chip_cleanup(struct bxe_softc *sc,
4042 uint32_t unload_mode,
4045 int port = SC_PORT(sc);
4046 struct ecore_mcast_ramrod_params rparam = { NULL };
4047 uint32_t reset_code;
4050 bxe_drain_tx_queues(sc);
4052 /* give HW time to discard old tx messages */
4055 /* Clean all ETH MACs */
4056 rc = bxe_del_all_macs(sc, &sc->sp_objs[0].mac_obj, ECORE_ETH_MAC, FALSE);
4058 BLOGE(sc, "Failed to delete all ETH MACs (%d)\n", rc);
4061 /* Clean up UC list */
4062 rc = bxe_del_all_macs(sc, &sc->sp_objs[0].mac_obj, ECORE_UC_LIST_MAC, TRUE);
4064 BLOGE(sc, "Failed to delete UC MACs list (%d)\n", rc);
4068 if (!CHIP_IS_E1(sc)) {
4069 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 0);
4072 /* Set "drop all" to stop Rx */
4075 * We need to take the BXE_MCAST_LOCK() here in order to prevent
4076 * a race between the completion code and this code.
4080 if (bxe_test_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state)) {
4081 bxe_set_bit(ECORE_FILTER_RX_MODE_SCHED, &sc->sp_state);
4083 bxe_set_storm_rx_mode(sc);
4086 /* Clean up multicast configuration */
4087 rparam.mcast_obj = &sc->mcast_obj;
4088 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL);
4090 BLOGE(sc, "Failed to send DEL MCAST command (%d)\n", rc);
4093 BXE_MCAST_UNLOCK(sc);
4095 // XXX bxe_iov_chip_cleanup(sc);
4098 * Send the UNLOAD_REQUEST to the MCP. This will return if
4099 * this function should perform FUNCTION, PORT, or COMMON HW
4102 reset_code = bxe_send_unload_req(sc, unload_mode);
4105 * (assumption: No Attention from MCP at this stage)
4106 * PMF probably in the middle of TX disable/enable transaction
4108 rc = bxe_func_wait_started(sc);
4110 BLOGE(sc, "bxe_func_wait_started failed (%d)\n", rc);
4114 * Close multi and leading connections
4115 * Completions for ramrods are collected in a synchronous way
4117 for (i = 0; i < sc->num_queues; i++) {
4118 if (bxe_stop_queue(sc, i)) {
4124 * If SP settings didn't get completed so far - something
4125 * very wrong has happen.
4127 if (!bxe_wait_sp_comp(sc, ~0x0UL)) {
4128 BLOGE(sc, "Common slow path ramrods got stuck!(%d)\n", rc);
4133 rc = bxe_func_stop(sc);
4135 BLOGE(sc, "Function stop failed!(%d)\n", rc);
4138 /* disable HW interrupts */
4139 bxe_int_disable_sync(sc, TRUE);
4141 /* detach interrupts */
4142 bxe_interrupt_detach(sc);
4144 /* Reset the chip */
4145 rc = bxe_reset_hw(sc, reset_code);
4147 BLOGE(sc, "Hardware reset failed(%d)\n", rc);
4150 /* Report UNLOAD_DONE to MCP */
4151 bxe_send_unload_done(sc, keep_link);
4155 bxe_disable_close_the_gate(struct bxe_softc *sc)
4158 int port = SC_PORT(sc);
4161 "Disabling 'close the gates'\n");
4163 if (CHIP_IS_E1(sc)) {
4164 uint32_t addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4165 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4166 val = REG_RD(sc, addr);
4168 REG_WR(sc, addr, val);
4170 val = REG_RD(sc, MISC_REG_AEU_GENERAL_MASK);
4171 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
4172 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
4173 REG_WR(sc, MISC_REG_AEU_GENERAL_MASK, val);
4178 * Cleans the object that have internal lists without sending
4179 * ramrods. Should be run when interrutps are disabled.
4182 bxe_squeeze_objects(struct bxe_softc *sc)
4184 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
4185 struct ecore_mcast_ramrod_params rparam = { NULL };
4186 struct ecore_vlan_mac_obj *mac_obj = &sc->sp_objs->mac_obj;
4189 /* Cleanup MACs' object first... */
4191 /* Wait for completion of requested */
4192 bxe_set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
4193 /* Perform a dry cleanup */
4194 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &ramrod_flags);
4196 /* Clean ETH primary MAC */
4197 bxe_set_bit(ECORE_ETH_MAC, &vlan_mac_flags);
4198 rc = mac_obj->delete_all(sc, &sc->sp_objs->mac_obj, &vlan_mac_flags,
4201 BLOGE(sc, "Failed to clean ETH MACs (%d)\n", rc);
4204 /* Cleanup UC list */
4206 bxe_set_bit(ECORE_UC_LIST_MAC, &vlan_mac_flags);
4207 rc = mac_obj->delete_all(sc, mac_obj, &vlan_mac_flags,
4210 BLOGE(sc, "Failed to clean UC list MACs (%d)\n", rc);
4213 /* Now clean mcast object... */
4215 rparam.mcast_obj = &sc->mcast_obj;
4216 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &rparam.ramrod_flags);
4218 /* Add a DEL command... */
4219 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL);
4221 BLOGE(sc, "Failed to send DEL MCAST command (%d)\n", rc);
4224 /* now wait until all pending commands are cleared */
4226 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT);
4229 BLOGE(sc, "Failed to clean MCAST object (%d)\n", rc);
4233 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT);
4237 /* stop the controller */
4238 static __noinline int
4239 bxe_nic_unload(struct bxe_softc *sc,
4240 uint32_t unload_mode,
4243 uint8_t global = FALSE;
4247 BXE_CORE_LOCK_ASSERT(sc);
4249 sc->ifnet->if_drv_flags &= ~IFF_DRV_RUNNING;
4251 for (i = 0; i < sc->num_queues; i++) {
4252 struct bxe_fastpath *fp;
4255 fp->watchdog_timer = 0;
4257 BXE_FP_TX_UNLOCK(fp);
4260 BLOGD(sc, DBG_LOAD, "Starting NIC unload...\n");
4262 /* mark driver as unloaded in shmem2 */
4263 if (IS_PF(sc) && SHMEM2_HAS(sc, drv_capabilities_flag)) {
4264 val = SHMEM2_RD(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)]);
4265 SHMEM2_WR(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)],
4266 val & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
4269 if (IS_PF(sc) && sc->recovery_state != BXE_RECOVERY_DONE &&
4270 (sc->state == BXE_STATE_CLOSED || sc->state == BXE_STATE_ERROR)) {
4272 if(CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) {
4274 * We can get here if the driver has been unloaded
4275 * during parity error recovery and is either waiting for a
4276 * leader to complete or for other functions to unload and
4277 * then ifconfig down has been issued. In this case we want to
4278 * unload and let other functions to complete a recovery
4281 sc->recovery_state = BXE_RECOVERY_DONE;
4283 bxe_release_leader_lock(sc);
4285 BLOGD(sc, DBG_LOAD, "Releasing a leadership...\n");
4287 BLOGE(sc, "Can't unload in closed or error state recover_state 0x%x"
4288 " state = 0x%x\n", sc->recovery_state, sc->state);
4293 * Nothing to do during unload if previous bxe_nic_load()
4294 * did not completed succesfully - all resourses are released.
4296 if ((sc->state == BXE_STATE_CLOSED) ||
4297 (sc->state == BXE_STATE_ERROR)) {
4301 sc->state = BXE_STATE_CLOSING_WAITING_HALT;
4307 sc->rx_mode = BXE_RX_MODE_NONE;
4308 /* XXX set rx mode ??? */
4310 if (IS_PF(sc) && !sc->grcdump_done) {
4311 /* set ALWAYS_ALIVE bit in shmem */
4312 sc->fw_drv_pulse_wr_seq |= DRV_PULSE_ALWAYS_ALIVE;
4316 bxe_stats_handle(sc, STATS_EVENT_STOP);
4317 bxe_save_statistics(sc);
4320 /* wait till consumers catch up with producers in all queues */
4321 bxe_drain_tx_queues(sc);
4323 /* if VF indicate to PF this function is going down (PF will delete sp
4324 * elements and clear initializations
4327 ; /* bxe_vfpf_close_vf(sc); */
4328 } else if (unload_mode != UNLOAD_RECOVERY) {
4329 /* if this is a normal/close unload need to clean up chip */
4330 if (!sc->grcdump_done)
4331 bxe_chip_cleanup(sc, unload_mode, keep_link);
4333 /* Send the UNLOAD_REQUEST to the MCP */
4334 bxe_send_unload_req(sc, unload_mode);
4337 * Prevent transactions to host from the functions on the
4338 * engine that doesn't reset global blocks in case of global
4339 * attention once gloabl blocks are reset and gates are opened
4340 * (the engine which leader will perform the recovery
4343 if (!CHIP_IS_E1x(sc)) {
4347 /* disable HW interrupts */
4348 bxe_int_disable_sync(sc, TRUE);
4350 /* detach interrupts */
4351 bxe_interrupt_detach(sc);
4353 /* Report UNLOAD_DONE to MCP */
4354 bxe_send_unload_done(sc, FALSE);
4358 * At this stage no more interrupts will arrive so we may safely clean
4359 * the queue'able objects here in case they failed to get cleaned so far.
4362 bxe_squeeze_objects(sc);
4365 /* There should be no more pending SP commands at this stage */
4370 bxe_free_fp_buffers(sc);
4376 bxe_free_fw_stats_mem(sc);
4378 sc->state = BXE_STATE_CLOSED;
4381 * Check if there are pending parity attentions. If there are - set
4382 * RECOVERY_IN_PROGRESS.
4384 if (IS_PF(sc) && bxe_chk_parity_attn(sc, &global, FALSE)) {
4385 bxe_set_reset_in_progress(sc);
4387 /* Set RESET_IS_GLOBAL if needed */
4389 bxe_set_reset_global(sc);
4394 * The last driver must disable a "close the gate" if there is no
4395 * parity attention or "process kill" pending.
4397 if (IS_PF(sc) && !bxe_clear_pf_load(sc) &&
4398 bxe_reset_is_done(sc, SC_PATH(sc))) {
4399 bxe_disable_close_the_gate(sc);
4402 BLOGD(sc, DBG_LOAD, "Ended NIC unload\n");
4404 bxe_link_report(sc);
4410 * Called by the OS to set various media options (i.e. link, speed, etc.) when
4411 * the user runs "ifconfig bxe media ..." or "ifconfig bxe mediaopt ...".
4414 bxe_ifmedia_update(struct ifnet *ifp)
4416 struct bxe_softc *sc = (struct bxe_softc *)ifp->if_softc;
4417 struct ifmedia *ifm;
4421 /* We only support Ethernet media type. */
4422 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) {
4426 switch (IFM_SUBTYPE(ifm->ifm_media)) {
4432 case IFM_10G_TWINAX:
4434 /* We don't support changing the media type. */
4435 BLOGD(sc, DBG_LOAD, "Invalid media type (%d)\n",
4436 IFM_SUBTYPE(ifm->ifm_media));
4444 * Called by the OS to get the current media status (i.e. link, speed, etc.).
4447 bxe_ifmedia_status(struct ifnet *ifp, struct ifmediareq *ifmr)
4449 struct bxe_softc *sc = ifp->if_softc;
4451 /* Bug 165447: the 'ifconfig' tool skips printing of the "status: ..."
4452 line if the IFM_AVALID flag is *NOT* set. So we need to set this
4453 flag unconditionally (irrespective of the admininistrative
4454 'up/down' state of the interface) to ensure that that line is always
4457 ifmr->ifm_status = IFM_AVALID;
4459 /* Setup the default interface info. */
4460 ifmr->ifm_active = IFM_ETHER;
4462 /* Report link down if the driver isn't running. */
4463 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
4464 ifmr->ifm_active |= IFM_NONE;
4465 BLOGD(sc, DBG_PHY, "in %s : nic still not loaded fully\n", __func__);
4466 BLOGD(sc, DBG_PHY, "in %s : link_up (1) : %d\n",
4467 __func__, sc->link_vars.link_up);
4472 if (sc->link_vars.link_up) {
4473 ifmr->ifm_status |= IFM_ACTIVE;
4474 ifmr->ifm_active |= IFM_FDX;
4476 ifmr->ifm_active |= IFM_NONE;
4477 BLOGD(sc, DBG_PHY, "in %s : setting IFM_NONE\n",
4482 ifmr->ifm_active |= sc->media;
4487 bxe_handle_chip_tq(void *context,
4490 struct bxe_softc *sc = (struct bxe_softc *)context;
4491 long work = atomic_load_acq_long(&sc->chip_tq_flags);
4495 case CHIP_TQ_REINIT:
4496 if (sc->ifnet->if_drv_flags & IFF_DRV_RUNNING) {
4497 /* restart the interface */
4498 BLOGD(sc, DBG_LOAD, "Restarting the interface...\n");
4499 bxe_periodic_stop(sc);
4501 bxe_stop_locked(sc);
4502 bxe_init_locked(sc);
4503 BXE_CORE_UNLOCK(sc);
4513 * Handles any IOCTL calls from the operating system.
4516 * 0 = Success, >0 Failure
4519 bxe_ioctl(struct ifnet *ifp,
4523 struct bxe_softc *sc = ifp->if_softc;
4524 struct ifreq *ifr = (struct ifreq *)data;
4529 int mtu_min = (ETH_MIN_PACKET_SIZE - ETH_HLEN);
4530 int mtu_max = (MJUM9BYTES - ETH_OVERHEAD - IP_HEADER_ALIGNMENT_PADDING);
4535 BLOGD(sc, DBG_IOCTL, "Received SIOCSIFMTU ioctl (mtu=%d)\n",
4538 if (sc->mtu == ifr->ifr_mtu) {
4539 /* nothing to change */
4543 if ((ifr->ifr_mtu < mtu_min) || (ifr->ifr_mtu > mtu_max)) {
4544 BLOGE(sc, "Unsupported MTU size %d (range is %d-%d)\n",
4545 ifr->ifr_mtu, mtu_min, mtu_max);
4550 atomic_store_rel_int((volatile unsigned int *)&sc->mtu,
4551 (unsigned long)ifr->ifr_mtu);
4552 atomic_store_rel_long((volatile unsigned long *)&ifp->if_mtu,
4553 (unsigned long)ifr->ifr_mtu);
4559 /* toggle the interface state up or down */
4560 BLOGD(sc, DBG_IOCTL, "Received SIOCSIFFLAGS ioctl\n");
4563 /* check if the interface is up */
4564 if (ifp->if_flags & IFF_UP) {
4565 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
4566 /* set the receive mode flags */
4567 bxe_set_rx_mode(sc);
4568 } else if(sc->state != BXE_STATE_DISABLED) {
4569 bxe_init_locked(sc);
4572 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
4573 bxe_periodic_stop(sc);
4574 bxe_stop_locked(sc);
4577 BXE_CORE_UNLOCK(sc);
4583 /* add/delete multicast addresses */
4584 BLOGD(sc, DBG_IOCTL, "Received SIOCADDMULTI/SIOCDELMULTI ioctl\n");
4586 /* check if the interface is up */
4587 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
4588 /* set the receive mode flags */
4590 bxe_set_rx_mode(sc);
4591 BXE_CORE_UNLOCK(sc);
4597 /* find out which capabilities have changed */
4598 mask = (ifr->ifr_reqcap ^ ifp->if_capenable);
4600 BLOGD(sc, DBG_IOCTL, "Received SIOCSIFCAP ioctl (mask=0x%08x)\n",
4603 /* toggle the LRO capabilites enable flag */
4604 if (mask & IFCAP_LRO) {
4605 ifp->if_capenable ^= IFCAP_LRO;
4606 BLOGD(sc, DBG_IOCTL, "Turning LRO %s\n",
4607 (ifp->if_capenable & IFCAP_LRO) ? "ON" : "OFF");
4611 /* toggle the TXCSUM checksum capabilites enable flag */
4612 if (mask & IFCAP_TXCSUM) {
4613 ifp->if_capenable ^= IFCAP_TXCSUM;
4614 BLOGD(sc, DBG_IOCTL, "Turning TXCSUM %s\n",
4615 (ifp->if_capenable & IFCAP_TXCSUM) ? "ON" : "OFF");
4616 if (ifp->if_capenable & IFCAP_TXCSUM) {
4617 ifp->if_hwassist = (CSUM_IP |
4624 ifp->if_hwassist = 0;
4628 /* toggle the RXCSUM checksum capabilities enable flag */
4629 if (mask & IFCAP_RXCSUM) {
4630 ifp->if_capenable ^= IFCAP_RXCSUM;
4631 BLOGD(sc, DBG_IOCTL, "Turning RXCSUM %s\n",
4632 (ifp->if_capenable & IFCAP_RXCSUM) ? "ON" : "OFF");
4633 if (ifp->if_capenable & IFCAP_RXCSUM) {
4634 ifp->if_hwassist = (CSUM_IP |
4641 ifp->if_hwassist = 0;
4645 /* toggle TSO4 capabilities enabled flag */
4646 if (mask & IFCAP_TSO4) {
4647 ifp->if_capenable ^= IFCAP_TSO4;
4648 BLOGD(sc, DBG_IOCTL, "Turning TSO4 %s\n",
4649 (ifp->if_capenable & IFCAP_TSO4) ? "ON" : "OFF");
4652 /* toggle TSO6 capabilities enabled flag */
4653 if (mask & IFCAP_TSO6) {
4654 ifp->if_capenable ^= IFCAP_TSO6;
4655 BLOGD(sc, DBG_IOCTL, "Turning TSO6 %s\n",
4656 (ifp->if_capenable & IFCAP_TSO6) ? "ON" : "OFF");
4659 /* toggle VLAN_HWTSO capabilities enabled flag */
4660 if (mask & IFCAP_VLAN_HWTSO) {
4661 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
4662 BLOGD(sc, DBG_IOCTL, "Turning VLAN_HWTSO %s\n",
4663 (ifp->if_capenable & IFCAP_VLAN_HWTSO) ? "ON" : "OFF");
4666 /* toggle VLAN_HWCSUM capabilities enabled flag */
4667 if (mask & IFCAP_VLAN_HWCSUM) {
4668 /* XXX investigate this... */
4669 BLOGE(sc, "Changing VLAN_HWCSUM is not supported!\n");
4673 /* toggle VLAN_MTU capabilities enable flag */
4674 if (mask & IFCAP_VLAN_MTU) {
4675 /* XXX investigate this... */
4676 BLOGE(sc, "Changing VLAN_MTU is not supported!\n");
4680 /* toggle VLAN_HWTAGGING capabilities enabled flag */
4681 if (mask & IFCAP_VLAN_HWTAGGING) {
4682 /* XXX investigate this... */
4683 BLOGE(sc, "Changing VLAN_HWTAGGING is not supported!\n");
4687 /* toggle VLAN_HWFILTER capabilities enabled flag */
4688 if (mask & IFCAP_VLAN_HWFILTER) {
4689 /* XXX investigate this... */
4690 BLOGE(sc, "Changing VLAN_HWFILTER is not supported!\n");
4702 /* set/get interface media */
4703 BLOGD(sc, DBG_IOCTL,
4704 "Received SIOCSIFMEDIA/SIOCGIFMEDIA ioctl (cmd=%lu)\n",
4706 error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, command);
4710 BLOGD(sc, DBG_IOCTL, "Received Unknown Ioctl (cmd=%lu)\n",
4712 error = ether_ioctl(ifp, command, data);
4716 if (reinit && (sc->ifnet->if_drv_flags & IFF_DRV_RUNNING)) {
4717 BLOGD(sc, DBG_LOAD | DBG_IOCTL,
4718 "Re-initializing hardware from IOCTL change\n");
4719 bxe_periodic_stop(sc);
4721 bxe_stop_locked(sc);
4722 bxe_init_locked(sc);
4723 BXE_CORE_UNLOCK(sc);
4729 static __noinline void
4730 bxe_dump_mbuf(struct bxe_softc *sc,
4737 if (!(sc->debug & DBG_MBUF)) {
4742 BLOGD(sc, DBG_MBUF, "mbuf: null pointer\n");
4748 #if __FreeBSD_version >= 1000000
4750 "%02d: mbuf=%p m_len=%d m_flags=0x%b m_data=%p\n",
4751 i, m, m->m_len, m->m_flags,
4752 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY", m->m_data);
4754 if (m->m_flags & M_PKTHDR) {
4756 "%02d: - m_pkthdr: tot_len=%d flags=0x%b csum_flags=%b\n",
4757 i, m->m_pkthdr.len, m->m_flags,
4758 "\20\12M_BCAST\13M_MCAST\14M_FRAG"
4759 "\15M_FIRSTFRAG\16M_LASTFRAG\21M_VLANTAG"
4760 "\22M_PROMISC\23M_NOFREE",
4761 (int)m->m_pkthdr.csum_flags,
4762 "\20\1CSUM_IP\2CSUM_TCP\3CSUM_UDP\4CSUM_IP_FRAGS"
4763 "\5CSUM_FRAGMENT\6CSUM_TSO\11CSUM_IP_CHECKED"
4764 "\12CSUM_IP_VALID\13CSUM_DATA_VALID"
4765 "\14CSUM_PSEUDO_HDR");
4769 "%02d: mbuf=%p m_len=%d m_flags=0x%b m_data=%p\n",
4770 i, m, m->m_len, m->m_flags,
4771 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY", m->m_data);
4773 if (m->m_flags & M_PKTHDR) {
4775 "%02d: - m_pkthdr: tot_len=%d flags=0x%b csum_flags=%b\n",
4776 i, m->m_pkthdr.len, m->m_flags,
4777 "\20\12M_BCAST\13M_MCAST\14M_FRAG"
4778 "\15M_FIRSTFRAG\16M_LASTFRAG\21M_VLANTAG"
4779 "\22M_PROMISC\23M_NOFREE",
4780 (int)m->m_pkthdr.csum_flags,
4781 "\20\1CSUM_IP\2CSUM_TCP\3CSUM_UDP\4CSUM_IP_FRAGS"
4782 "\5CSUM_FRAGMENT\6CSUM_TSO\11CSUM_IP_CHECKED"
4783 "\12CSUM_IP_VALID\13CSUM_DATA_VALID"
4784 "\14CSUM_PSEUDO_HDR");
4786 #endif /* #if __FreeBSD_version >= 1000000 */
4788 if (m->m_flags & M_EXT) {
4789 switch (m->m_ext.ext_type) {
4790 case EXT_CLUSTER: type = "EXT_CLUSTER"; break;
4791 case EXT_SFBUF: type = "EXT_SFBUF"; break;
4792 case EXT_JUMBOP: type = "EXT_JUMBOP"; break;
4793 case EXT_JUMBO9: type = "EXT_JUMBO9"; break;
4794 case EXT_JUMBO16: type = "EXT_JUMBO16"; break;
4795 case EXT_PACKET: type = "EXT_PACKET"; break;
4796 case EXT_MBUF: type = "EXT_MBUF"; break;
4797 case EXT_NET_DRV: type = "EXT_NET_DRV"; break;
4798 case EXT_MOD_TYPE: type = "EXT_MOD_TYPE"; break;
4799 case EXT_DISPOSABLE: type = "EXT_DISPOSABLE"; break;
4800 case EXT_EXTREF: type = "EXT_EXTREF"; break;
4801 default: type = "UNKNOWN"; break;
4805 "%02d: - m_ext: %p ext_size=%d type=%s\n",
4806 i, m->m_ext.ext_buf, m->m_ext.ext_size, type);
4810 bxe_dump_mbuf_data(sc, "mbuf data", m, TRUE);
4819 * Checks to ensure the 13 bd sliding window is >= MSS for TSO.
4820 * Check that (13 total bds - 3 bds) = 10 bd window >= MSS.
4821 * The window: 3 bds are = 1 for headers BD + 2 for parse BD and last BD
4822 * The headers comes in a seperate bd in FreeBSD so 13-3=10.
4823 * Returns: 0 if OK to send, 1 if packet needs further defragmentation
4826 bxe_chktso_window(struct bxe_softc *sc,
4828 bus_dma_segment_t *segs,
4831 uint32_t num_wnds, wnd_size, wnd_sum;
4832 int32_t frag_idx, wnd_idx;
4833 unsigned short lso_mss;
4839 num_wnds = nsegs - wnd_size;
4840 lso_mss = htole16(m->m_pkthdr.tso_segsz);
4843 * Total header lengths Eth+IP+TCP in first FreeBSD mbuf so calculate the
4844 * first window sum of data while skipping the first assuming it is the
4845 * header in FreeBSD.
4847 for (frag_idx = 1; (frag_idx <= wnd_size); frag_idx++) {
4848 wnd_sum += htole16(segs[frag_idx].ds_len);
4851 /* check the first 10 bd window size */
4852 if (wnd_sum < lso_mss) {
4856 /* run through the windows */
4857 for (wnd_idx = 0; wnd_idx < num_wnds; wnd_idx++, frag_idx++) {
4858 /* subtract the first mbuf->m_len of the last wndw(-header) */
4859 wnd_sum -= htole16(segs[wnd_idx+1].ds_len);
4860 /* add the next mbuf len to the len of our new window */
4861 wnd_sum += htole16(segs[frag_idx].ds_len);
4862 if (wnd_sum < lso_mss) {
4871 bxe_set_pbd_csum_e2(struct bxe_fastpath *fp,
4873 uint32_t *parsing_data)
4875 struct ether_vlan_header *eh = NULL;
4876 struct ip *ip4 = NULL;
4877 struct ip6_hdr *ip6 = NULL;
4879 struct tcphdr *th = NULL;
4880 int e_hlen, ip_hlen, l4_off;
4883 if (m->m_pkthdr.csum_flags == CSUM_IP) {
4884 /* no L4 checksum offload needed */
4888 /* get the Ethernet header */
4889 eh = mtod(m, struct ether_vlan_header *);
4891 /* handle VLAN encapsulation if present */
4892 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
4893 e_hlen = (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN);
4894 proto = ntohs(eh->evl_proto);
4896 e_hlen = ETHER_HDR_LEN;
4897 proto = ntohs(eh->evl_encap_proto);
4902 /* get the IP header, if mbuf len < 20 then header in next mbuf */
4903 ip4 = (m->m_len < sizeof(struct ip)) ?
4904 (struct ip *)m->m_next->m_data :
4905 (struct ip *)(m->m_data + e_hlen);
4906 /* ip_hl is number of 32-bit words */
4907 ip_hlen = (ip4->ip_hl << 2);
4910 case ETHERTYPE_IPV6:
4911 /* get the IPv6 header, if mbuf len < 40 then header in next mbuf */
4912 ip6 = (m->m_len < sizeof(struct ip6_hdr)) ?
4913 (struct ip6_hdr *)m->m_next->m_data :
4914 (struct ip6_hdr *)(m->m_data + e_hlen);
4915 /* XXX cannot support offload with IPv6 extensions */
4916 ip_hlen = sizeof(struct ip6_hdr);
4920 /* We can't offload in this case... */
4921 /* XXX error stat ??? */
4925 /* XXX assuming L4 header is contiguous to IPv4/IPv6 in the same mbuf */
4926 l4_off = (e_hlen + ip_hlen);
4929 (((l4_off >> 1) << ETH_TX_PARSE_BD_E2_L4_HDR_START_OFFSET_W_SHIFT) &
4930 ETH_TX_PARSE_BD_E2_L4_HDR_START_OFFSET_W);
4932 if (m->m_pkthdr.csum_flags & (CSUM_TCP |
4935 fp->eth_q_stats.tx_ofld_frames_csum_tcp++;
4936 th = (struct tcphdr *)(ip + ip_hlen);
4937 /* th_off is number of 32-bit words */
4938 *parsing_data |= ((th->th_off <<
4939 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW_SHIFT) &
4940 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW);
4941 return (l4_off + (th->th_off << 2)); /* entire header length */
4942 } else if (m->m_pkthdr.csum_flags & (CSUM_UDP |
4944 fp->eth_q_stats.tx_ofld_frames_csum_udp++;
4945 return (l4_off + sizeof(struct udphdr)); /* entire header length */
4947 /* XXX error stat ??? */
4953 bxe_set_pbd_csum(struct bxe_fastpath *fp,
4955 struct eth_tx_parse_bd_e1x *pbd)
4957 struct ether_vlan_header *eh = NULL;
4958 struct ip *ip4 = NULL;
4959 struct ip6_hdr *ip6 = NULL;
4961 struct tcphdr *th = NULL;
4962 struct udphdr *uh = NULL;
4963 int e_hlen, ip_hlen;
4969 /* get the Ethernet header */
4970 eh = mtod(m, struct ether_vlan_header *);
4972 /* handle VLAN encapsulation if present */
4973 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
4974 e_hlen = (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN);
4975 proto = ntohs(eh->evl_proto);
4977 e_hlen = ETHER_HDR_LEN;
4978 proto = ntohs(eh->evl_encap_proto);
4983 /* get the IP header, if mbuf len < 20 then header in next mbuf */
4984 ip4 = (m->m_len < sizeof(struct ip)) ?
4985 (struct ip *)m->m_next->m_data :
4986 (struct ip *)(m->m_data + e_hlen);
4987 /* ip_hl is number of 32-bit words */
4988 ip_hlen = (ip4->ip_hl << 1);
4991 case ETHERTYPE_IPV6:
4992 /* get the IPv6 header, if mbuf len < 40 then header in next mbuf */
4993 ip6 = (m->m_len < sizeof(struct ip6_hdr)) ?
4994 (struct ip6_hdr *)m->m_next->m_data :
4995 (struct ip6_hdr *)(m->m_data + e_hlen);
4996 /* XXX cannot support offload with IPv6 extensions */
4997 ip_hlen = (sizeof(struct ip6_hdr) >> 1);
5001 /* We can't offload in this case... */
5002 /* XXX error stat ??? */
5006 hlen = (e_hlen >> 1);
5008 /* note that rest of global_data is indirectly zeroed here */
5009 if (m->m_flags & M_VLANTAG) {
5011 htole16(hlen | (1 << ETH_TX_PARSE_BD_E1X_LLC_SNAP_EN_SHIFT));
5013 pbd->global_data = htole16(hlen);
5016 pbd->ip_hlen_w = ip_hlen;
5018 hlen += pbd->ip_hlen_w;
5020 /* XXX assuming L4 header is contiguous to IPv4/IPv6 in the same mbuf */
5022 if (m->m_pkthdr.csum_flags & (CSUM_TCP |
5025 th = (struct tcphdr *)(ip + (ip_hlen << 1));
5026 /* th_off is number of 32-bit words */
5027 hlen += (uint16_t)(th->th_off << 1);
5028 } else if (m->m_pkthdr.csum_flags & (CSUM_UDP |
5030 uh = (struct udphdr *)(ip + (ip_hlen << 1));
5031 hlen += (sizeof(struct udphdr) / 2);
5033 /* valid case as only CSUM_IP was set */
5037 pbd->total_hlen_w = htole16(hlen);
5039 if (m->m_pkthdr.csum_flags & (CSUM_TCP |
5042 fp->eth_q_stats.tx_ofld_frames_csum_tcp++;
5043 pbd->tcp_pseudo_csum = ntohs(th->th_sum);
5044 } else if (m->m_pkthdr.csum_flags & (CSUM_UDP |
5046 fp->eth_q_stats.tx_ofld_frames_csum_udp++;
5049 * Everest1 (i.e. 57710, 57711, 57711E) does not natively support UDP
5050 * checksums and does not know anything about the UDP header and where
5051 * the checksum field is located. It only knows about TCP. Therefore
5052 * we "lie" to the hardware for outgoing UDP packets w/ checksum
5053 * offload. Since the checksum field offset for TCP is 16 bytes and
5054 * for UDP it is 6 bytes we pass a pointer to the hardware that is 10
5055 * bytes less than the start of the UDP header. This allows the
5056 * hardware to write the checksum in the correct spot. But the
5057 * hardware will compute a checksum which includes the last 10 bytes
5058 * of the IP header. To correct this we tweak the stack computed
5059 * pseudo checksum by folding in the calculation of the inverse
5060 * checksum for those final 10 bytes of the IP header. This allows
5061 * the correct checksum to be computed by the hardware.
5064 /* set pointer 10 bytes before UDP header */
5065 tmp_uh = (uint32_t *)((uint8_t *)uh - 10);
5067 /* calculate a pseudo header checksum over the first 10 bytes */
5068 tmp_csum = in_pseudo(*tmp_uh,
5070 *(uint16_t *)(tmp_uh + 2));
5072 pbd->tcp_pseudo_csum = ntohs(in_addword(uh->uh_sum, ~tmp_csum));
5075 return (hlen * 2); /* entire header length, number of bytes */
5079 bxe_set_pbd_lso_e2(struct mbuf *m,
5080 uint32_t *parsing_data)
5082 *parsing_data |= ((m->m_pkthdr.tso_segsz <<
5083 ETH_TX_PARSE_BD_E2_LSO_MSS_SHIFT) &
5084 ETH_TX_PARSE_BD_E2_LSO_MSS);
5086 /* XXX test for IPv6 with extension header... */
5090 bxe_set_pbd_lso(struct mbuf *m,
5091 struct eth_tx_parse_bd_e1x *pbd)
5093 struct ether_vlan_header *eh = NULL;
5094 struct ip *ip = NULL;
5095 struct tcphdr *th = NULL;
5098 /* get the Ethernet header */
5099 eh = mtod(m, struct ether_vlan_header *);
5101 /* handle VLAN encapsulation if present */
5102 e_hlen = (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) ?
5103 (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN) : ETHER_HDR_LEN;
5105 /* get the IP and TCP header, with LSO entire header in first mbuf */
5106 /* XXX assuming IPv4 */
5107 ip = (struct ip *)(m->m_data + e_hlen);
5108 th = (struct tcphdr *)((caddr_t)ip + (ip->ip_hl << 2));
5110 pbd->lso_mss = htole16(m->m_pkthdr.tso_segsz);
5111 pbd->tcp_send_seq = ntohl(th->th_seq);
5112 pbd->tcp_flags = ((ntohl(((uint32_t *)th)[3]) >> 16) & 0xff);
5116 pbd->ip_id = ntohs(ip->ip_id);
5117 pbd->tcp_pseudo_csum =
5118 ntohs(in_pseudo(ip->ip_src.s_addr,
5120 htons(IPPROTO_TCP)));
5123 pbd->tcp_pseudo_csum =
5124 ntohs(in_pseudo(&ip6->ip6_src,
5126 htons(IPPROTO_TCP)));
5130 htole16(ETH_TX_PARSE_BD_E1X_PSEUDO_CS_WITHOUT_LEN);
5134 * Encapsulte an mbuf cluster into the tx bd chain and makes the memory
5135 * visible to the controller.
5137 * If an mbuf is submitted to this routine and cannot be given to the
5138 * controller (e.g. it has too many fragments) then the function may free
5139 * the mbuf and return to the caller.
5142 * 0 = Success, !0 = Failure
5143 * Note the side effect that an mbuf may be freed if it causes a problem.
5146 bxe_tx_encap(struct bxe_fastpath *fp, struct mbuf **m_head)
5148 bus_dma_segment_t segs[32];
5150 struct bxe_sw_tx_bd *tx_buf;
5151 struct eth_tx_parse_bd_e1x *pbd_e1x = NULL;
5152 struct eth_tx_parse_bd_e2 *pbd_e2 = NULL;
5153 /* struct eth_tx_parse_2nd_bd *pbd2 = NULL; */
5154 struct eth_tx_bd *tx_data_bd;
5155 struct eth_tx_bd *tx_total_pkt_size_bd;
5156 struct eth_tx_start_bd *tx_start_bd;
5157 uint16_t bd_prod, pkt_prod, total_pkt_size;
5159 int defragged, error, nsegs, rc, nbds, vlan_off, ovlan;
5160 struct bxe_softc *sc;
5161 uint16_t tx_bd_avail;
5162 struct ether_vlan_header *eh;
5163 uint32_t pbd_e2_parsing_data = 0;
5170 #if __FreeBSD_version >= 800000
5171 M_ASSERTPKTHDR(*m_head);
5172 #endif /* #if __FreeBSD_version >= 800000 */
5175 rc = defragged = nbds = ovlan = vlan_off = total_pkt_size = 0;
5178 tx_total_pkt_size_bd = NULL;
5180 /* get the H/W pointer for packets and BDs */
5181 pkt_prod = fp->tx_pkt_prod;
5182 bd_prod = fp->tx_bd_prod;
5184 mac_type = UNICAST_ADDRESS;
5186 /* map the mbuf into the next open DMAable memory */
5187 tx_buf = &fp->tx_mbuf_chain[TX_BD(pkt_prod)];
5188 error = bus_dmamap_load_mbuf_sg(fp->tx_mbuf_tag,
5190 segs, &nsegs, BUS_DMA_NOWAIT);
5192 /* mapping errors */
5193 if(__predict_false(error != 0)) {
5194 fp->eth_q_stats.tx_dma_mapping_failure++;
5195 if (error == ENOMEM) {
5196 /* resource issue, try again later */
5198 } else if (error == EFBIG) {
5199 /* possibly recoverable with defragmentation */
5200 fp->eth_q_stats.mbuf_defrag_attempts++;
5201 m0 = m_defrag(*m_head, M_DONTWAIT);
5203 fp->eth_q_stats.mbuf_defrag_failures++;
5206 /* defrag successful, try mapping again */
5208 error = bus_dmamap_load_mbuf_sg(fp->tx_mbuf_tag,
5210 segs, &nsegs, BUS_DMA_NOWAIT);
5212 fp->eth_q_stats.tx_dma_mapping_failure++;
5217 /* unknown, unrecoverable mapping error */
5218 BLOGE(sc, "Unknown TX mapping error rc=%d\n", error);
5219 bxe_dump_mbuf(sc, m0, FALSE);
5223 goto bxe_tx_encap_continue;
5226 tx_bd_avail = bxe_tx_avail(sc, fp);
5228 /* make sure there is enough room in the send queue */
5229 if (__predict_false(tx_bd_avail < (nsegs + 2))) {
5230 /* Recoverable, try again later. */
5231 fp->eth_q_stats.tx_hw_queue_full++;
5232 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
5234 goto bxe_tx_encap_continue;
5237 /* capture the current H/W TX chain high watermark */
5238 if (__predict_false(fp->eth_q_stats.tx_hw_max_queue_depth <
5239 (TX_BD_USABLE - tx_bd_avail))) {
5240 fp->eth_q_stats.tx_hw_max_queue_depth = (TX_BD_USABLE - tx_bd_avail);
5243 /* make sure it fits in the packet window */
5244 if (__predict_false(nsegs > BXE_MAX_SEGMENTS)) {
5246 * The mbuf may be to big for the controller to handle. If the frame
5247 * is a TSO frame we'll need to do an additional check.
5249 if (m0->m_pkthdr.csum_flags & CSUM_TSO) {
5250 if (bxe_chktso_window(sc, nsegs, segs, m0) == 0) {
5251 goto bxe_tx_encap_continue; /* OK to send */
5253 fp->eth_q_stats.tx_window_violation_tso++;
5256 fp->eth_q_stats.tx_window_violation_std++;
5259 /* lets try to defragment this mbuf and remap it */
5260 fp->eth_q_stats.mbuf_defrag_attempts++;
5261 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
5263 m0 = m_defrag(*m_head, M_DONTWAIT);
5265 fp->eth_q_stats.mbuf_defrag_failures++;
5266 /* Ugh, just drop the frame... :( */
5269 /* defrag successful, try mapping again */
5271 error = bus_dmamap_load_mbuf_sg(fp->tx_mbuf_tag,
5273 segs, &nsegs, BUS_DMA_NOWAIT);
5275 fp->eth_q_stats.tx_dma_mapping_failure++;
5276 /* No sense in trying to defrag/copy chain, drop it. :( */
5279 /* if the chain is still too long then drop it */
5280 if(m0->m_pkthdr.csum_flags & CSUM_TSO) {
5282 * in case TSO is enabled nsegs should be checked against
5283 * BXE_TSO_MAX_SEGMENTS
5285 if (__predict_false(nsegs > BXE_TSO_MAX_SEGMENTS)) {
5286 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
5287 fp->eth_q_stats.nsegs_path1_errors++;
5291 if (__predict_false(nsegs > BXE_MAX_SEGMENTS)) {
5292 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
5293 fp->eth_q_stats.nsegs_path2_errors++;
5301 bxe_tx_encap_continue:
5303 /* Check for errors */
5306 /* recoverable try again later */
5308 fp->eth_q_stats.tx_soft_errors++;
5309 fp->eth_q_stats.mbuf_alloc_tx--;
5317 /* set flag according to packet type (UNICAST_ADDRESS is default) */
5318 if (m0->m_flags & M_BCAST) {
5319 mac_type = BROADCAST_ADDRESS;
5320 } else if (m0->m_flags & M_MCAST) {
5321 mac_type = MULTICAST_ADDRESS;
5324 /* store the mbuf into the mbuf ring */
5326 tx_buf->first_bd = fp->tx_bd_prod;
5329 /* prepare the first transmit (start) BD for the mbuf */
5330 tx_start_bd = &fp->tx_chain[TX_BD(bd_prod)].start_bd;
5333 "sending pkt_prod=%u tx_buf=%p next_idx=%u bd=%u tx_start_bd=%p\n",
5334 pkt_prod, tx_buf, fp->tx_pkt_prod, bd_prod, tx_start_bd);
5336 tx_start_bd->addr_lo = htole32(U64_LO(segs[0].ds_addr));
5337 tx_start_bd->addr_hi = htole32(U64_HI(segs[0].ds_addr));
5338 tx_start_bd->nbytes = htole16(segs[0].ds_len);
5339 total_pkt_size += tx_start_bd->nbytes;
5340 tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
5342 tx_start_bd->general_data = (1 << ETH_TX_START_BD_HDR_NBDS_SHIFT);
5344 /* all frames have at least Start BD + Parsing BD */
5346 tx_start_bd->nbd = htole16(nbds);
5348 if (m0->m_flags & M_VLANTAG) {
5349 tx_start_bd->vlan_or_ethertype = htole16(m0->m_pkthdr.ether_vtag);
5350 tx_start_bd->bd_flags.as_bitfield |=
5351 (X_ETH_OUTBAND_VLAN << ETH_TX_BD_FLAGS_VLAN_MODE_SHIFT);
5353 /* vf tx, start bd must hold the ethertype for fw to enforce it */
5355 /* map ethernet header to find type and header length */
5356 eh = mtod(m0, struct ether_vlan_header *);
5357 tx_start_bd->vlan_or_ethertype = eh->evl_encap_proto;
5359 /* used by FW for packet accounting */
5360 tx_start_bd->vlan_or_ethertype = htole16(fp->tx_pkt_prod);
5365 * add a parsing BD from the chain. The parsing BD is always added
5366 * though it is only used for TSO and chksum
5368 bd_prod = TX_BD_NEXT(bd_prod);
5370 if (m0->m_pkthdr.csum_flags) {
5371 if (m0->m_pkthdr.csum_flags & CSUM_IP) {
5372 fp->eth_q_stats.tx_ofld_frames_csum_ip++;
5373 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_IP_CSUM;
5376 if (m0->m_pkthdr.csum_flags & CSUM_TCP_IPV6) {
5377 tx_start_bd->bd_flags.as_bitfield |= (ETH_TX_BD_FLAGS_IPV6 |
5378 ETH_TX_BD_FLAGS_L4_CSUM);
5379 } else if (m0->m_pkthdr.csum_flags & CSUM_UDP_IPV6) {
5380 tx_start_bd->bd_flags.as_bitfield |= (ETH_TX_BD_FLAGS_IPV6 |
5381 ETH_TX_BD_FLAGS_IS_UDP |
5382 ETH_TX_BD_FLAGS_L4_CSUM);
5383 } else if ((m0->m_pkthdr.csum_flags & CSUM_TCP) ||
5384 (m0->m_pkthdr.csum_flags & CSUM_TSO)) {
5385 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_L4_CSUM;
5386 } else if (m0->m_pkthdr.csum_flags & CSUM_UDP) {
5387 tx_start_bd->bd_flags.as_bitfield |= (ETH_TX_BD_FLAGS_L4_CSUM |
5388 ETH_TX_BD_FLAGS_IS_UDP);
5392 if (!CHIP_IS_E1x(sc)) {
5393 pbd_e2 = &fp->tx_chain[TX_BD(bd_prod)].parse_bd_e2;
5394 memset(pbd_e2, 0, sizeof(struct eth_tx_parse_bd_e2));
5396 if (m0->m_pkthdr.csum_flags) {
5397 hlen = bxe_set_pbd_csum_e2(fp, m0, &pbd_e2_parsing_data);
5400 SET_FLAG(pbd_e2_parsing_data, ETH_TX_PARSE_BD_E2_ETH_ADDR_TYPE,
5403 uint16_t global_data = 0;
5405 pbd_e1x = &fp->tx_chain[TX_BD(bd_prod)].parse_bd_e1x;
5406 memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x));
5408 if (m0->m_pkthdr.csum_flags) {
5409 hlen = bxe_set_pbd_csum(fp, m0, pbd_e1x);
5412 SET_FLAG(global_data,
5413 ETH_TX_PARSE_BD_E1X_ETH_ADDR_TYPE, mac_type);
5414 pbd_e1x->global_data |= htole16(global_data);
5417 /* setup the parsing BD with TSO specific info */
5418 if (m0->m_pkthdr.csum_flags & CSUM_TSO) {
5419 fp->eth_q_stats.tx_ofld_frames_lso++;
5420 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_SW_LSO;
5422 if (__predict_false(tx_start_bd->nbytes > hlen)) {
5423 fp->eth_q_stats.tx_ofld_frames_lso_hdr_splits++;
5425 /* split the first BD into header/data making the fw job easy */
5427 tx_start_bd->nbd = htole16(nbds);
5428 tx_start_bd->nbytes = htole16(hlen);
5430 bd_prod = TX_BD_NEXT(bd_prod);
5432 /* new transmit BD after the tx_parse_bd */
5433 tx_data_bd = &fp->tx_chain[TX_BD(bd_prod)].reg_bd;
5434 tx_data_bd->addr_hi = htole32(U64_HI(segs[0].ds_addr + hlen));
5435 tx_data_bd->addr_lo = htole32(U64_LO(segs[0].ds_addr + hlen));
5436 tx_data_bd->nbytes = htole16(segs[0].ds_len - hlen);
5437 if (tx_total_pkt_size_bd == NULL) {
5438 tx_total_pkt_size_bd = tx_data_bd;
5442 "TSO split header size is %d (%x:%x) nbds %d\n",
5443 le16toh(tx_start_bd->nbytes),
5444 le32toh(tx_start_bd->addr_hi),
5445 le32toh(tx_start_bd->addr_lo),
5449 if (!CHIP_IS_E1x(sc)) {
5450 bxe_set_pbd_lso_e2(m0, &pbd_e2_parsing_data);
5452 bxe_set_pbd_lso(m0, pbd_e1x);
5456 if (pbd_e2_parsing_data) {
5457 pbd_e2->parsing_data = htole32(pbd_e2_parsing_data);
5460 /* prepare remaining BDs, start tx bd contains first seg/frag */
5461 for (i = 1; i < nsegs ; i++) {
5462 bd_prod = TX_BD_NEXT(bd_prod);
5463 tx_data_bd = &fp->tx_chain[TX_BD(bd_prod)].reg_bd;
5464 tx_data_bd->addr_lo = htole32(U64_LO(segs[i].ds_addr));
5465 tx_data_bd->addr_hi = htole32(U64_HI(segs[i].ds_addr));
5466 tx_data_bd->nbytes = htole16(segs[i].ds_len);
5467 if (tx_total_pkt_size_bd == NULL) {
5468 tx_total_pkt_size_bd = tx_data_bd;
5470 total_pkt_size += tx_data_bd->nbytes;
5473 BLOGD(sc, DBG_TX, "last bd %p\n", tx_data_bd);
5475 if (tx_total_pkt_size_bd != NULL) {
5476 tx_total_pkt_size_bd->total_pkt_bytes = total_pkt_size;
5479 if (__predict_false(sc->debug & DBG_TX)) {
5480 tmp_bd = tx_buf->first_bd;
5481 for (i = 0; i < nbds; i++)
5485 "TX Strt: %p bd=%d nbd=%d vlan=0x%x "
5486 "bd_flags=0x%x hdr_nbds=%d\n",
5489 le16toh(tx_start_bd->nbd),
5490 le16toh(tx_start_bd->vlan_or_ethertype),
5491 tx_start_bd->bd_flags.as_bitfield,
5492 (tx_start_bd->general_data & ETH_TX_START_BD_HDR_NBDS));
5493 } else if (i == 1) {
5496 "-> Prse: %p bd=%d global=0x%x ip_hlen_w=%u "
5497 "ip_id=%u lso_mss=%u tcp_flags=0x%x csum=0x%x "
5498 "tcp_seq=%u total_hlen_w=%u\n",
5501 pbd_e1x->global_data,
5506 pbd_e1x->tcp_pseudo_csum,
5507 pbd_e1x->tcp_send_seq,
5508 le16toh(pbd_e1x->total_hlen_w));
5509 } else { /* if (pbd_e2) */
5511 "-> Parse: %p bd=%d dst=%02x:%02x:%02x "
5512 "src=%02x:%02x:%02x parsing_data=0x%x\n",
5515 pbd_e2->data.mac_addr.dst_hi,
5516 pbd_e2->data.mac_addr.dst_mid,
5517 pbd_e2->data.mac_addr.dst_lo,
5518 pbd_e2->data.mac_addr.src_hi,
5519 pbd_e2->data.mac_addr.src_mid,
5520 pbd_e2->data.mac_addr.src_lo,
5521 pbd_e2->parsing_data);
5525 if (i != 1) { /* skip parse db as it doesn't hold data */
5526 tx_data_bd = &fp->tx_chain[TX_BD(tmp_bd)].reg_bd;
5528 "-> Frag: %p bd=%d nbytes=%d hi=0x%x lo: 0x%x\n",
5531 le16toh(tx_data_bd->nbytes),
5532 le32toh(tx_data_bd->addr_hi),
5533 le32toh(tx_data_bd->addr_lo));
5536 tmp_bd = TX_BD_NEXT(tmp_bd);
5540 BLOGD(sc, DBG_TX, "doorbell: nbds=%d bd=%u\n", nbds, bd_prod);
5542 /* update TX BD producer index value for next TX */
5543 bd_prod = TX_BD_NEXT(bd_prod);
5546 * If the chain of tx_bd's describing this frame is adjacent to or spans
5547 * an eth_tx_next_bd element then we need to increment the nbds value.
5549 if (TX_BD_IDX(bd_prod) < nbds) {
5553 /* don't allow reordering of writes for nbd and packets */
5556 fp->tx_db.data.prod += nbds;
5558 /* producer points to the next free tx_bd at this point */
5560 fp->tx_bd_prod = bd_prod;
5562 DOORBELL(sc, fp->index, fp->tx_db.raw);
5564 fp->eth_q_stats.tx_pkts++;
5566 /* Prevent speculative reads from getting ahead of the status block. */
5567 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle,
5568 0, 0, BUS_SPACE_BARRIER_READ);
5570 /* Prevent speculative reads from getting ahead of the doorbell. */
5571 bus_space_barrier(sc->bar[BAR2].tag, sc->bar[BAR2].handle,
5572 0, 0, BUS_SPACE_BARRIER_READ);
5578 bxe_tx_start_locked(struct bxe_softc *sc,
5580 struct bxe_fastpath *fp)
5582 struct mbuf *m = NULL;
5584 uint16_t tx_bd_avail;
5586 BXE_FP_TX_LOCK_ASSERT(fp);
5588 /* keep adding entries while there are frames to send */
5589 while (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) {
5592 * check for any frames to send
5593 * dequeue can still be NULL even if queue is not empty
5595 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
5596 if (__predict_false(m == NULL)) {
5600 /* the mbuf now belongs to us */
5601 fp->eth_q_stats.mbuf_alloc_tx++;
5604 * Put the frame into the transmit ring. If we don't have room,
5605 * place the mbuf back at the head of the TX queue, set the
5606 * OACTIVE flag, and wait for the NIC to drain the chain.
5608 if (__predict_false(bxe_tx_encap(fp, &m))) {
5609 fp->eth_q_stats.tx_encap_failures++;
5611 /* mark the TX queue as full and return the frame */
5612 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
5613 IFQ_DRV_PREPEND(&ifp->if_snd, m);
5614 fp->eth_q_stats.mbuf_alloc_tx--;
5615 fp->eth_q_stats.tx_queue_xoff++;
5618 /* stop looking for more work */
5622 /* the frame was enqueued successfully */
5625 /* send a copy of the frame to any BPF listeners. */
5628 tx_bd_avail = bxe_tx_avail(sc, fp);
5630 /* handle any completions if we're running low */
5631 if (tx_bd_avail < BXE_TX_CLEANUP_THRESHOLD) {
5632 /* bxe_txeof will set IFF_DRV_OACTIVE appropriately */
5634 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
5640 /* all TX packets were dequeued and/or the tx ring is full */
5642 /* reset the TX watchdog timeout timer */
5643 fp->watchdog_timer = BXE_TX_TIMEOUT;
5647 /* Legacy (non-RSS) dispatch routine */
5649 bxe_tx_start(struct ifnet *ifp)
5651 struct bxe_softc *sc;
5652 struct bxe_fastpath *fp;
5656 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
5657 BLOGW(sc, "Interface not running, ignoring transmit request\n");
5661 if (!sc->link_vars.link_up) {
5662 BLOGW(sc, "Interface link is down, ignoring transmit request\n");
5668 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
5669 fp->eth_q_stats.tx_queue_full_return++;
5674 bxe_tx_start_locked(sc, ifp, fp);
5675 BXE_FP_TX_UNLOCK(fp);
5678 #if __FreeBSD_version >= 901504
5681 bxe_tx_mq_start_locked(struct bxe_softc *sc,
5683 struct bxe_fastpath *fp,
5686 struct buf_ring *tx_br = fp->tx_br;
5688 int depth, rc, tx_count;
5689 uint16_t tx_bd_avail;
5693 BXE_FP_TX_LOCK_ASSERT(fp);
5695 if (sc->state != BXE_STATE_OPEN) {
5696 fp->eth_q_stats.bxe_tx_mq_sc_state_failures++;
5701 BLOGE(sc, "Multiqueue TX and no buf_ring!\n");
5706 rc = drbr_enqueue(ifp, tx_br, m);
5708 fp->eth_q_stats.tx_soft_errors++;
5709 goto bxe_tx_mq_start_locked_exit;
5713 if (!sc->link_vars.link_up || !(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
5714 fp->eth_q_stats.tx_request_link_down_failures++;
5715 goto bxe_tx_mq_start_locked_exit;
5718 /* fetch the depth of the driver queue */
5719 depth = drbr_inuse(ifp, tx_br);
5720 if (depth > fp->eth_q_stats.tx_max_drbr_queue_depth) {
5721 fp->eth_q_stats.tx_max_drbr_queue_depth = depth;
5724 /* keep adding entries while there are frames to send */
5725 while ((next = drbr_peek(ifp, tx_br)) != NULL) {
5726 /* handle any completions if we're running low */
5727 tx_bd_avail = bxe_tx_avail(sc, fp);
5728 if (tx_bd_avail < BXE_TX_CLEANUP_THRESHOLD) {
5729 /* bxe_txeof will set IFF_DRV_OACTIVE appropriately */
5731 tx_bd_avail = bxe_tx_avail(sc, fp);
5732 if (tx_bd_avail < (BXE_TSO_MAX_SEGMENTS + 1)) {
5733 fp->eth_q_stats.bd_avail_too_less_failures++;
5735 drbr_advance(ifp, tx_br);
5741 /* the mbuf now belongs to us */
5742 fp->eth_q_stats.mbuf_alloc_tx++;
5745 * Put the frame into the transmit ring. If we don't have room,
5746 * place the mbuf back at the head of the TX queue, set the
5747 * OACTIVE flag, and wait for the NIC to drain the chain.
5749 rc = bxe_tx_encap(fp, &next);
5750 if (__predict_false(rc != 0)) {
5751 fp->eth_q_stats.tx_encap_failures++;
5753 /* mark the TX queue as full and save the frame */
5754 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
5755 drbr_putback(ifp, tx_br, next);
5756 fp->eth_q_stats.mbuf_alloc_tx--;
5757 fp->eth_q_stats.tx_frames_deferred++;
5759 drbr_advance(ifp, tx_br);
5761 /* stop looking for more work */
5765 /* the transmit frame was enqueued successfully */
5768 /* send a copy of the frame to any BPF listeners */
5769 BPF_MTAP(ifp, next);
5771 drbr_advance(ifp, tx_br);
5774 /* all TX packets were dequeued and/or the tx ring is full */
5776 /* reset the TX watchdog timeout timer */
5777 fp->watchdog_timer = BXE_TX_TIMEOUT;
5780 bxe_tx_mq_start_locked_exit:
5781 /* If we didn't drain the drbr, enqueue a task in the future to do it. */
5782 if (!drbr_empty(ifp, tx_br)) {
5783 fp->eth_q_stats.tx_mq_not_empty++;
5784 taskqueue_enqueue_timeout(fp->tq, &fp->tx_timeout_task, 1);
5791 bxe_tx_mq_start_deferred(void *arg,
5794 struct bxe_fastpath *fp = (struct bxe_fastpath *)arg;
5795 struct bxe_softc *sc = fp->sc;
5796 struct ifnet *ifp = sc->ifnet;
5799 bxe_tx_mq_start_locked(sc, ifp, fp, NULL);
5800 BXE_FP_TX_UNLOCK(fp);
5803 /* Multiqueue (TSS) dispatch routine. */
5805 bxe_tx_mq_start(struct ifnet *ifp,
5808 struct bxe_softc *sc = ifp->if_softc;
5809 struct bxe_fastpath *fp;
5812 fp_index = 0; /* default is the first queue */
5814 /* check if flowid is set */
5816 if (BXE_VALID_FLOWID(m))
5817 fp_index = (m->m_pkthdr.flowid % sc->num_queues);
5819 fp = &sc->fp[fp_index];
5821 if (sc->state != BXE_STATE_OPEN) {
5822 fp->eth_q_stats.bxe_tx_mq_sc_state_failures++;
5826 if (BXE_FP_TX_TRYLOCK(fp)) {
5827 rc = bxe_tx_mq_start_locked(sc, ifp, fp, m);
5828 BXE_FP_TX_UNLOCK(fp);
5830 rc = drbr_enqueue(ifp, fp->tx_br, m);
5831 taskqueue_enqueue(fp->tq, &fp->tx_task);
5838 bxe_mq_flush(struct ifnet *ifp)
5840 struct bxe_softc *sc = ifp->if_softc;
5841 struct bxe_fastpath *fp;
5845 for (i = 0; i < sc->num_queues; i++) {
5848 if (fp->state != BXE_FP_STATE_IRQ) {
5849 BLOGD(sc, DBG_LOAD, "Not clearing fp[%02d] buf_ring (state=%d)\n",
5850 fp->index, fp->state);
5854 if (fp->tx_br != NULL) {
5855 BLOGD(sc, DBG_LOAD, "Clearing fp[%02d] buf_ring\n", fp->index);
5857 while ((m = buf_ring_dequeue_sc(fp->tx_br)) != NULL) {
5860 BXE_FP_TX_UNLOCK(fp);
5867 #endif /* FreeBSD_version >= 901504 */
5870 bxe_cid_ilt_lines(struct bxe_softc *sc)
5873 return ((BXE_FIRST_VF_CID + BXE_VF_CIDS) / ILT_PAGE_CIDS);
5875 return (L2_ILT_LINES(sc));
5879 bxe_ilt_set_info(struct bxe_softc *sc)
5881 struct ilt_client_info *ilt_client;
5882 struct ecore_ilt *ilt = sc->ilt;
5885 ilt->start_line = FUNC_ILT_BASE(SC_FUNC(sc));
5886 BLOGD(sc, DBG_LOAD, "ilt starts at line %d\n", ilt->start_line);
5889 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
5890 ilt_client->client_num = ILT_CLIENT_CDU;
5891 ilt_client->page_size = CDU_ILT_PAGE_SZ;
5892 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
5893 ilt_client->start = line;
5894 line += bxe_cid_ilt_lines(sc);
5896 if (CNIC_SUPPORT(sc)) {
5897 line += CNIC_ILT_LINES;
5900 ilt_client->end = (line - 1);
5903 "ilt client[CDU]: start %d, end %d, "
5904 "psz 0x%x, flags 0x%x, hw psz %d\n",
5905 ilt_client->start, ilt_client->end,
5906 ilt_client->page_size,
5908 ilog2(ilt_client->page_size >> 12));
5911 if (QM_INIT(sc->qm_cid_count)) {
5912 ilt_client = &ilt->clients[ILT_CLIENT_QM];
5913 ilt_client->client_num = ILT_CLIENT_QM;
5914 ilt_client->page_size = QM_ILT_PAGE_SZ;
5915 ilt_client->flags = 0;
5916 ilt_client->start = line;
5918 /* 4 bytes for each cid */
5919 line += DIV_ROUND_UP(sc->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
5922 ilt_client->end = (line - 1);
5925 "ilt client[QM]: start %d, end %d, "
5926 "psz 0x%x, flags 0x%x, hw psz %d\n",
5927 ilt_client->start, ilt_client->end,
5928 ilt_client->page_size, ilt_client->flags,
5929 ilog2(ilt_client->page_size >> 12));
5932 if (CNIC_SUPPORT(sc)) {
5934 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
5935 ilt_client->client_num = ILT_CLIENT_SRC;
5936 ilt_client->page_size = SRC_ILT_PAGE_SZ;
5937 ilt_client->flags = 0;
5938 ilt_client->start = line;
5939 line += SRC_ILT_LINES;
5940 ilt_client->end = (line - 1);
5943 "ilt client[SRC]: start %d, end %d, "
5944 "psz 0x%x, flags 0x%x, hw psz %d\n",
5945 ilt_client->start, ilt_client->end,
5946 ilt_client->page_size, ilt_client->flags,
5947 ilog2(ilt_client->page_size >> 12));
5950 ilt_client = &ilt->clients[ILT_CLIENT_TM];
5951 ilt_client->client_num = ILT_CLIENT_TM;
5952 ilt_client->page_size = TM_ILT_PAGE_SZ;
5953 ilt_client->flags = 0;
5954 ilt_client->start = line;
5955 line += TM_ILT_LINES;
5956 ilt_client->end = (line - 1);
5959 "ilt client[TM]: start %d, end %d, "
5960 "psz 0x%x, flags 0x%x, hw psz %d\n",
5961 ilt_client->start, ilt_client->end,
5962 ilt_client->page_size, ilt_client->flags,
5963 ilog2(ilt_client->page_size >> 12));
5966 KASSERT((line <= ILT_MAX_LINES), ("Invalid number of ILT lines!"));
5970 bxe_set_fp_rx_buf_size(struct bxe_softc *sc)
5973 uint32_t rx_buf_size;
5975 rx_buf_size = (IP_HEADER_ALIGNMENT_PADDING + ETH_OVERHEAD + sc->mtu);
5977 for (i = 0; i < sc->num_queues; i++) {
5978 if(rx_buf_size <= MCLBYTES){
5979 sc->fp[i].rx_buf_size = rx_buf_size;
5980 sc->fp[i].mbuf_alloc_size = MCLBYTES;
5981 }else if (rx_buf_size <= MJUMPAGESIZE){
5982 sc->fp[i].rx_buf_size = rx_buf_size;
5983 sc->fp[i].mbuf_alloc_size = MJUMPAGESIZE;
5984 }else if (rx_buf_size <= (MJUMPAGESIZE + MCLBYTES)){
5985 sc->fp[i].rx_buf_size = MCLBYTES;
5986 sc->fp[i].mbuf_alloc_size = MCLBYTES;
5987 }else if (rx_buf_size <= (2 * MJUMPAGESIZE)){
5988 sc->fp[i].rx_buf_size = MJUMPAGESIZE;
5989 sc->fp[i].mbuf_alloc_size = MJUMPAGESIZE;
5991 sc->fp[i].rx_buf_size = MCLBYTES;
5992 sc->fp[i].mbuf_alloc_size = MCLBYTES;
5998 bxe_alloc_ilt_mem(struct bxe_softc *sc)
6003 (struct ecore_ilt *)malloc(sizeof(struct ecore_ilt),
6005 (M_NOWAIT | M_ZERO))) == NULL) {
6013 bxe_alloc_ilt_lines_mem(struct bxe_softc *sc)
6017 if ((sc->ilt->lines =
6018 (struct ilt_line *)malloc((sizeof(struct ilt_line) * ILT_MAX_LINES),
6020 (M_NOWAIT | M_ZERO))) == NULL) {
6028 bxe_free_ilt_mem(struct bxe_softc *sc)
6030 if (sc->ilt != NULL) {
6031 free(sc->ilt, M_BXE_ILT);
6037 bxe_free_ilt_lines_mem(struct bxe_softc *sc)
6039 if (sc->ilt->lines != NULL) {
6040 free(sc->ilt->lines, M_BXE_ILT);
6041 sc->ilt->lines = NULL;
6046 bxe_free_mem(struct bxe_softc *sc)
6050 for (i = 0; i < L2_ILT_LINES(sc); i++) {
6051 bxe_dma_free(sc, &sc->context[i].vcxt_dma);
6052 sc->context[i].vcxt = NULL;
6053 sc->context[i].size = 0;
6056 ecore_ilt_mem_op(sc, ILT_MEMOP_FREE);
6058 bxe_free_ilt_lines_mem(sc);
6063 bxe_alloc_mem(struct bxe_softc *sc)
6071 * Allocate memory for CDU context:
6072 * This memory is allocated separately and not in the generic ILT
6073 * functions because CDU differs in few aspects:
6074 * 1. There can be multiple entities allocating memory for context -
6075 * regular L2, CNIC, and SRIOV drivers. Each separately controls
6076 * its own ILT lines.
6077 * 2. Since CDU page-size is not a single 4KB page (which is the case
6078 * for the other ILT clients), to be efficient we want to support
6079 * allocation of sub-page-size in the last entry.
6080 * 3. Context pointers are used by the driver to pass to FW / update
6081 * the context (for the other ILT clients the pointers are used just to
6082 * free the memory during unload).
6084 context_size = (sizeof(union cdu_context) * BXE_L2_CID_COUNT(sc));
6085 for (i = 0, allocated = 0; allocated < context_size; i++) {
6086 sc->context[i].size = min(CDU_ILT_PAGE_SZ,
6087 (context_size - allocated));
6089 if (bxe_dma_alloc(sc, sc->context[i].size,
6090 &sc->context[i].vcxt_dma,
6091 "cdu context") != 0) {
6096 sc->context[i].vcxt =
6097 (union cdu_context *)sc->context[i].vcxt_dma.vaddr;
6099 allocated += sc->context[i].size;
6102 bxe_alloc_ilt_lines_mem(sc);
6104 BLOGD(sc, DBG_LOAD, "ilt=%p start_line=%u lines=%p\n",
6105 sc->ilt, sc->ilt->start_line, sc->ilt->lines);
6107 for (i = 0; i < 4; i++) {
6109 "c%d page_size=%u start=%u end=%u num=%u flags=0x%x\n",
6111 sc->ilt->clients[i].page_size,
6112 sc->ilt->clients[i].start,
6113 sc->ilt->clients[i].end,
6114 sc->ilt->clients[i].client_num,
6115 sc->ilt->clients[i].flags);
6118 if (ecore_ilt_mem_op(sc, ILT_MEMOP_ALLOC)) {
6119 BLOGE(sc, "ecore_ilt_mem_op ILT_MEMOP_ALLOC failed\n");
6128 bxe_free_rx_bd_chain(struct bxe_fastpath *fp)
6130 struct bxe_softc *sc;
6135 if (fp->rx_mbuf_tag == NULL) {
6139 /* free all mbufs and unload all maps */
6140 for (i = 0; i < RX_BD_TOTAL; i++) {
6141 if (fp->rx_mbuf_chain[i].m_map != NULL) {
6142 bus_dmamap_sync(fp->rx_mbuf_tag,
6143 fp->rx_mbuf_chain[i].m_map,
6144 BUS_DMASYNC_POSTREAD);
6145 bus_dmamap_unload(fp->rx_mbuf_tag,
6146 fp->rx_mbuf_chain[i].m_map);
6149 if (fp->rx_mbuf_chain[i].m != NULL) {
6150 m_freem(fp->rx_mbuf_chain[i].m);
6151 fp->rx_mbuf_chain[i].m = NULL;
6152 fp->eth_q_stats.mbuf_alloc_rx--;
6158 bxe_free_tpa_pool(struct bxe_fastpath *fp)
6160 struct bxe_softc *sc;
6161 int i, max_agg_queues;
6165 if (fp->rx_mbuf_tag == NULL) {
6169 max_agg_queues = MAX_AGG_QS(sc);
6171 /* release all mbufs and unload all DMA maps in the TPA pool */
6172 for (i = 0; i < max_agg_queues; i++) {
6173 if (fp->rx_tpa_info[i].bd.m_map != NULL) {
6174 bus_dmamap_sync(fp->rx_mbuf_tag,
6175 fp->rx_tpa_info[i].bd.m_map,
6176 BUS_DMASYNC_POSTREAD);
6177 bus_dmamap_unload(fp->rx_mbuf_tag,
6178 fp->rx_tpa_info[i].bd.m_map);
6181 if (fp->rx_tpa_info[i].bd.m != NULL) {
6182 m_freem(fp->rx_tpa_info[i].bd.m);
6183 fp->rx_tpa_info[i].bd.m = NULL;
6184 fp->eth_q_stats.mbuf_alloc_tpa--;
6190 bxe_free_sge_chain(struct bxe_fastpath *fp)
6192 struct bxe_softc *sc;
6197 if (fp->rx_sge_mbuf_tag == NULL) {
6201 /* rree all mbufs and unload all maps */
6202 for (i = 0; i < RX_SGE_TOTAL; i++) {
6203 if (fp->rx_sge_mbuf_chain[i].m_map != NULL) {
6204 bus_dmamap_sync(fp->rx_sge_mbuf_tag,
6205 fp->rx_sge_mbuf_chain[i].m_map,
6206 BUS_DMASYNC_POSTREAD);
6207 bus_dmamap_unload(fp->rx_sge_mbuf_tag,
6208 fp->rx_sge_mbuf_chain[i].m_map);
6211 if (fp->rx_sge_mbuf_chain[i].m != NULL) {
6212 m_freem(fp->rx_sge_mbuf_chain[i].m);
6213 fp->rx_sge_mbuf_chain[i].m = NULL;
6214 fp->eth_q_stats.mbuf_alloc_sge--;
6220 bxe_free_fp_buffers(struct bxe_softc *sc)
6222 struct bxe_fastpath *fp;
6225 for (i = 0; i < sc->num_queues; i++) {
6228 #if __FreeBSD_version >= 901504
6229 if (fp->tx_br != NULL) {
6230 /* just in case bxe_mq_flush() wasn't called */
6231 if (mtx_initialized(&fp->tx_mtx)) {
6235 while ((m = buf_ring_dequeue_sc(fp->tx_br)) != NULL)
6237 BXE_FP_TX_UNLOCK(fp);
6242 /* free all RX buffers */
6243 bxe_free_rx_bd_chain(fp);
6244 bxe_free_tpa_pool(fp);
6245 bxe_free_sge_chain(fp);
6247 if (fp->eth_q_stats.mbuf_alloc_rx != 0) {
6248 BLOGE(sc, "failed to claim all rx mbufs (%d left)\n",
6249 fp->eth_q_stats.mbuf_alloc_rx);
6252 if (fp->eth_q_stats.mbuf_alloc_sge != 0) {
6253 BLOGE(sc, "failed to claim all sge mbufs (%d left)\n",
6254 fp->eth_q_stats.mbuf_alloc_sge);
6257 if (fp->eth_q_stats.mbuf_alloc_tpa != 0) {
6258 BLOGE(sc, "failed to claim all sge mbufs (%d left)\n",
6259 fp->eth_q_stats.mbuf_alloc_tpa);
6262 if (fp->eth_q_stats.mbuf_alloc_tx != 0) {
6263 BLOGE(sc, "failed to release tx mbufs (%d left)\n",
6264 fp->eth_q_stats.mbuf_alloc_tx);
6267 /* XXX verify all mbufs were reclaimed */
6272 bxe_alloc_rx_bd_mbuf(struct bxe_fastpath *fp,
6273 uint16_t prev_index,
6276 struct bxe_sw_rx_bd *rx_buf;
6277 struct eth_rx_bd *rx_bd;
6278 bus_dma_segment_t segs[1];
6285 /* allocate the new RX BD mbuf */
6286 m = m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR, fp->mbuf_alloc_size);
6287 if (__predict_false(m == NULL)) {
6288 fp->eth_q_stats.mbuf_rx_bd_alloc_failed++;
6292 fp->eth_q_stats.mbuf_alloc_rx++;
6294 /* initialize the mbuf buffer length */
6295 m->m_pkthdr.len = m->m_len = fp->rx_buf_size;
6297 /* map the mbuf into non-paged pool */
6298 rc = bus_dmamap_load_mbuf_sg(fp->rx_mbuf_tag,
6299 fp->rx_mbuf_spare_map,
6300 m, segs, &nsegs, BUS_DMA_NOWAIT);
6301 if (__predict_false(rc != 0)) {
6302 fp->eth_q_stats.mbuf_rx_bd_mapping_failed++;
6304 fp->eth_q_stats.mbuf_alloc_rx--;
6308 /* all mbufs must map to a single segment */
6309 KASSERT((nsegs == 1), ("Too many segments, %d returned!", nsegs));
6311 /* release any existing RX BD mbuf mappings */
6313 if (prev_index != index) {
6314 rx_buf = &fp->rx_mbuf_chain[prev_index];
6316 if (rx_buf->m_map != NULL) {
6317 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map,
6318 BUS_DMASYNC_POSTREAD);
6319 bus_dmamap_unload(fp->rx_mbuf_tag, rx_buf->m_map);
6323 * We only get here from bxe_rxeof() when the maximum number
6324 * of rx buffers is less than RX_BD_USABLE. bxe_rxeof() already
6325 * holds the mbuf in the prev_index so it's OK to NULL it out
6326 * here without concern of a memory leak.
6328 fp->rx_mbuf_chain[prev_index].m = NULL;
6331 rx_buf = &fp->rx_mbuf_chain[index];
6333 if (rx_buf->m_map != NULL) {
6334 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map,
6335 BUS_DMASYNC_POSTREAD);
6336 bus_dmamap_unload(fp->rx_mbuf_tag, rx_buf->m_map);
6339 /* save the mbuf and mapping info for a future packet */
6340 map = (prev_index != index) ?
6341 fp->rx_mbuf_chain[prev_index].m_map : rx_buf->m_map;
6342 rx_buf->m_map = fp->rx_mbuf_spare_map;
6343 fp->rx_mbuf_spare_map = map;
6344 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map,
6345 BUS_DMASYNC_PREREAD);
6348 rx_bd = &fp->rx_chain[index];
6349 rx_bd->addr_hi = htole32(U64_HI(segs[0].ds_addr));
6350 rx_bd->addr_lo = htole32(U64_LO(segs[0].ds_addr));
6356 bxe_alloc_rx_tpa_mbuf(struct bxe_fastpath *fp,
6359 struct bxe_sw_tpa_info *tpa_info = &fp->rx_tpa_info[queue];
6360 bus_dma_segment_t segs[1];
6366 /* allocate the new TPA mbuf */
6367 m = m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR, fp->mbuf_alloc_size);
6368 if (__predict_false(m == NULL)) {
6369 fp->eth_q_stats.mbuf_rx_tpa_alloc_failed++;
6373 fp->eth_q_stats.mbuf_alloc_tpa++;
6375 /* initialize the mbuf buffer length */
6376 m->m_pkthdr.len = m->m_len = fp->rx_buf_size;
6378 /* map the mbuf into non-paged pool */
6379 rc = bus_dmamap_load_mbuf_sg(fp->rx_mbuf_tag,
6380 fp->rx_tpa_info_mbuf_spare_map,
6381 m, segs, &nsegs, BUS_DMA_NOWAIT);
6382 if (__predict_false(rc != 0)) {
6383 fp->eth_q_stats.mbuf_rx_tpa_mapping_failed++;
6385 fp->eth_q_stats.mbuf_alloc_tpa--;
6389 /* all mbufs must map to a single segment */
6390 KASSERT((nsegs == 1), ("Too many segments, %d returned!", nsegs));
6392 /* release any existing TPA mbuf mapping */
6393 if (tpa_info->bd.m_map != NULL) {
6394 bus_dmamap_sync(fp->rx_mbuf_tag, tpa_info->bd.m_map,
6395 BUS_DMASYNC_POSTREAD);
6396 bus_dmamap_unload(fp->rx_mbuf_tag, tpa_info->bd.m_map);
6399 /* save the mbuf and mapping info for the TPA mbuf */
6400 map = tpa_info->bd.m_map;
6401 tpa_info->bd.m_map = fp->rx_tpa_info_mbuf_spare_map;
6402 fp->rx_tpa_info_mbuf_spare_map = map;
6403 bus_dmamap_sync(fp->rx_mbuf_tag, tpa_info->bd.m_map,
6404 BUS_DMASYNC_PREREAD);
6406 tpa_info->seg = segs[0];
6412 * Allocate an mbuf and assign it to the receive scatter gather chain. The
6413 * caller must take care to save a copy of the existing mbuf in the SG mbuf
6417 bxe_alloc_rx_sge_mbuf(struct bxe_fastpath *fp,
6420 struct bxe_sw_rx_bd *sge_buf;
6421 struct eth_rx_sge *sge;
6422 bus_dma_segment_t segs[1];
6428 /* allocate a new SGE mbuf */
6429 m = m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR, SGE_PAGE_SIZE);
6430 if (__predict_false(m == NULL)) {
6431 fp->eth_q_stats.mbuf_rx_sge_alloc_failed++;
6435 fp->eth_q_stats.mbuf_alloc_sge++;
6437 /* initialize the mbuf buffer length */
6438 m->m_pkthdr.len = m->m_len = SGE_PAGE_SIZE;
6440 /* map the SGE mbuf into non-paged pool */
6441 rc = bus_dmamap_load_mbuf_sg(fp->rx_sge_mbuf_tag,
6442 fp->rx_sge_mbuf_spare_map,
6443 m, segs, &nsegs, BUS_DMA_NOWAIT);
6444 if (__predict_false(rc != 0)) {
6445 fp->eth_q_stats.mbuf_rx_sge_mapping_failed++;
6447 fp->eth_q_stats.mbuf_alloc_sge--;
6451 /* all mbufs must map to a single segment */
6452 KASSERT((nsegs == 1), ("Too many segments, %d returned!", nsegs));
6454 sge_buf = &fp->rx_sge_mbuf_chain[index];
6456 /* release any existing SGE mbuf mapping */
6457 if (sge_buf->m_map != NULL) {
6458 bus_dmamap_sync(fp->rx_sge_mbuf_tag, sge_buf->m_map,
6459 BUS_DMASYNC_POSTREAD);
6460 bus_dmamap_unload(fp->rx_sge_mbuf_tag, sge_buf->m_map);
6463 /* save the mbuf and mapping info for a future packet */
6464 map = sge_buf->m_map;
6465 sge_buf->m_map = fp->rx_sge_mbuf_spare_map;
6466 fp->rx_sge_mbuf_spare_map = map;
6467 bus_dmamap_sync(fp->rx_sge_mbuf_tag, sge_buf->m_map,
6468 BUS_DMASYNC_PREREAD);
6471 sge = &fp->rx_sge_chain[index];
6472 sge->addr_hi = htole32(U64_HI(segs[0].ds_addr));
6473 sge->addr_lo = htole32(U64_LO(segs[0].ds_addr));
6478 static __noinline int
6479 bxe_alloc_fp_buffers(struct bxe_softc *sc)
6481 struct bxe_fastpath *fp;
6483 int ring_prod, cqe_ring_prod;
6486 for (i = 0; i < sc->num_queues; i++) {
6489 ring_prod = cqe_ring_prod = 0;
6493 /* allocate buffers for the RX BDs in RX BD chain */
6494 for (j = 0; j < sc->max_rx_bufs; j++) {
6495 rc = bxe_alloc_rx_bd_mbuf(fp, ring_prod, ring_prod);
6497 BLOGE(sc, "mbuf alloc fail for fp[%02d] rx chain (%d)\n",
6499 goto bxe_alloc_fp_buffers_error;
6502 ring_prod = RX_BD_NEXT(ring_prod);
6503 cqe_ring_prod = RCQ_NEXT(cqe_ring_prod);
6506 fp->rx_bd_prod = ring_prod;
6507 fp->rx_cq_prod = cqe_ring_prod;
6508 fp->eth_q_stats.rx_calls = fp->eth_q_stats.rx_pkts = 0;
6510 max_agg_queues = MAX_AGG_QS(sc);
6512 fp->tpa_enable = TRUE;
6514 /* fill the TPA pool */
6515 for (j = 0; j < max_agg_queues; j++) {
6516 rc = bxe_alloc_rx_tpa_mbuf(fp, j);
6518 BLOGE(sc, "mbuf alloc fail for fp[%02d] TPA queue %d\n",
6520 fp->tpa_enable = FALSE;
6521 goto bxe_alloc_fp_buffers_error;
6524 fp->rx_tpa_info[j].state = BXE_TPA_STATE_STOP;
6527 if (fp->tpa_enable) {
6528 /* fill the RX SGE chain */
6530 for (j = 0; j < RX_SGE_USABLE; j++) {
6531 rc = bxe_alloc_rx_sge_mbuf(fp, ring_prod);
6533 BLOGE(sc, "mbuf alloc fail for fp[%02d] SGE %d\n",
6535 fp->tpa_enable = FALSE;
6537 goto bxe_alloc_fp_buffers_error;
6540 ring_prod = RX_SGE_NEXT(ring_prod);
6543 fp->rx_sge_prod = ring_prod;
6549 bxe_alloc_fp_buffers_error:
6551 /* unwind what was already allocated */
6552 bxe_free_rx_bd_chain(fp);
6553 bxe_free_tpa_pool(fp);
6554 bxe_free_sge_chain(fp);
6560 bxe_free_fw_stats_mem(struct bxe_softc *sc)
6562 bxe_dma_free(sc, &sc->fw_stats_dma);
6564 sc->fw_stats_num = 0;
6566 sc->fw_stats_req_size = 0;
6567 sc->fw_stats_req = NULL;
6568 sc->fw_stats_req_mapping = 0;
6570 sc->fw_stats_data_size = 0;
6571 sc->fw_stats_data = NULL;
6572 sc->fw_stats_data_mapping = 0;
6576 bxe_alloc_fw_stats_mem(struct bxe_softc *sc)
6578 uint8_t num_queue_stats;
6581 /* number of queues for statistics is number of eth queues */
6582 num_queue_stats = BXE_NUM_ETH_QUEUES(sc);
6585 * Total number of FW statistics requests =
6586 * 1 for port stats + 1 for PF stats + num of queues
6588 sc->fw_stats_num = (2 + num_queue_stats);
6591 * Request is built from stats_query_header and an array of
6592 * stats_query_cmd_group each of which contains STATS_QUERY_CMD_COUNT
6593 * rules. The real number or requests is configured in the
6594 * stats_query_header.
6597 ((sc->fw_stats_num / STATS_QUERY_CMD_COUNT) +
6598 ((sc->fw_stats_num % STATS_QUERY_CMD_COUNT) ? 1 : 0));
6600 BLOGD(sc, DBG_LOAD, "stats fw_stats_num %d num_groups %d\n",
6601 sc->fw_stats_num, num_groups);
6603 sc->fw_stats_req_size =
6604 (sizeof(struct stats_query_header) +
6605 (num_groups * sizeof(struct stats_query_cmd_group)));
6608 * Data for statistics requests + stats_counter.
6609 * stats_counter holds per-STORM counters that are incremented when
6610 * STORM has finished with the current request. Memory for FCoE
6611 * offloaded statistics are counted anyway, even if they will not be sent.
6612 * VF stats are not accounted for here as the data of VF stats is stored
6613 * in memory allocated by the VF, not here.
6615 sc->fw_stats_data_size =
6616 (sizeof(struct stats_counter) +
6617 sizeof(struct per_port_stats) +
6618 sizeof(struct per_pf_stats) +
6619 /* sizeof(struct fcoe_statistics_params) + */
6620 (sizeof(struct per_queue_stats) * num_queue_stats));
6622 if (bxe_dma_alloc(sc, (sc->fw_stats_req_size + sc->fw_stats_data_size),
6623 &sc->fw_stats_dma, "fw stats") != 0) {
6624 bxe_free_fw_stats_mem(sc);
6628 /* set up the shortcuts */
6631 (struct bxe_fw_stats_req *)sc->fw_stats_dma.vaddr;
6632 sc->fw_stats_req_mapping = sc->fw_stats_dma.paddr;
6635 (struct bxe_fw_stats_data *)((uint8_t *)sc->fw_stats_dma.vaddr +
6636 sc->fw_stats_req_size);
6637 sc->fw_stats_data_mapping = (sc->fw_stats_dma.paddr +
6638 sc->fw_stats_req_size);
6640 BLOGD(sc, DBG_LOAD, "statistics request base address set to %#jx\n",
6641 (uintmax_t)sc->fw_stats_req_mapping);
6643 BLOGD(sc, DBG_LOAD, "statistics data base address set to %#jx\n",
6644 (uintmax_t)sc->fw_stats_data_mapping);
6651 * 0-7 - Engine0 load counter.
6652 * 8-15 - Engine1 load counter.
6653 * 16 - Engine0 RESET_IN_PROGRESS bit.
6654 * 17 - Engine1 RESET_IN_PROGRESS bit.
6655 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active
6656 * function on the engine
6657 * 19 - Engine1 ONE_IS_LOADED.
6658 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
6659 * leader to complete (check for both RESET_IN_PROGRESS bits and not
6660 * for just the one belonging to its engine).
6662 #define BXE_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
6663 #define BXE_PATH0_LOAD_CNT_MASK 0x000000ff
6664 #define BXE_PATH0_LOAD_CNT_SHIFT 0
6665 #define BXE_PATH1_LOAD_CNT_MASK 0x0000ff00
6666 #define BXE_PATH1_LOAD_CNT_SHIFT 8
6667 #define BXE_PATH0_RST_IN_PROG_BIT 0x00010000
6668 #define BXE_PATH1_RST_IN_PROG_BIT 0x00020000
6669 #define BXE_GLOBAL_RESET_BIT 0x00040000
6671 /* set the GLOBAL_RESET bit, should be run under rtnl lock */
6673 bxe_set_reset_global(struct bxe_softc *sc)
6676 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6677 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6678 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val | BXE_GLOBAL_RESET_BIT);
6679 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6682 /* clear the GLOBAL_RESET bit, should be run under rtnl lock */
6684 bxe_clear_reset_global(struct bxe_softc *sc)
6687 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6688 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6689 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val & (~BXE_GLOBAL_RESET_BIT));
6690 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6693 /* checks the GLOBAL_RESET bit, should be run under rtnl lock */
6695 bxe_reset_is_global(struct bxe_softc *sc)
6697 uint32_t val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6698 BLOGD(sc, DBG_LOAD, "GLOB_REG=0x%08x\n", val);
6699 return (val & BXE_GLOBAL_RESET_BIT) ? TRUE : FALSE;
6702 /* clear RESET_IN_PROGRESS bit for the engine, should be run under rtnl lock */
6704 bxe_set_reset_done(struct bxe_softc *sc)
6707 uint32_t bit = SC_PATH(sc) ? BXE_PATH1_RST_IN_PROG_BIT :
6708 BXE_PATH0_RST_IN_PROG_BIT;
6710 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6712 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6715 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val);
6717 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6720 /* set RESET_IN_PROGRESS for the engine, should be run under rtnl lock */
6722 bxe_set_reset_in_progress(struct bxe_softc *sc)
6725 uint32_t bit = SC_PATH(sc) ? BXE_PATH1_RST_IN_PROG_BIT :
6726 BXE_PATH0_RST_IN_PROG_BIT;
6728 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6730 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6733 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val);
6735 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6738 /* check RESET_IN_PROGRESS bit for an engine, should be run under rtnl lock */
6740 bxe_reset_is_done(struct bxe_softc *sc,
6743 uint32_t val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6744 uint32_t bit = engine ? BXE_PATH1_RST_IN_PROG_BIT :
6745 BXE_PATH0_RST_IN_PROG_BIT;
6747 /* return false if bit is set */
6748 return (val & bit) ? FALSE : TRUE;
6751 /* get the load status for an engine, should be run under rtnl lock */
6753 bxe_get_load_status(struct bxe_softc *sc,
6756 uint32_t mask = engine ? BXE_PATH1_LOAD_CNT_MASK :
6757 BXE_PATH0_LOAD_CNT_MASK;
6758 uint32_t shift = engine ? BXE_PATH1_LOAD_CNT_SHIFT :
6759 BXE_PATH0_LOAD_CNT_SHIFT;
6760 uint32_t val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6762 BLOGD(sc, DBG_LOAD, "Old value for GLOB_REG=0x%08x\n", val);
6764 val = ((val & mask) >> shift);
6766 BLOGD(sc, DBG_LOAD, "Load mask engine %d = 0x%08x\n", engine, val);
6771 /* set pf load mark */
6772 /* XXX needs to be under rtnl lock */
6774 bxe_set_pf_load(struct bxe_softc *sc)
6778 uint32_t mask = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_MASK :
6779 BXE_PATH0_LOAD_CNT_MASK;
6780 uint32_t shift = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_SHIFT :
6781 BXE_PATH0_LOAD_CNT_SHIFT;
6783 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6785 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6786 BLOGD(sc, DBG_LOAD, "Old value for GLOB_REG=0x%08x\n", val);
6788 /* get the current counter value */
6789 val1 = ((val & mask) >> shift);
6791 /* set bit of this PF */
6792 val1 |= (1 << SC_ABS_FUNC(sc));
6794 /* clear the old value */
6797 /* set the new one */
6798 val |= ((val1 << shift) & mask);
6800 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val);
6802 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6805 /* clear pf load mark */
6806 /* XXX needs to be under rtnl lock */
6808 bxe_clear_pf_load(struct bxe_softc *sc)
6811 uint32_t mask = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_MASK :
6812 BXE_PATH0_LOAD_CNT_MASK;
6813 uint32_t shift = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_SHIFT :
6814 BXE_PATH0_LOAD_CNT_SHIFT;
6816 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6817 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6818 BLOGD(sc, DBG_LOAD, "Old GEN_REG_VAL=0x%08x\n", val);
6820 /* get the current counter value */
6821 val1 = (val & mask) >> shift;
6823 /* clear bit of that PF */
6824 val1 &= ~(1 << SC_ABS_FUNC(sc));
6826 /* clear the old value */
6829 /* set the new one */
6830 val |= ((val1 << shift) & mask);
6832 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val);
6833 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6837 /* send load requrest to mcp and analyze response */
6839 bxe_nic_load_request(struct bxe_softc *sc,
6840 uint32_t *load_code)
6844 (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_mb_header) &
6845 DRV_MSG_SEQ_NUMBER_MASK);
6847 BLOGD(sc, DBG_LOAD, "initial fw_seq 0x%04x\n", sc->fw_seq);
6849 /* get the current FW pulse sequence */
6850 sc->fw_drv_pulse_wr_seq =
6851 (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_pulse_mb) &
6852 DRV_PULSE_SEQ_MASK);
6854 BLOGD(sc, DBG_LOAD, "initial drv_pulse 0x%04x\n",
6855 sc->fw_drv_pulse_wr_seq);
6858 (*load_code) = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_REQ,
6859 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
6861 /* if the MCP fails to respond we must abort */
6862 if (!(*load_code)) {
6863 BLOGE(sc, "MCP response failure!\n");
6867 /* if MCP refused then must abort */
6868 if ((*load_code) == FW_MSG_CODE_DRV_LOAD_REFUSED) {
6869 BLOGE(sc, "MCP refused load request\n");
6877 * Check whether another PF has already loaded FW to chip. In virtualized
6878 * environments a pf from anoth VM may have already initialized the device
6879 * including loading FW.
6882 bxe_nic_load_analyze_req(struct bxe_softc *sc,
6885 uint32_t my_fw, loaded_fw;
6887 /* is another pf loaded on this engine? */
6888 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
6889 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
6890 /* build my FW version dword */
6891 my_fw = (BCM_5710_FW_MAJOR_VERSION +
6892 (BCM_5710_FW_MINOR_VERSION << 8 ) +
6893 (BCM_5710_FW_REVISION_VERSION << 16) +
6894 (BCM_5710_FW_ENGINEERING_VERSION << 24));
6896 /* read loaded FW from chip */
6897 loaded_fw = REG_RD(sc, XSEM_REG_PRAM);
6898 BLOGD(sc, DBG_LOAD, "loaded FW 0x%08x / my FW 0x%08x\n",
6901 /* abort nic load if version mismatch */
6902 if (my_fw != loaded_fw) {
6903 BLOGE(sc, "FW 0x%08x already loaded (mine is 0x%08x)",
6912 /* mark PMF if applicable */
6914 bxe_nic_load_pmf(struct bxe_softc *sc,
6917 uint32_t ncsi_oem_data_addr;
6919 if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) ||
6920 (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) ||
6921 (load_code == FW_MSG_CODE_DRV_LOAD_PORT)) {
6923 * Barrier here for ordering between the writing to sc->port.pmf here
6924 * and reading it from the periodic task.
6932 BLOGD(sc, DBG_LOAD, "pmf %d\n", sc->port.pmf);
6935 if (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) {
6936 if (SHMEM2_HAS(sc, ncsi_oem_data_addr)) {
6937 ncsi_oem_data_addr = SHMEM2_RD(sc, ncsi_oem_data_addr);
6938 if (ncsi_oem_data_addr) {
6940 (ncsi_oem_data_addr +
6941 offsetof(struct glob_ncsi_oem_data, driver_version)),
6949 bxe_read_mf_cfg(struct bxe_softc *sc)
6951 int n = (CHIP_IS_MODE_4_PORT(sc) ? 2 : 1);
6955 if (BXE_NOMCP(sc)) {
6956 return; /* what should be the default bvalue in this case */
6960 * The formula for computing the absolute function number is...
6961 * For 2 port configuration (4 functions per port):
6962 * abs_func = 2 * vn + SC_PORT + SC_PATH
6963 * For 4 port configuration (2 functions per port):
6964 * abs_func = 4 * vn + 2 * SC_PORT + SC_PATH
6966 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
6967 abs_func = (n * (2 * vn + SC_PORT(sc)) + SC_PATH(sc));
6968 if (abs_func >= E1H_FUNC_MAX) {
6971 sc->devinfo.mf_info.mf_config[vn] =
6972 MFCFG_RD(sc, func_mf_config[abs_func].config);
6975 if (sc->devinfo.mf_info.mf_config[SC_VN(sc)] &
6976 FUNC_MF_CFG_FUNC_DISABLED) {
6977 BLOGD(sc, DBG_LOAD, "mf_cfg function disabled\n");
6978 sc->flags |= BXE_MF_FUNC_DIS;
6980 BLOGD(sc, DBG_LOAD, "mf_cfg function enabled\n");
6981 sc->flags &= ~BXE_MF_FUNC_DIS;
6985 /* acquire split MCP access lock register */
6986 static int bxe_acquire_alr(struct bxe_softc *sc)
6990 for (j = 0; j < 1000; j++) {
6992 REG_WR(sc, GRCBASE_MCP + 0x9c, val);
6993 val = REG_RD(sc, GRCBASE_MCP + 0x9c);
6994 if (val & (1L << 31))
7000 if (!(val & (1L << 31))) {
7001 BLOGE(sc, "Cannot acquire MCP access lock register\n");
7008 /* release split MCP access lock register */
7009 static void bxe_release_alr(struct bxe_softc *sc)
7011 REG_WR(sc, GRCBASE_MCP + 0x9c, 0);
7015 bxe_fan_failure(struct bxe_softc *sc)
7017 int port = SC_PORT(sc);
7018 uint32_t ext_phy_config;
7020 /* mark the failure */
7022 SHMEM_RD(sc, dev_info.port_hw_config[port].external_phy_config);
7024 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
7025 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
7026 SHMEM_WR(sc, dev_info.port_hw_config[port].external_phy_config,
7029 /* log the failure */
7030 BLOGW(sc, "Fan Failure has caused the driver to shutdown "
7031 "the card to prevent permanent damage. "
7032 "Please contact OEM Support for assistance\n");
7036 bxe_panic(sc, ("Schedule task to handle fan failure\n"));
7039 * Schedule device reset (unload)
7040 * This is due to some boards consuming sufficient power when driver is
7041 * up to overheat if fan fails.
7043 bxe_set_bit(BXE_SP_RTNL_FAN_FAILURE, &sc->sp_rtnl_state);
7044 schedule_delayed_work(&sc->sp_rtnl_task, 0);
7048 /* this function is called upon a link interrupt */
7050 bxe_link_attn(struct bxe_softc *sc)
7052 uint32_t pause_enabled = 0;
7053 struct host_port_stats *pstats;
7055 struct bxe_fastpath *fp;
7058 /* Make sure that we are synced with the current statistics */
7059 bxe_stats_handle(sc, STATS_EVENT_STOP);
7060 BLOGD(sc, DBG_LOAD, "link_vars phy_flags : %x\n", sc->link_vars.phy_flags);
7061 elink_link_update(&sc->link_params, &sc->link_vars);
7063 if (sc->link_vars.link_up) {
7065 /* dropless flow control */
7066 if (!CHIP_IS_E1(sc) && sc->dropless_fc) {
7069 if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_TX) {
7074 (BAR_USTRORM_INTMEM +
7075 USTORM_ETH_PAUSE_ENABLED_OFFSET(SC_PORT(sc))),
7079 if (sc->link_vars.mac_type != ELINK_MAC_TYPE_EMAC) {
7080 pstats = BXE_SP(sc, port_stats);
7081 /* reset old mac stats */
7082 memset(&(pstats->mac_stx[0]), 0, sizeof(struct mac_stx));
7085 if (sc->state == BXE_STATE_OPEN) {
7086 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
7087 /* Restart tx when the link comes back. */
7088 FOR_EACH_ETH_QUEUE(sc, i) {
7090 taskqueue_enqueue(fp->tq, &fp->tx_task);
7096 if (sc->link_vars.link_up && sc->link_vars.line_speed) {
7097 cmng_fns = bxe_get_cmng_fns_mode(sc);
7099 if (cmng_fns != CMNG_FNS_NONE) {
7100 bxe_cmng_fns_init(sc, FALSE, cmng_fns);
7101 storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc));
7103 /* rate shaping and fairness are disabled */
7104 BLOGD(sc, DBG_LOAD, "single function mode without fairness\n");
7108 bxe_link_report_locked(sc);
7111 ; // XXX bxe_link_sync_notify(sc);
7116 bxe_attn_int_asserted(struct bxe_softc *sc,
7119 int port = SC_PORT(sc);
7120 uint32_t aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
7121 MISC_REG_AEU_MASK_ATTN_FUNC_0;
7122 uint32_t nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
7123 NIG_REG_MASK_INTERRUPT_PORT0;
7125 uint32_t nig_mask = 0;
7130 if (sc->attn_state & asserted) {
7131 BLOGE(sc, "IGU ERROR attn=0x%08x\n", asserted);
7134 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
7136 aeu_mask = REG_RD(sc, aeu_addr);
7138 BLOGD(sc, DBG_INTR, "aeu_mask 0x%08x newly asserted 0x%08x\n",
7139 aeu_mask, asserted);
7141 aeu_mask &= ~(asserted & 0x3ff);
7143 BLOGD(sc, DBG_INTR, "new mask 0x%08x\n", aeu_mask);
7145 REG_WR(sc, aeu_addr, aeu_mask);
7147 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
7149 BLOGD(sc, DBG_INTR, "attn_state 0x%08x\n", sc->attn_state);
7150 sc->attn_state |= asserted;
7151 BLOGD(sc, DBG_INTR, "new state 0x%08x\n", sc->attn_state);
7153 if (asserted & ATTN_HARD_WIRED_MASK) {
7154 if (asserted & ATTN_NIG_FOR_FUNC) {
7156 bxe_acquire_phy_lock(sc);
7157 /* save nig interrupt mask */
7158 nig_mask = REG_RD(sc, nig_int_mask_addr);
7160 /* If nig_mask is not set, no need to call the update function */
7162 REG_WR(sc, nig_int_mask_addr, 0);
7167 /* handle unicore attn? */
7170 if (asserted & ATTN_SW_TIMER_4_FUNC) {
7171 BLOGD(sc, DBG_INTR, "ATTN_SW_TIMER_4_FUNC!\n");
7174 if (asserted & GPIO_2_FUNC) {
7175 BLOGD(sc, DBG_INTR, "GPIO_2_FUNC!\n");
7178 if (asserted & GPIO_3_FUNC) {
7179 BLOGD(sc, DBG_INTR, "GPIO_3_FUNC!\n");
7182 if (asserted & GPIO_4_FUNC) {
7183 BLOGD(sc, DBG_INTR, "GPIO_4_FUNC!\n");
7187 if (asserted & ATTN_GENERAL_ATTN_1) {
7188 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_1!\n");
7189 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
7191 if (asserted & ATTN_GENERAL_ATTN_2) {
7192 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_2!\n");
7193 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
7195 if (asserted & ATTN_GENERAL_ATTN_3) {
7196 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_3!\n");
7197 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
7200 if (asserted & ATTN_GENERAL_ATTN_4) {
7201 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_4!\n");
7202 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
7204 if (asserted & ATTN_GENERAL_ATTN_5) {
7205 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_5!\n");
7206 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
7208 if (asserted & ATTN_GENERAL_ATTN_6) {
7209 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_6!\n");
7210 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
7215 if (sc->devinfo.int_block == INT_BLOCK_HC) {
7216 reg_addr = (HC_REG_COMMAND_REG + port*32 + COMMAND_REG_ATTN_BITS_SET);
7218 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
7221 BLOGD(sc, DBG_INTR, "about to mask 0x%08x at %s addr 0x%08x\n",
7223 (sc->devinfo.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
7224 REG_WR(sc, reg_addr, asserted);
7226 /* now set back the mask */
7227 if (asserted & ATTN_NIG_FOR_FUNC) {
7229 * Verify that IGU ack through BAR was written before restoring
7230 * NIG mask. This loop should exit after 2-3 iterations max.
7232 if (sc->devinfo.int_block != INT_BLOCK_HC) {
7236 igu_acked = REG_RD(sc, IGU_REG_ATTENTION_ACK_BITS);
7237 } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
7238 (++cnt < MAX_IGU_ATTN_ACK_TO));
7241 BLOGE(sc, "Failed to verify IGU ack on time\n");
7247 REG_WR(sc, nig_int_mask_addr, nig_mask);
7249 bxe_release_phy_lock(sc);
7254 bxe_print_next_block(struct bxe_softc *sc,
7258 BLOGI(sc, "%s%s", idx ? ", " : "", blk);
7262 bxe_check_blocks_with_parity0(struct bxe_softc *sc,
7267 uint32_t cur_bit = 0;
7270 for (i = 0; sig; i++) {
7271 cur_bit = ((uint32_t)0x1 << i);
7272 if (sig & cur_bit) {
7274 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
7276 bxe_print_next_block(sc, par_num++, "BRB");
7278 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
7280 bxe_print_next_block(sc, par_num++, "PARSER");
7282 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
7284 bxe_print_next_block(sc, par_num++, "TSDM");
7286 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
7288 bxe_print_next_block(sc, par_num++, "SEARCHER");
7290 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
7292 bxe_print_next_block(sc, par_num++, "TCM");
7294 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
7296 bxe_print_next_block(sc, par_num++, "TSEMI");
7298 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
7300 bxe_print_next_block(sc, par_num++, "XPB");
7313 bxe_check_blocks_with_parity1(struct bxe_softc *sc,
7320 uint32_t cur_bit = 0;
7321 for (i = 0; sig; i++) {
7322 cur_bit = ((uint32_t)0x1 << i);
7323 if (sig & cur_bit) {
7325 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
7327 bxe_print_next_block(sc, par_num++, "PBF");
7329 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
7331 bxe_print_next_block(sc, par_num++, "QM");
7333 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
7335 bxe_print_next_block(sc, par_num++, "TM");
7337 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
7339 bxe_print_next_block(sc, par_num++, "XSDM");
7341 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
7343 bxe_print_next_block(sc, par_num++, "XCM");
7345 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
7347 bxe_print_next_block(sc, par_num++, "XSEMI");
7349 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
7351 bxe_print_next_block(sc, par_num++, "DOORBELLQ");
7353 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
7355 bxe_print_next_block(sc, par_num++, "NIG");
7357 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
7359 bxe_print_next_block(sc, par_num++, "VAUX PCI CORE");
7362 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
7364 bxe_print_next_block(sc, par_num++, "DEBUG");
7366 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
7368 bxe_print_next_block(sc, par_num++, "USDM");
7370 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
7372 bxe_print_next_block(sc, par_num++, "UCM");
7374 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
7376 bxe_print_next_block(sc, par_num++, "USEMI");
7378 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
7380 bxe_print_next_block(sc, par_num++, "UPB");
7382 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
7384 bxe_print_next_block(sc, par_num++, "CSDM");
7386 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
7388 bxe_print_next_block(sc, par_num++, "CCM");
7401 bxe_check_blocks_with_parity2(struct bxe_softc *sc,
7406 uint32_t cur_bit = 0;
7409 for (i = 0; sig; i++) {
7410 cur_bit = ((uint32_t)0x1 << i);
7411 if (sig & cur_bit) {
7413 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
7415 bxe_print_next_block(sc, par_num++, "CSEMI");
7417 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
7419 bxe_print_next_block(sc, par_num++, "PXP");
7421 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
7423 bxe_print_next_block(sc, par_num++, "PXPPCICLOCKCLIENT");
7425 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
7427 bxe_print_next_block(sc, par_num++, "CFC");
7429 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
7431 bxe_print_next_block(sc, par_num++, "CDU");
7433 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
7435 bxe_print_next_block(sc, par_num++, "DMAE");
7437 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
7439 bxe_print_next_block(sc, par_num++, "IGU");
7441 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
7443 bxe_print_next_block(sc, par_num++, "MISC");
7456 bxe_check_blocks_with_parity3(struct bxe_softc *sc,
7462 uint32_t cur_bit = 0;
7465 for (i = 0; sig; i++) {
7466 cur_bit = ((uint32_t)0x1 << i);
7467 if (sig & cur_bit) {
7469 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
7471 bxe_print_next_block(sc, par_num++, "MCP ROM");
7474 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
7476 bxe_print_next_block(sc, par_num++,
7480 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
7482 bxe_print_next_block(sc, par_num++,
7486 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
7488 bxe_print_next_block(sc, par_num++,
7503 bxe_check_blocks_with_parity4(struct bxe_softc *sc,
7508 uint32_t cur_bit = 0;
7511 for (i = 0; sig; i++) {
7512 cur_bit = ((uint32_t)0x1 << i);
7513 if (sig & cur_bit) {
7515 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
7517 bxe_print_next_block(sc, par_num++, "PGLUE_B");
7519 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
7521 bxe_print_next_block(sc, par_num++, "ATC");
7534 bxe_parity_attn(struct bxe_softc *sc,
7541 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
7542 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
7543 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
7544 (sig[3] & HW_PRTY_ASSERT_SET_3) ||
7545 (sig[4] & HW_PRTY_ASSERT_SET_4)) {
7546 BLOGE(sc, "Parity error: HW block parity attention:\n"
7547 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
7548 (uint32_t)(sig[0] & HW_PRTY_ASSERT_SET_0),
7549 (uint32_t)(sig[1] & HW_PRTY_ASSERT_SET_1),
7550 (uint32_t)(sig[2] & HW_PRTY_ASSERT_SET_2),
7551 (uint32_t)(sig[3] & HW_PRTY_ASSERT_SET_3),
7552 (uint32_t)(sig[4] & HW_PRTY_ASSERT_SET_4));
7555 BLOGI(sc, "Parity errors detected in blocks: ");
7558 bxe_check_blocks_with_parity0(sc, sig[0] &
7559 HW_PRTY_ASSERT_SET_0,
7562 bxe_check_blocks_with_parity1(sc, sig[1] &
7563 HW_PRTY_ASSERT_SET_1,
7564 par_num, global, print);
7566 bxe_check_blocks_with_parity2(sc, sig[2] &
7567 HW_PRTY_ASSERT_SET_2,
7570 bxe_check_blocks_with_parity3(sc, sig[3] &
7571 HW_PRTY_ASSERT_SET_3,
7572 par_num, global, print);
7574 bxe_check_blocks_with_parity4(sc, sig[4] &
7575 HW_PRTY_ASSERT_SET_4,
7581 if( *global == TRUE ) {
7582 BXE_SET_ERROR_BIT(sc, BXE_ERR_GLOBAL);
7592 bxe_chk_parity_attn(struct bxe_softc *sc,
7596 struct attn_route attn = { {0} };
7597 int port = SC_PORT(sc);
7599 if(sc->state != BXE_STATE_OPEN)
7602 attn.sig[0] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
7603 attn.sig[1] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
7604 attn.sig[2] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
7605 attn.sig[3] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
7608 * Since MCP attentions can't be disabled inside the block, we need to
7609 * read AEU registers to see whether they're currently disabled
7611 attn.sig[3] &= ((REG_RD(sc, (!port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
7612 : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0)) &
7613 MISC_AEU_ENABLE_MCP_PRTY_BITS) |
7614 ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
7617 if (!CHIP_IS_E1x(sc))
7618 attn.sig[4] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
7620 return (bxe_parity_attn(sc, global, print, attn.sig));
7624 bxe_attn_int_deasserted4(struct bxe_softc *sc,
7628 boolean_t err_flg = FALSE;
7630 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
7631 val = REG_RD(sc, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
7632 BLOGE(sc, "PGLUE hw attention 0x%08x\n", val);
7634 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
7635 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
7636 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
7637 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
7638 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
7639 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
7640 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
7641 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
7642 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
7643 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
7644 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
7645 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
7646 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
7647 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
7648 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
7649 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
7650 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
7651 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
7654 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
7655 val = REG_RD(sc, ATC_REG_ATC_INT_STS_CLR);
7656 BLOGE(sc, "ATC hw attention 0x%08x\n", val);
7658 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
7659 BLOGE(sc, "ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
7660 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
7661 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
7662 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
7663 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
7664 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
7665 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
7666 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
7667 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
7668 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
7669 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
7672 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
7673 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
7674 BLOGE(sc, "FATAL parity attention set4 0x%08x\n",
7675 (uint32_t)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
7676 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
7680 BXE_SET_ERROR_BIT(sc, BXE_ERR_MISC);
7681 taskqueue_enqueue_timeout(taskqueue_thread,
7682 &sc->sp_err_timeout_task, hz/10);
7688 bxe_e1h_disable(struct bxe_softc *sc)
7690 int port = SC_PORT(sc);
7694 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 0);
7698 bxe_e1h_enable(struct bxe_softc *sc)
7700 int port = SC_PORT(sc);
7702 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 1);
7704 // XXX bxe_tx_enable(sc);
7708 * called due to MCP event (on pmf):
7709 * reread new bandwidth configuration
7711 * notify others function about the change
7714 bxe_config_mf_bw(struct bxe_softc *sc)
7716 if (sc->link_vars.link_up) {
7717 bxe_cmng_fns_init(sc, TRUE, CMNG_FNS_MINMAX);
7718 // XXX bxe_link_sync_notify(sc);
7721 storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc));
7725 bxe_set_mf_bw(struct bxe_softc *sc)
7727 bxe_config_mf_bw(sc);
7728 bxe_fw_command(sc, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
7732 bxe_handle_eee_event(struct bxe_softc *sc)
7734 BLOGD(sc, DBG_INTR, "EEE - LLDP event\n");
7735 bxe_fw_command(sc, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
7738 #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
7741 bxe_drv_info_ether_stat(struct bxe_softc *sc)
7743 struct eth_stats_info *ether_stat =
7744 &sc->sp->drv_info_to_mcp.ether_stat;
7746 strlcpy(ether_stat->version, BXE_DRIVER_VERSION,
7747 ETH_STAT_INFO_VERSION_LEN);
7749 /* XXX (+ MAC_PAD) taken from other driver... verify this is right */
7750 sc->sp_objs[0].mac_obj.get_n_elements(sc, &sc->sp_objs[0].mac_obj,
7751 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
7752 ether_stat->mac_local + MAC_PAD,
7755 ether_stat->mtu_size = sc->mtu;
7757 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
7758 if (sc->ifnet->if_capenable & (IFCAP_TSO4 | IFCAP_TSO6)) {
7759 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
7762 // XXX ether_stat->feature_flags |= ???;
7764 ether_stat->promiscuous_mode = 0; // (flags & PROMISC) ? 1 : 0;
7766 ether_stat->txq_size = sc->tx_ring_size;
7767 ether_stat->rxq_size = sc->rx_ring_size;
7771 bxe_handle_drv_info_req(struct bxe_softc *sc)
7773 enum drv_info_opcode op_code;
7774 uint32_t drv_info_ctl = SHMEM2_RD(sc, drv_info_control);
7776 /* if drv_info version supported by MFW doesn't match - send NACK */
7777 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
7778 bxe_fw_command(sc, DRV_MSG_CODE_DRV_INFO_NACK, 0);
7782 op_code = ((drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
7783 DRV_INFO_CONTROL_OP_CODE_SHIFT);
7785 memset(&sc->sp->drv_info_to_mcp, 0, sizeof(union drv_info_to_mcp));
7788 case ETH_STATS_OPCODE:
7789 bxe_drv_info_ether_stat(sc);
7791 case FCOE_STATS_OPCODE:
7792 case ISCSI_STATS_OPCODE:
7794 /* if op code isn't supported - send NACK */
7795 bxe_fw_command(sc, DRV_MSG_CODE_DRV_INFO_NACK, 0);
7800 * If we got drv_info attn from MFW then these fields are defined in
7803 SHMEM2_WR(sc, drv_info_host_addr_lo,
7804 U64_LO(BXE_SP_MAPPING(sc, drv_info_to_mcp)));
7805 SHMEM2_WR(sc, drv_info_host_addr_hi,
7806 U64_HI(BXE_SP_MAPPING(sc, drv_info_to_mcp)));
7808 bxe_fw_command(sc, DRV_MSG_CODE_DRV_INFO_ACK, 0);
7812 bxe_dcc_event(struct bxe_softc *sc,
7815 BLOGD(sc, DBG_INTR, "dcc_event 0x%08x\n", dcc_event);
7817 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
7819 * This is the only place besides the function initialization
7820 * where the sc->flags can change so it is done without any
7823 if (sc->devinfo.mf_info.mf_config[SC_VN(sc)] & FUNC_MF_CFG_FUNC_DISABLED) {
7824 BLOGD(sc, DBG_INTR, "mf_cfg function disabled\n");
7825 sc->flags |= BXE_MF_FUNC_DIS;
7826 bxe_e1h_disable(sc);
7828 BLOGD(sc, DBG_INTR, "mf_cfg function enabled\n");
7829 sc->flags &= ~BXE_MF_FUNC_DIS;
7832 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
7835 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
7836 bxe_config_mf_bw(sc);
7837 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
7840 /* Report results to MCP */
7842 bxe_fw_command(sc, DRV_MSG_CODE_DCC_FAILURE, 0);
7844 bxe_fw_command(sc, DRV_MSG_CODE_DCC_OK, 0);
7848 bxe_pmf_update(struct bxe_softc *sc)
7850 int port = SC_PORT(sc);
7854 BLOGD(sc, DBG_INTR, "pmf %d\n", sc->port.pmf);
7857 * We need the mb() to ensure the ordering between the writing to
7858 * sc->port.pmf here and reading it from the bxe_periodic_task().
7862 /* queue a periodic task */
7863 // XXX schedule task...
7865 // XXX bxe_dcbx_pmf_update(sc);
7867 /* enable nig attention */
7868 val = (0xff0f | (1 << (SC_VN(sc) + 4)));
7869 if (sc->devinfo.int_block == INT_BLOCK_HC) {
7870 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, val);
7871 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, val);
7872 } else if (!CHIP_IS_E1x(sc)) {
7873 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, val);
7874 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, val);
7877 bxe_stats_handle(sc, STATS_EVENT_PMF);
7881 bxe_mc_assert(struct bxe_softc *sc)
7885 uint32_t row0, row1, row2, row3;
7888 last_idx = REG_RD8(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_INDEX_OFFSET);
7890 BLOGE(sc, "XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
7892 /* print the asserts */
7893 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
7895 row0 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i));
7896 row1 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) + 4);
7897 row2 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) + 8);
7898 row3 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) + 12);
7900 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
7901 BLOGE(sc, "XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
7902 i, row3, row2, row1, row0);
7910 last_idx = REG_RD8(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_INDEX_OFFSET);
7912 BLOGE(sc, "TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
7915 /* print the asserts */
7916 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
7918 row0 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i));
7919 row1 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) + 4);
7920 row2 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) + 8);
7921 row3 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) + 12);
7923 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
7924 BLOGE(sc, "TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
7925 i, row3, row2, row1, row0);
7933 last_idx = REG_RD8(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_INDEX_OFFSET);
7935 BLOGE(sc, "CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
7938 /* print the asserts */
7939 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
7941 row0 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i));
7942 row1 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) + 4);
7943 row2 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) + 8);
7944 row3 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) + 12);
7946 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
7947 BLOGE(sc, "CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
7948 i, row3, row2, row1, row0);
7956 last_idx = REG_RD8(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_INDEX_OFFSET);
7958 BLOGE(sc, "USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
7961 /* print the asserts */
7962 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
7964 row0 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i));
7965 row1 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) + 4);
7966 row2 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) + 8);
7967 row3 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) + 12);
7969 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
7970 BLOGE(sc, "USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
7971 i, row3, row2, row1, row0);
7982 bxe_attn_int_deasserted3(struct bxe_softc *sc,
7985 int func = SC_FUNC(sc);
7988 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
7990 if (attn & BXE_PMF_LINK_ASSERT(sc)) {
7992 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7993 bxe_read_mf_cfg(sc);
7994 sc->devinfo.mf_info.mf_config[SC_VN(sc)] =
7995 MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config);
7996 val = SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_status);
7998 if (val & DRV_STATUS_DCC_EVENT_MASK)
7999 bxe_dcc_event(sc, (val & DRV_STATUS_DCC_EVENT_MASK));
8001 if (val & DRV_STATUS_SET_MF_BW)
8004 if (val & DRV_STATUS_DRV_INFO_REQ)
8005 bxe_handle_drv_info_req(sc);
8007 if ((sc->port.pmf == 0) && (val & DRV_STATUS_PMF))
8010 if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
8011 bxe_handle_eee_event(sc);
8013 if (sc->link_vars.periodic_flags &
8014 ELINK_PERIODIC_FLAGS_LINK_EVENT) {
8015 /* sync with link */
8016 bxe_acquire_phy_lock(sc);
8017 sc->link_vars.periodic_flags &=
8018 ~ELINK_PERIODIC_FLAGS_LINK_EVENT;
8019 bxe_release_phy_lock(sc);
8021 ; // XXX bxe_link_sync_notify(sc);
8022 bxe_link_report(sc);
8026 * Always call it here: bxe_link_report() will
8027 * prevent the link indication duplication.
8029 bxe_link_status_update(sc);
8031 } else if (attn & BXE_MC_ASSERT_BITS) {
8033 BLOGE(sc, "MC assert!\n");
8035 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_10, 0);
8036 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_9, 0);
8037 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_8, 0);
8038 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_7, 0);
8039 bxe_int_disable(sc);
8040 BXE_SET_ERROR_BIT(sc, BXE_ERR_MC_ASSERT);
8041 taskqueue_enqueue_timeout(taskqueue_thread,
8042 &sc->sp_err_timeout_task, hz/10);
8044 } else if (attn & BXE_MCP_ASSERT) {
8046 BLOGE(sc, "MCP assert!\n");
8047 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_11, 0);
8048 BXE_SET_ERROR_BIT(sc, BXE_ERR_MCP_ASSERT);
8049 taskqueue_enqueue_timeout(taskqueue_thread,
8050 &sc->sp_err_timeout_task, hz/10);
8051 bxe_int_disable(sc); /*avoid repetive assert alert */
8055 BLOGE(sc, "Unknown HW assert! (attn 0x%08x)\n", attn);
8059 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
8060 BLOGE(sc, "LATCHED attention 0x%08x (masked)\n", attn);
8061 if (attn & BXE_GRC_TIMEOUT) {
8062 val = CHIP_IS_E1(sc) ? 0 : REG_RD(sc, MISC_REG_GRC_TIMEOUT_ATTN);
8063 BLOGE(sc, "GRC time-out 0x%08x\n", val);
8065 if (attn & BXE_GRC_RSV) {
8066 val = CHIP_IS_E1(sc) ? 0 : REG_RD(sc, MISC_REG_GRC_RSV_ATTN);
8067 BLOGE(sc, "GRC reserved 0x%08x\n", val);
8069 REG_WR(sc, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
8074 bxe_attn_int_deasserted2(struct bxe_softc *sc,
8077 int port = SC_PORT(sc);
8079 uint32_t val0, mask0, val1, mask1;
8081 boolean_t err_flg = FALSE;
8083 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
8084 val = REG_RD(sc, CFC_REG_CFC_INT_STS_CLR);
8085 BLOGE(sc, "CFC hw attention 0x%08x\n", val);
8086 /* CFC error attention */
8088 BLOGE(sc, "FATAL error from CFC\n");
8093 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
8094 val = REG_RD(sc, PXP_REG_PXP_INT_STS_CLR_0);
8095 BLOGE(sc, "PXP hw attention-0 0x%08x\n", val);
8096 /* RQ_USDMDP_FIFO_OVERFLOW */
8097 if (val & 0x18000) {
8098 BLOGE(sc, "FATAL error from PXP\n");
8102 if (!CHIP_IS_E1x(sc)) {
8103 val = REG_RD(sc, PXP_REG_PXP_INT_STS_CLR_1);
8104 BLOGE(sc, "PXP hw attention-1 0x%08x\n", val);
8109 #define PXP2_EOP_ERROR_BIT PXP2_PXP2_INT_STS_CLR_0_REG_WR_PGLUE_EOP_ERROR
8110 #define AEU_PXP2_HW_INT_BIT AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_HW_INTERRUPT
8112 if (attn & AEU_PXP2_HW_INT_BIT) {
8113 /* CQ47854 workaround do not panic on
8114 * PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR
8116 if (!CHIP_IS_E1x(sc)) {
8117 mask0 = REG_RD(sc, PXP2_REG_PXP2_INT_MASK_0);
8118 val1 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_1);
8119 mask1 = REG_RD(sc, PXP2_REG_PXP2_INT_MASK_1);
8120 val0 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_0);
8122 * If the olny PXP2_EOP_ERROR_BIT is set in
8123 * STS0 and STS1 - clear it
8125 * probably we lose additional attentions between
8126 * STS0 and STS_CLR0, in this case user will not
8127 * be notified about them
8129 if (val0 & mask0 & PXP2_EOP_ERROR_BIT &&
8131 val0 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_CLR_0);
8133 /* print the register, since no one can restore it */
8134 BLOGE(sc, "PXP2_REG_PXP2_INT_STS_CLR_0 0x%08x\n", val0);
8137 * if PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR
8140 if (val0 & PXP2_EOP_ERROR_BIT) {
8141 BLOGE(sc, "PXP2_WR_PGLUE_EOP_ERROR\n");
8145 * if only PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR is
8146 * set then clear attention from PXP2 block without panic
8148 if (((val0 & mask0) == PXP2_EOP_ERROR_BIT) &&
8149 ((val1 & mask1) == 0))
8150 attn &= ~AEU_PXP2_HW_INT_BIT;
8155 if (attn & HW_INTERRUT_ASSERT_SET_2) {
8156 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
8157 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
8159 val = REG_RD(sc, reg_offset);
8160 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
8161 REG_WR(sc, reg_offset, val);
8163 BLOGE(sc, "FATAL HW block attention set2 0x%x\n",
8164 (uint32_t)(attn & HW_INTERRUT_ASSERT_SET_2));
8166 bxe_panic(sc, ("HW block attention set2\n"));
8169 BXE_SET_ERROR_BIT(sc, BXE_ERR_GLOBAL);
8170 taskqueue_enqueue_timeout(taskqueue_thread,
8171 &sc->sp_err_timeout_task, hz/10);
8177 bxe_attn_int_deasserted1(struct bxe_softc *sc,
8180 int port = SC_PORT(sc);
8183 boolean_t err_flg = FALSE;
8185 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
8186 val = REG_RD(sc, DORQ_REG_DORQ_INT_STS_CLR);
8187 BLOGE(sc, "DB hw attention 0x%08x\n", val);
8188 /* DORQ discard attention */
8190 BLOGE(sc, "FATAL error from DORQ\n");
8195 if (attn & HW_INTERRUT_ASSERT_SET_1) {
8196 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
8197 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
8199 val = REG_RD(sc, reg_offset);
8200 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
8201 REG_WR(sc, reg_offset, val);
8203 BLOGE(sc, "FATAL HW block attention set1 0x%08x\n",
8204 (uint32_t)(attn & HW_INTERRUT_ASSERT_SET_1));
8206 bxe_panic(sc, ("HW block attention set1\n"));
8209 BXE_SET_ERROR_BIT(sc, BXE_ERR_MISC);
8210 taskqueue_enqueue_timeout(taskqueue_thread,
8211 &sc->sp_err_timeout_task, hz/10);
8217 bxe_attn_int_deasserted0(struct bxe_softc *sc,
8220 int port = SC_PORT(sc);
8224 reg_offset = (port) ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
8225 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
8227 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
8228 val = REG_RD(sc, reg_offset);
8229 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
8230 REG_WR(sc, reg_offset, val);
8232 BLOGW(sc, "SPIO5 hw attention\n");
8234 /* Fan failure attention */
8235 elink_hw_reset_phy(&sc->link_params);
8236 bxe_fan_failure(sc);
8239 if ((attn & sc->link_vars.aeu_int_mask) && sc->port.pmf) {
8240 bxe_acquire_phy_lock(sc);
8241 elink_handle_module_detect_int(&sc->link_params);
8242 bxe_release_phy_lock(sc);
8245 if (attn & HW_INTERRUT_ASSERT_SET_0) {
8246 val = REG_RD(sc, reg_offset);
8247 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
8248 REG_WR(sc, reg_offset, val);
8251 BXE_SET_ERROR_BIT(sc, BXE_ERR_MISC);
8252 taskqueue_enqueue_timeout(taskqueue_thread,
8253 &sc->sp_err_timeout_task, hz/10);
8255 bxe_panic(sc, ("FATAL HW block attention set0 0x%lx\n",
8256 (attn & HW_INTERRUT_ASSERT_SET_0)));
8261 bxe_attn_int_deasserted(struct bxe_softc *sc,
8262 uint32_t deasserted)
8264 struct attn_route attn;
8265 struct attn_route *group_mask;
8266 int port = SC_PORT(sc);
8271 uint8_t global = FALSE;
8274 * Need to take HW lock because MCP or other port might also
8275 * try to handle this event.
8277 bxe_acquire_alr(sc);
8279 if (bxe_chk_parity_attn(sc, &global, TRUE)) {
8281 * In case of parity errors don't handle attentions so that
8282 * other function would "see" parity errors.
8284 // XXX schedule a recovery task...
8285 /* disable HW interrupts */
8286 bxe_int_disable(sc);
8287 BXE_SET_ERROR_BIT(sc, BXE_ERR_PARITY);
8288 taskqueue_enqueue_timeout(taskqueue_thread,
8289 &sc->sp_err_timeout_task, hz/10);
8290 bxe_release_alr(sc);
8294 attn.sig[0] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
8295 attn.sig[1] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
8296 attn.sig[2] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
8297 attn.sig[3] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
8298 if (!CHIP_IS_E1x(sc)) {
8299 attn.sig[4] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
8304 BLOGD(sc, DBG_INTR, "attn: 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
8305 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
8307 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
8308 if (deasserted & (1 << index)) {
8309 group_mask = &sc->attn_group[index];
8312 "group[%d]: 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n", index,
8313 group_mask->sig[0], group_mask->sig[1],
8314 group_mask->sig[2], group_mask->sig[3],
8315 group_mask->sig[4]);
8317 bxe_attn_int_deasserted4(sc, attn.sig[4] & group_mask->sig[4]);
8318 bxe_attn_int_deasserted3(sc, attn.sig[3] & group_mask->sig[3]);
8319 bxe_attn_int_deasserted1(sc, attn.sig[1] & group_mask->sig[1]);
8320 bxe_attn_int_deasserted2(sc, attn.sig[2] & group_mask->sig[2]);
8321 bxe_attn_int_deasserted0(sc, attn.sig[0] & group_mask->sig[0]);
8325 bxe_release_alr(sc);
8327 if (sc->devinfo.int_block == INT_BLOCK_HC) {
8328 reg_addr = (HC_REG_COMMAND_REG + port*32 +
8329 COMMAND_REG_ATTN_BITS_CLR);
8331 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
8336 "about to mask 0x%08x at %s addr 0x%08x\n", val,
8337 (sc->devinfo.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
8338 REG_WR(sc, reg_addr, val);
8340 if (~sc->attn_state & deasserted) {
8341 BLOGE(sc, "IGU error\n");
8344 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8345 MISC_REG_AEU_MASK_ATTN_FUNC_0;
8347 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
8349 aeu_mask = REG_RD(sc, reg_addr);
8351 BLOGD(sc, DBG_INTR, "aeu_mask 0x%08x newly deasserted 0x%08x\n",
8352 aeu_mask, deasserted);
8353 aeu_mask |= (deasserted & 0x3ff);
8354 BLOGD(sc, DBG_INTR, "new mask 0x%08x\n", aeu_mask);
8356 REG_WR(sc, reg_addr, aeu_mask);
8357 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
8359 BLOGD(sc, DBG_INTR, "attn_state 0x%08x\n", sc->attn_state);
8360 sc->attn_state &= ~deasserted;
8361 BLOGD(sc, DBG_INTR, "new state 0x%08x\n", sc->attn_state);
8365 bxe_attn_int(struct bxe_softc *sc)
8367 /* read local copy of bits */
8368 uint32_t attn_bits = le32toh(sc->def_sb->atten_status_block.attn_bits);
8369 uint32_t attn_ack = le32toh(sc->def_sb->atten_status_block.attn_bits_ack);
8370 uint32_t attn_state = sc->attn_state;
8372 /* look for changed bits */
8373 uint32_t asserted = attn_bits & ~attn_ack & ~attn_state;
8374 uint32_t deasserted = ~attn_bits & attn_ack & attn_state;
8377 "attn_bits 0x%08x attn_ack 0x%08x asserted 0x%08x deasserted 0x%08x\n",
8378 attn_bits, attn_ack, asserted, deasserted);
8380 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state)) {
8381 BLOGE(sc, "BAD attention state\n");
8384 /* handle bits that were raised */
8386 bxe_attn_int_asserted(sc, asserted);
8390 bxe_attn_int_deasserted(sc, deasserted);
8395 bxe_update_dsb_idx(struct bxe_softc *sc)
8397 struct host_sp_status_block *def_sb = sc->def_sb;
8400 mb(); /* status block is written to by the chip */
8402 if (sc->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
8403 sc->def_att_idx = def_sb->atten_status_block.attn_bits_index;
8404 rc |= BXE_DEF_SB_ATT_IDX;
8407 if (sc->def_idx != def_sb->sp_sb.running_index) {
8408 sc->def_idx = def_sb->sp_sb.running_index;
8409 rc |= BXE_DEF_SB_IDX;
8417 static inline struct ecore_queue_sp_obj *
8418 bxe_cid_to_q_obj(struct bxe_softc *sc,
8421 BLOGD(sc, DBG_SP, "retrieving fp from cid %d\n", cid);
8422 return (&sc->sp_objs[CID_TO_FP(cid, sc)].q_obj);
8426 bxe_handle_mcast_eqe(struct bxe_softc *sc)
8428 struct ecore_mcast_ramrod_params rparam;
8431 memset(&rparam, 0, sizeof(rparam));
8433 rparam.mcast_obj = &sc->mcast_obj;
8437 /* clear pending state for the last command */
8438 sc->mcast_obj.raw.clear_pending(&sc->mcast_obj.raw);
8440 /* if there are pending mcast commands - send them */
8441 if (sc->mcast_obj.check_pending(&sc->mcast_obj)) {
8442 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT);
8445 "ERROR: Failed to send pending mcast commands (%d)\n", rc);
8449 BXE_MCAST_UNLOCK(sc);
8453 bxe_handle_classification_eqe(struct bxe_softc *sc,
8454 union event_ring_elem *elem)
8456 unsigned long ramrod_flags = 0;
8458 uint32_t cid = elem->message.data.eth_event.echo & BXE_SWCID_MASK;
8459 struct ecore_vlan_mac_obj *vlan_mac_obj;
8461 /* always push next commands out, don't wait here */
8462 bit_set(&ramrod_flags, RAMROD_CONT);
8464 switch (le32toh(elem->message.data.eth_event.echo) >> BXE_SWCID_SHIFT) {
8465 case ECORE_FILTER_MAC_PENDING:
8466 BLOGD(sc, DBG_SP, "Got SETUP_MAC completions\n");
8467 vlan_mac_obj = &sc->sp_objs[cid].mac_obj;
8470 case ECORE_FILTER_MCAST_PENDING:
8471 BLOGD(sc, DBG_SP, "Got SETUP_MCAST completions\n");
8473 * This is only relevant for 57710 where multicast MACs are
8474 * configured as unicast MACs using the same ramrod.
8476 bxe_handle_mcast_eqe(sc);
8480 BLOGE(sc, "Unsupported classification command: %d\n",
8481 elem->message.data.eth_event.echo);
8485 rc = vlan_mac_obj->complete(sc, vlan_mac_obj, elem, &ramrod_flags);
8488 BLOGE(sc, "Failed to schedule new commands (%d)\n", rc);
8489 } else if (rc > 0) {
8490 BLOGD(sc, DBG_SP, "Scheduled next pending commands...\n");
8495 bxe_handle_rx_mode_eqe(struct bxe_softc *sc,
8496 union event_ring_elem *elem)
8498 bxe_clear_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state);
8500 /* send rx_mode command again if was requested */
8501 if (bxe_test_and_clear_bit(ECORE_FILTER_RX_MODE_SCHED,
8503 bxe_set_storm_rx_mode(sc);
8508 bxe_update_eq_prod(struct bxe_softc *sc,
8511 storm_memset_eq_prod(sc, prod, SC_FUNC(sc));
8512 wmb(); /* keep prod updates ordered */
8516 bxe_eq_int(struct bxe_softc *sc)
8518 uint16_t hw_cons, sw_cons, sw_prod;
8519 union event_ring_elem *elem;
8524 struct ecore_queue_sp_obj *q_obj;
8525 struct ecore_func_sp_obj *f_obj = &sc->func_obj;
8526 struct ecore_raw_obj *rss_raw = &sc->rss_conf_obj.raw;
8528 hw_cons = le16toh(*sc->eq_cons_sb);
8531 * The hw_cons range is 1-255, 257 - the sw_cons range is 0-254, 256.
8532 * when we get to the next-page we need to adjust so the loop
8533 * condition below will be met. The next element is the size of a
8534 * regular element and hence incrementing by 1
8536 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE) {
8541 * This function may never run in parallel with itself for a
8542 * specific sc and no need for a read memory barrier here.
8544 sw_cons = sc->eq_cons;
8545 sw_prod = sc->eq_prod;
8547 BLOGD(sc, DBG_SP,"EQ: hw_cons=%u sw_cons=%u eq_spq_left=0x%lx\n",
8548 hw_cons, sw_cons, atomic_load_acq_long(&sc->eq_spq_left));
8552 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
8554 elem = &sc->eq[EQ_DESC(sw_cons)];
8556 /* elem CID originates from FW, actually LE */
8557 cid = SW_CID(elem->message.data.cfc_del_event.cid);
8558 opcode = elem->message.opcode;
8560 /* handle eq element */
8563 case EVENT_RING_OPCODE_STAT_QUERY:
8564 BLOGD(sc, DBG_SP, "got statistics completion event %d\n",
8566 /* nothing to do with stats comp */
8569 case EVENT_RING_OPCODE_CFC_DEL:
8570 /* handle according to cid range */
8571 /* we may want to verify here that the sc state is HALTING */
8572 BLOGD(sc, DBG_SP, "got delete ramrod for MULTI[%d]\n", cid);
8573 q_obj = bxe_cid_to_q_obj(sc, cid);
8574 if (q_obj->complete_cmd(sc, q_obj, ECORE_Q_CMD_CFC_DEL)) {
8579 case EVENT_RING_OPCODE_STOP_TRAFFIC:
8580 BLOGD(sc, DBG_SP, "got STOP TRAFFIC\n");
8581 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_TX_STOP)) {
8584 // XXX bxe_dcbx_set_params(sc, BXE_DCBX_STATE_TX_PAUSED);
8587 case EVENT_RING_OPCODE_START_TRAFFIC:
8588 BLOGD(sc, DBG_SP, "got START TRAFFIC\n");
8589 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_TX_START)) {
8592 // XXX bxe_dcbx_set_params(sc, BXE_DCBX_STATE_TX_RELEASED);
8595 case EVENT_RING_OPCODE_FUNCTION_UPDATE:
8596 echo = elem->message.data.function_update_event.echo;
8597 if (echo == SWITCH_UPDATE) {
8598 BLOGD(sc, DBG_SP, "got FUNC_SWITCH_UPDATE ramrod\n");
8599 if (f_obj->complete_cmd(sc, f_obj,
8600 ECORE_F_CMD_SWITCH_UPDATE)) {
8606 "AFEX: ramrod completed FUNCTION_UPDATE\n");
8610 case EVENT_RING_OPCODE_FORWARD_SETUP:
8611 q_obj = &bxe_fwd_sp_obj(sc, q_obj);
8612 if (q_obj->complete_cmd(sc, q_obj,
8613 ECORE_Q_CMD_SETUP_TX_ONLY)) {
8618 case EVENT_RING_OPCODE_FUNCTION_START:
8619 BLOGD(sc, DBG_SP, "got FUNC_START ramrod\n");
8620 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_START)) {
8625 case EVENT_RING_OPCODE_FUNCTION_STOP:
8626 BLOGD(sc, DBG_SP, "got FUNC_STOP ramrod\n");
8627 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_STOP)) {
8633 switch (opcode | sc->state) {
8634 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | BXE_STATE_OPEN):
8635 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | BXE_STATE_OPENING_WAITING_PORT):
8636 cid = elem->message.data.eth_event.echo & BXE_SWCID_MASK;
8637 BLOGD(sc, DBG_SP, "got RSS_UPDATE ramrod. CID %d\n", cid);
8638 rss_raw->clear_pending(rss_raw);
8641 case (EVENT_RING_OPCODE_SET_MAC | BXE_STATE_OPEN):
8642 case (EVENT_RING_OPCODE_SET_MAC | BXE_STATE_DIAG):
8643 case (EVENT_RING_OPCODE_SET_MAC | BXE_STATE_CLOSING_WAITING_HALT):
8644 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BXE_STATE_OPEN):
8645 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BXE_STATE_DIAG):
8646 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BXE_STATE_CLOSING_WAITING_HALT):
8647 BLOGD(sc, DBG_SP, "got (un)set mac ramrod\n");
8648 bxe_handle_classification_eqe(sc, elem);
8651 case (EVENT_RING_OPCODE_MULTICAST_RULES | BXE_STATE_OPEN):
8652 case (EVENT_RING_OPCODE_MULTICAST_RULES | BXE_STATE_DIAG):
8653 case (EVENT_RING_OPCODE_MULTICAST_RULES | BXE_STATE_CLOSING_WAITING_HALT):
8654 BLOGD(sc, DBG_SP, "got mcast ramrod\n");
8655 bxe_handle_mcast_eqe(sc);
8658 case (EVENT_RING_OPCODE_FILTERS_RULES | BXE_STATE_OPEN):
8659 case (EVENT_RING_OPCODE_FILTERS_RULES | BXE_STATE_DIAG):
8660 case (EVENT_RING_OPCODE_FILTERS_RULES | BXE_STATE_CLOSING_WAITING_HALT):
8661 BLOGD(sc, DBG_SP, "got rx_mode ramrod\n");
8662 bxe_handle_rx_mode_eqe(sc, elem);
8666 /* unknown event log error and continue */
8667 BLOGE(sc, "Unknown EQ event %d, sc->state 0x%x\n",
8668 elem->message.opcode, sc->state);
8676 atomic_add_acq_long(&sc->eq_spq_left, spqe_cnt);
8678 sc->eq_cons = sw_cons;
8679 sc->eq_prod = sw_prod;
8681 /* make sure that above mem writes were issued towards the memory */
8684 /* update producer */
8685 bxe_update_eq_prod(sc, sc->eq_prod);
8689 bxe_handle_sp_tq(void *context,
8692 struct bxe_softc *sc = (struct bxe_softc *)context;
8695 BLOGD(sc, DBG_SP, "---> SP TASK <---\n");
8697 /* what work needs to be performed? */
8698 status = bxe_update_dsb_idx(sc);
8700 BLOGD(sc, DBG_SP, "dsb status 0x%04x\n", status);
8703 if (status & BXE_DEF_SB_ATT_IDX) {
8704 BLOGD(sc, DBG_SP, "---> ATTN INTR <---\n");
8706 status &= ~BXE_DEF_SB_ATT_IDX;
8709 /* SP events: STAT_QUERY and others */
8710 if (status & BXE_DEF_SB_IDX) {
8711 /* handle EQ completions */
8712 BLOGD(sc, DBG_SP, "---> EQ INTR <---\n");
8714 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID,
8715 le16toh(sc->def_idx), IGU_INT_NOP, 1);
8716 status &= ~BXE_DEF_SB_IDX;
8719 /* if status is non zero then something went wrong */
8720 if (__predict_false(status)) {
8721 BLOGE(sc, "Got an unknown SP interrupt! (0x%04x)\n", status);
8724 /* ack status block only if something was actually handled */
8725 bxe_ack_sb(sc, sc->igu_dsb_id, ATTENTION_ID,
8726 le16toh(sc->def_att_idx), IGU_INT_ENABLE, 1);
8729 * Must be called after the EQ processing (since eq leads to sriov
8730 * ramrod completion flows).
8731 * This flow may have been scheduled by the arrival of a ramrod
8732 * completion, or by the sriov code rescheduling itself.
8734 // XXX bxe_iov_sp_task(sc);
8739 bxe_handle_fp_tq(void *context,
8742 struct bxe_fastpath *fp = (struct bxe_fastpath *)context;
8743 struct bxe_softc *sc = fp->sc;
8744 uint8_t more_tx = FALSE;
8745 uint8_t more_rx = FALSE;
8747 BLOGD(sc, DBG_INTR, "---> FP TASK QUEUE (%d) <---\n", fp->index);
8750 * IFF_DRV_RUNNING state can't be checked here since we process
8751 * slowpath events on a client queue during setup. Instead
8752 * we need to add a "process/continue" flag here that the driver
8753 * can use to tell the task here not to do anything.
8756 if (!(sc->ifnet->if_drv_flags & IFF_DRV_RUNNING)) {
8761 /* update the fastpath index */
8762 bxe_update_fp_sb_idx(fp);
8764 /* XXX add loop here if ever support multiple tx CoS */
8765 /* fp->txdata[cos] */
8766 if (bxe_has_tx_work(fp)) {
8768 more_tx = bxe_txeof(sc, fp);
8769 BXE_FP_TX_UNLOCK(fp);
8772 if (bxe_has_rx_work(fp)) {
8773 more_rx = bxe_rxeof(sc, fp);
8776 if (more_rx /*|| more_tx*/) {
8777 /* still more work to do */
8778 taskqueue_enqueue_fast(fp->tq, &fp->tq_task);
8782 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID,
8783 le16toh(fp->fp_hc_idx), IGU_INT_ENABLE, 1);
8787 bxe_task_fp(struct bxe_fastpath *fp)
8789 struct bxe_softc *sc = fp->sc;
8790 uint8_t more_tx = FALSE;
8791 uint8_t more_rx = FALSE;
8793 BLOGD(sc, DBG_INTR, "---> FP TASK ISR (%d) <---\n", fp->index);
8795 /* update the fastpath index */
8796 bxe_update_fp_sb_idx(fp);
8798 /* XXX add loop here if ever support multiple tx CoS */
8799 /* fp->txdata[cos] */
8800 if (bxe_has_tx_work(fp)) {
8802 more_tx = bxe_txeof(sc, fp);
8803 BXE_FP_TX_UNLOCK(fp);
8806 if (bxe_has_rx_work(fp)) {
8807 more_rx = bxe_rxeof(sc, fp);
8810 if (more_rx /*|| more_tx*/) {
8811 /* still more work to do, bail out if this ISR and process later */
8812 taskqueue_enqueue_fast(fp->tq, &fp->tq_task);
8817 * Here we write the fastpath index taken before doing any tx or rx work.
8818 * It is very well possible other hw events occurred up to this point and
8819 * they were actually processed accordingly above. Since we're going to
8820 * write an older fastpath index, an interrupt is coming which we might
8821 * not do any work in.
8823 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID,
8824 le16toh(fp->fp_hc_idx), IGU_INT_ENABLE, 1);
8828 * Legacy interrupt entry point.
8830 * Verifies that the controller generated the interrupt and
8831 * then calls a separate routine to handle the various
8832 * interrupt causes: link, RX, and TX.
8835 bxe_intr_legacy(void *xsc)
8837 struct bxe_softc *sc = (struct bxe_softc *)xsc;
8838 struct bxe_fastpath *fp;
8839 uint16_t status, mask;
8842 BLOGD(sc, DBG_INTR, "---> BXE INTx <---\n");
8845 * 0 for ustorm, 1 for cstorm
8846 * the bits returned from ack_int() are 0-15
8847 * bit 0 = attention status block
8848 * bit 1 = fast path status block
8849 * a mask of 0x2 or more = tx/rx event
8850 * a mask of 1 = slow path event
8853 status = bxe_ack_int(sc);
8855 /* the interrupt is not for us */
8856 if (__predict_false(status == 0)) {
8857 BLOGD(sc, DBG_INTR, "Not our interrupt!\n");
8861 BLOGD(sc, DBG_INTR, "Interrupt status 0x%04x\n", status);
8863 FOR_EACH_ETH_QUEUE(sc, i) {
8865 mask = (0x2 << (fp->index + CNIC_SUPPORT(sc)));
8866 if (status & mask) {
8867 /* acknowledge and disable further fastpath interrupts */
8868 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
8874 if (__predict_false(status & 0x1)) {
8875 /* acknowledge and disable further slowpath interrupts */
8876 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
8878 /* schedule slowpath handler */
8879 taskqueue_enqueue_fast(sc->sp_tq, &sc->sp_tq_task);
8884 if (__predict_false(status)) {
8885 BLOGW(sc, "Unexpected fastpath status (0x%08x)!\n", status);
8889 /* slowpath interrupt entry point */
8891 bxe_intr_sp(void *xsc)
8893 struct bxe_softc *sc = (struct bxe_softc *)xsc;
8895 BLOGD(sc, (DBG_INTR | DBG_SP), "---> SP INTR <---\n");
8897 /* acknowledge and disable further slowpath interrupts */
8898 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
8900 /* schedule slowpath handler */
8901 taskqueue_enqueue_fast(sc->sp_tq, &sc->sp_tq_task);
8904 /* fastpath interrupt entry point */
8906 bxe_intr_fp(void *xfp)
8908 struct bxe_fastpath *fp = (struct bxe_fastpath *)xfp;
8909 struct bxe_softc *sc = fp->sc;
8911 BLOGD(sc, DBG_INTR, "---> FP INTR %d <---\n", fp->index);
8914 "(cpu=%d) MSI-X fp=%d fw_sb=%d igu_sb=%d\n",
8915 curcpu, fp->index, fp->fw_sb_id, fp->igu_sb_id);
8917 /* acknowledge and disable further fastpath interrupts */
8918 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
8923 /* Release all interrupts allocated by the driver. */
8925 bxe_interrupt_free(struct bxe_softc *sc)
8929 switch (sc->interrupt_mode) {
8930 case INTR_MODE_INTX:
8931 BLOGD(sc, DBG_LOAD, "Releasing legacy INTx vector\n");
8932 if (sc->intr[0].resource != NULL) {
8933 bus_release_resource(sc->dev,
8936 sc->intr[0].resource);
8940 for (i = 0; i < sc->intr_count; i++) {
8941 BLOGD(sc, DBG_LOAD, "Releasing MSI vector %d\n", i);
8942 if (sc->intr[i].resource && sc->intr[i].rid) {
8943 bus_release_resource(sc->dev,
8946 sc->intr[i].resource);
8949 pci_release_msi(sc->dev);
8951 case INTR_MODE_MSIX:
8952 for (i = 0; i < sc->intr_count; i++) {
8953 BLOGD(sc, DBG_LOAD, "Releasing MSI-X vector %d\n", i);
8954 if (sc->intr[i].resource && sc->intr[i].rid) {
8955 bus_release_resource(sc->dev,
8958 sc->intr[i].resource);
8961 pci_release_msi(sc->dev);
8964 /* nothing to do as initial allocation failed */
8970 * This function determines and allocates the appropriate
8971 * interrupt based on system capabilites and user request.
8973 * The user may force a particular interrupt mode, specify
8974 * the number of receive queues, specify the method for
8975 * distribuitng received frames to receive queues, or use
8976 * the default settings which will automatically select the
8977 * best supported combination. In addition, the OS may or
8978 * may not support certain combinations of these settings.
8979 * This routine attempts to reconcile the settings requested
8980 * by the user with the capabilites available from the system
8981 * to select the optimal combination of features.
8984 * 0 = Success, !0 = Failure.
8987 bxe_interrupt_alloc(struct bxe_softc *sc)
8991 int num_requested = 0;
8992 int num_allocated = 0;
8996 /* get the number of available MSI/MSI-X interrupts from the OS */
8997 if (sc->interrupt_mode > 0) {
8998 if (sc->devinfo.pcie_cap_flags & BXE_MSIX_CAPABLE_FLAG) {
8999 msix_count = pci_msix_count(sc->dev);
9002 if (sc->devinfo.pcie_cap_flags & BXE_MSI_CAPABLE_FLAG) {
9003 msi_count = pci_msi_count(sc->dev);
9006 BLOGD(sc, DBG_LOAD, "%d MSI and %d MSI-X vectors available\n",
9007 msi_count, msix_count);
9010 do { /* try allocating MSI-X interrupt resources (at least 2) */
9011 if (sc->interrupt_mode != INTR_MODE_MSIX) {
9015 if (((sc->devinfo.pcie_cap_flags & BXE_MSIX_CAPABLE_FLAG) == 0) ||
9017 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */
9021 /* ask for the necessary number of MSI-X vectors */
9022 num_requested = min((sc->num_queues + 1), msix_count);
9024 BLOGD(sc, DBG_LOAD, "Requesting %d MSI-X vectors\n", num_requested);
9026 num_allocated = num_requested;
9027 if ((rc = pci_alloc_msix(sc->dev, &num_allocated)) != 0) {
9028 BLOGE(sc, "MSI-X alloc failed! (%d)\n", rc);
9029 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */
9033 if (num_allocated < 2) { /* possible? */
9034 BLOGE(sc, "MSI-X allocation less than 2!\n");
9035 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */
9036 pci_release_msi(sc->dev);
9040 BLOGI(sc, "MSI-X vectors Requested %d and Allocated %d\n",
9041 num_requested, num_allocated);
9043 /* best effort so use the number of vectors allocated to us */
9044 sc->intr_count = num_allocated;
9045 sc->num_queues = num_allocated - 1;
9047 rid = 1; /* initial resource identifier */
9049 /* allocate the MSI-X vectors */
9050 for (i = 0; i < num_allocated; i++) {
9051 sc->intr[i].rid = (rid + i);
9053 if ((sc->intr[i].resource =
9054 bus_alloc_resource_any(sc->dev,
9057 RF_ACTIVE)) == NULL) {
9058 BLOGE(sc, "Failed to map MSI-X[%d] (rid=%d)!\n",
9061 for (j = (i - 1); j >= 0; j--) {
9062 bus_release_resource(sc->dev,
9065 sc->intr[j].resource);
9070 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */
9071 pci_release_msi(sc->dev);
9075 BLOGD(sc, DBG_LOAD, "Mapped MSI-X[%d] (rid=%d)\n", i, (rid + i));
9079 do { /* try allocating MSI vector resources (at least 2) */
9080 if (sc->interrupt_mode != INTR_MODE_MSI) {
9084 if (((sc->devinfo.pcie_cap_flags & BXE_MSI_CAPABLE_FLAG) == 0) ||
9086 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */
9090 /* ask for a single MSI vector */
9093 BLOGD(sc, DBG_LOAD, "Requesting %d MSI vectors\n", num_requested);
9095 num_allocated = num_requested;
9096 if ((rc = pci_alloc_msi(sc->dev, &num_allocated)) != 0) {
9097 BLOGE(sc, "MSI alloc failed (%d)!\n", rc);
9098 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */
9102 if (num_allocated != 1) { /* possible? */
9103 BLOGE(sc, "MSI allocation is not 1!\n");
9104 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */
9105 pci_release_msi(sc->dev);
9109 BLOGI(sc, "MSI vectors Requested %d and Allocated %d\n",
9110 num_requested, num_allocated);
9112 /* best effort so use the number of vectors allocated to us */
9113 sc->intr_count = num_allocated;
9114 sc->num_queues = num_allocated;
9116 rid = 1; /* initial resource identifier */
9118 sc->intr[0].rid = rid;
9120 if ((sc->intr[0].resource =
9121 bus_alloc_resource_any(sc->dev,
9124 RF_ACTIVE)) == NULL) {
9125 BLOGE(sc, "Failed to map MSI[0] (rid=%d)!\n", rid);
9128 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */
9129 pci_release_msi(sc->dev);
9133 BLOGD(sc, DBG_LOAD, "Mapped MSI[0] (rid=%d)\n", rid);
9136 do { /* try allocating INTx vector resources */
9137 if (sc->interrupt_mode != INTR_MODE_INTX) {
9141 BLOGD(sc, DBG_LOAD, "Requesting legacy INTx interrupt\n");
9143 /* only one vector for INTx */
9147 rid = 0; /* initial resource identifier */
9149 sc->intr[0].rid = rid;
9151 if ((sc->intr[0].resource =
9152 bus_alloc_resource_any(sc->dev,
9155 (RF_ACTIVE | RF_SHAREABLE))) == NULL) {
9156 BLOGE(sc, "Failed to map INTx (rid=%d)!\n", rid);
9159 sc->interrupt_mode = -1; /* Failed! */
9163 BLOGD(sc, DBG_LOAD, "Mapped INTx (rid=%d)\n", rid);
9166 if (sc->interrupt_mode == -1) {
9167 BLOGE(sc, "Interrupt Allocation: FAILED!!!\n");
9171 "Interrupt Allocation: interrupt_mode=%d, num_queues=%d\n",
9172 sc->interrupt_mode, sc->num_queues);
9180 bxe_interrupt_detach(struct bxe_softc *sc)
9182 struct bxe_fastpath *fp;
9185 /* release interrupt resources */
9186 for (i = 0; i < sc->intr_count; i++) {
9187 if (sc->intr[i].resource && sc->intr[i].tag) {
9188 BLOGD(sc, DBG_LOAD, "Disabling interrupt vector %d\n", i);
9189 bus_teardown_intr(sc->dev, sc->intr[i].resource, sc->intr[i].tag);
9193 for (i = 0; i < sc->num_queues; i++) {
9196 taskqueue_drain(fp->tq, &fp->tq_task);
9197 taskqueue_drain(fp->tq, &fp->tx_task);
9198 while (taskqueue_cancel_timeout(fp->tq, &fp->tx_timeout_task,
9200 taskqueue_drain_timeout(fp->tq, &fp->tx_timeout_task);
9203 for (i = 0; i < sc->num_queues; i++) {
9205 if (fp->tq != NULL) {
9206 taskqueue_free(fp->tq);
9213 taskqueue_drain(sc->sp_tq, &sc->sp_tq_task);
9214 taskqueue_free(sc->sp_tq);
9220 * Enables interrupts and attach to the ISR.
9222 * When using multiple MSI/MSI-X vectors the first vector
9223 * is used for slowpath operations while all remaining
9224 * vectors are used for fastpath operations. If only a
9225 * single MSI/MSI-X vector is used (SINGLE_ISR) then the
9226 * ISR must look for both slowpath and fastpath completions.
9229 bxe_interrupt_attach(struct bxe_softc *sc)
9231 struct bxe_fastpath *fp;
9235 snprintf(sc->sp_tq_name, sizeof(sc->sp_tq_name),
9236 "bxe%d_sp_tq", sc->unit);
9237 TASK_INIT(&sc->sp_tq_task, 0, bxe_handle_sp_tq, sc);
9238 sc->sp_tq = taskqueue_create(sc->sp_tq_name, M_NOWAIT,
9239 taskqueue_thread_enqueue,
9241 taskqueue_start_threads(&sc->sp_tq, 1, PWAIT, /* lower priority */
9242 "%s", sc->sp_tq_name);
9245 for (i = 0; i < sc->num_queues; i++) {
9247 snprintf(fp->tq_name, sizeof(fp->tq_name),
9248 "bxe%d_fp%d_tq", sc->unit, i);
9249 TASK_INIT(&fp->tq_task, 0, bxe_handle_fp_tq, fp);
9250 TASK_INIT(&fp->tx_task, 0, bxe_tx_mq_start_deferred, fp);
9251 fp->tq = taskqueue_create(fp->tq_name, M_NOWAIT,
9252 taskqueue_thread_enqueue,
9254 TIMEOUT_TASK_INIT(fp->tq, &fp->tx_timeout_task, 0,
9255 bxe_tx_mq_start_deferred, fp);
9256 taskqueue_start_threads(&fp->tq, 1, PI_NET, /* higher priority */
9260 /* setup interrupt handlers */
9261 if (sc->interrupt_mode == INTR_MODE_MSIX) {
9262 BLOGD(sc, DBG_LOAD, "Enabling slowpath MSI-X[0] vector\n");
9265 * Setup the interrupt handler. Note that we pass the driver instance
9266 * to the interrupt handler for the slowpath.
9268 if ((rc = bus_setup_intr(sc->dev, sc->intr[0].resource,
9269 (INTR_TYPE_NET | INTR_MPSAFE),
9270 NULL, bxe_intr_sp, sc,
9271 &sc->intr[0].tag)) != 0) {
9272 BLOGE(sc, "Failed to allocate MSI-X[0] vector (%d)\n", rc);
9273 goto bxe_interrupt_attach_exit;
9276 bus_describe_intr(sc->dev, sc->intr[0].resource,
9277 sc->intr[0].tag, "sp");
9279 /* bus_bind_intr(sc->dev, sc->intr[0].resource, 0); */
9281 /* initialize the fastpath vectors (note the first was used for sp) */
9282 for (i = 0; i < sc->num_queues; i++) {
9284 BLOGD(sc, DBG_LOAD, "Enabling MSI-X[%d] vector\n", (i + 1));
9287 * Setup the interrupt handler. Note that we pass the
9288 * fastpath context to the interrupt handler in this
9291 if ((rc = bus_setup_intr(sc->dev, sc->intr[i + 1].resource,
9292 (INTR_TYPE_NET | INTR_MPSAFE),
9293 NULL, bxe_intr_fp, fp,
9294 &sc->intr[i + 1].tag)) != 0) {
9295 BLOGE(sc, "Failed to allocate MSI-X[%d] vector (%d)\n",
9297 goto bxe_interrupt_attach_exit;
9300 bus_describe_intr(sc->dev, sc->intr[i + 1].resource,
9301 sc->intr[i + 1].tag, "fp%02d", i);
9303 /* bind the fastpath instance to a cpu */
9304 if (sc->num_queues > 1) {
9305 bus_bind_intr(sc->dev, sc->intr[i + 1].resource, i);
9308 fp->state = BXE_FP_STATE_IRQ;
9310 } else if (sc->interrupt_mode == INTR_MODE_MSI) {
9311 BLOGD(sc, DBG_LOAD, "Enabling MSI[0] vector\n");
9314 * Setup the interrupt handler. Note that we pass the
9315 * driver instance to the interrupt handler which
9316 * will handle both the slowpath and fastpath.
9318 if ((rc = bus_setup_intr(sc->dev, sc->intr[0].resource,
9319 (INTR_TYPE_NET | INTR_MPSAFE),
9320 NULL, bxe_intr_legacy, sc,
9321 &sc->intr[0].tag)) != 0) {
9322 BLOGE(sc, "Failed to allocate MSI[0] vector (%d)\n", rc);
9323 goto bxe_interrupt_attach_exit;
9326 } else { /* (sc->interrupt_mode == INTR_MODE_INTX) */
9327 BLOGD(sc, DBG_LOAD, "Enabling INTx interrupts\n");
9330 * Setup the interrupt handler. Note that we pass the
9331 * driver instance to the interrupt handler which
9332 * will handle both the slowpath and fastpath.
9334 if ((rc = bus_setup_intr(sc->dev, sc->intr[0].resource,
9335 (INTR_TYPE_NET | INTR_MPSAFE),
9336 NULL, bxe_intr_legacy, sc,
9337 &sc->intr[0].tag)) != 0) {
9338 BLOGE(sc, "Failed to allocate INTx interrupt (%d)\n", rc);
9339 goto bxe_interrupt_attach_exit;
9343 bxe_interrupt_attach_exit:
9348 static int bxe_init_hw_common_chip(struct bxe_softc *sc);
9349 static int bxe_init_hw_common(struct bxe_softc *sc);
9350 static int bxe_init_hw_port(struct bxe_softc *sc);
9351 static int bxe_init_hw_func(struct bxe_softc *sc);
9352 static void bxe_reset_common(struct bxe_softc *sc);
9353 static void bxe_reset_port(struct bxe_softc *sc);
9354 static void bxe_reset_func(struct bxe_softc *sc);
9355 static int bxe_gunzip_init(struct bxe_softc *sc);
9356 static void bxe_gunzip_end(struct bxe_softc *sc);
9357 static int bxe_init_firmware(struct bxe_softc *sc);
9358 static void bxe_release_firmware(struct bxe_softc *sc);
9361 ecore_func_sp_drv_ops bxe_func_sp_drv = {
9362 .init_hw_cmn_chip = bxe_init_hw_common_chip,
9363 .init_hw_cmn = bxe_init_hw_common,
9364 .init_hw_port = bxe_init_hw_port,
9365 .init_hw_func = bxe_init_hw_func,
9367 .reset_hw_cmn = bxe_reset_common,
9368 .reset_hw_port = bxe_reset_port,
9369 .reset_hw_func = bxe_reset_func,
9371 .gunzip_init = bxe_gunzip_init,
9372 .gunzip_end = bxe_gunzip_end,
9374 .init_fw = bxe_init_firmware,
9375 .release_fw = bxe_release_firmware,
9379 bxe_init_func_obj(struct bxe_softc *sc)
9383 ecore_init_func_obj(sc,
9385 BXE_SP(sc, func_rdata),
9386 BXE_SP_MAPPING(sc, func_rdata),
9387 BXE_SP(sc, func_afex_rdata),
9388 BXE_SP_MAPPING(sc, func_afex_rdata),
9393 bxe_init_hw(struct bxe_softc *sc,
9396 struct ecore_func_state_params func_params = { NULL };
9399 /* prepare the parameters for function state transitions */
9400 bit_set(&func_params.ramrod_flags, RAMROD_COMP_WAIT);
9402 func_params.f_obj = &sc->func_obj;
9403 func_params.cmd = ECORE_F_CMD_HW_INIT;
9405 func_params.params.hw_init.load_phase = load_code;
9408 * Via a plethora of function pointers, we will eventually reach
9409 * bxe_init_hw_common(), bxe_init_hw_port(), or bxe_init_hw_func().
9411 rc = ecore_func_state_change(sc, &func_params);
9417 bxe_fill(struct bxe_softc *sc,
9424 if (!(len % 4) && !(addr % 4)) {
9425 for (i = 0; i < len; i += 4) {
9426 REG_WR(sc, (addr + i), fill);
9429 for (i = 0; i < len; i++) {
9430 REG_WR8(sc, (addr + i), fill);
9435 /* writes FP SP data to FW - data_size in dwords */
9437 bxe_wr_fp_sb_data(struct bxe_softc *sc,
9439 uint32_t *sb_data_p,
9444 for (index = 0; index < data_size; index++) {
9446 (BAR_CSTRORM_INTMEM +
9447 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
9448 (sizeof(uint32_t) * index)),
9449 *(sb_data_p + index));
9454 bxe_zero_fp_sb(struct bxe_softc *sc,
9457 struct hc_status_block_data_e2 sb_data_e2;
9458 struct hc_status_block_data_e1x sb_data_e1x;
9459 uint32_t *sb_data_p;
9460 uint32_t data_size = 0;
9462 if (!CHIP_IS_E1x(sc)) {
9463 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
9464 sb_data_e2.common.state = SB_DISABLED;
9465 sb_data_e2.common.p_func.vf_valid = FALSE;
9466 sb_data_p = (uint32_t *)&sb_data_e2;
9467 data_size = (sizeof(struct hc_status_block_data_e2) /
9470 memset(&sb_data_e1x, 0, sizeof(struct hc_status_block_data_e1x));
9471 sb_data_e1x.common.state = SB_DISABLED;
9472 sb_data_e1x.common.p_func.vf_valid = FALSE;
9473 sb_data_p = (uint32_t *)&sb_data_e1x;
9474 data_size = (sizeof(struct hc_status_block_data_e1x) /
9478 bxe_wr_fp_sb_data(sc, fw_sb_id, sb_data_p, data_size);
9480 bxe_fill(sc, (BAR_CSTRORM_INTMEM + CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id)),
9481 0, CSTORM_STATUS_BLOCK_SIZE);
9482 bxe_fill(sc, (BAR_CSTRORM_INTMEM + CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id)),
9483 0, CSTORM_SYNC_BLOCK_SIZE);
9487 bxe_wr_sp_sb_data(struct bxe_softc *sc,
9488 struct hc_sp_status_block_data *sp_sb_data)
9493 i < (sizeof(struct hc_sp_status_block_data) / sizeof(uint32_t));
9496 (BAR_CSTRORM_INTMEM +
9497 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(SC_FUNC(sc)) +
9498 (i * sizeof(uint32_t))),
9499 *((uint32_t *)sp_sb_data + i));
9504 bxe_zero_sp_sb(struct bxe_softc *sc)
9506 struct hc_sp_status_block_data sp_sb_data;
9508 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
9510 sp_sb_data.state = SB_DISABLED;
9511 sp_sb_data.p_func.vf_valid = FALSE;
9513 bxe_wr_sp_sb_data(sc, &sp_sb_data);
9516 (BAR_CSTRORM_INTMEM +
9517 CSTORM_SP_STATUS_BLOCK_OFFSET(SC_FUNC(sc))),
9518 0, CSTORM_SP_STATUS_BLOCK_SIZE);
9520 (BAR_CSTRORM_INTMEM +
9521 CSTORM_SP_SYNC_BLOCK_OFFSET(SC_FUNC(sc))),
9522 0, CSTORM_SP_SYNC_BLOCK_SIZE);
9526 bxe_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
9530 hc_sm->igu_sb_id = igu_sb_id;
9531 hc_sm->igu_seg_id = igu_seg_id;
9532 hc_sm->timer_value = 0xFF;
9533 hc_sm->time_to_expire = 0xFFFFFFFF;
9537 bxe_map_sb_state_machines(struct hc_index_data *index_data)
9539 /* zero out state machine indices */
9542 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
9545 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
9546 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
9547 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
9548 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
9553 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
9554 (SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9557 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
9558 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9559 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
9560 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9561 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
9562 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9563 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
9564 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9568 bxe_init_sb(struct bxe_softc *sc,
9575 struct hc_status_block_data_e2 sb_data_e2;
9576 struct hc_status_block_data_e1x sb_data_e1x;
9577 struct hc_status_block_sm *hc_sm_p;
9578 uint32_t *sb_data_p;
9582 if (CHIP_INT_MODE_IS_BC(sc)) {
9583 igu_seg_id = HC_SEG_ACCESS_NORM;
9585 igu_seg_id = IGU_SEG_ACCESS_NORM;
9588 bxe_zero_fp_sb(sc, fw_sb_id);
9590 if (!CHIP_IS_E1x(sc)) {
9591 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
9592 sb_data_e2.common.state = SB_ENABLED;
9593 sb_data_e2.common.p_func.pf_id = SC_FUNC(sc);
9594 sb_data_e2.common.p_func.vf_id = vfid;
9595 sb_data_e2.common.p_func.vf_valid = vf_valid;
9596 sb_data_e2.common.p_func.vnic_id = SC_VN(sc);
9597 sb_data_e2.common.same_igu_sb_1b = TRUE;
9598 sb_data_e2.common.host_sb_addr.hi = U64_HI(busaddr);
9599 sb_data_e2.common.host_sb_addr.lo = U64_LO(busaddr);
9600 hc_sm_p = sb_data_e2.common.state_machine;
9601 sb_data_p = (uint32_t *)&sb_data_e2;
9602 data_size = (sizeof(struct hc_status_block_data_e2) /
9604 bxe_map_sb_state_machines(sb_data_e2.index_data);
9606 memset(&sb_data_e1x, 0, sizeof(struct hc_status_block_data_e1x));
9607 sb_data_e1x.common.state = SB_ENABLED;
9608 sb_data_e1x.common.p_func.pf_id = SC_FUNC(sc);
9609 sb_data_e1x.common.p_func.vf_id = 0xff;
9610 sb_data_e1x.common.p_func.vf_valid = FALSE;
9611 sb_data_e1x.common.p_func.vnic_id = SC_VN(sc);
9612 sb_data_e1x.common.same_igu_sb_1b = TRUE;
9613 sb_data_e1x.common.host_sb_addr.hi = U64_HI(busaddr);
9614 sb_data_e1x.common.host_sb_addr.lo = U64_LO(busaddr);
9615 hc_sm_p = sb_data_e1x.common.state_machine;
9616 sb_data_p = (uint32_t *)&sb_data_e1x;
9617 data_size = (sizeof(struct hc_status_block_data_e1x) /
9619 bxe_map_sb_state_machines(sb_data_e1x.index_data);
9622 bxe_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID], igu_sb_id, igu_seg_id);
9623 bxe_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID], igu_sb_id, igu_seg_id);
9625 BLOGD(sc, DBG_LOAD, "Init FW SB %d\n", fw_sb_id);
9627 /* write indices to HW - PCI guarantees endianity of regpairs */
9628 bxe_wr_fp_sb_data(sc, fw_sb_id, sb_data_p, data_size);
9631 static inline uint8_t
9632 bxe_fp_qzone_id(struct bxe_fastpath *fp)
9634 if (CHIP_IS_E1x(fp->sc)) {
9635 return (fp->cl_id + SC_PORT(fp->sc) * ETH_MAX_RX_CLIENTS_E1H);
9641 static inline uint32_t
9642 bxe_rx_ustorm_prods_offset(struct bxe_softc *sc,
9643 struct bxe_fastpath *fp)
9645 uint32_t offset = BAR_USTRORM_INTMEM;
9647 if (!CHIP_IS_E1x(sc)) {
9648 offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
9650 offset += USTORM_RX_PRODS_E1X_OFFSET(SC_PORT(sc), fp->cl_id);
9657 bxe_init_eth_fp(struct bxe_softc *sc,
9660 struct bxe_fastpath *fp = &sc->fp[idx];
9661 uint32_t cids[ECORE_MULTI_TX_COS] = { 0 };
9662 unsigned long q_type = 0;
9668 fp->igu_sb_id = (sc->igu_base_sb + idx + CNIC_SUPPORT(sc));
9669 fp->fw_sb_id = (sc->base_fw_ndsb + idx + CNIC_SUPPORT(sc));
9671 fp->cl_id = (CHIP_IS_E1x(sc)) ?
9672 (SC_L_ID(sc) + idx) :
9673 /* want client ID same as IGU SB ID for non-E1 */
9675 fp->cl_qzone_id = bxe_fp_qzone_id(fp);
9677 /* setup sb indices */
9678 if (!CHIP_IS_E1x(sc)) {
9679 fp->sb_index_values = fp->status_block.e2_sb->sb.index_values;
9680 fp->sb_running_index = fp->status_block.e2_sb->sb.running_index;
9682 fp->sb_index_values = fp->status_block.e1x_sb->sb.index_values;
9683 fp->sb_running_index = fp->status_block.e1x_sb->sb.running_index;
9687 fp->ustorm_rx_prods_offset = bxe_rx_ustorm_prods_offset(sc, fp);
9689 fp->rx_cq_cons_sb = &fp->sb_index_values[HC_INDEX_ETH_RX_CQ_CONS];
9692 * XXX If multiple CoS is ever supported then each fastpath structure
9693 * will need to maintain tx producer/consumer/dma/etc values *per* CoS.
9695 for (cos = 0; cos < sc->max_cos; cos++) {
9698 fp->tx_cons_sb = &fp->sb_index_values[HC_INDEX_ETH_TX_CQ_CONS_COS0];
9700 /* nothing more for a VF to do */
9705 bxe_init_sb(sc, fp->sb_dma.paddr, BXE_VF_ID_INVALID, FALSE,
9706 fp->fw_sb_id, fp->igu_sb_id);
9708 bxe_update_fp_sb_idx(fp);
9710 /* Configure Queue State object */
9711 bit_set(&q_type, ECORE_Q_TYPE_HAS_RX);
9712 bit_set(&q_type, ECORE_Q_TYPE_HAS_TX);
9714 ecore_init_queue_obj(sc,
9715 &sc->sp_objs[idx].q_obj,
9720 BXE_SP(sc, q_rdata),
9721 BXE_SP_MAPPING(sc, q_rdata),
9724 /* configure classification DBs */
9725 ecore_init_mac_obj(sc,
9726 &sc->sp_objs[idx].mac_obj,
9730 BXE_SP(sc, mac_rdata),
9731 BXE_SP_MAPPING(sc, mac_rdata),
9732 ECORE_FILTER_MAC_PENDING,
9734 ECORE_OBJ_TYPE_RX_TX,
9737 BLOGD(sc, DBG_LOAD, "fp[%d]: sb=%p cl_id=%d fw_sb=%d igu_sb=%d\n",
9738 idx, fp->status_block.e2_sb, fp->cl_id, fp->fw_sb_id, fp->igu_sb_id);
9742 bxe_update_rx_prod(struct bxe_softc *sc,
9743 struct bxe_fastpath *fp,
9744 uint16_t rx_bd_prod,
9745 uint16_t rx_cq_prod,
9746 uint16_t rx_sge_prod)
9748 struct ustorm_eth_rx_producers rx_prods = { 0 };
9751 /* update producers */
9752 rx_prods.bd_prod = rx_bd_prod;
9753 rx_prods.cqe_prod = rx_cq_prod;
9754 rx_prods.sge_prod = rx_sge_prod;
9757 * Make sure that the BD and SGE data is updated before updating the
9758 * producers since FW might read the BD/SGE right after the producer
9760 * This is only applicable for weak-ordered memory model archs such
9761 * as IA-64. The following barrier is also mandatory since FW will
9762 * assumes BDs must have buffers.
9766 for (i = 0; i < (sizeof(rx_prods) / 4); i++) {
9768 (fp->ustorm_rx_prods_offset + (i * 4)),
9769 ((uint32_t *)&rx_prods)[i]);
9772 wmb(); /* keep prod updates ordered */
9775 "RX fp[%d]: wrote prods bd_prod=%u cqe_prod=%u sge_prod=%u\n",
9776 fp->index, rx_bd_prod, rx_cq_prod, rx_sge_prod);
9780 bxe_init_rx_rings(struct bxe_softc *sc)
9782 struct bxe_fastpath *fp;
9785 for (i = 0; i < sc->num_queues; i++) {
9791 * Activate the BD ring...
9792 * Warning, this will generate an interrupt (to the TSTORM)
9793 * so this can only be done after the chip is initialized
9795 bxe_update_rx_prod(sc, fp,
9804 if (CHIP_IS_E1(sc)) {
9806 (BAR_USTRORM_INTMEM +
9807 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(SC_FUNC(sc))),
9808 U64_LO(fp->rcq_dma.paddr));
9810 (BAR_USTRORM_INTMEM +
9811 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(SC_FUNC(sc)) + 4),
9812 U64_HI(fp->rcq_dma.paddr));
9818 bxe_init_tx_ring_one(struct bxe_fastpath *fp)
9820 SET_FLAG(fp->tx_db.data.header.data, DOORBELL_HDR_T_DB_TYPE, 1);
9821 fp->tx_db.data.zero_fill1 = 0;
9822 fp->tx_db.data.prod = 0;
9824 fp->tx_pkt_prod = 0;
9825 fp->tx_pkt_cons = 0;
9828 fp->eth_q_stats.tx_pkts = 0;
9832 bxe_init_tx_rings(struct bxe_softc *sc)
9836 for (i = 0; i < sc->num_queues; i++) {
9837 bxe_init_tx_ring_one(&sc->fp[i]);
9842 bxe_init_def_sb(struct bxe_softc *sc)
9844 struct host_sp_status_block *def_sb = sc->def_sb;
9845 bus_addr_t mapping = sc->def_sb_dma.paddr;
9846 int igu_sp_sb_index;
9848 int port = SC_PORT(sc);
9849 int func = SC_FUNC(sc);
9850 int reg_offset, reg_offset_en5;
9853 struct hc_sp_status_block_data sp_sb_data;
9855 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
9857 if (CHIP_INT_MODE_IS_BC(sc)) {
9858 igu_sp_sb_index = DEF_SB_IGU_ID;
9859 igu_seg_id = HC_SEG_ACCESS_DEF;
9861 igu_sp_sb_index = sc->igu_dsb_id;
9862 igu_seg_id = IGU_SEG_ACCESS_DEF;
9866 section = ((uint64_t)mapping +
9867 offsetof(struct host_sp_status_block, atten_status_block));
9868 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
9871 reg_offset = (port) ?
9872 MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
9873 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
9874 reg_offset_en5 = (port) ?
9875 MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
9876 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0;
9878 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
9879 /* take care of sig[0]..sig[4] */
9880 for (sindex = 0; sindex < 4; sindex++) {
9881 sc->attn_group[index].sig[sindex] =
9882 REG_RD(sc, (reg_offset + (sindex * 0x4) + (0x10 * index)));
9885 if (!CHIP_IS_E1x(sc)) {
9887 * enable5 is separate from the rest of the registers,
9888 * and the address skip is 4 and not 16 between the
9891 sc->attn_group[index].sig[4] =
9892 REG_RD(sc, (reg_offset_en5 + (0x4 * index)));
9894 sc->attn_group[index].sig[4] = 0;
9898 if (sc->devinfo.int_block == INT_BLOCK_HC) {
9899 reg_offset = (port) ?
9900 HC_REG_ATTN_MSG1_ADDR_L :
9901 HC_REG_ATTN_MSG0_ADDR_L;
9902 REG_WR(sc, reg_offset, U64_LO(section));
9903 REG_WR(sc, (reg_offset + 4), U64_HI(section));
9904 } else if (!CHIP_IS_E1x(sc)) {
9905 REG_WR(sc, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
9906 REG_WR(sc, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
9909 section = ((uint64_t)mapping +
9910 offsetof(struct host_sp_status_block, sp_sb));
9914 /* PCI guarantees endianity of regpair */
9915 sp_sb_data.state = SB_ENABLED;
9916 sp_sb_data.host_sb_addr.lo = U64_LO(section);
9917 sp_sb_data.host_sb_addr.hi = U64_HI(section);
9918 sp_sb_data.igu_sb_id = igu_sp_sb_index;
9919 sp_sb_data.igu_seg_id = igu_seg_id;
9920 sp_sb_data.p_func.pf_id = func;
9921 sp_sb_data.p_func.vnic_id = SC_VN(sc);
9922 sp_sb_data.p_func.vf_id = 0xff;
9924 bxe_wr_sp_sb_data(sc, &sp_sb_data);
9926 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
9930 bxe_init_sp_ring(struct bxe_softc *sc)
9932 atomic_store_rel_long(&sc->cq_spq_left, MAX_SPQ_PENDING);
9933 sc->spq_prod_idx = 0;
9934 sc->dsb_sp_prod = &sc->def_sb->sp_sb.index_values[HC_SP_INDEX_ETH_DEF_CONS];
9935 sc->spq_prod_bd = sc->spq;
9936 sc->spq_last_bd = (sc->spq_prod_bd + MAX_SP_DESC_CNT);
9940 bxe_init_eq_ring(struct bxe_softc *sc)
9942 union event_ring_elem *elem;
9945 for (i = 1; i <= NUM_EQ_PAGES; i++) {
9946 elem = &sc->eq[EQ_DESC_CNT_PAGE * i - 1];
9948 elem->next_page.addr.hi = htole32(U64_HI(sc->eq_dma.paddr +
9950 (i % NUM_EQ_PAGES)));
9951 elem->next_page.addr.lo = htole32(U64_LO(sc->eq_dma.paddr +
9953 (i % NUM_EQ_PAGES)));
9957 sc->eq_prod = NUM_EQ_DESC;
9958 sc->eq_cons_sb = &sc->def_sb->sp_sb.index_values[HC_SP_INDEX_EQ_CONS];
9960 atomic_store_rel_long(&sc->eq_spq_left,
9961 (min((MAX_SP_DESC_CNT - MAX_SPQ_PENDING),
9966 bxe_init_internal_common(struct bxe_softc *sc)
9971 * Zero this manually as its initialization is currently missing
9974 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++) {
9976 (BAR_USTRORM_INTMEM + USTORM_AGG_DATA_OFFSET + (i * 4)),
9980 if (!CHIP_IS_E1x(sc)) {
9981 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET),
9982 CHIP_INT_MODE_IS_BC(sc) ? HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
9987 bxe_init_internal(struct bxe_softc *sc,
9990 switch (load_code) {
9991 case FW_MSG_CODE_DRV_LOAD_COMMON:
9992 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
9993 bxe_init_internal_common(sc);
9996 case FW_MSG_CODE_DRV_LOAD_PORT:
10000 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
10001 /* internal memory per function is initialized inside bxe_pf_init */
10005 BLOGE(sc, "Unknown load_code (0x%x) from MCP\n", load_code);
10011 storm_memset_func_cfg(struct bxe_softc *sc,
10012 struct tstorm_eth_function_common_config *tcfg,
10018 addr = (BAR_TSTRORM_INTMEM +
10019 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid));
10020 size = sizeof(struct tstorm_eth_function_common_config);
10021 ecore_storm_memset_struct(sc, addr, size, (uint32_t *)tcfg);
10025 bxe_func_init(struct bxe_softc *sc,
10026 struct bxe_func_init_params *p)
10028 struct tstorm_eth_function_common_config tcfg = { 0 };
10030 if (CHIP_IS_E1x(sc)) {
10031 storm_memset_func_cfg(sc, &tcfg, p->func_id);
10034 /* Enable the function in the FW */
10035 storm_memset_vf_to_pf(sc, p->func_id, p->pf_id);
10036 storm_memset_func_en(sc, p->func_id, 1);
10039 if (p->func_flgs & FUNC_FLG_SPQ) {
10040 storm_memset_spq_addr(sc, p->spq_map, p->func_id);
10042 (XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PROD_OFFSET(p->func_id)),
10048 * Calculates the sum of vn_min_rates.
10049 * It's needed for further normalizing of the min_rates.
10051 * sum of vn_min_rates.
10053 * 0 - if all the min_rates are 0.
10054 * In the later case fainess algorithm should be deactivated.
10055 * If all min rates are not zero then those that are zeroes will be set to 1.
10058 bxe_calc_vn_min(struct bxe_softc *sc,
10059 struct cmng_init_input *input)
10062 uint32_t vn_min_rate;
10066 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
10067 vn_cfg = sc->devinfo.mf_info.mf_config[vn];
10068 vn_min_rate = (((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
10069 FUNC_MF_CFG_MIN_BW_SHIFT) * 100);
10071 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
10072 /* skip hidden VNs */
10074 } else if (!vn_min_rate) {
10075 /* If min rate is zero - set it to 100 */
10076 vn_min_rate = DEF_MIN_RATE;
10081 input->vnic_min_rate[vn] = vn_min_rate;
10084 /* if ETS or all min rates are zeros - disable fairness */
10085 if (BXE_IS_ETS_ENABLED(sc)) {
10086 input->flags.cmng_enables &= ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
10087 BLOGD(sc, DBG_LOAD, "Fairness disabled (ETS)\n");
10088 } else if (all_zero) {
10089 input->flags.cmng_enables &= ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
10090 BLOGD(sc, DBG_LOAD,
10091 "Fariness disabled (all MIN values are zeroes)\n");
10093 input->flags.cmng_enables |= CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
10097 static inline uint16_t
10098 bxe_extract_max_cfg(struct bxe_softc *sc,
10101 uint16_t max_cfg = ((mf_cfg & FUNC_MF_CFG_MAX_BW_MASK) >>
10102 FUNC_MF_CFG_MAX_BW_SHIFT);
10105 BLOGD(sc, DBG_LOAD, "Max BW configured to 0 - using 100 instead\n");
10113 bxe_calc_vn_max(struct bxe_softc *sc,
10115 struct cmng_init_input *input)
10117 uint16_t vn_max_rate;
10118 uint32_t vn_cfg = sc->devinfo.mf_info.mf_config[vn];
10121 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
10124 max_cfg = bxe_extract_max_cfg(sc, vn_cfg);
10126 if (IS_MF_SI(sc)) {
10127 /* max_cfg in percents of linkspeed */
10128 vn_max_rate = ((sc->link_vars.line_speed * max_cfg) / 100);
10129 } else { /* SD modes */
10130 /* max_cfg is absolute in 100Mb units */
10131 vn_max_rate = (max_cfg * 100);
10135 BLOGD(sc, DBG_LOAD, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
10137 input->vnic_max_rate[vn] = vn_max_rate;
10141 bxe_cmng_fns_init(struct bxe_softc *sc,
10145 struct cmng_init_input input;
10148 memset(&input, 0, sizeof(struct cmng_init_input));
10150 input.port_rate = sc->link_vars.line_speed;
10152 if (cmng_type == CMNG_FNS_MINMAX) {
10153 /* read mf conf from shmem */
10155 bxe_read_mf_cfg(sc);
10158 /* get VN min rate and enable fairness if not 0 */
10159 bxe_calc_vn_min(sc, &input);
10161 /* get VN max rate */
10162 if (sc->port.pmf) {
10163 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
10164 bxe_calc_vn_max(sc, vn, &input);
10168 /* always enable rate shaping and fairness */
10169 input.flags.cmng_enables |= CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
10171 ecore_init_cmng(&input, &sc->cmng);
10175 /* rate shaping and fairness are disabled */
10176 BLOGD(sc, DBG_LOAD, "rate shaping and fairness have been disabled\n");
10180 bxe_get_cmng_fns_mode(struct bxe_softc *sc)
10182 if (CHIP_REV_IS_SLOW(sc)) {
10183 return (CMNG_FNS_NONE);
10187 return (CMNG_FNS_MINMAX);
10190 return (CMNG_FNS_NONE);
10194 storm_memset_cmng(struct bxe_softc *sc,
10195 struct cmng_init *cmng,
10203 addr = (BAR_XSTRORM_INTMEM +
10204 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port));
10205 size = sizeof(struct cmng_struct_per_port);
10206 ecore_storm_memset_struct(sc, addr, size, (uint32_t *)&cmng->port);
10208 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
10209 func = func_by_vn(sc, vn);
10211 addr = (BAR_XSTRORM_INTMEM +
10212 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func));
10213 size = sizeof(struct rate_shaping_vars_per_vn);
10214 ecore_storm_memset_struct(sc, addr, size,
10215 (uint32_t *)&cmng->vnic.vnic_max_rate[vn]);
10217 addr = (BAR_XSTRORM_INTMEM +
10218 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func));
10219 size = sizeof(struct fairness_vars_per_vn);
10220 ecore_storm_memset_struct(sc, addr, size,
10221 (uint32_t *)&cmng->vnic.vnic_min_rate[vn]);
10226 bxe_pf_init(struct bxe_softc *sc)
10228 struct bxe_func_init_params func_init = { 0 };
10229 struct event_ring_data eq_data = { { 0 } };
10232 if (!CHIP_IS_E1x(sc)) {
10233 /* reset IGU PF statistics: MSIX + ATTN */
10236 (IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
10237 (BXE_IGU_STAS_MSG_VF_CNT * 4) +
10238 ((CHIP_IS_MODE_4_PORT(sc) ? SC_FUNC(sc) : SC_VN(sc)) * 4)),
10242 (IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
10243 (BXE_IGU_STAS_MSG_VF_CNT * 4) +
10244 (BXE_IGU_STAS_MSG_PF_CNT * 4) +
10245 ((CHIP_IS_MODE_4_PORT(sc) ? SC_FUNC(sc) : SC_VN(sc)) * 4)),
10249 /* function setup flags */
10250 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
10253 * This flag is relevant for E1x only.
10254 * E2 doesn't have a TPA configuration in a function level.
10256 flags |= (sc->ifnet->if_capenable & IFCAP_LRO) ? FUNC_FLG_TPA : 0;
10258 func_init.func_flgs = flags;
10259 func_init.pf_id = SC_FUNC(sc);
10260 func_init.func_id = SC_FUNC(sc);
10261 func_init.spq_map = sc->spq_dma.paddr;
10262 func_init.spq_prod = sc->spq_prod_idx;
10264 bxe_func_init(sc, &func_init);
10266 memset(&sc->cmng, 0, sizeof(struct cmng_struct_per_port));
10269 * Congestion management values depend on the link rate.
10270 * There is no active link so initial link rate is set to 10Gbps.
10271 * When the link comes up the congestion management values are
10272 * re-calculated according to the actual link rate.
10274 sc->link_vars.line_speed = SPEED_10000;
10275 bxe_cmng_fns_init(sc, TRUE, bxe_get_cmng_fns_mode(sc));
10277 /* Only the PMF sets the HW */
10278 if (sc->port.pmf) {
10279 storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc));
10282 /* init Event Queue - PCI bus guarantees correct endainity */
10283 eq_data.base_addr.hi = U64_HI(sc->eq_dma.paddr);
10284 eq_data.base_addr.lo = U64_LO(sc->eq_dma.paddr);
10285 eq_data.producer = sc->eq_prod;
10286 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
10287 eq_data.sb_id = DEF_SB_ID;
10288 storm_memset_eq_data(sc, &eq_data, SC_FUNC(sc));
10292 bxe_hc_int_enable(struct bxe_softc *sc)
10294 int port = SC_PORT(sc);
10295 uint32_t addr = (port) ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
10296 uint32_t val = REG_RD(sc, addr);
10297 uint8_t msix = (sc->interrupt_mode == INTR_MODE_MSIX) ? TRUE : FALSE;
10298 uint8_t single_msix = ((sc->interrupt_mode == INTR_MODE_MSIX) &&
10299 (sc->intr_count == 1)) ? TRUE : FALSE;
10300 uint8_t msi = (sc->interrupt_mode == INTR_MODE_MSI) ? TRUE : FALSE;
10303 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10304 HC_CONFIG_0_REG_INT_LINE_EN_0);
10305 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
10306 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10308 val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
10311 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
10312 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10313 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
10314 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10316 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10317 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
10318 HC_CONFIG_0_REG_INT_LINE_EN_0 |
10319 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10321 if (!CHIP_IS_E1(sc)) {
10322 BLOGD(sc, DBG_INTR, "write %x to HC %d (addr 0x%x)\n",
10325 REG_WR(sc, addr, val);
10327 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
10331 if (CHIP_IS_E1(sc)) {
10332 REG_WR(sc, (HC_REG_INT_MASK + port*4), 0x1FFFF);
10335 BLOGD(sc, DBG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n",
10336 val, port, addr, ((msix) ? "MSI-X" : ((msi) ? "MSI" : "INTx")));
10338 REG_WR(sc, addr, val);
10340 /* ensure that HC_CONFIG is written before leading/trailing edge config */
10343 if (!CHIP_IS_E1(sc)) {
10344 /* init leading/trailing edge */
10346 val = (0xee0f | (1 << (SC_VN(sc) + 4)));
10347 if (sc->port.pmf) {
10348 /* enable nig and gpio3 attention */
10355 REG_WR(sc, (HC_REG_TRAILING_EDGE_0 + port*8), val);
10356 REG_WR(sc, (HC_REG_LEADING_EDGE_0 + port*8), val);
10359 /* make sure that interrupts are indeed enabled from here on */
10364 bxe_igu_int_enable(struct bxe_softc *sc)
10367 uint8_t msix = (sc->interrupt_mode == INTR_MODE_MSIX) ? TRUE : FALSE;
10368 uint8_t single_msix = ((sc->interrupt_mode == INTR_MODE_MSIX) &&
10369 (sc->intr_count == 1)) ? TRUE : FALSE;
10370 uint8_t msi = (sc->interrupt_mode == INTR_MODE_MSI) ? TRUE : FALSE;
10372 val = REG_RD(sc, IGU_REG_PF_CONFIGURATION);
10375 val &= ~(IGU_PF_CONF_INT_LINE_EN |
10376 IGU_PF_CONF_SINGLE_ISR_EN);
10377 val |= (IGU_PF_CONF_MSI_MSIX_EN |
10378 IGU_PF_CONF_ATTN_BIT_EN);
10380 val |= IGU_PF_CONF_SINGLE_ISR_EN;
10383 val &= ~IGU_PF_CONF_INT_LINE_EN;
10384 val |= (IGU_PF_CONF_MSI_MSIX_EN |
10385 IGU_PF_CONF_ATTN_BIT_EN |
10386 IGU_PF_CONF_SINGLE_ISR_EN);
10388 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
10389 val |= (IGU_PF_CONF_INT_LINE_EN |
10390 IGU_PF_CONF_ATTN_BIT_EN |
10391 IGU_PF_CONF_SINGLE_ISR_EN);
10394 /* clean previous status - need to configure igu prior to ack*/
10395 if ((!msix) || single_msix) {
10396 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
10400 val |= IGU_PF_CONF_FUNC_EN;
10402 BLOGD(sc, DBG_INTR, "write 0x%x to IGU mode %s\n",
10403 val, ((msix) ? "MSI-X" : ((msi) ? "MSI" : "INTx")));
10405 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
10409 /* init leading/trailing edge */
10411 val = (0xee0f | (1 << (SC_VN(sc) + 4)));
10412 if (sc->port.pmf) {
10413 /* enable nig and gpio3 attention */
10420 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, val);
10421 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, val);
10423 /* make sure that interrupts are indeed enabled from here on */
10428 bxe_int_enable(struct bxe_softc *sc)
10430 if (sc->devinfo.int_block == INT_BLOCK_HC) {
10431 bxe_hc_int_enable(sc);
10433 bxe_igu_int_enable(sc);
10438 bxe_hc_int_disable(struct bxe_softc *sc)
10440 int port = SC_PORT(sc);
10441 uint32_t addr = (port) ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
10442 uint32_t val = REG_RD(sc, addr);
10445 * In E1 we must use only PCI configuration space to disable MSI/MSIX
10446 * capablility. It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC
10449 if (CHIP_IS_E1(sc)) {
10451 * Since IGU_PF_CONF_MSI_MSIX_EN still always on use mask register
10452 * to prevent from HC sending interrupts after we exit the function
10454 REG_WR(sc, (HC_REG_INT_MASK + port*4), 0);
10456 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10457 HC_CONFIG_0_REG_INT_LINE_EN_0 |
10458 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10460 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10461 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
10462 HC_CONFIG_0_REG_INT_LINE_EN_0 |
10463 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10466 BLOGD(sc, DBG_INTR, "write %x to HC %d (addr 0x%x)\n", val, port, addr);
10468 /* flush all outstanding writes */
10471 REG_WR(sc, addr, val);
10472 if (REG_RD(sc, addr) != val) {
10473 BLOGE(sc, "proper val not read from HC IGU!\n");
10478 bxe_igu_int_disable(struct bxe_softc *sc)
10480 uint32_t val = REG_RD(sc, IGU_REG_PF_CONFIGURATION);
10482 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
10483 IGU_PF_CONF_INT_LINE_EN |
10484 IGU_PF_CONF_ATTN_BIT_EN);
10486 BLOGD(sc, DBG_INTR, "write %x to IGU\n", val);
10488 /* flush all outstanding writes */
10491 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
10492 if (REG_RD(sc, IGU_REG_PF_CONFIGURATION) != val) {
10493 BLOGE(sc, "proper val not read from IGU!\n");
10498 bxe_int_disable(struct bxe_softc *sc)
10500 if (sc->devinfo.int_block == INT_BLOCK_HC) {
10501 bxe_hc_int_disable(sc);
10503 bxe_igu_int_disable(sc);
10508 bxe_nic_init(struct bxe_softc *sc,
10513 for (i = 0; i < sc->num_queues; i++) {
10514 bxe_init_eth_fp(sc, i);
10517 rmb(); /* ensure status block indices were read */
10519 bxe_init_rx_rings(sc);
10520 bxe_init_tx_rings(sc);
10526 /* initialize MOD_ABS interrupts */
10527 elink_init_mod_abs_int(sc, &sc->link_vars,
10528 sc->devinfo.chip_id,
10529 sc->devinfo.shmem_base,
10530 sc->devinfo.shmem2_base,
10533 bxe_init_def_sb(sc);
10534 bxe_update_dsb_idx(sc);
10535 bxe_init_sp_ring(sc);
10536 bxe_init_eq_ring(sc);
10537 bxe_init_internal(sc, load_code);
10539 bxe_stats_init(sc);
10541 /* flush all before enabling interrupts */
10544 bxe_int_enable(sc);
10546 /* check for SPIO5 */
10547 bxe_attn_int_deasserted0(sc,
10549 (MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
10551 AEU_INPUTS_ATTN_BITS_SPIO5);
10555 bxe_init_objs(struct bxe_softc *sc)
10557 /* mcast rules must be added to tx if tx switching is enabled */
10558 ecore_obj_type o_type =
10559 (sc->flags & BXE_TX_SWITCHING) ? ECORE_OBJ_TYPE_RX_TX :
10562 /* RX_MODE controlling object */
10563 ecore_init_rx_mode_obj(sc, &sc->rx_mode_obj);
10565 /* multicast configuration controlling object */
10566 ecore_init_mcast_obj(sc,
10572 BXE_SP(sc, mcast_rdata),
10573 BXE_SP_MAPPING(sc, mcast_rdata),
10574 ECORE_FILTER_MCAST_PENDING,
10578 /* Setup CAM credit pools */
10579 ecore_init_mac_credit_pool(sc,
10582 CHIP_IS_E1x(sc) ? VNICS_PER_PORT(sc) :
10583 VNICS_PER_PATH(sc));
10585 ecore_init_vlan_credit_pool(sc,
10587 SC_ABS_FUNC(sc) >> 1,
10588 CHIP_IS_E1x(sc) ? VNICS_PER_PORT(sc) :
10589 VNICS_PER_PATH(sc));
10591 /* RSS configuration object */
10592 ecore_init_rss_config_obj(sc,
10598 BXE_SP(sc, rss_rdata),
10599 BXE_SP_MAPPING(sc, rss_rdata),
10600 ECORE_FILTER_RSS_CONF_PENDING,
10601 &sc->sp_state, ECORE_OBJ_TYPE_RX);
10605 * Initialize the function. This must be called before sending CLIENT_SETUP
10606 * for the first client.
10609 bxe_func_start(struct bxe_softc *sc)
10611 struct ecore_func_state_params func_params = { NULL };
10612 struct ecore_func_start_params *start_params = &func_params.params.start;
10614 /* Prepare parameters for function state transitions */
10615 bit_set(&func_params.ramrod_flags, RAMROD_COMP_WAIT);
10617 func_params.f_obj = &sc->func_obj;
10618 func_params.cmd = ECORE_F_CMD_START;
10620 /* Function parameters */
10621 start_params->mf_mode = sc->devinfo.mf_info.mf_mode;
10622 start_params->sd_vlan_tag = OVLAN(sc);
10624 if (CHIP_IS_E2(sc) || CHIP_IS_E3(sc)) {
10625 start_params->network_cos_mode = STATIC_COS;
10626 } else { /* CHIP_IS_E1X */
10627 start_params->network_cos_mode = FW_WRR;
10630 //start_params->gre_tunnel_mode = 0;
10631 //start_params->gre_tunnel_rss = 0;
10633 return (ecore_func_state_change(sc, &func_params));
10637 bxe_set_power_state(struct bxe_softc *sc,
10642 /* If there is no power capability, silently succeed */
10643 if (!(sc->devinfo.pcie_cap_flags & BXE_PM_CAPABLE_FLAG)) {
10644 BLOGW(sc, "No power capability\n");
10648 pmcsr = pci_read_config(sc->dev,
10649 (sc->devinfo.pcie_pm_cap_reg + PCIR_POWER_STATUS),
10654 pci_write_config(sc->dev,
10655 (sc->devinfo.pcie_pm_cap_reg + PCIR_POWER_STATUS),
10656 ((pmcsr & ~PCIM_PSTAT_DMASK) | PCIM_PSTAT_PME), 2);
10658 if (pmcsr & PCIM_PSTAT_DMASK) {
10659 /* delay required during transition out of D3hot */
10666 /* XXX if there are other clients above don't shut down the power */
10668 /* don't shut down the power for emulation and FPGA */
10669 if (CHIP_REV_IS_SLOW(sc)) {
10673 pmcsr &= ~PCIM_PSTAT_DMASK;
10674 pmcsr |= PCIM_PSTAT_D3;
10677 pmcsr |= PCIM_PSTAT_PMEENABLE;
10680 pci_write_config(sc->dev,
10681 (sc->devinfo.pcie_pm_cap_reg + PCIR_POWER_STATUS),
10685 * No more memory access after this point until device is brought back
10691 BLOGE(sc, "Can't support PCI power state = 0x%x pmcsr 0x%x\n",
10700 /* return true if succeeded to acquire the lock */
10702 bxe_trylock_hw_lock(struct bxe_softc *sc,
10705 uint32_t lock_status;
10706 uint32_t resource_bit = (1 << resource);
10707 int func = SC_FUNC(sc);
10708 uint32_t hw_lock_control_reg;
10710 BLOGD(sc, DBG_LOAD, "Trying to take a resource lock 0x%x\n", resource);
10712 /* Validating that the resource is within range */
10713 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
10714 BLOGD(sc, DBG_LOAD,
10715 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
10716 resource, HW_LOCK_MAX_RESOURCE_VALUE);
10721 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
10723 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
10726 /* try to acquire the lock */
10727 REG_WR(sc, hw_lock_control_reg + 4, resource_bit);
10728 lock_status = REG_RD(sc, hw_lock_control_reg);
10729 if (lock_status & resource_bit) {
10733 BLOGE(sc, "Failed to get a resource lock 0x%x func %d "
10734 "lock_status 0x%x resource_bit 0x%x\n", resource, func,
10735 lock_status, resource_bit);
10741 * Get the recovery leader resource id according to the engine this function
10742 * belongs to. Currently only only 2 engines is supported.
10745 bxe_get_leader_lock_resource(struct bxe_softc *sc)
10748 return (HW_LOCK_RESOURCE_RECOVERY_LEADER_1);
10750 return (HW_LOCK_RESOURCE_RECOVERY_LEADER_0);
10754 /* try to acquire a leader lock for current engine */
10756 bxe_trylock_leader_lock(struct bxe_softc *sc)
10758 return (bxe_trylock_hw_lock(sc, bxe_get_leader_lock_resource(sc)));
10762 bxe_release_leader_lock(struct bxe_softc *sc)
10764 return (bxe_release_hw_lock(sc, bxe_get_leader_lock_resource(sc)));
10767 /* close gates #2, #3 and #4 */
10769 bxe_set_234_gates(struct bxe_softc *sc,
10774 /* gates #2 and #4a are closed/opened for "not E1" only */
10775 if (!CHIP_IS_E1(sc)) {
10777 REG_WR(sc, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
10779 REG_WR(sc, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
10783 if (CHIP_IS_E1x(sc)) {
10784 /* prevent interrupts from HC on both ports */
10785 val = REG_RD(sc, HC_REG_CONFIG_1);
10786 REG_WR(sc, HC_REG_CONFIG_1,
10787 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
10788 (val & ~(uint32_t)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
10790 val = REG_RD(sc, HC_REG_CONFIG_0);
10791 REG_WR(sc, HC_REG_CONFIG_0,
10792 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
10793 (val & ~(uint32_t)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
10795 /* Prevent incomming interrupts in IGU */
10796 val = REG_RD(sc, IGU_REG_BLOCK_CONFIGURATION);
10798 REG_WR(sc, IGU_REG_BLOCK_CONFIGURATION,
10800 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
10801 (val & ~(uint32_t)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
10804 BLOGD(sc, DBG_LOAD, "%s gates #2, #3 and #4\n",
10805 close ? "closing" : "opening");
10810 /* poll for pending writes bit, it should get cleared in no more than 1s */
10812 bxe_er_poll_igu_vq(struct bxe_softc *sc)
10814 uint32_t cnt = 1000;
10815 uint32_t pend_bits = 0;
10818 pend_bits = REG_RD(sc, IGU_REG_PENDING_BITS_STATUS);
10820 if (pend_bits == 0) {
10825 } while (--cnt > 0);
10828 BLOGE(sc, "Still pending IGU requests bits=0x%08x!\n", pend_bits);
10835 #define SHARED_MF_CLP_MAGIC 0x80000000 /* 'magic' bit */
10838 bxe_clp_reset_prep(struct bxe_softc *sc,
10839 uint32_t *magic_val)
10841 /* Do some magic... */
10842 uint32_t val = MFCFG_RD(sc, shared_mf_config.clp_mb);
10843 *magic_val = val & SHARED_MF_CLP_MAGIC;
10844 MFCFG_WR(sc, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
10847 /* restore the value of the 'magic' bit */
10849 bxe_clp_reset_done(struct bxe_softc *sc,
10850 uint32_t magic_val)
10852 /* Restore the 'magic' bit value... */
10853 uint32_t val = MFCFG_RD(sc, shared_mf_config.clp_mb);
10854 MFCFG_WR(sc, shared_mf_config.clp_mb,
10855 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
10858 /* prepare for MCP reset, takes care of CLP configurations */
10860 bxe_reset_mcp_prep(struct bxe_softc *sc,
10861 uint32_t *magic_val)
10864 uint32_t validity_offset;
10866 /* set `magic' bit in order to save MF config */
10867 if (!CHIP_IS_E1(sc)) {
10868 bxe_clp_reset_prep(sc, magic_val);
10871 /* get shmem offset */
10872 shmem = REG_RD(sc, MISC_REG_SHARED_MEM_ADDR);
10874 offsetof(struct shmem_region, validity_map[SC_PORT(sc)]);
10876 /* Clear validity map flags */
10878 REG_WR(sc, shmem + validity_offset, 0);
10882 #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
10883 #define MCP_ONE_TIMEOUT 100 /* 100 ms */
10886 bxe_mcp_wait_one(struct bxe_softc *sc)
10888 /* special handling for emulation and FPGA (10 times longer) */
10889 if (CHIP_REV_IS_SLOW(sc)) {
10890 DELAY((MCP_ONE_TIMEOUT*10) * 1000);
10892 DELAY((MCP_ONE_TIMEOUT) * 1000);
10896 /* initialize shmem_base and waits for validity signature to appear */
10898 bxe_init_shmem(struct bxe_softc *sc)
10904 sc->devinfo.shmem_base =
10905 sc->link_params.shmem_base =
10906 REG_RD(sc, MISC_REG_SHARED_MEM_ADDR);
10908 if (sc->devinfo.shmem_base) {
10909 val = SHMEM_RD(sc, validity_map[SC_PORT(sc)]);
10910 if (val & SHR_MEM_VALIDITY_MB)
10914 bxe_mcp_wait_one(sc);
10916 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
10918 BLOGE(sc, "BAD MCP validity signature\n");
10924 bxe_reset_mcp_comp(struct bxe_softc *sc,
10925 uint32_t magic_val)
10927 int rc = bxe_init_shmem(sc);
10929 /* Restore the `magic' bit value */
10930 if (!CHIP_IS_E1(sc)) {
10931 bxe_clp_reset_done(sc, magic_val);
10938 bxe_pxp_prep(struct bxe_softc *sc)
10940 if (!CHIP_IS_E1(sc)) {
10941 REG_WR(sc, PXP2_REG_RD_START_INIT, 0);
10942 REG_WR(sc, PXP2_REG_RQ_RBC_DONE, 0);
10948 * Reset the whole chip except for:
10950 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by one reset bit)
10952 * - MISC (including AEU)
10957 bxe_process_kill_chip_reset(struct bxe_softc *sc,
10960 uint32_t not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
10961 uint32_t global_bits2, stay_reset2;
10964 * Bits that have to be set in reset_mask2 if we want to reset 'global'
10965 * (per chip) blocks.
10968 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
10969 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
10972 * Don't reset the following blocks.
10973 * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
10974 * reset, as in 4 port device they might still be owned
10975 * by the MCP (there is only one leader per path).
10978 MISC_REGISTERS_RESET_REG_1_RST_HC |
10979 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
10980 MISC_REGISTERS_RESET_REG_1_RST_PXP;
10983 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
10984 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
10985 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
10986 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
10987 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
10988 MISC_REGISTERS_RESET_REG_2_RST_GRC |
10989 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
10990 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
10991 MISC_REGISTERS_RESET_REG_2_RST_ATC |
10992 MISC_REGISTERS_RESET_REG_2_PGLC |
10993 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
10994 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
10995 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
10996 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
10997 MISC_REGISTERS_RESET_REG_2_UMAC0 |
10998 MISC_REGISTERS_RESET_REG_2_UMAC1;
11001 * Keep the following blocks in reset:
11002 * - all xxMACs are handled by the elink code.
11005 MISC_REGISTERS_RESET_REG_2_XMAC |
11006 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
11008 /* Full reset masks according to the chip */
11009 reset_mask1 = 0xffffffff;
11011 if (CHIP_IS_E1(sc))
11012 reset_mask2 = 0xffff;
11013 else if (CHIP_IS_E1H(sc))
11014 reset_mask2 = 0x1ffff;
11015 else if (CHIP_IS_E2(sc))
11016 reset_mask2 = 0xfffff;
11017 else /* CHIP_IS_E3 */
11018 reset_mask2 = 0x3ffffff;
11020 /* Don't reset global blocks unless we need to */
11022 reset_mask2 &= ~global_bits2;
11025 * In case of attention in the QM, we need to reset PXP
11026 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
11027 * because otherwise QM reset would release 'close the gates' shortly
11028 * before resetting the PXP, then the PSWRQ would send a write
11029 * request to PGLUE. Then when PXP is reset, PGLUE would try to
11030 * read the payload data from PSWWR, but PSWWR would not
11031 * respond. The write queue in PGLUE would stuck, dmae commands
11032 * would not return. Therefore it's important to reset the second
11033 * reset register (containing the
11034 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
11035 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
11038 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
11039 reset_mask2 & (~not_reset_mask2));
11041 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
11042 reset_mask1 & (~not_reset_mask1));
11047 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
11048 reset_mask2 & (~stay_reset2));
11053 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
11058 bxe_process_kill(struct bxe_softc *sc,
11063 uint32_t sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
11064 uint32_t tags_63_32 = 0;
11066 /* Empty the Tetris buffer, wait for 1s */
11068 sr_cnt = REG_RD(sc, PXP2_REG_RD_SR_CNT);
11069 blk_cnt = REG_RD(sc, PXP2_REG_RD_BLK_CNT);
11070 port_is_idle_0 = REG_RD(sc, PXP2_REG_RD_PORT_IS_IDLE_0);
11071 port_is_idle_1 = REG_RD(sc, PXP2_REG_RD_PORT_IS_IDLE_1);
11072 pgl_exp_rom2 = REG_RD(sc, PXP2_REG_PGL_EXP_ROM2);
11073 if (CHIP_IS_E3(sc)) {
11074 tags_63_32 = REG_RD(sc, PGLUE_B_REG_TAGS_63_32);
11077 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
11078 ((port_is_idle_0 & 0x1) == 0x1) &&
11079 ((port_is_idle_1 & 0x1) == 0x1) &&
11080 (pgl_exp_rom2 == 0xffffffff) &&
11081 (!CHIP_IS_E3(sc) || (tags_63_32 == 0xffffffff)))
11084 } while (cnt-- > 0);
11087 BLOGE(sc, "ERROR: Tetris buffer didn't get empty or there "
11088 "are still outstanding read requests after 1s! "
11089 "sr_cnt=0x%08x, blk_cnt=0x%08x, port_is_idle_0=0x%08x, "
11090 "port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
11091 sr_cnt, blk_cnt, port_is_idle_0,
11092 port_is_idle_1, pgl_exp_rom2);
11098 /* Close gates #2, #3 and #4 */
11099 bxe_set_234_gates(sc, TRUE);
11101 /* Poll for IGU VQs for 57712 and newer chips */
11102 if (!CHIP_IS_E1x(sc) && bxe_er_poll_igu_vq(sc)) {
11106 /* XXX indicate that "process kill" is in progress to MCP */
11108 /* clear "unprepared" bit */
11109 REG_WR(sc, MISC_REG_UNPREPARED, 0);
11112 /* Make sure all is written to the chip before the reset */
11116 * Wait for 1ms to empty GLUE and PCI-E core queues,
11117 * PSWHST, GRC and PSWRD Tetris buffer.
11121 /* Prepare to chip reset: */
11124 bxe_reset_mcp_prep(sc, &val);
11131 /* reset the chip */
11132 bxe_process_kill_chip_reset(sc, global);
11135 /* clear errors in PGB */
11136 if (!CHIP_IS_E1(sc))
11137 REG_WR(sc, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
11139 /* Recover after reset: */
11141 if (global && bxe_reset_mcp_comp(sc, val)) {
11145 /* XXX add resetting the NO_MCP mode DB here */
11147 /* Open the gates #2, #3 and #4 */
11148 bxe_set_234_gates(sc, FALSE);
11151 * IGU/AEU preparation bring back the AEU/IGU to a reset state
11152 * re-enable attentions
11159 bxe_leader_reset(struct bxe_softc *sc)
11162 uint8_t global = bxe_reset_is_global(sc);
11163 uint32_t load_code;
11166 * If not going to reset MCP, load "fake" driver to reset HW while
11167 * driver is owner of the HW.
11169 if (!global && !BXE_NOMCP(sc)) {
11170 load_code = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_REQ,
11171 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
11173 BLOGE(sc, "MCP response failure, aborting\n");
11175 goto exit_leader_reset;
11178 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
11179 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
11180 BLOGE(sc, "MCP unexpected response, aborting\n");
11182 goto exit_leader_reset2;
11185 load_code = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
11187 BLOGE(sc, "MCP response failure, aborting\n");
11189 goto exit_leader_reset2;
11193 /* try to recover after the failure */
11194 if (bxe_process_kill(sc, global)) {
11195 BLOGE(sc, "Something bad occurred on engine %d!\n", SC_PATH(sc));
11197 goto exit_leader_reset2;
11201 * Clear the RESET_IN_PROGRESS and RESET_GLOBAL bits and update the driver
11204 bxe_set_reset_done(sc);
11206 bxe_clear_reset_global(sc);
11209 exit_leader_reset2:
11211 /* unload "fake driver" if it was loaded */
11212 if (!global && !BXE_NOMCP(sc)) {
11213 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
11214 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, 0);
11220 bxe_release_leader_lock(sc);
11227 * prepare INIT transition, parameters configured:
11228 * - HC configuration
11229 * - Queue's CDU context
11232 bxe_pf_q_prep_init(struct bxe_softc *sc,
11233 struct bxe_fastpath *fp,
11234 struct ecore_queue_init_params *init_params)
11237 int cxt_index, cxt_offset;
11239 bxe_set_bit(ECORE_Q_FLG_HC, &init_params->rx.flags);
11240 bxe_set_bit(ECORE_Q_FLG_HC, &init_params->tx.flags);
11242 bxe_set_bit(ECORE_Q_FLG_HC_EN, &init_params->rx.flags);
11243 bxe_set_bit(ECORE_Q_FLG_HC_EN, &init_params->tx.flags);
11246 init_params->rx.hc_rate =
11247 sc->hc_rx_ticks ? (1000000 / sc->hc_rx_ticks) : 0;
11248 init_params->tx.hc_rate =
11249 sc->hc_tx_ticks ? (1000000 / sc->hc_tx_ticks) : 0;
11252 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id = fp->fw_sb_id;
11254 /* CQ index among the SB indices */
11255 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
11256 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
11258 /* set maximum number of COSs supported by this queue */
11259 init_params->max_cos = sc->max_cos;
11261 BLOGD(sc, DBG_LOAD, "fp %d setting queue params max cos to %d\n",
11262 fp->index, init_params->max_cos);
11264 /* set the context pointers queue object */
11265 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
11266 /* XXX change index/cid here if ever support multiple tx CoS */
11267 /* fp->txdata[cos]->cid */
11268 cxt_index = fp->index / ILT_PAGE_CIDS;
11269 cxt_offset = fp->index - (cxt_index * ILT_PAGE_CIDS);
11270 init_params->cxts[cos] = &sc->context[cxt_index].vcxt[cxt_offset].eth;
11274 /* set flags that are common for the Tx-only and not normal connections */
11275 static unsigned long
11276 bxe_get_common_flags(struct bxe_softc *sc,
11277 struct bxe_fastpath *fp,
11278 uint8_t zero_stats)
11280 unsigned long flags = 0;
11282 /* PF driver will always initialize the Queue to an ACTIVE state */
11283 bxe_set_bit(ECORE_Q_FLG_ACTIVE, &flags);
11286 * tx only connections collect statistics (on the same index as the
11287 * parent connection). The statistics are zeroed when the parent
11288 * connection is initialized.
11291 bxe_set_bit(ECORE_Q_FLG_STATS, &flags);
11293 bxe_set_bit(ECORE_Q_FLG_ZERO_STATS, &flags);
11297 * tx only connections can support tx-switching, though their
11298 * CoS-ness doesn't survive the loopback
11300 if (sc->flags & BXE_TX_SWITCHING) {
11301 bxe_set_bit(ECORE_Q_FLG_TX_SWITCH, &flags);
11304 bxe_set_bit(ECORE_Q_FLG_PCSUM_ON_PKT, &flags);
11309 static unsigned long
11310 bxe_get_q_flags(struct bxe_softc *sc,
11311 struct bxe_fastpath *fp,
11314 unsigned long flags = 0;
11316 if (IS_MF_SD(sc)) {
11317 bxe_set_bit(ECORE_Q_FLG_OV, &flags);
11320 if (sc->ifnet->if_capenable & IFCAP_LRO) {
11321 bxe_set_bit(ECORE_Q_FLG_TPA, &flags);
11322 #if __FreeBSD_version >= 800000
11323 bxe_set_bit(ECORE_Q_FLG_TPA_IPV6, &flags);
11328 bxe_set_bit(ECORE_Q_FLG_LEADING_RSS, &flags);
11329 bxe_set_bit(ECORE_Q_FLG_MCAST, &flags);
11332 bxe_set_bit(ECORE_Q_FLG_VLAN, &flags);
11334 /* merge with common flags */
11335 return (flags | bxe_get_common_flags(sc, fp, TRUE));
11339 bxe_pf_q_prep_general(struct bxe_softc *sc,
11340 struct bxe_fastpath *fp,
11341 struct ecore_general_setup_params *gen_init,
11344 gen_init->stat_id = bxe_stats_id(fp);
11345 gen_init->spcl_id = fp->cl_id;
11346 gen_init->mtu = sc->mtu;
11347 gen_init->cos = cos;
11351 bxe_pf_rx_q_prep(struct bxe_softc *sc,
11352 struct bxe_fastpath *fp,
11353 struct rxq_pause_params *pause,
11354 struct ecore_rxq_setup_params *rxq_init)
11356 uint8_t max_sge = 0;
11357 uint16_t sge_sz = 0;
11358 uint16_t tpa_agg_size = 0;
11360 pause->sge_th_lo = SGE_TH_LO(sc);
11361 pause->sge_th_hi = SGE_TH_HI(sc);
11363 /* validate SGE ring has enough to cross high threshold */
11364 if (sc->dropless_fc &&
11365 (pause->sge_th_hi + FW_PREFETCH_CNT) >
11366 (RX_SGE_USABLE_PER_PAGE * RX_SGE_NUM_PAGES)) {
11367 BLOGW(sc, "sge ring threshold limit\n");
11370 /* minimum max_aggregation_size is 2*MTU (two full buffers) */
11371 tpa_agg_size = (2 * sc->mtu);
11372 if (tpa_agg_size < sc->max_aggregation_size) {
11373 tpa_agg_size = sc->max_aggregation_size;
11376 max_sge = SGE_PAGE_ALIGN(sc->mtu) >> SGE_PAGE_SHIFT;
11377 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
11378 (~(PAGES_PER_SGE - 1))) >> PAGES_PER_SGE_SHIFT;
11379 sge_sz = (uint16_t)min(SGE_PAGES, 0xffff);
11381 /* pause - not for e1 */
11382 if (!CHIP_IS_E1(sc)) {
11383 pause->bd_th_lo = BD_TH_LO(sc);
11384 pause->bd_th_hi = BD_TH_HI(sc);
11386 pause->rcq_th_lo = RCQ_TH_LO(sc);
11387 pause->rcq_th_hi = RCQ_TH_HI(sc);
11389 /* validate rings have enough entries to cross high thresholds */
11390 if (sc->dropless_fc &&
11391 pause->bd_th_hi + FW_PREFETCH_CNT >
11392 sc->rx_ring_size) {
11393 BLOGW(sc, "rx bd ring threshold limit\n");
11396 if (sc->dropless_fc &&
11397 pause->rcq_th_hi + FW_PREFETCH_CNT >
11398 RCQ_NUM_PAGES * RCQ_USABLE_PER_PAGE) {
11399 BLOGW(sc, "rcq ring threshold limit\n");
11402 pause->pri_map = 1;
11406 rxq_init->dscr_map = fp->rx_dma.paddr;
11407 rxq_init->sge_map = fp->rx_sge_dma.paddr;
11408 rxq_init->rcq_map = fp->rcq_dma.paddr;
11409 rxq_init->rcq_np_map = (fp->rcq_dma.paddr + BCM_PAGE_SIZE);
11412 * This should be a maximum number of data bytes that may be
11413 * placed on the BD (not including paddings).
11415 rxq_init->buf_sz = (fp->rx_buf_size -
11416 IP_HEADER_ALIGNMENT_PADDING);
11418 rxq_init->cl_qzone_id = fp->cl_qzone_id;
11419 rxq_init->tpa_agg_sz = tpa_agg_size;
11420 rxq_init->sge_buf_sz = sge_sz;
11421 rxq_init->max_sges_pkt = max_sge;
11422 rxq_init->rss_engine_id = SC_FUNC(sc);
11423 rxq_init->mcast_engine_id = SC_FUNC(sc);
11426 * Maximum number or simultaneous TPA aggregation for this Queue.
11427 * For PF Clients it should be the maximum available number.
11428 * VF driver(s) may want to define it to a smaller value.
11430 rxq_init->max_tpa_queues = MAX_AGG_QS(sc);
11432 rxq_init->cache_line_log = BXE_RX_ALIGN_SHIFT;
11433 rxq_init->fw_sb_id = fp->fw_sb_id;
11435 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
11438 * configure silent vlan removal
11439 * if multi function mode is afex, then mask default vlan
11441 if (IS_MF_AFEX(sc)) {
11442 rxq_init->silent_removal_value =
11443 sc->devinfo.mf_info.afex_def_vlan_tag;
11444 rxq_init->silent_removal_mask = EVL_VLID_MASK;
11449 bxe_pf_tx_q_prep(struct bxe_softc *sc,
11450 struct bxe_fastpath *fp,
11451 struct ecore_txq_setup_params *txq_init,
11455 * XXX If multiple CoS is ever supported then each fastpath structure
11456 * will need to maintain tx producer/consumer/dma/etc values *per* CoS.
11457 * fp->txdata[cos]->tx_dma.paddr;
11459 txq_init->dscr_map = fp->tx_dma.paddr;
11460 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
11461 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
11462 txq_init->fw_sb_id = fp->fw_sb_id;
11465 * set the TSS leading client id for TX classfication to the
11466 * leading RSS client id
11468 txq_init->tss_leading_cl_id = BXE_FP(sc, 0, cl_id);
11472 * This function performs 2 steps in a queue state machine:
11477 bxe_setup_queue(struct bxe_softc *sc,
11478 struct bxe_fastpath *fp,
11481 struct ecore_queue_state_params q_params = { NULL };
11482 struct ecore_queue_setup_params *setup_params =
11483 &q_params.params.setup;
11486 BLOGD(sc, DBG_LOAD, "setting up queue %d\n", fp->index);
11488 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
11490 q_params.q_obj = &BXE_SP_OBJ(sc, fp).q_obj;
11492 /* we want to wait for completion in this context */
11493 bxe_set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
11495 /* prepare the INIT parameters */
11496 bxe_pf_q_prep_init(sc, fp, &q_params.params.init);
11498 /* Set the command */
11499 q_params.cmd = ECORE_Q_CMD_INIT;
11501 /* Change the state to INIT */
11502 rc = ecore_queue_state_change(sc, &q_params);
11504 BLOGE(sc, "Queue(%d) INIT failed rc = %d\n", fp->index, rc);
11508 BLOGD(sc, DBG_LOAD, "init complete\n");
11510 /* now move the Queue to the SETUP state */
11511 memset(setup_params, 0, sizeof(*setup_params));
11513 /* set Queue flags */
11514 setup_params->flags = bxe_get_q_flags(sc, fp, leading);
11516 /* set general SETUP parameters */
11517 bxe_pf_q_prep_general(sc, fp, &setup_params->gen_params,
11518 FIRST_TX_COS_INDEX);
11520 bxe_pf_rx_q_prep(sc, fp,
11521 &setup_params->pause_params,
11522 &setup_params->rxq_params);
11524 bxe_pf_tx_q_prep(sc, fp,
11525 &setup_params->txq_params,
11526 FIRST_TX_COS_INDEX);
11528 /* Set the command */
11529 q_params.cmd = ECORE_Q_CMD_SETUP;
11531 /* change the state to SETUP */
11532 rc = ecore_queue_state_change(sc, &q_params);
11534 BLOGE(sc, "Queue(%d) SETUP failed (rc = %d)\n", fp->index, rc);
11542 bxe_setup_leading(struct bxe_softc *sc)
11544 return (bxe_setup_queue(sc, &sc->fp[0], TRUE));
11548 bxe_config_rss_pf(struct bxe_softc *sc,
11549 struct ecore_rss_config_obj *rss_obj,
11550 uint8_t config_hash)
11552 struct ecore_config_rss_params params = { NULL };
11556 * Although RSS is meaningless when there is a single HW queue we
11557 * still need it enabled in order to have HW Rx hash generated.
11560 params.rss_obj = rss_obj;
11562 bxe_set_bit(RAMROD_COMP_WAIT, ¶ms.ramrod_flags);
11564 bxe_set_bit(ECORE_RSS_MODE_REGULAR, ¶ms.rss_flags);
11566 /* RSS configuration */
11567 bxe_set_bit(ECORE_RSS_IPV4, ¶ms.rss_flags);
11568 bxe_set_bit(ECORE_RSS_IPV4_TCP, ¶ms.rss_flags);
11569 bxe_set_bit(ECORE_RSS_IPV6, ¶ms.rss_flags);
11570 bxe_set_bit(ECORE_RSS_IPV6_TCP, ¶ms.rss_flags);
11571 if (rss_obj->udp_rss_v4) {
11572 bxe_set_bit(ECORE_RSS_IPV4_UDP, ¶ms.rss_flags);
11574 if (rss_obj->udp_rss_v6) {
11575 bxe_set_bit(ECORE_RSS_IPV6_UDP, ¶ms.rss_flags);
11579 params.rss_result_mask = MULTI_MASK;
11581 memcpy(params.ind_table, rss_obj->ind_table, sizeof(params.ind_table));
11585 for (i = 0; i < sizeof(params.rss_key) / 4; i++) {
11586 params.rss_key[i] = arc4random();
11589 bxe_set_bit(ECORE_RSS_SET_SRCH, ¶ms.rss_flags);
11592 return (ecore_config_rss(sc, ¶ms));
11596 bxe_config_rss_eth(struct bxe_softc *sc,
11597 uint8_t config_hash)
11599 return (bxe_config_rss_pf(sc, &sc->rss_conf_obj, config_hash));
11603 bxe_init_rss_pf(struct bxe_softc *sc)
11605 uint8_t num_eth_queues = BXE_NUM_ETH_QUEUES(sc);
11609 * Prepare the initial contents of the indirection table if
11612 for (i = 0; i < sizeof(sc->rss_conf_obj.ind_table); i++) {
11613 sc->rss_conf_obj.ind_table[i] =
11614 (sc->fp->cl_id + (i % num_eth_queues));
11618 sc->rss_conf_obj.udp_rss_v4 = sc->rss_conf_obj.udp_rss_v6 = 1;
11622 * For 57710 and 57711 SEARCHER configuration (rss_keys) is
11623 * per-port, so if explicit configuration is needed, do it only
11626 * For 57712 and newer it's a per-function configuration.
11628 return (bxe_config_rss_eth(sc, sc->port.pmf || !CHIP_IS_E1x(sc)));
11632 bxe_set_mac_one(struct bxe_softc *sc,
11634 struct ecore_vlan_mac_obj *obj,
11637 unsigned long *ramrod_flags)
11639 struct ecore_vlan_mac_ramrod_params ramrod_param;
11642 memset(&ramrod_param, 0, sizeof(ramrod_param));
11644 /* fill in general parameters */
11645 ramrod_param.vlan_mac_obj = obj;
11646 ramrod_param.ramrod_flags = *ramrod_flags;
11648 /* fill a user request section if needed */
11649 if (!bxe_test_bit(RAMROD_CONT, ramrod_flags)) {
11650 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
11652 bxe_set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
11654 /* Set the command: ADD or DEL */
11655 ramrod_param.user_req.cmd = (set) ? ECORE_VLAN_MAC_ADD :
11656 ECORE_VLAN_MAC_DEL;
11659 rc = ecore_config_vlan_mac(sc, &ramrod_param);
11661 if (rc == ECORE_EXISTS) {
11662 BLOGD(sc, DBG_SP, "Failed to schedule ADD operations (EEXIST)\n");
11663 /* do not treat adding same MAC as error */
11665 } else if (rc < 0) {
11666 BLOGE(sc, "%s MAC failed (%d)\n", (set ? "Set" : "Delete"), rc);
11673 bxe_set_eth_mac(struct bxe_softc *sc,
11676 unsigned long ramrod_flags = 0;
11678 BLOGD(sc, DBG_LOAD, "Adding Ethernet MAC\n");
11680 bxe_set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
11682 /* Eth MAC is set on RSS leading client (fp[0]) */
11683 return (bxe_set_mac_one(sc, sc->link_params.mac_addr,
11684 &sc->sp_objs->mac_obj,
11685 set, ECORE_ETH_MAC, &ramrod_flags));
11689 bxe_get_cur_phy_idx(struct bxe_softc *sc)
11691 uint32_t sel_phy_idx = 0;
11693 if (sc->link_params.num_phys <= 1) {
11694 return (ELINK_INT_PHY);
11697 if (sc->link_vars.link_up) {
11698 sel_phy_idx = ELINK_EXT_PHY1;
11699 /* In case link is SERDES, check if the ELINK_EXT_PHY2 is the one */
11700 if ((sc->link_vars.link_status & LINK_STATUS_SERDES_LINK) &&
11701 (sc->link_params.phy[ELINK_EXT_PHY2].supported &
11702 ELINK_SUPPORTED_FIBRE))
11703 sel_phy_idx = ELINK_EXT_PHY2;
11705 switch (elink_phy_selection(&sc->link_params)) {
11706 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
11707 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
11708 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
11709 sel_phy_idx = ELINK_EXT_PHY1;
11711 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
11712 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
11713 sel_phy_idx = ELINK_EXT_PHY2;
11718 return (sel_phy_idx);
11722 bxe_get_link_cfg_idx(struct bxe_softc *sc)
11724 uint32_t sel_phy_idx = bxe_get_cur_phy_idx(sc);
11727 * The selected activated PHY is always after swapping (in case PHY
11728 * swapping is enabled). So when swapping is enabled, we need to reverse
11729 * the configuration
11732 if (sc->link_params.multi_phy_config & PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
11733 if (sel_phy_idx == ELINK_EXT_PHY1)
11734 sel_phy_idx = ELINK_EXT_PHY2;
11735 else if (sel_phy_idx == ELINK_EXT_PHY2)
11736 sel_phy_idx = ELINK_EXT_PHY1;
11739 return (ELINK_LINK_CONFIG_IDX(sel_phy_idx));
11743 bxe_set_requested_fc(struct bxe_softc *sc)
11746 * Initialize link parameters structure variables
11747 * It is recommended to turn off RX FC for jumbo frames
11748 * for better performance
11750 if (CHIP_IS_E1x(sc) && (sc->mtu > 5000)) {
11751 sc->link_params.req_fc_auto_adv = ELINK_FLOW_CTRL_TX;
11753 sc->link_params.req_fc_auto_adv = ELINK_FLOW_CTRL_BOTH;
11758 bxe_calc_fc_adv(struct bxe_softc *sc)
11760 uint8_t cfg_idx = bxe_get_link_cfg_idx(sc);
11763 sc->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
11766 switch (sc->link_vars.ieee_fc &
11767 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
11769 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
11770 sc->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
11774 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
11775 sc->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
11785 bxe_get_mf_speed(struct bxe_softc *sc)
11787 uint16_t line_speed = sc->link_vars.line_speed;
11790 bxe_extract_max_cfg(sc, sc->devinfo.mf_info.mf_config[SC_VN(sc)]);
11792 /* calculate the current MAX line speed limit for the MF devices */
11793 if (IS_MF_SI(sc)) {
11794 line_speed = (line_speed * maxCfg) / 100;
11795 } else { /* SD mode */
11796 uint16_t vn_max_rate = maxCfg * 100;
11798 if (vn_max_rate < line_speed) {
11799 line_speed = vn_max_rate;
11804 return (line_speed);
11808 bxe_fill_report_data(struct bxe_softc *sc,
11809 struct bxe_link_report_data *data)
11811 uint16_t line_speed = bxe_get_mf_speed(sc);
11813 memset(data, 0, sizeof(*data));
11815 /* fill the report data with the effective line speed */
11816 data->line_speed = line_speed;
11819 if (!sc->link_vars.link_up || (sc->flags & BXE_MF_FUNC_DIS)) {
11820 bxe_set_bit(BXE_LINK_REPORT_LINK_DOWN, &data->link_report_flags);
11824 if (sc->link_vars.duplex == DUPLEX_FULL) {
11825 bxe_set_bit(BXE_LINK_REPORT_FULL_DUPLEX, &data->link_report_flags);
11828 /* Rx Flow Control is ON */
11829 if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_RX) {
11830 bxe_set_bit(BXE_LINK_REPORT_RX_FC_ON, &data->link_report_flags);
11833 /* Tx Flow Control is ON */
11834 if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_TX) {
11835 bxe_set_bit(BXE_LINK_REPORT_TX_FC_ON, &data->link_report_flags);
11839 /* report link status to OS, should be called under phy_lock */
11841 bxe_link_report_locked(struct bxe_softc *sc)
11843 struct bxe_link_report_data cur_data;
11845 /* reread mf_cfg */
11846 if (IS_PF(sc) && !CHIP_IS_E1(sc)) {
11847 bxe_read_mf_cfg(sc);
11850 /* Read the current link report info */
11851 bxe_fill_report_data(sc, &cur_data);
11853 /* Don't report link down or exactly the same link status twice */
11854 if (!memcmp(&cur_data, &sc->last_reported_link, sizeof(cur_data)) ||
11855 (bxe_test_bit(BXE_LINK_REPORT_LINK_DOWN,
11856 &sc->last_reported_link.link_report_flags) &&
11857 bxe_test_bit(BXE_LINK_REPORT_LINK_DOWN,
11858 &cur_data.link_report_flags))) {
11862 ELINK_DEBUG_P2(sc, "Change in link status : cur_data = %x, last_reported_link = %x\n",
11863 cur_data.link_report_flags, sc->last_reported_link.link_report_flags);
11866 ELINK_DEBUG_P1(sc, "link status change count = %x\n", sc->link_cnt);
11867 /* report new link params and remember the state for the next time */
11868 memcpy(&sc->last_reported_link, &cur_data, sizeof(cur_data));
11870 if (bxe_test_bit(BXE_LINK_REPORT_LINK_DOWN,
11871 &cur_data.link_report_flags)) {
11872 if_link_state_change(sc->ifnet, LINK_STATE_DOWN);
11874 const char *duplex;
11877 if (bxe_test_and_clear_bit(BXE_LINK_REPORT_FULL_DUPLEX,
11878 &cur_data.link_report_flags)) {
11880 ELINK_DEBUG_P0(sc, "link set to full duplex\n");
11883 ELINK_DEBUG_P0(sc, "link set to half duplex\n");
11887 * Handle the FC at the end so that only these flags would be
11888 * possibly set. This way we may easily check if there is no FC
11891 if (cur_data.link_report_flags) {
11892 if (bxe_test_bit(BXE_LINK_REPORT_RX_FC_ON,
11893 &cur_data.link_report_flags) &&
11894 bxe_test_bit(BXE_LINK_REPORT_TX_FC_ON,
11895 &cur_data.link_report_flags)) {
11896 flow = "ON - receive & transmit";
11897 } else if (bxe_test_bit(BXE_LINK_REPORT_RX_FC_ON,
11898 &cur_data.link_report_flags) &&
11899 !bxe_test_bit(BXE_LINK_REPORT_TX_FC_ON,
11900 &cur_data.link_report_flags)) {
11901 flow = "ON - receive";
11902 } else if (!bxe_test_bit(BXE_LINK_REPORT_RX_FC_ON,
11903 &cur_data.link_report_flags) &&
11904 bxe_test_bit(BXE_LINK_REPORT_TX_FC_ON,
11905 &cur_data.link_report_flags)) {
11906 flow = "ON - transmit";
11908 flow = "none"; /* possible? */
11914 if_link_state_change(sc->ifnet, LINK_STATE_UP);
11915 BLOGI(sc, "NIC Link is Up, %d Mbps %s duplex, Flow control: %s\n",
11916 cur_data.line_speed, duplex, flow);
11921 bxe_link_report(struct bxe_softc *sc)
11923 bxe_acquire_phy_lock(sc);
11924 bxe_link_report_locked(sc);
11925 bxe_release_phy_lock(sc);
11929 bxe_link_status_update(struct bxe_softc *sc)
11931 if (sc->state != BXE_STATE_OPEN) {
11935 if (IS_PF(sc) && !CHIP_REV_IS_SLOW(sc)) {
11936 elink_link_status_update(&sc->link_params, &sc->link_vars);
11938 sc->port.supported[0] |= (ELINK_SUPPORTED_10baseT_Half |
11939 ELINK_SUPPORTED_10baseT_Full |
11940 ELINK_SUPPORTED_100baseT_Half |
11941 ELINK_SUPPORTED_100baseT_Full |
11942 ELINK_SUPPORTED_1000baseT_Full |
11943 ELINK_SUPPORTED_2500baseX_Full |
11944 ELINK_SUPPORTED_10000baseT_Full |
11945 ELINK_SUPPORTED_TP |
11946 ELINK_SUPPORTED_FIBRE |
11947 ELINK_SUPPORTED_Autoneg |
11948 ELINK_SUPPORTED_Pause |
11949 ELINK_SUPPORTED_Asym_Pause);
11950 sc->port.advertising[0] = sc->port.supported[0];
11952 sc->link_params.sc = sc;
11953 sc->link_params.port = SC_PORT(sc);
11954 sc->link_params.req_duplex[0] = DUPLEX_FULL;
11955 sc->link_params.req_flow_ctrl[0] = ELINK_FLOW_CTRL_NONE;
11956 sc->link_params.req_line_speed[0] = SPEED_10000;
11957 sc->link_params.speed_cap_mask[0] = 0x7f0000;
11958 sc->link_params.switch_cfg = ELINK_SWITCH_CFG_10G;
11960 if (CHIP_REV_IS_FPGA(sc)) {
11961 sc->link_vars.mac_type = ELINK_MAC_TYPE_EMAC;
11962 sc->link_vars.line_speed = ELINK_SPEED_1000;
11963 sc->link_vars.link_status = (LINK_STATUS_LINK_UP |
11964 LINK_STATUS_SPEED_AND_DUPLEX_1000TFD);
11966 sc->link_vars.mac_type = ELINK_MAC_TYPE_BMAC;
11967 sc->link_vars.line_speed = ELINK_SPEED_10000;
11968 sc->link_vars.link_status = (LINK_STATUS_LINK_UP |
11969 LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
11972 sc->link_vars.link_up = 1;
11974 sc->link_vars.duplex = DUPLEX_FULL;
11975 sc->link_vars.flow_ctrl = ELINK_FLOW_CTRL_NONE;
11978 REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + sc->link_params.port*4, 0);
11979 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
11980 bxe_link_report(sc);
11985 if (sc->link_vars.link_up) {
11986 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
11988 bxe_stats_handle(sc, STATS_EVENT_STOP);
11990 bxe_link_report(sc);
11992 bxe_link_report(sc);
11993 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
11998 bxe_initial_phy_init(struct bxe_softc *sc,
12001 int rc, cfg_idx = bxe_get_link_cfg_idx(sc);
12002 uint16_t req_line_speed = sc->link_params.req_line_speed[cfg_idx];
12003 struct elink_params *lp = &sc->link_params;
12005 bxe_set_requested_fc(sc);
12007 if (CHIP_REV_IS_SLOW(sc)) {
12008 uint32_t bond = CHIP_BOND_ID(sc);
12011 if (CHIP_IS_E2(sc) && CHIP_IS_MODE_4_PORT(sc)) {
12012 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_BMAC;
12013 } else if (bond & 0x4) {
12014 if (CHIP_IS_E3(sc)) {
12015 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_XMAC;
12017 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_BMAC;
12019 } else if (bond & 0x8) {
12020 if (CHIP_IS_E3(sc)) {
12021 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_UMAC;
12023 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_EMAC;
12027 /* disable EMAC for E3 and above */
12029 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_EMAC;
12032 sc->link_params.feature_config_flags |= feat;
12035 bxe_acquire_phy_lock(sc);
12037 if (load_mode == LOAD_DIAG) {
12038 lp->loopback_mode = ELINK_LOOPBACK_XGXS;
12039 /* Prefer doing PHY loopback at 10G speed, if possible */
12040 if (lp->req_line_speed[cfg_idx] < ELINK_SPEED_10000) {
12041 if (lp->speed_cap_mask[cfg_idx] &
12042 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) {
12043 lp->req_line_speed[cfg_idx] = ELINK_SPEED_10000;
12045 lp->req_line_speed[cfg_idx] = ELINK_SPEED_1000;
12050 if (load_mode == LOAD_LOOPBACK_EXT) {
12051 lp->loopback_mode = ELINK_LOOPBACK_EXT;
12054 rc = elink_phy_init(&sc->link_params, &sc->link_vars);
12056 bxe_release_phy_lock(sc);
12058 bxe_calc_fc_adv(sc);
12060 if (sc->link_vars.link_up) {
12061 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
12062 bxe_link_report(sc);
12065 if (!CHIP_REV_IS_SLOW(sc)) {
12066 bxe_periodic_start(sc);
12069 sc->link_params.req_line_speed[cfg_idx] = req_line_speed;
12073 /* must be called under IF_ADDR_LOCK */
12075 bxe_init_mcast_macs_list(struct bxe_softc *sc,
12076 struct ecore_mcast_ramrod_params *p)
12078 struct ifnet *ifp = sc->ifnet;
12080 struct ifmultiaddr *ifma;
12081 struct ecore_mcast_list_elem *mc_mac;
12083 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
12084 if (ifma->ifma_addr->sa_family != AF_LINK) {
12091 ECORE_LIST_INIT(&p->mcast_list);
12092 p->mcast_list_len = 0;
12098 mc_mac = malloc(sizeof(*mc_mac) * mc_count, M_DEVBUF,
12099 (M_NOWAIT | M_ZERO));
12101 BLOGE(sc, "Failed to allocate temp mcast list\n");
12104 bzero(mc_mac, (sizeof(*mc_mac) * mc_count));
12106 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
12107 if (ifma->ifma_addr->sa_family != AF_LINK) {
12111 mc_mac->mac = (uint8_t *)LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
12112 ECORE_LIST_PUSH_TAIL(&mc_mac->link, &p->mcast_list);
12114 BLOGD(sc, DBG_LOAD,
12115 "Setting MCAST %02X:%02X:%02X:%02X:%02X:%02X and mc_count %d\n",
12116 mc_mac->mac[0], mc_mac->mac[1], mc_mac->mac[2],
12117 mc_mac->mac[3], mc_mac->mac[4], mc_mac->mac[5], mc_count);
12121 p->mcast_list_len = mc_count;
12128 bxe_free_mcast_macs_list(struct ecore_mcast_ramrod_params *p)
12130 struct ecore_mcast_list_elem *mc_mac =
12131 ECORE_LIST_FIRST_ENTRY(&p->mcast_list,
12132 struct ecore_mcast_list_elem,
12136 /* only a single free as all mc_macs are in the same heap array */
12137 free(mc_mac, M_DEVBUF);
12142 bxe_set_mc_list(struct bxe_softc *sc)
12144 struct ecore_mcast_ramrod_params rparam = { NULL };
12147 rparam.mcast_obj = &sc->mcast_obj;
12149 BXE_MCAST_LOCK(sc);
12151 /* first, clear all configured multicast MACs */
12152 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL);
12154 BLOGE(sc, "Failed to clear multicast configuration: %d\n", rc);
12155 /* Manual backport parts of FreeBSD upstream r284470. */
12156 BXE_MCAST_UNLOCK(sc);
12160 /* configure a new MACs list */
12161 rc = bxe_init_mcast_macs_list(sc, &rparam);
12163 BLOGE(sc, "Failed to create mcast MACs list (%d)\n", rc);
12164 BXE_MCAST_UNLOCK(sc);
12168 /* Now add the new MACs */
12169 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_ADD);
12171 BLOGE(sc, "Failed to set new mcast config (%d)\n", rc);
12174 bxe_free_mcast_macs_list(&rparam);
12176 BXE_MCAST_UNLOCK(sc);
12182 bxe_set_uc_list(struct bxe_softc *sc)
12184 struct ifnet *ifp = sc->ifnet;
12185 struct ecore_vlan_mac_obj *mac_obj = &sc->sp_objs->mac_obj;
12186 struct ifaddr *ifa;
12187 unsigned long ramrod_flags = 0;
12190 #if __FreeBSD_version < 800000
12193 if_addr_rlock(ifp);
12196 /* first schedule a cleanup up of old configuration */
12197 rc = bxe_del_all_macs(sc, mac_obj, ECORE_UC_LIST_MAC, FALSE);
12199 BLOGE(sc, "Failed to schedule delete of all ETH MACs (%d)\n", rc);
12200 #if __FreeBSD_version < 800000
12201 IF_ADDR_UNLOCK(ifp);
12203 if_addr_runlock(ifp);
12208 ifa = ifp->if_addr;
12210 if (ifa->ifa_addr->sa_family != AF_LINK) {
12211 ifa = TAILQ_NEXT(ifa, ifa_link);
12215 rc = bxe_set_mac_one(sc, (uint8_t *)LLADDR((struct sockaddr_dl *)ifa->ifa_addr),
12216 mac_obj, TRUE, ECORE_UC_LIST_MAC, &ramrod_flags);
12217 if (rc == -EEXIST) {
12218 BLOGD(sc, DBG_SP, "Failed to schedule ADD operations (EEXIST)\n");
12219 /* do not treat adding same MAC as an error */
12221 } else if (rc < 0) {
12222 BLOGE(sc, "Failed to schedule ADD operations (%d)\n", rc);
12223 #if __FreeBSD_version < 800000
12224 IF_ADDR_UNLOCK(ifp);
12226 if_addr_runlock(ifp);
12231 ifa = TAILQ_NEXT(ifa, ifa_link);
12234 #if __FreeBSD_version < 800000
12235 IF_ADDR_UNLOCK(ifp);
12237 if_addr_runlock(ifp);
12240 /* Execute the pending commands */
12241 bit_set(&ramrod_flags, RAMROD_CONT);
12242 return (bxe_set_mac_one(sc, NULL, mac_obj, FALSE /* don't care */,
12243 ECORE_UC_LIST_MAC, &ramrod_flags));
12247 bxe_set_rx_mode(struct bxe_softc *sc)
12249 struct ifnet *ifp = sc->ifnet;
12250 uint32_t rx_mode = BXE_RX_MODE_NORMAL;
12252 if (sc->state != BXE_STATE_OPEN) {
12253 BLOGD(sc, DBG_SP, "state is %x, returning\n", sc->state);
12257 BLOGD(sc, DBG_SP, "ifp->if_flags=0x%x\n", ifp->if_flags);
12259 if (ifp->if_flags & IFF_PROMISC) {
12260 rx_mode = BXE_RX_MODE_PROMISC;
12261 } else if ((ifp->if_flags & IFF_ALLMULTI) ||
12262 ((ifp->if_amcount > BXE_MAX_MULTICAST) &&
12264 rx_mode = BXE_RX_MODE_ALLMULTI;
12267 /* some multicasts */
12268 if (bxe_set_mc_list(sc) < 0) {
12269 rx_mode = BXE_RX_MODE_ALLMULTI;
12271 if (bxe_set_uc_list(sc) < 0) {
12272 rx_mode = BXE_RX_MODE_PROMISC;
12277 sc->rx_mode = rx_mode;
12279 /* schedule the rx_mode command */
12280 if (bxe_test_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state)) {
12281 BLOGD(sc, DBG_LOAD, "Scheduled setting rx_mode with ECORE...\n");
12282 bxe_set_bit(ECORE_FILTER_RX_MODE_SCHED, &sc->sp_state);
12287 bxe_set_storm_rx_mode(sc);
12292 /* update flags in shmem */
12294 bxe_update_drv_flags(struct bxe_softc *sc,
12298 uint32_t drv_flags;
12300 if (SHMEM2_HAS(sc, drv_flags)) {
12301 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_DRV_FLAGS);
12302 drv_flags = SHMEM2_RD(sc, drv_flags);
12305 SET_FLAGS(drv_flags, flags);
12307 RESET_FLAGS(drv_flags, flags);
12310 SHMEM2_WR(sc, drv_flags, drv_flags);
12311 BLOGD(sc, DBG_LOAD, "drv_flags 0x%08x\n", drv_flags);
12313 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_DRV_FLAGS);
12317 /* periodic timer callout routine, only runs when the interface is up */
12320 bxe_periodic_callout_func(void *xsc)
12322 struct bxe_softc *sc = (struct bxe_softc *)xsc;
12325 if (!BXE_CORE_TRYLOCK(sc)) {
12326 /* just bail and try again next time */
12328 if ((sc->state == BXE_STATE_OPEN) &&
12329 (atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_GO)) {
12330 /* schedule the next periodic callout */
12331 callout_reset(&sc->periodic_callout, hz,
12332 bxe_periodic_callout_func, sc);
12338 if ((sc->state != BXE_STATE_OPEN) ||
12339 (atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_STOP)) {
12340 BLOGW(sc, "periodic callout exit (state=0x%x)\n", sc->state);
12341 BXE_CORE_UNLOCK(sc);
12346 /* Check for TX timeouts on any fastpath. */
12347 FOR_EACH_QUEUE(sc, i) {
12348 if (bxe_watchdog(sc, &sc->fp[i]) != 0) {
12349 /* Ruh-Roh, chip was reset! */
12354 if (!CHIP_REV_IS_SLOW(sc)) {
12356 * This barrier is needed to ensure the ordering between the writing
12357 * to the sc->port.pmf in the bxe_nic_load() or bxe_pmf_update() and
12358 * the reading here.
12361 if (sc->port.pmf) {
12362 bxe_acquire_phy_lock(sc);
12363 elink_period_func(&sc->link_params, &sc->link_vars);
12364 bxe_release_phy_lock(sc);
12368 if (IS_PF(sc) && !(sc->flags & BXE_NO_PULSE)) {
12369 int mb_idx = SC_FW_MB_IDX(sc);
12370 uint32_t drv_pulse;
12371 uint32_t mcp_pulse;
12373 ++sc->fw_drv_pulse_wr_seq;
12374 sc->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
12376 drv_pulse = sc->fw_drv_pulse_wr_seq;
12379 mcp_pulse = (SHMEM_RD(sc, func_mb[mb_idx].mcp_pulse_mb) &
12380 MCP_PULSE_SEQ_MASK);
12383 * The delta between driver pulse and mcp response should
12384 * be 1 (before mcp response) or 0 (after mcp response).
12386 if ((drv_pulse != mcp_pulse) &&
12387 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
12388 /* someone lost a heartbeat... */
12389 BLOGE(sc, "drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
12390 drv_pulse, mcp_pulse);
12394 /* state is BXE_STATE_OPEN */
12395 bxe_stats_handle(sc, STATS_EVENT_UPDATE);
12397 BXE_CORE_UNLOCK(sc);
12399 if ((sc->state == BXE_STATE_OPEN) &&
12400 (atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_GO)) {
12401 /* schedule the next periodic callout */
12402 callout_reset(&sc->periodic_callout, hz,
12403 bxe_periodic_callout_func, sc);
12408 bxe_periodic_start(struct bxe_softc *sc)
12410 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_GO);
12411 callout_reset(&sc->periodic_callout, hz, bxe_periodic_callout_func, sc);
12415 bxe_periodic_stop(struct bxe_softc *sc)
12417 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_STOP);
12418 callout_drain(&sc->periodic_callout);
12422 bxe_parity_recover(struct bxe_softc *sc)
12424 uint8_t global = FALSE;
12425 uint32_t error_recovered, error_unrecovered;
12429 if ((sc->recovery_state == BXE_RECOVERY_FAILED) &&
12430 (sc->state == BXE_STATE_ERROR)) {
12431 BLOGE(sc, "RECOVERY failed, "
12432 "stack notified driver is NOT running! "
12433 "Please reboot/power cycle the system.\n");
12439 "%s sc=%p state=0x%x rec_state=0x%x error_status=%x\n",
12440 __func__, sc, sc->state, sc->recovery_state, sc->error_status);
12442 switch(sc->recovery_state) {
12444 case BXE_RECOVERY_INIT:
12445 is_parity = bxe_chk_parity_attn(sc, &global, FALSE);
12447 if ((CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ||
12448 (sc->error_status & BXE_ERR_MCP_ASSERT) ||
12449 (sc->error_status & BXE_ERR_GLOBAL)) {
12452 if (sc->ifnet->if_drv_flags & IFF_DRV_RUNNING) {
12453 bxe_periodic_stop(sc);
12455 bxe_nic_unload(sc, UNLOAD_RECOVERY, false);
12456 sc->state = BXE_STATE_ERROR;
12457 sc->recovery_state = BXE_RECOVERY_FAILED;
12458 BLOGE(sc, " No Recovery tried for error 0x%x"
12459 " stack notified driver is NOT running!"
12460 " Please reboot/power cycle the system.\n",
12462 BXE_CORE_UNLOCK(sc);
12467 /* Try to get a LEADER_LOCK HW lock */
12468 if (bxe_trylock_leader_lock(sc)) {
12470 bxe_set_reset_in_progress(sc);
12472 * Check if there is a global attention and if
12473 * there was a global attention, set the global
12477 bxe_set_reset_global(sc);
12482 /* If interface has been removed - break */
12484 if (sc->ifnet->if_drv_flags & IFF_DRV_RUNNING) {
12485 bxe_periodic_stop(sc);
12489 bxe_nic_unload(sc,UNLOAD_RECOVERY, false);
12490 sc->recovery_state = BXE_RECOVERY_WAIT;
12491 BXE_CORE_UNLOCK(sc);
12494 * Ensure "is_leader", MCP command sequence and
12495 * "recovery_state" update values are seen on other
12500 case BXE_RECOVERY_WAIT:
12502 if (sc->is_leader) {
12503 int other_engine = SC_PATH(sc) ? 0 : 1;
12504 bool other_load_status =
12505 bxe_get_load_status(sc, other_engine);
12507 bxe_get_load_status(sc, SC_PATH(sc));
12508 global = bxe_reset_is_global(sc);
12511 * In case of a parity in a global block, let
12512 * the first leader that performs a
12513 * leader_reset() reset the global blocks in
12514 * order to clear global attentions. Otherwise
12515 * the gates will remain closed for that
12519 (global && other_load_status)) {
12521 * Wait until all other functions get
12524 taskqueue_enqueue_timeout(taskqueue_thread,
12525 &sc->sp_err_timeout_task, hz/10);
12529 * If all other functions got down
12530 * try to bring the chip back to
12531 * normal. In any case it's an exit
12532 * point for a leader.
12534 if (bxe_leader_reset(sc)) {
12535 BLOGE(sc, "RECOVERY failed, "
12536 "stack notified driver is NOT running!\n");
12537 sc->recovery_state = BXE_RECOVERY_FAILED;
12538 sc->state = BXE_STATE_ERROR;
12544 * If we are here, means that the
12545 * leader has succeeded and doesn't
12546 * want to be a leader any more. Try
12547 * to continue as a none-leader.
12552 } else { /* non-leader */
12553 if (!bxe_reset_is_done(sc, SC_PATH(sc))) {
12555 * Try to get a LEADER_LOCK HW lock as
12556 * long as a former leader may have
12557 * been unloaded by the user or
12558 * released a leadership by another
12561 if (bxe_trylock_leader_lock(sc)) {
12563 * I'm a leader now! Restart a
12570 taskqueue_enqueue_timeout(taskqueue_thread,
12571 &sc->sp_err_timeout_task, hz/10);
12576 * If there was a global attention, wait
12577 * for it to be cleared.
12579 if (bxe_reset_is_global(sc)) {
12580 taskqueue_enqueue_timeout(taskqueue_thread,
12581 &sc->sp_err_timeout_task, hz/10);
12586 sc->eth_stats.recoverable_error;
12587 error_unrecovered =
12588 sc->eth_stats.unrecoverable_error;
12590 sc->recovery_state =
12591 BXE_RECOVERY_NIC_LOADING;
12592 if (bxe_nic_load(sc, LOAD_NORMAL)) {
12593 error_unrecovered++;
12594 sc->recovery_state = BXE_RECOVERY_FAILED;
12595 sc->state = BXE_STATE_ERROR;
12596 BLOGE(sc, "Recovery is NOT successfull, "
12597 " state=0x%x recovery_state=0x%x error=%x\n",
12598 sc->state, sc->recovery_state, sc->error_status);
12599 sc->error_status = 0;
12601 sc->recovery_state =
12604 BLOGI(sc, "Recovery is successfull from errors %x,"
12606 " recovery_state=0x%x \n", sc->error_status,
12607 sc->state, sc->recovery_state);
12610 sc->error_status = 0;
12611 BXE_CORE_UNLOCK(sc);
12612 sc->eth_stats.recoverable_error =
12614 sc->eth_stats.unrecoverable_error =
12626 bxe_handle_error(struct bxe_softc * sc)
12629 if(sc->recovery_state == BXE_RECOVERY_WAIT) {
12632 if(sc->error_status) {
12633 if (sc->state == BXE_STATE_OPEN) {
12634 bxe_int_disable(sc);
12636 if (sc->link_vars.link_up) {
12637 if_link_state_change(sc->ifnet, LINK_STATE_DOWN);
12639 sc->recovery_state = BXE_RECOVERY_INIT;
12640 BLOGI(sc, "bxe%d: Recovery started errors 0x%x recovery state 0x%x\n",
12641 sc->unit, sc->error_status, sc->recovery_state);
12642 bxe_parity_recover(sc);
12647 bxe_sp_err_timeout_task(void *arg, int pending)
12650 struct bxe_softc *sc = (struct bxe_softc *)arg;
12653 "%s state = 0x%x rec state=0x%x error_status=%x\n",
12654 __func__, sc->state, sc->recovery_state, sc->error_status);
12656 if((sc->recovery_state == BXE_RECOVERY_FAILED) &&
12657 (sc->state == BXE_STATE_ERROR)) {
12660 /* if can be taken */
12661 if ((sc->error_status) && (sc->trigger_grcdump)) {
12664 if (sc->recovery_state != BXE_RECOVERY_DONE) {
12665 bxe_handle_error(sc);
12666 bxe_parity_recover(sc);
12667 } else if (sc->error_status) {
12668 bxe_handle_error(sc);
12674 /* start the controller */
12675 static __noinline int
12676 bxe_nic_load(struct bxe_softc *sc,
12683 BXE_CORE_LOCK_ASSERT(sc);
12685 BLOGD(sc, DBG_LOAD, "Starting NIC load...\n");
12687 sc->state = BXE_STATE_OPENING_WAITING_LOAD;
12690 /* must be called before memory allocation and HW init */
12691 bxe_ilt_set_info(sc);
12694 sc->last_reported_link_state = LINK_STATE_UNKNOWN;
12696 bxe_set_fp_rx_buf_size(sc);
12698 if (bxe_alloc_fp_buffers(sc) != 0) {
12699 BLOGE(sc, "Failed to allocate fastpath memory\n");
12700 sc->state = BXE_STATE_CLOSED;
12702 goto bxe_nic_load_error0;
12705 if (bxe_alloc_mem(sc) != 0) {
12706 sc->state = BXE_STATE_CLOSED;
12708 goto bxe_nic_load_error0;
12711 if (bxe_alloc_fw_stats_mem(sc) != 0) {
12712 sc->state = BXE_STATE_CLOSED;
12714 goto bxe_nic_load_error0;
12718 /* set pf load just before approaching the MCP */
12719 bxe_set_pf_load(sc);
12721 /* if MCP exists send load request and analyze response */
12722 if (!BXE_NOMCP(sc)) {
12723 /* attempt to load pf */
12724 if (bxe_nic_load_request(sc, &load_code) != 0) {
12725 sc->state = BXE_STATE_CLOSED;
12727 goto bxe_nic_load_error1;
12730 /* what did the MCP say? */
12731 if (bxe_nic_load_analyze_req(sc, load_code) != 0) {
12732 bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
12733 sc->state = BXE_STATE_CLOSED;
12735 goto bxe_nic_load_error2;
12738 BLOGI(sc, "Device has no MCP!\n");
12739 load_code = bxe_nic_load_no_mcp(sc);
12742 /* mark PMF if applicable */
12743 bxe_nic_load_pmf(sc, load_code);
12745 /* Init Function state controlling object */
12746 bxe_init_func_obj(sc);
12748 /* Initialize HW */
12749 if (bxe_init_hw(sc, load_code) != 0) {
12750 BLOGE(sc, "HW init failed\n");
12751 bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
12752 sc->state = BXE_STATE_CLOSED;
12754 goto bxe_nic_load_error2;
12758 /* set ALWAYS_ALIVE bit in shmem */
12759 sc->fw_drv_pulse_wr_seq |= DRV_PULSE_ALWAYS_ALIVE;
12761 sc->flags |= BXE_NO_PULSE;
12763 /* attach interrupts */
12764 if (bxe_interrupt_attach(sc) != 0) {
12765 sc->state = BXE_STATE_CLOSED;
12767 goto bxe_nic_load_error2;
12770 bxe_nic_init(sc, load_code);
12772 /* Init per-function objects */
12775 // XXX bxe_iov_nic_init(sc);
12777 /* set AFEX default VLAN tag to an invalid value */
12778 sc->devinfo.mf_info.afex_def_vlan_tag = -1;
12779 // XXX bxe_nic_load_afex_dcc(sc, load_code);
12781 sc->state = BXE_STATE_OPENING_WAITING_PORT;
12782 rc = bxe_func_start(sc);
12784 BLOGE(sc, "Function start failed! rc = %d\n", rc);
12785 bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
12786 sc->state = BXE_STATE_ERROR;
12787 goto bxe_nic_load_error3;
12790 /* send LOAD_DONE command to MCP */
12791 if (!BXE_NOMCP(sc)) {
12792 load_code = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
12794 BLOGE(sc, "MCP response failure, aborting\n");
12795 sc->state = BXE_STATE_ERROR;
12797 goto bxe_nic_load_error3;
12801 rc = bxe_setup_leading(sc);
12803 BLOGE(sc, "Setup leading failed! rc = %d\n", rc);
12804 sc->state = BXE_STATE_ERROR;
12805 goto bxe_nic_load_error3;
12808 FOR_EACH_NONDEFAULT_ETH_QUEUE(sc, i) {
12809 rc = bxe_setup_queue(sc, &sc->fp[i], FALSE);
12811 BLOGE(sc, "Queue(%d) setup failed rc = %d\n", i, rc);
12812 sc->state = BXE_STATE_ERROR;
12813 goto bxe_nic_load_error3;
12817 rc = bxe_init_rss_pf(sc);
12819 BLOGE(sc, "PF RSS init failed\n");
12820 sc->state = BXE_STATE_ERROR;
12821 goto bxe_nic_load_error3;
12826 /* now when Clients are configured we are ready to work */
12827 sc->state = BXE_STATE_OPEN;
12829 /* Configure a ucast MAC */
12831 rc = bxe_set_eth_mac(sc, TRUE);
12834 BLOGE(sc, "Setting Ethernet MAC failed rc = %d\n", rc);
12835 sc->state = BXE_STATE_ERROR;
12836 goto bxe_nic_load_error3;
12839 if (sc->port.pmf) {
12840 rc = bxe_initial_phy_init(sc, /* XXX load_mode */LOAD_OPEN);
12842 sc->state = BXE_STATE_ERROR;
12843 goto bxe_nic_load_error3;
12847 sc->link_params.feature_config_flags &=
12848 ~ELINK_FEATURE_CONFIG_BOOT_FROM_SAN;
12850 /* start fast path */
12852 /* Initialize Rx filter */
12853 bxe_set_rx_mode(sc);
12856 switch (/* XXX load_mode */LOAD_OPEN) {
12862 case LOAD_LOOPBACK_EXT:
12863 sc->state = BXE_STATE_DIAG;
12870 if (sc->port.pmf) {
12871 bxe_update_drv_flags(sc, 1 << DRV_FLAGS_PORT_MASK, 0);
12873 bxe_link_status_update(sc);
12876 /* start the periodic timer callout */
12877 bxe_periodic_start(sc);
12879 if (IS_PF(sc) && SHMEM2_HAS(sc, drv_capabilities_flag)) {
12880 /* mark driver is loaded in shmem2 */
12881 val = SHMEM2_RD(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)]);
12882 SHMEM2_WR(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)],
12884 DRV_FLAGS_CAPABILITIES_LOADED_SUPPORTED |
12885 DRV_FLAGS_CAPABILITIES_LOADED_L2));
12888 /* wait for all pending SP commands to complete */
12889 if (IS_PF(sc) && !bxe_wait_sp_comp(sc, ~0x0UL)) {
12890 BLOGE(sc, "Timeout waiting for all SPs to complete!\n");
12891 bxe_periodic_stop(sc);
12892 bxe_nic_unload(sc, UNLOAD_CLOSE, FALSE);
12896 /* Tell the stack the driver is running! */
12897 sc->ifnet->if_drv_flags = IFF_DRV_RUNNING;
12899 BLOGD(sc, DBG_LOAD, "NIC successfully loaded\n");
12903 bxe_nic_load_error3:
12906 bxe_int_disable_sync(sc, 1);
12908 /* clean out queued objects */
12909 bxe_squeeze_objects(sc);
12912 bxe_interrupt_detach(sc);
12914 bxe_nic_load_error2:
12916 if (IS_PF(sc) && !BXE_NOMCP(sc)) {
12917 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
12918 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, 0);
12923 bxe_nic_load_error1:
12925 /* clear pf_load status, as it was already set */
12927 bxe_clear_pf_load(sc);
12930 bxe_nic_load_error0:
12932 bxe_free_fw_stats_mem(sc);
12933 bxe_free_fp_buffers(sc);
12940 bxe_init_locked(struct bxe_softc *sc)
12942 int other_engine = SC_PATH(sc) ? 0 : 1;
12943 uint8_t other_load_status, load_status;
12944 uint8_t global = FALSE;
12947 BXE_CORE_LOCK_ASSERT(sc);
12949 /* check if the driver is already running */
12950 if (sc->ifnet->if_drv_flags & IFF_DRV_RUNNING) {
12951 BLOGD(sc, DBG_LOAD, "Init called while driver is running!\n");
12955 if((sc->state == BXE_STATE_ERROR) &&
12956 (sc->recovery_state == BXE_RECOVERY_FAILED)) {
12957 BLOGE(sc, "Initialization not done, "
12958 "as previous recovery failed."
12959 "Reboot/Power-cycle the system\n" );
12964 bxe_set_power_state(sc, PCI_PM_D0);
12967 * If parity occurred during the unload, then attentions and/or
12968 * RECOVERY_IN_PROGRES may still be set. If so we want the first function
12969 * loaded on the current engine to complete the recovery. Parity recovery
12970 * is only relevant for PF driver.
12973 other_load_status = bxe_get_load_status(sc, other_engine);
12974 load_status = bxe_get_load_status(sc, SC_PATH(sc));
12976 if (!bxe_reset_is_done(sc, SC_PATH(sc)) ||
12977 bxe_chk_parity_attn(sc, &global, TRUE)) {
12980 * If there are attentions and they are in global blocks, set
12981 * the GLOBAL_RESET bit regardless whether it will be this
12982 * function that will complete the recovery or not.
12985 bxe_set_reset_global(sc);
12989 * Only the first function on the current engine should try
12990 * to recover in open. In case of attentions in global blocks
12991 * only the first in the chip should try to recover.
12993 if ((!load_status && (!global || !other_load_status)) &&
12994 bxe_trylock_leader_lock(sc) && !bxe_leader_reset(sc)) {
12995 BLOGI(sc, "Recovered during init\n");
12999 /* recovery has failed... */
13000 bxe_set_power_state(sc, PCI_PM_D3hot);
13001 sc->recovery_state = BXE_RECOVERY_FAILED;
13003 BLOGE(sc, "Recovery flow hasn't properly "
13004 "completed yet, try again later. "
13005 "If you still see this message after a "
13006 "few retries then power cycle is required.\n");
13009 goto bxe_init_locked_done;
13014 sc->recovery_state = BXE_RECOVERY_DONE;
13016 rc = bxe_nic_load(sc, LOAD_OPEN);
13018 bxe_init_locked_done:
13021 /* Tell the stack the driver is NOT running! */
13022 BLOGE(sc, "Initialization failed, "
13023 "stack notified driver is NOT running!\n");
13024 sc->ifnet->if_drv_flags &= ~IFF_DRV_RUNNING;
13031 bxe_stop_locked(struct bxe_softc *sc)
13033 BXE_CORE_LOCK_ASSERT(sc);
13034 return (bxe_nic_unload(sc, UNLOAD_NORMAL, TRUE));
13038 * Handles controller initialization when called from an unlocked routine.
13039 * ifconfig calls this function.
13045 bxe_init(void *xsc)
13047 struct bxe_softc *sc = (struct bxe_softc *)xsc;
13050 bxe_init_locked(sc);
13051 BXE_CORE_UNLOCK(sc);
13055 bxe_init_ifnet(struct bxe_softc *sc)
13059 /* ifconfig entrypoint for media type/status reporting */
13060 ifmedia_init(&sc->ifmedia, IFM_IMASK,
13061 bxe_ifmedia_update,
13062 bxe_ifmedia_status);
13064 /* set the default interface values */
13065 ifmedia_add(&sc->ifmedia, (IFM_ETHER | IFM_FDX | sc->media), 0, NULL);
13066 ifmedia_add(&sc->ifmedia, (IFM_ETHER | IFM_AUTO), 0, NULL);
13067 ifmedia_set(&sc->ifmedia, (IFM_ETHER | IFM_AUTO));
13069 sc->ifmedia.ifm_media = sc->ifmedia.ifm_cur->ifm_media; /* XXX ? */
13070 BLOGI(sc, "IFMEDIA flags : %x\n", sc->ifmedia.ifm_media);
13072 /* allocate the ifnet structure */
13073 if ((ifp = if_alloc(IFT_ETHER)) == NULL) {
13074 BLOGE(sc, "Interface allocation failed!\n");
13078 ifp->if_softc = sc;
13079 if_initname(ifp, device_get_name(sc->dev), device_get_unit(sc->dev));
13080 ifp->if_flags = (IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
13081 ifp->if_ioctl = bxe_ioctl;
13082 ifp->if_start = bxe_tx_start;
13083 #if __FreeBSD_version >= 901504
13084 ifp->if_transmit = bxe_tx_mq_start;
13085 ifp->if_qflush = bxe_mq_flush;
13090 ifp->if_init = bxe_init;
13091 ifp->if_mtu = sc->mtu;
13092 ifp->if_hwassist = (CSUM_IP |
13098 ifp->if_capabilities =
13099 #if __FreeBSD_version < 700000
13101 IFCAP_VLAN_HWTAGGING |
13107 IFCAP_VLAN_HWTAGGING |
13109 IFCAP_VLAN_HWFILTER |
13110 IFCAP_VLAN_HWCSUM |
13118 ifp->if_capenable = ifp->if_capabilities;
13119 ifp->if_capenable &= ~IFCAP_WOL_MAGIC; /* XXX not yet... */
13120 #if __FreeBSD_version < 1000025
13121 ifp->if_baudrate = 1000000000;
13123 if_initbaudrate(ifp, IF_Gbps(10));
13125 ifp->if_snd.ifq_drv_maxlen = sc->tx_ring_size;
13127 IFQ_SET_MAXLEN(&ifp->if_snd, ifp->if_snd.ifq_drv_maxlen);
13128 IFQ_SET_READY(&ifp->if_snd);
13132 /* attach to the Ethernet interface list */
13133 ether_ifattach(ifp, sc->link_params.mac_addr);
13139 bxe_deallocate_bars(struct bxe_softc *sc)
13143 for (i = 0; i < MAX_BARS; i++) {
13144 if (sc->bar[i].resource != NULL) {
13145 bus_release_resource(sc->dev,
13148 sc->bar[i].resource);
13149 BLOGD(sc, DBG_LOAD, "Released PCI BAR%d [%02x] memory\n",
13156 bxe_allocate_bars(struct bxe_softc *sc)
13161 memset(sc->bar, 0, sizeof(sc->bar));
13163 for (i = 0; i < MAX_BARS; i++) {
13165 /* memory resources reside at BARs 0, 2, 4 */
13166 /* Run `pciconf -lb` to see mappings */
13167 if ((i != 0) && (i != 2) && (i != 4)) {
13171 sc->bar[i].rid = PCIR_BAR(i);
13175 flags |= RF_SHAREABLE;
13178 if ((sc->bar[i].resource =
13179 bus_alloc_resource_any(sc->dev,
13186 sc->bar[i].tag = rman_get_bustag(sc->bar[i].resource);
13187 sc->bar[i].handle = rman_get_bushandle(sc->bar[i].resource);
13188 sc->bar[i].kva = (vm_offset_t)rman_get_virtual(sc->bar[i].resource);
13190 BLOGI(sc, "PCI BAR%d [%02x] memory allocated: %p-%p (%ld) -> %p\n",
13192 (void *)rman_get_start(sc->bar[i].resource),
13193 (void *)rman_get_end(sc->bar[i].resource),
13194 rman_get_size(sc->bar[i].resource),
13195 (void *)sc->bar[i].kva);
13202 bxe_get_function_num(struct bxe_softc *sc)
13207 * Read the ME register to get the function number. The ME register
13208 * holds the relative-function number and absolute-function number. The
13209 * absolute-function number appears only in E2 and above. Before that
13210 * these bits always contained zero, therefore we cannot blindly use them.
13213 val = REG_RD(sc, BAR_ME_REGISTER);
13216 (uint8_t)((val & ME_REG_PF_NUM) >> ME_REG_PF_NUM_SHIFT);
13218 (uint8_t)((val & ME_REG_ABS_PF_NUM) >> ME_REG_ABS_PF_NUM_SHIFT) & 1;
13220 if (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) {
13221 sc->pfunc_abs = ((sc->pfunc_rel << 1) | sc->path_id);
13223 sc->pfunc_abs = (sc->pfunc_rel | sc->path_id);
13226 BLOGD(sc, DBG_LOAD,
13227 "Relative function %d, Absolute function %d, Path %d\n",
13228 sc->pfunc_rel, sc->pfunc_abs, sc->path_id);
13232 bxe_get_shmem_mf_cfg_base(struct bxe_softc *sc)
13234 uint32_t shmem2_size;
13236 uint32_t mf_cfg_offset_value;
13239 offset = (SHMEM_RD(sc, func_mb) +
13240 (MAX_FUNC_NUM * sizeof(struct drv_func_mb)));
13243 if (sc->devinfo.shmem2_base != 0) {
13244 shmem2_size = SHMEM2_RD(sc, size);
13245 if (shmem2_size > offsetof(struct shmem2_region, mf_cfg_addr)) {
13246 mf_cfg_offset_value = SHMEM2_RD(sc, mf_cfg_addr);
13247 if (SHMEM_MF_CFG_ADDR_NONE != mf_cfg_offset_value) {
13248 offset = mf_cfg_offset_value;
13257 bxe_pcie_capability_read(struct bxe_softc *sc,
13263 /* ensure PCIe capability is enabled */
13264 if (pci_find_cap(sc->dev, PCIY_EXPRESS, &pcie_reg) == 0) {
13265 if (pcie_reg != 0) {
13266 BLOGD(sc, DBG_LOAD, "PCIe capability at 0x%04x\n", pcie_reg);
13267 return (pci_read_config(sc->dev, (pcie_reg + reg), width));
13271 BLOGE(sc, "PCIe capability NOT FOUND!!!\n");
13277 bxe_is_pcie_pending(struct bxe_softc *sc)
13279 return (bxe_pcie_capability_read(sc, PCIR_EXPRESS_DEVICE_STA, 2) &
13280 PCIM_EXP_STA_TRANSACTION_PND);
13284 * Walk the PCI capabiites list for the device to find what features are
13285 * supported. These capabilites may be enabled/disabled by firmware so it's
13286 * best to walk the list rather than make assumptions.
13289 bxe_probe_pci_caps(struct bxe_softc *sc)
13291 uint16_t link_status;
13294 /* check if PCI Power Management is enabled */
13295 if (pci_find_cap(sc->dev, PCIY_PMG, ®) == 0) {
13297 BLOGD(sc, DBG_LOAD, "Found PM capability at 0x%04x\n", reg);
13299 sc->devinfo.pcie_cap_flags |= BXE_PM_CAPABLE_FLAG;
13300 sc->devinfo.pcie_pm_cap_reg = (uint16_t)reg;
13304 link_status = bxe_pcie_capability_read(sc, PCIR_EXPRESS_LINK_STA, 2);
13306 /* handle PCIe 2.0 workarounds for 57710 */
13307 if (CHIP_IS_E1(sc)) {
13308 /* workaround for 57710 errata E4_57710_27462 */
13309 sc->devinfo.pcie_link_speed =
13310 (REG_RD(sc, 0x3d04) & (1 << 24)) ? 2 : 1;
13312 /* workaround for 57710 errata E4_57710_27488 */
13313 sc->devinfo.pcie_link_width =
13314 ((link_status & PCIM_LINK_STA_WIDTH) >> 4);
13315 if (sc->devinfo.pcie_link_speed > 1) {
13316 sc->devinfo.pcie_link_width =
13317 ((link_status & PCIM_LINK_STA_WIDTH) >> 4) >> 1;
13320 sc->devinfo.pcie_link_speed =
13321 (link_status & PCIM_LINK_STA_SPEED);
13322 sc->devinfo.pcie_link_width =
13323 ((link_status & PCIM_LINK_STA_WIDTH) >> 4);
13326 BLOGD(sc, DBG_LOAD, "PCIe link speed=%d width=%d\n",
13327 sc->devinfo.pcie_link_speed, sc->devinfo.pcie_link_width);
13329 sc->devinfo.pcie_cap_flags |= BXE_PCIE_CAPABLE_FLAG;
13330 sc->devinfo.pcie_pcie_cap_reg = (uint16_t)reg;
13332 /* check if MSI capability is enabled */
13333 if (pci_find_cap(sc->dev, PCIY_MSI, ®) == 0) {
13335 BLOGD(sc, DBG_LOAD, "Found MSI capability at 0x%04x\n", reg);
13337 sc->devinfo.pcie_cap_flags |= BXE_MSI_CAPABLE_FLAG;
13338 sc->devinfo.pcie_msi_cap_reg = (uint16_t)reg;
13342 /* check if MSI-X capability is enabled */
13343 if (pci_find_cap(sc->dev, PCIY_MSIX, ®) == 0) {
13345 BLOGD(sc, DBG_LOAD, "Found MSI-X capability at 0x%04x\n", reg);
13347 sc->devinfo.pcie_cap_flags |= BXE_MSIX_CAPABLE_FLAG;
13348 sc->devinfo.pcie_msix_cap_reg = (uint16_t)reg;
13354 bxe_get_shmem_mf_cfg_info_sd(struct bxe_softc *sc)
13356 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13359 /* get the outer vlan if we're in switch-dependent mode */
13361 val = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag);
13362 mf_info->ext_id = (uint16_t)val;
13364 mf_info->multi_vnics_mode = 1;
13366 if (!VALID_OVLAN(mf_info->ext_id)) {
13367 BLOGE(sc, "Invalid VLAN (%d)\n", mf_info->ext_id);
13371 /* get the capabilities */
13372 if ((mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_PROTOCOL_MASK) ==
13373 FUNC_MF_CFG_PROTOCOL_ISCSI) {
13374 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_ISCSI;
13375 } else if ((mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_PROTOCOL_MASK) ==
13376 FUNC_MF_CFG_PROTOCOL_FCOE) {
13377 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_FCOE;
13379 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_ETHERNET;
13382 mf_info->vnics_per_port =
13383 (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4;
13389 bxe_get_shmem_ext_proto_support_flags(struct bxe_softc *sc)
13391 uint32_t retval = 0;
13394 val = MFCFG_RD(sc, func_ext_config[SC_ABS_FUNC(sc)].func_cfg);
13396 if (val & MACP_FUNC_CFG_FLAGS_ENABLED) {
13397 if (val & MACP_FUNC_CFG_FLAGS_ETHERNET) {
13398 retval |= MF_PROTO_SUPPORT_ETHERNET;
13400 if (val & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
13401 retval |= MF_PROTO_SUPPORT_ISCSI;
13403 if (val & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
13404 retval |= MF_PROTO_SUPPORT_FCOE;
13412 bxe_get_shmem_mf_cfg_info_si(struct bxe_softc *sc)
13414 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13418 * There is no outer vlan if we're in switch-independent mode.
13419 * If the mac is valid then assume multi-function.
13422 val = MFCFG_RD(sc, func_ext_config[SC_ABS_FUNC(sc)].func_cfg);
13424 mf_info->multi_vnics_mode = ((val & MACP_FUNC_CFG_FLAGS_MASK) != 0);
13426 mf_info->mf_protos_supported = bxe_get_shmem_ext_proto_support_flags(sc);
13428 mf_info->vnics_per_port =
13429 (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4;
13435 bxe_get_shmem_mf_cfg_info_niv(struct bxe_softc *sc)
13437 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13438 uint32_t e1hov_tag;
13439 uint32_t func_config;
13440 uint32_t niv_config;
13442 mf_info->multi_vnics_mode = 1;
13444 e1hov_tag = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag);
13445 func_config = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config);
13446 niv_config = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].afex_config);
13449 (uint16_t)((e1hov_tag & FUNC_MF_CFG_E1HOV_TAG_MASK) >>
13450 FUNC_MF_CFG_E1HOV_TAG_SHIFT);
13452 mf_info->default_vlan =
13453 (uint16_t)((e1hov_tag & FUNC_MF_CFG_AFEX_VLAN_MASK) >>
13454 FUNC_MF_CFG_AFEX_VLAN_SHIFT);
13456 mf_info->niv_allowed_priorities =
13457 (uint8_t)((niv_config & FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
13458 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT);
13460 mf_info->niv_default_cos =
13461 (uint8_t)((func_config & FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
13462 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT);
13464 mf_info->afex_vlan_mode =
13465 ((niv_config & FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
13466 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT);
13468 mf_info->niv_mba_enabled =
13469 ((niv_config & FUNC_MF_CFG_AFEX_MBA_ENABLED_MASK) >>
13470 FUNC_MF_CFG_AFEX_MBA_ENABLED_SHIFT);
13472 mf_info->mf_protos_supported = bxe_get_shmem_ext_proto_support_flags(sc);
13474 mf_info->vnics_per_port =
13475 (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4;
13481 bxe_check_valid_mf_cfg(struct bxe_softc *sc)
13483 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13490 BLOGD(sc, DBG_LOAD, "MF config parameters for function %d\n",
13492 BLOGD(sc, DBG_LOAD, "\tmf_config=0x%x\n",
13493 mf_info->mf_config[SC_VN(sc)]);
13494 BLOGD(sc, DBG_LOAD, "\tmulti_vnics_mode=%d\n",
13495 mf_info->multi_vnics_mode);
13496 BLOGD(sc, DBG_LOAD, "\tvnics_per_port=%d\n",
13497 mf_info->vnics_per_port);
13498 BLOGD(sc, DBG_LOAD, "\tovlan/vifid=%d\n",
13500 BLOGD(sc, DBG_LOAD, "\tmin_bw=%d/%d/%d/%d\n",
13501 mf_info->min_bw[0], mf_info->min_bw[1],
13502 mf_info->min_bw[2], mf_info->min_bw[3]);
13503 BLOGD(sc, DBG_LOAD, "\tmax_bw=%d/%d/%d/%d\n",
13504 mf_info->max_bw[0], mf_info->max_bw[1],
13505 mf_info->max_bw[2], mf_info->max_bw[3]);
13506 BLOGD(sc, DBG_LOAD, "\tmac_addr: %s\n",
13509 /* various MF mode sanity checks... */
13511 if (mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_FUNC_HIDE) {
13512 BLOGE(sc, "Enumerated function %d is marked as hidden\n",
13517 if ((mf_info->vnics_per_port > 1) && !mf_info->multi_vnics_mode) {
13518 BLOGE(sc, "vnics_per_port=%d multi_vnics_mode=%d\n",
13519 mf_info->vnics_per_port, mf_info->multi_vnics_mode);
13523 if (mf_info->mf_mode == MULTI_FUNCTION_SD) {
13524 /* vnic id > 0 must have valid ovlan in switch-dependent mode */
13525 if ((SC_VN(sc) > 0) && !VALID_OVLAN(OVLAN(sc))) {
13526 BLOGE(sc, "mf_mode=SD vnic_id=%d ovlan=%d\n",
13527 SC_VN(sc), OVLAN(sc));
13531 if (!VALID_OVLAN(OVLAN(sc)) && mf_info->multi_vnics_mode) {
13532 BLOGE(sc, "mf_mode=SD multi_vnics_mode=%d ovlan=%d\n",
13533 mf_info->multi_vnics_mode, OVLAN(sc));
13538 * Verify all functions are either MF or SF mode. If MF, make sure
13539 * sure that all non-hidden functions have a valid ovlan. If SF,
13540 * make sure that all non-hidden functions have an invalid ovlan.
13542 FOREACH_ABS_FUNC_IN_PORT(sc, i) {
13543 mf_cfg1 = MFCFG_RD(sc, func_mf_config[i].config);
13544 ovlan1 = MFCFG_RD(sc, func_mf_config[i].e1hov_tag);
13545 if (!(mf_cfg1 & FUNC_MF_CFG_FUNC_HIDE) &&
13546 (((mf_info->multi_vnics_mode) && !VALID_OVLAN(ovlan1)) ||
13547 ((!mf_info->multi_vnics_mode) && VALID_OVLAN(ovlan1)))) {
13548 BLOGE(sc, "mf_mode=SD function %d MF config "
13549 "mismatch, multi_vnics_mode=%d ovlan=%d\n",
13550 i, mf_info->multi_vnics_mode, ovlan1);
13555 /* Verify all funcs on the same port each have a different ovlan. */
13556 FOREACH_ABS_FUNC_IN_PORT(sc, i) {
13557 mf_cfg1 = MFCFG_RD(sc, func_mf_config[i].config);
13558 ovlan1 = MFCFG_RD(sc, func_mf_config[i].e1hov_tag);
13559 /* iterate from the next function on the port to the max func */
13560 for (j = i + 2; j < MAX_FUNC_NUM; j += 2) {
13561 mf_cfg2 = MFCFG_RD(sc, func_mf_config[j].config);
13562 ovlan2 = MFCFG_RD(sc, func_mf_config[j].e1hov_tag);
13563 if (!(mf_cfg1 & FUNC_MF_CFG_FUNC_HIDE) &&
13564 VALID_OVLAN(ovlan1) &&
13565 !(mf_cfg2 & FUNC_MF_CFG_FUNC_HIDE) &&
13566 VALID_OVLAN(ovlan2) &&
13567 (ovlan1 == ovlan2)) {
13568 BLOGE(sc, "mf_mode=SD functions %d and %d "
13569 "have the same ovlan (%d)\n",
13575 } /* MULTI_FUNCTION_SD */
13581 bxe_get_mf_cfg_info(struct bxe_softc *sc)
13583 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13584 uint32_t val, mac_upper;
13587 /* initialize mf_info defaults */
13588 mf_info->vnics_per_port = 1;
13589 mf_info->multi_vnics_mode = FALSE;
13590 mf_info->path_has_ovlan = FALSE;
13591 mf_info->mf_mode = SINGLE_FUNCTION;
13593 if (!CHIP_IS_MF_CAP(sc)) {
13597 if (sc->devinfo.mf_cfg_base == SHMEM_MF_CFG_ADDR_NONE) {
13598 BLOGE(sc, "Invalid mf_cfg_base!\n");
13602 /* get the MF mode (switch dependent / independent / single-function) */
13604 val = SHMEM_RD(sc, dev_info.shared_feature_config.config);
13606 switch (val & SHARED_FEAT_CFG_FORCE_SF_MODE_MASK)
13608 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
13610 mac_upper = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper);
13612 /* check for legal upper mac bytes */
13613 if (mac_upper != FUNC_MF_CFG_UPPERMAC_DEFAULT) {
13614 mf_info->mf_mode = MULTI_FUNCTION_SI;
13616 BLOGE(sc, "Invalid config for Switch Independent mode\n");
13621 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
13622 case SHARED_FEAT_CFG_FORCE_SF_MODE_SPIO4:
13624 /* get outer vlan configuration */
13625 val = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag);
13627 if ((val & FUNC_MF_CFG_E1HOV_TAG_MASK) !=
13628 FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
13629 mf_info->mf_mode = MULTI_FUNCTION_SD;
13631 BLOGE(sc, "Invalid config for Switch Dependent mode\n");
13636 case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
13638 /* not in MF mode, vnics_per_port=1 and multi_vnics_mode=FALSE */
13641 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
13644 * Mark MF mode as NIV if MCP version includes NPAR-SD support
13645 * and the MAC address is valid.
13647 mac_upper = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper);
13649 if ((SHMEM2_HAS(sc, afex_driver_support)) &&
13650 (mac_upper != FUNC_MF_CFG_UPPERMAC_DEFAULT)) {
13651 mf_info->mf_mode = MULTI_FUNCTION_AFEX;
13653 BLOGE(sc, "Invalid config for AFEX mode\n");
13660 BLOGE(sc, "Unknown MF mode (0x%08x)\n",
13661 (val & SHARED_FEAT_CFG_FORCE_SF_MODE_MASK));
13666 /* set path mf_mode (which could be different than function mf_mode) */
13667 if (mf_info->mf_mode == MULTI_FUNCTION_SD) {
13668 mf_info->path_has_ovlan = TRUE;
13669 } else if (mf_info->mf_mode == SINGLE_FUNCTION) {
13671 * Decide on path multi vnics mode. If we're not in MF mode and in
13672 * 4-port mode, this is good enough to check vnic-0 of the other port
13675 if (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) {
13676 uint8_t other_port = !(PORT_ID(sc) & 1);
13677 uint8_t abs_func_other_port = (SC_PATH(sc) + (2 * other_port));
13679 val = MFCFG_RD(sc, func_mf_config[abs_func_other_port].e1hov_tag);
13681 mf_info->path_has_ovlan = VALID_OVLAN((uint16_t)val) ? 1 : 0;
13685 if (mf_info->mf_mode == SINGLE_FUNCTION) {
13686 /* invalid MF config */
13687 if (SC_VN(sc) >= 1) {
13688 BLOGE(sc, "VNIC ID >= 1 in SF mode\n");
13695 /* get the MF configuration */
13696 mf_info->mf_config[SC_VN(sc)] =
13697 MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config);
13699 switch(mf_info->mf_mode)
13701 case MULTI_FUNCTION_SD:
13703 bxe_get_shmem_mf_cfg_info_sd(sc);
13706 case MULTI_FUNCTION_SI:
13708 bxe_get_shmem_mf_cfg_info_si(sc);
13711 case MULTI_FUNCTION_AFEX:
13713 bxe_get_shmem_mf_cfg_info_niv(sc);
13718 BLOGE(sc, "Get MF config failed (mf_mode=0x%08x)\n",
13723 /* get the congestion management parameters */
13726 FOREACH_ABS_FUNC_IN_PORT(sc, i) {
13727 /* get min/max bw */
13728 val = MFCFG_RD(sc, func_mf_config[i].config);
13729 mf_info->min_bw[vnic] =
13730 ((val & FUNC_MF_CFG_MIN_BW_MASK) >> FUNC_MF_CFG_MIN_BW_SHIFT);
13731 mf_info->max_bw[vnic] =
13732 ((val & FUNC_MF_CFG_MAX_BW_MASK) >> FUNC_MF_CFG_MAX_BW_SHIFT);
13736 return (bxe_check_valid_mf_cfg(sc));
13740 bxe_get_shmem_info(struct bxe_softc *sc)
13743 uint32_t mac_hi, mac_lo, val;
13745 port = SC_PORT(sc);
13746 mac_hi = mac_lo = 0;
13748 sc->link_params.sc = sc;
13749 sc->link_params.port = port;
13751 /* get the hardware config info */
13752 sc->devinfo.hw_config =
13753 SHMEM_RD(sc, dev_info.shared_hw_config.config);
13754 sc->devinfo.hw_config2 =
13755 SHMEM_RD(sc, dev_info.shared_hw_config.config2);
13757 sc->link_params.hw_led_mode =
13758 ((sc->devinfo.hw_config & SHARED_HW_CFG_LED_MODE_MASK) >>
13759 SHARED_HW_CFG_LED_MODE_SHIFT);
13761 /* get the port feature config */
13763 SHMEM_RD(sc, dev_info.port_feature_config[port].config),
13765 /* get the link params */
13766 sc->link_params.speed_cap_mask[0] =
13767 SHMEM_RD(sc, dev_info.port_hw_config[port].speed_capability_mask);
13768 sc->link_params.speed_cap_mask[1] =
13769 SHMEM_RD(sc, dev_info.port_hw_config[port].speed_capability_mask2);
13771 /* get the lane config */
13772 sc->link_params.lane_config =
13773 SHMEM_RD(sc, dev_info.port_hw_config[port].lane_config);
13775 /* get the link config */
13776 val = SHMEM_RD(sc, dev_info.port_feature_config[port].link_config);
13777 sc->port.link_config[ELINK_INT_PHY] = val;
13778 sc->link_params.switch_cfg = (val & PORT_FEATURE_CONNECTED_SWITCH_MASK);
13779 sc->port.link_config[ELINK_EXT_PHY1] =
13780 SHMEM_RD(sc, dev_info.port_feature_config[port].link_config2);
13782 /* get the override preemphasis flag and enable it or turn it off */
13783 val = SHMEM_RD(sc, dev_info.shared_feature_config.config);
13784 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED) {
13785 sc->link_params.feature_config_flags |=
13786 ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
13788 sc->link_params.feature_config_flags &=
13789 ~ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
13792 /* get the initial value of the link params */
13793 sc->link_params.multi_phy_config =
13794 SHMEM_RD(sc, dev_info.port_hw_config[port].multi_phy_config);
13796 /* get external phy info */
13797 sc->port.ext_phy_config =
13798 SHMEM_RD(sc, dev_info.port_hw_config[port].external_phy_config);
13800 /* get the multifunction configuration */
13801 bxe_get_mf_cfg_info(sc);
13803 /* get the mac address */
13805 mac_hi = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper);
13806 mac_lo = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_lower);
13808 mac_hi = SHMEM_RD(sc, dev_info.port_hw_config[port].mac_upper);
13809 mac_lo = SHMEM_RD(sc, dev_info.port_hw_config[port].mac_lower);
13812 if ((mac_lo == 0) && (mac_hi == 0)) {
13813 *sc->mac_addr_str = 0;
13814 BLOGE(sc, "No Ethernet address programmed!\n");
13816 sc->link_params.mac_addr[0] = (uint8_t)(mac_hi >> 8);
13817 sc->link_params.mac_addr[1] = (uint8_t)(mac_hi);
13818 sc->link_params.mac_addr[2] = (uint8_t)(mac_lo >> 24);
13819 sc->link_params.mac_addr[3] = (uint8_t)(mac_lo >> 16);
13820 sc->link_params.mac_addr[4] = (uint8_t)(mac_lo >> 8);
13821 sc->link_params.mac_addr[5] = (uint8_t)(mac_lo);
13822 snprintf(sc->mac_addr_str, sizeof(sc->mac_addr_str),
13823 "%02x:%02x:%02x:%02x:%02x:%02x",
13824 sc->link_params.mac_addr[0], sc->link_params.mac_addr[1],
13825 sc->link_params.mac_addr[2], sc->link_params.mac_addr[3],
13826 sc->link_params.mac_addr[4], sc->link_params.mac_addr[5]);
13827 BLOGD(sc, DBG_LOAD, "Ethernet address: %s\n", sc->mac_addr_str);
13834 bxe_get_tunable_params(struct bxe_softc *sc)
13836 /* sanity checks */
13838 if ((bxe_interrupt_mode != INTR_MODE_INTX) &&
13839 (bxe_interrupt_mode != INTR_MODE_MSI) &&
13840 (bxe_interrupt_mode != INTR_MODE_MSIX)) {
13841 BLOGW(sc, "invalid interrupt_mode value (%d)\n", bxe_interrupt_mode);
13842 bxe_interrupt_mode = INTR_MODE_MSIX;
13845 if ((bxe_queue_count < 0) || (bxe_queue_count > MAX_RSS_CHAINS)) {
13846 BLOGW(sc, "invalid queue_count value (%d)\n", bxe_queue_count);
13847 bxe_queue_count = 0;
13850 if ((bxe_max_rx_bufs < 1) || (bxe_max_rx_bufs > RX_BD_USABLE)) {
13851 if (bxe_max_rx_bufs == 0) {
13852 bxe_max_rx_bufs = RX_BD_USABLE;
13854 BLOGW(sc, "invalid max_rx_bufs (%d)\n", bxe_max_rx_bufs);
13855 bxe_max_rx_bufs = 2048;
13859 if ((bxe_hc_rx_ticks < 1) || (bxe_hc_rx_ticks > 100)) {
13860 BLOGW(sc, "invalid hc_rx_ticks (%d)\n", bxe_hc_rx_ticks);
13861 bxe_hc_rx_ticks = 25;
13864 if ((bxe_hc_tx_ticks < 1) || (bxe_hc_tx_ticks > 100)) {
13865 BLOGW(sc, "invalid hc_tx_ticks (%d)\n", bxe_hc_tx_ticks);
13866 bxe_hc_tx_ticks = 50;
13869 if (bxe_max_aggregation_size == 0) {
13870 bxe_max_aggregation_size = TPA_AGG_SIZE;
13873 if (bxe_max_aggregation_size > 0xffff) {
13874 BLOGW(sc, "invalid max_aggregation_size (%d)\n",
13875 bxe_max_aggregation_size);
13876 bxe_max_aggregation_size = TPA_AGG_SIZE;
13879 if ((bxe_mrrs < -1) || (bxe_mrrs > 3)) {
13880 BLOGW(sc, "invalid mrrs (%d)\n", bxe_mrrs);
13884 if ((bxe_autogreeen < 0) || (bxe_autogreeen > 2)) {
13885 BLOGW(sc, "invalid autogreeen (%d)\n", bxe_autogreeen);
13886 bxe_autogreeen = 0;
13889 if ((bxe_udp_rss < 0) || (bxe_udp_rss > 1)) {
13890 BLOGW(sc, "invalid udp_rss (%d)\n", bxe_udp_rss);
13894 /* pull in user settings */
13896 sc->interrupt_mode = bxe_interrupt_mode;
13897 sc->max_rx_bufs = bxe_max_rx_bufs;
13898 sc->hc_rx_ticks = bxe_hc_rx_ticks;
13899 sc->hc_tx_ticks = bxe_hc_tx_ticks;
13900 sc->max_aggregation_size = bxe_max_aggregation_size;
13901 sc->mrrs = bxe_mrrs;
13902 sc->autogreeen = bxe_autogreeen;
13903 sc->udp_rss = bxe_udp_rss;
13905 if (bxe_interrupt_mode == INTR_MODE_INTX) {
13906 sc->num_queues = 1;
13907 } else { /* INTR_MODE_MSI or INTR_MODE_MSIX */
13909 min((bxe_queue_count ? bxe_queue_count : mp_ncpus),
13911 if (sc->num_queues > mp_ncpus) {
13912 sc->num_queues = mp_ncpus;
13916 BLOGD(sc, DBG_LOAD,
13919 "interrupt_mode=%d "
13924 "max_aggregation_size=%d "
13929 sc->interrupt_mode,
13934 sc->max_aggregation_size,
13941 bxe_media_detect(struct bxe_softc *sc)
13944 uint32_t phy_idx = bxe_get_cur_phy_idx(sc);
13946 switch (sc->link_params.phy[phy_idx].media_type) {
13947 case ELINK_ETH_PHY_SFPP_10G_FIBER:
13948 case ELINK_ETH_PHY_XFP_FIBER:
13949 BLOGI(sc, "Found 10Gb Fiber media.\n");
13950 sc->media = IFM_10G_SR;
13951 port_type = PORT_FIBRE;
13953 case ELINK_ETH_PHY_SFP_1G_FIBER:
13954 BLOGI(sc, "Found 1Gb Fiber media.\n");
13955 sc->media = IFM_1000_SX;
13956 port_type = PORT_FIBRE;
13958 case ELINK_ETH_PHY_KR:
13959 case ELINK_ETH_PHY_CX4:
13960 BLOGI(sc, "Found 10GBase-CX4 media.\n");
13961 sc->media = IFM_10G_CX4;
13962 port_type = PORT_FIBRE;
13964 case ELINK_ETH_PHY_DA_TWINAX:
13965 BLOGI(sc, "Found 10Gb Twinax media.\n");
13966 sc->media = IFM_10G_TWINAX;
13967 port_type = PORT_DA;
13969 case ELINK_ETH_PHY_BASE_T:
13970 if (sc->link_params.speed_cap_mask[0] &
13971 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) {
13972 BLOGI(sc, "Found 10GBase-T media.\n");
13973 sc->media = IFM_10G_T;
13974 port_type = PORT_TP;
13976 BLOGI(sc, "Found 1000Base-T media.\n");
13977 sc->media = IFM_1000_T;
13978 port_type = PORT_TP;
13981 case ELINK_ETH_PHY_NOT_PRESENT:
13982 BLOGI(sc, "Media not present.\n");
13984 port_type = PORT_OTHER;
13986 case ELINK_ETH_PHY_UNSPECIFIED:
13988 BLOGI(sc, "Unknown media!\n");
13990 port_type = PORT_OTHER;
13996 #define GET_FIELD(value, fname) \
13997 (((value) & (fname##_MASK)) >> (fname##_SHIFT))
13998 #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
13999 #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
14002 bxe_get_igu_cam_info(struct bxe_softc *sc)
14004 int pfid = SC_FUNC(sc);
14007 uint8_t fid, igu_sb_cnt = 0;
14009 sc->igu_base_sb = 0xff;
14011 if (CHIP_INT_MODE_IS_BC(sc)) {
14012 int vn = SC_VN(sc);
14013 igu_sb_cnt = sc->igu_sb_cnt;
14014 sc->igu_base_sb = ((CHIP_IS_MODE_4_PORT(sc) ? pfid : vn) *
14016 sc->igu_dsb_id = (E1HVN_MAX * FP_SB_MAX_E1x +
14017 (CHIP_IS_MODE_4_PORT(sc) ? pfid : vn));
14021 /* IGU in normal mode - read CAM */
14022 for (igu_sb_id = 0;
14023 igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
14025 val = REG_RD(sc, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
14026 if (!(val & IGU_REG_MAPPING_MEMORY_VALID)) {
14029 fid = IGU_FID(val);
14030 if ((fid & IGU_FID_ENCODE_IS_PF)) {
14031 if ((fid & IGU_FID_PF_NUM_MASK) != pfid) {
14034 if (IGU_VEC(val) == 0) {
14035 /* default status block */
14036 sc->igu_dsb_id = igu_sb_id;
14038 if (sc->igu_base_sb == 0xff) {
14039 sc->igu_base_sb = igu_sb_id;
14047 * Due to new PF resource allocation by MFW T7.4 and above, it's optional
14048 * that number of CAM entries will not be equal to the value advertised in
14049 * PCI. Driver should use the minimal value of both as the actual status
14052 sc->igu_sb_cnt = min(sc->igu_sb_cnt, igu_sb_cnt);
14054 if (igu_sb_cnt == 0) {
14055 BLOGE(sc, "CAM configuration error\n");
14063 * Gather various information from the device config space, the device itself,
14064 * shmem, and the user input.
14067 bxe_get_device_info(struct bxe_softc *sc)
14072 /* Get the data for the device */
14073 sc->devinfo.vendor_id = pci_get_vendor(sc->dev);
14074 sc->devinfo.device_id = pci_get_device(sc->dev);
14075 sc->devinfo.subvendor_id = pci_get_subvendor(sc->dev);
14076 sc->devinfo.subdevice_id = pci_get_subdevice(sc->dev);
14078 /* get the chip revision (chip metal comes from pci config space) */
14079 sc->devinfo.chip_id =
14080 sc->link_params.chip_id =
14081 (((REG_RD(sc, MISC_REG_CHIP_NUM) & 0xffff) << 16) |
14082 ((REG_RD(sc, MISC_REG_CHIP_REV) & 0xf) << 12) |
14083 (((REG_RD(sc, PCICFG_OFFSET + PCI_ID_VAL3) >> 24) & 0xf) << 4) |
14084 ((REG_RD(sc, MISC_REG_BOND_ID) & 0xf) << 0));
14086 /* force 57811 according to MISC register */
14087 if (REG_RD(sc, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
14088 if (CHIP_IS_57810(sc)) {
14089 sc->devinfo.chip_id = ((CHIP_NUM_57811 << 16) |
14090 (sc->devinfo.chip_id & 0x0000ffff));
14091 } else if (CHIP_IS_57810_MF(sc)) {
14092 sc->devinfo.chip_id = ((CHIP_NUM_57811_MF << 16) |
14093 (sc->devinfo.chip_id & 0x0000ffff));
14095 sc->devinfo.chip_id |= 0x1;
14098 BLOGD(sc, DBG_LOAD,
14099 "chip_id=0x%08x (num=0x%04x rev=0x%01x metal=0x%02x bond=0x%01x)\n",
14100 sc->devinfo.chip_id,
14101 ((sc->devinfo.chip_id >> 16) & 0xffff),
14102 ((sc->devinfo.chip_id >> 12) & 0xf),
14103 ((sc->devinfo.chip_id >> 4) & 0xff),
14104 ((sc->devinfo.chip_id >> 0) & 0xf));
14106 val = (REG_RD(sc, 0x2874) & 0x55);
14107 if ((sc->devinfo.chip_id & 0x1) ||
14108 (CHIP_IS_E1(sc) && val) ||
14109 (CHIP_IS_E1H(sc) && (val == 0x55))) {
14110 sc->flags |= BXE_ONE_PORT_FLAG;
14111 BLOGD(sc, DBG_LOAD, "single port device\n");
14114 /* set the doorbell size */
14115 sc->doorbell_size = (1 << BXE_DB_SHIFT);
14117 /* determine whether the device is in 2 port or 4 port mode */
14118 sc->devinfo.chip_port_mode = CHIP_PORT_MODE_NONE; /* E1 & E1h*/
14119 if (CHIP_IS_E2E3(sc)) {
14121 * Read port4mode_en_ovwr[0]:
14122 * If 1, four port mode is in port4mode_en_ovwr[1].
14123 * If 0, four port mode is in port4mode_en[0].
14125 val = REG_RD(sc, MISC_REG_PORT4MODE_EN_OVWR);
14127 val = ((val >> 1) & 1);
14129 val = REG_RD(sc, MISC_REG_PORT4MODE_EN);
14132 sc->devinfo.chip_port_mode =
14133 (val) ? CHIP_4_PORT_MODE : CHIP_2_PORT_MODE;
14135 BLOGD(sc, DBG_LOAD, "Port mode = %s\n", (val) ? "4" : "2");
14138 /* get the function and path info for the device */
14139 bxe_get_function_num(sc);
14141 /* get the shared memory base address */
14142 sc->devinfo.shmem_base =
14143 sc->link_params.shmem_base =
14144 REG_RD(sc, MISC_REG_SHARED_MEM_ADDR);
14145 sc->devinfo.shmem2_base =
14146 REG_RD(sc, (SC_PATH(sc) ? MISC_REG_GENERIC_CR_1 :
14147 MISC_REG_GENERIC_CR_0));
14149 BLOGD(sc, DBG_LOAD, "shmem_base=0x%08x, shmem2_base=0x%08x\n",
14150 sc->devinfo.shmem_base, sc->devinfo.shmem2_base);
14152 if (!sc->devinfo.shmem_base) {
14153 /* this should ONLY prevent upcoming shmem reads */
14154 BLOGI(sc, "MCP not active\n");
14155 sc->flags |= BXE_NO_MCP_FLAG;
14159 /* make sure the shared memory contents are valid */
14160 val = SHMEM_RD(sc, validity_map[SC_PORT(sc)]);
14161 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) !=
14162 (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) {
14163 BLOGE(sc, "Invalid SHMEM validity signature: 0x%08x\n", val);
14166 BLOGD(sc, DBG_LOAD, "Valid SHMEM validity signature: 0x%08x\n", val);
14168 /* get the bootcode version */
14169 sc->devinfo.bc_ver = SHMEM_RD(sc, dev_info.bc_rev);
14170 snprintf(sc->devinfo.bc_ver_str,
14171 sizeof(sc->devinfo.bc_ver_str),
14173 ((sc->devinfo.bc_ver >> 24) & 0xff),
14174 ((sc->devinfo.bc_ver >> 16) & 0xff),
14175 ((sc->devinfo.bc_ver >> 8) & 0xff));
14176 BLOGD(sc, DBG_LOAD, "Bootcode version: %s\n", sc->devinfo.bc_ver_str);
14178 /* get the bootcode shmem address */
14179 sc->devinfo.mf_cfg_base = bxe_get_shmem_mf_cfg_base(sc);
14180 BLOGD(sc, DBG_LOAD, "mf_cfg_base=0x08%x \n", sc->devinfo.mf_cfg_base);
14182 /* clean indirect addresses as they're not used */
14183 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, 0, 4);
14185 REG_WR(sc, PXP2_REG_PGL_ADDR_88_F0, 0);
14186 REG_WR(sc, PXP2_REG_PGL_ADDR_8C_F0, 0);
14187 REG_WR(sc, PXP2_REG_PGL_ADDR_90_F0, 0);
14188 REG_WR(sc, PXP2_REG_PGL_ADDR_94_F0, 0);
14189 if (CHIP_IS_E1x(sc)) {
14190 REG_WR(sc, PXP2_REG_PGL_ADDR_88_F1, 0);
14191 REG_WR(sc, PXP2_REG_PGL_ADDR_8C_F1, 0);
14192 REG_WR(sc, PXP2_REG_PGL_ADDR_90_F1, 0);
14193 REG_WR(sc, PXP2_REG_PGL_ADDR_94_F1, 0);
14197 * Enable internal target-read (in case we are probed after PF
14198 * FLR). Must be done prior to any BAR read access. Only for
14201 if (!CHIP_IS_E1x(sc)) {
14202 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
14206 /* get the nvram size */
14207 val = REG_RD(sc, MCP_REG_MCPR_NVM_CFG4);
14208 sc->devinfo.flash_size =
14209 (NVRAM_1MB_SIZE << (val & MCPR_NVM_CFG4_FLASH_SIZE));
14210 BLOGD(sc, DBG_LOAD, "nvram flash size: %d\n", sc->devinfo.flash_size);
14212 /* get PCI capabilites */
14213 bxe_probe_pci_caps(sc);
14215 bxe_set_power_state(sc, PCI_PM_D0);
14217 /* get various configuration parameters from shmem */
14218 bxe_get_shmem_info(sc);
14220 if (sc->devinfo.pcie_msix_cap_reg != 0) {
14221 val = pci_read_config(sc->dev,
14222 (sc->devinfo.pcie_msix_cap_reg +
14225 sc->igu_sb_cnt = (val & PCIM_MSIXCTRL_TABLE_SIZE);
14227 sc->igu_sb_cnt = 1;
14230 sc->igu_base_addr = BAR_IGU_INTMEM;
14232 /* initialize IGU parameters */
14233 if (CHIP_IS_E1x(sc)) {
14234 sc->devinfo.int_block = INT_BLOCK_HC;
14235 sc->igu_dsb_id = DEF_SB_IGU_ID;
14236 sc->igu_base_sb = 0;
14238 sc->devinfo.int_block = INT_BLOCK_IGU;
14240 /* do not allow device reset during IGU info preocessing */
14241 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
14243 val = REG_RD(sc, IGU_REG_BLOCK_CONFIGURATION);
14245 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
14248 BLOGD(sc, DBG_LOAD, "FORCING IGU Normal Mode\n");
14250 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
14251 REG_WR(sc, IGU_REG_BLOCK_CONFIGURATION, val);
14252 REG_WR(sc, IGU_REG_RESET_MEMORIES, 0x7f);
14254 while (tout && REG_RD(sc, IGU_REG_RESET_MEMORIES)) {
14259 if (REG_RD(sc, IGU_REG_RESET_MEMORIES)) {
14260 BLOGD(sc, DBG_LOAD, "FORCING IGU Normal Mode failed!!!\n");
14261 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
14266 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
14267 BLOGD(sc, DBG_LOAD, "IGU Backward Compatible Mode\n");
14268 sc->devinfo.int_block |= INT_BLOCK_MODE_BW_COMP;
14270 BLOGD(sc, DBG_LOAD, "IGU Normal Mode\n");
14273 rc = bxe_get_igu_cam_info(sc);
14275 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
14283 * Get base FW non-default (fast path) status block ID. This value is
14284 * used to initialize the fw_sb_id saved on the fp/queue structure to
14285 * determine the id used by the FW.
14287 if (CHIP_IS_E1x(sc)) {
14288 sc->base_fw_ndsb = ((SC_PORT(sc) * FP_SB_MAX_E1x) + SC_L_ID(sc));
14291 * 57712+ - We currently use one FW SB per IGU SB (Rx and Tx of
14292 * the same queue are indicated on the same IGU SB). So we prefer
14293 * FW and IGU SBs to be the same value.
14295 sc->base_fw_ndsb = sc->igu_base_sb;
14298 BLOGD(sc, DBG_LOAD,
14299 "igu_dsb_id=%d igu_base_sb=%d igu_sb_cnt=%d base_fw_ndsb=%d\n",
14300 sc->igu_dsb_id, sc->igu_base_sb,
14301 sc->igu_sb_cnt, sc->base_fw_ndsb);
14303 elink_phy_probe(&sc->link_params);
14309 bxe_link_settings_supported(struct bxe_softc *sc,
14310 uint32_t switch_cfg)
14312 uint32_t cfg_size = 0;
14314 uint8_t port = SC_PORT(sc);
14316 /* aggregation of supported attributes of all external phys */
14317 sc->port.supported[0] = 0;
14318 sc->port.supported[1] = 0;
14320 switch (sc->link_params.num_phys) {
14322 sc->port.supported[0] = sc->link_params.phy[ELINK_INT_PHY].supported;
14326 sc->port.supported[0] = sc->link_params.phy[ELINK_EXT_PHY1].supported;
14330 if (sc->link_params.multi_phy_config &
14331 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
14332 sc->port.supported[1] =
14333 sc->link_params.phy[ELINK_EXT_PHY1].supported;
14334 sc->port.supported[0] =
14335 sc->link_params.phy[ELINK_EXT_PHY2].supported;
14337 sc->port.supported[0] =
14338 sc->link_params.phy[ELINK_EXT_PHY1].supported;
14339 sc->port.supported[1] =
14340 sc->link_params.phy[ELINK_EXT_PHY2].supported;
14346 if (!(sc->port.supported[0] || sc->port.supported[1])) {
14347 BLOGE(sc, "Invalid phy config in NVRAM (PHY1=0x%08x PHY2=0x%08x)\n",
14349 dev_info.port_hw_config[port].external_phy_config),
14351 dev_info.port_hw_config[port].external_phy_config2));
14355 if (CHIP_IS_E3(sc))
14356 sc->port.phy_addr = REG_RD(sc, MISC_REG_WC0_CTRL_PHY_ADDR);
14358 switch (switch_cfg) {
14359 case ELINK_SWITCH_CFG_1G:
14360 sc->port.phy_addr =
14361 REG_RD(sc, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
14363 case ELINK_SWITCH_CFG_10G:
14364 sc->port.phy_addr =
14365 REG_RD(sc, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
14368 BLOGE(sc, "Invalid switch config in link_config=0x%08x\n",
14369 sc->port.link_config[0]);
14374 BLOGD(sc, DBG_LOAD, "PHY addr 0x%08x\n", sc->port.phy_addr);
14376 /* mask what we support according to speed_cap_mask per configuration */
14377 for (idx = 0; idx < cfg_size; idx++) {
14378 if (!(sc->link_params.speed_cap_mask[idx] &
14379 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) {
14380 sc->port.supported[idx] &= ~ELINK_SUPPORTED_10baseT_Half;
14383 if (!(sc->link_params.speed_cap_mask[idx] &
14384 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL)) {
14385 sc->port.supported[idx] &= ~ELINK_SUPPORTED_10baseT_Full;
14388 if (!(sc->link_params.speed_cap_mask[idx] &
14389 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)) {
14390 sc->port.supported[idx] &= ~ELINK_SUPPORTED_100baseT_Half;
14393 if (!(sc->link_params.speed_cap_mask[idx] &
14394 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL)) {
14395 sc->port.supported[idx] &= ~ELINK_SUPPORTED_100baseT_Full;
14398 if (!(sc->link_params.speed_cap_mask[idx] &
14399 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) {
14400 sc->port.supported[idx] &= ~ELINK_SUPPORTED_1000baseT_Full;
14403 if (!(sc->link_params.speed_cap_mask[idx] &
14404 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)) {
14405 sc->port.supported[idx] &= ~ELINK_SUPPORTED_2500baseX_Full;
14408 if (!(sc->link_params.speed_cap_mask[idx] &
14409 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
14410 sc->port.supported[idx] &= ~ELINK_SUPPORTED_10000baseT_Full;
14413 if (!(sc->link_params.speed_cap_mask[idx] &
14414 PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)) {
14415 sc->port.supported[idx] &= ~ELINK_SUPPORTED_20000baseKR2_Full;
14419 BLOGD(sc, DBG_LOAD, "PHY supported 0=0x%08x 1=0x%08x\n",
14420 sc->port.supported[0], sc->port.supported[1]);
14421 ELINK_DEBUG_P2(sc, "PHY supported 0=0x%08x 1=0x%08x\n",
14422 sc->port.supported[0], sc->port.supported[1]);
14426 bxe_link_settings_requested(struct bxe_softc *sc)
14428 uint32_t link_config;
14430 uint32_t cfg_size = 0;
14432 sc->port.advertising[0] = 0;
14433 sc->port.advertising[1] = 0;
14435 switch (sc->link_params.num_phys) {
14445 for (idx = 0; idx < cfg_size; idx++) {
14446 sc->link_params.req_duplex[idx] = DUPLEX_FULL;
14447 link_config = sc->port.link_config[idx];
14449 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
14450 case PORT_FEATURE_LINK_SPEED_AUTO:
14451 if (sc->port.supported[idx] & ELINK_SUPPORTED_Autoneg) {
14452 sc->link_params.req_line_speed[idx] = ELINK_SPEED_AUTO_NEG;
14453 sc->port.advertising[idx] |= sc->port.supported[idx];
14454 if (sc->link_params.phy[ELINK_EXT_PHY1].type ==
14455 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
14456 sc->port.advertising[idx] |=
14457 (ELINK_SUPPORTED_100baseT_Half |
14458 ELINK_SUPPORTED_100baseT_Full);
14460 /* force 10G, no AN */
14461 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10000;
14462 sc->port.advertising[idx] |=
14463 (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
14468 case PORT_FEATURE_LINK_SPEED_10M_FULL:
14469 if (sc->port.supported[idx] & ELINK_SUPPORTED_10baseT_Full) {
14470 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10;
14471 sc->port.advertising[idx] |= (ADVERTISED_10baseT_Full |
14474 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14475 "speed_cap_mask=0x%08x\n",
14476 link_config, sc->link_params.speed_cap_mask[idx]);
14481 case PORT_FEATURE_LINK_SPEED_10M_HALF:
14482 if (sc->port.supported[idx] & ELINK_SUPPORTED_10baseT_Half) {
14483 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10;
14484 sc->link_params.req_duplex[idx] = DUPLEX_HALF;
14485 sc->port.advertising[idx] |= (ADVERTISED_10baseT_Half |
14487 ELINK_DEBUG_P1(sc, "driver requesting DUPLEX_HALF req_duplex = %x!\n",
14488 sc->link_params.req_duplex[idx]);
14490 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14491 "speed_cap_mask=0x%08x\n",
14492 link_config, sc->link_params.speed_cap_mask[idx]);
14497 case PORT_FEATURE_LINK_SPEED_100M_FULL:
14498 if (sc->port.supported[idx] & ELINK_SUPPORTED_100baseT_Full) {
14499 sc->link_params.req_line_speed[idx] = ELINK_SPEED_100;
14500 sc->port.advertising[idx] |= (ADVERTISED_100baseT_Full |
14503 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14504 "speed_cap_mask=0x%08x\n",
14505 link_config, sc->link_params.speed_cap_mask[idx]);
14510 case PORT_FEATURE_LINK_SPEED_100M_HALF:
14511 if (sc->port.supported[idx] & ELINK_SUPPORTED_100baseT_Half) {
14512 sc->link_params.req_line_speed[idx] = ELINK_SPEED_100;
14513 sc->link_params.req_duplex[idx] = DUPLEX_HALF;
14514 sc->port.advertising[idx] |= (ADVERTISED_100baseT_Half |
14517 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14518 "speed_cap_mask=0x%08x\n",
14519 link_config, sc->link_params.speed_cap_mask[idx]);
14524 case PORT_FEATURE_LINK_SPEED_1G:
14525 if (sc->port.supported[idx] & ELINK_SUPPORTED_1000baseT_Full) {
14526 sc->link_params.req_line_speed[idx] = ELINK_SPEED_1000;
14527 sc->port.advertising[idx] |= (ADVERTISED_1000baseT_Full |
14530 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14531 "speed_cap_mask=0x%08x\n",
14532 link_config, sc->link_params.speed_cap_mask[idx]);
14537 case PORT_FEATURE_LINK_SPEED_2_5G:
14538 if (sc->port.supported[idx] & ELINK_SUPPORTED_2500baseX_Full) {
14539 sc->link_params.req_line_speed[idx] = ELINK_SPEED_2500;
14540 sc->port.advertising[idx] |= (ADVERTISED_2500baseX_Full |
14543 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14544 "speed_cap_mask=0x%08x\n",
14545 link_config, sc->link_params.speed_cap_mask[idx]);
14550 case PORT_FEATURE_LINK_SPEED_10G_CX4:
14551 if (sc->port.supported[idx] & ELINK_SUPPORTED_10000baseT_Full) {
14552 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10000;
14553 sc->port.advertising[idx] |= (ADVERTISED_10000baseT_Full |
14556 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14557 "speed_cap_mask=0x%08x\n",
14558 link_config, sc->link_params.speed_cap_mask[idx]);
14563 case PORT_FEATURE_LINK_SPEED_20G:
14564 sc->link_params.req_line_speed[idx] = ELINK_SPEED_20000;
14568 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14569 "speed_cap_mask=0x%08x\n",
14570 link_config, sc->link_params.speed_cap_mask[idx]);
14571 sc->link_params.req_line_speed[idx] = ELINK_SPEED_AUTO_NEG;
14572 sc->port.advertising[idx] = sc->port.supported[idx];
14576 sc->link_params.req_flow_ctrl[idx] =
14577 (link_config & PORT_FEATURE_FLOW_CONTROL_MASK);
14579 if (sc->link_params.req_flow_ctrl[idx] == ELINK_FLOW_CTRL_AUTO) {
14580 if (!(sc->port.supported[idx] & ELINK_SUPPORTED_Autoneg)) {
14581 sc->link_params.req_flow_ctrl[idx] = ELINK_FLOW_CTRL_NONE;
14583 bxe_set_requested_fc(sc);
14587 BLOGD(sc, DBG_LOAD, "req_line_speed=%d req_duplex=%d "
14588 "req_flow_ctrl=0x%x advertising=0x%x\n",
14589 sc->link_params.req_line_speed[idx],
14590 sc->link_params.req_duplex[idx],
14591 sc->link_params.req_flow_ctrl[idx],
14592 sc->port.advertising[idx]);
14593 ELINK_DEBUG_P3(sc, "req_line_speed=%d req_duplex=%d "
14594 "advertising=0x%x\n",
14595 sc->link_params.req_line_speed[idx],
14596 sc->link_params.req_duplex[idx],
14597 sc->port.advertising[idx]);
14602 bxe_get_phy_info(struct bxe_softc *sc)
14604 uint8_t port = SC_PORT(sc);
14605 uint32_t config = sc->port.config;
14608 /* shmem data already read in bxe_get_shmem_info() */
14610 ELINK_DEBUG_P3(sc, "lane_config=0x%08x speed_cap_mask0=0x%08x "
14611 "link_config0=0x%08x\n",
14612 sc->link_params.lane_config,
14613 sc->link_params.speed_cap_mask[0],
14614 sc->port.link_config[0]);
14617 bxe_link_settings_supported(sc, sc->link_params.switch_cfg);
14618 bxe_link_settings_requested(sc);
14620 if (sc->autogreeen == AUTO_GREEN_FORCE_ON) {
14621 sc->link_params.feature_config_flags |=
14622 ELINK_FEATURE_CONFIG_AUTOGREEEN_ENABLED;
14623 } else if (sc->autogreeen == AUTO_GREEN_FORCE_OFF) {
14624 sc->link_params.feature_config_flags &=
14625 ~ELINK_FEATURE_CONFIG_AUTOGREEEN_ENABLED;
14626 } else if (config & PORT_FEAT_CFG_AUTOGREEEN_ENABLED) {
14627 sc->link_params.feature_config_flags |=
14628 ELINK_FEATURE_CONFIG_AUTOGREEEN_ENABLED;
14631 /* configure link feature according to nvram value */
14633 (((SHMEM_RD(sc, dev_info.port_feature_config[port].eee_power_mode)) &
14634 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
14635 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
14636 if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
14637 sc->link_params.eee_mode = (ELINK_EEE_MODE_ADV_LPI |
14638 ELINK_EEE_MODE_ENABLE_LPI |
14639 ELINK_EEE_MODE_OUTPUT_TIME);
14641 sc->link_params.eee_mode = 0;
14644 /* get the media type */
14645 bxe_media_detect(sc);
14646 ELINK_DEBUG_P1(sc, "detected media type\n", sc->media);
14650 bxe_get_params(struct bxe_softc *sc)
14652 /* get user tunable params */
14653 bxe_get_tunable_params(sc);
14655 /* select the RX and TX ring sizes */
14656 sc->tx_ring_size = TX_BD_USABLE;
14657 sc->rx_ring_size = RX_BD_USABLE;
14659 /* XXX disable WoL */
14664 bxe_set_modes_bitmap(struct bxe_softc *sc)
14666 uint32_t flags = 0;
14668 if (CHIP_REV_IS_FPGA(sc)) {
14669 SET_FLAGS(flags, MODE_FPGA);
14670 } else if (CHIP_REV_IS_EMUL(sc)) {
14671 SET_FLAGS(flags, MODE_EMUL);
14673 SET_FLAGS(flags, MODE_ASIC);
14676 if (CHIP_IS_MODE_4_PORT(sc)) {
14677 SET_FLAGS(flags, MODE_PORT4);
14679 SET_FLAGS(flags, MODE_PORT2);
14682 if (CHIP_IS_E2(sc)) {
14683 SET_FLAGS(flags, MODE_E2);
14684 } else if (CHIP_IS_E3(sc)) {
14685 SET_FLAGS(flags, MODE_E3);
14686 if (CHIP_REV(sc) == CHIP_REV_Ax) {
14687 SET_FLAGS(flags, MODE_E3_A0);
14688 } else /*if (CHIP_REV(sc) == CHIP_REV_Bx)*/ {
14689 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
14694 SET_FLAGS(flags, MODE_MF);
14695 switch (sc->devinfo.mf_info.mf_mode) {
14696 case MULTI_FUNCTION_SD:
14697 SET_FLAGS(flags, MODE_MF_SD);
14699 case MULTI_FUNCTION_SI:
14700 SET_FLAGS(flags, MODE_MF_SI);
14702 case MULTI_FUNCTION_AFEX:
14703 SET_FLAGS(flags, MODE_MF_AFEX);
14707 SET_FLAGS(flags, MODE_SF);
14710 #if defined(__LITTLE_ENDIAN)
14711 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
14712 #else /* __BIG_ENDIAN */
14713 SET_FLAGS(flags, MODE_BIG_ENDIAN);
14716 INIT_MODE_FLAGS(sc) = flags;
14720 bxe_alloc_hsi_mem(struct bxe_softc *sc)
14722 struct bxe_fastpath *fp;
14723 bus_addr_t busaddr;
14724 int max_agg_queues;
14726 bus_size_t max_size;
14727 bus_size_t max_seg_size;
14732 /* XXX zero out all vars here and call bxe_alloc_hsi_mem on error */
14734 /* allocate the parent bus DMA tag */
14735 rc = bus_dma_tag_create(bus_get_dma_tag(sc->dev), /* parent tag */
14737 0, /* boundary limit */
14738 BUS_SPACE_MAXADDR, /* restricted low */
14739 BUS_SPACE_MAXADDR, /* restricted hi */
14740 NULL, /* addr filter() */
14741 NULL, /* addr filter() arg */
14742 BUS_SPACE_MAXSIZE_32BIT, /* max map size */
14743 BUS_SPACE_UNRESTRICTED, /* num discontinuous */
14744 BUS_SPACE_MAXSIZE_32BIT, /* max seg size */
14747 NULL, /* lock() arg */
14748 &sc->parent_dma_tag); /* returned dma tag */
14750 BLOGE(sc, "Failed to alloc parent DMA tag (%d)!\n", rc);
14754 /************************/
14755 /* DEFAULT STATUS BLOCK */
14756 /************************/
14758 if (bxe_dma_alloc(sc, sizeof(struct host_sp_status_block),
14759 &sc->def_sb_dma, "default status block") != 0) {
14761 bus_dma_tag_destroy(sc->parent_dma_tag);
14765 sc->def_sb = (struct host_sp_status_block *)sc->def_sb_dma.vaddr;
14771 if (bxe_dma_alloc(sc, BCM_PAGE_SIZE,
14772 &sc->eq_dma, "event queue") != 0) {
14774 bxe_dma_free(sc, &sc->def_sb_dma);
14776 bus_dma_tag_destroy(sc->parent_dma_tag);
14780 sc->eq = (union event_ring_elem * )sc->eq_dma.vaddr;
14786 if (bxe_dma_alloc(sc, sizeof(struct bxe_slowpath),
14787 &sc->sp_dma, "slow path") != 0) {
14789 bxe_dma_free(sc, &sc->eq_dma);
14791 bxe_dma_free(sc, &sc->def_sb_dma);
14793 bus_dma_tag_destroy(sc->parent_dma_tag);
14797 sc->sp = (struct bxe_slowpath *)sc->sp_dma.vaddr;
14799 /*******************/
14800 /* SLOW PATH QUEUE */
14801 /*******************/
14803 if (bxe_dma_alloc(sc, BCM_PAGE_SIZE,
14804 &sc->spq_dma, "slow path queue") != 0) {
14806 bxe_dma_free(sc, &sc->sp_dma);
14808 bxe_dma_free(sc, &sc->eq_dma);
14810 bxe_dma_free(sc, &sc->def_sb_dma);
14812 bus_dma_tag_destroy(sc->parent_dma_tag);
14816 sc->spq = (struct eth_spe *)sc->spq_dma.vaddr;
14818 /***************************/
14819 /* FW DECOMPRESSION BUFFER */
14820 /***************************/
14822 if (bxe_dma_alloc(sc, FW_BUF_SIZE, &sc->gz_buf_dma,
14823 "fw decompression buffer") != 0) {
14825 bxe_dma_free(sc, &sc->spq_dma);
14827 bxe_dma_free(sc, &sc->sp_dma);
14829 bxe_dma_free(sc, &sc->eq_dma);
14831 bxe_dma_free(sc, &sc->def_sb_dma);
14833 bus_dma_tag_destroy(sc->parent_dma_tag);
14837 sc->gz_buf = (void *)sc->gz_buf_dma.vaddr;
14840 malloc(sizeof(*sc->gz_strm), M_DEVBUF, M_NOWAIT)) == NULL) {
14842 bxe_dma_free(sc, &sc->gz_buf_dma);
14844 bxe_dma_free(sc, &sc->spq_dma);
14846 bxe_dma_free(sc, &sc->sp_dma);
14848 bxe_dma_free(sc, &sc->eq_dma);
14850 bxe_dma_free(sc, &sc->def_sb_dma);
14852 bus_dma_tag_destroy(sc->parent_dma_tag);
14860 /* allocate DMA memory for each fastpath structure */
14861 for (i = 0; i < sc->num_queues; i++) {
14866 /*******************/
14867 /* FP STATUS BLOCK */
14868 /*******************/
14870 snprintf(buf, sizeof(buf), "fp %d status block", i);
14871 if (bxe_dma_alloc(sc, sizeof(union bxe_host_hc_status_block),
14872 &fp->sb_dma, buf) != 0) {
14873 /* XXX unwind and free previous fastpath allocations */
14874 BLOGE(sc, "Failed to alloc %s\n", buf);
14877 if (CHIP_IS_E2E3(sc)) {
14878 fp->status_block.e2_sb =
14879 (struct host_hc_status_block_e2 *)fp->sb_dma.vaddr;
14881 fp->status_block.e1x_sb =
14882 (struct host_hc_status_block_e1x *)fp->sb_dma.vaddr;
14886 /******************/
14887 /* FP TX BD CHAIN */
14888 /******************/
14890 snprintf(buf, sizeof(buf), "fp %d tx bd chain", i);
14891 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * TX_BD_NUM_PAGES),
14892 &fp->tx_dma, buf) != 0) {
14893 /* XXX unwind and free previous fastpath allocations */
14894 BLOGE(sc, "Failed to alloc %s\n", buf);
14897 fp->tx_chain = (union eth_tx_bd_types *)fp->tx_dma.vaddr;
14900 /* link together the tx bd chain pages */
14901 for (j = 1; j <= TX_BD_NUM_PAGES; j++) {
14902 /* index into the tx bd chain array to last entry per page */
14903 struct eth_tx_next_bd *tx_next_bd =
14904 &fp->tx_chain[TX_BD_TOTAL_PER_PAGE * j - 1].next_bd;
14905 /* point to the next page and wrap from last page */
14906 busaddr = (fp->tx_dma.paddr +
14907 (BCM_PAGE_SIZE * (j % TX_BD_NUM_PAGES)));
14908 tx_next_bd->addr_hi = htole32(U64_HI(busaddr));
14909 tx_next_bd->addr_lo = htole32(U64_LO(busaddr));
14912 /******************/
14913 /* FP RX BD CHAIN */
14914 /******************/
14916 snprintf(buf, sizeof(buf), "fp %d rx bd chain", i);
14917 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * RX_BD_NUM_PAGES),
14918 &fp->rx_dma, buf) != 0) {
14919 /* XXX unwind and free previous fastpath allocations */
14920 BLOGE(sc, "Failed to alloc %s\n", buf);
14923 fp->rx_chain = (struct eth_rx_bd *)fp->rx_dma.vaddr;
14926 /* link together the rx bd chain pages */
14927 for (j = 1; j <= RX_BD_NUM_PAGES; j++) {
14928 /* index into the rx bd chain array to last entry per page */
14929 struct eth_rx_bd *rx_bd =
14930 &fp->rx_chain[RX_BD_TOTAL_PER_PAGE * j - 2];
14931 /* point to the next page and wrap from last page */
14932 busaddr = (fp->rx_dma.paddr +
14933 (BCM_PAGE_SIZE * (j % RX_BD_NUM_PAGES)));
14934 rx_bd->addr_hi = htole32(U64_HI(busaddr));
14935 rx_bd->addr_lo = htole32(U64_LO(busaddr));
14938 /*******************/
14939 /* FP RX RCQ CHAIN */
14940 /*******************/
14942 snprintf(buf, sizeof(buf), "fp %d rcq chain", i);
14943 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * RCQ_NUM_PAGES),
14944 &fp->rcq_dma, buf) != 0) {
14945 /* XXX unwind and free previous fastpath allocations */
14946 BLOGE(sc, "Failed to alloc %s\n", buf);
14949 fp->rcq_chain = (union eth_rx_cqe *)fp->rcq_dma.vaddr;
14952 /* link together the rcq chain pages */
14953 for (j = 1; j <= RCQ_NUM_PAGES; j++) {
14954 /* index into the rcq chain array to last entry per page */
14955 struct eth_rx_cqe_next_page *rx_cqe_next =
14956 (struct eth_rx_cqe_next_page *)
14957 &fp->rcq_chain[RCQ_TOTAL_PER_PAGE * j - 1];
14958 /* point to the next page and wrap from last page */
14959 busaddr = (fp->rcq_dma.paddr +
14960 (BCM_PAGE_SIZE * (j % RCQ_NUM_PAGES)));
14961 rx_cqe_next->addr_hi = htole32(U64_HI(busaddr));
14962 rx_cqe_next->addr_lo = htole32(U64_LO(busaddr));
14965 /*******************/
14966 /* FP RX SGE CHAIN */
14967 /*******************/
14969 snprintf(buf, sizeof(buf), "fp %d sge chain", i);
14970 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * RX_SGE_NUM_PAGES),
14971 &fp->rx_sge_dma, buf) != 0) {
14972 /* XXX unwind and free previous fastpath allocations */
14973 BLOGE(sc, "Failed to alloc %s\n", buf);
14976 fp->rx_sge_chain = (struct eth_rx_sge *)fp->rx_sge_dma.vaddr;
14979 /* link together the sge chain pages */
14980 for (j = 1; j <= RX_SGE_NUM_PAGES; j++) {
14981 /* index into the rcq chain array to last entry per page */
14982 struct eth_rx_sge *rx_sge =
14983 &fp->rx_sge_chain[RX_SGE_TOTAL_PER_PAGE * j - 2];
14984 /* point to the next page and wrap from last page */
14985 busaddr = (fp->rx_sge_dma.paddr +
14986 (BCM_PAGE_SIZE * (j % RX_SGE_NUM_PAGES)));
14987 rx_sge->addr_hi = htole32(U64_HI(busaddr));
14988 rx_sge->addr_lo = htole32(U64_LO(busaddr));
14991 /***********************/
14992 /* FP TX MBUF DMA MAPS */
14993 /***********************/
14995 /* set required sizes before mapping to conserve resources */
14996 if (sc->ifnet->if_capenable & (IFCAP_TSO4 | IFCAP_TSO6)) {
14997 max_size = BXE_TSO_MAX_SIZE;
14998 max_segments = BXE_TSO_MAX_SEGMENTS;
14999 max_seg_size = BXE_TSO_MAX_SEG_SIZE;
15001 max_size = (MCLBYTES * BXE_MAX_SEGMENTS);
15002 max_segments = BXE_MAX_SEGMENTS;
15003 max_seg_size = MCLBYTES;
15006 /* create a dma tag for the tx mbufs */
15007 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */
15009 0, /* boundary limit */
15010 BUS_SPACE_MAXADDR, /* restricted low */
15011 BUS_SPACE_MAXADDR, /* restricted hi */
15012 NULL, /* addr filter() */
15013 NULL, /* addr filter() arg */
15014 max_size, /* max map size */
15015 max_segments, /* num discontinuous */
15016 max_seg_size, /* max seg size */
15019 NULL, /* lock() arg */
15020 &fp->tx_mbuf_tag); /* returned dma tag */
15022 /* XXX unwind and free previous fastpath allocations */
15023 BLOGE(sc, "Failed to create dma tag for "
15024 "'fp %d tx mbufs' (%d)\n", i, rc);
15028 /* create dma maps for each of the tx mbuf clusters */
15029 for (j = 0; j < TX_BD_TOTAL; j++) {
15030 if (bus_dmamap_create(fp->tx_mbuf_tag,
15032 &fp->tx_mbuf_chain[j].m_map)) {
15033 /* XXX unwind and free previous fastpath allocations */
15034 BLOGE(sc, "Failed to create dma map for "
15035 "'fp %d tx mbuf %d' (%d)\n", i, j, rc);
15040 /***********************/
15041 /* FP RX MBUF DMA MAPS */
15042 /***********************/
15044 /* create a dma tag for the rx mbufs */
15045 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */
15047 0, /* boundary limit */
15048 BUS_SPACE_MAXADDR, /* restricted low */
15049 BUS_SPACE_MAXADDR, /* restricted hi */
15050 NULL, /* addr filter() */
15051 NULL, /* addr filter() arg */
15052 MJUM9BYTES, /* max map size */
15053 1, /* num discontinuous */
15054 MJUM9BYTES, /* max seg size */
15057 NULL, /* lock() arg */
15058 &fp->rx_mbuf_tag); /* returned dma tag */
15060 /* XXX unwind and free previous fastpath allocations */
15061 BLOGE(sc, "Failed to create dma tag for "
15062 "'fp %d rx mbufs' (%d)\n", i, rc);
15066 /* create dma maps for each of the rx mbuf clusters */
15067 for (j = 0; j < RX_BD_TOTAL; j++) {
15068 if (bus_dmamap_create(fp->rx_mbuf_tag,
15070 &fp->rx_mbuf_chain[j].m_map)) {
15071 /* XXX unwind and free previous fastpath allocations */
15072 BLOGE(sc, "Failed to create dma map for "
15073 "'fp %d rx mbuf %d' (%d)\n", i, j, rc);
15078 /* create dma map for the spare rx mbuf cluster */
15079 if (bus_dmamap_create(fp->rx_mbuf_tag,
15081 &fp->rx_mbuf_spare_map)) {
15082 /* XXX unwind and free previous fastpath allocations */
15083 BLOGE(sc, "Failed to create dma map for "
15084 "'fp %d spare rx mbuf' (%d)\n", i, rc);
15088 /***************************/
15089 /* FP RX SGE MBUF DMA MAPS */
15090 /***************************/
15092 /* create a dma tag for the rx sge mbufs */
15093 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */
15095 0, /* boundary limit */
15096 BUS_SPACE_MAXADDR, /* restricted low */
15097 BUS_SPACE_MAXADDR, /* restricted hi */
15098 NULL, /* addr filter() */
15099 NULL, /* addr filter() arg */
15100 BCM_PAGE_SIZE, /* max map size */
15101 1, /* num discontinuous */
15102 BCM_PAGE_SIZE, /* max seg size */
15105 NULL, /* lock() arg */
15106 &fp->rx_sge_mbuf_tag); /* returned dma tag */
15108 /* XXX unwind and free previous fastpath allocations */
15109 BLOGE(sc, "Failed to create dma tag for "
15110 "'fp %d rx sge mbufs' (%d)\n", i, rc);
15114 /* create dma maps for the rx sge mbuf clusters */
15115 for (j = 0; j < RX_SGE_TOTAL; j++) {
15116 if (bus_dmamap_create(fp->rx_sge_mbuf_tag,
15118 &fp->rx_sge_mbuf_chain[j].m_map)) {
15119 /* XXX unwind and free previous fastpath allocations */
15120 BLOGE(sc, "Failed to create dma map for "
15121 "'fp %d rx sge mbuf %d' (%d)\n", i, j, rc);
15126 /* create dma map for the spare rx sge mbuf cluster */
15127 if (bus_dmamap_create(fp->rx_sge_mbuf_tag,
15129 &fp->rx_sge_mbuf_spare_map)) {
15130 /* XXX unwind and free previous fastpath allocations */
15131 BLOGE(sc, "Failed to create dma map for "
15132 "'fp %d spare rx sge mbuf' (%d)\n", i, rc);
15136 /***************************/
15137 /* FP RX TPA MBUF DMA MAPS */
15138 /***************************/
15140 /* create dma maps for the rx tpa mbuf clusters */
15141 max_agg_queues = MAX_AGG_QS(sc);
15143 for (j = 0; j < max_agg_queues; j++) {
15144 if (bus_dmamap_create(fp->rx_mbuf_tag,
15146 &fp->rx_tpa_info[j].bd.m_map)) {
15147 /* XXX unwind and free previous fastpath allocations */
15148 BLOGE(sc, "Failed to create dma map for "
15149 "'fp %d rx tpa mbuf %d' (%d)\n", i, j, rc);
15154 /* create dma map for the spare rx tpa mbuf cluster */
15155 if (bus_dmamap_create(fp->rx_mbuf_tag,
15157 &fp->rx_tpa_info_mbuf_spare_map)) {
15158 /* XXX unwind and free previous fastpath allocations */
15159 BLOGE(sc, "Failed to create dma map for "
15160 "'fp %d spare rx tpa mbuf' (%d)\n", i, rc);
15164 bxe_init_sge_ring_bit_mask(fp);
15171 bxe_free_hsi_mem(struct bxe_softc *sc)
15173 struct bxe_fastpath *fp;
15174 int max_agg_queues;
15177 if (sc->parent_dma_tag == NULL) {
15178 return; /* assume nothing was allocated */
15181 for (i = 0; i < sc->num_queues; i++) {
15184 /*******************/
15185 /* FP STATUS BLOCK */
15186 /*******************/
15188 bxe_dma_free(sc, &fp->sb_dma);
15189 memset(&fp->status_block, 0, sizeof(fp->status_block));
15191 /******************/
15192 /* FP TX BD CHAIN */
15193 /******************/
15195 bxe_dma_free(sc, &fp->tx_dma);
15196 fp->tx_chain = NULL;
15198 /******************/
15199 /* FP RX BD CHAIN */
15200 /******************/
15202 bxe_dma_free(sc, &fp->rx_dma);
15203 fp->rx_chain = NULL;
15205 /*******************/
15206 /* FP RX RCQ CHAIN */
15207 /*******************/
15209 bxe_dma_free(sc, &fp->rcq_dma);
15210 fp->rcq_chain = NULL;
15212 /*******************/
15213 /* FP RX SGE CHAIN */
15214 /*******************/
15216 bxe_dma_free(sc, &fp->rx_sge_dma);
15217 fp->rx_sge_chain = NULL;
15219 /***********************/
15220 /* FP TX MBUF DMA MAPS */
15221 /***********************/
15223 if (fp->tx_mbuf_tag != NULL) {
15224 for (j = 0; j < TX_BD_TOTAL; j++) {
15225 if (fp->tx_mbuf_chain[j].m_map != NULL) {
15226 bus_dmamap_unload(fp->tx_mbuf_tag,
15227 fp->tx_mbuf_chain[j].m_map);
15228 bus_dmamap_destroy(fp->tx_mbuf_tag,
15229 fp->tx_mbuf_chain[j].m_map);
15233 bus_dma_tag_destroy(fp->tx_mbuf_tag);
15234 fp->tx_mbuf_tag = NULL;
15237 /***********************/
15238 /* FP RX MBUF DMA MAPS */
15239 /***********************/
15241 if (fp->rx_mbuf_tag != NULL) {
15242 for (j = 0; j < RX_BD_TOTAL; j++) {
15243 if (fp->rx_mbuf_chain[j].m_map != NULL) {
15244 bus_dmamap_unload(fp->rx_mbuf_tag,
15245 fp->rx_mbuf_chain[j].m_map);
15246 bus_dmamap_destroy(fp->rx_mbuf_tag,
15247 fp->rx_mbuf_chain[j].m_map);
15251 if (fp->rx_mbuf_spare_map != NULL) {
15252 bus_dmamap_unload(fp->rx_mbuf_tag, fp->rx_mbuf_spare_map);
15253 bus_dmamap_destroy(fp->rx_mbuf_tag, fp->rx_mbuf_spare_map);
15256 /***************************/
15257 /* FP RX TPA MBUF DMA MAPS */
15258 /***************************/
15260 max_agg_queues = MAX_AGG_QS(sc);
15262 for (j = 0; j < max_agg_queues; j++) {
15263 if (fp->rx_tpa_info[j].bd.m_map != NULL) {
15264 bus_dmamap_unload(fp->rx_mbuf_tag,
15265 fp->rx_tpa_info[j].bd.m_map);
15266 bus_dmamap_destroy(fp->rx_mbuf_tag,
15267 fp->rx_tpa_info[j].bd.m_map);
15271 if (fp->rx_tpa_info_mbuf_spare_map != NULL) {
15272 bus_dmamap_unload(fp->rx_mbuf_tag,
15273 fp->rx_tpa_info_mbuf_spare_map);
15274 bus_dmamap_destroy(fp->rx_mbuf_tag,
15275 fp->rx_tpa_info_mbuf_spare_map);
15278 bus_dma_tag_destroy(fp->rx_mbuf_tag);
15279 fp->rx_mbuf_tag = NULL;
15282 /***************************/
15283 /* FP RX SGE MBUF DMA MAPS */
15284 /***************************/
15286 if (fp->rx_sge_mbuf_tag != NULL) {
15287 for (j = 0; j < RX_SGE_TOTAL; j++) {
15288 if (fp->rx_sge_mbuf_chain[j].m_map != NULL) {
15289 bus_dmamap_unload(fp->rx_sge_mbuf_tag,
15290 fp->rx_sge_mbuf_chain[j].m_map);
15291 bus_dmamap_destroy(fp->rx_sge_mbuf_tag,
15292 fp->rx_sge_mbuf_chain[j].m_map);
15296 if (fp->rx_sge_mbuf_spare_map != NULL) {
15297 bus_dmamap_unload(fp->rx_sge_mbuf_tag,
15298 fp->rx_sge_mbuf_spare_map);
15299 bus_dmamap_destroy(fp->rx_sge_mbuf_tag,
15300 fp->rx_sge_mbuf_spare_map);
15303 bus_dma_tag_destroy(fp->rx_sge_mbuf_tag);
15304 fp->rx_sge_mbuf_tag = NULL;
15308 /***************************/
15309 /* FW DECOMPRESSION BUFFER */
15310 /***************************/
15312 bxe_dma_free(sc, &sc->gz_buf_dma);
15314 free(sc->gz_strm, M_DEVBUF);
15315 sc->gz_strm = NULL;
15317 /*******************/
15318 /* SLOW PATH QUEUE */
15319 /*******************/
15321 bxe_dma_free(sc, &sc->spq_dma);
15328 bxe_dma_free(sc, &sc->sp_dma);
15335 bxe_dma_free(sc, &sc->eq_dma);
15338 /************************/
15339 /* DEFAULT STATUS BLOCK */
15340 /************************/
15342 bxe_dma_free(sc, &sc->def_sb_dma);
15345 bus_dma_tag_destroy(sc->parent_dma_tag);
15346 sc->parent_dma_tag = NULL;
15350 * Previous driver DMAE transaction may have occurred when pre-boot stage
15351 * ended and boot began. This would invalidate the addresses of the
15352 * transaction, resulting in was-error bit set in the PCI causing all
15353 * hw-to-host PCIe transactions to timeout. If this happened we want to clear
15354 * the interrupt which detected this from the pglueb and the was-done bit
15357 bxe_prev_interrupted_dmae(struct bxe_softc *sc)
15361 if (!CHIP_IS_E1x(sc)) {
15362 val = REG_RD(sc, PGLUE_B_REG_PGLUE_B_INT_STS);
15363 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
15364 BLOGD(sc, DBG_LOAD,
15365 "Clearing 'was-error' bit that was set in pglueb");
15366 REG_WR(sc, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, 1 << SC_FUNC(sc));
15372 bxe_prev_mcp_done(struct bxe_softc *sc)
15374 uint32_t rc = bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE,
15375 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
15377 BLOGE(sc, "MCP response failure, aborting\n");
15384 static struct bxe_prev_list_node *
15385 bxe_prev_path_get_entry(struct bxe_softc *sc)
15387 struct bxe_prev_list_node *tmp;
15389 LIST_FOREACH(tmp, &bxe_prev_list, node) {
15390 if ((sc->pcie_bus == tmp->bus) &&
15391 (sc->pcie_device == tmp->slot) &&
15392 (SC_PATH(sc) == tmp->path)) {
15401 bxe_prev_is_path_marked(struct bxe_softc *sc)
15403 struct bxe_prev_list_node *tmp;
15406 mtx_lock(&bxe_prev_mtx);
15408 tmp = bxe_prev_path_get_entry(sc);
15411 BLOGD(sc, DBG_LOAD,
15412 "Path %d/%d/%d was marked by AER\n",
15413 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15416 BLOGD(sc, DBG_LOAD,
15417 "Path %d/%d/%d was already cleaned from previous drivers\n",
15418 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15422 mtx_unlock(&bxe_prev_mtx);
15428 bxe_prev_mark_path(struct bxe_softc *sc,
15429 uint8_t after_undi)
15431 struct bxe_prev_list_node *tmp;
15433 mtx_lock(&bxe_prev_mtx);
15435 /* Check whether the entry for this path already exists */
15436 tmp = bxe_prev_path_get_entry(sc);
15439 BLOGD(sc, DBG_LOAD,
15440 "Re-marking AER in path %d/%d/%d\n",
15441 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15443 BLOGD(sc, DBG_LOAD,
15444 "Removing AER indication from path %d/%d/%d\n",
15445 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15449 mtx_unlock(&bxe_prev_mtx);
15453 mtx_unlock(&bxe_prev_mtx);
15455 /* Create an entry for this path and add it */
15456 tmp = malloc(sizeof(struct bxe_prev_list_node), M_DEVBUF,
15457 (M_NOWAIT | M_ZERO));
15459 BLOGE(sc, "Failed to allocate 'bxe_prev_list_node'\n");
15463 tmp->bus = sc->pcie_bus;
15464 tmp->slot = sc->pcie_device;
15465 tmp->path = SC_PATH(sc);
15467 tmp->undi = after_undi ? (1 << SC_PORT(sc)) : 0;
15469 mtx_lock(&bxe_prev_mtx);
15471 BLOGD(sc, DBG_LOAD,
15472 "Marked path %d/%d/%d - finished previous unload\n",
15473 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15474 LIST_INSERT_HEAD(&bxe_prev_list, tmp, node);
15476 mtx_unlock(&bxe_prev_mtx);
15482 bxe_do_flr(struct bxe_softc *sc)
15486 /* only E2 and onwards support FLR */
15487 if (CHIP_IS_E1x(sc)) {
15488 BLOGD(sc, DBG_LOAD, "FLR not supported in E1/E1H\n");
15492 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
15493 if (sc->devinfo.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
15494 BLOGD(sc, DBG_LOAD, "FLR not supported by BC_VER: 0x%08x\n",
15495 sc->devinfo.bc_ver);
15499 /* Wait for Transaction Pending bit clean */
15500 for (i = 0; i < 4; i++) {
15502 DELAY(((1 << (i - 1)) * 100) * 1000);
15505 if (!bxe_is_pcie_pending(sc)) {
15510 BLOGE(sc, "PCIE transaction is not cleared, "
15511 "proceeding with reset anyway\n");
15515 BLOGD(sc, DBG_LOAD, "Initiating FLR\n");
15516 bxe_fw_command(sc, DRV_MSG_CODE_INITIATE_FLR, 0);
15521 struct bxe_mac_vals {
15522 uint32_t xmac_addr;
15524 uint32_t emac_addr;
15526 uint32_t umac_addr;
15528 uint32_t bmac_addr;
15529 uint32_t bmac_val[2];
15533 bxe_prev_unload_close_mac(struct bxe_softc *sc,
15534 struct bxe_mac_vals *vals)
15536 uint32_t val, base_addr, offset, mask, reset_reg;
15537 uint8_t mac_stopped = FALSE;
15538 uint8_t port = SC_PORT(sc);
15539 uint32_t wb_data[2];
15541 /* reset addresses as they also mark which values were changed */
15542 vals->bmac_addr = 0;
15543 vals->umac_addr = 0;
15544 vals->xmac_addr = 0;
15545 vals->emac_addr = 0;
15547 reset_reg = REG_RD(sc, MISC_REG_RESET_REG_2);
15549 if (!CHIP_IS_E3(sc)) {
15550 val = REG_RD(sc, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
15551 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
15552 if ((mask & reset_reg) && val) {
15553 BLOGD(sc, DBG_LOAD, "Disable BMAC Rx\n");
15554 base_addr = SC_PORT(sc) ? NIG_REG_INGRESS_BMAC1_MEM
15555 : NIG_REG_INGRESS_BMAC0_MEM;
15556 offset = CHIP_IS_E2(sc) ? BIGMAC2_REGISTER_BMAC_CONTROL
15557 : BIGMAC_REGISTER_BMAC_CONTROL;
15560 * use rd/wr since we cannot use dmae. This is safe
15561 * since MCP won't access the bus due to the request
15562 * to unload, and no function on the path can be
15563 * loaded at this time.
15565 wb_data[0] = REG_RD(sc, base_addr + offset);
15566 wb_data[1] = REG_RD(sc, base_addr + offset + 0x4);
15567 vals->bmac_addr = base_addr + offset;
15568 vals->bmac_val[0] = wb_data[0];
15569 vals->bmac_val[1] = wb_data[1];
15570 wb_data[0] &= ~ELINK_BMAC_CONTROL_RX_ENABLE;
15571 REG_WR(sc, vals->bmac_addr, wb_data[0]);
15572 REG_WR(sc, vals->bmac_addr + 0x4, wb_data[1]);
15575 BLOGD(sc, DBG_LOAD, "Disable EMAC Rx\n");
15576 vals->emac_addr = NIG_REG_NIG_EMAC0_EN + SC_PORT(sc)*4;
15577 vals->emac_val = REG_RD(sc, vals->emac_addr);
15578 REG_WR(sc, vals->emac_addr, 0);
15579 mac_stopped = TRUE;
15581 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
15582 BLOGD(sc, DBG_LOAD, "Disable XMAC Rx\n");
15583 base_addr = SC_PORT(sc) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
15584 val = REG_RD(sc, base_addr + XMAC_REG_PFC_CTRL_HI);
15585 REG_WR(sc, base_addr + XMAC_REG_PFC_CTRL_HI, val & ~(1 << 1));
15586 REG_WR(sc, base_addr + XMAC_REG_PFC_CTRL_HI, val | (1 << 1));
15587 vals->xmac_addr = base_addr + XMAC_REG_CTRL;
15588 vals->xmac_val = REG_RD(sc, vals->xmac_addr);
15589 REG_WR(sc, vals->xmac_addr, 0);
15590 mac_stopped = TRUE;
15593 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
15594 if (mask & reset_reg) {
15595 BLOGD(sc, DBG_LOAD, "Disable UMAC Rx\n");
15596 base_addr = SC_PORT(sc) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
15597 vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
15598 vals->umac_val = REG_RD(sc, vals->umac_addr);
15599 REG_WR(sc, vals->umac_addr, 0);
15600 mac_stopped = TRUE;
15609 #define BXE_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
15610 #define BXE_PREV_UNDI_RCQ(val) ((val) & 0xffff)
15611 #define BXE_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
15612 #define BXE_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
15615 bxe_prev_unload_undi_inc(struct bxe_softc *sc,
15620 uint32_t tmp_reg = REG_RD(sc, BXE_PREV_UNDI_PROD_ADDR(port));
15622 rcq = BXE_PREV_UNDI_RCQ(tmp_reg) + inc;
15623 bd = BXE_PREV_UNDI_BD(tmp_reg) + inc;
15625 tmp_reg = BXE_PREV_UNDI_PROD(rcq, bd);
15626 REG_WR(sc, BXE_PREV_UNDI_PROD_ADDR(port), tmp_reg);
15628 BLOGD(sc, DBG_LOAD,
15629 "UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
15634 bxe_prev_unload_common(struct bxe_softc *sc)
15636 uint32_t reset_reg, tmp_reg = 0, rc;
15637 uint8_t prev_undi = FALSE;
15638 struct bxe_mac_vals mac_vals;
15639 uint32_t timer_count = 1000;
15643 * It is possible a previous function received 'common' answer,
15644 * but hasn't loaded yet, therefore creating a scenario of
15645 * multiple functions receiving 'common' on the same path.
15647 BLOGD(sc, DBG_LOAD, "Common unload Flow\n");
15649 memset(&mac_vals, 0, sizeof(mac_vals));
15651 if (bxe_prev_is_path_marked(sc)) {
15652 return (bxe_prev_mcp_done(sc));
15655 reset_reg = REG_RD(sc, MISC_REG_RESET_REG_1);
15657 /* Reset should be performed after BRB is emptied */
15658 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
15659 /* Close the MAC Rx to prevent BRB from filling up */
15660 bxe_prev_unload_close_mac(sc, &mac_vals);
15662 /* close LLH filters towards the BRB */
15663 elink_set_rx_filter(&sc->link_params, 0);
15666 * Check if the UNDI driver was previously loaded.
15667 * UNDI driver initializes CID offset for normal bell to 0x7
15669 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
15670 tmp_reg = REG_RD(sc, DORQ_REG_NORM_CID_OFST);
15671 if (tmp_reg == 0x7) {
15672 BLOGD(sc, DBG_LOAD, "UNDI previously loaded\n");
15674 /* clear the UNDI indication */
15675 REG_WR(sc, DORQ_REG_NORM_CID_OFST, 0);
15676 /* clear possible idle check errors */
15677 REG_RD(sc, NIG_REG_NIG_INT_STS_CLR_0);
15681 /* wait until BRB is empty */
15682 tmp_reg = REG_RD(sc, BRB1_REG_NUM_OF_FULL_BLOCKS);
15683 while (timer_count) {
15684 prev_brb = tmp_reg;
15686 tmp_reg = REG_RD(sc, BRB1_REG_NUM_OF_FULL_BLOCKS);
15691 BLOGD(sc, DBG_LOAD, "BRB still has 0x%08x\n", tmp_reg);
15693 /* reset timer as long as BRB actually gets emptied */
15694 if (prev_brb > tmp_reg) {
15695 timer_count = 1000;
15700 /* If UNDI resides in memory, manually increment it */
15702 bxe_prev_unload_undi_inc(sc, SC_PORT(sc), 1);
15708 if (!timer_count) {
15709 BLOGE(sc, "Failed to empty BRB\n");
15713 /* No packets are in the pipeline, path is ready for reset */
15714 bxe_reset_common(sc);
15716 if (mac_vals.xmac_addr) {
15717 REG_WR(sc, mac_vals.xmac_addr, mac_vals.xmac_val);
15719 if (mac_vals.umac_addr) {
15720 REG_WR(sc, mac_vals.umac_addr, mac_vals.umac_val);
15722 if (mac_vals.emac_addr) {
15723 REG_WR(sc, mac_vals.emac_addr, mac_vals.emac_val);
15725 if (mac_vals.bmac_addr) {
15726 REG_WR(sc, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
15727 REG_WR(sc, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
15730 rc = bxe_prev_mark_path(sc, prev_undi);
15732 bxe_prev_mcp_done(sc);
15736 return (bxe_prev_mcp_done(sc));
15740 bxe_prev_unload_uncommon(struct bxe_softc *sc)
15744 BLOGD(sc, DBG_LOAD, "Uncommon unload Flow\n");
15746 /* Test if previous unload process was already finished for this path */
15747 if (bxe_prev_is_path_marked(sc)) {
15748 return (bxe_prev_mcp_done(sc));
15751 BLOGD(sc, DBG_LOAD, "Path is unmarked\n");
15754 * If function has FLR capabilities, and existing FW version matches
15755 * the one required, then FLR will be sufficient to clean any residue
15756 * left by previous driver
15758 rc = bxe_nic_load_analyze_req(sc, FW_MSG_CODE_DRV_LOAD_FUNCTION);
15760 /* fw version is good */
15761 BLOGD(sc, DBG_LOAD, "FW version matches our own, attempting FLR\n");
15762 rc = bxe_do_flr(sc);
15766 /* FLR was performed */
15767 BLOGD(sc, DBG_LOAD, "FLR successful\n");
15771 BLOGD(sc, DBG_LOAD, "Could not FLR\n");
15773 /* Close the MCP request, return failure*/
15774 rc = bxe_prev_mcp_done(sc);
15776 rc = BXE_PREV_WAIT_NEEDED;
15783 bxe_prev_unload(struct bxe_softc *sc)
15785 int time_counter = 10;
15786 uint32_t fw, hw_lock_reg, hw_lock_val;
15790 * Clear HW from errors which may have resulted from an interrupted
15791 * DMAE transaction.
15793 bxe_prev_interrupted_dmae(sc);
15795 /* Release previously held locks */
15797 (SC_FUNC(sc) <= 5) ?
15798 (MISC_REG_DRIVER_CONTROL_1 + SC_FUNC(sc) * 8) :
15799 (MISC_REG_DRIVER_CONTROL_7 + (SC_FUNC(sc) - 6) * 8);
15801 hw_lock_val = (REG_RD(sc, hw_lock_reg));
15803 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
15804 BLOGD(sc, DBG_LOAD, "Releasing previously held NVRAM lock\n");
15805 REG_WR(sc, MCP_REG_MCPR_NVM_SW_ARB,
15806 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << SC_PORT(sc)));
15808 BLOGD(sc, DBG_LOAD, "Releasing previously held HW lock\n");
15809 REG_WR(sc, hw_lock_reg, 0xffffffff);
15811 BLOGD(sc, DBG_LOAD, "No need to release HW/NVRAM locks\n");
15814 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(sc, MCP_REG_MCPR_ACCESS_LOCK)) {
15815 BLOGD(sc, DBG_LOAD, "Releasing previously held ALR\n");
15816 REG_WR(sc, MCP_REG_MCPR_ACCESS_LOCK, 0);
15820 /* Lock MCP using an unload request */
15821 fw = bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
15823 BLOGE(sc, "MCP response failure, aborting\n");
15828 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
15829 rc = bxe_prev_unload_common(sc);
15833 /* non-common reply from MCP night require looping */
15834 rc = bxe_prev_unload_uncommon(sc);
15835 if (rc != BXE_PREV_WAIT_NEEDED) {
15840 } while (--time_counter);
15842 if (!time_counter || rc) {
15843 BLOGE(sc, "Failed to unload previous driver!"
15844 " time_counter %d rc %d\n", time_counter, rc);
15852 bxe_dcbx_set_state(struct bxe_softc *sc,
15854 uint32_t dcbx_enabled)
15856 if (!CHIP_IS_E1x(sc)) {
15857 sc->dcb_state = dcb_on;
15858 sc->dcbx_enabled = dcbx_enabled;
15860 sc->dcb_state = FALSE;
15861 sc->dcbx_enabled = BXE_DCBX_ENABLED_INVALID;
15863 BLOGD(sc, DBG_LOAD,
15864 "DCB state [%s:%s]\n",
15865 dcb_on ? "ON" : "OFF",
15866 (dcbx_enabled == BXE_DCBX_ENABLED_OFF) ? "user-mode" :
15867 (dcbx_enabled == BXE_DCBX_ENABLED_ON_NEG_OFF) ? "on-chip static" :
15868 (dcbx_enabled == BXE_DCBX_ENABLED_ON_NEG_ON) ?
15869 "on-chip with negotiation" : "invalid");
15872 /* must be called after sriov-enable */
15874 bxe_set_qm_cid_count(struct bxe_softc *sc)
15876 int cid_count = BXE_L2_MAX_CID(sc);
15878 if (IS_SRIOV(sc)) {
15879 cid_count += BXE_VF_CIDS;
15882 if (CNIC_SUPPORT(sc)) {
15883 cid_count += CNIC_CID_MAX;
15886 return (roundup(cid_count, QM_CID_ROUND));
15890 bxe_init_multi_cos(struct bxe_softc *sc)
15894 uint32_t pri_map = 0; /* XXX change to user config */
15896 for (pri = 0; pri < BXE_MAX_PRIORITY; pri++) {
15897 cos = ((pri_map & (0xf << (pri * 4))) >> (pri * 4));
15898 if (cos < sc->max_cos) {
15899 sc->prio_to_cos[pri] = cos;
15901 BLOGW(sc, "Invalid COS %d for priority %d "
15902 "(max COS is %d), setting to 0\n",
15903 cos, pri, (sc->max_cos - 1));
15904 sc->prio_to_cos[pri] = 0;
15910 bxe_sysctl_state(SYSCTL_HANDLER_ARGS)
15912 struct bxe_softc *sc;
15916 error = sysctl_handle_int(oidp, &result, 0, req);
15918 if (error || !req->newptr) {
15924 sc = (struct bxe_softc *)arg1;
15926 BLOGI(sc, "... dumping driver state ...\n");
15927 temp = SHMEM2_RD(sc, temperature_in_half_celsius);
15928 BLOGI(sc, "\t Device Temperature = %d Celsius\n", (temp/2));
15935 bxe_sysctl_eth_stat(SYSCTL_HANDLER_ARGS)
15937 struct bxe_softc *sc = (struct bxe_softc *)arg1;
15938 uint32_t *eth_stats = (uint32_t *)&sc->eth_stats;
15940 uint64_t value = 0;
15941 int index = (int)arg2;
15943 if (index >= BXE_NUM_ETH_STATS) {
15944 BLOGE(sc, "bxe_eth_stats index out of range (%d)\n", index);
15948 offset = (eth_stats + bxe_eth_stats_arr[index].offset);
15950 switch (bxe_eth_stats_arr[index].size) {
15952 value = (uint64_t)*offset;
15955 value = HILO_U64(*offset, *(offset + 1));
15958 BLOGE(sc, "Invalid bxe_eth_stats size (index=%d size=%d)\n",
15959 index, bxe_eth_stats_arr[index].size);
15963 return (sysctl_handle_64(oidp, &value, 0, req));
15967 bxe_sysctl_eth_q_stat(SYSCTL_HANDLER_ARGS)
15969 struct bxe_softc *sc = (struct bxe_softc *)arg1;
15970 uint32_t *eth_stats;
15972 uint64_t value = 0;
15973 uint32_t q_stat = (uint32_t)arg2;
15974 uint32_t fp_index = ((q_stat >> 16) & 0xffff);
15975 uint32_t index = (q_stat & 0xffff);
15977 eth_stats = (uint32_t *)&sc->fp[fp_index].eth_q_stats;
15979 if (index >= BXE_NUM_ETH_Q_STATS) {
15980 BLOGE(sc, "bxe_eth_q_stats index out of range (%d)\n", index);
15984 offset = (eth_stats + bxe_eth_q_stats_arr[index].offset);
15986 switch (bxe_eth_q_stats_arr[index].size) {
15988 value = (uint64_t)*offset;
15991 value = HILO_U64(*offset, *(offset + 1));
15994 BLOGE(sc, "Invalid bxe_eth_q_stats size (index=%d size=%d)\n",
15995 index, bxe_eth_q_stats_arr[index].size);
15999 return (sysctl_handle_64(oidp, &value, 0, req));
16002 static void bxe_force_link_reset(struct bxe_softc *sc)
16005 bxe_acquire_phy_lock(sc);
16006 elink_link_reset(&sc->link_params, &sc->link_vars, 1);
16007 bxe_release_phy_lock(sc);
16011 bxe_sysctl_pauseparam(SYSCTL_HANDLER_ARGS)
16013 struct bxe_softc *sc = (struct bxe_softc *)arg1;;
16014 uint32_t cfg_idx = bxe_get_link_cfg_idx(sc);
16020 error = sysctl_handle_int(oidp, &sc->bxe_pause_param, 0, req);
16022 if (error || !req->newptr) {
16025 if ((sc->bxe_pause_param < 0) || (sc->bxe_pause_param > 8)) {
16026 BLOGW(sc, "invalid pause param (%d) - use intergers between 1 & 8\n",sc->bxe_pause_param);
16027 sc->bxe_pause_param = 8;
16030 result = (sc->bxe_pause_param << PORT_FEATURE_FLOW_CONTROL_SHIFT);
16033 if((result & 0x400) && !(sc->port.supported[cfg_idx] & ELINK_SUPPORTED_Autoneg)) {
16034 BLOGW(sc, "Does not support Autoneg pause_param %d\n", sc->bxe_pause_param);
16040 sc->link_params.req_flow_ctrl[cfg_idx] = ELINK_FLOW_CTRL_AUTO;
16041 if(result & ELINK_FLOW_CTRL_RX)
16042 sc->link_params.req_flow_ctrl[cfg_idx] |= ELINK_FLOW_CTRL_RX;
16044 if(result & ELINK_FLOW_CTRL_TX)
16045 sc->link_params.req_flow_ctrl[cfg_idx] |= ELINK_FLOW_CTRL_TX;
16046 if(sc->link_params.req_flow_ctrl[cfg_idx] == ELINK_FLOW_CTRL_AUTO)
16047 sc->link_params.req_flow_ctrl[cfg_idx] = ELINK_FLOW_CTRL_NONE;
16049 if(result & 0x400) {
16050 if (sc->link_params.req_line_speed[cfg_idx] == ELINK_SPEED_AUTO_NEG) {
16051 sc->link_params.req_flow_ctrl[cfg_idx] =
16052 ELINK_FLOW_CTRL_AUTO;
16054 sc->link_params.req_fc_auto_adv = 0;
16055 if (result & ELINK_FLOW_CTRL_RX)
16056 sc->link_params.req_fc_auto_adv |= ELINK_FLOW_CTRL_RX;
16058 if (result & ELINK_FLOW_CTRL_TX)
16059 sc->link_params.req_fc_auto_adv |= ELINK_FLOW_CTRL_TX;
16060 if (!sc->link_params.req_fc_auto_adv)
16061 sc->link_params.req_fc_auto_adv |= ELINK_FLOW_CTRL_NONE;
16064 if (sc->link_vars.link_up) {
16065 bxe_stats_handle(sc, STATS_EVENT_STOP);
16067 if (sc->ifnet->if_drv_flags & IFF_DRV_RUNNING) {
16068 bxe_force_link_reset(sc);
16069 bxe_acquire_phy_lock(sc);
16071 rc = elink_phy_init(&sc->link_params, &sc->link_vars);
16073 bxe_release_phy_lock(sc);
16075 bxe_calc_fc_adv(sc);
16083 bxe_add_sysctls(struct bxe_softc *sc)
16085 struct sysctl_ctx_list *ctx;
16086 struct sysctl_oid_list *children;
16087 struct sysctl_oid *queue_top, *queue;
16088 struct sysctl_oid_list *queue_top_children, *queue_children;
16089 char queue_num_buf[32];
16093 ctx = device_get_sysctl_ctx(sc->dev);
16094 children = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev));
16096 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "version",
16097 CTLFLAG_RD, BXE_DRIVER_VERSION, 0,
16100 snprintf(sc->fw_ver_str, sizeof(sc->fw_ver_str), "%d.%d.%d.%d",
16101 BCM_5710_FW_MAJOR_VERSION,
16102 BCM_5710_FW_MINOR_VERSION,
16103 BCM_5710_FW_REVISION_VERSION,
16104 BCM_5710_FW_ENGINEERING_VERSION);
16106 snprintf(sc->mf_mode_str, sizeof(sc->mf_mode_str), "%s",
16107 ((sc->devinfo.mf_info.mf_mode == SINGLE_FUNCTION) ? "Single" :
16108 (sc->devinfo.mf_info.mf_mode == MULTI_FUNCTION_SD) ? "MF-SD" :
16109 (sc->devinfo.mf_info.mf_mode == MULTI_FUNCTION_SI) ? "MF-SI" :
16110 (sc->devinfo.mf_info.mf_mode == MULTI_FUNCTION_AFEX) ? "MF-AFEX" :
16112 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "mf_vnics",
16113 CTLFLAG_RD, &sc->devinfo.mf_info.vnics_per_port, 0,
16114 "multifunction vnics per port");
16116 snprintf(sc->pci_link_str, sizeof(sc->pci_link_str), "%s x%d",
16117 ((sc->devinfo.pcie_link_speed == 1) ? "2.5GT/s" :
16118 (sc->devinfo.pcie_link_speed == 2) ? "5.0GT/s" :
16119 (sc->devinfo.pcie_link_speed == 4) ? "8.0GT/s" :
16121 sc->devinfo.pcie_link_width);
16123 sc->debug = bxe_debug;
16125 #if __FreeBSD_version >= 900000
16126 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "bc_version",
16127 CTLFLAG_RD, sc->devinfo.bc_ver_str, 0,
16128 "bootcode version");
16129 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "fw_version",
16130 CTLFLAG_RD, sc->fw_ver_str, 0,
16131 "firmware version");
16132 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "mf_mode",
16133 CTLFLAG_RD, sc->mf_mode_str, 0,
16134 "multifunction mode");
16135 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "mac_addr",
16136 CTLFLAG_RD, sc->mac_addr_str, 0,
16138 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "pci_link",
16139 CTLFLAG_RD, sc->pci_link_str, 0,
16140 "pci link status");
16141 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO, "debug",
16142 CTLFLAG_RW, &sc->debug,
16143 "debug logging mode");
16145 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "bc_version",
16146 CTLFLAG_RD, &sc->devinfo.bc_ver_str, 0,
16147 "bootcode version");
16148 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "fw_version",
16149 CTLFLAG_RD, &sc->fw_ver_str, 0,
16150 "firmware version");
16151 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "mf_mode",
16152 CTLFLAG_RD, &sc->mf_mode_str, 0,
16153 "multifunction mode");
16154 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "mac_addr",
16155 CTLFLAG_RD, &sc->mac_addr_str, 0,
16157 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "pci_link",
16158 CTLFLAG_RD, &sc->pci_link_str, 0,
16159 "pci link status");
16160 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "debug",
16161 CTLFLAG_RW, &sc->debug, 0,
16162 "debug logging mode");
16163 #endif /* #if __FreeBSD_version >= 900000 */
16165 sc->trigger_grcdump = 0;
16166 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "trigger_grcdump",
16167 CTLFLAG_RW, &sc->trigger_grcdump, 0,
16168 "trigger grcdump should be invoked"
16169 " before collecting grcdump");
16171 sc->grcdump_started = 0;
16172 sc->grcdump_done = 0;
16173 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "grcdump_done",
16174 CTLFLAG_RD, &sc->grcdump_done, 0,
16175 "set by driver when grcdump is done");
16177 sc->rx_budget = bxe_rx_budget;
16178 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "rx_budget",
16179 CTLFLAG_RW, &sc->rx_budget, 0,
16180 "rx processing budget");
16182 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pause_param",
16183 CTLTYPE_UINT | CTLFLAG_RW, sc, 0,
16184 bxe_sysctl_pauseparam, "IU",
16185 "need pause frames- DEF:0/TX:1/RX:2/BOTH:3/AUTO:4/AUTOTX:5/AUTORX:6/AUTORXTX:7/NONE:8");
16188 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "state",
16189 CTLTYPE_UINT | CTLFLAG_RW, sc, 0,
16190 bxe_sysctl_state, "IU", "dump driver state");
16192 for (i = 0; i < BXE_NUM_ETH_STATS; i++) {
16193 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
16194 bxe_eth_stats_arr[i].string,
16195 CTLTYPE_U64 | CTLFLAG_RD, sc, i,
16196 bxe_sysctl_eth_stat, "LU",
16197 bxe_eth_stats_arr[i].string);
16200 /* add a new parent node for all queues "dev.bxe.#.queue" */
16201 queue_top = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "queue",
16202 CTLFLAG_RD, NULL, "queue");
16203 queue_top_children = SYSCTL_CHILDREN(queue_top);
16205 for (i = 0; i < sc->num_queues; i++) {
16206 /* add a new parent node for a single queue "dev.bxe.#.queue.#" */
16207 snprintf(queue_num_buf, sizeof(queue_num_buf), "%d", i);
16208 queue = SYSCTL_ADD_NODE(ctx, queue_top_children, OID_AUTO,
16209 queue_num_buf, CTLFLAG_RD, NULL,
16211 queue_children = SYSCTL_CHILDREN(queue);
16213 for (j = 0; j < BXE_NUM_ETH_Q_STATS; j++) {
16214 q_stat = ((i << 16) | j);
16215 SYSCTL_ADD_PROC(ctx, queue_children, OID_AUTO,
16216 bxe_eth_q_stats_arr[j].string,
16217 CTLTYPE_U64 | CTLFLAG_RD, sc, q_stat,
16218 bxe_sysctl_eth_q_stat, "LU",
16219 bxe_eth_q_stats_arr[j].string);
16225 bxe_alloc_buf_rings(struct bxe_softc *sc)
16227 #if __FreeBSD_version >= 901504
16230 struct bxe_fastpath *fp;
16232 for (i = 0; i < sc->num_queues; i++) {
16236 fp->tx_br = buf_ring_alloc(BXE_BR_SIZE, M_DEVBUF,
16237 M_NOWAIT, &fp->tx_mtx);
16238 if (fp->tx_br == NULL)
16246 bxe_free_buf_rings(struct bxe_softc *sc)
16248 #if __FreeBSD_version >= 901504
16251 struct bxe_fastpath *fp;
16253 for (i = 0; i < sc->num_queues; i++) {
16258 buf_ring_free(fp->tx_br, M_DEVBUF);
16267 bxe_init_fp_mutexs(struct bxe_softc *sc)
16270 struct bxe_fastpath *fp;
16272 for (i = 0; i < sc->num_queues; i++) {
16276 snprintf(fp->tx_mtx_name, sizeof(fp->tx_mtx_name),
16277 "bxe%d_fp%d_tx_lock", sc->unit, i);
16278 mtx_init(&fp->tx_mtx, fp->tx_mtx_name, NULL, MTX_DEF);
16280 snprintf(fp->rx_mtx_name, sizeof(fp->rx_mtx_name),
16281 "bxe%d_fp%d_rx_lock", sc->unit, i);
16282 mtx_init(&fp->rx_mtx, fp->rx_mtx_name, NULL, MTX_DEF);
16287 bxe_destroy_fp_mutexs(struct bxe_softc *sc)
16290 struct bxe_fastpath *fp;
16292 for (i = 0; i < sc->num_queues; i++) {
16296 if (mtx_initialized(&fp->tx_mtx)) {
16297 mtx_destroy(&fp->tx_mtx);
16300 if (mtx_initialized(&fp->rx_mtx)) {
16301 mtx_destroy(&fp->rx_mtx);
16308 * Device attach function.
16310 * Allocates device resources, performs secondary chip identification, and
16311 * initializes driver instance variables. This function is called from driver
16312 * load after a successful probe.
16315 * 0 = Success, >0 = Failure
16318 bxe_attach(device_t dev)
16320 struct bxe_softc *sc;
16322 sc = device_get_softc(dev);
16324 BLOGD(sc, DBG_LOAD, "Starting attach...\n");
16326 sc->state = BXE_STATE_CLOSED;
16329 sc->unit = device_get_unit(dev);
16331 BLOGD(sc, DBG_LOAD, "softc = %p\n", sc);
16333 sc->pcie_bus = pci_get_bus(dev);
16334 sc->pcie_device = pci_get_slot(dev);
16335 sc->pcie_func = pci_get_function(dev);
16337 /* enable bus master capability */
16338 pci_enable_busmaster(dev);
16341 if (bxe_allocate_bars(sc) != 0) {
16345 /* initialize the mutexes */
16346 bxe_init_mutexes(sc);
16348 /* prepare the periodic callout */
16349 callout_init(&sc->periodic_callout, 0);
16351 /* prepare the chip taskqueue */
16352 sc->chip_tq_flags = CHIP_TQ_NONE;
16353 snprintf(sc->chip_tq_name, sizeof(sc->chip_tq_name),
16354 "bxe%d_chip_tq", sc->unit);
16355 TASK_INIT(&sc->chip_tq_task, 0, bxe_handle_chip_tq, sc);
16356 sc->chip_tq = taskqueue_create(sc->chip_tq_name, M_NOWAIT,
16357 taskqueue_thread_enqueue,
16359 taskqueue_start_threads(&sc->chip_tq, 1, PWAIT, /* lower priority */
16360 "%s", sc->chip_tq_name);
16362 TIMEOUT_TASK_INIT(taskqueue_thread,
16363 &sc->sp_err_timeout_task, 0, bxe_sp_err_timeout_task, sc);
16366 /* get device info and set params */
16367 if (bxe_get_device_info(sc) != 0) {
16368 BLOGE(sc, "getting device info\n");
16369 bxe_deallocate_bars(sc);
16370 pci_disable_busmaster(dev);
16374 /* get final misc params */
16375 bxe_get_params(sc);
16377 /* set the default MTU (changed via ifconfig) */
16378 sc->mtu = ETHERMTU;
16380 bxe_set_modes_bitmap(sc);
16383 * If in AFEX mode and the function is configured for FCoE
16384 * then bail... no L2 allowed.
16387 /* get phy settings from shmem and 'and' against admin settings */
16388 bxe_get_phy_info(sc);
16390 /* initialize the FreeBSD ifnet interface */
16391 if (bxe_init_ifnet(sc) != 0) {
16392 bxe_release_mutexes(sc);
16393 bxe_deallocate_bars(sc);
16394 pci_disable_busmaster(dev);
16398 if (bxe_add_cdev(sc) != 0) {
16399 if (sc->ifnet != NULL) {
16400 ether_ifdetach(sc->ifnet);
16402 ifmedia_removeall(&sc->ifmedia);
16403 bxe_release_mutexes(sc);
16404 bxe_deallocate_bars(sc);
16405 pci_disable_busmaster(dev);
16409 /* allocate device interrupts */
16410 if (bxe_interrupt_alloc(sc) != 0) {
16412 if (sc->ifnet != NULL) {
16413 ether_ifdetach(sc->ifnet);
16415 ifmedia_removeall(&sc->ifmedia);
16416 bxe_release_mutexes(sc);
16417 bxe_deallocate_bars(sc);
16418 pci_disable_busmaster(dev);
16422 bxe_init_fp_mutexs(sc);
16424 if (bxe_alloc_buf_rings(sc) != 0) {
16425 bxe_free_buf_rings(sc);
16426 bxe_interrupt_free(sc);
16428 if (sc->ifnet != NULL) {
16429 ether_ifdetach(sc->ifnet);
16431 ifmedia_removeall(&sc->ifmedia);
16432 bxe_release_mutexes(sc);
16433 bxe_deallocate_bars(sc);
16434 pci_disable_busmaster(dev);
16439 if (bxe_alloc_ilt_mem(sc) != 0) {
16440 bxe_free_buf_rings(sc);
16441 bxe_interrupt_free(sc);
16443 if (sc->ifnet != NULL) {
16444 ether_ifdetach(sc->ifnet);
16446 ifmedia_removeall(&sc->ifmedia);
16447 bxe_release_mutexes(sc);
16448 bxe_deallocate_bars(sc);
16449 pci_disable_busmaster(dev);
16453 /* allocate the host hardware/software hsi structures */
16454 if (bxe_alloc_hsi_mem(sc) != 0) {
16455 bxe_free_ilt_mem(sc);
16456 bxe_free_buf_rings(sc);
16457 bxe_interrupt_free(sc);
16459 if (sc->ifnet != NULL) {
16460 ether_ifdetach(sc->ifnet);
16462 ifmedia_removeall(&sc->ifmedia);
16463 bxe_release_mutexes(sc);
16464 bxe_deallocate_bars(sc);
16465 pci_disable_busmaster(dev);
16469 /* need to reset chip if UNDI was active */
16470 if (IS_PF(sc) && !BXE_NOMCP(sc)) {
16473 (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_mb_header) &
16474 DRV_MSG_SEQ_NUMBER_MASK);
16475 BLOGD(sc, DBG_LOAD, "prev unload fw_seq 0x%04x\n", sc->fw_seq);
16476 bxe_prev_unload(sc);
16481 bxe_dcbx_set_state(sc, FALSE, BXE_DCBX_ENABLED_OFF);
16483 if (SHMEM2_HAS(sc, dcbx_lldp_params_offset) &&
16484 SHMEM2_HAS(sc, dcbx_lldp_dcbx_stat_offset) &&
16485 SHMEM2_RD(sc, dcbx_lldp_params_offset) &&
16486 SHMEM2_RD(sc, dcbx_lldp_dcbx_stat_offset)) {
16487 bxe_dcbx_set_state(sc, TRUE, BXE_DCBX_ENABLED_ON_NEG_ON);
16488 bxe_dcbx_init_params(sc);
16490 bxe_dcbx_set_state(sc, FALSE, BXE_DCBX_ENABLED_OFF);
16494 /* calculate qm_cid_count */
16495 sc->qm_cid_count = bxe_set_qm_cid_count(sc);
16496 BLOGD(sc, DBG_LOAD, "qm_cid_count=%d\n", sc->qm_cid_count);
16499 bxe_init_multi_cos(sc);
16501 bxe_add_sysctls(sc);
16507 * Device detach function.
16509 * Stops the controller, resets the controller, and releases resources.
16512 * 0 = Success, >0 = Failure
16515 bxe_detach(device_t dev)
16517 struct bxe_softc *sc;
16520 sc = device_get_softc(dev);
16522 BLOGD(sc, DBG_LOAD, "Starting detach...\n");
16525 if (ifp != NULL && ifp->if_vlantrunk != NULL) {
16526 BLOGE(sc, "Cannot detach while VLANs are in use.\n");
16532 /* stop the periodic callout */
16533 bxe_periodic_stop(sc);
16535 /* stop the chip taskqueue */
16536 atomic_store_rel_long(&sc->chip_tq_flags, CHIP_TQ_NONE);
16538 taskqueue_drain(sc->chip_tq, &sc->chip_tq_task);
16539 taskqueue_free(sc->chip_tq);
16540 sc->chip_tq = NULL;
16541 taskqueue_drain_timeout(taskqueue_thread,
16542 &sc->sp_err_timeout_task);
16545 /* stop and reset the controller if it was open */
16546 if (sc->state != BXE_STATE_CLOSED) {
16548 bxe_nic_unload(sc, UNLOAD_CLOSE, TRUE);
16549 sc->state = BXE_STATE_DISABLED;
16550 BXE_CORE_UNLOCK(sc);
16553 /* release the network interface */
16555 ether_ifdetach(ifp);
16557 ifmedia_removeall(&sc->ifmedia);
16559 /* XXX do the following based on driver state... */
16561 /* free the host hardware/software hsi structures */
16562 bxe_free_hsi_mem(sc);
16565 bxe_free_ilt_mem(sc);
16567 bxe_free_buf_rings(sc);
16569 /* release the interrupts */
16570 bxe_interrupt_free(sc);
16572 /* Release the mutexes*/
16573 bxe_destroy_fp_mutexs(sc);
16574 bxe_release_mutexes(sc);
16577 /* Release the PCIe BAR mapped memory */
16578 bxe_deallocate_bars(sc);
16580 /* Release the FreeBSD interface. */
16581 if (sc->ifnet != NULL) {
16582 if_free(sc->ifnet);
16585 pci_disable_busmaster(dev);
16591 * Device shutdown function.
16593 * Stops and resets the controller.
16599 bxe_shutdown(device_t dev)
16601 struct bxe_softc *sc;
16603 sc = device_get_softc(dev);
16605 BLOGD(sc, DBG_LOAD, "Starting shutdown...\n");
16607 /* stop the periodic callout */
16608 bxe_periodic_stop(sc);
16610 if (sc->state != BXE_STATE_CLOSED) {
16612 bxe_nic_unload(sc, UNLOAD_NORMAL, FALSE);
16613 BXE_CORE_UNLOCK(sc);
16620 bxe_igu_ack_sb(struct bxe_softc *sc,
16627 uint32_t igu_addr = sc->igu_base_addr;
16628 igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
16629 bxe_igu_ack_sb_gen(sc, igu_sb_id, segment, index, op, update, igu_addr);
16633 bxe_igu_clear_sb_gen(struct bxe_softc *sc,
16638 uint32_t data, ctl, cnt = 100;
16639 uint32_t igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
16640 uint32_t igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
16641 uint32_t igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
16642 uint32_t sb_bit = 1 << (idu_sb_id%32);
16643 uint32_t func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
16644 uint32_t addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
16646 /* Not supported in BC mode */
16647 if (CHIP_INT_MODE_IS_BC(sc)) {
16651 data = ((IGU_USE_REGISTER_cstorm_type_0_sb_cleanup <<
16652 IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
16653 IGU_REGULAR_CLEANUP_SET |
16654 IGU_REGULAR_BCLEANUP);
16656 ctl = ((addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT) |
16657 (func_encode << IGU_CTRL_REG_FID_SHIFT) |
16658 (IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT));
16660 BLOGD(sc, DBG_LOAD, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
16661 data, igu_addr_data);
16662 REG_WR(sc, igu_addr_data, data);
16664 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle, 0, 0,
16665 BUS_SPACE_BARRIER_WRITE);
16668 BLOGD(sc, DBG_LOAD, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
16669 ctl, igu_addr_ctl);
16670 REG_WR(sc, igu_addr_ctl, ctl);
16672 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle, 0, 0,
16673 BUS_SPACE_BARRIER_WRITE);
16676 /* wait for clean up to finish */
16677 while (!(REG_RD(sc, igu_addr_ack) & sb_bit) && --cnt) {
16681 if (!(REG_RD(sc, igu_addr_ack) & sb_bit)) {
16682 BLOGD(sc, DBG_LOAD,
16683 "Unable to finish IGU cleanup: "
16684 "idu_sb_id %d offset %d bit %d (cnt %d)\n",
16685 idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
16690 bxe_igu_clear_sb(struct bxe_softc *sc,
16693 bxe_igu_clear_sb_gen(sc, SC_FUNC(sc), idu_sb_id, TRUE /*PF*/);
16702 /*******************/
16703 /* ECORE CALLBACKS */
16704 /*******************/
16707 bxe_reset_common(struct bxe_softc *sc)
16709 uint32_t val = 0x1400;
16712 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR), 0xd3ffff7f);
16714 if (CHIP_IS_E3(sc)) {
16715 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
16716 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
16719 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR), val);
16723 bxe_common_init_phy(struct bxe_softc *sc)
16725 uint32_t shmem_base[2];
16726 uint32_t shmem2_base[2];
16728 /* Avoid common init in case MFW supports LFA */
16729 if (SHMEM2_RD(sc, size) >
16730 (uint32_t)offsetof(struct shmem2_region,
16731 lfa_host_addr[SC_PORT(sc)])) {
16735 shmem_base[0] = sc->devinfo.shmem_base;
16736 shmem2_base[0] = sc->devinfo.shmem2_base;
16738 if (!CHIP_IS_E1x(sc)) {
16739 shmem_base[1] = SHMEM2_RD(sc, other_shmem_base_addr);
16740 shmem2_base[1] = SHMEM2_RD(sc, other_shmem2_base_addr);
16743 bxe_acquire_phy_lock(sc);
16744 elink_common_init_phy(sc, shmem_base, shmem2_base,
16745 sc->devinfo.chip_id, 0);
16746 bxe_release_phy_lock(sc);
16750 bxe_pf_disable(struct bxe_softc *sc)
16752 uint32_t val = REG_RD(sc, IGU_REG_PF_CONFIGURATION);
16754 val &= ~IGU_PF_CONF_FUNC_EN;
16756 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
16757 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
16758 REG_WR(sc, CFC_REG_WEAK_ENABLE_PF, 0);
16762 bxe_init_pxp(struct bxe_softc *sc)
16765 int r_order, w_order;
16767 devctl = bxe_pcie_capability_read(sc, PCIR_EXPRESS_DEVICE_CTL, 2);
16769 BLOGD(sc, DBG_LOAD, "read 0x%08x from devctl\n", devctl);
16771 w_order = ((devctl & PCIM_EXP_CTL_MAX_PAYLOAD) >> 5);
16773 if (sc->mrrs == -1) {
16774 r_order = ((devctl & PCIM_EXP_CTL_MAX_READ_REQUEST) >> 12);
16776 BLOGD(sc, DBG_LOAD, "forcing read order to %d\n", sc->mrrs);
16777 r_order = sc->mrrs;
16780 ecore_init_pxp_arb(sc, r_order, w_order);
16784 bxe_get_pretend_reg(struct bxe_softc *sc)
16786 uint32_t base = PXP2_REG_PGL_PRETEND_FUNC_F0;
16787 uint32_t stride = (PXP2_REG_PGL_PRETEND_FUNC_F1 - base);
16788 return (base + (SC_ABS_FUNC(sc)) * stride);
16792 * Called only on E1H or E2.
16793 * When pretending to be PF, the pretend value is the function number 0..7.
16794 * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
16798 bxe_pretend_func(struct bxe_softc *sc,
16799 uint16_t pretend_func_val)
16801 uint32_t pretend_reg;
16803 if (CHIP_IS_E1H(sc) && (pretend_func_val > E1H_FUNC_MAX)) {
16807 /* get my own pretend register */
16808 pretend_reg = bxe_get_pretend_reg(sc);
16809 REG_WR(sc, pretend_reg, pretend_func_val);
16810 REG_RD(sc, pretend_reg);
16815 bxe_iov_init_dmae(struct bxe_softc *sc)
16821 bxe_iov_init_dq(struct bxe_softc *sc)
16826 /* send a NIG loopback debug packet */
16828 bxe_lb_pckt(struct bxe_softc *sc)
16830 uint32_t wb_write[3];
16832 /* Ethernet source and destination addresses */
16833 wb_write[0] = 0x55555555;
16834 wb_write[1] = 0x55555555;
16835 wb_write[2] = 0x20; /* SOP */
16836 REG_WR_DMAE(sc, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
16838 /* NON-IP protocol */
16839 wb_write[0] = 0x09000000;
16840 wb_write[1] = 0x55555555;
16841 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
16842 REG_WR_DMAE(sc, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
16846 * Some of the internal memories are not directly readable from the driver.
16847 * To test them we send debug packets.
16850 bxe_int_mem_test(struct bxe_softc *sc)
16856 if (CHIP_REV_IS_FPGA(sc)) {
16858 } else if (CHIP_REV_IS_EMUL(sc)) {
16864 /* disable inputs of parser neighbor blocks */
16865 REG_WR(sc, TSDM_REG_ENABLE_IN1, 0x0);
16866 REG_WR(sc, TCM_REG_PRS_IFEN, 0x0);
16867 REG_WR(sc, CFC_REG_DEBUG0, 0x1);
16868 REG_WR(sc, NIG_REG_PRS_REQ_IN_EN, 0x0);
16870 /* write 0 to parser credits for CFC search request */
16871 REG_WR(sc, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
16873 /* send Ethernet packet */
16876 /* TODO do i reset NIG statistic? */
16877 /* Wait until NIG register shows 1 packet of size 0x10 */
16878 count = 1000 * factor;
16880 bxe_read_dmae(sc, NIG_REG_STAT2_BRB_OCTET, 2);
16881 val = *BXE_SP(sc, wb_data[0]);
16891 BLOGE(sc, "NIG timeout val=0x%x\n", val);
16895 /* wait until PRS register shows 1 packet */
16896 count = (1000 * factor);
16898 val = REG_RD(sc, PRS_REG_NUM_OF_PACKETS);
16908 BLOGE(sc, "PRS timeout val=0x%x\n", val);
16912 /* Reset and init BRB, PRS */
16913 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
16915 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
16917 ecore_init_block(sc, BLOCK_BRB1, PHASE_COMMON);
16918 ecore_init_block(sc, BLOCK_PRS, PHASE_COMMON);
16920 /* Disable inputs of parser neighbor blocks */
16921 REG_WR(sc, TSDM_REG_ENABLE_IN1, 0x0);
16922 REG_WR(sc, TCM_REG_PRS_IFEN, 0x0);
16923 REG_WR(sc, CFC_REG_DEBUG0, 0x1);
16924 REG_WR(sc, NIG_REG_PRS_REQ_IN_EN, 0x0);
16926 /* Write 0 to parser credits for CFC search request */
16927 REG_WR(sc, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
16929 /* send 10 Ethernet packets */
16930 for (i = 0; i < 10; i++) {
16934 /* Wait until NIG register shows 10+1 packets of size 11*0x10 = 0xb0 */
16935 count = (1000 * factor);
16937 bxe_read_dmae(sc, NIG_REG_STAT2_BRB_OCTET, 2);
16938 val = *BXE_SP(sc, wb_data[0]);
16948 BLOGE(sc, "NIG timeout val=0x%x\n", val);
16952 /* Wait until PRS register shows 2 packets */
16953 val = REG_RD(sc, PRS_REG_NUM_OF_PACKETS);
16955 BLOGE(sc, "PRS timeout val=0x%x\n", val);
16958 /* Write 1 to parser credits for CFC search request */
16959 REG_WR(sc, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
16961 /* Wait until PRS register shows 3 packets */
16962 DELAY(10000 * factor);
16964 /* Wait until NIG register shows 1 packet of size 0x10 */
16965 val = REG_RD(sc, PRS_REG_NUM_OF_PACKETS);
16967 BLOGE(sc, "PRS timeout val=0x%x\n", val);
16970 /* clear NIG EOP FIFO */
16971 for (i = 0; i < 11; i++) {
16972 REG_RD(sc, NIG_REG_INGRESS_EOP_LB_FIFO);
16975 val = REG_RD(sc, NIG_REG_INGRESS_EOP_LB_EMPTY);
16977 BLOGE(sc, "clear of NIG failed val=0x%x\n", val);
16981 /* Reset and init BRB, PRS, NIG */
16982 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
16984 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
16986 ecore_init_block(sc, BLOCK_BRB1, PHASE_COMMON);
16987 ecore_init_block(sc, BLOCK_PRS, PHASE_COMMON);
16988 if (!CNIC_SUPPORT(sc)) {
16990 REG_WR(sc, PRS_REG_NIC_MODE, 1);
16993 /* Enable inputs of parser neighbor blocks */
16994 REG_WR(sc, TSDM_REG_ENABLE_IN1, 0x7fffffff);
16995 REG_WR(sc, TCM_REG_PRS_IFEN, 0x1);
16996 REG_WR(sc, CFC_REG_DEBUG0, 0x0);
16997 REG_WR(sc, NIG_REG_PRS_REQ_IN_EN, 0x1);
17003 bxe_setup_fan_failure_detection(struct bxe_softc *sc)
17010 val = (SHMEM_RD(sc, dev_info.shared_hw_config.config2) &
17011 SHARED_HW_CFG_FAN_FAILURE_MASK);
17013 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED) {
17017 * The fan failure mechanism is usually related to the PHY type since
17018 * the power consumption of the board is affected by the PHY. Currently,
17019 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
17021 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE) {
17022 for (port = PORT_0; port < PORT_MAX; port++) {
17023 is_required |= elink_fan_failure_det_req(sc,
17024 sc->devinfo.shmem_base,
17025 sc->devinfo.shmem2_base,
17030 BLOGD(sc, DBG_LOAD, "fan detection setting: %d\n", is_required);
17032 if (is_required == 0) {
17036 /* Fan failure is indicated by SPIO 5 */
17037 bxe_set_spio(sc, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
17039 /* set to active low mode */
17040 val = REG_RD(sc, MISC_REG_SPIO_INT);
17041 val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
17042 REG_WR(sc, MISC_REG_SPIO_INT, val);
17044 /* enable interrupt to signal the IGU */
17045 val = REG_RD(sc, MISC_REG_SPIO_EVENT_EN);
17046 val |= MISC_SPIO_SPIO5;
17047 REG_WR(sc, MISC_REG_SPIO_EVENT_EN, val);
17051 bxe_enable_blocks_attention(struct bxe_softc *sc)
17055 REG_WR(sc, PXP_REG_PXP_INT_MASK_0, 0);
17056 if (!CHIP_IS_E1x(sc)) {
17057 REG_WR(sc, PXP_REG_PXP_INT_MASK_1, 0x40);
17059 REG_WR(sc, PXP_REG_PXP_INT_MASK_1, 0);
17061 REG_WR(sc, DORQ_REG_DORQ_INT_MASK, 0);
17062 REG_WR(sc, CFC_REG_CFC_INT_MASK, 0);
17064 * mask read length error interrupts in brb for parser
17065 * (parsing unit and 'checksum and crc' unit)
17066 * these errors are legal (PU reads fixed length and CAC can cause
17067 * read length error on truncated packets)
17069 REG_WR(sc, BRB1_REG_BRB1_INT_MASK, 0xFC00);
17070 REG_WR(sc, QM_REG_QM_INT_MASK, 0);
17071 REG_WR(sc, TM_REG_TM_INT_MASK, 0);
17072 REG_WR(sc, XSDM_REG_XSDM_INT_MASK_0, 0);
17073 REG_WR(sc, XSDM_REG_XSDM_INT_MASK_1, 0);
17074 REG_WR(sc, XCM_REG_XCM_INT_MASK, 0);
17075 /* REG_WR(sc, XSEM_REG_XSEM_INT_MASK_0, 0); */
17076 /* REG_WR(sc, XSEM_REG_XSEM_INT_MASK_1, 0); */
17077 REG_WR(sc, USDM_REG_USDM_INT_MASK_0, 0);
17078 REG_WR(sc, USDM_REG_USDM_INT_MASK_1, 0);
17079 REG_WR(sc, UCM_REG_UCM_INT_MASK, 0);
17080 /* REG_WR(sc, USEM_REG_USEM_INT_MASK_0, 0); */
17081 /* REG_WR(sc, USEM_REG_USEM_INT_MASK_1, 0); */
17082 REG_WR(sc, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
17083 REG_WR(sc, CSDM_REG_CSDM_INT_MASK_0, 0);
17084 REG_WR(sc, CSDM_REG_CSDM_INT_MASK_1, 0);
17085 REG_WR(sc, CCM_REG_CCM_INT_MASK, 0);
17086 /* REG_WR(sc, CSEM_REG_CSEM_INT_MASK_0, 0); */
17087 /* REG_WR(sc, CSEM_REG_CSEM_INT_MASK_1, 0); */
17089 val = (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
17090 PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
17091 PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN);
17092 if (!CHIP_IS_E1x(sc)) {
17093 val |= (PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
17094 PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED);
17096 REG_WR(sc, PXP2_REG_PXP2_INT_MASK_0, val);
17098 REG_WR(sc, TSDM_REG_TSDM_INT_MASK_0, 0);
17099 REG_WR(sc, TSDM_REG_TSDM_INT_MASK_1, 0);
17100 REG_WR(sc, TCM_REG_TCM_INT_MASK, 0);
17101 /* REG_WR(sc, TSEM_REG_TSEM_INT_MASK_0, 0); */
17103 if (!CHIP_IS_E1x(sc)) {
17104 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
17105 REG_WR(sc, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
17108 REG_WR(sc, CDU_REG_CDU_INT_MASK, 0);
17109 REG_WR(sc, DMAE_REG_DMAE_INT_MASK, 0);
17110 /* REG_WR(sc, MISC_REG_MISC_INT_MASK, 0); */
17111 REG_WR(sc, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
17115 * bxe_init_hw_common - initialize the HW at the COMMON phase.
17117 * @sc: driver handle
17120 bxe_init_hw_common(struct bxe_softc *sc)
17122 uint8_t abs_func_id;
17125 BLOGD(sc, DBG_LOAD, "starting common init for func %d\n",
17129 * take the RESET lock to protect undi_unload flow from accessing
17130 * registers while we are resetting the chip
17132 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
17134 bxe_reset_common(sc);
17136 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET), 0xffffffff);
17139 if (CHIP_IS_E3(sc)) {
17140 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
17141 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
17144 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET), val);
17146 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
17148 ecore_init_block(sc, BLOCK_MISC, PHASE_COMMON);
17149 BLOGD(sc, DBG_LOAD, "after misc block init\n");
17151 if (!CHIP_IS_E1x(sc)) {
17153 * 4-port mode or 2-port mode we need to turn off master-enable for
17154 * everyone. After that we turn it back on for self. So, we disregard
17155 * multi-function, and always disable all functions on the given path,
17156 * this means 0,2,4,6 for path 0 and 1,3,5,7 for path 1
17158 for (abs_func_id = SC_PATH(sc);
17159 abs_func_id < (E2_FUNC_MAX * 2);
17160 abs_func_id += 2) {
17161 if (abs_func_id == SC_ABS_FUNC(sc)) {
17162 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
17166 bxe_pretend_func(sc, abs_func_id);
17168 /* clear pf enable */
17169 bxe_pf_disable(sc);
17171 bxe_pretend_func(sc, SC_ABS_FUNC(sc));
17175 BLOGD(sc, DBG_LOAD, "after pf disable\n");
17177 ecore_init_block(sc, BLOCK_PXP, PHASE_COMMON);
17179 if (CHIP_IS_E1(sc)) {
17181 * enable HW interrupt from PXP on USDM overflow
17182 * bit 16 on INT_MASK_0
17184 REG_WR(sc, PXP_REG_PXP_INT_MASK_0, 0);
17187 ecore_init_block(sc, BLOCK_PXP2, PHASE_COMMON);
17190 #ifdef __BIG_ENDIAN
17191 REG_WR(sc, PXP2_REG_RQ_QM_ENDIAN_M, 1);
17192 REG_WR(sc, PXP2_REG_RQ_TM_ENDIAN_M, 1);
17193 REG_WR(sc, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
17194 REG_WR(sc, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
17195 REG_WR(sc, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
17196 /* make sure this value is 0 */
17197 REG_WR(sc, PXP2_REG_RQ_HC_ENDIAN_M, 0);
17199 //REG_WR(sc, PXP2_REG_RD_PBF_SWAP_MODE, 1);
17200 REG_WR(sc, PXP2_REG_RD_QM_SWAP_MODE, 1);
17201 REG_WR(sc, PXP2_REG_RD_TM_SWAP_MODE, 1);
17202 REG_WR(sc, PXP2_REG_RD_SRC_SWAP_MODE, 1);
17203 REG_WR(sc, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
17206 ecore_ilt_init_page_size(sc, INITOP_SET);
17208 if (CHIP_REV_IS_FPGA(sc) && CHIP_IS_E1H(sc)) {
17209 REG_WR(sc, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
17212 /* let the HW do it's magic... */
17215 /* finish PXP init */
17216 val = REG_RD(sc, PXP2_REG_RQ_CFG_DONE);
17218 BLOGE(sc, "PXP2 CFG failed PXP2_REG_RQ_CFG_DONE val = 0x%x\n",
17222 val = REG_RD(sc, PXP2_REG_RD_INIT_DONE);
17224 BLOGE(sc, "PXP2 RD_INIT failed val = 0x%x\n", val);
17228 BLOGD(sc, DBG_LOAD, "after pxp init\n");
17231 * Timer bug workaround for E2 only. We need to set the entire ILT to have
17232 * entries with value "0" and valid bit on. This needs to be done by the
17233 * first PF that is loaded in a path (i.e. common phase)
17235 if (!CHIP_IS_E1x(sc)) {
17237 * In E2 there is a bug in the timers block that can cause function 6 / 7
17238 * (i.e. vnic3) to start even if it is marked as "scan-off".
17239 * This occurs when a different function (func2,3) is being marked
17240 * as "scan-off". Real-life scenario for example: if a driver is being
17241 * load-unloaded while func6,7 are down. This will cause the timer to access
17242 * the ilt, translate to a logical address and send a request to read/write.
17243 * Since the ilt for the function that is down is not valid, this will cause
17244 * a translation error which is unrecoverable.
17245 * The Workaround is intended to make sure that when this happens nothing
17246 * fatal will occur. The workaround:
17247 * 1. First PF driver which loads on a path will:
17248 * a. After taking the chip out of reset, by using pretend,
17249 * it will write "0" to the following registers of
17251 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
17252 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
17253 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
17254 * And for itself it will write '1' to
17255 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
17256 * dmae-operations (writing to pram for example.)
17257 * note: can be done for only function 6,7 but cleaner this
17259 * b. Write zero+valid to the entire ILT.
17260 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
17261 * VNIC3 (of that port). The range allocated will be the
17262 * entire ILT. This is needed to prevent ILT range error.
17263 * 2. Any PF driver load flow:
17264 * a. ILT update with the physical addresses of the allocated
17266 * b. Wait 20msec. - note that this timeout is needed to make
17267 * sure there are no requests in one of the PXP internal
17268 * queues with "old" ILT addresses.
17269 * c. PF enable in the PGLC.
17270 * d. Clear the was_error of the PF in the PGLC. (could have
17271 * occurred while driver was down)
17272 * e. PF enable in the CFC (WEAK + STRONG)
17273 * f. Timers scan enable
17274 * 3. PF driver unload flow:
17275 * a. Clear the Timers scan_en.
17276 * b. Polling for scan_on=0 for that PF.
17277 * c. Clear the PF enable bit in the PXP.
17278 * d. Clear the PF enable in the CFC (WEAK + STRONG)
17279 * e. Write zero+valid to all ILT entries (The valid bit must
17281 * f. If this is VNIC 3 of a port then also init
17282 * first_timers_ilt_entry to zero and last_timers_ilt_entry
17283 * to the last enrty in the ILT.
17286 * Currently the PF error in the PGLC is non recoverable.
17287 * In the future the there will be a recovery routine for this error.
17288 * Currently attention is masked.
17289 * Having an MCP lock on the load/unload process does not guarantee that
17290 * there is no Timer disable during Func6/7 enable. This is because the
17291 * Timers scan is currently being cleared by the MCP on FLR.
17292 * Step 2.d can be done only for PF6/7 and the driver can also check if
17293 * there is error before clearing it. But the flow above is simpler and
17295 * All ILT entries are written by zero+valid and not just PF6/7
17296 * ILT entries since in the future the ILT entries allocation for
17297 * PF-s might be dynamic.
17299 struct ilt_client_info ilt_cli;
17300 struct ecore_ilt ilt;
17302 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
17303 memset(&ilt, 0, sizeof(struct ecore_ilt));
17305 /* initialize dummy TM client */
17307 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
17308 ilt_cli.client_num = ILT_CLIENT_TM;
17311 * Step 1: set zeroes to all ilt page entries with valid bit on
17312 * Step 2: set the timers first/last ilt entry to point
17313 * to the entire range to prevent ILT range error for 3rd/4th
17314 * vnic (this code assumes existence of the vnic)
17316 * both steps performed by call to ecore_ilt_client_init_op()
17317 * with dummy TM client
17319 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
17320 * and his brother are split registers
17323 bxe_pretend_func(sc, (SC_PATH(sc) + 6));
17324 ecore_ilt_client_init_op_ilt(sc, &ilt, &ilt_cli, INITOP_CLEAR);
17325 bxe_pretend_func(sc, SC_ABS_FUNC(sc));
17327 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN, BXE_PXP_DRAM_ALIGN);
17328 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN_RD, BXE_PXP_DRAM_ALIGN);
17329 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
17332 REG_WR(sc, PXP2_REG_RQ_DISABLE_INPUTS, 0);
17333 REG_WR(sc, PXP2_REG_RD_DISABLE_INPUTS, 0);
17335 if (!CHIP_IS_E1x(sc)) {
17336 int factor = CHIP_REV_IS_EMUL(sc) ? 1000 :
17337 (CHIP_REV_IS_FPGA(sc) ? 400 : 0);
17339 ecore_init_block(sc, BLOCK_PGLUE_B, PHASE_COMMON);
17340 ecore_init_block(sc, BLOCK_ATC, PHASE_COMMON);
17342 /* let the HW do it's magic... */
17345 val = REG_RD(sc, ATC_REG_ATC_INIT_DONE);
17346 } while (factor-- && (val != 1));
17349 BLOGE(sc, "ATC_INIT failed val = 0x%x\n", val);
17354 BLOGD(sc, DBG_LOAD, "after pglue and atc init\n");
17356 ecore_init_block(sc, BLOCK_DMAE, PHASE_COMMON);
17358 bxe_iov_init_dmae(sc);
17360 /* clean the DMAE memory */
17361 sc->dmae_ready = 1;
17362 ecore_init_fill(sc, TSEM_REG_PRAM, 0, 8, 1);
17364 ecore_init_block(sc, BLOCK_TCM, PHASE_COMMON);
17366 ecore_init_block(sc, BLOCK_UCM, PHASE_COMMON);
17368 ecore_init_block(sc, BLOCK_CCM, PHASE_COMMON);
17370 ecore_init_block(sc, BLOCK_XCM, PHASE_COMMON);
17372 bxe_read_dmae(sc, XSEM_REG_PASSIVE_BUFFER, 3);
17373 bxe_read_dmae(sc, CSEM_REG_PASSIVE_BUFFER, 3);
17374 bxe_read_dmae(sc, TSEM_REG_PASSIVE_BUFFER, 3);
17375 bxe_read_dmae(sc, USEM_REG_PASSIVE_BUFFER, 3);
17377 ecore_init_block(sc, BLOCK_QM, PHASE_COMMON);
17379 /* QM queues pointers table */
17380 ecore_qm_init_ptr_table(sc, sc->qm_cid_count, INITOP_SET);
17382 /* soft reset pulse */
17383 REG_WR(sc, QM_REG_SOFT_RESET, 1);
17384 REG_WR(sc, QM_REG_SOFT_RESET, 0);
17386 if (CNIC_SUPPORT(sc))
17387 ecore_init_block(sc, BLOCK_TM, PHASE_COMMON);
17389 ecore_init_block(sc, BLOCK_DORQ, PHASE_COMMON);
17390 REG_WR(sc, DORQ_REG_DPM_CID_OFST, BXE_DB_SHIFT);
17391 if (!CHIP_REV_IS_SLOW(sc)) {
17392 /* enable hw interrupt from doorbell Q */
17393 REG_WR(sc, DORQ_REG_DORQ_INT_MASK, 0);
17396 ecore_init_block(sc, BLOCK_BRB1, PHASE_COMMON);
17398 ecore_init_block(sc, BLOCK_PRS, PHASE_COMMON);
17399 REG_WR(sc, PRS_REG_A_PRSU_20, 0xf);
17401 if (!CHIP_IS_E1(sc)) {
17402 REG_WR(sc, PRS_REG_E1HOV_MODE, sc->devinfo.mf_info.path_has_ovlan);
17405 if (!CHIP_IS_E1x(sc) && !CHIP_IS_E3B0(sc)) {
17406 if (IS_MF_AFEX(sc)) {
17408 * configure that AFEX and VLAN headers must be
17409 * received in AFEX mode
17411 REG_WR(sc, PRS_REG_HDRS_AFTER_BASIC, 0xE);
17412 REG_WR(sc, PRS_REG_MUST_HAVE_HDRS, 0xA);
17413 REG_WR(sc, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
17414 REG_WR(sc, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
17415 REG_WR(sc, PRS_REG_TAG_LEN_0, 0x4);
17418 * Bit-map indicating which L2 hdrs may appear
17419 * after the basic Ethernet header
17421 REG_WR(sc, PRS_REG_HDRS_AFTER_BASIC,
17422 sc->devinfo.mf_info.path_has_ovlan ? 7 : 6);
17426 ecore_init_block(sc, BLOCK_TSDM, PHASE_COMMON);
17427 ecore_init_block(sc, BLOCK_CSDM, PHASE_COMMON);
17428 ecore_init_block(sc, BLOCK_USDM, PHASE_COMMON);
17429 ecore_init_block(sc, BLOCK_XSDM, PHASE_COMMON);
17431 if (!CHIP_IS_E1x(sc)) {
17432 /* reset VFC memories */
17433 REG_WR(sc, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
17434 VFC_MEMORIES_RST_REG_CAM_RST |
17435 VFC_MEMORIES_RST_REG_RAM_RST);
17436 REG_WR(sc, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
17437 VFC_MEMORIES_RST_REG_CAM_RST |
17438 VFC_MEMORIES_RST_REG_RAM_RST);
17443 ecore_init_block(sc, BLOCK_TSEM, PHASE_COMMON);
17444 ecore_init_block(sc, BLOCK_USEM, PHASE_COMMON);
17445 ecore_init_block(sc, BLOCK_CSEM, PHASE_COMMON);
17446 ecore_init_block(sc, BLOCK_XSEM, PHASE_COMMON);
17448 /* sync semi rtc */
17449 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
17451 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
17454 ecore_init_block(sc, BLOCK_UPB, PHASE_COMMON);
17455 ecore_init_block(sc, BLOCK_XPB, PHASE_COMMON);
17456 ecore_init_block(sc, BLOCK_PBF, PHASE_COMMON);
17458 if (!CHIP_IS_E1x(sc)) {
17459 if (IS_MF_AFEX(sc)) {
17461 * configure that AFEX and VLAN headers must be
17462 * sent in AFEX mode
17464 REG_WR(sc, PBF_REG_HDRS_AFTER_BASIC, 0xE);
17465 REG_WR(sc, PBF_REG_MUST_HAVE_HDRS, 0xA);
17466 REG_WR(sc, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
17467 REG_WR(sc, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
17468 REG_WR(sc, PBF_REG_TAG_LEN_0, 0x4);
17470 REG_WR(sc, PBF_REG_HDRS_AFTER_BASIC,
17471 sc->devinfo.mf_info.path_has_ovlan ? 7 : 6);
17475 REG_WR(sc, SRC_REG_SOFT_RST, 1);
17477 ecore_init_block(sc, BLOCK_SRC, PHASE_COMMON);
17479 if (CNIC_SUPPORT(sc)) {
17480 REG_WR(sc, SRC_REG_KEYSEARCH_0, 0x63285672);
17481 REG_WR(sc, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
17482 REG_WR(sc, SRC_REG_KEYSEARCH_2, 0x223aef9b);
17483 REG_WR(sc, SRC_REG_KEYSEARCH_3, 0x26001e3a);
17484 REG_WR(sc, SRC_REG_KEYSEARCH_4, 0x7ae91116);
17485 REG_WR(sc, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
17486 REG_WR(sc, SRC_REG_KEYSEARCH_6, 0x298d8adf);
17487 REG_WR(sc, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
17488 REG_WR(sc, SRC_REG_KEYSEARCH_8, 0x1830f82f);
17489 REG_WR(sc, SRC_REG_KEYSEARCH_9, 0x01e46be7);
17491 REG_WR(sc, SRC_REG_SOFT_RST, 0);
17493 if (sizeof(union cdu_context) != 1024) {
17494 /* we currently assume that a context is 1024 bytes */
17495 BLOGE(sc, "please adjust the size of cdu_context(%ld)\n",
17496 (long)sizeof(union cdu_context));
17499 ecore_init_block(sc, BLOCK_CDU, PHASE_COMMON);
17500 val = (4 << 24) + (0 << 12) + 1024;
17501 REG_WR(sc, CDU_REG_CDU_GLOBAL_PARAMS, val);
17503 ecore_init_block(sc, BLOCK_CFC, PHASE_COMMON);
17505 REG_WR(sc, CFC_REG_INIT_REG, 0x7FF);
17506 /* enable context validation interrupt from CFC */
17507 REG_WR(sc, CFC_REG_CFC_INT_MASK, 0);
17509 /* set the thresholds to prevent CFC/CDU race */
17510 REG_WR(sc, CFC_REG_DEBUG0, 0x20020000);
17511 ecore_init_block(sc, BLOCK_HC, PHASE_COMMON);
17513 if (!CHIP_IS_E1x(sc) && BXE_NOMCP(sc)) {
17514 REG_WR(sc, IGU_REG_RESET_MEMORIES, 0x36);
17517 ecore_init_block(sc, BLOCK_IGU, PHASE_COMMON);
17518 ecore_init_block(sc, BLOCK_MISC_AEU, PHASE_COMMON);
17520 /* Reset PCIE errors for debug */
17521 REG_WR(sc, 0x2814, 0xffffffff);
17522 REG_WR(sc, 0x3820, 0xffffffff);
17524 if (!CHIP_IS_E1x(sc)) {
17525 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
17526 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
17527 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
17528 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
17529 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
17530 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
17531 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
17532 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
17533 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
17534 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
17535 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
17538 ecore_init_block(sc, BLOCK_NIG, PHASE_COMMON);
17540 if (!CHIP_IS_E1(sc)) {
17541 /* in E3 this done in per-port section */
17542 if (!CHIP_IS_E3(sc))
17543 REG_WR(sc, NIG_REG_LLH_MF_MODE, IS_MF(sc));
17546 if (CHIP_IS_E1H(sc)) {
17547 /* not applicable for E2 (and above ...) */
17548 REG_WR(sc, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(sc));
17551 if (CHIP_REV_IS_SLOW(sc)) {
17555 /* finish CFC init */
17556 val = reg_poll(sc, CFC_REG_LL_INIT_DONE, 1, 100, 10);
17558 BLOGE(sc, "CFC LL_INIT failed val=0x%x\n", val);
17561 val = reg_poll(sc, CFC_REG_AC_INIT_DONE, 1, 100, 10);
17563 BLOGE(sc, "CFC AC_INIT failed val=0x%x\n", val);
17566 val = reg_poll(sc, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
17568 BLOGE(sc, "CFC CAM_INIT failed val=0x%x\n", val);
17571 REG_WR(sc, CFC_REG_DEBUG0, 0);
17573 if (CHIP_IS_E1(sc)) {
17574 /* read NIG statistic to see if this is our first up since powerup */
17575 bxe_read_dmae(sc, NIG_REG_STAT2_BRB_OCTET, 2);
17576 val = *BXE_SP(sc, wb_data[0]);
17578 /* do internal memory self test */
17579 if ((val == 0) && bxe_int_mem_test(sc)) {
17580 BLOGE(sc, "internal mem self test failed val=0x%x\n", val);
17585 bxe_setup_fan_failure_detection(sc);
17587 /* clear PXP2 attentions */
17588 REG_RD(sc, PXP2_REG_PXP2_INT_STS_CLR_0);
17590 bxe_enable_blocks_attention(sc);
17592 if (!CHIP_REV_IS_SLOW(sc)) {
17593 ecore_enable_blocks_parity(sc);
17596 if (!BXE_NOMCP(sc)) {
17597 if (CHIP_IS_E1x(sc)) {
17598 bxe_common_init_phy(sc);
17606 * bxe_init_hw_common_chip - init HW at the COMMON_CHIP phase.
17608 * @sc: driver handle
17611 bxe_init_hw_common_chip(struct bxe_softc *sc)
17613 int rc = bxe_init_hw_common(sc);
17616 BLOGE(sc, "bxe_init_hw_common failed rc=%d\n", rc);
17620 /* In E2 2-PORT mode, same ext phy is used for the two paths */
17621 if (!BXE_NOMCP(sc)) {
17622 bxe_common_init_phy(sc);
17629 bxe_init_hw_port(struct bxe_softc *sc)
17631 int port = SC_PORT(sc);
17632 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
17633 uint32_t low, high;
17636 BLOGD(sc, DBG_LOAD, "starting port init for port %d\n", port);
17638 REG_WR(sc, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
17640 ecore_init_block(sc, BLOCK_MISC, init_phase);
17641 ecore_init_block(sc, BLOCK_PXP, init_phase);
17642 ecore_init_block(sc, BLOCK_PXP2, init_phase);
17645 * Timers bug workaround: disables the pf_master bit in pglue at
17646 * common phase, we need to enable it here before any dmae access are
17647 * attempted. Therefore we manually added the enable-master to the
17648 * port phase (it also happens in the function phase)
17650 if (!CHIP_IS_E1x(sc)) {
17651 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
17654 ecore_init_block(sc, BLOCK_ATC, init_phase);
17655 ecore_init_block(sc, BLOCK_DMAE, init_phase);
17656 ecore_init_block(sc, BLOCK_PGLUE_B, init_phase);
17657 ecore_init_block(sc, BLOCK_QM, init_phase);
17659 ecore_init_block(sc, BLOCK_TCM, init_phase);
17660 ecore_init_block(sc, BLOCK_UCM, init_phase);
17661 ecore_init_block(sc, BLOCK_CCM, init_phase);
17662 ecore_init_block(sc, BLOCK_XCM, init_phase);
17664 /* QM cid (connection) count */
17665 ecore_qm_init_cid_count(sc, sc->qm_cid_count, INITOP_SET);
17667 if (CNIC_SUPPORT(sc)) {
17668 ecore_init_block(sc, BLOCK_TM, init_phase);
17669 REG_WR(sc, TM_REG_LIN0_SCAN_TIME + port*4, 20);
17670 REG_WR(sc, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
17673 ecore_init_block(sc, BLOCK_DORQ, init_phase);
17675 ecore_init_block(sc, BLOCK_BRB1, init_phase);
17677 if (CHIP_IS_E1(sc) || CHIP_IS_E1H(sc)) {
17679 low = (BXE_ONE_PORT(sc) ? 160 : 246);
17680 } else if (sc->mtu > 4096) {
17681 if (BXE_ONE_PORT(sc)) {
17685 /* (24*1024 + val*4)/256 */
17686 low = (96 + (val / 64) + ((val % 64) ? 1 : 0));
17689 low = (BXE_ONE_PORT(sc) ? 80 : 160);
17691 high = (low + 56); /* 14*1024/256 */
17692 REG_WR(sc, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
17693 REG_WR(sc, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
17696 if (CHIP_IS_MODE_4_PORT(sc)) {
17697 REG_WR(sc, SC_PORT(sc) ?
17698 BRB1_REG_MAC_GUARANTIED_1 :
17699 BRB1_REG_MAC_GUARANTIED_0, 40);
17702 ecore_init_block(sc, BLOCK_PRS, init_phase);
17703 if (CHIP_IS_E3B0(sc)) {
17704 if (IS_MF_AFEX(sc)) {
17705 /* configure headers for AFEX mode */
17706 REG_WR(sc, SC_PORT(sc) ?
17707 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
17708 PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
17709 REG_WR(sc, SC_PORT(sc) ?
17710 PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
17711 PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
17712 REG_WR(sc, SC_PORT(sc) ?
17713 PRS_REG_MUST_HAVE_HDRS_PORT_1 :
17714 PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
17716 /* Ovlan exists only if we are in multi-function +
17717 * switch-dependent mode, in switch-independent there
17718 * is no ovlan headers
17720 REG_WR(sc, SC_PORT(sc) ?
17721 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
17722 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
17723 (sc->devinfo.mf_info.path_has_ovlan ? 7 : 6));
17727 ecore_init_block(sc, BLOCK_TSDM, init_phase);
17728 ecore_init_block(sc, BLOCK_CSDM, init_phase);
17729 ecore_init_block(sc, BLOCK_USDM, init_phase);
17730 ecore_init_block(sc, BLOCK_XSDM, init_phase);
17732 ecore_init_block(sc, BLOCK_TSEM, init_phase);
17733 ecore_init_block(sc, BLOCK_USEM, init_phase);
17734 ecore_init_block(sc, BLOCK_CSEM, init_phase);
17735 ecore_init_block(sc, BLOCK_XSEM, init_phase);
17737 ecore_init_block(sc, BLOCK_UPB, init_phase);
17738 ecore_init_block(sc, BLOCK_XPB, init_phase);
17740 ecore_init_block(sc, BLOCK_PBF, init_phase);
17742 if (CHIP_IS_E1x(sc)) {
17743 /* configure PBF to work without PAUSE mtu 9000 */
17744 REG_WR(sc, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
17746 /* update threshold */
17747 REG_WR(sc, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
17748 /* update init credit */
17749 REG_WR(sc, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
17751 /* probe changes */
17752 REG_WR(sc, PBF_REG_INIT_P0 + port*4, 1);
17754 REG_WR(sc, PBF_REG_INIT_P0 + port*4, 0);
17757 if (CNIC_SUPPORT(sc)) {
17758 ecore_init_block(sc, BLOCK_SRC, init_phase);
17761 ecore_init_block(sc, BLOCK_CDU, init_phase);
17762 ecore_init_block(sc, BLOCK_CFC, init_phase);
17764 if (CHIP_IS_E1(sc)) {
17765 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, 0);
17766 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, 0);
17768 ecore_init_block(sc, BLOCK_HC, init_phase);
17770 ecore_init_block(sc, BLOCK_IGU, init_phase);
17772 ecore_init_block(sc, BLOCK_MISC_AEU, init_phase);
17773 /* init aeu_mask_attn_func_0/1:
17774 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
17775 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
17776 * bits 4-7 are used for "per vn group attention" */
17777 val = IS_MF(sc) ? 0xF7 : 0x7;
17778 /* Enable DCBX attention for all but E1 */
17779 val |= CHIP_IS_E1(sc) ? 0 : 0x10;
17780 REG_WR(sc, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
17782 ecore_init_block(sc, BLOCK_NIG, init_phase);
17784 if (!CHIP_IS_E1x(sc)) {
17785 /* Bit-map indicating which L2 hdrs may appear after the
17786 * basic Ethernet header
17788 if (IS_MF_AFEX(sc)) {
17789 REG_WR(sc, SC_PORT(sc) ?
17790 NIG_REG_P1_HDRS_AFTER_BASIC :
17791 NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
17793 REG_WR(sc, SC_PORT(sc) ?
17794 NIG_REG_P1_HDRS_AFTER_BASIC :
17795 NIG_REG_P0_HDRS_AFTER_BASIC,
17796 IS_MF_SD(sc) ? 7 : 6);
17799 if (CHIP_IS_E3(sc)) {
17800 REG_WR(sc, SC_PORT(sc) ?
17801 NIG_REG_LLH1_MF_MODE :
17802 NIG_REG_LLH_MF_MODE, IS_MF(sc));
17805 if (!CHIP_IS_E3(sc)) {
17806 REG_WR(sc, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
17809 if (!CHIP_IS_E1(sc)) {
17810 /* 0x2 disable mf_ov, 0x1 enable */
17811 REG_WR(sc, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
17812 (IS_MF_SD(sc) ? 0x1 : 0x2));
17814 if (!CHIP_IS_E1x(sc)) {
17816 switch (sc->devinfo.mf_info.mf_mode) {
17817 case MULTI_FUNCTION_SD:
17820 case MULTI_FUNCTION_SI:
17821 case MULTI_FUNCTION_AFEX:
17826 REG_WR(sc, (SC_PORT(sc) ? NIG_REG_LLH1_CLS_TYPE :
17827 NIG_REG_LLH0_CLS_TYPE), val);
17829 REG_WR(sc, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
17830 REG_WR(sc, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
17831 REG_WR(sc, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
17834 /* If SPIO5 is set to generate interrupts, enable it for this port */
17835 val = REG_RD(sc, MISC_REG_SPIO_EVENT_EN);
17836 if (val & MISC_SPIO_SPIO5) {
17837 uint32_t reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
17838 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
17839 val = REG_RD(sc, reg_addr);
17840 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
17841 REG_WR(sc, reg_addr, val);
17848 bxe_flr_clnup_reg_poll(struct bxe_softc *sc,
17851 uint32_t poll_count)
17853 uint32_t cur_cnt = poll_count;
17856 while ((val = REG_RD(sc, reg)) != expected && cur_cnt--) {
17857 DELAY(FLR_WAIT_INTERVAL);
17864 bxe_flr_clnup_poll_hw_counter(struct bxe_softc *sc,
17869 uint32_t val = bxe_flr_clnup_reg_poll(sc, reg, 0, poll_cnt);
17872 BLOGE(sc, "%s usage count=%d\n", msg, val);
17879 /* Common routines with VF FLR cleanup */
17881 bxe_flr_clnup_poll_count(struct bxe_softc *sc)
17883 /* adjust polling timeout */
17884 if (CHIP_REV_IS_EMUL(sc)) {
17885 return (FLR_POLL_CNT * 2000);
17888 if (CHIP_REV_IS_FPGA(sc)) {
17889 return (FLR_POLL_CNT * 120);
17892 return (FLR_POLL_CNT);
17896 bxe_poll_hw_usage_counters(struct bxe_softc *sc,
17899 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
17900 if (bxe_flr_clnup_poll_hw_counter(sc,
17901 CFC_REG_NUM_LCIDS_INSIDE_PF,
17902 "CFC PF usage counter timed out",
17907 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
17908 if (bxe_flr_clnup_poll_hw_counter(sc,
17909 DORQ_REG_PF_USAGE_CNT,
17910 "DQ PF usage counter timed out",
17915 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
17916 if (bxe_flr_clnup_poll_hw_counter(sc,
17917 QM_REG_PF_USG_CNT_0 + 4*SC_FUNC(sc),
17918 "QM PF usage counter timed out",
17923 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
17924 if (bxe_flr_clnup_poll_hw_counter(sc,
17925 TM_REG_LIN0_VNIC_UC + 4*SC_PORT(sc),
17926 "Timers VNIC usage counter timed out",
17931 if (bxe_flr_clnup_poll_hw_counter(sc,
17932 TM_REG_LIN0_NUM_SCANS + 4*SC_PORT(sc),
17933 "Timers NUM_SCANS usage counter timed out",
17938 /* Wait DMAE PF usage counter to zero */
17939 if (bxe_flr_clnup_poll_hw_counter(sc,
17940 dmae_reg_go_c[INIT_DMAE_C(sc)],
17941 "DMAE dommand register timed out",
17949 #define OP_GEN_PARAM(param) \
17950 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
17951 #define OP_GEN_TYPE(type) \
17952 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
17953 #define OP_GEN_AGG_VECT(index) \
17954 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
17957 bxe_send_final_clnup(struct bxe_softc *sc,
17958 uint8_t clnup_func,
17961 uint32_t op_gen_command = 0;
17962 uint32_t comp_addr = (BAR_CSTRORM_INTMEM +
17963 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func));
17966 if (REG_RD(sc, comp_addr)) {
17967 BLOGE(sc, "Cleanup complete was not 0 before sending\n");
17971 op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
17972 op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
17973 op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
17974 op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
17976 BLOGD(sc, DBG_LOAD, "sending FW Final cleanup\n");
17977 REG_WR(sc, XSDM_REG_OPERATION_GEN, op_gen_command);
17979 if (bxe_flr_clnup_reg_poll(sc, comp_addr, 1, poll_cnt) != 1) {
17980 BLOGE(sc, "FW final cleanup did not succeed\n");
17981 BLOGD(sc, DBG_LOAD, "At timeout completion address contained %x\n",
17982 (REG_RD(sc, comp_addr)));
17983 bxe_panic(sc, ("FLR cleanup failed\n"));
17987 /* Zero completion for nxt FLR */
17988 REG_WR(sc, comp_addr, 0);
17994 bxe_pbf_pN_buf_flushed(struct bxe_softc *sc,
17995 struct pbf_pN_buf_regs *regs,
17996 uint32_t poll_count)
17998 uint32_t init_crd, crd, crd_start, crd_freed, crd_freed_start;
17999 uint32_t cur_cnt = poll_count;
18001 crd_freed = crd_freed_start = REG_RD(sc, regs->crd_freed);
18002 crd = crd_start = REG_RD(sc, regs->crd);
18003 init_crd = REG_RD(sc, regs->init_crd);
18005 BLOGD(sc, DBG_LOAD, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
18006 BLOGD(sc, DBG_LOAD, "CREDIT[%d] : s:%x\n", regs->pN, crd);
18007 BLOGD(sc, DBG_LOAD, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
18009 while ((crd != init_crd) &&
18010 ((uint32_t)((int32_t)crd_freed - (int32_t)crd_freed_start) <
18011 (init_crd - crd_start))) {
18013 DELAY(FLR_WAIT_INTERVAL);
18014 crd = REG_RD(sc, regs->crd);
18015 crd_freed = REG_RD(sc, regs->crd_freed);
18017 BLOGD(sc, DBG_LOAD, "PBF tx buffer[%d] timed out\n", regs->pN);
18018 BLOGD(sc, DBG_LOAD, "CREDIT[%d] : c:%x\n", regs->pN, crd);
18019 BLOGD(sc, DBG_LOAD, "CREDIT_FREED[%d]: c:%x\n", regs->pN, crd_freed);
18024 BLOGD(sc, DBG_LOAD, "Waited %d*%d usec for PBF tx buffer[%d]\n",
18025 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
18029 bxe_pbf_pN_cmd_flushed(struct bxe_softc *sc,
18030 struct pbf_pN_cmd_regs *regs,
18031 uint32_t poll_count)
18033 uint32_t occup, to_free, freed, freed_start;
18034 uint32_t cur_cnt = poll_count;
18036 occup = to_free = REG_RD(sc, regs->lines_occup);
18037 freed = freed_start = REG_RD(sc, regs->lines_freed);
18039 BLOGD(sc, DBG_LOAD, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
18040 BLOGD(sc, DBG_LOAD, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
18043 ((uint32_t)((int32_t)freed - (int32_t)freed_start) < to_free)) {
18045 DELAY(FLR_WAIT_INTERVAL);
18046 occup = REG_RD(sc, regs->lines_occup);
18047 freed = REG_RD(sc, regs->lines_freed);
18049 BLOGD(sc, DBG_LOAD, "PBF cmd queue[%d] timed out\n", regs->pN);
18050 BLOGD(sc, DBG_LOAD, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
18051 BLOGD(sc, DBG_LOAD, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
18056 BLOGD(sc, DBG_LOAD, "Waited %d*%d usec for PBF cmd queue[%d]\n",
18057 poll_count - cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
18061 bxe_tx_hw_flushed(struct bxe_softc *sc, uint32_t poll_count)
18063 struct pbf_pN_cmd_regs cmd_regs[] = {
18064 {0, (CHIP_IS_E3B0(sc)) ?
18065 PBF_REG_TQ_OCCUPANCY_Q0 :
18066 PBF_REG_P0_TQ_OCCUPANCY,
18067 (CHIP_IS_E3B0(sc)) ?
18068 PBF_REG_TQ_LINES_FREED_CNT_Q0 :
18069 PBF_REG_P0_TQ_LINES_FREED_CNT},
18070 {1, (CHIP_IS_E3B0(sc)) ?
18071 PBF_REG_TQ_OCCUPANCY_Q1 :
18072 PBF_REG_P1_TQ_OCCUPANCY,
18073 (CHIP_IS_E3B0(sc)) ?
18074 PBF_REG_TQ_LINES_FREED_CNT_Q1 :
18075 PBF_REG_P1_TQ_LINES_FREED_CNT},
18076 {4, (CHIP_IS_E3B0(sc)) ?
18077 PBF_REG_TQ_OCCUPANCY_LB_Q :
18078 PBF_REG_P4_TQ_OCCUPANCY,
18079 (CHIP_IS_E3B0(sc)) ?
18080 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
18081 PBF_REG_P4_TQ_LINES_FREED_CNT}
18084 struct pbf_pN_buf_regs buf_regs[] = {
18085 {0, (CHIP_IS_E3B0(sc)) ?
18086 PBF_REG_INIT_CRD_Q0 :
18087 PBF_REG_P0_INIT_CRD ,
18088 (CHIP_IS_E3B0(sc)) ?
18089 PBF_REG_CREDIT_Q0 :
18091 (CHIP_IS_E3B0(sc)) ?
18092 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
18093 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
18094 {1, (CHIP_IS_E3B0(sc)) ?
18095 PBF_REG_INIT_CRD_Q1 :
18096 PBF_REG_P1_INIT_CRD,
18097 (CHIP_IS_E3B0(sc)) ?
18098 PBF_REG_CREDIT_Q1 :
18100 (CHIP_IS_E3B0(sc)) ?
18101 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
18102 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
18103 {4, (CHIP_IS_E3B0(sc)) ?
18104 PBF_REG_INIT_CRD_LB_Q :
18105 PBF_REG_P4_INIT_CRD,
18106 (CHIP_IS_E3B0(sc)) ?
18107 PBF_REG_CREDIT_LB_Q :
18109 (CHIP_IS_E3B0(sc)) ?
18110 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
18111 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
18116 /* Verify the command queues are flushed P0, P1, P4 */
18117 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++) {
18118 bxe_pbf_pN_cmd_flushed(sc, &cmd_regs[i], poll_count);
18121 /* Verify the transmission buffers are flushed P0, P1, P4 */
18122 for (i = 0; i < ARRAY_SIZE(buf_regs); i++) {
18123 bxe_pbf_pN_buf_flushed(sc, &buf_regs[i], poll_count);
18128 bxe_hw_enable_status(struct bxe_softc *sc)
18132 val = REG_RD(sc, CFC_REG_WEAK_ENABLE_PF);
18133 BLOGD(sc, DBG_LOAD, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
18135 val = REG_RD(sc, PBF_REG_DISABLE_PF);
18136 BLOGD(sc, DBG_LOAD, "PBF_REG_DISABLE_PF is 0x%x\n", val);
18138 val = REG_RD(sc, IGU_REG_PCI_PF_MSI_EN);
18139 BLOGD(sc, DBG_LOAD, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
18141 val = REG_RD(sc, IGU_REG_PCI_PF_MSIX_EN);
18142 BLOGD(sc, DBG_LOAD, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
18144 val = REG_RD(sc, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
18145 BLOGD(sc, DBG_LOAD, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
18147 val = REG_RD(sc, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
18148 BLOGD(sc, DBG_LOAD, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
18150 val = REG_RD(sc, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
18151 BLOGD(sc, DBG_LOAD, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
18153 val = REG_RD(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
18154 BLOGD(sc, DBG_LOAD, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n", val);
18158 bxe_pf_flr_clnup(struct bxe_softc *sc)
18160 uint32_t poll_cnt = bxe_flr_clnup_poll_count(sc);
18162 BLOGD(sc, DBG_LOAD, "Cleanup after FLR PF[%d]\n", SC_ABS_FUNC(sc));
18164 /* Re-enable PF target read access */
18165 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
18167 /* Poll HW usage counters */
18168 BLOGD(sc, DBG_LOAD, "Polling usage counters\n");
18169 if (bxe_poll_hw_usage_counters(sc, poll_cnt)) {
18173 /* Zero the igu 'trailing edge' and 'leading edge' */
18175 /* Send the FW cleanup command */
18176 if (bxe_send_final_clnup(sc, (uint8_t)SC_FUNC(sc), poll_cnt)) {
18182 /* Verify TX hw is flushed */
18183 bxe_tx_hw_flushed(sc, poll_cnt);
18185 /* Wait 100ms (not adjusted according to platform) */
18188 /* Verify no pending pci transactions */
18189 if (bxe_is_pcie_pending(sc)) {
18190 BLOGE(sc, "PCIE Transactions still pending\n");
18194 bxe_hw_enable_status(sc);
18197 * Master enable - Due to WB DMAE writes performed before this
18198 * register is re-initialized as part of the regular function init
18200 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
18206 bxe_init_hw_func(struct bxe_softc *sc)
18208 int port = SC_PORT(sc);
18209 int func = SC_FUNC(sc);
18210 int init_phase = PHASE_PF0 + func;
18211 struct ecore_ilt *ilt = sc->ilt;
18212 uint16_t cdu_ilt_start;
18213 uint32_t addr, val;
18214 uint32_t main_mem_base, main_mem_size, main_mem_prty_clr;
18215 int i, main_mem_width, rc;
18217 BLOGD(sc, DBG_LOAD, "starting func init for func %d\n", func);
18220 if (!CHIP_IS_E1x(sc)) {
18221 rc = bxe_pf_flr_clnup(sc);
18223 BLOGE(sc, "FLR cleanup failed!\n");
18224 // XXX bxe_fw_dump(sc);
18225 // XXX bxe_idle_chk(sc);
18230 /* set MSI reconfigure capability */
18231 if (sc->devinfo.int_block == INT_BLOCK_HC) {
18232 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
18233 val = REG_RD(sc, addr);
18234 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
18235 REG_WR(sc, addr, val);
18238 ecore_init_block(sc, BLOCK_PXP, init_phase);
18239 ecore_init_block(sc, BLOCK_PXP2, init_phase);
18242 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
18244 for (i = 0; i < L2_ILT_LINES(sc); i++) {
18245 ilt->lines[cdu_ilt_start + i].page = sc->context[i].vcxt;
18246 ilt->lines[cdu_ilt_start + i].page_mapping =
18247 sc->context[i].vcxt_dma.paddr;
18248 ilt->lines[cdu_ilt_start + i].size = sc->context[i].size;
18250 ecore_ilt_init_op(sc, INITOP_SET);
18253 REG_WR(sc, PRS_REG_NIC_MODE, 1);
18254 BLOGD(sc, DBG_LOAD, "NIC MODE configured\n");
18256 if (!CHIP_IS_E1x(sc)) {
18257 uint32_t pf_conf = IGU_PF_CONF_FUNC_EN;
18259 /* Turn on a single ISR mode in IGU if driver is going to use
18262 if (sc->interrupt_mode != INTR_MODE_MSIX) {
18263 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
18267 * Timers workaround bug: function init part.
18268 * Need to wait 20msec after initializing ILT,
18269 * needed to make sure there are no requests in
18270 * one of the PXP internal queues with "old" ILT addresses
18275 * Master enable - Due to WB DMAE writes performed before this
18276 * register is re-initialized as part of the regular function
18279 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
18280 /* Enable the function in IGU */
18281 REG_WR(sc, IGU_REG_PF_CONFIGURATION, pf_conf);
18284 sc->dmae_ready = 1;
18286 ecore_init_block(sc, BLOCK_PGLUE_B, init_phase);
18288 if (!CHIP_IS_E1x(sc))
18289 REG_WR(sc, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
18291 ecore_init_block(sc, BLOCK_ATC, init_phase);
18292 ecore_init_block(sc, BLOCK_DMAE, init_phase);
18293 ecore_init_block(sc, BLOCK_NIG, init_phase);
18294 ecore_init_block(sc, BLOCK_SRC, init_phase);
18295 ecore_init_block(sc, BLOCK_MISC, init_phase);
18296 ecore_init_block(sc, BLOCK_TCM, init_phase);
18297 ecore_init_block(sc, BLOCK_UCM, init_phase);
18298 ecore_init_block(sc, BLOCK_CCM, init_phase);
18299 ecore_init_block(sc, BLOCK_XCM, init_phase);
18300 ecore_init_block(sc, BLOCK_TSEM, init_phase);
18301 ecore_init_block(sc, BLOCK_USEM, init_phase);
18302 ecore_init_block(sc, BLOCK_CSEM, init_phase);
18303 ecore_init_block(sc, BLOCK_XSEM, init_phase);
18305 if (!CHIP_IS_E1x(sc))
18306 REG_WR(sc, QM_REG_PF_EN, 1);
18308 if (!CHIP_IS_E1x(sc)) {
18309 REG_WR(sc, TSEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func);
18310 REG_WR(sc, USEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func);
18311 REG_WR(sc, CSEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func);
18312 REG_WR(sc, XSEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func);
18314 ecore_init_block(sc, BLOCK_QM, init_phase);
18316 ecore_init_block(sc, BLOCK_TM, init_phase);
18317 ecore_init_block(sc, BLOCK_DORQ, init_phase);
18319 bxe_iov_init_dq(sc);
18321 ecore_init_block(sc, BLOCK_BRB1, init_phase);
18322 ecore_init_block(sc, BLOCK_PRS, init_phase);
18323 ecore_init_block(sc, BLOCK_TSDM, init_phase);
18324 ecore_init_block(sc, BLOCK_CSDM, init_phase);
18325 ecore_init_block(sc, BLOCK_USDM, init_phase);
18326 ecore_init_block(sc, BLOCK_XSDM, init_phase);
18327 ecore_init_block(sc, BLOCK_UPB, init_phase);
18328 ecore_init_block(sc, BLOCK_XPB, init_phase);
18329 ecore_init_block(sc, BLOCK_PBF, init_phase);
18330 if (!CHIP_IS_E1x(sc))
18331 REG_WR(sc, PBF_REG_DISABLE_PF, 0);
18333 ecore_init_block(sc, BLOCK_CDU, init_phase);
18335 ecore_init_block(sc, BLOCK_CFC, init_phase);
18337 if (!CHIP_IS_E1x(sc))
18338 REG_WR(sc, CFC_REG_WEAK_ENABLE_PF, 1);
18341 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 1);
18342 REG_WR(sc, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, OVLAN(sc));
18345 ecore_init_block(sc, BLOCK_MISC_AEU, init_phase);
18347 /* HC init per function */
18348 if (sc->devinfo.int_block == INT_BLOCK_HC) {
18349 if (CHIP_IS_E1H(sc)) {
18350 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
18352 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, 0);
18353 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, 0);
18355 ecore_init_block(sc, BLOCK_HC, init_phase);
18358 int num_segs, sb_idx, prod_offset;
18360 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
18362 if (!CHIP_IS_E1x(sc)) {
18363 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, 0);
18364 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, 0);
18367 ecore_init_block(sc, BLOCK_IGU, init_phase);
18369 if (!CHIP_IS_E1x(sc)) {
18373 * E2 mode: address 0-135 match to the mapping memory;
18374 * 136 - PF0 default prod; 137 - PF1 default prod;
18375 * 138 - PF2 default prod; 139 - PF3 default prod;
18376 * 140 - PF0 attn prod; 141 - PF1 attn prod;
18377 * 142 - PF2 attn prod; 143 - PF3 attn prod;
18378 * 144-147 reserved.
18380 * E1.5 mode - In backward compatible mode;
18381 * for non default SB; each even line in the memory
18382 * holds the U producer and each odd line hold
18383 * the C producer. The first 128 producers are for
18384 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
18385 * producers are for the DSB for each PF.
18386 * Each PF has five segments: (the order inside each
18387 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
18388 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
18389 * 144-147 attn prods;
18391 /* non-default-status-blocks */
18392 num_segs = CHIP_INT_MODE_IS_BC(sc) ?
18393 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
18394 for (sb_idx = 0; sb_idx < sc->igu_sb_cnt; sb_idx++) {
18395 prod_offset = (sc->igu_base_sb + sb_idx) *
18398 for (i = 0; i < num_segs; i++) {
18399 addr = IGU_REG_PROD_CONS_MEMORY +
18400 (prod_offset + i) * 4;
18401 REG_WR(sc, addr, 0);
18403 /* send consumer update with value 0 */
18404 bxe_ack_sb(sc, sc->igu_base_sb + sb_idx,
18405 USTORM_ID, 0, IGU_INT_NOP, 1);
18406 bxe_igu_clear_sb(sc, sc->igu_base_sb + sb_idx);
18409 /* default-status-blocks */
18410 num_segs = CHIP_INT_MODE_IS_BC(sc) ?
18411 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
18413 if (CHIP_IS_MODE_4_PORT(sc))
18414 dsb_idx = SC_FUNC(sc);
18416 dsb_idx = SC_VN(sc);
18418 prod_offset = (CHIP_INT_MODE_IS_BC(sc) ?
18419 IGU_BC_BASE_DSB_PROD + dsb_idx :
18420 IGU_NORM_BASE_DSB_PROD + dsb_idx);
18423 * igu prods come in chunks of E1HVN_MAX (4) -
18424 * does not matters what is the current chip mode
18426 for (i = 0; i < (num_segs * E1HVN_MAX);
18428 addr = IGU_REG_PROD_CONS_MEMORY +
18429 (prod_offset + i)*4;
18430 REG_WR(sc, addr, 0);
18432 /* send consumer update with 0 */
18433 if (CHIP_INT_MODE_IS_BC(sc)) {
18434 bxe_ack_sb(sc, sc->igu_dsb_id,
18435 USTORM_ID, 0, IGU_INT_NOP, 1);
18436 bxe_ack_sb(sc, sc->igu_dsb_id,
18437 CSTORM_ID, 0, IGU_INT_NOP, 1);
18438 bxe_ack_sb(sc, sc->igu_dsb_id,
18439 XSTORM_ID, 0, IGU_INT_NOP, 1);
18440 bxe_ack_sb(sc, sc->igu_dsb_id,
18441 TSTORM_ID, 0, IGU_INT_NOP, 1);
18442 bxe_ack_sb(sc, sc->igu_dsb_id,
18443 ATTENTION_ID, 0, IGU_INT_NOP, 1);
18445 bxe_ack_sb(sc, sc->igu_dsb_id,
18446 USTORM_ID, 0, IGU_INT_NOP, 1);
18447 bxe_ack_sb(sc, sc->igu_dsb_id,
18448 ATTENTION_ID, 0, IGU_INT_NOP, 1);
18450 bxe_igu_clear_sb(sc, sc->igu_dsb_id);
18452 /* !!! these should become driver const once
18453 rf-tool supports split-68 const */
18454 REG_WR(sc, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
18455 REG_WR(sc, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
18456 REG_WR(sc, IGU_REG_SB_MASK_LSB, 0);
18457 REG_WR(sc, IGU_REG_SB_MASK_MSB, 0);
18458 REG_WR(sc, IGU_REG_PBA_STATUS_LSB, 0);
18459 REG_WR(sc, IGU_REG_PBA_STATUS_MSB, 0);
18463 /* Reset PCIE errors for debug */
18464 REG_WR(sc, 0x2114, 0xffffffff);
18465 REG_WR(sc, 0x2120, 0xffffffff);
18467 if (CHIP_IS_E1x(sc)) {
18468 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
18469 main_mem_base = HC_REG_MAIN_MEMORY +
18470 SC_PORT(sc) * (main_mem_size * 4);
18471 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
18472 main_mem_width = 8;
18474 val = REG_RD(sc, main_mem_prty_clr);
18476 BLOGD(sc, DBG_LOAD,
18477 "Parity errors in HC block during function init (0x%x)!\n",
18481 /* Clear "false" parity errors in MSI-X table */
18482 for (i = main_mem_base;
18483 i < main_mem_base + main_mem_size * 4;
18484 i += main_mem_width) {
18485 bxe_read_dmae(sc, i, main_mem_width / 4);
18486 bxe_write_dmae(sc, BXE_SP_MAPPING(sc, wb_data),
18487 i, main_mem_width / 4);
18489 /* Clear HC parity attention */
18490 REG_RD(sc, main_mem_prty_clr);
18494 /* Enable STORMs SP logging */
18495 REG_WR8(sc, BAR_USTRORM_INTMEM +
18496 USTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
18497 REG_WR8(sc, BAR_TSTRORM_INTMEM +
18498 TSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
18499 REG_WR8(sc, BAR_CSTRORM_INTMEM +
18500 CSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
18501 REG_WR8(sc, BAR_XSTRORM_INTMEM +
18502 XSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
18505 elink_phy_probe(&sc->link_params);
18511 bxe_link_reset(struct bxe_softc *sc)
18513 if (!BXE_NOMCP(sc)) {
18514 bxe_acquire_phy_lock(sc);
18515 elink_lfa_reset(&sc->link_params, &sc->link_vars);
18516 bxe_release_phy_lock(sc);
18518 if (!CHIP_REV_IS_SLOW(sc)) {
18519 BLOGW(sc, "Bootcode is missing - cannot reset link\n");
18525 bxe_reset_port(struct bxe_softc *sc)
18527 int port = SC_PORT(sc);
18530 ELINK_DEBUG_P0(sc, "bxe_reset_port called\n");
18531 /* reset physical Link */
18532 bxe_link_reset(sc);
18534 REG_WR(sc, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
18536 /* Do not rcv packets to BRB */
18537 REG_WR(sc, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
18538 /* Do not direct rcv packets that are not for MCP to the BRB */
18539 REG_WR(sc, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
18540 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
18542 /* Configure AEU */
18543 REG_WR(sc, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
18547 /* Check for BRB port occupancy */
18548 val = REG_RD(sc, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
18550 BLOGD(sc, DBG_LOAD,
18551 "BRB1 is not empty, %d blocks are occupied\n", val);
18554 /* TODO: Close Doorbell port? */
18558 bxe_ilt_wr(struct bxe_softc *sc,
18563 uint32_t wb_write[2];
18565 if (CHIP_IS_E1(sc)) {
18566 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
18568 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
18571 wb_write[0] = ONCHIP_ADDR1(addr);
18572 wb_write[1] = ONCHIP_ADDR2(addr);
18573 REG_WR_DMAE(sc, reg, wb_write, 2);
18577 bxe_clear_func_ilt(struct bxe_softc *sc,
18580 uint32_t i, base = FUNC_ILT_BASE(func);
18581 for (i = base; i < base + ILT_PER_FUNC; i++) {
18582 bxe_ilt_wr(sc, i, 0);
18587 bxe_reset_func(struct bxe_softc *sc)
18589 struct bxe_fastpath *fp;
18590 int port = SC_PORT(sc);
18591 int func = SC_FUNC(sc);
18594 /* Disable the function in the FW */
18595 REG_WR8(sc, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
18596 REG_WR8(sc, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
18597 REG_WR8(sc, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
18598 REG_WR8(sc, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
18601 FOR_EACH_ETH_QUEUE(sc, i) {
18603 REG_WR8(sc, BAR_CSTRORM_INTMEM +
18604 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
18609 REG_WR8(sc, BAR_CSTRORM_INTMEM +
18610 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
18613 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++) {
18614 REG_WR(sc, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func), 0);
18617 /* Configure IGU */
18618 if (sc->devinfo.int_block == INT_BLOCK_HC) {
18619 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, 0);
18620 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, 0);
18622 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, 0);
18623 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, 0);
18626 if (CNIC_LOADED(sc)) {
18627 /* Disable Timer scan */
18628 REG_WR(sc, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
18630 * Wait for at least 10ms and up to 2 second for the timers
18633 for (i = 0; i < 200; i++) {
18635 if (!REG_RD(sc, TM_REG_LIN0_SCAN_ON + port*4))
18641 bxe_clear_func_ilt(sc, func);
18644 * Timers workaround bug for E2: if this is vnic-3,
18645 * we need to set the entire ilt range for this timers.
18647 if (!CHIP_IS_E1x(sc) && SC_VN(sc) == 3) {
18648 struct ilt_client_info ilt_cli;
18649 /* use dummy TM client */
18650 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
18652 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
18653 ilt_cli.client_num = ILT_CLIENT_TM;
18655 ecore_ilt_boundry_init_op(sc, &ilt_cli, 0, INITOP_CLEAR);
18658 /* this assumes that reset_port() called before reset_func()*/
18659 if (!CHIP_IS_E1x(sc)) {
18660 bxe_pf_disable(sc);
18663 sc->dmae_ready = 0;
18667 bxe_gunzip_init(struct bxe_softc *sc)
18673 bxe_gunzip_end(struct bxe_softc *sc)
18679 bxe_init_firmware(struct bxe_softc *sc)
18681 if (CHIP_IS_E1(sc)) {
18682 ecore_init_e1_firmware(sc);
18683 sc->iro_array = e1_iro_arr;
18684 } else if (CHIP_IS_E1H(sc)) {
18685 ecore_init_e1h_firmware(sc);
18686 sc->iro_array = e1h_iro_arr;
18687 } else if (!CHIP_IS_E1x(sc)) {
18688 ecore_init_e2_firmware(sc);
18689 sc->iro_array = e2_iro_arr;
18691 BLOGE(sc, "Unsupported chip revision\n");
18699 bxe_release_firmware(struct bxe_softc *sc)
18706 ecore_gunzip(struct bxe_softc *sc,
18707 const uint8_t *zbuf,
18710 /* XXX : Implement... */
18711 BLOGD(sc, DBG_LOAD, "ECORE_GUNZIP NOT IMPLEMENTED\n");
18716 ecore_reg_wr_ind(struct bxe_softc *sc,
18720 bxe_reg_wr_ind(sc, addr, val);
18724 ecore_write_dmae_phys_len(struct bxe_softc *sc,
18725 bus_addr_t phys_addr,
18729 bxe_write_dmae_phys_len(sc, phys_addr, addr, len);
18733 ecore_storm_memset_struct(struct bxe_softc *sc,
18739 for (i = 0; i < size/4; i++) {
18740 REG_WR(sc, addr + (i * 4), data[i]);
18746 * character device - ioctl interface definitions
18750 #include "bxe_dump.h"
18751 #include "bxe_ioctl.h"
18752 #include <sys/conf.h>
18754 static int bxe_eioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
18755 struct thread *td);
18757 static struct cdevsw bxe_cdevsw = {
18758 .d_version = D_VERSION,
18759 .d_ioctl = bxe_eioctl,
18760 .d_name = "bxecnic",
18763 #define BXE_PATH(sc) (CHIP_IS_E1x(sc) ? 0 : (sc->pcie_func & 1))
18766 #define DUMP_ALL_PRESETS 0x1FFF
18767 #define DUMP_MAX_PRESETS 13
18768 #define IS_E1_REG(chips) ((chips & DUMP_CHIP_E1) == DUMP_CHIP_E1)
18769 #define IS_E1H_REG(chips) ((chips & DUMP_CHIP_E1H) == DUMP_CHIP_E1H)
18770 #define IS_E2_REG(chips) ((chips & DUMP_CHIP_E2) == DUMP_CHIP_E2)
18771 #define IS_E3A0_REG(chips) ((chips & DUMP_CHIP_E3A0) == DUMP_CHIP_E3A0)
18772 #define IS_E3B0_REG(chips) ((chips & DUMP_CHIP_E3B0) == DUMP_CHIP_E3B0)
18774 #define IS_REG_IN_PRESET(presets, idx) \
18775 ((presets & (1 << (idx-1))) == (1 << (idx-1)))
18779 bxe_get_preset_regs_len(struct bxe_softc *sc, uint32_t preset)
18781 if (CHIP_IS_E1(sc))
18782 return dump_num_registers[0][preset-1];
18783 else if (CHIP_IS_E1H(sc))
18784 return dump_num_registers[1][preset-1];
18785 else if (CHIP_IS_E2(sc))
18786 return dump_num_registers[2][preset-1];
18787 else if (CHIP_IS_E3A0(sc))
18788 return dump_num_registers[3][preset-1];
18789 else if (CHIP_IS_E3B0(sc))
18790 return dump_num_registers[4][preset-1];
18796 bxe_get_total_regs_len32(struct bxe_softc *sc)
18798 uint32_t preset_idx;
18799 int regdump_len32 = 0;
18802 /* Calculate the total preset regs length */
18803 for (preset_idx = 1; preset_idx <= DUMP_MAX_PRESETS; preset_idx++) {
18804 regdump_len32 += bxe_get_preset_regs_len(sc, preset_idx);
18807 return regdump_len32;
18810 static const uint32_t *
18811 __bxe_get_page_addr_ar(struct bxe_softc *sc)
18813 if (CHIP_IS_E2(sc))
18814 return page_vals_e2;
18815 else if (CHIP_IS_E3(sc))
18816 return page_vals_e3;
18822 __bxe_get_page_reg_num(struct bxe_softc *sc)
18824 if (CHIP_IS_E2(sc))
18825 return PAGE_MODE_VALUES_E2;
18826 else if (CHIP_IS_E3(sc))
18827 return PAGE_MODE_VALUES_E3;
18832 static const uint32_t *
18833 __bxe_get_page_write_ar(struct bxe_softc *sc)
18835 if (CHIP_IS_E2(sc))
18836 return page_write_regs_e2;
18837 else if (CHIP_IS_E3(sc))
18838 return page_write_regs_e3;
18844 __bxe_get_page_write_num(struct bxe_softc *sc)
18846 if (CHIP_IS_E2(sc))
18847 return PAGE_WRITE_REGS_E2;
18848 else if (CHIP_IS_E3(sc))
18849 return PAGE_WRITE_REGS_E3;
18854 static const struct reg_addr *
18855 __bxe_get_page_read_ar(struct bxe_softc *sc)
18857 if (CHIP_IS_E2(sc))
18858 return page_read_regs_e2;
18859 else if (CHIP_IS_E3(sc))
18860 return page_read_regs_e3;
18866 __bxe_get_page_read_num(struct bxe_softc *sc)
18868 if (CHIP_IS_E2(sc))
18869 return PAGE_READ_REGS_E2;
18870 else if (CHIP_IS_E3(sc))
18871 return PAGE_READ_REGS_E3;
18877 bxe_is_reg_in_chip(struct bxe_softc *sc, const struct reg_addr *reg_info)
18879 if (CHIP_IS_E1(sc))
18880 return IS_E1_REG(reg_info->chips);
18881 else if (CHIP_IS_E1H(sc))
18882 return IS_E1H_REG(reg_info->chips);
18883 else if (CHIP_IS_E2(sc))
18884 return IS_E2_REG(reg_info->chips);
18885 else if (CHIP_IS_E3A0(sc))
18886 return IS_E3A0_REG(reg_info->chips);
18887 else if (CHIP_IS_E3B0(sc))
18888 return IS_E3B0_REG(reg_info->chips);
18894 bxe_is_wreg_in_chip(struct bxe_softc *sc, const struct wreg_addr *wreg_info)
18896 if (CHIP_IS_E1(sc))
18897 return IS_E1_REG(wreg_info->chips);
18898 else if (CHIP_IS_E1H(sc))
18899 return IS_E1H_REG(wreg_info->chips);
18900 else if (CHIP_IS_E2(sc))
18901 return IS_E2_REG(wreg_info->chips);
18902 else if (CHIP_IS_E3A0(sc))
18903 return IS_E3A0_REG(wreg_info->chips);
18904 else if (CHIP_IS_E3B0(sc))
18905 return IS_E3B0_REG(wreg_info->chips);
18911 * bxe_read_pages_regs - read "paged" registers
18913 * @bp device handle
18916 * Reads "paged" memories: memories that may only be read by first writing to a
18917 * specific address ("write address") and then reading from a specific address
18918 * ("read address"). There may be more than one write address per "page" and
18919 * more than one read address per write address.
18922 bxe_read_pages_regs(struct bxe_softc *sc, uint32_t *p, uint32_t preset)
18924 uint32_t i, j, k, n;
18926 /* addresses of the paged registers */
18927 const uint32_t *page_addr = __bxe_get_page_addr_ar(sc);
18928 /* number of paged registers */
18929 int num_pages = __bxe_get_page_reg_num(sc);
18930 /* write addresses */
18931 const uint32_t *write_addr = __bxe_get_page_write_ar(sc);
18932 /* number of write addresses */
18933 int write_num = __bxe_get_page_write_num(sc);
18934 /* read addresses info */
18935 const struct reg_addr *read_addr = __bxe_get_page_read_ar(sc);
18936 /* number of read addresses */
18937 int read_num = __bxe_get_page_read_num(sc);
18938 uint32_t addr, size;
18940 for (i = 0; i < num_pages; i++) {
18941 for (j = 0; j < write_num; j++) {
18942 REG_WR(sc, write_addr[j], page_addr[i]);
18944 for (k = 0; k < read_num; k++) {
18945 if (IS_REG_IN_PRESET(read_addr[k].presets, preset)) {
18946 size = read_addr[k].size;
18947 for (n = 0; n < size; n++) {
18948 addr = read_addr[k].addr + n*4;
18949 *p++ = REG_RD(sc, addr);
18960 bxe_get_preset_regs(struct bxe_softc *sc, uint32_t *p, uint32_t preset)
18962 uint32_t i, j, addr;
18963 const struct wreg_addr *wreg_addr_p = NULL;
18965 if (CHIP_IS_E1(sc))
18966 wreg_addr_p = &wreg_addr_e1;
18967 else if (CHIP_IS_E1H(sc))
18968 wreg_addr_p = &wreg_addr_e1h;
18969 else if (CHIP_IS_E2(sc))
18970 wreg_addr_p = &wreg_addr_e2;
18971 else if (CHIP_IS_E3A0(sc))
18972 wreg_addr_p = &wreg_addr_e3;
18973 else if (CHIP_IS_E3B0(sc))
18974 wreg_addr_p = &wreg_addr_e3b0;
18978 /* Read the idle_chk registers */
18979 for (i = 0; i < IDLE_REGS_COUNT; i++) {
18980 if (bxe_is_reg_in_chip(sc, &idle_reg_addrs[i]) &&
18981 IS_REG_IN_PRESET(idle_reg_addrs[i].presets, preset)) {
18982 for (j = 0; j < idle_reg_addrs[i].size; j++)
18983 *p++ = REG_RD(sc, idle_reg_addrs[i].addr + j*4);
18987 /* Read the regular registers */
18988 for (i = 0; i < REGS_COUNT; i++) {
18989 if (bxe_is_reg_in_chip(sc, ®_addrs[i]) &&
18990 IS_REG_IN_PRESET(reg_addrs[i].presets, preset)) {
18991 for (j = 0; j < reg_addrs[i].size; j++)
18992 *p++ = REG_RD(sc, reg_addrs[i].addr + j*4);
18996 /* Read the CAM registers */
18997 if (bxe_is_wreg_in_chip(sc, wreg_addr_p) &&
18998 IS_REG_IN_PRESET(wreg_addr_p->presets, preset)) {
18999 for (i = 0; i < wreg_addr_p->size; i++) {
19000 *p++ = REG_RD(sc, wreg_addr_p->addr + i*4);
19002 /* In case of wreg_addr register, read additional
19003 registers from read_regs array
19005 for (j = 0; j < wreg_addr_p->read_regs_count; j++) {
19006 addr = *(wreg_addr_p->read_regs);
19007 *p++ = REG_RD(sc, addr + j*4);
19012 /* Paged registers are supported in E2 & E3 only */
19013 if (CHIP_IS_E2(sc) || CHIP_IS_E3(sc)) {
19014 /* Read "paged" registers */
19015 bxe_read_pages_regs(sc, p, preset);
19022 bxe_grc_dump(struct bxe_softc *sc)
19025 uint32_t preset_idx;
19028 struct dump_header *d_hdr;
19032 uint32_t cmd_offset;
19033 struct ecore_ilt *ilt = SC_ILT(sc);
19034 struct bxe_fastpath *fp;
19035 struct ilt_client_info *ilt_cli;
19039 if (sc->grcdump_done || sc->grcdump_started)
19042 sc->grcdump_started = 1;
19043 BLOGI(sc, "Started collecting grcdump\n");
19045 grc_dump_size = (bxe_get_total_regs_len32(sc) * sizeof(uint32_t)) +
19046 sizeof(struct dump_header);
19048 sc->grc_dump = malloc(grc_dump_size, M_DEVBUF, M_NOWAIT);
19050 if (sc->grc_dump == NULL) {
19051 BLOGW(sc, "Unable to allocate memory for grcdump collection\n");
19057 /* Disable parity attentions as long as following dump may
19058 * cause false alarms by reading never written registers. We
19059 * will re-enable parity attentions right after the dump.
19062 /* Disable parity on path 0 */
19063 bxe_pretend_func(sc, 0);
19065 ecore_disable_blocks_parity(sc);
19067 /* Disable parity on path 1 */
19068 bxe_pretend_func(sc, 1);
19069 ecore_disable_blocks_parity(sc);
19071 /* Return to current function */
19072 bxe_pretend_func(sc, SC_ABS_FUNC(sc));
19074 buf = sc->grc_dump;
19075 d_hdr = sc->grc_dump;
19077 d_hdr->header_size = (sizeof(struct dump_header) >> 2) - 1;
19078 d_hdr->version = BNX2X_DUMP_VERSION;
19079 d_hdr->preset = DUMP_ALL_PRESETS;
19081 if (CHIP_IS_E1(sc)) {
19082 d_hdr->dump_meta_data = DUMP_CHIP_E1;
19083 } else if (CHIP_IS_E1H(sc)) {
19084 d_hdr->dump_meta_data = DUMP_CHIP_E1H;
19085 } else if (CHIP_IS_E2(sc)) {
19086 d_hdr->dump_meta_data = DUMP_CHIP_E2 |
19087 (BXE_PATH(sc) ? DUMP_PATH_1 : DUMP_PATH_0);
19088 } else if (CHIP_IS_E3A0(sc)) {
19089 d_hdr->dump_meta_data = DUMP_CHIP_E3A0 |
19090 (BXE_PATH(sc) ? DUMP_PATH_1 : DUMP_PATH_0);
19091 } else if (CHIP_IS_E3B0(sc)) {
19092 d_hdr->dump_meta_data = DUMP_CHIP_E3B0 |
19093 (BXE_PATH(sc) ? DUMP_PATH_1 : DUMP_PATH_0);
19096 buf += sizeof(struct dump_header);
19098 for (preset_idx = 1; preset_idx <= DUMP_MAX_PRESETS; preset_idx++) {
19100 /* Skip presets with IOR */
19101 if ((preset_idx == 2) || (preset_idx == 5) || (preset_idx == 8) ||
19102 (preset_idx == 11))
19105 rval = bxe_get_preset_regs(sc, (uint32_t *)buf, preset_idx);
19110 size = bxe_get_preset_regs_len(sc, preset_idx) * (sizeof (uint32_t));
19115 bxe_pretend_func(sc, 0);
19116 ecore_clear_blocks_parity(sc);
19117 ecore_enable_blocks_parity(sc);
19119 bxe_pretend_func(sc, 1);
19120 ecore_clear_blocks_parity(sc);
19121 ecore_enable_blocks_parity(sc);
19123 /* Return to current function */
19124 bxe_pretend_func(sc, SC_ABS_FUNC(sc));
19128 if(sc->state == BXE_STATE_OPEN) {
19129 if(sc->fw_stats_req != NULL) {
19130 BLOGI(sc, "fw stats start_paddr %#jx end_paddr %#jx vaddr %p size 0x%x\n",
19131 (uintmax_t)sc->fw_stats_req_mapping,
19132 (uintmax_t)sc->fw_stats_data_mapping,
19133 sc->fw_stats_req, (sc->fw_stats_req_size + sc->fw_stats_data_size));
19135 if(sc->def_sb != NULL) {
19136 BLOGI(sc, "def_status_block paddr %p vaddr %p size 0x%zx\n",
19137 (void *)sc->def_sb_dma.paddr, sc->def_sb,
19138 sizeof(struct host_sp_status_block));
19140 if(sc->eq_dma.vaddr != NULL) {
19141 BLOGI(sc, "event_queue paddr %#jx vaddr %p size 0x%x\n",
19142 (uintmax_t)sc->eq_dma.paddr, sc->eq_dma.vaddr, BCM_PAGE_SIZE);
19144 if(sc->sp_dma.vaddr != NULL) {
19145 BLOGI(sc, "slow path paddr %#jx vaddr %p size 0x%zx\n",
19146 (uintmax_t)sc->sp_dma.paddr, sc->sp_dma.vaddr,
19147 sizeof(struct bxe_slowpath));
19149 if(sc->spq_dma.vaddr != NULL) {
19150 BLOGI(sc, "slow path queue paddr %#jx vaddr %p size 0x%x\n",
19151 (uintmax_t)sc->spq_dma.paddr, sc->spq_dma.vaddr, BCM_PAGE_SIZE);
19153 if(sc->gz_buf_dma.vaddr != NULL) {
19154 BLOGI(sc, "fw_buf paddr %#jx vaddr %p size 0x%x\n",
19155 (uintmax_t)sc->gz_buf_dma.paddr, sc->gz_buf_dma.vaddr,
19158 for (i = 0; i < sc->num_queues; i++) {
19160 if(fp->sb_dma.vaddr != NULL && fp->tx_dma.vaddr != NULL &&
19161 fp->rx_dma.vaddr != NULL && fp->rcq_dma.vaddr != NULL &&
19162 fp->rx_sge_dma.vaddr != NULL) {
19164 BLOGI(sc, "FP status block fp %d paddr %#jx vaddr %p size 0x%zx\n", i,
19165 (uintmax_t)fp->sb_dma.paddr, fp->sb_dma.vaddr,
19166 sizeof(union bxe_host_hc_status_block));
19167 BLOGI(sc, "TX BD CHAIN fp %d paddr %#jx vaddr %p size 0x%x\n", i,
19168 (uintmax_t)fp->tx_dma.paddr, fp->tx_dma.vaddr,
19169 (BCM_PAGE_SIZE * TX_BD_NUM_PAGES));
19170 BLOGI(sc, "RX BD CHAIN fp %d paddr %#jx vaddr %p size 0x%x\n", i,
19171 (uintmax_t)fp->rx_dma.paddr, fp->rx_dma.vaddr,
19172 (BCM_PAGE_SIZE * RX_BD_NUM_PAGES));
19173 BLOGI(sc, "RX RCQ CHAIN fp %d paddr %#jx vaddr %p size 0x%zx\n", i,
19174 (uintmax_t)fp->rcq_dma.paddr, fp->rcq_dma.vaddr,
19175 (BCM_PAGE_SIZE * RCQ_NUM_PAGES));
19176 BLOGI(sc, "RX SGE CHAIN fp %d paddr %#jx vaddr %p size 0x%x\n", i,
19177 (uintmax_t)fp->rx_sge_dma.paddr, fp->rx_sge_dma.vaddr,
19178 (BCM_PAGE_SIZE * RX_SGE_NUM_PAGES));
19182 ilt_cli = &ilt->clients[1];
19183 if(ilt->lines != NULL) {
19184 for (i = ilt_cli->start; i <= ilt_cli->end; i++) {
19185 BLOGI(sc, "ECORE_ILT paddr %#jx vaddr %p size 0x%x\n",
19186 (uintmax_t)(((struct bxe_dma *)((&ilt->lines[i])->page))->paddr),
19187 ((struct bxe_dma *)((&ilt->lines[i])->page))->vaddr, BCM_PAGE_SIZE);
19193 cmd_offset = DMAE_REG_CMD_MEM;
19194 for (i = 0; i < 224; i++) {
19195 reg_addr = (cmd_offset +(i * 4));
19196 reg_val = REG_RD(sc, reg_addr);
19197 BLOGI(sc, "DMAE_REG_CMD_MEM i=%d reg_addr 0x%x reg_val 0x%08x\n",i,
19198 reg_addr, reg_val);
19202 BLOGI(sc, "Collection of grcdump done\n");
19203 sc->grcdump_done = 1;
19208 bxe_add_cdev(struct bxe_softc *sc)
19210 sc->eeprom = malloc(BXE_EEPROM_MAX_DATA_LEN, M_DEVBUF, M_NOWAIT);
19212 if (sc->eeprom == NULL) {
19213 BLOGW(sc, "Unable to alloc for eeprom size buffer\n");
19217 sc->ioctl_dev = make_dev(&bxe_cdevsw,
19218 sc->ifnet->if_dunit,
19223 if_name(sc->ifnet));
19225 if (sc->ioctl_dev == NULL) {
19226 free(sc->eeprom, M_DEVBUF);
19231 sc->ioctl_dev->si_drv1 = sc;
19237 bxe_del_cdev(struct bxe_softc *sc)
19239 if (sc->ioctl_dev != NULL)
19240 destroy_dev(sc->ioctl_dev);
19242 if (sc->eeprom != NULL) {
19243 free(sc->eeprom, M_DEVBUF);
19246 sc->ioctl_dev = NULL;
19251 static bool bxe_is_nvram_accessible(struct bxe_softc *sc)
19254 if ((sc->ifnet->if_drv_flags & IFF_DRV_RUNNING) == 0)
19262 bxe_wr_eeprom(struct bxe_softc *sc, void *data, uint32_t offset, uint32_t len)
19266 if(!bxe_is_nvram_accessible(sc)) {
19267 BLOGW(sc, "Cannot access eeprom when interface is down\n");
19270 rval = bxe_nvram_write(sc, offset, (uint8_t *)data, len);
19277 bxe_rd_eeprom(struct bxe_softc *sc, void *data, uint32_t offset, uint32_t len)
19281 if(!bxe_is_nvram_accessible(sc)) {
19282 BLOGW(sc, "Cannot access eeprom when interface is down\n");
19285 rval = bxe_nvram_read(sc, offset, (uint8_t *)data, len);
19291 bxe_eeprom_rd_wr(struct bxe_softc *sc, bxe_eeprom_t *eeprom)
19295 switch (eeprom->eeprom_cmd) {
19297 case BXE_EEPROM_CMD_SET_EEPROM:
19299 rval = copyin(eeprom->eeprom_data, sc->eeprom,
19300 eeprom->eeprom_data_len);
19305 rval = bxe_wr_eeprom(sc, sc->eeprom, eeprom->eeprom_offset,
19306 eeprom->eeprom_data_len);
19309 case BXE_EEPROM_CMD_GET_EEPROM:
19311 rval = bxe_rd_eeprom(sc, sc->eeprom, eeprom->eeprom_offset,
19312 eeprom->eeprom_data_len);
19318 rval = copyout(sc->eeprom, eeprom->eeprom_data,
19319 eeprom->eeprom_data_len);
19328 BLOGW(sc, "ioctl cmd %d failed rval %d\n", eeprom->eeprom_cmd, rval);
19335 bxe_get_settings(struct bxe_softc *sc, bxe_dev_setting_t *dev_p)
19337 uint32_t ext_phy_config;
19338 int port = SC_PORT(sc);
19339 int cfg_idx = bxe_get_link_cfg_idx(sc);
19341 dev_p->supported = sc->port.supported[cfg_idx] |
19342 (sc->port.supported[cfg_idx ^ 1] &
19343 (ELINK_SUPPORTED_TP | ELINK_SUPPORTED_FIBRE));
19344 dev_p->advertising = sc->port.advertising[cfg_idx];
19345 if(sc->link_params.phy[bxe_get_cur_phy_idx(sc)].media_type ==
19346 ELINK_ETH_PHY_SFP_1G_FIBER) {
19347 dev_p->supported = ~(ELINK_SUPPORTED_10000baseT_Full);
19348 dev_p->advertising &= ~(ADVERTISED_10000baseT_Full);
19350 if ((sc->state == BXE_STATE_OPEN) && sc->link_vars.link_up &&
19351 !(sc->flags & BXE_MF_FUNC_DIS)) {
19352 dev_p->duplex = sc->link_vars.duplex;
19353 if (IS_MF(sc) && !BXE_NOMCP(sc))
19354 dev_p->speed = bxe_get_mf_speed(sc);
19356 dev_p->speed = sc->link_vars.line_speed;
19358 dev_p->duplex = DUPLEX_UNKNOWN;
19359 dev_p->speed = SPEED_UNKNOWN;
19362 dev_p->port = bxe_media_detect(sc);
19364 ext_phy_config = SHMEM_RD(sc,
19365 dev_info.port_hw_config[port].external_phy_config);
19366 if((ext_phy_config & PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK) ==
19367 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
19368 dev_p->phy_address = sc->port.phy_addr;
19369 else if(((ext_phy_config & PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK) !=
19370 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
19371 ((ext_phy_config & PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK) !=
19372 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
19373 dev_p->phy_address = ELINK_XGXS_EXT_PHY_ADDR(ext_phy_config);
19375 dev_p->phy_address = 0;
19377 if(sc->link_params.req_line_speed[cfg_idx] == ELINK_SPEED_AUTO_NEG)
19378 dev_p->autoneg = AUTONEG_ENABLE;
19380 dev_p->autoneg = AUTONEG_DISABLE;
19387 bxe_eioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
19390 struct bxe_softc *sc;
19393 bxe_grcdump_t *dump = NULL;
19395 bxe_drvinfo_t *drv_infop = NULL;
19396 bxe_dev_setting_t *dev_p;
19397 bxe_dev_setting_t dev_set;
19398 bxe_get_regs_t *reg_p;
19399 bxe_reg_rdw_t *reg_rdw_p;
19400 bxe_pcicfg_rdw_t *cfg_rdw_p;
19401 bxe_perm_mac_addr_t *mac_addr_p;
19404 if ((sc = (struct bxe_softc *)dev->si_drv1) == NULL)
19409 dump = (bxe_grcdump_t *)data;
19413 case BXE_GRC_DUMP_SIZE:
19414 dump->pci_func = sc->pcie_func;
19415 dump->grcdump_size =
19416 (bxe_get_total_regs_len32(sc) * sizeof(uint32_t)) +
19417 sizeof(struct dump_header);
19422 grc_dump_size = (bxe_get_total_regs_len32(sc) * sizeof(uint32_t)) +
19423 sizeof(struct dump_header);
19424 if ((!sc->trigger_grcdump) || (dump->grcdump == NULL) ||
19425 (dump->grcdump_size < grc_dump_size)) {
19430 if((sc->trigger_grcdump) && (!sc->grcdump_done) &&
19431 (!sc->grcdump_started)) {
19432 rval = bxe_grc_dump(sc);
19435 if((!rval) && (sc->grcdump_done) && (sc->grcdump_started) &&
19436 (sc->grc_dump != NULL)) {
19437 dump->grcdump_dwords = grc_dump_size >> 2;
19438 rval = copyout(sc->grc_dump, dump->grcdump, grc_dump_size);
19439 free(sc->grc_dump, M_DEVBUF);
19440 sc->grc_dump = NULL;
19441 sc->grcdump_started = 0;
19442 sc->grcdump_done = 0;
19448 drv_infop = (bxe_drvinfo_t *)data;
19449 snprintf(drv_infop->drv_name, BXE_DRV_NAME_LENGTH, "%s", "bxe");
19450 snprintf(drv_infop->drv_version, BXE_DRV_VERSION_LENGTH, "v:%s",
19451 BXE_DRIVER_VERSION);
19452 snprintf(drv_infop->mfw_version, BXE_MFW_VERSION_LENGTH, "%s",
19453 sc->devinfo.bc_ver_str);
19454 snprintf(drv_infop->stormfw_version, BXE_STORMFW_VERSION_LENGTH,
19455 "%s", sc->fw_ver_str);
19456 drv_infop->eeprom_dump_len = sc->devinfo.flash_size;
19457 drv_infop->reg_dump_len =
19458 (bxe_get_total_regs_len32(sc) * sizeof(uint32_t))
19459 + sizeof(struct dump_header);
19460 snprintf(drv_infop->bus_info, BXE_BUS_INFO_LENGTH, "%d:%d:%d",
19461 sc->pcie_bus, sc->pcie_device, sc->pcie_func);
19464 case BXE_DEV_SETTING:
19465 dev_p = (bxe_dev_setting_t *)data;
19466 bxe_get_settings(sc, &dev_set);
19467 dev_p->supported = dev_set.supported;
19468 dev_p->advertising = dev_set.advertising;
19469 dev_p->speed = dev_set.speed;
19470 dev_p->duplex = dev_set.duplex;
19471 dev_p->port = dev_set.port;
19472 dev_p->phy_address = dev_set.phy_address;
19473 dev_p->autoneg = dev_set.autoneg;
19479 reg_p = (bxe_get_regs_t *)data;
19480 grc_dump_size = reg_p->reg_buf_len;
19482 if((!sc->grcdump_done) && (!sc->grcdump_started)) {
19485 if((sc->grcdump_done) && (sc->grcdump_started) &&
19486 (sc->grc_dump != NULL)) {
19487 rval = copyout(sc->grc_dump, reg_p->reg_buf, grc_dump_size);
19488 free(sc->grc_dump, M_DEVBUF);
19489 sc->grc_dump = NULL;
19490 sc->grcdump_started = 0;
19491 sc->grcdump_done = 0;
19497 reg_rdw_p = (bxe_reg_rdw_t *)data;
19498 if((reg_rdw_p->reg_cmd == BXE_READ_REG_CMD) &&
19499 (reg_rdw_p->reg_access_type == BXE_REG_ACCESS_DIRECT))
19500 reg_rdw_p->reg_val = REG_RD(sc, reg_rdw_p->reg_id);
19502 if((reg_rdw_p->reg_cmd == BXE_WRITE_REG_CMD) &&
19503 (reg_rdw_p->reg_access_type == BXE_REG_ACCESS_DIRECT))
19504 REG_WR(sc, reg_rdw_p->reg_id, reg_rdw_p->reg_val);
19508 case BXE_RDW_PCICFG:
19509 cfg_rdw_p = (bxe_pcicfg_rdw_t *)data;
19510 if(cfg_rdw_p->cfg_cmd == BXE_READ_PCICFG) {
19512 cfg_rdw_p->cfg_val = pci_read_config(sc->dev, cfg_rdw_p->cfg_id,
19513 cfg_rdw_p->cfg_width);
19515 } else if(cfg_rdw_p->cfg_cmd == BXE_WRITE_PCICFG) {
19516 pci_write_config(sc->dev, cfg_rdw_p->cfg_id, cfg_rdw_p->cfg_val,
19517 cfg_rdw_p->cfg_width);
19519 BLOGW(sc, "BXE_RDW_PCICFG ioctl wrong cmd passed\n");
19524 mac_addr_p = (bxe_perm_mac_addr_t *)data;
19525 snprintf(mac_addr_p->mac_addr_str, sizeof(sc->mac_addr_str), "%s",
19530 rval = bxe_eeprom_rd_wr(sc, (bxe_eeprom_t *)data);