2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2007-2014 QLogic Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #define BXE_DRIVER_VERSION "1.78.91"
36 #include "ecore_init.h"
37 #include "ecore_init_ops.h"
39 #include "57710_int_offsets.h"
40 #include "57711_int_offsets.h"
41 #include "57712_int_offsets.h"
44 * CTLTYPE_U64 and sysctl_handle_64 were added in r217616. Define these
45 * explicitly here for older kernels that don't include this changeset.
48 #define CTLTYPE_U64 CTLTYPE_QUAD
49 #define sysctl_handle_64 sysctl_handle_quad
53 * CSUM_TCP_IPV6 and CSUM_UDP_IPV6 were added in r236170. Define these
54 * here as zero(0) for older kernels that don't include this changeset
55 * thereby masking the functionality.
58 #define CSUM_TCP_IPV6 0
59 #define CSUM_UDP_IPV6 0
62 #define BXE_DEF_SB_ATT_IDX 0x0001
63 #define BXE_DEF_SB_IDX 0x0002
66 * FLR Support - bxe_pf_flr_clnup() is called during nic_load in the per
67 * function HW initialization.
69 #define FLR_WAIT_USEC 10000 /* 10 msecs */
70 #define FLR_WAIT_INTERVAL 50 /* usecs */
71 #define FLR_POLL_CNT (FLR_WAIT_USEC / FLR_WAIT_INTERVAL) /* 200 */
73 struct pbf_pN_buf_regs {
80 struct pbf_pN_cmd_regs {
87 * PCI Device ID Table used by bxe_probe().
89 #define BXE_DEVDESC_MAX 64
90 static struct bxe_device_type bxe_devs[] = {
94 PCI_ANY_ID, PCI_ANY_ID,
95 "QLogic NetXtreme II BCM57710 10GbE"
100 PCI_ANY_ID, PCI_ANY_ID,
101 "QLogic NetXtreme II BCM57711 10GbE"
106 PCI_ANY_ID, PCI_ANY_ID,
107 "QLogic NetXtreme II BCM57711E 10GbE"
112 PCI_ANY_ID, PCI_ANY_ID,
113 "QLogic NetXtreme II BCM57712 10GbE"
118 PCI_ANY_ID, PCI_ANY_ID,
119 "QLogic NetXtreme II BCM57712 MF 10GbE"
124 PCI_ANY_ID, PCI_ANY_ID,
125 "QLogic NetXtreme II BCM57800 10GbE"
130 PCI_ANY_ID, PCI_ANY_ID,
131 "QLogic NetXtreme II BCM57800 MF 10GbE"
136 PCI_ANY_ID, PCI_ANY_ID,
137 "QLogic NetXtreme II BCM57810 10GbE"
142 PCI_ANY_ID, PCI_ANY_ID,
143 "QLogic NetXtreme II BCM57810 MF 10GbE"
148 PCI_ANY_ID, PCI_ANY_ID,
149 "QLogic NetXtreme II BCM57811 10GbE"
154 PCI_ANY_ID, PCI_ANY_ID,
155 "QLogic NetXtreme II BCM57811 MF 10GbE"
160 PCI_ANY_ID, PCI_ANY_ID,
161 "QLogic NetXtreme II BCM57840 4x10GbE"
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 2x20GbE"
178 PCI_ANY_ID, PCI_ANY_ID,
179 "QLogic NetXtreme II BCM57840 MF 10GbE"
186 MALLOC_DECLARE(M_BXE_ILT);
187 MALLOC_DEFINE(M_BXE_ILT, "bxe_ilt", "bxe ILT pointer");
190 * FreeBSD device entry points.
192 static int bxe_probe(device_t);
193 static int bxe_attach(device_t);
194 static int bxe_detach(device_t);
195 static int bxe_shutdown(device_t);
199 * FreeBSD KLD module/device interface event handler method.
201 static device_method_t bxe_methods[] = {
202 /* Device interface (device_if.h) */
203 DEVMETHOD(device_probe, bxe_probe),
204 DEVMETHOD(device_attach, bxe_attach),
205 DEVMETHOD(device_detach, bxe_detach),
206 DEVMETHOD(device_shutdown, bxe_shutdown),
207 /* Bus interface (bus_if.h) */
208 DEVMETHOD(bus_print_child, bus_generic_print_child),
209 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
214 * FreeBSD KLD Module data declaration
216 static driver_t bxe_driver = {
217 "bxe", /* module name */
218 bxe_methods, /* event handler */
219 sizeof(struct bxe_softc) /* extra data */
223 * FreeBSD dev class is needed to manage dev instances and
224 * to associate with a bus type
226 static devclass_t bxe_devclass;
228 MODULE_DEPEND(bxe, pci, 1, 1, 1);
229 MODULE_DEPEND(bxe, ether, 1, 1, 1);
230 DRIVER_MODULE(bxe, pci, bxe_driver, bxe_devclass, 0, 0);
232 DEBUGNET_DEFINE(bxe);
234 /* resources needed for unloading a previously loaded device */
236 #define BXE_PREV_WAIT_NEEDED 1
237 struct mtx bxe_prev_mtx;
238 MTX_SYSINIT(bxe_prev_mtx, &bxe_prev_mtx, "bxe_prev_lock", MTX_DEF);
239 struct bxe_prev_list_node {
240 LIST_ENTRY(bxe_prev_list_node) node;
244 uint8_t aer; /* XXX automatic error recovery */
247 static LIST_HEAD(, bxe_prev_list_node) bxe_prev_list = LIST_HEAD_INITIALIZER(bxe_prev_list);
249 static int load_count[2][3] = { {0} }; /* per-path: 0-common, 1-port0, 2-port1 */
251 /* Tunable device values... */
253 SYSCTL_NODE(_hw, OID_AUTO, bxe, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
254 "bxe driver parameters");
257 unsigned long bxe_debug = 0;
258 SYSCTL_ULONG(_hw_bxe, OID_AUTO, debug, CTLFLAG_RDTUN,
259 &bxe_debug, 0, "Debug logging mode");
261 /* Interrupt Mode: 0 (IRQ), 1 (MSI/IRQ), and 2 (MSI-X/MSI/IRQ) */
262 static int bxe_interrupt_mode = INTR_MODE_MSIX;
263 SYSCTL_INT(_hw_bxe, OID_AUTO, interrupt_mode, CTLFLAG_RDTUN,
264 &bxe_interrupt_mode, 0, "Interrupt (MSI-X/MSI/INTx) mode");
266 /* Number of Queues: 0 (Auto) or 1 to 16 (fixed queue number) */
267 static int bxe_queue_count = 4;
268 SYSCTL_INT(_hw_bxe, OID_AUTO, queue_count, CTLFLAG_RDTUN,
269 &bxe_queue_count, 0, "Multi-Queue queue count");
271 /* max number of buffers per queue (default RX_BD_USABLE) */
272 static int bxe_max_rx_bufs = 0;
273 SYSCTL_INT(_hw_bxe, OID_AUTO, max_rx_bufs, CTLFLAG_RDTUN,
274 &bxe_max_rx_bufs, 0, "Maximum Number of Rx Buffers Per Queue");
276 /* Host interrupt coalescing RX tick timer (usecs) */
277 static int bxe_hc_rx_ticks = 25;
278 SYSCTL_INT(_hw_bxe, OID_AUTO, hc_rx_ticks, CTLFLAG_RDTUN,
279 &bxe_hc_rx_ticks, 0, "Host Coalescing Rx ticks");
281 /* Host interrupt coalescing TX tick timer (usecs) */
282 static int bxe_hc_tx_ticks = 50;
283 SYSCTL_INT(_hw_bxe, OID_AUTO, hc_tx_ticks, CTLFLAG_RDTUN,
284 &bxe_hc_tx_ticks, 0, "Host Coalescing Tx ticks");
286 /* Maximum number of Rx packets to process at a time */
287 static int bxe_rx_budget = 0xffffffff;
288 SYSCTL_INT(_hw_bxe, OID_AUTO, rx_budget, CTLFLAG_TUN,
289 &bxe_rx_budget, 0, "Rx processing budget");
291 /* Maximum LRO aggregation size */
292 static int bxe_max_aggregation_size = 0;
293 SYSCTL_INT(_hw_bxe, OID_AUTO, max_aggregation_size, CTLFLAG_TUN,
294 &bxe_max_aggregation_size, 0, "max aggregation size");
296 /* PCI MRRS: -1 (Auto), 0 (128B), 1 (256B), 2 (512B), 3 (1KB) */
297 static int bxe_mrrs = -1;
298 SYSCTL_INT(_hw_bxe, OID_AUTO, mrrs, CTLFLAG_RDTUN,
299 &bxe_mrrs, 0, "PCIe maximum read request size");
301 /* AutoGrEEEn: 0 (hardware default), 1 (force on), 2 (force off) */
302 static int bxe_autogreeen = 0;
303 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 SYSCTL_INT(_hw_bxe, OID_AUTO, udp_rss, CTLFLAG_RDTUN,
309 &bxe_udp_rss, 0, "UDP RSS support");
312 #define STAT_NAME_LEN 32 /* no stat names below can be longer than this */
314 #define STATS_OFFSET32(stat_name) \
315 (offsetof(struct bxe_eth_stats, stat_name) / 4)
317 #define Q_STATS_OFFSET32(stat_name) \
318 (offsetof(struct bxe_eth_q_stats, stat_name) / 4)
320 static const struct {
324 #define STATS_FLAGS_PORT 1
325 #define STATS_FLAGS_FUNC 2 /* MF only cares about function stats */
326 #define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
327 char string[STAT_NAME_LEN];
328 } bxe_eth_stats_arr[] = {
329 { STATS_OFFSET32(total_bytes_received_hi),
330 8, STATS_FLAGS_BOTH, "rx_bytes" },
331 { STATS_OFFSET32(error_bytes_received_hi),
332 8, STATS_FLAGS_BOTH, "rx_error_bytes" },
333 { STATS_OFFSET32(total_unicast_packets_received_hi),
334 8, STATS_FLAGS_BOTH, "rx_ucast_packets" },
335 { STATS_OFFSET32(total_multicast_packets_received_hi),
336 8, STATS_FLAGS_BOTH, "rx_mcast_packets" },
337 { STATS_OFFSET32(total_broadcast_packets_received_hi),
338 8, STATS_FLAGS_BOTH, "rx_bcast_packets" },
339 { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
340 8, STATS_FLAGS_PORT, "rx_crc_errors" },
341 { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
342 8, STATS_FLAGS_PORT, "rx_align_errors" },
343 { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
344 8, STATS_FLAGS_PORT, "rx_undersize_packets" },
345 { STATS_OFFSET32(etherstatsoverrsizepkts_hi),
346 8, STATS_FLAGS_PORT, "rx_oversize_packets" },
347 { STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
348 8, STATS_FLAGS_PORT, "rx_fragments" },
349 { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
350 8, STATS_FLAGS_PORT, "rx_jabbers" },
351 { STATS_OFFSET32(no_buff_discard_hi),
352 8, STATS_FLAGS_BOTH, "rx_discards" },
353 { STATS_OFFSET32(mac_filter_discard),
354 4, STATS_FLAGS_PORT, "rx_filtered_packets" },
355 { STATS_OFFSET32(mf_tag_discard),
356 4, STATS_FLAGS_PORT, "rx_mf_tag_discard" },
357 { STATS_OFFSET32(pfc_frames_received_hi),
358 8, STATS_FLAGS_PORT, "pfc_frames_received" },
359 { STATS_OFFSET32(pfc_frames_sent_hi),
360 8, STATS_FLAGS_PORT, "pfc_frames_sent" },
361 { STATS_OFFSET32(brb_drop_hi),
362 8, STATS_FLAGS_PORT, "rx_brb_discard" },
363 { STATS_OFFSET32(brb_truncate_hi),
364 8, STATS_FLAGS_PORT, "rx_brb_truncate" },
365 { STATS_OFFSET32(pause_frames_received_hi),
366 8, STATS_FLAGS_PORT, "rx_pause_frames" },
367 { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
368 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" },
369 { STATS_OFFSET32(nig_timer_max),
370 4, STATS_FLAGS_PORT, "rx_constant_pause_events" },
371 { STATS_OFFSET32(total_bytes_transmitted_hi),
372 8, STATS_FLAGS_BOTH, "tx_bytes" },
373 { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
374 8, STATS_FLAGS_PORT, "tx_error_bytes" },
375 { STATS_OFFSET32(total_unicast_packets_transmitted_hi),
376 8, STATS_FLAGS_BOTH, "tx_ucast_packets" },
377 { STATS_OFFSET32(total_multicast_packets_transmitted_hi),
378 8, STATS_FLAGS_BOTH, "tx_mcast_packets" },
379 { STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
380 8, STATS_FLAGS_BOTH, "tx_bcast_packets" },
381 { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
382 8, STATS_FLAGS_PORT, "tx_mac_errors" },
383 { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
384 8, STATS_FLAGS_PORT, "tx_carrier_errors" },
385 { STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
386 8, STATS_FLAGS_PORT, "tx_single_collisions" },
387 { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
388 8, STATS_FLAGS_PORT, "tx_multi_collisions" },
389 { STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
390 8, STATS_FLAGS_PORT, "tx_deferred" },
391 { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
392 8, STATS_FLAGS_PORT, "tx_excess_collisions" },
393 { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
394 8, STATS_FLAGS_PORT, "tx_late_collisions" },
395 { STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
396 8, STATS_FLAGS_PORT, "tx_total_collisions" },
397 { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
398 8, STATS_FLAGS_PORT, "tx_64_byte_packets" },
399 { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
400 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" },
401 { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
402 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" },
403 { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
404 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" },
405 { STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
406 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" },
407 { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
408 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" },
409 { STATS_OFFSET32(etherstatspktsover1522octets_hi),
410 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" },
411 { STATS_OFFSET32(pause_frames_sent_hi),
412 8, STATS_FLAGS_PORT, "tx_pause_frames" },
413 { STATS_OFFSET32(total_tpa_aggregations_hi),
414 8, STATS_FLAGS_FUNC, "tpa_aggregations" },
415 { STATS_OFFSET32(total_tpa_aggregated_frames_hi),
416 8, STATS_FLAGS_FUNC, "tpa_aggregated_frames"},
417 { STATS_OFFSET32(total_tpa_bytes_hi),
418 8, STATS_FLAGS_FUNC, "tpa_bytes"},
419 { STATS_OFFSET32(eee_tx_lpi),
420 4, STATS_FLAGS_PORT, "eee_tx_lpi"},
421 { STATS_OFFSET32(rx_calls),
422 4, STATS_FLAGS_FUNC, "rx_calls"},
423 { STATS_OFFSET32(rx_pkts),
424 4, STATS_FLAGS_FUNC, "rx_pkts"},
425 { STATS_OFFSET32(rx_tpa_pkts),
426 4, STATS_FLAGS_FUNC, "rx_tpa_pkts"},
427 { STATS_OFFSET32(rx_erroneous_jumbo_sge_pkts),
428 4, STATS_FLAGS_FUNC, "rx_erroneous_jumbo_sge_pkts"},
429 { STATS_OFFSET32(rx_bxe_service_rxsgl),
430 4, STATS_FLAGS_FUNC, "rx_bxe_service_rxsgl"},
431 { STATS_OFFSET32(rx_jumbo_sge_pkts),
432 4, STATS_FLAGS_FUNC, "rx_jumbo_sge_pkts"},
433 { STATS_OFFSET32(rx_soft_errors),
434 4, STATS_FLAGS_FUNC, "rx_soft_errors"},
435 { STATS_OFFSET32(rx_hw_csum_errors),
436 4, STATS_FLAGS_FUNC, "rx_hw_csum_errors"},
437 { STATS_OFFSET32(rx_ofld_frames_csum_ip),
438 4, STATS_FLAGS_FUNC, "rx_ofld_frames_csum_ip"},
439 { STATS_OFFSET32(rx_ofld_frames_csum_tcp_udp),
440 4, STATS_FLAGS_FUNC, "rx_ofld_frames_csum_tcp_udp"},
441 { STATS_OFFSET32(rx_budget_reached),
442 4, STATS_FLAGS_FUNC, "rx_budget_reached"},
443 { STATS_OFFSET32(tx_pkts),
444 4, STATS_FLAGS_FUNC, "tx_pkts"},
445 { STATS_OFFSET32(tx_soft_errors),
446 4, STATS_FLAGS_FUNC, "tx_soft_errors"},
447 { STATS_OFFSET32(tx_ofld_frames_csum_ip),
448 4, STATS_FLAGS_FUNC, "tx_ofld_frames_csum_ip"},
449 { STATS_OFFSET32(tx_ofld_frames_csum_tcp),
450 4, STATS_FLAGS_FUNC, "tx_ofld_frames_csum_tcp"},
451 { STATS_OFFSET32(tx_ofld_frames_csum_udp),
452 4, STATS_FLAGS_FUNC, "tx_ofld_frames_csum_udp"},
453 { STATS_OFFSET32(tx_ofld_frames_lso),
454 4, STATS_FLAGS_FUNC, "tx_ofld_frames_lso"},
455 { STATS_OFFSET32(tx_ofld_frames_lso_hdr_splits),
456 4, STATS_FLAGS_FUNC, "tx_ofld_frames_lso_hdr_splits"},
457 { STATS_OFFSET32(tx_encap_failures),
458 4, STATS_FLAGS_FUNC, "tx_encap_failures"},
459 { STATS_OFFSET32(tx_hw_queue_full),
460 4, STATS_FLAGS_FUNC, "tx_hw_queue_full"},
461 { STATS_OFFSET32(tx_hw_max_queue_depth),
462 4, STATS_FLAGS_FUNC, "tx_hw_max_queue_depth"},
463 { STATS_OFFSET32(tx_dma_mapping_failure),
464 4, STATS_FLAGS_FUNC, "tx_dma_mapping_failure"},
465 { STATS_OFFSET32(tx_max_drbr_queue_depth),
466 4, STATS_FLAGS_FUNC, "tx_max_drbr_queue_depth"},
467 { STATS_OFFSET32(tx_window_violation_std),
468 4, STATS_FLAGS_FUNC, "tx_window_violation_std"},
469 { STATS_OFFSET32(tx_window_violation_tso),
470 4, STATS_FLAGS_FUNC, "tx_window_violation_tso"},
471 { STATS_OFFSET32(tx_chain_lost_mbuf),
472 4, STATS_FLAGS_FUNC, "tx_chain_lost_mbuf"},
473 { STATS_OFFSET32(tx_frames_deferred),
474 4, STATS_FLAGS_FUNC, "tx_frames_deferred"},
475 { STATS_OFFSET32(tx_queue_xoff),
476 4, STATS_FLAGS_FUNC, "tx_queue_xoff"},
477 { STATS_OFFSET32(mbuf_defrag_attempts),
478 4, STATS_FLAGS_FUNC, "mbuf_defrag_attempts"},
479 { STATS_OFFSET32(mbuf_defrag_failures),
480 4, STATS_FLAGS_FUNC, "mbuf_defrag_failures"},
481 { STATS_OFFSET32(mbuf_rx_bd_alloc_failed),
482 4, STATS_FLAGS_FUNC, "mbuf_rx_bd_alloc_failed"},
483 { STATS_OFFSET32(mbuf_rx_bd_mapping_failed),
484 4, STATS_FLAGS_FUNC, "mbuf_rx_bd_mapping_failed"},
485 { STATS_OFFSET32(mbuf_rx_tpa_alloc_failed),
486 4, STATS_FLAGS_FUNC, "mbuf_rx_tpa_alloc_failed"},
487 { STATS_OFFSET32(mbuf_rx_tpa_mapping_failed),
488 4, STATS_FLAGS_FUNC, "mbuf_rx_tpa_mapping_failed"},
489 { STATS_OFFSET32(mbuf_rx_sge_alloc_failed),
490 4, STATS_FLAGS_FUNC, "mbuf_rx_sge_alloc_failed"},
491 { STATS_OFFSET32(mbuf_rx_sge_mapping_failed),
492 4, STATS_FLAGS_FUNC, "mbuf_rx_sge_mapping_failed"},
493 { STATS_OFFSET32(mbuf_alloc_tx),
494 4, STATS_FLAGS_FUNC, "mbuf_alloc_tx"},
495 { STATS_OFFSET32(mbuf_alloc_rx),
496 4, STATS_FLAGS_FUNC, "mbuf_alloc_rx"},
497 { STATS_OFFSET32(mbuf_alloc_sge),
498 4, STATS_FLAGS_FUNC, "mbuf_alloc_sge"},
499 { STATS_OFFSET32(mbuf_alloc_tpa),
500 4, STATS_FLAGS_FUNC, "mbuf_alloc_tpa"},
501 { STATS_OFFSET32(tx_queue_full_return),
502 4, STATS_FLAGS_FUNC, "tx_queue_full_return"},
503 { STATS_OFFSET32(bxe_tx_mq_sc_state_failures),
504 4, STATS_FLAGS_FUNC, "bxe_tx_mq_sc_state_failures"},
505 { STATS_OFFSET32(tx_request_link_down_failures),
506 4, STATS_FLAGS_FUNC, "tx_request_link_down_failures"},
507 { STATS_OFFSET32(bd_avail_too_less_failures),
508 4, STATS_FLAGS_FUNC, "bd_avail_too_less_failures"},
509 { STATS_OFFSET32(tx_mq_not_empty),
510 4, STATS_FLAGS_FUNC, "tx_mq_not_empty"},
511 { STATS_OFFSET32(nsegs_path1_errors),
512 4, STATS_FLAGS_FUNC, "nsegs_path1_errors"},
513 { STATS_OFFSET32(nsegs_path2_errors),
514 4, STATS_FLAGS_FUNC, "nsegs_path2_errors"}
519 static const struct {
522 char string[STAT_NAME_LEN];
523 } bxe_eth_q_stats_arr[] = {
524 { Q_STATS_OFFSET32(total_bytes_received_hi),
526 { Q_STATS_OFFSET32(total_unicast_packets_received_hi),
527 8, "rx_ucast_packets" },
528 { Q_STATS_OFFSET32(total_multicast_packets_received_hi),
529 8, "rx_mcast_packets" },
530 { Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
531 8, "rx_bcast_packets" },
532 { Q_STATS_OFFSET32(no_buff_discard_hi),
534 { Q_STATS_OFFSET32(total_bytes_transmitted_hi),
536 { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
537 8, "tx_ucast_packets" },
538 { Q_STATS_OFFSET32(total_multicast_packets_transmitted_hi),
539 8, "tx_mcast_packets" },
540 { Q_STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
541 8, "tx_bcast_packets" },
542 { Q_STATS_OFFSET32(total_tpa_aggregations_hi),
543 8, "tpa_aggregations" },
544 { Q_STATS_OFFSET32(total_tpa_aggregated_frames_hi),
545 8, "tpa_aggregated_frames"},
546 { Q_STATS_OFFSET32(total_tpa_bytes_hi),
548 { Q_STATS_OFFSET32(rx_calls),
550 { Q_STATS_OFFSET32(rx_pkts),
552 { Q_STATS_OFFSET32(rx_tpa_pkts),
554 { Q_STATS_OFFSET32(rx_erroneous_jumbo_sge_pkts),
555 4, "rx_erroneous_jumbo_sge_pkts"},
556 { Q_STATS_OFFSET32(rx_bxe_service_rxsgl),
557 4, "rx_bxe_service_rxsgl"},
558 { Q_STATS_OFFSET32(rx_jumbo_sge_pkts),
559 4, "rx_jumbo_sge_pkts"},
560 { Q_STATS_OFFSET32(rx_soft_errors),
561 4, "rx_soft_errors"},
562 { Q_STATS_OFFSET32(rx_hw_csum_errors),
563 4, "rx_hw_csum_errors"},
564 { Q_STATS_OFFSET32(rx_ofld_frames_csum_ip),
565 4, "rx_ofld_frames_csum_ip"},
566 { Q_STATS_OFFSET32(rx_ofld_frames_csum_tcp_udp),
567 4, "rx_ofld_frames_csum_tcp_udp"},
568 { Q_STATS_OFFSET32(rx_budget_reached),
569 4, "rx_budget_reached"},
570 { Q_STATS_OFFSET32(tx_pkts),
572 { Q_STATS_OFFSET32(tx_soft_errors),
573 4, "tx_soft_errors"},
574 { Q_STATS_OFFSET32(tx_ofld_frames_csum_ip),
575 4, "tx_ofld_frames_csum_ip"},
576 { Q_STATS_OFFSET32(tx_ofld_frames_csum_tcp),
577 4, "tx_ofld_frames_csum_tcp"},
578 { Q_STATS_OFFSET32(tx_ofld_frames_csum_udp),
579 4, "tx_ofld_frames_csum_udp"},
580 { Q_STATS_OFFSET32(tx_ofld_frames_lso),
581 4, "tx_ofld_frames_lso"},
582 { Q_STATS_OFFSET32(tx_ofld_frames_lso_hdr_splits),
583 4, "tx_ofld_frames_lso_hdr_splits"},
584 { Q_STATS_OFFSET32(tx_encap_failures),
585 4, "tx_encap_failures"},
586 { Q_STATS_OFFSET32(tx_hw_queue_full),
587 4, "tx_hw_queue_full"},
588 { Q_STATS_OFFSET32(tx_hw_max_queue_depth),
589 4, "tx_hw_max_queue_depth"},
590 { Q_STATS_OFFSET32(tx_dma_mapping_failure),
591 4, "tx_dma_mapping_failure"},
592 { Q_STATS_OFFSET32(tx_max_drbr_queue_depth),
593 4, "tx_max_drbr_queue_depth"},
594 { Q_STATS_OFFSET32(tx_window_violation_std),
595 4, "tx_window_violation_std"},
596 { Q_STATS_OFFSET32(tx_window_violation_tso),
597 4, "tx_window_violation_tso"},
598 { Q_STATS_OFFSET32(tx_chain_lost_mbuf),
599 4, "tx_chain_lost_mbuf"},
600 { Q_STATS_OFFSET32(tx_frames_deferred),
601 4, "tx_frames_deferred"},
602 { Q_STATS_OFFSET32(tx_queue_xoff),
604 { Q_STATS_OFFSET32(mbuf_defrag_attempts),
605 4, "mbuf_defrag_attempts"},
606 { Q_STATS_OFFSET32(mbuf_defrag_failures),
607 4, "mbuf_defrag_failures"},
608 { Q_STATS_OFFSET32(mbuf_rx_bd_alloc_failed),
609 4, "mbuf_rx_bd_alloc_failed"},
610 { Q_STATS_OFFSET32(mbuf_rx_bd_mapping_failed),
611 4, "mbuf_rx_bd_mapping_failed"},
612 { Q_STATS_OFFSET32(mbuf_rx_tpa_alloc_failed),
613 4, "mbuf_rx_tpa_alloc_failed"},
614 { Q_STATS_OFFSET32(mbuf_rx_tpa_mapping_failed),
615 4, "mbuf_rx_tpa_mapping_failed"},
616 { Q_STATS_OFFSET32(mbuf_rx_sge_alloc_failed),
617 4, "mbuf_rx_sge_alloc_failed"},
618 { Q_STATS_OFFSET32(mbuf_rx_sge_mapping_failed),
619 4, "mbuf_rx_sge_mapping_failed"},
620 { Q_STATS_OFFSET32(mbuf_alloc_tx),
622 { Q_STATS_OFFSET32(mbuf_alloc_rx),
624 { Q_STATS_OFFSET32(mbuf_alloc_sge),
625 4, "mbuf_alloc_sge"},
626 { Q_STATS_OFFSET32(mbuf_alloc_tpa),
627 4, "mbuf_alloc_tpa"},
628 { Q_STATS_OFFSET32(tx_queue_full_return),
629 4, "tx_queue_full_return"},
630 { Q_STATS_OFFSET32(bxe_tx_mq_sc_state_failures),
631 4, "bxe_tx_mq_sc_state_failures"},
632 { Q_STATS_OFFSET32(tx_request_link_down_failures),
633 4, "tx_request_link_down_failures"},
634 { Q_STATS_OFFSET32(bd_avail_too_less_failures),
635 4, "bd_avail_too_less_failures"},
636 { Q_STATS_OFFSET32(tx_mq_not_empty),
637 4, "tx_mq_not_empty"},
638 { Q_STATS_OFFSET32(nsegs_path1_errors),
639 4, "nsegs_path1_errors"},
640 { Q_STATS_OFFSET32(nsegs_path2_errors),
641 4, "nsegs_path2_errors"}
646 #define BXE_NUM_ETH_STATS ARRAY_SIZE(bxe_eth_stats_arr)
647 #define BXE_NUM_ETH_Q_STATS ARRAY_SIZE(bxe_eth_q_stats_arr)
650 static void bxe_cmng_fns_init(struct bxe_softc *sc,
653 static int bxe_get_cmng_fns_mode(struct bxe_softc *sc);
654 static void storm_memset_cmng(struct bxe_softc *sc,
655 struct cmng_init *cmng,
657 static void bxe_set_reset_global(struct bxe_softc *sc);
658 static void bxe_set_reset_in_progress(struct bxe_softc *sc);
659 static uint8_t bxe_reset_is_done(struct bxe_softc *sc,
661 static uint8_t bxe_clear_pf_load(struct bxe_softc *sc);
662 static uint8_t bxe_chk_parity_attn(struct bxe_softc *sc,
665 static void bxe_int_disable(struct bxe_softc *sc);
666 static int bxe_release_leader_lock(struct bxe_softc *sc);
667 static void bxe_pf_disable(struct bxe_softc *sc);
668 static void bxe_free_fp_buffers(struct bxe_softc *sc);
669 static inline void bxe_update_rx_prod(struct bxe_softc *sc,
670 struct bxe_fastpath *fp,
673 uint16_t rx_sge_prod);
674 static void bxe_link_report_locked(struct bxe_softc *sc);
675 static void bxe_link_report(struct bxe_softc *sc);
676 static void bxe_link_status_update(struct bxe_softc *sc);
677 static void bxe_periodic_callout_func(void *xsc);
678 static void bxe_periodic_start(struct bxe_softc *sc);
679 static void bxe_periodic_stop(struct bxe_softc *sc);
680 static int bxe_alloc_rx_bd_mbuf(struct bxe_fastpath *fp,
683 static int bxe_alloc_rx_tpa_mbuf(struct bxe_fastpath *fp,
685 static int bxe_alloc_rx_sge_mbuf(struct bxe_fastpath *fp,
687 static uint8_t bxe_txeof(struct bxe_softc *sc,
688 struct bxe_fastpath *fp);
689 static void bxe_task_fp(struct bxe_fastpath *fp);
690 static __noinline void bxe_dump_mbuf(struct bxe_softc *sc,
693 static int bxe_alloc_mem(struct bxe_softc *sc);
694 static void bxe_free_mem(struct bxe_softc *sc);
695 static int bxe_alloc_fw_stats_mem(struct bxe_softc *sc);
696 static void bxe_free_fw_stats_mem(struct bxe_softc *sc);
697 static int bxe_interrupt_attach(struct bxe_softc *sc);
698 static void bxe_interrupt_detach(struct bxe_softc *sc);
699 static void bxe_set_rx_mode(struct bxe_softc *sc);
700 static int bxe_init_locked(struct bxe_softc *sc);
701 static int bxe_stop_locked(struct bxe_softc *sc);
702 static void bxe_sp_err_timeout_task(void *arg, int pending);
703 void bxe_parity_recover(struct bxe_softc *sc);
704 void bxe_handle_error(struct bxe_softc *sc);
705 static __noinline int bxe_nic_load(struct bxe_softc *sc,
707 static __noinline int bxe_nic_unload(struct bxe_softc *sc,
708 uint32_t unload_mode,
711 static void bxe_handle_sp_tq(void *context, int pending);
712 static void bxe_handle_fp_tq(void *context, int pending);
714 static int bxe_add_cdev(struct bxe_softc *sc);
715 static void bxe_del_cdev(struct bxe_softc *sc);
716 int bxe_grc_dump(struct bxe_softc *sc);
717 static int bxe_alloc_buf_rings(struct bxe_softc *sc);
718 static void bxe_free_buf_rings(struct bxe_softc *sc);
720 /* calculate crc32 on a buffer (NOTE: crc32_length MUST be aligned to 8) */
722 calc_crc32(uint8_t *crc32_packet,
723 uint32_t crc32_length,
732 uint8_t current_byte = 0;
733 uint32_t crc32_result = crc32_seed;
734 const uint32_t CRC32_POLY = 0x1edc6f41;
736 if ((crc32_packet == NULL) ||
737 (crc32_length == 0) ||
738 ((crc32_length % 8) != 0))
740 return (crc32_result);
743 for (byte = 0; byte < crc32_length; byte = byte + 1)
745 current_byte = crc32_packet[byte];
746 for (bit = 0; bit < 8; bit = bit + 1)
748 /* msb = crc32_result[31]; */
749 msb = (uint8_t)(crc32_result >> 31);
751 crc32_result = crc32_result << 1;
753 /* it (msb != current_byte[bit]) */
754 if (msb != (0x1 & (current_byte >> bit)))
756 crc32_result = crc32_result ^ CRC32_POLY;
757 /* crc32_result[0] = 1 */
764 * 1. "mirror" every bit
765 * 2. swap the 4 bytes
766 * 3. complement each bit
771 shft = sizeof(crc32_result) * 8 - 1;
773 for (crc32_result >>= 1; crc32_result; crc32_result >>= 1)
776 temp |= crc32_result & 1;
780 /* temp[31-bit] = crc32_result[bit] */
784 /* crc32_result = {temp[7:0], temp[15:8], temp[23:16], temp[31:24]} */
786 uint32_t t0, t1, t2, t3;
787 t0 = (0x000000ff & (temp >> 24));
788 t1 = (0x0000ff00 & (temp >> 8));
789 t2 = (0x00ff0000 & (temp << 8));
790 t3 = (0xff000000 & (temp << 24));
791 crc32_result = t0 | t1 | t2 | t3;
797 crc32_result = ~crc32_result;
800 return (crc32_result);
805 volatile unsigned long *addr)
807 return ((atomic_load_acq_long(addr) & (1 << nr)) != 0);
811 bxe_set_bit(unsigned int nr,
812 volatile unsigned long *addr)
814 atomic_set_acq_long(addr, (1 << nr));
818 bxe_clear_bit(int nr,
819 volatile unsigned long *addr)
821 atomic_clear_acq_long(addr, (1 << nr));
825 bxe_test_and_set_bit(int nr,
826 volatile unsigned long *addr)
832 } while (atomic_cmpset_acq_long(addr, x, x | nr) == 0);
833 // if (x & nr) bit_was_set; else bit_was_not_set;
838 bxe_test_and_clear_bit(int nr,
839 volatile unsigned long *addr)
845 } while (atomic_cmpset_acq_long(addr, x, x & ~nr) == 0);
846 // if (x & nr) bit_was_set; else bit_was_not_set;
851 bxe_cmpxchg(volatile int *addr,
858 } while (atomic_cmpset_acq_int(addr, old, new) == 0);
863 * Get DMA memory from the OS.
865 * Validates that the OS has provided DMA buffers in response to a
866 * bus_dmamap_load call and saves the physical address of those buffers.
867 * When the callback is used the OS will return 0 for the mapping function
868 * (bus_dmamap_load) so we use the value of map_arg->maxsegs to pass any
869 * failures back to the caller.
875 bxe_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
877 struct bxe_dma *dma = arg;
882 BLOGE(dma->sc, "Failed DMA alloc '%s' (%d)!\n", dma->msg, error);
884 dma->paddr = segs->ds_addr;
890 * Allocate a block of memory and map it for DMA. No partial completions
891 * allowed and release any resources acquired if we can't acquire all
895 * 0 = Success, !0 = Failure
898 bxe_dma_alloc(struct bxe_softc *sc,
906 BLOGE(sc, "dma block '%s' already has size %lu\n", msg,
907 (unsigned long)dma->size);
911 memset(dma, 0, sizeof(*dma)); /* sanity */
914 snprintf(dma->msg, sizeof(dma->msg), "%s", msg);
916 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */
917 BCM_PAGE_SIZE, /* alignment */
918 0, /* boundary limit */
919 BUS_SPACE_MAXADDR, /* restricted low */
920 BUS_SPACE_MAXADDR, /* restricted hi */
921 NULL, /* addr filter() */
922 NULL, /* addr filter() arg */
923 size, /* max map size */
924 1, /* num discontinuous */
925 size, /* max seg size */
926 BUS_DMA_ALLOCNOW, /* flags */
928 NULL, /* lock() arg */
929 &dma->tag); /* returned dma tag */
931 BLOGE(sc, "Failed to create dma tag for '%s' (%d)\n", msg, rc);
932 memset(dma, 0, sizeof(*dma));
936 rc = bus_dmamem_alloc(dma->tag,
937 (void **)&dma->vaddr,
938 (BUS_DMA_NOWAIT | BUS_DMA_ZERO),
941 BLOGE(sc, "Failed to alloc dma mem for '%s' (%d)\n", msg, rc);
942 bus_dma_tag_destroy(dma->tag);
943 memset(dma, 0, sizeof(*dma));
947 rc = bus_dmamap_load(dma->tag,
951 bxe_dma_map_addr, /* BLOGD in here */
955 BLOGE(sc, "Failed to load dma map for '%s' (%d)\n", msg, rc);
956 bus_dmamem_free(dma->tag, dma->vaddr, dma->map);
957 bus_dma_tag_destroy(dma->tag);
958 memset(dma, 0, sizeof(*dma));
966 bxe_dma_free(struct bxe_softc *sc,
970 DBASSERT(sc, (dma->tag != NULL), ("dma tag is NULL"));
972 bus_dmamap_sync(dma->tag, dma->map,
973 (BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE));
974 bus_dmamap_unload(dma->tag, dma->map);
975 bus_dmamem_free(dma->tag, dma->vaddr, dma->map);
976 bus_dma_tag_destroy(dma->tag);
979 memset(dma, 0, sizeof(*dma));
983 * These indirect read and write routines are only during init.
984 * The locking is handled by the MCP.
988 bxe_reg_wr_ind(struct bxe_softc *sc,
992 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, addr, 4);
993 pci_write_config(sc->dev, PCICFG_GRC_DATA, val, 4);
994 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, 0, 4);
998 bxe_reg_rd_ind(struct bxe_softc *sc,
1003 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, addr, 4);
1004 val = pci_read_config(sc->dev, PCICFG_GRC_DATA, 4);
1005 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, 0, 4);
1011 bxe_acquire_hw_lock(struct bxe_softc *sc,
1014 uint32_t lock_status;
1015 uint32_t resource_bit = (1 << resource);
1016 int func = SC_FUNC(sc);
1017 uint32_t hw_lock_control_reg;
1020 /* validate the resource is within range */
1021 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1022 BLOGE(sc, "(resource 0x%x > HW_LOCK_MAX_RESOURCE_VALUE)"
1023 " resource_bit 0x%x\n", resource, resource_bit);
1028 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + (func * 8));
1030 hw_lock_control_reg =
1031 (MISC_REG_DRIVER_CONTROL_7 + ((func - 6) * 8));
1034 /* validate the resource is not already taken */
1035 lock_status = REG_RD(sc, hw_lock_control_reg);
1036 if (lock_status & resource_bit) {
1037 BLOGE(sc, "resource (0x%x) in use (status 0x%x bit 0x%x)\n",
1038 resource, lock_status, resource_bit);
1042 /* try every 5ms for 5 seconds */
1043 for (cnt = 0; cnt < 1000; cnt++) {
1044 REG_WR(sc, (hw_lock_control_reg + 4), resource_bit);
1045 lock_status = REG_RD(sc, hw_lock_control_reg);
1046 if (lock_status & resource_bit) {
1052 BLOGE(sc, "Resource 0x%x resource_bit 0x%x lock timeout!\n",
1053 resource, resource_bit);
1058 bxe_release_hw_lock(struct bxe_softc *sc,
1061 uint32_t lock_status;
1062 uint32_t resource_bit = (1 << resource);
1063 int func = SC_FUNC(sc);
1064 uint32_t hw_lock_control_reg;
1066 /* validate the resource is within range */
1067 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1068 BLOGE(sc, "(resource 0x%x > HW_LOCK_MAX_RESOURCE_VALUE)"
1069 " resource_bit 0x%x\n", resource, resource_bit);
1074 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + (func * 8));
1076 hw_lock_control_reg =
1077 (MISC_REG_DRIVER_CONTROL_7 + ((func - 6) * 8));
1080 /* validate the resource is currently taken */
1081 lock_status = REG_RD(sc, hw_lock_control_reg);
1082 if (!(lock_status & resource_bit)) {
1083 BLOGE(sc, "resource (0x%x) not in use (status 0x%x bit 0x%x)\n",
1084 resource, lock_status, resource_bit);
1088 REG_WR(sc, hw_lock_control_reg, resource_bit);
1091 static void bxe_acquire_phy_lock(struct bxe_softc *sc)
1094 bxe_acquire_hw_lock(sc,HW_LOCK_RESOURCE_MDIO);
1097 static void bxe_release_phy_lock(struct bxe_softc *sc)
1099 bxe_release_hw_lock(sc,HW_LOCK_RESOURCE_MDIO);
1103 * Per pf misc lock must be acquired before the per port mcp lock. Otherwise,
1104 * had we done things the other way around, if two pfs from the same port
1105 * would attempt to access nvram at the same time, we could run into a
1107 * pf A takes the port lock.
1108 * pf B succeeds in taking the same lock since they are from the same port.
1109 * pf A takes the per pf misc lock. Performs eeprom access.
1110 * pf A finishes. Unlocks the per pf misc lock.
1111 * Pf B takes the lock and proceeds to perform it's own access.
1112 * pf A unlocks the per port lock, while pf B is still working (!).
1113 * mcp takes the per port lock and corrupts pf B's access (and/or has it's own
1114 * access corrupted by pf B).*
1117 bxe_acquire_nvram_lock(struct bxe_softc *sc)
1119 int port = SC_PORT(sc);
1123 /* acquire HW lock: protect against other PFs in PF Direct Assignment */
1124 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_NVRAM);
1126 /* adjust timeout for emulation/FPGA */
1127 count = NVRAM_TIMEOUT_COUNT;
1128 if (CHIP_REV_IS_SLOW(sc)) {
1132 /* request access to nvram interface */
1133 REG_WR(sc, MCP_REG_MCPR_NVM_SW_ARB,
1134 (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port));
1136 for (i = 0; i < count*10; i++) {
1137 val = REG_RD(sc, MCP_REG_MCPR_NVM_SW_ARB);
1138 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
1145 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
1146 BLOGE(sc, "Cannot get access to nvram interface "
1147 "port %d val 0x%x (MCPR_NVM_SW_ARB_ARB_ARB1 << port)\n",
1156 bxe_release_nvram_lock(struct bxe_softc *sc)
1158 int port = SC_PORT(sc);
1162 /* adjust timeout for emulation/FPGA */
1163 count = NVRAM_TIMEOUT_COUNT;
1164 if (CHIP_REV_IS_SLOW(sc)) {
1168 /* relinquish nvram interface */
1169 REG_WR(sc, MCP_REG_MCPR_NVM_SW_ARB,
1170 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port));
1172 for (i = 0; i < count*10; i++) {
1173 val = REG_RD(sc, MCP_REG_MCPR_NVM_SW_ARB);
1174 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
1181 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
1182 BLOGE(sc, "Cannot free access to nvram interface "
1183 "port %d val 0x%x (MCPR_NVM_SW_ARB_ARB_ARB1 << port)\n",
1188 /* release HW lock: protect against other PFs in PF Direct Assignment */
1189 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_NVRAM);
1195 bxe_enable_nvram_access(struct bxe_softc *sc)
1199 val = REG_RD(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
1201 /* enable both bits, even on read */
1202 REG_WR(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
1203 (val | MCPR_NVM_ACCESS_ENABLE_EN | MCPR_NVM_ACCESS_ENABLE_WR_EN));
1207 bxe_disable_nvram_access(struct bxe_softc *sc)
1211 val = REG_RD(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
1213 /* disable both bits, even after read */
1214 REG_WR(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
1215 (val & ~(MCPR_NVM_ACCESS_ENABLE_EN |
1216 MCPR_NVM_ACCESS_ENABLE_WR_EN)));
1220 bxe_nvram_read_dword(struct bxe_softc *sc,
1228 /* build the command word */
1229 cmd_flags |= MCPR_NVM_COMMAND_DOIT;
1231 /* need to clear DONE bit separately */
1232 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
1234 /* address of the NVRAM to read from */
1235 REG_WR(sc, MCP_REG_MCPR_NVM_ADDR,
1236 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
1238 /* issue a read command */
1239 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
1241 /* adjust timeout for emulation/FPGA */
1242 count = NVRAM_TIMEOUT_COUNT;
1243 if (CHIP_REV_IS_SLOW(sc)) {
1247 /* wait for completion */
1250 for (i = 0; i < count; i++) {
1252 val = REG_RD(sc, MCP_REG_MCPR_NVM_COMMAND);
1254 if (val & MCPR_NVM_COMMAND_DONE) {
1255 val = REG_RD(sc, MCP_REG_MCPR_NVM_READ);
1256 /* we read nvram data in cpu order
1257 * but ethtool sees it as an array of bytes
1258 * converting to big-endian will do the work
1260 *ret_val = htobe32(val);
1267 BLOGE(sc, "nvram read timeout expired "
1268 "(offset 0x%x cmd_flags 0x%x val 0x%x)\n",
1269 offset, cmd_flags, val);
1276 bxe_nvram_read(struct bxe_softc *sc,
1285 if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
1286 BLOGE(sc, "Invalid parameter, offset 0x%x buf_size 0x%x\n",
1291 if ((offset + buf_size) > sc->devinfo.flash_size) {
1292 BLOGE(sc, "Invalid parameter, "
1293 "offset 0x%x + buf_size 0x%x > flash_size 0x%x\n",
1294 offset, buf_size, sc->devinfo.flash_size);
1298 /* request access to nvram interface */
1299 rc = bxe_acquire_nvram_lock(sc);
1304 /* enable access to nvram interface */
1305 bxe_enable_nvram_access(sc);
1307 /* read the first word(s) */
1308 cmd_flags = MCPR_NVM_COMMAND_FIRST;
1309 while ((buf_size > sizeof(uint32_t)) && (rc == 0)) {
1310 rc = bxe_nvram_read_dword(sc, offset, &val, cmd_flags);
1311 memcpy(ret_buf, &val, 4);
1313 /* advance to the next dword */
1314 offset += sizeof(uint32_t);
1315 ret_buf += sizeof(uint32_t);
1316 buf_size -= sizeof(uint32_t);
1321 cmd_flags |= MCPR_NVM_COMMAND_LAST;
1322 rc = bxe_nvram_read_dword(sc, offset, &val, cmd_flags);
1323 memcpy(ret_buf, &val, 4);
1326 /* disable access to nvram interface */
1327 bxe_disable_nvram_access(sc);
1328 bxe_release_nvram_lock(sc);
1334 bxe_nvram_write_dword(struct bxe_softc *sc,
1341 /* build the command word */
1342 cmd_flags |= (MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR);
1344 /* need to clear DONE bit separately */
1345 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
1347 /* write the data */
1348 REG_WR(sc, MCP_REG_MCPR_NVM_WRITE, val);
1350 /* address of the NVRAM to write to */
1351 REG_WR(sc, MCP_REG_MCPR_NVM_ADDR,
1352 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
1354 /* issue the write command */
1355 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
1357 /* adjust timeout for emulation/FPGA */
1358 count = NVRAM_TIMEOUT_COUNT;
1359 if (CHIP_REV_IS_SLOW(sc)) {
1363 /* wait for completion */
1365 for (i = 0; i < count; i++) {
1367 val = REG_RD(sc, MCP_REG_MCPR_NVM_COMMAND);
1368 if (val & MCPR_NVM_COMMAND_DONE) {
1375 BLOGE(sc, "nvram write timeout expired "
1376 "(offset 0x%x cmd_flags 0x%x val 0x%x)\n",
1377 offset, cmd_flags, val);
1383 #define BYTE_OFFSET(offset) (8 * (offset & 0x03))
1386 bxe_nvram_write1(struct bxe_softc *sc,
1392 uint32_t align_offset;
1396 if ((offset + buf_size) > sc->devinfo.flash_size) {
1397 BLOGE(sc, "Invalid parameter, "
1398 "offset 0x%x + buf_size 0x%x > flash_size 0x%x\n",
1399 offset, buf_size, sc->devinfo.flash_size);
1403 /* request access to nvram interface */
1404 rc = bxe_acquire_nvram_lock(sc);
1409 /* enable access to nvram interface */
1410 bxe_enable_nvram_access(sc);
1412 cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST);
1413 align_offset = (offset & ~0x03);
1414 rc = bxe_nvram_read_dword(sc, align_offset, &val, cmd_flags);
1417 val &= ~(0xff << BYTE_OFFSET(offset));
1418 val |= (*data_buf << BYTE_OFFSET(offset));
1420 /* nvram data is returned as an array of bytes
1421 * convert it back to cpu order
1425 rc = bxe_nvram_write_dword(sc, align_offset, val, cmd_flags);
1428 /* disable access to nvram interface */
1429 bxe_disable_nvram_access(sc);
1430 bxe_release_nvram_lock(sc);
1436 bxe_nvram_write(struct bxe_softc *sc,
1443 uint32_t written_so_far;
1446 if (buf_size == 1) {
1447 return (bxe_nvram_write1(sc, offset, data_buf, buf_size));
1450 if ((offset & 0x03) || (buf_size & 0x03) /* || (buf_size == 0) */) {
1451 BLOGE(sc, "Invalid parameter, offset 0x%x buf_size 0x%x\n",
1456 if (buf_size == 0) {
1457 return (0); /* nothing to do */
1460 if ((offset + buf_size) > sc->devinfo.flash_size) {
1461 BLOGE(sc, "Invalid parameter, "
1462 "offset 0x%x + buf_size 0x%x > flash_size 0x%x\n",
1463 offset, buf_size, sc->devinfo.flash_size);
1467 /* request access to nvram interface */
1468 rc = bxe_acquire_nvram_lock(sc);
1473 /* enable access to nvram interface */
1474 bxe_enable_nvram_access(sc);
1477 cmd_flags = MCPR_NVM_COMMAND_FIRST;
1478 while ((written_so_far < buf_size) && (rc == 0)) {
1479 if (written_so_far == (buf_size - sizeof(uint32_t))) {
1480 cmd_flags |= MCPR_NVM_COMMAND_LAST;
1481 } else if (((offset + 4) % NVRAM_PAGE_SIZE) == 0) {
1482 cmd_flags |= MCPR_NVM_COMMAND_LAST;
1483 } else if ((offset % NVRAM_PAGE_SIZE) == 0) {
1484 cmd_flags |= MCPR_NVM_COMMAND_FIRST;
1487 memcpy(&val, data_buf, 4);
1489 rc = bxe_nvram_write_dword(sc, offset, val, cmd_flags);
1491 /* advance to the next dword */
1492 offset += sizeof(uint32_t);
1493 data_buf += sizeof(uint32_t);
1494 written_so_far += sizeof(uint32_t);
1498 /* disable access to nvram interface */
1499 bxe_disable_nvram_access(sc);
1500 bxe_release_nvram_lock(sc);
1505 /* copy command into DMAE command memory and set DMAE command Go */
1507 bxe_post_dmae(struct bxe_softc *sc,
1508 struct dmae_cmd *dmae,
1511 uint32_t cmd_offset;
1514 cmd_offset = (DMAE_REG_CMD_MEM + (sizeof(struct dmae_cmd) * idx));
1515 for (i = 0; i < ((sizeof(struct dmae_cmd) / 4)); i++) {
1516 REG_WR(sc, (cmd_offset + (i * 4)), *(((uint32_t *)dmae) + i));
1519 REG_WR(sc, dmae_reg_go_c[idx], 1);
1523 bxe_dmae_opcode_add_comp(uint32_t opcode,
1526 return (opcode | ((comp_type << DMAE_CMD_C_DST_SHIFT) |
1527 DMAE_CMD_C_TYPE_ENABLE));
1531 bxe_dmae_opcode_clr_src_reset(uint32_t opcode)
1533 return (opcode & ~DMAE_CMD_SRC_RESET);
1537 bxe_dmae_opcode(struct bxe_softc *sc,
1543 uint32_t opcode = 0;
1545 opcode |= ((src_type << DMAE_CMD_SRC_SHIFT) |
1546 (dst_type << DMAE_CMD_DST_SHIFT));
1548 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
1550 opcode |= (SC_PORT(sc) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
1552 opcode |= ((SC_VN(sc) << DMAE_CMD_E1HVN_SHIFT) |
1553 (SC_VN(sc) << DMAE_CMD_DST_VN_SHIFT));
1555 opcode |= (DMAE_COM_SET_ERR << DMAE_CMD_ERR_POLICY_SHIFT);
1558 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
1560 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
1564 opcode = bxe_dmae_opcode_add_comp(opcode, comp_type);
1571 bxe_prep_dmae_with_comp(struct bxe_softc *sc,
1572 struct dmae_cmd *dmae,
1576 memset(dmae, 0, sizeof(struct dmae_cmd));
1578 /* set the opcode */
1579 dmae->opcode = bxe_dmae_opcode(sc, src_type, dst_type,
1580 TRUE, DMAE_COMP_PCI);
1582 /* fill in the completion parameters */
1583 dmae->comp_addr_lo = U64_LO(BXE_SP_MAPPING(sc, wb_comp));
1584 dmae->comp_addr_hi = U64_HI(BXE_SP_MAPPING(sc, wb_comp));
1585 dmae->comp_val = DMAE_COMP_VAL;
1588 /* issue a DMAE command over the init channel and wait for completion */
1590 bxe_issue_dmae_with_comp(struct bxe_softc *sc,
1591 struct dmae_cmd *dmae)
1593 uint32_t *wb_comp = BXE_SP(sc, wb_comp);
1594 int timeout = CHIP_REV_IS_SLOW(sc) ? 400000 : 4000;
1598 /* reset completion */
1601 /* post the command on the channel used for initializations */
1602 bxe_post_dmae(sc, dmae, INIT_DMAE_C(sc));
1604 /* wait for completion */
1607 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
1609 (sc->recovery_state != BXE_RECOVERY_DONE &&
1610 sc->recovery_state != BXE_RECOVERY_NIC_LOADING)) {
1611 BLOGE(sc, "DMAE timeout! *wb_comp 0x%x recovery_state 0x%x\n",
1612 *wb_comp, sc->recovery_state);
1613 BXE_DMAE_UNLOCK(sc);
1614 return (DMAE_TIMEOUT);
1621 if (*wb_comp & DMAE_PCI_ERR_FLAG) {
1622 BLOGE(sc, "DMAE PCI error! *wb_comp 0x%x recovery_state 0x%x\n",
1623 *wb_comp, sc->recovery_state);
1624 BXE_DMAE_UNLOCK(sc);
1625 return (DMAE_PCI_ERROR);
1628 BXE_DMAE_UNLOCK(sc);
1633 bxe_read_dmae(struct bxe_softc *sc,
1637 struct dmae_cmd dmae;
1641 DBASSERT(sc, (len32 <= 4), ("DMAE read length is %d", len32));
1643 if (!sc->dmae_ready) {
1644 data = BXE_SP(sc, wb_data[0]);
1646 for (i = 0; i < len32; i++) {
1647 data[i] = (CHIP_IS_E1(sc)) ?
1648 bxe_reg_rd_ind(sc, (src_addr + (i * 4))) :
1649 REG_RD(sc, (src_addr + (i * 4)));
1655 /* set opcode and fixed command fields */
1656 bxe_prep_dmae_with_comp(sc, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
1658 /* fill in addresses and len */
1659 dmae.src_addr_lo = (src_addr >> 2); /* GRC addr has dword resolution */
1660 dmae.src_addr_hi = 0;
1661 dmae.dst_addr_lo = U64_LO(BXE_SP_MAPPING(sc, wb_data));
1662 dmae.dst_addr_hi = U64_HI(BXE_SP_MAPPING(sc, wb_data));
1665 /* issue the command and wait for completion */
1666 if ((rc = bxe_issue_dmae_with_comp(sc, &dmae)) != 0) {
1667 bxe_panic(sc, ("DMAE failed (%d)\n", rc));
1672 bxe_write_dmae(struct bxe_softc *sc,
1673 bus_addr_t dma_addr,
1677 struct dmae_cmd dmae;
1680 if (!sc->dmae_ready) {
1681 DBASSERT(sc, (len32 <= 4), ("DMAE not ready and length is %d", len32));
1683 if (CHIP_IS_E1(sc)) {
1684 ecore_init_ind_wr(sc, dst_addr, BXE_SP(sc, wb_data[0]), len32);
1686 ecore_init_str_wr(sc, dst_addr, BXE_SP(sc, wb_data[0]), len32);
1692 /* set opcode and fixed command fields */
1693 bxe_prep_dmae_with_comp(sc, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
1695 /* fill in addresses and len */
1696 dmae.src_addr_lo = U64_LO(dma_addr);
1697 dmae.src_addr_hi = U64_HI(dma_addr);
1698 dmae.dst_addr_lo = (dst_addr >> 2); /* GRC addr has dword resolution */
1699 dmae.dst_addr_hi = 0;
1702 /* issue the command and wait for completion */
1703 if ((rc = bxe_issue_dmae_with_comp(sc, &dmae)) != 0) {
1704 bxe_panic(sc, ("DMAE failed (%d)\n", rc));
1709 bxe_write_dmae_phys_len(struct bxe_softc *sc,
1710 bus_addr_t phys_addr,
1714 int dmae_wr_max = DMAE_LEN32_WR_MAX(sc);
1717 while (len > dmae_wr_max) {
1719 (phys_addr + offset), /* src DMA address */
1720 (addr + offset), /* dst GRC address */
1722 offset += (dmae_wr_max * 4);
1727 (phys_addr + offset), /* src DMA address */
1728 (addr + offset), /* dst GRC address */
1733 bxe_set_ctx_validation(struct bxe_softc *sc,
1734 struct eth_context *cxt,
1737 /* ustorm cxt validation */
1738 cxt->ustorm_ag_context.cdu_usage =
1739 CDU_RSRVD_VALUE_TYPE_A(HW_CID(sc, cid),
1740 CDU_REGION_NUMBER_UCM_AG, ETH_CONNECTION_TYPE);
1741 /* xcontext validation */
1742 cxt->xstorm_ag_context.cdu_reserved =
1743 CDU_RSRVD_VALUE_TYPE_A(HW_CID(sc, cid),
1744 CDU_REGION_NUMBER_XCM_AG, ETH_CONNECTION_TYPE);
1748 bxe_storm_memset_hc_timeout(struct bxe_softc *sc,
1755 (BAR_CSTRORM_INTMEM +
1756 CSTORM_STATUS_BLOCK_DATA_TIMEOUT_OFFSET(fw_sb_id, sb_index));
1758 REG_WR8(sc, addr, ticks);
1761 "port %d fw_sb_id %d sb_index %d ticks %d\n",
1762 port, fw_sb_id, sb_index, ticks);
1766 bxe_storm_memset_hc_disable(struct bxe_softc *sc,
1772 uint32_t enable_flag =
1773 (disable) ? 0 : (1 << HC_INDEX_DATA_HC_ENABLED_SHIFT);
1775 (BAR_CSTRORM_INTMEM +
1776 CSTORM_STATUS_BLOCK_DATA_FLAGS_OFFSET(fw_sb_id, sb_index));
1780 flags = REG_RD8(sc, addr);
1781 flags &= ~HC_INDEX_DATA_HC_ENABLED;
1782 flags |= enable_flag;
1783 REG_WR8(sc, addr, flags);
1786 "port %d fw_sb_id %d sb_index %d disable %d\n",
1787 port, fw_sb_id, sb_index, disable);
1791 bxe_update_coalesce_sb_index(struct bxe_softc *sc,
1797 int port = SC_PORT(sc);
1798 uint8_t ticks = (usec / 4); /* XXX ??? */
1800 bxe_storm_memset_hc_timeout(sc, port, fw_sb_id, sb_index, ticks);
1802 disable = (disable) ? 1 : ((usec) ? 0 : 1);
1803 bxe_storm_memset_hc_disable(sc, port, fw_sb_id, sb_index, disable);
1807 elink_cb_udelay(struct bxe_softc *sc,
1814 elink_cb_reg_read(struct bxe_softc *sc,
1817 return (REG_RD(sc, reg_addr));
1821 elink_cb_reg_write(struct bxe_softc *sc,
1825 REG_WR(sc, reg_addr, val);
1829 elink_cb_reg_wb_write(struct bxe_softc *sc,
1834 REG_WR_DMAE(sc, offset, wb_write, len);
1838 elink_cb_reg_wb_read(struct bxe_softc *sc,
1843 REG_RD_DMAE(sc, offset, wb_write, len);
1847 elink_cb_path_id(struct bxe_softc *sc)
1849 return (SC_PATH(sc));
1853 elink_cb_event_log(struct bxe_softc *sc,
1854 const elink_log_id_t elink_log_id,
1858 BLOGI(sc, "ELINK EVENT LOG (%d)\n", elink_log_id);
1862 bxe_set_spio(struct bxe_softc *sc,
1868 /* Only 2 SPIOs are configurable */
1869 if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
1870 BLOGE(sc, "Invalid SPIO 0x%x mode 0x%x\n", spio, mode);
1874 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_SPIO);
1876 /* read SPIO and mask except the float bits */
1877 spio_reg = (REG_RD(sc, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
1880 case MISC_SPIO_OUTPUT_LOW:
1881 BLOGD(sc, DBG_LOAD, "Set SPIO 0x%x -> output low\n", spio);
1882 /* clear FLOAT and set CLR */
1883 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
1884 spio_reg |= (spio << MISC_SPIO_CLR_POS);
1887 case MISC_SPIO_OUTPUT_HIGH:
1888 BLOGD(sc, DBG_LOAD, "Set SPIO 0x%x -> output high\n", spio);
1889 /* clear FLOAT and set SET */
1890 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
1891 spio_reg |= (spio << MISC_SPIO_SET_POS);
1894 case MISC_SPIO_INPUT_HI_Z:
1895 BLOGD(sc, DBG_LOAD, "Set SPIO 0x%x -> input\n", spio);
1897 spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
1904 REG_WR(sc, MISC_REG_SPIO, spio_reg);
1905 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_SPIO);
1911 bxe_gpio_read(struct bxe_softc *sc,
1915 /* The GPIO should be swapped if swap register is set and active */
1916 int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) &&
1917 REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port);
1918 int gpio_shift = (gpio_num +
1919 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0));
1920 uint32_t gpio_mask = (1 << gpio_shift);
1923 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1924 BLOGE(sc, "Invalid GPIO %d port 0x%x gpio_port %d gpio_shift %d"
1925 " gpio_mask 0x%x\n", gpio_num, port, gpio_port, gpio_shift,
1930 /* read GPIO value */
1931 gpio_reg = REG_RD(sc, MISC_REG_GPIO);
1933 /* get the requested pin value */
1934 return ((gpio_reg & gpio_mask) == gpio_mask) ? 1 : 0;
1938 bxe_gpio_write(struct bxe_softc *sc,
1943 /* The GPIO should be swapped if swap register is set and active */
1944 int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) &&
1945 REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port);
1946 int gpio_shift = (gpio_num +
1947 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0));
1948 uint32_t gpio_mask = (1 << gpio_shift);
1951 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1952 BLOGE(sc, "Invalid GPIO %d mode 0x%x port 0x%x gpio_port %d"
1953 " gpio_shift %d gpio_mask 0x%x\n",
1954 gpio_num, mode, port, gpio_port, gpio_shift, gpio_mask);
1958 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
1960 /* read GPIO and mask except the float bits */
1961 gpio_reg = (REG_RD(sc, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
1964 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1966 "Set GPIO %d (shift %d) -> output low\n",
1967 gpio_num, gpio_shift);
1968 /* clear FLOAT and set CLR */
1969 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1970 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
1973 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1975 "Set GPIO %d (shift %d) -> output high\n",
1976 gpio_num, gpio_shift);
1977 /* clear FLOAT and set SET */
1978 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1979 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
1982 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
1984 "Set GPIO %d (shift %d) -> input\n",
1985 gpio_num, gpio_shift);
1987 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1994 REG_WR(sc, MISC_REG_GPIO, gpio_reg);
1995 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2001 bxe_gpio_mult_write(struct bxe_softc *sc,
2007 /* any port swapping should be handled by caller */
2009 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2011 /* read GPIO and mask except the float bits */
2012 gpio_reg = REG_RD(sc, MISC_REG_GPIO);
2013 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2014 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
2015 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
2018 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
2019 BLOGD(sc, DBG_PHY, "Set GPIO 0x%x -> output low\n", pins);
2021 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
2024 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
2025 BLOGD(sc, DBG_PHY, "Set GPIO 0x%x -> output high\n", pins);
2027 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
2030 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
2031 BLOGD(sc, DBG_PHY, "Set GPIO 0x%x -> input\n", pins);
2033 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2037 BLOGE(sc, "Invalid GPIO mode assignment pins 0x%x mode 0x%x"
2038 " gpio_reg 0x%x\n", pins, mode, gpio_reg);
2039 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2043 REG_WR(sc, MISC_REG_GPIO, gpio_reg);
2044 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2050 bxe_gpio_int_write(struct bxe_softc *sc,
2055 /* The GPIO should be swapped if swap register is set and active */
2056 int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) &&
2057 REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port);
2058 int gpio_shift = (gpio_num +
2059 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0));
2060 uint32_t gpio_mask = (1 << gpio_shift);
2063 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2064 BLOGE(sc, "Invalid GPIO %d mode 0x%x port 0x%x gpio_port %d"
2065 " gpio_shift %d gpio_mask 0x%x\n",
2066 gpio_num, mode, port, gpio_port, gpio_shift, gpio_mask);
2070 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2073 gpio_reg = REG_RD(sc, MISC_REG_GPIO_INT);
2076 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
2078 "Clear GPIO INT %d (shift %d) -> output low\n",
2079 gpio_num, gpio_shift);
2080 /* clear SET and set CLR */
2081 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2082 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2085 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
2087 "Set GPIO INT %d (shift %d) -> output high\n",
2088 gpio_num, gpio_shift);
2089 /* clear CLR and set SET */
2090 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2091 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2098 REG_WR(sc, MISC_REG_GPIO_INT, gpio_reg);
2099 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
2105 elink_cb_gpio_read(struct bxe_softc *sc,
2109 return (bxe_gpio_read(sc, gpio_num, port));
2113 elink_cb_gpio_write(struct bxe_softc *sc,
2115 uint8_t mode, /* 0=low 1=high */
2118 return (bxe_gpio_write(sc, gpio_num, mode, port));
2122 elink_cb_gpio_mult_write(struct bxe_softc *sc,
2124 uint8_t mode) /* 0=low 1=high */
2126 return (bxe_gpio_mult_write(sc, pins, mode));
2130 elink_cb_gpio_int_write(struct bxe_softc *sc,
2132 uint8_t mode, /* 0=low 1=high */
2135 return (bxe_gpio_int_write(sc, gpio_num, mode, port));
2139 elink_cb_notify_link_changed(struct bxe_softc *sc)
2141 REG_WR(sc, (MISC_REG_AEU_GENERAL_ATTN_12 +
2142 (SC_FUNC(sc) * sizeof(uint32_t))), 1);
2145 /* send the MCP a request, block until there is a reply */
2147 elink_cb_fw_command(struct bxe_softc *sc,
2151 int mb_idx = SC_FW_MB_IDX(sc);
2155 uint8_t delay = CHIP_REV_IS_SLOW(sc) ? 100 : 10;
2160 SHMEM_WR(sc, func_mb[mb_idx].drv_mb_param, param);
2161 SHMEM_WR(sc, func_mb[mb_idx].drv_mb_header, (command | seq));
2164 "wrote command 0x%08x to FW MB param 0x%08x\n",
2165 (command | seq), param);
2167 /* Let the FW do it's magic. GIve it up to 5 seconds... */
2169 DELAY(delay * 1000);
2170 rc = SHMEM_RD(sc, func_mb[mb_idx].fw_mb_header);
2171 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
2174 "[after %d ms] read 0x%x seq 0x%x from FW MB\n",
2175 cnt*delay, rc, seq);
2177 /* is this a reply to our command? */
2178 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK)) {
2179 rc &= FW_MSG_CODE_MASK;
2182 BLOGE(sc, "FW failed to respond!\n");
2183 // XXX bxe_fw_dump(sc);
2187 BXE_FWMB_UNLOCK(sc);
2192 bxe_fw_command(struct bxe_softc *sc,
2196 return (elink_cb_fw_command(sc, command, param));
2200 __storm_memset_dma_mapping(struct bxe_softc *sc,
2204 REG_WR(sc, addr, U64_LO(mapping));
2205 REG_WR(sc, (addr + 4), U64_HI(mapping));
2209 storm_memset_spq_addr(struct bxe_softc *sc,
2213 uint32_t addr = (XSEM_REG_FAST_MEMORY +
2214 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid));
2215 __storm_memset_dma_mapping(sc, addr, mapping);
2219 storm_memset_vf_to_pf(struct bxe_softc *sc,
2223 REG_WR8(sc, (BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id);
2224 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id);
2225 REG_WR8(sc, (BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id);
2226 REG_WR8(sc, (BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id);
2230 storm_memset_func_en(struct bxe_softc *sc,
2234 REG_WR8(sc, (BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid)), enable);
2235 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid)), enable);
2236 REG_WR8(sc, (BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid)), enable);
2237 REG_WR8(sc, (BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid)), enable);
2241 storm_memset_eq_data(struct bxe_softc *sc,
2242 struct event_ring_data *eq_data,
2248 addr = (BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid));
2249 size = sizeof(struct event_ring_data);
2250 ecore_storm_memset_struct(sc, addr, size, (uint32_t *)eq_data);
2254 storm_memset_eq_prod(struct bxe_softc *sc,
2258 uint32_t addr = (BAR_CSTRORM_INTMEM +
2259 CSTORM_EVENT_RING_PROD_OFFSET(pfid));
2260 REG_WR16(sc, addr, eq_prod);
2264 * Post a slowpath command.
2266 * A slowpath command is used to propagate a configuration change through
2267 * the controller in a controlled manner, allowing each STORM processor and
2268 * other H/W blocks to phase in the change. The commands sent on the
2269 * slowpath are referred to as ramrods. Depending on the ramrod used the
2270 * completion of the ramrod will occur in different ways. Here's a
2271 * breakdown of ramrods and how they complete:
2273 * RAMROD_CMD_ID_ETH_PORT_SETUP
2274 * Used to setup the leading connection on a port. Completes on the
2275 * Receive Completion Queue (RCQ) of that port (typically fp[0]).
2277 * RAMROD_CMD_ID_ETH_CLIENT_SETUP
2278 * Used to setup an additional connection on a port. Completes on the
2279 * RCQ of the multi-queue/RSS connection being initialized.
2281 * RAMROD_CMD_ID_ETH_STAT_QUERY
2282 * Used to force the storm processors to update the statistics database
2283 * in host memory. This ramrod is send on the leading connection CID and
2284 * completes as an index increment of the CSTORM on the default status
2287 * RAMROD_CMD_ID_ETH_UPDATE
2288 * Used to update the state of the leading connection, usually to udpate
2289 * the RSS indirection table. Completes on the RCQ of the leading
2290 * connection. (Not currently used under FreeBSD until OS support becomes
2293 * RAMROD_CMD_ID_ETH_HALT
2294 * Used when tearing down a connection prior to driver unload. Completes
2295 * on the RCQ of the multi-queue/RSS connection being torn down. Don't
2296 * use this on the leading connection.
2298 * RAMROD_CMD_ID_ETH_SET_MAC
2299 * Sets the Unicast/Broadcast/Multicast used by the port. Completes on
2300 * the RCQ of the leading connection.
2302 * RAMROD_CMD_ID_ETH_CFC_DEL
2303 * Used when tearing down a conneciton prior to driver unload. Completes
2304 * on the RCQ of the leading connection (since the current connection
2305 * has been completely removed from controller memory).
2307 * RAMROD_CMD_ID_ETH_PORT_DEL
2308 * Used to tear down the leading connection prior to driver unload,
2309 * typically fp[0]. Completes as an index increment of the CSTORM on the
2310 * default status block.
2312 * RAMROD_CMD_ID_ETH_FORWARD_SETUP
2313 * Used for connection offload. Completes on the RCQ of the multi-queue
2314 * RSS connection that is being offloaded. (Not currently used under
2317 * There can only be one command pending per function.
2320 * 0 = Success, !0 = Failure.
2323 /* must be called under the spq lock */
2325 struct eth_spe *bxe_sp_get_next(struct bxe_softc *sc)
2327 struct eth_spe *next_spe = sc->spq_prod_bd;
2329 if (sc->spq_prod_bd == sc->spq_last_bd) {
2330 /* wrap back to the first eth_spq */
2331 sc->spq_prod_bd = sc->spq;
2332 sc->spq_prod_idx = 0;
2341 /* must be called under the spq lock */
2343 void bxe_sp_prod_update(struct bxe_softc *sc)
2345 int func = SC_FUNC(sc);
2348 * Make sure that BD data is updated before writing the producer.
2349 * BD data is written to the memory, the producer is read from the
2350 * memory, thus we need a full memory barrier to ensure the ordering.
2354 REG_WR16(sc, (BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func)),
2357 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle, 0, 0,
2358 BUS_SPACE_BARRIER_WRITE);
2362 * bxe_is_contextless_ramrod - check if the current command ends on EQ
2364 * @cmd: command to check
2365 * @cmd_type: command type
2368 int bxe_is_contextless_ramrod(int cmd,
2371 if ((cmd_type == NONE_CONNECTION_TYPE) ||
2372 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
2373 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
2374 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
2375 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
2376 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
2377 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE)) {
2385 * bxe_sp_post - place a single command on an SP ring
2387 * @sc: driver handle
2388 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
2389 * @cid: SW CID the command is related to
2390 * @data_hi: command private data address (high 32 bits)
2391 * @data_lo: command private data address (low 32 bits)
2392 * @cmd_type: command type (e.g. NONE, ETH)
2394 * SP data is handled as if it's always an address pair, thus data fields are
2395 * not swapped to little endian in upper functions. Instead this function swaps
2396 * data as if it's two uint32 fields.
2399 bxe_sp_post(struct bxe_softc *sc,
2406 struct eth_spe *spe;
2410 common = bxe_is_contextless_ramrod(command, cmd_type);
2415 if (!atomic_load_acq_long(&sc->eq_spq_left)) {
2416 BLOGE(sc, "EQ ring is full!\n");
2421 if (!atomic_load_acq_long(&sc->cq_spq_left)) {
2422 BLOGE(sc, "SPQ ring is full!\n");
2428 spe = bxe_sp_get_next(sc);
2430 /* CID needs port number to be encoded int it */
2431 spe->hdr.conn_and_cmd_data =
2432 htole32((command << SPE_HDR_T_CMD_ID_SHIFT) | HW_CID(sc, cid));
2434 type = (cmd_type << SPE_HDR_T_CONN_TYPE_SHIFT) & SPE_HDR_T_CONN_TYPE;
2436 /* TBD: Check if it works for VFs */
2437 type |= ((SC_FUNC(sc) << SPE_HDR_T_FUNCTION_ID_SHIFT) &
2438 SPE_HDR_T_FUNCTION_ID);
2440 spe->hdr.type = htole16(type);
2442 spe->data.update_data_addr.hi = htole32(data_hi);
2443 spe->data.update_data_addr.lo = htole32(data_lo);
2446 * It's ok if the actual decrement is issued towards the memory
2447 * somewhere between the lock and unlock. Thus no more explict
2448 * memory barrier is needed.
2451 atomic_subtract_acq_long(&sc->eq_spq_left, 1);
2453 atomic_subtract_acq_long(&sc->cq_spq_left, 1);
2456 BLOGD(sc, DBG_SP, "SPQE -> %#jx\n", (uintmax_t)sc->spq_dma.paddr);
2457 BLOGD(sc, DBG_SP, "FUNC_RDATA -> %p / %#jx\n",
2458 BXE_SP(sc, func_rdata), (uintmax_t)BXE_SP_MAPPING(sc, func_rdata));
2460 "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%lx,%lx)\n",
2462 (uint32_t)U64_HI(sc->spq_dma.paddr),
2463 (uint32_t)(U64_LO(sc->spq_dma.paddr) + (uint8_t *)sc->spq_prod_bd - (uint8_t *)sc->spq),
2470 atomic_load_acq_long(&sc->cq_spq_left),
2471 atomic_load_acq_long(&sc->eq_spq_left));
2473 bxe_sp_prod_update(sc);
2480 * bxe_debug_print_ind_table - prints the indirection table configuration.
2482 * @sc: driver hanlde
2483 * @p: pointer to rss configuration
2487 * FreeBSD Device probe function.
2489 * Compares the device found to the driver's list of supported devices and
2490 * reports back to the bsd loader whether this is the right driver for the device.
2491 * This is the driver entry function called from the "kldload" command.
2494 * BUS_PROBE_DEFAULT on success, positive value on failure.
2497 bxe_probe(device_t dev)
2499 struct bxe_device_type *t;
2501 uint16_t did, sdid, svid, vid;
2503 /* Find our device structure */
2506 /* Get the data for the device to be probed. */
2507 vid = pci_get_vendor(dev);
2508 did = pci_get_device(dev);
2509 svid = pci_get_subvendor(dev);
2510 sdid = pci_get_subdevice(dev);
2512 /* Look through the list of known devices for a match. */
2513 while (t->bxe_name != NULL) {
2514 if ((vid == t->bxe_vid) && (did == t->bxe_did) &&
2515 ((svid == t->bxe_svid) || (t->bxe_svid == PCI_ANY_ID)) &&
2516 ((sdid == t->bxe_sdid) || (t->bxe_sdid == PCI_ANY_ID))) {
2517 descbuf = malloc(BXE_DEVDESC_MAX, M_TEMP, M_NOWAIT);
2518 if (descbuf == NULL)
2521 /* Print out the device identity. */
2522 snprintf(descbuf, BXE_DEVDESC_MAX,
2523 "%s (%c%d) BXE v:%s", t->bxe_name,
2524 (((pci_read_config(dev, PCIR_REVID, 4) &
2526 (pci_read_config(dev, PCIR_REVID, 4) & 0xf),
2527 BXE_DRIVER_VERSION);
2529 device_set_desc_copy(dev, descbuf);
2530 free(descbuf, M_TEMP);
2531 return (BUS_PROBE_DEFAULT);
2540 bxe_init_mutexes(struct bxe_softc *sc)
2542 #ifdef BXE_CORE_LOCK_SX
2543 snprintf(sc->core_sx_name, sizeof(sc->core_sx_name),
2544 "bxe%d_core_lock", sc->unit);
2545 sx_init(&sc->core_sx, sc->core_sx_name);
2547 snprintf(sc->core_mtx_name, sizeof(sc->core_mtx_name),
2548 "bxe%d_core_lock", sc->unit);
2549 mtx_init(&sc->core_mtx, sc->core_mtx_name, NULL, MTX_DEF);
2552 snprintf(sc->sp_mtx_name, sizeof(sc->sp_mtx_name),
2553 "bxe%d_sp_lock", sc->unit);
2554 mtx_init(&sc->sp_mtx, sc->sp_mtx_name, NULL, MTX_DEF);
2556 snprintf(sc->dmae_mtx_name, sizeof(sc->dmae_mtx_name),
2557 "bxe%d_dmae_lock", sc->unit);
2558 mtx_init(&sc->dmae_mtx, sc->dmae_mtx_name, NULL, MTX_DEF);
2560 snprintf(sc->port.phy_mtx_name, sizeof(sc->port.phy_mtx_name),
2561 "bxe%d_phy_lock", sc->unit);
2562 mtx_init(&sc->port.phy_mtx, sc->port.phy_mtx_name, NULL, MTX_DEF);
2564 snprintf(sc->fwmb_mtx_name, sizeof(sc->fwmb_mtx_name),
2565 "bxe%d_fwmb_lock", sc->unit);
2566 mtx_init(&sc->fwmb_mtx, sc->fwmb_mtx_name, NULL, MTX_DEF);
2568 snprintf(sc->print_mtx_name, sizeof(sc->print_mtx_name),
2569 "bxe%d_print_lock", sc->unit);
2570 mtx_init(&(sc->print_mtx), sc->print_mtx_name, NULL, MTX_DEF);
2572 snprintf(sc->stats_mtx_name, sizeof(sc->stats_mtx_name),
2573 "bxe%d_stats_lock", sc->unit);
2574 mtx_init(&(sc->stats_mtx), sc->stats_mtx_name, NULL, MTX_DEF);
2576 snprintf(sc->mcast_mtx_name, sizeof(sc->mcast_mtx_name),
2577 "bxe%d_mcast_lock", sc->unit);
2578 mtx_init(&(sc->mcast_mtx), sc->mcast_mtx_name, NULL, MTX_DEF);
2582 bxe_release_mutexes(struct bxe_softc *sc)
2584 #ifdef BXE_CORE_LOCK_SX
2585 sx_destroy(&sc->core_sx);
2587 if (mtx_initialized(&sc->core_mtx)) {
2588 mtx_destroy(&sc->core_mtx);
2592 if (mtx_initialized(&sc->sp_mtx)) {
2593 mtx_destroy(&sc->sp_mtx);
2596 if (mtx_initialized(&sc->dmae_mtx)) {
2597 mtx_destroy(&sc->dmae_mtx);
2600 if (mtx_initialized(&sc->port.phy_mtx)) {
2601 mtx_destroy(&sc->port.phy_mtx);
2604 if (mtx_initialized(&sc->fwmb_mtx)) {
2605 mtx_destroy(&sc->fwmb_mtx);
2608 if (mtx_initialized(&sc->print_mtx)) {
2609 mtx_destroy(&sc->print_mtx);
2612 if (mtx_initialized(&sc->stats_mtx)) {
2613 mtx_destroy(&sc->stats_mtx);
2616 if (mtx_initialized(&sc->mcast_mtx)) {
2617 mtx_destroy(&sc->mcast_mtx);
2622 bxe_tx_disable(struct bxe_softc* sc)
2626 /* tell the stack the driver is stopped and TX queue is full */
2628 if_setdrvflags(ifp, 0);
2633 bxe_drv_pulse(struct bxe_softc *sc)
2635 SHMEM_WR(sc, func_mb[SC_FW_MB_IDX(sc)].drv_pulse_mb,
2636 sc->fw_drv_pulse_wr_seq);
2639 static inline uint16_t
2640 bxe_tx_avail(struct bxe_softc *sc,
2641 struct bxe_fastpath *fp)
2647 prod = fp->tx_bd_prod;
2648 cons = fp->tx_bd_cons;
2650 used = SUB_S16(prod, cons);
2652 return (int16_t)(sc->tx_ring_size) - used;
2656 bxe_tx_queue_has_work(struct bxe_fastpath *fp)
2660 mb(); /* status block fields can change */
2661 hw_cons = le16toh(*fp->tx_cons_sb);
2662 return (hw_cons != fp->tx_pkt_cons);
2665 static inline uint8_t
2666 bxe_has_tx_work(struct bxe_fastpath *fp)
2668 /* expand this for multi-cos if ever supported */
2669 return (bxe_tx_queue_has_work(fp)) ? TRUE : FALSE;
2673 bxe_has_rx_work(struct bxe_fastpath *fp)
2675 uint16_t rx_cq_cons_sb;
2677 mb(); /* status block fields can change */
2678 rx_cq_cons_sb = le16toh(*fp->rx_cq_cons_sb);
2679 if ((rx_cq_cons_sb & RCQ_MAX) == RCQ_MAX)
2681 return (fp->rx_cq_cons != rx_cq_cons_sb);
2685 bxe_sp_event(struct bxe_softc *sc,
2686 struct bxe_fastpath *fp,
2687 union eth_rx_cqe *rr_cqe)
2689 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
2690 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
2691 enum ecore_queue_cmd drv_cmd = ECORE_Q_CMD_MAX;
2692 struct ecore_queue_sp_obj *q_obj = &BXE_SP_OBJ(sc, fp).q_obj;
2694 BLOGD(sc, DBG_SP, "fp=%d cid=%d got ramrod #%d state is %x type is %d\n",
2695 fp->index, cid, command, sc->state, rr_cqe->ramrod_cqe.ramrod_type);
2698 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
2699 BLOGD(sc, DBG_SP, "got UPDATE ramrod. CID %d\n", cid);
2700 drv_cmd = ECORE_Q_CMD_UPDATE;
2703 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
2704 BLOGD(sc, DBG_SP, "got MULTI[%d] setup ramrod\n", cid);
2705 drv_cmd = ECORE_Q_CMD_SETUP;
2708 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
2709 BLOGD(sc, DBG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
2710 drv_cmd = ECORE_Q_CMD_SETUP_TX_ONLY;
2713 case (RAMROD_CMD_ID_ETH_HALT):
2714 BLOGD(sc, DBG_SP, "got MULTI[%d] halt ramrod\n", cid);
2715 drv_cmd = ECORE_Q_CMD_HALT;
2718 case (RAMROD_CMD_ID_ETH_TERMINATE):
2719 BLOGD(sc, DBG_SP, "got MULTI[%d] teminate ramrod\n", cid);
2720 drv_cmd = ECORE_Q_CMD_TERMINATE;
2723 case (RAMROD_CMD_ID_ETH_EMPTY):
2724 BLOGD(sc, DBG_SP, "got MULTI[%d] empty ramrod\n", cid);
2725 drv_cmd = ECORE_Q_CMD_EMPTY;
2729 BLOGD(sc, DBG_SP, "ERROR: unexpected MC reply (%d) on fp[%d]\n",
2730 command, fp->index);
2734 if ((drv_cmd != ECORE_Q_CMD_MAX) &&
2735 q_obj->complete_cmd(sc, q_obj, drv_cmd)) {
2737 * q_obj->complete_cmd() failure means that this was
2738 * an unexpected completion.
2740 * In this case we don't want to increase the sc->spq_left
2741 * because apparently we haven't sent this command the first
2744 // bxe_panic(sc, ("Unexpected SP completion\n"));
2748 atomic_add_acq_long(&sc->cq_spq_left, 1);
2750 BLOGD(sc, DBG_SP, "sc->cq_spq_left 0x%lx\n",
2751 atomic_load_acq_long(&sc->cq_spq_left));
2755 * The current mbuf is part of an aggregation. Move the mbuf into the TPA
2756 * aggregation queue, put an empty mbuf back onto the receive chain, and mark
2757 * the current aggregation queue as in-progress.
2760 bxe_tpa_start(struct bxe_softc *sc,
2761 struct bxe_fastpath *fp,
2765 struct eth_fast_path_rx_cqe *cqe)
2767 struct bxe_sw_rx_bd tmp_bd;
2768 struct bxe_sw_rx_bd *rx_buf;
2769 struct eth_rx_bd *rx_bd;
2771 struct bxe_sw_tpa_info *tpa_info = &fp->rx_tpa_info[queue];
2774 BLOGD(sc, DBG_LRO, "fp[%02d].tpa[%02d] TPA START "
2775 "cons=%d prod=%d\n",
2776 fp->index, queue, cons, prod);
2778 max_agg_queues = MAX_AGG_QS(sc);
2780 KASSERT((queue < max_agg_queues),
2781 ("fp[%02d] invalid aggr queue (%d >= %d)!",
2782 fp->index, queue, max_agg_queues));
2784 KASSERT((tpa_info->state == BXE_TPA_STATE_STOP),
2785 ("fp[%02d].tpa[%02d] starting aggr on queue not stopped!",
2788 /* copy the existing mbuf and mapping from the TPA pool */
2789 tmp_bd = tpa_info->bd;
2791 if (tmp_bd.m == NULL) {
2794 tmp = (uint32_t *)cqe;
2796 BLOGE(sc, "fp[%02d].tpa[%02d] cons[%d] prod[%d]mbuf not allocated!\n",
2797 fp->index, queue, cons, prod);
2798 BLOGE(sc, "cqe [0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x]\n",
2799 *tmp, *(tmp+1), *(tmp+2), *(tmp+3), *(tmp+4), *(tmp+5), *(tmp+6), *(tmp+7));
2801 /* XXX Error handling? */
2805 /* change the TPA queue to the start state */
2806 tpa_info->state = BXE_TPA_STATE_START;
2807 tpa_info->placement_offset = cqe->placement_offset;
2808 tpa_info->parsing_flags = le16toh(cqe->pars_flags.flags);
2809 tpa_info->vlan_tag = le16toh(cqe->vlan_tag);
2810 tpa_info->len_on_bd = le16toh(cqe->len_on_bd);
2812 fp->rx_tpa_queue_used |= (1 << queue);
2815 * If all the buffer descriptors are filled with mbufs then fill in
2816 * the current consumer index with a new BD. Else if a maximum Rx
2817 * buffer limit is imposed then fill in the next producer index.
2819 index = (sc->max_rx_bufs != RX_BD_USABLE) ?
2822 /* move the received mbuf and mapping to TPA pool */
2823 tpa_info->bd = fp->rx_mbuf_chain[cons];
2825 /* release any existing RX BD mbuf mappings */
2826 if (cons != index) {
2827 rx_buf = &fp->rx_mbuf_chain[cons];
2829 if (rx_buf->m_map != NULL) {
2830 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map,
2831 BUS_DMASYNC_POSTREAD);
2832 bus_dmamap_unload(fp->rx_mbuf_tag, rx_buf->m_map);
2836 * We get here when the maximum number of rx buffers is less than
2837 * RX_BD_USABLE. The mbuf is already saved above so it's OK to NULL
2838 * it out here without concern of a memory leak.
2840 fp->rx_mbuf_chain[cons].m = NULL;
2843 /* update the Rx SW BD with the mbuf info from the TPA pool */
2844 fp->rx_mbuf_chain[index] = tmp_bd;
2846 /* update the Rx BD with the empty mbuf phys address from the TPA pool */
2847 rx_bd = &fp->rx_chain[index];
2848 rx_bd->addr_hi = htole32(U64_HI(tpa_info->seg.ds_addr));
2849 rx_bd->addr_lo = htole32(U64_LO(tpa_info->seg.ds_addr));
2853 * When a TPA aggregation is completed, loop through the individual mbufs
2854 * of the aggregation, combining them into a single mbuf which will be sent
2855 * up the stack. Refill all freed SGEs with mbufs as we go along.
2858 bxe_fill_frag_mbuf(struct bxe_softc *sc,
2859 struct bxe_fastpath *fp,
2860 struct bxe_sw_tpa_info *tpa_info,
2864 struct eth_end_agg_rx_cqe *cqe,
2867 struct mbuf *m_frag;
2868 uint32_t frag_len, frag_size, i;
2873 frag_size = le16toh(cqe->pkt_len) - tpa_info->len_on_bd;
2876 "fp[%02d].tpa[%02d] TPA fill len_on_bd=%d frag_size=%d pages=%d\n",
2877 fp->index, queue, tpa_info->len_on_bd, frag_size, pages);
2879 /* make sure the aggregated frame is not too big to handle */
2880 if (pages > 8 * PAGES_PER_SGE) {
2882 uint32_t *tmp = (uint32_t *)cqe;
2884 BLOGE(sc, "fp[%02d].sge[0x%04x] has too many pages (%d)! "
2885 "pkt_len=%d len_on_bd=%d frag_size=%d\n",
2886 fp->index, cqe_idx, pages, le16toh(cqe->pkt_len),
2887 tpa_info->len_on_bd, frag_size);
2889 BLOGE(sc, "cqe [0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x]\n",
2890 *tmp, *(tmp+1), *(tmp+2), *(tmp+3), *(tmp+4), *(tmp+5), *(tmp+6), *(tmp+7));
2892 bxe_panic(sc, ("sge page count error\n"));
2897 * Scan through the scatter gather list pulling individual mbufs into a
2898 * single mbuf for the host stack.
2900 for (i = 0, j = 0; i < pages; i += PAGES_PER_SGE, j++) {
2901 sge_idx = RX_SGE(le16toh(cqe->sgl_or_raw_data.sgl[j]));
2904 * Firmware gives the indices of the SGE as if the ring is an array
2905 * (meaning that the "next" element will consume 2 indices).
2907 frag_len = min(frag_size, (uint32_t)(SGE_PAGES));
2909 BLOGD(sc, DBG_LRO, "fp[%02d].tpa[%02d] TPA fill i=%d j=%d "
2910 "sge_idx=%d frag_size=%d frag_len=%d\n",
2911 fp->index, queue, i, j, sge_idx, frag_size, frag_len);
2913 m_frag = fp->rx_sge_mbuf_chain[sge_idx].m;
2915 /* allocate a new mbuf for the SGE */
2916 rc = bxe_alloc_rx_sge_mbuf(fp, sge_idx);
2918 /* Leave all remaining SGEs in the ring! */
2922 /* update the fragment length */
2923 m_frag->m_len = frag_len;
2925 /* concatenate the fragment to the head mbuf */
2927 fp->eth_q_stats.mbuf_alloc_sge--;
2929 /* update the TPA mbuf size and remaining fragment size */
2930 m->m_pkthdr.len += frag_len;
2931 frag_size -= frag_len;
2935 "fp[%02d].tpa[%02d] TPA fill done frag_size=%d\n",
2936 fp->index, queue, frag_size);
2942 bxe_clear_sge_mask_next_elems(struct bxe_fastpath *fp)
2946 for (i = 1; i <= RX_SGE_NUM_PAGES; i++) {
2947 int idx = RX_SGE_TOTAL_PER_PAGE * i - 1;
2949 for (j = 0; j < 2; j++) {
2950 BIT_VEC64_CLEAR_BIT(fp->sge_mask, idx);
2957 bxe_init_sge_ring_bit_mask(struct bxe_fastpath *fp)
2959 /* set the mask to all 1's, it's faster to compare to 0 than to 0xf's */
2960 memset(fp->sge_mask, 0xff, sizeof(fp->sge_mask));
2963 * Clear the two last indices in the page to 1. These are the indices that
2964 * correspond to the "next" element, hence will never be indicated and
2965 * should be removed from the calculations.
2967 bxe_clear_sge_mask_next_elems(fp);
2971 bxe_update_last_max_sge(struct bxe_fastpath *fp,
2974 uint16_t last_max = fp->last_max_sge;
2976 if (SUB_S16(idx, last_max) > 0) {
2977 fp->last_max_sge = idx;
2982 bxe_update_sge_prod(struct bxe_softc *sc,
2983 struct bxe_fastpath *fp,
2985 union eth_sgl_or_raw_data *cqe)
2987 uint16_t last_max, last_elem, first_elem;
2995 /* first mark all used pages */
2996 for (i = 0; i < sge_len; i++) {
2997 BIT_VEC64_CLEAR_BIT(fp->sge_mask,
2998 RX_SGE(le16toh(cqe->sgl[i])));
3002 "fp[%02d] fp_cqe->sgl[%d] = %d\n",
3003 fp->index, sge_len - 1,
3004 le16toh(cqe->sgl[sge_len - 1]));
3006 /* assume that the last SGE index is the biggest */
3007 bxe_update_last_max_sge(fp,
3008 le16toh(cqe->sgl[sge_len - 1]));
3010 last_max = RX_SGE(fp->last_max_sge);
3011 last_elem = last_max >> BIT_VEC64_ELEM_SHIFT;
3012 first_elem = RX_SGE(fp->rx_sge_prod) >> BIT_VEC64_ELEM_SHIFT;
3014 /* if ring is not full */
3015 if (last_elem + 1 != first_elem) {
3019 /* now update the prod */
3020 for (i = first_elem; i != last_elem; i = RX_SGE_NEXT_MASK_ELEM(i)) {
3021 if (__predict_true(fp->sge_mask[i])) {
3025 fp->sge_mask[i] = BIT_VEC64_ELEM_ONE_MASK;
3026 delta += BIT_VEC64_ELEM_SZ;
3030 fp->rx_sge_prod += delta;
3031 /* clear page-end entries */
3032 bxe_clear_sge_mask_next_elems(fp);
3036 "fp[%02d] fp->last_max_sge=%d fp->rx_sge_prod=%d\n",
3037 fp->index, fp->last_max_sge, fp->rx_sge_prod);
3041 * The aggregation on the current TPA queue has completed. Pull the individual
3042 * mbuf fragments together into a single mbuf, perform all necessary checksum
3043 * calculations, and send the resuting mbuf to the stack.
3046 bxe_tpa_stop(struct bxe_softc *sc,
3047 struct bxe_fastpath *fp,
3048 struct bxe_sw_tpa_info *tpa_info,
3051 struct eth_end_agg_rx_cqe *cqe,
3059 "fp[%02d].tpa[%02d] pad=%d pkt_len=%d pages=%d vlan=%d\n",
3060 fp->index, queue, tpa_info->placement_offset,
3061 le16toh(cqe->pkt_len), pages, tpa_info->vlan_tag);
3065 /* allocate a replacement before modifying existing mbuf */
3066 rc = bxe_alloc_rx_tpa_mbuf(fp, queue);
3068 /* drop the frame and log an error */
3069 fp->eth_q_stats.rx_soft_errors++;
3070 goto bxe_tpa_stop_exit;
3073 /* we have a replacement, fixup the current mbuf */
3074 m_adj(m, tpa_info->placement_offset);
3075 m->m_pkthdr.len = m->m_len = tpa_info->len_on_bd;
3077 /* mark the checksums valid (taken care of by the firmware) */
3078 fp->eth_q_stats.rx_ofld_frames_csum_ip++;
3079 fp->eth_q_stats.rx_ofld_frames_csum_tcp_udp++;
3080 m->m_pkthdr.csum_data = 0xffff;
3081 m->m_pkthdr.csum_flags |= (CSUM_IP_CHECKED |
3086 /* aggregate all of the SGEs into a single mbuf */
3087 rc = bxe_fill_frag_mbuf(sc, fp, tpa_info, queue, pages, m, cqe, cqe_idx);
3089 /* drop the packet and log an error */
3090 fp->eth_q_stats.rx_soft_errors++;
3093 if (tpa_info->parsing_flags & PARSING_FLAGS_INNER_VLAN_EXIST) {
3094 m->m_pkthdr.ether_vtag = tpa_info->vlan_tag;
3095 m->m_flags |= M_VLANTAG;
3098 /* assign packet to this interface interface */
3099 if_setrcvif(m, ifp);
3101 /* specify what RSS queue was used for this flow */
3102 m->m_pkthdr.flowid = fp->index;
3105 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
3106 fp->eth_q_stats.rx_tpa_pkts++;
3108 /* pass the frame to the stack */
3112 /* we passed an mbuf up the stack or dropped the frame */
3113 fp->eth_q_stats.mbuf_alloc_tpa--;
3117 fp->rx_tpa_info[queue].state = BXE_TPA_STATE_STOP;
3118 fp->rx_tpa_queue_used &= ~(1 << queue);
3123 struct bxe_fastpath *fp,
3127 struct eth_fast_path_rx_cqe *cqe_fp)
3129 struct mbuf *m_frag;
3130 uint16_t frags, frag_len;
3131 uint16_t sge_idx = 0;
3136 /* adjust the mbuf */
3139 frag_size = len - lenonbd;
3140 frags = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT;
3142 for (i = 0, j = 0; i < frags; i += PAGES_PER_SGE, j++) {
3143 sge_idx = RX_SGE(le16toh(cqe_fp->sgl_or_raw_data.sgl[j]));
3145 m_frag = fp->rx_sge_mbuf_chain[sge_idx].m;
3146 frag_len = min(frag_size, (uint32_t)(SGE_PAGE_SIZE));
3147 m_frag->m_len = frag_len;
3149 /* allocate a new mbuf for the SGE */
3150 rc = bxe_alloc_rx_sge_mbuf(fp, sge_idx);
3152 /* Leave all remaining SGEs in the ring! */
3155 fp->eth_q_stats.mbuf_alloc_sge--;
3157 /* concatenate the fragment to the head mbuf */
3160 frag_size -= frag_len;
3163 bxe_update_sge_prod(fp->sc, fp, frags, &cqe_fp->sgl_or_raw_data);
3169 bxe_rxeof(struct bxe_softc *sc,
3170 struct bxe_fastpath *fp)
3173 uint16_t bd_cons, bd_prod, bd_prod_fw, comp_ring_cons;
3174 uint16_t hw_cq_cons, sw_cq_cons, sw_cq_prod;
3180 /* CQ "next element" is of the size of the regular element */
3181 hw_cq_cons = le16toh(*fp->rx_cq_cons_sb);
3182 if ((hw_cq_cons & RCQ_USABLE_PER_PAGE) == RCQ_USABLE_PER_PAGE) {
3186 bd_cons = fp->rx_bd_cons;
3187 bd_prod = fp->rx_bd_prod;
3188 bd_prod_fw = bd_prod;
3189 sw_cq_cons = fp->rx_cq_cons;
3190 sw_cq_prod = fp->rx_cq_prod;
3193 * Memory barrier necessary as speculative reads of the rx
3194 * buffer can be ahead of the index in the status block
3199 "fp[%02d] Rx START hw_cq_cons=%u sw_cq_cons=%u\n",
3200 fp->index, hw_cq_cons, sw_cq_cons);
3202 while (sw_cq_cons != hw_cq_cons) {
3203 struct bxe_sw_rx_bd *rx_buf = NULL;
3204 union eth_rx_cqe *cqe;
3205 struct eth_fast_path_rx_cqe *cqe_fp;
3206 uint8_t cqe_fp_flags;
3207 enum eth_rx_cqe_type cqe_fp_type;
3208 uint16_t len, lenonbd, pad;
3209 struct mbuf *m = NULL;
3211 comp_ring_cons = RCQ(sw_cq_cons);
3212 bd_prod = RX_BD(bd_prod);
3213 bd_cons = RX_BD(bd_cons);
3215 cqe = &fp->rcq_chain[comp_ring_cons];
3216 cqe_fp = &cqe->fast_path_cqe;
3217 cqe_fp_flags = cqe_fp->type_error_flags;
3218 cqe_fp_type = cqe_fp_flags & ETH_FAST_PATH_RX_CQE_TYPE;
3221 "fp[%02d] Rx hw_cq_cons=%d hw_sw_cons=%d "
3222 "BD prod=%d cons=%d CQE type=0x%x err=0x%x "
3223 "status=0x%x rss_hash=0x%x vlan=0x%x len=%u lenonbd=%u\n",
3229 CQE_TYPE(cqe_fp_flags),
3231 cqe_fp->status_flags,
3232 le32toh(cqe_fp->rss_hash_result),
3233 le16toh(cqe_fp->vlan_tag),
3234 le16toh(cqe_fp->pkt_len_or_gro_seg_len),
3235 le16toh(cqe_fp->len_on_bd));
3237 /* is this a slowpath msg? */
3238 if (__predict_false(CQE_TYPE_SLOW(cqe_fp_type))) {
3239 bxe_sp_event(sc, fp, cqe);
3243 rx_buf = &fp->rx_mbuf_chain[bd_cons];
3245 if (!CQE_TYPE_FAST(cqe_fp_type)) {
3246 struct bxe_sw_tpa_info *tpa_info;
3247 uint16_t frag_size, pages;
3250 if (CQE_TYPE_START(cqe_fp_type)) {
3251 bxe_tpa_start(sc, fp, cqe_fp->queue_index,
3252 bd_cons, bd_prod, cqe_fp);
3253 m = NULL; /* packet not ready yet */
3257 KASSERT(CQE_TYPE_STOP(cqe_fp_type),
3258 ("CQE type is not STOP! (0x%x)\n", cqe_fp_type));
3260 queue = cqe->end_agg_cqe.queue_index;
3261 tpa_info = &fp->rx_tpa_info[queue];
3263 BLOGD(sc, DBG_LRO, "fp[%02d].tpa[%02d] TPA STOP\n",
3266 frag_size = (le16toh(cqe->end_agg_cqe.pkt_len) -
3267 tpa_info->len_on_bd);
3268 pages = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT;
3270 bxe_tpa_stop(sc, fp, tpa_info, queue, pages,
3271 &cqe->end_agg_cqe, comp_ring_cons);
3273 bxe_update_sge_prod(sc, fp, pages, &cqe->end_agg_cqe.sgl_or_raw_data);
3280 /* is this an error packet? */
3281 if (__predict_false(cqe_fp_flags &
3282 ETH_FAST_PATH_RX_CQE_PHY_DECODE_ERR_FLG)) {
3283 BLOGE(sc, "flags 0x%x rx packet %u\n", cqe_fp_flags, sw_cq_cons);
3284 fp->eth_q_stats.rx_soft_errors++;
3288 len = le16toh(cqe_fp->pkt_len_or_gro_seg_len);
3289 lenonbd = le16toh(cqe_fp->len_on_bd);
3290 pad = cqe_fp->placement_offset;
3294 if (__predict_false(m == NULL)) {
3295 BLOGE(sc, "No mbuf in rx chain descriptor %d for fp[%02d]\n",
3296 bd_cons, fp->index);
3300 /* XXX double copy if packet length under a threshold */
3303 * If all the buffer descriptors are filled with mbufs then fill in
3304 * the current consumer index with a new BD. Else if a maximum Rx
3305 * buffer limit is imposed then fill in the next producer index.
3307 rc = bxe_alloc_rx_bd_mbuf(fp, bd_cons,
3308 (sc->max_rx_bufs != RX_BD_USABLE) ?
3312 /* we simply reuse the received mbuf and don't post it to the stack */
3315 BLOGE(sc, "mbuf alloc fail for fp[%02d] rx chain (%d)\n",
3317 fp->eth_q_stats.rx_soft_errors++;
3319 if (sc->max_rx_bufs != RX_BD_USABLE) {
3320 /* copy this consumer index to the producer index */
3321 memcpy(&fp->rx_mbuf_chain[bd_prod], rx_buf,
3322 sizeof(struct bxe_sw_rx_bd));
3323 memset(rx_buf, 0, sizeof(struct bxe_sw_rx_bd));
3329 /* current mbuf was detached from the bd */
3330 fp->eth_q_stats.mbuf_alloc_rx--;
3332 /* we allocated a replacement mbuf, fixup the current one */
3334 m->m_pkthdr.len = m->m_len = len;
3336 if ((len > 60) && (len > lenonbd)) {
3337 fp->eth_q_stats.rx_bxe_service_rxsgl++;
3338 rc = bxe_service_rxsgl(fp, len, lenonbd, m, cqe_fp);
3341 fp->eth_q_stats.rx_jumbo_sge_pkts++;
3342 } else if (lenonbd < len) {
3343 fp->eth_q_stats.rx_erroneous_jumbo_sge_pkts++;
3346 /* assign packet to this interface interface */
3347 if_setrcvif(m, ifp);
3349 /* assume no hardware checksum has complated */
3350 m->m_pkthdr.csum_flags = 0;
3352 /* validate checksum if offload enabled */
3353 if (if_getcapenable(ifp) & IFCAP_RXCSUM) {
3354 /* check for a valid IP frame */
3355 if (!(cqe->fast_path_cqe.status_flags &
3356 ETH_FAST_PATH_RX_CQE_IP_XSUM_NO_VALIDATION_FLG)) {
3357 m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED;
3358 if (__predict_false(cqe_fp_flags &
3359 ETH_FAST_PATH_RX_CQE_IP_BAD_XSUM_FLG)) {
3360 fp->eth_q_stats.rx_hw_csum_errors++;
3362 fp->eth_q_stats.rx_ofld_frames_csum_ip++;
3363 m->m_pkthdr.csum_flags |= CSUM_IP_VALID;
3367 /* check for a valid TCP/UDP frame */
3368 if (!(cqe->fast_path_cqe.status_flags &
3369 ETH_FAST_PATH_RX_CQE_L4_XSUM_NO_VALIDATION_FLG)) {
3370 if (__predict_false(cqe_fp_flags &
3371 ETH_FAST_PATH_RX_CQE_L4_BAD_XSUM_FLG)) {
3372 fp->eth_q_stats.rx_hw_csum_errors++;
3374 fp->eth_q_stats.rx_ofld_frames_csum_tcp_udp++;
3375 m->m_pkthdr.csum_data = 0xFFFF;
3376 m->m_pkthdr.csum_flags |= (CSUM_DATA_VALID |
3382 /* if there is a VLAN tag then flag that info */
3383 if (cqe->fast_path_cqe.pars_flags.flags & PARSING_FLAGS_INNER_VLAN_EXIST) {
3384 m->m_pkthdr.ether_vtag = cqe->fast_path_cqe.vlan_tag;
3385 m->m_flags |= M_VLANTAG;
3388 /* specify what RSS queue was used for this flow */
3389 m->m_pkthdr.flowid = fp->index;
3394 bd_cons = RX_BD_NEXT(bd_cons);
3395 bd_prod = RX_BD_NEXT(bd_prod);
3396 bd_prod_fw = RX_BD_NEXT(bd_prod_fw);
3398 /* pass the frame to the stack */
3399 if (__predict_true(m != NULL)) {
3400 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
3407 sw_cq_prod = RCQ_NEXT(sw_cq_prod);
3408 sw_cq_cons = RCQ_NEXT(sw_cq_cons);
3410 /* limit spinning on the queue */
3414 if (rx_pkts == sc->rx_budget) {
3415 fp->eth_q_stats.rx_budget_reached++;
3418 } /* while work to do */
3420 fp->rx_bd_cons = bd_cons;
3421 fp->rx_bd_prod = bd_prod_fw;
3422 fp->rx_cq_cons = sw_cq_cons;
3423 fp->rx_cq_prod = sw_cq_prod;
3425 /* Update producers */
3426 bxe_update_rx_prod(sc, fp, bd_prod_fw, sw_cq_prod, fp->rx_sge_prod);
3428 fp->eth_q_stats.rx_pkts += rx_pkts;
3429 fp->eth_q_stats.rx_calls++;
3431 BXE_FP_RX_UNLOCK(fp);
3433 return (sw_cq_cons != hw_cq_cons);
3437 bxe_free_tx_pkt(struct bxe_softc *sc,
3438 struct bxe_fastpath *fp,
3441 struct bxe_sw_tx_bd *tx_buf = &fp->tx_mbuf_chain[idx];
3442 struct eth_tx_start_bd *tx_start_bd;
3443 uint16_t bd_idx = TX_BD(tx_buf->first_bd);
3447 /* unmap the mbuf from non-paged memory */
3448 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
3450 tx_start_bd = &fp->tx_chain[bd_idx].start_bd;
3451 nbd = le16toh(tx_start_bd->nbd) - 1;
3453 new_cons = (tx_buf->first_bd + nbd);
3456 if (__predict_true(tx_buf->m != NULL)) {
3458 fp->eth_q_stats.mbuf_alloc_tx--;
3460 fp->eth_q_stats.tx_chain_lost_mbuf++;
3464 tx_buf->first_bd = 0;
3469 /* transmit timeout watchdog */
3471 bxe_watchdog(struct bxe_softc *sc,
3472 struct bxe_fastpath *fp)
3476 if ((fp->watchdog_timer == 0) || (--fp->watchdog_timer)) {
3477 BXE_FP_TX_UNLOCK(fp);
3481 BLOGE(sc, "TX watchdog timeout on fp[%02d], resetting!\n", fp->index);
3483 BXE_FP_TX_UNLOCK(fp);
3484 BXE_SET_ERROR_BIT(sc, BXE_ERR_TXQ_STUCK);
3485 taskqueue_enqueue_timeout(taskqueue_thread,
3486 &sc->sp_err_timeout_task, hz/10);
3491 /* processes transmit completions */
3493 bxe_txeof(struct bxe_softc *sc,
3494 struct bxe_fastpath *fp)
3497 uint16_t bd_cons, hw_cons, sw_cons, pkt_cons;
3498 uint16_t tx_bd_avail;
3500 BXE_FP_TX_LOCK_ASSERT(fp);
3502 bd_cons = fp->tx_bd_cons;
3503 hw_cons = le16toh(*fp->tx_cons_sb);
3504 sw_cons = fp->tx_pkt_cons;
3506 while (sw_cons != hw_cons) {
3507 pkt_cons = TX_BD(sw_cons);
3510 "TX: fp[%d]: hw_cons=%u sw_cons=%u pkt_cons=%u\n",
3511 fp->index, hw_cons, sw_cons, pkt_cons);
3513 bd_cons = bxe_free_tx_pkt(sc, fp, pkt_cons);
3518 fp->tx_pkt_cons = sw_cons;
3519 fp->tx_bd_cons = bd_cons;
3522 "TX done: fp[%d]: hw_cons=%u sw_cons=%u sw_prod=%u\n",
3523 fp->index, hw_cons, fp->tx_pkt_cons, fp->tx_pkt_prod);
3527 tx_bd_avail = bxe_tx_avail(sc, fp);
3529 if (tx_bd_avail < BXE_TX_CLEANUP_THRESHOLD) {
3530 if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0);
3532 if_setdrvflagbits(ifp, 0, IFF_DRV_OACTIVE);
3535 if (fp->tx_pkt_prod != fp->tx_pkt_cons) {
3536 /* reset the watchdog timer if there are pending transmits */
3537 fp->watchdog_timer = BXE_TX_TIMEOUT;
3540 /* clear watchdog when there are no pending transmits */
3541 fp->watchdog_timer = 0;
3547 bxe_drain_tx_queues(struct bxe_softc *sc)
3549 struct bxe_fastpath *fp;
3552 /* wait until all TX fastpath tasks have completed */
3553 for (i = 0; i < sc->num_queues; i++) {
3558 while (bxe_has_tx_work(fp)) {
3562 BXE_FP_TX_UNLOCK(fp);
3565 BLOGE(sc, "Timeout waiting for fp[%d] "
3566 "transmits to complete!\n", i);
3567 bxe_panic(sc, ("tx drain failure\n"));
3581 bxe_del_all_macs(struct bxe_softc *sc,
3582 struct ecore_vlan_mac_obj *mac_obj,
3584 uint8_t wait_for_comp)
3586 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
3589 /* wait for completion of requested */
3590 if (wait_for_comp) {
3591 bxe_set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
3594 /* Set the mac type of addresses we want to clear */
3595 bxe_set_bit(mac_type, &vlan_mac_flags);
3597 rc = mac_obj->delete_all(sc, mac_obj, &vlan_mac_flags, &ramrod_flags);
3599 BLOGE(sc, "Failed to delete MACs (%d) mac_type %d wait_for_comp 0x%x\n",
3600 rc, mac_type, wait_for_comp);
3607 bxe_fill_accept_flags(struct bxe_softc *sc,
3609 unsigned long *rx_accept_flags,
3610 unsigned long *tx_accept_flags)
3612 /* Clear the flags first */
3613 *rx_accept_flags = 0;
3614 *tx_accept_flags = 0;
3617 case BXE_RX_MODE_NONE:
3619 * 'drop all' supersedes any accept flags that may have been
3620 * passed to the function.
3624 case BXE_RX_MODE_NORMAL:
3625 bxe_set_bit(ECORE_ACCEPT_UNICAST, rx_accept_flags);
3626 bxe_set_bit(ECORE_ACCEPT_MULTICAST, rx_accept_flags);
3627 bxe_set_bit(ECORE_ACCEPT_BROADCAST, rx_accept_flags);
3629 /* internal switching mode */
3630 bxe_set_bit(ECORE_ACCEPT_UNICAST, tx_accept_flags);
3631 bxe_set_bit(ECORE_ACCEPT_MULTICAST, tx_accept_flags);
3632 bxe_set_bit(ECORE_ACCEPT_BROADCAST, tx_accept_flags);
3636 case BXE_RX_MODE_ALLMULTI:
3637 bxe_set_bit(ECORE_ACCEPT_UNICAST, rx_accept_flags);
3638 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, rx_accept_flags);
3639 bxe_set_bit(ECORE_ACCEPT_BROADCAST, rx_accept_flags);
3641 /* internal switching mode */
3642 bxe_set_bit(ECORE_ACCEPT_UNICAST, tx_accept_flags);
3643 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, tx_accept_flags);
3644 bxe_set_bit(ECORE_ACCEPT_BROADCAST, tx_accept_flags);
3648 case BXE_RX_MODE_PROMISC:
3650 * According to deffinition of SI mode, iface in promisc mode
3651 * should receive matched and unmatched (in resolution of port)
3654 bxe_set_bit(ECORE_ACCEPT_UNMATCHED, rx_accept_flags);
3655 bxe_set_bit(ECORE_ACCEPT_UNICAST, rx_accept_flags);
3656 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, rx_accept_flags);
3657 bxe_set_bit(ECORE_ACCEPT_BROADCAST, rx_accept_flags);
3659 /* internal switching mode */
3660 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, tx_accept_flags);
3661 bxe_set_bit(ECORE_ACCEPT_BROADCAST, tx_accept_flags);
3664 bxe_set_bit(ECORE_ACCEPT_ALL_UNICAST, tx_accept_flags);
3666 bxe_set_bit(ECORE_ACCEPT_UNICAST, tx_accept_flags);
3672 BLOGE(sc, "Unknown rx_mode (0x%x)\n", rx_mode);
3676 /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
3677 if (rx_mode != BXE_RX_MODE_NONE) {
3678 bxe_set_bit(ECORE_ACCEPT_ANY_VLAN, rx_accept_flags);
3679 bxe_set_bit(ECORE_ACCEPT_ANY_VLAN, tx_accept_flags);
3686 bxe_set_q_rx_mode(struct bxe_softc *sc,
3688 unsigned long rx_mode_flags,
3689 unsigned long rx_accept_flags,
3690 unsigned long tx_accept_flags,
3691 unsigned long ramrod_flags)
3693 struct ecore_rx_mode_ramrod_params ramrod_param;
3696 memset(&ramrod_param, 0, sizeof(ramrod_param));
3698 /* Prepare ramrod parameters */
3699 ramrod_param.cid = 0;
3700 ramrod_param.cl_id = cl_id;
3701 ramrod_param.rx_mode_obj = &sc->rx_mode_obj;
3702 ramrod_param.func_id = SC_FUNC(sc);
3704 ramrod_param.pstate = &sc->sp_state;
3705 ramrod_param.state = ECORE_FILTER_RX_MODE_PENDING;
3707 ramrod_param.rdata = BXE_SP(sc, rx_mode_rdata);
3708 ramrod_param.rdata_mapping = BXE_SP_MAPPING(sc, rx_mode_rdata);
3710 bxe_set_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state);
3712 ramrod_param.ramrod_flags = ramrod_flags;
3713 ramrod_param.rx_mode_flags = rx_mode_flags;
3715 ramrod_param.rx_accept_flags = rx_accept_flags;
3716 ramrod_param.tx_accept_flags = tx_accept_flags;
3718 rc = ecore_config_rx_mode(sc, &ramrod_param);
3720 BLOGE(sc, "Set rx_mode %d cli_id 0x%x rx_mode_flags 0x%x "
3721 "rx_accept_flags 0x%x tx_accept_flags 0x%x "
3722 "ramrod_flags 0x%x rc %d failed\n", sc->rx_mode, cl_id,
3723 (uint32_t)rx_mode_flags, (uint32_t)rx_accept_flags,
3724 (uint32_t)tx_accept_flags, (uint32_t)ramrod_flags, rc);
3732 bxe_set_storm_rx_mode(struct bxe_softc *sc)
3734 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
3735 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
3738 rc = bxe_fill_accept_flags(sc, sc->rx_mode, &rx_accept_flags,
3744 bxe_set_bit(RAMROD_RX, &ramrod_flags);
3745 bxe_set_bit(RAMROD_TX, &ramrod_flags);
3747 /* XXX ensure all fastpath have same cl_id and/or move it to bxe_softc */
3748 return (bxe_set_q_rx_mode(sc, sc->fp[0].cl_id, rx_mode_flags,
3749 rx_accept_flags, tx_accept_flags,
3753 /* returns the "mcp load_code" according to global load_count array */
3755 bxe_nic_load_no_mcp(struct bxe_softc *sc)
3757 int path = SC_PATH(sc);
3758 int port = SC_PORT(sc);
3760 BLOGI(sc, "NO MCP - load counts[%d] %d, %d, %d\n",
3761 path, load_count[path][0], load_count[path][1],
3762 load_count[path][2]);
3763 load_count[path][0]++;
3764 load_count[path][1 + port]++;
3765 BLOGI(sc, "NO MCP - new load counts[%d] %d, %d, %d\n",
3766 path, load_count[path][0], load_count[path][1],
3767 load_count[path][2]);
3768 if (load_count[path][0] == 1) {
3769 return (FW_MSG_CODE_DRV_LOAD_COMMON);
3770 } else if (load_count[path][1 + port] == 1) {
3771 return (FW_MSG_CODE_DRV_LOAD_PORT);
3773 return (FW_MSG_CODE_DRV_LOAD_FUNCTION);
3777 /* returns the "mcp load_code" according to global load_count array */
3779 bxe_nic_unload_no_mcp(struct bxe_softc *sc)
3781 int port = SC_PORT(sc);
3782 int path = SC_PATH(sc);
3784 BLOGI(sc, "NO MCP - load counts[%d] %d, %d, %d\n",
3785 path, load_count[path][0], load_count[path][1],
3786 load_count[path][2]);
3787 load_count[path][0]--;
3788 load_count[path][1 + port]--;
3789 BLOGI(sc, "NO MCP - new load counts[%d] %d, %d, %d\n",
3790 path, load_count[path][0], load_count[path][1],
3791 load_count[path][2]);
3792 if (load_count[path][0] == 0) {
3793 return (FW_MSG_CODE_DRV_UNLOAD_COMMON);
3794 } else if (load_count[path][1 + port] == 0) {
3795 return (FW_MSG_CODE_DRV_UNLOAD_PORT);
3797 return (FW_MSG_CODE_DRV_UNLOAD_FUNCTION);
3801 /* request unload mode from the MCP: COMMON, PORT or FUNCTION */
3803 bxe_send_unload_req(struct bxe_softc *sc,
3806 uint32_t reset_code = 0;
3808 /* Select the UNLOAD request mode */
3809 if (unload_mode == UNLOAD_NORMAL) {
3810 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
3812 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
3815 /* Send the request to the MCP */
3816 if (!BXE_NOMCP(sc)) {
3817 reset_code = bxe_fw_command(sc, reset_code, 0);
3819 reset_code = bxe_nic_unload_no_mcp(sc);
3822 return (reset_code);
3825 /* send UNLOAD_DONE command to the MCP */
3827 bxe_send_unload_done(struct bxe_softc *sc,
3830 uint32_t reset_param =
3831 keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
3833 /* Report UNLOAD_DONE to MCP */
3834 if (!BXE_NOMCP(sc)) {
3835 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
3840 bxe_func_wait_started(struct bxe_softc *sc)
3844 if (!sc->port.pmf) {
3849 * (assumption: No Attention from MCP at this stage)
3850 * PMF probably in the middle of TX disable/enable transaction
3851 * 1. Sync IRS for default SB
3852 * 2. Sync SP queue - this guarantees us that attention handling started
3853 * 3. Wait, that TX disable/enable transaction completes
3855 * 1+2 guarantee that if DCBX attention was scheduled it already changed
3856 * pending bit of transaction from STARTED-->TX_STOPPED, if we already
3857 * received completion for the transaction the state is TX_STOPPED.
3858 * State will return to STARTED after completion of TX_STOPPED-->STARTED
3862 /* XXX make sure default SB ISR is done */
3863 /* need a way to synchronize an irq (intr_mtx?) */
3865 /* XXX flush any work queues */
3867 while (ecore_func_get_state(sc, &sc->func_obj) !=
3868 ECORE_F_STATE_STARTED && tout--) {
3872 if (ecore_func_get_state(sc, &sc->func_obj) != ECORE_F_STATE_STARTED) {
3874 * Failed to complete the transaction in a "good way"
3875 * Force both transactions with CLR bit.
3877 struct ecore_func_state_params func_params = { NULL };
3879 BLOGE(sc, "Unexpected function state! "
3880 "Forcing STARTED-->TX_STOPPED-->STARTED\n");
3882 func_params.f_obj = &sc->func_obj;
3883 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
3885 /* STARTED-->TX_STOPPED */
3886 func_params.cmd = ECORE_F_CMD_TX_STOP;
3887 ecore_func_state_change(sc, &func_params);
3889 /* TX_STOPPED-->STARTED */
3890 func_params.cmd = ECORE_F_CMD_TX_START;
3891 return (ecore_func_state_change(sc, &func_params));
3898 bxe_stop_queue(struct bxe_softc *sc,
3901 struct bxe_fastpath *fp = &sc->fp[index];
3902 struct ecore_queue_state_params q_params = { NULL };
3905 BLOGD(sc, DBG_LOAD, "stopping queue %d cid %d\n", index, fp->index);
3907 q_params.q_obj = &sc->sp_objs[fp->index].q_obj;
3908 /* We want to wait for completion in this context */
3909 bxe_set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
3911 /* Stop the primary connection: */
3913 /* ...halt the connection */
3914 q_params.cmd = ECORE_Q_CMD_HALT;
3915 rc = ecore_queue_state_change(sc, &q_params);
3920 /* ...terminate the connection */
3921 q_params.cmd = ECORE_Q_CMD_TERMINATE;
3922 memset(&q_params.params.terminate, 0, sizeof(q_params.params.terminate));
3923 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
3924 rc = ecore_queue_state_change(sc, &q_params);
3929 /* ...delete cfc entry */
3930 q_params.cmd = ECORE_Q_CMD_CFC_DEL;
3931 memset(&q_params.params.cfc_del, 0, sizeof(q_params.params.cfc_del));
3932 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
3933 return (ecore_queue_state_change(sc, &q_params));
3936 /* wait for the outstanding SP commands */
3937 static inline uint8_t
3938 bxe_wait_sp_comp(struct bxe_softc *sc,
3942 int tout = 5000; /* wait for 5 secs tops */
3946 if (!(atomic_load_acq_long(&sc->sp_state) & mask)) {
3955 tmp = atomic_load_acq_long(&sc->sp_state);
3957 BLOGE(sc, "Filtering completion timed out: "
3958 "sp_state 0x%lx, mask 0x%lx\n",
3967 bxe_func_stop(struct bxe_softc *sc)
3969 struct ecore_func_state_params func_params = { NULL };
3972 /* prepare parameters for function state transitions */
3973 bxe_set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
3974 func_params.f_obj = &sc->func_obj;
3975 func_params.cmd = ECORE_F_CMD_STOP;
3978 * Try to stop the function the 'good way'. If it fails (in case
3979 * of a parity error during bxe_chip_cleanup()) and we are
3980 * not in a debug mode, perform a state transaction in order to
3981 * enable further HW_RESET transaction.
3983 rc = ecore_func_state_change(sc, &func_params);
3985 BLOGE(sc, "FUNC_STOP ramrod failed. "
3986 "Running a dry transaction (%d)\n", rc);
3987 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
3988 return (ecore_func_state_change(sc, &func_params));
3995 bxe_reset_hw(struct bxe_softc *sc,
3998 struct ecore_func_state_params func_params = { NULL };
4000 /* Prepare parameters for function state transitions */
4001 bxe_set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
4003 func_params.f_obj = &sc->func_obj;
4004 func_params.cmd = ECORE_F_CMD_HW_RESET;
4006 func_params.params.hw_init.load_phase = load_code;
4008 return (ecore_func_state_change(sc, &func_params));
4012 bxe_int_disable_sync(struct bxe_softc *sc,
4016 /* prevent the HW from sending interrupts */
4017 bxe_int_disable(sc);
4020 /* XXX need a way to synchronize ALL irqs (intr_mtx?) */
4021 /* make sure all ISRs are done */
4023 /* XXX make sure sp_task is not running */
4024 /* cancel and flush work queues */
4028 bxe_chip_cleanup(struct bxe_softc *sc,
4029 uint32_t unload_mode,
4032 int port = SC_PORT(sc);
4033 struct ecore_mcast_ramrod_params rparam = { NULL };
4034 uint32_t reset_code;
4037 bxe_drain_tx_queues(sc);
4039 /* give HW time to discard old tx messages */
4042 /* Clean all ETH MACs */
4043 rc = bxe_del_all_macs(sc, &sc->sp_objs[0].mac_obj, ECORE_ETH_MAC, FALSE);
4045 BLOGE(sc, "Failed to delete all ETH MACs (%d)\n", rc);
4048 /* Clean up UC list */
4049 rc = bxe_del_all_macs(sc, &sc->sp_objs[0].mac_obj, ECORE_UC_LIST_MAC, TRUE);
4051 BLOGE(sc, "Failed to delete UC MACs list (%d)\n", rc);
4055 if (!CHIP_IS_E1(sc)) {
4056 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 0);
4059 /* Set "drop all" to stop Rx */
4062 * We need to take the BXE_MCAST_LOCK() here in order to prevent
4063 * a race between the completion code and this code.
4067 if (bxe_test_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state)) {
4068 bxe_set_bit(ECORE_FILTER_RX_MODE_SCHED, &sc->sp_state);
4070 bxe_set_storm_rx_mode(sc);
4073 /* Clean up multicast configuration */
4074 rparam.mcast_obj = &sc->mcast_obj;
4075 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL);
4077 BLOGE(sc, "Failed to send DEL MCAST command (%d)\n", rc);
4080 BXE_MCAST_UNLOCK(sc);
4082 // XXX bxe_iov_chip_cleanup(sc);
4085 * Send the UNLOAD_REQUEST to the MCP. This will return if
4086 * this function should perform FUNCTION, PORT, or COMMON HW
4089 reset_code = bxe_send_unload_req(sc, unload_mode);
4092 * (assumption: No Attention from MCP at this stage)
4093 * PMF probably in the middle of TX disable/enable transaction
4095 rc = bxe_func_wait_started(sc);
4097 BLOGE(sc, "bxe_func_wait_started failed (%d)\n", rc);
4101 * Close multi and leading connections
4102 * Completions for ramrods are collected in a synchronous way
4104 for (i = 0; i < sc->num_queues; i++) {
4105 if (bxe_stop_queue(sc, i)) {
4111 * If SP settings didn't get completed so far - something
4112 * very wrong has happen.
4114 if (!bxe_wait_sp_comp(sc, ~0x0UL)) {
4115 BLOGE(sc, "Common slow path ramrods got stuck!(%d)\n", rc);
4120 rc = bxe_func_stop(sc);
4122 BLOGE(sc, "Function stop failed!(%d)\n", rc);
4125 /* disable HW interrupts */
4126 bxe_int_disable_sync(sc, TRUE);
4128 /* detach interrupts */
4129 bxe_interrupt_detach(sc);
4131 /* Reset the chip */
4132 rc = bxe_reset_hw(sc, reset_code);
4134 BLOGE(sc, "Hardware reset failed(%d)\n", rc);
4137 /* Report UNLOAD_DONE to MCP */
4138 bxe_send_unload_done(sc, keep_link);
4142 bxe_disable_close_the_gate(struct bxe_softc *sc)
4145 int port = SC_PORT(sc);
4148 "Disabling 'close the gates'\n");
4150 if (CHIP_IS_E1(sc)) {
4151 uint32_t addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4152 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4153 val = REG_RD(sc, addr);
4155 REG_WR(sc, addr, val);
4157 val = REG_RD(sc, MISC_REG_AEU_GENERAL_MASK);
4158 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
4159 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
4160 REG_WR(sc, MISC_REG_AEU_GENERAL_MASK, val);
4165 * Cleans the object that have internal lists without sending
4166 * ramrods. Should be run when interrutps are disabled.
4169 bxe_squeeze_objects(struct bxe_softc *sc)
4171 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
4172 struct ecore_mcast_ramrod_params rparam = { NULL };
4173 struct ecore_vlan_mac_obj *mac_obj = &sc->sp_objs->mac_obj;
4176 /* Cleanup MACs' object first... */
4178 /* Wait for completion of requested */
4179 bxe_set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
4180 /* Perform a dry cleanup */
4181 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &ramrod_flags);
4183 /* Clean ETH primary MAC */
4184 bxe_set_bit(ECORE_ETH_MAC, &vlan_mac_flags);
4185 rc = mac_obj->delete_all(sc, &sc->sp_objs->mac_obj, &vlan_mac_flags,
4188 BLOGE(sc, "Failed to clean ETH MACs (%d)\n", rc);
4191 /* Cleanup UC list */
4193 bxe_set_bit(ECORE_UC_LIST_MAC, &vlan_mac_flags);
4194 rc = mac_obj->delete_all(sc, mac_obj, &vlan_mac_flags,
4197 BLOGE(sc, "Failed to clean UC list MACs (%d)\n", rc);
4200 /* Now clean mcast object... */
4202 rparam.mcast_obj = &sc->mcast_obj;
4203 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &rparam.ramrod_flags);
4205 /* Add a DEL command... */
4206 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL);
4208 BLOGE(sc, "Failed to send DEL MCAST command (%d)\n", rc);
4211 /* now wait until all pending commands are cleared */
4213 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT);
4216 BLOGE(sc, "Failed to clean MCAST object (%d)\n", rc);
4220 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT);
4224 /* stop the controller */
4225 static __noinline int
4226 bxe_nic_unload(struct bxe_softc *sc,
4227 uint32_t unload_mode,
4230 uint8_t global = FALSE;
4234 BXE_CORE_LOCK_ASSERT(sc);
4236 if_setdrvflagbits(sc->ifp, 0, IFF_DRV_RUNNING);
4238 for (i = 0; i < sc->num_queues; i++) {
4239 struct bxe_fastpath *fp;
4242 fp->watchdog_timer = 0;
4244 BXE_FP_TX_UNLOCK(fp);
4247 BLOGD(sc, DBG_LOAD, "Starting NIC unload...\n");
4249 /* mark driver as unloaded in shmem2 */
4250 if (IS_PF(sc) && SHMEM2_HAS(sc, drv_capabilities_flag)) {
4251 val = SHMEM2_RD(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)]);
4252 SHMEM2_WR(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)],
4253 val & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
4256 if (IS_PF(sc) && sc->recovery_state != BXE_RECOVERY_DONE &&
4257 (sc->state == BXE_STATE_CLOSED || sc->state == BXE_STATE_ERROR)) {
4259 if(CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) {
4261 * We can get here if the driver has been unloaded
4262 * during parity error recovery and is either waiting for a
4263 * leader to complete or for other functions to unload and
4264 * then ifconfig down has been issued. In this case we want to
4265 * unload and let other functions to complete a recovery
4268 sc->recovery_state = BXE_RECOVERY_DONE;
4270 bxe_release_leader_lock(sc);
4272 BLOGD(sc, DBG_LOAD, "Releasing a leadership...\n");
4274 BLOGE(sc, "Can't unload in closed or error state recover_state 0x%x"
4275 " state = 0x%x\n", sc->recovery_state, sc->state);
4280 * Nothing to do during unload if previous bxe_nic_load()
4281 * did not completed successfully - all resourses are released.
4283 if ((sc->state == BXE_STATE_CLOSED) ||
4284 (sc->state == BXE_STATE_ERROR)) {
4288 sc->state = BXE_STATE_CLOSING_WAITING_HALT;
4294 sc->rx_mode = BXE_RX_MODE_NONE;
4295 /* XXX set rx mode ??? */
4297 if (IS_PF(sc) && !sc->grcdump_done) {
4298 /* set ALWAYS_ALIVE bit in shmem */
4299 sc->fw_drv_pulse_wr_seq |= DRV_PULSE_ALWAYS_ALIVE;
4303 bxe_stats_handle(sc, STATS_EVENT_STOP);
4304 bxe_save_statistics(sc);
4307 /* wait till consumers catch up with producers in all queues */
4308 bxe_drain_tx_queues(sc);
4310 /* if VF indicate to PF this function is going down (PF will delete sp
4311 * elements and clear initializations
4314 ; /* bxe_vfpf_close_vf(sc); */
4315 } else if (unload_mode != UNLOAD_RECOVERY) {
4316 /* if this is a normal/close unload need to clean up chip */
4317 if (!sc->grcdump_done)
4318 bxe_chip_cleanup(sc, unload_mode, keep_link);
4320 /* Send the UNLOAD_REQUEST to the MCP */
4321 bxe_send_unload_req(sc, unload_mode);
4324 * Prevent transactions to host from the functions on the
4325 * engine that doesn't reset global blocks in case of global
4326 * attention once gloabl blocks are reset and gates are opened
4327 * (the engine which leader will perform the recovery
4330 if (!CHIP_IS_E1x(sc)) {
4334 /* disable HW interrupts */
4335 bxe_int_disable_sync(sc, TRUE);
4337 /* detach interrupts */
4338 bxe_interrupt_detach(sc);
4340 /* Report UNLOAD_DONE to MCP */
4341 bxe_send_unload_done(sc, FALSE);
4345 * At this stage no more interrupts will arrive so we may safely clean
4346 * the queue'able objects here in case they failed to get cleaned so far.
4349 bxe_squeeze_objects(sc);
4352 /* There should be no more pending SP commands at this stage */
4357 bxe_free_fp_buffers(sc);
4363 bxe_free_fw_stats_mem(sc);
4365 sc->state = BXE_STATE_CLOSED;
4368 * Check if there are pending parity attentions. If there are - set
4369 * RECOVERY_IN_PROGRESS.
4371 if (IS_PF(sc) && bxe_chk_parity_attn(sc, &global, FALSE)) {
4372 bxe_set_reset_in_progress(sc);
4374 /* Set RESET_IS_GLOBAL if needed */
4376 bxe_set_reset_global(sc);
4381 * The last driver must disable a "close the gate" if there is no
4382 * parity attention or "process kill" pending.
4384 if (IS_PF(sc) && !bxe_clear_pf_load(sc) &&
4385 bxe_reset_is_done(sc, SC_PATH(sc))) {
4386 bxe_disable_close_the_gate(sc);
4389 BLOGD(sc, DBG_LOAD, "Ended NIC unload\n");
4391 bxe_link_report(sc);
4397 * Called by the OS to set various media options (i.e. link, speed, etc.) when
4398 * the user runs "ifconfig bxe media ..." or "ifconfig bxe mediaopt ...".
4401 bxe_ifmedia_update(struct ifnet *ifp)
4403 struct bxe_softc *sc = (struct bxe_softc *)if_getsoftc(ifp);
4404 struct ifmedia *ifm;
4408 /* We only support Ethernet media type. */
4409 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) {
4413 switch (IFM_SUBTYPE(ifm->ifm_media)) {
4419 case IFM_10G_TWINAX:
4421 /* We don't support changing the media type. */
4422 BLOGD(sc, DBG_LOAD, "Invalid media type (%d)\n",
4423 IFM_SUBTYPE(ifm->ifm_media));
4431 * Called by the OS to get the current media status (i.e. link, speed, etc.).
4434 bxe_ifmedia_status(struct ifnet *ifp, struct ifmediareq *ifmr)
4436 struct bxe_softc *sc = if_getsoftc(ifp);
4438 /* Bug 165447: the 'ifconfig' tool skips printing of the "status: ..."
4439 line if the IFM_AVALID flag is *NOT* set. So we need to set this
4440 flag unconditionally (irrespective of the admininistrative
4441 'up/down' state of the interface) to ensure that that line is always
4444 ifmr->ifm_status = IFM_AVALID;
4446 /* Setup the default interface info. */
4447 ifmr->ifm_active = IFM_ETHER;
4449 /* Report link down if the driver isn't running. */
4450 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
4451 ifmr->ifm_active |= IFM_NONE;
4452 BLOGD(sc, DBG_PHY, "in %s : nic still not loaded fully\n", __func__);
4453 BLOGD(sc, DBG_PHY, "in %s : link_up (1) : %d\n",
4454 __func__, sc->link_vars.link_up);
4459 if (sc->link_vars.link_up) {
4460 ifmr->ifm_status |= IFM_ACTIVE;
4461 ifmr->ifm_active |= IFM_FDX;
4463 ifmr->ifm_active |= IFM_NONE;
4464 BLOGD(sc, DBG_PHY, "in %s : setting IFM_NONE\n",
4469 ifmr->ifm_active |= sc->media;
4474 bxe_handle_chip_tq(void *context,
4477 struct bxe_softc *sc = (struct bxe_softc *)context;
4478 long work = atomic_load_acq_long(&sc->chip_tq_flags);
4483 case CHIP_TQ_REINIT:
4484 if (if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING) {
4485 /* restart the interface */
4486 BLOGD(sc, DBG_LOAD, "Restarting the interface...\n");
4487 bxe_periodic_stop(sc);
4489 bxe_stop_locked(sc);
4490 bxe_init_locked(sc);
4491 BXE_CORE_UNLOCK(sc);
4501 * Handles any IOCTL calls from the operating system.
4504 * 0 = Success, >0 Failure
4511 struct bxe_softc *sc = if_getsoftc(ifp);
4512 struct ifreq *ifr = (struct ifreq *)data;
4517 int mtu_min = (ETH_MIN_PACKET_SIZE - ETH_HLEN);
4518 int mtu_max = (MJUM9BYTES - ETH_OVERHEAD - IP_HEADER_ALIGNMENT_PADDING);
4523 BLOGD(sc, DBG_IOCTL, "Received SIOCSIFMTU ioctl (mtu=%d)\n",
4526 if (sc->mtu == ifr->ifr_mtu) {
4527 /* nothing to change */
4531 if ((ifr->ifr_mtu < mtu_min) || (ifr->ifr_mtu > mtu_max)) {
4532 BLOGE(sc, "Unsupported MTU size %d (range is %d-%d)\n",
4533 ifr->ifr_mtu, mtu_min, mtu_max);
4538 atomic_store_rel_int((volatile unsigned int *)&sc->mtu,
4539 (unsigned long)ifr->ifr_mtu);
4541 atomic_store_rel_long((volatile unsigned long *)&if_getmtu(ifp),
4542 (unsigned long)ifr->ifr_mtu);
4543 XXX - Not sure why it needs to be atomic
4545 if_setmtu(ifp, ifr->ifr_mtu);
4550 /* toggle the interface state up or down */
4551 BLOGD(sc, DBG_IOCTL, "Received SIOCSIFFLAGS ioctl\n");
4554 /* check if the interface is up */
4555 if (if_getflags(ifp) & IFF_UP) {
4556 if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) {
4557 /* set the receive mode flags */
4558 bxe_set_rx_mode(sc);
4559 } else if(sc->state != BXE_STATE_DISABLED) {
4560 bxe_init_locked(sc);
4563 if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) {
4564 bxe_periodic_stop(sc);
4565 bxe_stop_locked(sc);
4568 BXE_CORE_UNLOCK(sc);
4574 /* add/delete multicast addresses */
4575 BLOGD(sc, DBG_IOCTL, "Received SIOCADDMULTI/SIOCDELMULTI ioctl\n");
4577 /* check if the interface is up */
4578 if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) {
4579 /* set the receive mode flags */
4581 bxe_set_rx_mode(sc);
4582 BXE_CORE_UNLOCK(sc);
4588 /* find out which capabilities have changed */
4589 mask = (ifr->ifr_reqcap ^ if_getcapenable(ifp));
4591 BLOGD(sc, DBG_IOCTL, "Received SIOCSIFCAP ioctl (mask=0x%08x)\n",
4594 /* toggle the LRO capabilites enable flag */
4595 if (mask & IFCAP_LRO) {
4596 if_togglecapenable(ifp, IFCAP_LRO);
4597 BLOGD(sc, DBG_IOCTL, "Turning LRO %s\n",
4598 (if_getcapenable(ifp) & IFCAP_LRO) ? "ON" : "OFF");
4602 /* toggle the TXCSUM checksum capabilites enable flag */
4603 if (mask & IFCAP_TXCSUM) {
4604 if_togglecapenable(ifp, IFCAP_TXCSUM);
4605 BLOGD(sc, DBG_IOCTL, "Turning TXCSUM %s\n",
4606 (if_getcapenable(ifp) & IFCAP_TXCSUM) ? "ON" : "OFF");
4607 if (if_getcapenable(ifp) & IFCAP_TXCSUM) {
4608 if_sethwassistbits(ifp, (CSUM_IP |
4615 if_clearhwassist(ifp); /* XXX */
4619 /* toggle the RXCSUM checksum capabilities enable flag */
4620 if (mask & IFCAP_RXCSUM) {
4621 if_togglecapenable(ifp, IFCAP_RXCSUM);
4622 BLOGD(sc, DBG_IOCTL, "Turning RXCSUM %s\n",
4623 (if_getcapenable(ifp) & IFCAP_RXCSUM) ? "ON" : "OFF");
4624 if (if_getcapenable(ifp) & IFCAP_RXCSUM) {
4625 if_sethwassistbits(ifp, (CSUM_IP |
4632 if_clearhwassist(ifp); /* XXX */
4636 /* toggle TSO4 capabilities enabled flag */
4637 if (mask & IFCAP_TSO4) {
4638 if_togglecapenable(ifp, IFCAP_TSO4);
4639 BLOGD(sc, DBG_IOCTL, "Turning TSO4 %s\n",
4640 (if_getcapenable(ifp) & IFCAP_TSO4) ? "ON" : "OFF");
4643 /* toggle TSO6 capabilities enabled flag */
4644 if (mask & IFCAP_TSO6) {
4645 if_togglecapenable(ifp, IFCAP_TSO6);
4646 BLOGD(sc, DBG_IOCTL, "Turning TSO6 %s\n",
4647 (if_getcapenable(ifp) & IFCAP_TSO6) ? "ON" : "OFF");
4650 /* toggle VLAN_HWTSO capabilities enabled flag */
4651 if (mask & IFCAP_VLAN_HWTSO) {
4653 if_togglecapenable(ifp, IFCAP_VLAN_HWTSO);
4654 BLOGD(sc, DBG_IOCTL, "Turning VLAN_HWTSO %s\n",
4655 (if_getcapenable(ifp) & IFCAP_VLAN_HWTSO) ? "ON" : "OFF");
4658 /* toggle VLAN_HWCSUM capabilities enabled flag */
4659 if (mask & IFCAP_VLAN_HWCSUM) {
4660 /* XXX investigate this... */
4661 BLOGE(sc, "Changing VLAN_HWCSUM is not supported!\n");
4665 /* toggle VLAN_MTU capabilities enable flag */
4666 if (mask & IFCAP_VLAN_MTU) {
4667 /* XXX investigate this... */
4668 BLOGE(sc, "Changing VLAN_MTU is not supported!\n");
4672 /* toggle VLAN_HWTAGGING capabilities enabled flag */
4673 if (mask & IFCAP_VLAN_HWTAGGING) {
4674 /* XXX investigate this... */
4675 BLOGE(sc, "Changing VLAN_HWTAGGING is not supported!\n");
4679 /* toggle VLAN_HWFILTER capabilities enabled flag */
4680 if (mask & IFCAP_VLAN_HWFILTER) {
4681 /* XXX investigate this... */
4682 BLOGE(sc, "Changing VLAN_HWFILTER is not supported!\n");
4694 /* set/get interface media */
4695 BLOGD(sc, DBG_IOCTL,
4696 "Received SIOCSIFMEDIA/SIOCGIFMEDIA ioctl (cmd=%lu)\n",
4698 error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, command);
4702 BLOGD(sc, DBG_IOCTL, "Received Unknown Ioctl (cmd=%lu)\n",
4704 error = ether_ioctl(ifp, command, data);
4708 if (reinit && (if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING)) {
4709 BLOGD(sc, DBG_LOAD | DBG_IOCTL,
4710 "Re-initializing hardware from IOCTL change\n");
4711 bxe_periodic_stop(sc);
4713 bxe_stop_locked(sc);
4714 bxe_init_locked(sc);
4715 BXE_CORE_UNLOCK(sc);
4721 static __noinline void
4722 bxe_dump_mbuf(struct bxe_softc *sc,
4729 if (!(sc->debug & DBG_MBUF)) {
4734 BLOGD(sc, DBG_MBUF, "mbuf: null pointer\n");
4741 "%02d: mbuf=%p m_len=%d m_flags=0x%b m_data=%p\n",
4742 i, m, m->m_len, m->m_flags, M_FLAG_BITS, m->m_data);
4744 if (m->m_flags & M_PKTHDR) {
4746 "%02d: - m_pkthdr: tot_len=%d flags=0x%b csum_flags=%b\n",
4747 i, m->m_pkthdr.len, m->m_flags, M_FLAG_BITS,
4748 (int)m->m_pkthdr.csum_flags, CSUM_BITS);
4751 if (m->m_flags & M_EXT) {
4752 switch (m->m_ext.ext_type) {
4753 case EXT_CLUSTER: type = "EXT_CLUSTER"; break;
4754 case EXT_SFBUF: type = "EXT_SFBUF"; break;
4755 case EXT_JUMBOP: type = "EXT_JUMBOP"; break;
4756 case EXT_JUMBO9: type = "EXT_JUMBO9"; break;
4757 case EXT_JUMBO16: type = "EXT_JUMBO16"; break;
4758 case EXT_PACKET: type = "EXT_PACKET"; break;
4759 case EXT_MBUF: type = "EXT_MBUF"; break;
4760 case EXT_NET_DRV: type = "EXT_NET_DRV"; break;
4761 case EXT_MOD_TYPE: type = "EXT_MOD_TYPE"; break;
4762 case EXT_DISPOSABLE: type = "EXT_DISPOSABLE"; break;
4763 case EXT_EXTREF: type = "EXT_EXTREF"; break;
4764 default: type = "UNKNOWN"; break;
4768 "%02d: - m_ext: %p ext_size=%d type=%s\n",
4769 i, m->m_ext.ext_buf, m->m_ext.ext_size, type);
4773 bxe_dump_mbuf_data(sc, "mbuf data", m, TRUE);
4782 * Checks to ensure the 13 bd sliding window is >= MSS for TSO.
4783 * Check that (13 total bds - 3 bds) = 10 bd window >= MSS.
4784 * The window: 3 bds are = 1 for headers BD + 2 for parse BD and last BD
4785 * The headers comes in a separate bd in FreeBSD so 13-3=10.
4786 * Returns: 0 if OK to send, 1 if packet needs further defragmentation
4789 bxe_chktso_window(struct bxe_softc *sc,
4791 bus_dma_segment_t *segs,
4794 uint32_t num_wnds, wnd_size, wnd_sum;
4795 int32_t frag_idx, wnd_idx;
4796 unsigned short lso_mss;
4802 num_wnds = nsegs - wnd_size;
4803 lso_mss = htole16(m->m_pkthdr.tso_segsz);
4806 * Total header lengths Eth+IP+TCP in first FreeBSD mbuf so calculate the
4807 * first window sum of data while skipping the first assuming it is the
4808 * header in FreeBSD.
4810 for (frag_idx = 1; (frag_idx <= wnd_size); frag_idx++) {
4811 wnd_sum += htole16(segs[frag_idx].ds_len);
4814 /* check the first 10 bd window size */
4815 if (wnd_sum < lso_mss) {
4819 /* run through the windows */
4820 for (wnd_idx = 0; wnd_idx < num_wnds; wnd_idx++, frag_idx++) {
4821 /* subtract the first mbuf->m_len of the last wndw(-header) */
4822 wnd_sum -= htole16(segs[wnd_idx+1].ds_len);
4823 /* add the next mbuf len to the len of our new window */
4824 wnd_sum += htole16(segs[frag_idx].ds_len);
4825 if (wnd_sum < lso_mss) {
4834 bxe_set_pbd_csum_e2(struct bxe_fastpath *fp,
4836 uint32_t *parsing_data)
4838 struct ether_vlan_header *eh = NULL;
4839 struct ip *ip4 = NULL;
4840 struct ip6_hdr *ip6 = NULL;
4842 struct tcphdr *th = NULL;
4843 int e_hlen, ip_hlen, l4_off;
4846 if (m->m_pkthdr.csum_flags == CSUM_IP) {
4847 /* no L4 checksum offload needed */
4851 /* get the Ethernet header */
4852 eh = mtod(m, struct ether_vlan_header *);
4854 /* handle VLAN encapsulation if present */
4855 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
4856 e_hlen = (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN);
4857 proto = ntohs(eh->evl_proto);
4859 e_hlen = ETHER_HDR_LEN;
4860 proto = ntohs(eh->evl_encap_proto);
4865 /* get the IP header, if mbuf len < 20 then header in next mbuf */
4866 ip4 = (m->m_len < sizeof(struct ip)) ?
4867 (struct ip *)m->m_next->m_data :
4868 (struct ip *)(m->m_data + e_hlen);
4869 /* ip_hl is number of 32-bit words */
4870 ip_hlen = (ip4->ip_hl << 2);
4873 case ETHERTYPE_IPV6:
4874 /* get the IPv6 header, if mbuf len < 40 then header in next mbuf */
4875 ip6 = (m->m_len < sizeof(struct ip6_hdr)) ?
4876 (struct ip6_hdr *)m->m_next->m_data :
4877 (struct ip6_hdr *)(m->m_data + e_hlen);
4878 /* XXX cannot support offload with IPv6 extensions */
4879 ip_hlen = sizeof(struct ip6_hdr);
4883 /* We can't offload in this case... */
4884 /* XXX error stat ??? */
4888 /* XXX assuming L4 header is contiguous to IPv4/IPv6 in the same mbuf */
4889 l4_off = (e_hlen + ip_hlen);
4892 (((l4_off >> 1) << ETH_TX_PARSE_BD_E2_L4_HDR_START_OFFSET_W_SHIFT) &
4893 ETH_TX_PARSE_BD_E2_L4_HDR_START_OFFSET_W);
4895 if (m->m_pkthdr.csum_flags & (CSUM_TCP |
4898 fp->eth_q_stats.tx_ofld_frames_csum_tcp++;
4899 th = (struct tcphdr *)(ip + ip_hlen);
4900 /* th_off is number of 32-bit words */
4901 *parsing_data |= ((th->th_off <<
4902 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW_SHIFT) &
4903 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW);
4904 return (l4_off + (th->th_off << 2)); /* entire header length */
4905 } else if (m->m_pkthdr.csum_flags & (CSUM_UDP |
4907 fp->eth_q_stats.tx_ofld_frames_csum_udp++;
4908 return (l4_off + sizeof(struct udphdr)); /* entire header length */
4910 /* XXX error stat ??? */
4916 bxe_set_pbd_csum(struct bxe_fastpath *fp,
4918 struct eth_tx_parse_bd_e1x *pbd)
4920 struct ether_vlan_header *eh = NULL;
4921 struct ip *ip4 = NULL;
4922 struct ip6_hdr *ip6 = NULL;
4924 struct tcphdr *th = NULL;
4925 struct udphdr *uh = NULL;
4926 int e_hlen, ip_hlen;
4932 /* get the Ethernet header */
4933 eh = mtod(m, struct ether_vlan_header *);
4935 /* handle VLAN encapsulation if present */
4936 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
4937 e_hlen = (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN);
4938 proto = ntohs(eh->evl_proto);
4940 e_hlen = ETHER_HDR_LEN;
4941 proto = ntohs(eh->evl_encap_proto);
4946 /* get the IP header, if mbuf len < 20 then header in next mbuf */
4947 ip4 = (m->m_len < sizeof(struct ip)) ?
4948 (struct ip *)m->m_next->m_data :
4949 (struct ip *)(m->m_data + e_hlen);
4950 /* ip_hl is number of 32-bit words */
4951 ip_hlen = (ip4->ip_hl << 1);
4954 case ETHERTYPE_IPV6:
4955 /* get the IPv6 header, if mbuf len < 40 then header in next mbuf */
4956 ip6 = (m->m_len < sizeof(struct ip6_hdr)) ?
4957 (struct ip6_hdr *)m->m_next->m_data :
4958 (struct ip6_hdr *)(m->m_data + e_hlen);
4959 /* XXX cannot support offload with IPv6 extensions */
4960 ip_hlen = (sizeof(struct ip6_hdr) >> 1);
4964 /* We can't offload in this case... */
4965 /* XXX error stat ??? */
4969 hlen = (e_hlen >> 1);
4971 /* note that rest of global_data is indirectly zeroed here */
4972 if (m->m_flags & M_VLANTAG) {
4974 htole16(hlen | (1 << ETH_TX_PARSE_BD_E1X_LLC_SNAP_EN_SHIFT));
4976 pbd->global_data = htole16(hlen);
4979 pbd->ip_hlen_w = ip_hlen;
4981 hlen += pbd->ip_hlen_w;
4983 /* XXX assuming L4 header is contiguous to IPv4/IPv6 in the same mbuf */
4985 if (m->m_pkthdr.csum_flags & (CSUM_TCP |
4988 th = (struct tcphdr *)(ip + (ip_hlen << 1));
4989 /* th_off is number of 32-bit words */
4990 hlen += (uint16_t)(th->th_off << 1);
4991 } else if (m->m_pkthdr.csum_flags & (CSUM_UDP |
4993 uh = (struct udphdr *)(ip + (ip_hlen << 1));
4994 hlen += (sizeof(struct udphdr) / 2);
4996 /* valid case as only CSUM_IP was set */
5000 pbd->total_hlen_w = htole16(hlen);
5002 if (m->m_pkthdr.csum_flags & (CSUM_TCP |
5005 fp->eth_q_stats.tx_ofld_frames_csum_tcp++;
5006 pbd->tcp_pseudo_csum = ntohs(th->th_sum);
5007 } else if (m->m_pkthdr.csum_flags & (CSUM_UDP |
5009 fp->eth_q_stats.tx_ofld_frames_csum_udp++;
5012 * Everest1 (i.e. 57710, 57711, 57711E) does not natively support UDP
5013 * checksums and does not know anything about the UDP header and where
5014 * the checksum field is located. It only knows about TCP. Therefore
5015 * we "lie" to the hardware for outgoing UDP packets w/ checksum
5016 * offload. Since the checksum field offset for TCP is 16 bytes and
5017 * for UDP it is 6 bytes we pass a pointer to the hardware that is 10
5018 * bytes less than the start of the UDP header. This allows the
5019 * hardware to write the checksum in the correct spot. But the
5020 * hardware will compute a checksum which includes the last 10 bytes
5021 * of the IP header. To correct this we tweak the stack computed
5022 * pseudo checksum by folding in the calculation of the inverse
5023 * checksum for those final 10 bytes of the IP header. This allows
5024 * the correct checksum to be computed by the hardware.
5027 /* set pointer 10 bytes before UDP header */
5028 tmp_uh = (uint32_t *)((uint8_t *)uh - 10);
5030 /* calculate a pseudo header checksum over the first 10 bytes */
5031 tmp_csum = in_pseudo(*tmp_uh,
5033 *(uint16_t *)(tmp_uh + 2));
5035 pbd->tcp_pseudo_csum = ntohs(in_addword(uh->uh_sum, ~tmp_csum));
5038 return (hlen * 2); /* entire header length, number of bytes */
5042 bxe_set_pbd_lso_e2(struct mbuf *m,
5043 uint32_t *parsing_data)
5045 *parsing_data |= ((m->m_pkthdr.tso_segsz <<
5046 ETH_TX_PARSE_BD_E2_LSO_MSS_SHIFT) &
5047 ETH_TX_PARSE_BD_E2_LSO_MSS);
5049 /* XXX test for IPv6 with extension header... */
5053 bxe_set_pbd_lso(struct mbuf *m,
5054 struct eth_tx_parse_bd_e1x *pbd)
5056 struct ether_vlan_header *eh = NULL;
5057 struct ip *ip = NULL;
5058 struct tcphdr *th = NULL;
5061 /* get the Ethernet header */
5062 eh = mtod(m, struct ether_vlan_header *);
5064 /* handle VLAN encapsulation if present */
5065 e_hlen = (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) ?
5066 (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN) : ETHER_HDR_LEN;
5068 /* get the IP and TCP header, with LSO entire header in first mbuf */
5069 /* XXX assuming IPv4 */
5070 ip = (struct ip *)(m->m_data + e_hlen);
5071 th = (struct tcphdr *)((caddr_t)ip + (ip->ip_hl << 2));
5073 pbd->lso_mss = htole16(m->m_pkthdr.tso_segsz);
5074 pbd->tcp_send_seq = ntohl(th->th_seq);
5075 pbd->tcp_flags = ((ntohl(((uint32_t *)th)[3]) >> 16) & 0xff);
5079 pbd->ip_id = ntohs(ip->ip_id);
5080 pbd->tcp_pseudo_csum =
5081 ntohs(in_pseudo(ip->ip_src.s_addr,
5083 htons(IPPROTO_TCP)));
5086 pbd->tcp_pseudo_csum =
5087 ntohs(in_pseudo(&ip6->ip6_src,
5089 htons(IPPROTO_TCP)));
5093 htole16(ETH_TX_PARSE_BD_E1X_PSEUDO_CS_WITHOUT_LEN);
5097 * Encapsulte an mbuf cluster into the tx bd chain and makes the memory
5098 * visible to the controller.
5100 * If an mbuf is submitted to this routine and cannot be given to the
5101 * controller (e.g. it has too many fragments) then the function may free
5102 * the mbuf and return to the caller.
5105 * 0 = Success, !0 = Failure
5106 * Note the side effect that an mbuf may be freed if it causes a problem.
5109 bxe_tx_encap(struct bxe_fastpath *fp, struct mbuf **m_head)
5111 bus_dma_segment_t segs[32];
5113 struct bxe_sw_tx_bd *tx_buf;
5114 struct eth_tx_parse_bd_e1x *pbd_e1x = NULL;
5115 struct eth_tx_parse_bd_e2 *pbd_e2 = NULL;
5116 /* struct eth_tx_parse_2nd_bd *pbd2 = NULL; */
5117 struct eth_tx_bd *tx_data_bd;
5118 struct eth_tx_bd *tx_total_pkt_size_bd;
5119 struct eth_tx_start_bd *tx_start_bd;
5120 uint16_t bd_prod, pkt_prod, total_pkt_size;
5122 int defragged, error, nsegs, rc, nbds, vlan_off, ovlan;
5123 struct bxe_softc *sc;
5124 uint16_t tx_bd_avail;
5125 struct ether_vlan_header *eh;
5126 uint32_t pbd_e2_parsing_data = 0;
5133 M_ASSERTPKTHDR(*m_head);
5136 rc = defragged = nbds = ovlan = vlan_off = total_pkt_size = 0;
5139 tx_total_pkt_size_bd = NULL;
5141 /* get the H/W pointer for packets and BDs */
5142 pkt_prod = fp->tx_pkt_prod;
5143 bd_prod = fp->tx_bd_prod;
5145 mac_type = UNICAST_ADDRESS;
5147 /* map the mbuf into the next open DMAable memory */
5148 tx_buf = &fp->tx_mbuf_chain[TX_BD(pkt_prod)];
5149 error = bus_dmamap_load_mbuf_sg(fp->tx_mbuf_tag,
5151 segs, &nsegs, BUS_DMA_NOWAIT);
5153 /* mapping errors */
5154 if(__predict_false(error != 0)) {
5155 fp->eth_q_stats.tx_dma_mapping_failure++;
5156 if (error == ENOMEM) {
5157 /* resource issue, try again later */
5159 } else if (error == EFBIG) {
5160 /* possibly recoverable with defragmentation */
5161 fp->eth_q_stats.mbuf_defrag_attempts++;
5162 m0 = m_defrag(*m_head, M_NOWAIT);
5164 fp->eth_q_stats.mbuf_defrag_failures++;
5167 /* defrag successful, try mapping again */
5169 error = bus_dmamap_load_mbuf_sg(fp->tx_mbuf_tag,
5171 segs, &nsegs, BUS_DMA_NOWAIT);
5173 fp->eth_q_stats.tx_dma_mapping_failure++;
5178 /* unknown, unrecoverable mapping error */
5179 BLOGE(sc, "Unknown TX mapping error rc=%d\n", error);
5180 bxe_dump_mbuf(sc, m0, FALSE);
5184 goto bxe_tx_encap_continue;
5187 tx_bd_avail = bxe_tx_avail(sc, fp);
5189 /* make sure there is enough room in the send queue */
5190 if (__predict_false(tx_bd_avail < (nsegs + 2))) {
5191 /* Recoverable, try again later. */
5192 fp->eth_q_stats.tx_hw_queue_full++;
5193 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
5195 goto bxe_tx_encap_continue;
5198 /* capture the current H/W TX chain high watermark */
5199 if (__predict_false(fp->eth_q_stats.tx_hw_max_queue_depth <
5200 (TX_BD_USABLE - tx_bd_avail))) {
5201 fp->eth_q_stats.tx_hw_max_queue_depth = (TX_BD_USABLE - tx_bd_avail);
5204 /* make sure it fits in the packet window */
5205 if (__predict_false(nsegs > BXE_MAX_SEGMENTS)) {
5207 * The mbuf may be to big for the controller to handle. If the frame
5208 * is a TSO frame we'll need to do an additional check.
5210 if (m0->m_pkthdr.csum_flags & CSUM_TSO) {
5211 if (bxe_chktso_window(sc, nsegs, segs, m0) == 0) {
5212 goto bxe_tx_encap_continue; /* OK to send */
5214 fp->eth_q_stats.tx_window_violation_tso++;
5217 fp->eth_q_stats.tx_window_violation_std++;
5220 /* lets try to defragment this mbuf and remap it */
5221 fp->eth_q_stats.mbuf_defrag_attempts++;
5222 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
5224 m0 = m_defrag(*m_head, M_NOWAIT);
5226 fp->eth_q_stats.mbuf_defrag_failures++;
5227 /* Ugh, just drop the frame... :( */
5230 /* defrag successful, try mapping again */
5232 error = bus_dmamap_load_mbuf_sg(fp->tx_mbuf_tag,
5234 segs, &nsegs, BUS_DMA_NOWAIT);
5236 fp->eth_q_stats.tx_dma_mapping_failure++;
5237 /* No sense in trying to defrag/copy chain, drop it. :( */
5240 /* if the chain is still too long then drop it */
5241 if(m0->m_pkthdr.csum_flags & CSUM_TSO) {
5243 * in case TSO is enabled nsegs should be checked against
5244 * BXE_TSO_MAX_SEGMENTS
5246 if (__predict_false(nsegs > BXE_TSO_MAX_SEGMENTS)) {
5247 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
5248 fp->eth_q_stats.nsegs_path1_errors++;
5252 if (__predict_false(nsegs > BXE_MAX_SEGMENTS)) {
5253 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map);
5254 fp->eth_q_stats.nsegs_path2_errors++;
5262 bxe_tx_encap_continue:
5264 /* Check for errors */
5267 /* recoverable try again later */
5269 fp->eth_q_stats.tx_soft_errors++;
5270 fp->eth_q_stats.mbuf_alloc_tx--;
5278 /* set flag according to packet type (UNICAST_ADDRESS is default) */
5279 if (m0->m_flags & M_BCAST) {
5280 mac_type = BROADCAST_ADDRESS;
5281 } else if (m0->m_flags & M_MCAST) {
5282 mac_type = MULTICAST_ADDRESS;
5285 /* store the mbuf into the mbuf ring */
5287 tx_buf->first_bd = fp->tx_bd_prod;
5290 /* prepare the first transmit (start) BD for the mbuf */
5291 tx_start_bd = &fp->tx_chain[TX_BD(bd_prod)].start_bd;
5294 "sending pkt_prod=%u tx_buf=%p next_idx=%u bd=%u tx_start_bd=%p\n",
5295 pkt_prod, tx_buf, fp->tx_pkt_prod, bd_prod, tx_start_bd);
5297 tx_start_bd->addr_lo = htole32(U64_LO(segs[0].ds_addr));
5298 tx_start_bd->addr_hi = htole32(U64_HI(segs[0].ds_addr));
5299 tx_start_bd->nbytes = htole16(segs[0].ds_len);
5300 total_pkt_size += tx_start_bd->nbytes;
5301 tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
5303 tx_start_bd->general_data = (1 << ETH_TX_START_BD_HDR_NBDS_SHIFT);
5305 /* all frames have at least Start BD + Parsing BD */
5307 tx_start_bd->nbd = htole16(nbds);
5309 if (m0->m_flags & M_VLANTAG) {
5310 tx_start_bd->vlan_or_ethertype = htole16(m0->m_pkthdr.ether_vtag);
5311 tx_start_bd->bd_flags.as_bitfield |=
5312 (X_ETH_OUTBAND_VLAN << ETH_TX_BD_FLAGS_VLAN_MODE_SHIFT);
5314 /* vf tx, start bd must hold the ethertype for fw to enforce it */
5316 /* map ethernet header to find type and header length */
5317 eh = mtod(m0, struct ether_vlan_header *);
5318 tx_start_bd->vlan_or_ethertype = eh->evl_encap_proto;
5320 /* used by FW for packet accounting */
5321 tx_start_bd->vlan_or_ethertype = htole16(fp->tx_pkt_prod);
5326 * add a parsing BD from the chain. The parsing BD is always added
5327 * though it is only used for TSO and chksum
5329 bd_prod = TX_BD_NEXT(bd_prod);
5331 if (m0->m_pkthdr.csum_flags) {
5332 if (m0->m_pkthdr.csum_flags & CSUM_IP) {
5333 fp->eth_q_stats.tx_ofld_frames_csum_ip++;
5334 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_IP_CSUM;
5337 if (m0->m_pkthdr.csum_flags & CSUM_TCP_IPV6) {
5338 tx_start_bd->bd_flags.as_bitfield |= (ETH_TX_BD_FLAGS_IPV6 |
5339 ETH_TX_BD_FLAGS_L4_CSUM);
5340 } else if (m0->m_pkthdr.csum_flags & CSUM_UDP_IPV6) {
5341 tx_start_bd->bd_flags.as_bitfield |= (ETH_TX_BD_FLAGS_IPV6 |
5342 ETH_TX_BD_FLAGS_IS_UDP |
5343 ETH_TX_BD_FLAGS_L4_CSUM);
5344 } else if ((m0->m_pkthdr.csum_flags & CSUM_TCP) ||
5345 (m0->m_pkthdr.csum_flags & CSUM_TSO)) {
5346 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_L4_CSUM;
5347 } else if (m0->m_pkthdr.csum_flags & CSUM_UDP) {
5348 tx_start_bd->bd_flags.as_bitfield |= (ETH_TX_BD_FLAGS_L4_CSUM |
5349 ETH_TX_BD_FLAGS_IS_UDP);
5353 if (!CHIP_IS_E1x(sc)) {
5354 pbd_e2 = &fp->tx_chain[TX_BD(bd_prod)].parse_bd_e2;
5355 memset(pbd_e2, 0, sizeof(struct eth_tx_parse_bd_e2));
5357 if (m0->m_pkthdr.csum_flags) {
5358 hlen = bxe_set_pbd_csum_e2(fp, m0, &pbd_e2_parsing_data);
5361 SET_FLAG(pbd_e2_parsing_data, ETH_TX_PARSE_BD_E2_ETH_ADDR_TYPE,
5364 uint16_t global_data = 0;
5366 pbd_e1x = &fp->tx_chain[TX_BD(bd_prod)].parse_bd_e1x;
5367 memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x));
5369 if (m0->m_pkthdr.csum_flags) {
5370 hlen = bxe_set_pbd_csum(fp, m0, pbd_e1x);
5373 SET_FLAG(global_data,
5374 ETH_TX_PARSE_BD_E1X_ETH_ADDR_TYPE, mac_type);
5375 pbd_e1x->global_data |= htole16(global_data);
5378 /* setup the parsing BD with TSO specific info */
5379 if (m0->m_pkthdr.csum_flags & CSUM_TSO) {
5380 fp->eth_q_stats.tx_ofld_frames_lso++;
5381 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_SW_LSO;
5383 if (__predict_false(tx_start_bd->nbytes > hlen)) {
5384 fp->eth_q_stats.tx_ofld_frames_lso_hdr_splits++;
5386 /* split the first BD into header/data making the fw job easy */
5388 tx_start_bd->nbd = htole16(nbds);
5389 tx_start_bd->nbytes = htole16(hlen);
5391 bd_prod = TX_BD_NEXT(bd_prod);
5393 /* new transmit BD after the tx_parse_bd */
5394 tx_data_bd = &fp->tx_chain[TX_BD(bd_prod)].reg_bd;
5395 tx_data_bd->addr_hi = htole32(U64_HI(segs[0].ds_addr + hlen));
5396 tx_data_bd->addr_lo = htole32(U64_LO(segs[0].ds_addr + hlen));
5397 tx_data_bd->nbytes = htole16(segs[0].ds_len - hlen);
5398 if (tx_total_pkt_size_bd == NULL) {
5399 tx_total_pkt_size_bd = tx_data_bd;
5403 "TSO split header size is %d (%x:%x) nbds %d\n",
5404 le16toh(tx_start_bd->nbytes),
5405 le32toh(tx_start_bd->addr_hi),
5406 le32toh(tx_start_bd->addr_lo),
5410 if (!CHIP_IS_E1x(sc)) {
5411 bxe_set_pbd_lso_e2(m0, &pbd_e2_parsing_data);
5413 bxe_set_pbd_lso(m0, pbd_e1x);
5417 if (pbd_e2_parsing_data) {
5418 pbd_e2->parsing_data = htole32(pbd_e2_parsing_data);
5421 /* prepare remaining BDs, start tx bd contains first seg/frag */
5422 for (i = 1; i < nsegs ; i++) {
5423 bd_prod = TX_BD_NEXT(bd_prod);
5424 tx_data_bd = &fp->tx_chain[TX_BD(bd_prod)].reg_bd;
5425 tx_data_bd->addr_lo = htole32(U64_LO(segs[i].ds_addr));
5426 tx_data_bd->addr_hi = htole32(U64_HI(segs[i].ds_addr));
5427 tx_data_bd->nbytes = htole16(segs[i].ds_len);
5428 if (tx_total_pkt_size_bd == NULL) {
5429 tx_total_pkt_size_bd = tx_data_bd;
5431 total_pkt_size += tx_data_bd->nbytes;
5434 BLOGD(sc, DBG_TX, "last bd %p\n", tx_data_bd);
5436 if (tx_total_pkt_size_bd != NULL) {
5437 tx_total_pkt_size_bd->total_pkt_bytes = total_pkt_size;
5440 if (__predict_false(sc->debug & DBG_TX)) {
5441 tmp_bd = tx_buf->first_bd;
5442 for (i = 0; i < nbds; i++)
5446 "TX Strt: %p bd=%d nbd=%d vlan=0x%x "
5447 "bd_flags=0x%x hdr_nbds=%d\n",
5450 le16toh(tx_start_bd->nbd),
5451 le16toh(tx_start_bd->vlan_or_ethertype),
5452 tx_start_bd->bd_flags.as_bitfield,
5453 (tx_start_bd->general_data & ETH_TX_START_BD_HDR_NBDS));
5454 } else if (i == 1) {
5457 "-> Prse: %p bd=%d global=0x%x ip_hlen_w=%u "
5458 "ip_id=%u lso_mss=%u tcp_flags=0x%x csum=0x%x "
5459 "tcp_seq=%u total_hlen_w=%u\n",
5462 pbd_e1x->global_data,
5467 pbd_e1x->tcp_pseudo_csum,
5468 pbd_e1x->tcp_send_seq,
5469 le16toh(pbd_e1x->total_hlen_w));
5470 } else { /* if (pbd_e2) */
5472 "-> Parse: %p bd=%d dst=%02x:%02x:%02x "
5473 "src=%02x:%02x:%02x parsing_data=0x%x\n",
5476 pbd_e2->data.mac_addr.dst_hi,
5477 pbd_e2->data.mac_addr.dst_mid,
5478 pbd_e2->data.mac_addr.dst_lo,
5479 pbd_e2->data.mac_addr.src_hi,
5480 pbd_e2->data.mac_addr.src_mid,
5481 pbd_e2->data.mac_addr.src_lo,
5482 pbd_e2->parsing_data);
5486 if (i != 1) { /* skip parse db as it doesn't hold data */
5487 tx_data_bd = &fp->tx_chain[TX_BD(tmp_bd)].reg_bd;
5489 "-> Frag: %p bd=%d nbytes=%d hi=0x%x lo: 0x%x\n",
5492 le16toh(tx_data_bd->nbytes),
5493 le32toh(tx_data_bd->addr_hi),
5494 le32toh(tx_data_bd->addr_lo));
5497 tmp_bd = TX_BD_NEXT(tmp_bd);
5501 BLOGD(sc, DBG_TX, "doorbell: nbds=%d bd=%u\n", nbds, bd_prod);
5503 /* update TX BD producer index value for next TX */
5504 bd_prod = TX_BD_NEXT(bd_prod);
5507 * If the chain of tx_bd's describing this frame is adjacent to or spans
5508 * an eth_tx_next_bd element then we need to increment the nbds value.
5510 if (TX_BD_IDX(bd_prod) < nbds) {
5514 /* don't allow reordering of writes for nbd and packets */
5517 fp->tx_db.data.prod += nbds;
5519 /* producer points to the next free tx_bd at this point */
5521 fp->tx_bd_prod = bd_prod;
5523 DOORBELL(sc, fp->index, fp->tx_db.raw);
5525 fp->eth_q_stats.tx_pkts++;
5527 /* Prevent speculative reads from getting ahead of the status block. */
5528 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle,
5529 0, 0, BUS_SPACE_BARRIER_READ);
5531 /* Prevent speculative reads from getting ahead of the doorbell. */
5532 bus_space_barrier(sc->bar[BAR2].tag, sc->bar[BAR2].handle,
5533 0, 0, BUS_SPACE_BARRIER_READ);
5539 bxe_tx_start_locked(struct bxe_softc *sc,
5541 struct bxe_fastpath *fp)
5543 struct mbuf *m = NULL;
5545 uint16_t tx_bd_avail;
5547 BXE_FP_TX_LOCK_ASSERT(fp);
5549 /* keep adding entries while there are frames to send */
5550 while (!if_sendq_empty(ifp)) {
5553 * check for any frames to send
5554 * dequeue can still be NULL even if queue is not empty
5556 m = if_dequeue(ifp);
5557 if (__predict_false(m == NULL)) {
5561 /* the mbuf now belongs to us */
5562 fp->eth_q_stats.mbuf_alloc_tx++;
5565 * Put the frame into the transmit ring. If we don't have room,
5566 * place the mbuf back at the head of the TX queue, set the
5567 * OACTIVE flag, and wait for the NIC to drain the chain.
5569 if (__predict_false(bxe_tx_encap(fp, &m))) {
5570 fp->eth_q_stats.tx_encap_failures++;
5572 /* mark the TX queue as full and return the frame */
5573 if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0);
5574 if_sendq_prepend(ifp, m);
5575 fp->eth_q_stats.mbuf_alloc_tx--;
5576 fp->eth_q_stats.tx_queue_xoff++;
5579 /* stop looking for more work */
5583 /* the frame was enqueued successfully */
5586 /* send a copy of the frame to any BPF listeners. */
5587 if_etherbpfmtap(ifp, m);
5589 tx_bd_avail = bxe_tx_avail(sc, fp);
5591 /* handle any completions if we're running low */
5592 if (tx_bd_avail < BXE_TX_CLEANUP_THRESHOLD) {
5593 /* bxe_txeof will set IFF_DRV_OACTIVE appropriately */
5595 if (if_getdrvflags(ifp) & IFF_DRV_OACTIVE) {
5601 /* all TX packets were dequeued and/or the tx ring is full */
5603 /* reset the TX watchdog timeout timer */
5604 fp->watchdog_timer = BXE_TX_TIMEOUT;
5608 /* Legacy (non-RSS) dispatch routine */
5610 bxe_tx_start(if_t ifp)
5612 struct bxe_softc *sc;
5613 struct bxe_fastpath *fp;
5615 sc = if_getsoftc(ifp);
5617 if (!(if_getdrvflags(ifp) & IFF_DRV_RUNNING)) {
5618 BLOGW(sc, "Interface not running, ignoring transmit request\n");
5622 if (!sc->link_vars.link_up) {
5623 BLOGW(sc, "Interface link is down, ignoring transmit request\n");
5629 if (if_getdrvflags(ifp) & IFF_DRV_OACTIVE) {
5630 fp->eth_q_stats.tx_queue_full_return++;
5635 bxe_tx_start_locked(sc, ifp, fp);
5636 BXE_FP_TX_UNLOCK(fp);
5640 bxe_tx_mq_start_locked(struct bxe_softc *sc,
5642 struct bxe_fastpath *fp,
5645 struct buf_ring *tx_br = fp->tx_br;
5647 int depth, rc, tx_count;
5648 uint16_t tx_bd_avail;
5652 BXE_FP_TX_LOCK_ASSERT(fp);
5654 if (sc->state != BXE_STATE_OPEN) {
5655 fp->eth_q_stats.bxe_tx_mq_sc_state_failures++;
5660 BLOGE(sc, "Multiqueue TX and no buf_ring!\n");
5665 rc = drbr_enqueue(ifp, tx_br, m);
5667 fp->eth_q_stats.tx_soft_errors++;
5668 goto bxe_tx_mq_start_locked_exit;
5672 if (!sc->link_vars.link_up || !(if_getdrvflags(ifp) & IFF_DRV_RUNNING)) {
5673 fp->eth_q_stats.tx_request_link_down_failures++;
5674 goto bxe_tx_mq_start_locked_exit;
5677 /* fetch the depth of the driver queue */
5678 depth = drbr_inuse_drv(ifp, tx_br);
5679 if (depth > fp->eth_q_stats.tx_max_drbr_queue_depth) {
5680 fp->eth_q_stats.tx_max_drbr_queue_depth = depth;
5683 /* keep adding entries while there are frames to send */
5684 while ((next = drbr_peek(ifp, tx_br)) != NULL) {
5685 /* handle any completions if we're running low */
5686 tx_bd_avail = bxe_tx_avail(sc, fp);
5687 if (tx_bd_avail < BXE_TX_CLEANUP_THRESHOLD) {
5688 /* bxe_txeof will set IFF_DRV_OACTIVE appropriately */
5690 tx_bd_avail = bxe_tx_avail(sc, fp);
5691 if (tx_bd_avail < (BXE_TSO_MAX_SEGMENTS + 1)) {
5692 fp->eth_q_stats.bd_avail_too_less_failures++;
5694 drbr_advance(ifp, tx_br);
5700 /* the mbuf now belongs to us */
5701 fp->eth_q_stats.mbuf_alloc_tx++;
5704 * Put the frame into the transmit ring. If we don't have room,
5705 * place the mbuf back at the head of the TX queue, set the
5706 * OACTIVE flag, and wait for the NIC to drain the chain.
5708 rc = bxe_tx_encap(fp, &next);
5709 if (__predict_false(rc != 0)) {
5710 fp->eth_q_stats.tx_encap_failures++;
5712 /* mark the TX queue as full and save the frame */
5713 if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0);
5714 drbr_putback(ifp, tx_br, next);
5715 fp->eth_q_stats.mbuf_alloc_tx--;
5716 fp->eth_q_stats.tx_frames_deferred++;
5718 drbr_advance(ifp, tx_br);
5720 /* stop looking for more work */
5724 /* the transmit frame was enqueued successfully */
5727 /* send a copy of the frame to any BPF listeners */
5728 if_etherbpfmtap(ifp, next);
5730 drbr_advance(ifp, tx_br);
5733 /* all TX packets were dequeued and/or the tx ring is full */
5735 /* reset the TX watchdog timeout timer */
5736 fp->watchdog_timer = BXE_TX_TIMEOUT;
5739 bxe_tx_mq_start_locked_exit:
5740 /* If we didn't drain the drbr, enqueue a task in the future to do it. */
5741 if (!drbr_empty(ifp, tx_br)) {
5742 fp->eth_q_stats.tx_mq_not_empty++;
5743 taskqueue_enqueue_timeout(fp->tq, &fp->tx_timeout_task, 1);
5750 bxe_tx_mq_start_deferred(void *arg,
5753 struct bxe_fastpath *fp = (struct bxe_fastpath *)arg;
5754 struct bxe_softc *sc = fp->sc;
5758 bxe_tx_mq_start_locked(sc, ifp, fp, NULL);
5759 BXE_FP_TX_UNLOCK(fp);
5762 /* Multiqueue (TSS) dispatch routine. */
5764 bxe_tx_mq_start(struct ifnet *ifp,
5767 struct bxe_softc *sc = if_getsoftc(ifp);
5768 struct bxe_fastpath *fp;
5771 fp_index = 0; /* default is the first queue */
5773 /* check if flowid is set */
5775 if (BXE_VALID_FLOWID(m))
5776 fp_index = (m->m_pkthdr.flowid % sc->num_queues);
5778 fp = &sc->fp[fp_index];
5780 if (sc->state != BXE_STATE_OPEN) {
5781 fp->eth_q_stats.bxe_tx_mq_sc_state_failures++;
5785 if (BXE_FP_TX_TRYLOCK(fp)) {
5786 rc = bxe_tx_mq_start_locked(sc, ifp, fp, m);
5787 BXE_FP_TX_UNLOCK(fp);
5789 rc = drbr_enqueue(ifp, fp->tx_br, m);
5790 taskqueue_enqueue(fp->tq, &fp->tx_task);
5797 bxe_mq_flush(struct ifnet *ifp)
5799 struct bxe_softc *sc = if_getsoftc(ifp);
5800 struct bxe_fastpath *fp;
5804 for (i = 0; i < sc->num_queues; i++) {
5807 if (fp->state != BXE_FP_STATE_IRQ) {
5808 BLOGD(sc, DBG_LOAD, "Not clearing fp[%02d] buf_ring (state=%d)\n",
5809 fp->index, fp->state);
5813 if (fp->tx_br != NULL) {
5814 BLOGD(sc, DBG_LOAD, "Clearing fp[%02d] buf_ring\n", fp->index);
5816 while ((m = buf_ring_dequeue_sc(fp->tx_br)) != NULL) {
5819 BXE_FP_TX_UNLOCK(fp);
5827 bxe_cid_ilt_lines(struct bxe_softc *sc)
5830 return ((BXE_FIRST_VF_CID + BXE_VF_CIDS) / ILT_PAGE_CIDS);
5832 return (L2_ILT_LINES(sc));
5836 bxe_ilt_set_info(struct bxe_softc *sc)
5838 struct ilt_client_info *ilt_client;
5839 struct ecore_ilt *ilt = sc->ilt;
5842 ilt->start_line = FUNC_ILT_BASE(SC_FUNC(sc));
5843 BLOGD(sc, DBG_LOAD, "ilt starts at line %d\n", ilt->start_line);
5846 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
5847 ilt_client->client_num = ILT_CLIENT_CDU;
5848 ilt_client->page_size = CDU_ILT_PAGE_SZ;
5849 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
5850 ilt_client->start = line;
5851 line += bxe_cid_ilt_lines(sc);
5853 if (CNIC_SUPPORT(sc)) {
5854 line += CNIC_ILT_LINES;
5857 ilt_client->end = (line - 1);
5860 "ilt client[CDU]: start %d, end %d, "
5861 "psz 0x%x, flags 0x%x, hw psz %d\n",
5862 ilt_client->start, ilt_client->end,
5863 ilt_client->page_size,
5865 ilog2(ilt_client->page_size >> 12));
5868 if (QM_INIT(sc->qm_cid_count)) {
5869 ilt_client = &ilt->clients[ILT_CLIENT_QM];
5870 ilt_client->client_num = ILT_CLIENT_QM;
5871 ilt_client->page_size = QM_ILT_PAGE_SZ;
5872 ilt_client->flags = 0;
5873 ilt_client->start = line;
5875 /* 4 bytes for each cid */
5876 line += DIV_ROUND_UP(sc->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
5879 ilt_client->end = (line - 1);
5882 "ilt client[QM]: start %d, end %d, "
5883 "psz 0x%x, flags 0x%x, hw psz %d\n",
5884 ilt_client->start, ilt_client->end,
5885 ilt_client->page_size, ilt_client->flags,
5886 ilog2(ilt_client->page_size >> 12));
5889 if (CNIC_SUPPORT(sc)) {
5891 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
5892 ilt_client->client_num = ILT_CLIENT_SRC;
5893 ilt_client->page_size = SRC_ILT_PAGE_SZ;
5894 ilt_client->flags = 0;
5895 ilt_client->start = line;
5896 line += SRC_ILT_LINES;
5897 ilt_client->end = (line - 1);
5900 "ilt client[SRC]: start %d, end %d, "
5901 "psz 0x%x, flags 0x%x, hw psz %d\n",
5902 ilt_client->start, ilt_client->end,
5903 ilt_client->page_size, ilt_client->flags,
5904 ilog2(ilt_client->page_size >> 12));
5907 ilt_client = &ilt->clients[ILT_CLIENT_TM];
5908 ilt_client->client_num = ILT_CLIENT_TM;
5909 ilt_client->page_size = TM_ILT_PAGE_SZ;
5910 ilt_client->flags = 0;
5911 ilt_client->start = line;
5912 line += TM_ILT_LINES;
5913 ilt_client->end = (line - 1);
5916 "ilt client[TM]: start %d, end %d, "
5917 "psz 0x%x, flags 0x%x, hw psz %d\n",
5918 ilt_client->start, ilt_client->end,
5919 ilt_client->page_size, ilt_client->flags,
5920 ilog2(ilt_client->page_size >> 12));
5923 KASSERT((line <= ILT_MAX_LINES), ("Invalid number of ILT lines!"));
5927 bxe_set_fp_rx_buf_size(struct bxe_softc *sc)
5930 uint32_t rx_buf_size;
5932 rx_buf_size = (IP_HEADER_ALIGNMENT_PADDING + ETH_OVERHEAD + sc->mtu);
5934 for (i = 0; i < sc->num_queues; i++) {
5935 if(rx_buf_size <= MCLBYTES){
5936 sc->fp[i].rx_buf_size = rx_buf_size;
5937 sc->fp[i].mbuf_alloc_size = MCLBYTES;
5938 }else if (rx_buf_size <= MJUMPAGESIZE){
5939 sc->fp[i].rx_buf_size = rx_buf_size;
5940 sc->fp[i].mbuf_alloc_size = MJUMPAGESIZE;
5941 }else if (rx_buf_size <= (MJUMPAGESIZE + MCLBYTES)){
5942 sc->fp[i].rx_buf_size = MCLBYTES;
5943 sc->fp[i].mbuf_alloc_size = MCLBYTES;
5944 }else if (rx_buf_size <= (2 * MJUMPAGESIZE)){
5945 sc->fp[i].rx_buf_size = MJUMPAGESIZE;
5946 sc->fp[i].mbuf_alloc_size = MJUMPAGESIZE;
5948 sc->fp[i].rx_buf_size = MCLBYTES;
5949 sc->fp[i].mbuf_alloc_size = MCLBYTES;
5955 bxe_alloc_ilt_mem(struct bxe_softc *sc)
5960 (struct ecore_ilt *)malloc(sizeof(struct ecore_ilt),
5962 (M_NOWAIT | M_ZERO))) == NULL) {
5970 bxe_alloc_ilt_lines_mem(struct bxe_softc *sc)
5974 if ((sc->ilt->lines =
5975 (struct ilt_line *)malloc((sizeof(struct ilt_line) * ILT_MAX_LINES),
5977 (M_NOWAIT | M_ZERO))) == NULL) {
5985 bxe_free_ilt_mem(struct bxe_softc *sc)
5987 if (sc->ilt != NULL) {
5988 free(sc->ilt, M_BXE_ILT);
5994 bxe_free_ilt_lines_mem(struct bxe_softc *sc)
5996 if (sc->ilt->lines != NULL) {
5997 free(sc->ilt->lines, M_BXE_ILT);
5998 sc->ilt->lines = NULL;
6003 bxe_free_mem(struct bxe_softc *sc)
6007 for (i = 0; i < L2_ILT_LINES(sc); i++) {
6008 bxe_dma_free(sc, &sc->context[i].vcxt_dma);
6009 sc->context[i].vcxt = NULL;
6010 sc->context[i].size = 0;
6013 ecore_ilt_mem_op(sc, ILT_MEMOP_FREE);
6015 bxe_free_ilt_lines_mem(sc);
6020 bxe_alloc_mem(struct bxe_softc *sc)
6028 * Allocate memory for CDU context:
6029 * This memory is allocated separately and not in the generic ILT
6030 * functions because CDU differs in few aspects:
6031 * 1. There can be multiple entities allocating memory for context -
6032 * regular L2, CNIC, and SRIOV drivers. Each separately controls
6033 * its own ILT lines.
6034 * 2. Since CDU page-size is not a single 4KB page (which is the case
6035 * for the other ILT clients), to be efficient we want to support
6036 * allocation of sub-page-size in the last entry.
6037 * 3. Context pointers are used by the driver to pass to FW / update
6038 * the context (for the other ILT clients the pointers are used just to
6039 * free the memory during unload).
6041 context_size = (sizeof(union cdu_context) * BXE_L2_CID_COUNT(sc));
6042 for (i = 0, allocated = 0; allocated < context_size; i++) {
6043 sc->context[i].size = min(CDU_ILT_PAGE_SZ,
6044 (context_size - allocated));
6046 if (bxe_dma_alloc(sc, sc->context[i].size,
6047 &sc->context[i].vcxt_dma,
6048 "cdu context") != 0) {
6053 sc->context[i].vcxt =
6054 (union cdu_context *)sc->context[i].vcxt_dma.vaddr;
6056 allocated += sc->context[i].size;
6059 bxe_alloc_ilt_lines_mem(sc);
6061 BLOGD(sc, DBG_LOAD, "ilt=%p start_line=%u lines=%p\n",
6062 sc->ilt, sc->ilt->start_line, sc->ilt->lines);
6064 for (i = 0; i < 4; i++) {
6066 "c%d page_size=%u start=%u end=%u num=%u flags=0x%x\n",
6068 sc->ilt->clients[i].page_size,
6069 sc->ilt->clients[i].start,
6070 sc->ilt->clients[i].end,
6071 sc->ilt->clients[i].client_num,
6072 sc->ilt->clients[i].flags);
6075 if (ecore_ilt_mem_op(sc, ILT_MEMOP_ALLOC)) {
6076 BLOGE(sc, "ecore_ilt_mem_op ILT_MEMOP_ALLOC failed\n");
6085 bxe_free_rx_bd_chain(struct bxe_fastpath *fp)
6087 struct bxe_softc *sc;
6092 if (fp->rx_mbuf_tag == NULL) {
6096 /* free all mbufs and unload all maps */
6097 for (i = 0; i < RX_BD_TOTAL; i++) {
6098 if (fp->rx_mbuf_chain[i].m_map != NULL) {
6099 bus_dmamap_sync(fp->rx_mbuf_tag,
6100 fp->rx_mbuf_chain[i].m_map,
6101 BUS_DMASYNC_POSTREAD);
6102 bus_dmamap_unload(fp->rx_mbuf_tag,
6103 fp->rx_mbuf_chain[i].m_map);
6106 if (fp->rx_mbuf_chain[i].m != NULL) {
6107 m_freem(fp->rx_mbuf_chain[i].m);
6108 fp->rx_mbuf_chain[i].m = NULL;
6109 fp->eth_q_stats.mbuf_alloc_rx--;
6115 bxe_free_tpa_pool(struct bxe_fastpath *fp)
6117 struct bxe_softc *sc;
6118 int i, max_agg_queues;
6122 if (fp->rx_mbuf_tag == NULL) {
6126 max_agg_queues = MAX_AGG_QS(sc);
6128 /* release all mbufs and unload all DMA maps in the TPA pool */
6129 for (i = 0; i < max_agg_queues; i++) {
6130 if (fp->rx_tpa_info[i].bd.m_map != NULL) {
6131 bus_dmamap_sync(fp->rx_mbuf_tag,
6132 fp->rx_tpa_info[i].bd.m_map,
6133 BUS_DMASYNC_POSTREAD);
6134 bus_dmamap_unload(fp->rx_mbuf_tag,
6135 fp->rx_tpa_info[i].bd.m_map);
6138 if (fp->rx_tpa_info[i].bd.m != NULL) {
6139 m_freem(fp->rx_tpa_info[i].bd.m);
6140 fp->rx_tpa_info[i].bd.m = NULL;
6141 fp->eth_q_stats.mbuf_alloc_tpa--;
6147 bxe_free_sge_chain(struct bxe_fastpath *fp)
6149 struct bxe_softc *sc;
6154 if (fp->rx_sge_mbuf_tag == NULL) {
6158 /* rree all mbufs and unload all maps */
6159 for (i = 0; i < RX_SGE_TOTAL; i++) {
6160 if (fp->rx_sge_mbuf_chain[i].m_map != NULL) {
6161 bus_dmamap_sync(fp->rx_sge_mbuf_tag,
6162 fp->rx_sge_mbuf_chain[i].m_map,
6163 BUS_DMASYNC_POSTREAD);
6164 bus_dmamap_unload(fp->rx_sge_mbuf_tag,
6165 fp->rx_sge_mbuf_chain[i].m_map);
6168 if (fp->rx_sge_mbuf_chain[i].m != NULL) {
6169 m_freem(fp->rx_sge_mbuf_chain[i].m);
6170 fp->rx_sge_mbuf_chain[i].m = NULL;
6171 fp->eth_q_stats.mbuf_alloc_sge--;
6177 bxe_free_fp_buffers(struct bxe_softc *sc)
6179 struct bxe_fastpath *fp;
6182 for (i = 0; i < sc->num_queues; i++) {
6185 if (fp->tx_br != NULL) {
6186 /* just in case bxe_mq_flush() wasn't called */
6187 if (mtx_initialized(&fp->tx_mtx)) {
6191 while ((m = buf_ring_dequeue_sc(fp->tx_br)) != NULL)
6193 BXE_FP_TX_UNLOCK(fp);
6197 /* free all RX buffers */
6198 bxe_free_rx_bd_chain(fp);
6199 bxe_free_tpa_pool(fp);
6200 bxe_free_sge_chain(fp);
6202 if (fp->eth_q_stats.mbuf_alloc_rx != 0) {
6203 BLOGE(sc, "failed to claim all rx mbufs (%d left)\n",
6204 fp->eth_q_stats.mbuf_alloc_rx);
6207 if (fp->eth_q_stats.mbuf_alloc_sge != 0) {
6208 BLOGE(sc, "failed to claim all sge mbufs (%d left)\n",
6209 fp->eth_q_stats.mbuf_alloc_sge);
6212 if (fp->eth_q_stats.mbuf_alloc_tpa != 0) {
6213 BLOGE(sc, "failed to claim all sge mbufs (%d left)\n",
6214 fp->eth_q_stats.mbuf_alloc_tpa);
6217 if (fp->eth_q_stats.mbuf_alloc_tx != 0) {
6218 BLOGE(sc, "failed to release tx mbufs (%d left)\n",
6219 fp->eth_q_stats.mbuf_alloc_tx);
6222 /* XXX verify all mbufs were reclaimed */
6227 bxe_alloc_rx_bd_mbuf(struct bxe_fastpath *fp,
6228 uint16_t prev_index,
6231 struct bxe_sw_rx_bd *rx_buf;
6232 struct eth_rx_bd *rx_bd;
6233 bus_dma_segment_t segs[1];
6240 /* allocate the new RX BD mbuf */
6241 m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, fp->mbuf_alloc_size);
6242 if (__predict_false(m == NULL)) {
6243 fp->eth_q_stats.mbuf_rx_bd_alloc_failed++;
6247 fp->eth_q_stats.mbuf_alloc_rx++;
6249 /* initialize the mbuf buffer length */
6250 m->m_pkthdr.len = m->m_len = fp->rx_buf_size;
6252 /* map the mbuf into non-paged pool */
6253 rc = bus_dmamap_load_mbuf_sg(fp->rx_mbuf_tag,
6254 fp->rx_mbuf_spare_map,
6255 m, segs, &nsegs, BUS_DMA_NOWAIT);
6256 if (__predict_false(rc != 0)) {
6257 fp->eth_q_stats.mbuf_rx_bd_mapping_failed++;
6259 fp->eth_q_stats.mbuf_alloc_rx--;
6263 /* all mbufs must map to a single segment */
6264 KASSERT((nsegs == 1), ("Too many segments, %d returned!", nsegs));
6266 /* release any existing RX BD mbuf mappings */
6268 if (prev_index != index) {
6269 rx_buf = &fp->rx_mbuf_chain[prev_index];
6271 if (rx_buf->m_map != NULL) {
6272 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map,
6273 BUS_DMASYNC_POSTREAD);
6274 bus_dmamap_unload(fp->rx_mbuf_tag, rx_buf->m_map);
6278 * We only get here from bxe_rxeof() when the maximum number
6279 * of rx buffers is less than RX_BD_USABLE. bxe_rxeof() already
6280 * holds the mbuf in the prev_index so it's OK to NULL it out
6281 * here without concern of a memory leak.
6283 fp->rx_mbuf_chain[prev_index].m = NULL;
6286 rx_buf = &fp->rx_mbuf_chain[index];
6288 if (rx_buf->m_map != NULL) {
6289 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map,
6290 BUS_DMASYNC_POSTREAD);
6291 bus_dmamap_unload(fp->rx_mbuf_tag, rx_buf->m_map);
6294 /* save the mbuf and mapping info for a future packet */
6295 map = (prev_index != index) ?
6296 fp->rx_mbuf_chain[prev_index].m_map : rx_buf->m_map;
6297 rx_buf->m_map = fp->rx_mbuf_spare_map;
6298 fp->rx_mbuf_spare_map = map;
6299 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map,
6300 BUS_DMASYNC_PREREAD);
6303 rx_bd = &fp->rx_chain[index];
6304 rx_bd->addr_hi = htole32(U64_HI(segs[0].ds_addr));
6305 rx_bd->addr_lo = htole32(U64_LO(segs[0].ds_addr));
6311 bxe_alloc_rx_tpa_mbuf(struct bxe_fastpath *fp,
6314 struct bxe_sw_tpa_info *tpa_info = &fp->rx_tpa_info[queue];
6315 bus_dma_segment_t segs[1];
6321 /* allocate the new TPA mbuf */
6322 m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, fp->mbuf_alloc_size);
6323 if (__predict_false(m == NULL)) {
6324 fp->eth_q_stats.mbuf_rx_tpa_alloc_failed++;
6328 fp->eth_q_stats.mbuf_alloc_tpa++;
6330 /* initialize the mbuf buffer length */
6331 m->m_pkthdr.len = m->m_len = fp->rx_buf_size;
6333 /* map the mbuf into non-paged pool */
6334 rc = bus_dmamap_load_mbuf_sg(fp->rx_mbuf_tag,
6335 fp->rx_tpa_info_mbuf_spare_map,
6336 m, segs, &nsegs, BUS_DMA_NOWAIT);
6337 if (__predict_false(rc != 0)) {
6338 fp->eth_q_stats.mbuf_rx_tpa_mapping_failed++;
6340 fp->eth_q_stats.mbuf_alloc_tpa--;
6344 /* all mbufs must map to a single segment */
6345 KASSERT((nsegs == 1), ("Too many segments, %d returned!", nsegs));
6347 /* release any existing TPA mbuf mapping */
6348 if (tpa_info->bd.m_map != NULL) {
6349 bus_dmamap_sync(fp->rx_mbuf_tag, tpa_info->bd.m_map,
6350 BUS_DMASYNC_POSTREAD);
6351 bus_dmamap_unload(fp->rx_mbuf_tag, tpa_info->bd.m_map);
6354 /* save the mbuf and mapping info for the TPA mbuf */
6355 map = tpa_info->bd.m_map;
6356 tpa_info->bd.m_map = fp->rx_tpa_info_mbuf_spare_map;
6357 fp->rx_tpa_info_mbuf_spare_map = map;
6358 bus_dmamap_sync(fp->rx_mbuf_tag, tpa_info->bd.m_map,
6359 BUS_DMASYNC_PREREAD);
6361 tpa_info->seg = segs[0];
6367 * Allocate an mbuf and assign it to the receive scatter gather chain. The
6368 * caller must take care to save a copy of the existing mbuf in the SG mbuf
6372 bxe_alloc_rx_sge_mbuf(struct bxe_fastpath *fp,
6375 struct bxe_sw_rx_bd *sge_buf;
6376 struct eth_rx_sge *sge;
6377 bus_dma_segment_t segs[1];
6383 /* allocate a new SGE mbuf */
6384 m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, SGE_PAGE_SIZE);
6385 if (__predict_false(m == NULL)) {
6386 fp->eth_q_stats.mbuf_rx_sge_alloc_failed++;
6390 fp->eth_q_stats.mbuf_alloc_sge++;
6392 /* initialize the mbuf buffer length */
6393 m->m_pkthdr.len = m->m_len = SGE_PAGE_SIZE;
6395 /* map the SGE mbuf into non-paged pool */
6396 rc = bus_dmamap_load_mbuf_sg(fp->rx_sge_mbuf_tag,
6397 fp->rx_sge_mbuf_spare_map,
6398 m, segs, &nsegs, BUS_DMA_NOWAIT);
6399 if (__predict_false(rc != 0)) {
6400 fp->eth_q_stats.mbuf_rx_sge_mapping_failed++;
6402 fp->eth_q_stats.mbuf_alloc_sge--;
6406 /* all mbufs must map to a single segment */
6407 KASSERT((nsegs == 1), ("Too many segments, %d returned!", nsegs));
6409 sge_buf = &fp->rx_sge_mbuf_chain[index];
6411 /* release any existing SGE mbuf mapping */
6412 if (sge_buf->m_map != NULL) {
6413 bus_dmamap_sync(fp->rx_sge_mbuf_tag, sge_buf->m_map,
6414 BUS_DMASYNC_POSTREAD);
6415 bus_dmamap_unload(fp->rx_sge_mbuf_tag, sge_buf->m_map);
6418 /* save the mbuf and mapping info for a future packet */
6419 map = sge_buf->m_map;
6420 sge_buf->m_map = fp->rx_sge_mbuf_spare_map;
6421 fp->rx_sge_mbuf_spare_map = map;
6422 bus_dmamap_sync(fp->rx_sge_mbuf_tag, sge_buf->m_map,
6423 BUS_DMASYNC_PREREAD);
6426 sge = &fp->rx_sge_chain[index];
6427 sge->addr_hi = htole32(U64_HI(segs[0].ds_addr));
6428 sge->addr_lo = htole32(U64_LO(segs[0].ds_addr));
6433 static __noinline int
6434 bxe_alloc_fp_buffers(struct bxe_softc *sc)
6436 struct bxe_fastpath *fp;
6438 int ring_prod, cqe_ring_prod;
6441 for (i = 0; i < sc->num_queues; i++) {
6444 ring_prod = cqe_ring_prod = 0;
6448 /* allocate buffers for the RX BDs in RX BD chain */
6449 for (j = 0; j < sc->max_rx_bufs; j++) {
6450 rc = bxe_alloc_rx_bd_mbuf(fp, ring_prod, ring_prod);
6452 BLOGE(sc, "mbuf alloc fail for fp[%02d] rx chain (%d)\n",
6454 goto bxe_alloc_fp_buffers_error;
6457 ring_prod = RX_BD_NEXT(ring_prod);
6458 cqe_ring_prod = RCQ_NEXT(cqe_ring_prod);
6461 fp->rx_bd_prod = ring_prod;
6462 fp->rx_cq_prod = cqe_ring_prod;
6463 fp->eth_q_stats.rx_calls = fp->eth_q_stats.rx_pkts = 0;
6465 max_agg_queues = MAX_AGG_QS(sc);
6467 fp->tpa_enable = TRUE;
6469 /* fill the TPA pool */
6470 for (j = 0; j < max_agg_queues; j++) {
6471 rc = bxe_alloc_rx_tpa_mbuf(fp, j);
6473 BLOGE(sc, "mbuf alloc fail for fp[%02d] TPA queue %d\n",
6475 fp->tpa_enable = FALSE;
6476 goto bxe_alloc_fp_buffers_error;
6479 fp->rx_tpa_info[j].state = BXE_TPA_STATE_STOP;
6482 if (fp->tpa_enable) {
6483 /* fill the RX SGE chain */
6485 for (j = 0; j < RX_SGE_USABLE; j++) {
6486 rc = bxe_alloc_rx_sge_mbuf(fp, ring_prod);
6488 BLOGE(sc, "mbuf alloc fail for fp[%02d] SGE %d\n",
6490 fp->tpa_enable = FALSE;
6492 goto bxe_alloc_fp_buffers_error;
6495 ring_prod = RX_SGE_NEXT(ring_prod);
6498 fp->rx_sge_prod = ring_prod;
6504 bxe_alloc_fp_buffers_error:
6506 /* unwind what was already allocated */
6507 bxe_free_rx_bd_chain(fp);
6508 bxe_free_tpa_pool(fp);
6509 bxe_free_sge_chain(fp);
6515 bxe_free_fw_stats_mem(struct bxe_softc *sc)
6517 bxe_dma_free(sc, &sc->fw_stats_dma);
6519 sc->fw_stats_num = 0;
6521 sc->fw_stats_req_size = 0;
6522 sc->fw_stats_req = NULL;
6523 sc->fw_stats_req_mapping = 0;
6525 sc->fw_stats_data_size = 0;
6526 sc->fw_stats_data = NULL;
6527 sc->fw_stats_data_mapping = 0;
6531 bxe_alloc_fw_stats_mem(struct bxe_softc *sc)
6533 uint8_t num_queue_stats;
6536 /* number of queues for statistics is number of eth queues */
6537 num_queue_stats = BXE_NUM_ETH_QUEUES(sc);
6540 * Total number of FW statistics requests =
6541 * 1 for port stats + 1 for PF stats + num of queues
6543 sc->fw_stats_num = (2 + num_queue_stats);
6546 * Request is built from stats_query_header and an array of
6547 * stats_query_cmd_group each of which contains STATS_QUERY_CMD_COUNT
6548 * rules. The real number or requests is configured in the
6549 * stats_query_header.
6552 ((sc->fw_stats_num / STATS_QUERY_CMD_COUNT) +
6553 ((sc->fw_stats_num % STATS_QUERY_CMD_COUNT) ? 1 : 0));
6555 BLOGD(sc, DBG_LOAD, "stats fw_stats_num %d num_groups %d\n",
6556 sc->fw_stats_num, num_groups);
6558 sc->fw_stats_req_size =
6559 (sizeof(struct stats_query_header) +
6560 (num_groups * sizeof(struct stats_query_cmd_group)));
6563 * Data for statistics requests + stats_counter.
6564 * stats_counter holds per-STORM counters that are incremented when
6565 * STORM has finished with the current request. Memory for FCoE
6566 * offloaded statistics are counted anyway, even if they will not be sent.
6567 * VF stats are not accounted for here as the data of VF stats is stored
6568 * in memory allocated by the VF, not here.
6570 sc->fw_stats_data_size =
6571 (sizeof(struct stats_counter) +
6572 sizeof(struct per_port_stats) +
6573 sizeof(struct per_pf_stats) +
6574 /* sizeof(struct fcoe_statistics_params) + */
6575 (sizeof(struct per_queue_stats) * num_queue_stats));
6577 if (bxe_dma_alloc(sc, (sc->fw_stats_req_size + sc->fw_stats_data_size),
6578 &sc->fw_stats_dma, "fw stats") != 0) {
6579 bxe_free_fw_stats_mem(sc);
6583 /* set up the shortcuts */
6586 (struct bxe_fw_stats_req *)sc->fw_stats_dma.vaddr;
6587 sc->fw_stats_req_mapping = sc->fw_stats_dma.paddr;
6590 (struct bxe_fw_stats_data *)((uint8_t *)sc->fw_stats_dma.vaddr +
6591 sc->fw_stats_req_size);
6592 sc->fw_stats_data_mapping = (sc->fw_stats_dma.paddr +
6593 sc->fw_stats_req_size);
6595 BLOGD(sc, DBG_LOAD, "statistics request base address set to %#jx\n",
6596 (uintmax_t)sc->fw_stats_req_mapping);
6598 BLOGD(sc, DBG_LOAD, "statistics data base address set to %#jx\n",
6599 (uintmax_t)sc->fw_stats_data_mapping);
6606 * 0-7 - Engine0 load counter.
6607 * 8-15 - Engine1 load counter.
6608 * 16 - Engine0 RESET_IN_PROGRESS bit.
6609 * 17 - Engine1 RESET_IN_PROGRESS bit.
6610 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active
6611 * function on the engine
6612 * 19 - Engine1 ONE_IS_LOADED.
6613 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
6614 * leader to complete (check for both RESET_IN_PROGRESS bits and not
6615 * for just the one belonging to its engine).
6617 #define BXE_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
6618 #define BXE_PATH0_LOAD_CNT_MASK 0x000000ff
6619 #define BXE_PATH0_LOAD_CNT_SHIFT 0
6620 #define BXE_PATH1_LOAD_CNT_MASK 0x0000ff00
6621 #define BXE_PATH1_LOAD_CNT_SHIFT 8
6622 #define BXE_PATH0_RST_IN_PROG_BIT 0x00010000
6623 #define BXE_PATH1_RST_IN_PROG_BIT 0x00020000
6624 #define BXE_GLOBAL_RESET_BIT 0x00040000
6626 /* set the GLOBAL_RESET bit, should be run under rtnl lock */
6628 bxe_set_reset_global(struct bxe_softc *sc)
6631 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6632 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6633 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val | BXE_GLOBAL_RESET_BIT);
6634 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6637 /* clear the GLOBAL_RESET bit, should be run under rtnl lock */
6639 bxe_clear_reset_global(struct bxe_softc *sc)
6642 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6643 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6644 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val & (~BXE_GLOBAL_RESET_BIT));
6645 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6648 /* checks the GLOBAL_RESET bit, should be run under rtnl lock */
6650 bxe_reset_is_global(struct bxe_softc *sc)
6652 uint32_t val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6653 BLOGD(sc, DBG_LOAD, "GLOB_REG=0x%08x\n", val);
6654 return (val & BXE_GLOBAL_RESET_BIT) ? TRUE : FALSE;
6657 /* clear RESET_IN_PROGRESS bit for the engine, should be run under rtnl lock */
6659 bxe_set_reset_done(struct bxe_softc *sc)
6662 uint32_t bit = SC_PATH(sc) ? BXE_PATH1_RST_IN_PROG_BIT :
6663 BXE_PATH0_RST_IN_PROG_BIT;
6665 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6667 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6670 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val);
6672 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6675 /* set RESET_IN_PROGRESS for the engine, should be run under rtnl lock */
6677 bxe_set_reset_in_progress(struct bxe_softc *sc)
6680 uint32_t bit = SC_PATH(sc) ? BXE_PATH1_RST_IN_PROG_BIT :
6681 BXE_PATH0_RST_IN_PROG_BIT;
6683 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6685 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6688 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val);
6690 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6693 /* check RESET_IN_PROGRESS bit for an engine, should be run under rtnl lock */
6695 bxe_reset_is_done(struct bxe_softc *sc,
6698 uint32_t val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6699 uint32_t bit = engine ? BXE_PATH1_RST_IN_PROG_BIT :
6700 BXE_PATH0_RST_IN_PROG_BIT;
6702 /* return false if bit is set */
6703 return (val & bit) ? FALSE : TRUE;
6706 /* get the load status for an engine, should be run under rtnl lock */
6708 bxe_get_load_status(struct bxe_softc *sc,
6711 uint32_t mask = engine ? BXE_PATH1_LOAD_CNT_MASK :
6712 BXE_PATH0_LOAD_CNT_MASK;
6713 uint32_t shift = engine ? BXE_PATH1_LOAD_CNT_SHIFT :
6714 BXE_PATH0_LOAD_CNT_SHIFT;
6715 uint32_t val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6717 BLOGD(sc, DBG_LOAD, "Old value for GLOB_REG=0x%08x\n", val);
6719 val = ((val & mask) >> shift);
6721 BLOGD(sc, DBG_LOAD, "Load mask engine %d = 0x%08x\n", engine, val);
6726 /* set pf load mark */
6727 /* XXX needs to be under rtnl lock */
6729 bxe_set_pf_load(struct bxe_softc *sc)
6733 uint32_t mask = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_MASK :
6734 BXE_PATH0_LOAD_CNT_MASK;
6735 uint32_t shift = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_SHIFT :
6736 BXE_PATH0_LOAD_CNT_SHIFT;
6738 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6740 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6741 BLOGD(sc, DBG_LOAD, "Old value for GLOB_REG=0x%08x\n", val);
6743 /* get the current counter value */
6744 val1 = ((val & mask) >> shift);
6746 /* set bit of this PF */
6747 val1 |= (1 << SC_ABS_FUNC(sc));
6749 /* clear the old value */
6752 /* set the new one */
6753 val |= ((val1 << shift) & mask);
6755 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val);
6757 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6760 /* clear pf load mark */
6761 /* XXX needs to be under rtnl lock */
6763 bxe_clear_pf_load(struct bxe_softc *sc)
6766 uint32_t mask = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_MASK :
6767 BXE_PATH0_LOAD_CNT_MASK;
6768 uint32_t shift = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_SHIFT :
6769 BXE_PATH0_LOAD_CNT_SHIFT;
6771 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6772 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG);
6773 BLOGD(sc, DBG_LOAD, "Old GEN_REG_VAL=0x%08x\n", val);
6775 /* get the current counter value */
6776 val1 = (val & mask) >> shift;
6778 /* clear bit of that PF */
6779 val1 &= ~(1 << SC_ABS_FUNC(sc));
6781 /* clear the old value */
6784 /* set the new one */
6785 val |= ((val1 << shift) & mask);
6787 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val);
6788 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
6792 /* send load requrest to mcp and analyze response */
6794 bxe_nic_load_request(struct bxe_softc *sc,
6795 uint32_t *load_code)
6799 (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_mb_header) &
6800 DRV_MSG_SEQ_NUMBER_MASK);
6802 BLOGD(sc, DBG_LOAD, "initial fw_seq 0x%04x\n", sc->fw_seq);
6804 /* get the current FW pulse sequence */
6805 sc->fw_drv_pulse_wr_seq =
6806 (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_pulse_mb) &
6807 DRV_PULSE_SEQ_MASK);
6809 BLOGD(sc, DBG_LOAD, "initial drv_pulse 0x%04x\n",
6810 sc->fw_drv_pulse_wr_seq);
6813 (*load_code) = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_REQ,
6814 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
6816 /* if the MCP fails to respond we must abort */
6817 if (!(*load_code)) {
6818 BLOGE(sc, "MCP response failure!\n");
6822 /* if MCP refused then must abort */
6823 if ((*load_code) == FW_MSG_CODE_DRV_LOAD_REFUSED) {
6824 BLOGE(sc, "MCP refused load request\n");
6832 * Check whether another PF has already loaded FW to chip. In virtualized
6833 * environments a pf from anoth VM may have already initialized the device
6834 * including loading FW.
6837 bxe_nic_load_analyze_req(struct bxe_softc *sc,
6840 uint32_t my_fw, loaded_fw;
6842 /* is another pf loaded on this engine? */
6843 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
6844 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
6845 /* build my FW version dword */
6846 my_fw = (BCM_5710_FW_MAJOR_VERSION +
6847 (BCM_5710_FW_MINOR_VERSION << 8 ) +
6848 (BCM_5710_FW_REVISION_VERSION << 16) +
6849 (BCM_5710_FW_ENGINEERING_VERSION << 24));
6851 /* read loaded FW from chip */
6852 loaded_fw = REG_RD(sc, XSEM_REG_PRAM);
6853 BLOGD(sc, DBG_LOAD, "loaded FW 0x%08x / my FW 0x%08x\n",
6856 /* abort nic load if version mismatch */
6857 if (my_fw != loaded_fw) {
6858 BLOGE(sc, "FW 0x%08x already loaded (mine is 0x%08x)",
6867 /* mark PMF if applicable */
6869 bxe_nic_load_pmf(struct bxe_softc *sc,
6872 uint32_t ncsi_oem_data_addr;
6874 if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) ||
6875 (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) ||
6876 (load_code == FW_MSG_CODE_DRV_LOAD_PORT)) {
6878 * Barrier here for ordering between the writing to sc->port.pmf here
6879 * and reading it from the periodic task.
6887 BLOGD(sc, DBG_LOAD, "pmf %d\n", sc->port.pmf);
6890 if (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) {
6891 if (SHMEM2_HAS(sc, ncsi_oem_data_addr)) {
6892 ncsi_oem_data_addr = SHMEM2_RD(sc, ncsi_oem_data_addr);
6893 if (ncsi_oem_data_addr) {
6895 (ncsi_oem_data_addr +
6896 offsetof(struct glob_ncsi_oem_data, driver_version)),
6904 bxe_read_mf_cfg(struct bxe_softc *sc)
6906 int n = (CHIP_IS_MODE_4_PORT(sc) ? 2 : 1);
6910 if (BXE_NOMCP(sc)) {
6911 return; /* what should be the default bvalue in this case */
6915 * The formula for computing the absolute function number is...
6916 * For 2 port configuration (4 functions per port):
6917 * abs_func = 2 * vn + SC_PORT + SC_PATH
6918 * For 4 port configuration (2 functions per port):
6919 * abs_func = 4 * vn + 2 * SC_PORT + SC_PATH
6921 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
6922 abs_func = (n * (2 * vn + SC_PORT(sc)) + SC_PATH(sc));
6923 if (abs_func >= E1H_FUNC_MAX) {
6926 sc->devinfo.mf_info.mf_config[vn] =
6927 MFCFG_RD(sc, func_mf_config[abs_func].config);
6930 if (sc->devinfo.mf_info.mf_config[SC_VN(sc)] &
6931 FUNC_MF_CFG_FUNC_DISABLED) {
6932 BLOGD(sc, DBG_LOAD, "mf_cfg function disabled\n");
6933 sc->flags |= BXE_MF_FUNC_DIS;
6935 BLOGD(sc, DBG_LOAD, "mf_cfg function enabled\n");
6936 sc->flags &= ~BXE_MF_FUNC_DIS;
6940 /* acquire split MCP access lock register */
6941 static int bxe_acquire_alr(struct bxe_softc *sc)
6945 for (j = 0; j < 1000; j++) {
6947 REG_WR(sc, GRCBASE_MCP + 0x9c, val);
6948 val = REG_RD(sc, GRCBASE_MCP + 0x9c);
6949 if (val & (1L << 31))
6955 if (!(val & (1L << 31))) {
6956 BLOGE(sc, "Cannot acquire MCP access lock register\n");
6963 /* release split MCP access lock register */
6964 static void bxe_release_alr(struct bxe_softc *sc)
6966 REG_WR(sc, GRCBASE_MCP + 0x9c, 0);
6970 bxe_fan_failure(struct bxe_softc *sc)
6972 int port = SC_PORT(sc);
6973 uint32_t ext_phy_config;
6975 /* mark the failure */
6977 SHMEM_RD(sc, dev_info.port_hw_config[port].external_phy_config);
6979 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
6980 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
6981 SHMEM_WR(sc, dev_info.port_hw_config[port].external_phy_config,
6984 /* log the failure */
6985 BLOGW(sc, "Fan Failure has caused the driver to shutdown "
6986 "the card to prevent permanent damage. "
6987 "Please contact OEM Support for assistance\n");
6991 bxe_panic(sc, ("Schedule task to handle fan failure\n"));
6994 * Schedule device reset (unload)
6995 * This is due to some boards consuming sufficient power when driver is
6996 * up to overheat if fan fails.
6998 bxe_set_bit(BXE_SP_RTNL_FAN_FAILURE, &sc->sp_rtnl_state);
6999 schedule_delayed_work(&sc->sp_rtnl_task, 0);
7003 /* this function is called upon a link interrupt */
7005 bxe_link_attn(struct bxe_softc *sc)
7007 uint32_t pause_enabled = 0;
7008 struct host_port_stats *pstats;
7010 struct bxe_fastpath *fp;
7013 /* Make sure that we are synced with the current statistics */
7014 bxe_stats_handle(sc, STATS_EVENT_STOP);
7015 BLOGD(sc, DBG_LOAD, "link_vars phy_flags : %x\n", sc->link_vars.phy_flags);
7016 elink_link_update(&sc->link_params, &sc->link_vars);
7018 if (sc->link_vars.link_up) {
7020 /* dropless flow control */
7021 if (!CHIP_IS_E1(sc) && sc->dropless_fc) {
7024 if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_TX) {
7029 (BAR_USTRORM_INTMEM +
7030 USTORM_ETH_PAUSE_ENABLED_OFFSET(SC_PORT(sc))),
7034 if (sc->link_vars.mac_type != ELINK_MAC_TYPE_EMAC) {
7035 pstats = BXE_SP(sc, port_stats);
7036 /* reset old mac stats */
7037 memset(&(pstats->mac_stx[0]), 0, sizeof(struct mac_stx));
7040 if (sc->state == BXE_STATE_OPEN) {
7041 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
7042 /* Restart tx when the link comes back. */
7043 FOR_EACH_ETH_QUEUE(sc, i) {
7045 taskqueue_enqueue(fp->tq, &fp->tx_task);
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,
7536 if( *global == TRUE ) {
7537 BXE_SET_ERROR_BIT(sc, BXE_ERR_GLOBAL);
7547 bxe_chk_parity_attn(struct bxe_softc *sc,
7551 struct attn_route attn = { {0} };
7552 int port = SC_PORT(sc);
7554 if(sc->state != BXE_STATE_OPEN)
7557 attn.sig[0] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
7558 attn.sig[1] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
7559 attn.sig[2] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
7560 attn.sig[3] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
7563 * Since MCP attentions can't be disabled inside the block, we need to
7564 * read AEU registers to see whether they're currently disabled
7566 attn.sig[3] &= ((REG_RD(sc, (!port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
7567 : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0)) &
7568 MISC_AEU_ENABLE_MCP_PRTY_BITS) |
7569 ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
7572 if (!CHIP_IS_E1x(sc))
7573 attn.sig[4] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
7575 return (bxe_parity_attn(sc, global, print, attn.sig));
7579 bxe_attn_int_deasserted4(struct bxe_softc *sc,
7583 boolean_t err_flg = FALSE;
7585 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
7586 val = REG_RD(sc, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
7587 BLOGE(sc, "PGLUE hw attention 0x%08x\n", val);
7589 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
7590 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
7591 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
7592 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
7593 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
7594 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
7595 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
7596 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
7597 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
7598 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
7599 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
7600 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
7601 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
7602 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
7603 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
7604 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
7605 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
7606 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
7609 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
7610 val = REG_RD(sc, ATC_REG_ATC_INT_STS_CLR);
7611 BLOGE(sc, "ATC hw attention 0x%08x\n", val);
7613 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
7614 BLOGE(sc, "ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
7615 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
7616 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
7617 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
7618 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
7619 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
7620 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
7621 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
7622 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
7623 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
7624 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
7627 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
7628 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
7629 BLOGE(sc, "FATAL parity attention set4 0x%08x\n",
7630 (uint32_t)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
7631 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
7635 BXE_SET_ERROR_BIT(sc, BXE_ERR_MISC);
7636 taskqueue_enqueue_timeout(taskqueue_thread,
7637 &sc->sp_err_timeout_task, hz/10);
7643 bxe_e1h_disable(struct bxe_softc *sc)
7645 int port = SC_PORT(sc);
7649 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 0);
7653 bxe_e1h_enable(struct bxe_softc *sc)
7655 int port = SC_PORT(sc);
7657 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 1);
7659 // XXX bxe_tx_enable(sc);
7663 * called due to MCP event (on pmf):
7664 * reread new bandwidth configuration
7666 * notify others function about the change
7669 bxe_config_mf_bw(struct bxe_softc *sc)
7671 if (sc->link_vars.link_up) {
7672 bxe_cmng_fns_init(sc, TRUE, CMNG_FNS_MINMAX);
7673 // XXX bxe_link_sync_notify(sc);
7676 storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc));
7680 bxe_set_mf_bw(struct bxe_softc *sc)
7682 bxe_config_mf_bw(sc);
7683 bxe_fw_command(sc, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
7687 bxe_handle_eee_event(struct bxe_softc *sc)
7689 BLOGD(sc, DBG_INTR, "EEE - LLDP event\n");
7690 bxe_fw_command(sc, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
7693 #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
7696 bxe_drv_info_ether_stat(struct bxe_softc *sc)
7698 struct eth_stats_info *ether_stat =
7699 &sc->sp->drv_info_to_mcp.ether_stat;
7701 strlcpy(ether_stat->version, BXE_DRIVER_VERSION,
7702 ETH_STAT_INFO_VERSION_LEN);
7704 /* XXX (+ MAC_PAD) taken from other driver... verify this is right */
7705 sc->sp_objs[0].mac_obj.get_n_elements(sc, &sc->sp_objs[0].mac_obj,
7706 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
7707 ether_stat->mac_local + MAC_PAD,
7710 ether_stat->mtu_size = sc->mtu;
7712 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
7713 if (if_getcapenable(sc->ifp) & (IFCAP_TSO4 | IFCAP_TSO6)) {
7714 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
7717 // XXX ether_stat->feature_flags |= ???;
7719 ether_stat->promiscuous_mode = 0; // (flags & PROMISC) ? 1 : 0;
7721 ether_stat->txq_size = sc->tx_ring_size;
7722 ether_stat->rxq_size = sc->rx_ring_size;
7726 bxe_handle_drv_info_req(struct bxe_softc *sc)
7728 enum drv_info_opcode op_code;
7729 uint32_t drv_info_ctl = SHMEM2_RD(sc, drv_info_control);
7731 /* if drv_info version supported by MFW doesn't match - send NACK */
7732 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
7733 bxe_fw_command(sc, DRV_MSG_CODE_DRV_INFO_NACK, 0);
7737 op_code = ((drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
7738 DRV_INFO_CONTROL_OP_CODE_SHIFT);
7740 memset(&sc->sp->drv_info_to_mcp, 0, sizeof(union drv_info_to_mcp));
7743 case ETH_STATS_OPCODE:
7744 bxe_drv_info_ether_stat(sc);
7746 case FCOE_STATS_OPCODE:
7747 case ISCSI_STATS_OPCODE:
7749 /* if op code isn't supported - send NACK */
7750 bxe_fw_command(sc, DRV_MSG_CODE_DRV_INFO_NACK, 0);
7755 * If we got drv_info attn from MFW then these fields are defined in
7758 SHMEM2_WR(sc, drv_info_host_addr_lo,
7759 U64_LO(BXE_SP_MAPPING(sc, drv_info_to_mcp)));
7760 SHMEM2_WR(sc, drv_info_host_addr_hi,
7761 U64_HI(BXE_SP_MAPPING(sc, drv_info_to_mcp)));
7763 bxe_fw_command(sc, DRV_MSG_CODE_DRV_INFO_ACK, 0);
7767 bxe_dcc_event(struct bxe_softc *sc,
7770 BLOGD(sc, DBG_INTR, "dcc_event 0x%08x\n", dcc_event);
7772 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
7774 * This is the only place besides the function initialization
7775 * where the sc->flags can change so it is done without any
7778 if (sc->devinfo.mf_info.mf_config[SC_VN(sc)] & FUNC_MF_CFG_FUNC_DISABLED) {
7779 BLOGD(sc, DBG_INTR, "mf_cfg function disabled\n");
7780 sc->flags |= BXE_MF_FUNC_DIS;
7781 bxe_e1h_disable(sc);
7783 BLOGD(sc, DBG_INTR, "mf_cfg function enabled\n");
7784 sc->flags &= ~BXE_MF_FUNC_DIS;
7787 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
7790 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
7791 bxe_config_mf_bw(sc);
7792 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
7795 /* Report results to MCP */
7797 bxe_fw_command(sc, DRV_MSG_CODE_DCC_FAILURE, 0);
7799 bxe_fw_command(sc, DRV_MSG_CODE_DCC_OK, 0);
7803 bxe_pmf_update(struct bxe_softc *sc)
7805 int port = SC_PORT(sc);
7809 BLOGD(sc, DBG_INTR, "pmf %d\n", sc->port.pmf);
7812 * We need the mb() to ensure the ordering between the writing to
7813 * sc->port.pmf here and reading it from the bxe_periodic_task().
7817 /* queue a periodic task */
7818 // XXX schedule task...
7820 // XXX bxe_dcbx_pmf_update(sc);
7822 /* enable nig attention */
7823 val = (0xff0f | (1 << (SC_VN(sc) + 4)));
7824 if (sc->devinfo.int_block == INT_BLOCK_HC) {
7825 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, val);
7826 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, val);
7827 } else if (!CHIP_IS_E1x(sc)) {
7828 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, val);
7829 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, val);
7832 bxe_stats_handle(sc, STATS_EVENT_PMF);
7836 bxe_mc_assert(struct bxe_softc *sc)
7840 uint32_t row0, row1, row2, row3;
7843 last_idx = REG_RD8(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_INDEX_OFFSET);
7845 BLOGE(sc, "XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
7847 /* print the asserts */
7848 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
7850 row0 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i));
7851 row1 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) + 4);
7852 row2 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) + 8);
7853 row3 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) + 12);
7855 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
7856 BLOGE(sc, "XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
7857 i, row3, row2, row1, row0);
7865 last_idx = REG_RD8(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_INDEX_OFFSET);
7867 BLOGE(sc, "TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
7870 /* print the asserts */
7871 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
7873 row0 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i));
7874 row1 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) + 4);
7875 row2 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) + 8);
7876 row3 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) + 12);
7878 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
7879 BLOGE(sc, "TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
7880 i, row3, row2, row1, row0);
7888 last_idx = REG_RD8(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_INDEX_OFFSET);
7890 BLOGE(sc, "CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
7893 /* print the asserts */
7894 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
7896 row0 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i));
7897 row1 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) + 4);
7898 row2 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) + 8);
7899 row3 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) + 12);
7901 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
7902 BLOGE(sc, "CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
7903 i, row3, row2, row1, row0);
7911 last_idx = REG_RD8(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_INDEX_OFFSET);
7913 BLOGE(sc, "USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
7916 /* print the asserts */
7917 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
7919 row0 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i));
7920 row1 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) + 4);
7921 row2 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) + 8);
7922 row3 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) + 12);
7924 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
7925 BLOGE(sc, "USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
7926 i, row3, row2, row1, row0);
7937 bxe_attn_int_deasserted3(struct bxe_softc *sc,
7940 int func = SC_FUNC(sc);
7943 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
7945 if (attn & BXE_PMF_LINK_ASSERT(sc)) {
7947 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7948 bxe_read_mf_cfg(sc);
7949 sc->devinfo.mf_info.mf_config[SC_VN(sc)] =
7950 MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config);
7951 val = SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_status);
7953 if (val & DRV_STATUS_DCC_EVENT_MASK)
7954 bxe_dcc_event(sc, (val & DRV_STATUS_DCC_EVENT_MASK));
7956 if (val & DRV_STATUS_SET_MF_BW)
7959 if (val & DRV_STATUS_DRV_INFO_REQ)
7960 bxe_handle_drv_info_req(sc);
7962 if ((sc->port.pmf == 0) && (val & DRV_STATUS_PMF))
7965 if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
7966 bxe_handle_eee_event(sc);
7968 if (sc->link_vars.periodic_flags &
7969 ELINK_PERIODIC_FLAGS_LINK_EVENT) {
7970 /* sync with link */
7971 bxe_acquire_phy_lock(sc);
7972 sc->link_vars.periodic_flags &=
7973 ~ELINK_PERIODIC_FLAGS_LINK_EVENT;
7974 bxe_release_phy_lock(sc);
7976 ; // XXX bxe_link_sync_notify(sc);
7977 bxe_link_report(sc);
7981 * Always call it here: bxe_link_report() will
7982 * prevent the link indication duplication.
7984 bxe_link_status_update(sc);
7986 } else if (attn & BXE_MC_ASSERT_BITS) {
7988 BLOGE(sc, "MC assert!\n");
7990 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_10, 0);
7991 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_9, 0);
7992 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_8, 0);
7993 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_7, 0);
7994 bxe_int_disable(sc);
7995 BXE_SET_ERROR_BIT(sc, BXE_ERR_MC_ASSERT);
7996 taskqueue_enqueue_timeout(taskqueue_thread,
7997 &sc->sp_err_timeout_task, hz/10);
7999 } else if (attn & BXE_MCP_ASSERT) {
8001 BLOGE(sc, "MCP assert!\n");
8002 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_11, 0);
8003 BXE_SET_ERROR_BIT(sc, BXE_ERR_MCP_ASSERT);
8004 taskqueue_enqueue_timeout(taskqueue_thread,
8005 &sc->sp_err_timeout_task, hz/10);
8006 bxe_int_disable(sc); /*avoid repetive assert alert */
8010 BLOGE(sc, "Unknown HW assert! (attn 0x%08x)\n", attn);
8014 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
8015 BLOGE(sc, "LATCHED attention 0x%08x (masked)\n", attn);
8016 if (attn & BXE_GRC_TIMEOUT) {
8017 val = CHIP_IS_E1(sc) ? 0 : REG_RD(sc, MISC_REG_GRC_TIMEOUT_ATTN);
8018 BLOGE(sc, "GRC time-out 0x%08x\n", val);
8020 if (attn & BXE_GRC_RSV) {
8021 val = CHIP_IS_E1(sc) ? 0 : REG_RD(sc, MISC_REG_GRC_RSV_ATTN);
8022 BLOGE(sc, "GRC reserved 0x%08x\n", val);
8024 REG_WR(sc, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
8029 bxe_attn_int_deasserted2(struct bxe_softc *sc,
8032 int port = SC_PORT(sc);
8034 uint32_t val0, mask0, val1, mask1;
8036 boolean_t err_flg = FALSE;
8038 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
8039 val = REG_RD(sc, CFC_REG_CFC_INT_STS_CLR);
8040 BLOGE(sc, "CFC hw attention 0x%08x\n", val);
8041 /* CFC error attention */
8043 BLOGE(sc, "FATAL error from CFC\n");
8048 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
8049 val = REG_RD(sc, PXP_REG_PXP_INT_STS_CLR_0);
8050 BLOGE(sc, "PXP hw attention-0 0x%08x\n", val);
8051 /* RQ_USDMDP_FIFO_OVERFLOW */
8052 if (val & 0x18000) {
8053 BLOGE(sc, "FATAL error from PXP\n");
8057 if (!CHIP_IS_E1x(sc)) {
8058 val = REG_RD(sc, PXP_REG_PXP_INT_STS_CLR_1);
8059 BLOGE(sc, "PXP hw attention-1 0x%08x\n", val);
8064 #define PXP2_EOP_ERROR_BIT PXP2_PXP2_INT_STS_CLR_0_REG_WR_PGLUE_EOP_ERROR
8065 #define AEU_PXP2_HW_INT_BIT AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_HW_INTERRUPT
8067 if (attn & AEU_PXP2_HW_INT_BIT) {
8068 /* CQ47854 workaround do not panic on
8069 * PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR
8071 if (!CHIP_IS_E1x(sc)) {
8072 mask0 = REG_RD(sc, PXP2_REG_PXP2_INT_MASK_0);
8073 val1 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_1);
8074 mask1 = REG_RD(sc, PXP2_REG_PXP2_INT_MASK_1);
8075 val0 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_0);
8077 * If the only PXP2_EOP_ERROR_BIT is set in
8078 * STS0 and STS1 - clear it
8080 * probably we lose additional attentions between
8081 * STS0 and STS_CLR0, in this case user will not
8082 * be notified about them
8084 if (val0 & mask0 & PXP2_EOP_ERROR_BIT &&
8086 val0 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_CLR_0);
8088 /* print the register, since no one can restore it */
8089 BLOGE(sc, "PXP2_REG_PXP2_INT_STS_CLR_0 0x%08x\n", val0);
8092 * if PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR
8095 if (val0 & PXP2_EOP_ERROR_BIT) {
8096 BLOGE(sc, "PXP2_WR_PGLUE_EOP_ERROR\n");
8100 * if only PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR is
8101 * set then clear attention from PXP2 block without panic
8103 if (((val0 & mask0) == PXP2_EOP_ERROR_BIT) &&
8104 ((val1 & mask1) == 0))
8105 attn &= ~AEU_PXP2_HW_INT_BIT;
8110 if (attn & HW_INTERRUT_ASSERT_SET_2) {
8111 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
8112 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
8114 val = REG_RD(sc, reg_offset);
8115 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
8116 REG_WR(sc, reg_offset, val);
8118 BLOGE(sc, "FATAL HW block attention set2 0x%x\n",
8119 (uint32_t)(attn & HW_INTERRUT_ASSERT_SET_2));
8121 bxe_panic(sc, ("HW block attention set2\n"));
8124 BXE_SET_ERROR_BIT(sc, BXE_ERR_GLOBAL);
8125 taskqueue_enqueue_timeout(taskqueue_thread,
8126 &sc->sp_err_timeout_task, hz/10);
8132 bxe_attn_int_deasserted1(struct bxe_softc *sc,
8135 int port = SC_PORT(sc);
8138 boolean_t err_flg = FALSE;
8140 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
8141 val = REG_RD(sc, DORQ_REG_DORQ_INT_STS_CLR);
8142 BLOGE(sc, "DB hw attention 0x%08x\n", val);
8143 /* DORQ discard attention */
8145 BLOGE(sc, "FATAL error from DORQ\n");
8150 if (attn & HW_INTERRUT_ASSERT_SET_1) {
8151 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
8152 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
8154 val = REG_RD(sc, reg_offset);
8155 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
8156 REG_WR(sc, reg_offset, val);
8158 BLOGE(sc, "FATAL HW block attention set1 0x%08x\n",
8159 (uint32_t)(attn & HW_INTERRUT_ASSERT_SET_1));
8161 bxe_panic(sc, ("HW block attention set1\n"));
8164 BXE_SET_ERROR_BIT(sc, BXE_ERR_MISC);
8165 taskqueue_enqueue_timeout(taskqueue_thread,
8166 &sc->sp_err_timeout_task, hz/10);
8172 bxe_attn_int_deasserted0(struct bxe_softc *sc,
8175 int port = SC_PORT(sc);
8179 reg_offset = (port) ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
8180 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
8182 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
8183 val = REG_RD(sc, reg_offset);
8184 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
8185 REG_WR(sc, reg_offset, val);
8187 BLOGW(sc, "SPIO5 hw attention\n");
8189 /* Fan failure attention */
8190 elink_hw_reset_phy(&sc->link_params);
8191 bxe_fan_failure(sc);
8194 if ((attn & sc->link_vars.aeu_int_mask) && sc->port.pmf) {
8195 bxe_acquire_phy_lock(sc);
8196 elink_handle_module_detect_int(&sc->link_params);
8197 bxe_release_phy_lock(sc);
8200 if (attn & HW_INTERRUT_ASSERT_SET_0) {
8201 val = REG_RD(sc, reg_offset);
8202 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
8203 REG_WR(sc, reg_offset, val);
8206 BXE_SET_ERROR_BIT(sc, BXE_ERR_MISC);
8207 taskqueue_enqueue_timeout(taskqueue_thread,
8208 &sc->sp_err_timeout_task, hz/10);
8210 bxe_panic(sc, ("FATAL HW block attention set0 0x%lx\n",
8211 (attn & HW_INTERRUT_ASSERT_SET_0)));
8216 bxe_attn_int_deasserted(struct bxe_softc *sc,
8217 uint32_t deasserted)
8219 struct attn_route attn;
8220 struct attn_route *group_mask;
8221 int port = SC_PORT(sc);
8226 uint8_t global = FALSE;
8229 * Need to take HW lock because MCP or other port might also
8230 * try to handle this event.
8232 bxe_acquire_alr(sc);
8234 if (bxe_chk_parity_attn(sc, &global, TRUE)) {
8236 * In case of parity errors don't handle attentions so that
8237 * other function would "see" parity errors.
8239 // XXX schedule a recovery task...
8240 /* disable HW interrupts */
8241 bxe_int_disable(sc);
8242 BXE_SET_ERROR_BIT(sc, BXE_ERR_PARITY);
8243 taskqueue_enqueue_timeout(taskqueue_thread,
8244 &sc->sp_err_timeout_task, hz/10);
8245 bxe_release_alr(sc);
8249 attn.sig[0] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
8250 attn.sig[1] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
8251 attn.sig[2] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
8252 attn.sig[3] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
8253 if (!CHIP_IS_E1x(sc)) {
8254 attn.sig[4] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
8259 BLOGD(sc, DBG_INTR, "attn: 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
8260 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
8262 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
8263 if (deasserted & (1 << index)) {
8264 group_mask = &sc->attn_group[index];
8267 "group[%d]: 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n", index,
8268 group_mask->sig[0], group_mask->sig[1],
8269 group_mask->sig[2], group_mask->sig[3],
8270 group_mask->sig[4]);
8272 bxe_attn_int_deasserted4(sc, attn.sig[4] & group_mask->sig[4]);
8273 bxe_attn_int_deasserted3(sc, attn.sig[3] & group_mask->sig[3]);
8274 bxe_attn_int_deasserted1(sc, attn.sig[1] & group_mask->sig[1]);
8275 bxe_attn_int_deasserted2(sc, attn.sig[2] & group_mask->sig[2]);
8276 bxe_attn_int_deasserted0(sc, attn.sig[0] & group_mask->sig[0]);
8280 bxe_release_alr(sc);
8282 if (sc->devinfo.int_block == INT_BLOCK_HC) {
8283 reg_addr = (HC_REG_COMMAND_REG + port*32 +
8284 COMMAND_REG_ATTN_BITS_CLR);
8286 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
8291 "about to mask 0x%08x at %s addr 0x%08x\n", val,
8292 (sc->devinfo.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
8293 REG_WR(sc, reg_addr, val);
8295 if (~sc->attn_state & deasserted) {
8296 BLOGE(sc, "IGU error\n");
8299 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8300 MISC_REG_AEU_MASK_ATTN_FUNC_0;
8302 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
8304 aeu_mask = REG_RD(sc, reg_addr);
8306 BLOGD(sc, DBG_INTR, "aeu_mask 0x%08x newly deasserted 0x%08x\n",
8307 aeu_mask, deasserted);
8308 aeu_mask |= (deasserted & 0x3ff);
8309 BLOGD(sc, DBG_INTR, "new mask 0x%08x\n", aeu_mask);
8311 REG_WR(sc, reg_addr, aeu_mask);
8312 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
8314 BLOGD(sc, DBG_INTR, "attn_state 0x%08x\n", sc->attn_state);
8315 sc->attn_state &= ~deasserted;
8316 BLOGD(sc, DBG_INTR, "new state 0x%08x\n", sc->attn_state);
8320 bxe_attn_int(struct bxe_softc *sc)
8322 /* read local copy of bits */
8323 uint32_t attn_bits = le32toh(sc->def_sb->atten_status_block.attn_bits);
8324 uint32_t attn_ack = le32toh(sc->def_sb->atten_status_block.attn_bits_ack);
8325 uint32_t attn_state = sc->attn_state;
8327 /* look for changed bits */
8328 uint32_t asserted = attn_bits & ~attn_ack & ~attn_state;
8329 uint32_t deasserted = ~attn_bits & attn_ack & attn_state;
8332 "attn_bits 0x%08x attn_ack 0x%08x asserted 0x%08x deasserted 0x%08x\n",
8333 attn_bits, attn_ack, asserted, deasserted);
8335 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state)) {
8336 BLOGE(sc, "BAD attention state\n");
8339 /* handle bits that were raised */
8341 bxe_attn_int_asserted(sc, asserted);
8345 bxe_attn_int_deasserted(sc, deasserted);
8350 bxe_update_dsb_idx(struct bxe_softc *sc)
8352 struct host_sp_status_block *def_sb = sc->def_sb;
8355 mb(); /* status block is written to by the chip */
8357 if (sc->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
8358 sc->def_att_idx = def_sb->atten_status_block.attn_bits_index;
8359 rc |= BXE_DEF_SB_ATT_IDX;
8362 if (sc->def_idx != def_sb->sp_sb.running_index) {
8363 sc->def_idx = def_sb->sp_sb.running_index;
8364 rc |= BXE_DEF_SB_IDX;
8372 static inline struct ecore_queue_sp_obj *
8373 bxe_cid_to_q_obj(struct bxe_softc *sc,
8376 BLOGD(sc, DBG_SP, "retrieving fp from cid %d\n", cid);
8377 return (&sc->sp_objs[CID_TO_FP(cid, sc)].q_obj);
8381 bxe_handle_mcast_eqe(struct bxe_softc *sc)
8383 struct ecore_mcast_ramrod_params rparam;
8386 memset(&rparam, 0, sizeof(rparam));
8388 rparam.mcast_obj = &sc->mcast_obj;
8392 /* clear pending state for the last command */
8393 sc->mcast_obj.raw.clear_pending(&sc->mcast_obj.raw);
8395 /* if there are pending mcast commands - send them */
8396 if (sc->mcast_obj.check_pending(&sc->mcast_obj)) {
8397 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT);
8400 "ERROR: Failed to send pending mcast commands (%d)\n", rc);
8404 BXE_MCAST_UNLOCK(sc);
8408 bxe_handle_classification_eqe(struct bxe_softc *sc,
8409 union event_ring_elem *elem)
8411 unsigned long ramrod_flags = 0;
8413 uint32_t cid = elem->message.data.eth_event.echo & BXE_SWCID_MASK;
8414 struct ecore_vlan_mac_obj *vlan_mac_obj;
8416 /* always push next commands out, don't wait here */
8417 bit_set(&ramrod_flags, RAMROD_CONT);
8419 switch (le32toh(elem->message.data.eth_event.echo) >> BXE_SWCID_SHIFT) {
8420 case ECORE_FILTER_MAC_PENDING:
8421 BLOGD(sc, DBG_SP, "Got SETUP_MAC completions\n");
8422 vlan_mac_obj = &sc->sp_objs[cid].mac_obj;
8425 case ECORE_FILTER_MCAST_PENDING:
8426 BLOGD(sc, DBG_SP, "Got SETUP_MCAST completions\n");
8428 * This is only relevant for 57710 where multicast MACs are
8429 * configured as unicast MACs using the same ramrod.
8431 bxe_handle_mcast_eqe(sc);
8435 BLOGE(sc, "Unsupported classification command: %d\n",
8436 elem->message.data.eth_event.echo);
8440 rc = vlan_mac_obj->complete(sc, vlan_mac_obj, elem, &ramrod_flags);
8443 BLOGE(sc, "Failed to schedule new commands (%d)\n", rc);
8444 } else if (rc > 0) {
8445 BLOGD(sc, DBG_SP, "Scheduled next pending commands...\n");
8450 bxe_handle_rx_mode_eqe(struct bxe_softc *sc,
8451 union event_ring_elem *elem)
8453 bxe_clear_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state);
8455 /* send rx_mode command again if was requested */
8456 if (bxe_test_and_clear_bit(ECORE_FILTER_RX_MODE_SCHED,
8458 bxe_set_storm_rx_mode(sc);
8463 bxe_update_eq_prod(struct bxe_softc *sc,
8466 storm_memset_eq_prod(sc, prod, SC_FUNC(sc));
8467 wmb(); /* keep prod updates ordered */
8471 bxe_eq_int(struct bxe_softc *sc)
8473 uint16_t hw_cons, sw_cons, sw_prod;
8474 union event_ring_elem *elem;
8479 struct ecore_queue_sp_obj *q_obj;
8480 struct ecore_func_sp_obj *f_obj = &sc->func_obj;
8481 struct ecore_raw_obj *rss_raw = &sc->rss_conf_obj.raw;
8483 hw_cons = le16toh(*sc->eq_cons_sb);
8486 * The hw_cons range is 1-255, 257 - the sw_cons range is 0-254, 256.
8487 * when we get to the next-page we need to adjust so the loop
8488 * condition below will be met. The next element is the size of a
8489 * regular element and hence incrementing by 1
8491 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE) {
8496 * This function may never run in parallel with itself for a
8497 * specific sc and no need for a read memory barrier here.
8499 sw_cons = sc->eq_cons;
8500 sw_prod = sc->eq_prod;
8502 BLOGD(sc, DBG_SP,"EQ: hw_cons=%u sw_cons=%u eq_spq_left=0x%lx\n",
8503 hw_cons, sw_cons, atomic_load_acq_long(&sc->eq_spq_left));
8507 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
8509 elem = &sc->eq[EQ_DESC(sw_cons)];
8511 /* elem CID originates from FW, actually LE */
8512 cid = SW_CID(elem->message.data.cfc_del_event.cid);
8513 opcode = elem->message.opcode;
8515 /* handle eq element */
8518 case EVENT_RING_OPCODE_STAT_QUERY:
8519 BLOGD(sc, DBG_SP, "got statistics completion event %d\n",
8521 /* nothing to do with stats comp */
8524 case EVENT_RING_OPCODE_CFC_DEL:
8525 /* handle according to cid range */
8526 /* we may want to verify here that the sc state is HALTING */
8527 BLOGD(sc, DBG_SP, "got delete ramrod for MULTI[%d]\n", cid);
8528 q_obj = bxe_cid_to_q_obj(sc, cid);
8529 if (q_obj->complete_cmd(sc, q_obj, ECORE_Q_CMD_CFC_DEL)) {
8534 case EVENT_RING_OPCODE_STOP_TRAFFIC:
8535 BLOGD(sc, DBG_SP, "got STOP TRAFFIC\n");
8536 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_TX_STOP)) {
8539 // XXX bxe_dcbx_set_params(sc, BXE_DCBX_STATE_TX_PAUSED);
8542 case EVENT_RING_OPCODE_START_TRAFFIC:
8543 BLOGD(sc, DBG_SP, "got START TRAFFIC\n");
8544 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_TX_START)) {
8547 // XXX bxe_dcbx_set_params(sc, BXE_DCBX_STATE_TX_RELEASED);
8550 case EVENT_RING_OPCODE_FUNCTION_UPDATE:
8551 echo = elem->message.data.function_update_event.echo;
8552 if (echo == SWITCH_UPDATE) {
8553 BLOGD(sc, DBG_SP, "got FUNC_SWITCH_UPDATE ramrod\n");
8554 if (f_obj->complete_cmd(sc, f_obj,
8555 ECORE_F_CMD_SWITCH_UPDATE)) {
8561 "AFEX: ramrod completed FUNCTION_UPDATE\n");
8565 case EVENT_RING_OPCODE_FORWARD_SETUP:
8566 q_obj = &bxe_fwd_sp_obj(sc, q_obj);
8567 if (q_obj->complete_cmd(sc, q_obj,
8568 ECORE_Q_CMD_SETUP_TX_ONLY)) {
8573 case EVENT_RING_OPCODE_FUNCTION_START:
8574 BLOGD(sc, DBG_SP, "got FUNC_START ramrod\n");
8575 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_START)) {
8580 case EVENT_RING_OPCODE_FUNCTION_STOP:
8581 BLOGD(sc, DBG_SP, "got FUNC_STOP ramrod\n");
8582 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_STOP)) {
8588 switch (opcode | sc->state) {
8589 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | BXE_STATE_OPEN):
8590 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | BXE_STATE_OPENING_WAITING_PORT):
8591 cid = elem->message.data.eth_event.echo & BXE_SWCID_MASK;
8592 BLOGD(sc, DBG_SP, "got RSS_UPDATE ramrod. CID %d\n", cid);
8593 rss_raw->clear_pending(rss_raw);
8596 case (EVENT_RING_OPCODE_SET_MAC | BXE_STATE_OPEN):
8597 case (EVENT_RING_OPCODE_SET_MAC | BXE_STATE_DIAG):
8598 case (EVENT_RING_OPCODE_SET_MAC | BXE_STATE_CLOSING_WAITING_HALT):
8599 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BXE_STATE_OPEN):
8600 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BXE_STATE_DIAG):
8601 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BXE_STATE_CLOSING_WAITING_HALT):
8602 BLOGD(sc, DBG_SP, "got (un)set mac ramrod\n");
8603 bxe_handle_classification_eqe(sc, elem);
8606 case (EVENT_RING_OPCODE_MULTICAST_RULES | BXE_STATE_OPEN):
8607 case (EVENT_RING_OPCODE_MULTICAST_RULES | BXE_STATE_DIAG):
8608 case (EVENT_RING_OPCODE_MULTICAST_RULES | BXE_STATE_CLOSING_WAITING_HALT):
8609 BLOGD(sc, DBG_SP, "got mcast ramrod\n");
8610 bxe_handle_mcast_eqe(sc);
8613 case (EVENT_RING_OPCODE_FILTERS_RULES | BXE_STATE_OPEN):
8614 case (EVENT_RING_OPCODE_FILTERS_RULES | BXE_STATE_DIAG):
8615 case (EVENT_RING_OPCODE_FILTERS_RULES | BXE_STATE_CLOSING_WAITING_HALT):
8616 BLOGD(sc, DBG_SP, "got rx_mode ramrod\n");
8617 bxe_handle_rx_mode_eqe(sc, elem);
8621 /* unknown event log error and continue */
8622 BLOGE(sc, "Unknown EQ event %d, sc->state 0x%x\n",
8623 elem->message.opcode, sc->state);
8631 atomic_add_acq_long(&sc->eq_spq_left, spqe_cnt);
8633 sc->eq_cons = sw_cons;
8634 sc->eq_prod = sw_prod;
8636 /* make sure that above mem writes were issued towards the memory */
8639 /* update producer */
8640 bxe_update_eq_prod(sc, sc->eq_prod);
8644 bxe_handle_sp_tq(void *context,
8647 struct bxe_softc *sc = (struct bxe_softc *)context;
8650 BLOGD(sc, DBG_SP, "---> SP TASK <---\n");
8652 /* what work needs to be performed? */
8653 status = bxe_update_dsb_idx(sc);
8655 BLOGD(sc, DBG_SP, "dsb status 0x%04x\n", status);
8658 if (status & BXE_DEF_SB_ATT_IDX) {
8659 BLOGD(sc, DBG_SP, "---> ATTN INTR <---\n");
8661 status &= ~BXE_DEF_SB_ATT_IDX;
8664 /* SP events: STAT_QUERY and others */
8665 if (status & BXE_DEF_SB_IDX) {
8666 /* handle EQ completions */
8667 BLOGD(sc, DBG_SP, "---> EQ INTR <---\n");
8669 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID,
8670 le16toh(sc->def_idx), IGU_INT_NOP, 1);
8671 status &= ~BXE_DEF_SB_IDX;
8674 /* if status is non zero then something went wrong */
8675 if (__predict_false(status)) {
8676 BLOGE(sc, "Got an unknown SP interrupt! (0x%04x)\n", status);
8679 /* ack status block only if something was actually handled */
8680 bxe_ack_sb(sc, sc->igu_dsb_id, ATTENTION_ID,
8681 le16toh(sc->def_att_idx), IGU_INT_ENABLE, 1);
8684 * Must be called after the EQ processing (since eq leads to sriov
8685 * ramrod completion flows).
8686 * This flow may have been scheduled by the arrival of a ramrod
8687 * completion, or by the sriov code rescheduling itself.
8689 // XXX bxe_iov_sp_task(sc);
8694 bxe_handle_fp_tq(void *context,
8697 struct bxe_fastpath *fp = (struct bxe_fastpath *)context;
8698 struct bxe_softc *sc = fp->sc;
8699 uint8_t more_tx = FALSE;
8700 uint8_t more_rx = FALSE;
8702 BLOGD(sc, DBG_INTR, "---> FP TASK QUEUE (%d) <---\n", fp->index);
8705 * IFF_DRV_RUNNING state can't be checked here since we process
8706 * slowpath events on a client queue during setup. Instead
8707 * we need to add a "process/continue" flag here that the driver
8708 * can use to tell the task here not to do anything.
8711 if (!(if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING)) {
8716 /* update the fastpath index */
8717 bxe_update_fp_sb_idx(fp);
8719 /* XXX add loop here if ever support multiple tx CoS */
8720 /* fp->txdata[cos] */
8721 if (bxe_has_tx_work(fp)) {
8723 more_tx = bxe_txeof(sc, fp);
8724 BXE_FP_TX_UNLOCK(fp);
8727 if (bxe_has_rx_work(fp)) {
8728 more_rx = bxe_rxeof(sc, fp);
8731 if (more_rx /*|| more_tx*/) {
8732 /* still more work to do */
8733 taskqueue_enqueue(fp->tq, &fp->tq_task);
8737 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID,
8738 le16toh(fp->fp_hc_idx), IGU_INT_ENABLE, 1);
8742 bxe_task_fp(struct bxe_fastpath *fp)
8744 struct bxe_softc *sc = fp->sc;
8745 uint8_t more_tx = FALSE;
8746 uint8_t more_rx = FALSE;
8748 BLOGD(sc, DBG_INTR, "---> FP TASK ISR (%d) <---\n", fp->index);
8750 /* update the fastpath index */
8751 bxe_update_fp_sb_idx(fp);
8753 /* XXX add loop here if ever support multiple tx CoS */
8754 /* fp->txdata[cos] */
8755 if (bxe_has_tx_work(fp)) {
8757 more_tx = bxe_txeof(sc, fp);
8758 BXE_FP_TX_UNLOCK(fp);
8761 if (bxe_has_rx_work(fp)) {
8762 more_rx = bxe_rxeof(sc, fp);
8765 if (more_rx /*|| more_tx*/) {
8766 /* still more work to do, bail out if this ISR and process later */
8767 taskqueue_enqueue(fp->tq, &fp->tq_task);
8772 * Here we write the fastpath index taken before doing any tx or rx work.
8773 * It is very well possible other hw events occurred up to this point and
8774 * they were actually processed accordingly above. Since we're going to
8775 * write an older fastpath index, an interrupt is coming which we might
8776 * not do any work in.
8778 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID,
8779 le16toh(fp->fp_hc_idx), IGU_INT_ENABLE, 1);
8783 * Legacy interrupt entry point.
8785 * Verifies that the controller generated the interrupt and
8786 * then calls a separate routine to handle the various
8787 * interrupt causes: link, RX, and TX.
8790 bxe_intr_legacy(void *xsc)
8792 struct bxe_softc *sc = (struct bxe_softc *)xsc;
8793 struct bxe_fastpath *fp;
8794 uint16_t status, mask;
8797 BLOGD(sc, DBG_INTR, "---> BXE INTx <---\n");
8800 * 0 for ustorm, 1 for cstorm
8801 * the bits returned from ack_int() are 0-15
8802 * bit 0 = attention status block
8803 * bit 1 = fast path status block
8804 * a mask of 0x2 or more = tx/rx event
8805 * a mask of 1 = slow path event
8808 status = bxe_ack_int(sc);
8810 /* the interrupt is not for us */
8811 if (__predict_false(status == 0)) {
8812 BLOGD(sc, DBG_INTR, "Not our interrupt!\n");
8816 BLOGD(sc, DBG_INTR, "Interrupt status 0x%04x\n", status);
8818 FOR_EACH_ETH_QUEUE(sc, i) {
8820 mask = (0x2 << (fp->index + CNIC_SUPPORT(sc)));
8821 if (status & mask) {
8822 /* acknowledge and disable further fastpath interrupts */
8823 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
8829 if (__predict_false(status & 0x1)) {
8830 /* acknowledge and disable further slowpath interrupts */
8831 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
8833 /* schedule slowpath handler */
8834 taskqueue_enqueue(sc->sp_tq, &sc->sp_tq_task);
8839 if (__predict_false(status)) {
8840 BLOGW(sc, "Unexpected fastpath status (0x%08x)!\n", status);
8844 /* slowpath interrupt entry point */
8846 bxe_intr_sp(void *xsc)
8848 struct bxe_softc *sc = (struct bxe_softc *)xsc;
8850 BLOGD(sc, (DBG_INTR | DBG_SP), "---> SP INTR <---\n");
8852 /* acknowledge and disable further slowpath interrupts */
8853 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
8855 /* schedule slowpath handler */
8856 taskqueue_enqueue(sc->sp_tq, &sc->sp_tq_task);
8859 /* fastpath interrupt entry point */
8861 bxe_intr_fp(void *xfp)
8863 struct bxe_fastpath *fp = (struct bxe_fastpath *)xfp;
8864 struct bxe_softc *sc = fp->sc;
8866 BLOGD(sc, DBG_INTR, "---> FP INTR %d <---\n", fp->index);
8869 "(cpu=%d) MSI-X fp=%d fw_sb=%d igu_sb=%d\n",
8870 curcpu, fp->index, fp->fw_sb_id, fp->igu_sb_id);
8872 /* acknowledge and disable further fastpath interrupts */
8873 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
8878 /* Release all interrupts allocated by the driver. */
8880 bxe_interrupt_free(struct bxe_softc *sc)
8884 switch (sc->interrupt_mode) {
8885 case INTR_MODE_INTX:
8886 BLOGD(sc, DBG_LOAD, "Releasing legacy INTx vector\n");
8887 if (sc->intr[0].resource != NULL) {
8888 bus_release_resource(sc->dev,
8891 sc->intr[0].resource);
8895 for (i = 0; i < sc->intr_count; i++) {
8896 BLOGD(sc, DBG_LOAD, "Releasing MSI vector %d\n", i);
8897 if (sc->intr[i].resource && sc->intr[i].rid) {
8898 bus_release_resource(sc->dev,
8901 sc->intr[i].resource);
8904 pci_release_msi(sc->dev);
8906 case INTR_MODE_MSIX:
8907 for (i = 0; i < sc->intr_count; i++) {
8908 BLOGD(sc, DBG_LOAD, "Releasing MSI-X vector %d\n", i);
8909 if (sc->intr[i].resource && sc->intr[i].rid) {
8910 bus_release_resource(sc->dev,
8913 sc->intr[i].resource);
8916 pci_release_msi(sc->dev);
8919 /* nothing to do as initial allocation failed */
8925 * This function determines and allocates the appropriate
8926 * interrupt based on system capabilites and user request.
8928 * The user may force a particular interrupt mode, specify
8929 * the number of receive queues, specify the method for
8930 * distribuitng received frames to receive queues, or use
8931 * the default settings which will automatically select the
8932 * best supported combination. In addition, the OS may or
8933 * may not support certain combinations of these settings.
8934 * This routine attempts to reconcile the settings requested
8935 * by the user with the capabilites available from the system
8936 * to select the optimal combination of features.
8939 * 0 = Success, !0 = Failure.
8942 bxe_interrupt_alloc(struct bxe_softc *sc)
8946 int num_requested = 0;
8947 int num_allocated = 0;
8951 /* get the number of available MSI/MSI-X interrupts from the OS */
8952 if (sc->interrupt_mode > 0) {
8953 if (sc->devinfo.pcie_cap_flags & BXE_MSIX_CAPABLE_FLAG) {
8954 msix_count = pci_msix_count(sc->dev);
8957 if (sc->devinfo.pcie_cap_flags & BXE_MSI_CAPABLE_FLAG) {
8958 msi_count = pci_msi_count(sc->dev);
8961 BLOGD(sc, DBG_LOAD, "%d MSI and %d MSI-X vectors available\n",
8962 msi_count, msix_count);
8965 do { /* try allocating MSI-X interrupt resources (at least 2) */
8966 if (sc->interrupt_mode != INTR_MODE_MSIX) {
8970 if (((sc->devinfo.pcie_cap_flags & BXE_MSIX_CAPABLE_FLAG) == 0) ||
8972 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */
8976 /* ask for the necessary number of MSI-X vectors */
8977 num_requested = min((sc->num_queues + 1), msix_count);
8979 BLOGD(sc, DBG_LOAD, "Requesting %d MSI-X vectors\n", num_requested);
8981 num_allocated = num_requested;
8982 if ((rc = pci_alloc_msix(sc->dev, &num_allocated)) != 0) {
8983 BLOGE(sc, "MSI-X alloc failed! (%d)\n", rc);
8984 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */
8988 if (num_allocated < 2) { /* possible? */
8989 BLOGE(sc, "MSI-X allocation less than 2!\n");
8990 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */
8991 pci_release_msi(sc->dev);
8995 BLOGI(sc, "MSI-X vectors Requested %d and Allocated %d\n",
8996 num_requested, num_allocated);
8998 /* best effort so use the number of vectors allocated to us */
8999 sc->intr_count = num_allocated;
9000 sc->num_queues = num_allocated - 1;
9002 rid = 1; /* initial resource identifier */
9004 /* allocate the MSI-X vectors */
9005 for (i = 0; i < num_allocated; i++) {
9006 sc->intr[i].rid = (rid + i);
9008 if ((sc->intr[i].resource =
9009 bus_alloc_resource_any(sc->dev,
9012 RF_ACTIVE)) == NULL) {
9013 BLOGE(sc, "Failed to map MSI-X[%d] (rid=%d)!\n",
9016 for (j = (i - 1); j >= 0; j--) {
9017 bus_release_resource(sc->dev,
9020 sc->intr[j].resource);
9025 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */
9026 pci_release_msi(sc->dev);
9030 BLOGD(sc, DBG_LOAD, "Mapped MSI-X[%d] (rid=%d)\n", i, (rid + i));
9034 do { /* try allocating MSI vector resources (at least 2) */
9035 if (sc->interrupt_mode != INTR_MODE_MSI) {
9039 if (((sc->devinfo.pcie_cap_flags & BXE_MSI_CAPABLE_FLAG) == 0) ||
9041 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */
9045 /* ask for a single MSI vector */
9048 BLOGD(sc, DBG_LOAD, "Requesting %d MSI vectors\n", num_requested);
9050 num_allocated = num_requested;
9051 if ((rc = pci_alloc_msi(sc->dev, &num_allocated)) != 0) {
9052 BLOGE(sc, "MSI alloc failed (%d)!\n", rc);
9053 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */
9057 if (num_allocated != 1) { /* possible? */
9058 BLOGE(sc, "MSI allocation is not 1!\n");
9059 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */
9060 pci_release_msi(sc->dev);
9064 BLOGI(sc, "MSI vectors Requested %d and Allocated %d\n",
9065 num_requested, num_allocated);
9067 /* best effort so use the number of vectors allocated to us */
9068 sc->intr_count = num_allocated;
9069 sc->num_queues = num_allocated;
9071 rid = 1; /* initial resource identifier */
9073 sc->intr[0].rid = rid;
9075 if ((sc->intr[0].resource =
9076 bus_alloc_resource_any(sc->dev,
9079 RF_ACTIVE)) == NULL) {
9080 BLOGE(sc, "Failed to map MSI[0] (rid=%d)!\n", rid);
9083 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */
9084 pci_release_msi(sc->dev);
9088 BLOGD(sc, DBG_LOAD, "Mapped MSI[0] (rid=%d)\n", rid);
9091 do { /* try allocating INTx vector resources */
9092 if (sc->interrupt_mode != INTR_MODE_INTX) {
9096 BLOGD(sc, DBG_LOAD, "Requesting legacy INTx interrupt\n");
9098 /* only one vector for INTx */
9102 rid = 0; /* initial resource identifier */
9104 sc->intr[0].rid = rid;
9106 if ((sc->intr[0].resource =
9107 bus_alloc_resource_any(sc->dev,
9110 (RF_ACTIVE | RF_SHAREABLE))) == NULL) {
9111 BLOGE(sc, "Failed to map INTx (rid=%d)!\n", rid);
9114 sc->interrupt_mode = -1; /* Failed! */
9118 BLOGD(sc, DBG_LOAD, "Mapped INTx (rid=%d)\n", rid);
9121 if (sc->interrupt_mode == -1) {
9122 BLOGE(sc, "Interrupt Allocation: FAILED!!!\n");
9126 "Interrupt Allocation: interrupt_mode=%d, num_queues=%d\n",
9127 sc->interrupt_mode, sc->num_queues);
9135 bxe_interrupt_detach(struct bxe_softc *sc)
9137 struct bxe_fastpath *fp;
9140 /* release interrupt resources */
9141 for (i = 0; i < sc->intr_count; i++) {
9142 if (sc->intr[i].resource && sc->intr[i].tag) {
9143 BLOGD(sc, DBG_LOAD, "Disabling interrupt vector %d\n", i);
9144 bus_teardown_intr(sc->dev, sc->intr[i].resource, sc->intr[i].tag);
9148 for (i = 0; i < sc->num_queues; i++) {
9151 taskqueue_drain(fp->tq, &fp->tq_task);
9152 taskqueue_drain(fp->tq, &fp->tx_task);
9153 while (taskqueue_cancel_timeout(fp->tq, &fp->tx_timeout_task,
9155 taskqueue_drain_timeout(fp->tq, &fp->tx_timeout_task);
9158 for (i = 0; i < sc->num_queues; i++) {
9160 if (fp->tq != NULL) {
9161 taskqueue_free(fp->tq);
9168 taskqueue_drain(sc->sp_tq, &sc->sp_tq_task);
9169 taskqueue_free(sc->sp_tq);
9175 * Enables interrupts and attach to the ISR.
9177 * When using multiple MSI/MSI-X vectors the first vector
9178 * is used for slowpath operations while all remaining
9179 * vectors are used for fastpath operations. If only a
9180 * single MSI/MSI-X vector is used (SINGLE_ISR) then the
9181 * ISR must look for both slowpath and fastpath completions.
9184 bxe_interrupt_attach(struct bxe_softc *sc)
9186 struct bxe_fastpath *fp;
9190 snprintf(sc->sp_tq_name, sizeof(sc->sp_tq_name),
9191 "bxe%d_sp_tq", sc->unit);
9192 TASK_INIT(&sc->sp_tq_task, 0, bxe_handle_sp_tq, sc);
9193 sc->sp_tq = taskqueue_create(sc->sp_tq_name, M_NOWAIT,
9194 taskqueue_thread_enqueue,
9196 taskqueue_start_threads(&sc->sp_tq, 1, PWAIT, /* lower priority */
9197 "%s", sc->sp_tq_name);
9200 for (i = 0; i < sc->num_queues; i++) {
9202 snprintf(fp->tq_name, sizeof(fp->tq_name),
9203 "bxe%d_fp%d_tq", sc->unit, i);
9204 NET_TASK_INIT(&fp->tq_task, 0, bxe_handle_fp_tq, fp);
9205 TASK_INIT(&fp->tx_task, 0, bxe_tx_mq_start_deferred, fp);
9206 fp->tq = taskqueue_create(fp->tq_name, M_NOWAIT,
9207 taskqueue_thread_enqueue,
9209 TIMEOUT_TASK_INIT(fp->tq, &fp->tx_timeout_task, 0,
9210 bxe_tx_mq_start_deferred, fp);
9211 taskqueue_start_threads(&fp->tq, 1, PI_NET, /* higher priority */
9215 /* setup interrupt handlers */
9216 if (sc->interrupt_mode == INTR_MODE_MSIX) {
9217 BLOGD(sc, DBG_LOAD, "Enabling slowpath MSI-X[0] vector\n");
9220 * Setup the interrupt handler. Note that we pass the driver instance
9221 * to the interrupt handler for the slowpath.
9223 if ((rc = bus_setup_intr(sc->dev, sc->intr[0].resource,
9224 (INTR_TYPE_NET | INTR_MPSAFE),
9225 NULL, bxe_intr_sp, sc,
9226 &sc->intr[0].tag)) != 0) {
9227 BLOGE(sc, "Failed to allocate MSI-X[0] vector (%d)\n", rc);
9228 goto bxe_interrupt_attach_exit;
9231 bus_describe_intr(sc->dev, sc->intr[0].resource,
9232 sc->intr[0].tag, "sp");
9234 /* bus_bind_intr(sc->dev, sc->intr[0].resource, 0); */
9236 /* initialize the fastpath vectors (note the first was used for sp) */
9237 for (i = 0; i < sc->num_queues; i++) {
9239 BLOGD(sc, DBG_LOAD, "Enabling MSI-X[%d] vector\n", (i + 1));
9242 * Setup the interrupt handler. Note that we pass the
9243 * fastpath context to the interrupt handler in this
9246 if ((rc = bus_setup_intr(sc->dev, sc->intr[i + 1].resource,
9247 (INTR_TYPE_NET | INTR_MPSAFE),
9248 NULL, bxe_intr_fp, fp,
9249 &sc->intr[i + 1].tag)) != 0) {
9250 BLOGE(sc, "Failed to allocate MSI-X[%d] vector (%d)\n",
9252 goto bxe_interrupt_attach_exit;
9255 bus_describe_intr(sc->dev, sc->intr[i + 1].resource,
9256 sc->intr[i + 1].tag, "fp%02d", i);
9258 /* bind the fastpath instance to a cpu */
9259 if (sc->num_queues > 1) {
9260 bus_bind_intr(sc->dev, sc->intr[i + 1].resource, i);
9263 fp->state = BXE_FP_STATE_IRQ;
9265 } else if (sc->interrupt_mode == INTR_MODE_MSI) {
9266 BLOGD(sc, DBG_LOAD, "Enabling MSI[0] vector\n");
9269 * Setup the interrupt handler. Note that we pass the
9270 * driver instance to the interrupt handler which
9271 * will handle both the slowpath and fastpath.
9273 if ((rc = bus_setup_intr(sc->dev, sc->intr[0].resource,
9274 (INTR_TYPE_NET | INTR_MPSAFE),
9275 NULL, bxe_intr_legacy, sc,
9276 &sc->intr[0].tag)) != 0) {
9277 BLOGE(sc, "Failed to allocate MSI[0] vector (%d)\n", rc);
9278 goto bxe_interrupt_attach_exit;
9281 } else { /* (sc->interrupt_mode == INTR_MODE_INTX) */
9282 BLOGD(sc, DBG_LOAD, "Enabling INTx interrupts\n");
9285 * Setup the interrupt handler. Note that we pass the
9286 * driver instance to the interrupt handler which
9287 * will handle both the slowpath and fastpath.
9289 if ((rc = bus_setup_intr(sc->dev, sc->intr[0].resource,
9290 (INTR_TYPE_NET | INTR_MPSAFE),
9291 NULL, bxe_intr_legacy, sc,
9292 &sc->intr[0].tag)) != 0) {
9293 BLOGE(sc, "Failed to allocate INTx interrupt (%d)\n", rc);
9294 goto bxe_interrupt_attach_exit;
9298 bxe_interrupt_attach_exit:
9303 static int bxe_init_hw_common_chip(struct bxe_softc *sc);
9304 static int bxe_init_hw_common(struct bxe_softc *sc);
9305 static int bxe_init_hw_port(struct bxe_softc *sc);
9306 static int bxe_init_hw_func(struct bxe_softc *sc);
9307 static void bxe_reset_common(struct bxe_softc *sc);
9308 static void bxe_reset_port(struct bxe_softc *sc);
9309 static void bxe_reset_func(struct bxe_softc *sc);
9310 static int bxe_gunzip_init(struct bxe_softc *sc);
9311 static void bxe_gunzip_end(struct bxe_softc *sc);
9312 static int bxe_init_firmware(struct bxe_softc *sc);
9313 static void bxe_release_firmware(struct bxe_softc *sc);
9316 ecore_func_sp_drv_ops bxe_func_sp_drv = {
9317 .init_hw_cmn_chip = bxe_init_hw_common_chip,
9318 .init_hw_cmn = bxe_init_hw_common,
9319 .init_hw_port = bxe_init_hw_port,
9320 .init_hw_func = bxe_init_hw_func,
9322 .reset_hw_cmn = bxe_reset_common,
9323 .reset_hw_port = bxe_reset_port,
9324 .reset_hw_func = bxe_reset_func,
9326 .gunzip_init = bxe_gunzip_init,
9327 .gunzip_end = bxe_gunzip_end,
9329 .init_fw = bxe_init_firmware,
9330 .release_fw = bxe_release_firmware,
9334 bxe_init_func_obj(struct bxe_softc *sc)
9338 ecore_init_func_obj(sc,
9340 BXE_SP(sc, func_rdata),
9341 BXE_SP_MAPPING(sc, func_rdata),
9342 BXE_SP(sc, func_afex_rdata),
9343 BXE_SP_MAPPING(sc, func_afex_rdata),
9348 bxe_init_hw(struct bxe_softc *sc,
9351 struct ecore_func_state_params func_params = { NULL };
9354 /* prepare the parameters for function state transitions */
9355 bit_set(&func_params.ramrod_flags, RAMROD_COMP_WAIT);
9357 func_params.f_obj = &sc->func_obj;
9358 func_params.cmd = ECORE_F_CMD_HW_INIT;
9360 func_params.params.hw_init.load_phase = load_code;
9363 * Via a plethora of function pointers, we will eventually reach
9364 * bxe_init_hw_common(), bxe_init_hw_port(), or bxe_init_hw_func().
9366 rc = ecore_func_state_change(sc, &func_params);
9372 bxe_fill(struct bxe_softc *sc,
9379 if (!(len % 4) && !(addr % 4)) {
9380 for (i = 0; i < len; i += 4) {
9381 REG_WR(sc, (addr + i), fill);
9384 for (i = 0; i < len; i++) {
9385 REG_WR8(sc, (addr + i), fill);
9390 /* writes FP SP data to FW - data_size in dwords */
9392 bxe_wr_fp_sb_data(struct bxe_softc *sc,
9394 uint32_t *sb_data_p,
9399 for (index = 0; index < data_size; index++) {
9401 (BAR_CSTRORM_INTMEM +
9402 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
9403 (sizeof(uint32_t) * index)),
9404 *(sb_data_p + index));
9409 bxe_zero_fp_sb(struct bxe_softc *sc,
9412 struct hc_status_block_data_e2 sb_data_e2;
9413 struct hc_status_block_data_e1x sb_data_e1x;
9414 uint32_t *sb_data_p;
9415 uint32_t data_size = 0;
9417 if (!CHIP_IS_E1x(sc)) {
9418 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
9419 sb_data_e2.common.state = SB_DISABLED;
9420 sb_data_e2.common.p_func.vf_valid = FALSE;
9421 sb_data_p = (uint32_t *)&sb_data_e2;
9422 data_size = (sizeof(struct hc_status_block_data_e2) /
9425 memset(&sb_data_e1x, 0, sizeof(struct hc_status_block_data_e1x));
9426 sb_data_e1x.common.state = SB_DISABLED;
9427 sb_data_e1x.common.p_func.vf_valid = FALSE;
9428 sb_data_p = (uint32_t *)&sb_data_e1x;
9429 data_size = (sizeof(struct hc_status_block_data_e1x) /
9433 bxe_wr_fp_sb_data(sc, fw_sb_id, sb_data_p, data_size);
9435 bxe_fill(sc, (BAR_CSTRORM_INTMEM + CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id)),
9436 0, CSTORM_STATUS_BLOCK_SIZE);
9437 bxe_fill(sc, (BAR_CSTRORM_INTMEM + CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id)),
9438 0, CSTORM_SYNC_BLOCK_SIZE);
9442 bxe_wr_sp_sb_data(struct bxe_softc *sc,
9443 struct hc_sp_status_block_data *sp_sb_data)
9448 i < (sizeof(struct hc_sp_status_block_data) / sizeof(uint32_t));
9451 (BAR_CSTRORM_INTMEM +
9452 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(SC_FUNC(sc)) +
9453 (i * sizeof(uint32_t))),
9454 *((uint32_t *)sp_sb_data + i));
9459 bxe_zero_sp_sb(struct bxe_softc *sc)
9461 struct hc_sp_status_block_data sp_sb_data;
9463 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
9465 sp_sb_data.state = SB_DISABLED;
9466 sp_sb_data.p_func.vf_valid = FALSE;
9468 bxe_wr_sp_sb_data(sc, &sp_sb_data);
9471 (BAR_CSTRORM_INTMEM +
9472 CSTORM_SP_STATUS_BLOCK_OFFSET(SC_FUNC(sc))),
9473 0, CSTORM_SP_STATUS_BLOCK_SIZE);
9475 (BAR_CSTRORM_INTMEM +
9476 CSTORM_SP_SYNC_BLOCK_OFFSET(SC_FUNC(sc))),
9477 0, CSTORM_SP_SYNC_BLOCK_SIZE);
9481 bxe_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
9485 hc_sm->igu_sb_id = igu_sb_id;
9486 hc_sm->igu_seg_id = igu_seg_id;
9487 hc_sm->timer_value = 0xFF;
9488 hc_sm->time_to_expire = 0xFFFFFFFF;
9492 bxe_map_sb_state_machines(struct hc_index_data *index_data)
9494 /* zero out state machine indices */
9497 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
9500 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
9501 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
9502 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
9503 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
9508 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
9509 (SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9512 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
9513 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9514 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
9515 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9516 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
9517 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9518 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
9519 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
9523 bxe_init_sb(struct bxe_softc *sc,
9530 struct hc_status_block_data_e2 sb_data_e2;
9531 struct hc_status_block_data_e1x sb_data_e1x;
9532 struct hc_status_block_sm *hc_sm_p;
9533 uint32_t *sb_data_p;
9537 if (CHIP_INT_MODE_IS_BC(sc)) {
9538 igu_seg_id = HC_SEG_ACCESS_NORM;
9540 igu_seg_id = IGU_SEG_ACCESS_NORM;
9543 bxe_zero_fp_sb(sc, fw_sb_id);
9545 if (!CHIP_IS_E1x(sc)) {
9546 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
9547 sb_data_e2.common.state = SB_ENABLED;
9548 sb_data_e2.common.p_func.pf_id = SC_FUNC(sc);
9549 sb_data_e2.common.p_func.vf_id = vfid;
9550 sb_data_e2.common.p_func.vf_valid = vf_valid;
9551 sb_data_e2.common.p_func.vnic_id = SC_VN(sc);
9552 sb_data_e2.common.same_igu_sb_1b = TRUE;
9553 sb_data_e2.common.host_sb_addr.hi = U64_HI(busaddr);
9554 sb_data_e2.common.host_sb_addr.lo = U64_LO(busaddr);
9555 hc_sm_p = sb_data_e2.common.state_machine;
9556 sb_data_p = (uint32_t *)&sb_data_e2;
9557 data_size = (sizeof(struct hc_status_block_data_e2) /
9559 bxe_map_sb_state_machines(sb_data_e2.index_data);
9561 memset(&sb_data_e1x, 0, sizeof(struct hc_status_block_data_e1x));
9562 sb_data_e1x.common.state = SB_ENABLED;
9563 sb_data_e1x.common.p_func.pf_id = SC_FUNC(sc);
9564 sb_data_e1x.common.p_func.vf_id = 0xff;
9565 sb_data_e1x.common.p_func.vf_valid = FALSE;
9566 sb_data_e1x.common.p_func.vnic_id = SC_VN(sc);
9567 sb_data_e1x.common.same_igu_sb_1b = TRUE;
9568 sb_data_e1x.common.host_sb_addr.hi = U64_HI(busaddr);
9569 sb_data_e1x.common.host_sb_addr.lo = U64_LO(busaddr);
9570 hc_sm_p = sb_data_e1x.common.state_machine;
9571 sb_data_p = (uint32_t *)&sb_data_e1x;
9572 data_size = (sizeof(struct hc_status_block_data_e1x) /
9574 bxe_map_sb_state_machines(sb_data_e1x.index_data);
9577 bxe_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID], igu_sb_id, igu_seg_id);
9578 bxe_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID], igu_sb_id, igu_seg_id);
9580 BLOGD(sc, DBG_LOAD, "Init FW SB %d\n", fw_sb_id);
9582 /* write indices to HW - PCI guarantees endianity of regpairs */
9583 bxe_wr_fp_sb_data(sc, fw_sb_id, sb_data_p, data_size);
9586 static inline uint8_t
9587 bxe_fp_qzone_id(struct bxe_fastpath *fp)
9589 if (CHIP_IS_E1x(fp->sc)) {
9590 return (fp->cl_id + SC_PORT(fp->sc) * ETH_MAX_RX_CLIENTS_E1H);
9596 static inline uint32_t
9597 bxe_rx_ustorm_prods_offset(struct bxe_softc *sc,
9598 struct bxe_fastpath *fp)
9600 uint32_t offset = BAR_USTRORM_INTMEM;
9602 if (!CHIP_IS_E1x(sc)) {
9603 offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
9605 offset += USTORM_RX_PRODS_E1X_OFFSET(SC_PORT(sc), fp->cl_id);
9612 bxe_init_eth_fp(struct bxe_softc *sc,
9615 struct bxe_fastpath *fp = &sc->fp[idx];
9616 uint32_t cids[ECORE_MULTI_TX_COS] = { 0 };
9617 unsigned long q_type = 0;
9623 fp->igu_sb_id = (sc->igu_base_sb + idx + CNIC_SUPPORT(sc));
9624 fp->fw_sb_id = (sc->base_fw_ndsb + idx + CNIC_SUPPORT(sc));
9626 fp->cl_id = (CHIP_IS_E1x(sc)) ?
9627 (SC_L_ID(sc) + idx) :
9628 /* want client ID same as IGU SB ID for non-E1 */
9630 fp->cl_qzone_id = bxe_fp_qzone_id(fp);
9632 /* setup sb indices */
9633 if (!CHIP_IS_E1x(sc)) {
9634 fp->sb_index_values = fp->status_block.e2_sb->sb.index_values;
9635 fp->sb_running_index = fp->status_block.e2_sb->sb.running_index;
9637 fp->sb_index_values = fp->status_block.e1x_sb->sb.index_values;
9638 fp->sb_running_index = fp->status_block.e1x_sb->sb.running_index;
9642 fp->ustorm_rx_prods_offset = bxe_rx_ustorm_prods_offset(sc, fp);
9644 fp->rx_cq_cons_sb = &fp->sb_index_values[HC_INDEX_ETH_RX_CQ_CONS];
9647 * XXX If multiple CoS is ever supported then each fastpath structure
9648 * will need to maintain tx producer/consumer/dma/etc values *per* CoS.
9650 for (cos = 0; cos < sc->max_cos; cos++) {
9653 fp->tx_cons_sb = &fp->sb_index_values[HC_INDEX_ETH_TX_CQ_CONS_COS0];
9655 /* nothing more for a VF to do */
9660 bxe_init_sb(sc, fp->sb_dma.paddr, BXE_VF_ID_INVALID, FALSE,
9661 fp->fw_sb_id, fp->igu_sb_id);
9663 bxe_update_fp_sb_idx(fp);
9665 /* Configure Queue State object */
9666 bit_set(&q_type, ECORE_Q_TYPE_HAS_RX);
9667 bit_set(&q_type, ECORE_Q_TYPE_HAS_TX);
9669 ecore_init_queue_obj(sc,
9670 &sc->sp_objs[idx].q_obj,
9675 BXE_SP(sc, q_rdata),
9676 BXE_SP_MAPPING(sc, q_rdata),
9679 /* configure classification DBs */
9680 ecore_init_mac_obj(sc,
9681 &sc->sp_objs[idx].mac_obj,
9685 BXE_SP(sc, mac_rdata),
9686 BXE_SP_MAPPING(sc, mac_rdata),
9687 ECORE_FILTER_MAC_PENDING,
9689 ECORE_OBJ_TYPE_RX_TX,
9692 BLOGD(sc, DBG_LOAD, "fp[%d]: sb=%p cl_id=%d fw_sb=%d igu_sb=%d\n",
9693 idx, fp->status_block.e2_sb, fp->cl_id, fp->fw_sb_id, fp->igu_sb_id);
9697 bxe_update_rx_prod(struct bxe_softc *sc,
9698 struct bxe_fastpath *fp,
9699 uint16_t rx_bd_prod,
9700 uint16_t rx_cq_prod,
9701 uint16_t rx_sge_prod)
9703 struct ustorm_eth_rx_producers rx_prods = { 0 };
9706 /* update producers */
9707 rx_prods.bd_prod = rx_bd_prod;
9708 rx_prods.cqe_prod = rx_cq_prod;
9709 rx_prods.sge_prod = rx_sge_prod;
9712 * Make sure that the BD and SGE data is updated before updating the
9713 * producers since FW might read the BD/SGE right after the producer
9715 * This is only applicable for weak-ordered memory model archs such
9716 * as IA-64. The following barrier is also mandatory since FW will
9717 * assumes BDs must have buffers.
9721 for (i = 0; i < (sizeof(rx_prods) / 4); i++) {
9723 (fp->ustorm_rx_prods_offset + (i * 4)),
9724 ((uint32_t *)&rx_prods)[i]);
9727 wmb(); /* keep prod updates ordered */
9730 "RX fp[%d]: wrote prods bd_prod=%u cqe_prod=%u sge_prod=%u\n",
9731 fp->index, rx_bd_prod, rx_cq_prod, rx_sge_prod);
9735 bxe_init_rx_rings(struct bxe_softc *sc)
9737 struct bxe_fastpath *fp;
9740 for (i = 0; i < sc->num_queues; i++) {
9746 * Activate the BD ring...
9747 * Warning, this will generate an interrupt (to the TSTORM)
9748 * so this can only be done after the chip is initialized
9750 bxe_update_rx_prod(sc, fp,
9759 if (CHIP_IS_E1(sc)) {
9761 (BAR_USTRORM_INTMEM +
9762 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(SC_FUNC(sc))),
9763 U64_LO(fp->rcq_dma.paddr));
9765 (BAR_USTRORM_INTMEM +
9766 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(SC_FUNC(sc)) + 4),
9767 U64_HI(fp->rcq_dma.paddr));
9773 bxe_init_tx_ring_one(struct bxe_fastpath *fp)
9775 SET_FLAG(fp->tx_db.data.header.data, DOORBELL_HDR_T_DB_TYPE, 1);
9776 fp->tx_db.data.zero_fill1 = 0;
9777 fp->tx_db.data.prod = 0;
9779 fp->tx_pkt_prod = 0;
9780 fp->tx_pkt_cons = 0;
9783 fp->eth_q_stats.tx_pkts = 0;
9787 bxe_init_tx_rings(struct bxe_softc *sc)
9791 for (i = 0; i < sc->num_queues; i++) {
9792 bxe_init_tx_ring_one(&sc->fp[i]);
9797 bxe_init_def_sb(struct bxe_softc *sc)
9799 struct host_sp_status_block *def_sb = sc->def_sb;
9800 bus_addr_t mapping = sc->def_sb_dma.paddr;
9801 int igu_sp_sb_index;
9803 int port = SC_PORT(sc);
9804 int func = SC_FUNC(sc);
9805 int reg_offset, reg_offset_en5;
9808 struct hc_sp_status_block_data sp_sb_data;
9810 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
9812 if (CHIP_INT_MODE_IS_BC(sc)) {
9813 igu_sp_sb_index = DEF_SB_IGU_ID;
9814 igu_seg_id = HC_SEG_ACCESS_DEF;
9816 igu_sp_sb_index = sc->igu_dsb_id;
9817 igu_seg_id = IGU_SEG_ACCESS_DEF;
9821 section = ((uint64_t)mapping +
9822 offsetof(struct host_sp_status_block, atten_status_block));
9823 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
9826 reg_offset = (port) ?
9827 MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
9828 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
9829 reg_offset_en5 = (port) ?
9830 MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
9831 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0;
9833 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
9834 /* take care of sig[0]..sig[4] */
9835 for (sindex = 0; sindex < 4; sindex++) {
9836 sc->attn_group[index].sig[sindex] =
9837 REG_RD(sc, (reg_offset + (sindex * 0x4) + (0x10 * index)));
9840 if (!CHIP_IS_E1x(sc)) {
9842 * enable5 is separate from the rest of the registers,
9843 * and the address skip is 4 and not 16 between the
9846 sc->attn_group[index].sig[4] =
9847 REG_RD(sc, (reg_offset_en5 + (0x4 * index)));
9849 sc->attn_group[index].sig[4] = 0;
9853 if (sc->devinfo.int_block == INT_BLOCK_HC) {
9854 reg_offset = (port) ?
9855 HC_REG_ATTN_MSG1_ADDR_L :
9856 HC_REG_ATTN_MSG0_ADDR_L;
9857 REG_WR(sc, reg_offset, U64_LO(section));
9858 REG_WR(sc, (reg_offset + 4), U64_HI(section));
9859 } else if (!CHIP_IS_E1x(sc)) {
9860 REG_WR(sc, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
9861 REG_WR(sc, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
9864 section = ((uint64_t)mapping +
9865 offsetof(struct host_sp_status_block, sp_sb));
9869 /* PCI guarantees endianity of regpair */
9870 sp_sb_data.state = SB_ENABLED;
9871 sp_sb_data.host_sb_addr.lo = U64_LO(section);
9872 sp_sb_data.host_sb_addr.hi = U64_HI(section);
9873 sp_sb_data.igu_sb_id = igu_sp_sb_index;
9874 sp_sb_data.igu_seg_id = igu_seg_id;
9875 sp_sb_data.p_func.pf_id = func;
9876 sp_sb_data.p_func.vnic_id = SC_VN(sc);
9877 sp_sb_data.p_func.vf_id = 0xff;
9879 bxe_wr_sp_sb_data(sc, &sp_sb_data);
9881 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
9885 bxe_init_sp_ring(struct bxe_softc *sc)
9887 atomic_store_rel_long(&sc->cq_spq_left, MAX_SPQ_PENDING);
9888 sc->spq_prod_idx = 0;
9889 sc->dsb_sp_prod = &sc->def_sb->sp_sb.index_values[HC_SP_INDEX_ETH_DEF_CONS];
9890 sc->spq_prod_bd = sc->spq;
9891 sc->spq_last_bd = (sc->spq_prod_bd + MAX_SP_DESC_CNT);
9895 bxe_init_eq_ring(struct bxe_softc *sc)
9897 union event_ring_elem *elem;
9900 for (i = 1; i <= NUM_EQ_PAGES; i++) {
9901 elem = &sc->eq[EQ_DESC_CNT_PAGE * i - 1];
9903 elem->next_page.addr.hi = htole32(U64_HI(sc->eq_dma.paddr +
9905 (i % NUM_EQ_PAGES)));
9906 elem->next_page.addr.lo = htole32(U64_LO(sc->eq_dma.paddr +
9908 (i % NUM_EQ_PAGES)));
9912 sc->eq_prod = NUM_EQ_DESC;
9913 sc->eq_cons_sb = &sc->def_sb->sp_sb.index_values[HC_SP_INDEX_EQ_CONS];
9915 atomic_store_rel_long(&sc->eq_spq_left,
9916 (min((MAX_SP_DESC_CNT - MAX_SPQ_PENDING),
9921 bxe_init_internal_common(struct bxe_softc *sc)
9926 * Zero this manually as its initialization is currently missing
9929 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++) {
9931 (BAR_USTRORM_INTMEM + USTORM_AGG_DATA_OFFSET + (i * 4)),
9935 if (!CHIP_IS_E1x(sc)) {
9936 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET),
9937 CHIP_INT_MODE_IS_BC(sc) ? HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
9942 bxe_init_internal(struct bxe_softc *sc,
9945 switch (load_code) {
9946 case FW_MSG_CODE_DRV_LOAD_COMMON:
9947 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
9948 bxe_init_internal_common(sc);
9951 case FW_MSG_CODE_DRV_LOAD_PORT:
9955 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
9956 /* internal memory per function is initialized inside bxe_pf_init */
9960 BLOGE(sc, "Unknown load_code (0x%x) from MCP\n", load_code);
9966 storm_memset_func_cfg(struct bxe_softc *sc,
9967 struct tstorm_eth_function_common_config *tcfg,
9973 addr = (BAR_TSTRORM_INTMEM +
9974 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid));
9975 size = sizeof(struct tstorm_eth_function_common_config);
9976 ecore_storm_memset_struct(sc, addr, size, (uint32_t *)tcfg);
9980 bxe_func_init(struct bxe_softc *sc,
9981 struct bxe_func_init_params *p)
9983 struct tstorm_eth_function_common_config tcfg = { 0 };
9985 if (CHIP_IS_E1x(sc)) {
9986 storm_memset_func_cfg(sc, &tcfg, p->func_id);
9989 /* Enable the function in the FW */
9990 storm_memset_vf_to_pf(sc, p->func_id, p->pf_id);
9991 storm_memset_func_en(sc, p->func_id, 1);
9994 if (p->func_flgs & FUNC_FLG_SPQ) {
9995 storm_memset_spq_addr(sc, p->spq_map, p->func_id);
9997 (XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PROD_OFFSET(p->func_id)),
10003 * Calculates the sum of vn_min_rates.
10004 * It's needed for further normalizing of the min_rates.
10006 * sum of vn_min_rates.
10008 * 0 - if all the min_rates are 0.
10009 * In the later case fainess algorithm should be deactivated.
10010 * If all min rates are not zero then those that are zeroes will be set to 1.
10013 bxe_calc_vn_min(struct bxe_softc *sc,
10014 struct cmng_init_input *input)
10017 uint32_t vn_min_rate;
10021 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
10022 vn_cfg = sc->devinfo.mf_info.mf_config[vn];
10023 vn_min_rate = (((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
10024 FUNC_MF_CFG_MIN_BW_SHIFT) * 100);
10026 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
10027 /* skip hidden VNs */
10029 } else if (!vn_min_rate) {
10030 /* If min rate is zero - set it to 100 */
10031 vn_min_rate = DEF_MIN_RATE;
10036 input->vnic_min_rate[vn] = vn_min_rate;
10039 /* if ETS or all min rates are zeros - disable fairness */
10040 if (BXE_IS_ETS_ENABLED(sc)) {
10041 input->flags.cmng_enables &= ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
10042 BLOGD(sc, DBG_LOAD, "Fairness disabled (ETS)\n");
10043 } else if (all_zero) {
10044 input->flags.cmng_enables &= ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
10045 BLOGD(sc, DBG_LOAD,
10046 "Fariness disabled (all MIN values are zeroes)\n");
10048 input->flags.cmng_enables |= CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
10052 static inline uint16_t
10053 bxe_extract_max_cfg(struct bxe_softc *sc,
10056 uint16_t max_cfg = ((mf_cfg & FUNC_MF_CFG_MAX_BW_MASK) >>
10057 FUNC_MF_CFG_MAX_BW_SHIFT);
10060 BLOGD(sc, DBG_LOAD, "Max BW configured to 0 - using 100 instead\n");
10068 bxe_calc_vn_max(struct bxe_softc *sc,
10070 struct cmng_init_input *input)
10072 uint16_t vn_max_rate;
10073 uint32_t vn_cfg = sc->devinfo.mf_info.mf_config[vn];
10076 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
10079 max_cfg = bxe_extract_max_cfg(sc, vn_cfg);
10081 if (IS_MF_SI(sc)) {
10082 /* max_cfg in percents of linkspeed */
10083 vn_max_rate = ((sc->link_vars.line_speed * max_cfg) / 100);
10084 } else { /* SD modes */
10085 /* max_cfg is absolute in 100Mb units */
10086 vn_max_rate = (max_cfg * 100);
10090 BLOGD(sc, DBG_LOAD, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
10092 input->vnic_max_rate[vn] = vn_max_rate;
10096 bxe_cmng_fns_init(struct bxe_softc *sc,
10100 struct cmng_init_input input;
10103 memset(&input, 0, sizeof(struct cmng_init_input));
10105 input.port_rate = sc->link_vars.line_speed;
10107 if (cmng_type == CMNG_FNS_MINMAX) {
10108 /* read mf conf from shmem */
10110 bxe_read_mf_cfg(sc);
10113 /* get VN min rate and enable fairness if not 0 */
10114 bxe_calc_vn_min(sc, &input);
10116 /* get VN max rate */
10117 if (sc->port.pmf) {
10118 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
10119 bxe_calc_vn_max(sc, vn, &input);
10123 /* always enable rate shaping and fairness */
10124 input.flags.cmng_enables |= CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
10126 ecore_init_cmng(&input, &sc->cmng);
10130 /* rate shaping and fairness are disabled */
10131 BLOGD(sc, DBG_LOAD, "rate shaping and fairness have been disabled\n");
10135 bxe_get_cmng_fns_mode(struct bxe_softc *sc)
10137 if (CHIP_REV_IS_SLOW(sc)) {
10138 return (CMNG_FNS_NONE);
10142 return (CMNG_FNS_MINMAX);
10145 return (CMNG_FNS_NONE);
10149 storm_memset_cmng(struct bxe_softc *sc,
10150 struct cmng_init *cmng,
10158 addr = (BAR_XSTRORM_INTMEM +
10159 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port));
10160 size = sizeof(struct cmng_struct_per_port);
10161 ecore_storm_memset_struct(sc, addr, size, (uint32_t *)&cmng->port);
10163 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
10164 func = func_by_vn(sc, vn);
10166 addr = (BAR_XSTRORM_INTMEM +
10167 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func));
10168 size = sizeof(struct rate_shaping_vars_per_vn);
10169 ecore_storm_memset_struct(sc, addr, size,
10170 (uint32_t *)&cmng->vnic.vnic_max_rate[vn]);
10172 addr = (BAR_XSTRORM_INTMEM +
10173 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func));
10174 size = sizeof(struct fairness_vars_per_vn);
10175 ecore_storm_memset_struct(sc, addr, size,
10176 (uint32_t *)&cmng->vnic.vnic_min_rate[vn]);
10181 bxe_pf_init(struct bxe_softc *sc)
10183 struct bxe_func_init_params func_init = { 0 };
10184 struct event_ring_data eq_data = { { 0 } };
10187 if (!CHIP_IS_E1x(sc)) {
10188 /* reset IGU PF statistics: MSIX + ATTN */
10191 (IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
10192 (BXE_IGU_STAS_MSG_VF_CNT * 4) +
10193 ((CHIP_IS_MODE_4_PORT(sc) ? SC_FUNC(sc) : SC_VN(sc)) * 4)),
10197 (IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
10198 (BXE_IGU_STAS_MSG_VF_CNT * 4) +
10199 (BXE_IGU_STAS_MSG_PF_CNT * 4) +
10200 ((CHIP_IS_MODE_4_PORT(sc) ? SC_FUNC(sc) : SC_VN(sc)) * 4)),
10204 /* function setup flags */
10205 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
10208 * This flag is relevant for E1x only.
10209 * E2 doesn't have a TPA configuration in a function level.
10211 flags |= (if_getcapenable(sc->ifp) & IFCAP_LRO) ? FUNC_FLG_TPA : 0;
10213 func_init.func_flgs = flags;
10214 func_init.pf_id = SC_FUNC(sc);
10215 func_init.func_id = SC_FUNC(sc);
10216 func_init.spq_map = sc->spq_dma.paddr;
10217 func_init.spq_prod = sc->spq_prod_idx;
10219 bxe_func_init(sc, &func_init);
10221 memset(&sc->cmng, 0, sizeof(struct cmng_struct_per_port));
10224 * Congestion management values depend on the link rate.
10225 * There is no active link so initial link rate is set to 10Gbps.
10226 * When the link comes up the congestion management values are
10227 * re-calculated according to the actual link rate.
10229 sc->link_vars.line_speed = SPEED_10000;
10230 bxe_cmng_fns_init(sc, TRUE, bxe_get_cmng_fns_mode(sc));
10232 /* Only the PMF sets the HW */
10233 if (sc->port.pmf) {
10234 storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc));
10237 /* init Event Queue - PCI bus guarantees correct endainity */
10238 eq_data.base_addr.hi = U64_HI(sc->eq_dma.paddr);
10239 eq_data.base_addr.lo = U64_LO(sc->eq_dma.paddr);
10240 eq_data.producer = sc->eq_prod;
10241 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
10242 eq_data.sb_id = DEF_SB_ID;
10243 storm_memset_eq_data(sc, &eq_data, SC_FUNC(sc));
10247 bxe_hc_int_enable(struct bxe_softc *sc)
10249 int port = SC_PORT(sc);
10250 uint32_t addr = (port) ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
10251 uint32_t val = REG_RD(sc, addr);
10252 uint8_t msix = (sc->interrupt_mode == INTR_MODE_MSIX) ? TRUE : FALSE;
10253 uint8_t single_msix = ((sc->interrupt_mode == INTR_MODE_MSIX) &&
10254 (sc->intr_count == 1)) ? TRUE : FALSE;
10255 uint8_t msi = (sc->interrupt_mode == INTR_MODE_MSI) ? TRUE : FALSE;
10258 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10259 HC_CONFIG_0_REG_INT_LINE_EN_0);
10260 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
10261 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10263 val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
10266 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
10267 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10268 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
10269 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10271 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10272 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
10273 HC_CONFIG_0_REG_INT_LINE_EN_0 |
10274 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10276 if (!CHIP_IS_E1(sc)) {
10277 BLOGD(sc, DBG_INTR, "write %x to HC %d (addr 0x%x)\n",
10280 REG_WR(sc, addr, val);
10282 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
10286 if (CHIP_IS_E1(sc)) {
10287 REG_WR(sc, (HC_REG_INT_MASK + port*4), 0x1FFFF);
10290 BLOGD(sc, DBG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n",
10291 val, port, addr, ((msix) ? "MSI-X" : ((msi) ? "MSI" : "INTx")));
10293 REG_WR(sc, addr, val);
10295 /* ensure that HC_CONFIG is written before leading/trailing edge config */
10298 if (!CHIP_IS_E1(sc)) {
10299 /* init leading/trailing edge */
10301 val = (0xee0f | (1 << (SC_VN(sc) + 4)));
10302 if (sc->port.pmf) {
10303 /* enable nig and gpio3 attention */
10310 REG_WR(sc, (HC_REG_TRAILING_EDGE_0 + port*8), val);
10311 REG_WR(sc, (HC_REG_LEADING_EDGE_0 + port*8), val);
10314 /* make sure that interrupts are indeed enabled from here on */
10319 bxe_igu_int_enable(struct bxe_softc *sc)
10322 uint8_t msix = (sc->interrupt_mode == INTR_MODE_MSIX) ? TRUE : FALSE;
10323 uint8_t single_msix = ((sc->interrupt_mode == INTR_MODE_MSIX) &&
10324 (sc->intr_count == 1)) ? TRUE : FALSE;
10325 uint8_t msi = (sc->interrupt_mode == INTR_MODE_MSI) ? TRUE : FALSE;
10327 val = REG_RD(sc, IGU_REG_PF_CONFIGURATION);
10330 val &= ~(IGU_PF_CONF_INT_LINE_EN |
10331 IGU_PF_CONF_SINGLE_ISR_EN);
10332 val |= (IGU_PF_CONF_MSI_MSIX_EN |
10333 IGU_PF_CONF_ATTN_BIT_EN);
10335 val |= IGU_PF_CONF_SINGLE_ISR_EN;
10338 val &= ~IGU_PF_CONF_INT_LINE_EN;
10339 val |= (IGU_PF_CONF_MSI_MSIX_EN |
10340 IGU_PF_CONF_ATTN_BIT_EN |
10341 IGU_PF_CONF_SINGLE_ISR_EN);
10343 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
10344 val |= (IGU_PF_CONF_INT_LINE_EN |
10345 IGU_PF_CONF_ATTN_BIT_EN |
10346 IGU_PF_CONF_SINGLE_ISR_EN);
10349 /* clean previous status - need to configure igu prior to ack*/
10350 if ((!msix) || single_msix) {
10351 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
10355 val |= IGU_PF_CONF_FUNC_EN;
10357 BLOGD(sc, DBG_INTR, "write 0x%x to IGU mode %s\n",
10358 val, ((msix) ? "MSI-X" : ((msi) ? "MSI" : "INTx")));
10360 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
10364 /* init leading/trailing edge */
10366 val = (0xee0f | (1 << (SC_VN(sc) + 4)));
10367 if (sc->port.pmf) {
10368 /* enable nig and gpio3 attention */
10375 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, val);
10376 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, val);
10378 /* make sure that interrupts are indeed enabled from here on */
10383 bxe_int_enable(struct bxe_softc *sc)
10385 if (sc->devinfo.int_block == INT_BLOCK_HC) {
10386 bxe_hc_int_enable(sc);
10388 bxe_igu_int_enable(sc);
10393 bxe_hc_int_disable(struct bxe_softc *sc)
10395 int port = SC_PORT(sc);
10396 uint32_t addr = (port) ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
10397 uint32_t val = REG_RD(sc, addr);
10400 * In E1 we must use only PCI configuration space to disable MSI/MSIX
10401 * capablility. It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC
10404 if (CHIP_IS_E1(sc)) {
10406 * Since IGU_PF_CONF_MSI_MSIX_EN still always on use mask register
10407 * to prevent from HC sending interrupts after we exit the function
10409 REG_WR(sc, (HC_REG_INT_MASK + port*4), 0);
10411 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10412 HC_CONFIG_0_REG_INT_LINE_EN_0 |
10413 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10415 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
10416 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
10417 HC_CONFIG_0_REG_INT_LINE_EN_0 |
10418 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
10421 BLOGD(sc, DBG_INTR, "write %x to HC %d (addr 0x%x)\n", val, port, addr);
10423 /* flush all outstanding writes */
10426 REG_WR(sc, addr, val);
10427 if (REG_RD(sc, addr) != val) {
10428 BLOGE(sc, "proper val not read from HC IGU!\n");
10433 bxe_igu_int_disable(struct bxe_softc *sc)
10435 uint32_t val = REG_RD(sc, IGU_REG_PF_CONFIGURATION);
10437 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
10438 IGU_PF_CONF_INT_LINE_EN |
10439 IGU_PF_CONF_ATTN_BIT_EN);
10441 BLOGD(sc, DBG_INTR, "write %x to IGU\n", val);
10443 /* flush all outstanding writes */
10446 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
10447 if (REG_RD(sc, IGU_REG_PF_CONFIGURATION) != val) {
10448 BLOGE(sc, "proper val not read from IGU!\n");
10453 bxe_int_disable(struct bxe_softc *sc)
10455 if (sc->devinfo.int_block == INT_BLOCK_HC) {
10456 bxe_hc_int_disable(sc);
10458 bxe_igu_int_disable(sc);
10463 bxe_nic_init(struct bxe_softc *sc,
10468 for (i = 0; i < sc->num_queues; i++) {
10469 bxe_init_eth_fp(sc, i);
10472 rmb(); /* ensure status block indices were read */
10474 bxe_init_rx_rings(sc);
10475 bxe_init_tx_rings(sc);
10481 /* initialize MOD_ABS interrupts */
10482 elink_init_mod_abs_int(sc, &sc->link_vars,
10483 sc->devinfo.chip_id,
10484 sc->devinfo.shmem_base,
10485 sc->devinfo.shmem2_base,
10488 bxe_init_def_sb(sc);
10489 bxe_update_dsb_idx(sc);
10490 bxe_init_sp_ring(sc);
10491 bxe_init_eq_ring(sc);
10492 bxe_init_internal(sc, load_code);
10494 bxe_stats_init(sc);
10496 /* flush all before enabling interrupts */
10499 bxe_int_enable(sc);
10501 /* check for SPIO5 */
10502 bxe_attn_int_deasserted0(sc,
10504 (MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
10506 AEU_INPUTS_ATTN_BITS_SPIO5);
10510 bxe_init_objs(struct bxe_softc *sc)
10512 /* mcast rules must be added to tx if tx switching is enabled */
10513 ecore_obj_type o_type =
10514 (sc->flags & BXE_TX_SWITCHING) ? ECORE_OBJ_TYPE_RX_TX :
10517 /* RX_MODE controlling object */
10518 ecore_init_rx_mode_obj(sc, &sc->rx_mode_obj);
10520 /* multicast configuration controlling object */
10521 ecore_init_mcast_obj(sc,
10527 BXE_SP(sc, mcast_rdata),
10528 BXE_SP_MAPPING(sc, mcast_rdata),
10529 ECORE_FILTER_MCAST_PENDING,
10533 /* Setup CAM credit pools */
10534 ecore_init_mac_credit_pool(sc,
10537 CHIP_IS_E1x(sc) ? VNICS_PER_PORT(sc) :
10538 VNICS_PER_PATH(sc));
10540 ecore_init_vlan_credit_pool(sc,
10542 SC_ABS_FUNC(sc) >> 1,
10543 CHIP_IS_E1x(sc) ? VNICS_PER_PORT(sc) :
10544 VNICS_PER_PATH(sc));
10546 /* RSS configuration object */
10547 ecore_init_rss_config_obj(sc,
10553 BXE_SP(sc, rss_rdata),
10554 BXE_SP_MAPPING(sc, rss_rdata),
10555 ECORE_FILTER_RSS_CONF_PENDING,
10556 &sc->sp_state, ECORE_OBJ_TYPE_RX);
10560 * Initialize the function. This must be called before sending CLIENT_SETUP
10561 * for the first client.
10564 bxe_func_start(struct bxe_softc *sc)
10566 struct ecore_func_state_params func_params = { NULL };
10567 struct ecore_func_start_params *start_params = &func_params.params.start;
10569 /* Prepare parameters for function state transitions */
10570 bit_set(&func_params.ramrod_flags, RAMROD_COMP_WAIT);
10572 func_params.f_obj = &sc->func_obj;
10573 func_params.cmd = ECORE_F_CMD_START;
10575 /* Function parameters */
10576 start_params->mf_mode = sc->devinfo.mf_info.mf_mode;
10577 start_params->sd_vlan_tag = OVLAN(sc);
10579 if (CHIP_IS_E2(sc) || CHIP_IS_E3(sc)) {
10580 start_params->network_cos_mode = STATIC_COS;
10581 } else { /* CHIP_IS_E1X */
10582 start_params->network_cos_mode = FW_WRR;
10585 //start_params->gre_tunnel_mode = 0;
10586 //start_params->gre_tunnel_rss = 0;
10588 return (ecore_func_state_change(sc, &func_params));
10592 bxe_set_power_state(struct bxe_softc *sc,
10597 /* If there is no power capability, silently succeed */
10598 if (!(sc->devinfo.pcie_cap_flags & BXE_PM_CAPABLE_FLAG)) {
10599 BLOGW(sc, "No power capability\n");
10603 pmcsr = pci_read_config(sc->dev,
10604 (sc->devinfo.pcie_pm_cap_reg + PCIR_POWER_STATUS),
10609 pci_write_config(sc->dev,
10610 (sc->devinfo.pcie_pm_cap_reg + PCIR_POWER_STATUS),
10611 ((pmcsr & ~PCIM_PSTAT_DMASK) | PCIM_PSTAT_PME), 2);
10613 if (pmcsr & PCIM_PSTAT_DMASK) {
10614 /* delay required during transition out of D3hot */
10621 /* XXX if there are other clients above don't shut down the power */
10623 /* don't shut down the power for emulation and FPGA */
10624 if (CHIP_REV_IS_SLOW(sc)) {
10628 pmcsr &= ~PCIM_PSTAT_DMASK;
10629 pmcsr |= PCIM_PSTAT_D3;
10632 pmcsr |= PCIM_PSTAT_PMEENABLE;
10635 pci_write_config(sc->dev,
10636 (sc->devinfo.pcie_pm_cap_reg + PCIR_POWER_STATUS),
10640 * No more memory access after this point until device is brought back
10646 BLOGE(sc, "Can't support PCI power state = 0x%x pmcsr 0x%x\n",
10655 /* return true if succeeded to acquire the lock */
10657 bxe_trylock_hw_lock(struct bxe_softc *sc,
10660 uint32_t lock_status;
10661 uint32_t resource_bit = (1 << resource);
10662 int func = SC_FUNC(sc);
10663 uint32_t hw_lock_control_reg;
10665 BLOGD(sc, DBG_LOAD, "Trying to take a resource lock 0x%x\n", resource);
10667 /* Validating that the resource is within range */
10668 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
10669 BLOGD(sc, DBG_LOAD,
10670 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
10671 resource, HW_LOCK_MAX_RESOURCE_VALUE);
10676 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
10678 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
10681 /* try to acquire the lock */
10682 REG_WR(sc, hw_lock_control_reg + 4, resource_bit);
10683 lock_status = REG_RD(sc, hw_lock_control_reg);
10684 if (lock_status & resource_bit) {
10688 BLOGE(sc, "Failed to get a resource lock 0x%x func %d "
10689 "lock_status 0x%x resource_bit 0x%x\n", resource, func,
10690 lock_status, resource_bit);
10696 * Get the recovery leader resource id according to the engine this function
10697 * belongs to. Currently only only 2 engines is supported.
10700 bxe_get_leader_lock_resource(struct bxe_softc *sc)
10703 return (HW_LOCK_RESOURCE_RECOVERY_LEADER_1);
10705 return (HW_LOCK_RESOURCE_RECOVERY_LEADER_0);
10709 /* try to acquire a leader lock for current engine */
10711 bxe_trylock_leader_lock(struct bxe_softc *sc)
10713 return (bxe_trylock_hw_lock(sc, bxe_get_leader_lock_resource(sc)));
10717 bxe_release_leader_lock(struct bxe_softc *sc)
10719 return (bxe_release_hw_lock(sc, bxe_get_leader_lock_resource(sc)));
10722 /* close gates #2, #3 and #4 */
10724 bxe_set_234_gates(struct bxe_softc *sc,
10729 /* gates #2 and #4a are closed/opened for "not E1" only */
10730 if (!CHIP_IS_E1(sc)) {
10732 REG_WR(sc, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
10734 REG_WR(sc, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
10738 if (CHIP_IS_E1x(sc)) {
10739 /* prevent interrupts from HC on both ports */
10740 val = REG_RD(sc, HC_REG_CONFIG_1);
10741 REG_WR(sc, HC_REG_CONFIG_1,
10742 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
10743 (val & ~(uint32_t)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
10745 val = REG_RD(sc, HC_REG_CONFIG_0);
10746 REG_WR(sc, HC_REG_CONFIG_0,
10747 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
10748 (val & ~(uint32_t)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
10750 /* Prevent incoming interrupts in IGU */
10751 val = REG_RD(sc, IGU_REG_BLOCK_CONFIGURATION);
10753 REG_WR(sc, IGU_REG_BLOCK_CONFIGURATION,
10755 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
10756 (val & ~(uint32_t)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
10759 BLOGD(sc, DBG_LOAD, "%s gates #2, #3 and #4\n",
10760 close ? "closing" : "opening");
10765 /* poll for pending writes bit, it should get cleared in no more than 1s */
10767 bxe_er_poll_igu_vq(struct bxe_softc *sc)
10769 uint32_t cnt = 1000;
10770 uint32_t pend_bits = 0;
10773 pend_bits = REG_RD(sc, IGU_REG_PENDING_BITS_STATUS);
10775 if (pend_bits == 0) {
10780 } while (--cnt > 0);
10783 BLOGE(sc, "Still pending IGU requests bits=0x%08x!\n", pend_bits);
10790 #define SHARED_MF_CLP_MAGIC 0x80000000 /* 'magic' bit */
10793 bxe_clp_reset_prep(struct bxe_softc *sc,
10794 uint32_t *magic_val)
10796 /* Do some magic... */
10797 uint32_t val = MFCFG_RD(sc, shared_mf_config.clp_mb);
10798 *magic_val = val & SHARED_MF_CLP_MAGIC;
10799 MFCFG_WR(sc, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
10802 /* restore the value of the 'magic' bit */
10804 bxe_clp_reset_done(struct bxe_softc *sc,
10805 uint32_t magic_val)
10807 /* Restore the 'magic' bit value... */
10808 uint32_t val = MFCFG_RD(sc, shared_mf_config.clp_mb);
10809 MFCFG_WR(sc, shared_mf_config.clp_mb,
10810 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
10813 /* prepare for MCP reset, takes care of CLP configurations */
10815 bxe_reset_mcp_prep(struct bxe_softc *sc,
10816 uint32_t *magic_val)
10819 uint32_t validity_offset;
10821 /* set `magic' bit in order to save MF config */
10822 if (!CHIP_IS_E1(sc)) {
10823 bxe_clp_reset_prep(sc, magic_val);
10826 /* get shmem offset */
10827 shmem = REG_RD(sc, MISC_REG_SHARED_MEM_ADDR);
10829 offsetof(struct shmem_region, validity_map[SC_PORT(sc)]);
10831 /* Clear validity map flags */
10833 REG_WR(sc, shmem + validity_offset, 0);
10837 #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
10838 #define MCP_ONE_TIMEOUT 100 /* 100 ms */
10841 bxe_mcp_wait_one(struct bxe_softc *sc)
10843 /* special handling for emulation and FPGA (10 times longer) */
10844 if (CHIP_REV_IS_SLOW(sc)) {
10845 DELAY((MCP_ONE_TIMEOUT*10) * 1000);
10847 DELAY((MCP_ONE_TIMEOUT) * 1000);
10851 /* initialize shmem_base and waits for validity signature to appear */
10853 bxe_init_shmem(struct bxe_softc *sc)
10859 sc->devinfo.shmem_base =
10860 sc->link_params.shmem_base =
10861 REG_RD(sc, MISC_REG_SHARED_MEM_ADDR);
10863 if (sc->devinfo.shmem_base) {
10864 val = SHMEM_RD(sc, validity_map[SC_PORT(sc)]);
10865 if (val & SHR_MEM_VALIDITY_MB)
10869 bxe_mcp_wait_one(sc);
10871 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
10873 BLOGE(sc, "BAD MCP validity signature\n");
10879 bxe_reset_mcp_comp(struct bxe_softc *sc,
10880 uint32_t magic_val)
10882 int rc = bxe_init_shmem(sc);
10884 /* Restore the `magic' bit value */
10885 if (!CHIP_IS_E1(sc)) {
10886 bxe_clp_reset_done(sc, magic_val);
10893 bxe_pxp_prep(struct bxe_softc *sc)
10895 if (!CHIP_IS_E1(sc)) {
10896 REG_WR(sc, PXP2_REG_RD_START_INIT, 0);
10897 REG_WR(sc, PXP2_REG_RQ_RBC_DONE, 0);
10903 * Reset the whole chip except for:
10905 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by one reset bit)
10907 * - MISC (including AEU)
10912 bxe_process_kill_chip_reset(struct bxe_softc *sc,
10915 uint32_t not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
10916 uint32_t global_bits2, stay_reset2;
10919 * Bits that have to be set in reset_mask2 if we want to reset 'global'
10920 * (per chip) blocks.
10923 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
10924 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
10927 * Don't reset the following blocks.
10928 * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
10929 * reset, as in 4 port device they might still be owned
10930 * by the MCP (there is only one leader per path).
10933 MISC_REGISTERS_RESET_REG_1_RST_HC |
10934 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
10935 MISC_REGISTERS_RESET_REG_1_RST_PXP;
10938 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
10939 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
10940 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
10941 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
10942 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
10943 MISC_REGISTERS_RESET_REG_2_RST_GRC |
10944 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
10945 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
10946 MISC_REGISTERS_RESET_REG_2_RST_ATC |
10947 MISC_REGISTERS_RESET_REG_2_PGLC |
10948 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
10949 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
10950 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
10951 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
10952 MISC_REGISTERS_RESET_REG_2_UMAC0 |
10953 MISC_REGISTERS_RESET_REG_2_UMAC1;
10956 * Keep the following blocks in reset:
10957 * - all xxMACs are handled by the elink code.
10960 MISC_REGISTERS_RESET_REG_2_XMAC |
10961 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
10963 /* Full reset masks according to the chip */
10964 reset_mask1 = 0xffffffff;
10966 if (CHIP_IS_E1(sc))
10967 reset_mask2 = 0xffff;
10968 else if (CHIP_IS_E1H(sc))
10969 reset_mask2 = 0x1ffff;
10970 else if (CHIP_IS_E2(sc))
10971 reset_mask2 = 0xfffff;
10972 else /* CHIP_IS_E3 */
10973 reset_mask2 = 0x3ffffff;
10975 /* Don't reset global blocks unless we need to */
10977 reset_mask2 &= ~global_bits2;
10980 * In case of attention in the QM, we need to reset PXP
10981 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
10982 * because otherwise QM reset would release 'close the gates' shortly
10983 * before resetting the PXP, then the PSWRQ would send a write
10984 * request to PGLUE. Then when PXP is reset, PGLUE would try to
10985 * read the payload data from PSWWR, but PSWWR would not
10986 * respond. The write queue in PGLUE would stuck, dmae commands
10987 * would not return. Therefore it's important to reset the second
10988 * reset register (containing the
10989 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
10990 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
10993 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
10994 reset_mask2 & (~not_reset_mask2));
10996 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
10997 reset_mask1 & (~not_reset_mask1));
11002 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
11003 reset_mask2 & (~stay_reset2));
11008 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
11013 bxe_process_kill(struct bxe_softc *sc,
11018 uint32_t sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
11019 uint32_t tags_63_32 = 0;
11021 /* Empty the Tetris buffer, wait for 1s */
11023 sr_cnt = REG_RD(sc, PXP2_REG_RD_SR_CNT);
11024 blk_cnt = REG_RD(sc, PXP2_REG_RD_BLK_CNT);
11025 port_is_idle_0 = REG_RD(sc, PXP2_REG_RD_PORT_IS_IDLE_0);
11026 port_is_idle_1 = REG_RD(sc, PXP2_REG_RD_PORT_IS_IDLE_1);
11027 pgl_exp_rom2 = REG_RD(sc, PXP2_REG_PGL_EXP_ROM2);
11028 if (CHIP_IS_E3(sc)) {
11029 tags_63_32 = REG_RD(sc, PGLUE_B_REG_TAGS_63_32);
11032 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
11033 ((port_is_idle_0 & 0x1) == 0x1) &&
11034 ((port_is_idle_1 & 0x1) == 0x1) &&
11035 (pgl_exp_rom2 == 0xffffffff) &&
11036 (!CHIP_IS_E3(sc) || (tags_63_32 == 0xffffffff)))
11039 } while (cnt-- > 0);
11042 BLOGE(sc, "ERROR: Tetris buffer didn't get empty or there "
11043 "are still outstanding read requests after 1s! "
11044 "sr_cnt=0x%08x, blk_cnt=0x%08x, port_is_idle_0=0x%08x, "
11045 "port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
11046 sr_cnt, blk_cnt, port_is_idle_0,
11047 port_is_idle_1, pgl_exp_rom2);
11053 /* Close gates #2, #3 and #4 */
11054 bxe_set_234_gates(sc, TRUE);
11056 /* Poll for IGU VQs for 57712 and newer chips */
11057 if (!CHIP_IS_E1x(sc) && bxe_er_poll_igu_vq(sc)) {
11061 /* XXX indicate that "process kill" is in progress to MCP */
11063 /* clear "unprepared" bit */
11064 REG_WR(sc, MISC_REG_UNPREPARED, 0);
11067 /* Make sure all is written to the chip before the reset */
11071 * Wait for 1ms to empty GLUE and PCI-E core queues,
11072 * PSWHST, GRC and PSWRD Tetris buffer.
11076 /* Prepare to chip reset: */
11079 bxe_reset_mcp_prep(sc, &val);
11086 /* reset the chip */
11087 bxe_process_kill_chip_reset(sc, global);
11090 /* clear errors in PGB */
11091 if (!CHIP_IS_E1(sc))
11092 REG_WR(sc, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
11094 /* Recover after reset: */
11096 if (global && bxe_reset_mcp_comp(sc, val)) {
11100 /* XXX add resetting the NO_MCP mode DB here */
11102 /* Open the gates #2, #3 and #4 */
11103 bxe_set_234_gates(sc, FALSE);
11106 * IGU/AEU preparation bring back the AEU/IGU to a reset state
11107 * re-enable attentions
11114 bxe_leader_reset(struct bxe_softc *sc)
11117 uint8_t global = bxe_reset_is_global(sc);
11118 uint32_t load_code;
11121 * If not going to reset MCP, load "fake" driver to reset HW while
11122 * driver is owner of the HW.
11124 if (!global && !BXE_NOMCP(sc)) {
11125 load_code = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_REQ,
11126 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
11128 BLOGE(sc, "MCP response failure, aborting\n");
11130 goto exit_leader_reset;
11133 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
11134 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
11135 BLOGE(sc, "MCP unexpected response, aborting\n");
11137 goto exit_leader_reset2;
11140 load_code = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
11142 BLOGE(sc, "MCP response failure, aborting\n");
11144 goto exit_leader_reset2;
11148 /* try to recover after the failure */
11149 if (bxe_process_kill(sc, global)) {
11150 BLOGE(sc, "Something bad occurred on engine %d!\n", SC_PATH(sc));
11152 goto exit_leader_reset2;
11156 * Clear the RESET_IN_PROGRESS and RESET_GLOBAL bits and update the driver
11159 bxe_set_reset_done(sc);
11161 bxe_clear_reset_global(sc);
11164 exit_leader_reset2:
11166 /* unload "fake driver" if it was loaded */
11167 if (!global && !BXE_NOMCP(sc)) {
11168 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
11169 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, 0);
11175 bxe_release_leader_lock(sc);
11182 * prepare INIT transition, parameters configured:
11183 * - HC configuration
11184 * - Queue's CDU context
11187 bxe_pf_q_prep_init(struct bxe_softc *sc,
11188 struct bxe_fastpath *fp,
11189 struct ecore_queue_init_params *init_params)
11192 int cxt_index, cxt_offset;
11194 bxe_set_bit(ECORE_Q_FLG_HC, &init_params->rx.flags);
11195 bxe_set_bit(ECORE_Q_FLG_HC, &init_params->tx.flags);
11197 bxe_set_bit(ECORE_Q_FLG_HC_EN, &init_params->rx.flags);
11198 bxe_set_bit(ECORE_Q_FLG_HC_EN, &init_params->tx.flags);
11201 init_params->rx.hc_rate =
11202 sc->hc_rx_ticks ? (1000000 / sc->hc_rx_ticks) : 0;
11203 init_params->tx.hc_rate =
11204 sc->hc_tx_ticks ? (1000000 / sc->hc_tx_ticks) : 0;
11207 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id = fp->fw_sb_id;
11209 /* CQ index among the SB indices */
11210 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
11211 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
11213 /* set maximum number of COSs supported by this queue */
11214 init_params->max_cos = sc->max_cos;
11216 BLOGD(sc, DBG_LOAD, "fp %d setting queue params max cos to %d\n",
11217 fp->index, init_params->max_cos);
11219 /* set the context pointers queue object */
11220 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
11221 /* XXX change index/cid here if ever support multiple tx CoS */
11222 /* fp->txdata[cos]->cid */
11223 cxt_index = fp->index / ILT_PAGE_CIDS;
11224 cxt_offset = fp->index - (cxt_index * ILT_PAGE_CIDS);
11225 init_params->cxts[cos] = &sc->context[cxt_index].vcxt[cxt_offset].eth;
11229 /* set flags that are common for the Tx-only and not normal connections */
11230 static unsigned long
11231 bxe_get_common_flags(struct bxe_softc *sc,
11232 struct bxe_fastpath *fp,
11233 uint8_t zero_stats)
11235 unsigned long flags = 0;
11237 /* PF driver will always initialize the Queue to an ACTIVE state */
11238 bxe_set_bit(ECORE_Q_FLG_ACTIVE, &flags);
11241 * tx only connections collect statistics (on the same index as the
11242 * parent connection). The statistics are zeroed when the parent
11243 * connection is initialized.
11246 bxe_set_bit(ECORE_Q_FLG_STATS, &flags);
11248 bxe_set_bit(ECORE_Q_FLG_ZERO_STATS, &flags);
11252 * tx only connections can support tx-switching, though their
11253 * CoS-ness doesn't survive the loopback
11255 if (sc->flags & BXE_TX_SWITCHING) {
11256 bxe_set_bit(ECORE_Q_FLG_TX_SWITCH, &flags);
11259 bxe_set_bit(ECORE_Q_FLG_PCSUM_ON_PKT, &flags);
11264 static unsigned long
11265 bxe_get_q_flags(struct bxe_softc *sc,
11266 struct bxe_fastpath *fp,
11269 unsigned long flags = 0;
11271 if (IS_MF_SD(sc)) {
11272 bxe_set_bit(ECORE_Q_FLG_OV, &flags);
11275 if (if_getcapenable(sc->ifp) & IFCAP_LRO) {
11276 bxe_set_bit(ECORE_Q_FLG_TPA, &flags);
11277 bxe_set_bit(ECORE_Q_FLG_TPA_IPV6, &flags);
11281 bxe_set_bit(ECORE_Q_FLG_LEADING_RSS, &flags);
11282 bxe_set_bit(ECORE_Q_FLG_MCAST, &flags);
11285 bxe_set_bit(ECORE_Q_FLG_VLAN, &flags);
11287 /* merge with common flags */
11288 return (flags | bxe_get_common_flags(sc, fp, TRUE));
11292 bxe_pf_q_prep_general(struct bxe_softc *sc,
11293 struct bxe_fastpath *fp,
11294 struct ecore_general_setup_params *gen_init,
11297 gen_init->stat_id = bxe_stats_id(fp);
11298 gen_init->spcl_id = fp->cl_id;
11299 gen_init->mtu = sc->mtu;
11300 gen_init->cos = cos;
11304 bxe_pf_rx_q_prep(struct bxe_softc *sc,
11305 struct bxe_fastpath *fp,
11306 struct rxq_pause_params *pause,
11307 struct ecore_rxq_setup_params *rxq_init)
11309 uint8_t max_sge = 0;
11310 uint16_t sge_sz = 0;
11311 uint16_t tpa_agg_size = 0;
11313 pause->sge_th_lo = SGE_TH_LO(sc);
11314 pause->sge_th_hi = SGE_TH_HI(sc);
11316 /* validate SGE ring has enough to cross high threshold */
11317 if (sc->dropless_fc &&
11318 (pause->sge_th_hi + FW_PREFETCH_CNT) >
11319 (RX_SGE_USABLE_PER_PAGE * RX_SGE_NUM_PAGES)) {
11320 BLOGW(sc, "sge ring threshold limit\n");
11323 /* minimum max_aggregation_size is 2*MTU (two full buffers) */
11324 tpa_agg_size = (2 * sc->mtu);
11325 if (tpa_agg_size < sc->max_aggregation_size) {
11326 tpa_agg_size = sc->max_aggregation_size;
11329 max_sge = SGE_PAGE_ALIGN(sc->mtu) >> SGE_PAGE_SHIFT;
11330 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
11331 (~(PAGES_PER_SGE - 1))) >> PAGES_PER_SGE_SHIFT;
11332 sge_sz = (uint16_t)min(SGE_PAGES, 0xffff);
11334 /* pause - not for e1 */
11335 if (!CHIP_IS_E1(sc)) {
11336 pause->bd_th_lo = BD_TH_LO(sc);
11337 pause->bd_th_hi = BD_TH_HI(sc);
11339 pause->rcq_th_lo = RCQ_TH_LO(sc);
11340 pause->rcq_th_hi = RCQ_TH_HI(sc);
11342 /* validate rings have enough entries to cross high thresholds */
11343 if (sc->dropless_fc &&
11344 pause->bd_th_hi + FW_PREFETCH_CNT >
11345 sc->rx_ring_size) {
11346 BLOGW(sc, "rx bd ring threshold limit\n");
11349 if (sc->dropless_fc &&
11350 pause->rcq_th_hi + FW_PREFETCH_CNT >
11351 RCQ_NUM_PAGES * RCQ_USABLE_PER_PAGE) {
11352 BLOGW(sc, "rcq ring threshold limit\n");
11355 pause->pri_map = 1;
11359 rxq_init->dscr_map = fp->rx_dma.paddr;
11360 rxq_init->sge_map = fp->rx_sge_dma.paddr;
11361 rxq_init->rcq_map = fp->rcq_dma.paddr;
11362 rxq_init->rcq_np_map = (fp->rcq_dma.paddr + BCM_PAGE_SIZE);
11365 * This should be a maximum number of data bytes that may be
11366 * placed on the BD (not including paddings).
11368 rxq_init->buf_sz = (fp->rx_buf_size -
11369 IP_HEADER_ALIGNMENT_PADDING);
11371 rxq_init->cl_qzone_id = fp->cl_qzone_id;
11372 rxq_init->tpa_agg_sz = tpa_agg_size;
11373 rxq_init->sge_buf_sz = sge_sz;
11374 rxq_init->max_sges_pkt = max_sge;
11375 rxq_init->rss_engine_id = SC_FUNC(sc);
11376 rxq_init->mcast_engine_id = SC_FUNC(sc);
11379 * Maximum number or simultaneous TPA aggregation for this Queue.
11380 * For PF Clients it should be the maximum available number.
11381 * VF driver(s) may want to define it to a smaller value.
11383 rxq_init->max_tpa_queues = MAX_AGG_QS(sc);
11385 rxq_init->cache_line_log = BXE_RX_ALIGN_SHIFT;
11386 rxq_init->fw_sb_id = fp->fw_sb_id;
11388 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
11391 * configure silent vlan removal
11392 * if multi function mode is afex, then mask default vlan
11394 if (IS_MF_AFEX(sc)) {
11395 rxq_init->silent_removal_value =
11396 sc->devinfo.mf_info.afex_def_vlan_tag;
11397 rxq_init->silent_removal_mask = EVL_VLID_MASK;
11402 bxe_pf_tx_q_prep(struct bxe_softc *sc,
11403 struct bxe_fastpath *fp,
11404 struct ecore_txq_setup_params *txq_init,
11408 * XXX If multiple CoS is ever supported then each fastpath structure
11409 * will need to maintain tx producer/consumer/dma/etc values *per* CoS.
11410 * fp->txdata[cos]->tx_dma.paddr;
11412 txq_init->dscr_map = fp->tx_dma.paddr;
11413 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
11414 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
11415 txq_init->fw_sb_id = fp->fw_sb_id;
11418 * set the TSS leading client id for TX classfication to the
11419 * leading RSS client id
11421 txq_init->tss_leading_cl_id = BXE_FP(sc, 0, cl_id);
11425 * This function performs 2 steps in a queue state machine:
11430 bxe_setup_queue(struct bxe_softc *sc,
11431 struct bxe_fastpath *fp,
11434 struct ecore_queue_state_params q_params = { NULL };
11435 struct ecore_queue_setup_params *setup_params =
11436 &q_params.params.setup;
11439 BLOGD(sc, DBG_LOAD, "setting up queue %d\n", fp->index);
11441 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
11443 q_params.q_obj = &BXE_SP_OBJ(sc, fp).q_obj;
11445 /* we want to wait for completion in this context */
11446 bxe_set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
11448 /* prepare the INIT parameters */
11449 bxe_pf_q_prep_init(sc, fp, &q_params.params.init);
11451 /* Set the command */
11452 q_params.cmd = ECORE_Q_CMD_INIT;
11454 /* Change the state to INIT */
11455 rc = ecore_queue_state_change(sc, &q_params);
11457 BLOGE(sc, "Queue(%d) INIT failed rc = %d\n", fp->index, rc);
11461 BLOGD(sc, DBG_LOAD, "init complete\n");
11463 /* now move the Queue to the SETUP state */
11464 memset(setup_params, 0, sizeof(*setup_params));
11466 /* set Queue flags */
11467 setup_params->flags = bxe_get_q_flags(sc, fp, leading);
11469 /* set general SETUP parameters */
11470 bxe_pf_q_prep_general(sc, fp, &setup_params->gen_params,
11471 FIRST_TX_COS_INDEX);
11473 bxe_pf_rx_q_prep(sc, fp,
11474 &setup_params->pause_params,
11475 &setup_params->rxq_params);
11477 bxe_pf_tx_q_prep(sc, fp,
11478 &setup_params->txq_params,
11479 FIRST_TX_COS_INDEX);
11481 /* Set the command */
11482 q_params.cmd = ECORE_Q_CMD_SETUP;
11484 /* change the state to SETUP */
11485 rc = ecore_queue_state_change(sc, &q_params);
11487 BLOGE(sc, "Queue(%d) SETUP failed (rc = %d)\n", fp->index, rc);
11495 bxe_setup_leading(struct bxe_softc *sc)
11497 return (bxe_setup_queue(sc, &sc->fp[0], TRUE));
11501 bxe_config_rss_pf(struct bxe_softc *sc,
11502 struct ecore_rss_config_obj *rss_obj,
11503 uint8_t config_hash)
11505 struct ecore_config_rss_params params = { NULL };
11509 * Although RSS is meaningless when there is a single HW queue we
11510 * still need it enabled in order to have HW Rx hash generated.
11513 params.rss_obj = rss_obj;
11515 bxe_set_bit(RAMROD_COMP_WAIT, ¶ms.ramrod_flags);
11517 bxe_set_bit(ECORE_RSS_MODE_REGULAR, ¶ms.rss_flags);
11519 /* RSS configuration */
11520 bxe_set_bit(ECORE_RSS_IPV4, ¶ms.rss_flags);
11521 bxe_set_bit(ECORE_RSS_IPV4_TCP, ¶ms.rss_flags);
11522 bxe_set_bit(ECORE_RSS_IPV6, ¶ms.rss_flags);
11523 bxe_set_bit(ECORE_RSS_IPV6_TCP, ¶ms.rss_flags);
11524 if (rss_obj->udp_rss_v4) {
11525 bxe_set_bit(ECORE_RSS_IPV4_UDP, ¶ms.rss_flags);
11527 if (rss_obj->udp_rss_v6) {
11528 bxe_set_bit(ECORE_RSS_IPV6_UDP, ¶ms.rss_flags);
11532 params.rss_result_mask = MULTI_MASK;
11534 memcpy(params.ind_table, rss_obj->ind_table, sizeof(params.ind_table));
11538 for (i = 0; i < sizeof(params.rss_key) / 4; i++) {
11539 params.rss_key[i] = arc4random();
11542 bxe_set_bit(ECORE_RSS_SET_SRCH, ¶ms.rss_flags);
11545 return (ecore_config_rss(sc, ¶ms));
11549 bxe_config_rss_eth(struct bxe_softc *sc,
11550 uint8_t config_hash)
11552 return (bxe_config_rss_pf(sc, &sc->rss_conf_obj, config_hash));
11556 bxe_init_rss_pf(struct bxe_softc *sc)
11558 uint8_t num_eth_queues = BXE_NUM_ETH_QUEUES(sc);
11562 * Prepare the initial contents of the indirection table if
11565 for (i = 0; i < sizeof(sc->rss_conf_obj.ind_table); i++) {
11566 sc->rss_conf_obj.ind_table[i] =
11567 (sc->fp->cl_id + (i % num_eth_queues));
11571 sc->rss_conf_obj.udp_rss_v4 = sc->rss_conf_obj.udp_rss_v6 = 1;
11575 * For 57710 and 57711 SEARCHER configuration (rss_keys) is
11576 * per-port, so if explicit configuration is needed, do it only
11579 * For 57712 and newer it's a per-function configuration.
11581 return (bxe_config_rss_eth(sc, sc->port.pmf || !CHIP_IS_E1x(sc)));
11585 bxe_set_mac_one(struct bxe_softc *sc,
11587 struct ecore_vlan_mac_obj *obj,
11590 unsigned long *ramrod_flags)
11592 struct ecore_vlan_mac_ramrod_params ramrod_param;
11595 memset(&ramrod_param, 0, sizeof(ramrod_param));
11597 /* fill in general parameters */
11598 ramrod_param.vlan_mac_obj = obj;
11599 ramrod_param.ramrod_flags = *ramrod_flags;
11601 /* fill a user request section if needed */
11602 if (!bxe_test_bit(RAMROD_CONT, ramrod_flags)) {
11603 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
11605 bxe_set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
11607 /* Set the command: ADD or DEL */
11608 ramrod_param.user_req.cmd = (set) ? ECORE_VLAN_MAC_ADD :
11609 ECORE_VLAN_MAC_DEL;
11612 rc = ecore_config_vlan_mac(sc, &ramrod_param);
11614 if (rc == ECORE_EXISTS) {
11615 BLOGD(sc, DBG_SP, "Failed to schedule ADD operations (EEXIST)\n");
11616 /* do not treat adding same MAC as error */
11618 } else if (rc < 0) {
11619 BLOGE(sc, "%s MAC failed (%d)\n", (set ? "Set" : "Delete"), rc);
11626 bxe_set_eth_mac(struct bxe_softc *sc,
11629 unsigned long ramrod_flags = 0;
11631 BLOGD(sc, DBG_LOAD, "Adding Ethernet MAC\n");
11633 bxe_set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
11635 /* Eth MAC is set on RSS leading client (fp[0]) */
11636 return (bxe_set_mac_one(sc, sc->link_params.mac_addr,
11637 &sc->sp_objs->mac_obj,
11638 set, ECORE_ETH_MAC, &ramrod_flags));
11642 bxe_get_cur_phy_idx(struct bxe_softc *sc)
11644 uint32_t sel_phy_idx = 0;
11646 if (sc->link_params.num_phys <= 1) {
11647 return (ELINK_INT_PHY);
11650 if (sc->link_vars.link_up) {
11651 sel_phy_idx = ELINK_EXT_PHY1;
11652 /* In case link is SERDES, check if the ELINK_EXT_PHY2 is the one */
11653 if ((sc->link_vars.link_status & LINK_STATUS_SERDES_LINK) &&
11654 (sc->link_params.phy[ELINK_EXT_PHY2].supported &
11655 ELINK_SUPPORTED_FIBRE))
11656 sel_phy_idx = ELINK_EXT_PHY2;
11658 switch (elink_phy_selection(&sc->link_params)) {
11659 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
11660 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
11661 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
11662 sel_phy_idx = ELINK_EXT_PHY1;
11664 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
11665 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
11666 sel_phy_idx = ELINK_EXT_PHY2;
11671 return (sel_phy_idx);
11675 bxe_get_link_cfg_idx(struct bxe_softc *sc)
11677 uint32_t sel_phy_idx = bxe_get_cur_phy_idx(sc);
11680 * The selected activated PHY is always after swapping (in case PHY
11681 * swapping is enabled). So when swapping is enabled, we need to reverse
11682 * the configuration
11685 if (sc->link_params.multi_phy_config & PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
11686 if (sel_phy_idx == ELINK_EXT_PHY1)
11687 sel_phy_idx = ELINK_EXT_PHY2;
11688 else if (sel_phy_idx == ELINK_EXT_PHY2)
11689 sel_phy_idx = ELINK_EXT_PHY1;
11692 return (ELINK_LINK_CONFIG_IDX(sel_phy_idx));
11696 bxe_set_requested_fc(struct bxe_softc *sc)
11699 * Initialize link parameters structure variables
11700 * It is recommended to turn off RX FC for jumbo frames
11701 * for better performance
11703 if (CHIP_IS_E1x(sc) && (sc->mtu > 5000)) {
11704 sc->link_params.req_fc_auto_adv = ELINK_FLOW_CTRL_TX;
11706 sc->link_params.req_fc_auto_adv = ELINK_FLOW_CTRL_BOTH;
11711 bxe_calc_fc_adv(struct bxe_softc *sc)
11713 uint8_t cfg_idx = bxe_get_link_cfg_idx(sc);
11716 sc->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
11719 switch (sc->link_vars.ieee_fc &
11720 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
11722 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
11723 sc->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
11727 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
11728 sc->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
11738 bxe_get_mf_speed(struct bxe_softc *sc)
11740 uint16_t line_speed = sc->link_vars.line_speed;
11743 bxe_extract_max_cfg(sc, sc->devinfo.mf_info.mf_config[SC_VN(sc)]);
11745 /* calculate the current MAX line speed limit for the MF devices */
11746 if (IS_MF_SI(sc)) {
11747 line_speed = (line_speed * maxCfg) / 100;
11748 } else { /* SD mode */
11749 uint16_t vn_max_rate = maxCfg * 100;
11751 if (vn_max_rate < line_speed) {
11752 line_speed = vn_max_rate;
11757 return (line_speed);
11761 bxe_fill_report_data(struct bxe_softc *sc,
11762 struct bxe_link_report_data *data)
11764 uint16_t line_speed = bxe_get_mf_speed(sc);
11766 memset(data, 0, sizeof(*data));
11768 /* fill the report data with the effective line speed */
11769 data->line_speed = line_speed;
11772 if (!sc->link_vars.link_up || (sc->flags & BXE_MF_FUNC_DIS)) {
11773 bxe_set_bit(BXE_LINK_REPORT_LINK_DOWN, &data->link_report_flags);
11777 if (sc->link_vars.duplex == DUPLEX_FULL) {
11778 bxe_set_bit(BXE_LINK_REPORT_FULL_DUPLEX, &data->link_report_flags);
11781 /* Rx Flow Control is ON */
11782 if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_RX) {
11783 bxe_set_bit(BXE_LINK_REPORT_RX_FC_ON, &data->link_report_flags);
11786 /* Tx Flow Control is ON */
11787 if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_TX) {
11788 bxe_set_bit(BXE_LINK_REPORT_TX_FC_ON, &data->link_report_flags);
11792 /* report link status to OS, should be called under phy_lock */
11794 bxe_link_report_locked(struct bxe_softc *sc)
11796 struct bxe_link_report_data cur_data;
11798 /* reread mf_cfg */
11799 if (IS_PF(sc) && !CHIP_IS_E1(sc)) {
11800 bxe_read_mf_cfg(sc);
11803 /* Read the current link report info */
11804 bxe_fill_report_data(sc, &cur_data);
11806 /* Don't report link down or exactly the same link status twice */
11807 if (!memcmp(&cur_data, &sc->last_reported_link, sizeof(cur_data)) ||
11808 (bxe_test_bit(BXE_LINK_REPORT_LINK_DOWN,
11809 &sc->last_reported_link.link_report_flags) &&
11810 bxe_test_bit(BXE_LINK_REPORT_LINK_DOWN,
11811 &cur_data.link_report_flags))) {
11815 ELINK_DEBUG_P2(sc, "Change in link status : cur_data = %x, last_reported_link = %x\n",
11816 cur_data.link_report_flags, sc->last_reported_link.link_report_flags);
11819 ELINK_DEBUG_P1(sc, "link status change count = %x\n", sc->link_cnt);
11820 /* report new link params and remember the state for the next time */
11821 memcpy(&sc->last_reported_link, &cur_data, sizeof(cur_data));
11823 if (bxe_test_bit(BXE_LINK_REPORT_LINK_DOWN,
11824 &cur_data.link_report_flags)) {
11825 if_link_state_change(sc->ifp, LINK_STATE_DOWN);
11827 const char *duplex;
11830 if (bxe_test_and_clear_bit(BXE_LINK_REPORT_FULL_DUPLEX,
11831 &cur_data.link_report_flags)) {
11833 ELINK_DEBUG_P0(sc, "link set to full duplex\n");
11836 ELINK_DEBUG_P0(sc, "link set to half duplex\n");
11840 * Handle the FC at the end so that only these flags would be
11841 * possibly set. This way we may easily check if there is no FC
11844 if (cur_data.link_report_flags) {
11845 if (bxe_test_bit(BXE_LINK_REPORT_RX_FC_ON,
11846 &cur_data.link_report_flags) &&
11847 bxe_test_bit(BXE_LINK_REPORT_TX_FC_ON,
11848 &cur_data.link_report_flags)) {
11849 flow = "ON - receive & transmit";
11850 } else if (bxe_test_bit(BXE_LINK_REPORT_RX_FC_ON,
11851 &cur_data.link_report_flags) &&
11852 !bxe_test_bit(BXE_LINK_REPORT_TX_FC_ON,
11853 &cur_data.link_report_flags)) {
11854 flow = "ON - receive";
11855 } else if (!bxe_test_bit(BXE_LINK_REPORT_RX_FC_ON,
11856 &cur_data.link_report_flags) &&
11857 bxe_test_bit(BXE_LINK_REPORT_TX_FC_ON,
11858 &cur_data.link_report_flags)) {
11859 flow = "ON - transmit";
11861 flow = "none"; /* possible? */
11867 if_link_state_change(sc->ifp, LINK_STATE_UP);
11868 BLOGI(sc, "NIC Link is Up, %d Mbps %s duplex, Flow control: %s\n",
11869 cur_data.line_speed, duplex, flow);
11874 bxe_link_report(struct bxe_softc *sc)
11876 bxe_acquire_phy_lock(sc);
11877 bxe_link_report_locked(sc);
11878 bxe_release_phy_lock(sc);
11882 bxe_link_status_update(struct bxe_softc *sc)
11884 if (sc->state != BXE_STATE_OPEN) {
11888 if (IS_PF(sc) && !CHIP_REV_IS_SLOW(sc)) {
11889 elink_link_status_update(&sc->link_params, &sc->link_vars);
11891 sc->port.supported[0] |= (ELINK_SUPPORTED_10baseT_Half |
11892 ELINK_SUPPORTED_10baseT_Full |
11893 ELINK_SUPPORTED_100baseT_Half |
11894 ELINK_SUPPORTED_100baseT_Full |
11895 ELINK_SUPPORTED_1000baseT_Full |
11896 ELINK_SUPPORTED_2500baseX_Full |
11897 ELINK_SUPPORTED_10000baseT_Full |
11898 ELINK_SUPPORTED_TP |
11899 ELINK_SUPPORTED_FIBRE |
11900 ELINK_SUPPORTED_Autoneg |
11901 ELINK_SUPPORTED_Pause |
11902 ELINK_SUPPORTED_Asym_Pause);
11903 sc->port.advertising[0] = sc->port.supported[0];
11905 sc->link_params.sc = sc;
11906 sc->link_params.port = SC_PORT(sc);
11907 sc->link_params.req_duplex[0] = DUPLEX_FULL;
11908 sc->link_params.req_flow_ctrl[0] = ELINK_FLOW_CTRL_NONE;
11909 sc->link_params.req_line_speed[0] = SPEED_10000;
11910 sc->link_params.speed_cap_mask[0] = 0x7f0000;
11911 sc->link_params.switch_cfg = ELINK_SWITCH_CFG_10G;
11913 if (CHIP_REV_IS_FPGA(sc)) {
11914 sc->link_vars.mac_type = ELINK_MAC_TYPE_EMAC;
11915 sc->link_vars.line_speed = ELINK_SPEED_1000;
11916 sc->link_vars.link_status = (LINK_STATUS_LINK_UP |
11917 LINK_STATUS_SPEED_AND_DUPLEX_1000TFD);
11919 sc->link_vars.mac_type = ELINK_MAC_TYPE_BMAC;
11920 sc->link_vars.line_speed = ELINK_SPEED_10000;
11921 sc->link_vars.link_status = (LINK_STATUS_LINK_UP |
11922 LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
11925 sc->link_vars.link_up = 1;
11927 sc->link_vars.duplex = DUPLEX_FULL;
11928 sc->link_vars.flow_ctrl = ELINK_FLOW_CTRL_NONE;
11931 REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + sc->link_params.port*4, 0);
11932 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
11933 bxe_link_report(sc);
11938 if (sc->link_vars.link_up) {
11939 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
11941 bxe_stats_handle(sc, STATS_EVENT_STOP);
11943 bxe_link_report(sc);
11945 bxe_link_report(sc);
11946 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
11951 bxe_initial_phy_init(struct bxe_softc *sc,
11954 int rc, cfg_idx = bxe_get_link_cfg_idx(sc);
11955 uint16_t req_line_speed = sc->link_params.req_line_speed[cfg_idx];
11956 struct elink_params *lp = &sc->link_params;
11958 bxe_set_requested_fc(sc);
11960 if (CHIP_REV_IS_SLOW(sc)) {
11961 uint32_t bond = CHIP_BOND_ID(sc);
11964 if (CHIP_IS_E2(sc) && CHIP_IS_MODE_4_PORT(sc)) {
11965 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_BMAC;
11966 } else if (bond & 0x4) {
11967 if (CHIP_IS_E3(sc)) {
11968 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_XMAC;
11970 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_BMAC;
11972 } else if (bond & 0x8) {
11973 if (CHIP_IS_E3(sc)) {
11974 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_UMAC;
11976 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_EMAC;
11980 /* disable EMAC for E3 and above */
11982 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_EMAC;
11985 sc->link_params.feature_config_flags |= feat;
11988 bxe_acquire_phy_lock(sc);
11990 if (load_mode == LOAD_DIAG) {
11991 lp->loopback_mode = ELINK_LOOPBACK_XGXS;
11992 /* Prefer doing PHY loopback at 10G speed, if possible */
11993 if (lp->req_line_speed[cfg_idx] < ELINK_SPEED_10000) {
11994 if (lp->speed_cap_mask[cfg_idx] &
11995 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) {
11996 lp->req_line_speed[cfg_idx] = ELINK_SPEED_10000;
11998 lp->req_line_speed[cfg_idx] = ELINK_SPEED_1000;
12003 if (load_mode == LOAD_LOOPBACK_EXT) {
12004 lp->loopback_mode = ELINK_LOOPBACK_EXT;
12007 rc = elink_phy_init(&sc->link_params, &sc->link_vars);
12009 bxe_release_phy_lock(sc);
12011 bxe_calc_fc_adv(sc);
12013 if (sc->link_vars.link_up) {
12014 bxe_stats_handle(sc, STATS_EVENT_LINK_UP);
12015 bxe_link_report(sc);
12018 if (!CHIP_REV_IS_SLOW(sc)) {
12019 bxe_periodic_start(sc);
12022 sc->link_params.req_line_speed[cfg_idx] = req_line_speed;
12027 bxe_push_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt)
12029 struct ecore_mcast_list_elem *mc_mac = arg;
12032 mc_mac->mac = (uint8_t *)LLADDR(sdl);
12038 bxe_init_mcast_macs_list(struct bxe_softc *sc,
12039 struct ecore_mcast_ramrod_params *p)
12041 if_t ifp = sc->ifp;
12043 struct ecore_mcast_list_elem *mc_mac;
12045 ECORE_LIST_INIT(&p->mcast_list);
12046 p->mcast_list_len = 0;
12048 /* XXXGL: multicast count may change later */
12049 mc_count = if_llmaddr_count(ifp);
12055 mc_mac = malloc(sizeof(*mc_mac) * mc_count, M_DEVBUF,
12056 (M_NOWAIT | M_ZERO));
12058 BLOGE(sc, "Failed to allocate temp mcast list\n");
12061 bzero(mc_mac, (sizeof(*mc_mac) * mc_count));
12062 if_foreach_llmaddr(ifp, bxe_push_maddr, mc_mac);
12064 for (int i = 0; i < mc_count; i ++) {
12065 ECORE_LIST_PUSH_TAIL(&mc_mac[i].link, &p->mcast_list);
12066 BLOGD(sc, DBG_LOAD,
12067 "Setting MCAST %02X:%02X:%02X:%02X:%02X:%02X and mc_count %d\n",
12068 mc_mac[i].mac[0], mc_mac[i].mac[1], mc_mac[i].mac[2],
12069 mc_mac[i].mac[3], mc_mac[i].mac[4], mc_mac[i].mac[5],
12073 p->mcast_list_len = mc_count;
12079 bxe_free_mcast_macs_list(struct ecore_mcast_ramrod_params *p)
12081 struct ecore_mcast_list_elem *mc_mac =
12082 ECORE_LIST_FIRST_ENTRY(&p->mcast_list,
12083 struct ecore_mcast_list_elem,
12087 /* only a single free as all mc_macs are in the same heap array */
12088 free(mc_mac, M_DEVBUF);
12092 bxe_set_mc_list(struct bxe_softc *sc)
12094 struct ecore_mcast_ramrod_params rparam = { NULL };
12097 rparam.mcast_obj = &sc->mcast_obj;
12099 BXE_MCAST_LOCK(sc);
12101 /* first, clear all configured multicast MACs */
12102 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL);
12104 BLOGE(sc, "Failed to clear multicast configuration: %d\n", rc);
12105 /* Manual backport parts of FreeBSD upstream r284470. */
12106 BXE_MCAST_UNLOCK(sc);
12110 /* configure a new MACs list */
12111 rc = bxe_init_mcast_macs_list(sc, &rparam);
12113 BLOGE(sc, "Failed to create mcast MACs list (%d)\n", rc);
12114 BXE_MCAST_UNLOCK(sc);
12118 /* Now add the new MACs */
12119 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_ADD);
12121 BLOGE(sc, "Failed to set new mcast config (%d)\n", rc);
12124 bxe_free_mcast_macs_list(&rparam);
12126 BXE_MCAST_UNLOCK(sc);
12131 struct bxe_set_addr_ctx {
12132 struct bxe_softc *sc;
12133 unsigned long ramrod_flags;
12138 bxe_set_addr(void *arg, struct sockaddr_dl *sdl, u_int cnt)
12140 struct bxe_set_addr_ctx *ctx = arg;
12141 struct ecore_vlan_mac_obj *mac_obj = &ctx->sc->sp_objs->mac_obj;
12147 rc = bxe_set_mac_one(ctx->sc, (uint8_t *)LLADDR(sdl), mac_obj, TRUE,
12148 ECORE_UC_LIST_MAC, &ctx->ramrod_flags);
12150 /* do not treat adding same MAC as an error */
12152 BLOGD(ctx->sc, DBG_SP, "Failed to schedule ADD operations (EEXIST)\n");
12154 BLOGE(ctx->sc, "Failed to schedule ADD operations (%d)\n", rc);
12162 bxe_set_uc_list(struct bxe_softc *sc)
12164 if_t ifp = sc->ifp;
12165 struct ecore_vlan_mac_obj *mac_obj = &sc->sp_objs->mac_obj;
12166 struct bxe_set_addr_ctx ctx = { sc, 0, 0 };
12169 /* first schedule a cleanup up of old configuration */
12170 rc = bxe_del_all_macs(sc, mac_obj, ECORE_UC_LIST_MAC, FALSE);
12172 BLOGE(sc, "Failed to schedule delete of all ETH MACs (%d)\n", rc);
12176 if_foreach_lladdr(ifp, bxe_set_addr, &ctx);
12180 /* Execute the pending commands */
12181 bit_set(&ctx.ramrod_flags, RAMROD_CONT);
12182 return (bxe_set_mac_one(sc, NULL, mac_obj, FALSE /* don't care */,
12183 ECORE_UC_LIST_MAC, &ctx.ramrod_flags));
12187 bxe_set_rx_mode(struct bxe_softc *sc)
12189 if_t ifp = sc->ifp;
12190 uint32_t rx_mode = BXE_RX_MODE_NORMAL;
12192 if (sc->state != BXE_STATE_OPEN) {
12193 BLOGD(sc, DBG_SP, "state is %x, returning\n", sc->state);
12197 BLOGD(sc, DBG_SP, "if_flags(ifp)=0x%x\n", if_getflags(sc->ifp));
12199 if (if_getflags(ifp) & IFF_PROMISC) {
12200 rx_mode = BXE_RX_MODE_PROMISC;
12201 } else if ((if_getflags(ifp) & IFF_ALLMULTI) ||
12202 ((if_getamcount(ifp) > BXE_MAX_MULTICAST) &&
12204 rx_mode = BXE_RX_MODE_ALLMULTI;
12207 /* some multicasts */
12208 if (bxe_set_mc_list(sc) < 0) {
12209 rx_mode = BXE_RX_MODE_ALLMULTI;
12211 if (bxe_set_uc_list(sc) < 0) {
12212 rx_mode = BXE_RX_MODE_PROMISC;
12217 sc->rx_mode = rx_mode;
12219 /* schedule the rx_mode command */
12220 if (bxe_test_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state)) {
12221 BLOGD(sc, DBG_LOAD, "Scheduled setting rx_mode with ECORE...\n");
12222 bxe_set_bit(ECORE_FILTER_RX_MODE_SCHED, &sc->sp_state);
12227 bxe_set_storm_rx_mode(sc);
12232 /* update flags in shmem */
12234 bxe_update_drv_flags(struct bxe_softc *sc,
12238 uint32_t drv_flags;
12240 if (SHMEM2_HAS(sc, drv_flags)) {
12241 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_DRV_FLAGS);
12242 drv_flags = SHMEM2_RD(sc, drv_flags);
12245 SET_FLAGS(drv_flags, flags);
12247 RESET_FLAGS(drv_flags, flags);
12250 SHMEM2_WR(sc, drv_flags, drv_flags);
12251 BLOGD(sc, DBG_LOAD, "drv_flags 0x%08x\n", drv_flags);
12253 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_DRV_FLAGS);
12257 /* periodic timer callout routine, only runs when the interface is up */
12260 bxe_periodic_callout_func(void *xsc)
12262 struct bxe_softc *sc = (struct bxe_softc *)xsc;
12265 if (!BXE_CORE_TRYLOCK(sc)) {
12266 /* just bail and try again next time */
12268 if ((sc->state == BXE_STATE_OPEN) &&
12269 (atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_GO)) {
12270 /* schedule the next periodic callout */
12271 callout_reset(&sc->periodic_callout, hz,
12272 bxe_periodic_callout_func, sc);
12278 if ((sc->state != BXE_STATE_OPEN) ||
12279 (atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_STOP)) {
12280 BLOGW(sc, "periodic callout exit (state=0x%x)\n", sc->state);
12281 BXE_CORE_UNLOCK(sc);
12286 /* Check for TX timeouts on any fastpath. */
12287 FOR_EACH_QUEUE(sc, i) {
12288 if (bxe_watchdog(sc, &sc->fp[i]) != 0) {
12289 /* Ruh-Roh, chip was reset! */
12294 if (!CHIP_REV_IS_SLOW(sc)) {
12296 * This barrier is needed to ensure the ordering between the writing
12297 * to the sc->port.pmf in the bxe_nic_load() or bxe_pmf_update() and
12298 * the reading here.
12301 if (sc->port.pmf) {
12302 bxe_acquire_phy_lock(sc);
12303 elink_period_func(&sc->link_params, &sc->link_vars);
12304 bxe_release_phy_lock(sc);
12308 if (IS_PF(sc) && !(sc->flags & BXE_NO_PULSE)) {
12309 int mb_idx = SC_FW_MB_IDX(sc);
12310 uint32_t drv_pulse;
12311 uint32_t mcp_pulse;
12313 ++sc->fw_drv_pulse_wr_seq;
12314 sc->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
12316 drv_pulse = sc->fw_drv_pulse_wr_seq;
12319 mcp_pulse = (SHMEM_RD(sc, func_mb[mb_idx].mcp_pulse_mb) &
12320 MCP_PULSE_SEQ_MASK);
12323 * The delta between driver pulse and mcp response should
12324 * be 1 (before mcp response) or 0 (after mcp response).
12326 if ((drv_pulse != mcp_pulse) &&
12327 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
12328 /* someone lost a heartbeat... */
12329 BLOGE(sc, "drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
12330 drv_pulse, mcp_pulse);
12334 /* state is BXE_STATE_OPEN */
12335 bxe_stats_handle(sc, STATS_EVENT_UPDATE);
12337 BXE_CORE_UNLOCK(sc);
12339 if ((sc->state == BXE_STATE_OPEN) &&
12340 (atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_GO)) {
12341 /* schedule the next periodic callout */
12342 callout_reset(&sc->periodic_callout, hz,
12343 bxe_periodic_callout_func, sc);
12348 bxe_periodic_start(struct bxe_softc *sc)
12350 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_GO);
12351 callout_reset(&sc->periodic_callout, hz, bxe_periodic_callout_func, sc);
12355 bxe_periodic_stop(struct bxe_softc *sc)
12357 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_STOP);
12358 callout_drain(&sc->periodic_callout);
12362 bxe_parity_recover(struct bxe_softc *sc)
12364 uint8_t global = FALSE;
12365 uint32_t error_recovered, error_unrecovered;
12369 if ((sc->recovery_state == BXE_RECOVERY_FAILED) &&
12370 (sc->state == BXE_STATE_ERROR)) {
12371 BLOGE(sc, "RECOVERY failed, "
12372 "stack notified driver is NOT running! "
12373 "Please reboot/power cycle the system.\n");
12379 "%s sc=%p state=0x%x rec_state=0x%x error_status=%x\n",
12380 __func__, sc, sc->state, sc->recovery_state, sc->error_status);
12382 switch(sc->recovery_state) {
12384 case BXE_RECOVERY_INIT:
12385 is_parity = bxe_chk_parity_attn(sc, &global, FALSE);
12387 if ((CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ||
12388 (sc->error_status & BXE_ERR_MCP_ASSERT) ||
12389 (sc->error_status & BXE_ERR_GLOBAL)) {
12392 if (if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING) {
12393 bxe_periodic_stop(sc);
12395 bxe_nic_unload(sc, UNLOAD_RECOVERY, false);
12396 sc->state = BXE_STATE_ERROR;
12397 sc->recovery_state = BXE_RECOVERY_FAILED;
12398 BLOGE(sc, " No Recovery tried for error 0x%x"
12399 " stack notified driver is NOT running!"
12400 " Please reboot/power cycle the system.\n",
12402 BXE_CORE_UNLOCK(sc);
12407 /* Try to get a LEADER_LOCK HW lock */
12408 if (bxe_trylock_leader_lock(sc)) {
12410 bxe_set_reset_in_progress(sc);
12412 * Check if there is a global attention and if
12413 * there was a global attention, set the global
12417 bxe_set_reset_global(sc);
12422 /* If interface has been removed - break */
12424 if (if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING) {
12425 bxe_periodic_stop(sc);
12429 bxe_nic_unload(sc,UNLOAD_RECOVERY, false);
12430 sc->recovery_state = BXE_RECOVERY_WAIT;
12431 BXE_CORE_UNLOCK(sc);
12434 * Ensure "is_leader", MCP command sequence and
12435 * "recovery_state" update values are seen on other
12440 case BXE_RECOVERY_WAIT:
12442 if (sc->is_leader) {
12443 int other_engine = SC_PATH(sc) ? 0 : 1;
12444 bool other_load_status =
12445 bxe_get_load_status(sc, other_engine);
12447 bxe_get_load_status(sc, SC_PATH(sc));
12448 global = bxe_reset_is_global(sc);
12451 * In case of a parity in a global block, let
12452 * the first leader that performs a
12453 * leader_reset() reset the global blocks in
12454 * order to clear global attentions. Otherwise
12455 * the gates will remain closed for that
12459 (global && other_load_status)) {
12461 * Wait until all other functions get
12464 taskqueue_enqueue_timeout(taskqueue_thread,
12465 &sc->sp_err_timeout_task, hz/10);
12469 * If all other functions got down
12470 * try to bring the chip back to
12471 * normal. In any case it's an exit
12472 * point for a leader.
12474 if (bxe_leader_reset(sc)) {
12475 BLOGE(sc, "RECOVERY failed, "
12476 "stack notified driver is NOT running!\n");
12477 sc->recovery_state = BXE_RECOVERY_FAILED;
12478 sc->state = BXE_STATE_ERROR;
12484 * If we are here, means that the
12485 * leader has succeeded and doesn't
12486 * want to be a leader any more. Try
12487 * to continue as a none-leader.
12492 } else { /* non-leader */
12493 if (!bxe_reset_is_done(sc, SC_PATH(sc))) {
12495 * Try to get a LEADER_LOCK HW lock as
12496 * long as a former leader may have
12497 * been unloaded by the user or
12498 * released a leadership by another
12501 if (bxe_trylock_leader_lock(sc)) {
12503 * I'm a leader now! Restart a
12510 taskqueue_enqueue_timeout(taskqueue_thread,
12511 &sc->sp_err_timeout_task, hz/10);
12516 * If there was a global attention, wait
12517 * for it to be cleared.
12519 if (bxe_reset_is_global(sc)) {
12520 taskqueue_enqueue_timeout(taskqueue_thread,
12521 &sc->sp_err_timeout_task, hz/10);
12526 sc->eth_stats.recoverable_error;
12527 error_unrecovered =
12528 sc->eth_stats.unrecoverable_error;
12530 sc->recovery_state =
12531 BXE_RECOVERY_NIC_LOADING;
12532 if (bxe_nic_load(sc, LOAD_NORMAL)) {
12533 error_unrecovered++;
12534 sc->recovery_state = BXE_RECOVERY_FAILED;
12535 sc->state = BXE_STATE_ERROR;
12536 BLOGE(sc, "Recovery is NOT successfull, "
12537 " state=0x%x recovery_state=0x%x error=%x\n",
12538 sc->state, sc->recovery_state, sc->error_status);
12539 sc->error_status = 0;
12541 sc->recovery_state =
12544 BLOGI(sc, "Recovery is successfull from errors %x,"
12546 " recovery_state=0x%x \n", sc->error_status,
12547 sc->state, sc->recovery_state);
12550 sc->error_status = 0;
12551 BXE_CORE_UNLOCK(sc);
12552 sc->eth_stats.recoverable_error =
12554 sc->eth_stats.unrecoverable_error =
12566 bxe_handle_error(struct bxe_softc * sc)
12569 if(sc->recovery_state == BXE_RECOVERY_WAIT) {
12572 if(sc->error_status) {
12573 if (sc->state == BXE_STATE_OPEN) {
12574 bxe_int_disable(sc);
12576 if (sc->link_vars.link_up) {
12577 if_link_state_change(sc->ifp, LINK_STATE_DOWN);
12579 sc->recovery_state = BXE_RECOVERY_INIT;
12580 BLOGI(sc, "bxe%d: Recovery started errors 0x%x recovery state 0x%x\n",
12581 sc->unit, sc->error_status, sc->recovery_state);
12582 bxe_parity_recover(sc);
12587 bxe_sp_err_timeout_task(void *arg, int pending)
12590 struct bxe_softc *sc = (struct bxe_softc *)arg;
12593 "%s state = 0x%x rec state=0x%x error_status=%x\n",
12594 __func__, sc->state, sc->recovery_state, sc->error_status);
12596 if((sc->recovery_state == BXE_RECOVERY_FAILED) &&
12597 (sc->state == BXE_STATE_ERROR)) {
12600 /* if can be taken */
12601 if ((sc->error_status) && (sc->trigger_grcdump)) {
12604 if (sc->recovery_state != BXE_RECOVERY_DONE) {
12605 bxe_handle_error(sc);
12606 bxe_parity_recover(sc);
12607 } else if (sc->error_status) {
12608 bxe_handle_error(sc);
12614 /* start the controller */
12615 static __noinline int
12616 bxe_nic_load(struct bxe_softc *sc,
12623 BXE_CORE_LOCK_ASSERT(sc);
12625 BLOGD(sc, DBG_LOAD, "Starting NIC load...\n");
12627 sc->state = BXE_STATE_OPENING_WAITING_LOAD;
12630 /* must be called before memory allocation and HW init */
12631 bxe_ilt_set_info(sc);
12634 sc->last_reported_link_state = LINK_STATE_UNKNOWN;
12636 bxe_set_fp_rx_buf_size(sc);
12638 if (bxe_alloc_fp_buffers(sc) != 0) {
12639 BLOGE(sc, "Failed to allocate fastpath memory\n");
12640 sc->state = BXE_STATE_CLOSED;
12642 goto bxe_nic_load_error0;
12645 if (bxe_alloc_mem(sc) != 0) {
12646 sc->state = BXE_STATE_CLOSED;
12648 goto bxe_nic_load_error0;
12651 if (bxe_alloc_fw_stats_mem(sc) != 0) {
12652 sc->state = BXE_STATE_CLOSED;
12654 goto bxe_nic_load_error0;
12658 /* set pf load just before approaching the MCP */
12659 bxe_set_pf_load(sc);
12661 /* if MCP exists send load request and analyze response */
12662 if (!BXE_NOMCP(sc)) {
12663 /* attempt to load pf */
12664 if (bxe_nic_load_request(sc, &load_code) != 0) {
12665 sc->state = BXE_STATE_CLOSED;
12667 goto bxe_nic_load_error1;
12670 /* what did the MCP say? */
12671 if (bxe_nic_load_analyze_req(sc, load_code) != 0) {
12672 bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
12673 sc->state = BXE_STATE_CLOSED;
12675 goto bxe_nic_load_error2;
12678 BLOGI(sc, "Device has no MCP!\n");
12679 load_code = bxe_nic_load_no_mcp(sc);
12682 /* mark PMF if applicable */
12683 bxe_nic_load_pmf(sc, load_code);
12685 /* Init Function state controlling object */
12686 bxe_init_func_obj(sc);
12688 /* Initialize HW */
12689 if (bxe_init_hw(sc, load_code) != 0) {
12690 BLOGE(sc, "HW init failed\n");
12691 bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
12692 sc->state = BXE_STATE_CLOSED;
12694 goto bxe_nic_load_error2;
12698 /* set ALWAYS_ALIVE bit in shmem */
12699 sc->fw_drv_pulse_wr_seq |= DRV_PULSE_ALWAYS_ALIVE;
12701 sc->flags |= BXE_NO_PULSE;
12703 /* attach interrupts */
12704 if (bxe_interrupt_attach(sc) != 0) {
12705 sc->state = BXE_STATE_CLOSED;
12707 goto bxe_nic_load_error2;
12710 bxe_nic_init(sc, load_code);
12712 /* Init per-function objects */
12715 // XXX bxe_iov_nic_init(sc);
12717 /* set AFEX default VLAN tag to an invalid value */
12718 sc->devinfo.mf_info.afex_def_vlan_tag = -1;
12719 // XXX bxe_nic_load_afex_dcc(sc, load_code);
12721 sc->state = BXE_STATE_OPENING_WAITING_PORT;
12722 rc = bxe_func_start(sc);
12724 BLOGE(sc, "Function start failed! rc = %d\n", rc);
12725 bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
12726 sc->state = BXE_STATE_ERROR;
12727 goto bxe_nic_load_error3;
12730 /* send LOAD_DONE command to MCP */
12731 if (!BXE_NOMCP(sc)) {
12732 load_code = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
12734 BLOGE(sc, "MCP response failure, aborting\n");
12735 sc->state = BXE_STATE_ERROR;
12737 goto bxe_nic_load_error3;
12741 rc = bxe_setup_leading(sc);
12743 BLOGE(sc, "Setup leading failed! rc = %d\n", rc);
12744 sc->state = BXE_STATE_ERROR;
12745 goto bxe_nic_load_error3;
12748 FOR_EACH_NONDEFAULT_ETH_QUEUE(sc, i) {
12749 rc = bxe_setup_queue(sc, &sc->fp[i], FALSE);
12751 BLOGE(sc, "Queue(%d) setup failed rc = %d\n", i, rc);
12752 sc->state = BXE_STATE_ERROR;
12753 goto bxe_nic_load_error3;
12757 rc = bxe_init_rss_pf(sc);
12759 BLOGE(sc, "PF RSS init failed\n");
12760 sc->state = BXE_STATE_ERROR;
12761 goto bxe_nic_load_error3;
12766 /* now when Clients are configured we are ready to work */
12767 sc->state = BXE_STATE_OPEN;
12769 /* Configure a ucast MAC */
12771 rc = bxe_set_eth_mac(sc, TRUE);
12774 BLOGE(sc, "Setting Ethernet MAC failed rc = %d\n", rc);
12775 sc->state = BXE_STATE_ERROR;
12776 goto bxe_nic_load_error3;
12779 if (sc->port.pmf) {
12780 rc = bxe_initial_phy_init(sc, /* XXX load_mode */LOAD_OPEN);
12782 sc->state = BXE_STATE_ERROR;
12783 goto bxe_nic_load_error3;
12787 sc->link_params.feature_config_flags &=
12788 ~ELINK_FEATURE_CONFIG_BOOT_FROM_SAN;
12790 /* start fast path */
12792 /* Initialize Rx filter */
12793 bxe_set_rx_mode(sc);
12796 switch (/* XXX load_mode */LOAD_OPEN) {
12802 case LOAD_LOOPBACK_EXT:
12803 sc->state = BXE_STATE_DIAG;
12810 if (sc->port.pmf) {
12811 bxe_update_drv_flags(sc, 1 << DRV_FLAGS_PORT_MASK, 0);
12813 bxe_link_status_update(sc);
12816 /* start the periodic timer callout */
12817 bxe_periodic_start(sc);
12819 if (IS_PF(sc) && SHMEM2_HAS(sc, drv_capabilities_flag)) {
12820 /* mark driver is loaded in shmem2 */
12821 val = SHMEM2_RD(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)]);
12822 SHMEM2_WR(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)],
12824 DRV_FLAGS_CAPABILITIES_LOADED_SUPPORTED |
12825 DRV_FLAGS_CAPABILITIES_LOADED_L2));
12828 /* wait for all pending SP commands to complete */
12829 if (IS_PF(sc) && !bxe_wait_sp_comp(sc, ~0x0UL)) {
12830 BLOGE(sc, "Timeout waiting for all SPs to complete!\n");
12831 bxe_periodic_stop(sc);
12832 bxe_nic_unload(sc, UNLOAD_CLOSE, FALSE);
12836 /* Tell the stack the driver is running! */
12837 if_setdrvflags(sc->ifp, IFF_DRV_RUNNING);
12839 BLOGD(sc, DBG_LOAD, "NIC successfully loaded\n");
12843 bxe_nic_load_error3:
12846 bxe_int_disable_sync(sc, 1);
12848 /* clean out queued objects */
12849 bxe_squeeze_objects(sc);
12852 bxe_interrupt_detach(sc);
12854 bxe_nic_load_error2:
12856 if (IS_PF(sc) && !BXE_NOMCP(sc)) {
12857 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
12858 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, 0);
12863 bxe_nic_load_error1:
12865 /* clear pf_load status, as it was already set */
12867 bxe_clear_pf_load(sc);
12870 bxe_nic_load_error0:
12872 bxe_free_fw_stats_mem(sc);
12873 bxe_free_fp_buffers(sc);
12880 bxe_init_locked(struct bxe_softc *sc)
12882 int other_engine = SC_PATH(sc) ? 0 : 1;
12883 uint8_t other_load_status, load_status;
12884 uint8_t global = FALSE;
12887 BXE_CORE_LOCK_ASSERT(sc);
12889 /* check if the driver is already running */
12890 if (if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING) {
12891 BLOGD(sc, DBG_LOAD, "Init called while driver is running!\n");
12895 if((sc->state == BXE_STATE_ERROR) &&
12896 (sc->recovery_state == BXE_RECOVERY_FAILED)) {
12897 BLOGE(sc, "Initialization not done, "
12898 "as previous recovery failed."
12899 "Reboot/Power-cycle the system\n" );
12904 bxe_set_power_state(sc, PCI_PM_D0);
12907 * If parity occurred during the unload, then attentions and/or
12908 * RECOVERY_IN_PROGRES may still be set. If so we want the first function
12909 * loaded on the current engine to complete the recovery. Parity recovery
12910 * is only relevant for PF driver.
12913 other_load_status = bxe_get_load_status(sc, other_engine);
12914 load_status = bxe_get_load_status(sc, SC_PATH(sc));
12916 if (!bxe_reset_is_done(sc, SC_PATH(sc)) ||
12917 bxe_chk_parity_attn(sc, &global, TRUE)) {
12920 * If there are attentions and they are in global blocks, set
12921 * the GLOBAL_RESET bit regardless whether it will be this
12922 * function that will complete the recovery or not.
12925 bxe_set_reset_global(sc);
12929 * Only the first function on the current engine should try
12930 * to recover in open. In case of attentions in global blocks
12931 * only the first in the chip should try to recover.
12933 if ((!load_status && (!global || !other_load_status)) &&
12934 bxe_trylock_leader_lock(sc) && !bxe_leader_reset(sc)) {
12935 BLOGI(sc, "Recovered during init\n");
12939 /* recovery has failed... */
12940 bxe_set_power_state(sc, PCI_PM_D3hot);
12941 sc->recovery_state = BXE_RECOVERY_FAILED;
12943 BLOGE(sc, "Recovery flow hasn't properly "
12944 "completed yet, try again later. "
12945 "If you still see this message after a "
12946 "few retries then power cycle is required.\n");
12949 goto bxe_init_locked_done;
12954 sc->recovery_state = BXE_RECOVERY_DONE;
12956 rc = bxe_nic_load(sc, LOAD_OPEN);
12958 bxe_init_locked_done:
12961 /* Tell the stack the driver is NOT running! */
12962 BLOGE(sc, "Initialization failed, "
12963 "stack notified driver is NOT running!\n");
12964 if_setdrvflagbits(sc->ifp, 0, IFF_DRV_RUNNING);
12971 bxe_stop_locked(struct bxe_softc *sc)
12973 BXE_CORE_LOCK_ASSERT(sc);
12974 return (bxe_nic_unload(sc, UNLOAD_NORMAL, TRUE));
12978 * Handles controller initialization when called from an unlocked routine.
12979 * ifconfig calls this function.
12985 bxe_init(void *xsc)
12987 struct bxe_softc *sc = (struct bxe_softc *)xsc;
12990 bxe_init_locked(sc);
12991 BXE_CORE_UNLOCK(sc);
12995 bxe_init_ifnet(struct bxe_softc *sc)
13000 /* ifconfig entrypoint for media type/status reporting */
13001 ifmedia_init(&sc->ifmedia, IFM_IMASK,
13002 bxe_ifmedia_update,
13003 bxe_ifmedia_status);
13005 /* set the default interface values */
13006 ifmedia_add(&sc->ifmedia, (IFM_ETHER | IFM_FDX | sc->media), 0, NULL);
13007 ifmedia_add(&sc->ifmedia, (IFM_ETHER | IFM_AUTO), 0, NULL);
13008 ifmedia_set(&sc->ifmedia, (IFM_ETHER | IFM_AUTO));
13010 sc->ifmedia.ifm_media = sc->ifmedia.ifm_cur->ifm_media; /* XXX ? */
13011 BLOGI(sc, "IFMEDIA flags : %x\n", sc->ifmedia.ifm_media);
13013 /* allocate the ifnet structure */
13014 if ((ifp = if_gethandle(IFT_ETHER)) == NULL) {
13015 BLOGE(sc, "Interface allocation failed!\n");
13019 if_setsoftc(ifp, sc);
13020 if_initname(ifp, device_get_name(sc->dev), device_get_unit(sc->dev));
13021 if_setflags(ifp, (IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST));
13022 if_setioctlfn(ifp, bxe_ioctl);
13023 if_setstartfn(ifp, bxe_tx_start);
13024 if_setgetcounterfn(ifp, bxe_get_counter);
13025 if_settransmitfn(ifp, bxe_tx_mq_start);
13026 if_setqflushfn(ifp, bxe_mq_flush);
13027 if_setinitfn(ifp, bxe_init);
13028 if_setmtu(ifp, sc->mtu);
13029 if_sethwassist(ifp, (CSUM_IP |
13038 IFCAP_VLAN_HWTAGGING |
13040 IFCAP_VLAN_HWFILTER |
13041 IFCAP_VLAN_HWCSUM |
13048 if_setcapabilitiesbit(ifp, capabilities, 0); /* XXX */
13049 if_setcapenable(ifp, if_getcapabilities(ifp));
13050 if_setbaudrate(ifp, IF_Gbps(10));
13052 if_setsendqlen(ifp, sc->tx_ring_size);
13053 if_setsendqready(ifp);
13058 /* attach to the Ethernet interface list */
13059 ether_ifattach(ifp, sc->link_params.mac_addr);
13061 /* Attach driver debugnet methods. */
13062 DEBUGNET_SET(ifp, bxe);
13068 bxe_deallocate_bars(struct bxe_softc *sc)
13072 for (i = 0; i < MAX_BARS; i++) {
13073 if (sc->bar[i].resource != NULL) {
13074 bus_release_resource(sc->dev,
13077 sc->bar[i].resource);
13078 BLOGD(sc, DBG_LOAD, "Released PCI BAR%d [%02x] memory\n",
13085 bxe_allocate_bars(struct bxe_softc *sc)
13090 memset(sc->bar, 0, sizeof(sc->bar));
13092 for (i = 0; i < MAX_BARS; i++) {
13094 /* memory resources reside at BARs 0, 2, 4 */
13095 /* Run `pciconf -lb` to see mappings */
13096 if ((i != 0) && (i != 2) && (i != 4)) {
13100 sc->bar[i].rid = PCIR_BAR(i);
13104 flags |= RF_SHAREABLE;
13107 if ((sc->bar[i].resource =
13108 bus_alloc_resource_any(sc->dev,
13115 sc->bar[i].tag = rman_get_bustag(sc->bar[i].resource);
13116 sc->bar[i].handle = rman_get_bushandle(sc->bar[i].resource);
13117 sc->bar[i].kva = (vm_offset_t)rman_get_virtual(sc->bar[i].resource);
13119 BLOGI(sc, "PCI BAR%d [%02x] memory allocated: %#jx-%#jx (%jd) -> %#jx\n",
13121 rman_get_start(sc->bar[i].resource),
13122 rman_get_end(sc->bar[i].resource),
13123 rman_get_size(sc->bar[i].resource),
13124 (uintmax_t)sc->bar[i].kva);
13131 bxe_get_function_num(struct bxe_softc *sc)
13136 * Read the ME register to get the function number. The ME register
13137 * holds the relative-function number and absolute-function number. The
13138 * absolute-function number appears only in E2 and above. Before that
13139 * these bits always contained zero, therefore we cannot blindly use them.
13142 val = REG_RD(sc, BAR_ME_REGISTER);
13145 (uint8_t)((val & ME_REG_PF_NUM) >> ME_REG_PF_NUM_SHIFT);
13147 (uint8_t)((val & ME_REG_ABS_PF_NUM) >> ME_REG_ABS_PF_NUM_SHIFT) & 1;
13149 if (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) {
13150 sc->pfunc_abs = ((sc->pfunc_rel << 1) | sc->path_id);
13152 sc->pfunc_abs = (sc->pfunc_rel | sc->path_id);
13155 BLOGD(sc, DBG_LOAD,
13156 "Relative function %d, Absolute function %d, Path %d\n",
13157 sc->pfunc_rel, sc->pfunc_abs, sc->path_id);
13161 bxe_get_shmem_mf_cfg_base(struct bxe_softc *sc)
13163 uint32_t shmem2_size;
13165 uint32_t mf_cfg_offset_value;
13168 offset = (SHMEM_RD(sc, func_mb) +
13169 (MAX_FUNC_NUM * sizeof(struct drv_func_mb)));
13172 if (sc->devinfo.shmem2_base != 0) {
13173 shmem2_size = SHMEM2_RD(sc, size);
13174 if (shmem2_size > offsetof(struct shmem2_region, mf_cfg_addr)) {
13175 mf_cfg_offset_value = SHMEM2_RD(sc, mf_cfg_addr);
13176 if (SHMEM_MF_CFG_ADDR_NONE != mf_cfg_offset_value) {
13177 offset = mf_cfg_offset_value;
13186 bxe_pcie_capability_read(struct bxe_softc *sc,
13192 /* ensure PCIe capability is enabled */
13193 if (pci_find_cap(sc->dev, PCIY_EXPRESS, &pcie_reg) == 0) {
13194 if (pcie_reg != 0) {
13195 BLOGD(sc, DBG_LOAD, "PCIe capability at 0x%04x\n", pcie_reg);
13196 return (pci_read_config(sc->dev, (pcie_reg + reg), width));
13200 BLOGE(sc, "PCIe capability NOT FOUND!!!\n");
13206 bxe_is_pcie_pending(struct bxe_softc *sc)
13208 return (bxe_pcie_capability_read(sc, PCIER_DEVICE_STA, 2) &
13209 PCIEM_STA_TRANSACTION_PND);
13213 * Walk the PCI capabiites list for the device to find what features are
13214 * supported. These capabilites may be enabled/disabled by firmware so it's
13215 * best to walk the list rather than make assumptions.
13218 bxe_probe_pci_caps(struct bxe_softc *sc)
13220 uint16_t link_status;
13223 /* check if PCI Power Management is enabled */
13224 if (pci_find_cap(sc->dev, PCIY_PMG, ®) == 0) {
13226 BLOGD(sc, DBG_LOAD, "Found PM capability at 0x%04x\n", reg);
13228 sc->devinfo.pcie_cap_flags |= BXE_PM_CAPABLE_FLAG;
13229 sc->devinfo.pcie_pm_cap_reg = (uint16_t)reg;
13233 link_status = bxe_pcie_capability_read(sc, PCIER_LINK_STA, 2);
13235 /* handle PCIe 2.0 workarounds for 57710 */
13236 if (CHIP_IS_E1(sc)) {
13237 /* workaround for 57710 errata E4_57710_27462 */
13238 sc->devinfo.pcie_link_speed =
13239 (REG_RD(sc, 0x3d04) & (1 << 24)) ? 2 : 1;
13241 /* workaround for 57710 errata E4_57710_27488 */
13242 sc->devinfo.pcie_link_width =
13243 ((link_status & PCIEM_LINK_STA_WIDTH) >> 4);
13244 if (sc->devinfo.pcie_link_speed > 1) {
13245 sc->devinfo.pcie_link_width =
13246 ((link_status & PCIEM_LINK_STA_WIDTH) >> 4) >> 1;
13249 sc->devinfo.pcie_link_speed =
13250 (link_status & PCIEM_LINK_STA_SPEED);
13251 sc->devinfo.pcie_link_width =
13252 ((link_status & PCIEM_LINK_STA_WIDTH) >> 4);
13255 BLOGD(sc, DBG_LOAD, "PCIe link speed=%d width=%d\n",
13256 sc->devinfo.pcie_link_speed, sc->devinfo.pcie_link_width);
13258 sc->devinfo.pcie_cap_flags |= BXE_PCIE_CAPABLE_FLAG;
13259 sc->devinfo.pcie_pcie_cap_reg = (uint16_t)reg;
13261 /* check if MSI capability is enabled */
13262 if (pci_find_cap(sc->dev, PCIY_MSI, ®) == 0) {
13264 BLOGD(sc, DBG_LOAD, "Found MSI capability at 0x%04x\n", reg);
13266 sc->devinfo.pcie_cap_flags |= BXE_MSI_CAPABLE_FLAG;
13267 sc->devinfo.pcie_msi_cap_reg = (uint16_t)reg;
13271 /* check if MSI-X capability is enabled */
13272 if (pci_find_cap(sc->dev, PCIY_MSIX, ®) == 0) {
13274 BLOGD(sc, DBG_LOAD, "Found MSI-X capability at 0x%04x\n", reg);
13276 sc->devinfo.pcie_cap_flags |= BXE_MSIX_CAPABLE_FLAG;
13277 sc->devinfo.pcie_msix_cap_reg = (uint16_t)reg;
13283 bxe_get_shmem_mf_cfg_info_sd(struct bxe_softc *sc)
13285 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13288 /* get the outer vlan if we're in switch-dependent mode */
13290 val = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag);
13291 mf_info->ext_id = (uint16_t)val;
13293 mf_info->multi_vnics_mode = 1;
13295 if (!VALID_OVLAN(mf_info->ext_id)) {
13296 BLOGE(sc, "Invalid VLAN (%d)\n", mf_info->ext_id);
13300 /* get the capabilities */
13301 if ((mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_PROTOCOL_MASK) ==
13302 FUNC_MF_CFG_PROTOCOL_ISCSI) {
13303 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_ISCSI;
13304 } else if ((mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_PROTOCOL_MASK) ==
13305 FUNC_MF_CFG_PROTOCOL_FCOE) {
13306 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_FCOE;
13308 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_ETHERNET;
13311 mf_info->vnics_per_port =
13312 (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4;
13318 bxe_get_shmem_ext_proto_support_flags(struct bxe_softc *sc)
13320 uint32_t retval = 0;
13323 val = MFCFG_RD(sc, func_ext_config[SC_ABS_FUNC(sc)].func_cfg);
13325 if (val & MACP_FUNC_CFG_FLAGS_ENABLED) {
13326 if (val & MACP_FUNC_CFG_FLAGS_ETHERNET) {
13327 retval |= MF_PROTO_SUPPORT_ETHERNET;
13329 if (val & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
13330 retval |= MF_PROTO_SUPPORT_ISCSI;
13332 if (val & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
13333 retval |= MF_PROTO_SUPPORT_FCOE;
13341 bxe_get_shmem_mf_cfg_info_si(struct bxe_softc *sc)
13343 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13347 * There is no outer vlan if we're in switch-independent mode.
13348 * If the mac is valid then assume multi-function.
13351 val = MFCFG_RD(sc, func_ext_config[SC_ABS_FUNC(sc)].func_cfg);
13353 mf_info->multi_vnics_mode = ((val & MACP_FUNC_CFG_FLAGS_MASK) != 0);
13355 mf_info->mf_protos_supported = bxe_get_shmem_ext_proto_support_flags(sc);
13357 mf_info->vnics_per_port =
13358 (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4;
13364 bxe_get_shmem_mf_cfg_info_niv(struct bxe_softc *sc)
13366 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13367 uint32_t e1hov_tag;
13368 uint32_t func_config;
13369 uint32_t niv_config;
13371 mf_info->multi_vnics_mode = 1;
13373 e1hov_tag = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag);
13374 func_config = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config);
13375 niv_config = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].afex_config);
13378 (uint16_t)((e1hov_tag & FUNC_MF_CFG_E1HOV_TAG_MASK) >>
13379 FUNC_MF_CFG_E1HOV_TAG_SHIFT);
13381 mf_info->default_vlan =
13382 (uint16_t)((e1hov_tag & FUNC_MF_CFG_AFEX_VLAN_MASK) >>
13383 FUNC_MF_CFG_AFEX_VLAN_SHIFT);
13385 mf_info->niv_allowed_priorities =
13386 (uint8_t)((niv_config & FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
13387 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT);
13389 mf_info->niv_default_cos =
13390 (uint8_t)((func_config & FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
13391 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT);
13393 mf_info->afex_vlan_mode =
13394 ((niv_config & FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
13395 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT);
13397 mf_info->niv_mba_enabled =
13398 ((niv_config & FUNC_MF_CFG_AFEX_MBA_ENABLED_MASK) >>
13399 FUNC_MF_CFG_AFEX_MBA_ENABLED_SHIFT);
13401 mf_info->mf_protos_supported = bxe_get_shmem_ext_proto_support_flags(sc);
13403 mf_info->vnics_per_port =
13404 (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4;
13410 bxe_check_valid_mf_cfg(struct bxe_softc *sc)
13412 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13419 BLOGD(sc, DBG_LOAD, "MF config parameters for function %d\n",
13421 BLOGD(sc, DBG_LOAD, "\tmf_config=0x%x\n",
13422 mf_info->mf_config[SC_VN(sc)]);
13423 BLOGD(sc, DBG_LOAD, "\tmulti_vnics_mode=%d\n",
13424 mf_info->multi_vnics_mode);
13425 BLOGD(sc, DBG_LOAD, "\tvnics_per_port=%d\n",
13426 mf_info->vnics_per_port);
13427 BLOGD(sc, DBG_LOAD, "\tovlan/vifid=%d\n",
13429 BLOGD(sc, DBG_LOAD, "\tmin_bw=%d/%d/%d/%d\n",
13430 mf_info->min_bw[0], mf_info->min_bw[1],
13431 mf_info->min_bw[2], mf_info->min_bw[3]);
13432 BLOGD(sc, DBG_LOAD, "\tmax_bw=%d/%d/%d/%d\n",
13433 mf_info->max_bw[0], mf_info->max_bw[1],
13434 mf_info->max_bw[2], mf_info->max_bw[3]);
13435 BLOGD(sc, DBG_LOAD, "\tmac_addr: %s\n",
13438 /* various MF mode sanity checks... */
13440 if (mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_FUNC_HIDE) {
13441 BLOGE(sc, "Enumerated function %d is marked as hidden\n",
13446 if ((mf_info->vnics_per_port > 1) && !mf_info->multi_vnics_mode) {
13447 BLOGE(sc, "vnics_per_port=%d multi_vnics_mode=%d\n",
13448 mf_info->vnics_per_port, mf_info->multi_vnics_mode);
13452 if (mf_info->mf_mode == MULTI_FUNCTION_SD) {
13453 /* vnic id > 0 must have valid ovlan in switch-dependent mode */
13454 if ((SC_VN(sc) > 0) && !VALID_OVLAN(OVLAN(sc))) {
13455 BLOGE(sc, "mf_mode=SD vnic_id=%d ovlan=%d\n",
13456 SC_VN(sc), OVLAN(sc));
13460 if (!VALID_OVLAN(OVLAN(sc)) && mf_info->multi_vnics_mode) {
13461 BLOGE(sc, "mf_mode=SD multi_vnics_mode=%d ovlan=%d\n",
13462 mf_info->multi_vnics_mode, OVLAN(sc));
13467 * Verify all functions are either MF or SF mode. If MF, make sure
13468 * sure that all non-hidden functions have a valid ovlan. If SF,
13469 * make sure that all non-hidden functions have an invalid ovlan.
13471 FOREACH_ABS_FUNC_IN_PORT(sc, i) {
13472 mf_cfg1 = MFCFG_RD(sc, func_mf_config[i].config);
13473 ovlan1 = MFCFG_RD(sc, func_mf_config[i].e1hov_tag);
13474 if (!(mf_cfg1 & FUNC_MF_CFG_FUNC_HIDE) &&
13475 (((mf_info->multi_vnics_mode) && !VALID_OVLAN(ovlan1)) ||
13476 ((!mf_info->multi_vnics_mode) && VALID_OVLAN(ovlan1)))) {
13477 BLOGE(sc, "mf_mode=SD function %d MF config "
13478 "mismatch, multi_vnics_mode=%d ovlan=%d\n",
13479 i, mf_info->multi_vnics_mode, ovlan1);
13484 /* Verify all funcs on the same port each have a different ovlan. */
13485 FOREACH_ABS_FUNC_IN_PORT(sc, i) {
13486 mf_cfg1 = MFCFG_RD(sc, func_mf_config[i].config);
13487 ovlan1 = MFCFG_RD(sc, func_mf_config[i].e1hov_tag);
13488 /* iterate from the next function on the port to the max func */
13489 for (j = i + 2; j < MAX_FUNC_NUM; j += 2) {
13490 mf_cfg2 = MFCFG_RD(sc, func_mf_config[j].config);
13491 ovlan2 = MFCFG_RD(sc, func_mf_config[j].e1hov_tag);
13492 if (!(mf_cfg1 & FUNC_MF_CFG_FUNC_HIDE) &&
13493 VALID_OVLAN(ovlan1) &&
13494 !(mf_cfg2 & FUNC_MF_CFG_FUNC_HIDE) &&
13495 VALID_OVLAN(ovlan2) &&
13496 (ovlan1 == ovlan2)) {
13497 BLOGE(sc, "mf_mode=SD functions %d and %d "
13498 "have the same ovlan (%d)\n",
13504 } /* MULTI_FUNCTION_SD */
13510 bxe_get_mf_cfg_info(struct bxe_softc *sc)
13512 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info;
13513 uint32_t val, mac_upper;
13516 /* initialize mf_info defaults */
13517 mf_info->vnics_per_port = 1;
13518 mf_info->multi_vnics_mode = FALSE;
13519 mf_info->path_has_ovlan = FALSE;
13520 mf_info->mf_mode = SINGLE_FUNCTION;
13522 if (!CHIP_IS_MF_CAP(sc)) {
13526 if (sc->devinfo.mf_cfg_base == SHMEM_MF_CFG_ADDR_NONE) {
13527 BLOGE(sc, "Invalid mf_cfg_base!\n");
13531 /* get the MF mode (switch dependent / independent / single-function) */
13533 val = SHMEM_RD(sc, dev_info.shared_feature_config.config);
13535 switch (val & SHARED_FEAT_CFG_FORCE_SF_MODE_MASK)
13537 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
13539 mac_upper = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper);
13541 /* check for legal upper mac bytes */
13542 if (mac_upper != FUNC_MF_CFG_UPPERMAC_DEFAULT) {
13543 mf_info->mf_mode = MULTI_FUNCTION_SI;
13545 BLOGE(sc, "Invalid config for Switch Independent mode\n");
13550 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
13551 case SHARED_FEAT_CFG_FORCE_SF_MODE_SPIO4:
13553 /* get outer vlan configuration */
13554 val = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag);
13556 if ((val & FUNC_MF_CFG_E1HOV_TAG_MASK) !=
13557 FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
13558 mf_info->mf_mode = MULTI_FUNCTION_SD;
13560 BLOGE(sc, "Invalid config for Switch Dependent mode\n");
13565 case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
13567 /* not in MF mode, vnics_per_port=1 and multi_vnics_mode=FALSE */
13570 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
13573 * Mark MF mode as NIV if MCP version includes NPAR-SD support
13574 * and the MAC address is valid.
13576 mac_upper = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper);
13578 if ((SHMEM2_HAS(sc, afex_driver_support)) &&
13579 (mac_upper != FUNC_MF_CFG_UPPERMAC_DEFAULT)) {
13580 mf_info->mf_mode = MULTI_FUNCTION_AFEX;
13582 BLOGE(sc, "Invalid config for AFEX mode\n");
13589 BLOGE(sc, "Unknown MF mode (0x%08x)\n",
13590 (val & SHARED_FEAT_CFG_FORCE_SF_MODE_MASK));
13595 /* set path mf_mode (which could be different than function mf_mode) */
13596 if (mf_info->mf_mode == MULTI_FUNCTION_SD) {
13597 mf_info->path_has_ovlan = TRUE;
13598 } else if (mf_info->mf_mode == SINGLE_FUNCTION) {
13600 * Decide on path multi vnics mode. If we're not in MF mode and in
13601 * 4-port mode, this is good enough to check vnic-0 of the other port
13604 if (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) {
13605 uint8_t other_port = !(PORT_ID(sc) & 1);
13606 uint8_t abs_func_other_port = (SC_PATH(sc) + (2 * other_port));
13608 val = MFCFG_RD(sc, func_mf_config[abs_func_other_port].e1hov_tag);
13610 mf_info->path_has_ovlan = VALID_OVLAN((uint16_t)val) ? 1 : 0;
13614 if (mf_info->mf_mode == SINGLE_FUNCTION) {
13615 /* invalid MF config */
13616 if (SC_VN(sc) >= 1) {
13617 BLOGE(sc, "VNIC ID >= 1 in SF mode\n");
13624 /* get the MF configuration */
13625 mf_info->mf_config[SC_VN(sc)] =
13626 MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config);
13628 switch(mf_info->mf_mode)
13630 case MULTI_FUNCTION_SD:
13632 bxe_get_shmem_mf_cfg_info_sd(sc);
13635 case MULTI_FUNCTION_SI:
13637 bxe_get_shmem_mf_cfg_info_si(sc);
13640 case MULTI_FUNCTION_AFEX:
13642 bxe_get_shmem_mf_cfg_info_niv(sc);
13647 BLOGE(sc, "Get MF config failed (mf_mode=0x%08x)\n",
13652 /* get the congestion management parameters */
13655 FOREACH_ABS_FUNC_IN_PORT(sc, i) {
13656 /* get min/max bw */
13657 val = MFCFG_RD(sc, func_mf_config[i].config);
13658 mf_info->min_bw[vnic] =
13659 ((val & FUNC_MF_CFG_MIN_BW_MASK) >> FUNC_MF_CFG_MIN_BW_SHIFT);
13660 mf_info->max_bw[vnic] =
13661 ((val & FUNC_MF_CFG_MAX_BW_MASK) >> FUNC_MF_CFG_MAX_BW_SHIFT);
13665 return (bxe_check_valid_mf_cfg(sc));
13669 bxe_get_shmem_info(struct bxe_softc *sc)
13672 uint32_t mac_hi, mac_lo, val;
13674 port = SC_PORT(sc);
13675 mac_hi = mac_lo = 0;
13677 sc->link_params.sc = sc;
13678 sc->link_params.port = port;
13680 /* get the hardware config info */
13681 sc->devinfo.hw_config =
13682 SHMEM_RD(sc, dev_info.shared_hw_config.config);
13683 sc->devinfo.hw_config2 =
13684 SHMEM_RD(sc, dev_info.shared_hw_config.config2);
13686 sc->link_params.hw_led_mode =
13687 ((sc->devinfo.hw_config & SHARED_HW_CFG_LED_MODE_MASK) >>
13688 SHARED_HW_CFG_LED_MODE_SHIFT);
13690 /* get the port feature config */
13692 SHMEM_RD(sc, dev_info.port_feature_config[port].config);
13694 /* get the link params */
13695 sc->link_params.speed_cap_mask[0] =
13696 SHMEM_RD(sc, dev_info.port_hw_config[port].speed_capability_mask);
13697 sc->link_params.speed_cap_mask[1] =
13698 SHMEM_RD(sc, dev_info.port_hw_config[port].speed_capability_mask2);
13700 /* get the lane config */
13701 sc->link_params.lane_config =
13702 SHMEM_RD(sc, dev_info.port_hw_config[port].lane_config);
13704 /* get the link config */
13705 val = SHMEM_RD(sc, dev_info.port_feature_config[port].link_config);
13706 sc->port.link_config[ELINK_INT_PHY] = val;
13707 sc->link_params.switch_cfg = (val & PORT_FEATURE_CONNECTED_SWITCH_MASK);
13708 sc->port.link_config[ELINK_EXT_PHY1] =
13709 SHMEM_RD(sc, dev_info.port_feature_config[port].link_config2);
13711 /* get the override preemphasis flag and enable it or turn it off */
13712 val = SHMEM_RD(sc, dev_info.shared_feature_config.config);
13713 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED) {
13714 sc->link_params.feature_config_flags |=
13715 ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
13717 sc->link_params.feature_config_flags &=
13718 ~ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
13721 /* get the initial value of the link params */
13722 sc->link_params.multi_phy_config =
13723 SHMEM_RD(sc, dev_info.port_hw_config[port].multi_phy_config);
13725 /* get external phy info */
13726 sc->port.ext_phy_config =
13727 SHMEM_RD(sc, dev_info.port_hw_config[port].external_phy_config);
13729 /* get the multifunction configuration */
13730 bxe_get_mf_cfg_info(sc);
13732 /* get the mac address */
13734 mac_hi = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper);
13735 mac_lo = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_lower);
13737 mac_hi = SHMEM_RD(sc, dev_info.port_hw_config[port].mac_upper);
13738 mac_lo = SHMEM_RD(sc, dev_info.port_hw_config[port].mac_lower);
13741 if ((mac_lo == 0) && (mac_hi == 0)) {
13742 *sc->mac_addr_str = 0;
13743 BLOGE(sc, "No Ethernet address programmed!\n");
13745 sc->link_params.mac_addr[0] = (uint8_t)(mac_hi >> 8);
13746 sc->link_params.mac_addr[1] = (uint8_t)(mac_hi);
13747 sc->link_params.mac_addr[2] = (uint8_t)(mac_lo >> 24);
13748 sc->link_params.mac_addr[3] = (uint8_t)(mac_lo >> 16);
13749 sc->link_params.mac_addr[4] = (uint8_t)(mac_lo >> 8);
13750 sc->link_params.mac_addr[5] = (uint8_t)(mac_lo);
13751 snprintf(sc->mac_addr_str, sizeof(sc->mac_addr_str),
13752 "%02x:%02x:%02x:%02x:%02x:%02x",
13753 sc->link_params.mac_addr[0], sc->link_params.mac_addr[1],
13754 sc->link_params.mac_addr[2], sc->link_params.mac_addr[3],
13755 sc->link_params.mac_addr[4], sc->link_params.mac_addr[5]);
13756 BLOGD(sc, DBG_LOAD, "Ethernet address: %s\n", sc->mac_addr_str);
13763 bxe_get_tunable_params(struct bxe_softc *sc)
13765 /* sanity checks */
13767 if ((bxe_interrupt_mode != INTR_MODE_INTX) &&
13768 (bxe_interrupt_mode != INTR_MODE_MSI) &&
13769 (bxe_interrupt_mode != INTR_MODE_MSIX)) {
13770 BLOGW(sc, "invalid interrupt_mode value (%d)\n", bxe_interrupt_mode);
13771 bxe_interrupt_mode = INTR_MODE_MSIX;
13774 if ((bxe_queue_count < 0) || (bxe_queue_count > MAX_RSS_CHAINS)) {
13775 BLOGW(sc, "invalid queue_count value (%d)\n", bxe_queue_count);
13776 bxe_queue_count = 0;
13779 if ((bxe_max_rx_bufs < 1) || (bxe_max_rx_bufs > RX_BD_USABLE)) {
13780 if (bxe_max_rx_bufs == 0) {
13781 bxe_max_rx_bufs = RX_BD_USABLE;
13783 BLOGW(sc, "invalid max_rx_bufs (%d)\n", bxe_max_rx_bufs);
13784 bxe_max_rx_bufs = 2048;
13788 if ((bxe_hc_rx_ticks < 1) || (bxe_hc_rx_ticks > 100)) {
13789 BLOGW(sc, "invalid hc_rx_ticks (%d)\n", bxe_hc_rx_ticks);
13790 bxe_hc_rx_ticks = 25;
13793 if ((bxe_hc_tx_ticks < 1) || (bxe_hc_tx_ticks > 100)) {
13794 BLOGW(sc, "invalid hc_tx_ticks (%d)\n", bxe_hc_tx_ticks);
13795 bxe_hc_tx_ticks = 50;
13798 if (bxe_max_aggregation_size == 0) {
13799 bxe_max_aggregation_size = TPA_AGG_SIZE;
13802 if (bxe_max_aggregation_size > 0xffff) {
13803 BLOGW(sc, "invalid max_aggregation_size (%d)\n",
13804 bxe_max_aggregation_size);
13805 bxe_max_aggregation_size = TPA_AGG_SIZE;
13808 if ((bxe_mrrs < -1) || (bxe_mrrs > 3)) {
13809 BLOGW(sc, "invalid mrrs (%d)\n", bxe_mrrs);
13813 if ((bxe_autogreeen < 0) || (bxe_autogreeen > 2)) {
13814 BLOGW(sc, "invalid autogreeen (%d)\n", bxe_autogreeen);
13815 bxe_autogreeen = 0;
13818 if ((bxe_udp_rss < 0) || (bxe_udp_rss > 1)) {
13819 BLOGW(sc, "invalid udp_rss (%d)\n", bxe_udp_rss);
13823 /* pull in user settings */
13825 sc->interrupt_mode = bxe_interrupt_mode;
13826 sc->max_rx_bufs = bxe_max_rx_bufs;
13827 sc->hc_rx_ticks = bxe_hc_rx_ticks;
13828 sc->hc_tx_ticks = bxe_hc_tx_ticks;
13829 sc->max_aggregation_size = bxe_max_aggregation_size;
13830 sc->mrrs = bxe_mrrs;
13831 sc->autogreeen = bxe_autogreeen;
13832 sc->udp_rss = bxe_udp_rss;
13834 if (bxe_interrupt_mode == INTR_MODE_INTX) {
13835 sc->num_queues = 1;
13836 } else { /* INTR_MODE_MSI or INTR_MODE_MSIX */
13838 min((bxe_queue_count ? bxe_queue_count : mp_ncpus),
13840 if (sc->num_queues > mp_ncpus) {
13841 sc->num_queues = mp_ncpus;
13845 BLOGD(sc, DBG_LOAD,
13848 "interrupt_mode=%d "
13853 "max_aggregation_size=%d "
13858 sc->interrupt_mode,
13863 sc->max_aggregation_size,
13870 bxe_media_detect(struct bxe_softc *sc)
13873 uint32_t phy_idx = bxe_get_cur_phy_idx(sc);
13875 switch (sc->link_params.phy[phy_idx].media_type) {
13876 case ELINK_ETH_PHY_SFPP_10G_FIBER:
13877 case ELINK_ETH_PHY_XFP_FIBER:
13878 BLOGI(sc, "Found 10Gb Fiber media.\n");
13879 sc->media = IFM_10G_SR;
13880 port_type = PORT_FIBRE;
13882 case ELINK_ETH_PHY_SFP_1G_FIBER:
13883 BLOGI(sc, "Found 1Gb Fiber media.\n");
13884 sc->media = IFM_1000_SX;
13885 port_type = PORT_FIBRE;
13887 case ELINK_ETH_PHY_KR:
13888 case ELINK_ETH_PHY_CX4:
13889 BLOGI(sc, "Found 10GBase-CX4 media.\n");
13890 sc->media = IFM_10G_CX4;
13891 port_type = PORT_FIBRE;
13893 case ELINK_ETH_PHY_DA_TWINAX:
13894 BLOGI(sc, "Found 10Gb Twinax media.\n");
13895 sc->media = IFM_10G_TWINAX;
13896 port_type = PORT_DA;
13898 case ELINK_ETH_PHY_BASE_T:
13899 if (sc->link_params.speed_cap_mask[0] &
13900 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) {
13901 BLOGI(sc, "Found 10GBase-T media.\n");
13902 sc->media = IFM_10G_T;
13903 port_type = PORT_TP;
13905 BLOGI(sc, "Found 1000Base-T media.\n");
13906 sc->media = IFM_1000_T;
13907 port_type = PORT_TP;
13910 case ELINK_ETH_PHY_NOT_PRESENT:
13911 BLOGI(sc, "Media not present.\n");
13913 port_type = PORT_OTHER;
13915 case ELINK_ETH_PHY_UNSPECIFIED:
13917 BLOGI(sc, "Unknown media!\n");
13919 port_type = PORT_OTHER;
13925 #define GET_FIELD(value, fname) \
13926 (((value) & (fname##_MASK)) >> (fname##_SHIFT))
13927 #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
13928 #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
13931 bxe_get_igu_cam_info(struct bxe_softc *sc)
13933 int pfid = SC_FUNC(sc);
13936 uint8_t fid, igu_sb_cnt = 0;
13938 sc->igu_base_sb = 0xff;
13940 if (CHIP_INT_MODE_IS_BC(sc)) {
13941 int vn = SC_VN(sc);
13942 igu_sb_cnt = sc->igu_sb_cnt;
13943 sc->igu_base_sb = ((CHIP_IS_MODE_4_PORT(sc) ? pfid : vn) *
13945 sc->igu_dsb_id = (E1HVN_MAX * FP_SB_MAX_E1x +
13946 (CHIP_IS_MODE_4_PORT(sc) ? pfid : vn));
13950 /* IGU in normal mode - read CAM */
13951 for (igu_sb_id = 0;
13952 igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
13954 val = REG_RD(sc, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
13955 if (!(val & IGU_REG_MAPPING_MEMORY_VALID)) {
13958 fid = IGU_FID(val);
13959 if ((fid & IGU_FID_ENCODE_IS_PF)) {
13960 if ((fid & IGU_FID_PF_NUM_MASK) != pfid) {
13963 if (IGU_VEC(val) == 0) {
13964 /* default status block */
13965 sc->igu_dsb_id = igu_sb_id;
13967 if (sc->igu_base_sb == 0xff) {
13968 sc->igu_base_sb = igu_sb_id;
13976 * Due to new PF resource allocation by MFW T7.4 and above, it's optional
13977 * that number of CAM entries will not be equal to the value advertised in
13978 * PCI. Driver should use the minimal value of both as the actual status
13981 sc->igu_sb_cnt = min(sc->igu_sb_cnt, igu_sb_cnt);
13983 if (igu_sb_cnt == 0) {
13984 BLOGE(sc, "CAM configuration error\n");
13992 * Gather various information from the device config space, the device itself,
13993 * shmem, and the user input.
13996 bxe_get_device_info(struct bxe_softc *sc)
14001 /* Get the data for the device */
14002 sc->devinfo.vendor_id = pci_get_vendor(sc->dev);
14003 sc->devinfo.device_id = pci_get_device(sc->dev);
14004 sc->devinfo.subvendor_id = pci_get_subvendor(sc->dev);
14005 sc->devinfo.subdevice_id = pci_get_subdevice(sc->dev);
14007 /* get the chip revision (chip metal comes from pci config space) */
14008 sc->devinfo.chip_id =
14009 sc->link_params.chip_id =
14010 (((REG_RD(sc, MISC_REG_CHIP_NUM) & 0xffff) << 16) |
14011 ((REG_RD(sc, MISC_REG_CHIP_REV) & 0xf) << 12) |
14012 (((REG_RD(sc, PCICFG_OFFSET + PCI_ID_VAL3) >> 24) & 0xf) << 4) |
14013 ((REG_RD(sc, MISC_REG_BOND_ID) & 0xf) << 0));
14015 /* force 57811 according to MISC register */
14016 if (REG_RD(sc, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
14017 if (CHIP_IS_57810(sc)) {
14018 sc->devinfo.chip_id = ((CHIP_NUM_57811 << 16) |
14019 (sc->devinfo.chip_id & 0x0000ffff));
14020 } else if (CHIP_IS_57810_MF(sc)) {
14021 sc->devinfo.chip_id = ((CHIP_NUM_57811_MF << 16) |
14022 (sc->devinfo.chip_id & 0x0000ffff));
14024 sc->devinfo.chip_id |= 0x1;
14027 BLOGD(sc, DBG_LOAD,
14028 "chip_id=0x%08x (num=0x%04x rev=0x%01x metal=0x%02x bond=0x%01x)\n",
14029 sc->devinfo.chip_id,
14030 ((sc->devinfo.chip_id >> 16) & 0xffff),
14031 ((sc->devinfo.chip_id >> 12) & 0xf),
14032 ((sc->devinfo.chip_id >> 4) & 0xff),
14033 ((sc->devinfo.chip_id >> 0) & 0xf));
14035 val = (REG_RD(sc, 0x2874) & 0x55);
14036 if ((sc->devinfo.chip_id & 0x1) ||
14037 (CHIP_IS_E1(sc) && val) ||
14038 (CHIP_IS_E1H(sc) && (val == 0x55))) {
14039 sc->flags |= BXE_ONE_PORT_FLAG;
14040 BLOGD(sc, DBG_LOAD, "single port device\n");
14043 /* set the doorbell size */
14044 sc->doorbell_size = (1 << BXE_DB_SHIFT);
14046 /* determine whether the device is in 2 port or 4 port mode */
14047 sc->devinfo.chip_port_mode = CHIP_PORT_MODE_NONE; /* E1 & E1h*/
14048 if (CHIP_IS_E2E3(sc)) {
14050 * Read port4mode_en_ovwr[0]:
14051 * If 1, four port mode is in port4mode_en_ovwr[1].
14052 * If 0, four port mode is in port4mode_en[0].
14054 val = REG_RD(sc, MISC_REG_PORT4MODE_EN_OVWR);
14056 val = ((val >> 1) & 1);
14058 val = REG_RD(sc, MISC_REG_PORT4MODE_EN);
14061 sc->devinfo.chip_port_mode =
14062 (val) ? CHIP_4_PORT_MODE : CHIP_2_PORT_MODE;
14064 BLOGD(sc, DBG_LOAD, "Port mode = %s\n", (val) ? "4" : "2");
14067 /* get the function and path info for the device */
14068 bxe_get_function_num(sc);
14070 /* get the shared memory base address */
14071 sc->devinfo.shmem_base =
14072 sc->link_params.shmem_base =
14073 REG_RD(sc, MISC_REG_SHARED_MEM_ADDR);
14074 sc->devinfo.shmem2_base =
14075 REG_RD(sc, (SC_PATH(sc) ? MISC_REG_GENERIC_CR_1 :
14076 MISC_REG_GENERIC_CR_0));
14078 BLOGD(sc, DBG_LOAD, "shmem_base=0x%08x, shmem2_base=0x%08x\n",
14079 sc->devinfo.shmem_base, sc->devinfo.shmem2_base);
14081 if (!sc->devinfo.shmem_base) {
14082 /* this should ONLY prevent upcoming shmem reads */
14083 BLOGI(sc, "MCP not active\n");
14084 sc->flags |= BXE_NO_MCP_FLAG;
14088 /* make sure the shared memory contents are valid */
14089 val = SHMEM_RD(sc, validity_map[SC_PORT(sc)]);
14090 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) !=
14091 (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) {
14092 BLOGE(sc, "Invalid SHMEM validity signature: 0x%08x\n", val);
14095 BLOGD(sc, DBG_LOAD, "Valid SHMEM validity signature: 0x%08x\n", val);
14097 /* get the bootcode version */
14098 sc->devinfo.bc_ver = SHMEM_RD(sc, dev_info.bc_rev);
14099 snprintf(sc->devinfo.bc_ver_str,
14100 sizeof(sc->devinfo.bc_ver_str),
14102 ((sc->devinfo.bc_ver >> 24) & 0xff),
14103 ((sc->devinfo.bc_ver >> 16) & 0xff),
14104 ((sc->devinfo.bc_ver >> 8) & 0xff));
14105 BLOGD(sc, DBG_LOAD, "Bootcode version: %s\n", sc->devinfo.bc_ver_str);
14107 /* get the bootcode shmem address */
14108 sc->devinfo.mf_cfg_base = bxe_get_shmem_mf_cfg_base(sc);
14109 BLOGD(sc, DBG_LOAD, "mf_cfg_base=0x08%x \n", sc->devinfo.mf_cfg_base);
14111 /* clean indirect addresses as they're not used */
14112 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, 0, 4);
14114 REG_WR(sc, PXP2_REG_PGL_ADDR_88_F0, 0);
14115 REG_WR(sc, PXP2_REG_PGL_ADDR_8C_F0, 0);
14116 REG_WR(sc, PXP2_REG_PGL_ADDR_90_F0, 0);
14117 REG_WR(sc, PXP2_REG_PGL_ADDR_94_F0, 0);
14118 if (CHIP_IS_E1x(sc)) {
14119 REG_WR(sc, PXP2_REG_PGL_ADDR_88_F1, 0);
14120 REG_WR(sc, PXP2_REG_PGL_ADDR_8C_F1, 0);
14121 REG_WR(sc, PXP2_REG_PGL_ADDR_90_F1, 0);
14122 REG_WR(sc, PXP2_REG_PGL_ADDR_94_F1, 0);
14126 * Enable internal target-read (in case we are probed after PF
14127 * FLR). Must be done prior to any BAR read access. Only for
14130 if (!CHIP_IS_E1x(sc)) {
14131 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
14135 /* get the nvram size */
14136 val = REG_RD(sc, MCP_REG_MCPR_NVM_CFG4);
14137 sc->devinfo.flash_size =
14138 (NVRAM_1MB_SIZE << (val & MCPR_NVM_CFG4_FLASH_SIZE));
14139 BLOGD(sc, DBG_LOAD, "nvram flash size: %d\n", sc->devinfo.flash_size);
14141 /* get PCI capabilites */
14142 bxe_probe_pci_caps(sc);
14144 bxe_set_power_state(sc, PCI_PM_D0);
14146 /* get various configuration parameters from shmem */
14147 bxe_get_shmem_info(sc);
14149 if (sc->devinfo.pcie_msix_cap_reg != 0) {
14150 val = pci_read_config(sc->dev,
14151 (sc->devinfo.pcie_msix_cap_reg +
14154 sc->igu_sb_cnt = (val & PCIM_MSIXCTRL_TABLE_SIZE);
14156 sc->igu_sb_cnt = 1;
14159 sc->igu_base_addr = BAR_IGU_INTMEM;
14161 /* initialize IGU parameters */
14162 if (CHIP_IS_E1x(sc)) {
14163 sc->devinfo.int_block = INT_BLOCK_HC;
14164 sc->igu_dsb_id = DEF_SB_IGU_ID;
14165 sc->igu_base_sb = 0;
14167 sc->devinfo.int_block = INT_BLOCK_IGU;
14169 /* do not allow device reset during IGU info preocessing */
14170 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
14172 val = REG_RD(sc, IGU_REG_BLOCK_CONFIGURATION);
14174 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
14177 BLOGD(sc, DBG_LOAD, "FORCING IGU Normal Mode\n");
14179 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
14180 REG_WR(sc, IGU_REG_BLOCK_CONFIGURATION, val);
14181 REG_WR(sc, IGU_REG_RESET_MEMORIES, 0x7f);
14183 while (tout && REG_RD(sc, IGU_REG_RESET_MEMORIES)) {
14188 if (REG_RD(sc, IGU_REG_RESET_MEMORIES)) {
14189 BLOGD(sc, DBG_LOAD, "FORCING IGU Normal Mode failed!!!\n");
14190 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
14195 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
14196 BLOGD(sc, DBG_LOAD, "IGU Backward Compatible Mode\n");
14197 sc->devinfo.int_block |= INT_BLOCK_MODE_BW_COMP;
14199 BLOGD(sc, DBG_LOAD, "IGU Normal Mode\n");
14202 rc = bxe_get_igu_cam_info(sc);
14204 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
14212 * Get base FW non-default (fast path) status block ID. This value is
14213 * used to initialize the fw_sb_id saved on the fp/queue structure to
14214 * determine the id used by the FW.
14216 if (CHIP_IS_E1x(sc)) {
14217 sc->base_fw_ndsb = ((SC_PORT(sc) * FP_SB_MAX_E1x) + SC_L_ID(sc));
14220 * 57712+ - We currently use one FW SB per IGU SB (Rx and Tx of
14221 * the same queue are indicated on the same IGU SB). So we prefer
14222 * FW and IGU SBs to be the same value.
14224 sc->base_fw_ndsb = sc->igu_base_sb;
14227 BLOGD(sc, DBG_LOAD,
14228 "igu_dsb_id=%d igu_base_sb=%d igu_sb_cnt=%d base_fw_ndsb=%d\n",
14229 sc->igu_dsb_id, sc->igu_base_sb,
14230 sc->igu_sb_cnt, sc->base_fw_ndsb);
14232 elink_phy_probe(&sc->link_params);
14238 bxe_link_settings_supported(struct bxe_softc *sc,
14239 uint32_t switch_cfg)
14241 uint32_t cfg_size = 0;
14243 uint8_t port = SC_PORT(sc);
14245 /* aggregation of supported attributes of all external phys */
14246 sc->port.supported[0] = 0;
14247 sc->port.supported[1] = 0;
14249 switch (sc->link_params.num_phys) {
14251 sc->port.supported[0] = sc->link_params.phy[ELINK_INT_PHY].supported;
14255 sc->port.supported[0] = sc->link_params.phy[ELINK_EXT_PHY1].supported;
14259 if (sc->link_params.multi_phy_config &
14260 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
14261 sc->port.supported[1] =
14262 sc->link_params.phy[ELINK_EXT_PHY1].supported;
14263 sc->port.supported[0] =
14264 sc->link_params.phy[ELINK_EXT_PHY2].supported;
14266 sc->port.supported[0] =
14267 sc->link_params.phy[ELINK_EXT_PHY1].supported;
14268 sc->port.supported[1] =
14269 sc->link_params.phy[ELINK_EXT_PHY2].supported;
14275 if (!(sc->port.supported[0] || sc->port.supported[1])) {
14276 BLOGE(sc, "Invalid phy config in NVRAM (PHY1=0x%08x PHY2=0x%08x)\n",
14278 dev_info.port_hw_config[port].external_phy_config),
14280 dev_info.port_hw_config[port].external_phy_config2));
14284 if (CHIP_IS_E3(sc))
14285 sc->port.phy_addr = REG_RD(sc, MISC_REG_WC0_CTRL_PHY_ADDR);
14287 switch (switch_cfg) {
14288 case ELINK_SWITCH_CFG_1G:
14289 sc->port.phy_addr =
14290 REG_RD(sc, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
14292 case ELINK_SWITCH_CFG_10G:
14293 sc->port.phy_addr =
14294 REG_RD(sc, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
14297 BLOGE(sc, "Invalid switch config in link_config=0x%08x\n",
14298 sc->port.link_config[0]);
14303 BLOGD(sc, DBG_LOAD, "PHY addr 0x%08x\n", sc->port.phy_addr);
14305 /* mask what we support according to speed_cap_mask per configuration */
14306 for (idx = 0; idx < cfg_size; idx++) {
14307 if (!(sc->link_params.speed_cap_mask[idx] &
14308 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) {
14309 sc->port.supported[idx] &= ~ELINK_SUPPORTED_10baseT_Half;
14312 if (!(sc->link_params.speed_cap_mask[idx] &
14313 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL)) {
14314 sc->port.supported[idx] &= ~ELINK_SUPPORTED_10baseT_Full;
14317 if (!(sc->link_params.speed_cap_mask[idx] &
14318 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)) {
14319 sc->port.supported[idx] &= ~ELINK_SUPPORTED_100baseT_Half;
14322 if (!(sc->link_params.speed_cap_mask[idx] &
14323 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL)) {
14324 sc->port.supported[idx] &= ~ELINK_SUPPORTED_100baseT_Full;
14327 if (!(sc->link_params.speed_cap_mask[idx] &
14328 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) {
14329 sc->port.supported[idx] &= ~ELINK_SUPPORTED_1000baseT_Full;
14332 if (!(sc->link_params.speed_cap_mask[idx] &
14333 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)) {
14334 sc->port.supported[idx] &= ~ELINK_SUPPORTED_2500baseX_Full;
14337 if (!(sc->link_params.speed_cap_mask[idx] &
14338 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
14339 sc->port.supported[idx] &= ~ELINK_SUPPORTED_10000baseT_Full;
14342 if (!(sc->link_params.speed_cap_mask[idx] &
14343 PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)) {
14344 sc->port.supported[idx] &= ~ELINK_SUPPORTED_20000baseKR2_Full;
14348 BLOGD(sc, DBG_LOAD, "PHY supported 0=0x%08x 1=0x%08x\n",
14349 sc->port.supported[0], sc->port.supported[1]);
14350 ELINK_DEBUG_P2(sc, "PHY supported 0=0x%08x 1=0x%08x\n",
14351 sc->port.supported[0], sc->port.supported[1]);
14355 bxe_link_settings_requested(struct bxe_softc *sc)
14357 uint32_t link_config;
14359 uint32_t cfg_size = 0;
14361 sc->port.advertising[0] = 0;
14362 sc->port.advertising[1] = 0;
14364 switch (sc->link_params.num_phys) {
14374 for (idx = 0; idx < cfg_size; idx++) {
14375 sc->link_params.req_duplex[idx] = DUPLEX_FULL;
14376 link_config = sc->port.link_config[idx];
14378 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
14379 case PORT_FEATURE_LINK_SPEED_AUTO:
14380 if (sc->port.supported[idx] & ELINK_SUPPORTED_Autoneg) {
14381 sc->link_params.req_line_speed[idx] = ELINK_SPEED_AUTO_NEG;
14382 sc->port.advertising[idx] |= sc->port.supported[idx];
14383 if (sc->link_params.phy[ELINK_EXT_PHY1].type ==
14384 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
14385 sc->port.advertising[idx] |=
14386 (ELINK_SUPPORTED_100baseT_Half |
14387 ELINK_SUPPORTED_100baseT_Full);
14389 /* force 10G, no AN */
14390 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10000;
14391 sc->port.advertising[idx] |=
14392 (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
14397 case PORT_FEATURE_LINK_SPEED_10M_FULL:
14398 if (sc->port.supported[idx] & ELINK_SUPPORTED_10baseT_Full) {
14399 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10;
14400 sc->port.advertising[idx] |= (ADVERTISED_10baseT_Full |
14403 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14404 "speed_cap_mask=0x%08x\n",
14405 link_config, sc->link_params.speed_cap_mask[idx]);
14410 case PORT_FEATURE_LINK_SPEED_10M_HALF:
14411 if (sc->port.supported[idx] & ELINK_SUPPORTED_10baseT_Half) {
14412 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10;
14413 sc->link_params.req_duplex[idx] = DUPLEX_HALF;
14414 sc->port.advertising[idx] |= (ADVERTISED_10baseT_Half |
14416 ELINK_DEBUG_P1(sc, "driver requesting DUPLEX_HALF req_duplex = %x!\n",
14417 sc->link_params.req_duplex[idx]);
14419 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14420 "speed_cap_mask=0x%08x\n",
14421 link_config, sc->link_params.speed_cap_mask[idx]);
14426 case PORT_FEATURE_LINK_SPEED_100M_FULL:
14427 if (sc->port.supported[idx] & ELINK_SUPPORTED_100baseT_Full) {
14428 sc->link_params.req_line_speed[idx] = ELINK_SPEED_100;
14429 sc->port.advertising[idx] |= (ADVERTISED_100baseT_Full |
14432 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14433 "speed_cap_mask=0x%08x\n",
14434 link_config, sc->link_params.speed_cap_mask[idx]);
14439 case PORT_FEATURE_LINK_SPEED_100M_HALF:
14440 if (sc->port.supported[idx] & ELINK_SUPPORTED_100baseT_Half) {
14441 sc->link_params.req_line_speed[idx] = ELINK_SPEED_100;
14442 sc->link_params.req_duplex[idx] = DUPLEX_HALF;
14443 sc->port.advertising[idx] |= (ADVERTISED_100baseT_Half |
14446 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14447 "speed_cap_mask=0x%08x\n",
14448 link_config, sc->link_params.speed_cap_mask[idx]);
14453 case PORT_FEATURE_LINK_SPEED_1G:
14454 if (sc->port.supported[idx] & ELINK_SUPPORTED_1000baseT_Full) {
14455 sc->link_params.req_line_speed[idx] = ELINK_SPEED_1000;
14456 sc->port.advertising[idx] |= (ADVERTISED_1000baseT_Full |
14459 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14460 "speed_cap_mask=0x%08x\n",
14461 link_config, sc->link_params.speed_cap_mask[idx]);
14466 case PORT_FEATURE_LINK_SPEED_2_5G:
14467 if (sc->port.supported[idx] & ELINK_SUPPORTED_2500baseX_Full) {
14468 sc->link_params.req_line_speed[idx] = ELINK_SPEED_2500;
14469 sc->port.advertising[idx] |= (ADVERTISED_2500baseX_Full |
14472 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14473 "speed_cap_mask=0x%08x\n",
14474 link_config, sc->link_params.speed_cap_mask[idx]);
14479 case PORT_FEATURE_LINK_SPEED_10G_CX4:
14480 if (sc->port.supported[idx] & ELINK_SUPPORTED_10000baseT_Full) {
14481 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10000;
14482 sc->port.advertising[idx] |= (ADVERTISED_10000baseT_Full |
14485 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14486 "speed_cap_mask=0x%08x\n",
14487 link_config, sc->link_params.speed_cap_mask[idx]);
14492 case PORT_FEATURE_LINK_SPEED_20G:
14493 sc->link_params.req_line_speed[idx] = ELINK_SPEED_20000;
14497 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x "
14498 "speed_cap_mask=0x%08x\n",
14499 link_config, sc->link_params.speed_cap_mask[idx]);
14500 sc->link_params.req_line_speed[idx] = ELINK_SPEED_AUTO_NEG;
14501 sc->port.advertising[idx] = sc->port.supported[idx];
14505 sc->link_params.req_flow_ctrl[idx] =
14506 (link_config & PORT_FEATURE_FLOW_CONTROL_MASK);
14508 if (sc->link_params.req_flow_ctrl[idx] == ELINK_FLOW_CTRL_AUTO) {
14509 if (!(sc->port.supported[idx] & ELINK_SUPPORTED_Autoneg)) {
14510 sc->link_params.req_flow_ctrl[idx] = ELINK_FLOW_CTRL_NONE;
14512 bxe_set_requested_fc(sc);
14516 BLOGD(sc, DBG_LOAD, "req_line_speed=%d req_duplex=%d "
14517 "req_flow_ctrl=0x%x advertising=0x%x\n",
14518 sc->link_params.req_line_speed[idx],
14519 sc->link_params.req_duplex[idx],
14520 sc->link_params.req_flow_ctrl[idx],
14521 sc->port.advertising[idx]);
14522 ELINK_DEBUG_P3(sc, "req_line_speed=%d req_duplex=%d "
14523 "advertising=0x%x\n",
14524 sc->link_params.req_line_speed[idx],
14525 sc->link_params.req_duplex[idx],
14526 sc->port.advertising[idx]);
14531 bxe_get_phy_info(struct bxe_softc *sc)
14533 uint8_t port = SC_PORT(sc);
14534 uint32_t config = sc->port.config;
14537 /* shmem data already read in bxe_get_shmem_info() */
14539 ELINK_DEBUG_P3(sc, "lane_config=0x%08x speed_cap_mask0=0x%08x "
14540 "link_config0=0x%08x\n",
14541 sc->link_params.lane_config,
14542 sc->link_params.speed_cap_mask[0],
14543 sc->port.link_config[0]);
14546 bxe_link_settings_supported(sc, sc->link_params.switch_cfg);
14547 bxe_link_settings_requested(sc);
14549 if (sc->autogreeen == AUTO_GREEN_FORCE_ON) {
14550 sc->link_params.feature_config_flags |=
14551 ELINK_FEATURE_CONFIG_AUTOGREEEN_ENABLED;
14552 } else if (sc->autogreeen == AUTO_GREEN_FORCE_OFF) {
14553 sc->link_params.feature_config_flags &=
14554 ~ELINK_FEATURE_CONFIG_AUTOGREEEN_ENABLED;
14555 } else if (config & PORT_FEAT_CFG_AUTOGREEEN_ENABLED) {
14556 sc->link_params.feature_config_flags |=
14557 ELINK_FEATURE_CONFIG_AUTOGREEEN_ENABLED;
14560 /* configure link feature according to nvram value */
14562 (((SHMEM_RD(sc, dev_info.port_feature_config[port].eee_power_mode)) &
14563 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
14564 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
14565 if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
14566 sc->link_params.eee_mode = (ELINK_EEE_MODE_ADV_LPI |
14567 ELINK_EEE_MODE_ENABLE_LPI |
14568 ELINK_EEE_MODE_OUTPUT_TIME);
14570 sc->link_params.eee_mode = 0;
14573 /* get the media type */
14574 bxe_media_detect(sc);
14575 ELINK_DEBUG_P1(sc, "detected media type\n", sc->media);
14579 bxe_get_params(struct bxe_softc *sc)
14581 /* get user tunable params */
14582 bxe_get_tunable_params(sc);
14584 /* select the RX and TX ring sizes */
14585 sc->tx_ring_size = TX_BD_USABLE;
14586 sc->rx_ring_size = RX_BD_USABLE;
14588 /* XXX disable WoL */
14593 bxe_set_modes_bitmap(struct bxe_softc *sc)
14595 uint32_t flags = 0;
14597 if (CHIP_REV_IS_FPGA(sc)) {
14598 SET_FLAGS(flags, MODE_FPGA);
14599 } else if (CHIP_REV_IS_EMUL(sc)) {
14600 SET_FLAGS(flags, MODE_EMUL);
14602 SET_FLAGS(flags, MODE_ASIC);
14605 if (CHIP_IS_MODE_4_PORT(sc)) {
14606 SET_FLAGS(flags, MODE_PORT4);
14608 SET_FLAGS(flags, MODE_PORT2);
14611 if (CHIP_IS_E2(sc)) {
14612 SET_FLAGS(flags, MODE_E2);
14613 } else if (CHIP_IS_E3(sc)) {
14614 SET_FLAGS(flags, MODE_E3);
14615 if (CHIP_REV(sc) == CHIP_REV_Ax) {
14616 SET_FLAGS(flags, MODE_E3_A0);
14617 } else /*if (CHIP_REV(sc) == CHIP_REV_Bx)*/ {
14618 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
14623 SET_FLAGS(flags, MODE_MF);
14624 switch (sc->devinfo.mf_info.mf_mode) {
14625 case MULTI_FUNCTION_SD:
14626 SET_FLAGS(flags, MODE_MF_SD);
14628 case MULTI_FUNCTION_SI:
14629 SET_FLAGS(flags, MODE_MF_SI);
14631 case MULTI_FUNCTION_AFEX:
14632 SET_FLAGS(flags, MODE_MF_AFEX);
14636 SET_FLAGS(flags, MODE_SF);
14639 #if defined(__LITTLE_ENDIAN)
14640 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
14641 #else /* __BIG_ENDIAN */
14642 SET_FLAGS(flags, MODE_BIG_ENDIAN);
14645 INIT_MODE_FLAGS(sc) = flags;
14649 bxe_alloc_hsi_mem(struct bxe_softc *sc)
14651 struct bxe_fastpath *fp;
14652 bus_addr_t busaddr;
14653 int max_agg_queues;
14655 bus_size_t max_size;
14656 bus_size_t max_seg_size;
14661 /* XXX zero out all vars here and call bxe_alloc_hsi_mem on error */
14663 /* allocate the parent bus DMA tag */
14664 rc = bus_dma_tag_create(bus_get_dma_tag(sc->dev), /* parent tag */
14666 0, /* boundary limit */
14667 BUS_SPACE_MAXADDR, /* restricted low */
14668 BUS_SPACE_MAXADDR, /* restricted hi */
14669 NULL, /* addr filter() */
14670 NULL, /* addr filter() arg */
14671 BUS_SPACE_MAXSIZE_32BIT, /* max map size */
14672 BUS_SPACE_UNRESTRICTED, /* num discontinuous */
14673 BUS_SPACE_MAXSIZE_32BIT, /* max seg size */
14676 NULL, /* lock() arg */
14677 &sc->parent_dma_tag); /* returned dma tag */
14679 BLOGE(sc, "Failed to alloc parent DMA tag (%d)!\n", rc);
14683 /************************/
14684 /* DEFAULT STATUS BLOCK */
14685 /************************/
14687 if (bxe_dma_alloc(sc, sizeof(struct host_sp_status_block),
14688 &sc->def_sb_dma, "default status block") != 0) {
14690 bus_dma_tag_destroy(sc->parent_dma_tag);
14694 sc->def_sb = (struct host_sp_status_block *)sc->def_sb_dma.vaddr;
14700 if (bxe_dma_alloc(sc, BCM_PAGE_SIZE,
14701 &sc->eq_dma, "event queue") != 0) {
14703 bxe_dma_free(sc, &sc->def_sb_dma);
14705 bus_dma_tag_destroy(sc->parent_dma_tag);
14709 sc->eq = (union event_ring_elem * )sc->eq_dma.vaddr;
14715 if (bxe_dma_alloc(sc, sizeof(struct bxe_slowpath),
14716 &sc->sp_dma, "slow path") != 0) {
14718 bxe_dma_free(sc, &sc->eq_dma);
14720 bxe_dma_free(sc, &sc->def_sb_dma);
14722 bus_dma_tag_destroy(sc->parent_dma_tag);
14726 sc->sp = (struct bxe_slowpath *)sc->sp_dma.vaddr;
14728 /*******************/
14729 /* SLOW PATH QUEUE */
14730 /*******************/
14732 if (bxe_dma_alloc(sc, BCM_PAGE_SIZE,
14733 &sc->spq_dma, "slow path queue") != 0) {
14735 bxe_dma_free(sc, &sc->sp_dma);
14737 bxe_dma_free(sc, &sc->eq_dma);
14739 bxe_dma_free(sc, &sc->def_sb_dma);
14741 bus_dma_tag_destroy(sc->parent_dma_tag);
14745 sc->spq = (struct eth_spe *)sc->spq_dma.vaddr;
14747 /***************************/
14748 /* FW DECOMPRESSION BUFFER */
14749 /***************************/
14751 if (bxe_dma_alloc(sc, FW_BUF_SIZE, &sc->gz_buf_dma,
14752 "fw decompression buffer") != 0) {
14754 bxe_dma_free(sc, &sc->spq_dma);
14756 bxe_dma_free(sc, &sc->sp_dma);
14758 bxe_dma_free(sc, &sc->eq_dma);
14760 bxe_dma_free(sc, &sc->def_sb_dma);
14762 bus_dma_tag_destroy(sc->parent_dma_tag);
14766 sc->gz_buf = (void *)sc->gz_buf_dma.vaddr;
14769 malloc(sizeof(*sc->gz_strm), M_DEVBUF, M_NOWAIT)) == NULL) {
14771 bxe_dma_free(sc, &sc->gz_buf_dma);
14773 bxe_dma_free(sc, &sc->spq_dma);
14775 bxe_dma_free(sc, &sc->sp_dma);
14777 bxe_dma_free(sc, &sc->eq_dma);
14779 bxe_dma_free(sc, &sc->def_sb_dma);
14781 bus_dma_tag_destroy(sc->parent_dma_tag);
14789 /* allocate DMA memory for each fastpath structure */
14790 for (i = 0; i < sc->num_queues; i++) {
14795 /*******************/
14796 /* FP STATUS BLOCK */
14797 /*******************/
14799 snprintf(buf, sizeof(buf), "fp %d status block", i);
14800 if (bxe_dma_alloc(sc, sizeof(union bxe_host_hc_status_block),
14801 &fp->sb_dma, buf) != 0) {
14802 /* XXX unwind and free previous fastpath allocations */
14803 BLOGE(sc, "Failed to alloc %s\n", buf);
14806 if (CHIP_IS_E2E3(sc)) {
14807 fp->status_block.e2_sb =
14808 (struct host_hc_status_block_e2 *)fp->sb_dma.vaddr;
14810 fp->status_block.e1x_sb =
14811 (struct host_hc_status_block_e1x *)fp->sb_dma.vaddr;
14815 /******************/
14816 /* FP TX BD CHAIN */
14817 /******************/
14819 snprintf(buf, sizeof(buf), "fp %d tx bd chain", i);
14820 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * TX_BD_NUM_PAGES),
14821 &fp->tx_dma, buf) != 0) {
14822 /* XXX unwind and free previous fastpath allocations */
14823 BLOGE(sc, "Failed to alloc %s\n", buf);
14826 fp->tx_chain = (union eth_tx_bd_types *)fp->tx_dma.vaddr;
14829 /* link together the tx bd chain pages */
14830 for (j = 1; j <= TX_BD_NUM_PAGES; j++) {
14831 /* index into the tx bd chain array to last entry per page */
14832 struct eth_tx_next_bd *tx_next_bd =
14833 &fp->tx_chain[TX_BD_TOTAL_PER_PAGE * j - 1].next_bd;
14834 /* point to the next page and wrap from last page */
14835 busaddr = (fp->tx_dma.paddr +
14836 (BCM_PAGE_SIZE * (j % TX_BD_NUM_PAGES)));
14837 tx_next_bd->addr_hi = htole32(U64_HI(busaddr));
14838 tx_next_bd->addr_lo = htole32(U64_LO(busaddr));
14841 /******************/
14842 /* FP RX BD CHAIN */
14843 /******************/
14845 snprintf(buf, sizeof(buf), "fp %d rx bd chain", i);
14846 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * RX_BD_NUM_PAGES),
14847 &fp->rx_dma, buf) != 0) {
14848 /* XXX unwind and free previous fastpath allocations */
14849 BLOGE(sc, "Failed to alloc %s\n", buf);
14852 fp->rx_chain = (struct eth_rx_bd *)fp->rx_dma.vaddr;
14855 /* link together the rx bd chain pages */
14856 for (j = 1; j <= RX_BD_NUM_PAGES; j++) {
14857 /* index into the rx bd chain array to last entry per page */
14858 struct eth_rx_bd *rx_bd =
14859 &fp->rx_chain[RX_BD_TOTAL_PER_PAGE * j - 2];
14860 /* point to the next page and wrap from last page */
14861 busaddr = (fp->rx_dma.paddr +
14862 (BCM_PAGE_SIZE * (j % RX_BD_NUM_PAGES)));
14863 rx_bd->addr_hi = htole32(U64_HI(busaddr));
14864 rx_bd->addr_lo = htole32(U64_LO(busaddr));
14867 /*******************/
14868 /* FP RX RCQ CHAIN */
14869 /*******************/
14871 snprintf(buf, sizeof(buf), "fp %d rcq chain", i);
14872 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * RCQ_NUM_PAGES),
14873 &fp->rcq_dma, buf) != 0) {
14874 /* XXX unwind and free previous fastpath allocations */
14875 BLOGE(sc, "Failed to alloc %s\n", buf);
14878 fp->rcq_chain = (union eth_rx_cqe *)fp->rcq_dma.vaddr;
14881 /* link together the rcq chain pages */
14882 for (j = 1; j <= RCQ_NUM_PAGES; j++) {
14883 /* index into the rcq chain array to last entry per page */
14884 struct eth_rx_cqe_next_page *rx_cqe_next =
14885 (struct eth_rx_cqe_next_page *)
14886 &fp->rcq_chain[RCQ_TOTAL_PER_PAGE * j - 1];
14887 /* point to the next page and wrap from last page */
14888 busaddr = (fp->rcq_dma.paddr +
14889 (BCM_PAGE_SIZE * (j % RCQ_NUM_PAGES)));
14890 rx_cqe_next->addr_hi = htole32(U64_HI(busaddr));
14891 rx_cqe_next->addr_lo = htole32(U64_LO(busaddr));
14894 /*******************/
14895 /* FP RX SGE CHAIN */
14896 /*******************/
14898 snprintf(buf, sizeof(buf), "fp %d sge chain", i);
14899 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * RX_SGE_NUM_PAGES),
14900 &fp->rx_sge_dma, buf) != 0) {
14901 /* XXX unwind and free previous fastpath allocations */
14902 BLOGE(sc, "Failed to alloc %s\n", buf);
14905 fp->rx_sge_chain = (struct eth_rx_sge *)fp->rx_sge_dma.vaddr;
14908 /* link together the sge chain pages */
14909 for (j = 1; j <= RX_SGE_NUM_PAGES; j++) {
14910 /* index into the rcq chain array to last entry per page */
14911 struct eth_rx_sge *rx_sge =
14912 &fp->rx_sge_chain[RX_SGE_TOTAL_PER_PAGE * j - 2];
14913 /* point to the next page and wrap from last page */
14914 busaddr = (fp->rx_sge_dma.paddr +
14915 (BCM_PAGE_SIZE * (j % RX_SGE_NUM_PAGES)));
14916 rx_sge->addr_hi = htole32(U64_HI(busaddr));
14917 rx_sge->addr_lo = htole32(U64_LO(busaddr));
14920 /***********************/
14921 /* FP TX MBUF DMA MAPS */
14922 /***********************/
14924 /* set required sizes before mapping to conserve resources */
14925 if (if_getcapenable(sc->ifp) & (IFCAP_TSO4 | IFCAP_TSO6)) {
14926 max_size = BXE_TSO_MAX_SIZE;
14927 max_segments = BXE_TSO_MAX_SEGMENTS;
14928 max_seg_size = BXE_TSO_MAX_SEG_SIZE;
14930 max_size = (MCLBYTES * BXE_MAX_SEGMENTS);
14931 max_segments = BXE_MAX_SEGMENTS;
14932 max_seg_size = MCLBYTES;
14935 /* create a dma tag for the tx mbufs */
14936 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */
14938 0, /* boundary limit */
14939 BUS_SPACE_MAXADDR, /* restricted low */
14940 BUS_SPACE_MAXADDR, /* restricted hi */
14941 NULL, /* addr filter() */
14942 NULL, /* addr filter() arg */
14943 max_size, /* max map size */
14944 max_segments, /* num discontinuous */
14945 max_seg_size, /* max seg size */
14948 NULL, /* lock() arg */
14949 &fp->tx_mbuf_tag); /* returned dma tag */
14951 /* XXX unwind and free previous fastpath allocations */
14952 BLOGE(sc, "Failed to create dma tag for "
14953 "'fp %d tx mbufs' (%d)\n", i, rc);
14957 /* create dma maps for each of the tx mbuf clusters */
14958 for (j = 0; j < TX_BD_TOTAL; j++) {
14959 if (bus_dmamap_create(fp->tx_mbuf_tag,
14961 &fp->tx_mbuf_chain[j].m_map)) {
14962 /* XXX unwind and free previous fastpath allocations */
14963 BLOGE(sc, "Failed to create dma map for "
14964 "'fp %d tx mbuf %d' (%d)\n", i, j, rc);
14969 /***********************/
14970 /* FP RX MBUF DMA MAPS */
14971 /***********************/
14973 /* create a dma tag for the rx mbufs */
14974 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */
14976 0, /* boundary limit */
14977 BUS_SPACE_MAXADDR, /* restricted low */
14978 BUS_SPACE_MAXADDR, /* restricted hi */
14979 NULL, /* addr filter() */
14980 NULL, /* addr filter() arg */
14981 MJUM9BYTES, /* max map size */
14982 1, /* num discontinuous */
14983 MJUM9BYTES, /* max seg size */
14986 NULL, /* lock() arg */
14987 &fp->rx_mbuf_tag); /* returned dma tag */
14989 /* XXX unwind and free previous fastpath allocations */
14990 BLOGE(sc, "Failed to create dma tag for "
14991 "'fp %d rx mbufs' (%d)\n", i, rc);
14995 /* create dma maps for each of the rx mbuf clusters */
14996 for (j = 0; j < RX_BD_TOTAL; j++) {
14997 if (bus_dmamap_create(fp->rx_mbuf_tag,
14999 &fp->rx_mbuf_chain[j].m_map)) {
15000 /* XXX unwind and free previous fastpath allocations */
15001 BLOGE(sc, "Failed to create dma map for "
15002 "'fp %d rx mbuf %d' (%d)\n", i, j, rc);
15007 /* create dma map for the spare rx mbuf cluster */
15008 if (bus_dmamap_create(fp->rx_mbuf_tag,
15010 &fp->rx_mbuf_spare_map)) {
15011 /* XXX unwind and free previous fastpath allocations */
15012 BLOGE(sc, "Failed to create dma map for "
15013 "'fp %d spare rx mbuf' (%d)\n", i, rc);
15017 /***************************/
15018 /* FP RX SGE MBUF DMA MAPS */
15019 /***************************/
15021 /* create a dma tag for the rx sge mbufs */
15022 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */
15024 0, /* boundary limit */
15025 BUS_SPACE_MAXADDR, /* restricted low */
15026 BUS_SPACE_MAXADDR, /* restricted hi */
15027 NULL, /* addr filter() */
15028 NULL, /* addr filter() arg */
15029 BCM_PAGE_SIZE, /* max map size */
15030 1, /* num discontinuous */
15031 BCM_PAGE_SIZE, /* max seg size */
15034 NULL, /* lock() arg */
15035 &fp->rx_sge_mbuf_tag); /* returned dma tag */
15037 /* XXX unwind and free previous fastpath allocations */
15038 BLOGE(sc, "Failed to create dma tag for "
15039 "'fp %d rx sge mbufs' (%d)\n", i, rc);
15043 /* create dma maps for the rx sge mbuf clusters */
15044 for (j = 0; j < RX_SGE_TOTAL; j++) {
15045 if (bus_dmamap_create(fp->rx_sge_mbuf_tag,
15047 &fp->rx_sge_mbuf_chain[j].m_map)) {
15048 /* XXX unwind and free previous fastpath allocations */
15049 BLOGE(sc, "Failed to create dma map for "
15050 "'fp %d rx sge mbuf %d' (%d)\n", i, j, rc);
15055 /* create dma map for the spare rx sge mbuf cluster */
15056 if (bus_dmamap_create(fp->rx_sge_mbuf_tag,
15058 &fp->rx_sge_mbuf_spare_map)) {
15059 /* XXX unwind and free previous fastpath allocations */
15060 BLOGE(sc, "Failed to create dma map for "
15061 "'fp %d spare rx sge mbuf' (%d)\n", i, rc);
15065 /***************************/
15066 /* FP RX TPA MBUF DMA MAPS */
15067 /***************************/
15069 /* create dma maps for the rx tpa mbuf clusters */
15070 max_agg_queues = MAX_AGG_QS(sc);
15072 for (j = 0; j < max_agg_queues; j++) {
15073 if (bus_dmamap_create(fp->rx_mbuf_tag,
15075 &fp->rx_tpa_info[j].bd.m_map)) {
15076 /* XXX unwind and free previous fastpath allocations */
15077 BLOGE(sc, "Failed to create dma map for "
15078 "'fp %d rx tpa mbuf %d' (%d)\n", i, j, rc);
15083 /* create dma map for the spare rx tpa mbuf cluster */
15084 if (bus_dmamap_create(fp->rx_mbuf_tag,
15086 &fp->rx_tpa_info_mbuf_spare_map)) {
15087 /* XXX unwind and free previous fastpath allocations */
15088 BLOGE(sc, "Failed to create dma map for "
15089 "'fp %d spare rx tpa mbuf' (%d)\n", i, rc);
15093 bxe_init_sge_ring_bit_mask(fp);
15100 bxe_free_hsi_mem(struct bxe_softc *sc)
15102 struct bxe_fastpath *fp;
15103 int max_agg_queues;
15106 if (sc->parent_dma_tag == NULL) {
15107 return; /* assume nothing was allocated */
15110 for (i = 0; i < sc->num_queues; i++) {
15113 /*******************/
15114 /* FP STATUS BLOCK */
15115 /*******************/
15117 bxe_dma_free(sc, &fp->sb_dma);
15118 memset(&fp->status_block, 0, sizeof(fp->status_block));
15120 /******************/
15121 /* FP TX BD CHAIN */
15122 /******************/
15124 bxe_dma_free(sc, &fp->tx_dma);
15125 fp->tx_chain = NULL;
15127 /******************/
15128 /* FP RX BD CHAIN */
15129 /******************/
15131 bxe_dma_free(sc, &fp->rx_dma);
15132 fp->rx_chain = NULL;
15134 /*******************/
15135 /* FP RX RCQ CHAIN */
15136 /*******************/
15138 bxe_dma_free(sc, &fp->rcq_dma);
15139 fp->rcq_chain = NULL;
15141 /*******************/
15142 /* FP RX SGE CHAIN */
15143 /*******************/
15145 bxe_dma_free(sc, &fp->rx_sge_dma);
15146 fp->rx_sge_chain = NULL;
15148 /***********************/
15149 /* FP TX MBUF DMA MAPS */
15150 /***********************/
15152 if (fp->tx_mbuf_tag != NULL) {
15153 for (j = 0; j < TX_BD_TOTAL; j++) {
15154 if (fp->tx_mbuf_chain[j].m_map != NULL) {
15155 bus_dmamap_unload(fp->tx_mbuf_tag,
15156 fp->tx_mbuf_chain[j].m_map);
15157 bus_dmamap_destroy(fp->tx_mbuf_tag,
15158 fp->tx_mbuf_chain[j].m_map);
15162 bus_dma_tag_destroy(fp->tx_mbuf_tag);
15163 fp->tx_mbuf_tag = NULL;
15166 /***********************/
15167 /* FP RX MBUF DMA MAPS */
15168 /***********************/
15170 if (fp->rx_mbuf_tag != NULL) {
15171 for (j = 0; j < RX_BD_TOTAL; j++) {
15172 if (fp->rx_mbuf_chain[j].m_map != NULL) {
15173 bus_dmamap_unload(fp->rx_mbuf_tag,
15174 fp->rx_mbuf_chain[j].m_map);
15175 bus_dmamap_destroy(fp->rx_mbuf_tag,
15176 fp->rx_mbuf_chain[j].m_map);
15180 if (fp->rx_mbuf_spare_map != NULL) {
15181 bus_dmamap_unload(fp->rx_mbuf_tag, fp->rx_mbuf_spare_map);
15182 bus_dmamap_destroy(fp->rx_mbuf_tag, fp->rx_mbuf_spare_map);
15185 /***************************/
15186 /* FP RX TPA MBUF DMA MAPS */
15187 /***************************/
15189 max_agg_queues = MAX_AGG_QS(sc);
15191 for (j = 0; j < max_agg_queues; j++) {
15192 if (fp->rx_tpa_info[j].bd.m_map != NULL) {
15193 bus_dmamap_unload(fp->rx_mbuf_tag,
15194 fp->rx_tpa_info[j].bd.m_map);
15195 bus_dmamap_destroy(fp->rx_mbuf_tag,
15196 fp->rx_tpa_info[j].bd.m_map);
15200 if (fp->rx_tpa_info_mbuf_spare_map != NULL) {
15201 bus_dmamap_unload(fp->rx_mbuf_tag,
15202 fp->rx_tpa_info_mbuf_spare_map);
15203 bus_dmamap_destroy(fp->rx_mbuf_tag,
15204 fp->rx_tpa_info_mbuf_spare_map);
15207 bus_dma_tag_destroy(fp->rx_mbuf_tag);
15208 fp->rx_mbuf_tag = NULL;
15211 /***************************/
15212 /* FP RX SGE MBUF DMA MAPS */
15213 /***************************/
15215 if (fp->rx_sge_mbuf_tag != NULL) {
15216 for (j = 0; j < RX_SGE_TOTAL; j++) {
15217 if (fp->rx_sge_mbuf_chain[j].m_map != NULL) {
15218 bus_dmamap_unload(fp->rx_sge_mbuf_tag,
15219 fp->rx_sge_mbuf_chain[j].m_map);
15220 bus_dmamap_destroy(fp->rx_sge_mbuf_tag,
15221 fp->rx_sge_mbuf_chain[j].m_map);
15225 if (fp->rx_sge_mbuf_spare_map != NULL) {
15226 bus_dmamap_unload(fp->rx_sge_mbuf_tag,
15227 fp->rx_sge_mbuf_spare_map);
15228 bus_dmamap_destroy(fp->rx_sge_mbuf_tag,
15229 fp->rx_sge_mbuf_spare_map);
15232 bus_dma_tag_destroy(fp->rx_sge_mbuf_tag);
15233 fp->rx_sge_mbuf_tag = NULL;
15237 /***************************/
15238 /* FW DECOMPRESSION BUFFER */
15239 /***************************/
15241 bxe_dma_free(sc, &sc->gz_buf_dma);
15243 free(sc->gz_strm, M_DEVBUF);
15244 sc->gz_strm = NULL;
15246 /*******************/
15247 /* SLOW PATH QUEUE */
15248 /*******************/
15250 bxe_dma_free(sc, &sc->spq_dma);
15257 bxe_dma_free(sc, &sc->sp_dma);
15264 bxe_dma_free(sc, &sc->eq_dma);
15267 /************************/
15268 /* DEFAULT STATUS BLOCK */
15269 /************************/
15271 bxe_dma_free(sc, &sc->def_sb_dma);
15274 bus_dma_tag_destroy(sc->parent_dma_tag);
15275 sc->parent_dma_tag = NULL;
15279 * Previous driver DMAE transaction may have occurred when pre-boot stage
15280 * ended and boot began. This would invalidate the addresses of the
15281 * transaction, resulting in was-error bit set in the PCI causing all
15282 * hw-to-host PCIe transactions to timeout. If this happened we want to clear
15283 * the interrupt which detected this from the pglueb and the was-done bit
15286 bxe_prev_interrupted_dmae(struct bxe_softc *sc)
15290 if (!CHIP_IS_E1x(sc)) {
15291 val = REG_RD(sc, PGLUE_B_REG_PGLUE_B_INT_STS);
15292 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
15293 BLOGD(sc, DBG_LOAD,
15294 "Clearing 'was-error' bit that was set in pglueb");
15295 REG_WR(sc, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, 1 << SC_FUNC(sc));
15301 bxe_prev_mcp_done(struct bxe_softc *sc)
15303 uint32_t rc = bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE,
15304 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
15306 BLOGE(sc, "MCP response failure, aborting\n");
15313 static struct bxe_prev_list_node *
15314 bxe_prev_path_get_entry(struct bxe_softc *sc)
15316 struct bxe_prev_list_node *tmp;
15318 LIST_FOREACH(tmp, &bxe_prev_list, node) {
15319 if ((sc->pcie_bus == tmp->bus) &&
15320 (sc->pcie_device == tmp->slot) &&
15321 (SC_PATH(sc) == tmp->path)) {
15330 bxe_prev_is_path_marked(struct bxe_softc *sc)
15332 struct bxe_prev_list_node *tmp;
15335 mtx_lock(&bxe_prev_mtx);
15337 tmp = bxe_prev_path_get_entry(sc);
15340 BLOGD(sc, DBG_LOAD,
15341 "Path %d/%d/%d was marked by AER\n",
15342 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15345 BLOGD(sc, DBG_LOAD,
15346 "Path %d/%d/%d was already cleaned from previous drivers\n",
15347 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15351 mtx_unlock(&bxe_prev_mtx);
15357 bxe_prev_mark_path(struct bxe_softc *sc,
15358 uint8_t after_undi)
15360 struct bxe_prev_list_node *tmp;
15362 mtx_lock(&bxe_prev_mtx);
15364 /* Check whether the entry for this path already exists */
15365 tmp = bxe_prev_path_get_entry(sc);
15368 BLOGD(sc, DBG_LOAD,
15369 "Re-marking AER in path %d/%d/%d\n",
15370 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15372 BLOGD(sc, DBG_LOAD,
15373 "Removing AER indication from path %d/%d/%d\n",
15374 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15378 mtx_unlock(&bxe_prev_mtx);
15382 mtx_unlock(&bxe_prev_mtx);
15384 /* Create an entry for this path and add it */
15385 tmp = malloc(sizeof(struct bxe_prev_list_node), M_DEVBUF,
15386 (M_NOWAIT | M_ZERO));
15388 BLOGE(sc, "Failed to allocate 'bxe_prev_list_node'\n");
15392 tmp->bus = sc->pcie_bus;
15393 tmp->slot = sc->pcie_device;
15394 tmp->path = SC_PATH(sc);
15396 tmp->undi = after_undi ? (1 << SC_PORT(sc)) : 0;
15398 mtx_lock(&bxe_prev_mtx);
15400 BLOGD(sc, DBG_LOAD,
15401 "Marked path %d/%d/%d - finished previous unload\n",
15402 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
15403 LIST_INSERT_HEAD(&bxe_prev_list, tmp, node);
15405 mtx_unlock(&bxe_prev_mtx);
15411 bxe_do_flr(struct bxe_softc *sc)
15415 /* only E2 and onwards support FLR */
15416 if (CHIP_IS_E1x(sc)) {
15417 BLOGD(sc, DBG_LOAD, "FLR not supported in E1/E1H\n");
15421 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
15422 if (sc->devinfo.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
15423 BLOGD(sc, DBG_LOAD, "FLR not supported by BC_VER: 0x%08x\n",
15424 sc->devinfo.bc_ver);
15428 /* Wait for Transaction Pending bit clean */
15429 for (i = 0; i < 4; i++) {
15431 DELAY(((1 << (i - 1)) * 100) * 1000);
15434 if (!bxe_is_pcie_pending(sc)) {
15439 BLOGE(sc, "PCIE transaction is not cleared, "
15440 "proceeding with reset anyway\n");
15444 BLOGD(sc, DBG_LOAD, "Initiating FLR\n");
15445 bxe_fw_command(sc, DRV_MSG_CODE_INITIATE_FLR, 0);
15450 struct bxe_mac_vals {
15451 uint32_t xmac_addr;
15453 uint32_t emac_addr;
15455 uint32_t umac_addr;
15457 uint32_t bmac_addr;
15458 uint32_t bmac_val[2];
15462 bxe_prev_unload_close_mac(struct bxe_softc *sc,
15463 struct bxe_mac_vals *vals)
15465 uint32_t val, base_addr, offset, mask, reset_reg;
15466 uint8_t mac_stopped = FALSE;
15467 uint8_t port = SC_PORT(sc);
15468 uint32_t wb_data[2];
15470 /* reset addresses as they also mark which values were changed */
15471 vals->bmac_addr = 0;
15472 vals->umac_addr = 0;
15473 vals->xmac_addr = 0;
15474 vals->emac_addr = 0;
15476 reset_reg = REG_RD(sc, MISC_REG_RESET_REG_2);
15478 if (!CHIP_IS_E3(sc)) {
15479 val = REG_RD(sc, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
15480 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
15481 if ((mask & reset_reg) && val) {
15482 BLOGD(sc, DBG_LOAD, "Disable BMAC Rx\n");
15483 base_addr = SC_PORT(sc) ? NIG_REG_INGRESS_BMAC1_MEM
15484 : NIG_REG_INGRESS_BMAC0_MEM;
15485 offset = CHIP_IS_E2(sc) ? BIGMAC2_REGISTER_BMAC_CONTROL
15486 : BIGMAC_REGISTER_BMAC_CONTROL;
15489 * use rd/wr since we cannot use dmae. This is safe
15490 * since MCP won't access the bus due to the request
15491 * to unload, and no function on the path can be
15492 * loaded at this time.
15494 wb_data[0] = REG_RD(sc, base_addr + offset);
15495 wb_data[1] = REG_RD(sc, base_addr + offset + 0x4);
15496 vals->bmac_addr = base_addr + offset;
15497 vals->bmac_val[0] = wb_data[0];
15498 vals->bmac_val[1] = wb_data[1];
15499 wb_data[0] &= ~ELINK_BMAC_CONTROL_RX_ENABLE;
15500 REG_WR(sc, vals->bmac_addr, wb_data[0]);
15501 REG_WR(sc, vals->bmac_addr + 0x4, wb_data[1]);
15504 BLOGD(sc, DBG_LOAD, "Disable EMAC Rx\n");
15505 vals->emac_addr = NIG_REG_NIG_EMAC0_EN + SC_PORT(sc)*4;
15506 vals->emac_val = REG_RD(sc, vals->emac_addr);
15507 REG_WR(sc, vals->emac_addr, 0);
15508 mac_stopped = TRUE;
15510 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
15511 BLOGD(sc, DBG_LOAD, "Disable XMAC Rx\n");
15512 base_addr = SC_PORT(sc) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
15513 val = REG_RD(sc, base_addr + XMAC_REG_PFC_CTRL_HI);
15514 REG_WR(sc, base_addr + XMAC_REG_PFC_CTRL_HI, val & ~(1 << 1));
15515 REG_WR(sc, base_addr + XMAC_REG_PFC_CTRL_HI, val | (1 << 1));
15516 vals->xmac_addr = base_addr + XMAC_REG_CTRL;
15517 vals->xmac_val = REG_RD(sc, vals->xmac_addr);
15518 REG_WR(sc, vals->xmac_addr, 0);
15519 mac_stopped = TRUE;
15522 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
15523 if (mask & reset_reg) {
15524 BLOGD(sc, DBG_LOAD, "Disable UMAC Rx\n");
15525 base_addr = SC_PORT(sc) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
15526 vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
15527 vals->umac_val = REG_RD(sc, vals->umac_addr);
15528 REG_WR(sc, vals->umac_addr, 0);
15529 mac_stopped = TRUE;
15538 #define BXE_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
15539 #define BXE_PREV_UNDI_RCQ(val) ((val) & 0xffff)
15540 #define BXE_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
15541 #define BXE_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
15544 bxe_prev_unload_undi_inc(struct bxe_softc *sc,
15549 uint32_t tmp_reg = REG_RD(sc, BXE_PREV_UNDI_PROD_ADDR(port));
15551 rcq = BXE_PREV_UNDI_RCQ(tmp_reg) + inc;
15552 bd = BXE_PREV_UNDI_BD(tmp_reg) + inc;
15554 tmp_reg = BXE_PREV_UNDI_PROD(rcq, bd);
15555 REG_WR(sc, BXE_PREV_UNDI_PROD_ADDR(port), tmp_reg);
15557 BLOGD(sc, DBG_LOAD,
15558 "UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
15563 bxe_prev_unload_common(struct bxe_softc *sc)
15565 uint32_t reset_reg, tmp_reg = 0, rc;
15566 uint8_t prev_undi = FALSE;
15567 struct bxe_mac_vals mac_vals;
15568 uint32_t timer_count = 1000;
15572 * It is possible a previous function received 'common' answer,
15573 * but hasn't loaded yet, therefore creating a scenario of
15574 * multiple functions receiving 'common' on the same path.
15576 BLOGD(sc, DBG_LOAD, "Common unload Flow\n");
15578 memset(&mac_vals, 0, sizeof(mac_vals));
15580 if (bxe_prev_is_path_marked(sc)) {
15581 return (bxe_prev_mcp_done(sc));
15584 reset_reg = REG_RD(sc, MISC_REG_RESET_REG_1);
15586 /* Reset should be performed after BRB is emptied */
15587 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
15588 /* Close the MAC Rx to prevent BRB from filling up */
15589 bxe_prev_unload_close_mac(sc, &mac_vals);
15591 /* close LLH filters towards the BRB */
15592 elink_set_rx_filter(&sc->link_params, 0);
15595 * Check if the UNDI driver was previously loaded.
15596 * UNDI driver initializes CID offset for normal bell to 0x7
15598 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
15599 tmp_reg = REG_RD(sc, DORQ_REG_NORM_CID_OFST);
15600 if (tmp_reg == 0x7) {
15601 BLOGD(sc, DBG_LOAD, "UNDI previously loaded\n");
15603 /* clear the UNDI indication */
15604 REG_WR(sc, DORQ_REG_NORM_CID_OFST, 0);
15605 /* clear possible idle check errors */
15606 REG_RD(sc, NIG_REG_NIG_INT_STS_CLR_0);
15610 /* wait until BRB is empty */
15611 tmp_reg = REG_RD(sc, BRB1_REG_NUM_OF_FULL_BLOCKS);
15612 while (timer_count) {
15613 prev_brb = tmp_reg;
15615 tmp_reg = REG_RD(sc, BRB1_REG_NUM_OF_FULL_BLOCKS);
15620 BLOGD(sc, DBG_LOAD, "BRB still has 0x%08x\n", tmp_reg);
15622 /* reset timer as long as BRB actually gets emptied */
15623 if (prev_brb > tmp_reg) {
15624 timer_count = 1000;
15629 /* If UNDI resides in memory, manually increment it */
15631 bxe_prev_unload_undi_inc(sc, SC_PORT(sc), 1);
15637 if (!timer_count) {
15638 BLOGE(sc, "Failed to empty BRB\n");
15642 /* No packets are in the pipeline, path is ready for reset */
15643 bxe_reset_common(sc);
15645 if (mac_vals.xmac_addr) {
15646 REG_WR(sc, mac_vals.xmac_addr, mac_vals.xmac_val);
15648 if (mac_vals.umac_addr) {
15649 REG_WR(sc, mac_vals.umac_addr, mac_vals.umac_val);
15651 if (mac_vals.emac_addr) {
15652 REG_WR(sc, mac_vals.emac_addr, mac_vals.emac_val);
15654 if (mac_vals.bmac_addr) {
15655 REG_WR(sc, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
15656 REG_WR(sc, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
15659 rc = bxe_prev_mark_path(sc, prev_undi);
15661 bxe_prev_mcp_done(sc);
15665 return (bxe_prev_mcp_done(sc));
15669 bxe_prev_unload_uncommon(struct bxe_softc *sc)
15673 BLOGD(sc, DBG_LOAD, "Uncommon unload Flow\n");
15675 /* Test if previous unload process was already finished for this path */
15676 if (bxe_prev_is_path_marked(sc)) {
15677 return (bxe_prev_mcp_done(sc));
15680 BLOGD(sc, DBG_LOAD, "Path is unmarked\n");
15683 * If function has FLR capabilities, and existing FW version matches
15684 * the one required, then FLR will be sufficient to clean any residue
15685 * left by previous driver
15687 rc = bxe_nic_load_analyze_req(sc, FW_MSG_CODE_DRV_LOAD_FUNCTION);
15689 /* fw version is good */
15690 BLOGD(sc, DBG_LOAD, "FW version matches our own, attempting FLR\n");
15691 rc = bxe_do_flr(sc);
15695 /* FLR was performed */
15696 BLOGD(sc, DBG_LOAD, "FLR successful\n");
15700 BLOGD(sc, DBG_LOAD, "Could not FLR\n");
15702 /* Close the MCP request, return failure*/
15703 rc = bxe_prev_mcp_done(sc);
15705 rc = BXE_PREV_WAIT_NEEDED;
15712 bxe_prev_unload(struct bxe_softc *sc)
15714 int time_counter = 10;
15715 uint32_t fw, hw_lock_reg, hw_lock_val;
15719 * Clear HW from errors which may have resulted from an interrupted
15720 * DMAE transaction.
15722 bxe_prev_interrupted_dmae(sc);
15724 /* Release previously held locks */
15726 (SC_FUNC(sc) <= 5) ?
15727 (MISC_REG_DRIVER_CONTROL_1 + SC_FUNC(sc) * 8) :
15728 (MISC_REG_DRIVER_CONTROL_7 + (SC_FUNC(sc) - 6) * 8);
15730 hw_lock_val = (REG_RD(sc, hw_lock_reg));
15732 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
15733 BLOGD(sc, DBG_LOAD, "Releasing previously held NVRAM lock\n");
15734 REG_WR(sc, MCP_REG_MCPR_NVM_SW_ARB,
15735 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << SC_PORT(sc)));
15737 BLOGD(sc, DBG_LOAD, "Releasing previously held HW lock\n");
15738 REG_WR(sc, hw_lock_reg, 0xffffffff);
15740 BLOGD(sc, DBG_LOAD, "No need to release HW/NVRAM locks\n");
15743 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(sc, MCP_REG_MCPR_ACCESS_LOCK)) {
15744 BLOGD(sc, DBG_LOAD, "Releasing previously held ALR\n");
15745 REG_WR(sc, MCP_REG_MCPR_ACCESS_LOCK, 0);
15749 /* Lock MCP using an unload request */
15750 fw = bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
15752 BLOGE(sc, "MCP response failure, aborting\n");
15757 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
15758 rc = bxe_prev_unload_common(sc);
15762 /* non-common reply from MCP night require looping */
15763 rc = bxe_prev_unload_uncommon(sc);
15764 if (rc != BXE_PREV_WAIT_NEEDED) {
15769 } while (--time_counter);
15771 if (!time_counter || rc) {
15772 BLOGE(sc, "Failed to unload previous driver!"
15773 " time_counter %d rc %d\n", time_counter, rc);
15781 bxe_dcbx_set_state(struct bxe_softc *sc,
15783 uint32_t dcbx_enabled)
15785 if (!CHIP_IS_E1x(sc)) {
15786 sc->dcb_state = dcb_on;
15787 sc->dcbx_enabled = dcbx_enabled;
15789 sc->dcb_state = FALSE;
15790 sc->dcbx_enabled = BXE_DCBX_ENABLED_INVALID;
15792 BLOGD(sc, DBG_LOAD,
15793 "DCB state [%s:%s]\n",
15794 dcb_on ? "ON" : "OFF",
15795 (dcbx_enabled == BXE_DCBX_ENABLED_OFF) ? "user-mode" :
15796 (dcbx_enabled == BXE_DCBX_ENABLED_ON_NEG_OFF) ? "on-chip static" :
15797 (dcbx_enabled == BXE_DCBX_ENABLED_ON_NEG_ON) ?
15798 "on-chip with negotiation" : "invalid");
15801 /* must be called after sriov-enable */
15803 bxe_set_qm_cid_count(struct bxe_softc *sc)
15805 int cid_count = BXE_L2_MAX_CID(sc);
15807 if (IS_SRIOV(sc)) {
15808 cid_count += BXE_VF_CIDS;
15811 if (CNIC_SUPPORT(sc)) {
15812 cid_count += CNIC_CID_MAX;
15815 return (roundup(cid_count, QM_CID_ROUND));
15819 bxe_init_multi_cos(struct bxe_softc *sc)
15823 uint32_t pri_map = 0; /* XXX change to user config */
15825 for (pri = 0; pri < BXE_MAX_PRIORITY; pri++) {
15826 cos = ((pri_map & (0xf << (pri * 4))) >> (pri * 4));
15827 if (cos < sc->max_cos) {
15828 sc->prio_to_cos[pri] = cos;
15830 BLOGW(sc, "Invalid COS %d for priority %d "
15831 "(max COS is %d), setting to 0\n",
15832 cos, pri, (sc->max_cos - 1));
15833 sc->prio_to_cos[pri] = 0;
15839 bxe_sysctl_state(SYSCTL_HANDLER_ARGS)
15841 struct bxe_softc *sc;
15845 error = sysctl_handle_int(oidp, &result, 0, req);
15847 if (error || !req->newptr) {
15853 sc = (struct bxe_softc *)arg1;
15855 BLOGI(sc, "... dumping driver state ...\n");
15856 temp = SHMEM2_RD(sc, temperature_in_half_celsius);
15857 BLOGI(sc, "\t Device Temperature = %d Celsius\n", (temp/2));
15864 bxe_sysctl_eth_stat(SYSCTL_HANDLER_ARGS)
15866 struct bxe_softc *sc = (struct bxe_softc *)arg1;
15867 uint32_t *eth_stats = (uint32_t *)&sc->eth_stats;
15869 uint64_t value = 0;
15870 int index = (int)arg2;
15872 if (index >= BXE_NUM_ETH_STATS) {
15873 BLOGE(sc, "bxe_eth_stats index out of range (%d)\n", index);
15877 offset = (eth_stats + bxe_eth_stats_arr[index].offset);
15879 switch (bxe_eth_stats_arr[index].size) {
15881 value = (uint64_t)*offset;
15884 value = HILO_U64(*offset, *(offset + 1));
15887 BLOGE(sc, "Invalid bxe_eth_stats size (index=%d size=%d)\n",
15888 index, bxe_eth_stats_arr[index].size);
15892 return (sysctl_handle_64(oidp, &value, 0, req));
15896 bxe_sysctl_eth_q_stat(SYSCTL_HANDLER_ARGS)
15898 struct bxe_softc *sc = (struct bxe_softc *)arg1;
15899 uint32_t *eth_stats;
15901 uint64_t value = 0;
15902 uint32_t q_stat = (uint32_t)arg2;
15903 uint32_t fp_index = ((q_stat >> 16) & 0xffff);
15904 uint32_t index = (q_stat & 0xffff);
15906 eth_stats = (uint32_t *)&sc->fp[fp_index].eth_q_stats;
15908 if (index >= BXE_NUM_ETH_Q_STATS) {
15909 BLOGE(sc, "bxe_eth_q_stats index out of range (%d)\n", index);
15913 offset = (eth_stats + bxe_eth_q_stats_arr[index].offset);
15915 switch (bxe_eth_q_stats_arr[index].size) {
15917 value = (uint64_t)*offset;
15920 value = HILO_U64(*offset, *(offset + 1));
15923 BLOGE(sc, "Invalid bxe_eth_q_stats size (index=%d size=%d)\n",
15924 index, bxe_eth_q_stats_arr[index].size);
15928 return (sysctl_handle_64(oidp, &value, 0, req));
15931 static void bxe_force_link_reset(struct bxe_softc *sc)
15934 bxe_acquire_phy_lock(sc);
15935 elink_link_reset(&sc->link_params, &sc->link_vars, 1);
15936 bxe_release_phy_lock(sc);
15940 bxe_sysctl_pauseparam(SYSCTL_HANDLER_ARGS)
15942 struct bxe_softc *sc = (struct bxe_softc *)arg1;
15943 uint32_t cfg_idx = bxe_get_link_cfg_idx(sc);
15949 error = sysctl_handle_int(oidp, &sc->bxe_pause_param, 0, req);
15951 if (error || !req->newptr) {
15954 if ((sc->bxe_pause_param < 0) || (sc->bxe_pause_param > 8)) {
15955 BLOGW(sc, "invalid pause param (%d) - use intergers between 1 & 8\n",sc->bxe_pause_param);
15956 sc->bxe_pause_param = 8;
15959 result = (sc->bxe_pause_param << PORT_FEATURE_FLOW_CONTROL_SHIFT);
15962 if((result & 0x400) && !(sc->port.supported[cfg_idx] & ELINK_SUPPORTED_Autoneg)) {
15963 BLOGW(sc, "Does not support Autoneg pause_param %d\n", sc->bxe_pause_param);
15969 sc->link_params.req_flow_ctrl[cfg_idx] = ELINK_FLOW_CTRL_AUTO;
15970 if(result & ELINK_FLOW_CTRL_RX)
15971 sc->link_params.req_flow_ctrl[cfg_idx] |= ELINK_FLOW_CTRL_RX;
15973 if(result & ELINK_FLOW_CTRL_TX)
15974 sc->link_params.req_flow_ctrl[cfg_idx] |= ELINK_FLOW_CTRL_TX;
15975 if(sc->link_params.req_flow_ctrl[cfg_idx] == ELINK_FLOW_CTRL_AUTO)
15976 sc->link_params.req_flow_ctrl[cfg_idx] = ELINK_FLOW_CTRL_NONE;
15978 if(result & 0x400) {
15979 if (sc->link_params.req_line_speed[cfg_idx] == ELINK_SPEED_AUTO_NEG) {
15980 sc->link_params.req_flow_ctrl[cfg_idx] =
15981 ELINK_FLOW_CTRL_AUTO;
15983 sc->link_params.req_fc_auto_adv = 0;
15984 if (result & ELINK_FLOW_CTRL_RX)
15985 sc->link_params.req_fc_auto_adv |= ELINK_FLOW_CTRL_RX;
15987 if (result & ELINK_FLOW_CTRL_TX)
15988 sc->link_params.req_fc_auto_adv |= ELINK_FLOW_CTRL_TX;
15989 if (!sc->link_params.req_fc_auto_adv)
15990 sc->link_params.req_fc_auto_adv |= ELINK_FLOW_CTRL_NONE;
15993 if (sc->link_vars.link_up) {
15994 bxe_stats_handle(sc, STATS_EVENT_STOP);
15996 if (if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING) {
15997 bxe_force_link_reset(sc);
15998 bxe_acquire_phy_lock(sc);
16000 rc = elink_phy_init(&sc->link_params, &sc->link_vars);
16002 bxe_release_phy_lock(sc);
16004 bxe_calc_fc_adv(sc);
16012 bxe_add_sysctls(struct bxe_softc *sc)
16014 struct sysctl_ctx_list *ctx;
16015 struct sysctl_oid_list *children;
16016 struct sysctl_oid *queue_top, *queue;
16017 struct sysctl_oid_list *queue_top_children, *queue_children;
16018 char queue_num_buf[32];
16022 ctx = device_get_sysctl_ctx(sc->dev);
16023 children = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev));
16025 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "version",
16026 CTLFLAG_RD, BXE_DRIVER_VERSION, 0,
16029 snprintf(sc->fw_ver_str, sizeof(sc->fw_ver_str), "%d.%d.%d.%d",
16030 BCM_5710_FW_MAJOR_VERSION,
16031 BCM_5710_FW_MINOR_VERSION,
16032 BCM_5710_FW_REVISION_VERSION,
16033 BCM_5710_FW_ENGINEERING_VERSION);
16035 snprintf(sc->mf_mode_str, sizeof(sc->mf_mode_str), "%s",
16036 ((sc->devinfo.mf_info.mf_mode == SINGLE_FUNCTION) ? "Single" :
16037 (sc->devinfo.mf_info.mf_mode == MULTI_FUNCTION_SD) ? "MF-SD" :
16038 (sc->devinfo.mf_info.mf_mode == MULTI_FUNCTION_SI) ? "MF-SI" :
16039 (sc->devinfo.mf_info.mf_mode == MULTI_FUNCTION_AFEX) ? "MF-AFEX" :
16041 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "mf_vnics",
16042 CTLFLAG_RD, &sc->devinfo.mf_info.vnics_per_port, 0,
16043 "multifunction vnics per port");
16045 snprintf(sc->pci_link_str, sizeof(sc->pci_link_str), "%s x%d",
16046 ((sc->devinfo.pcie_link_speed == 1) ? "2.5GT/s" :
16047 (sc->devinfo.pcie_link_speed == 2) ? "5.0GT/s" :
16048 (sc->devinfo.pcie_link_speed == 4) ? "8.0GT/s" :
16050 sc->devinfo.pcie_link_width);
16052 sc->debug = bxe_debug;
16054 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "bc_version",
16055 CTLFLAG_RD, sc->devinfo.bc_ver_str, 0,
16056 "bootcode version");
16057 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "fw_version",
16058 CTLFLAG_RD, sc->fw_ver_str, 0,
16059 "firmware version");
16060 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "mf_mode",
16061 CTLFLAG_RD, sc->mf_mode_str, 0,
16062 "multifunction mode");
16063 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "mac_addr",
16064 CTLFLAG_RD, sc->mac_addr_str, 0,
16066 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "pci_link",
16067 CTLFLAG_RD, sc->pci_link_str, 0,
16068 "pci link status");
16069 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO, "debug",
16070 CTLFLAG_RW, &sc->debug,
16071 "debug logging mode");
16073 sc->trigger_grcdump = 0;
16074 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "trigger_grcdump",
16075 CTLFLAG_RW, &sc->trigger_grcdump, 0,
16076 "trigger grcdump should be invoked"
16077 " before collecting grcdump");
16079 sc->grcdump_started = 0;
16080 sc->grcdump_done = 0;
16081 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "grcdump_done",
16082 CTLFLAG_RD, &sc->grcdump_done, 0,
16083 "set by driver when grcdump is done");
16085 sc->rx_budget = bxe_rx_budget;
16086 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "rx_budget",
16087 CTLFLAG_RW, &sc->rx_budget, 0,
16088 "rx processing budget");
16090 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pause_param",
16091 CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, sc, 0,
16092 bxe_sysctl_pauseparam, "IU",
16093 "need pause frames- DEF:0/TX:1/RX:2/BOTH:3/AUTO:4/AUTOTX:5/AUTORX:6/AUTORXTX:7/NONE:8");
16096 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "state",
16097 CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, sc, 0,
16098 bxe_sysctl_state, "IU", "dump driver state");
16100 for (i = 0; i < BXE_NUM_ETH_STATS; i++) {
16101 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
16102 bxe_eth_stats_arr[i].string,
16103 CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_NEEDGIANT, sc, i,
16104 bxe_sysctl_eth_stat, "LU", bxe_eth_stats_arr[i].string);
16107 /* add a new parent node for all queues "dev.bxe.#.queue" */
16108 queue_top = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "queue",
16109 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "queue");
16110 queue_top_children = SYSCTL_CHILDREN(queue_top);
16112 for (i = 0; i < sc->num_queues; i++) {
16113 /* add a new parent node for a single queue "dev.bxe.#.queue.#" */
16114 snprintf(queue_num_buf, sizeof(queue_num_buf), "%d", i);
16115 queue = SYSCTL_ADD_NODE(ctx, queue_top_children, OID_AUTO,
16116 queue_num_buf, CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "single queue");
16117 queue_children = SYSCTL_CHILDREN(queue);
16119 for (j = 0; j < BXE_NUM_ETH_Q_STATS; j++) {
16120 q_stat = ((i << 16) | j);
16121 SYSCTL_ADD_PROC(ctx, queue_children, OID_AUTO,
16122 bxe_eth_q_stats_arr[j].string,
16123 CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_NEEDGIANT, sc, q_stat,
16124 bxe_sysctl_eth_q_stat, "LU", bxe_eth_q_stats_arr[j].string);
16130 bxe_alloc_buf_rings(struct bxe_softc *sc)
16133 struct bxe_fastpath *fp;
16135 for (i = 0; i < sc->num_queues; i++) {
16139 fp->tx_br = buf_ring_alloc(BXE_BR_SIZE, M_DEVBUF,
16140 M_NOWAIT, &fp->tx_mtx);
16141 if (fp->tx_br == NULL)
16149 bxe_free_buf_rings(struct bxe_softc *sc)
16152 struct bxe_fastpath *fp;
16154 for (i = 0; i < sc->num_queues; i++) {
16159 buf_ring_free(fp->tx_br, M_DEVBUF);
16166 bxe_init_fp_mutexs(struct bxe_softc *sc)
16169 struct bxe_fastpath *fp;
16171 for (i = 0; i < sc->num_queues; i++) {
16175 snprintf(fp->tx_mtx_name, sizeof(fp->tx_mtx_name),
16176 "bxe%d_fp%d_tx_lock", sc->unit, i);
16177 mtx_init(&fp->tx_mtx, fp->tx_mtx_name, NULL, MTX_DEF);
16179 snprintf(fp->rx_mtx_name, sizeof(fp->rx_mtx_name),
16180 "bxe%d_fp%d_rx_lock", sc->unit, i);
16181 mtx_init(&fp->rx_mtx, fp->rx_mtx_name, NULL, MTX_DEF);
16186 bxe_destroy_fp_mutexs(struct bxe_softc *sc)
16189 struct bxe_fastpath *fp;
16191 for (i = 0; i < sc->num_queues; i++) {
16195 if (mtx_initialized(&fp->tx_mtx)) {
16196 mtx_destroy(&fp->tx_mtx);
16199 if (mtx_initialized(&fp->rx_mtx)) {
16200 mtx_destroy(&fp->rx_mtx);
16207 * Device attach function.
16209 * Allocates device resources, performs secondary chip identification, and
16210 * initializes driver instance variables. This function is called from driver
16211 * load after a successful probe.
16214 * 0 = Success, >0 = Failure
16217 bxe_attach(device_t dev)
16219 struct bxe_softc *sc;
16221 sc = device_get_softc(dev);
16223 BLOGD(sc, DBG_LOAD, "Starting attach...\n");
16225 sc->state = BXE_STATE_CLOSED;
16228 sc->unit = device_get_unit(dev);
16230 BLOGD(sc, DBG_LOAD, "softc = %p\n", sc);
16232 sc->pcie_bus = pci_get_bus(dev);
16233 sc->pcie_device = pci_get_slot(dev);
16234 sc->pcie_func = pci_get_function(dev);
16236 /* enable bus master capability */
16237 pci_enable_busmaster(dev);
16240 if (bxe_allocate_bars(sc) != 0) {
16244 /* initialize the mutexes */
16245 bxe_init_mutexes(sc);
16247 /* prepare the periodic callout */
16248 callout_init(&sc->periodic_callout, 0);
16250 /* prepare the chip taskqueue */
16251 sc->chip_tq_flags = CHIP_TQ_NONE;
16252 snprintf(sc->chip_tq_name, sizeof(sc->chip_tq_name),
16253 "bxe%d_chip_tq", sc->unit);
16254 TASK_INIT(&sc->chip_tq_task, 0, bxe_handle_chip_tq, sc);
16255 sc->chip_tq = taskqueue_create(sc->chip_tq_name, M_NOWAIT,
16256 taskqueue_thread_enqueue,
16258 taskqueue_start_threads(&sc->chip_tq, 1, PWAIT, /* lower priority */
16259 "%s", sc->chip_tq_name);
16261 TIMEOUT_TASK_INIT(taskqueue_thread,
16262 &sc->sp_err_timeout_task, 0, bxe_sp_err_timeout_task, sc);
16265 /* get device info and set params */
16266 if (bxe_get_device_info(sc) != 0) {
16267 BLOGE(sc, "getting device info\n");
16268 bxe_deallocate_bars(sc);
16269 pci_disable_busmaster(dev);
16273 /* get final misc params */
16274 bxe_get_params(sc);
16276 /* set the default MTU (changed via ifconfig) */
16277 sc->mtu = ETHERMTU;
16279 bxe_set_modes_bitmap(sc);
16282 * If in AFEX mode and the function is configured for FCoE
16283 * then bail... no L2 allowed.
16286 /* get phy settings from shmem and 'and' against admin settings */
16287 bxe_get_phy_info(sc);
16289 /* initialize the FreeBSD ifnet interface */
16290 if (bxe_init_ifnet(sc) != 0) {
16291 bxe_release_mutexes(sc);
16292 bxe_deallocate_bars(sc);
16293 pci_disable_busmaster(dev);
16297 if (bxe_add_cdev(sc) != 0) {
16298 if (sc->ifp != NULL) {
16299 ether_ifdetach(sc->ifp);
16301 ifmedia_removeall(&sc->ifmedia);
16302 bxe_release_mutexes(sc);
16303 bxe_deallocate_bars(sc);
16304 pci_disable_busmaster(dev);
16308 /* allocate device interrupts */
16309 if (bxe_interrupt_alloc(sc) != 0) {
16311 if (sc->ifp != NULL) {
16312 ether_ifdetach(sc->ifp);
16314 ifmedia_removeall(&sc->ifmedia);
16315 bxe_release_mutexes(sc);
16316 bxe_deallocate_bars(sc);
16317 pci_disable_busmaster(dev);
16321 bxe_init_fp_mutexs(sc);
16323 if (bxe_alloc_buf_rings(sc) != 0) {
16324 bxe_free_buf_rings(sc);
16325 bxe_interrupt_free(sc);
16327 if (sc->ifp != NULL) {
16328 ether_ifdetach(sc->ifp);
16330 ifmedia_removeall(&sc->ifmedia);
16331 bxe_release_mutexes(sc);
16332 bxe_deallocate_bars(sc);
16333 pci_disable_busmaster(dev);
16338 if (bxe_alloc_ilt_mem(sc) != 0) {
16339 bxe_free_buf_rings(sc);
16340 bxe_interrupt_free(sc);
16342 if (sc->ifp != NULL) {
16343 ether_ifdetach(sc->ifp);
16345 ifmedia_removeall(&sc->ifmedia);
16346 bxe_release_mutexes(sc);
16347 bxe_deallocate_bars(sc);
16348 pci_disable_busmaster(dev);
16352 /* allocate the host hardware/software hsi structures */
16353 if (bxe_alloc_hsi_mem(sc) != 0) {
16354 bxe_free_ilt_mem(sc);
16355 bxe_free_buf_rings(sc);
16356 bxe_interrupt_free(sc);
16358 if (sc->ifp != NULL) {
16359 ether_ifdetach(sc->ifp);
16361 ifmedia_removeall(&sc->ifmedia);
16362 bxe_release_mutexes(sc);
16363 bxe_deallocate_bars(sc);
16364 pci_disable_busmaster(dev);
16368 /* need to reset chip if UNDI was active */
16369 if (IS_PF(sc) && !BXE_NOMCP(sc)) {
16372 (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_mb_header) &
16373 DRV_MSG_SEQ_NUMBER_MASK);
16374 BLOGD(sc, DBG_LOAD, "prev unload fw_seq 0x%04x\n", sc->fw_seq);
16375 bxe_prev_unload(sc);
16380 bxe_dcbx_set_state(sc, FALSE, BXE_DCBX_ENABLED_OFF);
16382 if (SHMEM2_HAS(sc, dcbx_lldp_params_offset) &&
16383 SHMEM2_HAS(sc, dcbx_lldp_dcbx_stat_offset) &&
16384 SHMEM2_RD(sc, dcbx_lldp_params_offset) &&
16385 SHMEM2_RD(sc, dcbx_lldp_dcbx_stat_offset)) {
16386 bxe_dcbx_set_state(sc, TRUE, BXE_DCBX_ENABLED_ON_NEG_ON);
16387 bxe_dcbx_init_params(sc);
16389 bxe_dcbx_set_state(sc, FALSE, BXE_DCBX_ENABLED_OFF);
16393 /* calculate qm_cid_count */
16394 sc->qm_cid_count = bxe_set_qm_cid_count(sc);
16395 BLOGD(sc, DBG_LOAD, "qm_cid_count=%d\n", sc->qm_cid_count);
16398 bxe_init_multi_cos(sc);
16400 bxe_add_sysctls(sc);
16406 * Device detach function.
16408 * Stops the controller, resets the controller, and releases resources.
16411 * 0 = Success, >0 = Failure
16414 bxe_detach(device_t dev)
16416 struct bxe_softc *sc;
16419 sc = device_get_softc(dev);
16421 BLOGD(sc, DBG_LOAD, "Starting detach...\n");
16424 if (ifp != NULL && if_vlantrunkinuse(ifp)) {
16425 BLOGE(sc, "Cannot detach while VLANs are in use.\n");
16431 /* stop the periodic callout */
16432 bxe_periodic_stop(sc);
16434 /* stop the chip taskqueue */
16435 atomic_store_rel_long(&sc->chip_tq_flags, CHIP_TQ_NONE);
16437 taskqueue_drain(sc->chip_tq, &sc->chip_tq_task);
16438 taskqueue_free(sc->chip_tq);
16439 sc->chip_tq = NULL;
16440 taskqueue_drain_timeout(taskqueue_thread,
16441 &sc->sp_err_timeout_task);
16444 /* stop and reset the controller if it was open */
16445 if (sc->state != BXE_STATE_CLOSED) {
16447 bxe_nic_unload(sc, UNLOAD_CLOSE, TRUE);
16448 sc->state = BXE_STATE_DISABLED;
16449 BXE_CORE_UNLOCK(sc);
16452 /* release the network interface */
16454 ether_ifdetach(ifp);
16456 ifmedia_removeall(&sc->ifmedia);
16458 /* XXX do the following based on driver state... */
16460 /* free the host hardware/software hsi structures */
16461 bxe_free_hsi_mem(sc);
16464 bxe_free_ilt_mem(sc);
16466 bxe_free_buf_rings(sc);
16468 /* release the interrupts */
16469 bxe_interrupt_free(sc);
16471 /* Release the mutexes*/
16472 bxe_destroy_fp_mutexs(sc);
16473 bxe_release_mutexes(sc);
16476 /* Release the PCIe BAR mapped memory */
16477 bxe_deallocate_bars(sc);
16479 /* Release the FreeBSD interface. */
16480 if (sc->ifp != NULL) {
16484 pci_disable_busmaster(dev);
16490 * Device shutdown function.
16492 * Stops and resets the controller.
16498 bxe_shutdown(device_t dev)
16500 struct bxe_softc *sc;
16502 sc = device_get_softc(dev);
16504 BLOGD(sc, DBG_LOAD, "Starting shutdown...\n");
16506 /* stop the periodic callout */
16507 bxe_periodic_stop(sc);
16509 if (sc->state != BXE_STATE_CLOSED) {
16511 bxe_nic_unload(sc, UNLOAD_NORMAL, FALSE);
16512 BXE_CORE_UNLOCK(sc);
16519 bxe_igu_ack_sb(struct bxe_softc *sc,
16526 uint32_t igu_addr = sc->igu_base_addr;
16527 igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
16528 bxe_igu_ack_sb_gen(sc, igu_sb_id, segment, index, op, update, igu_addr);
16532 bxe_igu_clear_sb_gen(struct bxe_softc *sc,
16537 uint32_t data, ctl, cnt = 100;
16538 uint32_t igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
16539 uint32_t igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
16540 uint32_t igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
16541 uint32_t sb_bit = 1 << (idu_sb_id%32);
16542 uint32_t func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
16543 uint32_t addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
16545 /* Not supported in BC mode */
16546 if (CHIP_INT_MODE_IS_BC(sc)) {
16550 data = ((IGU_USE_REGISTER_cstorm_type_0_sb_cleanup <<
16551 IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
16552 IGU_REGULAR_CLEANUP_SET |
16553 IGU_REGULAR_BCLEANUP);
16555 ctl = ((addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT) |
16556 (func_encode << IGU_CTRL_REG_FID_SHIFT) |
16557 (IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT));
16559 BLOGD(sc, DBG_LOAD, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
16560 data, igu_addr_data);
16561 REG_WR(sc, igu_addr_data, data);
16563 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle, 0, 0,
16564 BUS_SPACE_BARRIER_WRITE);
16567 BLOGD(sc, DBG_LOAD, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
16568 ctl, igu_addr_ctl);
16569 REG_WR(sc, igu_addr_ctl, ctl);
16571 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle, 0, 0,
16572 BUS_SPACE_BARRIER_WRITE);
16575 /* wait for clean up to finish */
16576 while (!(REG_RD(sc, igu_addr_ack) & sb_bit) && --cnt) {
16580 if (!(REG_RD(sc, igu_addr_ack) & sb_bit)) {
16581 BLOGD(sc, DBG_LOAD,
16582 "Unable to finish IGU cleanup: "
16583 "idu_sb_id %d offset %d bit %d (cnt %d)\n",
16584 idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
16589 bxe_igu_clear_sb(struct bxe_softc *sc,
16592 bxe_igu_clear_sb_gen(sc, SC_FUNC(sc), idu_sb_id, TRUE /*PF*/);
16601 /*******************/
16602 /* ECORE CALLBACKS */
16603 /*******************/
16606 bxe_reset_common(struct bxe_softc *sc)
16608 uint32_t val = 0x1400;
16611 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR), 0xd3ffff7f);
16613 if (CHIP_IS_E3(sc)) {
16614 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
16615 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
16618 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR), val);
16622 bxe_common_init_phy(struct bxe_softc *sc)
16624 uint32_t shmem_base[2];
16625 uint32_t shmem2_base[2];
16627 /* Avoid common init in case MFW supports LFA */
16628 if (SHMEM2_RD(sc, size) >
16629 (uint32_t)offsetof(struct shmem2_region,
16630 lfa_host_addr[SC_PORT(sc)])) {
16634 shmem_base[0] = sc->devinfo.shmem_base;
16635 shmem2_base[0] = sc->devinfo.shmem2_base;
16637 if (!CHIP_IS_E1x(sc)) {
16638 shmem_base[1] = SHMEM2_RD(sc, other_shmem_base_addr);
16639 shmem2_base[1] = SHMEM2_RD(sc, other_shmem2_base_addr);
16642 bxe_acquire_phy_lock(sc);
16643 elink_common_init_phy(sc, shmem_base, shmem2_base,
16644 sc->devinfo.chip_id, 0);
16645 bxe_release_phy_lock(sc);
16649 bxe_pf_disable(struct bxe_softc *sc)
16651 uint32_t val = REG_RD(sc, IGU_REG_PF_CONFIGURATION);
16653 val &= ~IGU_PF_CONF_FUNC_EN;
16655 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
16656 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
16657 REG_WR(sc, CFC_REG_WEAK_ENABLE_PF, 0);
16661 bxe_init_pxp(struct bxe_softc *sc)
16664 int r_order, w_order;
16666 devctl = bxe_pcie_capability_read(sc, PCIER_DEVICE_CTL, 2);
16668 BLOGD(sc, DBG_LOAD, "read 0x%08x from devctl\n", devctl);
16670 w_order = ((devctl & PCIEM_CTL_MAX_PAYLOAD) >> 5);
16672 if (sc->mrrs == -1) {
16673 r_order = ((devctl & PCIEM_CTL_MAX_READ_REQUEST) >> 12);
16675 BLOGD(sc, DBG_LOAD, "forcing read order to %d\n", sc->mrrs);
16676 r_order = sc->mrrs;
16679 ecore_init_pxp_arb(sc, r_order, w_order);
16683 bxe_get_pretend_reg(struct bxe_softc *sc)
16685 uint32_t base = PXP2_REG_PGL_PRETEND_FUNC_F0;
16686 uint32_t stride = (PXP2_REG_PGL_PRETEND_FUNC_F1 - base);
16687 return (base + (SC_ABS_FUNC(sc)) * stride);
16691 * Called only on E1H or E2.
16692 * When pretending to be PF, the pretend value is the function number 0..7.
16693 * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
16697 bxe_pretend_func(struct bxe_softc *sc,
16698 uint16_t pretend_func_val)
16700 uint32_t pretend_reg;
16702 if (CHIP_IS_E1H(sc) && (pretend_func_val > E1H_FUNC_MAX)) {
16706 /* get my own pretend register */
16707 pretend_reg = bxe_get_pretend_reg(sc);
16708 REG_WR(sc, pretend_reg, pretend_func_val);
16709 REG_RD(sc, pretend_reg);
16714 bxe_iov_init_dmae(struct bxe_softc *sc)
16720 bxe_iov_init_dq(struct bxe_softc *sc)
16725 /* send a NIG loopback debug packet */
16727 bxe_lb_pckt(struct bxe_softc *sc)
16729 uint32_t wb_write[3];
16731 /* Ethernet source and destination addresses */
16732 wb_write[0] = 0x55555555;
16733 wb_write[1] = 0x55555555;
16734 wb_write[2] = 0x20; /* SOP */
16735 REG_WR_DMAE(sc, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
16737 /* NON-IP protocol */
16738 wb_write[0] = 0x09000000;
16739 wb_write[1] = 0x55555555;
16740 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
16741 REG_WR_DMAE(sc, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
16745 * Some of the internal memories are not directly readable from the driver.
16746 * To test them we send debug packets.
16749 bxe_int_mem_test(struct bxe_softc *sc)
16755 if (CHIP_REV_IS_FPGA(sc)) {
16757 } else if (CHIP_REV_IS_EMUL(sc)) {
16763 /* disable inputs of parser neighbor blocks */
16764 REG_WR(sc, TSDM_REG_ENABLE_IN1, 0x0);
16765 REG_WR(sc, TCM_REG_PRS_IFEN, 0x0);
16766 REG_WR(sc, CFC_REG_DEBUG0, 0x1);
16767 REG_WR(sc, NIG_REG_PRS_REQ_IN_EN, 0x0);
16769 /* write 0 to parser credits for CFC search request */
16770 REG_WR(sc, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
16772 /* send Ethernet packet */
16775 /* TODO do i reset NIG statistic? */
16776 /* Wait until NIG register shows 1 packet of size 0x10 */
16777 count = 1000 * factor;
16779 bxe_read_dmae(sc, NIG_REG_STAT2_BRB_OCTET, 2);
16780 val = *BXE_SP(sc, wb_data[0]);
16790 BLOGE(sc, "NIG timeout val=0x%x\n", val);
16794 /* wait until PRS register shows 1 packet */
16795 count = (1000 * factor);
16797 val = REG_RD(sc, PRS_REG_NUM_OF_PACKETS);
16807 BLOGE(sc, "PRS timeout val=0x%x\n", val);
16811 /* Reset and init BRB, PRS */
16812 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
16814 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
16816 ecore_init_block(sc, BLOCK_BRB1, PHASE_COMMON);
16817 ecore_init_block(sc, BLOCK_PRS, PHASE_COMMON);
16819 /* Disable inputs of parser neighbor blocks */
16820 REG_WR(sc, TSDM_REG_ENABLE_IN1, 0x0);
16821 REG_WR(sc, TCM_REG_PRS_IFEN, 0x0);
16822 REG_WR(sc, CFC_REG_DEBUG0, 0x1);
16823 REG_WR(sc, NIG_REG_PRS_REQ_IN_EN, 0x0);
16825 /* Write 0 to parser credits for CFC search request */
16826 REG_WR(sc, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
16828 /* send 10 Ethernet packets */
16829 for (i = 0; i < 10; i++) {
16833 /* Wait until NIG register shows 10+1 packets of size 11*0x10 = 0xb0 */
16834 count = (1000 * factor);
16836 bxe_read_dmae(sc, NIG_REG_STAT2_BRB_OCTET, 2);
16837 val = *BXE_SP(sc, wb_data[0]);
16847 BLOGE(sc, "NIG timeout val=0x%x\n", val);
16851 /* Wait until PRS register shows 2 packets */
16852 val = REG_RD(sc, PRS_REG_NUM_OF_PACKETS);
16854 BLOGE(sc, "PRS timeout val=0x%x\n", val);
16857 /* Write 1 to parser credits for CFC search request */
16858 REG_WR(sc, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
16860 /* Wait until PRS register shows 3 packets */
16861 DELAY(10000 * factor);
16863 /* Wait until NIG register shows 1 packet of size 0x10 */
16864 val = REG_RD(sc, PRS_REG_NUM_OF_PACKETS);
16866 BLOGE(sc, "PRS timeout val=0x%x\n", val);
16869 /* clear NIG EOP FIFO */
16870 for (i = 0; i < 11; i++) {
16871 REG_RD(sc, NIG_REG_INGRESS_EOP_LB_FIFO);
16874 val = REG_RD(sc, NIG_REG_INGRESS_EOP_LB_EMPTY);
16876 BLOGE(sc, "clear of NIG failed val=0x%x\n", val);
16880 /* Reset and init BRB, PRS, NIG */
16881 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
16883 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
16885 ecore_init_block(sc, BLOCK_BRB1, PHASE_COMMON);
16886 ecore_init_block(sc, BLOCK_PRS, PHASE_COMMON);
16887 if (!CNIC_SUPPORT(sc)) {
16889 REG_WR(sc, PRS_REG_NIC_MODE, 1);
16892 /* Enable inputs of parser neighbor blocks */
16893 REG_WR(sc, TSDM_REG_ENABLE_IN1, 0x7fffffff);
16894 REG_WR(sc, TCM_REG_PRS_IFEN, 0x1);
16895 REG_WR(sc, CFC_REG_DEBUG0, 0x0);
16896 REG_WR(sc, NIG_REG_PRS_REQ_IN_EN, 0x1);
16902 bxe_setup_fan_failure_detection(struct bxe_softc *sc)
16909 val = (SHMEM_RD(sc, dev_info.shared_hw_config.config2) &
16910 SHARED_HW_CFG_FAN_FAILURE_MASK);
16912 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED) {
16916 * The fan failure mechanism is usually related to the PHY type since
16917 * the power consumption of the board is affected by the PHY. Currently,
16918 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
16920 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE) {
16921 for (port = PORT_0; port < PORT_MAX; port++) {
16922 is_required |= elink_fan_failure_det_req(sc,
16923 sc->devinfo.shmem_base,
16924 sc->devinfo.shmem2_base,
16929 BLOGD(sc, DBG_LOAD, "fan detection setting: %d\n", is_required);
16931 if (is_required == 0) {
16935 /* Fan failure is indicated by SPIO 5 */
16936 bxe_set_spio(sc, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
16938 /* set to active low mode */
16939 val = REG_RD(sc, MISC_REG_SPIO_INT);
16940 val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
16941 REG_WR(sc, MISC_REG_SPIO_INT, val);
16943 /* enable interrupt to signal the IGU */
16944 val = REG_RD(sc, MISC_REG_SPIO_EVENT_EN);
16945 val |= MISC_SPIO_SPIO5;
16946 REG_WR(sc, MISC_REG_SPIO_EVENT_EN, val);
16950 bxe_enable_blocks_attention(struct bxe_softc *sc)
16954 REG_WR(sc, PXP_REG_PXP_INT_MASK_0, 0);
16955 if (!CHIP_IS_E1x(sc)) {
16956 REG_WR(sc, PXP_REG_PXP_INT_MASK_1, 0x40);
16958 REG_WR(sc, PXP_REG_PXP_INT_MASK_1, 0);
16960 REG_WR(sc, DORQ_REG_DORQ_INT_MASK, 0);
16961 REG_WR(sc, CFC_REG_CFC_INT_MASK, 0);
16963 * mask read length error interrupts in brb for parser
16964 * (parsing unit and 'checksum and crc' unit)
16965 * these errors are legal (PU reads fixed length and CAC can cause
16966 * read length error on truncated packets)
16968 REG_WR(sc, BRB1_REG_BRB1_INT_MASK, 0xFC00);
16969 REG_WR(sc, QM_REG_QM_INT_MASK, 0);
16970 REG_WR(sc, TM_REG_TM_INT_MASK, 0);
16971 REG_WR(sc, XSDM_REG_XSDM_INT_MASK_0, 0);
16972 REG_WR(sc, XSDM_REG_XSDM_INT_MASK_1, 0);
16973 REG_WR(sc, XCM_REG_XCM_INT_MASK, 0);
16974 /* REG_WR(sc, XSEM_REG_XSEM_INT_MASK_0, 0); */
16975 /* REG_WR(sc, XSEM_REG_XSEM_INT_MASK_1, 0); */
16976 REG_WR(sc, USDM_REG_USDM_INT_MASK_0, 0);
16977 REG_WR(sc, USDM_REG_USDM_INT_MASK_1, 0);
16978 REG_WR(sc, UCM_REG_UCM_INT_MASK, 0);
16979 /* REG_WR(sc, USEM_REG_USEM_INT_MASK_0, 0); */
16980 /* REG_WR(sc, USEM_REG_USEM_INT_MASK_1, 0); */
16981 REG_WR(sc, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
16982 REG_WR(sc, CSDM_REG_CSDM_INT_MASK_0, 0);
16983 REG_WR(sc, CSDM_REG_CSDM_INT_MASK_1, 0);
16984 REG_WR(sc, CCM_REG_CCM_INT_MASK, 0);
16985 /* REG_WR(sc, CSEM_REG_CSEM_INT_MASK_0, 0); */
16986 /* REG_WR(sc, CSEM_REG_CSEM_INT_MASK_1, 0); */
16988 val = (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
16989 PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
16990 PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN);
16991 if (!CHIP_IS_E1x(sc)) {
16992 val |= (PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
16993 PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED);
16995 REG_WR(sc, PXP2_REG_PXP2_INT_MASK_0, val);
16997 REG_WR(sc, TSDM_REG_TSDM_INT_MASK_0, 0);
16998 REG_WR(sc, TSDM_REG_TSDM_INT_MASK_1, 0);
16999 REG_WR(sc, TCM_REG_TCM_INT_MASK, 0);
17000 /* REG_WR(sc, TSEM_REG_TSEM_INT_MASK_0, 0); */
17002 if (!CHIP_IS_E1x(sc)) {
17003 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
17004 REG_WR(sc, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
17007 REG_WR(sc, CDU_REG_CDU_INT_MASK, 0);
17008 REG_WR(sc, DMAE_REG_DMAE_INT_MASK, 0);
17009 /* REG_WR(sc, MISC_REG_MISC_INT_MASK, 0); */
17010 REG_WR(sc, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
17014 * bxe_init_hw_common - initialize the HW at the COMMON phase.
17016 * @sc: driver handle
17019 bxe_init_hw_common(struct bxe_softc *sc)
17021 uint8_t abs_func_id;
17024 BLOGD(sc, DBG_LOAD, "starting common init for func %d\n",
17028 * take the RESET lock to protect undi_unload flow from accessing
17029 * registers while we are resetting the chip
17031 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
17033 bxe_reset_common(sc);
17035 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET), 0xffffffff);
17038 if (CHIP_IS_E3(sc)) {
17039 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
17040 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
17043 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET), val);
17045 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
17047 ecore_init_block(sc, BLOCK_MISC, PHASE_COMMON);
17048 BLOGD(sc, DBG_LOAD, "after misc block init\n");
17050 if (!CHIP_IS_E1x(sc)) {
17052 * 4-port mode or 2-port mode we need to turn off master-enable for
17053 * everyone. After that we turn it back on for self. So, we disregard
17054 * multi-function, and always disable all functions on the given path,
17055 * this means 0,2,4,6 for path 0 and 1,3,5,7 for path 1
17057 for (abs_func_id = SC_PATH(sc);
17058 abs_func_id < (E2_FUNC_MAX * 2);
17059 abs_func_id += 2) {
17060 if (abs_func_id == SC_ABS_FUNC(sc)) {
17061 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
17065 bxe_pretend_func(sc, abs_func_id);
17067 /* clear pf enable */
17068 bxe_pf_disable(sc);
17070 bxe_pretend_func(sc, SC_ABS_FUNC(sc));
17074 BLOGD(sc, DBG_LOAD, "after pf disable\n");
17076 ecore_init_block(sc, BLOCK_PXP, PHASE_COMMON);
17078 if (CHIP_IS_E1(sc)) {
17080 * enable HW interrupt from PXP on USDM overflow
17081 * bit 16 on INT_MASK_0
17083 REG_WR(sc, PXP_REG_PXP_INT_MASK_0, 0);
17086 ecore_init_block(sc, BLOCK_PXP2, PHASE_COMMON);
17089 #ifdef __BIG_ENDIAN
17090 REG_WR(sc, PXP2_REG_RQ_QM_ENDIAN_M, 1);
17091 REG_WR(sc, PXP2_REG_RQ_TM_ENDIAN_M, 1);
17092 REG_WR(sc, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
17093 REG_WR(sc, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
17094 REG_WR(sc, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
17095 /* make sure this value is 0 */
17096 REG_WR(sc, PXP2_REG_RQ_HC_ENDIAN_M, 0);
17098 //REG_WR(sc, PXP2_REG_RD_PBF_SWAP_MODE, 1);
17099 REG_WR(sc, PXP2_REG_RD_QM_SWAP_MODE, 1);
17100 REG_WR(sc, PXP2_REG_RD_TM_SWAP_MODE, 1);
17101 REG_WR(sc, PXP2_REG_RD_SRC_SWAP_MODE, 1);
17102 REG_WR(sc, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
17105 ecore_ilt_init_page_size(sc, INITOP_SET);
17107 if (CHIP_REV_IS_FPGA(sc) && CHIP_IS_E1H(sc)) {
17108 REG_WR(sc, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
17111 /* let the HW do it's magic... */
17114 /* finish PXP init */
17115 val = REG_RD(sc, PXP2_REG_RQ_CFG_DONE);
17117 BLOGE(sc, "PXP2 CFG failed PXP2_REG_RQ_CFG_DONE val = 0x%x\n",
17121 val = REG_RD(sc, PXP2_REG_RD_INIT_DONE);
17123 BLOGE(sc, "PXP2 RD_INIT failed val = 0x%x\n", val);
17127 BLOGD(sc, DBG_LOAD, "after pxp init\n");
17130 * Timer bug workaround for E2 only. We need to set the entire ILT to have
17131 * entries with value "0" and valid bit on. This needs to be done by the
17132 * first PF that is loaded in a path (i.e. common phase)
17134 if (!CHIP_IS_E1x(sc)) {
17136 * In E2 there is a bug in the timers block that can cause function 6 / 7
17137 * (i.e. vnic3) to start even if it is marked as "scan-off".
17138 * This occurs when a different function (func2,3) is being marked
17139 * as "scan-off". Real-life scenario for example: if a driver is being
17140 * load-unloaded while func6,7 are down. This will cause the timer to access
17141 * the ilt, translate to a logical address and send a request to read/write.
17142 * Since the ilt for the function that is down is not valid, this will cause
17143 * a translation error which is unrecoverable.
17144 * The Workaround is intended to make sure that when this happens nothing
17145 * fatal will occur. The workaround:
17146 * 1. First PF driver which loads on a path will:
17147 * a. After taking the chip out of reset, by using pretend,
17148 * it will write "0" to the following registers of
17150 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
17151 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
17152 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
17153 * And for itself it will write '1' to
17154 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
17155 * dmae-operations (writing to pram for example.)
17156 * note: can be done for only function 6,7 but cleaner this
17158 * b. Write zero+valid to the entire ILT.
17159 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
17160 * VNIC3 (of that port). The range allocated will be the
17161 * entire ILT. This is needed to prevent ILT range error.
17162 * 2. Any PF driver load flow:
17163 * a. ILT update with the physical addresses of the allocated
17165 * b. Wait 20msec. - note that this timeout is needed to make
17166 * sure there are no requests in one of the PXP internal
17167 * queues with "old" ILT addresses.
17168 * c. PF enable in the PGLC.
17169 * d. Clear the was_error of the PF in the PGLC. (could have
17170 * occurred while driver was down)
17171 * e. PF enable in the CFC (WEAK + STRONG)
17172 * f. Timers scan enable
17173 * 3. PF driver unload flow:
17174 * a. Clear the Timers scan_en.
17175 * b. Polling for scan_on=0 for that PF.
17176 * c. Clear the PF enable bit in the PXP.
17177 * d. Clear the PF enable in the CFC (WEAK + STRONG)
17178 * e. Write zero+valid to all ILT entries (The valid bit must
17180 * f. If this is VNIC 3 of a port then also init
17181 * first_timers_ilt_entry to zero and last_timers_ilt_entry
17182 * to the last enrty in the ILT.
17185 * Currently the PF error in the PGLC is non recoverable.
17186 * In the future the there will be a recovery routine for this error.
17187 * Currently attention is masked.
17188 * Having an MCP lock on the load/unload process does not guarantee that
17189 * there is no Timer disable during Func6/7 enable. This is because the
17190 * Timers scan is currently being cleared by the MCP on FLR.
17191 * Step 2.d can be done only for PF6/7 and the driver can also check if
17192 * there is error before clearing it. But the flow above is simpler and
17194 * All ILT entries are written by zero+valid and not just PF6/7
17195 * ILT entries since in the future the ILT entries allocation for
17196 * PF-s might be dynamic.
17198 struct ilt_client_info ilt_cli;
17199 struct ecore_ilt ilt;
17201 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
17202 memset(&ilt, 0, sizeof(struct ecore_ilt));
17204 /* initialize dummy TM client */
17206 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
17207 ilt_cli.client_num = ILT_CLIENT_TM;
17210 * Step 1: set zeroes to all ilt page entries with valid bit on
17211 * Step 2: set the timers first/last ilt entry to point
17212 * to the entire range to prevent ILT range error for 3rd/4th
17213 * vnic (this code assumes existence of the vnic)
17215 * both steps performed by call to ecore_ilt_client_init_op()
17216 * with dummy TM client
17218 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
17219 * and his brother are split registers
17222 bxe_pretend_func(sc, (SC_PATH(sc) + 6));
17223 ecore_ilt_client_init_op_ilt(sc, &ilt, &ilt_cli, INITOP_CLEAR);
17224 bxe_pretend_func(sc, SC_ABS_FUNC(sc));
17226 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN, BXE_PXP_DRAM_ALIGN);
17227 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN_RD, BXE_PXP_DRAM_ALIGN);
17228 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
17231 REG_WR(sc, PXP2_REG_RQ_DISABLE_INPUTS, 0);
17232 REG_WR(sc, PXP2_REG_RD_DISABLE_INPUTS, 0);
17234 if (!CHIP_IS_E1x(sc)) {
17235 int factor = CHIP_REV_IS_EMUL(sc) ? 1000 :
17236 (CHIP_REV_IS_FPGA(sc) ? 400 : 0);
17238 ecore_init_block(sc, BLOCK_PGLUE_B, PHASE_COMMON);
17239 ecore_init_block(sc, BLOCK_ATC, PHASE_COMMON);
17241 /* let the HW do it's magic... */
17244 val = REG_RD(sc, ATC_REG_ATC_INIT_DONE);
17245 } while (factor-- && (val != 1));
17248 BLOGE(sc, "ATC_INIT failed val = 0x%x\n", val);
17253 BLOGD(sc, DBG_LOAD, "after pglue and atc init\n");
17255 ecore_init_block(sc, BLOCK_DMAE, PHASE_COMMON);
17257 bxe_iov_init_dmae(sc);
17259 /* clean the DMAE memory */
17260 sc->dmae_ready = 1;
17261 ecore_init_fill(sc, TSEM_REG_PRAM, 0, 8, 1);
17263 ecore_init_block(sc, BLOCK_TCM, PHASE_COMMON);
17265 ecore_init_block(sc, BLOCK_UCM, PHASE_COMMON);
17267 ecore_init_block(sc, BLOCK_CCM, PHASE_COMMON);
17269 ecore_init_block(sc, BLOCK_XCM, PHASE_COMMON);
17271 bxe_read_dmae(sc, XSEM_REG_PASSIVE_BUFFER, 3);
17272 bxe_read_dmae(sc, CSEM_REG_PASSIVE_BUFFER, 3);
17273 bxe_read_dmae(sc, TSEM_REG_PASSIVE_BUFFER, 3);
17274 bxe_read_dmae(sc, USEM_REG_PASSIVE_BUFFER, 3);
17276 ecore_init_block(sc, BLOCK_QM, PHASE_COMMON);
17278 /* QM queues pointers table */
17279 ecore_qm_init_ptr_table(sc, sc->qm_cid_count, INITOP_SET);
17281 /* soft reset pulse */
17282 REG_WR(sc, QM_REG_SOFT_RESET, 1);
17283 REG_WR(sc, QM_REG_SOFT_RESET, 0);
17285 if (CNIC_SUPPORT(sc))
17286 ecore_init_block(sc, BLOCK_TM, PHASE_COMMON);
17288 ecore_init_block(sc, BLOCK_DORQ, PHASE_COMMON);
17289 REG_WR(sc, DORQ_REG_DPM_CID_OFST, BXE_DB_SHIFT);
17290 if (!CHIP_REV_IS_SLOW(sc)) {
17291 /* enable hw interrupt from doorbell Q */
17292 REG_WR(sc, DORQ_REG_DORQ_INT_MASK, 0);
17295 ecore_init_block(sc, BLOCK_BRB1, PHASE_COMMON);
17297 ecore_init_block(sc, BLOCK_PRS, PHASE_COMMON);
17298 REG_WR(sc, PRS_REG_A_PRSU_20, 0xf);
17300 if (!CHIP_IS_E1(sc)) {
17301 REG_WR(sc, PRS_REG_E1HOV_MODE, sc->devinfo.mf_info.path_has_ovlan);
17304 if (!CHIP_IS_E1x(sc) && !CHIP_IS_E3B0(sc)) {
17305 if (IS_MF_AFEX(sc)) {
17307 * configure that AFEX and VLAN headers must be
17308 * received in AFEX mode
17310 REG_WR(sc, PRS_REG_HDRS_AFTER_BASIC, 0xE);
17311 REG_WR(sc, PRS_REG_MUST_HAVE_HDRS, 0xA);
17312 REG_WR(sc, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
17313 REG_WR(sc, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
17314 REG_WR(sc, PRS_REG_TAG_LEN_0, 0x4);
17317 * Bit-map indicating which L2 hdrs may appear
17318 * after the basic Ethernet header
17320 REG_WR(sc, PRS_REG_HDRS_AFTER_BASIC,
17321 sc->devinfo.mf_info.path_has_ovlan ? 7 : 6);
17325 ecore_init_block(sc, BLOCK_TSDM, PHASE_COMMON);
17326 ecore_init_block(sc, BLOCK_CSDM, PHASE_COMMON);
17327 ecore_init_block(sc, BLOCK_USDM, PHASE_COMMON);
17328 ecore_init_block(sc, BLOCK_XSDM, PHASE_COMMON);
17330 if (!CHIP_IS_E1x(sc)) {
17331 /* reset VFC memories */
17332 REG_WR(sc, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
17333 VFC_MEMORIES_RST_REG_CAM_RST |
17334 VFC_MEMORIES_RST_REG_RAM_RST);
17335 REG_WR(sc, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
17336 VFC_MEMORIES_RST_REG_CAM_RST |
17337 VFC_MEMORIES_RST_REG_RAM_RST);
17342 ecore_init_block(sc, BLOCK_TSEM, PHASE_COMMON);
17343 ecore_init_block(sc, BLOCK_USEM, PHASE_COMMON);
17344 ecore_init_block(sc, BLOCK_CSEM, PHASE_COMMON);
17345 ecore_init_block(sc, BLOCK_XSEM, PHASE_COMMON);
17347 /* sync semi rtc */
17348 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
17350 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
17353 ecore_init_block(sc, BLOCK_UPB, PHASE_COMMON);
17354 ecore_init_block(sc, BLOCK_XPB, PHASE_COMMON);
17355 ecore_init_block(sc, BLOCK_PBF, PHASE_COMMON);
17357 if (!CHIP_IS_E1x(sc)) {
17358 if (IS_MF_AFEX(sc)) {
17360 * configure that AFEX and VLAN headers must be
17361 * sent in AFEX mode
17363 REG_WR(sc, PBF_REG_HDRS_AFTER_BASIC, 0xE);
17364 REG_WR(sc, PBF_REG_MUST_HAVE_HDRS, 0xA);
17365 REG_WR(sc, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
17366 REG_WR(sc, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
17367 REG_WR(sc, PBF_REG_TAG_LEN_0, 0x4);
17369 REG_WR(sc, PBF_REG_HDRS_AFTER_BASIC,
17370 sc->devinfo.mf_info.path_has_ovlan ? 7 : 6);
17374 REG_WR(sc, SRC_REG_SOFT_RST, 1);
17376 ecore_init_block(sc, BLOCK_SRC, PHASE_COMMON);
17378 if (CNIC_SUPPORT(sc)) {
17379 REG_WR(sc, SRC_REG_KEYSEARCH_0, 0x63285672);
17380 REG_WR(sc, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
17381 REG_WR(sc, SRC_REG_KEYSEARCH_2, 0x223aef9b);
17382 REG_WR(sc, SRC_REG_KEYSEARCH_3, 0x26001e3a);
17383 REG_WR(sc, SRC_REG_KEYSEARCH_4, 0x7ae91116);
17384 REG_WR(sc, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
17385 REG_WR(sc, SRC_REG_KEYSEARCH_6, 0x298d8adf);
17386 REG_WR(sc, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
17387 REG_WR(sc, SRC_REG_KEYSEARCH_8, 0x1830f82f);
17388 REG_WR(sc, SRC_REG_KEYSEARCH_9, 0x01e46be7);
17390 REG_WR(sc, SRC_REG_SOFT_RST, 0);
17392 if (sizeof(union cdu_context) != 1024) {
17393 /* we currently assume that a context is 1024 bytes */
17394 BLOGE(sc, "please adjust the size of cdu_context(%ld)\n",
17395 (long)sizeof(union cdu_context));
17398 ecore_init_block(sc, BLOCK_CDU, PHASE_COMMON);
17399 val = (4 << 24) + (0 << 12) + 1024;
17400 REG_WR(sc, CDU_REG_CDU_GLOBAL_PARAMS, val);
17402 ecore_init_block(sc, BLOCK_CFC, PHASE_COMMON);
17404 REG_WR(sc, CFC_REG_INIT_REG, 0x7FF);
17405 /* enable context validation interrupt from CFC */
17406 REG_WR(sc, CFC_REG_CFC_INT_MASK, 0);
17408 /* set the thresholds to prevent CFC/CDU race */
17409 REG_WR(sc, CFC_REG_DEBUG0, 0x20020000);
17410 ecore_init_block(sc, BLOCK_HC, PHASE_COMMON);
17412 if (!CHIP_IS_E1x(sc) && BXE_NOMCP(sc)) {
17413 REG_WR(sc, IGU_REG_RESET_MEMORIES, 0x36);
17416 ecore_init_block(sc, BLOCK_IGU, PHASE_COMMON);
17417 ecore_init_block(sc, BLOCK_MISC_AEU, PHASE_COMMON);
17419 /* Reset PCIE errors for debug */
17420 REG_WR(sc, 0x2814, 0xffffffff);
17421 REG_WR(sc, 0x3820, 0xffffffff);
17423 if (!CHIP_IS_E1x(sc)) {
17424 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
17425 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
17426 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
17427 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
17428 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
17429 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
17430 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
17431 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
17432 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
17433 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
17434 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
17437 ecore_init_block(sc, BLOCK_NIG, PHASE_COMMON);
17439 if (!CHIP_IS_E1(sc)) {
17440 /* in E3 this done in per-port section */
17441 if (!CHIP_IS_E3(sc))
17442 REG_WR(sc, NIG_REG_LLH_MF_MODE, IS_MF(sc));
17445 if (CHIP_IS_E1H(sc)) {
17446 /* not applicable for E2 (and above ...) */
17447 REG_WR(sc, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(sc));
17450 if (CHIP_REV_IS_SLOW(sc)) {
17454 /* finish CFC init */
17455 val = reg_poll(sc, CFC_REG_LL_INIT_DONE, 1, 100, 10);
17457 BLOGE(sc, "CFC LL_INIT failed val=0x%x\n", val);
17460 val = reg_poll(sc, CFC_REG_AC_INIT_DONE, 1, 100, 10);
17462 BLOGE(sc, "CFC AC_INIT failed val=0x%x\n", val);
17465 val = reg_poll(sc, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
17467 BLOGE(sc, "CFC CAM_INIT failed val=0x%x\n", val);
17470 REG_WR(sc, CFC_REG_DEBUG0, 0);
17472 if (CHIP_IS_E1(sc)) {
17473 /* read NIG statistic to see if this is our first up since powerup */
17474 bxe_read_dmae(sc, NIG_REG_STAT2_BRB_OCTET, 2);
17475 val = *BXE_SP(sc, wb_data[0]);
17477 /* do internal memory self test */
17478 if ((val == 0) && bxe_int_mem_test(sc)) {
17479 BLOGE(sc, "internal mem self test failed val=0x%x\n", val);
17484 bxe_setup_fan_failure_detection(sc);
17486 /* clear PXP2 attentions */
17487 REG_RD(sc, PXP2_REG_PXP2_INT_STS_CLR_0);
17489 bxe_enable_blocks_attention(sc);
17491 if (!CHIP_REV_IS_SLOW(sc)) {
17492 ecore_enable_blocks_parity(sc);
17495 if (!BXE_NOMCP(sc)) {
17496 if (CHIP_IS_E1x(sc)) {
17497 bxe_common_init_phy(sc);
17505 * bxe_init_hw_common_chip - init HW at the COMMON_CHIP phase.
17507 * @sc: driver handle
17510 bxe_init_hw_common_chip(struct bxe_softc *sc)
17512 int rc = bxe_init_hw_common(sc);
17515 BLOGE(sc, "bxe_init_hw_common failed rc=%d\n", rc);
17519 /* In E2 2-PORT mode, same ext phy is used for the two paths */
17520 if (!BXE_NOMCP(sc)) {
17521 bxe_common_init_phy(sc);
17528 bxe_init_hw_port(struct bxe_softc *sc)
17530 int port = SC_PORT(sc);
17531 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
17532 uint32_t low, high;
17535 BLOGD(sc, DBG_LOAD, "starting port init for port %d\n", port);
17537 REG_WR(sc, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
17539 ecore_init_block(sc, BLOCK_MISC, init_phase);
17540 ecore_init_block(sc, BLOCK_PXP, init_phase);
17541 ecore_init_block(sc, BLOCK_PXP2, init_phase);
17544 * Timers bug workaround: disables the pf_master bit in pglue at
17545 * common phase, we need to enable it here before any dmae access are
17546 * attempted. Therefore we manually added the enable-master to the
17547 * port phase (it also happens in the function phase)
17549 if (!CHIP_IS_E1x(sc)) {
17550 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
17553 ecore_init_block(sc, BLOCK_ATC, init_phase);
17554 ecore_init_block(sc, BLOCK_DMAE, init_phase);
17555 ecore_init_block(sc, BLOCK_PGLUE_B, init_phase);
17556 ecore_init_block(sc, BLOCK_QM, init_phase);
17558 ecore_init_block(sc, BLOCK_TCM, init_phase);
17559 ecore_init_block(sc, BLOCK_UCM, init_phase);
17560 ecore_init_block(sc, BLOCK_CCM, init_phase);
17561 ecore_init_block(sc, BLOCK_XCM, init_phase);
17563 /* QM cid (connection) count */
17564 ecore_qm_init_cid_count(sc, sc->qm_cid_count, INITOP_SET);
17566 if (CNIC_SUPPORT(sc)) {
17567 ecore_init_block(sc, BLOCK_TM, init_phase);
17568 REG_WR(sc, TM_REG_LIN0_SCAN_TIME + port*4, 20);
17569 REG_WR(sc, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
17572 ecore_init_block(sc, BLOCK_DORQ, init_phase);
17574 ecore_init_block(sc, BLOCK_BRB1, init_phase);
17576 if (CHIP_IS_E1(sc) || CHIP_IS_E1H(sc)) {
17578 low = (BXE_ONE_PORT(sc) ? 160 : 246);
17579 } else if (sc->mtu > 4096) {
17580 if (BXE_ONE_PORT(sc)) {
17584 /* (24*1024 + val*4)/256 */
17585 low = (96 + (val / 64) + ((val % 64) ? 1 : 0));
17588 low = (BXE_ONE_PORT(sc) ? 80 : 160);
17590 high = (low + 56); /* 14*1024/256 */
17591 REG_WR(sc, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
17592 REG_WR(sc, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
17595 if (CHIP_IS_MODE_4_PORT(sc)) {
17596 REG_WR(sc, SC_PORT(sc) ?
17597 BRB1_REG_MAC_GUARANTIED_1 :
17598 BRB1_REG_MAC_GUARANTIED_0, 40);
17601 ecore_init_block(sc, BLOCK_PRS, init_phase);
17602 if (CHIP_IS_E3B0(sc)) {
17603 if (IS_MF_AFEX(sc)) {
17604 /* configure headers for AFEX mode */
17605 REG_WR(sc, SC_PORT(sc) ?
17606 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
17607 PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
17608 REG_WR(sc, SC_PORT(sc) ?
17609 PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
17610 PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
17611 REG_WR(sc, SC_PORT(sc) ?
17612 PRS_REG_MUST_HAVE_HDRS_PORT_1 :
17613 PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
17615 /* Ovlan exists only if we are in multi-function +
17616 * switch-dependent mode, in switch-independent there
17617 * is no ovlan headers
17619 REG_WR(sc, SC_PORT(sc) ?
17620 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
17621 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
17622 (sc->devinfo.mf_info.path_has_ovlan ? 7 : 6));
17626 ecore_init_block(sc, BLOCK_TSDM, init_phase);
17627 ecore_init_block(sc, BLOCK_CSDM, init_phase);
17628 ecore_init_block(sc, BLOCK_USDM, init_phase);
17629 ecore_init_block(sc, BLOCK_XSDM, init_phase);
17631 ecore_init_block(sc, BLOCK_TSEM, init_phase);
17632 ecore_init_block(sc, BLOCK_USEM, init_phase);
17633 ecore_init_block(sc, BLOCK_CSEM, init_phase);
17634 ecore_init_block(sc, BLOCK_XSEM, init_phase);
17636 ecore_init_block(sc, BLOCK_UPB, init_phase);
17637 ecore_init_block(sc, BLOCK_XPB, init_phase);
17639 ecore_init_block(sc, BLOCK_PBF, init_phase);
17641 if (CHIP_IS_E1x(sc)) {
17642 /* configure PBF to work without PAUSE mtu 9000 */
17643 REG_WR(sc, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
17645 /* update threshold */
17646 REG_WR(sc, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
17647 /* update init credit */
17648 REG_WR(sc, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
17650 /* probe changes */
17651 REG_WR(sc, PBF_REG_INIT_P0 + port*4, 1);
17653 REG_WR(sc, PBF_REG_INIT_P0 + port*4, 0);
17656 if (CNIC_SUPPORT(sc)) {
17657 ecore_init_block(sc, BLOCK_SRC, init_phase);
17660 ecore_init_block(sc, BLOCK_CDU, init_phase);
17661 ecore_init_block(sc, BLOCK_CFC, init_phase);
17663 if (CHIP_IS_E1(sc)) {
17664 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, 0);
17665 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, 0);
17667 ecore_init_block(sc, BLOCK_HC, init_phase);
17669 ecore_init_block(sc, BLOCK_IGU, init_phase);
17671 ecore_init_block(sc, BLOCK_MISC_AEU, init_phase);
17672 /* init aeu_mask_attn_func_0/1:
17673 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
17674 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
17675 * bits 4-7 are used for "per vn group attention" */
17676 val = IS_MF(sc) ? 0xF7 : 0x7;
17677 /* Enable DCBX attention for all but E1 */
17678 val |= CHIP_IS_E1(sc) ? 0 : 0x10;
17679 REG_WR(sc, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
17681 ecore_init_block(sc, BLOCK_NIG, init_phase);
17683 if (!CHIP_IS_E1x(sc)) {
17684 /* Bit-map indicating which L2 hdrs may appear after the
17685 * basic Ethernet header
17687 if (IS_MF_AFEX(sc)) {
17688 REG_WR(sc, SC_PORT(sc) ?
17689 NIG_REG_P1_HDRS_AFTER_BASIC :
17690 NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
17692 REG_WR(sc, SC_PORT(sc) ?
17693 NIG_REG_P1_HDRS_AFTER_BASIC :
17694 NIG_REG_P0_HDRS_AFTER_BASIC,
17695 IS_MF_SD(sc) ? 7 : 6);
17698 if (CHIP_IS_E3(sc)) {
17699 REG_WR(sc, SC_PORT(sc) ?
17700 NIG_REG_LLH1_MF_MODE :
17701 NIG_REG_LLH_MF_MODE, IS_MF(sc));
17704 if (!CHIP_IS_E3(sc)) {
17705 REG_WR(sc, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
17708 if (!CHIP_IS_E1(sc)) {
17709 /* 0x2 disable mf_ov, 0x1 enable */
17710 REG_WR(sc, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
17711 (IS_MF_SD(sc) ? 0x1 : 0x2));
17713 if (!CHIP_IS_E1x(sc)) {
17715 switch (sc->devinfo.mf_info.mf_mode) {
17716 case MULTI_FUNCTION_SD:
17719 case MULTI_FUNCTION_SI:
17720 case MULTI_FUNCTION_AFEX:
17725 REG_WR(sc, (SC_PORT(sc) ? NIG_REG_LLH1_CLS_TYPE :
17726 NIG_REG_LLH0_CLS_TYPE), val);
17728 REG_WR(sc, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
17729 REG_WR(sc, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
17730 REG_WR(sc, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
17733 /* If SPIO5 is set to generate interrupts, enable it for this port */
17734 val = REG_RD(sc, MISC_REG_SPIO_EVENT_EN);
17735 if (val & MISC_SPIO_SPIO5) {
17736 uint32_t reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
17737 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
17738 val = REG_RD(sc, reg_addr);
17739 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
17740 REG_WR(sc, reg_addr, val);
17747 bxe_flr_clnup_reg_poll(struct bxe_softc *sc,
17750 uint32_t poll_count)
17752 uint32_t cur_cnt = poll_count;
17755 while ((val = REG_RD(sc, reg)) != expected && cur_cnt--) {
17756 DELAY(FLR_WAIT_INTERVAL);
17763 bxe_flr_clnup_poll_hw_counter(struct bxe_softc *sc,
17768 uint32_t val = bxe_flr_clnup_reg_poll(sc, reg, 0, poll_cnt);
17771 BLOGE(sc, "%s usage count=%d\n", msg, val);
17778 /* Common routines with VF FLR cleanup */
17780 bxe_flr_clnup_poll_count(struct bxe_softc *sc)
17782 /* adjust polling timeout */
17783 if (CHIP_REV_IS_EMUL(sc)) {
17784 return (FLR_POLL_CNT * 2000);
17787 if (CHIP_REV_IS_FPGA(sc)) {
17788 return (FLR_POLL_CNT * 120);
17791 return (FLR_POLL_CNT);
17795 bxe_poll_hw_usage_counters(struct bxe_softc *sc,
17798 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
17799 if (bxe_flr_clnup_poll_hw_counter(sc,
17800 CFC_REG_NUM_LCIDS_INSIDE_PF,
17801 "CFC PF usage counter timed out",
17806 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
17807 if (bxe_flr_clnup_poll_hw_counter(sc,
17808 DORQ_REG_PF_USAGE_CNT,
17809 "DQ PF usage counter timed out",
17814 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
17815 if (bxe_flr_clnup_poll_hw_counter(sc,
17816 QM_REG_PF_USG_CNT_0 + 4*SC_FUNC(sc),
17817 "QM PF usage counter timed out",
17822 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
17823 if (bxe_flr_clnup_poll_hw_counter(sc,
17824 TM_REG_LIN0_VNIC_UC + 4*SC_PORT(sc),
17825 "Timers VNIC usage counter timed out",
17830 if (bxe_flr_clnup_poll_hw_counter(sc,
17831 TM_REG_LIN0_NUM_SCANS + 4*SC_PORT(sc),
17832 "Timers NUM_SCANS usage counter timed out",
17837 /* Wait DMAE PF usage counter to zero */
17838 if (bxe_flr_clnup_poll_hw_counter(sc,
17839 dmae_reg_go_c[INIT_DMAE_C(sc)],
17840 "DMAE dommand register timed out",
17848 #define OP_GEN_PARAM(param) \
17849 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
17850 #define OP_GEN_TYPE(type) \
17851 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
17852 #define OP_GEN_AGG_VECT(index) \
17853 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
17856 bxe_send_final_clnup(struct bxe_softc *sc,
17857 uint8_t clnup_func,
17860 uint32_t op_gen_command = 0;
17861 uint32_t comp_addr = (BAR_CSTRORM_INTMEM +
17862 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func));
17865 if (REG_RD(sc, comp_addr)) {
17866 BLOGE(sc, "Cleanup complete was not 0 before sending\n");
17870 op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
17871 op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
17872 op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
17873 op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
17875 BLOGD(sc, DBG_LOAD, "sending FW Final cleanup\n");
17876 REG_WR(sc, XSDM_REG_OPERATION_GEN, op_gen_command);
17878 if (bxe_flr_clnup_reg_poll(sc, comp_addr, 1, poll_cnt) != 1) {
17879 BLOGE(sc, "FW final cleanup did not succeed\n");
17880 BLOGD(sc, DBG_LOAD, "At timeout completion address contained %x\n",
17881 (REG_RD(sc, comp_addr)));
17882 bxe_panic(sc, ("FLR cleanup failed\n"));
17886 /* Zero completion for nxt FLR */
17887 REG_WR(sc, comp_addr, 0);
17893 bxe_pbf_pN_buf_flushed(struct bxe_softc *sc,
17894 struct pbf_pN_buf_regs *regs,
17895 uint32_t poll_count)
17897 uint32_t init_crd, crd, crd_start, crd_freed, crd_freed_start;
17898 uint32_t cur_cnt = poll_count;
17900 crd_freed = crd_freed_start = REG_RD(sc, regs->crd_freed);
17901 crd = crd_start = REG_RD(sc, regs->crd);
17902 init_crd = REG_RD(sc, regs->init_crd);
17904 BLOGD(sc, DBG_LOAD, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
17905 BLOGD(sc, DBG_LOAD, "CREDIT[%d] : s:%x\n", regs->pN, crd);
17906 BLOGD(sc, DBG_LOAD, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
17908 while ((crd != init_crd) &&
17909 ((uint32_t)((int32_t)crd_freed - (int32_t)crd_freed_start) <
17910 (init_crd - crd_start))) {
17912 DELAY(FLR_WAIT_INTERVAL);
17913 crd = REG_RD(sc, regs->crd);
17914 crd_freed = REG_RD(sc, regs->crd_freed);
17916 BLOGD(sc, DBG_LOAD, "PBF tx buffer[%d] timed out\n", regs->pN);
17917 BLOGD(sc, DBG_LOAD, "CREDIT[%d] : c:%x\n", regs->pN, crd);
17918 BLOGD(sc, DBG_LOAD, "CREDIT_FREED[%d]: c:%x\n", regs->pN, crd_freed);
17923 BLOGD(sc, DBG_LOAD, "Waited %d*%d usec for PBF tx buffer[%d]\n",
17924 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
17928 bxe_pbf_pN_cmd_flushed(struct bxe_softc *sc,
17929 struct pbf_pN_cmd_regs *regs,
17930 uint32_t poll_count)
17932 uint32_t occup, to_free, freed, freed_start;
17933 uint32_t cur_cnt = poll_count;
17935 occup = to_free = REG_RD(sc, regs->lines_occup);
17936 freed = freed_start = REG_RD(sc, regs->lines_freed);
17938 BLOGD(sc, DBG_LOAD, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
17939 BLOGD(sc, DBG_LOAD, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
17942 ((uint32_t)((int32_t)freed - (int32_t)freed_start) < to_free)) {
17944 DELAY(FLR_WAIT_INTERVAL);
17945 occup = REG_RD(sc, regs->lines_occup);
17946 freed = REG_RD(sc, regs->lines_freed);
17948 BLOGD(sc, DBG_LOAD, "PBF cmd queue[%d] timed out\n", regs->pN);
17949 BLOGD(sc, DBG_LOAD, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
17950 BLOGD(sc, DBG_LOAD, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
17955 BLOGD(sc, DBG_LOAD, "Waited %d*%d usec for PBF cmd queue[%d]\n",
17956 poll_count - cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
17960 bxe_tx_hw_flushed(struct bxe_softc *sc, uint32_t poll_count)
17962 struct pbf_pN_cmd_regs cmd_regs[] = {
17963 {0, (CHIP_IS_E3B0(sc)) ?
17964 PBF_REG_TQ_OCCUPANCY_Q0 :
17965 PBF_REG_P0_TQ_OCCUPANCY,
17966 (CHIP_IS_E3B0(sc)) ?
17967 PBF_REG_TQ_LINES_FREED_CNT_Q0 :
17968 PBF_REG_P0_TQ_LINES_FREED_CNT},
17969 {1, (CHIP_IS_E3B0(sc)) ?
17970 PBF_REG_TQ_OCCUPANCY_Q1 :
17971 PBF_REG_P1_TQ_OCCUPANCY,
17972 (CHIP_IS_E3B0(sc)) ?
17973 PBF_REG_TQ_LINES_FREED_CNT_Q1 :
17974 PBF_REG_P1_TQ_LINES_FREED_CNT},
17975 {4, (CHIP_IS_E3B0(sc)) ?
17976 PBF_REG_TQ_OCCUPANCY_LB_Q :
17977 PBF_REG_P4_TQ_OCCUPANCY,
17978 (CHIP_IS_E3B0(sc)) ?
17979 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
17980 PBF_REG_P4_TQ_LINES_FREED_CNT}
17983 struct pbf_pN_buf_regs buf_regs[] = {
17984 {0, (CHIP_IS_E3B0(sc)) ?
17985 PBF_REG_INIT_CRD_Q0 :
17986 PBF_REG_P0_INIT_CRD ,
17987 (CHIP_IS_E3B0(sc)) ?
17988 PBF_REG_CREDIT_Q0 :
17990 (CHIP_IS_E3B0(sc)) ?
17991 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
17992 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
17993 {1, (CHIP_IS_E3B0(sc)) ?
17994 PBF_REG_INIT_CRD_Q1 :
17995 PBF_REG_P1_INIT_CRD,
17996 (CHIP_IS_E3B0(sc)) ?
17997 PBF_REG_CREDIT_Q1 :
17999 (CHIP_IS_E3B0(sc)) ?
18000 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
18001 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
18002 {4, (CHIP_IS_E3B0(sc)) ?
18003 PBF_REG_INIT_CRD_LB_Q :
18004 PBF_REG_P4_INIT_CRD,
18005 (CHIP_IS_E3B0(sc)) ?
18006 PBF_REG_CREDIT_LB_Q :
18008 (CHIP_IS_E3B0(sc)) ?
18009 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
18010 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
18015 /* Verify the command queues are flushed P0, P1, P4 */
18016 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++) {
18017 bxe_pbf_pN_cmd_flushed(sc, &cmd_regs[i], poll_count);
18020 /* Verify the transmission buffers are flushed P0, P1, P4 */
18021 for (i = 0; i < ARRAY_SIZE(buf_regs); i++) {
18022 bxe_pbf_pN_buf_flushed(sc, &buf_regs[i], poll_count);
18027 bxe_hw_enable_status(struct bxe_softc *sc)
18031 val = REG_RD(sc, CFC_REG_WEAK_ENABLE_PF);
18032 BLOGD(sc, DBG_LOAD, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
18034 val = REG_RD(sc, PBF_REG_DISABLE_PF);
18035 BLOGD(sc, DBG_LOAD, "PBF_REG_DISABLE_PF is 0x%x\n", val);
18037 val = REG_RD(sc, IGU_REG_PCI_PF_MSI_EN);
18038 BLOGD(sc, DBG_LOAD, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
18040 val = REG_RD(sc, IGU_REG_PCI_PF_MSIX_EN);
18041 BLOGD(sc, DBG_LOAD, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
18043 val = REG_RD(sc, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
18044 BLOGD(sc, DBG_LOAD, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
18046 val = REG_RD(sc, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
18047 BLOGD(sc, DBG_LOAD, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
18049 val = REG_RD(sc, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
18050 BLOGD(sc, DBG_LOAD, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
18052 val = REG_RD(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
18053 BLOGD(sc, DBG_LOAD, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n", val);
18057 bxe_pf_flr_clnup(struct bxe_softc *sc)
18059 uint32_t poll_cnt = bxe_flr_clnup_poll_count(sc);
18061 BLOGD(sc, DBG_LOAD, "Cleanup after FLR PF[%d]\n", SC_ABS_FUNC(sc));
18063 /* Re-enable PF target read access */
18064 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
18066 /* Poll HW usage counters */
18067 BLOGD(sc, DBG_LOAD, "Polling usage counters\n");
18068 if (bxe_poll_hw_usage_counters(sc, poll_cnt)) {
18072 /* Zero the igu 'trailing edge' and 'leading edge' */
18074 /* Send the FW cleanup command */
18075 if (bxe_send_final_clnup(sc, (uint8_t)SC_FUNC(sc), poll_cnt)) {
18081 /* Verify TX hw is flushed */
18082 bxe_tx_hw_flushed(sc, poll_cnt);
18084 /* Wait 100ms (not adjusted according to platform) */
18087 /* Verify no pending pci transactions */
18088 if (bxe_is_pcie_pending(sc)) {
18089 BLOGE(sc, "PCIE Transactions still pending\n");
18093 bxe_hw_enable_status(sc);
18096 * Master enable - Due to WB DMAE writes performed before this
18097 * register is re-initialized as part of the regular function init
18099 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
18105 bxe_init_hw_func(struct bxe_softc *sc)
18107 int port = SC_PORT(sc);
18108 int func = SC_FUNC(sc);
18109 int init_phase = PHASE_PF0 + func;
18110 struct ecore_ilt *ilt = sc->ilt;
18111 uint16_t cdu_ilt_start;
18112 uint32_t addr, val;
18113 uint32_t main_mem_base, main_mem_size, main_mem_prty_clr;
18114 int i, main_mem_width, rc;
18116 BLOGD(sc, DBG_LOAD, "starting func init for func %d\n", func);
18119 if (!CHIP_IS_E1x(sc)) {
18120 rc = bxe_pf_flr_clnup(sc);
18122 BLOGE(sc, "FLR cleanup failed!\n");
18123 // XXX bxe_fw_dump(sc);
18124 // XXX bxe_idle_chk(sc);
18129 /* set MSI reconfigure capability */
18130 if (sc->devinfo.int_block == INT_BLOCK_HC) {
18131 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
18132 val = REG_RD(sc, addr);
18133 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
18134 REG_WR(sc, addr, val);
18137 ecore_init_block(sc, BLOCK_PXP, init_phase);
18138 ecore_init_block(sc, BLOCK_PXP2, init_phase);
18141 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
18143 for (i = 0; i < L2_ILT_LINES(sc); i++) {
18144 ilt->lines[cdu_ilt_start + i].page = sc->context[i].vcxt;
18145 ilt->lines[cdu_ilt_start + i].page_mapping =
18146 sc->context[i].vcxt_dma.paddr;
18147 ilt->lines[cdu_ilt_start + i].size = sc->context[i].size;
18149 ecore_ilt_init_op(sc, INITOP_SET);
18152 REG_WR(sc, PRS_REG_NIC_MODE, 1);
18153 BLOGD(sc, DBG_LOAD, "NIC MODE configured\n");
18155 if (!CHIP_IS_E1x(sc)) {
18156 uint32_t pf_conf = IGU_PF_CONF_FUNC_EN;
18158 /* Turn on a single ISR mode in IGU if driver is going to use
18161 if (sc->interrupt_mode != INTR_MODE_MSIX) {
18162 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
18166 * Timers workaround bug: function init part.
18167 * Need to wait 20msec after initializing ILT,
18168 * needed to make sure there are no requests in
18169 * one of the PXP internal queues with "old" ILT addresses
18174 * Master enable - Due to WB DMAE writes performed before this
18175 * register is re-initialized as part of the regular function
18178 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
18179 /* Enable the function in IGU */
18180 REG_WR(sc, IGU_REG_PF_CONFIGURATION, pf_conf);
18183 sc->dmae_ready = 1;
18185 ecore_init_block(sc, BLOCK_PGLUE_B, init_phase);
18187 if (!CHIP_IS_E1x(sc))
18188 REG_WR(sc, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
18190 ecore_init_block(sc, BLOCK_ATC, init_phase);
18191 ecore_init_block(sc, BLOCK_DMAE, init_phase);
18192 ecore_init_block(sc, BLOCK_NIG, init_phase);
18193 ecore_init_block(sc, BLOCK_SRC, init_phase);
18194 ecore_init_block(sc, BLOCK_MISC, init_phase);
18195 ecore_init_block(sc, BLOCK_TCM, init_phase);
18196 ecore_init_block(sc, BLOCK_UCM, init_phase);
18197 ecore_init_block(sc, BLOCK_CCM, init_phase);
18198 ecore_init_block(sc, BLOCK_XCM, init_phase);
18199 ecore_init_block(sc, BLOCK_TSEM, init_phase);
18200 ecore_init_block(sc, BLOCK_USEM, init_phase);
18201 ecore_init_block(sc, BLOCK_CSEM, init_phase);
18202 ecore_init_block(sc, BLOCK_XSEM, init_phase);
18204 if (!CHIP_IS_E1x(sc))
18205 REG_WR(sc, QM_REG_PF_EN, 1);
18207 if (!CHIP_IS_E1x(sc)) {
18208 REG_WR(sc, TSEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func);
18209 REG_WR(sc, USEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func);
18210 REG_WR(sc, CSEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func);
18211 REG_WR(sc, XSEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func);
18213 ecore_init_block(sc, BLOCK_QM, init_phase);
18215 ecore_init_block(sc, BLOCK_TM, init_phase);
18216 ecore_init_block(sc, BLOCK_DORQ, init_phase);
18218 bxe_iov_init_dq(sc);
18220 ecore_init_block(sc, BLOCK_BRB1, init_phase);
18221 ecore_init_block(sc, BLOCK_PRS, init_phase);
18222 ecore_init_block(sc, BLOCK_TSDM, init_phase);
18223 ecore_init_block(sc, BLOCK_CSDM, init_phase);
18224 ecore_init_block(sc, BLOCK_USDM, init_phase);
18225 ecore_init_block(sc, BLOCK_XSDM, init_phase);
18226 ecore_init_block(sc, BLOCK_UPB, init_phase);
18227 ecore_init_block(sc, BLOCK_XPB, init_phase);
18228 ecore_init_block(sc, BLOCK_PBF, init_phase);
18229 if (!CHIP_IS_E1x(sc))
18230 REG_WR(sc, PBF_REG_DISABLE_PF, 0);
18232 ecore_init_block(sc, BLOCK_CDU, init_phase);
18234 ecore_init_block(sc, BLOCK_CFC, init_phase);
18236 if (!CHIP_IS_E1x(sc))
18237 REG_WR(sc, CFC_REG_WEAK_ENABLE_PF, 1);
18240 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 1);
18241 REG_WR(sc, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, OVLAN(sc));
18244 ecore_init_block(sc, BLOCK_MISC_AEU, init_phase);
18246 /* HC init per function */
18247 if (sc->devinfo.int_block == INT_BLOCK_HC) {
18248 if (CHIP_IS_E1H(sc)) {
18249 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
18251 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, 0);
18252 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, 0);
18254 ecore_init_block(sc, BLOCK_HC, init_phase);
18257 int num_segs, sb_idx, prod_offset;
18259 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
18261 if (!CHIP_IS_E1x(sc)) {
18262 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, 0);
18263 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, 0);
18266 ecore_init_block(sc, BLOCK_IGU, init_phase);
18268 if (!CHIP_IS_E1x(sc)) {
18272 * E2 mode: address 0-135 match to the mapping memory;
18273 * 136 - PF0 default prod; 137 - PF1 default prod;
18274 * 138 - PF2 default prod; 139 - PF3 default prod;
18275 * 140 - PF0 attn prod; 141 - PF1 attn prod;
18276 * 142 - PF2 attn prod; 143 - PF3 attn prod;
18277 * 144-147 reserved.
18279 * E1.5 mode - In backward compatible mode;
18280 * for non default SB; each even line in the memory
18281 * holds the U producer and each odd line hold
18282 * the C producer. The first 128 producers are for
18283 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
18284 * producers are for the DSB for each PF.
18285 * Each PF has five segments: (the order inside each
18286 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
18287 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
18288 * 144-147 attn prods;
18290 /* non-default-status-blocks */
18291 num_segs = CHIP_INT_MODE_IS_BC(sc) ?
18292 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
18293 for (sb_idx = 0; sb_idx < sc->igu_sb_cnt; sb_idx++) {
18294 prod_offset = (sc->igu_base_sb + sb_idx) *
18297 for (i = 0; i < num_segs; i++) {
18298 addr = IGU_REG_PROD_CONS_MEMORY +
18299 (prod_offset + i) * 4;
18300 REG_WR(sc, addr, 0);
18302 /* send consumer update with value 0 */
18303 bxe_ack_sb(sc, sc->igu_base_sb + sb_idx,
18304 USTORM_ID, 0, IGU_INT_NOP, 1);
18305 bxe_igu_clear_sb(sc, sc->igu_base_sb + sb_idx);
18308 /* default-status-blocks */
18309 num_segs = CHIP_INT_MODE_IS_BC(sc) ?
18310 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
18312 if (CHIP_IS_MODE_4_PORT(sc))
18313 dsb_idx = SC_FUNC(sc);
18315 dsb_idx = SC_VN(sc);
18317 prod_offset = (CHIP_INT_MODE_IS_BC(sc) ?
18318 IGU_BC_BASE_DSB_PROD + dsb_idx :
18319 IGU_NORM_BASE_DSB_PROD + dsb_idx);
18322 * igu prods come in chunks of E1HVN_MAX (4) -
18323 * does not matters what is the current chip mode
18325 for (i = 0; i < (num_segs * E1HVN_MAX);
18327 addr = IGU_REG_PROD_CONS_MEMORY +
18328 (prod_offset + i)*4;
18329 REG_WR(sc, addr, 0);
18331 /* send consumer update with 0 */
18332 if (CHIP_INT_MODE_IS_BC(sc)) {
18333 bxe_ack_sb(sc, sc->igu_dsb_id,
18334 USTORM_ID, 0, IGU_INT_NOP, 1);
18335 bxe_ack_sb(sc, sc->igu_dsb_id,
18336 CSTORM_ID, 0, IGU_INT_NOP, 1);
18337 bxe_ack_sb(sc, sc->igu_dsb_id,
18338 XSTORM_ID, 0, IGU_INT_NOP, 1);
18339 bxe_ack_sb(sc, sc->igu_dsb_id,
18340 TSTORM_ID, 0, IGU_INT_NOP, 1);
18341 bxe_ack_sb(sc, sc->igu_dsb_id,
18342 ATTENTION_ID, 0, IGU_INT_NOP, 1);
18344 bxe_ack_sb(sc, sc->igu_dsb_id,
18345 USTORM_ID, 0, IGU_INT_NOP, 1);
18346 bxe_ack_sb(sc, sc->igu_dsb_id,
18347 ATTENTION_ID, 0, IGU_INT_NOP, 1);
18349 bxe_igu_clear_sb(sc, sc->igu_dsb_id);
18351 /* !!! these should become driver const once
18352 rf-tool supports split-68 const */
18353 REG_WR(sc, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
18354 REG_WR(sc, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
18355 REG_WR(sc, IGU_REG_SB_MASK_LSB, 0);
18356 REG_WR(sc, IGU_REG_SB_MASK_MSB, 0);
18357 REG_WR(sc, IGU_REG_PBA_STATUS_LSB, 0);
18358 REG_WR(sc, IGU_REG_PBA_STATUS_MSB, 0);
18362 /* Reset PCIE errors for debug */
18363 REG_WR(sc, 0x2114, 0xffffffff);
18364 REG_WR(sc, 0x2120, 0xffffffff);
18366 if (CHIP_IS_E1x(sc)) {
18367 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
18368 main_mem_base = HC_REG_MAIN_MEMORY +
18369 SC_PORT(sc) * (main_mem_size * 4);
18370 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
18371 main_mem_width = 8;
18373 val = REG_RD(sc, main_mem_prty_clr);
18375 BLOGD(sc, DBG_LOAD,
18376 "Parity errors in HC block during function init (0x%x)!\n",
18380 /* Clear "false" parity errors in MSI-X table */
18381 for (i = main_mem_base;
18382 i < main_mem_base + main_mem_size * 4;
18383 i += main_mem_width) {
18384 bxe_read_dmae(sc, i, main_mem_width / 4);
18385 bxe_write_dmae(sc, BXE_SP_MAPPING(sc, wb_data),
18386 i, main_mem_width / 4);
18388 /* Clear HC parity attention */
18389 REG_RD(sc, main_mem_prty_clr);
18393 /* Enable STORMs SP logging */
18394 REG_WR8(sc, BAR_USTRORM_INTMEM +
18395 USTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
18396 REG_WR8(sc, BAR_TSTRORM_INTMEM +
18397 TSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
18398 REG_WR8(sc, BAR_CSTRORM_INTMEM +
18399 CSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
18400 REG_WR8(sc, BAR_XSTRORM_INTMEM +
18401 XSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
18404 elink_phy_probe(&sc->link_params);
18410 bxe_link_reset(struct bxe_softc *sc)
18412 if (!BXE_NOMCP(sc)) {
18413 bxe_acquire_phy_lock(sc);
18414 elink_lfa_reset(&sc->link_params, &sc->link_vars);
18415 bxe_release_phy_lock(sc);
18417 if (!CHIP_REV_IS_SLOW(sc)) {
18418 BLOGW(sc, "Bootcode is missing - cannot reset link\n");
18424 bxe_reset_port(struct bxe_softc *sc)
18426 int port = SC_PORT(sc);
18429 ELINK_DEBUG_P0(sc, "bxe_reset_port called\n");
18430 /* reset physical Link */
18431 bxe_link_reset(sc);
18433 REG_WR(sc, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
18435 /* Do not rcv packets to BRB */
18436 REG_WR(sc, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
18437 /* Do not direct rcv packets that are not for MCP to the BRB */
18438 REG_WR(sc, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
18439 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
18441 /* Configure AEU */
18442 REG_WR(sc, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
18446 /* Check for BRB port occupancy */
18447 val = REG_RD(sc, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
18449 BLOGD(sc, DBG_LOAD,
18450 "BRB1 is not empty, %d blocks are occupied\n", val);
18453 /* TODO: Close Doorbell port? */
18457 bxe_ilt_wr(struct bxe_softc *sc,
18462 uint32_t wb_write[2];
18464 if (CHIP_IS_E1(sc)) {
18465 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
18467 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
18470 wb_write[0] = ONCHIP_ADDR1(addr);
18471 wb_write[1] = ONCHIP_ADDR2(addr);
18472 REG_WR_DMAE(sc, reg, wb_write, 2);
18476 bxe_clear_func_ilt(struct bxe_softc *sc,
18479 uint32_t i, base = FUNC_ILT_BASE(func);
18480 for (i = base; i < base + ILT_PER_FUNC; i++) {
18481 bxe_ilt_wr(sc, i, 0);
18486 bxe_reset_func(struct bxe_softc *sc)
18488 struct bxe_fastpath *fp;
18489 int port = SC_PORT(sc);
18490 int func = SC_FUNC(sc);
18493 /* Disable the function in the FW */
18494 REG_WR8(sc, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
18495 REG_WR8(sc, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
18496 REG_WR8(sc, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
18497 REG_WR8(sc, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
18500 FOR_EACH_ETH_QUEUE(sc, i) {
18502 REG_WR8(sc, BAR_CSTRORM_INTMEM +
18503 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
18508 REG_WR8(sc, BAR_CSTRORM_INTMEM +
18509 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
18512 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++) {
18513 REG_WR(sc, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func), 0);
18516 /* Configure IGU */
18517 if (sc->devinfo.int_block == INT_BLOCK_HC) {
18518 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, 0);
18519 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, 0);
18521 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, 0);
18522 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, 0);
18525 if (CNIC_LOADED(sc)) {
18526 /* Disable Timer scan */
18527 REG_WR(sc, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
18529 * Wait for at least 10ms and up to 2 second for the timers
18532 for (i = 0; i < 200; i++) {
18534 if (!REG_RD(sc, TM_REG_LIN0_SCAN_ON + port*4))
18540 bxe_clear_func_ilt(sc, func);
18543 * Timers workaround bug for E2: if this is vnic-3,
18544 * we need to set the entire ilt range for this timers.
18546 if (!CHIP_IS_E1x(sc) && SC_VN(sc) == 3) {
18547 struct ilt_client_info ilt_cli;
18548 /* use dummy TM client */
18549 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
18551 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
18552 ilt_cli.client_num = ILT_CLIENT_TM;
18554 ecore_ilt_boundry_init_op(sc, &ilt_cli, 0, INITOP_CLEAR);
18557 /* this assumes that reset_port() called before reset_func()*/
18558 if (!CHIP_IS_E1x(sc)) {
18559 bxe_pf_disable(sc);
18562 sc->dmae_ready = 0;
18566 bxe_gunzip_init(struct bxe_softc *sc)
18572 bxe_gunzip_end(struct bxe_softc *sc)
18578 bxe_init_firmware(struct bxe_softc *sc)
18580 if (CHIP_IS_E1(sc)) {
18581 ecore_init_e1_firmware(sc);
18582 sc->iro_array = e1_iro_arr;
18583 } else if (CHIP_IS_E1H(sc)) {
18584 ecore_init_e1h_firmware(sc);
18585 sc->iro_array = e1h_iro_arr;
18586 } else if (!CHIP_IS_E1x(sc)) {
18587 ecore_init_e2_firmware(sc);
18588 sc->iro_array = e2_iro_arr;
18590 BLOGE(sc, "Unsupported chip revision\n");
18598 bxe_release_firmware(struct bxe_softc *sc)
18605 ecore_gunzip(struct bxe_softc *sc,
18606 const uint8_t *zbuf,
18609 /* XXX : Implement... */
18610 BLOGD(sc, DBG_LOAD, "ECORE_GUNZIP NOT IMPLEMENTED\n");
18615 ecore_reg_wr_ind(struct bxe_softc *sc,
18619 bxe_reg_wr_ind(sc, addr, val);
18623 ecore_write_dmae_phys_len(struct bxe_softc *sc,
18624 bus_addr_t phys_addr,
18628 bxe_write_dmae_phys_len(sc, phys_addr, addr, len);
18632 ecore_storm_memset_struct(struct bxe_softc *sc,
18638 for (i = 0; i < size/4; i++) {
18639 REG_WR(sc, addr + (i * 4), data[i]);
18645 * character device - ioctl interface definitions
18649 #include "bxe_dump.h"
18650 #include "bxe_ioctl.h"
18651 #include <sys/conf.h>
18653 static int bxe_eioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
18654 struct thread *td);
18656 static struct cdevsw bxe_cdevsw = {
18657 .d_version = D_VERSION,
18658 .d_ioctl = bxe_eioctl,
18659 .d_name = "bxecnic",
18662 #define BXE_PATH(sc) (CHIP_IS_E1x(sc) ? 0 : (sc->pcie_func & 1))
18665 #define DUMP_ALL_PRESETS 0x1FFF
18666 #define DUMP_MAX_PRESETS 13
18667 #define IS_E1_REG(chips) ((chips & DUMP_CHIP_E1) == DUMP_CHIP_E1)
18668 #define IS_E1H_REG(chips) ((chips & DUMP_CHIP_E1H) == DUMP_CHIP_E1H)
18669 #define IS_E2_REG(chips) ((chips & DUMP_CHIP_E2) == DUMP_CHIP_E2)
18670 #define IS_E3A0_REG(chips) ((chips & DUMP_CHIP_E3A0) == DUMP_CHIP_E3A0)
18671 #define IS_E3B0_REG(chips) ((chips & DUMP_CHIP_E3B0) == DUMP_CHIP_E3B0)
18673 #define IS_REG_IN_PRESET(presets, idx) \
18674 ((presets & (1 << (idx-1))) == (1 << (idx-1)))
18678 bxe_get_preset_regs_len(struct bxe_softc *sc, uint32_t preset)
18680 if (CHIP_IS_E1(sc))
18681 return dump_num_registers[0][preset-1];
18682 else if (CHIP_IS_E1H(sc))
18683 return dump_num_registers[1][preset-1];
18684 else if (CHIP_IS_E2(sc))
18685 return dump_num_registers[2][preset-1];
18686 else if (CHIP_IS_E3A0(sc))
18687 return dump_num_registers[3][preset-1];
18688 else if (CHIP_IS_E3B0(sc))
18689 return dump_num_registers[4][preset-1];
18695 bxe_get_total_regs_len32(struct bxe_softc *sc)
18697 uint32_t preset_idx;
18698 int regdump_len32 = 0;
18701 /* Calculate the total preset regs length */
18702 for (preset_idx = 1; preset_idx <= DUMP_MAX_PRESETS; preset_idx++) {
18703 regdump_len32 += bxe_get_preset_regs_len(sc, preset_idx);
18706 return regdump_len32;
18709 static const uint32_t *
18710 __bxe_get_page_addr_ar(struct bxe_softc *sc)
18712 if (CHIP_IS_E2(sc))
18713 return page_vals_e2;
18714 else if (CHIP_IS_E3(sc))
18715 return page_vals_e3;
18721 __bxe_get_page_reg_num(struct bxe_softc *sc)
18723 if (CHIP_IS_E2(sc))
18724 return PAGE_MODE_VALUES_E2;
18725 else if (CHIP_IS_E3(sc))
18726 return PAGE_MODE_VALUES_E3;
18731 static const uint32_t *
18732 __bxe_get_page_write_ar(struct bxe_softc *sc)
18734 if (CHIP_IS_E2(sc))
18735 return page_write_regs_e2;
18736 else if (CHIP_IS_E3(sc))
18737 return page_write_regs_e3;
18743 __bxe_get_page_write_num(struct bxe_softc *sc)
18745 if (CHIP_IS_E2(sc))
18746 return PAGE_WRITE_REGS_E2;
18747 else if (CHIP_IS_E3(sc))
18748 return PAGE_WRITE_REGS_E3;
18753 static const struct reg_addr *
18754 __bxe_get_page_read_ar(struct bxe_softc *sc)
18756 if (CHIP_IS_E2(sc))
18757 return page_read_regs_e2;
18758 else if (CHIP_IS_E3(sc))
18759 return page_read_regs_e3;
18765 __bxe_get_page_read_num(struct bxe_softc *sc)
18767 if (CHIP_IS_E2(sc))
18768 return PAGE_READ_REGS_E2;
18769 else if (CHIP_IS_E3(sc))
18770 return PAGE_READ_REGS_E3;
18776 bxe_is_reg_in_chip(struct bxe_softc *sc, const struct reg_addr *reg_info)
18778 if (CHIP_IS_E1(sc))
18779 return IS_E1_REG(reg_info->chips);
18780 else if (CHIP_IS_E1H(sc))
18781 return IS_E1H_REG(reg_info->chips);
18782 else if (CHIP_IS_E2(sc))
18783 return IS_E2_REG(reg_info->chips);
18784 else if (CHIP_IS_E3A0(sc))
18785 return IS_E3A0_REG(reg_info->chips);
18786 else if (CHIP_IS_E3B0(sc))
18787 return IS_E3B0_REG(reg_info->chips);
18793 bxe_is_wreg_in_chip(struct bxe_softc *sc, const struct wreg_addr *wreg_info)
18795 if (CHIP_IS_E1(sc))
18796 return IS_E1_REG(wreg_info->chips);
18797 else if (CHIP_IS_E1H(sc))
18798 return IS_E1H_REG(wreg_info->chips);
18799 else if (CHIP_IS_E2(sc))
18800 return IS_E2_REG(wreg_info->chips);
18801 else if (CHIP_IS_E3A0(sc))
18802 return IS_E3A0_REG(wreg_info->chips);
18803 else if (CHIP_IS_E3B0(sc))
18804 return IS_E3B0_REG(wreg_info->chips);
18810 * bxe_read_pages_regs - read "paged" registers
18812 * @bp device handle
18815 * Reads "paged" memories: memories that may only be read by first writing to a
18816 * specific address ("write address") and then reading from a specific address
18817 * ("read address"). There may be more than one write address per "page" and
18818 * more than one read address per write address.
18821 bxe_read_pages_regs(struct bxe_softc *sc, uint32_t *p, uint32_t preset)
18823 uint32_t i, j, k, n;
18825 /* addresses of the paged registers */
18826 const uint32_t *page_addr = __bxe_get_page_addr_ar(sc);
18827 /* number of paged registers */
18828 int num_pages = __bxe_get_page_reg_num(sc);
18829 /* write addresses */
18830 const uint32_t *write_addr = __bxe_get_page_write_ar(sc);
18831 /* number of write addresses */
18832 int write_num = __bxe_get_page_write_num(sc);
18833 /* read addresses info */
18834 const struct reg_addr *read_addr = __bxe_get_page_read_ar(sc);
18835 /* number of read addresses */
18836 int read_num = __bxe_get_page_read_num(sc);
18837 uint32_t addr, size;
18839 for (i = 0; i < num_pages; i++) {
18840 for (j = 0; j < write_num; j++) {
18841 REG_WR(sc, write_addr[j], page_addr[i]);
18843 for (k = 0; k < read_num; k++) {
18844 if (IS_REG_IN_PRESET(read_addr[k].presets, preset)) {
18845 size = read_addr[k].size;
18846 for (n = 0; n < size; n++) {
18847 addr = read_addr[k].addr + n*4;
18848 *p++ = REG_RD(sc, addr);
18859 bxe_get_preset_regs(struct bxe_softc *sc, uint32_t *p, uint32_t preset)
18861 uint32_t i, j, addr;
18862 const struct wreg_addr *wreg_addr_p = NULL;
18864 if (CHIP_IS_E1(sc))
18865 wreg_addr_p = &wreg_addr_e1;
18866 else if (CHIP_IS_E1H(sc))
18867 wreg_addr_p = &wreg_addr_e1h;
18868 else if (CHIP_IS_E2(sc))
18869 wreg_addr_p = &wreg_addr_e2;
18870 else if (CHIP_IS_E3A0(sc))
18871 wreg_addr_p = &wreg_addr_e3;
18872 else if (CHIP_IS_E3B0(sc))
18873 wreg_addr_p = &wreg_addr_e3b0;
18877 /* Read the idle_chk registers */
18878 for (i = 0; i < IDLE_REGS_COUNT; i++) {
18879 if (bxe_is_reg_in_chip(sc, &idle_reg_addrs[i]) &&
18880 IS_REG_IN_PRESET(idle_reg_addrs[i].presets, preset)) {
18881 for (j = 0; j < idle_reg_addrs[i].size; j++)
18882 *p++ = REG_RD(sc, idle_reg_addrs[i].addr + j*4);
18886 /* Read the regular registers */
18887 for (i = 0; i < REGS_COUNT; i++) {
18888 if (bxe_is_reg_in_chip(sc, ®_addrs[i]) &&
18889 IS_REG_IN_PRESET(reg_addrs[i].presets, preset)) {
18890 for (j = 0; j < reg_addrs[i].size; j++)
18891 *p++ = REG_RD(sc, reg_addrs[i].addr + j*4);
18895 /* Read the CAM registers */
18896 if (bxe_is_wreg_in_chip(sc, wreg_addr_p) &&
18897 IS_REG_IN_PRESET(wreg_addr_p->presets, preset)) {
18898 for (i = 0; i < wreg_addr_p->size; i++) {
18899 *p++ = REG_RD(sc, wreg_addr_p->addr + i*4);
18901 /* In case of wreg_addr register, read additional
18902 registers from read_regs array
18904 for (j = 0; j < wreg_addr_p->read_regs_count; j++) {
18905 addr = *(wreg_addr_p->read_regs);
18906 *p++ = REG_RD(sc, addr + j*4);
18911 /* Paged registers are supported in E2 & E3 only */
18912 if (CHIP_IS_E2(sc) || CHIP_IS_E3(sc)) {
18913 /* Read "paged" registers */
18914 bxe_read_pages_regs(sc, p, preset);
18921 bxe_grc_dump(struct bxe_softc *sc)
18924 uint32_t preset_idx;
18927 struct dump_header *d_hdr;
18931 uint32_t cmd_offset;
18932 struct ecore_ilt *ilt = SC_ILT(sc);
18933 struct bxe_fastpath *fp;
18934 struct ilt_client_info *ilt_cli;
18938 if (sc->grcdump_done || sc->grcdump_started)
18941 sc->grcdump_started = 1;
18942 BLOGI(sc, "Started collecting grcdump\n");
18944 grc_dump_size = (bxe_get_total_regs_len32(sc) * sizeof(uint32_t)) +
18945 sizeof(struct dump_header);
18947 sc->grc_dump = malloc(grc_dump_size, M_DEVBUF, M_NOWAIT);
18949 if (sc->grc_dump == NULL) {
18950 BLOGW(sc, "Unable to allocate memory for grcdump collection\n");
18956 /* Disable parity attentions as long as following dump may
18957 * cause false alarms by reading never written registers. We
18958 * will re-enable parity attentions right after the dump.
18961 /* Disable parity on path 0 */
18962 bxe_pretend_func(sc, 0);
18964 ecore_disable_blocks_parity(sc);
18966 /* Disable parity on path 1 */
18967 bxe_pretend_func(sc, 1);
18968 ecore_disable_blocks_parity(sc);
18970 /* Return to current function */
18971 bxe_pretend_func(sc, SC_ABS_FUNC(sc));
18973 buf = sc->grc_dump;
18974 d_hdr = sc->grc_dump;
18976 d_hdr->header_size = (sizeof(struct dump_header) >> 2) - 1;
18977 d_hdr->version = BNX2X_DUMP_VERSION;
18978 d_hdr->preset = DUMP_ALL_PRESETS;
18980 if (CHIP_IS_E1(sc)) {
18981 d_hdr->dump_meta_data = DUMP_CHIP_E1;
18982 } else if (CHIP_IS_E1H(sc)) {
18983 d_hdr->dump_meta_data = DUMP_CHIP_E1H;
18984 } else if (CHIP_IS_E2(sc)) {
18985 d_hdr->dump_meta_data = DUMP_CHIP_E2 |
18986 (BXE_PATH(sc) ? DUMP_PATH_1 : DUMP_PATH_0);
18987 } else if (CHIP_IS_E3A0(sc)) {
18988 d_hdr->dump_meta_data = DUMP_CHIP_E3A0 |
18989 (BXE_PATH(sc) ? DUMP_PATH_1 : DUMP_PATH_0);
18990 } else if (CHIP_IS_E3B0(sc)) {
18991 d_hdr->dump_meta_data = DUMP_CHIP_E3B0 |
18992 (BXE_PATH(sc) ? DUMP_PATH_1 : DUMP_PATH_0);
18995 buf += sizeof(struct dump_header);
18997 for (preset_idx = 1; preset_idx <= DUMP_MAX_PRESETS; preset_idx++) {
18999 /* Skip presets with IOR */
19000 if ((preset_idx == 2) || (preset_idx == 5) || (preset_idx == 8) ||
19001 (preset_idx == 11))
19004 rval = bxe_get_preset_regs(sc, (uint32_t *)buf, preset_idx);
19009 size = bxe_get_preset_regs_len(sc, preset_idx) * (sizeof (uint32_t));
19014 bxe_pretend_func(sc, 0);
19015 ecore_clear_blocks_parity(sc);
19016 ecore_enable_blocks_parity(sc);
19018 bxe_pretend_func(sc, 1);
19019 ecore_clear_blocks_parity(sc);
19020 ecore_enable_blocks_parity(sc);
19022 /* Return to current function */
19023 bxe_pretend_func(sc, SC_ABS_FUNC(sc));
19027 if(sc->state == BXE_STATE_OPEN) {
19028 if(sc->fw_stats_req != NULL) {
19029 BLOGI(sc, "fw stats start_paddr %#jx end_paddr %#jx vaddr %p size 0x%x\n",
19030 (uintmax_t)sc->fw_stats_req_mapping,
19031 (uintmax_t)sc->fw_stats_data_mapping,
19032 sc->fw_stats_req, (sc->fw_stats_req_size + sc->fw_stats_data_size));
19034 if(sc->def_sb != NULL) {
19035 BLOGI(sc, "def_status_block paddr %p vaddr %p size 0x%zx\n",
19036 (void *)sc->def_sb_dma.paddr, sc->def_sb,
19037 sizeof(struct host_sp_status_block));
19039 if(sc->eq_dma.vaddr != NULL) {
19040 BLOGI(sc, "event_queue paddr %#jx vaddr %p size 0x%x\n",
19041 (uintmax_t)sc->eq_dma.paddr, sc->eq_dma.vaddr, BCM_PAGE_SIZE);
19043 if(sc->sp_dma.vaddr != NULL) {
19044 BLOGI(sc, "slow path paddr %#jx vaddr %p size 0x%zx\n",
19045 (uintmax_t)sc->sp_dma.paddr, sc->sp_dma.vaddr,
19046 sizeof(struct bxe_slowpath));
19048 if(sc->spq_dma.vaddr != NULL) {
19049 BLOGI(sc, "slow path queue paddr %#jx vaddr %p size 0x%x\n",
19050 (uintmax_t)sc->spq_dma.paddr, sc->spq_dma.vaddr, BCM_PAGE_SIZE);
19052 if(sc->gz_buf_dma.vaddr != NULL) {
19053 BLOGI(sc, "fw_buf paddr %#jx vaddr %p size 0x%x\n",
19054 (uintmax_t)sc->gz_buf_dma.paddr, sc->gz_buf_dma.vaddr,
19057 for (i = 0; i < sc->num_queues; i++) {
19059 if(fp->sb_dma.vaddr != NULL && fp->tx_dma.vaddr != NULL &&
19060 fp->rx_dma.vaddr != NULL && fp->rcq_dma.vaddr != NULL &&
19061 fp->rx_sge_dma.vaddr != NULL) {
19063 BLOGI(sc, "FP status block fp %d paddr %#jx vaddr %p size 0x%zx\n", i,
19064 (uintmax_t)fp->sb_dma.paddr, fp->sb_dma.vaddr,
19065 sizeof(union bxe_host_hc_status_block));
19066 BLOGI(sc, "TX BD CHAIN fp %d paddr %#jx vaddr %p size 0x%x\n", i,
19067 (uintmax_t)fp->tx_dma.paddr, fp->tx_dma.vaddr,
19068 (BCM_PAGE_SIZE * TX_BD_NUM_PAGES));
19069 BLOGI(sc, "RX BD CHAIN fp %d paddr %#jx vaddr %p size 0x%x\n", i,
19070 (uintmax_t)fp->rx_dma.paddr, fp->rx_dma.vaddr,
19071 (BCM_PAGE_SIZE * RX_BD_NUM_PAGES));
19072 BLOGI(sc, "RX RCQ CHAIN fp %d paddr %#jx vaddr %p size 0x%zx\n", i,
19073 (uintmax_t)fp->rcq_dma.paddr, fp->rcq_dma.vaddr,
19074 (BCM_PAGE_SIZE * RCQ_NUM_PAGES));
19075 BLOGI(sc, "RX SGE CHAIN fp %d paddr %#jx vaddr %p size 0x%x\n", i,
19076 (uintmax_t)fp->rx_sge_dma.paddr, fp->rx_sge_dma.vaddr,
19077 (BCM_PAGE_SIZE * RX_SGE_NUM_PAGES));
19081 ilt_cli = &ilt->clients[1];
19082 if(ilt->lines != NULL) {
19083 for (i = ilt_cli->start; i <= ilt_cli->end; i++) {
19084 BLOGI(sc, "ECORE_ILT paddr %#jx vaddr %p size 0x%x\n",
19085 (uintmax_t)(((struct bxe_dma *)((&ilt->lines[i])->page))->paddr),
19086 ((struct bxe_dma *)((&ilt->lines[i])->page))->vaddr, BCM_PAGE_SIZE);
19092 cmd_offset = DMAE_REG_CMD_MEM;
19093 for (i = 0; i < 224; i++) {
19094 reg_addr = (cmd_offset +(i * 4));
19095 reg_val = REG_RD(sc, reg_addr);
19096 BLOGI(sc, "DMAE_REG_CMD_MEM i=%d reg_addr 0x%x reg_val 0x%08x\n",i,
19097 reg_addr, reg_val);
19101 BLOGI(sc, "Collection of grcdump done\n");
19102 sc->grcdump_done = 1;
19107 bxe_add_cdev(struct bxe_softc *sc)
19109 sc->eeprom = malloc(BXE_EEPROM_MAX_DATA_LEN, M_DEVBUF, M_NOWAIT);
19111 if (sc->eeprom == NULL) {
19112 BLOGW(sc, "Unable to alloc for eeprom size buffer\n");
19116 sc->ioctl_dev = make_dev(&bxe_cdevsw,
19124 if (sc->ioctl_dev == NULL) {
19125 free(sc->eeprom, M_DEVBUF);
19130 sc->ioctl_dev->si_drv1 = sc;
19136 bxe_del_cdev(struct bxe_softc *sc)
19138 if (sc->ioctl_dev != NULL)
19139 destroy_dev(sc->ioctl_dev);
19141 if (sc->eeprom != NULL) {
19142 free(sc->eeprom, M_DEVBUF);
19145 sc->ioctl_dev = NULL;
19150 static bool bxe_is_nvram_accessible(struct bxe_softc *sc)
19153 if ((if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING) == 0)
19161 bxe_wr_eeprom(struct bxe_softc *sc, void *data, uint32_t offset, uint32_t len)
19165 if(!bxe_is_nvram_accessible(sc)) {
19166 BLOGW(sc, "Cannot access eeprom when interface is down\n");
19169 rval = bxe_nvram_write(sc, offset, (uint8_t *)data, len);
19176 bxe_rd_eeprom(struct bxe_softc *sc, void *data, uint32_t offset, uint32_t len)
19180 if(!bxe_is_nvram_accessible(sc)) {
19181 BLOGW(sc, "Cannot access eeprom when interface is down\n");
19184 rval = bxe_nvram_read(sc, offset, (uint8_t *)data, len);
19190 bxe_eeprom_rd_wr(struct bxe_softc *sc, bxe_eeprom_t *eeprom)
19194 switch (eeprom->eeprom_cmd) {
19196 case BXE_EEPROM_CMD_SET_EEPROM:
19198 rval = copyin(eeprom->eeprom_data, sc->eeprom,
19199 eeprom->eeprom_data_len);
19204 rval = bxe_wr_eeprom(sc, sc->eeprom, eeprom->eeprom_offset,
19205 eeprom->eeprom_data_len);
19208 case BXE_EEPROM_CMD_GET_EEPROM:
19210 rval = bxe_rd_eeprom(sc, sc->eeprom, eeprom->eeprom_offset,
19211 eeprom->eeprom_data_len);
19217 rval = copyout(sc->eeprom, eeprom->eeprom_data,
19218 eeprom->eeprom_data_len);
19227 BLOGW(sc, "ioctl cmd %d failed rval %d\n", eeprom->eeprom_cmd, rval);
19234 bxe_get_settings(struct bxe_softc *sc, bxe_dev_setting_t *dev_p)
19236 uint32_t ext_phy_config;
19237 int port = SC_PORT(sc);
19238 int cfg_idx = bxe_get_link_cfg_idx(sc);
19240 dev_p->supported = sc->port.supported[cfg_idx] |
19241 (sc->port.supported[cfg_idx ^ 1] &
19242 (ELINK_SUPPORTED_TP | ELINK_SUPPORTED_FIBRE));
19243 dev_p->advertising = sc->port.advertising[cfg_idx];
19244 if(sc->link_params.phy[bxe_get_cur_phy_idx(sc)].media_type ==
19245 ELINK_ETH_PHY_SFP_1G_FIBER) {
19246 dev_p->supported = ~(ELINK_SUPPORTED_10000baseT_Full);
19247 dev_p->advertising &= ~(ADVERTISED_10000baseT_Full);
19249 if ((sc->state == BXE_STATE_OPEN) && sc->link_vars.link_up &&
19250 !(sc->flags & BXE_MF_FUNC_DIS)) {
19251 dev_p->duplex = sc->link_vars.duplex;
19252 if (IS_MF(sc) && !BXE_NOMCP(sc))
19253 dev_p->speed = bxe_get_mf_speed(sc);
19255 dev_p->speed = sc->link_vars.line_speed;
19257 dev_p->duplex = DUPLEX_UNKNOWN;
19258 dev_p->speed = SPEED_UNKNOWN;
19261 dev_p->port = bxe_media_detect(sc);
19263 ext_phy_config = SHMEM_RD(sc,
19264 dev_info.port_hw_config[port].external_phy_config);
19265 if((ext_phy_config & PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK) ==
19266 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
19267 dev_p->phy_address = sc->port.phy_addr;
19268 else if(((ext_phy_config & PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK) !=
19269 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
19270 ((ext_phy_config & PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK) !=
19271 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
19272 dev_p->phy_address = ELINK_XGXS_EXT_PHY_ADDR(ext_phy_config);
19274 dev_p->phy_address = 0;
19276 if(sc->link_params.req_line_speed[cfg_idx] == ELINK_SPEED_AUTO_NEG)
19277 dev_p->autoneg = AUTONEG_ENABLE;
19279 dev_p->autoneg = AUTONEG_DISABLE;
19286 bxe_eioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
19289 struct bxe_softc *sc;
19292 bxe_grcdump_t *dump = NULL;
19294 bxe_drvinfo_t *drv_infop = NULL;
19295 bxe_dev_setting_t *dev_p;
19296 bxe_dev_setting_t dev_set;
19297 bxe_get_regs_t *reg_p;
19298 bxe_reg_rdw_t *reg_rdw_p;
19299 bxe_pcicfg_rdw_t *cfg_rdw_p;
19300 bxe_perm_mac_addr_t *mac_addr_p;
19303 if ((sc = (struct bxe_softc *)dev->si_drv1) == NULL)
19308 dump = (bxe_grcdump_t *)data;
19312 case BXE_GRC_DUMP_SIZE:
19313 dump->pci_func = sc->pcie_func;
19314 dump->grcdump_size =
19315 (bxe_get_total_regs_len32(sc) * sizeof(uint32_t)) +
19316 sizeof(struct dump_header);
19321 grc_dump_size = (bxe_get_total_regs_len32(sc) * sizeof(uint32_t)) +
19322 sizeof(struct dump_header);
19323 if ((!sc->trigger_grcdump) || (dump->grcdump == NULL) ||
19324 (dump->grcdump_size < grc_dump_size)) {
19329 if((sc->trigger_grcdump) && (!sc->grcdump_done) &&
19330 (!sc->grcdump_started)) {
19331 rval = bxe_grc_dump(sc);
19334 if((!rval) && (sc->grcdump_done) && (sc->grcdump_started) &&
19335 (sc->grc_dump != NULL)) {
19336 dump->grcdump_dwords = grc_dump_size >> 2;
19337 rval = copyout(sc->grc_dump, dump->grcdump, grc_dump_size);
19338 free(sc->grc_dump, M_DEVBUF);
19339 sc->grc_dump = NULL;
19340 sc->grcdump_started = 0;
19341 sc->grcdump_done = 0;
19347 drv_infop = (bxe_drvinfo_t *)data;
19348 snprintf(drv_infop->drv_name, BXE_DRV_NAME_LENGTH, "%s", "bxe");
19349 snprintf(drv_infop->drv_version, BXE_DRV_VERSION_LENGTH, "v:%s",
19350 BXE_DRIVER_VERSION);
19351 snprintf(drv_infop->mfw_version, BXE_MFW_VERSION_LENGTH, "%s",
19352 sc->devinfo.bc_ver_str);
19353 snprintf(drv_infop->stormfw_version, BXE_STORMFW_VERSION_LENGTH,
19354 "%s", sc->fw_ver_str);
19355 drv_infop->eeprom_dump_len = sc->devinfo.flash_size;
19356 drv_infop->reg_dump_len =
19357 (bxe_get_total_regs_len32(sc) * sizeof(uint32_t))
19358 + sizeof(struct dump_header);
19359 snprintf(drv_infop->bus_info, BXE_BUS_INFO_LENGTH, "%d:%d:%d",
19360 sc->pcie_bus, sc->pcie_device, sc->pcie_func);
19363 case BXE_DEV_SETTING:
19364 dev_p = (bxe_dev_setting_t *)data;
19365 bxe_get_settings(sc, &dev_set);
19366 dev_p->supported = dev_set.supported;
19367 dev_p->advertising = dev_set.advertising;
19368 dev_p->speed = dev_set.speed;
19369 dev_p->duplex = dev_set.duplex;
19370 dev_p->port = dev_set.port;
19371 dev_p->phy_address = dev_set.phy_address;
19372 dev_p->autoneg = dev_set.autoneg;
19378 reg_p = (bxe_get_regs_t *)data;
19379 grc_dump_size = reg_p->reg_buf_len;
19381 if((!sc->grcdump_done) && (!sc->grcdump_started)) {
19384 if((sc->grcdump_done) && (sc->grcdump_started) &&
19385 (sc->grc_dump != NULL)) {
19386 rval = copyout(sc->grc_dump, reg_p->reg_buf, grc_dump_size);
19387 free(sc->grc_dump, M_DEVBUF);
19388 sc->grc_dump = NULL;
19389 sc->grcdump_started = 0;
19390 sc->grcdump_done = 0;
19396 reg_rdw_p = (bxe_reg_rdw_t *)data;
19397 if((reg_rdw_p->reg_cmd == BXE_READ_REG_CMD) &&
19398 (reg_rdw_p->reg_access_type == BXE_REG_ACCESS_DIRECT))
19399 reg_rdw_p->reg_val = REG_RD(sc, reg_rdw_p->reg_id);
19401 if((reg_rdw_p->reg_cmd == BXE_WRITE_REG_CMD) &&
19402 (reg_rdw_p->reg_access_type == BXE_REG_ACCESS_DIRECT))
19403 REG_WR(sc, reg_rdw_p->reg_id, reg_rdw_p->reg_val);
19407 case BXE_RDW_PCICFG:
19408 cfg_rdw_p = (bxe_pcicfg_rdw_t *)data;
19409 if(cfg_rdw_p->cfg_cmd == BXE_READ_PCICFG) {
19411 cfg_rdw_p->cfg_val = pci_read_config(sc->dev, cfg_rdw_p->cfg_id,
19412 cfg_rdw_p->cfg_width);
19414 } else if(cfg_rdw_p->cfg_cmd == BXE_WRITE_PCICFG) {
19415 pci_write_config(sc->dev, cfg_rdw_p->cfg_id, cfg_rdw_p->cfg_val,
19416 cfg_rdw_p->cfg_width);
19418 BLOGW(sc, "BXE_RDW_PCICFG ioctl wrong cmd passed\n");
19423 mac_addr_p = (bxe_perm_mac_addr_t *)data;
19424 snprintf(mac_addr_p->mac_addr_str, sizeof(sc->mac_addr_str), "%s",
19429 rval = bxe_eeprom_rd_wr(sc, (bxe_eeprom_t *)data);
19442 bxe_debugnet_init(struct ifnet *ifp, int *nrxr, int *ncl, int *clsize)
19444 struct bxe_softc *sc;
19446 sc = if_getsoftc(ifp);
19448 *nrxr = sc->num_queues;
19449 *ncl = DEBUGNET_MAX_IN_FLIGHT;
19450 *clsize = sc->fp[0].mbuf_alloc_size;
19451 BXE_CORE_UNLOCK(sc);
19455 bxe_debugnet_event(struct ifnet *ifp __unused, enum debugnet_ev event __unused)
19460 bxe_debugnet_transmit(struct ifnet *ifp, struct mbuf *m)
19462 struct bxe_softc *sc;
19465 sc = if_getsoftc(ifp);
19466 if ((if_getdrvflags(ifp) & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) !=
19467 IFF_DRV_RUNNING || !sc->link_vars.link_up)
19470 error = bxe_tx_encap(&sc->fp[0], &m);
19471 if (error != 0 && m != NULL)
19477 bxe_debugnet_poll(struct ifnet *ifp, int count)
19479 struct bxe_softc *sc;
19482 sc = if_getsoftc(ifp);
19483 if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0 ||
19484 !sc->link_vars.link_up)
19487 for (i = 0; i < sc->num_queues; i++)
19488 (void)bxe_rxeof(sc, &sc->fp[i]);
19489 (void)bxe_txeof(sc, &sc->fp[0]);
19492 #endif /* DEBUGNET */