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.90"
34 #include "ecore_init.h"
35 #include "ecore_init_ops.h"
37 #include "57710_int_offsets.h"
38 #include "57711_int_offsets.h"
39 #include "57712_int_offsets.h"
42 * CTLTYPE_U64 and sysctl_handle_64 were added in r217616. Define these
43 * explicitly here for older kernels that don't include this changeset.
46 #define CTLTYPE_U64 CTLTYPE_QUAD
47 #define sysctl_handle_64 sysctl_handle_quad
51 * CSUM_TCP_IPV6 and CSUM_UDP_IPV6 were added in r236170. Define these
52 * here as zero(0) for older kernels that don't include this changeset
53 * thereby masking the functionality.
56 #define CSUM_TCP_IPV6 0
57 #define CSUM_UDP_IPV6 0
61 * pci_find_cap was added in r219865. Re-define this at pci_find_extcap
62 * for older kernels that don't include this changeset.
64 #if __FreeBSD_version < 900035
65 #define pci_find_cap pci_find_extcap
68 #define BXE_DEF_SB_ATT_IDX 0x0001
69 #define BXE_DEF_SB_IDX 0x0002
72 * FLR Support - bxe_pf_flr_clnup() is called during nic_load in the per
73 * function HW initialization.
75 #define FLR_WAIT_USEC 10000 /* 10 msecs */
76 #define FLR_WAIT_INTERVAL 50 /* usecs */
77 #define FLR_POLL_CNT (FLR_WAIT_USEC / FLR_WAIT_INTERVAL) /* 200 */
79 struct pbf_pN_buf_regs {
86 struct pbf_pN_cmd_regs {
93 * PCI Device ID Table used by bxe_probe().
95 #define BXE_DEVDESC_MAX 64
96 static struct bxe_device_type bxe_devs[] = {
100 PCI_ANY_ID, PCI_ANY_ID,
101 "QLogic NetXtreme II BCM57710 10GbE"
106 PCI_ANY_ID, PCI_ANY_ID,
107 "QLogic NetXtreme II BCM57711 10GbE"
112 PCI_ANY_ID, PCI_ANY_ID,
113 "QLogic NetXtreme II BCM57711E 10GbE"
118 PCI_ANY_ID, PCI_ANY_ID,
119 "QLogic NetXtreme II BCM57712 10GbE"
124 PCI_ANY_ID, PCI_ANY_ID,
125 "QLogic NetXtreme II BCM57712 MF 10GbE"
130 PCI_ANY_ID, PCI_ANY_ID,
131 "QLogic NetXtreme II BCM57800 10GbE"
136 PCI_ANY_ID, PCI_ANY_ID,
137 "QLogic NetXtreme II BCM57800 MF 10GbE"
142 PCI_ANY_ID, PCI_ANY_ID,
143 "QLogic NetXtreme II BCM57810 10GbE"
148 PCI_ANY_ID, PCI_ANY_ID,
149 "QLogic NetXtreme II BCM57810 MF 10GbE"
154 PCI_ANY_ID, PCI_ANY_ID,
155 "QLogic NetXtreme II BCM57811 10GbE"
160 PCI_ANY_ID, PCI_ANY_ID,
161 "QLogic NetXtreme II BCM57811 MF 10GbE"
166 PCI_ANY_ID, PCI_ANY_ID,
167 "QLogic NetXtreme II BCM57840 4x10GbE"
172 PCI_ANY_ID, PCI_ANY_ID,
173 "QLogic NetXtreme II BCM57840 MF 10GbE"
180 MALLOC_DECLARE(M_BXE_ILT);
181 MALLOC_DEFINE(M_BXE_ILT, "bxe_ilt", "bxe ILT pointer");
184 * FreeBSD device entry points.
186 static int bxe_probe(device_t);
187 static int bxe_attach(device_t);
188 static int bxe_detach(device_t);
189 static int bxe_shutdown(device_t);
192 * FreeBSD KLD module/device interface event handler method.
194 static device_method_t bxe_methods[] = {
195 /* Device interface (device_if.h) */
196 DEVMETHOD(device_probe, bxe_probe),
197 DEVMETHOD(device_attach, bxe_attach),
198 DEVMETHOD(device_detach, bxe_detach),
199 DEVMETHOD(device_shutdown, bxe_shutdown),
200 /* Bus interface (bus_if.h) */
201 DEVMETHOD(bus_print_child, bus_generic_print_child),
202 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
207 * FreeBSD KLD Module data declaration
209 static driver_t bxe_driver = {
210 "bxe", /* module name */
211 bxe_methods, /* event handler */
212 sizeof(struct bxe_softc) /* extra data */
216 * FreeBSD dev class is needed to manage dev instances and
217 * to associate with a bus type
219 static devclass_t bxe_devclass;
221 MODULE_DEPEND(bxe, pci, 1, 1, 1);
222 MODULE_DEPEND(bxe, ether, 1, 1, 1);
223 DRIVER_MODULE(bxe, pci, bxe_driver, bxe_devclass, 0, 0);
225 /* resources needed for unloading a previously loaded device */
227 #define BXE_PREV_WAIT_NEEDED 1
228 struct mtx bxe_prev_mtx;
229 MTX_SYSINIT(bxe_prev_mtx, &bxe_prev_mtx, "bxe_prev_lock", MTX_DEF);
230 struct bxe_prev_list_node {
231 LIST_ENTRY(bxe_prev_list_node) node;
235 uint8_t aer; /* XXX automatic error recovery */
238 static LIST_HEAD(, bxe_prev_list_node) bxe_prev_list = LIST_HEAD_INITIALIZER(bxe_prev_list);
240 static int load_count[2][3] = { {0} }; /* per-path: 0-common, 1-port0, 2-port1 */
242 /* Tunable device values... */
244 SYSCTL_NODE(_hw, OID_AUTO, bxe, CTLFLAG_RD, 0, "bxe driver parameters");
247 unsigned long bxe_debug = 0;
248 TUNABLE_ULONG("hw.bxe.debug", &bxe_debug);
249 SYSCTL_ULONG(_hw_bxe, OID_AUTO, debug, (CTLFLAG_RDTUN),
250 &bxe_debug, 0, "Debug logging mode");
252 /* Interrupt Mode: 0 (IRQ), 1 (MSI/IRQ), and 2 (MSI-X/MSI/IRQ) */
253 static int bxe_interrupt_mode = INTR_MODE_MSIX;
254 TUNABLE_INT("hw.bxe.interrupt_mode", &bxe_interrupt_mode);
255 SYSCTL_INT(_hw_bxe, OID_AUTO, interrupt_mode, CTLFLAG_RDTUN,
256 &bxe_interrupt_mode, 0, "Interrupt (MSI-X/MSI/INTx) mode");
258 /* Number of Queues: 0 (Auto) or 1 to 16 (fixed queue number) */
259 static int bxe_queue_count = 4;
260 TUNABLE_INT("hw.bxe.queue_count", &bxe_queue_count);
261 SYSCTL_INT(_hw_bxe, OID_AUTO, queue_count, CTLFLAG_RDTUN,
262 &bxe_queue_count, 0, "Multi-Queue queue count");
264 /* max number of buffers per queue (default RX_BD_USABLE) */
265 static int bxe_max_rx_bufs = 0;
266 TUNABLE_INT("hw.bxe.max_rx_bufs", &bxe_max_rx_bufs);
267 SYSCTL_INT(_hw_bxe, OID_AUTO, max_rx_bufs, CTLFLAG_RDTUN,
268 &bxe_max_rx_bufs, 0, "Maximum Number of Rx Buffers Per Queue");
270 /* Host interrupt coalescing RX tick timer (usecs) */
271 static int bxe_hc_rx_ticks = 25;
272 TUNABLE_INT("hw.bxe.hc_rx_ticks", &bxe_hc_rx_ticks);
273 SYSCTL_INT(_hw_bxe, OID_AUTO, hc_rx_ticks, CTLFLAG_RDTUN,
274 &bxe_hc_rx_ticks, 0, "Host Coalescing Rx ticks");
276 /* Host interrupt coalescing TX tick timer (usecs) */
277 static int bxe_hc_tx_ticks = 50;
278 TUNABLE_INT("hw.bxe.hc_tx_ticks", &bxe_hc_tx_ticks);
279 SYSCTL_INT(_hw_bxe, OID_AUTO, hc_tx_ticks, CTLFLAG_RDTUN,
280 &bxe_hc_tx_ticks, 0, "Host Coalescing Tx ticks");
282 /* Maximum number of Rx packets to process at a time */
283 static int bxe_rx_budget = 0xffffffff;
284 TUNABLE_INT("hw.bxe.rx_budget", &bxe_rx_budget);
285 SYSCTL_INT(_hw_bxe, OID_AUTO, rx_budget, CTLFLAG_TUN,
286 &bxe_rx_budget, 0, "Rx processing budget");
288 /* Maximum LRO aggregation size */
289 static int bxe_max_aggregation_size = 0;
290 TUNABLE_INT("hw.bxe.max_aggregation_size", &bxe_max_aggregation_size);
291 SYSCTL_INT(_hw_bxe, OID_AUTO, max_aggregation_size, CTLFLAG_TUN,
292 &bxe_max_aggregation_size, 0, "max aggregation size");
294 /* PCI MRRS: -1 (Auto), 0 (128B), 1 (256B), 2 (512B), 3 (1KB) */
295 static int bxe_mrrs = -1;
296 TUNABLE_INT("hw.bxe.mrrs", &bxe_mrrs);
297 SYSCTL_INT(_hw_bxe, OID_AUTO, mrrs, CTLFLAG_RDTUN,
298 &bxe_mrrs, 0, "PCIe maximum read request size");
300 /* AutoGrEEEn: 0 (hardware default), 1 (force on), 2 (force off) */
301 static int bxe_autogreeen = 0;
302 TUNABLE_INT("hw.bxe.autogreeen", &bxe_autogreeen);
303 SYSCTL_INT(_hw_bxe, OID_AUTO, autogreeen, CTLFLAG_RDTUN,
304 &bxe_autogreeen, 0, "AutoGrEEEn support");
306 /* 4-tuple RSS support for UDP: 0 (disabled), 1 (enabled) */
307 static int bxe_udp_rss = 0;
308 TUNABLE_INT("hw.bxe.udp_rss", &bxe_udp_rss);
309 SYSCTL_INT(_hw_bxe, OID_AUTO, udp_rss, CTLFLAG_RDTUN,
310 &bxe_udp_rss, 0, "UDP RSS support");
313 #define STAT_NAME_LEN 32 /* no stat names below can be longer than this */
315 #define STATS_OFFSET32(stat_name) \
316 (offsetof(struct bxe_eth_stats, stat_name) / 4)
318 #define Q_STATS_OFFSET32(stat_name) \
319 (offsetof(struct bxe_eth_q_stats, stat_name) / 4)
321 static const struct {
325 #define STATS_FLAGS_PORT 1
326 #define STATS_FLAGS_FUNC 2 /* MF only cares about function stats */
327 #define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
328 char string[STAT_NAME_LEN];
329 } bxe_eth_stats_arr[] = {
330 { STATS_OFFSET32(total_bytes_received_hi),
331 8, STATS_FLAGS_BOTH, "rx_bytes" },
332 { STATS_OFFSET32(error_bytes_received_hi),
333 8, STATS_FLAGS_BOTH, "rx_error_bytes" },
334 { STATS_OFFSET32(total_unicast_packets_received_hi),
335 8, STATS_FLAGS_BOTH, "rx_ucast_packets" },
336 { STATS_OFFSET32(total_multicast_packets_received_hi),
337 8, STATS_FLAGS_BOTH, "rx_mcast_packets" },
338 { STATS_OFFSET32(total_broadcast_packets_received_hi),
339 8, STATS_FLAGS_BOTH, "rx_bcast_packets" },
340 { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
341 8, STATS_FLAGS_PORT, "rx_crc_errors" },
342 { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
343 8, STATS_FLAGS_PORT, "rx_align_errors" },
344 { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
345 8, STATS_FLAGS_PORT, "rx_undersize_packets" },
346 { STATS_OFFSET32(etherstatsoverrsizepkts_hi),
347 8, STATS_FLAGS_PORT, "rx_oversize_packets" },
348 { STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
349 8, STATS_FLAGS_PORT, "rx_fragments" },
350 { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
351 8, STATS_FLAGS_PORT, "rx_jabbers" },
352 { STATS_OFFSET32(no_buff_discard_hi),
353 8, STATS_FLAGS_BOTH, "rx_discards" },
354 { STATS_OFFSET32(mac_filter_discard),
355 4, STATS_FLAGS_PORT, "rx_filtered_packets" },
356 { STATS_OFFSET32(mf_tag_discard),
357 4, STATS_FLAGS_PORT, "rx_mf_tag_discard" },
358 { STATS_OFFSET32(pfc_frames_received_hi),
359 8, STATS_FLAGS_PORT, "pfc_frames_received" },
360 { STATS_OFFSET32(pfc_frames_sent_hi),
361 8, STATS_FLAGS_PORT, "pfc_frames_sent" },
362 { STATS_OFFSET32(brb_drop_hi),
363 8, STATS_FLAGS_PORT, "rx_brb_discard" },
364 { STATS_OFFSET32(brb_truncate_hi),
365 8, STATS_FLAGS_PORT, "rx_brb_truncate" },
366 { STATS_OFFSET32(pause_frames_received_hi),
367 8, STATS_FLAGS_PORT, "rx_pause_frames" },
368 { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
369 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" },
370 { STATS_OFFSET32(nig_timer_max),
371 4, STATS_FLAGS_PORT, "rx_constant_pause_events" },
372 { STATS_OFFSET32(total_bytes_transmitted_hi),
373 8, STATS_FLAGS_BOTH, "tx_bytes" },
374 { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
375 8, STATS_FLAGS_PORT, "tx_error_bytes" },
376 { STATS_OFFSET32(total_unicast_packets_transmitted_hi),
377 8, STATS_FLAGS_BOTH, "tx_ucast_packets" },
378 { STATS_OFFSET32(total_multicast_packets_transmitted_hi),
379 8, STATS_FLAGS_BOTH, "tx_mcast_packets" },
380 { STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
381 8, STATS_FLAGS_BOTH, "tx_bcast_packets" },
382 { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
383 8, STATS_FLAGS_PORT, "tx_mac_errors" },
384 { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
385 8, STATS_FLAGS_PORT, "tx_carrier_errors" },
386 { STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
387 8, STATS_FLAGS_PORT, "tx_single_collisions" },
388 { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
389 8, STATS_FLAGS_PORT, "tx_multi_collisions" },
390 { STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
391 8, STATS_FLAGS_PORT, "tx_deferred" },
392 { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
393 8, STATS_FLAGS_PORT, "tx_excess_collisions" },
394 { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
395 8, STATS_FLAGS_PORT, "tx_late_collisions" },
396 { STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
397 8, STATS_FLAGS_PORT, "tx_total_collisions" },
398 { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
399 8, STATS_FLAGS_PORT, "tx_64_byte_packets" },
400 { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
401 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" },
402 { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
403 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" },
404 { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
405 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" },
406 { STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
407 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" },
408 { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
409 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" },
410 { STATS_OFFSET32(etherstatspktsover1522octets_hi),
411 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" },
412 { STATS_OFFSET32(pause_frames_sent_hi),
413 8, STATS_FLAGS_PORT, "tx_pause_frames" },
414 { STATS_OFFSET32(total_tpa_aggregations_hi),
415 8, STATS_FLAGS_FUNC, "tpa_aggregations" },
416 { STATS_OFFSET32(total_tpa_aggregated_frames_hi),
417 8, STATS_FLAGS_FUNC, "tpa_aggregated_frames"},
418 { STATS_OFFSET32(total_tpa_bytes_hi),
419 8, STATS_FLAGS_FUNC, "tpa_bytes"},
420 { STATS_OFFSET32(eee_tx_lpi),
421 4, STATS_FLAGS_PORT, "eee_tx_lpi"},
422 { STATS_OFFSET32(rx_calls),
423 4, STATS_FLAGS_FUNC, "rx_calls"},
424 { STATS_OFFSET32(rx_pkts),
425 4, STATS_FLAGS_FUNC, "rx_pkts"},
426 { STATS_OFFSET32(rx_tpa_pkts),
427 4, STATS_FLAGS_FUNC, "rx_tpa_pkts"},
428 { STATS_OFFSET32(rx_erroneous_jumbo_sge_pkts),
429 4, STATS_FLAGS_FUNC, "rx_erroneous_jumbo_sge_pkts"},
430 { STATS_OFFSET32(rx_bxe_service_rxsgl),
431 4, STATS_FLAGS_FUNC, "rx_bxe_service_rxsgl"},
432 { STATS_OFFSET32(rx_jumbo_sge_pkts),
433 4, STATS_FLAGS_FUNC, "rx_jumbo_sge_pkts"},
434 { STATS_OFFSET32(rx_soft_errors),
435 4, STATS_FLAGS_FUNC, "rx_soft_errors"},
436 { STATS_OFFSET32(rx_hw_csum_errors),
437 4, STATS_FLAGS_FUNC, "rx_hw_csum_errors"},
438 { STATS_OFFSET32(rx_ofld_frames_csum_ip),
439 4, STATS_FLAGS_FUNC, "rx_ofld_frames_csum_ip"},
440 { STATS_OFFSET32(rx_ofld_frames_csum_tcp_udp),
441 4, STATS_FLAGS_FUNC, "rx_ofld_frames_csum_tcp_udp"},
442 { STATS_OFFSET32(rx_budget_reached),
443 4, STATS_FLAGS_FUNC, "rx_budget_reached"},
444 { STATS_OFFSET32(tx_pkts),
445 4, STATS_FLAGS_FUNC, "tx_pkts"},
446 { STATS_OFFSET32(tx_soft_errors),
447 4, STATS_FLAGS_FUNC, "tx_soft_errors"},
448 { STATS_OFFSET32(tx_ofld_frames_csum_ip),
449 4, STATS_FLAGS_FUNC, "tx_ofld_frames_csum_ip"},
450 { STATS_OFFSET32(tx_ofld_frames_csum_tcp),
451 4, STATS_FLAGS_FUNC, "tx_ofld_frames_csum_tcp"},
452 { STATS_OFFSET32(tx_ofld_frames_csum_udp),
453 4, STATS_FLAGS_FUNC, "tx_ofld_frames_csum_udp"},
454 { STATS_OFFSET32(tx_ofld_frames_lso),
455 4, STATS_FLAGS_FUNC, "tx_ofld_frames_lso"},
456 { STATS_OFFSET32(tx_ofld_frames_lso_hdr_splits),
457 4, STATS_FLAGS_FUNC, "tx_ofld_frames_lso_hdr_splits"},
458 { STATS_OFFSET32(tx_encap_failures),
459 4, STATS_FLAGS_FUNC, "tx_encap_failures"},
460 { STATS_OFFSET32(tx_hw_queue_full),
461 4, STATS_FLAGS_FUNC, "tx_hw_queue_full"},
462 { STATS_OFFSET32(tx_hw_max_queue_depth),
463 4, STATS_FLAGS_FUNC, "tx_hw_max_queue_depth"},
464 { STATS_OFFSET32(tx_dma_mapping_failure),
465 4, STATS_FLAGS_FUNC, "tx_dma_mapping_failure"},
466 { STATS_OFFSET32(tx_max_drbr_queue_depth),
467 4, STATS_FLAGS_FUNC, "tx_max_drbr_queue_depth"},
468 { STATS_OFFSET32(tx_window_violation_std),
469 4, STATS_FLAGS_FUNC, "tx_window_violation_std"},
470 { STATS_OFFSET32(tx_window_violation_tso),
471 4, STATS_FLAGS_FUNC, "tx_window_violation_tso"},
472 { STATS_OFFSET32(tx_chain_lost_mbuf),
473 4, STATS_FLAGS_FUNC, "tx_chain_lost_mbuf"},
474 { STATS_OFFSET32(tx_frames_deferred),
475 4, STATS_FLAGS_FUNC, "tx_frames_deferred"},
476 { STATS_OFFSET32(tx_queue_xoff),
477 4, STATS_FLAGS_FUNC, "tx_queue_xoff"},
478 { STATS_OFFSET32(mbuf_defrag_attempts),
479 4, STATS_FLAGS_FUNC, "mbuf_defrag_attempts"},
480 { STATS_OFFSET32(mbuf_defrag_failures),
481 4, STATS_FLAGS_FUNC, "mbuf_defrag_failures"},
482 { STATS_OFFSET32(mbuf_rx_bd_alloc_failed),
483 4, STATS_FLAGS_FUNC, "mbuf_rx_bd_alloc_failed"},
484 { STATS_OFFSET32(mbuf_rx_bd_mapping_failed),
485 4, STATS_FLAGS_FUNC, "mbuf_rx_bd_mapping_failed"},
486 { STATS_OFFSET32(mbuf_rx_tpa_alloc_failed),
487 4, STATS_FLAGS_FUNC, "mbuf_rx_tpa_alloc_failed"},
488 { STATS_OFFSET32(mbuf_rx_tpa_mapping_failed),
489 4, STATS_FLAGS_FUNC, "mbuf_rx_tpa_mapping_failed"},
490 { STATS_OFFSET32(mbuf_rx_sge_alloc_failed),
491 4, STATS_FLAGS_FUNC, "mbuf_rx_sge_alloc_failed"},
492 { STATS_OFFSET32(mbuf_rx_sge_mapping_failed),
493 4, STATS_FLAGS_FUNC, "mbuf_rx_sge_mapping_failed"},
494 { STATS_OFFSET32(mbuf_alloc_tx),
495 4, STATS_FLAGS_FUNC, "mbuf_alloc_tx"},
496 { STATS_OFFSET32(mbuf_alloc_rx),
497 4, STATS_FLAGS_FUNC, "mbuf_alloc_rx"},
498 { STATS_OFFSET32(mbuf_alloc_sge),
499 4, STATS_FLAGS_FUNC, "mbuf_alloc_sge"},
500 { STATS_OFFSET32(mbuf_alloc_tpa),
501 4, STATS_FLAGS_FUNC, "mbuf_alloc_tpa"},
502 { STATS_OFFSET32(tx_queue_full_return),
503 4, STATS_FLAGS_FUNC, "tx_queue_full_return"},
504 { STATS_OFFSET32(bxe_tx_mq_sc_state_failures),
505 4, STATS_FLAGS_FUNC, "bxe_tx_mq_sc_state_failures"},
506 { STATS_OFFSET32(tx_request_link_down_failures),
507 4, STATS_FLAGS_FUNC, "tx_request_link_down_failures"},
508 { STATS_OFFSET32(bd_avail_too_less_failures),
509 4, STATS_FLAGS_FUNC, "bd_avail_too_less_failures"},
510 { STATS_OFFSET32(tx_mq_not_empty),
511 4, STATS_FLAGS_FUNC, "tx_mq_not_empty"},
512 { STATS_OFFSET32(nsegs_path1_errors),
513 4, STATS_FLAGS_FUNC, "nsegs_path1_errors"},
514 { STATS_OFFSET32(nsegs_path2_errors),
515 4, STATS_FLAGS_FUNC, "nsegs_path2_errors"}
520 static const struct {
523 char string[STAT_NAME_LEN];
524 } bxe_eth_q_stats_arr[] = {
525 { Q_STATS_OFFSET32(total_bytes_received_hi),
527 { Q_STATS_OFFSET32(total_unicast_packets_received_hi),
528 8, "rx_ucast_packets" },
529 { Q_STATS_OFFSET32(total_multicast_packets_received_hi),
530 8, "rx_mcast_packets" },
531 { Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
532 8, "rx_bcast_packets" },
533 { Q_STATS_OFFSET32(no_buff_discard_hi),
535 { Q_STATS_OFFSET32(total_bytes_transmitted_hi),
537 { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
538 8, "tx_ucast_packets" },
539 { Q_STATS_OFFSET32(total_multicast_packets_transmitted_hi),
540 8, "tx_mcast_packets" },
541 { Q_STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
542 8, "tx_bcast_packets" },
543 { Q_STATS_OFFSET32(total_tpa_aggregations_hi),
544 8, "tpa_aggregations" },
545 { Q_STATS_OFFSET32(total_tpa_aggregated_frames_hi),
546 8, "tpa_aggregated_frames"},
547 { Q_STATS_OFFSET32(total_tpa_bytes_hi),
549 { Q_STATS_OFFSET32(rx_calls),
551 { Q_STATS_OFFSET32(rx_pkts),
553 { Q_STATS_OFFSET32(rx_tpa_pkts),
555 { Q_STATS_OFFSET32(rx_erroneous_jumbo_sge_pkts),
556 4, "rx_erroneous_jumbo_sge_pkts"},
557 { Q_STATS_OFFSET32(rx_bxe_service_rxsgl),
558 4, "rx_bxe_service_rxsgl"},
559 { Q_STATS_OFFSET32(rx_jumbo_sge_pkts),
560 4, "rx_jumbo_sge_pkts"},
561 { Q_STATS_OFFSET32(rx_soft_errors),
562 4, "rx_soft_errors"},
563 { Q_STATS_OFFSET32(rx_hw_csum_errors),
564 4, "rx_hw_csum_errors"},
565 { Q_STATS_OFFSET32(rx_ofld_frames_csum_ip),
566 4, "rx_ofld_frames_csum_ip"},
567 { Q_STATS_OFFSET32(rx_ofld_frames_csum_tcp_udp),
568 4, "rx_ofld_frames_csum_tcp_udp"},
569 { Q_STATS_OFFSET32(rx_budget_reached),
570 4, "rx_budget_reached"},
571 { Q_STATS_OFFSET32(tx_pkts),
573 { Q_STATS_OFFSET32(tx_soft_errors),
574 4, "tx_soft_errors"},
575 { Q_STATS_OFFSET32(tx_ofld_frames_csum_ip),
576 4, "tx_ofld_frames_csum_ip"},
577 { Q_STATS_OFFSET32(tx_ofld_frames_csum_tcp),
578 4, "tx_ofld_frames_csum_tcp"},
579 { Q_STATS_OFFSET32(tx_ofld_frames_csum_udp),
580 4, "tx_ofld_frames_csum_udp"},
581 { Q_STATS_OFFSET32(tx_ofld_frames_lso),
582 4, "tx_ofld_frames_lso"},
583 { Q_STATS_OFFSET32(tx_ofld_frames_lso_hdr_splits),
584 4, "tx_ofld_frames_lso_hdr_splits"},
585 { Q_STATS_OFFSET32(tx_encap_failures),
586 4, "tx_encap_failures"},
587 { Q_STATS_OFFSET32(tx_hw_queue_full),
588 4, "tx_hw_queue_full"},
589 { Q_STATS_OFFSET32(tx_hw_max_queue_depth),
590 4, "tx_hw_max_queue_depth"},
591 { Q_STATS_OFFSET32(tx_dma_mapping_failure),
592 4, "tx_dma_mapping_failure"},
593 { Q_STATS_OFFSET32(tx_max_drbr_queue_depth),
594 4, "tx_max_drbr_queue_depth"},
595 { Q_STATS_OFFSET32(tx_window_violation_std),
596 4, "tx_window_violation_std"},
597 { Q_STATS_OFFSET32(tx_window_violation_tso),
598 4, "tx_window_violation_tso"},
599 { Q_STATS_OFFSET32(tx_chain_lost_mbuf),
600 4, "tx_chain_lost_mbuf"},
601 { Q_STATS_OFFSET32(tx_frames_deferred),
602 4, "tx_frames_deferred"},
603 { Q_STATS_OFFSET32(tx_queue_xoff),
605 { Q_STATS_OFFSET32(mbuf_defrag_attempts),
606 4, "mbuf_defrag_attempts"},
607 { Q_STATS_OFFSET32(mbuf_defrag_failures),
608 4, "mbuf_defrag_failures"},
609 { Q_STATS_OFFSET32(mbuf_rx_bd_alloc_failed),
610 4, "mbuf_rx_bd_alloc_failed"},
611 { Q_STATS_OFFSET32(mbuf_rx_bd_mapping_failed),
612 4, "mbuf_rx_bd_mapping_failed"},
613 { Q_STATS_OFFSET32(mbuf_rx_tpa_alloc_failed),
614 4, "mbuf_rx_tpa_alloc_failed"},
615 { Q_STATS_OFFSET32(mbuf_rx_tpa_mapping_failed),
616 4, "mbuf_rx_tpa_mapping_failed"},
617 { Q_STATS_OFFSET32(mbuf_rx_sge_alloc_failed),
618 4, "mbuf_rx_sge_alloc_failed"},
619 { Q_STATS_OFFSET32(mbuf_rx_sge_mapping_failed),
620 4, "mbuf_rx_sge_mapping_failed"},
621 { Q_STATS_OFFSET32(mbuf_alloc_tx),
623 { Q_STATS_OFFSET32(mbuf_alloc_rx),
625 { Q_STATS_OFFSET32(mbuf_alloc_sge),
626 4, "mbuf_alloc_sge"},
627 { Q_STATS_OFFSET32(mbuf_alloc_tpa),
628 4, "mbuf_alloc_tpa"},
629 { Q_STATS_OFFSET32(tx_queue_full_return),
630 4, "tx_queue_full_return"},
631 { Q_STATS_OFFSET32(bxe_tx_mq_sc_state_failures),
632 4, "bxe_tx_mq_sc_state_failures"},
633 { Q_STATS_OFFSET32(tx_request_link_down_failures),
634 4, "tx_request_link_down_failures"},
635 { Q_STATS_OFFSET32(bd_avail_too_less_failures),
636 4, "bd_avail_too_less_failures"},
637 { Q_STATS_OFFSET32(tx_mq_not_empty),
638 4, "tx_mq_not_empty"},
639 { Q_STATS_OFFSET32(nsegs_path1_errors),
640 4, "nsegs_path1_errors"},
641 { Q_STATS_OFFSET32(nsegs_path2_errors),
642 4, "nsegs_path2_errors"}
645 #define BXE_NUM_ETH_STATS ARRAY_SIZE(bxe_eth_stats_arr)
646 #define BXE_NUM_ETH_Q_STATS ARRAY_SIZE(bxe_eth_q_stats_arr)
649 static void bxe_cmng_fns_init(struct bxe_softc *sc,
652 static int bxe_get_cmng_fns_mode(struct bxe_softc *sc);
653 static void storm_memset_cmng(struct bxe_softc *sc,
654 struct cmng_init *cmng,
656 static void bxe_set_reset_global(struct bxe_softc *sc);
657 static void bxe_set_reset_in_progress(struct bxe_softc *sc);
658 static uint8_t bxe_reset_is_done(struct bxe_softc *sc,
660 static uint8_t bxe_clear_pf_load(struct bxe_softc *sc);
661 static uint8_t bxe_chk_parity_attn(struct bxe_softc *sc,
664 static void bxe_int_disable(struct bxe_softc *sc);
665 static int bxe_release_leader_lock(struct bxe_softc *sc);
666 static void bxe_pf_disable(struct bxe_softc *sc);
667 static void bxe_free_fp_buffers(struct bxe_softc *sc);
668 static inline void bxe_update_rx_prod(struct bxe_softc *sc,
669 struct bxe_fastpath *fp,
672 uint16_t rx_sge_prod);
673 static void bxe_link_report_locked(struct bxe_softc *sc);
674 static void bxe_link_report(struct bxe_softc *sc);
675 static void bxe_link_status_update(struct bxe_softc *sc);
676 static void bxe_periodic_callout_func(void *xsc);
677 static void bxe_periodic_start(struct bxe_softc *sc);
678 static void bxe_periodic_stop(struct bxe_softc *sc);
679 static int bxe_alloc_rx_bd_mbuf(struct bxe_fastpath *fp,
682 static int bxe_alloc_rx_tpa_mbuf(struct bxe_fastpath *fp,
684 static int bxe_alloc_rx_sge_mbuf(struct bxe_fastpath *fp,
686 static uint8_t bxe_txeof(struct bxe_softc *sc,
687 struct bxe_fastpath *fp);
688 static void bxe_task_fp(struct bxe_fastpath *fp);
689 static __noinline void bxe_dump_mbuf(struct bxe_softc *sc,
692 static int bxe_alloc_mem(struct bxe_softc *sc);
693 static void bxe_free_mem(struct bxe_softc *sc);
694 static int bxe_alloc_fw_stats_mem(struct bxe_softc *sc);
695 static void bxe_free_fw_stats_mem(struct bxe_softc *sc);
696 static int bxe_interrupt_attach(struct bxe_softc *sc);
697 static void bxe_interrupt_detach(struct bxe_softc *sc);
698 static void bxe_set_rx_mode(struct bxe_softc *sc);
699 static int bxe_init_locked(struct bxe_softc *sc);
700 static int bxe_stop_locked(struct bxe_softc *sc);
701 static __noinline int bxe_nic_load(struct bxe_softc *sc,
703 static __noinline int bxe_nic_unload(struct bxe_softc *sc,
704 uint32_t unload_mode,
707 static void bxe_handle_sp_tq(void *context, int pending);
708 static void bxe_handle_fp_tq(void *context, int pending);
710 static int bxe_add_cdev(struct bxe_softc *sc);
711 static void bxe_del_cdev(struct bxe_softc *sc);
712 int bxe_grc_dump(struct bxe_softc *sc);
713 static int bxe_alloc_buf_rings(struct bxe_softc *sc);
714 static void bxe_free_buf_rings(struct bxe_softc *sc);
716 /* calculate crc32 on a buffer (NOTE: crc32_length MUST be aligned to 8) */
718 calc_crc32(uint8_t *crc32_packet,
719 uint32_t crc32_length,
728 uint8_t current_byte = 0;
729 uint32_t crc32_result = crc32_seed;
730 const uint32_t CRC32_POLY = 0x1edc6f41;
732 if ((crc32_packet == NULL) ||
733 (crc32_length == 0) ||
734 ((crc32_length % 8) != 0))
736 return (crc32_result);
739 for (byte = 0; byte < crc32_length; byte = byte + 1)
741 current_byte = crc32_packet[byte];
742 for (bit = 0; bit < 8; bit = bit + 1)
744 /* msb = crc32_result[31]; */
745 msb = (uint8_t)(crc32_result >> 31);
747 crc32_result = crc32_result << 1;
749 /* it (msb != current_byte[bit]) */
750 if (msb != (0x1 & (current_byte >> bit)))
752 crc32_result = crc32_result ^ CRC32_POLY;
753 /* crc32_result[0] = 1 */
760 * 1. "mirror" every bit
761 * 2. swap the 4 bytes
762 * 3. complement each bit
767 shft = sizeof(crc32_result) * 8 - 1;
769 for (crc32_result >>= 1; crc32_result; crc32_result >>= 1)
772 temp |= crc32_result & 1;
776 /* temp[31-bit] = crc32_result[bit] */
780 /* crc32_result = {temp[7:0], temp[15:8], temp[23:16], temp[31:24]} */
782 uint32_t t0, t1, t2, t3;
783 t0 = (0x000000ff & (temp >> 24));
784 t1 = (0x0000ff00 & (temp >> 8));
785 t2 = (0x00ff0000 & (temp << 8));
786 t3 = (0xff000000 & (temp << 24));
787 crc32_result = t0 | t1 | t2 | t3;
793 crc32_result = ~crc32_result;
796 return (crc32_result);
801 volatile unsigned long *addr)
803 return ((atomic_load_acq_long(addr) & (1 << nr)) != 0);
807 bxe_set_bit(unsigned int nr,
808 volatile unsigned long *addr)
810 atomic_set_acq_long(addr, (1 << nr));
814 bxe_clear_bit(int nr,
815 volatile unsigned long *addr)
817 atomic_clear_acq_long(addr, (1 << nr));
821 bxe_test_and_set_bit(int nr,
822 volatile unsigned long *addr)
828 } while (atomic_cmpset_acq_long(addr, x, x | nr) == 0);
829 // if (x & nr) bit_was_set; else bit_was_not_set;
834 bxe_test_and_clear_bit(int nr,
835 volatile unsigned long *addr)
841 } while (atomic_cmpset_acq_long(addr, x, x & ~nr) == 0);
842 // if (x & nr) bit_was_set; else bit_was_not_set;
847 bxe_cmpxchg(volatile int *addr,
854 } while (atomic_cmpset_acq_int(addr, old, new) == 0);
859 * Get DMA memory from the OS.
861 * Validates that the OS has provided DMA buffers in response to a
862 * bus_dmamap_load call and saves the physical address of those buffers.
863 * When the callback is used the OS will return 0 for the mapping function
864 * (bus_dmamap_load) so we use the value of map_arg->maxsegs to pass any
865 * failures back to the caller.
871 bxe_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
873 struct bxe_dma *dma = arg;
878 BLOGE(dma->sc, "Failed DMA alloc '%s' (%d)!\n", dma->msg, error);
880 dma->paddr = segs->ds_addr;
886 * Allocate a block of memory and map it for DMA. No partial completions
887 * allowed and release any resources acquired if we can't acquire all
891 * 0 = Success, !0 = Failure
894 bxe_dma_alloc(struct bxe_softc *sc,
902 BLOGE(sc, "dma block '%s' already has size %lu\n", msg,
903 (unsigned long)dma->size);
907 memset(dma, 0, sizeof(*dma)); /* sanity */
910 snprintf(dma->msg, sizeof(dma->msg), "%s", msg);
912 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */
913 BCM_PAGE_SIZE, /* alignment */
914 0, /* boundary limit */
915 BUS_SPACE_MAXADDR, /* restricted low */
916 BUS_SPACE_MAXADDR, /* restricted hi */
917 NULL, /* addr filter() */
918 NULL, /* addr filter() arg */
919 size, /* max map size */
920 1, /* num discontinuous */
921 size, /* max seg size */
922 BUS_DMA_ALLOCNOW, /* flags */
924 NULL, /* lock() arg */
925 &dma->tag); /* returned dma tag */
927 BLOGE(sc, "Failed to create dma tag for '%s' (%d)\n", msg, rc);
928 memset(dma, 0, sizeof(*dma));
932 rc = bus_dmamem_alloc(dma->tag,
933 (void **)&dma->vaddr,
934 (BUS_DMA_NOWAIT | BUS_DMA_ZERO),
937 BLOGE(sc, "Failed to alloc dma mem for '%s' (%d)\n", msg, rc);
938 bus_dma_tag_destroy(dma->tag);
939 memset(dma, 0, sizeof(*dma));
943 rc = bus_dmamap_load(dma->tag,
947 bxe_dma_map_addr, /* BLOGD in here */
951 BLOGE(sc, "Failed to load dma map for '%s' (%d)\n", msg, rc);
952 bus_dmamem_free(dma->tag, dma->vaddr, dma->map);
953 bus_dma_tag_destroy(dma->tag);
954 memset(dma, 0, sizeof(*dma));
962 bxe_dma_free(struct bxe_softc *sc,
966 DBASSERT(sc, (dma->tag != NULL), ("dma tag is NULL"));
968 bus_dmamap_sync(dma->tag, dma->map,
969 (BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE));
970 bus_dmamap_unload(dma->tag, dma->map);
971 bus_dmamem_free(dma->tag, dma->vaddr, dma->map);
972 bus_dma_tag_destroy(dma->tag);
975 memset(dma, 0, sizeof(*dma));
979 * These indirect read and write routines are only during init.
980 * The locking is handled by the MCP.
984 bxe_reg_wr_ind(struct bxe_softc *sc,
988 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, addr, 4);
989 pci_write_config(sc->dev, PCICFG_GRC_DATA, val, 4);
990 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, 0, 4);
994 bxe_reg_rd_ind(struct bxe_softc *sc,
999 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, addr, 4);
1000 val = pci_read_config(sc->dev, PCICFG_GRC_DATA, 4);
1001 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, 0, 4);
1007 bxe_acquire_hw_lock(struct bxe_softc *sc,
1010 uint32_t lock_status;
1011 uint32_t resource_bit = (1 << resource);
1012 int func = SC_FUNC(sc);
1013 uint32_t hw_lock_control_reg;
1016 /* validate the resource is within range */
1017 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1018 BLOGE(sc, "(resource 0x%x > HW_LOCK_MAX_RESOURCE_VALUE)"
1019 " resource_bit 0x%x\n", resource, resource_bit);
1024 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + (func * 8));
1026 hw_lock_control_reg =
1027 (MISC_REG_DRIVER_CONTROL_7 + ((func - 6) * 8));
1030 /* validate the resource is not already taken */
1031 lock_status = REG_RD(sc, hw_lock_control_reg);
1032 if (lock_status & resource_bit) {
1033 BLOGE(sc, "resource (0x%x) in use (status 0x%x bit 0x%x)\n",
1034 resource, lock_status, resource_bit);
1038 /* try every 5ms for 5 seconds */
1039 for (cnt = 0; cnt < 1000; cnt++) {
1040 REG_WR(sc, (hw_lock_control_reg + 4), resource_bit);
1041 lock_status = REG_RD(sc, hw_lock_control_reg);
1042 if (lock_status & resource_bit) {
1048 BLOGE(sc, "Resource 0x%x resource_bit 0x%x lock timeout!\n",
1049 resource, resource_bit);
1054 bxe_release_hw_lock(struct bxe_softc *sc,
1057 uint32_t lock_status;
1058 uint32_t resource_bit = (1 << resource);
1059 int func = SC_FUNC(sc);
1060 uint32_t hw_lock_control_reg;
1062 /* validate the resource is within range */
1063 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1064 BLOGE(sc, "(resource 0x%x > HW_LOCK_MAX_RESOURCE_VALUE)"
1065 " resource_bit 0x%x\n", resource, resource_bit);
1070 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + (func * 8));
1072 hw_lock_control_reg =
1073 (MISC_REG_DRIVER_CONTROL_7 + ((func - 6) * 8));
1076 /* validate the resource is currently taken */
1077 lock_status = REG_RD(sc, hw_lock_control_reg);
1078 if (!(lock_status & resource_bit)) {
1079 BLOGE(sc, "resource (0x%x) not in use (status 0x%x bit 0x%x)\n",
1080 resource, lock_status, resource_bit);
1084 REG_WR(sc, hw_lock_control_reg, resource_bit);
1087 static void bxe_acquire_phy_lock(struct bxe_softc *sc)
1090 bxe_acquire_hw_lock(sc,HW_LOCK_RESOURCE_MDIO);
1093 static void bxe_release_phy_lock(struct bxe_softc *sc)
1095 bxe_release_hw_lock(sc,HW_LOCK_RESOURCE_MDIO);
1099 * Per pf misc lock must be acquired before the per port mcp lock. Otherwise,
1100 * had we done things the other way around, if two pfs from the same port
1101 * would attempt to access nvram at the same time, we could run into a
1103 * pf A takes the port lock.
1104 * pf B succeeds in taking the same lock since they are from the same port.
1105 * pf A takes the per pf misc lock. Performs eeprom access.
1106 * pf A finishes. Unlocks the per pf misc lock.
1107 * Pf B takes the lock and proceeds to perform it's own access.
1108 * pf A unlocks the per port lock, while pf B is still working (!).
1109 * mcp takes the per port lock and corrupts pf B's access (and/or has it's own
1110 * access corrupted by pf B).*
1113 bxe_acquire_nvram_lock(struct bxe_softc *sc)
1115 int port = SC_PORT(sc);
1119 /* acquire HW lock: protect against other PFs in PF Direct Assignment */
1120 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_NVRAM);
1122 /* adjust timeout for emulation/FPGA */
1123 count = NVRAM_TIMEOUT_COUNT;
1124 if (CHIP_REV_IS_SLOW(sc)) {
1128 /* request access to nvram interface */
1129 REG_WR(sc, MCP_REG_MCPR_NVM_SW_ARB,
1130 (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port));
1132 for (i = 0; i < count*10; i++) {
1133 val = REG_RD(sc, MCP_REG_MCPR_NVM_SW_ARB);
1134 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
1141 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
1142 BLOGE(sc, "Cannot get access to nvram interface "
1143 "port %d val 0x%x (MCPR_NVM_SW_ARB_ARB_ARB1 << port)\n",
1152 bxe_release_nvram_lock(struct bxe_softc *sc)
1154 int port = SC_PORT(sc);
1158 /* adjust timeout for emulation/FPGA */
1159 count = NVRAM_TIMEOUT_COUNT;
1160 if (CHIP_REV_IS_SLOW(sc)) {
1164 /* relinquish nvram interface */
1165 REG_WR(sc, MCP_REG_MCPR_NVM_SW_ARB,
1166 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port));
1168 for (i = 0; i < count*10; i++) {
1169 val = REG_RD(sc, MCP_REG_MCPR_NVM_SW_ARB);
1170 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
1177 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
1178 BLOGE(sc, "Cannot free access to nvram interface "
1179 "port %d val 0x%x (MCPR_NVM_SW_ARB_ARB_ARB1 << port)\n",
1184 /* release HW lock: protect against other PFs in PF Direct Assignment */
1185 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_NVRAM);
1191 bxe_enable_nvram_access(struct bxe_softc *sc)
1195 val = REG_RD(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
1197 /* enable both bits, even on read */
1198 REG_WR(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
1199 (val | MCPR_NVM_ACCESS_ENABLE_EN | MCPR_NVM_ACCESS_ENABLE_WR_EN));
1203 bxe_disable_nvram_access(struct bxe_softc *sc)
1207 val = REG_RD(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
1209 /* disable both bits, even after read */
1210 REG_WR(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
1211 (val & ~(MCPR_NVM_ACCESS_ENABLE_EN |
1212 MCPR_NVM_ACCESS_ENABLE_WR_EN)));
1216 bxe_nvram_read_dword(struct bxe_softc *sc,
1224 /* build the command word */
1225 cmd_flags |= MCPR_NVM_COMMAND_DOIT;
1227 /* need to clear DONE bit separately */
1228 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
1230 /* address of the NVRAM to read from */
1231 REG_WR(sc, MCP_REG_MCPR_NVM_ADDR,
1232 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
1234 /* issue a read command */
1235 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
1237 /* adjust timeout for emulation/FPGA */
1238 count = NVRAM_TIMEOUT_COUNT;
1239 if (CHIP_REV_IS_SLOW(sc)) {
1243 /* wait for completion */
1246 for (i = 0; i < count; i++) {
1248 val = REG_RD(sc, MCP_REG_MCPR_NVM_COMMAND);
1250 if (val & MCPR_NVM_COMMAND_DONE) {
1251 val = REG_RD(sc, MCP_REG_MCPR_NVM_READ);
1252 /* we read nvram data in cpu order
1253 * but ethtool sees it as an array of bytes
1254 * converting to big-endian will do the work
1256 *ret_val = htobe32(val);
1263 BLOGE(sc, "nvram read timeout expired "
1264 "(offset 0x%x cmd_flags 0x%x val 0x%x)\n",
1265 offset, cmd_flags, val);
1272 bxe_nvram_read(struct bxe_softc *sc,
1281 if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
1282 BLOGE(sc, "Invalid parameter, offset 0x%x buf_size 0x%x\n",
1287 if ((offset + buf_size) > sc->devinfo.flash_size) {
1288 BLOGE(sc, "Invalid parameter, "
1289 "offset 0x%x + buf_size 0x%x > flash_size 0x%x\n",
1290 offset, buf_size, sc->devinfo.flash_size);
1294 /* request access to nvram interface */
1295 rc = bxe_acquire_nvram_lock(sc);
1300 /* enable access to nvram interface */
1301 bxe_enable_nvram_access(sc);
1303 /* read the first word(s) */
1304 cmd_flags = MCPR_NVM_COMMAND_FIRST;
1305 while ((buf_size > sizeof(uint32_t)) && (rc == 0)) {
1306 rc = bxe_nvram_read_dword(sc, offset, &val, cmd_flags);
1307 memcpy(ret_buf, &val, 4);
1309 /* advance to the next dword */
1310 offset += sizeof(uint32_t);
1311 ret_buf += sizeof(uint32_t);
1312 buf_size -= sizeof(uint32_t);
1317 cmd_flags |= MCPR_NVM_COMMAND_LAST;
1318 rc = bxe_nvram_read_dword(sc, offset, &val, cmd_flags);
1319 memcpy(ret_buf, &val, 4);
1322 /* disable access to nvram interface */
1323 bxe_disable_nvram_access(sc);
1324 bxe_release_nvram_lock(sc);
1330 bxe_nvram_write_dword(struct bxe_softc *sc,
1337 /* build the command word */
1338 cmd_flags |= (MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR);
1340 /* need to clear DONE bit separately */
1341 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
1343 /* write the data */
1344 REG_WR(sc, MCP_REG_MCPR_NVM_WRITE, val);
1346 /* address of the NVRAM to write to */
1347 REG_WR(sc, MCP_REG_MCPR_NVM_ADDR,
1348 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
1350 /* issue the write command */
1351 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
1353 /* adjust timeout for emulation/FPGA */
1354 count = NVRAM_TIMEOUT_COUNT;
1355 if (CHIP_REV_IS_SLOW(sc)) {
1359 /* wait for completion */
1361 for (i = 0; i < count; i++) {
1363 val = REG_RD(sc, MCP_REG_MCPR_NVM_COMMAND);
1364 if (val & MCPR_NVM_COMMAND_DONE) {
1371 BLOGE(sc, "nvram write timeout expired "
1372 "(offset 0x%x cmd_flags 0x%x val 0x%x)\n",
1373 offset, cmd_flags, val);
1379 #define BYTE_OFFSET(offset) (8 * (offset & 0x03))
1382 bxe_nvram_write1(struct bxe_softc *sc,
1388 uint32_t align_offset;
1392 if ((offset + buf_size) > sc->devinfo.flash_size) {
1393 BLOGE(sc, "Invalid parameter, "
1394 "offset 0x%x + buf_size 0x%x > flash_size 0x%x\n",
1395 offset, buf_size, sc->devinfo.flash_size);
1399 /* request access to nvram interface */
1400 rc = bxe_acquire_nvram_lock(sc);
1405 /* enable access to nvram interface */
1406 bxe_enable_nvram_access(sc);
1408 cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST);
1409 align_offset = (offset & ~0x03);
1410 rc = bxe_nvram_read_dword(sc, align_offset, &val, cmd_flags);
1413 val &= ~(0xff << BYTE_OFFSET(offset));
1414 val |= (*data_buf << BYTE_OFFSET(offset));
1416 /* nvram data is returned as an array of bytes
1417 * convert it back to cpu order
1421 rc = bxe_nvram_write_dword(sc, align_offset, val, cmd_flags);
1424 /* disable access to nvram interface */
1425 bxe_disable_nvram_access(sc);
1426 bxe_release_nvram_lock(sc);
1432 bxe_nvram_write(struct bxe_softc *sc,
1439 uint32_t written_so_far;
1442 if (buf_size == 1) {
1443 return (bxe_nvram_write1(sc, offset, data_buf, buf_size));
1446 if ((offset & 0x03) || (buf_size & 0x03) /* || (buf_size == 0) */) {
1447 BLOGE(sc, "Invalid parameter, offset 0x%x buf_size 0x%x\n",
1452 if (buf_size == 0) {
1453 return (0); /* nothing to do */
1456 if ((offset + buf_size) > sc->devinfo.flash_size) {
1457 BLOGE(sc, "Invalid parameter, "
1458 "offset 0x%x + buf_size 0x%x > flash_size 0x%x\n",
1459 offset, buf_size, sc->devinfo.flash_size);
1463 /* request access to nvram interface */
1464 rc = bxe_acquire_nvram_lock(sc);
1469 /* enable access to nvram interface */
1470 bxe_enable_nvram_access(sc);
1473 cmd_flags = MCPR_NVM_COMMAND_FIRST;
1474 while ((written_so_far < buf_size) && (rc == 0)) {
1475 if (written_so_far == (buf_size - sizeof(uint32_t))) {
1476 cmd_flags |= MCPR_NVM_COMMAND_LAST;
1477 } else if (((offset + 4) % NVRAM_PAGE_SIZE) == 0) {
1478 cmd_flags |= MCPR_NVM_COMMAND_LAST;
1479 } else if ((offset % NVRAM_PAGE_SIZE) == 0) {
1480 cmd_flags |= MCPR_NVM_COMMAND_FIRST;
1483 memcpy(&val, data_buf, 4);
1485 rc = bxe_nvram_write_dword(sc, offset, val, cmd_flags);
1487 /* advance to the next dword */
1488 offset += sizeof(uint32_t);
1489 data_buf += sizeof(uint32_t);
1490 written_so_far += sizeof(uint32_t);
1494 /* disable access to nvram interface */
1495 bxe_disable_nvram_access(sc);
1496 bxe_release_nvram_lock(sc);
1501 /* copy command into DMAE command memory and set DMAE command Go */
1503 bxe_post_dmae(struct bxe_softc *sc,
1504 struct dmae_cmd *dmae,
1507 uint32_t cmd_offset;
1510 cmd_offset = (DMAE_REG_CMD_MEM + (sizeof(struct dmae_cmd) * idx));
1511 for (i = 0; i < ((sizeof(struct dmae_cmd) / 4)); i++) {
1512 REG_WR(sc, (cmd_offset + (i * 4)), *(((uint32_t *)dmae) + i));
1515 REG_WR(sc, dmae_reg_go_c[idx], 1);
1519 bxe_dmae_opcode_add_comp(uint32_t opcode,
1522 return (opcode | ((comp_type << DMAE_CMD_C_DST_SHIFT) |
1523 DMAE_CMD_C_TYPE_ENABLE));
1527 bxe_dmae_opcode_clr_src_reset(uint32_t opcode)
1529 return (opcode & ~DMAE_CMD_SRC_RESET);
1533 bxe_dmae_opcode(struct bxe_softc *sc,
1539 uint32_t opcode = 0;
1541 opcode |= ((src_type << DMAE_CMD_SRC_SHIFT) |
1542 (dst_type << DMAE_CMD_DST_SHIFT));
1544 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
1546 opcode |= (SC_PORT(sc) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
1548 opcode |= ((SC_VN(sc) << DMAE_CMD_E1HVN_SHIFT) |
1549 (SC_VN(sc) << DMAE_CMD_DST_VN_SHIFT));
1551 opcode |= (DMAE_COM_SET_ERR << DMAE_CMD_ERR_POLICY_SHIFT);
1554 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
1556 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
1560 opcode = bxe_dmae_opcode_add_comp(opcode, comp_type);
1567 bxe_prep_dmae_with_comp(struct bxe_softc *sc,
1568 struct dmae_cmd *dmae,
1572 memset(dmae, 0, sizeof(struct dmae_cmd));
1574 /* set the opcode */
1575 dmae->opcode = bxe_dmae_opcode(sc, src_type, dst_type,
1576 TRUE, DMAE_COMP_PCI);
1578 /* fill in the completion parameters */
1579 dmae->comp_addr_lo = U64_LO(BXE_SP_MAPPING(sc, wb_comp));
1580 dmae->comp_addr_hi = U64_HI(BXE_SP_MAPPING(sc, wb_comp));
1581 dmae->comp_val = DMAE_COMP_VAL;
1584 /* issue a DMAE command over the init channel and wait for completion */
1586 bxe_issue_dmae_with_comp(struct bxe_softc *sc,
1587 struct dmae_cmd *dmae)
1589 uint32_t *wb_comp = BXE_SP(sc, wb_comp);
1590 int timeout = CHIP_REV_IS_SLOW(sc) ? 400000 : 4000;
1594 /* reset completion */
1597 /* post the command on the channel used for initializations */
1598 bxe_post_dmae(sc, dmae, INIT_DMAE_C(sc));
1600 /* wait for completion */
1603 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
1605 (sc->recovery_state != BXE_RECOVERY_DONE &&
1606 sc->recovery_state != BXE_RECOVERY_NIC_LOADING)) {
1607 BLOGE(sc, "DMAE timeout! *wb_comp 0x%x recovery_state 0x%x\n",
1608 *wb_comp, sc->recovery_state);
1609 BXE_DMAE_UNLOCK(sc);
1610 return (DMAE_TIMEOUT);
1617 if (*wb_comp & DMAE_PCI_ERR_FLAG) {
1618 BLOGE(sc, "DMAE PCI error! *wb_comp 0x%x recovery_state 0x%x\n",
1619 *wb_comp, sc->recovery_state);
1620 BXE_DMAE_UNLOCK(sc);
1621 return (DMAE_PCI_ERROR);
1624 BXE_DMAE_UNLOCK(sc);
1629 bxe_read_dmae(struct bxe_softc *sc,
1633 struct dmae_cmd dmae;
1637 DBASSERT(sc, (len32 <= 4), ("DMAE read length is %d", len32));
1639 if (!sc->dmae_ready) {
1640 data = BXE_SP(sc, wb_data[0]);
1642 for (i = 0; i < len32; i++) {
1643 data[i] = (CHIP_IS_E1(sc)) ?
1644 bxe_reg_rd_ind(sc, (src_addr + (i * 4))) :
1645 REG_RD(sc, (src_addr + (i * 4)));
1651 /* set opcode and fixed command fields */
1652 bxe_prep_dmae_with_comp(sc, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
1654 /* fill in addresses and len */
1655 dmae.src_addr_lo = (src_addr >> 2); /* GRC addr has dword resolution */
1656 dmae.src_addr_hi = 0;
1657 dmae.dst_addr_lo = U64_LO(BXE_SP_MAPPING(sc, wb_data));
1658 dmae.dst_addr_hi = U64_HI(BXE_SP_MAPPING(sc, wb_data));
1661 /* issue the command and wait for completion */
1662 if ((rc = bxe_issue_dmae_with_comp(sc, &dmae)) != 0) {
1663 bxe_panic(sc, ("DMAE failed (%d)\n", rc));
1668 bxe_write_dmae(struct bxe_softc *sc,
1669 bus_addr_t dma_addr,
1673 struct dmae_cmd dmae;
1676 if (!sc->dmae_ready) {
1677 DBASSERT(sc, (len32 <= 4), ("DMAE not ready and length is %d", len32));
1679 if (CHIP_IS_E1(sc)) {
1680 ecore_init_ind_wr(sc, dst_addr, BXE_SP(sc, wb_data[0]), len32);
1682 ecore_init_str_wr(sc, dst_addr, BXE_SP(sc, wb_data[0]), len32);
1688 /* set opcode and fixed command fields */
1689 bxe_prep_dmae_with_comp(sc, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
1691 /* fill in addresses and len */
1692 dmae.src_addr_lo = U64_LO(dma_addr);
1693 dmae.src_addr_hi = U64_HI(dma_addr);
1694 dmae.dst_addr_lo = (dst_addr >> 2); /* GRC addr has dword resolution */
1695 dmae.dst_addr_hi = 0;
1698 /* issue the command and wait for completion */
1699 if ((rc = bxe_issue_dmae_with_comp(sc, &dmae)) != 0) {
1700 bxe_panic(sc, ("DMAE failed (%d)\n", rc));
1705 bxe_write_dmae_phys_len(struct bxe_softc *sc,
1706 bus_addr_t phys_addr,
1710 int dmae_wr_max = DMAE_LEN32_WR_MAX(sc);
1713 while (len > dmae_wr_max) {
1715 (phys_addr + offset), /* src DMA address */
1716 (addr + offset), /* dst GRC address */
1718 offset += (dmae_wr_max * 4);
1723 (phys_addr + offset), /* src DMA address */
1724 (addr + offset), /* dst GRC address */
1729 bxe_set_ctx_validation(struct bxe_softc *sc,
1730 struct eth_context *cxt,
1733 /* ustorm cxt validation */
1734 cxt->ustorm_ag_context.cdu_usage =
1735 CDU_RSRVD_VALUE_TYPE_A(HW_CID(sc, cid),
1736 CDU_REGION_NUMBER_UCM_AG, ETH_CONNECTION_TYPE);
1737 /* xcontext validation */
1738 cxt->xstorm_ag_context.cdu_reserved =
1739 CDU_RSRVD_VALUE_TYPE_A(HW_CID(sc, cid),
1740 CDU_REGION_NUMBER_XCM_AG, ETH_CONNECTION_TYPE);
1744 bxe_storm_memset_hc_timeout(struct bxe_softc *sc,
1751 (BAR_CSTRORM_INTMEM +
1752 CSTORM_STATUS_BLOCK_DATA_TIMEOUT_OFFSET(fw_sb_id, sb_index));
1754 REG_WR8(sc, addr, ticks);
1757 "port %d fw_sb_id %d sb_index %d ticks %d\n",
1758 port, fw_sb_id, sb_index, ticks);
1762 bxe_storm_memset_hc_disable(struct bxe_softc *sc,
1768 uint32_t enable_flag =
1769 (disable) ? 0 : (1 << HC_INDEX_DATA_HC_ENABLED_SHIFT);
1771 (BAR_CSTRORM_INTMEM +
1772 CSTORM_STATUS_BLOCK_DATA_FLAGS_OFFSET(fw_sb_id, sb_index));
1776 flags = REG_RD8(sc, addr);
1777 flags &= ~HC_INDEX_DATA_HC_ENABLED;
1778 flags |= enable_flag;
1779 REG_WR8(sc, addr, flags);
1782 "port %d fw_sb_id %d sb_index %d disable %d\n",
1783 port, fw_sb_id, sb_index, disable);
1787 bxe_update_coalesce_sb_index(struct bxe_softc *sc,
1793 int port = SC_PORT(sc);
1794 uint8_t ticks = (usec / 4); /* XXX ??? */
1796 bxe_storm_memset_hc_timeout(sc, port, fw_sb_id, sb_index, ticks);
1798 disable = (disable) ? 1 : ((usec) ? 0 : 1);
1799 bxe_storm_memset_hc_disable(sc, port, fw_sb_id, sb_index, disable);
1803 elink_cb_udelay(struct bxe_softc *sc,
1810 elink_cb_reg_read(struct bxe_softc *sc,
1813 return (REG_RD(sc, reg_addr));
1817 elink_cb_reg_write(struct bxe_softc *sc,
1821 REG_WR(sc, reg_addr, val);
1825 elink_cb_reg_wb_write(struct bxe_softc *sc,
1830 REG_WR_DMAE(sc, offset, wb_write, len);
1834 elink_cb_reg_wb_read(struct bxe_softc *sc,
1839 REG_RD_DMAE(sc, offset, wb_write, len);
1843 elink_cb_path_id(struct bxe_softc *sc)
1845 return (SC_PATH(sc));
1849 elink_cb_event_log(struct bxe_softc *sc,
1850 const elink_log_id_t elink_log_id,
1854 BLOGI(sc, "ELINK EVENT LOG (%d)\n", elink_log_id);
1858 bxe_set_spio(struct bxe_softc *sc,
1864 /* Only 2 SPIOs are configurable */
1865 if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
1866 BLOGE(sc, "Invalid SPIO 0x%x mode 0x%x\n", spio, mode);
1870 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_SPIO);
1872 /* read SPIO and mask except the float bits */
1873 spio_reg = (REG_RD(sc, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
1876 case MISC_SPIO_OUTPUT_LOW:
1877 BLOGD(sc, DBG_LOAD, "Set SPIO 0x%x -> output low\n", spio);
1878 /* clear FLOAT and set CLR */
1879 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
1880 spio_reg |= (spio << MISC_SPIO_CLR_POS);
1883 case MISC_SPIO_OUTPUT_HIGH:
1884 BLOGD(sc, DBG_LOAD, "Set SPIO 0x%x -> output high\n", spio);
1885 /* clear FLOAT and set SET */
1886 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
1887 spio_reg |= (spio << MISC_SPIO_SET_POS);
1890 case MISC_SPIO_INPUT_HI_Z:
1891 BLOGD(sc, DBG_LOAD, "Set SPIO 0x%x -> input\n", spio);
1893 spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
1900 REG_WR(sc, MISC_REG_SPIO, spio_reg);
1901 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_SPIO);
1907 bxe_gpio_read(struct bxe_softc *sc,
1911 /* The GPIO should be swapped if swap register is set and active */
1912 int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) &&
1913 REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port);
1914 int gpio_shift = (gpio_num +
1915 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0));
1916 uint32_t gpio_mask = (1 << gpio_shift);
1919 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1920 BLOGE(sc, "Invalid GPIO %d port 0x%x gpio_port %d gpio_shift %d"
1921 " gpio_mask 0x%x\n", gpio_num, port, gpio_port, gpio_shift,
1926 /* read GPIO value */
1927 gpio_reg = REG_RD(sc, MISC_REG_GPIO);
1929 /* get the requested pin value */
1930 return ((gpio_reg & gpio_mask) == gpio_mask) ? 1 : 0;
1934 bxe_gpio_write(struct bxe_softc *sc,
1939 /* The GPIO should be swapped if swap register is set and active */
1940 int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) &&
1941 REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port);
1942 int gpio_shift = (gpio_num +
1943 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0));
1944 uint32_t gpio_mask = (1 << gpio_shift);
1947 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1948 BLOGE(sc, "Invalid GPIO %d mode 0x%x port 0x%x gpio_port %d"
1949 " gpio_shift %d gpio_mask 0x%x\n",
1950 gpio_num, mode, port, gpio_port, gpio_shift, gpio_mask);
1954 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
1956 /* read GPIO and mask except the float bits */
1957 gpio_reg = (REG_RD(sc, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
1960 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1962 "Set GPIO %d (shift %d) -> output low\n",
1963 gpio_num, gpio_shift);
1964 /* clear FLOAT and set CLR */
1965 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1966 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
1969 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1971 "Set GPIO %d (shift %d) -> output high\n",
1972 gpio_num, gpio_shift);
1973 /* clear FLOAT and set SET */
1974 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1975 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
1978 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
1980 "Set GPIO %d (shift %d) -> input\n",
1981 gpio_num, gpio_shift);
1983 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1990 REG_WR(sc, MISC_REG_GPIO, gpio_reg);
1991 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
1997 bxe_gpio_mult_write(struct bxe_softc *sc,
2003 /* any port swapping should be handled by caller */
2005 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2007 /* read GPIO and mask except the float bits */
2008 gpio_reg = REG_RD(sc, MISC_REG_GPIO);
2009 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2010 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
2011 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
2014 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
2015 BLOGD(sc, DBG_PHY, "Set GPIO 0x%x -> output low\n", pins);
2017 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
2020 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
2021 BLOGD(sc, DBG_PHY, "Set GPIO 0x%x -> output high\n", pins);
2023 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
2026 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
2027 BLOGD(sc, DBG_PHY, "Set GPIO 0x%x -> input\n", pins);
2029 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2033 BLOGE(sc, "Invalid GPIO mode assignment pins 0x%x mode 0x%x"
2034 " gpio_reg 0x%x\n", pins, mode, gpio_reg);
2035 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2039 REG_WR(sc, MISC_REG_GPIO, gpio_reg);
2040 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2046 bxe_gpio_int_write(struct bxe_softc *sc,
2051 /* The GPIO should be swapped if swap register is set and active */
2052 int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) &&
2053 REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port);
2054 int gpio_shift = (gpio_num +
2055 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0));
2056 uint32_t gpio_mask = (1 << gpio_shift);
2059 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2060 BLOGE(sc, "Invalid GPIO %d mode 0x%x port 0x%x gpio_port %d"
2061 " gpio_shift %d gpio_mask 0x%x\n",
2062 gpio_num, mode, port, gpio_port, gpio_shift, gpio_mask);
2066 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2069 gpio_reg = REG_RD(sc, MISC_REG_GPIO_INT);
2072 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
2074 "Clear GPIO INT %d (shift %d) -> output low\n",
2075 gpio_num, gpio_shift);
2076 /* clear SET and set CLR */
2077 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2078 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2081 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
2083 "Set GPIO INT %d (shift %d) -> output high\n",
2084 gpio_num, gpio_shift);
2085 /* clear CLR and set SET */
2086 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2087 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2094 REG_WR(sc, MISC_REG_GPIO_INT, gpio_reg);
2095 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2101 elink_cb_gpio_read(struct bxe_softc *sc,
2105 return (bxe_gpio_read(sc, gpio_num, port));
2109 elink_cb_gpio_write(struct bxe_softc *sc,
2111 uint8_t mode, /* 0=low 1=high */
2114 return (bxe_gpio_write(sc, gpio_num, mode, port));
2118 elink_cb_gpio_mult_write(struct bxe_softc *sc,
2120 uint8_t mode) /* 0=low 1=high */
2122 return (bxe_gpio_mult_write(sc, pins, mode));
2126 elink_cb_gpio_int_write(struct bxe_softc *sc,
2128 uint8_t mode, /* 0=low 1=high */
2131 return (bxe_gpio_int_write(sc, gpio_num, mode, port));
2135 elink_cb_notify_link_changed(struct bxe_softc *sc)
2137 REG_WR(sc, (MISC_REG_AEU_GENERAL_ATTN_12 +
2138 (SC_FUNC(sc) * sizeof(uint32_t))), 1);
2141 /* send the MCP a request, block until there is a reply */
2143 elink_cb_fw_command(struct bxe_softc *sc,
2147 int mb_idx = SC_FW_MB_IDX(sc);
2151 uint8_t delay = CHIP_REV_IS_SLOW(sc) ? 100 : 10;
2156 SHMEM_WR(sc, func_mb[mb_idx].drv_mb_param, param);
2157 SHMEM_WR(sc, func_mb[mb_idx].drv_mb_header, (command | seq));
2160 "wrote command 0x%08x to FW MB param 0x%08x\n",
2161 (command | seq), param);
2163 /* Let the FW do it's magic. GIve it up to 5 seconds... */
2165 DELAY(delay * 1000);
2166 rc = SHMEM_RD(sc, func_mb[mb_idx].fw_mb_header);
2167 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
2170 "[after %d ms] read 0x%x seq 0x%x from FW MB\n",
2171 cnt*delay, rc, seq);
2173 /* is this a reply to our command? */
2174 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK)) {
2175 rc &= FW_MSG_CODE_MASK;
2178 BLOGE(sc, "FW failed to respond!\n");
2179 // XXX bxe_fw_dump(sc);
2183 BXE_FWMB_UNLOCK(sc);
2188 bxe_fw_command(struct bxe_softc *sc,
2192 return (elink_cb_fw_command(sc, command, param));
2196 __storm_memset_dma_mapping(struct bxe_softc *sc,
2200 REG_WR(sc, addr, U64_LO(mapping));
2201 REG_WR(sc, (addr + 4), U64_HI(mapping));
2205 storm_memset_spq_addr(struct bxe_softc *sc,
2209 uint32_t addr = (XSEM_REG_FAST_MEMORY +
2210 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid));
2211 __storm_memset_dma_mapping(sc, addr, mapping);
2215 storm_memset_vf_to_pf(struct bxe_softc *sc,
2219 REG_WR8(sc, (BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id);
2220 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id);
2221 REG_WR8(sc, (BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id);
2222 REG_WR8(sc, (BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id);
2226 storm_memset_func_en(struct bxe_softc *sc,
2230 REG_WR8(sc, (BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid)), enable);
2231 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid)), enable);
2232 REG_WR8(sc, (BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid)), enable);
2233 REG_WR8(sc, (BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid)), enable);
2237 storm_memset_eq_data(struct bxe_softc *sc,
2238 struct event_ring_data *eq_data,
2244 addr = (BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid));
2245 size = sizeof(struct event_ring_data);
2246 ecore_storm_memset_struct(sc, addr, size, (uint32_t *)eq_data);
2250 storm_memset_eq_prod(struct bxe_softc *sc,
2254 uint32_t addr = (BAR_CSTRORM_INTMEM +
2255 CSTORM_EVENT_RING_PROD_OFFSET(pfid));
2256 REG_WR16(sc, addr, eq_prod);
2260 * Post a slowpath command.
2262 * A slowpath command is used to propogate a configuration change through
2263 * the controller in a controlled manner, allowing each STORM processor and
2264 * other H/W blocks to phase in the change. The commands sent on the
2265 * slowpath are referred to as ramrods. Depending on the ramrod used the
2266 * completion of the ramrod will occur in different ways. Here's a
2267 * breakdown of ramrods and how they complete:
2269 * RAMROD_CMD_ID_ETH_PORT_SETUP
2270 * Used to setup the leading connection on a port. Completes on the
2271 * Receive Completion Queue (RCQ) of that port (typically fp[0]).
2273 * RAMROD_CMD_ID_ETH_CLIENT_SETUP
2274 * Used to setup an additional connection on a port. Completes on the
2275 * RCQ of the multi-queue/RSS connection being initialized.
2277 * RAMROD_CMD_ID_ETH_STAT_QUERY
2278 * Used to force the storm processors to update the statistics database
2279 * in host memory. This ramrod is send on the leading connection CID and
2280 * completes as an index increment of the CSTORM on the default status
2283 * RAMROD_CMD_ID_ETH_UPDATE
2284 * Used to update the state of the leading connection, usually to udpate
2285 * the RSS indirection table. Completes on the RCQ of the leading
2286 * connection. (Not currently used under FreeBSD until OS support becomes
2289 * RAMROD_CMD_ID_ETH_HALT
2290 * Used when tearing down a connection prior to driver unload. Completes
2291 * on the RCQ of the multi-queue/RSS connection being torn down. Don't
2292 * use this on the leading connection.
2294 * RAMROD_CMD_ID_ETH_SET_MAC
2295 * Sets the Unicast/Broadcast/Multicast used by the port. Completes on
2296 * the RCQ of the leading connection.
2298 * RAMROD_CMD_ID_ETH_CFC_DEL
2299 * Used when tearing down a conneciton prior to driver unload. Completes
2300 * on the RCQ of the leading connection (since the current connection
2301 * has been completely removed from controller memory).
2303 * RAMROD_CMD_ID_ETH_PORT_DEL
2304 * Used to tear down the leading connection prior to driver unload,
2305 * typically fp[0]. Completes as an index increment of the CSTORM on the
2306 * default status block.
2308 * RAMROD_CMD_ID_ETH_FORWARD_SETUP
2309 * Used for connection offload. Completes on the RCQ of the multi-queue
2310 * RSS connection that is being offloaded. (Not currently used under
2313 * There can only be one command pending per function.
2316 * 0 = Success, !0 = Failure.
2319 /* must be called under the spq lock */
2321 struct eth_spe *bxe_sp_get_next(struct bxe_softc *sc)
2323 struct eth_spe *next_spe = sc->spq_prod_bd;
2325 if (sc->spq_prod_bd == sc->spq_last_bd) {
2326 /* wrap back to the first eth_spq */
2327 sc->spq_prod_bd = sc->spq;
2328 sc->spq_prod_idx = 0;
2337 /* must be called under the spq lock */
2339 void bxe_sp_prod_update(struct bxe_softc *sc)
2341 int func = SC_FUNC(sc);
2344 * Make sure that BD data is updated before writing the producer.
2345 * BD data is written to the memory, the producer is read from the
2346 * memory, thus we need a full memory barrier to ensure the ordering.
2350 REG_WR16(sc, (BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func)),
2353 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle, 0, 0,
2354 BUS_SPACE_BARRIER_WRITE);
2358 * bxe_is_contextless_ramrod - check if the current command ends on EQ
2360 * @cmd: command to check
2361 * @cmd_type: command type
2364 int bxe_is_contextless_ramrod(int cmd,
2367 if ((cmd_type == NONE_CONNECTION_TYPE) ||
2368 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
2369 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
2370 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
2371 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
2372 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
2373 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE)) {
2381 * bxe_sp_post - place a single command on an SP ring
2383 * @sc: driver handle
2384 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
2385 * @cid: SW CID the command is related to
2386 * @data_hi: command private data address (high 32 bits)
2387 * @data_lo: command private data address (low 32 bits)
2388 * @cmd_type: command type (e.g. NONE, ETH)
2390 * SP data is handled as if it's always an address pair, thus data fields are
2391 * not swapped to little endian in upper functions. Instead this function swaps
2392 * data as if it's two uint32 fields.
2395 bxe_sp_post(struct bxe_softc *sc,
2402 struct eth_spe *spe;
2406 common = bxe_is_contextless_ramrod(command, cmd_type);
2411 if (!atomic_load_acq_long(&sc->eq_spq_left)) {
2412 BLOGE(sc, "EQ ring is full!\n");
2417 if (!atomic_load_acq_long(&sc->cq_spq_left)) {
2418 BLOGE(sc, "SPQ ring is full!\n");
2424 spe = bxe_sp_get_next(sc);
2426 /* CID needs port number to be encoded int it */
2427 spe->hdr.conn_and_cmd_data =
2428 htole32((command << SPE_HDR_T_CMD_ID_SHIFT) | HW_CID(sc, cid));
2430 type = (cmd_type << SPE_HDR_T_CONN_TYPE_SHIFT) & SPE_HDR_T_CONN_TYPE;
2432 /* TBD: Check if it works for VFs */
2433 type |= ((SC_FUNC(sc) << SPE_HDR_T_FUNCTION_ID_SHIFT) &
2434 SPE_HDR_T_FUNCTION_ID);
2436 spe->hdr.type = htole16(type);
2438 spe->data.update_data_addr.hi = htole32(data_hi);
2439 spe->data.update_data_addr.lo = htole32(data_lo);
2442 * It's ok if the actual decrement is issued towards the memory
2443 * somewhere between the lock and unlock. Thus no more explict
2444 * memory barrier is needed.
2447 atomic_subtract_acq_long(&sc->eq_spq_left, 1);
2449 atomic_subtract_acq_long(&sc->cq_spq_left, 1);
2452 BLOGD(sc, DBG_SP, "SPQE -> %#jx\n", (uintmax_t)sc->spq_dma.paddr);
2453 BLOGD(sc, DBG_SP, "FUNC_RDATA -> %p / %#jx\n",
2454 BXE_SP(sc, func_rdata), (uintmax_t)BXE_SP_MAPPING(sc, func_rdata));
2456 "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%lx,%lx)\n",
2458 (uint32_t)U64_HI(sc->spq_dma.paddr),
2459 (uint32_t)(U64_LO(sc->spq_dma.paddr) + (uint8_t *)sc->spq_prod_bd - (uint8_t *)sc->spq),
2466 atomic_load_acq_long(&sc->cq_spq_left),
2467 atomic_load_acq_long(&sc->eq_spq_left));
2469 bxe_sp_prod_update(sc);
2476 * bxe_debug_print_ind_table - prints the indirection table configuration.
2478 * @sc: driver hanlde
2479 * @p: pointer to rss configuration
2483 * FreeBSD Device probe function.
2485 * Compares the device found to the driver's list of supported devices and
2486 * reports back to the bsd loader whether this is the right driver for the device.
2487 * This is the driver entry function called from the "kldload" command.
2490 * BUS_PROBE_DEFAULT on success, positive value on failure.
2493 bxe_probe(device_t dev)
2495 struct bxe_softc *sc;
2496 struct bxe_device_type *t;
2498 uint16_t did, sdid, svid, vid;
2500 /* Find our device structure */
2501 sc = device_get_softc(dev);
2505 /* Get the data for the device to be probed. */
2506 vid = pci_get_vendor(dev);
2507 did = pci_get_device(dev);
2508 svid = pci_get_subvendor(dev);
2509 sdid = pci_get_subdevice(dev);
2512 "%s(); VID = 0x%04X, DID = 0x%04X, SVID = 0x%04X, "
2513 "SDID = 0x%04X\n", __FUNCTION__, vid, did, svid, sdid);
2515 /* Look through the list of known devices for a match. */
2516 while (t->bxe_name != NULL) {
2517 if ((vid == t->bxe_vid) && (did == t->bxe_did) &&
2518 ((svid == t->bxe_svid) || (t->bxe_svid == PCI_ANY_ID)) &&
2519 ((sdid == t->bxe_sdid) || (t->bxe_sdid == PCI_ANY_ID))) {
2520 descbuf = malloc(BXE_DEVDESC_MAX, M_TEMP, M_NOWAIT);
2521 if (descbuf == NULL)
2524 /* Print out the device identity. */
2525 snprintf(descbuf, BXE_DEVDESC_MAX,
2526 "%s (%c%d) BXE v:%s\n", t->bxe_name,
2527 (((pci_read_config(dev, PCIR_REVID, 4) &
2529 (pci_read_config(dev, PCIR_REVID, 4) & 0xf),
2530 BXE_DRIVER_VERSION);
2532 device_set_desc_copy(dev, descbuf);
2533 free(descbuf, M_TEMP);
2534 return (BUS_PROBE_DEFAULT);
2543 bxe_init_mutexes(struct bxe_softc *sc)
2545 #ifdef BXE_CORE_LOCK_SX
2546 snprintf(sc->core_sx_name, sizeof(sc->core_sx_name),
2547 "bxe%d_core_lock", sc->unit);
2548 sx_init(&sc->core_sx, sc->core_sx_name);
2550 snprintf(sc->core_mtx_name, sizeof(sc->core_mtx_name),
2551 "bxe%d_core_lock", sc->unit);
2552 mtx_init(&sc->core_mtx, sc->core_mtx_name, NULL, MTX_DEF);
2555 snprintf(sc->sp_mtx_name, sizeof(sc->sp_mtx_name),
2556 "bxe%d_sp_lock", sc->unit);
2557 mtx_init(&sc->sp_mtx, sc->sp_mtx_name, NULL, MTX_DEF);
2559 snprintf(sc->dmae_mtx_name, sizeof(sc->dmae_mtx_name),
2560 "bxe%d_dmae_lock", sc->unit);
2561 mtx_init(&sc->dmae_mtx, sc->dmae_mtx_name, NULL, MTX_DEF);
2563 snprintf(sc->port.phy_mtx_name, sizeof(sc->port.phy_mtx_name),
2564 "bxe%d_phy_lock", sc->unit);
2565 mtx_init(&sc->port.phy_mtx, sc->port.phy_mtx_name, NULL, MTX_DEF);
2567 snprintf(sc->fwmb_mtx_name, sizeof(sc->fwmb_mtx_name),
2568 "bxe%d_fwmb_lock", sc->unit);
2569 mtx_init(&sc->fwmb_mtx, sc->fwmb_mtx_name, NULL, MTX_DEF);
2571 snprintf(sc->print_mtx_name, sizeof(sc->print_mtx_name),
2572 "bxe%d_print_lock", sc->unit);
2573 mtx_init(&(sc->print_mtx), sc->print_mtx_name, NULL, MTX_DEF);
2575 snprintf(sc->stats_mtx_name, sizeof(sc->stats_mtx_name),
2576 "bxe%d_stats_lock", sc->unit);
2577 mtx_init(&(sc->stats_mtx), sc->stats_mtx_name, NULL, MTX_DEF);
2579 snprintf(sc->mcast_mtx_name, sizeof(sc->mcast_mtx_name),
2580 "bxe%d_mcast_lock", sc->unit);
2581 mtx_init(&(sc->mcast_mtx), sc->mcast_mtx_name, NULL, MTX_DEF);
2585 bxe_release_mutexes(struct bxe_softc *sc)
2587 #ifdef BXE_CORE_LOCK_SX
2588 sx_destroy(&sc->core_sx);
2590 if (mtx_initialized(&sc->core_mtx)) {
2591 mtx_destroy(&sc->core_mtx);
2595 if (mtx_initialized(&sc->sp_mtx)) {
2596 mtx_destroy(&sc->sp_mtx);
2599 if (mtx_initialized(&sc->dmae_mtx)) {
2600 mtx_destroy(&sc->dmae_mtx);
2603 if (mtx_initialized(&sc->port.phy_mtx)) {
2604 mtx_destroy(&sc->port.phy_mtx);
2607 if (mtx_initialized(&sc->fwmb_mtx)) {
2608 mtx_destroy(&sc->fwmb_mtx);
2611 if (mtx_initialized(&sc->print_mtx)) {
2612 mtx_destroy(&sc->print_mtx);
2615 if (mtx_initialized(&sc->stats_mtx)) {
2616 mtx_destroy(&sc->stats_mtx);
2619 if (mtx_initialized(&sc->mcast_mtx)) {
2620 mtx_destroy(&sc->mcast_mtx);
2625 bxe_tx_disable(struct bxe_softc* sc)
2627 struct ifnet *ifp = sc->ifnet;
2629 /* tell the stack the driver is stopped and TX queue is full */
2631 ifp->if_drv_flags = 0;
2636 bxe_drv_pulse(struct bxe_softc *sc)
2638 SHMEM_WR(sc, func_mb[SC_FW_MB_IDX(sc)].drv_pulse_mb,
2639 sc->fw_drv_pulse_wr_seq);
2642 static inline uint16_t
2643 bxe_tx_avail(struct bxe_softc *sc,
2644 struct bxe_fastpath *fp)
2650 prod = fp->tx_bd_prod;
2651 cons = fp->tx_bd_cons;
2653 used = SUB_S16(prod, cons);
2655 return (int16_t)(sc->tx_ring_size) - used;
2659 bxe_tx_queue_has_work(struct bxe_fastpath *fp)
2663 mb(); /* status block fields can change */
2664 hw_cons = le16toh(*fp->tx_cons_sb);
2665 return (hw_cons != fp->tx_pkt_cons);
2668 static inline uint8_t
2669 bxe_has_tx_work(struct bxe_fastpath *fp)
2671 /* expand this for multi-cos if ever supported */
2672 return (bxe_tx_queue_has_work(fp)) ? TRUE : FALSE;
2676 bxe_has_rx_work(struct bxe_fastpath *fp)
2678 uint16_t rx_cq_cons_sb;
2680 mb(); /* status block fields can change */
2681 rx_cq_cons_sb = le16toh(*fp->rx_cq_cons_sb);
2682 if ((rx_cq_cons_sb & RCQ_MAX) == RCQ_MAX)
2684 return (fp->rx_cq_cons != rx_cq_cons_sb);
2688 bxe_sp_event(struct bxe_softc *sc,
2689 struct bxe_fastpath *fp,
2690 union eth_rx_cqe *rr_cqe)
2692 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
2693 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
2694 enum ecore_queue_cmd drv_cmd = ECORE_Q_CMD_MAX;
2695 struct ecore_queue_sp_obj *q_obj = &BXE_SP_OBJ(sc, fp).q_obj;
2697 BLOGD(sc, DBG_SP, "fp=%d cid=%d got ramrod #%d state is %x type is %d\n",
2698 fp->index, cid, command, sc->state, rr_cqe->ramrod_cqe.ramrod_type);
2701 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
2702 BLOGD(sc, DBG_SP, "got UPDATE ramrod. CID %d\n", cid);
2703 drv_cmd = ECORE_Q_CMD_UPDATE;
2706 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
2707 BLOGD(sc, DBG_SP, "got MULTI[%d] setup ramrod\n", cid);
2708 drv_cmd = ECORE_Q_CMD_SETUP;
2711 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
2712 BLOGD(sc, DBG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
2713 drv_cmd = ECORE_Q_CMD_SETUP_TX_ONLY;
2716 case (RAMROD_CMD_ID_ETH_HALT):
2717 BLOGD(sc, DBG_SP, "got MULTI[%d] halt ramrod\n", cid);
2718 drv_cmd = ECORE_Q_CMD_HALT;
2721 case (RAMROD_CMD_ID_ETH_TERMINATE):
2722 BLOGD(sc, DBG_SP, "got MULTI[%d] teminate ramrod\n", cid);
2723 drv_cmd = ECORE_Q_CMD_TERMINATE;
2726 case (RAMROD_CMD_ID_ETH_EMPTY):
2727 BLOGD(sc, DBG_SP, "got MULTI[%d] empty ramrod\n", cid);
2728 drv_cmd = ECORE_Q_CMD_EMPTY;
2732 BLOGD(sc, DBG_SP, "ERROR: unexpected MC reply (%d) on fp[%d]\n",
2733 command, fp->index);
2737 if ((drv_cmd != ECORE_Q_CMD_MAX) &&
2738 q_obj->complete_cmd(sc, q_obj, drv_cmd)) {
2740 * q_obj->complete_cmd() failure means that this was
2741 * an unexpected completion.
2743 * In this case we don't want to increase the sc->spq_left
2744 * because apparently we haven't sent this command the first
2747 // bxe_panic(sc, ("Unexpected SP completion\n"));
2751 atomic_add_acq_long(&sc->cq_spq_left, 1);
2753 BLOGD(sc, DBG_SP, "sc->cq_spq_left 0x%lx\n",
2754 atomic_load_acq_long(&sc->cq_spq_left));
2758 * The current mbuf is part of an aggregation. Move the mbuf into the TPA
2759 * aggregation queue, put an empty mbuf back onto the receive chain, and mark
2760 * the current aggregation queue as in-progress.
2763 bxe_tpa_start(struct bxe_softc *sc,
2764 struct bxe_fastpath *fp,
2768 struct eth_fast_path_rx_cqe *cqe)
2770 struct bxe_sw_rx_bd tmp_bd;
2771 struct bxe_sw_rx_bd *rx_buf;
2772 struct eth_rx_bd *rx_bd;
2774 struct bxe_sw_tpa_info *tpa_info = &fp->rx_tpa_info[queue];
2777 BLOGD(sc, DBG_LRO, "fp[%02d].tpa[%02d] TPA START "
2778 "cons=%d prod=%d\n",
2779 fp->index, queue, cons, prod);
2781 max_agg_queues = MAX_AGG_QS(sc);
2783 KASSERT((queue < max_agg_queues),
2784 ("fp[%02d] invalid aggr queue (%d >= %d)!",
2785 fp->index, queue, max_agg_queues));
2787 KASSERT((tpa_info->state == BXE_TPA_STATE_STOP),
2788 ("fp[%02d].tpa[%02d] starting aggr on queue not stopped!",
2791 /* copy the existing mbuf and mapping from the TPA pool */
2792 tmp_bd = tpa_info->bd;
2794 if (tmp_bd.m == NULL) {
2797 tmp = (uint32_t *)cqe;
2799 BLOGE(sc, "fp[%02d].tpa[%02d] cons[%d] prod[%d]mbuf not allocated!\n",
2800 fp->index, queue, cons, prod);
2801 BLOGE(sc, "cqe [0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x]\n",
2802 *tmp, *(tmp+1), *(tmp+2), *(tmp+3), *(tmp+4), *(tmp+5), *(tmp+6), *(tmp+7));
2804 /* XXX Error handling? */
2808 /* change the TPA queue to the start state */
2809 tpa_info->state = BXE_TPA_STATE_START;
2810 tpa_info->placement_offset = cqe->placement_offset;
2811 tpa_info->parsing_flags = le16toh(cqe->pars_flags.flags);
2812 tpa_info->vlan_tag = le16toh(cqe->vlan_tag);
2813 tpa_info->len_on_bd = le16toh(cqe->len_on_bd);
2815 fp->rx_tpa_queue_used |= (1 << queue);
2818 * If all the buffer descriptors are filled with mbufs then fill in
2819 * the current consumer index with a new BD. Else if a maximum Rx
2820 * buffer limit is imposed then fill in the next producer index.
2822 index = (sc->max_rx_bufs != RX_BD_USABLE) ?
2825 /* move the received mbuf and mapping to TPA pool */
2826 tpa_info->bd = fp->rx_mbuf_chain[cons];
2828 /* release any existing RX BD mbuf mappings */
2829 if (cons != index) {
2830 rx_buf = &fp->rx_mbuf_chain[cons];
2832 if (rx_buf->m_map != NULL) {
2833 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map,
2834 BUS_DMASYNC_POSTREAD);
2835 bus_dmamap_unload(fp->rx_mbuf_tag, rx_buf->m_map);
2839 * We get here when the maximum number of rx buffers is less than
2840 * RX_BD_USABLE. The mbuf is already saved above so it's OK to NULL
2841 * it out here without concern of a memory leak.
2843 fp->rx_mbuf_chain[cons].m = NULL;
2846 /* update the Rx SW BD with the mbuf info from the TPA pool */
2847 fp->rx_mbuf_chain[index] = tmp_bd;
2849 /* update the Rx BD with the empty mbuf phys address from the TPA pool */
2850 rx_bd = &fp->rx_chain[index];
2851 rx_bd->addr_hi = htole32(U64_HI(tpa_info->seg.ds_addr));
2852 rx_bd->addr_lo = htole32(U64_LO(tpa_info->seg.ds_addr));
2856 * When a TPA aggregation is completed, loop through the individual mbufs
2857 * of the aggregation, combining them into a single mbuf which will be sent
2858 * up the stack. Refill all freed SGEs with mbufs as we go along.
2861 bxe_fill_frag_mbuf(struct bxe_softc *sc,
2862 struct bxe_fastpath *fp,
2863 struct bxe_sw_tpa_info *tpa_info,
2867 struct eth_end_agg_rx_cqe *cqe,
2870 struct mbuf *m_frag;
2871 uint32_t frag_len, frag_size, i;
2876 frag_size = le16toh(cqe->pkt_len) - tpa_info->len_on_bd;
2879 "fp[%02d].tpa[%02d] TPA fill len_on_bd=%d frag_size=%d pages=%d\n",
2880 fp->index, queue, tpa_info->len_on_bd, frag_size, pages);
2882 /* make sure the aggregated frame is not too big to handle */
2883 if (pages > 8 * PAGES_PER_SGE) {
2885 uint32_t *tmp = (uint32_t *)cqe;
2887 BLOGE(sc, "fp[%02d].sge[0x%04x] has too many pages (%d)! "
2888 "pkt_len=%d len_on_bd=%d frag_size=%d\n",
2889 fp->index, cqe_idx, pages, le16toh(cqe->pkt_len),
2890 tpa_info->len_on_bd, frag_size);
2892 BLOGE(sc, "cqe [0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x]\n",
2893 *tmp, *(tmp+1), *(tmp+2), *(tmp+3), *(tmp+4), *(tmp+5), *(tmp+6), *(tmp+7));
2895 bxe_panic(sc, ("sge page count error\n"));
2900 * Scan through the scatter gather list pulling individual mbufs into a
2901 * single mbuf for the host stack.
2903 for (i = 0, j = 0; i < pages; i += PAGES_PER_SGE, j++) {
2904 sge_idx = RX_SGE(le16toh(cqe->sgl_or_raw_data.sgl[j]));
2907 * Firmware gives the indices of the SGE as if the ring is an array
2908 * (meaning that the "next" element will consume 2 indices).
2910 frag_len = min(frag_size, (uint32_t)(SGE_PAGES));
2912 BLOGD(sc, DBG_LRO, "fp[%02d].tpa[%02d] TPA fill i=%d j=%d "
2913 "sge_idx=%d frag_size=%d frag_len=%d\n",
2914 fp->index, queue, i, j, sge_idx, frag_size, frag_len);
2916 m_frag = fp->rx_sge_mbuf_chain[sge_idx].m;
2918 /* allocate a new mbuf for the SGE */
2919 rc = bxe_alloc_rx_sge_mbuf(fp, sge_idx);
2921 /* Leave all remaining SGEs in the ring! */
2925 /* update the fragment length */
2926 m_frag->m_len = frag_len;
2928 /* concatenate the fragment to the head mbuf */
2930 fp->eth_q_stats.mbuf_alloc_sge--;
2932 /* update the TPA mbuf size and remaining fragment size */
2933 m->m_pkthdr.len += frag_len;
2934 frag_size -= frag_len;
2938 "fp[%02d].tpa[%02d] TPA fill done frag_size=%d\n",
2939 fp->index, queue, frag_size);
2945 bxe_clear_sge_mask_next_elems(struct bxe_fastpath *fp)
2949 for (i = 1; i <= RX_SGE_NUM_PAGES; i++) {
2950 int idx = RX_SGE_TOTAL_PER_PAGE * i - 1;
2952 for (j = 0; j < 2; j++) {
2953 BIT_VEC64_CLEAR_BIT(fp->sge_mask, idx);
2960 bxe_init_sge_ring_bit_mask(struct bxe_fastpath *fp)
2962 /* set the mask to all 1's, it's faster to compare to 0 than to 0xf's */
2963 memset(fp->sge_mask, 0xff, sizeof(fp->sge_mask));
2966 * Clear the two last indices in the page to 1. These are the indices that
2967 * correspond to the "next" element, hence will never be indicated and
2968 * should be removed from the calculations.
2970 bxe_clear_sge_mask_next_elems(fp);
2974 bxe_update_last_max_sge(struct bxe_fastpath *fp,
2977 uint16_t last_max = fp->last_max_sge;
2979 if (SUB_S16(idx, last_max) > 0) {
2980 fp->last_max_sge = idx;
2985 bxe_update_sge_prod(struct bxe_softc *sc,
2986 struct bxe_fastpath *fp,
2988 union eth_sgl_or_raw_data *cqe)
2990 uint16_t last_max, last_elem, first_elem;
2998 /* first mark all used pages */
2999 for (i = 0; i < sge_len; i++) {
3000 BIT_VEC64_CLEAR_BIT(fp->sge_mask,
3001 RX_SGE(le16toh(cqe->sgl[i])));
3005 "fp[%02d] fp_cqe->sgl[%d] = %d\n",
3006 fp->index, sge_len - 1,
3007 le16toh(cqe->sgl[sge_len - 1]));
3009 /* assume that the last SGE index is the biggest */
3010 bxe_update_last_max_sge(fp,
3011 le16toh(cqe->sgl[sge_len - 1]));
3013 last_max = RX_SGE(fp->last_max_sge);
3014 last_elem = last_max >> BIT_VEC64_ELEM_SHIFT;
3015 first_elem = RX_SGE(fp->rx_sge_prod) >> BIT_VEC64_ELEM_SHIFT;
3017 /* if ring is not full */
3018 if (last_elem + 1 != first_elem) {
3022 /* now update the prod */
3023 for (i = first_elem; i != last_elem; i = RX_SGE_NEXT_MASK_ELEM(i)) {
3024 if (__predict_true(fp->sge_mask[i])) {
3028 fp->sge_mask[i] = BIT_VEC64_ELEM_ONE_MASK;
3029 delta += BIT_VEC64_ELEM_SZ;
3033 fp->rx_sge_prod += delta;
3034 /* clear page-end entries */
3035 bxe_clear_sge_mask_next_elems(fp);
3039 "fp[%02d] fp->last_max_sge=%d fp->rx_sge_prod=%d\n",
3040 fp->index, fp->last_max_sge, fp->rx_sge_prod);
3044 * The aggregation on the current TPA queue has completed. Pull the individual
3045 * mbuf fragments together into a single mbuf, perform all necessary checksum
3046 * calculations, and send the resuting mbuf to the stack.
3049 bxe_tpa_stop(struct bxe_softc *sc,
3050 struct bxe_fastpath *fp,
3051 struct bxe_sw_tpa_info *tpa_info,
3054 struct eth_end_agg_rx_cqe *cqe,
3057 struct ifnet *ifp = sc->ifnet;
3062 "fp[%02d].tpa[%02d] pad=%d pkt_len=%d pages=%d vlan=%d\n",
3063 fp->index, queue, tpa_info->placement_offset,
3064 le16toh(cqe->pkt_len), pages, tpa_info->vlan_tag);
3068 /* allocate a replacement before modifying existing mbuf */
3069 rc = bxe_alloc_rx_tpa_mbuf(fp, queue);
3071 /* drop the frame and log an error */
3072 fp->eth_q_stats.rx_soft_errors++;
3073 goto bxe_tpa_stop_exit;
3076 /* we have a replacement, fixup the current mbuf */
3077 m_adj(m, tpa_info->placement_offset);
3078 m->m_pkthdr.len = m->m_len = tpa_info->len_on_bd;
3080 /* mark the checksums valid (taken care of by the firmware) */
3081 fp->eth_q_stats.rx_ofld_frames_csum_ip++;
3082 fp->eth_q_stats.rx_ofld_frames_csum_tcp_udp++;
3083 m->m_pkthdr.csum_data = 0xffff;
3084 m->m_pkthdr.csum_flags |= (CSUM_IP_CHECKED |
3089 /* aggregate all of the SGEs into a single mbuf */
3090 rc = bxe_fill_frag_mbuf(sc, fp, tpa_info, queue, pages, m, cqe, cqe_idx);
3092 /* drop the packet and log an error */
3093 fp->eth_q_stats.rx_soft_errors++;
3096 if (tpa_info->parsing_flags & PARSING_FLAGS_INNER_VLAN_EXIST) {
3097 m->m_pkthdr.ether_vtag = tpa_info->vlan_tag;
3098 m->m_flags |= M_VLANTAG;
3101 /* assign packet to this interface interface */
3102 m->m_pkthdr.rcvif = ifp;
3104 #if __FreeBSD_version >= 800000
3105 /* specify what RSS queue was used for this flow */
3106 m->m_pkthdr.flowid = fp->index;
3111 fp->eth_q_stats.rx_tpa_pkts++;
3113 /* pass the frame to the stack */
3114 (*ifp->if_input)(ifp, m);
3117 /* we passed an mbuf up the stack or dropped the frame */
3118 fp->eth_q_stats.mbuf_alloc_tpa--;
3122 fp->rx_tpa_info[queue].state = BXE_TPA_STATE_STOP;
3123 fp->rx_tpa_queue_used &= ~(1 << queue);
3128 struct bxe_fastpath *fp,
3132 struct eth_fast_path_rx_cqe *cqe_fp)
3134 struct mbuf *m_frag;
3135 uint16_t frags, frag_len;
3136 uint16_t sge_idx = 0;
3141 /* adjust the mbuf */
3144 frag_size = len - lenonbd;
3145 frags = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT;
3147 for (i = 0, j = 0; i < frags; i += PAGES_PER_SGE, j++) {
3148 sge_idx = RX_SGE(le16toh(cqe_fp->sgl_or_raw_data.sgl[j]));
3150 m_frag = fp->rx_sge_mbuf_chain[sge_idx].m;
3151 frag_len = min(frag_size, (uint32_t)(SGE_PAGE_SIZE));
3152 m_frag->m_len = frag_len;
3154 /* allocate a new mbuf for the SGE */
3155 rc = bxe_alloc_rx_sge_mbuf(fp, sge_idx);
3157 /* Leave all remaining SGEs in the ring! */
3160 fp->eth_q_stats.mbuf_alloc_sge--;
3162 /* concatenate the fragment to the head mbuf */
3165 frag_size -= frag_len;
3168 bxe_update_sge_prod(fp->sc, fp, frags, &cqe_fp->sgl_or_raw_data);
3174 bxe_rxeof(struct bxe_softc *sc,
3175 struct bxe_fastpath *fp)
3177 struct ifnet *ifp = sc->ifnet;
3178 uint16_t bd_cons, bd_prod, bd_prod_fw, comp_ring_cons;
3179 uint16_t hw_cq_cons, sw_cq_cons, sw_cq_prod;
3185 /* CQ "next element" is of the size of the regular element */
3186 hw_cq_cons = le16toh(*fp->rx_cq_cons_sb);
3187 if ((hw_cq_cons & RCQ_USABLE_PER_PAGE) == RCQ_USABLE_PER_PAGE) {
3191 bd_cons = fp->rx_bd_cons;
3192 bd_prod = fp->rx_bd_prod;
3193 bd_prod_fw = bd_prod;
3194 sw_cq_cons = fp->rx_cq_cons;
3195 sw_cq_prod = fp->rx_cq_prod;
3198 * Memory barrier necessary as speculative reads of the rx
3199 * buffer can be ahead of the index in the status block
3204 "fp[%02d] Rx START hw_cq_cons=%u sw_cq_cons=%u\n",
3205 fp->index, hw_cq_cons, sw_cq_cons);
3207 while (sw_cq_cons != hw_cq_cons) {
3208 struct bxe_sw_rx_bd *rx_buf = NULL;
3209 union eth_rx_cqe *cqe;
3210 struct eth_fast_path_rx_cqe *cqe_fp;
3211 uint8_t cqe_fp_flags;
3212 enum eth_rx_cqe_type cqe_fp_type;
3213 uint16_t len, lenonbd, pad;
3214 struct mbuf *m = NULL;
3216 comp_ring_cons = RCQ(sw_cq_cons);
3217 bd_prod = RX_BD(bd_prod);
3218 bd_cons = RX_BD(bd_cons);
3220 cqe = &fp->rcq_chain[comp_ring_cons];
3221 cqe_fp = &cqe->fast_path_cqe;
3222 cqe_fp_flags = cqe_fp->type_error_flags;
3223 cqe_fp_type = cqe_fp_flags & ETH_FAST_PATH_RX_CQE_TYPE;
3226 "fp[%02d] Rx hw_cq_cons=%d hw_sw_cons=%d "
3227 "BD prod=%d cons=%d CQE type=0x%x err=0x%x "
3228 "status=0x%x rss_hash=0x%x vlan=0x%x len=%u lenonbd=%u\n",
3234 CQE_TYPE(cqe_fp_flags),
3236 cqe_fp->status_flags,
3237 le32toh(cqe_fp->rss_hash_result),
3238 le16toh(cqe_fp->vlan_tag),
3239 le16toh(cqe_fp->pkt_len_or_gro_seg_len),
3240 le16toh(cqe_fp->len_on_bd));
3242 /* is this a slowpath msg? */
3243 if (__predict_false(CQE_TYPE_SLOW(cqe_fp_type))) {
3244 bxe_sp_event(sc, fp, cqe);
3248 rx_buf = &fp->rx_mbuf_chain[bd_cons];
3250 if (!CQE_TYPE_FAST(cqe_fp_type)) {
3251 struct bxe_sw_tpa_info *tpa_info;
3252 uint16_t frag_size, pages;
3255 if (CQE_TYPE_START(cqe_fp_type)) {
3256 bxe_tpa_start(sc, fp, cqe_fp->queue_index,
3257 bd_cons, bd_prod, cqe_fp);
3258 m = NULL; /* packet not ready yet */
3262 KASSERT(CQE_TYPE_STOP(cqe_fp_type),
3263 ("CQE type is not STOP! (0x%x)\n", cqe_fp_type));
3265 queue = cqe->end_agg_cqe.queue_index;
3266 tpa_info = &fp->rx_tpa_info[queue];
3268 BLOGD(sc, DBG_LRO, "fp[%02d].tpa[%02d] TPA STOP\n",
3271 frag_size = (le16toh(cqe->end_agg_cqe.pkt_len) -
3272 tpa_info->len_on_bd);
3273 pages = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT;
3275 bxe_tpa_stop(sc, fp, tpa_info, queue, pages,
3276 &cqe->end_agg_cqe, comp_ring_cons);
3278 bxe_update_sge_prod(sc, fp, pages, &cqe->end_agg_cqe.sgl_or_raw_data);
3285 /* is this an error packet? */
3286 if (__predict_false(cqe_fp_flags &
3287 ETH_FAST_PATH_RX_CQE_PHY_DECODE_ERR_FLG)) {
3288 BLOGE(sc, "flags 0x%x rx packet %u\n", cqe_fp_flags, sw_cq_cons);
3289 fp->eth_q_stats.rx_soft_errors++;
3293 len = le16toh(cqe_fp->pkt_len_or_gro_seg_len);
3294 lenonbd = le16toh(cqe_fp->len_on_bd);
3295 pad = cqe_fp->placement_offset;
3299 if (__predict_false(m == NULL)) {
3300 BLOGE(sc, "No mbuf in rx chain descriptor %d for fp[%02d]\n",
3301 bd_cons, fp->index);
3305 /* XXX double copy if packet length under a threshold */
3308 * If all the buffer descriptors are filled with mbufs then fill in
3309 * the current consumer index with a new BD. Else if a maximum Rx
3310 * buffer limit is imposed then fill in the next producer index.
3312 rc = bxe_alloc_rx_bd_mbuf(fp, bd_cons,
3313 (sc->max_rx_bufs != RX_BD_USABLE) ?
3317 /* we simply reuse the received mbuf and don't post it to the stack */
3320 BLOGE(sc, "mbuf alloc fail for fp[%02d] rx chain (%d)\n",
3322 fp->eth_q_stats.rx_soft_errors++;
3324 if (sc->max_rx_bufs != RX_BD_USABLE) {
3325 /* copy this consumer index to the producer index */
3326 memcpy(&fp->rx_mbuf_chain[bd_prod], rx_buf,
3327 sizeof(struct bxe_sw_rx_bd));
3328 memset(rx_buf, 0, sizeof(struct bxe_sw_rx_bd));
3334 /* current mbuf was detached from the bd */
3335 fp->eth_q_stats.mbuf_alloc_rx--;
3337 /* we allocated a replacement mbuf, fixup the current one */
3339 m->m_pkthdr.len = m->m_len = len;
3341 if ((len > 60) && (len > lenonbd)) {
3342 fp->eth_q_stats.rx_bxe_service_rxsgl++;
3343 rc = bxe_service_rxsgl(fp, len, lenonbd, m, cqe_fp);
3346 fp->eth_q_stats.rx_jumbo_sge_pkts++;
3347 } else if (lenonbd < len) {
3348 fp->eth_q_stats.rx_erroneous_jumbo_sge_pkts++;
3351 /* assign packet to this interface interface */
3352 m->m_pkthdr.rcvif = ifp;
3354 /* assume no hardware checksum has complated */
3355 m->m_pkthdr.csum_flags = 0;
3357 /* validate checksum if offload enabled */
3358 if (ifp->if_capenable & IFCAP_RXCSUM) {
3359 /* check for a valid IP frame */
3360 if (!(cqe->fast_path_cqe.status_flags &
3361 ETH_FAST_PATH_RX_CQE_IP_XSUM_NO_VALIDATION_FLG)) {
3362 m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED;
3363 if (__predict_false(cqe_fp_flags &
3364 ETH_FAST_PATH_RX_CQE_IP_BAD_XSUM_FLG)) {
3365 fp->eth_q_stats.rx_hw_csum_errors++;
3367 fp->eth_q_stats.rx_ofld_frames_csum_ip++;
3368 m->m_pkthdr.csum_flags |= CSUM_IP_VALID;
3372 /* check for a valid TCP/UDP frame */
3373 if (!(cqe->fast_path_cqe.status_flags &
3374 ETH_FAST_PATH_RX_CQE_L4_XSUM_NO_VALIDATION_FLG)) {
3375 if (__predict_false(cqe_fp_flags &
3376 ETH_FAST_PATH_RX_CQE_L4_BAD_XSUM_FLG)) {
3377 fp->eth_q_stats.rx_hw_csum_errors++;
3379 fp->eth_q_stats.rx_ofld_frames_csum_tcp_udp++;
3380 m->m_pkthdr.csum_data = 0xFFFF;
3381 m->m_pkthdr.csum_flags |= (CSUM_DATA_VALID |
3387 /* if there is a VLAN tag then flag that info */
3388 if (cqe->fast_path_cqe.pars_flags.flags & PARSING_FLAGS_INNER_VLAN_EXIST) {
3389 m->m_pkthdr.ether_vtag = cqe->fast_path_cqe.vlan_tag;
3390 m->m_flags |= M_VLANTAG;
3393 #if __FreeBSD_version >= 800000
3394 /* specify what RSS queue was used for this flow */
3395 m->m_pkthdr.flowid = fp->index;
3401 bd_cons = RX_BD_NEXT(bd_cons);
3402 bd_prod = RX_BD_NEXT(bd_prod);
3403 bd_prod_fw = RX_BD_NEXT(bd_prod_fw);
3405 /* pass the frame to the stack */
3406 if (__predict_true(m != NULL)) {
3409 (*ifp->if_input)(ifp, m);
3414 sw_cq_prod = RCQ_NEXT(sw_cq_prod);
3415 sw_cq_cons = RCQ_NEXT(sw_cq_cons);
3417 /* limit spinning on the queue */
3421 if (rx_pkts == sc->rx_budget) {
3422 fp->eth_q_stats.rx_budget_reached++;
3425 } /* while work to do */
3427 fp->rx_bd_cons = bd_cons;
3428 fp->rx_bd_prod = bd_prod_fw;
3429 fp->rx_cq_cons = sw_cq_cons;
3430 fp->rx_cq_prod = sw_cq_prod;
3432 /* Update producers */
3433 bxe_update_rx_prod(sc, fp, bd_prod_fw, sw_cq_prod, fp->rx_sge_prod);
3435 fp->eth_q_stats.rx_pkts += rx_pkts;
3436 fp->eth_q_stats.rx_calls++;
3438 BXE_FP_RX_UNLOCK(fp);
3440 return (sw_cq_cons != hw_cq_cons);
3444 bxe_free_tx_pkt(struct bxe_softc *sc,
3445 struct bxe_fastpath *fp,
3448 struct bxe_sw_tx_bd *tx_buf = &fp->tx_mbuf_chain[idx];
3449 struct eth_tx_start_bd *tx_start_bd;
3450 uint16_t bd_idx = TX_BD(tx_buf->first_bd);
3454 /* unmap the mbuf from non-paged memory */
3455 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
3457 tx_start_bd = &fp->tx_chain[bd_idx].start_bd;
3458 nbd = le16toh(tx_start_bd->nbd) - 1;
3460 new_cons = (tx_buf->first_bd + nbd);
3463 if (__predict_true(tx_buf->m != NULL)) {
3465 fp->eth_q_stats.mbuf_alloc_tx--;
3467 fp->eth_q_stats.tx_chain_lost_mbuf++;
3471 tx_buf->first_bd = 0;
3476 /* transmit timeout watchdog */
3478 bxe_watchdog(struct bxe_softc *sc,
3479 struct bxe_fastpath *fp)
3483 if ((fp->watchdog_timer == 0) || (--fp->watchdog_timer)) {
3484 BXE_FP_TX_UNLOCK(fp);
3488 BLOGE(sc, "TX watchdog timeout on fp[%02d], resetting!\n", fp->index);
3489 if(sc->trigger_grcdump) {
3490 /* taking grcdump */
3494 BXE_FP_TX_UNLOCK(fp);
3496 atomic_store_rel_long(&sc->chip_tq_flags, CHIP_TQ_REINIT);
3497 taskqueue_enqueue(sc->chip_tq, &sc->chip_tq_task);
3502 /* processes transmit completions */
3504 bxe_txeof(struct bxe_softc *sc,
3505 struct bxe_fastpath *fp)
3507 struct ifnet *ifp = sc->ifnet;
3508 uint16_t bd_cons, hw_cons, sw_cons, pkt_cons;
3509 uint16_t tx_bd_avail;
3511 BXE_FP_TX_LOCK_ASSERT(fp);
3513 bd_cons = fp->tx_bd_cons;
3514 hw_cons = le16toh(*fp->tx_cons_sb);
3515 sw_cons = fp->tx_pkt_cons;
3517 while (sw_cons != hw_cons) {
3518 pkt_cons = TX_BD(sw_cons);
3521 "TX: fp[%d]: hw_cons=%u sw_cons=%u pkt_cons=%u\n",
3522 fp->index, hw_cons, sw_cons, pkt_cons);
3524 bd_cons = bxe_free_tx_pkt(sc, fp, pkt_cons);
3529 fp->tx_pkt_cons = sw_cons;
3530 fp->tx_bd_cons = bd_cons;
3533 "TX done: fp[%d]: hw_cons=%u sw_cons=%u sw_prod=%u\n",
3534 fp->index, hw_cons, fp->tx_pkt_cons, fp->tx_pkt_prod);
3538 tx_bd_avail = bxe_tx_avail(sc, fp);
3540 if (tx_bd_avail < BXE_TX_CLEANUP_THRESHOLD) {
3541 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
3543 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
3546 if (fp->tx_pkt_prod != fp->tx_pkt_cons) {
3547 /* reset the watchdog timer if there are pending transmits */
3548 fp->watchdog_timer = BXE_TX_TIMEOUT;
3551 /* clear watchdog when there are no pending transmits */
3552 fp->watchdog_timer = 0;
3558 bxe_drain_tx_queues(struct bxe_softc *sc)
3560 struct bxe_fastpath *fp;
3563 /* wait until all TX fastpath tasks have completed */
3564 for (i = 0; i < sc->num_queues; i++) {
3569 while (bxe_has_tx_work(fp)) {
3573 BXE_FP_TX_UNLOCK(fp);
3576 BLOGE(sc, "Timeout waiting for fp[%d] "
3577 "transmits to complete!\n", i);
3578 bxe_panic(sc, ("tx drain failure\n"));
3592 bxe_del_all_macs(struct bxe_softc *sc,
3593 struct ecore_vlan_mac_obj *mac_obj,
3595 uint8_t wait_for_comp)
3597 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
3600 /* wait for completion of requested */
3601 if (wait_for_comp) {
3602 bxe_set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
3605 /* Set the mac type of addresses we want to clear */
3606 bxe_set_bit(mac_type, &vlan_mac_flags);
3608 rc = mac_obj->delete_all(sc, mac_obj, &vlan_mac_flags, &ramrod_flags);
3610 BLOGE(sc, "Failed to delete MACs (%d) mac_type %d wait_for_comp 0x%x\n",
3611 rc, mac_type, wait_for_comp);
3618 bxe_fill_accept_flags(struct bxe_softc *sc,
3620 unsigned long *rx_accept_flags,
3621 unsigned long *tx_accept_flags)
3623 /* Clear the flags first */
3624 *rx_accept_flags = 0;
3625 *tx_accept_flags = 0;
3628 case BXE_RX_MODE_NONE:
3630 * 'drop all' supersedes any accept flags that may have been
3631 * passed to the function.
3635 case BXE_RX_MODE_NORMAL:
3636 bxe_set_bit(ECORE_ACCEPT_UNICAST, rx_accept_flags);
3637 bxe_set_bit(ECORE_ACCEPT_MULTICAST, rx_accept_flags);
3638 bxe_set_bit(ECORE_ACCEPT_BROADCAST, rx_accept_flags);
3640 /* internal switching mode */
3641 bxe_set_bit(ECORE_ACCEPT_UNICAST, tx_accept_flags);
3642 bxe_set_bit(ECORE_ACCEPT_MULTICAST, tx_accept_flags);
3643 bxe_set_bit(ECORE_ACCEPT_BROADCAST, tx_accept_flags);
3647 case BXE_RX_MODE_ALLMULTI:
3648 bxe_set_bit(ECORE_ACCEPT_UNICAST, rx_accept_flags);
3649 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, rx_accept_flags);
3650 bxe_set_bit(ECORE_ACCEPT_BROADCAST, rx_accept_flags);
3652 /* internal switching mode */
3653 bxe_set_bit(ECORE_ACCEPT_UNICAST, tx_accept_flags);
3654 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, tx_accept_flags);
3655 bxe_set_bit(ECORE_ACCEPT_BROADCAST, tx_accept_flags);
3659 case BXE_RX_MODE_PROMISC:
3661 * According to deffinition of SI mode, iface in promisc mode
3662 * should receive matched and unmatched (in resolution of port)
3665 bxe_set_bit(ECORE_ACCEPT_UNMATCHED, rx_accept_flags);
3666 bxe_set_bit(ECORE_ACCEPT_UNICAST, rx_accept_flags);
3667 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, rx_accept_flags);
3668 bxe_set_bit(ECORE_ACCEPT_BROADCAST, rx_accept_flags);
3670 /* internal switching mode */
3671 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, tx_accept_flags);
3672 bxe_set_bit(ECORE_ACCEPT_BROADCAST, tx_accept_flags);
3675 bxe_set_bit(ECORE_ACCEPT_ALL_UNICAST, tx_accept_flags);
3677 bxe_set_bit(ECORE_ACCEPT_UNICAST, tx_accept_flags);
3683 BLOGE(sc, "Unknown rx_mode (0x%x)\n", rx_mode);
3687 /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
3688 if (rx_mode != BXE_RX_MODE_NONE) {
3689 bxe_set_bit(ECORE_ACCEPT_ANY_VLAN, rx_accept_flags);
3690 bxe_set_bit(ECORE_ACCEPT_ANY_VLAN, tx_accept_flags);
3697 bxe_set_q_rx_mode(struct bxe_softc *sc,
3699 unsigned long rx_mode_flags,
3700 unsigned long rx_accept_flags,
3701 unsigned long tx_accept_flags,
3702 unsigned long ramrod_flags)
3704 struct ecore_rx_mode_ramrod_params ramrod_param;
3707 memset(&ramrod_param, 0, sizeof(ramrod_param));
3709 /* Prepare ramrod parameters */
3710 ramrod_param.cid = 0;
3711 ramrod_param.cl_id = cl_id;
3712 ramrod_param.rx_mode_obj = &sc->rx_mode_obj;
3713 ramrod_param.func_id = SC_FUNC(sc);
3715 ramrod_param.pstate = &sc->sp_state;
3716 ramrod_param.state = ECORE_FILTER_RX_MODE_PENDING;
3718 ramrod_param.rdata = BXE_SP(sc, rx_mode_rdata);
3719 ramrod_param.rdata_mapping = BXE_SP_MAPPING(sc, rx_mode_rdata);
3721 bxe_set_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state);
3723 ramrod_param.ramrod_flags = ramrod_flags;
3724 ramrod_param.rx_mode_flags = rx_mode_flags;
3726 ramrod_param.rx_accept_flags = rx_accept_flags;
3727 ramrod_param.tx_accept_flags = tx_accept_flags;
3729 rc = ecore_config_rx_mode(sc, &ramrod_param);
3731 BLOGE(sc, "Set rx_mode %d cli_id 0x%x rx_mode_flags 0x%x "
3732 "rx_accept_flags 0x%x tx_accept_flags 0x%x "
3733 "ramrod_flags 0x%x rc %d failed\n", sc->rx_mode, cl_id,
3734 (uint32_t)rx_mode_flags, (uint32_t)rx_accept_flags,
3735 (uint32_t)tx_accept_flags, (uint32_t)ramrod_flags, rc);
3743 bxe_set_storm_rx_mode(struct bxe_softc *sc)
3745 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
3746 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
3749 rc = bxe_fill_accept_flags(sc, sc->rx_mode, &rx_accept_flags,
3755 bxe_set_bit(RAMROD_RX, &ramrod_flags);
3756 bxe_set_bit(RAMROD_TX, &ramrod_flags);
3758 /* XXX ensure all fastpath have same cl_id and/or move it to bxe_softc */
3759 return (bxe_set_q_rx_mode(sc, sc->fp[0].cl_id, rx_mode_flags,
3760 rx_accept_flags, tx_accept_flags,
3764 /* returns the "mcp load_code" according to global load_count array */
3766 bxe_nic_load_no_mcp(struct bxe_softc *sc)
3768 int path = SC_PATH(sc);
3769 int port = SC_PORT(sc);
3771 BLOGI(sc, "NO MCP - load counts[%d] %d, %d, %d\n",
3772 path, load_count[path][0], load_count[path][1],
3773 load_count[path][2]);
3774 load_count[path][0]++;
3775 load_count[path][1 + port]++;
3776 BLOGI(sc, "NO MCP - new load counts[%d] %d, %d, %d\n",
3777 path, load_count[path][0], load_count[path][1],
3778 load_count[path][2]);
3779 if (load_count[path][0] == 1) {
3780 return (FW_MSG_CODE_DRV_LOAD_COMMON);
3781 } else if (load_count[path][1 + port] == 1) {
3782 return (FW_MSG_CODE_DRV_LOAD_PORT);
3784 return (FW_MSG_CODE_DRV_LOAD_FUNCTION);
3788 /* returns the "mcp load_code" according to global load_count array */
3790 bxe_nic_unload_no_mcp(struct bxe_softc *sc)
3792 int port = SC_PORT(sc);
3793 int path = SC_PATH(sc);
3795 BLOGI(sc, "NO MCP - load counts[%d] %d, %d, %d\n",
3796 path, load_count[path][0], load_count[path][1],
3797 load_count[path][2]);
3798 load_count[path][0]--;
3799 load_count[path][1 + port]--;
3800 BLOGI(sc, "NO MCP - new load counts[%d] %d, %d, %d\n",
3801 path, load_count[path][0], load_count[path][1],
3802 load_count[path][2]);
3803 if (load_count[path][0] == 0) {
3804 return (FW_MSG_CODE_DRV_UNLOAD_COMMON);
3805 } else if (load_count[path][1 + port] == 0) {
3806 return (FW_MSG_CODE_DRV_UNLOAD_PORT);
3808 return (FW_MSG_CODE_DRV_UNLOAD_FUNCTION);
3812 /* request unload mode from the MCP: COMMON, PORT or FUNCTION */
3814 bxe_send_unload_req(struct bxe_softc *sc,
3817 uint32_t reset_code = 0;
3819 /* Select the UNLOAD request mode */
3820 if (unload_mode == UNLOAD_NORMAL) {
3821 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
3823 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
3826 /* Send the request to the MCP */
3827 if (!BXE_NOMCP(sc)) {
3828 reset_code = bxe_fw_command(sc, reset_code, 0);
3830 reset_code = bxe_nic_unload_no_mcp(sc);
3833 return (reset_code);
3836 /* send UNLOAD_DONE command to the MCP */
3838 bxe_send_unload_done(struct bxe_softc *sc,
3841 uint32_t reset_param =
3842 keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
3844 /* Report UNLOAD_DONE to MCP */
3845 if (!BXE_NOMCP(sc)) {
3846 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
3851 bxe_func_wait_started(struct bxe_softc *sc)
3855 if (!sc->port.pmf) {
3860 * (assumption: No Attention from MCP at this stage)
3861 * PMF probably in the middle of TX disable/enable transaction
3862 * 1. Sync IRS for default SB
3863 * 2. Sync SP queue - this guarantees us that attention handling started
3864 * 3. Wait, that TX disable/enable transaction completes
3866 * 1+2 guarantee that if DCBX attention was scheduled it already changed
3867 * pending bit of transaction from STARTED-->TX_STOPPED, if we already
3868 * received completion for the transaction the state is TX_STOPPED.
3869 * State will return to STARTED after completion of TX_STOPPED-->STARTED
3873 /* XXX make sure default SB ISR is done */
3874 /* need a way to synchronize an irq (intr_mtx?) */
3876 /* XXX flush any work queues */
3878 while (ecore_func_get_state(sc, &sc->func_obj) !=
3879 ECORE_F_STATE_STARTED && tout--) {
3883 if (ecore_func_get_state(sc, &sc->func_obj) != ECORE_F_STATE_STARTED) {
3885 * Failed to complete the transaction in a "good way"
3886 * Force both transactions with CLR bit.
3888 struct ecore_func_state_params func_params = { NULL };
3890 BLOGE(sc, "Unexpected function state! "
3891 "Forcing STARTED-->TX_STOPPED-->STARTED\n");
3893 func_params.f_obj = &sc->func_obj;
3894 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
3896 /* STARTED-->TX_STOPPED */
3897 func_params.cmd = ECORE_F_CMD_TX_STOP;
3898 ecore_func_state_change(sc, &func_params);
3900 /* TX_STOPPED-->STARTED */
3901 func_params.cmd = ECORE_F_CMD_TX_START;
3902 return (ecore_func_state_change(sc, &func_params));
3909 bxe_stop_queue(struct bxe_softc *sc,
3912 struct bxe_fastpath *fp = &sc->fp[index];
3913 struct ecore_queue_state_params q_params = { NULL };
3916 BLOGD(sc, DBG_LOAD, "stopping queue %d cid %d\n", index, fp->index);
3918 q_params.q_obj = &sc->sp_objs[fp->index].q_obj;
3919 /* We want to wait for completion in this context */
3920 bxe_set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
3922 /* Stop the primary connection: */
3924 /* ...halt the connection */
3925 q_params.cmd = ECORE_Q_CMD_HALT;
3926 rc = ecore_queue_state_change(sc, &q_params);
3931 /* ...terminate the connection */
3932 q_params.cmd = ECORE_Q_CMD_TERMINATE;
3933 memset(&q_params.params.terminate, 0, sizeof(q_params.params.terminate));
3934 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
3935 rc = ecore_queue_state_change(sc, &q_params);
3940 /* ...delete cfc entry */
3941 q_params.cmd = ECORE_Q_CMD_CFC_DEL;
3942 memset(&q_params.params.cfc_del, 0, sizeof(q_params.params.cfc_del));
3943 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
3944 return (ecore_queue_state_change(sc, &q_params));
3947 /* wait for the outstanding SP commands */
3948 static inline uint8_t
3949 bxe_wait_sp_comp(struct bxe_softc *sc,
3953 int tout = 5000; /* wait for 5 secs tops */
3957 if (!(atomic_load_acq_long(&sc->sp_state) & mask)) {
3966 tmp = atomic_load_acq_long(&sc->sp_state);
3968 BLOGE(sc, "Filtering completion timed out: "
3969 "sp_state 0x%lx, mask 0x%lx\n",
3978 bxe_func_stop(struct bxe_softc *sc)
3980 struct ecore_func_state_params func_params = { NULL };
3983 /* prepare parameters for function state transitions */
3984 bxe_set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
3985 func_params.f_obj = &sc->func_obj;
3986 func_params.cmd = ECORE_F_CMD_STOP;
3989 * Try to stop the function the 'good way'. If it fails (in case
3990 * of a parity error during bxe_chip_cleanup()) and we are
3991 * not in a debug mode, perform a state transaction in order to
3992 * enable further HW_RESET transaction.
3994 rc = ecore_func_state_change(sc, &func_params);
3996 BLOGE(sc, "FUNC_STOP ramrod failed. "
3997 "Running a dry transaction (%d)\n", rc);
3998 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
3999 return (ecore_func_state_change(sc, &func_params));
4006 bxe_reset_hw(struct bxe_softc *sc,
4009 struct ecore_func_state_params func_params = { NULL };
4011 /* Prepare parameters for function state transitions */
4012 bxe_set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
4014 func_params.f_obj = &sc->func_obj;
4015 func_params.cmd = ECORE_F_CMD_HW_RESET;
4017 func_params.params.hw_init.load_phase = load_code;
4019 return (ecore_func_state_change(sc, &func_params));
4023 bxe_int_disable_sync(struct bxe_softc *sc,
4027 /* prevent the HW from sending interrupts */
4028 bxe_int_disable(sc);
4031 /* XXX need a way to synchronize ALL irqs (intr_mtx?) */
4032 /* make sure all ISRs are done */
4034 /* XXX make sure sp_task is not running */
4035 /* cancel and flush work queues */
4039 bxe_chip_cleanup(struct bxe_softc *sc,
4040 uint32_t unload_mode,
4043 int port = SC_PORT(sc);
4044 struct ecore_mcast_ramrod_params rparam = { NULL };
4045 uint32_t reset_code;
4048 bxe_drain_tx_queues(sc);
4050 /* give HW time to discard old tx messages */
4053 /* Clean all ETH MACs */
4054 rc = bxe_del_all_macs(sc, &sc->sp_objs[0].mac_obj, ECORE_ETH_MAC, FALSE);
4056 BLOGE(sc, "Failed to delete all ETH MACs (%d)\n", rc);
4059 /* Clean up UC list */
4060 rc = bxe_del_all_macs(sc, &sc->sp_objs[0].mac_obj, ECORE_UC_LIST_MAC, TRUE);
4062 BLOGE(sc, "Failed to delete UC MACs list (%d)\n", rc);
4066 if (!CHIP_IS_E1(sc)) {
4067 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 0);
4070 /* Set "drop all" to stop Rx */
4073 * We need to take the BXE_MCAST_LOCK() here in order to prevent
4074 * a race between the completion code and this code.
4078 if (bxe_test_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state)) {
4079 bxe_set_bit(ECORE_FILTER_RX_MODE_SCHED, &sc->sp_state);
4081 bxe_set_storm_rx_mode(sc);
4084 /* Clean up multicast configuration */
4085 rparam.mcast_obj = &sc->mcast_obj;
4086 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL);
4088 BLOGE(sc, "Failed to send DEL MCAST command (%d)\n", rc);
4091 BXE_MCAST_UNLOCK(sc);
4093 // XXX bxe_iov_chip_cleanup(sc);
4096 * Send the UNLOAD_REQUEST to the MCP. This will return if
4097 * this function should perform FUNCTION, PORT, or COMMON HW
4100 reset_code = bxe_send_unload_req(sc, unload_mode);
4103 * (assumption: No Attention from MCP at this stage)
4104 * PMF probably in the middle of TX disable/enable transaction
4106 rc = bxe_func_wait_started(sc);
4108 BLOGE(sc, "bxe_func_wait_started failed (%d)\n", rc);
4112 * Close multi and leading connections
4113 * Completions for ramrods are collected in a synchronous way
4115 for (i = 0; i < sc->num_queues; i++) {
4116 if (bxe_stop_queue(sc, i)) {
4122 * If SP settings didn't get completed so far - something
4123 * very wrong has happen.
4125 if (!bxe_wait_sp_comp(sc, ~0x0UL)) {
4126 BLOGE(sc, "Common slow path ramrods got stuck!(%d)\n", rc);
4131 rc = bxe_func_stop(sc);
4133 BLOGE(sc, "Function stop failed!(%d)\n", rc);
4136 /* disable HW interrupts */
4137 bxe_int_disable_sync(sc, TRUE);
4139 /* detach interrupts */
4140 bxe_interrupt_detach(sc);
4142 /* Reset the chip */
4143 rc = bxe_reset_hw(sc, reset_code);
4145 BLOGE(sc, "Hardware reset failed(%d)\n", rc);
4148 /* Report UNLOAD_DONE to MCP */
4149 bxe_send_unload_done(sc, keep_link);
4153 bxe_disable_close_the_gate(struct bxe_softc *sc)
4156 int port = SC_PORT(sc);
4159 "Disabling 'close the gates'\n");
4161 if (CHIP_IS_E1(sc)) {
4162 uint32_t addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4163 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4164 val = REG_RD(sc, addr);
4166 REG_WR(sc, addr, val);
4168 val = REG_RD(sc, MISC_REG_AEU_GENERAL_MASK);
4169 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
4170 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
4171 REG_WR(sc, MISC_REG_AEU_GENERAL_MASK, val);
4176 * Cleans the object that have internal lists without sending
4177 * ramrods. Should be run when interrutps are disabled.
4180 bxe_squeeze_objects(struct bxe_softc *sc)
4182 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
4183 struct ecore_mcast_ramrod_params rparam = { NULL };
4184 struct ecore_vlan_mac_obj *mac_obj = &sc->sp_objs->mac_obj;
4187 /* Cleanup MACs' object first... */
4189 /* Wait for completion of requested */
4190 bxe_set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
4191 /* Perform a dry cleanup */
4192 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &ramrod_flags);
4194 /* Clean ETH primary MAC */
4195 bxe_set_bit(ECORE_ETH_MAC, &vlan_mac_flags);
4196 rc = mac_obj->delete_all(sc, &sc->sp_objs->mac_obj, &vlan_mac_flags,
4199 BLOGE(sc, "Failed to clean ETH MACs (%d)\n", rc);
4202 /* Cleanup UC list */
4204 bxe_set_bit(ECORE_UC_LIST_MAC, &vlan_mac_flags);
4205 rc = mac_obj->delete_all(sc, mac_obj, &vlan_mac_flags,
4208 BLOGE(sc, "Failed to clean UC list MACs (%d)\n", rc);
4211 /* Now clean mcast object... */
4213 rparam.mcast_obj = &sc->mcast_obj;
4214 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &rparam.ramrod_flags);
4216 /* Add a DEL command... */
4217 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL);
4219 BLOGE(sc, "Failed to send DEL MCAST command (%d)\n", rc);
4222 /* now wait until all pending commands are cleared */
4224 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT);
4227 BLOGE(sc, "Failed to clean MCAST object (%d)\n", rc);
4231 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT);
4235 /* stop the controller */
4236 static __noinline int
4237 bxe_nic_unload(struct bxe_softc *sc,
4238 uint32_t unload_mode,
4241 uint8_t global = FALSE;
4245 BXE_CORE_LOCK_ASSERT(sc);
4247 sc->ifnet->if_drv_flags &= ~IFF_DRV_RUNNING;
4249 for (i = 0; i < sc->num_queues; i++) {
4250 struct bxe_fastpath *fp;
4254 BXE_FP_TX_UNLOCK(fp);
4257 BLOGD(sc, DBG_LOAD, "Starting NIC unload...\n");
4259 /* mark driver as unloaded in shmem2 */
4260 if (IS_PF(sc) && SHMEM2_HAS(sc, drv_capabilities_flag)) {
4261 val = SHMEM2_RD(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)]);
4262 SHMEM2_WR(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)],
4263 val & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
4266 if (IS_PF(sc) && sc->recovery_state != BXE_RECOVERY_DONE &&
4267 (sc->state == BXE_STATE_CLOSED || sc->state == BXE_STATE_ERROR)) {
4269 * We can get here if the driver has been unloaded
4270 * during parity error recovery and is either waiting for a
4271 * leader to complete or for other functions to unload and
4272 * then ifconfig down has been issued. In this case we want to
4273 * unload and let other functions to complete a recovery
4276 sc->recovery_state = BXE_RECOVERY_DONE;
4278 bxe_release_leader_lock(sc);
4281 BLOGD(sc, DBG_LOAD, "Releasing a leadership...\n");
4282 BLOGE(sc, "Can't unload in closed or error state recover_state 0x%x"
4283 " state = 0x%x\n", sc->recovery_state, sc->state);
4288 * Nothing to do during unload if previous bxe_nic_load()
4289 * did not completed succesfully - all resourses are released.
4291 if ((sc->state == BXE_STATE_CLOSED) ||
4292 (sc->state == BXE_STATE_ERROR)) {
4296 sc->state = BXE_STATE_CLOSING_WAITING_HALT;
4302 sc->rx_mode = BXE_RX_MODE_NONE;
4303 /* XXX set rx mode ??? */
4305 if (IS_PF(sc) && !sc->grcdump_done) {
4306 /* set ALWAYS_ALIVE bit in shmem */
4307 sc->fw_drv_pulse_wr_seq |= DRV_PULSE_ALWAYS_ALIVE;
4311 bxe_stats_handle(sc, STATS_EVENT_STOP);
4312 bxe_save_statistics(sc);
4315 /* wait till consumers catch up with producers in all queues */
4316 bxe_drain_tx_queues(sc);
4318 /* if VF indicate to PF this function is going down (PF will delete sp
4319 * elements and clear initializations
4322 ; /* bxe_vfpf_close_vf(sc); */
4323 } else if (unload_mode != UNLOAD_RECOVERY) {
4324 /* if this is a normal/close unload need to clean up chip */
4325 if (!sc->grcdump_done)
4326 bxe_chip_cleanup(sc, unload_mode, keep_link);
4328 /* Send the UNLOAD_REQUEST to the MCP */
4329 bxe_send_unload_req(sc, unload_mode);
4332 * Prevent transactions to host from the functions on the
4333 * engine that doesn't reset global blocks in case of global
4334 * attention once gloabl blocks are reset and gates are opened
4335 * (the engine which leader will perform the recovery
4338 if (!CHIP_IS_E1x(sc)) {
4342 /* disable HW interrupts */
4343 bxe_int_disable_sync(sc, TRUE);
4345 /* detach interrupts */
4346 bxe_interrupt_detach(sc);
4348 /* Report UNLOAD_DONE to MCP */
4349 bxe_send_unload_done(sc, FALSE);
4353 * At this stage no more interrupts will arrive so we may safely clean
4354 * the queue'able objects here in case they failed to get cleaned so far.
4357 bxe_squeeze_objects(sc);
4360 /* There should be no more pending SP commands at this stage */
4365 bxe_free_fp_buffers(sc);
4371 bxe_free_fw_stats_mem(sc);
4373 sc->state = BXE_STATE_CLOSED;
4376 * Check if there are pending parity attentions. If there are - set
4377 * RECOVERY_IN_PROGRESS.
4379 if (IS_PF(sc) && bxe_chk_parity_attn(sc, &global, FALSE)) {
4380 bxe_set_reset_in_progress(sc);
4382 /* Set RESET_IS_GLOBAL if needed */
4384 bxe_set_reset_global(sc);
4389 * The last driver must disable a "close the gate" if there is no
4390 * parity attention or "process kill" pending.
4392 if (IS_PF(sc) && !bxe_clear_pf_load(sc) &&
4393 bxe_reset_is_done(sc, SC_PATH(sc))) {
4394 bxe_disable_close_the_gate(sc);
4397 BLOGD(sc, DBG_LOAD, "Ended NIC unload\n");
4403 * Called by the OS to set various media options (i.e. link, speed, etc.) when
4404 * the user runs "ifconfig bxe media ..." or "ifconfig bxe mediaopt ...".
4407 bxe_ifmedia_update(struct ifnet *ifp)
4409 struct bxe_softc *sc = (struct bxe_softc *)ifp->if_softc;
4410 struct ifmedia *ifm;
4414 /* We only support Ethernet media type. */
4415 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) {
4419 switch (IFM_SUBTYPE(ifm->ifm_media)) {
4425 case IFM_10G_TWINAX:
4427 /* We don't support changing the media type. */
4428 BLOGD(sc, DBG_LOAD, "Invalid media type (%d)\n",
4429 IFM_SUBTYPE(ifm->ifm_media));
4437 * Called by the OS to get the current media status (i.e. link, speed, etc.).
4440 bxe_ifmedia_status(struct ifnet *ifp, struct ifmediareq *ifmr)
4442 struct bxe_softc *sc = ifp->if_softc;
4444 /* Report link down if the driver isn't running. */
4445 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
4446 ifmr->ifm_active |= IFM_NONE;
4450 /* Setup the default interface info. */
4451 ifmr->ifm_status = IFM_AVALID;
4452 ifmr->ifm_active = IFM_ETHER;
4454 if (sc->link_vars.link_up) {
4455 ifmr->ifm_status |= IFM_ACTIVE;
4457 ifmr->ifm_active |= IFM_NONE;
4461 ifmr->ifm_active |= sc->media;
4463 if (sc->link_vars.duplex == DUPLEX_FULL) {
4464 ifmr->ifm_active |= IFM_FDX;
4466 ifmr->ifm_active |= IFM_HDX;
4471 bxe_handle_chip_tq(void *context,
4474 struct bxe_softc *sc = (struct bxe_softc *)context;
4475 long work = atomic_load_acq_long(&sc->chip_tq_flags);
4479 case CHIP_TQ_REINIT:
4480 if (sc->ifnet->if_drv_flags & IFF_DRV_RUNNING) {
4481 /* restart the interface */
4482 BLOGD(sc, DBG_LOAD, "Restarting the interface...\n");
4483 bxe_periodic_stop(sc);
4485 bxe_stop_locked(sc);
4486 bxe_init_locked(sc);
4487 BXE_CORE_UNLOCK(sc);
4497 * Handles any IOCTL calls from the operating system.
4500 * 0 = Success, >0 Failure
4503 bxe_ioctl(struct ifnet *ifp,
4507 struct bxe_softc *sc = ifp->if_softc;
4508 struct ifreq *ifr = (struct ifreq *)data;
4513 int mtu_min = (ETH_MIN_PACKET_SIZE - ETH_HLEN);
4514 int mtu_max = (MJUM9BYTES - ETH_OVERHEAD - IP_HEADER_ALIGNMENT_PADDING);
4519 BLOGD(sc, DBG_IOCTL, "Received SIOCSIFMTU ioctl (mtu=%d)\n",
4522 if (sc->mtu == ifr->ifr_mtu) {
4523 /* nothing to change */
4527 if ((ifr->ifr_mtu < mtu_min) || (ifr->ifr_mtu > mtu_max)) {
4528 BLOGE(sc, "Unsupported MTU size %d (range is %d-%d)\n",
4529 ifr->ifr_mtu, mtu_min, mtu_max);
4534 atomic_store_rel_int((volatile unsigned int *)&sc->mtu,
4535 (unsigned long)ifr->ifr_mtu);
4536 atomic_store_rel_long((volatile unsigned long *)&ifp->if_mtu,
4537 (unsigned long)ifr->ifr_mtu);
4543 /* toggle the interface state up or down */
4544 BLOGD(sc, DBG_IOCTL, "Received SIOCSIFFLAGS ioctl\n");
4547 /* check if the interface is up */
4548 if (ifp->if_flags & IFF_UP) {
4549 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
4550 /* set the receive mode flags */
4551 bxe_set_rx_mode(sc);
4552 } else if(sc->state != BXE_STATE_DISABLED) {
4553 bxe_init_locked(sc);
4556 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
4557 bxe_periodic_stop(sc);
4558 bxe_stop_locked(sc);
4561 BXE_CORE_UNLOCK(sc);
4567 /* add/delete multicast addresses */
4568 BLOGD(sc, DBG_IOCTL, "Received SIOCADDMULTI/SIOCDELMULTI ioctl\n");
4570 /* check if the interface is up */
4571 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
4572 /* set the receive mode flags */
4574 bxe_set_rx_mode(sc);
4575 BXE_CORE_UNLOCK(sc);
4581 /* find out which capabilities have changed */
4582 mask = (ifr->ifr_reqcap ^ ifp->if_capenable);
4584 BLOGD(sc, DBG_IOCTL, "Received SIOCSIFCAP ioctl (mask=0x%08x)\n",
4587 /* toggle the LRO capabilites enable flag */
4588 if (mask & IFCAP_LRO) {
4589 ifp->if_capenable ^= IFCAP_LRO;
4590 BLOGD(sc, DBG_IOCTL, "Turning LRO %s\n",
4591 (ifp->if_capenable & IFCAP_LRO) ? "ON" : "OFF");
4595 /* toggle the TXCSUM checksum capabilites enable flag */
4596 if (mask & IFCAP_TXCSUM) {
4597 ifp->if_capenable ^= IFCAP_TXCSUM;
4598 BLOGD(sc, DBG_IOCTL, "Turning TXCSUM %s\n",
4599 (ifp->if_capenable & IFCAP_TXCSUM) ? "ON" : "OFF");
4600 if (ifp->if_capenable & IFCAP_TXCSUM) {
4601 ifp->if_hwassist = (CSUM_IP |
4608 ifp->if_hwassist = 0;
4612 /* toggle the RXCSUM checksum capabilities enable flag */
4613 if (mask & IFCAP_RXCSUM) {
4614 ifp->if_capenable ^= IFCAP_RXCSUM;
4615 BLOGD(sc, DBG_IOCTL, "Turning RXCSUM %s\n",
4616 (ifp->if_capenable & IFCAP_RXCSUM) ? "ON" : "OFF");
4617 if (ifp->if_capenable & IFCAP_RXCSUM) {
4618 ifp->if_hwassist = (CSUM_IP |
4625 ifp->if_hwassist = 0;
4629 /* toggle TSO4 capabilities enabled flag */
4630 if (mask & IFCAP_TSO4) {
4631 ifp->if_capenable ^= IFCAP_TSO4;
4632 BLOGD(sc, DBG_IOCTL, "Turning TSO4 %s\n",
4633 (ifp->if_capenable & IFCAP_TSO4) ? "ON" : "OFF");
4636 /* toggle TSO6 capabilities enabled flag */
4637 if (mask & IFCAP_TSO6) {
4638 ifp->if_capenable ^= IFCAP_TSO6;
4639 BLOGD(sc, DBG_IOCTL, "Turning TSO6 %s\n",
4640 (ifp->if_capenable & IFCAP_TSO6) ? "ON" : "OFF");
4643 /* toggle VLAN_HWTSO capabilities enabled flag */
4644 if (mask & IFCAP_VLAN_HWTSO) {
4645 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
4646 BLOGD(sc, DBG_IOCTL, "Turning VLAN_HWTSO %s\n",
4647 (ifp->if_capenable & IFCAP_VLAN_HWTSO) ? "ON" : "OFF");
4650 /* toggle VLAN_HWCSUM capabilities enabled flag */
4651 if (mask & IFCAP_VLAN_HWCSUM) {
4652 /* XXX investigate this... */
4653 BLOGE(sc, "Changing VLAN_HWCSUM is not supported!\n");
4657 /* toggle VLAN_MTU capabilities enable flag */
4658 if (mask & IFCAP_VLAN_MTU) {
4659 /* XXX investigate this... */
4660 BLOGE(sc, "Changing VLAN_MTU is not supported!\n");
4664 /* toggle VLAN_HWTAGGING capabilities enabled flag */
4665 if (mask & IFCAP_VLAN_HWTAGGING) {
4666 /* XXX investigate this... */
4667 BLOGE(sc, "Changing VLAN_HWTAGGING is not supported!\n");
4671 /* toggle VLAN_HWFILTER capabilities enabled flag */
4672 if (mask & IFCAP_VLAN_HWFILTER) {
4673 /* XXX investigate this... */
4674 BLOGE(sc, "Changing VLAN_HWFILTER is not supported!\n");
4686 /* set/get interface media */
4687 BLOGD(sc, DBG_IOCTL,
4688 "Received SIOCSIFMEDIA/SIOCGIFMEDIA ioctl (cmd=%lu)\n",
4690 error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, command);
4694 BLOGD(sc, DBG_IOCTL, "Received Unknown Ioctl (cmd=%lu)\n",
4696 error = ether_ioctl(ifp, command, data);
4700 if (reinit && (sc->ifnet->if_drv_flags & IFF_DRV_RUNNING)) {
4701 BLOGD(sc, DBG_LOAD | DBG_IOCTL,
4702 "Re-initializing hardware from IOCTL change\n");
4703 bxe_periodic_stop(sc);
4705 bxe_stop_locked(sc);
4706 bxe_init_locked(sc);
4707 BXE_CORE_UNLOCK(sc);
4713 static __noinline void
4714 bxe_dump_mbuf(struct bxe_softc *sc,
4721 if (!(sc->debug & DBG_MBUF)) {
4726 BLOGD(sc, DBG_MBUF, "mbuf: null pointer\n");
4732 #if __FreeBSD_version >= 1000000
4734 "%02d: mbuf=%p m_len=%d m_flags=0x%b m_data=%p\n",
4735 i, m, m->m_len, m->m_flags, M_FLAG_BITS, m->m_data);
4737 if (m->m_flags & M_PKTHDR) {
4739 "%02d: - m_pkthdr: tot_len=%d flags=0x%b csum_flags=%b\n",
4740 i, m->m_pkthdr.len, m->m_flags, M_FLAG_BITS,
4741 (int)m->m_pkthdr.csum_flags, CSUM_BITS);
4745 "%02d: mbuf=%p m_len=%d m_flags=0x%b m_data=%p\n",
4746 i, m, m->m_len, m->m_flags,
4747 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY", m->m_data);
4749 if (m->m_flags & M_PKTHDR) {
4751 "%02d: - m_pkthdr: tot_len=%d flags=0x%b csum_flags=%b\n",
4752 i, m->m_pkthdr.len, m->m_flags,
4753 "\20\12M_BCAST\13M_MCAST\14M_FRAG"
4754 "\15M_FIRSTFRAG\16M_LASTFRAG\21M_VLANTAG"
4755 "\22M_PROMISC\23M_NOFREE",
4756 (int)m->m_pkthdr.csum_flags,
4757 "\20\1CSUM_IP\2CSUM_TCP\3CSUM_UDP\4CSUM_IP_FRAGS"
4758 "\5CSUM_FRAGMENT\6CSUM_TSO\11CSUM_IP_CHECKED"
4759 "\12CSUM_IP_VALID\13CSUM_DATA_VALID"
4760 "\14CSUM_PSEUDO_HDR");
4762 #endif /* #if __FreeBSD_version >= 1000000 */
4764 if (m->m_flags & M_EXT) {
4765 switch (m->m_ext.ext_type) {
4766 case EXT_CLUSTER: type = "EXT_CLUSTER"; break;
4767 case EXT_SFBUF: type = "EXT_SFBUF"; break;
4768 case EXT_JUMBOP: type = "EXT_JUMBOP"; break;
4769 case EXT_JUMBO9: type = "EXT_JUMBO9"; break;
4770 case EXT_JUMBO16: type = "EXT_JUMBO16"; break;
4771 case EXT_PACKET: type = "EXT_PACKET"; break;
4772 case EXT_MBUF: type = "EXT_MBUF"; break;
4773 case EXT_NET_DRV: type = "EXT_NET_DRV"; break;
4774 case EXT_MOD_TYPE: type = "EXT_MOD_TYPE"; break;
4775 case EXT_DISPOSABLE: type = "EXT_DISPOSABLE"; break;
4776 case EXT_EXTREF: type = "EXT_EXTREF"; break;
4777 default: type = "UNKNOWN"; break;
4781 "%02d: - m_ext: %p ext_size=%d type=%s\n",
4782 i, m->m_ext.ext_buf, m->m_ext.ext_size, type);
4786 bxe_dump_mbuf_data(sc, "mbuf data", m, TRUE);
4795 * Checks to ensure the 13 bd sliding window is >= MSS for TSO.
4796 * Check that (13 total bds - 3 bds) = 10 bd window >= MSS.
4797 * The window: 3 bds are = 1 for headers BD + 2 for parse BD and last BD
4798 * The headers comes in a seperate bd in FreeBSD so 13-3=10.
4799 * Returns: 0 if OK to send, 1 if packet needs further defragmentation
4802 bxe_chktso_window(struct bxe_softc *sc,
4804 bus_dma_segment_t *segs,
4807 uint32_t num_wnds, wnd_size, wnd_sum;
4808 int32_t frag_idx, wnd_idx;
4809 unsigned short lso_mss;
4815 num_wnds = nsegs - wnd_size;
4816 lso_mss = htole16(m->m_pkthdr.tso_segsz);
4819 * Total header lengths Eth+IP+TCP in first FreeBSD mbuf so calculate the
4820 * first window sum of data while skipping the first assuming it is the
4821 * header in FreeBSD.
4823 for (frag_idx = 1; (frag_idx <= wnd_size); frag_idx++) {
4824 wnd_sum += htole16(segs[frag_idx].ds_len);
4827 /* check the first 10 bd window size */
4828 if (wnd_sum < lso_mss) {
4832 /* run through the windows */
4833 for (wnd_idx = 0; wnd_idx < num_wnds; wnd_idx++, frag_idx++) {
4834 /* subtract the first mbuf->m_len of the last wndw(-header) */
4835 wnd_sum -= htole16(segs[wnd_idx+1].ds_len);
4836 /* add the next mbuf len to the len of our new window */
4837 wnd_sum += htole16(segs[frag_idx].ds_len);
4838 if (wnd_sum < lso_mss) {
4847 bxe_set_pbd_csum_e2(struct bxe_fastpath *fp,
4849 uint32_t *parsing_data)
4851 struct ether_vlan_header *eh = NULL;
4852 struct ip *ip4 = NULL;
4853 struct ip6_hdr *ip6 = NULL;
4855 struct tcphdr *th = NULL;
4856 int e_hlen, ip_hlen, l4_off;
4859 if (m->m_pkthdr.csum_flags == CSUM_IP) {
4860 /* no L4 checksum offload needed */
4864 /* get the Ethernet header */
4865 eh = mtod(m, struct ether_vlan_header *);
4867 /* handle VLAN encapsulation if present */
4868 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
4869 e_hlen = (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN);
4870 proto = ntohs(eh->evl_proto);
4872 e_hlen = ETHER_HDR_LEN;
4873 proto = ntohs(eh->evl_encap_proto);
4878 /* get the IP header, if mbuf len < 20 then header in next mbuf */
4879 ip4 = (m->m_len < sizeof(struct ip)) ?
4880 (struct ip *)m->m_next->m_data :
4881 (struct ip *)(m->m_data + e_hlen);
4882 /* ip_hl is number of 32-bit words */
4883 ip_hlen = (ip4->ip_hl << 2);
4886 case ETHERTYPE_IPV6:
4887 /* get the IPv6 header, if mbuf len < 40 then header in next mbuf */
4888 ip6 = (m->m_len < sizeof(struct ip6_hdr)) ?
4889 (struct ip6_hdr *)m->m_next->m_data :
4890 (struct ip6_hdr *)(m->m_data + e_hlen);
4891 /* XXX cannot support offload with IPv6 extensions */
4892 ip_hlen = sizeof(struct ip6_hdr);
4896 /* We can't offload in this case... */
4897 /* XXX error stat ??? */
4901 /* XXX assuming L4 header is contiguous to IPv4/IPv6 in the same mbuf */
4902 l4_off = (e_hlen + ip_hlen);
4905 (((l4_off >> 1) << ETH_TX_PARSE_BD_E2_L4_HDR_START_OFFSET_W_SHIFT) &
4906 ETH_TX_PARSE_BD_E2_L4_HDR_START_OFFSET_W);
4908 if (m->m_pkthdr.csum_flags & (CSUM_TCP |
4911 fp->eth_q_stats.tx_ofld_frames_csum_tcp++;
4912 th = (struct tcphdr *)(ip + ip_hlen);
4913 /* th_off is number of 32-bit words */
4914 *parsing_data |= ((th->th_off <<
4915 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW_SHIFT) &
4916 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW);
4917 return (l4_off + (th->th_off << 2)); /* entire header length */
4918 } else if (m->m_pkthdr.csum_flags & (CSUM_UDP |
4920 fp->eth_q_stats.tx_ofld_frames_csum_udp++;
4921 return (l4_off + sizeof(struct udphdr)); /* entire header length */
4923 /* XXX error stat ??? */
4929 bxe_set_pbd_csum(struct bxe_fastpath *fp,
4931 struct eth_tx_parse_bd_e1x *pbd)
4933 struct ether_vlan_header *eh = NULL;
4934 struct ip *ip4 = NULL;
4935 struct ip6_hdr *ip6 = NULL;
4937 struct tcphdr *th = NULL;
4938 struct udphdr *uh = NULL;
4939 int e_hlen, ip_hlen;
4945 /* get the Ethernet header */
4946 eh = mtod(m, struct ether_vlan_header *);
4948 /* handle VLAN encapsulation if present */
4949 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
4950 e_hlen = (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN);
4951 proto = ntohs(eh->evl_proto);
4953 e_hlen = ETHER_HDR_LEN;
4954 proto = ntohs(eh->evl_encap_proto);
4959 /* get the IP header, if mbuf len < 20 then header in next mbuf */
4960 ip4 = (m->m_len < sizeof(struct ip)) ?
4961 (struct ip *)m->m_next->m_data :
4962 (struct ip *)(m->m_data + e_hlen);
4963 /* ip_hl is number of 32-bit words */
4964 ip_hlen = (ip4->ip_hl << 1);
4967 case ETHERTYPE_IPV6:
4968 /* get the IPv6 header, if mbuf len < 40 then header in next mbuf */
4969 ip6 = (m->m_len < sizeof(struct ip6_hdr)) ?
4970 (struct ip6_hdr *)m->m_next->m_data :
4971 (struct ip6_hdr *)(m->m_data + e_hlen);
4972 /* XXX cannot support offload with IPv6 extensions */
4973 ip_hlen = (sizeof(struct ip6_hdr) >> 1);
4977 /* We can't offload in this case... */
4978 /* XXX error stat ??? */
4982 hlen = (e_hlen >> 1);
4984 /* note that rest of global_data is indirectly zeroed here */
4985 if (m->m_flags & M_VLANTAG) {
4987 htole16(hlen | (1 << ETH_TX_PARSE_BD_E1X_LLC_SNAP_EN_SHIFT));
4989 pbd->global_data = htole16(hlen);
4992 pbd->ip_hlen_w = ip_hlen;
4994 hlen += pbd->ip_hlen_w;
4996 /* XXX assuming L4 header is contiguous to IPv4/IPv6 in the same mbuf */
4998 if (m->m_pkthdr.csum_flags & (CSUM_TCP |
5001 th = (struct tcphdr *)(ip + (ip_hlen << 1));
5002 /* th_off is number of 32-bit words */
5003 hlen += (uint16_t)(th->th_off << 1);
5004 } else if (m->m_pkthdr.csum_flags & (CSUM_UDP |
5006 uh = (struct udphdr *)(ip + (ip_hlen << 1));
5007 hlen += (sizeof(struct udphdr) / 2);
5009 /* valid case as only CSUM_IP was set */
5013 pbd->total_hlen_w = htole16(hlen);
5015 if (m->m_pkthdr.csum_flags & (CSUM_TCP |
5018 fp->eth_q_stats.tx_ofld_frames_csum_tcp++;
5019 pbd->tcp_pseudo_csum = ntohs(th->th_sum);
5020 } else if (m->m_pkthdr.csum_flags & (CSUM_UDP |
5022 fp->eth_q_stats.tx_ofld_frames_csum_udp++;
5025 * Everest1 (i.e. 57710, 57711, 57711E) does not natively support UDP
5026 * checksums and does not know anything about the UDP header and where
5027 * the checksum field is located. It only knows about TCP. Therefore
5028 * we "lie" to the hardware for outgoing UDP packets w/ checksum
5029 * offload. Since the checksum field offset for TCP is 16 bytes and
5030 * for UDP it is 6 bytes we pass a pointer to the hardware that is 10
5031 * bytes less than the start of the UDP header. This allows the
5032 * hardware to write the checksum in the correct spot. But the
5033 * hardware will compute a checksum which includes the last 10 bytes
5034 * of the IP header. To correct this we tweak the stack computed
5035 * pseudo checksum by folding in the calculation of the inverse
5036 * checksum for those final 10 bytes of the IP header. This allows
5037 * the correct checksum to be computed by the hardware.
5040 /* set pointer 10 bytes before UDP header */
5041 tmp_uh = (uint32_t *)((uint8_t *)uh - 10);
5043 /* calculate a pseudo header checksum over the first 10 bytes */
5044 tmp_csum = in_pseudo(*tmp_uh,
5046 *(uint16_t *)(tmp_uh + 2));
5048 pbd->tcp_pseudo_csum = ntohs(in_addword(uh->uh_sum, ~tmp_csum));
5051 return (hlen * 2); /* entire header length, number of bytes */
5055 bxe_set_pbd_lso_e2(struct mbuf *m,
5056 uint32_t *parsing_data)
5058 *parsing_data |= ((m->m_pkthdr.tso_segsz <<
5059 ETH_TX_PARSE_BD_E2_LSO_MSS_SHIFT) &
5060 ETH_TX_PARSE_BD_E2_LSO_MSS);
5062 /* XXX test for IPv6 with extension header... */
5066 bxe_set_pbd_lso(struct mbuf *m,
5067 struct eth_tx_parse_bd_e1x *pbd)
5069 struct ether_vlan_header *eh = NULL;
5070 struct ip *ip = NULL;
5071 struct tcphdr *th = NULL;
5074 /* get the Ethernet header */
5075 eh = mtod(m, struct ether_vlan_header *);
5077 /* handle VLAN encapsulation if present */
5078 e_hlen = (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) ?
5079 (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN) : ETHER_HDR_LEN;
5081 /* get the IP and TCP header, with LSO entire header in first mbuf */
5082 /* XXX assuming IPv4 */
5083 ip = (struct ip *)(m->m_data + e_hlen);
5084 th = (struct tcphdr *)((caddr_t)ip + (ip->ip_hl << 2));
5086 pbd->lso_mss = htole16(m->m_pkthdr.tso_segsz);
5087 pbd->tcp_send_seq = ntohl(th->th_seq);
5088 pbd->tcp_flags = ((ntohl(((uint32_t *)th)[3]) >> 16) & 0xff);
5092 pbd->ip_id = ntohs(ip->ip_id);
5093 pbd->tcp_pseudo_csum =
5094 ntohs(in_pseudo(ip->ip_src.s_addr,
5096 htons(IPPROTO_TCP)));
5099 pbd->tcp_pseudo_csum =
5100 ntohs(in_pseudo(&ip6->ip6_src,
5102 htons(IPPROTO_TCP)));
5106 htole16(ETH_TX_PARSE_BD_E1X_PSEUDO_CS_WITHOUT_LEN);
5110 * Encapsulte an mbuf cluster into the tx bd chain and makes the memory
5111 * visible to the controller.
5113 * If an mbuf is submitted to this routine and cannot be given to the
5114 * controller (e.g. it has too many fragments) then the function may free
5115 * the mbuf and return to the caller.
5118 * 0 = Success, !0 = Failure
5119 * Note the side effect that an mbuf may be freed if it causes a problem.
5122 bxe_tx_encap(struct bxe_fastpath *fp, struct mbuf **m_head)
5124 bus_dma_segment_t segs[32];
5126 struct bxe_sw_tx_bd *tx_buf;
5127 struct eth_tx_parse_bd_e1x *pbd_e1x = NULL;
5128 struct eth_tx_parse_bd_e2 *pbd_e2 = NULL;
5129 /* struct eth_tx_parse_2nd_bd *pbd2 = NULL; */
5130 struct eth_tx_bd *tx_data_bd;
5131 struct eth_tx_bd *tx_total_pkt_size_bd;
5132 struct eth_tx_start_bd *tx_start_bd;
5133 uint16_t bd_prod, pkt_prod, total_pkt_size;
5135 int defragged, error, nsegs, rc, nbds, vlan_off, ovlan;
5136 struct bxe_softc *sc;
5137 uint16_t tx_bd_avail;
5138 struct ether_vlan_header *eh;
5139 uint32_t pbd_e2_parsing_data = 0;
5146 #if __FreeBSD_version >= 800000
5147 M_ASSERTPKTHDR(*m_head);
5148 #endif /* #if __FreeBSD_version >= 800000 */
5151 rc = defragged = nbds = ovlan = vlan_off = total_pkt_size = 0;
5154 tx_total_pkt_size_bd = NULL;
5156 /* get the H/W pointer for packets and BDs */
5157 pkt_prod = fp->tx_pkt_prod;
5158 bd_prod = fp->tx_bd_prod;
5160 mac_type = UNICAST_ADDRESS;
5162 /* map the mbuf into the next open DMAable memory */
5163 tx_buf = &fp->tx_mbuf_chain[TX_BD(pkt_prod)];
5164 error = bus_dmamap_load_mbuf_sg(fp->tx_mbuf_tag,
5166 segs, &nsegs, BUS_DMA_NOWAIT);
5168 /* mapping errors */
5169 if(__predict_false(error != 0)) {
5170 fp->eth_q_stats.tx_dma_mapping_failure++;
5171 if (error == ENOMEM) {
5172 /* resource issue, try again later */
5174 } else if (error == EFBIG) {
5175 /* possibly recoverable with defragmentation */
5176 fp->eth_q_stats.mbuf_defrag_attempts++;
5177 m0 = m_defrag(*m_head, M_DONTWAIT);
5179 fp->eth_q_stats.mbuf_defrag_failures++;
5182 /* defrag successful, try mapping again */
5184 error = bus_dmamap_load_mbuf_sg(fp->tx_mbuf_tag,
5186 segs, &nsegs, BUS_DMA_NOWAIT);
5188 fp->eth_q_stats.tx_dma_mapping_failure++;
5193 /* unknown, unrecoverable mapping error */
5194 BLOGE(sc, "Unknown TX mapping error rc=%d\n", error);
5195 bxe_dump_mbuf(sc, m0, FALSE);
5199 goto bxe_tx_encap_continue;
5202 tx_bd_avail = bxe_tx_avail(sc, fp);
5204 /* make sure there is enough room in the send queue */
5205 if (__predict_false(tx_bd_avail < (nsegs + 2))) {
5206 /* Recoverable, try again later. */
5207 fp->eth_q_stats.tx_hw_queue_full++;
5208 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
5210 goto bxe_tx_encap_continue;
5213 /* capture the current H/W TX chain high watermark */
5214 if (__predict_false(fp->eth_q_stats.tx_hw_max_queue_depth <
5215 (TX_BD_USABLE - tx_bd_avail))) {
5216 fp->eth_q_stats.tx_hw_max_queue_depth = (TX_BD_USABLE - tx_bd_avail);
5219 /* make sure it fits in the packet window */
5220 if (__predict_false(nsegs > BXE_MAX_SEGMENTS)) {
5222 * The mbuf may be to big for the controller to handle. If the frame
5223 * is a TSO frame we'll need to do an additional check.
5225 if (m0->m_pkthdr.csum_flags & CSUM_TSO) {
5226 if (bxe_chktso_window(sc, nsegs, segs, m0) == 0) {
5227 goto bxe_tx_encap_continue; /* OK to send */
5229 fp->eth_q_stats.tx_window_violation_tso++;
5232 fp->eth_q_stats.tx_window_violation_std++;
5235 /* lets try to defragment this mbuf and remap it */
5236 fp->eth_q_stats.mbuf_defrag_attempts++;
5237 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
5239 m0 = m_defrag(*m_head, M_DONTWAIT);
5241 fp->eth_q_stats.mbuf_defrag_failures++;
5242 /* Ugh, just drop the frame... :( */
5245 /* defrag successful, try mapping again */
5247 error = bus_dmamap_load_mbuf_sg(fp->tx_mbuf_tag,
5249 segs, &nsegs, BUS_DMA_NOWAIT);
5251 fp->eth_q_stats.tx_dma_mapping_failure++;
5252 /* No sense in trying to defrag/copy chain, drop it. :( */
5255 /* if the chain is still too long then drop it */
5256 if(m0->m_pkthdr.csum_flags & CSUM_TSO) {
5258 * in case TSO is enabled nsegs should be checked against
5259 * BXE_TSO_MAX_SEGMENTS
5261 if (__predict_false(nsegs > BXE_TSO_MAX_SEGMENTS)) {
5262 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
5263 fp->eth_q_stats.nsegs_path1_errors++;
5267 if (__predict_false(nsegs > BXE_MAX_SEGMENTS)) {
5268 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
5269 fp->eth_q_stats.nsegs_path2_errors++;
5277 bxe_tx_encap_continue:
5279 /* Check for errors */
5282 /* recoverable try again later */
5284 fp->eth_q_stats.tx_soft_errors++;
5285 fp->eth_q_stats.mbuf_alloc_tx--;
5293 /* set flag according to packet type (UNICAST_ADDRESS is default) */
5294 if (m0->m_flags & M_BCAST) {
5295 mac_type = BROADCAST_ADDRESS;
5296 } else if (m0->m_flags & M_MCAST) {
5297 mac_type = MULTICAST_ADDRESS;
5300 /* store the mbuf into the mbuf ring */
5302 tx_buf->first_bd = fp->tx_bd_prod;
5305 /* prepare the first transmit (start) BD for the mbuf */
5306 tx_start_bd = &fp->tx_chain[TX_BD(bd_prod)].start_bd;
5309 "sending pkt_prod=%u tx_buf=%p next_idx=%u bd=%u tx_start_bd=%p\n",
5310 pkt_prod, tx_buf, fp->tx_pkt_prod, bd_prod, tx_start_bd);
5312 tx_start_bd->addr_lo = htole32(U64_LO(segs[0].ds_addr));
5313 tx_start_bd->addr_hi = htole32(U64_HI(segs[0].ds_addr));
5314 tx_start_bd->nbytes = htole16(segs[0].ds_len);
5315 total_pkt_size += tx_start_bd->nbytes;
5316 tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
5318 tx_start_bd->general_data = (1 << ETH_TX_START_BD_HDR_NBDS_SHIFT);
5320 /* all frames have at least Start BD + Parsing BD */
5322 tx_start_bd->nbd = htole16(nbds);
5324 if (m0->m_flags & M_VLANTAG) {
5325 tx_start_bd->vlan_or_ethertype = htole16(m0->m_pkthdr.ether_vtag);
5326 tx_start_bd->bd_flags.as_bitfield |=
5327 (X_ETH_OUTBAND_VLAN << ETH_TX_BD_FLAGS_VLAN_MODE_SHIFT);
5329 /* vf tx, start bd must hold the ethertype for fw to enforce it */
5331 /* map ethernet header to find type and header length */
5332 eh = mtod(m0, struct ether_vlan_header *);
5333 tx_start_bd->vlan_or_ethertype = eh->evl_encap_proto;
5335 /* used by FW for packet accounting */
5336 tx_start_bd->vlan_or_ethertype = htole16(fp->tx_pkt_prod);
5341 * add a parsing BD from the chain. The parsing BD is always added
5342 * though it is only used for TSO and chksum
5344 bd_prod = TX_BD_NEXT(bd_prod);
5346 if (m0->m_pkthdr.csum_flags) {
5347 if (m0->m_pkthdr.csum_flags & CSUM_IP) {
5348 fp->eth_q_stats.tx_ofld_frames_csum_ip++;
5349 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_IP_CSUM;
5352 if (m0->m_pkthdr.csum_flags & CSUM_TCP_IPV6) {
5353 tx_start_bd->bd_flags.as_bitfield |= (ETH_TX_BD_FLAGS_IPV6 |
5354 ETH_TX_BD_FLAGS_L4_CSUM);
5355 } else if (m0->m_pkthdr.csum_flags & CSUM_UDP_IPV6) {
5356 tx_start_bd->bd_flags.as_bitfield |= (ETH_TX_BD_FLAGS_IPV6 |
5357 ETH_TX_BD_FLAGS_IS_UDP |
5358 ETH_TX_BD_FLAGS_L4_CSUM);
5359 } else if ((m0->m_pkthdr.csum_flags & CSUM_TCP) ||
5360 (m0->m_pkthdr.csum_flags & CSUM_TSO)) {
5361 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_L4_CSUM;
5362 } else if (m0->m_pkthdr.csum_flags & CSUM_UDP) {
5363 tx_start_bd->bd_flags.as_bitfield |= (ETH_TX_BD_FLAGS_L4_CSUM |
5364 ETH_TX_BD_FLAGS_IS_UDP);
5368 if (!CHIP_IS_E1x(sc)) {
5369 pbd_e2 = &fp->tx_chain[TX_BD(bd_prod)].parse_bd_e2;
5370 memset(pbd_e2, 0, sizeof(struct eth_tx_parse_bd_e2));
5372 if (m0->m_pkthdr.csum_flags) {
5373 hlen = bxe_set_pbd_csum_e2(fp, m0, &pbd_e2_parsing_data);
5376 SET_FLAG(pbd_e2_parsing_data, ETH_TX_PARSE_BD_E2_ETH_ADDR_TYPE,
5379 uint16_t global_data = 0;
5381 pbd_e1x = &fp->tx_chain[TX_BD(bd_prod)].parse_bd_e1x;
5382 memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x));
5384 if (m0->m_pkthdr.csum_flags) {
5385 hlen = bxe_set_pbd_csum(fp, m0, pbd_e1x);
5388 SET_FLAG(global_data,
5389 ETH_TX_PARSE_BD_E1X_ETH_ADDR_TYPE, mac_type);
5390 pbd_e1x->global_data |= htole16(global_data);
5393 /* setup the parsing BD with TSO specific info */
5394 if (m0->m_pkthdr.csum_flags & CSUM_TSO) {
5395 fp->eth_q_stats.tx_ofld_frames_lso++;
5396 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_SW_LSO;
5398 if (__predict_false(tx_start_bd->nbytes > hlen)) {
5399 fp->eth_q_stats.tx_ofld_frames_lso_hdr_splits++;
5401 /* split the first BD into header/data making the fw job easy */
5403 tx_start_bd->nbd = htole16(nbds);
5404 tx_start_bd->nbytes = htole16(hlen);
5406 bd_prod = TX_BD_NEXT(bd_prod);
5408 /* new transmit BD after the tx_parse_bd */
5409 tx_data_bd = &fp->tx_chain[TX_BD(bd_prod)].reg_bd;
5410 tx_data_bd->addr_hi = htole32(U64_HI(segs[0].ds_addr + hlen));
5411 tx_data_bd->addr_lo = htole32(U64_LO(segs[0].ds_addr + hlen));
5412 tx_data_bd->nbytes = htole16(segs[0].ds_len - hlen);
5413 if (tx_total_pkt_size_bd == NULL) {
5414 tx_total_pkt_size_bd = tx_data_bd;
5418 "TSO split header size is %d (%x:%x) nbds %d\n",
5419 le16toh(tx_start_bd->nbytes),
5420 le32toh(tx_start_bd->addr_hi),
5421 le32toh(tx_start_bd->addr_lo),
5425 if (!CHIP_IS_E1x(sc)) {
5426 bxe_set_pbd_lso_e2(m0, &pbd_e2_parsing_data);
5428 bxe_set_pbd_lso(m0, pbd_e1x);
5432 if (pbd_e2_parsing_data) {
5433 pbd_e2->parsing_data = htole32(pbd_e2_parsing_data);
5436 /* prepare remaining BDs, start tx bd contains first seg/frag */
5437 for (i = 1; i < nsegs ; i++) {
5438 bd_prod = TX_BD_NEXT(bd_prod);
5439 tx_data_bd = &fp->tx_chain[TX_BD(bd_prod)].reg_bd;
5440 tx_data_bd->addr_lo = htole32(U64_LO(segs[i].ds_addr));
5441 tx_data_bd->addr_hi = htole32(U64_HI(segs[i].ds_addr));
5442 tx_data_bd->nbytes = htole16(segs[i].ds_len);
5443 if (tx_total_pkt_size_bd == NULL) {
5444 tx_total_pkt_size_bd = tx_data_bd;
5446 total_pkt_size += tx_data_bd->nbytes;
5449 BLOGD(sc, DBG_TX, "last bd %p\n", tx_data_bd);
5451 if (tx_total_pkt_size_bd != NULL) {
5452 tx_total_pkt_size_bd->total_pkt_bytes = total_pkt_size;
5455 if (__predict_false(sc->debug & DBG_TX)) {
5456 tmp_bd = tx_buf->first_bd;
5457 for (i = 0; i < nbds; i++)
5461 "TX Strt: %p bd=%d nbd=%d vlan=0x%x "
5462 "bd_flags=0x%x hdr_nbds=%d\n",
5465 le16toh(tx_start_bd->nbd),
5466 le16toh(tx_start_bd->vlan_or_ethertype),
5467 tx_start_bd->bd_flags.as_bitfield,
5468 (tx_start_bd->general_data & ETH_TX_START_BD_HDR_NBDS));
5469 } else if (i == 1) {
5472 "-> Prse: %p bd=%d global=0x%x ip_hlen_w=%u "
5473 "ip_id=%u lso_mss=%u tcp_flags=0x%x csum=0x%x "
5474 "tcp_seq=%u total_hlen_w=%u\n",
5477 pbd_e1x->global_data,
5482 pbd_e1x->tcp_pseudo_csum,
5483 pbd_e1x->tcp_send_seq,
5484 le16toh(pbd_e1x->total_hlen_w));
5485 } else { /* if (pbd_e2) */
5487 "-> Parse: %p bd=%d dst=%02x:%02x:%02x "
5488 "src=%02x:%02x:%02x parsing_data=0x%x\n",
5491 pbd_e2->data.mac_addr.dst_hi,
5492 pbd_e2->data.mac_addr.dst_mid,
5493 pbd_e2->data.mac_addr.dst_lo,
5494 pbd_e2->data.mac_addr.src_hi,
5495 pbd_e2->data.mac_addr.src_mid,
5496 pbd_e2->data.mac_addr.src_lo,
5497 pbd_e2->parsing_data);
5501 if (i != 1) { /* skip parse db as it doesn't hold data */
5502 tx_data_bd = &fp->tx_chain[TX_BD(tmp_bd)].reg_bd;
5504 "-> Frag: %p bd=%d nbytes=%d hi=0x%x lo: 0x%x\n",
5507 le16toh(tx_data_bd->nbytes),
5508 le32toh(tx_data_bd->addr_hi),
5509 le32toh(tx_data_bd->addr_lo));
5512 tmp_bd = TX_BD_NEXT(tmp_bd);
5516 BLOGD(sc, DBG_TX, "doorbell: nbds=%d bd=%u\n", nbds, bd_prod);
5518 /* update TX BD producer index value for next TX */
5519 bd_prod = TX_BD_NEXT(bd_prod);
5522 * If the chain of tx_bd's describing this frame is adjacent to or spans
5523 * an eth_tx_next_bd element then we need to increment the nbds value.
5525 if (TX_BD_IDX(bd_prod) < nbds) {
5529 /* don't allow reordering of writes for nbd and packets */
5532 fp->tx_db.data.prod += nbds;
5534 /* producer points to the next free tx_bd at this point */
5536 fp->tx_bd_prod = bd_prod;
5538 DOORBELL(sc, fp->index, fp->tx_db.raw);
5540 fp->eth_q_stats.tx_pkts++;
5542 /* Prevent speculative reads from getting ahead of the status block. */
5543 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle,
5544 0, 0, BUS_SPACE_BARRIER_READ);
5546 /* Prevent speculative reads from getting ahead of the doorbell. */
5547 bus_space_barrier(sc->bar[BAR2].tag, sc->bar[BAR2].handle,
5548 0, 0, BUS_SPACE_BARRIER_READ);
5554 bxe_tx_start_locked(struct bxe_softc *sc,
5556 struct bxe_fastpath *fp)
5558 struct mbuf *m = NULL;
5560 uint16_t tx_bd_avail;
5562 BXE_FP_TX_LOCK_ASSERT(fp);
5564 /* keep adding entries while there are frames to send */
5565 while (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) {
5568 * check for any frames to send
5569 * dequeue can still be NULL even if queue is not empty
5571 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
5572 if (__predict_false(m == NULL)) {
5576 /* the mbuf now belongs to us */
5577 fp->eth_q_stats.mbuf_alloc_tx++;
5580 * Put the frame into the transmit ring. If we don't have room,
5581 * place the mbuf back at the head of the TX queue, set the
5582 * OACTIVE flag, and wait for the NIC to drain the chain.
5584 if (__predict_false(bxe_tx_encap(fp, &m))) {
5585 fp->eth_q_stats.tx_encap_failures++;
5587 /* mark the TX queue as full and return the frame */
5588 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
5589 IFQ_DRV_PREPEND(&ifp->if_snd, m);
5590 fp->eth_q_stats.mbuf_alloc_tx--;
5591 fp->eth_q_stats.tx_queue_xoff++;
5594 /* stop looking for more work */
5598 /* the frame was enqueued successfully */
5601 /* send a copy of the frame to any BPF listeners. */
5604 tx_bd_avail = bxe_tx_avail(sc, fp);
5606 /* handle any completions if we're running low */
5607 if (tx_bd_avail < BXE_TX_CLEANUP_THRESHOLD) {
5608 /* bxe_txeof will set IFF_DRV_OACTIVE appropriately */
5610 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
5616 /* all TX packets were dequeued and/or the tx ring is full */
5618 /* reset the TX watchdog timeout timer */
5619 fp->watchdog_timer = BXE_TX_TIMEOUT;
5623 /* Legacy (non-RSS) dispatch routine */
5625 bxe_tx_start(struct ifnet *ifp)
5627 struct bxe_softc *sc;
5628 struct bxe_fastpath *fp;
5632 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
5633 BLOGW(sc, "Interface not running, ignoring transmit request\n");
5637 if (!sc->link_vars.link_up) {
5638 BLOGW(sc, "Interface link is down, ignoring transmit request\n");
5644 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
5645 fp->eth_q_stats.tx_queue_full_return++;
5650 bxe_tx_start_locked(sc, ifp, fp);
5651 BXE_FP_TX_UNLOCK(fp);
5654 #if __FreeBSD_version >= 800000
5657 bxe_tx_mq_start_locked(struct bxe_softc *sc,
5659 struct bxe_fastpath *fp,
5662 struct buf_ring *tx_br = fp->tx_br;
5664 int depth, rc, tx_count;
5665 uint16_t tx_bd_avail;
5669 BXE_FP_TX_LOCK_ASSERT(fp);
5671 if (sc->state != BXE_STATE_OPEN) {
5672 fp->eth_q_stats.bxe_tx_mq_sc_state_failures++;
5677 BLOGE(sc, "Multiqueue TX and no buf_ring!\n");
5681 if (!sc->link_vars.link_up ||
5682 (ifp->if_drv_flags &
5683 (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != IFF_DRV_RUNNING) {
5684 rc = drbr_enqueue(ifp, tx_br, m);
5685 goto bxe_tx_mq_start_locked_exit;
5688 /* fetch the depth of the driver queue */
5689 depth = drbr_inuse(ifp, tx_br);
5690 if (depth > fp->eth_q_stats.tx_max_drbr_queue_depth) {
5691 fp->eth_q_stats.tx_max_drbr_queue_depth = depth;
5695 /* no new work, check for pending frames */
5696 next = drbr_dequeue(ifp, tx_br);
5697 } else if (drbr_needs_enqueue(ifp, tx_br)) {
5698 /* have both new and pending work, maintain packet order */
5699 rc = drbr_enqueue(ifp, tx_br, m);
5701 fp->eth_q_stats.tx_soft_errors++;
5702 goto bxe_tx_mq_start_locked_exit;
5704 next = drbr_dequeue(ifp, tx_br);
5706 /* new work only and nothing pending */
5710 /* keep adding entries while there are frames to send */
5711 while (next != NULL) {
5713 /* the mbuf now belongs to us */
5714 fp->eth_q_stats.mbuf_alloc_tx++;
5717 * Put the frame into the transmit ring. If we don't have room,
5718 * place the mbuf back at the head of the TX queue, set the
5719 * OACTIVE flag, and wait for the NIC to drain the chain.
5721 rc = bxe_tx_encap(fp, &next);
5722 if (__predict_false(rc != 0)) {
5723 fp->eth_q_stats.tx_encap_failures++;
5725 /* mark the TX queue as full and save the frame */
5726 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
5727 /* XXX this may reorder the frame */
5728 rc = drbr_enqueue(ifp, tx_br, next);
5729 fp->eth_q_stats.mbuf_alloc_tx--;
5730 fp->eth_q_stats.tx_frames_deferred++;
5733 /* stop looking for more work */
5737 /* the transmit frame was enqueued successfully */
5740 /* send a copy of the frame to any BPF listeners */
5741 BPF_MTAP(ifp, next);
5743 tx_bd_avail = bxe_tx_avail(sc, fp);
5745 /* handle any completions if we're running low */
5746 if (tx_bd_avail < BXE_TX_CLEANUP_THRESHOLD) {
5747 /* bxe_txeof will set IFF_DRV_OACTIVE appropriately */
5749 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
5754 next = drbr_dequeue(ifp, tx_br);
5757 /* all TX packets were dequeued and/or the tx ring is full */
5759 /* reset the TX watchdog timeout timer */
5760 fp->watchdog_timer = BXE_TX_TIMEOUT;
5763 bxe_tx_mq_start_locked_exit:
5768 /* Multiqueue (TSS) dispatch routine. */
5770 bxe_tx_mq_start(struct ifnet *ifp,
5773 struct bxe_softc *sc = ifp->if_softc;
5774 struct bxe_fastpath *fp;
5777 fp_index = 0; /* default is the first queue */
5779 /* check if flowid is set */
5781 if (BXE_VALID_FLOWID(m))
5782 fp_index = (m->m_pkthdr.flowid % sc->num_queues);
5784 fp = &sc->fp[fp_index];
5786 if (sc->state != BXE_STATE_OPEN) {
5787 fp->eth_q_stats.bxe_tx_mq_sc_state_failures++;
5791 if (BXE_FP_TX_TRYLOCK(fp)) {
5792 rc = bxe_tx_mq_start_locked(sc, ifp, fp, m);
5793 BXE_FP_TX_UNLOCK(fp);
5795 rc = drbr_enqueue(ifp, fp->tx_br, m);
5801 bxe_mq_flush(struct ifnet *ifp)
5803 struct bxe_softc *sc = ifp->if_softc;
5804 struct bxe_fastpath *fp;
5808 for (i = 0; i < sc->num_queues; i++) {
5811 if (fp->state != BXE_FP_STATE_IRQ) {
5812 BLOGD(sc, DBG_LOAD, "Not clearing fp[%02d] buf_ring (state=%d)\n",
5813 fp->index, fp->state);
5817 if (fp->tx_br != NULL) {
5818 BLOGD(sc, DBG_LOAD, "Clearing fp[%02d] buf_ring\n", fp->index);
5820 while ((m = buf_ring_dequeue_sc(fp->tx_br)) != NULL) {
5823 BXE_FP_TX_UNLOCK(fp);
5830 #endif /* FreeBSD_version >= 800000 */
5833 bxe_cid_ilt_lines(struct bxe_softc *sc)
5836 return ((BXE_FIRST_VF_CID + BXE_VF_CIDS) / ILT_PAGE_CIDS);
5838 return (L2_ILT_LINES(sc));
5842 bxe_ilt_set_info(struct bxe_softc *sc)
5844 struct ilt_client_info *ilt_client;
5845 struct ecore_ilt *ilt = sc->ilt;
5848 ilt->start_line = FUNC_ILT_BASE(SC_FUNC(sc));
5849 BLOGD(sc, DBG_LOAD, "ilt starts at line %d\n", ilt->start_line);
5852 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
5853 ilt_client->client_num = ILT_CLIENT_CDU;
5854 ilt_client->page_size = CDU_ILT_PAGE_SZ;
5855 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
5856 ilt_client->start = line;
5857 line += bxe_cid_ilt_lines(sc);
5859 if (CNIC_SUPPORT(sc)) {
5860 line += CNIC_ILT_LINES;
5863 ilt_client->end = (line - 1);
5866 "ilt client[CDU]: start %d, end %d, "
5867 "psz 0x%x, flags 0x%x, hw psz %d\n",
5868 ilt_client->start, ilt_client->end,
5869 ilt_client->page_size,
5871 ilog2(ilt_client->page_size >> 12));
5874 if (QM_INIT(sc->qm_cid_count)) {
5875 ilt_client = &ilt->clients[ILT_CLIENT_QM];
5876 ilt_client->client_num = ILT_CLIENT_QM;
5877 ilt_client->page_size = QM_ILT_PAGE_SZ;
5878 ilt_client->flags = 0;
5879 ilt_client->start = line;
5881 /* 4 bytes for each cid */
5882 line += DIV_ROUND_UP(sc->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
5885 ilt_client->end = (line - 1);
5888 "ilt client[QM]: start %d, end %d, "
5889 "psz 0x%x, flags 0x%x, hw psz %d\n",
5890 ilt_client->start, ilt_client->end,
5891 ilt_client->page_size, ilt_client->flags,
5892 ilog2(ilt_client->page_size >> 12));
5895 if (CNIC_SUPPORT(sc)) {
5897 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
5898 ilt_client->client_num = ILT_CLIENT_SRC;
5899 ilt_client->page_size = SRC_ILT_PAGE_SZ;
5900 ilt_client->flags = 0;
5901 ilt_client->start = line;
5902 line += SRC_ILT_LINES;
5903 ilt_client->end = (line - 1);
5906 "ilt client[SRC]: start %d, end %d, "
5907 "psz 0x%x, flags 0x%x, hw psz %d\n",
5908 ilt_client->start, ilt_client->end,
5909 ilt_client->page_size, ilt_client->flags,
5910 ilog2(ilt_client->page_size >> 12));
5913 ilt_client = &ilt->clients[ILT_CLIENT_TM];
5914 ilt_client->client_num = ILT_CLIENT_TM;
5915 ilt_client->page_size = TM_ILT_PAGE_SZ;
5916 ilt_client->flags = 0;
5917 ilt_client->start = line;
5918 line += TM_ILT_LINES;
5919 ilt_client->end = (line - 1);
5922 "ilt client[TM]: start %d, end %d, "
5923 "psz 0x%x, flags 0x%x, hw psz %d\n",
5924 ilt_client->start, ilt_client->end,
5925 ilt_client->page_size, ilt_client->flags,
5926 ilog2(ilt_client->page_size >> 12));
5929 KASSERT((line <= ILT_MAX_LINES), ("Invalid number of ILT lines!"));
5933 bxe_set_fp_rx_buf_size(struct bxe_softc *sc)
5936 uint32_t rx_buf_size;
5938 rx_buf_size = (IP_HEADER_ALIGNMENT_PADDING + ETH_OVERHEAD + sc->mtu);
5940 for (i = 0; i < sc->num_queues; i++) {
5941 if(rx_buf_size <= MCLBYTES){
5942 sc->fp[i].rx_buf_size = rx_buf_size;
5943 sc->fp[i].mbuf_alloc_size = MCLBYTES;
5944 }else if (rx_buf_size <= MJUMPAGESIZE){
5945 sc->fp[i].rx_buf_size = rx_buf_size;
5946 sc->fp[i].mbuf_alloc_size = MJUMPAGESIZE;
5947 }else if (rx_buf_size <= (MJUMPAGESIZE + MCLBYTES)){
5948 sc->fp[i].rx_buf_size = MCLBYTES;
5949 sc->fp[i].mbuf_alloc_size = MCLBYTES;
5950 }else if (rx_buf_size <= (2 * MJUMPAGESIZE)){
5951 sc->fp[i].rx_buf_size = MJUMPAGESIZE;
5952 sc->fp[i].mbuf_alloc_size = MJUMPAGESIZE;
5954 sc->fp[i].rx_buf_size = MCLBYTES;
5955 sc->fp[i].mbuf_alloc_size = MCLBYTES;
5961 bxe_alloc_ilt_mem(struct bxe_softc *sc)
5966 (struct ecore_ilt *)malloc(sizeof(struct ecore_ilt),
5968 (M_NOWAIT | M_ZERO))) == NULL) {
5976 bxe_alloc_ilt_lines_mem(struct bxe_softc *sc)
5980 if ((sc->ilt->lines =
5981 (struct ilt_line *)malloc((sizeof(struct ilt_line) * ILT_MAX_LINES),
5983 (M_NOWAIT | M_ZERO))) == NULL) {
5991 bxe_free_ilt_mem(struct bxe_softc *sc)
5993 if (sc->ilt != NULL) {
5994 free(sc->ilt, M_BXE_ILT);
6000 bxe_free_ilt_lines_mem(struct bxe_softc *sc)
6002 if (sc->ilt->lines != NULL) {
6003 free(sc->ilt->lines, M_BXE_ILT);
6004 sc->ilt->lines = NULL;
6009 bxe_free_mem(struct bxe_softc *sc)
6013 for (i = 0; i < L2_ILT_LINES(sc); i++) {
6014 bxe_dma_free(sc, &sc->context[i].vcxt_dma);
6015 sc->context[i].vcxt = NULL;
6016 sc->context[i].size = 0;
6019 ecore_ilt_mem_op(sc, ILT_MEMOP_FREE);
6021 bxe_free_ilt_lines_mem(sc);
6026 bxe_alloc_mem(struct bxe_softc *sc)
6034 * Allocate memory for CDU context:
6035 * This memory is allocated separately and not in the generic ILT
6036 * functions because CDU differs in few aspects:
6037 * 1. There can be multiple entities allocating memory for context -
6038 * regular L2, CNIC, and SRIOV drivers. Each separately controls
6039 * its own ILT lines.
6040 * 2. Since CDU page-size is not a single 4KB page (which is the case
6041 * for the other ILT clients), to be efficient we want to support
6042 * allocation of sub-page-size in the last entry.
6043 * 3. Context pointers are used by the driver to pass to FW / update
6044 * the context (for the other ILT clients the pointers are used just to
6045 * free the memory during unload).
6047 context_size = (sizeof(union cdu_context) * BXE_L2_CID_COUNT(sc));
6048 for (i = 0, allocated = 0; allocated < context_size; i++) {
6049 sc->context[i].size = min(CDU_ILT_PAGE_SZ,
6050 (context_size - allocated));
6052 if (bxe_dma_alloc(sc, sc->context[i].size,
6053 &sc->context[i].vcxt_dma,
6054 "cdu context") != 0) {
6059 sc->context[i].vcxt =
6060 (union cdu_context *)sc->context[i].vcxt_dma.vaddr;
6062 allocated += sc->context[i].size;
6065 bxe_alloc_ilt_lines_mem(sc);
6067 BLOGD(sc, DBG_LOAD, "ilt=%p start_line=%u lines=%p\n",
6068 sc->ilt, sc->ilt->start_line, sc->ilt->lines);
6070 for (i = 0; i < 4; i++) {
6072 "c%d page_size=%u start=%u end=%u num=%u flags=0x%x\n",
6074 sc->ilt->clients[i].page_size,
6075 sc->ilt->clients[i].start,
6076 sc->ilt->clients[i].end,
6077 sc->ilt->clients[i].client_num,
6078 sc->ilt->clients[i].flags);
6081 if (ecore_ilt_mem_op(sc, ILT_MEMOP_ALLOC)) {
6082 BLOGE(sc, "ecore_ilt_mem_op ILT_MEMOP_ALLOC failed\n");
6091 bxe_free_rx_bd_chain(struct bxe_fastpath *fp)
6093 struct bxe_softc *sc;
6098 if (fp->rx_mbuf_tag == NULL) {
6102 /* free all mbufs and unload all maps */
6103 for (i = 0; i < RX_BD_TOTAL; i++) {
6104 if (fp->rx_mbuf_chain[i].m_map != NULL) {
6105 bus_dmamap_sync(fp->rx_mbuf_tag,
6106 fp->rx_mbuf_chain[i].m_map,
6107 BUS_DMASYNC_POSTREAD);
6108 bus_dmamap_unload(fp->rx_mbuf_tag,
6109 fp->rx_mbuf_chain[i].m_map);
6112 if (fp->rx_mbuf_chain[i].m != NULL) {
6113 m_freem(fp->rx_mbuf_chain[i].m);
6114 fp->rx_mbuf_chain[i].m = NULL;
6115 fp->eth_q_stats.mbuf_alloc_rx--;
6121 bxe_free_tpa_pool(struct bxe_fastpath *fp)
6123 struct bxe_softc *sc;
6124 int i, max_agg_queues;
6128 if (fp->rx_mbuf_tag == NULL) {
6132 max_agg_queues = MAX_AGG_QS(sc);
6134 /* release all mbufs and unload all DMA maps in the TPA pool */
6135 for (i = 0; i < max_agg_queues; i++) {
6136 if (fp->rx_tpa_info[i].bd.m_map != NULL) {
6137 bus_dmamap_sync(fp->rx_mbuf_tag,
6138 fp->rx_tpa_info[i].bd.m_map,
6139 BUS_DMASYNC_POSTREAD);
6140 bus_dmamap_unload(fp->rx_mbuf_tag,
6141 fp->rx_tpa_info[i].bd.m_map);
6144 if (fp->rx_tpa_info[i].bd.m != NULL) {
6145 m_freem(fp->rx_tpa_info[i].bd.m);
6146 fp->rx_tpa_info[i].bd.m = NULL;
6147 fp->eth_q_stats.mbuf_alloc_tpa--;
6153 bxe_free_sge_chain(struct bxe_fastpath *fp)
6155 struct bxe_softc *sc;
6160 if (fp->rx_sge_mbuf_tag == NULL) {
6164 /* rree all mbufs and unload all maps */
6165 for (i = 0; i < RX_SGE_TOTAL; i++) {
6166 if (fp->rx_sge_mbuf_chain[i].m_map != NULL) {
6167 bus_dmamap_sync(fp->rx_sge_mbuf_tag,
6168 fp->rx_sge_mbuf_chain[i].m_map,
6169 BUS_DMASYNC_POSTREAD);
6170 bus_dmamap_unload(fp->rx_sge_mbuf_tag,
6171 fp->rx_sge_mbuf_chain[i].m_map);
6174 if (fp->rx_sge_mbuf_chain[i].m != NULL) {
6175 m_freem(fp->rx_sge_mbuf_chain[i].m);
6176 fp->rx_sge_mbuf_chain[i].m = NULL;
6177 fp->eth_q_stats.mbuf_alloc_sge--;
6183 bxe_free_fp_buffers(struct bxe_softc *sc)
6185 struct bxe_fastpath *fp;
6188 for (i = 0; i < sc->num_queues; i++) {
6191 #if __FreeBSD_version >= 800000
6192 if (fp->tx_br != NULL) {
6193 /* just in case bxe_mq_flush() wasn't called */
6194 if (mtx_initialized(&fp->tx_mtx)) {
6198 while ((m = buf_ring_dequeue_sc(fp->tx_br)) != NULL)
6200 BXE_FP_TX_UNLOCK(fp);
6205 /* free all RX buffers */
6206 bxe_free_rx_bd_chain(fp);
6207 bxe_free_tpa_pool(fp);
6208 bxe_free_sge_chain(fp);
6210 if (fp->eth_q_stats.mbuf_alloc_rx != 0) {
6211 BLOGE(sc, "failed to claim all rx mbufs (%d left)\n",
6212 fp->eth_q_stats.mbuf_alloc_rx);
6215 if (fp->eth_q_stats.mbuf_alloc_sge != 0) {
6216 BLOGE(sc, "failed to claim all sge mbufs (%d left)\n",
6217 fp->eth_q_stats.mbuf_alloc_sge);
6220 if (fp->eth_q_stats.mbuf_alloc_tpa != 0) {
6221 BLOGE(sc, "failed to claim all sge mbufs (%d left)\n",
6222 fp->eth_q_stats.mbuf_alloc_tpa);
6225 if (fp->eth_q_stats.mbuf_alloc_tx != 0) {
6226 BLOGE(sc, "failed to release tx mbufs (%d left)\n",
6227 fp->eth_q_stats.mbuf_alloc_tx);
6230 /* XXX verify all mbufs were reclaimed */
6235 bxe_alloc_rx_bd_mbuf(struct bxe_fastpath *fp,
6236 uint16_t prev_index,
6239 struct bxe_sw_rx_bd *rx_buf;
6240 struct eth_rx_bd *rx_bd;
6241 bus_dma_segment_t segs[1];
6248 /* allocate the new RX BD mbuf */
6249 m = m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR, fp->mbuf_alloc_size);
6250 if (__predict_false(m == NULL)) {
6251 fp->eth_q_stats.mbuf_rx_bd_alloc_failed++;
6255 fp->eth_q_stats.mbuf_alloc_rx++;
6257 /* initialize the mbuf buffer length */
6258 m->m_pkthdr.len = m->m_len = fp->rx_buf_size;
6260 /* map the mbuf into non-paged pool */
6261 rc = bus_dmamap_load_mbuf_sg(fp->rx_mbuf_tag,
6262 fp->rx_mbuf_spare_map,
6263 m, segs, &nsegs, BUS_DMA_NOWAIT);
6264 if (__predict_false(rc != 0)) {
6265 fp->eth_q_stats.mbuf_rx_bd_mapping_failed++;
6267 fp->eth_q_stats.mbuf_alloc_rx--;
6271 /* all mbufs must map to a single segment */
6272 KASSERT((nsegs == 1), ("Too many segments, %d returned!", nsegs));
6274 /* release any existing RX BD mbuf mappings */
6276 if (prev_index != index) {
6277 rx_buf = &fp->rx_mbuf_chain[prev_index];
6279 if (rx_buf->m_map != NULL) {
6280 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map,
6281 BUS_DMASYNC_POSTREAD);
6282 bus_dmamap_unload(fp->rx_mbuf_tag, rx_buf->m_map);
6286 * We only get here from bxe_rxeof() when the maximum number
6287 * of rx buffers is less than RX_BD_USABLE. bxe_rxeof() already
6288 * holds the mbuf in the prev_index so it's OK to NULL it out
6289 * here without concern of a memory leak.
6291 fp->rx_mbuf_chain[prev_index].m = NULL;
6294 rx_buf = &fp->rx_mbuf_chain[index];
6296 if (rx_buf->m_map != NULL) {
6297 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map,
6298 BUS_DMASYNC_POSTREAD);
6299 bus_dmamap_unload(fp->rx_mbuf_tag, rx_buf->m_map);
6302 /* save the mbuf and mapping info for a future packet */
6303 map = (prev_index != index) ?
6304 fp->rx_mbuf_chain[prev_index].m_map : rx_buf->m_map;
6305 rx_buf->m_map = fp->rx_mbuf_spare_map;
6306 fp->rx_mbuf_spare_map = map;
6307 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map,
6308 BUS_DMASYNC_PREREAD);
6311 rx_bd = &fp->rx_chain[index];
6312 rx_bd->addr_hi = htole32(U64_HI(segs[0].ds_addr));
6313 rx_bd->addr_lo = htole32(U64_LO(segs[0].ds_addr));
6319 bxe_alloc_rx_tpa_mbuf(struct bxe_fastpath *fp,
6322 struct bxe_sw_tpa_info *tpa_info = &fp->rx_tpa_info[queue];
6323 bus_dma_segment_t segs[1];
6329 /* allocate the new TPA mbuf */
6330 m = m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR, fp->mbuf_alloc_size);
6331 if (__predict_false(m == NULL)) {
6332 fp->eth_q_stats.mbuf_rx_tpa_alloc_failed++;
6336 fp->eth_q_stats.mbuf_alloc_tpa++;
6338 /* initialize the mbuf buffer length */
6339 m->m_pkthdr.len = m->m_len = fp->rx_buf_size;
6341 /* map the mbuf into non-paged pool */
6342 rc = bus_dmamap_load_mbuf_sg(fp->rx_mbuf_tag,
6343 fp->rx_tpa_info_mbuf_spare_map,
6344 m, segs, &nsegs, BUS_DMA_NOWAIT);
6345 if (__predict_false(rc != 0)) {
6346 fp->eth_q_stats.mbuf_rx_tpa_mapping_failed++;
6348 fp->eth_q_stats.mbuf_alloc_tpa--;
6352 /* all mbufs must map to a single segment */
6353 KASSERT((nsegs == 1), ("Too many segments, %d returned!", nsegs));
6355 /* release any existing TPA mbuf mapping */
6356 if (tpa_info->bd.m_map != NULL) {
6357 bus_dmamap_sync(fp->rx_mbuf_tag, tpa_info->bd.m_map,
6358 BUS_DMASYNC_POSTREAD);
6359 bus_dmamap_unload(fp->rx_mbuf_tag, tpa_info->bd.m_map);
6362 /* save the mbuf and mapping info for the TPA mbuf */
6363 map = tpa_info->bd.m_map;
6364 tpa_info->bd.m_map = fp->rx_tpa_info_mbuf_spare_map;
6365 fp->rx_tpa_info_mbuf_spare_map = map;
6366 bus_dmamap_sync(fp->rx_mbuf_tag, tpa_info->bd.m_map,
6367 BUS_DMASYNC_PREREAD);
6369 tpa_info->seg = segs[0];
6375 * Allocate an mbuf and assign it to the receive scatter gather chain. The
6376 * caller must take care to save a copy of the existing mbuf in the SG mbuf
6380 bxe_alloc_rx_sge_mbuf(struct bxe_fastpath *fp,
6383 struct bxe_sw_rx_bd *sge_buf;
6384 struct eth_rx_sge *sge;
6385 bus_dma_segment_t segs[1];
6391 /* allocate a new SGE mbuf */
6392 m = m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR, SGE_PAGE_SIZE);
6393 if (__predict_false(m == NULL)) {
6394 fp->eth_q_stats.mbuf_rx_sge_alloc_failed++;
6398 fp->eth_q_stats.mbuf_alloc_sge++;
6400 /* initialize the mbuf buffer length */
6401 m->m_pkthdr.len = m->m_len = SGE_PAGE_SIZE;
6403 /* map the SGE mbuf into non-paged pool */
6404 rc = bus_dmamap_load_mbuf_sg(fp->rx_sge_mbuf_tag,
6405 fp->rx_sge_mbuf_spare_map,
6406 m, segs, &nsegs, BUS_DMA_NOWAIT);
6407 if (__predict_false(rc != 0)) {
6408 fp->eth_q_stats.mbuf_rx_sge_mapping_failed++;
6410 fp->eth_q_stats.mbuf_alloc_sge--;
6414 /* all mbufs must map to a single segment */
6415 KASSERT((nsegs == 1), ("Too many segments, %d returned!", nsegs));
6417 sge_buf = &fp->rx_sge_mbuf_chain[index];
6419 /* release any existing SGE mbuf mapping */
6420 if (sge_buf->m_map != NULL) {
6421 bus_dmamap_sync(fp->rx_sge_mbuf_tag, sge_buf->m_map,
6422 BUS_DMASYNC_POSTREAD);
6423 bus_dmamap_unload(fp->rx_sge_mbuf_tag, sge_buf->m_map);
6426 /* save the mbuf and mapping info for a future packet */
6427 map = sge_buf->m_map;
6428 sge_buf->m_map = fp->rx_sge_mbuf_spare_map;
6429 fp->rx_sge_mbuf_spare_map = map;
6430 bus_dmamap_sync(fp->rx_sge_mbuf_tag, sge_buf->m_map,
6431 BUS_DMASYNC_PREREAD);
6434 sge = &fp->rx_sge_chain[index];
6435 sge->addr_hi = htole32(U64_HI(segs[0].ds_addr));
6436 sge->addr_lo = htole32(U64_LO(segs[0].ds_addr));
6441 static __noinline int
6442 bxe_alloc_fp_buffers(struct bxe_softc *sc)
6444 struct bxe_fastpath *fp;
6446 int ring_prod, cqe_ring_prod;
6449 for (i = 0; i < sc->num_queues; i++) {
6452 ring_prod = cqe_ring_prod = 0;
6456 /* allocate buffers for the RX BDs in RX BD chain */
6457 for (j = 0; j < sc->max_rx_bufs; j++) {
6458 rc = bxe_alloc_rx_bd_mbuf(fp, ring_prod, ring_prod);
6460 BLOGE(sc, "mbuf alloc fail for fp[%02d] rx chain (%d)\n",
6462 goto bxe_alloc_fp_buffers_error;
6465 ring_prod = RX_BD_NEXT(ring_prod);
6466 cqe_ring_prod = RCQ_NEXT(cqe_ring_prod);
6469 fp->rx_bd_prod = ring_prod;
6470 fp->rx_cq_prod = cqe_ring_prod;
6471 fp->eth_q_stats.rx_calls = fp->eth_q_stats.rx_pkts = 0;
6473 max_agg_queues = MAX_AGG_QS(sc);
6475 fp->tpa_enable = TRUE;
6477 /* fill the TPA pool */
6478 for (j = 0; j < max_agg_queues; j++) {
6479 rc = bxe_alloc_rx_tpa_mbuf(fp, j);
6481 BLOGE(sc, "mbuf alloc fail for fp[%02d] TPA queue %d\n",
6483 fp->tpa_enable = FALSE;
6484 goto bxe_alloc_fp_buffers_error;
6487 fp->rx_tpa_info[j].state = BXE_TPA_STATE_STOP;
6490 if (fp->tpa_enable) {
6491 /* fill the RX SGE chain */
6493 for (j = 0; j < RX_SGE_USABLE; j++) {
6494 rc = bxe_alloc_rx_sge_mbuf(fp, ring_prod);
6496 BLOGE(sc, "mbuf alloc fail for fp[%02d] SGE %d\n",
6498 fp->tpa_enable = FALSE;
6500 goto bxe_alloc_fp_buffers_error;
6503 ring_prod = RX_SGE_NEXT(ring_prod);
6506 fp->rx_sge_prod = ring_prod;
6512 bxe_alloc_fp_buffers_error:
6514 /* unwind what was already allocated */
6515 bxe_free_rx_bd_chain(fp);
6516 bxe_free_tpa_pool(fp);
6517 bxe_free_sge_chain(fp);
6523 bxe_free_fw_stats_mem(struct bxe_softc *sc)
6525 bxe_dma_free(sc, &sc->fw_stats_dma);
6527 sc->fw_stats_num = 0;
6529 sc->fw_stats_req_size = 0;
6530 sc->fw_stats_req = NULL;
6531 sc->fw_stats_req_mapping = 0;
6533 sc->fw_stats_data_size = 0;
6534 sc->fw_stats_data = NULL;
6535 sc->fw_stats_data_mapping = 0;
6539 bxe_alloc_fw_stats_mem(struct bxe_softc *sc)
6541 uint8_t num_queue_stats;
6544 /* number of queues for statistics is number of eth queues */
6545 num_queue_stats = BXE_NUM_ETH_QUEUES(sc);
6548 * Total number of FW statistics requests =
6549 * 1 for port stats + 1 for PF stats + num of queues
6551 sc->fw_stats_num = (2 + num_queue_stats);
6554 * Request is built from stats_query_header and an array of
6555 * stats_query_cmd_group each of which contains STATS_QUERY_CMD_COUNT
6556 * rules. The real number or requests is configured in the
6557 * stats_query_header.
6560 ((sc->fw_stats_num / STATS_QUERY_CMD_COUNT) +
6561 ((sc->fw_stats_num % STATS_QUERY_CMD_COUNT) ? 1 : 0));
6563 BLOGD(sc, DBG_LOAD, "stats fw_stats_num %d num_groups %d\n",
6564 sc->fw_stats_num, num_groups);
6566 sc->fw_stats_req_size =
6567 (sizeof(struct stats_query_header) +
6568 (num_groups * sizeof(struct stats_query_cmd_group)));
6571 * Data for statistics requests + stats_counter.
6572 * stats_counter holds per-STORM counters that are incremented when
6573 * STORM has finished with the current request. Memory for FCoE
6574 * offloaded statistics are counted anyway, even if they will not be sent.
6575 * VF stats are not accounted for here as the data of VF stats is stored
6576 * in memory allocated by the VF, not here.
6578 sc->fw_stats_data_size =
6579 (sizeof(struct stats_counter) +
6580 sizeof(struct per_port_stats) +
6581 sizeof(struct per_pf_stats) +
6582 /* sizeof(struct fcoe_statistics_params) + */
6583 (sizeof(struct per_queue_stats) * num_queue_stats));
6585 if (bxe_dma_alloc(sc, (sc->fw_stats_req_size + sc->fw_stats_data_size),
6586 &sc->fw_stats_dma, "fw stats") != 0) {
6587 bxe_free_fw_stats_mem(sc);
6591 /* set up the shortcuts */
6594 (struct bxe_fw_stats_req *)sc->fw_stats_dma.vaddr;
6595 sc->fw_stats_req_mapping = sc->fw_stats_dma.paddr;
6598 (struct bxe_fw_stats_data *)((uint8_t *)sc->fw_stats_dma.vaddr +
6599 sc->fw_stats_req_size);
6600 sc->fw_stats_data_mapping = (sc->fw_stats_dma.paddr +
6601 sc->fw_stats_req_size);
6603 BLOGD(sc, DBG_LOAD, "statistics request base address set to %#jx\n",
6604 (uintmax_t)sc->fw_stats_req_mapping);
6606 BLOGD(sc, DBG_LOAD, "statistics data base address set to %#jx\n",
6607 (uintmax_t)sc->fw_stats_data_mapping);
6614 * 0-7 - Engine0 load counter.
6615 * 8-15 - Engine1 load counter.
6616 * 16 - Engine0 RESET_IN_PROGRESS bit.
6617 * 17 - Engine1 RESET_IN_PROGRESS bit.
6618 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active
6619 * function on the engine
6620 * 19 - Engine1 ONE_IS_LOADED.
6621 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
6622 * leader to complete (check for both RESET_IN_PROGRESS bits and not
6623 * for just the one belonging to its engine).
6625 #define BXE_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
6626 #define BXE_PATH0_LOAD_CNT_MASK 0x000000ff
6627 #define BXE_PATH0_LOAD_CNT_SHIFT 0
6628 #define BXE_PATH1_LOAD_CNT_MASK 0x0000ff00
6629 #define BXE_PATH1_LOAD_CNT_SHIFT 8
6630 #define BXE_PATH0_RST_IN_PROG_BIT 0x00010000
6631 #define BXE_PATH1_RST_IN_PROG_BIT 0x00020000
6632 #define BXE_GLOBAL_RESET_BIT 0x00040000
6634 /* set the GLOBAL_RESET bit, should be run under rtnl lock */
6636 bxe_set_reset_global(struct bxe_softc *sc)
6639 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6640 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6641 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val | BXE_GLOBAL_RESET_BIT);
6642 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6645 /* clear the GLOBAL_RESET bit, should be run under rtnl lock */
6647 bxe_clear_reset_global(struct bxe_softc *sc)
6650 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6651 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6652 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val & (~BXE_GLOBAL_RESET_BIT));
6653 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6656 /* checks the GLOBAL_RESET bit, should be run under rtnl lock */
6658 bxe_reset_is_global(struct bxe_softc *sc)
6660 uint32_t val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6661 BLOGD(sc, DBG_LOAD, "GLOB_REG=0x%08x\n", val);
6662 return (val & BXE_GLOBAL_RESET_BIT) ? TRUE : FALSE;
6665 /* clear RESET_IN_PROGRESS bit for the engine, should be run under rtnl lock */
6667 bxe_set_reset_done(struct bxe_softc *sc)
6670 uint32_t bit = SC_PATH(sc) ? BXE_PATH1_RST_IN_PROG_BIT :
6671 BXE_PATH0_RST_IN_PROG_BIT;
6673 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6675 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6678 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val);
6680 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6683 /* set RESET_IN_PROGRESS for the engine, should be run under rtnl lock */
6685 bxe_set_reset_in_progress(struct bxe_softc *sc)
6688 uint32_t bit = SC_PATH(sc) ? BXE_PATH1_RST_IN_PROG_BIT :
6689 BXE_PATH0_RST_IN_PROG_BIT;
6691 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6693 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6696 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val);
6698 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6701 /* check RESET_IN_PROGRESS bit for an engine, should be run under rtnl lock */
6703 bxe_reset_is_done(struct bxe_softc *sc,
6706 uint32_t val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6707 uint32_t bit = engine ? BXE_PATH1_RST_IN_PROG_BIT :
6708 BXE_PATH0_RST_IN_PROG_BIT;
6710 /* return false if bit is set */
6711 return (val & bit) ? FALSE : TRUE;
6714 /* get the load status for an engine, should be run under rtnl lock */
6716 bxe_get_load_status(struct bxe_softc *sc,
6719 uint32_t mask = engine ? BXE_PATH1_LOAD_CNT_MASK :
6720 BXE_PATH0_LOAD_CNT_MASK;
6721 uint32_t shift = engine ? BXE_PATH1_LOAD_CNT_SHIFT :
6722 BXE_PATH0_LOAD_CNT_SHIFT;
6723 uint32_t val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6725 BLOGD(sc, DBG_LOAD, "Old value for GLOB_REG=0x%08x\n", val);
6727 val = ((val & mask) >> shift);
6729 BLOGD(sc, DBG_LOAD, "Load mask engine %d = 0x%08x\n", engine, val);
6734 /* set pf load mark */
6735 /* XXX needs to be under rtnl lock */
6737 bxe_set_pf_load(struct bxe_softc *sc)
6741 uint32_t mask = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_MASK :
6742 BXE_PATH0_LOAD_CNT_MASK;
6743 uint32_t shift = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_SHIFT :
6744 BXE_PATH0_LOAD_CNT_SHIFT;
6746 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6748 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6749 BLOGD(sc, DBG_LOAD, "Old value for GLOB_REG=0x%08x\n", val);
6751 /* get the current counter value */
6752 val1 = ((val & mask) >> shift);
6754 /* set bit of this PF */
6755 val1 |= (1 << SC_ABS_FUNC(sc));
6757 /* clear the old value */
6760 /* set the new one */
6761 val |= ((val1 << shift) & mask);
6763 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val);
6765 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6768 /* clear pf load mark */
6769 /* XXX needs to be under rtnl lock */
6771 bxe_clear_pf_load(struct bxe_softc *sc)
6774 uint32_t mask = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_MASK :
6775 BXE_PATH0_LOAD_CNT_MASK;
6776 uint32_t shift = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_SHIFT :
6777 BXE_PATH0_LOAD_CNT_SHIFT;
6779 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6780 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6781 BLOGD(sc, DBG_LOAD, "Old GEN_REG_VAL=0x%08x\n", val);
6783 /* get the current counter value */
6784 val1 = (val & mask) >> shift;
6786 /* clear bit of that PF */
6787 val1 &= ~(1 << SC_ABS_FUNC(sc));
6789 /* clear the old value */
6792 /* set the new one */
6793 val |= ((val1 << shift) & mask);
6795 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val);
6796 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6800 /* send load requrest to mcp and analyze response */
6802 bxe_nic_load_request(struct bxe_softc *sc,
6803 uint32_t *load_code)
6807 (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_mb_header) &
6808 DRV_MSG_SEQ_NUMBER_MASK);
6810 BLOGD(sc, DBG_LOAD, "initial fw_seq 0x%04x\n", sc->fw_seq);
6812 /* get the current FW pulse sequence */
6813 sc->fw_drv_pulse_wr_seq =
6814 (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_pulse_mb) &
6815 DRV_PULSE_SEQ_MASK);
6817 BLOGD(sc, DBG_LOAD, "initial drv_pulse 0x%04x\n",
6818 sc->fw_drv_pulse_wr_seq);
6821 (*load_code) = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_REQ,
6822 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
6824 /* if the MCP fails to respond we must abort */
6825 if (!(*load_code)) {
6826 BLOGE(sc, "MCP response failure!\n");
6830 /* if MCP refused then must abort */
6831 if ((*load_code) == FW_MSG_CODE_DRV_LOAD_REFUSED) {
6832 BLOGE(sc, "MCP refused load request\n");
6840 * Check whether another PF has already loaded FW to chip. In virtualized
6841 * environments a pf from anoth VM may have already initialized the device
6842 * including loading FW.
6845 bxe_nic_load_analyze_req(struct bxe_softc *sc,
6848 uint32_t my_fw, loaded_fw;
6850 /* is another pf loaded on this engine? */
6851 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
6852 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
6853 /* build my FW version dword */
6854 my_fw = (BCM_5710_FW_MAJOR_VERSION +
6855 (BCM_5710_FW_MINOR_VERSION << 8 ) +
6856 (BCM_5710_FW_REVISION_VERSION << 16) +
6857 (BCM_5710_FW_ENGINEERING_VERSION << 24));
6859 /* read loaded FW from chip */
6860 loaded_fw = REG_RD(sc, XSEM_REG_PRAM);
6861 BLOGD(sc, DBG_LOAD, "loaded FW 0x%08x / my FW 0x%08x\n",
6864 /* abort nic load if version mismatch */
6865 if (my_fw != loaded_fw) {
6866 BLOGE(sc, "FW 0x%08x already loaded (mine is 0x%08x)",
6875 /* mark PMF if applicable */
6877 bxe_nic_load_pmf(struct bxe_softc *sc,
6880 uint32_t ncsi_oem_data_addr;
6882 if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) ||
6883 (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) ||
6884 (load_code == FW_MSG_CODE_DRV_LOAD_PORT)) {
6886 * Barrier here for ordering between the writing to sc->port.pmf here
6887 * and reading it from the periodic task.
6895 BLOGD(sc, DBG_LOAD, "pmf %d\n", sc->port.pmf);
6898 if (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) {
6899 if (SHMEM2_HAS(sc, ncsi_oem_data_addr)) {
6900 ncsi_oem_data_addr = SHMEM2_RD(sc, ncsi_oem_data_addr);
6901 if (ncsi_oem_data_addr) {
6903 (ncsi_oem_data_addr +
6904 offsetof(struct glob_ncsi_oem_data, driver_version)),
6912 bxe_read_mf_cfg(struct bxe_softc *sc)
6914 int n = (CHIP_IS_MODE_4_PORT(sc) ? 2 : 1);
6918 if (BXE_NOMCP(sc)) {
6919 return; /* what should be the default bvalue in this case */
6923 * The formula for computing the absolute function number is...
6924 * For 2 port configuration (4 functions per port):
6925 * abs_func = 2 * vn + SC_PORT + SC_PATH
6926 * For 4 port configuration (2 functions per port):
6927 * abs_func = 4 * vn + 2 * SC_PORT + SC_PATH
6929 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
6930 abs_func = (n * (2 * vn + SC_PORT(sc)) + SC_PATH(sc));
6931 if (abs_func >= E1H_FUNC_MAX) {
6934 sc->devinfo.mf_info.mf_config[vn] =
6935 MFCFG_RD(sc, func_mf_config[abs_func].config);
6938 if (sc->devinfo.mf_info.mf_config[SC_VN(sc)] &
6939 FUNC_MF_CFG_FUNC_DISABLED) {
6940 BLOGD(sc, DBG_LOAD, "mf_cfg function disabled\n");
6941 sc->flags |= BXE_MF_FUNC_DIS;
6943 BLOGD(sc, DBG_LOAD, "mf_cfg function enabled\n");
6944 sc->flags &= ~BXE_MF_FUNC_DIS;
6948 /* acquire split MCP access lock register */
6949 static int bxe_acquire_alr(struct bxe_softc *sc)
6953 for (j = 0; j < 1000; j++) {
6955 REG_WR(sc, GRCBASE_MCP + 0x9c, val);
6956 val = REG_RD(sc, GRCBASE_MCP + 0x9c);
6957 if (val & (1L << 31))
6963 if (!(val & (1L << 31))) {
6964 BLOGE(sc, "Cannot acquire MCP access lock register\n");
6971 /* release split MCP access lock register */
6972 static void bxe_release_alr(struct bxe_softc *sc)
6974 REG_WR(sc, GRCBASE_MCP + 0x9c, 0);
6978 bxe_fan_failure(struct bxe_softc *sc)
6980 int port = SC_PORT(sc);
6981 uint32_t ext_phy_config;
6983 /* mark the failure */
6985 SHMEM_RD(sc, dev_info.port_hw_config[port].external_phy_config);
6987 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
6988 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
6989 SHMEM_WR(sc, dev_info.port_hw_config[port].external_phy_config,
6992 /* log the failure */
6993 BLOGW(sc, "Fan Failure has caused the driver to shutdown "
6994 "the card to prevent permanent damage. "
6995 "Please contact OEM Support for assistance\n");
6999 bxe_panic(sc, ("Schedule task to handle fan failure\n"));
7002 * Schedule device reset (unload)
7003 * This is due to some boards consuming sufficient power when driver is
7004 * up to overheat if fan fails.
7006 bxe_set_bit(BXE_SP_RTNL_FAN_FAILURE, &sc->sp_rtnl_state);
7007 schedule_delayed_work(&sc->sp_rtnl_task, 0);
7011 /* this function is called upon a link interrupt */
7013 bxe_link_attn(struct bxe_softc *sc)
7015 uint32_t pause_enabled = 0;
7016 struct host_port_stats *pstats;
7019 /* Make sure that we are synced with the current statistics */
7020 bxe_stats_handle(sc, STATS_EVENT_STOP);
7021 BLOGI(sc, "link_vars phy_flags : %x\n", sc->link_vars.phy_flags);
7022 elink_link_update(&sc->link_params, &sc->link_vars);
7024 if (sc->link_vars.link_up) {
7026 /* dropless flow control */
7027 if (!CHIP_IS_E1(sc) && sc->dropless_fc) {
7030 if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_TX) {
7035 (BAR_USTRORM_INTMEM +
7036 USTORM_ETH_PAUSE_ENABLED_OFFSET(SC_PORT(sc))),
7040 if (sc->link_vars.mac_type != ELINK_MAC_TYPE_EMAC) {
7041 pstats = BXE_SP(sc, port_stats);
7042 /* reset old mac stats */
7043 memset(&(pstats->mac_stx[0]), 0, sizeof(struct mac_stx));
7046 if (sc->state == BXE_STATE_OPEN) {
7047 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
7051 if (sc->link_vars.link_up && sc->link_vars.line_speed) {
7052 cmng_fns = bxe_get_cmng_fns_mode(sc);
7054 if (cmng_fns != CMNG_FNS_NONE) {
7055 bxe_cmng_fns_init(sc, FALSE, cmng_fns);
7056 storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc));
7058 /* rate shaping and fairness are disabled */
7059 BLOGD(sc, DBG_LOAD, "single function mode without fairness\n");
7063 bxe_link_report_locked(sc);
7066 ; // XXX bxe_link_sync_notify(sc);
7071 bxe_attn_int_asserted(struct bxe_softc *sc,
7074 int port = SC_PORT(sc);
7075 uint32_t aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
7076 MISC_REG_AEU_MASK_ATTN_FUNC_0;
7077 uint32_t nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
7078 NIG_REG_MASK_INTERRUPT_PORT0;
7080 uint32_t nig_mask = 0;
7085 if (sc->attn_state & asserted) {
7086 BLOGE(sc, "IGU ERROR attn=0x%08x\n", asserted);
7089 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
7091 aeu_mask = REG_RD(sc, aeu_addr);
7093 BLOGD(sc, DBG_INTR, "aeu_mask 0x%08x newly asserted 0x%08x\n",
7094 aeu_mask, asserted);
7096 aeu_mask &= ~(asserted & 0x3ff);
7098 BLOGD(sc, DBG_INTR, "new mask 0x%08x\n", aeu_mask);
7100 REG_WR(sc, aeu_addr, aeu_mask);
7102 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
7104 BLOGD(sc, DBG_INTR, "attn_state 0x%08x\n", sc->attn_state);
7105 sc->attn_state |= asserted;
7106 BLOGD(sc, DBG_INTR, "new state 0x%08x\n", sc->attn_state);
7108 if (asserted & ATTN_HARD_WIRED_MASK) {
7109 if (asserted & ATTN_NIG_FOR_FUNC) {
7111 bxe_acquire_phy_lock(sc);
7112 /* save nig interrupt mask */
7113 nig_mask = REG_RD(sc, nig_int_mask_addr);
7115 /* If nig_mask is not set, no need to call the update function */
7117 REG_WR(sc, nig_int_mask_addr, 0);
7122 /* handle unicore attn? */
7125 if (asserted & ATTN_SW_TIMER_4_FUNC) {
7126 BLOGD(sc, DBG_INTR, "ATTN_SW_TIMER_4_FUNC!\n");
7129 if (asserted & GPIO_2_FUNC) {
7130 BLOGD(sc, DBG_INTR, "GPIO_2_FUNC!\n");
7133 if (asserted & GPIO_3_FUNC) {
7134 BLOGD(sc, DBG_INTR, "GPIO_3_FUNC!\n");
7137 if (asserted & GPIO_4_FUNC) {
7138 BLOGD(sc, DBG_INTR, "GPIO_4_FUNC!\n");
7142 if (asserted & ATTN_GENERAL_ATTN_1) {
7143 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_1!\n");
7144 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
7146 if (asserted & ATTN_GENERAL_ATTN_2) {
7147 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_2!\n");
7148 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
7150 if (asserted & ATTN_GENERAL_ATTN_3) {
7151 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_3!\n");
7152 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
7155 if (asserted & ATTN_GENERAL_ATTN_4) {
7156 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_4!\n");
7157 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
7159 if (asserted & ATTN_GENERAL_ATTN_5) {
7160 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_5!\n");
7161 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
7163 if (asserted & ATTN_GENERAL_ATTN_6) {
7164 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_6!\n");
7165 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
7170 if (sc->devinfo.int_block == INT_BLOCK_HC) {
7171 reg_addr = (HC_REG_COMMAND_REG + port*32 + COMMAND_REG_ATTN_BITS_SET);
7173 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
7176 BLOGD(sc, DBG_INTR, "about to mask 0x%08x at %s addr 0x%08x\n",
7178 (sc->devinfo.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
7179 REG_WR(sc, reg_addr, asserted);
7181 /* now set back the mask */
7182 if (asserted & ATTN_NIG_FOR_FUNC) {
7184 * Verify that IGU ack through BAR was written before restoring
7185 * NIG mask. This loop should exit after 2-3 iterations max.
7187 if (sc->devinfo.int_block != INT_BLOCK_HC) {
7191 igu_acked = REG_RD(sc, IGU_REG_ATTENTION_ACK_BITS);
7192 } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
7193 (++cnt < MAX_IGU_ATTN_ACK_TO));
7196 BLOGE(sc, "Failed to verify IGU ack on time\n");
7202 REG_WR(sc, nig_int_mask_addr, nig_mask);
7204 bxe_release_phy_lock(sc);
7209 bxe_print_next_block(struct bxe_softc *sc,
7213 BLOGI(sc, "%s%s", idx ? ", " : "", blk);
7217 bxe_check_blocks_with_parity0(struct bxe_softc *sc,
7222 uint32_t cur_bit = 0;
7225 for (i = 0; sig; i++) {
7226 cur_bit = ((uint32_t)0x1 << i);
7227 if (sig & cur_bit) {
7229 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
7231 bxe_print_next_block(sc, par_num++, "BRB");
7233 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
7235 bxe_print_next_block(sc, par_num++, "PARSER");
7237 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
7239 bxe_print_next_block(sc, par_num++, "TSDM");
7241 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
7243 bxe_print_next_block(sc, par_num++, "SEARCHER");
7245 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
7247 bxe_print_next_block(sc, par_num++, "TCM");
7249 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
7251 bxe_print_next_block(sc, par_num++, "TSEMI");
7253 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
7255 bxe_print_next_block(sc, par_num++, "XPB");
7268 bxe_check_blocks_with_parity1(struct bxe_softc *sc,
7275 uint32_t cur_bit = 0;
7276 for (i = 0; sig; i++) {
7277 cur_bit = ((uint32_t)0x1 << i);
7278 if (sig & cur_bit) {
7280 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
7282 bxe_print_next_block(sc, par_num++, "PBF");
7284 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
7286 bxe_print_next_block(sc, par_num++, "QM");
7288 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
7290 bxe_print_next_block(sc, par_num++, "TM");
7292 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
7294 bxe_print_next_block(sc, par_num++, "XSDM");
7296 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
7298 bxe_print_next_block(sc, par_num++, "XCM");
7300 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
7302 bxe_print_next_block(sc, par_num++, "XSEMI");
7304 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
7306 bxe_print_next_block(sc, par_num++, "DOORBELLQ");
7308 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
7310 bxe_print_next_block(sc, par_num++, "NIG");
7312 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
7314 bxe_print_next_block(sc, par_num++, "VAUX PCI CORE");
7317 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
7319 bxe_print_next_block(sc, par_num++, "DEBUG");
7321 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
7323 bxe_print_next_block(sc, par_num++, "USDM");
7325 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
7327 bxe_print_next_block(sc, par_num++, "UCM");
7329 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
7331 bxe_print_next_block(sc, par_num++, "USEMI");
7333 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
7335 bxe_print_next_block(sc, par_num++, "UPB");
7337 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
7339 bxe_print_next_block(sc, par_num++, "CSDM");
7341 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
7343 bxe_print_next_block(sc, par_num++, "CCM");
7356 bxe_check_blocks_with_parity2(struct bxe_softc *sc,
7361 uint32_t cur_bit = 0;
7364 for (i = 0; sig; i++) {
7365 cur_bit = ((uint32_t)0x1 << i);
7366 if (sig & cur_bit) {
7368 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
7370 bxe_print_next_block(sc, par_num++, "CSEMI");
7372 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
7374 bxe_print_next_block(sc, par_num++, "PXP");
7376 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
7378 bxe_print_next_block(sc, par_num++, "PXPPCICLOCKCLIENT");
7380 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
7382 bxe_print_next_block(sc, par_num++, "CFC");
7384 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
7386 bxe_print_next_block(sc, par_num++, "CDU");
7388 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
7390 bxe_print_next_block(sc, par_num++, "DMAE");
7392 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
7394 bxe_print_next_block(sc, par_num++, "IGU");
7396 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
7398 bxe_print_next_block(sc, par_num++, "MISC");
7411 bxe_check_blocks_with_parity3(struct bxe_softc *sc,
7417 uint32_t cur_bit = 0;
7420 for (i = 0; sig; i++) {
7421 cur_bit = ((uint32_t)0x1 << i);
7422 if (sig & cur_bit) {
7424 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
7426 bxe_print_next_block(sc, par_num++, "MCP ROM");
7429 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
7431 bxe_print_next_block(sc, par_num++,
7435 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
7437 bxe_print_next_block(sc, par_num++,
7441 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
7443 bxe_print_next_block(sc, par_num++,
7458 bxe_check_blocks_with_parity4(struct bxe_softc *sc,
7463 uint32_t cur_bit = 0;
7466 for (i = 0; sig; i++) {
7467 cur_bit = ((uint32_t)0x1 << i);
7468 if (sig & cur_bit) {
7470 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
7472 bxe_print_next_block(sc, par_num++, "PGLUE_B");
7474 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
7476 bxe_print_next_block(sc, par_num++, "ATC");
7489 bxe_parity_attn(struct bxe_softc *sc,
7496 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
7497 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
7498 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
7499 (sig[3] & HW_PRTY_ASSERT_SET_3) ||
7500 (sig[4] & HW_PRTY_ASSERT_SET_4)) {
7501 BLOGE(sc, "Parity error: HW block parity attention:\n"
7502 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
7503 (uint32_t)(sig[0] & HW_PRTY_ASSERT_SET_0),
7504 (uint32_t)(sig[1] & HW_PRTY_ASSERT_SET_1),
7505 (uint32_t)(sig[2] & HW_PRTY_ASSERT_SET_2),
7506 (uint32_t)(sig[3] & HW_PRTY_ASSERT_SET_3),
7507 (uint32_t)(sig[4] & HW_PRTY_ASSERT_SET_4));
7510 BLOGI(sc, "Parity errors detected in blocks: ");
7513 bxe_check_blocks_with_parity0(sc, sig[0] &
7514 HW_PRTY_ASSERT_SET_0,
7517 bxe_check_blocks_with_parity1(sc, sig[1] &
7518 HW_PRTY_ASSERT_SET_1,
7519 par_num, global, print);
7521 bxe_check_blocks_with_parity2(sc, sig[2] &
7522 HW_PRTY_ASSERT_SET_2,
7525 bxe_check_blocks_with_parity3(sc, sig[3] &
7526 HW_PRTY_ASSERT_SET_3,
7527 par_num, global, print);
7529 bxe_check_blocks_with_parity4(sc, sig[4] &
7530 HW_PRTY_ASSERT_SET_4,
7543 bxe_chk_parity_attn(struct bxe_softc *sc,
7547 struct attn_route attn = { {0} };
7548 int port = SC_PORT(sc);
7550 attn.sig[0] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
7551 attn.sig[1] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
7552 attn.sig[2] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
7553 attn.sig[3] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
7556 * Since MCP attentions can't be disabled inside the block, we need to
7557 * read AEU registers to see whether they're currently disabled
7559 attn.sig[3] &= ((REG_RD(sc, (!port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
7560 : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0)) &
7561 MISC_AEU_ENABLE_MCP_PRTY_BITS) |
7562 ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
7565 if (!CHIP_IS_E1x(sc))
7566 attn.sig[4] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
7568 return (bxe_parity_attn(sc, global, print, attn.sig));
7572 bxe_attn_int_deasserted4(struct bxe_softc *sc,
7577 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
7578 val = REG_RD(sc, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
7579 BLOGE(sc, "PGLUE hw attention 0x%08x\n", val);
7580 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
7581 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
7582 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
7583 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
7584 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
7585 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
7586 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
7587 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
7588 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
7589 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
7590 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
7591 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
7592 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
7593 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
7594 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
7595 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
7596 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
7597 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
7600 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
7601 val = REG_RD(sc, ATC_REG_ATC_INT_STS_CLR);
7602 BLOGE(sc, "ATC hw attention 0x%08x\n", val);
7603 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
7604 BLOGE(sc, "ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
7605 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
7606 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
7607 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
7608 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
7609 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
7610 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
7611 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
7612 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
7613 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
7614 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
7617 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
7618 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
7619 BLOGE(sc, "FATAL parity attention set4 0x%08x\n",
7620 (uint32_t)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
7621 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
7626 bxe_e1h_disable(struct bxe_softc *sc)
7628 int port = SC_PORT(sc);
7632 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 0);
7636 bxe_e1h_enable(struct bxe_softc *sc)
7638 int port = SC_PORT(sc);
7640 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 1);
7642 // XXX bxe_tx_enable(sc);
7646 * called due to MCP event (on pmf):
7647 * reread new bandwidth configuration
7649 * notify others function about the change
7652 bxe_config_mf_bw(struct bxe_softc *sc)
7654 if (sc->link_vars.link_up) {
7655 bxe_cmng_fns_init(sc, TRUE, CMNG_FNS_MINMAX);
7656 // XXX bxe_link_sync_notify(sc);
7659 storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc));
7663 bxe_set_mf_bw(struct bxe_softc *sc)
7665 bxe_config_mf_bw(sc);
7666 bxe_fw_command(sc, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
7670 bxe_handle_eee_event(struct bxe_softc *sc)
7672 BLOGD(sc, DBG_INTR, "EEE - LLDP event\n");
7673 bxe_fw_command(sc, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
7676 #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
7679 bxe_drv_info_ether_stat(struct bxe_softc *sc)
7681 struct eth_stats_info *ether_stat =
7682 &sc->sp->drv_info_to_mcp.ether_stat;
7684 strlcpy(ether_stat->version, BXE_DRIVER_VERSION,
7685 ETH_STAT_INFO_VERSION_LEN);
7687 /* XXX (+ MAC_PAD) taken from other driver... verify this is right */
7688 sc->sp_objs[0].mac_obj.get_n_elements(sc, &sc->sp_objs[0].mac_obj,
7689 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
7690 ether_stat->mac_local + MAC_PAD,
7693 ether_stat->mtu_size = sc->mtu;
7695 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
7696 if (sc->ifnet->if_capenable & (IFCAP_TSO4 | IFCAP_TSO6)) {
7697 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
7700 // XXX ether_stat->feature_flags |= ???;
7702 ether_stat->promiscuous_mode = 0; // (flags & PROMISC) ? 1 : 0;
7704 ether_stat->txq_size = sc->tx_ring_size;
7705 ether_stat->rxq_size = sc->rx_ring_size;
7709 bxe_handle_drv_info_req(struct bxe_softc *sc)
7711 enum drv_info_opcode op_code;
7712 uint32_t drv_info_ctl = SHMEM2_RD(sc, drv_info_control);
7714 /* if drv_info version supported by MFW doesn't match - send NACK */
7715 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
7716 bxe_fw_command(sc, DRV_MSG_CODE_DRV_INFO_NACK, 0);
7720 op_code = ((drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
7721 DRV_INFO_CONTROL_OP_CODE_SHIFT);
7723 memset(&sc->sp->drv_info_to_mcp, 0, sizeof(union drv_info_to_mcp));
7726 case ETH_STATS_OPCODE:
7727 bxe_drv_info_ether_stat(sc);
7729 case FCOE_STATS_OPCODE:
7730 case ISCSI_STATS_OPCODE:
7732 /* if op code isn't supported - send NACK */
7733 bxe_fw_command(sc, DRV_MSG_CODE_DRV_INFO_NACK, 0);
7738 * If we got drv_info attn from MFW then these fields are defined in
7741 SHMEM2_WR(sc, drv_info_host_addr_lo,
7742 U64_LO(BXE_SP_MAPPING(sc, drv_info_to_mcp)));
7743 SHMEM2_WR(sc, drv_info_host_addr_hi,
7744 U64_HI(BXE_SP_MAPPING(sc, drv_info_to_mcp)));
7746 bxe_fw_command(sc, DRV_MSG_CODE_DRV_INFO_ACK, 0);
7750 bxe_dcc_event(struct bxe_softc *sc,
7753 BLOGD(sc, DBG_INTR, "dcc_event 0x%08x\n", dcc_event);
7755 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
7757 * This is the only place besides the function initialization
7758 * where the sc->flags can change so it is done without any
7761 if (sc->devinfo.mf_info.mf_config[SC_VN(sc)] & FUNC_MF_CFG_FUNC_DISABLED) {
7762 BLOGD(sc, DBG_INTR, "mf_cfg function disabled\n");
7763 sc->flags |= BXE_MF_FUNC_DIS;
7764 bxe_e1h_disable(sc);
7766 BLOGD(sc, DBG_INTR, "mf_cfg function enabled\n");
7767 sc->flags &= ~BXE_MF_FUNC_DIS;
7770 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
7773 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
7774 bxe_config_mf_bw(sc);
7775 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
7778 /* Report results to MCP */
7780 bxe_fw_command(sc, DRV_MSG_CODE_DCC_FAILURE, 0);
7782 bxe_fw_command(sc, DRV_MSG_CODE_DCC_OK, 0);
7786 bxe_pmf_update(struct bxe_softc *sc)
7788 int port = SC_PORT(sc);
7792 BLOGD(sc, DBG_INTR, "pmf %d\n", sc->port.pmf);
7795 * We need the mb() to ensure the ordering between the writing to
7796 * sc->port.pmf here and reading it from the bxe_periodic_task().
7800 /* queue a periodic task */
7801 // XXX schedule task...
7803 // XXX bxe_dcbx_pmf_update(sc);
7805 /* enable nig attention */
7806 val = (0xff0f | (1 << (SC_VN(sc) + 4)));
7807 if (sc->devinfo.int_block == INT_BLOCK_HC) {
7808 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, val);
7809 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, val);
7810 } else if (!CHIP_IS_E1x(sc)) {
7811 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, val);
7812 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, val);
7815 bxe_stats_handle(sc, STATS_EVENT_PMF);
7819 bxe_mc_assert(struct bxe_softc *sc)
7823 uint32_t row0, row1, row2, row3;
7826 last_idx = REG_RD8(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_INDEX_OFFSET);
7828 BLOGE(sc, "XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
7830 /* print the asserts */
7831 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
7833 row0 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i));
7834 row1 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) + 4);
7835 row2 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) + 8);
7836 row3 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) + 12);
7838 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
7839 BLOGE(sc, "XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
7840 i, row3, row2, row1, row0);
7848 last_idx = REG_RD8(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_INDEX_OFFSET);
7850 BLOGE(sc, "TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
7853 /* print the asserts */
7854 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
7856 row0 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i));
7857 row1 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) + 4);
7858 row2 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) + 8);
7859 row3 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) + 12);
7861 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
7862 BLOGE(sc, "TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
7863 i, row3, row2, row1, row0);
7871 last_idx = REG_RD8(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_INDEX_OFFSET);
7873 BLOGE(sc, "CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
7876 /* print the asserts */
7877 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
7879 row0 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i));
7880 row1 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) + 4);
7881 row2 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) + 8);
7882 row3 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) + 12);
7884 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
7885 BLOGE(sc, "CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
7886 i, row3, row2, row1, row0);
7894 last_idx = REG_RD8(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_INDEX_OFFSET);
7896 BLOGE(sc, "USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
7899 /* print the asserts */
7900 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
7902 row0 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i));
7903 row1 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) + 4);
7904 row2 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) + 8);
7905 row3 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) + 12);
7907 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
7908 BLOGE(sc, "USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
7909 i, row3, row2, row1, row0);
7920 bxe_attn_int_deasserted3(struct bxe_softc *sc,
7923 int func = SC_FUNC(sc);
7926 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
7928 if (attn & BXE_PMF_LINK_ASSERT(sc)) {
7930 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7931 bxe_read_mf_cfg(sc);
7932 sc->devinfo.mf_info.mf_config[SC_VN(sc)] =
7933 MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config);
7934 val = SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_status);
7936 if (val & DRV_STATUS_DCC_EVENT_MASK)
7937 bxe_dcc_event(sc, (val & DRV_STATUS_DCC_EVENT_MASK));
7939 if (val & DRV_STATUS_SET_MF_BW)
7942 if (val & DRV_STATUS_DRV_INFO_REQ)
7943 bxe_handle_drv_info_req(sc);
7945 if ((sc->port.pmf == 0) && (val & DRV_STATUS_PMF))
7948 if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
7949 bxe_handle_eee_event(sc);
7951 if (sc->link_vars.periodic_flags &
7952 ELINK_PERIODIC_FLAGS_LINK_EVENT) {
7953 /* sync with link */
7954 bxe_acquire_phy_lock(sc);
7955 sc->link_vars.periodic_flags &=
7956 ~ELINK_PERIODIC_FLAGS_LINK_EVENT;
7957 bxe_release_phy_lock(sc);
7959 ; // XXX bxe_link_sync_notify(sc);
7960 bxe_link_report(sc);
7964 * Always call it here: bxe_link_report() will
7965 * prevent the link indication duplication.
7967 bxe_link_status_update(sc);
7969 } else if (attn & BXE_MC_ASSERT_BITS) {
7971 BLOGE(sc, "MC assert!\n");
7973 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_10, 0);
7974 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_9, 0);
7975 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_8, 0);
7976 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_7, 0);
7977 bxe_panic(sc, ("MC assert!\n"));
7979 } else if (attn & BXE_MCP_ASSERT) {
7981 BLOGE(sc, "MCP assert!\n");
7982 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_11, 0);
7983 // XXX bxe_fw_dump(sc);
7986 BLOGE(sc, "Unknown HW assert! (attn 0x%08x)\n", attn);
7990 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
7991 BLOGE(sc, "LATCHED attention 0x%08x (masked)\n", attn);
7992 if (attn & BXE_GRC_TIMEOUT) {
7993 val = CHIP_IS_E1(sc) ? 0 : REG_RD(sc, MISC_REG_GRC_TIMEOUT_ATTN);
7994 BLOGE(sc, "GRC time-out 0x%08x\n", val);
7996 if (attn & BXE_GRC_RSV) {
7997 val = CHIP_IS_E1(sc) ? 0 : REG_RD(sc, MISC_REG_GRC_RSV_ATTN);
7998 BLOGE(sc, "GRC reserved 0x%08x\n", val);
8000 REG_WR(sc, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
8005 bxe_attn_int_deasserted2(struct bxe_softc *sc,
8008 int port = SC_PORT(sc);
8010 uint32_t val0, mask0, val1, mask1;
8013 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
8014 val = REG_RD(sc, CFC_REG_CFC_INT_STS_CLR);
8015 BLOGE(sc, "CFC hw attention 0x%08x\n", val);
8016 /* CFC error attention */
8018 BLOGE(sc, "FATAL error from CFC\n");
8022 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
8023 val = REG_RD(sc, PXP_REG_PXP_INT_STS_CLR_0);
8024 BLOGE(sc, "PXP hw attention-0 0x%08x\n", val);
8025 /* RQ_USDMDP_FIFO_OVERFLOW */
8026 if (val & 0x18000) {
8027 BLOGE(sc, "FATAL error from PXP\n");
8030 if (!CHIP_IS_E1x(sc)) {
8031 val = REG_RD(sc, PXP_REG_PXP_INT_STS_CLR_1);
8032 BLOGE(sc, "PXP hw attention-1 0x%08x\n", val);
8036 #define PXP2_EOP_ERROR_BIT PXP2_PXP2_INT_STS_CLR_0_REG_WR_PGLUE_EOP_ERROR
8037 #define AEU_PXP2_HW_INT_BIT AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_HW_INTERRUPT
8039 if (attn & AEU_PXP2_HW_INT_BIT) {
8040 /* CQ47854 workaround do not panic on
8041 * PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR
8043 if (!CHIP_IS_E1x(sc)) {
8044 mask0 = REG_RD(sc, PXP2_REG_PXP2_INT_MASK_0);
8045 val1 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_1);
8046 mask1 = REG_RD(sc, PXP2_REG_PXP2_INT_MASK_1);
8047 val0 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_0);
8049 * If the olny PXP2_EOP_ERROR_BIT is set in
8050 * STS0 and STS1 - clear it
8052 * probably we lose additional attentions between
8053 * STS0 and STS_CLR0, in this case user will not
8054 * be notified about them
8056 if (val0 & mask0 & PXP2_EOP_ERROR_BIT &&
8058 val0 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_CLR_0);
8060 /* print the register, since no one can restore it */
8061 BLOGE(sc, "PXP2_REG_PXP2_INT_STS_CLR_0 0x%08x\n", val0);
8064 * if PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR
8067 if (val0 & PXP2_EOP_ERROR_BIT) {
8068 BLOGE(sc, "PXP2_WR_PGLUE_EOP_ERROR\n");
8071 * if only PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR is
8072 * set then clear attention from PXP2 block without panic
8074 if (((val0 & mask0) == PXP2_EOP_ERROR_BIT) &&
8075 ((val1 & mask1) == 0))
8076 attn &= ~AEU_PXP2_HW_INT_BIT;
8081 if (attn & HW_INTERRUT_ASSERT_SET_2) {
8082 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
8083 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
8085 val = REG_RD(sc, reg_offset);
8086 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
8087 REG_WR(sc, reg_offset, val);
8089 BLOGE(sc, "FATAL HW block attention set2 0x%x\n",
8090 (uint32_t)(attn & HW_INTERRUT_ASSERT_SET_2));
8091 bxe_panic(sc, ("HW block attention set2\n"));
8096 bxe_attn_int_deasserted1(struct bxe_softc *sc,
8099 int port = SC_PORT(sc);
8103 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
8104 val = REG_RD(sc, DORQ_REG_DORQ_INT_STS_CLR);
8105 BLOGE(sc, "DB hw attention 0x%08x\n", val);
8106 /* DORQ discard attention */
8108 BLOGE(sc, "FATAL error from DORQ\n");
8112 if (attn & HW_INTERRUT_ASSERT_SET_1) {
8113 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
8114 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
8116 val = REG_RD(sc, reg_offset);
8117 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
8118 REG_WR(sc, reg_offset, val);
8120 BLOGE(sc, "FATAL HW block attention set1 0x%08x\n",
8121 (uint32_t)(attn & HW_INTERRUT_ASSERT_SET_1));
8122 bxe_panic(sc, ("HW block attention set1\n"));
8127 bxe_attn_int_deasserted0(struct bxe_softc *sc,
8130 int port = SC_PORT(sc);
8134 reg_offset = (port) ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
8135 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
8137 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
8138 val = REG_RD(sc, reg_offset);
8139 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
8140 REG_WR(sc, reg_offset, val);
8142 BLOGW(sc, "SPIO5 hw attention\n");
8144 /* Fan failure attention */
8145 elink_hw_reset_phy(&sc->link_params);
8146 bxe_fan_failure(sc);
8149 if ((attn & sc->link_vars.aeu_int_mask) && sc->port.pmf) {
8150 bxe_acquire_phy_lock(sc);
8151 elink_handle_module_detect_int(&sc->link_params);
8152 bxe_release_phy_lock(sc);
8155 if (attn & HW_INTERRUT_ASSERT_SET_0) {
8156 val = REG_RD(sc, reg_offset);
8157 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
8158 REG_WR(sc, reg_offset, val);
8160 bxe_panic(sc, ("FATAL HW block attention set0 0x%lx\n",
8161 (attn & HW_INTERRUT_ASSERT_SET_0)));
8166 bxe_attn_int_deasserted(struct bxe_softc *sc,
8167 uint32_t deasserted)
8169 struct attn_route attn;
8170 struct attn_route *group_mask;
8171 int port = SC_PORT(sc);
8176 uint8_t global = FALSE;
8179 * Need to take HW lock because MCP or other port might also
8180 * try to handle this event.
8182 bxe_acquire_alr(sc);
8184 if (bxe_chk_parity_attn(sc, &global, TRUE)) {
8186 * In case of parity errors don't handle attentions so that
8187 * other function would "see" parity errors.
8189 sc->recovery_state = BXE_RECOVERY_INIT;
8190 // XXX schedule a recovery task...
8191 /* disable HW interrupts */
8192 bxe_int_disable(sc);
8193 bxe_release_alr(sc);
8197 attn.sig[0] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
8198 attn.sig[1] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
8199 attn.sig[2] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
8200 attn.sig[3] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
8201 if (!CHIP_IS_E1x(sc)) {
8202 attn.sig[4] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
8207 BLOGD(sc, DBG_INTR, "attn: 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
8208 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
8210 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
8211 if (deasserted & (1 << index)) {
8212 group_mask = &sc->attn_group[index];
8215 "group[%d]: 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n", index,
8216 group_mask->sig[0], group_mask->sig[1],
8217 group_mask->sig[2], group_mask->sig[3],
8218 group_mask->sig[4]);
8220 bxe_attn_int_deasserted4(sc, attn.sig[4] & group_mask->sig[4]);
8221 bxe_attn_int_deasserted3(sc, attn.sig[3] & group_mask->sig[3]);
8222 bxe_attn_int_deasserted1(sc, attn.sig[1] & group_mask->sig[1]);
8223 bxe_attn_int_deasserted2(sc, attn.sig[2] & group_mask->sig[2]);
8224 bxe_attn_int_deasserted0(sc, attn.sig[0] & group_mask->sig[0]);
8228 bxe_release_alr(sc);
8230 if (sc->devinfo.int_block == INT_BLOCK_HC) {
8231 reg_addr = (HC_REG_COMMAND_REG + port*32 +
8232 COMMAND_REG_ATTN_BITS_CLR);
8234 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
8239 "about to mask 0x%08x at %s addr 0x%08x\n", val,
8240 (sc->devinfo.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
8241 REG_WR(sc, reg_addr, val);
8243 if (~sc->attn_state & deasserted) {
8244 BLOGE(sc, "IGU error\n");
8247 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8248 MISC_REG_AEU_MASK_ATTN_FUNC_0;
8250 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
8252 aeu_mask = REG_RD(sc, reg_addr);
8254 BLOGD(sc, DBG_INTR, "aeu_mask 0x%08x newly deasserted 0x%08x\n",
8255 aeu_mask, deasserted);
8256 aeu_mask |= (deasserted & 0x3ff);
8257 BLOGD(sc, DBG_INTR, "new mask 0x%08x\n", aeu_mask);
8259 REG_WR(sc, reg_addr, aeu_mask);
8260 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
8262 BLOGD(sc, DBG_INTR, "attn_state 0x%08x\n", sc->attn_state);
8263 sc->attn_state &= ~deasserted;
8264 BLOGD(sc, DBG_INTR, "new state 0x%08x\n", sc->attn_state);
8268 bxe_attn_int(struct bxe_softc *sc)
8270 /* read local copy of bits */
8271 uint32_t attn_bits = le32toh(sc->def_sb->atten_status_block.attn_bits);
8272 uint32_t attn_ack = le32toh(sc->def_sb->atten_status_block.attn_bits_ack);
8273 uint32_t attn_state = sc->attn_state;
8275 /* look for changed bits */
8276 uint32_t asserted = attn_bits & ~attn_ack & ~attn_state;
8277 uint32_t deasserted = ~attn_bits & attn_ack & attn_state;
8280 "attn_bits 0x%08x attn_ack 0x%08x asserted 0x%08x deasserted 0x%08x\n",
8281 attn_bits, attn_ack, asserted, deasserted);
8283 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state)) {
8284 BLOGE(sc, "BAD attention state\n");
8287 /* handle bits that were raised */
8289 bxe_attn_int_asserted(sc, asserted);
8293 bxe_attn_int_deasserted(sc, deasserted);
8298 bxe_update_dsb_idx(struct bxe_softc *sc)
8300 struct host_sp_status_block *def_sb = sc->def_sb;
8303 mb(); /* status block is written to by the chip */
8305 if (sc->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
8306 sc->def_att_idx = def_sb->atten_status_block.attn_bits_index;
8307 rc |= BXE_DEF_SB_ATT_IDX;
8310 if (sc->def_idx != def_sb->sp_sb.running_index) {
8311 sc->def_idx = def_sb->sp_sb.running_index;
8312 rc |= BXE_DEF_SB_IDX;
8320 static inline struct ecore_queue_sp_obj *
8321 bxe_cid_to_q_obj(struct bxe_softc *sc,
8324 BLOGD(sc, DBG_SP, "retrieving fp from cid %d\n", cid);
8325 return (&sc->sp_objs[CID_TO_FP(cid, sc)].q_obj);
8329 bxe_handle_mcast_eqe(struct bxe_softc *sc)
8331 struct ecore_mcast_ramrod_params rparam;
8334 memset(&rparam, 0, sizeof(rparam));
8336 rparam.mcast_obj = &sc->mcast_obj;
8340 /* clear pending state for the last command */
8341 sc->mcast_obj.raw.clear_pending(&sc->mcast_obj.raw);
8343 /* if there are pending mcast commands - send them */
8344 if (sc->mcast_obj.check_pending(&sc->mcast_obj)) {
8345 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT);
8348 "ERROR: Failed to send pending mcast commands (%d)\n", rc);
8352 BXE_MCAST_UNLOCK(sc);
8356 bxe_handle_classification_eqe(struct bxe_softc *sc,
8357 union event_ring_elem *elem)
8359 unsigned long ramrod_flags = 0;
8361 uint32_t cid = elem->message.data.eth_event.echo & BXE_SWCID_MASK;
8362 struct ecore_vlan_mac_obj *vlan_mac_obj;
8364 /* always push next commands out, don't wait here */
8365 bit_set(&ramrod_flags, RAMROD_CONT);
8367 switch (le32toh(elem->message.data.eth_event.echo) >> BXE_SWCID_SHIFT) {
8368 case ECORE_FILTER_MAC_PENDING:
8369 BLOGD(sc, DBG_SP, "Got SETUP_MAC completions\n");
8370 vlan_mac_obj = &sc->sp_objs[cid].mac_obj;
8373 case ECORE_FILTER_MCAST_PENDING:
8374 BLOGD(sc, DBG_SP, "Got SETUP_MCAST completions\n");
8376 * This is only relevant for 57710 where multicast MACs are
8377 * configured as unicast MACs using the same ramrod.
8379 bxe_handle_mcast_eqe(sc);
8383 BLOGE(sc, "Unsupported classification command: %d\n",
8384 elem->message.data.eth_event.echo);
8388 rc = vlan_mac_obj->complete(sc, vlan_mac_obj, elem, &ramrod_flags);
8391 BLOGE(sc, "Failed to schedule new commands (%d)\n", rc);
8392 } else if (rc > 0) {
8393 BLOGD(sc, DBG_SP, "Scheduled next pending commands...\n");
8398 bxe_handle_rx_mode_eqe(struct bxe_softc *sc,
8399 union event_ring_elem *elem)
8401 bxe_clear_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state);
8403 /* send rx_mode command again if was requested */
8404 if (bxe_test_and_clear_bit(ECORE_FILTER_RX_MODE_SCHED,
8406 bxe_set_storm_rx_mode(sc);
8411 bxe_update_eq_prod(struct bxe_softc *sc,
8414 storm_memset_eq_prod(sc, prod, SC_FUNC(sc));
8415 wmb(); /* keep prod updates ordered */
8419 bxe_eq_int(struct bxe_softc *sc)
8421 uint16_t hw_cons, sw_cons, sw_prod;
8422 union event_ring_elem *elem;
8427 struct ecore_queue_sp_obj *q_obj;
8428 struct ecore_func_sp_obj *f_obj = &sc->func_obj;
8429 struct ecore_raw_obj *rss_raw = &sc->rss_conf_obj.raw;
8431 hw_cons = le16toh(*sc->eq_cons_sb);
8434 * The hw_cons range is 1-255, 257 - the sw_cons range is 0-254, 256.
8435 * when we get to the next-page we need to adjust so the loop
8436 * condition below will be met. The next element is the size of a
8437 * regular element and hence incrementing by 1
8439 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE) {
8444 * This function may never run in parallel with itself for a
8445 * specific sc and no need for a read memory barrier here.
8447 sw_cons = sc->eq_cons;
8448 sw_prod = sc->eq_prod;
8450 BLOGD(sc, DBG_SP,"EQ: hw_cons=%u sw_cons=%u eq_spq_left=0x%lx\n",
8451 hw_cons, sw_cons, atomic_load_acq_long(&sc->eq_spq_left));
8455 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
8457 elem = &sc->eq[EQ_DESC(sw_cons)];
8459 /* elem CID originates from FW, actually LE */
8460 cid = SW_CID(elem->message.data.cfc_del_event.cid);
8461 opcode = elem->message.opcode;
8463 /* handle eq element */
8466 case EVENT_RING_OPCODE_STAT_QUERY:
8467 BLOGD(sc, DBG_SP, "got statistics completion event %d\n",
8469 /* nothing to do with stats comp */
8472 case EVENT_RING_OPCODE_CFC_DEL:
8473 /* handle according to cid range */
8474 /* we may want to verify here that the sc state is HALTING */
8475 BLOGD(sc, DBG_SP, "got delete ramrod for MULTI[%d]\n", cid);
8476 q_obj = bxe_cid_to_q_obj(sc, cid);
8477 if (q_obj->complete_cmd(sc, q_obj, ECORE_Q_CMD_CFC_DEL)) {
8482 case EVENT_RING_OPCODE_STOP_TRAFFIC:
8483 BLOGD(sc, DBG_SP, "got STOP TRAFFIC\n");
8484 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_TX_STOP)) {
8487 // XXX bxe_dcbx_set_params(sc, BXE_DCBX_STATE_TX_PAUSED);
8490 case EVENT_RING_OPCODE_START_TRAFFIC:
8491 BLOGD(sc, DBG_SP, "got START TRAFFIC\n");
8492 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_TX_START)) {
8495 // XXX bxe_dcbx_set_params(sc, BXE_DCBX_STATE_TX_RELEASED);
8498 case EVENT_RING_OPCODE_FUNCTION_UPDATE:
8499 echo = elem->message.data.function_update_event.echo;
8500 if (echo == SWITCH_UPDATE) {
8501 BLOGD(sc, DBG_SP, "got FUNC_SWITCH_UPDATE ramrod\n");
8502 if (f_obj->complete_cmd(sc, f_obj,
8503 ECORE_F_CMD_SWITCH_UPDATE)) {
8509 "AFEX: ramrod completed FUNCTION_UPDATE\n");
8513 case EVENT_RING_OPCODE_FORWARD_SETUP:
8514 q_obj = &bxe_fwd_sp_obj(sc, q_obj);
8515 if (q_obj->complete_cmd(sc, q_obj,
8516 ECORE_Q_CMD_SETUP_TX_ONLY)) {
8521 case EVENT_RING_OPCODE_FUNCTION_START:
8522 BLOGD(sc, DBG_SP, "got FUNC_START ramrod\n");
8523 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_START)) {
8528 case EVENT_RING_OPCODE_FUNCTION_STOP:
8529 BLOGD(sc, DBG_SP, "got FUNC_STOP ramrod\n");
8530 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_STOP)) {
8536 switch (opcode | sc->state) {
8537 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | BXE_STATE_OPEN):
8538 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | BXE_STATE_OPENING_WAITING_PORT):
8539 cid = elem->message.data.eth_event.echo & BXE_SWCID_MASK;
8540 BLOGD(sc, DBG_SP, "got RSS_UPDATE ramrod. CID %d\n", cid);
8541 rss_raw->clear_pending(rss_raw);
8544 case (EVENT_RING_OPCODE_SET_MAC | BXE_STATE_OPEN):
8545 case (EVENT_RING_OPCODE_SET_MAC | BXE_STATE_DIAG):
8546 case (EVENT_RING_OPCODE_SET_MAC | BXE_STATE_CLOSING_WAITING_HALT):
8547 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BXE_STATE_OPEN):
8548 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BXE_STATE_DIAG):
8549 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BXE_STATE_CLOSING_WAITING_HALT):
8550 BLOGD(sc, DBG_SP, "got (un)set mac ramrod\n");
8551 bxe_handle_classification_eqe(sc, elem);
8554 case (EVENT_RING_OPCODE_MULTICAST_RULES | BXE_STATE_OPEN):
8555 case (EVENT_RING_OPCODE_MULTICAST_RULES | BXE_STATE_DIAG):
8556 case (EVENT_RING_OPCODE_MULTICAST_RULES | BXE_STATE_CLOSING_WAITING_HALT):
8557 BLOGD(sc, DBG_SP, "got mcast ramrod\n");
8558 bxe_handle_mcast_eqe(sc);
8561 case (EVENT_RING_OPCODE_FILTERS_RULES | BXE_STATE_OPEN):
8562 case (EVENT_RING_OPCODE_FILTERS_RULES | BXE_STATE_DIAG):
8563 case (EVENT_RING_OPCODE_FILTERS_RULES | BXE_STATE_CLOSING_WAITING_HALT):
8564 BLOGD(sc, DBG_SP, "got rx_mode ramrod\n");
8565 bxe_handle_rx_mode_eqe(sc, elem);
8569 /* unknown event log error and continue */
8570 BLOGE(sc, "Unknown EQ event %d, sc->state 0x%x\n",
8571 elem->message.opcode, sc->state);
8579 atomic_add_acq_long(&sc->eq_spq_left, spqe_cnt);
8581 sc->eq_cons = sw_cons;
8582 sc->eq_prod = sw_prod;
8584 /* make sure that above mem writes were issued towards the memory */
8587 /* update producer */
8588 bxe_update_eq_prod(sc, sc->eq_prod);
8592 bxe_handle_sp_tq(void *context,
8595 struct bxe_softc *sc = (struct bxe_softc *)context;
8598 BLOGD(sc, DBG_SP, "---> SP TASK <---\n");
8600 /* what work needs to be performed? */
8601 status = bxe_update_dsb_idx(sc);
8603 BLOGD(sc, DBG_SP, "dsb status 0x%04x\n", status);
8606 if (status & BXE_DEF_SB_ATT_IDX) {
8607 BLOGD(sc, DBG_SP, "---> ATTN INTR <---\n");
8609 status &= ~BXE_DEF_SB_ATT_IDX;
8612 /* SP events: STAT_QUERY and others */
8613 if (status & BXE_DEF_SB_IDX) {
8614 /* handle EQ completions */
8615 BLOGD(sc, DBG_SP, "---> EQ INTR <---\n");
8617 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID,
8618 le16toh(sc->def_idx), IGU_INT_NOP, 1);
8619 status &= ~BXE_DEF_SB_IDX;
8622 /* if status is non zero then something went wrong */
8623 if (__predict_false(status)) {
8624 BLOGE(sc, "Got an unknown SP interrupt! (0x%04x)\n", status);
8627 /* ack status block only if something was actually handled */
8628 bxe_ack_sb(sc, sc->igu_dsb_id, ATTENTION_ID,
8629 le16toh(sc->def_att_idx), IGU_INT_ENABLE, 1);
8632 * Must be called after the EQ processing (since eq leads to sriov
8633 * ramrod completion flows).
8634 * This flow may have been scheduled by the arrival of a ramrod
8635 * completion, or by the sriov code rescheduling itself.
8637 // XXX bxe_iov_sp_task(sc);
8642 bxe_handle_fp_tq(void *context,
8645 struct bxe_fastpath *fp = (struct bxe_fastpath *)context;
8646 struct bxe_softc *sc = fp->sc;
8647 uint8_t more_tx = FALSE;
8648 uint8_t more_rx = FALSE;
8650 BLOGD(sc, DBG_INTR, "---> FP TASK QUEUE (%d) <---\n", fp->index);
8653 * IFF_DRV_RUNNING state can't be checked here since we process
8654 * slowpath events on a client queue during setup. Instead
8655 * we need to add a "process/continue" flag here that the driver
8656 * can use to tell the task here not to do anything.
8659 if (!(sc->ifnet->if_drv_flags & IFF_DRV_RUNNING)) {
8664 /* update the fastpath index */
8665 bxe_update_fp_sb_idx(fp);
8667 /* XXX add loop here if ever support multiple tx CoS */
8668 /* fp->txdata[cos] */
8669 if (bxe_has_tx_work(fp)) {
8671 more_tx = bxe_txeof(sc, fp);
8672 BXE_FP_TX_UNLOCK(fp);
8675 if (bxe_has_rx_work(fp)) {
8676 more_rx = bxe_rxeof(sc, fp);
8679 if (more_rx /*|| more_tx*/) {
8680 /* still more work to do */
8681 taskqueue_enqueue_fast(fp->tq, &fp->tq_task);
8685 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID,
8686 le16toh(fp->fp_hc_idx), IGU_INT_ENABLE, 1);
8690 bxe_task_fp(struct bxe_fastpath *fp)
8692 struct bxe_softc *sc = fp->sc;
8693 uint8_t more_tx = FALSE;
8694 uint8_t more_rx = FALSE;
8696 BLOGD(sc, DBG_INTR, "---> FP TASK ISR (%d) <---\n", fp->index);
8698 /* update the fastpath index */
8699 bxe_update_fp_sb_idx(fp);
8701 /* XXX add loop here if ever support multiple tx CoS */
8702 /* fp->txdata[cos] */
8703 if (bxe_has_tx_work(fp)) {
8705 more_tx = bxe_txeof(sc, fp);
8706 BXE_FP_TX_UNLOCK(fp);
8709 if (bxe_has_rx_work(fp)) {
8710 more_rx = bxe_rxeof(sc, fp);
8713 if (more_rx /*|| more_tx*/) {
8714 /* still more work to do, bail out if this ISR and process later */
8715 taskqueue_enqueue_fast(fp->tq, &fp->tq_task);
8720 * Here we write the fastpath index taken before doing any tx or rx work.
8721 * It is very well possible other hw events occurred up to this point and
8722 * they were actually processed accordingly above. Since we're going to
8723 * write an older fastpath index, an interrupt is coming which we might
8724 * not do any work in.
8726 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID,
8727 le16toh(fp->fp_hc_idx), IGU_INT_ENABLE, 1);
8731 * Legacy interrupt entry point.
8733 * Verifies that the controller generated the interrupt and
8734 * then calls a separate routine to handle the various
8735 * interrupt causes: link, RX, and TX.
8738 bxe_intr_legacy(void *xsc)
8740 struct bxe_softc *sc = (struct bxe_softc *)xsc;
8741 struct bxe_fastpath *fp;
8742 uint16_t status, mask;
8745 BLOGD(sc, DBG_INTR, "---> BXE INTx <---\n");
8748 * 0 for ustorm, 1 for cstorm
8749 * the bits returned from ack_int() are 0-15
8750 * bit 0 = attention status block
8751 * bit 1 = fast path status block
8752 * a mask of 0x2 or more = tx/rx event
8753 * a mask of 1 = slow path event
8756 status = bxe_ack_int(sc);
8758 /* the interrupt is not for us */
8759 if (__predict_false(status == 0)) {
8760 BLOGD(sc, DBG_INTR, "Not our interrupt!\n");
8764 BLOGD(sc, DBG_INTR, "Interrupt status 0x%04x\n", status);
8766 FOR_EACH_ETH_QUEUE(sc, i) {
8768 mask = (0x2 << (fp->index + CNIC_SUPPORT(sc)));
8769 if (status & mask) {
8770 /* acknowledge and disable further fastpath interrupts */
8771 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
8777 if (__predict_false(status & 0x1)) {
8778 /* acknowledge and disable further slowpath interrupts */
8779 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
8781 /* schedule slowpath handler */
8782 taskqueue_enqueue_fast(sc->sp_tq, &sc->sp_tq_task);
8787 if (__predict_false(status)) {
8788 BLOGW(sc, "Unexpected fastpath status (0x%08x)!\n", status);
8792 /* slowpath interrupt entry point */
8794 bxe_intr_sp(void *xsc)
8796 struct bxe_softc *sc = (struct bxe_softc *)xsc;
8798 BLOGD(sc, (DBG_INTR | DBG_SP), "---> SP INTR <---\n");
8800 /* acknowledge and disable further slowpath interrupts */
8801 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
8803 /* schedule slowpath handler */
8804 taskqueue_enqueue_fast(sc->sp_tq, &sc->sp_tq_task);
8807 /* fastpath interrupt entry point */
8809 bxe_intr_fp(void *xfp)
8811 struct bxe_fastpath *fp = (struct bxe_fastpath *)xfp;
8812 struct bxe_softc *sc = fp->sc;
8814 BLOGD(sc, DBG_INTR, "---> FP INTR %d <---\n", fp->index);
8817 "(cpu=%d) MSI-X fp=%d fw_sb=%d igu_sb=%d\n",
8818 curcpu, fp->index, fp->fw_sb_id, fp->igu_sb_id);
8820 /* acknowledge and disable further fastpath interrupts */
8821 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
8826 /* Release all interrupts allocated by the driver. */
8828 bxe_interrupt_free(struct bxe_softc *sc)
8832 switch (sc->interrupt_mode) {
8833 case INTR_MODE_INTX:
8834 BLOGD(sc, DBG_LOAD, "Releasing legacy INTx vector\n");
8835 if (sc->intr[0].resource != NULL) {
8836 bus_release_resource(sc->dev,
8839 sc->intr[0].resource);
8843 for (i = 0; i < sc->intr_count; i++) {
8844 BLOGD(sc, DBG_LOAD, "Releasing MSI vector %d\n", i);
8845 if (sc->intr[i].resource && sc->intr[i].rid) {
8846 bus_release_resource(sc->dev,
8849 sc->intr[i].resource);
8852 pci_release_msi(sc->dev);
8854 case INTR_MODE_MSIX:
8855 for (i = 0; i < sc->intr_count; i++) {
8856 BLOGD(sc, DBG_LOAD, "Releasing MSI-X vector %d\n", i);
8857 if (sc->intr[i].resource && sc->intr[i].rid) {
8858 bus_release_resource(sc->dev,
8861 sc->intr[i].resource);
8864 pci_release_msi(sc->dev);
8867 /* nothing to do as initial allocation failed */
8873 * This function determines and allocates the appropriate
8874 * interrupt based on system capabilites and user request.
8876 * The user may force a particular interrupt mode, specify
8877 * the number of receive queues, specify the method for
8878 * distribuitng received frames to receive queues, or use
8879 * the default settings which will automatically select the
8880 * best supported combination. In addition, the OS may or
8881 * may not support certain combinations of these settings.
8882 * This routine attempts to reconcile the settings requested
8883 * by the user with the capabilites available from the system
8884 * to select the optimal combination of features.
8887 * 0 = Success, !0 = Failure.
8890 bxe_interrupt_alloc(struct bxe_softc *sc)
8894 int num_requested = 0;
8895 int num_allocated = 0;
8899 /* get the number of available MSI/MSI-X interrupts from the OS */
8900 if (sc->interrupt_mode > 0) {
8901 if (sc->devinfo.pcie_cap_flags & BXE_MSIX_CAPABLE_FLAG) {
8902 msix_count = pci_msix_count(sc->dev);
8905 if (sc->devinfo.pcie_cap_flags & BXE_MSI_CAPABLE_FLAG) {
8906 msi_count = pci_msi_count(sc->dev);
8909 BLOGD(sc, DBG_LOAD, "%d MSI and %d MSI-X vectors available\n",
8910 msi_count, msix_count);
8913 do { /* try allocating MSI-X interrupt resources (at least 2) */
8914 if (sc->interrupt_mode != INTR_MODE_MSIX) {
8918 if (((sc->devinfo.pcie_cap_flags & BXE_MSIX_CAPABLE_FLAG) == 0) ||
8920 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */
8924 /* ask for the necessary number of MSI-X vectors */
8925 num_requested = min((sc->num_queues + 1), msix_count);
8927 BLOGD(sc, DBG_LOAD, "Requesting %d MSI-X vectors\n", num_requested);
8929 num_allocated = num_requested;
8930 if ((rc = pci_alloc_msix(sc->dev, &num_allocated)) != 0) {
8931 BLOGE(sc, "MSI-X alloc failed! (%d)\n", rc);
8932 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */
8936 if (num_allocated < 2) { /* possible? */
8937 BLOGE(sc, "MSI-X allocation less than 2!\n");
8938 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */
8939 pci_release_msi(sc->dev);
8943 BLOGI(sc, "MSI-X vectors Requested %d and Allocated %d\n",
8944 num_requested, num_allocated);
8946 /* best effort so use the number of vectors allocated to us */
8947 sc->intr_count = num_allocated;
8948 sc->num_queues = num_allocated - 1;
8950 rid = 1; /* initial resource identifier */
8952 /* allocate the MSI-X vectors */
8953 for (i = 0; i < num_allocated; i++) {
8954 sc->intr[i].rid = (rid + i);
8956 if ((sc->intr[i].resource =
8957 bus_alloc_resource_any(sc->dev,
8960 RF_ACTIVE)) == NULL) {
8961 BLOGE(sc, "Failed to map MSI-X[%d] (rid=%d)!\n",
8964 for (j = (i - 1); j >= 0; j--) {
8965 bus_release_resource(sc->dev,
8968 sc->intr[j].resource);
8973 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */
8974 pci_release_msi(sc->dev);
8978 BLOGD(sc, DBG_LOAD, "Mapped MSI-X[%d] (rid=%d)\n", i, (rid + i));
8982 do { /* try allocating MSI vector resources (at least 2) */
8983 if (sc->interrupt_mode != INTR_MODE_MSI) {
8987 if (((sc->devinfo.pcie_cap_flags & BXE_MSI_CAPABLE_FLAG) == 0) ||
8989 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */
8993 /* ask for a single MSI vector */
8996 BLOGD(sc, DBG_LOAD, "Requesting %d MSI vectors\n", num_requested);
8998 num_allocated = num_requested;
8999 if ((rc = pci_alloc_msi(sc->dev, &num_allocated)) != 0) {
9000 BLOGE(sc, "MSI alloc failed (%d)!\n", rc);
9001 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */
9005 if (num_allocated != 1) { /* possible? */
9006 BLOGE(sc, "MSI allocation is not 1!\n");
9007 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */
9008 pci_release_msi(sc->dev);
9012 BLOGI(sc, "MSI vectors Requested %d and Allocated %d\n",
9013 num_requested, num_allocated);
9015 /* best effort so use the number of vectors allocated to us */
9016 sc->intr_count = num_allocated;
9017 sc->num_queues = num_allocated;
9019 rid = 1; /* initial resource identifier */
9021 sc->intr[0].rid = rid;
9023 if ((sc->intr[0].resource =
9024 bus_alloc_resource_any(sc->dev,
9027 RF_ACTIVE)) == NULL) {
9028 BLOGE(sc, "Failed to map MSI[0] (rid=%d)!\n", rid);
9031 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */
9032 pci_release_msi(sc->dev);
9036 BLOGD(sc, DBG_LOAD, "Mapped MSI[0] (rid=%d)\n", rid);
9039 do { /* try allocating INTx vector resources */
9040 if (sc->interrupt_mode != INTR_MODE_INTX) {
9044 BLOGD(sc, DBG_LOAD, "Requesting legacy INTx interrupt\n");
9046 /* only one vector for INTx */
9050 rid = 0; /* initial resource identifier */
9052 sc->intr[0].rid = rid;
9054 if ((sc->intr[0].resource =
9055 bus_alloc_resource_any(sc->dev,
9058 (RF_ACTIVE | RF_SHAREABLE))) == NULL) {
9059 BLOGE(sc, "Failed to map INTx (rid=%d)!\n", rid);
9062 sc->interrupt_mode = -1; /* Failed! */
9066 BLOGD(sc, DBG_LOAD, "Mapped INTx (rid=%d)\n", rid);
9069 if (sc->interrupt_mode == -1) {
9070 BLOGE(sc, "Interrupt Allocation: FAILED!!!\n");
9074 "Interrupt Allocation: interrupt_mode=%d, num_queues=%d\n",
9075 sc->interrupt_mode, sc->num_queues);
9083 bxe_interrupt_detach(struct bxe_softc *sc)
9085 struct bxe_fastpath *fp;
9088 /* release interrupt resources */
9089 for (i = 0; i < sc->intr_count; i++) {
9090 if (sc->intr[i].resource && sc->intr[i].tag) {
9091 BLOGD(sc, DBG_LOAD, "Disabling interrupt vector %d\n", i);
9092 bus_teardown_intr(sc->dev, sc->intr[i].resource, sc->intr[i].tag);
9096 for (i = 0; i < sc->num_queues; i++) {
9099 taskqueue_drain(fp->tq, &fp->tq_task);
9100 taskqueue_free(fp->tq);
9107 taskqueue_drain(sc->sp_tq, &sc->sp_tq_task);
9108 taskqueue_free(sc->sp_tq);
9114 * Enables interrupts and attach to the ISR.
9116 * When using multiple MSI/MSI-X vectors the first vector
9117 * is used for slowpath operations while all remaining
9118 * vectors are used for fastpath operations. If only a
9119 * single MSI/MSI-X vector is used (SINGLE_ISR) then the
9120 * ISR must look for both slowpath and fastpath completions.
9123 bxe_interrupt_attach(struct bxe_softc *sc)
9125 struct bxe_fastpath *fp;
9129 snprintf(sc->sp_tq_name, sizeof(sc->sp_tq_name),
9130 "bxe%d_sp_tq", sc->unit);
9131 TASK_INIT(&sc->sp_tq_task, 0, bxe_handle_sp_tq, sc);
9132 sc->sp_tq = taskqueue_create_fast(sc->sp_tq_name, M_NOWAIT,
9133 taskqueue_thread_enqueue,
9135 taskqueue_start_threads(&sc->sp_tq, 1, PWAIT, /* lower priority */
9136 "%s", sc->sp_tq_name);
9139 for (i = 0; i < sc->num_queues; i++) {
9141 snprintf(fp->tq_name, sizeof(fp->tq_name),
9142 "bxe%d_fp%d_tq", sc->unit, i);
9143 TASK_INIT(&fp->tq_task, 0, bxe_handle_fp_tq, fp);
9144 fp->tq = taskqueue_create_fast(fp->tq_name, M_NOWAIT,
9145 taskqueue_thread_enqueue,
9147 taskqueue_start_threads(&fp->tq, 1, PI_NET, /* higher priority */
9151 /* setup interrupt handlers */
9152 if (sc->interrupt_mode == INTR_MODE_MSIX) {
9153 BLOGD(sc, DBG_LOAD, "Enabling slowpath MSI-X[0] vector\n");
9156 * Setup the interrupt handler. Note that we pass the driver instance
9157 * to the interrupt handler for the slowpath.
9159 if ((rc = bus_setup_intr(sc->dev, sc->intr[0].resource,
9160 (INTR_TYPE_NET | INTR_MPSAFE),
9161 NULL, bxe_intr_sp, sc,
9162 &sc->intr[0].tag)) != 0) {
9163 BLOGE(sc, "Failed to allocate MSI-X[0] vector (%d)\n", rc);
9164 goto bxe_interrupt_attach_exit;
9167 bus_describe_intr(sc->dev, sc->intr[0].resource,
9168 sc->intr[0].tag, "sp");
9170 /* bus_bind_intr(sc->dev, sc->intr[0].resource, 0); */
9172 /* initialize the fastpath vectors (note the first was used for sp) */
9173 for (i = 0; i < sc->num_queues; i++) {
9175 BLOGD(sc, DBG_LOAD, "Enabling MSI-X[%d] vector\n", (i + 1));
9178 * Setup the interrupt handler. Note that we pass the
9179 * fastpath context to the interrupt handler in this
9182 if ((rc = bus_setup_intr(sc->dev, sc->intr[i + 1].resource,
9183 (INTR_TYPE_NET | INTR_MPSAFE),
9184 NULL, bxe_intr_fp, fp,
9185 &sc->intr[i + 1].tag)) != 0) {
9186 BLOGE(sc, "Failed to allocate MSI-X[%d] vector (%d)\n",
9188 goto bxe_interrupt_attach_exit;
9191 bus_describe_intr(sc->dev, sc->intr[i + 1].resource,
9192 sc->intr[i + 1].tag, "fp%02d", i);
9194 /* bind the fastpath instance to a cpu */
9195 if (sc->num_queues > 1) {
9196 bus_bind_intr(sc->dev, sc->intr[i + 1].resource, i);
9199 fp->state = BXE_FP_STATE_IRQ;
9201 } else if (sc->interrupt_mode == INTR_MODE_MSI) {
9202 BLOGD(sc, DBG_LOAD, "Enabling MSI[0] vector\n");
9205 * Setup the interrupt handler. Note that we pass the
9206 * driver instance to the interrupt handler which
9207 * will handle both the slowpath and fastpath.
9209 if ((rc = bus_setup_intr(sc->dev, sc->intr[0].resource,
9210 (INTR_TYPE_NET | INTR_MPSAFE),
9211 NULL, bxe_intr_legacy, sc,
9212 &sc->intr[0].tag)) != 0) {
9213 BLOGE(sc, "Failed to allocate MSI[0] vector (%d)\n", rc);
9214 goto bxe_interrupt_attach_exit;
9217 } else { /* (sc->interrupt_mode == INTR_MODE_INTX) */
9218 BLOGD(sc, DBG_LOAD, "Enabling INTx interrupts\n");
9221 * Setup the interrupt handler. Note that we pass the
9222 * driver instance to the interrupt handler which
9223 * will handle both the slowpath and fastpath.
9225 if ((rc = bus_setup_intr(sc->dev, sc->intr[0].resource,
9226 (INTR_TYPE_NET | INTR_MPSAFE),
9227 NULL, bxe_intr_legacy, sc,
9228 &sc->intr[0].tag)) != 0) {
9229 BLOGE(sc, "Failed to allocate INTx interrupt (%d)\n", rc);
9230 goto bxe_interrupt_attach_exit;
9234 bxe_interrupt_attach_exit:
9239 static int bxe_init_hw_common_chip(struct bxe_softc *sc);
9240 static int bxe_init_hw_common(struct bxe_softc *sc);
9241 static int bxe_init_hw_port(struct bxe_softc *sc);
9242 static int bxe_init_hw_func(struct bxe_softc *sc);
9243 static void bxe_reset_common(struct bxe_softc *sc);
9244 static void bxe_reset_port(struct bxe_softc *sc);
9245 static void bxe_reset_func(struct bxe_softc *sc);
9246 static int bxe_gunzip_init(struct bxe_softc *sc);
9247 static void bxe_gunzip_end(struct bxe_softc *sc);
9248 static int bxe_init_firmware(struct bxe_softc *sc);
9249 static void bxe_release_firmware(struct bxe_softc *sc);
9252 ecore_func_sp_drv_ops bxe_func_sp_drv = {
9253 .init_hw_cmn_chip = bxe_init_hw_common_chip,
9254 .init_hw_cmn = bxe_init_hw_common,
9255 .init_hw_port = bxe_init_hw_port,
9256 .init_hw_func = bxe_init_hw_func,
9258 .reset_hw_cmn = bxe_reset_common,
9259 .reset_hw_port = bxe_reset_port,
9260 .reset_hw_func = bxe_reset_func,
9262 .gunzip_init = bxe_gunzip_init,
9263 .gunzip_end = bxe_gunzip_end,
9265 .init_fw = bxe_init_firmware,
9266 .release_fw = bxe_release_firmware,
9270 bxe_init_func_obj(struct bxe_softc *sc)
9274 ecore_init_func_obj(sc,
9276 BXE_SP(sc, func_rdata),
9277 BXE_SP_MAPPING(sc, func_rdata),
9278 BXE_SP(sc, func_afex_rdata),
9279 BXE_SP_MAPPING(sc, func_afex_rdata),
9284 bxe_init_hw(struct bxe_softc *sc,
9287 struct ecore_func_state_params func_params = { NULL };
9290 /* prepare the parameters for function state transitions */
9291 bit_set(&func_params.ramrod_flags, RAMROD_COMP_WAIT);
9293 func_params.f_obj = &sc->func_obj;
9294 func_params.cmd = ECORE_F_CMD_HW_INIT;
9296 func_params.params.hw_init.load_phase = load_code;
9299 * Via a plethora of function pointers, we will eventually reach
9300 * bxe_init_hw_common(), bxe_init_hw_port(), or bxe_init_hw_func().
9302 rc = ecore_func_state_change(sc, &func_params);
9308 bxe_fill(struct bxe_softc *sc,
9315 if (!(len % 4) && !(addr % 4)) {
9316 for (i = 0; i < len; i += 4) {
9317 REG_WR(sc, (addr + i), fill);
9320 for (i = 0; i < len; i++) {
9321 REG_WR8(sc, (addr + i), fill);
9326 /* writes FP SP data to FW - data_size in dwords */
9328 bxe_wr_fp_sb_data(struct bxe_softc *sc,
9330 uint32_t *sb_data_p,
9335 for (index = 0; index < data_size; index++) {
9337 (BAR_CSTRORM_INTMEM +
9338 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
9339 (sizeof(uint32_t) * index)),
9340 *(sb_data_p + index));
9345 bxe_zero_fp_sb(struct bxe_softc *sc,
9348 struct hc_status_block_data_e2 sb_data_e2;
9349 struct hc_status_block_data_e1x sb_data_e1x;
9350 uint32_t *sb_data_p;
9351 uint32_t data_size = 0;
9353 if (!CHIP_IS_E1x(sc)) {
9354 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
9355 sb_data_e2.common.state = SB_DISABLED;
9356 sb_data_e2.common.p_func.vf_valid = FALSE;
9357 sb_data_p = (uint32_t *)&sb_data_e2;
9358 data_size = (sizeof(struct hc_status_block_data_e2) /
9361 memset(&sb_data_e1x, 0, sizeof(struct hc_status_block_data_e1x));
9362 sb_data_e1x.common.state = SB_DISABLED;
9363 sb_data_e1x.common.p_func.vf_valid = FALSE;
9364 sb_data_p = (uint32_t *)&sb_data_e1x;
9365 data_size = (sizeof(struct hc_status_block_data_e1x) /
9369 bxe_wr_fp_sb_data(sc, fw_sb_id, sb_data_p, data_size);
9371 bxe_fill(sc, (BAR_CSTRORM_INTMEM + CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id)),
9372 0, CSTORM_STATUS_BLOCK_SIZE);
9373 bxe_fill(sc, (BAR_CSTRORM_INTMEM + CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id)),
9374 0, CSTORM_SYNC_BLOCK_SIZE);
9378 bxe_wr_sp_sb_data(struct bxe_softc *sc,
9379 struct hc_sp_status_block_data *sp_sb_data)
9384 i < (sizeof(struct hc_sp_status_block_data) / sizeof(uint32_t));
9387 (BAR_CSTRORM_INTMEM +
9388 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(SC_FUNC(sc)) +
9389 (i * sizeof(uint32_t))),
9390 *((uint32_t *)sp_sb_data + i));
9395 bxe_zero_sp_sb(struct bxe_softc *sc)
9397 struct hc_sp_status_block_data sp_sb_data;
9399 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
9401 sp_sb_data.state = SB_DISABLED;
9402 sp_sb_data.p_func.vf_valid = FALSE;
9404 bxe_wr_sp_sb_data(sc, &sp_sb_data);
9407 (BAR_CSTRORM_INTMEM +
9408 CSTORM_SP_STATUS_BLOCK_OFFSET(SC_FUNC(sc))),
9409 0, CSTORM_SP_STATUS_BLOCK_SIZE);
9411 (BAR_CSTRORM_INTMEM +
9412 CSTORM_SP_SYNC_BLOCK_OFFSET(SC_FUNC(sc))),
9413 0, CSTORM_SP_SYNC_BLOCK_SIZE);
9417 bxe_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
9421 hc_sm->igu_sb_id = igu_sb_id;
9422 hc_sm->igu_seg_id = igu_seg_id;
9423 hc_sm->timer_value = 0xFF;
9424 hc_sm->time_to_expire = 0xFFFFFFFF;
9428 bxe_map_sb_state_machines(struct hc_index_data *index_data)
9430 /* zero out state machine indices */
9433 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
9436 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
9437 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
9438 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
9439 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
9444 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
9445 (SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9448 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
9449 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9450 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
9451 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9452 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
9453 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9454 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
9455 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9459 bxe_init_sb(struct bxe_softc *sc,
9466 struct hc_status_block_data_e2 sb_data_e2;
9467 struct hc_status_block_data_e1x sb_data_e1x;
9468 struct hc_status_block_sm *hc_sm_p;
9469 uint32_t *sb_data_p;
9473 if (CHIP_INT_MODE_IS_BC(sc)) {
9474 igu_seg_id = HC_SEG_ACCESS_NORM;
9476 igu_seg_id = IGU_SEG_ACCESS_NORM;
9479 bxe_zero_fp_sb(sc, fw_sb_id);
9481 if (!CHIP_IS_E1x(sc)) {
9482 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
9483 sb_data_e2.common.state = SB_ENABLED;
9484 sb_data_e2.common.p_func.pf_id = SC_FUNC(sc);
9485 sb_data_e2.common.p_func.vf_id = vfid;
9486 sb_data_e2.common.p_func.vf_valid = vf_valid;
9487 sb_data_e2.common.p_func.vnic_id = SC_VN(sc);
9488 sb_data_e2.common.same_igu_sb_1b = TRUE;
9489 sb_data_e2.common.host_sb_addr.hi = U64_HI(busaddr);
9490 sb_data_e2.common.host_sb_addr.lo = U64_LO(busaddr);
9491 hc_sm_p = sb_data_e2.common.state_machine;
9492 sb_data_p = (uint32_t *)&sb_data_e2;
9493 data_size = (sizeof(struct hc_status_block_data_e2) /
9495 bxe_map_sb_state_machines(sb_data_e2.index_data);
9497 memset(&sb_data_e1x, 0, sizeof(struct hc_status_block_data_e1x));
9498 sb_data_e1x.common.state = SB_ENABLED;
9499 sb_data_e1x.common.p_func.pf_id = SC_FUNC(sc);
9500 sb_data_e1x.common.p_func.vf_id = 0xff;
9501 sb_data_e1x.common.p_func.vf_valid = FALSE;
9502 sb_data_e1x.common.p_func.vnic_id = SC_VN(sc);
9503 sb_data_e1x.common.same_igu_sb_1b = TRUE;
9504 sb_data_e1x.common.host_sb_addr.hi = U64_HI(busaddr);
9505 sb_data_e1x.common.host_sb_addr.lo = U64_LO(busaddr);
9506 hc_sm_p = sb_data_e1x.common.state_machine;
9507 sb_data_p = (uint32_t *)&sb_data_e1x;
9508 data_size = (sizeof(struct hc_status_block_data_e1x) /
9510 bxe_map_sb_state_machines(sb_data_e1x.index_data);
9513 bxe_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID], igu_sb_id, igu_seg_id);
9514 bxe_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID], igu_sb_id, igu_seg_id);
9516 BLOGD(sc, DBG_LOAD, "Init FW SB %d\n", fw_sb_id);
9518 /* write indices to HW - PCI guarantees endianity of regpairs */
9519 bxe_wr_fp_sb_data(sc, fw_sb_id, sb_data_p, data_size);
9522 static inline uint8_t
9523 bxe_fp_qzone_id(struct bxe_fastpath *fp)
9525 if (CHIP_IS_E1x(fp->sc)) {
9526 return (fp->cl_id + SC_PORT(fp->sc) * ETH_MAX_RX_CLIENTS_E1H);
9532 static inline uint32_t
9533 bxe_rx_ustorm_prods_offset(struct bxe_softc *sc,
9534 struct bxe_fastpath *fp)
9536 uint32_t offset = BAR_USTRORM_INTMEM;
9538 if (!CHIP_IS_E1x(sc)) {
9539 offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
9541 offset += USTORM_RX_PRODS_E1X_OFFSET(SC_PORT(sc), fp->cl_id);
9548 bxe_init_eth_fp(struct bxe_softc *sc,
9551 struct bxe_fastpath *fp = &sc->fp[idx];
9552 uint32_t cids[ECORE_MULTI_TX_COS] = { 0 };
9553 unsigned long q_type = 0;
9559 fp->igu_sb_id = (sc->igu_base_sb + idx + CNIC_SUPPORT(sc));
9560 fp->fw_sb_id = (sc->base_fw_ndsb + idx + CNIC_SUPPORT(sc));
9562 fp->cl_id = (CHIP_IS_E1x(sc)) ?
9563 (SC_L_ID(sc) + idx) :
9564 /* want client ID same as IGU SB ID for non-E1 */
9566 fp->cl_qzone_id = bxe_fp_qzone_id(fp);
9568 /* setup sb indices */
9569 if (!CHIP_IS_E1x(sc)) {
9570 fp->sb_index_values = fp->status_block.e2_sb->sb.index_values;
9571 fp->sb_running_index = fp->status_block.e2_sb->sb.running_index;
9573 fp->sb_index_values = fp->status_block.e1x_sb->sb.index_values;
9574 fp->sb_running_index = fp->status_block.e1x_sb->sb.running_index;
9578 fp->ustorm_rx_prods_offset = bxe_rx_ustorm_prods_offset(sc, fp);
9580 fp->rx_cq_cons_sb = &fp->sb_index_values[HC_INDEX_ETH_RX_CQ_CONS];
9583 * XXX If multiple CoS is ever supported then each fastpath structure
9584 * will need to maintain tx producer/consumer/dma/etc values *per* CoS.
9586 for (cos = 0; cos < sc->max_cos; cos++) {
9589 fp->tx_cons_sb = &fp->sb_index_values[HC_INDEX_ETH_TX_CQ_CONS_COS0];
9591 /* nothing more for a VF to do */
9596 bxe_init_sb(sc, fp->sb_dma.paddr, BXE_VF_ID_INVALID, FALSE,
9597 fp->fw_sb_id, fp->igu_sb_id);
9599 bxe_update_fp_sb_idx(fp);
9601 /* Configure Queue State object */
9602 bit_set(&q_type, ECORE_Q_TYPE_HAS_RX);
9603 bit_set(&q_type, ECORE_Q_TYPE_HAS_TX);
9605 ecore_init_queue_obj(sc,
9606 &sc->sp_objs[idx].q_obj,
9611 BXE_SP(sc, q_rdata),
9612 BXE_SP_MAPPING(sc, q_rdata),
9615 /* configure classification DBs */
9616 ecore_init_mac_obj(sc,
9617 &sc->sp_objs[idx].mac_obj,
9621 BXE_SP(sc, mac_rdata),
9622 BXE_SP_MAPPING(sc, mac_rdata),
9623 ECORE_FILTER_MAC_PENDING,
9625 ECORE_OBJ_TYPE_RX_TX,
9628 BLOGD(sc, DBG_LOAD, "fp[%d]: sb=%p cl_id=%d fw_sb=%d igu_sb=%d\n",
9629 idx, fp->status_block.e2_sb, fp->cl_id, fp->fw_sb_id, fp->igu_sb_id);
9633 bxe_update_rx_prod(struct bxe_softc *sc,
9634 struct bxe_fastpath *fp,
9635 uint16_t rx_bd_prod,
9636 uint16_t rx_cq_prod,
9637 uint16_t rx_sge_prod)
9639 struct ustorm_eth_rx_producers rx_prods = { 0 };
9642 /* update producers */
9643 rx_prods.bd_prod = rx_bd_prod;
9644 rx_prods.cqe_prod = rx_cq_prod;
9645 rx_prods.sge_prod = rx_sge_prod;
9648 * Make sure that the BD and SGE data is updated before updating the
9649 * producers since FW might read the BD/SGE right after the producer
9651 * This is only applicable for weak-ordered memory model archs such
9652 * as IA-64. The following barrier is also mandatory since FW will
9653 * assumes BDs must have buffers.
9657 for (i = 0; i < (sizeof(rx_prods) / 4); i++) {
9659 (fp->ustorm_rx_prods_offset + (i * 4)),
9660 ((uint32_t *)&rx_prods)[i]);
9663 wmb(); /* keep prod updates ordered */
9666 "RX fp[%d]: wrote prods bd_prod=%u cqe_prod=%u sge_prod=%u\n",
9667 fp->index, rx_bd_prod, rx_cq_prod, rx_sge_prod);
9671 bxe_init_rx_rings(struct bxe_softc *sc)
9673 struct bxe_fastpath *fp;
9676 for (i = 0; i < sc->num_queues; i++) {
9682 * Activate the BD ring...
9683 * Warning, this will generate an interrupt (to the TSTORM)
9684 * so this can only be done after the chip is initialized
9686 bxe_update_rx_prod(sc, fp,
9695 if (CHIP_IS_E1(sc)) {
9697 (BAR_USTRORM_INTMEM +
9698 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(SC_FUNC(sc))),
9699 U64_LO(fp->rcq_dma.paddr));
9701 (BAR_USTRORM_INTMEM +
9702 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(SC_FUNC(sc)) + 4),
9703 U64_HI(fp->rcq_dma.paddr));
9709 bxe_init_tx_ring_one(struct bxe_fastpath *fp)
9711 SET_FLAG(fp->tx_db.data.header.data, DOORBELL_HDR_T_DB_TYPE, 1);
9712 fp->tx_db.data.zero_fill1 = 0;
9713 fp->tx_db.data.prod = 0;
9715 fp->tx_pkt_prod = 0;
9716 fp->tx_pkt_cons = 0;
9719 fp->eth_q_stats.tx_pkts = 0;
9723 bxe_init_tx_rings(struct bxe_softc *sc)
9727 for (i = 0; i < sc->num_queues; i++) {
9728 bxe_init_tx_ring_one(&sc->fp[i]);
9733 bxe_init_def_sb(struct bxe_softc *sc)
9735 struct host_sp_status_block *def_sb = sc->def_sb;
9736 bus_addr_t mapping = sc->def_sb_dma.paddr;
9737 int igu_sp_sb_index;
9739 int port = SC_PORT(sc);
9740 int func = SC_FUNC(sc);
9741 int reg_offset, reg_offset_en5;
9744 struct hc_sp_status_block_data sp_sb_data;
9746 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
9748 if (CHIP_INT_MODE_IS_BC(sc)) {
9749 igu_sp_sb_index = DEF_SB_IGU_ID;
9750 igu_seg_id = HC_SEG_ACCESS_DEF;
9752 igu_sp_sb_index = sc->igu_dsb_id;
9753 igu_seg_id = IGU_SEG_ACCESS_DEF;
9757 section = ((uint64_t)mapping +
9758 offsetof(struct host_sp_status_block, atten_status_block));
9759 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
9762 reg_offset = (port) ?
9763 MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
9764 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
9765 reg_offset_en5 = (port) ?
9766 MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
9767 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0;
9769 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
9770 /* take care of sig[0]..sig[4] */
9771 for (sindex = 0; sindex < 4; sindex++) {
9772 sc->attn_group[index].sig[sindex] =
9773 REG_RD(sc, (reg_offset + (sindex * 0x4) + (0x10 * index)));
9776 if (!CHIP_IS_E1x(sc)) {
9778 * enable5 is separate from the rest of the registers,
9779 * and the address skip is 4 and not 16 between the
9782 sc->attn_group[index].sig[4] =
9783 REG_RD(sc, (reg_offset_en5 + (0x4 * index)));
9785 sc->attn_group[index].sig[4] = 0;
9789 if (sc->devinfo.int_block == INT_BLOCK_HC) {
9790 reg_offset = (port) ?
9791 HC_REG_ATTN_MSG1_ADDR_L :
9792 HC_REG_ATTN_MSG0_ADDR_L;
9793 REG_WR(sc, reg_offset, U64_LO(section));
9794 REG_WR(sc, (reg_offset + 4), U64_HI(section));
9795 } else if (!CHIP_IS_E1x(sc)) {
9796 REG_WR(sc, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
9797 REG_WR(sc, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
9800 section = ((uint64_t)mapping +
9801 offsetof(struct host_sp_status_block, sp_sb));
9805 /* PCI guarantees endianity of regpair */
9806 sp_sb_data.state = SB_ENABLED;
9807 sp_sb_data.host_sb_addr.lo = U64_LO(section);
9808 sp_sb_data.host_sb_addr.hi = U64_HI(section);
9809 sp_sb_data.igu_sb_id = igu_sp_sb_index;
9810 sp_sb_data.igu_seg_id = igu_seg_id;
9811 sp_sb_data.p_func.pf_id = func;
9812 sp_sb_data.p_func.vnic_id = SC_VN(sc);
9813 sp_sb_data.p_func.vf_id = 0xff;
9815 bxe_wr_sp_sb_data(sc, &sp_sb_data);
9817 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
9821 bxe_init_sp_ring(struct bxe_softc *sc)
9823 atomic_store_rel_long(&sc->cq_spq_left, MAX_SPQ_PENDING);
9824 sc->spq_prod_idx = 0;
9825 sc->dsb_sp_prod = &sc->def_sb->sp_sb.index_values[HC_SP_INDEX_ETH_DEF_CONS];
9826 sc->spq_prod_bd = sc->spq;
9827 sc->spq_last_bd = (sc->spq_prod_bd + MAX_SP_DESC_CNT);
9831 bxe_init_eq_ring(struct bxe_softc *sc)
9833 union event_ring_elem *elem;
9836 for (i = 1; i <= NUM_EQ_PAGES; i++) {
9837 elem = &sc->eq[EQ_DESC_CNT_PAGE * i - 1];
9839 elem->next_page.addr.hi = htole32(U64_HI(sc->eq_dma.paddr +
9841 (i % NUM_EQ_PAGES)));
9842 elem->next_page.addr.lo = htole32(U64_LO(sc->eq_dma.paddr +
9844 (i % NUM_EQ_PAGES)));
9848 sc->eq_prod = NUM_EQ_DESC;
9849 sc->eq_cons_sb = &sc->def_sb->sp_sb.index_values[HC_SP_INDEX_EQ_CONS];
9851 atomic_store_rel_long(&sc->eq_spq_left,
9852 (min((MAX_SP_DESC_CNT - MAX_SPQ_PENDING),
9857 bxe_init_internal_common(struct bxe_softc *sc)
9862 * Zero this manually as its initialization is currently missing
9865 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++) {
9867 (BAR_USTRORM_INTMEM + USTORM_AGG_DATA_OFFSET + (i * 4)),
9871 if (!CHIP_IS_E1x(sc)) {
9872 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET),
9873 CHIP_INT_MODE_IS_BC(sc) ? HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
9878 bxe_init_internal(struct bxe_softc *sc,
9881 switch (load_code) {
9882 case FW_MSG_CODE_DRV_LOAD_COMMON:
9883 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
9884 bxe_init_internal_common(sc);
9887 case FW_MSG_CODE_DRV_LOAD_PORT:
9891 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
9892 /* internal memory per function is initialized inside bxe_pf_init */
9896 BLOGE(sc, "Unknown load_code (0x%x) from MCP\n", load_code);
9902 storm_memset_func_cfg(struct bxe_softc *sc,
9903 struct tstorm_eth_function_common_config *tcfg,
9909 addr = (BAR_TSTRORM_INTMEM +
9910 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid));
9911 size = sizeof(struct tstorm_eth_function_common_config);
9912 ecore_storm_memset_struct(sc, addr, size, (uint32_t *)tcfg);
9916 bxe_func_init(struct bxe_softc *sc,
9917 struct bxe_func_init_params *p)
9919 struct tstorm_eth_function_common_config tcfg = { 0 };
9921 if (CHIP_IS_E1x(sc)) {
9922 storm_memset_func_cfg(sc, &tcfg, p->func_id);
9925 /* Enable the function in the FW */
9926 storm_memset_vf_to_pf(sc, p->func_id, p->pf_id);
9927 storm_memset_func_en(sc, p->func_id, 1);
9930 if (p->func_flgs & FUNC_FLG_SPQ) {
9931 storm_memset_spq_addr(sc, p->spq_map, p->func_id);
9933 (XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PROD_OFFSET(p->func_id)),
9939 * Calculates the sum of vn_min_rates.
9940 * It's needed for further normalizing of the min_rates.
9942 * sum of vn_min_rates.
9944 * 0 - if all the min_rates are 0.
9945 * In the later case fainess algorithm should be deactivated.
9946 * If all min rates are not zero then those that are zeroes will be set to 1.
9949 bxe_calc_vn_min(struct bxe_softc *sc,
9950 struct cmng_init_input *input)
9953 uint32_t vn_min_rate;
9957 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
9958 vn_cfg = sc->devinfo.mf_info.mf_config[vn];
9959 vn_min_rate = (((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
9960 FUNC_MF_CFG_MIN_BW_SHIFT) * 100);
9962 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
9963 /* skip hidden VNs */
9965 } else if (!vn_min_rate) {
9966 /* If min rate is zero - set it to 100 */
9967 vn_min_rate = DEF_MIN_RATE;
9972 input->vnic_min_rate[vn] = vn_min_rate;
9975 /* if ETS or all min rates are zeros - disable fairness */
9976 if (BXE_IS_ETS_ENABLED(sc)) {
9977 input->flags.cmng_enables &= ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
9978 BLOGD(sc, DBG_LOAD, "Fairness disabled (ETS)\n");
9979 } else if (all_zero) {
9980 input->flags.cmng_enables &= ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
9982 "Fariness disabled (all MIN values are zeroes)\n");
9984 input->flags.cmng_enables |= CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
9988 static inline uint16_t
9989 bxe_extract_max_cfg(struct bxe_softc *sc,
9992 uint16_t max_cfg = ((mf_cfg & FUNC_MF_CFG_MAX_BW_MASK) >>
9993 FUNC_MF_CFG_MAX_BW_SHIFT);
9996 BLOGD(sc, DBG_LOAD, "Max BW configured to 0 - using 100 instead\n");
10004 bxe_calc_vn_max(struct bxe_softc *sc,
10006 struct cmng_init_input *input)
10008 uint16_t vn_max_rate;
10009 uint32_t vn_cfg = sc->devinfo.mf_info.mf_config[vn];
10012 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
10015 max_cfg = bxe_extract_max_cfg(sc, vn_cfg);
10017 if (IS_MF_SI(sc)) {
10018 /* max_cfg in percents of linkspeed */
10019 vn_max_rate = ((sc->link_vars.line_speed * max_cfg) / 100);
10020 } else { /* SD modes */
10021 /* max_cfg is absolute in 100Mb units */
10022 vn_max_rate = (max_cfg * 100);
10026 BLOGD(sc, DBG_LOAD, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
10028 input->vnic_max_rate[vn] = vn_max_rate;
10032 bxe_cmng_fns_init(struct bxe_softc *sc,
10036 struct cmng_init_input input;
10039 memset(&input, 0, sizeof(struct cmng_init_input));
10041 input.port_rate = sc->link_vars.line_speed;
10043 if (cmng_type == CMNG_FNS_MINMAX) {
10044 /* read mf conf from shmem */
10046 bxe_read_mf_cfg(sc);
10049 /* get VN min rate and enable fairness if not 0 */
10050 bxe_calc_vn_min(sc, &input);
10052 /* get VN max rate */
10053 if (sc->port.pmf) {
10054 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
10055 bxe_calc_vn_max(sc, vn, &input);
10059 /* always enable rate shaping and fairness */
10060 input.flags.cmng_enables |= CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
10062 ecore_init_cmng(&input, &sc->cmng);
10066 /* rate shaping and fairness are disabled */
10067 BLOGD(sc, DBG_LOAD, "rate shaping and fairness have been disabled\n");
10071 bxe_get_cmng_fns_mode(struct bxe_softc *sc)
10073 if (CHIP_REV_IS_SLOW(sc)) {
10074 return (CMNG_FNS_NONE);
10078 return (CMNG_FNS_MINMAX);
10081 return (CMNG_FNS_NONE);
10085 storm_memset_cmng(struct bxe_softc *sc,
10086 struct cmng_init *cmng,
10094 addr = (BAR_XSTRORM_INTMEM +
10095 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port));
10096 size = sizeof(struct cmng_struct_per_port);
10097 ecore_storm_memset_struct(sc, addr, size, (uint32_t *)&cmng->port);
10099 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
10100 func = func_by_vn(sc, vn);
10102 addr = (BAR_XSTRORM_INTMEM +
10103 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func));
10104 size = sizeof(struct rate_shaping_vars_per_vn);
10105 ecore_storm_memset_struct(sc, addr, size,
10106 (uint32_t *)&cmng->vnic.vnic_max_rate[vn]);
10108 addr = (BAR_XSTRORM_INTMEM +
10109 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func));
10110 size = sizeof(struct fairness_vars_per_vn);
10111 ecore_storm_memset_struct(sc, addr, size,
10112 (uint32_t *)&cmng->vnic.vnic_min_rate[vn]);
10117 bxe_pf_init(struct bxe_softc *sc)
10119 struct bxe_func_init_params func_init = { 0 };
10120 struct event_ring_data eq_data = { { 0 } };
10123 if (!CHIP_IS_E1x(sc)) {
10124 /* reset IGU PF statistics: MSIX + ATTN */
10127 (IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
10128 (BXE_IGU_STAS_MSG_VF_CNT * 4) +
10129 ((CHIP_IS_MODE_4_PORT(sc) ? SC_FUNC(sc) : SC_VN(sc)) * 4)),
10133 (IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
10134 (BXE_IGU_STAS_MSG_VF_CNT * 4) +
10135 (BXE_IGU_STAS_MSG_PF_CNT * 4) +
10136 ((CHIP_IS_MODE_4_PORT(sc) ? SC_FUNC(sc) : SC_VN(sc)) * 4)),
10140 /* function setup flags */
10141 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
10144 * This flag is relevant for E1x only.
10145 * E2 doesn't have a TPA configuration in a function level.
10147 flags |= (sc->ifnet->if_capenable & IFCAP_LRO) ? FUNC_FLG_TPA : 0;
10149 func_init.func_flgs = flags;
10150 func_init.pf_id = SC_FUNC(sc);
10151 func_init.func_id = SC_FUNC(sc);
10152 func_init.spq_map = sc->spq_dma.paddr;
10153 func_init.spq_prod = sc->spq_prod_idx;
10155 bxe_func_init(sc, &func_init);
10157 memset(&sc->cmng, 0, sizeof(struct cmng_struct_per_port));
10160 * Congestion management values depend on the link rate.
10161 * There is no active link so initial link rate is set to 10Gbps.
10162 * When the link comes up the congestion management values are
10163 * re-calculated according to the actual link rate.
10165 sc->link_vars.line_speed = SPEED_10000;
10166 bxe_cmng_fns_init(sc, TRUE, bxe_get_cmng_fns_mode(sc));
10168 /* Only the PMF sets the HW */
10169 if (sc->port.pmf) {
10170 storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc));
10173 /* init Event Queue - PCI bus guarantees correct endainity */
10174 eq_data.base_addr.hi = U64_HI(sc->eq_dma.paddr);
10175 eq_data.base_addr.lo = U64_LO(sc->eq_dma.paddr);
10176 eq_data.producer = sc->eq_prod;
10177 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
10178 eq_data.sb_id = DEF_SB_ID;
10179 storm_memset_eq_data(sc, &eq_data, SC_FUNC(sc));
10183 bxe_hc_int_enable(struct bxe_softc *sc)
10185 int port = SC_PORT(sc);
10186 uint32_t addr = (port) ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
10187 uint32_t val = REG_RD(sc, addr);
10188 uint8_t msix = (sc->interrupt_mode == INTR_MODE_MSIX) ? TRUE : FALSE;
10189 uint8_t single_msix = ((sc->interrupt_mode == INTR_MODE_MSIX) &&
10190 (sc->intr_count == 1)) ? TRUE : FALSE;
10191 uint8_t msi = (sc->interrupt_mode == INTR_MODE_MSI) ? TRUE : FALSE;
10194 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10195 HC_CONFIG_0_REG_INT_LINE_EN_0);
10196 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
10197 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10199 val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
10202 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
10203 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10204 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
10205 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10207 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10208 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
10209 HC_CONFIG_0_REG_INT_LINE_EN_0 |
10210 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10212 if (!CHIP_IS_E1(sc)) {
10213 BLOGD(sc, DBG_INTR, "write %x to HC %d (addr 0x%x)\n",
10216 REG_WR(sc, addr, val);
10218 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
10222 if (CHIP_IS_E1(sc)) {
10223 REG_WR(sc, (HC_REG_INT_MASK + port*4), 0x1FFFF);
10226 BLOGD(sc, DBG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n",
10227 val, port, addr, ((msix) ? "MSI-X" : ((msi) ? "MSI" : "INTx")));
10229 REG_WR(sc, addr, val);
10231 /* ensure that HC_CONFIG is written before leading/trailing edge config */
10234 if (!CHIP_IS_E1(sc)) {
10235 /* init leading/trailing edge */
10237 val = (0xee0f | (1 << (SC_VN(sc) + 4)));
10238 if (sc->port.pmf) {
10239 /* enable nig and gpio3 attention */
10246 REG_WR(sc, (HC_REG_TRAILING_EDGE_0 + port*8), val);
10247 REG_WR(sc, (HC_REG_LEADING_EDGE_0 + port*8), val);
10250 /* make sure that interrupts are indeed enabled from here on */
10255 bxe_igu_int_enable(struct bxe_softc *sc)
10258 uint8_t msix = (sc->interrupt_mode == INTR_MODE_MSIX) ? TRUE : FALSE;
10259 uint8_t single_msix = ((sc->interrupt_mode == INTR_MODE_MSIX) &&
10260 (sc->intr_count == 1)) ? TRUE : FALSE;
10261 uint8_t msi = (sc->interrupt_mode == INTR_MODE_MSI) ? TRUE : FALSE;
10263 val = REG_RD(sc, IGU_REG_PF_CONFIGURATION);
10266 val &= ~(IGU_PF_CONF_INT_LINE_EN |
10267 IGU_PF_CONF_SINGLE_ISR_EN);
10268 val |= (IGU_PF_CONF_MSI_MSIX_EN |
10269 IGU_PF_CONF_ATTN_BIT_EN);
10271 val |= IGU_PF_CONF_SINGLE_ISR_EN;
10274 val &= ~IGU_PF_CONF_INT_LINE_EN;
10275 val |= (IGU_PF_CONF_MSI_MSIX_EN |
10276 IGU_PF_CONF_ATTN_BIT_EN |
10277 IGU_PF_CONF_SINGLE_ISR_EN);
10279 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
10280 val |= (IGU_PF_CONF_INT_LINE_EN |
10281 IGU_PF_CONF_ATTN_BIT_EN |
10282 IGU_PF_CONF_SINGLE_ISR_EN);
10285 /* clean previous status - need to configure igu prior to ack*/
10286 if ((!msix) || single_msix) {
10287 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
10291 val |= IGU_PF_CONF_FUNC_EN;
10293 BLOGD(sc, DBG_INTR, "write 0x%x to IGU mode %s\n",
10294 val, ((msix) ? "MSI-X" : ((msi) ? "MSI" : "INTx")));
10296 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
10300 /* init leading/trailing edge */
10302 val = (0xee0f | (1 << (SC_VN(sc) + 4)));
10303 if (sc->port.pmf) {
10304 /* enable nig and gpio3 attention */
10311 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, val);
10312 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, val);
10314 /* make sure that interrupts are indeed enabled from here on */
10319 bxe_int_enable(struct bxe_softc *sc)
10321 if (sc->devinfo.int_block == INT_BLOCK_HC) {
10322 bxe_hc_int_enable(sc);
10324 bxe_igu_int_enable(sc);
10329 bxe_hc_int_disable(struct bxe_softc *sc)
10331 int port = SC_PORT(sc);
10332 uint32_t addr = (port) ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
10333 uint32_t val = REG_RD(sc, addr);
10336 * In E1 we must use only PCI configuration space to disable MSI/MSIX
10337 * capablility. It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC
10340 if (CHIP_IS_E1(sc)) {
10342 * Since IGU_PF_CONF_MSI_MSIX_EN still always on use mask register
10343 * to prevent from HC sending interrupts after we exit the function
10345 REG_WR(sc, (HC_REG_INT_MASK + port*4), 0);
10347 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10348 HC_CONFIG_0_REG_INT_LINE_EN_0 |
10349 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10351 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10352 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
10353 HC_CONFIG_0_REG_INT_LINE_EN_0 |
10354 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10357 BLOGD(sc, DBG_INTR, "write %x to HC %d (addr 0x%x)\n", val, port, addr);
10359 /* flush all outstanding writes */
10362 REG_WR(sc, addr, val);
10363 if (REG_RD(sc, addr) != val) {
10364 BLOGE(sc, "proper val not read from HC IGU!\n");
10369 bxe_igu_int_disable(struct bxe_softc *sc)
10371 uint32_t val = REG_RD(sc, IGU_REG_PF_CONFIGURATION);
10373 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
10374 IGU_PF_CONF_INT_LINE_EN |
10375 IGU_PF_CONF_ATTN_BIT_EN);
10377 BLOGD(sc, DBG_INTR, "write %x to IGU\n", val);
10379 /* flush all outstanding writes */
10382 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
10383 if (REG_RD(sc, IGU_REG_PF_CONFIGURATION) != val) {
10384 BLOGE(sc, "proper val not read from IGU!\n");
10389 bxe_int_disable(struct bxe_softc *sc)
10391 if (sc->devinfo.int_block == INT_BLOCK_HC) {
10392 bxe_hc_int_disable(sc);
10394 bxe_igu_int_disable(sc);
10399 bxe_nic_init(struct bxe_softc *sc,
10404 for (i = 0; i < sc->num_queues; i++) {
10405 bxe_init_eth_fp(sc, i);
10408 rmb(); /* ensure status block indices were read */
10410 bxe_init_rx_rings(sc);
10411 bxe_init_tx_rings(sc);
10417 /* initialize MOD_ABS interrupts */
10418 elink_init_mod_abs_int(sc, &sc->link_vars,
10419 sc->devinfo.chip_id,
10420 sc->devinfo.shmem_base,
10421 sc->devinfo.shmem2_base,
10424 bxe_init_def_sb(sc);
10425 bxe_update_dsb_idx(sc);
10426 bxe_init_sp_ring(sc);
10427 bxe_init_eq_ring(sc);
10428 bxe_init_internal(sc, load_code);
10430 bxe_stats_init(sc);
10432 /* flush all before enabling interrupts */
10435 bxe_int_enable(sc);
10437 /* check for SPIO5 */
10438 bxe_attn_int_deasserted0(sc,
10440 (MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
10442 AEU_INPUTS_ATTN_BITS_SPIO5);
10446 bxe_init_objs(struct bxe_softc *sc)
10448 /* mcast rules must be added to tx if tx switching is enabled */
10449 ecore_obj_type o_type =
10450 (sc->flags & BXE_TX_SWITCHING) ? ECORE_OBJ_TYPE_RX_TX :
10453 /* RX_MODE controlling object */
10454 ecore_init_rx_mode_obj(sc, &sc->rx_mode_obj);
10456 /* multicast configuration controlling object */
10457 ecore_init_mcast_obj(sc,
10463 BXE_SP(sc, mcast_rdata),
10464 BXE_SP_MAPPING(sc, mcast_rdata),
10465 ECORE_FILTER_MCAST_PENDING,
10469 /* Setup CAM credit pools */
10470 ecore_init_mac_credit_pool(sc,
10473 CHIP_IS_E1x(sc) ? VNICS_PER_PORT(sc) :
10474 VNICS_PER_PATH(sc));
10476 ecore_init_vlan_credit_pool(sc,
10478 SC_ABS_FUNC(sc) >> 1,
10479 CHIP_IS_E1x(sc) ? VNICS_PER_PORT(sc) :
10480 VNICS_PER_PATH(sc));
10482 /* RSS configuration object */
10483 ecore_init_rss_config_obj(sc,
10489 BXE_SP(sc, rss_rdata),
10490 BXE_SP_MAPPING(sc, rss_rdata),
10491 ECORE_FILTER_RSS_CONF_PENDING,
10492 &sc->sp_state, ECORE_OBJ_TYPE_RX);
10496 * Initialize the function. This must be called before sending CLIENT_SETUP
10497 * for the first client.
10500 bxe_func_start(struct bxe_softc *sc)
10502 struct ecore_func_state_params func_params = { NULL };
10503 struct ecore_func_start_params *start_params = &func_params.params.start;
10505 /* Prepare parameters for function state transitions */
10506 bit_set(&func_params.ramrod_flags, RAMROD_COMP_WAIT);
10508 func_params.f_obj = &sc->func_obj;
10509 func_params.cmd = ECORE_F_CMD_START;
10511 /* Function parameters */
10512 start_params->mf_mode = sc->devinfo.mf_info.mf_mode;
10513 start_params->sd_vlan_tag = OVLAN(sc);
10515 if (CHIP_IS_E2(sc) || CHIP_IS_E3(sc)) {
10516 start_params->network_cos_mode = STATIC_COS;
10517 } else { /* CHIP_IS_E1X */
10518 start_params->network_cos_mode = FW_WRR;
10521 //start_params->gre_tunnel_mode = 0;
10522 //start_params->gre_tunnel_rss = 0;
10524 return (ecore_func_state_change(sc, &func_params));
10528 bxe_set_power_state(struct bxe_softc *sc,
10533 /* If there is no power capability, silently succeed */
10534 if (!(sc->devinfo.pcie_cap_flags & BXE_PM_CAPABLE_FLAG)) {
10535 BLOGW(sc, "No power capability\n");
10539 pmcsr = pci_read_config(sc->dev,
10540 (sc->devinfo.pcie_pm_cap_reg + PCIR_POWER_STATUS),
10545 pci_write_config(sc->dev,
10546 (sc->devinfo.pcie_pm_cap_reg + PCIR_POWER_STATUS),
10547 ((pmcsr & ~PCIM_PSTAT_DMASK) | PCIM_PSTAT_PME), 2);
10549 if (pmcsr & PCIM_PSTAT_DMASK) {
10550 /* delay required during transition out of D3hot */
10557 /* XXX if there are other clients above don't shut down the power */
10559 /* don't shut down the power for emulation and FPGA */
10560 if (CHIP_REV_IS_SLOW(sc)) {
10564 pmcsr &= ~PCIM_PSTAT_DMASK;
10565 pmcsr |= PCIM_PSTAT_D3;
10568 pmcsr |= PCIM_PSTAT_PMEENABLE;
10571 pci_write_config(sc->dev,
10572 (sc->devinfo.pcie_pm_cap_reg + PCIR_POWER_STATUS),
10576 * No more memory access after this point until device is brought back
10582 BLOGE(sc, "Can't support PCI power state = 0x%x pmcsr 0x%x\n",
10591 /* return true if succeeded to acquire the lock */
10593 bxe_trylock_hw_lock(struct bxe_softc *sc,
10596 uint32_t lock_status;
10597 uint32_t resource_bit = (1 << resource);
10598 int func = SC_FUNC(sc);
10599 uint32_t hw_lock_control_reg;
10601 BLOGD(sc, DBG_LOAD, "Trying to take a resource lock 0x%x\n", resource);
10603 /* Validating that the resource is within range */
10604 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
10605 BLOGD(sc, DBG_LOAD,
10606 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
10607 resource, HW_LOCK_MAX_RESOURCE_VALUE);
10612 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
10614 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
10617 /* try to acquire the lock */
10618 REG_WR(sc, hw_lock_control_reg + 4, resource_bit);
10619 lock_status = REG_RD(sc, hw_lock_control_reg);
10620 if (lock_status & resource_bit) {
10624 BLOGE(sc, "Failed to get a resource lock 0x%x func %d "
10625 "lock_status 0x%x resource_bit 0x%x\n", resource, func,
10626 lock_status, resource_bit);
10632 * Get the recovery leader resource id according to the engine this function
10633 * belongs to. Currently only only 2 engines is supported.
10636 bxe_get_leader_lock_resource(struct bxe_softc *sc)
10639 return (HW_LOCK_RESOURCE_RECOVERY_LEADER_1);
10641 return (HW_LOCK_RESOURCE_RECOVERY_LEADER_0);
10645 /* try to acquire a leader lock for current engine */
10647 bxe_trylock_leader_lock(struct bxe_softc *sc)
10649 return (bxe_trylock_hw_lock(sc, bxe_get_leader_lock_resource(sc)));
10653 bxe_release_leader_lock(struct bxe_softc *sc)
10655 return (bxe_release_hw_lock(sc, bxe_get_leader_lock_resource(sc)));
10658 /* close gates #2, #3 and #4 */
10660 bxe_set_234_gates(struct bxe_softc *sc,
10665 /* gates #2 and #4a are closed/opened for "not E1" only */
10666 if (!CHIP_IS_E1(sc)) {
10668 REG_WR(sc, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
10670 REG_WR(sc, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
10674 if (CHIP_IS_E1x(sc)) {
10675 /* prevent interrupts from HC on both ports */
10676 val = REG_RD(sc, HC_REG_CONFIG_1);
10677 REG_WR(sc, HC_REG_CONFIG_1,
10678 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
10679 (val & ~(uint32_t)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
10681 val = REG_RD(sc, HC_REG_CONFIG_0);
10682 REG_WR(sc, HC_REG_CONFIG_0,
10683 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
10684 (val & ~(uint32_t)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
10686 /* Prevent incomming interrupts in IGU */
10687 val = REG_RD(sc, IGU_REG_BLOCK_CONFIGURATION);
10689 REG_WR(sc, IGU_REG_BLOCK_CONFIGURATION,
10691 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
10692 (val & ~(uint32_t)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
10695 BLOGD(sc, DBG_LOAD, "%s gates #2, #3 and #4\n",
10696 close ? "closing" : "opening");
10701 /* poll for pending writes bit, it should get cleared in no more than 1s */
10703 bxe_er_poll_igu_vq(struct bxe_softc *sc)
10705 uint32_t cnt = 1000;
10706 uint32_t pend_bits = 0;
10709 pend_bits = REG_RD(sc, IGU_REG_PENDING_BITS_STATUS);
10711 if (pend_bits == 0) {
10716 } while (--cnt > 0);
10719 BLOGE(sc, "Still pending IGU requests bits=0x%08x!\n", pend_bits);
10726 #define SHARED_MF_CLP_MAGIC 0x80000000 /* 'magic' bit */
10729 bxe_clp_reset_prep(struct bxe_softc *sc,
10730 uint32_t *magic_val)
10732 /* Do some magic... */
10733 uint32_t val = MFCFG_RD(sc, shared_mf_config.clp_mb);
10734 *magic_val = val & SHARED_MF_CLP_MAGIC;
10735 MFCFG_WR(sc, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
10738 /* restore the value of the 'magic' bit */
10740 bxe_clp_reset_done(struct bxe_softc *sc,
10741 uint32_t magic_val)
10743 /* Restore the 'magic' bit value... */
10744 uint32_t val = MFCFG_RD(sc, shared_mf_config.clp_mb);
10745 MFCFG_WR(sc, shared_mf_config.clp_mb,
10746 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
10749 /* prepare for MCP reset, takes care of CLP configurations */
10751 bxe_reset_mcp_prep(struct bxe_softc *sc,
10752 uint32_t *magic_val)
10755 uint32_t validity_offset;
10757 /* set `magic' bit in order to save MF config */
10758 if (!CHIP_IS_E1(sc)) {
10759 bxe_clp_reset_prep(sc, magic_val);
10762 /* get shmem offset */
10763 shmem = REG_RD(sc, MISC_REG_SHARED_MEM_ADDR);
10765 offsetof(struct shmem_region, validity_map[SC_PORT(sc)]);
10767 /* Clear validity map flags */
10769 REG_WR(sc, shmem + validity_offset, 0);
10773 #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
10774 #define MCP_ONE_TIMEOUT 100 /* 100 ms */
10777 bxe_mcp_wait_one(struct bxe_softc *sc)
10779 /* special handling for emulation and FPGA (10 times longer) */
10780 if (CHIP_REV_IS_SLOW(sc)) {
10781 DELAY((MCP_ONE_TIMEOUT*10) * 1000);
10783 DELAY((MCP_ONE_TIMEOUT) * 1000);
10787 /* initialize shmem_base and waits for validity signature to appear */
10789 bxe_init_shmem(struct bxe_softc *sc)
10795 sc->devinfo.shmem_base =
10796 sc->link_params.shmem_base =
10797 REG_RD(sc, MISC_REG_SHARED_MEM_ADDR);
10799 if (sc->devinfo.shmem_base) {
10800 val = SHMEM_RD(sc, validity_map[SC_PORT(sc)]);
10801 if (val & SHR_MEM_VALIDITY_MB)
10805 bxe_mcp_wait_one(sc);
10807 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
10809 BLOGE(sc, "BAD MCP validity signature\n");
10815 bxe_reset_mcp_comp(struct bxe_softc *sc,
10816 uint32_t magic_val)
10818 int rc = bxe_init_shmem(sc);
10820 /* Restore the `magic' bit value */
10821 if (!CHIP_IS_E1(sc)) {
10822 bxe_clp_reset_done(sc, magic_val);
10829 bxe_pxp_prep(struct bxe_softc *sc)
10831 if (!CHIP_IS_E1(sc)) {
10832 REG_WR(sc, PXP2_REG_RD_START_INIT, 0);
10833 REG_WR(sc, PXP2_REG_RQ_RBC_DONE, 0);
10839 * Reset the whole chip except for:
10841 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by one reset bit)
10843 * - MISC (including AEU)
10848 bxe_process_kill_chip_reset(struct bxe_softc *sc,
10851 uint32_t not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
10852 uint32_t global_bits2, stay_reset2;
10855 * Bits that have to be set in reset_mask2 if we want to reset 'global'
10856 * (per chip) blocks.
10859 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
10860 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
10863 * Don't reset the following blocks.
10864 * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
10865 * reset, as in 4 port device they might still be owned
10866 * by the MCP (there is only one leader per path).
10869 MISC_REGISTERS_RESET_REG_1_RST_HC |
10870 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
10871 MISC_REGISTERS_RESET_REG_1_RST_PXP;
10874 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
10875 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
10876 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
10877 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
10878 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
10879 MISC_REGISTERS_RESET_REG_2_RST_GRC |
10880 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
10881 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
10882 MISC_REGISTERS_RESET_REG_2_RST_ATC |
10883 MISC_REGISTERS_RESET_REG_2_PGLC |
10884 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
10885 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
10886 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
10887 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
10888 MISC_REGISTERS_RESET_REG_2_UMAC0 |
10889 MISC_REGISTERS_RESET_REG_2_UMAC1;
10892 * Keep the following blocks in reset:
10893 * - all xxMACs are handled by the elink code.
10896 MISC_REGISTERS_RESET_REG_2_XMAC |
10897 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
10899 /* Full reset masks according to the chip */
10900 reset_mask1 = 0xffffffff;
10902 if (CHIP_IS_E1(sc))
10903 reset_mask2 = 0xffff;
10904 else if (CHIP_IS_E1H(sc))
10905 reset_mask2 = 0x1ffff;
10906 else if (CHIP_IS_E2(sc))
10907 reset_mask2 = 0xfffff;
10908 else /* CHIP_IS_E3 */
10909 reset_mask2 = 0x3ffffff;
10911 /* Don't reset global blocks unless we need to */
10913 reset_mask2 &= ~global_bits2;
10916 * In case of attention in the QM, we need to reset PXP
10917 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
10918 * because otherwise QM reset would release 'close the gates' shortly
10919 * before resetting the PXP, then the PSWRQ would send a write
10920 * request to PGLUE. Then when PXP is reset, PGLUE would try to
10921 * read the payload data from PSWWR, but PSWWR would not
10922 * respond. The write queue in PGLUE would stuck, dmae commands
10923 * would not return. Therefore it's important to reset the second
10924 * reset register (containing the
10925 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
10926 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
10929 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
10930 reset_mask2 & (~not_reset_mask2));
10932 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
10933 reset_mask1 & (~not_reset_mask1));
10938 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
10939 reset_mask2 & (~stay_reset2));
10944 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
10949 bxe_process_kill(struct bxe_softc *sc,
10954 uint32_t sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
10955 uint32_t tags_63_32 = 0;
10957 /* Empty the Tetris buffer, wait for 1s */
10959 sr_cnt = REG_RD(sc, PXP2_REG_RD_SR_CNT);
10960 blk_cnt = REG_RD(sc, PXP2_REG_RD_BLK_CNT);
10961 port_is_idle_0 = REG_RD(sc, PXP2_REG_RD_PORT_IS_IDLE_0);
10962 port_is_idle_1 = REG_RD(sc, PXP2_REG_RD_PORT_IS_IDLE_1);
10963 pgl_exp_rom2 = REG_RD(sc, PXP2_REG_PGL_EXP_ROM2);
10964 if (CHIP_IS_E3(sc)) {
10965 tags_63_32 = REG_RD(sc, PGLUE_B_REG_TAGS_63_32);
10968 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
10969 ((port_is_idle_0 & 0x1) == 0x1) &&
10970 ((port_is_idle_1 & 0x1) == 0x1) &&
10971 (pgl_exp_rom2 == 0xffffffff) &&
10972 (!CHIP_IS_E3(sc) || (tags_63_32 == 0xffffffff)))
10975 } while (cnt-- > 0);
10978 BLOGE(sc, "ERROR: Tetris buffer didn't get empty or there "
10979 "are still outstanding read requests after 1s! "
10980 "sr_cnt=0x%08x, blk_cnt=0x%08x, port_is_idle_0=0x%08x, "
10981 "port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
10982 sr_cnt, blk_cnt, port_is_idle_0,
10983 port_is_idle_1, pgl_exp_rom2);
10989 /* Close gates #2, #3 and #4 */
10990 bxe_set_234_gates(sc, TRUE);
10992 /* Poll for IGU VQs for 57712 and newer chips */
10993 if (!CHIP_IS_E1x(sc) && bxe_er_poll_igu_vq(sc)) {
10997 /* XXX indicate that "process kill" is in progress to MCP */
10999 /* clear "unprepared" bit */
11000 REG_WR(sc, MISC_REG_UNPREPARED, 0);
11003 /* Make sure all is written to the chip before the reset */
11007 * Wait for 1ms to empty GLUE and PCI-E core queues,
11008 * PSWHST, GRC and PSWRD Tetris buffer.
11012 /* Prepare to chip reset: */
11015 bxe_reset_mcp_prep(sc, &val);
11022 /* reset the chip */
11023 bxe_process_kill_chip_reset(sc, global);
11026 /* clear errors in PGB */
11027 if (!CHIP_IS_E1(sc))
11028 REG_WR(sc, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
11030 /* Recover after reset: */
11032 if (global && bxe_reset_mcp_comp(sc, val)) {
11036 /* XXX add resetting the NO_MCP mode DB here */
11038 /* Open the gates #2, #3 and #4 */
11039 bxe_set_234_gates(sc, FALSE);
11042 * IGU/AEU preparation bring back the AEU/IGU to a reset state
11043 * re-enable attentions
11050 bxe_leader_reset(struct bxe_softc *sc)
11053 uint8_t global = bxe_reset_is_global(sc);
11054 uint32_t load_code;
11057 * If not going to reset MCP, load "fake" driver to reset HW while
11058 * driver is owner of the HW.
11060 if (!global && !BXE_NOMCP(sc)) {
11061 load_code = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_REQ,
11062 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
11064 BLOGE(sc, "MCP response failure, aborting\n");
11066 goto exit_leader_reset;
11069 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
11070 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
11071 BLOGE(sc, "MCP unexpected response, aborting\n");
11073 goto exit_leader_reset2;
11076 load_code = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
11078 BLOGE(sc, "MCP response failure, aborting\n");
11080 goto exit_leader_reset2;
11084 /* try to recover after the failure */
11085 if (bxe_process_kill(sc, global)) {
11086 BLOGE(sc, "Something bad occurred on engine %d!\n", SC_PATH(sc));
11088 goto exit_leader_reset2;
11092 * Clear the RESET_IN_PROGRESS and RESET_GLOBAL bits and update the driver
11095 bxe_set_reset_done(sc);
11097 bxe_clear_reset_global(sc);
11100 exit_leader_reset2:
11102 /* unload "fake driver" if it was loaded */
11103 if (!global && !BXE_NOMCP(sc)) {
11104 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
11105 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, 0);
11111 bxe_release_leader_lock(sc);
11118 * prepare INIT transition, parameters configured:
11119 * - HC configuration
11120 * - Queue's CDU context
11123 bxe_pf_q_prep_init(struct bxe_softc *sc,
11124 struct bxe_fastpath *fp,
11125 struct ecore_queue_init_params *init_params)
11128 int cxt_index, cxt_offset;
11130 bxe_set_bit(ECORE_Q_FLG_HC, &init_params->rx.flags);
11131 bxe_set_bit(ECORE_Q_FLG_HC, &init_params->tx.flags);
11133 bxe_set_bit(ECORE_Q_FLG_HC_EN, &init_params->rx.flags);
11134 bxe_set_bit(ECORE_Q_FLG_HC_EN, &init_params->tx.flags);
11137 init_params->rx.hc_rate =
11138 sc->hc_rx_ticks ? (1000000 / sc->hc_rx_ticks) : 0;
11139 init_params->tx.hc_rate =
11140 sc->hc_tx_ticks ? (1000000 / sc->hc_tx_ticks) : 0;
11143 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id = fp->fw_sb_id;
11145 /* CQ index among the SB indices */
11146 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
11147 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
11149 /* set maximum number of COSs supported by this queue */
11150 init_params->max_cos = sc->max_cos;
11152 BLOGD(sc, DBG_LOAD, "fp %d setting queue params max cos to %d\n",
11153 fp->index, init_params->max_cos);
11155 /* set the context pointers queue object */
11156 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
11157 /* XXX change index/cid here if ever support multiple tx CoS */
11158 /* fp->txdata[cos]->cid */
11159 cxt_index = fp->index / ILT_PAGE_CIDS;
11160 cxt_offset = fp->index - (cxt_index * ILT_PAGE_CIDS);
11161 init_params->cxts[cos] = &sc->context[cxt_index].vcxt[cxt_offset].eth;
11165 /* set flags that are common for the Tx-only and not normal connections */
11166 static unsigned long
11167 bxe_get_common_flags(struct bxe_softc *sc,
11168 struct bxe_fastpath *fp,
11169 uint8_t zero_stats)
11171 unsigned long flags = 0;
11173 /* PF driver will always initialize the Queue to an ACTIVE state */
11174 bxe_set_bit(ECORE_Q_FLG_ACTIVE, &flags);
11177 * tx only connections collect statistics (on the same index as the
11178 * parent connection). The statistics are zeroed when the parent
11179 * connection is initialized.
11182 bxe_set_bit(ECORE_Q_FLG_STATS, &flags);
11184 bxe_set_bit(ECORE_Q_FLG_ZERO_STATS, &flags);
11188 * tx only connections can support tx-switching, though their
11189 * CoS-ness doesn't survive the loopback
11191 if (sc->flags & BXE_TX_SWITCHING) {
11192 bxe_set_bit(ECORE_Q_FLG_TX_SWITCH, &flags);
11195 bxe_set_bit(ECORE_Q_FLG_PCSUM_ON_PKT, &flags);
11200 static unsigned long
11201 bxe_get_q_flags(struct bxe_softc *sc,
11202 struct bxe_fastpath *fp,
11205 unsigned long flags = 0;
11207 if (IS_MF_SD(sc)) {
11208 bxe_set_bit(ECORE_Q_FLG_OV, &flags);
11211 if (sc->ifnet->if_capenable & IFCAP_LRO) {
11212 bxe_set_bit(ECORE_Q_FLG_TPA, &flags);
11213 #if __FreeBSD_version >= 800000
11214 bxe_set_bit(ECORE_Q_FLG_TPA_IPV6, &flags);
11219 bxe_set_bit(ECORE_Q_FLG_LEADING_RSS, &flags);
11220 bxe_set_bit(ECORE_Q_FLG_MCAST, &flags);
11223 bxe_set_bit(ECORE_Q_FLG_VLAN, &flags);
11225 /* merge with common flags */
11226 return (flags | bxe_get_common_flags(sc, fp, TRUE));
11230 bxe_pf_q_prep_general(struct bxe_softc *sc,
11231 struct bxe_fastpath *fp,
11232 struct ecore_general_setup_params *gen_init,
11235 gen_init->stat_id = bxe_stats_id(fp);
11236 gen_init->spcl_id = fp->cl_id;
11237 gen_init->mtu = sc->mtu;
11238 gen_init->cos = cos;
11242 bxe_pf_rx_q_prep(struct bxe_softc *sc,
11243 struct bxe_fastpath *fp,
11244 struct rxq_pause_params *pause,
11245 struct ecore_rxq_setup_params *rxq_init)
11247 uint8_t max_sge = 0;
11248 uint16_t sge_sz = 0;
11249 uint16_t tpa_agg_size = 0;
11251 pause->sge_th_lo = SGE_TH_LO(sc);
11252 pause->sge_th_hi = SGE_TH_HI(sc);
11254 /* validate SGE ring has enough to cross high threshold */
11255 if (sc->dropless_fc &&
11256 (pause->sge_th_hi + FW_PREFETCH_CNT) >
11257 (RX_SGE_USABLE_PER_PAGE * RX_SGE_NUM_PAGES)) {
11258 BLOGW(sc, "sge ring threshold limit\n");
11261 /* minimum max_aggregation_size is 2*MTU (two full buffers) */
11262 tpa_agg_size = (2 * sc->mtu);
11263 if (tpa_agg_size < sc->max_aggregation_size) {
11264 tpa_agg_size = sc->max_aggregation_size;
11267 max_sge = SGE_PAGE_ALIGN(sc->mtu) >> SGE_PAGE_SHIFT;
11268 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
11269 (~(PAGES_PER_SGE - 1))) >> PAGES_PER_SGE_SHIFT;
11270 sge_sz = (uint16_t)min(SGE_PAGES, 0xffff);
11272 /* pause - not for e1 */
11273 if (!CHIP_IS_E1(sc)) {
11274 pause->bd_th_lo = BD_TH_LO(sc);
11275 pause->bd_th_hi = BD_TH_HI(sc);
11277 pause->rcq_th_lo = RCQ_TH_LO(sc);
11278 pause->rcq_th_hi = RCQ_TH_HI(sc);
11280 /* validate rings have enough entries to cross high thresholds */
11281 if (sc->dropless_fc &&
11282 pause->bd_th_hi + FW_PREFETCH_CNT >
11283 sc->rx_ring_size) {
11284 BLOGW(sc, "rx bd ring threshold limit\n");
11287 if (sc->dropless_fc &&
11288 pause->rcq_th_hi + FW_PREFETCH_CNT >
11289 RCQ_NUM_PAGES * RCQ_USABLE_PER_PAGE) {
11290 BLOGW(sc, "rcq ring threshold limit\n");
11293 pause->pri_map = 1;
11297 rxq_init->dscr_map = fp->rx_dma.paddr;
11298 rxq_init->sge_map = fp->rx_sge_dma.paddr;
11299 rxq_init->rcq_map = fp->rcq_dma.paddr;
11300 rxq_init->rcq_np_map = (fp->rcq_dma.paddr + BCM_PAGE_SIZE);
11303 * This should be a maximum number of data bytes that may be
11304 * placed on the BD (not including paddings).
11306 rxq_init->buf_sz = (fp->rx_buf_size -
11307 IP_HEADER_ALIGNMENT_PADDING);
11309 rxq_init->cl_qzone_id = fp->cl_qzone_id;
11310 rxq_init->tpa_agg_sz = tpa_agg_size;
11311 rxq_init->sge_buf_sz = sge_sz;
11312 rxq_init->max_sges_pkt = max_sge;
11313 rxq_init->rss_engine_id = SC_FUNC(sc);
11314 rxq_init->mcast_engine_id = SC_FUNC(sc);
11317 * Maximum number or simultaneous TPA aggregation for this Queue.
11318 * For PF Clients it should be the maximum available number.
11319 * VF driver(s) may want to define it to a smaller value.
11321 rxq_init->max_tpa_queues = MAX_AGG_QS(sc);
11323 rxq_init->cache_line_log = BXE_RX_ALIGN_SHIFT;
11324 rxq_init->fw_sb_id = fp->fw_sb_id;
11326 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
11329 * configure silent vlan removal
11330 * if multi function mode is afex, then mask default vlan
11332 if (IS_MF_AFEX(sc)) {
11333 rxq_init->silent_removal_value =
11334 sc->devinfo.mf_info.afex_def_vlan_tag;
11335 rxq_init->silent_removal_mask = EVL_VLID_MASK;
11340 bxe_pf_tx_q_prep(struct bxe_softc *sc,
11341 struct bxe_fastpath *fp,
11342 struct ecore_txq_setup_params *txq_init,
11346 * XXX If multiple CoS is ever supported then each fastpath structure
11347 * will need to maintain tx producer/consumer/dma/etc values *per* CoS.
11348 * fp->txdata[cos]->tx_dma.paddr;
11350 txq_init->dscr_map = fp->tx_dma.paddr;
11351 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
11352 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
11353 txq_init->fw_sb_id = fp->fw_sb_id;
11356 * set the TSS leading client id for TX classfication to the
11357 * leading RSS client id
11359 txq_init->tss_leading_cl_id = BXE_FP(sc, 0, cl_id);
11363 * This function performs 2 steps in a queue state machine:
11368 bxe_setup_queue(struct bxe_softc *sc,
11369 struct bxe_fastpath *fp,
11372 struct ecore_queue_state_params q_params = { NULL };
11373 struct ecore_queue_setup_params *setup_params =
11374 &q_params.params.setup;
11377 BLOGD(sc, DBG_LOAD, "setting up queue %d\n", fp->index);
11379 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
11381 q_params.q_obj = &BXE_SP_OBJ(sc, fp).q_obj;
11383 /* we want to wait for completion in this context */
11384 bxe_set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
11386 /* prepare the INIT parameters */
11387 bxe_pf_q_prep_init(sc, fp, &q_params.params.init);
11389 /* Set the command */
11390 q_params.cmd = ECORE_Q_CMD_INIT;
11392 /* Change the state to INIT */
11393 rc = ecore_queue_state_change(sc, &q_params);
11395 BLOGE(sc, "Queue(%d) INIT failed rc = %d\n", fp->index, rc);
11399 BLOGD(sc, DBG_LOAD, "init complete\n");
11401 /* now move the Queue to the SETUP state */
11402 memset(setup_params, 0, sizeof(*setup_params));
11404 /* set Queue flags */
11405 setup_params->flags = bxe_get_q_flags(sc, fp, leading);
11407 /* set general SETUP parameters */
11408 bxe_pf_q_prep_general(sc, fp, &setup_params->gen_params,
11409 FIRST_TX_COS_INDEX);
11411 bxe_pf_rx_q_prep(sc, fp,
11412 &setup_params->pause_params,
11413 &setup_params->rxq_params);
11415 bxe_pf_tx_q_prep(sc, fp,
11416 &setup_params->txq_params,
11417 FIRST_TX_COS_INDEX);
11419 /* Set the command */
11420 q_params.cmd = ECORE_Q_CMD_SETUP;
11422 /* change the state to SETUP */
11423 rc = ecore_queue_state_change(sc, &q_params);
11425 BLOGE(sc, "Queue(%d) SETUP failed (rc = %d)\n", fp->index, rc);
11433 bxe_setup_leading(struct bxe_softc *sc)
11435 return (bxe_setup_queue(sc, &sc->fp[0], TRUE));
11439 bxe_config_rss_pf(struct bxe_softc *sc,
11440 struct ecore_rss_config_obj *rss_obj,
11441 uint8_t config_hash)
11443 struct ecore_config_rss_params params = { NULL };
11447 * Although RSS is meaningless when there is a single HW queue we
11448 * still need it enabled in order to have HW Rx hash generated.
11451 params.rss_obj = rss_obj;
11453 bxe_set_bit(RAMROD_COMP_WAIT, ¶ms.ramrod_flags);
11455 bxe_set_bit(ECORE_RSS_MODE_REGULAR, ¶ms.rss_flags);
11457 /* RSS configuration */
11458 bxe_set_bit(ECORE_RSS_IPV4, ¶ms.rss_flags);
11459 bxe_set_bit(ECORE_RSS_IPV4_TCP, ¶ms.rss_flags);
11460 bxe_set_bit(ECORE_RSS_IPV6, ¶ms.rss_flags);
11461 bxe_set_bit(ECORE_RSS_IPV6_TCP, ¶ms.rss_flags);
11462 if (rss_obj->udp_rss_v4) {
11463 bxe_set_bit(ECORE_RSS_IPV4_UDP, ¶ms.rss_flags);
11465 if (rss_obj->udp_rss_v6) {
11466 bxe_set_bit(ECORE_RSS_IPV6_UDP, ¶ms.rss_flags);
11470 params.rss_result_mask = MULTI_MASK;
11472 memcpy(params.ind_table, rss_obj->ind_table, sizeof(params.ind_table));
11476 for (i = 0; i < sizeof(params.rss_key) / 4; i++) {
11477 params.rss_key[i] = arc4random();
11480 bxe_set_bit(ECORE_RSS_SET_SRCH, ¶ms.rss_flags);
11483 return (ecore_config_rss(sc, ¶ms));
11487 bxe_config_rss_eth(struct bxe_softc *sc,
11488 uint8_t config_hash)
11490 return (bxe_config_rss_pf(sc, &sc->rss_conf_obj, config_hash));
11494 bxe_init_rss_pf(struct bxe_softc *sc)
11496 uint8_t num_eth_queues = BXE_NUM_ETH_QUEUES(sc);
11500 * Prepare the initial contents of the indirection table if
11503 for (i = 0; i < sizeof(sc->rss_conf_obj.ind_table); i++) {
11504 sc->rss_conf_obj.ind_table[i] =
11505 (sc->fp->cl_id + (i % num_eth_queues));
11509 sc->rss_conf_obj.udp_rss_v4 = sc->rss_conf_obj.udp_rss_v6 = 1;
11513 * For 57710 and 57711 SEARCHER configuration (rss_keys) is
11514 * per-port, so if explicit configuration is needed, do it only
11517 * For 57712 and newer it's a per-function configuration.
11519 return (bxe_config_rss_eth(sc, sc->port.pmf || !CHIP_IS_E1x(sc)));
11523 bxe_set_mac_one(struct bxe_softc *sc,
11525 struct ecore_vlan_mac_obj *obj,
11528 unsigned long *ramrod_flags)
11530 struct ecore_vlan_mac_ramrod_params ramrod_param;
11533 memset(&ramrod_param, 0, sizeof(ramrod_param));
11535 /* fill in general parameters */
11536 ramrod_param.vlan_mac_obj = obj;
11537 ramrod_param.ramrod_flags = *ramrod_flags;
11539 /* fill a user request section if needed */
11540 if (!bxe_test_bit(RAMROD_CONT, ramrod_flags)) {
11541 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
11543 bxe_set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
11545 /* Set the command: ADD or DEL */
11546 ramrod_param.user_req.cmd = (set) ? ECORE_VLAN_MAC_ADD :
11547 ECORE_VLAN_MAC_DEL;
11550 rc = ecore_config_vlan_mac(sc, &ramrod_param);
11552 if (rc == ECORE_EXISTS) {
11553 BLOGD(sc, DBG_SP, "Failed to schedule ADD operations (EEXIST)\n");
11554 /* do not treat adding same MAC as error */
11556 } else if (rc < 0) {
11557 BLOGE(sc, "%s MAC failed (%d)\n", (set ? "Set" : "Delete"), rc);
11564 bxe_set_eth_mac(struct bxe_softc *sc,
11567 unsigned long ramrod_flags = 0;
11569 BLOGD(sc, DBG_LOAD, "Adding Ethernet MAC\n");
11571 bxe_set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
11573 /* Eth MAC is set on RSS leading client (fp[0]) */
11574 return (bxe_set_mac_one(sc, sc->link_params.mac_addr,
11575 &sc->sp_objs->mac_obj,
11576 set, ECORE_ETH_MAC, &ramrod_flags));
11580 bxe_get_cur_phy_idx(struct bxe_softc *sc)
11582 uint32_t sel_phy_idx = 0;
11584 if (sc->link_params.num_phys <= 1) {
11585 return (ELINK_INT_PHY);
11588 if (sc->link_vars.link_up) {
11589 sel_phy_idx = ELINK_EXT_PHY1;
11590 /* In case link is SERDES, check if the ELINK_EXT_PHY2 is the one */
11591 if ((sc->link_vars.link_status & LINK_STATUS_SERDES_LINK) &&
11592 (sc->link_params.phy[ELINK_EXT_PHY2].supported &
11593 ELINK_SUPPORTED_FIBRE))
11594 sel_phy_idx = ELINK_EXT_PHY2;
11596 switch (elink_phy_selection(&sc->link_params)) {
11597 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
11598 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
11599 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
11600 sel_phy_idx = ELINK_EXT_PHY1;
11602 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
11603 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
11604 sel_phy_idx = ELINK_EXT_PHY2;
11609 return (sel_phy_idx);
11613 bxe_get_link_cfg_idx(struct bxe_softc *sc)
11615 uint32_t sel_phy_idx = bxe_get_cur_phy_idx(sc);
11618 * The selected activated PHY is always after swapping (in case PHY
11619 * swapping is enabled). So when swapping is enabled, we need to reverse
11620 * the configuration
11623 if (sc->link_params.multi_phy_config & PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
11624 if (sel_phy_idx == ELINK_EXT_PHY1)
11625 sel_phy_idx = ELINK_EXT_PHY2;
11626 else if (sel_phy_idx == ELINK_EXT_PHY2)
11627 sel_phy_idx = ELINK_EXT_PHY1;
11630 return (ELINK_LINK_CONFIG_IDX(sel_phy_idx));
11634 bxe_set_requested_fc(struct bxe_softc *sc)
11637 * Initialize link parameters structure variables
11638 * It is recommended to turn off RX FC for jumbo frames
11639 * for better performance
11641 if (CHIP_IS_E1x(sc) && (sc->mtu > 5000)) {
11642 sc->link_params.req_fc_auto_adv = ELINK_FLOW_CTRL_TX;
11644 sc->link_params.req_fc_auto_adv = ELINK_FLOW_CTRL_BOTH;
11649 bxe_calc_fc_adv(struct bxe_softc *sc)
11651 uint8_t cfg_idx = bxe_get_link_cfg_idx(sc);
11654 sc->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
11657 switch (sc->link_vars.ieee_fc &
11658 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
11660 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
11661 sc->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
11665 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
11666 sc->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
11676 bxe_get_mf_speed(struct bxe_softc *sc)
11678 uint16_t line_speed = sc->link_vars.line_speed;
11681 bxe_extract_max_cfg(sc, sc->devinfo.mf_info.mf_config[SC_VN(sc)]);
11683 /* calculate the current MAX line speed limit for the MF devices */
11684 if (IS_MF_SI(sc)) {
11685 line_speed = (line_speed * maxCfg) / 100;
11686 } else { /* SD mode */
11687 uint16_t vn_max_rate = maxCfg * 100;
11689 if (vn_max_rate < line_speed) {
11690 line_speed = vn_max_rate;
11695 return (line_speed);
11699 bxe_fill_report_data(struct bxe_softc *sc,
11700 struct bxe_link_report_data *data)
11702 uint16_t line_speed = bxe_get_mf_speed(sc);
11704 memset(data, 0, sizeof(*data));
11706 /* fill the report data with the effective line speed */
11707 data->line_speed = line_speed;
11710 if (!sc->link_vars.link_up || (sc->flags & BXE_MF_FUNC_DIS)) {
11711 bxe_set_bit(BXE_LINK_REPORT_LINK_DOWN, &data->link_report_flags);
11715 if (sc->link_vars.duplex == DUPLEX_FULL) {
11716 bxe_set_bit(BXE_LINK_REPORT_FULL_DUPLEX, &data->link_report_flags);
11719 /* Rx Flow Control is ON */
11720 if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_RX) {
11721 bxe_set_bit(BXE_LINK_REPORT_RX_FC_ON, &data->link_report_flags);
11724 /* Tx Flow Control is ON */
11725 if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_TX) {
11726 bxe_set_bit(BXE_LINK_REPORT_TX_FC_ON, &data->link_report_flags);
11730 /* report link status to OS, should be called under phy_lock */
11732 bxe_link_report_locked(struct bxe_softc *sc)
11734 struct bxe_link_report_data cur_data;
11736 /* reread mf_cfg */
11737 if (IS_PF(sc) && !CHIP_IS_E1(sc)) {
11738 bxe_read_mf_cfg(sc);
11741 /* Read the current link report info */
11742 bxe_fill_report_data(sc, &cur_data);
11744 /* Don't report link down or exactly the same link status twice */
11745 if (!memcmp(&cur_data, &sc->last_reported_link, sizeof(cur_data)) ||
11746 (bxe_test_bit(BXE_LINK_REPORT_LINK_DOWN,
11747 &sc->last_reported_link.link_report_flags) &&
11748 bxe_test_bit(BXE_LINK_REPORT_LINK_DOWN,
11749 &cur_data.link_report_flags))) {
11753 ELINK_DEBUG_P2(sc, "Change in link status : cur_data = %x, last_reported_link = %x\n",
11754 cur_data.link_report_flags, sc->last_reported_link.link_report_flags);
11757 ELINK_DEBUG_P1(sc, "link status change count = %x\n", sc->link_cnt);
11758 /* report new link params and remember the state for the next time */
11759 memcpy(&sc->last_reported_link, &cur_data, sizeof(cur_data));
11761 if (bxe_test_bit(BXE_LINK_REPORT_LINK_DOWN,
11762 &cur_data.link_report_flags)) {
11763 if_link_state_change(sc->ifnet, LINK_STATE_DOWN);
11765 const char *duplex;
11768 if (bxe_test_and_clear_bit(BXE_LINK_REPORT_FULL_DUPLEX,
11769 &cur_data.link_report_flags)) {
11771 ELINK_DEBUG_P0(sc, "link set to full duplex\n");
11774 ELINK_DEBUG_P0(sc, "link set to half duplex\n");
11778 * Handle the FC at the end so that only these flags would be
11779 * possibly set. This way we may easily check if there is no FC
11782 if (cur_data.link_report_flags) {
11783 if (bxe_test_bit(BXE_LINK_REPORT_RX_FC_ON,
11784 &cur_data.link_report_flags) &&
11785 bxe_test_bit(BXE_LINK_REPORT_TX_FC_ON,
11786 &cur_data.link_report_flags)) {
11787 flow = "ON - receive & transmit";
11788 } else if (bxe_test_bit(BXE_LINK_REPORT_RX_FC_ON,
11789 &cur_data.link_report_flags) &&
11790 !bxe_test_bit(BXE_LINK_REPORT_TX_FC_ON,
11791 &cur_data.link_report_flags)) {
11792 flow = "ON - receive";
11793 } else if (!bxe_test_bit(BXE_LINK_REPORT_RX_FC_ON,
11794 &cur_data.link_report_flags) &&
11795 bxe_test_bit(BXE_LINK_REPORT_TX_FC_ON,
11796 &cur_data.link_report_flags)) {
11797 flow = "ON - transmit";
11799 flow = "none"; /* possible? */
11805 if_link_state_change(sc->ifnet, LINK_STATE_UP);
11806 BLOGI(sc, "NIC Link is Up, %d Mbps %s duplex, Flow control: %s\n",
11807 cur_data.line_speed, duplex, flow);
11812 bxe_link_report(struct bxe_softc *sc)
11814 bxe_acquire_phy_lock(sc);
11815 bxe_link_report_locked(sc);
11816 bxe_release_phy_lock(sc);
11820 bxe_link_status_update(struct bxe_softc *sc)
11822 if (sc->state != BXE_STATE_OPEN) {
11826 if (IS_PF(sc) && !CHIP_REV_IS_SLOW(sc)) {
11827 elink_link_status_update(&sc->link_params, &sc->link_vars);
11829 sc->port.supported[0] |= (ELINK_SUPPORTED_10baseT_Half |
11830 ELINK_SUPPORTED_10baseT_Full |
11831 ELINK_SUPPORTED_100baseT_Half |
11832 ELINK_SUPPORTED_100baseT_Full |
11833 ELINK_SUPPORTED_1000baseT_Full |
11834 ELINK_SUPPORTED_2500baseX_Full |
11835 ELINK_SUPPORTED_10000baseT_Full |
11836 ELINK_SUPPORTED_TP |
11837 ELINK_SUPPORTED_FIBRE |
11838 ELINK_SUPPORTED_Autoneg |
11839 ELINK_SUPPORTED_Pause |
11840 ELINK_SUPPORTED_Asym_Pause);
11841 sc->port.advertising[0] = sc->port.supported[0];
11843 sc->link_params.sc = sc;
11844 sc->link_params.port = SC_PORT(sc);
11845 sc->link_params.req_duplex[0] = DUPLEX_FULL;
11846 sc->link_params.req_flow_ctrl[0] = ELINK_FLOW_CTRL_NONE;
11847 sc->link_params.req_line_speed[0] = SPEED_10000;
11848 sc->link_params.speed_cap_mask[0] = 0x7f0000;
11849 sc->link_params.switch_cfg = ELINK_SWITCH_CFG_10G;
11851 if (CHIP_REV_IS_FPGA(sc)) {
11852 sc->link_vars.mac_type = ELINK_MAC_TYPE_EMAC;
11853 sc->link_vars.line_speed = ELINK_SPEED_1000;
11854 sc->link_vars.link_status = (LINK_STATUS_LINK_UP |
11855 LINK_STATUS_SPEED_AND_DUPLEX_1000TFD);
11857 sc->link_vars.mac_type = ELINK_MAC_TYPE_BMAC;
11858 sc->link_vars.line_speed = ELINK_SPEED_10000;
11859 sc->link_vars.link_status = (LINK_STATUS_LINK_UP |
11860 LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
11863 sc->link_vars.link_up = 1;
11865 sc->link_vars.duplex = DUPLEX_FULL;
11866 sc->link_vars.flow_ctrl = ELINK_FLOW_CTRL_NONE;
11869 REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + sc->link_params.port*4, 0);
11870 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
11871 bxe_link_report(sc);
11876 if (sc->link_vars.link_up) {
11877 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
11879 bxe_stats_handle(sc, STATS_EVENT_STOP);
11881 bxe_link_report(sc);
11883 bxe_link_report(sc);
11884 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
11889 bxe_initial_phy_init(struct bxe_softc *sc,
11892 int rc, cfg_idx = bxe_get_link_cfg_idx(sc);
11893 uint16_t req_line_speed = sc->link_params.req_line_speed[cfg_idx];
11894 struct elink_params *lp = &sc->link_params;
11896 bxe_set_requested_fc(sc);
11898 if (CHIP_REV_IS_SLOW(sc)) {
11899 uint32_t bond = CHIP_BOND_ID(sc);
11902 if (CHIP_IS_E2(sc) && CHIP_IS_MODE_4_PORT(sc)) {
11903 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_BMAC;
11904 } else if (bond & 0x4) {
11905 if (CHIP_IS_E3(sc)) {
11906 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_XMAC;
11908 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_BMAC;
11910 } else if (bond & 0x8) {
11911 if (CHIP_IS_E3(sc)) {
11912 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_UMAC;
11914 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_EMAC;
11918 /* disable EMAC for E3 and above */
11920 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_EMAC;
11923 sc->link_params.feature_config_flags |= feat;
11926 bxe_acquire_phy_lock(sc);
11928 if (load_mode == LOAD_DIAG) {
11929 lp->loopback_mode = ELINK_LOOPBACK_XGXS;
11930 /* Prefer doing PHY loopback at 10G speed, if possible */
11931 if (lp->req_line_speed[cfg_idx] < ELINK_SPEED_10000) {
11932 if (lp->speed_cap_mask[cfg_idx] &
11933 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) {
11934 lp->req_line_speed[cfg_idx] = ELINK_SPEED_10000;
11936 lp->req_line_speed[cfg_idx] = ELINK_SPEED_1000;
11941 if (load_mode == LOAD_LOOPBACK_EXT) {
11942 lp->loopback_mode = ELINK_LOOPBACK_EXT;
11945 rc = elink_phy_init(&sc->link_params, &sc->link_vars);
11947 bxe_release_phy_lock(sc);
11949 bxe_calc_fc_adv(sc);
11951 if (sc->link_vars.link_up) {
11952 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
11953 bxe_link_report(sc);
11956 if (!CHIP_REV_IS_SLOW(sc)) {
11957 bxe_periodic_start(sc);
11960 sc->link_params.req_line_speed[cfg_idx] = req_line_speed;
11964 /* must be called under IF_ADDR_LOCK */
11966 bxe_init_mcast_macs_list(struct bxe_softc *sc,
11967 struct ecore_mcast_ramrod_params *p)
11969 struct ifnet *ifp = sc->ifnet;
11971 struct ifmultiaddr *ifma;
11972 struct ecore_mcast_list_elem *mc_mac;
11974 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
11975 if (ifma->ifma_addr->sa_family != AF_LINK) {
11982 ECORE_LIST_INIT(&p->mcast_list);
11983 p->mcast_list_len = 0;
11989 mc_mac = malloc(sizeof(*mc_mac) * mc_count, M_DEVBUF,
11990 (M_NOWAIT | M_ZERO));
11992 BLOGE(sc, "Failed to allocate temp mcast list\n");
11995 bzero(mc_mac, (sizeof(*mc_mac) * mc_count));
11997 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
11998 if (ifma->ifma_addr->sa_family != AF_LINK) {
12002 mc_mac->mac = (uint8_t *)LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
12003 ECORE_LIST_PUSH_TAIL(&mc_mac->link, &p->mcast_list);
12005 BLOGD(sc, DBG_LOAD,
12006 "Setting MCAST %02X:%02X:%02X:%02X:%02X:%02X\n",
12007 mc_mac->mac[0], mc_mac->mac[1], mc_mac->mac[2],
12008 mc_mac->mac[3], mc_mac->mac[4], mc_mac->mac[5]);
12013 p->mcast_list_len = mc_count;
12019 bxe_free_mcast_macs_list(struct ecore_mcast_ramrod_params *p)
12021 struct ecore_mcast_list_elem *mc_mac =
12022 ECORE_LIST_FIRST_ENTRY(&p->mcast_list,
12023 struct ecore_mcast_list_elem,
12027 /* only a single free as all mc_macs are in the same heap array */
12028 free(mc_mac, M_DEVBUF);
12033 bxe_set_mc_list(struct bxe_softc *sc)
12035 struct ecore_mcast_ramrod_params rparam = { NULL };
12038 rparam.mcast_obj = &sc->mcast_obj;
12040 BXE_MCAST_LOCK(sc);
12042 /* first, clear all configured multicast MACs */
12043 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL);
12045 BLOGE(sc, "Failed to clear multicast configuration: %d\n", rc);
12046 BXE_MCAST_UNLOCK(sc);
12050 /* configure a new MACs list */
12051 rc = bxe_init_mcast_macs_list(sc, &rparam);
12053 BLOGE(sc, "Failed to create mcast MACs list (%d)\n", rc);
12054 BXE_MCAST_UNLOCK(sc);
12058 /* Now add the new MACs */
12059 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_ADD);
12061 BLOGE(sc, "Failed to set new mcast config (%d)\n", rc);
12064 bxe_free_mcast_macs_list(&rparam);
12066 BXE_MCAST_UNLOCK(sc);
12072 bxe_set_uc_list(struct bxe_softc *sc)
12074 struct ifnet *ifp = sc->ifnet;
12075 struct ecore_vlan_mac_obj *mac_obj = &sc->sp_objs->mac_obj;
12076 struct ifaddr *ifa;
12077 unsigned long ramrod_flags = 0;
12080 #if __FreeBSD_version < 800000
12083 if_addr_rlock(ifp);
12086 /* first schedule a cleanup up of old configuration */
12087 rc = bxe_del_all_macs(sc, mac_obj, ECORE_UC_LIST_MAC, FALSE);
12089 BLOGE(sc, "Failed to schedule delete of all ETH MACs (%d)\n", rc);
12090 #if __FreeBSD_version < 800000
12091 IF_ADDR_UNLOCK(ifp);
12093 if_addr_runlock(ifp);
12098 ifa = ifp->if_addr;
12100 if (ifa->ifa_addr->sa_family != AF_LINK) {
12101 ifa = TAILQ_NEXT(ifa, ifa_link);
12105 rc = bxe_set_mac_one(sc, (uint8_t *)LLADDR((struct sockaddr_dl *)ifa->ifa_addr),
12106 mac_obj, TRUE, ECORE_UC_LIST_MAC, &ramrod_flags);
12107 if (rc == -EEXIST) {
12108 BLOGD(sc, DBG_SP, "Failed to schedule ADD operations (EEXIST)\n");
12109 /* do not treat adding same MAC as an error */
12111 } else if (rc < 0) {
12112 BLOGE(sc, "Failed to schedule ADD operations (%d)\n", rc);
12113 #if __FreeBSD_version < 800000
12114 IF_ADDR_UNLOCK(ifp);
12116 if_addr_runlock(ifp);
12121 ifa = TAILQ_NEXT(ifa, ifa_link);
12124 #if __FreeBSD_version < 800000
12125 IF_ADDR_UNLOCK(ifp);
12127 if_addr_runlock(ifp);
12130 /* Execute the pending commands */
12131 bit_set(&ramrod_flags, RAMROD_CONT);
12132 return (bxe_set_mac_one(sc, NULL, mac_obj, FALSE /* don't care */,
12133 ECORE_UC_LIST_MAC, &ramrod_flags));
12137 bxe_set_rx_mode(struct bxe_softc *sc)
12139 struct ifnet *ifp = sc->ifnet;
12140 uint32_t rx_mode = BXE_RX_MODE_NORMAL;
12142 if (sc->state != BXE_STATE_OPEN) {
12143 BLOGD(sc, DBG_SP, "state is %x, returning\n", sc->state);
12147 BLOGD(sc, DBG_SP, "ifp->if_flags=0x%x\n", ifp->if_flags);
12149 if (ifp->if_flags & IFF_PROMISC) {
12150 rx_mode = BXE_RX_MODE_PROMISC;
12151 } else if ((ifp->if_flags & IFF_ALLMULTI) ||
12152 ((ifp->if_amcount > BXE_MAX_MULTICAST) &&
12154 rx_mode = BXE_RX_MODE_ALLMULTI;
12157 /* some multicasts */
12158 if (bxe_set_mc_list(sc) < 0) {
12159 rx_mode = BXE_RX_MODE_ALLMULTI;
12161 if (bxe_set_uc_list(sc) < 0) {
12162 rx_mode = BXE_RX_MODE_PROMISC;
12167 sc->rx_mode = rx_mode;
12169 /* schedule the rx_mode command */
12170 if (bxe_test_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state)) {
12171 BLOGD(sc, DBG_LOAD, "Scheduled setting rx_mode with ECORE...\n");
12172 bxe_set_bit(ECORE_FILTER_RX_MODE_SCHED, &sc->sp_state);
12177 bxe_set_storm_rx_mode(sc);
12182 /* update flags in shmem */
12184 bxe_update_drv_flags(struct bxe_softc *sc,
12188 uint32_t drv_flags;
12190 if (SHMEM2_HAS(sc, drv_flags)) {
12191 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_DRV_FLAGS);
12192 drv_flags = SHMEM2_RD(sc, drv_flags);
12195 SET_FLAGS(drv_flags, flags);
12197 RESET_FLAGS(drv_flags, flags);
12200 SHMEM2_WR(sc, drv_flags, drv_flags);
12201 BLOGD(sc, DBG_LOAD, "drv_flags 0x%08x\n", drv_flags);
12203 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_DRV_FLAGS);
12207 /* periodic timer callout routine, only runs when the interface is up */
12210 bxe_periodic_callout_func(void *xsc)
12212 struct bxe_softc *sc = (struct bxe_softc *)xsc;
12213 struct bxe_fastpath *fp;
12214 uint16_t tx_bd_avail;
12217 if (!BXE_CORE_TRYLOCK(sc)) {
12218 /* just bail and try again next time */
12220 if ((sc->state == BXE_STATE_OPEN) &&
12221 (atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_GO)) {
12222 /* schedule the next periodic callout */
12223 callout_reset(&sc->periodic_callout, hz,
12224 bxe_periodic_callout_func, sc);
12230 if ((sc->state != BXE_STATE_OPEN) ||
12231 (atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_STOP)) {
12232 BLOGW(sc, "periodic callout exit (state=0x%x)\n", sc->state);
12233 BXE_CORE_UNLOCK(sc);
12237 #if __FreeBSD_version >= 800000
12239 FOR_EACH_QUEUE(sc, i) {
12242 if (BXE_FP_TX_TRYLOCK(fp)) {
12243 struct ifnet *ifp = sc->ifnet;
12245 * If interface was stopped due to unavailable
12246 * bds, try to process some tx completions
12248 (void) bxe_txeof(sc, fp);
12250 tx_bd_avail = bxe_tx_avail(sc, fp);
12251 if (tx_bd_avail >= BXE_TX_CLEANUP_THRESHOLD) {
12252 bxe_tx_mq_start_locked(sc, ifp, fp, NULL);
12254 BXE_FP_TX_UNLOCK(fp);
12261 if (BXE_FP_TX_TRYLOCK(fp)) {
12262 struct ifnet *ifp = sc->ifnet;
12264 * If interface was stopped due to unavailable
12265 * bds, try to process some tx completions
12267 (void) bxe_txeof(sc, fp);
12269 tx_bd_avail = bxe_tx_avail(sc, fp);
12270 if (tx_bd_avail >= BXE_TX_CLEANUP_THRESHOLD) {
12271 bxe_tx_start_locked(sc, ifp, fp);
12274 BXE_FP_TX_UNLOCK(fp);
12277 #endif /* #if __FreeBSD_version >= 800000 */
12279 /* Check for TX timeouts on any fastpath. */
12280 FOR_EACH_QUEUE(sc, i) {
12281 if (bxe_watchdog(sc, &sc->fp[i]) != 0) {
12282 /* Ruh-Roh, chip was reset! */
12287 if (!CHIP_REV_IS_SLOW(sc)) {
12289 * This barrier is needed to ensure the ordering between the writing
12290 * to the sc->port.pmf in the bxe_nic_load() or bxe_pmf_update() and
12291 * the reading here.
12294 if (sc->port.pmf) {
12295 bxe_acquire_phy_lock(sc);
12296 elink_period_func(&sc->link_params, &sc->link_vars);
12297 bxe_release_phy_lock(sc);
12301 if (IS_PF(sc) && !(sc->flags & BXE_NO_PULSE)) {
12302 int mb_idx = SC_FW_MB_IDX(sc);
12303 uint32_t drv_pulse;
12304 uint32_t mcp_pulse;
12306 ++sc->fw_drv_pulse_wr_seq;
12307 sc->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
12309 drv_pulse = sc->fw_drv_pulse_wr_seq;
12312 mcp_pulse = (SHMEM_RD(sc, func_mb[mb_idx].mcp_pulse_mb) &
12313 MCP_PULSE_SEQ_MASK);
12316 * The delta between driver pulse and mcp response should
12317 * be 1 (before mcp response) or 0 (after mcp response).
12319 if ((drv_pulse != mcp_pulse) &&
12320 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
12321 /* someone lost a heartbeat... */
12322 BLOGE(sc, "drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
12323 drv_pulse, mcp_pulse);
12327 /* state is BXE_STATE_OPEN */
12328 bxe_stats_handle(sc, STATS_EVENT_UPDATE);
12330 BXE_CORE_UNLOCK(sc);
12332 if ((sc->state == BXE_STATE_OPEN) &&
12333 (atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_GO)) {
12334 /* schedule the next periodic callout */
12335 callout_reset(&sc->periodic_callout, hz,
12336 bxe_periodic_callout_func, sc);
12341 bxe_periodic_start(struct bxe_softc *sc)
12343 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_GO);
12344 callout_reset(&sc->periodic_callout, hz, bxe_periodic_callout_func, sc);
12348 bxe_periodic_stop(struct bxe_softc *sc)
12350 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_STOP);
12351 callout_drain(&sc->periodic_callout);
12354 /* start the controller */
12355 static __noinline int
12356 bxe_nic_load(struct bxe_softc *sc,
12363 BXE_CORE_LOCK_ASSERT(sc);
12365 BLOGD(sc, DBG_LOAD, "Starting NIC load...\n");
12367 sc->state = BXE_STATE_OPENING_WAITING_LOAD;
12370 /* must be called before memory allocation and HW init */
12371 bxe_ilt_set_info(sc);
12374 sc->last_reported_link_state = LINK_STATE_UNKNOWN;
12376 bxe_set_fp_rx_buf_size(sc);
12378 if (bxe_alloc_fp_buffers(sc) != 0) {
12379 BLOGE(sc, "Failed to allocate fastpath memory\n");
12380 sc->state = BXE_STATE_CLOSED;
12382 goto bxe_nic_load_error0;
12385 if (bxe_alloc_mem(sc) != 0) {
12386 sc->state = BXE_STATE_CLOSED;
12388 goto bxe_nic_load_error0;
12391 if (bxe_alloc_fw_stats_mem(sc) != 0) {
12392 sc->state = BXE_STATE_CLOSED;
12394 goto bxe_nic_load_error0;
12398 /* set pf load just before approaching the MCP */
12399 bxe_set_pf_load(sc);
12401 /* if MCP exists send load request and analyze response */
12402 if (!BXE_NOMCP(sc)) {
12403 /* attempt to load pf */
12404 if (bxe_nic_load_request(sc, &load_code) != 0) {
12405 sc->state = BXE_STATE_CLOSED;
12407 goto bxe_nic_load_error1;
12410 /* what did the MCP say? */
12411 if (bxe_nic_load_analyze_req(sc, load_code) != 0) {
12412 bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
12413 sc->state = BXE_STATE_CLOSED;
12415 goto bxe_nic_load_error2;
12418 BLOGI(sc, "Device has no MCP!\n");
12419 load_code = bxe_nic_load_no_mcp(sc);
12422 /* mark PMF if applicable */
12423 bxe_nic_load_pmf(sc, load_code);
12425 /* Init Function state controlling object */
12426 bxe_init_func_obj(sc);
12428 /* Initialize HW */
12429 if (bxe_init_hw(sc, load_code) != 0) {
12430 BLOGE(sc, "HW init failed\n");
12431 bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
12432 sc->state = BXE_STATE_CLOSED;
12434 goto bxe_nic_load_error2;
12438 /* set ALWAYS_ALIVE bit in shmem */
12439 sc->fw_drv_pulse_wr_seq |= DRV_PULSE_ALWAYS_ALIVE;
12441 sc->flags |= BXE_NO_PULSE;
12443 /* attach interrupts */
12444 if (bxe_interrupt_attach(sc) != 0) {
12445 sc->state = BXE_STATE_CLOSED;
12447 goto bxe_nic_load_error2;
12450 bxe_nic_init(sc, load_code);
12452 /* Init per-function objects */
12455 // XXX bxe_iov_nic_init(sc);
12457 /* set AFEX default VLAN tag to an invalid value */
12458 sc->devinfo.mf_info.afex_def_vlan_tag = -1;
12459 // XXX bxe_nic_load_afex_dcc(sc, load_code);
12461 sc->state = BXE_STATE_OPENING_WAITING_PORT;
12462 rc = bxe_func_start(sc);
12464 BLOGE(sc, "Function start failed! rc = %d\n", rc);
12465 bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
12466 sc->state = BXE_STATE_ERROR;
12467 goto bxe_nic_load_error3;
12470 /* send LOAD_DONE command to MCP */
12471 if (!BXE_NOMCP(sc)) {
12472 load_code = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
12474 BLOGE(sc, "MCP response failure, aborting\n");
12475 sc->state = BXE_STATE_ERROR;
12477 goto bxe_nic_load_error3;
12481 rc = bxe_setup_leading(sc);
12483 BLOGE(sc, "Setup leading failed! rc = %d\n", rc);
12484 sc->state = BXE_STATE_ERROR;
12485 goto bxe_nic_load_error3;
12488 FOR_EACH_NONDEFAULT_ETH_QUEUE(sc, i) {
12489 rc = bxe_setup_queue(sc, &sc->fp[i], FALSE);
12491 BLOGE(sc, "Queue(%d) setup failed rc = %d\n", i, rc);
12492 sc->state = BXE_STATE_ERROR;
12493 goto bxe_nic_load_error3;
12497 rc = bxe_init_rss_pf(sc);
12499 BLOGE(sc, "PF RSS init failed\n");
12500 sc->state = BXE_STATE_ERROR;
12501 goto bxe_nic_load_error3;
12506 /* now when Clients are configured we are ready to work */
12507 sc->state = BXE_STATE_OPEN;
12509 /* Configure a ucast MAC */
12511 rc = bxe_set_eth_mac(sc, TRUE);
12514 BLOGE(sc, "Setting Ethernet MAC failed rc = %d\n", rc);
12515 sc->state = BXE_STATE_ERROR;
12516 goto bxe_nic_load_error3;
12519 if (sc->port.pmf) {
12520 rc = bxe_initial_phy_init(sc, /* XXX load_mode */LOAD_OPEN);
12522 sc->state = BXE_STATE_ERROR;
12523 goto bxe_nic_load_error3;
12527 sc->link_params.feature_config_flags &=
12528 ~ELINK_FEATURE_CONFIG_BOOT_FROM_SAN;
12530 /* start fast path */
12532 /* Initialize Rx filter */
12533 bxe_set_rx_mode(sc);
12536 switch (/* XXX load_mode */LOAD_OPEN) {
12542 case LOAD_LOOPBACK_EXT:
12543 sc->state = BXE_STATE_DIAG;
12550 if (sc->port.pmf) {
12551 bxe_update_drv_flags(sc, 1 << DRV_FLAGS_PORT_MASK, 0);
12553 bxe_link_status_update(sc);
12556 /* start the periodic timer callout */
12557 bxe_periodic_start(sc);
12559 if (IS_PF(sc) && SHMEM2_HAS(sc, drv_capabilities_flag)) {
12560 /* mark driver is loaded in shmem2 */
12561 val = SHMEM2_RD(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)]);
12562 SHMEM2_WR(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)],
12564 DRV_FLAGS_CAPABILITIES_LOADED_SUPPORTED |
12565 DRV_FLAGS_CAPABILITIES_LOADED_L2));
12568 /* wait for all pending SP commands to complete */
12569 if (IS_PF(sc) && !bxe_wait_sp_comp(sc, ~0x0UL)) {
12570 BLOGE(sc, "Timeout waiting for all SPs to complete!\n");
12571 bxe_periodic_stop(sc);
12572 bxe_nic_unload(sc, UNLOAD_CLOSE, FALSE);
12576 /* Tell the stack the driver is running! */
12577 sc->ifnet->if_drv_flags = IFF_DRV_RUNNING;
12579 BLOGD(sc, DBG_LOAD, "NIC successfully loaded\n");
12583 bxe_nic_load_error3:
12586 bxe_int_disable_sync(sc, 1);
12588 /* clean out queued objects */
12589 bxe_squeeze_objects(sc);
12592 bxe_interrupt_detach(sc);
12594 bxe_nic_load_error2:
12596 if (IS_PF(sc) && !BXE_NOMCP(sc)) {
12597 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
12598 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, 0);
12603 bxe_nic_load_error1:
12605 /* clear pf_load status, as it was already set */
12607 bxe_clear_pf_load(sc);
12610 bxe_nic_load_error0:
12612 bxe_free_fw_stats_mem(sc);
12613 bxe_free_fp_buffers(sc);
12620 bxe_init_locked(struct bxe_softc *sc)
12622 int other_engine = SC_PATH(sc) ? 0 : 1;
12623 uint8_t other_load_status, load_status;
12624 uint8_t global = FALSE;
12627 BXE_CORE_LOCK_ASSERT(sc);
12629 /* check if the driver is already running */
12630 if (sc->ifnet->if_drv_flags & IFF_DRV_RUNNING) {
12631 BLOGD(sc, DBG_LOAD, "Init called while driver is running!\n");
12635 bxe_set_power_state(sc, PCI_PM_D0);
12638 * If parity occurred during the unload, then attentions and/or
12639 * RECOVERY_IN_PROGRES may still be set. If so we want the first function
12640 * loaded on the current engine to complete the recovery. Parity recovery
12641 * is only relevant for PF driver.
12644 other_load_status = bxe_get_load_status(sc, other_engine);
12645 load_status = bxe_get_load_status(sc, SC_PATH(sc));
12647 if (!bxe_reset_is_done(sc, SC_PATH(sc)) ||
12648 bxe_chk_parity_attn(sc, &global, TRUE)) {
12651 * If there are attentions and they are in global blocks, set
12652 * the GLOBAL_RESET bit regardless whether it will be this
12653 * function that will complete the recovery or not.
12656 bxe_set_reset_global(sc);
12660 * Only the first function on the current engine should try
12661 * to recover in open. In case of attentions in global blocks
12662 * only the first in the chip should try to recover.
12664 if ((!load_status && (!global || !other_load_status)) &&
12665 bxe_trylock_leader_lock(sc) && !bxe_leader_reset(sc)) {
12666 BLOGI(sc, "Recovered during init\n");
12670 /* recovery has failed... */
12671 bxe_set_power_state(sc, PCI_PM_D3hot);
12672 sc->recovery_state = BXE_RECOVERY_FAILED;
12674 BLOGE(sc, "Recovery flow hasn't properly "
12675 "completed yet, try again later. "
12676 "If you still see this message after a "
12677 "few retries then power cycle is required.\n");
12680 goto bxe_init_locked_done;
12685 sc->recovery_state = BXE_RECOVERY_DONE;
12687 rc = bxe_nic_load(sc, LOAD_OPEN);
12689 bxe_init_locked_done:
12692 /* Tell the stack the driver is NOT running! */
12693 BLOGE(sc, "Initialization failed, "
12694 "stack notified driver is NOT running!\n");
12695 sc->ifnet->if_drv_flags &= ~IFF_DRV_RUNNING;
12702 bxe_stop_locked(struct bxe_softc *sc)
12704 BXE_CORE_LOCK_ASSERT(sc);
12705 return (bxe_nic_unload(sc, UNLOAD_NORMAL, TRUE));
12709 * Handles controller initialization when called from an unlocked routine.
12710 * ifconfig calls this function.
12716 bxe_init(void *xsc)
12718 struct bxe_softc *sc = (struct bxe_softc *)xsc;
12721 bxe_init_locked(sc);
12722 BXE_CORE_UNLOCK(sc);
12726 bxe_init_ifnet(struct bxe_softc *sc)
12730 /* ifconfig entrypoint for media type/status reporting */
12731 ifmedia_init(&sc->ifmedia, IFM_IMASK,
12732 bxe_ifmedia_update,
12733 bxe_ifmedia_status);
12735 /* set the default interface values */
12736 ifmedia_add(&sc->ifmedia, (IFM_ETHER | IFM_FDX | sc->media), 0, NULL);
12737 ifmedia_add(&sc->ifmedia, (IFM_ETHER | IFM_AUTO), 0, NULL);
12738 ifmedia_set(&sc->ifmedia, (IFM_ETHER | IFM_AUTO));
12740 sc->ifmedia.ifm_media = sc->ifmedia.ifm_cur->ifm_media; /* XXX ? */
12741 BLOGI(sc, "IFMEDIA flags : %x\n", sc->ifmedia.ifm_media);
12743 /* allocate the ifnet structure */
12744 if ((ifp = if_alloc(IFT_ETHER)) == NULL) {
12745 BLOGE(sc, "Interface allocation failed!\n");
12749 ifp->if_softc = sc;
12750 if_initname(ifp, device_get_name(sc->dev), device_get_unit(sc->dev));
12751 ifp->if_flags = (IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
12752 ifp->if_ioctl = bxe_ioctl;
12753 ifp->if_start = bxe_tx_start;
12754 #if __FreeBSD_version >= 800000
12755 ifp->if_transmit = bxe_tx_mq_start;
12756 ifp->if_qflush = bxe_mq_flush;
12761 ifp->if_init = bxe_init;
12762 ifp->if_mtu = sc->mtu;
12763 ifp->if_hwassist = (CSUM_IP |
12769 ifp->if_capabilities =
12770 #if __FreeBSD_version < 700000
12772 IFCAP_VLAN_HWTAGGING |
12778 IFCAP_VLAN_HWTAGGING |
12780 IFCAP_VLAN_HWFILTER |
12781 IFCAP_VLAN_HWCSUM |
12789 ifp->if_capenable = ifp->if_capabilities;
12790 ifp->if_capenable &= ~IFCAP_WOL_MAGIC; /* XXX not yet... */
12791 #if __FreeBSD_version < 1000025
12792 ifp->if_baudrate = 1000000000;
12794 if_initbaudrate(ifp, IF_Gbps(10));
12796 ifp->if_snd.ifq_drv_maxlen = sc->tx_ring_size;
12798 IFQ_SET_MAXLEN(&ifp->if_snd, ifp->if_snd.ifq_drv_maxlen);
12799 IFQ_SET_READY(&ifp->if_snd);
12803 /* attach to the Ethernet interface list */
12804 ether_ifattach(ifp, sc->link_params.mac_addr);
12810 bxe_deallocate_bars(struct bxe_softc *sc)
12814 for (i = 0; i < MAX_BARS; i++) {
12815 if (sc->bar[i].resource != NULL) {
12816 bus_release_resource(sc->dev,
12819 sc->bar[i].resource);
12820 BLOGD(sc, DBG_LOAD, "Released PCI BAR%d [%02x] memory\n",
12827 bxe_allocate_bars(struct bxe_softc *sc)
12832 memset(sc->bar, 0, sizeof(sc->bar));
12834 for (i = 0; i < MAX_BARS; i++) {
12836 /* memory resources reside at BARs 0, 2, 4 */
12837 /* Run `pciconf -lb` to see mappings */
12838 if ((i != 0) && (i != 2) && (i != 4)) {
12842 sc->bar[i].rid = PCIR_BAR(i);
12846 flags |= RF_SHAREABLE;
12849 if ((sc->bar[i].resource =
12850 bus_alloc_resource_any(sc->dev,
12857 sc->bar[i].tag = rman_get_bustag(sc->bar[i].resource);
12858 sc->bar[i].handle = rman_get_bushandle(sc->bar[i].resource);
12859 sc->bar[i].kva = (vm_offset_t)rman_get_virtual(sc->bar[i].resource);
12861 BLOGI(sc, "PCI BAR%d [%02x] memory allocated: %p-%p (%ld) -> %p\n",
12863 (void *)rman_get_start(sc->bar[i].resource),
12864 (void *)rman_get_end(sc->bar[i].resource),
12865 rman_get_size(sc->bar[i].resource),
12866 (void *)sc->bar[i].kva);
12873 bxe_get_function_num(struct bxe_softc *sc)
12878 * Read the ME register to get the function number. The ME register
12879 * holds the relative-function number and absolute-function number. The
12880 * absolute-function number appears only in E2 and above. Before that
12881 * these bits always contained zero, therefore we cannot blindly use them.
12884 val = REG_RD(sc, BAR_ME_REGISTER);
12887 (uint8_t)((val & ME_REG_PF_NUM) >> ME_REG_PF_NUM_SHIFT);
12889 (uint8_t)((val & ME_REG_ABS_PF_NUM) >> ME_REG_ABS_PF_NUM_SHIFT) & 1;
12891 if (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) {
12892 sc->pfunc_abs = ((sc->pfunc_rel << 1) | sc->path_id);
12894 sc->pfunc_abs = (sc->pfunc_rel | sc->path_id);
12897 BLOGD(sc, DBG_LOAD,
12898 "Relative function %d, Absolute function %d, Path %d\n",
12899 sc->pfunc_rel, sc->pfunc_abs, sc->path_id);
12903 bxe_get_shmem_mf_cfg_base(struct bxe_softc *sc)
12905 uint32_t shmem2_size;
12907 uint32_t mf_cfg_offset_value;
12910 offset = (SHMEM_RD(sc, func_mb) +
12911 (MAX_FUNC_NUM * sizeof(struct drv_func_mb)));
12914 if (sc->devinfo.shmem2_base != 0) {
12915 shmem2_size = SHMEM2_RD(sc, size);
12916 if (shmem2_size > offsetof(struct shmem2_region, mf_cfg_addr)) {
12917 mf_cfg_offset_value = SHMEM2_RD(sc, mf_cfg_addr);
12918 if (SHMEM_MF_CFG_ADDR_NONE != mf_cfg_offset_value) {
12919 offset = mf_cfg_offset_value;
12928 bxe_pcie_capability_read(struct bxe_softc *sc,
12934 /* ensure PCIe capability is enabled */
12935 if (pci_find_cap(sc->dev, PCIY_EXPRESS, &pcie_reg) == 0) {
12936 if (pcie_reg != 0) {
12937 BLOGD(sc, DBG_LOAD, "PCIe capability at 0x%04x\n", pcie_reg);
12938 return (pci_read_config(sc->dev, (pcie_reg + reg), width));
12942 BLOGE(sc, "PCIe capability NOT FOUND!!!\n");
12948 bxe_is_pcie_pending(struct bxe_softc *sc)
12950 return (bxe_pcie_capability_read(sc, PCIR_EXPRESS_DEVICE_STA, 2) &
12951 PCIM_EXP_STA_TRANSACTION_PND);
12955 * Walk the PCI capabiites list for the device to find what features are
12956 * supported. These capabilites may be enabled/disabled by firmware so it's
12957 * best to walk the list rather than make assumptions.
12960 bxe_probe_pci_caps(struct bxe_softc *sc)
12962 uint16_t link_status;
12965 /* check if PCI Power Management is enabled */
12966 if (pci_find_cap(sc->dev, PCIY_PMG, ®) == 0) {
12968 BLOGD(sc, DBG_LOAD, "Found PM capability at 0x%04x\n", reg);
12970 sc->devinfo.pcie_cap_flags |= BXE_PM_CAPABLE_FLAG;
12971 sc->devinfo.pcie_pm_cap_reg = (uint16_t)reg;
12975 link_status = bxe_pcie_capability_read(sc, PCIR_EXPRESS_LINK_STA, 2);
12977 /* handle PCIe 2.0 workarounds for 57710 */
12978 if (CHIP_IS_E1(sc)) {
12979 /* workaround for 57710 errata E4_57710_27462 */
12980 sc->devinfo.pcie_link_speed =
12981 (REG_RD(sc, 0x3d04) & (1 << 24)) ? 2 : 1;
12983 /* workaround for 57710 errata E4_57710_27488 */
12984 sc->devinfo.pcie_link_width =
12985 ((link_status & PCIM_LINK_STA_WIDTH) >> 4);
12986 if (sc->devinfo.pcie_link_speed > 1) {
12987 sc->devinfo.pcie_link_width =
12988 ((link_status & PCIM_LINK_STA_WIDTH) >> 4) >> 1;
12991 sc->devinfo.pcie_link_speed =
12992 (link_status & PCIM_LINK_STA_SPEED);
12993 sc->devinfo.pcie_link_width =
12994 ((link_status & PCIM_LINK_STA_WIDTH) >> 4);
12997 BLOGD(sc, DBG_LOAD, "PCIe link speed=%d width=%d\n",
12998 sc->devinfo.pcie_link_speed, sc->devinfo.pcie_link_width);
13000 sc->devinfo.pcie_cap_flags |= BXE_PCIE_CAPABLE_FLAG;
13001 sc->devinfo.pcie_pcie_cap_reg = (uint16_t)reg;
13003 /* check if MSI capability is enabled */
13004 if (pci_find_cap(sc->dev, PCIY_MSI, ®) == 0) {
13006 BLOGD(sc, DBG_LOAD, "Found MSI capability at 0x%04x\n", reg);
13008 sc->devinfo.pcie_cap_flags |= BXE_MSI_CAPABLE_FLAG;
13009 sc->devinfo.pcie_msi_cap_reg = (uint16_t)reg;
13013 /* check if MSI-X capability is enabled */
13014 if (pci_find_cap(sc->dev, PCIY_MSIX, ®) == 0) {
13016 BLOGD(sc, DBG_LOAD, "Found MSI-X capability at 0x%04x\n", reg);
13018 sc->devinfo.pcie_cap_flags |= BXE_MSIX_CAPABLE_FLAG;
13019 sc->devinfo.pcie_msix_cap_reg = (uint16_t)reg;
13025 bxe_get_shmem_mf_cfg_info_sd(struct bxe_softc *sc)
13027 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13030 /* get the outer vlan if we're in switch-dependent mode */
13032 val = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag);
13033 mf_info->ext_id = (uint16_t)val;
13035 mf_info->multi_vnics_mode = 1;
13037 if (!VALID_OVLAN(mf_info->ext_id)) {
13038 BLOGE(sc, "Invalid VLAN (%d)\n", mf_info->ext_id);
13042 /* get the capabilities */
13043 if ((mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_PROTOCOL_MASK) ==
13044 FUNC_MF_CFG_PROTOCOL_ISCSI) {
13045 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_ISCSI;
13046 } else if ((mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_PROTOCOL_MASK) ==
13047 FUNC_MF_CFG_PROTOCOL_FCOE) {
13048 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_FCOE;
13050 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_ETHERNET;
13053 mf_info->vnics_per_port =
13054 (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4;
13060 bxe_get_shmem_ext_proto_support_flags(struct bxe_softc *sc)
13062 uint32_t retval = 0;
13065 val = MFCFG_RD(sc, func_ext_config[SC_ABS_FUNC(sc)].func_cfg);
13067 if (val & MACP_FUNC_CFG_FLAGS_ENABLED) {
13068 if (val & MACP_FUNC_CFG_FLAGS_ETHERNET) {
13069 retval |= MF_PROTO_SUPPORT_ETHERNET;
13071 if (val & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
13072 retval |= MF_PROTO_SUPPORT_ISCSI;
13074 if (val & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
13075 retval |= MF_PROTO_SUPPORT_FCOE;
13083 bxe_get_shmem_mf_cfg_info_si(struct bxe_softc *sc)
13085 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13089 * There is no outer vlan if we're in switch-independent mode.
13090 * If the mac is valid then assume multi-function.
13093 val = MFCFG_RD(sc, func_ext_config[SC_ABS_FUNC(sc)].func_cfg);
13095 mf_info->multi_vnics_mode = ((val & MACP_FUNC_CFG_FLAGS_MASK) != 0);
13097 mf_info->mf_protos_supported = bxe_get_shmem_ext_proto_support_flags(sc);
13099 mf_info->vnics_per_port =
13100 (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4;
13106 bxe_get_shmem_mf_cfg_info_niv(struct bxe_softc *sc)
13108 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13109 uint32_t e1hov_tag;
13110 uint32_t func_config;
13111 uint32_t niv_config;
13113 mf_info->multi_vnics_mode = 1;
13115 e1hov_tag = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag);
13116 func_config = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config);
13117 niv_config = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].afex_config);
13120 (uint16_t)((e1hov_tag & FUNC_MF_CFG_E1HOV_TAG_MASK) >>
13121 FUNC_MF_CFG_E1HOV_TAG_SHIFT);
13123 mf_info->default_vlan =
13124 (uint16_t)((e1hov_tag & FUNC_MF_CFG_AFEX_VLAN_MASK) >>
13125 FUNC_MF_CFG_AFEX_VLAN_SHIFT);
13127 mf_info->niv_allowed_priorities =
13128 (uint8_t)((niv_config & FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
13129 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT);
13131 mf_info->niv_default_cos =
13132 (uint8_t)((func_config & FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
13133 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT);
13135 mf_info->afex_vlan_mode =
13136 ((niv_config & FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
13137 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT);
13139 mf_info->niv_mba_enabled =
13140 ((niv_config & FUNC_MF_CFG_AFEX_MBA_ENABLED_MASK) >>
13141 FUNC_MF_CFG_AFEX_MBA_ENABLED_SHIFT);
13143 mf_info->mf_protos_supported = bxe_get_shmem_ext_proto_support_flags(sc);
13145 mf_info->vnics_per_port =
13146 (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4;
13152 bxe_check_valid_mf_cfg(struct bxe_softc *sc)
13154 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13161 BLOGD(sc, DBG_LOAD, "MF config parameters for function %d\n",
13163 BLOGD(sc, DBG_LOAD, "\tmf_config=0x%x\n",
13164 mf_info->mf_config[SC_VN(sc)]);
13165 BLOGD(sc, DBG_LOAD, "\tmulti_vnics_mode=%d\n",
13166 mf_info->multi_vnics_mode);
13167 BLOGD(sc, DBG_LOAD, "\tvnics_per_port=%d\n",
13168 mf_info->vnics_per_port);
13169 BLOGD(sc, DBG_LOAD, "\tovlan/vifid=%d\n",
13171 BLOGD(sc, DBG_LOAD, "\tmin_bw=%d/%d/%d/%d\n",
13172 mf_info->min_bw[0], mf_info->min_bw[1],
13173 mf_info->min_bw[2], mf_info->min_bw[3]);
13174 BLOGD(sc, DBG_LOAD, "\tmax_bw=%d/%d/%d/%d\n",
13175 mf_info->max_bw[0], mf_info->max_bw[1],
13176 mf_info->max_bw[2], mf_info->max_bw[3]);
13177 BLOGD(sc, DBG_LOAD, "\tmac_addr: %s\n",
13180 /* various MF mode sanity checks... */
13182 if (mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_FUNC_HIDE) {
13183 BLOGE(sc, "Enumerated function %d is marked as hidden\n",
13188 if ((mf_info->vnics_per_port > 1) && !mf_info->multi_vnics_mode) {
13189 BLOGE(sc, "vnics_per_port=%d multi_vnics_mode=%d\n",
13190 mf_info->vnics_per_port, mf_info->multi_vnics_mode);
13194 if (mf_info->mf_mode == MULTI_FUNCTION_SD) {
13195 /* vnic id > 0 must have valid ovlan in switch-dependent mode */
13196 if ((SC_VN(sc) > 0) && !VALID_OVLAN(OVLAN(sc))) {
13197 BLOGE(sc, "mf_mode=SD vnic_id=%d ovlan=%d\n",
13198 SC_VN(sc), OVLAN(sc));
13202 if (!VALID_OVLAN(OVLAN(sc)) && mf_info->multi_vnics_mode) {
13203 BLOGE(sc, "mf_mode=SD multi_vnics_mode=%d ovlan=%d\n",
13204 mf_info->multi_vnics_mode, OVLAN(sc));
13209 * Verify all functions are either MF or SF mode. If MF, make sure
13210 * sure that all non-hidden functions have a valid ovlan. If SF,
13211 * make sure that all non-hidden functions have an invalid ovlan.
13213 FOREACH_ABS_FUNC_IN_PORT(sc, i) {
13214 mf_cfg1 = MFCFG_RD(sc, func_mf_config[i].config);
13215 ovlan1 = MFCFG_RD(sc, func_mf_config[i].e1hov_tag);
13216 if (!(mf_cfg1 & FUNC_MF_CFG_FUNC_HIDE) &&
13217 (((mf_info->multi_vnics_mode) && !VALID_OVLAN(ovlan1)) ||
13218 ((!mf_info->multi_vnics_mode) && VALID_OVLAN(ovlan1)))) {
13219 BLOGE(sc, "mf_mode=SD function %d MF config "
13220 "mismatch, multi_vnics_mode=%d ovlan=%d\n",
13221 i, mf_info->multi_vnics_mode, ovlan1);
13226 /* Verify all funcs on the same port each have a different ovlan. */
13227 FOREACH_ABS_FUNC_IN_PORT(sc, i) {
13228 mf_cfg1 = MFCFG_RD(sc, func_mf_config[i].config);
13229 ovlan1 = MFCFG_RD(sc, func_mf_config[i].e1hov_tag);
13230 /* iterate from the next function on the port to the max func */
13231 for (j = i + 2; j < MAX_FUNC_NUM; j += 2) {
13232 mf_cfg2 = MFCFG_RD(sc, func_mf_config[j].config);
13233 ovlan2 = MFCFG_RD(sc, func_mf_config[j].e1hov_tag);
13234 if (!(mf_cfg1 & FUNC_MF_CFG_FUNC_HIDE) &&
13235 VALID_OVLAN(ovlan1) &&
13236 !(mf_cfg2 & FUNC_MF_CFG_FUNC_HIDE) &&
13237 VALID_OVLAN(ovlan2) &&
13238 (ovlan1 == ovlan2)) {
13239 BLOGE(sc, "mf_mode=SD functions %d and %d "
13240 "have the same ovlan (%d)\n",
13246 } /* MULTI_FUNCTION_SD */
13252 bxe_get_mf_cfg_info(struct bxe_softc *sc)
13254 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13255 uint32_t val, mac_upper;
13258 /* initialize mf_info defaults */
13259 mf_info->vnics_per_port = 1;
13260 mf_info->multi_vnics_mode = FALSE;
13261 mf_info->path_has_ovlan = FALSE;
13262 mf_info->mf_mode = SINGLE_FUNCTION;
13264 if (!CHIP_IS_MF_CAP(sc)) {
13268 if (sc->devinfo.mf_cfg_base == SHMEM_MF_CFG_ADDR_NONE) {
13269 BLOGE(sc, "Invalid mf_cfg_base!\n");
13273 /* get the MF mode (switch dependent / independent / single-function) */
13275 val = SHMEM_RD(sc, dev_info.shared_feature_config.config);
13277 switch (val & SHARED_FEAT_CFG_FORCE_SF_MODE_MASK)
13279 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
13281 mac_upper = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper);
13283 /* check for legal upper mac bytes */
13284 if (mac_upper != FUNC_MF_CFG_UPPERMAC_DEFAULT) {
13285 mf_info->mf_mode = MULTI_FUNCTION_SI;
13287 BLOGE(sc, "Invalid config for Switch Independent mode\n");
13292 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
13293 case SHARED_FEAT_CFG_FORCE_SF_MODE_SPIO4:
13295 /* get outer vlan configuration */
13296 val = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag);
13298 if ((val & FUNC_MF_CFG_E1HOV_TAG_MASK) !=
13299 FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
13300 mf_info->mf_mode = MULTI_FUNCTION_SD;
13302 BLOGE(sc, "Invalid config for Switch Dependent mode\n");
13307 case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
13309 /* not in MF mode, vnics_per_port=1 and multi_vnics_mode=FALSE */
13312 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
13315 * Mark MF mode as NIV if MCP version includes NPAR-SD support
13316 * and the MAC address is valid.
13318 mac_upper = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper);
13320 if ((SHMEM2_HAS(sc, afex_driver_support)) &&
13321 (mac_upper != FUNC_MF_CFG_UPPERMAC_DEFAULT)) {
13322 mf_info->mf_mode = MULTI_FUNCTION_AFEX;
13324 BLOGE(sc, "Invalid config for AFEX mode\n");
13331 BLOGE(sc, "Unknown MF mode (0x%08x)\n",
13332 (val & SHARED_FEAT_CFG_FORCE_SF_MODE_MASK));
13337 /* set path mf_mode (which could be different than function mf_mode) */
13338 if (mf_info->mf_mode == MULTI_FUNCTION_SD) {
13339 mf_info->path_has_ovlan = TRUE;
13340 } else if (mf_info->mf_mode == SINGLE_FUNCTION) {
13342 * Decide on path multi vnics mode. If we're not in MF mode and in
13343 * 4-port mode, this is good enough to check vnic-0 of the other port
13346 if (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) {
13347 uint8_t other_port = !(PORT_ID(sc) & 1);
13348 uint8_t abs_func_other_port = (SC_PATH(sc) + (2 * other_port));
13350 val = MFCFG_RD(sc, func_mf_config[abs_func_other_port].e1hov_tag);
13352 mf_info->path_has_ovlan = VALID_OVLAN((uint16_t)val) ? 1 : 0;
13356 if (mf_info->mf_mode == SINGLE_FUNCTION) {
13357 /* invalid MF config */
13358 if (SC_VN(sc) >= 1) {
13359 BLOGE(sc, "VNIC ID >= 1 in SF mode\n");
13366 /* get the MF configuration */
13367 mf_info->mf_config[SC_VN(sc)] =
13368 MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config);
13370 switch(mf_info->mf_mode)
13372 case MULTI_FUNCTION_SD:
13374 bxe_get_shmem_mf_cfg_info_sd(sc);
13377 case MULTI_FUNCTION_SI:
13379 bxe_get_shmem_mf_cfg_info_si(sc);
13382 case MULTI_FUNCTION_AFEX:
13384 bxe_get_shmem_mf_cfg_info_niv(sc);
13389 BLOGE(sc, "Get MF config failed (mf_mode=0x%08x)\n",
13394 /* get the congestion management parameters */
13397 FOREACH_ABS_FUNC_IN_PORT(sc, i) {
13398 /* get min/max bw */
13399 val = MFCFG_RD(sc, func_mf_config[i].config);
13400 mf_info->min_bw[vnic] =
13401 ((val & FUNC_MF_CFG_MIN_BW_MASK) >> FUNC_MF_CFG_MIN_BW_SHIFT);
13402 mf_info->max_bw[vnic] =
13403 ((val & FUNC_MF_CFG_MAX_BW_MASK) >> FUNC_MF_CFG_MAX_BW_SHIFT);
13407 return (bxe_check_valid_mf_cfg(sc));
13411 bxe_get_shmem_info(struct bxe_softc *sc)
13414 uint32_t mac_hi, mac_lo, val;
13416 port = SC_PORT(sc);
13417 mac_hi = mac_lo = 0;
13419 sc->link_params.sc = sc;
13420 sc->link_params.port = port;
13422 /* get the hardware config info */
13423 sc->devinfo.hw_config =
13424 SHMEM_RD(sc, dev_info.shared_hw_config.config);
13425 sc->devinfo.hw_config2 =
13426 SHMEM_RD(sc, dev_info.shared_hw_config.config2);
13428 sc->link_params.hw_led_mode =
13429 ((sc->devinfo.hw_config & SHARED_HW_CFG_LED_MODE_MASK) >>
13430 SHARED_HW_CFG_LED_MODE_SHIFT);
13432 /* get the port feature config */
13434 SHMEM_RD(sc, dev_info.port_feature_config[port].config),
13436 /* get the link params */
13437 sc->link_params.speed_cap_mask[0] =
13438 SHMEM_RD(sc, dev_info.port_hw_config[port].speed_capability_mask);
13439 sc->link_params.speed_cap_mask[1] =
13440 SHMEM_RD(sc, dev_info.port_hw_config[port].speed_capability_mask2);
13442 /* get the lane config */
13443 sc->link_params.lane_config =
13444 SHMEM_RD(sc, dev_info.port_hw_config[port].lane_config);
13446 /* get the link config */
13447 val = SHMEM_RD(sc, dev_info.port_feature_config[port].link_config);
13448 sc->port.link_config[ELINK_INT_PHY] = val;
13449 sc->link_params.switch_cfg = (val & PORT_FEATURE_CONNECTED_SWITCH_MASK);
13450 sc->port.link_config[ELINK_EXT_PHY1] =
13451 SHMEM_RD(sc, dev_info.port_feature_config[port].link_config2);
13453 /* get the override preemphasis flag and enable it or turn it off */
13454 val = SHMEM_RD(sc, dev_info.shared_feature_config.config);
13455 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED) {
13456 sc->link_params.feature_config_flags |=
13457 ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
13459 sc->link_params.feature_config_flags &=
13460 ~ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
13463 /* get the initial value of the link params */
13464 sc->link_params.multi_phy_config =
13465 SHMEM_RD(sc, dev_info.port_hw_config[port].multi_phy_config);
13467 /* get external phy info */
13468 sc->port.ext_phy_config =
13469 SHMEM_RD(sc, dev_info.port_hw_config[port].external_phy_config);
13471 /* get the multifunction configuration */
13472 bxe_get_mf_cfg_info(sc);
13474 /* get the mac address */
13476 mac_hi = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper);
13477 mac_lo = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_lower);
13479 mac_hi = SHMEM_RD(sc, dev_info.port_hw_config[port].mac_upper);
13480 mac_lo = SHMEM_RD(sc, dev_info.port_hw_config[port].mac_lower);
13483 if ((mac_lo == 0) && (mac_hi == 0)) {
13484 *sc->mac_addr_str = 0;
13485 BLOGE(sc, "No Ethernet address programmed!\n");
13487 sc->link_params.mac_addr[0] = (uint8_t)(mac_hi >> 8);
13488 sc->link_params.mac_addr[1] = (uint8_t)(mac_hi);
13489 sc->link_params.mac_addr[2] = (uint8_t)(mac_lo >> 24);
13490 sc->link_params.mac_addr[3] = (uint8_t)(mac_lo >> 16);
13491 sc->link_params.mac_addr[4] = (uint8_t)(mac_lo >> 8);
13492 sc->link_params.mac_addr[5] = (uint8_t)(mac_lo);
13493 snprintf(sc->mac_addr_str, sizeof(sc->mac_addr_str),
13494 "%02x:%02x:%02x:%02x:%02x:%02x",
13495 sc->link_params.mac_addr[0], sc->link_params.mac_addr[1],
13496 sc->link_params.mac_addr[2], sc->link_params.mac_addr[3],
13497 sc->link_params.mac_addr[4], sc->link_params.mac_addr[5]);
13498 BLOGD(sc, DBG_LOAD, "Ethernet address: %s\n", sc->mac_addr_str);
13505 bxe_get_tunable_params(struct bxe_softc *sc)
13507 /* sanity checks */
13509 if ((bxe_interrupt_mode != INTR_MODE_INTX) &&
13510 (bxe_interrupt_mode != INTR_MODE_MSI) &&
13511 (bxe_interrupt_mode != INTR_MODE_MSIX)) {
13512 BLOGW(sc, "invalid interrupt_mode value (%d)\n", bxe_interrupt_mode);
13513 bxe_interrupt_mode = INTR_MODE_MSIX;
13516 if ((bxe_queue_count < 0) || (bxe_queue_count > MAX_RSS_CHAINS)) {
13517 BLOGW(sc, "invalid queue_count value (%d)\n", bxe_queue_count);
13518 bxe_queue_count = 0;
13521 if ((bxe_max_rx_bufs < 1) || (bxe_max_rx_bufs > RX_BD_USABLE)) {
13522 if (bxe_max_rx_bufs == 0) {
13523 bxe_max_rx_bufs = RX_BD_USABLE;
13525 BLOGW(sc, "invalid max_rx_bufs (%d)\n", bxe_max_rx_bufs);
13526 bxe_max_rx_bufs = 2048;
13530 if ((bxe_hc_rx_ticks < 1) || (bxe_hc_rx_ticks > 100)) {
13531 BLOGW(sc, "invalid hc_rx_ticks (%d)\n", bxe_hc_rx_ticks);
13532 bxe_hc_rx_ticks = 25;
13535 if ((bxe_hc_tx_ticks < 1) || (bxe_hc_tx_ticks > 100)) {
13536 BLOGW(sc, "invalid hc_tx_ticks (%d)\n", bxe_hc_tx_ticks);
13537 bxe_hc_tx_ticks = 50;
13540 if (bxe_max_aggregation_size == 0) {
13541 bxe_max_aggregation_size = TPA_AGG_SIZE;
13544 if (bxe_max_aggregation_size > 0xffff) {
13545 BLOGW(sc, "invalid max_aggregation_size (%d)\n",
13546 bxe_max_aggregation_size);
13547 bxe_max_aggregation_size = TPA_AGG_SIZE;
13550 if ((bxe_mrrs < -1) || (bxe_mrrs > 3)) {
13551 BLOGW(sc, "invalid mrrs (%d)\n", bxe_mrrs);
13555 if ((bxe_autogreeen < 0) || (bxe_autogreeen > 2)) {
13556 BLOGW(sc, "invalid autogreeen (%d)\n", bxe_autogreeen);
13557 bxe_autogreeen = 0;
13560 if ((bxe_udp_rss < 0) || (bxe_udp_rss > 1)) {
13561 BLOGW(sc, "invalid udp_rss (%d)\n", bxe_udp_rss);
13565 /* pull in user settings */
13567 sc->interrupt_mode = bxe_interrupt_mode;
13568 sc->max_rx_bufs = bxe_max_rx_bufs;
13569 sc->hc_rx_ticks = bxe_hc_rx_ticks;
13570 sc->hc_tx_ticks = bxe_hc_tx_ticks;
13571 sc->max_aggregation_size = bxe_max_aggregation_size;
13572 sc->mrrs = bxe_mrrs;
13573 sc->autogreeen = bxe_autogreeen;
13574 sc->udp_rss = bxe_udp_rss;
13576 if (bxe_interrupt_mode == INTR_MODE_INTX) {
13577 sc->num_queues = 1;
13578 } else { /* INTR_MODE_MSI or INTR_MODE_MSIX */
13580 min((bxe_queue_count ? bxe_queue_count : mp_ncpus),
13582 if (sc->num_queues > mp_ncpus) {
13583 sc->num_queues = mp_ncpus;
13587 BLOGD(sc, DBG_LOAD,
13590 "interrupt_mode=%d "
13595 "max_aggregation_size=%d "
13600 sc->interrupt_mode,
13605 sc->max_aggregation_size,
13612 bxe_media_detect(struct bxe_softc *sc)
13615 uint32_t phy_idx = bxe_get_cur_phy_idx(sc);
13617 switch (sc->link_params.phy[phy_idx].media_type) {
13618 case ELINK_ETH_PHY_SFPP_10G_FIBER:
13619 case ELINK_ETH_PHY_XFP_FIBER:
13620 BLOGI(sc, "Found 10Gb Fiber media.\n");
13621 sc->media = IFM_10G_SR;
13622 port_type = PORT_FIBRE;
13624 case ELINK_ETH_PHY_SFP_1G_FIBER:
13625 BLOGI(sc, "Found 1Gb Fiber media.\n");
13626 sc->media = IFM_1000_SX;
13627 port_type = PORT_FIBRE;
13629 case ELINK_ETH_PHY_KR:
13630 case ELINK_ETH_PHY_CX4:
13631 BLOGI(sc, "Found 10GBase-CX4 media.\n");
13632 sc->media = IFM_10G_CX4;
13633 port_type = PORT_FIBRE;
13635 case ELINK_ETH_PHY_DA_TWINAX:
13636 BLOGI(sc, "Found 10Gb Twinax media.\n");
13637 sc->media = IFM_10G_TWINAX;
13638 port_type = PORT_DA;
13640 case ELINK_ETH_PHY_BASE_T:
13641 if (sc->link_params.speed_cap_mask[0] &
13642 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) {
13643 BLOGI(sc, "Found 10GBase-T media.\n");
13644 sc->media = IFM_10G_T;
13645 port_type = PORT_TP;
13647 BLOGI(sc, "Found 1000Base-T media.\n");
13648 sc->media = IFM_1000_T;
13649 port_type = PORT_TP;
13652 case ELINK_ETH_PHY_NOT_PRESENT:
13653 BLOGI(sc, "Media not present.\n");
13655 port_type = PORT_OTHER;
13657 case ELINK_ETH_PHY_UNSPECIFIED:
13659 BLOGI(sc, "Unknown media!\n");
13661 port_type = PORT_OTHER;
13667 #define GET_FIELD(value, fname) \
13668 (((value) & (fname##_MASK)) >> (fname##_SHIFT))
13669 #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
13670 #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
13673 bxe_get_igu_cam_info(struct bxe_softc *sc)
13675 int pfid = SC_FUNC(sc);
13678 uint8_t fid, igu_sb_cnt = 0;
13680 sc->igu_base_sb = 0xff;
13682 if (CHIP_INT_MODE_IS_BC(sc)) {
13683 int vn = SC_VN(sc);
13684 igu_sb_cnt = sc->igu_sb_cnt;
13685 sc->igu_base_sb = ((CHIP_IS_MODE_4_PORT(sc) ? pfid : vn) *
13687 sc->igu_dsb_id = (E1HVN_MAX * FP_SB_MAX_E1x +
13688 (CHIP_IS_MODE_4_PORT(sc) ? pfid : vn));
13692 /* IGU in normal mode - read CAM */
13693 for (igu_sb_id = 0;
13694 igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
13696 val = REG_RD(sc, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
13697 if (!(val & IGU_REG_MAPPING_MEMORY_VALID)) {
13700 fid = IGU_FID(val);
13701 if ((fid & IGU_FID_ENCODE_IS_PF)) {
13702 if ((fid & IGU_FID_PF_NUM_MASK) != pfid) {
13705 if (IGU_VEC(val) == 0) {
13706 /* default status block */
13707 sc->igu_dsb_id = igu_sb_id;
13709 if (sc->igu_base_sb == 0xff) {
13710 sc->igu_base_sb = igu_sb_id;
13718 * Due to new PF resource allocation by MFW T7.4 and above, it's optional
13719 * that number of CAM entries will not be equal to the value advertised in
13720 * PCI. Driver should use the minimal value of both as the actual status
13723 sc->igu_sb_cnt = min(sc->igu_sb_cnt, igu_sb_cnt);
13725 if (igu_sb_cnt == 0) {
13726 BLOGE(sc, "CAM configuration error\n");
13734 * Gather various information from the device config space, the device itself,
13735 * shmem, and the user input.
13738 bxe_get_device_info(struct bxe_softc *sc)
13743 /* Get the data for the device */
13744 sc->devinfo.vendor_id = pci_get_vendor(sc->dev);
13745 sc->devinfo.device_id = pci_get_device(sc->dev);
13746 sc->devinfo.subvendor_id = pci_get_subvendor(sc->dev);
13747 sc->devinfo.subdevice_id = pci_get_subdevice(sc->dev);
13749 /* get the chip revision (chip metal comes from pci config space) */
13750 sc->devinfo.chip_id =
13751 sc->link_params.chip_id =
13752 (((REG_RD(sc, MISC_REG_CHIP_NUM) & 0xffff) << 16) |
13753 ((REG_RD(sc, MISC_REG_CHIP_REV) & 0xf) << 12) |
13754 (((REG_RD(sc, PCICFG_OFFSET + PCI_ID_VAL3) >> 24) & 0xf) << 4) |
13755 ((REG_RD(sc, MISC_REG_BOND_ID) & 0xf) << 0));
13757 /* force 57811 according to MISC register */
13758 if (REG_RD(sc, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
13759 if (CHIP_IS_57810(sc)) {
13760 sc->devinfo.chip_id = ((CHIP_NUM_57811 << 16) |
13761 (sc->devinfo.chip_id & 0x0000ffff));
13762 } else if (CHIP_IS_57810_MF(sc)) {
13763 sc->devinfo.chip_id = ((CHIP_NUM_57811_MF << 16) |
13764 (sc->devinfo.chip_id & 0x0000ffff));
13766 sc->devinfo.chip_id |= 0x1;
13769 BLOGD(sc, DBG_LOAD,
13770 "chip_id=0x%08x (num=0x%04x rev=0x%01x metal=0x%02x bond=0x%01x)\n",
13771 sc->devinfo.chip_id,
13772 ((sc->devinfo.chip_id >> 16) & 0xffff),
13773 ((sc->devinfo.chip_id >> 12) & 0xf),
13774 ((sc->devinfo.chip_id >> 4) & 0xff),
13775 ((sc->devinfo.chip_id >> 0) & 0xf));
13777 val = (REG_RD(sc, 0x2874) & 0x55);
13778 if ((sc->devinfo.chip_id & 0x1) ||
13779 (CHIP_IS_E1(sc) && val) ||
13780 (CHIP_IS_E1H(sc) && (val == 0x55))) {
13781 sc->flags |= BXE_ONE_PORT_FLAG;
13782 BLOGD(sc, DBG_LOAD, "single port device\n");
13785 /* set the doorbell size */
13786 sc->doorbell_size = (1 << BXE_DB_SHIFT);
13788 /* determine whether the device is in 2 port or 4 port mode */
13789 sc->devinfo.chip_port_mode = CHIP_PORT_MODE_NONE; /* E1 & E1h*/
13790 if (CHIP_IS_E2E3(sc)) {
13792 * Read port4mode_en_ovwr[0]:
13793 * If 1, four port mode is in port4mode_en_ovwr[1].
13794 * If 0, four port mode is in port4mode_en[0].
13796 val = REG_RD(sc, MISC_REG_PORT4MODE_EN_OVWR);
13798 val = ((val >> 1) & 1);
13800 val = REG_RD(sc, MISC_REG_PORT4MODE_EN);
13803 sc->devinfo.chip_port_mode =
13804 (val) ? CHIP_4_PORT_MODE : CHIP_2_PORT_MODE;
13806 BLOGD(sc, DBG_LOAD, "Port mode = %s\n", (val) ? "4" : "2");
13809 /* get the function and path info for the device */
13810 bxe_get_function_num(sc);
13812 /* get the shared memory base address */
13813 sc->devinfo.shmem_base =
13814 sc->link_params.shmem_base =
13815 REG_RD(sc, MISC_REG_SHARED_MEM_ADDR);
13816 sc->devinfo.shmem2_base =
13817 REG_RD(sc, (SC_PATH(sc) ? MISC_REG_GENERIC_CR_1 :
13818 MISC_REG_GENERIC_CR_0));
13820 BLOGD(sc, DBG_LOAD, "shmem_base=0x%08x, shmem2_base=0x%08x\n",
13821 sc->devinfo.shmem_base, sc->devinfo.shmem2_base);
13823 if (!sc->devinfo.shmem_base) {
13824 /* this should ONLY prevent upcoming shmem reads */
13825 BLOGI(sc, "MCP not active\n");
13826 sc->flags |= BXE_NO_MCP_FLAG;
13830 /* make sure the shared memory contents are valid */
13831 val = SHMEM_RD(sc, validity_map[SC_PORT(sc)]);
13832 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) !=
13833 (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) {
13834 BLOGE(sc, "Invalid SHMEM validity signature: 0x%08x\n", val);
13837 BLOGD(sc, DBG_LOAD, "Valid SHMEM validity signature: 0x%08x\n", val);
13839 /* get the bootcode version */
13840 sc->devinfo.bc_ver = SHMEM_RD(sc, dev_info.bc_rev);
13841 snprintf(sc->devinfo.bc_ver_str,
13842 sizeof(sc->devinfo.bc_ver_str),
13844 ((sc->devinfo.bc_ver >> 24) & 0xff),
13845 ((sc->devinfo.bc_ver >> 16) & 0xff),
13846 ((sc->devinfo.bc_ver >> 8) & 0xff));
13847 BLOGD(sc, DBG_LOAD, "Bootcode version: %s\n", sc->devinfo.bc_ver_str);
13849 /* get the bootcode shmem address */
13850 sc->devinfo.mf_cfg_base = bxe_get_shmem_mf_cfg_base(sc);
13851 BLOGD(sc, DBG_LOAD, "mf_cfg_base=0x08%x \n", sc->devinfo.mf_cfg_base);
13853 /* clean indirect addresses as they're not used */
13854 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, 0, 4);
13856 REG_WR(sc, PXP2_REG_PGL_ADDR_88_F0, 0);
13857 REG_WR(sc, PXP2_REG_PGL_ADDR_8C_F0, 0);
13858 REG_WR(sc, PXP2_REG_PGL_ADDR_90_F0, 0);
13859 REG_WR(sc, PXP2_REG_PGL_ADDR_94_F0, 0);
13860 if (CHIP_IS_E1x(sc)) {
13861 REG_WR(sc, PXP2_REG_PGL_ADDR_88_F1, 0);
13862 REG_WR(sc, PXP2_REG_PGL_ADDR_8C_F1, 0);
13863 REG_WR(sc, PXP2_REG_PGL_ADDR_90_F1, 0);
13864 REG_WR(sc, PXP2_REG_PGL_ADDR_94_F1, 0);
13868 * Enable internal target-read (in case we are probed after PF
13869 * FLR). Must be done prior to any BAR read access. Only for
13872 if (!CHIP_IS_E1x(sc)) {
13873 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
13877 /* get the nvram size */
13878 val = REG_RD(sc, MCP_REG_MCPR_NVM_CFG4);
13879 sc->devinfo.flash_size =
13880 (NVRAM_1MB_SIZE << (val & MCPR_NVM_CFG4_FLASH_SIZE));
13881 BLOGD(sc, DBG_LOAD, "nvram flash size: %d\n", sc->devinfo.flash_size);
13883 /* get PCI capabilites */
13884 bxe_probe_pci_caps(sc);
13886 bxe_set_power_state(sc, PCI_PM_D0);
13888 /* get various configuration parameters from shmem */
13889 bxe_get_shmem_info(sc);
13891 if (sc->devinfo.pcie_msix_cap_reg != 0) {
13892 val = pci_read_config(sc->dev,
13893 (sc->devinfo.pcie_msix_cap_reg +
13896 sc->igu_sb_cnt = (val & PCIM_MSIXCTRL_TABLE_SIZE);
13898 sc->igu_sb_cnt = 1;
13901 sc->igu_base_addr = BAR_IGU_INTMEM;
13903 /* initialize IGU parameters */
13904 if (CHIP_IS_E1x(sc)) {
13905 sc->devinfo.int_block = INT_BLOCK_HC;
13906 sc->igu_dsb_id = DEF_SB_IGU_ID;
13907 sc->igu_base_sb = 0;
13909 sc->devinfo.int_block = INT_BLOCK_IGU;
13911 /* do not allow device reset during IGU info preocessing */
13912 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
13914 val = REG_RD(sc, IGU_REG_BLOCK_CONFIGURATION);
13916 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
13919 BLOGD(sc, DBG_LOAD, "FORCING IGU Normal Mode\n");
13921 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
13922 REG_WR(sc, IGU_REG_BLOCK_CONFIGURATION, val);
13923 REG_WR(sc, IGU_REG_RESET_MEMORIES, 0x7f);
13925 while (tout && REG_RD(sc, IGU_REG_RESET_MEMORIES)) {
13930 if (REG_RD(sc, IGU_REG_RESET_MEMORIES)) {
13931 BLOGD(sc, DBG_LOAD, "FORCING IGU Normal Mode failed!!!\n");
13932 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
13937 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
13938 BLOGD(sc, DBG_LOAD, "IGU Backward Compatible Mode\n");
13939 sc->devinfo.int_block |= INT_BLOCK_MODE_BW_COMP;
13941 BLOGD(sc, DBG_LOAD, "IGU Normal Mode\n");
13944 rc = bxe_get_igu_cam_info(sc);
13946 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
13954 * Get base FW non-default (fast path) status block ID. This value is
13955 * used to initialize the fw_sb_id saved on the fp/queue structure to
13956 * determine the id used by the FW.
13958 if (CHIP_IS_E1x(sc)) {
13959 sc->base_fw_ndsb = ((SC_PORT(sc) * FP_SB_MAX_E1x) + SC_L_ID(sc));
13962 * 57712+ - We currently use one FW SB per IGU SB (Rx and Tx of
13963 * the same queue are indicated on the same IGU SB). So we prefer
13964 * FW and IGU SBs to be the same value.
13966 sc->base_fw_ndsb = sc->igu_base_sb;
13969 BLOGD(sc, DBG_LOAD,
13970 "igu_dsb_id=%d igu_base_sb=%d igu_sb_cnt=%d base_fw_ndsb=%d\n",
13971 sc->igu_dsb_id, sc->igu_base_sb,
13972 sc->igu_sb_cnt, sc->base_fw_ndsb);
13974 elink_phy_probe(&sc->link_params);
13980 bxe_link_settings_supported(struct bxe_softc *sc,
13981 uint32_t switch_cfg)
13983 uint32_t cfg_size = 0;
13985 uint8_t port = SC_PORT(sc);
13987 /* aggregation of supported attributes of all external phys */
13988 sc->port.supported[0] = 0;
13989 sc->port.supported[1] = 0;
13991 switch (sc->link_params.num_phys) {
13993 sc->port.supported[0] = sc->link_params.phy[ELINK_INT_PHY].supported;
13997 sc->port.supported[0] = sc->link_params.phy[ELINK_EXT_PHY1].supported;
14001 if (sc->link_params.multi_phy_config &
14002 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
14003 sc->port.supported[1] =
14004 sc->link_params.phy[ELINK_EXT_PHY1].supported;
14005 sc->port.supported[0] =
14006 sc->link_params.phy[ELINK_EXT_PHY2].supported;
14008 sc->port.supported[0] =
14009 sc->link_params.phy[ELINK_EXT_PHY1].supported;
14010 sc->port.supported[1] =
14011 sc->link_params.phy[ELINK_EXT_PHY2].supported;
14017 if (!(sc->port.supported[0] || sc->port.supported[1])) {
14018 BLOGE(sc, "Invalid phy config in NVRAM (PHY1=0x%08x PHY2=0x%08x)\n",
14020 dev_info.port_hw_config[port].external_phy_config),
14022 dev_info.port_hw_config[port].external_phy_config2));
14026 if (CHIP_IS_E3(sc))
14027 sc->port.phy_addr = REG_RD(sc, MISC_REG_WC0_CTRL_PHY_ADDR);
14029 switch (switch_cfg) {
14030 case ELINK_SWITCH_CFG_1G:
14031 sc->port.phy_addr =
14032 REG_RD(sc, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
14034 case ELINK_SWITCH_CFG_10G:
14035 sc->port.phy_addr =
14036 REG_RD(sc, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
14039 BLOGE(sc, "Invalid switch config in link_config=0x%08x\n",
14040 sc->port.link_config[0]);
14045 BLOGD(sc, DBG_LOAD, "PHY addr 0x%08x\n", sc->port.phy_addr);
14047 /* mask what we support according to speed_cap_mask per configuration */
14048 for (idx = 0; idx < cfg_size; idx++) {
14049 if (!(sc->link_params.speed_cap_mask[idx] &
14050 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) {
14051 sc->port.supported[idx] &= ~ELINK_SUPPORTED_10baseT_Half;
14054 if (!(sc->link_params.speed_cap_mask[idx] &
14055 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL)) {
14056 sc->port.supported[idx] &= ~ELINK_SUPPORTED_10baseT_Full;
14059 if (!(sc->link_params.speed_cap_mask[idx] &
14060 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)) {
14061 sc->port.supported[idx] &= ~ELINK_SUPPORTED_100baseT_Half;
14064 if (!(sc->link_params.speed_cap_mask[idx] &
14065 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL)) {
14066 sc->port.supported[idx] &= ~ELINK_SUPPORTED_100baseT_Full;
14069 if (!(sc->link_params.speed_cap_mask[idx] &
14070 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) {
14071 sc->port.supported[idx] &= ~ELINK_SUPPORTED_1000baseT_Full;
14074 if (!(sc->link_params.speed_cap_mask[idx] &
14075 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)) {
14076 sc->port.supported[idx] &= ~ELINK_SUPPORTED_2500baseX_Full;
14079 if (!(sc->link_params.speed_cap_mask[idx] &
14080 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
14081 sc->port.supported[idx] &= ~ELINK_SUPPORTED_10000baseT_Full;
14084 if (!(sc->link_params.speed_cap_mask[idx] &
14085 PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)) {
14086 sc->port.supported[idx] &= ~ELINK_SUPPORTED_20000baseKR2_Full;
14090 BLOGD(sc, DBG_LOAD, "PHY supported 0=0x%08x 1=0x%08x\n",
14091 sc->port.supported[0], sc->port.supported[1]);
14092 ELINK_DEBUG_P2(sc, "PHY supported 0=0x%08x 1=0x%08x\n",
14093 sc->port.supported[0], sc->port.supported[1]);
14097 bxe_link_settings_requested(struct bxe_softc *sc)
14099 uint32_t link_config;
14101 uint32_t cfg_size = 0;
14103 sc->port.advertising[0] = 0;
14104 sc->port.advertising[1] = 0;
14106 switch (sc->link_params.num_phys) {
14116 for (idx = 0; idx < cfg_size; idx++) {
14117 sc->link_params.req_duplex[idx] = DUPLEX_FULL;
14118 link_config = sc->port.link_config[idx];
14120 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
14121 case PORT_FEATURE_LINK_SPEED_AUTO:
14122 if (sc->port.supported[idx] & ELINK_SUPPORTED_Autoneg) {
14123 sc->link_params.req_line_speed[idx] = ELINK_SPEED_AUTO_NEG;
14124 sc->port.advertising[idx] |= sc->port.supported[idx];
14125 if (sc->link_params.phy[ELINK_EXT_PHY1].type ==
14126 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
14127 sc->port.advertising[idx] |=
14128 (ELINK_SUPPORTED_100baseT_Half |
14129 ELINK_SUPPORTED_100baseT_Full);
14131 /* force 10G, no AN */
14132 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10000;
14133 sc->port.advertising[idx] |=
14134 (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
14139 case PORT_FEATURE_LINK_SPEED_10M_FULL:
14140 if (sc->port.supported[idx] & ELINK_SUPPORTED_10baseT_Full) {
14141 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10;
14142 sc->port.advertising[idx] |= (ADVERTISED_10baseT_Full |
14145 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14146 "speed_cap_mask=0x%08x\n",
14147 link_config, sc->link_params.speed_cap_mask[idx]);
14152 case PORT_FEATURE_LINK_SPEED_10M_HALF:
14153 if (sc->port.supported[idx] & ELINK_SUPPORTED_10baseT_Half) {
14154 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10;
14155 sc->link_params.req_duplex[idx] = DUPLEX_HALF;
14156 sc->port.advertising[idx] |= (ADVERTISED_10baseT_Half |
14158 ELINK_DEBUG_P1(sc, "driver requesting DUPLEX_HALF req_duplex = %x!\n",
14159 sc->link_params.req_duplex[idx]);
14161 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14162 "speed_cap_mask=0x%08x\n",
14163 link_config, sc->link_params.speed_cap_mask[idx]);
14168 case PORT_FEATURE_LINK_SPEED_100M_FULL:
14169 if (sc->port.supported[idx] & ELINK_SUPPORTED_100baseT_Full) {
14170 sc->link_params.req_line_speed[idx] = ELINK_SPEED_100;
14171 sc->port.advertising[idx] |= (ADVERTISED_100baseT_Full |
14174 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14175 "speed_cap_mask=0x%08x\n",
14176 link_config, sc->link_params.speed_cap_mask[idx]);
14181 case PORT_FEATURE_LINK_SPEED_100M_HALF:
14182 if (sc->port.supported[idx] & ELINK_SUPPORTED_100baseT_Half) {
14183 sc->link_params.req_line_speed[idx] = ELINK_SPEED_100;
14184 sc->link_params.req_duplex[idx] = DUPLEX_HALF;
14185 sc->port.advertising[idx] |= (ADVERTISED_100baseT_Half |
14188 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14189 "speed_cap_mask=0x%08x\n",
14190 link_config, sc->link_params.speed_cap_mask[idx]);
14195 case PORT_FEATURE_LINK_SPEED_1G:
14196 if (sc->port.supported[idx] & ELINK_SUPPORTED_1000baseT_Full) {
14197 sc->link_params.req_line_speed[idx] = ELINK_SPEED_1000;
14198 sc->port.advertising[idx] |= (ADVERTISED_1000baseT_Full |
14201 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14202 "speed_cap_mask=0x%08x\n",
14203 link_config, sc->link_params.speed_cap_mask[idx]);
14208 case PORT_FEATURE_LINK_SPEED_2_5G:
14209 if (sc->port.supported[idx] & ELINK_SUPPORTED_2500baseX_Full) {
14210 sc->link_params.req_line_speed[idx] = ELINK_SPEED_2500;
14211 sc->port.advertising[idx] |= (ADVERTISED_2500baseX_Full |
14214 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14215 "speed_cap_mask=0x%08x\n",
14216 link_config, sc->link_params.speed_cap_mask[idx]);
14221 case PORT_FEATURE_LINK_SPEED_10G_CX4:
14222 if (sc->port.supported[idx] & ELINK_SUPPORTED_10000baseT_Full) {
14223 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10000;
14224 sc->port.advertising[idx] |= (ADVERTISED_10000baseT_Full |
14227 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14228 "speed_cap_mask=0x%08x\n",
14229 link_config, sc->link_params.speed_cap_mask[idx]);
14234 case PORT_FEATURE_LINK_SPEED_20G:
14235 sc->link_params.req_line_speed[idx] = ELINK_SPEED_20000;
14239 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14240 "speed_cap_mask=0x%08x\n",
14241 link_config, sc->link_params.speed_cap_mask[idx]);
14242 sc->link_params.req_line_speed[idx] = ELINK_SPEED_AUTO_NEG;
14243 sc->port.advertising[idx] = sc->port.supported[idx];
14247 sc->link_params.req_flow_ctrl[idx] =
14248 (link_config & PORT_FEATURE_FLOW_CONTROL_MASK);
14250 if (sc->link_params.req_flow_ctrl[idx] == ELINK_FLOW_CTRL_AUTO) {
14251 if (!(sc->port.supported[idx] & ELINK_SUPPORTED_Autoneg)) {
14252 sc->link_params.req_flow_ctrl[idx] = ELINK_FLOW_CTRL_NONE;
14254 bxe_set_requested_fc(sc);
14258 BLOGD(sc, DBG_LOAD, "req_line_speed=%d req_duplex=%d "
14259 "req_flow_ctrl=0x%x advertising=0x%x\n",
14260 sc->link_params.req_line_speed[idx],
14261 sc->link_params.req_duplex[idx],
14262 sc->link_params.req_flow_ctrl[idx],
14263 sc->port.advertising[idx]);
14264 ELINK_DEBUG_P3(sc, "req_line_speed=%d req_duplex=%d "
14265 "advertising=0x%x\n",
14266 sc->link_params.req_line_speed[idx],
14267 sc->link_params.req_duplex[idx],
14268 sc->port.advertising[idx]);
14273 bxe_get_phy_info(struct bxe_softc *sc)
14275 uint8_t port = SC_PORT(sc);
14276 uint32_t config = sc->port.config;
14279 /* shmem data already read in bxe_get_shmem_info() */
14281 ELINK_DEBUG_P3(sc, "lane_config=0x%08x speed_cap_mask0=0x%08x "
14282 "link_config0=0x%08x\n",
14283 sc->link_params.lane_config,
14284 sc->link_params.speed_cap_mask[0],
14285 sc->port.link_config[0]);
14288 bxe_link_settings_supported(sc, sc->link_params.switch_cfg);
14289 bxe_link_settings_requested(sc);
14291 if (sc->autogreeen == AUTO_GREEN_FORCE_ON) {
14292 sc->link_params.feature_config_flags |=
14293 ELINK_FEATURE_CONFIG_AUTOGREEEN_ENABLED;
14294 } else if (sc->autogreeen == AUTO_GREEN_FORCE_OFF) {
14295 sc->link_params.feature_config_flags &=
14296 ~ELINK_FEATURE_CONFIG_AUTOGREEEN_ENABLED;
14297 } else if (config & PORT_FEAT_CFG_AUTOGREEEN_ENABLED) {
14298 sc->link_params.feature_config_flags |=
14299 ELINK_FEATURE_CONFIG_AUTOGREEEN_ENABLED;
14302 /* configure link feature according to nvram value */
14304 (((SHMEM_RD(sc, dev_info.port_feature_config[port].eee_power_mode)) &
14305 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
14306 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
14307 if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
14308 sc->link_params.eee_mode = (ELINK_EEE_MODE_ADV_LPI |
14309 ELINK_EEE_MODE_ENABLE_LPI |
14310 ELINK_EEE_MODE_OUTPUT_TIME);
14312 sc->link_params.eee_mode = 0;
14315 /* get the media type */
14316 bxe_media_detect(sc);
14317 ELINK_DEBUG_P1(sc, "detected media type\n", sc->media);
14321 bxe_get_params(struct bxe_softc *sc)
14323 /* get user tunable params */
14324 bxe_get_tunable_params(sc);
14326 /* select the RX and TX ring sizes */
14327 sc->tx_ring_size = TX_BD_USABLE;
14328 sc->rx_ring_size = RX_BD_USABLE;
14330 /* XXX disable WoL */
14335 bxe_set_modes_bitmap(struct bxe_softc *sc)
14337 uint32_t flags = 0;
14339 if (CHIP_REV_IS_FPGA(sc)) {
14340 SET_FLAGS(flags, MODE_FPGA);
14341 } else if (CHIP_REV_IS_EMUL(sc)) {
14342 SET_FLAGS(flags, MODE_EMUL);
14344 SET_FLAGS(flags, MODE_ASIC);
14347 if (CHIP_IS_MODE_4_PORT(sc)) {
14348 SET_FLAGS(flags, MODE_PORT4);
14350 SET_FLAGS(flags, MODE_PORT2);
14353 if (CHIP_IS_E2(sc)) {
14354 SET_FLAGS(flags, MODE_E2);
14355 } else if (CHIP_IS_E3(sc)) {
14356 SET_FLAGS(flags, MODE_E3);
14357 if (CHIP_REV(sc) == CHIP_REV_Ax) {
14358 SET_FLAGS(flags, MODE_E3_A0);
14359 } else /*if (CHIP_REV(sc) == CHIP_REV_Bx)*/ {
14360 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
14365 SET_FLAGS(flags, MODE_MF);
14366 switch (sc->devinfo.mf_info.mf_mode) {
14367 case MULTI_FUNCTION_SD:
14368 SET_FLAGS(flags, MODE_MF_SD);
14370 case MULTI_FUNCTION_SI:
14371 SET_FLAGS(flags, MODE_MF_SI);
14373 case MULTI_FUNCTION_AFEX:
14374 SET_FLAGS(flags, MODE_MF_AFEX);
14378 SET_FLAGS(flags, MODE_SF);
14381 #if defined(__LITTLE_ENDIAN)
14382 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
14383 #else /* __BIG_ENDIAN */
14384 SET_FLAGS(flags, MODE_BIG_ENDIAN);
14387 INIT_MODE_FLAGS(sc) = flags;
14391 bxe_alloc_hsi_mem(struct bxe_softc *sc)
14393 struct bxe_fastpath *fp;
14394 bus_addr_t busaddr;
14395 int max_agg_queues;
14397 bus_size_t max_size;
14398 bus_size_t max_seg_size;
14403 /* XXX zero out all vars here and call bxe_alloc_hsi_mem on error */
14405 /* allocate the parent bus DMA tag */
14406 rc = bus_dma_tag_create(bus_get_dma_tag(sc->dev), /* parent tag */
14408 0, /* boundary limit */
14409 BUS_SPACE_MAXADDR, /* restricted low */
14410 BUS_SPACE_MAXADDR, /* restricted hi */
14411 NULL, /* addr filter() */
14412 NULL, /* addr filter() arg */
14413 BUS_SPACE_MAXSIZE_32BIT, /* max map size */
14414 BUS_SPACE_UNRESTRICTED, /* num discontinuous */
14415 BUS_SPACE_MAXSIZE_32BIT, /* max seg size */
14418 NULL, /* lock() arg */
14419 &sc->parent_dma_tag); /* returned dma tag */
14421 BLOGE(sc, "Failed to alloc parent DMA tag (%d)!\n", rc);
14425 /************************/
14426 /* DEFAULT STATUS BLOCK */
14427 /************************/
14429 if (bxe_dma_alloc(sc, sizeof(struct host_sp_status_block),
14430 &sc->def_sb_dma, "default status block") != 0) {
14432 bus_dma_tag_destroy(sc->parent_dma_tag);
14436 sc->def_sb = (struct host_sp_status_block *)sc->def_sb_dma.vaddr;
14442 if (bxe_dma_alloc(sc, BCM_PAGE_SIZE,
14443 &sc->eq_dma, "event queue") != 0) {
14445 bxe_dma_free(sc, &sc->def_sb_dma);
14447 bus_dma_tag_destroy(sc->parent_dma_tag);
14451 sc->eq = (union event_ring_elem * )sc->eq_dma.vaddr;
14457 if (bxe_dma_alloc(sc, sizeof(struct bxe_slowpath),
14458 &sc->sp_dma, "slow path") != 0) {
14460 bxe_dma_free(sc, &sc->eq_dma);
14462 bxe_dma_free(sc, &sc->def_sb_dma);
14464 bus_dma_tag_destroy(sc->parent_dma_tag);
14468 sc->sp = (struct bxe_slowpath *)sc->sp_dma.vaddr;
14470 /*******************/
14471 /* SLOW PATH QUEUE */
14472 /*******************/
14474 if (bxe_dma_alloc(sc, BCM_PAGE_SIZE,
14475 &sc->spq_dma, "slow path queue") != 0) {
14477 bxe_dma_free(sc, &sc->sp_dma);
14479 bxe_dma_free(sc, &sc->eq_dma);
14481 bxe_dma_free(sc, &sc->def_sb_dma);
14483 bus_dma_tag_destroy(sc->parent_dma_tag);
14487 sc->spq = (struct eth_spe *)sc->spq_dma.vaddr;
14489 /***************************/
14490 /* FW DECOMPRESSION BUFFER */
14491 /***************************/
14493 if (bxe_dma_alloc(sc, FW_BUF_SIZE, &sc->gz_buf_dma,
14494 "fw decompression buffer") != 0) {
14496 bxe_dma_free(sc, &sc->spq_dma);
14498 bxe_dma_free(sc, &sc->sp_dma);
14500 bxe_dma_free(sc, &sc->eq_dma);
14502 bxe_dma_free(sc, &sc->def_sb_dma);
14504 bus_dma_tag_destroy(sc->parent_dma_tag);
14508 sc->gz_buf = (void *)sc->gz_buf_dma.vaddr;
14511 malloc(sizeof(*sc->gz_strm), M_DEVBUF, M_NOWAIT)) == NULL) {
14513 bxe_dma_free(sc, &sc->gz_buf_dma);
14515 bxe_dma_free(sc, &sc->spq_dma);
14517 bxe_dma_free(sc, &sc->sp_dma);
14519 bxe_dma_free(sc, &sc->eq_dma);
14521 bxe_dma_free(sc, &sc->def_sb_dma);
14523 bus_dma_tag_destroy(sc->parent_dma_tag);
14531 /* allocate DMA memory for each fastpath structure */
14532 for (i = 0; i < sc->num_queues; i++) {
14537 /*******************/
14538 /* FP STATUS BLOCK */
14539 /*******************/
14541 snprintf(buf, sizeof(buf), "fp %d status block", i);
14542 if (bxe_dma_alloc(sc, sizeof(union bxe_host_hc_status_block),
14543 &fp->sb_dma, buf) != 0) {
14544 /* XXX unwind and free previous fastpath allocations */
14545 BLOGE(sc, "Failed to alloc %s\n", buf);
14548 if (CHIP_IS_E2E3(sc)) {
14549 fp->status_block.e2_sb =
14550 (struct host_hc_status_block_e2 *)fp->sb_dma.vaddr;
14552 fp->status_block.e1x_sb =
14553 (struct host_hc_status_block_e1x *)fp->sb_dma.vaddr;
14557 /******************/
14558 /* FP TX BD CHAIN */
14559 /******************/
14561 snprintf(buf, sizeof(buf), "fp %d tx bd chain", i);
14562 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * TX_BD_NUM_PAGES),
14563 &fp->tx_dma, buf) != 0) {
14564 /* XXX unwind and free previous fastpath allocations */
14565 BLOGE(sc, "Failed to alloc %s\n", buf);
14568 fp->tx_chain = (union eth_tx_bd_types *)fp->tx_dma.vaddr;
14571 /* link together the tx bd chain pages */
14572 for (j = 1; j <= TX_BD_NUM_PAGES; j++) {
14573 /* index into the tx bd chain array to last entry per page */
14574 struct eth_tx_next_bd *tx_next_bd =
14575 &fp->tx_chain[TX_BD_TOTAL_PER_PAGE * j - 1].next_bd;
14576 /* point to the next page and wrap from last page */
14577 busaddr = (fp->tx_dma.paddr +
14578 (BCM_PAGE_SIZE * (j % TX_BD_NUM_PAGES)));
14579 tx_next_bd->addr_hi = htole32(U64_HI(busaddr));
14580 tx_next_bd->addr_lo = htole32(U64_LO(busaddr));
14583 /******************/
14584 /* FP RX BD CHAIN */
14585 /******************/
14587 snprintf(buf, sizeof(buf), "fp %d rx bd chain", i);
14588 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * RX_BD_NUM_PAGES),
14589 &fp->rx_dma, buf) != 0) {
14590 /* XXX unwind and free previous fastpath allocations */
14591 BLOGE(sc, "Failed to alloc %s\n", buf);
14594 fp->rx_chain = (struct eth_rx_bd *)fp->rx_dma.vaddr;
14597 /* link together the rx bd chain pages */
14598 for (j = 1; j <= RX_BD_NUM_PAGES; j++) {
14599 /* index into the rx bd chain array to last entry per page */
14600 struct eth_rx_bd *rx_bd =
14601 &fp->rx_chain[RX_BD_TOTAL_PER_PAGE * j - 2];
14602 /* point to the next page and wrap from last page */
14603 busaddr = (fp->rx_dma.paddr +
14604 (BCM_PAGE_SIZE * (j % RX_BD_NUM_PAGES)));
14605 rx_bd->addr_hi = htole32(U64_HI(busaddr));
14606 rx_bd->addr_lo = htole32(U64_LO(busaddr));
14609 /*******************/
14610 /* FP RX RCQ CHAIN */
14611 /*******************/
14613 snprintf(buf, sizeof(buf), "fp %d rcq chain", i);
14614 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * RCQ_NUM_PAGES),
14615 &fp->rcq_dma, buf) != 0) {
14616 /* XXX unwind and free previous fastpath allocations */
14617 BLOGE(sc, "Failed to alloc %s\n", buf);
14620 fp->rcq_chain = (union eth_rx_cqe *)fp->rcq_dma.vaddr;
14623 /* link together the rcq chain pages */
14624 for (j = 1; j <= RCQ_NUM_PAGES; j++) {
14625 /* index into the rcq chain array to last entry per page */
14626 struct eth_rx_cqe_next_page *rx_cqe_next =
14627 (struct eth_rx_cqe_next_page *)
14628 &fp->rcq_chain[RCQ_TOTAL_PER_PAGE * j - 1];
14629 /* point to the next page and wrap from last page */
14630 busaddr = (fp->rcq_dma.paddr +
14631 (BCM_PAGE_SIZE * (j % RCQ_NUM_PAGES)));
14632 rx_cqe_next->addr_hi = htole32(U64_HI(busaddr));
14633 rx_cqe_next->addr_lo = htole32(U64_LO(busaddr));
14636 /*******************/
14637 /* FP RX SGE CHAIN */
14638 /*******************/
14640 snprintf(buf, sizeof(buf), "fp %d sge chain", i);
14641 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * RX_SGE_NUM_PAGES),
14642 &fp->rx_sge_dma, buf) != 0) {
14643 /* XXX unwind and free previous fastpath allocations */
14644 BLOGE(sc, "Failed to alloc %s\n", buf);
14647 fp->rx_sge_chain = (struct eth_rx_sge *)fp->rx_sge_dma.vaddr;
14650 /* link together the sge chain pages */
14651 for (j = 1; j <= RX_SGE_NUM_PAGES; j++) {
14652 /* index into the rcq chain array to last entry per page */
14653 struct eth_rx_sge *rx_sge =
14654 &fp->rx_sge_chain[RX_SGE_TOTAL_PER_PAGE * j - 2];
14655 /* point to the next page and wrap from last page */
14656 busaddr = (fp->rx_sge_dma.paddr +
14657 (BCM_PAGE_SIZE * (j % RX_SGE_NUM_PAGES)));
14658 rx_sge->addr_hi = htole32(U64_HI(busaddr));
14659 rx_sge->addr_lo = htole32(U64_LO(busaddr));
14662 /***********************/
14663 /* FP TX MBUF DMA MAPS */
14664 /***********************/
14666 /* set required sizes before mapping to conserve resources */
14667 if (sc->ifnet->if_capenable & (IFCAP_TSO4 | IFCAP_TSO6)) {
14668 max_size = BXE_TSO_MAX_SIZE;
14669 max_segments = BXE_TSO_MAX_SEGMENTS;
14670 max_seg_size = BXE_TSO_MAX_SEG_SIZE;
14672 max_size = (MCLBYTES * BXE_MAX_SEGMENTS);
14673 max_segments = BXE_MAX_SEGMENTS;
14674 max_seg_size = MCLBYTES;
14677 /* create a dma tag for the tx mbufs */
14678 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */
14680 0, /* boundary limit */
14681 BUS_SPACE_MAXADDR, /* restricted low */
14682 BUS_SPACE_MAXADDR, /* restricted hi */
14683 NULL, /* addr filter() */
14684 NULL, /* addr filter() arg */
14685 max_size, /* max map size */
14686 max_segments, /* num discontinuous */
14687 max_seg_size, /* max seg size */
14690 NULL, /* lock() arg */
14691 &fp->tx_mbuf_tag); /* returned dma tag */
14693 /* XXX unwind and free previous fastpath allocations */
14694 BLOGE(sc, "Failed to create dma tag for "
14695 "'fp %d tx mbufs' (%d)\n", i, rc);
14699 /* create dma maps for each of the tx mbuf clusters */
14700 for (j = 0; j < TX_BD_TOTAL; j++) {
14701 if (bus_dmamap_create(fp->tx_mbuf_tag,
14703 &fp->tx_mbuf_chain[j].m_map)) {
14704 /* XXX unwind and free previous fastpath allocations */
14705 BLOGE(sc, "Failed to create dma map for "
14706 "'fp %d tx mbuf %d' (%d)\n", i, j, rc);
14711 /***********************/
14712 /* FP RX MBUF DMA MAPS */
14713 /***********************/
14715 /* create a dma tag for the rx mbufs */
14716 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */
14718 0, /* boundary limit */
14719 BUS_SPACE_MAXADDR, /* restricted low */
14720 BUS_SPACE_MAXADDR, /* restricted hi */
14721 NULL, /* addr filter() */
14722 NULL, /* addr filter() arg */
14723 MJUM9BYTES, /* max map size */
14724 1, /* num discontinuous */
14725 MJUM9BYTES, /* max seg size */
14728 NULL, /* lock() arg */
14729 &fp->rx_mbuf_tag); /* returned dma tag */
14731 /* XXX unwind and free previous fastpath allocations */
14732 BLOGE(sc, "Failed to create dma tag for "
14733 "'fp %d rx mbufs' (%d)\n", i, rc);
14737 /* create dma maps for each of the rx mbuf clusters */
14738 for (j = 0; j < RX_BD_TOTAL; j++) {
14739 if (bus_dmamap_create(fp->rx_mbuf_tag,
14741 &fp->rx_mbuf_chain[j].m_map)) {
14742 /* XXX unwind and free previous fastpath allocations */
14743 BLOGE(sc, "Failed to create dma map for "
14744 "'fp %d rx mbuf %d' (%d)\n", i, j, rc);
14749 /* create dma map for the spare rx mbuf cluster */
14750 if (bus_dmamap_create(fp->rx_mbuf_tag,
14752 &fp->rx_mbuf_spare_map)) {
14753 /* XXX unwind and free previous fastpath allocations */
14754 BLOGE(sc, "Failed to create dma map for "
14755 "'fp %d spare rx mbuf' (%d)\n", i, rc);
14759 /***************************/
14760 /* FP RX SGE MBUF DMA MAPS */
14761 /***************************/
14763 /* create a dma tag for the rx sge mbufs */
14764 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */
14766 0, /* boundary limit */
14767 BUS_SPACE_MAXADDR, /* restricted low */
14768 BUS_SPACE_MAXADDR, /* restricted hi */
14769 NULL, /* addr filter() */
14770 NULL, /* addr filter() arg */
14771 BCM_PAGE_SIZE, /* max map size */
14772 1, /* num discontinuous */
14773 BCM_PAGE_SIZE, /* max seg size */
14776 NULL, /* lock() arg */
14777 &fp->rx_sge_mbuf_tag); /* returned dma tag */
14779 /* XXX unwind and free previous fastpath allocations */
14780 BLOGE(sc, "Failed to create dma tag for "
14781 "'fp %d rx sge mbufs' (%d)\n", i, rc);
14785 /* create dma maps for the rx sge mbuf clusters */
14786 for (j = 0; j < RX_SGE_TOTAL; j++) {
14787 if (bus_dmamap_create(fp->rx_sge_mbuf_tag,
14789 &fp->rx_sge_mbuf_chain[j].m_map)) {
14790 /* XXX unwind and free previous fastpath allocations */
14791 BLOGE(sc, "Failed to create dma map for "
14792 "'fp %d rx sge mbuf %d' (%d)\n", i, j, rc);
14797 /* create dma map for the spare rx sge mbuf cluster */
14798 if (bus_dmamap_create(fp->rx_sge_mbuf_tag,
14800 &fp->rx_sge_mbuf_spare_map)) {
14801 /* XXX unwind and free previous fastpath allocations */
14802 BLOGE(sc, "Failed to create dma map for "
14803 "'fp %d spare rx sge mbuf' (%d)\n", i, rc);
14807 /***************************/
14808 /* FP RX TPA MBUF DMA MAPS */
14809 /***************************/
14811 /* create dma maps for the rx tpa mbuf clusters */
14812 max_agg_queues = MAX_AGG_QS(sc);
14814 for (j = 0; j < max_agg_queues; j++) {
14815 if (bus_dmamap_create(fp->rx_mbuf_tag,
14817 &fp->rx_tpa_info[j].bd.m_map)) {
14818 /* XXX unwind and free previous fastpath allocations */
14819 BLOGE(sc, "Failed to create dma map for "
14820 "'fp %d rx tpa mbuf %d' (%d)\n", i, j, rc);
14825 /* create dma map for the spare rx tpa mbuf cluster */
14826 if (bus_dmamap_create(fp->rx_mbuf_tag,
14828 &fp->rx_tpa_info_mbuf_spare_map)) {
14829 /* XXX unwind and free previous fastpath allocations */
14830 BLOGE(sc, "Failed to create dma map for "
14831 "'fp %d spare rx tpa mbuf' (%d)\n", i, rc);
14835 bxe_init_sge_ring_bit_mask(fp);
14842 bxe_free_hsi_mem(struct bxe_softc *sc)
14844 struct bxe_fastpath *fp;
14845 int max_agg_queues;
14848 if (sc->parent_dma_tag == NULL) {
14849 return; /* assume nothing was allocated */
14852 for (i = 0; i < sc->num_queues; i++) {
14855 /*******************/
14856 /* FP STATUS BLOCK */
14857 /*******************/
14859 bxe_dma_free(sc, &fp->sb_dma);
14860 memset(&fp->status_block, 0, sizeof(fp->status_block));
14862 /******************/
14863 /* FP TX BD CHAIN */
14864 /******************/
14866 bxe_dma_free(sc, &fp->tx_dma);
14867 fp->tx_chain = NULL;
14869 /******************/
14870 /* FP RX BD CHAIN */
14871 /******************/
14873 bxe_dma_free(sc, &fp->rx_dma);
14874 fp->rx_chain = NULL;
14876 /*******************/
14877 /* FP RX RCQ CHAIN */
14878 /*******************/
14880 bxe_dma_free(sc, &fp->rcq_dma);
14881 fp->rcq_chain = NULL;
14883 /*******************/
14884 /* FP RX SGE CHAIN */
14885 /*******************/
14887 bxe_dma_free(sc, &fp->rx_sge_dma);
14888 fp->rx_sge_chain = NULL;
14890 /***********************/
14891 /* FP TX MBUF DMA MAPS */
14892 /***********************/
14894 if (fp->tx_mbuf_tag != NULL) {
14895 for (j = 0; j < TX_BD_TOTAL; j++) {
14896 if (fp->tx_mbuf_chain[j].m_map != NULL) {
14897 bus_dmamap_unload(fp->tx_mbuf_tag,
14898 fp->tx_mbuf_chain[j].m_map);
14899 bus_dmamap_destroy(fp->tx_mbuf_tag,
14900 fp->tx_mbuf_chain[j].m_map);
14904 bus_dma_tag_destroy(fp->tx_mbuf_tag);
14905 fp->tx_mbuf_tag = NULL;
14908 /***********************/
14909 /* FP RX MBUF DMA MAPS */
14910 /***********************/
14912 if (fp->rx_mbuf_tag != NULL) {
14913 for (j = 0; j < RX_BD_TOTAL; j++) {
14914 if (fp->rx_mbuf_chain[j].m_map != NULL) {
14915 bus_dmamap_unload(fp->rx_mbuf_tag,
14916 fp->rx_mbuf_chain[j].m_map);
14917 bus_dmamap_destroy(fp->rx_mbuf_tag,
14918 fp->rx_mbuf_chain[j].m_map);
14922 if (fp->rx_mbuf_spare_map != NULL) {
14923 bus_dmamap_unload(fp->rx_mbuf_tag, fp->rx_mbuf_spare_map);
14924 bus_dmamap_destroy(fp->rx_mbuf_tag, fp->rx_mbuf_spare_map);
14927 /***************************/
14928 /* FP RX TPA MBUF DMA MAPS */
14929 /***************************/
14931 max_agg_queues = MAX_AGG_QS(sc);
14933 for (j = 0; j < max_agg_queues; j++) {
14934 if (fp->rx_tpa_info[j].bd.m_map != NULL) {
14935 bus_dmamap_unload(fp->rx_mbuf_tag,
14936 fp->rx_tpa_info[j].bd.m_map);
14937 bus_dmamap_destroy(fp->rx_mbuf_tag,
14938 fp->rx_tpa_info[j].bd.m_map);
14942 if (fp->rx_tpa_info_mbuf_spare_map != NULL) {
14943 bus_dmamap_unload(fp->rx_mbuf_tag,
14944 fp->rx_tpa_info_mbuf_spare_map);
14945 bus_dmamap_destroy(fp->rx_mbuf_tag,
14946 fp->rx_tpa_info_mbuf_spare_map);
14949 bus_dma_tag_destroy(fp->rx_mbuf_tag);
14950 fp->rx_mbuf_tag = NULL;
14953 /***************************/
14954 /* FP RX SGE MBUF DMA MAPS */
14955 /***************************/
14957 if (fp->rx_sge_mbuf_tag != NULL) {
14958 for (j = 0; j < RX_SGE_TOTAL; j++) {
14959 if (fp->rx_sge_mbuf_chain[j].m_map != NULL) {
14960 bus_dmamap_unload(fp->rx_sge_mbuf_tag,
14961 fp->rx_sge_mbuf_chain[j].m_map);
14962 bus_dmamap_destroy(fp->rx_sge_mbuf_tag,
14963 fp->rx_sge_mbuf_chain[j].m_map);
14967 if (fp->rx_sge_mbuf_spare_map != NULL) {
14968 bus_dmamap_unload(fp->rx_sge_mbuf_tag,
14969 fp->rx_sge_mbuf_spare_map);
14970 bus_dmamap_destroy(fp->rx_sge_mbuf_tag,
14971 fp->rx_sge_mbuf_spare_map);
14974 bus_dma_tag_destroy(fp->rx_sge_mbuf_tag);
14975 fp->rx_sge_mbuf_tag = NULL;
14979 /***************************/
14980 /* FW DECOMPRESSION BUFFER */
14981 /***************************/
14983 bxe_dma_free(sc, &sc->gz_buf_dma);
14985 free(sc->gz_strm, M_DEVBUF);
14986 sc->gz_strm = NULL;
14988 /*******************/
14989 /* SLOW PATH QUEUE */
14990 /*******************/
14992 bxe_dma_free(sc, &sc->spq_dma);
14999 bxe_dma_free(sc, &sc->sp_dma);
15006 bxe_dma_free(sc, &sc->eq_dma);
15009 /************************/
15010 /* DEFAULT STATUS BLOCK */
15011 /************************/
15013 bxe_dma_free(sc, &sc->def_sb_dma);
15016 bus_dma_tag_destroy(sc->parent_dma_tag);
15017 sc->parent_dma_tag = NULL;
15021 * Previous driver DMAE transaction may have occurred when pre-boot stage
15022 * ended and boot began. This would invalidate the addresses of the
15023 * transaction, resulting in was-error bit set in the PCI causing all
15024 * hw-to-host PCIe transactions to timeout. If this happened we want to clear
15025 * the interrupt which detected this from the pglueb and the was-done bit
15028 bxe_prev_interrupted_dmae(struct bxe_softc *sc)
15032 if (!CHIP_IS_E1x(sc)) {
15033 val = REG_RD(sc, PGLUE_B_REG_PGLUE_B_INT_STS);
15034 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
15035 BLOGD(sc, DBG_LOAD,
15036 "Clearing 'was-error' bit that was set in pglueb");
15037 REG_WR(sc, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, 1 << SC_FUNC(sc));
15043 bxe_prev_mcp_done(struct bxe_softc *sc)
15045 uint32_t rc = bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE,
15046 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
15048 BLOGE(sc, "MCP response failure, aborting\n");
15055 static struct bxe_prev_list_node *
15056 bxe_prev_path_get_entry(struct bxe_softc *sc)
15058 struct bxe_prev_list_node *tmp;
15060 LIST_FOREACH(tmp, &bxe_prev_list, node) {
15061 if ((sc->pcie_bus == tmp->bus) &&
15062 (sc->pcie_device == tmp->slot) &&
15063 (SC_PATH(sc) == tmp->path)) {
15072 bxe_prev_is_path_marked(struct bxe_softc *sc)
15074 struct bxe_prev_list_node *tmp;
15077 mtx_lock(&bxe_prev_mtx);
15079 tmp = bxe_prev_path_get_entry(sc);
15082 BLOGD(sc, DBG_LOAD,
15083 "Path %d/%d/%d was marked by AER\n",
15084 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15087 BLOGD(sc, DBG_LOAD,
15088 "Path %d/%d/%d was already cleaned from previous drivers\n",
15089 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15093 mtx_unlock(&bxe_prev_mtx);
15099 bxe_prev_mark_path(struct bxe_softc *sc,
15100 uint8_t after_undi)
15102 struct bxe_prev_list_node *tmp;
15104 mtx_lock(&bxe_prev_mtx);
15106 /* Check whether the entry for this path already exists */
15107 tmp = bxe_prev_path_get_entry(sc);
15110 BLOGD(sc, DBG_LOAD,
15111 "Re-marking AER in path %d/%d/%d\n",
15112 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15114 BLOGD(sc, DBG_LOAD,
15115 "Removing AER indication from path %d/%d/%d\n",
15116 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15120 mtx_unlock(&bxe_prev_mtx);
15124 mtx_unlock(&bxe_prev_mtx);
15126 /* Create an entry for this path and add it */
15127 tmp = malloc(sizeof(struct bxe_prev_list_node), M_DEVBUF,
15128 (M_NOWAIT | M_ZERO));
15130 BLOGE(sc, "Failed to allocate 'bxe_prev_list_node'\n");
15134 tmp->bus = sc->pcie_bus;
15135 tmp->slot = sc->pcie_device;
15136 tmp->path = SC_PATH(sc);
15138 tmp->undi = after_undi ? (1 << SC_PORT(sc)) : 0;
15140 mtx_lock(&bxe_prev_mtx);
15142 BLOGD(sc, DBG_LOAD,
15143 "Marked path %d/%d/%d - finished previous unload\n",
15144 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15145 LIST_INSERT_HEAD(&bxe_prev_list, tmp, node);
15147 mtx_unlock(&bxe_prev_mtx);
15153 bxe_do_flr(struct bxe_softc *sc)
15157 /* only E2 and onwards support FLR */
15158 if (CHIP_IS_E1x(sc)) {
15159 BLOGD(sc, DBG_LOAD, "FLR not supported in E1/E1H\n");
15163 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
15164 if (sc->devinfo.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
15165 BLOGD(sc, DBG_LOAD, "FLR not supported by BC_VER: 0x%08x\n",
15166 sc->devinfo.bc_ver);
15170 /* Wait for Transaction Pending bit clean */
15171 for (i = 0; i < 4; i++) {
15173 DELAY(((1 << (i - 1)) * 100) * 1000);
15176 if (!bxe_is_pcie_pending(sc)) {
15181 BLOGE(sc, "PCIE transaction is not cleared, "
15182 "proceeding with reset anyway\n");
15186 BLOGD(sc, DBG_LOAD, "Initiating FLR\n");
15187 bxe_fw_command(sc, DRV_MSG_CODE_INITIATE_FLR, 0);
15192 struct bxe_mac_vals {
15193 uint32_t xmac_addr;
15195 uint32_t emac_addr;
15197 uint32_t umac_addr;
15199 uint32_t bmac_addr;
15200 uint32_t bmac_val[2];
15204 bxe_prev_unload_close_mac(struct bxe_softc *sc,
15205 struct bxe_mac_vals *vals)
15207 uint32_t val, base_addr, offset, mask, reset_reg;
15208 uint8_t mac_stopped = FALSE;
15209 uint8_t port = SC_PORT(sc);
15210 uint32_t wb_data[2];
15212 /* reset addresses as they also mark which values were changed */
15213 vals->bmac_addr = 0;
15214 vals->umac_addr = 0;
15215 vals->xmac_addr = 0;
15216 vals->emac_addr = 0;
15218 reset_reg = REG_RD(sc, MISC_REG_RESET_REG_2);
15220 if (!CHIP_IS_E3(sc)) {
15221 val = REG_RD(sc, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
15222 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
15223 if ((mask & reset_reg) && val) {
15224 BLOGD(sc, DBG_LOAD, "Disable BMAC Rx\n");
15225 base_addr = SC_PORT(sc) ? NIG_REG_INGRESS_BMAC1_MEM
15226 : NIG_REG_INGRESS_BMAC0_MEM;
15227 offset = CHIP_IS_E2(sc) ? BIGMAC2_REGISTER_BMAC_CONTROL
15228 : BIGMAC_REGISTER_BMAC_CONTROL;
15231 * use rd/wr since we cannot use dmae. This is safe
15232 * since MCP won't access the bus due to the request
15233 * to unload, and no function on the path can be
15234 * loaded at this time.
15236 wb_data[0] = REG_RD(sc, base_addr + offset);
15237 wb_data[1] = REG_RD(sc, base_addr + offset + 0x4);
15238 vals->bmac_addr = base_addr + offset;
15239 vals->bmac_val[0] = wb_data[0];
15240 vals->bmac_val[1] = wb_data[1];
15241 wb_data[0] &= ~ELINK_BMAC_CONTROL_RX_ENABLE;
15242 REG_WR(sc, vals->bmac_addr, wb_data[0]);
15243 REG_WR(sc, vals->bmac_addr + 0x4, wb_data[1]);
15246 BLOGD(sc, DBG_LOAD, "Disable EMAC Rx\n");
15247 vals->emac_addr = NIG_REG_NIG_EMAC0_EN + SC_PORT(sc)*4;
15248 vals->emac_val = REG_RD(sc, vals->emac_addr);
15249 REG_WR(sc, vals->emac_addr, 0);
15250 mac_stopped = TRUE;
15252 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
15253 BLOGD(sc, DBG_LOAD, "Disable XMAC Rx\n");
15254 base_addr = SC_PORT(sc) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
15255 val = REG_RD(sc, base_addr + XMAC_REG_PFC_CTRL_HI);
15256 REG_WR(sc, base_addr + XMAC_REG_PFC_CTRL_HI, val & ~(1 << 1));
15257 REG_WR(sc, base_addr + XMAC_REG_PFC_CTRL_HI, val | (1 << 1));
15258 vals->xmac_addr = base_addr + XMAC_REG_CTRL;
15259 vals->xmac_val = REG_RD(sc, vals->xmac_addr);
15260 REG_WR(sc, vals->xmac_addr, 0);
15261 mac_stopped = TRUE;
15264 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
15265 if (mask & reset_reg) {
15266 BLOGD(sc, DBG_LOAD, "Disable UMAC Rx\n");
15267 base_addr = SC_PORT(sc) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
15268 vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
15269 vals->umac_val = REG_RD(sc, vals->umac_addr);
15270 REG_WR(sc, vals->umac_addr, 0);
15271 mac_stopped = TRUE;
15280 #define BXE_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
15281 #define BXE_PREV_UNDI_RCQ(val) ((val) & 0xffff)
15282 #define BXE_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
15283 #define BXE_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
15286 bxe_prev_unload_undi_inc(struct bxe_softc *sc,
15291 uint32_t tmp_reg = REG_RD(sc, BXE_PREV_UNDI_PROD_ADDR(port));
15293 rcq = BXE_PREV_UNDI_RCQ(tmp_reg) + inc;
15294 bd = BXE_PREV_UNDI_BD(tmp_reg) + inc;
15296 tmp_reg = BXE_PREV_UNDI_PROD(rcq, bd);
15297 REG_WR(sc, BXE_PREV_UNDI_PROD_ADDR(port), tmp_reg);
15299 BLOGD(sc, DBG_LOAD,
15300 "UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
15305 bxe_prev_unload_common(struct bxe_softc *sc)
15307 uint32_t reset_reg, tmp_reg = 0, rc;
15308 uint8_t prev_undi = FALSE;
15309 struct bxe_mac_vals mac_vals;
15310 uint32_t timer_count = 1000;
15314 * It is possible a previous function received 'common' answer,
15315 * but hasn't loaded yet, therefore creating a scenario of
15316 * multiple functions receiving 'common' on the same path.
15318 BLOGD(sc, DBG_LOAD, "Common unload Flow\n");
15320 memset(&mac_vals, 0, sizeof(mac_vals));
15322 if (bxe_prev_is_path_marked(sc)) {
15323 return (bxe_prev_mcp_done(sc));
15326 reset_reg = REG_RD(sc, MISC_REG_RESET_REG_1);
15328 /* Reset should be performed after BRB is emptied */
15329 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
15330 /* Close the MAC Rx to prevent BRB from filling up */
15331 bxe_prev_unload_close_mac(sc, &mac_vals);
15333 /* close LLH filters towards the BRB */
15334 elink_set_rx_filter(&sc->link_params, 0);
15337 * Check if the UNDI driver was previously loaded.
15338 * UNDI driver initializes CID offset for normal bell to 0x7
15340 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
15341 tmp_reg = REG_RD(sc, DORQ_REG_NORM_CID_OFST);
15342 if (tmp_reg == 0x7) {
15343 BLOGD(sc, DBG_LOAD, "UNDI previously loaded\n");
15345 /* clear the UNDI indication */
15346 REG_WR(sc, DORQ_REG_NORM_CID_OFST, 0);
15347 /* clear possible idle check errors */
15348 REG_RD(sc, NIG_REG_NIG_INT_STS_CLR_0);
15352 /* wait until BRB is empty */
15353 tmp_reg = REG_RD(sc, BRB1_REG_NUM_OF_FULL_BLOCKS);
15354 while (timer_count) {
15355 prev_brb = tmp_reg;
15357 tmp_reg = REG_RD(sc, BRB1_REG_NUM_OF_FULL_BLOCKS);
15362 BLOGD(sc, DBG_LOAD, "BRB still has 0x%08x\n", tmp_reg);
15364 /* reset timer as long as BRB actually gets emptied */
15365 if (prev_brb > tmp_reg) {
15366 timer_count = 1000;
15371 /* If UNDI resides in memory, manually increment it */
15373 bxe_prev_unload_undi_inc(sc, SC_PORT(sc), 1);
15379 if (!timer_count) {
15380 BLOGE(sc, "Failed to empty BRB\n");
15384 /* No packets are in the pipeline, path is ready for reset */
15385 bxe_reset_common(sc);
15387 if (mac_vals.xmac_addr) {
15388 REG_WR(sc, mac_vals.xmac_addr, mac_vals.xmac_val);
15390 if (mac_vals.umac_addr) {
15391 REG_WR(sc, mac_vals.umac_addr, mac_vals.umac_val);
15393 if (mac_vals.emac_addr) {
15394 REG_WR(sc, mac_vals.emac_addr, mac_vals.emac_val);
15396 if (mac_vals.bmac_addr) {
15397 REG_WR(sc, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
15398 REG_WR(sc, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
15401 rc = bxe_prev_mark_path(sc, prev_undi);
15403 bxe_prev_mcp_done(sc);
15407 return (bxe_prev_mcp_done(sc));
15411 bxe_prev_unload_uncommon(struct bxe_softc *sc)
15415 BLOGD(sc, DBG_LOAD, "Uncommon unload Flow\n");
15417 /* Test if previous unload process was already finished for this path */
15418 if (bxe_prev_is_path_marked(sc)) {
15419 return (bxe_prev_mcp_done(sc));
15422 BLOGD(sc, DBG_LOAD, "Path is unmarked\n");
15425 * If function has FLR capabilities, and existing FW version matches
15426 * the one required, then FLR will be sufficient to clean any residue
15427 * left by previous driver
15429 rc = bxe_nic_load_analyze_req(sc, FW_MSG_CODE_DRV_LOAD_FUNCTION);
15431 /* fw version is good */
15432 BLOGD(sc, DBG_LOAD, "FW version matches our own, attempting FLR\n");
15433 rc = bxe_do_flr(sc);
15437 /* FLR was performed */
15438 BLOGD(sc, DBG_LOAD, "FLR successful\n");
15442 BLOGD(sc, DBG_LOAD, "Could not FLR\n");
15444 /* Close the MCP request, return failure*/
15445 rc = bxe_prev_mcp_done(sc);
15447 rc = BXE_PREV_WAIT_NEEDED;
15454 bxe_prev_unload(struct bxe_softc *sc)
15456 int time_counter = 10;
15457 uint32_t fw, hw_lock_reg, hw_lock_val;
15461 * Clear HW from errors which may have resulted from an interrupted
15462 * DMAE transaction.
15464 bxe_prev_interrupted_dmae(sc);
15466 /* Release previously held locks */
15468 (SC_FUNC(sc) <= 5) ?
15469 (MISC_REG_DRIVER_CONTROL_1 + SC_FUNC(sc) * 8) :
15470 (MISC_REG_DRIVER_CONTROL_7 + (SC_FUNC(sc) - 6) * 8);
15472 hw_lock_val = (REG_RD(sc, hw_lock_reg));
15474 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
15475 BLOGD(sc, DBG_LOAD, "Releasing previously held NVRAM lock\n");
15476 REG_WR(sc, MCP_REG_MCPR_NVM_SW_ARB,
15477 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << SC_PORT(sc)));
15479 BLOGD(sc, DBG_LOAD, "Releasing previously held HW lock\n");
15480 REG_WR(sc, hw_lock_reg, 0xffffffff);
15482 BLOGD(sc, DBG_LOAD, "No need to release HW/NVRAM locks\n");
15485 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(sc, MCP_REG_MCPR_ACCESS_LOCK)) {
15486 BLOGD(sc, DBG_LOAD, "Releasing previously held ALR\n");
15487 REG_WR(sc, MCP_REG_MCPR_ACCESS_LOCK, 0);
15491 /* Lock MCP using an unload request */
15492 fw = bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
15494 BLOGE(sc, "MCP response failure, aborting\n");
15499 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
15500 rc = bxe_prev_unload_common(sc);
15504 /* non-common reply from MCP night require looping */
15505 rc = bxe_prev_unload_uncommon(sc);
15506 if (rc != BXE_PREV_WAIT_NEEDED) {
15511 } while (--time_counter);
15513 if (!time_counter || rc) {
15514 BLOGE(sc, "Failed to unload previous driver!"
15515 " time_counter %d rc %d\n", time_counter, rc);
15523 bxe_dcbx_set_state(struct bxe_softc *sc,
15525 uint32_t dcbx_enabled)
15527 if (!CHIP_IS_E1x(sc)) {
15528 sc->dcb_state = dcb_on;
15529 sc->dcbx_enabled = dcbx_enabled;
15531 sc->dcb_state = FALSE;
15532 sc->dcbx_enabled = BXE_DCBX_ENABLED_INVALID;
15534 BLOGD(sc, DBG_LOAD,
15535 "DCB state [%s:%s]\n",
15536 dcb_on ? "ON" : "OFF",
15537 (dcbx_enabled == BXE_DCBX_ENABLED_OFF) ? "user-mode" :
15538 (dcbx_enabled == BXE_DCBX_ENABLED_ON_NEG_OFF) ? "on-chip static" :
15539 (dcbx_enabled == BXE_DCBX_ENABLED_ON_NEG_ON) ?
15540 "on-chip with negotiation" : "invalid");
15543 /* must be called after sriov-enable */
15545 bxe_set_qm_cid_count(struct bxe_softc *sc)
15547 int cid_count = BXE_L2_MAX_CID(sc);
15549 if (IS_SRIOV(sc)) {
15550 cid_count += BXE_VF_CIDS;
15553 if (CNIC_SUPPORT(sc)) {
15554 cid_count += CNIC_CID_MAX;
15557 return (roundup(cid_count, QM_CID_ROUND));
15561 bxe_init_multi_cos(struct bxe_softc *sc)
15565 uint32_t pri_map = 0; /* XXX change to user config */
15567 for (pri = 0; pri < BXE_MAX_PRIORITY; pri++) {
15568 cos = ((pri_map & (0xf << (pri * 4))) >> (pri * 4));
15569 if (cos < sc->max_cos) {
15570 sc->prio_to_cos[pri] = cos;
15572 BLOGW(sc, "Invalid COS %d for priority %d "
15573 "(max COS is %d), setting to 0\n",
15574 cos, pri, (sc->max_cos - 1));
15575 sc->prio_to_cos[pri] = 0;
15581 bxe_sysctl_state(SYSCTL_HANDLER_ARGS)
15583 struct bxe_softc *sc;
15587 error = sysctl_handle_int(oidp, &result, 0, req);
15589 if (error || !req->newptr) {
15595 sc = (struct bxe_softc *)arg1;
15597 BLOGI(sc, "... dumping driver state ...\n");
15598 temp = SHMEM2_RD(sc, temperature_in_half_celsius);
15599 BLOGI(sc, "\t Device Temperature = %d Celsius\n", (temp/2));
15606 bxe_sysctl_eth_stat(SYSCTL_HANDLER_ARGS)
15608 struct bxe_softc *sc = (struct bxe_softc *)arg1;
15609 uint32_t *eth_stats = (uint32_t *)&sc->eth_stats;
15611 uint64_t value = 0;
15612 int index = (int)arg2;
15614 if (index >= BXE_NUM_ETH_STATS) {
15615 BLOGE(sc, "bxe_eth_stats index out of range (%d)\n", index);
15619 offset = (eth_stats + bxe_eth_stats_arr[index].offset);
15621 switch (bxe_eth_stats_arr[index].size) {
15623 value = (uint64_t)*offset;
15626 value = HILO_U64(*offset, *(offset + 1));
15629 BLOGE(sc, "Invalid bxe_eth_stats size (index=%d size=%d)\n",
15630 index, bxe_eth_stats_arr[index].size);
15634 return (sysctl_handle_64(oidp, &value, 0, req));
15638 bxe_sysctl_eth_q_stat(SYSCTL_HANDLER_ARGS)
15640 struct bxe_softc *sc = (struct bxe_softc *)arg1;
15641 uint32_t *eth_stats;
15643 uint64_t value = 0;
15644 uint32_t q_stat = (uint32_t)arg2;
15645 uint32_t fp_index = ((q_stat >> 16) & 0xffff);
15646 uint32_t index = (q_stat & 0xffff);
15648 eth_stats = (uint32_t *)&sc->fp[fp_index].eth_q_stats;
15650 if (index >= BXE_NUM_ETH_Q_STATS) {
15651 BLOGE(sc, "bxe_eth_q_stats index out of range (%d)\n", index);
15655 offset = (eth_stats + bxe_eth_q_stats_arr[index].offset);
15657 switch (bxe_eth_q_stats_arr[index].size) {
15659 value = (uint64_t)*offset;
15662 value = HILO_U64(*offset, *(offset + 1));
15665 BLOGE(sc, "Invalid bxe_eth_q_stats size (index=%d size=%d)\n",
15666 index, bxe_eth_q_stats_arr[index].size);
15670 return (sysctl_handle_64(oidp, &value, 0, req));
15673 static void bxe_force_link_reset(struct bxe_softc *sc)
15676 bxe_acquire_phy_lock(sc);
15677 elink_link_reset(&sc->link_params, &sc->link_vars, 1);
15678 bxe_release_phy_lock(sc);
15682 bxe_sysctl_pauseparam(SYSCTL_HANDLER_ARGS)
15684 struct bxe_softc *sc = (struct bxe_softc *)arg1;;
15685 uint32_t cfg_idx = bxe_get_link_cfg_idx(sc);
15691 error = sysctl_handle_int(oidp, &sc->bxe_pause_param, 0, req);
15693 if (error || !req->newptr) {
15696 if ((sc->bxe_pause_param < 0) || (sc->bxe_pause_param > 8)) {
15697 BLOGW(sc, "invalid pause param (%d) - use intergers between 1 & 8\n",sc->bxe_pause_param);
15698 sc->bxe_pause_param = 8;
15701 result = (sc->bxe_pause_param << PORT_FEATURE_FLOW_CONTROL_SHIFT);
15704 if((result & 0x400) && !(sc->port.supported[cfg_idx] & ELINK_SUPPORTED_Autoneg)) {
15705 BLOGW(sc, "Does not support Autoneg pause_param %d\n", sc->bxe_pause_param);
15711 sc->link_params.req_flow_ctrl[cfg_idx] = ELINK_FLOW_CTRL_AUTO;
15712 if(result & ELINK_FLOW_CTRL_RX)
15713 sc->link_params.req_flow_ctrl[cfg_idx] |= ELINK_FLOW_CTRL_RX;
15715 if(result & ELINK_FLOW_CTRL_TX)
15716 sc->link_params.req_flow_ctrl[cfg_idx] |= ELINK_FLOW_CTRL_TX;
15717 if(sc->link_params.req_flow_ctrl[cfg_idx] == ELINK_FLOW_CTRL_AUTO)
15718 sc->link_params.req_flow_ctrl[cfg_idx] = ELINK_FLOW_CTRL_NONE;
15720 if(result & 0x400) {
15721 if (sc->link_params.req_line_speed[cfg_idx] == ELINK_SPEED_AUTO_NEG) {
15722 sc->link_params.req_flow_ctrl[cfg_idx] =
15723 ELINK_FLOW_CTRL_AUTO;
15725 sc->link_params.req_fc_auto_adv = 0;
15726 if (result & ELINK_FLOW_CTRL_RX)
15727 sc->link_params.req_fc_auto_adv |= ELINK_FLOW_CTRL_RX;
15729 if (result & ELINK_FLOW_CTRL_TX)
15730 sc->link_params.req_fc_auto_adv |= ELINK_FLOW_CTRL_TX;
15731 if (!sc->link_params.req_fc_auto_adv)
15732 sc->link_params.req_fc_auto_adv |= ELINK_FLOW_CTRL_NONE;
15735 if (sc->link_vars.link_up) {
15736 bxe_stats_handle(sc, STATS_EVENT_STOP);
15738 if (sc->ifnet->if_drv_flags & IFF_DRV_RUNNING) {
15739 bxe_force_link_reset(sc);
15740 bxe_acquire_phy_lock(sc);
15742 rc = elink_phy_init(&sc->link_params, &sc->link_vars);
15744 bxe_release_phy_lock(sc);
15746 bxe_calc_fc_adv(sc);
15754 bxe_add_sysctls(struct bxe_softc *sc)
15756 struct sysctl_ctx_list *ctx;
15757 struct sysctl_oid_list *children;
15758 struct sysctl_oid *queue_top, *queue;
15759 struct sysctl_oid_list *queue_top_children, *queue_children;
15760 char queue_num_buf[32];
15764 ctx = device_get_sysctl_ctx(sc->dev);
15765 children = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev));
15767 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "version",
15768 CTLFLAG_RD, BXE_DRIVER_VERSION, 0,
15771 snprintf(sc->fw_ver_str, sizeof(sc->fw_ver_str), "%d.%d.%d.%d",
15772 BCM_5710_FW_MAJOR_VERSION,
15773 BCM_5710_FW_MINOR_VERSION,
15774 BCM_5710_FW_REVISION_VERSION,
15775 BCM_5710_FW_ENGINEERING_VERSION);
15777 snprintf(sc->mf_mode_str, sizeof(sc->mf_mode_str), "%s",
15778 ((sc->devinfo.mf_info.mf_mode == SINGLE_FUNCTION) ? "Single" :
15779 (sc->devinfo.mf_info.mf_mode == MULTI_FUNCTION_SD) ? "MF-SD" :
15780 (sc->devinfo.mf_info.mf_mode == MULTI_FUNCTION_SI) ? "MF-SI" :
15781 (sc->devinfo.mf_info.mf_mode == MULTI_FUNCTION_AFEX) ? "MF-AFEX" :
15783 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "mf_vnics",
15784 CTLFLAG_RD, &sc->devinfo.mf_info.vnics_per_port, 0,
15785 "multifunction vnics per port");
15787 snprintf(sc->pci_link_str, sizeof(sc->pci_link_str), "%s x%d",
15788 ((sc->devinfo.pcie_link_speed == 1) ? "2.5GT/s" :
15789 (sc->devinfo.pcie_link_speed == 2) ? "5.0GT/s" :
15790 (sc->devinfo.pcie_link_speed == 4) ? "8.0GT/s" :
15792 sc->devinfo.pcie_link_width);
15794 sc->debug = bxe_debug;
15796 #if __FreeBSD_version >= 900000
15797 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "bc_version",
15798 CTLFLAG_RD, sc->devinfo.bc_ver_str, 0,
15799 "bootcode version");
15800 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "fw_version",
15801 CTLFLAG_RD, sc->fw_ver_str, 0,
15802 "firmware version");
15803 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "mf_mode",
15804 CTLFLAG_RD, sc->mf_mode_str, 0,
15805 "multifunction mode");
15806 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "mac_addr",
15807 CTLFLAG_RD, sc->mac_addr_str, 0,
15809 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "pci_link",
15810 CTLFLAG_RD, &sc->pci_link_str, 0,
15811 "pci link status");
15812 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "debug",
15813 CTLFLAG_RW, &sc->debug, 0,
15814 "debug logging mode");
15816 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "bc_version",
15817 CTLFLAG_RD, &sc->devinfo.bc_ver_str, 0,
15818 "bootcode version");
15819 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "fw_version",
15820 CTLFLAG_RD, &sc->fw_ver_str, 0,
15821 "firmware version");
15822 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "mf_mode",
15823 CTLFLAG_RD, &sc->mf_mode_str, 0,
15824 "multifunction mode");
15825 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "mac_addr",
15826 CTLFLAG_RD, &sc->mac_addr_str, 0,
15828 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "pci_link",
15829 CTLFLAG_RD, &sc->pci_link_str, 0,
15830 "pci link status");
15831 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "debug",
15832 CTLFLAG_RW, &sc->debug, 0,
15833 "debug logging mode");
15834 #endif /* #if __FreeBSD_version >= 900000 */
15836 sc->trigger_grcdump = 0;
15837 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "trigger_grcdump",
15838 CTLFLAG_RW, &sc->trigger_grcdump, 0,
15839 "trigger grcdump should be invoked"
15840 " before collecting grcdump");
15842 sc->grcdump_started = 0;
15843 sc->grcdump_done = 0;
15844 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "grcdump_done",
15845 CTLFLAG_RD, &sc->grcdump_done, 0,
15846 "set by driver when grcdump is done");
15848 sc->rx_budget = bxe_rx_budget;
15849 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "rx_budget",
15850 CTLFLAG_RW, &sc->rx_budget, 0,
15851 "rx processing budget");
15853 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pause_param",
15854 CTLTYPE_UINT | CTLFLAG_RW, sc, 0,
15855 bxe_sysctl_pauseparam, "IU",
15856 "need pause frames- DEF:0/TX:1/RX:2/BOTH:3/AUTO:4/AUTOTX:5/AUTORX:6/AUTORXTX:7/NONE:8");
15859 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "state",
15860 CTLTYPE_UINT | CTLFLAG_RW, sc, 0,
15861 bxe_sysctl_state, "IU", "dump driver state");
15863 for (i = 0; i < BXE_NUM_ETH_STATS; i++) {
15864 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
15865 bxe_eth_stats_arr[i].string,
15866 CTLTYPE_U64 | CTLFLAG_RD, sc, i,
15867 bxe_sysctl_eth_stat, "LU",
15868 bxe_eth_stats_arr[i].string);
15871 /* add a new parent node for all queues "dev.bxe.#.queue" */
15872 queue_top = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "queue",
15873 CTLFLAG_RD, NULL, "queue");
15874 queue_top_children = SYSCTL_CHILDREN(queue_top);
15876 for (i = 0; i < sc->num_queues; i++) {
15877 /* add a new parent node for a single queue "dev.bxe.#.queue.#" */
15878 snprintf(queue_num_buf, sizeof(queue_num_buf), "%d", i);
15879 queue = SYSCTL_ADD_NODE(ctx, queue_top_children, OID_AUTO,
15880 queue_num_buf, CTLFLAG_RD, NULL,
15882 queue_children = SYSCTL_CHILDREN(queue);
15884 for (j = 0; j < BXE_NUM_ETH_Q_STATS; j++) {
15885 q_stat = ((i << 16) | j);
15886 SYSCTL_ADD_PROC(ctx, queue_children, OID_AUTO,
15887 bxe_eth_q_stats_arr[j].string,
15888 CTLTYPE_U64 | CTLFLAG_RD, sc, q_stat,
15889 bxe_sysctl_eth_q_stat, "LU",
15890 bxe_eth_q_stats_arr[j].string);
15896 bxe_alloc_buf_rings(struct bxe_softc *sc)
15898 #if __FreeBSD_version >= 800000
15901 struct bxe_fastpath *fp;
15903 for (i = 0; i < sc->num_queues; i++) {
15907 fp->tx_br = buf_ring_alloc(BXE_BR_SIZE, M_DEVBUF,
15908 M_NOWAIT, &fp->tx_mtx);
15909 if (fp->tx_br == NULL)
15917 bxe_free_buf_rings(struct bxe_softc *sc)
15919 #if __FreeBSD_version >= 800000
15922 struct bxe_fastpath *fp;
15924 for (i = 0; i < sc->num_queues; i++) {
15929 buf_ring_free(fp->tx_br, M_DEVBUF);
15938 bxe_init_fp_mutexs(struct bxe_softc *sc)
15941 struct bxe_fastpath *fp;
15943 for (i = 0; i < sc->num_queues; i++) {
15947 snprintf(fp->tx_mtx_name, sizeof(fp->tx_mtx_name),
15948 "bxe%d_fp%d_tx_lock", sc->unit, i);
15949 mtx_init(&fp->tx_mtx, fp->tx_mtx_name, NULL, MTX_DEF);
15951 snprintf(fp->rx_mtx_name, sizeof(fp->rx_mtx_name),
15952 "bxe%d_fp%d_rx_lock", sc->unit, i);
15953 mtx_init(&fp->rx_mtx, fp->rx_mtx_name, NULL, MTX_DEF);
15958 bxe_destroy_fp_mutexs(struct bxe_softc *sc)
15961 struct bxe_fastpath *fp;
15963 for (i = 0; i < sc->num_queues; i++) {
15967 if (mtx_initialized(&fp->tx_mtx)) {
15968 mtx_destroy(&fp->tx_mtx);
15971 if (mtx_initialized(&fp->rx_mtx)) {
15972 mtx_destroy(&fp->rx_mtx);
15979 * Device attach function.
15981 * Allocates device resources, performs secondary chip identification, and
15982 * initializes driver instance variables. This function is called from driver
15983 * load after a successful probe.
15986 * 0 = Success, >0 = Failure
15989 bxe_attach(device_t dev)
15991 struct bxe_softc *sc;
15993 sc = device_get_softc(dev);
15995 BLOGD(sc, DBG_LOAD, "Starting attach...\n");
15997 sc->state = BXE_STATE_CLOSED;
16000 sc->unit = device_get_unit(dev);
16002 BLOGD(sc, DBG_LOAD, "softc = %p\n", sc);
16004 sc->pcie_bus = pci_get_bus(dev);
16005 sc->pcie_device = pci_get_slot(dev);
16006 sc->pcie_func = pci_get_function(dev);
16008 /* enable bus master capability */
16009 pci_enable_busmaster(dev);
16012 if (bxe_allocate_bars(sc) != 0) {
16016 /* initialize the mutexes */
16017 bxe_init_mutexes(sc);
16019 /* prepare the periodic callout */
16020 callout_init(&sc->periodic_callout, 0);
16022 /* prepare the chip taskqueue */
16023 sc->chip_tq_flags = CHIP_TQ_NONE;
16024 snprintf(sc->chip_tq_name, sizeof(sc->chip_tq_name),
16025 "bxe%d_chip_tq", sc->unit);
16026 TASK_INIT(&sc->chip_tq_task, 0, bxe_handle_chip_tq, sc);
16027 sc->chip_tq = taskqueue_create(sc->chip_tq_name, M_NOWAIT,
16028 taskqueue_thread_enqueue,
16030 taskqueue_start_threads(&sc->chip_tq, 1, PWAIT, /* lower priority */
16031 "%s", sc->chip_tq_name);
16033 /* get device info and set params */
16034 if (bxe_get_device_info(sc) != 0) {
16035 BLOGE(sc, "getting device info\n");
16036 bxe_deallocate_bars(sc);
16037 pci_disable_busmaster(dev);
16041 /* get final misc params */
16042 bxe_get_params(sc);
16044 /* set the default MTU (changed via ifconfig) */
16045 sc->mtu = ETHERMTU;
16047 bxe_set_modes_bitmap(sc);
16050 * If in AFEX mode and the function is configured for FCoE
16051 * then bail... no L2 allowed.
16054 /* get phy settings from shmem and 'and' against admin settings */
16055 bxe_get_phy_info(sc);
16057 /* initialize the FreeBSD ifnet interface */
16058 if (bxe_init_ifnet(sc) != 0) {
16059 bxe_release_mutexes(sc);
16060 bxe_deallocate_bars(sc);
16061 pci_disable_busmaster(dev);
16065 if (bxe_add_cdev(sc) != 0) {
16066 if (sc->ifnet != NULL) {
16067 ether_ifdetach(sc->ifnet);
16069 ifmedia_removeall(&sc->ifmedia);
16070 bxe_release_mutexes(sc);
16071 bxe_deallocate_bars(sc);
16072 pci_disable_busmaster(dev);
16076 /* allocate device interrupts */
16077 if (bxe_interrupt_alloc(sc) != 0) {
16079 if (sc->ifnet != NULL) {
16080 ether_ifdetach(sc->ifnet);
16082 ifmedia_removeall(&sc->ifmedia);
16083 bxe_release_mutexes(sc);
16084 bxe_deallocate_bars(sc);
16085 pci_disable_busmaster(dev);
16089 bxe_init_fp_mutexs(sc);
16091 if (bxe_alloc_buf_rings(sc) != 0) {
16092 bxe_free_buf_rings(sc);
16093 bxe_interrupt_free(sc);
16095 if (sc->ifnet != NULL) {
16096 ether_ifdetach(sc->ifnet);
16098 ifmedia_removeall(&sc->ifmedia);
16099 bxe_release_mutexes(sc);
16100 bxe_deallocate_bars(sc);
16101 pci_disable_busmaster(dev);
16106 if (bxe_alloc_ilt_mem(sc) != 0) {
16107 bxe_free_buf_rings(sc);
16108 bxe_interrupt_free(sc);
16110 if (sc->ifnet != NULL) {
16111 ether_ifdetach(sc->ifnet);
16113 ifmedia_removeall(&sc->ifmedia);
16114 bxe_release_mutexes(sc);
16115 bxe_deallocate_bars(sc);
16116 pci_disable_busmaster(dev);
16120 /* allocate the host hardware/software hsi structures */
16121 if (bxe_alloc_hsi_mem(sc) != 0) {
16122 bxe_free_ilt_mem(sc);
16123 bxe_free_buf_rings(sc);
16124 bxe_interrupt_free(sc);
16126 if (sc->ifnet != NULL) {
16127 ether_ifdetach(sc->ifnet);
16129 ifmedia_removeall(&sc->ifmedia);
16130 bxe_release_mutexes(sc);
16131 bxe_deallocate_bars(sc);
16132 pci_disable_busmaster(dev);
16136 /* need to reset chip if UNDI was active */
16137 if (IS_PF(sc) && !BXE_NOMCP(sc)) {
16140 (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_mb_header) &
16141 DRV_MSG_SEQ_NUMBER_MASK);
16142 BLOGD(sc, DBG_LOAD, "prev unload fw_seq 0x%04x\n", sc->fw_seq);
16143 bxe_prev_unload(sc);
16148 bxe_dcbx_set_state(sc, FALSE, BXE_DCBX_ENABLED_OFF);
16150 if (SHMEM2_HAS(sc, dcbx_lldp_params_offset) &&
16151 SHMEM2_HAS(sc, dcbx_lldp_dcbx_stat_offset) &&
16152 SHMEM2_RD(sc, dcbx_lldp_params_offset) &&
16153 SHMEM2_RD(sc, dcbx_lldp_dcbx_stat_offset)) {
16154 bxe_dcbx_set_state(sc, TRUE, BXE_DCBX_ENABLED_ON_NEG_ON);
16155 bxe_dcbx_init_params(sc);
16157 bxe_dcbx_set_state(sc, FALSE, BXE_DCBX_ENABLED_OFF);
16161 /* calculate qm_cid_count */
16162 sc->qm_cid_count = bxe_set_qm_cid_count(sc);
16163 BLOGD(sc, DBG_LOAD, "qm_cid_count=%d\n", sc->qm_cid_count);
16166 bxe_init_multi_cos(sc);
16168 bxe_add_sysctls(sc);
16174 * Device detach function.
16176 * Stops the controller, resets the controller, and releases resources.
16179 * 0 = Success, >0 = Failure
16182 bxe_detach(device_t dev)
16184 struct bxe_softc *sc;
16187 sc = device_get_softc(dev);
16189 BLOGD(sc, DBG_LOAD, "Starting detach...\n");
16192 if (ifp != NULL && ifp->if_vlantrunk != NULL) {
16193 BLOGE(sc, "Cannot detach while VLANs are in use.\n");
16199 /* stop the periodic callout */
16200 bxe_periodic_stop(sc);
16202 /* stop the chip taskqueue */
16203 atomic_store_rel_long(&sc->chip_tq_flags, CHIP_TQ_NONE);
16205 taskqueue_drain(sc->chip_tq, &sc->chip_tq_task);
16206 taskqueue_free(sc->chip_tq);
16207 sc->chip_tq = NULL;
16210 /* stop and reset the controller if it was open */
16211 if (sc->state != BXE_STATE_CLOSED) {
16213 bxe_nic_unload(sc, UNLOAD_CLOSE, TRUE);
16214 sc->state = BXE_STATE_DISABLED;
16215 BXE_CORE_UNLOCK(sc);
16218 /* release the network interface */
16220 ether_ifdetach(ifp);
16222 ifmedia_removeall(&sc->ifmedia);
16224 /* XXX do the following based on driver state... */
16226 /* free the host hardware/software hsi structures */
16227 bxe_free_hsi_mem(sc);
16230 bxe_free_ilt_mem(sc);
16232 bxe_free_buf_rings(sc);
16234 /* release the interrupts */
16235 bxe_interrupt_free(sc);
16237 /* Release the mutexes*/
16238 bxe_destroy_fp_mutexs(sc);
16239 bxe_release_mutexes(sc);
16242 /* Release the PCIe BAR mapped memory */
16243 bxe_deallocate_bars(sc);
16245 /* Release the FreeBSD interface. */
16246 if (sc->ifnet != NULL) {
16247 if_free(sc->ifnet);
16250 pci_disable_busmaster(dev);
16256 * Device shutdown function.
16258 * Stops and resets the controller.
16264 bxe_shutdown(device_t dev)
16266 struct bxe_softc *sc;
16268 sc = device_get_softc(dev);
16270 BLOGD(sc, DBG_LOAD, "Starting shutdown...\n");
16272 /* stop the periodic callout */
16273 bxe_periodic_stop(sc);
16276 bxe_nic_unload(sc, UNLOAD_NORMAL, FALSE);
16277 BXE_CORE_UNLOCK(sc);
16283 bxe_igu_ack_sb(struct bxe_softc *sc,
16290 uint32_t igu_addr = sc->igu_base_addr;
16291 igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
16292 bxe_igu_ack_sb_gen(sc, igu_sb_id, segment, index, op, update, igu_addr);
16296 bxe_igu_clear_sb_gen(struct bxe_softc *sc,
16301 uint32_t data, ctl, cnt = 100;
16302 uint32_t igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
16303 uint32_t igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
16304 uint32_t igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
16305 uint32_t sb_bit = 1 << (idu_sb_id%32);
16306 uint32_t func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
16307 uint32_t addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
16309 /* Not supported in BC mode */
16310 if (CHIP_INT_MODE_IS_BC(sc)) {
16314 data = ((IGU_USE_REGISTER_cstorm_type_0_sb_cleanup <<
16315 IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
16316 IGU_REGULAR_CLEANUP_SET |
16317 IGU_REGULAR_BCLEANUP);
16319 ctl = ((addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT) |
16320 (func_encode << IGU_CTRL_REG_FID_SHIFT) |
16321 (IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT));
16323 BLOGD(sc, DBG_LOAD, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
16324 data, igu_addr_data);
16325 REG_WR(sc, igu_addr_data, data);
16327 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle, 0, 0,
16328 BUS_SPACE_BARRIER_WRITE);
16331 BLOGD(sc, DBG_LOAD, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
16332 ctl, igu_addr_ctl);
16333 REG_WR(sc, igu_addr_ctl, ctl);
16335 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle, 0, 0,
16336 BUS_SPACE_BARRIER_WRITE);
16339 /* wait for clean up to finish */
16340 while (!(REG_RD(sc, igu_addr_ack) & sb_bit) && --cnt) {
16344 if (!(REG_RD(sc, igu_addr_ack) & sb_bit)) {
16345 BLOGD(sc, DBG_LOAD,
16346 "Unable to finish IGU cleanup: "
16347 "idu_sb_id %d offset %d bit %d (cnt %d)\n",
16348 idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
16353 bxe_igu_clear_sb(struct bxe_softc *sc,
16356 bxe_igu_clear_sb_gen(sc, SC_FUNC(sc), idu_sb_id, TRUE /*PF*/);
16365 /*******************/
16366 /* ECORE CALLBACKS */
16367 /*******************/
16370 bxe_reset_common(struct bxe_softc *sc)
16372 uint32_t val = 0x1400;
16375 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR), 0xd3ffff7f);
16377 if (CHIP_IS_E3(sc)) {
16378 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
16379 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
16382 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR), val);
16386 bxe_common_init_phy(struct bxe_softc *sc)
16388 uint32_t shmem_base[2];
16389 uint32_t shmem2_base[2];
16391 /* Avoid common init in case MFW supports LFA */
16392 if (SHMEM2_RD(sc, size) >
16393 (uint32_t)offsetof(struct shmem2_region,
16394 lfa_host_addr[SC_PORT(sc)])) {
16398 shmem_base[0] = sc->devinfo.shmem_base;
16399 shmem2_base[0] = sc->devinfo.shmem2_base;
16401 if (!CHIP_IS_E1x(sc)) {
16402 shmem_base[1] = SHMEM2_RD(sc, other_shmem_base_addr);
16403 shmem2_base[1] = SHMEM2_RD(sc, other_shmem2_base_addr);
16406 bxe_acquire_phy_lock(sc);
16407 elink_common_init_phy(sc, shmem_base, shmem2_base,
16408 sc->devinfo.chip_id, 0);
16409 bxe_release_phy_lock(sc);
16413 bxe_pf_disable(struct bxe_softc *sc)
16415 uint32_t val = REG_RD(sc, IGU_REG_PF_CONFIGURATION);
16417 val &= ~IGU_PF_CONF_FUNC_EN;
16419 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
16420 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
16421 REG_WR(sc, CFC_REG_WEAK_ENABLE_PF, 0);
16425 bxe_init_pxp(struct bxe_softc *sc)
16428 int r_order, w_order;
16430 devctl = bxe_pcie_capability_read(sc, PCIR_EXPRESS_DEVICE_CTL, 2);
16432 BLOGD(sc, DBG_LOAD, "read 0x%08x from devctl\n", devctl);
16434 w_order = ((devctl & PCIM_EXP_CTL_MAX_PAYLOAD) >> 5);
16436 if (sc->mrrs == -1) {
16437 r_order = ((devctl & PCIM_EXP_CTL_MAX_READ_REQUEST) >> 12);
16439 BLOGD(sc, DBG_LOAD, "forcing read order to %d\n", sc->mrrs);
16440 r_order = sc->mrrs;
16443 ecore_init_pxp_arb(sc, r_order, w_order);
16447 bxe_get_pretend_reg(struct bxe_softc *sc)
16449 uint32_t base = PXP2_REG_PGL_PRETEND_FUNC_F0;
16450 uint32_t stride = (PXP2_REG_PGL_PRETEND_FUNC_F1 - base);
16451 return (base + (SC_ABS_FUNC(sc)) * stride);
16455 * Called only on E1H or E2.
16456 * When pretending to be PF, the pretend value is the function number 0..7.
16457 * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
16461 bxe_pretend_func(struct bxe_softc *sc,
16462 uint16_t pretend_func_val)
16464 uint32_t pretend_reg;
16466 if (CHIP_IS_E1H(sc) && (pretend_func_val > E1H_FUNC_MAX)) {
16470 /* get my own pretend register */
16471 pretend_reg = bxe_get_pretend_reg(sc);
16472 REG_WR(sc, pretend_reg, pretend_func_val);
16473 REG_RD(sc, pretend_reg);
16478 bxe_iov_init_dmae(struct bxe_softc *sc)
16484 bxe_iov_init_dq(struct bxe_softc *sc)
16489 /* send a NIG loopback debug packet */
16491 bxe_lb_pckt(struct bxe_softc *sc)
16493 uint32_t wb_write[3];
16495 /* Ethernet source and destination addresses */
16496 wb_write[0] = 0x55555555;
16497 wb_write[1] = 0x55555555;
16498 wb_write[2] = 0x20; /* SOP */
16499 REG_WR_DMAE(sc, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
16501 /* NON-IP protocol */
16502 wb_write[0] = 0x09000000;
16503 wb_write[1] = 0x55555555;
16504 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
16505 REG_WR_DMAE(sc, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
16509 * Some of the internal memories are not directly readable from the driver.
16510 * To test them we send debug packets.
16513 bxe_int_mem_test(struct bxe_softc *sc)
16519 if (CHIP_REV_IS_FPGA(sc)) {
16521 } else if (CHIP_REV_IS_EMUL(sc)) {
16527 /* disable inputs of parser neighbor blocks */
16528 REG_WR(sc, TSDM_REG_ENABLE_IN1, 0x0);
16529 REG_WR(sc, TCM_REG_PRS_IFEN, 0x0);
16530 REG_WR(sc, CFC_REG_DEBUG0, 0x1);
16531 REG_WR(sc, NIG_REG_PRS_REQ_IN_EN, 0x0);
16533 /* write 0 to parser credits for CFC search request */
16534 REG_WR(sc, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
16536 /* send Ethernet packet */
16539 /* TODO do i reset NIG statistic? */
16540 /* Wait until NIG register shows 1 packet of size 0x10 */
16541 count = 1000 * factor;
16543 bxe_read_dmae(sc, NIG_REG_STAT2_BRB_OCTET, 2);
16544 val = *BXE_SP(sc, wb_data[0]);
16554 BLOGE(sc, "NIG timeout val=0x%x\n", val);
16558 /* wait until PRS register shows 1 packet */
16559 count = (1000 * factor);
16561 val = REG_RD(sc, PRS_REG_NUM_OF_PACKETS);
16571 BLOGE(sc, "PRS timeout val=0x%x\n", val);
16575 /* Reset and init BRB, PRS */
16576 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
16578 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
16580 ecore_init_block(sc, BLOCK_BRB1, PHASE_COMMON);
16581 ecore_init_block(sc, BLOCK_PRS, PHASE_COMMON);
16583 /* Disable inputs of parser neighbor blocks */
16584 REG_WR(sc, TSDM_REG_ENABLE_IN1, 0x0);
16585 REG_WR(sc, TCM_REG_PRS_IFEN, 0x0);
16586 REG_WR(sc, CFC_REG_DEBUG0, 0x1);
16587 REG_WR(sc, NIG_REG_PRS_REQ_IN_EN, 0x0);
16589 /* Write 0 to parser credits for CFC search request */
16590 REG_WR(sc, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
16592 /* send 10 Ethernet packets */
16593 for (i = 0; i < 10; i++) {
16597 /* Wait until NIG register shows 10+1 packets of size 11*0x10 = 0xb0 */
16598 count = (1000 * factor);
16600 bxe_read_dmae(sc, NIG_REG_STAT2_BRB_OCTET, 2);
16601 val = *BXE_SP(sc, wb_data[0]);
16611 BLOGE(sc, "NIG timeout val=0x%x\n", val);
16615 /* Wait until PRS register shows 2 packets */
16616 val = REG_RD(sc, PRS_REG_NUM_OF_PACKETS);
16618 BLOGE(sc, "PRS timeout val=0x%x\n", val);
16621 /* Write 1 to parser credits for CFC search request */
16622 REG_WR(sc, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
16624 /* Wait until PRS register shows 3 packets */
16625 DELAY(10000 * factor);
16627 /* Wait until NIG register shows 1 packet of size 0x10 */
16628 val = REG_RD(sc, PRS_REG_NUM_OF_PACKETS);
16630 BLOGE(sc, "PRS timeout val=0x%x\n", val);
16633 /* clear NIG EOP FIFO */
16634 for (i = 0; i < 11; i++) {
16635 REG_RD(sc, NIG_REG_INGRESS_EOP_LB_FIFO);
16638 val = REG_RD(sc, NIG_REG_INGRESS_EOP_LB_EMPTY);
16640 BLOGE(sc, "clear of NIG failed val=0x%x\n", val);
16644 /* Reset and init BRB, PRS, NIG */
16645 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
16647 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
16649 ecore_init_block(sc, BLOCK_BRB1, PHASE_COMMON);
16650 ecore_init_block(sc, BLOCK_PRS, PHASE_COMMON);
16651 if (!CNIC_SUPPORT(sc)) {
16653 REG_WR(sc, PRS_REG_NIC_MODE, 1);
16656 /* Enable inputs of parser neighbor blocks */
16657 REG_WR(sc, TSDM_REG_ENABLE_IN1, 0x7fffffff);
16658 REG_WR(sc, TCM_REG_PRS_IFEN, 0x1);
16659 REG_WR(sc, CFC_REG_DEBUG0, 0x0);
16660 REG_WR(sc, NIG_REG_PRS_REQ_IN_EN, 0x1);
16666 bxe_setup_fan_failure_detection(struct bxe_softc *sc)
16673 val = (SHMEM_RD(sc, dev_info.shared_hw_config.config2) &
16674 SHARED_HW_CFG_FAN_FAILURE_MASK);
16676 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED) {
16680 * The fan failure mechanism is usually related to the PHY type since
16681 * the power consumption of the board is affected by the PHY. Currently,
16682 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
16684 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE) {
16685 for (port = PORT_0; port < PORT_MAX; port++) {
16686 is_required |= elink_fan_failure_det_req(sc,
16687 sc->devinfo.shmem_base,
16688 sc->devinfo.shmem2_base,
16693 BLOGD(sc, DBG_LOAD, "fan detection setting: %d\n", is_required);
16695 if (is_required == 0) {
16699 /* Fan failure is indicated by SPIO 5 */
16700 bxe_set_spio(sc, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
16702 /* set to active low mode */
16703 val = REG_RD(sc, MISC_REG_SPIO_INT);
16704 val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
16705 REG_WR(sc, MISC_REG_SPIO_INT, val);
16707 /* enable interrupt to signal the IGU */
16708 val = REG_RD(sc, MISC_REG_SPIO_EVENT_EN);
16709 val |= MISC_SPIO_SPIO5;
16710 REG_WR(sc, MISC_REG_SPIO_EVENT_EN, val);
16714 bxe_enable_blocks_attention(struct bxe_softc *sc)
16718 REG_WR(sc, PXP_REG_PXP_INT_MASK_0, 0);
16719 if (!CHIP_IS_E1x(sc)) {
16720 REG_WR(sc, PXP_REG_PXP_INT_MASK_1, 0x40);
16722 REG_WR(sc, PXP_REG_PXP_INT_MASK_1, 0);
16724 REG_WR(sc, DORQ_REG_DORQ_INT_MASK, 0);
16725 REG_WR(sc, CFC_REG_CFC_INT_MASK, 0);
16727 * mask read length error interrupts in brb for parser
16728 * (parsing unit and 'checksum and crc' unit)
16729 * these errors are legal (PU reads fixed length and CAC can cause
16730 * read length error on truncated packets)
16732 REG_WR(sc, BRB1_REG_BRB1_INT_MASK, 0xFC00);
16733 REG_WR(sc, QM_REG_QM_INT_MASK, 0);
16734 REG_WR(sc, TM_REG_TM_INT_MASK, 0);
16735 REG_WR(sc, XSDM_REG_XSDM_INT_MASK_0, 0);
16736 REG_WR(sc, XSDM_REG_XSDM_INT_MASK_1, 0);
16737 REG_WR(sc, XCM_REG_XCM_INT_MASK, 0);
16738 /* REG_WR(sc, XSEM_REG_XSEM_INT_MASK_0, 0); */
16739 /* REG_WR(sc, XSEM_REG_XSEM_INT_MASK_1, 0); */
16740 REG_WR(sc, USDM_REG_USDM_INT_MASK_0, 0);
16741 REG_WR(sc, USDM_REG_USDM_INT_MASK_1, 0);
16742 REG_WR(sc, UCM_REG_UCM_INT_MASK, 0);
16743 /* REG_WR(sc, USEM_REG_USEM_INT_MASK_0, 0); */
16744 /* REG_WR(sc, USEM_REG_USEM_INT_MASK_1, 0); */
16745 REG_WR(sc, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
16746 REG_WR(sc, CSDM_REG_CSDM_INT_MASK_0, 0);
16747 REG_WR(sc, CSDM_REG_CSDM_INT_MASK_1, 0);
16748 REG_WR(sc, CCM_REG_CCM_INT_MASK, 0);
16749 /* REG_WR(sc, CSEM_REG_CSEM_INT_MASK_0, 0); */
16750 /* REG_WR(sc, CSEM_REG_CSEM_INT_MASK_1, 0); */
16752 val = (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
16753 PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
16754 PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN);
16755 if (!CHIP_IS_E1x(sc)) {
16756 val |= (PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
16757 PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED);
16759 REG_WR(sc, PXP2_REG_PXP2_INT_MASK_0, val);
16761 REG_WR(sc, TSDM_REG_TSDM_INT_MASK_0, 0);
16762 REG_WR(sc, TSDM_REG_TSDM_INT_MASK_1, 0);
16763 REG_WR(sc, TCM_REG_TCM_INT_MASK, 0);
16764 /* REG_WR(sc, TSEM_REG_TSEM_INT_MASK_0, 0); */
16766 if (!CHIP_IS_E1x(sc)) {
16767 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
16768 REG_WR(sc, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
16771 REG_WR(sc, CDU_REG_CDU_INT_MASK, 0);
16772 REG_WR(sc, DMAE_REG_DMAE_INT_MASK, 0);
16773 /* REG_WR(sc, MISC_REG_MISC_INT_MASK, 0); */
16774 REG_WR(sc, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
16778 * bxe_init_hw_common - initialize the HW at the COMMON phase.
16780 * @sc: driver handle
16783 bxe_init_hw_common(struct bxe_softc *sc)
16785 uint8_t abs_func_id;
16788 BLOGD(sc, DBG_LOAD, "starting common init for func %d\n",
16792 * take the RESET lock to protect undi_unload flow from accessing
16793 * registers while we are resetting the chip
16795 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
16797 bxe_reset_common(sc);
16799 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET), 0xffffffff);
16802 if (CHIP_IS_E3(sc)) {
16803 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
16804 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
16807 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET), val);
16809 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
16811 ecore_init_block(sc, BLOCK_MISC, PHASE_COMMON);
16812 BLOGD(sc, DBG_LOAD, "after misc block init\n");
16814 if (!CHIP_IS_E1x(sc)) {
16816 * 4-port mode or 2-port mode we need to turn off master-enable for
16817 * everyone. After that we turn it back on for self. So, we disregard
16818 * multi-function, and always disable all functions on the given path,
16819 * this means 0,2,4,6 for path 0 and 1,3,5,7 for path 1
16821 for (abs_func_id = SC_PATH(sc);
16822 abs_func_id < (E2_FUNC_MAX * 2);
16823 abs_func_id += 2) {
16824 if (abs_func_id == SC_ABS_FUNC(sc)) {
16825 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
16829 bxe_pretend_func(sc, abs_func_id);
16831 /* clear pf enable */
16832 bxe_pf_disable(sc);
16834 bxe_pretend_func(sc, SC_ABS_FUNC(sc));
16838 BLOGD(sc, DBG_LOAD, "after pf disable\n");
16840 ecore_init_block(sc, BLOCK_PXP, PHASE_COMMON);
16842 if (CHIP_IS_E1(sc)) {
16844 * enable HW interrupt from PXP on USDM overflow
16845 * bit 16 on INT_MASK_0
16847 REG_WR(sc, PXP_REG_PXP_INT_MASK_0, 0);
16850 ecore_init_block(sc, BLOCK_PXP2, PHASE_COMMON);
16853 #ifdef __BIG_ENDIAN
16854 REG_WR(sc, PXP2_REG_RQ_QM_ENDIAN_M, 1);
16855 REG_WR(sc, PXP2_REG_RQ_TM_ENDIAN_M, 1);
16856 REG_WR(sc, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
16857 REG_WR(sc, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
16858 REG_WR(sc, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
16859 /* make sure this value is 0 */
16860 REG_WR(sc, PXP2_REG_RQ_HC_ENDIAN_M, 0);
16862 //REG_WR(sc, PXP2_REG_RD_PBF_SWAP_MODE, 1);
16863 REG_WR(sc, PXP2_REG_RD_QM_SWAP_MODE, 1);
16864 REG_WR(sc, PXP2_REG_RD_TM_SWAP_MODE, 1);
16865 REG_WR(sc, PXP2_REG_RD_SRC_SWAP_MODE, 1);
16866 REG_WR(sc, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
16869 ecore_ilt_init_page_size(sc, INITOP_SET);
16871 if (CHIP_REV_IS_FPGA(sc) && CHIP_IS_E1H(sc)) {
16872 REG_WR(sc, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
16875 /* let the HW do it's magic... */
16878 /* finish PXP init */
16879 val = REG_RD(sc, PXP2_REG_RQ_CFG_DONE);
16881 BLOGE(sc, "PXP2 CFG failed PXP2_REG_RQ_CFG_DONE val = 0x%x\n",
16885 val = REG_RD(sc, PXP2_REG_RD_INIT_DONE);
16887 BLOGE(sc, "PXP2 RD_INIT failed val = 0x%x\n", val);
16891 BLOGD(sc, DBG_LOAD, "after pxp init\n");
16894 * Timer bug workaround for E2 only. We need to set the entire ILT to have
16895 * entries with value "0" and valid bit on. This needs to be done by the
16896 * first PF that is loaded in a path (i.e. common phase)
16898 if (!CHIP_IS_E1x(sc)) {
16900 * In E2 there is a bug in the timers block that can cause function 6 / 7
16901 * (i.e. vnic3) to start even if it is marked as "scan-off".
16902 * This occurs when a different function (func2,3) is being marked
16903 * as "scan-off". Real-life scenario for example: if a driver is being
16904 * load-unloaded while func6,7 are down. This will cause the timer to access
16905 * the ilt, translate to a logical address and send a request to read/write.
16906 * Since the ilt for the function that is down is not valid, this will cause
16907 * a translation error which is unrecoverable.
16908 * The Workaround is intended to make sure that when this happens nothing
16909 * fatal will occur. The workaround:
16910 * 1. First PF driver which loads on a path will:
16911 * a. After taking the chip out of reset, by using pretend,
16912 * it will write "0" to the following registers of
16914 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
16915 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
16916 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
16917 * And for itself it will write '1' to
16918 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
16919 * dmae-operations (writing to pram for example.)
16920 * note: can be done for only function 6,7 but cleaner this
16922 * b. Write zero+valid to the entire ILT.
16923 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
16924 * VNIC3 (of that port). The range allocated will be the
16925 * entire ILT. This is needed to prevent ILT range error.
16926 * 2. Any PF driver load flow:
16927 * a. ILT update with the physical addresses of the allocated
16929 * b. Wait 20msec. - note that this timeout is needed to make
16930 * sure there are no requests in one of the PXP internal
16931 * queues with "old" ILT addresses.
16932 * c. PF enable in the PGLC.
16933 * d. Clear the was_error of the PF in the PGLC. (could have
16934 * occurred while driver was down)
16935 * e. PF enable in the CFC (WEAK + STRONG)
16936 * f. Timers scan enable
16937 * 3. PF driver unload flow:
16938 * a. Clear the Timers scan_en.
16939 * b. Polling for scan_on=0 for that PF.
16940 * c. Clear the PF enable bit in the PXP.
16941 * d. Clear the PF enable in the CFC (WEAK + STRONG)
16942 * e. Write zero+valid to all ILT entries (The valid bit must
16944 * f. If this is VNIC 3 of a port then also init
16945 * first_timers_ilt_entry to zero and last_timers_ilt_entry
16946 * to the last enrty in the ILT.
16949 * Currently the PF error in the PGLC is non recoverable.
16950 * In the future the there will be a recovery routine for this error.
16951 * Currently attention is masked.
16952 * Having an MCP lock on the load/unload process does not guarantee that
16953 * there is no Timer disable during Func6/7 enable. This is because the
16954 * Timers scan is currently being cleared by the MCP on FLR.
16955 * Step 2.d can be done only for PF6/7 and the driver can also check if
16956 * there is error before clearing it. But the flow above is simpler and
16958 * All ILT entries are written by zero+valid and not just PF6/7
16959 * ILT entries since in the future the ILT entries allocation for
16960 * PF-s might be dynamic.
16962 struct ilt_client_info ilt_cli;
16963 struct ecore_ilt ilt;
16965 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
16966 memset(&ilt, 0, sizeof(struct ecore_ilt));
16968 /* initialize dummy TM client */
16970 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
16971 ilt_cli.client_num = ILT_CLIENT_TM;
16974 * Step 1: set zeroes to all ilt page entries with valid bit on
16975 * Step 2: set the timers first/last ilt entry to point
16976 * to the entire range to prevent ILT range error for 3rd/4th
16977 * vnic (this code assumes existence of the vnic)
16979 * both steps performed by call to ecore_ilt_client_init_op()
16980 * with dummy TM client
16982 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
16983 * and his brother are split registers
16986 bxe_pretend_func(sc, (SC_PATH(sc) + 6));
16987 ecore_ilt_client_init_op_ilt(sc, &ilt, &ilt_cli, INITOP_CLEAR);
16988 bxe_pretend_func(sc, SC_ABS_FUNC(sc));
16990 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN, BXE_PXP_DRAM_ALIGN);
16991 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN_RD, BXE_PXP_DRAM_ALIGN);
16992 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
16995 REG_WR(sc, PXP2_REG_RQ_DISABLE_INPUTS, 0);
16996 REG_WR(sc, PXP2_REG_RD_DISABLE_INPUTS, 0);
16998 if (!CHIP_IS_E1x(sc)) {
16999 int factor = CHIP_REV_IS_EMUL(sc) ? 1000 :
17000 (CHIP_REV_IS_FPGA(sc) ? 400 : 0);
17002 ecore_init_block(sc, BLOCK_PGLUE_B, PHASE_COMMON);
17003 ecore_init_block(sc, BLOCK_ATC, PHASE_COMMON);
17005 /* let the HW do it's magic... */
17008 val = REG_RD(sc, ATC_REG_ATC_INIT_DONE);
17009 } while (factor-- && (val != 1));
17012 BLOGE(sc, "ATC_INIT failed val = 0x%x\n", val);
17017 BLOGD(sc, DBG_LOAD, "after pglue and atc init\n");
17019 ecore_init_block(sc, BLOCK_DMAE, PHASE_COMMON);
17021 bxe_iov_init_dmae(sc);
17023 /* clean the DMAE memory */
17024 sc->dmae_ready = 1;
17025 ecore_init_fill(sc, TSEM_REG_PRAM, 0, 8, 1);
17027 ecore_init_block(sc, BLOCK_TCM, PHASE_COMMON);
17029 ecore_init_block(sc, BLOCK_UCM, PHASE_COMMON);
17031 ecore_init_block(sc, BLOCK_CCM, PHASE_COMMON);
17033 ecore_init_block(sc, BLOCK_XCM, PHASE_COMMON);
17035 bxe_read_dmae(sc, XSEM_REG_PASSIVE_BUFFER, 3);
17036 bxe_read_dmae(sc, CSEM_REG_PASSIVE_BUFFER, 3);
17037 bxe_read_dmae(sc, TSEM_REG_PASSIVE_BUFFER, 3);
17038 bxe_read_dmae(sc, USEM_REG_PASSIVE_BUFFER, 3);
17040 ecore_init_block(sc, BLOCK_QM, PHASE_COMMON);
17042 /* QM queues pointers table */
17043 ecore_qm_init_ptr_table(sc, sc->qm_cid_count, INITOP_SET);
17045 /* soft reset pulse */
17046 REG_WR(sc, QM_REG_SOFT_RESET, 1);
17047 REG_WR(sc, QM_REG_SOFT_RESET, 0);
17049 if (CNIC_SUPPORT(sc))
17050 ecore_init_block(sc, BLOCK_TM, PHASE_COMMON);
17052 ecore_init_block(sc, BLOCK_DORQ, PHASE_COMMON);
17053 REG_WR(sc, DORQ_REG_DPM_CID_OFST, BXE_DB_SHIFT);
17054 if (!CHIP_REV_IS_SLOW(sc)) {
17055 /* enable hw interrupt from doorbell Q */
17056 REG_WR(sc, DORQ_REG_DORQ_INT_MASK, 0);
17059 ecore_init_block(sc, BLOCK_BRB1, PHASE_COMMON);
17061 ecore_init_block(sc, BLOCK_PRS, PHASE_COMMON);
17062 REG_WR(sc, PRS_REG_A_PRSU_20, 0xf);
17064 if (!CHIP_IS_E1(sc)) {
17065 REG_WR(sc, PRS_REG_E1HOV_MODE, sc->devinfo.mf_info.path_has_ovlan);
17068 if (!CHIP_IS_E1x(sc) && !CHIP_IS_E3B0(sc)) {
17069 if (IS_MF_AFEX(sc)) {
17071 * configure that AFEX and VLAN headers must be
17072 * received in AFEX mode
17074 REG_WR(sc, PRS_REG_HDRS_AFTER_BASIC, 0xE);
17075 REG_WR(sc, PRS_REG_MUST_HAVE_HDRS, 0xA);
17076 REG_WR(sc, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
17077 REG_WR(sc, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
17078 REG_WR(sc, PRS_REG_TAG_LEN_0, 0x4);
17081 * Bit-map indicating which L2 hdrs may appear
17082 * after the basic Ethernet header
17084 REG_WR(sc, PRS_REG_HDRS_AFTER_BASIC,
17085 sc->devinfo.mf_info.path_has_ovlan ? 7 : 6);
17089 ecore_init_block(sc, BLOCK_TSDM, PHASE_COMMON);
17090 ecore_init_block(sc, BLOCK_CSDM, PHASE_COMMON);
17091 ecore_init_block(sc, BLOCK_USDM, PHASE_COMMON);
17092 ecore_init_block(sc, BLOCK_XSDM, PHASE_COMMON);
17094 if (!CHIP_IS_E1x(sc)) {
17095 /* reset VFC memories */
17096 REG_WR(sc, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
17097 VFC_MEMORIES_RST_REG_CAM_RST |
17098 VFC_MEMORIES_RST_REG_RAM_RST);
17099 REG_WR(sc, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
17100 VFC_MEMORIES_RST_REG_CAM_RST |
17101 VFC_MEMORIES_RST_REG_RAM_RST);
17106 ecore_init_block(sc, BLOCK_TSEM, PHASE_COMMON);
17107 ecore_init_block(sc, BLOCK_USEM, PHASE_COMMON);
17108 ecore_init_block(sc, BLOCK_CSEM, PHASE_COMMON);
17109 ecore_init_block(sc, BLOCK_XSEM, PHASE_COMMON);
17111 /* sync semi rtc */
17112 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
17114 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
17117 ecore_init_block(sc, BLOCK_UPB, PHASE_COMMON);
17118 ecore_init_block(sc, BLOCK_XPB, PHASE_COMMON);
17119 ecore_init_block(sc, BLOCK_PBF, PHASE_COMMON);
17121 if (!CHIP_IS_E1x(sc)) {
17122 if (IS_MF_AFEX(sc)) {
17124 * configure that AFEX and VLAN headers must be
17125 * sent in AFEX mode
17127 REG_WR(sc, PBF_REG_HDRS_AFTER_BASIC, 0xE);
17128 REG_WR(sc, PBF_REG_MUST_HAVE_HDRS, 0xA);
17129 REG_WR(sc, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
17130 REG_WR(sc, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
17131 REG_WR(sc, PBF_REG_TAG_LEN_0, 0x4);
17133 REG_WR(sc, PBF_REG_HDRS_AFTER_BASIC,
17134 sc->devinfo.mf_info.path_has_ovlan ? 7 : 6);
17138 REG_WR(sc, SRC_REG_SOFT_RST, 1);
17140 ecore_init_block(sc, BLOCK_SRC, PHASE_COMMON);
17142 if (CNIC_SUPPORT(sc)) {
17143 REG_WR(sc, SRC_REG_KEYSEARCH_0, 0x63285672);
17144 REG_WR(sc, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
17145 REG_WR(sc, SRC_REG_KEYSEARCH_2, 0x223aef9b);
17146 REG_WR(sc, SRC_REG_KEYSEARCH_3, 0x26001e3a);
17147 REG_WR(sc, SRC_REG_KEYSEARCH_4, 0x7ae91116);
17148 REG_WR(sc, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
17149 REG_WR(sc, SRC_REG_KEYSEARCH_6, 0x298d8adf);
17150 REG_WR(sc, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
17151 REG_WR(sc, SRC_REG_KEYSEARCH_8, 0x1830f82f);
17152 REG_WR(sc, SRC_REG_KEYSEARCH_9, 0x01e46be7);
17154 REG_WR(sc, SRC_REG_SOFT_RST, 0);
17156 if (sizeof(union cdu_context) != 1024) {
17157 /* we currently assume that a context is 1024 bytes */
17158 BLOGE(sc, "please adjust the size of cdu_context(%ld)\n",
17159 (long)sizeof(union cdu_context));
17162 ecore_init_block(sc, BLOCK_CDU, PHASE_COMMON);
17163 val = (4 << 24) + (0 << 12) + 1024;
17164 REG_WR(sc, CDU_REG_CDU_GLOBAL_PARAMS, val);
17166 ecore_init_block(sc, BLOCK_CFC, PHASE_COMMON);
17168 REG_WR(sc, CFC_REG_INIT_REG, 0x7FF);
17169 /* enable context validation interrupt from CFC */
17170 REG_WR(sc, CFC_REG_CFC_INT_MASK, 0);
17172 /* set the thresholds to prevent CFC/CDU race */
17173 REG_WR(sc, CFC_REG_DEBUG0, 0x20020000);
17174 ecore_init_block(sc, BLOCK_HC, PHASE_COMMON);
17176 if (!CHIP_IS_E1x(sc) && BXE_NOMCP(sc)) {
17177 REG_WR(sc, IGU_REG_RESET_MEMORIES, 0x36);
17180 ecore_init_block(sc, BLOCK_IGU, PHASE_COMMON);
17181 ecore_init_block(sc, BLOCK_MISC_AEU, PHASE_COMMON);
17183 /* Reset PCIE errors for debug */
17184 REG_WR(sc, 0x2814, 0xffffffff);
17185 REG_WR(sc, 0x3820, 0xffffffff);
17187 if (!CHIP_IS_E1x(sc)) {
17188 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
17189 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
17190 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
17191 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
17192 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
17193 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
17194 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
17195 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
17196 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
17197 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
17198 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
17201 ecore_init_block(sc, BLOCK_NIG, PHASE_COMMON);
17203 if (!CHIP_IS_E1(sc)) {
17204 /* in E3 this done in per-port section */
17205 if (!CHIP_IS_E3(sc))
17206 REG_WR(sc, NIG_REG_LLH_MF_MODE, IS_MF(sc));
17209 if (CHIP_IS_E1H(sc)) {
17210 /* not applicable for E2 (and above ...) */
17211 REG_WR(sc, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(sc));
17214 if (CHIP_REV_IS_SLOW(sc)) {
17218 /* finish CFC init */
17219 val = reg_poll(sc, CFC_REG_LL_INIT_DONE, 1, 100, 10);
17221 BLOGE(sc, "CFC LL_INIT failed val=0x%x\n", val);
17224 val = reg_poll(sc, CFC_REG_AC_INIT_DONE, 1, 100, 10);
17226 BLOGE(sc, "CFC AC_INIT failed val=0x%x\n", val);
17229 val = reg_poll(sc, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
17231 BLOGE(sc, "CFC CAM_INIT failed val=0x%x\n", val);
17234 REG_WR(sc, CFC_REG_DEBUG0, 0);
17236 if (CHIP_IS_E1(sc)) {
17237 /* read NIG statistic to see if this is our first up since powerup */
17238 bxe_read_dmae(sc, NIG_REG_STAT2_BRB_OCTET, 2);
17239 val = *BXE_SP(sc, wb_data[0]);
17241 /* do internal memory self test */
17242 if ((val == 0) && bxe_int_mem_test(sc)) {
17243 BLOGE(sc, "internal mem self test failed val=0x%x\n", val);
17248 bxe_setup_fan_failure_detection(sc);
17250 /* clear PXP2 attentions */
17251 REG_RD(sc, PXP2_REG_PXP2_INT_STS_CLR_0);
17253 bxe_enable_blocks_attention(sc);
17255 if (!CHIP_REV_IS_SLOW(sc)) {
17256 ecore_enable_blocks_parity(sc);
17259 if (!BXE_NOMCP(sc)) {
17260 if (CHIP_IS_E1x(sc)) {
17261 bxe_common_init_phy(sc);
17269 * bxe_init_hw_common_chip - init HW at the COMMON_CHIP phase.
17271 * @sc: driver handle
17274 bxe_init_hw_common_chip(struct bxe_softc *sc)
17276 int rc = bxe_init_hw_common(sc);
17279 BLOGE(sc, "bxe_init_hw_common failed rc=%d\n", rc);
17283 /* In E2 2-PORT mode, same ext phy is used for the two paths */
17284 if (!BXE_NOMCP(sc)) {
17285 bxe_common_init_phy(sc);
17292 bxe_init_hw_port(struct bxe_softc *sc)
17294 int port = SC_PORT(sc);
17295 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
17296 uint32_t low, high;
17299 BLOGD(sc, DBG_LOAD, "starting port init for port %d\n", port);
17301 REG_WR(sc, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
17303 ecore_init_block(sc, BLOCK_MISC, init_phase);
17304 ecore_init_block(sc, BLOCK_PXP, init_phase);
17305 ecore_init_block(sc, BLOCK_PXP2, init_phase);
17308 * Timers bug workaround: disables the pf_master bit in pglue at
17309 * common phase, we need to enable it here before any dmae access are
17310 * attempted. Therefore we manually added the enable-master to the
17311 * port phase (it also happens in the function phase)
17313 if (!CHIP_IS_E1x(sc)) {
17314 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
17317 ecore_init_block(sc, BLOCK_ATC, init_phase);
17318 ecore_init_block(sc, BLOCK_DMAE, init_phase);
17319 ecore_init_block(sc, BLOCK_PGLUE_B, init_phase);
17320 ecore_init_block(sc, BLOCK_QM, init_phase);
17322 ecore_init_block(sc, BLOCK_TCM, init_phase);
17323 ecore_init_block(sc, BLOCK_UCM, init_phase);
17324 ecore_init_block(sc, BLOCK_CCM, init_phase);
17325 ecore_init_block(sc, BLOCK_XCM, init_phase);
17327 /* QM cid (connection) count */
17328 ecore_qm_init_cid_count(sc, sc->qm_cid_count, INITOP_SET);
17330 if (CNIC_SUPPORT(sc)) {
17331 ecore_init_block(sc, BLOCK_TM, init_phase);
17332 REG_WR(sc, TM_REG_LIN0_SCAN_TIME + port*4, 20);
17333 REG_WR(sc, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
17336 ecore_init_block(sc, BLOCK_DORQ, init_phase);
17338 ecore_init_block(sc, BLOCK_BRB1, init_phase);
17340 if (CHIP_IS_E1(sc) || CHIP_IS_E1H(sc)) {
17342 low = (BXE_ONE_PORT(sc) ? 160 : 246);
17343 } else if (sc->mtu > 4096) {
17344 if (BXE_ONE_PORT(sc)) {
17348 /* (24*1024 + val*4)/256 */
17349 low = (96 + (val / 64) + ((val % 64) ? 1 : 0));
17352 low = (BXE_ONE_PORT(sc) ? 80 : 160);
17354 high = (low + 56); /* 14*1024/256 */
17355 REG_WR(sc, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
17356 REG_WR(sc, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
17359 if (CHIP_IS_MODE_4_PORT(sc)) {
17360 REG_WR(sc, SC_PORT(sc) ?
17361 BRB1_REG_MAC_GUARANTIED_1 :
17362 BRB1_REG_MAC_GUARANTIED_0, 40);
17365 ecore_init_block(sc, BLOCK_PRS, init_phase);
17366 if (CHIP_IS_E3B0(sc)) {
17367 if (IS_MF_AFEX(sc)) {
17368 /* configure headers for AFEX mode */
17369 REG_WR(sc, SC_PORT(sc) ?
17370 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
17371 PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
17372 REG_WR(sc, SC_PORT(sc) ?
17373 PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
17374 PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
17375 REG_WR(sc, SC_PORT(sc) ?
17376 PRS_REG_MUST_HAVE_HDRS_PORT_1 :
17377 PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
17379 /* Ovlan exists only if we are in multi-function +
17380 * switch-dependent mode, in switch-independent there
17381 * is no ovlan headers
17383 REG_WR(sc, SC_PORT(sc) ?
17384 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
17385 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
17386 (sc->devinfo.mf_info.path_has_ovlan ? 7 : 6));
17390 ecore_init_block(sc, BLOCK_TSDM, init_phase);
17391 ecore_init_block(sc, BLOCK_CSDM, init_phase);
17392 ecore_init_block(sc, BLOCK_USDM, init_phase);
17393 ecore_init_block(sc, BLOCK_XSDM, init_phase);
17395 ecore_init_block(sc, BLOCK_TSEM, init_phase);
17396 ecore_init_block(sc, BLOCK_USEM, init_phase);
17397 ecore_init_block(sc, BLOCK_CSEM, init_phase);
17398 ecore_init_block(sc, BLOCK_XSEM, init_phase);
17400 ecore_init_block(sc, BLOCK_UPB, init_phase);
17401 ecore_init_block(sc, BLOCK_XPB, init_phase);
17403 ecore_init_block(sc, BLOCK_PBF, init_phase);
17405 if (CHIP_IS_E1x(sc)) {
17406 /* configure PBF to work without PAUSE mtu 9000 */
17407 REG_WR(sc, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
17409 /* update threshold */
17410 REG_WR(sc, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
17411 /* update init credit */
17412 REG_WR(sc, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
17414 /* probe changes */
17415 REG_WR(sc, PBF_REG_INIT_P0 + port*4, 1);
17417 REG_WR(sc, PBF_REG_INIT_P0 + port*4, 0);
17420 if (CNIC_SUPPORT(sc)) {
17421 ecore_init_block(sc, BLOCK_SRC, init_phase);
17424 ecore_init_block(sc, BLOCK_CDU, init_phase);
17425 ecore_init_block(sc, BLOCK_CFC, init_phase);
17427 if (CHIP_IS_E1(sc)) {
17428 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, 0);
17429 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, 0);
17431 ecore_init_block(sc, BLOCK_HC, init_phase);
17433 ecore_init_block(sc, BLOCK_IGU, init_phase);
17435 ecore_init_block(sc, BLOCK_MISC_AEU, init_phase);
17436 /* init aeu_mask_attn_func_0/1:
17437 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
17438 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
17439 * bits 4-7 are used for "per vn group attention" */
17440 val = IS_MF(sc) ? 0xF7 : 0x7;
17441 /* Enable DCBX attention for all but E1 */
17442 val |= CHIP_IS_E1(sc) ? 0 : 0x10;
17443 REG_WR(sc, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
17445 ecore_init_block(sc, BLOCK_NIG, init_phase);
17447 if (!CHIP_IS_E1x(sc)) {
17448 /* Bit-map indicating which L2 hdrs may appear after the
17449 * basic Ethernet header
17451 if (IS_MF_AFEX(sc)) {
17452 REG_WR(sc, SC_PORT(sc) ?
17453 NIG_REG_P1_HDRS_AFTER_BASIC :
17454 NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
17456 REG_WR(sc, SC_PORT(sc) ?
17457 NIG_REG_P1_HDRS_AFTER_BASIC :
17458 NIG_REG_P0_HDRS_AFTER_BASIC,
17459 IS_MF_SD(sc) ? 7 : 6);
17462 if (CHIP_IS_E3(sc)) {
17463 REG_WR(sc, SC_PORT(sc) ?
17464 NIG_REG_LLH1_MF_MODE :
17465 NIG_REG_LLH_MF_MODE, IS_MF(sc));
17468 if (!CHIP_IS_E3(sc)) {
17469 REG_WR(sc, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
17472 if (!CHIP_IS_E1(sc)) {
17473 /* 0x2 disable mf_ov, 0x1 enable */
17474 REG_WR(sc, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
17475 (IS_MF_SD(sc) ? 0x1 : 0x2));
17477 if (!CHIP_IS_E1x(sc)) {
17479 switch (sc->devinfo.mf_info.mf_mode) {
17480 case MULTI_FUNCTION_SD:
17483 case MULTI_FUNCTION_SI:
17484 case MULTI_FUNCTION_AFEX:
17489 REG_WR(sc, (SC_PORT(sc) ? NIG_REG_LLH1_CLS_TYPE :
17490 NIG_REG_LLH0_CLS_TYPE), val);
17492 REG_WR(sc, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
17493 REG_WR(sc, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
17494 REG_WR(sc, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
17497 /* If SPIO5 is set to generate interrupts, enable it for this port */
17498 val = REG_RD(sc, MISC_REG_SPIO_EVENT_EN);
17499 if (val & MISC_SPIO_SPIO5) {
17500 uint32_t reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
17501 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
17502 val = REG_RD(sc, reg_addr);
17503 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
17504 REG_WR(sc, reg_addr, val);
17511 bxe_flr_clnup_reg_poll(struct bxe_softc *sc,
17514 uint32_t poll_count)
17516 uint32_t cur_cnt = poll_count;
17519 while ((val = REG_RD(sc, reg)) != expected && cur_cnt--) {
17520 DELAY(FLR_WAIT_INTERVAL);
17527 bxe_flr_clnup_poll_hw_counter(struct bxe_softc *sc,
17532 uint32_t val = bxe_flr_clnup_reg_poll(sc, reg, 0, poll_cnt);
17535 BLOGE(sc, "%s usage count=%d\n", msg, val);
17542 /* Common routines with VF FLR cleanup */
17544 bxe_flr_clnup_poll_count(struct bxe_softc *sc)
17546 /* adjust polling timeout */
17547 if (CHIP_REV_IS_EMUL(sc)) {
17548 return (FLR_POLL_CNT * 2000);
17551 if (CHIP_REV_IS_FPGA(sc)) {
17552 return (FLR_POLL_CNT * 120);
17555 return (FLR_POLL_CNT);
17559 bxe_poll_hw_usage_counters(struct bxe_softc *sc,
17562 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
17563 if (bxe_flr_clnup_poll_hw_counter(sc,
17564 CFC_REG_NUM_LCIDS_INSIDE_PF,
17565 "CFC PF usage counter timed out",
17570 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
17571 if (bxe_flr_clnup_poll_hw_counter(sc,
17572 DORQ_REG_PF_USAGE_CNT,
17573 "DQ PF usage counter timed out",
17578 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
17579 if (bxe_flr_clnup_poll_hw_counter(sc,
17580 QM_REG_PF_USG_CNT_0 + 4*SC_FUNC(sc),
17581 "QM PF usage counter timed out",
17586 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
17587 if (bxe_flr_clnup_poll_hw_counter(sc,
17588 TM_REG_LIN0_VNIC_UC + 4*SC_PORT(sc),
17589 "Timers VNIC usage counter timed out",
17594 if (bxe_flr_clnup_poll_hw_counter(sc,
17595 TM_REG_LIN0_NUM_SCANS + 4*SC_PORT(sc),
17596 "Timers NUM_SCANS usage counter timed out",
17601 /* Wait DMAE PF usage counter to zero */
17602 if (bxe_flr_clnup_poll_hw_counter(sc,
17603 dmae_reg_go_c[INIT_DMAE_C(sc)],
17604 "DMAE dommand register timed out",
17612 #define OP_GEN_PARAM(param) \
17613 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
17614 #define OP_GEN_TYPE(type) \
17615 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
17616 #define OP_GEN_AGG_VECT(index) \
17617 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
17620 bxe_send_final_clnup(struct bxe_softc *sc,
17621 uint8_t clnup_func,
17624 uint32_t op_gen_command = 0;
17625 uint32_t comp_addr = (BAR_CSTRORM_INTMEM +
17626 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func));
17629 if (REG_RD(sc, comp_addr)) {
17630 BLOGE(sc, "Cleanup complete was not 0 before sending\n");
17634 op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
17635 op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
17636 op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
17637 op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
17639 BLOGD(sc, DBG_LOAD, "sending FW Final cleanup\n");
17640 REG_WR(sc, XSDM_REG_OPERATION_GEN, op_gen_command);
17642 if (bxe_flr_clnup_reg_poll(sc, comp_addr, 1, poll_cnt) != 1) {
17643 BLOGE(sc, "FW final cleanup did not succeed\n");
17644 BLOGD(sc, DBG_LOAD, "At timeout completion address contained %x\n",
17645 (REG_RD(sc, comp_addr)));
17646 bxe_panic(sc, ("FLR cleanup failed\n"));
17650 /* Zero completion for nxt FLR */
17651 REG_WR(sc, comp_addr, 0);
17657 bxe_pbf_pN_buf_flushed(struct bxe_softc *sc,
17658 struct pbf_pN_buf_regs *regs,
17659 uint32_t poll_count)
17661 uint32_t init_crd, crd, crd_start, crd_freed, crd_freed_start;
17662 uint32_t cur_cnt = poll_count;
17664 crd_freed = crd_freed_start = REG_RD(sc, regs->crd_freed);
17665 crd = crd_start = REG_RD(sc, regs->crd);
17666 init_crd = REG_RD(sc, regs->init_crd);
17668 BLOGD(sc, DBG_LOAD, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
17669 BLOGD(sc, DBG_LOAD, "CREDIT[%d] : s:%x\n", regs->pN, crd);
17670 BLOGD(sc, DBG_LOAD, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
17672 while ((crd != init_crd) &&
17673 ((uint32_t)((int32_t)crd_freed - (int32_t)crd_freed_start) <
17674 (init_crd - crd_start))) {
17676 DELAY(FLR_WAIT_INTERVAL);
17677 crd = REG_RD(sc, regs->crd);
17678 crd_freed = REG_RD(sc, regs->crd_freed);
17680 BLOGD(sc, DBG_LOAD, "PBF tx buffer[%d] timed out\n", regs->pN);
17681 BLOGD(sc, DBG_LOAD, "CREDIT[%d] : c:%x\n", regs->pN, crd);
17682 BLOGD(sc, DBG_LOAD, "CREDIT_FREED[%d]: c:%x\n", regs->pN, crd_freed);
17687 BLOGD(sc, DBG_LOAD, "Waited %d*%d usec for PBF tx buffer[%d]\n",
17688 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
17692 bxe_pbf_pN_cmd_flushed(struct bxe_softc *sc,
17693 struct pbf_pN_cmd_regs *regs,
17694 uint32_t poll_count)
17696 uint32_t occup, to_free, freed, freed_start;
17697 uint32_t cur_cnt = poll_count;
17699 occup = to_free = REG_RD(sc, regs->lines_occup);
17700 freed = freed_start = REG_RD(sc, regs->lines_freed);
17702 BLOGD(sc, DBG_LOAD, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
17703 BLOGD(sc, DBG_LOAD, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
17706 ((uint32_t)((int32_t)freed - (int32_t)freed_start) < to_free)) {
17708 DELAY(FLR_WAIT_INTERVAL);
17709 occup = REG_RD(sc, regs->lines_occup);
17710 freed = REG_RD(sc, regs->lines_freed);
17712 BLOGD(sc, DBG_LOAD, "PBF cmd queue[%d] timed out\n", regs->pN);
17713 BLOGD(sc, DBG_LOAD, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
17714 BLOGD(sc, DBG_LOAD, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
17719 BLOGD(sc, DBG_LOAD, "Waited %d*%d usec for PBF cmd queue[%d]\n",
17720 poll_count - cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
17724 bxe_tx_hw_flushed(struct bxe_softc *sc, uint32_t poll_count)
17726 struct pbf_pN_cmd_regs cmd_regs[] = {
17727 {0, (CHIP_IS_E3B0(sc)) ?
17728 PBF_REG_TQ_OCCUPANCY_Q0 :
17729 PBF_REG_P0_TQ_OCCUPANCY,
17730 (CHIP_IS_E3B0(sc)) ?
17731 PBF_REG_TQ_LINES_FREED_CNT_Q0 :
17732 PBF_REG_P0_TQ_LINES_FREED_CNT},
17733 {1, (CHIP_IS_E3B0(sc)) ?
17734 PBF_REG_TQ_OCCUPANCY_Q1 :
17735 PBF_REG_P1_TQ_OCCUPANCY,
17736 (CHIP_IS_E3B0(sc)) ?
17737 PBF_REG_TQ_LINES_FREED_CNT_Q1 :
17738 PBF_REG_P1_TQ_LINES_FREED_CNT},
17739 {4, (CHIP_IS_E3B0(sc)) ?
17740 PBF_REG_TQ_OCCUPANCY_LB_Q :
17741 PBF_REG_P4_TQ_OCCUPANCY,
17742 (CHIP_IS_E3B0(sc)) ?
17743 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
17744 PBF_REG_P4_TQ_LINES_FREED_CNT}
17747 struct pbf_pN_buf_regs buf_regs[] = {
17748 {0, (CHIP_IS_E3B0(sc)) ?
17749 PBF_REG_INIT_CRD_Q0 :
17750 PBF_REG_P0_INIT_CRD ,
17751 (CHIP_IS_E3B0(sc)) ?
17752 PBF_REG_CREDIT_Q0 :
17754 (CHIP_IS_E3B0(sc)) ?
17755 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
17756 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
17757 {1, (CHIP_IS_E3B0(sc)) ?
17758 PBF_REG_INIT_CRD_Q1 :
17759 PBF_REG_P1_INIT_CRD,
17760 (CHIP_IS_E3B0(sc)) ?
17761 PBF_REG_CREDIT_Q1 :
17763 (CHIP_IS_E3B0(sc)) ?
17764 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
17765 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
17766 {4, (CHIP_IS_E3B0(sc)) ?
17767 PBF_REG_INIT_CRD_LB_Q :
17768 PBF_REG_P4_INIT_CRD,
17769 (CHIP_IS_E3B0(sc)) ?
17770 PBF_REG_CREDIT_LB_Q :
17772 (CHIP_IS_E3B0(sc)) ?
17773 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
17774 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
17779 /* Verify the command queues are flushed P0, P1, P4 */
17780 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++) {
17781 bxe_pbf_pN_cmd_flushed(sc, &cmd_regs[i], poll_count);
17784 /* Verify the transmission buffers are flushed P0, P1, P4 */
17785 for (i = 0; i < ARRAY_SIZE(buf_regs); i++) {
17786 bxe_pbf_pN_buf_flushed(sc, &buf_regs[i], poll_count);
17791 bxe_hw_enable_status(struct bxe_softc *sc)
17795 val = REG_RD(sc, CFC_REG_WEAK_ENABLE_PF);
17796 BLOGD(sc, DBG_LOAD, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
17798 val = REG_RD(sc, PBF_REG_DISABLE_PF);
17799 BLOGD(sc, DBG_LOAD, "PBF_REG_DISABLE_PF is 0x%x\n", val);
17801 val = REG_RD(sc, IGU_REG_PCI_PF_MSI_EN);
17802 BLOGD(sc, DBG_LOAD, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
17804 val = REG_RD(sc, IGU_REG_PCI_PF_MSIX_EN);
17805 BLOGD(sc, DBG_LOAD, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
17807 val = REG_RD(sc, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
17808 BLOGD(sc, DBG_LOAD, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
17810 val = REG_RD(sc, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
17811 BLOGD(sc, DBG_LOAD, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
17813 val = REG_RD(sc, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
17814 BLOGD(sc, DBG_LOAD, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
17816 val = REG_RD(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
17817 BLOGD(sc, DBG_LOAD, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n", val);
17821 bxe_pf_flr_clnup(struct bxe_softc *sc)
17823 uint32_t poll_cnt = bxe_flr_clnup_poll_count(sc);
17825 BLOGD(sc, DBG_LOAD, "Cleanup after FLR PF[%d]\n", SC_ABS_FUNC(sc));
17827 /* Re-enable PF target read access */
17828 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
17830 /* Poll HW usage counters */
17831 BLOGD(sc, DBG_LOAD, "Polling usage counters\n");
17832 if (bxe_poll_hw_usage_counters(sc, poll_cnt)) {
17836 /* Zero the igu 'trailing edge' and 'leading edge' */
17838 /* Send the FW cleanup command */
17839 if (bxe_send_final_clnup(sc, (uint8_t)SC_FUNC(sc), poll_cnt)) {
17845 /* Verify TX hw is flushed */
17846 bxe_tx_hw_flushed(sc, poll_cnt);
17848 /* Wait 100ms (not adjusted according to platform) */
17851 /* Verify no pending pci transactions */
17852 if (bxe_is_pcie_pending(sc)) {
17853 BLOGE(sc, "PCIE Transactions still pending\n");
17857 bxe_hw_enable_status(sc);
17860 * Master enable - Due to WB DMAE writes performed before this
17861 * register is re-initialized as part of the regular function init
17863 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
17869 bxe_init_hw_func(struct bxe_softc *sc)
17871 int port = SC_PORT(sc);
17872 int func = SC_FUNC(sc);
17873 int init_phase = PHASE_PF0 + func;
17874 struct ecore_ilt *ilt = sc->ilt;
17875 uint16_t cdu_ilt_start;
17876 uint32_t addr, val;
17877 uint32_t main_mem_base, main_mem_size, main_mem_prty_clr;
17878 int i, main_mem_width, rc;
17880 BLOGD(sc, DBG_LOAD, "starting func init for func %d\n", func);
17883 if (!CHIP_IS_E1x(sc)) {
17884 rc = bxe_pf_flr_clnup(sc);
17886 BLOGE(sc, "FLR cleanup failed!\n");
17887 // XXX bxe_fw_dump(sc);
17888 // XXX bxe_idle_chk(sc);
17893 /* set MSI reconfigure capability */
17894 if (sc->devinfo.int_block == INT_BLOCK_HC) {
17895 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
17896 val = REG_RD(sc, addr);
17897 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
17898 REG_WR(sc, addr, val);
17901 ecore_init_block(sc, BLOCK_PXP, init_phase);
17902 ecore_init_block(sc, BLOCK_PXP2, init_phase);
17905 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
17907 for (i = 0; i < L2_ILT_LINES(sc); i++) {
17908 ilt->lines[cdu_ilt_start + i].page = sc->context[i].vcxt;
17909 ilt->lines[cdu_ilt_start + i].page_mapping =
17910 sc->context[i].vcxt_dma.paddr;
17911 ilt->lines[cdu_ilt_start + i].size = sc->context[i].size;
17913 ecore_ilt_init_op(sc, INITOP_SET);
17916 REG_WR(sc, PRS_REG_NIC_MODE, 1);
17917 BLOGD(sc, DBG_LOAD, "NIC MODE configured\n");
17919 if (!CHIP_IS_E1x(sc)) {
17920 uint32_t pf_conf = IGU_PF_CONF_FUNC_EN;
17922 /* Turn on a single ISR mode in IGU if driver is going to use
17925 if (sc->interrupt_mode != INTR_MODE_MSIX) {
17926 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
17930 * Timers workaround bug: function init part.
17931 * Need to wait 20msec after initializing ILT,
17932 * needed to make sure there are no requests in
17933 * one of the PXP internal queues with "old" ILT addresses
17938 * Master enable - Due to WB DMAE writes performed before this
17939 * register is re-initialized as part of the regular function
17942 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
17943 /* Enable the function in IGU */
17944 REG_WR(sc, IGU_REG_PF_CONFIGURATION, pf_conf);
17947 sc->dmae_ready = 1;
17949 ecore_init_block(sc, BLOCK_PGLUE_B, init_phase);
17951 if (!CHIP_IS_E1x(sc))
17952 REG_WR(sc, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
17954 ecore_init_block(sc, BLOCK_ATC, init_phase);
17955 ecore_init_block(sc, BLOCK_DMAE, init_phase);
17956 ecore_init_block(sc, BLOCK_NIG, init_phase);
17957 ecore_init_block(sc, BLOCK_SRC, init_phase);
17958 ecore_init_block(sc, BLOCK_MISC, init_phase);
17959 ecore_init_block(sc, BLOCK_TCM, init_phase);
17960 ecore_init_block(sc, BLOCK_UCM, init_phase);
17961 ecore_init_block(sc, BLOCK_CCM, init_phase);
17962 ecore_init_block(sc, BLOCK_XCM, init_phase);
17963 ecore_init_block(sc, BLOCK_TSEM, init_phase);
17964 ecore_init_block(sc, BLOCK_USEM, init_phase);
17965 ecore_init_block(sc, BLOCK_CSEM, init_phase);
17966 ecore_init_block(sc, BLOCK_XSEM, init_phase);
17968 if (!CHIP_IS_E1x(sc))
17969 REG_WR(sc, QM_REG_PF_EN, 1);
17971 if (!CHIP_IS_E1x(sc)) {
17972 REG_WR(sc, TSEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func);
17973 REG_WR(sc, USEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func);
17974 REG_WR(sc, CSEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func);
17975 REG_WR(sc, XSEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func);
17977 ecore_init_block(sc, BLOCK_QM, init_phase);
17979 ecore_init_block(sc, BLOCK_TM, init_phase);
17980 ecore_init_block(sc, BLOCK_DORQ, init_phase);
17982 bxe_iov_init_dq(sc);
17984 ecore_init_block(sc, BLOCK_BRB1, init_phase);
17985 ecore_init_block(sc, BLOCK_PRS, init_phase);
17986 ecore_init_block(sc, BLOCK_TSDM, init_phase);
17987 ecore_init_block(sc, BLOCK_CSDM, init_phase);
17988 ecore_init_block(sc, BLOCK_USDM, init_phase);
17989 ecore_init_block(sc, BLOCK_XSDM, init_phase);
17990 ecore_init_block(sc, BLOCK_UPB, init_phase);
17991 ecore_init_block(sc, BLOCK_XPB, init_phase);
17992 ecore_init_block(sc, BLOCK_PBF, init_phase);
17993 if (!CHIP_IS_E1x(sc))
17994 REG_WR(sc, PBF_REG_DISABLE_PF, 0);
17996 ecore_init_block(sc, BLOCK_CDU, init_phase);
17998 ecore_init_block(sc, BLOCK_CFC, init_phase);
18000 if (!CHIP_IS_E1x(sc))
18001 REG_WR(sc, CFC_REG_WEAK_ENABLE_PF, 1);
18004 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 1);
18005 REG_WR(sc, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, OVLAN(sc));
18008 ecore_init_block(sc, BLOCK_MISC_AEU, init_phase);
18010 /* HC init per function */
18011 if (sc->devinfo.int_block == INT_BLOCK_HC) {
18012 if (CHIP_IS_E1H(sc)) {
18013 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
18015 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, 0);
18016 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, 0);
18018 ecore_init_block(sc, BLOCK_HC, init_phase);
18021 int num_segs, sb_idx, prod_offset;
18023 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
18025 if (!CHIP_IS_E1x(sc)) {
18026 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, 0);
18027 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, 0);
18030 ecore_init_block(sc, BLOCK_IGU, init_phase);
18032 if (!CHIP_IS_E1x(sc)) {
18036 * E2 mode: address 0-135 match to the mapping memory;
18037 * 136 - PF0 default prod; 137 - PF1 default prod;
18038 * 138 - PF2 default prod; 139 - PF3 default prod;
18039 * 140 - PF0 attn prod; 141 - PF1 attn prod;
18040 * 142 - PF2 attn prod; 143 - PF3 attn prod;
18041 * 144-147 reserved.
18043 * E1.5 mode - In backward compatible mode;
18044 * for non default SB; each even line in the memory
18045 * holds the U producer and each odd line hold
18046 * the C producer. The first 128 producers are for
18047 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
18048 * producers are for the DSB for each PF.
18049 * Each PF has five segments: (the order inside each
18050 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
18051 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
18052 * 144-147 attn prods;
18054 /* non-default-status-blocks */
18055 num_segs = CHIP_INT_MODE_IS_BC(sc) ?
18056 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
18057 for (sb_idx = 0; sb_idx < sc->igu_sb_cnt; sb_idx++) {
18058 prod_offset = (sc->igu_base_sb + sb_idx) *
18061 for (i = 0; i < num_segs; i++) {
18062 addr = IGU_REG_PROD_CONS_MEMORY +
18063 (prod_offset + i) * 4;
18064 REG_WR(sc, addr, 0);
18066 /* send consumer update with value 0 */
18067 bxe_ack_sb(sc, sc->igu_base_sb + sb_idx,
18068 USTORM_ID, 0, IGU_INT_NOP, 1);
18069 bxe_igu_clear_sb(sc, sc->igu_base_sb + sb_idx);
18072 /* default-status-blocks */
18073 num_segs = CHIP_INT_MODE_IS_BC(sc) ?
18074 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
18076 if (CHIP_IS_MODE_4_PORT(sc))
18077 dsb_idx = SC_FUNC(sc);
18079 dsb_idx = SC_VN(sc);
18081 prod_offset = (CHIP_INT_MODE_IS_BC(sc) ?
18082 IGU_BC_BASE_DSB_PROD + dsb_idx :
18083 IGU_NORM_BASE_DSB_PROD + dsb_idx);
18086 * igu prods come in chunks of E1HVN_MAX (4) -
18087 * does not matters what is the current chip mode
18089 for (i = 0; i < (num_segs * E1HVN_MAX);
18091 addr = IGU_REG_PROD_CONS_MEMORY +
18092 (prod_offset + i)*4;
18093 REG_WR(sc, addr, 0);
18095 /* send consumer update with 0 */
18096 if (CHIP_INT_MODE_IS_BC(sc)) {
18097 bxe_ack_sb(sc, sc->igu_dsb_id,
18098 USTORM_ID, 0, IGU_INT_NOP, 1);
18099 bxe_ack_sb(sc, sc->igu_dsb_id,
18100 CSTORM_ID, 0, IGU_INT_NOP, 1);
18101 bxe_ack_sb(sc, sc->igu_dsb_id,
18102 XSTORM_ID, 0, IGU_INT_NOP, 1);
18103 bxe_ack_sb(sc, sc->igu_dsb_id,
18104 TSTORM_ID, 0, IGU_INT_NOP, 1);
18105 bxe_ack_sb(sc, sc->igu_dsb_id,
18106 ATTENTION_ID, 0, IGU_INT_NOP, 1);
18108 bxe_ack_sb(sc, sc->igu_dsb_id,
18109 USTORM_ID, 0, IGU_INT_NOP, 1);
18110 bxe_ack_sb(sc, sc->igu_dsb_id,
18111 ATTENTION_ID, 0, IGU_INT_NOP, 1);
18113 bxe_igu_clear_sb(sc, sc->igu_dsb_id);
18115 /* !!! these should become driver const once
18116 rf-tool supports split-68 const */
18117 REG_WR(sc, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
18118 REG_WR(sc, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
18119 REG_WR(sc, IGU_REG_SB_MASK_LSB, 0);
18120 REG_WR(sc, IGU_REG_SB_MASK_MSB, 0);
18121 REG_WR(sc, IGU_REG_PBA_STATUS_LSB, 0);
18122 REG_WR(sc, IGU_REG_PBA_STATUS_MSB, 0);
18126 /* Reset PCIE errors for debug */
18127 REG_WR(sc, 0x2114, 0xffffffff);
18128 REG_WR(sc, 0x2120, 0xffffffff);
18130 if (CHIP_IS_E1x(sc)) {
18131 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
18132 main_mem_base = HC_REG_MAIN_MEMORY +
18133 SC_PORT(sc) * (main_mem_size * 4);
18134 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
18135 main_mem_width = 8;
18137 val = REG_RD(sc, main_mem_prty_clr);
18139 BLOGD(sc, DBG_LOAD,
18140 "Parity errors in HC block during function init (0x%x)!\n",
18144 /* Clear "false" parity errors in MSI-X table */
18145 for (i = main_mem_base;
18146 i < main_mem_base + main_mem_size * 4;
18147 i += main_mem_width) {
18148 bxe_read_dmae(sc, i, main_mem_width / 4);
18149 bxe_write_dmae(sc, BXE_SP_MAPPING(sc, wb_data),
18150 i, main_mem_width / 4);
18152 /* Clear HC parity attention */
18153 REG_RD(sc, main_mem_prty_clr);
18157 /* Enable STORMs SP logging */
18158 REG_WR8(sc, BAR_USTRORM_INTMEM +
18159 USTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
18160 REG_WR8(sc, BAR_TSTRORM_INTMEM +
18161 TSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
18162 REG_WR8(sc, BAR_CSTRORM_INTMEM +
18163 CSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
18164 REG_WR8(sc, BAR_XSTRORM_INTMEM +
18165 XSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
18168 elink_phy_probe(&sc->link_params);
18174 bxe_link_reset(struct bxe_softc *sc)
18176 if (!BXE_NOMCP(sc)) {
18177 bxe_acquire_phy_lock(sc);
18178 elink_lfa_reset(&sc->link_params, &sc->link_vars);
18179 bxe_release_phy_lock(sc);
18181 if (!CHIP_REV_IS_SLOW(sc)) {
18182 BLOGW(sc, "Bootcode is missing - cannot reset link\n");
18188 bxe_reset_port(struct bxe_softc *sc)
18190 int port = SC_PORT(sc);
18193 ELINK_DEBUG_P0(sc, "bxe_reset_port called\n");
18194 /* reset physical Link */
18195 bxe_link_reset(sc);
18197 REG_WR(sc, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
18199 /* Do not rcv packets to BRB */
18200 REG_WR(sc, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
18201 /* Do not direct rcv packets that are not for MCP to the BRB */
18202 REG_WR(sc, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
18203 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
18205 /* Configure AEU */
18206 REG_WR(sc, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
18210 /* Check for BRB port occupancy */
18211 val = REG_RD(sc, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
18213 BLOGD(sc, DBG_LOAD,
18214 "BRB1 is not empty, %d blocks are occupied\n", val);
18217 /* TODO: Close Doorbell port? */
18221 bxe_ilt_wr(struct bxe_softc *sc,
18226 uint32_t wb_write[2];
18228 if (CHIP_IS_E1(sc)) {
18229 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
18231 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
18234 wb_write[0] = ONCHIP_ADDR1(addr);
18235 wb_write[1] = ONCHIP_ADDR2(addr);
18236 REG_WR_DMAE(sc, reg, wb_write, 2);
18240 bxe_clear_func_ilt(struct bxe_softc *sc,
18243 uint32_t i, base = FUNC_ILT_BASE(func);
18244 for (i = base; i < base + ILT_PER_FUNC; i++) {
18245 bxe_ilt_wr(sc, i, 0);
18250 bxe_reset_func(struct bxe_softc *sc)
18252 struct bxe_fastpath *fp;
18253 int port = SC_PORT(sc);
18254 int func = SC_FUNC(sc);
18257 /* Disable the function in the FW */
18258 REG_WR8(sc, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
18259 REG_WR8(sc, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
18260 REG_WR8(sc, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
18261 REG_WR8(sc, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
18264 FOR_EACH_ETH_QUEUE(sc, i) {
18266 REG_WR8(sc, BAR_CSTRORM_INTMEM +
18267 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
18272 REG_WR8(sc, BAR_CSTRORM_INTMEM +
18273 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
18276 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++) {
18277 REG_WR(sc, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func), 0);
18280 /* Configure IGU */
18281 if (sc->devinfo.int_block == INT_BLOCK_HC) {
18282 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, 0);
18283 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, 0);
18285 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, 0);
18286 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, 0);
18289 if (CNIC_LOADED(sc)) {
18290 /* Disable Timer scan */
18291 REG_WR(sc, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
18293 * Wait for at least 10ms and up to 2 second for the timers
18296 for (i = 0; i < 200; i++) {
18298 if (!REG_RD(sc, TM_REG_LIN0_SCAN_ON + port*4))
18304 bxe_clear_func_ilt(sc, func);
18307 * Timers workaround bug for E2: if this is vnic-3,
18308 * we need to set the entire ilt range for this timers.
18310 if (!CHIP_IS_E1x(sc) && SC_VN(sc) == 3) {
18311 struct ilt_client_info ilt_cli;
18312 /* use dummy TM client */
18313 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
18315 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
18316 ilt_cli.client_num = ILT_CLIENT_TM;
18318 ecore_ilt_boundry_init_op(sc, &ilt_cli, 0, INITOP_CLEAR);
18321 /* this assumes that reset_port() called before reset_func()*/
18322 if (!CHIP_IS_E1x(sc)) {
18323 bxe_pf_disable(sc);
18326 sc->dmae_ready = 0;
18330 bxe_gunzip_init(struct bxe_softc *sc)
18336 bxe_gunzip_end(struct bxe_softc *sc)
18342 bxe_init_firmware(struct bxe_softc *sc)
18344 if (CHIP_IS_E1(sc)) {
18345 ecore_init_e1_firmware(sc);
18346 sc->iro_array = e1_iro_arr;
18347 } else if (CHIP_IS_E1H(sc)) {
18348 ecore_init_e1h_firmware(sc);
18349 sc->iro_array = e1h_iro_arr;
18350 } else if (!CHIP_IS_E1x(sc)) {
18351 ecore_init_e2_firmware(sc);
18352 sc->iro_array = e2_iro_arr;
18354 BLOGE(sc, "Unsupported chip revision\n");
18362 bxe_release_firmware(struct bxe_softc *sc)
18369 ecore_gunzip(struct bxe_softc *sc,
18370 const uint8_t *zbuf,
18373 /* XXX : Implement... */
18374 BLOGD(sc, DBG_LOAD, "ECORE_GUNZIP NOT IMPLEMENTED\n");
18379 ecore_reg_wr_ind(struct bxe_softc *sc,
18383 bxe_reg_wr_ind(sc, addr, val);
18387 ecore_write_dmae_phys_len(struct bxe_softc *sc,
18388 bus_addr_t phys_addr,
18392 bxe_write_dmae_phys_len(sc, phys_addr, addr, len);
18396 ecore_storm_memset_struct(struct bxe_softc *sc,
18402 for (i = 0; i < size/4; i++) {
18403 REG_WR(sc, addr + (i * 4), data[i]);
18409 * character device - ioctl interface definitions
18413 #include "bxe_dump.h"
18414 #include "bxe_ioctl.h"
18415 #include <sys/conf.h>
18417 static int bxe_eioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
18418 struct thread *td);
18420 static struct cdevsw bxe_cdevsw = {
18421 .d_version = D_VERSION,
18422 .d_ioctl = bxe_eioctl,
18423 .d_name = "bxecnic",
18426 #define BXE_PATH(sc) (CHIP_IS_E1x(sc) ? 0 : (sc->pcie_func & 1))
18429 #define DUMP_ALL_PRESETS 0x1FFF
18430 #define DUMP_MAX_PRESETS 13
18431 #define IS_E1_REG(chips) ((chips & DUMP_CHIP_E1) == DUMP_CHIP_E1)
18432 #define IS_E1H_REG(chips) ((chips & DUMP_CHIP_E1H) == DUMP_CHIP_E1H)
18433 #define IS_E2_REG(chips) ((chips & DUMP_CHIP_E2) == DUMP_CHIP_E2)
18434 #define IS_E3A0_REG(chips) ((chips & DUMP_CHIP_E3A0) == DUMP_CHIP_E3A0)
18435 #define IS_E3B0_REG(chips) ((chips & DUMP_CHIP_E3B0) == DUMP_CHIP_E3B0)
18437 #define IS_REG_IN_PRESET(presets, idx) \
18438 ((presets & (1 << (idx-1))) == (1 << (idx-1)))
18442 bxe_get_preset_regs_len(struct bxe_softc *sc, uint32_t preset)
18444 if (CHIP_IS_E1(sc))
18445 return dump_num_registers[0][preset-1];
18446 else if (CHIP_IS_E1H(sc))
18447 return dump_num_registers[1][preset-1];
18448 else if (CHIP_IS_E2(sc))
18449 return dump_num_registers[2][preset-1];
18450 else if (CHIP_IS_E3A0(sc))
18451 return dump_num_registers[3][preset-1];
18452 else if (CHIP_IS_E3B0(sc))
18453 return dump_num_registers[4][preset-1];
18459 bxe_get_total_regs_len32(struct bxe_softc *sc)
18461 uint32_t preset_idx;
18462 int regdump_len32 = 0;
18465 /* Calculate the total preset regs length */
18466 for (preset_idx = 1; preset_idx <= DUMP_MAX_PRESETS; preset_idx++) {
18467 regdump_len32 += bxe_get_preset_regs_len(sc, preset_idx);
18470 return regdump_len32;
18473 static const uint32_t *
18474 __bxe_get_page_addr_ar(struct bxe_softc *sc)
18476 if (CHIP_IS_E2(sc))
18477 return page_vals_e2;
18478 else if (CHIP_IS_E3(sc))
18479 return page_vals_e3;
18485 __bxe_get_page_reg_num(struct bxe_softc *sc)
18487 if (CHIP_IS_E2(sc))
18488 return PAGE_MODE_VALUES_E2;
18489 else if (CHIP_IS_E3(sc))
18490 return PAGE_MODE_VALUES_E3;
18495 static const uint32_t *
18496 __bxe_get_page_write_ar(struct bxe_softc *sc)
18498 if (CHIP_IS_E2(sc))
18499 return page_write_regs_e2;
18500 else if (CHIP_IS_E3(sc))
18501 return page_write_regs_e3;
18507 __bxe_get_page_write_num(struct bxe_softc *sc)
18509 if (CHIP_IS_E2(sc))
18510 return PAGE_WRITE_REGS_E2;
18511 else if (CHIP_IS_E3(sc))
18512 return PAGE_WRITE_REGS_E3;
18517 static const struct reg_addr *
18518 __bxe_get_page_read_ar(struct bxe_softc *sc)
18520 if (CHIP_IS_E2(sc))
18521 return page_read_regs_e2;
18522 else if (CHIP_IS_E3(sc))
18523 return page_read_regs_e3;
18529 __bxe_get_page_read_num(struct bxe_softc *sc)
18531 if (CHIP_IS_E2(sc))
18532 return PAGE_READ_REGS_E2;
18533 else if (CHIP_IS_E3(sc))
18534 return PAGE_READ_REGS_E3;
18540 bxe_is_reg_in_chip(struct bxe_softc *sc, const struct reg_addr *reg_info)
18542 if (CHIP_IS_E1(sc))
18543 return IS_E1_REG(reg_info->chips);
18544 else if (CHIP_IS_E1H(sc))
18545 return IS_E1H_REG(reg_info->chips);
18546 else if (CHIP_IS_E2(sc))
18547 return IS_E2_REG(reg_info->chips);
18548 else if (CHIP_IS_E3A0(sc))
18549 return IS_E3A0_REG(reg_info->chips);
18550 else if (CHIP_IS_E3B0(sc))
18551 return IS_E3B0_REG(reg_info->chips);
18557 bxe_is_wreg_in_chip(struct bxe_softc *sc, const struct wreg_addr *wreg_info)
18559 if (CHIP_IS_E1(sc))
18560 return IS_E1_REG(wreg_info->chips);
18561 else if (CHIP_IS_E1H(sc))
18562 return IS_E1H_REG(wreg_info->chips);
18563 else if (CHIP_IS_E2(sc))
18564 return IS_E2_REG(wreg_info->chips);
18565 else if (CHIP_IS_E3A0(sc))
18566 return IS_E3A0_REG(wreg_info->chips);
18567 else if (CHIP_IS_E3B0(sc))
18568 return IS_E3B0_REG(wreg_info->chips);
18574 * bxe_read_pages_regs - read "paged" registers
18576 * @bp device handle
18579 * Reads "paged" memories: memories that may only be read by first writing to a
18580 * specific address ("write address") and then reading from a specific address
18581 * ("read address"). There may be more than one write address per "page" and
18582 * more than one read address per write address.
18585 bxe_read_pages_regs(struct bxe_softc *sc, uint32_t *p, uint32_t preset)
18587 uint32_t i, j, k, n;
18589 /* addresses of the paged registers */
18590 const uint32_t *page_addr = __bxe_get_page_addr_ar(sc);
18591 /* number of paged registers */
18592 int num_pages = __bxe_get_page_reg_num(sc);
18593 /* write addresses */
18594 const uint32_t *write_addr = __bxe_get_page_write_ar(sc);
18595 /* number of write addresses */
18596 int write_num = __bxe_get_page_write_num(sc);
18597 /* read addresses info */
18598 const struct reg_addr *read_addr = __bxe_get_page_read_ar(sc);
18599 /* number of read addresses */
18600 int read_num = __bxe_get_page_read_num(sc);
18601 uint32_t addr, size;
18603 for (i = 0; i < num_pages; i++) {
18604 for (j = 0; j < write_num; j++) {
18605 REG_WR(sc, write_addr[j], page_addr[i]);
18607 for (k = 0; k < read_num; k++) {
18608 if (IS_REG_IN_PRESET(read_addr[k].presets, preset)) {
18609 size = read_addr[k].size;
18610 for (n = 0; n < size; n++) {
18611 addr = read_addr[k].addr + n*4;
18612 *p++ = REG_RD(sc, addr);
18623 bxe_get_preset_regs(struct bxe_softc *sc, uint32_t *p, uint32_t preset)
18625 uint32_t i, j, addr;
18626 const struct wreg_addr *wreg_addr_p = NULL;
18628 if (CHIP_IS_E1(sc))
18629 wreg_addr_p = &wreg_addr_e1;
18630 else if (CHIP_IS_E1H(sc))
18631 wreg_addr_p = &wreg_addr_e1h;
18632 else if (CHIP_IS_E2(sc))
18633 wreg_addr_p = &wreg_addr_e2;
18634 else if (CHIP_IS_E3A0(sc))
18635 wreg_addr_p = &wreg_addr_e3;
18636 else if (CHIP_IS_E3B0(sc))
18637 wreg_addr_p = &wreg_addr_e3b0;
18641 /* Read the idle_chk registers */
18642 for (i = 0; i < IDLE_REGS_COUNT; i++) {
18643 if (bxe_is_reg_in_chip(sc, &idle_reg_addrs[i]) &&
18644 IS_REG_IN_PRESET(idle_reg_addrs[i].presets, preset)) {
18645 for (j = 0; j < idle_reg_addrs[i].size; j++)
18646 *p++ = REG_RD(sc, idle_reg_addrs[i].addr + j*4);
18650 /* Read the regular registers */
18651 for (i = 0; i < REGS_COUNT; i++) {
18652 if (bxe_is_reg_in_chip(sc, ®_addrs[i]) &&
18653 IS_REG_IN_PRESET(reg_addrs[i].presets, preset)) {
18654 for (j = 0; j < reg_addrs[i].size; j++)
18655 *p++ = REG_RD(sc, reg_addrs[i].addr + j*4);
18659 /* Read the CAM registers */
18660 if (bxe_is_wreg_in_chip(sc, wreg_addr_p) &&
18661 IS_REG_IN_PRESET(wreg_addr_p->presets, preset)) {
18662 for (i = 0; i < wreg_addr_p->size; i++) {
18663 *p++ = REG_RD(sc, wreg_addr_p->addr + i*4);
18665 /* In case of wreg_addr register, read additional
18666 registers from read_regs array
18668 for (j = 0; j < wreg_addr_p->read_regs_count; j++) {
18669 addr = *(wreg_addr_p->read_regs);
18670 *p++ = REG_RD(sc, addr + j*4);
18675 /* Paged registers are supported in E2 & E3 only */
18676 if (CHIP_IS_E2(sc) || CHIP_IS_E3(sc)) {
18677 /* Read "paged" registers */
18678 bxe_read_pages_regs(sc, p, preset);
18685 bxe_grc_dump(struct bxe_softc *sc)
18688 uint32_t preset_idx;
18691 struct dump_header *d_hdr;
18695 uint32_t cmd_offset;
18696 struct ecore_ilt *ilt = SC_ILT(sc);
18697 struct bxe_fastpath *fp;
18698 struct ilt_client_info *ilt_cli;
18702 if (sc->grcdump_done || sc->grcdump_started)
18705 sc->grcdump_started = 1;
18706 BLOGI(sc, "Started collecting grcdump\n");
18708 grc_dump_size = (bxe_get_total_regs_len32(sc) * sizeof(uint32_t)) +
18709 sizeof(struct dump_header);
18711 sc->grc_dump = malloc(grc_dump_size, M_DEVBUF, M_NOWAIT);
18713 if (sc->grc_dump == NULL) {
18714 BLOGW(sc, "Unable to allocate memory for grcdump collection\n");
18720 /* Disable parity attentions as long as following dump may
18721 * cause false alarms by reading never written registers. We
18722 * will re-enable parity attentions right after the dump.
18725 /* Disable parity on path 0 */
18726 bxe_pretend_func(sc, 0);
18728 ecore_disable_blocks_parity(sc);
18730 /* Disable parity on path 1 */
18731 bxe_pretend_func(sc, 1);
18732 ecore_disable_blocks_parity(sc);
18734 /* Return to current function */
18735 bxe_pretend_func(sc, SC_ABS_FUNC(sc));
18737 buf = sc->grc_dump;
18738 d_hdr = sc->grc_dump;
18740 d_hdr->header_size = (sizeof(struct dump_header) >> 2) - 1;
18741 d_hdr->version = BNX2X_DUMP_VERSION;
18742 d_hdr->preset = DUMP_ALL_PRESETS;
18744 if (CHIP_IS_E1(sc)) {
18745 d_hdr->dump_meta_data = DUMP_CHIP_E1;
18746 } else if (CHIP_IS_E1H(sc)) {
18747 d_hdr->dump_meta_data = DUMP_CHIP_E1H;
18748 } else if (CHIP_IS_E2(sc)) {
18749 d_hdr->dump_meta_data = DUMP_CHIP_E2 |
18750 (BXE_PATH(sc) ? DUMP_PATH_1 : DUMP_PATH_0);
18751 } else if (CHIP_IS_E3A0(sc)) {
18752 d_hdr->dump_meta_data = DUMP_CHIP_E3A0 |
18753 (BXE_PATH(sc) ? DUMP_PATH_1 : DUMP_PATH_0);
18754 } else if (CHIP_IS_E3B0(sc)) {
18755 d_hdr->dump_meta_data = DUMP_CHIP_E3B0 |
18756 (BXE_PATH(sc) ? DUMP_PATH_1 : DUMP_PATH_0);
18759 buf += sizeof(struct dump_header);
18761 for (preset_idx = 1; preset_idx <= DUMP_MAX_PRESETS; preset_idx++) {
18763 /* Skip presets with IOR */
18764 if ((preset_idx == 2) || (preset_idx == 5) || (preset_idx == 8) ||
18765 (preset_idx == 11))
18768 rval = bxe_get_preset_regs(sc, (uint32_t *)buf, preset_idx);
18773 size = bxe_get_preset_regs_len(sc, preset_idx) * (sizeof (uint32_t));
18778 bxe_pretend_func(sc, 0);
18779 ecore_clear_blocks_parity(sc);
18780 ecore_enable_blocks_parity(sc);
18782 bxe_pretend_func(sc, 1);
18783 ecore_clear_blocks_parity(sc);
18784 ecore_enable_blocks_parity(sc);
18786 /* Return to current function */
18787 bxe_pretend_func(sc, SC_ABS_FUNC(sc));
18791 if(sc->state == BXE_STATE_OPEN) {
18792 if(sc->fw_stats_req != NULL) {
18793 BLOGI(sc, "fw stats start_paddr %#jx end_paddr %#jx vaddr %p size 0x%x\n",
18794 (uintmax_t)sc->fw_stats_req_mapping,
18795 (uintmax_t)sc->fw_stats_data_mapping,
18796 sc->fw_stats_req, (sc->fw_stats_req_size + sc->fw_stats_data_size));
18798 if(sc->def_sb != NULL) {
18799 BLOGI(sc, "def_status_block paddr %p vaddr %p size 0x%zx\n",
18800 (void *)sc->def_sb_dma.paddr, sc->def_sb,
18801 sizeof(struct host_sp_status_block));
18803 if(sc->eq_dma.vaddr != NULL) {
18804 BLOGI(sc, "event_queue paddr %#jx vaddr %p size 0x%x\n",
18805 (uintmax_t)sc->eq_dma.paddr, sc->eq_dma.vaddr, BCM_PAGE_SIZE);
18807 if(sc->sp_dma.vaddr != NULL) {
18808 BLOGI(sc, "slow path paddr %#jx vaddr %p size 0x%zx\n",
18809 (uintmax_t)sc->sp_dma.paddr, sc->sp_dma.vaddr,
18810 sizeof(struct bxe_slowpath));
18812 if(sc->spq_dma.vaddr != NULL) {
18813 BLOGI(sc, "slow path queue paddr %#jx vaddr %p size 0x%x\n",
18814 (uintmax_t)sc->spq_dma.paddr, sc->spq_dma.vaddr, BCM_PAGE_SIZE);
18816 if(sc->gz_buf_dma.vaddr != NULL) {
18817 BLOGI(sc, "fw_buf paddr %#jx vaddr %p size 0x%x\n",
18818 (uintmax_t)sc->gz_buf_dma.paddr, sc->gz_buf_dma.vaddr,
18821 for (i = 0; i < sc->num_queues; i++) {
18823 if(fp->sb_dma.vaddr != NULL && fp->tx_dma.vaddr != NULL &&
18824 fp->rx_dma.vaddr != NULL && fp->rcq_dma.vaddr != NULL &&
18825 fp->rx_sge_dma.vaddr != NULL) {
18827 BLOGI(sc, "FP status block fp %d paddr %#jx vaddr %p size 0x%zx\n", i,
18828 (uintmax_t)fp->sb_dma.paddr, fp->sb_dma.vaddr,
18829 sizeof(union bxe_host_hc_status_block));
18830 BLOGI(sc, "TX BD CHAIN fp %d paddr %#jx vaddr %p size 0x%x\n", i,
18831 (uintmax_t)fp->tx_dma.paddr, fp->tx_dma.vaddr,
18832 (BCM_PAGE_SIZE * TX_BD_NUM_PAGES));
18833 BLOGI(sc, "RX BD CHAIN fp %d paddr %#jx vaddr %p size 0x%x\n", i,
18834 (uintmax_t)fp->rx_dma.paddr, fp->rx_dma.vaddr,
18835 (BCM_PAGE_SIZE * RX_BD_NUM_PAGES));
18836 BLOGI(sc, "RX RCQ CHAIN fp %d paddr %#jx vaddr %p size 0x%zx\n", i,
18837 (uintmax_t)fp->rcq_dma.paddr, fp->rcq_dma.vaddr,
18838 (BCM_PAGE_SIZE * RCQ_NUM_PAGES));
18839 BLOGI(sc, "RX SGE CHAIN fp %d paddr %#jx vaddr %p size 0x%x\n", i,
18840 (uintmax_t)fp->rx_sge_dma.paddr, fp->rx_sge_dma.vaddr,
18841 (BCM_PAGE_SIZE * RX_SGE_NUM_PAGES));
18845 ilt_cli = &ilt->clients[1];
18846 if(ilt->lines != NULL) {
18847 for (i = ilt_cli->start; i <= ilt_cli->end; i++) {
18848 BLOGI(sc, "ECORE_ILT paddr %#jx vaddr %p size 0x%x\n",
18849 (uintmax_t)(((struct bxe_dma *)((&ilt->lines[i])->page))->paddr),
18850 ((struct bxe_dma *)((&ilt->lines[i])->page))->vaddr, BCM_PAGE_SIZE);
18856 cmd_offset = DMAE_REG_CMD_MEM;
18857 for (i = 0; i < 224; i++) {
18858 reg_addr = (cmd_offset +(i * 4));
18859 reg_val = REG_RD(sc, reg_addr);
18860 BLOGI(sc, "DMAE_REG_CMD_MEM i=%d reg_addr 0x%x reg_val 0x%08x\n",i,
18861 reg_addr, reg_val);
18865 BLOGI(sc, "Collection of grcdump done\n");
18866 sc->grcdump_done = 1;
18871 bxe_add_cdev(struct bxe_softc *sc)
18873 sc->eeprom = malloc(BXE_EEPROM_MAX_DATA_LEN, M_DEVBUF, M_NOWAIT);
18875 if (sc->eeprom == NULL) {
18876 BLOGW(sc, "Unable to alloc for eeprom size buffer\n");
18880 sc->ioctl_dev = make_dev(&bxe_cdevsw,
18881 sc->ifnet->if_dunit,
18886 if_name(sc->ifnet));
18888 if (sc->ioctl_dev == NULL) {
18889 free(sc->eeprom, M_DEVBUF);
18894 sc->ioctl_dev->si_drv1 = sc;
18900 bxe_del_cdev(struct bxe_softc *sc)
18902 if (sc->ioctl_dev != NULL)
18903 destroy_dev(sc->ioctl_dev);
18905 if (sc->eeprom != NULL) {
18906 free(sc->eeprom, M_DEVBUF);
18909 sc->ioctl_dev = NULL;
18914 static bool bxe_is_nvram_accessible(struct bxe_softc *sc)
18917 if ((sc->ifnet->if_drv_flags & IFF_DRV_RUNNING) == 0)
18925 bxe_wr_eeprom(struct bxe_softc *sc, void *data, uint32_t offset, uint32_t len)
18929 if(!bxe_is_nvram_accessible(sc)) {
18930 BLOGW(sc, "Cannot access eeprom when interface is down\n");
18933 rval = bxe_nvram_write(sc, offset, (uint8_t *)data, len);
18940 bxe_rd_eeprom(struct bxe_softc *sc, void *data, uint32_t offset, uint32_t len)
18944 if(!bxe_is_nvram_accessible(sc)) {
18945 BLOGW(sc, "Cannot access eeprom when interface is down\n");
18948 rval = bxe_nvram_read(sc, offset, (uint8_t *)data, len);
18954 bxe_eeprom_rd_wr(struct bxe_softc *sc, bxe_eeprom_t *eeprom)
18958 switch (eeprom->eeprom_cmd) {
18960 case BXE_EEPROM_CMD_SET_EEPROM:
18962 rval = copyin(eeprom->eeprom_data, sc->eeprom,
18963 eeprom->eeprom_data_len);
18968 rval = bxe_wr_eeprom(sc, sc->eeprom, eeprom->eeprom_offset,
18969 eeprom->eeprom_data_len);
18972 case BXE_EEPROM_CMD_GET_EEPROM:
18974 rval = bxe_rd_eeprom(sc, sc->eeprom, eeprom->eeprom_offset,
18975 eeprom->eeprom_data_len);
18981 rval = copyout(sc->eeprom, eeprom->eeprom_data,
18982 eeprom->eeprom_data_len);
18991 BLOGW(sc, "ioctl cmd %d failed rval %d\n", eeprom->eeprom_cmd, rval);
18998 bxe_get_settings(struct bxe_softc *sc, bxe_dev_setting_t *dev_p)
19000 uint32_t ext_phy_config;
19001 int port = SC_PORT(sc);
19002 int cfg_idx = bxe_get_link_cfg_idx(sc);
19004 dev_p->supported = sc->port.supported[cfg_idx] |
19005 (sc->port.supported[cfg_idx ^ 1] &
19006 (ELINK_SUPPORTED_TP | ELINK_SUPPORTED_FIBRE));
19007 dev_p->advertising = sc->port.advertising[cfg_idx];
19008 if(sc->link_params.phy[bxe_get_cur_phy_idx(sc)].media_type ==
19009 ELINK_ETH_PHY_SFP_1G_FIBER) {
19010 dev_p->supported = ~(ELINK_SUPPORTED_10000baseT_Full);
19011 dev_p->advertising &= ~(ADVERTISED_10000baseT_Full);
19013 if ((sc->state == BXE_STATE_OPEN) && sc->link_vars.link_up &&
19014 !(sc->flags & BXE_MF_FUNC_DIS)) {
19015 dev_p->duplex = sc->link_vars.duplex;
19016 if (IS_MF(sc) && !BXE_NOMCP(sc))
19017 dev_p->speed = bxe_get_mf_speed(sc);
19019 dev_p->speed = sc->link_vars.line_speed;
19021 dev_p->duplex = DUPLEX_UNKNOWN;
19022 dev_p->speed = SPEED_UNKNOWN;
19025 dev_p->port = bxe_media_detect(sc);
19027 ext_phy_config = SHMEM_RD(sc,
19028 dev_info.port_hw_config[port].external_phy_config);
19029 if((ext_phy_config & PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK) ==
19030 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
19031 dev_p->phy_address = sc->port.phy_addr;
19032 else if(((ext_phy_config & PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK) !=
19033 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
19034 ((ext_phy_config & PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK) !=
19035 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
19036 dev_p->phy_address = ELINK_XGXS_EXT_PHY_ADDR(ext_phy_config);
19038 dev_p->phy_address = 0;
19040 if(sc->link_params.req_line_speed[cfg_idx] == ELINK_SPEED_AUTO_NEG)
19041 dev_p->autoneg = AUTONEG_ENABLE;
19043 dev_p->autoneg = AUTONEG_DISABLE;
19050 bxe_eioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
19053 struct bxe_softc *sc;
19056 bxe_grcdump_t *dump = NULL;
19058 bxe_drvinfo_t *drv_infop = NULL;
19059 bxe_dev_setting_t *dev_p;
19060 bxe_dev_setting_t dev_set;
19061 bxe_get_regs_t *reg_p;
19062 bxe_reg_rdw_t *reg_rdw_p;
19063 bxe_pcicfg_rdw_t *cfg_rdw_p;
19064 bxe_perm_mac_addr_t *mac_addr_p;
19067 if ((sc = (struct bxe_softc *)dev->si_drv1) == NULL)
19072 dump = (bxe_grcdump_t *)data;
19076 case BXE_GRC_DUMP_SIZE:
19077 dump->pci_func = sc->pcie_func;
19078 dump->grcdump_size =
19079 (bxe_get_total_regs_len32(sc) * sizeof(uint32_t)) +
19080 sizeof(struct dump_header);
19085 grc_dump_size = (bxe_get_total_regs_len32(sc) * sizeof(uint32_t)) +
19086 sizeof(struct dump_header);
19087 if ((!sc->trigger_grcdump) || (dump->grcdump == NULL) ||
19088 (dump->grcdump_size < grc_dump_size)) {
19093 if((sc->trigger_grcdump) && (!sc->grcdump_done) &&
19094 (!sc->grcdump_started)) {
19095 rval = bxe_grc_dump(sc);
19098 if((!rval) && (sc->grcdump_done) && (sc->grcdump_started) &&
19099 (sc->grc_dump != NULL)) {
19100 dump->grcdump_dwords = grc_dump_size >> 2;
19101 rval = copyout(sc->grc_dump, dump->grcdump, grc_dump_size);
19102 free(sc->grc_dump, M_DEVBUF);
19103 sc->grc_dump = NULL;
19104 sc->grcdump_started = 0;
19105 sc->grcdump_done = 0;
19111 drv_infop = (bxe_drvinfo_t *)data;
19112 snprintf(drv_infop->drv_name, BXE_DRV_NAME_LENGTH, "%s", "bxe");
19113 snprintf(drv_infop->drv_version, BXE_DRV_VERSION_LENGTH, "v:%s",
19114 BXE_DRIVER_VERSION);
19115 snprintf(drv_infop->mfw_version, BXE_MFW_VERSION_LENGTH, "%s",
19116 sc->devinfo.bc_ver_str);
19117 snprintf(drv_infop->stormfw_version, BXE_STORMFW_VERSION_LENGTH,
19118 "%s", sc->fw_ver_str);
19119 drv_infop->eeprom_dump_len = sc->devinfo.flash_size;
19120 drv_infop->reg_dump_len =
19121 (bxe_get_total_regs_len32(sc) * sizeof(uint32_t))
19122 + sizeof(struct dump_header);
19123 snprintf(drv_infop->bus_info, BXE_BUS_INFO_LENGTH, "%d:%d:%d",
19124 sc->pcie_bus, sc->pcie_device, sc->pcie_func);
19127 case BXE_DEV_SETTING:
19128 dev_p = (bxe_dev_setting_t *)data;
19129 bxe_get_settings(sc, &dev_set);
19130 dev_p->supported = dev_set.supported;
19131 dev_p->advertising = dev_set.advertising;
19132 dev_p->speed = dev_set.speed;
19133 dev_p->duplex = dev_set.duplex;
19134 dev_p->port = dev_set.port;
19135 dev_p->phy_address = dev_set.phy_address;
19136 dev_p->autoneg = dev_set.autoneg;
19142 reg_p = (bxe_get_regs_t *)data;
19143 grc_dump_size = reg_p->reg_buf_len;
19145 if((!sc->grcdump_done) && (!sc->grcdump_started)) {
19148 if((sc->grcdump_done) && (sc->grcdump_started) &&
19149 (sc->grc_dump != NULL)) {
19150 rval = copyout(sc->grc_dump, reg_p->reg_buf, grc_dump_size);
19151 free(sc->grc_dump, M_DEVBUF);
19152 sc->grc_dump = NULL;
19153 sc->grcdump_started = 0;
19154 sc->grcdump_done = 0;
19160 reg_rdw_p = (bxe_reg_rdw_t *)data;
19161 if((reg_rdw_p->reg_cmd == BXE_READ_REG_CMD) &&
19162 (reg_rdw_p->reg_access_type == BXE_REG_ACCESS_DIRECT))
19163 reg_rdw_p->reg_val = REG_RD(sc, reg_rdw_p->reg_id);
19165 if((reg_rdw_p->reg_cmd == BXE_WRITE_REG_CMD) &&
19166 (reg_rdw_p->reg_access_type == BXE_REG_ACCESS_DIRECT))
19167 REG_WR(sc, reg_rdw_p->reg_id, reg_rdw_p->reg_val);
19171 case BXE_RDW_PCICFG:
19172 cfg_rdw_p = (bxe_pcicfg_rdw_t *)data;
19173 if(cfg_rdw_p->cfg_cmd == BXE_READ_PCICFG) {
19175 cfg_rdw_p->cfg_val = pci_read_config(sc->dev, cfg_rdw_p->cfg_id,
19176 cfg_rdw_p->cfg_width);
19178 } else if(cfg_rdw_p->cfg_cmd == BXE_WRITE_PCICFG) {
19179 pci_write_config(sc->dev, cfg_rdw_p->cfg_id, cfg_rdw_p->cfg_val,
19180 cfg_rdw_p->cfg_width);
19182 BLOGW(sc, "BXE_RDW_PCICFG ioctl wrong cmd passed\n");
19187 mac_addr_p = (bxe_perm_mac_addr_t *)data;
19188 snprintf(mac_addr_p->mac_addr_str, sizeof(sc->mac_addr_str), "%s",
19193 rval = bxe_eeprom_rd_wr(sc, (bxe_eeprom_t *)data);