1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2007-2014 QLogic Corporation. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 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. 15 * 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. 27 */ 28 29 #include <sys/cdefs.h> 30 #define BXE_DRIVER_VERSION "1.78.91" 31 32 #include "bxe.h" 33 #include "ecore_sp.h" 34 #include "ecore_init.h" 35 #include "ecore_init_ops.h" 36 37 #include "57710_int_offsets.h" 38 #include "57711_int_offsets.h" 39 #include "57712_int_offsets.h" 40 41 /* 42 * CTLTYPE_U64 and sysctl_handle_64 were added in r217616. Define these 43 * explicitly here for older kernels that don't include this changeset. 44 */ 45 #ifndef CTLTYPE_U64 46 #define CTLTYPE_U64 CTLTYPE_QUAD 47 #define sysctl_handle_64 sysctl_handle_quad 48 #endif 49 50 /* 51 * CSUM_TCP_IPV6 and CSUM_UDP_IPV6 were added in r236170. Define these 52 * here as zero(0) for older kernels that don't include this changeset 53 * thereby masking the functionality. 54 */ 55 #ifndef CSUM_TCP_IPV6 56 #define CSUM_TCP_IPV6 0 57 #define CSUM_UDP_IPV6 0 58 #endif 59 60 #define BXE_DEF_SB_ATT_IDX 0x0001 61 #define BXE_DEF_SB_IDX 0x0002 62 63 /* 64 * FLR Support - bxe_pf_flr_clnup() is called during nic_load in the per 65 * function HW initialization. 66 */ 67 #define FLR_WAIT_USEC 10000 /* 10 msecs */ 68 #define FLR_WAIT_INTERVAL 50 /* usecs */ 69 #define FLR_POLL_CNT (FLR_WAIT_USEC / FLR_WAIT_INTERVAL) /* 200 */ 70 71 struct pbf_pN_buf_regs { 72 int pN; 73 uint32_t init_crd; 74 uint32_t crd; 75 uint32_t crd_freed; 76 }; 77 78 struct pbf_pN_cmd_regs { 79 int pN; 80 uint32_t lines_occup; 81 uint32_t lines_freed; 82 }; 83 84 /* 85 * PCI Device ID Table used by bxe_probe(). 86 */ 87 #define BXE_DEVDESC_MAX 64 88 static struct bxe_device_type bxe_devs[] = { 89 { 90 BRCM_VENDORID, 91 CHIP_NUM_57710, 92 PCI_ANY_ID, PCI_ANY_ID, 93 "QLogic NetXtreme II BCM57710 10GbE" 94 }, 95 { 96 BRCM_VENDORID, 97 CHIP_NUM_57711, 98 PCI_ANY_ID, PCI_ANY_ID, 99 "QLogic NetXtreme II BCM57711 10GbE" 100 }, 101 { 102 BRCM_VENDORID, 103 CHIP_NUM_57711E, 104 PCI_ANY_ID, PCI_ANY_ID, 105 "QLogic NetXtreme II BCM57711E 10GbE" 106 }, 107 { 108 BRCM_VENDORID, 109 CHIP_NUM_57712, 110 PCI_ANY_ID, PCI_ANY_ID, 111 "QLogic NetXtreme II BCM57712 10GbE" 112 }, 113 { 114 BRCM_VENDORID, 115 CHIP_NUM_57712_MF, 116 PCI_ANY_ID, PCI_ANY_ID, 117 "QLogic NetXtreme II BCM57712 MF 10GbE" 118 }, 119 { 120 BRCM_VENDORID, 121 CHIP_NUM_57800, 122 PCI_ANY_ID, PCI_ANY_ID, 123 "QLogic NetXtreme II BCM57800 10GbE" 124 }, 125 { 126 BRCM_VENDORID, 127 CHIP_NUM_57800_MF, 128 PCI_ANY_ID, PCI_ANY_ID, 129 "QLogic NetXtreme II BCM57800 MF 10GbE" 130 }, 131 { 132 BRCM_VENDORID, 133 CHIP_NUM_57810, 134 PCI_ANY_ID, PCI_ANY_ID, 135 "QLogic NetXtreme II BCM57810 10GbE" 136 }, 137 { 138 BRCM_VENDORID, 139 CHIP_NUM_57810_MF, 140 PCI_ANY_ID, PCI_ANY_ID, 141 "QLogic NetXtreme II BCM57810 MF 10GbE" 142 }, 143 { 144 BRCM_VENDORID, 145 CHIP_NUM_57811, 146 PCI_ANY_ID, PCI_ANY_ID, 147 "QLogic NetXtreme II BCM57811 10GbE" 148 }, 149 { 150 BRCM_VENDORID, 151 CHIP_NUM_57811_MF, 152 PCI_ANY_ID, PCI_ANY_ID, 153 "QLogic NetXtreme II BCM57811 MF 10GbE" 154 }, 155 { 156 BRCM_VENDORID, 157 CHIP_NUM_57840_4_10, 158 PCI_ANY_ID, PCI_ANY_ID, 159 "QLogic NetXtreme II BCM57840 4x10GbE" 160 }, 161 { 162 QLOGIC_VENDORID, 163 CHIP_NUM_57840_4_10, 164 PCI_ANY_ID, PCI_ANY_ID, 165 "QLogic NetXtreme II BCM57840 4x10GbE" 166 }, 167 { 168 BRCM_VENDORID, 169 CHIP_NUM_57840_2_20, 170 PCI_ANY_ID, PCI_ANY_ID, 171 "QLogic NetXtreme II BCM57840 2x20GbE" 172 }, 173 { 174 BRCM_VENDORID, 175 CHIP_NUM_57840_MF, 176 PCI_ANY_ID, PCI_ANY_ID, 177 "QLogic NetXtreme II BCM57840 MF 10GbE" 178 }, 179 { 180 0, 0, 0, 0, NULL 181 } 182 }; 183 184 MALLOC_DECLARE(M_BXE_ILT); 185 MALLOC_DEFINE(M_BXE_ILT, "bxe_ilt", "bxe ILT pointer"); 186 187 /* 188 * FreeBSD device entry points. 189 */ 190 static int bxe_probe(device_t); 191 static int bxe_attach(device_t); 192 static int bxe_detach(device_t); 193 static int bxe_shutdown(device_t); 194 195 196 /* 197 * FreeBSD KLD module/device interface event handler method. 198 */ 199 static device_method_t bxe_methods[] = { 200 /* Device interface (device_if.h) */ 201 DEVMETHOD(device_probe, bxe_probe), 202 DEVMETHOD(device_attach, bxe_attach), 203 DEVMETHOD(device_detach, bxe_detach), 204 DEVMETHOD(device_shutdown, bxe_shutdown), 205 /* Bus interface (bus_if.h) */ 206 DEVMETHOD(bus_print_child, bus_generic_print_child), 207 DEVMETHOD(bus_driver_added, bus_generic_driver_added), 208 KOBJMETHOD_END 209 }; 210 211 /* 212 * FreeBSD KLD Module data declaration 213 */ 214 static driver_t bxe_driver = { 215 "bxe", /* module name */ 216 bxe_methods, /* event handler */ 217 sizeof(struct bxe_softc) /* extra data */ 218 }; 219 220 MODULE_DEPEND(bxe, pci, 1, 1, 1); 221 MODULE_DEPEND(bxe, ether, 1, 1, 1); 222 DRIVER_MODULE(bxe, pci, bxe_driver, 0, 0); 223 224 DEBUGNET_DEFINE(bxe); 225 226 /* resources needed for unloading a previously loaded device */ 227 228 #define BXE_PREV_WAIT_NEEDED 1 229 struct mtx bxe_prev_mtx; 230 MTX_SYSINIT(bxe_prev_mtx, &bxe_prev_mtx, "bxe_prev_lock", MTX_DEF); 231 struct bxe_prev_list_node { 232 LIST_ENTRY(bxe_prev_list_node) node; 233 uint8_t bus; 234 uint8_t slot; 235 uint8_t path; 236 uint8_t aer; /* XXX automatic error recovery */ 237 uint8_t undi; 238 }; 239 static LIST_HEAD(, bxe_prev_list_node) bxe_prev_list = LIST_HEAD_INITIALIZER(bxe_prev_list); 240 241 static int load_count[2][3] = { {0} }; /* per-path: 0-common, 1-port0, 2-port1 */ 242 243 /* Tunable device values... */ 244 245 SYSCTL_NODE(_hw, OID_AUTO, bxe, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 246 "bxe driver parameters"); 247 248 /* Debug */ 249 unsigned long bxe_debug = 0; 250 SYSCTL_ULONG(_hw_bxe, OID_AUTO, debug, CTLFLAG_RDTUN, 251 &bxe_debug, 0, "Debug logging mode"); 252 253 /* Interrupt Mode: 0 (IRQ), 1 (MSI/IRQ), and 2 (MSI-X/MSI/IRQ) */ 254 static int bxe_interrupt_mode = INTR_MODE_MSIX; 255 SYSCTL_INT(_hw_bxe, OID_AUTO, interrupt_mode, CTLFLAG_RDTUN, 256 &bxe_interrupt_mode, 0, "Interrupt (MSI-X/MSI/INTx) mode"); 257 258 /* Number of Queues: 0 (Auto) or 1 to 16 (fixed queue number) */ 259 static int bxe_queue_count = 4; 260 SYSCTL_INT(_hw_bxe, OID_AUTO, queue_count, CTLFLAG_RDTUN, 261 &bxe_queue_count, 0, "Multi-Queue queue count"); 262 263 /* max number of buffers per queue (default RX_BD_USABLE) */ 264 static int bxe_max_rx_bufs = 0; 265 SYSCTL_INT(_hw_bxe, OID_AUTO, max_rx_bufs, CTLFLAG_RDTUN, 266 &bxe_max_rx_bufs, 0, "Maximum Number of Rx Buffers Per Queue"); 267 268 /* Host interrupt coalescing RX tick timer (usecs) */ 269 static int bxe_hc_rx_ticks = 25; 270 SYSCTL_INT(_hw_bxe, OID_AUTO, hc_rx_ticks, CTLFLAG_RDTUN, 271 &bxe_hc_rx_ticks, 0, "Host Coalescing Rx ticks"); 272 273 /* Host interrupt coalescing TX tick timer (usecs) */ 274 static int bxe_hc_tx_ticks = 50; 275 SYSCTL_INT(_hw_bxe, OID_AUTO, hc_tx_ticks, CTLFLAG_RDTUN, 276 &bxe_hc_tx_ticks, 0, "Host Coalescing Tx ticks"); 277 278 /* Maximum number of Rx packets to process at a time */ 279 static int bxe_rx_budget = 0xffffffff; 280 SYSCTL_INT(_hw_bxe, OID_AUTO, rx_budget, CTLFLAG_RDTUN, 281 &bxe_rx_budget, 0, "Rx processing budget"); 282 283 /* Maximum LRO aggregation size */ 284 static int bxe_max_aggregation_size = 0; 285 SYSCTL_INT(_hw_bxe, OID_AUTO, max_aggregation_size, CTLFLAG_RDTUN, 286 &bxe_max_aggregation_size, 0, "max aggregation size"); 287 288 /* PCI MRRS: -1 (Auto), 0 (128B), 1 (256B), 2 (512B), 3 (1KB) */ 289 static int bxe_mrrs = -1; 290 SYSCTL_INT(_hw_bxe, OID_AUTO, mrrs, CTLFLAG_RDTUN, 291 &bxe_mrrs, 0, "PCIe maximum read request size"); 292 293 /* AutoGrEEEn: 0 (hardware default), 1 (force on), 2 (force off) */ 294 static int bxe_autogreeen = 0; 295 SYSCTL_INT(_hw_bxe, OID_AUTO, autogreeen, CTLFLAG_RDTUN, 296 &bxe_autogreeen, 0, "AutoGrEEEn support"); 297 298 /* 4-tuple RSS support for UDP: 0 (disabled), 1 (enabled) */ 299 static int bxe_udp_rss = 0; 300 SYSCTL_INT(_hw_bxe, OID_AUTO, udp_rss, CTLFLAG_RDTUN, 301 &bxe_udp_rss, 0, "UDP RSS support"); 302 303 304 #define STAT_NAME_LEN 32 /* no stat names below can be longer than this */ 305 306 #define STATS_OFFSET32(stat_name) \ 307 (offsetof(struct bxe_eth_stats, stat_name) / 4) 308 309 #define Q_STATS_OFFSET32(stat_name) \ 310 (offsetof(struct bxe_eth_q_stats, stat_name) / 4) 311 312 static const struct { 313 uint32_t offset; 314 uint32_t size; 315 uint32_t flags; 316 #define STATS_FLAGS_PORT 1 317 #define STATS_FLAGS_FUNC 2 /* MF only cares about function stats */ 318 #define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT) 319 char string[STAT_NAME_LEN]; 320 } bxe_eth_stats_arr[] = { 321 { STATS_OFFSET32(total_bytes_received_hi), 322 8, STATS_FLAGS_BOTH, "rx_bytes" }, 323 { STATS_OFFSET32(error_bytes_received_hi), 324 8, STATS_FLAGS_BOTH, "rx_error_bytes" }, 325 { STATS_OFFSET32(total_unicast_packets_received_hi), 326 8, STATS_FLAGS_BOTH, "rx_ucast_packets" }, 327 { STATS_OFFSET32(total_multicast_packets_received_hi), 328 8, STATS_FLAGS_BOTH, "rx_mcast_packets" }, 329 { STATS_OFFSET32(total_broadcast_packets_received_hi), 330 8, STATS_FLAGS_BOTH, "rx_bcast_packets" }, 331 { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi), 332 8, STATS_FLAGS_PORT, "rx_crc_errors" }, 333 { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi), 334 8, STATS_FLAGS_PORT, "rx_align_errors" }, 335 { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi), 336 8, STATS_FLAGS_PORT, "rx_undersize_packets" }, 337 { STATS_OFFSET32(etherstatsoverrsizepkts_hi), 338 8, STATS_FLAGS_PORT, "rx_oversize_packets" }, 339 { STATS_OFFSET32(rx_stat_etherstatsfragments_hi), 340 8, STATS_FLAGS_PORT, "rx_fragments" }, 341 { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi), 342 8, STATS_FLAGS_PORT, "rx_jabbers" }, 343 { STATS_OFFSET32(no_buff_discard_hi), 344 8, STATS_FLAGS_BOTH, "rx_discards" }, 345 { STATS_OFFSET32(mac_filter_discard), 346 4, STATS_FLAGS_PORT, "rx_filtered_packets" }, 347 { STATS_OFFSET32(mf_tag_discard), 348 4, STATS_FLAGS_PORT, "rx_mf_tag_discard" }, 349 { STATS_OFFSET32(pfc_frames_received_hi), 350 8, STATS_FLAGS_PORT, "pfc_frames_received" }, 351 { STATS_OFFSET32(pfc_frames_sent_hi), 352 8, STATS_FLAGS_PORT, "pfc_frames_sent" }, 353 { STATS_OFFSET32(brb_drop_hi), 354 8, STATS_FLAGS_PORT, "rx_brb_discard" }, 355 { STATS_OFFSET32(brb_truncate_hi), 356 8, STATS_FLAGS_PORT, "rx_brb_truncate" }, 357 { STATS_OFFSET32(pause_frames_received_hi), 358 8, STATS_FLAGS_PORT, "rx_pause_frames" }, 359 { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi), 360 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" }, 361 { STATS_OFFSET32(nig_timer_max), 362 4, STATS_FLAGS_PORT, "rx_constant_pause_events" }, 363 { STATS_OFFSET32(total_bytes_transmitted_hi), 364 8, STATS_FLAGS_BOTH, "tx_bytes" }, 365 { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi), 366 8, STATS_FLAGS_PORT, "tx_error_bytes" }, 367 { STATS_OFFSET32(total_unicast_packets_transmitted_hi), 368 8, STATS_FLAGS_BOTH, "tx_ucast_packets" }, 369 { STATS_OFFSET32(total_multicast_packets_transmitted_hi), 370 8, STATS_FLAGS_BOTH, "tx_mcast_packets" }, 371 { STATS_OFFSET32(total_broadcast_packets_transmitted_hi), 372 8, STATS_FLAGS_BOTH, "tx_bcast_packets" }, 373 { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi), 374 8, STATS_FLAGS_PORT, "tx_mac_errors" }, 375 { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi), 376 8, STATS_FLAGS_PORT, "tx_carrier_errors" }, 377 { STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi), 378 8, STATS_FLAGS_PORT, "tx_single_collisions" }, 379 { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi), 380 8, STATS_FLAGS_PORT, "tx_multi_collisions" }, 381 { STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi), 382 8, STATS_FLAGS_PORT, "tx_deferred" }, 383 { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi), 384 8, STATS_FLAGS_PORT, "tx_excess_collisions" }, 385 { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi), 386 8, STATS_FLAGS_PORT, "tx_late_collisions" }, 387 { STATS_OFFSET32(tx_stat_etherstatscollisions_hi), 388 8, STATS_FLAGS_PORT, "tx_total_collisions" }, 389 { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi), 390 8, STATS_FLAGS_PORT, "tx_64_byte_packets" }, 391 { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi), 392 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" }, 393 { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi), 394 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" }, 395 { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi), 396 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" }, 397 { STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi), 398 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" }, 399 { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi), 400 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" }, 401 { STATS_OFFSET32(etherstatspktsover1522octets_hi), 402 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" }, 403 { STATS_OFFSET32(pause_frames_sent_hi), 404 8, STATS_FLAGS_PORT, "tx_pause_frames" }, 405 { STATS_OFFSET32(total_tpa_aggregations_hi), 406 8, STATS_FLAGS_FUNC, "tpa_aggregations" }, 407 { STATS_OFFSET32(total_tpa_aggregated_frames_hi), 408 8, STATS_FLAGS_FUNC, "tpa_aggregated_frames"}, 409 { STATS_OFFSET32(total_tpa_bytes_hi), 410 8, STATS_FLAGS_FUNC, "tpa_bytes"}, 411 { STATS_OFFSET32(eee_tx_lpi), 412 4, STATS_FLAGS_PORT, "eee_tx_lpi"}, 413 { STATS_OFFSET32(rx_calls), 414 4, STATS_FLAGS_FUNC, "rx_calls"}, 415 { STATS_OFFSET32(rx_pkts), 416 4, STATS_FLAGS_FUNC, "rx_pkts"}, 417 { STATS_OFFSET32(rx_tpa_pkts), 418 4, STATS_FLAGS_FUNC, "rx_tpa_pkts"}, 419 { STATS_OFFSET32(rx_erroneous_jumbo_sge_pkts), 420 4, STATS_FLAGS_FUNC, "rx_erroneous_jumbo_sge_pkts"}, 421 { STATS_OFFSET32(rx_bxe_service_rxsgl), 422 4, STATS_FLAGS_FUNC, "rx_bxe_service_rxsgl"}, 423 { STATS_OFFSET32(rx_jumbo_sge_pkts), 424 4, STATS_FLAGS_FUNC, "rx_jumbo_sge_pkts"}, 425 { STATS_OFFSET32(rx_soft_errors), 426 4, STATS_FLAGS_FUNC, "rx_soft_errors"}, 427 { STATS_OFFSET32(rx_hw_csum_errors), 428 4, STATS_FLAGS_FUNC, "rx_hw_csum_errors"}, 429 { STATS_OFFSET32(rx_ofld_frames_csum_ip), 430 4, STATS_FLAGS_FUNC, "rx_ofld_frames_csum_ip"}, 431 { STATS_OFFSET32(rx_ofld_frames_csum_tcp_udp), 432 4, STATS_FLAGS_FUNC, "rx_ofld_frames_csum_tcp_udp"}, 433 { STATS_OFFSET32(rx_budget_reached), 434 4, STATS_FLAGS_FUNC, "rx_budget_reached"}, 435 { STATS_OFFSET32(tx_pkts), 436 4, STATS_FLAGS_FUNC, "tx_pkts"}, 437 { STATS_OFFSET32(tx_soft_errors), 438 4, STATS_FLAGS_FUNC, "tx_soft_errors"}, 439 { STATS_OFFSET32(tx_ofld_frames_csum_ip), 440 4, STATS_FLAGS_FUNC, "tx_ofld_frames_csum_ip"}, 441 { STATS_OFFSET32(tx_ofld_frames_csum_tcp), 442 4, STATS_FLAGS_FUNC, "tx_ofld_frames_csum_tcp"}, 443 { STATS_OFFSET32(tx_ofld_frames_csum_udp), 444 4, STATS_FLAGS_FUNC, "tx_ofld_frames_csum_udp"}, 445 { STATS_OFFSET32(tx_ofld_frames_lso), 446 4, STATS_FLAGS_FUNC, "tx_ofld_frames_lso"}, 447 { STATS_OFFSET32(tx_ofld_frames_lso_hdr_splits), 448 4, STATS_FLAGS_FUNC, "tx_ofld_frames_lso_hdr_splits"}, 449 { STATS_OFFSET32(tx_encap_failures), 450 4, STATS_FLAGS_FUNC, "tx_encap_failures"}, 451 { STATS_OFFSET32(tx_hw_queue_full), 452 4, STATS_FLAGS_FUNC, "tx_hw_queue_full"}, 453 { STATS_OFFSET32(tx_hw_max_queue_depth), 454 4, STATS_FLAGS_FUNC, "tx_hw_max_queue_depth"}, 455 { STATS_OFFSET32(tx_dma_mapping_failure), 456 4, STATS_FLAGS_FUNC, "tx_dma_mapping_failure"}, 457 { STATS_OFFSET32(tx_max_drbr_queue_depth), 458 4, STATS_FLAGS_FUNC, "tx_max_drbr_queue_depth"}, 459 { STATS_OFFSET32(tx_window_violation_std), 460 4, STATS_FLAGS_FUNC, "tx_window_violation_std"}, 461 { STATS_OFFSET32(tx_window_violation_tso), 462 4, STATS_FLAGS_FUNC, "tx_window_violation_tso"}, 463 { STATS_OFFSET32(tx_chain_lost_mbuf), 464 4, STATS_FLAGS_FUNC, "tx_chain_lost_mbuf"}, 465 { STATS_OFFSET32(tx_frames_deferred), 466 4, STATS_FLAGS_FUNC, "tx_frames_deferred"}, 467 { STATS_OFFSET32(tx_queue_xoff), 468 4, STATS_FLAGS_FUNC, "tx_queue_xoff"}, 469 { STATS_OFFSET32(mbuf_defrag_attempts), 470 4, STATS_FLAGS_FUNC, "mbuf_defrag_attempts"}, 471 { STATS_OFFSET32(mbuf_defrag_failures), 472 4, STATS_FLAGS_FUNC, "mbuf_defrag_failures"}, 473 { STATS_OFFSET32(mbuf_rx_bd_alloc_failed), 474 4, STATS_FLAGS_FUNC, "mbuf_rx_bd_alloc_failed"}, 475 { STATS_OFFSET32(mbuf_rx_bd_mapping_failed), 476 4, STATS_FLAGS_FUNC, "mbuf_rx_bd_mapping_failed"}, 477 { STATS_OFFSET32(mbuf_rx_tpa_alloc_failed), 478 4, STATS_FLAGS_FUNC, "mbuf_rx_tpa_alloc_failed"}, 479 { STATS_OFFSET32(mbuf_rx_tpa_mapping_failed), 480 4, STATS_FLAGS_FUNC, "mbuf_rx_tpa_mapping_failed"}, 481 { STATS_OFFSET32(mbuf_rx_sge_alloc_failed), 482 4, STATS_FLAGS_FUNC, "mbuf_rx_sge_alloc_failed"}, 483 { STATS_OFFSET32(mbuf_rx_sge_mapping_failed), 484 4, STATS_FLAGS_FUNC, "mbuf_rx_sge_mapping_failed"}, 485 { STATS_OFFSET32(mbuf_alloc_tx), 486 4, STATS_FLAGS_FUNC, "mbuf_alloc_tx"}, 487 { STATS_OFFSET32(mbuf_alloc_rx), 488 4, STATS_FLAGS_FUNC, "mbuf_alloc_rx"}, 489 { STATS_OFFSET32(mbuf_alloc_sge), 490 4, STATS_FLAGS_FUNC, "mbuf_alloc_sge"}, 491 { STATS_OFFSET32(mbuf_alloc_tpa), 492 4, STATS_FLAGS_FUNC, "mbuf_alloc_tpa"}, 493 { STATS_OFFSET32(tx_queue_full_return), 494 4, STATS_FLAGS_FUNC, "tx_queue_full_return"}, 495 { STATS_OFFSET32(bxe_tx_mq_sc_state_failures), 496 4, STATS_FLAGS_FUNC, "bxe_tx_mq_sc_state_failures"}, 497 { STATS_OFFSET32(tx_request_link_down_failures), 498 4, STATS_FLAGS_FUNC, "tx_request_link_down_failures"}, 499 { STATS_OFFSET32(bd_avail_too_less_failures), 500 4, STATS_FLAGS_FUNC, "bd_avail_too_less_failures"}, 501 { STATS_OFFSET32(tx_mq_not_empty), 502 4, STATS_FLAGS_FUNC, "tx_mq_not_empty"}, 503 { STATS_OFFSET32(nsegs_path1_errors), 504 4, STATS_FLAGS_FUNC, "nsegs_path1_errors"}, 505 { STATS_OFFSET32(nsegs_path2_errors), 506 4, STATS_FLAGS_FUNC, "nsegs_path2_errors"} 507 508 509 }; 510 511 static const struct { 512 uint32_t offset; 513 uint32_t size; 514 char string[STAT_NAME_LEN]; 515 } bxe_eth_q_stats_arr[] = { 516 { Q_STATS_OFFSET32(total_bytes_received_hi), 517 8, "rx_bytes" }, 518 { Q_STATS_OFFSET32(total_unicast_packets_received_hi), 519 8, "rx_ucast_packets" }, 520 { Q_STATS_OFFSET32(total_multicast_packets_received_hi), 521 8, "rx_mcast_packets" }, 522 { Q_STATS_OFFSET32(total_broadcast_packets_received_hi), 523 8, "rx_bcast_packets" }, 524 { Q_STATS_OFFSET32(no_buff_discard_hi), 525 8, "rx_discards" }, 526 { Q_STATS_OFFSET32(total_bytes_transmitted_hi), 527 8, "tx_bytes" }, 528 { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi), 529 8, "tx_ucast_packets" }, 530 { Q_STATS_OFFSET32(total_multicast_packets_transmitted_hi), 531 8, "tx_mcast_packets" }, 532 { Q_STATS_OFFSET32(total_broadcast_packets_transmitted_hi), 533 8, "tx_bcast_packets" }, 534 { Q_STATS_OFFSET32(total_tpa_aggregations_hi), 535 8, "tpa_aggregations" }, 536 { Q_STATS_OFFSET32(total_tpa_aggregated_frames_hi), 537 8, "tpa_aggregated_frames"}, 538 { Q_STATS_OFFSET32(total_tpa_bytes_hi), 539 8, "tpa_bytes"}, 540 { Q_STATS_OFFSET32(rx_calls), 541 4, "rx_calls"}, 542 { Q_STATS_OFFSET32(rx_pkts), 543 4, "rx_pkts"}, 544 { Q_STATS_OFFSET32(rx_tpa_pkts), 545 4, "rx_tpa_pkts"}, 546 { Q_STATS_OFFSET32(rx_erroneous_jumbo_sge_pkts), 547 4, "rx_erroneous_jumbo_sge_pkts"}, 548 { Q_STATS_OFFSET32(rx_bxe_service_rxsgl), 549 4, "rx_bxe_service_rxsgl"}, 550 { Q_STATS_OFFSET32(rx_jumbo_sge_pkts), 551 4, "rx_jumbo_sge_pkts"}, 552 { Q_STATS_OFFSET32(rx_soft_errors), 553 4, "rx_soft_errors"}, 554 { Q_STATS_OFFSET32(rx_hw_csum_errors), 555 4, "rx_hw_csum_errors"}, 556 { Q_STATS_OFFSET32(rx_ofld_frames_csum_ip), 557 4, "rx_ofld_frames_csum_ip"}, 558 { Q_STATS_OFFSET32(rx_ofld_frames_csum_tcp_udp), 559 4, "rx_ofld_frames_csum_tcp_udp"}, 560 { Q_STATS_OFFSET32(rx_budget_reached), 561 4, "rx_budget_reached"}, 562 { Q_STATS_OFFSET32(tx_pkts), 563 4, "tx_pkts"}, 564 { Q_STATS_OFFSET32(tx_soft_errors), 565 4, "tx_soft_errors"}, 566 { Q_STATS_OFFSET32(tx_ofld_frames_csum_ip), 567 4, "tx_ofld_frames_csum_ip"}, 568 { Q_STATS_OFFSET32(tx_ofld_frames_csum_tcp), 569 4, "tx_ofld_frames_csum_tcp"}, 570 { Q_STATS_OFFSET32(tx_ofld_frames_csum_udp), 571 4, "tx_ofld_frames_csum_udp"}, 572 { Q_STATS_OFFSET32(tx_ofld_frames_lso), 573 4, "tx_ofld_frames_lso"}, 574 { Q_STATS_OFFSET32(tx_ofld_frames_lso_hdr_splits), 575 4, "tx_ofld_frames_lso_hdr_splits"}, 576 { Q_STATS_OFFSET32(tx_encap_failures), 577 4, "tx_encap_failures"}, 578 { Q_STATS_OFFSET32(tx_hw_queue_full), 579 4, "tx_hw_queue_full"}, 580 { Q_STATS_OFFSET32(tx_hw_max_queue_depth), 581 4, "tx_hw_max_queue_depth"}, 582 { Q_STATS_OFFSET32(tx_dma_mapping_failure), 583 4, "tx_dma_mapping_failure"}, 584 { Q_STATS_OFFSET32(tx_max_drbr_queue_depth), 585 4, "tx_max_drbr_queue_depth"}, 586 { Q_STATS_OFFSET32(tx_window_violation_std), 587 4, "tx_window_violation_std"}, 588 { Q_STATS_OFFSET32(tx_window_violation_tso), 589 4, "tx_window_violation_tso"}, 590 { Q_STATS_OFFSET32(tx_chain_lost_mbuf), 591 4, "tx_chain_lost_mbuf"}, 592 { Q_STATS_OFFSET32(tx_frames_deferred), 593 4, "tx_frames_deferred"}, 594 { Q_STATS_OFFSET32(tx_queue_xoff), 595 4, "tx_queue_xoff"}, 596 { Q_STATS_OFFSET32(mbuf_defrag_attempts), 597 4, "mbuf_defrag_attempts"}, 598 { Q_STATS_OFFSET32(mbuf_defrag_failures), 599 4, "mbuf_defrag_failures"}, 600 { Q_STATS_OFFSET32(mbuf_rx_bd_alloc_failed), 601 4, "mbuf_rx_bd_alloc_failed"}, 602 { Q_STATS_OFFSET32(mbuf_rx_bd_mapping_failed), 603 4, "mbuf_rx_bd_mapping_failed"}, 604 { Q_STATS_OFFSET32(mbuf_rx_tpa_alloc_failed), 605 4, "mbuf_rx_tpa_alloc_failed"}, 606 { Q_STATS_OFFSET32(mbuf_rx_tpa_mapping_failed), 607 4, "mbuf_rx_tpa_mapping_failed"}, 608 { Q_STATS_OFFSET32(mbuf_rx_sge_alloc_failed), 609 4, "mbuf_rx_sge_alloc_failed"}, 610 { Q_STATS_OFFSET32(mbuf_rx_sge_mapping_failed), 611 4, "mbuf_rx_sge_mapping_failed"}, 612 { Q_STATS_OFFSET32(mbuf_alloc_tx), 613 4, "mbuf_alloc_tx"}, 614 { Q_STATS_OFFSET32(mbuf_alloc_rx), 615 4, "mbuf_alloc_rx"}, 616 { Q_STATS_OFFSET32(mbuf_alloc_sge), 617 4, "mbuf_alloc_sge"}, 618 { Q_STATS_OFFSET32(mbuf_alloc_tpa), 619 4, "mbuf_alloc_tpa"}, 620 { Q_STATS_OFFSET32(tx_queue_full_return), 621 4, "tx_queue_full_return"}, 622 { Q_STATS_OFFSET32(bxe_tx_mq_sc_state_failures), 623 4, "bxe_tx_mq_sc_state_failures"}, 624 { Q_STATS_OFFSET32(tx_request_link_down_failures), 625 4, "tx_request_link_down_failures"}, 626 { Q_STATS_OFFSET32(bd_avail_too_less_failures), 627 4, "bd_avail_too_less_failures"}, 628 { Q_STATS_OFFSET32(tx_mq_not_empty), 629 4, "tx_mq_not_empty"}, 630 { Q_STATS_OFFSET32(nsegs_path1_errors), 631 4, "nsegs_path1_errors"}, 632 { Q_STATS_OFFSET32(nsegs_path2_errors), 633 4, "nsegs_path2_errors"} 634 635 636 }; 637 638 #define BXE_NUM_ETH_STATS ARRAY_SIZE(bxe_eth_stats_arr) 639 #define BXE_NUM_ETH_Q_STATS ARRAY_SIZE(bxe_eth_q_stats_arr) 640 641 642 static void bxe_cmng_fns_init(struct bxe_softc *sc, 643 uint8_t read_cfg, 644 uint8_t cmng_type); 645 static int bxe_get_cmng_fns_mode(struct bxe_softc *sc); 646 static void storm_memset_cmng(struct bxe_softc *sc, 647 struct cmng_init *cmng, 648 uint8_t port); 649 static void bxe_set_reset_global(struct bxe_softc *sc); 650 static void bxe_set_reset_in_progress(struct bxe_softc *sc); 651 static uint8_t bxe_reset_is_done(struct bxe_softc *sc, 652 int engine); 653 static uint8_t bxe_clear_pf_load(struct bxe_softc *sc); 654 static uint8_t bxe_chk_parity_attn(struct bxe_softc *sc, 655 uint8_t *global, 656 uint8_t print); 657 static void bxe_int_disable(struct bxe_softc *sc); 658 static int bxe_release_leader_lock(struct bxe_softc *sc); 659 static void bxe_pf_disable(struct bxe_softc *sc); 660 static void bxe_free_fp_buffers(struct bxe_softc *sc); 661 static inline void bxe_update_rx_prod(struct bxe_softc *sc, 662 struct bxe_fastpath *fp, 663 uint16_t rx_bd_prod, 664 uint16_t rx_cq_prod, 665 uint16_t rx_sge_prod); 666 static void bxe_link_report_locked(struct bxe_softc *sc); 667 static void bxe_link_report(struct bxe_softc *sc); 668 static void bxe_link_status_update(struct bxe_softc *sc); 669 static void bxe_periodic_callout_func(void *xsc); 670 static void bxe_periodic_start(struct bxe_softc *sc); 671 static void bxe_periodic_stop(struct bxe_softc *sc); 672 static int bxe_alloc_rx_bd_mbuf(struct bxe_fastpath *fp, 673 uint16_t prev_index, 674 uint16_t index); 675 static int bxe_alloc_rx_tpa_mbuf(struct bxe_fastpath *fp, 676 int queue); 677 static int bxe_alloc_rx_sge_mbuf(struct bxe_fastpath *fp, 678 uint16_t index); 679 static uint8_t bxe_txeof(struct bxe_softc *sc, 680 struct bxe_fastpath *fp); 681 static void bxe_task_fp(struct bxe_fastpath *fp); 682 static __noinline void bxe_dump_mbuf(struct bxe_softc *sc, 683 struct mbuf *m, 684 uint8_t contents); 685 static int bxe_alloc_mem(struct bxe_softc *sc); 686 static void bxe_free_mem(struct bxe_softc *sc); 687 static int bxe_alloc_fw_stats_mem(struct bxe_softc *sc); 688 static void bxe_free_fw_stats_mem(struct bxe_softc *sc); 689 static int bxe_interrupt_attach(struct bxe_softc *sc); 690 static void bxe_interrupt_detach(struct bxe_softc *sc); 691 static void bxe_set_rx_mode(struct bxe_softc *sc); 692 static int bxe_init_locked(struct bxe_softc *sc); 693 static int bxe_stop_locked(struct bxe_softc *sc); 694 static void bxe_sp_err_timeout_task(void *arg, int pending); 695 void bxe_parity_recover(struct bxe_softc *sc); 696 void bxe_handle_error(struct bxe_softc *sc); 697 static __noinline int bxe_nic_load(struct bxe_softc *sc, 698 int load_mode); 699 static __noinline int bxe_nic_unload(struct bxe_softc *sc, 700 uint32_t unload_mode, 701 uint8_t keep_link); 702 703 static void bxe_handle_sp_tq(void *context, int pending); 704 static void bxe_handle_fp_tq(void *context, int pending); 705 706 static int bxe_add_cdev(struct bxe_softc *sc); 707 static void bxe_del_cdev(struct bxe_softc *sc); 708 int bxe_grc_dump(struct bxe_softc *sc); 709 static int bxe_alloc_buf_rings(struct bxe_softc *sc); 710 static void bxe_free_buf_rings(struct bxe_softc *sc); 711 712 /* calculate crc32 on a buffer (NOTE: crc32_length MUST be aligned to 8) */ 713 uint32_t 714 calc_crc32(uint8_t *crc32_packet, 715 uint32_t crc32_length, 716 uint32_t crc32_seed, 717 uint8_t complement) 718 { 719 uint32_t byte = 0; 720 uint32_t bit = 0; 721 uint8_t msb = 0; 722 uint32_t temp = 0; 723 uint32_t shft = 0; 724 uint8_t current_byte = 0; 725 uint32_t crc32_result = crc32_seed; 726 const uint32_t CRC32_POLY = 0x1edc6f41; 727 728 if ((crc32_packet == NULL) || 729 (crc32_length == 0) || 730 ((crc32_length % 8) != 0)) 731 { 732 return (crc32_result); 733 } 734 735 for (byte = 0; byte < crc32_length; byte = byte + 1) 736 { 737 current_byte = crc32_packet[byte]; 738 for (bit = 0; bit < 8; bit = bit + 1) 739 { 740 /* msb = crc32_result[31]; */ 741 msb = (uint8_t)(crc32_result >> 31); 742 743 crc32_result = crc32_result << 1; 744 745 /* it (msb != current_byte[bit]) */ 746 if (msb != (0x1 & (current_byte >> bit))) 747 { 748 crc32_result = crc32_result ^ CRC32_POLY; 749 /* crc32_result[0] = 1 */ 750 crc32_result |= 1; 751 } 752 } 753 } 754 755 /* Last step is to: 756 * 1. "mirror" every bit 757 * 2. swap the 4 bytes 758 * 3. complement each bit 759 */ 760 761 /* Mirror */ 762 temp = crc32_result; 763 shft = sizeof(crc32_result) * 8 - 1; 764 765 for (crc32_result >>= 1; crc32_result; crc32_result >>= 1) 766 { 767 temp <<= 1; 768 temp |= crc32_result & 1; 769 shft-- ; 770 } 771 772 /* temp[31-bit] = crc32_result[bit] */ 773 temp <<= shft; 774 775 /* Swap */ 776 /* crc32_result = {temp[7:0], temp[15:8], temp[23:16], temp[31:24]} */ 777 { 778 uint32_t t0, t1, t2, t3; 779 t0 = (0x000000ff & (temp >> 24)); 780 t1 = (0x0000ff00 & (temp >> 8)); 781 t2 = (0x00ff0000 & (temp << 8)); 782 t3 = (0xff000000 & (temp << 24)); 783 crc32_result = t0 | t1 | t2 | t3; 784 } 785 786 /* Complement */ 787 if (complement) 788 { 789 crc32_result = ~crc32_result; 790 } 791 792 return (crc32_result); 793 } 794 795 int 796 bxe_test_bit(int nr, 797 volatile unsigned long *addr) 798 { 799 return ((atomic_load_acq_long(addr) & (1 << nr)) != 0); 800 } 801 802 void 803 bxe_set_bit(unsigned int nr, 804 volatile unsigned long *addr) 805 { 806 atomic_set_acq_long(addr, (1 << nr)); 807 } 808 809 void 810 bxe_clear_bit(int nr, 811 volatile unsigned long *addr) 812 { 813 atomic_clear_acq_long(addr, (1 << nr)); 814 } 815 816 int 817 bxe_test_and_set_bit(int nr, 818 volatile unsigned long *addr) 819 { 820 unsigned long x; 821 nr = (1 << nr); 822 do { 823 x = *addr; 824 } while (atomic_cmpset_acq_long(addr, x, x | nr) == 0); 825 // if (x & nr) bit_was_set; else bit_was_not_set; 826 return (x & nr); 827 } 828 829 int 830 bxe_test_and_clear_bit(int nr, 831 volatile unsigned long *addr) 832 { 833 unsigned long x; 834 nr = (1 << nr); 835 do { 836 x = *addr; 837 } while (atomic_cmpset_acq_long(addr, x, x & ~nr) == 0); 838 // if (x & nr) bit_was_set; else bit_was_not_set; 839 return (x & nr); 840 } 841 842 int 843 bxe_cmpxchg(volatile int *addr, 844 int old, 845 int new) 846 { 847 int x; 848 do { 849 x = *addr; 850 } while (atomic_cmpset_acq_int(addr, old, new) == 0); 851 return (x); 852 } 853 854 /* 855 * Get DMA memory from the OS. 856 * 857 * Validates that the OS has provided DMA buffers in response to a 858 * bus_dmamap_load call and saves the physical address of those buffers. 859 * When the callback is used the OS will return 0 for the mapping function 860 * (bus_dmamap_load) so we use the value of map_arg->maxsegs to pass any 861 * failures back to the caller. 862 * 863 * Returns: 864 * Nothing. 865 */ 866 static void 867 bxe_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error) 868 { 869 struct bxe_dma *dma = arg; 870 871 if (error) { 872 dma->paddr = 0; 873 dma->nseg = 0; 874 BLOGE(dma->sc, "Failed DMA alloc '%s' (%d)!\n", dma->msg, error); 875 } else { 876 dma->paddr = segs->ds_addr; 877 dma->nseg = nseg; 878 } 879 } 880 881 /* 882 * Allocate a block of memory and map it for DMA. No partial completions 883 * allowed and release any resources acquired if we can't acquire all 884 * resources. 885 * 886 * Returns: 887 * 0 = Success, !0 = Failure 888 */ 889 int 890 bxe_dma_alloc(struct bxe_softc *sc, 891 bus_size_t size, 892 struct bxe_dma *dma, 893 const char *msg) 894 { 895 int rc; 896 897 if (dma->size > 0) { 898 BLOGE(sc, "dma block '%s' already has size %lu\n", msg, 899 (unsigned long)dma->size); 900 return (1); 901 } 902 903 memset(dma, 0, sizeof(*dma)); /* sanity */ 904 dma->sc = sc; 905 dma->size = size; 906 snprintf(dma->msg, sizeof(dma->msg), "%s", msg); 907 908 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */ 909 BCM_PAGE_SIZE, /* alignment */ 910 0, /* boundary limit */ 911 BUS_SPACE_MAXADDR, /* restricted low */ 912 BUS_SPACE_MAXADDR, /* restricted hi */ 913 NULL, /* addr filter() */ 914 NULL, /* addr filter() arg */ 915 size, /* max map size */ 916 1, /* num discontinuous */ 917 size, /* max seg size */ 918 BUS_DMA_ALLOCNOW, /* flags */ 919 NULL, /* lock() */ 920 NULL, /* lock() arg */ 921 &dma->tag); /* returned dma tag */ 922 if (rc != 0) { 923 BLOGE(sc, "Failed to create dma tag for '%s' (%d)\n", msg, rc); 924 memset(dma, 0, sizeof(*dma)); 925 return (1); 926 } 927 928 rc = bus_dmamem_alloc(dma->tag, 929 (void **)&dma->vaddr, 930 (BUS_DMA_NOWAIT | BUS_DMA_ZERO), 931 &dma->map); 932 if (rc != 0) { 933 BLOGE(sc, "Failed to alloc dma mem for '%s' (%d)\n", msg, rc); 934 bus_dma_tag_destroy(dma->tag); 935 memset(dma, 0, sizeof(*dma)); 936 return (1); 937 } 938 939 rc = bus_dmamap_load(dma->tag, 940 dma->map, 941 dma->vaddr, 942 size, 943 bxe_dma_map_addr, /* BLOGD in here */ 944 dma, 945 BUS_DMA_NOWAIT); 946 if (rc != 0) { 947 BLOGE(sc, "Failed to load dma map for '%s' (%d)\n", msg, rc); 948 bus_dmamem_free(dma->tag, dma->vaddr, dma->map); 949 bus_dma_tag_destroy(dma->tag); 950 memset(dma, 0, sizeof(*dma)); 951 return (1); 952 } 953 954 return (0); 955 } 956 957 void 958 bxe_dma_free(struct bxe_softc *sc, 959 struct bxe_dma *dma) 960 { 961 if (dma->size > 0) { 962 DBASSERT(sc, (dma->tag != NULL), ("dma tag is NULL")); 963 964 bus_dmamap_sync(dma->tag, dma->map, 965 (BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE)); 966 bus_dmamap_unload(dma->tag, dma->map); 967 bus_dmamem_free(dma->tag, dma->vaddr, dma->map); 968 bus_dma_tag_destroy(dma->tag); 969 } 970 971 memset(dma, 0, sizeof(*dma)); 972 } 973 974 /* 975 * These indirect read and write routines are only during init. 976 * The locking is handled by the MCP. 977 */ 978 979 void 980 bxe_reg_wr_ind(struct bxe_softc *sc, 981 uint32_t addr, 982 uint32_t val) 983 { 984 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, addr, 4); 985 pci_write_config(sc->dev, PCICFG_GRC_DATA, val, 4); 986 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, 0, 4); 987 } 988 989 uint32_t 990 bxe_reg_rd_ind(struct bxe_softc *sc, 991 uint32_t addr) 992 { 993 uint32_t val; 994 995 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, addr, 4); 996 val = pci_read_config(sc->dev, PCICFG_GRC_DATA, 4); 997 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, 0, 4); 998 999 return (val); 1000 } 1001 1002 static int 1003 bxe_acquire_hw_lock(struct bxe_softc *sc, 1004 uint32_t resource) 1005 { 1006 uint32_t lock_status; 1007 uint32_t resource_bit = (1 << resource); 1008 int func = SC_FUNC(sc); 1009 uint32_t hw_lock_control_reg; 1010 int cnt; 1011 1012 /* validate the resource is within range */ 1013 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { 1014 BLOGE(sc, "(resource 0x%x > HW_LOCK_MAX_RESOURCE_VALUE)" 1015 " resource_bit 0x%x\n", resource, resource_bit); 1016 return (-1); 1017 } 1018 1019 if (func <= 5) { 1020 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + (func * 8)); 1021 } else { 1022 hw_lock_control_reg = 1023 (MISC_REG_DRIVER_CONTROL_7 + ((func - 6) * 8)); 1024 } 1025 1026 /* validate the resource is not already taken */ 1027 lock_status = REG_RD(sc, hw_lock_control_reg); 1028 if (lock_status & resource_bit) { 1029 BLOGE(sc, "resource (0x%x) in use (status 0x%x bit 0x%x)\n", 1030 resource, lock_status, resource_bit); 1031 return (-1); 1032 } 1033 1034 /* try every 5ms for 5 seconds */ 1035 for (cnt = 0; cnt < 1000; cnt++) { 1036 REG_WR(sc, (hw_lock_control_reg + 4), resource_bit); 1037 lock_status = REG_RD(sc, hw_lock_control_reg); 1038 if (lock_status & resource_bit) { 1039 return (0); 1040 } 1041 DELAY(5000); 1042 } 1043 1044 BLOGE(sc, "Resource 0x%x resource_bit 0x%x lock timeout!\n", 1045 resource, resource_bit); 1046 return (-1); 1047 } 1048 1049 static int 1050 bxe_release_hw_lock(struct bxe_softc *sc, 1051 uint32_t resource) 1052 { 1053 uint32_t lock_status; 1054 uint32_t resource_bit = (1 << resource); 1055 int func = SC_FUNC(sc); 1056 uint32_t hw_lock_control_reg; 1057 1058 /* validate the resource is within range */ 1059 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { 1060 BLOGE(sc, "(resource 0x%x > HW_LOCK_MAX_RESOURCE_VALUE)" 1061 " resource_bit 0x%x\n", resource, resource_bit); 1062 return (-1); 1063 } 1064 1065 if (func <= 5) { 1066 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + (func * 8)); 1067 } else { 1068 hw_lock_control_reg = 1069 (MISC_REG_DRIVER_CONTROL_7 + ((func - 6) * 8)); 1070 } 1071 1072 /* validate the resource is currently taken */ 1073 lock_status = REG_RD(sc, hw_lock_control_reg); 1074 if (!(lock_status & resource_bit)) { 1075 BLOGE(sc, "resource (0x%x) not in use (status 0x%x bit 0x%x)\n", 1076 resource, lock_status, resource_bit); 1077 return (-1); 1078 } 1079 1080 REG_WR(sc, hw_lock_control_reg, resource_bit); 1081 return (0); 1082 } 1083 static void bxe_acquire_phy_lock(struct bxe_softc *sc) 1084 { 1085 BXE_PHY_LOCK(sc); 1086 bxe_acquire_hw_lock(sc,HW_LOCK_RESOURCE_MDIO); 1087 } 1088 1089 static void bxe_release_phy_lock(struct bxe_softc *sc) 1090 { 1091 bxe_release_hw_lock(sc,HW_LOCK_RESOURCE_MDIO); 1092 BXE_PHY_UNLOCK(sc); 1093 } 1094 /* 1095 * Per pf misc lock must be acquired before the per port mcp lock. Otherwise, 1096 * had we done things the other way around, if two pfs from the same port 1097 * would attempt to access nvram at the same time, we could run into a 1098 * scenario such as: 1099 * pf A takes the port lock. 1100 * pf B succeeds in taking the same lock since they are from the same port. 1101 * pf A takes the per pf misc lock. Performs eeprom access. 1102 * pf A finishes. Unlocks the per pf misc lock. 1103 * Pf B takes the lock and proceeds to perform it's own access. 1104 * pf A unlocks the per port lock, while pf B is still working (!). 1105 * mcp takes the per port lock and corrupts pf B's access (and/or has it's own 1106 * access corrupted by pf B).* 1107 */ 1108 static int 1109 bxe_acquire_nvram_lock(struct bxe_softc *sc) 1110 { 1111 int port = SC_PORT(sc); 1112 int count, i; 1113 uint32_t val = 0; 1114 1115 /* acquire HW lock: protect against other PFs in PF Direct Assignment */ 1116 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_NVRAM); 1117 1118 /* adjust timeout for emulation/FPGA */ 1119 count = NVRAM_TIMEOUT_COUNT; 1120 if (CHIP_REV_IS_SLOW(sc)) { 1121 count *= 100; 1122 } 1123 1124 /* request access to nvram interface */ 1125 REG_WR(sc, MCP_REG_MCPR_NVM_SW_ARB, 1126 (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port)); 1127 1128 for (i = 0; i < count*10; i++) { 1129 val = REG_RD(sc, MCP_REG_MCPR_NVM_SW_ARB); 1130 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) { 1131 break; 1132 } 1133 1134 DELAY(5); 1135 } 1136 1137 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) { 1138 BLOGE(sc, "Cannot get access to nvram interface " 1139 "port %d val 0x%x (MCPR_NVM_SW_ARB_ARB_ARB1 << port)\n", 1140 port, val); 1141 return (-1); 1142 } 1143 1144 return (0); 1145 } 1146 1147 static int 1148 bxe_release_nvram_lock(struct bxe_softc *sc) 1149 { 1150 int port = SC_PORT(sc); 1151 int count, i; 1152 uint32_t val = 0; 1153 1154 /* adjust timeout for emulation/FPGA */ 1155 count = NVRAM_TIMEOUT_COUNT; 1156 if (CHIP_REV_IS_SLOW(sc)) { 1157 count *= 100; 1158 } 1159 1160 /* relinquish nvram interface */ 1161 REG_WR(sc, MCP_REG_MCPR_NVM_SW_ARB, 1162 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port)); 1163 1164 for (i = 0; i < count*10; i++) { 1165 val = REG_RD(sc, MCP_REG_MCPR_NVM_SW_ARB); 1166 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) { 1167 break; 1168 } 1169 1170 DELAY(5); 1171 } 1172 1173 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) { 1174 BLOGE(sc, "Cannot free access to nvram interface " 1175 "port %d val 0x%x (MCPR_NVM_SW_ARB_ARB_ARB1 << port)\n", 1176 port, val); 1177 return (-1); 1178 } 1179 1180 /* release HW lock: protect against other PFs in PF Direct Assignment */ 1181 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_NVRAM); 1182 1183 return (0); 1184 } 1185 1186 static void 1187 bxe_enable_nvram_access(struct bxe_softc *sc) 1188 { 1189 uint32_t val; 1190 1191 val = REG_RD(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE); 1192 1193 /* enable both bits, even on read */ 1194 REG_WR(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE, 1195 (val | MCPR_NVM_ACCESS_ENABLE_EN | MCPR_NVM_ACCESS_ENABLE_WR_EN)); 1196 } 1197 1198 static void 1199 bxe_disable_nvram_access(struct bxe_softc *sc) 1200 { 1201 uint32_t val; 1202 1203 val = REG_RD(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE); 1204 1205 /* disable both bits, even after read */ 1206 REG_WR(sc, MCP_REG_MCPR_NVM_ACCESS_ENABLE, 1207 (val & ~(MCPR_NVM_ACCESS_ENABLE_EN | 1208 MCPR_NVM_ACCESS_ENABLE_WR_EN))); 1209 } 1210 1211 static int 1212 bxe_nvram_read_dword(struct bxe_softc *sc, 1213 uint32_t offset, 1214 uint32_t *ret_val, 1215 uint32_t cmd_flags) 1216 { 1217 int count, i, rc; 1218 uint32_t val; 1219 1220 /* build the command word */ 1221 cmd_flags |= MCPR_NVM_COMMAND_DOIT; 1222 1223 /* need to clear DONE bit separately */ 1224 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE); 1225 1226 /* address of the NVRAM to read from */ 1227 REG_WR(sc, MCP_REG_MCPR_NVM_ADDR, 1228 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE)); 1229 1230 /* issue a read command */ 1231 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, cmd_flags); 1232 1233 /* adjust timeout for emulation/FPGA */ 1234 count = NVRAM_TIMEOUT_COUNT; 1235 if (CHIP_REV_IS_SLOW(sc)) { 1236 count *= 100; 1237 } 1238 1239 /* wait for completion */ 1240 *ret_val = 0; 1241 rc = -1; 1242 for (i = 0; i < count; i++) { 1243 DELAY(5); 1244 val = REG_RD(sc, MCP_REG_MCPR_NVM_COMMAND); 1245 1246 if (val & MCPR_NVM_COMMAND_DONE) { 1247 val = REG_RD(sc, MCP_REG_MCPR_NVM_READ); 1248 /* we read nvram data in cpu order 1249 * but ethtool sees it as an array of bytes 1250 * converting to big-endian will do the work 1251 */ 1252 *ret_val = htobe32(val); 1253 rc = 0; 1254 break; 1255 } 1256 } 1257 1258 if (rc == -1) { 1259 BLOGE(sc, "nvram read timeout expired " 1260 "(offset 0x%x cmd_flags 0x%x val 0x%x)\n", 1261 offset, cmd_flags, val); 1262 } 1263 1264 return (rc); 1265 } 1266 1267 static int 1268 bxe_nvram_read(struct bxe_softc *sc, 1269 uint32_t offset, 1270 uint8_t *ret_buf, 1271 int buf_size) 1272 { 1273 uint32_t cmd_flags; 1274 uint32_t val; 1275 int rc; 1276 1277 if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) { 1278 BLOGE(sc, "Invalid parameter, offset 0x%x buf_size 0x%x\n", 1279 offset, buf_size); 1280 return (-1); 1281 } 1282 1283 if ((offset + buf_size) > sc->devinfo.flash_size) { 1284 BLOGE(sc, "Invalid parameter, " 1285 "offset 0x%x + buf_size 0x%x > flash_size 0x%x\n", 1286 offset, buf_size, sc->devinfo.flash_size); 1287 return (-1); 1288 } 1289 1290 /* request access to nvram interface */ 1291 rc = bxe_acquire_nvram_lock(sc); 1292 if (rc) { 1293 return (rc); 1294 } 1295 1296 /* enable access to nvram interface */ 1297 bxe_enable_nvram_access(sc); 1298 1299 /* read the first word(s) */ 1300 cmd_flags = MCPR_NVM_COMMAND_FIRST; 1301 while ((buf_size > sizeof(uint32_t)) && (rc == 0)) { 1302 rc = bxe_nvram_read_dword(sc, offset, &val, cmd_flags); 1303 memcpy(ret_buf, &val, 4); 1304 1305 /* advance to the next dword */ 1306 offset += sizeof(uint32_t); 1307 ret_buf += sizeof(uint32_t); 1308 buf_size -= sizeof(uint32_t); 1309 cmd_flags = 0; 1310 } 1311 1312 if (rc == 0) { 1313 cmd_flags |= MCPR_NVM_COMMAND_LAST; 1314 rc = bxe_nvram_read_dword(sc, offset, &val, cmd_flags); 1315 memcpy(ret_buf, &val, 4); 1316 } 1317 1318 /* disable access to nvram interface */ 1319 bxe_disable_nvram_access(sc); 1320 bxe_release_nvram_lock(sc); 1321 1322 return (rc); 1323 } 1324 1325 static int 1326 bxe_nvram_write_dword(struct bxe_softc *sc, 1327 uint32_t offset, 1328 uint32_t val, 1329 uint32_t cmd_flags) 1330 { 1331 int count, i, rc; 1332 1333 /* build the command word */ 1334 cmd_flags |= (MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR); 1335 1336 /* need to clear DONE bit separately */ 1337 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE); 1338 1339 /* write the data */ 1340 REG_WR(sc, MCP_REG_MCPR_NVM_WRITE, val); 1341 1342 /* address of the NVRAM to write to */ 1343 REG_WR(sc, MCP_REG_MCPR_NVM_ADDR, 1344 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE)); 1345 1346 /* issue the write command */ 1347 REG_WR(sc, MCP_REG_MCPR_NVM_COMMAND, cmd_flags); 1348 1349 /* adjust timeout for emulation/FPGA */ 1350 count = NVRAM_TIMEOUT_COUNT; 1351 if (CHIP_REV_IS_SLOW(sc)) { 1352 count *= 100; 1353 } 1354 1355 /* wait for completion */ 1356 rc = -1; 1357 for (i = 0; i < count; i++) { 1358 DELAY(5); 1359 val = REG_RD(sc, MCP_REG_MCPR_NVM_COMMAND); 1360 if (val & MCPR_NVM_COMMAND_DONE) { 1361 rc = 0; 1362 break; 1363 } 1364 } 1365 1366 if (rc == -1) { 1367 BLOGE(sc, "nvram write timeout expired " 1368 "(offset 0x%x cmd_flags 0x%x val 0x%x)\n", 1369 offset, cmd_flags, val); 1370 } 1371 1372 return (rc); 1373 } 1374 1375 #define BYTE_OFFSET(offset) (8 * (offset & 0x03)) 1376 1377 static int 1378 bxe_nvram_write1(struct bxe_softc *sc, 1379 uint32_t offset, 1380 uint8_t *data_buf, 1381 int buf_size) 1382 { 1383 uint32_t cmd_flags; 1384 uint32_t align_offset; 1385 uint32_t val; 1386 int rc; 1387 1388 if ((offset + buf_size) > sc->devinfo.flash_size) { 1389 BLOGE(sc, "Invalid parameter, " 1390 "offset 0x%x + buf_size 0x%x > flash_size 0x%x\n", 1391 offset, buf_size, sc->devinfo.flash_size); 1392 return (-1); 1393 } 1394 1395 /* request access to nvram interface */ 1396 rc = bxe_acquire_nvram_lock(sc); 1397 if (rc) { 1398 return (rc); 1399 } 1400 1401 /* enable access to nvram interface */ 1402 bxe_enable_nvram_access(sc); 1403 1404 cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST); 1405 align_offset = (offset & ~0x03); 1406 rc = bxe_nvram_read_dword(sc, align_offset, &val, cmd_flags); 1407 1408 if (rc == 0) { 1409 val &= ~(0xff << BYTE_OFFSET(offset)); 1410 val |= (*data_buf << BYTE_OFFSET(offset)); 1411 1412 /* nvram data is returned as an array of bytes 1413 * convert it back to cpu order 1414 */ 1415 val = be32toh(val); 1416 1417 rc = bxe_nvram_write_dword(sc, align_offset, val, cmd_flags); 1418 } 1419 1420 /* disable access to nvram interface */ 1421 bxe_disable_nvram_access(sc); 1422 bxe_release_nvram_lock(sc); 1423 1424 return (rc); 1425 } 1426 1427 static int 1428 bxe_nvram_write(struct bxe_softc *sc, 1429 uint32_t offset, 1430 uint8_t *data_buf, 1431 int buf_size) 1432 { 1433 uint32_t cmd_flags; 1434 uint32_t val; 1435 uint32_t written_so_far; 1436 int rc; 1437 1438 if (buf_size == 1) { 1439 return (bxe_nvram_write1(sc, offset, data_buf, buf_size)); 1440 } 1441 1442 if ((offset & 0x03) || (buf_size & 0x03) /* || (buf_size == 0) */) { 1443 BLOGE(sc, "Invalid parameter, offset 0x%x buf_size 0x%x\n", 1444 offset, buf_size); 1445 return (-1); 1446 } 1447 1448 if (buf_size == 0) { 1449 return (0); /* nothing to do */ 1450 } 1451 1452 if ((offset + buf_size) > sc->devinfo.flash_size) { 1453 BLOGE(sc, "Invalid parameter, " 1454 "offset 0x%x + buf_size 0x%x > flash_size 0x%x\n", 1455 offset, buf_size, sc->devinfo.flash_size); 1456 return (-1); 1457 } 1458 1459 /* request access to nvram interface */ 1460 rc = bxe_acquire_nvram_lock(sc); 1461 if (rc) { 1462 return (rc); 1463 } 1464 1465 /* enable access to nvram interface */ 1466 bxe_enable_nvram_access(sc); 1467 1468 written_so_far = 0; 1469 cmd_flags = MCPR_NVM_COMMAND_FIRST; 1470 while ((written_so_far < buf_size) && (rc == 0)) { 1471 if (written_so_far == (buf_size - sizeof(uint32_t))) { 1472 cmd_flags |= MCPR_NVM_COMMAND_LAST; 1473 } else if (((offset + 4) % NVRAM_PAGE_SIZE) == 0) { 1474 cmd_flags |= MCPR_NVM_COMMAND_LAST; 1475 } else if ((offset % NVRAM_PAGE_SIZE) == 0) { 1476 cmd_flags |= MCPR_NVM_COMMAND_FIRST; 1477 } 1478 1479 memcpy(&val, data_buf, 4); 1480 1481 rc = bxe_nvram_write_dword(sc, offset, val, cmd_flags); 1482 1483 /* advance to the next dword */ 1484 offset += sizeof(uint32_t); 1485 data_buf += sizeof(uint32_t); 1486 written_so_far += sizeof(uint32_t); 1487 cmd_flags = 0; 1488 } 1489 1490 /* disable access to nvram interface */ 1491 bxe_disable_nvram_access(sc); 1492 bxe_release_nvram_lock(sc); 1493 1494 return (rc); 1495 } 1496 1497 /* copy command into DMAE command memory and set DMAE command Go */ 1498 void 1499 bxe_post_dmae(struct bxe_softc *sc, 1500 struct dmae_cmd *dmae, 1501 int idx) 1502 { 1503 uint32_t cmd_offset; 1504 int i; 1505 1506 cmd_offset = (DMAE_REG_CMD_MEM + (sizeof(struct dmae_cmd) * idx)); 1507 for (i = 0; i < ((sizeof(struct dmae_cmd) / 4)); i++) { 1508 REG_WR(sc, (cmd_offset + (i * 4)), *(((uint32_t *)dmae) + i)); 1509 } 1510 1511 REG_WR(sc, dmae_reg_go_c[idx], 1); 1512 } 1513 1514 uint32_t 1515 bxe_dmae_opcode_add_comp(uint32_t opcode, 1516 uint8_t comp_type) 1517 { 1518 return (opcode | ((comp_type << DMAE_CMD_C_DST_SHIFT) | 1519 DMAE_CMD_C_TYPE_ENABLE)); 1520 } 1521 1522 uint32_t 1523 bxe_dmae_opcode_clr_src_reset(uint32_t opcode) 1524 { 1525 return (opcode & ~DMAE_CMD_SRC_RESET); 1526 } 1527 1528 uint32_t 1529 bxe_dmae_opcode(struct bxe_softc *sc, 1530 uint8_t src_type, 1531 uint8_t dst_type, 1532 uint8_t with_comp, 1533 uint8_t comp_type) 1534 { 1535 uint32_t opcode = 0; 1536 1537 opcode |= ((src_type << DMAE_CMD_SRC_SHIFT) | 1538 (dst_type << DMAE_CMD_DST_SHIFT)); 1539 1540 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET); 1541 1542 opcode |= (SC_PORT(sc) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0); 1543 1544 opcode |= ((SC_VN(sc) << DMAE_CMD_E1HVN_SHIFT) | 1545 (SC_VN(sc) << DMAE_CMD_DST_VN_SHIFT)); 1546 1547 opcode |= (DMAE_COM_SET_ERR << DMAE_CMD_ERR_POLICY_SHIFT); 1548 1549 #ifdef __BIG_ENDIAN 1550 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP; 1551 #else 1552 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP; 1553 #endif 1554 1555 if (with_comp) { 1556 opcode = bxe_dmae_opcode_add_comp(opcode, comp_type); 1557 } 1558 1559 return (opcode); 1560 } 1561 1562 static void 1563 bxe_prep_dmae_with_comp(struct bxe_softc *sc, 1564 struct dmae_cmd *dmae, 1565 uint8_t src_type, 1566 uint8_t dst_type) 1567 { 1568 memset(dmae, 0, sizeof(struct dmae_cmd)); 1569 1570 /* set the opcode */ 1571 dmae->opcode = bxe_dmae_opcode(sc, src_type, dst_type, 1572 TRUE, DMAE_COMP_PCI); 1573 1574 /* fill in the completion parameters */ 1575 dmae->comp_addr_lo = U64_LO(BXE_SP_MAPPING(sc, wb_comp)); 1576 dmae->comp_addr_hi = U64_HI(BXE_SP_MAPPING(sc, wb_comp)); 1577 dmae->comp_val = DMAE_COMP_VAL; 1578 } 1579 1580 /* issue a DMAE command over the init channel and wait for completion */ 1581 static int 1582 bxe_issue_dmae_with_comp(struct bxe_softc *sc, 1583 struct dmae_cmd *dmae) 1584 { 1585 uint32_t *wb_comp = BXE_SP(sc, wb_comp); 1586 int timeout = CHIP_REV_IS_SLOW(sc) ? 400000 : 4000; 1587 1588 BXE_DMAE_LOCK(sc); 1589 1590 /* reset completion */ 1591 *wb_comp = 0; 1592 1593 /* post the command on the channel used for initializations */ 1594 bxe_post_dmae(sc, dmae, INIT_DMAE_C(sc)); 1595 1596 /* wait for completion */ 1597 DELAY(5); 1598 1599 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) { 1600 if (!timeout || 1601 (sc->recovery_state != BXE_RECOVERY_DONE && 1602 sc->recovery_state != BXE_RECOVERY_NIC_LOADING)) { 1603 BLOGE(sc, "DMAE timeout! *wb_comp 0x%x recovery_state 0x%x\n", 1604 *wb_comp, sc->recovery_state); 1605 BXE_DMAE_UNLOCK(sc); 1606 return (DMAE_TIMEOUT); 1607 } 1608 1609 timeout--; 1610 DELAY(50); 1611 } 1612 1613 if (*wb_comp & DMAE_PCI_ERR_FLAG) { 1614 BLOGE(sc, "DMAE PCI error! *wb_comp 0x%x recovery_state 0x%x\n", 1615 *wb_comp, sc->recovery_state); 1616 BXE_DMAE_UNLOCK(sc); 1617 return (DMAE_PCI_ERROR); 1618 } 1619 1620 BXE_DMAE_UNLOCK(sc); 1621 return (0); 1622 } 1623 1624 void 1625 bxe_read_dmae(struct bxe_softc *sc, 1626 uint32_t src_addr, 1627 uint32_t len32) 1628 { 1629 struct dmae_cmd dmae; 1630 uint32_t *data; 1631 int i, rc; 1632 1633 DBASSERT(sc, (len32 <= 4), ("DMAE read length is %d", len32)); 1634 1635 if (!sc->dmae_ready) { 1636 data = BXE_SP(sc, wb_data[0]); 1637 1638 for (i = 0; i < len32; i++) { 1639 data[i] = (CHIP_IS_E1(sc)) ? 1640 bxe_reg_rd_ind(sc, (src_addr + (i * 4))) : 1641 REG_RD(sc, (src_addr + (i * 4))); 1642 } 1643 1644 return; 1645 } 1646 1647 /* set opcode and fixed command fields */ 1648 bxe_prep_dmae_with_comp(sc, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI); 1649 1650 /* fill in addresses and len */ 1651 dmae.src_addr_lo = (src_addr >> 2); /* GRC addr has dword resolution */ 1652 dmae.src_addr_hi = 0; 1653 dmae.dst_addr_lo = U64_LO(BXE_SP_MAPPING(sc, wb_data)); 1654 dmae.dst_addr_hi = U64_HI(BXE_SP_MAPPING(sc, wb_data)); 1655 dmae.len = len32; 1656 1657 /* issue the command and wait for completion */ 1658 if ((rc = bxe_issue_dmae_with_comp(sc, &dmae)) != 0) { 1659 bxe_panic(sc, ("DMAE failed (%d)\n", rc)); 1660 } 1661 } 1662 1663 void 1664 bxe_write_dmae(struct bxe_softc *sc, 1665 bus_addr_t dma_addr, 1666 uint32_t dst_addr, 1667 uint32_t len32) 1668 { 1669 struct dmae_cmd dmae; 1670 int rc; 1671 1672 if (!sc->dmae_ready) { 1673 DBASSERT(sc, (len32 <= 4), ("DMAE not ready and length is %d", len32)); 1674 1675 if (CHIP_IS_E1(sc)) { 1676 ecore_init_ind_wr(sc, dst_addr, BXE_SP(sc, wb_data[0]), len32); 1677 } else { 1678 ecore_init_str_wr(sc, dst_addr, BXE_SP(sc, wb_data[0]), len32); 1679 } 1680 1681 return; 1682 } 1683 1684 /* set opcode and fixed command fields */ 1685 bxe_prep_dmae_with_comp(sc, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC); 1686 1687 /* fill in addresses and len */ 1688 dmae.src_addr_lo = U64_LO(dma_addr); 1689 dmae.src_addr_hi = U64_HI(dma_addr); 1690 dmae.dst_addr_lo = (dst_addr >> 2); /* GRC addr has dword resolution */ 1691 dmae.dst_addr_hi = 0; 1692 dmae.len = len32; 1693 1694 /* issue the command and wait for completion */ 1695 if ((rc = bxe_issue_dmae_with_comp(sc, &dmae)) != 0) { 1696 bxe_panic(sc, ("DMAE failed (%d)\n", rc)); 1697 } 1698 } 1699 1700 void 1701 bxe_write_dmae_phys_len(struct bxe_softc *sc, 1702 bus_addr_t phys_addr, 1703 uint32_t addr, 1704 uint32_t len) 1705 { 1706 int dmae_wr_max = DMAE_LEN32_WR_MAX(sc); 1707 int offset = 0; 1708 1709 while (len > dmae_wr_max) { 1710 bxe_write_dmae(sc, 1711 (phys_addr + offset), /* src DMA address */ 1712 (addr + offset), /* dst GRC address */ 1713 dmae_wr_max); 1714 offset += (dmae_wr_max * 4); 1715 len -= dmae_wr_max; 1716 } 1717 1718 bxe_write_dmae(sc, 1719 (phys_addr + offset), /* src DMA address */ 1720 (addr + offset), /* dst GRC address */ 1721 len); 1722 } 1723 1724 void 1725 bxe_set_ctx_validation(struct bxe_softc *sc, 1726 struct eth_context *cxt, 1727 uint32_t cid) 1728 { 1729 /* ustorm cxt validation */ 1730 cxt->ustorm_ag_context.cdu_usage = 1731 CDU_RSRVD_VALUE_TYPE_A(HW_CID(sc, cid), 1732 CDU_REGION_NUMBER_UCM_AG, ETH_CONNECTION_TYPE); 1733 /* xcontext validation */ 1734 cxt->xstorm_ag_context.cdu_reserved = 1735 CDU_RSRVD_VALUE_TYPE_A(HW_CID(sc, cid), 1736 CDU_REGION_NUMBER_XCM_AG, ETH_CONNECTION_TYPE); 1737 } 1738 1739 static void 1740 bxe_storm_memset_hc_timeout(struct bxe_softc *sc, 1741 uint8_t port, 1742 uint8_t fw_sb_id, 1743 uint8_t sb_index, 1744 uint8_t ticks) 1745 { 1746 uint32_t addr = 1747 (BAR_CSTRORM_INTMEM + 1748 CSTORM_STATUS_BLOCK_DATA_TIMEOUT_OFFSET(fw_sb_id, sb_index)); 1749 1750 REG_WR8(sc, addr, ticks); 1751 1752 BLOGD(sc, DBG_LOAD, 1753 "port %d fw_sb_id %d sb_index %d ticks %d\n", 1754 port, fw_sb_id, sb_index, ticks); 1755 } 1756 1757 static void 1758 bxe_storm_memset_hc_disable(struct bxe_softc *sc, 1759 uint8_t port, 1760 uint16_t fw_sb_id, 1761 uint8_t sb_index, 1762 uint8_t disable) 1763 { 1764 uint32_t enable_flag = 1765 (disable) ? 0 : (1 << HC_INDEX_DATA_HC_ENABLED_SHIFT); 1766 uint32_t addr = 1767 (BAR_CSTRORM_INTMEM + 1768 CSTORM_STATUS_BLOCK_DATA_FLAGS_OFFSET(fw_sb_id, sb_index)); 1769 uint8_t flags; 1770 1771 /* clear and set */ 1772 flags = REG_RD8(sc, addr); 1773 flags &= ~HC_INDEX_DATA_HC_ENABLED; 1774 flags |= enable_flag; 1775 REG_WR8(sc, addr, flags); 1776 1777 BLOGD(sc, DBG_LOAD, 1778 "port %d fw_sb_id %d sb_index %d disable %d\n", 1779 port, fw_sb_id, sb_index, disable); 1780 } 1781 1782 void 1783 bxe_update_coalesce_sb_index(struct bxe_softc *sc, 1784 uint8_t fw_sb_id, 1785 uint8_t sb_index, 1786 uint8_t disable, 1787 uint16_t usec) 1788 { 1789 int port = SC_PORT(sc); 1790 uint8_t ticks = (usec / 4); /* XXX ??? */ 1791 1792 bxe_storm_memset_hc_timeout(sc, port, fw_sb_id, sb_index, ticks); 1793 1794 disable = (disable) ? 1 : ((usec) ? 0 : 1); 1795 bxe_storm_memset_hc_disable(sc, port, fw_sb_id, sb_index, disable); 1796 } 1797 1798 void 1799 elink_cb_udelay(struct bxe_softc *sc, 1800 uint32_t usecs) 1801 { 1802 DELAY(usecs); 1803 } 1804 1805 uint32_t 1806 elink_cb_reg_read(struct bxe_softc *sc, 1807 uint32_t reg_addr) 1808 { 1809 return (REG_RD(sc, reg_addr)); 1810 } 1811 1812 void 1813 elink_cb_reg_write(struct bxe_softc *sc, 1814 uint32_t reg_addr, 1815 uint32_t val) 1816 { 1817 REG_WR(sc, reg_addr, val); 1818 } 1819 1820 void 1821 elink_cb_reg_wb_write(struct bxe_softc *sc, 1822 uint32_t offset, 1823 uint32_t *wb_write, 1824 uint16_t len) 1825 { 1826 REG_WR_DMAE(sc, offset, wb_write, len); 1827 } 1828 1829 void 1830 elink_cb_reg_wb_read(struct bxe_softc *sc, 1831 uint32_t offset, 1832 uint32_t *wb_write, 1833 uint16_t len) 1834 { 1835 REG_RD_DMAE(sc, offset, wb_write, len); 1836 } 1837 1838 uint8_t 1839 elink_cb_path_id(struct bxe_softc *sc) 1840 { 1841 return (SC_PATH(sc)); 1842 } 1843 1844 void 1845 elink_cb_event_log(struct bxe_softc *sc, 1846 const elink_log_id_t elink_log_id, 1847 ...) 1848 { 1849 /* XXX */ 1850 BLOGI(sc, "ELINK EVENT LOG (%d)\n", elink_log_id); 1851 } 1852 1853 static int 1854 bxe_set_spio(struct bxe_softc *sc, 1855 int spio, 1856 uint32_t mode) 1857 { 1858 uint32_t spio_reg; 1859 1860 /* Only 2 SPIOs are configurable */ 1861 if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) { 1862 BLOGE(sc, "Invalid SPIO 0x%x mode 0x%x\n", spio, mode); 1863 return (-1); 1864 } 1865 1866 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_SPIO); 1867 1868 /* read SPIO and mask except the float bits */ 1869 spio_reg = (REG_RD(sc, MISC_REG_SPIO) & MISC_SPIO_FLOAT); 1870 1871 switch (mode) { 1872 case MISC_SPIO_OUTPUT_LOW: 1873 BLOGD(sc, DBG_LOAD, "Set SPIO 0x%x -> output low\n", spio); 1874 /* clear FLOAT and set CLR */ 1875 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS); 1876 spio_reg |= (spio << MISC_SPIO_CLR_POS); 1877 break; 1878 1879 case MISC_SPIO_OUTPUT_HIGH: 1880 BLOGD(sc, DBG_LOAD, "Set SPIO 0x%x -> output high\n", spio); 1881 /* clear FLOAT and set SET */ 1882 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS); 1883 spio_reg |= (spio << MISC_SPIO_SET_POS); 1884 break; 1885 1886 case MISC_SPIO_INPUT_HI_Z: 1887 BLOGD(sc, DBG_LOAD, "Set SPIO 0x%x -> input\n", spio); 1888 /* set FLOAT */ 1889 spio_reg |= (spio << MISC_SPIO_FLOAT_POS); 1890 break; 1891 1892 default: 1893 break; 1894 } 1895 1896 REG_WR(sc, MISC_REG_SPIO, spio_reg); 1897 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_SPIO); 1898 1899 return (0); 1900 } 1901 1902 static int 1903 bxe_gpio_read(struct bxe_softc *sc, 1904 int gpio_num, 1905 uint8_t port) 1906 { 1907 /* The GPIO should be swapped if swap register is set and active */ 1908 int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) && 1909 REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port); 1910 int gpio_shift = (gpio_num + 1911 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0)); 1912 uint32_t gpio_mask = (1 << gpio_shift); 1913 uint32_t gpio_reg; 1914 1915 if (gpio_num > MISC_REGISTERS_GPIO_3) { 1916 BLOGE(sc, "Invalid GPIO %d port 0x%x gpio_port %d gpio_shift %d" 1917 " gpio_mask 0x%x\n", gpio_num, port, gpio_port, gpio_shift, 1918 gpio_mask); 1919 return (-1); 1920 } 1921 1922 /* read GPIO value */ 1923 gpio_reg = REG_RD(sc, MISC_REG_GPIO); 1924 1925 /* get the requested pin value */ 1926 return ((gpio_reg & gpio_mask) == gpio_mask) ? 1 : 0; 1927 } 1928 1929 static int 1930 bxe_gpio_write(struct bxe_softc *sc, 1931 int gpio_num, 1932 uint32_t mode, 1933 uint8_t port) 1934 { 1935 /* The GPIO should be swapped if swap register is set and active */ 1936 int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) && 1937 REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port); 1938 int gpio_shift = (gpio_num + 1939 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0)); 1940 uint32_t gpio_mask = (1 << gpio_shift); 1941 uint32_t gpio_reg; 1942 1943 if (gpio_num > MISC_REGISTERS_GPIO_3) { 1944 BLOGE(sc, "Invalid GPIO %d mode 0x%x port 0x%x gpio_port %d" 1945 " gpio_shift %d gpio_mask 0x%x\n", 1946 gpio_num, mode, port, gpio_port, gpio_shift, gpio_mask); 1947 return (-1); 1948 } 1949 1950 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO); 1951 1952 /* read GPIO and mask except the float bits */ 1953 gpio_reg = (REG_RD(sc, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT); 1954 1955 switch (mode) { 1956 case MISC_REGISTERS_GPIO_OUTPUT_LOW: 1957 BLOGD(sc, DBG_PHY, 1958 "Set GPIO %d (shift %d) -> output low\n", 1959 gpio_num, gpio_shift); 1960 /* clear FLOAT and set CLR */ 1961 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); 1962 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS); 1963 break; 1964 1965 case MISC_REGISTERS_GPIO_OUTPUT_HIGH: 1966 BLOGD(sc, DBG_PHY, 1967 "Set GPIO %d (shift %d) -> output high\n", 1968 gpio_num, gpio_shift); 1969 /* clear FLOAT and set SET */ 1970 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); 1971 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS); 1972 break; 1973 1974 case MISC_REGISTERS_GPIO_INPUT_HI_Z: 1975 BLOGD(sc, DBG_PHY, 1976 "Set GPIO %d (shift %d) -> input\n", 1977 gpio_num, gpio_shift); 1978 /* set FLOAT */ 1979 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); 1980 break; 1981 1982 default: 1983 break; 1984 } 1985 1986 REG_WR(sc, MISC_REG_GPIO, gpio_reg); 1987 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO); 1988 1989 return (0); 1990 } 1991 1992 static int 1993 bxe_gpio_mult_write(struct bxe_softc *sc, 1994 uint8_t pins, 1995 uint32_t mode) 1996 { 1997 uint32_t gpio_reg; 1998 1999 /* any port swapping should be handled by caller */ 2000 2001 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO); 2002 2003 /* read GPIO and mask except the float bits */ 2004 gpio_reg = REG_RD(sc, MISC_REG_GPIO); 2005 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS); 2006 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS); 2007 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS); 2008 2009 switch (mode) { 2010 case MISC_REGISTERS_GPIO_OUTPUT_LOW: 2011 BLOGD(sc, DBG_PHY, "Set GPIO 0x%x -> output low\n", pins); 2012 /* set CLR */ 2013 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS); 2014 break; 2015 2016 case MISC_REGISTERS_GPIO_OUTPUT_HIGH: 2017 BLOGD(sc, DBG_PHY, "Set GPIO 0x%x -> output high\n", pins); 2018 /* set SET */ 2019 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS); 2020 break; 2021 2022 case MISC_REGISTERS_GPIO_INPUT_HI_Z: 2023 BLOGD(sc, DBG_PHY, "Set GPIO 0x%x -> input\n", pins); 2024 /* set FLOAT */ 2025 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS); 2026 break; 2027 2028 default: 2029 BLOGE(sc, "Invalid GPIO mode assignment pins 0x%x mode 0x%x" 2030 " gpio_reg 0x%x\n", pins, mode, gpio_reg); 2031 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO); 2032 return (-1); 2033 } 2034 2035 REG_WR(sc, MISC_REG_GPIO, gpio_reg); 2036 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO); 2037 2038 return (0); 2039 } 2040 2041 static int 2042 bxe_gpio_int_write(struct bxe_softc *sc, 2043 int gpio_num, 2044 uint32_t mode, 2045 uint8_t port) 2046 { 2047 /* The GPIO should be swapped if swap register is set and active */ 2048 int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) && 2049 REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port); 2050 int gpio_shift = (gpio_num + 2051 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0)); 2052 uint32_t gpio_mask = (1 << gpio_shift); 2053 uint32_t gpio_reg; 2054 2055 if (gpio_num > MISC_REGISTERS_GPIO_3) { 2056 BLOGE(sc, "Invalid GPIO %d mode 0x%x port 0x%x gpio_port %d" 2057 " gpio_shift %d gpio_mask 0x%x\n", 2058 gpio_num, mode, port, gpio_port, gpio_shift, gpio_mask); 2059 return (-1); 2060 } 2061 2062 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO); 2063 2064 /* read GPIO int */ 2065 gpio_reg = REG_RD(sc, MISC_REG_GPIO_INT); 2066 2067 switch (mode) { 2068 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR: 2069 BLOGD(sc, DBG_PHY, 2070 "Clear GPIO INT %d (shift %d) -> output low\n", 2071 gpio_num, gpio_shift); 2072 /* clear SET and set CLR */ 2073 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS); 2074 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS); 2075 break; 2076 2077 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET: 2078 BLOGD(sc, DBG_PHY, 2079 "Set GPIO INT %d (shift %d) -> output high\n", 2080 gpio_num, gpio_shift); 2081 /* clear CLR and set SET */ 2082 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS); 2083 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS); 2084 break; 2085 2086 default: 2087 break; 2088 } 2089 2090 REG_WR(sc, MISC_REG_GPIO_INT, gpio_reg); 2091 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO); 2092 2093 return (0); 2094 } 2095 2096 uint32_t 2097 elink_cb_gpio_read(struct bxe_softc *sc, 2098 uint16_t gpio_num, 2099 uint8_t port) 2100 { 2101 return (bxe_gpio_read(sc, gpio_num, port)); 2102 } 2103 2104 uint8_t 2105 elink_cb_gpio_write(struct bxe_softc *sc, 2106 uint16_t gpio_num, 2107 uint8_t mode, /* 0=low 1=high */ 2108 uint8_t port) 2109 { 2110 return (bxe_gpio_write(sc, gpio_num, mode, port)); 2111 } 2112 2113 uint8_t 2114 elink_cb_gpio_mult_write(struct bxe_softc *sc, 2115 uint8_t pins, 2116 uint8_t mode) /* 0=low 1=high */ 2117 { 2118 return (bxe_gpio_mult_write(sc, pins, mode)); 2119 } 2120 2121 uint8_t 2122 elink_cb_gpio_int_write(struct bxe_softc *sc, 2123 uint16_t gpio_num, 2124 uint8_t mode, /* 0=low 1=high */ 2125 uint8_t port) 2126 { 2127 return (bxe_gpio_int_write(sc, gpio_num, mode, port)); 2128 } 2129 2130 void 2131 elink_cb_notify_link_changed(struct bxe_softc *sc) 2132 { 2133 REG_WR(sc, (MISC_REG_AEU_GENERAL_ATTN_12 + 2134 (SC_FUNC(sc) * sizeof(uint32_t))), 1); 2135 } 2136 2137 /* send the MCP a request, block until there is a reply */ 2138 uint32_t 2139 elink_cb_fw_command(struct bxe_softc *sc, 2140 uint32_t command, 2141 uint32_t param) 2142 { 2143 int mb_idx = SC_FW_MB_IDX(sc); 2144 uint32_t seq; 2145 uint32_t rc = 0; 2146 uint32_t cnt = 1; 2147 uint8_t delay = CHIP_REV_IS_SLOW(sc) ? 100 : 10; 2148 2149 BXE_FWMB_LOCK(sc); 2150 2151 seq = ++sc->fw_seq; 2152 SHMEM_WR(sc, func_mb[mb_idx].drv_mb_param, param); 2153 SHMEM_WR(sc, func_mb[mb_idx].drv_mb_header, (command | seq)); 2154 2155 BLOGD(sc, DBG_PHY, 2156 "wrote command 0x%08x to FW MB param 0x%08x\n", 2157 (command | seq), param); 2158 2159 /* Let the FW do it's magic. GIve it up to 5 seconds... */ 2160 do { 2161 DELAY(delay * 1000); 2162 rc = SHMEM_RD(sc, func_mb[mb_idx].fw_mb_header); 2163 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500)); 2164 2165 BLOGD(sc, DBG_PHY, 2166 "[after %d ms] read 0x%x seq 0x%x from FW MB\n", 2167 cnt*delay, rc, seq); 2168 2169 /* is this a reply to our command? */ 2170 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK)) { 2171 rc &= FW_MSG_CODE_MASK; 2172 } else { 2173 /* Ruh-roh! */ 2174 BLOGE(sc, "FW failed to respond!\n"); 2175 // XXX bxe_fw_dump(sc); 2176 rc = 0; 2177 } 2178 2179 BXE_FWMB_UNLOCK(sc); 2180 return (rc); 2181 } 2182 2183 static uint32_t 2184 bxe_fw_command(struct bxe_softc *sc, 2185 uint32_t command, 2186 uint32_t param) 2187 { 2188 return (elink_cb_fw_command(sc, command, param)); 2189 } 2190 2191 static void 2192 __storm_memset_dma_mapping(struct bxe_softc *sc, 2193 uint32_t addr, 2194 bus_addr_t mapping) 2195 { 2196 REG_WR(sc, addr, U64_LO(mapping)); 2197 REG_WR(sc, (addr + 4), U64_HI(mapping)); 2198 } 2199 2200 static void 2201 storm_memset_spq_addr(struct bxe_softc *sc, 2202 bus_addr_t mapping, 2203 uint16_t abs_fid) 2204 { 2205 uint32_t addr = (XSEM_REG_FAST_MEMORY + 2206 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid)); 2207 __storm_memset_dma_mapping(sc, addr, mapping); 2208 } 2209 2210 static void 2211 storm_memset_vf_to_pf(struct bxe_softc *sc, 2212 uint16_t abs_fid, 2213 uint16_t pf_id) 2214 { 2215 REG_WR8(sc, (BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id); 2216 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id); 2217 REG_WR8(sc, (BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id); 2218 REG_WR8(sc, (BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid)), pf_id); 2219 } 2220 2221 static void 2222 storm_memset_func_en(struct bxe_softc *sc, 2223 uint16_t abs_fid, 2224 uint8_t enable) 2225 { 2226 REG_WR8(sc, (BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid)), enable); 2227 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid)), enable); 2228 REG_WR8(sc, (BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid)), enable); 2229 REG_WR8(sc, (BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid)), enable); 2230 } 2231 2232 static void 2233 storm_memset_eq_data(struct bxe_softc *sc, 2234 struct event_ring_data *eq_data, 2235 uint16_t pfid) 2236 { 2237 uint32_t addr; 2238 size_t size; 2239 2240 addr = (BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid)); 2241 size = sizeof(struct event_ring_data); 2242 ecore_storm_memset_struct(sc, addr, size, (uint32_t *)eq_data); 2243 } 2244 2245 static void 2246 storm_memset_eq_prod(struct bxe_softc *sc, 2247 uint16_t eq_prod, 2248 uint16_t pfid) 2249 { 2250 uint32_t addr = (BAR_CSTRORM_INTMEM + 2251 CSTORM_EVENT_RING_PROD_OFFSET(pfid)); 2252 REG_WR16(sc, addr, eq_prod); 2253 } 2254 2255 /* 2256 * Post a slowpath command. 2257 * 2258 * A slowpath command is used to propagate a configuration change through 2259 * the controller in a controlled manner, allowing each STORM processor and 2260 * other H/W blocks to phase in the change. The commands sent on the 2261 * slowpath are referred to as ramrods. Depending on the ramrod used the 2262 * completion of the ramrod will occur in different ways. Here's a 2263 * breakdown of ramrods and how they complete: 2264 * 2265 * RAMROD_CMD_ID_ETH_PORT_SETUP 2266 * Used to setup the leading connection on a port. Completes on the 2267 * Receive Completion Queue (RCQ) of that port (typically fp[0]). 2268 * 2269 * RAMROD_CMD_ID_ETH_CLIENT_SETUP 2270 * Used to setup an additional connection on a port. Completes on the 2271 * RCQ of the multi-queue/RSS connection being initialized. 2272 * 2273 * RAMROD_CMD_ID_ETH_STAT_QUERY 2274 * Used to force the storm processors to update the statistics database 2275 * in host memory. This ramrod is send on the leading connection CID and 2276 * completes as an index increment of the CSTORM on the default status 2277 * block. 2278 * 2279 * RAMROD_CMD_ID_ETH_UPDATE 2280 * Used to update the state of the leading connection, usually to udpate 2281 * the RSS indirection table. Completes on the RCQ of the leading 2282 * connection. (Not currently used under FreeBSD until OS support becomes 2283 * available.) 2284 * 2285 * RAMROD_CMD_ID_ETH_HALT 2286 * Used when tearing down a connection prior to driver unload. Completes 2287 * on the RCQ of the multi-queue/RSS connection being torn down. Don't 2288 * use this on the leading connection. 2289 * 2290 * RAMROD_CMD_ID_ETH_SET_MAC 2291 * Sets the Unicast/Broadcast/Multicast used by the port. Completes on 2292 * the RCQ of the leading connection. 2293 * 2294 * RAMROD_CMD_ID_ETH_CFC_DEL 2295 * Used when tearing down a conneciton prior to driver unload. Completes 2296 * on the RCQ of the leading connection (since the current connection 2297 * has been completely removed from controller memory). 2298 * 2299 * RAMROD_CMD_ID_ETH_PORT_DEL 2300 * Used to tear down the leading connection prior to driver unload, 2301 * typically fp[0]. Completes as an index increment of the CSTORM on the 2302 * default status block. 2303 * 2304 * RAMROD_CMD_ID_ETH_FORWARD_SETUP 2305 * Used for connection offload. Completes on the RCQ of the multi-queue 2306 * RSS connection that is being offloaded. (Not currently used under 2307 * FreeBSD.) 2308 * 2309 * There can only be one command pending per function. 2310 * 2311 * Returns: 2312 * 0 = Success, !0 = Failure. 2313 */ 2314 2315 /* must be called under the spq lock */ 2316 static inline 2317 struct eth_spe *bxe_sp_get_next(struct bxe_softc *sc) 2318 { 2319 struct eth_spe *next_spe = sc->spq_prod_bd; 2320 2321 if (sc->spq_prod_bd == sc->spq_last_bd) { 2322 /* wrap back to the first eth_spq */ 2323 sc->spq_prod_bd = sc->spq; 2324 sc->spq_prod_idx = 0; 2325 } else { 2326 sc->spq_prod_bd++; 2327 sc->spq_prod_idx++; 2328 } 2329 2330 return (next_spe); 2331 } 2332 2333 /* must be called under the spq lock */ 2334 static inline 2335 void bxe_sp_prod_update(struct bxe_softc *sc) 2336 { 2337 int func = SC_FUNC(sc); 2338 2339 /* 2340 * Make sure that BD data is updated before writing the producer. 2341 * BD data is written to the memory, the producer is read from the 2342 * memory, thus we need a full memory barrier to ensure the ordering. 2343 */ 2344 mb(); 2345 2346 REG_WR16(sc, (BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func)), 2347 sc->spq_prod_idx); 2348 2349 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle, 0, 0, 2350 BUS_SPACE_BARRIER_WRITE); 2351 } 2352 2353 /** 2354 * bxe_is_contextless_ramrod - check if the current command ends on EQ 2355 * 2356 * @cmd: command to check 2357 * @cmd_type: command type 2358 */ 2359 static inline 2360 int bxe_is_contextless_ramrod(int cmd, 2361 int cmd_type) 2362 { 2363 if ((cmd_type == NONE_CONNECTION_TYPE) || 2364 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) || 2365 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) || 2366 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) || 2367 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) || 2368 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) || 2369 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE)) { 2370 return (TRUE); 2371 } else { 2372 return (FALSE); 2373 } 2374 } 2375 2376 /** 2377 * bxe_sp_post - place a single command on an SP ring 2378 * 2379 * @sc: driver handle 2380 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.) 2381 * @cid: SW CID the command is related to 2382 * @data_hi: command private data address (high 32 bits) 2383 * @data_lo: command private data address (low 32 bits) 2384 * @cmd_type: command type (e.g. NONE, ETH) 2385 * 2386 * SP data is handled as if it's always an address pair, thus data fields are 2387 * not swapped to little endian in upper functions. Instead this function swaps 2388 * data as if it's two uint32 fields. 2389 */ 2390 int 2391 bxe_sp_post(struct bxe_softc *sc, 2392 int command, 2393 int cid, 2394 uint32_t data_hi, 2395 uint32_t data_lo, 2396 int cmd_type) 2397 { 2398 struct eth_spe *spe; 2399 uint16_t type; 2400 int common; 2401 2402 common = bxe_is_contextless_ramrod(command, cmd_type); 2403 2404 BXE_SP_LOCK(sc); 2405 2406 if (common) { 2407 if (!atomic_load_acq_long(&sc->eq_spq_left)) { 2408 BLOGE(sc, "EQ ring is full!\n"); 2409 BXE_SP_UNLOCK(sc); 2410 return (-1); 2411 } 2412 } else { 2413 if (!atomic_load_acq_long(&sc->cq_spq_left)) { 2414 BLOGE(sc, "SPQ ring is full!\n"); 2415 BXE_SP_UNLOCK(sc); 2416 return (-1); 2417 } 2418 } 2419 2420 spe = bxe_sp_get_next(sc); 2421 2422 /* CID needs port number to be encoded int it */ 2423 spe->hdr.conn_and_cmd_data = 2424 htole32((command << SPE_HDR_T_CMD_ID_SHIFT) | HW_CID(sc, cid)); 2425 2426 type = (cmd_type << SPE_HDR_T_CONN_TYPE_SHIFT) & SPE_HDR_T_CONN_TYPE; 2427 2428 /* TBD: Check if it works for VFs */ 2429 type |= ((SC_FUNC(sc) << SPE_HDR_T_FUNCTION_ID_SHIFT) & 2430 SPE_HDR_T_FUNCTION_ID); 2431 2432 spe->hdr.type = htole16(type); 2433 2434 spe->data.update_data_addr.hi = htole32(data_hi); 2435 spe->data.update_data_addr.lo = htole32(data_lo); 2436 2437 /* 2438 * It's ok if the actual decrement is issued towards the memory 2439 * somewhere between the lock and unlock. Thus no more explict 2440 * memory barrier is needed. 2441 */ 2442 if (common) { 2443 atomic_subtract_acq_long(&sc->eq_spq_left, 1); 2444 } else { 2445 atomic_subtract_acq_long(&sc->cq_spq_left, 1); 2446 } 2447 2448 BLOGD(sc, DBG_SP, "SPQE -> %#jx\n", (uintmax_t)sc->spq_dma.paddr); 2449 BLOGD(sc, DBG_SP, "FUNC_RDATA -> %p / %#jx\n", 2450 BXE_SP(sc, func_rdata), (uintmax_t)BXE_SP_MAPPING(sc, func_rdata)); 2451 BLOGD(sc, DBG_SP, 2452 "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%lx,%lx)\n", 2453 sc->spq_prod_idx, 2454 (uint32_t)U64_HI(sc->spq_dma.paddr), 2455 (uint32_t)(U64_LO(sc->spq_dma.paddr) + (uint8_t *)sc->spq_prod_bd - (uint8_t *)sc->spq), 2456 command, 2457 common, 2458 HW_CID(sc, cid), 2459 data_hi, 2460 data_lo, 2461 type, 2462 atomic_load_acq_long(&sc->cq_spq_left), 2463 atomic_load_acq_long(&sc->eq_spq_left)); 2464 2465 bxe_sp_prod_update(sc); 2466 2467 BXE_SP_UNLOCK(sc); 2468 return (0); 2469 } 2470 2471 /** 2472 * bxe_debug_print_ind_table - prints the indirection table configuration. 2473 * 2474 * @sc: driver hanlde 2475 * @p: pointer to rss configuration 2476 */ 2477 2478 /* 2479 * FreeBSD Device probe function. 2480 * 2481 * Compares the device found to the driver's list of supported devices and 2482 * reports back to the bsd loader whether this is the right driver for the device. 2483 * This is the driver entry function called from the "kldload" command. 2484 * 2485 * Returns: 2486 * BUS_PROBE_DEFAULT on success, positive value on failure. 2487 */ 2488 static int 2489 bxe_probe(device_t dev) 2490 { 2491 struct bxe_device_type *t; 2492 uint16_t did, sdid, svid, vid; 2493 2494 /* Find our device structure */ 2495 t = bxe_devs; 2496 2497 /* Get the data for the device to be probed. */ 2498 vid = pci_get_vendor(dev); 2499 did = pci_get_device(dev); 2500 svid = pci_get_subvendor(dev); 2501 sdid = pci_get_subdevice(dev); 2502 2503 /* Look through the list of known devices for a match. */ 2504 while (t->bxe_name != NULL) { 2505 if ((vid == t->bxe_vid) && (did == t->bxe_did) && 2506 ((svid == t->bxe_svid) || (t->bxe_svid == PCI_ANY_ID)) && 2507 ((sdid == t->bxe_sdid) || (t->bxe_sdid == PCI_ANY_ID))) { 2508 device_set_descf(dev, 2509 "%s (%c%d) BXE v:%s", t->bxe_name, 2510 (((pci_read_config(dev, PCIR_REVID, 4) & 2511 0xf0) >> 4) + 'A'), 2512 (pci_read_config(dev, PCIR_REVID, 4) & 0xf), 2513 BXE_DRIVER_VERSION); 2514 return (BUS_PROBE_DEFAULT); 2515 } 2516 t++; 2517 } 2518 2519 return (ENXIO); 2520 } 2521 2522 static void 2523 bxe_init_mutexes(struct bxe_softc *sc) 2524 { 2525 #ifdef BXE_CORE_LOCK_SX 2526 snprintf(sc->core_sx_name, sizeof(sc->core_sx_name), 2527 "bxe%d_core_lock", sc->unit); 2528 sx_init(&sc->core_sx, sc->core_sx_name); 2529 #else 2530 snprintf(sc->core_mtx_name, sizeof(sc->core_mtx_name), 2531 "bxe%d_core_lock", sc->unit); 2532 mtx_init(&sc->core_mtx, sc->core_mtx_name, NULL, MTX_DEF); 2533 #endif 2534 2535 snprintf(sc->sp_mtx_name, sizeof(sc->sp_mtx_name), 2536 "bxe%d_sp_lock", sc->unit); 2537 mtx_init(&sc->sp_mtx, sc->sp_mtx_name, NULL, MTX_DEF); 2538 2539 snprintf(sc->dmae_mtx_name, sizeof(sc->dmae_mtx_name), 2540 "bxe%d_dmae_lock", sc->unit); 2541 mtx_init(&sc->dmae_mtx, sc->dmae_mtx_name, NULL, MTX_DEF); 2542 2543 snprintf(sc->port.phy_mtx_name, sizeof(sc->port.phy_mtx_name), 2544 "bxe%d_phy_lock", sc->unit); 2545 mtx_init(&sc->port.phy_mtx, sc->port.phy_mtx_name, NULL, MTX_DEF); 2546 2547 snprintf(sc->fwmb_mtx_name, sizeof(sc->fwmb_mtx_name), 2548 "bxe%d_fwmb_lock", sc->unit); 2549 mtx_init(&sc->fwmb_mtx, sc->fwmb_mtx_name, NULL, MTX_DEF); 2550 2551 snprintf(sc->print_mtx_name, sizeof(sc->print_mtx_name), 2552 "bxe%d_print_lock", sc->unit); 2553 mtx_init(&(sc->print_mtx), sc->print_mtx_name, NULL, MTX_DEF); 2554 2555 snprintf(sc->stats_mtx_name, sizeof(sc->stats_mtx_name), 2556 "bxe%d_stats_lock", sc->unit); 2557 mtx_init(&(sc->stats_mtx), sc->stats_mtx_name, NULL, MTX_DEF); 2558 2559 snprintf(sc->mcast_mtx_name, sizeof(sc->mcast_mtx_name), 2560 "bxe%d_mcast_lock", sc->unit); 2561 mtx_init(&(sc->mcast_mtx), sc->mcast_mtx_name, NULL, MTX_DEF); 2562 } 2563 2564 static void 2565 bxe_release_mutexes(struct bxe_softc *sc) 2566 { 2567 #ifdef BXE_CORE_LOCK_SX 2568 sx_destroy(&sc->core_sx); 2569 #else 2570 if (mtx_initialized(&sc->core_mtx)) { 2571 mtx_destroy(&sc->core_mtx); 2572 } 2573 #endif 2574 2575 if (mtx_initialized(&sc->sp_mtx)) { 2576 mtx_destroy(&sc->sp_mtx); 2577 } 2578 2579 if (mtx_initialized(&sc->dmae_mtx)) { 2580 mtx_destroy(&sc->dmae_mtx); 2581 } 2582 2583 if (mtx_initialized(&sc->port.phy_mtx)) { 2584 mtx_destroy(&sc->port.phy_mtx); 2585 } 2586 2587 if (mtx_initialized(&sc->fwmb_mtx)) { 2588 mtx_destroy(&sc->fwmb_mtx); 2589 } 2590 2591 if (mtx_initialized(&sc->print_mtx)) { 2592 mtx_destroy(&sc->print_mtx); 2593 } 2594 2595 if (mtx_initialized(&sc->stats_mtx)) { 2596 mtx_destroy(&sc->stats_mtx); 2597 } 2598 2599 if (mtx_initialized(&sc->mcast_mtx)) { 2600 mtx_destroy(&sc->mcast_mtx); 2601 } 2602 } 2603 2604 static void 2605 bxe_tx_disable(struct bxe_softc* sc) 2606 { 2607 if_t ifp = sc->ifp; 2608 2609 /* tell the stack the driver is stopped and TX queue is full */ 2610 if (ifp != NULL) { 2611 if_setdrvflags(ifp, 0); 2612 } 2613 } 2614 2615 static void 2616 bxe_drv_pulse(struct bxe_softc *sc) 2617 { 2618 SHMEM_WR(sc, func_mb[SC_FW_MB_IDX(sc)].drv_pulse_mb, 2619 sc->fw_drv_pulse_wr_seq); 2620 } 2621 2622 static inline uint16_t 2623 bxe_tx_avail(struct bxe_softc *sc, 2624 struct bxe_fastpath *fp) 2625 { 2626 int16_t used; 2627 uint16_t prod; 2628 uint16_t cons; 2629 2630 prod = fp->tx_bd_prod; 2631 cons = fp->tx_bd_cons; 2632 2633 used = SUB_S16(prod, cons); 2634 2635 return (int16_t)(sc->tx_ring_size) - used; 2636 } 2637 2638 static inline int 2639 bxe_tx_queue_has_work(struct bxe_fastpath *fp) 2640 { 2641 uint16_t hw_cons; 2642 2643 mb(); /* status block fields can change */ 2644 hw_cons = le16toh(*fp->tx_cons_sb); 2645 return (hw_cons != fp->tx_pkt_cons); 2646 } 2647 2648 static inline uint8_t 2649 bxe_has_tx_work(struct bxe_fastpath *fp) 2650 { 2651 /* expand this for multi-cos if ever supported */ 2652 return (bxe_tx_queue_has_work(fp)) ? TRUE : FALSE; 2653 } 2654 2655 static inline int 2656 bxe_has_rx_work(struct bxe_fastpath *fp) 2657 { 2658 uint16_t rx_cq_cons_sb; 2659 2660 mb(); /* status block fields can change */ 2661 rx_cq_cons_sb = le16toh(*fp->rx_cq_cons_sb); 2662 if ((rx_cq_cons_sb & RCQ_MAX) == RCQ_MAX) 2663 rx_cq_cons_sb++; 2664 return (fp->rx_cq_cons != rx_cq_cons_sb); 2665 } 2666 2667 static void 2668 bxe_sp_event(struct bxe_softc *sc, 2669 struct bxe_fastpath *fp, 2670 union eth_rx_cqe *rr_cqe) 2671 { 2672 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data); 2673 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data); 2674 enum ecore_queue_cmd drv_cmd = ECORE_Q_CMD_MAX; 2675 struct ecore_queue_sp_obj *q_obj = &BXE_SP_OBJ(sc, fp).q_obj; 2676 2677 BLOGD(sc, DBG_SP, "fp=%d cid=%d got ramrod #%d state is %x type is %d\n", 2678 fp->index, cid, command, sc->state, rr_cqe->ramrod_cqe.ramrod_type); 2679 2680 switch (command) { 2681 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE): 2682 BLOGD(sc, DBG_SP, "got UPDATE ramrod. CID %d\n", cid); 2683 drv_cmd = ECORE_Q_CMD_UPDATE; 2684 break; 2685 2686 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP): 2687 BLOGD(sc, DBG_SP, "got MULTI[%d] setup ramrod\n", cid); 2688 drv_cmd = ECORE_Q_CMD_SETUP; 2689 break; 2690 2691 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP): 2692 BLOGD(sc, DBG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid); 2693 drv_cmd = ECORE_Q_CMD_SETUP_TX_ONLY; 2694 break; 2695 2696 case (RAMROD_CMD_ID_ETH_HALT): 2697 BLOGD(sc, DBG_SP, "got MULTI[%d] halt ramrod\n", cid); 2698 drv_cmd = ECORE_Q_CMD_HALT; 2699 break; 2700 2701 case (RAMROD_CMD_ID_ETH_TERMINATE): 2702 BLOGD(sc, DBG_SP, "got MULTI[%d] teminate ramrod\n", cid); 2703 drv_cmd = ECORE_Q_CMD_TERMINATE; 2704 break; 2705 2706 case (RAMROD_CMD_ID_ETH_EMPTY): 2707 BLOGD(sc, DBG_SP, "got MULTI[%d] empty ramrod\n", cid); 2708 drv_cmd = ECORE_Q_CMD_EMPTY; 2709 break; 2710 2711 default: 2712 BLOGD(sc, DBG_SP, "ERROR: unexpected MC reply (%d) on fp[%d]\n", 2713 command, fp->index); 2714 return; 2715 } 2716 2717 if ((drv_cmd != ECORE_Q_CMD_MAX) && 2718 q_obj->complete_cmd(sc, q_obj, drv_cmd)) { 2719 /* 2720 * q_obj->complete_cmd() failure means that this was 2721 * an unexpected completion. 2722 * 2723 * In this case we don't want to increase the sc->spq_left 2724 * because apparently we haven't sent this command the first 2725 * place. 2726 */ 2727 // bxe_panic(sc, ("Unexpected SP completion\n")); 2728 return; 2729 } 2730 2731 atomic_add_acq_long(&sc->cq_spq_left, 1); 2732 2733 BLOGD(sc, DBG_SP, "sc->cq_spq_left 0x%lx\n", 2734 atomic_load_acq_long(&sc->cq_spq_left)); 2735 } 2736 2737 /* 2738 * The current mbuf is part of an aggregation. Move the mbuf into the TPA 2739 * aggregation queue, put an empty mbuf back onto the receive chain, and mark 2740 * the current aggregation queue as in-progress. 2741 */ 2742 static void 2743 bxe_tpa_start(struct bxe_softc *sc, 2744 struct bxe_fastpath *fp, 2745 uint16_t queue, 2746 uint16_t cons, 2747 uint16_t prod, 2748 struct eth_fast_path_rx_cqe *cqe) 2749 { 2750 struct bxe_sw_rx_bd tmp_bd; 2751 struct bxe_sw_rx_bd *rx_buf; 2752 struct eth_rx_bd *rx_bd; 2753 int max_agg_queues __diagused; 2754 struct bxe_sw_tpa_info *tpa_info = &fp->rx_tpa_info[queue]; 2755 uint16_t index; 2756 2757 BLOGD(sc, DBG_LRO, "fp[%02d].tpa[%02d] TPA START " 2758 "cons=%d prod=%d\n", 2759 fp->index, queue, cons, prod); 2760 2761 max_agg_queues = MAX_AGG_QS(sc); 2762 2763 KASSERT((queue < max_agg_queues), 2764 ("fp[%02d] invalid aggr queue (%d >= %d)!", 2765 fp->index, queue, max_agg_queues)); 2766 2767 KASSERT((tpa_info->state == BXE_TPA_STATE_STOP), 2768 ("fp[%02d].tpa[%02d] starting aggr on queue not stopped!", 2769 fp->index, queue)); 2770 2771 /* copy the existing mbuf and mapping from the TPA pool */ 2772 tmp_bd = tpa_info->bd; 2773 2774 if (tmp_bd.m == NULL) { 2775 uint32_t *tmp; 2776 2777 tmp = (uint32_t *)cqe; 2778 2779 BLOGE(sc, "fp[%02d].tpa[%02d] cons[%d] prod[%d]mbuf not allocated!\n", 2780 fp->index, queue, cons, prod); 2781 BLOGE(sc, "cqe [0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x]\n", 2782 *tmp, *(tmp+1), *(tmp+2), *(tmp+3), *(tmp+4), *(tmp+5), *(tmp+6), *(tmp+7)); 2783 2784 /* XXX Error handling? */ 2785 return; 2786 } 2787 2788 /* change the TPA queue to the start state */ 2789 tpa_info->state = BXE_TPA_STATE_START; 2790 tpa_info->placement_offset = cqe->placement_offset; 2791 tpa_info->parsing_flags = le16toh(cqe->pars_flags.flags); 2792 tpa_info->vlan_tag = le16toh(cqe->vlan_tag); 2793 tpa_info->len_on_bd = le16toh(cqe->len_on_bd); 2794 2795 fp->rx_tpa_queue_used |= (1 << queue); 2796 2797 /* 2798 * If all the buffer descriptors are filled with mbufs then fill in 2799 * the current consumer index with a new BD. Else if a maximum Rx 2800 * buffer limit is imposed then fill in the next producer index. 2801 */ 2802 index = (sc->max_rx_bufs != RX_BD_USABLE) ? 2803 prod : cons; 2804 2805 /* move the received mbuf and mapping to TPA pool */ 2806 tpa_info->bd = fp->rx_mbuf_chain[cons]; 2807 2808 /* release any existing RX BD mbuf mappings */ 2809 if (cons != index) { 2810 rx_buf = &fp->rx_mbuf_chain[cons]; 2811 2812 if (rx_buf->m_map != NULL) { 2813 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map, 2814 BUS_DMASYNC_POSTREAD); 2815 bus_dmamap_unload(fp->rx_mbuf_tag, rx_buf->m_map); 2816 } 2817 2818 /* 2819 * We get here when the maximum number of rx buffers is less than 2820 * RX_BD_USABLE. The mbuf is already saved above so it's OK to NULL 2821 * it out here without concern of a memory leak. 2822 */ 2823 fp->rx_mbuf_chain[cons].m = NULL; 2824 } 2825 2826 /* update the Rx SW BD with the mbuf info from the TPA pool */ 2827 fp->rx_mbuf_chain[index] = tmp_bd; 2828 2829 /* update the Rx BD with the empty mbuf phys address from the TPA pool */ 2830 rx_bd = &fp->rx_chain[index]; 2831 rx_bd->addr_hi = htole32(U64_HI(tpa_info->seg.ds_addr)); 2832 rx_bd->addr_lo = htole32(U64_LO(tpa_info->seg.ds_addr)); 2833 } 2834 2835 /* 2836 * When a TPA aggregation is completed, loop through the individual mbufs 2837 * of the aggregation, combining them into a single mbuf which will be sent 2838 * up the stack. Refill all freed SGEs with mbufs as we go along. 2839 */ 2840 static int 2841 bxe_fill_frag_mbuf(struct bxe_softc *sc, 2842 struct bxe_fastpath *fp, 2843 struct bxe_sw_tpa_info *tpa_info, 2844 uint16_t queue, 2845 uint16_t pages, 2846 struct mbuf *m, 2847 struct eth_end_agg_rx_cqe *cqe, 2848 uint16_t cqe_idx) 2849 { 2850 struct mbuf *m_frag; 2851 uint32_t frag_len, frag_size, i; 2852 uint16_t sge_idx; 2853 int rc = 0; 2854 int j; 2855 2856 frag_size = le16toh(cqe->pkt_len) - tpa_info->len_on_bd; 2857 2858 BLOGD(sc, DBG_LRO, 2859 "fp[%02d].tpa[%02d] TPA fill len_on_bd=%d frag_size=%d pages=%d\n", 2860 fp->index, queue, tpa_info->len_on_bd, frag_size, pages); 2861 2862 /* make sure the aggregated frame is not too big to handle */ 2863 if (pages > 8 * PAGES_PER_SGE) { 2864 2865 uint32_t *tmp = (uint32_t *)cqe; 2866 2867 BLOGE(sc, "fp[%02d].sge[0x%04x] has too many pages (%d)! " 2868 "pkt_len=%d len_on_bd=%d frag_size=%d\n", 2869 fp->index, cqe_idx, pages, le16toh(cqe->pkt_len), 2870 tpa_info->len_on_bd, frag_size); 2871 2872 BLOGE(sc, "cqe [0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x]\n", 2873 *tmp, *(tmp+1), *(tmp+2), *(tmp+3), *(tmp+4), *(tmp+5), *(tmp+6), *(tmp+7)); 2874 2875 bxe_panic(sc, ("sge page count error\n")); 2876 return (EINVAL); 2877 } 2878 2879 /* 2880 * Scan through the scatter gather list pulling individual mbufs into a 2881 * single mbuf for the host stack. 2882 */ 2883 for (i = 0, j = 0; i < pages; i += PAGES_PER_SGE, j++) { 2884 sge_idx = RX_SGE(le16toh(cqe->sgl_or_raw_data.sgl[j])); 2885 2886 /* 2887 * Firmware gives the indices of the SGE as if the ring is an array 2888 * (meaning that the "next" element will consume 2 indices). 2889 */ 2890 frag_len = min(frag_size, (uint32_t)(SGE_PAGES)); 2891 2892 BLOGD(sc, DBG_LRO, "fp[%02d].tpa[%02d] TPA fill i=%d j=%d " 2893 "sge_idx=%d frag_size=%d frag_len=%d\n", 2894 fp->index, queue, i, j, sge_idx, frag_size, frag_len); 2895 2896 m_frag = fp->rx_sge_mbuf_chain[sge_idx].m; 2897 2898 /* allocate a new mbuf for the SGE */ 2899 rc = bxe_alloc_rx_sge_mbuf(fp, sge_idx); 2900 if (rc) { 2901 /* Leave all remaining SGEs in the ring! */ 2902 return (rc); 2903 } 2904 2905 /* update the fragment length */ 2906 m_frag->m_len = frag_len; 2907 2908 /* concatenate the fragment to the head mbuf */ 2909 m_cat(m, m_frag); 2910 fp->eth_q_stats.mbuf_alloc_sge--; 2911 2912 /* update the TPA mbuf size and remaining fragment size */ 2913 m->m_pkthdr.len += frag_len; 2914 frag_size -= frag_len; 2915 } 2916 2917 BLOGD(sc, DBG_LRO, 2918 "fp[%02d].tpa[%02d] TPA fill done frag_size=%d\n", 2919 fp->index, queue, frag_size); 2920 2921 return (rc); 2922 } 2923 2924 static inline void 2925 bxe_clear_sge_mask_next_elems(struct bxe_fastpath *fp) 2926 { 2927 int i, j; 2928 2929 for (i = 1; i <= RX_SGE_NUM_PAGES; i++) { 2930 int idx = RX_SGE_TOTAL_PER_PAGE * i - 1; 2931 2932 for (j = 0; j < 2; j++) { 2933 BIT_VEC64_CLEAR_BIT(fp->sge_mask, idx); 2934 idx--; 2935 } 2936 } 2937 } 2938 2939 static inline void 2940 bxe_init_sge_ring_bit_mask(struct bxe_fastpath *fp) 2941 { 2942 /* set the mask to all 1's, it's faster to compare to 0 than to 0xf's */ 2943 memset(fp->sge_mask, 0xff, sizeof(fp->sge_mask)); 2944 2945 /* 2946 * Clear the two last indices in the page to 1. These are the indices that 2947 * correspond to the "next" element, hence will never be indicated and 2948 * should be removed from the calculations. 2949 */ 2950 bxe_clear_sge_mask_next_elems(fp); 2951 } 2952 2953 static inline void 2954 bxe_update_last_max_sge(struct bxe_fastpath *fp, 2955 uint16_t idx) 2956 { 2957 uint16_t last_max = fp->last_max_sge; 2958 2959 if (SUB_S16(idx, last_max) > 0) { 2960 fp->last_max_sge = idx; 2961 } 2962 } 2963 2964 static inline void 2965 bxe_update_sge_prod(struct bxe_softc *sc, 2966 struct bxe_fastpath *fp, 2967 uint16_t sge_len, 2968 union eth_sgl_or_raw_data *cqe) 2969 { 2970 uint16_t last_max, last_elem, first_elem; 2971 uint16_t delta = 0; 2972 uint16_t i; 2973 2974 if (!sge_len) { 2975 return; 2976 } 2977 2978 /* first mark all used pages */ 2979 for (i = 0; i < sge_len; i++) { 2980 BIT_VEC64_CLEAR_BIT(fp->sge_mask, 2981 RX_SGE(le16toh(cqe->sgl[i]))); 2982 } 2983 2984 BLOGD(sc, DBG_LRO, 2985 "fp[%02d] fp_cqe->sgl[%d] = %d\n", 2986 fp->index, sge_len - 1, 2987 le16toh(cqe->sgl[sge_len - 1])); 2988 2989 /* assume that the last SGE index is the biggest */ 2990 bxe_update_last_max_sge(fp, 2991 le16toh(cqe->sgl[sge_len - 1])); 2992 2993 last_max = RX_SGE(fp->last_max_sge); 2994 last_elem = last_max >> BIT_VEC64_ELEM_SHIFT; 2995 first_elem = RX_SGE(fp->rx_sge_prod) >> BIT_VEC64_ELEM_SHIFT; 2996 2997 /* if ring is not full */ 2998 if (last_elem + 1 != first_elem) { 2999 last_elem++; 3000 } 3001 3002 /* now update the prod */ 3003 for (i = first_elem; i != last_elem; i = RX_SGE_NEXT_MASK_ELEM(i)) { 3004 if (__predict_true(fp->sge_mask[i])) { 3005 break; 3006 } 3007 3008 fp->sge_mask[i] = BIT_VEC64_ELEM_ONE_MASK; 3009 delta += BIT_VEC64_ELEM_SZ; 3010 } 3011 3012 if (delta > 0) { 3013 fp->rx_sge_prod += delta; 3014 /* clear page-end entries */ 3015 bxe_clear_sge_mask_next_elems(fp); 3016 } 3017 3018 BLOGD(sc, DBG_LRO, 3019 "fp[%02d] fp->last_max_sge=%d fp->rx_sge_prod=%d\n", 3020 fp->index, fp->last_max_sge, fp->rx_sge_prod); 3021 } 3022 3023 /* 3024 * The aggregation on the current TPA queue has completed. Pull the individual 3025 * mbuf fragments together into a single mbuf, perform all necessary checksum 3026 * calculations, and send the resuting mbuf to the stack. 3027 */ 3028 static void 3029 bxe_tpa_stop(struct bxe_softc *sc, 3030 struct bxe_fastpath *fp, 3031 struct bxe_sw_tpa_info *tpa_info, 3032 uint16_t queue, 3033 uint16_t pages, 3034 struct eth_end_agg_rx_cqe *cqe, 3035 uint16_t cqe_idx) 3036 { 3037 if_t ifp = sc->ifp; 3038 struct mbuf *m; 3039 int rc = 0; 3040 3041 BLOGD(sc, DBG_LRO, 3042 "fp[%02d].tpa[%02d] pad=%d pkt_len=%d pages=%d vlan=%d\n", 3043 fp->index, queue, tpa_info->placement_offset, 3044 le16toh(cqe->pkt_len), pages, tpa_info->vlan_tag); 3045 3046 m = tpa_info->bd.m; 3047 3048 /* allocate a replacement before modifying existing mbuf */ 3049 rc = bxe_alloc_rx_tpa_mbuf(fp, queue); 3050 if (rc) { 3051 /* drop the frame and log an error */ 3052 fp->eth_q_stats.rx_soft_errors++; 3053 goto bxe_tpa_stop_exit; 3054 } 3055 3056 /* we have a replacement, fixup the current mbuf */ 3057 m_adj(m, tpa_info->placement_offset); 3058 m->m_pkthdr.len = m->m_len = tpa_info->len_on_bd; 3059 3060 /* mark the checksums valid (taken care of by the firmware) */ 3061 fp->eth_q_stats.rx_ofld_frames_csum_ip++; 3062 fp->eth_q_stats.rx_ofld_frames_csum_tcp_udp++; 3063 m->m_pkthdr.csum_data = 0xffff; 3064 m->m_pkthdr.csum_flags |= (CSUM_IP_CHECKED | 3065 CSUM_IP_VALID | 3066 CSUM_DATA_VALID | 3067 CSUM_PSEUDO_HDR); 3068 3069 /* aggregate all of the SGEs into a single mbuf */ 3070 rc = bxe_fill_frag_mbuf(sc, fp, tpa_info, queue, pages, m, cqe, cqe_idx); 3071 if (rc) { 3072 /* drop the packet and log an error */ 3073 fp->eth_q_stats.rx_soft_errors++; 3074 m_freem(m); 3075 } else { 3076 if (tpa_info->parsing_flags & PARSING_FLAGS_INNER_VLAN_EXIST) { 3077 m->m_pkthdr.ether_vtag = tpa_info->vlan_tag; 3078 m->m_flags |= M_VLANTAG; 3079 } 3080 3081 /* assign packet to this interface interface */ 3082 if_setrcvif(m, ifp); 3083 3084 /* specify what RSS queue was used for this flow */ 3085 m->m_pkthdr.flowid = fp->index; 3086 BXE_SET_FLOWID(m); 3087 3088 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1); 3089 fp->eth_q_stats.rx_tpa_pkts++; 3090 3091 /* pass the frame to the stack */ 3092 if_input(ifp, m); 3093 } 3094 3095 /* we passed an mbuf up the stack or dropped the frame */ 3096 fp->eth_q_stats.mbuf_alloc_tpa--; 3097 3098 bxe_tpa_stop_exit: 3099 3100 fp->rx_tpa_info[queue].state = BXE_TPA_STATE_STOP; 3101 fp->rx_tpa_queue_used &= ~(1 << queue); 3102 } 3103 3104 static uint8_t 3105 bxe_service_rxsgl( 3106 struct bxe_fastpath *fp, 3107 uint16_t len, 3108 uint16_t lenonbd, 3109 struct mbuf *m, 3110 struct eth_fast_path_rx_cqe *cqe_fp) 3111 { 3112 struct mbuf *m_frag; 3113 uint16_t frags, frag_len; 3114 uint16_t sge_idx = 0; 3115 uint16_t j; 3116 uint8_t i, rc = 0; 3117 uint32_t frag_size; 3118 3119 /* adjust the mbuf */ 3120 m->m_len = lenonbd; 3121 3122 frag_size = len - lenonbd; 3123 frags = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT; 3124 3125 for (i = 0, j = 0; i < frags; i += PAGES_PER_SGE, j++) { 3126 sge_idx = RX_SGE(le16toh(cqe_fp->sgl_or_raw_data.sgl[j])); 3127 3128 m_frag = fp->rx_sge_mbuf_chain[sge_idx].m; 3129 frag_len = min(frag_size, (uint32_t)(SGE_PAGE_SIZE)); 3130 m_frag->m_len = frag_len; 3131 3132 /* allocate a new mbuf for the SGE */ 3133 rc = bxe_alloc_rx_sge_mbuf(fp, sge_idx); 3134 if (rc) { 3135 /* Leave all remaining SGEs in the ring! */ 3136 return (rc); 3137 } 3138 fp->eth_q_stats.mbuf_alloc_sge--; 3139 3140 /* concatenate the fragment to the head mbuf */ 3141 m_cat(m, m_frag); 3142 3143 frag_size -= frag_len; 3144 } 3145 3146 bxe_update_sge_prod(fp->sc, fp, frags, &cqe_fp->sgl_or_raw_data); 3147 3148 return rc; 3149 } 3150 3151 static uint8_t 3152 bxe_rxeof(struct bxe_softc *sc, 3153 struct bxe_fastpath *fp) 3154 { 3155 if_t ifp = sc->ifp; 3156 uint16_t bd_cons, bd_prod, bd_prod_fw, comp_ring_cons; 3157 uint16_t hw_cq_cons, sw_cq_cons, sw_cq_prod; 3158 int rx_pkts = 0; 3159 int rc = 0; 3160 3161 BXE_FP_RX_LOCK(fp); 3162 3163 /* CQ "next element" is of the size of the regular element */ 3164 hw_cq_cons = le16toh(*fp->rx_cq_cons_sb); 3165 if ((hw_cq_cons & RCQ_USABLE_PER_PAGE) == RCQ_USABLE_PER_PAGE) { 3166 hw_cq_cons++; 3167 } 3168 3169 bd_cons = fp->rx_bd_cons; 3170 bd_prod = fp->rx_bd_prod; 3171 bd_prod_fw = bd_prod; 3172 sw_cq_cons = fp->rx_cq_cons; 3173 sw_cq_prod = fp->rx_cq_prod; 3174 3175 /* 3176 * Memory barrier necessary as speculative reads of the rx 3177 * buffer can be ahead of the index in the status block 3178 */ 3179 rmb(); 3180 3181 BLOGD(sc, DBG_RX, 3182 "fp[%02d] Rx START hw_cq_cons=%u sw_cq_cons=%u\n", 3183 fp->index, hw_cq_cons, sw_cq_cons); 3184 3185 while (sw_cq_cons != hw_cq_cons) { 3186 struct bxe_sw_rx_bd *rx_buf = NULL; 3187 union eth_rx_cqe *cqe; 3188 struct eth_fast_path_rx_cqe *cqe_fp; 3189 uint8_t cqe_fp_flags; 3190 enum eth_rx_cqe_type cqe_fp_type; 3191 uint16_t len, lenonbd, pad; 3192 struct mbuf *m = NULL; 3193 3194 comp_ring_cons = RCQ(sw_cq_cons); 3195 bd_prod = RX_BD(bd_prod); 3196 bd_cons = RX_BD(bd_cons); 3197 3198 cqe = &fp->rcq_chain[comp_ring_cons]; 3199 cqe_fp = &cqe->fast_path_cqe; 3200 cqe_fp_flags = cqe_fp->type_error_flags; 3201 cqe_fp_type = cqe_fp_flags & ETH_FAST_PATH_RX_CQE_TYPE; 3202 3203 BLOGD(sc, DBG_RX, 3204 "fp[%02d] Rx hw_cq_cons=%d hw_sw_cons=%d " 3205 "BD prod=%d cons=%d CQE type=0x%x err=0x%x " 3206 "status=0x%x rss_hash=0x%x vlan=0x%x len=%u lenonbd=%u\n", 3207 fp->index, 3208 hw_cq_cons, 3209 sw_cq_cons, 3210 bd_prod, 3211 bd_cons, 3212 CQE_TYPE(cqe_fp_flags), 3213 cqe_fp_flags, 3214 cqe_fp->status_flags, 3215 le32toh(cqe_fp->rss_hash_result), 3216 le16toh(cqe_fp->vlan_tag), 3217 le16toh(cqe_fp->pkt_len_or_gro_seg_len), 3218 le16toh(cqe_fp->len_on_bd)); 3219 3220 /* is this a slowpath msg? */ 3221 if (__predict_false(CQE_TYPE_SLOW(cqe_fp_type))) { 3222 bxe_sp_event(sc, fp, cqe); 3223 goto next_cqe; 3224 } 3225 3226 rx_buf = &fp->rx_mbuf_chain[bd_cons]; 3227 3228 if (!CQE_TYPE_FAST(cqe_fp_type)) { 3229 struct bxe_sw_tpa_info *tpa_info; 3230 uint16_t frag_size, pages; 3231 uint8_t queue; 3232 3233 if (CQE_TYPE_START(cqe_fp_type)) { 3234 bxe_tpa_start(sc, fp, cqe_fp->queue_index, 3235 bd_cons, bd_prod, cqe_fp); 3236 m = NULL; /* packet not ready yet */ 3237 goto next_rx; 3238 } 3239 3240 KASSERT(CQE_TYPE_STOP(cqe_fp_type), 3241 ("CQE type is not STOP! (0x%x)\n", cqe_fp_type)); 3242 3243 queue = cqe->end_agg_cqe.queue_index; 3244 tpa_info = &fp->rx_tpa_info[queue]; 3245 3246 BLOGD(sc, DBG_LRO, "fp[%02d].tpa[%02d] TPA STOP\n", 3247 fp->index, queue); 3248 3249 frag_size = (le16toh(cqe->end_agg_cqe.pkt_len) - 3250 tpa_info->len_on_bd); 3251 pages = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT; 3252 3253 bxe_tpa_stop(sc, fp, tpa_info, queue, pages, 3254 &cqe->end_agg_cqe, comp_ring_cons); 3255 3256 bxe_update_sge_prod(sc, fp, pages, &cqe->end_agg_cqe.sgl_or_raw_data); 3257 3258 goto next_cqe; 3259 } 3260 3261 /* non TPA */ 3262 3263 /* is this an error packet? */ 3264 if (__predict_false(cqe_fp_flags & 3265 ETH_FAST_PATH_RX_CQE_PHY_DECODE_ERR_FLG)) { 3266 BLOGE(sc, "flags 0x%x rx packet %u\n", cqe_fp_flags, sw_cq_cons); 3267 fp->eth_q_stats.rx_soft_errors++; 3268 goto next_rx; 3269 } 3270 3271 len = le16toh(cqe_fp->pkt_len_or_gro_seg_len); 3272 lenonbd = le16toh(cqe_fp->len_on_bd); 3273 pad = cqe_fp->placement_offset; 3274 3275 m = rx_buf->m; 3276 3277 if (__predict_false(m == NULL)) { 3278 BLOGE(sc, "No mbuf in rx chain descriptor %d for fp[%02d]\n", 3279 bd_cons, fp->index); 3280 goto next_rx; 3281 } 3282 3283 /* XXX double copy if packet length under a threshold */ 3284 3285 /* 3286 * If all the buffer descriptors are filled with mbufs then fill in 3287 * the current consumer index with a new BD. Else if a maximum Rx 3288 * buffer limit is imposed then fill in the next producer index. 3289 */ 3290 rc = bxe_alloc_rx_bd_mbuf(fp, bd_cons, 3291 (sc->max_rx_bufs != RX_BD_USABLE) ? 3292 bd_prod : bd_cons); 3293 if (rc != 0) { 3294 3295 /* we simply reuse the received mbuf and don't post it to the stack */ 3296 m = NULL; 3297 3298 BLOGE(sc, "mbuf alloc fail for fp[%02d] rx chain (%d)\n", 3299 fp->index, rc); 3300 fp->eth_q_stats.rx_soft_errors++; 3301 3302 if (sc->max_rx_bufs != RX_BD_USABLE) { 3303 /* copy this consumer index to the producer index */ 3304 memcpy(&fp->rx_mbuf_chain[bd_prod], rx_buf, 3305 sizeof(struct bxe_sw_rx_bd)); 3306 memset(rx_buf, 0, sizeof(struct bxe_sw_rx_bd)); 3307 } 3308 3309 goto next_rx; 3310 } 3311 3312 /* current mbuf was detached from the bd */ 3313 fp->eth_q_stats.mbuf_alloc_rx--; 3314 3315 /* we allocated a replacement mbuf, fixup the current one */ 3316 m_adj(m, pad); 3317 m->m_pkthdr.len = m->m_len = len; 3318 3319 if ((len > 60) && (len > lenonbd)) { 3320 fp->eth_q_stats.rx_bxe_service_rxsgl++; 3321 rc = bxe_service_rxsgl(fp, len, lenonbd, m, cqe_fp); 3322 if (rc) 3323 break; 3324 fp->eth_q_stats.rx_jumbo_sge_pkts++; 3325 } else if (lenonbd < len) { 3326 fp->eth_q_stats.rx_erroneous_jumbo_sge_pkts++; 3327 } 3328 3329 /* assign packet to this interface interface */ 3330 if_setrcvif(m, ifp); 3331 3332 /* assume no hardware checksum has complated */ 3333 m->m_pkthdr.csum_flags = 0; 3334 3335 /* validate checksum if offload enabled */ 3336 if (if_getcapenable(ifp) & IFCAP_RXCSUM) { 3337 /* check for a valid IP frame */ 3338 if (!(cqe->fast_path_cqe.status_flags & 3339 ETH_FAST_PATH_RX_CQE_IP_XSUM_NO_VALIDATION_FLG)) { 3340 m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED; 3341 if (__predict_false(cqe_fp_flags & 3342 ETH_FAST_PATH_RX_CQE_IP_BAD_XSUM_FLG)) { 3343 fp->eth_q_stats.rx_hw_csum_errors++; 3344 } else { 3345 fp->eth_q_stats.rx_ofld_frames_csum_ip++; 3346 m->m_pkthdr.csum_flags |= CSUM_IP_VALID; 3347 } 3348 } 3349 3350 /* check for a valid TCP/UDP frame */ 3351 if (!(cqe->fast_path_cqe.status_flags & 3352 ETH_FAST_PATH_RX_CQE_L4_XSUM_NO_VALIDATION_FLG)) { 3353 if (__predict_false(cqe_fp_flags & 3354 ETH_FAST_PATH_RX_CQE_L4_BAD_XSUM_FLG)) { 3355 fp->eth_q_stats.rx_hw_csum_errors++; 3356 } else { 3357 fp->eth_q_stats.rx_ofld_frames_csum_tcp_udp++; 3358 m->m_pkthdr.csum_data = 0xFFFF; 3359 m->m_pkthdr.csum_flags |= (CSUM_DATA_VALID | 3360 CSUM_PSEUDO_HDR); 3361 } 3362 } 3363 } 3364 3365 /* if there is a VLAN tag then flag that info */ 3366 if (cqe->fast_path_cqe.pars_flags.flags & PARSING_FLAGS_INNER_VLAN_EXIST) { 3367 m->m_pkthdr.ether_vtag = cqe->fast_path_cqe.vlan_tag; 3368 m->m_flags |= M_VLANTAG; 3369 } 3370 3371 /* specify what RSS queue was used for this flow */ 3372 m->m_pkthdr.flowid = fp->index; 3373 BXE_SET_FLOWID(m); 3374 3375 next_rx: 3376 3377 bd_cons = RX_BD_NEXT(bd_cons); 3378 bd_prod = RX_BD_NEXT(bd_prod); 3379 bd_prod_fw = RX_BD_NEXT(bd_prod_fw); 3380 3381 /* pass the frame to the stack */ 3382 if (__predict_true(m != NULL)) { 3383 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1); 3384 rx_pkts++; 3385 if_input(ifp, m); 3386 } 3387 3388 next_cqe: 3389 3390 sw_cq_prod = RCQ_NEXT(sw_cq_prod); 3391 sw_cq_cons = RCQ_NEXT(sw_cq_cons); 3392 3393 /* limit spinning on the queue */ 3394 if (rc != 0) 3395 break; 3396 3397 if (rx_pkts == sc->rx_budget) { 3398 fp->eth_q_stats.rx_budget_reached++; 3399 break; 3400 } 3401 } /* while work to do */ 3402 3403 fp->rx_bd_cons = bd_cons; 3404 fp->rx_bd_prod = bd_prod_fw; 3405 fp->rx_cq_cons = sw_cq_cons; 3406 fp->rx_cq_prod = sw_cq_prod; 3407 3408 /* Update producers */ 3409 bxe_update_rx_prod(sc, fp, bd_prod_fw, sw_cq_prod, fp->rx_sge_prod); 3410 3411 fp->eth_q_stats.rx_pkts += rx_pkts; 3412 fp->eth_q_stats.rx_calls++; 3413 3414 BXE_FP_RX_UNLOCK(fp); 3415 3416 return (sw_cq_cons != hw_cq_cons); 3417 } 3418 3419 static uint16_t 3420 bxe_free_tx_pkt(struct bxe_softc *sc, 3421 struct bxe_fastpath *fp, 3422 uint16_t idx) 3423 { 3424 struct bxe_sw_tx_bd *tx_buf = &fp->tx_mbuf_chain[idx]; 3425 struct eth_tx_start_bd *tx_start_bd; 3426 uint16_t bd_idx = TX_BD(tx_buf->first_bd); 3427 uint16_t new_cons; 3428 int nbd; 3429 3430 /* unmap the mbuf from non-paged memory */ 3431 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map); 3432 3433 tx_start_bd = &fp->tx_chain[bd_idx].start_bd; 3434 nbd = le16toh(tx_start_bd->nbd) - 1; 3435 3436 new_cons = (tx_buf->first_bd + nbd); 3437 3438 /* free the mbuf */ 3439 if (__predict_true(tx_buf->m != NULL)) { 3440 m_freem(tx_buf->m); 3441 fp->eth_q_stats.mbuf_alloc_tx--; 3442 } else { 3443 fp->eth_q_stats.tx_chain_lost_mbuf++; 3444 } 3445 3446 tx_buf->m = NULL; 3447 tx_buf->first_bd = 0; 3448 3449 return (new_cons); 3450 } 3451 3452 /* transmit timeout watchdog */ 3453 static int 3454 bxe_watchdog(struct bxe_softc *sc, 3455 struct bxe_fastpath *fp) 3456 { 3457 BXE_FP_TX_LOCK(fp); 3458 3459 if ((fp->watchdog_timer == 0) || (--fp->watchdog_timer)) { 3460 BXE_FP_TX_UNLOCK(fp); 3461 return (0); 3462 } 3463 3464 BLOGE(sc, "TX watchdog timeout on fp[%02d], resetting!\n", fp->index); 3465 3466 BXE_FP_TX_UNLOCK(fp); 3467 BXE_SET_ERROR_BIT(sc, BXE_ERR_TXQ_STUCK); 3468 taskqueue_enqueue_timeout(taskqueue_thread, 3469 &sc->sp_err_timeout_task, hz/10); 3470 3471 return (-1); 3472 } 3473 3474 /* processes transmit completions */ 3475 static uint8_t 3476 bxe_txeof(struct bxe_softc *sc, 3477 struct bxe_fastpath *fp) 3478 { 3479 if_t ifp = sc->ifp; 3480 uint16_t bd_cons, hw_cons, sw_cons, pkt_cons; 3481 uint16_t tx_bd_avail; 3482 3483 BXE_FP_TX_LOCK_ASSERT(fp); 3484 3485 bd_cons = fp->tx_bd_cons; 3486 hw_cons = le16toh(*fp->tx_cons_sb); 3487 sw_cons = fp->tx_pkt_cons; 3488 3489 while (sw_cons != hw_cons) { 3490 pkt_cons = TX_BD(sw_cons); 3491 3492 BLOGD(sc, DBG_TX, 3493 "TX: fp[%d]: hw_cons=%u sw_cons=%u pkt_cons=%u\n", 3494 fp->index, hw_cons, sw_cons, pkt_cons); 3495 3496 bd_cons = bxe_free_tx_pkt(sc, fp, pkt_cons); 3497 3498 sw_cons++; 3499 } 3500 3501 fp->tx_pkt_cons = sw_cons; 3502 fp->tx_bd_cons = bd_cons; 3503 3504 BLOGD(sc, DBG_TX, 3505 "TX done: fp[%d]: hw_cons=%u sw_cons=%u sw_prod=%u\n", 3506 fp->index, hw_cons, fp->tx_pkt_cons, fp->tx_pkt_prod); 3507 3508 mb(); 3509 3510 tx_bd_avail = bxe_tx_avail(sc, fp); 3511 3512 if (tx_bd_avail < BXE_TX_CLEANUP_THRESHOLD) { 3513 if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0); 3514 } else { 3515 if_setdrvflagbits(ifp, 0, IFF_DRV_OACTIVE); 3516 } 3517 3518 if (fp->tx_pkt_prod != fp->tx_pkt_cons) { 3519 /* reset the watchdog timer if there are pending transmits */ 3520 fp->watchdog_timer = BXE_TX_TIMEOUT; 3521 return (TRUE); 3522 } else { 3523 /* clear watchdog when there are no pending transmits */ 3524 fp->watchdog_timer = 0; 3525 return (FALSE); 3526 } 3527 } 3528 3529 static void 3530 bxe_drain_tx_queues(struct bxe_softc *sc) 3531 { 3532 struct bxe_fastpath *fp; 3533 int i, count; 3534 3535 /* wait until all TX fastpath tasks have completed */ 3536 for (i = 0; i < sc->num_queues; i++) { 3537 fp = &sc->fp[i]; 3538 3539 count = 1000; 3540 3541 while (bxe_has_tx_work(fp)) { 3542 3543 BXE_FP_TX_LOCK(fp); 3544 bxe_txeof(sc, fp); 3545 BXE_FP_TX_UNLOCK(fp); 3546 3547 if (count == 0) { 3548 BLOGE(sc, "Timeout waiting for fp[%d] " 3549 "transmits to complete!\n", i); 3550 bxe_panic(sc, ("tx drain failure\n")); 3551 return; 3552 } 3553 3554 count--; 3555 DELAY(1000); 3556 rmb(); 3557 } 3558 } 3559 3560 return; 3561 } 3562 3563 static int 3564 bxe_del_all_macs(struct bxe_softc *sc, 3565 struct ecore_vlan_mac_obj *mac_obj, 3566 int mac_type, 3567 uint8_t wait_for_comp) 3568 { 3569 unsigned long ramrod_flags = 0, vlan_mac_flags = 0; 3570 int rc; 3571 3572 /* wait for completion of requested */ 3573 if (wait_for_comp) { 3574 bxe_set_bit(RAMROD_COMP_WAIT, &ramrod_flags); 3575 } 3576 3577 /* Set the mac type of addresses we want to clear */ 3578 bxe_set_bit(mac_type, &vlan_mac_flags); 3579 3580 rc = mac_obj->delete_all(sc, mac_obj, &vlan_mac_flags, &ramrod_flags); 3581 if (rc < 0) { 3582 BLOGE(sc, "Failed to delete MACs (%d) mac_type %d wait_for_comp 0x%x\n", 3583 rc, mac_type, wait_for_comp); 3584 } 3585 3586 return (rc); 3587 } 3588 3589 static int 3590 bxe_fill_accept_flags(struct bxe_softc *sc, 3591 uint32_t rx_mode, 3592 unsigned long *rx_accept_flags, 3593 unsigned long *tx_accept_flags) 3594 { 3595 /* Clear the flags first */ 3596 *rx_accept_flags = 0; 3597 *tx_accept_flags = 0; 3598 3599 switch (rx_mode) { 3600 case BXE_RX_MODE_NONE: 3601 /* 3602 * 'drop all' supersedes any accept flags that may have been 3603 * passed to the function. 3604 */ 3605 break; 3606 3607 case BXE_RX_MODE_NORMAL: 3608 bxe_set_bit(ECORE_ACCEPT_UNICAST, rx_accept_flags); 3609 bxe_set_bit(ECORE_ACCEPT_MULTICAST, rx_accept_flags); 3610 bxe_set_bit(ECORE_ACCEPT_BROADCAST, rx_accept_flags); 3611 3612 /* internal switching mode */ 3613 bxe_set_bit(ECORE_ACCEPT_UNICAST, tx_accept_flags); 3614 bxe_set_bit(ECORE_ACCEPT_MULTICAST, tx_accept_flags); 3615 bxe_set_bit(ECORE_ACCEPT_BROADCAST, tx_accept_flags); 3616 3617 break; 3618 3619 case BXE_RX_MODE_ALLMULTI: 3620 bxe_set_bit(ECORE_ACCEPT_UNICAST, rx_accept_flags); 3621 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, rx_accept_flags); 3622 bxe_set_bit(ECORE_ACCEPT_BROADCAST, rx_accept_flags); 3623 3624 /* internal switching mode */ 3625 bxe_set_bit(ECORE_ACCEPT_UNICAST, tx_accept_flags); 3626 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, tx_accept_flags); 3627 bxe_set_bit(ECORE_ACCEPT_BROADCAST, tx_accept_flags); 3628 3629 break; 3630 3631 case BXE_RX_MODE_PROMISC: 3632 /* 3633 * According to deffinition of SI mode, iface in promisc mode 3634 * should receive matched and unmatched (in resolution of port) 3635 * unicast packets. 3636 */ 3637 bxe_set_bit(ECORE_ACCEPT_UNMATCHED, rx_accept_flags); 3638 bxe_set_bit(ECORE_ACCEPT_UNICAST, rx_accept_flags); 3639 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, rx_accept_flags); 3640 bxe_set_bit(ECORE_ACCEPT_BROADCAST, rx_accept_flags); 3641 3642 /* internal switching mode */ 3643 bxe_set_bit(ECORE_ACCEPT_ALL_MULTICAST, tx_accept_flags); 3644 bxe_set_bit(ECORE_ACCEPT_BROADCAST, tx_accept_flags); 3645 3646 if (IS_MF_SI(sc)) { 3647 bxe_set_bit(ECORE_ACCEPT_ALL_UNICAST, tx_accept_flags); 3648 } else { 3649 bxe_set_bit(ECORE_ACCEPT_UNICAST, tx_accept_flags); 3650 } 3651 3652 break; 3653 3654 default: 3655 BLOGE(sc, "Unknown rx_mode (0x%x)\n", rx_mode); 3656 return (-1); 3657 } 3658 3659 /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */ 3660 if (rx_mode != BXE_RX_MODE_NONE) { 3661 bxe_set_bit(ECORE_ACCEPT_ANY_VLAN, rx_accept_flags); 3662 bxe_set_bit(ECORE_ACCEPT_ANY_VLAN, tx_accept_flags); 3663 } 3664 3665 return (0); 3666 } 3667 3668 static int 3669 bxe_set_q_rx_mode(struct bxe_softc *sc, 3670 uint8_t cl_id, 3671 unsigned long rx_mode_flags, 3672 unsigned long rx_accept_flags, 3673 unsigned long tx_accept_flags, 3674 unsigned long ramrod_flags) 3675 { 3676 struct ecore_rx_mode_ramrod_params ramrod_param; 3677 int rc; 3678 3679 memset(&ramrod_param, 0, sizeof(ramrod_param)); 3680 3681 /* Prepare ramrod parameters */ 3682 ramrod_param.cid = 0; 3683 ramrod_param.cl_id = cl_id; 3684 ramrod_param.rx_mode_obj = &sc->rx_mode_obj; 3685 ramrod_param.func_id = SC_FUNC(sc); 3686 3687 ramrod_param.pstate = &sc->sp_state; 3688 ramrod_param.state = ECORE_FILTER_RX_MODE_PENDING; 3689 3690 ramrod_param.rdata = BXE_SP(sc, rx_mode_rdata); 3691 ramrod_param.rdata_mapping = BXE_SP_MAPPING(sc, rx_mode_rdata); 3692 3693 bxe_set_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state); 3694 3695 ramrod_param.ramrod_flags = ramrod_flags; 3696 ramrod_param.rx_mode_flags = rx_mode_flags; 3697 3698 ramrod_param.rx_accept_flags = rx_accept_flags; 3699 ramrod_param.tx_accept_flags = tx_accept_flags; 3700 3701 rc = ecore_config_rx_mode(sc, &ramrod_param); 3702 if (rc < 0) { 3703 BLOGE(sc, "Set rx_mode %d cli_id 0x%x rx_mode_flags 0x%x " 3704 "rx_accept_flags 0x%x tx_accept_flags 0x%x " 3705 "ramrod_flags 0x%x rc %d failed\n", sc->rx_mode, cl_id, 3706 (uint32_t)rx_mode_flags, (uint32_t)rx_accept_flags, 3707 (uint32_t)tx_accept_flags, (uint32_t)ramrod_flags, rc); 3708 return (rc); 3709 } 3710 3711 return (0); 3712 } 3713 3714 static int 3715 bxe_set_storm_rx_mode(struct bxe_softc *sc) 3716 { 3717 unsigned long rx_mode_flags = 0, ramrod_flags = 0; 3718 unsigned long rx_accept_flags = 0, tx_accept_flags = 0; 3719 int rc; 3720 3721 rc = bxe_fill_accept_flags(sc, sc->rx_mode, &rx_accept_flags, 3722 &tx_accept_flags); 3723 if (rc) { 3724 return (rc); 3725 } 3726 3727 bxe_set_bit(RAMROD_RX, &ramrod_flags); 3728 bxe_set_bit(RAMROD_TX, &ramrod_flags); 3729 3730 /* XXX ensure all fastpath have same cl_id and/or move it to bxe_softc */ 3731 return (bxe_set_q_rx_mode(sc, sc->fp[0].cl_id, rx_mode_flags, 3732 rx_accept_flags, tx_accept_flags, 3733 ramrod_flags)); 3734 } 3735 3736 /* returns the "mcp load_code" according to global load_count array */ 3737 static int 3738 bxe_nic_load_no_mcp(struct bxe_softc *sc) 3739 { 3740 int path = SC_PATH(sc); 3741 int port = SC_PORT(sc); 3742 3743 BLOGI(sc, "NO MCP - load counts[%d] %d, %d, %d\n", 3744 path, load_count[path][0], load_count[path][1], 3745 load_count[path][2]); 3746 load_count[path][0]++; 3747 load_count[path][1 + port]++; 3748 BLOGI(sc, "NO MCP - new load counts[%d] %d, %d, %d\n", 3749 path, load_count[path][0], load_count[path][1], 3750 load_count[path][2]); 3751 if (load_count[path][0] == 1) { 3752 return (FW_MSG_CODE_DRV_LOAD_COMMON); 3753 } else if (load_count[path][1 + port] == 1) { 3754 return (FW_MSG_CODE_DRV_LOAD_PORT); 3755 } else { 3756 return (FW_MSG_CODE_DRV_LOAD_FUNCTION); 3757 } 3758 } 3759 3760 /* returns the "mcp load_code" according to global load_count array */ 3761 static int 3762 bxe_nic_unload_no_mcp(struct bxe_softc *sc) 3763 { 3764 int port = SC_PORT(sc); 3765 int path = SC_PATH(sc); 3766 3767 BLOGI(sc, "NO MCP - load counts[%d] %d, %d, %d\n", 3768 path, load_count[path][0], load_count[path][1], 3769 load_count[path][2]); 3770 load_count[path][0]--; 3771 load_count[path][1 + port]--; 3772 BLOGI(sc, "NO MCP - new load counts[%d] %d, %d, %d\n", 3773 path, load_count[path][0], load_count[path][1], 3774 load_count[path][2]); 3775 if (load_count[path][0] == 0) { 3776 return (FW_MSG_CODE_DRV_UNLOAD_COMMON); 3777 } else if (load_count[path][1 + port] == 0) { 3778 return (FW_MSG_CODE_DRV_UNLOAD_PORT); 3779 } else { 3780 return (FW_MSG_CODE_DRV_UNLOAD_FUNCTION); 3781 } 3782 } 3783 3784 /* request unload mode from the MCP: COMMON, PORT or FUNCTION */ 3785 static uint32_t 3786 bxe_send_unload_req(struct bxe_softc *sc, 3787 int unload_mode) 3788 { 3789 uint32_t reset_code = 0; 3790 3791 /* Select the UNLOAD request mode */ 3792 if (unload_mode == UNLOAD_NORMAL) { 3793 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; 3794 } else { 3795 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; 3796 } 3797 3798 /* Send the request to the MCP */ 3799 if (!BXE_NOMCP(sc)) { 3800 reset_code = bxe_fw_command(sc, reset_code, 0); 3801 } else { 3802 reset_code = bxe_nic_unload_no_mcp(sc); 3803 } 3804 3805 return (reset_code); 3806 } 3807 3808 /* send UNLOAD_DONE command to the MCP */ 3809 static void 3810 bxe_send_unload_done(struct bxe_softc *sc, 3811 uint8_t keep_link) 3812 { 3813 uint32_t reset_param = 3814 keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0; 3815 3816 /* Report UNLOAD_DONE to MCP */ 3817 if (!BXE_NOMCP(sc)) { 3818 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, reset_param); 3819 } 3820 } 3821 3822 static int 3823 bxe_func_wait_started(struct bxe_softc *sc) 3824 { 3825 int tout = 50; 3826 3827 if (!sc->port.pmf) { 3828 return (0); 3829 } 3830 3831 /* 3832 * (assumption: No Attention from MCP at this stage) 3833 * PMF probably in the middle of TX disable/enable transaction 3834 * 1. Sync IRS for default SB 3835 * 2. Sync SP queue - this guarantees us that attention handling started 3836 * 3. Wait, that TX disable/enable transaction completes 3837 * 3838 * 1+2 guarantee that if DCBX attention was scheduled it already changed 3839 * pending bit of transaction from STARTED-->TX_STOPPED, if we already 3840 * received completion for the transaction the state is TX_STOPPED. 3841 * State will return to STARTED after completion of TX_STOPPED-->STARTED 3842 * transaction. 3843 */ 3844 3845 /* XXX make sure default SB ISR is done */ 3846 /* need a way to synchronize an irq (intr_mtx?) */ 3847 3848 /* XXX flush any work queues */ 3849 3850 while (ecore_func_get_state(sc, &sc->func_obj) != 3851 ECORE_F_STATE_STARTED && tout--) { 3852 DELAY(20000); 3853 } 3854 3855 if (ecore_func_get_state(sc, &sc->func_obj) != ECORE_F_STATE_STARTED) { 3856 /* 3857 * Failed to complete the transaction in a "good way" 3858 * Force both transactions with CLR bit. 3859 */ 3860 struct ecore_func_state_params func_params = { NULL }; 3861 3862 BLOGE(sc, "Unexpected function state! " 3863 "Forcing STARTED-->TX_STOPPED-->STARTED\n"); 3864 3865 func_params.f_obj = &sc->func_obj; 3866 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags); 3867 3868 /* STARTED-->TX_STOPPED */ 3869 func_params.cmd = ECORE_F_CMD_TX_STOP; 3870 ecore_func_state_change(sc, &func_params); 3871 3872 /* TX_STOPPED-->STARTED */ 3873 func_params.cmd = ECORE_F_CMD_TX_START; 3874 return (ecore_func_state_change(sc, &func_params)); 3875 } 3876 3877 return (0); 3878 } 3879 3880 static int 3881 bxe_stop_queue(struct bxe_softc *sc, 3882 int index) 3883 { 3884 struct bxe_fastpath *fp = &sc->fp[index]; 3885 struct ecore_queue_state_params q_params = { NULL }; 3886 int rc; 3887 3888 BLOGD(sc, DBG_LOAD, "stopping queue %d cid %d\n", index, fp->index); 3889 3890 q_params.q_obj = &sc->sp_objs[fp->index].q_obj; 3891 /* We want to wait for completion in this context */ 3892 bxe_set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags); 3893 3894 /* Stop the primary connection: */ 3895 3896 /* ...halt the connection */ 3897 q_params.cmd = ECORE_Q_CMD_HALT; 3898 rc = ecore_queue_state_change(sc, &q_params); 3899 if (rc) { 3900 return (rc); 3901 } 3902 3903 /* ...terminate the connection */ 3904 q_params.cmd = ECORE_Q_CMD_TERMINATE; 3905 memset(&q_params.params.terminate, 0, sizeof(q_params.params.terminate)); 3906 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX; 3907 rc = ecore_queue_state_change(sc, &q_params); 3908 if (rc) { 3909 return (rc); 3910 } 3911 3912 /* ...delete cfc entry */ 3913 q_params.cmd = ECORE_Q_CMD_CFC_DEL; 3914 memset(&q_params.params.cfc_del, 0, sizeof(q_params.params.cfc_del)); 3915 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX; 3916 return (ecore_queue_state_change(sc, &q_params)); 3917 } 3918 3919 /* wait for the outstanding SP commands */ 3920 static inline uint8_t 3921 bxe_wait_sp_comp(struct bxe_softc *sc, 3922 unsigned long mask) 3923 { 3924 unsigned long tmp; 3925 int tout = 5000; /* wait for 5 secs tops */ 3926 3927 while (tout--) { 3928 mb(); 3929 if (!(atomic_load_acq_long(&sc->sp_state) & mask)) { 3930 return (TRUE); 3931 } 3932 3933 DELAY(1000); 3934 } 3935 3936 mb(); 3937 3938 tmp = atomic_load_acq_long(&sc->sp_state); 3939 if (tmp & mask) { 3940 BLOGE(sc, "Filtering completion timed out: " 3941 "sp_state 0x%lx, mask 0x%lx\n", 3942 tmp, mask); 3943 return (FALSE); 3944 } 3945 3946 return (FALSE); 3947 } 3948 3949 static int 3950 bxe_func_stop(struct bxe_softc *sc) 3951 { 3952 struct ecore_func_state_params func_params = { NULL }; 3953 int rc; 3954 3955 /* prepare parameters for function state transitions */ 3956 bxe_set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags); 3957 func_params.f_obj = &sc->func_obj; 3958 func_params.cmd = ECORE_F_CMD_STOP; 3959 3960 /* 3961 * Try to stop the function the 'good way'. If it fails (in case 3962 * of a parity error during bxe_chip_cleanup()) and we are 3963 * not in a debug mode, perform a state transaction in order to 3964 * enable further HW_RESET transaction. 3965 */ 3966 rc = ecore_func_state_change(sc, &func_params); 3967 if (rc) { 3968 BLOGE(sc, "FUNC_STOP ramrod failed. " 3969 "Running a dry transaction (%d)\n", rc); 3970 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags); 3971 return (ecore_func_state_change(sc, &func_params)); 3972 } 3973 3974 return (0); 3975 } 3976 3977 static int 3978 bxe_reset_hw(struct bxe_softc *sc, 3979 uint32_t load_code) 3980 { 3981 struct ecore_func_state_params func_params = { NULL }; 3982 3983 /* Prepare parameters for function state transitions */ 3984 bxe_set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags); 3985 3986 func_params.f_obj = &sc->func_obj; 3987 func_params.cmd = ECORE_F_CMD_HW_RESET; 3988 3989 func_params.params.hw_init.load_phase = load_code; 3990 3991 return (ecore_func_state_change(sc, &func_params)); 3992 } 3993 3994 static void 3995 bxe_int_disable_sync(struct bxe_softc *sc, 3996 int disable_hw) 3997 { 3998 if (disable_hw) { 3999 /* prevent the HW from sending interrupts */ 4000 bxe_int_disable(sc); 4001 } 4002 4003 /* XXX need a way to synchronize ALL irqs (intr_mtx?) */ 4004 /* make sure all ISRs are done */ 4005 4006 /* XXX make sure sp_task is not running */ 4007 /* cancel and flush work queues */ 4008 } 4009 4010 static void 4011 bxe_chip_cleanup(struct bxe_softc *sc, 4012 uint32_t unload_mode, 4013 uint8_t keep_link) 4014 { 4015 int port = SC_PORT(sc); 4016 struct ecore_mcast_ramrod_params rparam = { NULL }; 4017 uint32_t reset_code; 4018 int i, rc = 0; 4019 4020 bxe_drain_tx_queues(sc); 4021 4022 /* give HW time to discard old tx messages */ 4023 DELAY(1000); 4024 4025 /* Clean all ETH MACs */ 4026 rc = bxe_del_all_macs(sc, &sc->sp_objs[0].mac_obj, ECORE_ETH_MAC, FALSE); 4027 if (rc < 0) { 4028 BLOGE(sc, "Failed to delete all ETH MACs (%d)\n", rc); 4029 } 4030 4031 /* Clean up UC list */ 4032 rc = bxe_del_all_macs(sc, &sc->sp_objs[0].mac_obj, ECORE_UC_LIST_MAC, TRUE); 4033 if (rc < 0) { 4034 BLOGE(sc, "Failed to delete UC MACs list (%d)\n", rc); 4035 } 4036 4037 /* Disable LLH */ 4038 if (!CHIP_IS_E1(sc)) { 4039 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 0); 4040 } 4041 4042 /* Set "drop all" to stop Rx */ 4043 4044 /* 4045 * We need to take the BXE_MCAST_LOCK() here in order to prevent 4046 * a race between the completion code and this code. 4047 */ 4048 BXE_MCAST_LOCK(sc); 4049 4050 if (bxe_test_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state)) { 4051 bxe_set_bit(ECORE_FILTER_RX_MODE_SCHED, &sc->sp_state); 4052 } else { 4053 bxe_set_storm_rx_mode(sc); 4054 } 4055 4056 /* Clean up multicast configuration */ 4057 rparam.mcast_obj = &sc->mcast_obj; 4058 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL); 4059 if (rc < 0) { 4060 BLOGE(sc, "Failed to send DEL MCAST command (%d)\n", rc); 4061 } 4062 4063 BXE_MCAST_UNLOCK(sc); 4064 4065 // XXX bxe_iov_chip_cleanup(sc); 4066 4067 /* 4068 * Send the UNLOAD_REQUEST to the MCP. This will return if 4069 * this function should perform FUNCTION, PORT, or COMMON HW 4070 * reset. 4071 */ 4072 reset_code = bxe_send_unload_req(sc, unload_mode); 4073 4074 /* 4075 * (assumption: No Attention from MCP at this stage) 4076 * PMF probably in the middle of TX disable/enable transaction 4077 */ 4078 rc = bxe_func_wait_started(sc); 4079 if (rc) { 4080 BLOGE(sc, "bxe_func_wait_started failed (%d)\n", rc); 4081 } 4082 4083 /* 4084 * Close multi and leading connections 4085 * Completions for ramrods are collected in a synchronous way 4086 */ 4087 for (i = 0; i < sc->num_queues; i++) { 4088 if (bxe_stop_queue(sc, i)) { 4089 goto unload_error; 4090 } 4091 } 4092 4093 /* 4094 * If SP settings didn't get completed so far - something 4095 * very wrong has happen. 4096 */ 4097 if (!bxe_wait_sp_comp(sc, ~0x0UL)) { 4098 BLOGE(sc, "Common slow path ramrods got stuck!(%d)\n", rc); 4099 } 4100 4101 unload_error: 4102 4103 rc = bxe_func_stop(sc); 4104 if (rc) { 4105 BLOGE(sc, "Function stop failed!(%d)\n", rc); 4106 } 4107 4108 /* disable HW interrupts */ 4109 bxe_int_disable_sync(sc, TRUE); 4110 4111 /* detach interrupts */ 4112 bxe_interrupt_detach(sc); 4113 4114 /* Reset the chip */ 4115 rc = bxe_reset_hw(sc, reset_code); 4116 if (rc) { 4117 BLOGE(sc, "Hardware reset failed(%d)\n", rc); 4118 } 4119 4120 /* Report UNLOAD_DONE to MCP */ 4121 bxe_send_unload_done(sc, keep_link); 4122 } 4123 4124 static void 4125 bxe_disable_close_the_gate(struct bxe_softc *sc) 4126 { 4127 uint32_t val; 4128 int port = SC_PORT(sc); 4129 4130 BLOGD(sc, DBG_LOAD, 4131 "Disabling 'close the gates'\n"); 4132 4133 if (CHIP_IS_E1(sc)) { 4134 uint32_t addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : 4135 MISC_REG_AEU_MASK_ATTN_FUNC_0; 4136 val = REG_RD(sc, addr); 4137 val &= ~(0x300); 4138 REG_WR(sc, addr, val); 4139 } else { 4140 val = REG_RD(sc, MISC_REG_AEU_GENERAL_MASK); 4141 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK | 4142 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK); 4143 REG_WR(sc, MISC_REG_AEU_GENERAL_MASK, val); 4144 } 4145 } 4146 4147 /* 4148 * Cleans the object that have internal lists without sending 4149 * ramrods. Should be run when interrupts are disabled. 4150 */ 4151 static void 4152 bxe_squeeze_objects(struct bxe_softc *sc) 4153 { 4154 unsigned long ramrod_flags = 0, vlan_mac_flags = 0; 4155 struct ecore_mcast_ramrod_params rparam = { NULL }; 4156 struct ecore_vlan_mac_obj *mac_obj = &sc->sp_objs->mac_obj; 4157 int rc; 4158 4159 /* Cleanup MACs' object first... */ 4160 4161 /* Wait for completion of requested */ 4162 bxe_set_bit(RAMROD_COMP_WAIT, &ramrod_flags); 4163 /* Perform a dry cleanup */ 4164 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &ramrod_flags); 4165 4166 /* Clean ETH primary MAC */ 4167 bxe_set_bit(ECORE_ETH_MAC, &vlan_mac_flags); 4168 rc = mac_obj->delete_all(sc, &sc->sp_objs->mac_obj, &vlan_mac_flags, 4169 &ramrod_flags); 4170 if (rc != 0) { 4171 BLOGE(sc, "Failed to clean ETH MACs (%d)\n", rc); 4172 } 4173 4174 /* Cleanup UC list */ 4175 vlan_mac_flags = 0; 4176 bxe_set_bit(ECORE_UC_LIST_MAC, &vlan_mac_flags); 4177 rc = mac_obj->delete_all(sc, mac_obj, &vlan_mac_flags, 4178 &ramrod_flags); 4179 if (rc != 0) { 4180 BLOGE(sc, "Failed to clean UC list MACs (%d)\n", rc); 4181 } 4182 4183 /* Now clean mcast object... */ 4184 4185 rparam.mcast_obj = &sc->mcast_obj; 4186 bxe_set_bit(RAMROD_DRV_CLR_ONLY, &rparam.ramrod_flags); 4187 4188 /* Add a DEL command... */ 4189 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL); 4190 if (rc < 0) { 4191 BLOGE(sc, "Failed to send DEL MCAST command (%d)\n", rc); 4192 } 4193 4194 /* now wait until all pending commands are cleared */ 4195 4196 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT); 4197 while (rc != 0) { 4198 if (rc < 0) { 4199 BLOGE(sc, "Failed to clean MCAST object (%d)\n", rc); 4200 return; 4201 } 4202 4203 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT); 4204 } 4205 } 4206 4207 /* stop the controller */ 4208 static __noinline int 4209 bxe_nic_unload(struct bxe_softc *sc, 4210 uint32_t unload_mode, 4211 uint8_t keep_link) 4212 { 4213 uint8_t global = FALSE; 4214 uint32_t val; 4215 int i; 4216 4217 BXE_CORE_LOCK_ASSERT(sc); 4218 4219 if_setdrvflagbits(sc->ifp, 0, IFF_DRV_RUNNING); 4220 4221 for (i = 0; i < sc->num_queues; i++) { 4222 struct bxe_fastpath *fp; 4223 4224 fp = &sc->fp[i]; 4225 fp->watchdog_timer = 0; 4226 BXE_FP_TX_LOCK(fp); 4227 BXE_FP_TX_UNLOCK(fp); 4228 } 4229 4230 BLOGD(sc, DBG_LOAD, "Starting NIC unload...\n"); 4231 4232 /* mark driver as unloaded in shmem2 */ 4233 if (IS_PF(sc) && SHMEM2_HAS(sc, drv_capabilities_flag)) { 4234 val = SHMEM2_RD(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)]); 4235 SHMEM2_WR(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)], 4236 val & ~DRV_FLAGS_CAPABILITIES_LOADED_L2); 4237 } 4238 4239 if (IS_PF(sc) && sc->recovery_state != BXE_RECOVERY_DONE && 4240 (sc->state == BXE_STATE_CLOSED || sc->state == BXE_STATE_ERROR)) { 4241 4242 if(CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) { 4243 /* 4244 * We can get here if the driver has been unloaded 4245 * during parity error recovery and is either waiting for a 4246 * leader to complete or for other functions to unload and 4247 * then ifconfig down has been issued. In this case we want to 4248 * unload and let other functions to complete a recovery 4249 * process. 4250 */ 4251 sc->recovery_state = BXE_RECOVERY_DONE; 4252 sc->is_leader = 0; 4253 bxe_release_leader_lock(sc); 4254 mb(); 4255 BLOGD(sc, DBG_LOAD, "Releasing a leadership...\n"); 4256 } 4257 BLOGE(sc, "Can't unload in closed or error state recover_state 0x%x" 4258 " state = 0x%x\n", sc->recovery_state, sc->state); 4259 return (-1); 4260 } 4261 4262 /* 4263 * Nothing to do during unload if previous bxe_nic_load() 4264 * did not completed successfully - all resourses are released. 4265 */ 4266 if ((sc->state == BXE_STATE_CLOSED) || 4267 (sc->state == BXE_STATE_ERROR)) { 4268 return (0); 4269 } 4270 4271 sc->state = BXE_STATE_CLOSING_WAITING_HALT; 4272 mb(); 4273 4274 /* stop tx */ 4275 bxe_tx_disable(sc); 4276 4277 sc->rx_mode = BXE_RX_MODE_NONE; 4278 /* XXX set rx mode ??? */ 4279 4280 if (IS_PF(sc) && !sc->grcdump_done) { 4281 /* set ALWAYS_ALIVE bit in shmem */ 4282 sc->fw_drv_pulse_wr_seq |= DRV_PULSE_ALWAYS_ALIVE; 4283 4284 bxe_drv_pulse(sc); 4285 4286 bxe_stats_handle(sc, STATS_EVENT_STOP); 4287 bxe_save_statistics(sc); 4288 } 4289 4290 /* wait till consumers catch up with producers in all queues */ 4291 bxe_drain_tx_queues(sc); 4292 4293 /* if VF indicate to PF this function is going down (PF will delete sp 4294 * elements and clear initializations 4295 */ 4296 if (IS_VF(sc)) { 4297 ; /* bxe_vfpf_close_vf(sc); */ 4298 } else if (unload_mode != UNLOAD_RECOVERY) { 4299 /* if this is a normal/close unload need to clean up chip */ 4300 if (!sc->grcdump_done) 4301 bxe_chip_cleanup(sc, unload_mode, keep_link); 4302 } else { 4303 /* Send the UNLOAD_REQUEST to the MCP */ 4304 bxe_send_unload_req(sc, unload_mode); 4305 4306 /* 4307 * Prevent transactions to host from the functions on the 4308 * engine that doesn't reset global blocks in case of global 4309 * attention once gloabl blocks are reset and gates are opened 4310 * (the engine which leader will perform the recovery 4311 * last). 4312 */ 4313 if (!CHIP_IS_E1x(sc)) { 4314 bxe_pf_disable(sc); 4315 } 4316 4317 /* disable HW interrupts */ 4318 bxe_int_disable_sync(sc, TRUE); 4319 4320 /* detach interrupts */ 4321 bxe_interrupt_detach(sc); 4322 4323 /* Report UNLOAD_DONE to MCP */ 4324 bxe_send_unload_done(sc, FALSE); 4325 } 4326 4327 /* 4328 * At this stage no more interrupts will arrive so we may safely clean 4329 * the queue'able objects here in case they failed to get cleaned so far. 4330 */ 4331 if (IS_PF(sc)) { 4332 bxe_squeeze_objects(sc); 4333 } 4334 4335 /* There should be no more pending SP commands at this stage */ 4336 sc->sp_state = 0; 4337 4338 sc->port.pmf = 0; 4339 4340 bxe_free_fp_buffers(sc); 4341 4342 if (IS_PF(sc)) { 4343 bxe_free_mem(sc); 4344 } 4345 4346 bxe_free_fw_stats_mem(sc); 4347 4348 sc->state = BXE_STATE_CLOSED; 4349 4350 /* 4351 * Check if there are pending parity attentions. If there are - set 4352 * RECOVERY_IN_PROGRESS. 4353 */ 4354 if (IS_PF(sc) && bxe_chk_parity_attn(sc, &global, FALSE)) { 4355 bxe_set_reset_in_progress(sc); 4356 4357 /* Set RESET_IS_GLOBAL if needed */ 4358 if (global) { 4359 bxe_set_reset_global(sc); 4360 } 4361 } 4362 4363 /* 4364 * The last driver must disable a "close the gate" if there is no 4365 * parity attention or "process kill" pending. 4366 */ 4367 if (IS_PF(sc) && !bxe_clear_pf_load(sc) && 4368 bxe_reset_is_done(sc, SC_PATH(sc))) { 4369 bxe_disable_close_the_gate(sc); 4370 } 4371 4372 BLOGD(sc, DBG_LOAD, "Ended NIC unload\n"); 4373 4374 bxe_link_report(sc); 4375 4376 return (0); 4377 } 4378 4379 /* 4380 * Called by the OS to set various media options (i.e. link, speed, etc.) when 4381 * the user runs "ifconfig bxe media ..." or "ifconfig bxe mediaopt ...". 4382 */ 4383 static int 4384 bxe_ifmedia_update(if_t ifp) 4385 { 4386 struct bxe_softc *sc = (struct bxe_softc *)if_getsoftc(ifp); 4387 struct ifmedia *ifm; 4388 4389 ifm = &sc->ifmedia; 4390 4391 /* We only support Ethernet media type. */ 4392 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) { 4393 return (EINVAL); 4394 } 4395 4396 switch (IFM_SUBTYPE(ifm->ifm_media)) { 4397 case IFM_AUTO: 4398 break; 4399 case IFM_10G_CX4: 4400 case IFM_10G_SR: 4401 case IFM_10G_T: 4402 case IFM_10G_TWINAX: 4403 default: 4404 /* We don't support changing the media type. */ 4405 BLOGD(sc, DBG_LOAD, "Invalid media type (%d)\n", 4406 IFM_SUBTYPE(ifm->ifm_media)); 4407 return (EINVAL); 4408 } 4409 4410 return (0); 4411 } 4412 4413 /* 4414 * Called by the OS to get the current media status (i.e. link, speed, etc.). 4415 */ 4416 static void 4417 bxe_ifmedia_status(if_t ifp, struct ifmediareq *ifmr) 4418 { 4419 struct bxe_softc *sc = if_getsoftc(ifp); 4420 4421 /* Bug 165447: the 'ifconfig' tool skips printing of the "status: ..." 4422 line if the IFM_AVALID flag is *NOT* set. So we need to set this 4423 flag unconditionally (irrespective of the admininistrative 4424 'up/down' state of the interface) to ensure that the line is always 4425 displayed. 4426 */ 4427 ifmr->ifm_status = IFM_AVALID; 4428 4429 /* Setup the default interface info. */ 4430 ifmr->ifm_active = IFM_ETHER; 4431 4432 /* Report link down if the driver isn't running. */ 4433 if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0) { 4434 ifmr->ifm_active |= IFM_NONE; 4435 BLOGD(sc, DBG_PHY, "in %s : nic still not loaded fully\n", __func__); 4436 BLOGD(sc, DBG_PHY, "in %s : link_up (1) : %d\n", 4437 __func__, sc->link_vars.link_up); 4438 return; 4439 } 4440 4441 4442 if (sc->link_vars.link_up) { 4443 ifmr->ifm_status |= IFM_ACTIVE; 4444 ifmr->ifm_active |= IFM_FDX; 4445 } else { 4446 ifmr->ifm_active |= IFM_NONE; 4447 BLOGD(sc, DBG_PHY, "in %s : setting IFM_NONE\n", 4448 __func__); 4449 return; 4450 } 4451 4452 ifmr->ifm_active |= sc->media; 4453 return; 4454 } 4455 4456 static void 4457 bxe_handle_chip_tq(void *context, 4458 int pending) 4459 { 4460 struct bxe_softc *sc = (struct bxe_softc *)context; 4461 long work = atomic_load_acq_long(&sc->chip_tq_flags); 4462 4463 switch (work) 4464 { 4465 4466 case CHIP_TQ_REINIT: 4467 if (if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING) { 4468 /* restart the interface */ 4469 BLOGD(sc, DBG_LOAD, "Restarting the interface...\n"); 4470 bxe_periodic_stop(sc); 4471 BXE_CORE_LOCK(sc); 4472 bxe_stop_locked(sc); 4473 bxe_init_locked(sc); 4474 BXE_CORE_UNLOCK(sc); 4475 } 4476 break; 4477 4478 default: 4479 break; 4480 } 4481 } 4482 4483 /* 4484 * Handles any IOCTL calls from the operating system. 4485 * 4486 * Returns: 4487 * 0 = Success, >0 Failure 4488 */ 4489 static int 4490 bxe_ioctl(if_t ifp, 4491 u_long command, 4492 caddr_t data) 4493 { 4494 struct bxe_softc *sc = if_getsoftc(ifp); 4495 struct ifreq *ifr = (struct ifreq *)data; 4496 int mask = 0; 4497 int reinit = 0; 4498 int error = 0; 4499 4500 int mtu_min = (ETH_MIN_PACKET_SIZE - ETH_HLEN); 4501 int mtu_max = (MJUM9BYTES - ETH_OVERHEAD - IP_HEADER_ALIGNMENT_PADDING); 4502 4503 switch (command) 4504 { 4505 case SIOCSIFMTU: 4506 BLOGD(sc, DBG_IOCTL, "Received SIOCSIFMTU ioctl (mtu=%d)\n", 4507 ifr->ifr_mtu); 4508 4509 if (sc->mtu == ifr->ifr_mtu) { 4510 /* nothing to change */ 4511 break; 4512 } 4513 4514 if ((ifr->ifr_mtu < mtu_min) || (ifr->ifr_mtu > mtu_max)) { 4515 BLOGE(sc, "Unsupported MTU size %d (range is %d-%d)\n", 4516 ifr->ifr_mtu, mtu_min, mtu_max); 4517 error = EINVAL; 4518 break; 4519 } 4520 4521 atomic_store_rel_int((volatile unsigned int *)&sc->mtu, 4522 (unsigned long)ifr->ifr_mtu); 4523 /* 4524 atomic_store_rel_long((volatile unsigned long *)&if_getmtu(ifp), 4525 (unsigned long)ifr->ifr_mtu); 4526 XXX - Not sure why it needs to be atomic 4527 */ 4528 if_setmtu(ifp, ifr->ifr_mtu); 4529 reinit = 1; 4530 break; 4531 4532 case SIOCSIFFLAGS: 4533 /* toggle the interface state up or down */ 4534 BLOGD(sc, DBG_IOCTL, "Received SIOCSIFFLAGS ioctl\n"); 4535 4536 BXE_CORE_LOCK(sc); 4537 /* check if the interface is up */ 4538 if (if_getflags(ifp) & IFF_UP) { 4539 if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) { 4540 /* set the receive mode flags */ 4541 bxe_set_rx_mode(sc); 4542 } else if(sc->state != BXE_STATE_DISABLED) { 4543 bxe_init_locked(sc); 4544 } 4545 } else { 4546 if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) { 4547 bxe_periodic_stop(sc); 4548 bxe_stop_locked(sc); 4549 } 4550 } 4551 BXE_CORE_UNLOCK(sc); 4552 4553 break; 4554 4555 case SIOCADDMULTI: 4556 case SIOCDELMULTI: 4557 /* add/delete multicast addresses */ 4558 BLOGD(sc, DBG_IOCTL, "Received SIOCADDMULTI/SIOCDELMULTI ioctl\n"); 4559 4560 /* check if the interface is up */ 4561 if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) { 4562 /* set the receive mode flags */ 4563 BXE_CORE_LOCK(sc); 4564 bxe_set_rx_mode(sc); 4565 BXE_CORE_UNLOCK(sc); 4566 } 4567 4568 break; 4569 4570 case SIOCSIFCAP: 4571 /* find out which capabilities have changed */ 4572 mask = (ifr->ifr_reqcap ^ if_getcapenable(ifp)); 4573 4574 BLOGD(sc, DBG_IOCTL, "Received SIOCSIFCAP ioctl (mask=0x%08x)\n", 4575 mask); 4576 4577 /* toggle the LRO capabilites enable flag */ 4578 if (mask & IFCAP_LRO) { 4579 if_togglecapenable(ifp, IFCAP_LRO); 4580 BLOGD(sc, DBG_IOCTL, "Turning LRO %s\n", 4581 (if_getcapenable(ifp) & IFCAP_LRO) ? "ON" : "OFF"); 4582 reinit = 1; 4583 } 4584 4585 /* toggle the TXCSUM checksum capabilites enable flag */ 4586 if (mask & IFCAP_TXCSUM) { 4587 if_togglecapenable(ifp, IFCAP_TXCSUM); 4588 BLOGD(sc, DBG_IOCTL, "Turning TXCSUM %s\n", 4589 (if_getcapenable(ifp) & IFCAP_TXCSUM) ? "ON" : "OFF"); 4590 if (if_getcapenable(ifp) & IFCAP_TXCSUM) { 4591 if_sethwassistbits(ifp, (CSUM_IP | 4592 CSUM_TCP | 4593 CSUM_UDP | 4594 CSUM_TSO | 4595 CSUM_TCP_IPV6 | 4596 CSUM_UDP_IPV6), 0); 4597 } else { 4598 if_clearhwassist(ifp); /* XXX */ 4599 } 4600 } 4601 4602 /* toggle the RXCSUM checksum capabilities enable flag */ 4603 if (mask & IFCAP_RXCSUM) { 4604 if_togglecapenable(ifp, IFCAP_RXCSUM); 4605 BLOGD(sc, DBG_IOCTL, "Turning RXCSUM %s\n", 4606 (if_getcapenable(ifp) & IFCAP_RXCSUM) ? "ON" : "OFF"); 4607 if (if_getcapenable(ifp) & IFCAP_RXCSUM) { 4608 if_sethwassistbits(ifp, (CSUM_IP | 4609 CSUM_TCP | 4610 CSUM_UDP | 4611 CSUM_TSO | 4612 CSUM_TCP_IPV6 | 4613 CSUM_UDP_IPV6), 0); 4614 } else { 4615 if_clearhwassist(ifp); /* XXX */ 4616 } 4617 } 4618 4619 /* toggle TSO4 capabilities enabled flag */ 4620 if (mask & IFCAP_TSO4) { 4621 if_togglecapenable(ifp, IFCAP_TSO4); 4622 BLOGD(sc, DBG_IOCTL, "Turning TSO4 %s\n", 4623 (if_getcapenable(ifp) & IFCAP_TSO4) ? "ON" : "OFF"); 4624 } 4625 4626 /* toggle TSO6 capabilities enabled flag */ 4627 if (mask & IFCAP_TSO6) { 4628 if_togglecapenable(ifp, IFCAP_TSO6); 4629 BLOGD(sc, DBG_IOCTL, "Turning TSO6 %s\n", 4630 (if_getcapenable(ifp) & IFCAP_TSO6) ? "ON" : "OFF"); 4631 } 4632 4633 /* toggle VLAN_HWTSO capabilities enabled flag */ 4634 if (mask & IFCAP_VLAN_HWTSO) { 4635 4636 if_togglecapenable(ifp, IFCAP_VLAN_HWTSO); 4637 BLOGD(sc, DBG_IOCTL, "Turning VLAN_HWTSO %s\n", 4638 (if_getcapenable(ifp) & IFCAP_VLAN_HWTSO) ? "ON" : "OFF"); 4639 } 4640 4641 /* toggle VLAN_HWCSUM capabilities enabled flag */ 4642 if (mask & IFCAP_VLAN_HWCSUM) { 4643 /* XXX investigate this... */ 4644 BLOGE(sc, "Changing VLAN_HWCSUM is not supported!\n"); 4645 error = EINVAL; 4646 } 4647 4648 /* toggle VLAN_MTU capabilities enable flag */ 4649 if (mask & IFCAP_VLAN_MTU) { 4650 /* XXX investigate this... */ 4651 BLOGE(sc, "Changing VLAN_MTU is not supported!\n"); 4652 error = EINVAL; 4653 } 4654 4655 /* toggle VLAN_HWTAGGING capabilities enabled flag */ 4656 if (mask & IFCAP_VLAN_HWTAGGING) { 4657 /* XXX investigate this... */ 4658 BLOGE(sc, "Changing VLAN_HWTAGGING is not supported!\n"); 4659 error = EINVAL; 4660 } 4661 4662 /* toggle VLAN_HWFILTER capabilities enabled flag */ 4663 if (mask & IFCAP_VLAN_HWFILTER) { 4664 /* XXX investigate this... */ 4665 BLOGE(sc, "Changing VLAN_HWFILTER is not supported!\n"); 4666 error = EINVAL; 4667 } 4668 4669 /* XXX not yet... 4670 * IFCAP_WOL_MAGIC 4671 */ 4672 4673 break; 4674 4675 case SIOCSIFMEDIA: 4676 case SIOCGIFMEDIA: 4677 /* set/get interface media */ 4678 BLOGD(sc, DBG_IOCTL, 4679 "Received SIOCSIFMEDIA/SIOCGIFMEDIA ioctl (cmd=%lu)\n", 4680 (command & 0xff)); 4681 error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, command); 4682 break; 4683 4684 default: 4685 BLOGD(sc, DBG_IOCTL, "Received Unknown Ioctl (cmd=%lu)\n", 4686 (command & 0xff)); 4687 error = ether_ioctl(ifp, command, data); 4688 break; 4689 } 4690 4691 if (reinit && (if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING)) { 4692 BLOGD(sc, DBG_LOAD | DBG_IOCTL, 4693 "Re-initializing hardware from IOCTL change\n"); 4694 bxe_periodic_stop(sc); 4695 BXE_CORE_LOCK(sc); 4696 bxe_stop_locked(sc); 4697 bxe_init_locked(sc); 4698 BXE_CORE_UNLOCK(sc); 4699 } 4700 4701 return (error); 4702 } 4703 4704 static __noinline void 4705 bxe_dump_mbuf(struct bxe_softc *sc, 4706 struct mbuf *m, 4707 uint8_t contents) 4708 { 4709 char * type; 4710 int i = 0; 4711 4712 if (!(sc->debug & DBG_MBUF)) { 4713 return; 4714 } 4715 4716 if (m == NULL) { 4717 BLOGD(sc, DBG_MBUF, "mbuf: null pointer\n"); 4718 return; 4719 } 4720 4721 while (m) { 4722 4723 BLOGD(sc, DBG_MBUF, 4724 "%02d: mbuf=%p m_len=%d m_flags=0x%b m_data=%p\n", 4725 i, m, m->m_len, m->m_flags, M_FLAG_BITS, m->m_data); 4726 4727 if (m->m_flags & M_PKTHDR) { 4728 BLOGD(sc, DBG_MBUF, 4729 "%02d: - m_pkthdr: tot_len=%d flags=0x%b csum_flags=%b\n", 4730 i, m->m_pkthdr.len, m->m_flags, M_FLAG_BITS, 4731 (int)m->m_pkthdr.csum_flags, CSUM_BITS); 4732 } 4733 4734 if (m->m_flags & M_EXT) { 4735 switch (m->m_ext.ext_type) { 4736 case EXT_CLUSTER: type = "EXT_CLUSTER"; break; 4737 case EXT_SFBUF: type = "EXT_SFBUF"; break; 4738 case EXT_JUMBOP: type = "EXT_JUMBOP"; break; 4739 case EXT_JUMBO9: type = "EXT_JUMBO9"; break; 4740 case EXT_JUMBO16: type = "EXT_JUMBO16"; break; 4741 case EXT_PACKET: type = "EXT_PACKET"; break; 4742 case EXT_MBUF: type = "EXT_MBUF"; break; 4743 case EXT_NET_DRV: type = "EXT_NET_DRV"; break; 4744 case EXT_MOD_TYPE: type = "EXT_MOD_TYPE"; break; 4745 case EXT_DISPOSABLE: type = "EXT_DISPOSABLE"; break; 4746 case EXT_EXTREF: type = "EXT_EXTREF"; break; 4747 default: type = "UNKNOWN"; break; 4748 } 4749 4750 BLOGD(sc, DBG_MBUF, 4751 "%02d: - m_ext: %p ext_size=%d type=%s\n", 4752 i, m->m_ext.ext_buf, m->m_ext.ext_size, type); 4753 } 4754 4755 if (contents) { 4756 bxe_dump_mbuf_data(sc, "mbuf data", m, TRUE); 4757 } 4758 4759 m = m->m_next; 4760 i++; 4761 } 4762 } 4763 4764 /* 4765 * Checks to ensure the 13 bd sliding window is >= MSS for TSO. 4766 * Check that (13 total bds - 3 bds) = 10 bd window >= MSS. 4767 * The window: 3 bds are = 1 for headers BD + 2 for parse BD and last BD 4768 * The headers comes in a separate bd in FreeBSD so 13-3=10. 4769 * Returns: 0 if OK to send, 1 if packet needs further defragmentation 4770 */ 4771 static int 4772 bxe_chktso_window(struct bxe_softc *sc, 4773 int nsegs, 4774 bus_dma_segment_t *segs, 4775 struct mbuf *m) 4776 { 4777 uint32_t num_wnds, wnd_size, wnd_sum; 4778 int32_t frag_idx, wnd_idx; 4779 unsigned short lso_mss; 4780 4781 wnd_sum = 0; 4782 wnd_size = 10; 4783 num_wnds = nsegs - wnd_size; 4784 lso_mss = htole16(m->m_pkthdr.tso_segsz); 4785 4786 /* 4787 * Total header lengths Eth+IP+TCP in first FreeBSD mbuf so calculate the 4788 * first window sum of data while skipping the first assuming it is the 4789 * header in FreeBSD. 4790 */ 4791 for (frag_idx = 1; (frag_idx <= wnd_size); frag_idx++) { 4792 wnd_sum += htole16(segs[frag_idx].ds_len); 4793 } 4794 4795 /* check the first 10 bd window size */ 4796 if (wnd_sum < lso_mss) { 4797 return (1); 4798 } 4799 4800 /* run through the windows */ 4801 for (wnd_idx = 0; wnd_idx < num_wnds; wnd_idx++, frag_idx++) { 4802 /* subtract the first mbuf->m_len of the last wndw(-header) */ 4803 wnd_sum -= htole16(segs[wnd_idx+1].ds_len); 4804 /* add the next mbuf len to the len of our new window */ 4805 wnd_sum += htole16(segs[frag_idx].ds_len); 4806 if (wnd_sum < lso_mss) { 4807 return (1); 4808 } 4809 } 4810 4811 return (0); 4812 } 4813 4814 static uint8_t 4815 bxe_set_pbd_csum_e2(struct bxe_fastpath *fp, 4816 struct mbuf *m, 4817 uint32_t *parsing_data) 4818 { 4819 struct ether_vlan_header *eh = NULL; 4820 struct ip *ip4 = NULL; 4821 struct ip6_hdr *ip6 = NULL; 4822 caddr_t ip = NULL; 4823 struct tcphdr *th = NULL; 4824 int e_hlen, ip_hlen, l4_off; 4825 uint16_t proto; 4826 4827 if (m->m_pkthdr.csum_flags == CSUM_IP) { 4828 /* no L4 checksum offload needed */ 4829 return (0); 4830 } 4831 4832 /* get the Ethernet header */ 4833 eh = mtod(m, struct ether_vlan_header *); 4834 4835 /* handle VLAN encapsulation if present */ 4836 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) { 4837 e_hlen = (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN); 4838 proto = ntohs(eh->evl_proto); 4839 } else { 4840 e_hlen = ETHER_HDR_LEN; 4841 proto = ntohs(eh->evl_encap_proto); 4842 } 4843 4844 switch (proto) { 4845 case ETHERTYPE_IP: 4846 /* get the IP header, if mbuf len < 20 then header in next mbuf */ 4847 ip4 = (m->m_len < sizeof(struct ip)) ? 4848 (struct ip *)m->m_next->m_data : 4849 (struct ip *)(m->m_data + e_hlen); 4850 /* ip_hl is number of 32-bit words */ 4851 ip_hlen = (ip4->ip_hl << 2); 4852 ip = (caddr_t)ip4; 4853 break; 4854 case ETHERTYPE_IPV6: 4855 /* get the IPv6 header, if mbuf len < 40 then header in next mbuf */ 4856 ip6 = (m->m_len < sizeof(struct ip6_hdr)) ? 4857 (struct ip6_hdr *)m->m_next->m_data : 4858 (struct ip6_hdr *)(m->m_data + e_hlen); 4859 /* XXX cannot support offload with IPv6 extensions */ 4860 ip_hlen = sizeof(struct ip6_hdr); 4861 ip = (caddr_t)ip6; 4862 break; 4863 default: 4864 /* We can't offload in this case... */ 4865 /* XXX error stat ??? */ 4866 return (0); 4867 } 4868 4869 /* XXX assuming L4 header is contiguous to IPv4/IPv6 in the same mbuf */ 4870 l4_off = (e_hlen + ip_hlen); 4871 4872 *parsing_data |= 4873 (((l4_off >> 1) << ETH_TX_PARSE_BD_E2_L4_HDR_START_OFFSET_W_SHIFT) & 4874 ETH_TX_PARSE_BD_E2_L4_HDR_START_OFFSET_W); 4875 4876 if (m->m_pkthdr.csum_flags & (CSUM_TCP | 4877 CSUM_TSO | 4878 CSUM_TCP_IPV6)) { 4879 fp->eth_q_stats.tx_ofld_frames_csum_tcp++; 4880 th = (struct tcphdr *)(ip + ip_hlen); 4881 /* th_off is number of 32-bit words */ 4882 *parsing_data |= ((th->th_off << 4883 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW_SHIFT) & 4884 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW); 4885 return (l4_off + (th->th_off << 2)); /* entire header length */ 4886 } else if (m->m_pkthdr.csum_flags & (CSUM_UDP | 4887 CSUM_UDP_IPV6)) { 4888 fp->eth_q_stats.tx_ofld_frames_csum_udp++; 4889 return (l4_off + sizeof(struct udphdr)); /* entire header length */ 4890 } else { 4891 /* XXX error stat ??? */ 4892 return (0); 4893 } 4894 } 4895 4896 static uint8_t 4897 bxe_set_pbd_csum(struct bxe_fastpath *fp, 4898 struct mbuf *m, 4899 struct eth_tx_parse_bd_e1x *pbd) 4900 { 4901 struct ether_vlan_header *eh = NULL; 4902 struct ip *ip4 = NULL; 4903 struct ip6_hdr *ip6 = NULL; 4904 caddr_t ip = NULL; 4905 struct tcphdr *th = NULL; 4906 struct udphdr *uh = NULL; 4907 int e_hlen, ip_hlen; 4908 uint16_t proto; 4909 uint8_t hlen; 4910 uint16_t tmp_csum; 4911 uint32_t *tmp_uh; 4912 4913 /* get the Ethernet header */ 4914 eh = mtod(m, struct ether_vlan_header *); 4915 4916 /* handle VLAN encapsulation if present */ 4917 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) { 4918 e_hlen = (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN); 4919 proto = ntohs(eh->evl_proto); 4920 } else { 4921 e_hlen = ETHER_HDR_LEN; 4922 proto = ntohs(eh->evl_encap_proto); 4923 } 4924 4925 switch (proto) { 4926 case ETHERTYPE_IP: 4927 /* get the IP header, if mbuf len < 20 then header in next mbuf */ 4928 ip4 = (m->m_len < sizeof(struct ip)) ? 4929 (struct ip *)m->m_next->m_data : 4930 (struct ip *)(m->m_data + e_hlen); 4931 /* ip_hl is number of 32-bit words */ 4932 ip_hlen = (ip4->ip_hl << 1); 4933 ip = (caddr_t)ip4; 4934 break; 4935 case ETHERTYPE_IPV6: 4936 /* get the IPv6 header, if mbuf len < 40 then header in next mbuf */ 4937 ip6 = (m->m_len < sizeof(struct ip6_hdr)) ? 4938 (struct ip6_hdr *)m->m_next->m_data : 4939 (struct ip6_hdr *)(m->m_data + e_hlen); 4940 /* XXX cannot support offload with IPv6 extensions */ 4941 ip_hlen = (sizeof(struct ip6_hdr) >> 1); 4942 ip = (caddr_t)ip6; 4943 break; 4944 default: 4945 /* We can't offload in this case... */ 4946 /* XXX error stat ??? */ 4947 return (0); 4948 } 4949 4950 hlen = (e_hlen >> 1); 4951 4952 /* note that rest of global_data is indirectly zeroed here */ 4953 if (m->m_flags & M_VLANTAG) { 4954 pbd->global_data = 4955 htole16(hlen | (1 << ETH_TX_PARSE_BD_E1X_LLC_SNAP_EN_SHIFT)); 4956 } else { 4957 pbd->global_data = htole16(hlen); 4958 } 4959 4960 pbd->ip_hlen_w = ip_hlen; 4961 4962 hlen += pbd->ip_hlen_w; 4963 4964 /* XXX assuming L4 header is contiguous to IPv4/IPv6 in the same mbuf */ 4965 4966 if (m->m_pkthdr.csum_flags & (CSUM_TCP | 4967 CSUM_TSO | 4968 CSUM_TCP_IPV6)) { 4969 th = (struct tcphdr *)(ip + (ip_hlen << 1)); 4970 /* th_off is number of 32-bit words */ 4971 hlen += (uint16_t)(th->th_off << 1); 4972 } else if (m->m_pkthdr.csum_flags & (CSUM_UDP | 4973 CSUM_UDP_IPV6)) { 4974 uh = (struct udphdr *)(ip + (ip_hlen << 1)); 4975 hlen += (sizeof(struct udphdr) / 2); 4976 } else { 4977 /* valid case as only CSUM_IP was set */ 4978 return (0); 4979 } 4980 4981 pbd->total_hlen_w = htole16(hlen); 4982 4983 if (m->m_pkthdr.csum_flags & (CSUM_TCP | 4984 CSUM_TSO | 4985 CSUM_TCP_IPV6)) { 4986 fp->eth_q_stats.tx_ofld_frames_csum_tcp++; 4987 pbd->tcp_pseudo_csum = ntohs(th->th_sum); 4988 } else if (m->m_pkthdr.csum_flags & (CSUM_UDP | 4989 CSUM_UDP_IPV6)) { 4990 fp->eth_q_stats.tx_ofld_frames_csum_udp++; 4991 4992 /* 4993 * Everest1 (i.e. 57710, 57711, 57711E) does not natively support UDP 4994 * checksums and does not know anything about the UDP header and where 4995 * the checksum field is located. It only knows about TCP. Therefore 4996 * we "lie" to the hardware for outgoing UDP packets w/ checksum 4997 * offload. Since the checksum field offset for TCP is 16 bytes and 4998 * for UDP it is 6 bytes we pass a pointer to the hardware that is 10 4999 * bytes less than the start of the UDP header. This allows the 5000 * hardware to write the checksum in the correct spot. But the 5001 * hardware will compute a checksum which includes the last 10 bytes 5002 * of the IP header. To correct this we tweak the stack computed 5003 * pseudo checksum by folding in the calculation of the inverse 5004 * checksum for those final 10 bytes of the IP header. This allows 5005 * the correct checksum to be computed by the hardware. 5006 */ 5007 5008 /* set pointer 10 bytes before UDP header */ 5009 tmp_uh = (uint32_t *)((uint8_t *)uh - 10); 5010 5011 /* calculate a pseudo header checksum over the first 10 bytes */ 5012 tmp_csum = in_pseudo(*tmp_uh, 5013 *(tmp_uh + 1), 5014 *(uint16_t *)(tmp_uh + 2)); 5015 5016 pbd->tcp_pseudo_csum = ntohs(in_addword(uh->uh_sum, ~tmp_csum)); 5017 } 5018 5019 return (hlen * 2); /* entire header length, number of bytes */ 5020 } 5021 5022 static void 5023 bxe_set_pbd_lso_e2(struct mbuf *m, 5024 uint32_t *parsing_data) 5025 { 5026 *parsing_data |= ((m->m_pkthdr.tso_segsz << 5027 ETH_TX_PARSE_BD_E2_LSO_MSS_SHIFT) & 5028 ETH_TX_PARSE_BD_E2_LSO_MSS); 5029 5030 /* XXX test for IPv6 with extension header... */ 5031 } 5032 5033 static void 5034 bxe_set_pbd_lso(struct mbuf *m, 5035 struct eth_tx_parse_bd_e1x *pbd) 5036 { 5037 struct ether_vlan_header *eh = NULL; 5038 struct ip *ip = NULL; 5039 struct tcphdr *th = NULL; 5040 int e_hlen; 5041 5042 /* get the Ethernet header */ 5043 eh = mtod(m, struct ether_vlan_header *); 5044 5045 /* handle VLAN encapsulation if present */ 5046 e_hlen = (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) ? 5047 (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN) : ETHER_HDR_LEN; 5048 5049 /* get the IP and TCP header, with LSO entire header in first mbuf */ 5050 /* XXX assuming IPv4 */ 5051 ip = (struct ip *)(m->m_data + e_hlen); 5052 th = (struct tcphdr *)((caddr_t)ip + (ip->ip_hl << 2)); 5053 5054 pbd->lso_mss = htole16(m->m_pkthdr.tso_segsz); 5055 pbd->tcp_send_seq = ntohl(th->th_seq); 5056 pbd->tcp_flags = ((ntohl(((uint32_t *)th)[3]) >> 16) & 0xff); 5057 5058 #if 1 5059 /* XXX IPv4 */ 5060 pbd->ip_id = ntohs(ip->ip_id); 5061 pbd->tcp_pseudo_csum = 5062 ntohs(in_pseudo(ip->ip_src.s_addr, 5063 ip->ip_dst.s_addr, 5064 htons(IPPROTO_TCP))); 5065 #else 5066 /* XXX IPv6 */ 5067 pbd->tcp_pseudo_csum = 5068 ntohs(in_pseudo(&ip6->ip6_src, 5069 &ip6->ip6_dst, 5070 htons(IPPROTO_TCP))); 5071 #endif 5072 5073 pbd->global_data |= 5074 htole16(ETH_TX_PARSE_BD_E1X_PSEUDO_CS_WITHOUT_LEN); 5075 } 5076 5077 /* 5078 * Encapsulte an mbuf cluster into the tx bd chain and makes the memory 5079 * visible to the controller. 5080 * 5081 * If an mbuf is submitted to this routine and cannot be given to the 5082 * controller (e.g. it has too many fragments) then the function may free 5083 * the mbuf and return to the caller. 5084 * 5085 * Returns: 5086 * 0 = Success, !0 = Failure 5087 * Note the side effect that an mbuf may be freed if it causes a problem. 5088 */ 5089 static int 5090 bxe_tx_encap(struct bxe_fastpath *fp, struct mbuf **m_head) 5091 { 5092 bus_dma_segment_t segs[32]; 5093 struct mbuf *m0; 5094 struct bxe_sw_tx_bd *tx_buf; 5095 struct eth_tx_parse_bd_e1x *pbd_e1x = NULL; 5096 struct eth_tx_parse_bd_e2 *pbd_e2 = NULL; 5097 /* struct eth_tx_parse_2nd_bd *pbd2 = NULL; */ 5098 struct eth_tx_bd *tx_data_bd; 5099 struct eth_tx_bd *tx_total_pkt_size_bd; 5100 struct eth_tx_start_bd *tx_start_bd; 5101 uint16_t bd_prod, pkt_prod, total_pkt_size; 5102 uint8_t mac_type; 5103 int defragged, error, nsegs, rc, nbds, vlan_off, ovlan; 5104 struct bxe_softc *sc; 5105 uint16_t tx_bd_avail; 5106 struct ether_vlan_header *eh; 5107 uint32_t pbd_e2_parsing_data = 0; 5108 uint8_t hlen = 0; 5109 int tmp_bd; 5110 int i; 5111 5112 sc = fp->sc; 5113 5114 M_ASSERTPKTHDR(*m_head); 5115 5116 m0 = *m_head; 5117 rc = defragged = nbds = ovlan = vlan_off = total_pkt_size = 0; 5118 tx_start_bd = NULL; 5119 tx_data_bd = NULL; 5120 tx_total_pkt_size_bd = NULL; 5121 5122 /* get the H/W pointer for packets and BDs */ 5123 pkt_prod = fp->tx_pkt_prod; 5124 bd_prod = fp->tx_bd_prod; 5125 5126 mac_type = UNICAST_ADDRESS; 5127 5128 /* map the mbuf into the next open DMAable memory */ 5129 tx_buf = &fp->tx_mbuf_chain[TX_BD(pkt_prod)]; 5130 error = bus_dmamap_load_mbuf_sg(fp->tx_mbuf_tag, 5131 tx_buf->m_map, m0, 5132 segs, &nsegs, BUS_DMA_NOWAIT); 5133 5134 /* mapping errors */ 5135 if(__predict_false(error != 0)) { 5136 fp->eth_q_stats.tx_dma_mapping_failure++; 5137 if (error == ENOMEM) { 5138 /* resource issue, try again later */ 5139 rc = ENOMEM; 5140 } else if (error == EFBIG) { 5141 /* possibly recoverable with defragmentation */ 5142 fp->eth_q_stats.mbuf_defrag_attempts++; 5143 m0 = m_defrag(*m_head, M_NOWAIT); 5144 if (m0 == NULL) { 5145 fp->eth_q_stats.mbuf_defrag_failures++; 5146 rc = ENOBUFS; 5147 } else { 5148 /* defrag successful, try mapping again */ 5149 *m_head = m0; 5150 error = bus_dmamap_load_mbuf_sg(fp->tx_mbuf_tag, 5151 tx_buf->m_map, m0, 5152 segs, &nsegs, BUS_DMA_NOWAIT); 5153 if (error) { 5154 fp->eth_q_stats.tx_dma_mapping_failure++; 5155 rc = error; 5156 } 5157 } 5158 } else { 5159 /* unknown, unrecoverable mapping error */ 5160 BLOGE(sc, "Unknown TX mapping error rc=%d\n", error); 5161 bxe_dump_mbuf(sc, m0, FALSE); 5162 rc = error; 5163 } 5164 5165 goto bxe_tx_encap_continue; 5166 } 5167 5168 tx_bd_avail = bxe_tx_avail(sc, fp); 5169 5170 /* make sure there is enough room in the send queue */ 5171 if (__predict_false(tx_bd_avail < (nsegs + 2))) { 5172 /* Recoverable, try again later. */ 5173 fp->eth_q_stats.tx_hw_queue_full++; 5174 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map); 5175 rc = ENOMEM; 5176 goto bxe_tx_encap_continue; 5177 } 5178 5179 /* capture the current H/W TX chain high watermark */ 5180 if (__predict_false(fp->eth_q_stats.tx_hw_max_queue_depth < 5181 (TX_BD_USABLE - tx_bd_avail))) { 5182 fp->eth_q_stats.tx_hw_max_queue_depth = (TX_BD_USABLE - tx_bd_avail); 5183 } 5184 5185 /* make sure it fits in the packet window */ 5186 if (__predict_false(nsegs > BXE_MAX_SEGMENTS)) { 5187 /* 5188 * The mbuf may be to big for the controller to handle. If the frame 5189 * is a TSO frame we'll need to do an additional check. 5190 */ 5191 if (m0->m_pkthdr.csum_flags & CSUM_TSO) { 5192 if (bxe_chktso_window(sc, nsegs, segs, m0) == 0) { 5193 goto bxe_tx_encap_continue; /* OK to send */ 5194 } else { 5195 fp->eth_q_stats.tx_window_violation_tso++; 5196 } 5197 } else { 5198 fp->eth_q_stats.tx_window_violation_std++; 5199 } 5200 5201 /* lets try to defragment this mbuf and remap it */ 5202 fp->eth_q_stats.mbuf_defrag_attempts++; 5203 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map); 5204 5205 m0 = m_defrag(*m_head, M_NOWAIT); 5206 if (m0 == NULL) { 5207 fp->eth_q_stats.mbuf_defrag_failures++; 5208 /* Ugh, just drop the frame... :( */ 5209 rc = ENOBUFS; 5210 } else { 5211 /* defrag successful, try mapping again */ 5212 *m_head = m0; 5213 error = bus_dmamap_load_mbuf_sg(fp->tx_mbuf_tag, 5214 tx_buf->m_map, m0, 5215 segs, &nsegs, BUS_DMA_NOWAIT); 5216 if (error) { 5217 fp->eth_q_stats.tx_dma_mapping_failure++; 5218 /* No sense in trying to defrag/copy chain, drop it. :( */ 5219 rc = error; 5220 } else { 5221 /* if the chain is still too long then drop it */ 5222 if(m0->m_pkthdr.csum_flags & CSUM_TSO) { 5223 /* 5224 * in case TSO is enabled nsegs should be checked against 5225 * BXE_TSO_MAX_SEGMENTS 5226 */ 5227 if (__predict_false(nsegs > BXE_TSO_MAX_SEGMENTS)) { 5228 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map); 5229 fp->eth_q_stats.nsegs_path1_errors++; 5230 rc = ENODEV; 5231 } 5232 } else { 5233 if (__predict_false(nsegs > BXE_MAX_SEGMENTS)) { 5234 bus_dmamap_unload(fp->tx_mbuf_tag, tx_buf->m_map); 5235 fp->eth_q_stats.nsegs_path2_errors++; 5236 rc = ENODEV; 5237 } 5238 } 5239 } 5240 } 5241 } 5242 5243 bxe_tx_encap_continue: 5244 5245 /* Check for errors */ 5246 if (rc) { 5247 if (rc == ENOMEM) { 5248 /* recoverable try again later */ 5249 } else { 5250 fp->eth_q_stats.tx_soft_errors++; 5251 fp->eth_q_stats.mbuf_alloc_tx--; 5252 m_freem(*m_head); 5253 *m_head = NULL; 5254 } 5255 5256 return (rc); 5257 } 5258 5259 /* set flag according to packet type (UNICAST_ADDRESS is default) */ 5260 if (m0->m_flags & M_BCAST) { 5261 mac_type = BROADCAST_ADDRESS; 5262 } else if (m0->m_flags & M_MCAST) { 5263 mac_type = MULTICAST_ADDRESS; 5264 } 5265 5266 /* store the mbuf into the mbuf ring */ 5267 tx_buf->m = m0; 5268 tx_buf->first_bd = fp->tx_bd_prod; 5269 tx_buf->flags = 0; 5270 5271 /* prepare the first transmit (start) BD for the mbuf */ 5272 tx_start_bd = &fp->tx_chain[TX_BD(bd_prod)].start_bd; 5273 5274 BLOGD(sc, DBG_TX, 5275 "sending pkt_prod=%u tx_buf=%p next_idx=%u bd=%u tx_start_bd=%p\n", 5276 pkt_prod, tx_buf, fp->tx_pkt_prod, bd_prod, tx_start_bd); 5277 5278 tx_start_bd->addr_lo = htole32(U64_LO(segs[0].ds_addr)); 5279 tx_start_bd->addr_hi = htole32(U64_HI(segs[0].ds_addr)); 5280 tx_start_bd->nbytes = htole16(segs[0].ds_len); 5281 total_pkt_size += tx_start_bd->nbytes; 5282 tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD; 5283 5284 tx_start_bd->general_data = (1 << ETH_TX_START_BD_HDR_NBDS_SHIFT); 5285 5286 /* all frames have at least Start BD + Parsing BD */ 5287 nbds = nsegs + 1; 5288 tx_start_bd->nbd = htole16(nbds); 5289 5290 if (m0->m_flags & M_VLANTAG) { 5291 tx_start_bd->vlan_or_ethertype = htole16(m0->m_pkthdr.ether_vtag); 5292 tx_start_bd->bd_flags.as_bitfield |= 5293 (X_ETH_OUTBAND_VLAN << ETH_TX_BD_FLAGS_VLAN_MODE_SHIFT); 5294 } else { 5295 /* vf tx, start bd must hold the ethertype for fw to enforce it */ 5296 if (IS_VF(sc)) { 5297 /* map ethernet header to find type and header length */ 5298 eh = mtod(m0, struct ether_vlan_header *); 5299 tx_start_bd->vlan_or_ethertype = eh->evl_encap_proto; 5300 } else { 5301 /* used by FW for packet accounting */ 5302 tx_start_bd->vlan_or_ethertype = htole16(fp->tx_pkt_prod); 5303 } 5304 } 5305 5306 /* 5307 * add a parsing BD from the chain. The parsing BD is always added 5308 * though it is only used for TSO and chksum 5309 */ 5310 bd_prod = TX_BD_NEXT(bd_prod); 5311 5312 if (m0->m_pkthdr.csum_flags) { 5313 if (m0->m_pkthdr.csum_flags & CSUM_IP) { 5314 fp->eth_q_stats.tx_ofld_frames_csum_ip++; 5315 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_IP_CSUM; 5316 } 5317 5318 if (m0->m_pkthdr.csum_flags & CSUM_TCP_IPV6) { 5319 tx_start_bd->bd_flags.as_bitfield |= (ETH_TX_BD_FLAGS_IPV6 | 5320 ETH_TX_BD_FLAGS_L4_CSUM); 5321 } else if (m0->m_pkthdr.csum_flags & CSUM_UDP_IPV6) { 5322 tx_start_bd->bd_flags.as_bitfield |= (ETH_TX_BD_FLAGS_IPV6 | 5323 ETH_TX_BD_FLAGS_IS_UDP | 5324 ETH_TX_BD_FLAGS_L4_CSUM); 5325 } else if ((m0->m_pkthdr.csum_flags & CSUM_TCP) || 5326 (m0->m_pkthdr.csum_flags & CSUM_TSO)) { 5327 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_L4_CSUM; 5328 } else if (m0->m_pkthdr.csum_flags & CSUM_UDP) { 5329 tx_start_bd->bd_flags.as_bitfield |= (ETH_TX_BD_FLAGS_L4_CSUM | 5330 ETH_TX_BD_FLAGS_IS_UDP); 5331 } 5332 } 5333 5334 if (!CHIP_IS_E1x(sc)) { 5335 pbd_e2 = &fp->tx_chain[TX_BD(bd_prod)].parse_bd_e2; 5336 memset(pbd_e2, 0, sizeof(struct eth_tx_parse_bd_e2)); 5337 5338 if (m0->m_pkthdr.csum_flags) { 5339 hlen = bxe_set_pbd_csum_e2(fp, m0, &pbd_e2_parsing_data); 5340 } 5341 5342 SET_FLAG(pbd_e2_parsing_data, ETH_TX_PARSE_BD_E2_ETH_ADDR_TYPE, 5343 mac_type); 5344 } else { 5345 uint16_t global_data = 0; 5346 5347 pbd_e1x = &fp->tx_chain[TX_BD(bd_prod)].parse_bd_e1x; 5348 memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x)); 5349 5350 if (m0->m_pkthdr.csum_flags) { 5351 hlen = bxe_set_pbd_csum(fp, m0, pbd_e1x); 5352 } 5353 5354 SET_FLAG(global_data, 5355 ETH_TX_PARSE_BD_E1X_ETH_ADDR_TYPE, mac_type); 5356 pbd_e1x->global_data |= htole16(global_data); 5357 } 5358 5359 /* setup the parsing BD with TSO specific info */ 5360 if (m0->m_pkthdr.csum_flags & CSUM_TSO) { 5361 fp->eth_q_stats.tx_ofld_frames_lso++; 5362 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_SW_LSO; 5363 5364 if (__predict_false(tx_start_bd->nbytes > hlen)) { 5365 fp->eth_q_stats.tx_ofld_frames_lso_hdr_splits++; 5366 5367 /* split the first BD into header/data making the fw job easy */ 5368 nbds++; 5369 tx_start_bd->nbd = htole16(nbds); 5370 tx_start_bd->nbytes = htole16(hlen); 5371 5372 bd_prod = TX_BD_NEXT(bd_prod); 5373 5374 /* new transmit BD after the tx_parse_bd */ 5375 tx_data_bd = &fp->tx_chain[TX_BD(bd_prod)].reg_bd; 5376 tx_data_bd->addr_hi = htole32(U64_HI(segs[0].ds_addr + hlen)); 5377 tx_data_bd->addr_lo = htole32(U64_LO(segs[0].ds_addr + hlen)); 5378 tx_data_bd->nbytes = htole16(segs[0].ds_len - hlen); 5379 if (tx_total_pkt_size_bd == NULL) { 5380 tx_total_pkt_size_bd = tx_data_bd; 5381 } 5382 5383 BLOGD(sc, DBG_TX, 5384 "TSO split header size is %d (%x:%x) nbds %d\n", 5385 le16toh(tx_start_bd->nbytes), 5386 le32toh(tx_start_bd->addr_hi), 5387 le32toh(tx_start_bd->addr_lo), 5388 nbds); 5389 } 5390 5391 if (!CHIP_IS_E1x(sc)) { 5392 bxe_set_pbd_lso_e2(m0, &pbd_e2_parsing_data); 5393 } else { 5394 bxe_set_pbd_lso(m0, pbd_e1x); 5395 } 5396 } 5397 5398 if (pbd_e2_parsing_data) { 5399 pbd_e2->parsing_data = htole32(pbd_e2_parsing_data); 5400 } 5401 5402 /* prepare remaining BDs, start tx bd contains first seg/frag */ 5403 for (i = 1; i < nsegs ; i++) { 5404 bd_prod = TX_BD_NEXT(bd_prod); 5405 tx_data_bd = &fp->tx_chain[TX_BD(bd_prod)].reg_bd; 5406 tx_data_bd->addr_lo = htole32(U64_LO(segs[i].ds_addr)); 5407 tx_data_bd->addr_hi = htole32(U64_HI(segs[i].ds_addr)); 5408 tx_data_bd->nbytes = htole16(segs[i].ds_len); 5409 if (tx_total_pkt_size_bd == NULL) { 5410 tx_total_pkt_size_bd = tx_data_bd; 5411 } 5412 total_pkt_size += tx_data_bd->nbytes; 5413 } 5414 5415 BLOGD(sc, DBG_TX, "last bd %p\n", tx_data_bd); 5416 5417 if (tx_total_pkt_size_bd != NULL) { 5418 tx_total_pkt_size_bd->total_pkt_bytes = total_pkt_size; 5419 } 5420 5421 if (__predict_false(sc->debug & DBG_TX)) { 5422 tmp_bd = tx_buf->first_bd; 5423 for (i = 0; i < nbds; i++) 5424 { 5425 if (i == 0) { 5426 BLOGD(sc, DBG_TX, 5427 "TX Strt: %p bd=%d nbd=%d vlan=0x%x " 5428 "bd_flags=0x%x hdr_nbds=%d\n", 5429 tx_start_bd, 5430 tmp_bd, 5431 le16toh(tx_start_bd->nbd), 5432 le16toh(tx_start_bd->vlan_or_ethertype), 5433 tx_start_bd->bd_flags.as_bitfield, 5434 (tx_start_bd->general_data & ETH_TX_START_BD_HDR_NBDS)); 5435 } else if (i == 1) { 5436 if (pbd_e1x) { 5437 BLOGD(sc, DBG_TX, 5438 "-> Prse: %p bd=%d global=0x%x ip_hlen_w=%u " 5439 "ip_id=%u lso_mss=%u tcp_flags=0x%x csum=0x%x " 5440 "tcp_seq=%u total_hlen_w=%u\n", 5441 pbd_e1x, 5442 tmp_bd, 5443 pbd_e1x->global_data, 5444 pbd_e1x->ip_hlen_w, 5445 pbd_e1x->ip_id, 5446 pbd_e1x->lso_mss, 5447 pbd_e1x->tcp_flags, 5448 pbd_e1x->tcp_pseudo_csum, 5449 pbd_e1x->tcp_send_seq, 5450 le16toh(pbd_e1x->total_hlen_w)); 5451 } else { /* if (pbd_e2) */ 5452 BLOGD(sc, DBG_TX, 5453 "-> Parse: %p bd=%d dst=%02x:%02x:%02x " 5454 "src=%02x:%02x:%02x parsing_data=0x%x\n", 5455 pbd_e2, 5456 tmp_bd, 5457 pbd_e2->data.mac_addr.dst_hi, 5458 pbd_e2->data.mac_addr.dst_mid, 5459 pbd_e2->data.mac_addr.dst_lo, 5460 pbd_e2->data.mac_addr.src_hi, 5461 pbd_e2->data.mac_addr.src_mid, 5462 pbd_e2->data.mac_addr.src_lo, 5463 pbd_e2->parsing_data); 5464 } 5465 } 5466 5467 if (i != 1) { /* skip parse db as it doesn't hold data */ 5468 tx_data_bd = &fp->tx_chain[TX_BD(tmp_bd)].reg_bd; 5469 BLOGD(sc, DBG_TX, 5470 "-> Frag: %p bd=%d nbytes=%d hi=0x%x lo: 0x%x\n", 5471 tx_data_bd, 5472 tmp_bd, 5473 le16toh(tx_data_bd->nbytes), 5474 le32toh(tx_data_bd->addr_hi), 5475 le32toh(tx_data_bd->addr_lo)); 5476 } 5477 5478 tmp_bd = TX_BD_NEXT(tmp_bd); 5479 } 5480 } 5481 5482 BLOGD(sc, DBG_TX, "doorbell: nbds=%d bd=%u\n", nbds, bd_prod); 5483 5484 /* update TX BD producer index value for next TX */ 5485 bd_prod = TX_BD_NEXT(bd_prod); 5486 5487 /* 5488 * If the chain of tx_bd's describing this frame is adjacent to or spans 5489 * an eth_tx_next_bd element then we need to increment the nbds value. 5490 */ 5491 if (TX_BD_IDX(bd_prod) < nbds) { 5492 nbds++; 5493 } 5494 5495 /* don't allow reordering of writes for nbd and packets */ 5496 mb(); 5497 5498 fp->tx_db.data.prod += nbds; 5499 5500 /* producer points to the next free tx_bd at this point */ 5501 fp->tx_pkt_prod++; 5502 fp->tx_bd_prod = bd_prod; 5503 5504 DOORBELL(sc, fp->index, fp->tx_db.raw); 5505 5506 fp->eth_q_stats.tx_pkts++; 5507 5508 /* Prevent speculative reads from getting ahead of the status block. */ 5509 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle, 5510 0, 0, BUS_SPACE_BARRIER_READ); 5511 5512 /* Prevent speculative reads from getting ahead of the doorbell. */ 5513 bus_space_barrier(sc->bar[BAR2].tag, sc->bar[BAR2].handle, 5514 0, 0, BUS_SPACE_BARRIER_READ); 5515 5516 return (0); 5517 } 5518 5519 static void 5520 bxe_tx_start_locked(struct bxe_softc *sc, 5521 if_t ifp, 5522 struct bxe_fastpath *fp) 5523 { 5524 struct mbuf *m = NULL; 5525 int tx_count = 0; 5526 uint16_t tx_bd_avail; 5527 5528 BXE_FP_TX_LOCK_ASSERT(fp); 5529 5530 /* keep adding entries while there are frames to send */ 5531 while (!if_sendq_empty(ifp)) { 5532 5533 /* 5534 * check for any frames to send 5535 * dequeue can still be NULL even if queue is not empty 5536 */ 5537 m = if_dequeue(ifp); 5538 if (__predict_false(m == NULL)) { 5539 break; 5540 } 5541 5542 /* the mbuf now belongs to us */ 5543 fp->eth_q_stats.mbuf_alloc_tx++; 5544 5545 /* 5546 * Put the frame into the transmit ring. If we don't have room, 5547 * place the mbuf back at the head of the TX queue, set the 5548 * OACTIVE flag, and wait for the NIC to drain the chain. 5549 */ 5550 if (__predict_false(bxe_tx_encap(fp, &m))) { 5551 fp->eth_q_stats.tx_encap_failures++; 5552 if (m != NULL) { 5553 /* mark the TX queue as full and return the frame */ 5554 if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0); 5555 if_sendq_prepend(ifp, m); 5556 fp->eth_q_stats.mbuf_alloc_tx--; 5557 fp->eth_q_stats.tx_queue_xoff++; 5558 } 5559 5560 /* stop looking for more work */ 5561 break; 5562 } 5563 5564 /* the frame was enqueued successfully */ 5565 tx_count++; 5566 5567 /* send a copy of the frame to any BPF listeners. */ 5568 ether_bpf_mtap_if(ifp, m); 5569 5570 tx_bd_avail = bxe_tx_avail(sc, fp); 5571 5572 /* handle any completions if we're running low */ 5573 if (tx_bd_avail < BXE_TX_CLEANUP_THRESHOLD) { 5574 /* bxe_txeof will set IFF_DRV_OACTIVE appropriately */ 5575 bxe_txeof(sc, fp); 5576 if (if_getdrvflags(ifp) & IFF_DRV_OACTIVE) { 5577 break; 5578 } 5579 } 5580 } 5581 5582 /* all TX packets were dequeued and/or the tx ring is full */ 5583 if (tx_count > 0) { 5584 /* reset the TX watchdog timeout timer */ 5585 fp->watchdog_timer = BXE_TX_TIMEOUT; 5586 } 5587 } 5588 5589 /* Legacy (non-RSS) dispatch routine */ 5590 static void 5591 bxe_tx_start(if_t ifp) 5592 { 5593 struct bxe_softc *sc; 5594 struct bxe_fastpath *fp; 5595 5596 sc = if_getsoftc(ifp); 5597 5598 if (!(if_getdrvflags(ifp) & IFF_DRV_RUNNING)) { 5599 BLOGW(sc, "Interface not running, ignoring transmit request\n"); 5600 return; 5601 } 5602 5603 if (!sc->link_vars.link_up) { 5604 BLOGW(sc, "Interface link is down, ignoring transmit request\n"); 5605 return; 5606 } 5607 5608 fp = &sc->fp[0]; 5609 5610 if (if_getdrvflags(ifp) & IFF_DRV_OACTIVE) { 5611 fp->eth_q_stats.tx_queue_full_return++; 5612 return; 5613 } 5614 5615 BXE_FP_TX_LOCK(fp); 5616 bxe_tx_start_locked(sc, ifp, fp); 5617 BXE_FP_TX_UNLOCK(fp); 5618 } 5619 5620 static int 5621 bxe_tx_mq_start_locked(struct bxe_softc *sc, 5622 if_t ifp, 5623 struct bxe_fastpath *fp, 5624 struct mbuf *m) 5625 { 5626 struct buf_ring *tx_br = fp->tx_br; 5627 struct mbuf *next; 5628 int depth, rc, tx_count; 5629 uint16_t tx_bd_avail; 5630 5631 rc = tx_count = 0; 5632 5633 BXE_FP_TX_LOCK_ASSERT(fp); 5634 5635 if (sc->state != BXE_STATE_OPEN) { 5636 fp->eth_q_stats.bxe_tx_mq_sc_state_failures++; 5637 return ENETDOWN; 5638 } 5639 5640 if (!tx_br) { 5641 BLOGE(sc, "Multiqueue TX and no buf_ring!\n"); 5642 return (EINVAL); 5643 } 5644 5645 if (m != NULL) { 5646 rc = drbr_enqueue(ifp, tx_br, m); 5647 if (rc != 0) { 5648 fp->eth_q_stats.tx_soft_errors++; 5649 goto bxe_tx_mq_start_locked_exit; 5650 } 5651 } 5652 5653 if (!sc->link_vars.link_up || !(if_getdrvflags(ifp) & IFF_DRV_RUNNING)) { 5654 fp->eth_q_stats.tx_request_link_down_failures++; 5655 goto bxe_tx_mq_start_locked_exit; 5656 } 5657 5658 /* fetch the depth of the driver queue */ 5659 depth = drbr_inuse(ifp, tx_br); 5660 if (depth > fp->eth_q_stats.tx_max_drbr_queue_depth) { 5661 fp->eth_q_stats.tx_max_drbr_queue_depth = depth; 5662 } 5663 5664 /* keep adding entries while there are frames to send */ 5665 while ((next = drbr_peek(ifp, tx_br)) != NULL) { 5666 /* handle any completions if we're running low */ 5667 tx_bd_avail = bxe_tx_avail(sc, fp); 5668 if (tx_bd_avail < BXE_TX_CLEANUP_THRESHOLD) { 5669 /* bxe_txeof will set IFF_DRV_OACTIVE appropriately */ 5670 bxe_txeof(sc, fp); 5671 tx_bd_avail = bxe_tx_avail(sc, fp); 5672 if (tx_bd_avail < (BXE_TSO_MAX_SEGMENTS + 1)) { 5673 fp->eth_q_stats.bd_avail_too_less_failures++; 5674 m_freem(next); 5675 drbr_advance(ifp, tx_br); 5676 rc = ENOBUFS; 5677 break; 5678 } 5679 } 5680 5681 /* the mbuf now belongs to us */ 5682 fp->eth_q_stats.mbuf_alloc_tx++; 5683 5684 /* 5685 * Put the frame into the transmit ring. If we don't have room, 5686 * place the mbuf back at the head of the TX queue, set the 5687 * OACTIVE flag, and wait for the NIC to drain the chain. 5688 */ 5689 rc = bxe_tx_encap(fp, &next); 5690 if (__predict_false(rc != 0)) { 5691 fp->eth_q_stats.tx_encap_failures++; 5692 if (next != NULL) { 5693 /* mark the TX queue as full and save the frame */ 5694 if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0); 5695 drbr_putback(ifp, tx_br, next); 5696 fp->eth_q_stats.mbuf_alloc_tx--; 5697 fp->eth_q_stats.tx_frames_deferred++; 5698 } else 5699 drbr_advance(ifp, tx_br); 5700 5701 /* stop looking for more work */ 5702 break; 5703 } 5704 5705 /* the transmit frame was enqueued successfully */ 5706 tx_count++; 5707 5708 /* send a copy of the frame to any BPF listeners */ 5709 ether_bpf_mtap_if(ifp, next); 5710 5711 drbr_advance(ifp, tx_br); 5712 } 5713 5714 /* all TX packets were dequeued and/or the tx ring is full */ 5715 if (tx_count > 0) { 5716 /* reset the TX watchdog timeout timer */ 5717 fp->watchdog_timer = BXE_TX_TIMEOUT; 5718 } 5719 5720 bxe_tx_mq_start_locked_exit: 5721 /* If we didn't drain the drbr, enqueue a task in the future to do it. */ 5722 if (!drbr_empty(ifp, tx_br)) { 5723 fp->eth_q_stats.tx_mq_not_empty++; 5724 taskqueue_enqueue_timeout(fp->tq, &fp->tx_timeout_task, 1); 5725 } 5726 5727 return (rc); 5728 } 5729 5730 static void 5731 bxe_tx_mq_start_deferred(void *arg, 5732 int pending) 5733 { 5734 struct bxe_fastpath *fp = (struct bxe_fastpath *)arg; 5735 struct bxe_softc *sc = fp->sc; 5736 if_t ifp = sc->ifp; 5737 5738 BXE_FP_TX_LOCK(fp); 5739 bxe_tx_mq_start_locked(sc, ifp, fp, NULL); 5740 BXE_FP_TX_UNLOCK(fp); 5741 } 5742 5743 /* Multiqueue (TSS) dispatch routine. */ 5744 static int 5745 bxe_tx_mq_start(if_t ifp, 5746 struct mbuf *m) 5747 { 5748 struct bxe_softc *sc = if_getsoftc(ifp); 5749 struct bxe_fastpath *fp; 5750 int fp_index, rc; 5751 5752 fp_index = 0; /* default is the first queue */ 5753 5754 /* check if flowid is set */ 5755 5756 if (BXE_VALID_FLOWID(m)) 5757 fp_index = (m->m_pkthdr.flowid % sc->num_queues); 5758 5759 fp = &sc->fp[fp_index]; 5760 5761 if (sc->state != BXE_STATE_OPEN) { 5762 fp->eth_q_stats.bxe_tx_mq_sc_state_failures++; 5763 return ENETDOWN; 5764 } 5765 5766 if (BXE_FP_TX_TRYLOCK(fp)) { 5767 rc = bxe_tx_mq_start_locked(sc, ifp, fp, m); 5768 BXE_FP_TX_UNLOCK(fp); 5769 } else { 5770 rc = drbr_enqueue(ifp, fp->tx_br, m); 5771 taskqueue_enqueue(fp->tq, &fp->tx_task); 5772 } 5773 5774 return (rc); 5775 } 5776 5777 static void 5778 bxe_mq_flush(if_t ifp) 5779 { 5780 struct bxe_softc *sc = if_getsoftc(ifp); 5781 struct bxe_fastpath *fp; 5782 struct mbuf *m; 5783 int i; 5784 5785 for (i = 0; i < sc->num_queues; i++) { 5786 fp = &sc->fp[i]; 5787 5788 if (fp->state != BXE_FP_STATE_IRQ) { 5789 BLOGD(sc, DBG_LOAD, "Not clearing fp[%02d] buf_ring (state=%d)\n", 5790 fp->index, fp->state); 5791 continue; 5792 } 5793 5794 if (fp->tx_br != NULL) { 5795 BLOGD(sc, DBG_LOAD, "Clearing fp[%02d] buf_ring\n", fp->index); 5796 BXE_FP_TX_LOCK(fp); 5797 while ((m = buf_ring_dequeue_sc(fp->tx_br)) != NULL) { 5798 m_freem(m); 5799 } 5800 BXE_FP_TX_UNLOCK(fp); 5801 } 5802 } 5803 5804 if_qflush(ifp); 5805 } 5806 5807 static uint16_t 5808 bxe_cid_ilt_lines(struct bxe_softc *sc) 5809 { 5810 if (IS_SRIOV(sc)) { 5811 return ((BXE_FIRST_VF_CID + BXE_VF_CIDS) / ILT_PAGE_CIDS); 5812 } 5813 return (L2_ILT_LINES(sc)); 5814 } 5815 5816 static void 5817 bxe_ilt_set_info(struct bxe_softc *sc) 5818 { 5819 struct ilt_client_info *ilt_client; 5820 struct ecore_ilt *ilt = sc->ilt; 5821 uint16_t line = 0; 5822 5823 ilt->start_line = FUNC_ILT_BASE(SC_FUNC(sc)); 5824 BLOGD(sc, DBG_LOAD, "ilt starts at line %d\n", ilt->start_line); 5825 5826 /* CDU */ 5827 ilt_client = &ilt->clients[ILT_CLIENT_CDU]; 5828 ilt_client->client_num = ILT_CLIENT_CDU; 5829 ilt_client->page_size = CDU_ILT_PAGE_SZ; 5830 ilt_client->flags = ILT_CLIENT_SKIP_MEM; 5831 ilt_client->start = line; 5832 line += bxe_cid_ilt_lines(sc); 5833 5834 if (CNIC_SUPPORT(sc)) { 5835 line += CNIC_ILT_LINES; 5836 } 5837 5838 ilt_client->end = (line - 1); 5839 5840 BLOGD(sc, DBG_LOAD, 5841 "ilt client[CDU]: start %d, end %d, " 5842 "psz 0x%x, flags 0x%x, hw psz %d\n", 5843 ilt_client->start, ilt_client->end, 5844 ilt_client->page_size, 5845 ilt_client->flags, 5846 ilog2(ilt_client->page_size >> 12)); 5847 5848 /* QM */ 5849 if (QM_INIT(sc->qm_cid_count)) { 5850 ilt_client = &ilt->clients[ILT_CLIENT_QM]; 5851 ilt_client->client_num = ILT_CLIENT_QM; 5852 ilt_client->page_size = QM_ILT_PAGE_SZ; 5853 ilt_client->flags = 0; 5854 ilt_client->start = line; 5855 5856 /* 4 bytes for each cid */ 5857 line += DIV_ROUND_UP(sc->qm_cid_count * QM_QUEUES_PER_FUNC * 4, 5858 QM_ILT_PAGE_SZ); 5859 5860 ilt_client->end = (line - 1); 5861 5862 BLOGD(sc, DBG_LOAD, 5863 "ilt client[QM]: start %d, end %d, " 5864 "psz 0x%x, flags 0x%x, hw psz %d\n", 5865 ilt_client->start, ilt_client->end, 5866 ilt_client->page_size, ilt_client->flags, 5867 ilog2(ilt_client->page_size >> 12)); 5868 } 5869 5870 if (CNIC_SUPPORT(sc)) { 5871 /* SRC */ 5872 ilt_client = &ilt->clients[ILT_CLIENT_SRC]; 5873 ilt_client->client_num = ILT_CLIENT_SRC; 5874 ilt_client->page_size = SRC_ILT_PAGE_SZ; 5875 ilt_client->flags = 0; 5876 ilt_client->start = line; 5877 line += SRC_ILT_LINES; 5878 ilt_client->end = (line - 1); 5879 5880 BLOGD(sc, DBG_LOAD, 5881 "ilt client[SRC]: start %d, end %d, " 5882 "psz 0x%x, flags 0x%x, hw psz %d\n", 5883 ilt_client->start, ilt_client->end, 5884 ilt_client->page_size, ilt_client->flags, 5885 ilog2(ilt_client->page_size >> 12)); 5886 5887 /* TM */ 5888 ilt_client = &ilt->clients[ILT_CLIENT_TM]; 5889 ilt_client->client_num = ILT_CLIENT_TM; 5890 ilt_client->page_size = TM_ILT_PAGE_SZ; 5891 ilt_client->flags = 0; 5892 ilt_client->start = line; 5893 line += TM_ILT_LINES; 5894 ilt_client->end = (line - 1); 5895 5896 BLOGD(sc, DBG_LOAD, 5897 "ilt client[TM]: start %d, end %d, " 5898 "psz 0x%x, flags 0x%x, hw psz %d\n", 5899 ilt_client->start, ilt_client->end, 5900 ilt_client->page_size, ilt_client->flags, 5901 ilog2(ilt_client->page_size >> 12)); 5902 } else { 5903 ilt->clients[ILT_CLIENT_SRC].flags = 5904 (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM); 5905 ilt->clients[ILT_CLIENT_TM].flags = 5906 (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM); 5907 } 5908 5909 KASSERT((line <= ILT_MAX_LINES), ("Invalid number of ILT lines!")); 5910 } 5911 5912 static void 5913 bxe_set_fp_rx_buf_size(struct bxe_softc *sc) 5914 { 5915 int i; 5916 uint32_t rx_buf_size; 5917 5918 rx_buf_size = (IP_HEADER_ALIGNMENT_PADDING + ETH_OVERHEAD + sc->mtu); 5919 5920 for (i = 0; i < sc->num_queues; i++) { 5921 if(rx_buf_size <= MCLBYTES){ 5922 sc->fp[i].rx_buf_size = rx_buf_size; 5923 sc->fp[i].mbuf_alloc_size = MCLBYTES; 5924 }else if (rx_buf_size <= MJUMPAGESIZE){ 5925 sc->fp[i].rx_buf_size = rx_buf_size; 5926 sc->fp[i].mbuf_alloc_size = MJUMPAGESIZE; 5927 }else if (rx_buf_size <= (MJUMPAGESIZE + MCLBYTES)){ 5928 sc->fp[i].rx_buf_size = MCLBYTES; 5929 sc->fp[i].mbuf_alloc_size = MCLBYTES; 5930 }else if (rx_buf_size <= (2 * MJUMPAGESIZE)){ 5931 sc->fp[i].rx_buf_size = MJUMPAGESIZE; 5932 sc->fp[i].mbuf_alloc_size = MJUMPAGESIZE; 5933 }else { 5934 sc->fp[i].rx_buf_size = MCLBYTES; 5935 sc->fp[i].mbuf_alloc_size = MCLBYTES; 5936 } 5937 } 5938 } 5939 5940 static int 5941 bxe_alloc_ilt_mem(struct bxe_softc *sc) 5942 { 5943 int rc = 0; 5944 5945 if ((sc->ilt = 5946 (struct ecore_ilt *)malloc(sizeof(struct ecore_ilt), 5947 M_BXE_ILT, 5948 (M_NOWAIT | M_ZERO))) == NULL) { 5949 rc = 1; 5950 } 5951 5952 return (rc); 5953 } 5954 5955 static int 5956 bxe_alloc_ilt_lines_mem(struct bxe_softc *sc) 5957 { 5958 int rc = 0; 5959 5960 if ((sc->ilt->lines = 5961 (struct ilt_line *)malloc((sizeof(struct ilt_line) * ILT_MAX_LINES), 5962 M_BXE_ILT, 5963 (M_NOWAIT | M_ZERO))) == NULL) { 5964 rc = 1; 5965 } 5966 5967 return (rc); 5968 } 5969 5970 static void 5971 bxe_free_ilt_mem(struct bxe_softc *sc) 5972 { 5973 if (sc->ilt != NULL) { 5974 free(sc->ilt, M_BXE_ILT); 5975 sc->ilt = NULL; 5976 } 5977 } 5978 5979 static void 5980 bxe_free_ilt_lines_mem(struct bxe_softc *sc) 5981 { 5982 if (sc->ilt->lines != NULL) { 5983 free(sc->ilt->lines, M_BXE_ILT); 5984 sc->ilt->lines = NULL; 5985 } 5986 } 5987 5988 static void 5989 bxe_free_mem(struct bxe_softc *sc) 5990 { 5991 int i; 5992 5993 for (i = 0; i < L2_ILT_LINES(sc); i++) { 5994 bxe_dma_free(sc, &sc->context[i].vcxt_dma); 5995 sc->context[i].vcxt = NULL; 5996 sc->context[i].size = 0; 5997 } 5998 5999 ecore_ilt_mem_op(sc, ILT_MEMOP_FREE); 6000 6001 bxe_free_ilt_lines_mem(sc); 6002 6003 } 6004 6005 static int 6006 bxe_alloc_mem(struct bxe_softc *sc) 6007 { 6008 6009 int context_size; 6010 int allocated; 6011 int i; 6012 6013 /* 6014 * Allocate memory for CDU context: 6015 * This memory is allocated separately and not in the generic ILT 6016 * functions because CDU differs in few aspects: 6017 * 1. There can be multiple entities allocating memory for context - 6018 * regular L2, CNIC, and SRIOV drivers. Each separately controls 6019 * its own ILT lines. 6020 * 2. Since CDU page-size is not a single 4KB page (which is the case 6021 * for the other ILT clients), to be efficient we want to support 6022 * allocation of sub-page-size in the last entry. 6023 * 3. Context pointers are used by the driver to pass to FW / update 6024 * the context (for the other ILT clients the pointers are used just to 6025 * free the memory during unload). 6026 */ 6027 context_size = (sizeof(union cdu_context) * BXE_L2_CID_COUNT(sc)); 6028 for (i = 0, allocated = 0; allocated < context_size; i++) { 6029 sc->context[i].size = min(CDU_ILT_PAGE_SZ, 6030 (context_size - allocated)); 6031 6032 if (bxe_dma_alloc(sc, sc->context[i].size, 6033 &sc->context[i].vcxt_dma, 6034 "cdu context") != 0) { 6035 bxe_free_mem(sc); 6036 return (-1); 6037 } 6038 6039 sc->context[i].vcxt = 6040 (union cdu_context *)sc->context[i].vcxt_dma.vaddr; 6041 6042 allocated += sc->context[i].size; 6043 } 6044 6045 bxe_alloc_ilt_lines_mem(sc); 6046 6047 BLOGD(sc, DBG_LOAD, "ilt=%p start_line=%u lines=%p\n", 6048 sc->ilt, sc->ilt->start_line, sc->ilt->lines); 6049 { 6050 for (i = 0; i < 4; i++) { 6051 BLOGD(sc, DBG_LOAD, 6052 "c%d page_size=%u start=%u end=%u num=%u flags=0x%x\n", 6053 i, 6054 sc->ilt->clients[i].page_size, 6055 sc->ilt->clients[i].start, 6056 sc->ilt->clients[i].end, 6057 sc->ilt->clients[i].client_num, 6058 sc->ilt->clients[i].flags); 6059 } 6060 } 6061 if (ecore_ilt_mem_op(sc, ILT_MEMOP_ALLOC)) { 6062 BLOGE(sc, "ecore_ilt_mem_op ILT_MEMOP_ALLOC failed\n"); 6063 bxe_free_mem(sc); 6064 return (-1); 6065 } 6066 6067 return (0); 6068 } 6069 6070 static void 6071 bxe_free_rx_bd_chain(struct bxe_fastpath *fp) 6072 { 6073 int i; 6074 6075 if (fp->rx_mbuf_tag == NULL) { 6076 return; 6077 } 6078 6079 /* free all mbufs and unload all maps */ 6080 for (i = 0; i < RX_BD_TOTAL; i++) { 6081 if (fp->rx_mbuf_chain[i].m_map != NULL) { 6082 bus_dmamap_sync(fp->rx_mbuf_tag, 6083 fp->rx_mbuf_chain[i].m_map, 6084 BUS_DMASYNC_POSTREAD); 6085 bus_dmamap_unload(fp->rx_mbuf_tag, 6086 fp->rx_mbuf_chain[i].m_map); 6087 } 6088 6089 if (fp->rx_mbuf_chain[i].m != NULL) { 6090 m_freem(fp->rx_mbuf_chain[i].m); 6091 fp->rx_mbuf_chain[i].m = NULL; 6092 fp->eth_q_stats.mbuf_alloc_rx--; 6093 } 6094 } 6095 } 6096 6097 static void 6098 bxe_free_tpa_pool(struct bxe_fastpath *fp) 6099 { 6100 struct bxe_softc *sc; 6101 int i, max_agg_queues; 6102 6103 sc = fp->sc; 6104 6105 if (fp->rx_mbuf_tag == NULL) { 6106 return; 6107 } 6108 6109 max_agg_queues = MAX_AGG_QS(sc); 6110 6111 /* release all mbufs and unload all DMA maps in the TPA pool */ 6112 for (i = 0; i < max_agg_queues; i++) { 6113 if (fp->rx_tpa_info[i].bd.m_map != NULL) { 6114 bus_dmamap_sync(fp->rx_mbuf_tag, 6115 fp->rx_tpa_info[i].bd.m_map, 6116 BUS_DMASYNC_POSTREAD); 6117 bus_dmamap_unload(fp->rx_mbuf_tag, 6118 fp->rx_tpa_info[i].bd.m_map); 6119 } 6120 6121 if (fp->rx_tpa_info[i].bd.m != NULL) { 6122 m_freem(fp->rx_tpa_info[i].bd.m); 6123 fp->rx_tpa_info[i].bd.m = NULL; 6124 fp->eth_q_stats.mbuf_alloc_tpa--; 6125 } 6126 } 6127 } 6128 6129 static void 6130 bxe_free_sge_chain(struct bxe_fastpath *fp) 6131 { 6132 int i; 6133 6134 if (fp->rx_sge_mbuf_tag == NULL) { 6135 return; 6136 } 6137 6138 /* rree all mbufs and unload all maps */ 6139 for (i = 0; i < RX_SGE_TOTAL; i++) { 6140 if (fp->rx_sge_mbuf_chain[i].m_map != NULL) { 6141 bus_dmamap_sync(fp->rx_sge_mbuf_tag, 6142 fp->rx_sge_mbuf_chain[i].m_map, 6143 BUS_DMASYNC_POSTREAD); 6144 bus_dmamap_unload(fp->rx_sge_mbuf_tag, 6145 fp->rx_sge_mbuf_chain[i].m_map); 6146 } 6147 6148 if (fp->rx_sge_mbuf_chain[i].m != NULL) { 6149 m_freem(fp->rx_sge_mbuf_chain[i].m); 6150 fp->rx_sge_mbuf_chain[i].m = NULL; 6151 fp->eth_q_stats.mbuf_alloc_sge--; 6152 } 6153 } 6154 } 6155 6156 static void 6157 bxe_free_fp_buffers(struct bxe_softc *sc) 6158 { 6159 struct bxe_fastpath *fp; 6160 int i; 6161 6162 for (i = 0; i < sc->num_queues; i++) { 6163 fp = &sc->fp[i]; 6164 6165 if (fp->tx_br != NULL) { 6166 /* just in case bxe_mq_flush() wasn't called */ 6167 if (mtx_initialized(&fp->tx_mtx)) { 6168 struct mbuf *m; 6169 6170 BXE_FP_TX_LOCK(fp); 6171 while ((m = buf_ring_dequeue_sc(fp->tx_br)) != NULL) 6172 m_freem(m); 6173 BXE_FP_TX_UNLOCK(fp); 6174 } 6175 } 6176 6177 /* free all RX buffers */ 6178 bxe_free_rx_bd_chain(fp); 6179 bxe_free_tpa_pool(fp); 6180 bxe_free_sge_chain(fp); 6181 6182 if (fp->eth_q_stats.mbuf_alloc_rx != 0) { 6183 BLOGE(sc, "failed to claim all rx mbufs (%d left)\n", 6184 fp->eth_q_stats.mbuf_alloc_rx); 6185 } 6186 6187 if (fp->eth_q_stats.mbuf_alloc_sge != 0) { 6188 BLOGE(sc, "failed to claim all sge mbufs (%d left)\n", 6189 fp->eth_q_stats.mbuf_alloc_sge); 6190 } 6191 6192 if (fp->eth_q_stats.mbuf_alloc_tpa != 0) { 6193 BLOGE(sc, "failed to claim all sge mbufs (%d left)\n", 6194 fp->eth_q_stats.mbuf_alloc_tpa); 6195 } 6196 6197 if (fp->eth_q_stats.mbuf_alloc_tx != 0) { 6198 BLOGE(sc, "failed to release tx mbufs (%d left)\n", 6199 fp->eth_q_stats.mbuf_alloc_tx); 6200 } 6201 6202 /* XXX verify all mbufs were reclaimed */ 6203 } 6204 } 6205 6206 static int 6207 bxe_alloc_rx_bd_mbuf(struct bxe_fastpath *fp, 6208 uint16_t prev_index, 6209 uint16_t index) 6210 { 6211 struct bxe_sw_rx_bd *rx_buf; 6212 struct eth_rx_bd *rx_bd; 6213 bus_dma_segment_t segs[1]; 6214 bus_dmamap_t map; 6215 struct mbuf *m; 6216 int nsegs, rc; 6217 6218 rc = 0; 6219 6220 /* allocate the new RX BD mbuf */ 6221 m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, fp->mbuf_alloc_size); 6222 if (__predict_false(m == NULL)) { 6223 fp->eth_q_stats.mbuf_rx_bd_alloc_failed++; 6224 return (ENOBUFS); 6225 } 6226 6227 fp->eth_q_stats.mbuf_alloc_rx++; 6228 6229 /* initialize the mbuf buffer length */ 6230 m->m_pkthdr.len = m->m_len = fp->rx_buf_size; 6231 6232 /* map the mbuf into non-paged pool */ 6233 rc = bus_dmamap_load_mbuf_sg(fp->rx_mbuf_tag, 6234 fp->rx_mbuf_spare_map, 6235 m, segs, &nsegs, BUS_DMA_NOWAIT); 6236 if (__predict_false(rc != 0)) { 6237 fp->eth_q_stats.mbuf_rx_bd_mapping_failed++; 6238 m_freem(m); 6239 fp->eth_q_stats.mbuf_alloc_rx--; 6240 return (rc); 6241 } 6242 6243 /* all mbufs must map to a single segment */ 6244 KASSERT((nsegs == 1), ("Too many segments, %d returned!", nsegs)); 6245 6246 /* release any existing RX BD mbuf mappings */ 6247 6248 if (prev_index != index) { 6249 rx_buf = &fp->rx_mbuf_chain[prev_index]; 6250 6251 if (rx_buf->m_map != NULL) { 6252 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map, 6253 BUS_DMASYNC_POSTREAD); 6254 bus_dmamap_unload(fp->rx_mbuf_tag, rx_buf->m_map); 6255 } 6256 6257 /* 6258 * We only get here from bxe_rxeof() when the maximum number 6259 * of rx buffers is less than RX_BD_USABLE. bxe_rxeof() already 6260 * holds the mbuf in the prev_index so it's OK to NULL it out 6261 * here without concern of a memory leak. 6262 */ 6263 fp->rx_mbuf_chain[prev_index].m = NULL; 6264 } 6265 6266 rx_buf = &fp->rx_mbuf_chain[index]; 6267 6268 if (rx_buf->m_map != NULL) { 6269 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map, 6270 BUS_DMASYNC_POSTREAD); 6271 bus_dmamap_unload(fp->rx_mbuf_tag, rx_buf->m_map); 6272 } 6273 6274 /* save the mbuf and mapping info for a future packet */ 6275 map = (prev_index != index) ? 6276 fp->rx_mbuf_chain[prev_index].m_map : rx_buf->m_map; 6277 rx_buf->m_map = fp->rx_mbuf_spare_map; 6278 fp->rx_mbuf_spare_map = map; 6279 bus_dmamap_sync(fp->rx_mbuf_tag, rx_buf->m_map, 6280 BUS_DMASYNC_PREREAD); 6281 rx_buf->m = m; 6282 6283 rx_bd = &fp->rx_chain[index]; 6284 rx_bd->addr_hi = htole32(U64_HI(segs[0].ds_addr)); 6285 rx_bd->addr_lo = htole32(U64_LO(segs[0].ds_addr)); 6286 6287 return (rc); 6288 } 6289 6290 static int 6291 bxe_alloc_rx_tpa_mbuf(struct bxe_fastpath *fp, 6292 int queue) 6293 { 6294 struct bxe_sw_tpa_info *tpa_info = &fp->rx_tpa_info[queue]; 6295 bus_dma_segment_t segs[1]; 6296 bus_dmamap_t map; 6297 struct mbuf *m; 6298 int nsegs; 6299 int rc = 0; 6300 6301 /* allocate the new TPA mbuf */ 6302 m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, fp->mbuf_alloc_size); 6303 if (__predict_false(m == NULL)) { 6304 fp->eth_q_stats.mbuf_rx_tpa_alloc_failed++; 6305 return (ENOBUFS); 6306 } 6307 6308 fp->eth_q_stats.mbuf_alloc_tpa++; 6309 6310 /* initialize the mbuf buffer length */ 6311 m->m_pkthdr.len = m->m_len = fp->rx_buf_size; 6312 6313 /* map the mbuf into non-paged pool */ 6314 rc = bus_dmamap_load_mbuf_sg(fp->rx_mbuf_tag, 6315 fp->rx_tpa_info_mbuf_spare_map, 6316 m, segs, &nsegs, BUS_DMA_NOWAIT); 6317 if (__predict_false(rc != 0)) { 6318 fp->eth_q_stats.mbuf_rx_tpa_mapping_failed++; 6319 m_free(m); 6320 fp->eth_q_stats.mbuf_alloc_tpa--; 6321 return (rc); 6322 } 6323 6324 /* all mbufs must map to a single segment */ 6325 KASSERT((nsegs == 1), ("Too many segments, %d returned!", nsegs)); 6326 6327 /* release any existing TPA mbuf mapping */ 6328 if (tpa_info->bd.m_map != NULL) { 6329 bus_dmamap_sync(fp->rx_mbuf_tag, tpa_info->bd.m_map, 6330 BUS_DMASYNC_POSTREAD); 6331 bus_dmamap_unload(fp->rx_mbuf_tag, tpa_info->bd.m_map); 6332 } 6333 6334 /* save the mbuf and mapping info for the TPA mbuf */ 6335 map = tpa_info->bd.m_map; 6336 tpa_info->bd.m_map = fp->rx_tpa_info_mbuf_spare_map; 6337 fp->rx_tpa_info_mbuf_spare_map = map; 6338 bus_dmamap_sync(fp->rx_mbuf_tag, tpa_info->bd.m_map, 6339 BUS_DMASYNC_PREREAD); 6340 tpa_info->bd.m = m; 6341 tpa_info->seg = segs[0]; 6342 6343 return (rc); 6344 } 6345 6346 /* 6347 * Allocate an mbuf and assign it to the receive scatter gather chain. The 6348 * caller must take care to save a copy of the existing mbuf in the SG mbuf 6349 * chain. 6350 */ 6351 static int 6352 bxe_alloc_rx_sge_mbuf(struct bxe_fastpath *fp, 6353 uint16_t index) 6354 { 6355 struct bxe_sw_rx_bd *sge_buf; 6356 struct eth_rx_sge *sge; 6357 bus_dma_segment_t segs[1]; 6358 bus_dmamap_t map; 6359 struct mbuf *m; 6360 int nsegs; 6361 int rc = 0; 6362 6363 /* allocate a new SGE mbuf */ 6364 m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, SGE_PAGE_SIZE); 6365 if (__predict_false(m == NULL)) { 6366 fp->eth_q_stats.mbuf_rx_sge_alloc_failed++; 6367 return (ENOMEM); 6368 } 6369 6370 fp->eth_q_stats.mbuf_alloc_sge++; 6371 6372 /* initialize the mbuf buffer length */ 6373 m->m_pkthdr.len = m->m_len = SGE_PAGE_SIZE; 6374 6375 /* map the SGE mbuf into non-paged pool */ 6376 rc = bus_dmamap_load_mbuf_sg(fp->rx_sge_mbuf_tag, 6377 fp->rx_sge_mbuf_spare_map, 6378 m, segs, &nsegs, BUS_DMA_NOWAIT); 6379 if (__predict_false(rc != 0)) { 6380 fp->eth_q_stats.mbuf_rx_sge_mapping_failed++; 6381 m_freem(m); 6382 fp->eth_q_stats.mbuf_alloc_sge--; 6383 return (rc); 6384 } 6385 6386 /* all mbufs must map to a single segment */ 6387 KASSERT((nsegs == 1), ("Too many segments, %d returned!", nsegs)); 6388 6389 sge_buf = &fp->rx_sge_mbuf_chain[index]; 6390 6391 /* release any existing SGE mbuf mapping */ 6392 if (sge_buf->m_map != NULL) { 6393 bus_dmamap_sync(fp->rx_sge_mbuf_tag, sge_buf->m_map, 6394 BUS_DMASYNC_POSTREAD); 6395 bus_dmamap_unload(fp->rx_sge_mbuf_tag, sge_buf->m_map); 6396 } 6397 6398 /* save the mbuf and mapping info for a future packet */ 6399 map = sge_buf->m_map; 6400 sge_buf->m_map = fp->rx_sge_mbuf_spare_map; 6401 fp->rx_sge_mbuf_spare_map = map; 6402 bus_dmamap_sync(fp->rx_sge_mbuf_tag, sge_buf->m_map, 6403 BUS_DMASYNC_PREREAD); 6404 sge_buf->m = m; 6405 6406 sge = &fp->rx_sge_chain[index]; 6407 sge->addr_hi = htole32(U64_HI(segs[0].ds_addr)); 6408 sge->addr_lo = htole32(U64_LO(segs[0].ds_addr)); 6409 6410 return (rc); 6411 } 6412 6413 static __noinline int 6414 bxe_alloc_fp_buffers(struct bxe_softc *sc) 6415 { 6416 struct bxe_fastpath *fp; 6417 int i, j, rc = 0; 6418 int ring_prod, cqe_ring_prod; 6419 int max_agg_queues; 6420 6421 for (i = 0; i < sc->num_queues; i++) { 6422 fp = &sc->fp[i]; 6423 6424 ring_prod = cqe_ring_prod = 0; 6425 fp->rx_bd_cons = 0; 6426 fp->rx_cq_cons = 0; 6427 6428 /* allocate buffers for the RX BDs in RX BD chain */ 6429 for (j = 0; j < sc->max_rx_bufs; j++) { 6430 rc = bxe_alloc_rx_bd_mbuf(fp, ring_prod, ring_prod); 6431 if (rc != 0) { 6432 BLOGE(sc, "mbuf alloc fail for fp[%02d] rx chain (%d)\n", 6433 i, rc); 6434 goto bxe_alloc_fp_buffers_error; 6435 } 6436 6437 ring_prod = RX_BD_NEXT(ring_prod); 6438 cqe_ring_prod = RCQ_NEXT(cqe_ring_prod); 6439 } 6440 6441 fp->rx_bd_prod = ring_prod; 6442 fp->rx_cq_prod = cqe_ring_prod; 6443 fp->eth_q_stats.rx_calls = fp->eth_q_stats.rx_pkts = 0; 6444 6445 max_agg_queues = MAX_AGG_QS(sc); 6446 6447 fp->tpa_enable = TRUE; 6448 6449 /* fill the TPA pool */ 6450 for (j = 0; j < max_agg_queues; j++) { 6451 rc = bxe_alloc_rx_tpa_mbuf(fp, j); 6452 if (rc != 0) { 6453 BLOGE(sc, "mbuf alloc fail for fp[%02d] TPA queue %d\n", 6454 i, j); 6455 fp->tpa_enable = FALSE; 6456 goto bxe_alloc_fp_buffers_error; 6457 } 6458 6459 fp->rx_tpa_info[j].state = BXE_TPA_STATE_STOP; 6460 } 6461 6462 if (fp->tpa_enable) { 6463 /* fill the RX SGE chain */ 6464 ring_prod = 0; 6465 for (j = 0; j < RX_SGE_USABLE; j++) { 6466 rc = bxe_alloc_rx_sge_mbuf(fp, ring_prod); 6467 if (rc != 0) { 6468 BLOGE(sc, "mbuf alloc fail for fp[%02d] SGE %d\n", 6469 i, ring_prod); 6470 fp->tpa_enable = FALSE; 6471 ring_prod = 0; 6472 goto bxe_alloc_fp_buffers_error; 6473 } 6474 6475 ring_prod = RX_SGE_NEXT(ring_prod); 6476 } 6477 6478 fp->rx_sge_prod = ring_prod; 6479 } 6480 } 6481 6482 return (0); 6483 6484 bxe_alloc_fp_buffers_error: 6485 6486 /* unwind what was already allocated */ 6487 bxe_free_rx_bd_chain(fp); 6488 bxe_free_tpa_pool(fp); 6489 bxe_free_sge_chain(fp); 6490 6491 return (ENOBUFS); 6492 } 6493 6494 static void 6495 bxe_free_fw_stats_mem(struct bxe_softc *sc) 6496 { 6497 bxe_dma_free(sc, &sc->fw_stats_dma); 6498 6499 sc->fw_stats_num = 0; 6500 6501 sc->fw_stats_req_size = 0; 6502 sc->fw_stats_req = NULL; 6503 sc->fw_stats_req_mapping = 0; 6504 6505 sc->fw_stats_data_size = 0; 6506 sc->fw_stats_data = NULL; 6507 sc->fw_stats_data_mapping = 0; 6508 } 6509 6510 static int 6511 bxe_alloc_fw_stats_mem(struct bxe_softc *sc) 6512 { 6513 uint8_t num_queue_stats; 6514 int num_groups; 6515 6516 /* number of queues for statistics is number of eth queues */ 6517 num_queue_stats = BXE_NUM_ETH_QUEUES(sc); 6518 6519 /* 6520 * Total number of FW statistics requests = 6521 * 1 for port stats + 1 for PF stats + num of queues 6522 */ 6523 sc->fw_stats_num = (2 + num_queue_stats); 6524 6525 /* 6526 * Request is built from stats_query_header and an array of 6527 * stats_query_cmd_group each of which contains STATS_QUERY_CMD_COUNT 6528 * rules. The real number or requests is configured in the 6529 * stats_query_header. 6530 */ 6531 num_groups = 6532 ((sc->fw_stats_num / STATS_QUERY_CMD_COUNT) + 6533 ((sc->fw_stats_num % STATS_QUERY_CMD_COUNT) ? 1 : 0)); 6534 6535 BLOGD(sc, DBG_LOAD, "stats fw_stats_num %d num_groups %d\n", 6536 sc->fw_stats_num, num_groups); 6537 6538 sc->fw_stats_req_size = 6539 (sizeof(struct stats_query_header) + 6540 (num_groups * sizeof(struct stats_query_cmd_group))); 6541 6542 /* 6543 * Data for statistics requests + stats_counter. 6544 * stats_counter holds per-STORM counters that are incremented when 6545 * STORM has finished with the current request. Memory for FCoE 6546 * offloaded statistics are counted anyway, even if they will not be sent. 6547 * VF stats are not accounted for here as the data of VF stats is stored 6548 * in memory allocated by the VF, not here. 6549 */ 6550 sc->fw_stats_data_size = 6551 (sizeof(struct stats_counter) + 6552 sizeof(struct per_port_stats) + 6553 sizeof(struct per_pf_stats) + 6554 /* sizeof(struct fcoe_statistics_params) + */ 6555 (sizeof(struct per_queue_stats) * num_queue_stats)); 6556 6557 if (bxe_dma_alloc(sc, (sc->fw_stats_req_size + sc->fw_stats_data_size), 6558 &sc->fw_stats_dma, "fw stats") != 0) { 6559 bxe_free_fw_stats_mem(sc); 6560 return (-1); 6561 } 6562 6563 /* set up the shortcuts */ 6564 6565 sc->fw_stats_req = 6566 (struct bxe_fw_stats_req *)sc->fw_stats_dma.vaddr; 6567 sc->fw_stats_req_mapping = sc->fw_stats_dma.paddr; 6568 6569 sc->fw_stats_data = 6570 (struct bxe_fw_stats_data *)((uint8_t *)sc->fw_stats_dma.vaddr + 6571 sc->fw_stats_req_size); 6572 sc->fw_stats_data_mapping = (sc->fw_stats_dma.paddr + 6573 sc->fw_stats_req_size); 6574 6575 BLOGD(sc, DBG_LOAD, "statistics request base address set to %#jx\n", 6576 (uintmax_t)sc->fw_stats_req_mapping); 6577 6578 BLOGD(sc, DBG_LOAD, "statistics data base address set to %#jx\n", 6579 (uintmax_t)sc->fw_stats_data_mapping); 6580 6581 return (0); 6582 } 6583 6584 /* 6585 * Bits map: 6586 * 0-7 - Engine0 load counter. 6587 * 8-15 - Engine1 load counter. 6588 * 16 - Engine0 RESET_IN_PROGRESS bit. 6589 * 17 - Engine1 RESET_IN_PROGRESS bit. 6590 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active 6591 * function on the engine 6592 * 19 - Engine1 ONE_IS_LOADED. 6593 * 20 - Chip reset flow bit. When set none-leader must wait for both engines 6594 * leader to complete (check for both RESET_IN_PROGRESS bits and not 6595 * for just the one belonging to its engine). 6596 */ 6597 #define BXE_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1 6598 #define BXE_PATH0_LOAD_CNT_MASK 0x000000ff 6599 #define BXE_PATH0_LOAD_CNT_SHIFT 0 6600 #define BXE_PATH1_LOAD_CNT_MASK 0x0000ff00 6601 #define BXE_PATH1_LOAD_CNT_SHIFT 8 6602 #define BXE_PATH0_RST_IN_PROG_BIT 0x00010000 6603 #define BXE_PATH1_RST_IN_PROG_BIT 0x00020000 6604 #define BXE_GLOBAL_RESET_BIT 0x00040000 6605 6606 /* set the GLOBAL_RESET bit, should be run under rtnl lock */ 6607 static void 6608 bxe_set_reset_global(struct bxe_softc *sc) 6609 { 6610 uint32_t val; 6611 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG); 6612 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG); 6613 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val | BXE_GLOBAL_RESET_BIT); 6614 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG); 6615 } 6616 6617 /* clear the GLOBAL_RESET bit, should be run under rtnl lock */ 6618 static void 6619 bxe_clear_reset_global(struct bxe_softc *sc) 6620 { 6621 uint32_t val; 6622 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG); 6623 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG); 6624 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val & (~BXE_GLOBAL_RESET_BIT)); 6625 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG); 6626 } 6627 6628 /* checks the GLOBAL_RESET bit, should be run under rtnl lock */ 6629 static uint8_t 6630 bxe_reset_is_global(struct bxe_softc *sc) 6631 { 6632 uint32_t val = REG_RD(sc, BXE_RECOVERY_GLOB_REG); 6633 BLOGD(sc, DBG_LOAD, "GLOB_REG=0x%08x\n", val); 6634 return (val & BXE_GLOBAL_RESET_BIT) ? TRUE : FALSE; 6635 } 6636 6637 /* clear RESET_IN_PROGRESS bit for the engine, should be run under rtnl lock */ 6638 static void 6639 bxe_set_reset_done(struct bxe_softc *sc) 6640 { 6641 uint32_t val; 6642 uint32_t bit = SC_PATH(sc) ? BXE_PATH1_RST_IN_PROG_BIT : 6643 BXE_PATH0_RST_IN_PROG_BIT; 6644 6645 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG); 6646 6647 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG); 6648 /* Clear the bit */ 6649 val &= ~bit; 6650 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val); 6651 6652 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG); 6653 } 6654 6655 /* set RESET_IN_PROGRESS for the engine, should be run under rtnl lock */ 6656 static void 6657 bxe_set_reset_in_progress(struct bxe_softc *sc) 6658 { 6659 uint32_t val; 6660 uint32_t bit = SC_PATH(sc) ? BXE_PATH1_RST_IN_PROG_BIT : 6661 BXE_PATH0_RST_IN_PROG_BIT; 6662 6663 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG); 6664 6665 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG); 6666 /* Set the bit */ 6667 val |= bit; 6668 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val); 6669 6670 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG); 6671 } 6672 6673 /* check RESET_IN_PROGRESS bit for an engine, should be run under rtnl lock */ 6674 static uint8_t 6675 bxe_reset_is_done(struct bxe_softc *sc, 6676 int engine) 6677 { 6678 uint32_t val = REG_RD(sc, BXE_RECOVERY_GLOB_REG); 6679 uint32_t bit = engine ? BXE_PATH1_RST_IN_PROG_BIT : 6680 BXE_PATH0_RST_IN_PROG_BIT; 6681 6682 /* return false if bit is set */ 6683 return (val & bit) ? FALSE : TRUE; 6684 } 6685 6686 /* get the load status for an engine, should be run under rtnl lock */ 6687 static uint8_t 6688 bxe_get_load_status(struct bxe_softc *sc, 6689 int engine) 6690 { 6691 uint32_t mask = engine ? BXE_PATH1_LOAD_CNT_MASK : 6692 BXE_PATH0_LOAD_CNT_MASK; 6693 uint32_t shift = engine ? BXE_PATH1_LOAD_CNT_SHIFT : 6694 BXE_PATH0_LOAD_CNT_SHIFT; 6695 uint32_t val = REG_RD(sc, BXE_RECOVERY_GLOB_REG); 6696 6697 BLOGD(sc, DBG_LOAD, "Old value for GLOB_REG=0x%08x\n", val); 6698 6699 val = ((val & mask) >> shift); 6700 6701 BLOGD(sc, DBG_LOAD, "Load mask engine %d = 0x%08x\n", engine, val); 6702 6703 return (val != 0); 6704 } 6705 6706 /* set pf load mark */ 6707 /* XXX needs to be under rtnl lock */ 6708 static void 6709 bxe_set_pf_load(struct bxe_softc *sc) 6710 { 6711 uint32_t val; 6712 uint32_t val1; 6713 uint32_t mask = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_MASK : 6714 BXE_PATH0_LOAD_CNT_MASK; 6715 uint32_t shift = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_SHIFT : 6716 BXE_PATH0_LOAD_CNT_SHIFT; 6717 6718 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG); 6719 6720 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG); 6721 BLOGD(sc, DBG_LOAD, "Old value for GLOB_REG=0x%08x\n", val); 6722 6723 /* get the current counter value */ 6724 val1 = ((val & mask) >> shift); 6725 6726 /* set bit of this PF */ 6727 val1 |= (1 << SC_ABS_FUNC(sc)); 6728 6729 /* clear the old value */ 6730 val &= ~mask; 6731 6732 /* set the new one */ 6733 val |= ((val1 << shift) & mask); 6734 6735 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val); 6736 6737 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG); 6738 } 6739 6740 /* clear pf load mark */ 6741 /* XXX needs to be under rtnl lock */ 6742 static uint8_t 6743 bxe_clear_pf_load(struct bxe_softc *sc) 6744 { 6745 uint32_t val1, val; 6746 uint32_t mask = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_MASK : 6747 BXE_PATH0_LOAD_CNT_MASK; 6748 uint32_t shift = SC_PATH(sc) ? BXE_PATH1_LOAD_CNT_SHIFT : 6749 BXE_PATH0_LOAD_CNT_SHIFT; 6750 6751 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG); 6752 val = REG_RD(sc, BXE_RECOVERY_GLOB_REG); 6753 BLOGD(sc, DBG_LOAD, "Old GEN_REG_VAL=0x%08x\n", val); 6754 6755 /* get the current counter value */ 6756 val1 = (val & mask) >> shift; 6757 6758 /* clear bit of that PF */ 6759 val1 &= ~(1 << SC_ABS_FUNC(sc)); 6760 6761 /* clear the old value */ 6762 val &= ~mask; 6763 6764 /* set the new one */ 6765 val |= ((val1 << shift) & mask); 6766 6767 REG_WR(sc, BXE_RECOVERY_GLOB_REG, val); 6768 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG); 6769 return (val1 != 0); 6770 } 6771 6772 /* send load requrest to mcp and analyze response */ 6773 static int 6774 bxe_nic_load_request(struct bxe_softc *sc, 6775 uint32_t *load_code) 6776 { 6777 /* init fw_seq */ 6778 sc->fw_seq = 6779 (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_mb_header) & 6780 DRV_MSG_SEQ_NUMBER_MASK); 6781 6782 BLOGD(sc, DBG_LOAD, "initial fw_seq 0x%04x\n", sc->fw_seq); 6783 6784 /* get the current FW pulse sequence */ 6785 sc->fw_drv_pulse_wr_seq = 6786 (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_pulse_mb) & 6787 DRV_PULSE_SEQ_MASK); 6788 6789 BLOGD(sc, DBG_LOAD, "initial drv_pulse 0x%04x\n", 6790 sc->fw_drv_pulse_wr_seq); 6791 6792 /* load request */ 6793 (*load_code) = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_REQ, 6794 DRV_MSG_CODE_LOAD_REQ_WITH_LFA); 6795 6796 /* if the MCP fails to respond we must abort */ 6797 if (!(*load_code)) { 6798 BLOGE(sc, "MCP response failure!\n"); 6799 return (-1); 6800 } 6801 6802 /* if MCP refused then must abort */ 6803 if ((*load_code) == FW_MSG_CODE_DRV_LOAD_REFUSED) { 6804 BLOGE(sc, "MCP refused load request\n"); 6805 return (-1); 6806 } 6807 6808 return (0); 6809 } 6810 6811 /* 6812 * Check whether another PF has already loaded FW to chip. In virtualized 6813 * environments a pf from anoth VM may have already initialized the device 6814 * including loading FW. 6815 */ 6816 static int 6817 bxe_nic_load_analyze_req(struct bxe_softc *sc, 6818 uint32_t load_code) 6819 { 6820 uint32_t my_fw, loaded_fw; 6821 6822 /* is another pf loaded on this engine? */ 6823 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) && 6824 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) { 6825 /* build my FW version dword */ 6826 my_fw = (BCM_5710_FW_MAJOR_VERSION + 6827 (BCM_5710_FW_MINOR_VERSION << 8 ) + 6828 (BCM_5710_FW_REVISION_VERSION << 16) + 6829 (BCM_5710_FW_ENGINEERING_VERSION << 24)); 6830 6831 /* read loaded FW from chip */ 6832 loaded_fw = REG_RD(sc, XSEM_REG_PRAM); 6833 BLOGD(sc, DBG_LOAD, "loaded FW 0x%08x / my FW 0x%08x\n", 6834 loaded_fw, my_fw); 6835 6836 /* abort nic load if version mismatch */ 6837 if (my_fw != loaded_fw) { 6838 BLOGE(sc, "FW 0x%08x already loaded (mine is 0x%08x)", 6839 loaded_fw, my_fw); 6840 return (-1); 6841 } 6842 } 6843 6844 return (0); 6845 } 6846 6847 /* mark PMF if applicable */ 6848 static void 6849 bxe_nic_load_pmf(struct bxe_softc *sc, 6850 uint32_t load_code) 6851 { 6852 uint32_t ncsi_oem_data_addr; 6853 6854 if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) || 6855 (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) || 6856 (load_code == FW_MSG_CODE_DRV_LOAD_PORT)) { 6857 /* 6858 * Barrier here for ordering between the writing to sc->port.pmf here 6859 * and reading it from the periodic task. 6860 */ 6861 sc->port.pmf = 1; 6862 mb(); 6863 } else { 6864 sc->port.pmf = 0; 6865 } 6866 6867 BLOGD(sc, DBG_LOAD, "pmf %d\n", sc->port.pmf); 6868 6869 /* XXX needed? */ 6870 if (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) { 6871 if (SHMEM2_HAS(sc, ncsi_oem_data_addr)) { 6872 ncsi_oem_data_addr = SHMEM2_RD(sc, ncsi_oem_data_addr); 6873 if (ncsi_oem_data_addr) { 6874 REG_WR(sc, 6875 (ncsi_oem_data_addr + 6876 offsetof(struct glob_ncsi_oem_data, driver_version)), 6877 0); 6878 } 6879 } 6880 } 6881 } 6882 6883 static void 6884 bxe_read_mf_cfg(struct bxe_softc *sc) 6885 { 6886 int n = (CHIP_IS_MODE_4_PORT(sc) ? 2 : 1); 6887 int abs_func; 6888 int vn; 6889 6890 if (BXE_NOMCP(sc)) { 6891 return; /* what should be the default bvalue in this case */ 6892 } 6893 6894 /* 6895 * The formula for computing the absolute function number is... 6896 * For 2 port configuration (4 functions per port): 6897 * abs_func = 2 * vn + SC_PORT + SC_PATH 6898 * For 4 port configuration (2 functions per port): 6899 * abs_func = 4 * vn + 2 * SC_PORT + SC_PATH 6900 */ 6901 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) { 6902 abs_func = (n * (2 * vn + SC_PORT(sc)) + SC_PATH(sc)); 6903 if (abs_func >= E1H_FUNC_MAX) { 6904 break; 6905 } 6906 sc->devinfo.mf_info.mf_config[vn] = 6907 MFCFG_RD(sc, func_mf_config[abs_func].config); 6908 } 6909 6910 if (sc->devinfo.mf_info.mf_config[SC_VN(sc)] & 6911 FUNC_MF_CFG_FUNC_DISABLED) { 6912 BLOGD(sc, DBG_LOAD, "mf_cfg function disabled\n"); 6913 sc->flags |= BXE_MF_FUNC_DIS; 6914 } else { 6915 BLOGD(sc, DBG_LOAD, "mf_cfg function enabled\n"); 6916 sc->flags &= ~BXE_MF_FUNC_DIS; 6917 } 6918 } 6919 6920 /* acquire split MCP access lock register */ 6921 static int bxe_acquire_alr(struct bxe_softc *sc) 6922 { 6923 uint32_t j, val; 6924 6925 for (j = 0; j < 1000; j++) { 6926 val = (1UL << 31); 6927 REG_WR(sc, GRCBASE_MCP + 0x9c, val); 6928 val = REG_RD(sc, GRCBASE_MCP + 0x9c); 6929 if (val & (1L << 31)) 6930 break; 6931 6932 DELAY(5000); 6933 } 6934 6935 if (!(val & (1L << 31))) { 6936 BLOGE(sc, "Cannot acquire MCP access lock register\n"); 6937 return (-1); 6938 } 6939 6940 return (0); 6941 } 6942 6943 /* release split MCP access lock register */ 6944 static void bxe_release_alr(struct bxe_softc *sc) 6945 { 6946 REG_WR(sc, GRCBASE_MCP + 0x9c, 0); 6947 } 6948 6949 static void 6950 bxe_fan_failure(struct bxe_softc *sc) 6951 { 6952 int port = SC_PORT(sc); 6953 uint32_t ext_phy_config; 6954 6955 /* mark the failure */ 6956 ext_phy_config = 6957 SHMEM_RD(sc, dev_info.port_hw_config[port].external_phy_config); 6958 6959 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK; 6960 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE; 6961 SHMEM_WR(sc, dev_info.port_hw_config[port].external_phy_config, 6962 ext_phy_config); 6963 6964 /* log the failure */ 6965 BLOGW(sc, "Fan Failure has caused the driver to shutdown " 6966 "the card to prevent permanent damage. " 6967 "Please contact OEM Support for assistance\n"); 6968 6969 /* XXX */ 6970 #if 1 6971 bxe_panic(sc, ("Schedule task to handle fan failure\n")); 6972 #else 6973 /* 6974 * Schedule device reset (unload) 6975 * This is due to some boards consuming sufficient power when driver is 6976 * up to overheat if fan fails. 6977 */ 6978 bxe_set_bit(BXE_SP_RTNL_FAN_FAILURE, &sc->sp_rtnl_state); 6979 schedule_delayed_work(&sc->sp_rtnl_task, 0); 6980 #endif 6981 } 6982 6983 /* this function is called upon a link interrupt */ 6984 static void 6985 bxe_link_attn(struct bxe_softc *sc) 6986 { 6987 uint32_t pause_enabled = 0; 6988 struct host_port_stats *pstats; 6989 int cmng_fns; 6990 struct bxe_fastpath *fp; 6991 int i; 6992 6993 /* Make sure that we are synced with the current statistics */ 6994 bxe_stats_handle(sc, STATS_EVENT_STOP); 6995 BLOGD(sc, DBG_LOAD, "link_vars phy_flags : %x\n", sc->link_vars.phy_flags); 6996 elink_link_update(&sc->link_params, &sc->link_vars); 6997 6998 if (sc->link_vars.link_up) { 6999 7000 /* dropless flow control */ 7001 if (!CHIP_IS_E1(sc) && sc->dropless_fc) { 7002 pause_enabled = 0; 7003 7004 if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_TX) { 7005 pause_enabled = 1; 7006 } 7007 7008 REG_WR(sc, 7009 (BAR_USTRORM_INTMEM + 7010 USTORM_ETH_PAUSE_ENABLED_OFFSET(SC_PORT(sc))), 7011 pause_enabled); 7012 } 7013 7014 if (sc->link_vars.mac_type != ELINK_MAC_TYPE_EMAC) { 7015 pstats = BXE_SP(sc, port_stats); 7016 /* reset old mac stats */ 7017 memset(&(pstats->mac_stx[0]), 0, sizeof(struct mac_stx)); 7018 } 7019 7020 if (sc->state == BXE_STATE_OPEN) { 7021 bxe_stats_handle(sc, STATS_EVENT_LINK_UP); 7022 /* Restart tx when the link comes back. */ 7023 FOR_EACH_ETH_QUEUE(sc, i) { 7024 fp = &sc->fp[i]; 7025 taskqueue_enqueue(fp->tq, &fp->tx_task); 7026 } 7027 } 7028 7029 } 7030 7031 if (sc->link_vars.link_up && sc->link_vars.line_speed) { 7032 cmng_fns = bxe_get_cmng_fns_mode(sc); 7033 7034 if (cmng_fns != CMNG_FNS_NONE) { 7035 bxe_cmng_fns_init(sc, FALSE, cmng_fns); 7036 storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc)); 7037 } else { 7038 /* rate shaping and fairness are disabled */ 7039 BLOGD(sc, DBG_LOAD, "single function mode without fairness\n"); 7040 } 7041 } 7042 7043 bxe_link_report_locked(sc); 7044 7045 if (IS_MF(sc)) { 7046 ; // XXX bxe_link_sync_notify(sc); 7047 } 7048 } 7049 7050 static void 7051 bxe_attn_int_asserted(struct bxe_softc *sc, 7052 uint32_t asserted) 7053 { 7054 int port = SC_PORT(sc); 7055 uint32_t aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : 7056 MISC_REG_AEU_MASK_ATTN_FUNC_0; 7057 uint32_t nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 : 7058 NIG_REG_MASK_INTERRUPT_PORT0; 7059 uint32_t aeu_mask; 7060 uint32_t nig_mask = 0; 7061 uint32_t reg_addr; 7062 uint32_t igu_acked; 7063 uint32_t cnt; 7064 7065 if (sc->attn_state & asserted) { 7066 BLOGE(sc, "IGU ERROR attn=0x%08x\n", asserted); 7067 } 7068 7069 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); 7070 7071 aeu_mask = REG_RD(sc, aeu_addr); 7072 7073 BLOGD(sc, DBG_INTR, "aeu_mask 0x%08x newly asserted 0x%08x\n", 7074 aeu_mask, asserted); 7075 7076 aeu_mask &= ~(asserted & 0x3ff); 7077 7078 BLOGD(sc, DBG_INTR, "new mask 0x%08x\n", aeu_mask); 7079 7080 REG_WR(sc, aeu_addr, aeu_mask); 7081 7082 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); 7083 7084 BLOGD(sc, DBG_INTR, "attn_state 0x%08x\n", sc->attn_state); 7085 sc->attn_state |= asserted; 7086 BLOGD(sc, DBG_INTR, "new state 0x%08x\n", sc->attn_state); 7087 7088 if (asserted & ATTN_HARD_WIRED_MASK) { 7089 if (asserted & ATTN_NIG_FOR_FUNC) { 7090 7091 bxe_acquire_phy_lock(sc); 7092 /* save nig interrupt mask */ 7093 nig_mask = REG_RD(sc, nig_int_mask_addr); 7094 7095 /* If nig_mask is not set, no need to call the update function */ 7096 if (nig_mask) { 7097 REG_WR(sc, nig_int_mask_addr, 0); 7098 7099 bxe_link_attn(sc); 7100 } 7101 7102 /* handle unicore attn? */ 7103 } 7104 7105 if (asserted & ATTN_SW_TIMER_4_FUNC) { 7106 BLOGD(sc, DBG_INTR, "ATTN_SW_TIMER_4_FUNC!\n"); 7107 } 7108 7109 if (asserted & GPIO_2_FUNC) { 7110 BLOGD(sc, DBG_INTR, "GPIO_2_FUNC!\n"); 7111 } 7112 7113 if (asserted & GPIO_3_FUNC) { 7114 BLOGD(sc, DBG_INTR, "GPIO_3_FUNC!\n"); 7115 } 7116 7117 if (asserted & GPIO_4_FUNC) { 7118 BLOGD(sc, DBG_INTR, "GPIO_4_FUNC!\n"); 7119 } 7120 7121 if (port == 0) { 7122 if (asserted & ATTN_GENERAL_ATTN_1) { 7123 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_1!\n"); 7124 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_1, 0x0); 7125 } 7126 if (asserted & ATTN_GENERAL_ATTN_2) { 7127 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_2!\n"); 7128 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_2, 0x0); 7129 } 7130 if (asserted & ATTN_GENERAL_ATTN_3) { 7131 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_3!\n"); 7132 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_3, 0x0); 7133 } 7134 } else { 7135 if (asserted & ATTN_GENERAL_ATTN_4) { 7136 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_4!\n"); 7137 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_4, 0x0); 7138 } 7139 if (asserted & ATTN_GENERAL_ATTN_5) { 7140 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_5!\n"); 7141 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_5, 0x0); 7142 } 7143 if (asserted & ATTN_GENERAL_ATTN_6) { 7144 BLOGD(sc, DBG_INTR, "ATTN_GENERAL_ATTN_6!\n"); 7145 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_6, 0x0); 7146 } 7147 } 7148 } /* hardwired */ 7149 7150 if (sc->devinfo.int_block == INT_BLOCK_HC) { 7151 reg_addr = (HC_REG_COMMAND_REG + port*32 + COMMAND_REG_ATTN_BITS_SET); 7152 } else { 7153 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8); 7154 } 7155 7156 BLOGD(sc, DBG_INTR, "about to mask 0x%08x at %s addr 0x%08x\n", 7157 asserted, 7158 (sc->devinfo.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr); 7159 REG_WR(sc, reg_addr, asserted); 7160 7161 /* now set back the mask */ 7162 if (asserted & ATTN_NIG_FOR_FUNC) { 7163 /* 7164 * Verify that IGU ack through BAR was written before restoring 7165 * NIG mask. This loop should exit after 2-3 iterations max. 7166 */ 7167 if (sc->devinfo.int_block != INT_BLOCK_HC) { 7168 cnt = 0; 7169 7170 do { 7171 igu_acked = REG_RD(sc, IGU_REG_ATTENTION_ACK_BITS); 7172 } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) && 7173 (++cnt < MAX_IGU_ATTN_ACK_TO)); 7174 7175 if (!igu_acked) { 7176 BLOGE(sc, "Failed to verify IGU ack on time\n"); 7177 } 7178 7179 mb(); 7180 } 7181 7182 REG_WR(sc, nig_int_mask_addr, nig_mask); 7183 7184 bxe_release_phy_lock(sc); 7185 } 7186 } 7187 7188 static void 7189 bxe_print_next_block(struct bxe_softc *sc, 7190 int idx, 7191 const char *blk) 7192 { 7193 BLOGI(sc, "%s%s", idx ? ", " : "", blk); 7194 } 7195 7196 static int 7197 bxe_check_blocks_with_parity0(struct bxe_softc *sc, 7198 uint32_t sig, 7199 int par_num, 7200 uint8_t print) 7201 { 7202 uint32_t cur_bit = 0; 7203 int i = 0; 7204 7205 for (i = 0; sig; i++) { 7206 cur_bit = ((uint32_t)0x1 << i); 7207 if (sig & cur_bit) { 7208 switch (cur_bit) { 7209 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR: 7210 if (print) 7211 bxe_print_next_block(sc, par_num++, "BRB"); 7212 break; 7213 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR: 7214 if (print) 7215 bxe_print_next_block(sc, par_num++, "PARSER"); 7216 break; 7217 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR: 7218 if (print) 7219 bxe_print_next_block(sc, par_num++, "TSDM"); 7220 break; 7221 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR: 7222 if (print) 7223 bxe_print_next_block(sc, par_num++, "SEARCHER"); 7224 break; 7225 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR: 7226 if (print) 7227 bxe_print_next_block(sc, par_num++, "TCM"); 7228 break; 7229 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR: 7230 if (print) 7231 bxe_print_next_block(sc, par_num++, "TSEMI"); 7232 break; 7233 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR: 7234 if (print) 7235 bxe_print_next_block(sc, par_num++, "XPB"); 7236 break; 7237 } 7238 7239 /* Clear the bit */ 7240 sig &= ~cur_bit; 7241 } 7242 } 7243 7244 return (par_num); 7245 } 7246 7247 static int 7248 bxe_check_blocks_with_parity1(struct bxe_softc *sc, 7249 uint32_t sig, 7250 int par_num, 7251 uint8_t *global, 7252 uint8_t print) 7253 { 7254 int i = 0; 7255 uint32_t cur_bit = 0; 7256 for (i = 0; sig; i++) { 7257 cur_bit = ((uint32_t)0x1 << i); 7258 if (sig & cur_bit) { 7259 switch (cur_bit) { 7260 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR: 7261 if (print) 7262 bxe_print_next_block(sc, par_num++, "PBF"); 7263 break; 7264 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR: 7265 if (print) 7266 bxe_print_next_block(sc, par_num++, "QM"); 7267 break; 7268 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR: 7269 if (print) 7270 bxe_print_next_block(sc, par_num++, "TM"); 7271 break; 7272 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR: 7273 if (print) 7274 bxe_print_next_block(sc, par_num++, "XSDM"); 7275 break; 7276 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR: 7277 if (print) 7278 bxe_print_next_block(sc, par_num++, "XCM"); 7279 break; 7280 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR: 7281 if (print) 7282 bxe_print_next_block(sc, par_num++, "XSEMI"); 7283 break; 7284 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR: 7285 if (print) 7286 bxe_print_next_block(sc, par_num++, "DOORBELLQ"); 7287 break; 7288 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR: 7289 if (print) 7290 bxe_print_next_block(sc, par_num++, "NIG"); 7291 break; 7292 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR: 7293 if (print) 7294 bxe_print_next_block(sc, par_num++, "VAUX PCI CORE"); 7295 *global = TRUE; 7296 break; 7297 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR: 7298 if (print) 7299 bxe_print_next_block(sc, par_num++, "DEBUG"); 7300 break; 7301 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR: 7302 if (print) 7303 bxe_print_next_block(sc, par_num++, "USDM"); 7304 break; 7305 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR: 7306 if (print) 7307 bxe_print_next_block(sc, par_num++, "UCM"); 7308 break; 7309 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR: 7310 if (print) 7311 bxe_print_next_block(sc, par_num++, "USEMI"); 7312 break; 7313 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR: 7314 if (print) 7315 bxe_print_next_block(sc, par_num++, "UPB"); 7316 break; 7317 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR: 7318 if (print) 7319 bxe_print_next_block(sc, par_num++, "CSDM"); 7320 break; 7321 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR: 7322 if (print) 7323 bxe_print_next_block(sc, par_num++, "CCM"); 7324 break; 7325 } 7326 7327 /* Clear the bit */ 7328 sig &= ~cur_bit; 7329 } 7330 } 7331 7332 return (par_num); 7333 } 7334 7335 static int 7336 bxe_check_blocks_with_parity2(struct bxe_softc *sc, 7337 uint32_t sig, 7338 int par_num, 7339 uint8_t print) 7340 { 7341 uint32_t cur_bit = 0; 7342 int i = 0; 7343 7344 for (i = 0; sig; i++) { 7345 cur_bit = ((uint32_t)0x1 << i); 7346 if (sig & cur_bit) { 7347 switch (cur_bit) { 7348 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR: 7349 if (print) 7350 bxe_print_next_block(sc, par_num++, "CSEMI"); 7351 break; 7352 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR: 7353 if (print) 7354 bxe_print_next_block(sc, par_num++, "PXP"); 7355 break; 7356 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR: 7357 if (print) 7358 bxe_print_next_block(sc, par_num++, "PXPPCICLOCKCLIENT"); 7359 break; 7360 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR: 7361 if (print) 7362 bxe_print_next_block(sc, par_num++, "CFC"); 7363 break; 7364 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR: 7365 if (print) 7366 bxe_print_next_block(sc, par_num++, "CDU"); 7367 break; 7368 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR: 7369 if (print) 7370 bxe_print_next_block(sc, par_num++, "DMAE"); 7371 break; 7372 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR: 7373 if (print) 7374 bxe_print_next_block(sc, par_num++, "IGU"); 7375 break; 7376 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR: 7377 if (print) 7378 bxe_print_next_block(sc, par_num++, "MISC"); 7379 break; 7380 } 7381 7382 /* Clear the bit */ 7383 sig &= ~cur_bit; 7384 } 7385 } 7386 7387 return (par_num); 7388 } 7389 7390 static int 7391 bxe_check_blocks_with_parity3(struct bxe_softc *sc, 7392 uint32_t sig, 7393 int par_num, 7394 uint8_t *global, 7395 uint8_t print) 7396 { 7397 uint32_t cur_bit = 0; 7398 int i = 0; 7399 7400 for (i = 0; sig; i++) { 7401 cur_bit = ((uint32_t)0x1 << i); 7402 if (sig & cur_bit) { 7403 switch (cur_bit) { 7404 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY: 7405 if (print) 7406 bxe_print_next_block(sc, par_num++, "MCP ROM"); 7407 *global = TRUE; 7408 break; 7409 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY: 7410 if (print) 7411 bxe_print_next_block(sc, par_num++, 7412 "MCP UMP RX"); 7413 *global = TRUE; 7414 break; 7415 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY: 7416 if (print) 7417 bxe_print_next_block(sc, par_num++, 7418 "MCP UMP TX"); 7419 *global = TRUE; 7420 break; 7421 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY: 7422 if (print) 7423 bxe_print_next_block(sc, par_num++, 7424 "MCP SCPAD"); 7425 *global = TRUE; 7426 break; 7427 } 7428 7429 /* Clear the bit */ 7430 sig &= ~cur_bit; 7431 } 7432 } 7433 7434 return (par_num); 7435 } 7436 7437 static int 7438 bxe_check_blocks_with_parity4(struct bxe_softc *sc, 7439 uint32_t sig, 7440 int par_num, 7441 uint8_t print) 7442 { 7443 uint32_t cur_bit = 0; 7444 int i = 0; 7445 7446 for (i = 0; sig; i++) { 7447 cur_bit = ((uint32_t)0x1 << i); 7448 if (sig & cur_bit) { 7449 switch (cur_bit) { 7450 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR: 7451 if (print) 7452 bxe_print_next_block(sc, par_num++, "PGLUE_B"); 7453 break; 7454 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR: 7455 if (print) 7456 bxe_print_next_block(sc, par_num++, "ATC"); 7457 break; 7458 } 7459 7460 /* Clear the bit */ 7461 sig &= ~cur_bit; 7462 } 7463 } 7464 7465 return (par_num); 7466 } 7467 7468 static uint8_t 7469 bxe_parity_attn(struct bxe_softc *sc, 7470 uint8_t *global, 7471 uint8_t print, 7472 uint32_t *sig) 7473 { 7474 int par_num = 0; 7475 7476 if ((sig[0] & HW_PRTY_ASSERT_SET_0) || 7477 (sig[1] & HW_PRTY_ASSERT_SET_1) || 7478 (sig[2] & HW_PRTY_ASSERT_SET_2) || 7479 (sig[3] & HW_PRTY_ASSERT_SET_3) || 7480 (sig[4] & HW_PRTY_ASSERT_SET_4)) { 7481 BLOGE(sc, "Parity error: HW block parity attention:\n" 7482 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n", 7483 (uint32_t)(sig[0] & HW_PRTY_ASSERT_SET_0), 7484 (uint32_t)(sig[1] & HW_PRTY_ASSERT_SET_1), 7485 (uint32_t)(sig[2] & HW_PRTY_ASSERT_SET_2), 7486 (uint32_t)(sig[3] & HW_PRTY_ASSERT_SET_3), 7487 (uint32_t)(sig[4] & HW_PRTY_ASSERT_SET_4)); 7488 7489 if (print) 7490 BLOGI(sc, "Parity errors detected in blocks: "); 7491 7492 par_num = 7493 bxe_check_blocks_with_parity0(sc, sig[0] & 7494 HW_PRTY_ASSERT_SET_0, 7495 par_num, print); 7496 par_num = 7497 bxe_check_blocks_with_parity1(sc, sig[1] & 7498 HW_PRTY_ASSERT_SET_1, 7499 par_num, global, print); 7500 par_num = 7501 bxe_check_blocks_with_parity2(sc, sig[2] & 7502 HW_PRTY_ASSERT_SET_2, 7503 par_num, print); 7504 par_num = 7505 bxe_check_blocks_with_parity3(sc, sig[3] & 7506 HW_PRTY_ASSERT_SET_3, 7507 par_num, global, print); 7508 par_num = 7509 bxe_check_blocks_with_parity4(sc, sig[4] & 7510 HW_PRTY_ASSERT_SET_4, 7511 par_num, print); 7512 7513 if (print) 7514 BLOGI(sc, "\n"); 7515 7516 if( *global == TRUE ) { 7517 BXE_SET_ERROR_BIT(sc, BXE_ERR_GLOBAL); 7518 } 7519 7520 return (TRUE); 7521 } 7522 7523 return (FALSE); 7524 } 7525 7526 static uint8_t 7527 bxe_chk_parity_attn(struct bxe_softc *sc, 7528 uint8_t *global, 7529 uint8_t print) 7530 { 7531 struct attn_route attn = { {0} }; 7532 int port = SC_PORT(sc); 7533 7534 if(sc->state != BXE_STATE_OPEN) 7535 return FALSE; 7536 7537 attn.sig[0] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4); 7538 attn.sig[1] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4); 7539 attn.sig[2] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4); 7540 attn.sig[3] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4); 7541 7542 /* 7543 * Since MCP attentions can't be disabled inside the block, we need to 7544 * read AEU registers to see whether they're currently disabled 7545 */ 7546 attn.sig[3] &= ((REG_RD(sc, (!port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0 7547 : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0)) & 7548 MISC_AEU_ENABLE_MCP_PRTY_BITS) | 7549 ~MISC_AEU_ENABLE_MCP_PRTY_BITS); 7550 7551 7552 if (!CHIP_IS_E1x(sc)) 7553 attn.sig[4] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4); 7554 7555 return (bxe_parity_attn(sc, global, print, attn.sig)); 7556 } 7557 7558 static void 7559 bxe_attn_int_deasserted4(struct bxe_softc *sc, 7560 uint32_t attn) 7561 { 7562 uint32_t val; 7563 bool err_flg = false; 7564 7565 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) { 7566 val = REG_RD(sc, PGLUE_B_REG_PGLUE_B_INT_STS_CLR); 7567 BLOGE(sc, "PGLUE hw attention 0x%08x\n", val); 7568 err_flg = true; 7569 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR) 7570 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n"); 7571 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR) 7572 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n"); 7573 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) 7574 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n"); 7575 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN) 7576 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n"); 7577 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN) 7578 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n"); 7579 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN) 7580 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n"); 7581 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN) 7582 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n"); 7583 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN) 7584 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n"); 7585 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW) 7586 BLOGE(sc, "PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n"); 7587 } 7588 7589 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) { 7590 val = REG_RD(sc, ATC_REG_ATC_INT_STS_CLR); 7591 BLOGE(sc, "ATC hw attention 0x%08x\n", val); 7592 err_flg = true; 7593 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR) 7594 BLOGE(sc, "ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n"); 7595 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND) 7596 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n"); 7597 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS) 7598 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n"); 7599 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT) 7600 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n"); 7601 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR) 7602 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n"); 7603 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU) 7604 BLOGE(sc, "ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n"); 7605 } 7606 7607 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR | 7608 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) { 7609 BLOGE(sc, "FATAL parity attention set4 0x%08x\n", 7610 (uint32_t)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR | 7611 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR))); 7612 err_flg = true; 7613 } 7614 if (err_flg) { 7615 BXE_SET_ERROR_BIT(sc, BXE_ERR_MISC); 7616 taskqueue_enqueue_timeout(taskqueue_thread, 7617 &sc->sp_err_timeout_task, hz/10); 7618 } 7619 7620 } 7621 7622 static void 7623 bxe_e1h_disable(struct bxe_softc *sc) 7624 { 7625 int port = SC_PORT(sc); 7626 7627 bxe_tx_disable(sc); 7628 7629 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 0); 7630 } 7631 7632 static void 7633 bxe_e1h_enable(struct bxe_softc *sc) 7634 { 7635 int port = SC_PORT(sc); 7636 7637 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 1); 7638 7639 // XXX bxe_tx_enable(sc); 7640 } 7641 7642 /* 7643 * called due to MCP event (on pmf): 7644 * reread new bandwidth configuration 7645 * configure FW 7646 * notify others function about the change 7647 */ 7648 static void 7649 bxe_config_mf_bw(struct bxe_softc *sc) 7650 { 7651 if (sc->link_vars.link_up) { 7652 bxe_cmng_fns_init(sc, TRUE, CMNG_FNS_MINMAX); 7653 // XXX bxe_link_sync_notify(sc); 7654 } 7655 7656 storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc)); 7657 } 7658 7659 static void 7660 bxe_set_mf_bw(struct bxe_softc *sc) 7661 { 7662 bxe_config_mf_bw(sc); 7663 bxe_fw_command(sc, DRV_MSG_CODE_SET_MF_BW_ACK, 0); 7664 } 7665 7666 static void 7667 bxe_handle_eee_event(struct bxe_softc *sc) 7668 { 7669 BLOGD(sc, DBG_INTR, "EEE - LLDP event\n"); 7670 bxe_fw_command(sc, DRV_MSG_CODE_EEE_RESULTS_ACK, 0); 7671 } 7672 7673 #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3 7674 7675 static void 7676 bxe_drv_info_ether_stat(struct bxe_softc *sc) 7677 { 7678 struct eth_stats_info *ether_stat = 7679 &sc->sp->drv_info_to_mcp.ether_stat; 7680 7681 strlcpy(ether_stat->version, BXE_DRIVER_VERSION, 7682 ETH_STAT_INFO_VERSION_LEN); 7683 7684 /* XXX (+ MAC_PAD) taken from other driver... verify this is right */ 7685 sc->sp_objs[0].mac_obj.get_n_elements(sc, &sc->sp_objs[0].mac_obj, 7686 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED, 7687 ether_stat->mac_local + MAC_PAD, 7688 MAC_PAD, ETH_ALEN); 7689 7690 ether_stat->mtu_size = sc->mtu; 7691 7692 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK; 7693 if (if_getcapenable(sc->ifp) & (IFCAP_TSO4 | IFCAP_TSO6)) { 7694 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK; 7695 } 7696 7697 // XXX ether_stat->feature_flags |= ???; 7698 7699 ether_stat->promiscuous_mode = 0; // (flags & PROMISC) ? 1 : 0; 7700 7701 ether_stat->txq_size = sc->tx_ring_size; 7702 ether_stat->rxq_size = sc->rx_ring_size; 7703 } 7704 7705 static void 7706 bxe_handle_drv_info_req(struct bxe_softc *sc) 7707 { 7708 enum drv_info_opcode op_code; 7709 uint32_t drv_info_ctl = SHMEM2_RD(sc, drv_info_control); 7710 7711 /* if drv_info version supported by MFW doesn't match - send NACK */ 7712 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) { 7713 bxe_fw_command(sc, DRV_MSG_CODE_DRV_INFO_NACK, 0); 7714 return; 7715 } 7716 7717 op_code = ((drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >> 7718 DRV_INFO_CONTROL_OP_CODE_SHIFT); 7719 7720 memset(&sc->sp->drv_info_to_mcp, 0, sizeof(union drv_info_to_mcp)); 7721 7722 switch (op_code) { 7723 case ETH_STATS_OPCODE: 7724 bxe_drv_info_ether_stat(sc); 7725 break; 7726 case FCOE_STATS_OPCODE: 7727 case ISCSI_STATS_OPCODE: 7728 default: 7729 /* if op code isn't supported - send NACK */ 7730 bxe_fw_command(sc, DRV_MSG_CODE_DRV_INFO_NACK, 0); 7731 return; 7732 } 7733 7734 /* 7735 * If we got drv_info attn from MFW then these fields are defined in 7736 * shmem2 for sure 7737 */ 7738 SHMEM2_WR(sc, drv_info_host_addr_lo, 7739 U64_LO(BXE_SP_MAPPING(sc, drv_info_to_mcp))); 7740 SHMEM2_WR(sc, drv_info_host_addr_hi, 7741 U64_HI(BXE_SP_MAPPING(sc, drv_info_to_mcp))); 7742 7743 bxe_fw_command(sc, DRV_MSG_CODE_DRV_INFO_ACK, 0); 7744 } 7745 7746 static void 7747 bxe_dcc_event(struct bxe_softc *sc, 7748 uint32_t dcc_event) 7749 { 7750 BLOGD(sc, DBG_INTR, "dcc_event 0x%08x\n", dcc_event); 7751 7752 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) { 7753 /* 7754 * This is the only place besides the function initialization 7755 * where the sc->flags can change so it is done without any 7756 * locks 7757 */ 7758 if (sc->devinfo.mf_info.mf_config[SC_VN(sc)] & FUNC_MF_CFG_FUNC_DISABLED) { 7759 BLOGD(sc, DBG_INTR, "mf_cfg function disabled\n"); 7760 sc->flags |= BXE_MF_FUNC_DIS; 7761 bxe_e1h_disable(sc); 7762 } else { 7763 BLOGD(sc, DBG_INTR, "mf_cfg function enabled\n"); 7764 sc->flags &= ~BXE_MF_FUNC_DIS; 7765 bxe_e1h_enable(sc); 7766 } 7767 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF; 7768 } 7769 7770 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) { 7771 bxe_config_mf_bw(sc); 7772 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION; 7773 } 7774 7775 /* Report results to MCP */ 7776 if (dcc_event) 7777 bxe_fw_command(sc, DRV_MSG_CODE_DCC_FAILURE, 0); 7778 else 7779 bxe_fw_command(sc, DRV_MSG_CODE_DCC_OK, 0); 7780 } 7781 7782 static void 7783 bxe_pmf_update(struct bxe_softc *sc) 7784 { 7785 int port = SC_PORT(sc); 7786 uint32_t val; 7787 7788 sc->port.pmf = 1; 7789 BLOGD(sc, DBG_INTR, "pmf %d\n", sc->port.pmf); 7790 7791 /* 7792 * We need the mb() to ensure the ordering between the writing to 7793 * sc->port.pmf here and reading it from the bxe_periodic_task(). 7794 */ 7795 mb(); 7796 7797 /* queue a periodic task */ 7798 // XXX schedule task... 7799 7800 // XXX bxe_dcbx_pmf_update(sc); 7801 7802 /* enable nig attention */ 7803 val = (0xff0f | (1 << (SC_VN(sc) + 4))); 7804 if (sc->devinfo.int_block == INT_BLOCK_HC) { 7805 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, val); 7806 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, val); 7807 } else if (!CHIP_IS_E1x(sc)) { 7808 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, val); 7809 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, val); 7810 } 7811 7812 bxe_stats_handle(sc, STATS_EVENT_PMF); 7813 } 7814 7815 static int 7816 bxe_mc_assert(struct bxe_softc *sc) 7817 { 7818 char last_idx; 7819 int i, rc = 0; 7820 uint32_t row0, row1, row2, row3; 7821 7822 /* XSTORM */ 7823 last_idx = REG_RD8(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_INDEX_OFFSET); 7824 if (last_idx) 7825 BLOGE(sc, "XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); 7826 7827 /* print the asserts */ 7828 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) { 7829 7830 row0 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i)); 7831 row1 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) + 4); 7832 row2 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) + 8); 7833 row3 = REG_RD(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) + 12); 7834 7835 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { 7836 BLOGE(sc, "XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n", 7837 i, row3, row2, row1, row0); 7838 rc++; 7839 } else { 7840 break; 7841 } 7842 } 7843 7844 /* TSTORM */ 7845 last_idx = REG_RD8(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_INDEX_OFFSET); 7846 if (last_idx) { 7847 BLOGE(sc, "TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); 7848 } 7849 7850 /* print the asserts */ 7851 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) { 7852 7853 row0 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i)); 7854 row1 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) + 4); 7855 row2 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) + 8); 7856 row3 = REG_RD(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) + 12); 7857 7858 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { 7859 BLOGE(sc, "TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n", 7860 i, row3, row2, row1, row0); 7861 rc++; 7862 } else { 7863 break; 7864 } 7865 } 7866 7867 /* CSTORM */ 7868 last_idx = REG_RD8(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_INDEX_OFFSET); 7869 if (last_idx) { 7870 BLOGE(sc, "CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); 7871 } 7872 7873 /* print the asserts */ 7874 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) { 7875 7876 row0 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i)); 7877 row1 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) + 4); 7878 row2 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) + 8); 7879 row3 = REG_RD(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) + 12); 7880 7881 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { 7882 BLOGE(sc, "CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n", 7883 i, row3, row2, row1, row0); 7884 rc++; 7885 } else { 7886 break; 7887 } 7888 } 7889 7890 /* USTORM */ 7891 last_idx = REG_RD8(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_INDEX_OFFSET); 7892 if (last_idx) { 7893 BLOGE(sc, "USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); 7894 } 7895 7896 /* print the asserts */ 7897 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) { 7898 7899 row0 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i)); 7900 row1 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) + 4); 7901 row2 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) + 8); 7902 row3 = REG_RD(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) + 12); 7903 7904 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { 7905 BLOGE(sc, "USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n", 7906 i, row3, row2, row1, row0); 7907 rc++; 7908 } else { 7909 break; 7910 } 7911 } 7912 7913 return (rc); 7914 } 7915 7916 static void 7917 bxe_attn_int_deasserted3(struct bxe_softc *sc, 7918 uint32_t attn) 7919 { 7920 int func = SC_FUNC(sc); 7921 uint32_t val; 7922 7923 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) { 7924 7925 if (attn & BXE_PMF_LINK_ASSERT(sc)) { 7926 7927 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); 7928 bxe_read_mf_cfg(sc); 7929 sc->devinfo.mf_info.mf_config[SC_VN(sc)] = 7930 MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config); 7931 val = SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_status); 7932 7933 if (val & DRV_STATUS_DCC_EVENT_MASK) 7934 bxe_dcc_event(sc, (val & DRV_STATUS_DCC_EVENT_MASK)); 7935 7936 if (val & DRV_STATUS_SET_MF_BW) 7937 bxe_set_mf_bw(sc); 7938 7939 if (val & DRV_STATUS_DRV_INFO_REQ) 7940 bxe_handle_drv_info_req(sc); 7941 7942 if ((sc->port.pmf == 0) && (val & DRV_STATUS_PMF)) 7943 bxe_pmf_update(sc); 7944 7945 if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS) 7946 bxe_handle_eee_event(sc); 7947 7948 if (sc->link_vars.periodic_flags & 7949 ELINK_PERIODIC_FLAGS_LINK_EVENT) { 7950 /* sync with link */ 7951 bxe_acquire_phy_lock(sc); 7952 sc->link_vars.periodic_flags &= 7953 ~ELINK_PERIODIC_FLAGS_LINK_EVENT; 7954 bxe_release_phy_lock(sc); 7955 if (IS_MF(sc)) 7956 ; // XXX bxe_link_sync_notify(sc); 7957 bxe_link_report(sc); 7958 } 7959 7960 /* 7961 * Always call it here: bxe_link_report() will 7962 * prevent the link indication duplication. 7963 */ 7964 bxe_link_status_update(sc); 7965 7966 } else if (attn & BXE_MC_ASSERT_BITS) { 7967 7968 BLOGE(sc, "MC assert!\n"); 7969 bxe_mc_assert(sc); 7970 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_10, 0); 7971 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_9, 0); 7972 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_8, 0); 7973 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_7, 0); 7974 bxe_int_disable(sc); 7975 BXE_SET_ERROR_BIT(sc, BXE_ERR_MC_ASSERT); 7976 taskqueue_enqueue_timeout(taskqueue_thread, 7977 &sc->sp_err_timeout_task, hz/10); 7978 7979 } else if (attn & BXE_MCP_ASSERT) { 7980 7981 BLOGE(sc, "MCP assert!\n"); 7982 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_11, 0); 7983 BXE_SET_ERROR_BIT(sc, BXE_ERR_MCP_ASSERT); 7984 taskqueue_enqueue_timeout(taskqueue_thread, 7985 &sc->sp_err_timeout_task, hz/10); 7986 bxe_int_disable(sc); /*avoid repetive assert alert */ 7987 7988 7989 } else { 7990 BLOGE(sc, "Unknown HW assert! (attn 0x%08x)\n", attn); 7991 } 7992 } 7993 7994 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) { 7995 BLOGE(sc, "LATCHED attention 0x%08x (masked)\n", attn); 7996 if (attn & BXE_GRC_TIMEOUT) { 7997 val = CHIP_IS_E1(sc) ? 0 : REG_RD(sc, MISC_REG_GRC_TIMEOUT_ATTN); 7998 BLOGE(sc, "GRC time-out 0x%08x\n", val); 7999 } 8000 if (attn & BXE_GRC_RSV) { 8001 val = CHIP_IS_E1(sc) ? 0 : REG_RD(sc, MISC_REG_GRC_RSV_ATTN); 8002 BLOGE(sc, "GRC reserved 0x%08x\n", val); 8003 } 8004 REG_WR(sc, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff); 8005 } 8006 } 8007 8008 static void 8009 bxe_attn_int_deasserted2(struct bxe_softc *sc, 8010 uint32_t attn) 8011 { 8012 int port = SC_PORT(sc); 8013 int reg_offset; 8014 uint32_t val0, mask0, val1, mask1; 8015 uint32_t val; 8016 bool err_flg = false; 8017 8018 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) { 8019 val = REG_RD(sc, CFC_REG_CFC_INT_STS_CLR); 8020 BLOGE(sc, "CFC hw attention 0x%08x\n", val); 8021 /* CFC error attention */ 8022 if (val & 0x2) { 8023 BLOGE(sc, "FATAL error from CFC\n"); 8024 err_flg = true; 8025 } 8026 } 8027 8028 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) { 8029 val = REG_RD(sc, PXP_REG_PXP_INT_STS_CLR_0); 8030 BLOGE(sc, "PXP hw attention-0 0x%08x\n", val); 8031 /* RQ_USDMDP_FIFO_OVERFLOW */ 8032 if (val & 0x18000) { 8033 BLOGE(sc, "FATAL error from PXP\n"); 8034 err_flg = true; 8035 } 8036 8037 if (!CHIP_IS_E1x(sc)) { 8038 val = REG_RD(sc, PXP_REG_PXP_INT_STS_CLR_1); 8039 BLOGE(sc, "PXP hw attention-1 0x%08x\n", val); 8040 err_flg = true; 8041 } 8042 } 8043 8044 #define PXP2_EOP_ERROR_BIT PXP2_PXP2_INT_STS_CLR_0_REG_WR_PGLUE_EOP_ERROR 8045 #define AEU_PXP2_HW_INT_BIT AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_HW_INTERRUPT 8046 8047 if (attn & AEU_PXP2_HW_INT_BIT) { 8048 /* CQ47854 workaround do not panic on 8049 * PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR 8050 */ 8051 if (!CHIP_IS_E1x(sc)) { 8052 mask0 = REG_RD(sc, PXP2_REG_PXP2_INT_MASK_0); 8053 val1 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_1); 8054 mask1 = REG_RD(sc, PXP2_REG_PXP2_INT_MASK_1); 8055 val0 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_0); 8056 /* 8057 * If the only PXP2_EOP_ERROR_BIT is set in 8058 * STS0 and STS1 - clear it 8059 * 8060 * probably we lose additional attentions between 8061 * STS0 and STS_CLR0, in this case user will not 8062 * be notified about them 8063 */ 8064 if (val0 & mask0 & PXP2_EOP_ERROR_BIT && 8065 !(val1 & mask1)) 8066 val0 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_CLR_0); 8067 8068 /* print the register, since no one can restore it */ 8069 BLOGE(sc, "PXP2_REG_PXP2_INT_STS_CLR_0 0x%08x\n", val0); 8070 8071 /* 8072 * if PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR 8073 * then notify 8074 */ 8075 if (val0 & PXP2_EOP_ERROR_BIT) { 8076 BLOGE(sc, "PXP2_WR_PGLUE_EOP_ERROR\n"); 8077 err_flg = true; 8078 8079 /* 8080 * if only PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR is 8081 * set then clear attention from PXP2 block without panic 8082 */ 8083 if (((val0 & mask0) == PXP2_EOP_ERROR_BIT) && 8084 ((val1 & mask1) == 0)) 8085 attn &= ~AEU_PXP2_HW_INT_BIT; 8086 } 8087 } 8088 } 8089 8090 if (attn & HW_INTERRUT_ASSERT_SET_2) { 8091 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 : 8092 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2); 8093 8094 val = REG_RD(sc, reg_offset); 8095 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2); 8096 REG_WR(sc, reg_offset, val); 8097 8098 BLOGE(sc, "FATAL HW block attention set2 0x%x\n", 8099 (uint32_t)(attn & HW_INTERRUT_ASSERT_SET_2)); 8100 err_flg = true; 8101 bxe_panic(sc, ("HW block attention set2\n")); 8102 } 8103 if(err_flg) { 8104 BXE_SET_ERROR_BIT(sc, BXE_ERR_GLOBAL); 8105 taskqueue_enqueue_timeout(taskqueue_thread, 8106 &sc->sp_err_timeout_task, hz/10); 8107 } 8108 8109 } 8110 8111 static void 8112 bxe_attn_int_deasserted1(struct bxe_softc *sc, 8113 uint32_t attn) 8114 { 8115 int port = SC_PORT(sc); 8116 int reg_offset; 8117 uint32_t val; 8118 bool err_flg = false; 8119 8120 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) { 8121 val = REG_RD(sc, DORQ_REG_DORQ_INT_STS_CLR); 8122 BLOGE(sc, "DB hw attention 0x%08x\n", val); 8123 /* DORQ discard attention */ 8124 if (val & 0x2) { 8125 BLOGE(sc, "FATAL error from DORQ\n"); 8126 err_flg = true; 8127 } 8128 } 8129 8130 if (attn & HW_INTERRUT_ASSERT_SET_1) { 8131 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 : 8132 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1); 8133 8134 val = REG_RD(sc, reg_offset); 8135 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1); 8136 REG_WR(sc, reg_offset, val); 8137 8138 BLOGE(sc, "FATAL HW block attention set1 0x%08x\n", 8139 (uint32_t)(attn & HW_INTERRUT_ASSERT_SET_1)); 8140 err_flg = true; 8141 bxe_panic(sc, ("HW block attention set1\n")); 8142 } 8143 if(err_flg) { 8144 BXE_SET_ERROR_BIT(sc, BXE_ERR_MISC); 8145 taskqueue_enqueue_timeout(taskqueue_thread, 8146 &sc->sp_err_timeout_task, hz/10); 8147 } 8148 8149 } 8150 8151 static void 8152 bxe_attn_int_deasserted0(struct bxe_softc *sc, 8153 uint32_t attn) 8154 { 8155 int port = SC_PORT(sc); 8156 int reg_offset; 8157 uint32_t val; 8158 8159 reg_offset = (port) ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : 8160 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0; 8161 8162 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) { 8163 val = REG_RD(sc, reg_offset); 8164 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5; 8165 REG_WR(sc, reg_offset, val); 8166 8167 BLOGW(sc, "SPIO5 hw attention\n"); 8168 8169 /* Fan failure attention */ 8170 elink_hw_reset_phy(&sc->link_params); 8171 bxe_fan_failure(sc); 8172 } 8173 8174 if ((attn & sc->link_vars.aeu_int_mask) && sc->port.pmf) { 8175 bxe_acquire_phy_lock(sc); 8176 elink_handle_module_detect_int(&sc->link_params); 8177 bxe_release_phy_lock(sc); 8178 } 8179 8180 if (attn & HW_INTERRUT_ASSERT_SET_0) { 8181 val = REG_RD(sc, reg_offset); 8182 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0); 8183 REG_WR(sc, reg_offset, val); 8184 8185 8186 BXE_SET_ERROR_BIT(sc, BXE_ERR_MISC); 8187 taskqueue_enqueue_timeout(taskqueue_thread, 8188 &sc->sp_err_timeout_task, hz/10); 8189 8190 bxe_panic(sc, ("FATAL HW block attention set0 0x%lx\n", 8191 (attn & HW_INTERRUT_ASSERT_SET_0))); 8192 } 8193 } 8194 8195 static void 8196 bxe_attn_int_deasserted(struct bxe_softc *sc, 8197 uint32_t deasserted) 8198 { 8199 struct attn_route attn; 8200 struct attn_route *group_mask; 8201 int port = SC_PORT(sc); 8202 int index; 8203 uint32_t reg_addr; 8204 uint32_t val; 8205 uint32_t aeu_mask; 8206 uint8_t global = FALSE; 8207 8208 /* 8209 * Need to take HW lock because MCP or other port might also 8210 * try to handle this event. 8211 */ 8212 bxe_acquire_alr(sc); 8213 8214 if (bxe_chk_parity_attn(sc, &global, TRUE)) { 8215 /* XXX 8216 * In case of parity errors don't handle attentions so that 8217 * other function would "see" parity errors. 8218 */ 8219 // XXX schedule a recovery task... 8220 /* disable HW interrupts */ 8221 bxe_int_disable(sc); 8222 BXE_SET_ERROR_BIT(sc, BXE_ERR_PARITY); 8223 taskqueue_enqueue_timeout(taskqueue_thread, 8224 &sc->sp_err_timeout_task, hz/10); 8225 bxe_release_alr(sc); 8226 return; 8227 } 8228 8229 attn.sig[0] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4); 8230 attn.sig[1] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4); 8231 attn.sig[2] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4); 8232 attn.sig[3] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4); 8233 if (!CHIP_IS_E1x(sc)) { 8234 attn.sig[4] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4); 8235 } else { 8236 attn.sig[4] = 0; 8237 } 8238 8239 BLOGD(sc, DBG_INTR, "attn: 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n", 8240 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]); 8241 8242 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) { 8243 if (deasserted & (1 << index)) { 8244 group_mask = &sc->attn_group[index]; 8245 8246 BLOGD(sc, DBG_INTR, 8247 "group[%d]: 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n", index, 8248 group_mask->sig[0], group_mask->sig[1], 8249 group_mask->sig[2], group_mask->sig[3], 8250 group_mask->sig[4]); 8251 8252 bxe_attn_int_deasserted4(sc, attn.sig[4] & group_mask->sig[4]); 8253 bxe_attn_int_deasserted3(sc, attn.sig[3] & group_mask->sig[3]); 8254 bxe_attn_int_deasserted1(sc, attn.sig[1] & group_mask->sig[1]); 8255 bxe_attn_int_deasserted2(sc, attn.sig[2] & group_mask->sig[2]); 8256 bxe_attn_int_deasserted0(sc, attn.sig[0] & group_mask->sig[0]); 8257 } 8258 } 8259 8260 bxe_release_alr(sc); 8261 8262 if (sc->devinfo.int_block == INT_BLOCK_HC) { 8263 reg_addr = (HC_REG_COMMAND_REG + port*32 + 8264 COMMAND_REG_ATTN_BITS_CLR); 8265 } else { 8266 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8); 8267 } 8268 8269 val = ~deasserted; 8270 BLOGD(sc, DBG_INTR, 8271 "about to mask 0x%08x at %s addr 0x%08x\n", val, 8272 (sc->devinfo.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr); 8273 REG_WR(sc, reg_addr, val); 8274 8275 if (~sc->attn_state & deasserted) { 8276 BLOGE(sc, "IGU error\n"); 8277 } 8278 8279 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : 8280 MISC_REG_AEU_MASK_ATTN_FUNC_0; 8281 8282 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); 8283 8284 aeu_mask = REG_RD(sc, reg_addr); 8285 8286 BLOGD(sc, DBG_INTR, "aeu_mask 0x%08x newly deasserted 0x%08x\n", 8287 aeu_mask, deasserted); 8288 aeu_mask |= (deasserted & 0x3ff); 8289 BLOGD(sc, DBG_INTR, "new mask 0x%08x\n", aeu_mask); 8290 8291 REG_WR(sc, reg_addr, aeu_mask); 8292 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); 8293 8294 BLOGD(sc, DBG_INTR, "attn_state 0x%08x\n", sc->attn_state); 8295 sc->attn_state &= ~deasserted; 8296 BLOGD(sc, DBG_INTR, "new state 0x%08x\n", sc->attn_state); 8297 } 8298 8299 static void 8300 bxe_attn_int(struct bxe_softc *sc) 8301 { 8302 /* read local copy of bits */ 8303 uint32_t attn_bits = le32toh(sc->def_sb->atten_status_block.attn_bits); 8304 uint32_t attn_ack = le32toh(sc->def_sb->atten_status_block.attn_bits_ack); 8305 uint32_t attn_state = sc->attn_state; 8306 8307 /* look for changed bits */ 8308 uint32_t asserted = attn_bits & ~attn_ack & ~attn_state; 8309 uint32_t deasserted = ~attn_bits & attn_ack & attn_state; 8310 8311 BLOGD(sc, DBG_INTR, 8312 "attn_bits 0x%08x attn_ack 0x%08x asserted 0x%08x deasserted 0x%08x\n", 8313 attn_bits, attn_ack, asserted, deasserted); 8314 8315 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state)) { 8316 BLOGE(sc, "BAD attention state\n"); 8317 } 8318 8319 /* handle bits that were raised */ 8320 if (asserted) { 8321 bxe_attn_int_asserted(sc, asserted); 8322 } 8323 8324 if (deasserted) { 8325 bxe_attn_int_deasserted(sc, deasserted); 8326 } 8327 } 8328 8329 static uint16_t 8330 bxe_update_dsb_idx(struct bxe_softc *sc) 8331 { 8332 struct host_sp_status_block *def_sb = sc->def_sb; 8333 uint16_t rc = 0; 8334 8335 mb(); /* status block is written to by the chip */ 8336 8337 if (sc->def_att_idx != def_sb->atten_status_block.attn_bits_index) { 8338 sc->def_att_idx = def_sb->atten_status_block.attn_bits_index; 8339 rc |= BXE_DEF_SB_ATT_IDX; 8340 } 8341 8342 if (sc->def_idx != def_sb->sp_sb.running_index) { 8343 sc->def_idx = def_sb->sp_sb.running_index; 8344 rc |= BXE_DEF_SB_IDX; 8345 } 8346 8347 mb(); 8348 8349 return (rc); 8350 } 8351 8352 static inline struct ecore_queue_sp_obj * 8353 bxe_cid_to_q_obj(struct bxe_softc *sc, 8354 uint32_t cid) 8355 { 8356 BLOGD(sc, DBG_SP, "retrieving fp from cid %d\n", cid); 8357 return (&sc->sp_objs[CID_TO_FP(cid, sc)].q_obj); 8358 } 8359 8360 static void 8361 bxe_handle_mcast_eqe(struct bxe_softc *sc) 8362 { 8363 struct ecore_mcast_ramrod_params rparam; 8364 int rc; 8365 8366 memset(&rparam, 0, sizeof(rparam)); 8367 8368 rparam.mcast_obj = &sc->mcast_obj; 8369 8370 BXE_MCAST_LOCK(sc); 8371 8372 /* clear pending state for the last command */ 8373 sc->mcast_obj.raw.clear_pending(&sc->mcast_obj.raw); 8374 8375 /* if there are pending mcast commands - send them */ 8376 if (sc->mcast_obj.check_pending(&sc->mcast_obj)) { 8377 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT); 8378 if (rc < 0) { 8379 BLOGD(sc, DBG_SP, 8380 "ERROR: Failed to send pending mcast commands (%d)\n", rc); 8381 } 8382 } 8383 8384 BXE_MCAST_UNLOCK(sc); 8385 } 8386 8387 static void 8388 bxe_handle_classification_eqe(struct bxe_softc *sc, 8389 union event_ring_elem *elem) 8390 { 8391 unsigned long ramrod_flags = 0; 8392 int rc = 0; 8393 uint32_t cid = elem->message.data.eth_event.echo & BXE_SWCID_MASK; 8394 struct ecore_vlan_mac_obj *vlan_mac_obj; 8395 8396 /* always push next commands out, don't wait here */ 8397 bit_set(&ramrod_flags, RAMROD_CONT); 8398 8399 switch (le32toh(elem->message.data.eth_event.echo) >> BXE_SWCID_SHIFT) { 8400 case ECORE_FILTER_MAC_PENDING: 8401 BLOGD(sc, DBG_SP, "Got SETUP_MAC completions\n"); 8402 vlan_mac_obj = &sc->sp_objs[cid].mac_obj; 8403 break; 8404 8405 case ECORE_FILTER_MCAST_PENDING: 8406 BLOGD(sc, DBG_SP, "Got SETUP_MCAST completions\n"); 8407 /* 8408 * This is only relevant for 57710 where multicast MACs are 8409 * configured as unicast MACs using the same ramrod. 8410 */ 8411 bxe_handle_mcast_eqe(sc); 8412 return; 8413 8414 default: 8415 BLOGE(sc, "Unsupported classification command: %d\n", 8416 elem->message.data.eth_event.echo); 8417 return; 8418 } 8419 8420 rc = vlan_mac_obj->complete(sc, vlan_mac_obj, elem, &ramrod_flags); 8421 8422 if (rc < 0) { 8423 BLOGE(sc, "Failed to schedule new commands (%d)\n", rc); 8424 } else if (rc > 0) { 8425 BLOGD(sc, DBG_SP, "Scheduled next pending commands...\n"); 8426 } 8427 } 8428 8429 static void 8430 bxe_handle_rx_mode_eqe(struct bxe_softc *sc, 8431 union event_ring_elem *elem) 8432 { 8433 bxe_clear_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state); 8434 8435 /* send rx_mode command again if was requested */ 8436 if (bxe_test_and_clear_bit(ECORE_FILTER_RX_MODE_SCHED, 8437 &sc->sp_state)) { 8438 bxe_set_storm_rx_mode(sc); 8439 } 8440 } 8441 8442 static void 8443 bxe_update_eq_prod(struct bxe_softc *sc, 8444 uint16_t prod) 8445 { 8446 storm_memset_eq_prod(sc, prod, SC_FUNC(sc)); 8447 wmb(); /* keep prod updates ordered */ 8448 } 8449 8450 static void 8451 bxe_eq_int(struct bxe_softc *sc) 8452 { 8453 uint16_t hw_cons, sw_cons, sw_prod; 8454 union event_ring_elem *elem; 8455 uint8_t echo; 8456 uint32_t cid; 8457 uint8_t opcode; 8458 int spqe_cnt = 0; 8459 struct ecore_queue_sp_obj *q_obj; 8460 struct ecore_func_sp_obj *f_obj = &sc->func_obj; 8461 struct ecore_raw_obj *rss_raw = &sc->rss_conf_obj.raw; 8462 8463 hw_cons = le16toh(*sc->eq_cons_sb); 8464 8465 /* 8466 * The hw_cons range is 1-255, 257 - the sw_cons range is 0-254, 256. 8467 * when we get to the next-page we need to adjust so the loop 8468 * condition below will be met. The next element is the size of a 8469 * regular element and hence incrementing by 1 8470 */ 8471 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE) { 8472 hw_cons++; 8473 } 8474 8475 /* 8476 * This function may never run in parallel with itself for a 8477 * specific sc and no need for a read memory barrier here. 8478 */ 8479 sw_cons = sc->eq_cons; 8480 sw_prod = sc->eq_prod; 8481 8482 BLOGD(sc, DBG_SP,"EQ: hw_cons=%u sw_cons=%u eq_spq_left=0x%lx\n", 8483 hw_cons, sw_cons, atomic_load_acq_long(&sc->eq_spq_left)); 8484 8485 for (; 8486 sw_cons != hw_cons; 8487 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) { 8488 8489 elem = &sc->eq[EQ_DESC(sw_cons)]; 8490 8491 /* elem CID originates from FW, actually LE */ 8492 cid = SW_CID(elem->message.data.cfc_del_event.cid); 8493 opcode = elem->message.opcode; 8494 8495 /* handle eq element */ 8496 switch (opcode) { 8497 8498 case EVENT_RING_OPCODE_STAT_QUERY: 8499 BLOGD(sc, DBG_SP, "got statistics completion event %d\n", 8500 sc->stats_comp++); 8501 /* nothing to do with stats comp */ 8502 goto next_spqe; 8503 8504 case EVENT_RING_OPCODE_CFC_DEL: 8505 /* handle according to cid range */ 8506 /* we may want to verify here that the sc state is HALTING */ 8507 BLOGD(sc, DBG_SP, "got delete ramrod for MULTI[%d]\n", cid); 8508 q_obj = bxe_cid_to_q_obj(sc, cid); 8509 if (q_obj->complete_cmd(sc, q_obj, ECORE_Q_CMD_CFC_DEL)) { 8510 break; 8511 } 8512 goto next_spqe; 8513 8514 case EVENT_RING_OPCODE_STOP_TRAFFIC: 8515 BLOGD(sc, DBG_SP, "got STOP TRAFFIC\n"); 8516 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_TX_STOP)) { 8517 break; 8518 } 8519 // XXX bxe_dcbx_set_params(sc, BXE_DCBX_STATE_TX_PAUSED); 8520 goto next_spqe; 8521 8522 case EVENT_RING_OPCODE_START_TRAFFIC: 8523 BLOGD(sc, DBG_SP, "got START TRAFFIC\n"); 8524 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_TX_START)) { 8525 break; 8526 } 8527 // XXX bxe_dcbx_set_params(sc, BXE_DCBX_STATE_TX_RELEASED); 8528 goto next_spqe; 8529 8530 case EVENT_RING_OPCODE_FUNCTION_UPDATE: 8531 echo = elem->message.data.function_update_event.echo; 8532 if (echo == SWITCH_UPDATE) { 8533 BLOGD(sc, DBG_SP, "got FUNC_SWITCH_UPDATE ramrod\n"); 8534 if (f_obj->complete_cmd(sc, f_obj, 8535 ECORE_F_CMD_SWITCH_UPDATE)) { 8536 break; 8537 } 8538 } 8539 else { 8540 BLOGD(sc, DBG_SP, 8541 "AFEX: ramrod completed FUNCTION_UPDATE\n"); 8542 } 8543 goto next_spqe; 8544 8545 case EVENT_RING_OPCODE_FORWARD_SETUP: 8546 q_obj = &bxe_fwd_sp_obj(sc, q_obj); 8547 if (q_obj->complete_cmd(sc, q_obj, 8548 ECORE_Q_CMD_SETUP_TX_ONLY)) { 8549 break; 8550 } 8551 goto next_spqe; 8552 8553 case EVENT_RING_OPCODE_FUNCTION_START: 8554 BLOGD(sc, DBG_SP, "got FUNC_START ramrod\n"); 8555 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_START)) { 8556 break; 8557 } 8558 goto next_spqe; 8559 8560 case EVENT_RING_OPCODE_FUNCTION_STOP: 8561 BLOGD(sc, DBG_SP, "got FUNC_STOP ramrod\n"); 8562 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_STOP)) { 8563 break; 8564 } 8565 goto next_spqe; 8566 } 8567 8568 switch (opcode | sc->state) { 8569 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | BXE_STATE_OPEN): 8570 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | BXE_STATE_OPENING_WAITING_PORT): 8571 cid = elem->message.data.eth_event.echo & BXE_SWCID_MASK; 8572 BLOGD(sc, DBG_SP, "got RSS_UPDATE ramrod. CID %d\n", cid); 8573 rss_raw->clear_pending(rss_raw); 8574 break; 8575 8576 case (EVENT_RING_OPCODE_SET_MAC | BXE_STATE_OPEN): 8577 case (EVENT_RING_OPCODE_SET_MAC | BXE_STATE_DIAG): 8578 case (EVENT_RING_OPCODE_SET_MAC | BXE_STATE_CLOSING_WAITING_HALT): 8579 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BXE_STATE_OPEN): 8580 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BXE_STATE_DIAG): 8581 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BXE_STATE_CLOSING_WAITING_HALT): 8582 BLOGD(sc, DBG_SP, "got (un)set mac ramrod\n"); 8583 bxe_handle_classification_eqe(sc, elem); 8584 break; 8585 8586 case (EVENT_RING_OPCODE_MULTICAST_RULES | BXE_STATE_OPEN): 8587 case (EVENT_RING_OPCODE_MULTICAST_RULES | BXE_STATE_DIAG): 8588 case (EVENT_RING_OPCODE_MULTICAST_RULES | BXE_STATE_CLOSING_WAITING_HALT): 8589 BLOGD(sc, DBG_SP, "got mcast ramrod\n"); 8590 bxe_handle_mcast_eqe(sc); 8591 break; 8592 8593 case (EVENT_RING_OPCODE_FILTERS_RULES | BXE_STATE_OPEN): 8594 case (EVENT_RING_OPCODE_FILTERS_RULES | BXE_STATE_DIAG): 8595 case (EVENT_RING_OPCODE_FILTERS_RULES | BXE_STATE_CLOSING_WAITING_HALT): 8596 BLOGD(sc, DBG_SP, "got rx_mode ramrod\n"); 8597 bxe_handle_rx_mode_eqe(sc, elem); 8598 break; 8599 8600 default: 8601 /* unknown event log error and continue */ 8602 BLOGE(sc, "Unknown EQ event %d, sc->state 0x%x\n", 8603 elem->message.opcode, sc->state); 8604 } 8605 8606 next_spqe: 8607 spqe_cnt++; 8608 } /* for */ 8609 8610 mb(); 8611 atomic_add_acq_long(&sc->eq_spq_left, spqe_cnt); 8612 8613 sc->eq_cons = sw_cons; 8614 sc->eq_prod = sw_prod; 8615 8616 /* make sure that above mem writes were issued towards the memory */ 8617 wmb(); 8618 8619 /* update producer */ 8620 bxe_update_eq_prod(sc, sc->eq_prod); 8621 } 8622 8623 static void 8624 bxe_handle_sp_tq(void *context, 8625 int pending) 8626 { 8627 struct bxe_softc *sc = (struct bxe_softc *)context; 8628 uint16_t status; 8629 8630 BLOGD(sc, DBG_SP, "---> SP TASK <---\n"); 8631 8632 /* what work needs to be performed? */ 8633 status = bxe_update_dsb_idx(sc); 8634 8635 BLOGD(sc, DBG_SP, "dsb status 0x%04x\n", status); 8636 8637 /* HW attentions */ 8638 if (status & BXE_DEF_SB_ATT_IDX) { 8639 BLOGD(sc, DBG_SP, "---> ATTN INTR <---\n"); 8640 bxe_attn_int(sc); 8641 status &= ~BXE_DEF_SB_ATT_IDX; 8642 } 8643 8644 /* SP events: STAT_QUERY and others */ 8645 if (status & BXE_DEF_SB_IDX) { 8646 /* handle EQ completions */ 8647 BLOGD(sc, DBG_SP, "---> EQ INTR <---\n"); 8648 bxe_eq_int(sc); 8649 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID, 8650 le16toh(sc->def_idx), IGU_INT_NOP, 1); 8651 status &= ~BXE_DEF_SB_IDX; 8652 } 8653 8654 /* if status is non zero then something went wrong */ 8655 if (__predict_false(status)) { 8656 BLOGE(sc, "Got an unknown SP interrupt! (0x%04x)\n", status); 8657 } 8658 8659 /* ack status block only if something was actually handled */ 8660 bxe_ack_sb(sc, sc->igu_dsb_id, ATTENTION_ID, 8661 le16toh(sc->def_att_idx), IGU_INT_ENABLE, 1); 8662 8663 /* 8664 * Must be called after the EQ processing (since eq leads to sriov 8665 * ramrod completion flows). 8666 * This flow may have been scheduled by the arrival of a ramrod 8667 * completion, or by the sriov code rescheduling itself. 8668 */ 8669 // XXX bxe_iov_sp_task(sc); 8670 8671 } 8672 8673 static void 8674 bxe_handle_fp_tq(void *context, 8675 int pending) 8676 { 8677 struct bxe_fastpath *fp = (struct bxe_fastpath *)context; 8678 struct bxe_softc *sc = fp->sc; 8679 /* uint8_t more_tx = FALSE; */ 8680 uint8_t more_rx = FALSE; 8681 8682 BLOGD(sc, DBG_INTR, "---> FP TASK QUEUE (%d) <---\n", fp->index); 8683 8684 /* XXX 8685 * IFF_DRV_RUNNING state can't be checked here since we process 8686 * slowpath events on a client queue during setup. Instead 8687 * we need to add a "process/continue" flag here that the driver 8688 * can use to tell the task here not to do anything. 8689 */ 8690 #if 0 8691 if (!(if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING)) { 8692 return; 8693 } 8694 #endif 8695 8696 /* update the fastpath index */ 8697 bxe_update_fp_sb_idx(fp); 8698 8699 /* XXX add loop here if ever support multiple tx CoS */ 8700 /* fp->txdata[cos] */ 8701 if (bxe_has_tx_work(fp)) { 8702 BXE_FP_TX_LOCK(fp); 8703 /* more_tx = */ bxe_txeof(sc, fp); 8704 BXE_FP_TX_UNLOCK(fp); 8705 } 8706 8707 if (bxe_has_rx_work(fp)) { 8708 more_rx = bxe_rxeof(sc, fp); 8709 } 8710 8711 if (more_rx /*|| more_tx*/) { 8712 /* still more work to do */ 8713 taskqueue_enqueue(fp->tq, &fp->tq_task); 8714 return; 8715 } 8716 8717 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 8718 le16toh(fp->fp_hc_idx), IGU_INT_ENABLE, 1); 8719 } 8720 8721 static void 8722 bxe_task_fp(struct bxe_fastpath *fp) 8723 { 8724 struct bxe_softc *sc = fp->sc; 8725 /* uint8_t more_tx = FALSE; */ 8726 uint8_t more_rx = FALSE; 8727 8728 BLOGD(sc, DBG_INTR, "---> FP TASK ISR (%d) <---\n", fp->index); 8729 8730 /* update the fastpath index */ 8731 bxe_update_fp_sb_idx(fp); 8732 8733 /* XXX add loop here if ever support multiple tx CoS */ 8734 /* fp->txdata[cos] */ 8735 if (bxe_has_tx_work(fp)) { 8736 BXE_FP_TX_LOCK(fp); 8737 /* more_tx = */ bxe_txeof(sc, fp); 8738 BXE_FP_TX_UNLOCK(fp); 8739 } 8740 8741 if (bxe_has_rx_work(fp)) { 8742 more_rx = bxe_rxeof(sc, fp); 8743 } 8744 8745 if (more_rx /*|| more_tx*/) { 8746 /* still more work to do, bail out if this ISR and process later */ 8747 taskqueue_enqueue(fp->tq, &fp->tq_task); 8748 return; 8749 } 8750 8751 /* 8752 * Here we write the fastpath index taken before doing any tx or rx work. 8753 * It is very well possible other hw events occurred up to this point and 8754 * they were actually processed accordingly above. Since we're going to 8755 * write an older fastpath index, an interrupt is coming which we might 8756 * not do any work in. 8757 */ 8758 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 8759 le16toh(fp->fp_hc_idx), IGU_INT_ENABLE, 1); 8760 } 8761 8762 /* 8763 * Legacy interrupt entry point. 8764 * 8765 * Verifies that the controller generated the interrupt and 8766 * then calls a separate routine to handle the various 8767 * interrupt causes: link, RX, and TX. 8768 */ 8769 static void 8770 bxe_intr_legacy(void *xsc) 8771 { 8772 struct bxe_softc *sc = (struct bxe_softc *)xsc; 8773 struct bxe_fastpath *fp; 8774 uint16_t status, mask; 8775 int i; 8776 8777 BLOGD(sc, DBG_INTR, "---> BXE INTx <---\n"); 8778 8779 /* 8780 * 0 for ustorm, 1 for cstorm 8781 * the bits returned from ack_int() are 0-15 8782 * bit 0 = attention status block 8783 * bit 1 = fast path status block 8784 * a mask of 0x2 or more = tx/rx event 8785 * a mask of 1 = slow path event 8786 */ 8787 8788 status = bxe_ack_int(sc); 8789 8790 /* the interrupt is not for us */ 8791 if (__predict_false(status == 0)) { 8792 BLOGD(sc, DBG_INTR, "Not our interrupt!\n"); 8793 return; 8794 } 8795 8796 BLOGD(sc, DBG_INTR, "Interrupt status 0x%04x\n", status); 8797 8798 FOR_EACH_ETH_QUEUE(sc, i) { 8799 fp = &sc->fp[i]; 8800 mask = (0x2 << (fp->index + CNIC_SUPPORT(sc))); 8801 if (status & mask) { 8802 /* acknowledge and disable further fastpath interrupts */ 8803 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0); 8804 bxe_task_fp(fp); 8805 status &= ~mask; 8806 } 8807 } 8808 8809 if (__predict_false(status & 0x1)) { 8810 /* acknowledge and disable further slowpath interrupts */ 8811 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0); 8812 8813 /* schedule slowpath handler */ 8814 taskqueue_enqueue(sc->sp_tq, &sc->sp_tq_task); 8815 8816 status &= ~0x1; 8817 } 8818 8819 if (__predict_false(status)) { 8820 BLOGW(sc, "Unexpected fastpath status (0x%08x)!\n", status); 8821 } 8822 } 8823 8824 /* slowpath interrupt entry point */ 8825 static void 8826 bxe_intr_sp(void *xsc) 8827 { 8828 struct bxe_softc *sc = (struct bxe_softc *)xsc; 8829 8830 BLOGD(sc, (DBG_INTR | DBG_SP), "---> SP INTR <---\n"); 8831 8832 /* acknowledge and disable further slowpath interrupts */ 8833 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0); 8834 8835 /* schedule slowpath handler */ 8836 taskqueue_enqueue(sc->sp_tq, &sc->sp_tq_task); 8837 } 8838 8839 /* fastpath interrupt entry point */ 8840 static void 8841 bxe_intr_fp(void *xfp) 8842 { 8843 struct bxe_fastpath *fp = (struct bxe_fastpath *)xfp; 8844 struct bxe_softc *sc = fp->sc; 8845 8846 BLOGD(sc, DBG_INTR, "---> FP INTR %d <---\n", fp->index); 8847 8848 BLOGD(sc, DBG_INTR, 8849 "(cpu=%d) MSI-X fp=%d fw_sb=%d igu_sb=%d\n", 8850 curcpu, fp->index, fp->fw_sb_id, fp->igu_sb_id); 8851 8852 /* acknowledge and disable further fastpath interrupts */ 8853 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0); 8854 8855 bxe_task_fp(fp); 8856 } 8857 8858 /* Release all interrupts allocated by the driver. */ 8859 static void 8860 bxe_interrupt_free(struct bxe_softc *sc) 8861 { 8862 int i; 8863 8864 switch (sc->interrupt_mode) { 8865 case INTR_MODE_INTX: 8866 BLOGD(sc, DBG_LOAD, "Releasing legacy INTx vector\n"); 8867 if (sc->intr[0].resource != NULL) { 8868 bus_release_resource(sc->dev, 8869 SYS_RES_IRQ, 8870 sc->intr[0].rid, 8871 sc->intr[0].resource); 8872 } 8873 break; 8874 case INTR_MODE_MSI: 8875 for (i = 0; i < sc->intr_count; i++) { 8876 BLOGD(sc, DBG_LOAD, "Releasing MSI vector %d\n", i); 8877 if (sc->intr[i].resource && sc->intr[i].rid) { 8878 bus_release_resource(sc->dev, 8879 SYS_RES_IRQ, 8880 sc->intr[i].rid, 8881 sc->intr[i].resource); 8882 } 8883 } 8884 pci_release_msi(sc->dev); 8885 break; 8886 case INTR_MODE_MSIX: 8887 for (i = 0; i < sc->intr_count; i++) { 8888 BLOGD(sc, DBG_LOAD, "Releasing MSI-X vector %d\n", i); 8889 if (sc->intr[i].resource && sc->intr[i].rid) { 8890 bus_release_resource(sc->dev, 8891 SYS_RES_IRQ, 8892 sc->intr[i].rid, 8893 sc->intr[i].resource); 8894 } 8895 } 8896 pci_release_msi(sc->dev); 8897 break; 8898 default: 8899 /* nothing to do as initial allocation failed */ 8900 break; 8901 } 8902 } 8903 8904 /* 8905 * This function determines and allocates the appropriate 8906 * interrupt based on system capabilites and user request. 8907 * 8908 * The user may force a particular interrupt mode, specify 8909 * the number of receive queues, specify the method for 8910 * distribuitng received frames to receive queues, or use 8911 * the default settings which will automatically select the 8912 * best supported combination. In addition, the OS may or 8913 * may not support certain combinations of these settings. 8914 * This routine attempts to reconcile the settings requested 8915 * by the user with the capabilites available from the system 8916 * to select the optimal combination of features. 8917 * 8918 * Returns: 8919 * 0 = Success, !0 = Failure. 8920 */ 8921 static int 8922 bxe_interrupt_alloc(struct bxe_softc *sc) 8923 { 8924 int msix_count = 0; 8925 int msi_count = 0; 8926 int num_requested = 0; 8927 int num_allocated = 0; 8928 int rid, i, j; 8929 int rc; 8930 8931 /* get the number of available MSI/MSI-X interrupts from the OS */ 8932 if (sc->interrupt_mode > 0) { 8933 if (sc->devinfo.pcie_cap_flags & BXE_MSIX_CAPABLE_FLAG) { 8934 msix_count = pci_msix_count(sc->dev); 8935 } 8936 8937 if (sc->devinfo.pcie_cap_flags & BXE_MSI_CAPABLE_FLAG) { 8938 msi_count = pci_msi_count(sc->dev); 8939 } 8940 8941 BLOGD(sc, DBG_LOAD, "%d MSI and %d MSI-X vectors available\n", 8942 msi_count, msix_count); 8943 } 8944 8945 do { /* try allocating MSI-X interrupt resources (at least 2) */ 8946 if (sc->interrupt_mode != INTR_MODE_MSIX) { 8947 break; 8948 } 8949 8950 if (((sc->devinfo.pcie_cap_flags & BXE_MSIX_CAPABLE_FLAG) == 0) || 8951 (msix_count < 2)) { 8952 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */ 8953 break; 8954 } 8955 8956 /* ask for the necessary number of MSI-X vectors */ 8957 num_requested = min((sc->num_queues + 1), msix_count); 8958 8959 BLOGD(sc, DBG_LOAD, "Requesting %d MSI-X vectors\n", num_requested); 8960 8961 num_allocated = num_requested; 8962 if ((rc = pci_alloc_msix(sc->dev, &num_allocated)) != 0) { 8963 BLOGE(sc, "MSI-X alloc failed! (%d)\n", rc); 8964 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */ 8965 break; 8966 } 8967 8968 if (num_allocated < 2) { /* possible? */ 8969 BLOGE(sc, "MSI-X allocation less than 2!\n"); 8970 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */ 8971 pci_release_msi(sc->dev); 8972 break; 8973 } 8974 8975 BLOGI(sc, "MSI-X vectors Requested %d and Allocated %d\n", 8976 num_requested, num_allocated); 8977 8978 /* best effort so use the number of vectors allocated to us */ 8979 sc->intr_count = num_allocated; 8980 sc->num_queues = num_allocated - 1; 8981 8982 rid = 1; /* initial resource identifier */ 8983 8984 /* allocate the MSI-X vectors */ 8985 for (i = 0; i < num_allocated; i++) { 8986 sc->intr[i].rid = (rid + i); 8987 8988 if ((sc->intr[i].resource = 8989 bus_alloc_resource_any(sc->dev, 8990 SYS_RES_IRQ, 8991 &sc->intr[i].rid, 8992 RF_ACTIVE)) == NULL) { 8993 BLOGE(sc, "Failed to map MSI-X[%d] (rid=%d)!\n", 8994 i, (rid + i)); 8995 8996 for (j = (i - 1); j >= 0; j--) { 8997 bus_release_resource(sc->dev, 8998 SYS_RES_IRQ, 8999 sc->intr[j].rid, 9000 sc->intr[j].resource); 9001 } 9002 9003 sc->intr_count = 0; 9004 sc->num_queues = 0; 9005 sc->interrupt_mode = INTR_MODE_MSI; /* try MSI next */ 9006 pci_release_msi(sc->dev); 9007 break; 9008 } 9009 9010 BLOGD(sc, DBG_LOAD, "Mapped MSI-X[%d] (rid=%d)\n", i, (rid + i)); 9011 } 9012 } while (0); 9013 9014 do { /* try allocating MSI vector resources (at least 2) */ 9015 if (sc->interrupt_mode != INTR_MODE_MSI) { 9016 break; 9017 } 9018 9019 if (((sc->devinfo.pcie_cap_flags & BXE_MSI_CAPABLE_FLAG) == 0) || 9020 (msi_count < 1)) { 9021 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */ 9022 break; 9023 } 9024 9025 /* ask for a single MSI vector */ 9026 num_requested = 1; 9027 9028 BLOGD(sc, DBG_LOAD, "Requesting %d MSI vectors\n", num_requested); 9029 9030 num_allocated = num_requested; 9031 if ((rc = pci_alloc_msi(sc->dev, &num_allocated)) != 0) { 9032 BLOGE(sc, "MSI alloc failed (%d)!\n", rc); 9033 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */ 9034 break; 9035 } 9036 9037 if (num_allocated != 1) { /* possible? */ 9038 BLOGE(sc, "MSI allocation is not 1!\n"); 9039 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */ 9040 pci_release_msi(sc->dev); 9041 break; 9042 } 9043 9044 BLOGI(sc, "MSI vectors Requested %d and Allocated %d\n", 9045 num_requested, num_allocated); 9046 9047 /* best effort so use the number of vectors allocated to us */ 9048 sc->intr_count = num_allocated; 9049 sc->num_queues = num_allocated; 9050 9051 rid = 1; /* initial resource identifier */ 9052 9053 sc->intr[0].rid = rid; 9054 9055 if ((sc->intr[0].resource = 9056 bus_alloc_resource_any(sc->dev, 9057 SYS_RES_IRQ, 9058 &sc->intr[0].rid, 9059 RF_ACTIVE)) == NULL) { 9060 BLOGE(sc, "Failed to map MSI[0] (rid=%d)!\n", rid); 9061 sc->intr_count = 0; 9062 sc->num_queues = 0; 9063 sc->interrupt_mode = INTR_MODE_INTX; /* try INTx next */ 9064 pci_release_msi(sc->dev); 9065 break; 9066 } 9067 9068 BLOGD(sc, DBG_LOAD, "Mapped MSI[0] (rid=%d)\n", rid); 9069 } while (0); 9070 9071 do { /* try allocating INTx vector resources */ 9072 if (sc->interrupt_mode != INTR_MODE_INTX) { 9073 break; 9074 } 9075 9076 BLOGD(sc, DBG_LOAD, "Requesting legacy INTx interrupt\n"); 9077 9078 /* only one vector for INTx */ 9079 sc->intr_count = 1; 9080 sc->num_queues = 1; 9081 9082 rid = 0; /* initial resource identifier */ 9083 9084 sc->intr[0].rid = rid; 9085 9086 if ((sc->intr[0].resource = 9087 bus_alloc_resource_any(sc->dev, 9088 SYS_RES_IRQ, 9089 &sc->intr[0].rid, 9090 (RF_ACTIVE | RF_SHAREABLE))) == NULL) { 9091 BLOGE(sc, "Failed to map INTx (rid=%d)!\n", rid); 9092 sc->intr_count = 0; 9093 sc->num_queues = 0; 9094 sc->interrupt_mode = -1; /* Failed! */ 9095 break; 9096 } 9097 9098 BLOGD(sc, DBG_LOAD, "Mapped INTx (rid=%d)\n", rid); 9099 } while (0); 9100 9101 if (sc->interrupt_mode == -1) { 9102 BLOGE(sc, "Interrupt Allocation: FAILED!!!\n"); 9103 rc = 1; 9104 } else { 9105 BLOGD(sc, DBG_LOAD, 9106 "Interrupt Allocation: interrupt_mode=%d, num_queues=%d\n", 9107 sc->interrupt_mode, sc->num_queues); 9108 rc = 0; 9109 } 9110 9111 return (rc); 9112 } 9113 9114 static void 9115 bxe_interrupt_detach(struct bxe_softc *sc) 9116 { 9117 struct bxe_fastpath *fp; 9118 int i; 9119 9120 /* release interrupt resources */ 9121 for (i = 0; i < sc->intr_count; i++) { 9122 if (sc->intr[i].resource && sc->intr[i].tag) { 9123 BLOGD(sc, DBG_LOAD, "Disabling interrupt vector %d\n", i); 9124 bus_teardown_intr(sc->dev, sc->intr[i].resource, sc->intr[i].tag); 9125 } 9126 } 9127 9128 for (i = 0; i < sc->num_queues; i++) { 9129 fp = &sc->fp[i]; 9130 if (fp->tq) { 9131 taskqueue_drain(fp->tq, &fp->tq_task); 9132 taskqueue_drain(fp->tq, &fp->tx_task); 9133 while (taskqueue_cancel_timeout(fp->tq, &fp->tx_timeout_task, 9134 NULL)) 9135 taskqueue_drain_timeout(fp->tq, &fp->tx_timeout_task); 9136 } 9137 9138 for (i = 0; i < sc->num_queues; i++) { 9139 fp = &sc->fp[i]; 9140 if (fp->tq != NULL) { 9141 taskqueue_free(fp->tq); 9142 fp->tq = NULL; 9143 } 9144 } 9145 } 9146 9147 if (sc->sp_tq) { 9148 taskqueue_drain(sc->sp_tq, &sc->sp_tq_task); 9149 taskqueue_free(sc->sp_tq); 9150 sc->sp_tq = NULL; 9151 } 9152 } 9153 9154 /* 9155 * Enables interrupts and attach to the ISR. 9156 * 9157 * When using multiple MSI/MSI-X vectors the first vector 9158 * is used for slowpath operations while all remaining 9159 * vectors are used for fastpath operations. If only a 9160 * single MSI/MSI-X vector is used (SINGLE_ISR) then the 9161 * ISR must look for both slowpath and fastpath completions. 9162 */ 9163 static int 9164 bxe_interrupt_attach(struct bxe_softc *sc) 9165 { 9166 struct bxe_fastpath *fp; 9167 int rc = 0; 9168 int i; 9169 9170 snprintf(sc->sp_tq_name, sizeof(sc->sp_tq_name), 9171 "bxe%d_sp_tq", sc->unit); 9172 TASK_INIT(&sc->sp_tq_task, 0, bxe_handle_sp_tq, sc); 9173 sc->sp_tq = taskqueue_create(sc->sp_tq_name, M_NOWAIT, 9174 taskqueue_thread_enqueue, 9175 &sc->sp_tq); 9176 taskqueue_start_threads(&sc->sp_tq, 1, PWAIT, /* lower priority */ 9177 "%s", sc->sp_tq_name); 9178 9179 9180 for (i = 0; i < sc->num_queues; i++) { 9181 fp = &sc->fp[i]; 9182 snprintf(fp->tq_name, sizeof(fp->tq_name), 9183 "bxe%d_fp%d_tq", sc->unit, i); 9184 NET_TASK_INIT(&fp->tq_task, 0, bxe_handle_fp_tq, fp); 9185 TASK_INIT(&fp->tx_task, 0, bxe_tx_mq_start_deferred, fp); 9186 fp->tq = taskqueue_create(fp->tq_name, M_NOWAIT, 9187 taskqueue_thread_enqueue, 9188 &fp->tq); 9189 TIMEOUT_TASK_INIT(fp->tq, &fp->tx_timeout_task, 0, 9190 bxe_tx_mq_start_deferred, fp); 9191 taskqueue_start_threads(&fp->tq, 1, PI_NET, /* higher priority */ 9192 "%s", fp->tq_name); 9193 } 9194 9195 /* setup interrupt handlers */ 9196 if (sc->interrupt_mode == INTR_MODE_MSIX) { 9197 BLOGD(sc, DBG_LOAD, "Enabling slowpath MSI-X[0] vector\n"); 9198 9199 /* 9200 * Setup the interrupt handler. Note that we pass the driver instance 9201 * to the interrupt handler for the slowpath. 9202 */ 9203 if ((rc = bus_setup_intr(sc->dev, sc->intr[0].resource, 9204 (INTR_TYPE_NET | INTR_MPSAFE), 9205 NULL, bxe_intr_sp, sc, 9206 &sc->intr[0].tag)) != 0) { 9207 BLOGE(sc, "Failed to allocate MSI-X[0] vector (%d)\n", rc); 9208 goto bxe_interrupt_attach_exit; 9209 } 9210 9211 bus_describe_intr(sc->dev, sc->intr[0].resource, 9212 sc->intr[0].tag, "sp"); 9213 9214 /* bus_bind_intr(sc->dev, sc->intr[0].resource, 0); */ 9215 9216 /* initialize the fastpath vectors (note the first was used for sp) */ 9217 for (i = 0; i < sc->num_queues; i++) { 9218 fp = &sc->fp[i]; 9219 BLOGD(sc, DBG_LOAD, "Enabling MSI-X[%d] vector\n", (i + 1)); 9220 9221 /* 9222 * Setup the interrupt handler. Note that we pass the 9223 * fastpath context to the interrupt handler in this 9224 * case. 9225 */ 9226 if ((rc = bus_setup_intr(sc->dev, sc->intr[i + 1].resource, 9227 (INTR_TYPE_NET | INTR_MPSAFE), 9228 NULL, bxe_intr_fp, fp, 9229 &sc->intr[i + 1].tag)) != 0) { 9230 BLOGE(sc, "Failed to allocate MSI-X[%d] vector (%d)\n", 9231 (i + 1), rc); 9232 goto bxe_interrupt_attach_exit; 9233 } 9234 9235 bus_describe_intr(sc->dev, sc->intr[i + 1].resource, 9236 sc->intr[i + 1].tag, "fp%02d", i); 9237 9238 /* bind the fastpath instance to a cpu */ 9239 if (sc->num_queues > 1) { 9240 bus_bind_intr(sc->dev, sc->intr[i + 1].resource, i); 9241 } 9242 9243 fp->state = BXE_FP_STATE_IRQ; 9244 } 9245 } else if (sc->interrupt_mode == INTR_MODE_MSI) { 9246 BLOGD(sc, DBG_LOAD, "Enabling MSI[0] vector\n"); 9247 9248 /* 9249 * Setup the interrupt handler. Note that we pass the 9250 * driver instance to the interrupt handler which 9251 * will handle both the slowpath and fastpath. 9252 */ 9253 if ((rc = bus_setup_intr(sc->dev, sc->intr[0].resource, 9254 (INTR_TYPE_NET | INTR_MPSAFE), 9255 NULL, bxe_intr_legacy, sc, 9256 &sc->intr[0].tag)) != 0) { 9257 BLOGE(sc, "Failed to allocate MSI[0] vector (%d)\n", rc); 9258 goto bxe_interrupt_attach_exit; 9259 } 9260 9261 } else { /* (sc->interrupt_mode == INTR_MODE_INTX) */ 9262 BLOGD(sc, DBG_LOAD, "Enabling INTx interrupts\n"); 9263 9264 /* 9265 * Setup the interrupt handler. Note that we pass the 9266 * driver instance to the interrupt handler which 9267 * will handle both the slowpath and fastpath. 9268 */ 9269 if ((rc = bus_setup_intr(sc->dev, sc->intr[0].resource, 9270 (INTR_TYPE_NET | INTR_MPSAFE), 9271 NULL, bxe_intr_legacy, sc, 9272 &sc->intr[0].tag)) != 0) { 9273 BLOGE(sc, "Failed to allocate INTx interrupt (%d)\n", rc); 9274 goto bxe_interrupt_attach_exit; 9275 } 9276 } 9277 9278 bxe_interrupt_attach_exit: 9279 9280 return (rc); 9281 } 9282 9283 static int bxe_init_hw_common_chip(struct bxe_softc *sc); 9284 static int bxe_init_hw_common(struct bxe_softc *sc); 9285 static int bxe_init_hw_port(struct bxe_softc *sc); 9286 static int bxe_init_hw_func(struct bxe_softc *sc); 9287 static void bxe_reset_common(struct bxe_softc *sc); 9288 static void bxe_reset_port(struct bxe_softc *sc); 9289 static void bxe_reset_func(struct bxe_softc *sc); 9290 static int bxe_gunzip_init(struct bxe_softc *sc); 9291 static void bxe_gunzip_end(struct bxe_softc *sc); 9292 static int bxe_init_firmware(struct bxe_softc *sc); 9293 static void bxe_release_firmware(struct bxe_softc *sc); 9294 9295 static struct 9296 ecore_func_sp_drv_ops bxe_func_sp_drv = { 9297 .init_hw_cmn_chip = bxe_init_hw_common_chip, 9298 .init_hw_cmn = bxe_init_hw_common, 9299 .init_hw_port = bxe_init_hw_port, 9300 .init_hw_func = bxe_init_hw_func, 9301 9302 .reset_hw_cmn = bxe_reset_common, 9303 .reset_hw_port = bxe_reset_port, 9304 .reset_hw_func = bxe_reset_func, 9305 9306 .gunzip_init = bxe_gunzip_init, 9307 .gunzip_end = bxe_gunzip_end, 9308 9309 .init_fw = bxe_init_firmware, 9310 .release_fw = bxe_release_firmware, 9311 }; 9312 9313 static void 9314 bxe_init_func_obj(struct bxe_softc *sc) 9315 { 9316 sc->dmae_ready = 0; 9317 9318 ecore_init_func_obj(sc, 9319 &sc->func_obj, 9320 BXE_SP(sc, func_rdata), 9321 BXE_SP_MAPPING(sc, func_rdata), 9322 BXE_SP(sc, func_afex_rdata), 9323 BXE_SP_MAPPING(sc, func_afex_rdata), 9324 &bxe_func_sp_drv); 9325 } 9326 9327 static int 9328 bxe_init_hw(struct bxe_softc *sc, 9329 uint32_t load_code) 9330 { 9331 struct ecore_func_state_params func_params = { NULL }; 9332 int rc; 9333 9334 /* prepare the parameters for function state transitions */ 9335 bit_set(&func_params.ramrod_flags, RAMROD_COMP_WAIT); 9336 9337 func_params.f_obj = &sc->func_obj; 9338 func_params.cmd = ECORE_F_CMD_HW_INIT; 9339 9340 func_params.params.hw_init.load_phase = load_code; 9341 9342 /* 9343 * Via a plethora of function pointers, we will eventually reach 9344 * bxe_init_hw_common(), bxe_init_hw_port(), or bxe_init_hw_func(). 9345 */ 9346 rc = ecore_func_state_change(sc, &func_params); 9347 9348 return (rc); 9349 } 9350 9351 static void 9352 bxe_fill(struct bxe_softc *sc, 9353 uint32_t addr, 9354 int fill, 9355 uint32_t len) 9356 { 9357 uint32_t i; 9358 9359 if (!(len % 4) && !(addr % 4)) { 9360 for (i = 0; i < len; i += 4) { 9361 REG_WR(sc, (addr + i), fill); 9362 } 9363 } else { 9364 for (i = 0; i < len; i++) { 9365 REG_WR8(sc, (addr + i), fill); 9366 } 9367 } 9368 } 9369 9370 /* writes FP SP data to FW - data_size in dwords */ 9371 static void 9372 bxe_wr_fp_sb_data(struct bxe_softc *sc, 9373 int fw_sb_id, 9374 uint32_t *sb_data_p, 9375 uint32_t data_size) 9376 { 9377 int index; 9378 9379 for (index = 0; index < data_size; index++) { 9380 REG_WR(sc, 9381 (BAR_CSTRORM_INTMEM + 9382 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) + 9383 (sizeof(uint32_t) * index)), 9384 *(sb_data_p + index)); 9385 } 9386 } 9387 9388 static void 9389 bxe_zero_fp_sb(struct bxe_softc *sc, 9390 int fw_sb_id) 9391 { 9392 struct hc_status_block_data_e2 sb_data_e2; 9393 struct hc_status_block_data_e1x sb_data_e1x; 9394 uint32_t *sb_data_p; 9395 uint32_t data_size = 0; 9396 9397 if (!CHIP_IS_E1x(sc)) { 9398 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2)); 9399 sb_data_e2.common.state = SB_DISABLED; 9400 sb_data_e2.common.p_func.vf_valid = FALSE; 9401 sb_data_p = (uint32_t *)&sb_data_e2; 9402 data_size = (sizeof(struct hc_status_block_data_e2) / 9403 sizeof(uint32_t)); 9404 } else { 9405 memset(&sb_data_e1x, 0, sizeof(struct hc_status_block_data_e1x)); 9406 sb_data_e1x.common.state = SB_DISABLED; 9407 sb_data_e1x.common.p_func.vf_valid = FALSE; 9408 sb_data_p = (uint32_t *)&sb_data_e1x; 9409 data_size = (sizeof(struct hc_status_block_data_e1x) / 9410 sizeof(uint32_t)); 9411 } 9412 9413 bxe_wr_fp_sb_data(sc, fw_sb_id, sb_data_p, data_size); 9414 9415 bxe_fill(sc, (BAR_CSTRORM_INTMEM + CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id)), 9416 0, CSTORM_STATUS_BLOCK_SIZE); 9417 bxe_fill(sc, (BAR_CSTRORM_INTMEM + CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id)), 9418 0, CSTORM_SYNC_BLOCK_SIZE); 9419 } 9420 9421 static void 9422 bxe_wr_sp_sb_data(struct bxe_softc *sc, 9423 struct hc_sp_status_block_data *sp_sb_data) 9424 { 9425 int i; 9426 9427 for (i = 0; 9428 i < (sizeof(struct hc_sp_status_block_data) / sizeof(uint32_t)); 9429 i++) { 9430 REG_WR(sc, 9431 (BAR_CSTRORM_INTMEM + 9432 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(SC_FUNC(sc)) + 9433 (i * sizeof(uint32_t))), 9434 *((uint32_t *)sp_sb_data + i)); 9435 } 9436 } 9437 9438 static void 9439 bxe_zero_sp_sb(struct bxe_softc *sc) 9440 { 9441 struct hc_sp_status_block_data sp_sb_data; 9442 9443 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data)); 9444 9445 sp_sb_data.state = SB_DISABLED; 9446 sp_sb_data.p_func.vf_valid = FALSE; 9447 9448 bxe_wr_sp_sb_data(sc, &sp_sb_data); 9449 9450 bxe_fill(sc, 9451 (BAR_CSTRORM_INTMEM + 9452 CSTORM_SP_STATUS_BLOCK_OFFSET(SC_FUNC(sc))), 9453 0, CSTORM_SP_STATUS_BLOCK_SIZE); 9454 bxe_fill(sc, 9455 (BAR_CSTRORM_INTMEM + 9456 CSTORM_SP_SYNC_BLOCK_OFFSET(SC_FUNC(sc))), 9457 0, CSTORM_SP_SYNC_BLOCK_SIZE); 9458 } 9459 9460 static void 9461 bxe_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm, 9462 int igu_sb_id, 9463 int igu_seg_id) 9464 { 9465 hc_sm->igu_sb_id = igu_sb_id; 9466 hc_sm->igu_seg_id = igu_seg_id; 9467 hc_sm->timer_value = 0xFF; 9468 hc_sm->time_to_expire = 0xFFFFFFFF; 9469 } 9470 9471 static void 9472 bxe_map_sb_state_machines(struct hc_index_data *index_data) 9473 { 9474 /* zero out state machine indices */ 9475 9476 /* rx indices */ 9477 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID; 9478 9479 /* tx indices */ 9480 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID; 9481 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID; 9482 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID; 9483 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID; 9484 9485 /* map indices */ 9486 9487 /* rx indices */ 9488 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |= 9489 (SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT); 9490 9491 /* tx indices */ 9492 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |= 9493 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT); 9494 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |= 9495 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT); 9496 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |= 9497 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT); 9498 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |= 9499 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT); 9500 } 9501 9502 static void 9503 bxe_init_sb(struct bxe_softc *sc, 9504 bus_addr_t busaddr, 9505 int vfid, 9506 uint8_t vf_valid, 9507 int fw_sb_id, 9508 int igu_sb_id) 9509 { 9510 struct hc_status_block_data_e2 sb_data_e2; 9511 struct hc_status_block_data_e1x sb_data_e1x; 9512 struct hc_status_block_sm *hc_sm_p; 9513 uint32_t *sb_data_p; 9514 int igu_seg_id; 9515 int data_size; 9516 9517 if (CHIP_INT_MODE_IS_BC(sc)) { 9518 igu_seg_id = HC_SEG_ACCESS_NORM; 9519 } else { 9520 igu_seg_id = IGU_SEG_ACCESS_NORM; 9521 } 9522 9523 bxe_zero_fp_sb(sc, fw_sb_id); 9524 9525 if (!CHIP_IS_E1x(sc)) { 9526 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2)); 9527 sb_data_e2.common.state = SB_ENABLED; 9528 sb_data_e2.common.p_func.pf_id = SC_FUNC(sc); 9529 sb_data_e2.common.p_func.vf_id = vfid; 9530 sb_data_e2.common.p_func.vf_valid = vf_valid; 9531 sb_data_e2.common.p_func.vnic_id = SC_VN(sc); 9532 sb_data_e2.common.same_igu_sb_1b = TRUE; 9533 sb_data_e2.common.host_sb_addr.hi = U64_HI(busaddr); 9534 sb_data_e2.common.host_sb_addr.lo = U64_LO(busaddr); 9535 hc_sm_p = sb_data_e2.common.state_machine; 9536 sb_data_p = (uint32_t *)&sb_data_e2; 9537 data_size = (sizeof(struct hc_status_block_data_e2) / 9538 sizeof(uint32_t)); 9539 bxe_map_sb_state_machines(sb_data_e2.index_data); 9540 } else { 9541 memset(&sb_data_e1x, 0, sizeof(struct hc_status_block_data_e1x)); 9542 sb_data_e1x.common.state = SB_ENABLED; 9543 sb_data_e1x.common.p_func.pf_id = SC_FUNC(sc); 9544 sb_data_e1x.common.p_func.vf_id = 0xff; 9545 sb_data_e1x.common.p_func.vf_valid = FALSE; 9546 sb_data_e1x.common.p_func.vnic_id = SC_VN(sc); 9547 sb_data_e1x.common.same_igu_sb_1b = TRUE; 9548 sb_data_e1x.common.host_sb_addr.hi = U64_HI(busaddr); 9549 sb_data_e1x.common.host_sb_addr.lo = U64_LO(busaddr); 9550 hc_sm_p = sb_data_e1x.common.state_machine; 9551 sb_data_p = (uint32_t *)&sb_data_e1x; 9552 data_size = (sizeof(struct hc_status_block_data_e1x) / 9553 sizeof(uint32_t)); 9554 bxe_map_sb_state_machines(sb_data_e1x.index_data); 9555 } 9556 9557 bxe_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID], igu_sb_id, igu_seg_id); 9558 bxe_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID], igu_sb_id, igu_seg_id); 9559 9560 BLOGD(sc, DBG_LOAD, "Init FW SB %d\n", fw_sb_id); 9561 9562 /* write indices to HW - PCI guarantees endianity of regpairs */ 9563 bxe_wr_fp_sb_data(sc, fw_sb_id, sb_data_p, data_size); 9564 } 9565 9566 static inline uint8_t 9567 bxe_fp_qzone_id(struct bxe_fastpath *fp) 9568 { 9569 if (CHIP_IS_E1x(fp->sc)) { 9570 return (fp->cl_id + SC_PORT(fp->sc) * ETH_MAX_RX_CLIENTS_E1H); 9571 } else { 9572 return (fp->cl_id); 9573 } 9574 } 9575 9576 static inline uint32_t 9577 bxe_rx_ustorm_prods_offset(struct bxe_softc *sc, 9578 struct bxe_fastpath *fp) 9579 { 9580 uint32_t offset = BAR_USTRORM_INTMEM; 9581 9582 if (!CHIP_IS_E1x(sc)) { 9583 offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id); 9584 } else { 9585 offset += USTORM_RX_PRODS_E1X_OFFSET(SC_PORT(sc), fp->cl_id); 9586 } 9587 9588 return (offset); 9589 } 9590 9591 static void 9592 bxe_init_eth_fp(struct bxe_softc *sc, 9593 int idx) 9594 { 9595 struct bxe_fastpath *fp = &sc->fp[idx]; 9596 uint32_t cids[ECORE_MULTI_TX_COS] = { 0 }; 9597 unsigned long q_type = 0; 9598 int cos; 9599 9600 fp->sc = sc; 9601 fp->index = idx; 9602 9603 fp->igu_sb_id = (sc->igu_base_sb + idx + CNIC_SUPPORT(sc)); 9604 fp->fw_sb_id = (sc->base_fw_ndsb + idx + CNIC_SUPPORT(sc)); 9605 9606 fp->cl_id = (CHIP_IS_E1x(sc)) ? 9607 (SC_L_ID(sc) + idx) : 9608 /* want client ID same as IGU SB ID for non-E1 */ 9609 fp->igu_sb_id; 9610 fp->cl_qzone_id = bxe_fp_qzone_id(fp); 9611 9612 /* setup sb indices */ 9613 if (!CHIP_IS_E1x(sc)) { 9614 fp->sb_index_values = fp->status_block.e2_sb->sb.index_values; 9615 fp->sb_running_index = fp->status_block.e2_sb->sb.running_index; 9616 } else { 9617 fp->sb_index_values = fp->status_block.e1x_sb->sb.index_values; 9618 fp->sb_running_index = fp->status_block.e1x_sb->sb.running_index; 9619 } 9620 9621 /* init shortcut */ 9622 fp->ustorm_rx_prods_offset = bxe_rx_ustorm_prods_offset(sc, fp); 9623 9624 fp->rx_cq_cons_sb = &fp->sb_index_values[HC_INDEX_ETH_RX_CQ_CONS]; 9625 9626 /* 9627 * XXX If multiple CoS is ever supported then each fastpath structure 9628 * will need to maintain tx producer/consumer/dma/etc values *per* CoS. 9629 */ 9630 for (cos = 0; cos < sc->max_cos; cos++) { 9631 cids[cos] = idx; 9632 } 9633 fp->tx_cons_sb = &fp->sb_index_values[HC_INDEX_ETH_TX_CQ_CONS_COS0]; 9634 9635 /* nothing more for a VF to do */ 9636 if (IS_VF(sc)) { 9637 return; 9638 } 9639 9640 bxe_init_sb(sc, fp->sb_dma.paddr, BXE_VF_ID_INVALID, FALSE, 9641 fp->fw_sb_id, fp->igu_sb_id); 9642 9643 bxe_update_fp_sb_idx(fp); 9644 9645 /* Configure Queue State object */ 9646 bit_set(&q_type, ECORE_Q_TYPE_HAS_RX); 9647 bit_set(&q_type, ECORE_Q_TYPE_HAS_TX); 9648 9649 ecore_init_queue_obj(sc, 9650 &sc->sp_objs[idx].q_obj, 9651 fp->cl_id, 9652 cids, 9653 sc->max_cos, 9654 SC_FUNC(sc), 9655 BXE_SP(sc, q_rdata), 9656 BXE_SP_MAPPING(sc, q_rdata), 9657 q_type); 9658 9659 /* configure classification DBs */ 9660 ecore_init_mac_obj(sc, 9661 &sc->sp_objs[idx].mac_obj, 9662 fp->cl_id, 9663 idx, 9664 SC_FUNC(sc), 9665 BXE_SP(sc, mac_rdata), 9666 BXE_SP_MAPPING(sc, mac_rdata), 9667 ECORE_FILTER_MAC_PENDING, 9668 &sc->sp_state, 9669 ECORE_OBJ_TYPE_RX_TX, 9670 &sc->macs_pool); 9671 9672 BLOGD(sc, DBG_LOAD, "fp[%d]: sb=%p cl_id=%d fw_sb=%d igu_sb=%d\n", 9673 idx, fp->status_block.e2_sb, fp->cl_id, fp->fw_sb_id, fp->igu_sb_id); 9674 } 9675 9676 static inline void 9677 bxe_update_rx_prod(struct bxe_softc *sc, 9678 struct bxe_fastpath *fp, 9679 uint16_t rx_bd_prod, 9680 uint16_t rx_cq_prod, 9681 uint16_t rx_sge_prod) 9682 { 9683 struct ustorm_eth_rx_producers rx_prods = { 0 }; 9684 uint32_t i; 9685 9686 /* update producers */ 9687 rx_prods.bd_prod = rx_bd_prod; 9688 rx_prods.cqe_prod = rx_cq_prod; 9689 rx_prods.sge_prod = rx_sge_prod; 9690 9691 /* 9692 * Make sure that the BD and SGE data is updated before updating the 9693 * producers since FW might read the BD/SGE right after the producer 9694 * is updated. 9695 * This is only applicable for weak-ordered memory model archs such 9696 * as IA-64. The following barrier is also mandatory since FW will 9697 * assumes BDs must have buffers. 9698 */ 9699 wmb(); 9700 9701 for (i = 0; i < (sizeof(rx_prods) / 4); i++) { 9702 REG_WR(sc, 9703 (fp->ustorm_rx_prods_offset + (i * 4)), 9704 ((uint32_t *)&rx_prods)[i]); 9705 } 9706 9707 wmb(); /* keep prod updates ordered */ 9708 9709 BLOGD(sc, DBG_RX, 9710 "RX fp[%d]: wrote prods bd_prod=%u cqe_prod=%u sge_prod=%u\n", 9711 fp->index, rx_bd_prod, rx_cq_prod, rx_sge_prod); 9712 } 9713 9714 static void 9715 bxe_init_rx_rings(struct bxe_softc *sc) 9716 { 9717 struct bxe_fastpath *fp; 9718 int i; 9719 9720 for (i = 0; i < sc->num_queues; i++) { 9721 fp = &sc->fp[i]; 9722 9723 fp->rx_bd_cons = 0; 9724 9725 /* 9726 * Activate the BD ring... 9727 * Warning, this will generate an interrupt (to the TSTORM) 9728 * so this can only be done after the chip is initialized 9729 */ 9730 bxe_update_rx_prod(sc, fp, 9731 fp->rx_bd_prod, 9732 fp->rx_cq_prod, 9733 fp->rx_sge_prod); 9734 9735 if (i != 0) { 9736 continue; 9737 } 9738 9739 if (CHIP_IS_E1(sc)) { 9740 REG_WR(sc, 9741 (BAR_USTRORM_INTMEM + 9742 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(SC_FUNC(sc))), 9743 U64_LO(fp->rcq_dma.paddr)); 9744 REG_WR(sc, 9745 (BAR_USTRORM_INTMEM + 9746 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(SC_FUNC(sc)) + 4), 9747 U64_HI(fp->rcq_dma.paddr)); 9748 } 9749 } 9750 } 9751 9752 static void 9753 bxe_init_tx_ring_one(struct bxe_fastpath *fp) 9754 { 9755 SET_FLAG(fp->tx_db.data.header.data, DOORBELL_HDR_T_DB_TYPE, 1); 9756 fp->tx_db.data.zero_fill1 = 0; 9757 fp->tx_db.data.prod = 0; 9758 9759 fp->tx_pkt_prod = 0; 9760 fp->tx_pkt_cons = 0; 9761 fp->tx_bd_prod = 0; 9762 fp->tx_bd_cons = 0; 9763 fp->eth_q_stats.tx_pkts = 0; 9764 } 9765 9766 static inline void 9767 bxe_init_tx_rings(struct bxe_softc *sc) 9768 { 9769 int i; 9770 9771 for (i = 0; i < sc->num_queues; i++) { 9772 bxe_init_tx_ring_one(&sc->fp[i]); 9773 } 9774 } 9775 9776 static void 9777 bxe_init_def_sb(struct bxe_softc *sc) 9778 { 9779 struct host_sp_status_block *def_sb = sc->def_sb; 9780 bus_addr_t mapping = sc->def_sb_dma.paddr; 9781 int igu_sp_sb_index; 9782 int igu_seg_id; 9783 int port = SC_PORT(sc); 9784 int func = SC_FUNC(sc); 9785 int reg_offset, reg_offset_en5; 9786 uint64_t section; 9787 int index, sindex; 9788 struct hc_sp_status_block_data sp_sb_data; 9789 9790 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data)); 9791 9792 if (CHIP_INT_MODE_IS_BC(sc)) { 9793 igu_sp_sb_index = DEF_SB_IGU_ID; 9794 igu_seg_id = HC_SEG_ACCESS_DEF; 9795 } else { 9796 igu_sp_sb_index = sc->igu_dsb_id; 9797 igu_seg_id = IGU_SEG_ACCESS_DEF; 9798 } 9799 9800 /* attentions */ 9801 section = ((uint64_t)mapping + 9802 offsetof(struct host_sp_status_block, atten_status_block)); 9803 def_sb->atten_status_block.status_block_id = igu_sp_sb_index; 9804 sc->attn_state = 0; 9805 9806 reg_offset = (port) ? 9807 MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : 9808 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0; 9809 reg_offset_en5 = (port) ? 9810 MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 : 9811 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0; 9812 9813 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) { 9814 /* take care of sig[0]..sig[4] */ 9815 for (sindex = 0; sindex < 4; sindex++) { 9816 sc->attn_group[index].sig[sindex] = 9817 REG_RD(sc, (reg_offset + (sindex * 0x4) + (0x10 * index))); 9818 } 9819 9820 if (!CHIP_IS_E1x(sc)) { 9821 /* 9822 * enable5 is separate from the rest of the registers, 9823 * and the address skip is 4 and not 16 between the 9824 * different groups 9825 */ 9826 sc->attn_group[index].sig[4] = 9827 REG_RD(sc, (reg_offset_en5 + (0x4 * index))); 9828 } else { 9829 sc->attn_group[index].sig[4] = 0; 9830 } 9831 } 9832 9833 if (sc->devinfo.int_block == INT_BLOCK_HC) { 9834 reg_offset = (port) ? 9835 HC_REG_ATTN_MSG1_ADDR_L : 9836 HC_REG_ATTN_MSG0_ADDR_L; 9837 REG_WR(sc, reg_offset, U64_LO(section)); 9838 REG_WR(sc, (reg_offset + 4), U64_HI(section)); 9839 } else if (!CHIP_IS_E1x(sc)) { 9840 REG_WR(sc, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section)); 9841 REG_WR(sc, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section)); 9842 } 9843 9844 section = ((uint64_t)mapping + 9845 offsetof(struct host_sp_status_block, sp_sb)); 9846 9847 bxe_zero_sp_sb(sc); 9848 9849 /* PCI guarantees endianity of regpair */ 9850 sp_sb_data.state = SB_ENABLED; 9851 sp_sb_data.host_sb_addr.lo = U64_LO(section); 9852 sp_sb_data.host_sb_addr.hi = U64_HI(section); 9853 sp_sb_data.igu_sb_id = igu_sp_sb_index; 9854 sp_sb_data.igu_seg_id = igu_seg_id; 9855 sp_sb_data.p_func.pf_id = func; 9856 sp_sb_data.p_func.vnic_id = SC_VN(sc); 9857 sp_sb_data.p_func.vf_id = 0xff; 9858 9859 bxe_wr_sp_sb_data(sc, &sp_sb_data); 9860 9861 bxe_ack_sb(sc, sc->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0); 9862 } 9863 9864 static void 9865 bxe_init_sp_ring(struct bxe_softc *sc) 9866 { 9867 atomic_store_rel_long(&sc->cq_spq_left, MAX_SPQ_PENDING); 9868 sc->spq_prod_idx = 0; 9869 sc->dsb_sp_prod = &sc->def_sb->sp_sb.index_values[HC_SP_INDEX_ETH_DEF_CONS]; 9870 sc->spq_prod_bd = sc->spq; 9871 sc->spq_last_bd = (sc->spq_prod_bd + MAX_SP_DESC_CNT); 9872 } 9873 9874 static void 9875 bxe_init_eq_ring(struct bxe_softc *sc) 9876 { 9877 union event_ring_elem *elem; 9878 int i; 9879 9880 for (i = 1; i <= NUM_EQ_PAGES; i++) { 9881 elem = &sc->eq[EQ_DESC_CNT_PAGE * i - 1]; 9882 9883 elem->next_page.addr.hi = htole32(U64_HI(sc->eq_dma.paddr + 9884 BCM_PAGE_SIZE * 9885 (i % NUM_EQ_PAGES))); 9886 elem->next_page.addr.lo = htole32(U64_LO(sc->eq_dma.paddr + 9887 BCM_PAGE_SIZE * 9888 (i % NUM_EQ_PAGES))); 9889 } 9890 9891 sc->eq_cons = 0; 9892 sc->eq_prod = NUM_EQ_DESC; 9893 sc->eq_cons_sb = &sc->def_sb->sp_sb.index_values[HC_SP_INDEX_EQ_CONS]; 9894 9895 atomic_store_rel_long(&sc->eq_spq_left, 9896 (min((MAX_SP_DESC_CNT - MAX_SPQ_PENDING), 9897 NUM_EQ_DESC) - 1)); 9898 } 9899 9900 static void 9901 bxe_init_internal_common(struct bxe_softc *sc) 9902 { 9903 int i; 9904 9905 /* 9906 * Zero this manually as its initialization is currently missing 9907 * in the initTool. 9908 */ 9909 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++) { 9910 REG_WR(sc, 9911 (BAR_USTRORM_INTMEM + USTORM_AGG_DATA_OFFSET + (i * 4)), 9912 0); 9913 } 9914 9915 if (!CHIP_IS_E1x(sc)) { 9916 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET), 9917 CHIP_INT_MODE_IS_BC(sc) ? HC_IGU_BC_MODE : HC_IGU_NBC_MODE); 9918 } 9919 } 9920 9921 static void 9922 bxe_init_internal(struct bxe_softc *sc, 9923 uint32_t load_code) 9924 { 9925 switch (load_code) { 9926 case FW_MSG_CODE_DRV_LOAD_COMMON: 9927 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: 9928 bxe_init_internal_common(sc); 9929 /* no break */ 9930 9931 case FW_MSG_CODE_DRV_LOAD_PORT: 9932 /* nothing to do */ 9933 /* no break */ 9934 9935 case FW_MSG_CODE_DRV_LOAD_FUNCTION: 9936 /* internal memory per function is initialized inside bxe_pf_init */ 9937 break; 9938 9939 default: 9940 BLOGE(sc, "Unknown load_code (0x%x) from MCP\n", load_code); 9941 break; 9942 } 9943 } 9944 9945 static void 9946 storm_memset_func_cfg(struct bxe_softc *sc, 9947 struct tstorm_eth_function_common_config *tcfg, 9948 uint16_t abs_fid) 9949 { 9950 uint32_t addr; 9951 size_t size; 9952 9953 addr = (BAR_TSTRORM_INTMEM + 9954 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid)); 9955 size = sizeof(struct tstorm_eth_function_common_config); 9956 ecore_storm_memset_struct(sc, addr, size, (uint32_t *)tcfg); 9957 } 9958 9959 static void 9960 bxe_func_init(struct bxe_softc *sc, 9961 struct bxe_func_init_params *p) 9962 { 9963 struct tstorm_eth_function_common_config tcfg = { 0 }; 9964 9965 if (CHIP_IS_E1x(sc)) { 9966 storm_memset_func_cfg(sc, &tcfg, p->func_id); 9967 } 9968 9969 /* Enable the function in the FW */ 9970 storm_memset_vf_to_pf(sc, p->func_id, p->pf_id); 9971 storm_memset_func_en(sc, p->func_id, 1); 9972 9973 /* spq */ 9974 if (p->func_flgs & FUNC_FLG_SPQ) { 9975 storm_memset_spq_addr(sc, p->spq_map, p->func_id); 9976 REG_WR(sc, 9977 (XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PROD_OFFSET(p->func_id)), 9978 p->spq_prod); 9979 } 9980 } 9981 9982 /* 9983 * Calculates the sum of vn_min_rates. 9984 * It's needed for further normalizing of the min_rates. 9985 * Returns: 9986 * sum of vn_min_rates. 9987 * or 9988 * 0 - if all the min_rates are 0. 9989 * In the later case fainess algorithm should be deactivated. 9990 * If all min rates are not zero then those that are zeroes will be set to 1. 9991 */ 9992 static void 9993 bxe_calc_vn_min(struct bxe_softc *sc, 9994 struct cmng_init_input *input) 9995 { 9996 uint32_t vn_cfg; 9997 uint32_t vn_min_rate; 9998 int all_zero = 1; 9999 int vn; 10000 10001 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) { 10002 vn_cfg = sc->devinfo.mf_info.mf_config[vn]; 10003 vn_min_rate = (((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >> 10004 FUNC_MF_CFG_MIN_BW_SHIFT) * 100); 10005 10006 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) { 10007 /* skip hidden VNs */ 10008 vn_min_rate = 0; 10009 } else if (!vn_min_rate) { 10010 /* If min rate is zero - set it to 100 */ 10011 vn_min_rate = DEF_MIN_RATE; 10012 } else { 10013 all_zero = 0; 10014 } 10015 10016 input->vnic_min_rate[vn] = vn_min_rate; 10017 } 10018 10019 /* if ETS or all min rates are zeros - disable fairness */ 10020 if (BXE_IS_ETS_ENABLED(sc)) { 10021 input->flags.cmng_enables &= ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN; 10022 BLOGD(sc, DBG_LOAD, "Fairness disabled (ETS)\n"); 10023 } else if (all_zero) { 10024 input->flags.cmng_enables &= ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN; 10025 BLOGD(sc, DBG_LOAD, 10026 "Fariness disabled (all MIN values are zeroes)\n"); 10027 } else { 10028 input->flags.cmng_enables |= CMNG_FLAGS_PER_PORT_FAIRNESS_VN; 10029 } 10030 } 10031 10032 static inline uint16_t 10033 bxe_extract_max_cfg(struct bxe_softc *sc, 10034 uint32_t mf_cfg) 10035 { 10036 uint16_t max_cfg = ((mf_cfg & FUNC_MF_CFG_MAX_BW_MASK) >> 10037 FUNC_MF_CFG_MAX_BW_SHIFT); 10038 10039 if (!max_cfg) { 10040 BLOGD(sc, DBG_LOAD, "Max BW configured to 0 - using 100 instead\n"); 10041 max_cfg = 100; 10042 } 10043 10044 return (max_cfg); 10045 } 10046 10047 static void 10048 bxe_calc_vn_max(struct bxe_softc *sc, 10049 int vn, 10050 struct cmng_init_input *input) 10051 { 10052 uint16_t vn_max_rate; 10053 uint32_t vn_cfg = sc->devinfo.mf_info.mf_config[vn]; 10054 uint32_t max_cfg; 10055 10056 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) { 10057 vn_max_rate = 0; 10058 } else { 10059 max_cfg = bxe_extract_max_cfg(sc, vn_cfg); 10060 10061 if (IS_MF_SI(sc)) { 10062 /* max_cfg in percents of linkspeed */ 10063 vn_max_rate = ((sc->link_vars.line_speed * max_cfg) / 100); 10064 } else { /* SD modes */ 10065 /* max_cfg is absolute in 100Mb units */ 10066 vn_max_rate = (max_cfg * 100); 10067 } 10068 } 10069 10070 BLOGD(sc, DBG_LOAD, "vn %d: vn_max_rate %d\n", vn, vn_max_rate); 10071 10072 input->vnic_max_rate[vn] = vn_max_rate; 10073 } 10074 10075 static void 10076 bxe_cmng_fns_init(struct bxe_softc *sc, 10077 uint8_t read_cfg, 10078 uint8_t cmng_type) 10079 { 10080 struct cmng_init_input input; 10081 int vn; 10082 10083 memset(&input, 0, sizeof(struct cmng_init_input)); 10084 10085 input.port_rate = sc->link_vars.line_speed; 10086 10087 if (cmng_type == CMNG_FNS_MINMAX) { 10088 /* read mf conf from shmem */ 10089 if (read_cfg) { 10090 bxe_read_mf_cfg(sc); 10091 } 10092 10093 /* get VN min rate and enable fairness if not 0 */ 10094 bxe_calc_vn_min(sc, &input); 10095 10096 /* get VN max rate */ 10097 if (sc->port.pmf) { 10098 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) { 10099 bxe_calc_vn_max(sc, vn, &input); 10100 } 10101 } 10102 10103 /* always enable rate shaping and fairness */ 10104 input.flags.cmng_enables |= CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN; 10105 10106 ecore_init_cmng(&input, &sc->cmng); 10107 return; 10108 } 10109 10110 /* rate shaping and fairness are disabled */ 10111 BLOGD(sc, DBG_LOAD, "rate shaping and fairness have been disabled\n"); 10112 } 10113 10114 static int 10115 bxe_get_cmng_fns_mode(struct bxe_softc *sc) 10116 { 10117 if (CHIP_REV_IS_SLOW(sc)) { 10118 return (CMNG_FNS_NONE); 10119 } 10120 10121 if (IS_MF(sc)) { 10122 return (CMNG_FNS_MINMAX); 10123 } 10124 10125 return (CMNG_FNS_NONE); 10126 } 10127 10128 static void 10129 storm_memset_cmng(struct bxe_softc *sc, 10130 struct cmng_init *cmng, 10131 uint8_t port) 10132 { 10133 int vn; 10134 int func; 10135 uint32_t addr; 10136 size_t size; 10137 10138 addr = (BAR_XSTRORM_INTMEM + 10139 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port)); 10140 size = sizeof(struct cmng_struct_per_port); 10141 ecore_storm_memset_struct(sc, addr, size, (uint32_t *)&cmng->port); 10142 10143 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) { 10144 func = func_by_vn(sc, vn); 10145 10146 addr = (BAR_XSTRORM_INTMEM + 10147 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func)); 10148 size = sizeof(struct rate_shaping_vars_per_vn); 10149 ecore_storm_memset_struct(sc, addr, size, 10150 (uint32_t *)&cmng->vnic.vnic_max_rate[vn]); 10151 10152 addr = (BAR_XSTRORM_INTMEM + 10153 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func)); 10154 size = sizeof(struct fairness_vars_per_vn); 10155 ecore_storm_memset_struct(sc, addr, size, 10156 (uint32_t *)&cmng->vnic.vnic_min_rate[vn]); 10157 } 10158 } 10159 10160 static void 10161 bxe_pf_init(struct bxe_softc *sc) 10162 { 10163 struct bxe_func_init_params func_init = { 0 }; 10164 struct event_ring_data eq_data = { { 0 } }; 10165 uint16_t flags; 10166 10167 if (!CHIP_IS_E1x(sc)) { 10168 /* reset IGU PF statistics: MSIX + ATTN */ 10169 /* PF */ 10170 REG_WR(sc, 10171 (IGU_REG_STATISTIC_NUM_MESSAGE_SENT + 10172 (BXE_IGU_STAS_MSG_VF_CNT * 4) + 10173 ((CHIP_IS_MODE_4_PORT(sc) ? SC_FUNC(sc) : SC_VN(sc)) * 4)), 10174 0); 10175 /* ATTN */ 10176 REG_WR(sc, 10177 (IGU_REG_STATISTIC_NUM_MESSAGE_SENT + 10178 (BXE_IGU_STAS_MSG_VF_CNT * 4) + 10179 (BXE_IGU_STAS_MSG_PF_CNT * 4) + 10180 ((CHIP_IS_MODE_4_PORT(sc) ? SC_FUNC(sc) : SC_VN(sc)) * 4)), 10181 0); 10182 } 10183 10184 /* function setup flags */ 10185 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ); 10186 10187 /* 10188 * This flag is relevant for E1x only. 10189 * E2 doesn't have a TPA configuration in a function level. 10190 */ 10191 flags |= (if_getcapenable(sc->ifp) & IFCAP_LRO) ? FUNC_FLG_TPA : 0; 10192 10193 func_init.func_flgs = flags; 10194 func_init.pf_id = SC_FUNC(sc); 10195 func_init.func_id = SC_FUNC(sc); 10196 func_init.spq_map = sc->spq_dma.paddr; 10197 func_init.spq_prod = sc->spq_prod_idx; 10198 10199 bxe_func_init(sc, &func_init); 10200 10201 memset(&sc->cmng, 0, sizeof(struct cmng_struct_per_port)); 10202 10203 /* 10204 * Congestion management values depend on the link rate. 10205 * There is no active link so initial link rate is set to 10Gbps. 10206 * When the link comes up the congestion management values are 10207 * re-calculated according to the actual link rate. 10208 */ 10209 sc->link_vars.line_speed = SPEED_10000; 10210 bxe_cmng_fns_init(sc, TRUE, bxe_get_cmng_fns_mode(sc)); 10211 10212 /* Only the PMF sets the HW */ 10213 if (sc->port.pmf) { 10214 storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc)); 10215 } 10216 10217 /* init Event Queue - PCI bus guarantees correct endainity */ 10218 eq_data.base_addr.hi = U64_HI(sc->eq_dma.paddr); 10219 eq_data.base_addr.lo = U64_LO(sc->eq_dma.paddr); 10220 eq_data.producer = sc->eq_prod; 10221 eq_data.index_id = HC_SP_INDEX_EQ_CONS; 10222 eq_data.sb_id = DEF_SB_ID; 10223 storm_memset_eq_data(sc, &eq_data, SC_FUNC(sc)); 10224 } 10225 10226 static void 10227 bxe_hc_int_enable(struct bxe_softc *sc) 10228 { 10229 int port = SC_PORT(sc); 10230 uint32_t addr = (port) ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0; 10231 uint32_t val = REG_RD(sc, addr); 10232 uint8_t msix = (sc->interrupt_mode == INTR_MODE_MSIX) ? TRUE : FALSE; 10233 uint8_t single_msix = ((sc->interrupt_mode == INTR_MODE_MSIX) && 10234 (sc->intr_count == 1)) ? TRUE : FALSE; 10235 uint8_t msi = (sc->interrupt_mode == INTR_MODE_MSI) ? TRUE : FALSE; 10236 10237 if (msix) { 10238 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | 10239 HC_CONFIG_0_REG_INT_LINE_EN_0); 10240 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | 10241 HC_CONFIG_0_REG_ATTN_BIT_EN_0); 10242 if (single_msix) { 10243 val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0; 10244 } 10245 } else if (msi) { 10246 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0; 10247 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | 10248 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | 10249 HC_CONFIG_0_REG_ATTN_BIT_EN_0); 10250 } else { 10251 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | 10252 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | 10253 HC_CONFIG_0_REG_INT_LINE_EN_0 | 10254 HC_CONFIG_0_REG_ATTN_BIT_EN_0); 10255 10256 if (!CHIP_IS_E1(sc)) { 10257 BLOGD(sc, DBG_INTR, "write %x to HC %d (addr 0x%x)\n", 10258 val, port, addr); 10259 10260 REG_WR(sc, addr, val); 10261 10262 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0; 10263 } 10264 } 10265 10266 if (CHIP_IS_E1(sc)) { 10267 REG_WR(sc, (HC_REG_INT_MASK + port*4), 0x1FFFF); 10268 } 10269 10270 BLOGD(sc, DBG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n", 10271 val, port, addr, ((msix) ? "MSI-X" : ((msi) ? "MSI" : "INTx"))); 10272 10273 REG_WR(sc, addr, val); 10274 10275 /* ensure that HC_CONFIG is written before leading/trailing edge config */ 10276 mb(); 10277 10278 if (!CHIP_IS_E1(sc)) { 10279 /* init leading/trailing edge */ 10280 if (IS_MF(sc)) { 10281 val = (0xee0f | (1 << (SC_VN(sc) + 4))); 10282 if (sc->port.pmf) { 10283 /* enable nig and gpio3 attention */ 10284 val |= 0x1100; 10285 } 10286 } else { 10287 val = 0xffff; 10288 } 10289 10290 REG_WR(sc, (HC_REG_TRAILING_EDGE_0 + port*8), val); 10291 REG_WR(sc, (HC_REG_LEADING_EDGE_0 + port*8), val); 10292 } 10293 10294 /* make sure that interrupts are indeed enabled from here on */ 10295 mb(); 10296 } 10297 10298 static void 10299 bxe_igu_int_enable(struct bxe_softc *sc) 10300 { 10301 uint32_t val; 10302 uint8_t msix = (sc->interrupt_mode == INTR_MODE_MSIX) ? TRUE : FALSE; 10303 uint8_t single_msix = ((sc->interrupt_mode == INTR_MODE_MSIX) && 10304 (sc->intr_count == 1)) ? TRUE : FALSE; 10305 uint8_t msi = (sc->interrupt_mode == INTR_MODE_MSI) ? TRUE : FALSE; 10306 10307 val = REG_RD(sc, IGU_REG_PF_CONFIGURATION); 10308 10309 if (msix) { 10310 val &= ~(IGU_PF_CONF_INT_LINE_EN | 10311 IGU_PF_CONF_SINGLE_ISR_EN); 10312 val |= (IGU_PF_CONF_MSI_MSIX_EN | 10313 IGU_PF_CONF_ATTN_BIT_EN); 10314 if (single_msix) { 10315 val |= IGU_PF_CONF_SINGLE_ISR_EN; 10316 } 10317 } else if (msi) { 10318 val &= ~IGU_PF_CONF_INT_LINE_EN; 10319 val |= (IGU_PF_CONF_MSI_MSIX_EN | 10320 IGU_PF_CONF_ATTN_BIT_EN | 10321 IGU_PF_CONF_SINGLE_ISR_EN); 10322 } else { 10323 val &= ~IGU_PF_CONF_MSI_MSIX_EN; 10324 val |= (IGU_PF_CONF_INT_LINE_EN | 10325 IGU_PF_CONF_ATTN_BIT_EN | 10326 IGU_PF_CONF_SINGLE_ISR_EN); 10327 } 10328 10329 /* clean previous status - need to configure igu prior to ack*/ 10330 if ((!msix) || single_msix) { 10331 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val); 10332 bxe_ack_int(sc); 10333 } 10334 10335 val |= IGU_PF_CONF_FUNC_EN; 10336 10337 BLOGD(sc, DBG_INTR, "write 0x%x to IGU mode %s\n", 10338 val, ((msix) ? "MSI-X" : ((msi) ? "MSI" : "INTx"))); 10339 10340 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val); 10341 10342 mb(); 10343 10344 /* init leading/trailing edge */ 10345 if (IS_MF(sc)) { 10346 val = (0xee0f | (1 << (SC_VN(sc) + 4))); 10347 if (sc->port.pmf) { 10348 /* enable nig and gpio3 attention */ 10349 val |= 0x1100; 10350 } 10351 } else { 10352 val = 0xffff; 10353 } 10354 10355 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, val); 10356 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, val); 10357 10358 /* make sure that interrupts are indeed enabled from here on */ 10359 mb(); 10360 } 10361 10362 static void 10363 bxe_int_enable(struct bxe_softc *sc) 10364 { 10365 if (sc->devinfo.int_block == INT_BLOCK_HC) { 10366 bxe_hc_int_enable(sc); 10367 } else { 10368 bxe_igu_int_enable(sc); 10369 } 10370 } 10371 10372 static void 10373 bxe_hc_int_disable(struct bxe_softc *sc) 10374 { 10375 int port = SC_PORT(sc); 10376 uint32_t addr = (port) ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0; 10377 uint32_t val = REG_RD(sc, addr); 10378 10379 /* 10380 * In E1 we must use only PCI configuration space to disable MSI/MSIX 10381 * capablility. It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC 10382 * block 10383 */ 10384 if (CHIP_IS_E1(sc)) { 10385 /* 10386 * Since IGU_PF_CONF_MSI_MSIX_EN still always on use mask register 10387 * to prevent from HC sending interrupts after we exit the function 10388 */ 10389 REG_WR(sc, (HC_REG_INT_MASK + port*4), 0); 10390 10391 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | 10392 HC_CONFIG_0_REG_INT_LINE_EN_0 | 10393 HC_CONFIG_0_REG_ATTN_BIT_EN_0); 10394 } else { 10395 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | 10396 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | 10397 HC_CONFIG_0_REG_INT_LINE_EN_0 | 10398 HC_CONFIG_0_REG_ATTN_BIT_EN_0); 10399 } 10400 10401 BLOGD(sc, DBG_INTR, "write %x to HC %d (addr 0x%x)\n", val, port, addr); 10402 10403 /* flush all outstanding writes */ 10404 mb(); 10405 10406 REG_WR(sc, addr, val); 10407 if (REG_RD(sc, addr) != val) { 10408 BLOGE(sc, "proper val not read from HC IGU!\n"); 10409 } 10410 } 10411 10412 static void 10413 bxe_igu_int_disable(struct bxe_softc *sc) 10414 { 10415 uint32_t val = REG_RD(sc, IGU_REG_PF_CONFIGURATION); 10416 10417 val &= ~(IGU_PF_CONF_MSI_MSIX_EN | 10418 IGU_PF_CONF_INT_LINE_EN | 10419 IGU_PF_CONF_ATTN_BIT_EN); 10420 10421 BLOGD(sc, DBG_INTR, "write %x to IGU\n", val); 10422 10423 /* flush all outstanding writes */ 10424 mb(); 10425 10426 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val); 10427 if (REG_RD(sc, IGU_REG_PF_CONFIGURATION) != val) { 10428 BLOGE(sc, "proper val not read from IGU!\n"); 10429 } 10430 } 10431 10432 static void 10433 bxe_int_disable(struct bxe_softc *sc) 10434 { 10435 if (sc->devinfo.int_block == INT_BLOCK_HC) { 10436 bxe_hc_int_disable(sc); 10437 } else { 10438 bxe_igu_int_disable(sc); 10439 } 10440 } 10441 10442 static void 10443 bxe_nic_init(struct bxe_softc *sc, 10444 int load_code) 10445 { 10446 int i; 10447 10448 for (i = 0; i < sc->num_queues; i++) { 10449 bxe_init_eth_fp(sc, i); 10450 } 10451 10452 rmb(); /* ensure status block indices were read */ 10453 10454 bxe_init_rx_rings(sc); 10455 bxe_init_tx_rings(sc); 10456 10457 if (IS_VF(sc)) { 10458 return; 10459 } 10460 10461 /* initialize MOD_ABS interrupts */ 10462 elink_init_mod_abs_int(sc, &sc->link_vars, 10463 sc->devinfo.chip_id, 10464 sc->devinfo.shmem_base, 10465 sc->devinfo.shmem2_base, 10466 SC_PORT(sc)); 10467 10468 bxe_init_def_sb(sc); 10469 bxe_update_dsb_idx(sc); 10470 bxe_init_sp_ring(sc); 10471 bxe_init_eq_ring(sc); 10472 bxe_init_internal(sc, load_code); 10473 bxe_pf_init(sc); 10474 bxe_stats_init(sc); 10475 10476 /* flush all before enabling interrupts */ 10477 mb(); 10478 10479 bxe_int_enable(sc); 10480 10481 /* check for SPIO5 */ 10482 bxe_attn_int_deasserted0(sc, 10483 REG_RD(sc, 10484 (MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + 10485 SC_PORT(sc)*4)) & 10486 AEU_INPUTS_ATTN_BITS_SPIO5); 10487 } 10488 10489 static inline void 10490 bxe_init_objs(struct bxe_softc *sc) 10491 { 10492 /* mcast rules must be added to tx if tx switching is enabled */ 10493 ecore_obj_type o_type = 10494 (sc->flags & BXE_TX_SWITCHING) ? ECORE_OBJ_TYPE_RX_TX : 10495 ECORE_OBJ_TYPE_RX; 10496 10497 /* RX_MODE controlling object */ 10498 ecore_init_rx_mode_obj(sc, &sc->rx_mode_obj); 10499 10500 /* multicast configuration controlling object */ 10501 ecore_init_mcast_obj(sc, 10502 &sc->mcast_obj, 10503 sc->fp[0].cl_id, 10504 sc->fp[0].index, 10505 SC_FUNC(sc), 10506 SC_FUNC(sc), 10507 BXE_SP(sc, mcast_rdata), 10508 BXE_SP_MAPPING(sc, mcast_rdata), 10509 ECORE_FILTER_MCAST_PENDING, 10510 &sc->sp_state, 10511 o_type); 10512 10513 /* Setup CAM credit pools */ 10514 ecore_init_mac_credit_pool(sc, 10515 &sc->macs_pool, 10516 SC_FUNC(sc), 10517 CHIP_IS_E1x(sc) ? VNICS_PER_PORT(sc) : 10518 VNICS_PER_PATH(sc)); 10519 10520 ecore_init_vlan_credit_pool(sc, 10521 &sc->vlans_pool, 10522 SC_ABS_FUNC(sc) >> 1, 10523 CHIP_IS_E1x(sc) ? VNICS_PER_PORT(sc) : 10524 VNICS_PER_PATH(sc)); 10525 10526 /* RSS configuration object */ 10527 ecore_init_rss_config_obj(sc, 10528 &sc->rss_conf_obj, 10529 sc->fp[0].cl_id, 10530 sc->fp[0].index, 10531 SC_FUNC(sc), 10532 SC_FUNC(sc), 10533 BXE_SP(sc, rss_rdata), 10534 BXE_SP_MAPPING(sc, rss_rdata), 10535 ECORE_FILTER_RSS_CONF_PENDING, 10536 &sc->sp_state, ECORE_OBJ_TYPE_RX); 10537 } 10538 10539 /* 10540 * Initialize the function. This must be called before sending CLIENT_SETUP 10541 * for the first client. 10542 */ 10543 static inline int 10544 bxe_func_start(struct bxe_softc *sc) 10545 { 10546 struct ecore_func_state_params func_params = { NULL }; 10547 struct ecore_func_start_params *start_params = &func_params.params.start; 10548 10549 /* Prepare parameters for function state transitions */ 10550 bit_set(&func_params.ramrod_flags, RAMROD_COMP_WAIT); 10551 10552 func_params.f_obj = &sc->func_obj; 10553 func_params.cmd = ECORE_F_CMD_START; 10554 10555 /* Function parameters */ 10556 start_params->mf_mode = sc->devinfo.mf_info.mf_mode; 10557 start_params->sd_vlan_tag = OVLAN(sc); 10558 10559 if (CHIP_IS_E2(sc) || CHIP_IS_E3(sc)) { 10560 start_params->network_cos_mode = STATIC_COS; 10561 } else { /* CHIP_IS_E1X */ 10562 start_params->network_cos_mode = FW_WRR; 10563 } 10564 10565 //start_params->gre_tunnel_mode = 0; 10566 //start_params->gre_tunnel_rss = 0; 10567 10568 return (ecore_func_state_change(sc, &func_params)); 10569 } 10570 10571 static int 10572 bxe_set_power_state(struct bxe_softc *sc, 10573 uint8_t state) 10574 { 10575 uint16_t pmcsr; 10576 10577 /* If there is no power capability, silently succeed */ 10578 if (!(sc->devinfo.pcie_cap_flags & BXE_PM_CAPABLE_FLAG)) { 10579 BLOGW(sc, "No power capability\n"); 10580 return (0); 10581 } 10582 10583 pmcsr = pci_read_config(sc->dev, 10584 (sc->devinfo.pcie_pm_cap_reg + PCIR_POWER_STATUS), 10585 2); 10586 10587 switch (state) { 10588 case PCI_PM_D0: 10589 pci_write_config(sc->dev, 10590 (sc->devinfo.pcie_pm_cap_reg + PCIR_POWER_STATUS), 10591 ((pmcsr & ~PCIM_PSTAT_DMASK) | PCIM_PSTAT_PME), 2); 10592 10593 if (pmcsr & PCIM_PSTAT_DMASK) { 10594 /* delay required during transition out of D3hot */ 10595 DELAY(20000); 10596 } 10597 10598 break; 10599 10600 case PCI_PM_D3hot: 10601 /* XXX if there are other clients above don't shut down the power */ 10602 10603 /* don't shut down the power for emulation and FPGA */ 10604 if (CHIP_REV_IS_SLOW(sc)) { 10605 return (0); 10606 } 10607 10608 pmcsr &= ~PCIM_PSTAT_DMASK; 10609 pmcsr |= PCIM_PSTAT_D3; 10610 10611 if (sc->wol) { 10612 pmcsr |= PCIM_PSTAT_PMEENABLE; 10613 } 10614 10615 pci_write_config(sc->dev, 10616 (sc->devinfo.pcie_pm_cap_reg + PCIR_POWER_STATUS), 10617 pmcsr, 4); 10618 10619 /* 10620 * No more memory access after this point until device is brought back 10621 * to D0 state. 10622 */ 10623 break; 10624 10625 default: 10626 BLOGE(sc, "Can't support PCI power state = 0x%x pmcsr 0x%x\n", 10627 state, pmcsr); 10628 return (-1); 10629 } 10630 10631 return (0); 10632 } 10633 10634 10635 /* return true if succeeded to acquire the lock */ 10636 static uint8_t 10637 bxe_trylock_hw_lock(struct bxe_softc *sc, 10638 uint32_t resource) 10639 { 10640 uint32_t lock_status; 10641 uint32_t resource_bit = (1 << resource); 10642 int func = SC_FUNC(sc); 10643 uint32_t hw_lock_control_reg; 10644 10645 BLOGD(sc, DBG_LOAD, "Trying to take a resource lock 0x%x\n", resource); 10646 10647 /* Validating that the resource is within range */ 10648 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { 10649 BLOGD(sc, DBG_LOAD, 10650 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", 10651 resource, HW_LOCK_MAX_RESOURCE_VALUE); 10652 return (FALSE); 10653 } 10654 10655 if (func <= 5) { 10656 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); 10657 } else { 10658 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); 10659 } 10660 10661 /* try to acquire the lock */ 10662 REG_WR(sc, hw_lock_control_reg + 4, resource_bit); 10663 lock_status = REG_RD(sc, hw_lock_control_reg); 10664 if (lock_status & resource_bit) { 10665 return (TRUE); 10666 } 10667 10668 BLOGE(sc, "Failed to get a resource lock 0x%x func %d " 10669 "lock_status 0x%x resource_bit 0x%x\n", resource, func, 10670 lock_status, resource_bit); 10671 10672 return (FALSE); 10673 } 10674 10675 /* 10676 * Get the recovery leader resource id according to the engine this function 10677 * belongs to. Currently only only 2 engines is supported. 10678 */ 10679 static int 10680 bxe_get_leader_lock_resource(struct bxe_softc *sc) 10681 { 10682 if (SC_PATH(sc)) { 10683 return (HW_LOCK_RESOURCE_RECOVERY_LEADER_1); 10684 } else { 10685 return (HW_LOCK_RESOURCE_RECOVERY_LEADER_0); 10686 } 10687 } 10688 10689 /* try to acquire a leader lock for current engine */ 10690 static uint8_t 10691 bxe_trylock_leader_lock(struct bxe_softc *sc) 10692 { 10693 return (bxe_trylock_hw_lock(sc, bxe_get_leader_lock_resource(sc))); 10694 } 10695 10696 static int 10697 bxe_release_leader_lock(struct bxe_softc *sc) 10698 { 10699 return (bxe_release_hw_lock(sc, bxe_get_leader_lock_resource(sc))); 10700 } 10701 10702 /* close gates #2, #3 and #4 */ 10703 static void 10704 bxe_set_234_gates(struct bxe_softc *sc, 10705 uint8_t close) 10706 { 10707 uint32_t val; 10708 10709 /* gates #2 and #4a are closed/opened for "not E1" only */ 10710 if (!CHIP_IS_E1(sc)) { 10711 /* #4 */ 10712 REG_WR(sc, PXP_REG_HST_DISCARD_DOORBELLS, !!close); 10713 /* #2 */ 10714 REG_WR(sc, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close); 10715 } 10716 10717 /* #3 */ 10718 if (CHIP_IS_E1x(sc)) { 10719 /* prevent interrupts from HC on both ports */ 10720 val = REG_RD(sc, HC_REG_CONFIG_1); 10721 REG_WR(sc, HC_REG_CONFIG_1, 10722 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) : 10723 (val & ~(uint32_t)HC_CONFIG_1_REG_BLOCK_DISABLE_1)); 10724 10725 val = REG_RD(sc, HC_REG_CONFIG_0); 10726 REG_WR(sc, HC_REG_CONFIG_0, 10727 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) : 10728 (val & ~(uint32_t)HC_CONFIG_0_REG_BLOCK_DISABLE_0)); 10729 } else { 10730 /* Prevent incoming interrupts in IGU */ 10731 val = REG_RD(sc, IGU_REG_BLOCK_CONFIGURATION); 10732 10733 REG_WR(sc, IGU_REG_BLOCK_CONFIGURATION, 10734 (!close) ? 10735 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) : 10736 (val & ~(uint32_t)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE)); 10737 } 10738 10739 BLOGD(sc, DBG_LOAD, "%s gates #2, #3 and #4\n", 10740 close ? "closing" : "opening"); 10741 10742 wmb(); 10743 } 10744 10745 /* poll for pending writes bit, it should get cleared in no more than 1s */ 10746 static int 10747 bxe_er_poll_igu_vq(struct bxe_softc *sc) 10748 { 10749 uint32_t cnt = 1000; 10750 uint32_t pend_bits = 0; 10751 10752 do { 10753 pend_bits = REG_RD(sc, IGU_REG_PENDING_BITS_STATUS); 10754 10755 if (pend_bits == 0) { 10756 break; 10757 } 10758 10759 DELAY(1000); 10760 } while (--cnt > 0); 10761 10762 if (cnt == 0) { 10763 BLOGE(sc, "Still pending IGU requests bits=0x%08x!\n", pend_bits); 10764 return (-1); 10765 } 10766 10767 return (0); 10768 } 10769 10770 #define SHARED_MF_CLP_MAGIC 0x80000000 /* 'magic' bit */ 10771 10772 static void 10773 bxe_clp_reset_prep(struct bxe_softc *sc, 10774 uint32_t *magic_val) 10775 { 10776 /* Do some magic... */ 10777 uint32_t val = MFCFG_RD(sc, shared_mf_config.clp_mb); 10778 *magic_val = val & SHARED_MF_CLP_MAGIC; 10779 MFCFG_WR(sc, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC); 10780 } 10781 10782 /* restore the value of the 'magic' bit */ 10783 static void 10784 bxe_clp_reset_done(struct bxe_softc *sc, 10785 uint32_t magic_val) 10786 { 10787 /* Restore the 'magic' bit value... */ 10788 uint32_t val = MFCFG_RD(sc, shared_mf_config.clp_mb); 10789 MFCFG_WR(sc, shared_mf_config.clp_mb, 10790 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val); 10791 } 10792 10793 /* prepare for MCP reset, takes care of CLP configurations */ 10794 static void 10795 bxe_reset_mcp_prep(struct bxe_softc *sc, 10796 uint32_t *magic_val) 10797 { 10798 uint32_t shmem; 10799 uint32_t validity_offset; 10800 10801 /* set `magic' bit in order to save MF config */ 10802 if (!CHIP_IS_E1(sc)) { 10803 bxe_clp_reset_prep(sc, magic_val); 10804 } 10805 10806 /* get shmem offset */ 10807 shmem = REG_RD(sc, MISC_REG_SHARED_MEM_ADDR); 10808 validity_offset = 10809 offsetof(struct shmem_region, validity_map[SC_PORT(sc)]); 10810 10811 /* Clear validity map flags */ 10812 if (shmem > 0) { 10813 REG_WR(sc, shmem + validity_offset, 0); 10814 } 10815 } 10816 10817 #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */ 10818 #define MCP_ONE_TIMEOUT 100 /* 100 ms */ 10819 10820 static void 10821 bxe_mcp_wait_one(struct bxe_softc *sc) 10822 { 10823 /* special handling for emulation and FPGA (10 times longer) */ 10824 if (CHIP_REV_IS_SLOW(sc)) { 10825 DELAY((MCP_ONE_TIMEOUT*10) * 1000); 10826 } else { 10827 DELAY((MCP_ONE_TIMEOUT) * 1000); 10828 } 10829 } 10830 10831 /* initialize shmem_base and waits for validity signature to appear */ 10832 static int 10833 bxe_init_shmem(struct bxe_softc *sc) 10834 { 10835 int cnt = 0; 10836 uint32_t val = 0; 10837 10838 do { 10839 sc->devinfo.shmem_base = 10840 sc->link_params.shmem_base = 10841 REG_RD(sc, MISC_REG_SHARED_MEM_ADDR); 10842 10843 if (sc->devinfo.shmem_base) { 10844 val = SHMEM_RD(sc, validity_map[SC_PORT(sc)]); 10845 if (val & SHR_MEM_VALIDITY_MB) 10846 return (0); 10847 } 10848 10849 bxe_mcp_wait_one(sc); 10850 10851 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT)); 10852 10853 BLOGE(sc, "BAD MCP validity signature\n"); 10854 10855 return (-1); 10856 } 10857 10858 static int 10859 bxe_reset_mcp_comp(struct bxe_softc *sc, 10860 uint32_t magic_val) 10861 { 10862 int rc = bxe_init_shmem(sc); 10863 10864 /* Restore the `magic' bit value */ 10865 if (!CHIP_IS_E1(sc)) { 10866 bxe_clp_reset_done(sc, magic_val); 10867 } 10868 10869 return (rc); 10870 } 10871 10872 static void 10873 bxe_pxp_prep(struct bxe_softc *sc) 10874 { 10875 if (!CHIP_IS_E1(sc)) { 10876 REG_WR(sc, PXP2_REG_RD_START_INIT, 0); 10877 REG_WR(sc, PXP2_REG_RQ_RBC_DONE, 0); 10878 wmb(); 10879 } 10880 } 10881 10882 /* 10883 * Reset the whole chip except for: 10884 * - PCIE core 10885 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by one reset bit) 10886 * - IGU 10887 * - MISC (including AEU) 10888 * - GRC 10889 * - RBCN, RBCP 10890 */ 10891 static void 10892 bxe_process_kill_chip_reset(struct bxe_softc *sc, 10893 uint8_t global) 10894 { 10895 uint32_t not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2; 10896 uint32_t global_bits2, stay_reset2; 10897 10898 /* 10899 * Bits that have to be set in reset_mask2 if we want to reset 'global' 10900 * (per chip) blocks. 10901 */ 10902 global_bits2 = 10903 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU | 10904 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE; 10905 10906 /* 10907 * Don't reset the following blocks. 10908 * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be 10909 * reset, as in 4 port device they might still be owned 10910 * by the MCP (there is only one leader per path). 10911 */ 10912 not_reset_mask1 = 10913 MISC_REGISTERS_RESET_REG_1_RST_HC | 10914 MISC_REGISTERS_RESET_REG_1_RST_PXPV | 10915 MISC_REGISTERS_RESET_REG_1_RST_PXP; 10916 10917 not_reset_mask2 = 10918 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO | 10919 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE | 10920 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE | 10921 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE | 10922 MISC_REGISTERS_RESET_REG_2_RST_RBCN | 10923 MISC_REGISTERS_RESET_REG_2_RST_GRC | 10924 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE | 10925 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B | 10926 MISC_REGISTERS_RESET_REG_2_RST_ATC | 10927 MISC_REGISTERS_RESET_REG_2_PGLC | 10928 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 | 10929 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 | 10930 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 | 10931 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 | 10932 MISC_REGISTERS_RESET_REG_2_UMAC0 | 10933 MISC_REGISTERS_RESET_REG_2_UMAC1; 10934 10935 /* 10936 * Keep the following blocks in reset: 10937 * - all xxMACs are handled by the elink code. 10938 */ 10939 stay_reset2 = 10940 MISC_REGISTERS_RESET_REG_2_XMAC | 10941 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT; 10942 10943 /* Full reset masks according to the chip */ 10944 reset_mask1 = 0xffffffff; 10945 10946 if (CHIP_IS_E1(sc)) 10947 reset_mask2 = 0xffff; 10948 else if (CHIP_IS_E1H(sc)) 10949 reset_mask2 = 0x1ffff; 10950 else if (CHIP_IS_E2(sc)) 10951 reset_mask2 = 0xfffff; 10952 else /* CHIP_IS_E3 */ 10953 reset_mask2 = 0x3ffffff; 10954 10955 /* Don't reset global blocks unless we need to */ 10956 if (!global) 10957 reset_mask2 &= ~global_bits2; 10958 10959 /* 10960 * In case of attention in the QM, we need to reset PXP 10961 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM 10962 * because otherwise QM reset would release 'close the gates' shortly 10963 * before resetting the PXP, then the PSWRQ would send a write 10964 * request to PGLUE. Then when PXP is reset, PGLUE would try to 10965 * read the payload data from PSWWR, but PSWWR would not 10966 * respond. The write queue in PGLUE would stuck, dmae commands 10967 * would not return. Therefore it's important to reset the second 10968 * reset register (containing the 10969 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the 10970 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM 10971 * bit). 10972 */ 10973 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, 10974 reset_mask2 & (~not_reset_mask2)); 10975 10976 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 10977 reset_mask1 & (~not_reset_mask1)); 10978 10979 mb(); 10980 wmb(); 10981 10982 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, 10983 reset_mask2 & (~stay_reset2)); 10984 10985 mb(); 10986 wmb(); 10987 10988 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1); 10989 wmb(); 10990 } 10991 10992 static int 10993 bxe_process_kill(struct bxe_softc *sc, 10994 uint8_t global) 10995 { 10996 int cnt = 1000; 10997 uint32_t val = 0; 10998 uint32_t sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2; 10999 uint32_t tags_63_32 = 0; 11000 11001 /* Empty the Tetris buffer, wait for 1s */ 11002 do { 11003 sr_cnt = REG_RD(sc, PXP2_REG_RD_SR_CNT); 11004 blk_cnt = REG_RD(sc, PXP2_REG_RD_BLK_CNT); 11005 port_is_idle_0 = REG_RD(sc, PXP2_REG_RD_PORT_IS_IDLE_0); 11006 port_is_idle_1 = REG_RD(sc, PXP2_REG_RD_PORT_IS_IDLE_1); 11007 pgl_exp_rom2 = REG_RD(sc, PXP2_REG_PGL_EXP_ROM2); 11008 if (CHIP_IS_E3(sc)) { 11009 tags_63_32 = REG_RD(sc, PGLUE_B_REG_TAGS_63_32); 11010 } 11011 11012 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) && 11013 ((port_is_idle_0 & 0x1) == 0x1) && 11014 ((port_is_idle_1 & 0x1) == 0x1) && 11015 (pgl_exp_rom2 == 0xffffffff) && 11016 (!CHIP_IS_E3(sc) || (tags_63_32 == 0xffffffff))) 11017 break; 11018 DELAY(1000); 11019 } while (cnt-- > 0); 11020 11021 if (cnt <= 0) { 11022 BLOGE(sc, "ERROR: Tetris buffer didn't get empty or there " 11023 "are still outstanding read requests after 1s! " 11024 "sr_cnt=0x%08x, blk_cnt=0x%08x, port_is_idle_0=0x%08x, " 11025 "port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n", 11026 sr_cnt, blk_cnt, port_is_idle_0, 11027 port_is_idle_1, pgl_exp_rom2); 11028 return (-1); 11029 } 11030 11031 mb(); 11032 11033 /* Close gates #2, #3 and #4 */ 11034 bxe_set_234_gates(sc, TRUE); 11035 11036 /* Poll for IGU VQs for 57712 and newer chips */ 11037 if (!CHIP_IS_E1x(sc) && bxe_er_poll_igu_vq(sc)) { 11038 return (-1); 11039 } 11040 11041 /* XXX indicate that "process kill" is in progress to MCP */ 11042 11043 /* clear "unprepared" bit */ 11044 REG_WR(sc, MISC_REG_UNPREPARED, 0); 11045 mb(); 11046 11047 /* Make sure all is written to the chip before the reset */ 11048 wmb(); 11049 11050 /* 11051 * Wait for 1ms to empty GLUE and PCI-E core queues, 11052 * PSWHST, GRC and PSWRD Tetris buffer. 11053 */ 11054 DELAY(1000); 11055 11056 /* Prepare to chip reset: */ 11057 /* MCP */ 11058 if (global) { 11059 bxe_reset_mcp_prep(sc, &val); 11060 } 11061 11062 /* PXP */ 11063 bxe_pxp_prep(sc); 11064 mb(); 11065 11066 /* reset the chip */ 11067 bxe_process_kill_chip_reset(sc, global); 11068 mb(); 11069 11070 /* clear errors in PGB */ 11071 if (!CHIP_IS_E1(sc)) 11072 REG_WR(sc, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f); 11073 11074 /* Recover after reset: */ 11075 /* MCP */ 11076 if (global && bxe_reset_mcp_comp(sc, val)) { 11077 return (-1); 11078 } 11079 11080 /* XXX add resetting the NO_MCP mode DB here */ 11081 11082 /* Open the gates #2, #3 and #4 */ 11083 bxe_set_234_gates(sc, FALSE); 11084 11085 /* XXX 11086 * IGU/AEU preparation bring back the AEU/IGU to a reset state 11087 * re-enable attentions 11088 */ 11089 11090 return (0); 11091 } 11092 11093 static int 11094 bxe_leader_reset(struct bxe_softc *sc) 11095 { 11096 int rc = 0; 11097 uint8_t global = bxe_reset_is_global(sc); 11098 uint32_t load_code; 11099 11100 /* 11101 * If not going to reset MCP, load "fake" driver to reset HW while 11102 * driver is owner of the HW. 11103 */ 11104 if (!global && !BXE_NOMCP(sc)) { 11105 load_code = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_REQ, 11106 DRV_MSG_CODE_LOAD_REQ_WITH_LFA); 11107 if (!load_code) { 11108 BLOGE(sc, "MCP response failure, aborting\n"); 11109 rc = -1; 11110 goto exit_leader_reset; 11111 } 11112 11113 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) && 11114 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) { 11115 BLOGE(sc, "MCP unexpected response, aborting\n"); 11116 rc = -1; 11117 goto exit_leader_reset2; 11118 } 11119 11120 load_code = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0); 11121 if (!load_code) { 11122 BLOGE(sc, "MCP response failure, aborting\n"); 11123 rc = -1; 11124 goto exit_leader_reset2; 11125 } 11126 } 11127 11128 /* try to recover after the failure */ 11129 if (bxe_process_kill(sc, global)) { 11130 BLOGE(sc, "Something bad occurred on engine %d!\n", SC_PATH(sc)); 11131 rc = -1; 11132 goto exit_leader_reset2; 11133 } 11134 11135 /* 11136 * Clear the RESET_IN_PROGRESS and RESET_GLOBAL bits and update the driver 11137 * state. 11138 */ 11139 bxe_set_reset_done(sc); 11140 if (global) { 11141 bxe_clear_reset_global(sc); 11142 } 11143 11144 exit_leader_reset2: 11145 11146 /* unload "fake driver" if it was loaded */ 11147 if (!global && !BXE_NOMCP(sc)) { 11148 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0); 11149 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, 0); 11150 } 11151 11152 exit_leader_reset: 11153 11154 sc->is_leader = 0; 11155 bxe_release_leader_lock(sc); 11156 11157 mb(); 11158 return (rc); 11159 } 11160 11161 /* 11162 * prepare INIT transition, parameters configured: 11163 * - HC configuration 11164 * - Queue's CDU context 11165 */ 11166 static void 11167 bxe_pf_q_prep_init(struct bxe_softc *sc, 11168 struct bxe_fastpath *fp, 11169 struct ecore_queue_init_params *init_params) 11170 { 11171 uint8_t cos; 11172 int cxt_index, cxt_offset; 11173 11174 bxe_set_bit(ECORE_Q_FLG_HC, &init_params->rx.flags); 11175 bxe_set_bit(ECORE_Q_FLG_HC, &init_params->tx.flags); 11176 11177 bxe_set_bit(ECORE_Q_FLG_HC_EN, &init_params->rx.flags); 11178 bxe_set_bit(ECORE_Q_FLG_HC_EN, &init_params->tx.flags); 11179 11180 /* HC rate */ 11181 init_params->rx.hc_rate = 11182 sc->hc_rx_ticks ? (1000000 / sc->hc_rx_ticks) : 0; 11183 init_params->tx.hc_rate = 11184 sc->hc_tx_ticks ? (1000000 / sc->hc_tx_ticks) : 0; 11185 11186 /* FW SB ID */ 11187 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id = fp->fw_sb_id; 11188 11189 /* CQ index among the SB indices */ 11190 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS; 11191 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS; 11192 11193 /* set maximum number of COSs supported by this queue */ 11194 init_params->max_cos = sc->max_cos; 11195 11196 BLOGD(sc, DBG_LOAD, "fp %d setting queue params max cos to %d\n", 11197 fp->index, init_params->max_cos); 11198 11199 /* set the context pointers queue object */ 11200 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) { 11201 /* XXX change index/cid here if ever support multiple tx CoS */ 11202 /* fp->txdata[cos]->cid */ 11203 cxt_index = fp->index / ILT_PAGE_CIDS; 11204 cxt_offset = fp->index - (cxt_index * ILT_PAGE_CIDS); 11205 init_params->cxts[cos] = &sc->context[cxt_index].vcxt[cxt_offset].eth; 11206 } 11207 } 11208 11209 /* set flags that are common for the Tx-only and not normal connections */ 11210 static unsigned long 11211 bxe_get_common_flags(struct bxe_softc *sc, 11212 struct bxe_fastpath *fp, 11213 uint8_t zero_stats) 11214 { 11215 unsigned long flags = 0; 11216 11217 /* PF driver will always initialize the Queue to an ACTIVE state */ 11218 bxe_set_bit(ECORE_Q_FLG_ACTIVE, &flags); 11219 11220 /* 11221 * tx only connections collect statistics (on the same index as the 11222 * parent connection). The statistics are zeroed when the parent 11223 * connection is initialized. 11224 */ 11225 11226 bxe_set_bit(ECORE_Q_FLG_STATS, &flags); 11227 if (zero_stats) { 11228 bxe_set_bit(ECORE_Q_FLG_ZERO_STATS, &flags); 11229 } 11230 11231 /* 11232 * tx only connections can support tx-switching, though their 11233 * CoS-ness doesn't survive the loopback 11234 */ 11235 if (sc->flags & BXE_TX_SWITCHING) { 11236 bxe_set_bit(ECORE_Q_FLG_TX_SWITCH, &flags); 11237 } 11238 11239 bxe_set_bit(ECORE_Q_FLG_PCSUM_ON_PKT, &flags); 11240 11241 return (flags); 11242 } 11243 11244 static unsigned long 11245 bxe_get_q_flags(struct bxe_softc *sc, 11246 struct bxe_fastpath *fp, 11247 uint8_t leading) 11248 { 11249 unsigned long flags = 0; 11250 11251 if (IS_MF_SD(sc)) { 11252 bxe_set_bit(ECORE_Q_FLG_OV, &flags); 11253 } 11254 11255 if (if_getcapenable(sc->ifp) & IFCAP_LRO) { 11256 bxe_set_bit(ECORE_Q_FLG_TPA, &flags); 11257 bxe_set_bit(ECORE_Q_FLG_TPA_IPV6, &flags); 11258 } 11259 11260 if (leading) { 11261 bxe_set_bit(ECORE_Q_FLG_LEADING_RSS, &flags); 11262 bxe_set_bit(ECORE_Q_FLG_MCAST, &flags); 11263 } 11264 11265 bxe_set_bit(ECORE_Q_FLG_VLAN, &flags); 11266 11267 /* merge with common flags */ 11268 return (flags | bxe_get_common_flags(sc, fp, TRUE)); 11269 } 11270 11271 static void 11272 bxe_pf_q_prep_general(struct bxe_softc *sc, 11273 struct bxe_fastpath *fp, 11274 struct ecore_general_setup_params *gen_init, 11275 uint8_t cos) 11276 { 11277 gen_init->stat_id = bxe_stats_id(fp); 11278 gen_init->spcl_id = fp->cl_id; 11279 gen_init->mtu = sc->mtu; 11280 gen_init->cos = cos; 11281 } 11282 11283 static void 11284 bxe_pf_rx_q_prep(struct bxe_softc *sc, 11285 struct bxe_fastpath *fp, 11286 struct rxq_pause_params *pause, 11287 struct ecore_rxq_setup_params *rxq_init) 11288 { 11289 uint8_t max_sge = 0; 11290 uint16_t sge_sz = 0; 11291 uint16_t tpa_agg_size = 0; 11292 11293 pause->sge_th_lo = SGE_TH_LO(sc); 11294 pause->sge_th_hi = SGE_TH_HI(sc); 11295 11296 /* validate SGE ring has enough to cross high threshold */ 11297 if (sc->dropless_fc && 11298 (pause->sge_th_hi + FW_PREFETCH_CNT) > 11299 (RX_SGE_USABLE_PER_PAGE * RX_SGE_NUM_PAGES)) { 11300 BLOGW(sc, "sge ring threshold limit\n"); 11301 } 11302 11303 /* minimum max_aggregation_size is 2*MTU (two full buffers) */ 11304 tpa_agg_size = (2 * sc->mtu); 11305 if (tpa_agg_size < sc->max_aggregation_size) { 11306 tpa_agg_size = sc->max_aggregation_size; 11307 } 11308 11309 max_sge = SGE_PAGE_ALIGN(sc->mtu) >> SGE_PAGE_SHIFT; 11310 max_sge = ((max_sge + PAGES_PER_SGE - 1) & 11311 (~(PAGES_PER_SGE - 1))) >> PAGES_PER_SGE_SHIFT; 11312 sge_sz = (uint16_t)min(SGE_PAGES, 0xffff); 11313 11314 /* pause - not for e1 */ 11315 if (!CHIP_IS_E1(sc)) { 11316 pause->bd_th_lo = BD_TH_LO(sc); 11317 pause->bd_th_hi = BD_TH_HI(sc); 11318 11319 pause->rcq_th_lo = RCQ_TH_LO(sc); 11320 pause->rcq_th_hi = RCQ_TH_HI(sc); 11321 11322 /* validate rings have enough entries to cross high thresholds */ 11323 if (sc->dropless_fc && 11324 pause->bd_th_hi + FW_PREFETCH_CNT > 11325 sc->rx_ring_size) { 11326 BLOGW(sc, "rx bd ring threshold limit\n"); 11327 } 11328 11329 if (sc->dropless_fc && 11330 pause->rcq_th_hi + FW_PREFETCH_CNT > 11331 RCQ_NUM_PAGES * RCQ_USABLE_PER_PAGE) { 11332 BLOGW(sc, "rcq ring threshold limit\n"); 11333 } 11334 11335 pause->pri_map = 1; 11336 } 11337 11338 /* rxq setup */ 11339 rxq_init->dscr_map = fp->rx_dma.paddr; 11340 rxq_init->sge_map = fp->rx_sge_dma.paddr; 11341 rxq_init->rcq_map = fp->rcq_dma.paddr; 11342 rxq_init->rcq_np_map = (fp->rcq_dma.paddr + BCM_PAGE_SIZE); 11343 11344 /* 11345 * This should be a maximum number of data bytes that may be 11346 * placed on the BD (not including paddings). 11347 */ 11348 rxq_init->buf_sz = (fp->rx_buf_size - 11349 IP_HEADER_ALIGNMENT_PADDING); 11350 11351 rxq_init->cl_qzone_id = fp->cl_qzone_id; 11352 rxq_init->tpa_agg_sz = tpa_agg_size; 11353 rxq_init->sge_buf_sz = sge_sz; 11354 rxq_init->max_sges_pkt = max_sge; 11355 rxq_init->rss_engine_id = SC_FUNC(sc); 11356 rxq_init->mcast_engine_id = SC_FUNC(sc); 11357 11358 /* 11359 * Maximum number or simultaneous TPA aggregation for this Queue. 11360 * For PF Clients it should be the maximum available number. 11361 * VF driver(s) may want to define it to a smaller value. 11362 */ 11363 rxq_init->max_tpa_queues = MAX_AGG_QS(sc); 11364 11365 rxq_init->cache_line_log = BXE_RX_ALIGN_SHIFT; 11366 rxq_init->fw_sb_id = fp->fw_sb_id; 11367 11368 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS; 11369 11370 /* 11371 * configure silent vlan removal 11372 * if multi function mode is afex, then mask default vlan 11373 */ 11374 if (IS_MF_AFEX(sc)) { 11375 rxq_init->silent_removal_value = 11376 sc->devinfo.mf_info.afex_def_vlan_tag; 11377 rxq_init->silent_removal_mask = EVL_VLID_MASK; 11378 } 11379 } 11380 11381 static void 11382 bxe_pf_tx_q_prep(struct bxe_softc *sc, 11383 struct bxe_fastpath *fp, 11384 struct ecore_txq_setup_params *txq_init, 11385 uint8_t cos) 11386 { 11387 /* 11388 * XXX If multiple CoS is ever supported then each fastpath structure 11389 * will need to maintain tx producer/consumer/dma/etc values *per* CoS. 11390 * fp->txdata[cos]->tx_dma.paddr; 11391 */ 11392 txq_init->dscr_map = fp->tx_dma.paddr; 11393 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos; 11394 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW; 11395 txq_init->fw_sb_id = fp->fw_sb_id; 11396 11397 /* 11398 * set the TSS leading client id for TX classfication to the 11399 * leading RSS client id 11400 */ 11401 txq_init->tss_leading_cl_id = BXE_FP(sc, 0, cl_id); 11402 } 11403 11404 /* 11405 * This function performs 2 steps in a queue state machine: 11406 * 1) RESET->INIT 11407 * 2) INIT->SETUP 11408 */ 11409 static int 11410 bxe_setup_queue(struct bxe_softc *sc, 11411 struct bxe_fastpath *fp, 11412 uint8_t leading) 11413 { 11414 struct ecore_queue_state_params q_params = { NULL }; 11415 struct ecore_queue_setup_params *setup_params = 11416 &q_params.params.setup; 11417 int rc; 11418 11419 BLOGD(sc, DBG_LOAD, "setting up queue %d\n", fp->index); 11420 11421 bxe_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0); 11422 11423 q_params.q_obj = &BXE_SP_OBJ(sc, fp).q_obj; 11424 11425 /* we want to wait for completion in this context */ 11426 bxe_set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags); 11427 11428 /* prepare the INIT parameters */ 11429 bxe_pf_q_prep_init(sc, fp, &q_params.params.init); 11430 11431 /* Set the command */ 11432 q_params.cmd = ECORE_Q_CMD_INIT; 11433 11434 /* Change the state to INIT */ 11435 rc = ecore_queue_state_change(sc, &q_params); 11436 if (rc) { 11437 BLOGE(sc, "Queue(%d) INIT failed rc = %d\n", fp->index, rc); 11438 return (rc); 11439 } 11440 11441 BLOGD(sc, DBG_LOAD, "init complete\n"); 11442 11443 /* now move the Queue to the SETUP state */ 11444 memset(setup_params, 0, sizeof(*setup_params)); 11445 11446 /* set Queue flags */ 11447 setup_params->flags = bxe_get_q_flags(sc, fp, leading); 11448 11449 /* set general SETUP parameters */ 11450 bxe_pf_q_prep_general(sc, fp, &setup_params->gen_params, 11451 FIRST_TX_COS_INDEX); 11452 11453 bxe_pf_rx_q_prep(sc, fp, 11454 &setup_params->pause_params, 11455 &setup_params->rxq_params); 11456 11457 bxe_pf_tx_q_prep(sc, fp, 11458 &setup_params->txq_params, 11459 FIRST_TX_COS_INDEX); 11460 11461 /* Set the command */ 11462 q_params.cmd = ECORE_Q_CMD_SETUP; 11463 11464 /* change the state to SETUP */ 11465 rc = ecore_queue_state_change(sc, &q_params); 11466 if (rc) { 11467 BLOGE(sc, "Queue(%d) SETUP failed (rc = %d)\n", fp->index, rc); 11468 return (rc); 11469 } 11470 11471 return (rc); 11472 } 11473 11474 static int 11475 bxe_setup_leading(struct bxe_softc *sc) 11476 { 11477 return (bxe_setup_queue(sc, &sc->fp[0], TRUE)); 11478 } 11479 11480 static int 11481 bxe_config_rss_pf(struct bxe_softc *sc, 11482 struct ecore_rss_config_obj *rss_obj, 11483 uint8_t config_hash) 11484 { 11485 struct ecore_config_rss_params params = { NULL }; 11486 int i; 11487 11488 /* 11489 * Although RSS is meaningless when there is a single HW queue we 11490 * still need it enabled in order to have HW Rx hash generated. 11491 */ 11492 11493 params.rss_obj = rss_obj; 11494 11495 bxe_set_bit(RAMROD_COMP_WAIT, ¶ms.ramrod_flags); 11496 11497 bxe_set_bit(ECORE_RSS_MODE_REGULAR, ¶ms.rss_flags); 11498 11499 /* RSS configuration */ 11500 bxe_set_bit(ECORE_RSS_IPV4, ¶ms.rss_flags); 11501 bxe_set_bit(ECORE_RSS_IPV4_TCP, ¶ms.rss_flags); 11502 bxe_set_bit(ECORE_RSS_IPV6, ¶ms.rss_flags); 11503 bxe_set_bit(ECORE_RSS_IPV6_TCP, ¶ms.rss_flags); 11504 if (rss_obj->udp_rss_v4) { 11505 bxe_set_bit(ECORE_RSS_IPV4_UDP, ¶ms.rss_flags); 11506 } 11507 if (rss_obj->udp_rss_v6) { 11508 bxe_set_bit(ECORE_RSS_IPV6_UDP, ¶ms.rss_flags); 11509 } 11510 11511 /* Hash bits */ 11512 params.rss_result_mask = MULTI_MASK; 11513 11514 memcpy(params.ind_table, rss_obj->ind_table, sizeof(params.ind_table)); 11515 11516 if (config_hash) { 11517 /* RSS keys */ 11518 for (i = 0; i < sizeof(params.rss_key) / 4; i++) { 11519 params.rss_key[i] = arc4random(); 11520 } 11521 11522 bxe_set_bit(ECORE_RSS_SET_SRCH, ¶ms.rss_flags); 11523 } 11524 11525 return (ecore_config_rss(sc, ¶ms)); 11526 } 11527 11528 static int 11529 bxe_config_rss_eth(struct bxe_softc *sc, 11530 uint8_t config_hash) 11531 { 11532 return (bxe_config_rss_pf(sc, &sc->rss_conf_obj, config_hash)); 11533 } 11534 11535 static int 11536 bxe_init_rss_pf(struct bxe_softc *sc) 11537 { 11538 uint8_t num_eth_queues = BXE_NUM_ETH_QUEUES(sc); 11539 int i; 11540 11541 /* 11542 * Prepare the initial contents of the indirection table if 11543 * RSS is enabled 11544 */ 11545 for (i = 0; i < sizeof(sc->rss_conf_obj.ind_table); i++) { 11546 sc->rss_conf_obj.ind_table[i] = 11547 (sc->fp->cl_id + (i % num_eth_queues)); 11548 } 11549 11550 if (sc->udp_rss) { 11551 sc->rss_conf_obj.udp_rss_v4 = sc->rss_conf_obj.udp_rss_v6 = 1; 11552 } 11553 11554 /* 11555 * For 57710 and 57711 SEARCHER configuration (rss_keys) is 11556 * per-port, so if explicit configuration is needed, do it only 11557 * for a PMF. 11558 * 11559 * For 57712 and newer it's a per-function configuration. 11560 */ 11561 return (bxe_config_rss_eth(sc, sc->port.pmf || !CHIP_IS_E1x(sc))); 11562 } 11563 11564 static int 11565 bxe_set_mac_one(struct bxe_softc *sc, 11566 uint8_t *mac, 11567 struct ecore_vlan_mac_obj *obj, 11568 uint8_t set, 11569 int mac_type, 11570 unsigned long *ramrod_flags) 11571 { 11572 struct ecore_vlan_mac_ramrod_params ramrod_param; 11573 int rc; 11574 11575 memset(&ramrod_param, 0, sizeof(ramrod_param)); 11576 11577 /* fill in general parameters */ 11578 ramrod_param.vlan_mac_obj = obj; 11579 ramrod_param.ramrod_flags = *ramrod_flags; 11580 11581 /* fill a user request section if needed */ 11582 if (!bxe_test_bit(RAMROD_CONT, ramrod_flags)) { 11583 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN); 11584 11585 bxe_set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags); 11586 11587 /* Set the command: ADD or DEL */ 11588 ramrod_param.user_req.cmd = (set) ? ECORE_VLAN_MAC_ADD : 11589 ECORE_VLAN_MAC_DEL; 11590 } 11591 11592 rc = ecore_config_vlan_mac(sc, &ramrod_param); 11593 11594 if (rc == ECORE_EXISTS) { 11595 BLOGD(sc, DBG_SP, "Failed to schedule ADD operations (EEXIST)\n"); 11596 /* do not treat adding same MAC as error */ 11597 rc = 0; 11598 } else if (rc < 0) { 11599 BLOGE(sc, "%s MAC failed (%d)\n", (set ? "Set" : "Delete"), rc); 11600 } 11601 11602 return (rc); 11603 } 11604 11605 static int 11606 bxe_set_eth_mac(struct bxe_softc *sc, 11607 uint8_t set) 11608 { 11609 unsigned long ramrod_flags = 0; 11610 11611 BLOGD(sc, DBG_LOAD, "Adding Ethernet MAC\n"); 11612 11613 bxe_set_bit(RAMROD_COMP_WAIT, &ramrod_flags); 11614 11615 /* Eth MAC is set on RSS leading client (fp[0]) */ 11616 return (bxe_set_mac_one(sc, sc->link_params.mac_addr, 11617 &sc->sp_objs->mac_obj, 11618 set, ECORE_ETH_MAC, &ramrod_flags)); 11619 } 11620 11621 static int 11622 bxe_get_cur_phy_idx(struct bxe_softc *sc) 11623 { 11624 uint32_t sel_phy_idx = 0; 11625 11626 if (sc->link_params.num_phys <= 1) { 11627 return (ELINK_INT_PHY); 11628 } 11629 11630 if (sc->link_vars.link_up) { 11631 sel_phy_idx = ELINK_EXT_PHY1; 11632 /* In case link is SERDES, check if the ELINK_EXT_PHY2 is the one */ 11633 if ((sc->link_vars.link_status & LINK_STATUS_SERDES_LINK) && 11634 (sc->link_params.phy[ELINK_EXT_PHY2].supported & 11635 ELINK_SUPPORTED_FIBRE)) 11636 sel_phy_idx = ELINK_EXT_PHY2; 11637 } else { 11638 switch (elink_phy_selection(&sc->link_params)) { 11639 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT: 11640 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY: 11641 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY: 11642 sel_phy_idx = ELINK_EXT_PHY1; 11643 break; 11644 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY: 11645 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY: 11646 sel_phy_idx = ELINK_EXT_PHY2; 11647 break; 11648 } 11649 } 11650 11651 return (sel_phy_idx); 11652 } 11653 11654 static int 11655 bxe_get_link_cfg_idx(struct bxe_softc *sc) 11656 { 11657 uint32_t sel_phy_idx = bxe_get_cur_phy_idx(sc); 11658 11659 /* 11660 * The selected activated PHY is always after swapping (in case PHY 11661 * swapping is enabled). So when swapping is enabled, we need to reverse 11662 * the configuration 11663 */ 11664 11665 if (sc->link_params.multi_phy_config & PORT_HW_CFG_PHY_SWAPPED_ENABLED) { 11666 if (sel_phy_idx == ELINK_EXT_PHY1) 11667 sel_phy_idx = ELINK_EXT_PHY2; 11668 else if (sel_phy_idx == ELINK_EXT_PHY2) 11669 sel_phy_idx = ELINK_EXT_PHY1; 11670 } 11671 11672 return (ELINK_LINK_CONFIG_IDX(sel_phy_idx)); 11673 } 11674 11675 static void 11676 bxe_set_requested_fc(struct bxe_softc *sc) 11677 { 11678 /* 11679 * Initialize link parameters structure variables 11680 * It is recommended to turn off RX FC for jumbo frames 11681 * for better performance 11682 */ 11683 if (CHIP_IS_E1x(sc) && (sc->mtu > 5000)) { 11684 sc->link_params.req_fc_auto_adv = ELINK_FLOW_CTRL_TX; 11685 } else { 11686 sc->link_params.req_fc_auto_adv = ELINK_FLOW_CTRL_BOTH; 11687 } 11688 } 11689 11690 static void 11691 bxe_calc_fc_adv(struct bxe_softc *sc) 11692 { 11693 uint8_t cfg_idx = bxe_get_link_cfg_idx(sc); 11694 11695 11696 sc->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause | 11697 ADVERTISED_Pause); 11698 11699 switch (sc->link_vars.ieee_fc & 11700 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) { 11701 11702 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH: 11703 sc->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause | 11704 ADVERTISED_Pause); 11705 break; 11706 11707 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC: 11708 sc->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause; 11709 break; 11710 11711 default: 11712 break; 11713 11714 } 11715 } 11716 11717 static uint16_t 11718 bxe_get_mf_speed(struct bxe_softc *sc) 11719 { 11720 uint16_t line_speed = sc->link_vars.line_speed; 11721 if (IS_MF(sc)) { 11722 uint16_t maxCfg = 11723 bxe_extract_max_cfg(sc, sc->devinfo.mf_info.mf_config[SC_VN(sc)]); 11724 11725 /* calculate the current MAX line speed limit for the MF devices */ 11726 if (IS_MF_SI(sc)) { 11727 line_speed = (line_speed * maxCfg) / 100; 11728 } else { /* SD mode */ 11729 uint16_t vn_max_rate = maxCfg * 100; 11730 11731 if (vn_max_rate < line_speed) { 11732 line_speed = vn_max_rate; 11733 } 11734 } 11735 } 11736 11737 return (line_speed); 11738 } 11739 11740 static void 11741 bxe_fill_report_data(struct bxe_softc *sc, 11742 struct bxe_link_report_data *data) 11743 { 11744 uint16_t line_speed = bxe_get_mf_speed(sc); 11745 11746 memset(data, 0, sizeof(*data)); 11747 11748 /* fill the report data with the effective line speed */ 11749 data->line_speed = line_speed; 11750 11751 /* Link is down */ 11752 if (!sc->link_vars.link_up || (sc->flags & BXE_MF_FUNC_DIS)) { 11753 bxe_set_bit(BXE_LINK_REPORT_LINK_DOWN, &data->link_report_flags); 11754 } 11755 11756 /* Full DUPLEX */ 11757 if (sc->link_vars.duplex == DUPLEX_FULL) { 11758 bxe_set_bit(BXE_LINK_REPORT_FULL_DUPLEX, &data->link_report_flags); 11759 } 11760 11761 /* Rx Flow Control is ON */ 11762 if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_RX) { 11763 bxe_set_bit(BXE_LINK_REPORT_RX_FC_ON, &data->link_report_flags); 11764 } 11765 11766 /* Tx Flow Control is ON */ 11767 if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_TX) { 11768 bxe_set_bit(BXE_LINK_REPORT_TX_FC_ON, &data->link_report_flags); 11769 } 11770 } 11771 11772 /* report link status to OS, should be called under phy_lock */ 11773 static void 11774 bxe_link_report_locked(struct bxe_softc *sc) 11775 { 11776 struct bxe_link_report_data cur_data; 11777 11778 /* reread mf_cfg */ 11779 if (IS_PF(sc) && !CHIP_IS_E1(sc)) { 11780 bxe_read_mf_cfg(sc); 11781 } 11782 11783 /* Read the current link report info */ 11784 bxe_fill_report_data(sc, &cur_data); 11785 11786 /* Don't report link down or exactly the same link status twice */ 11787 if (!memcmp(&cur_data, &sc->last_reported_link, sizeof(cur_data)) || 11788 (bxe_test_bit(BXE_LINK_REPORT_LINK_DOWN, 11789 &sc->last_reported_link.link_report_flags) && 11790 bxe_test_bit(BXE_LINK_REPORT_LINK_DOWN, 11791 &cur_data.link_report_flags))) { 11792 return; 11793 } 11794 11795 ELINK_DEBUG_P2(sc, "Change in link status : cur_data = %x, last_reported_link = %x\n", 11796 cur_data.link_report_flags, sc->last_reported_link.link_report_flags); 11797 sc->link_cnt++; 11798 11799 ELINK_DEBUG_P1(sc, "link status change count = %x\n", sc->link_cnt); 11800 /* report new link params and remember the state for the next time */ 11801 memcpy(&sc->last_reported_link, &cur_data, sizeof(cur_data)); 11802 11803 if (bxe_test_bit(BXE_LINK_REPORT_LINK_DOWN, 11804 &cur_data.link_report_flags)) { 11805 if_link_state_change(sc->ifp, LINK_STATE_DOWN); 11806 } else { 11807 const char *duplex; 11808 const char *flow; 11809 11810 if (bxe_test_and_clear_bit(BXE_LINK_REPORT_FULL_DUPLEX, 11811 &cur_data.link_report_flags)) { 11812 duplex = "full"; 11813 ELINK_DEBUG_P0(sc, "link set to full duplex\n"); 11814 } else { 11815 duplex = "half"; 11816 ELINK_DEBUG_P0(sc, "link set to half duplex\n"); 11817 } 11818 11819 /* 11820 * Handle the FC at the end so that only these flags would be 11821 * possibly set. This way we may easily check if there is no FC 11822 * enabled. 11823 */ 11824 if (cur_data.link_report_flags) { 11825 if (bxe_test_bit(BXE_LINK_REPORT_RX_FC_ON, 11826 &cur_data.link_report_flags) && 11827 bxe_test_bit(BXE_LINK_REPORT_TX_FC_ON, 11828 &cur_data.link_report_flags)) { 11829 flow = "ON - receive & transmit"; 11830 } else if (bxe_test_bit(BXE_LINK_REPORT_RX_FC_ON, 11831 &cur_data.link_report_flags) && 11832 !bxe_test_bit(BXE_LINK_REPORT_TX_FC_ON, 11833 &cur_data.link_report_flags)) { 11834 flow = "ON - receive"; 11835 } else if (!bxe_test_bit(BXE_LINK_REPORT_RX_FC_ON, 11836 &cur_data.link_report_flags) && 11837 bxe_test_bit(BXE_LINK_REPORT_TX_FC_ON, 11838 &cur_data.link_report_flags)) { 11839 flow = "ON - transmit"; 11840 } else { 11841 flow = "none"; /* possible? */ 11842 } 11843 } else { 11844 flow = "none"; 11845 } 11846 11847 if_link_state_change(sc->ifp, LINK_STATE_UP); 11848 BLOGI(sc, "NIC Link is Up, %d Mbps %s duplex, Flow control: %s\n", 11849 cur_data.line_speed, duplex, flow); 11850 } 11851 } 11852 11853 static void 11854 bxe_link_report(struct bxe_softc *sc) 11855 { 11856 bxe_acquire_phy_lock(sc); 11857 bxe_link_report_locked(sc); 11858 bxe_release_phy_lock(sc); 11859 } 11860 11861 static void 11862 bxe_link_status_update(struct bxe_softc *sc) 11863 { 11864 if (sc->state != BXE_STATE_OPEN) { 11865 return; 11866 } 11867 11868 if (IS_PF(sc) && !CHIP_REV_IS_SLOW(sc)) { 11869 elink_link_status_update(&sc->link_params, &sc->link_vars); 11870 } else { 11871 sc->port.supported[0] |= (ELINK_SUPPORTED_10baseT_Half | 11872 ELINK_SUPPORTED_10baseT_Full | 11873 ELINK_SUPPORTED_100baseT_Half | 11874 ELINK_SUPPORTED_100baseT_Full | 11875 ELINK_SUPPORTED_1000baseT_Full | 11876 ELINK_SUPPORTED_2500baseX_Full | 11877 ELINK_SUPPORTED_10000baseT_Full | 11878 ELINK_SUPPORTED_TP | 11879 ELINK_SUPPORTED_FIBRE | 11880 ELINK_SUPPORTED_Autoneg | 11881 ELINK_SUPPORTED_Pause | 11882 ELINK_SUPPORTED_Asym_Pause); 11883 sc->port.advertising[0] = sc->port.supported[0]; 11884 11885 sc->link_params.sc = sc; 11886 sc->link_params.port = SC_PORT(sc); 11887 sc->link_params.req_duplex[0] = DUPLEX_FULL; 11888 sc->link_params.req_flow_ctrl[0] = ELINK_FLOW_CTRL_NONE; 11889 sc->link_params.req_line_speed[0] = SPEED_10000; 11890 sc->link_params.speed_cap_mask[0] = 0x7f0000; 11891 sc->link_params.switch_cfg = ELINK_SWITCH_CFG_10G; 11892 11893 if (CHIP_REV_IS_FPGA(sc)) { 11894 sc->link_vars.mac_type = ELINK_MAC_TYPE_EMAC; 11895 sc->link_vars.line_speed = ELINK_SPEED_1000; 11896 sc->link_vars.link_status = (LINK_STATUS_LINK_UP | 11897 LINK_STATUS_SPEED_AND_DUPLEX_1000TFD); 11898 } else { 11899 sc->link_vars.mac_type = ELINK_MAC_TYPE_BMAC; 11900 sc->link_vars.line_speed = ELINK_SPEED_10000; 11901 sc->link_vars.link_status = (LINK_STATUS_LINK_UP | 11902 LINK_STATUS_SPEED_AND_DUPLEX_10GTFD); 11903 } 11904 11905 sc->link_vars.link_up = 1; 11906 11907 sc->link_vars.duplex = DUPLEX_FULL; 11908 sc->link_vars.flow_ctrl = ELINK_FLOW_CTRL_NONE; 11909 11910 if (IS_PF(sc)) { 11911 REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + sc->link_params.port*4, 0); 11912 bxe_stats_handle(sc, STATS_EVENT_LINK_UP); 11913 bxe_link_report(sc); 11914 } 11915 } 11916 11917 if (IS_PF(sc)) { 11918 if (sc->link_vars.link_up) { 11919 bxe_stats_handle(sc, STATS_EVENT_LINK_UP); 11920 } else { 11921 bxe_stats_handle(sc, STATS_EVENT_STOP); 11922 } 11923 bxe_link_report(sc); 11924 } else { 11925 bxe_link_report(sc); 11926 bxe_stats_handle(sc, STATS_EVENT_LINK_UP); 11927 } 11928 } 11929 11930 static int 11931 bxe_initial_phy_init(struct bxe_softc *sc, 11932 int load_mode) 11933 { 11934 int rc, cfg_idx = bxe_get_link_cfg_idx(sc); 11935 uint16_t req_line_speed = sc->link_params.req_line_speed[cfg_idx]; 11936 struct elink_params *lp = &sc->link_params; 11937 11938 bxe_set_requested_fc(sc); 11939 11940 if (CHIP_REV_IS_SLOW(sc)) { 11941 uint32_t bond = CHIP_BOND_ID(sc); 11942 uint32_t feat = 0; 11943 11944 if (CHIP_IS_E2(sc) && CHIP_IS_MODE_4_PORT(sc)) { 11945 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_BMAC; 11946 } else if (bond & 0x4) { 11947 if (CHIP_IS_E3(sc)) { 11948 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_XMAC; 11949 } else { 11950 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_BMAC; 11951 } 11952 } else if (bond & 0x8) { 11953 if (CHIP_IS_E3(sc)) { 11954 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_UMAC; 11955 } else { 11956 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_EMAC; 11957 } 11958 } 11959 11960 /* disable EMAC for E3 and above */ 11961 if (bond & 0x2) { 11962 feat |= ELINK_FEATURE_CONFIG_EMUL_DISABLE_EMAC; 11963 } 11964 11965 sc->link_params.feature_config_flags |= feat; 11966 } 11967 11968 bxe_acquire_phy_lock(sc); 11969 11970 if (load_mode == LOAD_DIAG) { 11971 lp->loopback_mode = ELINK_LOOPBACK_XGXS; 11972 /* Prefer doing PHY loopback at 10G speed, if possible */ 11973 if (lp->req_line_speed[cfg_idx] < ELINK_SPEED_10000) { 11974 if (lp->speed_cap_mask[cfg_idx] & 11975 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) { 11976 lp->req_line_speed[cfg_idx] = ELINK_SPEED_10000; 11977 } else { 11978 lp->req_line_speed[cfg_idx] = ELINK_SPEED_1000; 11979 } 11980 } 11981 } 11982 11983 if (load_mode == LOAD_LOOPBACK_EXT) { 11984 lp->loopback_mode = ELINK_LOOPBACK_EXT; 11985 } 11986 11987 rc = elink_phy_init(&sc->link_params, &sc->link_vars); 11988 11989 bxe_release_phy_lock(sc); 11990 11991 bxe_calc_fc_adv(sc); 11992 11993 if (sc->link_vars.link_up) { 11994 bxe_stats_handle(sc, STATS_EVENT_LINK_UP); 11995 bxe_link_report(sc); 11996 } 11997 11998 if (!CHIP_REV_IS_SLOW(sc)) { 11999 bxe_periodic_start(sc); 12000 } 12001 12002 sc->link_params.req_line_speed[cfg_idx] = req_line_speed; 12003 return (rc); 12004 } 12005 12006 static u_int 12007 bxe_push_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt) 12008 { 12009 struct ecore_mcast_list_elem *mc_mac = arg; 12010 12011 mc_mac += cnt; 12012 mc_mac->mac = (uint8_t *)LLADDR(sdl); 12013 12014 return (1); 12015 } 12016 12017 static int 12018 bxe_init_mcast_macs_list(struct bxe_softc *sc, 12019 struct ecore_mcast_ramrod_params *p) 12020 { 12021 if_t ifp = sc->ifp; 12022 int mc_count; 12023 struct ecore_mcast_list_elem *mc_mac; 12024 12025 ECORE_LIST_INIT(&p->mcast_list); 12026 p->mcast_list_len = 0; 12027 12028 /* XXXGL: multicast count may change later */ 12029 mc_count = if_llmaddr_count(ifp); 12030 12031 if (!mc_count) { 12032 return (0); 12033 } 12034 12035 mc_mac = malloc(sizeof(*mc_mac) * mc_count, M_DEVBUF, 12036 (M_NOWAIT | M_ZERO)); 12037 if (!mc_mac) { 12038 BLOGE(sc, "Failed to allocate temp mcast list\n"); 12039 return (-1); 12040 } 12041 bzero(mc_mac, (sizeof(*mc_mac) * mc_count)); 12042 if_foreach_llmaddr(ifp, bxe_push_maddr, mc_mac); 12043 12044 for (int i = 0; i < mc_count; i ++) { 12045 ECORE_LIST_PUSH_TAIL(&mc_mac[i].link, &p->mcast_list); 12046 BLOGD(sc, DBG_LOAD, 12047 "Setting MCAST %02X:%02X:%02X:%02X:%02X:%02X and mc_count %d\n", 12048 mc_mac[i].mac[0], mc_mac[i].mac[1], mc_mac[i].mac[2], 12049 mc_mac[i].mac[3], mc_mac[i].mac[4], mc_mac[i].mac[5], 12050 mc_count); 12051 } 12052 12053 p->mcast_list_len = mc_count; 12054 12055 return (0); 12056 } 12057 12058 static void 12059 bxe_free_mcast_macs_list(struct ecore_mcast_ramrod_params *p) 12060 { 12061 struct ecore_mcast_list_elem *mc_mac = 12062 ECORE_LIST_FIRST_ENTRY(&p->mcast_list, 12063 struct ecore_mcast_list_elem, 12064 link); 12065 12066 if (mc_mac) { 12067 /* only a single free as all mc_macs are in the same heap array */ 12068 free(mc_mac, M_DEVBUF); 12069 } 12070 } 12071 static int 12072 bxe_set_mc_list(struct bxe_softc *sc) 12073 { 12074 struct ecore_mcast_ramrod_params rparam = { NULL }; 12075 int rc = 0; 12076 12077 rparam.mcast_obj = &sc->mcast_obj; 12078 12079 BXE_MCAST_LOCK(sc); 12080 12081 /* first, clear all configured multicast MACs */ 12082 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL); 12083 if (rc < 0) { 12084 BLOGE(sc, "Failed to clear multicast configuration: %d\n", rc); 12085 /* Manual backport parts of FreeBSD upstream r284470. */ 12086 BXE_MCAST_UNLOCK(sc); 12087 return (rc); 12088 } 12089 12090 /* configure a new MACs list */ 12091 rc = bxe_init_mcast_macs_list(sc, &rparam); 12092 if (rc) { 12093 BLOGE(sc, "Failed to create mcast MACs list (%d)\n", rc); 12094 BXE_MCAST_UNLOCK(sc); 12095 return (rc); 12096 } 12097 12098 /* Now add the new MACs */ 12099 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_ADD); 12100 if (rc < 0) { 12101 BLOGE(sc, "Failed to set new mcast config (%d)\n", rc); 12102 } 12103 12104 bxe_free_mcast_macs_list(&rparam); 12105 12106 BXE_MCAST_UNLOCK(sc); 12107 12108 return (rc); 12109 } 12110 12111 struct bxe_set_addr_ctx { 12112 struct bxe_softc *sc; 12113 unsigned long ramrod_flags; 12114 int rc; 12115 }; 12116 12117 static u_int 12118 bxe_set_addr(void *arg, struct sockaddr_dl *sdl, u_int cnt) 12119 { 12120 struct bxe_set_addr_ctx *ctx = arg; 12121 struct ecore_vlan_mac_obj *mac_obj = &ctx->sc->sp_objs->mac_obj; 12122 int rc; 12123 12124 if (ctx->rc < 0) 12125 return (0); 12126 12127 rc = bxe_set_mac_one(ctx->sc, (uint8_t *)LLADDR(sdl), mac_obj, TRUE, 12128 ECORE_UC_LIST_MAC, &ctx->ramrod_flags); 12129 12130 /* do not treat adding same MAC as an error */ 12131 if (rc == -EEXIST) 12132 BLOGD(ctx->sc, DBG_SP, "Failed to schedule ADD operations (EEXIST)\n"); 12133 else if (rc < 0) { 12134 BLOGE(ctx->sc, "Failed to schedule ADD operations (%d)\n", rc); 12135 ctx->rc = rc; 12136 } 12137 12138 return (1); 12139 } 12140 12141 static int 12142 bxe_set_uc_list(struct bxe_softc *sc) 12143 { 12144 if_t ifp = sc->ifp; 12145 struct ecore_vlan_mac_obj *mac_obj = &sc->sp_objs->mac_obj; 12146 struct bxe_set_addr_ctx ctx = { sc, 0, 0 }; 12147 int rc; 12148 12149 /* first schedule a cleanup up of old configuration */ 12150 rc = bxe_del_all_macs(sc, mac_obj, ECORE_UC_LIST_MAC, FALSE); 12151 if (rc < 0) { 12152 BLOGE(sc, "Failed to schedule delete of all ETH MACs (%d)\n", rc); 12153 return (rc); 12154 } 12155 12156 if_foreach_lladdr(ifp, bxe_set_addr, &ctx); 12157 if (ctx.rc < 0) 12158 return (ctx.rc); 12159 12160 /* Execute the pending commands */ 12161 bit_set(&ctx.ramrod_flags, RAMROD_CONT); 12162 return (bxe_set_mac_one(sc, NULL, mac_obj, FALSE /* don't care */, 12163 ECORE_UC_LIST_MAC, &ctx.ramrod_flags)); 12164 } 12165 12166 static void 12167 bxe_set_rx_mode(struct bxe_softc *sc) 12168 { 12169 if_t ifp = sc->ifp; 12170 uint32_t rx_mode = BXE_RX_MODE_NORMAL; 12171 12172 if (sc->state != BXE_STATE_OPEN) { 12173 BLOGD(sc, DBG_SP, "state is %x, returning\n", sc->state); 12174 return; 12175 } 12176 12177 BLOGD(sc, DBG_SP, "if_flags(ifp)=0x%x\n", if_getflags(sc->ifp)); 12178 12179 if (if_getflags(ifp) & IFF_PROMISC) { 12180 rx_mode = BXE_RX_MODE_PROMISC; 12181 } else if ((if_getflags(ifp) & IFF_ALLMULTI) || 12182 (if_llmaddr_count(ifp) > BXE_MAX_MULTICAST && 12183 CHIP_IS_E1(sc))) { 12184 rx_mode = BXE_RX_MODE_ALLMULTI; 12185 } else { 12186 if (IS_PF(sc)) { 12187 /* some multicasts */ 12188 if (bxe_set_mc_list(sc) < 0) { 12189 rx_mode = BXE_RX_MODE_ALLMULTI; 12190 } 12191 if (bxe_set_uc_list(sc) < 0) { 12192 rx_mode = BXE_RX_MODE_PROMISC; 12193 } 12194 } 12195 } 12196 12197 sc->rx_mode = rx_mode; 12198 12199 /* schedule the rx_mode command */ 12200 if (bxe_test_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state)) { 12201 BLOGD(sc, DBG_LOAD, "Scheduled setting rx_mode with ECORE...\n"); 12202 bxe_set_bit(ECORE_FILTER_RX_MODE_SCHED, &sc->sp_state); 12203 return; 12204 } 12205 12206 if (IS_PF(sc)) { 12207 bxe_set_storm_rx_mode(sc); 12208 } 12209 } 12210 12211 12212 /* update flags in shmem */ 12213 static void 12214 bxe_update_drv_flags(struct bxe_softc *sc, 12215 uint32_t flags, 12216 uint32_t set) 12217 { 12218 uint32_t drv_flags; 12219 12220 if (SHMEM2_HAS(sc, drv_flags)) { 12221 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_DRV_FLAGS); 12222 drv_flags = SHMEM2_RD(sc, drv_flags); 12223 12224 if (set) { 12225 SET_FLAGS(drv_flags, flags); 12226 } else { 12227 RESET_FLAGS(drv_flags, flags); 12228 } 12229 12230 SHMEM2_WR(sc, drv_flags, drv_flags); 12231 BLOGD(sc, DBG_LOAD, "drv_flags 0x%08x\n", drv_flags); 12232 12233 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_DRV_FLAGS); 12234 } 12235 } 12236 12237 /* periodic timer callout routine, only runs when the interface is up */ 12238 12239 static void 12240 bxe_periodic_callout_func(void *xsc) 12241 { 12242 struct bxe_softc *sc = (struct bxe_softc *)xsc; 12243 int i; 12244 12245 if (!BXE_CORE_TRYLOCK(sc)) { 12246 /* just bail and try again next time */ 12247 12248 if ((sc->state == BXE_STATE_OPEN) && 12249 (atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_GO)) { 12250 /* schedule the next periodic callout */ 12251 callout_reset(&sc->periodic_callout, hz, 12252 bxe_periodic_callout_func, sc); 12253 } 12254 12255 return; 12256 } 12257 12258 if ((sc->state != BXE_STATE_OPEN) || 12259 (atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_STOP)) { 12260 BLOGW(sc, "periodic callout exit (state=0x%x)\n", sc->state); 12261 BXE_CORE_UNLOCK(sc); 12262 return; 12263 } 12264 12265 12266 /* Check for TX timeouts on any fastpath. */ 12267 FOR_EACH_QUEUE(sc, i) { 12268 if (bxe_watchdog(sc, &sc->fp[i]) != 0) { 12269 /* Ruh-Roh, chip was reset! */ 12270 break; 12271 } 12272 } 12273 12274 if (!CHIP_REV_IS_SLOW(sc)) { 12275 /* 12276 * This barrier is needed to ensure the ordering between the writing 12277 * to the sc->port.pmf in the bxe_nic_load() or bxe_pmf_update() and 12278 * the reading here. 12279 */ 12280 mb(); 12281 if (sc->port.pmf) { 12282 bxe_acquire_phy_lock(sc); 12283 elink_period_func(&sc->link_params, &sc->link_vars); 12284 bxe_release_phy_lock(sc); 12285 } 12286 } 12287 12288 if (IS_PF(sc) && !(sc->flags & BXE_NO_PULSE)) { 12289 int mb_idx = SC_FW_MB_IDX(sc); 12290 uint32_t drv_pulse; 12291 uint32_t mcp_pulse; 12292 12293 ++sc->fw_drv_pulse_wr_seq; 12294 sc->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK; 12295 12296 drv_pulse = sc->fw_drv_pulse_wr_seq; 12297 bxe_drv_pulse(sc); 12298 12299 mcp_pulse = (SHMEM_RD(sc, func_mb[mb_idx].mcp_pulse_mb) & 12300 MCP_PULSE_SEQ_MASK); 12301 12302 /* 12303 * The delta between driver pulse and mcp response should 12304 * be 1 (before mcp response) or 0 (after mcp response). 12305 */ 12306 if ((drv_pulse != mcp_pulse) && 12307 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) { 12308 /* someone lost a heartbeat... */ 12309 BLOGE(sc, "drv_pulse (0x%x) != mcp_pulse (0x%x)\n", 12310 drv_pulse, mcp_pulse); 12311 } 12312 } 12313 12314 /* state is BXE_STATE_OPEN */ 12315 bxe_stats_handle(sc, STATS_EVENT_UPDATE); 12316 12317 BXE_CORE_UNLOCK(sc); 12318 12319 if ((sc->state == BXE_STATE_OPEN) && 12320 (atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_GO)) { 12321 /* schedule the next periodic callout */ 12322 callout_reset(&sc->periodic_callout, hz, 12323 bxe_periodic_callout_func, sc); 12324 } 12325 } 12326 12327 static void 12328 bxe_periodic_start(struct bxe_softc *sc) 12329 { 12330 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_GO); 12331 callout_reset(&sc->periodic_callout, hz, bxe_periodic_callout_func, sc); 12332 } 12333 12334 static void 12335 bxe_periodic_stop(struct bxe_softc *sc) 12336 { 12337 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_STOP); 12338 callout_drain(&sc->periodic_callout); 12339 } 12340 12341 void 12342 bxe_parity_recover(struct bxe_softc *sc) 12343 { 12344 uint8_t global = FALSE; 12345 uint32_t error_recovered, error_unrecovered; 12346 12347 12348 if ((sc->recovery_state == BXE_RECOVERY_FAILED) && 12349 (sc->state == BXE_STATE_ERROR)) { 12350 BLOGE(sc, "RECOVERY failed, " 12351 "stack notified driver is NOT running! " 12352 "Please reboot/power cycle the system.\n"); 12353 return; 12354 } 12355 12356 while (1) { 12357 BLOGD(sc, DBG_SP, 12358 "%s sc=%p state=0x%x rec_state=0x%x error_status=%x\n", 12359 __func__, sc, sc->state, sc->recovery_state, sc->error_status); 12360 12361 switch(sc->recovery_state) { 12362 12363 case BXE_RECOVERY_INIT: 12364 bxe_chk_parity_attn(sc, &global, FALSE); 12365 12366 if ((CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) || 12367 (sc->error_status & BXE_ERR_MCP_ASSERT) || 12368 (sc->error_status & BXE_ERR_GLOBAL)) { 12369 12370 BXE_CORE_LOCK(sc); 12371 if (if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING) { 12372 bxe_periodic_stop(sc); 12373 } 12374 bxe_nic_unload(sc, UNLOAD_RECOVERY, false); 12375 sc->state = BXE_STATE_ERROR; 12376 sc->recovery_state = BXE_RECOVERY_FAILED; 12377 BLOGE(sc, " No Recovery tried for error 0x%x" 12378 " stack notified driver is NOT running!" 12379 " Please reboot/power cycle the system.\n", 12380 sc->error_status); 12381 BXE_CORE_UNLOCK(sc); 12382 return; 12383 } 12384 12385 12386 /* Try to get a LEADER_LOCK HW lock */ 12387 if (bxe_trylock_leader_lock(sc)) { 12388 12389 bxe_set_reset_in_progress(sc); 12390 /* 12391 * Check if there is a global attention and if 12392 * there was a global attention, set the global 12393 * reset bit. 12394 */ 12395 if (global) { 12396 bxe_set_reset_global(sc); 12397 } 12398 sc->is_leader = 1; 12399 } 12400 12401 /* If interface has been removed - break */ 12402 12403 if (if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING) { 12404 bxe_periodic_stop(sc); 12405 } 12406 12407 BXE_CORE_LOCK(sc); 12408 bxe_nic_unload(sc,UNLOAD_RECOVERY, false); 12409 sc->recovery_state = BXE_RECOVERY_WAIT; 12410 BXE_CORE_UNLOCK(sc); 12411 12412 /* 12413 * Ensure "is_leader", MCP command sequence and 12414 * "recovery_state" update values are seen on other 12415 * CPUs. 12416 */ 12417 mb(); 12418 break; 12419 case BXE_RECOVERY_WAIT: 12420 12421 if (sc->is_leader) { 12422 int other_engine = SC_PATH(sc) ? 0 : 1; 12423 bool other_load_status = 12424 bxe_get_load_status(sc, other_engine); 12425 bool load_status = 12426 bxe_get_load_status(sc, SC_PATH(sc)); 12427 global = bxe_reset_is_global(sc); 12428 12429 /* 12430 * In case of a parity in a global block, let 12431 * the first leader that performs a 12432 * leader_reset() reset the global blocks in 12433 * order to clear global attentions. Otherwise 12434 * the gates will remain closed for that 12435 * engine. 12436 */ 12437 if (load_status || 12438 (global && other_load_status)) { 12439 /* 12440 * Wait until all other functions get 12441 * down. 12442 */ 12443 taskqueue_enqueue_timeout(taskqueue_thread, 12444 &sc->sp_err_timeout_task, hz/10); 12445 return; 12446 } else { 12447 /* 12448 * If all other functions got down 12449 * try to bring the chip back to 12450 * normal. In any case it's an exit 12451 * point for a leader. 12452 */ 12453 if (bxe_leader_reset(sc)) { 12454 BLOGE(sc, "RECOVERY failed, " 12455 "stack notified driver is NOT running!\n"); 12456 sc->recovery_state = BXE_RECOVERY_FAILED; 12457 sc->state = BXE_STATE_ERROR; 12458 mb(); 12459 return; 12460 } 12461 12462 /* 12463 * If we are here, means that the 12464 * leader has succeeded and doesn't 12465 * want to be a leader any more. Try 12466 * to continue as a none-leader. 12467 */ 12468 break; 12469 } 12470 12471 } else { /* non-leader */ 12472 if (!bxe_reset_is_done(sc, SC_PATH(sc))) { 12473 /* 12474 * Try to get a LEADER_LOCK HW lock as 12475 * long as a former leader may have 12476 * been unloaded by the user or 12477 * released a leadership by another 12478 * reason. 12479 */ 12480 if (bxe_trylock_leader_lock(sc)) { 12481 /* 12482 * I'm a leader now! Restart a 12483 * switch case. 12484 */ 12485 sc->is_leader = 1; 12486 break; 12487 } 12488 12489 taskqueue_enqueue_timeout(taskqueue_thread, 12490 &sc->sp_err_timeout_task, hz/10); 12491 return; 12492 12493 } else { 12494 /* 12495 * If there was a global attention, wait 12496 * for it to be cleared. 12497 */ 12498 if (bxe_reset_is_global(sc)) { 12499 taskqueue_enqueue_timeout(taskqueue_thread, 12500 &sc->sp_err_timeout_task, hz/10); 12501 return; 12502 } 12503 12504 error_recovered = 12505 sc->eth_stats.recoverable_error; 12506 error_unrecovered = 12507 sc->eth_stats.unrecoverable_error; 12508 BXE_CORE_LOCK(sc); 12509 sc->recovery_state = 12510 BXE_RECOVERY_NIC_LOADING; 12511 if (bxe_nic_load(sc, LOAD_NORMAL)) { 12512 error_unrecovered++; 12513 sc->recovery_state = BXE_RECOVERY_FAILED; 12514 sc->state = BXE_STATE_ERROR; 12515 BLOGE(sc, "Recovery is NOT successful, " 12516 " state=0x%x recovery_state=0x%x error=%x\n", 12517 sc->state, sc->recovery_state, sc->error_status); 12518 sc->error_status = 0; 12519 } else { 12520 sc->recovery_state = 12521 BXE_RECOVERY_DONE; 12522 error_recovered++; 12523 BLOGI(sc, "Recovery is successful from errors %x," 12524 " state=0x%x" 12525 " recovery_state=0x%x \n", sc->error_status, 12526 sc->state, sc->recovery_state); 12527 mb(); 12528 } 12529 sc->error_status = 0; 12530 BXE_CORE_UNLOCK(sc); 12531 sc->eth_stats.recoverable_error = 12532 error_recovered; 12533 sc->eth_stats.unrecoverable_error = 12534 error_unrecovered; 12535 12536 return; 12537 } 12538 } 12539 default: 12540 return; 12541 } 12542 } 12543 } 12544 void 12545 bxe_handle_error(struct bxe_softc * sc) 12546 { 12547 12548 if(sc->recovery_state == BXE_RECOVERY_WAIT) { 12549 return; 12550 } 12551 if(sc->error_status) { 12552 if (sc->state == BXE_STATE_OPEN) { 12553 bxe_int_disable(sc); 12554 } 12555 if (sc->link_vars.link_up) { 12556 if_link_state_change(sc->ifp, LINK_STATE_DOWN); 12557 } 12558 sc->recovery_state = BXE_RECOVERY_INIT; 12559 BLOGI(sc, "bxe%d: Recovery started errors 0x%x recovery state 0x%x\n", 12560 sc->unit, sc->error_status, sc->recovery_state); 12561 bxe_parity_recover(sc); 12562 } 12563 } 12564 12565 static void 12566 bxe_sp_err_timeout_task(void *arg, int pending) 12567 { 12568 12569 struct bxe_softc *sc = (struct bxe_softc *)arg; 12570 12571 BLOGD(sc, DBG_SP, 12572 "%s state = 0x%x rec state=0x%x error_status=%x\n", 12573 __func__, sc->state, sc->recovery_state, sc->error_status); 12574 12575 if((sc->recovery_state == BXE_RECOVERY_FAILED) && 12576 (sc->state == BXE_STATE_ERROR)) { 12577 return; 12578 } 12579 /* if can be taken */ 12580 if ((sc->error_status) && (sc->trigger_grcdump)) { 12581 bxe_grc_dump(sc); 12582 } 12583 if (sc->recovery_state != BXE_RECOVERY_DONE) { 12584 bxe_handle_error(sc); 12585 bxe_parity_recover(sc); 12586 } else if (sc->error_status) { 12587 bxe_handle_error(sc); 12588 } 12589 12590 return; 12591 } 12592 12593 /* start the controller */ 12594 static __noinline int 12595 bxe_nic_load(struct bxe_softc *sc, 12596 int load_mode) 12597 { 12598 uint32_t val; 12599 int load_code = 0; 12600 int i, rc = 0; 12601 12602 BXE_CORE_LOCK_ASSERT(sc); 12603 12604 BLOGD(sc, DBG_LOAD, "Starting NIC load...\n"); 12605 12606 sc->state = BXE_STATE_OPENING_WAITING_LOAD; 12607 12608 if (IS_PF(sc)) { 12609 /* must be called before memory allocation and HW init */ 12610 bxe_ilt_set_info(sc); 12611 } 12612 12613 sc->last_reported_link_state = LINK_STATE_UNKNOWN; 12614 12615 bxe_set_fp_rx_buf_size(sc); 12616 12617 if (bxe_alloc_fp_buffers(sc) != 0) { 12618 BLOGE(sc, "Failed to allocate fastpath memory\n"); 12619 sc->state = BXE_STATE_CLOSED; 12620 rc = ENOMEM; 12621 goto bxe_nic_load_error0; 12622 } 12623 12624 if (bxe_alloc_mem(sc) != 0) { 12625 sc->state = BXE_STATE_CLOSED; 12626 rc = ENOMEM; 12627 goto bxe_nic_load_error0; 12628 } 12629 12630 if (bxe_alloc_fw_stats_mem(sc) != 0) { 12631 sc->state = BXE_STATE_CLOSED; 12632 rc = ENOMEM; 12633 goto bxe_nic_load_error0; 12634 } 12635 12636 if (IS_PF(sc)) { 12637 /* set pf load just before approaching the MCP */ 12638 bxe_set_pf_load(sc); 12639 12640 /* if MCP exists send load request and analyze response */ 12641 if (!BXE_NOMCP(sc)) { 12642 /* attempt to load pf */ 12643 if (bxe_nic_load_request(sc, &load_code) != 0) { 12644 sc->state = BXE_STATE_CLOSED; 12645 rc = ENXIO; 12646 goto bxe_nic_load_error1; 12647 } 12648 12649 /* what did the MCP say? */ 12650 if (bxe_nic_load_analyze_req(sc, load_code) != 0) { 12651 bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0); 12652 sc->state = BXE_STATE_CLOSED; 12653 rc = ENXIO; 12654 goto bxe_nic_load_error2; 12655 } 12656 } else { 12657 BLOGI(sc, "Device has no MCP!\n"); 12658 load_code = bxe_nic_load_no_mcp(sc); 12659 } 12660 12661 /* mark PMF if applicable */ 12662 bxe_nic_load_pmf(sc, load_code); 12663 12664 /* Init Function state controlling object */ 12665 bxe_init_func_obj(sc); 12666 12667 /* Initialize HW */ 12668 if (bxe_init_hw(sc, load_code) != 0) { 12669 BLOGE(sc, "HW init failed\n"); 12670 bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0); 12671 sc->state = BXE_STATE_CLOSED; 12672 rc = ENXIO; 12673 goto bxe_nic_load_error2; 12674 } 12675 } 12676 12677 /* set ALWAYS_ALIVE bit in shmem */ 12678 sc->fw_drv_pulse_wr_seq |= DRV_PULSE_ALWAYS_ALIVE; 12679 bxe_drv_pulse(sc); 12680 sc->flags |= BXE_NO_PULSE; 12681 12682 /* attach interrupts */ 12683 if (bxe_interrupt_attach(sc) != 0) { 12684 sc->state = BXE_STATE_CLOSED; 12685 rc = ENXIO; 12686 goto bxe_nic_load_error2; 12687 } 12688 12689 bxe_nic_init(sc, load_code); 12690 12691 /* Init per-function objects */ 12692 if (IS_PF(sc)) { 12693 bxe_init_objs(sc); 12694 // XXX bxe_iov_nic_init(sc); 12695 12696 /* set AFEX default VLAN tag to an invalid value */ 12697 sc->devinfo.mf_info.afex_def_vlan_tag = -1; 12698 // XXX bxe_nic_load_afex_dcc(sc, load_code); 12699 12700 sc->state = BXE_STATE_OPENING_WAITING_PORT; 12701 rc = bxe_func_start(sc); 12702 if (rc) { 12703 BLOGE(sc, "Function start failed! rc = %d\n", rc); 12704 bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0); 12705 sc->state = BXE_STATE_ERROR; 12706 goto bxe_nic_load_error3; 12707 } 12708 12709 /* send LOAD_DONE command to MCP */ 12710 if (!BXE_NOMCP(sc)) { 12711 load_code = bxe_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0); 12712 if (!load_code) { 12713 BLOGE(sc, "MCP response failure, aborting\n"); 12714 sc->state = BXE_STATE_ERROR; 12715 rc = ENXIO; 12716 goto bxe_nic_load_error3; 12717 } 12718 } 12719 12720 rc = bxe_setup_leading(sc); 12721 if (rc) { 12722 BLOGE(sc, "Setup leading failed! rc = %d\n", rc); 12723 sc->state = BXE_STATE_ERROR; 12724 goto bxe_nic_load_error3; 12725 } 12726 12727 FOR_EACH_NONDEFAULT_ETH_QUEUE(sc, i) { 12728 rc = bxe_setup_queue(sc, &sc->fp[i], FALSE); 12729 if (rc) { 12730 BLOGE(sc, "Queue(%d) setup failed rc = %d\n", i, rc); 12731 sc->state = BXE_STATE_ERROR; 12732 goto bxe_nic_load_error3; 12733 } 12734 } 12735 12736 rc = bxe_init_rss_pf(sc); 12737 if (rc) { 12738 BLOGE(sc, "PF RSS init failed\n"); 12739 sc->state = BXE_STATE_ERROR; 12740 goto bxe_nic_load_error3; 12741 } 12742 } 12743 /* XXX VF */ 12744 12745 /* now when Clients are configured we are ready to work */ 12746 sc->state = BXE_STATE_OPEN; 12747 12748 /* Configure a ucast MAC */ 12749 if (IS_PF(sc)) { 12750 rc = bxe_set_eth_mac(sc, TRUE); 12751 } 12752 if (rc) { 12753 BLOGE(sc, "Setting Ethernet MAC failed rc = %d\n", rc); 12754 sc->state = BXE_STATE_ERROR; 12755 goto bxe_nic_load_error3; 12756 } 12757 12758 if (sc->port.pmf) { 12759 rc = bxe_initial_phy_init(sc, /* XXX load_mode */LOAD_OPEN); 12760 if (rc) { 12761 sc->state = BXE_STATE_ERROR; 12762 goto bxe_nic_load_error3; 12763 } 12764 } 12765 12766 sc->link_params.feature_config_flags &= 12767 ~ELINK_FEATURE_CONFIG_BOOT_FROM_SAN; 12768 12769 /* start fast path */ 12770 12771 /* Initialize Rx filter */ 12772 bxe_set_rx_mode(sc); 12773 12774 /* start the Tx */ 12775 switch (/* XXX load_mode */LOAD_OPEN) { 12776 case LOAD_NORMAL: 12777 case LOAD_OPEN: 12778 break; 12779 12780 case LOAD_DIAG: 12781 case LOAD_LOOPBACK_EXT: 12782 sc->state = BXE_STATE_DIAG; 12783 break; 12784 12785 default: 12786 break; 12787 } 12788 12789 if (sc->port.pmf) { 12790 bxe_update_drv_flags(sc, 1 << DRV_FLAGS_PORT_MASK, 0); 12791 } else { 12792 bxe_link_status_update(sc); 12793 } 12794 12795 /* start the periodic timer callout */ 12796 bxe_periodic_start(sc); 12797 12798 if (IS_PF(sc) && SHMEM2_HAS(sc, drv_capabilities_flag)) { 12799 /* mark driver is loaded in shmem2 */ 12800 val = SHMEM2_RD(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)]); 12801 SHMEM2_WR(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)], 12802 (val | 12803 DRV_FLAGS_CAPABILITIES_LOADED_SUPPORTED | 12804 DRV_FLAGS_CAPABILITIES_LOADED_L2)); 12805 } 12806 12807 /* wait for all pending SP commands to complete */ 12808 if (IS_PF(sc) && !bxe_wait_sp_comp(sc, ~0x0UL)) { 12809 BLOGE(sc, "Timeout waiting for all SPs to complete!\n"); 12810 bxe_periodic_stop(sc); 12811 bxe_nic_unload(sc, UNLOAD_CLOSE, FALSE); 12812 return (ENXIO); 12813 } 12814 12815 /* Tell the stack the driver is running! */ 12816 if_setdrvflags(sc->ifp, IFF_DRV_RUNNING); 12817 12818 BLOGD(sc, DBG_LOAD, "NIC successfully loaded\n"); 12819 12820 return (0); 12821 12822 bxe_nic_load_error3: 12823 12824 if (IS_PF(sc)) { 12825 bxe_int_disable_sync(sc, 1); 12826 12827 /* clean out queued objects */ 12828 bxe_squeeze_objects(sc); 12829 } 12830 12831 bxe_interrupt_detach(sc); 12832 12833 bxe_nic_load_error2: 12834 12835 if (IS_PF(sc) && !BXE_NOMCP(sc)) { 12836 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0); 12837 bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, 0); 12838 } 12839 12840 sc->port.pmf = 0; 12841 12842 bxe_nic_load_error1: 12843 12844 /* clear pf_load status, as it was already set */ 12845 if (IS_PF(sc)) { 12846 bxe_clear_pf_load(sc); 12847 } 12848 12849 bxe_nic_load_error0: 12850 12851 bxe_free_fw_stats_mem(sc); 12852 bxe_free_fp_buffers(sc); 12853 bxe_free_mem(sc); 12854 12855 return (rc); 12856 } 12857 12858 static int 12859 bxe_init_locked(struct bxe_softc *sc) 12860 { 12861 int other_engine = SC_PATH(sc) ? 0 : 1; 12862 uint8_t other_load_status, load_status; 12863 uint8_t global = FALSE; 12864 int rc; 12865 12866 BXE_CORE_LOCK_ASSERT(sc); 12867 12868 /* check if the driver is already running */ 12869 if (if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING) { 12870 BLOGD(sc, DBG_LOAD, "Init called while driver is running!\n"); 12871 return (0); 12872 } 12873 12874 if((sc->state == BXE_STATE_ERROR) && 12875 (sc->recovery_state == BXE_RECOVERY_FAILED)) { 12876 BLOGE(sc, "Initialization not done, " 12877 "as previous recovery failed." 12878 "Reboot/Power-cycle the system\n" ); 12879 return (ENXIO); 12880 } 12881 12882 12883 bxe_set_power_state(sc, PCI_PM_D0); 12884 12885 /* 12886 * If parity occurred during the unload, then attentions and/or 12887 * RECOVERY_IN_PROGRES may still be set. If so we want the first function 12888 * loaded on the current engine to complete the recovery. Parity recovery 12889 * is only relevant for PF driver. 12890 */ 12891 if (IS_PF(sc)) { 12892 other_load_status = bxe_get_load_status(sc, other_engine); 12893 load_status = bxe_get_load_status(sc, SC_PATH(sc)); 12894 12895 if (!bxe_reset_is_done(sc, SC_PATH(sc)) || 12896 bxe_chk_parity_attn(sc, &global, TRUE)) { 12897 do { 12898 /* 12899 * If there are attentions and they are in global blocks, set 12900 * the GLOBAL_RESET bit regardless whether it will be this 12901 * function that will complete the recovery or not. 12902 */ 12903 if (global) { 12904 bxe_set_reset_global(sc); 12905 } 12906 12907 /* 12908 * Only the first function on the current engine should try 12909 * to recover in open. In case of attentions in global blocks 12910 * only the first in the chip should try to recover. 12911 */ 12912 if ((!load_status && (!global || !other_load_status)) && 12913 bxe_trylock_leader_lock(sc) && !bxe_leader_reset(sc)) { 12914 BLOGI(sc, "Recovered during init\n"); 12915 break; 12916 } 12917 12918 /* recovery has failed... */ 12919 bxe_set_power_state(sc, PCI_PM_D3hot); 12920 sc->recovery_state = BXE_RECOVERY_FAILED; 12921 12922 BLOGE(sc, "Recovery flow hasn't properly " 12923 "completed yet, try again later. " 12924 "If you still see this message after a " 12925 "few retries then power cycle is required.\n"); 12926 12927 rc = ENXIO; 12928 goto bxe_init_locked_done; 12929 } while (0); 12930 } 12931 } 12932 12933 sc->recovery_state = BXE_RECOVERY_DONE; 12934 12935 rc = bxe_nic_load(sc, LOAD_OPEN); 12936 12937 bxe_init_locked_done: 12938 12939 if (rc) { 12940 /* Tell the stack the driver is NOT running! */ 12941 BLOGE(sc, "Initialization failed, " 12942 "stack notified driver is NOT running!\n"); 12943 if_setdrvflagbits(sc->ifp, 0, IFF_DRV_RUNNING); 12944 } 12945 12946 return (rc); 12947 } 12948 12949 static int 12950 bxe_stop_locked(struct bxe_softc *sc) 12951 { 12952 BXE_CORE_LOCK_ASSERT(sc); 12953 return (bxe_nic_unload(sc, UNLOAD_NORMAL, TRUE)); 12954 } 12955 12956 /* 12957 * Handles controller initialization when called from an unlocked routine. 12958 * ifconfig calls this function. 12959 * 12960 * Returns: 12961 * void 12962 */ 12963 static void 12964 bxe_init(void *xsc) 12965 { 12966 struct bxe_softc *sc = (struct bxe_softc *)xsc; 12967 12968 BXE_CORE_LOCK(sc); 12969 bxe_init_locked(sc); 12970 BXE_CORE_UNLOCK(sc); 12971 } 12972 12973 static void 12974 bxe_init_ifnet(struct bxe_softc *sc) 12975 { 12976 if_t ifp; 12977 int capabilities; 12978 12979 /* ifconfig entrypoint for media type/status reporting */ 12980 ifmedia_init(&sc->ifmedia, IFM_IMASK, 12981 bxe_ifmedia_update, 12982 bxe_ifmedia_status); 12983 12984 /* set the default interface values */ 12985 ifmedia_add(&sc->ifmedia, (IFM_ETHER | IFM_FDX | sc->media), 0, NULL); 12986 ifmedia_add(&sc->ifmedia, (IFM_ETHER | IFM_AUTO), 0, NULL); 12987 ifmedia_set(&sc->ifmedia, (IFM_ETHER | IFM_AUTO)); 12988 12989 sc->ifmedia.ifm_media = sc->ifmedia.ifm_cur->ifm_media; /* XXX ? */ 12990 BLOGI(sc, "IFMEDIA flags : %x\n", sc->ifmedia.ifm_media); 12991 12992 /* allocate the ifnet structure */ 12993 ifp = if_gethandle(IFT_ETHER); 12994 12995 if_setsoftc(ifp, sc); 12996 if_initname(ifp, device_get_name(sc->dev), device_get_unit(sc->dev)); 12997 if_setflags(ifp, (IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST)); 12998 if_setioctlfn(ifp, bxe_ioctl); 12999 if_setstartfn(ifp, bxe_tx_start); 13000 if_setgetcounterfn(ifp, bxe_get_counter); 13001 if_settransmitfn(ifp, bxe_tx_mq_start); 13002 if_setqflushfn(ifp, bxe_mq_flush); 13003 if_setinitfn(ifp, bxe_init); 13004 if_setmtu(ifp, sc->mtu); 13005 if_sethwassist(ifp, (CSUM_IP | 13006 CSUM_TCP | 13007 CSUM_UDP | 13008 CSUM_TSO | 13009 CSUM_TCP_IPV6 | 13010 CSUM_UDP_IPV6)); 13011 13012 capabilities = 13013 (IFCAP_VLAN_MTU | 13014 IFCAP_VLAN_HWTAGGING | 13015 IFCAP_VLAN_HWTSO | 13016 IFCAP_VLAN_HWFILTER | 13017 IFCAP_VLAN_HWCSUM | 13018 IFCAP_HWCSUM | 13019 IFCAP_JUMBO_MTU | 13020 IFCAP_LRO | 13021 IFCAP_TSO4 | 13022 IFCAP_TSO6 | 13023 IFCAP_WOL_MAGIC); 13024 if_setcapabilitiesbit(ifp, capabilities, 0); /* XXX */ 13025 if_setcapenable(ifp, if_getcapabilities(ifp)); 13026 if_setbaudrate(ifp, IF_Gbps(10)); 13027 /* XXX */ 13028 if_setsendqlen(ifp, sc->tx_ring_size); 13029 if_setsendqready(ifp); 13030 /* XXX */ 13031 13032 sc->ifp = ifp; 13033 13034 /* attach to the Ethernet interface list */ 13035 ether_ifattach(ifp, sc->link_params.mac_addr); 13036 13037 /* Attach driver debugnet methods. */ 13038 DEBUGNET_SET(ifp, bxe); 13039 } 13040 13041 static void 13042 bxe_deallocate_bars(struct bxe_softc *sc) 13043 { 13044 int i; 13045 13046 for (i = 0; i < MAX_BARS; i++) { 13047 if (sc->bar[i].resource != NULL) { 13048 bus_release_resource(sc->dev, 13049 SYS_RES_MEMORY, 13050 sc->bar[i].rid, 13051 sc->bar[i].resource); 13052 BLOGD(sc, DBG_LOAD, "Released PCI BAR%d [%02x] memory\n", 13053 i, PCIR_BAR(i)); 13054 } 13055 } 13056 } 13057 13058 static int 13059 bxe_allocate_bars(struct bxe_softc *sc) 13060 { 13061 u_int flags; 13062 int i; 13063 13064 memset(sc->bar, 0, sizeof(sc->bar)); 13065 13066 for (i = 0; i < MAX_BARS; i++) { 13067 13068 /* memory resources reside at BARs 0, 2, 4 */ 13069 /* Run `pciconf -lb` to see mappings */ 13070 if ((i != 0) && (i != 2) && (i != 4)) { 13071 continue; 13072 } 13073 13074 sc->bar[i].rid = PCIR_BAR(i); 13075 13076 flags = RF_ACTIVE; 13077 if (i == 0) { 13078 flags |= RF_SHAREABLE; 13079 } 13080 13081 if ((sc->bar[i].resource = 13082 bus_alloc_resource_any(sc->dev, 13083 SYS_RES_MEMORY, 13084 &sc->bar[i].rid, 13085 flags)) == NULL) { 13086 return (0); 13087 } 13088 13089 sc->bar[i].tag = rman_get_bustag(sc->bar[i].resource); 13090 sc->bar[i].handle = rman_get_bushandle(sc->bar[i].resource); 13091 sc->bar[i].kva = (vm_offset_t)rman_get_virtual(sc->bar[i].resource); 13092 13093 BLOGI(sc, "PCI BAR%d [%02x] memory allocated: %#jx-%#jx (%jd) -> %#jx\n", 13094 i, PCIR_BAR(i), 13095 rman_get_start(sc->bar[i].resource), 13096 rman_get_end(sc->bar[i].resource), 13097 rman_get_size(sc->bar[i].resource), 13098 (uintmax_t)sc->bar[i].kva); 13099 } 13100 13101 return (0); 13102 } 13103 13104 static void 13105 bxe_get_function_num(struct bxe_softc *sc) 13106 { 13107 uint32_t val = 0; 13108 13109 /* 13110 * Read the ME register to get the function number. The ME register 13111 * holds the relative-function number and absolute-function number. The 13112 * absolute-function number appears only in E2 and above. Before that 13113 * these bits always contained zero, therefore we cannot blindly use them. 13114 */ 13115 13116 val = REG_RD(sc, BAR_ME_REGISTER); 13117 13118 sc->pfunc_rel = 13119 (uint8_t)((val & ME_REG_PF_NUM) >> ME_REG_PF_NUM_SHIFT); 13120 sc->path_id = 13121 (uint8_t)((val & ME_REG_ABS_PF_NUM) >> ME_REG_ABS_PF_NUM_SHIFT) & 1; 13122 13123 if (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) { 13124 sc->pfunc_abs = ((sc->pfunc_rel << 1) | sc->path_id); 13125 } else { 13126 sc->pfunc_abs = (sc->pfunc_rel | sc->path_id); 13127 } 13128 13129 BLOGD(sc, DBG_LOAD, 13130 "Relative function %d, Absolute function %d, Path %d\n", 13131 sc->pfunc_rel, sc->pfunc_abs, sc->path_id); 13132 } 13133 13134 static uint32_t 13135 bxe_get_shmem_mf_cfg_base(struct bxe_softc *sc) 13136 { 13137 uint32_t shmem2_size; 13138 uint32_t offset; 13139 uint32_t mf_cfg_offset_value; 13140 13141 /* Non 57712 */ 13142 offset = (SHMEM_RD(sc, func_mb) + 13143 (MAX_FUNC_NUM * sizeof(struct drv_func_mb))); 13144 13145 /* 57712 plus */ 13146 if (sc->devinfo.shmem2_base != 0) { 13147 shmem2_size = SHMEM2_RD(sc, size); 13148 if (shmem2_size > offsetof(struct shmem2_region, mf_cfg_addr)) { 13149 mf_cfg_offset_value = SHMEM2_RD(sc, mf_cfg_addr); 13150 if (SHMEM_MF_CFG_ADDR_NONE != mf_cfg_offset_value) { 13151 offset = mf_cfg_offset_value; 13152 } 13153 } 13154 } 13155 13156 return (offset); 13157 } 13158 13159 static uint32_t 13160 bxe_pcie_capability_read(struct bxe_softc *sc, 13161 int reg, 13162 int width) 13163 { 13164 int pcie_reg; 13165 13166 /* ensure PCIe capability is enabled */ 13167 if (pci_find_cap(sc->dev, PCIY_EXPRESS, &pcie_reg) == 0) { 13168 if (pcie_reg != 0) { 13169 BLOGD(sc, DBG_LOAD, "PCIe capability at 0x%04x\n", pcie_reg); 13170 return (pci_read_config(sc->dev, (pcie_reg + reg), width)); 13171 } 13172 } 13173 13174 BLOGE(sc, "PCIe capability NOT FOUND!!!\n"); 13175 13176 return (0); 13177 } 13178 13179 static uint8_t 13180 bxe_is_pcie_pending(struct bxe_softc *sc) 13181 { 13182 return (bxe_pcie_capability_read(sc, PCIER_DEVICE_STA, 2) & 13183 PCIEM_STA_TRANSACTION_PND); 13184 } 13185 13186 /* 13187 * Walk the PCI capabiites list for the device to find what features are 13188 * supported. These capabilites may be enabled/disabled by firmware so it's 13189 * best to walk the list rather than make assumptions. 13190 */ 13191 static void 13192 bxe_probe_pci_caps(struct bxe_softc *sc) 13193 { 13194 uint16_t link_status; 13195 int reg; 13196 13197 /* check if PCI Power Management is enabled */ 13198 if (pci_find_cap(sc->dev, PCIY_PMG, ®) == 0) { 13199 if (reg != 0) { 13200 BLOGD(sc, DBG_LOAD, "Found PM capability at 0x%04x\n", reg); 13201 13202 sc->devinfo.pcie_cap_flags |= BXE_PM_CAPABLE_FLAG; 13203 sc->devinfo.pcie_pm_cap_reg = (uint16_t)reg; 13204 } 13205 } 13206 13207 link_status = bxe_pcie_capability_read(sc, PCIER_LINK_STA, 2); 13208 13209 /* handle PCIe 2.0 workarounds for 57710 */ 13210 if (CHIP_IS_E1(sc)) { 13211 /* workaround for 57710 errata E4_57710_27462 */ 13212 sc->devinfo.pcie_link_speed = 13213 (REG_RD(sc, 0x3d04) & (1 << 24)) ? 2 : 1; 13214 13215 /* workaround for 57710 errata E4_57710_27488 */ 13216 sc->devinfo.pcie_link_width = 13217 ((link_status & PCIEM_LINK_STA_WIDTH) >> 4); 13218 if (sc->devinfo.pcie_link_speed > 1) { 13219 sc->devinfo.pcie_link_width = 13220 ((link_status & PCIEM_LINK_STA_WIDTH) >> 4) >> 1; 13221 } 13222 } else { 13223 sc->devinfo.pcie_link_speed = 13224 (link_status & PCIEM_LINK_STA_SPEED); 13225 sc->devinfo.pcie_link_width = 13226 ((link_status & PCIEM_LINK_STA_WIDTH) >> 4); 13227 } 13228 13229 BLOGD(sc, DBG_LOAD, "PCIe link speed=%d width=%d\n", 13230 sc->devinfo.pcie_link_speed, sc->devinfo.pcie_link_width); 13231 13232 sc->devinfo.pcie_cap_flags |= BXE_PCIE_CAPABLE_FLAG; 13233 sc->devinfo.pcie_pcie_cap_reg = (uint16_t)reg; 13234 13235 /* check if MSI capability is enabled */ 13236 if (pci_find_cap(sc->dev, PCIY_MSI, ®) == 0) { 13237 if (reg != 0) { 13238 BLOGD(sc, DBG_LOAD, "Found MSI capability at 0x%04x\n", reg); 13239 13240 sc->devinfo.pcie_cap_flags |= BXE_MSI_CAPABLE_FLAG; 13241 sc->devinfo.pcie_msi_cap_reg = (uint16_t)reg; 13242 } 13243 } 13244 13245 /* check if MSI-X capability is enabled */ 13246 if (pci_find_cap(sc->dev, PCIY_MSIX, ®) == 0) { 13247 if (reg != 0) { 13248 BLOGD(sc, DBG_LOAD, "Found MSI-X capability at 0x%04x\n", reg); 13249 13250 sc->devinfo.pcie_cap_flags |= BXE_MSIX_CAPABLE_FLAG; 13251 sc->devinfo.pcie_msix_cap_reg = (uint16_t)reg; 13252 } 13253 } 13254 } 13255 13256 static int 13257 bxe_get_shmem_mf_cfg_info_sd(struct bxe_softc *sc) 13258 { 13259 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info; 13260 uint32_t val; 13261 13262 /* get the outer vlan if we're in switch-dependent mode */ 13263 13264 val = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag); 13265 mf_info->ext_id = (uint16_t)val; 13266 13267 mf_info->multi_vnics_mode = 1; 13268 13269 if (!VALID_OVLAN(mf_info->ext_id)) { 13270 BLOGE(sc, "Invalid VLAN (%d)\n", mf_info->ext_id); 13271 return (1); 13272 } 13273 13274 /* get the capabilities */ 13275 if ((mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_PROTOCOL_MASK) == 13276 FUNC_MF_CFG_PROTOCOL_ISCSI) { 13277 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_ISCSI; 13278 } else if ((mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_PROTOCOL_MASK) == 13279 FUNC_MF_CFG_PROTOCOL_FCOE) { 13280 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_FCOE; 13281 } else { 13282 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_ETHERNET; 13283 } 13284 13285 mf_info->vnics_per_port = 13286 (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4; 13287 13288 return (0); 13289 } 13290 13291 static uint32_t 13292 bxe_get_shmem_ext_proto_support_flags(struct bxe_softc *sc) 13293 { 13294 uint32_t retval = 0; 13295 uint32_t val; 13296 13297 val = MFCFG_RD(sc, func_ext_config[SC_ABS_FUNC(sc)].func_cfg); 13298 13299 if (val & MACP_FUNC_CFG_FLAGS_ENABLED) { 13300 if (val & MACP_FUNC_CFG_FLAGS_ETHERNET) { 13301 retval |= MF_PROTO_SUPPORT_ETHERNET; 13302 } 13303 if (val & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) { 13304 retval |= MF_PROTO_SUPPORT_ISCSI; 13305 } 13306 if (val & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) { 13307 retval |= MF_PROTO_SUPPORT_FCOE; 13308 } 13309 } 13310 13311 return (retval); 13312 } 13313 13314 static int 13315 bxe_get_shmem_mf_cfg_info_si(struct bxe_softc *sc) 13316 { 13317 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info; 13318 uint32_t val; 13319 13320 /* 13321 * There is no outer vlan if we're in switch-independent mode. 13322 * If the mac is valid then assume multi-function. 13323 */ 13324 13325 val = MFCFG_RD(sc, func_ext_config[SC_ABS_FUNC(sc)].func_cfg); 13326 13327 mf_info->multi_vnics_mode = ((val & MACP_FUNC_CFG_FLAGS_MASK) != 0); 13328 13329 mf_info->mf_protos_supported = bxe_get_shmem_ext_proto_support_flags(sc); 13330 13331 mf_info->vnics_per_port = 13332 (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4; 13333 13334 return (0); 13335 } 13336 13337 static int 13338 bxe_get_shmem_mf_cfg_info_niv(struct bxe_softc *sc) 13339 { 13340 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info; 13341 uint32_t e1hov_tag; 13342 uint32_t func_config; 13343 uint32_t niv_config; 13344 13345 mf_info->multi_vnics_mode = 1; 13346 13347 e1hov_tag = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag); 13348 func_config = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config); 13349 niv_config = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].afex_config); 13350 13351 mf_info->ext_id = 13352 (uint16_t)((e1hov_tag & FUNC_MF_CFG_E1HOV_TAG_MASK) >> 13353 FUNC_MF_CFG_E1HOV_TAG_SHIFT); 13354 13355 mf_info->default_vlan = 13356 (uint16_t)((e1hov_tag & FUNC_MF_CFG_AFEX_VLAN_MASK) >> 13357 FUNC_MF_CFG_AFEX_VLAN_SHIFT); 13358 13359 mf_info->niv_allowed_priorities = 13360 (uint8_t)((niv_config & FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >> 13361 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT); 13362 13363 mf_info->niv_default_cos = 13364 (uint8_t)((func_config & FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >> 13365 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT); 13366 13367 mf_info->afex_vlan_mode = 13368 ((niv_config & FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >> 13369 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT); 13370 13371 mf_info->niv_mba_enabled = 13372 ((niv_config & FUNC_MF_CFG_AFEX_MBA_ENABLED_MASK) >> 13373 FUNC_MF_CFG_AFEX_MBA_ENABLED_SHIFT); 13374 13375 mf_info->mf_protos_supported = bxe_get_shmem_ext_proto_support_flags(sc); 13376 13377 mf_info->vnics_per_port = 13378 (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4; 13379 13380 return (0); 13381 } 13382 13383 static int 13384 bxe_check_valid_mf_cfg(struct bxe_softc *sc) 13385 { 13386 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info; 13387 uint32_t mf_cfg1; 13388 uint32_t mf_cfg2; 13389 uint32_t ovlan1; 13390 uint32_t ovlan2; 13391 uint8_t i, j; 13392 13393 BLOGD(sc, DBG_LOAD, "MF config parameters for function %d\n", 13394 SC_PORT(sc)); 13395 BLOGD(sc, DBG_LOAD, "\tmf_config=0x%x\n", 13396 mf_info->mf_config[SC_VN(sc)]); 13397 BLOGD(sc, DBG_LOAD, "\tmulti_vnics_mode=%d\n", 13398 mf_info->multi_vnics_mode); 13399 BLOGD(sc, DBG_LOAD, "\tvnics_per_port=%d\n", 13400 mf_info->vnics_per_port); 13401 BLOGD(sc, DBG_LOAD, "\tovlan/vifid=%d\n", 13402 mf_info->ext_id); 13403 BLOGD(sc, DBG_LOAD, "\tmin_bw=%d/%d/%d/%d\n", 13404 mf_info->min_bw[0], mf_info->min_bw[1], 13405 mf_info->min_bw[2], mf_info->min_bw[3]); 13406 BLOGD(sc, DBG_LOAD, "\tmax_bw=%d/%d/%d/%d\n", 13407 mf_info->max_bw[0], mf_info->max_bw[1], 13408 mf_info->max_bw[2], mf_info->max_bw[3]); 13409 BLOGD(sc, DBG_LOAD, "\tmac_addr: %s\n", 13410 sc->mac_addr_str); 13411 13412 /* various MF mode sanity checks... */ 13413 13414 if (mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_FUNC_HIDE) { 13415 BLOGE(sc, "Enumerated function %d is marked as hidden\n", 13416 SC_PORT(sc)); 13417 return (1); 13418 } 13419 13420 if ((mf_info->vnics_per_port > 1) && !mf_info->multi_vnics_mode) { 13421 BLOGE(sc, "vnics_per_port=%d multi_vnics_mode=%d\n", 13422 mf_info->vnics_per_port, mf_info->multi_vnics_mode); 13423 return (1); 13424 } 13425 13426 if (mf_info->mf_mode == MULTI_FUNCTION_SD) { 13427 /* vnic id > 0 must have valid ovlan in switch-dependent mode */ 13428 if ((SC_VN(sc) > 0) && !VALID_OVLAN(OVLAN(sc))) { 13429 BLOGE(sc, "mf_mode=SD vnic_id=%d ovlan=%d\n", 13430 SC_VN(sc), OVLAN(sc)); 13431 return (1); 13432 } 13433 13434 if (!VALID_OVLAN(OVLAN(sc)) && mf_info->multi_vnics_mode) { 13435 BLOGE(sc, "mf_mode=SD multi_vnics_mode=%d ovlan=%d\n", 13436 mf_info->multi_vnics_mode, OVLAN(sc)); 13437 return (1); 13438 } 13439 13440 /* 13441 * Verify all functions are either MF or SF mode. If MF, make sure 13442 * sure that all non-hidden functions have a valid ovlan. If SF, 13443 * make sure that all non-hidden functions have an invalid ovlan. 13444 */ 13445 FOREACH_ABS_FUNC_IN_PORT(sc, i) { 13446 mf_cfg1 = MFCFG_RD(sc, func_mf_config[i].config); 13447 ovlan1 = MFCFG_RD(sc, func_mf_config[i].e1hov_tag); 13448 if (!(mf_cfg1 & FUNC_MF_CFG_FUNC_HIDE) && 13449 (((mf_info->multi_vnics_mode) && !VALID_OVLAN(ovlan1)) || 13450 ((!mf_info->multi_vnics_mode) && VALID_OVLAN(ovlan1)))) { 13451 BLOGE(sc, "mf_mode=SD function %d MF config " 13452 "mismatch, multi_vnics_mode=%d ovlan=%d\n", 13453 i, mf_info->multi_vnics_mode, ovlan1); 13454 return (1); 13455 } 13456 } 13457 13458 /* Verify all funcs on the same port each have a different ovlan. */ 13459 FOREACH_ABS_FUNC_IN_PORT(sc, i) { 13460 mf_cfg1 = MFCFG_RD(sc, func_mf_config[i].config); 13461 ovlan1 = MFCFG_RD(sc, func_mf_config[i].e1hov_tag); 13462 /* iterate from the next function on the port to the max func */ 13463 for (j = i + 2; j < MAX_FUNC_NUM; j += 2) { 13464 mf_cfg2 = MFCFG_RD(sc, func_mf_config[j].config); 13465 ovlan2 = MFCFG_RD(sc, func_mf_config[j].e1hov_tag); 13466 if (!(mf_cfg1 & FUNC_MF_CFG_FUNC_HIDE) && 13467 VALID_OVLAN(ovlan1) && 13468 !(mf_cfg2 & FUNC_MF_CFG_FUNC_HIDE) && 13469 VALID_OVLAN(ovlan2) && 13470 (ovlan1 == ovlan2)) { 13471 BLOGE(sc, "mf_mode=SD functions %d and %d " 13472 "have the same ovlan (%d)\n", 13473 i, j, ovlan1); 13474 return (1); 13475 } 13476 } 13477 } 13478 } /* MULTI_FUNCTION_SD */ 13479 13480 return (0); 13481 } 13482 13483 static int 13484 bxe_get_mf_cfg_info(struct bxe_softc *sc) 13485 { 13486 struct bxe_mf_info *mf_info = &sc->devinfo.mf_info; 13487 uint32_t val, mac_upper; 13488 uint8_t i, vnic; 13489 13490 /* initialize mf_info defaults */ 13491 mf_info->vnics_per_port = 1; 13492 mf_info->multi_vnics_mode = FALSE; 13493 mf_info->path_has_ovlan = FALSE; 13494 mf_info->mf_mode = SINGLE_FUNCTION; 13495 13496 if (!CHIP_IS_MF_CAP(sc)) { 13497 return (0); 13498 } 13499 13500 if (sc->devinfo.mf_cfg_base == SHMEM_MF_CFG_ADDR_NONE) { 13501 BLOGE(sc, "Invalid mf_cfg_base!\n"); 13502 return (1); 13503 } 13504 13505 /* get the MF mode (switch dependent / independent / single-function) */ 13506 13507 val = SHMEM_RD(sc, dev_info.shared_feature_config.config); 13508 13509 switch (val & SHARED_FEAT_CFG_FORCE_SF_MODE_MASK) 13510 { 13511 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT: 13512 13513 mac_upper = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper); 13514 13515 /* check for legal upper mac bytes */ 13516 if (mac_upper != FUNC_MF_CFG_UPPERMAC_DEFAULT) { 13517 mf_info->mf_mode = MULTI_FUNCTION_SI; 13518 } else { 13519 BLOGE(sc, "Invalid config for Switch Independent mode\n"); 13520 } 13521 13522 break; 13523 13524 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED: 13525 case SHARED_FEAT_CFG_FORCE_SF_MODE_SPIO4: 13526 13527 /* get outer vlan configuration */ 13528 val = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag); 13529 13530 if ((val & FUNC_MF_CFG_E1HOV_TAG_MASK) != 13531 FUNC_MF_CFG_E1HOV_TAG_DEFAULT) { 13532 mf_info->mf_mode = MULTI_FUNCTION_SD; 13533 } else { 13534 BLOGE(sc, "Invalid config for Switch Dependent mode\n"); 13535 } 13536 13537 break; 13538 13539 case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF: 13540 13541 /* not in MF mode, vnics_per_port=1 and multi_vnics_mode=FALSE */ 13542 return (0); 13543 13544 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE: 13545 13546 /* 13547 * Mark MF mode as NIV if MCP version includes NPAR-SD support 13548 * and the MAC address is valid. 13549 */ 13550 mac_upper = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper); 13551 13552 if ((SHMEM2_HAS(sc, afex_driver_support)) && 13553 (mac_upper != FUNC_MF_CFG_UPPERMAC_DEFAULT)) { 13554 mf_info->mf_mode = MULTI_FUNCTION_AFEX; 13555 } else { 13556 BLOGE(sc, "Invalid config for AFEX mode\n"); 13557 } 13558 13559 break; 13560 13561 default: 13562 13563 BLOGE(sc, "Unknown MF mode (0x%08x)\n", 13564 (val & SHARED_FEAT_CFG_FORCE_SF_MODE_MASK)); 13565 13566 return (1); 13567 } 13568 13569 /* set path mf_mode (which could be different than function mf_mode) */ 13570 if (mf_info->mf_mode == MULTI_FUNCTION_SD) { 13571 mf_info->path_has_ovlan = TRUE; 13572 } else if (mf_info->mf_mode == SINGLE_FUNCTION) { 13573 /* 13574 * Decide on path multi vnics mode. If we're not in MF mode and in 13575 * 4-port mode, this is good enough to check vnic-0 of the other port 13576 * on the same path 13577 */ 13578 if (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) { 13579 uint8_t other_port = !(PORT_ID(sc) & 1); 13580 uint8_t abs_func_other_port = (SC_PATH(sc) + (2 * other_port)); 13581 13582 val = MFCFG_RD(sc, func_mf_config[abs_func_other_port].e1hov_tag); 13583 13584 mf_info->path_has_ovlan = VALID_OVLAN((uint16_t)val) ? 1 : 0; 13585 } 13586 } 13587 13588 if (mf_info->mf_mode == SINGLE_FUNCTION) { 13589 /* invalid MF config */ 13590 if (SC_VN(sc) >= 1) { 13591 BLOGE(sc, "VNIC ID >= 1 in SF mode\n"); 13592 return (1); 13593 } 13594 13595 return (0); 13596 } 13597 13598 /* get the MF configuration */ 13599 mf_info->mf_config[SC_VN(sc)] = 13600 MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config); 13601 13602 switch(mf_info->mf_mode) 13603 { 13604 case MULTI_FUNCTION_SD: 13605 13606 bxe_get_shmem_mf_cfg_info_sd(sc); 13607 break; 13608 13609 case MULTI_FUNCTION_SI: 13610 13611 bxe_get_shmem_mf_cfg_info_si(sc); 13612 break; 13613 13614 case MULTI_FUNCTION_AFEX: 13615 13616 bxe_get_shmem_mf_cfg_info_niv(sc); 13617 break; 13618 13619 default: 13620 13621 BLOGE(sc, "Get MF config failed (mf_mode=0x%08x)\n", 13622 mf_info->mf_mode); 13623 return (1); 13624 } 13625 13626 /* get the congestion management parameters */ 13627 13628 vnic = 0; 13629 FOREACH_ABS_FUNC_IN_PORT(sc, i) { 13630 /* get min/max bw */ 13631 val = MFCFG_RD(sc, func_mf_config[i].config); 13632 mf_info->min_bw[vnic] = 13633 ((val & FUNC_MF_CFG_MIN_BW_MASK) >> FUNC_MF_CFG_MIN_BW_SHIFT); 13634 mf_info->max_bw[vnic] = 13635 ((val & FUNC_MF_CFG_MAX_BW_MASK) >> FUNC_MF_CFG_MAX_BW_SHIFT); 13636 vnic++; 13637 } 13638 13639 return (bxe_check_valid_mf_cfg(sc)); 13640 } 13641 13642 static int 13643 bxe_get_shmem_info(struct bxe_softc *sc) 13644 { 13645 int port; 13646 uint32_t mac_hi, mac_lo, val; 13647 13648 port = SC_PORT(sc); 13649 mac_hi = mac_lo = 0; 13650 13651 sc->link_params.sc = sc; 13652 sc->link_params.port = port; 13653 13654 /* get the hardware config info */ 13655 sc->devinfo.hw_config = 13656 SHMEM_RD(sc, dev_info.shared_hw_config.config); 13657 sc->devinfo.hw_config2 = 13658 SHMEM_RD(sc, dev_info.shared_hw_config.config2); 13659 13660 sc->link_params.hw_led_mode = 13661 ((sc->devinfo.hw_config & SHARED_HW_CFG_LED_MODE_MASK) >> 13662 SHARED_HW_CFG_LED_MODE_SHIFT); 13663 13664 /* get the port feature config */ 13665 sc->port.config = 13666 SHMEM_RD(sc, dev_info.port_feature_config[port].config); 13667 13668 /* get the link params */ 13669 sc->link_params.speed_cap_mask[0] = 13670 SHMEM_RD(sc, dev_info.port_hw_config[port].speed_capability_mask); 13671 sc->link_params.speed_cap_mask[1] = 13672 SHMEM_RD(sc, dev_info.port_hw_config[port].speed_capability_mask2); 13673 13674 /* get the lane config */ 13675 sc->link_params.lane_config = 13676 SHMEM_RD(sc, dev_info.port_hw_config[port].lane_config); 13677 13678 /* get the link config */ 13679 val = SHMEM_RD(sc, dev_info.port_feature_config[port].link_config); 13680 sc->port.link_config[ELINK_INT_PHY] = val; 13681 sc->link_params.switch_cfg = (val & PORT_FEATURE_CONNECTED_SWITCH_MASK); 13682 sc->port.link_config[ELINK_EXT_PHY1] = 13683 SHMEM_RD(sc, dev_info.port_feature_config[port].link_config2); 13684 13685 /* get the override preemphasis flag and enable it or turn it off */ 13686 val = SHMEM_RD(sc, dev_info.shared_feature_config.config); 13687 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED) { 13688 sc->link_params.feature_config_flags |= 13689 ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED; 13690 } else { 13691 sc->link_params.feature_config_flags &= 13692 ~ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED; 13693 } 13694 13695 /* get the initial value of the link params */ 13696 sc->link_params.multi_phy_config = 13697 SHMEM_RD(sc, dev_info.port_hw_config[port].multi_phy_config); 13698 13699 /* get external phy info */ 13700 sc->port.ext_phy_config = 13701 SHMEM_RD(sc, dev_info.port_hw_config[port].external_phy_config); 13702 13703 /* get the multifunction configuration */ 13704 bxe_get_mf_cfg_info(sc); 13705 13706 /* get the mac address */ 13707 if (IS_MF(sc)) { 13708 mac_hi = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper); 13709 mac_lo = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_lower); 13710 } else { 13711 mac_hi = SHMEM_RD(sc, dev_info.port_hw_config[port].mac_upper); 13712 mac_lo = SHMEM_RD(sc, dev_info.port_hw_config[port].mac_lower); 13713 } 13714 13715 if ((mac_lo == 0) && (mac_hi == 0)) { 13716 *sc->mac_addr_str = 0; 13717 BLOGE(sc, "No Ethernet address programmed!\n"); 13718 } else { 13719 sc->link_params.mac_addr[0] = (uint8_t)(mac_hi >> 8); 13720 sc->link_params.mac_addr[1] = (uint8_t)(mac_hi); 13721 sc->link_params.mac_addr[2] = (uint8_t)(mac_lo >> 24); 13722 sc->link_params.mac_addr[3] = (uint8_t)(mac_lo >> 16); 13723 sc->link_params.mac_addr[4] = (uint8_t)(mac_lo >> 8); 13724 sc->link_params.mac_addr[5] = (uint8_t)(mac_lo); 13725 snprintf(sc->mac_addr_str, sizeof(sc->mac_addr_str), 13726 "%02x:%02x:%02x:%02x:%02x:%02x", 13727 sc->link_params.mac_addr[0], sc->link_params.mac_addr[1], 13728 sc->link_params.mac_addr[2], sc->link_params.mac_addr[3], 13729 sc->link_params.mac_addr[4], sc->link_params.mac_addr[5]); 13730 BLOGD(sc, DBG_LOAD, "Ethernet address: %s\n", sc->mac_addr_str); 13731 } 13732 13733 return (0); 13734 } 13735 13736 static void 13737 bxe_get_tunable_params(struct bxe_softc *sc) 13738 { 13739 /* sanity checks */ 13740 13741 if ((bxe_interrupt_mode != INTR_MODE_INTX) && 13742 (bxe_interrupt_mode != INTR_MODE_MSI) && 13743 (bxe_interrupt_mode != INTR_MODE_MSIX)) { 13744 BLOGW(sc, "invalid interrupt_mode value (%d)\n", bxe_interrupt_mode); 13745 bxe_interrupt_mode = INTR_MODE_MSIX; 13746 } 13747 13748 if ((bxe_queue_count < 0) || (bxe_queue_count > MAX_RSS_CHAINS)) { 13749 BLOGW(sc, "invalid queue_count value (%d)\n", bxe_queue_count); 13750 bxe_queue_count = 0; 13751 } 13752 13753 if ((bxe_max_rx_bufs < 1) || (bxe_max_rx_bufs > RX_BD_USABLE)) { 13754 if (bxe_max_rx_bufs == 0) { 13755 bxe_max_rx_bufs = RX_BD_USABLE; 13756 } else { 13757 BLOGW(sc, "invalid max_rx_bufs (%d)\n", bxe_max_rx_bufs); 13758 bxe_max_rx_bufs = 2048; 13759 } 13760 } 13761 13762 if ((bxe_hc_rx_ticks < 1) || (bxe_hc_rx_ticks > 100)) { 13763 BLOGW(sc, "invalid hc_rx_ticks (%d)\n", bxe_hc_rx_ticks); 13764 bxe_hc_rx_ticks = 25; 13765 } 13766 13767 if ((bxe_hc_tx_ticks < 1) || (bxe_hc_tx_ticks > 100)) { 13768 BLOGW(sc, "invalid hc_tx_ticks (%d)\n", bxe_hc_tx_ticks); 13769 bxe_hc_tx_ticks = 50; 13770 } 13771 13772 if (bxe_max_aggregation_size == 0) { 13773 bxe_max_aggregation_size = TPA_AGG_SIZE; 13774 } 13775 13776 if (bxe_max_aggregation_size > 0xffff) { 13777 BLOGW(sc, "invalid max_aggregation_size (%d)\n", 13778 bxe_max_aggregation_size); 13779 bxe_max_aggregation_size = TPA_AGG_SIZE; 13780 } 13781 13782 if ((bxe_mrrs < -1) || (bxe_mrrs > 3)) { 13783 BLOGW(sc, "invalid mrrs (%d)\n", bxe_mrrs); 13784 bxe_mrrs = -1; 13785 } 13786 13787 if ((bxe_autogreeen < 0) || (bxe_autogreeen > 2)) { 13788 BLOGW(sc, "invalid autogreeen (%d)\n", bxe_autogreeen); 13789 bxe_autogreeen = 0; 13790 } 13791 13792 if ((bxe_udp_rss < 0) || (bxe_udp_rss > 1)) { 13793 BLOGW(sc, "invalid udp_rss (%d)\n", bxe_udp_rss); 13794 bxe_udp_rss = 0; 13795 } 13796 13797 /* pull in user settings */ 13798 13799 sc->interrupt_mode = bxe_interrupt_mode; 13800 sc->max_rx_bufs = bxe_max_rx_bufs; 13801 sc->hc_rx_ticks = bxe_hc_rx_ticks; 13802 sc->hc_tx_ticks = bxe_hc_tx_ticks; 13803 sc->max_aggregation_size = bxe_max_aggregation_size; 13804 sc->mrrs = bxe_mrrs; 13805 sc->autogreeen = bxe_autogreeen; 13806 sc->udp_rss = bxe_udp_rss; 13807 13808 if (bxe_interrupt_mode == INTR_MODE_INTX) { 13809 sc->num_queues = 1; 13810 } else { /* INTR_MODE_MSI or INTR_MODE_MSIX */ 13811 sc->num_queues = 13812 min((bxe_queue_count ? bxe_queue_count : mp_ncpus), 13813 MAX_RSS_CHAINS); 13814 if (sc->num_queues > mp_ncpus) { 13815 sc->num_queues = mp_ncpus; 13816 } 13817 } 13818 13819 BLOGD(sc, DBG_LOAD, 13820 "User Config: " 13821 "debug=0x%lx " 13822 "interrupt_mode=%d " 13823 "queue_count=%d " 13824 "hc_rx_ticks=%d " 13825 "hc_tx_ticks=%d " 13826 "rx_budget=%d " 13827 "max_aggregation_size=%d " 13828 "mrrs=%d " 13829 "autogreeen=%d " 13830 "udp_rss=%d\n", 13831 bxe_debug, 13832 sc->interrupt_mode, 13833 sc->num_queues, 13834 sc->hc_rx_ticks, 13835 sc->hc_tx_ticks, 13836 bxe_rx_budget, 13837 sc->max_aggregation_size, 13838 sc->mrrs, 13839 sc->autogreeen, 13840 sc->udp_rss); 13841 } 13842 13843 static int 13844 bxe_media_detect(struct bxe_softc *sc) 13845 { 13846 int port_type; 13847 uint32_t phy_idx = bxe_get_cur_phy_idx(sc); 13848 13849 switch (sc->link_params.phy[phy_idx].media_type) { 13850 case ELINK_ETH_PHY_SFPP_10G_FIBER: 13851 case ELINK_ETH_PHY_XFP_FIBER: 13852 BLOGI(sc, "Found 10Gb Fiber media.\n"); 13853 sc->media = IFM_10G_SR; 13854 port_type = PORT_FIBRE; 13855 break; 13856 case ELINK_ETH_PHY_SFP_1G_FIBER: 13857 BLOGI(sc, "Found 1Gb Fiber media.\n"); 13858 sc->media = IFM_1000_SX; 13859 port_type = PORT_FIBRE; 13860 break; 13861 case ELINK_ETH_PHY_KR: 13862 case ELINK_ETH_PHY_CX4: 13863 BLOGI(sc, "Found 10GBase-CX4 media.\n"); 13864 sc->media = IFM_10G_CX4; 13865 port_type = PORT_FIBRE; 13866 break; 13867 case ELINK_ETH_PHY_DA_TWINAX: 13868 BLOGI(sc, "Found 10Gb Twinax media.\n"); 13869 sc->media = IFM_10G_TWINAX; 13870 port_type = PORT_DA; 13871 break; 13872 case ELINK_ETH_PHY_BASE_T: 13873 if (sc->link_params.speed_cap_mask[0] & 13874 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) { 13875 BLOGI(sc, "Found 10GBase-T media.\n"); 13876 sc->media = IFM_10G_T; 13877 port_type = PORT_TP; 13878 } else { 13879 BLOGI(sc, "Found 1000Base-T media.\n"); 13880 sc->media = IFM_1000_T; 13881 port_type = PORT_TP; 13882 } 13883 break; 13884 case ELINK_ETH_PHY_NOT_PRESENT: 13885 BLOGI(sc, "Media not present.\n"); 13886 sc->media = 0; 13887 port_type = PORT_OTHER; 13888 break; 13889 case ELINK_ETH_PHY_UNSPECIFIED: 13890 default: 13891 BLOGI(sc, "Unknown media!\n"); 13892 sc->media = 0; 13893 port_type = PORT_OTHER; 13894 break; 13895 } 13896 return port_type; 13897 } 13898 13899 #define GET_FIELD(value, fname) \ 13900 (((value) & (fname##_MASK)) >> (fname##_SHIFT)) 13901 #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID) 13902 #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR) 13903 13904 static int 13905 bxe_get_igu_cam_info(struct bxe_softc *sc) 13906 { 13907 int pfid = SC_FUNC(sc); 13908 int igu_sb_id; 13909 uint32_t val; 13910 uint8_t fid, igu_sb_cnt = 0; 13911 13912 sc->igu_base_sb = 0xff; 13913 13914 if (CHIP_INT_MODE_IS_BC(sc)) { 13915 int vn = SC_VN(sc); 13916 igu_sb_cnt = sc->igu_sb_cnt; 13917 sc->igu_base_sb = ((CHIP_IS_MODE_4_PORT(sc) ? pfid : vn) * 13918 FP_SB_MAX_E1x); 13919 sc->igu_dsb_id = (E1HVN_MAX * FP_SB_MAX_E1x + 13920 (CHIP_IS_MODE_4_PORT(sc) ? pfid : vn)); 13921 return (0); 13922 } 13923 13924 /* IGU in normal mode - read CAM */ 13925 for (igu_sb_id = 0; 13926 igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE; 13927 igu_sb_id++) { 13928 val = REG_RD(sc, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4); 13929 if (!(val & IGU_REG_MAPPING_MEMORY_VALID)) { 13930 continue; 13931 } 13932 fid = IGU_FID(val); 13933 if ((fid & IGU_FID_ENCODE_IS_PF)) { 13934 if ((fid & IGU_FID_PF_NUM_MASK) != pfid) { 13935 continue; 13936 } 13937 if (IGU_VEC(val) == 0) { 13938 /* default status block */ 13939 sc->igu_dsb_id = igu_sb_id; 13940 } else { 13941 if (sc->igu_base_sb == 0xff) { 13942 sc->igu_base_sb = igu_sb_id; 13943 } 13944 igu_sb_cnt++; 13945 } 13946 } 13947 } 13948 13949 /* 13950 * Due to new PF resource allocation by MFW T7.4 and above, it's optional 13951 * that number of CAM entries will not be equal to the value advertised in 13952 * PCI. Driver should use the minimal value of both as the actual status 13953 * block count 13954 */ 13955 sc->igu_sb_cnt = min(sc->igu_sb_cnt, igu_sb_cnt); 13956 13957 if (igu_sb_cnt == 0) { 13958 BLOGE(sc, "CAM configuration error\n"); 13959 return (-1); 13960 } 13961 13962 return (0); 13963 } 13964 13965 /* 13966 * Gather various information from the device config space, the device itself, 13967 * shmem, and the user input. 13968 */ 13969 static int 13970 bxe_get_device_info(struct bxe_softc *sc) 13971 { 13972 uint32_t val; 13973 int rc; 13974 13975 /* Get the data for the device */ 13976 sc->devinfo.vendor_id = pci_get_vendor(sc->dev); 13977 sc->devinfo.device_id = pci_get_device(sc->dev); 13978 sc->devinfo.subvendor_id = pci_get_subvendor(sc->dev); 13979 sc->devinfo.subdevice_id = pci_get_subdevice(sc->dev); 13980 13981 /* get the chip revision (chip metal comes from pci config space) */ 13982 sc->devinfo.chip_id = 13983 sc->link_params.chip_id = 13984 (((REG_RD(sc, MISC_REG_CHIP_NUM) & 0xffff) << 16) | 13985 ((REG_RD(sc, MISC_REG_CHIP_REV) & 0xf) << 12) | 13986 (((REG_RD(sc, PCICFG_OFFSET + PCI_ID_VAL3) >> 24) & 0xf) << 4) | 13987 ((REG_RD(sc, MISC_REG_BOND_ID) & 0xf) << 0)); 13988 13989 /* force 57811 according to MISC register */ 13990 if (REG_RD(sc, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) { 13991 if (CHIP_IS_57810(sc)) { 13992 sc->devinfo.chip_id = ((CHIP_NUM_57811 << 16) | 13993 (sc->devinfo.chip_id & 0x0000ffff)); 13994 } else if (CHIP_IS_57810_MF(sc)) { 13995 sc->devinfo.chip_id = ((CHIP_NUM_57811_MF << 16) | 13996 (sc->devinfo.chip_id & 0x0000ffff)); 13997 } 13998 sc->devinfo.chip_id |= 0x1; 13999 } 14000 14001 BLOGD(sc, DBG_LOAD, 14002 "chip_id=0x%08x (num=0x%04x rev=0x%01x metal=0x%02x bond=0x%01x)\n", 14003 sc->devinfo.chip_id, 14004 ((sc->devinfo.chip_id >> 16) & 0xffff), 14005 ((sc->devinfo.chip_id >> 12) & 0xf), 14006 ((sc->devinfo.chip_id >> 4) & 0xff), 14007 ((sc->devinfo.chip_id >> 0) & 0xf)); 14008 14009 val = (REG_RD(sc, 0x2874) & 0x55); 14010 if ((sc->devinfo.chip_id & 0x1) || 14011 (CHIP_IS_E1(sc) && val) || 14012 (CHIP_IS_E1H(sc) && (val == 0x55))) { 14013 sc->flags |= BXE_ONE_PORT_FLAG; 14014 BLOGD(sc, DBG_LOAD, "single port device\n"); 14015 } 14016 14017 /* set the doorbell size */ 14018 sc->doorbell_size = (1 << BXE_DB_SHIFT); 14019 14020 /* determine whether the device is in 2 port or 4 port mode */ 14021 sc->devinfo.chip_port_mode = CHIP_PORT_MODE_NONE; /* E1 & E1h*/ 14022 if (CHIP_IS_E2E3(sc)) { 14023 /* 14024 * Read port4mode_en_ovwr[0]: 14025 * If 1, four port mode is in port4mode_en_ovwr[1]. 14026 * If 0, four port mode is in port4mode_en[0]. 14027 */ 14028 val = REG_RD(sc, MISC_REG_PORT4MODE_EN_OVWR); 14029 if (val & 1) { 14030 val = ((val >> 1) & 1); 14031 } else { 14032 val = REG_RD(sc, MISC_REG_PORT4MODE_EN); 14033 } 14034 14035 sc->devinfo.chip_port_mode = 14036 (val) ? CHIP_4_PORT_MODE : CHIP_2_PORT_MODE; 14037 14038 BLOGD(sc, DBG_LOAD, "Port mode = %s\n", (val) ? "4" : "2"); 14039 } 14040 14041 /* get the function and path info for the device */ 14042 bxe_get_function_num(sc); 14043 14044 /* get the shared memory base address */ 14045 sc->devinfo.shmem_base = 14046 sc->link_params.shmem_base = 14047 REG_RD(sc, MISC_REG_SHARED_MEM_ADDR); 14048 sc->devinfo.shmem2_base = 14049 REG_RD(sc, (SC_PATH(sc) ? MISC_REG_GENERIC_CR_1 : 14050 MISC_REG_GENERIC_CR_0)); 14051 14052 BLOGD(sc, DBG_LOAD, "shmem_base=0x%08x, shmem2_base=0x%08x\n", 14053 sc->devinfo.shmem_base, sc->devinfo.shmem2_base); 14054 14055 if (!sc->devinfo.shmem_base) { 14056 /* this should ONLY prevent upcoming shmem reads */ 14057 BLOGI(sc, "MCP not active\n"); 14058 sc->flags |= BXE_NO_MCP_FLAG; 14059 return (0); 14060 } 14061 14062 /* make sure the shared memory contents are valid */ 14063 val = SHMEM_RD(sc, validity_map[SC_PORT(sc)]); 14064 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) != 14065 (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) { 14066 BLOGE(sc, "Invalid SHMEM validity signature: 0x%08x\n", val); 14067 return (0); 14068 } 14069 BLOGD(sc, DBG_LOAD, "Valid SHMEM validity signature: 0x%08x\n", val); 14070 14071 /* get the bootcode version */ 14072 sc->devinfo.bc_ver = SHMEM_RD(sc, dev_info.bc_rev); 14073 snprintf(sc->devinfo.bc_ver_str, 14074 sizeof(sc->devinfo.bc_ver_str), 14075 "%d.%d.%d", 14076 ((sc->devinfo.bc_ver >> 24) & 0xff), 14077 ((sc->devinfo.bc_ver >> 16) & 0xff), 14078 ((sc->devinfo.bc_ver >> 8) & 0xff)); 14079 BLOGD(sc, DBG_LOAD, "Bootcode version: %s\n", sc->devinfo.bc_ver_str); 14080 14081 /* get the bootcode shmem address */ 14082 sc->devinfo.mf_cfg_base = bxe_get_shmem_mf_cfg_base(sc); 14083 BLOGD(sc, DBG_LOAD, "mf_cfg_base=0x08%x \n", sc->devinfo.mf_cfg_base); 14084 14085 /* clean indirect addresses as they're not used */ 14086 pci_write_config(sc->dev, PCICFG_GRC_ADDRESS, 0, 4); 14087 if (IS_PF(sc)) { 14088 REG_WR(sc, PXP2_REG_PGL_ADDR_88_F0, 0); 14089 REG_WR(sc, PXP2_REG_PGL_ADDR_8C_F0, 0); 14090 REG_WR(sc, PXP2_REG_PGL_ADDR_90_F0, 0); 14091 REG_WR(sc, PXP2_REG_PGL_ADDR_94_F0, 0); 14092 if (CHIP_IS_E1x(sc)) { 14093 REG_WR(sc, PXP2_REG_PGL_ADDR_88_F1, 0); 14094 REG_WR(sc, PXP2_REG_PGL_ADDR_8C_F1, 0); 14095 REG_WR(sc, PXP2_REG_PGL_ADDR_90_F1, 0); 14096 REG_WR(sc, PXP2_REG_PGL_ADDR_94_F1, 0); 14097 } 14098 14099 /* 14100 * Enable internal target-read (in case we are probed after PF 14101 * FLR). Must be done prior to any BAR read access. Only for 14102 * 57712 and up 14103 */ 14104 if (!CHIP_IS_E1x(sc)) { 14105 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1); 14106 } 14107 } 14108 14109 /* get the nvram size */ 14110 val = REG_RD(sc, MCP_REG_MCPR_NVM_CFG4); 14111 sc->devinfo.flash_size = 14112 (NVRAM_1MB_SIZE << (val & MCPR_NVM_CFG4_FLASH_SIZE)); 14113 BLOGD(sc, DBG_LOAD, "nvram flash size: %d\n", sc->devinfo.flash_size); 14114 14115 /* get PCI capabilites */ 14116 bxe_probe_pci_caps(sc); 14117 14118 bxe_set_power_state(sc, PCI_PM_D0); 14119 14120 /* get various configuration parameters from shmem */ 14121 bxe_get_shmem_info(sc); 14122 14123 if (sc->devinfo.pcie_msix_cap_reg != 0) { 14124 val = pci_read_config(sc->dev, 14125 (sc->devinfo.pcie_msix_cap_reg + 14126 PCIR_MSIX_CTRL), 14127 2); 14128 sc->igu_sb_cnt = (val & PCIM_MSIXCTRL_TABLE_SIZE); 14129 } else { 14130 sc->igu_sb_cnt = 1; 14131 } 14132 14133 sc->igu_base_addr = BAR_IGU_INTMEM; 14134 14135 /* initialize IGU parameters */ 14136 if (CHIP_IS_E1x(sc)) { 14137 sc->devinfo.int_block = INT_BLOCK_HC; 14138 sc->igu_dsb_id = DEF_SB_IGU_ID; 14139 sc->igu_base_sb = 0; 14140 } else { 14141 sc->devinfo.int_block = INT_BLOCK_IGU; 14142 14143 /* do not allow device reset during IGU info preocessing */ 14144 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RESET); 14145 14146 val = REG_RD(sc, IGU_REG_BLOCK_CONFIGURATION); 14147 14148 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) { 14149 int tout = 5000; 14150 14151 BLOGD(sc, DBG_LOAD, "FORCING IGU Normal Mode\n"); 14152 14153 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN); 14154 REG_WR(sc, IGU_REG_BLOCK_CONFIGURATION, val); 14155 REG_WR(sc, IGU_REG_RESET_MEMORIES, 0x7f); 14156 14157 while (tout && REG_RD(sc, IGU_REG_RESET_MEMORIES)) { 14158 tout--; 14159 DELAY(1000); 14160 } 14161 14162 if (REG_RD(sc, IGU_REG_RESET_MEMORIES)) { 14163 BLOGD(sc, DBG_LOAD, "FORCING IGU Normal Mode failed!!!\n"); 14164 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET); 14165 return (-1); 14166 } 14167 } 14168 14169 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) { 14170 BLOGD(sc, DBG_LOAD, "IGU Backward Compatible Mode\n"); 14171 sc->devinfo.int_block |= INT_BLOCK_MODE_BW_COMP; 14172 } else { 14173 BLOGD(sc, DBG_LOAD, "IGU Normal Mode\n"); 14174 } 14175 14176 rc = bxe_get_igu_cam_info(sc); 14177 14178 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET); 14179 14180 if (rc) { 14181 return (rc); 14182 } 14183 } 14184 14185 /* 14186 * Get base FW non-default (fast path) status block ID. This value is 14187 * used to initialize the fw_sb_id saved on the fp/queue structure to 14188 * determine the id used by the FW. 14189 */ 14190 if (CHIP_IS_E1x(sc)) { 14191 sc->base_fw_ndsb = ((SC_PORT(sc) * FP_SB_MAX_E1x) + SC_L_ID(sc)); 14192 } else { 14193 /* 14194 * 57712+ - We currently use one FW SB per IGU SB (Rx and Tx of 14195 * the same queue are indicated on the same IGU SB). So we prefer 14196 * FW and IGU SBs to be the same value. 14197 */ 14198 sc->base_fw_ndsb = sc->igu_base_sb; 14199 } 14200 14201 BLOGD(sc, DBG_LOAD, 14202 "igu_dsb_id=%d igu_base_sb=%d igu_sb_cnt=%d base_fw_ndsb=%d\n", 14203 sc->igu_dsb_id, sc->igu_base_sb, 14204 sc->igu_sb_cnt, sc->base_fw_ndsb); 14205 14206 elink_phy_probe(&sc->link_params); 14207 14208 return (0); 14209 } 14210 14211 static void 14212 bxe_link_settings_supported(struct bxe_softc *sc, 14213 uint32_t switch_cfg) 14214 { 14215 uint32_t cfg_size = 0; 14216 uint32_t idx; 14217 uint8_t port = SC_PORT(sc); 14218 14219 /* aggregation of supported attributes of all external phys */ 14220 sc->port.supported[0] = 0; 14221 sc->port.supported[1] = 0; 14222 14223 switch (sc->link_params.num_phys) { 14224 case 1: 14225 sc->port.supported[0] = sc->link_params.phy[ELINK_INT_PHY].supported; 14226 cfg_size = 1; 14227 break; 14228 case 2: 14229 sc->port.supported[0] = sc->link_params.phy[ELINK_EXT_PHY1].supported; 14230 cfg_size = 1; 14231 break; 14232 case 3: 14233 if (sc->link_params.multi_phy_config & 14234 PORT_HW_CFG_PHY_SWAPPED_ENABLED) { 14235 sc->port.supported[1] = 14236 sc->link_params.phy[ELINK_EXT_PHY1].supported; 14237 sc->port.supported[0] = 14238 sc->link_params.phy[ELINK_EXT_PHY2].supported; 14239 } else { 14240 sc->port.supported[0] = 14241 sc->link_params.phy[ELINK_EXT_PHY1].supported; 14242 sc->port.supported[1] = 14243 sc->link_params.phy[ELINK_EXT_PHY2].supported; 14244 } 14245 cfg_size = 2; 14246 break; 14247 } 14248 14249 if (!(sc->port.supported[0] || sc->port.supported[1])) { 14250 BLOGE(sc, "Invalid phy config in NVRAM (PHY1=0x%08x PHY2=0x%08x)\n", 14251 SHMEM_RD(sc, 14252 dev_info.port_hw_config[port].external_phy_config), 14253 SHMEM_RD(sc, 14254 dev_info.port_hw_config[port].external_phy_config2)); 14255 return; 14256 } 14257 14258 if (CHIP_IS_E3(sc)) 14259 sc->port.phy_addr = REG_RD(sc, MISC_REG_WC0_CTRL_PHY_ADDR); 14260 else { 14261 switch (switch_cfg) { 14262 case ELINK_SWITCH_CFG_1G: 14263 sc->port.phy_addr = 14264 REG_RD(sc, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10); 14265 break; 14266 case ELINK_SWITCH_CFG_10G: 14267 sc->port.phy_addr = 14268 REG_RD(sc, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18); 14269 break; 14270 default: 14271 BLOGE(sc, "Invalid switch config in link_config=0x%08x\n", 14272 sc->port.link_config[0]); 14273 return; 14274 } 14275 } 14276 14277 BLOGD(sc, DBG_LOAD, "PHY addr 0x%08x\n", sc->port.phy_addr); 14278 14279 /* mask what we support according to speed_cap_mask per configuration */ 14280 for (idx = 0; idx < cfg_size; idx++) { 14281 if (!(sc->link_params.speed_cap_mask[idx] & 14282 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) { 14283 sc->port.supported[idx] &= ~ELINK_SUPPORTED_10baseT_Half; 14284 } 14285 14286 if (!(sc->link_params.speed_cap_mask[idx] & 14287 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL)) { 14288 sc->port.supported[idx] &= ~ELINK_SUPPORTED_10baseT_Full; 14289 } 14290 14291 if (!(sc->link_params.speed_cap_mask[idx] & 14292 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)) { 14293 sc->port.supported[idx] &= ~ELINK_SUPPORTED_100baseT_Half; 14294 } 14295 14296 if (!(sc->link_params.speed_cap_mask[idx] & 14297 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL)) { 14298 sc->port.supported[idx] &= ~ELINK_SUPPORTED_100baseT_Full; 14299 } 14300 14301 if (!(sc->link_params.speed_cap_mask[idx] & 14302 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) { 14303 sc->port.supported[idx] &= ~ELINK_SUPPORTED_1000baseT_Full; 14304 } 14305 14306 if (!(sc->link_params.speed_cap_mask[idx] & 14307 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)) { 14308 sc->port.supported[idx] &= ~ELINK_SUPPORTED_2500baseX_Full; 14309 } 14310 14311 if (!(sc->link_params.speed_cap_mask[idx] & 14312 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) { 14313 sc->port.supported[idx] &= ~ELINK_SUPPORTED_10000baseT_Full; 14314 } 14315 14316 if (!(sc->link_params.speed_cap_mask[idx] & 14317 PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)) { 14318 sc->port.supported[idx] &= ~ELINK_SUPPORTED_20000baseKR2_Full; 14319 } 14320 } 14321 14322 BLOGD(sc, DBG_LOAD, "PHY supported 0=0x%08x 1=0x%08x\n", 14323 sc->port.supported[0], sc->port.supported[1]); 14324 ELINK_DEBUG_P2(sc, "PHY supported 0=0x%08x 1=0x%08x\n", 14325 sc->port.supported[0], sc->port.supported[1]); 14326 } 14327 14328 static void 14329 bxe_link_settings_requested(struct bxe_softc *sc) 14330 { 14331 uint32_t link_config; 14332 uint32_t idx; 14333 uint32_t cfg_size = 0; 14334 14335 sc->port.advertising[0] = 0; 14336 sc->port.advertising[1] = 0; 14337 14338 switch (sc->link_params.num_phys) { 14339 case 1: 14340 case 2: 14341 cfg_size = 1; 14342 break; 14343 case 3: 14344 cfg_size = 2; 14345 break; 14346 } 14347 14348 for (idx = 0; idx < cfg_size; idx++) { 14349 sc->link_params.req_duplex[idx] = DUPLEX_FULL; 14350 link_config = sc->port.link_config[idx]; 14351 14352 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) { 14353 case PORT_FEATURE_LINK_SPEED_AUTO: 14354 if (sc->port.supported[idx] & ELINK_SUPPORTED_Autoneg) { 14355 sc->link_params.req_line_speed[idx] = ELINK_SPEED_AUTO_NEG; 14356 sc->port.advertising[idx] |= sc->port.supported[idx]; 14357 if (sc->link_params.phy[ELINK_EXT_PHY1].type == 14358 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) 14359 sc->port.advertising[idx] |= 14360 (ELINK_SUPPORTED_100baseT_Half | 14361 ELINK_SUPPORTED_100baseT_Full); 14362 } else { 14363 /* force 10G, no AN */ 14364 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10000; 14365 sc->port.advertising[idx] |= 14366 (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE); 14367 continue; 14368 } 14369 break; 14370 14371 case PORT_FEATURE_LINK_SPEED_10M_FULL: 14372 if (sc->port.supported[idx] & ELINK_SUPPORTED_10baseT_Full) { 14373 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10; 14374 sc->port.advertising[idx] |= (ADVERTISED_10baseT_Full | 14375 ADVERTISED_TP); 14376 } else { 14377 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x " 14378 "speed_cap_mask=0x%08x\n", 14379 link_config, sc->link_params.speed_cap_mask[idx]); 14380 return; 14381 } 14382 break; 14383 14384 case PORT_FEATURE_LINK_SPEED_10M_HALF: 14385 if (sc->port.supported[idx] & ELINK_SUPPORTED_10baseT_Half) { 14386 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10; 14387 sc->link_params.req_duplex[idx] = DUPLEX_HALF; 14388 sc->port.advertising[idx] |= (ADVERTISED_10baseT_Half | 14389 ADVERTISED_TP); 14390 ELINK_DEBUG_P1(sc, "driver requesting DUPLEX_HALF req_duplex = %x!\n", 14391 sc->link_params.req_duplex[idx]); 14392 } else { 14393 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x " 14394 "speed_cap_mask=0x%08x\n", 14395 link_config, sc->link_params.speed_cap_mask[idx]); 14396 return; 14397 } 14398 break; 14399 14400 case PORT_FEATURE_LINK_SPEED_100M_FULL: 14401 if (sc->port.supported[idx] & ELINK_SUPPORTED_100baseT_Full) { 14402 sc->link_params.req_line_speed[idx] = ELINK_SPEED_100; 14403 sc->port.advertising[idx] |= (ADVERTISED_100baseT_Full | 14404 ADVERTISED_TP); 14405 } else { 14406 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x " 14407 "speed_cap_mask=0x%08x\n", 14408 link_config, sc->link_params.speed_cap_mask[idx]); 14409 return; 14410 } 14411 break; 14412 14413 case PORT_FEATURE_LINK_SPEED_100M_HALF: 14414 if (sc->port.supported[idx] & ELINK_SUPPORTED_100baseT_Half) { 14415 sc->link_params.req_line_speed[idx] = ELINK_SPEED_100; 14416 sc->link_params.req_duplex[idx] = DUPLEX_HALF; 14417 sc->port.advertising[idx] |= (ADVERTISED_100baseT_Half | 14418 ADVERTISED_TP); 14419 } else { 14420 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x " 14421 "speed_cap_mask=0x%08x\n", 14422 link_config, sc->link_params.speed_cap_mask[idx]); 14423 return; 14424 } 14425 break; 14426 14427 case PORT_FEATURE_LINK_SPEED_1G: 14428 if (sc->port.supported[idx] & ELINK_SUPPORTED_1000baseT_Full) { 14429 sc->link_params.req_line_speed[idx] = ELINK_SPEED_1000; 14430 sc->port.advertising[idx] |= (ADVERTISED_1000baseT_Full | 14431 ADVERTISED_TP); 14432 } else { 14433 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x " 14434 "speed_cap_mask=0x%08x\n", 14435 link_config, sc->link_params.speed_cap_mask[idx]); 14436 return; 14437 } 14438 break; 14439 14440 case PORT_FEATURE_LINK_SPEED_2_5G: 14441 if (sc->port.supported[idx] & ELINK_SUPPORTED_2500baseX_Full) { 14442 sc->link_params.req_line_speed[idx] = ELINK_SPEED_2500; 14443 sc->port.advertising[idx] |= (ADVERTISED_2500baseX_Full | 14444 ADVERTISED_TP); 14445 } else { 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]); 14449 return; 14450 } 14451 break; 14452 14453 case PORT_FEATURE_LINK_SPEED_10G_CX4: 14454 if (sc->port.supported[idx] & ELINK_SUPPORTED_10000baseT_Full) { 14455 sc->link_params.req_line_speed[idx] = ELINK_SPEED_10000; 14456 sc->port.advertising[idx] |= (ADVERTISED_10000baseT_Full | 14457 ADVERTISED_FIBRE); 14458 } else { 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]); 14462 return; 14463 } 14464 break; 14465 14466 case PORT_FEATURE_LINK_SPEED_20G: 14467 sc->link_params.req_line_speed[idx] = ELINK_SPEED_20000; 14468 break; 14469 14470 default: 14471 BLOGE(sc, "Invalid NVRAM config link_config=0x%08x " 14472 "speed_cap_mask=0x%08x\n", 14473 link_config, sc->link_params.speed_cap_mask[idx]); 14474 sc->link_params.req_line_speed[idx] = ELINK_SPEED_AUTO_NEG; 14475 sc->port.advertising[idx] = sc->port.supported[idx]; 14476 break; 14477 } 14478 14479 sc->link_params.req_flow_ctrl[idx] = 14480 (link_config & PORT_FEATURE_FLOW_CONTROL_MASK); 14481 14482 if (sc->link_params.req_flow_ctrl[idx] == ELINK_FLOW_CTRL_AUTO) { 14483 if (!(sc->port.supported[idx] & ELINK_SUPPORTED_Autoneg)) { 14484 sc->link_params.req_flow_ctrl[idx] = ELINK_FLOW_CTRL_NONE; 14485 } else { 14486 bxe_set_requested_fc(sc); 14487 } 14488 } 14489 14490 BLOGD(sc, DBG_LOAD, "req_line_speed=%d req_duplex=%d " 14491 "req_flow_ctrl=0x%x advertising=0x%x\n", 14492 sc->link_params.req_line_speed[idx], 14493 sc->link_params.req_duplex[idx], 14494 sc->link_params.req_flow_ctrl[idx], 14495 sc->port.advertising[idx]); 14496 ELINK_DEBUG_P3(sc, "req_line_speed=%d req_duplex=%d " 14497 "advertising=0x%x\n", 14498 sc->link_params.req_line_speed[idx], 14499 sc->link_params.req_duplex[idx], 14500 sc->port.advertising[idx]); 14501 } 14502 } 14503 14504 static void 14505 bxe_get_phy_info(struct bxe_softc *sc) 14506 { 14507 uint8_t port = SC_PORT(sc); 14508 uint32_t config = sc->port.config; 14509 uint32_t eee_mode; 14510 14511 /* shmem data already read in bxe_get_shmem_info() */ 14512 14513 ELINK_DEBUG_P3(sc, "lane_config=0x%08x speed_cap_mask0=0x%08x " 14514 "link_config0=0x%08x\n", 14515 sc->link_params.lane_config, 14516 sc->link_params.speed_cap_mask[0], 14517 sc->port.link_config[0]); 14518 14519 14520 bxe_link_settings_supported(sc, sc->link_params.switch_cfg); 14521 bxe_link_settings_requested(sc); 14522 14523 if (sc->autogreeen == AUTO_GREEN_FORCE_ON) { 14524 sc->link_params.feature_config_flags |= 14525 ELINK_FEATURE_CONFIG_AUTOGREEEN_ENABLED; 14526 } else if (sc->autogreeen == AUTO_GREEN_FORCE_OFF) { 14527 sc->link_params.feature_config_flags &= 14528 ~ELINK_FEATURE_CONFIG_AUTOGREEEN_ENABLED; 14529 } else if (config & PORT_FEAT_CFG_AUTOGREEEN_ENABLED) { 14530 sc->link_params.feature_config_flags |= 14531 ELINK_FEATURE_CONFIG_AUTOGREEEN_ENABLED; 14532 } 14533 14534 /* configure link feature according to nvram value */ 14535 eee_mode = 14536 (((SHMEM_RD(sc, dev_info.port_feature_config[port].eee_power_mode)) & 14537 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >> 14538 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT); 14539 if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) { 14540 sc->link_params.eee_mode = (ELINK_EEE_MODE_ADV_LPI | 14541 ELINK_EEE_MODE_ENABLE_LPI | 14542 ELINK_EEE_MODE_OUTPUT_TIME); 14543 } else { 14544 sc->link_params.eee_mode = 0; 14545 } 14546 14547 /* get the media type */ 14548 bxe_media_detect(sc); 14549 ELINK_DEBUG_P1(sc, "detected media type\n", sc->media); 14550 } 14551 14552 static void 14553 bxe_get_params(struct bxe_softc *sc) 14554 { 14555 /* get user tunable params */ 14556 bxe_get_tunable_params(sc); 14557 14558 /* select the RX and TX ring sizes */ 14559 sc->tx_ring_size = TX_BD_USABLE; 14560 sc->rx_ring_size = RX_BD_USABLE; 14561 14562 /* XXX disable WoL */ 14563 sc->wol = 0; 14564 } 14565 14566 static void 14567 bxe_set_modes_bitmap(struct bxe_softc *sc) 14568 { 14569 uint32_t flags = 0; 14570 14571 if (CHIP_REV_IS_FPGA(sc)) { 14572 SET_FLAGS(flags, MODE_FPGA); 14573 } else if (CHIP_REV_IS_EMUL(sc)) { 14574 SET_FLAGS(flags, MODE_EMUL); 14575 } else { 14576 SET_FLAGS(flags, MODE_ASIC); 14577 } 14578 14579 if (CHIP_IS_MODE_4_PORT(sc)) { 14580 SET_FLAGS(flags, MODE_PORT4); 14581 } else { 14582 SET_FLAGS(flags, MODE_PORT2); 14583 } 14584 14585 if (CHIP_IS_E2(sc)) { 14586 SET_FLAGS(flags, MODE_E2); 14587 } else if (CHIP_IS_E3(sc)) { 14588 SET_FLAGS(flags, MODE_E3); 14589 if (CHIP_REV(sc) == CHIP_REV_Ax) { 14590 SET_FLAGS(flags, MODE_E3_A0); 14591 } else /*if (CHIP_REV(sc) == CHIP_REV_Bx)*/ { 14592 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3); 14593 } 14594 } 14595 14596 if (IS_MF(sc)) { 14597 SET_FLAGS(flags, MODE_MF); 14598 switch (sc->devinfo.mf_info.mf_mode) { 14599 case MULTI_FUNCTION_SD: 14600 SET_FLAGS(flags, MODE_MF_SD); 14601 break; 14602 case MULTI_FUNCTION_SI: 14603 SET_FLAGS(flags, MODE_MF_SI); 14604 break; 14605 case MULTI_FUNCTION_AFEX: 14606 SET_FLAGS(flags, MODE_MF_AFEX); 14607 break; 14608 } 14609 } else { 14610 SET_FLAGS(flags, MODE_SF); 14611 } 14612 14613 #if defined(__LITTLE_ENDIAN) 14614 SET_FLAGS(flags, MODE_LITTLE_ENDIAN); 14615 #else /* __BIG_ENDIAN */ 14616 SET_FLAGS(flags, MODE_BIG_ENDIAN); 14617 #endif 14618 14619 INIT_MODE_FLAGS(sc) = flags; 14620 } 14621 14622 static int 14623 bxe_alloc_hsi_mem(struct bxe_softc *sc) 14624 { 14625 struct bxe_fastpath *fp; 14626 bus_addr_t busaddr; 14627 int max_agg_queues; 14628 int max_segments; 14629 bus_size_t max_size; 14630 bus_size_t max_seg_size; 14631 char buf[32]; 14632 int rc; 14633 int i, j; 14634 14635 /* XXX zero out all vars here and call bxe_alloc_hsi_mem on error */ 14636 14637 /* allocate the parent bus DMA tag */ 14638 rc = bus_dma_tag_create(bus_get_dma_tag(sc->dev), /* parent tag */ 14639 1, /* alignment */ 14640 0, /* boundary limit */ 14641 BUS_SPACE_MAXADDR, /* restricted low */ 14642 BUS_SPACE_MAXADDR, /* restricted hi */ 14643 NULL, /* addr filter() */ 14644 NULL, /* addr filter() arg */ 14645 BUS_SPACE_MAXSIZE_32BIT, /* max map size */ 14646 BUS_SPACE_UNRESTRICTED, /* num discontinuous */ 14647 BUS_SPACE_MAXSIZE_32BIT, /* max seg size */ 14648 0, /* flags */ 14649 NULL, /* lock() */ 14650 NULL, /* lock() arg */ 14651 &sc->parent_dma_tag); /* returned dma tag */ 14652 if (rc != 0) { 14653 BLOGE(sc, "Failed to alloc parent DMA tag (%d)!\n", rc); 14654 return (1); 14655 } 14656 14657 /************************/ 14658 /* DEFAULT STATUS BLOCK */ 14659 /************************/ 14660 14661 if (bxe_dma_alloc(sc, sizeof(struct host_sp_status_block), 14662 &sc->def_sb_dma, "default status block") != 0) { 14663 /* XXX */ 14664 bus_dma_tag_destroy(sc->parent_dma_tag); 14665 return (1); 14666 } 14667 14668 sc->def_sb = (struct host_sp_status_block *)sc->def_sb_dma.vaddr; 14669 14670 /***************/ 14671 /* EVENT QUEUE */ 14672 /***************/ 14673 14674 if (bxe_dma_alloc(sc, BCM_PAGE_SIZE, 14675 &sc->eq_dma, "event queue") != 0) { 14676 /* XXX */ 14677 bxe_dma_free(sc, &sc->def_sb_dma); 14678 sc->def_sb = NULL; 14679 bus_dma_tag_destroy(sc->parent_dma_tag); 14680 return (1); 14681 } 14682 14683 sc->eq = (union event_ring_elem * )sc->eq_dma.vaddr; 14684 14685 /*************/ 14686 /* SLOW PATH */ 14687 /*************/ 14688 14689 if (bxe_dma_alloc(sc, sizeof(struct bxe_slowpath), 14690 &sc->sp_dma, "slow path") != 0) { 14691 /* XXX */ 14692 bxe_dma_free(sc, &sc->eq_dma); 14693 sc->eq = NULL; 14694 bxe_dma_free(sc, &sc->def_sb_dma); 14695 sc->def_sb = NULL; 14696 bus_dma_tag_destroy(sc->parent_dma_tag); 14697 return (1); 14698 } 14699 14700 sc->sp = (struct bxe_slowpath *)sc->sp_dma.vaddr; 14701 14702 /*******************/ 14703 /* SLOW PATH QUEUE */ 14704 /*******************/ 14705 14706 if (bxe_dma_alloc(sc, BCM_PAGE_SIZE, 14707 &sc->spq_dma, "slow path queue") != 0) { 14708 /* XXX */ 14709 bxe_dma_free(sc, &sc->sp_dma); 14710 sc->sp = NULL; 14711 bxe_dma_free(sc, &sc->eq_dma); 14712 sc->eq = NULL; 14713 bxe_dma_free(sc, &sc->def_sb_dma); 14714 sc->def_sb = NULL; 14715 bus_dma_tag_destroy(sc->parent_dma_tag); 14716 return (1); 14717 } 14718 14719 sc->spq = (struct eth_spe *)sc->spq_dma.vaddr; 14720 14721 /***************************/ 14722 /* FW DECOMPRESSION BUFFER */ 14723 /***************************/ 14724 14725 if (bxe_dma_alloc(sc, FW_BUF_SIZE, &sc->gz_buf_dma, 14726 "fw decompression buffer") != 0) { 14727 /* XXX */ 14728 bxe_dma_free(sc, &sc->spq_dma); 14729 sc->spq = NULL; 14730 bxe_dma_free(sc, &sc->sp_dma); 14731 sc->sp = NULL; 14732 bxe_dma_free(sc, &sc->eq_dma); 14733 sc->eq = NULL; 14734 bxe_dma_free(sc, &sc->def_sb_dma); 14735 sc->def_sb = NULL; 14736 bus_dma_tag_destroy(sc->parent_dma_tag); 14737 return (1); 14738 } 14739 14740 sc->gz_buf = (void *)sc->gz_buf_dma.vaddr; 14741 14742 if ((sc->gz_strm = 14743 malloc(sizeof(*sc->gz_strm), M_DEVBUF, M_NOWAIT)) == NULL) { 14744 /* XXX */ 14745 bxe_dma_free(sc, &sc->gz_buf_dma); 14746 sc->gz_buf = NULL; 14747 bxe_dma_free(sc, &sc->spq_dma); 14748 sc->spq = NULL; 14749 bxe_dma_free(sc, &sc->sp_dma); 14750 sc->sp = NULL; 14751 bxe_dma_free(sc, &sc->eq_dma); 14752 sc->eq = NULL; 14753 bxe_dma_free(sc, &sc->def_sb_dma); 14754 sc->def_sb = NULL; 14755 bus_dma_tag_destroy(sc->parent_dma_tag); 14756 return (1); 14757 } 14758 14759 /*************/ 14760 /* FASTPATHS */ 14761 /*************/ 14762 14763 /* allocate DMA memory for each fastpath structure */ 14764 for (i = 0; i < sc->num_queues; i++) { 14765 fp = &sc->fp[i]; 14766 fp->sc = sc; 14767 fp->index = i; 14768 14769 /*******************/ 14770 /* FP STATUS BLOCK */ 14771 /*******************/ 14772 14773 snprintf(buf, sizeof(buf), "fp %d status block", i); 14774 if (bxe_dma_alloc(sc, sizeof(union bxe_host_hc_status_block), 14775 &fp->sb_dma, buf) != 0) { 14776 /* XXX unwind and free previous fastpath allocations */ 14777 BLOGE(sc, "Failed to alloc %s\n", buf); 14778 return (1); 14779 } else { 14780 if (CHIP_IS_E2E3(sc)) { 14781 fp->status_block.e2_sb = 14782 (struct host_hc_status_block_e2 *)fp->sb_dma.vaddr; 14783 } else { 14784 fp->status_block.e1x_sb = 14785 (struct host_hc_status_block_e1x *)fp->sb_dma.vaddr; 14786 } 14787 } 14788 14789 /******************/ 14790 /* FP TX BD CHAIN */ 14791 /******************/ 14792 14793 snprintf(buf, sizeof(buf), "fp %d tx bd chain", i); 14794 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * TX_BD_NUM_PAGES), 14795 &fp->tx_dma, buf) != 0) { 14796 /* XXX unwind and free previous fastpath allocations */ 14797 BLOGE(sc, "Failed to alloc %s\n", buf); 14798 return (1); 14799 } else { 14800 fp->tx_chain = (union eth_tx_bd_types *)fp->tx_dma.vaddr; 14801 } 14802 14803 /* link together the tx bd chain pages */ 14804 for (j = 1; j <= TX_BD_NUM_PAGES; j++) { 14805 /* index into the tx bd chain array to last entry per page */ 14806 struct eth_tx_next_bd *tx_next_bd = 14807 &fp->tx_chain[TX_BD_TOTAL_PER_PAGE * j - 1].next_bd; 14808 /* point to the next page and wrap from last page */ 14809 busaddr = (fp->tx_dma.paddr + 14810 (BCM_PAGE_SIZE * (j % TX_BD_NUM_PAGES))); 14811 tx_next_bd->addr_hi = htole32(U64_HI(busaddr)); 14812 tx_next_bd->addr_lo = htole32(U64_LO(busaddr)); 14813 } 14814 14815 /******************/ 14816 /* FP RX BD CHAIN */ 14817 /******************/ 14818 14819 snprintf(buf, sizeof(buf), "fp %d rx bd chain", i); 14820 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * RX_BD_NUM_PAGES), 14821 &fp->rx_dma, buf) != 0) { 14822 /* XXX unwind and free previous fastpath allocations */ 14823 BLOGE(sc, "Failed to alloc %s\n", buf); 14824 return (1); 14825 } else { 14826 fp->rx_chain = (struct eth_rx_bd *)fp->rx_dma.vaddr; 14827 } 14828 14829 /* link together the rx bd chain pages */ 14830 for (j = 1; j <= RX_BD_NUM_PAGES; j++) { 14831 /* index into the rx bd chain array to last entry per page */ 14832 struct eth_rx_bd *rx_bd = 14833 &fp->rx_chain[RX_BD_TOTAL_PER_PAGE * j - 2]; 14834 /* point to the next page and wrap from last page */ 14835 busaddr = (fp->rx_dma.paddr + 14836 (BCM_PAGE_SIZE * (j % RX_BD_NUM_PAGES))); 14837 rx_bd->addr_hi = htole32(U64_HI(busaddr)); 14838 rx_bd->addr_lo = htole32(U64_LO(busaddr)); 14839 } 14840 14841 /*******************/ 14842 /* FP RX RCQ CHAIN */ 14843 /*******************/ 14844 14845 snprintf(buf, sizeof(buf), "fp %d rcq chain", i); 14846 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * RCQ_NUM_PAGES), 14847 &fp->rcq_dma, buf) != 0) { 14848 /* XXX unwind and free previous fastpath allocations */ 14849 BLOGE(sc, "Failed to alloc %s\n", buf); 14850 return (1); 14851 } else { 14852 fp->rcq_chain = (union eth_rx_cqe *)fp->rcq_dma.vaddr; 14853 } 14854 14855 /* link together the rcq chain pages */ 14856 for (j = 1; j <= RCQ_NUM_PAGES; j++) { 14857 /* index into the rcq chain array to last entry per page */ 14858 struct eth_rx_cqe_next_page *rx_cqe_next = 14859 (struct eth_rx_cqe_next_page *) 14860 &fp->rcq_chain[RCQ_TOTAL_PER_PAGE * j - 1]; 14861 /* point to the next page and wrap from last page */ 14862 busaddr = (fp->rcq_dma.paddr + 14863 (BCM_PAGE_SIZE * (j % RCQ_NUM_PAGES))); 14864 rx_cqe_next->addr_hi = htole32(U64_HI(busaddr)); 14865 rx_cqe_next->addr_lo = htole32(U64_LO(busaddr)); 14866 } 14867 14868 /*******************/ 14869 /* FP RX SGE CHAIN */ 14870 /*******************/ 14871 14872 snprintf(buf, sizeof(buf), "fp %d sge chain", i); 14873 if (bxe_dma_alloc(sc, (BCM_PAGE_SIZE * RX_SGE_NUM_PAGES), 14874 &fp->rx_sge_dma, buf) != 0) { 14875 /* XXX unwind and free previous fastpath allocations */ 14876 BLOGE(sc, "Failed to alloc %s\n", buf); 14877 return (1); 14878 } else { 14879 fp->rx_sge_chain = (struct eth_rx_sge *)fp->rx_sge_dma.vaddr; 14880 } 14881 14882 /* link together the sge chain pages */ 14883 for (j = 1; j <= RX_SGE_NUM_PAGES; j++) { 14884 /* index into the rcq chain array to last entry per page */ 14885 struct eth_rx_sge *rx_sge = 14886 &fp->rx_sge_chain[RX_SGE_TOTAL_PER_PAGE * j - 2]; 14887 /* point to the next page and wrap from last page */ 14888 busaddr = (fp->rx_sge_dma.paddr + 14889 (BCM_PAGE_SIZE * (j % RX_SGE_NUM_PAGES))); 14890 rx_sge->addr_hi = htole32(U64_HI(busaddr)); 14891 rx_sge->addr_lo = htole32(U64_LO(busaddr)); 14892 } 14893 14894 /***********************/ 14895 /* FP TX MBUF DMA MAPS */ 14896 /***********************/ 14897 14898 /* set required sizes before mapping to conserve resources */ 14899 if (if_getcapenable(sc->ifp) & (IFCAP_TSO4 | IFCAP_TSO6)) { 14900 max_size = BXE_TSO_MAX_SIZE; 14901 max_segments = BXE_TSO_MAX_SEGMENTS; 14902 max_seg_size = BXE_TSO_MAX_SEG_SIZE; 14903 } else { 14904 max_size = (MCLBYTES * BXE_MAX_SEGMENTS); 14905 max_segments = BXE_MAX_SEGMENTS; 14906 max_seg_size = MCLBYTES; 14907 } 14908 14909 /* create a dma tag for the tx mbufs */ 14910 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */ 14911 1, /* alignment */ 14912 0, /* boundary limit */ 14913 BUS_SPACE_MAXADDR, /* restricted low */ 14914 BUS_SPACE_MAXADDR, /* restricted hi */ 14915 NULL, /* addr filter() */ 14916 NULL, /* addr filter() arg */ 14917 max_size, /* max map size */ 14918 max_segments, /* num discontinuous */ 14919 max_seg_size, /* max seg size */ 14920 0, /* flags */ 14921 NULL, /* lock() */ 14922 NULL, /* lock() arg */ 14923 &fp->tx_mbuf_tag); /* returned dma tag */ 14924 if (rc != 0) { 14925 /* XXX unwind and free previous fastpath allocations */ 14926 BLOGE(sc, "Failed to create dma tag for " 14927 "'fp %d tx mbufs' (%d)\n", i, rc); 14928 return (1); 14929 } 14930 14931 /* create dma maps for each of the tx mbuf clusters */ 14932 for (j = 0; j < TX_BD_TOTAL; j++) { 14933 if (bus_dmamap_create(fp->tx_mbuf_tag, 14934 BUS_DMA_NOWAIT, 14935 &fp->tx_mbuf_chain[j].m_map)) { 14936 /* XXX unwind and free previous fastpath allocations */ 14937 BLOGE(sc, "Failed to create dma map for " 14938 "'fp %d tx mbuf %d' (%d)\n", i, j, rc); 14939 return (1); 14940 } 14941 } 14942 14943 /***********************/ 14944 /* FP RX MBUF DMA MAPS */ 14945 /***********************/ 14946 14947 /* create a dma tag for the rx mbufs */ 14948 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */ 14949 1, /* alignment */ 14950 0, /* boundary limit */ 14951 BUS_SPACE_MAXADDR, /* restricted low */ 14952 BUS_SPACE_MAXADDR, /* restricted hi */ 14953 NULL, /* addr filter() */ 14954 NULL, /* addr filter() arg */ 14955 MJUM9BYTES, /* max map size */ 14956 1, /* num discontinuous */ 14957 MJUM9BYTES, /* max seg size */ 14958 0, /* flags */ 14959 NULL, /* lock() */ 14960 NULL, /* lock() arg */ 14961 &fp->rx_mbuf_tag); /* returned dma tag */ 14962 if (rc != 0) { 14963 /* XXX unwind and free previous fastpath allocations */ 14964 BLOGE(sc, "Failed to create dma tag for " 14965 "'fp %d rx mbufs' (%d)\n", i, rc); 14966 return (1); 14967 } 14968 14969 /* create dma maps for each of the rx mbuf clusters */ 14970 for (j = 0; j < RX_BD_TOTAL; j++) { 14971 if (bus_dmamap_create(fp->rx_mbuf_tag, 14972 BUS_DMA_NOWAIT, 14973 &fp->rx_mbuf_chain[j].m_map)) { 14974 /* XXX unwind and free previous fastpath allocations */ 14975 BLOGE(sc, "Failed to create dma map for " 14976 "'fp %d rx mbuf %d' (%d)\n", i, j, rc); 14977 return (1); 14978 } 14979 } 14980 14981 /* create dma map for the spare rx mbuf cluster */ 14982 if (bus_dmamap_create(fp->rx_mbuf_tag, 14983 BUS_DMA_NOWAIT, 14984 &fp->rx_mbuf_spare_map)) { 14985 /* XXX unwind and free previous fastpath allocations */ 14986 BLOGE(sc, "Failed to create dma map for " 14987 "'fp %d spare rx mbuf' (%d)\n", i, rc); 14988 return (1); 14989 } 14990 14991 /***************************/ 14992 /* FP RX SGE MBUF DMA MAPS */ 14993 /***************************/ 14994 14995 /* create a dma tag for the rx sge mbufs */ 14996 rc = bus_dma_tag_create(sc->parent_dma_tag, /* parent tag */ 14997 1, /* alignment */ 14998 0, /* boundary limit */ 14999 BUS_SPACE_MAXADDR, /* restricted low */ 15000 BUS_SPACE_MAXADDR, /* restricted hi */ 15001 NULL, /* addr filter() */ 15002 NULL, /* addr filter() arg */ 15003 BCM_PAGE_SIZE, /* max map size */ 15004 1, /* num discontinuous */ 15005 BCM_PAGE_SIZE, /* max seg size */ 15006 0, /* flags */ 15007 NULL, /* lock() */ 15008 NULL, /* lock() arg */ 15009 &fp->rx_sge_mbuf_tag); /* returned dma tag */ 15010 if (rc != 0) { 15011 /* XXX unwind and free previous fastpath allocations */ 15012 BLOGE(sc, "Failed to create dma tag for " 15013 "'fp %d rx sge mbufs' (%d)\n", i, rc); 15014 return (1); 15015 } 15016 15017 /* create dma maps for the rx sge mbuf clusters */ 15018 for (j = 0; j < RX_SGE_TOTAL; j++) { 15019 if (bus_dmamap_create(fp->rx_sge_mbuf_tag, 15020 BUS_DMA_NOWAIT, 15021 &fp->rx_sge_mbuf_chain[j].m_map)) { 15022 /* XXX unwind and free previous fastpath allocations */ 15023 BLOGE(sc, "Failed to create dma map for " 15024 "'fp %d rx sge mbuf %d' (%d)\n", i, j, rc); 15025 return (1); 15026 } 15027 } 15028 15029 /* create dma map for the spare rx sge mbuf cluster */ 15030 if (bus_dmamap_create(fp->rx_sge_mbuf_tag, 15031 BUS_DMA_NOWAIT, 15032 &fp->rx_sge_mbuf_spare_map)) { 15033 /* XXX unwind and free previous fastpath allocations */ 15034 BLOGE(sc, "Failed to create dma map for " 15035 "'fp %d spare rx sge mbuf' (%d)\n", i, rc); 15036 return (1); 15037 } 15038 15039 /***************************/ 15040 /* FP RX TPA MBUF DMA MAPS */ 15041 /***************************/ 15042 15043 /* create dma maps for the rx tpa mbuf clusters */ 15044 max_agg_queues = MAX_AGG_QS(sc); 15045 15046 for (j = 0; j < max_agg_queues; j++) { 15047 if (bus_dmamap_create(fp->rx_mbuf_tag, 15048 BUS_DMA_NOWAIT, 15049 &fp->rx_tpa_info[j].bd.m_map)) { 15050 /* XXX unwind and free previous fastpath allocations */ 15051 BLOGE(sc, "Failed to create dma map for " 15052 "'fp %d rx tpa mbuf %d' (%d)\n", i, j, rc); 15053 return (1); 15054 } 15055 } 15056 15057 /* create dma map for the spare rx tpa mbuf cluster */ 15058 if (bus_dmamap_create(fp->rx_mbuf_tag, 15059 BUS_DMA_NOWAIT, 15060 &fp->rx_tpa_info_mbuf_spare_map)) { 15061 /* XXX unwind and free previous fastpath allocations */ 15062 BLOGE(sc, "Failed to create dma map for " 15063 "'fp %d spare rx tpa mbuf' (%d)\n", i, rc); 15064 return (1); 15065 } 15066 15067 bxe_init_sge_ring_bit_mask(fp); 15068 } 15069 15070 return (0); 15071 } 15072 15073 static void 15074 bxe_free_hsi_mem(struct bxe_softc *sc) 15075 { 15076 struct bxe_fastpath *fp; 15077 int max_agg_queues; 15078 int i, j; 15079 15080 if (sc->parent_dma_tag == NULL) { 15081 return; /* assume nothing was allocated */ 15082 } 15083 15084 for (i = 0; i < sc->num_queues; i++) { 15085 fp = &sc->fp[i]; 15086 15087 /*******************/ 15088 /* FP STATUS BLOCK */ 15089 /*******************/ 15090 15091 bxe_dma_free(sc, &fp->sb_dma); 15092 memset(&fp->status_block, 0, sizeof(fp->status_block)); 15093 15094 /******************/ 15095 /* FP TX BD CHAIN */ 15096 /******************/ 15097 15098 bxe_dma_free(sc, &fp->tx_dma); 15099 fp->tx_chain = NULL; 15100 15101 /******************/ 15102 /* FP RX BD CHAIN */ 15103 /******************/ 15104 15105 bxe_dma_free(sc, &fp->rx_dma); 15106 fp->rx_chain = NULL; 15107 15108 /*******************/ 15109 /* FP RX RCQ CHAIN */ 15110 /*******************/ 15111 15112 bxe_dma_free(sc, &fp->rcq_dma); 15113 fp->rcq_chain = NULL; 15114 15115 /*******************/ 15116 /* FP RX SGE CHAIN */ 15117 /*******************/ 15118 15119 bxe_dma_free(sc, &fp->rx_sge_dma); 15120 fp->rx_sge_chain = NULL; 15121 15122 /***********************/ 15123 /* FP TX MBUF DMA MAPS */ 15124 /***********************/ 15125 15126 if (fp->tx_mbuf_tag != NULL) { 15127 for (j = 0; j < TX_BD_TOTAL; j++) { 15128 if (fp->tx_mbuf_chain[j].m_map != NULL) { 15129 bus_dmamap_unload(fp->tx_mbuf_tag, 15130 fp->tx_mbuf_chain[j].m_map); 15131 bus_dmamap_destroy(fp->tx_mbuf_tag, 15132 fp->tx_mbuf_chain[j].m_map); 15133 } 15134 } 15135 15136 bus_dma_tag_destroy(fp->tx_mbuf_tag); 15137 fp->tx_mbuf_tag = NULL; 15138 } 15139 15140 /***********************/ 15141 /* FP RX MBUF DMA MAPS */ 15142 /***********************/ 15143 15144 if (fp->rx_mbuf_tag != NULL) { 15145 for (j = 0; j < RX_BD_TOTAL; j++) { 15146 if (fp->rx_mbuf_chain[j].m_map != NULL) { 15147 bus_dmamap_unload(fp->rx_mbuf_tag, 15148 fp->rx_mbuf_chain[j].m_map); 15149 bus_dmamap_destroy(fp->rx_mbuf_tag, 15150 fp->rx_mbuf_chain[j].m_map); 15151 } 15152 } 15153 15154 if (fp->rx_mbuf_spare_map != NULL) { 15155 bus_dmamap_unload(fp->rx_mbuf_tag, fp->rx_mbuf_spare_map); 15156 bus_dmamap_destroy(fp->rx_mbuf_tag, fp->rx_mbuf_spare_map); 15157 } 15158 15159 /***************************/ 15160 /* FP RX TPA MBUF DMA MAPS */ 15161 /***************************/ 15162 15163 max_agg_queues = MAX_AGG_QS(sc); 15164 15165 for (j = 0; j < max_agg_queues; j++) { 15166 if (fp->rx_tpa_info[j].bd.m_map != NULL) { 15167 bus_dmamap_unload(fp->rx_mbuf_tag, 15168 fp->rx_tpa_info[j].bd.m_map); 15169 bus_dmamap_destroy(fp->rx_mbuf_tag, 15170 fp->rx_tpa_info[j].bd.m_map); 15171 } 15172 } 15173 15174 if (fp->rx_tpa_info_mbuf_spare_map != NULL) { 15175 bus_dmamap_unload(fp->rx_mbuf_tag, 15176 fp->rx_tpa_info_mbuf_spare_map); 15177 bus_dmamap_destroy(fp->rx_mbuf_tag, 15178 fp->rx_tpa_info_mbuf_spare_map); 15179 } 15180 15181 bus_dma_tag_destroy(fp->rx_mbuf_tag); 15182 fp->rx_mbuf_tag = NULL; 15183 } 15184 15185 /***************************/ 15186 /* FP RX SGE MBUF DMA MAPS */ 15187 /***************************/ 15188 15189 if (fp->rx_sge_mbuf_tag != NULL) { 15190 for (j = 0; j < RX_SGE_TOTAL; j++) { 15191 if (fp->rx_sge_mbuf_chain[j].m_map != NULL) { 15192 bus_dmamap_unload(fp->rx_sge_mbuf_tag, 15193 fp->rx_sge_mbuf_chain[j].m_map); 15194 bus_dmamap_destroy(fp->rx_sge_mbuf_tag, 15195 fp->rx_sge_mbuf_chain[j].m_map); 15196 } 15197 } 15198 15199 if (fp->rx_sge_mbuf_spare_map != NULL) { 15200 bus_dmamap_unload(fp->rx_sge_mbuf_tag, 15201 fp->rx_sge_mbuf_spare_map); 15202 bus_dmamap_destroy(fp->rx_sge_mbuf_tag, 15203 fp->rx_sge_mbuf_spare_map); 15204 } 15205 15206 bus_dma_tag_destroy(fp->rx_sge_mbuf_tag); 15207 fp->rx_sge_mbuf_tag = NULL; 15208 } 15209 } 15210 15211 /***************************/ 15212 /* FW DECOMPRESSION BUFFER */ 15213 /***************************/ 15214 15215 bxe_dma_free(sc, &sc->gz_buf_dma); 15216 sc->gz_buf = NULL; 15217 free(sc->gz_strm, M_DEVBUF); 15218 sc->gz_strm = NULL; 15219 15220 /*******************/ 15221 /* SLOW PATH QUEUE */ 15222 /*******************/ 15223 15224 bxe_dma_free(sc, &sc->spq_dma); 15225 sc->spq = NULL; 15226 15227 /*************/ 15228 /* SLOW PATH */ 15229 /*************/ 15230 15231 bxe_dma_free(sc, &sc->sp_dma); 15232 sc->sp = NULL; 15233 15234 /***************/ 15235 /* EVENT QUEUE */ 15236 /***************/ 15237 15238 bxe_dma_free(sc, &sc->eq_dma); 15239 sc->eq = NULL; 15240 15241 /************************/ 15242 /* DEFAULT STATUS BLOCK */ 15243 /************************/ 15244 15245 bxe_dma_free(sc, &sc->def_sb_dma); 15246 sc->def_sb = NULL; 15247 15248 bus_dma_tag_destroy(sc->parent_dma_tag); 15249 sc->parent_dma_tag = NULL; 15250 } 15251 15252 /* 15253 * Previous driver DMAE transaction may have occurred when pre-boot stage 15254 * ended and boot began. This would invalidate the addresses of the 15255 * transaction, resulting in was-error bit set in the PCI causing all 15256 * hw-to-host PCIe transactions to timeout. If this happened we want to clear 15257 * the interrupt which detected this from the pglueb and the was-done bit 15258 */ 15259 static void 15260 bxe_prev_interrupted_dmae(struct bxe_softc *sc) 15261 { 15262 uint32_t val; 15263 15264 if (!CHIP_IS_E1x(sc)) { 15265 val = REG_RD(sc, PGLUE_B_REG_PGLUE_B_INT_STS); 15266 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) { 15267 BLOGD(sc, DBG_LOAD, 15268 "Clearing 'was-error' bit that was set in pglueb"); 15269 REG_WR(sc, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, 1 << SC_FUNC(sc)); 15270 } 15271 } 15272 } 15273 15274 static int 15275 bxe_prev_mcp_done(struct bxe_softc *sc) 15276 { 15277 uint32_t rc = bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, 15278 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET); 15279 if (!rc) { 15280 BLOGE(sc, "MCP response failure, aborting\n"); 15281 return (-1); 15282 } 15283 15284 return (0); 15285 } 15286 15287 static struct bxe_prev_list_node * 15288 bxe_prev_path_get_entry(struct bxe_softc *sc) 15289 { 15290 struct bxe_prev_list_node *tmp; 15291 15292 LIST_FOREACH(tmp, &bxe_prev_list, node) { 15293 if ((sc->pcie_bus == tmp->bus) && 15294 (sc->pcie_device == tmp->slot) && 15295 (SC_PATH(sc) == tmp->path)) { 15296 return (tmp); 15297 } 15298 } 15299 15300 return (NULL); 15301 } 15302 15303 static uint8_t 15304 bxe_prev_is_path_marked(struct bxe_softc *sc) 15305 { 15306 struct bxe_prev_list_node *tmp; 15307 int rc = FALSE; 15308 15309 mtx_lock(&bxe_prev_mtx); 15310 15311 tmp = bxe_prev_path_get_entry(sc); 15312 if (tmp) { 15313 if (tmp->aer) { 15314 BLOGD(sc, DBG_LOAD, 15315 "Path %d/%d/%d was marked by AER\n", 15316 sc->pcie_bus, sc->pcie_device, SC_PATH(sc)); 15317 } else { 15318 rc = TRUE; 15319 BLOGD(sc, DBG_LOAD, 15320 "Path %d/%d/%d was already cleaned from previous drivers\n", 15321 sc->pcie_bus, sc->pcie_device, SC_PATH(sc)); 15322 } 15323 } 15324 15325 mtx_unlock(&bxe_prev_mtx); 15326 15327 return (rc); 15328 } 15329 15330 static int 15331 bxe_prev_mark_path(struct bxe_softc *sc, 15332 uint8_t after_undi) 15333 { 15334 struct bxe_prev_list_node *tmp; 15335 15336 mtx_lock(&bxe_prev_mtx); 15337 15338 /* Check whether the entry for this path already exists */ 15339 tmp = bxe_prev_path_get_entry(sc); 15340 if (tmp) { 15341 if (!tmp->aer) { 15342 BLOGD(sc, DBG_LOAD, 15343 "Re-marking AER in path %d/%d/%d\n", 15344 sc->pcie_bus, sc->pcie_device, SC_PATH(sc)); 15345 } else { 15346 BLOGD(sc, DBG_LOAD, 15347 "Removing AER indication from path %d/%d/%d\n", 15348 sc->pcie_bus, sc->pcie_device, SC_PATH(sc)); 15349 tmp->aer = 0; 15350 } 15351 15352 mtx_unlock(&bxe_prev_mtx); 15353 return (0); 15354 } 15355 15356 mtx_unlock(&bxe_prev_mtx); 15357 15358 /* Create an entry for this path and add it */ 15359 tmp = malloc(sizeof(struct bxe_prev_list_node), M_DEVBUF, 15360 (M_NOWAIT | M_ZERO)); 15361 if (!tmp) { 15362 BLOGE(sc, "Failed to allocate 'bxe_prev_list_node'\n"); 15363 return (-1); 15364 } 15365 15366 tmp->bus = sc->pcie_bus; 15367 tmp->slot = sc->pcie_device; 15368 tmp->path = SC_PATH(sc); 15369 tmp->aer = 0; 15370 tmp->undi = after_undi ? (1 << SC_PORT(sc)) : 0; 15371 15372 mtx_lock(&bxe_prev_mtx); 15373 15374 BLOGD(sc, DBG_LOAD, 15375 "Marked path %d/%d/%d - finished previous unload\n", 15376 sc->pcie_bus, sc->pcie_device, SC_PATH(sc)); 15377 LIST_INSERT_HEAD(&bxe_prev_list, tmp, node); 15378 15379 mtx_unlock(&bxe_prev_mtx); 15380 15381 return (0); 15382 } 15383 15384 static int 15385 bxe_do_flr(struct bxe_softc *sc) 15386 { 15387 int i; 15388 15389 /* only E2 and onwards support FLR */ 15390 if (CHIP_IS_E1x(sc)) { 15391 BLOGD(sc, DBG_LOAD, "FLR not supported in E1/E1H\n"); 15392 return (-1); 15393 } 15394 15395 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */ 15396 if (sc->devinfo.bc_ver < REQ_BC_VER_4_INITIATE_FLR) { 15397 BLOGD(sc, DBG_LOAD, "FLR not supported by BC_VER: 0x%08x\n", 15398 sc->devinfo.bc_ver); 15399 return (-1); 15400 } 15401 15402 /* Wait for Transaction Pending bit clean */ 15403 for (i = 0; i < 4; i++) { 15404 if (i) { 15405 DELAY(((1 << (i - 1)) * 100) * 1000); 15406 } 15407 15408 if (!bxe_is_pcie_pending(sc)) { 15409 goto clear; 15410 } 15411 } 15412 15413 BLOGE(sc, "PCIE transaction is not cleared, " 15414 "proceeding with reset anyway\n"); 15415 15416 clear: 15417 15418 BLOGD(sc, DBG_LOAD, "Initiating FLR\n"); 15419 bxe_fw_command(sc, DRV_MSG_CODE_INITIATE_FLR, 0); 15420 15421 return (0); 15422 } 15423 15424 struct bxe_mac_vals { 15425 uint32_t xmac_addr; 15426 uint32_t xmac_val; 15427 uint32_t emac_addr; 15428 uint32_t emac_val; 15429 uint32_t umac_addr; 15430 uint32_t umac_val; 15431 uint32_t bmac_addr; 15432 uint32_t bmac_val[2]; 15433 }; 15434 15435 static void 15436 bxe_prev_unload_close_mac(struct bxe_softc *sc, 15437 struct bxe_mac_vals *vals) 15438 { 15439 uint32_t val, base_addr, offset, mask, reset_reg; 15440 uint8_t mac_stopped = FALSE; 15441 uint8_t port = SC_PORT(sc); 15442 uint32_t wb_data[2]; 15443 15444 /* reset addresses as they also mark which values were changed */ 15445 vals->bmac_addr = 0; 15446 vals->umac_addr = 0; 15447 vals->xmac_addr = 0; 15448 vals->emac_addr = 0; 15449 15450 reset_reg = REG_RD(sc, MISC_REG_RESET_REG_2); 15451 15452 if (!CHIP_IS_E3(sc)) { 15453 val = REG_RD(sc, NIG_REG_BMAC0_REGS_OUT_EN + port * 4); 15454 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port; 15455 if ((mask & reset_reg) && val) { 15456 BLOGD(sc, DBG_LOAD, "Disable BMAC Rx\n"); 15457 base_addr = SC_PORT(sc) ? NIG_REG_INGRESS_BMAC1_MEM 15458 : NIG_REG_INGRESS_BMAC0_MEM; 15459 offset = CHIP_IS_E2(sc) ? BIGMAC2_REGISTER_BMAC_CONTROL 15460 : BIGMAC_REGISTER_BMAC_CONTROL; 15461 15462 /* 15463 * use rd/wr since we cannot use dmae. This is safe 15464 * since MCP won't access the bus due to the request 15465 * to unload, and no function on the path can be 15466 * loaded at this time. 15467 */ 15468 wb_data[0] = REG_RD(sc, base_addr + offset); 15469 wb_data[1] = REG_RD(sc, base_addr + offset + 0x4); 15470 vals->bmac_addr = base_addr + offset; 15471 vals->bmac_val[0] = wb_data[0]; 15472 vals->bmac_val[1] = wb_data[1]; 15473 wb_data[0] &= ~ELINK_BMAC_CONTROL_RX_ENABLE; 15474 REG_WR(sc, vals->bmac_addr, wb_data[0]); 15475 REG_WR(sc, vals->bmac_addr + 0x4, wb_data[1]); 15476 } 15477 15478 BLOGD(sc, DBG_LOAD, "Disable EMAC Rx\n"); 15479 vals->emac_addr = NIG_REG_NIG_EMAC0_EN + SC_PORT(sc)*4; 15480 vals->emac_val = REG_RD(sc, vals->emac_addr); 15481 REG_WR(sc, vals->emac_addr, 0); 15482 mac_stopped = TRUE; 15483 } else { 15484 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) { 15485 BLOGD(sc, DBG_LOAD, "Disable XMAC Rx\n"); 15486 base_addr = SC_PORT(sc) ? GRCBASE_XMAC1 : GRCBASE_XMAC0; 15487 val = REG_RD(sc, base_addr + XMAC_REG_PFC_CTRL_HI); 15488 REG_WR(sc, base_addr + XMAC_REG_PFC_CTRL_HI, val & ~(1 << 1)); 15489 REG_WR(sc, base_addr + XMAC_REG_PFC_CTRL_HI, val | (1 << 1)); 15490 vals->xmac_addr = base_addr + XMAC_REG_CTRL; 15491 vals->xmac_val = REG_RD(sc, vals->xmac_addr); 15492 REG_WR(sc, vals->xmac_addr, 0); 15493 mac_stopped = TRUE; 15494 } 15495 15496 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port; 15497 if (mask & reset_reg) { 15498 BLOGD(sc, DBG_LOAD, "Disable UMAC Rx\n"); 15499 base_addr = SC_PORT(sc) ? GRCBASE_UMAC1 : GRCBASE_UMAC0; 15500 vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG; 15501 vals->umac_val = REG_RD(sc, vals->umac_addr); 15502 REG_WR(sc, vals->umac_addr, 0); 15503 mac_stopped = TRUE; 15504 } 15505 } 15506 15507 if (mac_stopped) { 15508 DELAY(20000); 15509 } 15510 } 15511 15512 #define BXE_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4)) 15513 #define BXE_PREV_UNDI_RCQ(val) ((val) & 0xffff) 15514 #define BXE_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff) 15515 #define BXE_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq)) 15516 15517 static void 15518 bxe_prev_unload_undi_inc(struct bxe_softc *sc, 15519 uint8_t port, 15520 uint8_t inc) 15521 { 15522 uint16_t rcq, bd; 15523 uint32_t tmp_reg = REG_RD(sc, BXE_PREV_UNDI_PROD_ADDR(port)); 15524 15525 rcq = BXE_PREV_UNDI_RCQ(tmp_reg) + inc; 15526 bd = BXE_PREV_UNDI_BD(tmp_reg) + inc; 15527 15528 tmp_reg = BXE_PREV_UNDI_PROD(rcq, bd); 15529 REG_WR(sc, BXE_PREV_UNDI_PROD_ADDR(port), tmp_reg); 15530 15531 BLOGD(sc, DBG_LOAD, 15532 "UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n", 15533 port, bd, rcq); 15534 } 15535 15536 static int 15537 bxe_prev_unload_common(struct bxe_softc *sc) 15538 { 15539 uint32_t reset_reg, tmp_reg = 0, rc; 15540 uint8_t prev_undi = FALSE; 15541 struct bxe_mac_vals mac_vals; 15542 uint32_t timer_count = 1000; 15543 uint32_t prev_brb; 15544 15545 /* 15546 * It is possible a previous function received 'common' answer, 15547 * but hasn't loaded yet, therefore creating a scenario of 15548 * multiple functions receiving 'common' on the same path. 15549 */ 15550 BLOGD(sc, DBG_LOAD, "Common unload Flow\n"); 15551 15552 memset(&mac_vals, 0, sizeof(mac_vals)); 15553 15554 if (bxe_prev_is_path_marked(sc)) { 15555 return (bxe_prev_mcp_done(sc)); 15556 } 15557 15558 reset_reg = REG_RD(sc, MISC_REG_RESET_REG_1); 15559 15560 /* Reset should be performed after BRB is emptied */ 15561 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) { 15562 /* Close the MAC Rx to prevent BRB from filling up */ 15563 bxe_prev_unload_close_mac(sc, &mac_vals); 15564 15565 /* close LLH filters towards the BRB */ 15566 elink_set_rx_filter(&sc->link_params, 0); 15567 15568 /* 15569 * Check if the UNDI driver was previously loaded. 15570 * UNDI driver initializes CID offset for normal bell to 0x7 15571 */ 15572 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) { 15573 tmp_reg = REG_RD(sc, DORQ_REG_NORM_CID_OFST); 15574 if (tmp_reg == 0x7) { 15575 BLOGD(sc, DBG_LOAD, "UNDI previously loaded\n"); 15576 prev_undi = TRUE; 15577 /* clear the UNDI indication */ 15578 REG_WR(sc, DORQ_REG_NORM_CID_OFST, 0); 15579 /* clear possible idle check errors */ 15580 REG_RD(sc, NIG_REG_NIG_INT_STS_CLR_0); 15581 } 15582 } 15583 15584 /* wait until BRB is empty */ 15585 tmp_reg = REG_RD(sc, BRB1_REG_NUM_OF_FULL_BLOCKS); 15586 while (timer_count) { 15587 prev_brb = tmp_reg; 15588 15589 tmp_reg = REG_RD(sc, BRB1_REG_NUM_OF_FULL_BLOCKS); 15590 if (!tmp_reg) { 15591 break; 15592 } 15593 15594 BLOGD(sc, DBG_LOAD, "BRB still has 0x%08x\n", tmp_reg); 15595 15596 /* reset timer as long as BRB actually gets emptied */ 15597 if (prev_brb > tmp_reg) { 15598 timer_count = 1000; 15599 } else { 15600 timer_count--; 15601 } 15602 15603 /* If UNDI resides in memory, manually increment it */ 15604 if (prev_undi) { 15605 bxe_prev_unload_undi_inc(sc, SC_PORT(sc), 1); 15606 } 15607 15608 DELAY(10); 15609 } 15610 15611 if (!timer_count) { 15612 BLOGE(sc, "Failed to empty BRB\n"); 15613 } 15614 } 15615 15616 /* No packets are in the pipeline, path is ready for reset */ 15617 bxe_reset_common(sc); 15618 15619 if (mac_vals.xmac_addr) { 15620 REG_WR(sc, mac_vals.xmac_addr, mac_vals.xmac_val); 15621 } 15622 if (mac_vals.umac_addr) { 15623 REG_WR(sc, mac_vals.umac_addr, mac_vals.umac_val); 15624 } 15625 if (mac_vals.emac_addr) { 15626 REG_WR(sc, mac_vals.emac_addr, mac_vals.emac_val); 15627 } 15628 if (mac_vals.bmac_addr) { 15629 REG_WR(sc, mac_vals.bmac_addr, mac_vals.bmac_val[0]); 15630 REG_WR(sc, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]); 15631 } 15632 15633 rc = bxe_prev_mark_path(sc, prev_undi); 15634 if (rc) { 15635 bxe_prev_mcp_done(sc); 15636 return (rc); 15637 } 15638 15639 return (bxe_prev_mcp_done(sc)); 15640 } 15641 15642 static int 15643 bxe_prev_unload_uncommon(struct bxe_softc *sc) 15644 { 15645 int rc; 15646 15647 BLOGD(sc, DBG_LOAD, "Uncommon unload Flow\n"); 15648 15649 /* Test if previous unload process was already finished for this path */ 15650 if (bxe_prev_is_path_marked(sc)) { 15651 return (bxe_prev_mcp_done(sc)); 15652 } 15653 15654 BLOGD(sc, DBG_LOAD, "Path is unmarked\n"); 15655 15656 /* 15657 * If function has FLR capabilities, and existing FW version matches 15658 * the one required, then FLR will be sufficient to clean any residue 15659 * left by previous driver 15660 */ 15661 rc = bxe_nic_load_analyze_req(sc, FW_MSG_CODE_DRV_LOAD_FUNCTION); 15662 if (!rc) { 15663 /* fw version is good */ 15664 BLOGD(sc, DBG_LOAD, "FW version matches our own, attempting FLR\n"); 15665 rc = bxe_do_flr(sc); 15666 } 15667 15668 if (!rc) { 15669 /* FLR was performed */ 15670 BLOGD(sc, DBG_LOAD, "FLR successful\n"); 15671 return (0); 15672 } 15673 15674 BLOGD(sc, DBG_LOAD, "Could not FLR\n"); 15675 15676 /* Close the MCP request, return failure*/ 15677 rc = bxe_prev_mcp_done(sc); 15678 if (!rc) { 15679 rc = BXE_PREV_WAIT_NEEDED; 15680 } 15681 15682 return (rc); 15683 } 15684 15685 static int 15686 bxe_prev_unload(struct bxe_softc *sc) 15687 { 15688 int time_counter = 10; 15689 uint32_t fw, hw_lock_reg, hw_lock_val; 15690 uint32_t rc = 0; 15691 15692 /* 15693 * Clear HW from errors which may have resulted from an interrupted 15694 * DMAE transaction. 15695 */ 15696 bxe_prev_interrupted_dmae(sc); 15697 15698 /* Release previously held locks */ 15699 hw_lock_reg = 15700 (SC_FUNC(sc) <= 5) ? 15701 (MISC_REG_DRIVER_CONTROL_1 + SC_FUNC(sc) * 8) : 15702 (MISC_REG_DRIVER_CONTROL_7 + (SC_FUNC(sc) - 6) * 8); 15703 15704 hw_lock_val = (REG_RD(sc, hw_lock_reg)); 15705 if (hw_lock_val) { 15706 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) { 15707 BLOGD(sc, DBG_LOAD, "Releasing previously held NVRAM lock\n"); 15708 REG_WR(sc, MCP_REG_MCPR_NVM_SW_ARB, 15709 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << SC_PORT(sc))); 15710 } 15711 BLOGD(sc, DBG_LOAD, "Releasing previously held HW lock\n"); 15712 REG_WR(sc, hw_lock_reg, 0xffffffff); 15713 } else { 15714 BLOGD(sc, DBG_LOAD, "No need to release HW/NVRAM locks\n"); 15715 } 15716 15717 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(sc, MCP_REG_MCPR_ACCESS_LOCK)) { 15718 BLOGD(sc, DBG_LOAD, "Releasing previously held ALR\n"); 15719 REG_WR(sc, MCP_REG_MCPR_ACCESS_LOCK, 0); 15720 } 15721 15722 do { 15723 /* Lock MCP using an unload request */ 15724 fw = bxe_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0); 15725 if (!fw) { 15726 BLOGE(sc, "MCP response failure, aborting\n"); 15727 rc = -1; 15728 break; 15729 } 15730 15731 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) { 15732 rc = bxe_prev_unload_common(sc); 15733 break; 15734 } 15735 15736 /* non-common reply from MCP night require looping */ 15737 rc = bxe_prev_unload_uncommon(sc); 15738 if (rc != BXE_PREV_WAIT_NEEDED) { 15739 break; 15740 } 15741 15742 DELAY(20000); 15743 } while (--time_counter); 15744 15745 if (!time_counter || rc) { 15746 BLOGE(sc, "Failed to unload previous driver!" 15747 " time_counter %d rc %d\n", time_counter, rc); 15748 rc = -1; 15749 } 15750 15751 return (rc); 15752 } 15753 15754 void 15755 bxe_dcbx_set_state(struct bxe_softc *sc, 15756 uint8_t dcb_on, 15757 uint32_t dcbx_enabled) 15758 { 15759 if (!CHIP_IS_E1x(sc)) { 15760 sc->dcb_state = dcb_on; 15761 sc->dcbx_enabled = dcbx_enabled; 15762 } else { 15763 sc->dcb_state = FALSE; 15764 sc->dcbx_enabled = BXE_DCBX_ENABLED_INVALID; 15765 } 15766 BLOGD(sc, DBG_LOAD, 15767 "DCB state [%s:%s]\n", 15768 dcb_on ? "ON" : "OFF", 15769 (dcbx_enabled == BXE_DCBX_ENABLED_OFF) ? "user-mode" : 15770 (dcbx_enabled == BXE_DCBX_ENABLED_ON_NEG_OFF) ? "on-chip static" : 15771 (dcbx_enabled == BXE_DCBX_ENABLED_ON_NEG_ON) ? 15772 "on-chip with negotiation" : "invalid"); 15773 } 15774 15775 /* must be called after sriov-enable */ 15776 static int 15777 bxe_set_qm_cid_count(struct bxe_softc *sc) 15778 { 15779 int cid_count = BXE_L2_MAX_CID(sc); 15780 15781 if (IS_SRIOV(sc)) { 15782 cid_count += BXE_VF_CIDS; 15783 } 15784 15785 if (CNIC_SUPPORT(sc)) { 15786 cid_count += CNIC_CID_MAX; 15787 } 15788 15789 return (roundup(cid_count, QM_CID_ROUND)); 15790 } 15791 15792 static void 15793 bxe_init_multi_cos(struct bxe_softc *sc) 15794 { 15795 int pri, cos; 15796 15797 uint32_t pri_map = 0; /* XXX change to user config */ 15798 15799 for (pri = 0; pri < BXE_MAX_PRIORITY; pri++) { 15800 cos = ((pri_map & (0xf << (pri * 4))) >> (pri * 4)); 15801 if (cos < sc->max_cos) { 15802 sc->prio_to_cos[pri] = cos; 15803 } else { 15804 BLOGW(sc, "Invalid COS %d for priority %d " 15805 "(max COS is %d), setting to 0\n", 15806 cos, pri, (sc->max_cos - 1)); 15807 sc->prio_to_cos[pri] = 0; 15808 } 15809 } 15810 } 15811 15812 static int 15813 bxe_sysctl_state(SYSCTL_HANDLER_ARGS) 15814 { 15815 struct bxe_softc *sc; 15816 int error, result; 15817 15818 result = 0; 15819 error = sysctl_handle_int(oidp, &result, 0, req); 15820 15821 if (error || !req->newptr) { 15822 return (error); 15823 } 15824 15825 if (result == 1) { 15826 uint32_t temp; 15827 sc = (struct bxe_softc *)arg1; 15828 15829 BLOGI(sc, "... dumping driver state ...\n"); 15830 temp = SHMEM2_RD(sc, temperature_in_half_celsius); 15831 BLOGI(sc, "\t Device Temperature = %d Celsius\n", (temp/2)); 15832 } 15833 15834 return (error); 15835 } 15836 15837 static int 15838 bxe_sysctl_eth_stat(SYSCTL_HANDLER_ARGS) 15839 { 15840 struct bxe_softc *sc = (struct bxe_softc *)arg1; 15841 uint32_t *eth_stats = (uint32_t *)&sc->eth_stats; 15842 uint32_t *offset; 15843 uint64_t value = 0; 15844 int index = (int)arg2; 15845 15846 if (index >= BXE_NUM_ETH_STATS) { 15847 BLOGE(sc, "bxe_eth_stats index out of range (%d)\n", index); 15848 return (-1); 15849 } 15850 15851 offset = (eth_stats + bxe_eth_stats_arr[index].offset); 15852 15853 switch (bxe_eth_stats_arr[index].size) { 15854 case 4: 15855 value = (uint64_t)*offset; 15856 break; 15857 case 8: 15858 value = HILO_U64(*offset, *(offset + 1)); 15859 break; 15860 default: 15861 BLOGE(sc, "Invalid bxe_eth_stats size (index=%d size=%d)\n", 15862 index, bxe_eth_stats_arr[index].size); 15863 return (-1); 15864 } 15865 15866 return (sysctl_handle_64(oidp, &value, 0, req)); 15867 } 15868 15869 static int 15870 bxe_sysctl_eth_q_stat(SYSCTL_HANDLER_ARGS) 15871 { 15872 struct bxe_softc *sc = (struct bxe_softc *)arg1; 15873 uint32_t *eth_stats; 15874 uint32_t *offset; 15875 uint64_t value = 0; 15876 uint32_t q_stat = (uint32_t)arg2; 15877 uint32_t fp_index = ((q_stat >> 16) & 0xffff); 15878 uint32_t index = (q_stat & 0xffff); 15879 15880 eth_stats = (uint32_t *)&sc->fp[fp_index].eth_q_stats; 15881 15882 if (index >= BXE_NUM_ETH_Q_STATS) { 15883 BLOGE(sc, "bxe_eth_q_stats index out of range (%d)\n", index); 15884 return (-1); 15885 } 15886 15887 offset = (eth_stats + bxe_eth_q_stats_arr[index].offset); 15888 15889 switch (bxe_eth_q_stats_arr[index].size) { 15890 case 4: 15891 value = (uint64_t)*offset; 15892 break; 15893 case 8: 15894 value = HILO_U64(*offset, *(offset + 1)); 15895 break; 15896 default: 15897 BLOGE(sc, "Invalid bxe_eth_q_stats size (index=%d size=%d)\n", 15898 index, bxe_eth_q_stats_arr[index].size); 15899 return (-1); 15900 } 15901 15902 return (sysctl_handle_64(oidp, &value, 0, req)); 15903 } 15904 15905 static void bxe_force_link_reset(struct bxe_softc *sc) 15906 { 15907 15908 bxe_acquire_phy_lock(sc); 15909 elink_link_reset(&sc->link_params, &sc->link_vars, 1); 15910 bxe_release_phy_lock(sc); 15911 } 15912 15913 static int 15914 bxe_sysctl_pauseparam(SYSCTL_HANDLER_ARGS) 15915 { 15916 struct bxe_softc *sc = (struct bxe_softc *)arg1; 15917 uint32_t cfg_idx = bxe_get_link_cfg_idx(sc); 15918 int rc = 0; 15919 int error; 15920 int result; 15921 15922 15923 error = sysctl_handle_int(oidp, &sc->bxe_pause_param, 0, req); 15924 15925 if (error || !req->newptr) { 15926 return (error); 15927 } 15928 if ((sc->bxe_pause_param < 0) || (sc->bxe_pause_param > 8)) { 15929 BLOGW(sc, "invalid pause param (%d) - use integers between 1 & 8\n",sc->bxe_pause_param); 15930 sc->bxe_pause_param = 8; 15931 } 15932 15933 result = (sc->bxe_pause_param << PORT_FEATURE_FLOW_CONTROL_SHIFT); 15934 15935 15936 if((result & 0x400) && !(sc->port.supported[cfg_idx] & ELINK_SUPPORTED_Autoneg)) { 15937 BLOGW(sc, "Does not support Autoneg pause_param %d\n", sc->bxe_pause_param); 15938 return -EINVAL; 15939 } 15940 15941 if(IS_MF(sc)) 15942 return 0; 15943 sc->link_params.req_flow_ctrl[cfg_idx] = ELINK_FLOW_CTRL_AUTO; 15944 if(result & ELINK_FLOW_CTRL_RX) 15945 sc->link_params.req_flow_ctrl[cfg_idx] |= ELINK_FLOW_CTRL_RX; 15946 15947 if(result & ELINK_FLOW_CTRL_TX) 15948 sc->link_params.req_flow_ctrl[cfg_idx] |= ELINK_FLOW_CTRL_TX; 15949 if(sc->link_params.req_flow_ctrl[cfg_idx] == ELINK_FLOW_CTRL_AUTO) 15950 sc->link_params.req_flow_ctrl[cfg_idx] = ELINK_FLOW_CTRL_NONE; 15951 15952 if(result & 0x400) { 15953 if (sc->link_params.req_line_speed[cfg_idx] == ELINK_SPEED_AUTO_NEG) { 15954 sc->link_params.req_flow_ctrl[cfg_idx] = 15955 ELINK_FLOW_CTRL_AUTO; 15956 } 15957 sc->link_params.req_fc_auto_adv = 0; 15958 if (result & ELINK_FLOW_CTRL_RX) 15959 sc->link_params.req_fc_auto_adv |= ELINK_FLOW_CTRL_RX; 15960 15961 if (result & ELINK_FLOW_CTRL_TX) 15962 sc->link_params.req_fc_auto_adv |= ELINK_FLOW_CTRL_TX; 15963 if (!sc->link_params.req_fc_auto_adv) 15964 sc->link_params.req_fc_auto_adv |= ELINK_FLOW_CTRL_NONE; 15965 } 15966 if (IS_PF(sc)) { 15967 if (sc->link_vars.link_up) { 15968 bxe_stats_handle(sc, STATS_EVENT_STOP); 15969 } 15970 if (if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING) { 15971 bxe_force_link_reset(sc); 15972 bxe_acquire_phy_lock(sc); 15973 15974 rc = elink_phy_init(&sc->link_params, &sc->link_vars); 15975 15976 bxe_release_phy_lock(sc); 15977 15978 bxe_calc_fc_adv(sc); 15979 } 15980 } 15981 return rc; 15982 } 15983 15984 15985 static void 15986 bxe_add_sysctls(struct bxe_softc *sc) 15987 { 15988 struct sysctl_ctx_list *ctx; 15989 struct sysctl_oid_list *children; 15990 struct sysctl_oid *queue_top, *queue; 15991 struct sysctl_oid_list *queue_top_children, *queue_children; 15992 char queue_num_buf[32]; 15993 uint32_t q_stat; 15994 int i, j; 15995 15996 ctx = device_get_sysctl_ctx(sc->dev); 15997 children = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)); 15998 15999 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "version", 16000 CTLFLAG_RD, BXE_DRIVER_VERSION, 0, 16001 "version"); 16002 16003 snprintf(sc->fw_ver_str, sizeof(sc->fw_ver_str), "%d.%d.%d.%d", 16004 BCM_5710_FW_MAJOR_VERSION, 16005 BCM_5710_FW_MINOR_VERSION, 16006 BCM_5710_FW_REVISION_VERSION, 16007 BCM_5710_FW_ENGINEERING_VERSION); 16008 16009 snprintf(sc->mf_mode_str, sizeof(sc->mf_mode_str), "%s", 16010 ((sc->devinfo.mf_info.mf_mode == SINGLE_FUNCTION) ? "Single" : 16011 (sc->devinfo.mf_info.mf_mode == MULTI_FUNCTION_SD) ? "MF-SD" : 16012 (sc->devinfo.mf_info.mf_mode == MULTI_FUNCTION_SI) ? "MF-SI" : 16013 (sc->devinfo.mf_info.mf_mode == MULTI_FUNCTION_AFEX) ? "MF-AFEX" : 16014 "Unknown")); 16015 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "mf_vnics", 16016 CTLFLAG_RD, &sc->devinfo.mf_info.vnics_per_port, 0, 16017 "multifunction vnics per port"); 16018 16019 snprintf(sc->pci_link_str, sizeof(sc->pci_link_str), "%s x%d", 16020 ((sc->devinfo.pcie_link_speed == 1) ? "2.5GT/s" : 16021 (sc->devinfo.pcie_link_speed == 2) ? "5.0GT/s" : 16022 (sc->devinfo.pcie_link_speed == 4) ? "8.0GT/s" : 16023 "???GT/s"), 16024 sc->devinfo.pcie_link_width); 16025 16026 sc->debug = bxe_debug; 16027 16028 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "bc_version", 16029 CTLFLAG_RD, sc->devinfo.bc_ver_str, 0, 16030 "bootcode version"); 16031 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "fw_version", 16032 CTLFLAG_RD, sc->fw_ver_str, 0, 16033 "firmware version"); 16034 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "mf_mode", 16035 CTLFLAG_RD, sc->mf_mode_str, 0, 16036 "multifunction mode"); 16037 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "mac_addr", 16038 CTLFLAG_RD, sc->mac_addr_str, 0, 16039 "mac address"); 16040 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "pci_link", 16041 CTLFLAG_RD, sc->pci_link_str, 0, 16042 "pci link status"); 16043 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO, "debug", 16044 CTLFLAG_RW, &sc->debug, 16045 "debug logging mode"); 16046 16047 sc->trigger_grcdump = 0; 16048 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "trigger_grcdump", 16049 CTLFLAG_RW, &sc->trigger_grcdump, 0, 16050 "trigger grcdump should be invoked" 16051 " before collecting grcdump"); 16052 16053 sc->grcdump_started = 0; 16054 sc->grcdump_done = 0; 16055 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "grcdump_done", 16056 CTLFLAG_RD, &sc->grcdump_done, 0, 16057 "set by driver when grcdump is done"); 16058 16059 sc->rx_budget = bxe_rx_budget; 16060 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "rx_budget", 16061 CTLFLAG_RW, &sc->rx_budget, 0, 16062 "rx processing budget"); 16063 16064 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pause_param", 16065 CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, 0, 16066 bxe_sysctl_pauseparam, "IU", 16067 "need pause frames- DEF:0/TX:1/RX:2/BOTH:3/AUTO:4/AUTOTX:5/AUTORX:6/AUTORXTX:7/NONE:8"); 16068 16069 16070 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "state", 16071 CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, 0, 16072 bxe_sysctl_state, "IU", "dump driver state"); 16073 16074 for (i = 0; i < BXE_NUM_ETH_STATS; i++) { 16075 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, 16076 bxe_eth_stats_arr[i].string, 16077 CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, i, 16078 bxe_sysctl_eth_stat, "LU", bxe_eth_stats_arr[i].string); 16079 } 16080 16081 /* add a new parent node for all queues "dev.bxe.#.queue" */ 16082 queue_top = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "queue", 16083 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "queue"); 16084 queue_top_children = SYSCTL_CHILDREN(queue_top); 16085 16086 for (i = 0; i < sc->num_queues; i++) { 16087 /* add a new parent node for a single queue "dev.bxe.#.queue.#" */ 16088 snprintf(queue_num_buf, sizeof(queue_num_buf), "%d", i); 16089 queue = SYSCTL_ADD_NODE(ctx, queue_top_children, OID_AUTO, 16090 queue_num_buf, CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "single queue"); 16091 queue_children = SYSCTL_CHILDREN(queue); 16092 16093 for (j = 0; j < BXE_NUM_ETH_Q_STATS; j++) { 16094 q_stat = ((i << 16) | j); 16095 SYSCTL_ADD_PROC(ctx, queue_children, OID_AUTO, 16096 bxe_eth_q_stats_arr[j].string, 16097 CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, q_stat, 16098 bxe_sysctl_eth_q_stat, "LU", bxe_eth_q_stats_arr[j].string); 16099 } 16100 } 16101 } 16102 16103 static int 16104 bxe_alloc_buf_rings(struct bxe_softc *sc) 16105 { 16106 int i; 16107 struct bxe_fastpath *fp; 16108 16109 for (i = 0; i < sc->num_queues; i++) { 16110 16111 fp = &sc->fp[i]; 16112 16113 fp->tx_br = buf_ring_alloc(BXE_BR_SIZE, M_DEVBUF, 16114 M_NOWAIT, &fp->tx_mtx); 16115 if (fp->tx_br == NULL) 16116 return (-1); 16117 } 16118 16119 return (0); 16120 } 16121 16122 static void 16123 bxe_free_buf_rings(struct bxe_softc *sc) 16124 { 16125 int i; 16126 struct bxe_fastpath *fp; 16127 16128 for (i = 0; i < sc->num_queues; i++) { 16129 16130 fp = &sc->fp[i]; 16131 16132 if (fp->tx_br) { 16133 buf_ring_free(fp->tx_br, M_DEVBUF); 16134 fp->tx_br = NULL; 16135 } 16136 } 16137 } 16138 16139 static void 16140 bxe_init_fp_mutexs(struct bxe_softc *sc) 16141 { 16142 int i; 16143 struct bxe_fastpath *fp; 16144 16145 for (i = 0; i < sc->num_queues; i++) { 16146 16147 fp = &sc->fp[i]; 16148 16149 snprintf(fp->tx_mtx_name, sizeof(fp->tx_mtx_name), 16150 "bxe%d_fp%d_tx_lock", sc->unit, i); 16151 mtx_init(&fp->tx_mtx, fp->tx_mtx_name, NULL, MTX_DEF); 16152 16153 snprintf(fp->rx_mtx_name, sizeof(fp->rx_mtx_name), 16154 "bxe%d_fp%d_rx_lock", sc->unit, i); 16155 mtx_init(&fp->rx_mtx, fp->rx_mtx_name, NULL, MTX_DEF); 16156 } 16157 } 16158 16159 static void 16160 bxe_destroy_fp_mutexs(struct bxe_softc *sc) 16161 { 16162 int i; 16163 struct bxe_fastpath *fp; 16164 16165 for (i = 0; i < sc->num_queues; i++) { 16166 16167 fp = &sc->fp[i]; 16168 16169 if (mtx_initialized(&fp->tx_mtx)) { 16170 mtx_destroy(&fp->tx_mtx); 16171 } 16172 16173 if (mtx_initialized(&fp->rx_mtx)) { 16174 mtx_destroy(&fp->rx_mtx); 16175 } 16176 } 16177 } 16178 16179 16180 /* 16181 * Device attach function. 16182 * 16183 * Allocates device resources, performs secondary chip identification, and 16184 * initializes driver instance variables. This function is called from driver 16185 * load after a successful probe. 16186 * 16187 * Returns: 16188 * 0 = Success, >0 = Failure 16189 */ 16190 static int 16191 bxe_attach(device_t dev) 16192 { 16193 struct bxe_softc *sc; 16194 16195 sc = device_get_softc(dev); 16196 16197 BLOGD(sc, DBG_LOAD, "Starting attach...\n"); 16198 16199 sc->state = BXE_STATE_CLOSED; 16200 16201 sc->dev = dev; 16202 sc->unit = device_get_unit(dev); 16203 16204 BLOGD(sc, DBG_LOAD, "softc = %p\n", sc); 16205 16206 sc->pcie_bus = pci_get_bus(dev); 16207 sc->pcie_device = pci_get_slot(dev); 16208 sc->pcie_func = pci_get_function(dev); 16209 16210 /* enable bus master capability */ 16211 pci_enable_busmaster(dev); 16212 16213 /* get the BARs */ 16214 if (bxe_allocate_bars(sc) != 0) { 16215 return (ENXIO); 16216 } 16217 16218 /* initialize the mutexes */ 16219 bxe_init_mutexes(sc); 16220 16221 /* prepare the periodic callout */ 16222 callout_init(&sc->periodic_callout, 1); 16223 16224 /* prepare the chip taskqueue */ 16225 sc->chip_tq_flags = CHIP_TQ_NONE; 16226 snprintf(sc->chip_tq_name, sizeof(sc->chip_tq_name), 16227 "bxe%d_chip_tq", sc->unit); 16228 TASK_INIT(&sc->chip_tq_task, 0, bxe_handle_chip_tq, sc); 16229 sc->chip_tq = taskqueue_create(sc->chip_tq_name, M_NOWAIT, 16230 taskqueue_thread_enqueue, 16231 &sc->chip_tq); 16232 taskqueue_start_threads(&sc->chip_tq, 1, PWAIT, /* lower priority */ 16233 "%s", sc->chip_tq_name); 16234 16235 TIMEOUT_TASK_INIT(taskqueue_thread, 16236 &sc->sp_err_timeout_task, 0, bxe_sp_err_timeout_task, sc); 16237 16238 16239 /* get device info and set params */ 16240 if (bxe_get_device_info(sc) != 0) { 16241 BLOGE(sc, "getting device info\n"); 16242 bxe_deallocate_bars(sc); 16243 pci_disable_busmaster(dev); 16244 return (ENXIO); 16245 } 16246 16247 /* get final misc params */ 16248 bxe_get_params(sc); 16249 16250 /* set the default MTU (changed via ifconfig) */ 16251 sc->mtu = ETHERMTU; 16252 16253 bxe_set_modes_bitmap(sc); 16254 16255 /* XXX 16256 * If in AFEX mode and the function is configured for FCoE 16257 * then bail... no L2 allowed. 16258 */ 16259 16260 /* get phy settings from shmem and 'and' against admin settings */ 16261 bxe_get_phy_info(sc); 16262 16263 /* initialize the FreeBSD ifnet interface */ 16264 bxe_init_ifnet(sc); 16265 16266 if (bxe_add_cdev(sc) != 0) { 16267 if (sc->ifp != NULL) { 16268 ether_ifdetach(sc->ifp); 16269 } 16270 ifmedia_removeall(&sc->ifmedia); 16271 bxe_release_mutexes(sc); 16272 bxe_deallocate_bars(sc); 16273 pci_disable_busmaster(dev); 16274 return (ENXIO); 16275 } 16276 16277 /* allocate device interrupts */ 16278 if (bxe_interrupt_alloc(sc) != 0) { 16279 bxe_del_cdev(sc); 16280 if (sc->ifp != NULL) { 16281 ether_ifdetach(sc->ifp); 16282 } 16283 ifmedia_removeall(&sc->ifmedia); 16284 bxe_release_mutexes(sc); 16285 bxe_deallocate_bars(sc); 16286 pci_disable_busmaster(dev); 16287 return (ENXIO); 16288 } 16289 16290 bxe_init_fp_mutexs(sc); 16291 16292 if (bxe_alloc_buf_rings(sc) != 0) { 16293 bxe_free_buf_rings(sc); 16294 bxe_interrupt_free(sc); 16295 bxe_del_cdev(sc); 16296 if (sc->ifp != NULL) { 16297 ether_ifdetach(sc->ifp); 16298 } 16299 ifmedia_removeall(&sc->ifmedia); 16300 bxe_release_mutexes(sc); 16301 bxe_deallocate_bars(sc); 16302 pci_disable_busmaster(dev); 16303 return (ENXIO); 16304 } 16305 16306 /* allocate ilt */ 16307 if (bxe_alloc_ilt_mem(sc) != 0) { 16308 bxe_free_buf_rings(sc); 16309 bxe_interrupt_free(sc); 16310 bxe_del_cdev(sc); 16311 if (sc->ifp != NULL) { 16312 ether_ifdetach(sc->ifp); 16313 } 16314 ifmedia_removeall(&sc->ifmedia); 16315 bxe_release_mutexes(sc); 16316 bxe_deallocate_bars(sc); 16317 pci_disable_busmaster(dev); 16318 return (ENXIO); 16319 } 16320 16321 /* allocate the host hardware/software hsi structures */ 16322 if (bxe_alloc_hsi_mem(sc) != 0) { 16323 bxe_free_ilt_mem(sc); 16324 bxe_free_buf_rings(sc); 16325 bxe_interrupt_free(sc); 16326 bxe_del_cdev(sc); 16327 if (sc->ifp != NULL) { 16328 ether_ifdetach(sc->ifp); 16329 } 16330 ifmedia_removeall(&sc->ifmedia); 16331 bxe_release_mutexes(sc); 16332 bxe_deallocate_bars(sc); 16333 pci_disable_busmaster(dev); 16334 return (ENXIO); 16335 } 16336 16337 /* need to reset chip if UNDI was active */ 16338 if (IS_PF(sc) && !BXE_NOMCP(sc)) { 16339 /* init fw_seq */ 16340 sc->fw_seq = 16341 (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_mb_header) & 16342 DRV_MSG_SEQ_NUMBER_MASK); 16343 BLOGD(sc, DBG_LOAD, "prev unload fw_seq 0x%04x\n", sc->fw_seq); 16344 bxe_prev_unload(sc); 16345 } 16346 16347 #if 1 16348 /* XXX */ 16349 bxe_dcbx_set_state(sc, FALSE, BXE_DCBX_ENABLED_OFF); 16350 #else 16351 if (SHMEM2_HAS(sc, dcbx_lldp_params_offset) && 16352 SHMEM2_HAS(sc, dcbx_lldp_dcbx_stat_offset) && 16353 SHMEM2_RD(sc, dcbx_lldp_params_offset) && 16354 SHMEM2_RD(sc, dcbx_lldp_dcbx_stat_offset)) { 16355 bxe_dcbx_set_state(sc, TRUE, BXE_DCBX_ENABLED_ON_NEG_ON); 16356 bxe_dcbx_init_params(sc); 16357 } else { 16358 bxe_dcbx_set_state(sc, FALSE, BXE_DCBX_ENABLED_OFF); 16359 } 16360 #endif 16361 16362 /* calculate qm_cid_count */ 16363 sc->qm_cid_count = bxe_set_qm_cid_count(sc); 16364 BLOGD(sc, DBG_LOAD, "qm_cid_count=%d\n", sc->qm_cid_count); 16365 16366 sc->max_cos = 1; 16367 bxe_init_multi_cos(sc); 16368 16369 bxe_add_sysctls(sc); 16370 16371 return (0); 16372 } 16373 16374 /* 16375 * Device detach function. 16376 * 16377 * Stops the controller, resets the controller, and releases resources. 16378 * 16379 * Returns: 16380 * 0 = Success, >0 = Failure 16381 */ 16382 static int 16383 bxe_detach(device_t dev) 16384 { 16385 struct bxe_softc *sc; 16386 if_t ifp; 16387 16388 sc = device_get_softc(dev); 16389 16390 BLOGD(sc, DBG_LOAD, "Starting detach...\n"); 16391 16392 ifp = sc->ifp; 16393 if (ifp != NULL && if_vlantrunkinuse(ifp)) { 16394 BLOGE(sc, "Cannot detach while VLANs are in use.\n"); 16395 return(EBUSY); 16396 } 16397 16398 bxe_del_cdev(sc); 16399 16400 /* stop the periodic callout */ 16401 bxe_periodic_stop(sc); 16402 16403 /* stop the chip taskqueue */ 16404 atomic_store_rel_long(&sc->chip_tq_flags, CHIP_TQ_NONE); 16405 if (sc->chip_tq) { 16406 taskqueue_drain(sc->chip_tq, &sc->chip_tq_task); 16407 taskqueue_free(sc->chip_tq); 16408 sc->chip_tq = NULL; 16409 taskqueue_drain_timeout(taskqueue_thread, 16410 &sc->sp_err_timeout_task); 16411 } 16412 16413 /* stop and reset the controller if it was open */ 16414 if (sc->state != BXE_STATE_CLOSED) { 16415 BXE_CORE_LOCK(sc); 16416 bxe_nic_unload(sc, UNLOAD_CLOSE, TRUE); 16417 sc->state = BXE_STATE_DISABLED; 16418 BXE_CORE_UNLOCK(sc); 16419 } 16420 16421 /* release the network interface */ 16422 if (ifp != NULL) { 16423 ether_ifdetach(ifp); 16424 } 16425 ifmedia_removeall(&sc->ifmedia); 16426 16427 /* XXX do the following based on driver state... */ 16428 16429 /* free the host hardware/software hsi structures */ 16430 bxe_free_hsi_mem(sc); 16431 16432 /* free ilt */ 16433 bxe_free_ilt_mem(sc); 16434 16435 bxe_free_buf_rings(sc); 16436 16437 /* release the interrupts */ 16438 bxe_interrupt_free(sc); 16439 16440 /* Release the mutexes*/ 16441 bxe_destroy_fp_mutexs(sc); 16442 bxe_release_mutexes(sc); 16443 16444 16445 /* Release the PCIe BAR mapped memory */ 16446 bxe_deallocate_bars(sc); 16447 16448 /* Release the FreeBSD interface. */ 16449 if (sc->ifp != NULL) { 16450 if_free(sc->ifp); 16451 } 16452 16453 pci_disable_busmaster(dev); 16454 16455 return (0); 16456 } 16457 16458 /* 16459 * Device shutdown function. 16460 * 16461 * Stops and resets the controller. 16462 * 16463 * Returns: 16464 * Nothing 16465 */ 16466 static int 16467 bxe_shutdown(device_t dev) 16468 { 16469 struct bxe_softc *sc; 16470 16471 sc = device_get_softc(dev); 16472 16473 BLOGD(sc, DBG_LOAD, "Starting shutdown...\n"); 16474 16475 /* stop the periodic callout */ 16476 bxe_periodic_stop(sc); 16477 16478 if (sc->state != BXE_STATE_CLOSED) { 16479 BXE_CORE_LOCK(sc); 16480 bxe_nic_unload(sc, UNLOAD_NORMAL, FALSE); 16481 BXE_CORE_UNLOCK(sc); 16482 } 16483 16484 return (0); 16485 } 16486 16487 void 16488 bxe_igu_ack_sb(struct bxe_softc *sc, 16489 uint8_t igu_sb_id, 16490 uint8_t segment, 16491 uint16_t index, 16492 uint8_t op, 16493 uint8_t update) 16494 { 16495 uint32_t igu_addr = sc->igu_base_addr; 16496 igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8; 16497 bxe_igu_ack_sb_gen(sc, igu_sb_id, segment, index, op, update, igu_addr); 16498 } 16499 16500 static void 16501 bxe_igu_clear_sb_gen(struct bxe_softc *sc, 16502 uint8_t func, 16503 uint8_t idu_sb_id, 16504 uint8_t is_pf) 16505 { 16506 uint32_t data, ctl, cnt = 100; 16507 uint32_t igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA; 16508 uint32_t igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL; 16509 uint32_t igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4; 16510 uint32_t sb_bit = 1 << (idu_sb_id%32); 16511 uint32_t func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT; 16512 uint32_t addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id; 16513 16514 /* Not supported in BC mode */ 16515 if (CHIP_INT_MODE_IS_BC(sc)) { 16516 return; 16517 } 16518 16519 data = ((IGU_USE_REGISTER_cstorm_type_0_sb_cleanup << 16520 IGU_REGULAR_CLEANUP_TYPE_SHIFT) | 16521 IGU_REGULAR_CLEANUP_SET | 16522 IGU_REGULAR_BCLEANUP); 16523 16524 ctl = ((addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT) | 16525 (func_encode << IGU_CTRL_REG_FID_SHIFT) | 16526 (IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT)); 16527 16528 BLOGD(sc, DBG_LOAD, "write 0x%08x to IGU(via GRC) addr 0x%x\n", 16529 data, igu_addr_data); 16530 REG_WR(sc, igu_addr_data, data); 16531 16532 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle, 0, 0, 16533 BUS_SPACE_BARRIER_WRITE); 16534 mb(); 16535 16536 BLOGD(sc, DBG_LOAD, "write 0x%08x to IGU(via GRC) addr 0x%x\n", 16537 ctl, igu_addr_ctl); 16538 REG_WR(sc, igu_addr_ctl, ctl); 16539 16540 bus_space_barrier(sc->bar[BAR0].tag, sc->bar[BAR0].handle, 0, 0, 16541 BUS_SPACE_BARRIER_WRITE); 16542 mb(); 16543 16544 /* wait for clean up to finish */ 16545 while (!(REG_RD(sc, igu_addr_ack) & sb_bit) && --cnt) { 16546 DELAY(20000); 16547 } 16548 16549 if (!(REG_RD(sc, igu_addr_ack) & sb_bit)) { 16550 BLOGD(sc, DBG_LOAD, 16551 "Unable to finish IGU cleanup: " 16552 "idu_sb_id %d offset %d bit %d (cnt %d)\n", 16553 idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt); 16554 } 16555 } 16556 16557 static void 16558 bxe_igu_clear_sb(struct bxe_softc *sc, 16559 uint8_t idu_sb_id) 16560 { 16561 bxe_igu_clear_sb_gen(sc, SC_FUNC(sc), idu_sb_id, TRUE /*PF*/); 16562 } 16563 16564 16565 16566 16567 16568 16569 16570 /*******************/ 16571 /* ECORE CALLBACKS */ 16572 /*******************/ 16573 16574 static void 16575 bxe_reset_common(struct bxe_softc *sc) 16576 { 16577 uint32_t val = 0x1400; 16578 16579 /* reset_common */ 16580 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR), 0xd3ffff7f); 16581 16582 if (CHIP_IS_E3(sc)) { 16583 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0; 16584 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1; 16585 } 16586 16587 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR), val); 16588 } 16589 16590 static void 16591 bxe_common_init_phy(struct bxe_softc *sc) 16592 { 16593 uint32_t shmem_base[2]; 16594 uint32_t shmem2_base[2]; 16595 16596 /* Avoid common init in case MFW supports LFA */ 16597 if (SHMEM2_RD(sc, size) > 16598 (uint32_t)offsetof(struct shmem2_region, 16599 lfa_host_addr[SC_PORT(sc)])) { 16600 return; 16601 } 16602 16603 shmem_base[0] = sc->devinfo.shmem_base; 16604 shmem2_base[0] = sc->devinfo.shmem2_base; 16605 16606 if (!CHIP_IS_E1x(sc)) { 16607 shmem_base[1] = SHMEM2_RD(sc, other_shmem_base_addr); 16608 shmem2_base[1] = SHMEM2_RD(sc, other_shmem2_base_addr); 16609 } 16610 16611 bxe_acquire_phy_lock(sc); 16612 elink_common_init_phy(sc, shmem_base, shmem2_base, 16613 sc->devinfo.chip_id, 0); 16614 bxe_release_phy_lock(sc); 16615 } 16616 16617 static void 16618 bxe_pf_disable(struct bxe_softc *sc) 16619 { 16620 uint32_t val = REG_RD(sc, IGU_REG_PF_CONFIGURATION); 16621 16622 val &= ~IGU_PF_CONF_FUNC_EN; 16623 16624 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val); 16625 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0); 16626 REG_WR(sc, CFC_REG_WEAK_ENABLE_PF, 0); 16627 } 16628 16629 static void 16630 bxe_init_pxp(struct bxe_softc *sc) 16631 { 16632 uint16_t devctl; 16633 int r_order, w_order; 16634 16635 devctl = bxe_pcie_capability_read(sc, PCIER_DEVICE_CTL, 2); 16636 16637 BLOGD(sc, DBG_LOAD, "read 0x%08x from devctl\n", devctl); 16638 16639 w_order = ((devctl & PCIEM_CTL_MAX_PAYLOAD) >> 5); 16640 16641 if (sc->mrrs == -1) { 16642 r_order = ((devctl & PCIEM_CTL_MAX_READ_REQUEST) >> 12); 16643 } else { 16644 BLOGD(sc, DBG_LOAD, "forcing read order to %d\n", sc->mrrs); 16645 r_order = sc->mrrs; 16646 } 16647 16648 ecore_init_pxp_arb(sc, r_order, w_order); 16649 } 16650 16651 static uint32_t 16652 bxe_get_pretend_reg(struct bxe_softc *sc) 16653 { 16654 uint32_t base = PXP2_REG_PGL_PRETEND_FUNC_F0; 16655 uint32_t stride = (PXP2_REG_PGL_PRETEND_FUNC_F1 - base); 16656 return (base + (SC_ABS_FUNC(sc)) * stride); 16657 } 16658 16659 /* 16660 * Called only on E1H or E2. 16661 * When pretending to be PF, the pretend value is the function number 0..7. 16662 * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID 16663 * combination. 16664 */ 16665 static int 16666 bxe_pretend_func(struct bxe_softc *sc, 16667 uint16_t pretend_func_val) 16668 { 16669 uint32_t pretend_reg; 16670 16671 if (CHIP_IS_E1H(sc) && (pretend_func_val > E1H_FUNC_MAX)) { 16672 return (-1); 16673 } 16674 16675 /* get my own pretend register */ 16676 pretend_reg = bxe_get_pretend_reg(sc); 16677 REG_WR(sc, pretend_reg, pretend_func_val); 16678 REG_RD(sc, pretend_reg); 16679 return (0); 16680 } 16681 16682 static void 16683 bxe_iov_init_dmae(struct bxe_softc *sc) 16684 { 16685 return; 16686 } 16687 16688 static void 16689 bxe_iov_init_dq(struct bxe_softc *sc) 16690 { 16691 return; 16692 } 16693 16694 /* send a NIG loopback debug packet */ 16695 static void 16696 bxe_lb_pckt(struct bxe_softc *sc) 16697 { 16698 uint32_t wb_write[3]; 16699 16700 /* Ethernet source and destination addresses */ 16701 wb_write[0] = 0x55555555; 16702 wb_write[1] = 0x55555555; 16703 wb_write[2] = 0x20; /* SOP */ 16704 REG_WR_DMAE(sc, NIG_REG_DEBUG_PACKET_LB, wb_write, 3); 16705 16706 /* NON-IP protocol */ 16707 wb_write[0] = 0x09000000; 16708 wb_write[1] = 0x55555555; 16709 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */ 16710 REG_WR_DMAE(sc, NIG_REG_DEBUG_PACKET_LB, wb_write, 3); 16711 } 16712 16713 /* 16714 * Some of the internal memories are not directly readable from the driver. 16715 * To test them we send debug packets. 16716 */ 16717 static int 16718 bxe_int_mem_test(struct bxe_softc *sc) 16719 { 16720 int factor; 16721 int count, i; 16722 uint32_t val = 0; 16723 16724 if (CHIP_REV_IS_FPGA(sc)) { 16725 factor = 120; 16726 } else if (CHIP_REV_IS_EMUL(sc)) { 16727 factor = 200; 16728 } else { 16729 factor = 1; 16730 } 16731 16732 /* disable inputs of parser neighbor blocks */ 16733 REG_WR(sc, TSDM_REG_ENABLE_IN1, 0x0); 16734 REG_WR(sc, TCM_REG_PRS_IFEN, 0x0); 16735 REG_WR(sc, CFC_REG_DEBUG0, 0x1); 16736 REG_WR(sc, NIG_REG_PRS_REQ_IN_EN, 0x0); 16737 16738 /* write 0 to parser credits for CFC search request */ 16739 REG_WR(sc, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0); 16740 16741 /* send Ethernet packet */ 16742 bxe_lb_pckt(sc); 16743 16744 /* TODO do i reset NIG statistic? */ 16745 /* Wait until NIG register shows 1 packet of size 0x10 */ 16746 count = 1000 * factor; 16747 while (count) { 16748 bxe_read_dmae(sc, NIG_REG_STAT2_BRB_OCTET, 2); 16749 val = *BXE_SP(sc, wb_data[0]); 16750 if (val == 0x10) { 16751 break; 16752 } 16753 16754 DELAY(10000); 16755 count--; 16756 } 16757 16758 if (val != 0x10) { 16759 BLOGE(sc, "NIG timeout val=0x%x\n", val); 16760 return (-1); 16761 } 16762 16763 /* wait until PRS register shows 1 packet */ 16764 count = (1000 * factor); 16765 while (count) { 16766 val = REG_RD(sc, PRS_REG_NUM_OF_PACKETS); 16767 if (val == 1) { 16768 break; 16769 } 16770 16771 DELAY(10000); 16772 count--; 16773 } 16774 16775 if (val != 0x1) { 16776 BLOGE(sc, "PRS timeout val=0x%x\n", val); 16777 return (-2); 16778 } 16779 16780 /* Reset and init BRB, PRS */ 16781 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03); 16782 DELAY(50000); 16783 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03); 16784 DELAY(50000); 16785 ecore_init_block(sc, BLOCK_BRB1, PHASE_COMMON); 16786 ecore_init_block(sc, BLOCK_PRS, PHASE_COMMON); 16787 16788 /* Disable inputs of parser neighbor blocks */ 16789 REG_WR(sc, TSDM_REG_ENABLE_IN1, 0x0); 16790 REG_WR(sc, TCM_REG_PRS_IFEN, 0x0); 16791 REG_WR(sc, CFC_REG_DEBUG0, 0x1); 16792 REG_WR(sc, NIG_REG_PRS_REQ_IN_EN, 0x0); 16793 16794 /* Write 0 to parser credits for CFC search request */ 16795 REG_WR(sc, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0); 16796 16797 /* send 10 Ethernet packets */ 16798 for (i = 0; i < 10; i++) { 16799 bxe_lb_pckt(sc); 16800 } 16801 16802 /* Wait until NIG register shows 10+1 packets of size 11*0x10 = 0xb0 */ 16803 count = (1000 * factor); 16804 while (count) { 16805 bxe_read_dmae(sc, NIG_REG_STAT2_BRB_OCTET, 2); 16806 val = *BXE_SP(sc, wb_data[0]); 16807 if (val == 0xb0) { 16808 break; 16809 } 16810 16811 DELAY(10000); 16812 count--; 16813 } 16814 16815 if (val != 0xb0) { 16816 BLOGE(sc, "NIG timeout val=0x%x\n", val); 16817 return (-3); 16818 } 16819 16820 /* Wait until PRS register shows 2 packets */ 16821 val = REG_RD(sc, PRS_REG_NUM_OF_PACKETS); 16822 if (val != 2) { 16823 BLOGE(sc, "PRS timeout val=0x%x\n", val); 16824 } 16825 16826 /* Write 1 to parser credits for CFC search request */ 16827 REG_WR(sc, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1); 16828 16829 /* Wait until PRS register shows 3 packets */ 16830 DELAY(10000 * factor); 16831 16832 /* Wait until NIG register shows 1 packet of size 0x10 */ 16833 val = REG_RD(sc, PRS_REG_NUM_OF_PACKETS); 16834 if (val != 3) { 16835 BLOGE(sc, "PRS timeout val=0x%x\n", val); 16836 } 16837 16838 /* clear NIG EOP FIFO */ 16839 for (i = 0; i < 11; i++) { 16840 REG_RD(sc, NIG_REG_INGRESS_EOP_LB_FIFO); 16841 } 16842 16843 val = REG_RD(sc, NIG_REG_INGRESS_EOP_LB_EMPTY); 16844 if (val != 1) { 16845 BLOGE(sc, "clear of NIG failed val=0x%x\n", val); 16846 return (-4); 16847 } 16848 16849 /* Reset and init BRB, PRS, NIG */ 16850 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03); 16851 DELAY(50000); 16852 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03); 16853 DELAY(50000); 16854 ecore_init_block(sc, BLOCK_BRB1, PHASE_COMMON); 16855 ecore_init_block(sc, BLOCK_PRS, PHASE_COMMON); 16856 if (!CNIC_SUPPORT(sc)) { 16857 /* set NIC mode */ 16858 REG_WR(sc, PRS_REG_NIC_MODE, 1); 16859 } 16860 16861 /* Enable inputs of parser neighbor blocks */ 16862 REG_WR(sc, TSDM_REG_ENABLE_IN1, 0x7fffffff); 16863 REG_WR(sc, TCM_REG_PRS_IFEN, 0x1); 16864 REG_WR(sc, CFC_REG_DEBUG0, 0x0); 16865 REG_WR(sc, NIG_REG_PRS_REQ_IN_EN, 0x1); 16866 16867 return (0); 16868 } 16869 16870 static void 16871 bxe_setup_fan_failure_detection(struct bxe_softc *sc) 16872 { 16873 int is_required; 16874 uint32_t val; 16875 int port; 16876 16877 is_required = 0; 16878 val = (SHMEM_RD(sc, dev_info.shared_hw_config.config2) & 16879 SHARED_HW_CFG_FAN_FAILURE_MASK); 16880 16881 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED) { 16882 is_required = 1; 16883 } 16884 /* 16885 * The fan failure mechanism is usually related to the PHY type since 16886 * the power consumption of the board is affected by the PHY. Currently, 16887 * fan is required for most designs with SFX7101, BCM8727 and BCM8481. 16888 */ 16889 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE) { 16890 for (port = PORT_0; port < PORT_MAX; port++) { 16891 is_required |= elink_fan_failure_det_req(sc, 16892 sc->devinfo.shmem_base, 16893 sc->devinfo.shmem2_base, 16894 port); 16895 } 16896 } 16897 16898 BLOGD(sc, DBG_LOAD, "fan detection setting: %d\n", is_required); 16899 16900 if (is_required == 0) { 16901 return; 16902 } 16903 16904 /* Fan failure is indicated by SPIO 5 */ 16905 bxe_set_spio(sc, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z); 16906 16907 /* set to active low mode */ 16908 val = REG_RD(sc, MISC_REG_SPIO_INT); 16909 val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS); 16910 REG_WR(sc, MISC_REG_SPIO_INT, val); 16911 16912 /* enable interrupt to signal the IGU */ 16913 val = REG_RD(sc, MISC_REG_SPIO_EVENT_EN); 16914 val |= MISC_SPIO_SPIO5; 16915 REG_WR(sc, MISC_REG_SPIO_EVENT_EN, val); 16916 } 16917 16918 static void 16919 bxe_enable_blocks_attention(struct bxe_softc *sc) 16920 { 16921 uint32_t val; 16922 16923 REG_WR(sc, PXP_REG_PXP_INT_MASK_0, 0); 16924 if (!CHIP_IS_E1x(sc)) { 16925 REG_WR(sc, PXP_REG_PXP_INT_MASK_1, 0x40); 16926 } else { 16927 REG_WR(sc, PXP_REG_PXP_INT_MASK_1, 0); 16928 } 16929 REG_WR(sc, DORQ_REG_DORQ_INT_MASK, 0); 16930 REG_WR(sc, CFC_REG_CFC_INT_MASK, 0); 16931 /* 16932 * mask read length error interrupts in brb for parser 16933 * (parsing unit and 'checksum and crc' unit) 16934 * these errors are legal (PU reads fixed length and CAC can cause 16935 * read length error on truncated packets) 16936 */ 16937 REG_WR(sc, BRB1_REG_BRB1_INT_MASK, 0xFC00); 16938 REG_WR(sc, QM_REG_QM_INT_MASK, 0); 16939 REG_WR(sc, TM_REG_TM_INT_MASK, 0); 16940 REG_WR(sc, XSDM_REG_XSDM_INT_MASK_0, 0); 16941 REG_WR(sc, XSDM_REG_XSDM_INT_MASK_1, 0); 16942 REG_WR(sc, XCM_REG_XCM_INT_MASK, 0); 16943 /* REG_WR(sc, XSEM_REG_XSEM_INT_MASK_0, 0); */ 16944 /* REG_WR(sc, XSEM_REG_XSEM_INT_MASK_1, 0); */ 16945 REG_WR(sc, USDM_REG_USDM_INT_MASK_0, 0); 16946 REG_WR(sc, USDM_REG_USDM_INT_MASK_1, 0); 16947 REG_WR(sc, UCM_REG_UCM_INT_MASK, 0); 16948 /* REG_WR(sc, USEM_REG_USEM_INT_MASK_0, 0); */ 16949 /* REG_WR(sc, USEM_REG_USEM_INT_MASK_1, 0); */ 16950 REG_WR(sc, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0); 16951 REG_WR(sc, CSDM_REG_CSDM_INT_MASK_0, 0); 16952 REG_WR(sc, CSDM_REG_CSDM_INT_MASK_1, 0); 16953 REG_WR(sc, CCM_REG_CCM_INT_MASK, 0); 16954 /* REG_WR(sc, CSEM_REG_CSEM_INT_MASK_0, 0); */ 16955 /* REG_WR(sc, CSEM_REG_CSEM_INT_MASK_1, 0); */ 16956 16957 val = (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT | 16958 PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF | 16959 PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN); 16960 if (!CHIP_IS_E1x(sc)) { 16961 val |= (PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED | 16962 PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED); 16963 } 16964 REG_WR(sc, PXP2_REG_PXP2_INT_MASK_0, val); 16965 16966 REG_WR(sc, TSDM_REG_TSDM_INT_MASK_0, 0); 16967 REG_WR(sc, TSDM_REG_TSDM_INT_MASK_1, 0); 16968 REG_WR(sc, TCM_REG_TCM_INT_MASK, 0); 16969 /* REG_WR(sc, TSEM_REG_TSEM_INT_MASK_0, 0); */ 16970 16971 if (!CHIP_IS_E1x(sc)) { 16972 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */ 16973 REG_WR(sc, TSEM_REG_TSEM_INT_MASK_1, 0x07ff); 16974 } 16975 16976 REG_WR(sc, CDU_REG_CDU_INT_MASK, 0); 16977 REG_WR(sc, DMAE_REG_DMAE_INT_MASK, 0); 16978 /* REG_WR(sc, MISC_REG_MISC_INT_MASK, 0); */ 16979 REG_WR(sc, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */ 16980 } 16981 16982 /** 16983 * bxe_init_hw_common - initialize the HW at the COMMON phase. 16984 * 16985 * @sc: driver handle 16986 */ 16987 static int 16988 bxe_init_hw_common(struct bxe_softc *sc) 16989 { 16990 uint8_t abs_func_id; 16991 uint32_t val; 16992 16993 BLOGD(sc, DBG_LOAD, "starting common init for func %d\n", 16994 SC_ABS_FUNC(sc)); 16995 16996 /* 16997 * take the RESET lock to protect undi_unload flow from accessing 16998 * registers while we are resetting the chip 16999 */ 17000 bxe_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RESET); 17001 17002 bxe_reset_common(sc); 17003 17004 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET), 0xffffffff); 17005 17006 val = 0xfffc; 17007 if (CHIP_IS_E3(sc)) { 17008 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0; 17009 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1; 17010 } 17011 17012 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET), val); 17013 17014 bxe_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET); 17015 17016 ecore_init_block(sc, BLOCK_MISC, PHASE_COMMON); 17017 BLOGD(sc, DBG_LOAD, "after misc block init\n"); 17018 17019 if (!CHIP_IS_E1x(sc)) { 17020 /* 17021 * 4-port mode or 2-port mode we need to turn off master-enable for 17022 * everyone. After that we turn it back on for self. So, we disregard 17023 * multi-function, and always disable all functions on the given path, 17024 * this means 0,2,4,6 for path 0 and 1,3,5,7 for path 1 17025 */ 17026 for (abs_func_id = SC_PATH(sc); 17027 abs_func_id < (E2_FUNC_MAX * 2); 17028 abs_func_id += 2) { 17029 if (abs_func_id == SC_ABS_FUNC(sc)) { 17030 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1); 17031 continue; 17032 } 17033 17034 bxe_pretend_func(sc, abs_func_id); 17035 17036 /* clear pf enable */ 17037 bxe_pf_disable(sc); 17038 17039 bxe_pretend_func(sc, SC_ABS_FUNC(sc)); 17040 } 17041 } 17042 17043 BLOGD(sc, DBG_LOAD, "after pf disable\n"); 17044 17045 ecore_init_block(sc, BLOCK_PXP, PHASE_COMMON); 17046 17047 if (CHIP_IS_E1(sc)) { 17048 /* 17049 * enable HW interrupt from PXP on USDM overflow 17050 * bit 16 on INT_MASK_0 17051 */ 17052 REG_WR(sc, PXP_REG_PXP_INT_MASK_0, 0); 17053 } 17054 17055 ecore_init_block(sc, BLOCK_PXP2, PHASE_COMMON); 17056 bxe_init_pxp(sc); 17057 17058 #ifdef __BIG_ENDIAN 17059 REG_WR(sc, PXP2_REG_RQ_QM_ENDIAN_M, 1); 17060 REG_WR(sc, PXP2_REG_RQ_TM_ENDIAN_M, 1); 17061 REG_WR(sc, PXP2_REG_RQ_SRC_ENDIAN_M, 1); 17062 REG_WR(sc, PXP2_REG_RQ_CDU_ENDIAN_M, 1); 17063 REG_WR(sc, PXP2_REG_RQ_DBG_ENDIAN_M, 1); 17064 /* make sure this value is 0 */ 17065 REG_WR(sc, PXP2_REG_RQ_HC_ENDIAN_M, 0); 17066 17067 //REG_WR(sc, PXP2_REG_RD_PBF_SWAP_MODE, 1); 17068 REG_WR(sc, PXP2_REG_RD_QM_SWAP_MODE, 1); 17069 REG_WR(sc, PXP2_REG_RD_TM_SWAP_MODE, 1); 17070 REG_WR(sc, PXP2_REG_RD_SRC_SWAP_MODE, 1); 17071 REG_WR(sc, PXP2_REG_RD_CDURD_SWAP_MODE, 1); 17072 #endif 17073 17074 ecore_ilt_init_page_size(sc, INITOP_SET); 17075 17076 if (CHIP_REV_IS_FPGA(sc) && CHIP_IS_E1H(sc)) { 17077 REG_WR(sc, PXP2_REG_PGL_TAGS_LIMIT, 0x1); 17078 } 17079 17080 /* let the HW do it's magic... */ 17081 DELAY(100000); 17082 17083 /* finish PXP init */ 17084 val = REG_RD(sc, PXP2_REG_RQ_CFG_DONE); 17085 if (val != 1) { 17086 BLOGE(sc, "PXP2 CFG failed PXP2_REG_RQ_CFG_DONE val = 0x%x\n", 17087 val); 17088 return (-1); 17089 } 17090 val = REG_RD(sc, PXP2_REG_RD_INIT_DONE); 17091 if (val != 1) { 17092 BLOGE(sc, "PXP2 RD_INIT failed val = 0x%x\n", val); 17093 return (-1); 17094 } 17095 17096 BLOGD(sc, DBG_LOAD, "after pxp init\n"); 17097 17098 /* 17099 * Timer bug workaround for E2 only. We need to set the entire ILT to have 17100 * entries with value "0" and valid bit on. This needs to be done by the 17101 * first PF that is loaded in a path (i.e. common phase) 17102 */ 17103 if (!CHIP_IS_E1x(sc)) { 17104 /* 17105 * In E2 there is a bug in the timers block that can cause function 6 / 7 17106 * (i.e. vnic3) to start even if it is marked as "scan-off". 17107 * This occurs when a different function (func2,3) is being marked 17108 * as "scan-off". Real-life scenario for example: if a driver is being 17109 * load-unloaded while func6,7 are down. This will cause the timer to access 17110 * the ilt, translate to a logical address and send a request to read/write. 17111 * Since the ilt for the function that is down is not valid, this will cause 17112 * a translation error which is unrecoverable. 17113 * The Workaround is intended to make sure that when this happens nothing 17114 * fatal will occur. The workaround: 17115 * 1. First PF driver which loads on a path will: 17116 * a. After taking the chip out of reset, by using pretend, 17117 * it will write "0" to the following registers of 17118 * the other vnics. 17119 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0); 17120 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0); 17121 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0); 17122 * And for itself it will write '1' to 17123 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable 17124 * dmae-operations (writing to pram for example.) 17125 * note: can be done for only function 6,7 but cleaner this 17126 * way. 17127 * b. Write zero+valid to the entire ILT. 17128 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of 17129 * VNIC3 (of that port). The range allocated will be the 17130 * entire ILT. This is needed to prevent ILT range error. 17131 * 2. Any PF driver load flow: 17132 * a. ILT update with the physical addresses of the allocated 17133 * logical pages. 17134 * b. Wait 20msec. - note that this timeout is needed to make 17135 * sure there are no requests in one of the PXP internal 17136 * queues with "old" ILT addresses. 17137 * c. PF enable in the PGLC. 17138 * d. Clear the was_error of the PF in the PGLC. (could have 17139 * occurred while driver was down) 17140 * e. PF enable in the CFC (WEAK + STRONG) 17141 * f. Timers scan enable 17142 * 3. PF driver unload flow: 17143 * a. Clear the Timers scan_en. 17144 * b. Polling for scan_on=0 for that PF. 17145 * c. Clear the PF enable bit in the PXP. 17146 * d. Clear the PF enable in the CFC (WEAK + STRONG) 17147 * e. Write zero+valid to all ILT entries (The valid bit must 17148 * stay set) 17149 * f. If this is VNIC 3 of a port then also init 17150 * first_timers_ilt_entry to zero and last_timers_ilt_entry 17151 * to the last entry in the ILT. 17152 * 17153 * Notes: 17154 * Currently the PF error in the PGLC is non recoverable. 17155 * In the future the there will be a recovery routine for this error. 17156 * Currently attention is masked. 17157 * Having an MCP lock on the load/unload process does not guarantee that 17158 * there is no Timer disable during Func6/7 enable. This is because the 17159 * Timers scan is currently being cleared by the MCP on FLR. 17160 * Step 2.d can be done only for PF6/7 and the driver can also check if 17161 * there is error before clearing it. But the flow above is simpler and 17162 * more general. 17163 * All ILT entries are written by zero+valid and not just PF6/7 17164 * ILT entries since in the future the ILT entries allocation for 17165 * PF-s might be dynamic. 17166 */ 17167 struct ilt_client_info ilt_cli; 17168 struct ecore_ilt ilt; 17169 17170 memset(&ilt_cli, 0, sizeof(struct ilt_client_info)); 17171 memset(&ilt, 0, sizeof(struct ecore_ilt)); 17172 17173 /* initialize dummy TM client */ 17174 ilt_cli.start = 0; 17175 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1; 17176 ilt_cli.client_num = ILT_CLIENT_TM; 17177 17178 /* 17179 * Step 1: set zeroes to all ilt page entries with valid bit on 17180 * Step 2: set the timers first/last ilt entry to point 17181 * to the entire range to prevent ILT range error for 3rd/4th 17182 * vnic (this code assumes existence of the vnic) 17183 * 17184 * both steps performed by call to ecore_ilt_client_init_op() 17185 * with dummy TM client 17186 * 17187 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT 17188 * and his brother are split registers 17189 */ 17190 17191 bxe_pretend_func(sc, (SC_PATH(sc) + 6)); 17192 ecore_ilt_client_init_op_ilt(sc, &ilt, &ilt_cli, INITOP_CLEAR); 17193 bxe_pretend_func(sc, SC_ABS_FUNC(sc)); 17194 17195 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN, BXE_PXP_DRAM_ALIGN); 17196 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN_RD, BXE_PXP_DRAM_ALIGN); 17197 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1); 17198 } 17199 17200 REG_WR(sc, PXP2_REG_RQ_DISABLE_INPUTS, 0); 17201 REG_WR(sc, PXP2_REG_RD_DISABLE_INPUTS, 0); 17202 17203 if (!CHIP_IS_E1x(sc)) { 17204 int factor = CHIP_REV_IS_EMUL(sc) ? 1000 : 17205 (CHIP_REV_IS_FPGA(sc) ? 400 : 0); 17206 17207 ecore_init_block(sc, BLOCK_PGLUE_B, PHASE_COMMON); 17208 ecore_init_block(sc, BLOCK_ATC, PHASE_COMMON); 17209 17210 /* let the HW do it's magic... */ 17211 do { 17212 DELAY(200000); 17213 val = REG_RD(sc, ATC_REG_ATC_INIT_DONE); 17214 } while (factor-- && (val != 1)); 17215 17216 if (val != 1) { 17217 BLOGE(sc, "ATC_INIT failed val = 0x%x\n", val); 17218 return (-1); 17219 } 17220 } 17221 17222 BLOGD(sc, DBG_LOAD, "after pglue and atc init\n"); 17223 17224 ecore_init_block(sc, BLOCK_DMAE, PHASE_COMMON); 17225 17226 bxe_iov_init_dmae(sc); 17227 17228 /* clean the DMAE memory */ 17229 sc->dmae_ready = 1; 17230 ecore_init_fill(sc, TSEM_REG_PRAM, 0, 8, 1); 17231 17232 ecore_init_block(sc, BLOCK_TCM, PHASE_COMMON); 17233 17234 ecore_init_block(sc, BLOCK_UCM, PHASE_COMMON); 17235 17236 ecore_init_block(sc, BLOCK_CCM, PHASE_COMMON); 17237 17238 ecore_init_block(sc, BLOCK_XCM, PHASE_COMMON); 17239 17240 bxe_read_dmae(sc, XSEM_REG_PASSIVE_BUFFER, 3); 17241 bxe_read_dmae(sc, CSEM_REG_PASSIVE_BUFFER, 3); 17242 bxe_read_dmae(sc, TSEM_REG_PASSIVE_BUFFER, 3); 17243 bxe_read_dmae(sc, USEM_REG_PASSIVE_BUFFER, 3); 17244 17245 ecore_init_block(sc, BLOCK_QM, PHASE_COMMON); 17246 17247 /* QM queues pointers table */ 17248 ecore_qm_init_ptr_table(sc, sc->qm_cid_count, INITOP_SET); 17249 17250 /* soft reset pulse */ 17251 REG_WR(sc, QM_REG_SOFT_RESET, 1); 17252 REG_WR(sc, QM_REG_SOFT_RESET, 0); 17253 17254 if (CNIC_SUPPORT(sc)) 17255 ecore_init_block(sc, BLOCK_TM, PHASE_COMMON); 17256 17257 ecore_init_block(sc, BLOCK_DORQ, PHASE_COMMON); 17258 REG_WR(sc, DORQ_REG_DPM_CID_OFST, BXE_DB_SHIFT); 17259 if (!CHIP_REV_IS_SLOW(sc)) { 17260 /* enable hw interrupt from doorbell Q */ 17261 REG_WR(sc, DORQ_REG_DORQ_INT_MASK, 0); 17262 } 17263 17264 ecore_init_block(sc, BLOCK_BRB1, PHASE_COMMON); 17265 17266 ecore_init_block(sc, BLOCK_PRS, PHASE_COMMON); 17267 REG_WR(sc, PRS_REG_A_PRSU_20, 0xf); 17268 17269 if (!CHIP_IS_E1(sc)) { 17270 REG_WR(sc, PRS_REG_E1HOV_MODE, sc->devinfo.mf_info.path_has_ovlan); 17271 } 17272 17273 if (!CHIP_IS_E1x(sc) && !CHIP_IS_E3B0(sc)) { 17274 if (IS_MF_AFEX(sc)) { 17275 /* 17276 * configure that AFEX and VLAN headers must be 17277 * received in AFEX mode 17278 */ 17279 REG_WR(sc, PRS_REG_HDRS_AFTER_BASIC, 0xE); 17280 REG_WR(sc, PRS_REG_MUST_HAVE_HDRS, 0xA); 17281 REG_WR(sc, PRS_REG_HDRS_AFTER_TAG_0, 0x6); 17282 REG_WR(sc, PRS_REG_TAG_ETHERTYPE_0, 0x8926); 17283 REG_WR(sc, PRS_REG_TAG_LEN_0, 0x4); 17284 } else { 17285 /* 17286 * Bit-map indicating which L2 hdrs may appear 17287 * after the basic Ethernet header 17288 */ 17289 REG_WR(sc, PRS_REG_HDRS_AFTER_BASIC, 17290 sc->devinfo.mf_info.path_has_ovlan ? 7 : 6); 17291 } 17292 } 17293 17294 ecore_init_block(sc, BLOCK_TSDM, PHASE_COMMON); 17295 ecore_init_block(sc, BLOCK_CSDM, PHASE_COMMON); 17296 ecore_init_block(sc, BLOCK_USDM, PHASE_COMMON); 17297 ecore_init_block(sc, BLOCK_XSDM, PHASE_COMMON); 17298 17299 if (!CHIP_IS_E1x(sc)) { 17300 /* reset VFC memories */ 17301 REG_WR(sc, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST, 17302 VFC_MEMORIES_RST_REG_CAM_RST | 17303 VFC_MEMORIES_RST_REG_RAM_RST); 17304 REG_WR(sc, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST, 17305 VFC_MEMORIES_RST_REG_CAM_RST | 17306 VFC_MEMORIES_RST_REG_RAM_RST); 17307 17308 DELAY(20000); 17309 } 17310 17311 ecore_init_block(sc, BLOCK_TSEM, PHASE_COMMON); 17312 ecore_init_block(sc, BLOCK_USEM, PHASE_COMMON); 17313 ecore_init_block(sc, BLOCK_CSEM, PHASE_COMMON); 17314 ecore_init_block(sc, BLOCK_XSEM, PHASE_COMMON); 17315 17316 /* sync semi rtc */ 17317 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 17318 0x80000000); 17319 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 17320 0x80000000); 17321 17322 ecore_init_block(sc, BLOCK_UPB, PHASE_COMMON); 17323 ecore_init_block(sc, BLOCK_XPB, PHASE_COMMON); 17324 ecore_init_block(sc, BLOCK_PBF, PHASE_COMMON); 17325 17326 if (!CHIP_IS_E1x(sc)) { 17327 if (IS_MF_AFEX(sc)) { 17328 /* 17329 * configure that AFEX and VLAN headers must be 17330 * sent in AFEX mode 17331 */ 17332 REG_WR(sc, PBF_REG_HDRS_AFTER_BASIC, 0xE); 17333 REG_WR(sc, PBF_REG_MUST_HAVE_HDRS, 0xA); 17334 REG_WR(sc, PBF_REG_HDRS_AFTER_TAG_0, 0x6); 17335 REG_WR(sc, PBF_REG_TAG_ETHERTYPE_0, 0x8926); 17336 REG_WR(sc, PBF_REG_TAG_LEN_0, 0x4); 17337 } else { 17338 REG_WR(sc, PBF_REG_HDRS_AFTER_BASIC, 17339 sc->devinfo.mf_info.path_has_ovlan ? 7 : 6); 17340 } 17341 } 17342 17343 REG_WR(sc, SRC_REG_SOFT_RST, 1); 17344 17345 ecore_init_block(sc, BLOCK_SRC, PHASE_COMMON); 17346 17347 if (CNIC_SUPPORT(sc)) { 17348 REG_WR(sc, SRC_REG_KEYSEARCH_0, 0x63285672); 17349 REG_WR(sc, SRC_REG_KEYSEARCH_1, 0x24b8f2cc); 17350 REG_WR(sc, SRC_REG_KEYSEARCH_2, 0x223aef9b); 17351 REG_WR(sc, SRC_REG_KEYSEARCH_3, 0x26001e3a); 17352 REG_WR(sc, SRC_REG_KEYSEARCH_4, 0x7ae91116); 17353 REG_WR(sc, SRC_REG_KEYSEARCH_5, 0x5ce5230b); 17354 REG_WR(sc, SRC_REG_KEYSEARCH_6, 0x298d8adf); 17355 REG_WR(sc, SRC_REG_KEYSEARCH_7, 0x6eb0ff09); 17356 REG_WR(sc, SRC_REG_KEYSEARCH_8, 0x1830f82f); 17357 REG_WR(sc, SRC_REG_KEYSEARCH_9, 0x01e46be7); 17358 } 17359 REG_WR(sc, SRC_REG_SOFT_RST, 0); 17360 17361 if (sizeof(union cdu_context) != 1024) { 17362 /* we currently assume that a context is 1024 bytes */ 17363 BLOGE(sc, "please adjust the size of cdu_context(%ld)\n", 17364 (long)sizeof(union cdu_context)); 17365 } 17366 17367 ecore_init_block(sc, BLOCK_CDU, PHASE_COMMON); 17368 val = (4 << 24) + (0 << 12) + 1024; 17369 REG_WR(sc, CDU_REG_CDU_GLOBAL_PARAMS, val); 17370 17371 ecore_init_block(sc, BLOCK_CFC, PHASE_COMMON); 17372 17373 REG_WR(sc, CFC_REG_INIT_REG, 0x7FF); 17374 /* enable context validation interrupt from CFC */ 17375 REG_WR(sc, CFC_REG_CFC_INT_MASK, 0); 17376 17377 /* set the thresholds to prevent CFC/CDU race */ 17378 REG_WR(sc, CFC_REG_DEBUG0, 0x20020000); 17379 ecore_init_block(sc, BLOCK_HC, PHASE_COMMON); 17380 17381 if (!CHIP_IS_E1x(sc) && BXE_NOMCP(sc)) { 17382 REG_WR(sc, IGU_REG_RESET_MEMORIES, 0x36); 17383 } 17384 17385 ecore_init_block(sc, BLOCK_IGU, PHASE_COMMON); 17386 ecore_init_block(sc, BLOCK_MISC_AEU, PHASE_COMMON); 17387 17388 /* Reset PCIE errors for debug */ 17389 REG_WR(sc, 0x2814, 0xffffffff); 17390 REG_WR(sc, 0x3820, 0xffffffff); 17391 17392 if (!CHIP_IS_E1x(sc)) { 17393 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_CONTROL_5, 17394 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 | 17395 PXPCS_TL_CONTROL_5_ERR_UNSPPORT)); 17396 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT, 17397 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 | 17398 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 | 17399 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2)); 17400 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT, 17401 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 | 17402 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 | 17403 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5)); 17404 } 17405 17406 ecore_init_block(sc, BLOCK_NIG, PHASE_COMMON); 17407 17408 if (!CHIP_IS_E1(sc)) { 17409 /* in E3 this done in per-port section */ 17410 if (!CHIP_IS_E3(sc)) 17411 REG_WR(sc, NIG_REG_LLH_MF_MODE, IS_MF(sc)); 17412 } 17413 17414 if (CHIP_IS_E1H(sc)) { 17415 /* not applicable for E2 (and above ...) */ 17416 REG_WR(sc, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(sc)); 17417 } 17418 17419 if (CHIP_REV_IS_SLOW(sc)) { 17420 DELAY(200000); 17421 } 17422 17423 /* finish CFC init */ 17424 val = reg_poll(sc, CFC_REG_LL_INIT_DONE, 1, 100, 10); 17425 if (val != 1) { 17426 BLOGE(sc, "CFC LL_INIT failed val=0x%x\n", val); 17427 return (-1); 17428 } 17429 val = reg_poll(sc, CFC_REG_AC_INIT_DONE, 1, 100, 10); 17430 if (val != 1) { 17431 BLOGE(sc, "CFC AC_INIT failed val=0x%x\n", val); 17432 return (-1); 17433 } 17434 val = reg_poll(sc, CFC_REG_CAM_INIT_DONE, 1, 100, 10); 17435 if (val != 1) { 17436 BLOGE(sc, "CFC CAM_INIT failed val=0x%x\n", val); 17437 return (-1); 17438 } 17439 REG_WR(sc, CFC_REG_DEBUG0, 0); 17440 17441 if (CHIP_IS_E1(sc)) { 17442 /* read NIG statistic to see if this is our first up since powerup */ 17443 bxe_read_dmae(sc, NIG_REG_STAT2_BRB_OCTET, 2); 17444 val = *BXE_SP(sc, wb_data[0]); 17445 17446 /* do internal memory self test */ 17447 if ((val == 0) && bxe_int_mem_test(sc)) { 17448 BLOGE(sc, "internal mem self test failed val=0x%x\n", val); 17449 return (-1); 17450 } 17451 } 17452 17453 bxe_setup_fan_failure_detection(sc); 17454 17455 /* clear PXP2 attentions */ 17456 REG_RD(sc, PXP2_REG_PXP2_INT_STS_CLR_0); 17457 17458 bxe_enable_blocks_attention(sc); 17459 17460 if (!CHIP_REV_IS_SLOW(sc)) { 17461 ecore_enable_blocks_parity(sc); 17462 } 17463 17464 if (!BXE_NOMCP(sc)) { 17465 if (CHIP_IS_E1x(sc)) { 17466 bxe_common_init_phy(sc); 17467 } 17468 } 17469 17470 return (0); 17471 } 17472 17473 /** 17474 * bxe_init_hw_common_chip - init HW at the COMMON_CHIP phase. 17475 * 17476 * @sc: driver handle 17477 */ 17478 static int 17479 bxe_init_hw_common_chip(struct bxe_softc *sc) 17480 { 17481 int rc = bxe_init_hw_common(sc); 17482 17483 if (rc) { 17484 BLOGE(sc, "bxe_init_hw_common failed rc=%d\n", rc); 17485 return (rc); 17486 } 17487 17488 /* In E2 2-PORT mode, same ext phy is used for the two paths */ 17489 if (!BXE_NOMCP(sc)) { 17490 bxe_common_init_phy(sc); 17491 } 17492 17493 return (0); 17494 } 17495 17496 static int 17497 bxe_init_hw_port(struct bxe_softc *sc) 17498 { 17499 int port = SC_PORT(sc); 17500 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0; 17501 uint32_t low, high; 17502 uint32_t val; 17503 17504 BLOGD(sc, DBG_LOAD, "starting port init for port %d\n", port); 17505 17506 REG_WR(sc, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0); 17507 17508 ecore_init_block(sc, BLOCK_MISC, init_phase); 17509 ecore_init_block(sc, BLOCK_PXP, init_phase); 17510 ecore_init_block(sc, BLOCK_PXP2, init_phase); 17511 17512 /* 17513 * Timers bug workaround: disables the pf_master bit in pglue at 17514 * common phase, we need to enable it here before any dmae access are 17515 * attempted. Therefore we manually added the enable-master to the 17516 * port phase (it also happens in the function phase) 17517 */ 17518 if (!CHIP_IS_E1x(sc)) { 17519 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1); 17520 } 17521 17522 ecore_init_block(sc, BLOCK_ATC, init_phase); 17523 ecore_init_block(sc, BLOCK_DMAE, init_phase); 17524 ecore_init_block(sc, BLOCK_PGLUE_B, init_phase); 17525 ecore_init_block(sc, BLOCK_QM, init_phase); 17526 17527 ecore_init_block(sc, BLOCK_TCM, init_phase); 17528 ecore_init_block(sc, BLOCK_UCM, init_phase); 17529 ecore_init_block(sc, BLOCK_CCM, init_phase); 17530 ecore_init_block(sc, BLOCK_XCM, init_phase); 17531 17532 /* QM cid (connection) count */ 17533 ecore_qm_init_cid_count(sc, sc->qm_cid_count, INITOP_SET); 17534 17535 if (CNIC_SUPPORT(sc)) { 17536 ecore_init_block(sc, BLOCK_TM, init_phase); 17537 REG_WR(sc, TM_REG_LIN0_SCAN_TIME + port*4, 20); 17538 REG_WR(sc, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31); 17539 } 17540 17541 ecore_init_block(sc, BLOCK_DORQ, init_phase); 17542 17543 ecore_init_block(sc, BLOCK_BRB1, init_phase); 17544 17545 if (CHIP_IS_E1(sc) || CHIP_IS_E1H(sc)) { 17546 if (IS_MF(sc)) { 17547 low = (BXE_ONE_PORT(sc) ? 160 : 246); 17548 } else if (sc->mtu > 4096) { 17549 if (BXE_ONE_PORT(sc)) { 17550 low = 160; 17551 } else { 17552 val = sc->mtu; 17553 /* (24*1024 + val*4)/256 */ 17554 low = (96 + (val / 64) + ((val % 64) ? 1 : 0)); 17555 } 17556 } else { 17557 low = (BXE_ONE_PORT(sc) ? 80 : 160); 17558 } 17559 high = (low + 56); /* 14*1024/256 */ 17560 REG_WR(sc, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low); 17561 REG_WR(sc, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high); 17562 } 17563 17564 if (CHIP_IS_MODE_4_PORT(sc)) { 17565 REG_WR(sc, SC_PORT(sc) ? 17566 BRB1_REG_MAC_GUARANTIED_1 : 17567 BRB1_REG_MAC_GUARANTIED_0, 40); 17568 } 17569 17570 ecore_init_block(sc, BLOCK_PRS, init_phase); 17571 if (CHIP_IS_E3B0(sc)) { 17572 if (IS_MF_AFEX(sc)) { 17573 /* configure headers for AFEX mode */ 17574 REG_WR(sc, SC_PORT(sc) ? 17575 PRS_REG_HDRS_AFTER_BASIC_PORT_1 : 17576 PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE); 17577 REG_WR(sc, SC_PORT(sc) ? 17578 PRS_REG_HDRS_AFTER_TAG_0_PORT_1 : 17579 PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6); 17580 REG_WR(sc, SC_PORT(sc) ? 17581 PRS_REG_MUST_HAVE_HDRS_PORT_1 : 17582 PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA); 17583 } else { 17584 /* Ovlan exists only if we are in multi-function + 17585 * switch-dependent mode, in switch-independent there 17586 * is no ovlan headers 17587 */ 17588 REG_WR(sc, SC_PORT(sc) ? 17589 PRS_REG_HDRS_AFTER_BASIC_PORT_1 : 17590 PRS_REG_HDRS_AFTER_BASIC_PORT_0, 17591 (sc->devinfo.mf_info.path_has_ovlan ? 7 : 6)); 17592 } 17593 } 17594 17595 ecore_init_block(sc, BLOCK_TSDM, init_phase); 17596 ecore_init_block(sc, BLOCK_CSDM, init_phase); 17597 ecore_init_block(sc, BLOCK_USDM, init_phase); 17598 ecore_init_block(sc, BLOCK_XSDM, init_phase); 17599 17600 ecore_init_block(sc, BLOCK_TSEM, init_phase); 17601 ecore_init_block(sc, BLOCK_USEM, init_phase); 17602 ecore_init_block(sc, BLOCK_CSEM, init_phase); 17603 ecore_init_block(sc, BLOCK_XSEM, init_phase); 17604 17605 ecore_init_block(sc, BLOCK_UPB, init_phase); 17606 ecore_init_block(sc, BLOCK_XPB, init_phase); 17607 17608 ecore_init_block(sc, BLOCK_PBF, init_phase); 17609 17610 if (CHIP_IS_E1x(sc)) { 17611 /* configure PBF to work without PAUSE mtu 9000 */ 17612 REG_WR(sc, PBF_REG_P0_PAUSE_ENABLE + port*4, 0); 17613 17614 /* update threshold */ 17615 REG_WR(sc, PBF_REG_P0_ARB_THRSH + port*4, (9040/16)); 17616 /* update init credit */ 17617 REG_WR(sc, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22); 17618 17619 /* probe changes */ 17620 REG_WR(sc, PBF_REG_INIT_P0 + port*4, 1); 17621 DELAY(50); 17622 REG_WR(sc, PBF_REG_INIT_P0 + port*4, 0); 17623 } 17624 17625 if (CNIC_SUPPORT(sc)) { 17626 ecore_init_block(sc, BLOCK_SRC, init_phase); 17627 } 17628 17629 ecore_init_block(sc, BLOCK_CDU, init_phase); 17630 ecore_init_block(sc, BLOCK_CFC, init_phase); 17631 17632 if (CHIP_IS_E1(sc)) { 17633 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, 0); 17634 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, 0); 17635 } 17636 ecore_init_block(sc, BLOCK_HC, init_phase); 17637 17638 ecore_init_block(sc, BLOCK_IGU, init_phase); 17639 17640 ecore_init_block(sc, BLOCK_MISC_AEU, init_phase); 17641 /* init aeu_mask_attn_func_0/1: 17642 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use 17643 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF 17644 * bits 4-7 are used for "per vn group attention" */ 17645 val = IS_MF(sc) ? 0xF7 : 0x7; 17646 /* Enable DCBX attention for all but E1 */ 17647 val |= CHIP_IS_E1(sc) ? 0 : 0x10; 17648 REG_WR(sc, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val); 17649 17650 ecore_init_block(sc, BLOCK_NIG, init_phase); 17651 17652 if (!CHIP_IS_E1x(sc)) { 17653 /* Bit-map indicating which L2 hdrs may appear after the 17654 * basic Ethernet header 17655 */ 17656 if (IS_MF_AFEX(sc)) { 17657 REG_WR(sc, SC_PORT(sc) ? 17658 NIG_REG_P1_HDRS_AFTER_BASIC : 17659 NIG_REG_P0_HDRS_AFTER_BASIC, 0xE); 17660 } else { 17661 REG_WR(sc, SC_PORT(sc) ? 17662 NIG_REG_P1_HDRS_AFTER_BASIC : 17663 NIG_REG_P0_HDRS_AFTER_BASIC, 17664 IS_MF_SD(sc) ? 7 : 6); 17665 } 17666 17667 if (CHIP_IS_E3(sc)) { 17668 REG_WR(sc, SC_PORT(sc) ? 17669 NIG_REG_LLH1_MF_MODE : 17670 NIG_REG_LLH_MF_MODE, IS_MF(sc)); 17671 } 17672 } 17673 if (!CHIP_IS_E3(sc)) { 17674 REG_WR(sc, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1); 17675 } 17676 17677 if (!CHIP_IS_E1(sc)) { 17678 /* 0x2 disable mf_ov, 0x1 enable */ 17679 REG_WR(sc, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4, 17680 (IS_MF_SD(sc) ? 0x1 : 0x2)); 17681 17682 if (!CHIP_IS_E1x(sc)) { 17683 val = 0; 17684 switch (sc->devinfo.mf_info.mf_mode) { 17685 case MULTI_FUNCTION_SD: 17686 val = 1; 17687 break; 17688 case MULTI_FUNCTION_SI: 17689 case MULTI_FUNCTION_AFEX: 17690 val = 2; 17691 break; 17692 } 17693 17694 REG_WR(sc, (SC_PORT(sc) ? NIG_REG_LLH1_CLS_TYPE : 17695 NIG_REG_LLH0_CLS_TYPE), val); 17696 } 17697 REG_WR(sc, NIG_REG_LLFC_ENABLE_0 + port*4, 0); 17698 REG_WR(sc, NIG_REG_LLFC_OUT_EN_0 + port*4, 0); 17699 REG_WR(sc, NIG_REG_PAUSE_ENABLE_0 + port*4, 1); 17700 } 17701 17702 /* If SPIO5 is set to generate interrupts, enable it for this port */ 17703 val = REG_RD(sc, MISC_REG_SPIO_EVENT_EN); 17704 if (val & MISC_SPIO_SPIO5) { 17705 uint32_t reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : 17706 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); 17707 val = REG_RD(sc, reg_addr); 17708 val |= AEU_INPUTS_ATTN_BITS_SPIO5; 17709 REG_WR(sc, reg_addr, val); 17710 } 17711 17712 return (0); 17713 } 17714 17715 static uint32_t 17716 bxe_flr_clnup_reg_poll(struct bxe_softc *sc, 17717 uint32_t reg, 17718 uint32_t expected, 17719 uint32_t poll_count) 17720 { 17721 uint32_t cur_cnt = poll_count; 17722 uint32_t val; 17723 17724 while ((val = REG_RD(sc, reg)) != expected && cur_cnt--) { 17725 DELAY(FLR_WAIT_INTERVAL); 17726 } 17727 17728 return (val); 17729 } 17730 17731 static int 17732 bxe_flr_clnup_poll_hw_counter(struct bxe_softc *sc, 17733 uint32_t reg, 17734 char *msg, 17735 uint32_t poll_cnt) 17736 { 17737 uint32_t val = bxe_flr_clnup_reg_poll(sc, reg, 0, poll_cnt); 17738 17739 if (val != 0) { 17740 BLOGE(sc, "%s usage count=%d\n", msg, val); 17741 return (1); 17742 } 17743 17744 return (0); 17745 } 17746 17747 /* Common routines with VF FLR cleanup */ 17748 static uint32_t 17749 bxe_flr_clnup_poll_count(struct bxe_softc *sc) 17750 { 17751 /* adjust polling timeout */ 17752 if (CHIP_REV_IS_EMUL(sc)) { 17753 return (FLR_POLL_CNT * 2000); 17754 } 17755 17756 if (CHIP_REV_IS_FPGA(sc)) { 17757 return (FLR_POLL_CNT * 120); 17758 } 17759 17760 return (FLR_POLL_CNT); 17761 } 17762 17763 static int 17764 bxe_poll_hw_usage_counters(struct bxe_softc *sc, 17765 uint32_t poll_cnt) 17766 { 17767 /* wait for CFC PF usage-counter to zero (includes all the VFs) */ 17768 if (bxe_flr_clnup_poll_hw_counter(sc, 17769 CFC_REG_NUM_LCIDS_INSIDE_PF, 17770 "CFC PF usage counter timed out", 17771 poll_cnt)) { 17772 return (1); 17773 } 17774 17775 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */ 17776 if (bxe_flr_clnup_poll_hw_counter(sc, 17777 DORQ_REG_PF_USAGE_CNT, 17778 "DQ PF usage counter timed out", 17779 poll_cnt)) { 17780 return (1); 17781 } 17782 17783 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */ 17784 if (bxe_flr_clnup_poll_hw_counter(sc, 17785 QM_REG_PF_USG_CNT_0 + 4*SC_FUNC(sc), 17786 "QM PF usage counter timed out", 17787 poll_cnt)) { 17788 return (1); 17789 } 17790 17791 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */ 17792 if (bxe_flr_clnup_poll_hw_counter(sc, 17793 TM_REG_LIN0_VNIC_UC + 4*SC_PORT(sc), 17794 "Timers VNIC usage counter timed out", 17795 poll_cnt)) { 17796 return (1); 17797 } 17798 17799 if (bxe_flr_clnup_poll_hw_counter(sc, 17800 TM_REG_LIN0_NUM_SCANS + 4*SC_PORT(sc), 17801 "Timers NUM_SCANS usage counter timed out", 17802 poll_cnt)) { 17803 return (1); 17804 } 17805 17806 /* Wait DMAE PF usage counter to zero */ 17807 if (bxe_flr_clnup_poll_hw_counter(sc, 17808 dmae_reg_go_c[INIT_DMAE_C(sc)], 17809 "DMAE dommand register timed out", 17810 poll_cnt)) { 17811 return (1); 17812 } 17813 17814 return (0); 17815 } 17816 17817 #define OP_GEN_PARAM(param) \ 17818 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM) 17819 #define OP_GEN_TYPE(type) \ 17820 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE) 17821 #define OP_GEN_AGG_VECT(index) \ 17822 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX) 17823 17824 static int 17825 bxe_send_final_clnup(struct bxe_softc *sc, 17826 uint8_t clnup_func, 17827 uint32_t poll_cnt) 17828 { 17829 uint32_t op_gen_command = 0; 17830 uint32_t comp_addr = (BAR_CSTRORM_INTMEM + 17831 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func)); 17832 int ret = 0; 17833 17834 if (REG_RD(sc, comp_addr)) { 17835 BLOGE(sc, "Cleanup complete was not 0 before sending\n"); 17836 return (1); 17837 } 17838 17839 op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX); 17840 op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE); 17841 op_gen_command |= OP_GEN_AGG_VECT(clnup_func); 17842 op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT; 17843 17844 BLOGD(sc, DBG_LOAD, "sending FW Final cleanup\n"); 17845 REG_WR(sc, XSDM_REG_OPERATION_GEN, op_gen_command); 17846 17847 if (bxe_flr_clnup_reg_poll(sc, comp_addr, 1, poll_cnt) != 1) { 17848 BLOGE(sc, "FW final cleanup did not succeed\n"); 17849 BLOGD(sc, DBG_LOAD, "At timeout completion address contained %x\n", 17850 (REG_RD(sc, comp_addr))); 17851 bxe_panic(sc, ("FLR cleanup failed\n")); 17852 return (1); 17853 } 17854 17855 /* Zero completion for nxt FLR */ 17856 REG_WR(sc, comp_addr, 0); 17857 17858 return (ret); 17859 } 17860 17861 static void 17862 bxe_pbf_pN_buf_flushed(struct bxe_softc *sc, 17863 struct pbf_pN_buf_regs *regs, 17864 uint32_t poll_count) 17865 { 17866 uint32_t init_crd, crd, crd_start, crd_freed, crd_freed_start; 17867 uint32_t cur_cnt = poll_count; 17868 17869 crd_freed = crd_freed_start = REG_RD(sc, regs->crd_freed); 17870 crd = crd_start = REG_RD(sc, regs->crd); 17871 init_crd = REG_RD(sc, regs->init_crd); 17872 17873 BLOGD(sc, DBG_LOAD, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd); 17874 BLOGD(sc, DBG_LOAD, "CREDIT[%d] : s:%x\n", regs->pN, crd); 17875 BLOGD(sc, DBG_LOAD, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed); 17876 17877 while ((crd != init_crd) && 17878 ((uint32_t)((int32_t)crd_freed - (int32_t)crd_freed_start) < 17879 (init_crd - crd_start))) { 17880 if (cur_cnt--) { 17881 DELAY(FLR_WAIT_INTERVAL); 17882 crd = REG_RD(sc, regs->crd); 17883 crd_freed = REG_RD(sc, regs->crd_freed); 17884 } else { 17885 BLOGD(sc, DBG_LOAD, "PBF tx buffer[%d] timed out\n", regs->pN); 17886 BLOGD(sc, DBG_LOAD, "CREDIT[%d] : c:%x\n", regs->pN, crd); 17887 BLOGD(sc, DBG_LOAD, "CREDIT_FREED[%d]: c:%x\n", regs->pN, crd_freed); 17888 break; 17889 } 17890 } 17891 17892 BLOGD(sc, DBG_LOAD, "Waited %d*%d usec for PBF tx buffer[%d]\n", 17893 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN); 17894 } 17895 17896 static void 17897 bxe_pbf_pN_cmd_flushed(struct bxe_softc *sc, 17898 struct pbf_pN_cmd_regs *regs, 17899 uint32_t poll_count) 17900 { 17901 uint32_t occup, to_free, freed, freed_start; 17902 uint32_t cur_cnt = poll_count; 17903 17904 occup = to_free = REG_RD(sc, regs->lines_occup); 17905 freed = freed_start = REG_RD(sc, regs->lines_freed); 17906 17907 BLOGD(sc, DBG_LOAD, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup); 17908 BLOGD(sc, DBG_LOAD, "LINES_FREED[%d] : s:%x\n", regs->pN, freed); 17909 17910 while (occup && 17911 ((uint32_t)((int32_t)freed - (int32_t)freed_start) < to_free)) { 17912 if (cur_cnt--) { 17913 DELAY(FLR_WAIT_INTERVAL); 17914 occup = REG_RD(sc, regs->lines_occup); 17915 freed = REG_RD(sc, regs->lines_freed); 17916 } else { 17917 BLOGD(sc, DBG_LOAD, "PBF cmd queue[%d] timed out\n", regs->pN); 17918 BLOGD(sc, DBG_LOAD, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup); 17919 BLOGD(sc, DBG_LOAD, "LINES_FREED[%d] : s:%x\n", regs->pN, freed); 17920 break; 17921 } 17922 } 17923 17924 BLOGD(sc, DBG_LOAD, "Waited %d*%d usec for PBF cmd queue[%d]\n", 17925 poll_count - cur_cnt, FLR_WAIT_INTERVAL, regs->pN); 17926 } 17927 17928 static void 17929 bxe_tx_hw_flushed(struct bxe_softc *sc, uint32_t poll_count) 17930 { 17931 struct pbf_pN_cmd_regs cmd_regs[] = { 17932 {0, (CHIP_IS_E3B0(sc)) ? 17933 PBF_REG_TQ_OCCUPANCY_Q0 : 17934 PBF_REG_P0_TQ_OCCUPANCY, 17935 (CHIP_IS_E3B0(sc)) ? 17936 PBF_REG_TQ_LINES_FREED_CNT_Q0 : 17937 PBF_REG_P0_TQ_LINES_FREED_CNT}, 17938 {1, (CHIP_IS_E3B0(sc)) ? 17939 PBF_REG_TQ_OCCUPANCY_Q1 : 17940 PBF_REG_P1_TQ_OCCUPANCY, 17941 (CHIP_IS_E3B0(sc)) ? 17942 PBF_REG_TQ_LINES_FREED_CNT_Q1 : 17943 PBF_REG_P1_TQ_LINES_FREED_CNT}, 17944 {4, (CHIP_IS_E3B0(sc)) ? 17945 PBF_REG_TQ_OCCUPANCY_LB_Q : 17946 PBF_REG_P4_TQ_OCCUPANCY, 17947 (CHIP_IS_E3B0(sc)) ? 17948 PBF_REG_TQ_LINES_FREED_CNT_LB_Q : 17949 PBF_REG_P4_TQ_LINES_FREED_CNT} 17950 }; 17951 17952 struct pbf_pN_buf_regs buf_regs[] = { 17953 {0, (CHIP_IS_E3B0(sc)) ? 17954 PBF_REG_INIT_CRD_Q0 : 17955 PBF_REG_P0_INIT_CRD , 17956 (CHIP_IS_E3B0(sc)) ? 17957 PBF_REG_CREDIT_Q0 : 17958 PBF_REG_P0_CREDIT, 17959 (CHIP_IS_E3B0(sc)) ? 17960 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 : 17961 PBF_REG_P0_INTERNAL_CRD_FREED_CNT}, 17962 {1, (CHIP_IS_E3B0(sc)) ? 17963 PBF_REG_INIT_CRD_Q1 : 17964 PBF_REG_P1_INIT_CRD, 17965 (CHIP_IS_E3B0(sc)) ? 17966 PBF_REG_CREDIT_Q1 : 17967 PBF_REG_P1_CREDIT, 17968 (CHIP_IS_E3B0(sc)) ? 17969 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 : 17970 PBF_REG_P1_INTERNAL_CRD_FREED_CNT}, 17971 {4, (CHIP_IS_E3B0(sc)) ? 17972 PBF_REG_INIT_CRD_LB_Q : 17973 PBF_REG_P4_INIT_CRD, 17974 (CHIP_IS_E3B0(sc)) ? 17975 PBF_REG_CREDIT_LB_Q : 17976 PBF_REG_P4_CREDIT, 17977 (CHIP_IS_E3B0(sc)) ? 17978 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q : 17979 PBF_REG_P4_INTERNAL_CRD_FREED_CNT}, 17980 }; 17981 17982 int i; 17983 17984 /* Verify the command queues are flushed P0, P1, P4 */ 17985 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++) { 17986 bxe_pbf_pN_cmd_flushed(sc, &cmd_regs[i], poll_count); 17987 } 17988 17989 /* Verify the transmission buffers are flushed P0, P1, P4 */ 17990 for (i = 0; i < ARRAY_SIZE(buf_regs); i++) { 17991 bxe_pbf_pN_buf_flushed(sc, &buf_regs[i], poll_count); 17992 } 17993 } 17994 17995 static void 17996 bxe_hw_enable_status(struct bxe_softc *sc) 17997 { 17998 uint32_t val; 17999 18000 val = REG_RD(sc, CFC_REG_WEAK_ENABLE_PF); 18001 BLOGD(sc, DBG_LOAD, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val); 18002 18003 val = REG_RD(sc, PBF_REG_DISABLE_PF); 18004 BLOGD(sc, DBG_LOAD, "PBF_REG_DISABLE_PF is 0x%x\n", val); 18005 18006 val = REG_RD(sc, IGU_REG_PCI_PF_MSI_EN); 18007 BLOGD(sc, DBG_LOAD, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val); 18008 18009 val = REG_RD(sc, IGU_REG_PCI_PF_MSIX_EN); 18010 BLOGD(sc, DBG_LOAD, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val); 18011 18012 val = REG_RD(sc, IGU_REG_PCI_PF_MSIX_FUNC_MASK); 18013 BLOGD(sc, DBG_LOAD, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val); 18014 18015 val = REG_RD(sc, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR); 18016 BLOGD(sc, DBG_LOAD, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val); 18017 18018 val = REG_RD(sc, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR); 18019 BLOGD(sc, DBG_LOAD, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val); 18020 18021 val = REG_RD(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER); 18022 BLOGD(sc, DBG_LOAD, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n", val); 18023 } 18024 18025 static int 18026 bxe_pf_flr_clnup(struct bxe_softc *sc) 18027 { 18028 uint32_t poll_cnt = bxe_flr_clnup_poll_count(sc); 18029 18030 BLOGD(sc, DBG_LOAD, "Cleanup after FLR PF[%d]\n", SC_ABS_FUNC(sc)); 18031 18032 /* Re-enable PF target read access */ 18033 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1); 18034 18035 /* Poll HW usage counters */ 18036 BLOGD(sc, DBG_LOAD, "Polling usage counters\n"); 18037 if (bxe_poll_hw_usage_counters(sc, poll_cnt)) { 18038 return (-1); 18039 } 18040 18041 /* Zero the igu 'trailing edge' and 'leading edge' */ 18042 18043 /* Send the FW cleanup command */ 18044 if (bxe_send_final_clnup(sc, (uint8_t)SC_FUNC(sc), poll_cnt)) { 18045 return (-1); 18046 } 18047 18048 /* ATC cleanup */ 18049 18050 /* Verify TX hw is flushed */ 18051 bxe_tx_hw_flushed(sc, poll_cnt); 18052 18053 /* Wait 100ms (not adjusted according to platform) */ 18054 DELAY(100000); 18055 18056 /* Verify no pending pci transactions */ 18057 if (bxe_is_pcie_pending(sc)) { 18058 BLOGE(sc, "PCIE Transactions still pending\n"); 18059 } 18060 18061 /* Debug */ 18062 bxe_hw_enable_status(sc); 18063 18064 /* 18065 * Master enable - Due to WB DMAE writes performed before this 18066 * register is re-initialized as part of the regular function init 18067 */ 18068 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1); 18069 18070 return (0); 18071 } 18072 18073 static int 18074 bxe_init_hw_func(struct bxe_softc *sc) 18075 { 18076 int port = SC_PORT(sc); 18077 int func = SC_FUNC(sc); 18078 int init_phase = PHASE_PF0 + func; 18079 struct ecore_ilt *ilt = sc->ilt; 18080 uint16_t cdu_ilt_start; 18081 uint32_t addr, val; 18082 uint32_t main_mem_base, main_mem_size, main_mem_prty_clr; 18083 int i, main_mem_width, rc; 18084 18085 BLOGD(sc, DBG_LOAD, "starting func init for func %d\n", func); 18086 18087 /* FLR cleanup */ 18088 if (!CHIP_IS_E1x(sc)) { 18089 rc = bxe_pf_flr_clnup(sc); 18090 if (rc) { 18091 BLOGE(sc, "FLR cleanup failed!\n"); 18092 // XXX bxe_fw_dump(sc); 18093 // XXX bxe_idle_chk(sc); 18094 return (rc); 18095 } 18096 } 18097 18098 /* set MSI reconfigure capability */ 18099 if (sc->devinfo.int_block == INT_BLOCK_HC) { 18100 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0); 18101 val = REG_RD(sc, addr); 18102 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0; 18103 REG_WR(sc, addr, val); 18104 } 18105 18106 ecore_init_block(sc, BLOCK_PXP, init_phase); 18107 ecore_init_block(sc, BLOCK_PXP2, init_phase); 18108 18109 ilt = sc->ilt; 18110 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start; 18111 18112 for (i = 0; i < L2_ILT_LINES(sc); i++) { 18113 ilt->lines[cdu_ilt_start + i].page = sc->context[i].vcxt; 18114 ilt->lines[cdu_ilt_start + i].page_mapping = 18115 sc->context[i].vcxt_dma.paddr; 18116 ilt->lines[cdu_ilt_start + i].size = sc->context[i].size; 18117 } 18118 ecore_ilt_init_op(sc, INITOP_SET); 18119 18120 /* Set NIC mode */ 18121 REG_WR(sc, PRS_REG_NIC_MODE, 1); 18122 BLOGD(sc, DBG_LOAD, "NIC MODE configured\n"); 18123 18124 if (!CHIP_IS_E1x(sc)) { 18125 uint32_t pf_conf = IGU_PF_CONF_FUNC_EN; 18126 18127 /* Turn on a single ISR mode in IGU if driver is going to use 18128 * INT#x or MSI 18129 */ 18130 if (sc->interrupt_mode != INTR_MODE_MSIX) { 18131 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN; 18132 } 18133 18134 /* 18135 * Timers workaround bug: function init part. 18136 * Need to wait 20msec after initializing ILT, 18137 * needed to make sure there are no requests in 18138 * one of the PXP internal queues with "old" ILT addresses 18139 */ 18140 DELAY(20000); 18141 18142 /* 18143 * Master enable - Due to WB DMAE writes performed before this 18144 * register is re-initialized as part of the regular function 18145 * init 18146 */ 18147 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1); 18148 /* Enable the function in IGU */ 18149 REG_WR(sc, IGU_REG_PF_CONFIGURATION, pf_conf); 18150 } 18151 18152 sc->dmae_ready = 1; 18153 18154 ecore_init_block(sc, BLOCK_PGLUE_B, init_phase); 18155 18156 if (!CHIP_IS_E1x(sc)) 18157 REG_WR(sc, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func); 18158 18159 ecore_init_block(sc, BLOCK_ATC, init_phase); 18160 ecore_init_block(sc, BLOCK_DMAE, init_phase); 18161 ecore_init_block(sc, BLOCK_NIG, init_phase); 18162 ecore_init_block(sc, BLOCK_SRC, init_phase); 18163 ecore_init_block(sc, BLOCK_MISC, init_phase); 18164 ecore_init_block(sc, BLOCK_TCM, init_phase); 18165 ecore_init_block(sc, BLOCK_UCM, init_phase); 18166 ecore_init_block(sc, BLOCK_CCM, init_phase); 18167 ecore_init_block(sc, BLOCK_XCM, init_phase); 18168 ecore_init_block(sc, BLOCK_TSEM, init_phase); 18169 ecore_init_block(sc, BLOCK_USEM, init_phase); 18170 ecore_init_block(sc, BLOCK_CSEM, init_phase); 18171 ecore_init_block(sc, BLOCK_XSEM, init_phase); 18172 18173 if (!CHIP_IS_E1x(sc)) 18174 REG_WR(sc, QM_REG_PF_EN, 1); 18175 18176 if (!CHIP_IS_E1x(sc)) { 18177 REG_WR(sc, TSEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func); 18178 REG_WR(sc, USEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func); 18179 REG_WR(sc, CSEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func); 18180 REG_WR(sc, XSEM_REG_VFPF_ERR_NUM, BXE_MAX_NUM_OF_VFS + func); 18181 } 18182 ecore_init_block(sc, BLOCK_QM, init_phase); 18183 18184 ecore_init_block(sc, BLOCK_TM, init_phase); 18185 ecore_init_block(sc, BLOCK_DORQ, init_phase); 18186 18187 bxe_iov_init_dq(sc); 18188 18189 ecore_init_block(sc, BLOCK_BRB1, init_phase); 18190 ecore_init_block(sc, BLOCK_PRS, init_phase); 18191 ecore_init_block(sc, BLOCK_TSDM, init_phase); 18192 ecore_init_block(sc, BLOCK_CSDM, init_phase); 18193 ecore_init_block(sc, BLOCK_USDM, init_phase); 18194 ecore_init_block(sc, BLOCK_XSDM, init_phase); 18195 ecore_init_block(sc, BLOCK_UPB, init_phase); 18196 ecore_init_block(sc, BLOCK_XPB, init_phase); 18197 ecore_init_block(sc, BLOCK_PBF, init_phase); 18198 if (!CHIP_IS_E1x(sc)) 18199 REG_WR(sc, PBF_REG_DISABLE_PF, 0); 18200 18201 ecore_init_block(sc, BLOCK_CDU, init_phase); 18202 18203 ecore_init_block(sc, BLOCK_CFC, init_phase); 18204 18205 if (!CHIP_IS_E1x(sc)) 18206 REG_WR(sc, CFC_REG_WEAK_ENABLE_PF, 1); 18207 18208 if (IS_MF(sc)) { 18209 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port*8, 1); 18210 REG_WR(sc, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, OVLAN(sc)); 18211 } 18212 18213 ecore_init_block(sc, BLOCK_MISC_AEU, init_phase); 18214 18215 /* HC init per function */ 18216 if (sc->devinfo.int_block == INT_BLOCK_HC) { 18217 if (CHIP_IS_E1H(sc)) { 18218 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); 18219 18220 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, 0); 18221 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, 0); 18222 } 18223 ecore_init_block(sc, BLOCK_HC, init_phase); 18224 18225 } else { 18226 int num_segs, sb_idx, prod_offset; 18227 18228 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); 18229 18230 if (!CHIP_IS_E1x(sc)) { 18231 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, 0); 18232 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, 0); 18233 } 18234 18235 ecore_init_block(sc, BLOCK_IGU, init_phase); 18236 18237 if (!CHIP_IS_E1x(sc)) { 18238 int dsb_idx = 0; 18239 /** 18240 * Producer memory: 18241 * E2 mode: address 0-135 match to the mapping memory; 18242 * 136 - PF0 default prod; 137 - PF1 default prod; 18243 * 138 - PF2 default prod; 139 - PF3 default prod; 18244 * 140 - PF0 attn prod; 141 - PF1 attn prod; 18245 * 142 - PF2 attn prod; 143 - PF3 attn prod; 18246 * 144-147 reserved. 18247 * 18248 * E1.5 mode - In backward compatible mode; 18249 * for non default SB; each even line in the memory 18250 * holds the U producer and each odd line hold 18251 * the C producer. The first 128 producers are for 18252 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20 18253 * producers are for the DSB for each PF. 18254 * Each PF has five segments: (the order inside each 18255 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods; 18256 * 132-135 C prods; 136-139 X prods; 140-143 T prods; 18257 * 144-147 attn prods; 18258 */ 18259 /* non-default-status-blocks */ 18260 num_segs = CHIP_INT_MODE_IS_BC(sc) ? 18261 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS; 18262 for (sb_idx = 0; sb_idx < sc->igu_sb_cnt; sb_idx++) { 18263 prod_offset = (sc->igu_base_sb + sb_idx) * 18264 num_segs; 18265 18266 for (i = 0; i < num_segs; i++) { 18267 addr = IGU_REG_PROD_CONS_MEMORY + 18268 (prod_offset + i) * 4; 18269 REG_WR(sc, addr, 0); 18270 } 18271 /* send consumer update with value 0 */ 18272 bxe_ack_sb(sc, sc->igu_base_sb + sb_idx, 18273 USTORM_ID, 0, IGU_INT_NOP, 1); 18274 bxe_igu_clear_sb(sc, sc->igu_base_sb + sb_idx); 18275 } 18276 18277 /* default-status-blocks */ 18278 num_segs = CHIP_INT_MODE_IS_BC(sc) ? 18279 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS; 18280 18281 if (CHIP_IS_MODE_4_PORT(sc)) 18282 dsb_idx = SC_FUNC(sc); 18283 else 18284 dsb_idx = SC_VN(sc); 18285 18286 prod_offset = (CHIP_INT_MODE_IS_BC(sc) ? 18287 IGU_BC_BASE_DSB_PROD + dsb_idx : 18288 IGU_NORM_BASE_DSB_PROD + dsb_idx); 18289 18290 /* 18291 * igu prods come in chunks of E1HVN_MAX (4) - 18292 * does not matters what is the current chip mode 18293 */ 18294 for (i = 0; i < (num_segs * E1HVN_MAX); 18295 i += E1HVN_MAX) { 18296 addr = IGU_REG_PROD_CONS_MEMORY + 18297 (prod_offset + i)*4; 18298 REG_WR(sc, addr, 0); 18299 } 18300 /* send consumer update with 0 */ 18301 if (CHIP_INT_MODE_IS_BC(sc)) { 18302 bxe_ack_sb(sc, sc->igu_dsb_id, 18303 USTORM_ID, 0, IGU_INT_NOP, 1); 18304 bxe_ack_sb(sc, sc->igu_dsb_id, 18305 CSTORM_ID, 0, IGU_INT_NOP, 1); 18306 bxe_ack_sb(sc, sc->igu_dsb_id, 18307 XSTORM_ID, 0, IGU_INT_NOP, 1); 18308 bxe_ack_sb(sc, sc->igu_dsb_id, 18309 TSTORM_ID, 0, IGU_INT_NOP, 1); 18310 bxe_ack_sb(sc, sc->igu_dsb_id, 18311 ATTENTION_ID, 0, IGU_INT_NOP, 1); 18312 } else { 18313 bxe_ack_sb(sc, sc->igu_dsb_id, 18314 USTORM_ID, 0, IGU_INT_NOP, 1); 18315 bxe_ack_sb(sc, sc->igu_dsb_id, 18316 ATTENTION_ID, 0, IGU_INT_NOP, 1); 18317 } 18318 bxe_igu_clear_sb(sc, sc->igu_dsb_id); 18319 18320 /* !!! these should become driver const once 18321 rf-tool supports split-68 const */ 18322 REG_WR(sc, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0); 18323 REG_WR(sc, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0); 18324 REG_WR(sc, IGU_REG_SB_MASK_LSB, 0); 18325 REG_WR(sc, IGU_REG_SB_MASK_MSB, 0); 18326 REG_WR(sc, IGU_REG_PBA_STATUS_LSB, 0); 18327 REG_WR(sc, IGU_REG_PBA_STATUS_MSB, 0); 18328 } 18329 } 18330 18331 /* Reset PCIE errors for debug */ 18332 REG_WR(sc, 0x2114, 0xffffffff); 18333 REG_WR(sc, 0x2120, 0xffffffff); 18334 18335 if (CHIP_IS_E1x(sc)) { 18336 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/ 18337 main_mem_base = HC_REG_MAIN_MEMORY + 18338 SC_PORT(sc) * (main_mem_size * 4); 18339 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR; 18340 main_mem_width = 8; 18341 18342 val = REG_RD(sc, main_mem_prty_clr); 18343 if (val) { 18344 BLOGD(sc, DBG_LOAD, 18345 "Parity errors in HC block during function init (0x%x)!\n", 18346 val); 18347 } 18348 18349 /* Clear "false" parity errors in MSI-X table */ 18350 for (i = main_mem_base; 18351 i < main_mem_base + main_mem_size * 4; 18352 i += main_mem_width) { 18353 bxe_read_dmae(sc, i, main_mem_width / 4); 18354 bxe_write_dmae(sc, BXE_SP_MAPPING(sc, wb_data), 18355 i, main_mem_width / 4); 18356 } 18357 /* Clear HC parity attention */ 18358 REG_RD(sc, main_mem_prty_clr); 18359 } 18360 18361 #if 1 18362 /* Enable STORMs SP logging */ 18363 REG_WR8(sc, BAR_USTRORM_INTMEM + 18364 USTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1); 18365 REG_WR8(sc, BAR_TSTRORM_INTMEM + 18366 TSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1); 18367 REG_WR8(sc, BAR_CSTRORM_INTMEM + 18368 CSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1); 18369 REG_WR8(sc, BAR_XSTRORM_INTMEM + 18370 XSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1); 18371 #endif 18372 18373 elink_phy_probe(&sc->link_params); 18374 18375 return (0); 18376 } 18377 18378 static void 18379 bxe_link_reset(struct bxe_softc *sc) 18380 { 18381 if (!BXE_NOMCP(sc)) { 18382 bxe_acquire_phy_lock(sc); 18383 elink_lfa_reset(&sc->link_params, &sc->link_vars); 18384 bxe_release_phy_lock(sc); 18385 } else { 18386 if (!CHIP_REV_IS_SLOW(sc)) { 18387 BLOGW(sc, "Bootcode is missing - cannot reset link\n"); 18388 } 18389 } 18390 } 18391 18392 static void 18393 bxe_reset_port(struct bxe_softc *sc) 18394 { 18395 int port = SC_PORT(sc); 18396 uint32_t val; 18397 18398 ELINK_DEBUG_P0(sc, "bxe_reset_port called\n"); 18399 /* reset physical Link */ 18400 bxe_link_reset(sc); 18401 18402 REG_WR(sc, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0); 18403 18404 /* Do not rcv packets to BRB */ 18405 REG_WR(sc, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0); 18406 /* Do not direct rcv packets that are not for MCP to the BRB */ 18407 REG_WR(sc, (port ? NIG_REG_LLH1_BRB1_NOT_MCP : 18408 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0); 18409 18410 /* Configure AEU */ 18411 REG_WR(sc, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0); 18412 18413 DELAY(100000); 18414 18415 /* Check for BRB port occupancy */ 18416 val = REG_RD(sc, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4); 18417 if (val) { 18418 BLOGD(sc, DBG_LOAD, 18419 "BRB1 is not empty, %d blocks are occupied\n", val); 18420 } 18421 18422 /* TODO: Close Doorbell port? */ 18423 } 18424 18425 static void 18426 bxe_ilt_wr(struct bxe_softc *sc, 18427 uint32_t index, 18428 bus_addr_t addr) 18429 { 18430 int reg; 18431 uint32_t wb_write[2]; 18432 18433 if (CHIP_IS_E1(sc)) { 18434 reg = PXP2_REG_RQ_ONCHIP_AT + index*8; 18435 } else { 18436 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8; 18437 } 18438 18439 wb_write[0] = ONCHIP_ADDR1(addr); 18440 wb_write[1] = ONCHIP_ADDR2(addr); 18441 REG_WR_DMAE(sc, reg, wb_write, 2); 18442 } 18443 18444 static void 18445 bxe_clear_func_ilt(struct bxe_softc *sc, 18446 uint32_t func) 18447 { 18448 uint32_t i, base = FUNC_ILT_BASE(func); 18449 for (i = base; i < base + ILT_PER_FUNC; i++) { 18450 bxe_ilt_wr(sc, i, 0); 18451 } 18452 } 18453 18454 static void 18455 bxe_reset_func(struct bxe_softc *sc) 18456 { 18457 struct bxe_fastpath *fp; 18458 int port = SC_PORT(sc); 18459 int func = SC_FUNC(sc); 18460 int i; 18461 18462 /* Disable the function in the FW */ 18463 REG_WR8(sc, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0); 18464 REG_WR8(sc, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0); 18465 REG_WR8(sc, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0); 18466 REG_WR8(sc, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0); 18467 18468 /* FP SBs */ 18469 FOR_EACH_ETH_QUEUE(sc, i) { 18470 fp = &sc->fp[i]; 18471 REG_WR8(sc, BAR_CSTRORM_INTMEM + 18472 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id), 18473 SB_DISABLED); 18474 } 18475 18476 /* SP SB */ 18477 REG_WR8(sc, BAR_CSTRORM_INTMEM + 18478 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func), 18479 SB_DISABLED); 18480 18481 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++) { 18482 REG_WR(sc, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func), 0); 18483 } 18484 18485 /* Configure IGU */ 18486 if (sc->devinfo.int_block == INT_BLOCK_HC) { 18487 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port*8, 0); 18488 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port*8, 0); 18489 } else { 18490 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, 0); 18491 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, 0); 18492 } 18493 18494 if (CNIC_LOADED(sc)) { 18495 /* Disable Timer scan */ 18496 REG_WR(sc, TM_REG_EN_LINEAR0_TIMER + port*4, 0); 18497 /* 18498 * Wait for at least 10ms and up to 2 second for the timers 18499 * scan to complete 18500 */ 18501 for (i = 0; i < 200; i++) { 18502 DELAY(10000); 18503 if (!REG_RD(sc, TM_REG_LIN0_SCAN_ON + port*4)) 18504 break; 18505 } 18506 } 18507 18508 /* Clear ILT */ 18509 bxe_clear_func_ilt(sc, func); 18510 18511 /* 18512 * Timers workaround bug for E2: if this is vnic-3, 18513 * we need to set the entire ilt range for this timers. 18514 */ 18515 if (!CHIP_IS_E1x(sc) && SC_VN(sc) == 3) { 18516 struct ilt_client_info ilt_cli; 18517 /* use dummy TM client */ 18518 memset(&ilt_cli, 0, sizeof(struct ilt_client_info)); 18519 ilt_cli.start = 0; 18520 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1; 18521 ilt_cli.client_num = ILT_CLIENT_TM; 18522 18523 ecore_ilt_boundry_init_op(sc, &ilt_cli, 0, INITOP_CLEAR); 18524 } 18525 18526 /* this assumes that reset_port() called before reset_func()*/ 18527 if (!CHIP_IS_E1x(sc)) { 18528 bxe_pf_disable(sc); 18529 } 18530 18531 sc->dmae_ready = 0; 18532 } 18533 18534 static int 18535 bxe_gunzip_init(struct bxe_softc *sc) 18536 { 18537 return (0); 18538 } 18539 18540 static void 18541 bxe_gunzip_end(struct bxe_softc *sc) 18542 { 18543 return; 18544 } 18545 18546 static int 18547 bxe_init_firmware(struct bxe_softc *sc) 18548 { 18549 if (CHIP_IS_E1(sc)) { 18550 ecore_init_e1_firmware(sc); 18551 sc->iro_array = e1_iro_arr; 18552 } else if (CHIP_IS_E1H(sc)) { 18553 ecore_init_e1h_firmware(sc); 18554 sc->iro_array = e1h_iro_arr; 18555 } else if (!CHIP_IS_E1x(sc)) { 18556 ecore_init_e2_firmware(sc); 18557 sc->iro_array = e2_iro_arr; 18558 } else { 18559 BLOGE(sc, "Unsupported chip revision\n"); 18560 return (-1); 18561 } 18562 18563 return (0); 18564 } 18565 18566 static void 18567 bxe_release_firmware(struct bxe_softc *sc) 18568 { 18569 /* Do nothing */ 18570 return; 18571 } 18572 18573 static int 18574 ecore_gunzip(struct bxe_softc *sc, 18575 const uint8_t *zbuf, 18576 int len) 18577 { 18578 /* XXX : Implement... */ 18579 BLOGD(sc, DBG_LOAD, "ECORE_GUNZIP NOT IMPLEMENTED\n"); 18580 return (FALSE); 18581 } 18582 18583 static void 18584 ecore_reg_wr_ind(struct bxe_softc *sc, 18585 uint32_t addr, 18586 uint32_t val) 18587 { 18588 bxe_reg_wr_ind(sc, addr, val); 18589 } 18590 18591 static void 18592 ecore_write_dmae_phys_len(struct bxe_softc *sc, 18593 bus_addr_t phys_addr, 18594 uint32_t addr, 18595 uint32_t len) 18596 { 18597 bxe_write_dmae_phys_len(sc, phys_addr, addr, len); 18598 } 18599 18600 void 18601 ecore_storm_memset_struct(struct bxe_softc *sc, 18602 uint32_t addr, 18603 size_t size, 18604 uint32_t *data) 18605 { 18606 uint8_t i; 18607 for (i = 0; i < size/4; i++) { 18608 REG_WR(sc, addr + (i * 4), data[i]); 18609 } 18610 } 18611 18612 18613 /* 18614 * character device - ioctl interface definitions 18615 */ 18616 18617 18618 #include "bxe_dump.h" 18619 #include "bxe_ioctl.h" 18620 #include <sys/conf.h> 18621 18622 static int bxe_eioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, 18623 struct thread *td); 18624 18625 static struct cdevsw bxe_cdevsw = { 18626 .d_version = D_VERSION, 18627 .d_ioctl = bxe_eioctl, 18628 .d_name = "bxecnic", 18629 }; 18630 18631 #define BXE_PATH(sc) (CHIP_IS_E1x(sc) ? 0 : (sc->pcie_func & 1)) 18632 18633 18634 #define DUMP_ALL_PRESETS 0x1FFF 18635 #define DUMP_MAX_PRESETS 13 18636 #define IS_E1_REG(chips) ((chips & DUMP_CHIP_E1) == DUMP_CHIP_E1) 18637 #define IS_E1H_REG(chips) ((chips & DUMP_CHIP_E1H) == DUMP_CHIP_E1H) 18638 #define IS_E2_REG(chips) ((chips & DUMP_CHIP_E2) == DUMP_CHIP_E2) 18639 #define IS_E3A0_REG(chips) ((chips & DUMP_CHIP_E3A0) == DUMP_CHIP_E3A0) 18640 #define IS_E3B0_REG(chips) ((chips & DUMP_CHIP_E3B0) == DUMP_CHIP_E3B0) 18641 18642 #define IS_REG_IN_PRESET(presets, idx) \ 18643 ((presets & (1 << (idx-1))) == (1 << (idx-1))) 18644 18645 18646 static int 18647 bxe_get_preset_regs_len(struct bxe_softc *sc, uint32_t preset) 18648 { 18649 if (CHIP_IS_E1(sc)) 18650 return dump_num_registers[0][preset-1]; 18651 else if (CHIP_IS_E1H(sc)) 18652 return dump_num_registers[1][preset-1]; 18653 else if (CHIP_IS_E2(sc)) 18654 return dump_num_registers[2][preset-1]; 18655 else if (CHIP_IS_E3A0(sc)) 18656 return dump_num_registers[3][preset-1]; 18657 else if (CHIP_IS_E3B0(sc)) 18658 return dump_num_registers[4][preset-1]; 18659 else 18660 return 0; 18661 } 18662 18663 static int 18664 bxe_get_total_regs_len32(struct bxe_softc *sc) 18665 { 18666 uint32_t preset_idx; 18667 int regdump_len32 = 0; 18668 18669 18670 /* Calculate the total preset regs length */ 18671 for (preset_idx = 1; preset_idx <= DUMP_MAX_PRESETS; preset_idx++) { 18672 regdump_len32 += bxe_get_preset_regs_len(sc, preset_idx); 18673 } 18674 18675 return regdump_len32; 18676 } 18677 18678 static const uint32_t * 18679 __bxe_get_page_addr_ar(struct bxe_softc *sc) 18680 { 18681 if (CHIP_IS_E2(sc)) 18682 return page_vals_e2; 18683 else if (CHIP_IS_E3(sc)) 18684 return page_vals_e3; 18685 else 18686 return NULL; 18687 } 18688 18689 static uint32_t 18690 __bxe_get_page_reg_num(struct bxe_softc *sc) 18691 { 18692 if (CHIP_IS_E2(sc)) 18693 return PAGE_MODE_VALUES_E2; 18694 else if (CHIP_IS_E3(sc)) 18695 return PAGE_MODE_VALUES_E3; 18696 else 18697 return 0; 18698 } 18699 18700 static const uint32_t * 18701 __bxe_get_page_write_ar(struct bxe_softc *sc) 18702 { 18703 if (CHIP_IS_E2(sc)) 18704 return page_write_regs_e2; 18705 else if (CHIP_IS_E3(sc)) 18706 return page_write_regs_e3; 18707 else 18708 return NULL; 18709 } 18710 18711 static uint32_t 18712 __bxe_get_page_write_num(struct bxe_softc *sc) 18713 { 18714 if (CHIP_IS_E2(sc)) 18715 return PAGE_WRITE_REGS_E2; 18716 else if (CHIP_IS_E3(sc)) 18717 return PAGE_WRITE_REGS_E3; 18718 else 18719 return 0; 18720 } 18721 18722 static const struct reg_addr * 18723 __bxe_get_page_read_ar(struct bxe_softc *sc) 18724 { 18725 if (CHIP_IS_E2(sc)) 18726 return page_read_regs_e2; 18727 else if (CHIP_IS_E3(sc)) 18728 return page_read_regs_e3; 18729 else 18730 return NULL; 18731 } 18732 18733 static uint32_t 18734 __bxe_get_page_read_num(struct bxe_softc *sc) 18735 { 18736 if (CHIP_IS_E2(sc)) 18737 return PAGE_READ_REGS_E2; 18738 else if (CHIP_IS_E3(sc)) 18739 return PAGE_READ_REGS_E3; 18740 else 18741 return 0; 18742 } 18743 18744 static bool 18745 bxe_is_reg_in_chip(struct bxe_softc *sc, const struct reg_addr *reg_info) 18746 { 18747 if (CHIP_IS_E1(sc)) 18748 return IS_E1_REG(reg_info->chips); 18749 else if (CHIP_IS_E1H(sc)) 18750 return IS_E1H_REG(reg_info->chips); 18751 else if (CHIP_IS_E2(sc)) 18752 return IS_E2_REG(reg_info->chips); 18753 else if (CHIP_IS_E3A0(sc)) 18754 return IS_E3A0_REG(reg_info->chips); 18755 else if (CHIP_IS_E3B0(sc)) 18756 return IS_E3B0_REG(reg_info->chips); 18757 else 18758 return 0; 18759 } 18760 18761 static bool 18762 bxe_is_wreg_in_chip(struct bxe_softc *sc, const struct wreg_addr *wreg_info) 18763 { 18764 if (CHIP_IS_E1(sc)) 18765 return IS_E1_REG(wreg_info->chips); 18766 else if (CHIP_IS_E1H(sc)) 18767 return IS_E1H_REG(wreg_info->chips); 18768 else if (CHIP_IS_E2(sc)) 18769 return IS_E2_REG(wreg_info->chips); 18770 else if (CHIP_IS_E3A0(sc)) 18771 return IS_E3A0_REG(wreg_info->chips); 18772 else if (CHIP_IS_E3B0(sc)) 18773 return IS_E3B0_REG(wreg_info->chips); 18774 else 18775 return 0; 18776 } 18777 18778 /** 18779 * bxe_read_pages_regs - read "paged" registers 18780 * 18781 * @bp device handle 18782 * @p output buffer 18783 * 18784 * Reads "paged" memories: memories that may only be read by first writing to a 18785 * specific address ("write address") and then reading from a specific address 18786 * ("read address"). There may be more than one write address per "page" and 18787 * more than one read address per write address. 18788 */ 18789 static void 18790 bxe_read_pages_regs(struct bxe_softc *sc, uint32_t *p, uint32_t preset) 18791 { 18792 uint32_t i, j, k, n; 18793 18794 /* addresses of the paged registers */ 18795 const uint32_t *page_addr = __bxe_get_page_addr_ar(sc); 18796 /* number of paged registers */ 18797 int num_pages = __bxe_get_page_reg_num(sc); 18798 /* write addresses */ 18799 const uint32_t *write_addr = __bxe_get_page_write_ar(sc); 18800 /* number of write addresses */ 18801 int write_num = __bxe_get_page_write_num(sc); 18802 /* read addresses info */ 18803 const struct reg_addr *read_addr = __bxe_get_page_read_ar(sc); 18804 /* number of read addresses */ 18805 int read_num = __bxe_get_page_read_num(sc); 18806 uint32_t addr, size; 18807 18808 for (i = 0; i < num_pages; i++) { 18809 for (j = 0; j < write_num; j++) { 18810 REG_WR(sc, write_addr[j], page_addr[i]); 18811 18812 for (k = 0; k < read_num; k++) { 18813 if (IS_REG_IN_PRESET(read_addr[k].presets, preset)) { 18814 size = read_addr[k].size; 18815 for (n = 0; n < size; n++) { 18816 addr = read_addr[k].addr + n*4; 18817 *p++ = REG_RD(sc, addr); 18818 } 18819 } 18820 } 18821 } 18822 } 18823 return; 18824 } 18825 18826 18827 static int 18828 bxe_get_preset_regs(struct bxe_softc *sc, uint32_t *p, uint32_t preset) 18829 { 18830 uint32_t i, j, addr; 18831 const struct wreg_addr *wreg_addr_p = NULL; 18832 18833 if (CHIP_IS_E1(sc)) 18834 wreg_addr_p = &wreg_addr_e1; 18835 else if (CHIP_IS_E1H(sc)) 18836 wreg_addr_p = &wreg_addr_e1h; 18837 else if (CHIP_IS_E2(sc)) 18838 wreg_addr_p = &wreg_addr_e2; 18839 else if (CHIP_IS_E3A0(sc)) 18840 wreg_addr_p = &wreg_addr_e3; 18841 else if (CHIP_IS_E3B0(sc)) 18842 wreg_addr_p = &wreg_addr_e3b0; 18843 else 18844 return (-1); 18845 18846 /* Read the idle_chk registers */ 18847 for (i = 0; i < IDLE_REGS_COUNT; i++) { 18848 if (bxe_is_reg_in_chip(sc, &idle_reg_addrs[i]) && 18849 IS_REG_IN_PRESET(idle_reg_addrs[i].presets, preset)) { 18850 for (j = 0; j < idle_reg_addrs[i].size; j++) 18851 *p++ = REG_RD(sc, idle_reg_addrs[i].addr + j*4); 18852 } 18853 } 18854 18855 /* Read the regular registers */ 18856 for (i = 0; i < REGS_COUNT; i++) { 18857 if (bxe_is_reg_in_chip(sc, ®_addrs[i]) && 18858 IS_REG_IN_PRESET(reg_addrs[i].presets, preset)) { 18859 for (j = 0; j < reg_addrs[i].size; j++) 18860 *p++ = REG_RD(sc, reg_addrs[i].addr + j*4); 18861 } 18862 } 18863 18864 /* Read the CAM registers */ 18865 if (bxe_is_wreg_in_chip(sc, wreg_addr_p) && 18866 IS_REG_IN_PRESET(wreg_addr_p->presets, preset)) { 18867 for (i = 0; i < wreg_addr_p->size; i++) { 18868 *p++ = REG_RD(sc, wreg_addr_p->addr + i*4); 18869 18870 /* In case of wreg_addr register, read additional 18871 registers from read_regs array 18872 */ 18873 for (j = 0; j < wreg_addr_p->read_regs_count; j++) { 18874 addr = *(wreg_addr_p->read_regs); 18875 *p++ = REG_RD(sc, addr + j*4); 18876 } 18877 } 18878 } 18879 18880 /* Paged registers are supported in E2 & E3 only */ 18881 if (CHIP_IS_E2(sc) || CHIP_IS_E3(sc)) { 18882 /* Read "paged" registers */ 18883 bxe_read_pages_regs(sc, p, preset); 18884 } 18885 18886 return 0; 18887 } 18888 18889 int 18890 bxe_grc_dump(struct bxe_softc *sc) 18891 { 18892 int rval = 0; 18893 uint32_t preset_idx; 18894 uint8_t *buf; 18895 uint32_t size; 18896 struct dump_header *d_hdr; 18897 uint32_t i; 18898 uint32_t reg_val; 18899 uint32_t reg_addr; 18900 uint32_t cmd_offset; 18901 struct ecore_ilt *ilt = SC_ILT(sc); 18902 struct bxe_fastpath *fp; 18903 struct ilt_client_info *ilt_cli; 18904 int grc_dump_size; 18905 18906 18907 if (sc->grcdump_done || sc->grcdump_started) 18908 return (rval); 18909 18910 sc->grcdump_started = 1; 18911 BLOGI(sc, "Started collecting grcdump\n"); 18912 18913 grc_dump_size = (bxe_get_total_regs_len32(sc) * sizeof(uint32_t)) + 18914 sizeof(struct dump_header); 18915 18916 sc->grc_dump = malloc(grc_dump_size, M_DEVBUF, M_NOWAIT); 18917 18918 if (sc->grc_dump == NULL) { 18919 BLOGW(sc, "Unable to allocate memory for grcdump collection\n"); 18920 return(ENOMEM); 18921 } 18922 18923 18924 18925 /* Disable parity attentions as long as following dump may 18926 * cause false alarms by reading never written registers. We 18927 * will re-enable parity attentions right after the dump. 18928 */ 18929 18930 /* Disable parity on path 0 */ 18931 bxe_pretend_func(sc, 0); 18932 18933 ecore_disable_blocks_parity(sc); 18934 18935 /* Disable parity on path 1 */ 18936 bxe_pretend_func(sc, 1); 18937 ecore_disable_blocks_parity(sc); 18938 18939 /* Return to current function */ 18940 bxe_pretend_func(sc, SC_ABS_FUNC(sc)); 18941 18942 buf = sc->grc_dump; 18943 d_hdr = sc->grc_dump; 18944 18945 d_hdr->header_size = (sizeof(struct dump_header) >> 2) - 1; 18946 d_hdr->version = BNX2X_DUMP_VERSION; 18947 d_hdr->preset = DUMP_ALL_PRESETS; 18948 18949 if (CHIP_IS_E1(sc)) { 18950 d_hdr->dump_meta_data = DUMP_CHIP_E1; 18951 } else if (CHIP_IS_E1H(sc)) { 18952 d_hdr->dump_meta_data = DUMP_CHIP_E1H; 18953 } else if (CHIP_IS_E2(sc)) { 18954 d_hdr->dump_meta_data = DUMP_CHIP_E2 | 18955 (BXE_PATH(sc) ? DUMP_PATH_1 : DUMP_PATH_0); 18956 } else if (CHIP_IS_E3A0(sc)) { 18957 d_hdr->dump_meta_data = DUMP_CHIP_E3A0 | 18958 (BXE_PATH(sc) ? DUMP_PATH_1 : DUMP_PATH_0); 18959 } else if (CHIP_IS_E3B0(sc)) { 18960 d_hdr->dump_meta_data = DUMP_CHIP_E3B0 | 18961 (BXE_PATH(sc) ? DUMP_PATH_1 : DUMP_PATH_0); 18962 } 18963 18964 buf += sizeof(struct dump_header); 18965 18966 for (preset_idx = 1; preset_idx <= DUMP_MAX_PRESETS; preset_idx++) { 18967 18968 /* Skip presets with IOR */ 18969 if ((preset_idx == 2) || (preset_idx == 5) || (preset_idx == 8) || 18970 (preset_idx == 11)) 18971 continue; 18972 18973 rval = bxe_get_preset_regs(sc, (uint32_t *)buf, preset_idx); 18974 18975 if (rval) 18976 break; 18977 18978 size = bxe_get_preset_regs_len(sc, preset_idx) * (sizeof (uint32_t)); 18979 18980 buf += size; 18981 } 18982 18983 bxe_pretend_func(sc, 0); 18984 ecore_clear_blocks_parity(sc); 18985 ecore_enable_blocks_parity(sc); 18986 18987 bxe_pretend_func(sc, 1); 18988 ecore_clear_blocks_parity(sc); 18989 ecore_enable_blocks_parity(sc); 18990 18991 /* Return to current function */ 18992 bxe_pretend_func(sc, SC_ABS_FUNC(sc)); 18993 18994 18995 18996 if(sc->state == BXE_STATE_OPEN) { 18997 if(sc->fw_stats_req != NULL) { 18998 BLOGI(sc, "fw stats start_paddr %#jx end_paddr %#jx vaddr %p size 0x%x\n", 18999 (uintmax_t)sc->fw_stats_req_mapping, 19000 (uintmax_t)sc->fw_stats_data_mapping, 19001 sc->fw_stats_req, (sc->fw_stats_req_size + sc->fw_stats_data_size)); 19002 } 19003 if(sc->def_sb != NULL) { 19004 BLOGI(sc, "def_status_block paddr %p vaddr %p size 0x%zx\n", 19005 (void *)sc->def_sb_dma.paddr, sc->def_sb, 19006 sizeof(struct host_sp_status_block)); 19007 } 19008 if(sc->eq_dma.vaddr != NULL) { 19009 BLOGI(sc, "event_queue paddr %#jx vaddr %p size 0x%x\n", 19010 (uintmax_t)sc->eq_dma.paddr, sc->eq_dma.vaddr, BCM_PAGE_SIZE); 19011 } 19012 if(sc->sp_dma.vaddr != NULL) { 19013 BLOGI(sc, "slow path paddr %#jx vaddr %p size 0x%zx\n", 19014 (uintmax_t)sc->sp_dma.paddr, sc->sp_dma.vaddr, 19015 sizeof(struct bxe_slowpath)); 19016 } 19017 if(sc->spq_dma.vaddr != NULL) { 19018 BLOGI(sc, "slow path queue paddr %#jx vaddr %p size 0x%x\n", 19019 (uintmax_t)sc->spq_dma.paddr, sc->spq_dma.vaddr, BCM_PAGE_SIZE); 19020 } 19021 if(sc->gz_buf_dma.vaddr != NULL) { 19022 BLOGI(sc, "fw_buf paddr %#jx vaddr %p size 0x%x\n", 19023 (uintmax_t)sc->gz_buf_dma.paddr, sc->gz_buf_dma.vaddr, 19024 FW_BUF_SIZE); 19025 } 19026 for (i = 0; i < sc->num_queues; i++) { 19027 fp = &sc->fp[i]; 19028 if(fp->sb_dma.vaddr != NULL && fp->tx_dma.vaddr != NULL && 19029 fp->rx_dma.vaddr != NULL && fp->rcq_dma.vaddr != NULL && 19030 fp->rx_sge_dma.vaddr != NULL) { 19031 19032 BLOGI(sc, "FP status block fp %d paddr %#jx vaddr %p size 0x%zx\n", i, 19033 (uintmax_t)fp->sb_dma.paddr, fp->sb_dma.vaddr, 19034 sizeof(union bxe_host_hc_status_block)); 19035 BLOGI(sc, "TX BD CHAIN fp %d paddr %#jx vaddr %p size 0x%x\n", i, 19036 (uintmax_t)fp->tx_dma.paddr, fp->tx_dma.vaddr, 19037 (BCM_PAGE_SIZE * TX_BD_NUM_PAGES)); 19038 BLOGI(sc, "RX BD CHAIN fp %d paddr %#jx vaddr %p size 0x%x\n", i, 19039 (uintmax_t)fp->rx_dma.paddr, fp->rx_dma.vaddr, 19040 (BCM_PAGE_SIZE * RX_BD_NUM_PAGES)); 19041 BLOGI(sc, "RX RCQ CHAIN fp %d paddr %#jx vaddr %p size 0x%zx\n", i, 19042 (uintmax_t)fp->rcq_dma.paddr, fp->rcq_dma.vaddr, 19043 (BCM_PAGE_SIZE * RCQ_NUM_PAGES)); 19044 BLOGI(sc, "RX SGE CHAIN fp %d paddr %#jx vaddr %p size 0x%x\n", i, 19045 (uintmax_t)fp->rx_sge_dma.paddr, fp->rx_sge_dma.vaddr, 19046 (BCM_PAGE_SIZE * RX_SGE_NUM_PAGES)); 19047 } 19048 } 19049 if(ilt != NULL ) { 19050 ilt_cli = &ilt->clients[1]; 19051 if(ilt->lines != NULL) { 19052 for (i = ilt_cli->start; i <= ilt_cli->end; i++) { 19053 BLOGI(sc, "ECORE_ILT paddr %#jx vaddr %p size 0x%x\n", 19054 (uintmax_t)(((struct bxe_dma *)((&ilt->lines[i])->page))->paddr), 19055 ((struct bxe_dma *)((&ilt->lines[i])->page))->vaddr, BCM_PAGE_SIZE); 19056 } 19057 } 19058 } 19059 19060 19061 cmd_offset = DMAE_REG_CMD_MEM; 19062 for (i = 0; i < 224; i++) { 19063 reg_addr = (cmd_offset +(i * 4)); 19064 reg_val = REG_RD(sc, reg_addr); 19065 BLOGI(sc, "DMAE_REG_CMD_MEM i=%d reg_addr 0x%x reg_val 0x%08x\n",i, 19066 reg_addr, reg_val); 19067 } 19068 } 19069 19070 BLOGI(sc, "Collection of grcdump done\n"); 19071 sc->grcdump_done = 1; 19072 return(rval); 19073 } 19074 19075 static int 19076 bxe_add_cdev(struct bxe_softc *sc) 19077 { 19078 sc->eeprom = malloc(BXE_EEPROM_MAX_DATA_LEN, M_DEVBUF, M_NOWAIT); 19079 19080 if (sc->eeprom == NULL) { 19081 BLOGW(sc, "Unable to alloc for eeprom size buffer\n"); 19082 return (-1); 19083 } 19084 19085 sc->ioctl_dev = make_dev(&bxe_cdevsw, 19086 if_getdunit(sc->ifp), 19087 UID_ROOT, 19088 GID_WHEEL, 19089 0600, 19090 "%s", 19091 if_name(sc->ifp)); 19092 19093 if (sc->ioctl_dev == NULL) { 19094 free(sc->eeprom, M_DEVBUF); 19095 sc->eeprom = NULL; 19096 return (-1); 19097 } 19098 19099 sc->ioctl_dev->si_drv1 = sc; 19100 19101 return (0); 19102 } 19103 19104 static void 19105 bxe_del_cdev(struct bxe_softc *sc) 19106 { 19107 if (sc->ioctl_dev != NULL) 19108 destroy_dev(sc->ioctl_dev); 19109 19110 if (sc->eeprom != NULL) { 19111 free(sc->eeprom, M_DEVBUF); 19112 sc->eeprom = NULL; 19113 } 19114 sc->ioctl_dev = NULL; 19115 19116 return; 19117 } 19118 19119 static bool bxe_is_nvram_accessible(struct bxe_softc *sc) 19120 { 19121 19122 if ((if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING) == 0) 19123 return FALSE; 19124 19125 return TRUE; 19126 } 19127 19128 19129 static int 19130 bxe_wr_eeprom(struct bxe_softc *sc, void *data, uint32_t offset, uint32_t len) 19131 { 19132 int rval = 0; 19133 19134 if(!bxe_is_nvram_accessible(sc)) { 19135 BLOGW(sc, "Cannot access eeprom when interface is down\n"); 19136 return (-EAGAIN); 19137 } 19138 rval = bxe_nvram_write(sc, offset, (uint8_t *)data, len); 19139 19140 19141 return (rval); 19142 } 19143 19144 static int 19145 bxe_rd_eeprom(struct bxe_softc *sc, void *data, uint32_t offset, uint32_t len) 19146 { 19147 int rval = 0; 19148 19149 if(!bxe_is_nvram_accessible(sc)) { 19150 BLOGW(sc, "Cannot access eeprom when interface is down\n"); 19151 return (-EAGAIN); 19152 } 19153 rval = bxe_nvram_read(sc, offset, (uint8_t *)data, len); 19154 19155 return (rval); 19156 } 19157 19158 static int 19159 bxe_eeprom_rd_wr(struct bxe_softc *sc, bxe_eeprom_t *eeprom) 19160 { 19161 int rval = 0; 19162 19163 switch (eeprom->eeprom_cmd) { 19164 19165 case BXE_EEPROM_CMD_SET_EEPROM: 19166 19167 rval = copyin(eeprom->eeprom_data, sc->eeprom, 19168 eeprom->eeprom_data_len); 19169 19170 if (rval) 19171 break; 19172 19173 rval = bxe_wr_eeprom(sc, sc->eeprom, eeprom->eeprom_offset, 19174 eeprom->eeprom_data_len); 19175 break; 19176 19177 case BXE_EEPROM_CMD_GET_EEPROM: 19178 19179 rval = bxe_rd_eeprom(sc, sc->eeprom, eeprom->eeprom_offset, 19180 eeprom->eeprom_data_len); 19181 19182 if (rval) { 19183 break; 19184 } 19185 19186 rval = copyout(sc->eeprom, eeprom->eeprom_data, 19187 eeprom->eeprom_data_len); 19188 break; 19189 19190 default: 19191 rval = EINVAL; 19192 break; 19193 } 19194 19195 if (rval) { 19196 BLOGW(sc, "ioctl cmd %d failed rval %d\n", eeprom->eeprom_cmd, rval); 19197 } 19198 19199 return (rval); 19200 } 19201 19202 static int 19203 bxe_get_settings(struct bxe_softc *sc, bxe_dev_setting_t *dev_p) 19204 { 19205 uint32_t ext_phy_config; 19206 int port = SC_PORT(sc); 19207 int cfg_idx = bxe_get_link_cfg_idx(sc); 19208 19209 dev_p->supported = sc->port.supported[cfg_idx] | 19210 (sc->port.supported[cfg_idx ^ 1] & 19211 (ELINK_SUPPORTED_TP | ELINK_SUPPORTED_FIBRE)); 19212 dev_p->advertising = sc->port.advertising[cfg_idx]; 19213 if(sc->link_params.phy[bxe_get_cur_phy_idx(sc)].media_type == 19214 ELINK_ETH_PHY_SFP_1G_FIBER) { 19215 dev_p->supported = ~(ELINK_SUPPORTED_10000baseT_Full); 19216 dev_p->advertising &= ~(ADVERTISED_10000baseT_Full); 19217 } 19218 if ((sc->state == BXE_STATE_OPEN) && sc->link_vars.link_up && 19219 !(sc->flags & BXE_MF_FUNC_DIS)) { 19220 dev_p->duplex = sc->link_vars.duplex; 19221 if (IS_MF(sc) && !BXE_NOMCP(sc)) 19222 dev_p->speed = bxe_get_mf_speed(sc); 19223 else 19224 dev_p->speed = sc->link_vars.line_speed; 19225 } else { 19226 dev_p->duplex = DUPLEX_UNKNOWN; 19227 dev_p->speed = SPEED_UNKNOWN; 19228 } 19229 19230 dev_p->port = bxe_media_detect(sc); 19231 19232 ext_phy_config = SHMEM_RD(sc, 19233 dev_info.port_hw_config[port].external_phy_config); 19234 if((ext_phy_config & PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK) == 19235 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) 19236 dev_p->phy_address = sc->port.phy_addr; 19237 else if(((ext_phy_config & PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK) != 19238 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) && 19239 ((ext_phy_config & PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK) != 19240 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)) 19241 dev_p->phy_address = ELINK_XGXS_EXT_PHY_ADDR(ext_phy_config); 19242 else 19243 dev_p->phy_address = 0; 19244 19245 if(sc->link_params.req_line_speed[cfg_idx] == ELINK_SPEED_AUTO_NEG) 19246 dev_p->autoneg = AUTONEG_ENABLE; 19247 else 19248 dev_p->autoneg = AUTONEG_DISABLE; 19249 19250 19251 return 0; 19252 } 19253 19254 static int 19255 bxe_eioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, 19256 struct thread *td) 19257 { 19258 struct bxe_softc *sc; 19259 int rval = 0; 19260 bxe_grcdump_t *dump = NULL; 19261 int grc_dump_size; 19262 bxe_drvinfo_t *drv_infop = NULL; 19263 bxe_dev_setting_t *dev_p; 19264 bxe_dev_setting_t dev_set; 19265 bxe_get_regs_t *reg_p; 19266 bxe_reg_rdw_t *reg_rdw_p; 19267 bxe_pcicfg_rdw_t *cfg_rdw_p; 19268 bxe_perm_mac_addr_t *mac_addr_p; 19269 19270 19271 if ((sc = (struct bxe_softc *)dev->si_drv1) == NULL) 19272 return ENXIO; 19273 19274 dump = (bxe_grcdump_t *)data; 19275 19276 switch(cmd) { 19277 19278 case BXE_GRC_DUMP_SIZE: 19279 dump->pci_func = sc->pcie_func; 19280 dump->grcdump_size = 19281 (bxe_get_total_regs_len32(sc) * sizeof(uint32_t)) + 19282 sizeof(struct dump_header); 19283 break; 19284 19285 case BXE_GRC_DUMP: 19286 19287 grc_dump_size = (bxe_get_total_regs_len32(sc) * sizeof(uint32_t)) + 19288 sizeof(struct dump_header); 19289 if ((!sc->trigger_grcdump) || (dump->grcdump == NULL) || 19290 (dump->grcdump_size < grc_dump_size)) { 19291 rval = EINVAL; 19292 break; 19293 } 19294 19295 if((sc->trigger_grcdump) && (!sc->grcdump_done) && 19296 (!sc->grcdump_started)) { 19297 rval = bxe_grc_dump(sc); 19298 } 19299 19300 if((!rval) && (sc->grcdump_done) && (sc->grcdump_started) && 19301 (sc->grc_dump != NULL)) { 19302 dump->grcdump_dwords = grc_dump_size >> 2; 19303 rval = copyout(sc->grc_dump, dump->grcdump, grc_dump_size); 19304 free(sc->grc_dump, M_DEVBUF); 19305 sc->grc_dump = NULL; 19306 sc->grcdump_started = 0; 19307 sc->grcdump_done = 0; 19308 } 19309 19310 break; 19311 19312 case BXE_DRV_INFO: 19313 drv_infop = (bxe_drvinfo_t *)data; 19314 snprintf(drv_infop->drv_name, BXE_DRV_NAME_LENGTH, "%s", "bxe"); 19315 snprintf(drv_infop->drv_version, BXE_DRV_VERSION_LENGTH, "v:%s", 19316 BXE_DRIVER_VERSION); 19317 snprintf(drv_infop->mfw_version, BXE_MFW_VERSION_LENGTH, "%s", 19318 sc->devinfo.bc_ver_str); 19319 snprintf(drv_infop->stormfw_version, BXE_STORMFW_VERSION_LENGTH, 19320 "%s", sc->fw_ver_str); 19321 drv_infop->eeprom_dump_len = sc->devinfo.flash_size; 19322 drv_infop->reg_dump_len = 19323 (bxe_get_total_regs_len32(sc) * sizeof(uint32_t)) 19324 + sizeof(struct dump_header); 19325 snprintf(drv_infop->bus_info, BXE_BUS_INFO_LENGTH, "%d:%d:%d", 19326 sc->pcie_bus, sc->pcie_device, sc->pcie_func); 19327 break; 19328 19329 case BXE_DEV_SETTING: 19330 dev_p = (bxe_dev_setting_t *)data; 19331 bxe_get_settings(sc, &dev_set); 19332 dev_p->supported = dev_set.supported; 19333 dev_p->advertising = dev_set.advertising; 19334 dev_p->speed = dev_set.speed; 19335 dev_p->duplex = dev_set.duplex; 19336 dev_p->port = dev_set.port; 19337 dev_p->phy_address = dev_set.phy_address; 19338 dev_p->autoneg = dev_set.autoneg; 19339 19340 break; 19341 19342 case BXE_GET_REGS: 19343 19344 reg_p = (bxe_get_regs_t *)data; 19345 grc_dump_size = reg_p->reg_buf_len; 19346 19347 if((!sc->grcdump_done) && (!sc->grcdump_started)) { 19348 bxe_grc_dump(sc); 19349 } 19350 if((sc->grcdump_done) && (sc->grcdump_started) && 19351 (sc->grc_dump != NULL)) { 19352 rval = copyout(sc->grc_dump, reg_p->reg_buf, grc_dump_size); 19353 free(sc->grc_dump, M_DEVBUF); 19354 sc->grc_dump = NULL; 19355 sc->grcdump_started = 0; 19356 sc->grcdump_done = 0; 19357 } 19358 19359 break; 19360 19361 case BXE_RDW_REG: 19362 reg_rdw_p = (bxe_reg_rdw_t *)data; 19363 if((reg_rdw_p->reg_cmd == BXE_READ_REG_CMD) && 19364 (reg_rdw_p->reg_access_type == BXE_REG_ACCESS_DIRECT)) 19365 reg_rdw_p->reg_val = REG_RD(sc, reg_rdw_p->reg_id); 19366 19367 if((reg_rdw_p->reg_cmd == BXE_WRITE_REG_CMD) && 19368 (reg_rdw_p->reg_access_type == BXE_REG_ACCESS_DIRECT)) 19369 REG_WR(sc, reg_rdw_p->reg_id, reg_rdw_p->reg_val); 19370 19371 break; 19372 19373 case BXE_RDW_PCICFG: 19374 cfg_rdw_p = (bxe_pcicfg_rdw_t *)data; 19375 if(cfg_rdw_p->cfg_cmd == BXE_READ_PCICFG) { 19376 19377 cfg_rdw_p->cfg_val = pci_read_config(sc->dev, cfg_rdw_p->cfg_id, 19378 cfg_rdw_p->cfg_width); 19379 19380 } else if(cfg_rdw_p->cfg_cmd == BXE_WRITE_PCICFG) { 19381 pci_write_config(sc->dev, cfg_rdw_p->cfg_id, cfg_rdw_p->cfg_val, 19382 cfg_rdw_p->cfg_width); 19383 } else { 19384 BLOGW(sc, "BXE_RDW_PCICFG ioctl wrong cmd passed\n"); 19385 } 19386 break; 19387 19388 case BXE_MAC_ADDR: 19389 mac_addr_p = (bxe_perm_mac_addr_t *)data; 19390 snprintf(mac_addr_p->mac_addr_str, sizeof(sc->mac_addr_str), "%s", 19391 sc->mac_addr_str); 19392 break; 19393 19394 case BXE_EEPROM: 19395 rval = bxe_eeprom_rd_wr(sc, (bxe_eeprom_t *)data); 19396 break; 19397 19398 19399 default: 19400 break; 19401 } 19402 19403 return (rval); 19404 } 19405 19406 #ifdef DEBUGNET 19407 static void 19408 bxe_debugnet_init(if_t ifp, int *nrxr, int *ncl, int *clsize) 19409 { 19410 struct bxe_softc *sc; 19411 19412 sc = if_getsoftc(ifp); 19413 BXE_CORE_LOCK(sc); 19414 *nrxr = sc->num_queues; 19415 *ncl = DEBUGNET_MAX_IN_FLIGHT; 19416 *clsize = sc->fp[0].mbuf_alloc_size; 19417 BXE_CORE_UNLOCK(sc); 19418 } 19419 19420 static void 19421 bxe_debugnet_event(if_t ifp __unused, enum debugnet_ev event __unused) 19422 { 19423 } 19424 19425 static int 19426 bxe_debugnet_transmit(if_t ifp, struct mbuf *m) 19427 { 19428 struct bxe_softc *sc; 19429 int error; 19430 19431 sc = if_getsoftc(ifp); 19432 if ((if_getdrvflags(ifp) & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != 19433 IFF_DRV_RUNNING || !sc->link_vars.link_up) 19434 return (ENOENT); 19435 19436 error = bxe_tx_encap(&sc->fp[0], &m); 19437 if (error != 0 && m != NULL) 19438 m_freem(m); 19439 return (error); 19440 } 19441 19442 static int 19443 bxe_debugnet_poll(if_t ifp, int count) 19444 { 19445 struct bxe_softc *sc; 19446 int i; 19447 19448 sc = if_getsoftc(ifp); 19449 if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0 || 19450 !sc->link_vars.link_up) 19451 return (ENOENT); 19452 19453 for (i = 0; i < sc->num_queues; i++) 19454 (void)bxe_rxeof(sc, &sc->fp[i]); 19455 (void)bxe_txeof(sc, &sc->fp[0]); 19456 return (0); 19457 } 19458 #endif /* DEBUGNET */ 19459